@embedpdf-editor/vue3-chapter-viewer 0.3.0 → 0.3.2
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/README.md +212 -215
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +70 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1001 -966
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/vite.ts +2 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent, computed, h, openBlock, createElementBlock, normalizeStyle, unref, normalizeClass, createVNode, withCtx, renderSlot, createCommentVNode, ref, watch, onBeforeUnmount, Fragment, renderList, createElementVNode, toDisplayString, onMounted, createBlock, resolveDynamicComponent, withModifiers, isRef, normalizeProps, guardReactiveProps, createSlots } from "vue";
|
|
1
|
+
import { defineComponent, computed, h as h$1, openBlock, createElementBlock, normalizeStyle, unref, normalizeClass, createVNode, withCtx, renderSlot, createCommentVNode, ref, watch, onBeforeUnmount, Fragment, renderList, createElementVNode, toDisplayString, onMounted, createBlock, resolveDynamicComponent, withModifiers, isRef, normalizeProps, guardReactiveProps, createSlots } from "vue";
|
|
2
2
|
import { useRegistry, useCapability, EmbedPDF } from "@embedpdf/core/vue";
|
|
3
3
|
import { EmbedPDF as EmbedPDF2, useCapability as useCapability2, useRegistry as useRegistry2 } from "@embedpdf/core/vue";
|
|
4
4
|
import { LockModeType, AnnotationPluginPackage, AnnotationPlugin, ANNOTATION_PLUGIN_ID } from "@embedpdf/plugin-annotation";
|
|
@@ -24,40 +24,45 @@ import { AnnotationLayer } from "@embedpdf/plugin-annotation/vue";
|
|
|
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 ve$1 = { position: "relative", height: "100%", width: "100%" }, be$1 = {
|
|
28
|
-
function
|
|
27
|
+
const ve$1 = { position: "relative", height: "100%", width: "100%" }, be$1 = { userSelect: "none", WebkitUserSelect: "none" };
|
|
28
|
+
function Pe$1() {
|
|
29
|
+
var _a2;
|
|
30
|
+
"undefined" != typeof window && ((_a2 = window.getSelection()) == null ? void 0 : _a2.removeAllRanges());
|
|
31
|
+
}
|
|
32
|
+
const we$1 = { highlight: { offsetY: 0 }, underline: { offsetY: 2.5 }, squiggly: { offsetY: 0 }, strikeout: { offsetY: 0 } }, ye = { highlight: PdfAnnotationSubtype.HIGHLIGHT, underline: PdfAnnotationSubtype.UNDERLINE, squiggly: PdfAnnotationSubtype.SQUIGGLY, strikeout: PdfAnnotationSubtype.STRIKEOUT };
|
|
33
|
+
function Ce(e14, t2) {
|
|
29
34
|
return 0 === t2 ? e14 : e14.map((e15) => ({ origin: { x: e15.origin.x, y: e15.origin.y + t2 }, size: { ...e15.size } }));
|
|
30
35
|
}
|
|
31
|
-
function
|
|
32
|
-
let t2 = 1 / 0, a3 = 1 / 0, s9 = -1 / 0,
|
|
33
|
-
for (const o of e14) t2 = Math.min(t2, o.origin.x), a3 = Math.min(a3, o.origin.y), s9 = Math.max(s9, o.origin.x + o.size.width),
|
|
34
|
-
return { origin: { x: t2, y: a3 }, size: { width: s9 - t2, height:
|
|
36
|
+
function Ie(e14) {
|
|
37
|
+
let t2 = 1 / 0, a3 = 1 / 0, s9 = -1 / 0, i2 = -1 / 0;
|
|
38
|
+
for (const o of e14) t2 = Math.min(t2, o.origin.x), a3 = Math.min(a3, o.origin.y), s9 = Math.max(s9, o.origin.x + o.size.width), i2 = Math.max(i2, o.origin.y + o.size.height);
|
|
39
|
+
return { origin: { x: t2, y: a3 }, size: { width: s9 - t2, height: i2 - a3 } };
|
|
35
40
|
}
|
|
36
|
-
function
|
|
41
|
+
function Me(e14, t2, a3, s9, i2) {
|
|
37
42
|
const o = a3.forDocument(e14), r2 = s9.forDocument(e14);
|
|
38
43
|
if (!o || !r2) return false;
|
|
39
44
|
const n2 = "highlight" === t2 ? "highlight" : "underline" === t2 ? "underline" : "squiggly" === t2 ? "squiggly" : "strikeout", l = a3.getTool(n2);
|
|
40
45
|
if (!l) return false;
|
|
41
|
-
const h2 = l.defaults,
|
|
42
|
-
return { ...
|
|
43
|
-
})(t2,
|
|
46
|
+
const h2 = l.defaults, d2 = (function(e15, t3) {
|
|
47
|
+
return { ...we$1[e15], ...null == t3 ? void 0 : t3[e15] };
|
|
48
|
+
})(t2, i2), c = r2.getFormattedSelection();
|
|
44
49
|
if (0 === c.length) return false;
|
|
45
50
|
o.setLocked({ type: LockModeType.Exclude, categories: ["markup", "shape"] });
|
|
46
51
|
for (const u of c) {
|
|
47
|
-
const e15 = uuidV4(), a4 =
|
|
48
|
-
o.createAnnotation(u.pageIndex, { id: e15, created: /* @__PURE__ */ new Date(), flags: ["print"], type:
|
|
52
|
+
const e15 = uuidV4(), a4 = d2.color ?? h2.color ?? h2.strokeColor, s10 = d2.opacity ?? h2.opacity, i3 = d2.thickness ?? h2.strokeWidth, r3 = d2.offsetY ?? 0, n3 = "underline" === t2 || "squiggly" === t2 || "strikeout" === t2 ? Ce(u.segmentRects, r3) : u.segmentRects, l2 = "underline" === t2 || "squiggly" === t2 || "strikeout" === t2 ? Ie(n3) : u.rect;
|
|
53
|
+
o.createAnnotation(u.pageIndex, { id: e15, created: /* @__PURE__ */ new Date(), flags: ["print"], type: ye[t2], ..."highlight" === t2 ? { blendMode: PdfBlendMode.Multiply } : {}, strokeColor: a4, opacity: s10, ...null != i3 ? { strokeWidth: i3 } : {}, pageIndex: u.pageIndex, rect: l2, segmentRects: n3 });
|
|
49
54
|
}
|
|
50
55
|
return r2.clear(), true;
|
|
51
56
|
}
|
|
52
|
-
function
|
|
57
|
+
function Se(e14, t2) {
|
|
53
58
|
const a3 = e14;
|
|
54
59
|
return false === e14 ? { ...t2, enabled: false } : true === e14 || void 0 === e14 ? { ...t2, enabled: t2.enabled ?? true } : { ...t2, ...a3, enabled: false !== (null == a3 ? void 0 : a3.enabled) };
|
|
55
60
|
}
|
|
56
|
-
function
|
|
57
|
-
const t2 =
|
|
58
|
-
return { markup: t2, bookmarks: a3, notes: s9, zoom:
|
|
61
|
+
function xe(e14) {
|
|
62
|
+
const t2 = Se(null == e14 ? void 0 : e14.markup, { enabled: true }), a3 = Se(null == e14 ? void 0 : e14.bookmarks, { enabled: true }), s9 = Se(null == e14 ? void 0 : e14.notes, { enabled: true });
|
|
63
|
+
return { markup: t2, bookmarks: a3, notes: s9, zoom: Se(null == e14 ? void 0 : e14.zoom, { enabled: true, min: 0.5, max: 3, initial: 1 }), selectionToolbar: Se(void 0 === (null == e14 ? void 0 : e14.selectionToolbar) ? false !== t2.enabled || false !== s9.enabled : e14.selectionToolbar, { enabled: true }) };
|
|
59
64
|
}
|
|
60
|
-
class
|
|
65
|
+
class Le {
|
|
61
66
|
constructor(e14) {
|
|
62
67
|
this.cb = e14;
|
|
63
68
|
}
|
|
@@ -65,9 +70,9 @@ class Se {
|
|
|
65
70
|
return this.cb(e14, t2);
|
|
66
71
|
}
|
|
67
72
|
}
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
function
|
|
73
|
+
const Ge = "chapter-manager", Ne = { id: Ge, name: "Chapter Manager Plugin", version: "0.1.0", provides: ["chapter-manager"], requires: ["document-manager"], optional: [], defaultConfig: { manifest: { chapters: [] }, prefetchChapters: 1, unloadTimeoutMs: 6e4, autoActivateOnLoad: true } };
|
|
74
|
+
const Ae = { kind: "first-wins" };
|
|
75
|
+
function Ve(e14, t2, a3) {
|
|
71
76
|
if (1 === t2.length) return t2[0].chapterId;
|
|
72
77
|
switch (a3.kind) {
|
|
73
78
|
case "first-wins":
|
|
@@ -85,7 +90,7 @@ function $e(e14, t2, a3) {
|
|
|
85
90
|
return a3.resolve(e14, t2);
|
|
86
91
|
}
|
|
87
92
|
}
|
|
88
|
-
let
|
|
93
|
+
let _e = class {
|
|
89
94
|
constructor(e14) {
|
|
90
95
|
this._pages = e14, this._byChapter = /* @__PURE__ */ new Map(), this._byGlobalNumber = /* @__PURE__ */ new Map();
|
|
91
96
|
for (const t2 of e14) {
|
|
@@ -119,37 +124,37 @@ let ze = class {
|
|
|
119
124
|
return a3 ? this._pages.indexOf(a3) : -1;
|
|
120
125
|
}
|
|
121
126
|
};
|
|
122
|
-
function
|
|
123
|
-
const a3 = (function(e15, t3 =
|
|
127
|
+
function Ee(e14, t2 = Ae) {
|
|
128
|
+
const a3 = (function(e15, t3 = Ae) {
|
|
124
129
|
const a4 = /* @__PURE__ */ new Map();
|
|
125
|
-
for (const
|
|
126
|
-
const [e16, t4] =
|
|
130
|
+
for (const i3 of e15.chapters) {
|
|
131
|
+
const [e16, t4] = i3.globalPageRange;
|
|
127
132
|
for (let s11 = e16; s11 <= t4; s11++) {
|
|
128
133
|
const e17 = a4.get(s11);
|
|
129
|
-
e17 ? e17.push(
|
|
134
|
+
e17 ? e17.push(i3) : a4.set(s11, [i3]);
|
|
130
135
|
}
|
|
131
136
|
}
|
|
132
137
|
const s10 = /* @__PURE__ */ new Map();
|
|
133
|
-
for (const [
|
|
138
|
+
for (const [i3, o2] of a4) s10.set(i3, Ve(i3, o2, t3));
|
|
134
139
|
return s10;
|
|
135
140
|
})(e14, t2), s9 = /* @__PURE__ */ new Map();
|
|
136
141
|
for (const n2 of e14.chapters) s9.set(n2.chapterId, n2);
|
|
137
|
-
const
|
|
142
|
+
const i2 = Array.from(a3.keys()).sort((e15, t3) => e15 - t3), o = [];
|
|
138
143
|
let r2 = 0;
|
|
139
|
-
for (const n2 of
|
|
144
|
+
for (const n2 of i2) {
|
|
140
145
|
const e15 = a3.get(n2), t3 = s9.get(e15);
|
|
141
146
|
if (!t3) continue;
|
|
142
|
-
const [
|
|
147
|
+
const [i3] = t3.globalPageRange, [l] = t3.localPageRange, h2 = l + (n2 - i3);
|
|
143
148
|
o.push({ globalPageIndex: r2++, globalPageNumber: n2, chapterId: e15, localPageIndex: h2 });
|
|
144
149
|
}
|
|
145
|
-
return new
|
|
150
|
+
return new _e(o);
|
|
146
151
|
}
|
|
147
|
-
const
|
|
152
|
+
const Re = class e extends BasePlugin {
|
|
148
153
|
constructor(e14, t2) {
|
|
149
|
-
super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy =
|
|
154
|
+
super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = Ae, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingLoadPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
|
|
150
155
|
}
|
|
151
156
|
async initialize(e14) {
|
|
152
|
-
if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ??
|
|
157
|
+
if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? Ae, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
|
|
153
158
|
this.isOwnedChapter(e15.id) && (this.passwordAttempts.delete(e15.id), this.updateStatus(e15.id, "loaded"));
|
|
154
159
|
}), this.documentManager.provides().onDocumentClosed((e15) => {
|
|
155
160
|
this.isOwnedChapter(e15) && this.updateStatus(e15, "closed");
|
|
@@ -175,16 +180,16 @@ const De = class e extends BasePlugin {
|
|
|
175
180
|
const t3 = [], a4 = /* @__PURE__ */ new Set();
|
|
176
181
|
for (const s10 of e14.chapters) {
|
|
177
182
|
a4.has(s10.chapterId) && t3.push(`Duplicate chapterId: ${s10.chapterId}`), a4.add(s10.chapterId);
|
|
178
|
-
const [e15,
|
|
179
|
-
if (e15 >
|
|
183
|
+
const [e15, i3] = s10.globalPageRange, [o, r2] = s10.localPageRange;
|
|
184
|
+
if (e15 > i3 && t3.push(`${s10.chapterId}: invalid globalPageRange [${e15},${i3}]`), o > r2 && t3.push(`${s10.chapterId}: invalid localPageRange [${o},${r2}]`), i3 - e15 !== r2 - o && t3.push(`${s10.chapterId}: page-count mismatch (global ${i3 - e15 + 1} vs local ${r2 - o + 1})`), s10.ownedGlobalPages) for (const a5 of s10.ownedGlobalPages) (a5 < e15 || a5 > i3) && t3.push(`${s10.chapterId}: ownedGlobalPages contains ${a5} outside range`);
|
|
180
185
|
}
|
|
181
186
|
return t3;
|
|
182
187
|
})(t2);
|
|
183
188
|
a3.length > 0 && this.logger.warn(e.id, "ManifestValidation", `Chapter manifest has issues: ${a3.join("; ")}`);
|
|
184
|
-
const s9 = new Set(this.chapterStatus.keys()),
|
|
185
|
-
for (const e14 of s9)
|
|
189
|
+
const s9 = new Set(this.chapterStatus.keys()), i2 = new Set(t2.chapters.map((e14) => e14.chapterId));
|
|
190
|
+
for (const e14 of s9) i2.has(e14) || (this.closeChapter(e14), this.chapterStatus.delete(e14));
|
|
186
191
|
for (const e14 of t2.chapters) this.chapterStatus.has(e14.chapterId) || this.chapterStatus.set(e14.chapterId, "idle");
|
|
187
|
-
this.manifest = t2, this.virtualPageMap =
|
|
192
|
+
this.manifest = t2, this.virtualPageMap = Ee(t2, this.overlapStrategy), this.manifestChange$.emit({ manifest: t2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
|
|
188
193
|
}
|
|
189
194
|
eagerPrefetchFromManifest() {
|
|
190
195
|
const e14 = this.config.prefetchChapters ?? 0;
|
|
@@ -211,20 +216,20 @@ const De = class e extends BasePlugin {
|
|
|
211
216
|
e15 && s9.add(e15.chapterId);
|
|
212
217
|
}
|
|
213
218
|
if (0 === s9.size) return;
|
|
214
|
-
const
|
|
219
|
+
const i2 = this.manifest.chapters.map((e15) => e15.chapterId), o = /* @__PURE__ */ new Set();
|
|
215
220
|
for (const n2 of s9) {
|
|
216
|
-
const e15 =
|
|
217
|
-
if (-1 !== e15) for (let t3 = e15 - a3; t3 <= e15 + a3; t3++) t3 >= 0 && t3 <
|
|
221
|
+
const e15 = i2.indexOf(n2);
|
|
222
|
+
if (-1 !== e15) for (let t3 = e15 - a3; t3 <= e15 + a3; t3++) t3 >= 0 && t3 < i2.length && o.add(t3);
|
|
218
223
|
}
|
|
219
224
|
const r2 = /* @__PURE__ */ new Set();
|
|
220
|
-
for (const n2 of o) r2.add(
|
|
225
|
+
for (const n2 of o) r2.add(i2[n2]);
|
|
221
226
|
for (const n2 of r2) {
|
|
222
227
|
this.chapterLastUsed.set(n2, t2);
|
|
223
228
|
const e15 = this.chapterStatus.get(n2) ?? "idle";
|
|
224
229
|
"idle" !== e15 && "closed" !== e15 && "error" !== e15 || this.ensureChapterLoaded(n2);
|
|
225
230
|
}
|
|
226
231
|
if (this.config.autoActivateOnLoad ?? 1) {
|
|
227
|
-
const e15 =
|
|
232
|
+
const e15 = i2.find((e16) => s9.has(e16));
|
|
228
233
|
if (e15 && this.documentManager.provides().isDocumentOpen(e15)) {
|
|
229
234
|
this.documentManager.provides().getActiveDocumentId() !== e15 && this.documentManager.provides().setActiveDocument(e15);
|
|
230
235
|
}
|
|
@@ -247,10 +252,10 @@ const De = class e extends BasePlugin {
|
|
|
247
252
|
const s9 = this.chapterStatus.get(e14) ?? "idle";
|
|
248
253
|
if ("loaded" === s9) return this.chapterLastUsed.set(e14, Date.now()), Promise.resolve("loaded");
|
|
249
254
|
if ("loading" === s9) return this.waitForTerminalStatus(e14);
|
|
250
|
-
const
|
|
255
|
+
const i2 = this.startLoad(a3).finally(() => {
|
|
251
256
|
this.pendingLoadPromises.delete(e14);
|
|
252
257
|
});
|
|
253
|
-
return this.pendingLoadPromises.set(e14,
|
|
258
|
+
return this.pendingLoadPromises.set(e14, i2), i2;
|
|
254
259
|
}
|
|
255
260
|
async resolvePdfPayload(e14) {
|
|
256
261
|
const t2 = e14.source;
|
|
@@ -268,17 +273,17 @@ const De = class e extends BasePlugin {
|
|
|
268
273
|
const s9 = t2.chapterId;
|
|
269
274
|
this.updateStatus(s9, "loading"), this.chapterLastUsed.set(s9, Date.now());
|
|
270
275
|
try {
|
|
271
|
-
const e14 = t2.encrypted && (null == (a3 = this.passwordProvider) ? void 0 : a3.getCachedPassword) ? this.passwordProvider.getCachedPassword(s9) : null,
|
|
276
|
+
const e14 = t2.encrypted && (null == (a3 = this.passwordProvider) ? void 0 : a3.getCachedPassword) ? this.passwordProvider.getCachedPassword(s9) : null, i2 = await this.resolvePdfPayload(t2), o = this.documentManager.provides(), r2 = "url" in i2 ? o.openDocumentUrl({ documentId: s9, url: i2.url, name: t2.title, password: e14 ?? void 0, autoActivate: false }) : o.openDocumentBuffer({ documentId: s9, buffer: i2.buffer, name: t2.title, password: e14 ?? void 0, autoActivate: false }), n2 = await new Promise((e15, t3) => {
|
|
272
277
|
r2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
273
278
|
});
|
|
274
279
|
return await new Promise((e15, t3) => {
|
|
275
280
|
n2.task.wait(() => e15(), (e16) => t3(e16));
|
|
276
281
|
}), o.isDocumentOpen(s9) && this.updateStatus(s9, "loaded"), this.waitForTerminalStatus(s9);
|
|
277
|
-
} catch (
|
|
282
|
+
} catch (i2) {
|
|
278
283
|
const t3 = this.chapterStatus.get(s9);
|
|
279
284
|
if ("loaded" !== t3 && "password-required" !== t3) {
|
|
280
|
-
const t4 =
|
|
281
|
-
this.logger.error(e.id, "LoadChapter", t4,
|
|
285
|
+
const t4 = i2 instanceof Error ? i2.message : `Failed to load chapter "${s9}"`;
|
|
286
|
+
this.logger.error(e.id, "LoadChapter", t4, i2), this.updateStatus(s9, "error", t4);
|
|
282
287
|
}
|
|
283
288
|
return this.chapterStatus.get(s9) ?? "error";
|
|
284
289
|
}
|
|
@@ -296,13 +301,13 @@ const De = class e extends BasePlugin {
|
|
|
296
301
|
async handleDocumentError(t2, a3, s9) {
|
|
297
302
|
if (a3 !== PdfErrorCode.Password) return void this.updateStatus(t2, "error");
|
|
298
303
|
if (!this.passwordProvider) return void this.updateStatus(t2, "password-required");
|
|
299
|
-
const
|
|
300
|
-
if (!
|
|
304
|
+
const i2 = this.findChapter(t2);
|
|
305
|
+
if (!i2) return;
|
|
301
306
|
const o = (this.passwordAttempts.get(t2) ?? 0) + 1;
|
|
302
307
|
this.passwordAttempts.set(t2, o);
|
|
303
308
|
let r2 = null;
|
|
304
309
|
try {
|
|
305
|
-
r2 = await this.passwordProvider.resolvePassword(
|
|
310
|
+
r2 = await this.passwordProvider.resolvePassword(i2, o - 1);
|
|
306
311
|
} catch (n2) {
|
|
307
312
|
this.logger.error(e.id, "PasswordProvider", `Provider rejected for ${t2}`, n2);
|
|
308
313
|
}
|
|
@@ -322,11 +327,11 @@ const De = class e extends BasePlugin {
|
|
|
322
327
|
this.chapterStatus.get(e14) !== t2 && (this.chapterStatus.set(e14, t2), this.statusChange$.emit({ chapterId: e14, status: t2, ..."error" === t2 && a3 ? { error: { message: a3 } } : {} }));
|
|
323
328
|
}
|
|
324
329
|
};
|
|
325
|
-
|
|
326
|
-
let
|
|
327
|
-
const
|
|
328
|
-
const
|
|
329
|
-
function
|
|
330
|
+
Re.id = "chapter-manager";
|
|
331
|
+
let Fe = Re;
|
|
332
|
+
const Ue = { manifest: Ne, create: (e14) => new Fe(Ge, e14), reducer: (e14) => e14, initialState: {} }, qe = "chapter-scroll", We = { id: qe, name: "Chapter Scroll Plugin", version: "0.1.0", provides: ["chapter-scroll"], requires: ["chapter-manager"], optional: [], defaultConfig: { placeholderPageHeight: 1200, placeholderPageWidth: 900, bufferSize: 2, pageGap: 20 } };
|
|
333
|
+
const He = { kind: "first-wins" };
|
|
334
|
+
function Be(e14, t2, a3) {
|
|
330
335
|
if (1 === t2.length) return t2[0].chapterId;
|
|
331
336
|
switch (a3.kind) {
|
|
332
337
|
case "first-wins":
|
|
@@ -344,7 +349,7 @@ function _e(e14, t2, a3) {
|
|
|
344
349
|
return a3.resolve(e14, t2);
|
|
345
350
|
}
|
|
346
351
|
}
|
|
347
|
-
let
|
|
352
|
+
let je = class {
|
|
348
353
|
constructor(e14) {
|
|
349
354
|
this._pages = e14, this._byChapter = /* @__PURE__ */ new Map(), this._byGlobalNumber = /* @__PURE__ */ new Map();
|
|
350
355
|
for (const t2 of e14) {
|
|
@@ -378,37 +383,37 @@ let Ee = class {
|
|
|
378
383
|
return a3 ? this._pages.indexOf(a3) : -1;
|
|
379
384
|
}
|
|
380
385
|
};
|
|
381
|
-
function
|
|
382
|
-
const a3 = (function(e15, t3 =
|
|
386
|
+
function Ze(e14, t2 = He) {
|
|
387
|
+
const a3 = (function(e15, t3 = He) {
|
|
383
388
|
const a4 = /* @__PURE__ */ new Map();
|
|
384
|
-
for (const
|
|
385
|
-
const [e16, t4] =
|
|
389
|
+
for (const i3 of e15.chapters) {
|
|
390
|
+
const [e16, t4] = i3.globalPageRange;
|
|
386
391
|
for (let s11 = e16; s11 <= t4; s11++) {
|
|
387
392
|
const e17 = a4.get(s11);
|
|
388
|
-
e17 ? e17.push(
|
|
393
|
+
e17 ? e17.push(i3) : a4.set(s11, [i3]);
|
|
389
394
|
}
|
|
390
395
|
}
|
|
391
396
|
const s10 = /* @__PURE__ */ new Map();
|
|
392
|
-
for (const [
|
|
397
|
+
for (const [i3, o2] of a4) s10.set(i3, Be(i3, o2, t3));
|
|
393
398
|
return s10;
|
|
394
399
|
})(e14, t2), s9 = /* @__PURE__ */ new Map();
|
|
395
400
|
for (const n2 of e14.chapters) s9.set(n2.chapterId, n2);
|
|
396
|
-
const
|
|
401
|
+
const i2 = Array.from(a3.keys()).sort((e15, t3) => e15 - t3), o = [];
|
|
397
402
|
let r2 = 0;
|
|
398
|
-
for (const n2 of
|
|
403
|
+
for (const n2 of i2) {
|
|
399
404
|
const e15 = a3.get(n2), t3 = s9.get(e15);
|
|
400
405
|
if (!t3) continue;
|
|
401
|
-
const [
|
|
406
|
+
const [i3] = t3.globalPageRange, [l] = t3.localPageRange, h2 = l + (n2 - i3);
|
|
402
407
|
o.push({ globalPageIndex: r2++, globalPageNumber: n2, chapterId: e15, localPageIndex: h2 });
|
|
403
408
|
}
|
|
404
|
-
return new
|
|
409
|
+
return new je(o);
|
|
405
410
|
}
|
|
406
|
-
const
|
|
411
|
+
const Ye = class e2 extends BasePlugin {
|
|
407
412
|
constructor(e14, t2) {
|
|
408
|
-
super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy =
|
|
413
|
+
super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = He, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingLoadPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
|
|
409
414
|
}
|
|
410
415
|
async initialize(e14) {
|
|
411
|
-
if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ??
|
|
416
|
+
if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? He, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
|
|
412
417
|
this.isOwnedChapter(e15.id) && (this.passwordAttempts.delete(e15.id), this.updateStatus(e15.id, "loaded"));
|
|
413
418
|
}), this.documentManager.provides().onDocumentClosed((e15) => {
|
|
414
419
|
this.isOwnedChapter(e15) && this.updateStatus(e15, "closed");
|
|
@@ -434,16 +439,16 @@ const Fe = class e2 extends BasePlugin {
|
|
|
434
439
|
const t3 = [], a4 = /* @__PURE__ */ new Set();
|
|
435
440
|
for (const s10 of e14.chapters) {
|
|
436
441
|
a4.has(s10.chapterId) && t3.push(`Duplicate chapterId: ${s10.chapterId}`), a4.add(s10.chapterId);
|
|
437
|
-
const [e15,
|
|
438
|
-
if (e15 >
|
|
442
|
+
const [e15, i3] = s10.globalPageRange, [o, r2] = s10.localPageRange;
|
|
443
|
+
if (e15 > i3 && t3.push(`${s10.chapterId}: invalid globalPageRange [${e15},${i3}]`), o > r2 && t3.push(`${s10.chapterId}: invalid localPageRange [${o},${r2}]`), i3 - e15 !== r2 - o && t3.push(`${s10.chapterId}: page-count mismatch (global ${i3 - e15 + 1} vs local ${r2 - o + 1})`), s10.ownedGlobalPages) for (const a5 of s10.ownedGlobalPages) (a5 < e15 || a5 > i3) && t3.push(`${s10.chapterId}: ownedGlobalPages contains ${a5} outside range`);
|
|
439
444
|
}
|
|
440
445
|
return t3;
|
|
441
446
|
})(t2);
|
|
442
447
|
a3.length > 0 && this.logger.warn(e2.id, "ManifestValidation", `Chapter manifest has issues: ${a3.join("; ")}`);
|
|
443
|
-
const s9 = new Set(this.chapterStatus.keys()),
|
|
444
|
-
for (const e14 of s9)
|
|
448
|
+
const s9 = new Set(this.chapterStatus.keys()), i2 = new Set(t2.chapters.map((e14) => e14.chapterId));
|
|
449
|
+
for (const e14 of s9) i2.has(e14) || (this.closeChapter(e14), this.chapterStatus.delete(e14));
|
|
445
450
|
for (const e14 of t2.chapters) this.chapterStatus.has(e14.chapterId) || this.chapterStatus.set(e14.chapterId, "idle");
|
|
446
|
-
this.manifest = t2, this.virtualPageMap =
|
|
451
|
+
this.manifest = t2, this.virtualPageMap = Ze(t2, this.overlapStrategy), this.manifestChange$.emit({ manifest: t2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
|
|
447
452
|
}
|
|
448
453
|
eagerPrefetchFromManifest() {
|
|
449
454
|
const e14 = this.config.prefetchChapters ?? 0;
|
|
@@ -470,20 +475,20 @@ const Fe = class e2 extends BasePlugin {
|
|
|
470
475
|
e15 && s9.add(e15.chapterId);
|
|
471
476
|
}
|
|
472
477
|
if (0 === s9.size) return;
|
|
473
|
-
const
|
|
478
|
+
const i2 = this.manifest.chapters.map((e15) => e15.chapterId), o = /* @__PURE__ */ new Set();
|
|
474
479
|
for (const n2 of s9) {
|
|
475
|
-
const e15 =
|
|
476
|
-
if (-1 !== e15) for (let t3 = e15 - a3; t3 <= e15 + a3; t3++) t3 >= 0 && t3 <
|
|
480
|
+
const e15 = i2.indexOf(n2);
|
|
481
|
+
if (-1 !== e15) for (let t3 = e15 - a3; t3 <= e15 + a3; t3++) t3 >= 0 && t3 < i2.length && o.add(t3);
|
|
477
482
|
}
|
|
478
483
|
const r2 = /* @__PURE__ */ new Set();
|
|
479
|
-
for (const n2 of o) r2.add(
|
|
484
|
+
for (const n2 of o) r2.add(i2[n2]);
|
|
480
485
|
for (const n2 of r2) {
|
|
481
486
|
this.chapterLastUsed.set(n2, t2);
|
|
482
487
|
const e15 = this.chapterStatus.get(n2) ?? "idle";
|
|
483
488
|
"idle" !== e15 && "closed" !== e15 && "error" !== e15 || this.ensureChapterLoaded(n2);
|
|
484
489
|
}
|
|
485
490
|
if (this.config.autoActivateOnLoad ?? 1) {
|
|
486
|
-
const e15 =
|
|
491
|
+
const e15 = i2.find((e16) => s9.has(e16));
|
|
487
492
|
if (e15 && this.documentManager.provides().isDocumentOpen(e15)) {
|
|
488
493
|
this.documentManager.provides().getActiveDocumentId() !== e15 && this.documentManager.provides().setActiveDocument(e15);
|
|
489
494
|
}
|
|
@@ -506,10 +511,10 @@ const Fe = class e2 extends BasePlugin {
|
|
|
506
511
|
const s9 = this.chapterStatus.get(e14) ?? "idle";
|
|
507
512
|
if ("loaded" === s9) return this.chapterLastUsed.set(e14, Date.now()), Promise.resolve("loaded");
|
|
508
513
|
if ("loading" === s9) return this.waitForTerminalStatus(e14);
|
|
509
|
-
const
|
|
514
|
+
const i2 = this.startLoad(a3).finally(() => {
|
|
510
515
|
this.pendingLoadPromises.delete(e14);
|
|
511
516
|
});
|
|
512
|
-
return this.pendingLoadPromises.set(e14,
|
|
517
|
+
return this.pendingLoadPromises.set(e14, i2), i2;
|
|
513
518
|
}
|
|
514
519
|
async resolvePdfPayload(e14) {
|
|
515
520
|
const t2 = e14.source;
|
|
@@ -527,17 +532,17 @@ const Fe = class e2 extends BasePlugin {
|
|
|
527
532
|
const s9 = t2.chapterId;
|
|
528
533
|
this.updateStatus(s9, "loading"), this.chapterLastUsed.set(s9, Date.now());
|
|
529
534
|
try {
|
|
530
|
-
const e14 = t2.encrypted && (null == (a3 = this.passwordProvider) ? void 0 : a3.getCachedPassword) ? this.passwordProvider.getCachedPassword(s9) : null,
|
|
535
|
+
const e14 = t2.encrypted && (null == (a3 = this.passwordProvider) ? void 0 : a3.getCachedPassword) ? this.passwordProvider.getCachedPassword(s9) : null, i2 = await this.resolvePdfPayload(t2), o = this.documentManager.provides(), r2 = "url" in i2 ? o.openDocumentUrl({ documentId: s9, url: i2.url, name: t2.title, password: e14 ?? void 0, autoActivate: false }) : o.openDocumentBuffer({ documentId: s9, buffer: i2.buffer, name: t2.title, password: e14 ?? void 0, autoActivate: false }), n2 = await new Promise((e15, t3) => {
|
|
531
536
|
r2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
532
537
|
});
|
|
533
538
|
return await new Promise((e15, t3) => {
|
|
534
539
|
n2.task.wait(() => e15(), (e16) => t3(e16));
|
|
535
540
|
}), o.isDocumentOpen(s9) && this.updateStatus(s9, "loaded"), this.waitForTerminalStatus(s9);
|
|
536
|
-
} catch (
|
|
541
|
+
} catch (i2) {
|
|
537
542
|
const t3 = this.chapterStatus.get(s9);
|
|
538
543
|
if ("loaded" !== t3 && "password-required" !== t3) {
|
|
539
|
-
const t4 =
|
|
540
|
-
this.logger.error(e2.id, "LoadChapter", t4,
|
|
544
|
+
const t4 = i2 instanceof Error ? i2.message : `Failed to load chapter "${s9}"`;
|
|
545
|
+
this.logger.error(e2.id, "LoadChapter", t4, i2), this.updateStatus(s9, "error", t4);
|
|
541
546
|
}
|
|
542
547
|
return this.chapterStatus.get(s9) ?? "error";
|
|
543
548
|
}
|
|
@@ -555,13 +560,13 @@ const Fe = class e2 extends BasePlugin {
|
|
|
555
560
|
async handleDocumentError(t2, a3, s9) {
|
|
556
561
|
if (a3 !== PdfErrorCode.Password) return void this.updateStatus(t2, "error");
|
|
557
562
|
if (!this.passwordProvider) return void this.updateStatus(t2, "password-required");
|
|
558
|
-
const
|
|
559
|
-
if (!
|
|
563
|
+
const i2 = this.findChapter(t2);
|
|
564
|
+
if (!i2) return;
|
|
560
565
|
const o = (this.passwordAttempts.get(t2) ?? 0) + 1;
|
|
561
566
|
this.passwordAttempts.set(t2, o);
|
|
562
567
|
let r2 = null;
|
|
563
568
|
try {
|
|
564
|
-
r2 = await this.passwordProvider.resolvePassword(
|
|
569
|
+
r2 = await this.passwordProvider.resolvePassword(i2, o - 1);
|
|
565
570
|
} catch (n2) {
|
|
566
571
|
this.logger.error(e2.id, "PasswordProvider", `Provider rejected for ${t2}`, n2);
|
|
567
572
|
}
|
|
@@ -581,20 +586,20 @@ const Fe = class e2 extends BasePlugin {
|
|
|
581
586
|
this.chapterStatus.get(e14) !== t2 && (this.chapterStatus.set(e14, t2), this.statusChange$.emit({ chapterId: e14, status: t2, ..."error" === t2 && a3 ? { error: { message: a3 } } : {} }));
|
|
582
587
|
}
|
|
583
588
|
};
|
|
584
|
-
|
|
585
|
-
let
|
|
586
|
-
function
|
|
589
|
+
Ye.id = "chapter-manager";
|
|
590
|
+
let Ke = Ye;
|
|
591
|
+
function Xe(e14, t2) {
|
|
587
592
|
if (e14 === t2) return true;
|
|
588
593
|
if (e14.totalHeight !== t2.totalHeight || e14.totalWidth !== t2.totalWidth || e14.pageGap !== t2.pageGap || e14.items.length !== t2.items.length) return false;
|
|
589
594
|
for (let a3 = 0; a3 < e14.items.length; a3++) {
|
|
590
|
-
const s9 = e14.items[a3],
|
|
591
|
-
if (s9.globalPageIndex !==
|
|
595
|
+
const s9 = e14.items[a3], i2 = t2.items[a3];
|
|
596
|
+
if (s9.globalPageIndex !== i2.globalPageIndex || s9.isPlaceholder !== i2.isPlaceholder || s9.chapterId !== i2.chapterId || s9.localPageIndex !== i2.localPageIndex || s9.offsetTop !== i2.offsetTop || s9.width !== i2.width || s9.height !== i2.height) return false;
|
|
592
597
|
}
|
|
593
598
|
return true;
|
|
594
599
|
}
|
|
595
|
-
const
|
|
600
|
+
const Qe = class extends BasePlugin {
|
|
596
601
|
constructor(e14, t2) {
|
|
597
|
-
super(e14, t2), this.layoutChange$ = createBehaviorEmitter(void 0,
|
|
602
|
+
super(e14, t2), this.layoutChange$ = createBehaviorEmitter(void 0, Xe), 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.chapterManagerUnsubs = [], this.chapterManager = this.registry.getPlugin(Ke.id), this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
|
|
598
603
|
}
|
|
599
604
|
async initialize(e14) {
|
|
600
605
|
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 }) => {
|
|
@@ -648,8 +653,8 @@ const We = class extends BasePlugin {
|
|
|
648
653
|
this.offsets = new Array(e14);
|
|
649
654
|
let t2 = 0, a3 = 0;
|
|
650
655
|
for (let s9 = 0; s9 < e14; s9++) {
|
|
651
|
-
const { width: e15, height:
|
|
652
|
-
this.offsets[s9] = t2, t2 +=
|
|
656
|
+
const { width: e15, height: i2 } = this.getPageSize(s9);
|
|
657
|
+
this.offsets[s9] = t2, t2 += i2 + this.config.pageGap, e15 > a3 && (a3 = e15);
|
|
653
658
|
}
|
|
654
659
|
this.totalHeight = e14 > 0 ? t2 - this.config.pageGap : 0, this.totalWidth = a3, this.layoutChange$.emit(this.computeLayout());
|
|
655
660
|
}
|
|
@@ -659,8 +664,8 @@ const We = class extends BasePlugin {
|
|
|
659
664
|
for (const s9 of t2) {
|
|
660
665
|
const t3 = this.virtualPageMap.toGlobal(e14, s9.localPageIndex);
|
|
661
666
|
if (!t3) continue;
|
|
662
|
-
const
|
|
663
|
-
|
|
667
|
+
const i2 = this.pageSizes.get(t3.globalPageIndex);
|
|
668
|
+
i2 && i2.width === s9.width && i2.height === s9.height || (this.pageSizes.set(t3.globalPageIndex, { width: s9.width, height: s9.height }), a3 = true);
|
|
664
669
|
}
|
|
665
670
|
if (a3) {
|
|
666
671
|
const e15 = this.currentGlobalPageIndex, t3 = this.offsets[e15] ?? 0;
|
|
@@ -678,10 +683,10 @@ const We = class extends BasePlugin {
|
|
|
678
683
|
harvestChapterSizes(e14, t2 = 0) {
|
|
679
684
|
var a3;
|
|
680
685
|
if (!this.virtualPageMap) return;
|
|
681
|
-
const s9 = this.documentManager.provides().getDocument(e14),
|
|
682
|
-
if (!(null == (a3 = null == s9 ? void 0 : s9.pages) ? void 0 : a3.length) || 0 ===
|
|
686
|
+
const s9 = this.documentManager.provides().getDocument(e14), i2 = this.virtualPageMap.pagesOfChapter(e14);
|
|
687
|
+
if (!(null == (a3 = null == s9 ? void 0 : s9.pages) ? void 0 : a3.length) || 0 === i2.length) return void (t2 < 60 && requestAnimationFrame(() => this.harvestChapterSizes(e14, t2 + 1)));
|
|
683
688
|
const o = this.getChapterDocumentScale(e14), r2 = [];
|
|
684
|
-
for (const n2 of
|
|
689
|
+
for (const n2 of i2) {
|
|
685
690
|
const e15 = s9.pages[n2.localPageIndex];
|
|
686
691
|
(null == e15 ? void 0 : e15.size) && r2.push({ localPageIndex: n2.localPageIndex, width: e15.size.width * o, height: e15.size.height * o });
|
|
687
692
|
}
|
|
@@ -712,38 +717,38 @@ const We = class extends BasePlugin {
|
|
|
712
717
|
const e14 = this.virtualPageMap.totalPages;
|
|
713
718
|
if (0 === e14) return this.currentVisible = [], this.currentGlobalPageIndex = 0, void this.layoutChange$.emit(this.computeLayout());
|
|
714
719
|
const t2 = this.viewportEl.scrollTop, a3 = t2 + this.viewportEl.clientHeight, s9 = this.findFirstVisibleIndex(t2);
|
|
715
|
-
let
|
|
716
|
-
for (;
|
|
717
|
-
const e15 = this.getPageSize(
|
|
720
|
+
let i2 = s9;
|
|
721
|
+
for (; i2 < e14; ) {
|
|
722
|
+
const e15 = this.getPageSize(i2), t3 = this.offsets[i2];
|
|
718
723
|
if (e15.height, t3 >= a3) break;
|
|
719
|
-
|
|
724
|
+
i2++;
|
|
720
725
|
}
|
|
721
726
|
const o = [];
|
|
722
727
|
let r2 = s9, n2 = -1;
|
|
723
|
-
for (let l = s9; l <
|
|
728
|
+
for (let l = s9; l < i2; l++) {
|
|
724
729
|
o.push(l);
|
|
725
|
-
const e15 = this.offsets[l], s10 = e15 + this.getPageSize(l).height,
|
|
726
|
-
|
|
730
|
+
const e15 = this.offsets[l], s10 = e15 + this.getPageSize(l).height, i3 = Math.max(0, Math.min(s10, a3) - Math.max(e15, t2));
|
|
731
|
+
i3 > n2 && (n2 = i3, r2 = l);
|
|
727
732
|
}
|
|
728
733
|
this.currentVisible = o, this.currentGlobalPageIndex = r2, this.visibleChange$.emit({ visibleGlobalPageIndices: o, currentGlobalPageIndex: r2 }), this.chapterManager.provides().setVisibleGlobalPages(o), this.layoutChange$.emit(this.computeLayout());
|
|
729
734
|
}
|
|
730
735
|
findFirstVisibleIndex(e14) {
|
|
731
736
|
let t2 = 0, a3 = this.offsets.length - 1, s9 = 0;
|
|
732
737
|
for (; t2 <= a3; ) {
|
|
733
|
-
const
|
|
734
|
-
this.offsets[
|
|
738
|
+
const i2 = t2 + a3 >> 1;
|
|
739
|
+
this.offsets[i2] <= e14 ? (s9 = i2, t2 = i2 + 1) : a3 = i2 - 1;
|
|
735
740
|
}
|
|
736
741
|
return s9;
|
|
737
742
|
}
|
|
738
743
|
computeLayout() {
|
|
739
|
-
const e14 = this.config.bufferSize, t2 = Math.max(0, (this.currentVisible[0] ?? 0) - e14), a3 = this.currentVisible[this.currentVisible.length - 1] ?? -1, s9 = Math.min(this.offsets.length - 1, (a3 >= 0 ? a3 : 0) + e14),
|
|
744
|
+
const e14 = this.config.bufferSize, t2 = Math.max(0, (this.currentVisible[0] ?? 0) - e14), a3 = this.currentVisible[this.currentVisible.length - 1] ?? -1, s9 = Math.min(this.offsets.length - 1, (a3 >= 0 ? a3 : 0) + e14), i2 = [];
|
|
740
745
|
if (this.virtualPageMap && this.offsets.length > 0) for (let o = t2; o <= s9; o++) {
|
|
741
746
|
const e15 = this.virtualPageMap.atIndex(o);
|
|
742
747
|
if (!e15) continue;
|
|
743
748
|
const t3 = this.getPageSize(o), a4 = this.isChapterPagePlaceholder(e15.chapterId);
|
|
744
|
-
|
|
749
|
+
i2.push({ globalPageIndex: o, globalPageNumber: e15.globalPageNumber, chapterId: e15.chapterId, localPageIndex: e15.localPageIndex, width: t3.width, height: t3.height, offsetTop: this.offsets[o], isPlaceholder: a4 });
|
|
745
750
|
}
|
|
746
|
-
return { totalHeight: this.totalHeight, totalWidth: this.totalWidth || this.config.placeholderPageWidth, items:
|
|
751
|
+
return { totalHeight: this.totalHeight, totalWidth: this.totalWidth || this.config.placeholderPageWidth, items: i2, pageGap: this.config.pageGap };
|
|
747
752
|
}
|
|
748
753
|
scrollToIndex(e14, t2) {
|
|
749
754
|
if (!this.viewportEl || e14 < 0 || e14 >= this.offsets.length) return;
|
|
@@ -753,11 +758,11 @@ const We = class extends BasePlugin {
|
|
|
753
758
|
scrollToGlobalPdfPoint(e14, t2, a3) {
|
|
754
759
|
var s9;
|
|
755
760
|
if (!this.viewportEl || e14 < 0 || e14 >= this.offsets.length || !this.virtualPageMap) return;
|
|
756
|
-
const
|
|
761
|
+
const i2 = (null == a3 ? void 0 : a3.marginTop) ?? 80, o = this.virtualPageMap.atIndex(e14);
|
|
757
762
|
if (!o) return void this.scrollToIndex(e14, a3);
|
|
758
763
|
const r2 = this.pageSizes.get(e14), n2 = null == (s9 = this.documentManager.provides().getDocument(o.chapterId)) ? void 0 : s9.pages[o.localPageIndex];
|
|
759
764
|
if (!r2 || !n2) return void this.scrollToIndex(e14, a3);
|
|
760
|
-
const l = r2.height / n2.size.height, h2 = (this.offsets[e14] ?? 0) + t2 * l -
|
|
765
|
+
const l = r2.height / n2.size.height, h2 = (this.offsets[e14] ?? 0) + t2 * l - i2;
|
|
761
766
|
this.viewportEl.scrollTo({ top: Math.max(0, h2), behavior: (null == a3 ? void 0 : a3.behavior) ?? "auto" });
|
|
762
767
|
}
|
|
763
768
|
scrollToChapter(e14, t2) {
|
|
@@ -771,12 +776,12 @@ const We = class extends BasePlugin {
|
|
|
771
776
|
a3 && this.scrollToIndex(a3.globalPageIndex, t2);
|
|
772
777
|
}
|
|
773
778
|
};
|
|
774
|
-
|
|
775
|
-
let
|
|
776
|
-
const
|
|
779
|
+
Qe.id = "chapter-scroll";
|
|
780
|
+
let Je = Qe;
|
|
781
|
+
const et$1 = { manifest: We, create: (e14) => new Je(qe, e14), reducer: (e14) => e14, initialState: {} }, tt$1 = "note", at$1 = { id: tt$1, name: "Note Plugin", version: "0.1.0", provides: ["note"], requires: ["selection", "chapter-scroll", "chapter-manager"], optional: [], defaultConfig: { callbacks: { onCreateNote: async () => null, onActivateNote: () => {
|
|
777
782
|
} }, markerSize: 18 } };
|
|
778
|
-
const
|
|
779
|
-
function
|
|
783
|
+
const st$1 = { kind: "first-wins" };
|
|
784
|
+
function it$1(e14, t2, a3) {
|
|
780
785
|
if (1 === t2.length) return t2[0].chapterId;
|
|
781
786
|
switch (a3.kind) {
|
|
782
787
|
case "first-wins":
|
|
@@ -794,7 +799,7 @@ function Ke(e14, t2, a3) {
|
|
|
794
799
|
return a3.resolve(e14, t2);
|
|
795
800
|
}
|
|
796
801
|
}
|
|
797
|
-
let
|
|
802
|
+
let ot$1 = class ot {
|
|
798
803
|
constructor(e14) {
|
|
799
804
|
this._pages = e14, this._byChapter = /* @__PURE__ */ new Map(), this._byGlobalNumber = /* @__PURE__ */ new Map();
|
|
800
805
|
for (const t2 of e14) {
|
|
@@ -828,37 +833,37 @@ let Xe = class {
|
|
|
828
833
|
return a3 ? this._pages.indexOf(a3) : -1;
|
|
829
834
|
}
|
|
830
835
|
};
|
|
831
|
-
function
|
|
832
|
-
const a3 = (function(e15, t3 =
|
|
836
|
+
function rt$1(e14, t2 = st$1) {
|
|
837
|
+
const a3 = (function(e15, t3 = st$1) {
|
|
833
838
|
const a4 = /* @__PURE__ */ new Map();
|
|
834
|
-
for (const
|
|
835
|
-
const [e16, t4] =
|
|
839
|
+
for (const i3 of e15.chapters) {
|
|
840
|
+
const [e16, t4] = i3.globalPageRange;
|
|
836
841
|
for (let s11 = e16; s11 <= t4; s11++) {
|
|
837
842
|
const e17 = a4.get(s11);
|
|
838
|
-
e17 ? e17.push(
|
|
843
|
+
e17 ? e17.push(i3) : a4.set(s11, [i3]);
|
|
839
844
|
}
|
|
840
845
|
}
|
|
841
846
|
const s10 = /* @__PURE__ */ new Map();
|
|
842
|
-
for (const [
|
|
847
|
+
for (const [i3, o2] of a4) s10.set(i3, it$1(i3, o2, t3));
|
|
843
848
|
return s10;
|
|
844
849
|
})(e14, t2), s9 = /* @__PURE__ */ new Map();
|
|
845
850
|
for (const n2 of e14.chapters) s9.set(n2.chapterId, n2);
|
|
846
|
-
const
|
|
851
|
+
const i2 = Array.from(a3.keys()).sort((e15, t3) => e15 - t3), o = [];
|
|
847
852
|
let r2 = 0;
|
|
848
|
-
for (const n2 of
|
|
853
|
+
for (const n2 of i2) {
|
|
849
854
|
const e15 = a3.get(n2), t3 = s9.get(e15);
|
|
850
855
|
if (!t3) continue;
|
|
851
|
-
const [
|
|
856
|
+
const [i3] = t3.globalPageRange, [l] = t3.localPageRange, h2 = l + (n2 - i3);
|
|
852
857
|
o.push({ globalPageIndex: r2++, globalPageNumber: n2, chapterId: e15, localPageIndex: h2 });
|
|
853
858
|
}
|
|
854
|
-
return new
|
|
859
|
+
return new ot$1(o);
|
|
855
860
|
}
|
|
856
|
-
const
|
|
861
|
+
const nt$1 = class e3 extends BasePlugin {
|
|
857
862
|
constructor(e14, t2) {
|
|
858
|
-
super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy =
|
|
863
|
+
super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = st$1, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingLoadPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
|
|
859
864
|
}
|
|
860
865
|
async initialize(e14) {
|
|
861
|
-
if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ??
|
|
866
|
+
if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? st$1, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
|
|
862
867
|
this.isOwnedChapter(e15.id) && (this.passwordAttempts.delete(e15.id), this.updateStatus(e15.id, "loaded"));
|
|
863
868
|
}), this.documentManager.provides().onDocumentClosed((e15) => {
|
|
864
869
|
this.isOwnedChapter(e15) && this.updateStatus(e15, "closed");
|
|
@@ -884,16 +889,16 @@ const Je = class e3 extends BasePlugin {
|
|
|
884
889
|
const t3 = [], a4 = /* @__PURE__ */ new Set();
|
|
885
890
|
for (const s10 of e14.chapters) {
|
|
886
891
|
a4.has(s10.chapterId) && t3.push(`Duplicate chapterId: ${s10.chapterId}`), a4.add(s10.chapterId);
|
|
887
|
-
const [e15,
|
|
888
|
-
if (e15 >
|
|
892
|
+
const [e15, i3] = s10.globalPageRange, [o, r2] = s10.localPageRange;
|
|
893
|
+
if (e15 > i3 && t3.push(`${s10.chapterId}: invalid globalPageRange [${e15},${i3}]`), o > r2 && t3.push(`${s10.chapterId}: invalid localPageRange [${o},${r2}]`), i3 - e15 !== r2 - o && t3.push(`${s10.chapterId}: page-count mismatch (global ${i3 - e15 + 1} vs local ${r2 - o + 1})`), s10.ownedGlobalPages) for (const a5 of s10.ownedGlobalPages) (a5 < e15 || a5 > i3) && t3.push(`${s10.chapterId}: ownedGlobalPages contains ${a5} outside range`);
|
|
889
894
|
}
|
|
890
895
|
return t3;
|
|
891
896
|
})(t2);
|
|
892
897
|
a3.length > 0 && this.logger.warn(e3.id, "ManifestValidation", `Chapter manifest has issues: ${a3.join("; ")}`);
|
|
893
|
-
const s9 = new Set(this.chapterStatus.keys()),
|
|
894
|
-
for (const e14 of s9)
|
|
898
|
+
const s9 = new Set(this.chapterStatus.keys()), i2 = new Set(t2.chapters.map((e14) => e14.chapterId));
|
|
899
|
+
for (const e14 of s9) i2.has(e14) || (this.closeChapter(e14), this.chapterStatus.delete(e14));
|
|
895
900
|
for (const e14 of t2.chapters) this.chapterStatus.has(e14.chapterId) || this.chapterStatus.set(e14.chapterId, "idle");
|
|
896
|
-
this.manifest = t2, this.virtualPageMap =
|
|
901
|
+
this.manifest = t2, this.virtualPageMap = rt$1(t2, this.overlapStrategy), this.manifestChange$.emit({ manifest: t2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
|
|
897
902
|
}
|
|
898
903
|
eagerPrefetchFromManifest() {
|
|
899
904
|
const e14 = this.config.prefetchChapters ?? 0;
|
|
@@ -920,20 +925,20 @@ const Je = class e3 extends BasePlugin {
|
|
|
920
925
|
e15 && s9.add(e15.chapterId);
|
|
921
926
|
}
|
|
922
927
|
if (0 === s9.size) return;
|
|
923
|
-
const
|
|
928
|
+
const i2 = this.manifest.chapters.map((e15) => e15.chapterId), o = /* @__PURE__ */ new Set();
|
|
924
929
|
for (const n2 of s9) {
|
|
925
|
-
const e15 =
|
|
926
|
-
if (-1 !== e15) for (let t3 = e15 - a3; t3 <= e15 + a3; t3++) t3 >= 0 && t3 <
|
|
930
|
+
const e15 = i2.indexOf(n2);
|
|
931
|
+
if (-1 !== e15) for (let t3 = e15 - a3; t3 <= e15 + a3; t3++) t3 >= 0 && t3 < i2.length && o.add(t3);
|
|
927
932
|
}
|
|
928
933
|
const r2 = /* @__PURE__ */ new Set();
|
|
929
|
-
for (const n2 of o) r2.add(
|
|
934
|
+
for (const n2 of o) r2.add(i2[n2]);
|
|
930
935
|
for (const n2 of r2) {
|
|
931
936
|
this.chapterLastUsed.set(n2, t2);
|
|
932
937
|
const e15 = this.chapterStatus.get(n2) ?? "idle";
|
|
933
938
|
"idle" !== e15 && "closed" !== e15 && "error" !== e15 || this.ensureChapterLoaded(n2);
|
|
934
939
|
}
|
|
935
940
|
if (this.config.autoActivateOnLoad ?? 1) {
|
|
936
|
-
const e15 =
|
|
941
|
+
const e15 = i2.find((e16) => s9.has(e16));
|
|
937
942
|
if (e15 && this.documentManager.provides().isDocumentOpen(e15)) {
|
|
938
943
|
this.documentManager.provides().getActiveDocumentId() !== e15 && this.documentManager.provides().setActiveDocument(e15);
|
|
939
944
|
}
|
|
@@ -956,10 +961,10 @@ const Je = class e3 extends BasePlugin {
|
|
|
956
961
|
const s9 = this.chapterStatus.get(e14) ?? "idle";
|
|
957
962
|
if ("loaded" === s9) return this.chapterLastUsed.set(e14, Date.now()), Promise.resolve("loaded");
|
|
958
963
|
if ("loading" === s9) return this.waitForTerminalStatus(e14);
|
|
959
|
-
const
|
|
964
|
+
const i2 = this.startLoad(a3).finally(() => {
|
|
960
965
|
this.pendingLoadPromises.delete(e14);
|
|
961
966
|
});
|
|
962
|
-
return this.pendingLoadPromises.set(e14,
|
|
967
|
+
return this.pendingLoadPromises.set(e14, i2), i2;
|
|
963
968
|
}
|
|
964
969
|
async resolvePdfPayload(e14) {
|
|
965
970
|
const t2 = e14.source;
|
|
@@ -977,17 +982,17 @@ const Je = class e3 extends BasePlugin {
|
|
|
977
982
|
const s9 = t2.chapterId;
|
|
978
983
|
this.updateStatus(s9, "loading"), this.chapterLastUsed.set(s9, Date.now());
|
|
979
984
|
try {
|
|
980
|
-
const e14 = t2.encrypted && (null == (a3 = this.passwordProvider) ? void 0 : a3.getCachedPassword) ? this.passwordProvider.getCachedPassword(s9) : null,
|
|
985
|
+
const e14 = t2.encrypted && (null == (a3 = this.passwordProvider) ? void 0 : a3.getCachedPassword) ? this.passwordProvider.getCachedPassword(s9) : null, i2 = await this.resolvePdfPayload(t2), o = this.documentManager.provides(), r2 = "url" in i2 ? o.openDocumentUrl({ documentId: s9, url: i2.url, name: t2.title, password: e14 ?? void 0, autoActivate: false }) : o.openDocumentBuffer({ documentId: s9, buffer: i2.buffer, name: t2.title, password: e14 ?? void 0, autoActivate: false }), n2 = await new Promise((e15, t3) => {
|
|
981
986
|
r2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
982
987
|
});
|
|
983
988
|
return await new Promise((e15, t3) => {
|
|
984
989
|
n2.task.wait(() => e15(), (e16) => t3(e16));
|
|
985
990
|
}), o.isDocumentOpen(s9) && this.updateStatus(s9, "loaded"), this.waitForTerminalStatus(s9);
|
|
986
|
-
} catch (
|
|
991
|
+
} catch (i2) {
|
|
987
992
|
const t3 = this.chapterStatus.get(s9);
|
|
988
993
|
if ("loaded" !== t3 && "password-required" !== t3) {
|
|
989
|
-
const t4 =
|
|
990
|
-
this.logger.error(e3.id, "LoadChapter", t4,
|
|
994
|
+
const t4 = i2 instanceof Error ? i2.message : `Failed to load chapter "${s9}"`;
|
|
995
|
+
this.logger.error(e3.id, "LoadChapter", t4, i2), this.updateStatus(s9, "error", t4);
|
|
991
996
|
}
|
|
992
997
|
return this.chapterStatus.get(s9) ?? "error";
|
|
993
998
|
}
|
|
@@ -1005,13 +1010,13 @@ const Je = class e3 extends BasePlugin {
|
|
|
1005
1010
|
async handleDocumentError(t2, a3, s9) {
|
|
1006
1011
|
if (a3 !== PdfErrorCode.Password) return void this.updateStatus(t2, "error");
|
|
1007
1012
|
if (!this.passwordProvider) return void this.updateStatus(t2, "password-required");
|
|
1008
|
-
const
|
|
1009
|
-
if (!
|
|
1013
|
+
const i2 = this.findChapter(t2);
|
|
1014
|
+
if (!i2) return;
|
|
1010
1015
|
const o = (this.passwordAttempts.get(t2) ?? 0) + 1;
|
|
1011
1016
|
this.passwordAttempts.set(t2, o);
|
|
1012
1017
|
let r2 = null;
|
|
1013
1018
|
try {
|
|
1014
|
-
r2 = await this.passwordProvider.resolvePassword(
|
|
1019
|
+
r2 = await this.passwordProvider.resolvePassword(i2, o - 1);
|
|
1015
1020
|
} catch (n2) {
|
|
1016
1021
|
this.logger.error(e3.id, "PasswordProvider", `Provider rejected for ${t2}`, n2);
|
|
1017
1022
|
}
|
|
@@ -1031,10 +1036,10 @@ const Je = class e3 extends BasePlugin {
|
|
|
1031
1036
|
this.chapterStatus.get(e14) !== t2 && (this.chapterStatus.set(e14, t2), this.statusChange$.emit({ chapterId: e14, status: t2, ..."error" === t2 && a3 ? { error: { message: a3 } } : {} }));
|
|
1032
1037
|
}
|
|
1033
1038
|
};
|
|
1034
|
-
|
|
1035
|
-
let
|
|
1036
|
-
const
|
|
1037
|
-
function
|
|
1039
|
+
nt$1.id = "chapter-manager";
|
|
1040
|
+
let lt$1 = nt$1;
|
|
1041
|
+
const ht$1 = { kind: "first-wins" };
|
|
1042
|
+
function dt$1(e14, t2, a3) {
|
|
1038
1043
|
if (1 === t2.length) return t2[0].chapterId;
|
|
1039
1044
|
switch (a3.kind) {
|
|
1040
1045
|
case "first-wins":
|
|
@@ -1052,7 +1057,7 @@ function at$1(e14, t2, a3) {
|
|
|
1052
1057
|
return a3.resolve(e14, t2);
|
|
1053
1058
|
}
|
|
1054
1059
|
}
|
|
1055
|
-
let
|
|
1060
|
+
let ct$1 = class ct {
|
|
1056
1061
|
constructor(e14) {
|
|
1057
1062
|
this._pages = e14, this._byChapter = /* @__PURE__ */ new Map(), this._byGlobalNumber = /* @__PURE__ */ new Map();
|
|
1058
1063
|
for (const t2 of e14) {
|
|
@@ -1086,37 +1091,37 @@ let st$1 = class st {
|
|
|
1086
1091
|
return a3 ? this._pages.indexOf(a3) : -1;
|
|
1087
1092
|
}
|
|
1088
1093
|
};
|
|
1089
|
-
function
|
|
1090
|
-
const a3 = (function(e15, t3 =
|
|
1094
|
+
function ut(e14, t2 = ht$1) {
|
|
1095
|
+
const a3 = (function(e15, t3 = ht$1) {
|
|
1091
1096
|
const a4 = /* @__PURE__ */ new Map();
|
|
1092
|
-
for (const
|
|
1093
|
-
const [e16, t4] =
|
|
1097
|
+
for (const i3 of e15.chapters) {
|
|
1098
|
+
const [e16, t4] = i3.globalPageRange;
|
|
1094
1099
|
for (let s11 = e16; s11 <= t4; s11++) {
|
|
1095
1100
|
const e17 = a4.get(s11);
|
|
1096
|
-
e17 ? e17.push(
|
|
1101
|
+
e17 ? e17.push(i3) : a4.set(s11, [i3]);
|
|
1097
1102
|
}
|
|
1098
1103
|
}
|
|
1099
1104
|
const s10 = /* @__PURE__ */ new Map();
|
|
1100
|
-
for (const [
|
|
1105
|
+
for (const [i3, o2] of a4) s10.set(i3, dt$1(i3, o2, t3));
|
|
1101
1106
|
return s10;
|
|
1102
1107
|
})(e14, t2), s9 = /* @__PURE__ */ new Map();
|
|
1103
1108
|
for (const n2 of e14.chapters) s9.set(n2.chapterId, n2);
|
|
1104
|
-
const
|
|
1109
|
+
const i2 = Array.from(a3.keys()).sort((e15, t3) => e15 - t3), o = [];
|
|
1105
1110
|
let r2 = 0;
|
|
1106
|
-
for (const n2 of
|
|
1111
|
+
for (const n2 of i2) {
|
|
1107
1112
|
const e15 = a3.get(n2), t3 = s9.get(e15);
|
|
1108
1113
|
if (!t3) continue;
|
|
1109
|
-
const [
|
|
1114
|
+
const [i3] = t3.globalPageRange, [l] = t3.localPageRange, h2 = l + (n2 - i3);
|
|
1110
1115
|
o.push({ globalPageIndex: r2++, globalPageNumber: n2, chapterId: e15, localPageIndex: h2 });
|
|
1111
1116
|
}
|
|
1112
|
-
return new
|
|
1117
|
+
return new ct$1(o);
|
|
1113
1118
|
}
|
|
1114
|
-
const
|
|
1119
|
+
const pt = class e4 extends BasePlugin {
|
|
1115
1120
|
constructor(e14, t2) {
|
|
1116
|
-
super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy =
|
|
1121
|
+
super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = ht$1, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingLoadPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
|
|
1117
1122
|
}
|
|
1118
1123
|
async initialize(e14) {
|
|
1119
|
-
if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ??
|
|
1124
|
+
if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? ht$1, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
|
|
1120
1125
|
this.isOwnedChapter(e15.id) && (this.passwordAttempts.delete(e15.id), this.updateStatus(e15.id, "loaded"));
|
|
1121
1126
|
}), this.documentManager.provides().onDocumentClosed((e15) => {
|
|
1122
1127
|
this.isOwnedChapter(e15) && this.updateStatus(e15, "closed");
|
|
@@ -1142,16 +1147,16 @@ const ot$1 = class e4 extends BasePlugin {
|
|
|
1142
1147
|
const t3 = [], a4 = /* @__PURE__ */ new Set();
|
|
1143
1148
|
for (const s10 of e14.chapters) {
|
|
1144
1149
|
a4.has(s10.chapterId) && t3.push(`Duplicate chapterId: ${s10.chapterId}`), a4.add(s10.chapterId);
|
|
1145
|
-
const [e15,
|
|
1146
|
-
if (e15 >
|
|
1150
|
+
const [e15, i3] = s10.globalPageRange, [o, r2] = s10.localPageRange;
|
|
1151
|
+
if (e15 > i3 && t3.push(`${s10.chapterId}: invalid globalPageRange [${e15},${i3}]`), o > r2 && t3.push(`${s10.chapterId}: invalid localPageRange [${o},${r2}]`), i3 - e15 !== r2 - o && t3.push(`${s10.chapterId}: page-count mismatch (global ${i3 - e15 + 1} vs local ${r2 - o + 1})`), s10.ownedGlobalPages) for (const a5 of s10.ownedGlobalPages) (a5 < e15 || a5 > i3) && t3.push(`${s10.chapterId}: ownedGlobalPages contains ${a5} outside range`);
|
|
1147
1152
|
}
|
|
1148
1153
|
return t3;
|
|
1149
1154
|
})(t2);
|
|
1150
1155
|
a3.length > 0 && this.logger.warn(e4.id, "ManifestValidation", `Chapter manifest has issues: ${a3.join("; ")}`);
|
|
1151
|
-
const s9 = new Set(this.chapterStatus.keys()),
|
|
1152
|
-
for (const e14 of s9)
|
|
1156
|
+
const s9 = new Set(this.chapterStatus.keys()), i2 = new Set(t2.chapters.map((e14) => e14.chapterId));
|
|
1157
|
+
for (const e14 of s9) i2.has(e14) || (this.closeChapter(e14), this.chapterStatus.delete(e14));
|
|
1153
1158
|
for (const e14 of t2.chapters) this.chapterStatus.has(e14.chapterId) || this.chapterStatus.set(e14.chapterId, "idle");
|
|
1154
|
-
this.manifest = t2, this.virtualPageMap =
|
|
1159
|
+
this.manifest = t2, this.virtualPageMap = ut(t2, this.overlapStrategy), this.manifestChange$.emit({ manifest: t2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
|
|
1155
1160
|
}
|
|
1156
1161
|
eagerPrefetchFromManifest() {
|
|
1157
1162
|
const e14 = this.config.prefetchChapters ?? 0;
|
|
@@ -1178,20 +1183,20 @@ const ot$1 = class e4 extends BasePlugin {
|
|
|
1178
1183
|
e15 && s9.add(e15.chapterId);
|
|
1179
1184
|
}
|
|
1180
1185
|
if (0 === s9.size) return;
|
|
1181
|
-
const
|
|
1186
|
+
const i2 = this.manifest.chapters.map((e15) => e15.chapterId), o = /* @__PURE__ */ new Set();
|
|
1182
1187
|
for (const n2 of s9) {
|
|
1183
|
-
const e15 =
|
|
1184
|
-
if (-1 !== e15) for (let t3 = e15 - a3; t3 <= e15 + a3; t3++) t3 >= 0 && t3 <
|
|
1188
|
+
const e15 = i2.indexOf(n2);
|
|
1189
|
+
if (-1 !== e15) for (let t3 = e15 - a3; t3 <= e15 + a3; t3++) t3 >= 0 && t3 < i2.length && o.add(t3);
|
|
1185
1190
|
}
|
|
1186
1191
|
const r2 = /* @__PURE__ */ new Set();
|
|
1187
|
-
for (const n2 of o) r2.add(
|
|
1192
|
+
for (const n2 of o) r2.add(i2[n2]);
|
|
1188
1193
|
for (const n2 of r2) {
|
|
1189
1194
|
this.chapterLastUsed.set(n2, t2);
|
|
1190
1195
|
const e15 = this.chapterStatus.get(n2) ?? "idle";
|
|
1191
1196
|
"idle" !== e15 && "closed" !== e15 && "error" !== e15 || this.ensureChapterLoaded(n2);
|
|
1192
1197
|
}
|
|
1193
1198
|
if (this.config.autoActivateOnLoad ?? 1) {
|
|
1194
|
-
const e15 =
|
|
1199
|
+
const e15 = i2.find((e16) => s9.has(e16));
|
|
1195
1200
|
if (e15 && this.documentManager.provides().isDocumentOpen(e15)) {
|
|
1196
1201
|
this.documentManager.provides().getActiveDocumentId() !== e15 && this.documentManager.provides().setActiveDocument(e15);
|
|
1197
1202
|
}
|
|
@@ -1214,10 +1219,10 @@ const ot$1 = class e4 extends BasePlugin {
|
|
|
1214
1219
|
const s9 = this.chapterStatus.get(e14) ?? "idle";
|
|
1215
1220
|
if ("loaded" === s9) return this.chapterLastUsed.set(e14, Date.now()), Promise.resolve("loaded");
|
|
1216
1221
|
if ("loading" === s9) return this.waitForTerminalStatus(e14);
|
|
1217
|
-
const
|
|
1222
|
+
const i2 = this.startLoad(a3).finally(() => {
|
|
1218
1223
|
this.pendingLoadPromises.delete(e14);
|
|
1219
1224
|
});
|
|
1220
|
-
return this.pendingLoadPromises.set(e14,
|
|
1225
|
+
return this.pendingLoadPromises.set(e14, i2), i2;
|
|
1221
1226
|
}
|
|
1222
1227
|
async resolvePdfPayload(e14) {
|
|
1223
1228
|
const t2 = e14.source;
|
|
@@ -1235,17 +1240,17 @@ const ot$1 = class e4 extends BasePlugin {
|
|
|
1235
1240
|
const s9 = t2.chapterId;
|
|
1236
1241
|
this.updateStatus(s9, "loading"), this.chapterLastUsed.set(s9, Date.now());
|
|
1237
1242
|
try {
|
|
1238
|
-
const e14 = t2.encrypted && (null == (a3 = this.passwordProvider) ? void 0 : a3.getCachedPassword) ? this.passwordProvider.getCachedPassword(s9) : null,
|
|
1243
|
+
const e14 = t2.encrypted && (null == (a3 = this.passwordProvider) ? void 0 : a3.getCachedPassword) ? this.passwordProvider.getCachedPassword(s9) : null, i2 = await this.resolvePdfPayload(t2), o = this.documentManager.provides(), r2 = "url" in i2 ? o.openDocumentUrl({ documentId: s9, url: i2.url, name: t2.title, password: e14 ?? void 0, autoActivate: false }) : o.openDocumentBuffer({ documentId: s9, buffer: i2.buffer, name: t2.title, password: e14 ?? void 0, autoActivate: false }), n2 = await new Promise((e15, t3) => {
|
|
1239
1244
|
r2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
1240
1245
|
});
|
|
1241
1246
|
return await new Promise((e15, t3) => {
|
|
1242
1247
|
n2.task.wait(() => e15(), (e16) => t3(e16));
|
|
1243
1248
|
}), o.isDocumentOpen(s9) && this.updateStatus(s9, "loaded"), this.waitForTerminalStatus(s9);
|
|
1244
|
-
} catch (
|
|
1249
|
+
} catch (i2) {
|
|
1245
1250
|
const t3 = this.chapterStatus.get(s9);
|
|
1246
1251
|
if ("loaded" !== t3 && "password-required" !== t3) {
|
|
1247
|
-
const t4 =
|
|
1248
|
-
this.logger.error(e4.id, "LoadChapter", t4,
|
|
1252
|
+
const t4 = i2 instanceof Error ? i2.message : `Failed to load chapter "${s9}"`;
|
|
1253
|
+
this.logger.error(e4.id, "LoadChapter", t4, i2), this.updateStatus(s9, "error", t4);
|
|
1249
1254
|
}
|
|
1250
1255
|
return this.chapterStatus.get(s9) ?? "error";
|
|
1251
1256
|
}
|
|
@@ -1263,13 +1268,13 @@ const ot$1 = class e4 extends BasePlugin {
|
|
|
1263
1268
|
async handleDocumentError(t2, a3, s9) {
|
|
1264
1269
|
if (a3 !== PdfErrorCode.Password) return void this.updateStatus(t2, "error");
|
|
1265
1270
|
if (!this.passwordProvider) return void this.updateStatus(t2, "password-required");
|
|
1266
|
-
const
|
|
1267
|
-
if (!
|
|
1271
|
+
const i2 = this.findChapter(t2);
|
|
1272
|
+
if (!i2) return;
|
|
1268
1273
|
const o = (this.passwordAttempts.get(t2) ?? 0) + 1;
|
|
1269
1274
|
this.passwordAttempts.set(t2, o);
|
|
1270
1275
|
let r2 = null;
|
|
1271
1276
|
try {
|
|
1272
|
-
r2 = await this.passwordProvider.resolvePassword(
|
|
1277
|
+
r2 = await this.passwordProvider.resolvePassword(i2, o - 1);
|
|
1273
1278
|
} catch (n2) {
|
|
1274
1279
|
this.logger.error(e4.id, "PasswordProvider", `Provider rejected for ${t2}`, n2);
|
|
1275
1280
|
}
|
|
@@ -1289,20 +1294,20 @@ const ot$1 = class e4 extends BasePlugin {
|
|
|
1289
1294
|
this.chapterStatus.get(e14) !== t2 && (this.chapterStatus.set(e14, t2), this.statusChange$.emit({ chapterId: e14, status: t2, ..."error" === t2 && a3 ? { error: { message: a3 } } : {} }));
|
|
1290
1295
|
}
|
|
1291
1296
|
};
|
|
1292
|
-
|
|
1293
|
-
let
|
|
1294
|
-
function
|
|
1297
|
+
pt.id = "chapter-manager";
|
|
1298
|
+
let gt = pt;
|
|
1299
|
+
function ft$1(e14, t2) {
|
|
1295
1300
|
if (e14 === t2) return true;
|
|
1296
1301
|
if (e14.totalHeight !== t2.totalHeight || e14.totalWidth !== t2.totalWidth || e14.pageGap !== t2.pageGap || e14.items.length !== t2.items.length) return false;
|
|
1297
1302
|
for (let a3 = 0; a3 < e14.items.length; a3++) {
|
|
1298
|
-
const s9 = e14.items[a3],
|
|
1299
|
-
if (s9.globalPageIndex !==
|
|
1303
|
+
const s9 = e14.items[a3], i2 = t2.items[a3];
|
|
1304
|
+
if (s9.globalPageIndex !== i2.globalPageIndex || s9.isPlaceholder !== i2.isPlaceholder || s9.chapterId !== i2.chapterId || s9.localPageIndex !== i2.localPageIndex || s9.offsetTop !== i2.offsetTop || s9.width !== i2.width || s9.height !== i2.height) return false;
|
|
1300
1305
|
}
|
|
1301
1306
|
return true;
|
|
1302
1307
|
}
|
|
1303
|
-
const
|
|
1308
|
+
const mt$1 = class mt extends BasePlugin {
|
|
1304
1309
|
constructor(e14, t2) {
|
|
1305
|
-
super(e14, t2), this.layoutChange$ = createBehaviorEmitter(void 0,
|
|
1310
|
+
super(e14, t2), this.layoutChange$ = createBehaviorEmitter(void 0, ft$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.chapterManagerUnsubs = [], this.chapterManager = this.registry.getPlugin(gt.id), this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
|
|
1306
1311
|
}
|
|
1307
1312
|
async initialize(e14) {
|
|
1308
1313
|
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 }) => {
|
|
@@ -1356,8 +1361,8 @@ const lt$1 = class lt extends BasePlugin {
|
|
|
1356
1361
|
this.offsets = new Array(e14);
|
|
1357
1362
|
let t2 = 0, a3 = 0;
|
|
1358
1363
|
for (let s9 = 0; s9 < e14; s9++) {
|
|
1359
|
-
const { width: e15, height:
|
|
1360
|
-
this.offsets[s9] = t2, t2 +=
|
|
1364
|
+
const { width: e15, height: i2 } = this.getPageSize(s9);
|
|
1365
|
+
this.offsets[s9] = t2, t2 += i2 + this.config.pageGap, e15 > a3 && (a3 = e15);
|
|
1361
1366
|
}
|
|
1362
1367
|
this.totalHeight = e14 > 0 ? t2 - this.config.pageGap : 0, this.totalWidth = a3, this.layoutChange$.emit(this.computeLayout());
|
|
1363
1368
|
}
|
|
@@ -1367,8 +1372,8 @@ const lt$1 = class lt extends BasePlugin {
|
|
|
1367
1372
|
for (const s9 of t2) {
|
|
1368
1373
|
const t3 = this.virtualPageMap.toGlobal(e14, s9.localPageIndex);
|
|
1369
1374
|
if (!t3) continue;
|
|
1370
|
-
const
|
|
1371
|
-
|
|
1375
|
+
const i2 = this.pageSizes.get(t3.globalPageIndex);
|
|
1376
|
+
i2 && i2.width === s9.width && i2.height === s9.height || (this.pageSizes.set(t3.globalPageIndex, { width: s9.width, height: s9.height }), a3 = true);
|
|
1372
1377
|
}
|
|
1373
1378
|
if (a3) {
|
|
1374
1379
|
const e15 = this.currentGlobalPageIndex, t3 = this.offsets[e15] ?? 0;
|
|
@@ -1386,10 +1391,10 @@ const lt$1 = class lt extends BasePlugin {
|
|
|
1386
1391
|
harvestChapterSizes(e14, t2 = 0) {
|
|
1387
1392
|
var a3;
|
|
1388
1393
|
if (!this.virtualPageMap) return;
|
|
1389
|
-
const s9 = this.documentManager.provides().getDocument(e14),
|
|
1390
|
-
if (!(null == (a3 = null == s9 ? void 0 : s9.pages) ? void 0 : a3.length) || 0 ===
|
|
1394
|
+
const s9 = this.documentManager.provides().getDocument(e14), i2 = this.virtualPageMap.pagesOfChapter(e14);
|
|
1395
|
+
if (!(null == (a3 = null == s9 ? void 0 : s9.pages) ? void 0 : a3.length) || 0 === i2.length) return void (t2 < 60 && requestAnimationFrame(() => this.harvestChapterSizes(e14, t2 + 1)));
|
|
1391
1396
|
const o = this.getChapterDocumentScale(e14), r2 = [];
|
|
1392
|
-
for (const n2 of
|
|
1397
|
+
for (const n2 of i2) {
|
|
1393
1398
|
const e15 = s9.pages[n2.localPageIndex];
|
|
1394
1399
|
(null == e15 ? void 0 : e15.size) && r2.push({ localPageIndex: n2.localPageIndex, width: e15.size.width * o, height: e15.size.height * o });
|
|
1395
1400
|
}
|
|
@@ -1420,38 +1425,38 @@ const lt$1 = class lt extends BasePlugin {
|
|
|
1420
1425
|
const e14 = this.virtualPageMap.totalPages;
|
|
1421
1426
|
if (0 === e14) return this.currentVisible = [], this.currentGlobalPageIndex = 0, void this.layoutChange$.emit(this.computeLayout());
|
|
1422
1427
|
const t2 = this.viewportEl.scrollTop, a3 = t2 + this.viewportEl.clientHeight, s9 = this.findFirstVisibleIndex(t2);
|
|
1423
|
-
let
|
|
1424
|
-
for (;
|
|
1425
|
-
const e15 = this.getPageSize(
|
|
1428
|
+
let i2 = s9;
|
|
1429
|
+
for (; i2 < e14; ) {
|
|
1430
|
+
const e15 = this.getPageSize(i2), t3 = this.offsets[i2];
|
|
1426
1431
|
if (e15.height, t3 >= a3) break;
|
|
1427
|
-
|
|
1432
|
+
i2++;
|
|
1428
1433
|
}
|
|
1429
1434
|
const o = [];
|
|
1430
1435
|
let r2 = s9, n2 = -1;
|
|
1431
|
-
for (let l = s9; l <
|
|
1436
|
+
for (let l = s9; l < i2; l++) {
|
|
1432
1437
|
o.push(l);
|
|
1433
|
-
const e15 = this.offsets[l], s10 = e15 + this.getPageSize(l).height,
|
|
1434
|
-
|
|
1438
|
+
const e15 = this.offsets[l], s10 = e15 + this.getPageSize(l).height, i3 = Math.max(0, Math.min(s10, a3) - Math.max(e15, t2));
|
|
1439
|
+
i3 > n2 && (n2 = i3, r2 = l);
|
|
1435
1440
|
}
|
|
1436
1441
|
this.currentVisible = o, this.currentGlobalPageIndex = r2, this.visibleChange$.emit({ visibleGlobalPageIndices: o, currentGlobalPageIndex: r2 }), this.chapterManager.provides().setVisibleGlobalPages(o), this.layoutChange$.emit(this.computeLayout());
|
|
1437
1442
|
}
|
|
1438
1443
|
findFirstVisibleIndex(e14) {
|
|
1439
1444
|
let t2 = 0, a3 = this.offsets.length - 1, s9 = 0;
|
|
1440
1445
|
for (; t2 <= a3; ) {
|
|
1441
|
-
const
|
|
1442
|
-
this.offsets[
|
|
1446
|
+
const i2 = t2 + a3 >> 1;
|
|
1447
|
+
this.offsets[i2] <= e14 ? (s9 = i2, t2 = i2 + 1) : a3 = i2 - 1;
|
|
1443
1448
|
}
|
|
1444
1449
|
return s9;
|
|
1445
1450
|
}
|
|
1446
1451
|
computeLayout() {
|
|
1447
|
-
const e14 = this.config.bufferSize, t2 = Math.max(0, (this.currentVisible[0] ?? 0) - e14), a3 = this.currentVisible[this.currentVisible.length - 1] ?? -1, s9 = Math.min(this.offsets.length - 1, (a3 >= 0 ? a3 : 0) + e14),
|
|
1452
|
+
const e14 = this.config.bufferSize, t2 = Math.max(0, (this.currentVisible[0] ?? 0) - e14), a3 = this.currentVisible[this.currentVisible.length - 1] ?? -1, s9 = Math.min(this.offsets.length - 1, (a3 >= 0 ? a3 : 0) + e14), i2 = [];
|
|
1448
1453
|
if (this.virtualPageMap && this.offsets.length > 0) for (let o = t2; o <= s9; o++) {
|
|
1449
1454
|
const e15 = this.virtualPageMap.atIndex(o);
|
|
1450
1455
|
if (!e15) continue;
|
|
1451
1456
|
const t3 = this.getPageSize(o), a4 = this.isChapterPagePlaceholder(e15.chapterId);
|
|
1452
|
-
|
|
1457
|
+
i2.push({ globalPageIndex: o, globalPageNumber: e15.globalPageNumber, chapterId: e15.chapterId, localPageIndex: e15.localPageIndex, width: t3.width, height: t3.height, offsetTop: this.offsets[o], isPlaceholder: a4 });
|
|
1453
1458
|
}
|
|
1454
|
-
return { totalHeight: this.totalHeight, totalWidth: this.totalWidth || this.config.placeholderPageWidth, items:
|
|
1459
|
+
return { totalHeight: this.totalHeight, totalWidth: this.totalWidth || this.config.placeholderPageWidth, items: i2, pageGap: this.config.pageGap };
|
|
1455
1460
|
}
|
|
1456
1461
|
scrollToIndex(e14, t2) {
|
|
1457
1462
|
if (!this.viewportEl || e14 < 0 || e14 >= this.offsets.length) return;
|
|
@@ -1461,11 +1466,11 @@ const lt$1 = class lt extends BasePlugin {
|
|
|
1461
1466
|
scrollToGlobalPdfPoint(e14, t2, a3) {
|
|
1462
1467
|
var s9;
|
|
1463
1468
|
if (!this.viewportEl || e14 < 0 || e14 >= this.offsets.length || !this.virtualPageMap) return;
|
|
1464
|
-
const
|
|
1469
|
+
const i2 = (null == a3 ? void 0 : a3.marginTop) ?? 80, o = this.virtualPageMap.atIndex(e14);
|
|
1465
1470
|
if (!o) return void this.scrollToIndex(e14, a3);
|
|
1466
1471
|
const r2 = this.pageSizes.get(e14), n2 = null == (s9 = this.documentManager.provides().getDocument(o.chapterId)) ? void 0 : s9.pages[o.localPageIndex];
|
|
1467
1472
|
if (!r2 || !n2) return void this.scrollToIndex(e14, a3);
|
|
1468
|
-
const l = r2.height / n2.size.height, h2 = (this.offsets[e14] ?? 0) + t2 * l -
|
|
1473
|
+
const l = r2.height / n2.size.height, h2 = (this.offsets[e14] ?? 0) + t2 * l - i2;
|
|
1469
1474
|
this.viewportEl.scrollTo({ top: Math.max(0, h2), behavior: (null == a3 ? void 0 : a3.behavior) ?? "auto" });
|
|
1470
1475
|
}
|
|
1471
1476
|
scrollToChapter(e14, t2) {
|
|
@@ -1479,11 +1484,11 @@ const lt$1 = class lt extends BasePlugin {
|
|
|
1479
1484
|
a3 && this.scrollToIndex(a3.globalPageIndex, t2);
|
|
1480
1485
|
}
|
|
1481
1486
|
};
|
|
1482
|
-
|
|
1483
|
-
let
|
|
1484
|
-
const
|
|
1487
|
+
mt$1.id = "chapter-scroll";
|
|
1488
|
+
let vt$1 = mt$1;
|
|
1489
|
+
const bt$1 = class e5 extends BasePlugin {
|
|
1485
1490
|
constructor(e14, t2) {
|
|
1486
|
-
super(e14, t2), this.notesChange$ = createBehaviorEmitter([]), this.noteActivated$ = createEmitter(), this.notes = /* @__PURE__ */ new Map(), this.chapterScroll = this.registry.getPlugin(
|
|
1491
|
+
super(e14, t2), this.notesChange$ = createBehaviorEmitter([]), this.noteActivated$ = createEmitter(), this.notes = /* @__PURE__ */ new Map(), this.chapterScroll = this.registry.getPlugin(vt$1.id), this.chapterManager = this.registry.getPlugin(lt$1.id), this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
|
|
1487
1492
|
}
|
|
1488
1493
|
async initialize(t2) {
|
|
1489
1494
|
if (this.config = t2, t2.callbacks.loadNotes) try {
|
|
@@ -1521,7 +1526,7 @@ const dt$1 = class e5 extends BasePlugin {
|
|
|
1521
1526
|
this.notesChange$.emit(this.listAll());
|
|
1522
1527
|
}
|
|
1523
1528
|
buildDraft(e14) {
|
|
1524
|
-
return { chapterId: e14.chapterId, localPageIndex: e14.localPageIndex, globalPageNumber: e14.globalPageNumber, globalPageIndex: e14.globalPageIndex, rectsPdfCoord: e14.rectsPdfCoord, endAnchor:
|
|
1529
|
+
return { chapterId: e14.chapterId, localPageIndex: e14.localPageIndex, globalPageNumber: e14.globalPageNumber, globalPageIndex: e14.globalPageIndex, rectsPdfCoord: e14.rectsPdfCoord, endAnchor: wt$1(e14.rectsPdfCoord), selectedText: e14.selectedText, content: e14.content };
|
|
1525
1530
|
}
|
|
1526
1531
|
async requestCreateFromSelection(e14) {
|
|
1527
1532
|
if (0 === e14.rectsPdfCoord.length) return null;
|
|
@@ -1535,14 +1540,14 @@ const dt$1 = class e5 extends BasePlugin {
|
|
|
1535
1540
|
if (0 === t2.rectsPdfCoord.length) return null;
|
|
1536
1541
|
const a3 = this.buildDraft(t2), s9 = this.config.callbacks.onCreateNote;
|
|
1537
1542
|
if (!s9) return this.logger.error(e5.id, "CreateNote", "Missing onCreateNote / onRequestCreateNote"), null;
|
|
1538
|
-
let
|
|
1543
|
+
let i2 = null;
|
|
1539
1544
|
try {
|
|
1540
|
-
|
|
1545
|
+
i2 = await s9(a3);
|
|
1541
1546
|
} catch (r2) {
|
|
1542
1547
|
return this.logger.error(e5.id, "OnCreateNote", "Callback failed", r2), null;
|
|
1543
1548
|
}
|
|
1544
|
-
if (!
|
|
1545
|
-
const o = { ...a3, noteId:
|
|
1549
|
+
if (!i2) return null;
|
|
1550
|
+
const o = { ...a3, noteId: i2.noteId };
|
|
1546
1551
|
return this.registerNote(o), o;
|
|
1547
1552
|
}
|
|
1548
1553
|
async deleteNote(t2) {
|
|
@@ -1550,19 +1555,19 @@ const dt$1 = class e5 extends BasePlugin {
|
|
|
1550
1555
|
if (this.notes.has(t2)) {
|
|
1551
1556
|
try {
|
|
1552
1557
|
await (null == (s9 = (a3 = this.config.callbacks).onDeleteNote) ? void 0 : s9.call(a3, t2));
|
|
1553
|
-
} catch (
|
|
1554
|
-
return void this.logger.error(e5.id, "OnDeleteNote", "Callback failed",
|
|
1558
|
+
} catch (i2) {
|
|
1559
|
+
return void this.logger.error(e5.id, "OnDeleteNote", "Callback failed", i2);
|
|
1555
1560
|
}
|
|
1556
1561
|
this.notes.delete(t2), this.notesChange$.emit(this.listAll());
|
|
1557
1562
|
}
|
|
1558
1563
|
}
|
|
1559
1564
|
async updateNoteContent(t2, a3) {
|
|
1560
|
-
var s9,
|
|
1565
|
+
var s9, i2;
|
|
1561
1566
|
const o = this.notes.get(t2);
|
|
1562
1567
|
if (!o) return;
|
|
1563
1568
|
const r2 = { ...o, content: a3 };
|
|
1564
1569
|
try {
|
|
1565
|
-
await (null == (
|
|
1570
|
+
await (null == (i2 = (s9 = this.config.callbacks).onUpdateNote) ? void 0 : i2.call(s9, r2));
|
|
1566
1571
|
} catch (n2) {
|
|
1567
1572
|
return void this.logger.error(e5.id, "OnUpdateNote", "Callback failed", n2);
|
|
1568
1573
|
}
|
|
@@ -1580,23 +1585,23 @@ const dt$1 = class e5 extends BasePlugin {
|
|
|
1580
1585
|
const t2 = this.chapterScroll.provides(), a3 = t2.getLayout().items.find((t3) => t3.globalPageIndex === e14 && !t3.isPlaceholder);
|
|
1581
1586
|
return a3 ? Promise.resolve(a3) : new Promise((a4) => {
|
|
1582
1587
|
const s9 = setTimeout(() => {
|
|
1583
|
-
|
|
1584
|
-
}, 2500),
|
|
1588
|
+
i2(), a4(null);
|
|
1589
|
+
}, 2500), i2 = t2.onLayoutChange((t3) => {
|
|
1585
1590
|
const o = t3.items.find((t4) => t4.globalPageIndex === e14 && !t4.isPlaceholder);
|
|
1586
|
-
o && (clearTimeout(s9),
|
|
1591
|
+
o && (clearTimeout(s9), i2(), a4(o));
|
|
1587
1592
|
});
|
|
1588
1593
|
});
|
|
1589
1594
|
}
|
|
1590
1595
|
};
|
|
1591
|
-
|
|
1592
|
-
let
|
|
1593
|
-
function
|
|
1596
|
+
bt$1.id = "note";
|
|
1597
|
+
let Pt$1 = bt$1;
|
|
1598
|
+
function wt$1(e14) {
|
|
1594
1599
|
const t2 = e14[e14.length - 1];
|
|
1595
1600
|
return { x: t2.origin.x + t2.size.width, y: t2.origin.y + t2.size.height };
|
|
1596
1601
|
}
|
|
1597
|
-
const
|
|
1598
|
-
const
|
|
1599
|
-
function
|
|
1602
|
+
const yt$1 = { manifest: at$1, create: (e14) => new Pt$1(tt$1, e14), reducer: (e14) => e14, initialState: {} }, Ct$1 = "paragraph-bookmark", It$1 = { id: Ct$1, name: "Paragraph Bookmark Plugin", version: "0.1.0", provides: ["paragraph-bookmark"], requires: ["chapter-scroll", "chapter-manager"], optional: [], defaultConfig: {} };
|
|
1603
|
+
const Mt$1 = { kind: "first-wins" };
|
|
1604
|
+
function St$1(e14, t2, a3) {
|
|
1600
1605
|
if (1 === t2.length) return t2[0].chapterId;
|
|
1601
1606
|
switch (a3.kind) {
|
|
1602
1607
|
case "first-wins":
|
|
@@ -1614,7 +1619,7 @@ function vt$1(e14, t2, a3) {
|
|
|
1614
1619
|
return a3.resolve(e14, t2);
|
|
1615
1620
|
}
|
|
1616
1621
|
}
|
|
1617
|
-
let
|
|
1622
|
+
let xt$1 = class xt {
|
|
1618
1623
|
constructor(e14) {
|
|
1619
1624
|
this._pages = e14, this._byChapter = /* @__PURE__ */ new Map(), this._byGlobalNumber = /* @__PURE__ */ new Map();
|
|
1620
1625
|
for (const t2 of e14) {
|
|
@@ -1648,37 +1653,37 @@ let bt$1 = class bt {
|
|
|
1648
1653
|
return a3 ? this._pages.indexOf(a3) : -1;
|
|
1649
1654
|
}
|
|
1650
1655
|
};
|
|
1651
|
-
function
|
|
1652
|
-
const a3 = (function(e15, t3 =
|
|
1656
|
+
function kt$1(e14, t2 = Mt$1) {
|
|
1657
|
+
const a3 = (function(e15, t3 = Mt$1) {
|
|
1653
1658
|
const a4 = /* @__PURE__ */ new Map();
|
|
1654
|
-
for (const
|
|
1655
|
-
const [e16, t4] =
|
|
1659
|
+
for (const i3 of e15.chapters) {
|
|
1660
|
+
const [e16, t4] = i3.globalPageRange;
|
|
1656
1661
|
for (let s11 = e16; s11 <= t4; s11++) {
|
|
1657
1662
|
const e17 = a4.get(s11);
|
|
1658
|
-
e17 ? e17.push(
|
|
1663
|
+
e17 ? e17.push(i3) : a4.set(s11, [i3]);
|
|
1659
1664
|
}
|
|
1660
1665
|
}
|
|
1661
1666
|
const s10 = /* @__PURE__ */ new Map();
|
|
1662
|
-
for (const [
|
|
1667
|
+
for (const [i3, o2] of a4) s10.set(i3, St$1(i3, o2, t3));
|
|
1663
1668
|
return s10;
|
|
1664
1669
|
})(e14, t2), s9 = /* @__PURE__ */ new Map();
|
|
1665
1670
|
for (const n2 of e14.chapters) s9.set(n2.chapterId, n2);
|
|
1666
|
-
const
|
|
1671
|
+
const i2 = Array.from(a3.keys()).sort((e15, t3) => e15 - t3), o = [];
|
|
1667
1672
|
let r2 = 0;
|
|
1668
|
-
for (const n2 of
|
|
1673
|
+
for (const n2 of i2) {
|
|
1669
1674
|
const e15 = a3.get(n2), t3 = s9.get(e15);
|
|
1670
1675
|
if (!t3) continue;
|
|
1671
|
-
const [
|
|
1676
|
+
const [i3] = t3.globalPageRange, [l] = t3.localPageRange, h2 = l + (n2 - i3);
|
|
1672
1677
|
o.push({ globalPageIndex: r2++, globalPageNumber: n2, chapterId: e15, localPageIndex: h2 });
|
|
1673
1678
|
}
|
|
1674
|
-
return new
|
|
1679
|
+
return new xt$1(o);
|
|
1675
1680
|
}
|
|
1676
|
-
const
|
|
1681
|
+
const Lt$1 = class e6 extends BasePlugin {
|
|
1677
1682
|
constructor(e14, t2) {
|
|
1678
|
-
super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy =
|
|
1683
|
+
super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = Mt$1, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingLoadPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
|
|
1679
1684
|
}
|
|
1680
1685
|
async initialize(e14) {
|
|
1681
|
-
if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ??
|
|
1686
|
+
if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? Mt$1, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
|
|
1682
1687
|
this.isOwnedChapter(e15.id) && (this.passwordAttempts.delete(e15.id), this.updateStatus(e15.id, "loaded"));
|
|
1683
1688
|
}), this.documentManager.provides().onDocumentClosed((e15) => {
|
|
1684
1689
|
this.isOwnedChapter(e15) && this.updateStatus(e15, "closed");
|
|
@@ -1704,16 +1709,16 @@ const wt$1 = class e6 extends BasePlugin {
|
|
|
1704
1709
|
const t3 = [], a4 = /* @__PURE__ */ new Set();
|
|
1705
1710
|
for (const s10 of e14.chapters) {
|
|
1706
1711
|
a4.has(s10.chapterId) && t3.push(`Duplicate chapterId: ${s10.chapterId}`), a4.add(s10.chapterId);
|
|
1707
|
-
const [e15,
|
|
1708
|
-
if (e15 >
|
|
1712
|
+
const [e15, i3] = s10.globalPageRange, [o, r2] = s10.localPageRange;
|
|
1713
|
+
if (e15 > i3 && t3.push(`${s10.chapterId}: invalid globalPageRange [${e15},${i3}]`), o > r2 && t3.push(`${s10.chapterId}: invalid localPageRange [${o},${r2}]`), i3 - e15 !== r2 - o && t3.push(`${s10.chapterId}: page-count mismatch (global ${i3 - e15 + 1} vs local ${r2 - o + 1})`), s10.ownedGlobalPages) for (const a5 of s10.ownedGlobalPages) (a5 < e15 || a5 > i3) && t3.push(`${s10.chapterId}: ownedGlobalPages contains ${a5} outside range`);
|
|
1709
1714
|
}
|
|
1710
1715
|
return t3;
|
|
1711
1716
|
})(t2);
|
|
1712
1717
|
a3.length > 0 && this.logger.warn(e6.id, "ManifestValidation", `Chapter manifest has issues: ${a3.join("; ")}`);
|
|
1713
|
-
const s9 = new Set(this.chapterStatus.keys()),
|
|
1714
|
-
for (const e14 of s9)
|
|
1718
|
+
const s9 = new Set(this.chapterStatus.keys()), i2 = new Set(t2.chapters.map((e14) => e14.chapterId));
|
|
1719
|
+
for (const e14 of s9) i2.has(e14) || (this.closeChapter(e14), this.chapterStatus.delete(e14));
|
|
1715
1720
|
for (const e14 of t2.chapters) this.chapterStatus.has(e14.chapterId) || this.chapterStatus.set(e14.chapterId, "idle");
|
|
1716
|
-
this.manifest = t2, this.virtualPageMap =
|
|
1721
|
+
this.manifest = t2, this.virtualPageMap = kt$1(t2, this.overlapStrategy), this.manifestChange$.emit({ manifest: t2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
|
|
1717
1722
|
}
|
|
1718
1723
|
eagerPrefetchFromManifest() {
|
|
1719
1724
|
const e14 = this.config.prefetchChapters ?? 0;
|
|
@@ -1740,20 +1745,20 @@ const wt$1 = class e6 extends BasePlugin {
|
|
|
1740
1745
|
e15 && s9.add(e15.chapterId);
|
|
1741
1746
|
}
|
|
1742
1747
|
if (0 === s9.size) return;
|
|
1743
|
-
const
|
|
1748
|
+
const i2 = this.manifest.chapters.map((e15) => e15.chapterId), o = /* @__PURE__ */ new Set();
|
|
1744
1749
|
for (const n2 of s9) {
|
|
1745
|
-
const e15 =
|
|
1746
|
-
if (-1 !== e15) for (let t3 = e15 - a3; t3 <= e15 + a3; t3++) t3 >= 0 && t3 <
|
|
1750
|
+
const e15 = i2.indexOf(n2);
|
|
1751
|
+
if (-1 !== e15) for (let t3 = e15 - a3; t3 <= e15 + a3; t3++) t3 >= 0 && t3 < i2.length && o.add(t3);
|
|
1747
1752
|
}
|
|
1748
1753
|
const r2 = /* @__PURE__ */ new Set();
|
|
1749
|
-
for (const n2 of o) r2.add(
|
|
1754
|
+
for (const n2 of o) r2.add(i2[n2]);
|
|
1750
1755
|
for (const n2 of r2) {
|
|
1751
1756
|
this.chapterLastUsed.set(n2, t2);
|
|
1752
1757
|
const e15 = this.chapterStatus.get(n2) ?? "idle";
|
|
1753
1758
|
"idle" !== e15 && "closed" !== e15 && "error" !== e15 || this.ensureChapterLoaded(n2);
|
|
1754
1759
|
}
|
|
1755
1760
|
if (this.config.autoActivateOnLoad ?? 1) {
|
|
1756
|
-
const e15 =
|
|
1761
|
+
const e15 = i2.find((e16) => s9.has(e16));
|
|
1757
1762
|
if (e15 && this.documentManager.provides().isDocumentOpen(e15)) {
|
|
1758
1763
|
this.documentManager.provides().getActiveDocumentId() !== e15 && this.documentManager.provides().setActiveDocument(e15);
|
|
1759
1764
|
}
|
|
@@ -1776,10 +1781,10 @@ const wt$1 = class e6 extends BasePlugin {
|
|
|
1776
1781
|
const s9 = this.chapterStatus.get(e14) ?? "idle";
|
|
1777
1782
|
if ("loaded" === s9) return this.chapterLastUsed.set(e14, Date.now()), Promise.resolve("loaded");
|
|
1778
1783
|
if ("loading" === s9) return this.waitForTerminalStatus(e14);
|
|
1779
|
-
const
|
|
1784
|
+
const i2 = this.startLoad(a3).finally(() => {
|
|
1780
1785
|
this.pendingLoadPromises.delete(e14);
|
|
1781
1786
|
});
|
|
1782
|
-
return this.pendingLoadPromises.set(e14,
|
|
1787
|
+
return this.pendingLoadPromises.set(e14, i2), i2;
|
|
1783
1788
|
}
|
|
1784
1789
|
async resolvePdfPayload(e14) {
|
|
1785
1790
|
const t2 = e14.source;
|
|
@@ -1797,17 +1802,17 @@ const wt$1 = class e6 extends BasePlugin {
|
|
|
1797
1802
|
const s9 = t2.chapterId;
|
|
1798
1803
|
this.updateStatus(s9, "loading"), this.chapterLastUsed.set(s9, Date.now());
|
|
1799
1804
|
try {
|
|
1800
|
-
const e14 = t2.encrypted && (null == (a3 = this.passwordProvider) ? void 0 : a3.getCachedPassword) ? this.passwordProvider.getCachedPassword(s9) : null,
|
|
1805
|
+
const e14 = t2.encrypted && (null == (a3 = this.passwordProvider) ? void 0 : a3.getCachedPassword) ? this.passwordProvider.getCachedPassword(s9) : null, i2 = await this.resolvePdfPayload(t2), o = this.documentManager.provides(), r2 = "url" in i2 ? o.openDocumentUrl({ documentId: s9, url: i2.url, name: t2.title, password: e14 ?? void 0, autoActivate: false }) : o.openDocumentBuffer({ documentId: s9, buffer: i2.buffer, name: t2.title, password: e14 ?? void 0, autoActivate: false }), n2 = await new Promise((e15, t3) => {
|
|
1801
1806
|
r2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
1802
1807
|
});
|
|
1803
1808
|
return await new Promise((e15, t3) => {
|
|
1804
1809
|
n2.task.wait(() => e15(), (e16) => t3(e16));
|
|
1805
1810
|
}), o.isDocumentOpen(s9) && this.updateStatus(s9, "loaded"), this.waitForTerminalStatus(s9);
|
|
1806
|
-
} catch (
|
|
1811
|
+
} catch (i2) {
|
|
1807
1812
|
const t3 = this.chapterStatus.get(s9);
|
|
1808
1813
|
if ("loaded" !== t3 && "password-required" !== t3) {
|
|
1809
|
-
const t4 =
|
|
1810
|
-
this.logger.error(e6.id, "LoadChapter", t4,
|
|
1814
|
+
const t4 = i2 instanceof Error ? i2.message : `Failed to load chapter "${s9}"`;
|
|
1815
|
+
this.logger.error(e6.id, "LoadChapter", t4, i2), this.updateStatus(s9, "error", t4);
|
|
1811
1816
|
}
|
|
1812
1817
|
return this.chapterStatus.get(s9) ?? "error";
|
|
1813
1818
|
}
|
|
@@ -1825,13 +1830,13 @@ const wt$1 = class e6 extends BasePlugin {
|
|
|
1825
1830
|
async handleDocumentError(t2, a3, s9) {
|
|
1826
1831
|
if (a3 !== PdfErrorCode.Password) return void this.updateStatus(t2, "error");
|
|
1827
1832
|
if (!this.passwordProvider) return void this.updateStatus(t2, "password-required");
|
|
1828
|
-
const
|
|
1829
|
-
if (!
|
|
1833
|
+
const i2 = this.findChapter(t2);
|
|
1834
|
+
if (!i2) return;
|
|
1830
1835
|
const o = (this.passwordAttempts.get(t2) ?? 0) + 1;
|
|
1831
1836
|
this.passwordAttempts.set(t2, o);
|
|
1832
1837
|
let r2 = null;
|
|
1833
1838
|
try {
|
|
1834
|
-
r2 = await this.passwordProvider.resolvePassword(
|
|
1839
|
+
r2 = await this.passwordProvider.resolvePassword(i2, o - 1);
|
|
1835
1840
|
} catch (n2) {
|
|
1836
1841
|
this.logger.error(e6.id, "PasswordProvider", `Provider rejected for ${t2}`, n2);
|
|
1837
1842
|
}
|
|
@@ -1851,10 +1856,10 @@ const wt$1 = class e6 extends BasePlugin {
|
|
|
1851
1856
|
this.chapterStatus.get(e14) !== t2 && (this.chapterStatus.set(e14, t2), this.statusChange$.emit({ chapterId: e14, status: t2, ..."error" === t2 && a3 ? { error: { message: a3 } } : {} }));
|
|
1852
1857
|
}
|
|
1853
1858
|
};
|
|
1854
|
-
|
|
1855
|
-
let
|
|
1856
|
-
const
|
|
1857
|
-
function
|
|
1859
|
+
Lt$1.id = "chapter-manager";
|
|
1860
|
+
let $t$1 = Lt$1;
|
|
1861
|
+
const zt$1 = { kind: "first-wins" };
|
|
1862
|
+
function Tt$1(e14, t2, a3) {
|
|
1858
1863
|
if (1 === t2.length) return t2[0].chapterId;
|
|
1859
1864
|
switch (a3.kind) {
|
|
1860
1865
|
case "first-wins":
|
|
@@ -1872,7 +1877,7 @@ function It$1(e14, t2, a3) {
|
|
|
1872
1877
|
return a3.resolve(e14, t2);
|
|
1873
1878
|
}
|
|
1874
1879
|
}
|
|
1875
|
-
let
|
|
1880
|
+
let Dt$1 = class Dt {
|
|
1876
1881
|
constructor(e14) {
|
|
1877
1882
|
this._pages = e14, this._byChapter = /* @__PURE__ */ new Map(), this._byGlobalNumber = /* @__PURE__ */ new Map();
|
|
1878
1883
|
for (const t2 of e14) {
|
|
@@ -1906,37 +1911,37 @@ let Mt$1 = class Mt {
|
|
|
1906
1911
|
return a3 ? this._pages.indexOf(a3) : -1;
|
|
1907
1912
|
}
|
|
1908
1913
|
};
|
|
1909
|
-
function
|
|
1910
|
-
const a3 = (function(e15, t3 =
|
|
1914
|
+
function Ot$1(e14, t2 = zt$1) {
|
|
1915
|
+
const a3 = (function(e15, t3 = zt$1) {
|
|
1911
1916
|
const a4 = /* @__PURE__ */ new Map();
|
|
1912
|
-
for (const
|
|
1913
|
-
const [e16, t4] =
|
|
1917
|
+
for (const i3 of e15.chapters) {
|
|
1918
|
+
const [e16, t4] = i3.globalPageRange;
|
|
1914
1919
|
for (let s11 = e16; s11 <= t4; s11++) {
|
|
1915
1920
|
const e17 = a4.get(s11);
|
|
1916
|
-
e17 ? e17.push(
|
|
1921
|
+
e17 ? e17.push(i3) : a4.set(s11, [i3]);
|
|
1917
1922
|
}
|
|
1918
1923
|
}
|
|
1919
1924
|
const s10 = /* @__PURE__ */ new Map();
|
|
1920
|
-
for (const [
|
|
1925
|
+
for (const [i3, o2] of a4) s10.set(i3, Tt$1(i3, o2, t3));
|
|
1921
1926
|
return s10;
|
|
1922
1927
|
})(e14, t2), s9 = /* @__PURE__ */ new Map();
|
|
1923
1928
|
for (const n2 of e14.chapters) s9.set(n2.chapterId, n2);
|
|
1924
|
-
const
|
|
1929
|
+
const i2 = Array.from(a3.keys()).sort((e15, t3) => e15 - t3), o = [];
|
|
1925
1930
|
let r2 = 0;
|
|
1926
|
-
for (const n2 of
|
|
1931
|
+
for (const n2 of i2) {
|
|
1927
1932
|
const e15 = a3.get(n2), t3 = s9.get(e15);
|
|
1928
1933
|
if (!t3) continue;
|
|
1929
|
-
const [
|
|
1934
|
+
const [i3] = t3.globalPageRange, [l] = t3.localPageRange, h2 = l + (n2 - i3);
|
|
1930
1935
|
o.push({ globalPageIndex: r2++, globalPageNumber: n2, chapterId: e15, localPageIndex: h2 });
|
|
1931
1936
|
}
|
|
1932
|
-
return new
|
|
1937
|
+
return new Dt$1(o);
|
|
1933
1938
|
}
|
|
1934
|
-
const
|
|
1939
|
+
const Gt$1 = class e7 extends BasePlugin {
|
|
1935
1940
|
constructor(e14, t2) {
|
|
1936
|
-
super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy =
|
|
1941
|
+
super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = zt$1, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingLoadPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
|
|
1937
1942
|
}
|
|
1938
1943
|
async initialize(e14) {
|
|
1939
|
-
if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ??
|
|
1944
|
+
if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? zt$1, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
|
|
1940
1945
|
this.isOwnedChapter(e15.id) && (this.passwordAttempts.delete(e15.id), this.updateStatus(e15.id, "loaded"));
|
|
1941
1946
|
}), this.documentManager.provides().onDocumentClosed((e15) => {
|
|
1942
1947
|
this.isOwnedChapter(e15) && this.updateStatus(e15, "closed");
|
|
@@ -1962,16 +1967,16 @@ const xt$1 = class e7 extends BasePlugin {
|
|
|
1962
1967
|
const t3 = [], a4 = /* @__PURE__ */ new Set();
|
|
1963
1968
|
for (const s10 of e14.chapters) {
|
|
1964
1969
|
a4.has(s10.chapterId) && t3.push(`Duplicate chapterId: ${s10.chapterId}`), a4.add(s10.chapterId);
|
|
1965
|
-
const [e15,
|
|
1966
|
-
if (e15 >
|
|
1970
|
+
const [e15, i3] = s10.globalPageRange, [o, r2] = s10.localPageRange;
|
|
1971
|
+
if (e15 > i3 && t3.push(`${s10.chapterId}: invalid globalPageRange [${e15},${i3}]`), o > r2 && t3.push(`${s10.chapterId}: invalid localPageRange [${o},${r2}]`), i3 - e15 !== r2 - o && t3.push(`${s10.chapterId}: page-count mismatch (global ${i3 - e15 + 1} vs local ${r2 - o + 1})`), s10.ownedGlobalPages) for (const a5 of s10.ownedGlobalPages) (a5 < e15 || a5 > i3) && t3.push(`${s10.chapterId}: ownedGlobalPages contains ${a5} outside range`);
|
|
1967
1972
|
}
|
|
1968
1973
|
return t3;
|
|
1969
1974
|
})(t2);
|
|
1970
1975
|
a3.length > 0 && this.logger.warn(e7.id, "ManifestValidation", `Chapter manifest has issues: ${a3.join("; ")}`);
|
|
1971
|
-
const s9 = new Set(this.chapterStatus.keys()),
|
|
1972
|
-
for (const e14 of s9)
|
|
1976
|
+
const s9 = new Set(this.chapterStatus.keys()), i2 = new Set(t2.chapters.map((e14) => e14.chapterId));
|
|
1977
|
+
for (const e14 of s9) i2.has(e14) || (this.closeChapter(e14), this.chapterStatus.delete(e14));
|
|
1973
1978
|
for (const e14 of t2.chapters) this.chapterStatus.has(e14.chapterId) || this.chapterStatus.set(e14.chapterId, "idle");
|
|
1974
|
-
this.manifest = t2, this.virtualPageMap =
|
|
1979
|
+
this.manifest = t2, this.virtualPageMap = Ot$1(t2, this.overlapStrategy), this.manifestChange$.emit({ manifest: t2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
|
|
1975
1980
|
}
|
|
1976
1981
|
eagerPrefetchFromManifest() {
|
|
1977
1982
|
const e14 = this.config.prefetchChapters ?? 0;
|
|
@@ -1998,20 +2003,20 @@ const xt$1 = class e7 extends BasePlugin {
|
|
|
1998
2003
|
e15 && s9.add(e15.chapterId);
|
|
1999
2004
|
}
|
|
2000
2005
|
if (0 === s9.size) return;
|
|
2001
|
-
const
|
|
2006
|
+
const i2 = this.manifest.chapters.map((e15) => e15.chapterId), o = /* @__PURE__ */ new Set();
|
|
2002
2007
|
for (const n2 of s9) {
|
|
2003
|
-
const e15 =
|
|
2004
|
-
if (-1 !== e15) for (let t3 = e15 - a3; t3 <= e15 + a3; t3++) t3 >= 0 && t3 <
|
|
2008
|
+
const e15 = i2.indexOf(n2);
|
|
2009
|
+
if (-1 !== e15) for (let t3 = e15 - a3; t3 <= e15 + a3; t3++) t3 >= 0 && t3 < i2.length && o.add(t3);
|
|
2005
2010
|
}
|
|
2006
2011
|
const r2 = /* @__PURE__ */ new Set();
|
|
2007
|
-
for (const n2 of o) r2.add(
|
|
2012
|
+
for (const n2 of o) r2.add(i2[n2]);
|
|
2008
2013
|
for (const n2 of r2) {
|
|
2009
2014
|
this.chapterLastUsed.set(n2, t2);
|
|
2010
2015
|
const e15 = this.chapterStatus.get(n2) ?? "idle";
|
|
2011
2016
|
"idle" !== e15 && "closed" !== e15 && "error" !== e15 || this.ensureChapterLoaded(n2);
|
|
2012
2017
|
}
|
|
2013
2018
|
if (this.config.autoActivateOnLoad ?? 1) {
|
|
2014
|
-
const e15 =
|
|
2019
|
+
const e15 = i2.find((e16) => s9.has(e16));
|
|
2015
2020
|
if (e15 && this.documentManager.provides().isDocumentOpen(e15)) {
|
|
2016
2021
|
this.documentManager.provides().getActiveDocumentId() !== e15 && this.documentManager.provides().setActiveDocument(e15);
|
|
2017
2022
|
}
|
|
@@ -2034,10 +2039,10 @@ const xt$1 = class e7 extends BasePlugin {
|
|
|
2034
2039
|
const s9 = this.chapterStatus.get(e14) ?? "idle";
|
|
2035
2040
|
if ("loaded" === s9) return this.chapterLastUsed.set(e14, Date.now()), Promise.resolve("loaded");
|
|
2036
2041
|
if ("loading" === s9) return this.waitForTerminalStatus(e14);
|
|
2037
|
-
const
|
|
2042
|
+
const i2 = this.startLoad(a3).finally(() => {
|
|
2038
2043
|
this.pendingLoadPromises.delete(e14);
|
|
2039
2044
|
});
|
|
2040
|
-
return this.pendingLoadPromises.set(e14,
|
|
2045
|
+
return this.pendingLoadPromises.set(e14, i2), i2;
|
|
2041
2046
|
}
|
|
2042
2047
|
async resolvePdfPayload(e14) {
|
|
2043
2048
|
const t2 = e14.source;
|
|
@@ -2055,17 +2060,17 @@ const xt$1 = class e7 extends BasePlugin {
|
|
|
2055
2060
|
const s9 = t2.chapterId;
|
|
2056
2061
|
this.updateStatus(s9, "loading"), this.chapterLastUsed.set(s9, Date.now());
|
|
2057
2062
|
try {
|
|
2058
|
-
const e14 = t2.encrypted && (null == (a3 = this.passwordProvider) ? void 0 : a3.getCachedPassword) ? this.passwordProvider.getCachedPassword(s9) : null,
|
|
2063
|
+
const e14 = t2.encrypted && (null == (a3 = this.passwordProvider) ? void 0 : a3.getCachedPassword) ? this.passwordProvider.getCachedPassword(s9) : null, i2 = await this.resolvePdfPayload(t2), o = this.documentManager.provides(), r2 = "url" in i2 ? o.openDocumentUrl({ documentId: s9, url: i2.url, name: t2.title, password: e14 ?? void 0, autoActivate: false }) : o.openDocumentBuffer({ documentId: s9, buffer: i2.buffer, name: t2.title, password: e14 ?? void 0, autoActivate: false }), n2 = await new Promise((e15, t3) => {
|
|
2059
2064
|
r2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
2060
2065
|
});
|
|
2061
2066
|
return await new Promise((e15, t3) => {
|
|
2062
2067
|
n2.task.wait(() => e15(), (e16) => t3(e16));
|
|
2063
2068
|
}), o.isDocumentOpen(s9) && this.updateStatus(s9, "loaded"), this.waitForTerminalStatus(s9);
|
|
2064
|
-
} catch (
|
|
2069
|
+
} catch (i2) {
|
|
2065
2070
|
const t3 = this.chapterStatus.get(s9);
|
|
2066
2071
|
if ("loaded" !== t3 && "password-required" !== t3) {
|
|
2067
|
-
const t4 =
|
|
2068
|
-
this.logger.error(e7.id, "LoadChapter", t4,
|
|
2072
|
+
const t4 = i2 instanceof Error ? i2.message : `Failed to load chapter "${s9}"`;
|
|
2073
|
+
this.logger.error(e7.id, "LoadChapter", t4, i2), this.updateStatus(s9, "error", t4);
|
|
2069
2074
|
}
|
|
2070
2075
|
return this.chapterStatus.get(s9) ?? "error";
|
|
2071
2076
|
}
|
|
@@ -2083,13 +2088,13 @@ const xt$1 = class e7 extends BasePlugin {
|
|
|
2083
2088
|
async handleDocumentError(t2, a3, s9) {
|
|
2084
2089
|
if (a3 !== PdfErrorCode.Password) return void this.updateStatus(t2, "error");
|
|
2085
2090
|
if (!this.passwordProvider) return void this.updateStatus(t2, "password-required");
|
|
2086
|
-
const
|
|
2087
|
-
if (!
|
|
2091
|
+
const i2 = this.findChapter(t2);
|
|
2092
|
+
if (!i2) return;
|
|
2088
2093
|
const o = (this.passwordAttempts.get(t2) ?? 0) + 1;
|
|
2089
2094
|
this.passwordAttempts.set(t2, o);
|
|
2090
2095
|
let r2 = null;
|
|
2091
2096
|
try {
|
|
2092
|
-
r2 = await this.passwordProvider.resolvePassword(
|
|
2097
|
+
r2 = await this.passwordProvider.resolvePassword(i2, o - 1);
|
|
2093
2098
|
} catch (n2) {
|
|
2094
2099
|
this.logger.error(e7.id, "PasswordProvider", `Provider rejected for ${t2}`, n2);
|
|
2095
2100
|
}
|
|
@@ -2109,20 +2114,20 @@ const xt$1 = class e7 extends BasePlugin {
|
|
|
2109
2114
|
this.chapterStatus.get(e14) !== t2 && (this.chapterStatus.set(e14, t2), this.statusChange$.emit({ chapterId: e14, status: t2, ..."error" === t2 && a3 ? { error: { message: a3 } } : {} }));
|
|
2110
2115
|
}
|
|
2111
2116
|
};
|
|
2112
|
-
|
|
2113
|
-
let
|
|
2114
|
-
function
|
|
2117
|
+
Gt$1.id = "chapter-manager";
|
|
2118
|
+
let Nt = Gt$1;
|
|
2119
|
+
function At$1(e14, t2) {
|
|
2115
2120
|
if (e14 === t2) return true;
|
|
2116
2121
|
if (e14.totalHeight !== t2.totalHeight || e14.totalWidth !== t2.totalWidth || e14.pageGap !== t2.pageGap || e14.items.length !== t2.items.length) return false;
|
|
2117
2122
|
for (let a3 = 0; a3 < e14.items.length; a3++) {
|
|
2118
|
-
const s9 = e14.items[a3],
|
|
2119
|
-
if (s9.globalPageIndex !==
|
|
2123
|
+
const s9 = e14.items[a3], i2 = t2.items[a3];
|
|
2124
|
+
if (s9.globalPageIndex !== i2.globalPageIndex || s9.isPlaceholder !== i2.isPlaceholder || s9.chapterId !== i2.chapterId || s9.localPageIndex !== i2.localPageIndex || s9.offsetTop !== i2.offsetTop || s9.width !== i2.width || s9.height !== i2.height) return false;
|
|
2120
2125
|
}
|
|
2121
2126
|
return true;
|
|
2122
2127
|
}
|
|
2123
|
-
const
|
|
2128
|
+
const Vt = class extends BasePlugin {
|
|
2124
2129
|
constructor(e14, t2) {
|
|
2125
|
-
super(e14, t2), this.layoutChange$ = createBehaviorEmitter(void 0,
|
|
2130
|
+
super(e14, t2), this.layoutChange$ = createBehaviorEmitter(void 0, At$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.chapterManagerUnsubs = [], this.chapterManager = this.registry.getPlugin(Nt.id), this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
|
|
2126
2131
|
}
|
|
2127
2132
|
async initialize(e14) {
|
|
2128
2133
|
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 }) => {
|
|
@@ -2176,8 +2181,8 @@ const $t$1 = class $t extends BasePlugin {
|
|
|
2176
2181
|
this.offsets = new Array(e14);
|
|
2177
2182
|
let t2 = 0, a3 = 0;
|
|
2178
2183
|
for (let s9 = 0; s9 < e14; s9++) {
|
|
2179
|
-
const { width: e15, height:
|
|
2180
|
-
this.offsets[s9] = t2, t2 +=
|
|
2184
|
+
const { width: e15, height: i2 } = this.getPageSize(s9);
|
|
2185
|
+
this.offsets[s9] = t2, t2 += i2 + this.config.pageGap, e15 > a3 && (a3 = e15);
|
|
2181
2186
|
}
|
|
2182
2187
|
this.totalHeight = e14 > 0 ? t2 - this.config.pageGap : 0, this.totalWidth = a3, this.layoutChange$.emit(this.computeLayout());
|
|
2183
2188
|
}
|
|
@@ -2187,8 +2192,8 @@ const $t$1 = class $t extends BasePlugin {
|
|
|
2187
2192
|
for (const s9 of t2) {
|
|
2188
2193
|
const t3 = this.virtualPageMap.toGlobal(e14, s9.localPageIndex);
|
|
2189
2194
|
if (!t3) continue;
|
|
2190
|
-
const
|
|
2191
|
-
|
|
2195
|
+
const i2 = this.pageSizes.get(t3.globalPageIndex);
|
|
2196
|
+
i2 && i2.width === s9.width && i2.height === s9.height || (this.pageSizes.set(t3.globalPageIndex, { width: s9.width, height: s9.height }), a3 = true);
|
|
2192
2197
|
}
|
|
2193
2198
|
if (a3) {
|
|
2194
2199
|
const e15 = this.currentGlobalPageIndex, t3 = this.offsets[e15] ?? 0;
|
|
@@ -2206,10 +2211,10 @@ const $t$1 = class $t extends BasePlugin {
|
|
|
2206
2211
|
harvestChapterSizes(e14, t2 = 0) {
|
|
2207
2212
|
var a3;
|
|
2208
2213
|
if (!this.virtualPageMap) return;
|
|
2209
|
-
const s9 = this.documentManager.provides().getDocument(e14),
|
|
2210
|
-
if (!(null == (a3 = null == s9 ? void 0 : s9.pages) ? void 0 : a3.length) || 0 ===
|
|
2214
|
+
const s9 = this.documentManager.provides().getDocument(e14), i2 = this.virtualPageMap.pagesOfChapter(e14);
|
|
2215
|
+
if (!(null == (a3 = null == s9 ? void 0 : s9.pages) ? void 0 : a3.length) || 0 === i2.length) return void (t2 < 60 && requestAnimationFrame(() => this.harvestChapterSizes(e14, t2 + 1)));
|
|
2211
2216
|
const o = this.getChapterDocumentScale(e14), r2 = [];
|
|
2212
|
-
for (const n2 of
|
|
2217
|
+
for (const n2 of i2) {
|
|
2213
2218
|
const e15 = s9.pages[n2.localPageIndex];
|
|
2214
2219
|
(null == e15 ? void 0 : e15.size) && r2.push({ localPageIndex: n2.localPageIndex, width: e15.size.width * o, height: e15.size.height * o });
|
|
2215
2220
|
}
|
|
@@ -2240,38 +2245,38 @@ const $t$1 = class $t extends BasePlugin {
|
|
|
2240
2245
|
const e14 = this.virtualPageMap.totalPages;
|
|
2241
2246
|
if (0 === e14) return this.currentVisible = [], this.currentGlobalPageIndex = 0, void this.layoutChange$.emit(this.computeLayout());
|
|
2242
2247
|
const t2 = this.viewportEl.scrollTop, a3 = t2 + this.viewportEl.clientHeight, s9 = this.findFirstVisibleIndex(t2);
|
|
2243
|
-
let
|
|
2244
|
-
for (;
|
|
2245
|
-
const e15 = this.getPageSize(
|
|
2248
|
+
let i2 = s9;
|
|
2249
|
+
for (; i2 < e14; ) {
|
|
2250
|
+
const e15 = this.getPageSize(i2), t3 = this.offsets[i2];
|
|
2246
2251
|
if (e15.height, t3 >= a3) break;
|
|
2247
|
-
|
|
2252
|
+
i2++;
|
|
2248
2253
|
}
|
|
2249
2254
|
const o = [];
|
|
2250
2255
|
let r2 = s9, n2 = -1;
|
|
2251
|
-
for (let l = s9; l <
|
|
2256
|
+
for (let l = s9; l < i2; l++) {
|
|
2252
2257
|
o.push(l);
|
|
2253
|
-
const e15 = this.offsets[l], s10 = e15 + this.getPageSize(l).height,
|
|
2254
|
-
|
|
2258
|
+
const e15 = this.offsets[l], s10 = e15 + this.getPageSize(l).height, i3 = Math.max(0, Math.min(s10, a3) - Math.max(e15, t2));
|
|
2259
|
+
i3 > n2 && (n2 = i3, r2 = l);
|
|
2255
2260
|
}
|
|
2256
2261
|
this.currentVisible = o, this.currentGlobalPageIndex = r2, this.visibleChange$.emit({ visibleGlobalPageIndices: o, currentGlobalPageIndex: r2 }), this.chapterManager.provides().setVisibleGlobalPages(o), this.layoutChange$.emit(this.computeLayout());
|
|
2257
2262
|
}
|
|
2258
2263
|
findFirstVisibleIndex(e14) {
|
|
2259
2264
|
let t2 = 0, a3 = this.offsets.length - 1, s9 = 0;
|
|
2260
2265
|
for (; t2 <= a3; ) {
|
|
2261
|
-
const
|
|
2262
|
-
this.offsets[
|
|
2266
|
+
const i2 = t2 + a3 >> 1;
|
|
2267
|
+
this.offsets[i2] <= e14 ? (s9 = i2, t2 = i2 + 1) : a3 = i2 - 1;
|
|
2263
2268
|
}
|
|
2264
2269
|
return s9;
|
|
2265
2270
|
}
|
|
2266
2271
|
computeLayout() {
|
|
2267
|
-
const e14 = this.config.bufferSize, t2 = Math.max(0, (this.currentVisible[0] ?? 0) - e14), a3 = this.currentVisible[this.currentVisible.length - 1] ?? -1, s9 = Math.min(this.offsets.length - 1, (a3 >= 0 ? a3 : 0) + e14),
|
|
2272
|
+
const e14 = this.config.bufferSize, t2 = Math.max(0, (this.currentVisible[0] ?? 0) - e14), a3 = this.currentVisible[this.currentVisible.length - 1] ?? -1, s9 = Math.min(this.offsets.length - 1, (a3 >= 0 ? a3 : 0) + e14), i2 = [];
|
|
2268
2273
|
if (this.virtualPageMap && this.offsets.length > 0) for (let o = t2; o <= s9; o++) {
|
|
2269
2274
|
const e15 = this.virtualPageMap.atIndex(o);
|
|
2270
2275
|
if (!e15) continue;
|
|
2271
2276
|
const t3 = this.getPageSize(o), a4 = this.isChapterPagePlaceholder(e15.chapterId);
|
|
2272
|
-
|
|
2277
|
+
i2.push({ globalPageIndex: o, globalPageNumber: e15.globalPageNumber, chapterId: e15.chapterId, localPageIndex: e15.localPageIndex, width: t3.width, height: t3.height, offsetTop: this.offsets[o], isPlaceholder: a4 });
|
|
2273
2278
|
}
|
|
2274
|
-
return { totalHeight: this.totalHeight, totalWidth: this.totalWidth || this.config.placeholderPageWidth, items:
|
|
2279
|
+
return { totalHeight: this.totalHeight, totalWidth: this.totalWidth || this.config.placeholderPageWidth, items: i2, pageGap: this.config.pageGap };
|
|
2275
2280
|
}
|
|
2276
2281
|
scrollToIndex(e14, t2) {
|
|
2277
2282
|
if (!this.viewportEl || e14 < 0 || e14 >= this.offsets.length) return;
|
|
@@ -2281,11 +2286,11 @@ const $t$1 = class $t extends BasePlugin {
|
|
|
2281
2286
|
scrollToGlobalPdfPoint(e14, t2, a3) {
|
|
2282
2287
|
var s9;
|
|
2283
2288
|
if (!this.viewportEl || e14 < 0 || e14 >= this.offsets.length || !this.virtualPageMap) return;
|
|
2284
|
-
const
|
|
2289
|
+
const i2 = (null == a3 ? void 0 : a3.marginTop) ?? 80, o = this.virtualPageMap.atIndex(e14);
|
|
2285
2290
|
if (!o) return void this.scrollToIndex(e14, a3);
|
|
2286
2291
|
const r2 = this.pageSizes.get(e14), n2 = null == (s9 = this.documentManager.provides().getDocument(o.chapterId)) ? void 0 : s9.pages[o.localPageIndex];
|
|
2287
2292
|
if (!r2 || !n2) return void this.scrollToIndex(e14, a3);
|
|
2288
|
-
const l = r2.height / n2.size.height, h2 = (this.offsets[e14] ?? 0) + t2 * l -
|
|
2293
|
+
const l = r2.height / n2.size.height, h2 = (this.offsets[e14] ?? 0) + t2 * l - i2;
|
|
2289
2294
|
this.viewportEl.scrollTo({ top: Math.max(0, h2), behavior: (null == a3 ? void 0 : a3.behavior) ?? "auto" });
|
|
2290
2295
|
}
|
|
2291
2296
|
scrollToChapter(e14, t2) {
|
|
@@ -2299,56 +2304,56 @@ const $t$1 = class $t extends BasePlugin {
|
|
|
2299
2304
|
a3 && this.scrollToIndex(a3.globalPageIndex, t2);
|
|
2300
2305
|
}
|
|
2301
2306
|
};
|
|
2302
|
-
|
|
2303
|
-
let
|
|
2304
|
-
function
|
|
2307
|
+
Vt.id = "chapter-scroll";
|
|
2308
|
+
let _t = Vt;
|
|
2309
|
+
function Et(e14) {
|
|
2305
2310
|
if (0 === e14.length) throw new Error("unionRects: empty rects");
|
|
2306
|
-
let t2 = 1 / 0, a3 = 1 / 0, s9 = -1 / 0,
|
|
2307
|
-
for (const o of e14) t2 = Math.min(t2, o.origin.x), a3 = Math.min(a3, o.origin.y), s9 = Math.max(s9, o.origin.x + o.size.width),
|
|
2308
|
-
return { origin: { x: t2, y: a3 }, size: { width: s9 - t2, height:
|
|
2311
|
+
let t2 = 1 / 0, a3 = 1 / 0, s9 = -1 / 0, i2 = -1 / 0;
|
|
2312
|
+
for (const o of e14) t2 = Math.min(t2, o.origin.x), a3 = Math.min(a3, o.origin.y), s9 = Math.max(s9, o.origin.x + o.size.width), i2 = Math.max(i2, o.origin.y + o.size.height);
|
|
2313
|
+
return { origin: { x: t2, y: a3 }, size: { width: s9 - t2, height: i2 - a3 } };
|
|
2309
2314
|
}
|
|
2310
|
-
function
|
|
2315
|
+
function Rt(e14) {
|
|
2311
2316
|
const t2 = e14[e14.length - 1];
|
|
2312
2317
|
return { x: t2.origin.x + t2.size.width, y: t2.origin.y + t2.size.height };
|
|
2313
2318
|
}
|
|
2314
|
-
function
|
|
2315
|
-
const a3 = e14.origin.y, s9 = e14.origin.y + e14.size.height,
|
|
2319
|
+
function Ft(e14, t2) {
|
|
2320
|
+
const a3 = e14.origin.y, s9 = e14.origin.y + e14.size.height, i2 = t2.origin.y, o = t2.origin.y + t2.size.height, r2 = Math.max(s9, o) - Math.min(a3, i2);
|
|
2316
2321
|
if (r2 <= 0) return 0;
|
|
2317
|
-
return Math.max(0, Math.min(s9, o) - Math.max(a3,
|
|
2322
|
+
return Math.max(0, Math.min(s9, o) - Math.max(a3, i2)) / r2;
|
|
2318
2323
|
}
|
|
2319
|
-
function
|
|
2324
|
+
function Ut(e14, t2) {
|
|
2320
2325
|
var a3, s9;
|
|
2321
2326
|
if (e14.chapterId !== t2.chapterId || e14.localPageIndex !== t2.localPageIndex) return false;
|
|
2322
|
-
const
|
|
2327
|
+
const i2 = (null == (a3 = e14.rectsPdfCoord) ? void 0 : a3.length) ? e14.rectsPdfCoord : [e14.rectPdfCoord], o = (null == (s9 = t2.rectsPdfCoord) ? void 0 : s9.length) ? t2.rectsPdfCoord : [t2.rectPdfCoord], r2 = e14.markerAnchor ?? Rt(i2), n2 = t2.markerAnchor ?? Rt(o);
|
|
2323
2328
|
if (Math.hypot(r2.x - n2.x, r2.y - n2.y) <= 6) return true;
|
|
2324
|
-
for (const l of
|
|
2325
|
-
if (
|
|
2329
|
+
for (const l of i2) for (const e15 of o) {
|
|
2330
|
+
if (Ft(l, e15) < 0.5) continue;
|
|
2326
2331
|
const t3 = Math.max(l.origin.x, e15.origin.x);
|
|
2327
2332
|
if (Math.min(l.origin.x + l.size.width, e15.origin.x + e15.size.width) - t3 > 0.25 * Math.min(l.size.width, e15.size.width)) return true;
|
|
2328
2333
|
}
|
|
2329
2334
|
return false;
|
|
2330
2335
|
}
|
|
2331
|
-
function
|
|
2332
|
-
const
|
|
2333
|
-
if (0 ===
|
|
2334
|
-
return { chapterId: e14, localPageIndex: t2, globalPageIndex: null == s9 ? void 0 : s9.globalPageIndex, globalPageNumber: null == s9 ? void 0 : s9.globalPageNumber, rectPdfCoord:
|
|
2336
|
+
function qt(e14, t2, a3, s9) {
|
|
2337
|
+
const i2 = a3.length > 0 ? a3 : [];
|
|
2338
|
+
if (0 === i2.length) throw new Error("buildParagraphBookmarkAnchor: no rects");
|
|
2339
|
+
return { chapterId: e14, localPageIndex: t2, globalPageIndex: null == s9 ? void 0 : s9.globalPageIndex, globalPageNumber: null == s9 ? void 0 : s9.globalPageNumber, rectPdfCoord: Et(i2), rectsPdfCoord: i2, markerAnchor: Rt(i2) };
|
|
2335
2340
|
}
|
|
2336
|
-
async function
|
|
2341
|
+
async function Wt(e14, t2, a3) {
|
|
2337
2342
|
e14.scrollToGlobalPageIndex(t2), await (function(e15, t3, a4 = 2500) {
|
|
2338
2343
|
const s9 = e15.getLayout().items.find((e16) => e16.globalPageIndex === t3 && !e16.isPlaceholder);
|
|
2339
2344
|
return s9 ? Promise.resolve(s9) : new Promise((s10) => {
|
|
2340
|
-
const
|
|
2345
|
+
const i2 = setTimeout(() => {
|
|
2341
2346
|
o(), s10(null);
|
|
2342
2347
|
}, a4), o = e15.onLayoutChange((e16) => {
|
|
2343
2348
|
const a5 = e16.items.find((e17) => e17.globalPageIndex === t3 && !e17.isPlaceholder);
|
|
2344
|
-
a5 && (clearTimeout(
|
|
2349
|
+
a5 && (clearTimeout(i2), o(), s10(a5));
|
|
2345
2350
|
});
|
|
2346
2351
|
});
|
|
2347
2352
|
})(e14, t2), e14.scrollToGlobalPdfPoint(t2, a3, { marginTop: 80 });
|
|
2348
2353
|
}
|
|
2349
|
-
const
|
|
2354
|
+
const Ht$1 = class e8 extends BasePlugin {
|
|
2350
2355
|
constructor(e14, t2) {
|
|
2351
|
-
super(e14, t2), this.change$ = createBehaviorEmitter([]), this.entries = /* @__PURE__ */ new Map(), this.chapterScroll = this.registry.getPlugin(
|
|
2356
|
+
super(e14, t2), this.change$ = createBehaviorEmitter([]), this.entries = /* @__PURE__ */ new Map(), this.chapterScroll = this.registry.getPlugin(_t.id), this.chapterManager = this.registry.getPlugin($t$1.id), this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
|
|
2352
2357
|
}
|
|
2353
2358
|
async initialize(t2) {
|
|
2354
2359
|
var a3;
|
|
@@ -2364,7 +2369,7 @@ const Vt = class e8 extends BasePlugin {
|
|
|
2364
2369
|
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 };
|
|
2365
2370
|
}
|
|
2366
2371
|
addBookmark(e14) {
|
|
2367
|
-
for (const s9 of this.entries.values()) if (
|
|
2372
|
+
for (const s9 of this.entries.values()) if (Ut(s9.anchor, e14.anchor)) return s9;
|
|
2368
2373
|
const t2 = e14.id ?? `bm-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`, a3 = { id: t2, label: e14.label, anchor: e14.anchor, metadata: e14.metadata, createdAt: Date.now() };
|
|
2369
2374
|
return this.entries.set(t2, a3), this.notifyAndPersist(), a3;
|
|
2370
2375
|
}
|
|
@@ -2374,11 +2379,11 @@ const Vt = class e8 extends BasePlugin {
|
|
|
2374
2379
|
}
|
|
2375
2380
|
async requestRemoveBookmark(t2) {
|
|
2376
2381
|
var a3, s9;
|
|
2377
|
-
const
|
|
2378
|
-
if (!
|
|
2382
|
+
const i2 = this.entries.get(t2);
|
|
2383
|
+
if (!i2) return false;
|
|
2379
2384
|
const o = null == (s9 = null == (a3 = this.config) ? void 0 : a3.callbacks) ? void 0 : s9.onRequestRemove;
|
|
2380
2385
|
if (o) try {
|
|
2381
|
-
if (!await o(
|
|
2386
|
+
if (!await o(i2)) return false;
|
|
2382
2387
|
} catch (r2) {
|
|
2383
2388
|
return this.logger.error(e8.id, "RequestRemove", "callback failed", r2), false;
|
|
2384
2389
|
}
|
|
@@ -2415,18 +2420,18 @@ const Vt = class e8 extends BasePlugin {
|
|
|
2415
2420
|
if (!e15) return;
|
|
2416
2421
|
s9 = e15.globalPageIndex;
|
|
2417
2422
|
}
|
|
2418
|
-
const
|
|
2423
|
+
const i2 = (function(e15) {
|
|
2419
2424
|
if (e15.markerAnchor) return e15.markerAnchor.y;
|
|
2420
2425
|
const t3 = e15.rectPdfCoord;
|
|
2421
2426
|
return t3.origin.y + t3.size.height;
|
|
2422
2427
|
})(t2.anchor);
|
|
2423
|
-
await
|
|
2428
|
+
await Wt(a3, s9, i2);
|
|
2424
2429
|
}
|
|
2425
2430
|
};
|
|
2426
|
-
|
|
2427
|
-
let
|
|
2428
|
-
const Et = { manifest: ft$1, create: (e14) => new _t(gt, e14), reducer: (e14) => e14, initialState: {} }, Rt = { "annotation-toolbar": { id: "annotation-toolbar", position: { placement: "top", slot: "secondary", order: 0 }, responsive: { breakpoints: { sm: { maxWidth: 640, hide: ["add-text", "add-ink", "add-ink-highlighter", "add-insert-text", "add-replace-text", "add-comment", "add-callout"], show: ["overflow-annotation-tools"] }, md: { minWidth: 640, hide: ["overflow-annotation-tools"], show: ["add-text", "add-ink", "add-ink-highlighter", "add-insert-text", "add-replace-text", "add-comment", "add-callout"] } } }, permanent: false, categories: ["annotation"], items: [{ type: "spacer", id: "spacer-3", flex: true }, { type: "group", id: "annotation-tools", alignment: "start", gap: 2, items: [{ type: "command-button", id: "add-highlight", commandId: "annotation:add-highlight", variant: "icon", categories: ["annotation", "annotation-markup", "annotation-highlight"] }, { type: "command-button", id: "add-strikeout", commandId: "annotation:add-strikeout", variant: "icon", categories: ["annotation", "annotation-markup", "annotation-strikeout"] }, { type: "command-button", id: "add-underline", commandId: "annotation:add-underline", variant: "icon", categories: ["annotation", "annotation-markup", "annotation-underline"] }, { type: "command-button", id: "add-squiggly", commandId: "annotation:add-squiggly", variant: "icon", categories: ["annotation", "annotation-markup", "annotation-squiggly"] }, { type: "command-button", id: "add-ink", commandId: "annotation:add-ink", variant: "icon", categories: ["annotation", "annotation-ink"] }, { type: "command-button", id: "add-ink-highlighter", commandId: "annotation:add-ink-highlighter", variant: "icon", categories: ["annotation", "annotation-ink"] }, { type: "command-button", id: "add-text", commandId: "annotation:add-text", variant: "icon", categories: ["annotation", "annotation-text"] }, { type: "command-button", id: "add-insert-text", commandId: "annotation:add-insert-text", variant: "icon", categories: ["annotation", "annotation-markup", "annotation-insert-text"] }, { type: "command-button", id: "add-replace-text", commandId: "annotation:add-replace-text", variant: "icon", categories: ["annotation", "annotation-markup", "annotation-replace-text"] }, { type: "command-button", id: "add-comment", commandId: "annotation:add-comment", variant: "icon", categories: ["annotation", "annotation-comment-tool"] }, { type: "command-button", id: "add-callout", commandId: "annotation:add-callout", variant: "icon", categories: ["annotation", "annotation-text"] }, { type: "command-button", id: "overflow-annotation-tools", commandId: "annotation:overflow-tools", variant: "icon", categories: ["annotation", "annotation-overflow"] }, { type: "divider", id: "annotation-tools-divider-1", orientation: "vertical" }, { type: "command-button", id: "toggle-annotation-style", commandId: "panel:toggle-annotation-style", variant: "icon", categories: ["panel", "panel-annotation-style"] }, { type: "divider", id: "annotation-tools-divider-2", orientation: "vertical", visibilityDependsOn: { itemIds: ["toggle-annotation-style"] } }, { type: "command-button", id: "undo-button", commandId: "history:undo", variant: "icon", categories: ["history", "history-undo"] }, { type: "command-button", id: "redo-button", commandId: "history:redo", variant: "icon", categories: ["history", "history-redo"] }] }, { type: "spacer", id: "spacer-4", flex: true }] }, "shapes-toolbar": { id: "shapes-toolbar", position: { placement: "top", slot: "secondary", order: 0 }, responsive: { breakpoints: { sm: { maxWidth: 640, hide: ["add-polygon", "add-polyline"], show: ["overflow-shapes-tools"] }, md: { minWidth: 640, hide: ["overflow-shapes-tools"], show: ["add-polygon", "add-polyline"] } } }, permanent: false, categories: ["annotation", "annotation-shape"], items: [{ type: "spacer", id: "spacer-5", flex: true }, { type: "group", id: "shapes-tools", alignment: "start", gap: 2, items: [{ type: "command-button", id: "add-rectangle", commandId: "annotation:add-rectangle", variant: "icon", categories: ["annotation", "annotation-shape", "annotation-rectangle"] }, { type: "command-button", id: "add-circle", commandId: "annotation:add-circle", variant: "icon", categories: ["annotation", "annotation-shape", "annotation-circle"] }, { type: "command-button", id: "add-line", commandId: "annotation:add-line", variant: "icon", categories: ["annotation", "annotation-shape", "annotation-line"] }, { type: "command-button", id: "add-arrow", commandId: "annotation:add-arrow", variant: "icon", categories: ["annotation", "annotation-shape", "annotation-arrow"] }, { type: "command-button", id: "add-polygon", commandId: "annotation:add-polygon", variant: "icon", categories: ["annotation", "annotation-shape", "annotation-polygon"] }, { type: "command-button", id: "add-polyline", commandId: "annotation:add-polyline", variant: "icon", categories: ["annotation", "annotation-shape", "annotation-polyline"] }, { type: "command-button", id: "overflow-shapes-tools", commandId: "annotation:overflow-shapes", variant: "icon", categories: ["annotation", "annotation-shape", "annotation-overflow"] }, { type: "divider", id: "shapes-tools-divider-1", orientation: "vertical" }, { type: "command-button", id: "toggle-annotation-style", commandId: "panel:toggle-annotation-style", variant: "icon", categories: ["panel", "panel-annotation-style"] }, { type: "divider", id: "shapes-tools-divider-2", orientation: "vertical", visibilityDependsOn: { itemIds: ["toggle-annotation-style"] } }, { type: "command-button", id: "undo-button", commandId: "history:undo", variant: "icon", categories: ["history", "history-undo"] }, { type: "command-button", id: "redo-button", commandId: "history:redo", variant: "icon", categories: ["history", "history-redo"] }] }, { type: "spacer", id: "spacer-6", flex: true }] }, "form-toolbar": { id: "form-toolbar", position: { placement: "top", slot: "secondary", order: 0 }, responsive: { breakpoints: { sm: { maxWidth: 640, hide: ["add-form-select", "add-form-listbox"], show: ["overflow-forms-tools"] }, md: { minWidth: 640, hide: ["overflow-forms-tools"], show: ["add-form-select", "add-form-listbox"] } } }, permanent: false, categories: ["form"], items: [{ type: "spacer", id: "spacer-form-1", flex: true }, { type: "group", id: "form-tools", alignment: "start", gap: 2, items: [{ type: "command-button", id: "add-form-textfield", commandId: "form:add-textfield", variant: "icon", categories: ["form", "form-textfield"] }, { type: "command-button", id: "add-form-checkbox", commandId: "form:add-checkbox", variant: "icon", categories: ["form", "form-checkbox"] }, { type: "command-button", id: "add-form-radio", commandId: "form:add-radio", variant: "icon", categories: ["form", "form-radio"] }, { type: "command-button", id: "add-form-select", commandId: "form:add-select", variant: "icon", categories: ["form", "form-select"] }, { type: "command-button", id: "add-form-listbox", commandId: "form:add-listbox", variant: "icon", categories: ["form", "form-listbox"] }, { type: "command-button", id: "overflow-forms-tools", commandId: "form:overflow-tools", variant: "icon", categories: ["form", "form-overflow"] }, { type: "divider", id: "form-tools-divider-1", orientation: "vertical" }, { type: "command-button", id: "toggle-annotation-style", commandId: "panel:toggle-annotation-style", variant: "icon", categories: ["panel", "panel-annotation-style"] }, { type: "command-button", id: "toggle-form-fill-mode", commandId: "form:toggle-fill-mode", variant: "icon", categories: ["form", "form-fill-mode"] }, { type: "divider", id: "form-tools-divider-2", orientation: "vertical" }, { type: "command-button", id: "undo-button", commandId: "history:undo", variant: "icon", categories: ["history", "history-undo"] }, { type: "command-button", id: "redo-button", commandId: "history:redo", variant: "icon", categories: ["history", "history-redo"] }] }, { type: "spacer", id: "spacer-form-2", flex: true }] }, "insert-toolbar": { id: "insert-toolbar", position: { placement: "top", slot: "secondary", order: 0 }, permanent: false, categories: ["insert"], items: [{ type: "spacer", id: "spacer-insert-1", flex: true }, { type: "group", id: "insert-tools", alignment: "start", gap: 2, items: [{ type: "command-button", id: "add-rubber-stamp", commandId: "insert:add-rubber-stamp", variant: "icon", categories: ["insert", "insert-rubber-stamp"] }, { type: "command-button", id: "add-signature", commandId: "insert:add-signature", variant: "icon", categories: ["insert", "insert-signature"] }, { type: "command-button", id: "add-image", commandId: "insert:add-image", variant: "icon", categories: ["insert", "insert-image"] }, { type: "divider", id: "insert-tools-divider-1", orientation: "vertical" }, { type: "command-button", id: "toggle-annotation-style", commandId: "panel:toggle-annotation-style", variant: "icon", categories: ["panel", "panel-annotation-style"] }, { type: "divider", id: "insert-tools-divider-2", orientation: "vertical", visibilityDependsOn: { itemIds: ["toggle-annotation-style"] } }, { type: "command-button", id: "undo-button", commandId: "history:undo", variant: "icon", categories: ["history", "history-undo"] }, { type: "command-button", id: "redo-button", commandId: "history:redo", variant: "icon", categories: ["history", "history-redo"] }] }, { type: "spacer", id: "spacer-insert-2", flex: true }] }, "redaction-toolbar": { id: "redaction-toolbar", position: { placement: "top", slot: "secondary", order: 0 }, permanent: false, categories: ["redaction"], items: [{ type: "spacer", id: "spacer-7", flex: true }, { type: "group", id: "redaction-tools", alignment: "start", gap: 2, items: [{ type: "command-button", id: "redact", commandId: "redaction:redact", variant: "icon", categories: ["redaction", "redaction-combined"] }, { type: "divider", id: "redaction-tools-divider-1", orientation: "vertical" }, { type: "command-button", id: "toggle-redaction-panel", commandId: "panel:toggle-redaction", variant: "icon", categories: ["panel", "panel-redaction"] }, { type: "command-button", id: "toggle-annotation-style", commandId: "panel:toggle-annotation-style", variant: "icon", categories: ["panel", "panel-annotation-style"] }, { type: "divider", id: "redaction-tools-divider-2", orientation: "vertical", visibilityDependsOn: { itemIds: ["toggle-annotation-style"] } }, { type: "command-button", id: "undo-button", commandId: "history:undo", variant: "icon", categories: ["history", "history-undo"] }, { type: "command-button", id: "redo-button", commandId: "history:redo", variant: "icon", categories: ["history", "history-redo"] }] }, { type: "spacer", id: "spacer-8", flex: true }] } };
|
|
2429
|
-
class
|
|
2431
|
+
Ht$1.id = "paragraph-bookmark";
|
|
2432
|
+
let Bt$1 = Ht$1;
|
|
2433
|
+
const jt = { manifest: It$1, create: (e14) => new Bt$1(Ct$1, e14), reducer: (e14) => e14, initialState: {} }, Zt = { "annotation-toolbar": { id: "annotation-toolbar", position: { placement: "top", slot: "secondary", order: 0 }, responsive: { breakpoints: { sm: { maxWidth: 640, hide: ["add-text", "add-ink", "add-ink-highlighter", "add-insert-text", "add-replace-text", "add-comment", "add-callout"], show: ["overflow-annotation-tools"] }, md: { minWidth: 640, hide: ["overflow-annotation-tools"], show: ["add-text", "add-ink", "add-ink-highlighter", "add-insert-text", "add-replace-text", "add-comment", "add-callout"] } } }, permanent: false, categories: ["annotation"], items: [{ type: "spacer", id: "spacer-3", flex: true }, { type: "group", id: "annotation-tools", alignment: "start", gap: 2, items: [{ type: "command-button", id: "add-highlight", commandId: "annotation:add-highlight", variant: "icon", categories: ["annotation", "annotation-markup", "annotation-highlight"] }, { type: "command-button", id: "add-strikeout", commandId: "annotation:add-strikeout", variant: "icon", categories: ["annotation", "annotation-markup", "annotation-strikeout"] }, { type: "command-button", id: "add-underline", commandId: "annotation:add-underline", variant: "icon", categories: ["annotation", "annotation-markup", "annotation-underline"] }, { type: "command-button", id: "add-squiggly", commandId: "annotation:add-squiggly", variant: "icon", categories: ["annotation", "annotation-markup", "annotation-squiggly"] }, { type: "command-button", id: "add-ink", commandId: "annotation:add-ink", variant: "icon", categories: ["annotation", "annotation-ink"] }, { type: "command-button", id: "add-ink-highlighter", commandId: "annotation:add-ink-highlighter", variant: "icon", categories: ["annotation", "annotation-ink"] }, { type: "command-button", id: "add-text", commandId: "annotation:add-text", variant: "icon", categories: ["annotation", "annotation-text"] }, { type: "command-button", id: "add-insert-text", commandId: "annotation:add-insert-text", variant: "icon", categories: ["annotation", "annotation-markup", "annotation-insert-text"] }, { type: "command-button", id: "add-replace-text", commandId: "annotation:add-replace-text", variant: "icon", categories: ["annotation", "annotation-markup", "annotation-replace-text"] }, { type: "command-button", id: "add-comment", commandId: "annotation:add-comment", variant: "icon", categories: ["annotation", "annotation-comment-tool"] }, { type: "command-button", id: "add-callout", commandId: "annotation:add-callout", variant: "icon", categories: ["annotation", "annotation-text"] }, { type: "command-button", id: "overflow-annotation-tools", commandId: "annotation:overflow-tools", variant: "icon", categories: ["annotation", "annotation-overflow"] }, { type: "divider", id: "annotation-tools-divider-1", orientation: "vertical" }, { type: "command-button", id: "toggle-annotation-style", commandId: "panel:toggle-annotation-style", variant: "icon", categories: ["panel", "panel-annotation-style"] }, { type: "divider", id: "annotation-tools-divider-2", orientation: "vertical", visibilityDependsOn: { itemIds: ["toggle-annotation-style"] } }, { type: "command-button", id: "undo-button", commandId: "history:undo", variant: "icon", categories: ["history", "history-undo"] }, { type: "command-button", id: "redo-button", commandId: "history:redo", variant: "icon", categories: ["history", "history-redo"] }] }, { type: "spacer", id: "spacer-4", flex: true }] }, "shapes-toolbar": { id: "shapes-toolbar", position: { placement: "top", slot: "secondary", order: 0 }, responsive: { breakpoints: { sm: { maxWidth: 640, hide: ["add-polygon", "add-polyline"], show: ["overflow-shapes-tools"] }, md: { minWidth: 640, hide: ["overflow-shapes-tools"], show: ["add-polygon", "add-polyline"] } } }, permanent: false, categories: ["annotation", "annotation-shape"], items: [{ type: "spacer", id: "spacer-5", flex: true }, { type: "group", id: "shapes-tools", alignment: "start", gap: 2, items: [{ type: "command-button", id: "add-rectangle", commandId: "annotation:add-rectangle", variant: "icon", categories: ["annotation", "annotation-shape", "annotation-rectangle"] }, { type: "command-button", id: "add-circle", commandId: "annotation:add-circle", variant: "icon", categories: ["annotation", "annotation-shape", "annotation-circle"] }, { type: "command-button", id: "add-line", commandId: "annotation:add-line", variant: "icon", categories: ["annotation", "annotation-shape", "annotation-line"] }, { type: "command-button", id: "add-arrow", commandId: "annotation:add-arrow", variant: "icon", categories: ["annotation", "annotation-shape", "annotation-arrow"] }, { type: "command-button", id: "add-polygon", commandId: "annotation:add-polygon", variant: "icon", categories: ["annotation", "annotation-shape", "annotation-polygon"] }, { type: "command-button", id: "add-polyline", commandId: "annotation:add-polyline", variant: "icon", categories: ["annotation", "annotation-shape", "annotation-polyline"] }, { type: "command-button", id: "overflow-shapes-tools", commandId: "annotation:overflow-shapes", variant: "icon", categories: ["annotation", "annotation-shape", "annotation-overflow"] }, { type: "divider", id: "shapes-tools-divider-1", orientation: "vertical" }, { type: "command-button", id: "toggle-annotation-style", commandId: "panel:toggle-annotation-style", variant: "icon", categories: ["panel", "panel-annotation-style"] }, { type: "divider", id: "shapes-tools-divider-2", orientation: "vertical", visibilityDependsOn: { itemIds: ["toggle-annotation-style"] } }, { type: "command-button", id: "undo-button", commandId: "history:undo", variant: "icon", categories: ["history", "history-undo"] }, { type: "command-button", id: "redo-button", commandId: "history:redo", variant: "icon", categories: ["history", "history-redo"] }] }, { type: "spacer", id: "spacer-6", flex: true }] }, "form-toolbar": { id: "form-toolbar", position: { placement: "top", slot: "secondary", order: 0 }, responsive: { breakpoints: { sm: { maxWidth: 640, hide: ["add-form-select", "add-form-listbox"], show: ["overflow-forms-tools"] }, md: { minWidth: 640, hide: ["overflow-forms-tools"], show: ["add-form-select", "add-form-listbox"] } } }, permanent: false, categories: ["form"], items: [{ type: "spacer", id: "spacer-form-1", flex: true }, { type: "group", id: "form-tools", alignment: "start", gap: 2, items: [{ type: "command-button", id: "add-form-textfield", commandId: "form:add-textfield", variant: "icon", categories: ["form", "form-textfield"] }, { type: "command-button", id: "add-form-checkbox", commandId: "form:add-checkbox", variant: "icon", categories: ["form", "form-checkbox"] }, { type: "command-button", id: "add-form-radio", commandId: "form:add-radio", variant: "icon", categories: ["form", "form-radio"] }, { type: "command-button", id: "add-form-select", commandId: "form:add-select", variant: "icon", categories: ["form", "form-select"] }, { type: "command-button", id: "add-form-listbox", commandId: "form:add-listbox", variant: "icon", categories: ["form", "form-listbox"] }, { type: "command-button", id: "overflow-forms-tools", commandId: "form:overflow-tools", variant: "icon", categories: ["form", "form-overflow"] }, { type: "divider", id: "form-tools-divider-1", orientation: "vertical" }, { type: "command-button", id: "toggle-annotation-style", commandId: "panel:toggle-annotation-style", variant: "icon", categories: ["panel", "panel-annotation-style"] }, { type: "command-button", id: "toggle-form-fill-mode", commandId: "form:toggle-fill-mode", variant: "icon", categories: ["form", "form-fill-mode"] }, { type: "divider", id: "form-tools-divider-2", orientation: "vertical" }, { type: "command-button", id: "undo-button", commandId: "history:undo", variant: "icon", categories: ["history", "history-undo"] }, { type: "command-button", id: "redo-button", commandId: "history:redo", variant: "icon", categories: ["history", "history-redo"] }] }, { type: "spacer", id: "spacer-form-2", flex: true }] }, "insert-toolbar": { id: "insert-toolbar", position: { placement: "top", slot: "secondary", order: 0 }, permanent: false, categories: ["insert"], items: [{ type: "spacer", id: "spacer-insert-1", flex: true }, { type: "group", id: "insert-tools", alignment: "start", gap: 2, items: [{ type: "command-button", id: "add-rubber-stamp", commandId: "insert:add-rubber-stamp", variant: "icon", categories: ["insert", "insert-rubber-stamp"] }, { type: "command-button", id: "add-signature", commandId: "insert:add-signature", variant: "icon", categories: ["insert", "insert-signature"] }, { type: "command-button", id: "add-image", commandId: "insert:add-image", variant: "icon", categories: ["insert", "insert-image"] }, { type: "divider", id: "insert-tools-divider-1", orientation: "vertical" }, { type: "command-button", id: "toggle-annotation-style", commandId: "panel:toggle-annotation-style", variant: "icon", categories: ["panel", "panel-annotation-style"] }, { type: "divider", id: "insert-tools-divider-2", orientation: "vertical", visibilityDependsOn: { itemIds: ["toggle-annotation-style"] } }, { type: "command-button", id: "undo-button", commandId: "history:undo", variant: "icon", categories: ["history", "history-undo"] }, { type: "command-button", id: "redo-button", commandId: "history:redo", variant: "icon", categories: ["history", "history-redo"] }] }, { type: "spacer", id: "spacer-insert-2", flex: true }] }, "redaction-toolbar": { id: "redaction-toolbar", position: { placement: "top", slot: "secondary", order: 0 }, permanent: false, categories: ["redaction"], items: [{ type: "spacer", id: "spacer-7", flex: true }, { type: "group", id: "redaction-tools", alignment: "start", gap: 2, items: [{ type: "command-button", id: "redact", commandId: "redaction:redact", variant: "icon", categories: ["redaction", "redaction-combined"] }, { type: "divider", id: "redaction-tools-divider-1", orientation: "vertical" }, { type: "command-button", id: "toggle-redaction-panel", commandId: "panel:toggle-redaction", variant: "icon", categories: ["panel", "panel-redaction"] }, { type: "command-button", id: "toggle-annotation-style", commandId: "panel:toggle-annotation-style", variant: "icon", categories: ["panel", "panel-annotation-style"] }, { type: "divider", id: "redaction-tools-divider-2", orientation: "vertical", visibilityDependsOn: { itemIds: ["toggle-annotation-style"] } }, { type: "command-button", id: "undo-button", commandId: "history:undo", variant: "icon", categories: ["history", "history-undo"] }, { type: "command-button", id: "redo-button", commandId: "history:redo", variant: "icon", categories: ["history", "history-redo"] }] }, { type: "spacer", id: "spacer-8", flex: true }] } };
|
|
2434
|
+
class Yt {
|
|
2430
2435
|
constructor() {
|
|
2431
2436
|
this.specs = [];
|
|
2432
2437
|
}
|
|
@@ -2441,30 +2446,30 @@ class Ft {
|
|
|
2441
2446
|
return this.specs;
|
|
2442
2447
|
}
|
|
2443
2448
|
buildToolbars() {
|
|
2444
|
-
const e14 = structuredClone(
|
|
2449
|
+
const e14 = structuredClone(Zt);
|
|
2445
2450
|
for (const t2 of this.specs) {
|
|
2446
2451
|
const a3 = e14[t2.toolbarSlot];
|
|
2447
2452
|
if (!a3) continue;
|
|
2448
2453
|
const s9 = { type: "command-button", id: t2.id, commandId: t2.commandId, variant: "icon", ...t2.icon ? { icon: t2.icon } : {}, ...t2.i18nKey ? { labelKey: t2.i18nKey } : {}, ...t2.label ? { label: t2.label } : {}, categories: t2.categories ?? [] };
|
|
2449
|
-
a3.items =
|
|
2454
|
+
a3.items = Kt(a3.items, s9, t2.position);
|
|
2450
2455
|
}
|
|
2451
2456
|
return e14;
|
|
2452
2457
|
}
|
|
2453
2458
|
}
|
|
2454
|
-
function
|
|
2459
|
+
function Kt(e14, t2, a3) {
|
|
2455
2460
|
return (null == a3 ? void 0 : a3.after) || (null == a3 ? void 0 : a3.before) ? (function(e15, t3, a4) {
|
|
2456
2461
|
const s9 = (e16) => {
|
|
2457
|
-
const
|
|
2458
|
-
for (const o of e16) "group" !== o.type ? a4.before && o.id === a4.before ?
|
|
2459
|
-
return
|
|
2462
|
+
const i2 = [];
|
|
2463
|
+
for (const o of e16) "group" !== o.type ? a4.before && o.id === a4.before ? i2.push(t3, o) : (i2.push(o), a4.after && o.id === a4.after && i2.push(t3)) : i2.push({ ...o, items: s9(o.items) });
|
|
2464
|
+
return i2;
|
|
2460
2465
|
};
|
|
2461
2466
|
return s9(e15);
|
|
2462
2467
|
})(e14, t2, a3) : (function(e15, t3) {
|
|
2463
2468
|
return e15.map((e16) => "group" === e16.type ? { ...e16, items: [...e16.items, t3] } : e16);
|
|
2464
2469
|
})(e14, t2);
|
|
2465
2470
|
}
|
|
2466
|
-
const
|
|
2467
|
-
function
|
|
2471
|
+
const Xt = { annotate: "annotation-toolbar", shapes: "shapes-toolbar", insert: "insert-toolbar", form: "form-toolbar", redact: "redaction-toolbar" };
|
|
2472
|
+
function Qt() {
|
|
2468
2473
|
return { "mode:view": { id: "mode:view", label: "View", categories: ["mode", "mode-view"], action: ({ registry: e14, documentId: t2 }) => {
|
|
2469
2474
|
var _a2, _b, _c, _d;
|
|
2470
2475
|
const a3 = (_a2 = e14.getPlugin("ui")) == null ? void 0 : _a2.provides(), s9 = (_b = e14.getPlugin("interaction-manager")) == null ? void 0 : _b.provides();
|
|
@@ -2491,28 +2496,28 @@ function Wt() {
|
|
|
2491
2496
|
a3 && (a3.setActiveToolbar("top", "secondary", "redaction-toolbar", t2), (_b = e14.getPlugin(ANNOTATION_PLUGIN_ID)) == null ? void 0 : _b.provides().forDocument(t2).setLocked({ type: LockModeType.Include, categories: ["form"] }));
|
|
2492
2497
|
}, active: ({ state: e14, documentId: t2 }) => isToolbarOpen(e14.plugins, t2, "top", "secondary", "redaction-toolbar") } };
|
|
2493
2498
|
}
|
|
2494
|
-
function
|
|
2499
|
+
function Jt(e14) {
|
|
2495
2500
|
var _a2, _b, _c, _d, _e2, _f;
|
|
2496
|
-
const t2 = e14.toolbar ?? {}, a3 = t2.enabledModes ?? ["view", "annotate", "shapes", "insert", "form", "redact"], s9 = a3.length > 0, { schema:
|
|
2497
|
-
var t3, a4, s10,
|
|
2498
|
-
const n3 = new Set(e15.enabledModes ?? ["view", "annotate", "shapes", "insert", "form", "redact"]), l = new
|
|
2501
|
+
const t2 = e14.toolbar ?? {}, a3 = t2.enabledModes ?? ["view", "annotate", "shapes", "insert", "form", "redact"], s9 = a3.length > 0, { schema: i2, operationRegistry: o } = (function(e15 = {}) {
|
|
2502
|
+
var t3, a4, s10, i3, o2, r3;
|
|
2503
|
+
const n3 = new Set(e15.enabledModes ?? ["view", "annotate", "shapes", "insert", "form", "redact"]), l = new Yt();
|
|
2499
2504
|
(null == (t3 = e15.customOperations) ? void 0 : t3.length) && l.registerAll(e15.customOperations);
|
|
2500
|
-
const h2 = l.buildToolbars(),
|
|
2505
|
+
const h2 = l.buildToolbars(), d2 = {};
|
|
2501
2506
|
for (const u of n3) {
|
|
2502
2507
|
if ("view" === u) continue;
|
|
2503
|
-
const e16 =
|
|
2504
|
-
h2[e16] && (
|
|
2508
|
+
const e16 = Xt[u];
|
|
2509
|
+
h2[e16] && (d2[e16] = h2[e16]);
|
|
2505
2510
|
}
|
|
2506
2511
|
const c = (function(e16) {
|
|
2507
2512
|
if (0 === e16.size) return null;
|
|
2508
2513
|
const t4 = (e17, t5, a5) => ({ type: "command-button", id: `${e17}-mode`, commandId: a5, variant: "text", label: t5, categories: ["mode", e17] });
|
|
2509
2514
|
return { id: "chapter-editor-main-toolbar", position: { placement: "top", slot: "main", order: 0 }, permanent: true, items: [{ type: "spacer", id: "main-spacer-left", flex: true }, { type: "group", id: "mode-group", alignment: "start", gap: 2, items: [...e16.has("view") ? [t4("view", "View", "mode:view")] : [], ...e16.has("annotate") ? [t4("annotate", "Annotate", "mode:annotate")] : [], ...e16.has("shapes") ? [t4("shapes", "Shapes", "mode:shapes")] : [], ...e16.has("insert") ? [t4("insert", "Insert", "mode:insert")] : [], ...e16.has("form") ? [t4("form", "Form", "mode:form")] : [], ...e16.has("redact") ? [t4("redact", "Redact", "mode:redact")] : []] }, { type: "spacer", id: "main-spacer-right", flex: true }] };
|
|
2510
2515
|
})(n3);
|
|
2511
|
-
return c && (
|
|
2512
|
-
})({ ...t2, enabledModes: a3 }), r2 = { ...s9 ?
|
|
2513
|
-
return e14.notes && n2.push(createPluginRegistration(
|
|
2516
|
+
return c && (d2["chapter-editor-main-toolbar"] = c), (null == (a4 = e15.extend) ? void 0 : a4.toolbars) && Object.assign(d2, e15.extend.toolbars), { schema: { id: "chapter-pdf-editor-ui", version: "1.0.0", toolbars: d2, menus: (null == (s10 = e15.extend) ? void 0 : s10.menus) ?? {}, sidebars: (null == (i3 = e15.extend) ? void 0 : i3.sidebars) ?? {}, modals: (null == (o2 = e15.extend) ? void 0 : o2.modals) ?? {}, selectionMenus: (null == (r3 = e15.extend) ? void 0 : r3.selectionMenus) ?? {} }, operationRegistry: l };
|
|
2517
|
+
})({ ...t2, enabledModes: a3 }), r2 = { ...s9 ? Qt() : {}, ...s9 ? ea(o.list()) : {}, ...e14.commands ?? {} }, n2 = [createPluginRegistration(DocumentManagerPluginPackage, { initialDocuments: [] }), createPluginRegistration(Ue, { manifest: e14.manifest, overlapStrategy: e14.overlapStrategy, passwordProvider: e14.passwordProvider, chapterPdfLoader: e14.chapterPdfLoader, prefetchChapters: e14.prefetchChapters, unloadTimeoutMs: e14.unloadTimeoutMs }), createPluginRegistration(et$1, { placeholderPageHeight: e14.placeholderPageHeight, placeholderPageWidth: e14.placeholderPageWidth }), createPluginRegistration(InteractionManagerPluginPackage), createPluginRegistration(RenderPluginPackage), createPluginRegistration(RotatePluginPackage), createPluginRegistration(SelectionPluginPackage, { marquee: { enabled: false }, toleranceFactor: 1.2, minSelectionDragDistance: 4 }), createPluginRegistration(HistoryPluginPackage), createPluginRegistration(AnnotationPluginPackage), createPluginRegistration(RedactionPluginPackage), createPluginRegistration(FormPluginPackage), createPluginRegistration(StampPluginPackage, false === e14.loadDefaultStampLibrary ? { manifests: [] } : void 0), createPluginRegistration(SignaturePluginPackage), ...Object.keys(r2).length > 0 ? [createPluginRegistration(CommandsPluginPackage, { commands: r2 })] : [], ...s9 ? [createPluginRegistration(I18nPluginPackage), createPluginRegistration(UIPluginPackage, { schema: i2 })] : []];
|
|
2518
|
+
return e14.notes && n2.push(createPluginRegistration(yt$1, { callbacks: e14.notes.callbacks, ui: (_b = (_a2 = e14.features) == null ? void 0 : _a2.notes) == null ? void 0 : _b.marker })), e14.bookmarks && n2.push(createPluginRegistration(jt, { callbacks: e14.bookmarks.callbacks, ui: (_d = (_c = e14.features) == null ? void 0 : _c.bookmarks) == null ? void 0 : _d.marker, hover: (_f = (_e2 = e14.features) == null ? void 0 : _e2.bookmarks) == null ? void 0 : _f.hover })), { plugins: n2, uiSchema: i2, operationRegistry: o };
|
|
2514
2519
|
}
|
|
2515
|
-
function
|
|
2520
|
+
function ea(e14) {
|
|
2516
2521
|
const t2 = {};
|
|
2517
2522
|
for (const a3 of e14) a3.handler && (t2[a3.commandId] = { id: a3.commandId, labelKey: a3.i18nKey, label: a3.label, icon: a3.icon, categories: a3.categories, action: ({ documentId: e15 }) => {
|
|
2518
2523
|
var _a2;
|
|
@@ -2520,55 +2525,55 @@ function Bt$1(e14) {
|
|
|
2520
2525
|
} });
|
|
2521
2526
|
return t2;
|
|
2522
2527
|
}
|
|
2523
|
-
const
|
|
2524
|
-
function
|
|
2525
|
-
return
|
|
2528
|
+
const ta = xe(), aa = {};
|
|
2529
|
+
function sa(e14) {
|
|
2530
|
+
return Jt({ ...e14, toolbar: e14.toolbar ?? { enabledModes: [] }, features: xe(e14.features) });
|
|
2526
2531
|
}
|
|
2527
|
-
const
|
|
2528
|
-
function
|
|
2532
|
+
const ia = { overlapStrategy: { kind: "first-wins" }, passwordProvider: new Le(async () => null), prefetchChapters: 1, loadDefaultStampLibrary: false, unloadTimeoutMs: 12e4, toolbar: { enabledModes: [] } };
|
|
2533
|
+
function oa(e14) {
|
|
2529
2534
|
return (function(e15) {
|
|
2530
2535
|
return "callbacks" in e15.notes;
|
|
2531
2536
|
})(e14) ? { manifest: e14.manifest, chapterPdfLoader: e14.chapterPdfLoader, notes: e14.notes.callbacks, bookmarks: e14.bookmarks.callbacks } : e14;
|
|
2532
2537
|
}
|
|
2533
|
-
function
|
|
2534
|
-
return { manifest: e14.manifest, chapterPdfLoader: e14.chapterPdfLoader,
|
|
2538
|
+
function ra(e14) {
|
|
2539
|
+
return { ...ia, manifest: e14.manifest, chapterPdfLoader: e14.chapterPdfLoader, overlapStrategy: e14.overlapStrategy ?? ia.overlapStrategy, notes: { callbacks: e14.notes }, bookmarks: { callbacks: e14.bookmarks }, features: xe(e14.features) };
|
|
2535
2540
|
}
|
|
2536
|
-
function
|
|
2537
|
-
const t2 =
|
|
2541
|
+
function na(e14) {
|
|
2542
|
+
const t2 = ra(oa(e14)), { plugins: a3 } = sa(t2);
|
|
2538
2543
|
return { plugins: a3, features: t2.features, editorOptions: t2 };
|
|
2539
2544
|
}
|
|
2540
|
-
function
|
|
2541
|
-
const { features: t2, ...a3 } =
|
|
2545
|
+
function la(e14) {
|
|
2546
|
+
const { features: t2, ...a3 } = ra(oa(e14));
|
|
2542
2547
|
return a3;
|
|
2543
2548
|
}
|
|
2544
|
-
function
|
|
2549
|
+
function ha(e14, t2 = 0.5, a3 = 3) {
|
|
2545
2550
|
return Math.min(a3, Math.max(t2, e14));
|
|
2546
2551
|
}
|
|
2547
|
-
function
|
|
2552
|
+
function da(i2, o) {
|
|
2548
2553
|
var _a2;
|
|
2549
|
-
const r2 = isRef(
|
|
2554
|
+
const r2 = isRef(i2) ? i2 : computed(() => i2), { registry: n2 } = useRegistry(), { provides: l } = useCapability(DocumentManagerPlugin.id), { provides: h2 } = useCapability(Fe.id), d2 = ref(((_a2 = o.value) == null ? void 0 : _a2.initial) ?? 1), c = ref(d2.value), u = () => {
|
|
2550
2555
|
var _a3;
|
|
2551
2556
|
return ((_a3 = o.value) == null ? void 0 : _a3.min) ?? 0.5;
|
|
2552
|
-
},
|
|
2557
|
+
}, p2 = () => {
|
|
2553
2558
|
var _a3;
|
|
2554
2559
|
return ((_a3 = o.value) == null ? void 0 : _a3.max) ?? 3;
|
|
2555
|
-
},
|
|
2560
|
+
}, g2 = () => {
|
|
2556
2561
|
var _a3;
|
|
2557
2562
|
return (_a3 = o.value) == null ? void 0 : _a3.pageWidth;
|
|
2558
2563
|
};
|
|
2559
2564
|
function f(e14) {
|
|
2560
|
-
const t2 =
|
|
2561
|
-
c.value = t2,
|
|
2565
|
+
const t2 = ha(e14, u(), p2());
|
|
2566
|
+
c.value = t2, d2.value = t2, (function(e15, t3, a3, s9 = 0.5, i3 = 3) {
|
|
2562
2567
|
const o2 = e15 == null ? void 0 : e15.getStore();
|
|
2563
2568
|
if (!o2) return;
|
|
2564
|
-
const r3 =
|
|
2569
|
+
const r3 = ha(a3, s9, i3);
|
|
2565
2570
|
o2.dispatchToCore(setDefaultScale(r3));
|
|
2566
2571
|
for (const n3 of t3.chapters) o2.getState().core.documents[n3.chapterId] && o2.dispatchToCore(setScale(r3, n3.chapterId));
|
|
2567
|
-
})(n2.value, r2.value, t2, u(),
|
|
2572
|
+
})(n2.value, r2.value, t2, u(), p2());
|
|
2568
2573
|
}
|
|
2569
2574
|
function m(e14) {
|
|
2570
|
-
|
|
2571
|
-
const t2 =
|
|
2575
|
+
g2() ? (function(e15) {
|
|
2576
|
+
const t2 = g2();
|
|
2572
2577
|
if (!t2 || !l.value) return;
|
|
2573
2578
|
const a3 = l.value.getDocument(e15);
|
|
2574
2579
|
a3 && f((function(e16, t3, a4 = 0) {
|
|
@@ -2586,7 +2591,7 @@ function aa(i, o) {
|
|
|
2586
2591
|
return (_a3 = o.value) == null ? void 0 : _a3.pageWidth;
|
|
2587
2592
|
}], () => {
|
|
2588
2593
|
var _a3;
|
|
2589
|
-
n2.value && (
|
|
2594
|
+
n2.value && (g2() || f(((_a3 = o.value) == null ? void 0 : _a3.initial) ?? 1));
|
|
2590
2595
|
}, { immediate: true }), watch([h2, r2, () => {
|
|
2591
2596
|
var _a3;
|
|
2592
2597
|
return (_a3 = o.value) == null ? void 0 : _a3.pageWidth;
|
|
@@ -2598,24 +2603,24 @@ function aa(i, o) {
|
|
|
2598
2603
|
"loaded" === e15.status && m(e15.chapterId);
|
|
2599
2604
|
});
|
|
2600
2605
|
}
|
|
2601
|
-
}, { immediate: true }), { scale:
|
|
2606
|
+
}, { immediate: true }), { scale: d2, setScale: f, zoomEnabled: () => {
|
|
2602
2607
|
var _a3;
|
|
2603
2608
|
return false !== ((_a3 = o.value) == null ? void 0 : _a3.enabled);
|
|
2604
|
-
}, minZoom: u, maxZoom:
|
|
2609
|
+
}, minZoom: u, maxZoom: p2 };
|
|
2605
2610
|
}
|
|
2606
|
-
function
|
|
2611
|
+
function ca(e14, t2, a3) {
|
|
2607
2612
|
return Math.min(a3, Math.max(t2, e14));
|
|
2608
2613
|
}
|
|
2609
|
-
function
|
|
2614
|
+
function ua(e14, t2) {
|
|
2610
2615
|
if (!e14 || false === t2.enabled) return () => {
|
|
2611
2616
|
};
|
|
2612
|
-
let a3 = null, s9 = null,
|
|
2617
|
+
let a3 = null, s9 = null, i2 = 0;
|
|
2613
2618
|
const o = () => {
|
|
2614
2619
|
const s10 = e14.querySelector("[data-chapter-scroll-viewport]");
|
|
2615
|
-
return !!s10 && (a3 == null ? void 0 : a3(), a3 = (function({ container: e15, getScale: t3, setScale: a4, minZoom: s11 = 0.5, maxZoom:
|
|
2620
|
+
return !!s10 && (a3 == null ? void 0 : a3(), a3 = (function({ container: e15, getScale: t3, setScale: a4, minZoom: s11 = 0.5, maxZoom: i3 = 3 }) {
|
|
2616
2621
|
let o2 = 0, r2 = 1, n2 = null, l = 1, h2 = 1;
|
|
2617
|
-
const
|
|
2618
|
-
(e16.ctrlKey || e16.metaKey) && (e16.preventDefault(), null === n2 ? (h2 = t3(), l = 1) : clearTimeout(n2), l *= 1 - 0.01 * e16.deltaY, l =
|
|
2622
|
+
const d2 = (e16) => {
|
|
2623
|
+
(e16.ctrlKey || e16.metaKey) && (e16.preventDefault(), null === n2 ? (h2 = t3(), l = 1) : clearTimeout(n2), l *= 1 - 0.01 * e16.deltaY, l = ca(l, 0.1, 10), a4(ca(h2 * l, s11, i3)), n2 = setTimeout(() => {
|
|
2619
2624
|
n2 = null;
|
|
2620
2625
|
}, 120));
|
|
2621
2626
|
}, c = /* @__PURE__ */ new Map(), u = (e16) => {
|
|
@@ -2623,46 +2628,46 @@ function ia(e14, t2) {
|
|
|
2623
2628
|
const [e17, a5] = [...c.values()];
|
|
2624
2629
|
o2 = Math.hypot(a5.x - e17.x, a5.y - e17.y), r2 = t3();
|
|
2625
2630
|
}
|
|
2626
|
-
},
|
|
2631
|
+
}, p2 = (e16) => {
|
|
2627
2632
|
if (c.has(e16.pointerId) && (c.set(e16.pointerId, { x: e16.clientX, y: e16.clientY }), 2 === c.size && o2 > 0)) {
|
|
2628
2633
|
e16.preventDefault();
|
|
2629
2634
|
const [t4, n3] = [...c.values()], l2 = Math.hypot(n3.x - t4.x, n3.y - t4.y);
|
|
2630
|
-
a4(
|
|
2635
|
+
a4(ca(r2 * (l2 / o2), s11, i3));
|
|
2631
2636
|
}
|
|
2632
|
-
},
|
|
2637
|
+
}, g2 = (e16) => {
|
|
2633
2638
|
c.delete(e16.pointerId), c.size < 2 && (o2 = 0);
|
|
2634
2639
|
};
|
|
2635
|
-
return e15.addEventListener("wheel",
|
|
2636
|
-
e15.removeEventListener("wheel",
|
|
2640
|
+
return e15.addEventListener("wheel", d2, { passive: false }), e15.addEventListener("pointerdown", u), e15.addEventListener("pointermove", p2, { passive: false }), e15.addEventListener("pointerup", g2), e15.addEventListener("pointercancel", g2), () => {
|
|
2641
|
+
e15.removeEventListener("wheel", d2), e15.removeEventListener("pointerdown", u), e15.removeEventListener("pointermove", p2), e15.removeEventListener("pointerup", g2), e15.removeEventListener("pointercancel", g2), n2 && clearTimeout(n2);
|
|
2637
2642
|
};
|
|
2638
2643
|
})({ container: s10, getScale: t2.getScale, setScale: t2.setScale, minZoom: t2.minZoom, maxZoom: t2.maxZoom }), true);
|
|
2639
2644
|
};
|
|
2640
2645
|
return o() || (s9 = new MutationObserver(() => {
|
|
2641
2646
|
o() && (s9 == null ? void 0 : s9.disconnect(), s9 = null);
|
|
2642
|
-
}), s9.observe(e14, { childList: true, subtree: true }),
|
|
2643
|
-
|
|
2647
|
+
}), s9.observe(e14, { childList: true, subtree: true }), i2 = requestAnimationFrame(() => o())), () => {
|
|
2648
|
+
i2 && cancelAnimationFrame(i2), s9 == null ? void 0 : s9.disconnect(), a3 == null ? void 0 : a3();
|
|
2644
2649
|
};
|
|
2645
2650
|
}
|
|
2646
|
-
const
|
|
2647
|
-
function
|
|
2648
|
-
const o = ref(null), { provides: r2 } = useCapability(
|
|
2651
|
+
const pa = { chapters: [] };
|
|
2652
|
+
function ga(e14) {
|
|
2653
|
+
const o = ref(null), { provides: r2 } = useCapability(Fe.id), n2 = computed(() => {
|
|
2649
2654
|
var _a2;
|
|
2650
|
-
return ((_a2 = r2.value) == null ? void 0 : _a2.getManifest()) ??
|
|
2655
|
+
return ((_a2 = r2.value) == null ? void 0 : _a2.getManifest()) ?? pa;
|
|
2651
2656
|
}), l = computed(() => {
|
|
2652
2657
|
var _a2;
|
|
2653
2658
|
return (_a2 = e14.value) == null ? void 0 : _a2.zoom;
|
|
2654
|
-
}), { scale: h2, setScale:
|
|
2659
|
+
}), { scale: h2, setScale: d2, zoomEnabled: c, minZoom: u, maxZoom: p2 } = da(n2, l);
|
|
2655
2660
|
return (function(e15, t2) {
|
|
2656
2661
|
let a3 = null;
|
|
2657
2662
|
watch([e15, t2], () => {
|
|
2658
2663
|
a3 == null ? void 0 : a3();
|
|
2659
2664
|
const s9 = t2.value;
|
|
2660
|
-
a3 =
|
|
2665
|
+
a3 = ua(e15.value ?? null, { enabled: s9.enabled, getScale: s9.getScale, setScale: s9.setScale, minZoom: s9.minZoom, maxZoom: s9.maxZoom });
|
|
2661
2666
|
}, { deep: true, flush: "post" }), onBeforeUnmount(() => a3 == null ? void 0 : a3());
|
|
2662
|
-
})(o, computed(() => ({ enabled: c(), getScale: () => h2.value, setScale:
|
|
2667
|
+
})(o, computed(() => ({ enabled: c(), getScale: () => h2.value, setScale: d2, minZoom: u(), maxZoom: p2() }))), { hostRef: o, scale: h2, setScale: d2, zoomEnabled: c };
|
|
2663
2668
|
}
|
|
2664
|
-
const
|
|
2665
|
-
function
|
|
2669
|
+
const fa = { kind: "first-wins" };
|
|
2670
|
+
function ma(e14, t2, a3) {
|
|
2666
2671
|
if (1 === t2.length) return t2[0].chapterId;
|
|
2667
2672
|
switch (a3.kind) {
|
|
2668
2673
|
case "first-wins":
|
|
@@ -2680,7 +2685,7 @@ function la(e14, t2, a3) {
|
|
|
2680
2685
|
return a3.resolve(e14, t2);
|
|
2681
2686
|
}
|
|
2682
2687
|
}
|
|
2683
|
-
|
|
2688
|
+
class va {
|
|
2684
2689
|
constructor(e14) {
|
|
2685
2690
|
this._pages = e14, this._byChapter = /* @__PURE__ */ new Map(), this._byGlobalNumber = /* @__PURE__ */ new Map();
|
|
2686
2691
|
for (const t2 of e14) {
|
|
@@ -2713,38 +2718,38 @@ let ha = class {
|
|
|
2713
2718
|
const a3 = null == (t2 = this._byChapter.get(e14)) ? void 0 : t2[0];
|
|
2714
2719
|
return a3 ? this._pages.indexOf(a3) : -1;
|
|
2715
2720
|
}
|
|
2716
|
-
}
|
|
2717
|
-
function
|
|
2718
|
-
const a3 = (function(e15, t3 =
|
|
2721
|
+
}
|
|
2722
|
+
function ba(e14, t2 = fa) {
|
|
2723
|
+
const a3 = (function(e15, t3 = fa) {
|
|
2719
2724
|
const a4 = /* @__PURE__ */ new Map();
|
|
2720
|
-
for (const
|
|
2721
|
-
const [e16, t4] =
|
|
2725
|
+
for (const i3 of e15.chapters) {
|
|
2726
|
+
const [e16, t4] = i3.globalPageRange;
|
|
2722
2727
|
for (let s11 = e16; s11 <= t4; s11++) {
|
|
2723
2728
|
const e17 = a4.get(s11);
|
|
2724
|
-
e17 ? e17.push(
|
|
2729
|
+
e17 ? e17.push(i3) : a4.set(s11, [i3]);
|
|
2725
2730
|
}
|
|
2726
2731
|
}
|
|
2727
2732
|
const s10 = /* @__PURE__ */ new Map();
|
|
2728
|
-
for (const [
|
|
2733
|
+
for (const [i3, o2] of a4) s10.set(i3, ma(i3, o2, t3));
|
|
2729
2734
|
return s10;
|
|
2730
2735
|
})(e14, t2), s9 = /* @__PURE__ */ new Map();
|
|
2731
2736
|
for (const n2 of e14.chapters) s9.set(n2.chapterId, n2);
|
|
2732
|
-
const
|
|
2737
|
+
const i2 = Array.from(a3.keys()).sort((e15, t3) => e15 - t3), o = [];
|
|
2733
2738
|
let r2 = 0;
|
|
2734
|
-
for (const n2 of
|
|
2739
|
+
for (const n2 of i2) {
|
|
2735
2740
|
const e15 = a3.get(n2), t3 = s9.get(e15);
|
|
2736
2741
|
if (!t3) continue;
|
|
2737
|
-
const [
|
|
2742
|
+
const [i3] = t3.globalPageRange, [l] = t3.localPageRange, h2 = l + (n2 - i3);
|
|
2738
2743
|
o.push({ globalPageIndex: r2++, globalPageNumber: n2, chapterId: e15, localPageIndex: h2 });
|
|
2739
2744
|
}
|
|
2740
|
-
return new
|
|
2745
|
+
return new va(o);
|
|
2741
2746
|
}
|
|
2742
|
-
const
|
|
2747
|
+
const Pa = class e9 extends BasePlugin {
|
|
2743
2748
|
constructor(e14, t2) {
|
|
2744
|
-
super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy =
|
|
2749
|
+
super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = fa, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingLoadPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
|
|
2745
2750
|
}
|
|
2746
2751
|
async initialize(e14) {
|
|
2747
|
-
if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ??
|
|
2752
|
+
if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? fa, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
|
|
2748
2753
|
this.isOwnedChapter(e15.id) && (this.passwordAttempts.delete(e15.id), this.updateStatus(e15.id, "loaded"));
|
|
2749
2754
|
}), this.documentManager.provides().onDocumentClosed((e15) => {
|
|
2750
2755
|
this.isOwnedChapter(e15) && this.updateStatus(e15, "closed");
|
|
@@ -2770,16 +2775,16 @@ const ca = class e9 extends BasePlugin {
|
|
|
2770
2775
|
const t3 = [], a4 = /* @__PURE__ */ new Set();
|
|
2771
2776
|
for (const s10 of e14.chapters) {
|
|
2772
2777
|
a4.has(s10.chapterId) && t3.push(`Duplicate chapterId: ${s10.chapterId}`), a4.add(s10.chapterId);
|
|
2773
|
-
const [e15,
|
|
2774
|
-
if (e15 >
|
|
2778
|
+
const [e15, i3] = s10.globalPageRange, [o, r2] = s10.localPageRange;
|
|
2779
|
+
if (e15 > i3 && t3.push(`${s10.chapterId}: invalid globalPageRange [${e15},${i3}]`), o > r2 && t3.push(`${s10.chapterId}: invalid localPageRange [${o},${r2}]`), i3 - e15 !== r2 - o && t3.push(`${s10.chapterId}: page-count mismatch (global ${i3 - e15 + 1} vs local ${r2 - o + 1})`), s10.ownedGlobalPages) for (const a5 of s10.ownedGlobalPages) (a5 < e15 || a5 > i3) && t3.push(`${s10.chapterId}: ownedGlobalPages contains ${a5} outside range`);
|
|
2775
2780
|
}
|
|
2776
2781
|
return t3;
|
|
2777
2782
|
})(t2);
|
|
2778
2783
|
a3.length > 0 && this.logger.warn(e9.id, "ManifestValidation", `Chapter manifest has issues: ${a3.join("; ")}`);
|
|
2779
|
-
const s9 = new Set(this.chapterStatus.keys()),
|
|
2780
|
-
for (const e14 of s9)
|
|
2784
|
+
const s9 = new Set(this.chapterStatus.keys()), i2 = new Set(t2.chapters.map((e14) => e14.chapterId));
|
|
2785
|
+
for (const e14 of s9) i2.has(e14) || (this.closeChapter(e14), this.chapterStatus.delete(e14));
|
|
2781
2786
|
for (const e14 of t2.chapters) this.chapterStatus.has(e14.chapterId) || this.chapterStatus.set(e14.chapterId, "idle");
|
|
2782
|
-
this.manifest = t2, this.virtualPageMap =
|
|
2787
|
+
this.manifest = t2, this.virtualPageMap = ba(t2, this.overlapStrategy), this.manifestChange$.emit({ manifest: t2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
|
|
2783
2788
|
}
|
|
2784
2789
|
eagerPrefetchFromManifest() {
|
|
2785
2790
|
const e14 = this.config.prefetchChapters ?? 0;
|
|
@@ -2806,20 +2811,20 @@ const ca = class e9 extends BasePlugin {
|
|
|
2806
2811
|
e15 && s9.add(e15.chapterId);
|
|
2807
2812
|
}
|
|
2808
2813
|
if (0 === s9.size) return;
|
|
2809
|
-
const
|
|
2814
|
+
const i2 = this.manifest.chapters.map((e15) => e15.chapterId), o = /* @__PURE__ */ new Set();
|
|
2810
2815
|
for (const n2 of s9) {
|
|
2811
|
-
const e15 =
|
|
2812
|
-
if (-1 !== e15) for (let t3 = e15 - a3; t3 <= e15 + a3; t3++) t3 >= 0 && t3 <
|
|
2816
|
+
const e15 = i2.indexOf(n2);
|
|
2817
|
+
if (-1 !== e15) for (let t3 = e15 - a3; t3 <= e15 + a3; t3++) t3 >= 0 && t3 < i2.length && o.add(t3);
|
|
2813
2818
|
}
|
|
2814
2819
|
const r2 = /* @__PURE__ */ new Set();
|
|
2815
|
-
for (const n2 of o) r2.add(
|
|
2820
|
+
for (const n2 of o) r2.add(i2[n2]);
|
|
2816
2821
|
for (const n2 of r2) {
|
|
2817
2822
|
this.chapterLastUsed.set(n2, t2);
|
|
2818
2823
|
const e15 = this.chapterStatus.get(n2) ?? "idle";
|
|
2819
2824
|
"idle" !== e15 && "closed" !== e15 && "error" !== e15 || this.ensureChapterLoaded(n2);
|
|
2820
2825
|
}
|
|
2821
2826
|
if (this.config.autoActivateOnLoad ?? 1) {
|
|
2822
|
-
const e15 =
|
|
2827
|
+
const e15 = i2.find((e16) => s9.has(e16));
|
|
2823
2828
|
if (e15 && this.documentManager.provides().isDocumentOpen(e15)) {
|
|
2824
2829
|
this.documentManager.provides().getActiveDocumentId() !== e15 && this.documentManager.provides().setActiveDocument(e15);
|
|
2825
2830
|
}
|
|
@@ -2842,10 +2847,10 @@ const ca = class e9 extends BasePlugin {
|
|
|
2842
2847
|
const s9 = this.chapterStatus.get(e14) ?? "idle";
|
|
2843
2848
|
if ("loaded" === s9) return this.chapterLastUsed.set(e14, Date.now()), Promise.resolve("loaded");
|
|
2844
2849
|
if ("loading" === s9) return this.waitForTerminalStatus(e14);
|
|
2845
|
-
const
|
|
2850
|
+
const i2 = this.startLoad(a3).finally(() => {
|
|
2846
2851
|
this.pendingLoadPromises.delete(e14);
|
|
2847
2852
|
});
|
|
2848
|
-
return this.pendingLoadPromises.set(e14,
|
|
2853
|
+
return this.pendingLoadPromises.set(e14, i2), i2;
|
|
2849
2854
|
}
|
|
2850
2855
|
async resolvePdfPayload(e14) {
|
|
2851
2856
|
const t2 = e14.source;
|
|
@@ -2863,17 +2868,17 @@ const ca = class e9 extends BasePlugin {
|
|
|
2863
2868
|
const s9 = t2.chapterId;
|
|
2864
2869
|
this.updateStatus(s9, "loading"), this.chapterLastUsed.set(s9, Date.now());
|
|
2865
2870
|
try {
|
|
2866
|
-
const e14 = t2.encrypted && (null == (a3 = this.passwordProvider) ? void 0 : a3.getCachedPassword) ? this.passwordProvider.getCachedPassword(s9) : null,
|
|
2871
|
+
const e14 = t2.encrypted && (null == (a3 = this.passwordProvider) ? void 0 : a3.getCachedPassword) ? this.passwordProvider.getCachedPassword(s9) : null, i2 = await this.resolvePdfPayload(t2), o = this.documentManager.provides(), r2 = "url" in i2 ? o.openDocumentUrl({ documentId: s9, url: i2.url, name: t2.title, password: e14 ?? void 0, autoActivate: false }) : o.openDocumentBuffer({ documentId: s9, buffer: i2.buffer, name: t2.title, password: e14 ?? void 0, autoActivate: false }), n2 = await new Promise((e15, t3) => {
|
|
2867
2872
|
r2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
2868
2873
|
});
|
|
2869
2874
|
return await new Promise((e15, t3) => {
|
|
2870
2875
|
n2.task.wait(() => e15(), (e16) => t3(e16));
|
|
2871
2876
|
}), o.isDocumentOpen(s9) && this.updateStatus(s9, "loaded"), this.waitForTerminalStatus(s9);
|
|
2872
|
-
} catch (
|
|
2877
|
+
} catch (i2) {
|
|
2873
2878
|
const t3 = this.chapterStatus.get(s9);
|
|
2874
2879
|
if ("loaded" !== t3 && "password-required" !== t3) {
|
|
2875
|
-
const t4 =
|
|
2876
|
-
this.logger.error(e9.id, "LoadChapter", t4,
|
|
2880
|
+
const t4 = i2 instanceof Error ? i2.message : `Failed to load chapter "${s9}"`;
|
|
2881
|
+
this.logger.error(e9.id, "LoadChapter", t4, i2), this.updateStatus(s9, "error", t4);
|
|
2877
2882
|
}
|
|
2878
2883
|
return this.chapterStatus.get(s9) ?? "error";
|
|
2879
2884
|
}
|
|
@@ -2891,13 +2896,13 @@ const ca = class e9 extends BasePlugin {
|
|
|
2891
2896
|
async handleDocumentError(t2, a3, s9) {
|
|
2892
2897
|
if (a3 !== PdfErrorCode.Password) return void this.updateStatus(t2, "error");
|
|
2893
2898
|
if (!this.passwordProvider) return void this.updateStatus(t2, "password-required");
|
|
2894
|
-
const
|
|
2895
|
-
if (!
|
|
2899
|
+
const i2 = this.findChapter(t2);
|
|
2900
|
+
if (!i2) return;
|
|
2896
2901
|
const o = (this.passwordAttempts.get(t2) ?? 0) + 1;
|
|
2897
2902
|
this.passwordAttempts.set(t2, o);
|
|
2898
2903
|
let r2 = null;
|
|
2899
2904
|
try {
|
|
2900
|
-
r2 = await this.passwordProvider.resolvePassword(
|
|
2905
|
+
r2 = await this.passwordProvider.resolvePassword(i2, o - 1);
|
|
2901
2906
|
} catch (n2) {
|
|
2902
2907
|
this.logger.error(e9.id, "PasswordProvider", `Provider rejected for ${t2}`, n2);
|
|
2903
2908
|
}
|
|
@@ -2917,20 +2922,20 @@ const ca = class e9 extends BasePlugin {
|
|
|
2917
2922
|
this.chapterStatus.get(e14) !== t2 && (this.chapterStatus.set(e14, t2), this.statusChange$.emit({ chapterId: e14, status: t2, ..."error" === t2 && a3 ? { error: { message: a3 } } : {} }));
|
|
2918
2923
|
}
|
|
2919
2924
|
};
|
|
2920
|
-
|
|
2921
|
-
let
|
|
2922
|
-
function
|
|
2925
|
+
Pa.id = "chapter-manager";
|
|
2926
|
+
let wa = Pa;
|
|
2927
|
+
function ya(e14, t2) {
|
|
2923
2928
|
if (e14 === t2) return true;
|
|
2924
2929
|
if (e14.totalHeight !== t2.totalHeight || e14.totalWidth !== t2.totalWidth || e14.pageGap !== t2.pageGap || e14.items.length !== t2.items.length) return false;
|
|
2925
2930
|
for (let a3 = 0; a3 < e14.items.length; a3++) {
|
|
2926
|
-
const s9 = e14.items[a3],
|
|
2927
|
-
if (s9.globalPageIndex !==
|
|
2931
|
+
const s9 = e14.items[a3], i2 = t2.items[a3];
|
|
2932
|
+
if (s9.globalPageIndex !== i2.globalPageIndex || s9.isPlaceholder !== i2.isPlaceholder || s9.chapterId !== i2.chapterId || s9.localPageIndex !== i2.localPageIndex || s9.offsetTop !== i2.offsetTop || s9.width !== i2.width || s9.height !== i2.height) return false;
|
|
2928
2933
|
}
|
|
2929
2934
|
return true;
|
|
2930
2935
|
}
|
|
2931
|
-
const
|
|
2936
|
+
const Ca = class extends BasePlugin {
|
|
2932
2937
|
constructor(e14, t2) {
|
|
2933
|
-
super(e14, t2), this.layoutChange$ = createBehaviorEmitter(void 0,
|
|
2938
|
+
super(e14, t2), this.layoutChange$ = createBehaviorEmitter(void 0, ya), 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.chapterManagerUnsubs = [], this.chapterManager = this.registry.getPlugin(wa.id), this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
|
|
2934
2939
|
}
|
|
2935
2940
|
async initialize(e14) {
|
|
2936
2941
|
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 }) => {
|
|
@@ -2984,8 +2989,8 @@ const ga = class extends BasePlugin {
|
|
|
2984
2989
|
this.offsets = new Array(e14);
|
|
2985
2990
|
let t2 = 0, a3 = 0;
|
|
2986
2991
|
for (let s9 = 0; s9 < e14; s9++) {
|
|
2987
|
-
const { width: e15, height:
|
|
2988
|
-
this.offsets[s9] = t2, t2 +=
|
|
2992
|
+
const { width: e15, height: i2 } = this.getPageSize(s9);
|
|
2993
|
+
this.offsets[s9] = t2, t2 += i2 + this.config.pageGap, e15 > a3 && (a3 = e15);
|
|
2989
2994
|
}
|
|
2990
2995
|
this.totalHeight = e14 > 0 ? t2 - this.config.pageGap : 0, this.totalWidth = a3, this.layoutChange$.emit(this.computeLayout());
|
|
2991
2996
|
}
|
|
@@ -2995,8 +3000,8 @@ const ga = class extends BasePlugin {
|
|
|
2995
3000
|
for (const s9 of t2) {
|
|
2996
3001
|
const t3 = this.virtualPageMap.toGlobal(e14, s9.localPageIndex);
|
|
2997
3002
|
if (!t3) continue;
|
|
2998
|
-
const
|
|
2999
|
-
|
|
3003
|
+
const i2 = this.pageSizes.get(t3.globalPageIndex);
|
|
3004
|
+
i2 && i2.width === s9.width && i2.height === s9.height || (this.pageSizes.set(t3.globalPageIndex, { width: s9.width, height: s9.height }), a3 = true);
|
|
3000
3005
|
}
|
|
3001
3006
|
if (a3) {
|
|
3002
3007
|
const e15 = this.currentGlobalPageIndex, t3 = this.offsets[e15] ?? 0;
|
|
@@ -3014,10 +3019,10 @@ const ga = class extends BasePlugin {
|
|
|
3014
3019
|
harvestChapterSizes(e14, t2 = 0) {
|
|
3015
3020
|
var a3;
|
|
3016
3021
|
if (!this.virtualPageMap) return;
|
|
3017
|
-
const s9 = this.documentManager.provides().getDocument(e14),
|
|
3018
|
-
if (!(null == (a3 = null == s9 ? void 0 : s9.pages) ? void 0 : a3.length) || 0 ===
|
|
3022
|
+
const s9 = this.documentManager.provides().getDocument(e14), i2 = this.virtualPageMap.pagesOfChapter(e14);
|
|
3023
|
+
if (!(null == (a3 = null == s9 ? void 0 : s9.pages) ? void 0 : a3.length) || 0 === i2.length) return void (t2 < 60 && requestAnimationFrame(() => this.harvestChapterSizes(e14, t2 + 1)));
|
|
3019
3024
|
const o = this.getChapterDocumentScale(e14), r2 = [];
|
|
3020
|
-
for (const n2 of
|
|
3025
|
+
for (const n2 of i2) {
|
|
3021
3026
|
const e15 = s9.pages[n2.localPageIndex];
|
|
3022
3027
|
(null == e15 ? void 0 : e15.size) && r2.push({ localPageIndex: n2.localPageIndex, width: e15.size.width * o, height: e15.size.height * o });
|
|
3023
3028
|
}
|
|
@@ -3048,38 +3053,38 @@ const ga = class extends BasePlugin {
|
|
|
3048
3053
|
const e14 = this.virtualPageMap.totalPages;
|
|
3049
3054
|
if (0 === e14) return this.currentVisible = [], this.currentGlobalPageIndex = 0, void this.layoutChange$.emit(this.computeLayout());
|
|
3050
3055
|
const t2 = this.viewportEl.scrollTop, a3 = t2 + this.viewportEl.clientHeight, s9 = this.findFirstVisibleIndex(t2);
|
|
3051
|
-
let
|
|
3052
|
-
for (;
|
|
3053
|
-
const e15 = this.getPageSize(
|
|
3056
|
+
let i2 = s9;
|
|
3057
|
+
for (; i2 < e14; ) {
|
|
3058
|
+
const e15 = this.getPageSize(i2), t3 = this.offsets[i2];
|
|
3054
3059
|
if (e15.height, t3 >= a3) break;
|
|
3055
|
-
|
|
3060
|
+
i2++;
|
|
3056
3061
|
}
|
|
3057
3062
|
const o = [];
|
|
3058
3063
|
let r2 = s9, n2 = -1;
|
|
3059
|
-
for (let l = s9; l <
|
|
3064
|
+
for (let l = s9; l < i2; l++) {
|
|
3060
3065
|
o.push(l);
|
|
3061
|
-
const e15 = this.offsets[l], s10 = e15 + this.getPageSize(l).height,
|
|
3062
|
-
|
|
3066
|
+
const e15 = this.offsets[l], s10 = e15 + this.getPageSize(l).height, i3 = Math.max(0, Math.min(s10, a3) - Math.max(e15, t2));
|
|
3067
|
+
i3 > n2 && (n2 = i3, r2 = l);
|
|
3063
3068
|
}
|
|
3064
3069
|
this.currentVisible = o, this.currentGlobalPageIndex = r2, this.visibleChange$.emit({ visibleGlobalPageIndices: o, currentGlobalPageIndex: r2 }), this.chapterManager.provides().setVisibleGlobalPages(o), this.layoutChange$.emit(this.computeLayout());
|
|
3065
3070
|
}
|
|
3066
3071
|
findFirstVisibleIndex(e14) {
|
|
3067
3072
|
let t2 = 0, a3 = this.offsets.length - 1, s9 = 0;
|
|
3068
3073
|
for (; t2 <= a3; ) {
|
|
3069
|
-
const
|
|
3070
|
-
this.offsets[
|
|
3074
|
+
const i2 = t2 + a3 >> 1;
|
|
3075
|
+
this.offsets[i2] <= e14 ? (s9 = i2, t2 = i2 + 1) : a3 = i2 - 1;
|
|
3071
3076
|
}
|
|
3072
3077
|
return s9;
|
|
3073
3078
|
}
|
|
3074
3079
|
computeLayout() {
|
|
3075
|
-
const e14 = this.config.bufferSize, t2 = Math.max(0, (this.currentVisible[0] ?? 0) - e14), a3 = this.currentVisible[this.currentVisible.length - 1] ?? -1, s9 = Math.min(this.offsets.length - 1, (a3 >= 0 ? a3 : 0) + e14),
|
|
3080
|
+
const e14 = this.config.bufferSize, t2 = Math.max(0, (this.currentVisible[0] ?? 0) - e14), a3 = this.currentVisible[this.currentVisible.length - 1] ?? -1, s9 = Math.min(this.offsets.length - 1, (a3 >= 0 ? a3 : 0) + e14), i2 = [];
|
|
3076
3081
|
if (this.virtualPageMap && this.offsets.length > 0) for (let o = t2; o <= s9; o++) {
|
|
3077
3082
|
const e15 = this.virtualPageMap.atIndex(o);
|
|
3078
3083
|
if (!e15) continue;
|
|
3079
3084
|
const t3 = this.getPageSize(o), a4 = this.isChapterPagePlaceholder(e15.chapterId);
|
|
3080
|
-
|
|
3085
|
+
i2.push({ globalPageIndex: o, globalPageNumber: e15.globalPageNumber, chapterId: e15.chapterId, localPageIndex: e15.localPageIndex, width: t3.width, height: t3.height, offsetTop: this.offsets[o], isPlaceholder: a4 });
|
|
3081
3086
|
}
|
|
3082
|
-
return { totalHeight: this.totalHeight, totalWidth: this.totalWidth || this.config.placeholderPageWidth, items:
|
|
3087
|
+
return { totalHeight: this.totalHeight, totalWidth: this.totalWidth || this.config.placeholderPageWidth, items: i2, pageGap: this.config.pageGap };
|
|
3083
3088
|
}
|
|
3084
3089
|
scrollToIndex(e14, t2) {
|
|
3085
3090
|
if (!this.viewportEl || e14 < 0 || e14 >= this.offsets.length) return;
|
|
@@ -3089,11 +3094,11 @@ const ga = class extends BasePlugin {
|
|
|
3089
3094
|
scrollToGlobalPdfPoint(e14, t2, a3) {
|
|
3090
3095
|
var s9;
|
|
3091
3096
|
if (!this.viewportEl || e14 < 0 || e14 >= this.offsets.length || !this.virtualPageMap) return;
|
|
3092
|
-
const
|
|
3097
|
+
const i2 = (null == a3 ? void 0 : a3.marginTop) ?? 80, o = this.virtualPageMap.atIndex(e14);
|
|
3093
3098
|
if (!o) return void this.scrollToIndex(e14, a3);
|
|
3094
3099
|
const r2 = this.pageSizes.get(e14), n2 = null == (s9 = this.documentManager.provides().getDocument(o.chapterId)) ? void 0 : s9.pages[o.localPageIndex];
|
|
3095
3100
|
if (!r2 || !n2) return void this.scrollToIndex(e14, a3);
|
|
3096
|
-
const l = r2.height / n2.size.height, h2 = (this.offsets[e14] ?? 0) + t2 * l -
|
|
3101
|
+
const l = r2.height / n2.size.height, h2 = (this.offsets[e14] ?? 0) + t2 * l - i2;
|
|
3097
3102
|
this.viewportEl.scrollTo({ top: Math.max(0, h2), behavior: (null == a3 ? void 0 : a3.behavior) ?? "auto" });
|
|
3098
3103
|
}
|
|
3099
3104
|
scrollToChapter(e14, t2) {
|
|
@@ -3107,14 +3112,14 @@ const ga = class extends BasePlugin {
|
|
|
3107
3112
|
a3 && this.scrollToIndex(a3.globalPageIndex, t2);
|
|
3108
3113
|
}
|
|
3109
3114
|
};
|
|
3110
|
-
|
|
3111
|
-
let
|
|
3112
|
-
const
|
|
3115
|
+
Ca.id = "chapter-scroll";
|
|
3116
|
+
let Ia = Ca;
|
|
3117
|
+
const Ma = ["data-global-page-index", "data-chapter-id", "data-local-page-index"], Sa = /* @__PURE__ */ ((e14, t2) => {
|
|
3113
3118
|
const a3 = e14.__vccOpts || e14;
|
|
3114
|
-
for (const [s9,
|
|
3119
|
+
for (const [s9, i2] of t2) a3[s9] = i2;
|
|
3115
3120
|
return a3;
|
|
3116
3121
|
})(/* @__PURE__ */ defineComponent({ __name: "ChapterScroller", props: { class: {}, style: {} }, setup(e14) {
|
|
3117
|
-
const { provides: t2 } = useCapability(
|
|
3122
|
+
const { provides: t2 } = useCapability(Ia.id), o = ref(null), f = ref(null);
|
|
3118
3123
|
let m = null;
|
|
3119
3124
|
const v = () => {
|
|
3120
3125
|
null == m || m(), m = null, t2.value && (t2.value.registerViewport(o.value), m = t2.value.onLayoutChange((e15) => {
|
|
@@ -3125,12 +3130,12 @@ const ma = ["data-global-page-index", "data-chapter-id", "data-local-page-index"
|
|
|
3125
3130
|
var e15;
|
|
3126
3131
|
null == m || m(), null == (e15 = t2.value) || e15.registerViewport(null);
|
|
3127
3132
|
}), watch(t2, v), (e15, t3) => {
|
|
3128
|
-
var a3, s9,
|
|
3129
|
-
return openBlock(), createElementBlock("div", { ref_key: "containerRef", ref: o, "data-chapter-scroll-viewport": "", class: normalizeClass(e15.$props.class), style: normalizeStyle({ overflow: "auto", position: "relative", width: "100%", height: "100%", ...e15.$props.style }) }, [createElementVNode("div", { style: normalizeStyle({ position: "relative", width: `${(null == (a3 = f.value) ? void 0 : a3.totalWidth) ?? 0}px`, height: `${(null == (s9 = f.value) ? void 0 : s9.totalHeight) ?? 0}px`, margin: "0 auto" }) }, [(openBlock(true), createElementBlock(Fragment, null, renderList((null == (
|
|
3133
|
+
var a3, s9, i2;
|
|
3134
|
+
return openBlock(), createElementBlock("div", { ref_key: "containerRef", ref: o, "data-chapter-scroll-viewport": "", class: normalizeClass(e15.$props.class), style: normalizeStyle({ overflow: "auto", position: "relative", width: "100%", height: "100%", ...e15.$props.style }) }, [createElementVNode("div", { style: normalizeStyle({ position: "relative", width: `${(null == (a3 = f.value) ? void 0 : a3.totalWidth) ?? 0}px`, height: `${(null == (s9 = f.value) ? void 0 : s9.totalHeight) ?? 0}px`, margin: "0 auto" }) }, [(openBlock(true), createElementBlock(Fragment, null, renderList((null == (i2 = f.value) ? void 0 : i2.items) ?? [], (a4) => (openBlock(), createElementBlock("div", { key: a4.globalPageIndex, "data-global-page-index": a4.globalPageIndex, "data-chapter-id": a4.chapterId, "data-local-page-index": a4.localPageIndex, style: normalizeStyle({ position: "absolute", top: `${a4.offsetTop}px`, left: "50%", transform: "translateX(-50%)", width: `${a4.width}px`, height: `${a4.height}px`, backgroundColor: a4.isPlaceholder ? "#f3f4f6" : "#fff", boxShadow: "0 1px 4px rgba(0,0,0,0.08)" }) }, [a4.isPlaceholder ? renderSlot(e15.$slots, "placeholder", { key: 0, item: a4 }, () => [t3[0] || (t3[0] = createElementVNode("div", { class: "chapter-scroll-placeholder" }, "Loading chapter…", -1))], true) : renderSlot(e15.$slots, "page", { key: 1, item: a4 }, void 0, true)], 12, Ma))), 128))], 4)], 6);
|
|
3130
3135
|
};
|
|
3131
|
-
} }), [["__scopeId", "data-v-8a737137"]]),
|
|
3132
|
-
const
|
|
3133
|
-
function
|
|
3136
|
+
} }), [["__scopeId", "data-v-8a737137"]]), xa = /* @__PURE__ */ defineComponent({ __name: "ChapterRenderLayer", props: { chapterId: {}, localPageIndex: {}, scale: {}, dpr: {}, class: {} }, setup: (e14) => (t2, a3) => (openBlock(), createBlock(unref(RenderLayer), { "document-id": e14.chapterId, "page-index": e14.localPageIndex, scale: e14.scale, dpr: e14.dpr, class: normalizeClass(e14.class), style: { pointerEvents: "none" } }, null, 8, ["document-id", "page-index", "scale", "dpr", "class"])) });
|
|
3137
|
+
const ka = { kind: "first-wins" };
|
|
3138
|
+
function La(e14, t2, a3) {
|
|
3134
3139
|
if (1 === t2.length) return t2[0].chapterId;
|
|
3135
3140
|
switch (a3.kind) {
|
|
3136
3141
|
case "first-wins":
|
|
@@ -3148,7 +3153,7 @@ function wa(e14, t2, a3) {
|
|
|
3148
3153
|
return a3.resolve(e14, t2);
|
|
3149
3154
|
}
|
|
3150
3155
|
}
|
|
3151
|
-
let
|
|
3156
|
+
let $a = class {
|
|
3152
3157
|
constructor(e14) {
|
|
3153
3158
|
this._pages = e14, this._byChapter = /* @__PURE__ */ new Map(), this._byGlobalNumber = /* @__PURE__ */ new Map();
|
|
3154
3159
|
for (const t2 of e14) {
|
|
@@ -3182,37 +3187,37 @@ let ya = class {
|
|
|
3182
3187
|
return a3 ? this._pages.indexOf(a3) : -1;
|
|
3183
3188
|
}
|
|
3184
3189
|
};
|
|
3185
|
-
function
|
|
3186
|
-
const a3 = (function(e15, t3 =
|
|
3190
|
+
function za(e14, t2 = ka) {
|
|
3191
|
+
const a3 = (function(e15, t3 = ka) {
|
|
3187
3192
|
const a4 = /* @__PURE__ */ new Map();
|
|
3188
|
-
for (const
|
|
3189
|
-
const [e16, t4] =
|
|
3193
|
+
for (const i3 of e15.chapters) {
|
|
3194
|
+
const [e16, t4] = i3.globalPageRange;
|
|
3190
3195
|
for (let s11 = e16; s11 <= t4; s11++) {
|
|
3191
3196
|
const e17 = a4.get(s11);
|
|
3192
|
-
e17 ? e17.push(
|
|
3197
|
+
e17 ? e17.push(i3) : a4.set(s11, [i3]);
|
|
3193
3198
|
}
|
|
3194
3199
|
}
|
|
3195
3200
|
const s10 = /* @__PURE__ */ new Map();
|
|
3196
|
-
for (const [
|
|
3201
|
+
for (const [i3, o2] of a4) s10.set(i3, La(i3, o2, t3));
|
|
3197
3202
|
return s10;
|
|
3198
3203
|
})(e14, t2), s9 = /* @__PURE__ */ new Map();
|
|
3199
3204
|
for (const n2 of e14.chapters) s9.set(n2.chapterId, n2);
|
|
3200
|
-
const
|
|
3205
|
+
const i2 = Array.from(a3.keys()).sort((e15, t3) => e15 - t3), o = [];
|
|
3201
3206
|
let r2 = 0;
|
|
3202
|
-
for (const n2 of
|
|
3207
|
+
for (const n2 of i2) {
|
|
3203
3208
|
const e15 = a3.get(n2), t3 = s9.get(e15);
|
|
3204
3209
|
if (!t3) continue;
|
|
3205
|
-
const [
|
|
3210
|
+
const [i3] = t3.globalPageRange, [l] = t3.localPageRange, h2 = l + (n2 - i3);
|
|
3206
3211
|
o.push({ globalPageIndex: r2++, globalPageNumber: n2, chapterId: e15, localPageIndex: h2 });
|
|
3207
3212
|
}
|
|
3208
|
-
return new
|
|
3213
|
+
return new $a(o);
|
|
3209
3214
|
}
|
|
3210
|
-
const
|
|
3215
|
+
const Ta = class e10 extends BasePlugin {
|
|
3211
3216
|
constructor(e14, t2) {
|
|
3212
|
-
super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy =
|
|
3217
|
+
super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = ka, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingLoadPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
|
|
3213
3218
|
}
|
|
3214
3219
|
async initialize(e14) {
|
|
3215
|
-
if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ??
|
|
3220
|
+
if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? ka, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
|
|
3216
3221
|
this.isOwnedChapter(e15.id) && (this.passwordAttempts.delete(e15.id), this.updateStatus(e15.id, "loaded"));
|
|
3217
3222
|
}), this.documentManager.provides().onDocumentClosed((e15) => {
|
|
3218
3223
|
this.isOwnedChapter(e15) && this.updateStatus(e15, "closed");
|
|
@@ -3238,16 +3243,16 @@ const Ia = class e10 extends BasePlugin {
|
|
|
3238
3243
|
const t3 = [], a4 = /* @__PURE__ */ new Set();
|
|
3239
3244
|
for (const s10 of e14.chapters) {
|
|
3240
3245
|
a4.has(s10.chapterId) && t3.push(`Duplicate chapterId: ${s10.chapterId}`), a4.add(s10.chapterId);
|
|
3241
|
-
const [e15,
|
|
3242
|
-
if (e15 >
|
|
3246
|
+
const [e15, i3] = s10.globalPageRange, [o, r2] = s10.localPageRange;
|
|
3247
|
+
if (e15 > i3 && t3.push(`${s10.chapterId}: invalid globalPageRange [${e15},${i3}]`), o > r2 && t3.push(`${s10.chapterId}: invalid localPageRange [${o},${r2}]`), i3 - e15 !== r2 - o && t3.push(`${s10.chapterId}: page-count mismatch (global ${i3 - e15 + 1} vs local ${r2 - o + 1})`), s10.ownedGlobalPages) for (const a5 of s10.ownedGlobalPages) (a5 < e15 || a5 > i3) && t3.push(`${s10.chapterId}: ownedGlobalPages contains ${a5} outside range`);
|
|
3243
3248
|
}
|
|
3244
3249
|
return t3;
|
|
3245
3250
|
})(t2);
|
|
3246
3251
|
a3.length > 0 && this.logger.warn(e10.id, "ManifestValidation", `Chapter manifest has issues: ${a3.join("; ")}`);
|
|
3247
|
-
const s9 = new Set(this.chapterStatus.keys()),
|
|
3248
|
-
for (const e14 of s9)
|
|
3252
|
+
const s9 = new Set(this.chapterStatus.keys()), i2 = new Set(t2.chapters.map((e14) => e14.chapterId));
|
|
3253
|
+
for (const e14 of s9) i2.has(e14) || (this.closeChapter(e14), this.chapterStatus.delete(e14));
|
|
3249
3254
|
for (const e14 of t2.chapters) this.chapterStatus.has(e14.chapterId) || this.chapterStatus.set(e14.chapterId, "idle");
|
|
3250
|
-
this.manifest = t2, this.virtualPageMap =
|
|
3255
|
+
this.manifest = t2, this.virtualPageMap = za(t2, this.overlapStrategy), this.manifestChange$.emit({ manifest: t2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
|
|
3251
3256
|
}
|
|
3252
3257
|
eagerPrefetchFromManifest() {
|
|
3253
3258
|
const e14 = this.config.prefetchChapters ?? 0;
|
|
@@ -3274,20 +3279,20 @@ const Ia = class e10 extends BasePlugin {
|
|
|
3274
3279
|
e15 && s9.add(e15.chapterId);
|
|
3275
3280
|
}
|
|
3276
3281
|
if (0 === s9.size) return;
|
|
3277
|
-
const
|
|
3282
|
+
const i2 = this.manifest.chapters.map((e15) => e15.chapterId), o = /* @__PURE__ */ new Set();
|
|
3278
3283
|
for (const n2 of s9) {
|
|
3279
|
-
const e15 =
|
|
3280
|
-
if (-1 !== e15) for (let t3 = e15 - a3; t3 <= e15 + a3; t3++) t3 >= 0 && t3 <
|
|
3284
|
+
const e15 = i2.indexOf(n2);
|
|
3285
|
+
if (-1 !== e15) for (let t3 = e15 - a3; t3 <= e15 + a3; t3++) t3 >= 0 && t3 < i2.length && o.add(t3);
|
|
3281
3286
|
}
|
|
3282
3287
|
const r2 = /* @__PURE__ */ new Set();
|
|
3283
|
-
for (const n2 of o) r2.add(
|
|
3288
|
+
for (const n2 of o) r2.add(i2[n2]);
|
|
3284
3289
|
for (const n2 of r2) {
|
|
3285
3290
|
this.chapterLastUsed.set(n2, t2);
|
|
3286
3291
|
const e15 = this.chapterStatus.get(n2) ?? "idle";
|
|
3287
3292
|
"idle" !== e15 && "closed" !== e15 && "error" !== e15 || this.ensureChapterLoaded(n2);
|
|
3288
3293
|
}
|
|
3289
3294
|
if (this.config.autoActivateOnLoad ?? 1) {
|
|
3290
|
-
const e15 =
|
|
3295
|
+
const e15 = i2.find((e16) => s9.has(e16));
|
|
3291
3296
|
if (e15 && this.documentManager.provides().isDocumentOpen(e15)) {
|
|
3292
3297
|
this.documentManager.provides().getActiveDocumentId() !== e15 && this.documentManager.provides().setActiveDocument(e15);
|
|
3293
3298
|
}
|
|
@@ -3310,10 +3315,10 @@ const Ia = class e10 extends BasePlugin {
|
|
|
3310
3315
|
const s9 = this.chapterStatus.get(e14) ?? "idle";
|
|
3311
3316
|
if ("loaded" === s9) return this.chapterLastUsed.set(e14, Date.now()), Promise.resolve("loaded");
|
|
3312
3317
|
if ("loading" === s9) return this.waitForTerminalStatus(e14);
|
|
3313
|
-
const
|
|
3318
|
+
const i2 = this.startLoad(a3).finally(() => {
|
|
3314
3319
|
this.pendingLoadPromises.delete(e14);
|
|
3315
3320
|
});
|
|
3316
|
-
return this.pendingLoadPromises.set(e14,
|
|
3321
|
+
return this.pendingLoadPromises.set(e14, i2), i2;
|
|
3317
3322
|
}
|
|
3318
3323
|
async resolvePdfPayload(e14) {
|
|
3319
3324
|
const t2 = e14.source;
|
|
@@ -3331,17 +3336,17 @@ const Ia = class e10 extends BasePlugin {
|
|
|
3331
3336
|
const s9 = t2.chapterId;
|
|
3332
3337
|
this.updateStatus(s9, "loading"), this.chapterLastUsed.set(s9, Date.now());
|
|
3333
3338
|
try {
|
|
3334
|
-
const e14 = t2.encrypted && (null == (a3 = this.passwordProvider) ? void 0 : a3.getCachedPassword) ? this.passwordProvider.getCachedPassword(s9) : null,
|
|
3339
|
+
const e14 = t2.encrypted && (null == (a3 = this.passwordProvider) ? void 0 : a3.getCachedPassword) ? this.passwordProvider.getCachedPassword(s9) : null, i2 = await this.resolvePdfPayload(t2), o = this.documentManager.provides(), r2 = "url" in i2 ? o.openDocumentUrl({ documentId: s9, url: i2.url, name: t2.title, password: e14 ?? void 0, autoActivate: false }) : o.openDocumentBuffer({ documentId: s9, buffer: i2.buffer, name: t2.title, password: e14 ?? void 0, autoActivate: false }), n2 = await new Promise((e15, t3) => {
|
|
3335
3340
|
r2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
3336
3341
|
});
|
|
3337
3342
|
return await new Promise((e15, t3) => {
|
|
3338
3343
|
n2.task.wait(() => e15(), (e16) => t3(e16));
|
|
3339
3344
|
}), o.isDocumentOpen(s9) && this.updateStatus(s9, "loaded"), this.waitForTerminalStatus(s9);
|
|
3340
|
-
} catch (
|
|
3345
|
+
} catch (i2) {
|
|
3341
3346
|
const t3 = this.chapterStatus.get(s9);
|
|
3342
3347
|
if ("loaded" !== t3 && "password-required" !== t3) {
|
|
3343
|
-
const t4 =
|
|
3344
|
-
this.logger.error(e10.id, "LoadChapter", t4,
|
|
3348
|
+
const t4 = i2 instanceof Error ? i2.message : `Failed to load chapter "${s9}"`;
|
|
3349
|
+
this.logger.error(e10.id, "LoadChapter", t4, i2), this.updateStatus(s9, "error", t4);
|
|
3345
3350
|
}
|
|
3346
3351
|
return this.chapterStatus.get(s9) ?? "error";
|
|
3347
3352
|
}
|
|
@@ -3359,13 +3364,13 @@ const Ia = class e10 extends BasePlugin {
|
|
|
3359
3364
|
async handleDocumentError(t2, a3, s9) {
|
|
3360
3365
|
if (a3 !== PdfErrorCode.Password) return void this.updateStatus(t2, "error");
|
|
3361
3366
|
if (!this.passwordProvider) return void this.updateStatus(t2, "password-required");
|
|
3362
|
-
const
|
|
3363
|
-
if (!
|
|
3367
|
+
const i2 = this.findChapter(t2);
|
|
3368
|
+
if (!i2) return;
|
|
3364
3369
|
const o = (this.passwordAttempts.get(t2) ?? 0) + 1;
|
|
3365
3370
|
this.passwordAttempts.set(t2, o);
|
|
3366
3371
|
let r2 = null;
|
|
3367
3372
|
try {
|
|
3368
|
-
r2 = await this.passwordProvider.resolvePassword(
|
|
3373
|
+
r2 = await this.passwordProvider.resolvePassword(i2, o - 1);
|
|
3369
3374
|
} catch (n2) {
|
|
3370
3375
|
this.logger.error(e10.id, "PasswordProvider", `Provider rejected for ${t2}`, n2);
|
|
3371
3376
|
}
|
|
@@ -3385,10 +3390,10 @@ const Ia = class e10 extends BasePlugin {
|
|
|
3385
3390
|
this.chapterStatus.get(e14) !== t2 && (this.chapterStatus.set(e14, t2), this.statusChange$.emit({ chapterId: e14, status: t2, ..."error" === t2 && a3 ? { error: { message: a3 } } : {} }));
|
|
3386
3391
|
}
|
|
3387
3392
|
};
|
|
3388
|
-
|
|
3389
|
-
let
|
|
3390
|
-
const
|
|
3391
|
-
function
|
|
3393
|
+
Ta.id = "chapter-manager";
|
|
3394
|
+
let Da = Ta;
|
|
3395
|
+
const Oa = { kind: "first-wins" };
|
|
3396
|
+
function Ga(e14, t2, a3) {
|
|
3392
3397
|
if (1 === t2.length) return t2[0].chapterId;
|
|
3393
3398
|
switch (a3.kind) {
|
|
3394
3399
|
case "first-wins":
|
|
@@ -3406,7 +3411,7 @@ function xa(e14, t2, a3) {
|
|
|
3406
3411
|
return a3.resolve(e14, t2);
|
|
3407
3412
|
}
|
|
3408
3413
|
}
|
|
3409
|
-
class
|
|
3414
|
+
class Na {
|
|
3410
3415
|
constructor(e14) {
|
|
3411
3416
|
this._pages = e14, this._byChapter = /* @__PURE__ */ new Map(), this._byGlobalNumber = /* @__PURE__ */ new Map();
|
|
3412
3417
|
for (const t2 of e14) {
|
|
@@ -3440,37 +3445,37 @@ class ka {
|
|
|
3440
3445
|
return a3 ? this._pages.indexOf(a3) : -1;
|
|
3441
3446
|
}
|
|
3442
3447
|
}
|
|
3443
|
-
function
|
|
3444
|
-
const a3 = (function(e15, t3 =
|
|
3448
|
+
function Aa(e14, t2 = Oa) {
|
|
3449
|
+
const a3 = (function(e15, t3 = Oa) {
|
|
3445
3450
|
const a4 = /* @__PURE__ */ new Map();
|
|
3446
|
-
for (const
|
|
3447
|
-
const [e16, t4] =
|
|
3451
|
+
for (const i3 of e15.chapters) {
|
|
3452
|
+
const [e16, t4] = i3.globalPageRange;
|
|
3448
3453
|
for (let s11 = e16; s11 <= t4; s11++) {
|
|
3449
3454
|
const e17 = a4.get(s11);
|
|
3450
|
-
e17 ? e17.push(
|
|
3455
|
+
e17 ? e17.push(i3) : a4.set(s11, [i3]);
|
|
3451
3456
|
}
|
|
3452
3457
|
}
|
|
3453
3458
|
const s10 = /* @__PURE__ */ new Map();
|
|
3454
|
-
for (const [
|
|
3459
|
+
for (const [i3, o2] of a4) s10.set(i3, Ga(i3, o2, t3));
|
|
3455
3460
|
return s10;
|
|
3456
3461
|
})(e14, t2), s9 = /* @__PURE__ */ new Map();
|
|
3457
3462
|
for (const n2 of e14.chapters) s9.set(n2.chapterId, n2);
|
|
3458
|
-
const
|
|
3463
|
+
const i2 = Array.from(a3.keys()).sort((e15, t3) => e15 - t3), o = [];
|
|
3459
3464
|
let r2 = 0;
|
|
3460
|
-
for (const n2 of
|
|
3465
|
+
for (const n2 of i2) {
|
|
3461
3466
|
const e15 = a3.get(n2), t3 = s9.get(e15);
|
|
3462
3467
|
if (!t3) continue;
|
|
3463
|
-
const [
|
|
3468
|
+
const [i3] = t3.globalPageRange, [l] = t3.localPageRange, h2 = l + (n2 - i3);
|
|
3464
3469
|
o.push({ globalPageIndex: r2++, globalPageNumber: n2, chapterId: e15, localPageIndex: h2 });
|
|
3465
3470
|
}
|
|
3466
|
-
return new
|
|
3471
|
+
return new Na(o);
|
|
3467
3472
|
}
|
|
3468
|
-
const
|
|
3473
|
+
const Va = class e11 extends BasePlugin {
|
|
3469
3474
|
constructor(e14, t2) {
|
|
3470
|
-
super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy =
|
|
3475
|
+
super(e14, t2), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = Oa, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingLoadPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
|
|
3471
3476
|
}
|
|
3472
3477
|
async initialize(e14) {
|
|
3473
|
-
if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ??
|
|
3478
|
+
if (this.config = e14, this.passwordProvider = e14.passwordProvider, this.overlapStrategy = e14.overlapStrategy ?? Oa, this.documentManagerUnsubs.push(this.documentManager.provides().onDocumentOpened((e15) => {
|
|
3474
3479
|
this.isOwnedChapter(e15.id) && (this.passwordAttempts.delete(e15.id), this.updateStatus(e15.id, "loaded"));
|
|
3475
3480
|
}), this.documentManager.provides().onDocumentClosed((e15) => {
|
|
3476
3481
|
this.isOwnedChapter(e15) && this.updateStatus(e15, "closed");
|
|
@@ -3496,16 +3501,16 @@ const $a = class e11 extends BasePlugin {
|
|
|
3496
3501
|
const t3 = [], a4 = /* @__PURE__ */ new Set();
|
|
3497
3502
|
for (const s10 of e14.chapters) {
|
|
3498
3503
|
a4.has(s10.chapterId) && t3.push(`Duplicate chapterId: ${s10.chapterId}`), a4.add(s10.chapterId);
|
|
3499
|
-
const [e15,
|
|
3500
|
-
if (e15 >
|
|
3504
|
+
const [e15, i3] = s10.globalPageRange, [o, r2] = s10.localPageRange;
|
|
3505
|
+
if (e15 > i3 && t3.push(`${s10.chapterId}: invalid globalPageRange [${e15},${i3}]`), o > r2 && t3.push(`${s10.chapterId}: invalid localPageRange [${o},${r2}]`), i3 - e15 !== r2 - o && t3.push(`${s10.chapterId}: page-count mismatch (global ${i3 - e15 + 1} vs local ${r2 - o + 1})`), s10.ownedGlobalPages) for (const a5 of s10.ownedGlobalPages) (a5 < e15 || a5 > i3) && t3.push(`${s10.chapterId}: ownedGlobalPages contains ${a5} outside range`);
|
|
3501
3506
|
}
|
|
3502
3507
|
return t3;
|
|
3503
3508
|
})(t2);
|
|
3504
3509
|
a3.length > 0 && this.logger.warn(e11.id, "ManifestValidation", `Chapter manifest has issues: ${a3.join("; ")}`);
|
|
3505
|
-
const s9 = new Set(this.chapterStatus.keys()),
|
|
3506
|
-
for (const e14 of s9)
|
|
3510
|
+
const s9 = new Set(this.chapterStatus.keys()), i2 = new Set(t2.chapters.map((e14) => e14.chapterId));
|
|
3511
|
+
for (const e14 of s9) i2.has(e14) || (this.closeChapter(e14), this.chapterStatus.delete(e14));
|
|
3507
3512
|
for (const e14 of t2.chapters) this.chapterStatus.has(e14.chapterId) || this.chapterStatus.set(e14.chapterId, "idle");
|
|
3508
|
-
this.manifest = t2, this.virtualPageMap =
|
|
3513
|
+
this.manifest = t2, this.virtualPageMap = Aa(t2, this.overlapStrategy), this.manifestChange$.emit({ manifest: t2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
|
|
3509
3514
|
}
|
|
3510
3515
|
eagerPrefetchFromManifest() {
|
|
3511
3516
|
const e14 = this.config.prefetchChapters ?? 0;
|
|
@@ -3532,20 +3537,20 @@ const $a = class e11 extends BasePlugin {
|
|
|
3532
3537
|
e15 && s9.add(e15.chapterId);
|
|
3533
3538
|
}
|
|
3534
3539
|
if (0 === s9.size) return;
|
|
3535
|
-
const
|
|
3540
|
+
const i2 = this.manifest.chapters.map((e15) => e15.chapterId), o = /* @__PURE__ */ new Set();
|
|
3536
3541
|
for (const n2 of s9) {
|
|
3537
|
-
const e15 =
|
|
3538
|
-
if (-1 !== e15) for (let t3 = e15 - a3; t3 <= e15 + a3; t3++) t3 >= 0 && t3 <
|
|
3542
|
+
const e15 = i2.indexOf(n2);
|
|
3543
|
+
if (-1 !== e15) for (let t3 = e15 - a3; t3 <= e15 + a3; t3++) t3 >= 0 && t3 < i2.length && o.add(t3);
|
|
3539
3544
|
}
|
|
3540
3545
|
const r2 = /* @__PURE__ */ new Set();
|
|
3541
|
-
for (const n2 of o) r2.add(
|
|
3546
|
+
for (const n2 of o) r2.add(i2[n2]);
|
|
3542
3547
|
for (const n2 of r2) {
|
|
3543
3548
|
this.chapterLastUsed.set(n2, t2);
|
|
3544
3549
|
const e15 = this.chapterStatus.get(n2) ?? "idle";
|
|
3545
3550
|
"idle" !== e15 && "closed" !== e15 && "error" !== e15 || this.ensureChapterLoaded(n2);
|
|
3546
3551
|
}
|
|
3547
3552
|
if (this.config.autoActivateOnLoad ?? 1) {
|
|
3548
|
-
const e15 =
|
|
3553
|
+
const e15 = i2.find((e16) => s9.has(e16));
|
|
3549
3554
|
if (e15 && this.documentManager.provides().isDocumentOpen(e15)) {
|
|
3550
3555
|
this.documentManager.provides().getActiveDocumentId() !== e15 && this.documentManager.provides().setActiveDocument(e15);
|
|
3551
3556
|
}
|
|
@@ -3568,10 +3573,10 @@ const $a = class e11 extends BasePlugin {
|
|
|
3568
3573
|
const s9 = this.chapterStatus.get(e14) ?? "idle";
|
|
3569
3574
|
if ("loaded" === s9) return this.chapterLastUsed.set(e14, Date.now()), Promise.resolve("loaded");
|
|
3570
3575
|
if ("loading" === s9) return this.waitForTerminalStatus(e14);
|
|
3571
|
-
const
|
|
3576
|
+
const i2 = this.startLoad(a3).finally(() => {
|
|
3572
3577
|
this.pendingLoadPromises.delete(e14);
|
|
3573
3578
|
});
|
|
3574
|
-
return this.pendingLoadPromises.set(e14,
|
|
3579
|
+
return this.pendingLoadPromises.set(e14, i2), i2;
|
|
3575
3580
|
}
|
|
3576
3581
|
async resolvePdfPayload(e14) {
|
|
3577
3582
|
const t2 = e14.source;
|
|
@@ -3589,17 +3594,17 @@ const $a = class e11 extends BasePlugin {
|
|
|
3589
3594
|
const s9 = t2.chapterId;
|
|
3590
3595
|
this.updateStatus(s9, "loading"), this.chapterLastUsed.set(s9, Date.now());
|
|
3591
3596
|
try {
|
|
3592
|
-
const e14 = t2.encrypted && (null == (a3 = this.passwordProvider) ? void 0 : a3.getCachedPassword) ? this.passwordProvider.getCachedPassword(s9) : null,
|
|
3597
|
+
const e14 = t2.encrypted && (null == (a3 = this.passwordProvider) ? void 0 : a3.getCachedPassword) ? this.passwordProvider.getCachedPassword(s9) : null, i2 = await this.resolvePdfPayload(t2), o = this.documentManager.provides(), r2 = "url" in i2 ? o.openDocumentUrl({ documentId: s9, url: i2.url, name: t2.title, password: e14 ?? void 0, autoActivate: false }) : o.openDocumentBuffer({ documentId: s9, buffer: i2.buffer, name: t2.title, password: e14 ?? void 0, autoActivate: false }), n2 = await new Promise((e15, t3) => {
|
|
3593
3598
|
r2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
3594
3599
|
});
|
|
3595
3600
|
return await new Promise((e15, t3) => {
|
|
3596
3601
|
n2.task.wait(() => e15(), (e16) => t3(e16));
|
|
3597
3602
|
}), o.isDocumentOpen(s9) && this.updateStatus(s9, "loaded"), this.waitForTerminalStatus(s9);
|
|
3598
|
-
} catch (
|
|
3603
|
+
} catch (i2) {
|
|
3599
3604
|
const t3 = this.chapterStatus.get(s9);
|
|
3600
3605
|
if ("loaded" !== t3 && "password-required" !== t3) {
|
|
3601
|
-
const t4 =
|
|
3602
|
-
this.logger.error(e11.id, "LoadChapter", t4,
|
|
3606
|
+
const t4 = i2 instanceof Error ? i2.message : `Failed to load chapter "${s9}"`;
|
|
3607
|
+
this.logger.error(e11.id, "LoadChapter", t4, i2), this.updateStatus(s9, "error", t4);
|
|
3603
3608
|
}
|
|
3604
3609
|
return this.chapterStatus.get(s9) ?? "error";
|
|
3605
3610
|
}
|
|
@@ -3617,13 +3622,13 @@ const $a = class e11 extends BasePlugin {
|
|
|
3617
3622
|
async handleDocumentError(t2, a3, s9) {
|
|
3618
3623
|
if (a3 !== PdfErrorCode.Password) return void this.updateStatus(t2, "error");
|
|
3619
3624
|
if (!this.passwordProvider) return void this.updateStatus(t2, "password-required");
|
|
3620
|
-
const
|
|
3621
|
-
if (!
|
|
3625
|
+
const i2 = this.findChapter(t2);
|
|
3626
|
+
if (!i2) return;
|
|
3622
3627
|
const o = (this.passwordAttempts.get(t2) ?? 0) + 1;
|
|
3623
3628
|
this.passwordAttempts.set(t2, o);
|
|
3624
3629
|
let r2 = null;
|
|
3625
3630
|
try {
|
|
3626
|
-
r2 = await this.passwordProvider.resolvePassword(
|
|
3631
|
+
r2 = await this.passwordProvider.resolvePassword(i2, o - 1);
|
|
3627
3632
|
} catch (n2) {
|
|
3628
3633
|
this.logger.error(e11.id, "PasswordProvider", `Provider rejected for ${t2}`, n2);
|
|
3629
3634
|
}
|
|
@@ -3643,20 +3648,20 @@ const $a = class e11 extends BasePlugin {
|
|
|
3643
3648
|
this.chapterStatus.get(e14) !== t2 && (this.chapterStatus.set(e14, t2), this.statusChange$.emit({ chapterId: e14, status: t2, ..."error" === t2 && a3 ? { error: { message: a3 } } : {} }));
|
|
3644
3649
|
}
|
|
3645
3650
|
};
|
|
3646
|
-
|
|
3647
|
-
let
|
|
3648
|
-
function
|
|
3651
|
+
Va.id = "chapter-manager";
|
|
3652
|
+
let _a = Va;
|
|
3653
|
+
function Ea(e14, t2) {
|
|
3649
3654
|
if (e14 === t2) return true;
|
|
3650
3655
|
if (e14.totalHeight !== t2.totalHeight || e14.totalWidth !== t2.totalWidth || e14.pageGap !== t2.pageGap || e14.items.length !== t2.items.length) return false;
|
|
3651
3656
|
for (let a3 = 0; a3 < e14.items.length; a3++) {
|
|
3652
|
-
const s9 = e14.items[a3],
|
|
3653
|
-
if (s9.globalPageIndex !==
|
|
3657
|
+
const s9 = e14.items[a3], i2 = t2.items[a3];
|
|
3658
|
+
if (s9.globalPageIndex !== i2.globalPageIndex || s9.isPlaceholder !== i2.isPlaceholder || s9.chapterId !== i2.chapterId || s9.localPageIndex !== i2.localPageIndex || s9.offsetTop !== i2.offsetTop || s9.width !== i2.width || s9.height !== i2.height) return false;
|
|
3654
3659
|
}
|
|
3655
3660
|
return true;
|
|
3656
3661
|
}
|
|
3657
|
-
const
|
|
3662
|
+
const Ra = class extends BasePlugin {
|
|
3658
3663
|
constructor(e14, t2) {
|
|
3659
|
-
super(e14, t2), this.layoutChange$ = createBehaviorEmitter(void 0,
|
|
3664
|
+
super(e14, t2), this.layoutChange$ = createBehaviorEmitter(void 0, Ea), 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.chapterManagerUnsubs = [], this.chapterManager = this.registry.getPlugin(_a.id), this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
|
|
3660
3665
|
}
|
|
3661
3666
|
async initialize(e14) {
|
|
3662
3667
|
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 }) => {
|
|
@@ -3710,8 +3715,8 @@ const Da = class extends BasePlugin {
|
|
|
3710
3715
|
this.offsets = new Array(e14);
|
|
3711
3716
|
let t2 = 0, a3 = 0;
|
|
3712
3717
|
for (let s9 = 0; s9 < e14; s9++) {
|
|
3713
|
-
const { width: e15, height:
|
|
3714
|
-
this.offsets[s9] = t2, t2 +=
|
|
3718
|
+
const { width: e15, height: i2 } = this.getPageSize(s9);
|
|
3719
|
+
this.offsets[s9] = t2, t2 += i2 + this.config.pageGap, e15 > a3 && (a3 = e15);
|
|
3715
3720
|
}
|
|
3716
3721
|
this.totalHeight = e14 > 0 ? t2 - this.config.pageGap : 0, this.totalWidth = a3, this.layoutChange$.emit(this.computeLayout());
|
|
3717
3722
|
}
|
|
@@ -3721,8 +3726,8 @@ const Da = class extends BasePlugin {
|
|
|
3721
3726
|
for (const s9 of t2) {
|
|
3722
3727
|
const t3 = this.virtualPageMap.toGlobal(e14, s9.localPageIndex);
|
|
3723
3728
|
if (!t3) continue;
|
|
3724
|
-
const
|
|
3725
|
-
|
|
3729
|
+
const i2 = this.pageSizes.get(t3.globalPageIndex);
|
|
3730
|
+
i2 && i2.width === s9.width && i2.height === s9.height || (this.pageSizes.set(t3.globalPageIndex, { width: s9.width, height: s9.height }), a3 = true);
|
|
3726
3731
|
}
|
|
3727
3732
|
if (a3) {
|
|
3728
3733
|
const e15 = this.currentGlobalPageIndex, t3 = this.offsets[e15] ?? 0;
|
|
@@ -3740,10 +3745,10 @@ const Da = class extends BasePlugin {
|
|
|
3740
3745
|
harvestChapterSizes(e14, t2 = 0) {
|
|
3741
3746
|
var a3;
|
|
3742
3747
|
if (!this.virtualPageMap) return;
|
|
3743
|
-
const s9 = this.documentManager.provides().getDocument(e14),
|
|
3744
|
-
if (!(null == (a3 = null == s9 ? void 0 : s9.pages) ? void 0 : a3.length) || 0 ===
|
|
3748
|
+
const s9 = this.documentManager.provides().getDocument(e14), i2 = this.virtualPageMap.pagesOfChapter(e14);
|
|
3749
|
+
if (!(null == (a3 = null == s9 ? void 0 : s9.pages) ? void 0 : a3.length) || 0 === i2.length) return void (t2 < 60 && requestAnimationFrame(() => this.harvestChapterSizes(e14, t2 + 1)));
|
|
3745
3750
|
const o = this.getChapterDocumentScale(e14), r2 = [];
|
|
3746
|
-
for (const n2 of
|
|
3751
|
+
for (const n2 of i2) {
|
|
3747
3752
|
const e15 = s9.pages[n2.localPageIndex];
|
|
3748
3753
|
(null == e15 ? void 0 : e15.size) && r2.push({ localPageIndex: n2.localPageIndex, width: e15.size.width * o, height: e15.size.height * o });
|
|
3749
3754
|
}
|
|
@@ -3774,38 +3779,38 @@ const Da = class extends BasePlugin {
|
|
|
3774
3779
|
const e14 = this.virtualPageMap.totalPages;
|
|
3775
3780
|
if (0 === e14) return this.currentVisible = [], this.currentGlobalPageIndex = 0, void this.layoutChange$.emit(this.computeLayout());
|
|
3776
3781
|
const t2 = this.viewportEl.scrollTop, a3 = t2 + this.viewportEl.clientHeight, s9 = this.findFirstVisibleIndex(t2);
|
|
3777
|
-
let
|
|
3778
|
-
for (;
|
|
3779
|
-
const e15 = this.getPageSize(
|
|
3782
|
+
let i2 = s9;
|
|
3783
|
+
for (; i2 < e14; ) {
|
|
3784
|
+
const e15 = this.getPageSize(i2), t3 = this.offsets[i2];
|
|
3780
3785
|
if (e15.height, t3 >= a3) break;
|
|
3781
|
-
|
|
3786
|
+
i2++;
|
|
3782
3787
|
}
|
|
3783
3788
|
const o = [];
|
|
3784
3789
|
let r2 = s9, n2 = -1;
|
|
3785
|
-
for (let l = s9; l <
|
|
3790
|
+
for (let l = s9; l < i2; l++) {
|
|
3786
3791
|
o.push(l);
|
|
3787
|
-
const e15 = this.offsets[l], s10 = e15 + this.getPageSize(l).height,
|
|
3788
|
-
|
|
3792
|
+
const e15 = this.offsets[l], s10 = e15 + this.getPageSize(l).height, i3 = Math.max(0, Math.min(s10, a3) - Math.max(e15, t2));
|
|
3793
|
+
i3 > n2 && (n2 = i3, r2 = l);
|
|
3789
3794
|
}
|
|
3790
3795
|
this.currentVisible = o, this.currentGlobalPageIndex = r2, this.visibleChange$.emit({ visibleGlobalPageIndices: o, currentGlobalPageIndex: r2 }), this.chapterManager.provides().setVisibleGlobalPages(o), this.layoutChange$.emit(this.computeLayout());
|
|
3791
3796
|
}
|
|
3792
3797
|
findFirstVisibleIndex(e14) {
|
|
3793
3798
|
let t2 = 0, a3 = this.offsets.length - 1, s9 = 0;
|
|
3794
3799
|
for (; t2 <= a3; ) {
|
|
3795
|
-
const
|
|
3796
|
-
this.offsets[
|
|
3800
|
+
const i2 = t2 + a3 >> 1;
|
|
3801
|
+
this.offsets[i2] <= e14 ? (s9 = i2, t2 = i2 + 1) : a3 = i2 - 1;
|
|
3797
3802
|
}
|
|
3798
3803
|
return s9;
|
|
3799
3804
|
}
|
|
3800
3805
|
computeLayout() {
|
|
3801
|
-
const e14 = this.config.bufferSize, t2 = Math.max(0, (this.currentVisible[0] ?? 0) - e14), a3 = this.currentVisible[this.currentVisible.length - 1] ?? -1, s9 = Math.min(this.offsets.length - 1, (a3 >= 0 ? a3 : 0) + e14),
|
|
3806
|
+
const e14 = this.config.bufferSize, t2 = Math.max(0, (this.currentVisible[0] ?? 0) - e14), a3 = this.currentVisible[this.currentVisible.length - 1] ?? -1, s9 = Math.min(this.offsets.length - 1, (a3 >= 0 ? a3 : 0) + e14), i2 = [];
|
|
3802
3807
|
if (this.virtualPageMap && this.offsets.length > 0) for (let o = t2; o <= s9; o++) {
|
|
3803
3808
|
const e15 = this.virtualPageMap.atIndex(o);
|
|
3804
3809
|
if (!e15) continue;
|
|
3805
3810
|
const t3 = this.getPageSize(o), a4 = this.isChapterPagePlaceholder(e15.chapterId);
|
|
3806
|
-
|
|
3811
|
+
i2.push({ globalPageIndex: o, globalPageNumber: e15.globalPageNumber, chapterId: e15.chapterId, localPageIndex: e15.localPageIndex, width: t3.width, height: t3.height, offsetTop: this.offsets[o], isPlaceholder: a4 });
|
|
3807
3812
|
}
|
|
3808
|
-
return { totalHeight: this.totalHeight, totalWidth: this.totalWidth || this.config.placeholderPageWidth, items:
|
|
3813
|
+
return { totalHeight: this.totalHeight, totalWidth: this.totalWidth || this.config.placeholderPageWidth, items: i2, pageGap: this.config.pageGap };
|
|
3809
3814
|
}
|
|
3810
3815
|
scrollToIndex(e14, t2) {
|
|
3811
3816
|
if (!this.viewportEl || e14 < 0 || e14 >= this.offsets.length) return;
|
|
@@ -3815,11 +3820,11 @@ const Da = class extends BasePlugin {
|
|
|
3815
3820
|
scrollToGlobalPdfPoint(e14, t2, a3) {
|
|
3816
3821
|
var s9;
|
|
3817
3822
|
if (!this.viewportEl || e14 < 0 || e14 >= this.offsets.length || !this.virtualPageMap) return;
|
|
3818
|
-
const
|
|
3823
|
+
const i2 = (null == a3 ? void 0 : a3.marginTop) ?? 80, o = this.virtualPageMap.atIndex(e14);
|
|
3819
3824
|
if (!o) return void this.scrollToIndex(e14, a3);
|
|
3820
3825
|
const r2 = this.pageSizes.get(e14), n2 = null == (s9 = this.documentManager.provides().getDocument(o.chapterId)) ? void 0 : s9.pages[o.localPageIndex];
|
|
3821
3826
|
if (!r2 || !n2) return void this.scrollToIndex(e14, a3);
|
|
3822
|
-
const l = r2.height / n2.size.height, h2 = (this.offsets[e14] ?? 0) + t2 * l -
|
|
3827
|
+
const l = r2.height / n2.size.height, h2 = (this.offsets[e14] ?? 0) + t2 * l - i2;
|
|
3823
3828
|
this.viewportEl.scrollTo({ top: Math.max(0, h2), behavior: (null == a3 ? void 0 : a3.behavior) ?? "auto" });
|
|
3824
3829
|
}
|
|
3825
3830
|
scrollToChapter(e14, t2) {
|
|
@@ -3833,11 +3838,11 @@ const Da = class extends BasePlugin {
|
|
|
3833
3838
|
a3 && this.scrollToIndex(a3.globalPageIndex, t2);
|
|
3834
3839
|
}
|
|
3835
3840
|
};
|
|
3836
|
-
|
|
3837
|
-
let
|
|
3838
|
-
const
|
|
3841
|
+
Ra.id = "chapter-scroll";
|
|
3842
|
+
let Fa = Ra;
|
|
3843
|
+
const Ua = class e12 extends BasePlugin {
|
|
3839
3844
|
constructor(e14, t2) {
|
|
3840
|
-
super(e14, t2), this.notesChange$ = createBehaviorEmitter([]), this.noteActivated$ = createEmitter(), this.notes = /* @__PURE__ */ new Map(), this.chapterScroll = this.registry.getPlugin(
|
|
3845
|
+
super(e14, t2), this.notesChange$ = createBehaviorEmitter([]), this.noteActivated$ = createEmitter(), this.notes = /* @__PURE__ */ new Map(), this.chapterScroll = this.registry.getPlugin(Fa.id), this.chapterManager = this.registry.getPlugin(Da.id), this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
|
|
3841
3846
|
}
|
|
3842
3847
|
async initialize(t2) {
|
|
3843
3848
|
if (this.config = t2, t2.callbacks.loadNotes) try {
|
|
@@ -3875,7 +3880,7 @@ const Ga = class e12 extends BasePlugin {
|
|
|
3875
3880
|
this.notesChange$.emit(this.listAll());
|
|
3876
3881
|
}
|
|
3877
3882
|
buildDraft(e14) {
|
|
3878
|
-
return { chapterId: e14.chapterId, localPageIndex: e14.localPageIndex, globalPageNumber: e14.globalPageNumber, globalPageIndex: e14.globalPageIndex, rectsPdfCoord: e14.rectsPdfCoord, endAnchor:
|
|
3883
|
+
return { chapterId: e14.chapterId, localPageIndex: e14.localPageIndex, globalPageNumber: e14.globalPageNumber, globalPageIndex: e14.globalPageIndex, rectsPdfCoord: e14.rectsPdfCoord, endAnchor: Wa(e14.rectsPdfCoord), selectedText: e14.selectedText, content: e14.content };
|
|
3879
3884
|
}
|
|
3880
3885
|
async requestCreateFromSelection(e14) {
|
|
3881
3886
|
if (0 === e14.rectsPdfCoord.length) return null;
|
|
@@ -3889,14 +3894,14 @@ const Ga = class e12 extends BasePlugin {
|
|
|
3889
3894
|
if (0 === t2.rectsPdfCoord.length) return null;
|
|
3890
3895
|
const a3 = this.buildDraft(t2), s9 = this.config.callbacks.onCreateNote;
|
|
3891
3896
|
if (!s9) return this.logger.error(e12.id, "CreateNote", "Missing onCreateNote / onRequestCreateNote"), null;
|
|
3892
|
-
let
|
|
3897
|
+
let i2 = null;
|
|
3893
3898
|
try {
|
|
3894
|
-
|
|
3899
|
+
i2 = await s9(a3);
|
|
3895
3900
|
} catch (r2) {
|
|
3896
3901
|
return this.logger.error(e12.id, "OnCreateNote", "Callback failed", r2), null;
|
|
3897
3902
|
}
|
|
3898
|
-
if (!
|
|
3899
|
-
const o = { ...a3, noteId:
|
|
3903
|
+
if (!i2) return null;
|
|
3904
|
+
const o = { ...a3, noteId: i2.noteId };
|
|
3900
3905
|
return this.registerNote(o), o;
|
|
3901
3906
|
}
|
|
3902
3907
|
async deleteNote(t2) {
|
|
@@ -3904,19 +3909,19 @@ const Ga = class e12 extends BasePlugin {
|
|
|
3904
3909
|
if (this.notes.has(t2)) {
|
|
3905
3910
|
try {
|
|
3906
3911
|
await (null == (s9 = (a3 = this.config.callbacks).onDeleteNote) ? void 0 : s9.call(a3, t2));
|
|
3907
|
-
} catch (
|
|
3908
|
-
return void this.logger.error(e12.id, "OnDeleteNote", "Callback failed",
|
|
3912
|
+
} catch (i2) {
|
|
3913
|
+
return void this.logger.error(e12.id, "OnDeleteNote", "Callback failed", i2);
|
|
3909
3914
|
}
|
|
3910
3915
|
this.notes.delete(t2), this.notesChange$.emit(this.listAll());
|
|
3911
3916
|
}
|
|
3912
3917
|
}
|
|
3913
3918
|
async updateNoteContent(t2, a3) {
|
|
3914
|
-
var s9,
|
|
3919
|
+
var s9, i2;
|
|
3915
3920
|
const o = this.notes.get(t2);
|
|
3916
3921
|
if (!o) return;
|
|
3917
3922
|
const r2 = { ...o, content: a3 };
|
|
3918
3923
|
try {
|
|
3919
|
-
await (null == (
|
|
3924
|
+
await (null == (i2 = (s9 = this.config.callbacks).onUpdateNote) ? void 0 : i2.call(s9, r2));
|
|
3920
3925
|
} catch (n2) {
|
|
3921
3926
|
return void this.logger.error(e12.id, "OnUpdateNote", "Callback failed", n2);
|
|
3922
3927
|
}
|
|
@@ -3934,32 +3939,32 @@ const Ga = class e12 extends BasePlugin {
|
|
|
3934
3939
|
const t2 = this.chapterScroll.provides(), a3 = t2.getLayout().items.find((t3) => t3.globalPageIndex === e14 && !t3.isPlaceholder);
|
|
3935
3940
|
return a3 ? Promise.resolve(a3) : new Promise((a4) => {
|
|
3936
3941
|
const s9 = setTimeout(() => {
|
|
3937
|
-
|
|
3938
|
-
}, 2500),
|
|
3942
|
+
i2(), a4(null);
|
|
3943
|
+
}, 2500), i2 = t2.onLayoutChange((t3) => {
|
|
3939
3944
|
const o = t3.items.find((t4) => t4.globalPageIndex === e14 && !t4.isPlaceholder);
|
|
3940
|
-
o && (clearTimeout(s9),
|
|
3945
|
+
o && (clearTimeout(s9), i2(), a4(o));
|
|
3941
3946
|
});
|
|
3942
3947
|
});
|
|
3943
3948
|
}
|
|
3944
3949
|
};
|
|
3945
|
-
|
|
3946
|
-
let
|
|
3947
|
-
function
|
|
3950
|
+
Ua.id = "note";
|
|
3951
|
+
let qa = Ua;
|
|
3952
|
+
function Wa(e14) {
|
|
3948
3953
|
const t2 = e14[e14.length - 1];
|
|
3949
3954
|
return { x: t2.origin.x + t2.size.width, y: t2.origin.y + t2.size.height };
|
|
3950
3955
|
}
|
|
3951
|
-
function
|
|
3952
|
-
const { markerPdf: t2, lineRects: a3, sx: s9, sy:
|
|
3953
|
-
let h2,
|
|
3954
|
-
l ? (h2 = (l.origin.x + l.size.width) * s9 + n2,
|
|
3956
|
+
function Ha(e14) {
|
|
3957
|
+
const { markerPdf: t2, lineRects: a3, sx: s9, sy: i2, cssPageWidth: o, iconSize: r2, gapPx: n2 = 6 } = e14, l = (a3 == null ? void 0 : a3.length) ? a3[a3.length - 1] : void 0;
|
|
3958
|
+
let h2, d2;
|
|
3959
|
+
l ? (h2 = (l.origin.x + l.size.width) * s9 + n2, d2 = l.origin.y * i2 + (l.size.height * i2 - r2) / 2) : (h2 = t2.x * s9 - r2 / 2, d2 = t2.y * i2 - r2 - n2);
|
|
3955
3960
|
const c = Math.max(0, o - r2 - 2);
|
|
3956
|
-
return h2 > c && (h2 = c),
|
|
3961
|
+
return h2 > c && (h2 = c), d2 < 0 && (d2 = 0), { left: h2, top: d2 };
|
|
3957
3962
|
}
|
|
3958
|
-
const
|
|
3959
|
-
const o = e14, { provides: r2 } = useCapability(
|
|
3963
|
+
const Ba = { key: 0, style: { position: "absolute", inset: "0", pointerEvents: "none", zIndex: 25 } }, ja = ["onMouseenter"], Za = ["data-note-marker-zone", "onMouseenter", "onMouseleave"], Ya = ["onClick"], Ka = ["onClick"], Xa = ["onClick"], Qa = /* @__PURE__ */ defineComponent({ __name: "NoteMarkerLayer", props: { chapterId: {}, localPageIndex: {}, pdfPageWidth: {}, pdfPageHeight: {}, cssPageWidth: {}, cssPageHeight: {}, ui: {} }, setup(e14) {
|
|
3964
|
+
const o = e14, { provides: r2 } = useCapability(qa.id), d2 = ref([]), g2 = ref(null), f = ref(null);
|
|
3960
3965
|
watch(r2, (e15) => {
|
|
3961
3966
|
if (e15) return e15.onNotesChange((e16) => {
|
|
3962
|
-
|
|
3967
|
+
d2.value = e16.filter((e17) => e17.chapterId === o.chapterId && e17.localPageIndex === o.localPageIndex);
|
|
3963
3968
|
});
|
|
3964
3969
|
}, { immediate: true });
|
|
3965
3970
|
let P = null;
|
|
@@ -3967,7 +3972,7 @@ const _a = { key: 0, style: { position: "absolute", inset: "0", pointerEvents: "
|
|
|
3967
3972
|
P && (document.removeEventListener("mousedown", P), P = null), e15 && (P = (t2) => {
|
|
3968
3973
|
var _a2;
|
|
3969
3974
|
const a3 = t2.target;
|
|
3970
|
-
((_a2 = a3.closest) == null ? void 0 : _a2.call(a3, `[data-note-marker-zone="${e15}"]`)) || (f.value = null,
|
|
3975
|
+
((_a2 = a3.closest) == null ? void 0 : _a2.call(a3, `[data-note-marker-zone="${e15}"]`)) || (f.value = null, g2.value = null);
|
|
3971
3976
|
}, document.addEventListener("mousedown", P));
|
|
3972
3977
|
}), onBeforeUnmount(() => {
|
|
3973
3978
|
P && document.removeEventListener("mousedown", P);
|
|
@@ -3980,37 +3985,37 @@ const _a = { key: 0, style: { position: "absolute", inset: "0", pointerEvents: "
|
|
|
3980
3985
|
return ((_a2 = o.ui) == null ? void 0 : _a2.highlightColor) ?? "rgba(245, 158, 11, 0.08)";
|
|
3981
3986
|
});
|
|
3982
3987
|
function C(e15) {
|
|
3983
|
-
const t2 = o.cssPageWidth / o.pdfPageWidth, a3 = o.cssPageHeight / o.pdfPageHeight, s9 = w.value, { left:
|
|
3984
|
-
let s10 = 1 / 0,
|
|
3985
|
-
for (const n3 of e16) s10 = Math.min(s10, n3.origin.x * t3),
|
|
3986
|
-
return { left: s10, top:
|
|
3987
|
-
})(e15.rectsPdfCoord, t2, a3), l = f.value === e15.noteId ? 72 : 0, h2 = Math.max(0, Math.min(n2.left,
|
|
3988
|
-
return { zoneLeft: h2, zoneTop:
|
|
3989
|
-
}
|
|
3990
|
-
return (t2, a3) => unref(r2) &&
|
|
3991
|
-
}, ["stop"])), onClick: withModifiers((t3) => f.value = f.value === e15.noteId ? null : e15.noteId, ["stop"]) }, " 💬 ", 44,
|
|
3988
|
+
const t2 = o.cssPageWidth / o.pdfPageWidth, a3 = o.cssPageHeight / o.pdfPageHeight, s9 = w.value, { left: i2, top: r3 } = Ha({ markerPdf: e15.endAnchor, lineRects: e15.rectsPdfCoord, sx: t2, sy: a3, cssPageWidth: o.cssPageWidth, iconSize: s9 }), n2 = (function(e16, t3, a4) {
|
|
3989
|
+
let s10 = 1 / 0, i3 = 1 / 0, o2 = -1 / 0, r4 = -1 / 0;
|
|
3990
|
+
for (const n3 of e16) s10 = Math.min(s10, n3.origin.x * t3), i3 = Math.min(i3, n3.origin.y * a4), o2 = Math.max(o2, (n3.origin.x + n3.size.width) * t3), r4 = Math.max(r4, (n3.origin.y + n3.size.height) * a4);
|
|
3991
|
+
return { left: s10, top: i3, width: o2 - s10, height: r4 - i3 };
|
|
3992
|
+
})(e15.rectsPdfCoord, t2, a3), l = f.value === e15.noteId ? 72 : 0, h2 = Math.max(0, Math.min(n2.left, i2) - 8), d3 = Math.max(0, Math.min(n2.top, r3) - 8);
|
|
3993
|
+
return { zoneLeft: h2, zoneTop: d3, zoneW: Math.min(o.cssPageWidth, Math.max(n2.left + n2.width, i2 + s9) + 8) - h2, zoneH: Math.max(n2.top + n2.height, r3 + s9 + 6 + l) + 8 - d3, iconLeft: i2, iconTop: r3, sx: t2, sy: a3 };
|
|
3994
|
+
}
|
|
3995
|
+
return (t2, a3) => unref(r2) && d2.value.length && e14.pdfPageWidth && e14.pdfPageHeight ? (openBlock(), createElementBlock("div", Ba, [(openBlock(true), createElementBlock(Fragment, null, renderList(d2.value, (e15) => (openBlock(), createElementBlock(Fragment, { key: e15.noteId }, [(openBlock(true), createElementBlock(Fragment, null, renderList(e15.rectsPdfCoord, (t3, a4) => (openBlock(), createElementBlock("div", { key: `${e15.noteId}-bg-${a4}`, style: normalizeStyle({ position: "absolute", left: t3.origin.x * C(e15).sx + "px", top: t3.origin.y * C(e15).sy + "px", width: t3.size.width * C(e15).sx + "px", height: t3.size.height * C(e15).sy + "px", background: y.value, borderRadius: "2px", pointerEvents: "auto" }), onMouseenter: (t4) => g2.value = e15.noteId }, null, 44, ja))), 128)), g2.value === e15.noteId || f.value === e15.noteId ? (openBlock(), createElementBlock("div", { key: 0, "data-note-marker-zone": e15.noteId, style: normalizeStyle({ position: "absolute", left: `${C(e15).zoneLeft}px`, top: `${C(e15).zoneTop}px`, width: `${C(e15).zoneW}px`, height: `${C(e15).zoneH}px`, pointerEvents: "auto", zIndex: 26 }), onMouseenter: (t3) => g2.value = e15.noteId, onMouseleave: (t3) => f.value !== e15.noteId && (g2.value = null) }, [createElementVNode("button", { type: "button", title: "笔记", style: normalizeStyle({ position: "absolute", left: C(e15).iconLeft - C(e15).zoneLeft + "px", top: C(e15).iconTop - C(e15).zoneTop + "px", width: `${w.value}px`, height: `${w.value}px`, border: "none", borderRadius: "50%", background: "#f59e0b", color: "#fff", cursor: "pointer", fontSize: "11px", padding: 0 }), onMousedown: a3[0] || (a3[0] = withModifiers(() => {
|
|
3996
|
+
}, ["stop"])), onClick: withModifiers((t3) => f.value = f.value === e15.noteId ? null : e15.noteId, ["stop"]) }, " 💬 ", 44, Ya), f.value === e15.noteId ? (openBlock(), createElementBlock("div", { key: 0, style: normalizeStyle({ position: "absolute", left: C(e15).iconLeft - C(e15).zoneLeft + "px", top: `${C(e15).iconTop - C(e15).zoneTop + w.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: a3[1] || (a3[1] = withModifiers(() => {
|
|
3992
3997
|
}, ["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) {
|
|
3993
3998
|
var _a2;
|
|
3994
3999
|
(_a2 = r2.value) == null ? void 0 : _a2.requestEditNote(e16.noteId, e16);
|
|
3995
|
-
})(e15) }, " 编辑 ", 8,
|
|
4000
|
+
})(e15) }, " 编辑 ", 8, Ka), createElementVNode("button", { type: "button", style: { display: "block", width: "100%", padding: "6px 8px", "font-size": "12px", border: "none", "border-radius": "4px", background: "transparent", color: "#dc2626", cursor: "pointer", "text-align": "left" }, onClick: (t3) => {
|
|
3996
4001
|
var _a2;
|
|
3997
4002
|
return a4 = e15.noteId, (_a2 = r2.value) == null ? void 0 : _a2.requestDeleteNote(a4), void (f.value = null);
|
|
3998
4003
|
var a4;
|
|
3999
|
-
} }, " 删除 ", 8,
|
|
4000
|
-
} }),
|
|
4001
|
-
const o = e14, { provides: r2 } = useCapability(
|
|
4004
|
+
} }, " 删除 ", 8, Xa)], 36)) : createCommentVNode("", true)], 44, Za)) : createCommentVNode("", true)], 64))), 128))])) : createCommentVNode("", true);
|
|
4005
|
+
} }), Ja = { key: 0, style: { position: "absolute", inset: "0", pointerEvents: "none" } }, es = ["title", "onClick"], ts = ["onClick"], as = /* @__PURE__ */ defineComponent({ __name: "BookmarkMarkerLayer", props: { chapterId: {}, localPageIndex: {}, pdfPageWidth: {}, pdfPageHeight: {}, cssPageWidth: {}, cssPageHeight: {}, ui: {} }, setup(e14) {
|
|
4006
|
+
const o = e14, { provides: r2 } = useCapability(Bt$1.id), d2 = ref([]), g2 = ref(null), f = ref(null);
|
|
4002
4007
|
function P() {
|
|
4003
4008
|
const e15 = r2.value;
|
|
4004
|
-
e15 && (
|
|
4009
|
+
e15 && (d2.value = e15.listBookmarks().filter((e16) => e16.anchor.chapterId === o.chapterId && e16.anchor.localPageIndex === o.localPageIndex));
|
|
4005
4010
|
}
|
|
4006
4011
|
watch(r2, (e15) => {
|
|
4007
4012
|
if (e15) return P(), e15.onBookmarksChange(P);
|
|
4008
4013
|
}, { immediate: true });
|
|
4009
4014
|
let w = null;
|
|
4010
|
-
watch(
|
|
4015
|
+
watch(g2, (e15) => {
|
|
4011
4016
|
w && (document.removeEventListener("mousedown", w), w = null), e15 && (w = (e16) => {
|
|
4012
4017
|
var _a2;
|
|
4013
|
-
((_a2 = f.value) == null ? void 0 : _a2.contains(e16.target)) || (
|
|
4018
|
+
((_a2 = f.value) == null ? void 0 : _a2.contains(e16.target)) || (g2.value = null);
|
|
4014
4019
|
}, document.addEventListener("mousedown", w));
|
|
4015
4020
|
}), onBeforeUnmount(() => {
|
|
4016
4021
|
w && document.removeEventListener("mousedown", w);
|
|
@@ -4023,46 +4028,46 @@ const _a = { key: 0, style: { position: "absolute", inset: "0", pointerEvents: "
|
|
|
4023
4028
|
const { left: t2, top: a3 } = (function(e16) {
|
|
4024
4029
|
var _a2;
|
|
4025
4030
|
const t3 = o.cssPageWidth / o.pdfPageWidth, a4 = o.cssPageHeight / o.pdfPageHeight, s9 = ((_a2 = e16.anchor.rectsPdfCoord) == null ? void 0 : _a2.length) ? e16.anchor.rectsPdfCoord : [e16.anchor.rectPdfCoord];
|
|
4026
|
-
return
|
|
4031
|
+
return Ha({ markerPdf: e16.anchor.markerAnchor ?? { x: e16.anchor.rectPdfCoord.origin.x + e16.anchor.rectPdfCoord.size.width, y: e16.anchor.rectPdfCoord.origin.y + e16.anchor.rectPdfCoord.size.height }, lineRects: s9, sx: t3, sy: a4, cssPageWidth: o.cssPageWidth, iconSize: y.value });
|
|
4027
4032
|
})(e15);
|
|
4028
4033
|
return { position: "absolute", left: `${Math.max(0, t2 - 6)}px`, top: `${Math.max(0, a3 - 6)}px`, width: `${y.value + 12}px`, height: `${y.value + 12}px`, pointerEvents: "auto", zIndex: 20 };
|
|
4029
4034
|
}
|
|
4030
|
-
return (t2, a3) => unref(r2) &&
|
|
4031
|
-
}, ["stop"])) }, [createElementVNode("button", { type: "button", title: e15.label, style: normalizeStyle({ position: "absolute", left: "6px", top: "6px", width: `${y.value}px`, height: `${y.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) =>
|
|
4035
|
+
return (t2, a3) => unref(r2) && d2.value.length && e14.pdfPageWidth && e14.pdfPageHeight ? (openBlock(), createElementBlock("div", Ja, [(openBlock(true), createElementBlock(Fragment, null, renderList(d2.value, (e15) => (openBlock(), createElementBlock("div", { key: e15.id, style: normalizeStyle(C(e15)), onMousedown: a3[1] || (a3[1] = withModifiers(() => {
|
|
4036
|
+
}, ["stop"])) }, [createElementVNode("button", { type: "button", title: e15.label, style: normalizeStyle({ position: "absolute", left: "6px", top: "6px", width: `${y.value}px`, height: `${y.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, es), g2.value === e15.id ? (openBlock(), createElementBlock("div", { key: 0, ref_for: true, ref_key: "deleteMenuRef", ref: f, 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: a3[0] || (a3[0] = withModifiers(() => {
|
|
4032
4037
|
}, ["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) {
|
|
4033
4038
|
const t4 = r2.value;
|
|
4034
4039
|
if (!t4) return;
|
|
4035
|
-
await t4.requestRemoveBookmark(e16) && (
|
|
4036
|
-
})(e15.id) }, " 删除书签 ", 8,
|
|
4040
|
+
await t4.requestRemoveBookmark(e16) && (g2.value = null);
|
|
4041
|
+
})(e15.id) }, " 删除书签 ", 8, ts)], 512)) : createCommentVNode("", true)], 36))), 128))])) : createCommentVNode("", true);
|
|
4037
4042
|
} });
|
|
4038
|
-
function
|
|
4043
|
+
function ss(e14) {
|
|
4039
4044
|
return e14.chapterId;
|
|
4040
4045
|
}
|
|
4041
|
-
function
|
|
4046
|
+
function is(e14, t2) {
|
|
4042
4047
|
e14.wait(t2, () => {
|
|
4043
4048
|
});
|
|
4044
4049
|
}
|
|
4045
|
-
const
|
|
4046
|
-
const a3 = e14,
|
|
4050
|
+
const os = /* @__PURE__ */ defineComponent({ __name: "ChapterPageSurface", props: { item: {}, features: {}, showNoteMarkers: { type: Boolean }, showBookmarkMarkers: { type: Boolean }, showRedactionLayer: { type: Boolean }, noteMarkerUi: {}, bookmarkMarkerUi: {}, buildSelectionMenu: { type: Function }, createNote: {}, annotationSelectionMenu: {}, redactionSelectionMenu: {}, renderPageOverlay: { type: Function } }, setup(e14) {
|
|
4051
|
+
const a3 = e14, i2 = computed(() => ss(a3.item));
|
|
4047
4052
|
!(function(e15) {
|
|
4048
4053
|
const { provides: t2 } = useCapability(DocumentManagerPlugin.id);
|
|
4049
4054
|
watch([t2, e15], ([e16, t3]) => {
|
|
4050
4055
|
e16 && t3 && e16.isDocumentOpen(t3) && e16.setActiveDocument(t3);
|
|
4051
4056
|
}, { immediate: true });
|
|
4052
|
-
})(
|
|
4057
|
+
})(i2);
|
|
4053
4058
|
const { provides: o } = useCapability(DocumentManagerPlugin.id), { provides: r2 } = useCapability(SelectionPlugin.id), l = computed(() => {
|
|
4054
4059
|
var _a2, _b;
|
|
4055
|
-
return (_b = (_a2 = o.value) == null ? void 0 : _a2.getDocument(
|
|
4060
|
+
return (_b = (_a2 = o.value) == null ? void 0 : _a2.getDocument(i2.value)) == null ? void 0 : _b.pages[a3.item.localPageIndex];
|
|
4056
4061
|
});
|
|
4057
|
-
function
|
|
4062
|
+
function d2(e15, t2) {
|
|
4058
4063
|
const s9 = a3.createNote.value;
|
|
4059
4064
|
if (s9) return (a4) => {
|
|
4060
4065
|
var _a2;
|
|
4061
|
-
const
|
|
4062
|
-
return h("div", a4.menuWrapperProps, [h("div", { style:
|
|
4066
|
+
const i3 = { position: "absolute", pointerEvents: "auto", left: "50%", transform: "translateX(-50%)", top: ((_a2 = a4.placement) == null ? void 0 : _a2.suggestTop) ? -40 : a4.rect.size.height + 8 };
|
|
4067
|
+
return h$1("div", a4.menuWrapperProps, [h$1("div", { style: i3 }, h$1("button", { type: "button", style: { padding: "6px 10px", fontSize: "12px", border: "1px solid #e2e8f0", borderRadius: "6px", background: "#fff", cursor: "pointer" }, onClick: () => {
|
|
4063
4068
|
if (!r2.value) return;
|
|
4064
4069
|
const a5 = r2.value.getHighlightRectsForPage(e15.localPageIndex, t2);
|
|
4065
|
-
|
|
4070
|
+
is(r2.value.getSelectedText(t2), (t3) => {
|
|
4066
4071
|
s9((function(e16, t4, a6) {
|
|
4067
4072
|
return { chapterId: e16.chapterId, localPageIndex: e16.localPageIndex, globalPageIndex: e16.globalPageIndex, globalPageNumber: e16.globalPageNumber, rectsPdfCoord: t4, selectedText: a6 };
|
|
4068
4073
|
})(e15, a5, t3.join("\n")));
|
|
@@ -4070,33 +4075,33 @@ const Xa = /* @__PURE__ */ defineComponent({ __name: "ChapterPageSurface", props
|
|
|
4070
4075
|
} }, "添加附注"))]);
|
|
4071
4076
|
};
|
|
4072
4077
|
}
|
|
4073
|
-
const
|
|
4074
|
-
const e15 = a3.buildSelectionMenu, t2 = { item: a3.item, defaultMenu:
|
|
4078
|
+
const c = computed(() => {
|
|
4079
|
+
const e15 = a3.buildSelectionMenu, t2 = { item: a3.item, defaultMenu: d2(a3.item, i2.value), createNote: a3.createNote.value };
|
|
4075
4080
|
if (e15) {
|
|
4076
4081
|
const a4 = e15(t2);
|
|
4077
4082
|
if (a4) return a4;
|
|
4078
4083
|
}
|
|
4079
4084
|
return t2.defaultMenu;
|
|
4080
|
-
}),
|
|
4085
|
+
}), u = computed(() => {
|
|
4081
4086
|
var _a2;
|
|
4082
4087
|
return (_a2 = a3.renderPageOverlay) == null ? void 0 : _a2.call(a3, a3.item);
|
|
4083
4088
|
});
|
|
4084
|
-
return (t2, a4) => e14.item.isPlaceholder ? createCommentVNode("", true) : (openBlock(), createBlock(unref(GlobalPointerProvider), { key: 0, "document-id":
|
|
4089
|
+
return (t2, a4) => e14.item.isPlaceholder ? createCommentVNode("", true) : (openBlock(), createBlock(unref(GlobalPointerProvider), { key: 0, "document-id": i2.value }, { default: withCtx(() => [createVNode(unref(Rotate), { "document-id": i2.value, "page-index": e14.item.localPageIndex, style: { backgroundColor: "#fff" } }, { default: withCtx(() => [createVNode(unref(PagePointerProvider), { "document-id": i2.value, "page-index": e14.item.localPageIndex, style: normalizeStyle(unref(be$1)), onPointerdown: unref(Pe$1) }, { default: withCtx(() => [createVNode(unref(xa), { "chapter-id": i2.value, "local-page-index": e14.item.localPageIndex }, null, 8, ["chapter-id", "local-page-index"]), createVNode(unref(SelectionLayer), { "document-id": i2.value, "page-index": e14.item.localPageIndex, "selection-menu": c.value }, null, 8, ["document-id", "page-index", "selection-menu"]), e14.showRedactionLayer ? (openBlock(), createBlock(unref(RedactionLayer), { key: 0, "document-id": i2.value, "page-index": e14.item.localPageIndex, "selection-menu": e14.redactionSelectionMenu }, null, 8, ["document-id", "page-index", "selection-menu"])) : createCommentVNode("", true), createVNode(unref(AnnotationLayer), { "document-id": i2.value, "page-index": e14.item.localPageIndex, "selection-menu": e14.annotationSelectionMenu }, null, 8, ["document-id", "page-index", "selection-menu"]), e14.showBookmarkMarkers && l.value ? (openBlock(), createBlock(as, { key: 1, "chapter-id": i2.value, "local-page-index": e14.item.localPageIndex, "pdf-page-width": l.value.size.width, "pdf-page-height": l.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), u.value ? (openBlock(), createBlock(resolveDynamicComponent(u.value), { key: 2 })) : createCommentVNode("", true), e14.showNoteMarkers && l.value ? (openBlock(), createBlock(Qa, { key: 3, "chapter-id": i2.value, "local-page-index": e14.item.localPageIndex, "pdf-page-width": l.value.size.width, "pdf-page-height": l.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"]));
|
|
4085
4090
|
} });
|
|
4086
|
-
const
|
|
4087
|
-
const o = e14, r2 = computed(() =>
|
|
4091
|
+
const rs = /* @__PURE__ */ defineComponent({ __name: "HoverBookmarkLayer", props: { item: {}, pdfPageWidth: {}, pdfPageHeight: {}, cssPageWidth: {}, cssPageHeight: {}, hoverUi: {} }, setup(e14) {
|
|
4092
|
+
const o = e14, r2 = computed(() => ss(o.item)), { provides: d2 } = useCapability(SelectionPlugin.id), { provides: u } = useCapability(Bt$1.id), p2 = ref(null), g2 = ref(null), f = ref(null), P = ref(null), w = computed(() => {
|
|
4088
4093
|
var _a2;
|
|
4089
4094
|
return ((_a2 = o.hoverUi) == null ? void 0 : _a2.iconSize) ?? 16;
|
|
4090
4095
|
}), y = computed(() => P.value ?? f.value);
|
|
4091
4096
|
let C = null, I = 0;
|
|
4092
4097
|
function M() {
|
|
4093
|
-
const e15 =
|
|
4098
|
+
const e15 = d2.value;
|
|
4094
4099
|
if (!e15) return;
|
|
4095
4100
|
const t2 = e15.forDocument(r2.value).getState().geometry[o.item.localPageIndex];
|
|
4096
|
-
t2 && (
|
|
4101
|
+
t2 && (g2.value = t2);
|
|
4097
4102
|
}
|
|
4098
|
-
watch([
|
|
4099
|
-
if (C == null ? void 0 : C(), C = null, cancelAnimationFrame(I),
|
|
4103
|
+
watch([d2, r2, () => o.item.localPageIndex], ([e15]) => {
|
|
4104
|
+
if (C == null ? void 0 : C(), C = null, cancelAnimationFrame(I), g2.value = null, !e15) return;
|
|
4100
4105
|
const t2 = e15.forDocument(r2.value);
|
|
4101
4106
|
C = t2.onSelectionChange(M);
|
|
4102
4107
|
let a3 = false;
|
|
@@ -4114,37 +4119,37 @@ const Qa = /* @__PURE__ */ defineComponent({ __name: "HoverBookmarkLayer", props
|
|
|
4114
4119
|
};
|
|
4115
4120
|
}, { immediate: true });
|
|
4116
4121
|
let x = null;
|
|
4117
|
-
watch([
|
|
4118
|
-
x && (document.removeEventListener("mousemove", x), x = null),
|
|
4122
|
+
watch([g2, () => o.pdfPageWidth, P, d2], () => {
|
|
4123
|
+
x && (document.removeEventListener("mousemove", x), x = null), g2.value && o.pdfPageWidth && (x = (e15) => {
|
|
4119
4124
|
if (P.value) return;
|
|
4120
|
-
const t2 =
|
|
4125
|
+
const t2 = d2.value;
|
|
4121
4126
|
if (t2) try {
|
|
4122
4127
|
if (t2.forDocument(r2.value).getState().selecting) return void (f.value = null);
|
|
4123
4128
|
} catch {
|
|
4124
4129
|
}
|
|
4125
|
-
const a3 =
|
|
4130
|
+
const a3 = p2.value;
|
|
4126
4131
|
if (!a3) return;
|
|
4127
4132
|
const s9 = a3.getBoundingClientRect();
|
|
4128
4133
|
if (e15.clientX < s9.left || e15.clientX > s9.right || e15.clientY < s9.top || e15.clientY > s9.bottom) return void (f.value = null);
|
|
4129
|
-
const
|
|
4134
|
+
const i2 = (function(e16, t3) {
|
|
4130
4135
|
const a4 = glyphAt(e16, t3);
|
|
4131
4136
|
if (a4 < 0) return null;
|
|
4132
4137
|
const s10 = expandToLineBoundary(e16, a4);
|
|
4133
4138
|
if (!s10) return null;
|
|
4134
|
-
const
|
|
4135
|
-
return 0 ===
|
|
4136
|
-
})(
|
|
4137
|
-
f.value = (
|
|
4139
|
+
const i3 = rectsWithinSlice(e16, s10.from, s10.to);
|
|
4140
|
+
return 0 === i3.length ? null : { lineRects: i3, charFrom: s10.from, charTo: s10.to };
|
|
4141
|
+
})(g2.value, { x: (e15.clientX - s9.left) / (o.cssPageWidth / o.pdfPageWidth), y: (e15.clientY - s9.top) / (o.cssPageHeight / o.pdfPageHeight) });
|
|
4142
|
+
f.value = (i2 == null ? void 0 : i2.lineRects) ?? null;
|
|
4138
4143
|
}, document.addEventListener("mousemove", x));
|
|
4139
4144
|
}, { immediate: true }), onBeforeUnmount(() => {
|
|
4140
4145
|
x && document.removeEventListener("mousemove", x), cancelAnimationFrame(I), C == null ? void 0 : C();
|
|
4141
4146
|
});
|
|
4142
4147
|
const k2 = computed(() => {
|
|
4143
4148
|
const e15 = y.value;
|
|
4144
|
-
return (e15 == null ? void 0 : e15.length) ?
|
|
4149
|
+
return (e15 == null ? void 0 : e15.length) ? qt(o.item.chapterId, o.item.localPageIndex, e15, { globalPageIndex: o.item.globalPageIndex, globalPageNumber: o.item.globalPageNumber }) : null;
|
|
4145
4150
|
}), L2 = computed(() => {
|
|
4146
4151
|
const e15 = k2.value, t2 = u.value;
|
|
4147
|
-
return !(!e15 || !t2) && t2.listBookmarks().some((t3) =>
|
|
4152
|
+
return !(!e15 || !t2) && t2.listBookmarks().some((t3) => Ut(t3.anchor, e15));
|
|
4148
4153
|
});
|
|
4149
4154
|
function $2() {
|
|
4150
4155
|
const e15 = u.value, t2 = k2.value;
|
|
@@ -4153,45 +4158,45 @@ const Qa = /* @__PURE__ */ defineComponent({ __name: "HoverBookmarkLayer", props
|
|
|
4153
4158
|
const z = computed(() => {
|
|
4154
4159
|
const e15 = y.value, t2 = e15 == null ? void 0 : e15[e15.length - 1];
|
|
4155
4160
|
if (!t2 || !o.pdfPageWidth) return null;
|
|
4156
|
-
const a3 = o.cssPageWidth / o.pdfPageWidth, s9 = o.cssPageHeight / o.pdfPageHeight,
|
|
4157
|
-
return { iconLeft: Math.min((t2.origin.x + t2.size.width) * a3 + 6, Math.max(0, o.cssPageWidth -
|
|
4161
|
+
const a3 = o.cssPageWidth / o.pdfPageWidth, s9 = o.cssPageHeight / o.pdfPageHeight, i2 = w.value;
|
|
4162
|
+
return { iconLeft: Math.min((t2.origin.x + t2.size.width) * a3 + 6, Math.max(0, o.cssPageWidth - i2 - 2)), iconTop: t2.origin.y * s9 + (t2.size.height * s9 - i2) / 2, zoneLeft: Math.max(0, (t2.origin.x + t2.size.width) * a3 - 4), zoneTop: Math.max(0, t2.origin.y * s9 - 4), size: i2 };
|
|
4158
4163
|
});
|
|
4159
4164
|
return (t2, a3) => {
|
|
4160
4165
|
var _a2;
|
|
4161
|
-
return unref(u) && e14.pdfPageWidth && e14.pdfPageHeight ? (openBlock(), createElementBlock("div", { key: 0, ref_key: "rootRef", ref:
|
|
4166
|
+
return unref(u) && e14.pdfPageWidth && e14.pdfPageHeight ? (openBlock(), createElementBlock("div", { key: 0, ref_key: "rootRef", ref: p2, style: { position: "absolute", inset: "0", zIndex: 14, pointerEvents: "none" } }, [z.value && y.value && !L2.value ? (openBlock(), createElementBlock("div", { key: 0, style: normalizeStyle({ position: "absolute", left: `${z.value.zoneLeft}px`, top: `${z.value.zoneTop}px`, width: `${z.value.size + 20}px`, height: `${(((_a2 = y.value[y.value.length - 1]) == null ? void 0 : _a2.size.height) ?? 0) * (e14.cssPageHeight / e14.pdfPageHeight) + z.value.size + 12}px`, pointerEvents: "auto" }), onMouseenter: a3[0] || (a3[0] = (e15) => P.value = y.value), onMouseleave: a3[1] || (a3[1] = (e15) => P.value = null) }, [createElementVNode("button", { type: "button", title: "添加书签", style: normalizeStyle({ position: "absolute", left: z.value.iconLeft - z.value.zoneLeft + "px", top: z.value.iconTop - z.value.zoneTop + "px", width: `${z.value.size}px`, height: `${z.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($2, ["stop"]) }, " 🔖 ", 4)], 36)) : createCommentVNode("", true)], 512)) : createCommentVNode("", true);
|
|
4162
4167
|
};
|
|
4163
|
-
} }),
|
|
4164
|
-
const
|
|
4168
|
+
} }), ns = { key: 0, width: "24", height: "24", viewBox: "0 0 28 28", fill: "none", "aria-hidden": "" }, ls = { key: 0, x: "5", y: "4", width: "18", height: "20", rx: "3", fill: "#fde047" }, hs = { key: 1, d: "M6 22h16", stroke: "#dc2626", "stroke-width": "2.2", "stroke-linecap": "round" }, ds = { 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" }, cs = { key: 3, d: "M5 14h18", stroke: "#dc2626", "stroke-width": "2.2", "stroke-linecap": "round" }, us = { key: 1, width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "" }, ps = /* @__PURE__ */ defineComponent({ __name: "SelectionToolbarIcons", props: { kind: {} }, setup: (e14) => (t2, a3) => "note" !== e14.kind ? (openBlock(), createElementBlock("svg", ns, ["highlight" === e14.kind ? (openBlock(), createElementBlock("rect", ls)) : createCommentVNode("", true), a3[0] || (a3[0] = 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", hs)) : "squiggly" === e14.kind ? (openBlock(), createElementBlock("path", ds)) : "strikeout" === e14.kind ? (openBlock(), createElementBlock("path", cs)) : createCommentVNode("", true)])) : (openBlock(), createElementBlock("svg", us, [...a3[1] || (a3[1] = [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)])])) }), gs = ["title", "aria-label", "onMouseenter", "onClick"], fs = ["title", "onMouseenter", "onClick"], ms = { style: { "font-size": "11px", "font-weight": "600" } }, vs = /* @__PURE__ */ defineComponent({ __name: "SelectionToolbarCard", props: { placementAbove: { type: Boolean }, anchorHeight: {}, hiddenBuiltinActions: {}, extraActions: {} }, emits: ["action"], setup(e14, { emit: s9 }) {
|
|
4169
|
+
const i2 = e14, o = s9, r2 = [{ id: "highlight", label: "高亮背景" }, { id: "underline", label: "下划线" }, { id: "squiggly", label: "波浪线" }, { id: "strikeout", label: "删除线" }, { id: "note", label: "添加笔记" }], d2 = computed(() => new Set(i2.hiddenBuiltinActions ?? [])), g2 = computed(() => r2.filter((e15) => "note" !== e15.id && !d2.value.has(e15.id))), f = computed(() => !d2.value.has("note")), m = computed(() => [...i2.extraActions ?? []].sort((e15, t2) => (e15.order ?? 0) - (t2.order ?? 0))), v = ref(null), P = computed(() => ({ position: "absolute", pointerEvents: "auto", left: "50%", transform: "translateX(-50%)", top: i2.placementAbove ? void 0 : `${i2.anchorHeight + 10}px`, bottom: i2.placementAbove ? `${i2.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)" }));
|
|
4165
4170
|
function y(e15, t2 = false) {
|
|
4166
4171
|
return { display: "flex", alignItems: "center", justifyContent: "center", width: "32px", height: "32px", padding: 0, margin: 0, border: "none", borderRadius: "8px", background: v.value === e15 ? t2 ? "#fffbeb" : "#f1f5f9" : "transparent", color: t2 ? "#b45309" : "#334155", cursor: "pointer", flexShrink: 0, WebkitAppearance: "none", appearance: "none" };
|
|
4167
4172
|
}
|
|
4168
4173
|
const C = { width: "1px", height: "20px", margin: "0 4px", background: "rgba(15, 23, 42, 0.1)", flexShrink: 0 };
|
|
4169
|
-
return (e15, t2) => (openBlock(), createElementBlock("div", { role: "toolbar", "aria-label": "选区工具", style: normalizeStyle(P.value) }, [(openBlock(true), createElementBlock(Fragment, null, renderList(
|
|
4170
|
-
} }),
|
|
4171
|
-
const
|
|
4172
|
-
const a3 = e14, s9 = computed(() => a3.features), { hostRef:
|
|
4174
|
+
return (e15, t2) => (openBlock(), createElementBlock("div", { role: "toolbar", "aria-label": "选区工具", style: normalizeStyle(P.value) }, [(openBlock(true), createElementBlock(Fragment, null, renderList(g2.value, (e16) => (openBlock(), createElementBlock("button", { key: e16.id, type: "button", title: e16.label, "aria-label": e16.label, style: normalizeStyle(y(e16.id)), onMouseenter: (t3) => v.value = e16.id, onMouseleave: t2[0] || (t2[0] = (e17) => v.value = null), onClick: (t3) => o("action", e16.id) }, [createVNode(ps, { kind: e16.id }, null, 8, ["kind"])], 44, gs))), 128)), (openBlock(true), createElementBlock(Fragment, null, renderList(m.value, (e16) => (openBlock(), createElementBlock("button", { key: e16.id, type: "button", title: e16.label, style: normalizeStyle(y(e16.id)), onMouseenter: (t3) => v.value = e16.id, onMouseleave: t2[1] || (t2[1] = (e17) => v.value = null), onClick: (t3) => o("action", e16.id) }, [createElementVNode("span", ms, toDisplayString(e16.label.slice(0, 2)), 1)], 44, fs))), 128)), f.value ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [createElementVNode("span", { style: C, "aria-hidden": "" }), createElementVNode("button", { type: "button", title: "添加笔记", "aria-label": "添加笔记", style: normalizeStyle(y("note", true)), onMouseenter: t2[2] || (t2[2] = (e16) => v.value = "note"), onMouseleave: t2[3] || (t2[3] = (e16) => v.value = null), onClick: t2[4] || (t2[4] = (e16) => o("action", "note")) }, [createVNode(ps, { kind: "note" })], 36)], 64)) : createCommentVNode("", true)], 4));
|
|
4175
|
+
} }), bs = { highlight: "highlight", underline: "underline", squiggly: "squiggly", strikeout: "strikeout" };
|
|
4176
|
+
const Ps = /* @__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) {
|
|
4177
|
+
const a3 = e14, s9 = computed(() => a3.features), { hostRef: i2 } = ga(s9), o = (function() {
|
|
4173
4178
|
const { registry: e15 } = useRegistry();
|
|
4174
4179
|
return computed(() => {
|
|
4175
4180
|
var _a2, _b, _c;
|
|
4176
|
-
const t2 = (_c = (_b = (_a2 = e15.value) == null ? void 0 : _a2.getPlugin(
|
|
4181
|
+
const t2 = (_c = (_b = (_a2 = e15.value) == null ? void 0 : _a2.getPlugin(Pt$1.id)) == null ? void 0 : _b.provides) == null ? void 0 : _c.call(_b);
|
|
4177
4182
|
return t2 ? (e16) => t2.createNoteFromSelection(e16) : null;
|
|
4178
4183
|
});
|
|
4179
4184
|
})(), r2 = (function() {
|
|
4180
4185
|
const { registry: e15 } = useRegistry();
|
|
4181
4186
|
return computed(() => {
|
|
4182
4187
|
var _a2;
|
|
4183
|
-
return !!((_a2 = e15.value) == null ? void 0 : _a2.getPlugin(
|
|
4188
|
+
return !!((_a2 = e15.value) == null ? void 0 : _a2.getPlugin(Pt$1.id));
|
|
4184
4189
|
});
|
|
4185
4190
|
})(), c = (function() {
|
|
4186
4191
|
const { registry: e15 } = useRegistry();
|
|
4187
4192
|
return computed(() => {
|
|
4188
4193
|
var _a2;
|
|
4189
|
-
return !!((_a2 = e15.value) == null ? void 0 : _a2.getPlugin(
|
|
4194
|
+
return !!((_a2 = e15.value) == null ? void 0 : _a2.getPlugin(Bt$1.id));
|
|
4190
4195
|
});
|
|
4191
4196
|
})(), u = computed(() => {
|
|
4192
4197
|
var _a2, _b;
|
|
4193
4198
|
return a3.showNoteMarkers && r2.value && false !== ((_b = (_a2 = a3.features) == null ? void 0 : _a2.notes) == null ? void 0 : _b.enabled);
|
|
4194
|
-
}),
|
|
4199
|
+
}), p2 = computed(() => {
|
|
4195
4200
|
var _a2, _b;
|
|
4196
4201
|
return a3.showBookmarkMarkers && c.value && false !== ((_b = (_a2 = a3.features) == null ? void 0 : _a2.bookmarks) == null ? void 0 : _b.enabled);
|
|
4197
4202
|
}), f = computed(() => {
|
|
@@ -4201,34 +4206,34 @@ const cs = /* @__PURE__ */ defineComponent({ __name: "PdfChapterViewport", props
|
|
|
4201
4206
|
const s10 = computed(() => {
|
|
4202
4207
|
var _a2;
|
|
4203
4208
|
return (_a2 = e15()) == null ? void 0 : _a2.selectionToolbar;
|
|
4204
|
-
}),
|
|
4209
|
+
}), i3 = computed(() => {
|
|
4205
4210
|
var _a2, _b;
|
|
4206
4211
|
return false !== ((_b = (_a2 = e15()) == null ? void 0 : _a2.markup) == null ? void 0 : _b.enabled);
|
|
4207
4212
|
}), o2 = computed(() => {
|
|
4208
4213
|
var _a2, _b;
|
|
4209
4214
|
return false !== ((_b = (_a2 = e15()) == null ? void 0 : _a2.notes) == null ? void 0 : _b.enabled);
|
|
4210
|
-
}), { provides: r3 } = useCapability(SelectionPlugin.id), { provides: n2 } = useCapability(AnnotationPlugin.id), { provides: l } = useCapability(
|
|
4215
|
+
}), { provides: r3 } = useCapability(SelectionPlugin.id), { provides: n2 } = useCapability(AnnotationPlugin.id), { provides: l } = useCapability(Pt$1.id);
|
|
4211
4216
|
return computed(() => {
|
|
4212
4217
|
var _a2, _b, _c;
|
|
4213
|
-
if (false !== ((_a2 = s10.value) == null ? void 0 : _a2.enabled) && (
|
|
4214
|
-
const
|
|
4215
|
-
return (
|
|
4218
|
+
if (false !== ((_a2 = s10.value) == null ? void 0 : _a2.enabled) && (i3.value || o2.value || ((_c = (_b = s10.value) == null ? void 0 : _b.extraActions) == null ? void 0 : _c.length))) return (t2) => {
|
|
4219
|
+
const h2 = ss(t2.item);
|
|
4220
|
+
return (d2) => {
|
|
4216
4221
|
var _a3, _b2, _c2;
|
|
4217
|
-
return h("div",
|
|
4222
|
+
return h$1("div", d2.menuWrapperProps, h$1(vs, { placementAbove: !!((_a3 = d2.placement) == null ? void 0 : _a3.suggestTop), anchorHeight: d2.rect.size.height, hiddenBuiltinActions: (_b2 = s10.value) == null ? void 0 : _b2.hiddenBuiltinActions, extraActions: (_c2 = s10.value) == null ? void 0 : _c2.extraActions, onAction: (s11) => {
|
|
4218
4223
|
var _a4, _b3, _c3;
|
|
4219
4224
|
if ("highlight" !== s11 && "underline" !== s11 && "squiggly" !== s11 && "strikeout" !== s11) {
|
|
4220
4225
|
if ("note" === s11) {
|
|
4221
4226
|
if (!r3.value || !l.value || !o2.value) return;
|
|
4222
|
-
const e16 = r3.value.getHighlightRectsForPage(t2.item.localPageIndex,
|
|
4223
|
-
return void
|
|
4227
|
+
const e16 = r3.value.getHighlightRectsForPage(t2.item.localPageIndex, h2);
|
|
4228
|
+
return void is(r3.value.getSelectedText(h2), (a5) => {
|
|
4224
4229
|
var _a5;
|
|
4225
4230
|
(_a5 = l.value) == null ? void 0 : _a5.requestCreateFromSelection({ chapterId: t2.item.chapterId, localPageIndex: t2.item.localPageIndex, globalPageIndex: t2.item.globalPageIndex, globalPageNumber: t2.item.globalPageNumber, rectsPdfCoord: e16, selectedText: a5.join("\n") });
|
|
4226
4231
|
});
|
|
4227
4232
|
}
|
|
4228
4233
|
(_a4 = a4 == null ? void 0 : a4.onExtraAction) == null ? void 0 : _a4.call(a4, s11, t2);
|
|
4229
4234
|
} else {
|
|
4230
|
-
if (!r3.value || !n2.value || !
|
|
4231
|
-
|
|
4235
|
+
if (!r3.value || !n2.value || !i3.value) return;
|
|
4236
|
+
Me(h2, bs[s11], n2.value, r3.value, (_c3 = (_b3 = e15()) == null ? void 0 : _b3.markup) == null ? void 0 : _c3.styles);
|
|
4232
4237
|
}
|
|
4233
4238
|
} }));
|
|
4234
4239
|
};
|
|
@@ -4246,52 +4251,52 @@ const cs = /* @__PURE__ */ defineComponent({ __name: "PdfChapterViewport", props
|
|
|
4246
4251
|
if (f.value) {
|
|
4247
4252
|
const s11 = (function(e16) {
|
|
4248
4253
|
var _a3, _b, _c, _d;
|
|
4249
|
-
const t3 =
|
|
4250
|
-
return e16.isPlaceholder || !s12 ? null : h(
|
|
4254
|
+
const t3 = ss(e16), s12 = (_b = (_a3 = y.value) == null ? void 0 : _a3.getDocument(t3)) == null ? void 0 : _b.pages[e16.localPageIndex];
|
|
4255
|
+
return e16.isPlaceholder || !s12 ? null : h$1(rs, { item: e16, pdfPageWidth: s12.size.width, pdfPageHeight: s12.size.height, cssPageWidth: e16.width, cssPageHeight: e16.height, hoverUi: (_d = (_c = a3.features) == null ? void 0 : _c.bookmarks) == null ? void 0 : _d.hover });
|
|
4251
4256
|
})(e15);
|
|
4252
4257
|
s11 && t2.push(s11);
|
|
4253
4258
|
}
|
|
4254
4259
|
const s10 = (_a2 = a3.renderPageOverlay) == null ? void 0 : _a2.call(a3, e15);
|
|
4255
|
-
if (s10 && t2.push(s10), t2.length) return h("div", t2);
|
|
4260
|
+
if (s10 && t2.push(s10), t2.length) return h$1("div", t2);
|
|
4256
4261
|
}
|
|
4257
|
-
return (t2, a4) => (openBlock(), createElementBlock("div", { ref_key: "hostRef", ref:
|
|
4262
|
+
return (t2, a4) => (openBlock(), createElementBlock("div", { ref_key: "hostRef", ref: i2, class: normalizeClass(e14.className), style: normalizeStyle(e14.className ? void 0 : unref(ve$1)) }, [createVNode(unref(Sa), { class: normalizeClass(e14.className) }, { page: withCtx(({ item: t3 }) => {
|
|
4258
4263
|
var _a2, _b, _c, _d;
|
|
4259
|
-
return [createVNode(
|
|
4264
|
+
return [createVNode(os, { item: t3, features: e14.features, "show-note-markers": u.value, "show-bookmark-markers": p2.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": b.value, "create-note": unref(o), "annotation-selection-menu": e14.annotationSelectionMenu, "redaction-selection-menu": e14.redactionSelectionMenu, "render-page-overlay": I }, 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"])];
|
|
4260
4265
|
}), _: 1 }, 8, ["class"]), renderSlot(t2.$slots, "default")], 6));
|
|
4261
|
-
} }),
|
|
4266
|
+
} }), ws = { key: 0, style: { display: "flex", flexDirection: "column", height: "100%", minHeight: 0, width: "100%" } }, ys = /* @__PURE__ */ defineComponent({ __name: "ChapterPdfViewer", props: { engine: {}, options: {}, editorOptions: {}, features: {}, className: {}, viewportClassName: {}, onExtraSelectionAction: { type: Function } }, setup(e14) {
|
|
4262
4267
|
const a3 = e14, s9 = computed(() => (function(e15) {
|
|
4263
|
-
if (e15.options) return
|
|
4268
|
+
if (e15.options) return na(e15.options);
|
|
4264
4269
|
if (!e15.editorOptions) throw new Error("ChapterPdfViewer: 请传入 `options`(推荐),或同时传入 `editorOptions` 与 `features`");
|
|
4265
|
-
const t2 =
|
|
4270
|
+
const t2 = xe(e15.features), { plugins: a4 } = sa({ ...e15.editorOptions, features: t2 });
|
|
4266
4271
|
return { plugins: a4, features: t2, editorOptions: { ...e15.editorOptions, features: t2 } };
|
|
4267
4272
|
})({ engine: a3.engine, options: a3.options, editorOptions: a3.editorOptions, features: a3.features }));
|
|
4268
|
-
return (t2, a4) => (openBlock(), createElementBlock("div", { class: normalizeClass(e14.className), style: normalizeStyle(e14.className ? void 0 : unref(ve$1)) }, [createVNode(unref(EmbedPDF), { engine: e14.engine, plugins: s9.value.plugins }, { default: withCtx(({ pluginsReady: a5 }) => [a5 ? (openBlock(), createElementBlock("div",
|
|
4269
|
-
} }),
|
|
4273
|
+
return (t2, a4) => (openBlock(), createElementBlock("div", { class: normalizeClass(e14.className), style: normalizeStyle(e14.className ? void 0 : unref(ve$1)) }, [createVNode(unref(EmbedPDF), { engine: e14.engine, plugins: s9.value.plugins }, { default: withCtx(({ pluginsReady: a5 }) => [a5 ? (openBlock(), createElementBlock("div", ws, [renderSlot(t2.$slots, "prepend"), createVNode(Ps, { class: normalizeClass(e14.viewportClassName), style: { flex: 1, minHeight: 0 }, features: s9.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));
|
|
4274
|
+
} }), Cs = { class: "chapter-tree-row" }, Is = ["aria-expanded"], Ms = { key: 1, class: "chapter-tree-toggle-spacer", "aria-hidden": "" }, Ss = { class: "chapter-tree-label" }, xs = { class: "chapter-tree-meta" }, ks = { key: 0 }, Ls = (e14, t2) => {
|
|
4270
4275
|
const a3 = e14.__vccOpts || e14;
|
|
4271
|
-
for (const [s9,
|
|
4276
|
+
for (const [s9, i2] of t2) a3[s9] = i2;
|
|
4272
4277
|
return a3;
|
|
4273
|
-
},
|
|
4274
|
-
const s9 = { idle: "未加载", loading: "加载中", loaded: "已加载", closed: "已卸载", error: "失败", "password-required": "需密码" },
|
|
4275
|
-
return (t2, a3) => (openBlock(), createElementBlock("li", null, [createElementVNode("div",
|
|
4276
|
-
} }), [["__scopeId", "data-v-315bbf7a"]]),
|
|
4277
|
-
const o = e14, r2 = t2, { provides: h2 } = useCapability(
|
|
4278
|
-
function
|
|
4279
|
-
if (!
|
|
4278
|
+
}, $s = /* @__PURE__ */ Ls(/* @__PURE__ */ defineComponent({ __name: "ChapterTreeItem", props: { node: {}, depth: {}, activeChapterId: {}, chapterStatus: {} }, emits: ["select"], setup(e14) {
|
|
4279
|
+
const s9 = { idle: "未加载", loading: "加载中", loaded: "已加载", closed: "已卸载", error: "失败", "password-required": "需密码" }, i2 = e14, o = computed(() => i2.node.children ?? []), r2 = computed(() => o.value.length > 0), h2 = ref(i2.depth < 1), u = computed(() => i2.activeChapterId === i2.node.id), p2 = computed(() => i2.chapterStatus[i2.node.id] ?? "idle"), g2 = computed(() => !r2.value);
|
|
4280
|
+
return (t2, a3) => (openBlock(), createElementBlock("li", null, [createElementVNode("div", Cs, [r2.value ? (openBlock(), createElementBlock("button", { key: 0, type: "button", class: "chapter-tree-toggle", "aria-expanded": h2.value, onClick: a3[0] || (a3[0] = (e15) => h2.value = !h2.value) }, toDisplayString(h2.value ? "▼" : "▶"), 9, Is)) : (openBlock(), createElementBlock("span", Ms)), createElementVNode("button", { type: "button", class: normalizeClass(["chapter-tree-btn", { "chapter-tree-btn-active": u.value }]), onClick: a3[1] || (a3[1] = (a4) => t2.$emit("select", e14.node.id)) }, [createElementVNode("div", Ss, toDisplayString(e14.node.title), 1), createElementVNode("div", xs, [createElementVNode("span", null, " 第 " + toDisplayString(e14.node.startPage) + toDisplayString(e14.node.endPage !== e14.node.startPage ? `–${e14.node.endPage}` : "") + " 页 ", 1), g2.value ? (openBlock(), createElementBlock("span", ks, toDisplayString(s9[p2.value]), 1)) : createCommentVNode("", true)])], 2)]), r2.value && h2.value ? (openBlock(), createBlock(zs, { key: 0, nodes: o.value, depth: e14.depth + 1, "active-chapter-id": e14.activeChapterId, "chapter-status": e14.chapterStatus, onSelect: a3[2] || (a3[2] = (e15) => t2.$emit("select", e15)) }, null, 8, ["nodes", "depth", "active-chapter-id", "chapter-status"])) : createCommentVNode("", true)]));
|
|
4281
|
+
} }), [["__scopeId", "data-v-315bbf7a"]]), zs = /* @__PURE__ */ Ls(/* @__PURE__ */ defineComponent({ __name: "ChapterTreeList", props: { nodes: {}, depth: {}, activeChapterId: {}, chapterStatus: {} }, emits: ["select"], setup: (e14) => (t2, a3) => (openBlock(), createElementBlock("ul", { class: "chapter-tree-list", style: normalizeStyle({ marginLeft: e14.depth > 0 ? "12px" : "0" }) }, [(openBlock(true), createElementBlock(Fragment, null, renderList(e14.nodes, (s9) => (openBlock(), createBlock($s, { key: s9.id, node: s9, depth: e14.depth, "active-chapter-id": e14.activeChapterId, "chapter-status": e14.chapterStatus, onSelect: a3[0] || (a3[0] = (e15) => t2.$emit("select", e15)) }, null, 8, ["node", "depth", "active-chapter-id", "chapter-status"]))), 128))], 4)) }), [["__scopeId", "data-v-eb742e4f"]]), Ts = { class: "chapter-tree" }, Ds = { class: "chapter-tree-nav", "aria-label": "章节目录" }, Os = /* @__PURE__ */ Ls(/* @__PURE__ */ defineComponent({ __name: "ChapterTreePanel", props: { tree: {}, activeChapterId: {} }, emits: ["active-chapter-change"], setup(e14, { emit: t2 }) {
|
|
4282
|
+
const o = e14, r2 = t2, { provides: h2 } = useCapability(Je.id), { provides: d2 } = useCapability(Fe.id), u = ref({});
|
|
4283
|
+
function p2() {
|
|
4284
|
+
if (!d2.value) return;
|
|
4280
4285
|
const e15 = {}, t3 = (a3) => {
|
|
4281
4286
|
var _a2;
|
|
4282
|
-
for (const s9 of a3) e15[s9.id] =
|
|
4287
|
+
for (const s9 of a3) e15[s9.id] = d2.value.getChapterStatus(s9.id), ((_a2 = s9.children) == null ? void 0 : _a2.length) && t3(s9.children);
|
|
4283
4288
|
};
|
|
4284
4289
|
t3(o.tree), u.value = e15;
|
|
4285
4290
|
}
|
|
4286
|
-
watch([
|
|
4287
|
-
let
|
|
4291
|
+
watch([d2, () => o.tree], p2, { immediate: true });
|
|
4292
|
+
let g2 = null;
|
|
4288
4293
|
function f(e15) {
|
|
4289
4294
|
var _a2;
|
|
4290
4295
|
r2("active-chapter-change", e15), (_a2 = h2.value) == null ? void 0 : _a2.scrollToChapter(e15);
|
|
4291
4296
|
}
|
|
4292
|
-
return watch(
|
|
4293
|
-
|
|
4294
|
-
}, { immediate: true }), onBeforeUnmount(() =>
|
|
4297
|
+
return watch(d2, (e15) => {
|
|
4298
|
+
g2 == null ? void 0 : g2(), g2 = e15 ? e15.onChapterStatusChange(p2) : null;
|
|
4299
|
+
}, { immediate: true }), onBeforeUnmount(() => g2 == null ? void 0 : g2()), (t3, a3) => (openBlock(), createElementBlock("aside", Ts, [a3[0] || (a3[0] = createElementVNode("h2", { class: "chapter-tree-title" }, "章节目录", -1)), createElementVNode("nav", Ds, [createVNode(zs, { nodes: e14.tree, depth: 0, "active-chapter-id": e14.activeChapterId, "chapter-status": u.value, onSelect: f }, null, 8, ["nodes", "active-chapter-id", "chapter-status"])])]));
|
|
4295
4300
|
} }), [["__scopeId", "data-v-d7a0838d"]]);
|
|
4296
4301
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
4297
4302
|
__name: "ChapterPdfViewer",
|
|
@@ -4305,7 +4310,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
4305
4310
|
},
|
|
4306
4311
|
setup(__props) {
|
|
4307
4312
|
return (_ctx, _cache) => {
|
|
4308
|
-
return openBlock(), createBlock(unref(
|
|
4313
|
+
return openBlock(), createBlock(unref(ys), normalizeProps(guardReactiveProps(_ctx.$props)), createSlots({
|
|
4309
4314
|
default: withCtx(() => [
|
|
4310
4315
|
renderSlot(_ctx.$slots, "default")
|
|
4311
4316
|
]),
|
|
@@ -4323,47 +4328,47 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
4323
4328
|
}
|
|
4324
4329
|
});
|
|
4325
4330
|
function e13(e22) {
|
|
4326
|
-
const t2 = [],
|
|
4327
|
-
for (const
|
|
4328
|
-
|
|
4329
|
-
const [e32,
|
|
4330
|
-
if (e32 >
|
|
4331
|
+
const t2 = [], n2 = /* @__PURE__ */ new Set();
|
|
4332
|
+
for (const r2 of e22.chapters) {
|
|
4333
|
+
n2.has(r2.chapterId) && t2.push(`Duplicate chapterId: ${r2.chapterId}`), n2.add(r2.chapterId);
|
|
4334
|
+
const [e32, s22] = r2.globalPageRange, [a22, o] = r2.localPageRange;
|
|
4335
|
+
if (e32 > s22 && t2.push(`${r2.chapterId}: invalid globalPageRange [${e32},${s22}]`), a22 > o && t2.push(`${r2.chapterId}: invalid localPageRange [${a22},${o}]`), s22 - e32 !== o - a22 && t2.push(`${r2.chapterId}: page-count mismatch (global ${s22 - e32 + 1} vs local ${o - a22 + 1})`), r2.ownedGlobalPages) for (const n3 of r2.ownedGlobalPages) (n3 < e32 || n3 > s22) && t2.push(`${r2.chapterId}: ownedGlobalPages contains ${n3} outside range`);
|
|
4331
4336
|
}
|
|
4332
4337
|
return t2;
|
|
4333
4338
|
}
|
|
4334
|
-
const t = { kind: "first-wins" };
|
|
4335
|
-
function
|
|
4336
|
-
const
|
|
4339
|
+
const t$1 = { kind: "first-wins" };
|
|
4340
|
+
function n(e22, n2 = t$1) {
|
|
4341
|
+
const s22 = /* @__PURE__ */ new Map();
|
|
4337
4342
|
for (const t2 of e22.chapters) {
|
|
4338
|
-
const [e32,
|
|
4339
|
-
for (let
|
|
4340
|
-
const e42 =
|
|
4341
|
-
e42 ? e42.push(t2) :
|
|
4343
|
+
const [e32, n3] = t2.globalPageRange;
|
|
4344
|
+
for (let r2 = e32; r2 <= n3; r2++) {
|
|
4345
|
+
const e42 = s22.get(r2);
|
|
4346
|
+
e42 ? e42.push(t2) : s22.set(r2, [t2]);
|
|
4342
4347
|
}
|
|
4343
4348
|
}
|
|
4344
|
-
const
|
|
4345
|
-
for (const [t2, o] of
|
|
4346
|
-
return
|
|
4349
|
+
const a22 = /* @__PURE__ */ new Map();
|
|
4350
|
+
for (const [t2, o] of s22) a22.set(t2, r(t2, o, n2));
|
|
4351
|
+
return a22;
|
|
4347
4352
|
}
|
|
4348
|
-
function
|
|
4353
|
+
function r(e22, t2, n2) {
|
|
4349
4354
|
if (1 === t2.length) return t2[0].chapterId;
|
|
4350
|
-
switch (
|
|
4355
|
+
switch (n2.kind) {
|
|
4351
4356
|
case "first-wins":
|
|
4352
4357
|
return t2[0].chapterId;
|
|
4353
4358
|
case "last-wins":
|
|
4354
4359
|
return t2[t2.length - 1].chapterId;
|
|
4355
4360
|
case "explicit": {
|
|
4356
|
-
const
|
|
4361
|
+
const n3 = t2.find((t3) => {
|
|
4357
4362
|
var _a2;
|
|
4358
4363
|
return (_a2 = t3.ownedGlobalPages) == null ? void 0 : _a2.includes(e22);
|
|
4359
4364
|
});
|
|
4360
|
-
return
|
|
4365
|
+
return n3 ? n3.chapterId : t2[0].chapterId;
|
|
4361
4366
|
}
|
|
4362
4367
|
case "custom":
|
|
4363
|
-
return
|
|
4368
|
+
return n2.resolve(e22, t2);
|
|
4364
4369
|
}
|
|
4365
4370
|
}
|
|
4366
|
-
class
|
|
4371
|
+
class s {
|
|
4367
4372
|
constructor(e22) {
|
|
4368
4373
|
this._pages = e22, this._byChapter = /* @__PURE__ */ new Map(), this._byGlobalNumber = /* @__PURE__ */ new Map();
|
|
4369
4374
|
for (const t2 of e22) {
|
|
@@ -4385,8 +4390,8 @@ class n {
|
|
|
4385
4390
|
return this._byGlobalNumber.get(e22) ?? null;
|
|
4386
4391
|
}
|
|
4387
4392
|
toGlobal(e22, t2) {
|
|
4388
|
-
const
|
|
4389
|
-
return
|
|
4393
|
+
const n2 = this._byChapter.get(e22);
|
|
4394
|
+
return n2 ? n2.find((e32) => e32.localPageIndex === t2) ?? null : null;
|
|
4390
4395
|
}
|
|
4391
4396
|
pagesOfChapter(e22) {
|
|
4392
4397
|
return this._byChapter.get(e22) ?? [];
|
|
@@ -4397,25 +4402,25 @@ class n {
|
|
|
4397
4402
|
return t2 ? this._pages.indexOf(t2) : -1;
|
|
4398
4403
|
}
|
|
4399
4404
|
}
|
|
4400
|
-
function
|
|
4401
|
-
const
|
|
4405
|
+
function a(e22, r2 = t$1) {
|
|
4406
|
+
const a22 = n(e22, r2), o = /* @__PURE__ */ new Map();
|
|
4402
4407
|
for (const t2 of e22.chapters) o.set(t2.chapterId, t2);
|
|
4403
|
-
const
|
|
4404
|
-
let
|
|
4405
|
-
for (const t2 of
|
|
4406
|
-
const e32 =
|
|
4407
|
-
if (!
|
|
4408
|
-
const [
|
|
4409
|
-
|
|
4410
|
-
}
|
|
4411
|
-
return new
|
|
4408
|
+
const c = Array.from(a22.keys()).sort((e32, t2) => e32 - t2), l = [];
|
|
4409
|
+
let i2 = 0;
|
|
4410
|
+
for (const t2 of c) {
|
|
4411
|
+
const e32 = a22.get(t2), n2 = o.get(e32);
|
|
4412
|
+
if (!n2) continue;
|
|
4413
|
+
const [r3] = n2.globalPageRange, [s22] = n2.localPageRange, c2 = s22 + (t2 - r3);
|
|
4414
|
+
l.push({ globalPageIndex: i2++, globalPageNumber: t2, chapterId: e32, localPageIndex: c2 });
|
|
4415
|
+
}
|
|
4416
|
+
return new s(l);
|
|
4412
4417
|
}
|
|
4413
4418
|
const _ChapterManagerPlugin = class _ChapterManagerPlugin2 extends BasePlugin {
|
|
4414
4419
|
constructor(id, registry) {
|
|
4415
4420
|
super(id, registry);
|
|
4416
4421
|
this.statusChange$ = createBehaviorEmitter();
|
|
4417
4422
|
this.manifestChange$ = createEmitter();
|
|
4418
|
-
this.overlapStrategy = t;
|
|
4423
|
+
this.overlapStrategy = t$1;
|
|
4419
4424
|
this.chapterStatus = /* @__PURE__ */ new Map();
|
|
4420
4425
|
this.chapterLastUsed = /* @__PURE__ */ new Map();
|
|
4421
4426
|
this.passwordAttempts = /* @__PURE__ */ new Map();
|
|
@@ -4427,7 +4432,7 @@ const _ChapterManagerPlugin = class _ChapterManagerPlugin2 extends BasePlugin {
|
|
|
4427
4432
|
async initialize(config) {
|
|
4428
4433
|
this.config = config;
|
|
4429
4434
|
this.passwordProvider = config.passwordProvider;
|
|
4430
|
-
this.overlapStrategy = config.overlapStrategy ?? t;
|
|
4435
|
+
this.overlapStrategy = config.overlapStrategy ?? t$1;
|
|
4431
4436
|
this.documentManagerUnsubs.push(
|
|
4432
4437
|
this.documentManager.provides().onDocumentOpened((docState) => {
|
|
4433
4438
|
if (!this.isOwnedChapter(docState.id)) return;
|
|
@@ -4498,7 +4503,7 @@ const _ChapterManagerPlugin = class _ChapterManagerPlugin2 extends BasePlugin {
|
|
|
4498
4503
|
}
|
|
4499
4504
|
}
|
|
4500
4505
|
this.manifest = manifest2;
|
|
4501
|
-
this.virtualPageMap =
|
|
4506
|
+
this.virtualPageMap = a(manifest2, this.overlapStrategy);
|
|
4502
4507
|
this.manifestChange$.emit({ manifest: manifest2, map: this.virtualPageMap });
|
|
4503
4508
|
this.eagerPrefetchFromManifest();
|
|
4504
4509
|
}
|
|
@@ -4508,11 +4513,11 @@ const _ChapterManagerPlugin = class _ChapterManagerPlugin2 extends BasePlugin {
|
|
|
4508
4513
|
if (prefetch <= 0 || this.manifest.chapters.length === 0) return;
|
|
4509
4514
|
const now = Date.now();
|
|
4510
4515
|
const count = Math.min(prefetch, this.manifest.chapters.length);
|
|
4511
|
-
for (let
|
|
4512
|
-
const chapterId = this.manifest.chapters[
|
|
4516
|
+
for (let i2 = 0; i2 < count; i2++) {
|
|
4517
|
+
const chapterId = this.manifest.chapters[i2].chapterId;
|
|
4513
4518
|
this.chapterLastUsed.set(chapterId, now);
|
|
4514
|
-
const
|
|
4515
|
-
if (
|
|
4519
|
+
const st2 = this.chapterStatus.get(chapterId) ?? "idle";
|
|
4520
|
+
if (st2 === "idle" || st2 === "closed" || st2 === "error") {
|
|
4516
4521
|
void this.ensureChapterLoaded(chapterId);
|
|
4517
4522
|
}
|
|
4518
4523
|
}
|
|
@@ -4537,18 +4542,18 @@ const _ChapterManagerPlugin = class _ChapterManagerPlugin2 extends BasePlugin {
|
|
|
4537
4542
|
const orderedIds = this.manifest.chapters.map((c) => c.chapterId);
|
|
4538
4543
|
const neededIdx = /* @__PURE__ */ new Set();
|
|
4539
4544
|
for (const cid of visibleChapters) {
|
|
4540
|
-
const
|
|
4541
|
-
if (
|
|
4542
|
-
for (let k2 =
|
|
4545
|
+
const i2 = orderedIds.indexOf(cid);
|
|
4546
|
+
if (i2 === -1) continue;
|
|
4547
|
+
for (let k2 = i2 - prefetch; k2 <= i2 + prefetch; k2++) {
|
|
4543
4548
|
if (k2 >= 0 && k2 < orderedIds.length) neededIdx.add(k2);
|
|
4544
4549
|
}
|
|
4545
4550
|
}
|
|
4546
4551
|
const needed = /* @__PURE__ */ new Set();
|
|
4547
|
-
for (const
|
|
4552
|
+
for (const i2 of neededIdx) needed.add(orderedIds[i2]);
|
|
4548
4553
|
for (const cid of needed) {
|
|
4549
4554
|
this.chapterLastUsed.set(cid, now);
|
|
4550
|
-
const
|
|
4551
|
-
if (
|
|
4555
|
+
const st2 = this.chapterStatus.get(cid) ?? "idle";
|
|
4556
|
+
if (st2 === "idle" || st2 === "closed" || st2 === "error") {
|
|
4552
4557
|
void this.ensureChapterLoaded(cid);
|
|
4553
4558
|
}
|
|
4554
4559
|
}
|
|
@@ -4566,8 +4571,8 @@ const _ChapterManagerPlugin = class _ChapterManagerPlugin2 extends BasePlugin {
|
|
|
4566
4571
|
const timeout = this.config.unloadTimeoutMs ?? 6e4;
|
|
4567
4572
|
if (timeout <= 0) return;
|
|
4568
4573
|
const now = Date.now();
|
|
4569
|
-
for (const [cid,
|
|
4570
|
-
if (
|
|
4574
|
+
for (const [cid, st2] of this.chapterStatus) {
|
|
4575
|
+
if (st2 !== "loaded") continue;
|
|
4571
4576
|
const last = this.chapterLastUsed.get(cid) ?? 0;
|
|
4572
4577
|
if (now - last > timeout) {
|
|
4573
4578
|
this.closeChapter(cid);
|
|
@@ -4656,9 +4661,9 @@ const _ChapterManagerPlugin = class _ChapterManagerPlugin2 extends BasePlugin {
|
|
|
4656
4661
|
/** 阻塞等待该章节状态进入 loaded / error / password-required / closed */
|
|
4657
4662
|
waitForTerminalStatus(chapterId) {
|
|
4658
4663
|
return new Promise((resolve) => {
|
|
4659
|
-
const check = (
|
|
4660
|
-
if (
|
|
4661
|
-
resolve(
|
|
4664
|
+
const check = (st2) => {
|
|
4665
|
+
if (st2 === "loaded" || st2 === "error" || st2 === "password-required" || st2 === "closed") {
|
|
4666
|
+
resolve(st2);
|
|
4662
4667
|
return true;
|
|
4663
4668
|
}
|
|
4664
4669
|
return false;
|
|
@@ -4804,12 +4809,12 @@ function T(t2, e14 = k) {
|
|
|
4804
4809
|
})(t2, e14), s9 = /* @__PURE__ */ new Map();
|
|
4805
4810
|
for (const n2 of t2.chapters) s9.set(n2.chapterId, n2);
|
|
4806
4811
|
const o = Array.from(a3.keys()).sort((t3, e15) => t3 - e15), r2 = [];
|
|
4807
|
-
let
|
|
4812
|
+
let i2 = 0;
|
|
4808
4813
|
for (const n2 of o) {
|
|
4809
4814
|
const t3 = a3.get(n2), e15 = s9.get(t3);
|
|
4810
4815
|
if (!e15) continue;
|
|
4811
|
-
const [o2] = e15.globalPageRange, [h2] = e15.localPageRange,
|
|
4812
|
-
r2.push({ globalPageIndex:
|
|
4816
|
+
const [o2] = e15.globalPageRange, [h2] = e15.localPageRange, d2 = h2 + (n2 - o2);
|
|
4817
|
+
r2.push({ globalPageIndex: i2++, globalPageNumber: n2, chapterId: t3, localPageIndex: d2 });
|
|
4813
4818
|
}
|
|
4814
4819
|
return new $(r2);
|
|
4815
4820
|
}
|
|
@@ -4844,8 +4849,8 @@ const D = class s2 extends BasePlugin {
|
|
|
4844
4849
|
const e15 = [], a4 = /* @__PURE__ */ new Set();
|
|
4845
4850
|
for (const s9 of t3.chapters) {
|
|
4846
4851
|
a4.has(s9.chapterId) && e15.push(`Duplicate chapterId: ${s9.chapterId}`), a4.add(s9.chapterId);
|
|
4847
|
-
const [t4, o2] = s9.globalPageRange, [r2,
|
|
4848
|
-
if (t4 > o2 && e15.push(`${s9.chapterId}: invalid globalPageRange [${t4},${o2}]`), r2 >
|
|
4852
|
+
const [t4, o2] = s9.globalPageRange, [r2, i2] = s9.localPageRange;
|
|
4853
|
+
if (t4 > o2 && e15.push(`${s9.chapterId}: invalid globalPageRange [${t4},${o2}]`), r2 > i2 && e15.push(`${s9.chapterId}: invalid localPageRange [${r2},${i2}]`), o2 - t4 !== i2 - r2 && e15.push(`${s9.chapterId}: page-count mismatch (global ${o2 - t4 + 1} vs local ${i2 - r2 + 1})`), s9.ownedGlobalPages) for (const a5 of s9.ownedGlobalPages) (a5 < t4 || a5 > o2) && e15.push(`${s9.chapterId}: ownedGlobalPages contains ${a5} outside range`);
|
|
4849
4854
|
}
|
|
4850
4855
|
return e15;
|
|
4851
4856
|
})(t2);
|
|
@@ -4885,9 +4890,9 @@ const D = class s2 extends BasePlugin {
|
|
|
4885
4890
|
const t3 = o.indexOf(n2);
|
|
4886
4891
|
if (-1 !== t3) for (let e15 = t3 - a3; e15 <= t3 + a3; e15++) e15 >= 0 && e15 < o.length && r2.add(e15);
|
|
4887
4892
|
}
|
|
4888
|
-
const
|
|
4889
|
-
for (const n2 of r2)
|
|
4890
|
-
for (const n2 of
|
|
4893
|
+
const i2 = /* @__PURE__ */ new Set();
|
|
4894
|
+
for (const n2 of r2) i2.add(o[n2]);
|
|
4895
|
+
for (const n2 of i2) {
|
|
4891
4896
|
this.chapterLastUsed.set(n2, e14);
|
|
4892
4897
|
const t3 = this.chapterStatus.get(n2) ?? "idle";
|
|
4893
4898
|
"idle" !== t3 && "closed" !== t3 && "error" !== t3 || this.ensureChapterLoaded(n2);
|
|
@@ -4937,8 +4942,8 @@ const D = class s2 extends BasePlugin {
|
|
|
4937
4942
|
const a3 = t2.chapterId;
|
|
4938
4943
|
this.updateStatus(a3, "loading"), this.chapterLastUsed.set(a3, Date.now());
|
|
4939
4944
|
try {
|
|
4940
|
-
const s9 = t2.encrypted && (null == (e14 = this.passwordProvider) ? void 0 : e14.getCachedPassword) ? this.passwordProvider.getCachedPassword(a3) : null, o = await this.resolvePdfPayload(t2), r2 = this.documentManager.provides(),
|
|
4941
|
-
|
|
4945
|
+
const s9 = t2.encrypted && (null == (e14 = this.passwordProvider) ? void 0 : e14.getCachedPassword) ? this.passwordProvider.getCachedPassword(a3) : null, o = await this.resolvePdfPayload(t2), r2 = this.documentManager.provides(), i2 = "url" in o ? r2.openDocumentUrl({ documentId: a3, url: o.url, name: t2.title, password: s9 ?? void 0, autoActivate: false }) : r2.openDocumentBuffer({ documentId: a3, buffer: o.buffer, name: t2.title, password: s9 ?? void 0, autoActivate: false }), n2 = await new Promise((t3, e15) => {
|
|
4946
|
+
i2.wait((e16) => t3(e16), (t4) => e15(t4));
|
|
4942
4947
|
});
|
|
4943
4948
|
return await new Promise((t3, e15) => {
|
|
4944
4949
|
n2.task.wait(() => t3(), (t4) => e15(t4));
|
|
@@ -4969,15 +4974,15 @@ const D = class s2 extends BasePlugin {
|
|
|
4969
4974
|
if (!o) return;
|
|
4970
4975
|
const r2 = (this.passwordAttempts.get(t2) ?? 0) + 1;
|
|
4971
4976
|
this.passwordAttempts.set(t2, r2);
|
|
4972
|
-
let
|
|
4977
|
+
let i2 = null;
|
|
4973
4978
|
try {
|
|
4974
|
-
|
|
4979
|
+
i2 = await this.passwordProvider.resolvePassword(o, r2 - 1);
|
|
4975
4980
|
} catch (n2) {
|
|
4976
4981
|
this.logger.error(s2.id, "PasswordProvider", `Provider rejected for ${t2}`, n2);
|
|
4977
4982
|
}
|
|
4978
|
-
if (!
|
|
4983
|
+
if (!i2) return void this.updateStatus(t2, "password-required");
|
|
4979
4984
|
this.updateStatus(t2, "loading");
|
|
4980
|
-
this.documentManager.provides().retryDocument(t2, { password:
|
|
4985
|
+
this.documentManager.provides().retryDocument(t2, { password: i2 }).wait(() => {
|
|
4981
4986
|
}, () => {
|
|
4982
4987
|
});
|
|
4983
4988
|
}
|
|
@@ -5062,12 +5067,12 @@ function E(t2, e14 = N) {
|
|
|
5062
5067
|
})(t2, e14), s9 = /* @__PURE__ */ new Map();
|
|
5063
5068
|
for (const n2 of t2.chapters) s9.set(n2.chapterId, n2);
|
|
5064
5069
|
const o = Array.from(a3.keys()).sort((t3, e15) => t3 - e15), r2 = [];
|
|
5065
|
-
let
|
|
5070
|
+
let i2 = 0;
|
|
5066
5071
|
for (const n2 of o) {
|
|
5067
5072
|
const t3 = a3.get(n2), e15 = s9.get(t3);
|
|
5068
5073
|
if (!e15) continue;
|
|
5069
|
-
const [o2] = e15.globalPageRange, [h2] = e15.localPageRange,
|
|
5070
|
-
r2.push({ globalPageIndex:
|
|
5074
|
+
const [o2] = e15.globalPageRange, [h2] = e15.localPageRange, d2 = h2 + (n2 - o2);
|
|
5075
|
+
r2.push({ globalPageIndex: i2++, globalPageNumber: n2, chapterId: t3, localPageIndex: d2 });
|
|
5071
5076
|
}
|
|
5072
5077
|
return new F(r2);
|
|
5073
5078
|
}
|
|
@@ -5102,8 +5107,8 @@ const U = class s3 extends BasePlugin {
|
|
|
5102
5107
|
const e15 = [], a4 = /* @__PURE__ */ new Set();
|
|
5103
5108
|
for (const s9 of t3.chapters) {
|
|
5104
5109
|
a4.has(s9.chapterId) && e15.push(`Duplicate chapterId: ${s9.chapterId}`), a4.add(s9.chapterId);
|
|
5105
|
-
const [t4, o2] = s9.globalPageRange, [r2,
|
|
5106
|
-
if (t4 > o2 && e15.push(`${s9.chapterId}: invalid globalPageRange [${t4},${o2}]`), r2 >
|
|
5110
|
+
const [t4, o2] = s9.globalPageRange, [r2, i2] = s9.localPageRange;
|
|
5111
|
+
if (t4 > o2 && e15.push(`${s9.chapterId}: invalid globalPageRange [${t4},${o2}]`), r2 > i2 && e15.push(`${s9.chapterId}: invalid localPageRange [${r2},${i2}]`), o2 - t4 !== i2 - r2 && e15.push(`${s9.chapterId}: page-count mismatch (global ${o2 - t4 + 1} vs local ${i2 - r2 + 1})`), s9.ownedGlobalPages) for (const a5 of s9.ownedGlobalPages) (a5 < t4 || a5 > o2) && e15.push(`${s9.chapterId}: ownedGlobalPages contains ${a5} outside range`);
|
|
5107
5112
|
}
|
|
5108
5113
|
return e15;
|
|
5109
5114
|
})(t2);
|
|
@@ -5143,9 +5148,9 @@ const U = class s3 extends BasePlugin {
|
|
|
5143
5148
|
const t3 = o.indexOf(n2);
|
|
5144
5149
|
if (-1 !== t3) for (let e15 = t3 - a3; e15 <= t3 + a3; e15++) e15 >= 0 && e15 < o.length && r2.add(e15);
|
|
5145
5150
|
}
|
|
5146
|
-
const
|
|
5147
|
-
for (const n2 of r2)
|
|
5148
|
-
for (const n2 of
|
|
5151
|
+
const i2 = /* @__PURE__ */ new Set();
|
|
5152
|
+
for (const n2 of r2) i2.add(o[n2]);
|
|
5153
|
+
for (const n2 of i2) {
|
|
5149
5154
|
this.chapterLastUsed.set(n2, e14);
|
|
5150
5155
|
const t3 = this.chapterStatus.get(n2) ?? "idle";
|
|
5151
5156
|
"idle" !== t3 && "closed" !== t3 && "error" !== t3 || this.ensureChapterLoaded(n2);
|
|
@@ -5195,8 +5200,8 @@ const U = class s3 extends BasePlugin {
|
|
|
5195
5200
|
const a3 = t2.chapterId;
|
|
5196
5201
|
this.updateStatus(a3, "loading"), this.chapterLastUsed.set(a3, Date.now());
|
|
5197
5202
|
try {
|
|
5198
|
-
const s9 = t2.encrypted && (null == (e14 = this.passwordProvider) ? void 0 : e14.getCachedPassword) ? this.passwordProvider.getCachedPassword(a3) : null, o = await this.resolvePdfPayload(t2), r2 = this.documentManager.provides(),
|
|
5199
|
-
|
|
5203
|
+
const s9 = t2.encrypted && (null == (e14 = this.passwordProvider) ? void 0 : e14.getCachedPassword) ? this.passwordProvider.getCachedPassword(a3) : null, o = await this.resolvePdfPayload(t2), r2 = this.documentManager.provides(), i2 = "url" in o ? r2.openDocumentUrl({ documentId: a3, url: o.url, name: t2.title, password: s9 ?? void 0, autoActivate: false }) : r2.openDocumentBuffer({ documentId: a3, buffer: o.buffer, name: t2.title, password: s9 ?? void 0, autoActivate: false }), n2 = await new Promise((t3, e15) => {
|
|
5204
|
+
i2.wait((e16) => t3(e16), (t4) => e15(t4));
|
|
5200
5205
|
});
|
|
5201
5206
|
return await new Promise((t3, e15) => {
|
|
5202
5207
|
n2.task.wait(() => t3(), (t4) => e15(t4));
|
|
@@ -5227,15 +5232,15 @@ const U = class s3 extends BasePlugin {
|
|
|
5227
5232
|
if (!o) return;
|
|
5228
5233
|
const r2 = (this.passwordAttempts.get(t2) ?? 0) + 1;
|
|
5229
5234
|
this.passwordAttempts.set(t2, r2);
|
|
5230
|
-
let
|
|
5235
|
+
let i2 = null;
|
|
5231
5236
|
try {
|
|
5232
|
-
|
|
5237
|
+
i2 = await this.passwordProvider.resolvePassword(o, r2 - 1);
|
|
5233
5238
|
} catch (n2) {
|
|
5234
5239
|
this.logger.error(s3.id, "PasswordProvider", `Provider rejected for ${t2}`, n2);
|
|
5235
5240
|
}
|
|
5236
|
-
if (!
|
|
5241
|
+
if (!i2) return void this.updateStatus(t2, "password-required");
|
|
5237
5242
|
this.updateStatus(t2, "loading");
|
|
5238
|
-
this.documentManager.provides().retryDocument(t2, { password:
|
|
5243
|
+
this.documentManager.provides().retryDocument(t2, { password: i2 }).wait(() => {
|
|
5239
5244
|
}, () => {
|
|
5240
5245
|
});
|
|
5241
5246
|
}
|
|
@@ -5348,12 +5353,12 @@ const q = class extends BasePlugin {
|
|
|
5348
5353
|
if (!this.virtualPageMap) return;
|
|
5349
5354
|
const s9 = this.documentManager.provides().getDocument(t2), o = this.virtualPageMap.pagesOfChapter(t2);
|
|
5350
5355
|
if (!(null == (a3 = null == s9 ? void 0 : s9.pages) ? void 0 : a3.length) || 0 === o.length) return void (e14 < 60 && requestAnimationFrame(() => this.harvestChapterSizes(t2, e14 + 1)));
|
|
5351
|
-
const r2 = this.getChapterDocumentScale(t2),
|
|
5356
|
+
const r2 = this.getChapterDocumentScale(t2), i2 = [];
|
|
5352
5357
|
for (const n2 of o) {
|
|
5353
5358
|
const t3 = s9.pages[n2.localPageIndex];
|
|
5354
|
-
(null == t3 ? void 0 : t3.size) &&
|
|
5359
|
+
(null == t3 ? void 0 : t3.size) && i2.push({ localPageIndex: n2.localPageIndex, width: t3.size.width * r2, height: t3.size.height * r2 });
|
|
5355
5360
|
}
|
|
5356
|
-
0 !==
|
|
5361
|
+
0 !== i2.length ? this.applyChapterPageSizes(t2, i2) : e14 < 60 && requestAnimationFrame(() => this.harvestChapterSizes(t2, e14 + 1));
|
|
5357
5362
|
}
|
|
5358
5363
|
onScaleChanged(t2) {
|
|
5359
5364
|
const e14 = this.coreState.core.documents[t2];
|
|
@@ -5387,13 +5392,13 @@ const q = class extends BasePlugin {
|
|
|
5387
5392
|
o++;
|
|
5388
5393
|
}
|
|
5389
5394
|
const r2 = [];
|
|
5390
|
-
let
|
|
5395
|
+
let i2 = s9, n2 = -1;
|
|
5391
5396
|
for (let h2 = s9; h2 < o; h2++) {
|
|
5392
5397
|
r2.push(h2);
|
|
5393
5398
|
const t3 = this.offsets[h2], s10 = t3 + this.getPageSize(h2).height, o2 = Math.max(0, Math.min(s10, a3) - Math.max(t3, e14));
|
|
5394
|
-
o2 > n2 && (n2 = o2,
|
|
5399
|
+
o2 > n2 && (n2 = o2, i2 = h2);
|
|
5395
5400
|
}
|
|
5396
|
-
this.currentVisible = r2, this.currentGlobalPageIndex =
|
|
5401
|
+
this.currentVisible = r2, this.currentGlobalPageIndex = i2, this.visibleChange$.emit({ visibleGlobalPageIndices: r2, currentGlobalPageIndex: i2 }), this.chapterManager.provides().setVisibleGlobalPages(r2), this.layoutChange$.emit(this.computeLayout());
|
|
5397
5402
|
}
|
|
5398
5403
|
findFirstVisibleIndex(t2) {
|
|
5399
5404
|
let e14 = 0, a3 = this.offsets.length - 1, s9 = 0;
|
|
@@ -5423,10 +5428,10 @@ const q = class extends BasePlugin {
|
|
|
5423
5428
|
if (!this.viewportEl || t2 < 0 || t2 >= this.offsets.length || !this.virtualPageMap) return;
|
|
5424
5429
|
const o = (null == a3 ? void 0 : a3.marginTop) ?? 80, r2 = this.virtualPageMap.atIndex(t2);
|
|
5425
5430
|
if (!r2) return void this.scrollToIndex(t2, a3);
|
|
5426
|
-
const
|
|
5427
|
-
if (!
|
|
5428
|
-
const h2 =
|
|
5429
|
-
this.viewportEl.scrollTo({ top: Math.max(0,
|
|
5431
|
+
const i2 = this.pageSizes.get(t2), n2 = null == (s9 = this.documentManager.provides().getDocument(r2.chapterId)) ? void 0 : s9.pages[r2.localPageIndex];
|
|
5432
|
+
if (!i2 || !n2) return void this.scrollToIndex(t2, a3);
|
|
5433
|
+
const h2 = i2.height / n2.size.height, d2 = (this.offsets[t2] ?? 0) + e14 * h2 - o;
|
|
5434
|
+
this.viewportEl.scrollTo({ top: Math.max(0, d2), behavior: (null == a3 ? void 0 : a3.behavior) ?? "auto" });
|
|
5430
5435
|
}
|
|
5431
5436
|
scrollToChapter(t2, e14) {
|
|
5432
5437
|
if (!this.virtualPageMap) return;
|
|
@@ -5509,12 +5514,12 @@ function Y(t2, e14 = J) {
|
|
|
5509
5514
|
})(t2, e14), s9 = /* @__PURE__ */ new Map();
|
|
5510
5515
|
for (const n2 of t2.chapters) s9.set(n2.chapterId, n2);
|
|
5511
5516
|
const o = Array.from(a3.keys()).sort((t3, e15) => t3 - e15), r2 = [];
|
|
5512
|
-
let
|
|
5517
|
+
let i2 = 0;
|
|
5513
5518
|
for (const n2 of o) {
|
|
5514
5519
|
const t3 = a3.get(n2), e15 = s9.get(t3);
|
|
5515
5520
|
if (!e15) continue;
|
|
5516
|
-
const [o2] = e15.globalPageRange, [h2] = e15.localPageRange,
|
|
5517
|
-
r2.push({ globalPageIndex:
|
|
5521
|
+
const [o2] = e15.globalPageRange, [h2] = e15.localPageRange, d2 = h2 + (n2 - o2);
|
|
5522
|
+
r2.push({ globalPageIndex: i2++, globalPageNumber: n2, chapterId: t3, localPageIndex: d2 });
|
|
5518
5523
|
}
|
|
5519
5524
|
return new Q(r2);
|
|
5520
5525
|
}
|
|
@@ -5549,8 +5554,8 @@ const X = class s4 extends BasePlugin {
|
|
|
5549
5554
|
const e15 = [], a4 = /* @__PURE__ */ new Set();
|
|
5550
5555
|
for (const s9 of t3.chapters) {
|
|
5551
5556
|
a4.has(s9.chapterId) && e15.push(`Duplicate chapterId: ${s9.chapterId}`), a4.add(s9.chapterId);
|
|
5552
|
-
const [t4, o2] = s9.globalPageRange, [r2,
|
|
5553
|
-
if (t4 > o2 && e15.push(`${s9.chapterId}: invalid globalPageRange [${t4},${o2}]`), r2 >
|
|
5557
|
+
const [t4, o2] = s9.globalPageRange, [r2, i2] = s9.localPageRange;
|
|
5558
|
+
if (t4 > o2 && e15.push(`${s9.chapterId}: invalid globalPageRange [${t4},${o2}]`), r2 > i2 && e15.push(`${s9.chapterId}: invalid localPageRange [${r2},${i2}]`), o2 - t4 !== i2 - r2 && e15.push(`${s9.chapterId}: page-count mismatch (global ${o2 - t4 + 1} vs local ${i2 - r2 + 1})`), s9.ownedGlobalPages) for (const a5 of s9.ownedGlobalPages) (a5 < t4 || a5 > o2) && e15.push(`${s9.chapterId}: ownedGlobalPages contains ${a5} outside range`);
|
|
5554
5559
|
}
|
|
5555
5560
|
return e15;
|
|
5556
5561
|
})(t2);
|
|
@@ -5590,9 +5595,9 @@ const X = class s4 extends BasePlugin {
|
|
|
5590
5595
|
const t3 = o.indexOf(n2);
|
|
5591
5596
|
if (-1 !== t3) for (let e15 = t3 - a3; e15 <= t3 + a3; e15++) e15 >= 0 && e15 < o.length && r2.add(e15);
|
|
5592
5597
|
}
|
|
5593
|
-
const
|
|
5594
|
-
for (const n2 of r2)
|
|
5595
|
-
for (const n2 of
|
|
5598
|
+
const i2 = /* @__PURE__ */ new Set();
|
|
5599
|
+
for (const n2 of r2) i2.add(o[n2]);
|
|
5600
|
+
for (const n2 of i2) {
|
|
5596
5601
|
this.chapterLastUsed.set(n2, e14);
|
|
5597
5602
|
const t3 = this.chapterStatus.get(n2) ?? "idle";
|
|
5598
5603
|
"idle" !== t3 && "closed" !== t3 && "error" !== t3 || this.ensureChapterLoaded(n2);
|
|
@@ -5642,8 +5647,8 @@ const X = class s4 extends BasePlugin {
|
|
|
5642
5647
|
const a3 = t2.chapterId;
|
|
5643
5648
|
this.updateStatus(a3, "loading"), this.chapterLastUsed.set(a3, Date.now());
|
|
5644
5649
|
try {
|
|
5645
|
-
const s9 = t2.encrypted && (null == (e14 = this.passwordProvider) ? void 0 : e14.getCachedPassword) ? this.passwordProvider.getCachedPassword(a3) : null, o = await this.resolvePdfPayload(t2), r2 = this.documentManager.provides(),
|
|
5646
|
-
|
|
5650
|
+
const s9 = t2.encrypted && (null == (e14 = this.passwordProvider) ? void 0 : e14.getCachedPassword) ? this.passwordProvider.getCachedPassword(a3) : null, o = await this.resolvePdfPayload(t2), r2 = this.documentManager.provides(), i2 = "url" in o ? r2.openDocumentUrl({ documentId: a3, url: o.url, name: t2.title, password: s9 ?? void 0, autoActivate: false }) : r2.openDocumentBuffer({ documentId: a3, buffer: o.buffer, name: t2.title, password: s9 ?? void 0, autoActivate: false }), n2 = await new Promise((t3, e15) => {
|
|
5651
|
+
i2.wait((e16) => t3(e16), (t4) => e15(t4));
|
|
5647
5652
|
});
|
|
5648
5653
|
return await new Promise((t3, e15) => {
|
|
5649
5654
|
n2.task.wait(() => t3(), (t4) => e15(t4));
|
|
@@ -5674,15 +5679,15 @@ const X = class s4 extends BasePlugin {
|
|
|
5674
5679
|
if (!o) return;
|
|
5675
5680
|
const r2 = (this.passwordAttempts.get(t2) ?? 0) + 1;
|
|
5676
5681
|
this.passwordAttempts.set(t2, r2);
|
|
5677
|
-
let
|
|
5682
|
+
let i2 = null;
|
|
5678
5683
|
try {
|
|
5679
|
-
|
|
5684
|
+
i2 = await this.passwordProvider.resolvePassword(o, r2 - 1);
|
|
5680
5685
|
} catch (n2) {
|
|
5681
5686
|
this.logger.error(s4.id, "PasswordProvider", `Provider rejected for ${t2}`, n2);
|
|
5682
5687
|
}
|
|
5683
|
-
if (!
|
|
5688
|
+
if (!i2) return void this.updateStatus(t2, "password-required");
|
|
5684
5689
|
this.updateStatus(t2, "loading");
|
|
5685
|
-
this.documentManager.provides().retryDocument(t2, { password:
|
|
5690
|
+
this.documentManager.provides().retryDocument(t2, { password: i2 }).wait(() => {
|
|
5686
5691
|
}, () => {
|
|
5687
5692
|
});
|
|
5688
5693
|
}
|
|
@@ -5751,7 +5756,7 @@ let at = class {
|
|
|
5751
5756
|
return a3 ? this._pages.indexOf(a3) : -1;
|
|
5752
5757
|
}
|
|
5753
5758
|
};
|
|
5754
|
-
function
|
|
5759
|
+
function st(t2, e14 = tt) {
|
|
5755
5760
|
const a3 = (function(t3, e15 = tt) {
|
|
5756
5761
|
const a4 = /* @__PURE__ */ new Map();
|
|
5757
5762
|
for (const o2 of t3.chapters) {
|
|
@@ -5767,16 +5772,16 @@ function st2(t2, e14 = tt) {
|
|
|
5767
5772
|
})(t2, e14), s9 = /* @__PURE__ */ new Map();
|
|
5768
5773
|
for (const n2 of t2.chapters) s9.set(n2.chapterId, n2);
|
|
5769
5774
|
const o = Array.from(a3.keys()).sort((t3, e15) => t3 - e15), r2 = [];
|
|
5770
|
-
let
|
|
5775
|
+
let i2 = 0;
|
|
5771
5776
|
for (const n2 of o) {
|
|
5772
5777
|
const t3 = a3.get(n2), e15 = s9.get(t3);
|
|
5773
5778
|
if (!e15) continue;
|
|
5774
|
-
const [o2] = e15.globalPageRange, [h2] = e15.localPageRange,
|
|
5775
|
-
r2.push({ globalPageIndex:
|
|
5779
|
+
const [o2] = e15.globalPageRange, [h2] = e15.localPageRange, d2 = h2 + (n2 - o2);
|
|
5780
|
+
r2.push({ globalPageIndex: i2++, globalPageNumber: n2, chapterId: t3, localPageIndex: d2 });
|
|
5776
5781
|
}
|
|
5777
5782
|
return new at(r2);
|
|
5778
5783
|
}
|
|
5779
|
-
const
|
|
5784
|
+
const ot2 = class s5 extends BasePlugin {
|
|
5780
5785
|
constructor(t2, s9) {
|
|
5781
5786
|
super(t2, s9), this.statusChange$ = createBehaviorEmitter(), this.manifestChange$ = createEmitter(), this.overlapStrategy = tt, this.chapterStatus = /* @__PURE__ */ new Map(), this.chapterLastUsed = /* @__PURE__ */ new Map(), this.passwordAttempts = /* @__PURE__ */ new Map(), this.pendingLoadPromises = /* @__PURE__ */ new Map(), this.unloadTimer = null, this.documentManagerUnsubs = [], this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
|
|
5782
5787
|
}
|
|
@@ -5807,8 +5812,8 @@ const ot = class s5 extends BasePlugin {
|
|
|
5807
5812
|
const e15 = [], a4 = /* @__PURE__ */ new Set();
|
|
5808
5813
|
for (const s9 of t3.chapters) {
|
|
5809
5814
|
a4.has(s9.chapterId) && e15.push(`Duplicate chapterId: ${s9.chapterId}`), a4.add(s9.chapterId);
|
|
5810
|
-
const [t4, o2] = s9.globalPageRange, [r2,
|
|
5811
|
-
if (t4 > o2 && e15.push(`${s9.chapterId}: invalid globalPageRange [${t4},${o2}]`), r2 >
|
|
5815
|
+
const [t4, o2] = s9.globalPageRange, [r2, i2] = s9.localPageRange;
|
|
5816
|
+
if (t4 > o2 && e15.push(`${s9.chapterId}: invalid globalPageRange [${t4},${o2}]`), r2 > i2 && e15.push(`${s9.chapterId}: invalid localPageRange [${r2},${i2}]`), o2 - t4 !== i2 - r2 && e15.push(`${s9.chapterId}: page-count mismatch (global ${o2 - t4 + 1} vs local ${i2 - r2 + 1})`), s9.ownedGlobalPages) for (const a5 of s9.ownedGlobalPages) (a5 < t4 || a5 > o2) && e15.push(`${s9.chapterId}: ownedGlobalPages contains ${a5} outside range`);
|
|
5812
5817
|
}
|
|
5813
5818
|
return e15;
|
|
5814
5819
|
})(t2);
|
|
@@ -5816,7 +5821,7 @@ const ot = class s5 extends BasePlugin {
|
|
|
5816
5821
|
const a3 = new Set(this.chapterStatus.keys()), o = new Set(t2.chapters.map((t3) => t3.chapterId));
|
|
5817
5822
|
for (const s9 of a3) o.has(s9) || (this.closeChapter(s9), this.chapterStatus.delete(s9));
|
|
5818
5823
|
for (const s9 of t2.chapters) this.chapterStatus.has(s9.chapterId) || this.chapterStatus.set(s9.chapterId, "idle");
|
|
5819
|
-
this.manifest = t2, this.virtualPageMap =
|
|
5824
|
+
this.manifest = t2, this.virtualPageMap = st(t2, this.overlapStrategy), this.manifestChange$.emit({ manifest: t2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
|
|
5820
5825
|
}
|
|
5821
5826
|
eagerPrefetchFromManifest() {
|
|
5822
5827
|
const t2 = this.config.prefetchChapters ?? 0;
|
|
@@ -5848,9 +5853,9 @@ const ot = class s5 extends BasePlugin {
|
|
|
5848
5853
|
const t3 = o.indexOf(n2);
|
|
5849
5854
|
if (-1 !== t3) for (let e15 = t3 - a3; e15 <= t3 + a3; e15++) e15 >= 0 && e15 < o.length && r2.add(e15);
|
|
5850
5855
|
}
|
|
5851
|
-
const
|
|
5852
|
-
for (const n2 of r2)
|
|
5853
|
-
for (const n2 of
|
|
5856
|
+
const i2 = /* @__PURE__ */ new Set();
|
|
5857
|
+
for (const n2 of r2) i2.add(o[n2]);
|
|
5858
|
+
for (const n2 of i2) {
|
|
5854
5859
|
this.chapterLastUsed.set(n2, e14);
|
|
5855
5860
|
const t3 = this.chapterStatus.get(n2) ?? "idle";
|
|
5856
5861
|
"idle" !== t3 && "closed" !== t3 && "error" !== t3 || this.ensureChapterLoaded(n2);
|
|
@@ -5900,8 +5905,8 @@ const ot = class s5 extends BasePlugin {
|
|
|
5900
5905
|
const a3 = t2.chapterId;
|
|
5901
5906
|
this.updateStatus(a3, "loading"), this.chapterLastUsed.set(a3, Date.now());
|
|
5902
5907
|
try {
|
|
5903
|
-
const s9 = t2.encrypted && (null == (e14 = this.passwordProvider) ? void 0 : e14.getCachedPassword) ? this.passwordProvider.getCachedPassword(a3) : null, o = await this.resolvePdfPayload(t2), r2 = this.documentManager.provides(),
|
|
5904
|
-
|
|
5908
|
+
const s9 = t2.encrypted && (null == (e14 = this.passwordProvider) ? void 0 : e14.getCachedPassword) ? this.passwordProvider.getCachedPassword(a3) : null, o = await this.resolvePdfPayload(t2), r2 = this.documentManager.provides(), i2 = "url" in o ? r2.openDocumentUrl({ documentId: a3, url: o.url, name: t2.title, password: s9 ?? void 0, autoActivate: false }) : r2.openDocumentBuffer({ documentId: a3, buffer: o.buffer, name: t2.title, password: s9 ?? void 0, autoActivate: false }), n2 = await new Promise((t3, e15) => {
|
|
5909
|
+
i2.wait((e16) => t3(e16), (t4) => e15(t4));
|
|
5905
5910
|
});
|
|
5906
5911
|
return await new Promise((t3, e15) => {
|
|
5907
5912
|
n2.task.wait(() => t3(), (t4) => e15(t4));
|
|
@@ -5932,15 +5937,15 @@ const ot = class s5 extends BasePlugin {
|
|
|
5932
5937
|
if (!o) return;
|
|
5933
5938
|
const r2 = (this.passwordAttempts.get(t2) ?? 0) + 1;
|
|
5934
5939
|
this.passwordAttempts.set(t2, r2);
|
|
5935
|
-
let
|
|
5940
|
+
let i2 = null;
|
|
5936
5941
|
try {
|
|
5937
|
-
|
|
5942
|
+
i2 = await this.passwordProvider.resolvePassword(o, r2 - 1);
|
|
5938
5943
|
} catch (n2) {
|
|
5939
5944
|
this.logger.error(s5.id, "PasswordProvider", `Provider rejected for ${t2}`, n2);
|
|
5940
5945
|
}
|
|
5941
|
-
if (!
|
|
5946
|
+
if (!i2) return void this.updateStatus(t2, "password-required");
|
|
5942
5947
|
this.updateStatus(t2, "loading");
|
|
5943
|
-
this.documentManager.provides().retryDocument(t2, { password:
|
|
5948
|
+
this.documentManager.provides().retryDocument(t2, { password: i2 }).wait(() => {
|
|
5944
5949
|
}, () => {
|
|
5945
5950
|
});
|
|
5946
5951
|
}
|
|
@@ -5954,8 +5959,8 @@ const ot = class s5 extends BasePlugin {
|
|
|
5954
5959
|
this.chapterStatus.get(t2) !== e14 && (this.chapterStatus.set(t2, e14), this.statusChange$.emit({ chapterId: t2, status: e14, ..."error" === e14 && a3 ? { error: { message: a3 } } : {} }));
|
|
5955
5960
|
}
|
|
5956
5961
|
};
|
|
5957
|
-
|
|
5958
|
-
let rt =
|
|
5962
|
+
ot2.id = "chapter-manager";
|
|
5963
|
+
let rt = ot2;
|
|
5959
5964
|
function it(t2, e14) {
|
|
5960
5965
|
if (t2 === e14) return true;
|
|
5961
5966
|
if (t2.totalHeight !== e14.totalHeight || t2.totalWidth !== e14.totalWidth || t2.pageGap !== e14.pageGap || t2.items.length !== e14.items.length) return false;
|
|
@@ -6053,12 +6058,12 @@ const nt = class extends BasePlugin {
|
|
|
6053
6058
|
if (!this.virtualPageMap) return;
|
|
6054
6059
|
const s9 = this.documentManager.provides().getDocument(t2), o = this.virtualPageMap.pagesOfChapter(t2);
|
|
6055
6060
|
if (!(null == (a3 = null == s9 ? void 0 : s9.pages) ? void 0 : a3.length) || 0 === o.length) return void (e14 < 60 && requestAnimationFrame(() => this.harvestChapterSizes(t2, e14 + 1)));
|
|
6056
|
-
const r2 = this.getChapterDocumentScale(t2),
|
|
6061
|
+
const r2 = this.getChapterDocumentScale(t2), i2 = [];
|
|
6057
6062
|
for (const n2 of o) {
|
|
6058
6063
|
const t3 = s9.pages[n2.localPageIndex];
|
|
6059
|
-
(null == t3 ? void 0 : t3.size) &&
|
|
6064
|
+
(null == t3 ? void 0 : t3.size) && i2.push({ localPageIndex: n2.localPageIndex, width: t3.size.width * r2, height: t3.size.height * r2 });
|
|
6060
6065
|
}
|
|
6061
|
-
0 !==
|
|
6066
|
+
0 !== i2.length ? this.applyChapterPageSizes(t2, i2) : e14 < 60 && requestAnimationFrame(() => this.harvestChapterSizes(t2, e14 + 1));
|
|
6062
6067
|
}
|
|
6063
6068
|
onScaleChanged(t2) {
|
|
6064
6069
|
const e14 = this.coreState.core.documents[t2];
|
|
@@ -6092,13 +6097,13 @@ const nt = class extends BasePlugin {
|
|
|
6092
6097
|
o++;
|
|
6093
6098
|
}
|
|
6094
6099
|
const r2 = [];
|
|
6095
|
-
let
|
|
6100
|
+
let i2 = s9, n2 = -1;
|
|
6096
6101
|
for (let h2 = s9; h2 < o; h2++) {
|
|
6097
6102
|
r2.push(h2);
|
|
6098
6103
|
const t3 = this.offsets[h2], s10 = t3 + this.getPageSize(h2).height, o2 = Math.max(0, Math.min(s10, a3) - Math.max(t3, e14));
|
|
6099
|
-
o2 > n2 && (n2 = o2,
|
|
6104
|
+
o2 > n2 && (n2 = o2, i2 = h2);
|
|
6100
6105
|
}
|
|
6101
|
-
this.currentVisible = r2, this.currentGlobalPageIndex =
|
|
6106
|
+
this.currentVisible = r2, this.currentGlobalPageIndex = i2, this.visibleChange$.emit({ visibleGlobalPageIndices: r2, currentGlobalPageIndex: i2 }), this.chapterManager.provides().setVisibleGlobalPages(r2), this.layoutChange$.emit(this.computeLayout());
|
|
6102
6107
|
}
|
|
6103
6108
|
findFirstVisibleIndex(t2) {
|
|
6104
6109
|
let e14 = 0, a3 = this.offsets.length - 1, s9 = 0;
|
|
@@ -6128,10 +6133,10 @@ const nt = class extends BasePlugin {
|
|
|
6128
6133
|
if (!this.viewportEl || t2 < 0 || t2 >= this.offsets.length || !this.virtualPageMap) return;
|
|
6129
6134
|
const o = (null == a3 ? void 0 : a3.marginTop) ?? 80, r2 = this.virtualPageMap.atIndex(t2);
|
|
6130
6135
|
if (!r2) return void this.scrollToIndex(t2, a3);
|
|
6131
|
-
const
|
|
6132
|
-
if (!
|
|
6133
|
-
const h2 =
|
|
6134
|
-
this.viewportEl.scrollTo({ top: Math.max(0,
|
|
6136
|
+
const i2 = this.pageSizes.get(t2), n2 = null == (s9 = this.documentManager.provides().getDocument(r2.chapterId)) ? void 0 : s9.pages[r2.localPageIndex];
|
|
6137
|
+
if (!i2 || !n2) return void this.scrollToIndex(t2, a3);
|
|
6138
|
+
const h2 = i2.height / n2.size.height, d2 = (this.offsets[t2] ?? 0) + e14 * h2 - o;
|
|
6139
|
+
this.viewportEl.scrollTo({ top: Math.max(0, d2), behavior: (null == a3 ? void 0 : a3.behavior) ?? "auto" });
|
|
6135
6140
|
}
|
|
6136
6141
|
scrollToChapter(t2, e14) {
|
|
6137
6142
|
if (!this.virtualPageMap) return;
|
|
@@ -6186,7 +6191,7 @@ const dt = class s6 extends BasePlugin {
|
|
|
6186
6191
|
this.notesChange$.emit(this.listAll());
|
|
6187
6192
|
}
|
|
6188
6193
|
buildDraft(t2) {
|
|
6189
|
-
return { chapterId: t2.chapterId, localPageIndex: t2.localPageIndex, globalPageNumber: t2.globalPageNumber, globalPageIndex: t2.globalPageIndex, rectsPdfCoord: t2.rectsPdfCoord, endAnchor:
|
|
6194
|
+
return { chapterId: t2.chapterId, localPageIndex: t2.localPageIndex, globalPageNumber: t2.globalPageNumber, globalPageIndex: t2.globalPageIndex, rectsPdfCoord: t2.rectsPdfCoord, endAnchor: ct2(t2.rectsPdfCoord), selectedText: t2.selectedText, content: t2.content };
|
|
6190
6195
|
}
|
|
6191
6196
|
async requestCreateFromSelection(t2) {
|
|
6192
6197
|
if (0 === t2.rectsPdfCoord.length) return null;
|
|
@@ -6203,8 +6208,8 @@ const dt = class s6 extends BasePlugin {
|
|
|
6203
6208
|
let o = null;
|
|
6204
6209
|
try {
|
|
6205
6210
|
o = await a3(e14);
|
|
6206
|
-
} catch (
|
|
6207
|
-
return this.logger.error(s6.id, "OnCreateNote", "Callback failed",
|
|
6211
|
+
} catch (i2) {
|
|
6212
|
+
return this.logger.error(s6.id, "OnCreateNote", "Callback failed", i2), null;
|
|
6208
6213
|
}
|
|
6209
6214
|
if (!o) return null;
|
|
6210
6215
|
const r2 = { ...e14, noteId: o.noteId };
|
|
@@ -6225,13 +6230,13 @@ const dt = class s6 extends BasePlugin {
|
|
|
6225
6230
|
var a3, o;
|
|
6226
6231
|
const r2 = this.notes.get(t2);
|
|
6227
6232
|
if (!r2) return;
|
|
6228
|
-
const
|
|
6233
|
+
const i2 = { ...r2, content: e14 };
|
|
6229
6234
|
try {
|
|
6230
|
-
await (null == (o = (a3 = this.config.callbacks).onUpdateNote) ? void 0 : o.call(a3,
|
|
6235
|
+
await (null == (o = (a3 = this.config.callbacks).onUpdateNote) ? void 0 : o.call(a3, i2));
|
|
6231
6236
|
} catch (n2) {
|
|
6232
6237
|
return void this.logger.error(s6.id, "OnUpdateNote", "Callback failed", n2);
|
|
6233
6238
|
}
|
|
6234
|
-
this.notes.set(t2,
|
|
6239
|
+
this.notes.set(t2, i2), this.notesChange$.emit(this.listAll());
|
|
6235
6240
|
}
|
|
6236
6241
|
async scrollToNote(t2) {
|
|
6237
6242
|
var e14;
|
|
@@ -6254,13 +6259,13 @@ const dt = class s6 extends BasePlugin {
|
|
|
6254
6259
|
}
|
|
6255
6260
|
};
|
|
6256
6261
|
dt.id = "note";
|
|
6257
|
-
let
|
|
6258
|
-
function
|
|
6262
|
+
let lt = dt;
|
|
6263
|
+
function ct2(t2) {
|
|
6259
6264
|
const e14 = t2[t2.length - 1];
|
|
6260
6265
|
return { x: e14.origin.x + e14.size.width, y: e14.origin.y + e14.size.height };
|
|
6261
6266
|
}
|
|
6262
6267
|
const ft = { kind: "first-wins" };
|
|
6263
|
-
function
|
|
6268
|
+
function mt2(t2, e14, a3) {
|
|
6264
6269
|
if (1 === e14.length) return e14[0].chapterId;
|
|
6265
6270
|
switch (a3.kind) {
|
|
6266
6271
|
case "first-wins":
|
|
@@ -6312,7 +6317,7 @@ let vt = class {
|
|
|
6312
6317
|
return a3 ? this._pages.indexOf(a3) : -1;
|
|
6313
6318
|
}
|
|
6314
6319
|
};
|
|
6315
|
-
function
|
|
6320
|
+
function bt(t2, e14 = ft) {
|
|
6316
6321
|
const a3 = (function(t3, e15 = ft) {
|
|
6317
6322
|
const a4 = /* @__PURE__ */ new Map();
|
|
6318
6323
|
for (const o2 of t3.chapters) {
|
|
@@ -6323,17 +6328,17 @@ function bt2(t2, e14 = ft) {
|
|
|
6323
6328
|
}
|
|
6324
6329
|
}
|
|
6325
6330
|
const s10 = /* @__PURE__ */ new Map();
|
|
6326
|
-
for (const [o2, r3] of a4) s10.set(o2,
|
|
6331
|
+
for (const [o2, r3] of a4) s10.set(o2, mt2(o2, r3, e15));
|
|
6327
6332
|
return s10;
|
|
6328
6333
|
})(t2, e14), s9 = /* @__PURE__ */ new Map();
|
|
6329
6334
|
for (const n2 of t2.chapters) s9.set(n2.chapterId, n2);
|
|
6330
6335
|
const o = Array.from(a3.keys()).sort((t3, e15) => t3 - e15), r2 = [];
|
|
6331
|
-
let
|
|
6336
|
+
let i2 = 0;
|
|
6332
6337
|
for (const n2 of o) {
|
|
6333
6338
|
const t3 = a3.get(n2), e15 = s9.get(t3);
|
|
6334
6339
|
if (!e15) continue;
|
|
6335
|
-
const [o2] = e15.globalPageRange, [h2] = e15.localPageRange,
|
|
6336
|
-
r2.push({ globalPageIndex:
|
|
6340
|
+
const [o2] = e15.globalPageRange, [h2] = e15.localPageRange, d2 = h2 + (n2 - o2);
|
|
6341
|
+
r2.push({ globalPageIndex: i2++, globalPageNumber: n2, chapterId: t3, localPageIndex: d2 });
|
|
6337
6342
|
}
|
|
6338
6343
|
return new vt(r2);
|
|
6339
6344
|
}
|
|
@@ -6368,8 +6373,8 @@ const Pt = class s7 extends BasePlugin {
|
|
|
6368
6373
|
const e15 = [], a4 = /* @__PURE__ */ new Set();
|
|
6369
6374
|
for (const s9 of t3.chapters) {
|
|
6370
6375
|
a4.has(s9.chapterId) && e15.push(`Duplicate chapterId: ${s9.chapterId}`), a4.add(s9.chapterId);
|
|
6371
|
-
const [t4, o2] = s9.globalPageRange, [r2,
|
|
6372
|
-
if (t4 > o2 && e15.push(`${s9.chapterId}: invalid globalPageRange [${t4},${o2}]`), r2 >
|
|
6376
|
+
const [t4, o2] = s9.globalPageRange, [r2, i2] = s9.localPageRange;
|
|
6377
|
+
if (t4 > o2 && e15.push(`${s9.chapterId}: invalid globalPageRange [${t4},${o2}]`), r2 > i2 && e15.push(`${s9.chapterId}: invalid localPageRange [${r2},${i2}]`), o2 - t4 !== i2 - r2 && e15.push(`${s9.chapterId}: page-count mismatch (global ${o2 - t4 + 1} vs local ${i2 - r2 + 1})`), s9.ownedGlobalPages) for (const a5 of s9.ownedGlobalPages) (a5 < t4 || a5 > o2) && e15.push(`${s9.chapterId}: ownedGlobalPages contains ${a5} outside range`);
|
|
6373
6378
|
}
|
|
6374
6379
|
return e15;
|
|
6375
6380
|
})(t2);
|
|
@@ -6377,7 +6382,7 @@ const Pt = class s7 extends BasePlugin {
|
|
|
6377
6382
|
const a3 = new Set(this.chapterStatus.keys()), o = new Set(t2.chapters.map((t3) => t3.chapterId));
|
|
6378
6383
|
for (const s9 of a3) o.has(s9) || (this.closeChapter(s9), this.chapterStatus.delete(s9));
|
|
6379
6384
|
for (const s9 of t2.chapters) this.chapterStatus.has(s9.chapterId) || this.chapterStatus.set(s9.chapterId, "idle");
|
|
6380
|
-
this.manifest = t2, this.virtualPageMap =
|
|
6385
|
+
this.manifest = t2, this.virtualPageMap = bt(t2, this.overlapStrategy), this.manifestChange$.emit({ manifest: t2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
|
|
6381
6386
|
}
|
|
6382
6387
|
eagerPrefetchFromManifest() {
|
|
6383
6388
|
const t2 = this.config.prefetchChapters ?? 0;
|
|
@@ -6409,9 +6414,9 @@ const Pt = class s7 extends BasePlugin {
|
|
|
6409
6414
|
const t3 = o.indexOf(n2);
|
|
6410
6415
|
if (-1 !== t3) for (let e15 = t3 - a3; e15 <= t3 + a3; e15++) e15 >= 0 && e15 < o.length && r2.add(e15);
|
|
6411
6416
|
}
|
|
6412
|
-
const
|
|
6413
|
-
for (const n2 of r2)
|
|
6414
|
-
for (const n2 of
|
|
6417
|
+
const i2 = /* @__PURE__ */ new Set();
|
|
6418
|
+
for (const n2 of r2) i2.add(o[n2]);
|
|
6419
|
+
for (const n2 of i2) {
|
|
6415
6420
|
this.chapterLastUsed.set(n2, e14);
|
|
6416
6421
|
const t3 = this.chapterStatus.get(n2) ?? "idle";
|
|
6417
6422
|
"idle" !== t3 && "closed" !== t3 && "error" !== t3 || this.ensureChapterLoaded(n2);
|
|
@@ -6461,8 +6466,8 @@ const Pt = class s7 extends BasePlugin {
|
|
|
6461
6466
|
const a3 = t2.chapterId;
|
|
6462
6467
|
this.updateStatus(a3, "loading"), this.chapterLastUsed.set(a3, Date.now());
|
|
6463
6468
|
try {
|
|
6464
|
-
const s9 = t2.encrypted && (null == (e14 = this.passwordProvider) ? void 0 : e14.getCachedPassword) ? this.passwordProvider.getCachedPassword(a3) : null, o = await this.resolvePdfPayload(t2), r2 = this.documentManager.provides(),
|
|
6465
|
-
|
|
6469
|
+
const s9 = t2.encrypted && (null == (e14 = this.passwordProvider) ? void 0 : e14.getCachedPassword) ? this.passwordProvider.getCachedPassword(a3) : null, o = await this.resolvePdfPayload(t2), r2 = this.documentManager.provides(), i2 = "url" in o ? r2.openDocumentUrl({ documentId: a3, url: o.url, name: t2.title, password: s9 ?? void 0, autoActivate: false }) : r2.openDocumentBuffer({ documentId: a3, buffer: o.buffer, name: t2.title, password: s9 ?? void 0, autoActivate: false }), n2 = await new Promise((t3, e15) => {
|
|
6470
|
+
i2.wait((e16) => t3(e16), (t4) => e15(t4));
|
|
6466
6471
|
});
|
|
6467
6472
|
return await new Promise((t3, e15) => {
|
|
6468
6473
|
n2.task.wait(() => t3(), (t4) => e15(t4));
|
|
@@ -6493,15 +6498,15 @@ const Pt = class s7 extends BasePlugin {
|
|
|
6493
6498
|
if (!o) return;
|
|
6494
6499
|
const r2 = (this.passwordAttempts.get(t2) ?? 0) + 1;
|
|
6495
6500
|
this.passwordAttempts.set(t2, r2);
|
|
6496
|
-
let
|
|
6501
|
+
let i2 = null;
|
|
6497
6502
|
try {
|
|
6498
|
-
|
|
6503
|
+
i2 = await this.passwordProvider.resolvePassword(o, r2 - 1);
|
|
6499
6504
|
} catch (n2) {
|
|
6500
6505
|
this.logger.error(s7.id, "PasswordProvider", `Provider rejected for ${t2}`, n2);
|
|
6501
6506
|
}
|
|
6502
|
-
if (!
|
|
6507
|
+
if (!i2) return void this.updateStatus(t2, "password-required");
|
|
6503
6508
|
this.updateStatus(t2, "loading");
|
|
6504
|
-
this.documentManager.provides().retryDocument(t2, { password:
|
|
6509
|
+
this.documentManager.provides().retryDocument(t2, { password: i2 }).wait(() => {
|
|
6505
6510
|
}, () => {
|
|
6506
6511
|
});
|
|
6507
6512
|
}
|
|
@@ -6570,7 +6575,7 @@ class Ct {
|
|
|
6570
6575
|
return a3 ? this._pages.indexOf(a3) : -1;
|
|
6571
6576
|
}
|
|
6572
6577
|
}
|
|
6573
|
-
function
|
|
6578
|
+
function Mt(t2, e14 = yt) {
|
|
6574
6579
|
const a3 = (function(t3, e15 = yt) {
|
|
6575
6580
|
const a4 = /* @__PURE__ */ new Map();
|
|
6576
6581
|
for (const o2 of t3.chapters) {
|
|
@@ -6586,12 +6591,12 @@ function Mt2(t2, e14 = yt) {
|
|
|
6586
6591
|
})(t2, e14), s9 = /* @__PURE__ */ new Map();
|
|
6587
6592
|
for (const n2 of t2.chapters) s9.set(n2.chapterId, n2);
|
|
6588
6593
|
const o = Array.from(a3.keys()).sort((t3, e15) => t3 - e15), r2 = [];
|
|
6589
|
-
let
|
|
6594
|
+
let i2 = 0;
|
|
6590
6595
|
for (const n2 of o) {
|
|
6591
6596
|
const t3 = a3.get(n2), e15 = s9.get(t3);
|
|
6592
6597
|
if (!e15) continue;
|
|
6593
|
-
const [o2] = e15.globalPageRange, [h2] = e15.localPageRange,
|
|
6594
|
-
r2.push({ globalPageIndex:
|
|
6598
|
+
const [o2] = e15.globalPageRange, [h2] = e15.localPageRange, d2 = h2 + (n2 - o2);
|
|
6599
|
+
r2.push({ globalPageIndex: i2++, globalPageNumber: n2, chapterId: t3, localPageIndex: d2 });
|
|
6595
6600
|
}
|
|
6596
6601
|
return new Ct(r2);
|
|
6597
6602
|
}
|
|
@@ -6626,8 +6631,8 @@ const St = class s8 extends BasePlugin {
|
|
|
6626
6631
|
const e15 = [], a4 = /* @__PURE__ */ new Set();
|
|
6627
6632
|
for (const s9 of t3.chapters) {
|
|
6628
6633
|
a4.has(s9.chapterId) && e15.push(`Duplicate chapterId: ${s9.chapterId}`), a4.add(s9.chapterId);
|
|
6629
|
-
const [t4, o2] = s9.globalPageRange, [r2,
|
|
6630
|
-
if (t4 > o2 && e15.push(`${s9.chapterId}: invalid globalPageRange [${t4},${o2}]`), r2 >
|
|
6634
|
+
const [t4, o2] = s9.globalPageRange, [r2, i2] = s9.localPageRange;
|
|
6635
|
+
if (t4 > o2 && e15.push(`${s9.chapterId}: invalid globalPageRange [${t4},${o2}]`), r2 > i2 && e15.push(`${s9.chapterId}: invalid localPageRange [${r2},${i2}]`), o2 - t4 !== i2 - r2 && e15.push(`${s9.chapterId}: page-count mismatch (global ${o2 - t4 + 1} vs local ${i2 - r2 + 1})`), s9.ownedGlobalPages) for (const a5 of s9.ownedGlobalPages) (a5 < t4 || a5 > o2) && e15.push(`${s9.chapterId}: ownedGlobalPages contains ${a5} outside range`);
|
|
6631
6636
|
}
|
|
6632
6637
|
return e15;
|
|
6633
6638
|
})(t2);
|
|
@@ -6635,7 +6640,7 @@ const St = class s8 extends BasePlugin {
|
|
|
6635
6640
|
const a3 = new Set(this.chapterStatus.keys()), o = new Set(t2.chapters.map((t3) => t3.chapterId));
|
|
6636
6641
|
for (const s9 of a3) o.has(s9) || (this.closeChapter(s9), this.chapterStatus.delete(s9));
|
|
6637
6642
|
for (const s9 of t2.chapters) this.chapterStatus.has(s9.chapterId) || this.chapterStatus.set(s9.chapterId, "idle");
|
|
6638
|
-
this.manifest = t2, this.virtualPageMap =
|
|
6643
|
+
this.manifest = t2, this.virtualPageMap = Mt(t2, this.overlapStrategy), this.manifestChange$.emit({ manifest: t2, map: this.virtualPageMap }), this.eagerPrefetchFromManifest();
|
|
6639
6644
|
}
|
|
6640
6645
|
eagerPrefetchFromManifest() {
|
|
6641
6646
|
const t2 = this.config.prefetchChapters ?? 0;
|
|
@@ -6667,9 +6672,9 @@ const St = class s8 extends BasePlugin {
|
|
|
6667
6672
|
const t3 = o.indexOf(n2);
|
|
6668
6673
|
if (-1 !== t3) for (let e15 = t3 - a3; e15 <= t3 + a3; e15++) e15 >= 0 && e15 < o.length && r2.add(e15);
|
|
6669
6674
|
}
|
|
6670
|
-
const
|
|
6671
|
-
for (const n2 of r2)
|
|
6672
|
-
for (const n2 of
|
|
6675
|
+
const i2 = /* @__PURE__ */ new Set();
|
|
6676
|
+
for (const n2 of r2) i2.add(o[n2]);
|
|
6677
|
+
for (const n2 of i2) {
|
|
6673
6678
|
this.chapterLastUsed.set(n2, e14);
|
|
6674
6679
|
const t3 = this.chapterStatus.get(n2) ?? "idle";
|
|
6675
6680
|
"idle" !== t3 && "closed" !== t3 && "error" !== t3 || this.ensureChapterLoaded(n2);
|
|
@@ -6719,8 +6724,8 @@ const St = class s8 extends BasePlugin {
|
|
|
6719
6724
|
const a3 = t2.chapterId;
|
|
6720
6725
|
this.updateStatus(a3, "loading"), this.chapterLastUsed.set(a3, Date.now());
|
|
6721
6726
|
try {
|
|
6722
|
-
const s9 = t2.encrypted && (null == (e14 = this.passwordProvider) ? void 0 : e14.getCachedPassword) ? this.passwordProvider.getCachedPassword(a3) : null, o = await this.resolvePdfPayload(t2), r2 = this.documentManager.provides(),
|
|
6723
|
-
|
|
6727
|
+
const s9 = t2.encrypted && (null == (e14 = this.passwordProvider) ? void 0 : e14.getCachedPassword) ? this.passwordProvider.getCachedPassword(a3) : null, o = await this.resolvePdfPayload(t2), r2 = this.documentManager.provides(), i2 = "url" in o ? r2.openDocumentUrl({ documentId: a3, url: o.url, name: t2.title, password: s9 ?? void 0, autoActivate: false }) : r2.openDocumentBuffer({ documentId: a3, buffer: o.buffer, name: t2.title, password: s9 ?? void 0, autoActivate: false }), n2 = await new Promise((t3, e15) => {
|
|
6728
|
+
i2.wait((e16) => t3(e16), (t4) => e15(t4));
|
|
6724
6729
|
});
|
|
6725
6730
|
return await new Promise((t3, e15) => {
|
|
6726
6731
|
n2.task.wait(() => t3(), (t4) => e15(t4));
|
|
@@ -6751,15 +6756,15 @@ const St = class s8 extends BasePlugin {
|
|
|
6751
6756
|
if (!o) return;
|
|
6752
6757
|
const r2 = (this.passwordAttempts.get(t2) ?? 0) + 1;
|
|
6753
6758
|
this.passwordAttempts.set(t2, r2);
|
|
6754
|
-
let
|
|
6759
|
+
let i2 = null;
|
|
6755
6760
|
try {
|
|
6756
|
-
|
|
6761
|
+
i2 = await this.passwordProvider.resolvePassword(o, r2 - 1);
|
|
6757
6762
|
} catch (n2) {
|
|
6758
6763
|
this.logger.error(s8.id, "PasswordProvider", `Provider rejected for ${t2}`, n2);
|
|
6759
6764
|
}
|
|
6760
|
-
if (!
|
|
6765
|
+
if (!i2) return void this.updateStatus(t2, "password-required");
|
|
6761
6766
|
this.updateStatus(t2, "loading");
|
|
6762
|
-
this.documentManager.provides().retryDocument(t2, { password:
|
|
6767
|
+
this.documentManager.provides().retryDocument(t2, { password: i2 }).wait(() => {
|
|
6763
6768
|
}, () => {
|
|
6764
6769
|
});
|
|
6765
6770
|
}
|
|
@@ -6774,7 +6779,7 @@ const St = class s8 extends BasePlugin {
|
|
|
6774
6779
|
}
|
|
6775
6780
|
};
|
|
6776
6781
|
St.id = "chapter-manager";
|
|
6777
|
-
let
|
|
6782
|
+
let xt2 = St;
|
|
6778
6783
|
function kt(t2, e14) {
|
|
6779
6784
|
if (t2 === e14) return true;
|
|
6780
6785
|
if (t2.totalHeight !== e14.totalHeight || t2.totalWidth !== e14.totalWidth || t2.pageGap !== e14.pageGap || t2.items.length !== e14.items.length) return false;
|
|
@@ -6786,7 +6791,7 @@ function kt(t2, e14) {
|
|
|
6786
6791
|
}
|
|
6787
6792
|
const Lt = class extends BasePlugin {
|
|
6788
6793
|
constructor(t2, a3) {
|
|
6789
|
-
super(t2, a3), this.layoutChange$ = createBehaviorEmitter(void 0, kt), 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.chapterManagerUnsubs = [], this.chapterManager = this.registry.getPlugin(
|
|
6794
|
+
super(t2, a3), this.layoutChange$ = createBehaviorEmitter(void 0, kt), 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.chapterManagerUnsubs = [], this.chapterManager = this.registry.getPlugin(xt2.id), this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
|
|
6790
6795
|
}
|
|
6791
6796
|
async initialize(t2) {
|
|
6792
6797
|
this.config = { placeholderPageHeight: t2.placeholderPageHeight ?? 1200, placeholderPageWidth: t2.placeholderPageWidth ?? 900, bufferSize: t2.bufferSize ?? 2, pageGap: t2.pageGap ?? 20 }, this.virtualPageMap = this.chapterManager.provides().getVirtualPageMap(), this.rebuildOffsets(), this.chapterManagerUnsubs.push(this.chapterManager.provides().onManifestChange(({ map: t3 }) => {
|
|
@@ -6872,12 +6877,12 @@ const Lt = class extends BasePlugin {
|
|
|
6872
6877
|
if (!this.virtualPageMap) return;
|
|
6873
6878
|
const s9 = this.documentManager.provides().getDocument(t2), o = this.virtualPageMap.pagesOfChapter(t2);
|
|
6874
6879
|
if (!(null == (a3 = null == s9 ? void 0 : s9.pages) ? void 0 : a3.length) || 0 === o.length) return void (e14 < 60 && requestAnimationFrame(() => this.harvestChapterSizes(t2, e14 + 1)));
|
|
6875
|
-
const r2 = this.getChapterDocumentScale(t2),
|
|
6880
|
+
const r2 = this.getChapterDocumentScale(t2), i2 = [];
|
|
6876
6881
|
for (const n2 of o) {
|
|
6877
6882
|
const t3 = s9.pages[n2.localPageIndex];
|
|
6878
|
-
(null == t3 ? void 0 : t3.size) &&
|
|
6883
|
+
(null == t3 ? void 0 : t3.size) && i2.push({ localPageIndex: n2.localPageIndex, width: t3.size.width * r2, height: t3.size.height * r2 });
|
|
6879
6884
|
}
|
|
6880
|
-
0 !==
|
|
6885
|
+
0 !== i2.length ? this.applyChapterPageSizes(t2, i2) : e14 < 60 && requestAnimationFrame(() => this.harvestChapterSizes(t2, e14 + 1));
|
|
6881
6886
|
}
|
|
6882
6887
|
onScaleChanged(t2) {
|
|
6883
6888
|
const e14 = this.coreState.core.documents[t2];
|
|
@@ -6911,13 +6916,13 @@ const Lt = class extends BasePlugin {
|
|
|
6911
6916
|
o++;
|
|
6912
6917
|
}
|
|
6913
6918
|
const r2 = [];
|
|
6914
|
-
let
|
|
6919
|
+
let i2 = s9, n2 = -1;
|
|
6915
6920
|
for (let h2 = s9; h2 < o; h2++) {
|
|
6916
6921
|
r2.push(h2);
|
|
6917
6922
|
const t3 = this.offsets[h2], s10 = t3 + this.getPageSize(h2).height, o2 = Math.max(0, Math.min(s10, a3) - Math.max(t3, e14));
|
|
6918
|
-
o2 > n2 && (n2 = o2,
|
|
6923
|
+
o2 > n2 && (n2 = o2, i2 = h2);
|
|
6919
6924
|
}
|
|
6920
|
-
this.currentVisible = r2, this.currentGlobalPageIndex =
|
|
6925
|
+
this.currentVisible = r2, this.currentGlobalPageIndex = i2, this.visibleChange$.emit({ visibleGlobalPageIndices: r2, currentGlobalPageIndex: i2 }), this.chapterManager.provides().setVisibleGlobalPages(r2), this.layoutChange$.emit(this.computeLayout());
|
|
6921
6926
|
}
|
|
6922
6927
|
findFirstVisibleIndex(t2) {
|
|
6923
6928
|
let e14 = 0, a3 = this.offsets.length - 1, s9 = 0;
|
|
@@ -6947,10 +6952,10 @@ const Lt = class extends BasePlugin {
|
|
|
6947
6952
|
if (!this.viewportEl || t2 < 0 || t2 >= this.offsets.length || !this.virtualPageMap) return;
|
|
6948
6953
|
const o = (null == a3 ? void 0 : a3.marginTop) ?? 80, r2 = this.virtualPageMap.atIndex(t2);
|
|
6949
6954
|
if (!r2) return void this.scrollToIndex(t2, a3);
|
|
6950
|
-
const
|
|
6951
|
-
if (!
|
|
6952
|
-
const h2 =
|
|
6953
|
-
this.viewportEl.scrollTo({ top: Math.max(0,
|
|
6955
|
+
const i2 = this.pageSizes.get(t2), n2 = null == (s9 = this.documentManager.provides().getDocument(r2.chapterId)) ? void 0 : s9.pages[r2.localPageIndex];
|
|
6956
|
+
if (!i2 || !n2) return void this.scrollToIndex(t2, a3);
|
|
6957
|
+
const h2 = i2.height / n2.size.height, d2 = (this.offsets[t2] ?? 0) + e14 * h2 - o;
|
|
6958
|
+
this.viewportEl.scrollTo({ top: Math.max(0, d2), behavior: (null == a3 ? void 0 : a3.behavior) ?? "auto" });
|
|
6954
6959
|
}
|
|
6955
6960
|
scrollToChapter(t2, e14) {
|
|
6956
6961
|
if (!this.virtualPageMap) return;
|
|
@@ -6964,23 +6969,23 @@ const Lt = class extends BasePlugin {
|
|
|
6964
6969
|
}
|
|
6965
6970
|
};
|
|
6966
6971
|
Lt.id = "chapter-scroll";
|
|
6967
|
-
let $
|
|
6972
|
+
let $t = Lt;
|
|
6968
6973
|
function Tt(t2) {
|
|
6969
6974
|
const e14 = t2[t2.length - 1];
|
|
6970
6975
|
return { x: e14.origin.x + e14.size.width, y: e14.origin.y + e14.size.height };
|
|
6971
6976
|
}
|
|
6972
|
-
function
|
|
6973
|
-
const a3 = t2.origin.y, s9 = t2.origin.y + t2.size.height, o = e14.origin.y, r2 = e14.origin.y + e14.size.height,
|
|
6974
|
-
if (
|
|
6975
|
-
return Math.max(0, Math.min(s9, r2) - Math.max(a3, o)) /
|
|
6977
|
+
function Dt2(t2, e14) {
|
|
6978
|
+
const a3 = t2.origin.y, s9 = t2.origin.y + t2.size.height, o = e14.origin.y, r2 = e14.origin.y + e14.size.height, i2 = Math.max(s9, r2) - Math.min(a3, o);
|
|
6979
|
+
if (i2 <= 0) return 0;
|
|
6980
|
+
return Math.max(0, Math.min(s9, r2) - Math.max(a3, o)) / i2;
|
|
6976
6981
|
}
|
|
6977
6982
|
function Ot(t2, e14) {
|
|
6978
6983
|
var a3, s9;
|
|
6979
6984
|
if (t2.chapterId !== e14.chapterId || t2.localPageIndex !== e14.localPageIndex) return false;
|
|
6980
|
-
const o = (null == (a3 = t2.rectsPdfCoord) ? void 0 : a3.length) ? t2.rectsPdfCoord : [t2.rectPdfCoord], r2 = (null == (s9 = e14.rectsPdfCoord) ? void 0 : s9.length) ? e14.rectsPdfCoord : [e14.rectPdfCoord],
|
|
6981
|
-
if (Math.hypot(
|
|
6985
|
+
const o = (null == (a3 = t2.rectsPdfCoord) ? void 0 : a3.length) ? t2.rectsPdfCoord : [t2.rectPdfCoord], r2 = (null == (s9 = e14.rectsPdfCoord) ? void 0 : s9.length) ? e14.rectsPdfCoord : [e14.rectPdfCoord], i2 = t2.markerAnchor ?? Tt(o), n2 = e14.markerAnchor ?? Tt(r2);
|
|
6986
|
+
if (Math.hypot(i2.x - n2.x, i2.y - n2.y) <= 6) return true;
|
|
6982
6987
|
for (const h2 of o) for (const t3 of r2) {
|
|
6983
|
-
if (
|
|
6988
|
+
if (Dt2(h2, t3) < 0.5) continue;
|
|
6984
6989
|
const e15 = Math.max(h2.origin.x, t3.origin.x);
|
|
6985
6990
|
if (Math.min(h2.origin.x + h2.size.width, t3.origin.x + t3.size.width) - e15 > 0.25 * Math.min(h2.size.width, t3.size.width)) return true;
|
|
6986
6991
|
}
|
|
@@ -7001,7 +7006,7 @@ async function Gt(t2, e14, a3) {
|
|
|
7001
7006
|
}
|
|
7002
7007
|
const zt = class a2 extends BasePlugin {
|
|
7003
7008
|
constructor(t2, a3) {
|
|
7004
|
-
super(t2, a3), this.change$ = createBehaviorEmitter([]), this.entries = /* @__PURE__ */ new Map(), this.chapterScroll = this.registry.getPlugin($
|
|
7009
|
+
super(t2, a3), this.change$ = createBehaviorEmitter([]), this.entries = /* @__PURE__ */ new Map(), this.chapterScroll = this.registry.getPlugin($t.id), this.chapterManager = this.registry.getPlugin(wt.id), this.documentManager = this.registry.getPlugin(DocumentManagerPlugin.id);
|
|
7005
7010
|
}
|
|
7006
7011
|
async initialize(t2) {
|
|
7007
7012
|
var e14;
|
|
@@ -7032,8 +7037,8 @@ const zt = class a2 extends BasePlugin {
|
|
|
7032
7037
|
const r2 = null == (s9 = null == (e14 = this.config) ? void 0 : e14.callbacks) ? void 0 : s9.onRequestRemove;
|
|
7033
7038
|
if (r2) try {
|
|
7034
7039
|
if (!await r2(o)) return false;
|
|
7035
|
-
} catch (
|
|
7036
|
-
return this.logger.error(a2.id, "RequestRemove", "callback failed",
|
|
7040
|
+
} catch (i2) {
|
|
7041
|
+
return this.logger.error(a2.id, "RequestRemove", "callback failed", i2), false;
|
|
7037
7042
|
}
|
|
7038
7043
|
return this.removeBookmark(t2), true;
|
|
7039
7044
|
}
|
|
@@ -7119,7 +7124,7 @@ function ne(t2) {
|
|
|
7119
7124
|
}
|
|
7120
7125
|
function he(t2) {
|
|
7121
7126
|
var _a2, _b, _c, _d;
|
|
7122
|
-
const e14 = (_a2 = t2.getPlugin(AnnotationPlugin.id)) == null ? void 0 : _a2.provides(), a3 = (_b = t2.getPlugin(
|
|
7127
|
+
const e14 = (_a2 = t2.getPlugin(AnnotationPlugin.id)) == null ? void 0 : _a2.provides(), a3 = (_b = t2.getPlugin(lt.id)) == null ? void 0 : _b.provides(), s9 = (_c = t2.getPlugin(At.id)) == null ? void 0 : _c.provides(), o = (_d = t2.getPlugin(O.id)) == null ? void 0 : _d.provides();
|
|
7123
7128
|
return { annotation: e14, note: a3, bookmark: s9, chapterManager: o };
|
|
7124
7129
|
}
|
|
7125
7130
|
async function de(t2, e14, a3) {
|
|
@@ -7128,10 +7133,10 @@ async function de(t2, e14, a3) {
|
|
|
7128
7133
|
if ("loaded" !== s9) throw new Error(`章节 ${e14} 未加载成功(${s9}),无法导入/导出划线`);
|
|
7129
7134
|
}
|
|
7130
7135
|
async function le(t2, e14, a3) {
|
|
7131
|
-
const s9 = ne(a3), { annotation: o, note: r2, bookmark:
|
|
7136
|
+
const s9 = ne(a3), { annotation: o, note: r2, bookmark: i2, chapterManager: n2 } = he(t2), h2 = { chapterId: e14 };
|
|
7132
7137
|
if (s9.bookmarks) {
|
|
7133
|
-
if (!
|
|
7134
|
-
h2.bookmarks =
|
|
7138
|
+
if (!i2) throw new Error("paragraph-bookmark 插件未注册");
|
|
7139
|
+
h2.bookmarks = i2.listBookmarksForChapter(e14);
|
|
7135
7140
|
}
|
|
7136
7141
|
if (s9.notes) {
|
|
7137
7142
|
if (!r2) throw new Error("note 插件未注册");
|
|
@@ -7140,41 +7145,41 @@ async function le(t2, e14, a3) {
|
|
|
7140
7145
|
if (s9.markup) {
|
|
7141
7146
|
if (!o) throw new Error("annotation 插件未注册");
|
|
7142
7147
|
await de(n2, e14, false !== (a3 == null ? void 0 : a3.ensureChapterLoaded));
|
|
7143
|
-
const t3 = await (
|
|
7144
|
-
|
|
7148
|
+
const t3 = await (d2 = o.forDocument(e14).exportAnnotations(), new Promise((t4, e15) => {
|
|
7149
|
+
d2.wait((e16) => t4(e16), (t5) => e15(t5));
|
|
7145
7150
|
}));
|
|
7146
7151
|
h2.markup = re(t3);
|
|
7147
7152
|
}
|
|
7148
|
-
var
|
|
7153
|
+
var d2;
|
|
7149
7154
|
return h2;
|
|
7150
7155
|
}
|
|
7151
7156
|
async function ce(t2, e14, a3) {
|
|
7152
7157
|
const s9 = {};
|
|
7153
7158
|
for (const o of e14.chapters) {
|
|
7154
|
-
const e15 = await le(t2, o.chapterId, a3), { chapterId: r2, ...
|
|
7155
|
-
s9[o.chapterId] =
|
|
7159
|
+
const e15 = await le(t2, o.chapterId, a3), { chapterId: r2, ...i2 } = e15;
|
|
7160
|
+
s9[o.chapterId] = i2;
|
|
7156
7161
|
}
|
|
7157
7162
|
return { version: 1, exportedAt: /* @__PURE__ */ (/* @__PURE__ */ new Date()).toISOString(), chapters: s9 };
|
|
7158
7163
|
}
|
|
7159
7164
|
async function ue(t2, e14, a3) {
|
|
7160
|
-
const s9 = ne(a3), o = (a3 == null ? void 0 : a3.mode) ?? "replace", { annotation: r2, note:
|
|
7165
|
+
const s9 = ne(a3), o = (a3 == null ? void 0 : a3.mode) ?? "replace", { annotation: r2, note: i2, bookmark: n2, chapterManager: h2 } = he(t2), d2 = e14.chapterId;
|
|
7161
7166
|
if (s9.bookmarks && e14.bookmarks) {
|
|
7162
7167
|
if (!n2) throw new Error("paragraph-bookmark 插件未注册");
|
|
7163
|
-
if ("replace" === o) n2.replaceBookmarksForChapter(
|
|
7168
|
+
if ("replace" === o) n2.replaceBookmarksForChapter(d2, e14.bookmarks);
|
|
7164
7169
|
else for (const t3 of e14.bookmarks) n2.addBookmark(t3);
|
|
7165
7170
|
}
|
|
7166
7171
|
if (s9.notes && e14.notes) {
|
|
7167
|
-
if (!
|
|
7168
|
-
if ("replace" === o)
|
|
7169
|
-
else for (const t3 of e14.notes)
|
|
7172
|
+
if (!i2) throw new Error("note 插件未注册");
|
|
7173
|
+
if ("replace" === o) i2.replaceNotesForChapter(d2, e14.notes);
|
|
7174
|
+
else for (const t3 of e14.notes) i2.registerNote(t3);
|
|
7170
7175
|
}
|
|
7171
7176
|
if (s9.markup && e14.markup) {
|
|
7172
7177
|
if (!r2) throw new Error("annotation 插件未注册");
|
|
7173
|
-
await de(h2,
|
|
7174
|
-
const t3 = r2.forDocument(
|
|
7178
|
+
await de(h2, d2, false !== (a3 == null ? void 0 : a3.ensureChapterLoaded));
|
|
7179
|
+
const t3 = r2.forDocument(d2), s10 = ie(e14.markup);
|
|
7175
7180
|
"replace" === o && t3.deleteAllAnnotations(), t3.importAnnotations(s10);
|
|
7176
7181
|
}
|
|
7177
|
-
(a3 == null ? void 0 : a3.persistNotes) &&
|
|
7182
|
+
(a3 == null ? void 0 : a3.persistNotes) && i2 && await a3.persistNotes(i2.listAllNotes()), (a3 == null ? void 0 : a3.persistBookmarks) && n2 && await a3.persistBookmarks(n2.listBookmarks());
|
|
7178
7183
|
}
|
|
7179
7184
|
async function pe(t2, e14, a3) {
|
|
7180
7185
|
if (1 !== e14.version) throw new Error(`不支持的归档版本 ${e14.version},当前为 1`);
|
|
@@ -7206,33 +7211,63 @@ function Pe(t2, e14 = "chapter-annotations.json") {
|
|
|
7206
7211
|
function we(t2, e14) {
|
|
7207
7212
|
be(e14 ?? `chapter-annotations-${t2.chapterId}.json`, me(t2));
|
|
7208
7213
|
}
|
|
7214
|
+
const t = { kind: "first-wins" };
|
|
7215
|
+
function i(e14) {
|
|
7216
|
+
return "last" === e14 ? { kind: "last-wins" } : { kind: "first-wins" };
|
|
7217
|
+
}
|
|
7218
|
+
function h(e14) {
|
|
7219
|
+
const t2 = e14.endPage - e14.startPage + 1;
|
|
7220
|
+
return { chapterId: e14.chapterId, title: e14.title, globalPageRange: [e14.startPage, e14.endPage], localPageRange: [0, t2 - 1], ...e14.source ? { source: e14.source } : {}, ...e14.encrypted ? { encrypted: e14.encrypted } : {} };
|
|
7221
|
+
}
|
|
7222
|
+
function p(e14) {
|
|
7223
|
+
const t2 = [], n2 = (e15) => {
|
|
7224
|
+
var _a2;
|
|
7225
|
+
for (const r2 of e15) t2.push(h(r2)), ((_a2 = r2.children) == null ? void 0 : _a2.length) && n2(r2.children);
|
|
7226
|
+
};
|
|
7227
|
+
return n2(e14), t2;
|
|
7228
|
+
}
|
|
7229
|
+
function g(e14) {
|
|
7230
|
+
return e14.map((e15) => {
|
|
7231
|
+
var _a2;
|
|
7232
|
+
return { id: e15.chapterId, title: e15.title, startPage: e15.startPage, endPage: e15.endPage, children: ((_a2 = e15.children) == null ? void 0 : _a2.length) ? g(e15.children) : void 0 };
|
|
7233
|
+
});
|
|
7234
|
+
}
|
|
7235
|
+
function d(e14) {
|
|
7236
|
+
return { tree: g(e14), manifest: { chapters: p(e14) } };
|
|
7237
|
+
}
|
|
7209
7238
|
export {
|
|
7210
7239
|
se as CHAPTER_ANNOTATIONS_ARCHIVE_VERSION,
|
|
7211
|
-
|
|
7240
|
+
Le as CallbackPasswordProvider,
|
|
7212
7241
|
ChapterManagerPlugin,
|
|
7213
7242
|
_sfc_main as ChapterPdfViewer,
|
|
7214
|
-
|
|
7215
|
-
|
|
7216
|
-
|
|
7243
|
+
Os as ChapterTreePanel,
|
|
7244
|
+
aa as DEFAULT_CHAPTER_VIEWER_CONFIG,
|
|
7245
|
+
ta as DEFAULT_CHAPTER_VIEWER_FEATURES,
|
|
7217
7246
|
EmbedPDF2 as EmbedPDF,
|
|
7218
|
-
|
|
7219
|
-
|
|
7220
|
-
|
|
7247
|
+
Ps as PdfChapterViewport,
|
|
7248
|
+
Me as applySelectionMarkup,
|
|
7249
|
+
d as buildChapterViewerCatalog,
|
|
7250
|
+
qt as buildParagraphBookmarkAnchor,
|
|
7221
7251
|
ge as chapterAnnotationsArchiveToJson,
|
|
7222
7252
|
me as chapterAnnotationsSnapshotToJson,
|
|
7223
|
-
|
|
7224
|
-
|
|
7225
|
-
|
|
7226
|
-
|
|
7253
|
+
h as chapterDescriptorFromTreeNode,
|
|
7254
|
+
na as createChapterViewerBundle,
|
|
7255
|
+
sa as createChapterViewerEditor,
|
|
7256
|
+
la as createChapterViewerEditorOptions,
|
|
7257
|
+
Jt as createPdfChapterEditor,
|
|
7258
|
+
t as defaultOverlapStrategy,
|
|
7227
7259
|
Pe as downloadChapterAnnotationsArchive,
|
|
7228
7260
|
we as downloadChapterAnnotationsSnapshot,
|
|
7229
7261
|
be as downloadJsonFile,
|
|
7230
7262
|
ce as exportAllChapterAnnotations,
|
|
7231
7263
|
le as exportChapterAnnotations,
|
|
7264
|
+
p as flattenChapterTree,
|
|
7232
7265
|
ue as importChapterAnnotations,
|
|
7233
7266
|
pe as importChapterAnnotationsArchive,
|
|
7267
|
+
i as overlapStrategyForSamePageOwner,
|
|
7234
7268
|
fe as parseChapterAnnotationsArchiveJson,
|
|
7235
7269
|
ve as parseChapterAnnotationsSnapshotJson,
|
|
7270
|
+
g as toChapterTreeNodes,
|
|
7236
7271
|
useCapability2 as useCapability,
|
|
7237
7272
|
usePdfiumEngine,
|
|
7238
7273
|
useRegistry2 as useRegistry
|