@embedpdf-editor/vue3-chapter-viewer 1.0.7-beta.4 → 1.0.7-beta.5

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/index.js CHANGED
@@ -24,7 +24,7 @@ import { AnnotationLayer, useAnnotationCapability } from "@embedpdf/plugin-annot
24
24
  import { RedactionLayer } from "@embedpdf/plugin-redaction/vue";
25
25
  import { RenderLayer } from "@embedpdf/plugin-render/vue";
26
26
  import { usePdfiumEngine } from "@embedpdf/engines/vue";
27
- const Pe = { position: "relative", height: "100%", width: "100%" }, Ie$1 = { userSelect: "none", WebkitUserSelect: "none" };
27
+ const Pe$1 = { position: "relative", height: "100%", width: "100%" }, Ie$1 = { userSelect: "none", WebkitUserSelect: "none" };
28
28
  function be$1() {
29
29
  var _a2;
30
30
  "undefined" != typeof window && ((_a2 = window.getSelection()) == null ? void 0 : _a2.removeAllRanges());
@@ -71,7 +71,7 @@ function De$1(e14) {
71
71
  function Ee$1(e14, t2) {
72
72
  return `${e14}#s${t2}`;
73
73
  }
74
- function Te$1(e14) {
74
+ function Ue$1(e14) {
75
75
  const t2 = (function(e15) {
76
76
  if (null != e15.segmentPageThreshold && e15.segmentPageThreshold > 0) return e15.segmentPageThreshold;
77
77
  const t3 = e15.source;
@@ -99,23 +99,23 @@ let Fe$1 = class Fe {
99
99
  return this.cb(e14, t2);
100
100
  }
101
101
  };
102
- const ze$1 = "chapter-manager", _e$1 = { id: ze$1, name: "Chapter Manager Plugin", version: "0.1.0", provides: ["chapter-manager"], requires: ["document-manager"], optional: [], defaultConfig: { manifest: { chapters: [] }, prefetchChapters: 1, maxConcurrentSegmentLoads: 2, unloadTimeoutMs: 6e4, autoActivateOnLoad: true } };
103
- function Ge$1(e14) {
102
+ const ze$1 = "chapter-manager", Ge$1 = { id: ze$1, name: "Chapter Manager Plugin", version: "0.1.0", provides: ["chapter-manager"], requires: ["document-manager"], optional: [], defaultConfig: { manifest: { chapters: [] }, prefetchChapters: 1, maxConcurrentSegmentLoads: 1, unloadTimeoutMs: 6e4, autoActivateOnLoad: true } };
103
+ function _e$1(e14) {
104
104
  const [t2, s2] = e14.localPageRange;
105
105
  return s2 - t2 + 1;
106
106
  }
107
107
  function Be$1(e14) {
108
108
  return !!e14 && "urls" in e14 && Array.isArray(e14.urls);
109
109
  }
110
- function He$1(e14) {
110
+ function We$1(e14) {
111
111
  if (null != e14.segmentPageThreshold && e14.segmentPageThreshold > 0) return e14.segmentPageThreshold;
112
112
  const t2 = e14.source;
113
113
  return Be$1(t2) ? t2.segmentPageThreshold : null;
114
114
  }
115
- function We$1(e14, t2) {
115
+ function qe$1(e14, t2) {
116
116
  return `${e14}#s${t2}`;
117
117
  }
118
- function qe$1(e14) {
118
+ function He$1(e14) {
119
119
  const t2 = e14.lastIndexOf("#s");
120
120
  if (-1 === t2) return { chapterId: e14, segmentIndex: null };
121
121
  const s2 = e14.slice(0, t2), n9 = Number.parseInt(e14.slice(t2 + 2), 10);
@@ -125,13 +125,13 @@ function Ke$1(e14, t2) {
125
125
  return e14 <= 0 || t2 <= 0 ? 0 : Math.ceil(e14 / t2);
126
126
  }
127
127
  function je$1(e14) {
128
- const t2 = He$1(e14);
128
+ const t2 = We$1(e14);
129
129
  if (!t2) return null;
130
- const s2 = Ge$1(e14), n9 = Ke$1(s2, t2), r2 = Be$1(e14.source) ? e14.source.urls : void 0, a2 = [];
130
+ const s2 = _e$1(e14), n9 = Ke$1(s2, t2), r2 = Be$1(e14.source) ? e14.source.urls : void 0, a2 = [];
131
131
  for (let i2 = 0; i2 < n9; i2++) {
132
132
  const n10 = i2 * t2, o2 = Math.min(n10 + t2 - 1, s2 - 1);
133
133
  if (n10 >= s2) break;
134
- a2.push({ index: i2, url: (null == r2 ? void 0 : r2[i2]) ?? "", localPageStart: n10, localPageEnd: o2, documentId: We$1(e14.chapterId, i2) });
134
+ a2.push({ index: i2, url: (null == r2 ? void 0 : r2[i2]) ?? "", localPageStart: n10, localPageEnd: o2, documentId: qe$1(e14.chapterId, i2) });
135
135
  }
136
136
  return { chapterId: e14.chapterId, threshold: t2, pageCount: s2, segments: a2 };
137
137
  }
@@ -153,9 +153,9 @@ function Ze$1(e14, t2) {
153
153
  }
154
154
  function Ye$1(e14) {
155
155
  var t2;
156
- const s2 = He$1(e14);
156
+ const s2 = We$1(e14);
157
157
  if (!s2) return [];
158
- const n9 = [], { chapterId: r2 } = e14, a2 = Ge$1(e14);
158
+ const n9 = [], { chapterId: r2 } = e14, a2 = _e$1(e14);
159
159
  s2 <= 0 && n9.push(`${r2}: segmentPageThreshold must be > 0`);
160
160
  const i2 = e14.source;
161
161
  if (!Be$1(i2)) return n9;
@@ -245,17 +245,17 @@ function tt$1(e14, t2 = Qe$1) {
245
245
  }
246
246
  const st$1 = class e extends BasePlugin {
247
247
  constructor(e14, t2) {
248
- super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = Qe$1, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.SEG_PRIO_PREFETCH_NEXT = 120, this.SEG_PRIO_CHAPTER_PREFETCH_BASE = 3e3, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
248
+ super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = Qe$1, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
249
249
  }
250
250
  async initialize(e14) {
251
251
  if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? Qe$1, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
252
- const { chapterId: t2 } = qe$1(e15.id);
252
+ const { chapterId: t2 } = He$1(e15.id);
253
253
  this.findChapter(t2) && (this.passwordAttempts.delete(t2), this.syncChapterStatusFromDocuments(t2));
254
254
  }), this.documentManager.provides().onDocumentClosed((e15) => {
255
- const { chapterId: t2 } = qe$1(e15);
255
+ const { chapterId: t2 } = He$1(e15);
256
256
  this.findChapter(t2) && this.syncChapterStatusFromDocuments(t2);
257
257
  }), this.documentManager.provides().onDocumentError((e15) => {
258
- const { chapterId: t2 } = qe$1(e15.documentId);
258
+ const { chapterId: t2 } = He$1(e15.documentId);
259
259
  this.findChapter(t2) && this.handleDocumentError(e15.documentId, t2, e15.code, e15.message);
260
260
  })), this.setManifestInternal(e14.manifest), e14.unloadTimeoutMs && e14.unloadTimeoutMs > 0) {
261
261
  const t2 = Math.max(5e3, Math.floor(e14.unloadTimeoutMs / 4));
@@ -387,13 +387,22 @@ const st$1 = class e extends BasePlugin {
387
387
  clearVisibleSegmentBacklog() {
388
388
  this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0;
389
389
  }
390
+ globalSegmentSortKey(e14, t2) {
391
+ var s2;
392
+ if (!this.virtualPageMap) return Number.MAX_SAFE_INTEGER;
393
+ const n9 = this.findChapter(e14);
394
+ if (!n9) return Number.MAX_SAFE_INTEGER;
395
+ const r2 = je$1(n9), a2 = (null == (s2 = null == r2 ? void 0 : r2.segments[t2]) ? void 0 : s2.localPageStart) ?? 0, i2 = this.virtualPageMap.toGlobal(e14, a2);
396
+ if (i2) return i2.globalPageIndex;
397
+ return 1e4 * this.manifest.chapters.findIndex((t3) => t3.chapterId === e14) + t2;
398
+ }
390
399
  scheduleVisibleSegmentLoads(e14) {
391
- const t2 = /* @__PURE__ */ new Set(), s2 = [...e14].sort((e15, t3) => e15.priority - t3.priority);
392
- for (const n9 of s2) {
393
- const e15 = `${n9.chapterId}:${n9.segmentIndex}`;
394
- t2.has(e15) || (t2.add(e15), this.isSegmentDocumentOpen(n9.chapterId, n9.segmentIndex) || this.isSegmentLoadPending(n9.chapterId, n9.segmentIndex) || this.visibleSegmentBacklog.push({ chapterId: n9.chapterId, segmentIndex: n9.segmentIndex }));
400
+ const t2 = [...e14].sort((e15, t3) => e15.priority - t3.priority), s2 = /* @__PURE__ */ new Set(), n9 = [];
401
+ for (const r2 of t2) {
402
+ const e15 = `${r2.chapterId}:${r2.segmentIndex}`;
403
+ s2.has(e15) || (s2.add(e15), this.isSegmentDocumentOpen(r2.chapterId, r2.segmentIndex) || this.isSegmentLoadPending(r2.chapterId, r2.segmentIndex) || n9.push({ chapterId: r2.chapterId, segmentIndex: r2.segmentIndex }));
395
404
  }
396
- this.pumpVisibleSegmentBacklog();
405
+ this.visibleSegmentBacklog = n9, this.pumpVisibleSegmentBacklog();
397
406
  }
398
407
  pumpVisibleSegmentBacklog() {
399
408
  const e14 = Math.max(1, this.config.maxConcurrentSegmentLoads ?? 2);
@@ -412,53 +421,41 @@ const st$1 = class e extends BasePlugin {
412
421
  const t2 = e14.join(","), s2 = this.visibleRangeNeedsSegmentLoad(e14);
413
422
  if (t2 === this.lastVisibleIndicesKey && !s2) return;
414
423
  this.lastVisibleIndicesKey = t2;
415
- const n9 = Date.now(), r2 = this.config.prefetchChapters ?? 1, a2 = e14[Math.floor(e14.length / 2)] ?? e14[0], i2 = /* @__PURE__ */ new Set(), o2 = /* @__PURE__ */ new Map(), l = (e15, t3, s3) => {
424
+ const n9 = Date.now(), r2 = e14[Math.floor(e14.length / 2)] ?? e14[0], a2 = /* @__PURE__ */ new Set(), i2 = /* @__PURE__ */ new Map(), o2 = (e15, t3) => {
416
425
  if (t3 < 0) return;
417
- const n10 = this.findChapter(e15);
418
- if (!n10) return;
419
- const r3 = je$1(n10);
420
- if (r3 && t3 >= r3.segments.length) return;
421
- const a3 = `${e15}:${t3}`, i3 = o2.get(a3);
422
- (void 0 === i3 || s3 < i3) && o2.set(a3, s3);
426
+ const s3 = this.findChapter(e15);
427
+ if (!s3) return;
428
+ const n10 = je$1(s3);
429
+ if (n10 && t3 >= n10.segments.length) return;
430
+ const r3 = `${e15}:${t3}`, a3 = this.globalSegmentSortKey(e15, t3), o3 = i2.get(r3);
431
+ (void 0 === o3 || a3 < o3) && i2.set(r3, a3);
423
432
  };
424
- for (const p2 of e14) {
425
- const e15 = this.virtualPageMap.atIndex(p2);
433
+ for (const d2 of e14) {
434
+ const e15 = this.virtualPageMap.atIndex(d2);
426
435
  if (!e15) continue;
427
- i2.add(e15.chapterId);
436
+ a2.add(e15.chapterId);
428
437
  const t3 = this.findChapter(e15.chapterId);
429
438
  if (!t3) continue;
430
- const s3 = Math.abs(p2 - a2), n10 = Ze$1(t3, e15.localPageIndex);
431
- l(e15.chapterId, n10, s3), l(e15.chapterId, n10 + 1, s3 + this.SEG_PRIO_PREFETCH_NEXT), this.resolveChapterUrls(t3).catch(() => {
439
+ const s3 = Ze$1(t3, e15.localPageIndex);
440
+ o2(e15.chapterId, s3), this.resolveChapterUrls(t3).catch(() => {
432
441
  });
433
442
  }
434
- if (0 === i2.size) return;
435
- const h2 = this.manifest.chapters.map((e15) => e15.chapterId);
436
- let d2 = 0;
437
- const c2 = this.virtualPageMap.atIndex(a2);
438
- if (c2) {
439
- const e15 = h2.indexOf(c2.chapterId);
440
- e15 >= 0 && (d2 = e15);
441
- }
442
- for (const p2 of i2) {
443
- this.chapterLastUsed.set(p2, n9);
444
- const e15 = h2.indexOf(p2);
445
- if (-1 !== e15) for (let t3 = e15 - r2; t3 <= e15 + r2; t3++) {
446
- if (t3 < 0 || t3 >= h2.length) continue;
447
- const e16 = h2[t3];
448
- this.chapterLastUsed.set(e16, n9);
449
- const s3 = Math.abs(t3 - d2);
450
- l(e16, 0, this.SEG_PRIO_CHAPTER_PREFETCH_BASE + 100 * s3);
451
- const r3 = this.findChapter(e16);
452
- r3 && this.resolveChapterUrls(r3).catch(() => {
453
- });
443
+ if (0 === a2.size) return;
444
+ const l = this.virtualPageMap.atIndex(r2);
445
+ if (l) {
446
+ const e15 = this.findChapter(l.chapterId);
447
+ if (e15) {
448
+ const t3 = Ze$1(e15, l.localPageIndex);
449
+ o2(l.chapterId, t3 + 1);
454
450
  }
455
451
  }
456
- const u2 = [...o2.entries()].map(([e15, t3]) => {
452
+ for (const d2 of a2) this.chapterLastUsed.set(d2, n9);
453
+ const h2 = [...i2.entries()].map(([e15, t3]) => {
457
454
  const [s3, n10] = e15.split(":");
458
455
  return { chapterId: s3, segmentIndex: Number.parseInt(n10, 10), priority: t3 };
459
456
  }).filter((e15) => e15.chapterId && Number.isFinite(e15.segmentIndex));
460
- if (this.scheduleVisibleSegmentLoads(u2), this.config.autoActivateOnLoad ?? 1) {
461
- const e15 = this.virtualPageMap.atIndex(a2);
457
+ if (this.scheduleVisibleSegmentLoads(h2), this.config.autoActivateOnLoad ?? 1) {
458
+ const e15 = this.virtualPageMap.atIndex(r2);
462
459
  if (e15) {
463
460
  const t3 = Xe$1(this.findChapter(e15.chapterId), e15.localPageIndex);
464
461
  if (this.documentManager.provides().isDocumentOpen(t3.documentId)) {
@@ -552,9 +549,9 @@ const st$1 = class e extends BasePlugin {
552
549
  return (null == r2 ? void 0 : r2.openPdf) ? r2.openPdf(a2) : { url: n9 };
553
550
  }
554
551
  async resolvePdfPayload(t2, s2) {
555
- const n9 = t2.source, r2 = this.config.chapterPdfLoader, a2 = He$1(t2);
552
+ const n9 = t2.source, r2 = this.config.chapterPdfLoader, a2 = We$1(t2);
556
553
  if (a2) {
557
- const n10 = Ke$1(Ge$1(t2), a2);
554
+ const n10 = Ke$1(_e$1(t2), a2);
558
555
  if (s2 < 0 || s2 >= n10) throw new Error(`Chapter "${t2.chapterId}" invalid segmentIndex ${s2} (expected 0..${n10 - 1})`);
559
556
  const r3 = await this.resolveChapterUrls(t2);
560
557
  if (r3.length !== n10) {
@@ -613,7 +610,7 @@ const st$1 = class e extends BasePlugin {
613
610
  async handleDocumentError(t2, s2, n9, r2) {
614
611
  if (this.pendingSegmentLoadPromises.has(t2)) return;
615
612
  if (n9 !== PdfErrorCode.Password) {
616
- const e14 = this.getSegmentPlanForChapter(s2), { segmentIndex: n10 } = qe$1(t2);
613
+ const e14 = this.getSegmentPlanForChapter(s2), { segmentIndex: n10 } = He$1(t2);
617
614
  return void (e14 && 0 !== n10 && null !== n10 || this.updateStatus(s2, "error"));
618
615
  }
619
616
  if (!this.passwordProvider) return void this.updateStatus(s2, "password-required");
@@ -652,7 +649,7 @@ const st$1 = class e extends BasePlugin {
652
649
  };
653
650
  st$1.id = "chapter-manager";
654
651
  let nt$1 = st$1;
655
- const rt$1 = { manifest: _e$1, create: (e14) => new nt$1(ze$1, e14), reducer: (e14) => e14, initialState: {} }, at$1 = "chapter-scroll", it = { id: at$1, name: "Chapter Scroll Plugin", version: "0.1.0", provides: ["chapter-scroll"], requires: ["chapter-manager"], optional: [], defaultConfig: { placeholderPageHeight: 1200, placeholderPageWidth: 900, bufferSize: 2, pageGap: 20 } };
652
+ const rt$1 = { manifest: Ge$1, create: (e14) => new nt$1(ze$1, e14), reducer: (e14) => e14, initialState: {} }, at$1 = "chapter-scroll", it = { id: at$1, name: "Chapter Scroll Plugin", version: "0.1.0", provides: ["chapter-scroll"], requires: ["chapter-manager"], optional: [], defaultConfig: { placeholderPageHeight: 1200, placeholderPageWidth: 900, bufferSize: 2, pageGap: 20 } };
656
653
  function ot(e14) {
657
654
  return !!e14 && "urls" in e14 && Array.isArray(e14.urls);
658
655
  }
@@ -692,12 +689,12 @@ function ct$1(e14) {
692
689
  function ut$1(e14) {
693
690
  return !!e14 && "urls" in e14 && Array.isArray(e14.urls);
694
691
  }
695
- function pt$1(e14) {
692
+ function gt$1(e14) {
696
693
  if (null != e14.segmentPageThreshold && e14.segmentPageThreshold > 0) return e14.segmentPageThreshold;
697
694
  const t2 = e14.source;
698
695
  return ut$1(t2) ? t2.segmentPageThreshold : null;
699
696
  }
700
- function gt$1(e14, t2) {
697
+ function pt$1(e14, t2) {
701
698
  return `${e14}#s${t2}`;
702
699
  }
703
700
  function mt$1(e14) {
@@ -710,13 +707,13 @@ function ft$1(e14, t2) {
710
707
  return e14 <= 0 || t2 <= 0 ? 0 : Math.ceil(e14 / t2);
711
708
  }
712
709
  function vt$1(e14) {
713
- const t2 = pt$1(e14);
710
+ const t2 = gt$1(e14);
714
711
  if (!t2) return null;
715
712
  const s2 = ct$1(e14), n9 = ft$1(s2, t2), r2 = ut$1(e14.source) ? e14.source.urls : void 0, a2 = [];
716
713
  for (let i2 = 0; i2 < n9; i2++) {
717
714
  const n10 = i2 * t2, o2 = Math.min(n10 + t2 - 1, s2 - 1);
718
715
  if (n10 >= s2) break;
719
- a2.push({ index: i2, url: (null == r2 ? void 0 : r2[i2]) ?? "", localPageStart: n10, localPageEnd: o2, documentId: gt$1(e14.chapterId, i2) });
716
+ a2.push({ index: i2, url: (null == r2 ? void 0 : r2[i2]) ?? "", localPageStart: n10, localPageEnd: o2, documentId: pt$1(e14.chapterId, i2) });
720
717
  }
721
718
  return { chapterId: e14.chapterId, threshold: t2, pageCount: s2, segments: a2 };
722
719
  }
@@ -738,7 +735,7 @@ function It$1(e14, t2) {
738
735
  }
739
736
  function bt$1(e14) {
740
737
  var t2;
741
- const s2 = pt$1(e14);
738
+ const s2 = gt$1(e14);
742
739
  if (!s2) return [];
743
740
  const n9 = [], { chapterId: r2 } = e14, a2 = ct$1(e14);
744
741
  s2 <= 0 && n9.push(`${r2}: segmentPageThreshold must be > 0`);
@@ -830,7 +827,7 @@ function wt$1(e14, t2 = St$1) {
830
827
  }
831
828
  const Mt$1 = class e2 extends BasePlugin {
832
829
  constructor(e14, t2) {
833
- super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = St$1, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.SEG_PRIO_PREFETCH_NEXT = 120, this.SEG_PRIO_CHAPTER_PREFETCH_BASE = 3e3, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
830
+ super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = St$1, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
834
831
  }
835
832
  async initialize(e14) {
836
833
  if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? St$1, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
@@ -972,13 +969,22 @@ const Mt$1 = class e2 extends BasePlugin {
972
969
  clearVisibleSegmentBacklog() {
973
970
  this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0;
974
971
  }
972
+ globalSegmentSortKey(e14, t2) {
973
+ var s2;
974
+ if (!this.virtualPageMap) return Number.MAX_SAFE_INTEGER;
975
+ const n9 = this.findChapter(e14);
976
+ if (!n9) return Number.MAX_SAFE_INTEGER;
977
+ const r2 = vt$1(n9), a2 = (null == (s2 = null == r2 ? void 0 : r2.segments[t2]) ? void 0 : s2.localPageStart) ?? 0, i2 = this.virtualPageMap.toGlobal(e14, a2);
978
+ if (i2) return i2.globalPageIndex;
979
+ return 1e4 * this.manifest.chapters.findIndex((t3) => t3.chapterId === e14) + t2;
980
+ }
975
981
  scheduleVisibleSegmentLoads(e14) {
976
- const t2 = /* @__PURE__ */ new Set(), s2 = [...e14].sort((e15, t3) => e15.priority - t3.priority);
977
- for (const n9 of s2) {
978
- const e15 = `${n9.chapterId}:${n9.segmentIndex}`;
979
- t2.has(e15) || (t2.add(e15), this.isSegmentDocumentOpen(n9.chapterId, n9.segmentIndex) || this.isSegmentLoadPending(n9.chapterId, n9.segmentIndex) || this.visibleSegmentBacklog.push({ chapterId: n9.chapterId, segmentIndex: n9.segmentIndex }));
982
+ const t2 = [...e14].sort((e15, t3) => e15.priority - t3.priority), s2 = /* @__PURE__ */ new Set(), n9 = [];
983
+ for (const r2 of t2) {
984
+ const e15 = `${r2.chapterId}:${r2.segmentIndex}`;
985
+ s2.has(e15) || (s2.add(e15), this.isSegmentDocumentOpen(r2.chapterId, r2.segmentIndex) || this.isSegmentLoadPending(r2.chapterId, r2.segmentIndex) || n9.push({ chapterId: r2.chapterId, segmentIndex: r2.segmentIndex }));
980
986
  }
981
- this.pumpVisibleSegmentBacklog();
987
+ this.visibleSegmentBacklog = n9, this.pumpVisibleSegmentBacklog();
982
988
  }
983
989
  pumpVisibleSegmentBacklog() {
984
990
  const e14 = Math.max(1, this.config.maxConcurrentSegmentLoads ?? 2);
@@ -997,53 +1003,41 @@ const Mt$1 = class e2 extends BasePlugin {
997
1003
  const t2 = e14.join(","), s2 = this.visibleRangeNeedsSegmentLoad(e14);
998
1004
  if (t2 === this.lastVisibleIndicesKey && !s2) return;
999
1005
  this.lastVisibleIndicesKey = t2;
1000
- const n9 = Date.now(), r2 = this.config.prefetchChapters ?? 1, a2 = e14[Math.floor(e14.length / 2)] ?? e14[0], i2 = /* @__PURE__ */ new Set(), o2 = /* @__PURE__ */ new Map(), l = (e15, t3, s3) => {
1006
+ const n9 = Date.now(), r2 = e14[Math.floor(e14.length / 2)] ?? e14[0], a2 = /* @__PURE__ */ new Set(), i2 = /* @__PURE__ */ new Map(), o2 = (e15, t3) => {
1001
1007
  if (t3 < 0) return;
1002
- const n10 = this.findChapter(e15);
1003
- if (!n10) return;
1004
- const r3 = vt$1(n10);
1005
- if (r3 && t3 >= r3.segments.length) return;
1006
- const a3 = `${e15}:${t3}`, i3 = o2.get(a3);
1007
- (void 0 === i3 || s3 < i3) && o2.set(a3, s3);
1008
+ const s3 = this.findChapter(e15);
1009
+ if (!s3) return;
1010
+ const n10 = vt$1(s3);
1011
+ if (n10 && t3 >= n10.segments.length) return;
1012
+ const r3 = `${e15}:${t3}`, a3 = this.globalSegmentSortKey(e15, t3), o3 = i2.get(r3);
1013
+ (void 0 === o3 || a3 < o3) && i2.set(r3, a3);
1008
1014
  };
1009
- for (const p2 of e14) {
1010
- const e15 = this.virtualPageMap.atIndex(p2);
1015
+ for (const d2 of e14) {
1016
+ const e15 = this.virtualPageMap.atIndex(d2);
1011
1017
  if (!e15) continue;
1012
- i2.add(e15.chapterId);
1018
+ a2.add(e15.chapterId);
1013
1019
  const t3 = this.findChapter(e15.chapterId);
1014
1020
  if (!t3) continue;
1015
- const s3 = Math.abs(p2 - a2), n10 = It$1(t3, e15.localPageIndex);
1016
- l(e15.chapterId, n10, s3), l(e15.chapterId, n10 + 1, s3 + this.SEG_PRIO_PREFETCH_NEXT), this.resolveChapterUrls(t3).catch(() => {
1021
+ const s3 = It$1(t3, e15.localPageIndex);
1022
+ o2(e15.chapterId, s3), this.resolveChapterUrls(t3).catch(() => {
1017
1023
  });
1018
1024
  }
1019
- if (0 === i2.size) return;
1020
- const h2 = this.manifest.chapters.map((e15) => e15.chapterId);
1021
- let d2 = 0;
1022
- const c2 = this.virtualPageMap.atIndex(a2);
1023
- if (c2) {
1024
- const e15 = h2.indexOf(c2.chapterId);
1025
- e15 >= 0 && (d2 = e15);
1026
- }
1027
- for (const p2 of i2) {
1028
- this.chapterLastUsed.set(p2, n9);
1029
- const e15 = h2.indexOf(p2);
1030
- if (-1 !== e15) for (let t3 = e15 - r2; t3 <= e15 + r2; t3++) {
1031
- if (t3 < 0 || t3 >= h2.length) continue;
1032
- const e16 = h2[t3];
1033
- this.chapterLastUsed.set(e16, n9);
1034
- const s3 = Math.abs(t3 - d2);
1035
- l(e16, 0, this.SEG_PRIO_CHAPTER_PREFETCH_BASE + 100 * s3);
1036
- const r3 = this.findChapter(e16);
1037
- r3 && this.resolveChapterUrls(r3).catch(() => {
1038
- });
1025
+ if (0 === a2.size) return;
1026
+ const l = this.virtualPageMap.atIndex(r2);
1027
+ if (l) {
1028
+ const e15 = this.findChapter(l.chapterId);
1029
+ if (e15) {
1030
+ const t3 = It$1(e15, l.localPageIndex);
1031
+ o2(l.chapterId, t3 + 1);
1039
1032
  }
1040
1033
  }
1041
- const u2 = [...o2.entries()].map(([e15, t3]) => {
1034
+ for (const d2 of a2) this.chapterLastUsed.set(d2, n9);
1035
+ const h2 = [...i2.entries()].map(([e15, t3]) => {
1042
1036
  const [s3, n10] = e15.split(":");
1043
1037
  return { chapterId: s3, segmentIndex: Number.parseInt(n10, 10), priority: t3 };
1044
1038
  }).filter((e15) => e15.chapterId && Number.isFinite(e15.segmentIndex));
1045
- if (this.scheduleVisibleSegmentLoads(u2), this.config.autoActivateOnLoad ?? 1) {
1046
- const e15 = this.virtualPageMap.atIndex(a2);
1039
+ if (this.scheduleVisibleSegmentLoads(h2), this.config.autoActivateOnLoad ?? 1) {
1040
+ const e15 = this.virtualPageMap.atIndex(r2);
1047
1041
  if (e15) {
1048
1042
  const t3 = Pt$1(this.findChapter(e15.chapterId), e15.localPageIndex);
1049
1043
  if (this.documentManager.provides().isDocumentOpen(t3.documentId)) {
@@ -1137,7 +1131,7 @@ const Mt$1 = class e2 extends BasePlugin {
1137
1131
  return (null == r2 ? void 0 : r2.openPdf) ? r2.openPdf(a2) : { url: n9 };
1138
1132
  }
1139
1133
  async resolvePdfPayload(t2, s2) {
1140
- const n9 = t2.source, r2 = this.config.chapterPdfLoader, a2 = pt$1(t2);
1134
+ const n9 = t2.source, r2 = this.config.chapterPdfLoader, a2 = gt$1(t2);
1141
1135
  if (a2) {
1142
1136
  const n10 = ft$1(ct$1(t2), a2);
1143
1137
  if (s2 < 0 || s2 >= n10) throw new Error(`Chapter "${t2.chapterId}" invalid segmentIndex ${s2} (expected 0..${n10 - 1})`);
@@ -1468,45 +1462,45 @@ const $t$1 = class $t extends BasePlugin {
1468
1462
  };
1469
1463
  $t$1.id = "chapter-scroll";
1470
1464
  let kt$1 = $t$1;
1471
- const Dt$1 = { manifest: it, create: (e14) => new kt$1(at$1, e14), reducer: (e14) => e14, initialState: {} }, Et$1 = "note", Tt$1 = { id: Et$1, name: "Note Plugin", version: "0.1.0", provides: ["note"], requires: ["selection", "chapter-scroll", "chapter-manager"], optional: [], defaultConfig: { callbacks: { onCreateNote: async () => null, onActivateNote: () => {
1465
+ const Dt$1 = { manifest: it, create: (e14) => new kt$1(at$1, e14), reducer: (e14) => e14, initialState: {} }, Et$1 = "note", Ut$1 = { id: Et$1, name: "Note Plugin", version: "0.1.0", provides: ["note"], requires: ["selection", "chapter-scroll", "chapter-manager"], optional: [], defaultConfig: { callbacks: { onCreateNote: async () => null, onActivateNote: () => {
1472
1466
  } }, markerSize: 18 } };
1473
- function Ut$1(e14) {
1467
+ function Tt$1(e14) {
1474
1468
  const [t2, s2] = e14.localPageRange;
1475
1469
  return s2 - t2 + 1;
1476
1470
  }
1477
1471
  function Ft$1(e14) {
1478
1472
  return !!e14 && "urls" in e14 && Array.isArray(e14.urls);
1479
1473
  }
1480
- function Ot$1(e14) {
1474
+ function Nt$1(e14) {
1481
1475
  if (null != e14.segmentPageThreshold && e14.segmentPageThreshold > 0) return e14.segmentPageThreshold;
1482
1476
  const t2 = e14.source;
1483
1477
  return Ft$1(t2) ? t2.segmentPageThreshold : null;
1484
1478
  }
1485
- function Rt$1(e14, t2) {
1479
+ function At$1(e14, t2) {
1486
1480
  return `${e14}#s${t2}`;
1487
1481
  }
1488
- function Nt$1(e14) {
1482
+ function Vt$1(e14) {
1489
1483
  const t2 = e14.lastIndexOf("#s");
1490
1484
  if (-1 === t2) return { chapterId: e14, segmentIndex: null };
1491
1485
  const s2 = e14.slice(0, t2), n9 = Number.parseInt(e14.slice(t2 + 2), 10);
1492
1486
  return !Number.isFinite(n9) || n9 < 0 ? { chapterId: e14, segmentIndex: null } : { chapterId: s2, segmentIndex: n9 };
1493
1487
  }
1494
- function At$1(e14, t2) {
1488
+ function Ot$1(e14, t2) {
1495
1489
  return e14 <= 0 || t2 <= 0 ? 0 : Math.ceil(e14 / t2);
1496
1490
  }
1497
- function Vt$1(e14) {
1498
- const t2 = Ot$1(e14);
1491
+ function Rt$1(e14) {
1492
+ const t2 = Nt$1(e14);
1499
1493
  if (!t2) return null;
1500
- const s2 = Ut$1(e14), n9 = At$1(s2, t2), r2 = Ft$1(e14.source) ? e14.source.urls : void 0, a2 = [];
1494
+ const s2 = Tt$1(e14), n9 = Ot$1(s2, t2), r2 = Ft$1(e14.source) ? e14.source.urls : void 0, a2 = [];
1501
1495
  for (let i2 = 0; i2 < n9; i2++) {
1502
1496
  const n10 = i2 * t2, o2 = Math.min(n10 + t2 - 1, s2 - 1);
1503
1497
  if (n10 >= s2) break;
1504
- a2.push({ index: i2, url: (null == r2 ? void 0 : r2[i2]) ?? "", localPageStart: n10, localPageEnd: o2, documentId: Rt$1(e14.chapterId, i2) });
1498
+ a2.push({ index: i2, url: (null == r2 ? void 0 : r2[i2]) ?? "", localPageStart: n10, localPageEnd: o2, documentId: At$1(e14.chapterId, i2) });
1505
1499
  }
1506
1500
  return { chapterId: e14.chapterId, threshold: t2, pageCount: s2, segments: a2 };
1507
1501
  }
1508
1502
  function zt$1(e14, t2) {
1509
- const s2 = Vt$1(e14);
1503
+ const s2 = Rt$1(e14);
1510
1504
  if (!s2) return { documentId: e14.chapterId, pageIndex: t2 };
1511
1505
  const n9 = s2.segments.find((e15) => t2 >= e15.localPageStart && t2 <= e15.localPageEnd);
1512
1506
  if (!n9) {
@@ -1515,28 +1509,28 @@ function zt$1(e14, t2) {
1515
1509
  }
1516
1510
  return { documentId: n9.documentId, pageIndex: t2 - n9.localPageStart };
1517
1511
  }
1518
- function _t$1(e14, t2) {
1519
- const s2 = Vt$1(e14);
1512
+ function Gt$1(e14, t2) {
1513
+ const s2 = Rt$1(e14);
1520
1514
  if (!s2) return 0;
1521
1515
  const n9 = s2.segments.find((e15) => t2 >= e15.localPageStart && t2 <= e15.localPageEnd);
1522
1516
  return (null == n9 ? void 0 : n9.index) ?? Math.floor(t2 / s2.threshold);
1523
1517
  }
1524
- function Gt$1(e14) {
1518
+ function _t$1(e14) {
1525
1519
  var t2;
1526
- const s2 = Ot$1(e14);
1520
+ const s2 = Nt$1(e14);
1527
1521
  if (!s2) return [];
1528
- const n9 = [], { chapterId: r2 } = e14, a2 = Ut$1(e14);
1522
+ const n9 = [], { chapterId: r2 } = e14, a2 = Tt$1(e14);
1529
1523
  s2 <= 0 && n9.push(`${r2}: segmentPageThreshold must be > 0`);
1530
1524
  const i2 = e14.source;
1531
1525
  if (!Ft$1(i2)) return n9;
1532
1526
  0 === i2.urls.length && n9.push(`${r2}: source.urls must not be empty`);
1533
- const o2 = At$1(a2, s2);
1527
+ const o2 = Ot$1(a2, s2);
1534
1528
  i2.urls.length !== o2 && n9.push(`${r2}: source.urls.length (${i2.urls.length}) must equal ceil(pageCount/threshold) (${o2})`);
1535
1529
  for (let l = 0; l < i2.urls.length; l++) (null == (t2 = i2.urls[l]) ? void 0 : t2.trim()) || n9.push(`${r2}: source.urls[${l}] is empty`);
1536
1530
  return n9;
1537
1531
  }
1538
1532
  const Bt$1 = { kind: "first-wins" };
1539
- function Ht$1(e14, t2, s2) {
1533
+ function Wt$1(e14, t2, s2) {
1540
1534
  if (1 === t2.length) return t2[0].chapterId;
1541
1535
  switch (s2.kind) {
1542
1536
  case "first-wins":
@@ -1554,7 +1548,7 @@ function Ht$1(e14, t2, s2) {
1554
1548
  return s2.resolve(e14, t2);
1555
1549
  }
1556
1550
  }
1557
- let Wt$1 = class Wt {
1551
+ let qt$1 = class qt {
1558
1552
  constructor(e14) {
1559
1553
  this._pages = e14, this._byChapter = /* @__PURE__ */ new Map(), this._byGlobalNumber = /* @__PURE__ */ new Map();
1560
1554
  for (const t2 of e14) {
@@ -1588,7 +1582,7 @@ let Wt$1 = class Wt {
1588
1582
  return s2 ? this._pages.indexOf(s2) : -1;
1589
1583
  }
1590
1584
  };
1591
- function qt$1(e14, t2 = Bt$1) {
1585
+ function Ht$1(e14, t2 = Bt$1) {
1592
1586
  const s2 = (function(e15, t3 = Bt$1) {
1593
1587
  const s3 = /* @__PURE__ */ new Map();
1594
1588
  for (const r3 of e15.chapters) {
@@ -1599,7 +1593,7 @@ function qt$1(e14, t2 = Bt$1) {
1599
1593
  }
1600
1594
  }
1601
1595
  const n10 = /* @__PURE__ */ new Map();
1602
- for (const [r3, a3] of s3) n10.set(r3, Ht$1(r3, a3, t3));
1596
+ for (const [r3, a3] of s3) n10.set(r3, Wt$1(r3, a3, t3));
1603
1597
  return n10;
1604
1598
  })(e14, t2), n9 = /* @__PURE__ */ new Map();
1605
1599
  for (const o2 of e14.chapters) n9.set(o2.chapterId, o2);
@@ -1611,21 +1605,21 @@ function qt$1(e14, t2 = Bt$1) {
1611
1605
  const [r3] = t3.globalPageRange, [l] = t3.localPageRange, h2 = l + (o2 - r3);
1612
1606
  a2.push({ globalPageIndex: i2++, globalPageNumber: o2, chapterId: e15, localPageIndex: h2 });
1613
1607
  }
1614
- return new Wt$1(a2);
1608
+ return new qt$1(a2);
1615
1609
  }
1616
1610
  const Kt$1 = class e3 extends BasePlugin {
1617
1611
  constructor(e14, t2) {
1618
- super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = Bt$1, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.SEG_PRIO_PREFETCH_NEXT = 120, this.SEG_PRIO_CHAPTER_PREFETCH_BASE = 3e3, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
1612
+ super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = Bt$1, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
1619
1613
  }
1620
1614
  async initialize(e14) {
1621
1615
  if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? Bt$1, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
1622
- const { chapterId: t2 } = Nt$1(e15.id);
1616
+ const { chapterId: t2 } = Vt$1(e15.id);
1623
1617
  this.findChapter(t2) && (this.passwordAttempts.delete(t2), this.syncChapterStatusFromDocuments(t2));
1624
1618
  }), this.documentManager.provides().onDocumentClosed((e15) => {
1625
- const { chapterId: t2 } = Nt$1(e15);
1619
+ const { chapterId: t2 } = Vt$1(e15);
1626
1620
  this.findChapter(t2) && this.syncChapterStatusFromDocuments(t2);
1627
1621
  }), this.documentManager.provides().onDocumentError((e15) => {
1628
- const { chapterId: t2 } = Nt$1(e15.documentId);
1622
+ const { chapterId: t2 } = Vt$1(e15.documentId);
1629
1623
  this.findChapter(t2) && this.handleDocumentError(e15.documentId, t2, e15.code, e15.message);
1630
1624
  })), this.setManifestInternal(e14.manifest), e14.unloadTimeoutMs && e14.unloadTimeoutMs > 0) {
1631
1625
  const t2 = Math.max(5e3, Math.floor(e14.unloadTimeoutMs / 4));
@@ -1640,7 +1634,7 @@ const Kt$1 = class e3 extends BasePlugin {
1640
1634
  return s2 ? zt$1(s2, t2) : null;
1641
1635
  }, getSegmentPlan: (e14) => {
1642
1636
  const t2 = this.findChapter(e14);
1643
- return t2 ? Vt$1(t2) : null;
1637
+ return t2 ? Rt$1(t2) : null;
1644
1638
  }, isSegmentLoaded: (e14, t2) => this.isSegmentDocumentOpen(e14, t2), isSegmentLoadPending: (e14, t2) => this.isSegmentLoadPending(e14, t2), getChapterErrorMessage: (e14) => this.chapterErrorMessages.get(e14), getChapterStatus: (e14) => this.chapterStatus.get(e14) ?? "idle", getChapter: (e14) => this.findChapter(e14), onChapterStatusChange: this.statusChange$.on, onManifestChange: this.manifestChange$.on };
1645
1639
  }
1646
1640
  destroy() {
@@ -1672,7 +1666,7 @@ const Kt$1 = class e3 extends BasePlugin {
1672
1666
  s3.has(n10.chapterId) && t3.push(`Duplicate chapterId: ${n10.chapterId}`), s3.add(n10.chapterId);
1673
1667
  const [e15, r3] = n10.globalPageRange, [a3, i2] = n10.localPageRange;
1674
1668
  if (e15 > r3 && t3.push(`${n10.chapterId}: invalid globalPageRange [${e15},${r3}]`), a3 > i2 && t3.push(`${n10.chapterId}: invalid localPageRange [${a3},${i2}]`), r3 - e15 !== i2 - a3 && t3.push(`${n10.chapterId}: page-count mismatch (global ${r3 - e15 + 1} vs local ${i2 - a3 + 1})`), n10.ownedGlobalPages) for (const s4 of n10.ownedGlobalPages) (s4 < e15 || s4 > r3) && t3.push(`${n10.chapterId}: ownedGlobalPages contains ${s4} outside range`);
1675
- t3.push(...Gt$1(n10));
1669
+ t3.push(..._t$1(n10));
1676
1670
  }
1677
1671
  return t3;
1678
1672
  })(s2);
@@ -1680,7 +1674,7 @@ const Kt$1 = class e3 extends BasePlugin {
1680
1674
  const r2 = new Set(this.chapterStatus.keys()), a2 = new Set(s2.chapters.map((e14) => e14.chapterId));
1681
1675
  for (const e14 of r2) a2.has(e14) || (this.closeChapter(e14), this.chapterStatus.delete(e14), this.chapterErrorMessages.delete(e14), this.chapterUrlsCache.delete(e14), this.pendingChapterUrlsPromises.delete(e14));
1682
1676
  for (const e14 of s2.chapters) this.chapterStatus.has(e14.chapterId) || this.chapterStatus.set(e14.chapterId, "idle");
1683
- this.manifest = s2, this.lastVisibleIndicesKey = "", this.clearVisibleSegmentBacklog(), this.virtualPageMap = qt$1(s2, this.overlapStrategy), this.manifestChange$.emit({ manifest: s2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
1677
+ this.manifest = s2, this.lastVisibleIndicesKey = "", this.clearVisibleSegmentBacklog(), this.virtualPageMap = Ht$1(s2, this.overlapStrategy), this.manifestChange$.emit({ manifest: s2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
1684
1678
  }
1685
1679
  eagerPrefetchFromManifest() {
1686
1680
  const e14 = this.config.prefetchChapters ?? 0;
@@ -1698,7 +1692,7 @@ const Kt$1 = class e3 extends BasePlugin {
1698
1692
  }
1699
1693
  getSegmentPlanForChapter(e14) {
1700
1694
  const t2 = this.findChapter(e14);
1701
- return t2 ? Vt$1(t2) : null;
1695
+ return t2 ? Rt$1(t2) : null;
1702
1696
  }
1703
1697
  anySegmentOpen(e14) {
1704
1698
  const t2 = this.getSegmentPlanForChapter(e14), s2 = this.documentManager.provides();
@@ -1746,7 +1740,7 @@ const Kt$1 = class e3 extends BasePlugin {
1746
1740
  if (!e15) continue;
1747
1741
  const s2 = this.findChapter(e15.chapterId);
1748
1742
  if (!s2) continue;
1749
- const n9 = _t$1(s2, e15.localPageIndex);
1743
+ const n9 = Gt$1(s2, e15.localPageIndex);
1750
1744
  if (!this.isSegmentDocumentOpen(e15.chapterId, n9)) return true;
1751
1745
  }
1752
1746
  return false;
@@ -1757,13 +1751,22 @@ const Kt$1 = class e3 extends BasePlugin {
1757
1751
  clearVisibleSegmentBacklog() {
1758
1752
  this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0;
1759
1753
  }
1754
+ globalSegmentSortKey(e14, t2) {
1755
+ var s2;
1756
+ if (!this.virtualPageMap) return Number.MAX_SAFE_INTEGER;
1757
+ const n9 = this.findChapter(e14);
1758
+ if (!n9) return Number.MAX_SAFE_INTEGER;
1759
+ const r2 = Rt$1(n9), a2 = (null == (s2 = null == r2 ? void 0 : r2.segments[t2]) ? void 0 : s2.localPageStart) ?? 0, i2 = this.virtualPageMap.toGlobal(e14, a2);
1760
+ if (i2) return i2.globalPageIndex;
1761
+ return 1e4 * this.manifest.chapters.findIndex((t3) => t3.chapterId === e14) + t2;
1762
+ }
1760
1763
  scheduleVisibleSegmentLoads(e14) {
1761
- const t2 = /* @__PURE__ */ new Set(), s2 = [...e14].sort((e15, t3) => e15.priority - t3.priority);
1762
- for (const n9 of s2) {
1763
- const e15 = `${n9.chapterId}:${n9.segmentIndex}`;
1764
- t2.has(e15) || (t2.add(e15), this.isSegmentDocumentOpen(n9.chapterId, n9.segmentIndex) || this.isSegmentLoadPending(n9.chapterId, n9.segmentIndex) || this.visibleSegmentBacklog.push({ chapterId: n9.chapterId, segmentIndex: n9.segmentIndex }));
1764
+ const t2 = [...e14].sort((e15, t3) => e15.priority - t3.priority), s2 = /* @__PURE__ */ new Set(), n9 = [];
1765
+ for (const r2 of t2) {
1766
+ const e15 = `${r2.chapterId}:${r2.segmentIndex}`;
1767
+ s2.has(e15) || (s2.add(e15), this.isSegmentDocumentOpen(r2.chapterId, r2.segmentIndex) || this.isSegmentLoadPending(r2.chapterId, r2.segmentIndex) || n9.push({ chapterId: r2.chapterId, segmentIndex: r2.segmentIndex }));
1765
1768
  }
1766
- this.pumpVisibleSegmentBacklog();
1769
+ this.visibleSegmentBacklog = n9, this.pumpVisibleSegmentBacklog();
1767
1770
  }
1768
1771
  pumpVisibleSegmentBacklog() {
1769
1772
  const e14 = Math.max(1, this.config.maxConcurrentSegmentLoads ?? 2);
@@ -1782,53 +1785,41 @@ const Kt$1 = class e3 extends BasePlugin {
1782
1785
  const t2 = e14.join(","), s2 = this.visibleRangeNeedsSegmentLoad(e14);
1783
1786
  if (t2 === this.lastVisibleIndicesKey && !s2) return;
1784
1787
  this.lastVisibleIndicesKey = t2;
1785
- const n9 = Date.now(), r2 = this.config.prefetchChapters ?? 1, a2 = e14[Math.floor(e14.length / 2)] ?? e14[0], i2 = /* @__PURE__ */ new Set(), o2 = /* @__PURE__ */ new Map(), l = (e15, t3, s3) => {
1788
+ const n9 = Date.now(), r2 = e14[Math.floor(e14.length / 2)] ?? e14[0], a2 = /* @__PURE__ */ new Set(), i2 = /* @__PURE__ */ new Map(), o2 = (e15, t3) => {
1786
1789
  if (t3 < 0) return;
1787
- const n10 = this.findChapter(e15);
1788
- if (!n10) return;
1789
- const r3 = Vt$1(n10);
1790
- if (r3 && t3 >= r3.segments.length) return;
1791
- const a3 = `${e15}:${t3}`, i3 = o2.get(a3);
1792
- (void 0 === i3 || s3 < i3) && o2.set(a3, s3);
1790
+ const s3 = this.findChapter(e15);
1791
+ if (!s3) return;
1792
+ const n10 = Rt$1(s3);
1793
+ if (n10 && t3 >= n10.segments.length) return;
1794
+ const r3 = `${e15}:${t3}`, a3 = this.globalSegmentSortKey(e15, t3), o3 = i2.get(r3);
1795
+ (void 0 === o3 || a3 < o3) && i2.set(r3, a3);
1793
1796
  };
1794
- for (const p2 of e14) {
1795
- const e15 = this.virtualPageMap.atIndex(p2);
1797
+ for (const d2 of e14) {
1798
+ const e15 = this.virtualPageMap.atIndex(d2);
1796
1799
  if (!e15) continue;
1797
- i2.add(e15.chapterId);
1800
+ a2.add(e15.chapterId);
1798
1801
  const t3 = this.findChapter(e15.chapterId);
1799
1802
  if (!t3) continue;
1800
- const s3 = Math.abs(p2 - a2), n10 = _t$1(t3, e15.localPageIndex);
1801
- l(e15.chapterId, n10, s3), l(e15.chapterId, n10 + 1, s3 + this.SEG_PRIO_PREFETCH_NEXT), this.resolveChapterUrls(t3).catch(() => {
1803
+ const s3 = Gt$1(t3, e15.localPageIndex);
1804
+ o2(e15.chapterId, s3), this.resolveChapterUrls(t3).catch(() => {
1802
1805
  });
1803
1806
  }
1804
- if (0 === i2.size) return;
1805
- const h2 = this.manifest.chapters.map((e15) => e15.chapterId);
1806
- let d2 = 0;
1807
- const c2 = this.virtualPageMap.atIndex(a2);
1808
- if (c2) {
1809
- const e15 = h2.indexOf(c2.chapterId);
1810
- e15 >= 0 && (d2 = e15);
1811
- }
1812
- for (const p2 of i2) {
1813
- this.chapterLastUsed.set(p2, n9);
1814
- const e15 = h2.indexOf(p2);
1815
- if (-1 !== e15) for (let t3 = e15 - r2; t3 <= e15 + r2; t3++) {
1816
- if (t3 < 0 || t3 >= h2.length) continue;
1817
- const e16 = h2[t3];
1818
- this.chapterLastUsed.set(e16, n9);
1819
- const s3 = Math.abs(t3 - d2);
1820
- l(e16, 0, this.SEG_PRIO_CHAPTER_PREFETCH_BASE + 100 * s3);
1821
- const r3 = this.findChapter(e16);
1822
- r3 && this.resolveChapterUrls(r3).catch(() => {
1823
- });
1807
+ if (0 === a2.size) return;
1808
+ const l = this.virtualPageMap.atIndex(r2);
1809
+ if (l) {
1810
+ const e15 = this.findChapter(l.chapterId);
1811
+ if (e15) {
1812
+ const t3 = Gt$1(e15, l.localPageIndex);
1813
+ o2(l.chapterId, t3 + 1);
1824
1814
  }
1825
1815
  }
1826
- const u2 = [...o2.entries()].map(([e15, t3]) => {
1816
+ for (const d2 of a2) this.chapterLastUsed.set(d2, n9);
1817
+ const h2 = [...i2.entries()].map(([e15, t3]) => {
1827
1818
  const [s3, n10] = e15.split(":");
1828
1819
  return { chapterId: s3, segmentIndex: Number.parseInt(n10, 10), priority: t3 };
1829
1820
  }).filter((e15) => e15.chapterId && Number.isFinite(e15.segmentIndex));
1830
- if (this.scheduleVisibleSegmentLoads(u2), this.config.autoActivateOnLoad ?? 1) {
1831
- const e15 = this.virtualPageMap.atIndex(a2);
1821
+ if (this.scheduleVisibleSegmentLoads(h2), this.config.autoActivateOnLoad ?? 1) {
1822
+ const e15 = this.virtualPageMap.atIndex(r2);
1832
1823
  if (e15) {
1833
1824
  const t3 = zt$1(this.findChapter(e15.chapterId), e15.localPageIndex);
1834
1825
  if (this.documentManager.provides().isDocumentOpen(t3.documentId)) {
@@ -1866,7 +1857,7 @@ const Kt$1 = class e3 extends BasePlugin {
1866
1857
  this.prepareChapterForSegmentLoad(e14);
1867
1858
  const s2 = this.findChapter(e14);
1868
1859
  if (!s2) return Promise.resolve("error");
1869
- const n9 = Vt$1(s2);
1860
+ const n9 = Rt$1(s2);
1870
1861
  if (!n9) return 0 !== t2 ? Promise.resolve(this.isSegmentDocumentOpen(e14, 0) ? "loaded" : "error") : this.ensureSingleDocumentChapter(s2);
1871
1862
  if (t2 < 0 || t2 >= n9.segments.length) return Promise.resolve("error");
1872
1863
  const r2 = n9.segments[t2], a2 = r2.documentId;
@@ -1922,9 +1913,9 @@ const Kt$1 = class e3 extends BasePlugin {
1922
1913
  return (null == r2 ? void 0 : r2.openPdf) ? r2.openPdf(a2) : { url: n9 };
1923
1914
  }
1924
1915
  async resolvePdfPayload(t2, s2) {
1925
- const n9 = t2.source, r2 = this.config.chapterPdfLoader, a2 = Ot$1(t2);
1916
+ const n9 = t2.source, r2 = this.config.chapterPdfLoader, a2 = Nt$1(t2);
1926
1917
  if (a2) {
1927
- const n10 = At$1(Ut$1(t2), a2);
1918
+ const n10 = Ot$1(Tt$1(t2), a2);
1928
1919
  if (s2 < 0 || s2 >= n10) throw new Error(`Chapter "${t2.chapterId}" invalid segmentIndex ${s2} (expected 0..${n10 - 1})`);
1929
1920
  const r3 = await this.resolveChapterUrls(t2);
1930
1921
  if (r3.length !== n10) {
@@ -1983,7 +1974,7 @@ const Kt$1 = class e3 extends BasePlugin {
1983
1974
  async handleDocumentError(t2, s2, n9, r2) {
1984
1975
  if (this.pendingSegmentLoadPromises.has(t2)) return;
1985
1976
  if (n9 !== PdfErrorCode.Password) {
1986
- const e14 = this.getSegmentPlanForChapter(s2), { segmentIndex: n10 } = Nt$1(t2);
1977
+ const e14 = this.getSegmentPlanForChapter(s2), { segmentIndex: n10 } = Vt$1(t2);
1987
1978
  return void (e14 && 0 !== n10 && null !== n10 || this.updateStatus(s2, "error"));
1988
1979
  }
1989
1980
  if (!this.passwordProvider) return void this.updateStatus(s2, "password-required");
@@ -2004,7 +1995,7 @@ const Kt$1 = class e3 extends BasePlugin {
2004
1995
  });
2005
1996
  }
2006
1997
  closeChapter(e14) {
2007
- const t2 = this.findChapter(e14), s2 = this.documentManager.provides(), n9 = t2 ? Vt$1(t2) : null, r2 = (e15) => {
1998
+ const t2 = this.findChapter(e14), s2 = this.documentManager.provides(), n9 = t2 ? Rt$1(t2) : null, r2 = (e15) => {
2008
1999
  if (s2.isDocumentOpen(e15)) {
2009
2000
  s2.closeDocument(e15).wait(() => {
2010
2001
  }, () => {
@@ -2105,7 +2096,7 @@ function os(e14, t2) {
2105
2096
  const n9 = s2.segments.find((e15) => t2 >= e15.localPageStart && t2 <= e15.localPageEnd);
2106
2097
  return (null == n9 ? void 0 : n9.index) ?? Math.floor(t2 / s2.threshold);
2107
2098
  }
2108
- function ls(e14) {
2099
+ function ls$1(e14) {
2109
2100
  var t2;
2110
2101
  const s2 = ts(e14);
2111
2102
  if (!s2) return [];
@@ -2120,7 +2111,7 @@ function ls(e14) {
2120
2111
  return n9;
2121
2112
  }
2122
2113
  const hs$1 = { kind: "first-wins" };
2123
- function ds$1(e14, t2, s2) {
2114
+ function ds(e14, t2, s2) {
2124
2115
  if (1 === t2.length) return t2[0].chapterId;
2125
2116
  switch (s2.kind) {
2126
2117
  case "first-wins":
@@ -2183,7 +2174,7 @@ function us(e14, t2 = hs$1) {
2183
2174
  }
2184
2175
  }
2185
2176
  const n10 = /* @__PURE__ */ new Map();
2186
- for (const [r3, a3] of s3) n10.set(r3, ds$1(r3, a3, t3));
2177
+ for (const [r3, a3] of s3) n10.set(r3, ds(r3, a3, t3));
2187
2178
  return n10;
2188
2179
  })(e14, t2), n9 = /* @__PURE__ */ new Map();
2189
2180
  for (const o2 of e14.chapters) n9.set(o2.chapterId, o2);
@@ -2197,9 +2188,9 @@ function us(e14, t2 = hs$1) {
2197
2188
  }
2198
2189
  return new cs(a2);
2199
2190
  }
2200
- const ps$1 = class e4 extends BasePlugin {
2191
+ const gs$1 = class e4 extends BasePlugin {
2201
2192
  constructor(e14, t2) {
2202
- super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = hs$1, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.SEG_PRIO_PREFETCH_NEXT = 120, this.SEG_PRIO_CHAPTER_PREFETCH_BASE = 3e3, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
2193
+ super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = hs$1, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
2203
2194
  }
2204
2195
  async initialize(e14) {
2205
2196
  if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? hs$1, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
@@ -2256,7 +2247,7 @@ const ps$1 = class e4 extends BasePlugin {
2256
2247
  s3.has(n10.chapterId) && t3.push(`Duplicate chapterId: ${n10.chapterId}`), s3.add(n10.chapterId);
2257
2248
  const [e15, r3] = n10.globalPageRange, [a3, i2] = n10.localPageRange;
2258
2249
  if (e15 > r3 && t3.push(`${n10.chapterId}: invalid globalPageRange [${e15},${r3}]`), a3 > i2 && t3.push(`${n10.chapterId}: invalid localPageRange [${a3},${i2}]`), r3 - e15 !== i2 - a3 && t3.push(`${n10.chapterId}: page-count mismatch (global ${r3 - e15 + 1} vs local ${i2 - a3 + 1})`), n10.ownedGlobalPages) for (const s4 of n10.ownedGlobalPages) (s4 < e15 || s4 > r3) && t3.push(`${n10.chapterId}: ownedGlobalPages contains ${s4} outside range`);
2259
- t3.push(...ls(n10));
2250
+ t3.push(...ls$1(n10));
2260
2251
  }
2261
2252
  return t3;
2262
2253
  })(s2);
@@ -2341,13 +2332,22 @@ const ps$1 = class e4 extends BasePlugin {
2341
2332
  clearVisibleSegmentBacklog() {
2342
2333
  this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0;
2343
2334
  }
2335
+ globalSegmentSortKey(e14, t2) {
2336
+ var s2;
2337
+ if (!this.virtualPageMap) return Number.MAX_SAFE_INTEGER;
2338
+ const n9 = this.findChapter(e14);
2339
+ if (!n9) return Number.MAX_SAFE_INTEGER;
2340
+ const r2 = as(n9), a2 = (null == (s2 = null == r2 ? void 0 : r2.segments[t2]) ? void 0 : s2.localPageStart) ?? 0, i2 = this.virtualPageMap.toGlobal(e14, a2);
2341
+ if (i2) return i2.globalPageIndex;
2342
+ return 1e4 * this.manifest.chapters.findIndex((t3) => t3.chapterId === e14) + t2;
2343
+ }
2344
2344
  scheduleVisibleSegmentLoads(e14) {
2345
- const t2 = /* @__PURE__ */ new Set(), s2 = [...e14].sort((e15, t3) => e15.priority - t3.priority);
2346
- for (const n9 of s2) {
2347
- const e15 = `${n9.chapterId}:${n9.segmentIndex}`;
2348
- t2.has(e15) || (t2.add(e15), this.isSegmentDocumentOpen(n9.chapterId, n9.segmentIndex) || this.isSegmentLoadPending(n9.chapterId, n9.segmentIndex) || this.visibleSegmentBacklog.push({ chapterId: n9.chapterId, segmentIndex: n9.segmentIndex }));
2345
+ const t2 = [...e14].sort((e15, t3) => e15.priority - t3.priority), s2 = /* @__PURE__ */ new Set(), n9 = [];
2346
+ for (const r2 of t2) {
2347
+ const e15 = `${r2.chapterId}:${r2.segmentIndex}`;
2348
+ s2.has(e15) || (s2.add(e15), this.isSegmentDocumentOpen(r2.chapterId, r2.segmentIndex) || this.isSegmentLoadPending(r2.chapterId, r2.segmentIndex) || n9.push({ chapterId: r2.chapterId, segmentIndex: r2.segmentIndex }));
2349
2349
  }
2350
- this.pumpVisibleSegmentBacklog();
2350
+ this.visibleSegmentBacklog = n9, this.pumpVisibleSegmentBacklog();
2351
2351
  }
2352
2352
  pumpVisibleSegmentBacklog() {
2353
2353
  const e14 = Math.max(1, this.config.maxConcurrentSegmentLoads ?? 2);
@@ -2366,53 +2366,41 @@ const ps$1 = class e4 extends BasePlugin {
2366
2366
  const t2 = e14.join(","), s2 = this.visibleRangeNeedsSegmentLoad(e14);
2367
2367
  if (t2 === this.lastVisibleIndicesKey && !s2) return;
2368
2368
  this.lastVisibleIndicesKey = t2;
2369
- const n9 = Date.now(), r2 = this.config.prefetchChapters ?? 1, a2 = e14[Math.floor(e14.length / 2)] ?? e14[0], i2 = /* @__PURE__ */ new Set(), o2 = /* @__PURE__ */ new Map(), l = (e15, t3, s3) => {
2369
+ const n9 = Date.now(), r2 = e14[Math.floor(e14.length / 2)] ?? e14[0], a2 = /* @__PURE__ */ new Set(), i2 = /* @__PURE__ */ new Map(), o2 = (e15, t3) => {
2370
2370
  if (t3 < 0) return;
2371
- const n10 = this.findChapter(e15);
2372
- if (!n10) return;
2373
- const r3 = as(n10);
2374
- if (r3 && t3 >= r3.segments.length) return;
2375
- const a3 = `${e15}:${t3}`, i3 = o2.get(a3);
2376
- (void 0 === i3 || s3 < i3) && o2.set(a3, s3);
2371
+ const s3 = this.findChapter(e15);
2372
+ if (!s3) return;
2373
+ const n10 = as(s3);
2374
+ if (n10 && t3 >= n10.segments.length) return;
2375
+ const r3 = `${e15}:${t3}`, a3 = this.globalSegmentSortKey(e15, t3), o3 = i2.get(r3);
2376
+ (void 0 === o3 || a3 < o3) && i2.set(r3, a3);
2377
2377
  };
2378
- for (const p2 of e14) {
2379
- const e15 = this.virtualPageMap.atIndex(p2);
2378
+ for (const d2 of e14) {
2379
+ const e15 = this.virtualPageMap.atIndex(d2);
2380
2380
  if (!e15) continue;
2381
- i2.add(e15.chapterId);
2381
+ a2.add(e15.chapterId);
2382
2382
  const t3 = this.findChapter(e15.chapterId);
2383
2383
  if (!t3) continue;
2384
- const s3 = Math.abs(p2 - a2), n10 = os(t3, e15.localPageIndex);
2385
- l(e15.chapterId, n10, s3), l(e15.chapterId, n10 + 1, s3 + this.SEG_PRIO_PREFETCH_NEXT), this.resolveChapterUrls(t3).catch(() => {
2384
+ const s3 = os(t3, e15.localPageIndex);
2385
+ o2(e15.chapterId, s3), this.resolveChapterUrls(t3).catch(() => {
2386
2386
  });
2387
2387
  }
2388
- if (0 === i2.size) return;
2389
- const h2 = this.manifest.chapters.map((e15) => e15.chapterId);
2390
- let d2 = 0;
2391
- const c2 = this.virtualPageMap.atIndex(a2);
2392
- if (c2) {
2393
- const e15 = h2.indexOf(c2.chapterId);
2394
- e15 >= 0 && (d2 = e15);
2395
- }
2396
- for (const p2 of i2) {
2397
- this.chapterLastUsed.set(p2, n9);
2398
- const e15 = h2.indexOf(p2);
2399
- if (-1 !== e15) for (let t3 = e15 - r2; t3 <= e15 + r2; t3++) {
2400
- if (t3 < 0 || t3 >= h2.length) continue;
2401
- const e16 = h2[t3];
2402
- this.chapterLastUsed.set(e16, n9);
2403
- const s3 = Math.abs(t3 - d2);
2404
- l(e16, 0, this.SEG_PRIO_CHAPTER_PREFETCH_BASE + 100 * s3);
2405
- const r3 = this.findChapter(e16);
2406
- r3 && this.resolveChapterUrls(r3).catch(() => {
2407
- });
2388
+ if (0 === a2.size) return;
2389
+ const l = this.virtualPageMap.atIndex(r2);
2390
+ if (l) {
2391
+ const e15 = this.findChapter(l.chapterId);
2392
+ if (e15) {
2393
+ const t3 = os(e15, l.localPageIndex);
2394
+ o2(l.chapterId, t3 + 1);
2408
2395
  }
2409
2396
  }
2410
- const u2 = [...o2.entries()].map(([e15, t3]) => {
2397
+ for (const d2 of a2) this.chapterLastUsed.set(d2, n9);
2398
+ const h2 = [...i2.entries()].map(([e15, t3]) => {
2411
2399
  const [s3, n10] = e15.split(":");
2412
2400
  return { chapterId: s3, segmentIndex: Number.parseInt(n10, 10), priority: t3 };
2413
2401
  }).filter((e15) => e15.chapterId && Number.isFinite(e15.segmentIndex));
2414
- if (this.scheduleVisibleSegmentLoads(u2), this.config.autoActivateOnLoad ?? 1) {
2415
- const e15 = this.virtualPageMap.atIndex(a2);
2402
+ if (this.scheduleVisibleSegmentLoads(h2), this.config.autoActivateOnLoad ?? 1) {
2403
+ const e15 = this.virtualPageMap.atIndex(r2);
2416
2404
  if (e15) {
2417
2405
  const t3 = is(this.findChapter(e15.chapterId), e15.localPageIndex);
2418
2406
  if (this.documentManager.provides().isDocumentOpen(t3.documentId)) {
@@ -2604,8 +2592,8 @@ const ps$1 = class e4 extends BasePlugin {
2604
2592
  "error" === t2 && s2 ? this.chapterErrorMessages.set(e14, s2) : "loading" !== t2 && "loaded" !== t2 || this.chapterErrorMessages.delete(e14), n9 !== t2 && (this.chapterStatus.set(e14, t2), this.statusChange$.emit({ chapterId: e14, status: t2, ..."error" === t2 && s2 ? { error: { message: s2 } } : {} }));
2605
2593
  }
2606
2594
  };
2607
- ps$1.id = "chapter-manager";
2608
- let gs$1 = ps$1;
2595
+ gs$1.id = "chapter-manager";
2596
+ let ps$1 = gs$1;
2609
2597
  function ms$1(e14, t2) {
2610
2598
  if (e14 === t2) return true;
2611
2599
  if (e14.totalHeight !== t2.totalHeight || e14.totalWidth !== t2.totalWidth || e14.pageGap !== t2.pageGap || e14.items.length !== t2.items.length) return false;
@@ -2617,7 +2605,7 @@ function ms$1(e14, t2) {
2617
2605
  }
2618
2606
  const fs$1 = class fs extends BasePlugin {
2619
2607
  constructor(e14, t2) {
2620
- super(e14, t2), this.layoutChange$ = createBehaviorEmitter(void 0, ms$1), this.visibleChange$ = createBehaviorEmitter(), this.virtualPageMap = null, this.pageSizes = /* @__PURE__ */ new Map(), this.offsets = [], this.totalHeight = 0, this.totalWidth = 0, this.viewportEl = null, this.viewportObservers = null, this.currentVisible = [], this.currentGlobalPageIndex = 0, this.lastLoadIndicesKey = "", this.loadPushRaf = null, this.chapterManagerUnsubs = [], this.chapterManager = this.registry.getPlugin(gs$1.id), this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
2608
+ super(e14, t2), this.layoutChange$ = createBehaviorEmitter(void 0, ms$1), this.visibleChange$ = createBehaviorEmitter(), this.virtualPageMap = null, this.pageSizes = /* @__PURE__ */ new Map(), this.offsets = [], this.totalHeight = 0, this.totalWidth = 0, this.viewportEl = null, this.viewportObservers = null, this.currentVisible = [], this.currentGlobalPageIndex = 0, this.lastLoadIndicesKey = "", this.loadPushRaf = null, this.chapterManagerUnsubs = [], this.chapterManager = this.registry.getPlugin(ps$1.id), this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
2621
2609
  }
2622
2610
  async initialize(e14) {
2623
2611
  this.config = { placeholderPageHeight: e14.placeholderPageHeight ?? 1200, placeholderPageWidth: e14.placeholderPageWidth ?? 900, bufferSize: e14.bufferSize ?? 2, pageGap: e14.pageGap ?? 20 }, this.virtualPageMap = this.chapterManager.provides().getVirtualPageMap(), this.rebuildOffsets(), this.chapterManagerUnsubs.push(this.chapterManager.provides().onManifestChange(({ map: e15 }) => {
@@ -2951,7 +2939,7 @@ function bs(e14) {
2951
2939
  const t2 = e14[e14.length - 1];
2952
2940
  return { x: t2.origin.x + t2.size.width, y: t2.origin.y + t2.size.height };
2953
2941
  }
2954
- const Ss = { manifest: Tt$1, create: (e14) => new Is(Et$1, e14), reducer: (e14) => e14, initialState: {} }, Cs = "paragraph-bookmark", ys = { id: Cs, name: "Paragraph Bookmark Plugin", version: "0.1.0", provides: ["paragraph-bookmark"], requires: ["chapter-scroll", "chapter-manager"], optional: [], defaultConfig: {} };
2942
+ const Ss = { manifest: Ut$1, create: (e14) => new Is(Et$1, e14), reducer: (e14) => e14, initialState: {} }, Cs = "paragraph-bookmark", ys = { id: Cs, name: "Paragraph Bookmark Plugin", version: "0.1.0", provides: ["paragraph-bookmark"], requires: ["chapter-scroll", "chapter-manager"], optional: [], defaultConfig: {} };
2955
2943
  function ws(e14) {
2956
2944
  const [t2, s2] = e14.localPageRange;
2957
2945
  return s2 - t2 + 1;
@@ -2997,13 +2985,13 @@ function Es$1(e14, t2) {
2997
2985
  }
2998
2986
  return { documentId: n9.documentId, pageIndex: t2 - n9.localPageStart };
2999
2987
  }
3000
- function Ts$1(e14, t2) {
2988
+ function Us$1(e14, t2) {
3001
2989
  const s2 = Ds$1(e14);
3002
2990
  if (!s2) return 0;
3003
2991
  const n9 = s2.segments.find((e15) => t2 >= e15.localPageStart && t2 <= e15.localPageEnd);
3004
2992
  return (null == n9 ? void 0 : n9.index) ?? Math.floor(t2 / s2.threshold);
3005
2993
  }
3006
- function Us$1(e14) {
2994
+ function Ts$1(e14) {
3007
2995
  var t2;
3008
2996
  const s2 = xs(e14);
3009
2997
  if (!s2) return [];
@@ -3018,7 +3006,7 @@ function Us$1(e14) {
3018
3006
  return n9;
3019
3007
  }
3020
3008
  const Fs$1 = { kind: "first-wins" };
3021
- function Os$1(e14, t2, s2) {
3009
+ function Ns$1(e14, t2, s2) {
3022
3010
  if (1 === t2.length) return t2[0].chapterId;
3023
3011
  switch (s2.kind) {
3024
3012
  case "first-wins":
@@ -3036,7 +3024,7 @@ function Os$1(e14, t2, s2) {
3036
3024
  return s2.resolve(e14, t2);
3037
3025
  }
3038
3026
  }
3039
- let Rs$1 = class Rs {
3027
+ let As$1 = class As {
3040
3028
  constructor(e14) {
3041
3029
  this._pages = e14, this._byChapter = /* @__PURE__ */ new Map(), this._byGlobalNumber = /* @__PURE__ */ new Map();
3042
3030
  for (const t2 of e14) {
@@ -3070,7 +3058,7 @@ let Rs$1 = class Rs {
3070
3058
  return s2 ? this._pages.indexOf(s2) : -1;
3071
3059
  }
3072
3060
  };
3073
- function Ns$1(e14, t2 = Fs$1) {
3061
+ function Vs$1(e14, t2 = Fs$1) {
3074
3062
  const s2 = (function(e15, t3 = Fs$1) {
3075
3063
  const s3 = /* @__PURE__ */ new Map();
3076
3064
  for (const r3 of e15.chapters) {
@@ -3081,7 +3069,7 @@ function Ns$1(e14, t2 = Fs$1) {
3081
3069
  }
3082
3070
  }
3083
3071
  const n10 = /* @__PURE__ */ new Map();
3084
- for (const [r3, a3] of s3) n10.set(r3, Os$1(r3, a3, t3));
3072
+ for (const [r3, a3] of s3) n10.set(r3, Ns$1(r3, a3, t3));
3085
3073
  return n10;
3086
3074
  })(e14, t2), n9 = /* @__PURE__ */ new Map();
3087
3075
  for (const o2 of e14.chapters) n9.set(o2.chapterId, o2);
@@ -3093,11 +3081,11 @@ function Ns$1(e14, t2 = Fs$1) {
3093
3081
  const [r3] = t3.globalPageRange, [l] = t3.localPageRange, h2 = l + (o2 - r3);
3094
3082
  a2.push({ globalPageIndex: i2++, globalPageNumber: o2, chapterId: e15, localPageIndex: h2 });
3095
3083
  }
3096
- return new Rs$1(a2);
3084
+ return new As$1(a2);
3097
3085
  }
3098
- const As$1 = class e6 extends BasePlugin {
3086
+ const Os$1 = class e6 extends BasePlugin {
3099
3087
  constructor(e14, t2) {
3100
- super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = Fs$1, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.SEG_PRIO_PREFETCH_NEXT = 120, this.SEG_PRIO_CHAPTER_PREFETCH_BASE = 3e3, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
3088
+ super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = Fs$1, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
3101
3089
  }
3102
3090
  async initialize(e14) {
3103
3091
  if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? Fs$1, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
@@ -3154,7 +3142,7 @@ const As$1 = class e6 extends BasePlugin {
3154
3142
  s3.has(n10.chapterId) && t3.push(`Duplicate chapterId: ${n10.chapterId}`), s3.add(n10.chapterId);
3155
3143
  const [e15, r3] = n10.globalPageRange, [a3, i2] = n10.localPageRange;
3156
3144
  if (e15 > r3 && t3.push(`${n10.chapterId}: invalid globalPageRange [${e15},${r3}]`), a3 > i2 && t3.push(`${n10.chapterId}: invalid localPageRange [${a3},${i2}]`), r3 - e15 !== i2 - a3 && t3.push(`${n10.chapterId}: page-count mismatch (global ${r3 - e15 + 1} vs local ${i2 - a3 + 1})`), n10.ownedGlobalPages) for (const s4 of n10.ownedGlobalPages) (s4 < e15 || s4 > r3) && t3.push(`${n10.chapterId}: ownedGlobalPages contains ${s4} outside range`);
3157
- t3.push(...Us$1(n10));
3145
+ t3.push(...Ts$1(n10));
3158
3146
  }
3159
3147
  return t3;
3160
3148
  })(s2);
@@ -3162,7 +3150,7 @@ const As$1 = class e6 extends BasePlugin {
3162
3150
  const r2 = new Set(this.chapterStatus.keys()), a2 = new Set(s2.chapters.map((e14) => e14.chapterId));
3163
3151
  for (const e14 of r2) a2.has(e14) || (this.closeChapter(e14), this.chapterStatus.delete(e14), this.chapterErrorMessages.delete(e14), this.chapterUrlsCache.delete(e14), this.pendingChapterUrlsPromises.delete(e14));
3164
3152
  for (const e14 of s2.chapters) this.chapterStatus.has(e14.chapterId) || this.chapterStatus.set(e14.chapterId, "idle");
3165
- this.manifest = s2, this.lastVisibleIndicesKey = "", this.clearVisibleSegmentBacklog(), this.virtualPageMap = Ns$1(s2, this.overlapStrategy), this.manifestChange$.emit({ manifest: s2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
3153
+ this.manifest = s2, this.lastVisibleIndicesKey = "", this.clearVisibleSegmentBacklog(), this.virtualPageMap = Vs$1(s2, this.overlapStrategy), this.manifestChange$.emit({ manifest: s2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
3166
3154
  }
3167
3155
  eagerPrefetchFromManifest() {
3168
3156
  const e14 = this.config.prefetchChapters ?? 0;
@@ -3228,7 +3216,7 @@ const As$1 = class e6 extends BasePlugin {
3228
3216
  if (!e15) continue;
3229
3217
  const s2 = this.findChapter(e15.chapterId);
3230
3218
  if (!s2) continue;
3231
- const n9 = Ts$1(s2, e15.localPageIndex);
3219
+ const n9 = Us$1(s2, e15.localPageIndex);
3232
3220
  if (!this.isSegmentDocumentOpen(e15.chapterId, n9)) return true;
3233
3221
  }
3234
3222
  return false;
@@ -3239,13 +3227,22 @@ const As$1 = class e6 extends BasePlugin {
3239
3227
  clearVisibleSegmentBacklog() {
3240
3228
  this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0;
3241
3229
  }
3230
+ globalSegmentSortKey(e14, t2) {
3231
+ var s2;
3232
+ if (!this.virtualPageMap) return Number.MAX_SAFE_INTEGER;
3233
+ const n9 = this.findChapter(e14);
3234
+ if (!n9) return Number.MAX_SAFE_INTEGER;
3235
+ const r2 = Ds$1(n9), a2 = (null == (s2 = null == r2 ? void 0 : r2.segments[t2]) ? void 0 : s2.localPageStart) ?? 0, i2 = this.virtualPageMap.toGlobal(e14, a2);
3236
+ if (i2) return i2.globalPageIndex;
3237
+ return 1e4 * this.manifest.chapters.findIndex((t3) => t3.chapterId === e14) + t2;
3238
+ }
3242
3239
  scheduleVisibleSegmentLoads(e14) {
3243
- const t2 = /* @__PURE__ */ new Set(), s2 = [...e14].sort((e15, t3) => e15.priority - t3.priority);
3244
- for (const n9 of s2) {
3245
- const e15 = `${n9.chapterId}:${n9.segmentIndex}`;
3246
- t2.has(e15) || (t2.add(e15), this.isSegmentDocumentOpen(n9.chapterId, n9.segmentIndex) || this.isSegmentLoadPending(n9.chapterId, n9.segmentIndex) || this.visibleSegmentBacklog.push({ chapterId: n9.chapterId, segmentIndex: n9.segmentIndex }));
3240
+ const t2 = [...e14].sort((e15, t3) => e15.priority - t3.priority), s2 = /* @__PURE__ */ new Set(), n9 = [];
3241
+ for (const r2 of t2) {
3242
+ const e15 = `${r2.chapterId}:${r2.segmentIndex}`;
3243
+ s2.has(e15) || (s2.add(e15), this.isSegmentDocumentOpen(r2.chapterId, r2.segmentIndex) || this.isSegmentLoadPending(r2.chapterId, r2.segmentIndex) || n9.push({ chapterId: r2.chapterId, segmentIndex: r2.segmentIndex }));
3247
3244
  }
3248
- this.pumpVisibleSegmentBacklog();
3245
+ this.visibleSegmentBacklog = n9, this.pumpVisibleSegmentBacklog();
3249
3246
  }
3250
3247
  pumpVisibleSegmentBacklog() {
3251
3248
  const e14 = Math.max(1, this.config.maxConcurrentSegmentLoads ?? 2);
@@ -3264,53 +3261,41 @@ const As$1 = class e6 extends BasePlugin {
3264
3261
  const t2 = e14.join(","), s2 = this.visibleRangeNeedsSegmentLoad(e14);
3265
3262
  if (t2 === this.lastVisibleIndicesKey && !s2) return;
3266
3263
  this.lastVisibleIndicesKey = t2;
3267
- const n9 = Date.now(), r2 = this.config.prefetchChapters ?? 1, a2 = e14[Math.floor(e14.length / 2)] ?? e14[0], i2 = /* @__PURE__ */ new Set(), o2 = /* @__PURE__ */ new Map(), l = (e15, t3, s3) => {
3264
+ const n9 = Date.now(), r2 = e14[Math.floor(e14.length / 2)] ?? e14[0], a2 = /* @__PURE__ */ new Set(), i2 = /* @__PURE__ */ new Map(), o2 = (e15, t3) => {
3268
3265
  if (t3 < 0) return;
3269
- const n10 = this.findChapter(e15);
3270
- if (!n10) return;
3271
- const r3 = Ds$1(n10);
3272
- if (r3 && t3 >= r3.segments.length) return;
3273
- const a3 = `${e15}:${t3}`, i3 = o2.get(a3);
3274
- (void 0 === i3 || s3 < i3) && o2.set(a3, s3);
3266
+ const s3 = this.findChapter(e15);
3267
+ if (!s3) return;
3268
+ const n10 = Ds$1(s3);
3269
+ if (n10 && t3 >= n10.segments.length) return;
3270
+ const r3 = `${e15}:${t3}`, a3 = this.globalSegmentSortKey(e15, t3), o3 = i2.get(r3);
3271
+ (void 0 === o3 || a3 < o3) && i2.set(r3, a3);
3275
3272
  };
3276
- for (const p2 of e14) {
3277
- const e15 = this.virtualPageMap.atIndex(p2);
3273
+ for (const d2 of e14) {
3274
+ const e15 = this.virtualPageMap.atIndex(d2);
3278
3275
  if (!e15) continue;
3279
- i2.add(e15.chapterId);
3276
+ a2.add(e15.chapterId);
3280
3277
  const t3 = this.findChapter(e15.chapterId);
3281
3278
  if (!t3) continue;
3282
- const s3 = Math.abs(p2 - a2), n10 = Ts$1(t3, e15.localPageIndex);
3283
- l(e15.chapterId, n10, s3), l(e15.chapterId, n10 + 1, s3 + this.SEG_PRIO_PREFETCH_NEXT), this.resolveChapterUrls(t3).catch(() => {
3279
+ const s3 = Us$1(t3, e15.localPageIndex);
3280
+ o2(e15.chapterId, s3), this.resolveChapterUrls(t3).catch(() => {
3284
3281
  });
3285
3282
  }
3286
- if (0 === i2.size) return;
3287
- const h2 = this.manifest.chapters.map((e15) => e15.chapterId);
3288
- let d2 = 0;
3289
- const c2 = this.virtualPageMap.atIndex(a2);
3290
- if (c2) {
3291
- const e15 = h2.indexOf(c2.chapterId);
3292
- e15 >= 0 && (d2 = e15);
3293
- }
3294
- for (const p2 of i2) {
3295
- this.chapterLastUsed.set(p2, n9);
3296
- const e15 = h2.indexOf(p2);
3297
- if (-1 !== e15) for (let t3 = e15 - r2; t3 <= e15 + r2; t3++) {
3298
- if (t3 < 0 || t3 >= h2.length) continue;
3299
- const e16 = h2[t3];
3300
- this.chapterLastUsed.set(e16, n9);
3301
- const s3 = Math.abs(t3 - d2);
3302
- l(e16, 0, this.SEG_PRIO_CHAPTER_PREFETCH_BASE + 100 * s3);
3303
- const r3 = this.findChapter(e16);
3304
- r3 && this.resolveChapterUrls(r3).catch(() => {
3305
- });
3283
+ if (0 === a2.size) return;
3284
+ const l = this.virtualPageMap.atIndex(r2);
3285
+ if (l) {
3286
+ const e15 = this.findChapter(l.chapterId);
3287
+ if (e15) {
3288
+ const t3 = Us$1(e15, l.localPageIndex);
3289
+ o2(l.chapterId, t3 + 1);
3306
3290
  }
3307
3291
  }
3308
- const u2 = [...o2.entries()].map(([e15, t3]) => {
3292
+ for (const d2 of a2) this.chapterLastUsed.set(d2, n9);
3293
+ const h2 = [...i2.entries()].map(([e15, t3]) => {
3309
3294
  const [s3, n10] = e15.split(":");
3310
3295
  return { chapterId: s3, segmentIndex: Number.parseInt(n10, 10), priority: t3 };
3311
3296
  }).filter((e15) => e15.chapterId && Number.isFinite(e15.segmentIndex));
3312
- if (this.scheduleVisibleSegmentLoads(u2), this.config.autoActivateOnLoad ?? 1) {
3313
- const e15 = this.virtualPageMap.atIndex(a2);
3297
+ if (this.scheduleVisibleSegmentLoads(h2), this.config.autoActivateOnLoad ?? 1) {
3298
+ const e15 = this.virtualPageMap.atIndex(r2);
3314
3299
  if (e15) {
3315
3300
  const t3 = Es$1(this.findChapter(e15.chapterId), e15.localPageIndex);
3316
3301
  if (this.documentManager.provides().isDocumentOpen(t3.documentId)) {
@@ -3502,15 +3487,15 @@ const As$1 = class e6 extends BasePlugin {
3502
3487
  "error" === t2 && s2 ? this.chapterErrorMessages.set(e14, s2) : "loading" !== t2 && "loaded" !== t2 || this.chapterErrorMessages.delete(e14), n9 !== t2 && (this.chapterStatus.set(e14, t2), this.statusChange$.emit({ chapterId: e14, status: t2, ..."error" === t2 && s2 ? { error: { message: s2 } } : {} }));
3503
3488
  }
3504
3489
  };
3505
- As$1.id = "chapter-manager";
3506
- let Vs$1 = As$1;
3490
+ Os$1.id = "chapter-manager";
3491
+ let Rs$1 = Os$1;
3507
3492
  function zs$1(e14) {
3508
3493
  return !!e14 && "urls" in e14 && Array.isArray(e14.urls);
3509
3494
  }
3510
- function _s$1(e14, t2) {
3495
+ function Gs$1(e14, t2) {
3511
3496
  return `${e14}#s${t2}`;
3512
3497
  }
3513
- function Gs$1(e14) {
3498
+ function _s$1(e14) {
3514
3499
  const t2 = e14.lastIndexOf("#s");
3515
3500
  if (-1 === t2) return { chapterId: e14, segmentIndex: null };
3516
3501
  const s2 = e14.slice(0, t2), n9 = Number.parseInt(e14.slice(t2 + 2), 10);
@@ -3532,21 +3517,21 @@ function Bs$1(e14) {
3532
3517
  for (let i2 = 0; i2 < n9; i2++) {
3533
3518
  const n10 = i2 * t2, o2 = Math.min(n10 + t2 - 1, s2 - 1);
3534
3519
  if (n10 >= s2) break;
3535
- a2.push({ index: i2, url: (null == r2 ? void 0 : r2[i2]) ?? "", localPageStart: n10, localPageEnd: o2, documentId: _s$1(e14.chapterId, i2) });
3520
+ a2.push({ index: i2, url: (null == r2 ? void 0 : r2[i2]) ?? "", localPageStart: n10, localPageEnd: o2, documentId: Gs$1(e14.chapterId, i2) });
3536
3521
  }
3537
3522
  return { chapterId: e14.chapterId, threshold: t2, pageCount: s2, segments: a2 };
3538
3523
  }
3539
- function Hs$1(e14) {
3524
+ function Ws$1(e14) {
3540
3525
  const [t2, s2] = e14.localPageRange;
3541
3526
  return s2 - t2 + 1;
3542
3527
  }
3543
- function Ws(e14) {
3528
+ function qs$1(e14) {
3544
3529
  return !!e14 && "urls" in e14 && Array.isArray(e14.urls);
3545
3530
  }
3546
- function qs$1(e14) {
3531
+ function Hs(e14) {
3547
3532
  if (null != e14.segmentPageThreshold && e14.segmentPageThreshold > 0) return e14.segmentPageThreshold;
3548
3533
  const t2 = e14.source;
3549
- return Ws(t2) ? t2.segmentPageThreshold : null;
3534
+ return qs$1(t2) ? t2.segmentPageThreshold : null;
3550
3535
  }
3551
3536
  function Ks(e14, t2) {
3552
3537
  return `${e14}#s${t2}`;
@@ -3561,9 +3546,9 @@ function Xs(e14, t2) {
3561
3546
  return e14 <= 0 || t2 <= 0 ? 0 : Math.ceil(e14 / t2);
3562
3547
  }
3563
3548
  function Zs(e14) {
3564
- const t2 = qs$1(e14);
3549
+ const t2 = Hs(e14);
3565
3550
  if (!t2) return null;
3566
- const s2 = Hs$1(e14), n9 = Xs(s2, t2), r2 = Ws(e14.source) ? e14.source.urls : void 0, a2 = [];
3551
+ const s2 = Ws$1(e14), n9 = Xs(s2, t2), r2 = qs$1(e14.source) ? e14.source.urls : void 0, a2 = [];
3567
3552
  for (let i2 = 0; i2 < n9; i2++) {
3568
3553
  const n10 = i2 * t2, o2 = Math.min(n10 + t2 - 1, s2 - 1);
3569
3554
  if (n10 >= s2) break;
@@ -3589,12 +3574,12 @@ function Qs(e14, t2) {
3589
3574
  }
3590
3575
  function Js(e14) {
3591
3576
  var t2;
3592
- const s2 = qs$1(e14);
3577
+ const s2 = Hs(e14);
3593
3578
  if (!s2) return [];
3594
- const n9 = [], { chapterId: r2 } = e14, a2 = Hs$1(e14);
3579
+ const n9 = [], { chapterId: r2 } = e14, a2 = Ws$1(e14);
3595
3580
  s2 <= 0 && n9.push(`${r2}: segmentPageThreshold must be > 0`);
3596
3581
  const i2 = e14.source;
3597
- if (!Ws(i2)) return n9;
3582
+ if (!qs$1(i2)) return n9;
3598
3583
  0 === i2.urls.length && n9.push(`${r2}: source.urls must not be empty`);
3599
3584
  const o2 = Xs(a2, s2);
3600
3585
  i2.urls.length !== o2 && n9.push(`${r2}: source.urls.length (${i2.urls.length}) must equal ceil(pageCount/threshold) (${o2})`);
@@ -3681,7 +3666,7 @@ function nn(e14, t2 = en) {
3681
3666
  }
3682
3667
  const rn = class e7 extends BasePlugin {
3683
3668
  constructor(e14, t2) {
3684
- super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = en, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.SEG_PRIO_PREFETCH_NEXT = 120, this.SEG_PRIO_CHAPTER_PREFETCH_BASE = 3e3, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
3669
+ super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = en, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
3685
3670
  }
3686
3671
  async initialize(e14) {
3687
3672
  if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? en, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
@@ -3823,13 +3808,22 @@ const rn = class e7 extends BasePlugin {
3823
3808
  clearVisibleSegmentBacklog() {
3824
3809
  this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0;
3825
3810
  }
3811
+ globalSegmentSortKey(e14, t2) {
3812
+ var s2;
3813
+ if (!this.virtualPageMap) return Number.MAX_SAFE_INTEGER;
3814
+ const n9 = this.findChapter(e14);
3815
+ if (!n9) return Number.MAX_SAFE_INTEGER;
3816
+ const r2 = Zs(n9), a2 = (null == (s2 = null == r2 ? void 0 : r2.segments[t2]) ? void 0 : s2.localPageStart) ?? 0, i2 = this.virtualPageMap.toGlobal(e14, a2);
3817
+ if (i2) return i2.globalPageIndex;
3818
+ return 1e4 * this.manifest.chapters.findIndex((t3) => t3.chapterId === e14) + t2;
3819
+ }
3826
3820
  scheduleVisibleSegmentLoads(e14) {
3827
- const t2 = /* @__PURE__ */ new Set(), s2 = [...e14].sort((e15, t3) => e15.priority - t3.priority);
3828
- for (const n9 of s2) {
3829
- const e15 = `${n9.chapterId}:${n9.segmentIndex}`;
3830
- t2.has(e15) || (t2.add(e15), this.isSegmentDocumentOpen(n9.chapterId, n9.segmentIndex) || this.isSegmentLoadPending(n9.chapterId, n9.segmentIndex) || this.visibleSegmentBacklog.push({ chapterId: n9.chapterId, segmentIndex: n9.segmentIndex }));
3821
+ const t2 = [...e14].sort((e15, t3) => e15.priority - t3.priority), s2 = /* @__PURE__ */ new Set(), n9 = [];
3822
+ for (const r2 of t2) {
3823
+ const e15 = `${r2.chapterId}:${r2.segmentIndex}`;
3824
+ s2.has(e15) || (s2.add(e15), this.isSegmentDocumentOpen(r2.chapterId, r2.segmentIndex) || this.isSegmentLoadPending(r2.chapterId, r2.segmentIndex) || n9.push({ chapterId: r2.chapterId, segmentIndex: r2.segmentIndex }));
3831
3825
  }
3832
- this.pumpVisibleSegmentBacklog();
3826
+ this.visibleSegmentBacklog = n9, this.pumpVisibleSegmentBacklog();
3833
3827
  }
3834
3828
  pumpVisibleSegmentBacklog() {
3835
3829
  const e14 = Math.max(1, this.config.maxConcurrentSegmentLoads ?? 2);
@@ -3848,53 +3842,41 @@ const rn = class e7 extends BasePlugin {
3848
3842
  const t2 = e14.join(","), s2 = this.visibleRangeNeedsSegmentLoad(e14);
3849
3843
  if (t2 === this.lastVisibleIndicesKey && !s2) return;
3850
3844
  this.lastVisibleIndicesKey = t2;
3851
- const n9 = Date.now(), r2 = this.config.prefetchChapters ?? 1, a2 = e14[Math.floor(e14.length / 2)] ?? e14[0], i2 = /* @__PURE__ */ new Set(), o2 = /* @__PURE__ */ new Map(), l = (e15, t3, s3) => {
3845
+ const n9 = Date.now(), r2 = e14[Math.floor(e14.length / 2)] ?? e14[0], a2 = /* @__PURE__ */ new Set(), i2 = /* @__PURE__ */ new Map(), o2 = (e15, t3) => {
3852
3846
  if (t3 < 0) return;
3853
- const n10 = this.findChapter(e15);
3854
- if (!n10) return;
3855
- const r3 = Zs(n10);
3856
- if (r3 && t3 >= r3.segments.length) return;
3857
- const a3 = `${e15}:${t3}`, i3 = o2.get(a3);
3858
- (void 0 === i3 || s3 < i3) && o2.set(a3, s3);
3847
+ const s3 = this.findChapter(e15);
3848
+ if (!s3) return;
3849
+ const n10 = Zs(s3);
3850
+ if (n10 && t3 >= n10.segments.length) return;
3851
+ const r3 = `${e15}:${t3}`, a3 = this.globalSegmentSortKey(e15, t3), o3 = i2.get(r3);
3852
+ (void 0 === o3 || a3 < o3) && i2.set(r3, a3);
3859
3853
  };
3860
- for (const p2 of e14) {
3861
- const e15 = this.virtualPageMap.atIndex(p2);
3854
+ for (const d2 of e14) {
3855
+ const e15 = this.virtualPageMap.atIndex(d2);
3862
3856
  if (!e15) continue;
3863
- i2.add(e15.chapterId);
3857
+ a2.add(e15.chapterId);
3864
3858
  const t3 = this.findChapter(e15.chapterId);
3865
3859
  if (!t3) continue;
3866
- const s3 = Math.abs(p2 - a2), n10 = Qs(t3, e15.localPageIndex);
3867
- l(e15.chapterId, n10, s3), l(e15.chapterId, n10 + 1, s3 + this.SEG_PRIO_PREFETCH_NEXT), this.resolveChapterUrls(t3).catch(() => {
3860
+ const s3 = Qs(t3, e15.localPageIndex);
3861
+ o2(e15.chapterId, s3), this.resolveChapterUrls(t3).catch(() => {
3868
3862
  });
3869
3863
  }
3870
- if (0 === i2.size) return;
3871
- const h2 = this.manifest.chapters.map((e15) => e15.chapterId);
3872
- let d2 = 0;
3873
- const c2 = this.virtualPageMap.atIndex(a2);
3874
- if (c2) {
3875
- const e15 = h2.indexOf(c2.chapterId);
3876
- e15 >= 0 && (d2 = e15);
3877
- }
3878
- for (const p2 of i2) {
3879
- this.chapterLastUsed.set(p2, n9);
3880
- const e15 = h2.indexOf(p2);
3881
- if (-1 !== e15) for (let t3 = e15 - r2; t3 <= e15 + r2; t3++) {
3882
- if (t3 < 0 || t3 >= h2.length) continue;
3883
- const e16 = h2[t3];
3884
- this.chapterLastUsed.set(e16, n9);
3885
- const s3 = Math.abs(t3 - d2);
3886
- l(e16, 0, this.SEG_PRIO_CHAPTER_PREFETCH_BASE + 100 * s3);
3887
- const r3 = this.findChapter(e16);
3888
- r3 && this.resolveChapterUrls(r3).catch(() => {
3889
- });
3864
+ if (0 === a2.size) return;
3865
+ const l = this.virtualPageMap.atIndex(r2);
3866
+ if (l) {
3867
+ const e15 = this.findChapter(l.chapterId);
3868
+ if (e15) {
3869
+ const t3 = Qs(e15, l.localPageIndex);
3870
+ o2(l.chapterId, t3 + 1);
3890
3871
  }
3891
3872
  }
3892
- const u2 = [...o2.entries()].map(([e15, t3]) => {
3873
+ for (const d2 of a2) this.chapterLastUsed.set(d2, n9);
3874
+ const h2 = [...i2.entries()].map(([e15, t3]) => {
3893
3875
  const [s3, n10] = e15.split(":");
3894
3876
  return { chapterId: s3, segmentIndex: Number.parseInt(n10, 10), priority: t3 };
3895
3877
  }).filter((e15) => e15.chapterId && Number.isFinite(e15.segmentIndex));
3896
- if (this.scheduleVisibleSegmentLoads(u2), this.config.autoActivateOnLoad ?? 1) {
3897
- const e15 = this.virtualPageMap.atIndex(a2);
3878
+ if (this.scheduleVisibleSegmentLoads(h2), this.config.autoActivateOnLoad ?? 1) {
3879
+ const e15 = this.virtualPageMap.atIndex(r2);
3898
3880
  if (e15) {
3899
3881
  const t3 = Ys(this.findChapter(e15.chapterId), e15.localPageIndex);
3900
3882
  if (this.documentManager.provides().isDocumentOpen(t3.documentId)) {
@@ -3962,7 +3944,7 @@ const rn = class e7 extends BasePlugin {
3962
3944
  if (n9) return n9;
3963
3945
  const r2 = (async () => {
3964
3946
  const s3 = e14.source;
3965
- if (Ws(s3)) {
3947
+ if (qs$1(s3)) {
3966
3948
  const e15 = [...s3.urls];
3967
3949
  return this.chapterUrlsCache.set(t2, e15), e15;
3968
3950
  }
@@ -3988,9 +3970,9 @@ const rn = class e7 extends BasePlugin {
3988
3970
  return (null == r2 ? void 0 : r2.openPdf) ? r2.openPdf(a2) : { url: n9 };
3989
3971
  }
3990
3972
  async resolvePdfPayload(t2, s2) {
3991
- const n9 = t2.source, r2 = this.config.chapterPdfLoader, a2 = qs$1(t2);
3973
+ const n9 = t2.source, r2 = this.config.chapterPdfLoader, a2 = Hs(t2);
3992
3974
  if (a2) {
3993
- const n10 = Xs(Hs$1(t2), a2);
3975
+ const n10 = Xs(Ws$1(t2), a2);
3994
3976
  if (s2 < 0 || s2 >= n10) throw new Error(`Chapter "${t2.chapterId}" invalid segmentIndex ${s2} (expected 0..${n10 - 1})`);
3995
3977
  const r3 = await this.resolveChapterUrls(t2);
3996
3978
  if (r3.length !== n10) {
@@ -4001,7 +3983,7 @@ const rn = class e7 extends BasePlugin {
4001
3983
  }
4002
3984
  if (0 !== s2) throw new Error(`Chapter "${t2.chapterId}" is not segmented`);
4003
3985
  if (n9) {
4004
- if (Ws(n9)) {
3986
+ if (qs$1(n9)) {
4005
3987
  const e14 = await this.resolveChapterUrls(t2);
4006
3988
  return this.openPayloadFromUrl(t2, s2, e14);
4007
3989
  }
@@ -4145,14 +4127,14 @@ const ln = class extends BasePlugin {
4145
4127
  }
4146
4128
  onDocumentLoaded(e14) {
4147
4129
  var t2;
4148
- const { chapterId: s2 } = Gs$1(e14);
4130
+ const { chapterId: s2 } = _s$1(e14);
4149
4131
  if (0 === ((null == (t2 = this.virtualPageMap) ? void 0 : t2.pagesOfChapter(s2).length) ?? 0)) return;
4150
4132
  const n9 = this.documentManager.provides();
4151
4133
  n9.getActiveDocumentId() || n9.setActiveDocument(e14), this.harvestChapterSizes(s2), this.refreshLayout(), this.lastLoadIndicesKey = "", this.schedulePushVisibleLoads();
4152
4134
  }
4153
4135
  onDocumentClosed(e14) {
4154
4136
  var t2;
4155
- const { chapterId: s2 } = Gs$1(e14);
4137
+ const { chapterId: s2 } = _s$1(e14);
4156
4138
  0 !== ((null == (t2 = this.virtualPageMap) ? void 0 : t2.pagesOfChapter(s2).length) ?? 0) && (this.dropChapterSizes(s2), this.refreshLayout());
4157
4139
  }
4158
4140
  buildCapability() {
@@ -4226,7 +4208,7 @@ const ln = class extends BasePlugin {
4226
4208
  onScaleChanged(e14) {
4227
4209
  const t2 = this.coreState.core.documents[e14];
4228
4210
  if (!t2 || "loaded" !== t2.status) return;
4229
- const { chapterId: s2 } = Gs$1(e14);
4211
+ const { chapterId: s2 } = _s$1(e14);
4230
4212
  this.chapterManager.provides().getChapter(s2) && this.harvestChapterSizes(s2);
4231
4213
  }
4232
4214
  dropChapterSizes(e14) {
@@ -4334,7 +4316,7 @@ function un(e14, t2) {
4334
4316
  if (i2 <= 0) return 0;
4335
4317
  return Math.max(0, Math.min(n9, a2) - Math.max(s2, r2)) / i2;
4336
4318
  }
4337
- function pn(e14, t2) {
4319
+ function gn(e14, t2) {
4338
4320
  var s2, n9;
4339
4321
  if (e14.chapterId !== t2.chapterId || e14.localPageIndex !== t2.localPageIndex) return false;
4340
4322
  const r2 = (null == (s2 = e14.rectsPdfCoord) ? void 0 : s2.length) ? e14.rectsPdfCoord : [e14.rectPdfCoord], a2 = (null == (n9 = t2.rectsPdfCoord) ? void 0 : n9.length) ? t2.rectsPdfCoord : [t2.rectPdfCoord], i2 = e14.markerAnchor ?? cn(r2), o2 = t2.markerAnchor ?? cn(a2);
@@ -4346,7 +4328,7 @@ function pn(e14, t2) {
4346
4328
  }
4347
4329
  return false;
4348
4330
  }
4349
- function gn(e14, t2, s2, n9) {
4331
+ function pn(e14, t2, s2, n9) {
4350
4332
  const r2 = s2.length > 0 ? s2 : [];
4351
4333
  if (0 === r2.length) throw new Error("buildParagraphBookmarkAnchor: no rects");
4352
4334
  return { chapterId: e14, localPageIndex: t2, globalPageIndex: null == n9 ? void 0 : n9.globalPageIndex, globalPageNumber: null == n9 ? void 0 : n9.globalPageNumber, rectPdfCoord: dn(r2), rectsPdfCoord: r2, markerAnchor: cn(r2) };
@@ -4366,7 +4348,7 @@ async function mn(e14, t2, s2) {
4366
4348
  }
4367
4349
  const fn = class e8 extends BasePlugin {
4368
4350
  constructor(e14, t2) {
4369
- super(e14, t2), this.change$ = createBehaviorEmitter([]), this.entries = /* @__PURE__ */ new Map(), this.chapterScroll = this.registry.getPlugin(hn.id), this.chapterManager = this.registry.getPlugin(Vs$1.id), this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
4351
+ super(e14, t2), this.change$ = createBehaviorEmitter([]), this.entries = /* @__PURE__ */ new Map(), this.chapterScroll = this.registry.getPlugin(hn.id), this.chapterManager = this.registry.getPlugin(Rs$1.id), this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
4370
4352
  }
4371
4353
  async initialize(t2) {
4372
4354
  var s2;
@@ -4382,7 +4364,7 @@ const fn = class e8 extends BasePlugin {
4382
4364
  return { addBookmark: (e14) => this.addBookmark(e14), removeBookmark: (e14) => this.removeBookmark(e14), updateBookmark: (e14, t2) => this.updateBookmark(e14, t2), listBookmarks: () => this.list(), getBookmark: (e14) => this.entries.get(e14) ?? null, scrollToBookmark: (e14) => this.scrollToBookmark(e14), requestRemoveBookmark: (e14) => this.requestRemoveBookmark(e14), listBookmarksForChapter: (e14) => this.listBookmarksForChapter(e14), replaceBookmarksForChapter: (e14, t2) => this.replaceBookmarksForChapter(e14, t2), onBookmarksChange: this.change$.on };
4383
4365
  }
4384
4366
  addBookmark(e14) {
4385
- for (const n9 of this.entries.values()) if (pn(n9.anchor, e14.anchor)) return n9;
4367
+ for (const n9 of this.entries.values()) if (gn(n9.anchor, e14.anchor)) return n9;
4386
4368
  const t2 = e14.id ?? `bm-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`, s2 = { id: t2, label: e14.label, anchor: e14.anchor, metadata: e14.metadata, createdAt: Date.now() };
4387
4369
  return this.entries.set(t2, s2), this.notifyAndPersist(), s2;
4388
4370
  }
@@ -4542,27 +4524,27 @@ const xn = ke$1(), Ln = {};
4542
4524
  function $n(e14) {
4543
4525
  return wn({ ...e14, toolbar: e14.toolbar ?? { enabledModes: [] }, features: ke$1(e14.features) });
4544
4526
  }
4545
- const kn = { overlapStrategy: { kind: "first-wins" }, passwordProvider: new Fe$1(async () => null), prefetchChapters: 1, maxConcurrentSegmentLoads: 2, loadDefaultStampLibrary: false, unloadTimeoutMs: 12e4, toolbar: { enabledModes: [] } };
4527
+ const kn = { overlapStrategy: { kind: "first-wins" }, passwordProvider: new Fe$1(async () => null), prefetchChapters: 1, maxConcurrentSegmentLoads: 1, loadDefaultStampLibrary: false, unloadTimeoutMs: 12e4, toolbar: { enabledModes: [] } };
4546
4528
  function Dn(e14) {
4547
4529
  return (function(e15) {
4548
4530
  return "callbacks" in e15.notes;
4549
4531
  })(e14) ? { manifest: e14.manifest, chapterPdfLoader: e14.chapterPdfLoader, notes: e14.notes.callbacks, bookmarks: e14.bookmarks.callbacks } : e14;
4550
4532
  }
4551
4533
  function En(e14) {
4552
- return { ...kn, manifest: e14.manifest, chapterPdfLoader: e14.chapterPdfLoader, overlapStrategy: e14.overlapStrategy ?? kn.overlapStrategy, notes: { callbacks: e14.notes }, bookmarks: { callbacks: e14.bookmarks }, features: ke$1(e14.features) };
4534
+ return { ...kn, manifest: e14.manifest, chapterPdfLoader: e14.chapterPdfLoader, overlapStrategy: e14.overlapStrategy ?? kn.overlapStrategy, prefetchChapters: e14.prefetchChapters ?? kn.prefetchChapters, maxConcurrentSegmentLoads: e14.maxConcurrentSegmentLoads ?? kn.maxConcurrentSegmentLoads, unloadTimeoutMs: e14.unloadTimeoutMs ?? kn.unloadTimeoutMs, notes: { callbacks: e14.notes }, bookmarks: { callbacks: e14.bookmarks }, features: ke$1(e14.features) };
4553
4535
  }
4554
- function Tn(e14) {
4536
+ function Un(e14) {
4555
4537
  const t2 = En(Dn(e14)), { plugins: s2 } = $n(t2);
4556
4538
  return { plugins: s2, features: t2.features, editorOptions: t2 };
4557
4539
  }
4558
- function Un(e14) {
4540
+ function Tn(e14) {
4559
4541
  const { features: t2, ...s2 } = En(Dn(e14));
4560
4542
  return s2;
4561
4543
  }
4562
4544
  function Fn(e14, t2 = 0.5, s2 = 3) {
4563
4545
  return Math.min(s2, Math.max(t2, e14));
4564
4546
  }
4565
- function On(e14, t2) {
4547
+ function Nn(e14, t2) {
4566
4548
  var _a2;
4567
4549
  if (t2 <= 0) return 1;
4568
4550
  let s2 = 0;
@@ -4572,17 +4554,17 @@ function On(e14, t2) {
4572
4554
  }
4573
4555
  return s2 <= 0 ? 1 : t2 / s2;
4574
4556
  }
4575
- function Rn(e14, t2) {
4557
+ function An(e14, t2) {
4576
4558
  return e14 <= 0 ? t2 ?? 0 : null == t2 || t2 <= 0 ? e14 : Math.min(t2, e14);
4577
4559
  }
4578
- function Nn(e14, t2, s2, n9) {
4579
- const r2 = Rn(t2, s2);
4560
+ function Vn(e14, t2, s2, n9) {
4561
+ const r2 = An(t2, s2);
4580
4562
  if (r2 <= 0) return n9;
4581
- const a2 = On(e14, r2);
4563
+ const a2 = Nn(e14, r2);
4582
4564
  return Math.min(n9, a2);
4583
4565
  }
4584
- function An(e14, t2, s2) {
4585
- const n9 = Te$1(t2);
4566
+ function On(e14, t2, s2) {
4567
+ const n9 = Ue$1(t2);
4586
4568
  if (n9) {
4587
4569
  for (const t3 of n9.segments) {
4588
4570
  const n10 = e14.getDocument(t3.documentId);
@@ -4593,11 +4575,11 @@ function An(e14, t2, s2) {
4593
4575
  const r2 = e14.getDocument(t2.chapterId);
4594
4576
  r2 && s2(r2, t2.chapterId);
4595
4577
  }
4596
- function Vn(e14) {
4578
+ function Rn(e14) {
4597
4579
  return e14 instanceof HTMLElement ? e14.clientWidth : 0;
4598
4580
  }
4599
4581
  function zn(a2, i2, o2) {
4600
- const l = isRef(a2) ? a2 : computed(() => a2), { registry: h2 } = useRegistry(), { provides: d2 } = useCapability(DocumentManagerPlugin.id), { provides: c2 } = useCapability(nt$1.id), u2 = ref(P2()), p2 = ref(u2.value), g2 = ref(0), m2 = ref(false), f2 = () => {
4582
+ const l = isRef(a2) ? a2 : computed(() => a2), { registry: h2 } = useRegistry(), { provides: d2 } = useCapability(DocumentManagerPlugin.id), { provides: c2 } = useCapability(nt$1.id), u2 = ref(P2()), g2 = ref(u2.value), p2 = ref(0), m2 = ref(false), f2 = () => {
4601
4583
  var _a2;
4602
4584
  return (_a2 = i2.value) == null ? void 0 : _a2.pageWidth;
4603
4585
  }, v = () => (function(e14) {
@@ -4610,11 +4592,11 @@ function zn(a2, i2, o2) {
4610
4592
  return (function(e14, t2, s2, n9, r2) {
4611
4593
  if (!e14 || s2 <= 0) return r2;
4612
4594
  let a3 = r2;
4613
- for (const i3 of t2.chapters) An(e14, i3, (e15) => {
4614
- a3 = Math.min(a3, Nn(e15, s2, n9, r2));
4595
+ for (const i3 of t2.chapters) On(e14, i3, (e15) => {
4596
+ a3 = Math.min(a3, Vn(e15, s2, n9, r2));
4615
4597
  });
4616
4598
  return a3;
4617
- })(d2.value, l.value, g2.value, f2(), ((_a2 = i2.value) == null ? void 0 : _a2.max) ?? 3);
4599
+ })(d2.value, l.value, p2.value, f2(), ((_a2 = i2.value) == null ? void 0 : _a2.max) ?? 3);
4618
4600
  }), b2 = computed(() => {
4619
4601
  var _a2;
4620
4602
  return Math.min(((_a2 = i2.value) == null ? void 0 : _a2.min) ?? 0.5, I2.value);
@@ -4622,13 +4604,13 @@ function zn(a2, i2, o2) {
4622
4604
  let S;
4623
4605
  function C2(e14) {
4624
4606
  const t2 = I2.value, s2 = b2.value, n9 = Fn(e14, s2, t2);
4625
- p2.value = n9, u2.value = n9, (function(e15, t3, s3, n10 = 0.5, r2 = 3) {
4607
+ g2.value = n9, u2.value = n9, (function(e15, t3, s3, n10 = 0.5, r2 = 3) {
4626
4608
  const a3 = e15 == null ? void 0 : e15.getStore();
4627
4609
  if (!a3) return;
4628
4610
  const i3 = Fn(s3, n10, r2);
4629
4611
  a3.dispatchToCore(setDefaultScale(i3));
4630
4612
  for (const o3 of t3.chapters) {
4631
- const e16 = Te$1(o3);
4613
+ const e16 = Ue$1(o3);
4632
4614
  if (e16) for (const t4 of e16.segments) a3.getState().core.documents[t4.documentId] && a3.dispatchToCore(setScale(i3, t4.documentId));
4633
4615
  else a3.getState().core.documents[o3.chapterId] && a3.dispatchToCore(setScale(i3, o3.chapterId));
4634
4616
  }
@@ -4638,12 +4620,12 @@ function zn(a2, i2, o2) {
4638
4620
  if (!d2.value || !c2.value) return;
4639
4621
  const t2 = c2.value.resolvePageDocument(e14, 0), s2 = d2.value.getDocument(t2.documentId);
4640
4622
  if (!s2) return;
4641
- const n9 = Rn(g2.value, f2());
4642
- n9 <= 0 || C2(On(s2, n9));
4623
+ const n9 = An(p2.value, f2());
4624
+ n9 <= 0 || C2(Nn(s2, n9));
4643
4625
  }
4644
4626
  function x(e14) {
4645
4627
  if (!m2.value) return v() ? y(e14) : C2(P2()), void (m2.value = true);
4646
- C2(p2.value);
4628
+ C2(g2.value);
4647
4629
  }
4648
4630
  return watch(() => o2 == null ? void 0 : o2.value, (e14) => {
4649
4631
  S == null ? void 0 : S(), S = e14 ? (function(e15, t2) {
@@ -4651,10 +4633,10 @@ function zn(a2, i2, o2) {
4651
4633
  };
4652
4634
  let s2 = null;
4653
4635
  const n9 = new ResizeObserver(() => {
4654
- t2(Vn(s2));
4636
+ t2(Rn(s2));
4655
4637
  }), r2 = () => {
4656
4638
  const r3 = e15.querySelector("[data-chapter-scroll-viewport]");
4657
- r3 !== s2 ? (s2 && n9.unobserve(s2), s2 = r3, s2 ? (n9.observe(s2), t2(Vn(s2))) : t2(0)) : t2(Vn(s2));
4639
+ r3 !== s2 ? (s2 && n9.unobserve(s2), s2 = r3, s2 ? (n9.observe(s2), t2(Rn(s2))) : t2(0)) : t2(Rn(s2));
4658
4640
  };
4659
4641
  r2();
4660
4642
  const a3 = new MutationObserver(r2);
@@ -4664,12 +4646,12 @@ function zn(a2, i2, o2) {
4664
4646
  cancelAnimationFrame(i3), a3.disconnect(), s2 && n9.unobserve(s2), n9.disconnect();
4665
4647
  };
4666
4648
  })(e14, (e15) => {
4667
- g2.value = e15;
4649
+ p2.value = e15;
4668
4650
  }) : void 0;
4669
4651
  }, { immediate: true }), onBeforeUnmount(() => S == null ? void 0 : S()), watch([h2, () => P2(), () => v()], () => {
4670
4652
  h2.value && (v() || C2(P2()));
4671
4653
  }, { immediate: true }), watch(I2, (e14) => {
4672
- p2.value > e14 && C2(e14);
4654
+ g2.value > e14 && C2(e14);
4673
4655
  }), watch([c2, l, () => v(), () => P2()], () => {
4674
4656
  const e14 = c2.value;
4675
4657
  if (e14) {
@@ -4681,10 +4663,10 @@ function zn(a2, i2, o2) {
4681
4663
  }, { immediate: true }), watch(d2, (e14, t2, s2) => {
4682
4664
  if (!e14) return;
4683
4665
  s2(e14.onDocumentOpened(() => {
4684
- m2.value && C2(p2.value);
4666
+ m2.value && C2(g2.value);
4685
4667
  }));
4686
- }), watch([g2, () => v(), c2, l], () => {
4687
- if (v() && !(g2.value <= 0) && c2.value && !m2.value) {
4668
+ }), watch([p2, () => v(), c2, l], () => {
4669
+ if (v() && !(p2.value <= 0) && c2.value && !m2.value) {
4688
4670
  for (const e14 of l.value.chapters) if ("loaded" === c2.value.getChapterStatus(e14.chapterId)) {
4689
4671
  y(e14.chapterId), m2.value = true;
4690
4672
  break;
@@ -4695,10 +4677,10 @@ function zn(a2, i2, o2) {
4695
4677
  return false !== ((_a2 = i2.value) == null ? void 0 : _a2.enabled);
4696
4678
  }, minZoom: b2, maxZoom: I2 };
4697
4679
  }
4698
- function _n(e14, t2, s2) {
4680
+ function Gn(e14, t2, s2) {
4699
4681
  return Math.min(s2, Math.max(t2, e14));
4700
4682
  }
4701
- function Gn(e14, t2) {
4683
+ function _n(e14, t2) {
4702
4684
  if (!e14 || false === t2.enabled) return () => {
4703
4685
  };
4704
4686
  let s2 = null, n9 = null, r2 = 0;
@@ -4707,7 +4689,7 @@ function Gn(e14, t2) {
4707
4689
  return !!n10 && (s2 == null ? void 0 : s2(), s2 = (function({ container: e15, getScale: t3, setScale: s3, minZoom: n11 = 0.5, maxZoom: r3 = 3 }) {
4708
4690
  let a3 = 0, i2 = 1, o2 = null, l = 1, h2 = 1;
4709
4691
  const d2 = (e16) => {
4710
- (e16.ctrlKey || e16.metaKey) && (e16.preventDefault(), null === o2 ? (h2 = t3(), l = 1) : clearTimeout(o2), l *= 1 - 0.01 * e16.deltaY, l = _n(l, 0.1, 10), s3(_n(h2 * l, n11, r3)), o2 = setTimeout(() => {
4692
+ (e16.ctrlKey || e16.metaKey) && (e16.preventDefault(), null === o2 ? (h2 = t3(), l = 1) : clearTimeout(o2), l *= 1 - 0.01 * e16.deltaY, l = Gn(l, 0.1, 10), s3(Gn(h2 * l, n11, r3)), o2 = setTimeout(() => {
4711
4693
  o2 = null;
4712
4694
  }, 120));
4713
4695
  }, c2 = /* @__PURE__ */ new Map(), u2 = (e16) => {
@@ -4715,17 +4697,17 @@ function Gn(e14, t2) {
4715
4697
  const [e17, s4] = [...c2.values()];
4716
4698
  a3 = Math.hypot(s4.x - e17.x, s4.y - e17.y), i2 = t3();
4717
4699
  }
4718
- }, p2 = (e16) => {
4700
+ }, g2 = (e16) => {
4719
4701
  if (c2.has(e16.pointerId) && (c2.set(e16.pointerId, { x: e16.clientX, y: e16.clientY }), 2 === c2.size && a3 > 0)) {
4720
4702
  e16.preventDefault();
4721
4703
  const [t4, o3] = [...c2.values()], l2 = Math.hypot(o3.x - t4.x, o3.y - t4.y);
4722
- s3(_n(i2 * (l2 / a3), n11, r3));
4704
+ s3(Gn(i2 * (l2 / a3), n11, r3));
4723
4705
  }
4724
- }, g2 = (e16) => {
4706
+ }, p2 = (e16) => {
4725
4707
  c2.delete(e16.pointerId), c2.size < 2 && (a3 = 0);
4726
4708
  };
4727
- return e15.addEventListener("wheel", d2, { passive: false }), e15.addEventListener("pointerdown", u2), e15.addEventListener("pointermove", p2, { passive: false }), e15.addEventListener("pointerup", g2), e15.addEventListener("pointercancel", g2), () => {
4728
- e15.removeEventListener("wheel", d2), e15.removeEventListener("pointerdown", u2), e15.removeEventListener("pointermove", p2), e15.removeEventListener("pointerup", g2), e15.removeEventListener("pointercancel", g2), o2 && clearTimeout(o2);
4709
+ return e15.addEventListener("wheel", d2, { passive: false }), e15.addEventListener("pointerdown", u2), e15.addEventListener("pointermove", g2, { passive: false }), e15.addEventListener("pointerup", p2), e15.addEventListener("pointercancel", p2), () => {
4710
+ e15.removeEventListener("wheel", d2), e15.removeEventListener("pointerdown", u2), e15.removeEventListener("pointermove", g2), e15.removeEventListener("pointerup", p2), e15.removeEventListener("pointercancel", p2), o2 && clearTimeout(o2);
4729
4711
  };
4730
4712
  })({ container: n10, getScale: t2.getScale, setScale: t2.setScale, minZoom: t2.minZoom, maxZoom: t2.maxZoom }), true);
4731
4713
  };
@@ -4736,27 +4718,27 @@ function Gn(e14, t2) {
4736
4718
  };
4737
4719
  }
4738
4720
  const Bn = { chapters: [] };
4739
- function Hn(e14) {
4721
+ function Wn(e14) {
4740
4722
  const a2 = ref(null), { provides: i2 } = useCapability(nt$1.id), o2 = computed(() => {
4741
4723
  var _a2;
4742
4724
  return ((_a2 = i2.value) == null ? void 0 : _a2.getManifest()) ?? Bn;
4743
4725
  }), l = computed(() => {
4744
4726
  var _a2;
4745
4727
  return (_a2 = e14.value) == null ? void 0 : _a2.zoom;
4746
- }), { scale: h2, setScale: d2, zoomEnabled: c2, minZoom: u2, maxZoom: p2 } = zn(o2, l, a2);
4728
+ }), { scale: h2, setScale: d2, zoomEnabled: c2, minZoom: u2, maxZoom: g2 } = zn(o2, l, a2);
4747
4729
  return (function(e15, t2) {
4748
4730
  let s2 = null;
4749
4731
  watch([e15, t2], () => {
4750
4732
  s2 == null ? void 0 : s2();
4751
4733
  const n9 = t2.value;
4752
- s2 = Gn(e15.value ?? null, { enabled: n9.enabled, getScale: n9.getScale, setScale: n9.setScale, minZoom: n9.minZoom, maxZoom: n9.maxZoom });
4734
+ s2 = _n(e15.value ?? null, { enabled: n9.enabled, getScale: n9.getScale, setScale: n9.setScale, minZoom: n9.minZoom, maxZoom: n9.maxZoom });
4753
4735
  }, { deep: true, flush: "post" }), onBeforeUnmount(() => s2 == null ? void 0 : s2());
4754
- })(a2, computed(() => ({ enabled: c2(), getScale: () => h2.value, setScale: d2, minZoom: u2.value, maxZoom: p2.value }))), { hostRef: a2, scale: h2, setScale: d2, zoomEnabled: c2 };
4736
+ })(a2, computed(() => ({ enabled: c2(), getScale: () => h2.value, setScale: d2, minZoom: u2.value, maxZoom: g2.value }))), { hostRef: a2, scale: h2, setScale: d2, zoomEnabled: c2 };
4755
4737
  }
4756
- function Wn(e14) {
4738
+ function qn(e14) {
4757
4739
  return !!e14 && "urls" in e14 && Array.isArray(e14.urls);
4758
4740
  }
4759
- function qn(e14, t2) {
4741
+ function Hn(e14, t2) {
4760
4742
  return `${e14}#s${t2}`;
4761
4743
  }
4762
4744
  function Kn(e14) {
@@ -4769,7 +4751,7 @@ function jn(e14) {
4769
4751
  const t2 = (function(e15) {
4770
4752
  if (null != e15.segmentPageThreshold && e15.segmentPageThreshold > 0) return e15.segmentPageThreshold;
4771
4753
  const t3 = e15.source;
4772
- return Wn(t3) ? t3.segmentPageThreshold : null;
4754
+ return qn(t3) ? t3.segmentPageThreshold : null;
4773
4755
  })(e14);
4774
4756
  if (!t2) return null;
4775
4757
  const s2 = (function(e15) {
@@ -4777,11 +4759,11 @@ function jn(e14) {
4777
4759
  return s3 - t3 + 1;
4778
4760
  })(e14), n9 = (function(e15, t3) {
4779
4761
  return e15 <= 0 || t3 <= 0 ? 0 : Math.ceil(e15 / t3);
4780
- })(s2, t2), r2 = Wn(e14.source) ? e14.source.urls : void 0, a2 = [];
4762
+ })(s2, t2), r2 = qn(e14.source) ? e14.source.urls : void 0, a2 = [];
4781
4763
  for (let i2 = 0; i2 < n9; i2++) {
4782
4764
  const n10 = i2 * t2, o2 = Math.min(n10 + t2 - 1, s2 - 1);
4783
4765
  if (n10 >= s2) break;
4784
- a2.push({ index: i2, url: (null == r2 ? void 0 : r2[i2]) ?? "", localPageStart: n10, localPageEnd: o2, documentId: qn(e14.chapterId, i2) });
4766
+ a2.push({ index: i2, url: (null == r2 ? void 0 : r2[i2]) ?? "", localPageStart: n10, localPageEnd: o2, documentId: Hn(e14.chapterId, i2) });
4785
4767
  }
4786
4768
  return { chapterId: e14.chapterId, threshold: t2, pageCount: s2, segments: a2 };
4787
4769
  }
@@ -4930,7 +4912,7 @@ function lr(e14, t2 = ar) {
4930
4912
  }
4931
4913
  const hr = class e9 extends BasePlugin {
4932
4914
  constructor(e14, t2) {
4933
- super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = ar, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.SEG_PRIO_PREFETCH_NEXT = 120, this.SEG_PRIO_CHAPTER_PREFETCH_BASE = 3e3, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
4915
+ super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = ar, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
4934
4916
  }
4935
4917
  async initialize(e14) {
4936
4918
  if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? ar, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
@@ -5072,13 +5054,22 @@ const hr = class e9 extends BasePlugin {
5072
5054
  clearVisibleSegmentBacklog() {
5073
5055
  this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0;
5074
5056
  }
5057
+ globalSegmentSortKey(e14, t2) {
5058
+ var s2;
5059
+ if (!this.virtualPageMap) return Number.MAX_SAFE_INTEGER;
5060
+ const n9 = this.findChapter(e14);
5061
+ if (!n9) return Number.MAX_SAFE_INTEGER;
5062
+ const r2 = tr(n9), a2 = (null == (s2 = null == r2 ? void 0 : r2.segments[t2]) ? void 0 : s2.localPageStart) ?? 0, i2 = this.virtualPageMap.toGlobal(e14, a2);
5063
+ if (i2) return i2.globalPageIndex;
5064
+ return 1e4 * this.manifest.chapters.findIndex((t3) => t3.chapterId === e14) + t2;
5065
+ }
5075
5066
  scheduleVisibleSegmentLoads(e14) {
5076
- const t2 = /* @__PURE__ */ new Set(), s2 = [...e14].sort((e15, t3) => e15.priority - t3.priority);
5077
- for (const n9 of s2) {
5078
- const e15 = `${n9.chapterId}:${n9.segmentIndex}`;
5079
- t2.has(e15) || (t2.add(e15), this.isSegmentDocumentOpen(n9.chapterId, n9.segmentIndex) || this.isSegmentLoadPending(n9.chapterId, n9.segmentIndex) || this.visibleSegmentBacklog.push({ chapterId: n9.chapterId, segmentIndex: n9.segmentIndex }));
5067
+ const t2 = [...e14].sort((e15, t3) => e15.priority - t3.priority), s2 = /* @__PURE__ */ new Set(), n9 = [];
5068
+ for (const r2 of t2) {
5069
+ const e15 = `${r2.chapterId}:${r2.segmentIndex}`;
5070
+ s2.has(e15) || (s2.add(e15), this.isSegmentDocumentOpen(r2.chapterId, r2.segmentIndex) || this.isSegmentLoadPending(r2.chapterId, r2.segmentIndex) || n9.push({ chapterId: r2.chapterId, segmentIndex: r2.segmentIndex }));
5080
5071
  }
5081
- this.pumpVisibleSegmentBacklog();
5072
+ this.visibleSegmentBacklog = n9, this.pumpVisibleSegmentBacklog();
5082
5073
  }
5083
5074
  pumpVisibleSegmentBacklog() {
5084
5075
  const e14 = Math.max(1, this.config.maxConcurrentSegmentLoads ?? 2);
@@ -5097,53 +5088,41 @@ const hr = class e9 extends BasePlugin {
5097
5088
  const t2 = e14.join(","), s2 = this.visibleRangeNeedsSegmentLoad(e14);
5098
5089
  if (t2 === this.lastVisibleIndicesKey && !s2) return;
5099
5090
  this.lastVisibleIndicesKey = t2;
5100
- const n9 = Date.now(), r2 = this.config.prefetchChapters ?? 1, a2 = e14[Math.floor(e14.length / 2)] ?? e14[0], i2 = /* @__PURE__ */ new Set(), o2 = /* @__PURE__ */ new Map(), l = (e15, t3, s3) => {
5091
+ const n9 = Date.now(), r2 = e14[Math.floor(e14.length / 2)] ?? e14[0], a2 = /* @__PURE__ */ new Set(), i2 = /* @__PURE__ */ new Map(), o2 = (e15, t3) => {
5101
5092
  if (t3 < 0) return;
5102
- const n10 = this.findChapter(e15);
5103
- if (!n10) return;
5104
- const r3 = tr(n10);
5105
- if (r3 && t3 >= r3.segments.length) return;
5106
- const a3 = `${e15}:${t3}`, i3 = o2.get(a3);
5107
- (void 0 === i3 || s3 < i3) && o2.set(a3, s3);
5093
+ const s3 = this.findChapter(e15);
5094
+ if (!s3) return;
5095
+ const n10 = tr(s3);
5096
+ if (n10 && t3 >= n10.segments.length) return;
5097
+ const r3 = `${e15}:${t3}`, a3 = this.globalSegmentSortKey(e15, t3), o3 = i2.get(r3);
5098
+ (void 0 === o3 || a3 < o3) && i2.set(r3, a3);
5108
5099
  };
5109
- for (const p2 of e14) {
5110
- const e15 = this.virtualPageMap.atIndex(p2);
5100
+ for (const d2 of e14) {
5101
+ const e15 = this.virtualPageMap.atIndex(d2);
5111
5102
  if (!e15) continue;
5112
- i2.add(e15.chapterId);
5103
+ a2.add(e15.chapterId);
5113
5104
  const t3 = this.findChapter(e15.chapterId);
5114
5105
  if (!t3) continue;
5115
- const s3 = Math.abs(p2 - a2), n10 = nr(t3, e15.localPageIndex);
5116
- l(e15.chapterId, n10, s3), l(e15.chapterId, n10 + 1, s3 + this.SEG_PRIO_PREFETCH_NEXT), this.resolveChapterUrls(t3).catch(() => {
5106
+ const s3 = nr(t3, e15.localPageIndex);
5107
+ o2(e15.chapterId, s3), this.resolveChapterUrls(t3).catch(() => {
5117
5108
  });
5118
5109
  }
5119
- if (0 === i2.size) return;
5120
- const h2 = this.manifest.chapters.map((e15) => e15.chapterId);
5121
- let d2 = 0;
5122
- const c2 = this.virtualPageMap.atIndex(a2);
5123
- if (c2) {
5124
- const e15 = h2.indexOf(c2.chapterId);
5125
- e15 >= 0 && (d2 = e15);
5126
- }
5127
- for (const p2 of i2) {
5128
- this.chapterLastUsed.set(p2, n9);
5129
- const e15 = h2.indexOf(p2);
5130
- if (-1 !== e15) for (let t3 = e15 - r2; t3 <= e15 + r2; t3++) {
5131
- if (t3 < 0 || t3 >= h2.length) continue;
5132
- const e16 = h2[t3];
5133
- this.chapterLastUsed.set(e16, n9);
5134
- const s3 = Math.abs(t3 - d2);
5135
- l(e16, 0, this.SEG_PRIO_CHAPTER_PREFETCH_BASE + 100 * s3);
5136
- const r3 = this.findChapter(e16);
5137
- r3 && this.resolveChapterUrls(r3).catch(() => {
5138
- });
5110
+ if (0 === a2.size) return;
5111
+ const l = this.virtualPageMap.atIndex(r2);
5112
+ if (l) {
5113
+ const e15 = this.findChapter(l.chapterId);
5114
+ if (e15) {
5115
+ const t3 = nr(e15, l.localPageIndex);
5116
+ o2(l.chapterId, t3 + 1);
5139
5117
  }
5140
5118
  }
5141
- const u2 = [...o2.entries()].map(([e15, t3]) => {
5119
+ for (const d2 of a2) this.chapterLastUsed.set(d2, n9);
5120
+ const h2 = [...i2.entries()].map(([e15, t3]) => {
5142
5121
  const [s3, n10] = e15.split(":");
5143
5122
  return { chapterId: s3, segmentIndex: Number.parseInt(n10, 10), priority: t3 };
5144
5123
  }).filter((e15) => e15.chapterId && Number.isFinite(e15.segmentIndex));
5145
- if (this.scheduleVisibleSegmentLoads(u2), this.config.autoActivateOnLoad ?? 1) {
5146
- const e15 = this.virtualPageMap.atIndex(a2);
5124
+ if (this.scheduleVisibleSegmentLoads(h2), this.config.autoActivateOnLoad ?? 1) {
5125
+ const e15 = this.virtualPageMap.atIndex(r2);
5147
5126
  if (e15) {
5148
5127
  const t3 = sr(this.findChapter(e15.chapterId), e15.localPageIndex);
5149
5128
  if (this.documentManager.provides().isDocumentOpen(t3.documentId)) {
@@ -5567,13 +5546,13 @@ const ur = class extends BasePlugin {
5567
5546
  }
5568
5547
  };
5569
5548
  ur.id = "chapter-scroll";
5570
- let pr = ur;
5571
- const gr = ["data-global-page-index", "data-chapter-id", "data-local-page-index"], mr = /* @__PURE__ */ ((e14, t2) => {
5549
+ let gr = ur;
5550
+ const pr = ["data-global-page-index", "data-chapter-id", "data-local-page-index"], mr = /* @__PURE__ */ ((e14, t2) => {
5572
5551
  const s2 = e14.__vccOpts || e14;
5573
5552
  for (const [n9, r2] of t2) s2[n9] = r2;
5574
5553
  return s2;
5575
5554
  })(/* @__PURE__ */ defineComponent({ __name: "ChapterScroller", props: { class: {}, style: {} }, setup(e14) {
5576
- const { provides: t2 } = useCapability(pr.id), a2 = ref(null), m2 = ref(null);
5555
+ const { provides: t2 } = useCapability(gr.id), a2 = ref(null), m2 = ref(null);
5577
5556
  let f2 = null;
5578
5557
  const v = () => {
5579
5558
  null == f2 || f2(), f2 = null, t2.value && (t2.value.registerViewport(a2.value), f2 = t2.value.onLayoutChange((e15) => {
@@ -5585,7 +5564,7 @@ const gr = ["data-global-page-index", "data-chapter-id", "data-local-page-index"
5585
5564
  null == f2 || f2(), null == (e15 = t2.value) || e15.registerViewport(null);
5586
5565
  }), watch(t2, v), (e15, t3) => {
5587
5566
  var s2, n9, r2;
5588
- return openBlock(), createElementBlock("div", { ref_key: "containerRef", ref: a2, "data-chapter-scroll-viewport": "", class: normalizeClass(e15.$props.class), style: normalizeStyle({ overflow: "auto", overflowX: "hidden", position: "relative", width: "100%", height: "100%", ...e15.$props.style }) }, [createElementVNode("div", { style: normalizeStyle({ position: "relative", width: `${(null == (s2 = m2.value) ? void 0 : s2.totalWidth) ?? 0}px`, height: `${(null == (n9 = m2.value) ? void 0 : n9.totalHeight) ?? 0}px`, margin: "0 auto" }) }, [(openBlock(true), createElementBlock(Fragment, null, renderList((null == (r2 = m2.value) ? void 0 : r2.items) ?? [], (s3) => (openBlock(), createElementBlock("div", { key: s3.globalPageIndex, "data-global-page-index": s3.globalPageIndex, "data-chapter-id": s3.chapterId, "data-local-page-index": s3.localPageIndex, style: normalizeStyle({ position: "absolute", top: `${s3.offsetTop}px`, left: "50%", transform: "translateX(-50%)", width: `${s3.width}px`, height: `${s3.height}px`, backgroundColor: s3.isPlaceholder ? "#f3f4f6" : "#fff", boxShadow: "0 1px 4px rgba(0,0,0,0.08)" }) }, [s3.isPlaceholder ? renderSlot(e15.$slots, "placeholder", { key: 0, item: s3 }, () => [t3[0] || (t3[0] = createElementVNode("div", { class: "chapter-scroll-placeholder" }, "Loading chapter…", -1))], true) : renderSlot(e15.$slots, "page", { key: 1, item: s3 }, void 0, true)], 12, gr))), 128))], 4)], 6);
5567
+ return openBlock(), createElementBlock("div", { ref_key: "containerRef", ref: a2, "data-chapter-scroll-viewport": "", class: normalizeClass(e15.$props.class), style: normalizeStyle({ overflow: "auto", overflowX: "hidden", position: "relative", width: "100%", height: "100%", ...e15.$props.style }) }, [createElementVNode("div", { style: normalizeStyle({ position: "relative", width: `${(null == (s2 = m2.value) ? void 0 : s2.totalWidth) ?? 0}px`, height: `${(null == (n9 = m2.value) ? void 0 : n9.totalHeight) ?? 0}px`, margin: "0 auto" }) }, [(openBlock(true), createElementBlock(Fragment, null, renderList((null == (r2 = m2.value) ? void 0 : r2.items) ?? [], (s3) => (openBlock(), createElementBlock("div", { key: s3.globalPageIndex, "data-global-page-index": s3.globalPageIndex, "data-chapter-id": s3.chapterId, "data-local-page-index": s3.localPageIndex, style: normalizeStyle({ position: "absolute", top: `${s3.offsetTop}px`, left: "50%", transform: "translateX(-50%)", width: `${s3.width}px`, height: `${s3.height}px`, backgroundColor: s3.isPlaceholder ? "#f3f4f6" : "#fff", boxShadow: "0 1px 4px rgba(0,0,0,0.08)" }) }, [s3.isPlaceholder ? renderSlot(e15.$slots, "placeholder", { key: 0, item: s3 }, () => [t3[0] || (t3[0] = createElementVNode("div", { class: "chapter-scroll-placeholder" }, "Loading chapter…", -1))], true) : renderSlot(e15.$slots, "page", { key: 1, item: s3 }, void 0, true)], 12, pr))), 128))], 4)], 6);
5589
5568
  };
5590
5569
  } }), [["__scopeId", "data-v-e9ab4da3"]]), fr = /* @__PURE__ */ defineComponent({ __name: "ChapterRenderLayer", props: { chapterId: {}, localPageIndex: {}, pdfDocumentId: {}, pdfPageIndex: {}, scale: {}, dpr: {}, class: {} }, setup(e14) {
5591
5570
  const t2 = e14;
@@ -5736,7 +5715,7 @@ function Dr(e14, t2 = Lr) {
5736
5715
  }
5737
5716
  const Er = class e10 extends BasePlugin {
5738
5717
  constructor(e14, t2) {
5739
- super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = Lr, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.SEG_PRIO_PREFETCH_NEXT = 120, this.SEG_PRIO_CHAPTER_PREFETCH_BASE = 3e3, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
5718
+ super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = Lr, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
5740
5719
  }
5741
5720
  async initialize(e14) {
5742
5721
  if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? Lr, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
@@ -5878,13 +5857,22 @@ const Er = class e10 extends BasePlugin {
5878
5857
  clearVisibleSegmentBacklog() {
5879
5858
  this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0;
5880
5859
  }
5860
+ globalSegmentSortKey(e14, t2) {
5861
+ var s2;
5862
+ if (!this.virtualPageMap) return Number.MAX_SAFE_INTEGER;
5863
+ const n9 = this.findChapter(e14);
5864
+ if (!n9) return Number.MAX_SAFE_INTEGER;
5865
+ const r2 = yr(n9), a2 = (null == (s2 = null == r2 ? void 0 : r2.segments[t2]) ? void 0 : s2.localPageStart) ?? 0, i2 = this.virtualPageMap.toGlobal(e14, a2);
5866
+ if (i2) return i2.globalPageIndex;
5867
+ return 1e4 * this.manifest.chapters.findIndex((t3) => t3.chapterId === e14) + t2;
5868
+ }
5881
5869
  scheduleVisibleSegmentLoads(e14) {
5882
- const t2 = /* @__PURE__ */ new Set(), s2 = [...e14].sort((e15, t3) => e15.priority - t3.priority);
5883
- for (const n9 of s2) {
5884
- const e15 = `${n9.chapterId}:${n9.segmentIndex}`;
5885
- t2.has(e15) || (t2.add(e15), this.isSegmentDocumentOpen(n9.chapterId, n9.segmentIndex) || this.isSegmentLoadPending(n9.chapterId, n9.segmentIndex) || this.visibleSegmentBacklog.push({ chapterId: n9.chapterId, segmentIndex: n9.segmentIndex }));
5870
+ const t2 = [...e14].sort((e15, t3) => e15.priority - t3.priority), s2 = /* @__PURE__ */ new Set(), n9 = [];
5871
+ for (const r2 of t2) {
5872
+ const e15 = `${r2.chapterId}:${r2.segmentIndex}`;
5873
+ s2.has(e15) || (s2.add(e15), this.isSegmentDocumentOpen(r2.chapterId, r2.segmentIndex) || this.isSegmentLoadPending(r2.chapterId, r2.segmentIndex) || n9.push({ chapterId: r2.chapterId, segmentIndex: r2.segmentIndex }));
5886
5874
  }
5887
- this.pumpVisibleSegmentBacklog();
5875
+ this.visibleSegmentBacklog = n9, this.pumpVisibleSegmentBacklog();
5888
5876
  }
5889
5877
  pumpVisibleSegmentBacklog() {
5890
5878
  const e14 = Math.max(1, this.config.maxConcurrentSegmentLoads ?? 2);
@@ -5903,53 +5891,41 @@ const Er = class e10 extends BasePlugin {
5903
5891
  const t2 = e14.join(","), s2 = this.visibleRangeNeedsSegmentLoad(e14);
5904
5892
  if (t2 === this.lastVisibleIndicesKey && !s2) return;
5905
5893
  this.lastVisibleIndicesKey = t2;
5906
- const n9 = Date.now(), r2 = this.config.prefetchChapters ?? 1, a2 = e14[Math.floor(e14.length / 2)] ?? e14[0], i2 = /* @__PURE__ */ new Set(), o2 = /* @__PURE__ */ new Map(), l = (e15, t3, s3) => {
5894
+ const n9 = Date.now(), r2 = e14[Math.floor(e14.length / 2)] ?? e14[0], a2 = /* @__PURE__ */ new Set(), i2 = /* @__PURE__ */ new Map(), o2 = (e15, t3) => {
5907
5895
  if (t3 < 0) return;
5908
- const n10 = this.findChapter(e15);
5909
- if (!n10) return;
5910
- const r3 = yr(n10);
5911
- if (r3 && t3 >= r3.segments.length) return;
5912
- const a3 = `${e15}:${t3}`, i3 = o2.get(a3);
5913
- (void 0 === i3 || s3 < i3) && o2.set(a3, s3);
5896
+ const s3 = this.findChapter(e15);
5897
+ if (!s3) return;
5898
+ const n10 = yr(s3);
5899
+ if (n10 && t3 >= n10.segments.length) return;
5900
+ const r3 = `${e15}:${t3}`, a3 = this.globalSegmentSortKey(e15, t3), o3 = i2.get(r3);
5901
+ (void 0 === o3 || a3 < o3) && i2.set(r3, a3);
5914
5902
  };
5915
- for (const p2 of e14) {
5916
- const e15 = this.virtualPageMap.atIndex(p2);
5903
+ for (const d2 of e14) {
5904
+ const e15 = this.virtualPageMap.atIndex(d2);
5917
5905
  if (!e15) continue;
5918
- i2.add(e15.chapterId);
5906
+ a2.add(e15.chapterId);
5919
5907
  const t3 = this.findChapter(e15.chapterId);
5920
5908
  if (!t3) continue;
5921
- const s3 = Math.abs(p2 - a2), n10 = Mr(t3, e15.localPageIndex);
5922
- l(e15.chapterId, n10, s3), l(e15.chapterId, n10 + 1, s3 + this.SEG_PRIO_PREFETCH_NEXT), this.resolveChapterUrls(t3).catch(() => {
5909
+ const s3 = Mr(t3, e15.localPageIndex);
5910
+ o2(e15.chapterId, s3), this.resolveChapterUrls(t3).catch(() => {
5923
5911
  });
5924
5912
  }
5925
- if (0 === i2.size) return;
5926
- const h2 = this.manifest.chapters.map((e15) => e15.chapterId);
5927
- let d2 = 0;
5928
- const c2 = this.virtualPageMap.atIndex(a2);
5929
- if (c2) {
5930
- const e15 = h2.indexOf(c2.chapterId);
5931
- e15 >= 0 && (d2 = e15);
5932
- }
5933
- for (const p2 of i2) {
5934
- this.chapterLastUsed.set(p2, n9);
5935
- const e15 = h2.indexOf(p2);
5936
- if (-1 !== e15) for (let t3 = e15 - r2; t3 <= e15 + r2; t3++) {
5937
- if (t3 < 0 || t3 >= h2.length) continue;
5938
- const e16 = h2[t3];
5939
- this.chapterLastUsed.set(e16, n9);
5940
- const s3 = Math.abs(t3 - d2);
5941
- l(e16, 0, this.SEG_PRIO_CHAPTER_PREFETCH_BASE + 100 * s3);
5942
- const r3 = this.findChapter(e16);
5943
- r3 && this.resolveChapterUrls(r3).catch(() => {
5944
- });
5913
+ if (0 === a2.size) return;
5914
+ const l = this.virtualPageMap.atIndex(r2);
5915
+ if (l) {
5916
+ const e15 = this.findChapter(l.chapterId);
5917
+ if (e15) {
5918
+ const t3 = Mr(e15, l.localPageIndex);
5919
+ o2(l.chapterId, t3 + 1);
5945
5920
  }
5946
5921
  }
5947
- const u2 = [...o2.entries()].map(([e15, t3]) => {
5922
+ for (const d2 of a2) this.chapterLastUsed.set(d2, n9);
5923
+ const h2 = [...i2.entries()].map(([e15, t3]) => {
5948
5924
  const [s3, n10] = e15.split(":");
5949
5925
  return { chapterId: s3, segmentIndex: Number.parseInt(n10, 10), priority: t3 };
5950
5926
  }).filter((e15) => e15.chapterId && Number.isFinite(e15.segmentIndex));
5951
- if (this.scheduleVisibleSegmentLoads(u2), this.config.autoActivateOnLoad ?? 1) {
5952
- const e15 = this.virtualPageMap.atIndex(a2);
5927
+ if (this.scheduleVisibleSegmentLoads(h2), this.config.autoActivateOnLoad ?? 1) {
5928
+ const e15 = this.virtualPageMap.atIndex(r2);
5953
5929
  if (e15) {
5954
5930
  const t3 = wr(this.findChapter(e15.chapterId), e15.localPageIndex);
5955
5931
  if (this.documentManager.provides().isDocumentOpen(t3.documentId)) {
@@ -6142,24 +6118,24 @@ const Er = class e10 extends BasePlugin {
6142
6118
  }
6143
6119
  };
6144
6120
  Er.id = "chapter-manager";
6145
- let Tr = Er;
6146
- function Ur(e14) {
6121
+ let Ur = Er;
6122
+ function Tr(e14) {
6147
6123
  return !!e14 && "urls" in e14 && Array.isArray(e14.urls);
6148
6124
  }
6149
6125
  function Fr(e14, t2) {
6150
6126
  return `${e14}#s${t2}`;
6151
6127
  }
6152
- function Or(e14) {
6128
+ function Nr(e14) {
6153
6129
  const t2 = e14.lastIndexOf("#s");
6154
6130
  if (-1 === t2) return { chapterId: e14, segmentIndex: null };
6155
6131
  const s2 = e14.slice(0, t2), n9 = Number.parseInt(e14.slice(t2 + 2), 10);
6156
6132
  return !Number.isFinite(n9) || n9 < 0 ? { chapterId: e14, segmentIndex: null } : { chapterId: s2, segmentIndex: n9 };
6157
6133
  }
6158
- function Rr(e14) {
6134
+ function Ar(e14) {
6159
6135
  const t2 = (function(e15) {
6160
6136
  if (null != e15.segmentPageThreshold && e15.segmentPageThreshold > 0) return e15.segmentPageThreshold;
6161
6137
  const t3 = e15.source;
6162
- return Ur(t3) ? t3.segmentPageThreshold : null;
6138
+ return Tr(t3) ? t3.segmentPageThreshold : null;
6163
6139
  })(e14);
6164
6140
  if (!t2) return null;
6165
6141
  const s2 = (function(e15) {
@@ -6167,7 +6143,7 @@ function Rr(e14) {
6167
6143
  return s3 - t3 + 1;
6168
6144
  })(e14), n9 = (function(e15, t3) {
6169
6145
  return e15 <= 0 || t3 <= 0 ? 0 : Math.ceil(e15 / t3);
6170
- })(s2, t2), r2 = Ur(e14.source) ? e14.source.urls : void 0, a2 = [];
6146
+ })(s2, t2), r2 = Tr(e14.source) ? e14.source.urls : void 0, a2 = [];
6171
6147
  for (let i2 = 0; i2 < n9; i2++) {
6172
6148
  const n10 = i2 * t2, o2 = Math.min(n10 + t2 - 1, s2 - 1);
6173
6149
  if (n10 >= s2) break;
@@ -6175,34 +6151,34 @@ function Rr(e14) {
6175
6151
  }
6176
6152
  return { chapterId: e14.chapterId, threshold: t2, pageCount: s2, segments: a2 };
6177
6153
  }
6178
- function Nr(e14) {
6154
+ function Vr(e14) {
6179
6155
  const [t2, s2] = e14.localPageRange;
6180
6156
  return s2 - t2 + 1;
6181
6157
  }
6182
- function Ar(e14) {
6158
+ function Or(e14) {
6183
6159
  return !!e14 && "urls" in e14 && Array.isArray(e14.urls);
6184
6160
  }
6185
- function Vr(e14) {
6161
+ function Rr(e14) {
6186
6162
  if (null != e14.segmentPageThreshold && e14.segmentPageThreshold > 0) return e14.segmentPageThreshold;
6187
6163
  const t2 = e14.source;
6188
- return Ar(t2) ? t2.segmentPageThreshold : null;
6164
+ return Or(t2) ? t2.segmentPageThreshold : null;
6189
6165
  }
6190
6166
  function zr(e14, t2) {
6191
6167
  return `${e14}#s${t2}`;
6192
6168
  }
6193
- function _r(e14) {
6169
+ function Gr(e14) {
6194
6170
  const t2 = e14.lastIndexOf("#s");
6195
6171
  if (-1 === t2) return { chapterId: e14, segmentIndex: null };
6196
6172
  const s2 = e14.slice(0, t2), n9 = Number.parseInt(e14.slice(t2 + 2), 10);
6197
6173
  return !Number.isFinite(n9) || n9 < 0 ? { chapterId: e14, segmentIndex: null } : { chapterId: s2, segmentIndex: n9 };
6198
6174
  }
6199
- function Gr(e14, t2) {
6175
+ function _r(e14, t2) {
6200
6176
  return e14 <= 0 || t2 <= 0 ? 0 : Math.ceil(e14 / t2);
6201
6177
  }
6202
6178
  function Br(e14) {
6203
- const t2 = Vr(e14);
6179
+ const t2 = Rr(e14);
6204
6180
  if (!t2) return null;
6205
- const s2 = Nr(e14), n9 = Gr(s2, t2), r2 = Ar(e14.source) ? e14.source.urls : void 0, a2 = [];
6181
+ const s2 = Vr(e14), n9 = _r(s2, t2), r2 = Or(e14.source) ? e14.source.urls : void 0, a2 = [];
6206
6182
  for (let i2 = 0; i2 < n9; i2++) {
6207
6183
  const n10 = i2 * t2, o2 = Math.min(n10 + t2 - 1, s2 - 1);
6208
6184
  if (n10 >= s2) break;
@@ -6210,7 +6186,7 @@ function Br(e14) {
6210
6186
  }
6211
6187
  return { chapterId: e14.chapterId, threshold: t2, pageCount: s2, segments: a2 };
6212
6188
  }
6213
- function Hr(e14, t2) {
6189
+ function Wr(e14, t2) {
6214
6190
  const s2 = Br(e14);
6215
6191
  if (!s2) return { documentId: e14.chapterId, pageIndex: t2 };
6216
6192
  const n9 = s2.segments.find((e15) => t2 >= e15.localPageStart && t2 <= e15.localPageEnd);
@@ -6220,22 +6196,22 @@ function Hr(e14, t2) {
6220
6196
  }
6221
6197
  return { documentId: n9.documentId, pageIndex: t2 - n9.localPageStart };
6222
6198
  }
6223
- function Wr(e14, t2) {
6199
+ function qr(e14, t2) {
6224
6200
  const s2 = Br(e14);
6225
6201
  if (!s2) return 0;
6226
6202
  const n9 = s2.segments.find((e15) => t2 >= e15.localPageStart && t2 <= e15.localPageEnd);
6227
6203
  return (null == n9 ? void 0 : n9.index) ?? Math.floor(t2 / s2.threshold);
6228
6204
  }
6229
- function qr(e14) {
6205
+ function Hr(e14) {
6230
6206
  var t2;
6231
- const s2 = Vr(e14);
6207
+ const s2 = Rr(e14);
6232
6208
  if (!s2) return [];
6233
- const n9 = [], { chapterId: r2 } = e14, a2 = Nr(e14);
6209
+ const n9 = [], { chapterId: r2 } = e14, a2 = Vr(e14);
6234
6210
  s2 <= 0 && n9.push(`${r2}: segmentPageThreshold must be > 0`);
6235
6211
  const i2 = e14.source;
6236
- if (!Ar(i2)) return n9;
6212
+ if (!Or(i2)) return n9;
6237
6213
  0 === i2.urls.length && n9.push(`${r2}: source.urls must not be empty`);
6238
- const o2 = Gr(a2, s2);
6214
+ const o2 = _r(a2, s2);
6239
6215
  i2.urls.length !== o2 && n9.push(`${r2}: source.urls.length (${i2.urls.length}) must equal ceil(pageCount/threshold) (${o2})`);
6240
6216
  for (let l = 0; l < i2.urls.length; l++) (null == (t2 = i2.urls[l]) ? void 0 : t2.trim()) || n9.push(`${r2}: source.urls[${l}] is empty`);
6241
6217
  return n9;
@@ -6320,17 +6296,17 @@ function Zr(e14, t2 = Kr) {
6320
6296
  }
6321
6297
  const Yr = class e11 extends BasePlugin {
6322
6298
  constructor(e14, t2) {
6323
- super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = Kr, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.SEG_PRIO_PREFETCH_NEXT = 120, this.SEG_PRIO_CHAPTER_PREFETCH_BASE = 3e3, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
6299
+ super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = Kr, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
6324
6300
  }
6325
6301
  async initialize(e14) {
6326
6302
  if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? Kr, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
6327
- const { chapterId: t2 } = _r(e15.id);
6303
+ const { chapterId: t2 } = Gr(e15.id);
6328
6304
  this.findChapter(t2) && (this.passwordAttempts.delete(t2), this.syncChapterStatusFromDocuments(t2));
6329
6305
  }), this.documentManager.provides().onDocumentClosed((e15) => {
6330
- const { chapterId: t2 } = _r(e15);
6306
+ const { chapterId: t2 } = Gr(e15);
6331
6307
  this.findChapter(t2) && this.syncChapterStatusFromDocuments(t2);
6332
6308
  }), this.documentManager.provides().onDocumentError((e15) => {
6333
- const { chapterId: t2 } = _r(e15.documentId);
6309
+ const { chapterId: t2 } = Gr(e15.documentId);
6334
6310
  this.findChapter(t2) && this.handleDocumentError(e15.documentId, t2, e15.code, e15.message);
6335
6311
  })), this.setManifestInternal(e14.manifest), e14.unloadTimeoutMs && e14.unloadTimeoutMs > 0) {
6336
6312
  const t2 = Math.max(5e3, Math.floor(e14.unloadTimeoutMs / 4));
@@ -6342,7 +6318,7 @@ const Yr = class e11 extends BasePlugin {
6342
6318
  t2 && (this.overlapStrategy = t2), this.setManifestInternal(e14);
6343
6319
  }, getManifest: () => this.manifest, getVirtualPageMap: () => this.virtualPageMap, setVisibleGlobalPages: (e14) => this.handleVisibleChange(e14), visibleRangeNeedsSegmentLoad: (e14) => this.visibleRangeNeedsSegmentLoad(e14), shouldShowChapterLoadError: (e14, t2) => this.shouldShowChapterLoadError(e14, t2), ensureChapterLoaded: (e14) => this.ensureChapterLoaded(e14), ensureSegmentLoaded: (e14, t2) => this.ensureSegmentLoaded(e14, t2), ensureAllSegmentsLoaded: (e14) => this.ensureAllSegmentsLoaded(e14), resolvePageDocument: (e14, t2) => {
6344
6320
  const s2 = this.findChapter(e14);
6345
- return s2 ? Hr(s2, t2) : null;
6321
+ return s2 ? Wr(s2, t2) : null;
6346
6322
  }, getSegmentPlan: (e14) => {
6347
6323
  const t2 = this.findChapter(e14);
6348
6324
  return t2 ? Br(t2) : null;
@@ -6377,7 +6353,7 @@ const Yr = class e11 extends BasePlugin {
6377
6353
  s3.has(n10.chapterId) && t3.push(`Duplicate chapterId: ${n10.chapterId}`), s3.add(n10.chapterId);
6378
6354
  const [e15, r3] = n10.globalPageRange, [a3, i2] = n10.localPageRange;
6379
6355
  if (e15 > r3 && t3.push(`${n10.chapterId}: invalid globalPageRange [${e15},${r3}]`), a3 > i2 && t3.push(`${n10.chapterId}: invalid localPageRange [${a3},${i2}]`), r3 - e15 !== i2 - a3 && t3.push(`${n10.chapterId}: page-count mismatch (global ${r3 - e15 + 1} vs local ${i2 - a3 + 1})`), n10.ownedGlobalPages) for (const s4 of n10.ownedGlobalPages) (s4 < e15 || s4 > r3) && t3.push(`${n10.chapterId}: ownedGlobalPages contains ${s4} outside range`);
6380
- t3.push(...qr(n10));
6356
+ t3.push(...Hr(n10));
6381
6357
  }
6382
6358
  return t3;
6383
6359
  })(s2);
@@ -6451,7 +6427,7 @@ const Yr = class e11 extends BasePlugin {
6451
6427
  if (!e15) continue;
6452
6428
  const s2 = this.findChapter(e15.chapterId);
6453
6429
  if (!s2) continue;
6454
- const n9 = Wr(s2, e15.localPageIndex);
6430
+ const n9 = qr(s2, e15.localPageIndex);
6455
6431
  if (!this.isSegmentDocumentOpen(e15.chapterId, n9)) return true;
6456
6432
  }
6457
6433
  return false;
@@ -6462,13 +6438,22 @@ const Yr = class e11 extends BasePlugin {
6462
6438
  clearVisibleSegmentBacklog() {
6463
6439
  this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0;
6464
6440
  }
6441
+ globalSegmentSortKey(e14, t2) {
6442
+ var s2;
6443
+ if (!this.virtualPageMap) return Number.MAX_SAFE_INTEGER;
6444
+ const n9 = this.findChapter(e14);
6445
+ if (!n9) return Number.MAX_SAFE_INTEGER;
6446
+ const r2 = Br(n9), a2 = (null == (s2 = null == r2 ? void 0 : r2.segments[t2]) ? void 0 : s2.localPageStart) ?? 0, i2 = this.virtualPageMap.toGlobal(e14, a2);
6447
+ if (i2) return i2.globalPageIndex;
6448
+ return 1e4 * this.manifest.chapters.findIndex((t3) => t3.chapterId === e14) + t2;
6449
+ }
6465
6450
  scheduleVisibleSegmentLoads(e14) {
6466
- const t2 = /* @__PURE__ */ new Set(), s2 = [...e14].sort((e15, t3) => e15.priority - t3.priority);
6467
- for (const n9 of s2) {
6468
- const e15 = `${n9.chapterId}:${n9.segmentIndex}`;
6469
- t2.has(e15) || (t2.add(e15), this.isSegmentDocumentOpen(n9.chapterId, n9.segmentIndex) || this.isSegmentLoadPending(n9.chapterId, n9.segmentIndex) || this.visibleSegmentBacklog.push({ chapterId: n9.chapterId, segmentIndex: n9.segmentIndex }));
6451
+ const t2 = [...e14].sort((e15, t3) => e15.priority - t3.priority), s2 = /* @__PURE__ */ new Set(), n9 = [];
6452
+ for (const r2 of t2) {
6453
+ const e15 = `${r2.chapterId}:${r2.segmentIndex}`;
6454
+ s2.has(e15) || (s2.add(e15), this.isSegmentDocumentOpen(r2.chapterId, r2.segmentIndex) || this.isSegmentLoadPending(r2.chapterId, r2.segmentIndex) || n9.push({ chapterId: r2.chapterId, segmentIndex: r2.segmentIndex }));
6470
6455
  }
6471
- this.pumpVisibleSegmentBacklog();
6456
+ this.visibleSegmentBacklog = n9, this.pumpVisibleSegmentBacklog();
6472
6457
  }
6473
6458
  pumpVisibleSegmentBacklog() {
6474
6459
  const e14 = Math.max(1, this.config.maxConcurrentSegmentLoads ?? 2);
@@ -6487,55 +6472,43 @@ const Yr = class e11 extends BasePlugin {
6487
6472
  const t2 = e14.join(","), s2 = this.visibleRangeNeedsSegmentLoad(e14);
6488
6473
  if (t2 === this.lastVisibleIndicesKey && !s2) return;
6489
6474
  this.lastVisibleIndicesKey = t2;
6490
- const n9 = Date.now(), r2 = this.config.prefetchChapters ?? 1, a2 = e14[Math.floor(e14.length / 2)] ?? e14[0], i2 = /* @__PURE__ */ new Set(), o2 = /* @__PURE__ */ new Map(), l = (e15, t3, s3) => {
6475
+ const n9 = Date.now(), r2 = e14[Math.floor(e14.length / 2)] ?? e14[0], a2 = /* @__PURE__ */ new Set(), i2 = /* @__PURE__ */ new Map(), o2 = (e15, t3) => {
6491
6476
  if (t3 < 0) return;
6492
- const n10 = this.findChapter(e15);
6493
- if (!n10) return;
6494
- const r3 = Br(n10);
6495
- if (r3 && t3 >= r3.segments.length) return;
6496
- const a3 = `${e15}:${t3}`, i3 = o2.get(a3);
6497
- (void 0 === i3 || s3 < i3) && o2.set(a3, s3);
6477
+ const s3 = this.findChapter(e15);
6478
+ if (!s3) return;
6479
+ const n10 = Br(s3);
6480
+ if (n10 && t3 >= n10.segments.length) return;
6481
+ const r3 = `${e15}:${t3}`, a3 = this.globalSegmentSortKey(e15, t3), o3 = i2.get(r3);
6482
+ (void 0 === o3 || a3 < o3) && i2.set(r3, a3);
6498
6483
  };
6499
- for (const p2 of e14) {
6500
- const e15 = this.virtualPageMap.atIndex(p2);
6484
+ for (const d2 of e14) {
6485
+ const e15 = this.virtualPageMap.atIndex(d2);
6501
6486
  if (!e15) continue;
6502
- i2.add(e15.chapterId);
6487
+ a2.add(e15.chapterId);
6503
6488
  const t3 = this.findChapter(e15.chapterId);
6504
6489
  if (!t3) continue;
6505
- const s3 = Math.abs(p2 - a2), n10 = Wr(t3, e15.localPageIndex);
6506
- l(e15.chapterId, n10, s3), l(e15.chapterId, n10 + 1, s3 + this.SEG_PRIO_PREFETCH_NEXT), this.resolveChapterUrls(t3).catch(() => {
6490
+ const s3 = qr(t3, e15.localPageIndex);
6491
+ o2(e15.chapterId, s3), this.resolveChapterUrls(t3).catch(() => {
6507
6492
  });
6508
6493
  }
6509
- if (0 === i2.size) return;
6510
- const h2 = this.manifest.chapters.map((e15) => e15.chapterId);
6511
- let d2 = 0;
6512
- const c2 = this.virtualPageMap.atIndex(a2);
6513
- if (c2) {
6514
- const e15 = h2.indexOf(c2.chapterId);
6515
- e15 >= 0 && (d2 = e15);
6516
- }
6517
- for (const p2 of i2) {
6518
- this.chapterLastUsed.set(p2, n9);
6519
- const e15 = h2.indexOf(p2);
6520
- if (-1 !== e15) for (let t3 = e15 - r2; t3 <= e15 + r2; t3++) {
6521
- if (t3 < 0 || t3 >= h2.length) continue;
6522
- const e16 = h2[t3];
6523
- this.chapterLastUsed.set(e16, n9);
6524
- const s3 = Math.abs(t3 - d2);
6525
- l(e16, 0, this.SEG_PRIO_CHAPTER_PREFETCH_BASE + 100 * s3);
6526
- const r3 = this.findChapter(e16);
6527
- r3 && this.resolveChapterUrls(r3).catch(() => {
6528
- });
6494
+ if (0 === a2.size) return;
6495
+ const l = this.virtualPageMap.atIndex(r2);
6496
+ if (l) {
6497
+ const e15 = this.findChapter(l.chapterId);
6498
+ if (e15) {
6499
+ const t3 = qr(e15, l.localPageIndex);
6500
+ o2(l.chapterId, t3 + 1);
6529
6501
  }
6530
6502
  }
6531
- const u2 = [...o2.entries()].map(([e15, t3]) => {
6503
+ for (const d2 of a2) this.chapterLastUsed.set(d2, n9);
6504
+ const h2 = [...i2.entries()].map(([e15, t3]) => {
6532
6505
  const [s3, n10] = e15.split(":");
6533
6506
  return { chapterId: s3, segmentIndex: Number.parseInt(n10, 10), priority: t3 };
6534
6507
  }).filter((e15) => e15.chapterId && Number.isFinite(e15.segmentIndex));
6535
- if (this.scheduleVisibleSegmentLoads(u2), this.config.autoActivateOnLoad ?? 1) {
6536
- const e15 = this.virtualPageMap.atIndex(a2);
6508
+ if (this.scheduleVisibleSegmentLoads(h2), this.config.autoActivateOnLoad ?? 1) {
6509
+ const e15 = this.virtualPageMap.atIndex(r2);
6537
6510
  if (e15) {
6538
- const t3 = Hr(this.findChapter(e15.chapterId), e15.localPageIndex);
6511
+ const t3 = Wr(this.findChapter(e15.chapterId), e15.localPageIndex);
6539
6512
  if (this.documentManager.provides().isDocumentOpen(t3.documentId)) {
6540
6513
  this.documentManager.provides().getActiveDocumentId() !== t3.documentId && this.documentManager.provides().setActiveDocument(t3.documentId);
6541
6514
  }
@@ -6601,7 +6574,7 @@ const Yr = class e11 extends BasePlugin {
6601
6574
  if (n9) return n9;
6602
6575
  const r2 = (async () => {
6603
6576
  const s3 = e14.source;
6604
- if (Ar(s3)) {
6577
+ if (Or(s3)) {
6605
6578
  const e15 = [...s3.urls];
6606
6579
  return this.chapterUrlsCache.set(t2, e15), e15;
6607
6580
  }
@@ -6627,9 +6600,9 @@ const Yr = class e11 extends BasePlugin {
6627
6600
  return (null == r2 ? void 0 : r2.openPdf) ? r2.openPdf(a2) : { url: n9 };
6628
6601
  }
6629
6602
  async resolvePdfPayload(t2, s2) {
6630
- const n9 = t2.source, r2 = this.config.chapterPdfLoader, a2 = Vr(t2);
6603
+ const n9 = t2.source, r2 = this.config.chapterPdfLoader, a2 = Rr(t2);
6631
6604
  if (a2) {
6632
- const n10 = Gr(Nr(t2), a2);
6605
+ const n10 = _r(Vr(t2), a2);
6633
6606
  if (s2 < 0 || s2 >= n10) throw new Error(`Chapter "${t2.chapterId}" invalid segmentIndex ${s2} (expected 0..${n10 - 1})`);
6634
6607
  const r3 = await this.resolveChapterUrls(t2);
6635
6608
  if (r3.length !== n10) {
@@ -6640,7 +6613,7 @@ const Yr = class e11 extends BasePlugin {
6640
6613
  }
6641
6614
  if (0 !== s2) throw new Error(`Chapter "${t2.chapterId}" is not segmented`);
6642
6615
  if (n9) {
6643
- if (Ar(n9)) {
6616
+ if (Or(n9)) {
6644
6617
  const e14 = await this.resolveChapterUrls(t2);
6645
6618
  return this.openPayloadFromUrl(t2, s2, e14);
6646
6619
  }
@@ -6688,7 +6661,7 @@ const Yr = class e11 extends BasePlugin {
6688
6661
  async handleDocumentError(t2, s2, n9, r2) {
6689
6662
  if (this.pendingSegmentLoadPromises.has(t2)) return;
6690
6663
  if (n9 !== PdfErrorCode.Password) {
6691
- const e14 = this.getSegmentPlanForChapter(s2), { segmentIndex: n10 } = _r(t2);
6664
+ const e14 = this.getSegmentPlanForChapter(s2), { segmentIndex: n10 } = Gr(t2);
6692
6665
  return void (e14 && 0 !== n10 && null !== n10 || this.updateStatus(s2, "error"));
6693
6666
  }
6694
6667
  if (!this.passwordProvider) return void this.updateStatus(s2, "password-required");
@@ -6754,7 +6727,7 @@ const ea = class extends BasePlugin {
6754
6727
  const s2 = this.chapterManager.provides(), n9 = s2.getChapter(e14);
6755
6728
  if (!n9) return true;
6756
6729
  const r2 = (function(e15, t3) {
6757
- const s3 = Rr(e15);
6730
+ const s3 = Ar(e15);
6758
6731
  if (!s3) return 0;
6759
6732
  const n10 = s3.segments.find((e16) => t3 >= e16.localPageStart && t3 <= e16.localPageEnd);
6760
6733
  return (null == n10 ? void 0 : n10.index) ?? Math.floor(t3 / s3.threshold);
@@ -6784,14 +6757,14 @@ const ea = class extends BasePlugin {
6784
6757
  }
6785
6758
  onDocumentLoaded(e14) {
6786
6759
  var t2;
6787
- const { chapterId: s2 } = Or(e14);
6760
+ const { chapterId: s2 } = Nr(e14);
6788
6761
  if (0 === ((null == (t2 = this.virtualPageMap) ? void 0 : t2.pagesOfChapter(s2).length) ?? 0)) return;
6789
6762
  const n9 = this.documentManager.provides();
6790
6763
  n9.getActiveDocumentId() || n9.setActiveDocument(e14), this.harvestChapterSizes(s2), this.refreshLayout(), this.lastLoadIndicesKey = "", this.schedulePushVisibleLoads();
6791
6764
  }
6792
6765
  onDocumentClosed(e14) {
6793
6766
  var t2;
6794
- const { chapterId: s2 } = Or(e14);
6767
+ const { chapterId: s2 } = Nr(e14);
6795
6768
  0 !== ((null == (t2 = this.virtualPageMap) ? void 0 : t2.pagesOfChapter(s2).length) ?? 0) && (this.dropChapterSizes(s2), this.refreshLayout());
6796
6769
  }
6797
6770
  buildCapability() {
@@ -6843,7 +6816,7 @@ const ea = class extends BasePlugin {
6843
6816
  if (!this.virtualPageMap) return;
6844
6817
  const s2 = this.chapterManager.provides(), n9 = s2.getChapter(e14), r2 = this.virtualPageMap.pagesOfChapter(e14);
6845
6818
  if (!n9 || 0 === r2.length) return;
6846
- const a2 = Rr(n9), i2 = this.documentManager.provides(), o2 = [], l = (e15, t3, s3, n10) => {
6819
+ const a2 = Ar(n9), i2 = this.documentManager.provides(), o2 = [], l = (e15, t3, s3, n10) => {
6847
6820
  var r3;
6848
6821
  const a3 = i2.getDocument(e15);
6849
6822
  if (!(null == (r3 = null == a3 ? void 0 : a3.pages) ? void 0 : r3.length)) return false;
@@ -6865,7 +6838,7 @@ const ea = class extends BasePlugin {
6865
6838
  onScaleChanged(e14) {
6866
6839
  const t2 = this.coreState.core.documents[e14];
6867
6840
  if (!t2 || "loaded" !== t2.status) return;
6868
- const { chapterId: s2 } = Or(e14);
6841
+ const { chapterId: s2 } = Nr(e14);
6869
6842
  this.chapterManager.provides().getChapter(s2) && this.harvestChapterSizes(s2);
6870
6843
  }
6871
6844
  dropChapterSizes(e14) {
@@ -6960,7 +6933,7 @@ ea.id = "chapter-scroll";
6960
6933
  let ta = ea;
6961
6934
  const sa = class e12 extends BasePlugin {
6962
6935
  constructor(e14, t2) {
6963
- super(e14, t2), this.notesChange$ = createBehaviorEmitter([]), this.noteActivated$ = createEmitter(), this.notes = /* @__PURE__ */ new Map(), this.chapterScroll = this.registry.getPlugin(ta.id), this.chapterManager = this.registry.getPlugin(Tr.id), this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
6936
+ super(e14, t2), this.notesChange$ = createBehaviorEmitter([]), this.noteActivated$ = createEmitter(), this.notes = /* @__PURE__ */ new Map(), this.chapterScroll = this.registry.getPlugin(ta.id), this.chapterManager = this.registry.getPlugin(Ur.id), this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
6964
6937
  }
6965
6938
  async initialize(t2) {
6966
6939
  if (this.config = t2, t2.callbacks.loadNotes) try {
@@ -7080,7 +7053,7 @@ function aa(e14) {
7080
7053
  return h2 > c2 && (h2 = c2), d2 < 0 && (d2 = 0), { left: h2, top: d2 };
7081
7054
  }
7082
7055
  const ia = { key: 0, style: { position: "absolute", inset: "0", pointerEvents: "none", zIndex: 25 } }, oa = ["onMouseenter"], la = ["data-note-marker-zone", "onMouseenter", "onMouseleave"], ha = ["onClick"], da = ["onClick"], ca = ["onClick"], ua = /* @__PURE__ */ defineComponent({ __name: "NoteMarkerLayer", props: { chapterId: {}, localPageIndex: {}, pdfPageWidth: {}, pdfPageHeight: {}, cssPageWidth: {}, cssPageHeight: {}, ui: {} }, setup(e14) {
7083
- const a2 = e14, { provides: i2 } = useCapability(na.id), d2 = ref([]), g2 = ref(null), m2 = ref(null);
7056
+ const a2 = e14, { provides: i2 } = useCapability(na.id), d2 = ref([]), p2 = ref(null), m2 = ref(null);
7084
7057
  watch(i2, (e15) => {
7085
7058
  if (e15) return e15.onNotesChange((e16) => {
7086
7059
  d2.value = e16.filter((e17) => e17.chapterId === a2.chapterId && e17.localPageIndex === a2.localPageIndex);
@@ -7091,7 +7064,7 @@ const ia = { key: 0, style: { position: "absolute", inset: "0", pointerEvents: "
7091
7064
  I2 && (document.removeEventListener("mousedown", I2), I2 = null), e15 && (I2 = (t2) => {
7092
7065
  var _a2;
7093
7066
  const s2 = t2.target;
7094
- ((_a2 = s2.closest) == null ? void 0 : _a2.call(s2, `[data-note-marker-zone="${e15}"]`)) || (m2.value = null, g2.value = null);
7067
+ ((_a2 = s2.closest) == null ? void 0 : _a2.call(s2, `[data-note-marker-zone="${e15}"]`)) || (m2.value = null, p2.value = null);
7095
7068
  }, document.addEventListener("mousedown", I2));
7096
7069
  }), onBeforeUnmount(() => {
7097
7070
  I2 && document.removeEventListener("mousedown", I2);
@@ -7111,7 +7084,7 @@ const ia = { key: 0, style: { position: "absolute", inset: "0", pointerEvents: "
7111
7084
  })(e15.rectsPdfCoord, t2, s2), l = m2.value === e15.noteId ? 72 : 0, h2 = Math.max(0, Math.min(o2.left, r2) - 8), d3 = Math.max(0, Math.min(o2.top, i3) - 8);
7112
7085
  return { zoneLeft: h2, zoneTop: d3, zoneW: Math.min(a2.cssPageWidth, Math.max(o2.left + o2.width, r2 + n9) + 8) - h2, zoneH: Math.max(o2.top + o2.height, i3 + n9 + 6 + l) + 8 - d3, iconLeft: r2, iconTop: i3, sx: t2, sy: s2 };
7113
7086
  }
7114
- return (t2, s2) => unref(i2) && d2.value.length && e14.pdfPageWidth && e14.pdfPageHeight ? (openBlock(), createElementBlock("div", ia, [(openBlock(true), createElementBlock(Fragment, null, renderList(d2.value, (e15) => (openBlock(), createElementBlock(Fragment, { key: e15.noteId }, [(openBlock(true), createElementBlock(Fragment, null, renderList(e15.rectsPdfCoord, (t3, s3) => (openBlock(), createElementBlock("div", { key: `${e15.noteId}-bg-${s3}`, style: normalizeStyle({ position: "absolute", left: t3.origin.x * C2(e15).sx + "px", top: t3.origin.y * C2(e15).sy + "px", width: t3.size.width * C2(e15).sx + "px", height: t3.size.height * C2(e15).sy + "px", background: S.value, borderRadius: "2px", pointerEvents: "auto" }), onMouseenter: (t4) => g2.value = e15.noteId }, null, 44, oa))), 128)), g2.value === e15.noteId || m2.value === e15.noteId ? (openBlock(), createElementBlock("div", { key: 0, "data-note-marker-zone": e15.noteId, style: normalizeStyle({ position: "absolute", left: `${C2(e15).zoneLeft}px`, top: `${C2(e15).zoneTop}px`, width: `${C2(e15).zoneW}px`, height: `${C2(e15).zoneH}px`, pointerEvents: "auto", zIndex: 26 }), onMouseenter: (t3) => g2.value = e15.noteId, onMouseleave: (t3) => m2.value !== e15.noteId && (g2.value = null) }, [createElementVNode("button", { type: "button", title: "笔记", style: normalizeStyle({ position: "absolute", left: C2(e15).iconLeft - C2(e15).zoneLeft + "px", top: C2(e15).iconTop - C2(e15).zoneTop + "px", width: `${b2.value}px`, height: `${b2.value}px`, border: "none", borderRadius: "50%", background: "#f59e0b", color: "#fff", cursor: "pointer", fontSize: "11px", padding: 0 }), onMousedown: s2[0] || (s2[0] = withModifiers(() => {
7087
+ return (t2, s2) => unref(i2) && d2.value.length && e14.pdfPageWidth && e14.pdfPageHeight ? (openBlock(), createElementBlock("div", ia, [(openBlock(true), createElementBlock(Fragment, null, renderList(d2.value, (e15) => (openBlock(), createElementBlock(Fragment, { key: e15.noteId }, [(openBlock(true), createElementBlock(Fragment, null, renderList(e15.rectsPdfCoord, (t3, s3) => (openBlock(), createElementBlock("div", { key: `${e15.noteId}-bg-${s3}`, style: normalizeStyle({ position: "absolute", left: t3.origin.x * C2(e15).sx + "px", top: t3.origin.y * C2(e15).sy + "px", width: t3.size.width * C2(e15).sx + "px", height: t3.size.height * C2(e15).sy + "px", background: S.value, borderRadius: "2px", pointerEvents: "auto" }), onMouseenter: (t4) => p2.value = e15.noteId }, null, 44, oa))), 128)), p2.value === e15.noteId || m2.value === e15.noteId ? (openBlock(), createElementBlock("div", { key: 0, "data-note-marker-zone": e15.noteId, style: normalizeStyle({ position: "absolute", left: `${C2(e15).zoneLeft}px`, top: `${C2(e15).zoneTop}px`, width: `${C2(e15).zoneW}px`, height: `${C2(e15).zoneH}px`, pointerEvents: "auto", zIndex: 26 }), onMouseenter: (t3) => p2.value = e15.noteId, onMouseleave: (t3) => m2.value !== e15.noteId && (p2.value = null) }, [createElementVNode("button", { type: "button", title: "笔记", style: normalizeStyle({ position: "absolute", left: C2(e15).iconLeft - C2(e15).zoneLeft + "px", top: C2(e15).iconTop - C2(e15).zoneTop + "px", width: `${b2.value}px`, height: `${b2.value}px`, border: "none", borderRadius: "50%", background: "#f59e0b", color: "#fff", cursor: "pointer", fontSize: "11px", padding: 0 }), onMousedown: s2[0] || (s2[0] = withModifiers(() => {
7115
7088
  }, ["stop"])), onClick: withModifiers((t3) => m2.value = m2.value === e15.noteId ? null : e15.noteId, ["stop"]) }, " 💬 ", 44, ha), m2.value === e15.noteId ? (openBlock(), createElementBlock("div", { key: 0, style: normalizeStyle({ position: "absolute", left: C2(e15).iconLeft - C2(e15).zoneLeft + "px", top: `${C2(e15).iconTop - C2(e15).zoneTop + b2.value + 4}px`, minWidth: "120px", padding: "6px", borderRadius: "8px", background: "#fff", border: "1px solid #e5e7eb", boxShadow: "0 4px 12px rgba(0,0,0,0.12)", zIndex: 30 }), onMousedown: s2[1] || (s2[1] = withModifiers(() => {
7116
7089
  }, ["stop"])) }, [createElementVNode("button", { type: "button", style: { display: "block", width: "100%", padding: "6px 8px", "font-size": "12px", border: "none", "border-radius": "4px", background: "transparent", color: "#334155", cursor: "pointer", "text-align": "left" }, onClick: (t3) => (function(e16) {
7117
7090
  var _a2;
@@ -7121,8 +7094,8 @@ const ia = { key: 0, style: { position: "absolute", inset: "0", pointerEvents: "
7121
7094
  return s3 = e15.noteId, (_a2 = i2.value) == null ? void 0 : _a2.requestDeleteNote(s3), void (m2.value = null);
7122
7095
  var s3;
7123
7096
  } }, " 删除 ", 8, ca)], 36)) : createCommentVNode("", true)], 44, la)) : createCommentVNode("", true)], 64))), 128))])) : createCommentVNode("", true);
7124
- } }), pa = { key: 0, style: { position: "absolute", inset: "0", pointerEvents: "none" } }, ga = ["title", "onClick"], ma = ["onClick"], fa = /* @__PURE__ */ defineComponent({ __name: "BookmarkMarkerLayer", props: { chapterId: {}, localPageIndex: {}, pdfPageWidth: {}, pdfPageHeight: {}, cssPageWidth: {}, cssPageHeight: {}, ui: {} }, setup(e14) {
7125
- const a2 = e14, { provides: i2 } = useCapability(vn.id), d2 = ref([]), g2 = ref(null), m2 = ref(null);
7097
+ } }), ga = { key: 0, style: { position: "absolute", inset: "0", pointerEvents: "none" } }, pa = ["title", "onClick"], ma = ["onClick"], fa = /* @__PURE__ */ defineComponent({ __name: "BookmarkMarkerLayer", props: { chapterId: {}, localPageIndex: {}, pdfPageWidth: {}, pdfPageHeight: {}, cssPageWidth: {}, cssPageHeight: {}, ui: {} }, setup(e14) {
7098
+ const a2 = e14, { provides: i2 } = useCapability(vn.id), d2 = ref([]), p2 = ref(null), m2 = ref(null);
7126
7099
  function I2() {
7127
7100
  const e15 = i2.value;
7128
7101
  e15 && (d2.value = e15.listBookmarks().filter((e16) => e16.anchor.chapterId === a2.chapterId && e16.anchor.localPageIndex === a2.localPageIndex));
@@ -7131,10 +7104,10 @@ const ia = { key: 0, style: { position: "absolute", inset: "0", pointerEvents: "
7131
7104
  if (e15) return I2(), e15.onBookmarksChange(I2);
7132
7105
  }, { immediate: true });
7133
7106
  let b2 = null;
7134
- watch(g2, (e15) => {
7107
+ watch(p2, (e15) => {
7135
7108
  b2 && (document.removeEventListener("mousedown", b2), b2 = null), e15 && (b2 = (e16) => {
7136
7109
  var _a2;
7137
- ((_a2 = m2.value) == null ? void 0 : _a2.contains(e16.target)) || (g2.value = null);
7110
+ ((_a2 = m2.value) == null ? void 0 : _a2.contains(e16.target)) || (p2.value = null);
7138
7111
  }, document.addEventListener("mousedown", b2));
7139
7112
  }), onBeforeUnmount(() => {
7140
7113
  b2 && document.removeEventListener("mousedown", b2);
@@ -7151,12 +7124,12 @@ const ia = { key: 0, style: { position: "absolute", inset: "0", pointerEvents: "
7151
7124
  })(e15);
7152
7125
  return { position: "absolute", left: `${Math.max(0, t2 - 6)}px`, top: `${Math.max(0, s2 - 6)}px`, width: `${S.value + 12}px`, height: `${S.value + 12}px`, pointerEvents: "auto", zIndex: 20 };
7153
7126
  }
7154
- return (t2, s2) => unref(i2) && d2.value.length && e14.pdfPageWidth && e14.pdfPageHeight ? (openBlock(), createElementBlock("div", pa, [(openBlock(true), createElementBlock(Fragment, null, renderList(d2.value, (e15) => (openBlock(), createElementBlock("div", { key: e15.id, style: normalizeStyle(C2(e15)), onMousedown: s2[1] || (s2[1] = withModifiers(() => {
7155
- }, ["stop"])) }, [createElementVNode("button", { type: "button", title: e15.label, style: normalizeStyle({ position: "absolute", left: "6px", top: "6px", width: `${S.value}px`, height: `${S.value}px`, border: "none", borderRadius: "4px", background: "#3b82f6", color: "#fff", cursor: "pointer", boxShadow: "0 2px 6px rgba(37, 99, 235, 0.35)", fontSize: "11px", padding: 0 }), onClick: withModifiers((t3) => g2.value = g2.value === e15.id ? null : e15.id, ["stop"]) }, " 🔖 ", 12, ga), g2.value === e15.id ? (openBlock(), createElementBlock("div", { key: 0, ref_for: true, ref_key: "deleteMenuRef", ref: m2, style: { position: "absolute", left: "6px", top: "-36px", zIndex: 30, pointerEvents: "auto", minWidth: "88px", padding: "4px", borderRadius: "6px", background: "#fff", border: "1px solid #e5e7eb", boxShadow: "0 4px 12px rgba(0,0,0,0.12)" }, onClick: s2[0] || (s2[0] = withModifiers(() => {
7127
+ return (t2, s2) => unref(i2) && d2.value.length && e14.pdfPageWidth && e14.pdfPageHeight ? (openBlock(), createElementBlock("div", ga, [(openBlock(true), createElementBlock(Fragment, null, renderList(d2.value, (e15) => (openBlock(), createElementBlock("div", { key: e15.id, style: normalizeStyle(C2(e15)), onMousedown: s2[1] || (s2[1] = withModifiers(() => {
7128
+ }, ["stop"])) }, [createElementVNode("button", { type: "button", title: e15.label, style: normalizeStyle({ position: "absolute", left: "6px", top: "6px", width: `${S.value}px`, height: `${S.value}px`, border: "none", borderRadius: "4px", background: "#3b82f6", color: "#fff", cursor: "pointer", boxShadow: "0 2px 6px rgba(37, 99, 235, 0.35)", fontSize: "11px", padding: 0 }), onClick: withModifiers((t3) => p2.value = p2.value === e15.id ? null : e15.id, ["stop"]) }, " 🔖 ", 12, pa), p2.value === e15.id ? (openBlock(), createElementBlock("div", { key: 0, ref_for: true, ref_key: "deleteMenuRef", ref: m2, style: { position: "absolute", left: "6px", top: "-36px", zIndex: 30, pointerEvents: "auto", minWidth: "88px", padding: "4px", borderRadius: "6px", background: "#fff", border: "1px solid #e5e7eb", boxShadow: "0 4px 12px rgba(0,0,0,0.12)" }, onClick: s2[0] || (s2[0] = withModifiers(() => {
7156
7129
  }, ["stop"])) }, [createElementVNode("button", { type: "button", style: { width: "100%", padding: "6px 8px", "font-size": "12px", border: "none", "border-radius": "4px", background: "transparent", color: "#dc2626", cursor: "pointer", "text-align": "left" }, onClick: (t3) => (async function(e16) {
7157
7130
  const t4 = i2.value;
7158
7131
  if (!t4) return;
7159
- await t4.requestRemoveBookmark(e16) && (g2.value = null);
7132
+ await t4.requestRemoveBookmark(e16) && (p2.value = null);
7160
7133
  })(e15.id) }, " 删除书签 ", 8, ma)], 512)) : createCommentVNode("", true)], 36))), 128))])) : createCommentVNode("", true);
7161
7134
  } });
7162
7135
  function va(e14) {
@@ -7199,10 +7172,10 @@ function ya(e14, s2) {
7199
7172
  if (s3.structurallyLocked) return h$1("span", o2);
7200
7173
  if (h2 = s3.annotation.object.type, !Le$1.has(h2)) return h$1("span", o2);
7201
7174
  var h2;
7202
- const d2 = n9.value.forDocument(t2), { pageIndex: c2, id: u2 } = s3.annotation.object, p2 = () => {
7175
+ const d2 = n9.value.forDocument(t2), { pageIndex: c2, id: u2 } = s3.annotation.object, g2 = () => {
7203
7176
  d2 == null ? void 0 : d2.deleteAnnotation(c2, u2);
7204
- }, g2 = { position: "absolute", pointerEvents: "auto", left: "50%", transform: "translateX(-50%)", top: (i3 == null ? void 0 : i3.suggestTop) ? void 0 : `${a3.size.height + 8}px`, bottom: (i3 == null ? void 0 : i3.suggestTop) ? `${a3.size.height + 8}px` : void 0 }, m2 = (r2 == null ? void 0 : r2.renderMenu) ? r2.renderMenu({ pageIndex: c2, annotationId: u2, onDelete: p2 }) : h$1("button", { type: "button", style: Ca, onClick: p2 }, "删除");
7205
- return h$1("div", o2, [h$1("div", { style: g2 }, [h$1("div", { style: Sa, role: "toolbar", "aria-label": "划线标注" }, [m2])])]);
7177
+ }, p2 = { position: "absolute", pointerEvents: "auto", left: "50%", transform: "translateX(-50%)", top: (i3 == null ? void 0 : i3.suggestTop) ? void 0 : `${a3.size.height + 8}px`, bottom: (i3 == null ? void 0 : i3.suggestTop) ? `${a3.size.height + 8}px` : void 0 }, m2 = (r2 == null ? void 0 : r2.renderMenu) ? r2.renderMenu({ pageIndex: c2, annotationId: u2, onDelete: g2 }) : h$1("button", { type: "button", style: Ca, onClick: g2 }, "删除");
7178
+ return h$1("div", o2, [h$1("div", { style: p2 }, [h$1("div", { style: Sa, role: "toolbar", "aria-label": "划线标注" }, [m2])])]);
7206
7179
  };
7207
7180
  });
7208
7181
  }
@@ -7242,7 +7215,7 @@ const wa = /* @__PURE__ */ defineComponent({ __name: "ChapterPageSurface", props
7242
7215
  if (s3) return s3;
7243
7216
  }
7244
7217
  return t2.defaultMenu;
7245
- }), p2 = ya(r2, s2.features), v = computed(() => (function(e15, t2) {
7218
+ }), g2 = ya(r2, s2.features), v = computed(() => (function(e15, t2) {
7246
7219
  if (e15 || t2) return (s3) => {
7247
7220
  if (e15) {
7248
7221
  const t3 = e15(s3);
@@ -7250,7 +7223,7 @@ const wa = /* @__PURE__ */ defineComponent({ __name: "ChapterPageSurface", props
7250
7223
  }
7251
7224
  return (t2 == null ? void 0 : t2(s3)) ?? null;
7252
7225
  };
7253
- })(s2.annotationSelectionMenu, p2.value)), y = computed(() => {
7226
+ })(s2.annotationSelectionMenu, g2.value)), y = computed(() => {
7254
7227
  var _a2;
7255
7228
  return (_a2 = s2.renderPageOverlay) == null ? void 0 : _a2.call(s2, s2.item);
7256
7229
  }), w2 = computed(() => {
@@ -7263,7 +7236,7 @@ const wa = /* @__PURE__ */ defineComponent({ __name: "ChapterPageSurface", props
7263
7236
  return (t2, s3) => e14.item.isPlaceholder ? createCommentVNode("", true) : (openBlock(), createBlock(unref(GlobalPointerProvider), { key: 0, "document-id": r2.value }, { default: withCtx(() => [createVNode(unref(Rotate), { "document-id": r2.value, "page-index": a2.value, style: { backgroundColor: "#fff" } }, { default: withCtx(() => [createVNode(unref(PagePointerProvider), { "document-id": r2.value, "page-index": a2.value, style: normalizeStyle(unref(Ie$1)), onPointerdown: unref(be$1) }, { default: withCtx(() => [createVNode(unref(fr), { "chapter-id": e14.item.chapterId, "local-page-index": e14.item.localPageIndex, "pdf-document-id": r2.value, "pdf-page-index": a2.value }, null, 8, ["chapter-id", "local-page-index", "pdf-document-id", "pdf-page-index"]), createVNode(unref(SelectionLayer), { "document-id": r2.value, "page-index": a2.value, "text-style": w2.value, "selection-menu": u2.value }, null, 8, ["document-id", "page-index", "text-style", "selection-menu"]), e14.showRedactionLayer ? (openBlock(), createBlock(unref(RedactionLayer), { key: 0, "document-id": r2.value, "page-index": a2.value, "selection-menu": e14.redactionSelectionMenu }, null, 8, ["document-id", "page-index", "selection-menu"])) : createCommentVNode("", true), createVNode(unref(AnnotationLayer), { "document-id": r2.value, "page-index": a2.value, "selection-menu": v.value }, null, 8, ["document-id", "page-index", "selection-menu"]), e14.showBookmarkMarkers && d2.value ? (openBlock(), createBlock(fa, { key: 1, "chapter-id": e14.item.chapterId, "local-page-index": e14.item.localPageIndex, "pdf-page-width": d2.value.size.width, "pdf-page-height": d2.value.size.height, "css-page-width": e14.item.width, "css-page-height": e14.item.height, ui: e14.bookmarkMarkerUi }, null, 8, ["chapter-id", "local-page-index", "pdf-page-width", "pdf-page-height", "css-page-width", "css-page-height", "ui"])) : createCommentVNode("", true), y.value ? (openBlock(), createBlock(resolveDynamicComponent(y.value), { key: 2 })) : createCommentVNode("", true), e14.showNoteMarkers && d2.value ? (openBlock(), createBlock(ua, { key: 3, "chapter-id": e14.item.chapterId, "local-page-index": e14.item.localPageIndex, "pdf-page-width": d2.value.size.width, "pdf-page-height": d2.value.size.height, "css-page-width": e14.item.width, "css-page-height": e14.item.height, ui: e14.noteMarkerUi }, null, 8, ["chapter-id", "local-page-index", "pdf-page-width", "pdf-page-height", "css-page-width", "css-page-height", "ui"])) : createCommentVNode("", true), renderSlot(t2.$slots, "default")]), _: 3 }, 8, ["document-id", "page-index", "style", "onPointerdown"])]), _: 3 }, 8, ["document-id", "page-index"])]), _: 3 }, 8, ["document-id"]));
7264
7237
  } });
7265
7238
  const Ma = /* @__PURE__ */ defineComponent({ __name: "HoverBookmarkLayer", props: { item: {}, pdfPageWidth: {}, pdfPageHeight: {}, cssPageWidth: {}, cssPageHeight: {}, hoverUi: {} }, setup(e14) {
7266
- const a2 = e14, i2 = computed(() => va(a2.item)), { provides: d2 } = useCapability(SelectionPlugin.id), { provides: u2 } = useCapability(vn.id), p2 = ref(null), g2 = ref(null), m2 = ref(null), I2 = ref(null), b2 = computed(() => {
7239
+ const a2 = e14, i2 = computed(() => va(a2.item)), { provides: d2 } = useCapability(SelectionPlugin.id), { provides: u2 } = useCapability(vn.id), g2 = ref(null), p2 = ref(null), m2 = ref(null), I2 = ref(null), b2 = computed(() => {
7267
7240
  var _a2;
7268
7241
  return ((_a2 = a2.hoverUi) == null ? void 0 : _a2.iconSize) ?? 16;
7269
7242
  }), S = computed(() => I2.value ?? m2.value);
@@ -7272,10 +7245,10 @@ const Ma = /* @__PURE__ */ defineComponent({ __name: "HoverBookmarkLayer", props
7272
7245
  const e15 = d2.value;
7273
7246
  if (!e15) return;
7274
7247
  const t2 = e15.forDocument(i2.value).getState().geometry[a2.item.localPageIndex];
7275
- t2 && (g2.value = t2);
7248
+ t2 && (p2.value = t2);
7276
7249
  }
7277
7250
  watch([d2, i2, () => a2.item.localPageIndex], ([e15]) => {
7278
- if (C2 == null ? void 0 : C2(), C2 = null, cancelAnimationFrame(y), g2.value = null, !e15) return;
7251
+ if (C2 == null ? void 0 : C2(), C2 = null, cancelAnimationFrame(y), p2.value = null, !e15) return;
7279
7252
  const t2 = e15.forDocument(i2.value);
7280
7253
  C2 = t2.onSelectionChange(w2);
7281
7254
  let s2 = false;
@@ -7293,15 +7266,15 @@ const Ma = /* @__PURE__ */ defineComponent({ __name: "HoverBookmarkLayer", props
7293
7266
  };
7294
7267
  }, { immediate: true });
7295
7268
  let x = null;
7296
- watch([g2, () => a2.pdfPageWidth, I2, d2], () => {
7297
- x && (document.removeEventListener("mousemove", x), x = null), g2.value && a2.pdfPageWidth && (x = (e15) => {
7269
+ watch([p2, () => a2.pdfPageWidth, I2, d2], () => {
7270
+ x && (document.removeEventListener("mousemove", x), x = null), p2.value && a2.pdfPageWidth && (x = (e15) => {
7298
7271
  if (I2.value) return;
7299
7272
  const t2 = d2.value;
7300
7273
  if (t2) try {
7301
7274
  if (t2.forDocument(i2.value).getState().selecting) return void (m2.value = null);
7302
7275
  } catch {
7303
7276
  }
7304
- const s2 = p2.value;
7277
+ const s2 = g2.value;
7305
7278
  if (!s2) return;
7306
7279
  const n9 = s2.getBoundingClientRect();
7307
7280
  if (e15.clientX < n9.left || e15.clientX > n9.right || e15.clientY < n9.top || e15.clientY > n9.bottom) return void (m2.value = null);
@@ -7312,7 +7285,7 @@ const Ma = /* @__PURE__ */ defineComponent({ __name: "HoverBookmarkLayer", props
7312
7285
  if (!n10) return null;
7313
7286
  const r3 = rectsWithinSlice(e16, n10.from, n10.to);
7314
7287
  return 0 === r3.length ? null : { lineRects: r3, charFrom: n10.from, charTo: n10.to };
7315
- })(g2.value, { x: (e15.clientX - n9.left) / (a2.cssPageWidth / a2.pdfPageWidth), y: (e15.clientY - n9.top) / (a2.cssPageHeight / a2.pdfPageHeight) });
7288
+ })(p2.value, { x: (e15.clientX - n9.left) / (a2.cssPageWidth / a2.pdfPageWidth), y: (e15.clientY - n9.top) / (a2.cssPageHeight / a2.pdfPageHeight) });
7316
7289
  m2.value = (r2 == null ? void 0 : r2.lineRects) ?? null;
7317
7290
  }, document.addEventListener("mousemove", x));
7318
7291
  }, { immediate: true }), onBeforeUnmount(() => {
@@ -7320,10 +7293,10 @@ const Ma = /* @__PURE__ */ defineComponent({ __name: "HoverBookmarkLayer", props
7320
7293
  });
7321
7294
  const L2 = computed(() => {
7322
7295
  const e15 = S.value;
7323
- return (e15 == null ? void 0 : e15.length) ? gn(a2.item.chapterId, a2.item.localPageIndex, e15, { globalPageIndex: a2.item.globalPageIndex, globalPageNumber: a2.item.globalPageNumber }) : null;
7296
+ return (e15 == null ? void 0 : e15.length) ? pn(a2.item.chapterId, a2.item.localPageIndex, e15, { globalPageIndex: a2.item.globalPageIndex, globalPageNumber: a2.item.globalPageNumber }) : null;
7324
7297
  }), $2 = computed(() => {
7325
7298
  const e15 = L2.value, t2 = u2.value;
7326
- return !(!e15 || !t2) && t2.listBookmarks().some((t3) => pn(t3.anchor, e15));
7299
+ return !(!e15 || !t2) && t2.listBookmarks().some((t3) => gn(t3.anchor, e15));
7327
7300
  });
7328
7301
  function k2() {
7329
7302
  const e15 = u2.value, t2 = L2.value;
@@ -7337,18 +7310,18 @@ const Ma = /* @__PURE__ */ defineComponent({ __name: "HoverBookmarkLayer", props
7337
7310
  });
7338
7311
  return (t2, s2) => {
7339
7312
  var _a2;
7340
- return unref(u2) && e14.pdfPageWidth && e14.pdfPageHeight ? (openBlock(), createElementBlock("div", { key: 0, ref_key: "rootRef", ref: p2, style: { position: "absolute", inset: "0", zIndex: 14, pointerEvents: "none" } }, [D2.value && S.value && !$2.value ? (openBlock(), createElementBlock("div", { key: 0, style: normalizeStyle({ position: "absolute", left: `${D2.value.zoneLeft}px`, top: `${D2.value.zoneTop}px`, width: `${D2.value.size + 20}px`, height: `${(((_a2 = S.value[S.value.length - 1]) == null ? void 0 : _a2.size.height) ?? 0) * (e14.cssPageHeight / e14.pdfPageHeight) + D2.value.size + 12}px`, pointerEvents: "auto" }), onMouseenter: s2[0] || (s2[0] = (e15) => I2.value = S.value), onMouseleave: s2[1] || (s2[1] = (e15) => I2.value = null) }, [createElementVNode("button", { type: "button", title: "添加书签", style: normalizeStyle({ position: "absolute", left: D2.value.iconLeft - D2.value.zoneLeft + "px", top: D2.value.iconTop - D2.value.zoneTop + "px", width: `${D2.value.size}px`, height: `${D2.value.size}px`, cursor: "pointer", display: "flex", alignItems: "center", justifyContent: "center", background: "#3b82f6", color: "#fff", border: "none", borderRadius: "4px", boxShadow: "0 2px 8px rgba(37, 99, 235, 0.45)", fontSize: "12px", padding: 0 }), onClick: withModifiers(k2, ["stop"]) }, " 🔖 ", 4)], 36)) : createCommentVNode("", true)], 512)) : createCommentVNode("", true);
7313
+ return unref(u2) && e14.pdfPageWidth && e14.pdfPageHeight ? (openBlock(), createElementBlock("div", { key: 0, ref_key: "rootRef", ref: g2, style: { position: "absolute", inset: "0", zIndex: 14, pointerEvents: "none" } }, [D2.value && S.value && !$2.value ? (openBlock(), createElementBlock("div", { key: 0, style: normalizeStyle({ position: "absolute", left: `${D2.value.zoneLeft}px`, top: `${D2.value.zoneTop}px`, width: `${D2.value.size + 20}px`, height: `${(((_a2 = S.value[S.value.length - 1]) == null ? void 0 : _a2.size.height) ?? 0) * (e14.cssPageHeight / e14.pdfPageHeight) + D2.value.size + 12}px`, pointerEvents: "auto" }), onMouseenter: s2[0] || (s2[0] = (e15) => I2.value = S.value), onMouseleave: s2[1] || (s2[1] = (e15) => I2.value = null) }, [createElementVNode("button", { type: "button", title: "添加书签", style: normalizeStyle({ position: "absolute", left: D2.value.iconLeft - D2.value.zoneLeft + "px", top: D2.value.iconTop - D2.value.zoneTop + "px", width: `${D2.value.size}px`, height: `${D2.value.size}px`, cursor: "pointer", display: "flex", alignItems: "center", justifyContent: "center", background: "#3b82f6", color: "#fff", border: "none", borderRadius: "4px", boxShadow: "0 2px 8px rgba(37, 99, 235, 0.45)", fontSize: "12px", padding: 0 }), onClick: withModifiers(k2, ["stop"]) }, " 🔖 ", 4)], 36)) : createCommentVNode("", true)], 512)) : createCommentVNode("", true);
7341
7314
  };
7342
- } }), xa = { key: 0, width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "" }, La = { key: 1, width: "24", height: "24", viewBox: "0 0 28 28", fill: "none", "aria-hidden": "" }, $a = { key: 0, x: "5", y: "4", width: "18", height: "20", rx: "3", fill: "#fde047" }, ka = { key: 1, d: "M6 22h16", stroke: "#dc2626", "stroke-width": "2.2", "stroke-linecap": "round" }, Da = { key: 2, d: "M6 22c2-2 3-2 5 0s3 2 5 0 3-2 5 0", stroke: "#dc2626", "stroke-width": "2", "stroke-linecap": "round", fill: "none" }, Ea = { key: 3, d: "M5 14h18", stroke: "#dc2626", "stroke-width": "2.2", "stroke-linecap": "round" }, Ta = { key: 2, width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "" }, Ua = /* @__PURE__ */ defineComponent({ __name: "SelectionToolbarIcons", props: { kind: {} }, setup: (e14) => (t2, s2) => "copy" === e14.kind ? (openBlock(), createElementBlock("svg", xa, [...s2[0] || (s2[0] = [createElementVNode("rect", { x: "8.5", y: "8.5", width: "11", height: "13", rx: "2.25", fill: "#f1f5f9", stroke: "#94a3b8", "stroke-width": "1.35" }, null, -1), createElementVNode("rect", { x: "4.5", y: "3.5", width: "11", height: "13", rx: "2.25", fill: "#ffffff", stroke: "#334155", "stroke-width": "1.5" }, null, -1), createElementVNode("path", { d: "M7.5 7h5.5a1.5 1.5 0 0 1 1.5 1.5V14", stroke: "#64748b", "stroke-width": "1.2", "stroke-linecap": "round" }, null, -1)])])) : "note" !== e14.kind ? (openBlock(), createElementBlock("svg", La, ["highlight" === e14.kind ? (openBlock(), createElementBlock("rect", $a)) : createCommentVNode("", true), s2[1] || (s2[1] = createElementVNode("text", { x: "14", y: "19", "text-anchor": "middle", "font-size": "15", "font-weight": "700", "font-family": "system-ui, -apple-system, sans-serif", fill: "#0f172a" }, " A ", -1)), "underline" === e14.kind ? (openBlock(), createElementBlock("path", ka)) : "squiggly" === e14.kind ? (openBlock(), createElementBlock("path", Da)) : "strikeout" === e14.kind ? (openBlock(), createElementBlock("path", Ea)) : createCommentVNode("", true)])) : (openBlock(), createElementBlock("svg", Ta, [...s2[2] || (s2[2] = [createElementVNode("path", { d: "M8 3h8l4 4v14H8V3z", fill: "#fef3c7", stroke: "#d97706", "stroke-width": "1.2", "stroke-linejoin": "round" }, null, -1), createElementVNode("path", { d: "M16 3v4h4", stroke: "#d97706", "stroke-width": "1.2" }, null, -1), createElementVNode("path", { d: "M10 12h6M10 16h4", stroke: "#92400e", "stroke-width": "1.2", "stroke-linecap": "round" }, null, -1)])])) }), Fa = ["title", "aria-label", "onMouseenter", "onClick"], Oa = ["title", "onMouseenter", "onClick"], Ra = { style: { "font-size": "11px", "font-weight": "600" } }, Na = /* @__PURE__ */ defineComponent({ __name: "SelectionToolbarCard", props: { placementAbove: { type: Boolean }, anchorHeight: {}, hiddenBuiltinActions: {}, extraActions: {}, renderCopyIcon: { type: Function } }, emits: ["action"], setup(e14, { emit: n9 }) {
7343
- const r2 = e14, a2 = n9, i2 = [{ id: "highlight", label: "高亮背景" }, { id: "underline", label: "下划线" }, { id: "squiggly", label: "波浪线" }, { id: "strikeout", label: "删除线" }], d2 = computed(() => new Set(r2.hiddenBuiltinActions ?? [])), g2 = computed(() => !d2.value.has("copy")), f2 = computed(() => i2.filter((e15) => !d2.value.has(e15.id))), v = computed(() => !d2.value.has("note")), I2 = computed(() => [...r2.extraActions ?? []].sort((e15, t2) => (e15.order ?? 0) - (t2.order ?? 0))), b2 = computed(() => f2.value.length > 0 || I2.value.length > 0), w2 = ref(null), M2 = computed(() => ({ position: "absolute", pointerEvents: "auto", left: "50%", transform: "translateX(-50%)", top: r2.placementAbove ? void 0 : `${r2.anchorHeight + 10}px`, bottom: r2.placementAbove ? `${r2.anchorHeight + 10}px` : void 0, display: "flex", alignItems: "center", gap: "2px", padding: "4px 6px", borderRadius: "12px", background: "rgba(255, 255, 255, 0.96)", border: "1px solid rgba(15, 23, 42, 0.06)", boxShadow: "0 2px 8px rgba(15, 23, 42, 0.08), 0 12px 32px rgba(15, 23, 42, 0.1)", backdropFilter: "blur(10px)", WebkitBackdropFilter: "blur(10px)" }));
7315
+ } }), xa = { key: 0, width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "" }, La = { key: 1, width: "24", height: "24", viewBox: "0 0 28 28", fill: "none", "aria-hidden": "" }, $a = { key: 0, x: "5", y: "4", width: "18", height: "20", rx: "3", fill: "#fde047" }, ka = { key: 1, d: "M6 22h16", stroke: "#dc2626", "stroke-width": "2.2", "stroke-linecap": "round" }, Da = { key: 2, d: "M6 22c2-2 3-2 5 0s3 2 5 0 3-2 5 0", stroke: "#dc2626", "stroke-width": "2", "stroke-linecap": "round", fill: "none" }, Ea = { key: 3, d: "M5 14h18", stroke: "#dc2626", "stroke-width": "2.2", "stroke-linecap": "round" }, Ua = { key: 2, width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "" }, Ta = /* @__PURE__ */ defineComponent({ __name: "SelectionToolbarIcons", props: { kind: {} }, setup: (e14) => (t2, s2) => "copy" === e14.kind ? (openBlock(), createElementBlock("svg", xa, [...s2[0] || (s2[0] = [createElementVNode("rect", { x: "8.5", y: "8.5", width: "11", height: "13", rx: "2.25", fill: "#f1f5f9", stroke: "#94a3b8", "stroke-width": "1.35" }, null, -1), createElementVNode("rect", { x: "4.5", y: "3.5", width: "11", height: "13", rx: "2.25", fill: "#ffffff", stroke: "#334155", "stroke-width": "1.5" }, null, -1), createElementVNode("path", { d: "M7.5 7h5.5a1.5 1.5 0 0 1 1.5 1.5V14", stroke: "#64748b", "stroke-width": "1.2", "stroke-linecap": "round" }, null, -1)])])) : "note" !== e14.kind ? (openBlock(), createElementBlock("svg", La, ["highlight" === e14.kind ? (openBlock(), createElementBlock("rect", $a)) : createCommentVNode("", true), s2[1] || (s2[1] = createElementVNode("text", { x: "14", y: "19", "text-anchor": "middle", "font-size": "15", "font-weight": "700", "font-family": "system-ui, -apple-system, sans-serif", fill: "#0f172a" }, " A ", -1)), "underline" === e14.kind ? (openBlock(), createElementBlock("path", ka)) : "squiggly" === e14.kind ? (openBlock(), createElementBlock("path", Da)) : "strikeout" === e14.kind ? (openBlock(), createElementBlock("path", Ea)) : createCommentVNode("", true)])) : (openBlock(), createElementBlock("svg", Ua, [...s2[2] || (s2[2] = [createElementVNode("path", { d: "M8 3h8l4 4v14H8V3z", fill: "#fef3c7", stroke: "#d97706", "stroke-width": "1.2", "stroke-linejoin": "round" }, null, -1), createElementVNode("path", { d: "M16 3v4h4", stroke: "#d97706", "stroke-width": "1.2" }, null, -1), createElementVNode("path", { d: "M10 12h6M10 16h4", stroke: "#92400e", "stroke-width": "1.2", "stroke-linecap": "round" }, null, -1)])])) }), Fa = ["title", "aria-label", "onMouseenter", "onClick"], Na = ["title", "onMouseenter", "onClick"], Aa = { style: { "font-size": "11px", "font-weight": "600" } }, Va = /* @__PURE__ */ defineComponent({ __name: "SelectionToolbarCard", props: { placementAbove: { type: Boolean }, anchorHeight: {}, hiddenBuiltinActions: {}, extraActions: {}, renderCopyIcon: { type: Function } }, emits: ["action"], setup(e14, { emit: n9 }) {
7316
+ const r2 = e14, a2 = n9, i2 = [{ id: "highlight", label: "高亮背景" }, { id: "underline", label: "下划线" }, { id: "squiggly", label: "波浪线" }, { id: "strikeout", label: "删除线" }], d2 = computed(() => new Set(r2.hiddenBuiltinActions ?? [])), p2 = computed(() => !d2.value.has("copy")), f2 = computed(() => i2.filter((e15) => !d2.value.has(e15.id))), v = computed(() => !d2.value.has("note")), I2 = computed(() => [...r2.extraActions ?? []].sort((e15, t2) => (e15.order ?? 0) - (t2.order ?? 0))), b2 = computed(() => f2.value.length > 0 || I2.value.length > 0), w2 = ref(null), M2 = computed(() => ({ position: "absolute", pointerEvents: "auto", left: "50%", transform: "translateX(-50%)", top: r2.placementAbove ? void 0 : `${r2.anchorHeight + 10}px`, bottom: r2.placementAbove ? `${r2.anchorHeight + 10}px` : void 0, display: "flex", alignItems: "center", gap: "2px", padding: "4px 6px", borderRadius: "12px", background: "rgba(255, 255, 255, 0.96)", border: "1px solid rgba(15, 23, 42, 0.06)", boxShadow: "0 2px 8px rgba(15, 23, 42, 0.08), 0 12px 32px rgba(15, 23, 42, 0.1)", backdropFilter: "blur(10px)", WebkitBackdropFilter: "blur(10px)" }));
7344
7317
  function x(e15, t2 = false) {
7345
7318
  return { display: "flex", alignItems: "center", justifyContent: "center", width: "32px", height: "32px", padding: 0, margin: 0, border: "none", borderRadius: "8px", background: w2.value === e15 ? t2 ? "#fffbeb" : "#f1f5f9" : "transparent", color: t2 ? "#b45309" : "#334155", cursor: "pointer", flexShrink: 0, WebkitAppearance: "none", appearance: "none" };
7346
7319
  }
7347
7320
  const L2 = { width: "1px", height: "20px", margin: "0 4px", background: "rgba(15, 23, 42, 0.1)", flexShrink: 0 };
7348
- return (t2, s2) => (openBlock(), createElementBlock("div", { role: "toolbar", "aria-label": "选区工具", style: normalizeStyle(M2.value) }, [g2.value ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [createElementVNode("button", { type: "button", title: "复制", "aria-label": "复制", style: normalizeStyle(x("copy")), onMouseenter: s2[0] || (s2[0] = (e15) => w2.value = "copy"), onMouseleave: s2[1] || (s2[1] = (e15) => w2.value = null), onClick: s2[2] || (s2[2] = (e15) => a2("action", "copy")) }, [e14.renderCopyIcon ? (openBlock(), createBlock(resolveDynamicComponent(e14.renderCopyIcon), { key: 0 })) : (openBlock(), createBlock(Ua, { key: 1, kind: "copy" }))], 36), b2.value ? (openBlock(), createElementBlock("span", { key: 0, style: L2, "aria-hidden": "" })) : createCommentVNode("", true)], 64)) : createCommentVNode("", true), (openBlock(true), createElementBlock(Fragment, null, renderList(f2.value, (e15) => (openBlock(), createElementBlock("button", { key: e15.id, type: "button", title: e15.label, "aria-label": e15.label, style: normalizeStyle(x(e15.id)), onMouseenter: (t3) => w2.value = e15.id, onMouseleave: s2[3] || (s2[3] = (e16) => w2.value = null), onClick: (t3) => a2("action", e15.id) }, [createVNode(Ua, { kind: e15.id }, null, 8, ["kind"])], 44, Fa))), 128)), (openBlock(true), createElementBlock(Fragment, null, renderList(I2.value, (e15) => (openBlock(), createElementBlock("button", { key: e15.id, type: "button", title: e15.label, style: normalizeStyle(x(e15.id)), onMouseenter: (t3) => w2.value = e15.id, onMouseleave: s2[4] || (s2[4] = (e16) => w2.value = null), onClick: (t3) => a2("action", e15.id) }, [createElementVNode("span", Ra, toDisplayString(e15.label.slice(0, 2)), 1)], 44, Oa))), 128)), v.value ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [b2.value || g2.value ? (openBlock(), createElementBlock("span", { key: 0, style: L2, "aria-hidden": "" })) : createCommentVNode("", true), createElementVNode("button", { type: "button", title: "添加笔记", "aria-label": "添加笔记", style: normalizeStyle(x("note", true)), onMouseenter: s2[5] || (s2[5] = (e15) => w2.value = "note"), onMouseleave: s2[6] || (s2[6] = (e15) => w2.value = null), onClick: s2[7] || (s2[7] = (e15) => a2("action", "note")) }, [createVNode(Ua, { kind: "note" })], 36)], 64)) : createCommentVNode("", true)], 4));
7349
- } }), Aa = { highlight: "highlight", underline: "underline", squiggly: "squiggly", strikeout: "strikeout" };
7350
- const Va = /* @__PURE__ */ defineComponent({ __name: "PdfChapterViewport", props: { className: {}, features: {}, buildSelectionMenu: {}, annotationSelectionMenu: {}, redactionSelectionMenu: {}, showNoteMarkers: { type: Boolean, default: true }, showBookmarkMarkers: { type: Boolean, default: true }, showRedactionLayer: { type: Boolean, default: false }, renderPageOverlay: {}, onExtraSelectionAction: {} }, setup(e14) {
7351
- const s2 = e14, n9 = computed(() => s2.features), { hostRef: r2 } = Hn(n9), a2 = computed(() => {
7321
+ return (t2, s2) => (openBlock(), createElementBlock("div", { role: "toolbar", "aria-label": "选区工具", style: normalizeStyle(M2.value) }, [p2.value ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [createElementVNode("button", { type: "button", title: "复制", "aria-label": "复制", style: normalizeStyle(x("copy")), onMouseenter: s2[0] || (s2[0] = (e15) => w2.value = "copy"), onMouseleave: s2[1] || (s2[1] = (e15) => w2.value = null), onClick: s2[2] || (s2[2] = (e15) => a2("action", "copy")) }, [e14.renderCopyIcon ? (openBlock(), createBlock(resolveDynamicComponent(e14.renderCopyIcon), { key: 0 })) : (openBlock(), createBlock(Ta, { key: 1, kind: "copy" }))], 36), b2.value ? (openBlock(), createElementBlock("span", { key: 0, style: L2, "aria-hidden": "" })) : createCommentVNode("", true)], 64)) : createCommentVNode("", true), (openBlock(true), createElementBlock(Fragment, null, renderList(f2.value, (e15) => (openBlock(), createElementBlock("button", { key: e15.id, type: "button", title: e15.label, "aria-label": e15.label, style: normalizeStyle(x(e15.id)), onMouseenter: (t3) => w2.value = e15.id, onMouseleave: s2[3] || (s2[3] = (e16) => w2.value = null), onClick: (t3) => a2("action", e15.id) }, [createVNode(Ta, { kind: e15.id }, null, 8, ["kind"])], 44, Fa))), 128)), (openBlock(true), createElementBlock(Fragment, null, renderList(I2.value, (e15) => (openBlock(), createElementBlock("button", { key: e15.id, type: "button", title: e15.label, style: normalizeStyle(x(e15.id)), onMouseenter: (t3) => w2.value = e15.id, onMouseleave: s2[4] || (s2[4] = (e16) => w2.value = null), onClick: (t3) => a2("action", e15.id) }, [createElementVNode("span", Aa, toDisplayString(e15.label.slice(0, 2)), 1)], 44, Na))), 128)), v.value ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [b2.value || p2.value ? (openBlock(), createElementBlock("span", { key: 0, style: L2, "aria-hidden": "" })) : createCommentVNode("", true), createElementVNode("button", { type: "button", title: "添加笔记", "aria-label": "添加笔记", style: normalizeStyle(x("note", true)), onMouseenter: s2[5] || (s2[5] = (e15) => w2.value = "note"), onMouseleave: s2[6] || (s2[6] = (e15) => w2.value = null), onClick: s2[7] || (s2[7] = (e15) => a2("action", "note")) }, [createVNode(Ta, { kind: "note" })], 36)], 64)) : createCommentVNode("", true)], 4));
7322
+ } }), Oa = { highlight: "highlight", underline: "underline", squiggly: "squiggly", strikeout: "strikeout" };
7323
+ const Ra = /* @__PURE__ */ defineComponent({ __name: "PdfChapterViewport", props: { className: {}, features: {}, buildSelectionMenu: {}, annotationSelectionMenu: {}, redactionSelectionMenu: {}, showNoteMarkers: { type: Boolean, default: true }, showBookmarkMarkers: { type: Boolean, default: true }, showRedactionLayer: { type: Boolean, default: false }, renderPageOverlay: {}, onExtraSelectionAction: {} }, setup(e14) {
7324
+ const s2 = e14, n9 = computed(() => s2.features), { hostRef: r2 } = Wn(n9), a2 = computed(() => {
7352
7325
  var _a2, _b;
7353
7326
  return { background: ((_b = (_a2 = s2.features) == null ? void 0 : _a2.scrollViewport) == null ? void 0 : _b.background) ?? Se$1 };
7354
7327
  }), i2 = (function() {
@@ -7370,7 +7343,7 @@ const Va = /* @__PURE__ */ defineComponent({ __name: "PdfChapterViewport", props
7370
7343
  var _a2;
7371
7344
  return !!((_a2 = e15.value) == null ? void 0 : _a2.getPlugin(vn.id));
7372
7345
  });
7373
- })(), p2 = computed(() => {
7346
+ })(), g2 = computed(() => {
7374
7347
  var _a2, _b;
7375
7348
  return s2.showNoteMarkers && c2.value && false !== ((_b = (_a2 = s2.features) == null ? void 0 : _a2.notes) == null ? void 0 : _b.enabled);
7376
7349
  }), m2 = computed(() => {
@@ -7399,7 +7372,7 @@ const Va = /* @__PURE__ */ defineComponent({ __name: "PdfChapterViewport", props
7399
7372
  const d2 = va(t2.item), c3 = Pa(t2.item);
7400
7373
  return (u3) => {
7401
7374
  var _a3, _b2, _c2, _d;
7402
- return h$1("div", u3.menuWrapperProps, h$1(Na, { placementAbove: !!((_a3 = u3.placement) == null ? void 0 : _a3.suggestTop), anchorHeight: u3.rect.size.height, hiddenBuiltinActions: (_b2 = n10.value) == null ? void 0 : _b2.hiddenBuiltinActions, extraActions: (_c2 = n10.value) == null ? void 0 : _c2.extraActions, renderCopyIcon: (_d = n10.value) == null ? void 0 : _d.renderCopyIcon, onAction: (n11) => {
7375
+ return h$1("div", u3.menuWrapperProps, h$1(Va, { placementAbove: !!((_a3 = u3.placement) == null ? void 0 : _a3.suggestTop), anchorHeight: u3.rect.size.height, hiddenBuiltinActions: (_b2 = n10.value) == null ? void 0 : _b2.hiddenBuiltinActions, extraActions: (_c2 = n10.value) == null ? void 0 : _c2.extraActions, renderCopyIcon: (_d = n10.value) == null ? void 0 : _d.renderCopyIcon, onAction: (n11) => {
7403
7376
  var _a4, _b3, _c3;
7404
7377
  if ("copy" !== n11) if ("highlight" !== n11 && "underline" !== n11 && "squiggly" !== n11 && "strikeout" !== n11) {
7405
7378
  if ("note" === n11) {
@@ -7413,7 +7386,7 @@ const Va = /* @__PURE__ */ defineComponent({ __name: "PdfChapterViewport", props
7413
7386
  (_a4 = s3 == null ? void 0 : s3.onExtraAction) == null ? void 0 : _a4.call(s3, n11, t2);
7414
7387
  } else {
7415
7388
  if (!o2.value || !l.value || !r3.value) return;
7416
- xe$1(d2, Aa[n11], l.value, o2.value, (_c3 = (_b3 = e15()) == null ? void 0 : _b3.markup) == null ? void 0 : _c3.styles);
7389
+ xe$1(d2, Oa[n11], l.value, o2.value, (_c3 = (_b3 = e15()) == null ? void 0 : _b3.markup) == null ? void 0 : _c3.styles);
7417
7390
  }
7418
7391
  else {
7419
7392
  if (!o2.value || !i3.value) return;
@@ -7445,28 +7418,28 @@ const Va = /* @__PURE__ */ defineComponent({ __name: "PdfChapterViewport", props
7445
7418
  const n10 = (_a2 = s2.renderPageOverlay) == null ? void 0 : _a2.call(s2, e15);
7446
7419
  if (n10 && t2.push(n10), t2.length) return h$1("div", t2);
7447
7420
  }
7448
- return (t2, s3) => (openBlock(), createElementBlock("div", { ref_key: "hostRef", ref: r2, class: normalizeClass(e14.className), style: normalizeStyle(e14.className ? void 0 : unref(Pe)) }, [createVNode(unref(mr), { class: normalizeClass(e14.className), style: normalizeStyle(a2.value) }, { page: withCtx(({ item: t3 }) => {
7421
+ return (t2, s3) => (openBlock(), createElementBlock("div", { ref_key: "hostRef", ref: r2, class: normalizeClass(e14.className), style: normalizeStyle(e14.className ? void 0 : unref(Pe$1)) }, [createVNode(unref(mr), { class: normalizeClass(e14.className), style: normalizeStyle(a2.value) }, { page: withCtx(({ item: t3 }) => {
7449
7422
  var _a2, _b, _c, _d;
7450
- return [createVNode(wa, { item: t3, features: e14.features, "show-note-markers": p2.value, "show-bookmark-markers": m2.value, "show-redaction-layer": e14.showRedactionLayer, "note-marker-ui": (_b = (_a2 = e14.features) == null ? void 0 : _a2.notes) == null ? void 0 : _b.marker, "bookmark-marker-ui": (_d = (_c = e14.features) == null ? void 0 : _c.bookmarks) == null ? void 0 : _d.marker, "build-selection-menu": C2.value, "create-note": unref(i2), "annotation-selection-menu": e14.annotationSelectionMenu, "redaction-selection-menu": e14.redactionSelectionMenu, "render-page-overlay": x }, null, 8, ["item", "features", "show-note-markers", "show-bookmark-markers", "show-redaction-layer", "note-marker-ui", "bookmark-marker-ui", "build-selection-menu", "create-note", "annotation-selection-menu", "redaction-selection-menu"])];
7423
+ return [createVNode(wa, { item: t3, features: e14.features, "show-note-markers": g2.value, "show-bookmark-markers": m2.value, "show-redaction-layer": e14.showRedactionLayer, "note-marker-ui": (_b = (_a2 = e14.features) == null ? void 0 : _a2.notes) == null ? void 0 : _b.marker, "bookmark-marker-ui": (_d = (_c = e14.features) == null ? void 0 : _c.bookmarks) == null ? void 0 : _d.marker, "build-selection-menu": C2.value, "create-note": unref(i2), "annotation-selection-menu": e14.annotationSelectionMenu, "redaction-selection-menu": e14.redactionSelectionMenu, "render-page-overlay": x }, null, 8, ["item", "features", "show-note-markers", "show-bookmark-markers", "show-redaction-layer", "note-marker-ui", "bookmark-marker-ui", "build-selection-menu", "create-note", "annotation-selection-menu", "redaction-selection-menu"])];
7451
7424
  }), _: 1 }, 8, ["class", "style"]), renderSlot(t2.$slots, "default")], 6));
7452
- } }), za = { key: 0, style: { display: "flex", flexDirection: "column", height: "100%", minHeight: 0, width: "100%" } }, _a = /* @__PURE__ */ defineComponent({ __name: "ChapterPdfViewer", props: { engine: {}, options: {}, editorOptions: {}, features: {}, className: {}, viewportClassName: {}, onExtraSelectionAction: { type: Function } }, setup(e14) {
7425
+ } }), za = { key: 0, style: { display: "flex", flexDirection: "column", height: "100%", minHeight: 0, width: "100%" } }, Ga = /* @__PURE__ */ defineComponent({ __name: "ChapterPdfViewer", props: { engine: {}, options: {}, editorOptions: {}, features: {}, className: {}, viewportClassName: {}, onExtraSelectionAction: { type: Function } }, setup(e14) {
7453
7426
  const s2 = e14, n9 = computed(() => (function(e15) {
7454
- if (e15.options) return Tn(e15.options);
7427
+ if (e15.options) return Un(e15.options);
7455
7428
  if (!e15.editorOptions) throw new Error("ChapterPdfViewer: 请传入 `options`(推荐),或同时传入 `editorOptions` 与 `features`");
7456
7429
  const t2 = ke$1(e15.features), { plugins: s3 } = $n({ ...e15.editorOptions, features: t2 });
7457
7430
  return { plugins: s3, features: t2, editorOptions: { ...e15.editorOptions, features: t2 } };
7458
7431
  })({ engine: s2.engine, options: s2.options, editorOptions: s2.editorOptions, features: s2.features }));
7459
- return (t2, s3) => (openBlock(), createElementBlock("div", { class: normalizeClass(e14.className), style: normalizeStyle(e14.className ? void 0 : unref(Pe)) }, [createVNode(unref(EmbedPDF), { engine: e14.engine, plugins: n9.value.plugins }, { default: withCtx(({ pluginsReady: s4 }) => [s4 ? (openBlock(), createElementBlock("div", za, [renderSlot(t2.$slots, "prepend"), createVNode(Va, { class: normalizeClass(e14.viewportClassName), style: { flex: 1, minHeight: 0 }, features: n9.value.features, "on-extra-selection-action": e14.onExtraSelectionAction }, null, 8, ["class", "features", "on-extra-selection-action"]), renderSlot(t2.$slots, "default")])) : createCommentVNode("", true)]), _: 3 }, 8, ["engine", "plugins"])], 6));
7460
- } }), Ga = { class: "chapter-tree-row" }, Ba = ["aria-expanded"], Ha = { key: 1, class: "chapter-tree-toggle-spacer", "aria-hidden": "" }, Wa = { class: "chapter-tree-label" }, qa = { class: "chapter-tree-meta" }, Ka = { key: 0 }, ja = (e14, t2) => {
7432
+ return (t2, s3) => (openBlock(), createElementBlock("div", { class: normalizeClass(e14.className), style: normalizeStyle(e14.className ? void 0 : unref(Pe$1)) }, [createVNode(unref(EmbedPDF), { engine: e14.engine, plugins: n9.value.plugins }, { default: withCtx(({ pluginsReady: s4 }) => [s4 ? (openBlock(), createElementBlock("div", za, [renderSlot(t2.$slots, "prepend"), createVNode(Ra, { class: normalizeClass(e14.viewportClassName), style: { flex: 1, minHeight: 0 }, features: n9.value.features, "on-extra-selection-action": e14.onExtraSelectionAction }, null, 8, ["class", "features", "on-extra-selection-action"]), renderSlot(t2.$slots, "default")])) : createCommentVNode("", true)]), _: 3 }, 8, ["engine", "plugins"])], 6));
7433
+ } }), _a = { class: "chapter-tree-row" }, Ba = ["aria-expanded"], Wa = { key: 1, class: "chapter-tree-toggle-spacer", "aria-hidden": "" }, qa = { class: "chapter-tree-label" }, Ha = { class: "chapter-tree-meta" }, Ka = { key: 0 }, ja = (e14, t2) => {
7461
7434
  const s2 = e14.__vccOpts || e14;
7462
7435
  for (const [n9, r2] of t2) s2[n9] = r2;
7463
7436
  return s2;
7464
7437
  }, Xa = /* @__PURE__ */ ja(/* @__PURE__ */ defineComponent({ __name: "ChapterTreeItem", props: { node: {}, depth: {}, activeChapterId: {}, chapterStatus: {} }, emits: ["select"], setup(e14) {
7465
- const n9 = { idle: "未加载", loading: "加载中", loaded: "已加载", closed: "已卸载", error: "失败", "password-required": "需密码" }, r2 = e14, a2 = computed(() => r2.node.children ?? []), i2 = computed(() => a2.value.length > 0), h2 = ref(r2.depth < 1), u2 = computed(() => r2.activeChapterId === r2.node.id), p2 = computed(() => r2.chapterStatus[r2.node.id] ?? "idle"), g2 = computed(() => !i2.value);
7466
- return (t2, s2) => (openBlock(), createElementBlock("li", null, [createElementVNode("div", Ga, [i2.value ? (openBlock(), createElementBlock("button", { key: 0, type: "button", class: "chapter-tree-toggle", "aria-expanded": h2.value, onClick: s2[0] || (s2[0] = (e15) => h2.value = !h2.value) }, toDisplayString(h2.value ? "▼" : "▶"), 9, Ba)) : (openBlock(), createElementBlock("span", Ha)), createElementVNode("button", { type: "button", class: normalizeClass(["chapter-tree-btn", { "chapter-tree-btn-active": u2.value }]), onClick: s2[1] || (s2[1] = (s3) => t2.$emit("select", e14.node.id)) }, [createElementVNode("div", Wa, toDisplayString(e14.node.title), 1), createElementVNode("div", qa, [createElementVNode("span", null, " 第 " + toDisplayString(e14.node.startPage) + toDisplayString(e14.node.endPage !== e14.node.startPage ? `–${e14.node.endPage}` : "") + " 页 ", 1), g2.value ? (openBlock(), createElementBlock("span", Ka, toDisplayString(n9[p2.value]), 1)) : createCommentVNode("", true)])], 2)]), i2.value && h2.value ? (openBlock(), createBlock(Za, { key: 0, nodes: a2.value, depth: e14.depth + 1, "active-chapter-id": e14.activeChapterId, "chapter-status": e14.chapterStatus, onSelect: s2[2] || (s2[2] = (e15) => t2.$emit("select", e15)) }, null, 8, ["nodes", "depth", "active-chapter-id", "chapter-status"])) : createCommentVNode("", true)]));
7438
+ const n9 = { idle: "未加载", loading: "加载中", loaded: "已加载", closed: "已卸载", error: "失败", "password-required": "需密码" }, r2 = e14, a2 = computed(() => r2.node.children ?? []), i2 = computed(() => a2.value.length > 0), h2 = ref(r2.depth < 1), u2 = computed(() => r2.activeChapterId === r2.node.id), g2 = computed(() => r2.chapterStatus[r2.node.id] ?? "idle"), p2 = computed(() => !i2.value);
7439
+ return (t2, s2) => (openBlock(), createElementBlock("li", null, [createElementVNode("div", _a, [i2.value ? (openBlock(), createElementBlock("button", { key: 0, type: "button", class: "chapter-tree-toggle", "aria-expanded": h2.value, onClick: s2[0] || (s2[0] = (e15) => h2.value = !h2.value) }, toDisplayString(h2.value ? "▼" : "▶"), 9, Ba)) : (openBlock(), createElementBlock("span", Wa)), createElementVNode("button", { type: "button", class: normalizeClass(["chapter-tree-btn", { "chapter-tree-btn-active": u2.value }]), onClick: s2[1] || (s2[1] = (s3) => t2.$emit("select", e14.node.id)) }, [createElementVNode("div", qa, toDisplayString(e14.node.title), 1), createElementVNode("div", Ha, [createElementVNode("span", null, " 第 " + toDisplayString(e14.node.startPage) + toDisplayString(e14.node.endPage !== e14.node.startPage ? `–${e14.node.endPage}` : "") + " 页 ", 1), p2.value ? (openBlock(), createElementBlock("span", Ka, toDisplayString(n9[g2.value]), 1)) : createCommentVNode("", true)])], 2)]), i2.value && h2.value ? (openBlock(), createBlock(Za, { key: 0, nodes: a2.value, depth: e14.depth + 1, "active-chapter-id": e14.activeChapterId, "chapter-status": e14.chapterStatus, onSelect: s2[2] || (s2[2] = (e15) => t2.$emit("select", e15)) }, null, 8, ["nodes", "depth", "active-chapter-id", "chapter-status"])) : createCommentVNode("", true)]));
7467
7440
  } }), [["__scopeId", "data-v-315bbf7a"]]), Za = /* @__PURE__ */ ja(/* @__PURE__ */ defineComponent({ __name: "ChapterTreeList", props: { nodes: {}, depth: {}, activeChapterId: {}, chapterStatus: {} }, emits: ["select"], setup: (e14) => (t2, s2) => (openBlock(), createElementBlock("ul", { class: "chapter-tree-list", style: normalizeStyle({ marginLeft: e14.depth > 0 ? "12px" : "0" }) }, [(openBlock(true), createElementBlock(Fragment, null, renderList(e14.nodes, (n9) => (openBlock(), createBlock(Xa, { key: n9.id, node: n9, depth: e14.depth, "active-chapter-id": e14.activeChapterId, "chapter-status": e14.chapterStatus, onSelect: s2[0] || (s2[0] = (e15) => t2.$emit("select", e15)) }, null, 8, ["node", "depth", "active-chapter-id", "chapter-status"]))), 128))], 4)) }), [["__scopeId", "data-v-eb742e4f"]]), Ya = { class: "chapter-tree" }, Qa = { class: "chapter-tree-nav", "aria-label": "章节目录" }, Ja = /* @__PURE__ */ ja(/* @__PURE__ */ defineComponent({ __name: "ChapterTreePanel", props: { tree: {}, activeChapterId: {} }, emits: ["active-chapter-change"], setup(e14, { emit: t2 }) {
7468
7441
  const a2 = e14, i2 = t2, { provides: h2 } = useCapability(kt$1.id), { provides: d2 } = useCapability(nt$1.id), u2 = ref({});
7469
- function p2() {
7442
+ function g2() {
7470
7443
  if (!d2.value) return;
7471
7444
  const e15 = {}, t3 = (s2) => {
7472
7445
  var _a2;
@@ -7474,15 +7447,15 @@ const Va = /* @__PURE__ */ defineComponent({ __name: "PdfChapterViewport", props
7474
7447
  };
7475
7448
  t3(a2.tree), u2.value = e15;
7476
7449
  }
7477
- watch([d2, () => a2.tree], p2, { immediate: true });
7478
- let g2 = null;
7450
+ watch([d2, () => a2.tree], g2, { immediate: true });
7451
+ let p2 = null;
7479
7452
  function m2(e15) {
7480
7453
  var _a2;
7481
7454
  i2("active-chapter-change", e15), (_a2 = h2.value) == null ? void 0 : _a2.scrollToChapter(e15);
7482
7455
  }
7483
7456
  return watch(d2, (e15) => {
7484
- g2 == null ? void 0 : g2(), g2 = e15 ? e15.onChapterStatusChange(p2) : null;
7485
- }, { immediate: true }), onBeforeUnmount(() => g2 == null ? void 0 : g2()), (t3, s2) => (openBlock(), createElementBlock("aside", Ya, [s2[0] || (s2[0] = createElementVNode("h2", { class: "chapter-tree-title" }, "章节目录", -1)), createElementVNode("nav", Qa, [createVNode(Za, { nodes: e14.tree, depth: 0, "active-chapter-id": e14.activeChapterId, "chapter-status": u2.value, onSelect: m2 }, null, 8, ["nodes", "active-chapter-id", "chapter-status"])])]));
7457
+ p2 == null ? void 0 : p2(), p2 = e15 ? e15.onChapterStatusChange(g2) : null;
7458
+ }, { immediate: true }), onBeforeUnmount(() => p2 == null ? void 0 : p2()), (t3, s2) => (openBlock(), createElementBlock("aside", Ya, [s2[0] || (s2[0] = createElementVNode("h2", { class: "chapter-tree-title" }, "章节目录", -1)), createElementVNode("nav", Qa, [createVNode(Za, { nodes: e14.tree, depth: 0, "active-chapter-id": e14.activeChapterId, "chapter-status": u2.value, onSelect: m2 }, null, 8, ["nodes", "active-chapter-id", "chapter-status"])])]));
7486
7459
  } }), [["__scopeId", "data-v-d7a0838d"]]);
7487
7460
  const _sfc_main = /* @__PURE__ */ defineComponent({
7488
7461
  __name: "ChapterPdfViewer",
@@ -7496,7 +7469,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
7496
7469
  },
7497
7470
  setup(__props) {
7498
7471
  return (_ctx, _cache) => {
7499
- return openBlock(), createBlock(unref(_a), normalizeProps(guardReactiveProps(_ctx.$props)), createSlots({
7472
+ return openBlock(), createBlock(unref(Ga), normalizeProps(guardReactiveProps(_ctx.$props)), createSlots({
7500
7473
  default: withCtx(() => [
7501
7474
  renderSlot(_ctx.$slots, "default")
7502
7475
  ]),
@@ -7528,19 +7501,19 @@ function D(e14) {
7528
7501
  function k(e14, t2) {
7529
7502
  return `${e14}#s${t2}`;
7530
7503
  }
7531
- function E(e14) {
7504
+ function U(e14) {
7532
7505
  const t2 = e14.lastIndexOf("#s");
7533
7506
  if (-1 === t2) return { chapterId: e14, segmentIndex: null };
7534
7507
  const s2 = e14.slice(0, t2), n9 = Number.parseInt(e14.slice(t2 + 2), 10);
7535
7508
  return !Number.isFinite(n9) || n9 < 0 ? { chapterId: e14, segmentIndex: null } : { chapterId: s2, segmentIndex: n9 };
7536
7509
  }
7537
- function U(e14, t2) {
7510
+ function E(e14, t2) {
7538
7511
  return e14 <= 0 || t2 <= 0 ? 0 : Math.ceil(e14 / t2);
7539
7512
  }
7540
7513
  function T(e14) {
7541
7514
  const t2 = D(e14);
7542
7515
  if (!t2) return null;
7543
- const s2 = L(e14), n9 = U(s2, t2), r2 = $$1(e14.source) ? e14.source.urls : void 0, a2 = [];
7516
+ const s2 = L(e14), n9 = E(s2, t2), r2 = $$1(e14.source) ? e14.source.urls : void 0, a2 = [];
7544
7517
  for (let o2 = 0; o2 < n9; o2++) {
7545
7518
  const n10 = o2 * t2, i2 = Math.min(n10 + t2 - 1, s2 - 1);
7546
7519
  if (n10 >= s2) break;
@@ -7558,7 +7531,7 @@ function F(e14, t2) {
7558
7531
  }
7559
7532
  return { documentId: n9.documentId, pageIndex: t2 - n9.localPageStart };
7560
7533
  }
7561
- function O(e14, t2) {
7534
+ function N(e14, t2) {
7562
7535
  const s2 = T(e14);
7563
7536
  if (!s2) return 0;
7564
7537
  const n9 = s2.segments.find((e15) => t2 >= e15.localPageStart && t2 <= e15.localPageEnd);
@@ -7573,13 +7546,13 @@ function A(e14) {
7573
7546
  const o2 = e14.source;
7574
7547
  if (!$$1(o2)) return n9;
7575
7548
  0 === o2.urls.length && n9.push(`${r2}: source.urls must not be empty`);
7576
- const i2 = U(a2, s2);
7549
+ const i2 = E(a2, s2);
7577
7550
  o2.urls.length !== i2 && n9.push(`${r2}: source.urls.length (${o2.urls.length}) must equal ceil(pageCount/threshold) (${i2})`);
7578
7551
  for (let h2 = 0; h2 < o2.urls.length; h2++) (null == (t2 = o2.urls[h2]) ? void 0 : t2.trim()) || n9.push(`${r2}: source.urls[${h2}] is empty`);
7579
7552
  return n9;
7580
7553
  }
7581
- const R$1 = { kind: "first-wins" };
7582
- function V(e14, t2, s2) {
7554
+ const V = { kind: "first-wins" };
7555
+ function O(e14, t2, s2) {
7583
7556
  if (1 === t2.length) return t2[0].chapterId;
7584
7557
  switch (s2.kind) {
7585
7558
  case "first-wins":
@@ -7597,7 +7570,7 @@ function V(e14, t2, s2) {
7597
7570
  return s2.resolve(e14, t2);
7598
7571
  }
7599
7572
  }
7600
- let N = class {
7573
+ let R$1 = class R {
7601
7574
  constructor(e14) {
7602
7575
  this._pages = e14, this._byChapter = /* @__PURE__ */ new Map(), this._byGlobalNumber = /* @__PURE__ */ new Map();
7603
7576
  for (const t2 of e14) {
@@ -7631,8 +7604,8 @@ let N = class {
7631
7604
  return s2 ? this._pages.indexOf(s2) : -1;
7632
7605
  }
7633
7606
  };
7634
- function G$1(e14, t2 = R$1) {
7635
- const s2 = (function(e15, t3 = R$1) {
7607
+ function G$1(e14, t2 = V) {
7608
+ const s2 = (function(e15, t3 = V) {
7636
7609
  const s3 = /* @__PURE__ */ new Map();
7637
7610
  for (const r3 of e15.chapters) {
7638
7611
  const [e16, t4] = r3.globalPageRange;
@@ -7642,7 +7615,7 @@ function G$1(e14, t2 = R$1) {
7642
7615
  }
7643
7616
  }
7644
7617
  const n10 = /* @__PURE__ */ new Map();
7645
- for (const [r3, a3] of s3) n10.set(r3, V(r3, a3, t3));
7618
+ for (const [r3, a3] of s3) n10.set(r3, O(r3, a3, t3));
7646
7619
  return n10;
7647
7620
  })(e14, t2), n9 = /* @__PURE__ */ new Map();
7648
7621
  for (const i2 of e14.chapters) n9.set(i2.chapterId, i2);
@@ -7651,24 +7624,24 @@ function G$1(e14, t2 = R$1) {
7651
7624
  for (const i2 of r2) {
7652
7625
  const e15 = s2.get(i2), t3 = n9.get(e15);
7653
7626
  if (!t3) continue;
7654
- const [r3] = t3.globalPageRange, [h2] = t3.localPageRange, d2 = h2 + (i2 - r3);
7655
- a2.push({ globalPageIndex: o2++, globalPageNumber: i2, chapterId: e15, localPageIndex: d2 });
7627
+ const [r3] = t3.globalPageRange, [h2] = t3.localPageRange, l = h2 + (i2 - r3);
7628
+ a2.push({ globalPageIndex: o2++, globalPageNumber: i2, chapterId: e15, localPageIndex: l });
7656
7629
  }
7657
- return new N(a2);
7630
+ return new R$1(a2);
7658
7631
  }
7659
- const _$1 = class n extends BasePlugin {
7632
+ const z = class n extends BasePlugin {
7660
7633
  constructor(e14, n9) {
7661
- super(e14, n9), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = R$1, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.SEG_PRIO_PREFETCH_NEXT = 120, this.SEG_PRIO_CHAPTER_PREFETCH_BASE = 3e3, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
7634
+ super(e14, n9), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = V, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
7662
7635
  }
7663
7636
  async initialize(e14) {
7664
- if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? R$1, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
7665
- const { chapterId: t2 } = E(e15.id);
7637
+ if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? V, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
7638
+ const { chapterId: t2 } = U(e15.id);
7666
7639
  this.findChapter(t2) && (this.passwordAttempts.delete(t2), this.syncChapterStatusFromDocuments(t2));
7667
7640
  }), this.documentManager.provides().onDocumentClosed((e15) => {
7668
- const { chapterId: t2 } = E(e15);
7641
+ const { chapterId: t2 } = U(e15);
7669
7642
  this.findChapter(t2) && this.syncChapterStatusFromDocuments(t2);
7670
7643
  }), this.documentManager.provides().onDocumentError((e15) => {
7671
- const { chapterId: t2 } = E(e15.documentId);
7644
+ const { chapterId: t2 } = U(e15.documentId);
7672
7645
  this.findChapter(t2) && this.handleDocumentError(e15.documentId, t2, e15.code, e15.message);
7673
7646
  })), this.setManifestInternal(e14.manifest), e14.unloadTimeoutMs && e14.unloadTimeoutMs > 0) {
7674
7647
  const t2 = Math.max(5e3, Math.floor(e14.unloadTimeoutMs / 4));
@@ -7789,7 +7762,7 @@ const _$1 = class n extends BasePlugin {
7789
7762
  if (!e15) continue;
7790
7763
  const s2 = this.findChapter(e15.chapterId);
7791
7764
  if (!s2) continue;
7792
- const n9 = O(s2, e15.localPageIndex);
7765
+ const n9 = N(s2, e15.localPageIndex);
7793
7766
  if (!this.isSegmentDocumentOpen(e15.chapterId, n9)) return true;
7794
7767
  }
7795
7768
  return false;
@@ -7800,13 +7773,22 @@ const _$1 = class n extends BasePlugin {
7800
7773
  clearVisibleSegmentBacklog() {
7801
7774
  this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0;
7802
7775
  }
7776
+ globalSegmentSortKey(e14, t2) {
7777
+ var s2;
7778
+ if (!this.virtualPageMap) return Number.MAX_SAFE_INTEGER;
7779
+ const n9 = this.findChapter(e14);
7780
+ if (!n9) return Number.MAX_SAFE_INTEGER;
7781
+ const r2 = T(n9), a2 = (null == (s2 = null == r2 ? void 0 : r2.segments[t2]) ? void 0 : s2.localPageStart) ?? 0, o2 = this.virtualPageMap.toGlobal(e14, a2);
7782
+ if (o2) return o2.globalPageIndex;
7783
+ return 1e4 * this.manifest.chapters.findIndex((t3) => t3.chapterId === e14) + t2;
7784
+ }
7803
7785
  scheduleVisibleSegmentLoads(e14) {
7804
- const t2 = /* @__PURE__ */ new Set(), s2 = [...e14].sort((e15, t3) => e15.priority - t3.priority);
7805
- for (const n9 of s2) {
7806
- const e15 = `${n9.chapterId}:${n9.segmentIndex}`;
7807
- t2.has(e15) || (t2.add(e15), this.isSegmentDocumentOpen(n9.chapterId, n9.segmentIndex) || this.isSegmentLoadPending(n9.chapterId, n9.segmentIndex) || this.visibleSegmentBacklog.push({ chapterId: n9.chapterId, segmentIndex: n9.segmentIndex }));
7786
+ const t2 = [...e14].sort((e15, t3) => e15.priority - t3.priority), s2 = /* @__PURE__ */ new Set(), n9 = [];
7787
+ for (const r2 of t2) {
7788
+ const e15 = `${r2.chapterId}:${r2.segmentIndex}`;
7789
+ s2.has(e15) || (s2.add(e15), this.isSegmentDocumentOpen(r2.chapterId, r2.segmentIndex) || this.isSegmentLoadPending(r2.chapterId, r2.segmentIndex) || n9.push({ chapterId: r2.chapterId, segmentIndex: r2.segmentIndex }));
7808
7790
  }
7809
- this.pumpVisibleSegmentBacklog();
7791
+ this.visibleSegmentBacklog = n9, this.pumpVisibleSegmentBacklog();
7810
7792
  }
7811
7793
  pumpVisibleSegmentBacklog() {
7812
7794
  const e14 = Math.max(1, this.config.maxConcurrentSegmentLoads ?? 2);
@@ -7825,53 +7807,41 @@ const _$1 = class n extends BasePlugin {
7825
7807
  const t2 = e14.join(","), s2 = this.visibleRangeNeedsSegmentLoad(e14);
7826
7808
  if (t2 === this.lastVisibleIndicesKey && !s2) return;
7827
7809
  this.lastVisibleIndicesKey = t2;
7828
- const n9 = Date.now(), r2 = this.config.prefetchChapters ?? 1, a2 = e14[Math.floor(e14.length / 2)] ?? e14[0], o2 = /* @__PURE__ */ new Set(), i2 = /* @__PURE__ */ new Map(), h2 = (e15, t3, s3) => {
7810
+ const n9 = Date.now(), r2 = e14[Math.floor(e14.length / 2)] ?? e14[0], a2 = /* @__PURE__ */ new Set(), o2 = /* @__PURE__ */ new Map(), i2 = (e15, t3) => {
7829
7811
  if (t3 < 0) return;
7830
- const n10 = this.findChapter(e15);
7831
- if (!n10) return;
7832
- const r3 = T(n10);
7833
- if (r3 && t3 >= r3.segments.length) return;
7834
- const a3 = `${e15}:${t3}`, o3 = i2.get(a3);
7835
- (void 0 === o3 || s3 < o3) && i2.set(a3, s3);
7812
+ const s3 = this.findChapter(e15);
7813
+ if (!s3) return;
7814
+ const n10 = T(s3);
7815
+ if (n10 && t3 >= n10.segments.length) return;
7816
+ const r3 = `${e15}:${t3}`, a3 = this.globalSegmentSortKey(e15, t3), i3 = o2.get(r3);
7817
+ (void 0 === i3 || a3 < i3) && o2.set(r3, a3);
7836
7818
  };
7837
- for (const g2 of e14) {
7838
- const e15 = this.virtualPageMap.atIndex(g2);
7819
+ for (const d2 of e14) {
7820
+ const e15 = this.virtualPageMap.atIndex(d2);
7839
7821
  if (!e15) continue;
7840
- o2.add(e15.chapterId);
7822
+ a2.add(e15.chapterId);
7841
7823
  const t3 = this.findChapter(e15.chapterId);
7842
7824
  if (!t3) continue;
7843
- const s3 = Math.abs(g2 - a2), n10 = O(t3, e15.localPageIndex);
7844
- h2(e15.chapterId, n10, s3), h2(e15.chapterId, n10 + 1, s3 + this.SEG_PRIO_PREFETCH_NEXT), this.resolveChapterUrls(t3).catch(() => {
7825
+ const s3 = N(t3, e15.localPageIndex);
7826
+ i2(e15.chapterId, s3), this.resolveChapterUrls(t3).catch(() => {
7845
7827
  });
7846
7828
  }
7847
- if (0 === o2.size) return;
7848
- const d2 = this.manifest.chapters.map((e15) => e15.chapterId);
7849
- let l = 0;
7850
- const c2 = this.virtualPageMap.atIndex(a2);
7851
- if (c2) {
7852
- const e15 = d2.indexOf(c2.chapterId);
7853
- e15 >= 0 && (l = e15);
7854
- }
7855
- for (const g2 of o2) {
7856
- this.chapterLastUsed.set(g2, n9);
7857
- const e15 = d2.indexOf(g2);
7858
- if (-1 !== e15) for (let t3 = e15 - r2; t3 <= e15 + r2; t3++) {
7859
- if (t3 < 0 || t3 >= d2.length) continue;
7860
- const e16 = d2[t3];
7861
- this.chapterLastUsed.set(e16, n9);
7862
- const s3 = Math.abs(t3 - l);
7863
- h2(e16, 0, this.SEG_PRIO_CHAPTER_PREFETCH_BASE + 100 * s3);
7864
- const r3 = this.findChapter(e16);
7865
- r3 && this.resolveChapterUrls(r3).catch(() => {
7866
- });
7829
+ if (0 === a2.size) return;
7830
+ const h2 = this.virtualPageMap.atIndex(r2);
7831
+ if (h2) {
7832
+ const e15 = this.findChapter(h2.chapterId);
7833
+ if (e15) {
7834
+ const t3 = N(e15, h2.localPageIndex);
7835
+ i2(h2.chapterId, t3 + 1);
7867
7836
  }
7868
7837
  }
7869
- const u2 = [...i2.entries()].map(([e15, t3]) => {
7838
+ for (const d2 of a2) this.chapterLastUsed.set(d2, n9);
7839
+ const l = [...o2.entries()].map(([e15, t3]) => {
7870
7840
  const [s3, n10] = e15.split(":");
7871
7841
  return { chapterId: s3, segmentIndex: Number.parseInt(n10, 10), priority: t3 };
7872
7842
  }).filter((e15) => e15.chapterId && Number.isFinite(e15.segmentIndex));
7873
- if (this.scheduleVisibleSegmentLoads(u2), this.config.autoActivateOnLoad ?? 1) {
7874
- const e15 = this.virtualPageMap.atIndex(a2);
7843
+ if (this.scheduleVisibleSegmentLoads(l), this.config.autoActivateOnLoad ?? 1) {
7844
+ const e15 = this.virtualPageMap.atIndex(r2);
7875
7845
  if (e15) {
7876
7846
  const t3 = F(this.findChapter(e15.chapterId), e15.localPageIndex);
7877
7847
  if (this.documentManager.provides().isDocumentOpen(t3.documentId)) {
@@ -7967,7 +7937,7 @@ const _$1 = class n extends BasePlugin {
7967
7937
  async resolvePdfPayload(e14, t2) {
7968
7938
  const s2 = e14.source, r2 = this.config.chapterPdfLoader, a2 = D(e14);
7969
7939
  if (a2) {
7970
- const s3 = U(L(e14), a2);
7940
+ const s3 = E(L(e14), a2);
7971
7941
  if (t2 < 0 || t2 >= s3) throw new Error(`Chapter "${e14.chapterId}" invalid segmentIndex ${t2} (expected 0..${s3 - 1})`);
7972
7942
  const r3 = await this.resolveChapterUrls(e14);
7973
7943
  if (r3.length !== s3) {
@@ -7998,11 +7968,11 @@ const _$1 = class n extends BasePlugin {
7998
7968
  const r2 = e14.chapterId, a2 = (null == t2 ? void 0 : t2.index) ?? 0, o2 = (null == t2 ? void 0 : t2.documentId) ?? r2;
7999
7969
  this.chapterErrorMessages.delete(r2), this.anySegmentOpen(r2) || this.updateStatus(r2, "loading"), this.chapterLastUsed.set(r2, Date.now());
8000
7970
  try {
8001
- const n9 = e14.encrypted && (null == (s2 = this.passwordProvider) ? void 0 : s2.getCachedPassword) ? this.passwordProvider.getCachedPassword(r2) : null, i2 = await this.resolvePdfPayload(e14, a2), h2 = this.documentManager.provides(), d2 = "url" in i2 ? h2.openDocumentUrl({ documentId: o2, url: i2.url, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }) : h2.openDocumentBuffer({ documentId: o2, buffer: i2.buffer, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }), l = await new Promise((e15, t3) => {
8002
- d2.wait((t4) => e15(t4), (e16) => t3(e16));
7971
+ const n9 = e14.encrypted && (null == (s2 = this.passwordProvider) ? void 0 : s2.getCachedPassword) ? this.passwordProvider.getCachedPassword(r2) : null, i2 = await this.resolvePdfPayload(e14, a2), h2 = this.documentManager.provides(), l = "url" in i2 ? h2.openDocumentUrl({ documentId: o2, url: i2.url, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }) : h2.openDocumentBuffer({ documentId: o2, buffer: i2.buffer, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }), d2 = await new Promise((e15, t3) => {
7972
+ l.wait((t4) => e15(t4), (e16) => t3(e16));
8003
7973
  });
8004
7974
  return await new Promise((e15, t3) => {
8005
- l.task.wait(() => e15(), (e16) => t3(e16));
7975
+ d2.task.wait(() => e15(), (e16) => t3(e16));
8006
7976
  }), h2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(r2), this.waitForTerminalStatus(r2);
8007
7977
  } catch (i2) {
8008
7978
  const e15 = this.chapterStatus.get(r2);
@@ -8026,7 +7996,7 @@ const _$1 = class n extends BasePlugin {
8026
7996
  async handleDocumentError(e14, t2, s2, r2) {
8027
7997
  if (this.pendingSegmentLoadPromises.has(e14)) return;
8028
7998
  if (s2 !== PdfErrorCode.Password) {
8029
- const s3 = this.getSegmentPlanForChapter(t2), { segmentIndex: n9 } = E(e14);
7999
+ const s3 = this.getSegmentPlanForChapter(t2), { segmentIndex: n9 } = U(e14);
8030
8000
  return void (s3 && 0 !== n9 && null !== n9 || this.updateStatus(t2, "error"));
8031
8001
  }
8032
8002
  if (!this.passwordProvider) return void this.updateStatus(t2, "password-required");
@@ -8063,12 +8033,12 @@ const _$1 = class n extends BasePlugin {
8063
8033
  "error" === t2 && s2 ? this.chapterErrorMessages.set(e14, s2) : "loading" !== t2 && "loaded" !== t2 || this.chapterErrorMessages.delete(e14), n9 !== t2 && (this.chapterStatus.set(e14, t2), this.statusChange$.emit({ chapterId: e14, status: t2, ..."error" === t2 && s2 ? { error: { message: s2 } } : {} }));
8064
8034
  }
8065
8035
  };
8066
- _$1.id = "chapter-manager";
8067
- let z = _$1;
8068
- function W(e14) {
8036
+ z.id = "chapter-manager";
8037
+ let B = z;
8038
+ function K(e14) {
8069
8039
  return !!e14 && "urls" in e14 && Array.isArray(e14.urls);
8070
8040
  }
8071
- function K(e14, t2) {
8041
+ function H(e14, t2) {
8072
8042
  return `${e14}#s${t2}`;
8073
8043
  }
8074
8044
  function j(e14) {
@@ -8081,7 +8051,7 @@ function X(e14) {
8081
8051
  const t2 = (function(e15) {
8082
8052
  if (null != e15.segmentPageThreshold && e15.segmentPageThreshold > 0) return e15.segmentPageThreshold;
8083
8053
  const t3 = e15.source;
8084
- return W(t3) ? t3.segmentPageThreshold : null;
8054
+ return K(t3) ? t3.segmentPageThreshold : null;
8085
8055
  })(e14);
8086
8056
  if (!t2) return null;
8087
8057
  const s2 = (function(e15) {
@@ -8089,11 +8059,11 @@ function X(e14) {
8089
8059
  return s3 - t3 + 1;
8090
8060
  })(e14), n9 = (function(e15, t3) {
8091
8061
  return e15 <= 0 || t3 <= 0 ? 0 : Math.ceil(e15 / t3);
8092
- })(s2, t2), r2 = W(e14.source) ? e14.source.urls : void 0, a2 = [];
8062
+ })(s2, t2), r2 = K(e14.source) ? e14.source.urls : void 0, a2 = [];
8093
8063
  for (let o2 = 0; o2 < n9; o2++) {
8094
8064
  const n10 = o2 * t2, i2 = Math.min(n10 + t2 - 1, s2 - 1);
8095
8065
  if (n10 >= s2) break;
8096
- a2.push({ index: o2, url: (null == r2 ? void 0 : r2[o2]) ?? "", localPageStart: n10, localPageEnd: i2, documentId: K(e14.chapterId, o2) });
8066
+ a2.push({ index: o2, url: (null == r2 ? void 0 : r2[o2]) ?? "", localPageStart: n10, localPageEnd: i2, documentId: H(e14.chapterId, o2) });
8097
8067
  }
8098
8068
  return { chapterId: e14.chapterId, threshold: t2, pageCount: s2, segments: a2 };
8099
8069
  }
@@ -8215,7 +8185,7 @@ class he {
8215
8185
  return s2 ? this._pages.indexOf(s2) : -1;
8216
8186
  }
8217
8187
  }
8218
- function de(e14, t2 = oe) {
8188
+ function le(e14, t2 = oe) {
8219
8189
  const s2 = (function(e15, t3 = oe) {
8220
8190
  const s3 = /* @__PURE__ */ new Map();
8221
8191
  for (const r3 of e15.chapters) {
@@ -8235,14 +8205,14 @@ function de(e14, t2 = oe) {
8235
8205
  for (const i2 of r2) {
8236
8206
  const e15 = s2.get(i2), t3 = n9.get(e15);
8237
8207
  if (!t3) continue;
8238
- const [r3] = t3.globalPageRange, [h2] = t3.localPageRange, d2 = h2 + (i2 - r3);
8239
- a2.push({ globalPageIndex: o2++, globalPageNumber: i2, chapterId: e15, localPageIndex: d2 });
8208
+ const [r3] = t3.globalPageRange, [h2] = t3.localPageRange, l = h2 + (i2 - r3);
8209
+ a2.push({ globalPageIndex: o2++, globalPageNumber: i2, chapterId: e15, localPageIndex: l });
8240
8210
  }
8241
8211
  return new he(a2);
8242
8212
  }
8243
- const le = class n2 extends BasePlugin {
8213
+ const de = class n2 extends BasePlugin {
8244
8214
  constructor(e14, n9) {
8245
- super(e14, n9), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = oe, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.SEG_PRIO_PREFETCH_NEXT = 120, this.SEG_PRIO_CHAPTER_PREFETCH_BASE = 3e3, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
8215
+ super(e14, n9), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = oe, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
8246
8216
  }
8247
8217
  async initialize(e14) {
8248
8218
  if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? oe, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
@@ -8307,7 +8277,7 @@ const le = class n2 extends BasePlugin {
8307
8277
  const r2 = new Set(this.chapterStatus.keys()), a2 = new Set(t2.chapters.map((e15) => e15.chapterId));
8308
8278
  for (const n9 of r2) a2.has(n9) || (this.closeChapter(n9), this.chapterStatus.delete(n9), this.chapterErrorMessages.delete(n9), this.chapterUrlsCache.delete(n9), this.pendingChapterUrlsPromises.delete(n9));
8309
8279
  for (const n9 of t2.chapters) this.chapterStatus.has(n9.chapterId) || this.chapterStatus.set(n9.chapterId, "idle");
8310
- this.manifest = t2, this.lastVisibleIndicesKey = "", this.clearVisibleSegmentBacklog(), this.virtualPageMap = de(t2, this.overlapStrategy), this.manifestChange$.emit({ manifest: t2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
8280
+ this.manifest = t2, this.lastVisibleIndicesKey = "", this.clearVisibleSegmentBacklog(), this.virtualPageMap = le(t2, this.overlapStrategy), this.manifestChange$.emit({ manifest: t2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
8311
8281
  }
8312
8282
  eagerPrefetchFromManifest() {
8313
8283
  const e14 = this.config.prefetchChapters ?? 0;
@@ -8384,13 +8354,22 @@ const le = class n2 extends BasePlugin {
8384
8354
  clearVisibleSegmentBacklog() {
8385
8355
  this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0;
8386
8356
  }
8357
+ globalSegmentSortKey(e14, t2) {
8358
+ var s2;
8359
+ if (!this.virtualPageMap) return Number.MAX_SAFE_INTEGER;
8360
+ const n9 = this.findChapter(e14);
8361
+ if (!n9) return Number.MAX_SAFE_INTEGER;
8362
+ const r2 = se(n9), a2 = (null == (s2 = null == r2 ? void 0 : r2.segments[t2]) ? void 0 : s2.localPageStart) ?? 0, o2 = this.virtualPageMap.toGlobal(e14, a2);
8363
+ if (o2) return o2.globalPageIndex;
8364
+ return 1e4 * this.manifest.chapters.findIndex((t3) => t3.chapterId === e14) + t2;
8365
+ }
8387
8366
  scheduleVisibleSegmentLoads(e14) {
8388
- const t2 = /* @__PURE__ */ new Set(), s2 = [...e14].sort((e15, t3) => e15.priority - t3.priority);
8389
- for (const n9 of s2) {
8390
- const e15 = `${n9.chapterId}:${n9.segmentIndex}`;
8391
- t2.has(e15) || (t2.add(e15), this.isSegmentDocumentOpen(n9.chapterId, n9.segmentIndex) || this.isSegmentLoadPending(n9.chapterId, n9.segmentIndex) || this.visibleSegmentBacklog.push({ chapterId: n9.chapterId, segmentIndex: n9.segmentIndex }));
8367
+ const t2 = [...e14].sort((e15, t3) => e15.priority - t3.priority), s2 = /* @__PURE__ */ new Set(), n9 = [];
8368
+ for (const r2 of t2) {
8369
+ const e15 = `${r2.chapterId}:${r2.segmentIndex}`;
8370
+ s2.has(e15) || (s2.add(e15), this.isSegmentDocumentOpen(r2.chapterId, r2.segmentIndex) || this.isSegmentLoadPending(r2.chapterId, r2.segmentIndex) || n9.push({ chapterId: r2.chapterId, segmentIndex: r2.segmentIndex }));
8392
8371
  }
8393
- this.pumpVisibleSegmentBacklog();
8372
+ this.visibleSegmentBacklog = n9, this.pumpVisibleSegmentBacklog();
8394
8373
  }
8395
8374
  pumpVisibleSegmentBacklog() {
8396
8375
  const e14 = Math.max(1, this.config.maxConcurrentSegmentLoads ?? 2);
@@ -8409,53 +8388,41 @@ const le = class n2 extends BasePlugin {
8409
8388
  const t2 = e14.join(","), s2 = this.visibleRangeNeedsSegmentLoad(e14);
8410
8389
  if (t2 === this.lastVisibleIndicesKey && !s2) return;
8411
8390
  this.lastVisibleIndicesKey = t2;
8412
- const n9 = Date.now(), r2 = this.config.prefetchChapters ?? 1, a2 = e14[Math.floor(e14.length / 2)] ?? e14[0], o2 = /* @__PURE__ */ new Set(), i2 = /* @__PURE__ */ new Map(), h2 = (e15, t3, s3) => {
8391
+ const n9 = Date.now(), r2 = e14[Math.floor(e14.length / 2)] ?? e14[0], a2 = /* @__PURE__ */ new Set(), o2 = /* @__PURE__ */ new Map(), i2 = (e15, t3) => {
8413
8392
  if (t3 < 0) return;
8414
- const n10 = this.findChapter(e15);
8415
- if (!n10) return;
8416
- const r3 = se(n10);
8417
- if (r3 && t3 >= r3.segments.length) return;
8418
- const a3 = `${e15}:${t3}`, o3 = i2.get(a3);
8419
- (void 0 === o3 || s3 < o3) && i2.set(a3, s3);
8393
+ const s3 = this.findChapter(e15);
8394
+ if (!s3) return;
8395
+ const n10 = se(s3);
8396
+ if (n10 && t3 >= n10.segments.length) return;
8397
+ const r3 = `${e15}:${t3}`, a3 = this.globalSegmentSortKey(e15, t3), i3 = o2.get(r3);
8398
+ (void 0 === i3 || a3 < i3) && o2.set(r3, a3);
8420
8399
  };
8421
- for (const g2 of e14) {
8422
- const e15 = this.virtualPageMap.atIndex(g2);
8400
+ for (const d2 of e14) {
8401
+ const e15 = this.virtualPageMap.atIndex(d2);
8423
8402
  if (!e15) continue;
8424
- o2.add(e15.chapterId);
8403
+ a2.add(e15.chapterId);
8425
8404
  const t3 = this.findChapter(e15.chapterId);
8426
8405
  if (!t3) continue;
8427
- const s3 = Math.abs(g2 - a2), n10 = re(t3, e15.localPageIndex);
8428
- h2(e15.chapterId, n10, s3), h2(e15.chapterId, n10 + 1, s3 + this.SEG_PRIO_PREFETCH_NEXT), this.resolveChapterUrls(t3).catch(() => {
8406
+ const s3 = re(t3, e15.localPageIndex);
8407
+ i2(e15.chapterId, s3), this.resolveChapterUrls(t3).catch(() => {
8429
8408
  });
8430
8409
  }
8431
- if (0 === o2.size) return;
8432
- const d2 = this.manifest.chapters.map((e15) => e15.chapterId);
8433
- let l = 0;
8434
- const c2 = this.virtualPageMap.atIndex(a2);
8435
- if (c2) {
8436
- const e15 = d2.indexOf(c2.chapterId);
8437
- e15 >= 0 && (l = e15);
8438
- }
8439
- for (const g2 of o2) {
8440
- this.chapterLastUsed.set(g2, n9);
8441
- const e15 = d2.indexOf(g2);
8442
- if (-1 !== e15) for (let t3 = e15 - r2; t3 <= e15 + r2; t3++) {
8443
- if (t3 < 0 || t3 >= d2.length) continue;
8444
- const e16 = d2[t3];
8445
- this.chapterLastUsed.set(e16, n9);
8446
- const s3 = Math.abs(t3 - l);
8447
- h2(e16, 0, this.SEG_PRIO_CHAPTER_PREFETCH_BASE + 100 * s3);
8448
- const r3 = this.findChapter(e16);
8449
- r3 && this.resolveChapterUrls(r3).catch(() => {
8450
- });
8410
+ if (0 === a2.size) return;
8411
+ const h2 = this.virtualPageMap.atIndex(r2);
8412
+ if (h2) {
8413
+ const e15 = this.findChapter(h2.chapterId);
8414
+ if (e15) {
8415
+ const t3 = re(e15, h2.localPageIndex);
8416
+ i2(h2.chapterId, t3 + 1);
8451
8417
  }
8452
8418
  }
8453
- const u2 = [...i2.entries()].map(([e15, t3]) => {
8419
+ for (const d2 of a2) this.chapterLastUsed.set(d2, n9);
8420
+ const l = [...o2.entries()].map(([e15, t3]) => {
8454
8421
  const [s3, n10] = e15.split(":");
8455
8422
  return { chapterId: s3, segmentIndex: Number.parseInt(n10, 10), priority: t3 };
8456
8423
  }).filter((e15) => e15.chapterId && Number.isFinite(e15.segmentIndex));
8457
- if (this.scheduleVisibleSegmentLoads(u2), this.config.autoActivateOnLoad ?? 1) {
8458
- const e15 = this.virtualPageMap.atIndex(a2);
8424
+ if (this.scheduleVisibleSegmentLoads(l), this.config.autoActivateOnLoad ?? 1) {
8425
+ const e15 = this.virtualPageMap.atIndex(r2);
8459
8426
  if (e15) {
8460
8427
  const t3 = ne(this.findChapter(e15.chapterId), e15.localPageIndex);
8461
8428
  if (this.documentManager.provides().isDocumentOpen(t3.documentId)) {
@@ -8582,11 +8549,11 @@ const le = class n2 extends BasePlugin {
8582
8549
  const r2 = e14.chapterId, a2 = (null == t2 ? void 0 : t2.index) ?? 0, o2 = (null == t2 ? void 0 : t2.documentId) ?? r2;
8583
8550
  this.chapterErrorMessages.delete(r2), this.anySegmentOpen(r2) || this.updateStatus(r2, "loading"), this.chapterLastUsed.set(r2, Date.now());
8584
8551
  try {
8585
- const n9 = e14.encrypted && (null == (s2 = this.passwordProvider) ? void 0 : s2.getCachedPassword) ? this.passwordProvider.getCachedPassword(r2) : null, i2 = await this.resolvePdfPayload(e14, a2), h2 = this.documentManager.provides(), d2 = "url" in i2 ? h2.openDocumentUrl({ documentId: o2, url: i2.url, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }) : h2.openDocumentBuffer({ documentId: o2, buffer: i2.buffer, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }), l = await new Promise((e15, t3) => {
8586
- d2.wait((t4) => e15(t4), (e16) => t3(e16));
8552
+ const n9 = e14.encrypted && (null == (s2 = this.passwordProvider) ? void 0 : s2.getCachedPassword) ? this.passwordProvider.getCachedPassword(r2) : null, i2 = await this.resolvePdfPayload(e14, a2), h2 = this.documentManager.provides(), l = "url" in i2 ? h2.openDocumentUrl({ documentId: o2, url: i2.url, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }) : h2.openDocumentBuffer({ documentId: o2, buffer: i2.buffer, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }), d2 = await new Promise((e15, t3) => {
8553
+ l.wait((t4) => e15(t4), (e16) => t3(e16));
8587
8554
  });
8588
8555
  return await new Promise((e15, t3) => {
8589
- l.task.wait(() => e15(), (e16) => t3(e16));
8556
+ d2.task.wait(() => e15(), (e16) => t3(e16));
8590
8557
  }), h2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(r2), this.waitForTerminalStatus(r2);
8591
8558
  } catch (i2) {
8592
8559
  const e15 = this.chapterStatus.get(r2);
@@ -8647,8 +8614,8 @@ const le = class n2 extends BasePlugin {
8647
8614
  "error" === t2 && s2 ? this.chapterErrorMessages.set(e14, s2) : "loading" !== t2 && "loaded" !== t2 || this.chapterErrorMessages.delete(e14), n9 !== t2 && (this.chapterStatus.set(e14, t2), this.statusChange$.emit({ chapterId: e14, status: t2, ..."error" === t2 && s2 ? { error: { message: s2 } } : {} }));
8648
8615
  }
8649
8616
  };
8650
- le.id = "chapter-manager";
8651
- let ce = le;
8617
+ de.id = "chapter-manager";
8618
+ let ce = de;
8652
8619
  function ue(e14, t2) {
8653
8620
  if (e14 === t2) return true;
8654
8621
  if (e14.totalHeight !== t2.totalHeight || e14.totalWidth !== t2.totalWidth || e14.pageGap !== t2.pageGap || e14.items.length !== t2.items.length) return false;
@@ -8776,10 +8743,10 @@ const ge = class extends BasePlugin {
8776
8743
  }
8777
8744
  return i2.length > 0;
8778
8745
  };
8779
- if (a2) for (const d2 of a2.segments) {
8780
- if (!s2.isSegmentLoaded(e14, d2.index)) continue;
8781
- const t3 = d2.localPageEnd - d2.localPageStart + 1;
8782
- h2(d2.documentId, d2.localPageStart, 0, t3);
8746
+ if (a2) for (const l of a2.segments) {
8747
+ if (!s2.isSegmentLoaded(e14, l.index)) continue;
8748
+ const t3 = l.localPageEnd - l.localPageStart + 1;
8749
+ h2(l.documentId, l.localPageStart, 0, t3);
8783
8750
  }
8784
8751
  else s2.isSegmentLoaded(e14, 0) && h2(e14, 0, 0, r2.length);
8785
8752
  0 !== i2.length ? this.applyChapterPageSizes(e14, i2) : t2 < 60 && requestAnimationFrame(() => this.harvestChapterSizes(e14, t2 + 1));
@@ -8864,8 +8831,8 @@ const ge = class extends BasePlugin {
8864
8831
  if (!a2) return void this.scrollToIndex(e14, s2);
8865
8832
  const o2 = this.pageSizes.get(e14), i2 = this.chapterManager.provides().resolvePageDocument(a2.chapterId, a2.localPageIndex), h2 = i2 ? null == (n9 = this.documentManager.provides().getDocument(i2.documentId)) ? void 0 : n9.pages[i2.pageIndex] : void 0;
8866
8833
  if (!o2 || !h2) return void this.scrollToIndex(e14, s2);
8867
- const d2 = o2.height / h2.size.height, l = (this.offsets[e14] ?? 0) + t2 * d2 - r2;
8868
- this.viewportEl.scrollTo({ top: Math.max(0, l), behavior: (null == s2 ? void 0 : s2.behavior) ?? "auto" });
8834
+ const l = o2.height / h2.size.height, d2 = (this.offsets[e14] ?? 0) + t2 * l - r2;
8835
+ this.viewportEl.scrollTo({ top: Math.max(0, d2), behavior: (null == s2 ? void 0 : s2.behavior) ?? "auto" });
8869
8836
  }
8870
8837
  scrollToChapter(e14, t2) {
8871
8838
  if (!this.virtualPageMap) return;
@@ -8879,7 +8846,7 @@ const ge = class extends BasePlugin {
8879
8846
  }
8880
8847
  };
8881
8848
  ge.id = "chapter-scroll";
8882
- function ve(e14) {
8849
+ function Pe(e14) {
8883
8850
  const [t2, s2] = e14.localPageRange;
8884
8851
  return s2 - t2 + 1;
8885
8852
  }
@@ -8900,13 +8867,13 @@ function Ce(e14) {
8900
8867
  const s2 = e14.slice(0, t2), n9 = Number.parseInt(e14.slice(t2 + 2), 10);
8901
8868
  return !Number.isFinite(n9) || n9 < 0 ? { chapterId: e14, segmentIndex: null } : { chapterId: s2, segmentIndex: n9 };
8902
8869
  }
8903
- function we(e14, t2) {
8870
+ function ye(e14, t2) {
8904
8871
  return e14 <= 0 || t2 <= 0 ? 0 : Math.ceil(e14 / t2);
8905
8872
  }
8906
- function ye(e14) {
8873
+ function we(e14) {
8907
8874
  const t2 = be(e14);
8908
8875
  if (!t2) return null;
8909
- const s2 = ve(e14), n9 = we(s2, t2), r2 = Ie(e14.source) ? e14.source.urls : void 0, a2 = [];
8876
+ const s2 = Pe(e14), n9 = ye(s2, t2), r2 = Ie(e14.source) ? e14.source.urls : void 0, a2 = [];
8910
8877
  for (let o2 = 0; o2 < n9; o2++) {
8911
8878
  const n10 = o2 * t2, i2 = Math.min(n10 + t2 - 1, s2 - 1);
8912
8879
  if (n10 >= s2) break;
@@ -8915,7 +8882,7 @@ function ye(e14) {
8915
8882
  return { chapterId: e14.chapterId, threshold: t2, pageCount: s2, segments: a2 };
8916
8883
  }
8917
8884
  function Me(e14, t2) {
8918
- const s2 = ye(e14);
8885
+ const s2 = we(e14);
8919
8886
  if (!s2) return { documentId: e14.chapterId, pageIndex: t2 };
8920
8887
  const n9 = s2.segments.find((e15) => t2 >= e15.localPageStart && t2 <= e15.localPageEnd);
8921
8888
  if (!n9) {
@@ -8925,7 +8892,7 @@ function Me(e14, t2) {
8925
8892
  return { documentId: n9.documentId, pageIndex: t2 - n9.localPageStart };
8926
8893
  }
8927
8894
  function xe(e14, t2) {
8928
- const s2 = ye(e14);
8895
+ const s2 = we(e14);
8929
8896
  if (!s2) return 0;
8930
8897
  const n9 = s2.segments.find((e15) => t2 >= e15.localPageStart && t2 <= e15.localPageEnd);
8931
8898
  return (null == n9 ? void 0 : n9.index) ?? Math.floor(t2 / s2.threshold);
@@ -8934,12 +8901,12 @@ function Le(e14) {
8934
8901
  var t2;
8935
8902
  const s2 = be(e14);
8936
8903
  if (!s2) return [];
8937
- const n9 = [], { chapterId: r2 } = e14, a2 = ve(e14);
8904
+ const n9 = [], { chapterId: r2 } = e14, a2 = Pe(e14);
8938
8905
  s2 <= 0 && n9.push(`${r2}: segmentPageThreshold must be > 0`);
8939
8906
  const o2 = e14.source;
8940
8907
  if (!Ie(o2)) return n9;
8941
8908
  0 === o2.urls.length && n9.push(`${r2}: source.urls must not be empty`);
8942
- const i2 = we(a2, s2);
8909
+ const i2 = ye(a2, s2);
8943
8910
  o2.urls.length !== i2 && n9.push(`${r2}: source.urls.length (${o2.urls.length}) must equal ceil(pageCount/threshold) (${i2})`);
8944
8911
  for (let h2 = 0; h2 < o2.urls.length; h2++) (null == (t2 = o2.urls[h2]) ? void 0 : t2.trim()) || n9.push(`${r2}: source.urls[${h2}] is empty`);
8945
8912
  return n9;
@@ -8997,7 +8964,7 @@ let ke = class {
8997
8964
  return s2 ? this._pages.indexOf(s2) : -1;
8998
8965
  }
8999
8966
  };
9000
- function Ee(e14, t2 = $e) {
8967
+ function Ue(e14, t2 = $e) {
9001
8968
  const s2 = (function(e15, t3 = $e) {
9002
8969
  const s3 = /* @__PURE__ */ new Map();
9003
8970
  for (const r3 of e15.chapters) {
@@ -9017,14 +8984,14 @@ function Ee(e14, t2 = $e) {
9017
8984
  for (const i2 of r2) {
9018
8985
  const e15 = s2.get(i2), t3 = n9.get(e15);
9019
8986
  if (!t3) continue;
9020
- const [r3] = t3.globalPageRange, [h2] = t3.localPageRange, d2 = h2 + (i2 - r3);
9021
- a2.push({ globalPageIndex: o2++, globalPageNumber: i2, chapterId: e15, localPageIndex: d2 });
8987
+ const [r3] = t3.globalPageRange, [h2] = t3.localPageRange, l = h2 + (i2 - r3);
8988
+ a2.push({ globalPageIndex: o2++, globalPageNumber: i2, chapterId: e15, localPageIndex: l });
9022
8989
  }
9023
8990
  return new ke(a2);
9024
8991
  }
9025
- const Ue = class n3 extends BasePlugin {
8992
+ const Ee = class n3 extends BasePlugin {
9026
8993
  constructor(e14, n9) {
9027
- super(e14, n9), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = $e, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.SEG_PRIO_PREFETCH_NEXT = 120, this.SEG_PRIO_CHAPTER_PREFETCH_BASE = 3e3, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
8994
+ super(e14, n9), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = $e, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
9028
8995
  }
9029
8996
  async initialize(e14) {
9030
8997
  if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? $e, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
@@ -9049,7 +9016,7 @@ const Ue = class n3 extends BasePlugin {
9049
9016
  return s2 ? Me(s2, t2) : null;
9050
9017
  }, getSegmentPlan: (e14) => {
9051
9018
  const t2 = this.findChapter(e14);
9052
- return t2 ? ye(t2) : null;
9019
+ return t2 ? we(t2) : null;
9053
9020
  }, isSegmentLoaded: (e14, t2) => this.isSegmentDocumentOpen(e14, t2), isSegmentLoadPending: (e14, t2) => this.isSegmentLoadPending(e14, t2), getChapterErrorMessage: (e14) => this.chapterErrorMessages.get(e14), getChapterStatus: (e14) => this.chapterStatus.get(e14) ?? "idle", getChapter: (e14) => this.findChapter(e14), onChapterStatusChange: this.statusChange$.on, onManifestChange: this.manifestChange$.on };
9054
9021
  }
9055
9022
  destroy() {
@@ -9089,7 +9056,7 @@ const Ue = class n3 extends BasePlugin {
9089
9056
  const r2 = new Set(this.chapterStatus.keys()), a2 = new Set(t2.chapters.map((e15) => e15.chapterId));
9090
9057
  for (const n9 of r2) a2.has(n9) || (this.closeChapter(n9), this.chapterStatus.delete(n9), this.chapterErrorMessages.delete(n9), this.chapterUrlsCache.delete(n9), this.pendingChapterUrlsPromises.delete(n9));
9091
9058
  for (const n9 of t2.chapters) this.chapterStatus.has(n9.chapterId) || this.chapterStatus.set(n9.chapterId, "idle");
9092
- this.manifest = t2, this.lastVisibleIndicesKey = "", this.clearVisibleSegmentBacklog(), this.virtualPageMap = Ee(t2, this.overlapStrategy), this.manifestChange$.emit({ manifest: t2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
9059
+ this.manifest = t2, this.lastVisibleIndicesKey = "", this.clearVisibleSegmentBacklog(), this.virtualPageMap = Ue(t2, this.overlapStrategy), this.manifestChange$.emit({ manifest: t2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
9093
9060
  }
9094
9061
  eagerPrefetchFromManifest() {
9095
9062
  const e14 = this.config.prefetchChapters ?? 0;
@@ -9107,7 +9074,7 @@ const Ue = class n3 extends BasePlugin {
9107
9074
  }
9108
9075
  getSegmentPlanForChapter(e14) {
9109
9076
  const t2 = this.findChapter(e14);
9110
- return t2 ? ye(t2) : null;
9077
+ return t2 ? we(t2) : null;
9111
9078
  }
9112
9079
  anySegmentOpen(e14) {
9113
9080
  const t2 = this.getSegmentPlanForChapter(e14), s2 = this.documentManager.provides();
@@ -9166,13 +9133,22 @@ const Ue = class n3 extends BasePlugin {
9166
9133
  clearVisibleSegmentBacklog() {
9167
9134
  this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0;
9168
9135
  }
9136
+ globalSegmentSortKey(e14, t2) {
9137
+ var s2;
9138
+ if (!this.virtualPageMap) return Number.MAX_SAFE_INTEGER;
9139
+ const n9 = this.findChapter(e14);
9140
+ if (!n9) return Number.MAX_SAFE_INTEGER;
9141
+ const r2 = we(n9), a2 = (null == (s2 = null == r2 ? void 0 : r2.segments[t2]) ? void 0 : s2.localPageStart) ?? 0, o2 = this.virtualPageMap.toGlobal(e14, a2);
9142
+ if (o2) return o2.globalPageIndex;
9143
+ return 1e4 * this.manifest.chapters.findIndex((t3) => t3.chapterId === e14) + t2;
9144
+ }
9169
9145
  scheduleVisibleSegmentLoads(e14) {
9170
- const t2 = /* @__PURE__ */ new Set(), s2 = [...e14].sort((e15, t3) => e15.priority - t3.priority);
9171
- for (const n9 of s2) {
9172
- const e15 = `${n9.chapterId}:${n9.segmentIndex}`;
9173
- t2.has(e15) || (t2.add(e15), this.isSegmentDocumentOpen(n9.chapterId, n9.segmentIndex) || this.isSegmentLoadPending(n9.chapterId, n9.segmentIndex) || this.visibleSegmentBacklog.push({ chapterId: n9.chapterId, segmentIndex: n9.segmentIndex }));
9146
+ const t2 = [...e14].sort((e15, t3) => e15.priority - t3.priority), s2 = /* @__PURE__ */ new Set(), n9 = [];
9147
+ for (const r2 of t2) {
9148
+ const e15 = `${r2.chapterId}:${r2.segmentIndex}`;
9149
+ s2.has(e15) || (s2.add(e15), this.isSegmentDocumentOpen(r2.chapterId, r2.segmentIndex) || this.isSegmentLoadPending(r2.chapterId, r2.segmentIndex) || n9.push({ chapterId: r2.chapterId, segmentIndex: r2.segmentIndex }));
9174
9150
  }
9175
- this.pumpVisibleSegmentBacklog();
9151
+ this.visibleSegmentBacklog = n9, this.pumpVisibleSegmentBacklog();
9176
9152
  }
9177
9153
  pumpVisibleSegmentBacklog() {
9178
9154
  const e14 = Math.max(1, this.config.maxConcurrentSegmentLoads ?? 2);
@@ -9191,53 +9167,41 @@ const Ue = class n3 extends BasePlugin {
9191
9167
  const t2 = e14.join(","), s2 = this.visibleRangeNeedsSegmentLoad(e14);
9192
9168
  if (t2 === this.lastVisibleIndicesKey && !s2) return;
9193
9169
  this.lastVisibleIndicesKey = t2;
9194
- const n9 = Date.now(), r2 = this.config.prefetchChapters ?? 1, a2 = e14[Math.floor(e14.length / 2)] ?? e14[0], o2 = /* @__PURE__ */ new Set(), i2 = /* @__PURE__ */ new Map(), h2 = (e15, t3, s3) => {
9170
+ const n9 = Date.now(), r2 = e14[Math.floor(e14.length / 2)] ?? e14[0], a2 = /* @__PURE__ */ new Set(), o2 = /* @__PURE__ */ new Map(), i2 = (e15, t3) => {
9195
9171
  if (t3 < 0) return;
9196
- const n10 = this.findChapter(e15);
9197
- if (!n10) return;
9198
- const r3 = ye(n10);
9199
- if (r3 && t3 >= r3.segments.length) return;
9200
- const a3 = `${e15}:${t3}`, o3 = i2.get(a3);
9201
- (void 0 === o3 || s3 < o3) && i2.set(a3, s3);
9172
+ const s3 = this.findChapter(e15);
9173
+ if (!s3) return;
9174
+ const n10 = we(s3);
9175
+ if (n10 && t3 >= n10.segments.length) return;
9176
+ const r3 = `${e15}:${t3}`, a3 = this.globalSegmentSortKey(e15, t3), i3 = o2.get(r3);
9177
+ (void 0 === i3 || a3 < i3) && o2.set(r3, a3);
9202
9178
  };
9203
- for (const g2 of e14) {
9204
- const e15 = this.virtualPageMap.atIndex(g2);
9179
+ for (const d2 of e14) {
9180
+ const e15 = this.virtualPageMap.atIndex(d2);
9205
9181
  if (!e15) continue;
9206
- o2.add(e15.chapterId);
9182
+ a2.add(e15.chapterId);
9207
9183
  const t3 = this.findChapter(e15.chapterId);
9208
9184
  if (!t3) continue;
9209
- const s3 = Math.abs(g2 - a2), n10 = xe(t3, e15.localPageIndex);
9210
- h2(e15.chapterId, n10, s3), h2(e15.chapterId, n10 + 1, s3 + this.SEG_PRIO_PREFETCH_NEXT), this.resolveChapterUrls(t3).catch(() => {
9185
+ const s3 = xe(t3, e15.localPageIndex);
9186
+ i2(e15.chapterId, s3), this.resolveChapterUrls(t3).catch(() => {
9211
9187
  });
9212
9188
  }
9213
- if (0 === o2.size) return;
9214
- const d2 = this.manifest.chapters.map((e15) => e15.chapterId);
9215
- let l = 0;
9216
- const c2 = this.virtualPageMap.atIndex(a2);
9217
- if (c2) {
9218
- const e15 = d2.indexOf(c2.chapterId);
9219
- e15 >= 0 && (l = e15);
9220
- }
9221
- for (const g2 of o2) {
9222
- this.chapterLastUsed.set(g2, n9);
9223
- const e15 = d2.indexOf(g2);
9224
- if (-1 !== e15) for (let t3 = e15 - r2; t3 <= e15 + r2; t3++) {
9225
- if (t3 < 0 || t3 >= d2.length) continue;
9226
- const e16 = d2[t3];
9227
- this.chapterLastUsed.set(e16, n9);
9228
- const s3 = Math.abs(t3 - l);
9229
- h2(e16, 0, this.SEG_PRIO_CHAPTER_PREFETCH_BASE + 100 * s3);
9230
- const r3 = this.findChapter(e16);
9231
- r3 && this.resolveChapterUrls(r3).catch(() => {
9232
- });
9189
+ if (0 === a2.size) return;
9190
+ const h2 = this.virtualPageMap.atIndex(r2);
9191
+ if (h2) {
9192
+ const e15 = this.findChapter(h2.chapterId);
9193
+ if (e15) {
9194
+ const t3 = xe(e15, h2.localPageIndex);
9195
+ i2(h2.chapterId, t3 + 1);
9233
9196
  }
9234
9197
  }
9235
- const u2 = [...i2.entries()].map(([e15, t3]) => {
9198
+ for (const d2 of a2) this.chapterLastUsed.set(d2, n9);
9199
+ const l = [...o2.entries()].map(([e15, t3]) => {
9236
9200
  const [s3, n10] = e15.split(":");
9237
9201
  return { chapterId: s3, segmentIndex: Number.parseInt(n10, 10), priority: t3 };
9238
9202
  }).filter((e15) => e15.chapterId && Number.isFinite(e15.segmentIndex));
9239
- if (this.scheduleVisibleSegmentLoads(u2), this.config.autoActivateOnLoad ?? 1) {
9240
- const e15 = this.virtualPageMap.atIndex(a2);
9203
+ if (this.scheduleVisibleSegmentLoads(l), this.config.autoActivateOnLoad ?? 1) {
9204
+ const e15 = this.virtualPageMap.atIndex(r2);
9241
9205
  if (e15) {
9242
9206
  const t3 = Me(this.findChapter(e15.chapterId), e15.localPageIndex);
9243
9207
  if (this.documentManager.provides().isDocumentOpen(t3.documentId)) {
@@ -9275,7 +9239,7 @@ const Ue = class n3 extends BasePlugin {
9275
9239
  this.prepareChapterForSegmentLoad(e14);
9276
9240
  const s2 = this.findChapter(e14);
9277
9241
  if (!s2) return Promise.resolve("error");
9278
- const n9 = ye(s2);
9242
+ const n9 = we(s2);
9279
9243
  if (!n9) return 0 !== t2 ? Promise.resolve(this.isSegmentDocumentOpen(e14, 0) ? "loaded" : "error") : this.ensureSingleDocumentChapter(s2);
9280
9244
  if (t2 < 0 || t2 >= n9.segments.length) return Promise.resolve("error");
9281
9245
  const r2 = n9.segments[t2], a2 = r2.documentId;
@@ -9333,7 +9297,7 @@ const Ue = class n3 extends BasePlugin {
9333
9297
  async resolvePdfPayload(e14, t2) {
9334
9298
  const s2 = e14.source, r2 = this.config.chapterPdfLoader, a2 = be(e14);
9335
9299
  if (a2) {
9336
- const s3 = we(ve(e14), a2);
9300
+ const s3 = ye(Pe(e14), a2);
9337
9301
  if (t2 < 0 || t2 >= s3) throw new Error(`Chapter "${e14.chapterId}" invalid segmentIndex ${t2} (expected 0..${s3 - 1})`);
9338
9302
  const r3 = await this.resolveChapterUrls(e14);
9339
9303
  if (r3.length !== s3) {
@@ -9364,11 +9328,11 @@ const Ue = class n3 extends BasePlugin {
9364
9328
  const r2 = e14.chapterId, a2 = (null == t2 ? void 0 : t2.index) ?? 0, o2 = (null == t2 ? void 0 : t2.documentId) ?? r2;
9365
9329
  this.chapterErrorMessages.delete(r2), this.anySegmentOpen(r2) || this.updateStatus(r2, "loading"), this.chapterLastUsed.set(r2, Date.now());
9366
9330
  try {
9367
- const n9 = e14.encrypted && (null == (s2 = this.passwordProvider) ? void 0 : s2.getCachedPassword) ? this.passwordProvider.getCachedPassword(r2) : null, i2 = await this.resolvePdfPayload(e14, a2), h2 = this.documentManager.provides(), d2 = "url" in i2 ? h2.openDocumentUrl({ documentId: o2, url: i2.url, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }) : h2.openDocumentBuffer({ documentId: o2, buffer: i2.buffer, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }), l = await new Promise((e15, t3) => {
9368
- d2.wait((t4) => e15(t4), (e16) => t3(e16));
9331
+ const n9 = e14.encrypted && (null == (s2 = this.passwordProvider) ? void 0 : s2.getCachedPassword) ? this.passwordProvider.getCachedPassword(r2) : null, i2 = await this.resolvePdfPayload(e14, a2), h2 = this.documentManager.provides(), l = "url" in i2 ? h2.openDocumentUrl({ documentId: o2, url: i2.url, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }) : h2.openDocumentBuffer({ documentId: o2, buffer: i2.buffer, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }), d2 = await new Promise((e15, t3) => {
9332
+ l.wait((t4) => e15(t4), (e16) => t3(e16));
9369
9333
  });
9370
9334
  return await new Promise((e15, t3) => {
9371
- l.task.wait(() => e15(), (e16) => t3(e16));
9335
+ d2.task.wait(() => e15(), (e16) => t3(e16));
9372
9336
  }), h2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(r2), this.waitForTerminalStatus(r2);
9373
9337
  } catch (i2) {
9374
9338
  const e15 = this.chapterStatus.get(r2);
@@ -9413,7 +9377,7 @@ const Ue = class n3 extends BasePlugin {
9413
9377
  });
9414
9378
  }
9415
9379
  closeChapter(e14) {
9416
- const t2 = this.findChapter(e14), s2 = this.documentManager.provides(), n9 = t2 ? ye(t2) : null, r2 = (e15) => {
9380
+ const t2 = this.findChapter(e14), s2 = this.documentManager.provides(), n9 = t2 ? we(t2) : null, r2 = (e15) => {
9417
9381
  if (s2.isDocumentOpen(e15)) {
9418
9382
  s2.closeDocument(e15).wait(() => {
9419
9383
  }, () => {
@@ -9429,12 +9393,12 @@ const Ue = class n3 extends BasePlugin {
9429
9393
  "error" === t2 && s2 ? this.chapterErrorMessages.set(e14, s2) : "loading" !== t2 && "loaded" !== t2 || this.chapterErrorMessages.delete(e14), n9 !== t2 && (this.chapterStatus.set(e14, t2), this.statusChange$.emit({ chapterId: e14, status: t2, ..."error" === t2 && s2 ? { error: { message: s2 } } : {} }));
9430
9394
  }
9431
9395
  };
9432
- Ue.id = "chapter-manager";
9433
- let Te = Ue;
9396
+ Ee.id = "chapter-manager";
9397
+ let Te = Ee;
9434
9398
  function Fe2(e14) {
9435
9399
  return !!e14 && "urls" in e14 && Array.isArray(e14.urls);
9436
9400
  }
9437
- function Oe(e14, t2) {
9401
+ function Ne(e14, t2) {
9438
9402
  return `${e14}#s${t2}`;
9439
9403
  }
9440
9404
  function Ae(e14) {
@@ -9443,7 +9407,7 @@ function Ae(e14) {
9443
9407
  const s2 = e14.slice(0, t2), n9 = Number.parseInt(e14.slice(t2 + 2), 10);
9444
9408
  return !Number.isFinite(n9) || n9 < 0 ? { chapterId: e14, segmentIndex: null } : { chapterId: s2, segmentIndex: n9 };
9445
9409
  }
9446
- function Re(e14) {
9410
+ function Ve(e14) {
9447
9411
  const t2 = (function(e15) {
9448
9412
  if (null != e15.segmentPageThreshold && e15.segmentPageThreshold > 0) return e15.segmentPageThreshold;
9449
9413
  const t3 = e15.source;
@@ -9459,47 +9423,47 @@ function Re(e14) {
9459
9423
  for (let o2 = 0; o2 < n9; o2++) {
9460
9424
  const n10 = o2 * t2, i2 = Math.min(n10 + t2 - 1, s2 - 1);
9461
9425
  if (n10 >= s2) break;
9462
- a2.push({ index: o2, url: (null == r2 ? void 0 : r2[o2]) ?? "", localPageStart: n10, localPageEnd: i2, documentId: Oe(e14.chapterId, o2) });
9426
+ a2.push({ index: o2, url: (null == r2 ? void 0 : r2[o2]) ?? "", localPageStart: n10, localPageEnd: i2, documentId: Ne(e14.chapterId, o2) });
9463
9427
  }
9464
9428
  return { chapterId: e14.chapterId, threshold: t2, pageCount: s2, segments: a2 };
9465
9429
  }
9466
- function Ve(e14) {
9430
+ function Oe(e14) {
9467
9431
  const [t2, s2] = e14.localPageRange;
9468
9432
  return s2 - t2 + 1;
9469
9433
  }
9470
- function Ne(e14) {
9434
+ function Re(e14) {
9471
9435
  return !!e14 && "urls" in e14 && Array.isArray(e14.urls);
9472
9436
  }
9473
9437
  function Ge(e14) {
9474
9438
  if (null != e14.segmentPageThreshold && e14.segmentPageThreshold > 0) return e14.segmentPageThreshold;
9475
9439
  const t2 = e14.source;
9476
- return Ne(t2) ? t2.segmentPageThreshold : null;
9440
+ return Re(t2) ? t2.segmentPageThreshold : null;
9477
9441
  }
9478
- function _e(e14, t2) {
9442
+ function ze(e14, t2) {
9479
9443
  return `${e14}#s${t2}`;
9480
9444
  }
9481
- function ze(e14) {
9445
+ function Be(e14) {
9482
9446
  const t2 = e14.lastIndexOf("#s");
9483
9447
  if (-1 === t2) return { chapterId: e14, segmentIndex: null };
9484
9448
  const s2 = e14.slice(0, t2), n9 = Number.parseInt(e14.slice(t2 + 2), 10);
9485
9449
  return !Number.isFinite(n9) || n9 < 0 ? { chapterId: e14, segmentIndex: null } : { chapterId: s2, segmentIndex: n9 };
9486
9450
  }
9487
- function Be(e14, t2) {
9451
+ function _e(e14, t2) {
9488
9452
  return e14 <= 0 || t2 <= 0 ? 0 : Math.ceil(e14 / t2);
9489
9453
  }
9490
- function He(e14) {
9454
+ function qe(e14) {
9491
9455
  const t2 = Ge(e14);
9492
9456
  if (!t2) return null;
9493
- const s2 = Ve(e14), n9 = Be(s2, t2), r2 = Ne(e14.source) ? e14.source.urls : void 0, a2 = [];
9457
+ const s2 = Oe(e14), n9 = _e(s2, t2), r2 = Re(e14.source) ? e14.source.urls : void 0, a2 = [];
9494
9458
  for (let o2 = 0; o2 < n9; o2++) {
9495
9459
  const n10 = o2 * t2, i2 = Math.min(n10 + t2 - 1, s2 - 1);
9496
9460
  if (n10 >= s2) break;
9497
- a2.push({ index: o2, url: (null == r2 ? void 0 : r2[o2]) ?? "", localPageStart: n10, localPageEnd: i2, documentId: _e(e14.chapterId, o2) });
9461
+ a2.push({ index: o2, url: (null == r2 ? void 0 : r2[o2]) ?? "", localPageStart: n10, localPageEnd: i2, documentId: ze(e14.chapterId, o2) });
9498
9462
  }
9499
9463
  return { chapterId: e14.chapterId, threshold: t2, pageCount: s2, segments: a2 };
9500
9464
  }
9501
- function qe(e14, t2) {
9502
- const s2 = He(e14);
9465
+ function We(e14, t2) {
9466
+ const s2 = qe(e14);
9503
9467
  if (!s2) return { documentId: e14.chapterId, pageIndex: t2 };
9504
9468
  const n9 = s2.segments.find((e15) => t2 >= e15.localPageStart && t2 <= e15.localPageEnd);
9505
9469
  if (!n9) {
@@ -9508,22 +9472,22 @@ function qe(e14, t2) {
9508
9472
  }
9509
9473
  return { documentId: n9.documentId, pageIndex: t2 - n9.localPageStart };
9510
9474
  }
9511
- function We(e14, t2) {
9512
- const s2 = He(e14);
9475
+ function Ke(e14, t2) {
9476
+ const s2 = qe(e14);
9513
9477
  if (!s2) return 0;
9514
9478
  const n9 = s2.segments.find((e15) => t2 >= e15.localPageStart && t2 <= e15.localPageEnd);
9515
9479
  return (null == n9 ? void 0 : n9.index) ?? Math.floor(t2 / s2.threshold);
9516
9480
  }
9517
- function Ke(e14) {
9481
+ function He(e14) {
9518
9482
  var t2;
9519
9483
  const s2 = Ge(e14);
9520
9484
  if (!s2) return [];
9521
- const n9 = [], { chapterId: r2 } = e14, a2 = Ve(e14);
9485
+ const n9 = [], { chapterId: r2 } = e14, a2 = Oe(e14);
9522
9486
  s2 <= 0 && n9.push(`${r2}: segmentPageThreshold must be > 0`);
9523
9487
  const o2 = e14.source;
9524
- if (!Ne(o2)) return n9;
9488
+ if (!Re(o2)) return n9;
9525
9489
  0 === o2.urls.length && n9.push(`${r2}: source.urls must not be empty`);
9526
- const i2 = Be(a2, s2);
9490
+ const i2 = _e(a2, s2);
9527
9491
  o2.urls.length !== i2 && n9.push(`${r2}: source.urls.length (${o2.urls.length}) must equal ceil(pageCount/threshold) (${i2})`);
9528
9492
  for (let h2 = 0; h2 < o2.urls.length; h2++) (null == (t2 = o2.urls[h2]) ? void 0 : t2.trim()) || n9.push(`${r2}: source.urls[${h2}] is empty`);
9529
9493
  return n9;
@@ -9601,24 +9565,24 @@ function Qe(e14, t2 = je) {
9601
9565
  for (const i2 of r2) {
9602
9566
  const e15 = s2.get(i2), t3 = n9.get(e15);
9603
9567
  if (!t3) continue;
9604
- const [r3] = t3.globalPageRange, [h2] = t3.localPageRange, d2 = h2 + (i2 - r3);
9605
- a2.push({ globalPageIndex: o2++, globalPageNumber: i2, chapterId: e15, localPageIndex: d2 });
9568
+ const [r3] = t3.globalPageRange, [h2] = t3.localPageRange, l = h2 + (i2 - r3);
9569
+ a2.push({ globalPageIndex: o2++, globalPageNumber: i2, chapterId: e15, localPageIndex: l });
9606
9570
  }
9607
9571
  return new Je(a2);
9608
9572
  }
9609
9573
  const Ye = class n4 extends BasePlugin {
9610
9574
  constructor(e14, n9) {
9611
- super(e14, n9), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = je, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.SEG_PRIO_PREFETCH_NEXT = 120, this.SEG_PRIO_CHAPTER_PREFETCH_BASE = 3e3, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
9575
+ super(e14, n9), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = je, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
9612
9576
  }
9613
9577
  async initialize(e14) {
9614
9578
  if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? je, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
9615
- const { chapterId: t2 } = ze(e15.id);
9579
+ const { chapterId: t2 } = Be(e15.id);
9616
9580
  this.findChapter(t2) && (this.passwordAttempts.delete(t2), this.syncChapterStatusFromDocuments(t2));
9617
9581
  }), this.documentManager.provides().onDocumentClosed((e15) => {
9618
- const { chapterId: t2 } = ze(e15);
9582
+ const { chapterId: t2 } = Be(e15);
9619
9583
  this.findChapter(t2) && this.syncChapterStatusFromDocuments(t2);
9620
9584
  }), this.documentManager.provides().onDocumentError((e15) => {
9621
- const { chapterId: t2 } = ze(e15.documentId);
9585
+ const { chapterId: t2 } = Be(e15.documentId);
9622
9586
  this.findChapter(t2) && this.handleDocumentError(e15.documentId, t2, e15.code, e15.message);
9623
9587
  })), this.setManifestInternal(e14.manifest), e14.unloadTimeoutMs && e14.unloadTimeoutMs > 0) {
9624
9588
  const t2 = Math.max(5e3, Math.floor(e14.unloadTimeoutMs / 4));
@@ -9630,10 +9594,10 @@ const Ye = class n4 extends BasePlugin {
9630
9594
  t2 && (this.overlapStrategy = t2), this.setManifestInternal(e14);
9631
9595
  }, getManifest: () => this.manifest, getVirtualPageMap: () => this.virtualPageMap, setVisibleGlobalPages: (e14) => this.handleVisibleChange(e14), visibleRangeNeedsSegmentLoad: (e14) => this.visibleRangeNeedsSegmentLoad(e14), shouldShowChapterLoadError: (e14, t2) => this.shouldShowChapterLoadError(e14, t2), ensureChapterLoaded: (e14) => this.ensureChapterLoaded(e14), ensureSegmentLoaded: (e14, t2) => this.ensureSegmentLoaded(e14, t2), ensureAllSegmentsLoaded: (e14) => this.ensureAllSegmentsLoaded(e14), resolvePageDocument: (e14, t2) => {
9632
9596
  const s2 = this.findChapter(e14);
9633
- return s2 ? qe(s2, t2) : null;
9597
+ return s2 ? We(s2, t2) : null;
9634
9598
  }, getSegmentPlan: (e14) => {
9635
9599
  const t2 = this.findChapter(e14);
9636
- return t2 ? He(t2) : null;
9600
+ return t2 ? qe(t2) : null;
9637
9601
  }, isSegmentLoaded: (e14, t2) => this.isSegmentDocumentOpen(e14, t2), isSegmentLoadPending: (e14, t2) => this.isSegmentLoadPending(e14, t2), getChapterErrorMessage: (e14) => this.chapterErrorMessages.get(e14), getChapterStatus: (e14) => this.chapterStatus.get(e14) ?? "idle", getChapter: (e14) => this.findChapter(e14), onChapterStatusChange: this.statusChange$.on, onManifestChange: this.manifestChange$.on };
9638
9602
  }
9639
9603
  destroy() {
@@ -9665,7 +9629,7 @@ const Ye = class n4 extends BasePlugin {
9665
9629
  s3.has(n9.chapterId) && t3.push(`Duplicate chapterId: ${n9.chapterId}`), s3.add(n9.chapterId);
9666
9630
  const [e16, r3] = n9.globalPageRange, [a3, o2] = n9.localPageRange;
9667
9631
  if (e16 > r3 && t3.push(`${n9.chapterId}: invalid globalPageRange [${e16},${r3}]`), a3 > o2 && t3.push(`${n9.chapterId}: invalid localPageRange [${a3},${o2}]`), r3 - e16 !== o2 - a3 && t3.push(`${n9.chapterId}: page-count mismatch (global ${r3 - e16 + 1} vs local ${o2 - a3 + 1})`), n9.ownedGlobalPages) for (const s4 of n9.ownedGlobalPages) (s4 < e16 || s4 > r3) && t3.push(`${n9.chapterId}: ownedGlobalPages contains ${s4} outside range`);
9668
- t3.push(...Ke(n9));
9632
+ t3.push(...He(n9));
9669
9633
  }
9670
9634
  return t3;
9671
9635
  })(t2);
@@ -9691,7 +9655,7 @@ const Ye = class n4 extends BasePlugin {
9691
9655
  }
9692
9656
  getSegmentPlanForChapter(e14) {
9693
9657
  const t2 = this.findChapter(e14);
9694
- return t2 ? He(t2) : null;
9658
+ return t2 ? qe(t2) : null;
9695
9659
  }
9696
9660
  anySegmentOpen(e14) {
9697
9661
  const t2 = this.getSegmentPlanForChapter(e14), s2 = this.documentManager.provides();
@@ -9739,7 +9703,7 @@ const Ye = class n4 extends BasePlugin {
9739
9703
  if (!e15) continue;
9740
9704
  const s2 = this.findChapter(e15.chapterId);
9741
9705
  if (!s2) continue;
9742
- const n9 = We(s2, e15.localPageIndex);
9706
+ const n9 = Ke(s2, e15.localPageIndex);
9743
9707
  if (!this.isSegmentDocumentOpen(e15.chapterId, n9)) return true;
9744
9708
  }
9745
9709
  return false;
@@ -9750,13 +9714,22 @@ const Ye = class n4 extends BasePlugin {
9750
9714
  clearVisibleSegmentBacklog() {
9751
9715
  this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0;
9752
9716
  }
9717
+ globalSegmentSortKey(e14, t2) {
9718
+ var s2;
9719
+ if (!this.virtualPageMap) return Number.MAX_SAFE_INTEGER;
9720
+ const n9 = this.findChapter(e14);
9721
+ if (!n9) return Number.MAX_SAFE_INTEGER;
9722
+ const r2 = qe(n9), a2 = (null == (s2 = null == r2 ? void 0 : r2.segments[t2]) ? void 0 : s2.localPageStart) ?? 0, o2 = this.virtualPageMap.toGlobal(e14, a2);
9723
+ if (o2) return o2.globalPageIndex;
9724
+ return 1e4 * this.manifest.chapters.findIndex((t3) => t3.chapterId === e14) + t2;
9725
+ }
9753
9726
  scheduleVisibleSegmentLoads(e14) {
9754
- const t2 = /* @__PURE__ */ new Set(), s2 = [...e14].sort((e15, t3) => e15.priority - t3.priority);
9755
- for (const n9 of s2) {
9756
- const e15 = `${n9.chapterId}:${n9.segmentIndex}`;
9757
- t2.has(e15) || (t2.add(e15), this.isSegmentDocumentOpen(n9.chapterId, n9.segmentIndex) || this.isSegmentLoadPending(n9.chapterId, n9.segmentIndex) || this.visibleSegmentBacklog.push({ chapterId: n9.chapterId, segmentIndex: n9.segmentIndex }));
9727
+ const t2 = [...e14].sort((e15, t3) => e15.priority - t3.priority), s2 = /* @__PURE__ */ new Set(), n9 = [];
9728
+ for (const r2 of t2) {
9729
+ const e15 = `${r2.chapterId}:${r2.segmentIndex}`;
9730
+ s2.has(e15) || (s2.add(e15), this.isSegmentDocumentOpen(r2.chapterId, r2.segmentIndex) || this.isSegmentLoadPending(r2.chapterId, r2.segmentIndex) || n9.push({ chapterId: r2.chapterId, segmentIndex: r2.segmentIndex }));
9758
9731
  }
9759
- this.pumpVisibleSegmentBacklog();
9732
+ this.visibleSegmentBacklog = n9, this.pumpVisibleSegmentBacklog();
9760
9733
  }
9761
9734
  pumpVisibleSegmentBacklog() {
9762
9735
  const e14 = Math.max(1, this.config.maxConcurrentSegmentLoads ?? 2);
@@ -9775,55 +9748,43 @@ const Ye = class n4 extends BasePlugin {
9775
9748
  const t2 = e14.join(","), s2 = this.visibleRangeNeedsSegmentLoad(e14);
9776
9749
  if (t2 === this.lastVisibleIndicesKey && !s2) return;
9777
9750
  this.lastVisibleIndicesKey = t2;
9778
- const n9 = Date.now(), r2 = this.config.prefetchChapters ?? 1, a2 = e14[Math.floor(e14.length / 2)] ?? e14[0], o2 = /* @__PURE__ */ new Set(), i2 = /* @__PURE__ */ new Map(), h2 = (e15, t3, s3) => {
9751
+ const n9 = Date.now(), r2 = e14[Math.floor(e14.length / 2)] ?? e14[0], a2 = /* @__PURE__ */ new Set(), o2 = /* @__PURE__ */ new Map(), i2 = (e15, t3) => {
9779
9752
  if (t3 < 0) return;
9780
- const n10 = this.findChapter(e15);
9781
- if (!n10) return;
9782
- const r3 = He(n10);
9783
- if (r3 && t3 >= r3.segments.length) return;
9784
- const a3 = `${e15}:${t3}`, o3 = i2.get(a3);
9785
- (void 0 === o3 || s3 < o3) && i2.set(a3, s3);
9753
+ const s3 = this.findChapter(e15);
9754
+ if (!s3) return;
9755
+ const n10 = qe(s3);
9756
+ if (n10 && t3 >= n10.segments.length) return;
9757
+ const r3 = `${e15}:${t3}`, a3 = this.globalSegmentSortKey(e15, t3), i3 = o2.get(r3);
9758
+ (void 0 === i3 || a3 < i3) && o2.set(r3, a3);
9786
9759
  };
9787
- for (const g2 of e14) {
9788
- const e15 = this.virtualPageMap.atIndex(g2);
9760
+ for (const d2 of e14) {
9761
+ const e15 = this.virtualPageMap.atIndex(d2);
9789
9762
  if (!e15) continue;
9790
- o2.add(e15.chapterId);
9763
+ a2.add(e15.chapterId);
9791
9764
  const t3 = this.findChapter(e15.chapterId);
9792
9765
  if (!t3) continue;
9793
- const s3 = Math.abs(g2 - a2), n10 = We(t3, e15.localPageIndex);
9794
- h2(e15.chapterId, n10, s3), h2(e15.chapterId, n10 + 1, s3 + this.SEG_PRIO_PREFETCH_NEXT), this.resolveChapterUrls(t3).catch(() => {
9766
+ const s3 = Ke(t3, e15.localPageIndex);
9767
+ i2(e15.chapterId, s3), this.resolveChapterUrls(t3).catch(() => {
9795
9768
  });
9796
9769
  }
9797
- if (0 === o2.size) return;
9798
- const d2 = this.manifest.chapters.map((e15) => e15.chapterId);
9799
- let l = 0;
9800
- const c2 = this.virtualPageMap.atIndex(a2);
9801
- if (c2) {
9802
- const e15 = d2.indexOf(c2.chapterId);
9803
- e15 >= 0 && (l = e15);
9804
- }
9805
- for (const g2 of o2) {
9806
- this.chapterLastUsed.set(g2, n9);
9807
- const e15 = d2.indexOf(g2);
9808
- if (-1 !== e15) for (let t3 = e15 - r2; t3 <= e15 + r2; t3++) {
9809
- if (t3 < 0 || t3 >= d2.length) continue;
9810
- const e16 = d2[t3];
9811
- this.chapterLastUsed.set(e16, n9);
9812
- const s3 = Math.abs(t3 - l);
9813
- h2(e16, 0, this.SEG_PRIO_CHAPTER_PREFETCH_BASE + 100 * s3);
9814
- const r3 = this.findChapter(e16);
9815
- r3 && this.resolveChapterUrls(r3).catch(() => {
9816
- });
9770
+ if (0 === a2.size) return;
9771
+ const h2 = this.virtualPageMap.atIndex(r2);
9772
+ if (h2) {
9773
+ const e15 = this.findChapter(h2.chapterId);
9774
+ if (e15) {
9775
+ const t3 = Ke(e15, h2.localPageIndex);
9776
+ i2(h2.chapterId, t3 + 1);
9817
9777
  }
9818
9778
  }
9819
- const u2 = [...i2.entries()].map(([e15, t3]) => {
9779
+ for (const d2 of a2) this.chapterLastUsed.set(d2, n9);
9780
+ const l = [...o2.entries()].map(([e15, t3]) => {
9820
9781
  const [s3, n10] = e15.split(":");
9821
9782
  return { chapterId: s3, segmentIndex: Number.parseInt(n10, 10), priority: t3 };
9822
9783
  }).filter((e15) => e15.chapterId && Number.isFinite(e15.segmentIndex));
9823
- if (this.scheduleVisibleSegmentLoads(u2), this.config.autoActivateOnLoad ?? 1) {
9824
- const e15 = this.virtualPageMap.atIndex(a2);
9784
+ if (this.scheduleVisibleSegmentLoads(l), this.config.autoActivateOnLoad ?? 1) {
9785
+ const e15 = this.virtualPageMap.atIndex(r2);
9825
9786
  if (e15) {
9826
- const t3 = qe(this.findChapter(e15.chapterId), e15.localPageIndex);
9787
+ const t3 = We(this.findChapter(e15.chapterId), e15.localPageIndex);
9827
9788
  if (this.documentManager.provides().isDocumentOpen(t3.documentId)) {
9828
9789
  this.documentManager.provides().getActiveDocumentId() !== t3.documentId && this.documentManager.provides().setActiveDocument(t3.documentId);
9829
9790
  }
@@ -9859,7 +9820,7 @@ const Ye = class n4 extends BasePlugin {
9859
9820
  this.prepareChapterForSegmentLoad(e14);
9860
9821
  const s2 = this.findChapter(e14);
9861
9822
  if (!s2) return Promise.resolve("error");
9862
- const n9 = He(s2);
9823
+ const n9 = qe(s2);
9863
9824
  if (!n9) return 0 !== t2 ? Promise.resolve(this.isSegmentDocumentOpen(e14, 0) ? "loaded" : "error") : this.ensureSingleDocumentChapter(s2);
9864
9825
  if (t2 < 0 || t2 >= n9.segments.length) return Promise.resolve("error");
9865
9826
  const r2 = n9.segments[t2], a2 = r2.documentId;
@@ -9889,7 +9850,7 @@ const Ye = class n4 extends BasePlugin {
9889
9850
  if (n9) return n9;
9890
9851
  const r2 = (async () => {
9891
9852
  const s3 = e14.source;
9892
- if (Ne(s3)) {
9853
+ if (Re(s3)) {
9893
9854
  const e15 = [...s3.urls];
9894
9855
  return this.chapterUrlsCache.set(t2, e15), e15;
9895
9856
  }
@@ -9917,7 +9878,7 @@ const Ye = class n4 extends BasePlugin {
9917
9878
  async resolvePdfPayload(e14, t2) {
9918
9879
  const s2 = e14.source, r2 = this.config.chapterPdfLoader, a2 = Ge(e14);
9919
9880
  if (a2) {
9920
- const s3 = Be(Ve(e14), a2);
9881
+ const s3 = _e(Oe(e14), a2);
9921
9882
  if (t2 < 0 || t2 >= s3) throw new Error(`Chapter "${e14.chapterId}" invalid segmentIndex ${t2} (expected 0..${s3 - 1})`);
9922
9883
  const r3 = await this.resolveChapterUrls(e14);
9923
9884
  if (r3.length !== s3) {
@@ -9928,7 +9889,7 @@ const Ye = class n4 extends BasePlugin {
9928
9889
  }
9929
9890
  if (0 !== t2) throw new Error(`Chapter "${e14.chapterId}" is not segmented`);
9930
9891
  if (s2) {
9931
- if (Ne(s2)) {
9892
+ if (Re(s2)) {
9932
9893
  const s3 = await this.resolveChapterUrls(e14);
9933
9894
  return this.openPayloadFromUrl(e14, t2, s3);
9934
9895
  }
@@ -9948,11 +9909,11 @@ const Ye = class n4 extends BasePlugin {
9948
9909
  const r2 = e14.chapterId, a2 = (null == t2 ? void 0 : t2.index) ?? 0, o2 = (null == t2 ? void 0 : t2.documentId) ?? r2;
9949
9910
  this.chapterErrorMessages.delete(r2), this.anySegmentOpen(r2) || this.updateStatus(r2, "loading"), this.chapterLastUsed.set(r2, Date.now());
9950
9911
  try {
9951
- const n9 = e14.encrypted && (null == (s2 = this.passwordProvider) ? void 0 : s2.getCachedPassword) ? this.passwordProvider.getCachedPassword(r2) : null, i2 = await this.resolvePdfPayload(e14, a2), h2 = this.documentManager.provides(), d2 = "url" in i2 ? h2.openDocumentUrl({ documentId: o2, url: i2.url, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }) : h2.openDocumentBuffer({ documentId: o2, buffer: i2.buffer, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }), l = await new Promise((e15, t3) => {
9952
- d2.wait((t4) => e15(t4), (e16) => t3(e16));
9912
+ const n9 = e14.encrypted && (null == (s2 = this.passwordProvider) ? void 0 : s2.getCachedPassword) ? this.passwordProvider.getCachedPassword(r2) : null, i2 = await this.resolvePdfPayload(e14, a2), h2 = this.documentManager.provides(), l = "url" in i2 ? h2.openDocumentUrl({ documentId: o2, url: i2.url, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }) : h2.openDocumentBuffer({ documentId: o2, buffer: i2.buffer, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }), d2 = await new Promise((e15, t3) => {
9913
+ l.wait((t4) => e15(t4), (e16) => t3(e16));
9953
9914
  });
9954
9915
  return await new Promise((e15, t3) => {
9955
- l.task.wait(() => e15(), (e16) => t3(e16));
9916
+ d2.task.wait(() => e15(), (e16) => t3(e16));
9956
9917
  }), h2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(r2), this.waitForTerminalStatus(r2);
9957
9918
  } catch (i2) {
9958
9919
  const e15 = this.chapterStatus.get(r2);
@@ -9976,7 +9937,7 @@ const Ye = class n4 extends BasePlugin {
9976
9937
  async handleDocumentError(e14, t2, s2, r2) {
9977
9938
  if (this.pendingSegmentLoadPromises.has(e14)) return;
9978
9939
  if (s2 !== PdfErrorCode.Password) {
9979
- const s3 = this.getSegmentPlanForChapter(t2), { segmentIndex: n9 } = ze(e14);
9940
+ const s3 = this.getSegmentPlanForChapter(t2), { segmentIndex: n9 } = Be(e14);
9980
9941
  return void (s3 && 0 !== n9 && null !== n9 || this.updateStatus(t2, "error"));
9981
9942
  }
9982
9943
  if (!this.passwordProvider) return void this.updateStatus(t2, "password-required");
@@ -9997,7 +9958,7 @@ const Ye = class n4 extends BasePlugin {
9997
9958
  });
9998
9959
  }
9999
9960
  closeChapter(e14) {
10000
- const t2 = this.findChapter(e14), s2 = this.documentManager.provides(), n9 = t2 ? He(t2) : null, r2 = (e15) => {
9961
+ const t2 = this.findChapter(e14), s2 = this.documentManager.provides(), n9 = t2 ? qe(t2) : null, r2 = (e15) => {
10001
9962
  if (s2.isDocumentOpen(e15)) {
10002
9963
  s2.closeDocument(e15).wait(() => {
10003
9964
  }, () => {
@@ -10042,7 +10003,7 @@ const tt = class extends BasePlugin {
10042
10003
  const s2 = this.chapterManager.provides(), n9 = s2.getChapter(e14);
10043
10004
  if (!n9) return true;
10044
10005
  const r2 = (function(e15, t3) {
10045
- const s3 = Re(e15);
10006
+ const s3 = Ve(e15);
10046
10007
  if (!s3) return 0;
10047
10008
  const n10 = s3.segments.find((e16) => t3 >= e16.localPageStart && t3 <= e16.localPageEnd);
10048
10009
  return (null == n10 ? void 0 : n10.index) ?? Math.floor(t3 / s3.threshold);
@@ -10131,7 +10092,7 @@ const tt = class extends BasePlugin {
10131
10092
  if (!this.virtualPageMap) return;
10132
10093
  const s2 = this.chapterManager.provides(), n9 = s2.getChapter(e14), r2 = this.virtualPageMap.pagesOfChapter(e14);
10133
10094
  if (!n9 || 0 === r2.length) return;
10134
- const a2 = Re(n9), o2 = this.documentManager.provides(), i2 = [], h2 = (e15, t3, s3, n10) => {
10095
+ const a2 = Ve(n9), o2 = this.documentManager.provides(), i2 = [], h2 = (e15, t3, s3, n10) => {
10135
10096
  var r3;
10136
10097
  const a3 = o2.getDocument(e15);
10137
10098
  if (!(null == (r3 = null == a3 ? void 0 : a3.pages) ? void 0 : r3.length)) return false;
@@ -10142,10 +10103,10 @@ const tt = class extends BasePlugin {
10142
10103
  }
10143
10104
  return i2.length > 0;
10144
10105
  };
10145
- if (a2) for (const d2 of a2.segments) {
10146
- if (!s2.isSegmentLoaded(e14, d2.index)) continue;
10147
- const t3 = d2.localPageEnd - d2.localPageStart + 1;
10148
- h2(d2.documentId, d2.localPageStart, 0, t3);
10106
+ if (a2) for (const l of a2.segments) {
10107
+ if (!s2.isSegmentLoaded(e14, l.index)) continue;
10108
+ const t3 = l.localPageEnd - l.localPageStart + 1;
10109
+ h2(l.documentId, l.localPageStart, 0, t3);
10149
10110
  }
10150
10111
  else s2.isSegmentLoaded(e14, 0) && h2(e14, 0, 0, r2.length);
10151
10112
  0 !== i2.length ? this.applyChapterPageSizes(e14, i2) : t2 < 60 && requestAnimationFrame(() => this.harvestChapterSizes(e14, t2 + 1));
@@ -10230,8 +10191,8 @@ const tt = class extends BasePlugin {
10230
10191
  if (!a2) return void this.scrollToIndex(e14, s2);
10231
10192
  const o2 = this.pageSizes.get(e14), i2 = this.chapterManager.provides().resolvePageDocument(a2.chapterId, a2.localPageIndex), h2 = i2 ? null == (n9 = this.documentManager.provides().getDocument(i2.documentId)) ? void 0 : n9.pages[i2.pageIndex] : void 0;
10232
10193
  if (!o2 || !h2) return void this.scrollToIndex(e14, s2);
10233
- const d2 = o2.height / h2.size.height, l = (this.offsets[e14] ?? 0) + t2 * d2 - r2;
10234
- this.viewportEl.scrollTo({ top: Math.max(0, l), behavior: (null == s2 ? void 0 : s2.behavior) ?? "auto" });
10194
+ const l = o2.height / h2.size.height, d2 = (this.offsets[e14] ?? 0) + t2 * l - r2;
10195
+ this.viewportEl.scrollTo({ top: Math.max(0, d2), behavior: (null == s2 ? void 0 : s2.behavior) ?? "auto" });
10235
10196
  }
10236
10197
  scrollToChapter(e14, t2) {
10237
10198
  if (!this.virtualPageMap) return;
@@ -10360,17 +10321,17 @@ function at(e14) {
10360
10321
  const t2 = e14[e14.length - 1];
10361
10322
  return { x: t2.origin.x + t2.size.width, y: t2.origin.y + t2.size.height };
10362
10323
  }
10363
- function dt(e14) {
10324
+ function lt(e14) {
10364
10325
  const [t2, s2] = e14.localPageRange;
10365
10326
  return s2 - t2 + 1;
10366
10327
  }
10367
- function lt(e14) {
10328
+ function dt(e14) {
10368
10329
  return !!e14 && "urls" in e14 && Array.isArray(e14.urls);
10369
10330
  }
10370
10331
  function ct(e14) {
10371
10332
  if (null != e14.segmentPageThreshold && e14.segmentPageThreshold > 0) return e14.segmentPageThreshold;
10372
10333
  const t2 = e14.source;
10373
- return lt(t2) ? t2.segmentPageThreshold : null;
10334
+ return dt(t2) ? t2.segmentPageThreshold : null;
10374
10335
  }
10375
10336
  function ut(e14, t2) {
10376
10337
  return `${e14}#s${t2}`;
@@ -10387,7 +10348,7 @@ function pt(e14, t2) {
10387
10348
  function mt(e14) {
10388
10349
  const t2 = ct(e14);
10389
10350
  if (!t2) return null;
10390
- const s2 = dt(e14), n9 = pt(s2, t2), r2 = lt(e14.source) ? e14.source.urls : void 0, a2 = [];
10351
+ const s2 = lt(e14), n9 = pt(s2, t2), r2 = dt(e14.source) ? e14.source.urls : void 0, a2 = [];
10391
10352
  for (let o2 = 0; o2 < n9; o2++) {
10392
10353
  const n10 = o2 * t2, i2 = Math.min(n10 + t2 - 1, s2 - 1);
10393
10354
  if (n10 >= s2) break;
@@ -10405,20 +10366,20 @@ function ft(e14, t2) {
10405
10366
  }
10406
10367
  return { documentId: n9.documentId, pageIndex: t2 - n9.localPageStart };
10407
10368
  }
10408
- function Pt(e14, t2) {
10369
+ function vt(e14, t2) {
10409
10370
  const s2 = mt(e14);
10410
10371
  if (!s2) return 0;
10411
10372
  const n9 = s2.segments.find((e15) => t2 >= e15.localPageStart && t2 <= e15.localPageEnd);
10412
10373
  return (null == n9 ? void 0 : n9.index) ?? Math.floor(t2 / s2.threshold);
10413
10374
  }
10414
- function vt(e14) {
10375
+ function Pt(e14) {
10415
10376
  var t2;
10416
10377
  const s2 = ct(e14);
10417
10378
  if (!s2) return [];
10418
- const n9 = [], { chapterId: r2 } = e14, a2 = dt(e14);
10379
+ const n9 = [], { chapterId: r2 } = e14, a2 = lt(e14);
10419
10380
  s2 <= 0 && n9.push(`${r2}: segmentPageThreshold must be > 0`);
10420
10381
  const o2 = e14.source;
10421
- if (!lt(o2)) return n9;
10382
+ if (!dt(o2)) return n9;
10422
10383
  0 === o2.urls.length && n9.push(`${r2}: source.urls must not be empty`);
10423
10384
  const i2 = pt(a2, s2);
10424
10385
  o2.urls.length !== i2 && n9.push(`${r2}: source.urls.length (${o2.urls.length}) must equal ceil(pageCount/threshold) (${i2})`);
@@ -10498,14 +10459,14 @@ function Ct(e14, t2 = It) {
10498
10459
  for (const i2 of r2) {
10499
10460
  const e15 = s2.get(i2), t3 = n9.get(e15);
10500
10461
  if (!t3) continue;
10501
- const [r3] = t3.globalPageRange, [h2] = t3.localPageRange, d2 = h2 + (i2 - r3);
10502
- a2.push({ globalPageIndex: o2++, globalPageNumber: i2, chapterId: e15, localPageIndex: d2 });
10462
+ const [r3] = t3.globalPageRange, [h2] = t3.localPageRange, l = h2 + (i2 - r3);
10463
+ a2.push({ globalPageIndex: o2++, globalPageNumber: i2, chapterId: e15, localPageIndex: l });
10503
10464
  }
10504
10465
  return new St(a2);
10505
10466
  }
10506
- const wt = class n6 extends BasePlugin {
10467
+ const yt2 = class n6 extends BasePlugin {
10507
10468
  constructor(e14, n9) {
10508
- super(e14, n9), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = It, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.SEG_PRIO_PREFETCH_NEXT = 120, this.SEG_PRIO_CHAPTER_PREFETCH_BASE = 3e3, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
10469
+ super(e14, n9), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = It, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
10509
10470
  }
10510
10471
  async initialize(e14) {
10511
10472
  if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? It, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
@@ -10562,7 +10523,7 @@ const wt = class n6 extends BasePlugin {
10562
10523
  s3.has(n9.chapterId) && t3.push(`Duplicate chapterId: ${n9.chapterId}`), s3.add(n9.chapterId);
10563
10524
  const [e16, r3] = n9.globalPageRange, [a3, o2] = n9.localPageRange;
10564
10525
  if (e16 > r3 && t3.push(`${n9.chapterId}: invalid globalPageRange [${e16},${r3}]`), a3 > o2 && t3.push(`${n9.chapterId}: invalid localPageRange [${a3},${o2}]`), r3 - e16 !== o2 - a3 && t3.push(`${n9.chapterId}: page-count mismatch (global ${r3 - e16 + 1} vs local ${o2 - a3 + 1})`), n9.ownedGlobalPages) for (const s4 of n9.ownedGlobalPages) (s4 < e16 || s4 > r3) && t3.push(`${n9.chapterId}: ownedGlobalPages contains ${s4} outside range`);
10565
- t3.push(...vt(n9));
10526
+ t3.push(...Pt(n9));
10566
10527
  }
10567
10528
  return t3;
10568
10529
  })(t2);
@@ -10636,7 +10597,7 @@ const wt = class n6 extends BasePlugin {
10636
10597
  if (!e15) continue;
10637
10598
  const s2 = this.findChapter(e15.chapterId);
10638
10599
  if (!s2) continue;
10639
- const n9 = Pt(s2, e15.localPageIndex);
10600
+ const n9 = vt(s2, e15.localPageIndex);
10640
10601
  if (!this.isSegmentDocumentOpen(e15.chapterId, n9)) return true;
10641
10602
  }
10642
10603
  return false;
@@ -10647,13 +10608,22 @@ const wt = class n6 extends BasePlugin {
10647
10608
  clearVisibleSegmentBacklog() {
10648
10609
  this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0;
10649
10610
  }
10611
+ globalSegmentSortKey(e14, t2) {
10612
+ var s2;
10613
+ if (!this.virtualPageMap) return Number.MAX_SAFE_INTEGER;
10614
+ const n9 = this.findChapter(e14);
10615
+ if (!n9) return Number.MAX_SAFE_INTEGER;
10616
+ const r2 = mt(n9), a2 = (null == (s2 = null == r2 ? void 0 : r2.segments[t2]) ? void 0 : s2.localPageStart) ?? 0, o2 = this.virtualPageMap.toGlobal(e14, a2);
10617
+ if (o2) return o2.globalPageIndex;
10618
+ return 1e4 * this.manifest.chapters.findIndex((t3) => t3.chapterId === e14) + t2;
10619
+ }
10650
10620
  scheduleVisibleSegmentLoads(e14) {
10651
- const t2 = /* @__PURE__ */ new Set(), s2 = [...e14].sort((e15, t3) => e15.priority - t3.priority);
10652
- for (const n9 of s2) {
10653
- const e15 = `${n9.chapterId}:${n9.segmentIndex}`;
10654
- t2.has(e15) || (t2.add(e15), this.isSegmentDocumentOpen(n9.chapterId, n9.segmentIndex) || this.isSegmentLoadPending(n9.chapterId, n9.segmentIndex) || this.visibleSegmentBacklog.push({ chapterId: n9.chapterId, segmentIndex: n9.segmentIndex }));
10621
+ const t2 = [...e14].sort((e15, t3) => e15.priority - t3.priority), s2 = /* @__PURE__ */ new Set(), n9 = [];
10622
+ for (const r2 of t2) {
10623
+ const e15 = `${r2.chapterId}:${r2.segmentIndex}`;
10624
+ s2.has(e15) || (s2.add(e15), this.isSegmentDocumentOpen(r2.chapterId, r2.segmentIndex) || this.isSegmentLoadPending(r2.chapterId, r2.segmentIndex) || n9.push({ chapterId: r2.chapterId, segmentIndex: r2.segmentIndex }));
10655
10625
  }
10656
- this.pumpVisibleSegmentBacklog();
10626
+ this.visibleSegmentBacklog = n9, this.pumpVisibleSegmentBacklog();
10657
10627
  }
10658
10628
  pumpVisibleSegmentBacklog() {
10659
10629
  const e14 = Math.max(1, this.config.maxConcurrentSegmentLoads ?? 2);
@@ -10672,53 +10642,41 @@ const wt = class n6 extends BasePlugin {
10672
10642
  const t2 = e14.join(","), s2 = this.visibleRangeNeedsSegmentLoad(e14);
10673
10643
  if (t2 === this.lastVisibleIndicesKey && !s2) return;
10674
10644
  this.lastVisibleIndicesKey = t2;
10675
- const n9 = Date.now(), r2 = this.config.prefetchChapters ?? 1, a2 = e14[Math.floor(e14.length / 2)] ?? e14[0], o2 = /* @__PURE__ */ new Set(), i2 = /* @__PURE__ */ new Map(), h2 = (e15, t3, s3) => {
10645
+ const n9 = Date.now(), r2 = e14[Math.floor(e14.length / 2)] ?? e14[0], a2 = /* @__PURE__ */ new Set(), o2 = /* @__PURE__ */ new Map(), i2 = (e15, t3) => {
10676
10646
  if (t3 < 0) return;
10677
- const n10 = this.findChapter(e15);
10678
- if (!n10) return;
10679
- const r3 = mt(n10);
10680
- if (r3 && t3 >= r3.segments.length) return;
10681
- const a3 = `${e15}:${t3}`, o3 = i2.get(a3);
10682
- (void 0 === o3 || s3 < o3) && i2.set(a3, s3);
10647
+ const s3 = this.findChapter(e15);
10648
+ if (!s3) return;
10649
+ const n10 = mt(s3);
10650
+ if (n10 && t3 >= n10.segments.length) return;
10651
+ const r3 = `${e15}:${t3}`, a3 = this.globalSegmentSortKey(e15, t3), i3 = o2.get(r3);
10652
+ (void 0 === i3 || a3 < i3) && o2.set(r3, a3);
10683
10653
  };
10684
- for (const g2 of e14) {
10685
- const e15 = this.virtualPageMap.atIndex(g2);
10654
+ for (const d2 of e14) {
10655
+ const e15 = this.virtualPageMap.atIndex(d2);
10686
10656
  if (!e15) continue;
10687
- o2.add(e15.chapterId);
10657
+ a2.add(e15.chapterId);
10688
10658
  const t3 = this.findChapter(e15.chapterId);
10689
10659
  if (!t3) continue;
10690
- const s3 = Math.abs(g2 - a2), n10 = Pt(t3, e15.localPageIndex);
10691
- h2(e15.chapterId, n10, s3), h2(e15.chapterId, n10 + 1, s3 + this.SEG_PRIO_PREFETCH_NEXT), this.resolveChapterUrls(t3).catch(() => {
10660
+ const s3 = vt(t3, e15.localPageIndex);
10661
+ i2(e15.chapterId, s3), this.resolveChapterUrls(t3).catch(() => {
10692
10662
  });
10693
10663
  }
10694
- if (0 === o2.size) return;
10695
- const d2 = this.manifest.chapters.map((e15) => e15.chapterId);
10696
- let l = 0;
10697
- const c2 = this.virtualPageMap.atIndex(a2);
10698
- if (c2) {
10699
- const e15 = d2.indexOf(c2.chapterId);
10700
- e15 >= 0 && (l = e15);
10701
- }
10702
- for (const g2 of o2) {
10703
- this.chapterLastUsed.set(g2, n9);
10704
- const e15 = d2.indexOf(g2);
10705
- if (-1 !== e15) for (let t3 = e15 - r2; t3 <= e15 + r2; t3++) {
10706
- if (t3 < 0 || t3 >= d2.length) continue;
10707
- const e16 = d2[t3];
10708
- this.chapterLastUsed.set(e16, n9);
10709
- const s3 = Math.abs(t3 - l);
10710
- h2(e16, 0, this.SEG_PRIO_CHAPTER_PREFETCH_BASE + 100 * s3);
10711
- const r3 = this.findChapter(e16);
10712
- r3 && this.resolveChapterUrls(r3).catch(() => {
10713
- });
10664
+ if (0 === a2.size) return;
10665
+ const h2 = this.virtualPageMap.atIndex(r2);
10666
+ if (h2) {
10667
+ const e15 = this.findChapter(h2.chapterId);
10668
+ if (e15) {
10669
+ const t3 = vt(e15, h2.localPageIndex);
10670
+ i2(h2.chapterId, t3 + 1);
10714
10671
  }
10715
10672
  }
10716
- const u2 = [...i2.entries()].map(([e15, t3]) => {
10673
+ for (const d2 of a2) this.chapterLastUsed.set(d2, n9);
10674
+ const l = [...o2.entries()].map(([e15, t3]) => {
10717
10675
  const [s3, n10] = e15.split(":");
10718
10676
  return { chapterId: s3, segmentIndex: Number.parseInt(n10, 10), priority: t3 };
10719
10677
  }).filter((e15) => e15.chapterId && Number.isFinite(e15.segmentIndex));
10720
- if (this.scheduleVisibleSegmentLoads(u2), this.config.autoActivateOnLoad ?? 1) {
10721
- const e15 = this.virtualPageMap.atIndex(a2);
10678
+ if (this.scheduleVisibleSegmentLoads(l), this.config.autoActivateOnLoad ?? 1) {
10679
+ const e15 = this.virtualPageMap.atIndex(r2);
10722
10680
  if (e15) {
10723
10681
  const t3 = ft(this.findChapter(e15.chapterId), e15.localPageIndex);
10724
10682
  if (this.documentManager.provides().isDocumentOpen(t3.documentId)) {
@@ -10786,7 +10744,7 @@ const wt = class n6 extends BasePlugin {
10786
10744
  if (n9) return n9;
10787
10745
  const r2 = (async () => {
10788
10746
  const s3 = e14.source;
10789
- if (lt(s3)) {
10747
+ if (dt(s3)) {
10790
10748
  const e15 = [...s3.urls];
10791
10749
  return this.chapterUrlsCache.set(t2, e15), e15;
10792
10750
  }
@@ -10814,7 +10772,7 @@ const wt = class n6 extends BasePlugin {
10814
10772
  async resolvePdfPayload(e14, t2) {
10815
10773
  const s2 = e14.source, r2 = this.config.chapterPdfLoader, a2 = ct(e14);
10816
10774
  if (a2) {
10817
- const s3 = pt(dt(e14), a2);
10775
+ const s3 = pt(lt(e14), a2);
10818
10776
  if (t2 < 0 || t2 >= s3) throw new Error(`Chapter "${e14.chapterId}" invalid segmentIndex ${t2} (expected 0..${s3 - 1})`);
10819
10777
  const r3 = await this.resolveChapterUrls(e14);
10820
10778
  if (r3.length !== s3) {
@@ -10825,7 +10783,7 @@ const wt = class n6 extends BasePlugin {
10825
10783
  }
10826
10784
  if (0 !== t2) throw new Error(`Chapter "${e14.chapterId}" is not segmented`);
10827
10785
  if (s2) {
10828
- if (lt(s2)) {
10786
+ if (dt(s2)) {
10829
10787
  const s3 = await this.resolveChapterUrls(e14);
10830
10788
  return this.openPayloadFromUrl(e14, t2, s3);
10831
10789
  }
@@ -10845,11 +10803,11 @@ const wt = class n6 extends BasePlugin {
10845
10803
  const r2 = e14.chapterId, a2 = (null == t2 ? void 0 : t2.index) ?? 0, o2 = (null == t2 ? void 0 : t2.documentId) ?? r2;
10846
10804
  this.chapterErrorMessages.delete(r2), this.anySegmentOpen(r2) || this.updateStatus(r2, "loading"), this.chapterLastUsed.set(r2, Date.now());
10847
10805
  try {
10848
- const n9 = e14.encrypted && (null == (s2 = this.passwordProvider) ? void 0 : s2.getCachedPassword) ? this.passwordProvider.getCachedPassword(r2) : null, i2 = await this.resolvePdfPayload(e14, a2), h2 = this.documentManager.provides(), d2 = "url" in i2 ? h2.openDocumentUrl({ documentId: o2, url: i2.url, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }) : h2.openDocumentBuffer({ documentId: o2, buffer: i2.buffer, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }), l = await new Promise((e15, t3) => {
10849
- d2.wait((t4) => e15(t4), (e16) => t3(e16));
10806
+ const n9 = e14.encrypted && (null == (s2 = this.passwordProvider) ? void 0 : s2.getCachedPassword) ? this.passwordProvider.getCachedPassword(r2) : null, i2 = await this.resolvePdfPayload(e14, a2), h2 = this.documentManager.provides(), l = "url" in i2 ? h2.openDocumentUrl({ documentId: o2, url: i2.url, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }) : h2.openDocumentBuffer({ documentId: o2, buffer: i2.buffer, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }), d2 = await new Promise((e15, t3) => {
10807
+ l.wait((t4) => e15(t4), (e16) => t3(e16));
10850
10808
  });
10851
10809
  return await new Promise((e15, t3) => {
10852
- l.task.wait(() => e15(), (e16) => t3(e16));
10810
+ d2.task.wait(() => e15(), (e16) => t3(e16));
10853
10811
  }), h2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(r2), this.waitForTerminalStatus(r2);
10854
10812
  } catch (i2) {
10855
10813
  const e15 = this.chapterStatus.get(r2);
@@ -10910,8 +10868,8 @@ const wt = class n6 extends BasePlugin {
10910
10868
  "error" === t2 && s2 ? this.chapterErrorMessages.set(e14, s2) : "loading" !== t2 && "loaded" !== t2 || this.chapterErrorMessages.delete(e14), n9 !== t2 && (this.chapterStatus.set(e14, t2), this.statusChange$.emit({ chapterId: e14, status: t2, ..."error" === t2 && s2 ? { error: { message: s2 } } : {} }));
10911
10869
  }
10912
10870
  };
10913
- wt.id = "chapter-manager";
10914
- let yt2 = wt;
10871
+ yt2.id = "chapter-manager";
10872
+ let wt = yt2;
10915
10873
  function Mt(e14) {
10916
10874
  return !!e14 && "urls" in e14 && Array.isArray(e14.urls);
10917
10875
  }
@@ -10951,12 +10909,12 @@ function Dt(e14) {
10951
10909
  function kt(e14) {
10952
10910
  return !!e14 && "urls" in e14 && Array.isArray(e14.urls);
10953
10911
  }
10954
- function Et(e14) {
10912
+ function Ut(e14) {
10955
10913
  if (null != e14.segmentPageThreshold && e14.segmentPageThreshold > 0) return e14.segmentPageThreshold;
10956
10914
  const t2 = e14.source;
10957
10915
  return kt(t2) ? t2.segmentPageThreshold : null;
10958
10916
  }
10959
- function Ut(e14, t2) {
10917
+ function Et(e14, t2) {
10960
10918
  return `${e14}#s${t2}`;
10961
10919
  }
10962
10920
  function Tt(e14) {
@@ -10968,19 +10926,19 @@ function Tt(e14) {
10968
10926
  function Ft(e14, t2) {
10969
10927
  return e14 <= 0 || t2 <= 0 ? 0 : Math.ceil(e14 / t2);
10970
10928
  }
10971
- function Ot(e14) {
10972
- const t2 = Et(e14);
10929
+ function Nt(e14) {
10930
+ const t2 = Ut(e14);
10973
10931
  if (!t2) return null;
10974
10932
  const s2 = Dt(e14), n9 = Ft(s2, t2), r2 = kt(e14.source) ? e14.source.urls : void 0, a2 = [];
10975
10933
  for (let o2 = 0; o2 < n9; o2++) {
10976
10934
  const n10 = o2 * t2, i2 = Math.min(n10 + t2 - 1, s2 - 1);
10977
10935
  if (n10 >= s2) break;
10978
- a2.push({ index: o2, url: (null == r2 ? void 0 : r2[o2]) ?? "", localPageStart: n10, localPageEnd: i2, documentId: Ut(e14.chapterId, o2) });
10936
+ a2.push({ index: o2, url: (null == r2 ? void 0 : r2[o2]) ?? "", localPageStart: n10, localPageEnd: i2, documentId: Et(e14.chapterId, o2) });
10979
10937
  }
10980
10938
  return { chapterId: e14.chapterId, threshold: t2, pageCount: s2, segments: a2 };
10981
10939
  }
10982
10940
  function At(e14, t2) {
10983
- const s2 = Ot(e14);
10941
+ const s2 = Nt(e14);
10984
10942
  if (!s2) return { documentId: e14.chapterId, pageIndex: t2 };
10985
10943
  const n9 = s2.segments.find((e15) => t2 >= e15.localPageStart && t2 <= e15.localPageEnd);
10986
10944
  if (!n9) {
@@ -10989,15 +10947,15 @@ function At(e14, t2) {
10989
10947
  }
10990
10948
  return { documentId: n9.documentId, pageIndex: t2 - n9.localPageStart };
10991
10949
  }
10992
- function Rt(e14, t2) {
10993
- const s2 = Ot(e14);
10950
+ function Vt(e14, t2) {
10951
+ const s2 = Nt(e14);
10994
10952
  if (!s2) return 0;
10995
10953
  const n9 = s2.segments.find((e15) => t2 >= e15.localPageStart && t2 <= e15.localPageEnd);
10996
10954
  return (null == n9 ? void 0 : n9.index) ?? Math.floor(t2 / s2.threshold);
10997
10955
  }
10998
- function Vt(e14) {
10956
+ function Ot(e14) {
10999
10957
  var t2;
11000
- const s2 = Et(e14);
10958
+ const s2 = Ut(e14);
11001
10959
  if (!s2) return [];
11002
10960
  const n9 = [], { chapterId: r2 } = e14, a2 = Dt(e14);
11003
10961
  s2 <= 0 && n9.push(`${r2}: segmentPageThreshold must be > 0`);
@@ -11009,7 +10967,7 @@ function Vt(e14) {
11009
10967
  for (let h2 = 0; h2 < o2.urls.length; h2++) (null == (t2 = o2.urls[h2]) ? void 0 : t2.trim()) || n9.push(`${r2}: source.urls[${h2}] is empty`);
11010
10968
  return n9;
11011
10969
  }
11012
- const Nt = { kind: "first-wins" };
10970
+ const Rt = { kind: "first-wins" };
11013
10971
  function Gt(e14, t2, s2) {
11014
10972
  if (1 === t2.length) return t2[0].chapterId;
11015
10973
  switch (s2.kind) {
@@ -11028,7 +10986,7 @@ function Gt(e14, t2, s2) {
11028
10986
  return s2.resolve(e14, t2);
11029
10987
  }
11030
10988
  }
11031
- class _t {
10989
+ class zt {
11032
10990
  constructor(e14) {
11033
10991
  this._pages = e14, this._byChapter = /* @__PURE__ */ new Map(), this._byGlobalNumber = /* @__PURE__ */ new Map();
11034
10992
  for (const t2 of e14) {
@@ -11062,8 +11020,8 @@ class _t {
11062
11020
  return s2 ? this._pages.indexOf(s2) : -1;
11063
11021
  }
11064
11022
  }
11065
- function zt(e14, t2 = Nt) {
11066
- const s2 = (function(e15, t3 = Nt) {
11023
+ function Bt(e14, t2 = Rt) {
11024
+ const s2 = (function(e15, t3 = Rt) {
11067
11025
  const s3 = /* @__PURE__ */ new Map();
11068
11026
  for (const r3 of e15.chapters) {
11069
11027
  const [e16, t4] = r3.globalPageRange;
@@ -11082,17 +11040,17 @@ function zt(e14, t2 = Nt) {
11082
11040
  for (const i2 of r2) {
11083
11041
  const e15 = s2.get(i2), t3 = n9.get(e15);
11084
11042
  if (!t3) continue;
11085
- const [r3] = t3.globalPageRange, [h2] = t3.localPageRange, d2 = h2 + (i2 - r3);
11086
- a2.push({ globalPageIndex: o2++, globalPageNumber: i2, chapterId: e15, localPageIndex: d2 });
11043
+ const [r3] = t3.globalPageRange, [h2] = t3.localPageRange, l = h2 + (i2 - r3);
11044
+ a2.push({ globalPageIndex: o2++, globalPageNumber: i2, chapterId: e15, localPageIndex: l });
11087
11045
  }
11088
- return new _t(a2);
11046
+ return new zt(a2);
11089
11047
  }
11090
- const Bt = class n7 extends BasePlugin {
11048
+ const _t = class n7 extends BasePlugin {
11091
11049
  constructor(e14, n9) {
11092
- super(e14, n9), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = Nt, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.SEG_PRIO_PREFETCH_NEXT = 120, this.SEG_PRIO_CHAPTER_PREFETCH_BASE = 3e3, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
11050
+ super(e14, n9), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = Rt, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterErrorMessages = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingChapterLoadPromises = /* @__PURE__ */ new Map(), this.pendingSegmentLoadPromises = /* @__PURE__ */ new Map(), this.chapterUrlsCache = /* @__PURE__ */ new Map(), this.pendingChapterUrlsPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0, this.lastVisibleIndicesKey = "", this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
11093
11051
  }
11094
11052
  async initialize(e14) {
11095
- if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? Nt, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
11053
+ if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? Rt, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
11096
11054
  const { chapterId: t2 } = Tt(e15.id);
11097
11055
  this.findChapter(t2) && (this.passwordAttempts.delete(t2), this.syncChapterStatusFromDocuments(t2));
11098
11056
  }), this.documentManager.provides().onDocumentClosed((e15) => {
@@ -11114,7 +11072,7 @@ const Bt = class n7 extends BasePlugin {
11114
11072
  return s2 ? At(s2, t2) : null;
11115
11073
  }, getSegmentPlan: (e14) => {
11116
11074
  const t2 = this.findChapter(e14);
11117
- return t2 ? Ot(t2) : null;
11075
+ return t2 ? Nt(t2) : null;
11118
11076
  }, isSegmentLoaded: (e14, t2) => this.isSegmentDocumentOpen(e14, t2), isSegmentLoadPending: (e14, t2) => this.isSegmentLoadPending(e14, t2), getChapterErrorMessage: (e14) => this.chapterErrorMessages.get(e14), getChapterStatus: (e14) => this.chapterStatus.get(e14) ?? "idle", getChapter: (e14) => this.findChapter(e14), onChapterStatusChange: this.statusChange$.on, onManifestChange: this.manifestChange$.on };
11119
11077
  }
11120
11078
  destroy() {
@@ -11146,7 +11104,7 @@ const Bt = class n7 extends BasePlugin {
11146
11104
  s3.has(n9.chapterId) && t3.push(`Duplicate chapterId: ${n9.chapterId}`), s3.add(n9.chapterId);
11147
11105
  const [e16, r3] = n9.globalPageRange, [a3, o2] = n9.localPageRange;
11148
11106
  if (e16 > r3 && t3.push(`${n9.chapterId}: invalid globalPageRange [${e16},${r3}]`), a3 > o2 && t3.push(`${n9.chapterId}: invalid localPageRange [${a3},${o2}]`), r3 - e16 !== o2 - a3 && t3.push(`${n9.chapterId}: page-count mismatch (global ${r3 - e16 + 1} vs local ${o2 - a3 + 1})`), n9.ownedGlobalPages) for (const s4 of n9.ownedGlobalPages) (s4 < e16 || s4 > r3) && t3.push(`${n9.chapterId}: ownedGlobalPages contains ${s4} outside range`);
11149
- t3.push(...Vt(n9));
11107
+ t3.push(...Ot(n9));
11150
11108
  }
11151
11109
  return t3;
11152
11110
  })(t2);
@@ -11154,7 +11112,7 @@ const Bt = class n7 extends BasePlugin {
11154
11112
  const r2 = new Set(this.chapterStatus.keys()), a2 = new Set(t2.chapters.map((e15) => e15.chapterId));
11155
11113
  for (const n9 of r2) a2.has(n9) || (this.closeChapter(n9), this.chapterStatus.delete(n9), this.chapterErrorMessages.delete(n9), this.chapterUrlsCache.delete(n9), this.pendingChapterUrlsPromises.delete(n9));
11156
11114
  for (const n9 of t2.chapters) this.chapterStatus.has(n9.chapterId) || this.chapterStatus.set(n9.chapterId, "idle");
11157
- this.manifest = t2, this.lastVisibleIndicesKey = "", this.clearVisibleSegmentBacklog(), this.virtualPageMap = zt(t2, this.overlapStrategy), this.manifestChange$.emit({ manifest: t2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
11115
+ this.manifest = t2, this.lastVisibleIndicesKey = "", this.clearVisibleSegmentBacklog(), this.virtualPageMap = Bt(t2, this.overlapStrategy), this.manifestChange$.emit({ manifest: t2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
11158
11116
  }
11159
11117
  eagerPrefetchFromManifest() {
11160
11118
  const e14 = this.config.prefetchChapters ?? 0;
@@ -11172,7 +11130,7 @@ const Bt = class n7 extends BasePlugin {
11172
11130
  }
11173
11131
  getSegmentPlanForChapter(e14) {
11174
11132
  const t2 = this.findChapter(e14);
11175
- return t2 ? Ot(t2) : null;
11133
+ return t2 ? Nt(t2) : null;
11176
11134
  }
11177
11135
  anySegmentOpen(e14) {
11178
11136
  const t2 = this.getSegmentPlanForChapter(e14), s2 = this.documentManager.provides();
@@ -11220,7 +11178,7 @@ const Bt = class n7 extends BasePlugin {
11220
11178
  if (!e15) continue;
11221
11179
  const s2 = this.findChapter(e15.chapterId);
11222
11180
  if (!s2) continue;
11223
- const n9 = Rt(s2, e15.localPageIndex);
11181
+ const n9 = Vt(s2, e15.localPageIndex);
11224
11182
  if (!this.isSegmentDocumentOpen(e15.chapterId, n9)) return true;
11225
11183
  }
11226
11184
  return false;
@@ -11231,13 +11189,22 @@ const Bt = class n7 extends BasePlugin {
11231
11189
  clearVisibleSegmentBacklog() {
11232
11190
  this.visibleSegmentBacklog = [], this.activeVisibleSegmentLoads = 0;
11233
11191
  }
11192
+ globalSegmentSortKey(e14, t2) {
11193
+ var s2;
11194
+ if (!this.virtualPageMap) return Number.MAX_SAFE_INTEGER;
11195
+ const n9 = this.findChapter(e14);
11196
+ if (!n9) return Number.MAX_SAFE_INTEGER;
11197
+ const r2 = Nt(n9), a2 = (null == (s2 = null == r2 ? void 0 : r2.segments[t2]) ? void 0 : s2.localPageStart) ?? 0, o2 = this.virtualPageMap.toGlobal(e14, a2);
11198
+ if (o2) return o2.globalPageIndex;
11199
+ return 1e4 * this.manifest.chapters.findIndex((t3) => t3.chapterId === e14) + t2;
11200
+ }
11234
11201
  scheduleVisibleSegmentLoads(e14) {
11235
- const t2 = /* @__PURE__ */ new Set(), s2 = [...e14].sort((e15, t3) => e15.priority - t3.priority);
11236
- for (const n9 of s2) {
11237
- const e15 = `${n9.chapterId}:${n9.segmentIndex}`;
11238
- t2.has(e15) || (t2.add(e15), this.isSegmentDocumentOpen(n9.chapterId, n9.segmentIndex) || this.isSegmentLoadPending(n9.chapterId, n9.segmentIndex) || this.visibleSegmentBacklog.push({ chapterId: n9.chapterId, segmentIndex: n9.segmentIndex }));
11202
+ const t2 = [...e14].sort((e15, t3) => e15.priority - t3.priority), s2 = /* @__PURE__ */ new Set(), n9 = [];
11203
+ for (const r2 of t2) {
11204
+ const e15 = `${r2.chapterId}:${r2.segmentIndex}`;
11205
+ s2.has(e15) || (s2.add(e15), this.isSegmentDocumentOpen(r2.chapterId, r2.segmentIndex) || this.isSegmentLoadPending(r2.chapterId, r2.segmentIndex) || n9.push({ chapterId: r2.chapterId, segmentIndex: r2.segmentIndex }));
11239
11206
  }
11240
- this.pumpVisibleSegmentBacklog();
11207
+ this.visibleSegmentBacklog = n9, this.pumpVisibleSegmentBacklog();
11241
11208
  }
11242
11209
  pumpVisibleSegmentBacklog() {
11243
11210
  const e14 = Math.max(1, this.config.maxConcurrentSegmentLoads ?? 2);
@@ -11256,53 +11223,41 @@ const Bt = class n7 extends BasePlugin {
11256
11223
  const t2 = e14.join(","), s2 = this.visibleRangeNeedsSegmentLoad(e14);
11257
11224
  if (t2 === this.lastVisibleIndicesKey && !s2) return;
11258
11225
  this.lastVisibleIndicesKey = t2;
11259
- const n9 = Date.now(), r2 = this.config.prefetchChapters ?? 1, a2 = e14[Math.floor(e14.length / 2)] ?? e14[0], o2 = /* @__PURE__ */ new Set(), i2 = /* @__PURE__ */ new Map(), h2 = (e15, t3, s3) => {
11226
+ const n9 = Date.now(), r2 = e14[Math.floor(e14.length / 2)] ?? e14[0], a2 = /* @__PURE__ */ new Set(), o2 = /* @__PURE__ */ new Map(), i2 = (e15, t3) => {
11260
11227
  if (t3 < 0) return;
11261
- const n10 = this.findChapter(e15);
11262
- if (!n10) return;
11263
- const r3 = Ot(n10);
11264
- if (r3 && t3 >= r3.segments.length) return;
11265
- const a3 = `${e15}:${t3}`, o3 = i2.get(a3);
11266
- (void 0 === o3 || s3 < o3) && i2.set(a3, s3);
11228
+ const s3 = this.findChapter(e15);
11229
+ if (!s3) return;
11230
+ const n10 = Nt(s3);
11231
+ if (n10 && t3 >= n10.segments.length) return;
11232
+ const r3 = `${e15}:${t3}`, a3 = this.globalSegmentSortKey(e15, t3), i3 = o2.get(r3);
11233
+ (void 0 === i3 || a3 < i3) && o2.set(r3, a3);
11267
11234
  };
11268
- for (const g2 of e14) {
11269
- const e15 = this.virtualPageMap.atIndex(g2);
11235
+ for (const d2 of e14) {
11236
+ const e15 = this.virtualPageMap.atIndex(d2);
11270
11237
  if (!e15) continue;
11271
- o2.add(e15.chapterId);
11238
+ a2.add(e15.chapterId);
11272
11239
  const t3 = this.findChapter(e15.chapterId);
11273
11240
  if (!t3) continue;
11274
- const s3 = Math.abs(g2 - a2), n10 = Rt(t3, e15.localPageIndex);
11275
- h2(e15.chapterId, n10, s3), h2(e15.chapterId, n10 + 1, s3 + this.SEG_PRIO_PREFETCH_NEXT), this.resolveChapterUrls(t3).catch(() => {
11241
+ const s3 = Vt(t3, e15.localPageIndex);
11242
+ i2(e15.chapterId, s3), this.resolveChapterUrls(t3).catch(() => {
11276
11243
  });
11277
11244
  }
11278
- if (0 === o2.size) return;
11279
- const d2 = this.manifest.chapters.map((e15) => e15.chapterId);
11280
- let l = 0;
11281
- const c2 = this.virtualPageMap.atIndex(a2);
11282
- if (c2) {
11283
- const e15 = d2.indexOf(c2.chapterId);
11284
- e15 >= 0 && (l = e15);
11285
- }
11286
- for (const g2 of o2) {
11287
- this.chapterLastUsed.set(g2, n9);
11288
- const e15 = d2.indexOf(g2);
11289
- if (-1 !== e15) for (let t3 = e15 - r2; t3 <= e15 + r2; t3++) {
11290
- if (t3 < 0 || t3 >= d2.length) continue;
11291
- const e16 = d2[t3];
11292
- this.chapterLastUsed.set(e16, n9);
11293
- const s3 = Math.abs(t3 - l);
11294
- h2(e16, 0, this.SEG_PRIO_CHAPTER_PREFETCH_BASE + 100 * s3);
11295
- const r3 = this.findChapter(e16);
11296
- r3 && this.resolveChapterUrls(r3).catch(() => {
11297
- });
11245
+ if (0 === a2.size) return;
11246
+ const h2 = this.virtualPageMap.atIndex(r2);
11247
+ if (h2) {
11248
+ const e15 = this.findChapter(h2.chapterId);
11249
+ if (e15) {
11250
+ const t3 = Vt(e15, h2.localPageIndex);
11251
+ i2(h2.chapterId, t3 + 1);
11298
11252
  }
11299
11253
  }
11300
- const u2 = [...i2.entries()].map(([e15, t3]) => {
11254
+ for (const d2 of a2) this.chapterLastUsed.set(d2, n9);
11255
+ const l = [...o2.entries()].map(([e15, t3]) => {
11301
11256
  const [s3, n10] = e15.split(":");
11302
11257
  return { chapterId: s3, segmentIndex: Number.parseInt(n10, 10), priority: t3 };
11303
11258
  }).filter((e15) => e15.chapterId && Number.isFinite(e15.segmentIndex));
11304
- if (this.scheduleVisibleSegmentLoads(u2), this.config.autoActivateOnLoad ?? 1) {
11305
- const e15 = this.virtualPageMap.atIndex(a2);
11259
+ if (this.scheduleVisibleSegmentLoads(l), this.config.autoActivateOnLoad ?? 1) {
11260
+ const e15 = this.virtualPageMap.atIndex(r2);
11306
11261
  if (e15) {
11307
11262
  const t3 = At(this.findChapter(e15.chapterId), e15.localPageIndex);
11308
11263
  if (this.documentManager.provides().isDocumentOpen(t3.documentId)) {
@@ -11340,7 +11295,7 @@ const Bt = class n7 extends BasePlugin {
11340
11295
  this.prepareChapterForSegmentLoad(e14);
11341
11296
  const s2 = this.findChapter(e14);
11342
11297
  if (!s2) return Promise.resolve("error");
11343
- const n9 = Ot(s2);
11298
+ const n9 = Nt(s2);
11344
11299
  if (!n9) return 0 !== t2 ? Promise.resolve(this.isSegmentDocumentOpen(e14, 0) ? "loaded" : "error") : this.ensureSingleDocumentChapter(s2);
11345
11300
  if (t2 < 0 || t2 >= n9.segments.length) return Promise.resolve("error");
11346
11301
  const r2 = n9.segments[t2], a2 = r2.documentId;
@@ -11396,7 +11351,7 @@ const Bt = class n7 extends BasePlugin {
11396
11351
  return (null == r2 ? void 0 : r2.openPdf) ? r2.openPdf(a2) : { url: n9 };
11397
11352
  }
11398
11353
  async resolvePdfPayload(e14, t2) {
11399
- const s2 = e14.source, r2 = this.config.chapterPdfLoader, a2 = Et(e14);
11354
+ const s2 = e14.source, r2 = this.config.chapterPdfLoader, a2 = Ut(e14);
11400
11355
  if (a2) {
11401
11356
  const s3 = Ft(Dt(e14), a2);
11402
11357
  if (t2 < 0 || t2 >= s3) throw new Error(`Chapter "${e14.chapterId}" invalid segmentIndex ${t2} (expected 0..${s3 - 1})`);
@@ -11429,11 +11384,11 @@ const Bt = class n7 extends BasePlugin {
11429
11384
  const r2 = e14.chapterId, a2 = (null == t2 ? void 0 : t2.index) ?? 0, o2 = (null == t2 ? void 0 : t2.documentId) ?? r2;
11430
11385
  this.chapterErrorMessages.delete(r2), this.anySegmentOpen(r2) || this.updateStatus(r2, "loading"), this.chapterLastUsed.set(r2, Date.now());
11431
11386
  try {
11432
- const n9 = e14.encrypted && (null == (s2 = this.passwordProvider) ? void 0 : s2.getCachedPassword) ? this.passwordProvider.getCachedPassword(r2) : null, i2 = await this.resolvePdfPayload(e14, a2), h2 = this.documentManager.provides(), d2 = "url" in i2 ? h2.openDocumentUrl({ documentId: o2, url: i2.url, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }) : h2.openDocumentBuffer({ documentId: o2, buffer: i2.buffer, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }), l = await new Promise((e15, t3) => {
11433
- d2.wait((t4) => e15(t4), (e16) => t3(e16));
11387
+ const n9 = e14.encrypted && (null == (s2 = this.passwordProvider) ? void 0 : s2.getCachedPassword) ? this.passwordProvider.getCachedPassword(r2) : null, i2 = await this.resolvePdfPayload(e14, a2), h2 = this.documentManager.provides(), l = "url" in i2 ? h2.openDocumentUrl({ documentId: o2, url: i2.url, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }) : h2.openDocumentBuffer({ documentId: o2, buffer: i2.buffer, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }), d2 = await new Promise((e15, t3) => {
11388
+ l.wait((t4) => e15(t4), (e16) => t3(e16));
11434
11389
  });
11435
11390
  return await new Promise((e15, t3) => {
11436
- l.task.wait(() => e15(), (e16) => t3(e16));
11391
+ d2.task.wait(() => e15(), (e16) => t3(e16));
11437
11392
  }), h2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(r2), this.waitForTerminalStatus(r2);
11438
11393
  } catch (i2) {
11439
11394
  const e15 = this.chapterStatus.get(r2);
@@ -11478,7 +11433,7 @@ const Bt = class n7 extends BasePlugin {
11478
11433
  });
11479
11434
  }
11480
11435
  closeChapter(e14) {
11481
- const t2 = this.findChapter(e14), s2 = this.documentManager.provides(), n9 = t2 ? Ot(t2) : null, r2 = (e15) => {
11436
+ const t2 = this.findChapter(e14), s2 = this.documentManager.provides(), n9 = t2 ? Nt(t2) : null, r2 = (e15) => {
11482
11437
  if (s2.isDocumentOpen(e15)) {
11483
11438
  s2.closeDocument(e15).wait(() => {
11484
11439
  }, () => {
@@ -11494,9 +11449,9 @@ const Bt = class n7 extends BasePlugin {
11494
11449
  "error" === t2 && s2 ? this.chapterErrorMessages.set(e14, s2) : "loading" !== t2 && "loaded" !== t2 || this.chapterErrorMessages.delete(e14), n9 !== t2 && (this.chapterStatus.set(e14, t2), this.statusChange$.emit({ chapterId: e14, status: t2, ..."error" === t2 && s2 ? { error: { message: s2 } } : {} }));
11495
11450
  }
11496
11451
  };
11497
- Bt.id = "chapter-manager";
11498
- let Ht = Bt;
11499
- function qt(e14, t2) {
11452
+ _t.id = "chapter-manager";
11453
+ let qt2 = _t;
11454
+ function Wt(e14, t2) {
11500
11455
  if (e14 === t2) return true;
11501
11456
  if (e14.totalHeight !== t2.totalHeight || e14.totalWidth !== t2.totalWidth || e14.pageGap !== t2.pageGap || e14.items.length !== t2.items.length) return false;
11502
11457
  for (let s2 = 0; s2 < e14.items.length; s2++) {
@@ -11505,9 +11460,9 @@ function qt(e14, t2) {
11505
11460
  }
11506
11461
  return true;
11507
11462
  }
11508
- const Wt2 = class extends BasePlugin {
11463
+ const Kt = class extends BasePlugin {
11509
11464
  constructor(e14, s2) {
11510
- super(e14, s2), this.layoutChange$ = createBehaviorEmitter(void 0, qt), this.visibleChange$ = createBehaviorEmitter(), this.virtualPageMap = null, this.pageSizes = /* @__PURE__ */ new Map(), this.offsets = [], this.totalHeight = 0, this.totalWidth = 0, this.viewportEl = null, this.viewportObservers = null, this.currentVisible = [], this.currentGlobalPageIndex = 0, this.lastLoadIndicesKey = "", this.loadPushRaf = null, this.chapterManagerUnsubs = [], this.chapterManager = this.registry.getPlugin(Ht.id), this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
11465
+ super(e14, s2), this.layoutChange$ = createBehaviorEmitter(void 0, Wt), this.visibleChange$ = createBehaviorEmitter(), this.virtualPageMap = null, this.pageSizes = /* @__PURE__ */ new Map(), this.offsets = [], this.totalHeight = 0, this.totalWidth = 0, this.viewportEl = null, this.viewportObservers = null, this.currentVisible = [], this.currentGlobalPageIndex = 0, this.lastLoadIndicesKey = "", this.loadPushRaf = null, this.chapterManagerUnsubs = [], this.chapterManager = this.registry.getPlugin(qt2.id), this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
11511
11466
  }
11512
11467
  async initialize(e14) {
11513
11468
  this.config = { placeholderPageHeight: e14.placeholderPageHeight ?? 1200, placeholderPageWidth: e14.placeholderPageWidth ?? 900, bufferSize: e14.bufferSize ?? 2, pageGap: e14.pageGap ?? 20 }, this.virtualPageMap = this.chapterManager.provides().getVirtualPageMap(), this.rebuildOffsets(), this.chapterManagerUnsubs.push(this.chapterManager.provides().onManifestChange(({ map: e15 }) => {
@@ -11623,10 +11578,10 @@ const Wt2 = class extends BasePlugin {
11623
11578
  }
11624
11579
  return i2.length > 0;
11625
11580
  };
11626
- if (a2) for (const d2 of a2.segments) {
11627
- if (!s2.isSegmentLoaded(e14, d2.index)) continue;
11628
- const t3 = d2.localPageEnd - d2.localPageStart + 1;
11629
- h2(d2.documentId, d2.localPageStart, 0, t3);
11581
+ if (a2) for (const l of a2.segments) {
11582
+ if (!s2.isSegmentLoaded(e14, l.index)) continue;
11583
+ const t3 = l.localPageEnd - l.localPageStart + 1;
11584
+ h2(l.documentId, l.localPageStart, 0, t3);
11630
11585
  }
11631
11586
  else s2.isSegmentLoaded(e14, 0) && h2(e14, 0, 0, r2.length);
11632
11587
  0 !== i2.length ? this.applyChapterPageSizes(e14, i2) : t2 < 60 && requestAnimationFrame(() => this.harvestChapterSizes(e14, t2 + 1));
@@ -11711,8 +11666,8 @@ const Wt2 = class extends BasePlugin {
11711
11666
  if (!a2) return void this.scrollToIndex(e14, s2);
11712
11667
  const o2 = this.pageSizes.get(e14), i2 = this.chapterManager.provides().resolvePageDocument(a2.chapterId, a2.localPageIndex), h2 = i2 ? null == (n9 = this.documentManager.provides().getDocument(i2.documentId)) ? void 0 : n9.pages[i2.pageIndex] : void 0;
11713
11668
  if (!o2 || !h2) return void this.scrollToIndex(e14, s2);
11714
- const d2 = o2.height / h2.size.height, l = (this.offsets[e14] ?? 0) + t2 * d2 - r2;
11715
- this.viewportEl.scrollTo({ top: Math.max(0, l), behavior: (null == s2 ? void 0 : s2.behavior) ?? "auto" });
11669
+ const l = o2.height / h2.size.height, d2 = (this.offsets[e14] ?? 0) + t2 * l - r2;
11670
+ this.viewportEl.scrollTo({ top: Math.max(0, d2), behavior: (null == s2 ? void 0 : s2.behavior) ?? "auto" });
11716
11671
  }
11717
11672
  scrollToChapter(e14, t2) {
11718
11673
  if (!this.virtualPageMap) return;
@@ -11725,8 +11680,8 @@ const Wt2 = class extends BasePlugin {
11725
11680
  s2 && this.scrollToIndex(s2.globalPageIndex, t2);
11726
11681
  }
11727
11682
  };
11728
- Wt2.id = "chapter-scroll";
11729
- let Kt = Wt2;
11683
+ Kt.id = "chapter-scroll";
11684
+ let Ht = Kt;
11730
11685
  function jt(e14) {
11731
11686
  const t2 = e14[e14.length - 1];
11732
11687
  return { x: t2.origin.x + t2.size.width, y: t2.origin.y + t2.size.height };
@@ -11763,7 +11718,7 @@ async function Qt(e14, t2, s2) {
11763
11718
  }
11764
11719
  const Yt = class s extends BasePlugin {
11765
11720
  constructor(e14, s2) {
11766
- super(e14, s2), this.change$ = createBehaviorEmitter([]), this.entries = /* @__PURE__ */ new Map(), this.chapterScroll = this.registry.getPlugin(Kt.id), this.chapterManager = this.registry.getPlugin(yt2.id), this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
11721
+ super(e14, s2), this.change$ = createBehaviorEmitter([]), this.entries = /* @__PURE__ */ new Map(), this.chapterScroll = this.registry.getPlugin(Ht.id), this.chapterManager = this.registry.getPlugin(wt.id), this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
11767
11722
  }
11768
11723
  async initialize(e14) {
11769
11724
  var t2;
@@ -11844,13 +11799,13 @@ function hs(e14, t2) {
11844
11799
  const s2 = e14;
11845
11800
  return false === e14 ? { ...t2, enabled: false } : true === e14 || void 0 === e14 ? { ...t2, enabled: t2.enabled ?? true } : { ...t2, ...s2, enabled: false !== (null == s2 ? void 0 : s2.enabled) };
11846
11801
  }
11847
- function ds(e14) {
11802
+ function ls(e14) {
11848
11803
  var t2;
11849
11804
  const s2 = hs(void 0, { enabled: true }), n9 = hs(void 0, { enabled: true }), r2 = hs(void 0, { enabled: true }), a2 = hs(void 0, { enabled: true, min: 0.5, max: 3, initial: 1 }), o2 = hs(false !== s2.enabled || false !== r2.enabled, { enabled: true });
11850
11805
  return { markup: s2, bookmarks: n9, notes: r2, zoom: a2, scrollViewport: { background: (null == (t2 = void 0) ? void 0 : t2.background) ?? "#f1f5f9" }, selectionToolbar: o2 };
11851
11806
  }
11852
11807
  PdfAnnotationSubtype.HIGHLIGHT, PdfAnnotationSubtype.UNDERLINE, PdfAnnotationSubtype.SQUIGGLY, PdfAnnotationSubtype.STRIKEOUT, PdfAnnotationSubtype.HIGHLIGHT, PdfAnnotationSubtype.UNDERLINE, PdfAnnotationSubtype.SQUIGGLY, PdfAnnotationSubtype.STRIKEOUT;
11853
- ds();
11808
+ ls();
11854
11809
  function gs(e14) {
11855
11810
  return !!e14 && "urls" in e14 && Array.isArray(e14.urls);
11856
11811
  }
@@ -11927,17 +11882,17 @@ function ks(e14) {
11927
11882
  return { annotation: e15.annotation, ctx: { data: t2, ...e15.ctx.mimeType ? { mimeType: e15.ctx.mimeType } : {} } };
11928
11883
  });
11929
11884
  }
11930
- function Es(e14) {
11885
+ function Us(e14) {
11931
11886
  return { bookmarks: false !== (e14 == null ? void 0 : e14.bookmarks), notes: false !== (e14 == null ? void 0 : e14.notes), markup: false !== (e14 == null ? void 0 : e14.markup) };
11932
11887
  }
11933
- function Us(e14) {
11888
+ function Es(e14) {
11934
11889
  return new Promise((t2, s2) => {
11935
11890
  e14.wait((e15) => t2(e15), (e15) => s2(e15));
11936
11891
  });
11937
11892
  }
11938
11893
  function Ts(e14) {
11939
11894
  var _a2, _b, _c, _d;
11940
- const t2 = (_a2 = e14.getPlugin(AnnotationPlugin.id)) == null ? void 0 : _a2.provides(), s2 = (_b = e14.getPlugin(rt.id)) == null ? void 0 : _b.provides(), n9 = (_c = e14.getPlugin(Zt.id)) == null ? void 0 : _c.provides(), r2 = (_d = e14.getPlugin(z.id)) == null ? void 0 : _d.provides();
11895
+ const t2 = (_a2 = e14.getPlugin(AnnotationPlugin.id)) == null ? void 0 : _a2.provides(), s2 = (_b = e14.getPlugin(rt.id)) == null ? void 0 : _b.provides(), n9 = (_c = e14.getPlugin(Zt.id)) == null ? void 0 : _c.provides(), r2 = (_d = e14.getPlugin(B.id)) == null ? void 0 : _d.provides();
11941
11896
  return { annotation: t2, note: s2, bookmark: n9, chapterManager: r2 };
11942
11897
  }
11943
11898
  async function Fs(e14, t2, s2) {
@@ -11945,8 +11900,8 @@ async function Fs(e14, t2, s2) {
11945
11900
  const n9 = e14.getSegmentPlan(t2) ? await e14.ensureAllSegmentsLoaded(t2) : await e14.ensureChapterLoaded(t2);
11946
11901
  if ("loaded" !== n9) throw new Error(`章节 ${t2} 未加载成功(${n9}),无法导入/导出划线`);
11947
11902
  }
11948
- async function Os(e14, t2, s2) {
11949
- const n9 = Es(s2), { annotation: r2, note: a2, bookmark: o2, chapterManager: i2 } = Ts(e14), h2 = { chapterId: t2 };
11903
+ async function Ns(e14, t2, s2) {
11904
+ const n9 = Us(s2), { annotation: r2, note: a2, bookmark: o2, chapterManager: i2 } = Ts(e14), h2 = { chapterId: t2 };
11950
11905
  if (n9.bookmarks) {
11951
11906
  if (!o2) throw new Error("paragraph-bookmark 插件未注册");
11952
11907
  h2.bookmarks = o2.listBookmarksForChapter(t2);
@@ -11960,11 +11915,11 @@ async function Os(e14, t2, s2) {
11960
11915
  await Fs(i2, t2, false !== (s2 == null ? void 0 : s2.ensureChapterLoaded));
11961
11916
  const e15 = await (async function(e16, t3, s3) {
11962
11917
  const n10 = t3.getSegmentPlan(s3);
11963
- if (!n10) return Us(e16.forDocument(s3).exportAnnotations());
11918
+ if (!n10) return Es(e16.forDocument(s3).exportAnnotations());
11964
11919
  const r3 = [];
11965
11920
  for (const a3 of n10.segments) {
11966
11921
  if (!t3.isSegmentLoaded(s3, a3.index)) continue;
11967
- const n11 = await Us(e16.forDocument(a3.documentId).exportAnnotations());
11922
+ const n11 = await Es(e16.forDocument(a3.documentId).exportAnnotations());
11968
11923
  for (const e17 of n11) {
11969
11924
  const t4 = e17.annotation.pageIndex;
11970
11925
  r3.push({ ...e17, annotation: { ...e17.annotation, pageIndex: t4 + a3.localPageStart } });
@@ -11976,29 +11931,29 @@ async function Os(e14, t2, s2) {
11976
11931
  }
11977
11932
  return h2;
11978
11933
  }
11979
- async function As(e14, t2, s2) {
11934
+ async function As2(e14, t2, s2) {
11980
11935
  const n9 = {};
11981
11936
  for (const r2 of t2.chapters) {
11982
- const t3 = await Os(e14, r2.chapterId, s2), { chapterId: a2, ...o2 } = t3;
11937
+ const t3 = await Ns(e14, r2.chapterId, s2), { chapterId: a2, ...o2 } = t3;
11983
11938
  n9[r2.chapterId] = o2;
11984
11939
  }
11985
11940
  return { version: 1, exportedAt: /* @__PURE__ */ (/* @__PURE__ */ new Date()).toISOString(), chapters: n9 };
11986
11941
  }
11987
- async function Rs2(e14, t2, s2) {
11988
- const n9 = Es(s2), r2 = (s2 == null ? void 0 : s2.mode) ?? "replace", { annotation: a2, note: o2, bookmark: i2, chapterManager: h2 } = Ts(e14), d2 = t2.chapterId;
11942
+ async function Vs(e14, t2, s2) {
11943
+ const n9 = Us(s2), r2 = (s2 == null ? void 0 : s2.mode) ?? "replace", { annotation: a2, note: o2, bookmark: i2, chapterManager: h2 } = Ts(e14), l = t2.chapterId;
11989
11944
  if (n9.bookmarks && t2.bookmarks) {
11990
11945
  if (!i2) throw new Error("paragraph-bookmark 插件未注册");
11991
- if ("replace" === r2) i2.replaceBookmarksForChapter(d2, t2.bookmarks);
11946
+ if ("replace" === r2) i2.replaceBookmarksForChapter(l, t2.bookmarks);
11992
11947
  else for (const e15 of t2.bookmarks) i2.addBookmark(e15);
11993
11948
  }
11994
11949
  if (n9.notes && t2.notes) {
11995
11950
  if (!o2) throw new Error("note 插件未注册");
11996
- if ("replace" === r2) o2.replaceNotesForChapter(d2, t2.notes);
11951
+ if ("replace" === r2) o2.replaceNotesForChapter(l, t2.notes);
11997
11952
  else for (const e15 of t2.notes) o2.registerNote(e15);
11998
11953
  }
11999
11954
  if (n9.markup && t2.markup) {
12000
11955
  if (!a2) throw new Error("annotation 插件未注册");
12001
- await Fs(h2, d2, false !== (s2 == null ? void 0 : s2.ensureChapterLoaded));
11956
+ await Fs(h2, l, false !== (s2 == null ? void 0 : s2.ensureChapterLoaded));
12002
11957
  !(function(e15, t3, s3, n10, r3) {
12003
11958
  const a3 = t3.getSegmentPlan(s3);
12004
11959
  if (!a3) {
@@ -12018,15 +11973,15 @@ async function Rs2(e14, t2, s2) {
12018
11973
  const t4 = e15.forDocument(h3.documentId), s4 = i3.get(h3.index) ?? [];
12019
11974
  "replace" === r3 && t4.deleteAllAnnotations(), s4.length > 0 && t4.importAnnotations(s4);
12020
11975
  }
12021
- })(a2, h2, d2, ks(t2.markup), r2);
11976
+ })(a2, h2, l, ks(t2.markup), r2);
12022
11977
  }
12023
11978
  (s2 == null ? void 0 : s2.persistNotes) && o2 && await s2.persistNotes(o2.listAllNotes()), (s2 == null ? void 0 : s2.persistBookmarks) && i2 && await s2.persistBookmarks(i2.listBookmarks());
12024
11979
  }
12025
- async function Vs(e14, t2, s2) {
11980
+ async function Os(e14, t2, s2) {
12026
11981
  if (1 !== t2.version) throw new Error(`不支持的归档版本 ${t2.version},当前为 1`);
12027
- for (const [n9, r2] of Object.entries(t2.chapters)) await Rs2(e14, { chapterId: n9, ...r2 }, s2);
11982
+ for (const [n9, r2] of Object.entries(t2.chapters)) await Vs(e14, { chapterId: n9, ...r2 }, s2);
12028
11983
  }
12029
- function Ns(e14) {
11984
+ function Rs(e14) {
12030
11985
  return JSON.stringify(e14, null, 2);
12031
11986
  }
12032
11987
  function Gs(e14) {
@@ -12034,23 +11989,23 @@ function Gs(e14) {
12034
11989
  if (!t2 || "object" != typeof t2 || !t2.chapters) throw new Error("无效的章节标注 JSON");
12035
11990
  return t2;
12036
11991
  }
12037
- function _s(e14) {
11992
+ function zs(e14) {
12038
11993
  return JSON.stringify(e14, null, 2);
12039
11994
  }
12040
- function zs(e14) {
11995
+ function Bs(e14) {
12041
11996
  const t2 = JSON.parse(e14);
12042
11997
  if (!(t2 == null ? void 0 : t2.chapterId)) throw new Error("无效的章节标注 JSON:缺少 chapterId");
12043
11998
  return t2;
12044
11999
  }
12045
- function Bs(e14, t2) {
12000
+ function _s(e14, t2) {
12046
12001
  const s2 = new Blob([t2], { type: "application/json;charset=utf-8" }), n9 = URL.createObjectURL(s2), r2 = document.createElement("a");
12047
12002
  r2.href = n9, r2.download = e14, r2.click(), URL.revokeObjectURL(n9);
12048
12003
  }
12049
- function Hs(e14, t2 = "chapter-annotations.json") {
12050
- Bs(t2, Ns(e14));
12004
+ function qs(e14, t2 = "chapter-annotations.json") {
12005
+ _s(t2, Rs(e14));
12051
12006
  }
12052
- function qs(e14, t2) {
12053
- Bs(t2 ?? `chapter-annotations-${e14.chapterId}.json`, _s(e14));
12007
+ function Ws(e14, t2) {
12008
+ _s(t2 ?? `chapter-annotations-${e14.chapterId}.json`, zs(e14));
12054
12009
  }
12055
12010
  const DEFAULT_CHAPTER_TEXT_SELECTION_BACKGROUND = "rgba(33, 150, 243)";
12056
12011
  ({
@@ -12256,8 +12211,6 @@ const _ChapterManagerPlugin = class _ChapterManagerPlugin2 extends BasePlugin {
12256
12211
  this.documentManagerUnsubs = [];
12257
12212
  this.visibleSegmentBacklog = [];
12258
12213
  this.activeVisibleSegmentLoads = 0;
12259
- this.SEG_PRIO_PREFETCH_NEXT = 120;
12260
- this.SEG_PRIO_CHAPTER_PREFETCH_BASE = 3e3;
12261
12214
  this.lastVisibleIndicesKey = "";
12262
12215
  this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
12263
12216
  }
@@ -12487,21 +12440,33 @@ const _ChapterManagerPlugin = class _ChapterManagerPlugin2 extends BasePlugin {
12487
12440
  this.visibleSegmentBacklog = [];
12488
12441
  this.activeVisibleSegmentLoads = 0;
12489
12442
  }
12490
- /** 按优先级排队并立即 pump,确保在 loadChapterUrls 缓存后会 open PDF */
12443
+ /** 分段在整本中的阅读顺序(globalPageIndex 升序 按章按段依次 open PDF */
12444
+ globalSegmentSortKey(chapterId, segmentIndex) {
12445
+ var _a2;
12446
+ if (!this.virtualPageMap) return Number.MAX_SAFE_INTEGER;
12447
+ const chapter = this.findChapter(chapterId);
12448
+ if (!chapter) return Number.MAX_SAFE_INTEGER;
12449
+ const plan = u(chapter);
12450
+ const localStart = ((_a2 = plan == null ? void 0 : plan.segments[segmentIndex]) == null ? void 0 : _a2.localPageStart) ?? 0;
12451
+ const loc = this.virtualPageMap.toGlobal(chapterId, localStart);
12452
+ if (loc) return loc.globalPageIndex;
12453
+ const chIdx = this.manifest.chapters.findIndex((c2) => c2.chapterId === chapterId);
12454
+ return chIdx * 1e4 + segmentIndex;
12455
+ }
12456
+ /** 按阅读顺序重建队列并立即 pump(替换旧 backlog,避免末尾多章同时 loading) */
12491
12457
  scheduleVisibleSegmentLoads(ranked) {
12492
- const seen = /* @__PURE__ */ new Set();
12493
12458
  const sorted = [...ranked].sort((a2, b2) => a2.priority - b2.priority);
12459
+ const seen = /* @__PURE__ */ new Set();
12460
+ const nextBacklog = [];
12494
12461
  for (const t2 of sorted) {
12495
12462
  const k2 = `${t2.chapterId}:${t2.segmentIndex}`;
12496
12463
  if (seen.has(k2)) continue;
12497
12464
  seen.add(k2);
12498
12465
  if (this.isSegmentDocumentOpen(t2.chapterId, t2.segmentIndex)) continue;
12499
12466
  if (this.isSegmentLoadPending(t2.chapterId, t2.segmentIndex)) continue;
12500
- this.visibleSegmentBacklog.push({
12501
- chapterId: t2.chapterId,
12502
- segmentIndex: t2.segmentIndex
12503
- });
12467
+ nextBacklog.push({ chapterId: t2.chapterId, segmentIndex: t2.segmentIndex });
12504
12468
  }
12469
+ this.visibleSegmentBacklog = nextBacklog;
12505
12470
  this.pumpVisibleSegmentBacklog();
12506
12471
  }
12507
12472
  pumpVisibleSegmentBacklog() {
@@ -12532,17 +12497,17 @@ const _ChapterManagerPlugin = class _ChapterManagerPlugin2 extends BasePlugin {
12532
12497
  if (key === this.lastVisibleIndicesKey && !needsLoad) return;
12533
12498
  this.lastVisibleIndicesKey = key;
12534
12499
  const now = Date.now();
12535
- const prefetch = this.config.prefetchChapters ?? 1;
12536
12500
  const focalIdx = visibleGlobalPageIndices[Math.floor(visibleGlobalPageIndices.length / 2)] ?? visibleGlobalPageIndices[0];
12537
12501
  const visibleChapters = /* @__PURE__ */ new Set();
12538
12502
  const segmentPriorities = /* @__PURE__ */ new Map();
12539
- const setSegPriority = (chapterId, segmentIndex, priority) => {
12503
+ const setSegPriority = (chapterId, segmentIndex) => {
12540
12504
  if (segmentIndex < 0) return;
12541
12505
  const chapter = this.findChapter(chapterId);
12542
12506
  if (!chapter) return;
12543
12507
  const plan = u(chapter);
12544
12508
  if (plan && segmentIndex >= plan.segments.length) return;
12545
12509
  const segKey = `${chapterId}:${segmentIndex}`;
12510
+ const priority = this.globalSegmentSortKey(chapterId, segmentIndex);
12546
12511
  const prev = segmentPriorities.get(segKey);
12547
12512
  if (prev === void 0 || priority < prev) segmentPriorities.set(segKey, priority);
12548
12513
  };
@@ -12552,39 +12517,22 @@ const _ChapterManagerPlugin = class _ChapterManagerPlugin2 extends BasePlugin {
12552
12517
  visibleChapters.add(loc.chapterId);
12553
12518
  const chapter = this.findChapter(loc.chapterId);
12554
12519
  if (!chapter) continue;
12555
- const dist = Math.abs(idx - focalIdx);
12556
12520
  const seg = i(chapter, loc.localPageIndex);
12557
- setSegPriority(loc.chapterId, seg, dist);
12558
- setSegPriority(loc.chapterId, seg + 1, dist + this.SEG_PRIO_PREFETCH_NEXT);
12521
+ setSegPriority(loc.chapterId, seg);
12559
12522
  void this.resolveChapterUrls(chapter).catch(() => {
12560
12523
  });
12561
12524
  }
12562
12525
  if (visibleChapters.size === 0) return;
12563
- const orderedIds = this.manifest.chapters.map((c2) => c2.chapterId);
12564
- let focalChapterIdx = 0;
12565
12526
  const focalLoc = this.virtualPageMap.atIndex(focalIdx);
12566
12527
  if (focalLoc) {
12567
- const i2 = orderedIds.indexOf(focalLoc.chapterId);
12568
- if (i2 >= 0) focalChapterIdx = i2;
12528
+ const focalChapter = this.findChapter(focalLoc.chapterId);
12529
+ if (focalChapter) {
12530
+ const focalSeg = i(focalChapter, focalLoc.localPageIndex);
12531
+ setSegPriority(focalLoc.chapterId, focalSeg + 1);
12532
+ }
12569
12533
  }
12570
12534
  for (const cid of visibleChapters) {
12571
12535
  this.chapterLastUsed.set(cid, now);
12572
- const i2 = orderedIds.indexOf(cid);
12573
- if (i2 === -1) continue;
12574
- for (let k2 = i2 - prefetch; k2 <= i2 + prefetch; k2++) {
12575
- if (k2 < 0 || k2 >= orderedIds.length) continue;
12576
- const prefetchCid = orderedIds[k2];
12577
- this.chapterLastUsed.set(prefetchCid, now);
12578
- const chapterDist = Math.abs(k2 - focalChapterIdx);
12579
- setSegPriority(
12580
- prefetchCid,
12581
- 0,
12582
- this.SEG_PRIO_CHAPTER_PREFETCH_BASE + chapterDist * 100
12583
- );
12584
- const prefetchChapter = this.findChapter(prefetchCid);
12585
- if (prefetchChapter) void this.resolveChapterUrls(prefetchChapter).catch(() => {
12586
- });
12587
- }
12588
12536
  }
12589
12537
  const rankedLoads = [...segmentPriorities.entries()].map(([segKey, priority]) => {
12590
12538
  const [chapterId, segStr] = segKey.split(":");
@@ -12953,14 +12901,14 @@ const m = { kind: "first-wins" };
12953
12901
  function _(e14) {
12954
12902
  return "last" === e14 ? { kind: "last-wins" } : { kind: "first-wins" };
12955
12903
  }
12956
- function R(e14) {
12904
+ function R2(e14) {
12957
12905
  const t2 = e14.endPage - e14.startPage + 1;
12958
12906
  return { chapterId: e14.chapterId, title: e14.title, globalPageRange: [e14.startPage, e14.endPage], localPageRange: [0, t2 - 1], ...e14.source ? { source: e14.source } : {}, ...null != e14.segmentPageThreshold ? { segmentPageThreshold: e14.segmentPageThreshold } : {}, ...e14.encrypted ? { encrypted: e14.encrypted } : {} };
12959
12907
  }
12960
12908
  function C(e14) {
12961
12909
  const t2 = [], n9 = (e15) => {
12962
12910
  var _a2;
12963
- for (const r2 of e15) t2.push(R(r2)), ((_a2 = r2.children) == null ? void 0 : _a2.length) && n9(r2.children);
12911
+ for (const r2 of e15) t2.push(R2(r2)), ((_a2 = r2.children) == null ? void 0 : _a2.length) && n9(r2.children);
12964
12912
  };
12965
12913
  return n9(e14), t2;
12966
12914
  }
@@ -12983,30 +12931,30 @@ export {
12983
12931
  Ln as DEFAULT_CHAPTER_VIEWER_CONFIG,
12984
12932
  xn as DEFAULT_CHAPTER_VIEWER_FEATURES,
12985
12933
  EmbedPDF2 as EmbedPDF,
12986
- Va as PdfChapterViewport,
12934
+ Ra as PdfChapterViewport,
12987
12935
  xe$1 as applySelectionMarkup,
12988
12936
  M as buildChapterViewerCatalog,
12989
- gn as buildParagraphBookmarkAnchor,
12990
- Ns as chapterAnnotationsArchiveToJson,
12991
- _s as chapterAnnotationsSnapshotToJson,
12992
- R as chapterDescriptorFromTreeNode,
12937
+ pn as buildParagraphBookmarkAnchor,
12938
+ Rs as chapterAnnotationsArchiveToJson,
12939
+ zs as chapterAnnotationsSnapshotToJson,
12940
+ R2 as chapterDescriptorFromTreeNode,
12993
12941
  Ms as copyTextToClipboard,
12994
- Tn as createChapterViewerBundle,
12942
+ Un as createChapterViewerBundle,
12995
12943
  $n as createChapterViewerEditor,
12996
- Un as createChapterViewerEditorOptions,
12944
+ Tn as createChapterViewerEditorOptions,
12997
12945
  wn as createPdfChapterEditor,
12998
12946
  m as defaultOverlapStrategy,
12999
- Hs as downloadChapterAnnotationsArchive,
13000
- qs as downloadChapterAnnotationsSnapshot,
13001
- Bs as downloadJsonFile,
13002
- As as exportAllChapterAnnotations,
13003
- Os as exportChapterAnnotations,
12947
+ qs as downloadChapterAnnotationsArchive,
12948
+ Ws as downloadChapterAnnotationsSnapshot,
12949
+ _s as downloadJsonFile,
12950
+ As2 as exportAllChapterAnnotations,
12951
+ Ns as exportChapterAnnotations,
13004
12952
  C as flattenChapterTree,
13005
- Rs2 as importChapterAnnotations,
13006
- Vs as importChapterAnnotationsArchive,
12953
+ Vs as importChapterAnnotations,
12954
+ Os as importChapterAnnotationsArchive,
13007
12955
  _ as overlapStrategyForSamePageOwner,
13008
12956
  Gs as parseChapterAnnotationsArchiveJson,
13009
- zs as parseChapterAnnotationsSnapshotJson,
12957
+ Bs as parseChapterAnnotationsSnapshotJson,
13010
12958
  G as toChapterTreeNodes,
13011
12959
  useCapability2 as useCapability,
13012
12960
  usePdfiumEngine,