@xtctwins/tctwins-pdf-core 0.1.1 → 0.1.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/dist/pdf-core.js CHANGED
@@ -4,12 +4,12 @@ import { Fragment as t, computed as n, createCommentVNode as r, createElementBlo
4
4
  function w(t) {
5
5
  t && (e.GlobalWorkerOptions.workerSrc = t);
6
6
  }
7
- function T(t = "/pdf.worker.min.mjs") {
7
+ function ee(t = "/pdf.worker.min.mjs") {
8
8
  e.GlobalWorkerOptions.workerSrc = t, fetch(t, { method: "HEAD" }).catch(() => {
9
9
  e.GlobalWorkerOptions.workerSrc = "https://unpkg.com/pdfjs-dist@5.7.284/legacy/build/pdf.worker.min.mjs";
10
10
  });
11
11
  }
12
- async function E(t, n = {}) {
12
+ async function T(t, n = {}) {
13
13
  let r = t instanceof File ? await t.arrayBuffer() : t, i = r.slice(0);
14
14
  n.workerSrc && w(n.workerSrc);
15
15
  let a = await e.getDocument({ data: i }).promise;
@@ -20,8 +20,396 @@ async function E(t, n = {}) {
20
20
  };
21
21
  }
22
22
  //#endregion
23
- //#region src/core/TileCache.ts
24
- var D = class e {
23
+ //#region src/core/ColorInverter.ts
24
+ var E = "invert(1)", te = "invert(1) hue-rotate(180deg)", ne = 24, re = "\nattribute vec2 aPos;\nvarying vec2 vUv;\nvoid main() {\n vUv = aPos * 0.5 + 0.5;\n gl_Position = vec4(aPos, 0.0, 1.0);\n}", ie = "\nprecision mediump float;\nuniform sampler2D uTex;\nuniform float uThreshold;\nuniform float uUnblend;\nvarying vec2 vUv;\nvoid main() {\n vec4 c = texture2D(uTex, vUv);\n float mx = max(c.r, max(c.g, c.b));\n float mn = min(c.r, min(c.g, c.b));\n float chroma = mx - mn;\n float luma = dot(c.rgb, vec3(0.299, 0.587, 0.114));\n if (chroma <= uThreshold) {\n // 灰度(含抗锯齿灰阶):按亮度反色 → 纸白→纸黑、黑线→白线,斜坡平滑\n gl_FragColor = vec4(vec3(1.0 - luma), 1.0);\n } else if (uUnblend > 0.5) {\n // 彩色 + 覆盖度反解:像素 - min(通道) = 原墨色 × 覆盖度(新纸色为黑)\n gl_FragColor = vec4(c.rgb - mn, 1.0);\n } else {\n // 彩色原样保留(\"achromatic\" 模式;代价是边缘会有一圈亮边)\n gl_FragColor = vec4(c.rgb, 1.0);\n }\n}", D = (e, t, n) => Math.max(t, Math.min(n, e)), O = class {
25
+ constructor() {
26
+ this.glCanvas = null, this.gl = null, this.program = null, this.texture = null, this.thresholdLoc = null, this.unblendLoc = null, this.webglReady = null, this.loggedPath = !1;
27
+ }
28
+ get usingWebGL() {
29
+ return this.webglReady === !0;
30
+ }
31
+ presentPerPixel(e, t, n, r, i, a = "unblend", o = 24) {
32
+ if (r <= 0 || i <= 0) return !1;
33
+ if (this.ensureWebGL()) try {
34
+ return this.drawWithGL(e, n, r, i, a, o), this.loggedPath || (this.loggedPath = !0, console.debug("[PDF-CORE] 智能反色:WebGL 着色器快路径")), !0;
35
+ } catch {
36
+ this.disableWebGL();
37
+ }
38
+ return this.loggedPath || (this.loggedPath = !0, console.debug("[PDF-CORE] 智能反色:WebGL 不可用,降级为逐像素处理(较慢)")), this.invertPixels(t, n, r, i, a, o), !1;
39
+ }
40
+ presentAchromatic(e, t, n, r, i, a = 24) {
41
+ return this.presentPerPixel(e, t, n, r, i, "achromatic", a);
42
+ }
43
+ dispose() {
44
+ this.disableWebGL(), this.webglReady = !1;
45
+ }
46
+ ensureWebGL() {
47
+ if (this.webglReady === !1) return !1;
48
+ if (this.webglReady === !0) return !0;
49
+ try {
50
+ let e = document.createElement("canvas"), t = e.getContext("webgl", {
51
+ alpha: !1,
52
+ antialias: !1,
53
+ depth: !1,
54
+ stencil: !1,
55
+ premultipliedAlpha: !1,
56
+ preserveDrawingBuffer: !0
57
+ });
58
+ if (!t) throw Error("WebGL 不可用");
59
+ let n = this.buildProgram(t), r = t.createTexture(), i = t.createBuffer();
60
+ if (!r || !i) throw Error("WebGL 资源创建失败");
61
+ t.useProgram(n), t.bindBuffer(t.ARRAY_BUFFER, i), t.bufferData(t.ARRAY_BUFFER, new Float32Array([
62
+ -1,
63
+ -1,
64
+ 1,
65
+ -1,
66
+ -1,
67
+ 1,
68
+ 1,
69
+ 1
70
+ ]), t.STATIC_DRAW);
71
+ let a = t.getAttribLocation(n, "aPos");
72
+ return t.enableVertexAttribArray(a), t.vertexAttribPointer(a, 2, t.FLOAT, !1, 0, 0), t.bindTexture(t.TEXTURE_2D, r), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MIN_FILTER, t.LINEAR), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_MAG_FILTER, t.LINEAR), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_WRAP_S, t.CLAMP_TO_EDGE), t.texParameteri(t.TEXTURE_2D, t.TEXTURE_WRAP_T, t.CLAMP_TO_EDGE), t.uniform1i(t.getUniformLocation(n, "uTex"), 0), e.addEventListener("webglcontextlost", (e) => {
73
+ e.preventDefault(), this.disableWebGL();
74
+ }), this.glCanvas = e, this.gl = t, this.program = n, this.texture = r, this.thresholdLoc = t.getUniformLocation(n, "uThreshold"), this.unblendLoc = t.getUniformLocation(n, "uUnblend"), this.webglReady = !0, !0;
75
+ } catch {
76
+ return this.webglReady = !1, !1;
77
+ }
78
+ }
79
+ buildProgram(e) {
80
+ let t = e.createShader(e.VERTEX_SHADER), n = e.createShader(e.FRAGMENT_SHADER);
81
+ if (!t || !n) throw Error("shader 创建失败");
82
+ if (e.shaderSource(t, re), e.compileShader(t), e.shaderSource(n, ie), e.compileShader(n), !e.getShaderParameter(t, e.COMPILE_STATUS) || !e.getShaderParameter(n, e.COMPILE_STATUS)) throw Error("shader 编译失败");
83
+ let r = e.createProgram();
84
+ if (!r) throw Error("program 创建失败");
85
+ if (e.attachShader(r, t), e.attachShader(r, n), e.linkProgram(r), !e.getProgramParameter(r, e.LINK_STATUS)) throw Error("program 链接失败");
86
+ return e.deleteShader(t), e.deleteShader(n), r;
87
+ }
88
+ drawWithGL(e, t, n, r, i, a) {
89
+ let o = this.gl, s = this.glCanvas;
90
+ if (!o || !s || !this.texture) throw Error("WebGL 未就绪");
91
+ (s.width !== n || s.height !== r) && (s.width = n, s.height = r), o.viewport(0, 0, n, r), o.useProgram(this.program), o.activeTexture(o.TEXTURE0), o.bindTexture(o.TEXTURE_2D, this.texture), o.pixelStorei(o.UNPACK_FLIP_Y_WEBGL, 1), o.texImage2D(o.TEXTURE_2D, 0, o.RGBA, o.RGBA, o.UNSIGNED_BYTE, e), this.thresholdLoc && o.uniform1f(this.thresholdLoc, D(a, 0, 255) / 255), this.unblendLoc && o.uniform1f(this.unblendLoc, +(i === "unblend")), o.drawArrays(o.TRIANGLE_STRIP, 0, 4), t.setTransform(1, 0, 0, 1, 0, 0), t.drawImage(s, 0, 0);
92
+ }
93
+ disableWebGL() {
94
+ let e = this.gl;
95
+ e && (this.texture && e.deleteTexture(this.texture), this.program && e.deleteProgram(this.program), e.getExtension("WEBGL_lose_context")?.loseContext()), this.glCanvas = null, this.gl = null, this.program = null, this.texture = null, this.thresholdLoc = null, this.unblendLoc = null, this.webglReady = !1;
96
+ }
97
+ invertPixels(e, t, n, r, i, a) {
98
+ let o = e.getImageData(0, 0, n, r), s = o.data;
99
+ for (let e = 0; e < s.length; e += 4) {
100
+ let t = s[e], n = s[e + 1], r = s[e + 2], o = t > n ? t > r ? t : r : n > r ? n : r, c = t < n ? t < r ? t : r : n < r ? n : r;
101
+ if (o - c <= a) {
102
+ let i = 255 - ((t * 299 + n * 587 + r * 114) / 1e3 | 0);
103
+ s[e] = i, s[e + 1] = i, s[e + 2] = i;
104
+ } else i === "unblend" && (s[e] = t - c, s[e + 1] = n - c, s[e + 2] = r - c);
105
+ }
106
+ t.setTransform(1, 0, 0, 1, 0, 0), t.putImageData(o, 0, 0);
107
+ }
108
+ }, ae = 8192, oe = 1.25, se = .05, ce = 128, k = (e, t, n) => Math.max(t, Math.min(n, e)), le = (() => {
109
+ try {
110
+ let e = document.createElement("canvas").getContext("2d");
111
+ return e ? (e.filter = "invert(1)", e.filter === "invert(1)") : !1;
112
+ } catch {
113
+ return !1;
114
+ }
115
+ })(), A = class {
116
+ constructor(e) {
117
+ this.doc = null, this.page = null, this.pageW = 0, this.pageH = 0, this.inkCenter = {
118
+ x: 0,
119
+ y: 0
120
+ }, this.zoomValue = 1, this.centerValue = {
121
+ x: 0,
122
+ y: 0
123
+ }, this.presentedValue = {
124
+ zoom: 1,
125
+ center: {
126
+ x: 0,
127
+ y: 0
128
+ },
129
+ region: {
130
+ x: 0,
131
+ y: 0,
132
+ w: 0,
133
+ h: 0,
134
+ tiled: !1
135
+ },
136
+ offset: {
137
+ x: 0,
138
+ y: 0
139
+ }
140
+ }, this.unpresented = {
141
+ x: 0,
142
+ y: 0
143
+ }, this.dragExtra = {
144
+ x: 0,
145
+ y: 0
146
+ }, this.seq = 0, this.task = null, this.rafId = null, this.backgroundColor = "rgb(255,255,255)", this.invertColorsValue = !1, this.invertModeValue = "unblend", this.invertThresholdValue = 24, this.inverter = new O(), this.destroyed = !1, this.stageBox = {
147
+ left: 0,
148
+ top: 0,
149
+ w: 0,
150
+ h: 0
151
+ }, this.canvas = e.canvas, this.stage = e.stage, this.wrap = e.wrap ?? null, this.dprOf = e.dpr ?? (() => window.devicePixelRatio || 1), this.maxSide = e.maxSide ?? ae, this.prefetch = e.prefetch ?? oe, this.minZoom = e.minZoom ?? se, this.maxZoomValue = e.maxZoom ?? ce, this.onPresented = e.onPresented ?? null, this.backgroundColor = e.backgroundColor ?? "rgb(255,255,255)", this.invertColorsValue = e.invertColors ?? !1, this.invertModeValue = e.invertMode ?? "unblend", this.invertThresholdValue = e.invertThreshold ?? 24;
152
+ let t = this.canvas.getContext("2d");
153
+ if (!t) throw Error("[PDF-CORE] 2d context 不可用");
154
+ this.ctx = t, this.off = document.createElement("canvas");
155
+ let n = this.off.getContext("2d");
156
+ if (!n) throw Error("[PDF-CORE] 离屏 2d context 不可用");
157
+ this.offCtx = n, this.canvas.style.position = "absolute", this.canvas.style.display = "block", this.canvas.style.transformOrigin = "0 0";
158
+ }
159
+ get zoom() {
160
+ return this.zoomValue;
161
+ }
162
+ get center() {
163
+ return { ...this.centerValue };
164
+ }
165
+ get size() {
166
+ return {
167
+ wPt: this.pageW,
168
+ hPt: this.pageH
169
+ };
170
+ }
171
+ get presented() {
172
+ return this.presentedValue;
173
+ }
174
+ get pageRef() {
175
+ return this.page;
176
+ }
177
+ async open(e) {
178
+ this.doc = e, this.page = await e.getPage(1);
179
+ let t = this.page.getViewport({ scale: 1 });
180
+ return this.pageW = t.width, this.pageH = t.height, this.inkCenter = await this.detectInkCenter(this.page), this.centerValue = { ...this.inkCenter }, {
181
+ wPt: this.pageW,
182
+ hPt: this.pageH
183
+ };
184
+ }
185
+ async detectInkCenter(e) {
186
+ let t = {
187
+ x: this.pageW / 2,
188
+ y: this.pageH / 2
189
+ };
190
+ try {
191
+ let n = e.getViewport({ scale: 1 }), r = 220 / Math.max(n.width, n.height), i = e.getViewport({ scale: r }), a = document.createElement("canvas");
192
+ a.width = Math.max(1, Math.floor(i.width)), a.height = Math.max(1, Math.floor(i.height));
193
+ let o = a.getContext("2d", { willReadFrequently: !0 });
194
+ if (!o) return t;
195
+ await e.render({
196
+ canvas: a,
197
+ canvasContext: o,
198
+ viewport: i
199
+ }).promise;
200
+ let s = o.getImageData(0, 0, a.width, a.height).data, c = Infinity, l = Infinity, u = -1, d = -1;
201
+ for (let e = 0; e < a.height; e += 3) for (let t = 0; t < a.width; t += 3) {
202
+ let n = (e * a.width + t) * 4;
203
+ (s[n] < 250 || s[n + 1] < 250 || s[n + 2] < 250) && (t < c && (c = t), e < l && (l = e), t > u && (u = t), e > d && (d = e));
204
+ }
205
+ return a.width = 0, a.height = 0, u < 0 ? t : {
206
+ x: (c + u) / 2 / r,
207
+ y: (l + d) / 2 / r
208
+ };
209
+ } catch {
210
+ return t;
211
+ }
212
+ }
213
+ destroy() {
214
+ this.destroyed = !0, this.cancel(), this.rafId !== null && (cancelAnimationFrame(this.rafId), this.rafId = null), this.doc = null, this.page = null, this.canvas.width = 0, this.canvas.height = 0, this.canvas.style.filter = "", this.inverter.dispose(), this.off.width = 0, this.off.height = 0;
215
+ }
216
+ unload() {
217
+ this.cancel(), this.seq++, this.doc = null, this.page = null, this.pageW = 0, this.pageH = 0, this.canvas.width = 0, this.canvas.height = 0, this.canvas.style.transform = "", this.unpresented = {
218
+ x: 0,
219
+ y: 0
220
+ }, this.dragExtra = {
221
+ x: 0,
222
+ y: 0
223
+ }, this.wrap && (this.wrap.style.width = "0px", this.wrap.style.height = "0px");
224
+ }
225
+ cancel() {
226
+ if (this.task) {
227
+ try {
228
+ this.task.cancel();
229
+ } catch {}
230
+ this.task = null;
231
+ }
232
+ }
233
+ setBackgroundColor(e) {
234
+ this.backgroundColor = e, this.canvas.style.background = e, this.requestRender();
235
+ }
236
+ get invertColors() {
237
+ return this.invertColorsValue;
238
+ }
239
+ get invertMode() {
240
+ return this.invertModeValue;
241
+ }
242
+ setInvertColors(e) {
243
+ e !== this.invertColorsValue && (this.invertColorsValue = e, this.requestRender());
244
+ }
245
+ setInvertMode(e, t) {
246
+ let n = t ?? this.invertThresholdValue;
247
+ e === this.invertModeValue && n === this.invertThresholdValue || (this.invertModeValue = e, this.invertThresholdValue = n, this.requestRender());
248
+ }
249
+ get usingWebGLInvert() {
250
+ return this.inverter.usingWebGL;
251
+ }
252
+ get maxZoom() {
253
+ return this.maxZoomValue;
254
+ }
255
+ setMaxZoom(e) {
256
+ !(e > 0) || e === this.maxZoomValue || (this.maxZoomValue = e, this.zoomValue > e && (this.zoomValue = e, this.requestRender()));
257
+ }
258
+ setZoom(e) {
259
+ let t = k(e, this.minZoom, this.maxZoomValue);
260
+ t !== this.zoomValue && (this.zoomValue = t, this.requestRender());
261
+ }
262
+ anchorAt(e, t, n, r) {
263
+ let i = k(r, this.minZoom, this.maxZoomValue);
264
+ this.zoomValue = i;
265
+ let a = this.stageCenterOnScreen();
266
+ this.centerValue = {
267
+ x: n.x - (e - a.x) / i,
268
+ y: n.y - (t - a.y) / i
269
+ }, this.requestRender();
270
+ }
271
+ zoomAt(e, t, n) {
272
+ let r = k(this.zoomValue * n, this.minZoom, this.maxZoomValue);
273
+ if (r === this.zoomValue) return !1;
274
+ let i = this.screenToPt(e, t);
275
+ return this.anchorAt(e, t, i, r), !0;
276
+ }
277
+ setDragOffset(e, t) {
278
+ this.dragExtra = {
279
+ x: e,
280
+ y: t
281
+ }, this.applyBitmapOffset();
282
+ }
283
+ commitDrag(e, t) {
284
+ let n = this.presentedValue.zoom || 1;
285
+ this.centerValue = {
286
+ x: this.centerValue.x - e / n,
287
+ y: this.centerValue.y - t / n
288
+ }, this.unpresented = {
289
+ x: this.unpresented.x + e,
290
+ y: this.unpresented.y + t
291
+ }, this.dragExtra = {
292
+ x: 0,
293
+ y: 0
294
+ }, this.requestRender();
295
+ }
296
+ centerOnContent() {
297
+ this.centerValue = { ...this.inkCenter }, this.requestRender();
298
+ }
299
+ applyBitmapOffset() {
300
+ let e = this.unpresented.x + this.dragExtra.x, t = this.unpresented.y + this.dragExtra.y;
301
+ this.canvas.style.transform = e === 0 && t === 0 ? "" : `translate(${e}px, ${t}px)`;
302
+ }
303
+ screenToPt(e, t) {
304
+ let n = this.presentedValue, r = n.zoom || 1, i = this.stageCenterOnScreen(), a = {
305
+ x: this.unpresented.x + this.dragExtra.x,
306
+ y: this.unpresented.y + this.dragExtra.y
307
+ };
308
+ return {
309
+ x: n.center.x + (e - i.x - a.x) / r,
310
+ y: n.center.y + (t - i.y - a.y) / r
311
+ };
312
+ }
313
+ ptToScreen(e) {
314
+ let t = this.presentedValue, n = t.zoom || 1, r = this.stageCenterOnScreen(), i = {
315
+ x: this.unpresented.x + this.dragExtra.x,
316
+ y: this.unpresented.y + this.dragExtra.y
317
+ };
318
+ return {
319
+ x: r.x + (e.x - t.center.x) * n + i.x,
320
+ y: r.y + (e.y - t.center.y) * n + i.y
321
+ };
322
+ }
323
+ refreshStageBox() {
324
+ let e = this.stage.getBoundingClientRect(), t = this.stage.clientWidth || e.width, n = this.stage.clientHeight || e.height;
325
+ this.stageBox = {
326
+ left: e.left + (e.width - t) / 2,
327
+ top: e.top + (e.height - n) / 2,
328
+ w: t,
329
+ h: n
330
+ };
331
+ }
332
+ stageCenterOnScreen() {
333
+ return {
334
+ x: this.stageBox.left + this.stageBox.w / 2,
335
+ y: this.stageBox.top + this.stageBox.h / 2
336
+ };
337
+ }
338
+ computeRegion() {
339
+ let e = this.zoomValue * this.dprOf();
340
+ if (Math.max(this.pageW * e, this.pageH * e) <= this.maxSide) return null;
341
+ let t = (this.stageBox.w || 1) / this.zoomValue * this.prefetch, n = (this.stageBox.h || 1) / this.zoomValue * this.prefetch, r = Math.min(t, this.pageW), i = Math.min(n, this.pageH), a = k(this.centerValue.x - r / 2, 0, Math.max(this.pageW - r, 0)), o = k(this.centerValue.y - i / 2, 0, Math.max(this.pageH - i, 0)), s = {
342
+ x: a,
343
+ y: o,
344
+ w: r,
345
+ h: i,
346
+ tiled: !0
347
+ };
348
+ return this.centerValue = {
349
+ x: a + r / 2,
350
+ y: o + i / 2
351
+ }, s;
352
+ }
353
+ layout(e) {
354
+ let t = this.zoomValue;
355
+ this.wrap && (this.wrap.style.position = "absolute", this.wrap.style.left = "0", this.wrap.style.top = "0", this.wrap.style.width = `${Math.round(this.pageW * t)}px`, this.wrap.style.height = `${Math.round(this.pageH * t)}px`, this.wrap.style.transformOrigin = "0 0", this.wrap.style.transform = `translate(${this.stageBox.w / 2 - this.centerValue.x * t}px, ${this.stageBox.h / 2 - this.centerValue.y * t}px)`);
356
+ let n = this.wrap ? 0 : this.stageBox.w / 2 - this.centerValue.x * t, r = this.wrap ? 0 : this.stageBox.h / 2 - this.centerValue.y * t;
357
+ this.canvas.style.left = `${n + e.x * t}px`, this.canvas.style.top = `${r + e.y * t}px`, this.canvas.style.width = `${Math.round(e.w * t)}px`, this.canvas.style.height = `${Math.round(e.h * t)}px`, this.unpresented = {
358
+ x: 0,
359
+ y: 0
360
+ }, this.dragExtra = {
361
+ x: 0,
362
+ y: 0
363
+ }, this.canvas.style.transform = "";
364
+ }
365
+ requestRender() {
366
+ this.destroyed || this.rafId !== null || (this.rafId = requestAnimationFrame(() => {
367
+ this.rafId = null, this.render();
368
+ }));
369
+ }
370
+ async render() {
371
+ if (this.destroyed || !this.page || this.pageW <= 0) return;
372
+ let e = ++this.seq;
373
+ this.cancel(), this.refreshStageBox();
374
+ let t = this.zoomValue * this.dprOf(), n = this.computeRegion(), r = n ?? {
375
+ x: 0,
376
+ y: 0,
377
+ w: this.pageW,
378
+ h: this.pageH,
379
+ tiled: !1
380
+ }, i = this.page.getViewport({ scale: t });
381
+ n && (i = i.clone({
382
+ offsetX: -n.x * t,
383
+ offsetY: -n.y * t
384
+ }));
385
+ let a = Math.max(1, Math.floor(r.w * t)), o = Math.max(1, Math.floor(r.h * t));
386
+ this.off.width = a, this.off.height = o, this.offCtx.setTransform(1, 0, 0, 1, 0, 0), this.offCtx.fillStyle = this.invertColorsValue ? "#ffffff" : this.backgroundColor, this.offCtx.fillRect(0, 0, a, o);
387
+ let s = null;
388
+ try {
389
+ s = this.page.render({
390
+ canvas: this.off,
391
+ canvasContext: this.offCtx,
392
+ viewport: i
393
+ }), this.task = s, await s.promise;
394
+ } catch (t) {
395
+ if (e !== this.seq || (t?.name ?? "") === "RenderingCancelledException") return;
396
+ throw t;
397
+ } finally {
398
+ this.task === s && (this.task = null);
399
+ }
400
+ if (e !== this.seq) return;
401
+ let c = this.invertColorsValue, l = this.invertModeValue, u = c && (l === "unblend" || l === "achromatic"), d = l === "all" ? E : te, f = c && !u && le;
402
+ this.canvas.width = a, this.canvas.height = o, u ? this.inverter.presentPerPixel(this.off, this.offCtx, this.ctx, a, o, l, this.invertThresholdValue) : (this.ctx.setTransform(1, 0, 0, 1, 0, 0), f && (this.ctx.filter = d), this.ctx.drawImage(this.off, 0, 0), f && (this.ctx.filter = "none")), this.canvas.style.filter = c && !u && !f ? d : "", this.canvas.style.background = this.backgroundColor, this.presentedValue = {
403
+ zoom: this.zoomValue,
404
+ center: { ...this.centerValue },
405
+ region: r,
406
+ offset: {
407
+ x: 0,
408
+ y: 0
409
+ }
410
+ }, this.layout(r), this.onPresented?.(this.presentedValue);
411
+ }
412
+ }, j = class e {
25
413
  constructor(e = 100) {
26
414
  this.cache = /* @__PURE__ */ new Map(), this.capacity = e;
27
415
  }
@@ -57,20 +445,20 @@ var D = class e {
57
445
  get size() {
58
446
  return this.cache.size;
59
447
  }
60
- }, O = () => typeof navigator < "u" && /Mobi|Android|iPhone|iPad/i.test(navigator.userAgent);
61
- function k(e) {
448
+ }, M = () => typeof navigator < "u" && /Mobi|Android|iPhone|iPad/i.test(navigator.userAgent);
449
+ function ue(e) {
62
450
  let t = window.devicePixelRatio ?? 1;
63
451
  return e >= 32 ? 1 : e >= 16 ? Math.min(t, 2) : t;
64
452
  }
65
- function ee(e) {
453
+ function N(e) {
66
454
  return e ? 2048 : 4096;
67
455
  }
68
- var A = 4096, j = 128;
69
- async function M(e, t = {}) {
70
- let n = t.scale ?? 1.5, r = O(), i = t.backgroundColor ?? "rgb(255,255,255)";
456
+ var P = 4096, de = 128;
457
+ async function F(e, t = {}) {
458
+ let n = t.scale ?? 1.5, r = M(), i = t.backgroundColor ?? "rgb(255,255,255)";
71
459
  t.cache;
72
- let a = k(n), o = e.getViewport({ scale: n * a }), s = o.width, c = o.height, l = ee(r), u = Math.min(l, A, Math.max(s, c)), d = Math.ceil(s / u), f = Math.ceil(c / u), p = d * f;
73
- p > j && console.warn(`[PDF-CORE] scale=${n} dpr=${a}, tile=${p} (${d}×${f}), tileSize=${u}px (physical). IntersectionObserver 将按需渲染。`);
460
+ let a = ue(n), o = e.getViewport({ scale: n * a }), s = o.width, c = o.height, l = N(r), u = Math.min(l, P, Math.max(s, c)), d = Math.ceil(s / u), f = Math.ceil(c / u), p = d * f;
461
+ p > de && console.warn(`[PDF-CORE] scale=${n} dpr=${a}, tile=${p} (${d}×${f}), tileSize=${u}px (physical). IntersectionObserver 将按需渲染。`);
74
462
  let m = s / a, h = c / a, g = document.createElement("div");
75
463
  g.style.cssText = [
76
464
  "position:relative",
@@ -99,14 +487,14 @@ async function M(e, t = {}) {
99
487
  }).finally(() => {
100
488
  v.delete(s), b--, S();
101
489
  });
102
- }, w = r ? "128px" : "256px", T = r ? 2 : 3, E = new IntersectionObserver((e) => {
490
+ }, w = r ? "128px" : "256px", ee = r ? 2 : 3, T = new IntersectionObserver((e) => {
103
491
  e.forEach((e) => {
104
492
  let t = e.target, r = t.dataset.tileKey, [a, o] = (t.dataset.tilePos ?? "0,0").split(",").map(Number);
105
493
  if (e.isIntersecting) {
106
494
  if (_.has(r) || v.has(r)) return;
107
495
  let e = () => C(t, a, o);
108
496
  b >= y ? x.push(e) : e();
109
- } else if (n >= T && _.has(r)) {
497
+ } else if (n >= ee && _.has(r)) {
110
498
  let e = t.getContext("2d", { alpha: !1 });
111
499
  e.setTransform(1, 0, 0, 1, 0, 0), e.fillStyle = i, e.fillRect(0, 0, t.width, t.height), _.delete(r);
112
500
  }
@@ -115,7 +503,7 @@ async function M(e, t = {}) {
115
503
  root: null,
116
504
  rootMargin: w,
117
505
  threshold: 0
118
- }), M = [];
506
+ }), E = [];
119
507
  for (let t = 0; t < f; t++) for (let r = 0; r < d; r++) {
120
508
  let o = r * u, l = t * u, d = Math.round(Math.min(u, s - o)), f = Math.round(Math.min(u, c - l)), p = o / a, m = l / a, h = d / a, _ = f / a, v = document.createElement("canvas");
121
509
  v.width = d, v.height = f;
@@ -127,7 +515,7 @@ async function M(e, t = {}) {
127
515
  `width:${h}px`,
128
516
  `height:${_}px`,
129
517
  `background:${i}`
130
- ].join(";"), v.dataset.tileKey = D.makeKey(e.pageNumber, n, r, t), v.dataset.tilePos = `${r},${t}`, g.appendChild(v), E.observe(v), M.push({
518
+ ].join(";"), v.dataset.tileKey = j.makeKey(e.pageNumber, n, r, t), v.dataset.tilePos = `${r},${t}`, g.appendChild(v), T.observe(v), E.push({
131
519
  canvas: v,
132
520
  col: r,
133
521
  row: t,
@@ -142,14 +530,14 @@ async function M(e, t = {}) {
142
530
  container: g,
143
531
  pageWidth: m,
144
532
  pageHeight: h,
145
- tiles: M
533
+ tiles: E
146
534
  },
147
- observer: E
535
+ observer: T
148
536
  };
149
537
  }
150
538
  //#endregion
151
539
  //#region src/core/coords/CoordTransformer.ts
152
- var te = class {
540
+ var I = class {
153
541
  constructor(e, t, n) {
154
542
  if (this.viewport = e, this.scale = t, this.pageSizePt = n, t <= 0) throw RangeError(`scale 必须大于 0,收到: ${t}`);
155
543
  }
@@ -195,7 +583,7 @@ var te = class {
195
583
  get pageSize() {
196
584
  return this.pageSizePt;
197
585
  }
198
- }, N = [
586
+ }, L = [
199
587
  5,
200
588
  10,
201
589
  25,
@@ -216,12 +604,18 @@ var te = class {
216
604
  1800,
217
605
  2e3,
218
606
  2200,
219
- 2800
607
+ 2800,
608
+ 3200,
609
+ 4e3,
610
+ 6e3,
611
+ 8e3,
612
+ 1e4,
613
+ 12800
220
614
  ];
221
- function P(e, t) {
222
- return t === "in" ? N.find((t) => t > e) ?? N[N.length - 1] : [...N].reverse().find((t) => t < e) ?? N[0];
615
+ function R(e, t) {
616
+ return t === "in" ? L.find((t) => t > e) ?? L[L.length - 1] : [...L].reverse().find((t) => t < e) ?? L[0];
223
617
  }
224
- var F = class {
618
+ var z = class {
225
619
  constructor() {
226
620
  this.interaction = null, this.toolManager = null, this.drawCallback = null, this.domContainerId = null, this.zoomCtrl = null, this.initialScale = 1.5;
227
621
  }
@@ -259,12 +653,12 @@ var F = class {
259
653
  }
260
654
  zoomIn() {
261
655
  if (!this.zoomCtrl) return;
262
- let e = this.zoomCtrl.getScale(), t = P(Math.round(e * 100), "in");
656
+ let e = this.zoomCtrl.getScale(), t = R(Math.round(e * 100), "in");
263
657
  this.zoomCtrl.setScale(t / 100);
264
658
  }
265
659
  zoomOut() {
266
660
  if (!this.zoomCtrl) return;
267
- let e = this.zoomCtrl.getScale(), t = P(Math.round(e * 100), "out");
661
+ let e = this.zoomCtrl.getScale(), t = R(Math.round(e * 100), "out");
268
662
  this.zoomCtrl.setScale(t / 100);
269
663
  }
270
664
  setScale(e) {
@@ -325,7 +719,7 @@ var F = class {
325
719
  };
326
720
  //#endregion
327
721
  //#region src/annotations/utils.ts
328
- function I(e, t = 0, n = "px") {
722
+ function B(e, t = 0, n = "px") {
329
723
  return {
330
724
  id: `measure-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
331
725
  kind: "measure",
@@ -337,7 +731,7 @@ function I(e, t = 0, n = "px") {
337
731
  createdAt: Date.now()
338
732
  };
339
733
  }
340
- function L(e, t = "rectangle") {
734
+ function V(e, t = "rectangle") {
341
735
  return {
342
736
  id: `shape-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
343
737
  kind: "shape",
@@ -348,12 +742,12 @@ function L(e, t = "rectangle") {
348
742
  createdAt: Date.now()
349
743
  };
350
744
  }
351
- function R(e) {
745
+ function fe(e) {
352
746
  return JSON.parse(JSON.stringify(e));
353
747
  }
354
748
  //#endregion
355
749
  //#region src/utils/EventTrigger.ts
356
- var z = class {
750
+ var H = class {
357
751
  constructor() {
358
752
  this._events = /* @__PURE__ */ new Map();
359
753
  }
@@ -391,107 +785,136 @@ var z = class {
391
785
  destroy() {
392
786
  this._events.clear();
393
787
  }
394
- }, B = () => typeof navigator < "u" && /Mobi|Android|iPhone|iPad/i.test(navigator.userAgent);
395
- function V(e = {}) {
396
- let t = h(null), n = _(null), r = _(null), i = h(0), a = h(1), o = h(e.scale ?? 1.5), s = h(e.backgroundColor ?? "rgb(255,255,255)"), c = h(!1), l = h(null), u = new z(), d = new D(B() ? 30 : 100), f = !1, p = 0, m = null, g = B() ? 200 : 60, v = null, y = null, b = null, x = async (e) => {
397
- c.value = !0, l.value = null;
788
+ };
789
+ //#endregion
790
+ //#region src/vue/usePdfCore.ts
791
+ function pe(e = {}) {
792
+ let t = h(null), n = _(null), r = _(null), i = _(null), a = h(0), o = h(1), s = h(e.scale ?? 1), c = h(e.backgroundColor ?? "rgb(255,255,255)"), l = h(e.invertColors ?? !1), u = h(!1), d = h(null), f = new H(), p = (i) => {
793
+ let { canvas: a, stage: u, wrap: d } = i;
794
+ if (!a || !u) return null;
795
+ n.value && n.value.destroy();
796
+ let p = new A({
797
+ canvas: a,
798
+ stage: u,
799
+ wrap: d ?? null,
800
+ maxSide: e.maxSide,
801
+ maxZoom: e.maxZoom,
802
+ backgroundColor: c.value,
803
+ invertColors: l.value,
804
+ invertMode: e.invertMode,
805
+ invertThreshold: e.invertThreshold ?? 24,
806
+ onPresented: (t) => {
807
+ s.value = t.zoom, f.emit("render_complete", {
808
+ pageNum: o.value,
809
+ scale: t.zoom
810
+ }), e.onPresented?.({
811
+ zoom: t.zoom,
812
+ pageNum: o.value,
813
+ tiled: t.region.tiled
814
+ });
815
+ }
816
+ });
817
+ p.refreshStageBox(), n.value = p, t.value = u;
818
+ let m = r.value;
819
+ return m && m.destroyed !== !0 && (async () => {
820
+ try {
821
+ if (n.value !== p || (await p.open(m), p.setZoom(s.value), n.value !== p)) return;
822
+ await p.render();
823
+ } catch (e) {
824
+ console.error("[PDF-CORE] 重新挂载后恢复渲染失败:", e);
825
+ }
826
+ })(), p;
827
+ }, m = () => {
828
+ n.value?.destroy(), n.value = null;
829
+ }, g = async (e) => {
830
+ u.value = !0, d.value = null;
398
831
  try {
399
- let t = await E(e);
400
- n.value = t.doc, i.value = t.pageCount, a.value = 1, await S(), u.emit("loaded", {
832
+ let t = await T(e);
833
+ r.value = t.doc, a.value = t.pageCount, o.value = 1;
834
+ let c = n.value;
835
+ if (c) {
836
+ let e = await c.open(t.doc);
837
+ c.setZoom(s.value), c.refreshStageBox(), e.wPt > 0 && (i.value = c.pageRef);
838
+ }
839
+ await v(), f.emit("loaded", {
401
840
  pageCount: t.pageCount,
402
841
  currentPage: 1
403
842
  });
404
843
  } catch (e) {
405
844
  let t = e instanceof Error ? e.message : "Failed to load PDF";
406
- l.value = t, u.emit("error_occurred", { message: t });
845
+ d.value = t, f.emit("error_occurred", { message: t });
407
846
  } finally {
408
- c.value = !1;
847
+ u.value = !1;
409
848
  }
410
- }, S = async () => {
411
- if (!n.value || !t.value) return;
412
- let e = ++p;
413
- if (!f) {
414
- f = !0;
415
- try {
416
- m &&= (m.disconnect(), null);
417
- let i = await n.value.getPage(a.value);
418
- if (e !== p) {
419
- f = !1;
420
- return;
421
- }
422
- r.value = i;
423
- let { tiledPage: c, observer: l } = await M(i, {
424
- scale: o.value,
425
- cache: d,
426
- backgroundColor: s.value
427
- });
428
- if (e !== p) {
429
- l.disconnect(), f = !1;
430
- return;
431
- }
432
- m = l, t.value.replaceChildren(c.container), u.emit("render_complete", {
433
- pageNum: a.value,
434
- scale: o.value
435
- });
436
- } catch (e) {
437
- console.error("[PDF-CORE] renderCurrentPage failed:", e), u.emit("error_occurred", { message: e instanceof Error ? e.message : "Render failed" });
438
- } finally {
439
- f = !1, p > e && S();
440
- }
849
+ }, v = async () => {
850
+ let e = n.value;
851
+ if (!(!e || !r.value)) try {
852
+ await e.render();
853
+ } catch (e) {
854
+ console.error("[PDF-CORE] render failed:", e), f.emit("error_occurred", { message: e instanceof Error ? e.message : "Render failed" });
441
855
  }
442
856
  };
443
857
  return {
444
858
  containerRef: t,
445
- doc: n,
446
- page: r,
447
- pageCount: i,
448
- currentPageNum: a,
449
- currentScale: o,
450
- backgroundColor: s,
451
- isLoading: c,
452
- error: l,
453
- events: u,
454
- loadFile: x,
455
- renderCurrentPage: S,
456
- setScale: (e) => new Promise((t) => {
457
- if (e <= 0) {
458
- t();
459
- return;
460
- }
461
- y = e, v !== null && (clearTimeout(v), b?.()), b = t, v = setTimeout(async () => {
462
- v = null;
463
- let e = y, t = b;
464
- if (y = null, b = null, e === null || e === o.value) {
465
- t?.();
466
- return;
467
- }
468
- d.clear();
469
- let r = o.value;
470
- o.value = e, n.value && await S(), t?.(), u.emit("scale_changed", {
471
- scale: e,
472
- previousScale: r
473
- });
474
- }, g);
475
- }),
476
- setBackgroundColor: (e) => new Promise((t) => {
477
- s.value = e, d.clear(), n.value ? S().then(() => t()) : t();
478
- }),
859
+ renderer: n,
860
+ doc: r,
861
+ page: i,
862
+ pageCount: a,
863
+ currentPageNum: o,
864
+ currentScale: s,
865
+ backgroundColor: c,
866
+ isLoading: u,
867
+ error: d,
868
+ events: f,
869
+ attach: p,
870
+ detach: m,
871
+ loadFile: g,
872
+ renderCurrentPage: v,
873
+ setScale: async (e) => {
874
+ let t = n.value;
875
+ if (!t || e <= 0) return;
876
+ let r = t.zoom;
877
+ t.setZoom(e), await t.render(), r !== t.zoom && f.emit("scale_changed", {
878
+ scale: t.zoom,
879
+ previousScale: r
880
+ });
881
+ },
882
+ setBackgroundColor: async (e) => {
883
+ c.value = e;
884
+ let t = n.value;
885
+ t && (t.setBackgroundColor(e), t.pageRef && await t.render());
886
+ },
887
+ setInvertColors: (e) => {
888
+ l.value = e;
889
+ let t = n.value;
890
+ t && (t.setInvertColors(e), t.pageRef && t.render());
891
+ },
892
+ setInvertMode: (e, t) => {
893
+ n.value?.setInvertMode(e, t);
894
+ },
895
+ setMaxZoom: (e) => {
896
+ n.value?.setMaxZoom(e);
897
+ },
898
+ invertColors: l,
899
+ resetView: () => {
900
+ n.value?.centerOnContent(), n.value?.requestRender();
901
+ },
479
902
  reset: () => {
480
- m &&= (m.disconnect(), null), v !== null && (clearTimeout(v), v = null), b?.(), y = null, b = null, d.clear(), n.value = null, r.value = null, i.value = 0, a.value = 1, l.value = null, c.value = !1, f = !1, t.value && t.value.replaceChildren(), u.emit("cleared");
903
+ n.value?.unload(), r.value = null, i.value = null, a.value = 0, o.value = 1, d.value = null, u.value = !1, f.emit("cleared");
481
904
  }
482
905
  };
483
906
  }
484
907
  //#endregion
485
908
  //#region src/vue/useAnnotations.ts
486
- function H() {
909
+ function U() {
487
910
  let e = h([]);
488
911
  return {
489
912
  annotations: e,
490
913
  addMeasureAnnotation: (t, n = 0, r = "px") => {
491
- e.value = [...e.value, I(t, n, r)];
914
+ e.value = [...e.value, B(t, n, r)];
492
915
  },
493
916
  addShapeAnnotation: (t, n = "rectangle") => {
494
- e.value = [...e.value, L(t, n)];
917
+ e.value = [...e.value, V(t, n)];
495
918
  },
496
919
  removeAnnotation: (t) => {
497
920
  e.value = e.value.filter((e) => e.id !== t);
@@ -500,13 +923,13 @@ function H() {
500
923
  e.value = [];
501
924
  },
502
925
  replaceAnnotations: (t) => {
503
- e.value = t.map(R);
926
+ e.value = t.map(fe);
504
927
  }
505
928
  };
506
929
  }
507
930
  //#endregion
508
931
  //#region src/vue/useMeasurement.ts
509
- function U() {
932
+ function W() {
510
933
  let e = h([]);
511
934
  return {
512
935
  points: e,
@@ -525,8 +948,8 @@ function U() {
525
948
  }
526
949
  //#endregion
527
950
  //#region src/vue/useInteraction.ts
528
- function W() {
529
- let { annotations: e, addMeasureAnnotation: t, clearAnnotations: n } = H(), { points: r, addPoint: i, clearPoints: a, distance: o } = U(), s = h(!1);
951
+ function me() {
952
+ let { annotations: e, addMeasureAnnotation: t, clearAnnotations: n } = U(), { points: r, addPoint: i, clearPoints: a, distance: o } = W(), s = h(!1);
530
953
  return {
531
954
  points: r,
532
955
  annotations: e,
@@ -547,7 +970,7 @@ function W() {
547
970
  }
548
971
  //#endregion
549
972
  //#region src/components/interaction.ts
550
- function G() {
973
+ function he() {
551
974
  let e = [], t = [], n = "none", r = null;
552
975
  return {
553
976
  get points() {
@@ -567,11 +990,11 @@ function G() {
567
990
  },
568
991
  addPoint(i) {
569
992
  if (e = [...e, i], n === "measure" && e.length >= 2) {
570
- let n = I([e[e.length - 2], e[e.length - 1]], Math.hypot(e[e.length - 1].x - e[e.length - 2].x, e[e.length - 1].y - e[e.length - 2].y));
993
+ let n = B([e[e.length - 2], e[e.length - 1]], Math.hypot(e[e.length - 1].x - e[e.length - 2].x, e[e.length - 1].y - e[e.length - 2].y));
571
994
  return t = [...t, n], r = n.id, e = [], n;
572
995
  }
573
996
  if (n === "rectangle" && e.length >= 2) {
574
- let n = L([e[e.length - 2], e[e.length - 1]], "rectangle");
997
+ let n = V([e[e.length - 2], e[e.length - 1]], "rectangle");
575
998
  return t = [...t, n], r = n.id, e = [], n;
576
999
  }
577
1000
  return null;
@@ -593,7 +1016,7 @@ function G() {
593
1016
  }
594
1017
  //#endregion
595
1018
  //#region src/components/useAnnotationCanvas.ts
596
- function K(e) {
1019
+ function ge(e) {
597
1020
  let { annotationCanvas: t, rootRef: n, pdfLayerRef: r, interaction: i, previewPoint: a } = e, o = (e) => {
598
1021
  let t = e.currentTarget.getBoundingClientRect();
599
1022
  return {
@@ -657,7 +1080,7 @@ function K(e) {
657
1080
  }
658
1081
  //#endregion
659
1082
  //#region src/components/usePointerInteraction.ts
660
- function ne(e) {
1083
+ function _e(e) {
661
1084
  let { annotationCanvas: t, interaction: n, previewPoint: r, isRectangleDragging: i, getCanvasPoint: a, hitTestAnnotation: o, drawAnnotations: s, deleteSelectedAnnotation: c, emit: l } = e;
662
1085
  return {
663
1086
  handlePointerDown: (e) => {
@@ -722,158 +1145,110 @@ function ne(e) {
722
1145
  }
723
1146
  //#endregion
724
1147
  //#region src/components/useViewerLayout.ts
725
- var q = (e, t, n) => Math.max(t, Math.min(n, e)), J = (e) => Math.hypot(e[0].clientX - e[1].clientX, e[0].clientY - e[1].clientY), Y = (e) => ({
726
- x: (e[0].clientX + e[1].clientX) / 2,
727
- y: (e[0].clientY + e[1].clientY) / 2
728
- }), X = (e) => {
729
- let t = N[0], n = Math.abs(e - t);
730
- for (let r = 1; r < N.length; r++) {
731
- let i = Math.abs(e - N[r]);
732
- i < n && (n = i, t = N[r]);
733
- }
734
- return t;
735
- }, Z = () => typeof navigator < "u" && /Mobi|Android|iPhone|iPad/i.test(navigator.userAgent);
736
- function re(e) {
737
- let { viewerRef: t, rootRef: r, pdfLayerRef: i, currentScale: a, setScale: o, zoomSpeed: s, theme: c, syncCanvasSize: l, drawAnnotations: u } = e, d = 0, f = 0, p = a.value, m = 1, g = null, _ = () => {
738
- let e = r.value;
739
- e && (e.style.transformOrigin = "0 0", m === 1 ? e.style.transform = `translate(${d}px, ${f}px)` : e.style.transform = `translate(${d}px, ${f}px) scale(${m})`);
740
- }, v = () => {
741
- let e = i.value;
742
- return e ? {
743
- w: e.scrollWidth || e.offsetWidth,
744
- h: e.scrollHeight || e.offsetHeight
745
- } : {
746
- w: 0,
747
- h: 0
748
- };
749
- }, y = (e, n) => {
750
- let r = t.value;
751
- if (!r) return {
752
- ntx: e,
753
- nty: n
754
- };
755
- let i = r.clientWidth, a = r.clientHeight, { w: o, h: s } = v(), c = o * m, l = s * m;
756
- return {
757
- ntx: q(e, -(c - 80), i - 80),
758
- nty: q(n, -(l - 80), a - 80)
759
- };
760
- }, b = () => {
761
- let e = t.value;
762
- if (!e) return;
763
- let { w: n, h: r } = v(), i = n * m, a = r * m;
764
- d = Math.max(0, (e.clientWidth - i) / 2), f = Math.max(0, (e.clientHeight - a) / 2), _();
765
- }, x = (e = !1) => {
766
- let t = r.value;
767
- t && (t.style.position = "absolute", t.style.top = "0", t.style.left = "0", t.style.width = "auto", t.style.height = "auto"), e ? requestAnimationFrame(() => requestAnimationFrame(() => {
768
- b(), l(), u();
769
- })) : (_(), l(), u());
770
- }, S = n(() => ({
1148
+ function ve(e) {
1149
+ let { viewerRef: t, renderer: r, zoomSpeed: i, theme: a, onViewChanged: o } = e, s = n(() => ({
771
1150
  width: "100%",
772
1151
  height: "100%",
773
- background: c.value === "dark" ? "#1e1e1e" : "#ffffff",
1152
+ background: a.value === "dark" ? "#000000" : "#ffffff",
774
1153
  overflow: "hidden",
775
- borderRadius: "8px",
776
- border: c.value === "dark" ? "1px solid #374151" : "1px solid #e2e8f0",
777
1154
  position: "relative",
778
1155
  touchAction: "none",
779
1156
  display: "block"
780
- })), C = h(!1), w = 0, T = 0, E = 0, D = 0, O = null, k = null, ee = (e) => {
781
- e.button === 0 && (C.value = !0, w = e.clientX, T = e.clientY, E = d, D = f, O = (e) => {
782
- if (!C.value) return;
783
- let { ntx: t, nty: n } = y(E + e.clientX - w, D + e.clientY - T);
784
- d = t, f = n, _();
785
- }, k = () => {
786
- C.value = !1, window.removeEventListener("mousemove", O), window.removeEventListener("mouseup", k), O = null, k = null;
787
- }, window.addEventListener("mousemove", O), window.addEventListener("mouseup", k), e.preventDefault());
788
- }, A = () => {
789
- C.value = !1, O &&= (window.removeEventListener("mousemove", O), null), k &&= (window.removeEventListener("mouseup", k), null);
790
- }, j = (e, t) => {
791
- g = e;
792
- let n = m, r = d, i = f, { w: a, h: s } = v();
793
- o(t).then(() => {
794
- if (g !== e) return;
795
- g = null;
796
- let o = e / t, { w: c, h } = v(), b = a * n, x = s * n, S = c * o, C = h * o;
797
- d = r + (b - S) / 2, f = i + (x - C) / 2, p = t, m = o;
798
- let { ntx: w, nty: T } = y(d, f);
799
- d = w, f = T, _(), l(), u();
800
- });
801
- }, M = null, te = (e) => {
802
- e.preventDefault();
803
- let n = t.value;
804
- if (!n) return;
805
- let r = e.deltaY < 0 ? "in" : "out", i = Math.max(1, s ?? 1), a = p * m, o = Math.round(a * 100);
806
- for (let e = 0; e < i; e++) {
807
- let e = P(o, r);
808
- if (e === o) break;
809
- o = e;
810
- }
811
- let c = o / 100;
812
- if (Math.abs(c - a) < .001) return;
813
- let l = n.getBoundingClientRect(), u = e.clientX - l.left, h = e.clientY - l.top, g = c / a;
814
- d = u - (u - d) * g, f = h - (h - f) * g, m = c / p;
815
- let { ntx: v, nty: b } = y(d, f);
816
- d = v, f = b, _(), M !== null && cancelAnimationFrame(M), M = requestAnimationFrame(() => {
817
- M = null;
818
- let e = Z() ? Math.min(c, 8) : c;
819
- j(c, e);
820
- });
821
- }, F = 0, I = 0, L = 0, R = 0, z = !1, B = 0, V = 0, H = 0, U = 0, W = null, G = 0, K = null;
822
- return {
823
- containerStyle: S,
824
- adjustLayout: x,
825
- handleWheel: te,
826
- handleTouchStart: (e) => {
827
- e.touches.length === 1 ? (z = !0, F = e.touches[0].clientX, I = e.touches[0].clientY, L = d, R = f, B = 0, W = null) : e.touches.length === 2 && (z = !1, K !== null && (clearTimeout(K), K = null), B = J(e.touches), V = p * m, W = Y(e.touches), H = d, U = f, G = V);
828
- },
829
- handleTouchMove: (e) => {
830
- if (e.preventDefault(), e.touches.length === 1 && z) {
831
- let t = e.touches[0].clientX - F, n = e.touches[0].clientY - I, { ntx: r, nty: i } = y(L + t, R + n);
832
- d = r, f = i, _();
833
- } else if (e.touches.length === 2 && B > 0 && W) {
834
- let n = t.value;
835
- if (!n) return;
836
- let r = J(e.touches), i = Y(e.touches);
837
- if (Math.abs(r - B) < 1) return;
838
- let a = q(r / B * V, N[0] / 100, N[N.length - 1] / 100);
839
- G = a;
840
- let o = n.getBoundingClientRect(), s = W.x - o.left, c = W.y - o.top, l = a / V, u = i.x - W.x, h = i.y - W.y, g = s - (s - H) * l + u, v = c - (c - U) * l + h;
841
- m = a / p;
842
- let { ntx: b, nty: x } = y(g, v);
843
- d = b, f = x, _(), Z() || (K !== null && clearTimeout(K), K = setTimeout(() => {
844
- K = null;
845
- let e = X(Math.round(G * 100)) / 100;
846
- j(e, e);
847
- }, 300));
1157
+ })), c = (e = !1) => {
1158
+ let t = r.value;
1159
+ t && (t.refreshStageBox(), e && t.centerOnContent(), t.requestRender(), o?.());
1160
+ }, l = h(!1), u = /* @__PURE__ */ new Map(), d = null, f = null, p = (e, t) => Math.hypot(e.x - t.x, e.y - t.y), m = (e, t) => ({
1161
+ x: (e.x + t.x) / 2,
1162
+ y: (e.y + t.y) / 2
1163
+ }), g = (e) => {
1164
+ try {
1165
+ t.value?.setPointerCapture?.(e);
1166
+ } catch {}
1167
+ }, _ = (e) => {
1168
+ try {
1169
+ t.value?.releasePointerCapture?.(e);
1170
+ } catch {}
1171
+ }, v = () => {
1172
+ f = null;
1173
+ }, y = (e) => {
1174
+ let t = r.value;
1175
+ if (t && !(e.pointerType === "mouse" && e.button !== 0)) {
1176
+ if (u.set(e.pointerId, {
1177
+ x: e.clientX,
1178
+ y: e.clientY
1179
+ }), g(e.pointerId), u.size === 1) {
1180
+ d = {
1181
+ id: e.pointerId,
1182
+ sx: e.clientX,
1183
+ sy: e.clientY
1184
+ }, l.value = !0, e.preventDefault();
1185
+ return;
848
1186
  }
849
- },
850
- handleTouchEnd: (e) => {
851
- let t = e.touches.length;
852
- if (t === 0) {
853
- if (B > 0 && G > 0) {
854
- let e = X(Math.round(G * 100)) / 100, t = Z() ? Math.min(e, 8) : e;
855
- K !== null && (clearTimeout(K), K = null), j(e, t);
856
- }
857
- z = !1, B = 0, W = null, G = 0;
858
- } else if (t === 1) {
859
- if (B > 0 && G > 0) {
860
- let e = X(Math.round(G * 100)) / 100, t = Z() ? Math.min(e, 8) : e;
861
- K !== null && (clearTimeout(K), K = null), j(e, t);
1187
+ if (u.size === 2) {
1188
+ if (d) {
1189
+ let e = u.get(d.id);
1190
+ e && t.commitDrag(e.x - d.sx, e.y - d.sy), d = null, l.value = !1;
862
1191
  }
863
- z = !0, B = 0, W = null, G = 0, F = e.touches[0].clientX, I = e.touches[0].clientY, L = d, R = f;
1192
+ let [n, r] = [...u.values()], i = m(n, r);
1193
+ f = {
1194
+ dist: Math.max(1, p(n, r)),
1195
+ zoom: t.zoom,
1196
+ pt: t.screenToPt(i.x, i.y)
1197
+ }, e.preventDefault();
864
1198
  }
1199
+ }
1200
+ }, b = (e) => {
1201
+ let t = r.value;
1202
+ if (!(!t || !u.has(e.pointerId))) {
1203
+ if (u.set(e.pointerId, {
1204
+ x: e.clientX,
1205
+ y: e.clientY
1206
+ }), u.size >= 2 && f) {
1207
+ let [n, r] = [...u.values()], i = m(n, r), a = f.zoom * p(n, r) / f.dist;
1208
+ t.anchorAt(i.x, i.y, f.pt, a), e.preventDefault();
1209
+ return;
1210
+ }
1211
+ d && e.pointerId === d.id && (t.setDragOffset(e.clientX - d.sx, e.clientY - d.sy), e.preventDefault());
1212
+ }
1213
+ }, x = (e) => {
1214
+ let t = r.value;
1215
+ if (u.delete(e.pointerId), _(e.pointerId), t && (f && u.size < 2 && v(), d && e.pointerId === d.id && (t.commitDrag(e.clientX - d.sx, e.clientY - d.sy), d = null, l.value = !1, o?.()), !d && u.size === 1)) {
1216
+ let [e, t] = [...u.entries()][0];
1217
+ d = {
1218
+ id: e,
1219
+ sx: t.x,
1220
+ sy: t.y
1221
+ }, l.value = !0;
1222
+ }
1223
+ };
1224
+ return {
1225
+ containerStyle: s,
1226
+ adjustLayout: c,
1227
+ handleWheel: (e) => {
1228
+ let t = r.value;
1229
+ if (!t) return;
1230
+ e.preventDefault();
1231
+ let n = Math.max(1, Math.round(i || 1)), a = (e.deltaY < 0 ? 1.12 : 1 / 1.12) ** n;
1232
+ t.zoomAt(e.clientX, e.clientY, a), o?.();
865
1233
  },
866
- handleMouseDown: ee,
867
- isMouseDragging: C,
868
- cleanupMouseDrag: A
1234
+ handlePointerDown: y,
1235
+ handlePointerMove: b,
1236
+ handlePointerUp: x,
1237
+ handlePointerCancel: (e) => {
1238
+ u.has(e.pointerId) ? x(e) : u.delete(e.pointerId);
1239
+ },
1240
+ isMouseDragging: l,
1241
+ cleanupMouseDrag: () => {
1242
+ u.clear(), d = null, v(), l.value = !1;
1243
+ }
869
1244
  };
870
1245
  }
871
1246
  //#endregion
872
1247
  //#region src/types/tools.ts
873
- var ie = {
1248
+ var ye = {
874
1249
  mode: "none",
875
1250
  measureSubType: "distance"
876
- }, Q = class {
1251
+ }, G = class {
877
1252
  constructor(e) {
878
1253
  this.TOOLNAME = "measure", this._active = !1, this._isStart = !1, this._isEnd = !1, this._isMeasuring = !1, this._isDragging = !1, this._startPoint = null, this._endPoint = null, this._points = [], this._measureList = /* @__PURE__ */ new Map(), this._dragStart = null, this._dragThreshold = 3, this.coordProvider = e.coordProvider, this.calibration = e.calibration ?? {
879
1254
  scale: 1,
@@ -958,7 +1333,7 @@ var ie = {
958
1333
  destroy() {
959
1334
  this._measureList.clear(), this.resetState(), this._active = !1;
960
1335
  }
961
- }, ae = class extends Q {
1336
+ }, K = class extends G {
962
1337
  constructor(e) {
963
1338
  super(e), this.currentType = "distance", this._previewEnd = null;
964
1339
  }
@@ -1010,7 +1385,7 @@ var ie = {
1010
1385
  interrupt() {
1011
1386
  this._previewEnd = null, super.interrupt();
1012
1387
  }
1013
- }, oe = class extends Q {
1388
+ }, q = class extends G {
1014
1389
  constructor(e) {
1015
1390
  super(e), this.currentType = "angle", this._secondPoint = null, this._thirdPoint = null;
1016
1391
  }
@@ -1040,7 +1415,7 @@ var ie = {
1040
1415
  let u = Math.max(-1, Math.min(1, s / (c * l)));
1041
1416
  return parseFloat((Math.acos(u) * 180 / Math.PI).toFixed(2));
1042
1417
  }
1043
- }, se = class extends Q {
1418
+ }, J = class extends G {
1044
1419
  constructor(e) {
1045
1420
  super(e), this.currentType = "area";
1046
1421
  }
@@ -1068,7 +1443,7 @@ var ie = {
1068
1443
  }
1069
1444
  return Math.abs(t) / 2;
1070
1445
  }
1071
- }, $ = class {
1446
+ }, Y = class {
1072
1447
  get currentType() {
1073
1448
  return this._currentSubType;
1074
1449
  }
@@ -1077,7 +1452,7 @@ var ie = {
1077
1452
  this._isCreating = !0;
1078
1453
  }, this._onMeasureCreated = (e) => {
1079
1454
  this._isCreating = !1, this._resultList.set(e.result.id, e.result);
1080
- }, this.events = e.eventTrigger ?? new z();
1455
+ }, this.events = e.eventTrigger ?? new H();
1081
1456
  let t = {
1082
1457
  coordProvider: e.coordProvider,
1083
1458
  calibration: e.calibration ?? {
@@ -1087,7 +1462,7 @@ var ie = {
1087
1462
  },
1088
1463
  eventTrigger: this.events
1089
1464
  };
1090
- this.distanceMeasure = new ae(t), this.angleMeasure = new oe(t), this.areaMeasure = new se(t), this._subTools = /* @__PURE__ */ new Map([
1465
+ this.distanceMeasure = new K(t), this.angleMeasure = new q(t), this.areaMeasure = new J(t), this._subTools = /* @__PURE__ */ new Map([
1091
1466
  ["distance", this.distanceMeasure],
1092
1467
  ["angle", this.angleMeasure],
1093
1468
  ["area", this.areaMeasure]
@@ -1157,9 +1532,9 @@ var ie = {
1157
1532
  for (let e of this._subTools.values()) e.destroy();
1158
1533
  this._subTools.clear(), this._resultList.clear(), this._active = !1;
1159
1534
  }
1160
- }, ce = class {
1535
+ }, X = class {
1161
1536
  constructor(e) {
1162
- this._activeTool = null, this._activeMode = "none", this._tools = /* @__PURE__ */ new Map(), this.events = new z(), this.measureTool = new $({
1537
+ this._activeTool = null, this._activeMode = "none", this._tools = /* @__PURE__ */ new Map(), this.events = new H(), this.measureTool = new Y({
1163
1538
  coordProvider: e.coordProvider,
1164
1539
  calibration: e.calibration,
1165
1540
  eventTrigger: this.events
@@ -1207,8 +1582,8 @@ var ie = {
1207
1582
  };
1208
1583
  //#endregion
1209
1584
  //#region src/components/useViewerManager.ts
1210
- function le(e) {
1211
- let { drawAnnotations: t, currentScale: n, setScale: r, viewerRef: i, adjustLayout: a, screenToScene: o, toggleTheme: s } = e, c = new ce({ coordProvider: {
1585
+ function be(e) {
1586
+ let { drawAnnotations: t, currentScale: n, setScale: r, viewerRef: i, adjustLayout: a, screenToScene: o, toggleTheme: s } = e, c = new X({ coordProvider: {
1212
1587
  screenToScene: o,
1213
1588
  sceneToScreen: (e) => ({
1214
1589
  x: 0,
@@ -1275,7 +1650,7 @@ function le(e) {
1275
1650
  toggleTheme: () => {
1276
1651
  s();
1277
1652
  }
1278
- }, o = new F();
1653
+ }, o = new z();
1279
1654
  o.registerWithToolManager(c, t, e), window.pdfViewer = o;
1280
1655
  },
1281
1656
  unregisterManager: () => {
@@ -1285,10 +1660,10 @@ function le(e) {
1285
1660
  }
1286
1661
  //#endregion
1287
1662
  //#region src/components/MobileConsole.vue?vue&type=script&setup=true&lang.ts
1288
- var ue = { class: "mobile-console__title" }, de = { class: "mobile-console__count" }, fe = { class: "mobile-console__actions" }, pe = { class: "mobile-console__toggle" }, me = { class: "mobile-console__level" }, he = { class: "mobile-console__msg" }, ge = {
1663
+ var xe = { class: "mobile-console__title" }, Se = { class: "mobile-console__count" }, Ce = { class: "mobile-console__actions" }, Z = { class: "mobile-console__toggle" }, we = { class: "mobile-console__level" }, Q = { class: "mobile-console__msg" }, Te = {
1289
1664
  key: 0,
1290
1665
  class: "mobile-console__empty"
1291
- }, _e = /*@__PURE__*/ c({
1666
+ }, Ee = /*@__PURE__*/ c({
1292
1667
  __name: "MobileConsole",
1293
1668
  props: {
1294
1669
  visible: {
@@ -1318,7 +1693,7 @@ var ue = { class: "mobile-console__title" }, de = { class: "mobile-console__coun
1318
1693
  });
1319
1694
  let w = () => {
1320
1695
  s.value = [];
1321
- }, T = async () => {
1696
+ }, ee = async () => {
1322
1697
  let e = s.value.map((e) => `[${e.level.toUpperCase()}] ${e.message}`).join("\n");
1323
1698
  if (e) try {
1324
1699
  await navigator.clipboard.writeText(e);
@@ -1326,7 +1701,7 @@ var ue = { class: "mobile-console__title" }, de = { class: "mobile-console__coun
1326
1701
  let t = document.createElement("textarea");
1327
1702
  t.value = e, t.style.position = "fixed", t.style.left = "-9999px", document.body.appendChild(t), t.select(), document.execCommand("copy"), document.body.removeChild(t);
1328
1703
  }
1329
- }, E = () => {
1704
+ }, T = () => {
1330
1705
  c.value = !c.value, c.value || l(() => {
1331
1706
  d.value && (d.value.scrollTop = d.value.scrollHeight);
1332
1707
  });
@@ -1342,8 +1717,8 @@ var ue = { class: "mobile-console__title" }, de = { class: "mobile-console__coun
1342
1717
  class: u(["mobile-console", { collapsed: c.value }])
1343
1718
  }, [a("div", {
1344
1719
  class: "mobile-console__header",
1345
- onClick: E
1346
- }, [a("span", ue, [l[0] ||= o(" 📟 Console ", -1), a("span", de, v(s.value.length), 1)]), a("span", fe, [
1720
+ onClick: T
1721
+ }, [a("span", xe, [l[0] ||= o(" 📟 Console ", -1), a("span", Se, v(s.value.length), 1)]), a("span", Ce, [
1347
1722
  a("button", {
1348
1723
  class: "mobile-console__btn",
1349
1724
  title: "清空",
@@ -1352,9 +1727,9 @@ var ue = { class: "mobile-console__title" }, de = { class: "mobile-console__coun
1352
1727
  a("button", {
1353
1728
  class: "mobile-console__btn",
1354
1729
  title: "复制全部",
1355
- onClick: C(T, ["stop"])
1730
+ onClick: C(ee, ["stop"])
1356
1731
  }, "📋"),
1357
- a("span", pe, v(c.value ? "▲" : "▼"), 1)
1732
+ a("span", Z, v(c.value ? "▲" : "▼"), 1)
1358
1733
  ])]), S(a("div", {
1359
1734
  ref_key: "logListRef",
1360
1735
  ref: d,
@@ -1362,13 +1737,13 @@ var ue = { class: "mobile-console__title" }, de = { class: "mobile-console__coun
1362
1737
  }, [(m(!0), i(t, null, g(s.value, (e, t) => (m(), i("div", {
1363
1738
  key: t,
1364
1739
  class: u(["mobile-console__entry", "mobile-console__entry--" + e.level])
1365
- }, [a("span", me, v(e.level.toUpperCase()), 1), a("span", he, v(e.message), 1)], 2))), 128)), s.value.length === 0 ? (m(), i("div", ge, "暂无日志")) : r("", !0)], 512), [[b, !c.value]])], 2)) : r("", !0);
1740
+ }, [a("span", we, v(e.level.toUpperCase()), 1), a("span", Q, v(e.message), 1)], 2))), 128)), s.value.length === 0 ? (m(), i("div", Te, "暂无日志")) : r("", !0)], 512), [[b, !c.value]])], 2)) : r("", !0);
1366
1741
  }
1367
- }), ve = (e, t) => {
1742
+ }), $ = (e, t) => {
1368
1743
  let n = e.__vccOpts || e;
1369
1744
  for (let [e, r] of t) n[e] = r;
1370
1745
  return n;
1371
- }, ye = /*#__PURE__*/ ve(_e, [["__scopeId", "data-v-ef8b578a"]]), be = /*#__PURE__*/ ve(/* @__PURE__ */ c({
1746
+ }, De = /*#__PURE__*/ $(Ee, [["__scopeId", "data-v-ef8b578a"]]), Oe = /*#__PURE__*/ $(/* @__PURE__ */ c({
1372
1747
  __name: "PdfViewer",
1373
1748
  props: {
1374
1749
  modelValue: { default: null },
@@ -1381,6 +1756,13 @@ var ue = { class: "mobile-console__title" }, de = { class: "mobile-console__coun
1381
1756
  default: !1
1382
1757
  },
1383
1758
  zoomSpeed: { default: 1 },
1759
+ invertDarkContent: {
1760
+ type: Boolean,
1761
+ default: !0
1762
+ },
1763
+ invertMode: { default: "unblend" },
1764
+ invertThreshold: { default: 24 },
1765
+ maxZoom: { default: 128 },
1384
1766
  showConsole: {
1385
1767
  type: Boolean,
1386
1768
  default: !1
@@ -1392,118 +1774,140 @@ var ue = { class: "mobile-console__title" }, de = { class: "mobile-console__coun
1392
1774
  "annotation-added"
1393
1775
  ],
1394
1776
  setup(e, { expose: t, emit: r }) {
1395
- let o = e, c = r, u = h(null), g = h(null), _ = h(null), v = h(null), b = h(o.theme), S = n(() => b.value === "dark" ? "#1e1e1e" : "rgb(255,255,255)"), w = () => {
1777
+ let o = e, c = r, u = h(null), g = h(null), _ = h(null), v = h(null), b = h(o.theme), S = n(() => b.value === "dark" ? "#000000" : "rgb(255,255,255)"), C = n(() => b.value === "dark" && o.invertDarkContent !== !1), w = () => {
1396
1778
  b.value = b.value === "light" ? "dark" : "light";
1397
- }, { containerRef: T, loadFile: E, doc: D, pageCount: O, currentPageNum: k, error: ee, currentScale: A, setScale: j, setBackgroundColor: M, reset: te, events: N } = V({
1779
+ }, { containerRef: ee, renderer: T, loadFile: E, doc: te, pageCount: ne, currentPageNum: re, error: ie, currentScale: D, setScale: O, setBackgroundColor: ae, setInvertColors: oe, setInvertMode: se, setMaxZoom: ce, reset: k, resetView: le, attach: A, detach: j, events: M } = pe({
1398
1780
  autoLoad: !1,
1399
1781
  scale: o.scale,
1400
- backgroundColor: S.value
1401
- }), P = G(), F = h(null), I = h(!1), { drawAnnotations: L, syncCanvasSize: R, getCanvasPoint: z, hitTestAnnotation: B } = K({
1782
+ backgroundColor: S.value,
1783
+ invertColors: C.value,
1784
+ invertMode: o.invertMode,
1785
+ invertThreshold: o.invertThreshold,
1786
+ maxZoom: o.maxZoom,
1787
+ onPresented: () => ue()
1788
+ });
1789
+ function ue() {
1790
+ I(), F();
1791
+ }
1792
+ let N = he(), P = h(null), de = h(!1), { drawAnnotations: F, syncCanvasSize: I, getCanvasPoint: L, hitTestAnnotation: R } = ge({
1402
1793
  annotationCanvas: v,
1403
1794
  rootRef: g,
1404
- pdfLayerRef: _,
1405
- interaction: P,
1406
- previewPoint: F
1407
- }), { containerStyle: H, adjustLayout: U, handleWheel: W, handleTouchStart: q, handleTouchMove: J, handleTouchEnd: Y, handleMouseDown: X, isMouseDragging: Z, cleanupMouseDrag: ie } = re({
1795
+ pdfLayerRef: g,
1796
+ interaction: N,
1797
+ previewPoint: P
1798
+ }), { containerStyle: z, adjustLayout: B, handleWheel: V, handlePointerDown: fe, handlePointerMove: H, handlePointerUp: U, handlePointerCancel: W, isMouseDragging: me, cleanupMouseDrag: ye } = ve({
1408
1799
  viewerRef: u,
1409
- rootRef: g,
1410
- pdfLayerRef: _,
1411
- currentScale: A,
1412
- setScale: j,
1800
+ renderer: T,
1413
1801
  zoomSpeed: o.zoomSpeed ?? 1,
1414
- theme: b,
1415
- syncCanvasSize: R,
1416
- drawAnnotations: L
1417
- }), Q = (e) => {
1418
- P.mode === "none" && X(e);
1419
- }, ae = n(() => ({
1420
- ...H.value,
1421
- cursor: Z.value ? "grabbing" : "grab"
1422
- })), { setMode: oe, clearInteraction: se, deleteSelectedAnnotation: $, selectAnnotation: ce, registerManager: ue, unregisterManager: de } = le({
1423
- drawAnnotations: L,
1424
- currentScale: A,
1425
- setScale: j,
1802
+ theme: b
1803
+ }), G = (e) => {
1804
+ N.mode === "none" && fe(e);
1805
+ }, K = n(() => ({
1806
+ ...z.value,
1807
+ cursor: me.value ? "grabbing" : "grab"
1808
+ })), { setMode: q, clearInteraction: J, deleteSelectedAnnotation: Y, selectAnnotation: X, registerManager: xe, unregisterManager: Se } = be({
1809
+ drawAnnotations: F,
1810
+ currentScale: D,
1811
+ setScale: O,
1426
1812
  viewerRef: u,
1427
- adjustLayout: U,
1813
+ adjustLayout: B,
1428
1814
  screenToScene: (e) => {
1429
- let t = z(e);
1815
+ let t = L(e);
1430
1816
  return {
1431
1817
  x: t.x,
1432
1818
  y: t.y
1433
1819
  };
1434
1820
  },
1435
1821
  toggleTheme: w
1436
- }), { handlePointerDown: fe, handlePointerMove: pe, handlePointerUp: me, handleKeydown: he } = ne({
1822
+ }), { handlePointerDown: Ce, handlePointerMove: Z, handlePointerUp: we, handleKeydown: Q } = _e({
1437
1823
  annotationCanvas: v,
1438
- interaction: P,
1439
- previewPoint: F,
1440
- isRectangleDragging: I,
1441
- getCanvasPoint: z,
1442
- hitTestAnnotation: B,
1443
- drawAnnotations: L,
1444
- deleteSelectedAnnotation: $,
1824
+ interaction: N,
1825
+ previewPoint: P,
1826
+ isRectangleDragging: de,
1827
+ getCanvasPoint: L,
1828
+ hitTestAnnotation: R,
1829
+ drawAnnotations: F,
1830
+ deleteSelectedAnnotation: Y,
1445
1831
  emit: c
1446
- });
1447
- return N.on("loaded", (e) => {
1832
+ }), Te = async (e) => {
1833
+ await E(e);
1834
+ }, Ee = () => {
1835
+ k();
1836
+ };
1837
+ M.on("loaded", (e) => {
1448
1838
  c("loaded", {
1449
1839
  pageCount: e.pageCount,
1450
1840
  currentPage: e.currentPage
1451
1841
  });
1452
- }), N.on("error_occurred", (e) => {
1842
+ }), M.on("error_occurred", (e) => {
1453
1843
  c("error", { message: e.message });
1454
- }), x(() => P.annotations.length, () => {
1455
- L();
1844
+ }), x(() => N.annotations.length, () => {
1845
+ F();
1456
1846
  }), x(() => o.scale, async (e) => {
1457
- e && e !== A.value && (await j(e), await l(), U());
1847
+ e && e !== D.value && (await O(e), await l(), B());
1458
1848
  }), x(() => o.modelValue, async (e) => {
1459
- e && (await E(e), await l(), U(!0));
1849
+ e && (await E(e), await l(), B(!0));
1460
1850
  }, {
1461
1851
  immediate: !0,
1462
1852
  flush: "post"
1463
- }), x(b, async (e) => {
1464
- await M(e === "dark" ? "#1e1e1e" : "rgb(255,255,255)");
1465
- }), p(() => {
1466
- T.value = _.value, g.value && (g.value.style.position = "absolute", g.value.style.top = "0", g.value.style.left = "0"), R(), L(), window.addEventListener("keydown", he), ue(), u.value && (u.value.addEventListener("touchstart", q, { passive: !1 }), u.value.addEventListener("touchmove", J, { passive: !1 }), u.value.addEventListener("touchend", Y, { passive: !1 }));
1853
+ }), x([b, C], async () => {
1854
+ oe(C.value), await ae(S.value);
1855
+ }), x([() => o.invertMode, () => o.invertThreshold], () => {
1856
+ se(o.invertMode ?? "unblend", o.invertThreshold);
1857
+ }), x(() => o.maxZoom, (e) => {
1858
+ e && e > 0 && ce(e);
1859
+ });
1860
+ let $ = null;
1861
+ return p(() => {
1862
+ A({
1863
+ canvas: _.value,
1864
+ stage: u.value,
1865
+ wrap: g.value
1866
+ }), I(), F(), window.addEventListener("keydown", Q), xe(), $ = new ResizeObserver(() => {
1867
+ T.value?.refreshStageBox(), T.value?.requestRender();
1868
+ }), u.value && $.observe(u.value);
1467
1869
  }), f(() => {
1468
- window.removeEventListener("keydown", he), ie(), u.value && (u.value.removeEventListener("touchstart", q), u.value.removeEventListener("touchmove", J), u.value.removeEventListener("touchend", Y)), de();
1870
+ $?.disconnect(), $ = null, window.removeEventListener("keydown", Q), ye(), Se(), j();
1469
1871
  }), t({
1470
- load: async (e) => {
1471
- await E(e);
1472
- },
1473
- clear: () => {
1474
- te();
1475
- },
1476
- setMode: oe,
1477
- clearInteraction: se,
1478
- deleteSelectedAnnotation: $,
1479
- selectAnnotation: ce
1872
+ load: Te,
1873
+ clear: Ee,
1874
+ setMode: q,
1875
+ clearInteraction: J,
1876
+ deleteSelectedAnnotation: Y,
1877
+ selectAnnotation: X,
1878
+ resetView: le,
1879
+ zoomIn: () => O(T.value ? T.value.zoom * 1.25 : D.value),
1880
+ zoomOut: () => O(T.value ? T.value.zoom / 1.25 : D.value)
1480
1881
  }), (t, n) => (m(), i("div", {
1481
1882
  ref_key: "viewerRef",
1482
1883
  ref: u,
1483
1884
  class: "pdf-core-viewer",
1484
- style: d(ae.value),
1485
- onWheel: n[3] ||= C((...e) => y(W) && y(W)(...e), ["prevent"]),
1486
- onMousedown: Q
1885
+ style: d(K.value),
1886
+ onWheel: n[3] ||= (...e) => y(V) && y(V)(...e),
1887
+ onPointerdown: G,
1888
+ onPointermove: n[4] ||= (...e) => y(H) && y(H)(...e),
1889
+ onPointerup: n[5] ||= (...e) => y(U) && y(U)(...e),
1890
+ onPointercancel: n[6] ||= (...e) => y(W) && y(W)(...e)
1487
1891
  }, [a("div", {
1488
1892
  ref_key: "rootRef",
1489
1893
  ref: g,
1490
- class: "pdf-core-canvas-wrapper"
1491
- }, [a("div", {
1492
- ref_key: "pdfLayerRef",
1894
+ class: "pdf-core-content"
1895
+ }, [a("canvas", {
1896
+ ref_key: "pageCanvas",
1493
1897
  ref: _,
1494
- class: "pdf-core-pdf-layer"
1898
+ class: "pdf-core-page-canvas"
1495
1899
  }, null, 512), a("div", {
1496
1900
  class: "pdf-core-overlay",
1497
- onPointerdown: n[0] ||= (...e) => y(fe) && y(fe)(...e),
1498
- onPointerup: n[1] ||= (...e) => y(me) && y(me)(...e),
1499
- onPointermove: n[2] ||= (...e) => y(pe) && y(pe)(...e)
1500
- }, null, 32)], 512), s(ye, { visible: e.showConsole }, null, 8, ["visible"])], 36));
1901
+ onPointerdown: n[0] ||= (...e) => y(Ce) && y(Ce)(...e),
1902
+ onPointerup: n[1] ||= (...e) => y(we) && y(we)(...e),
1903
+ onPointermove: n[2] ||= (...e) => y(Z) && y(Z)(...e)
1904
+ }, null, 32)], 512), s(De, { visible: e.showConsole }, null, 8, ["visible"])], 36));
1501
1905
  }
1502
- }), [["__scopeId", "data-v-58f287f7"]]);
1906
+ }), [["__scopeId", "data-v-dc25679e"]]);
1503
1907
  //#endregion
1504
1908
  //#region src/vue/plugin.ts
1505
- function xe(e) {
1506
- e.component("PdfViewer", be);
1909
+ function ke(e) {
1910
+ e.component("PdfViewer", Oe);
1507
1911
  }
1508
1912
  //#endregion
1509
- export { oe as AngleMeasure, se as AreaMeasure, te as CoordTransformer, ie as DEFAULT_TOOL_STATE, ae as DistanceMeasure, z as EventTrigger, Q as MeasureBase, $ as MeasureTool, be as PdfViewer, F as PdfViewerCore, D as TileLRUCache, ce as ToolManager, N as ZOOM_LEVELS, I as createMeasureAnnotation, L as createShapeAnnotation, P as getNextZoom, xe as installPdfCore, E as loadPDF, M as renderPageTiledVirtual, w as setPDFWorkerSrc, H as useAnnotations, T as useDefaultWorker, W as useInteraction, U as useMeasurement, V as usePdfCore };
1913
+ export { q as AngleMeasure, J as AreaMeasure, O as ColorInverter, I as CoordTransformer, ne as DEFAULT_ACHROMATIC_THRESHOLD, ye as DEFAULT_TOOL_STATE, K as DistanceMeasure, H as EventTrigger, E as INVERT_FILTER_ALL, te as INVERT_FILTER_HUE, G as MeasureBase, Y as MeasureTool, A as PageCanvasRenderer, Oe as PdfViewer, z as PdfViewerCore, j as TileLRUCache, X as ToolManager, L as ZOOM_LEVELS, B as createMeasureAnnotation, V as createShapeAnnotation, R as getNextZoom, ke as installPdfCore, T as loadPDF, F as renderPageTiledVirtual, w as setPDFWorkerSrc, U as useAnnotations, ee as useDefaultWorker, me as useInteraction, W as useMeasurement, pe as usePdfCore };