@xtctwins/tctwins-pdf-core 0.1.1 → 0.1.3

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
@@ -20,8 +20,413 @@ 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 D = "invert(1)", ee = "invert(1) hue-rotate(180deg)", te = 24, ne = "\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}", re = "\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}", O = (e, t, n) => Math.max(t, Math.min(n, e)), k = 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, ne), e.compileShader(t), e.shaderSource(n, re), 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, O(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
+ }, ie = 8192, ae = 1.25, oe = .05, se = 128, A = (e, t, n) => Math.max(t, Math.min(n, e)), ce = (e, t) => {
109
+ if (e === t) return !0;
110
+ let n = (e) => {
111
+ let t = (e || "").trim().toLowerCase(), n = /^#([0-9a-f]{3})$/.exec(t);
112
+ return n ? `#${n[1][0]}${n[1][0]}${n[1][1]}${n[1][1]}${n[1][2]}${n[1][2]}` : (n = /^#([0-9a-f]{6})$/.exec(t), n ? `#${n[1]}` : (n = /^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/.exec(t), n ? `#${[
113
+ n[1],
114
+ n[2],
115
+ n[3]
116
+ ].map((e) => (+e).toString(16).padStart(2, "0")).join("")}` : t));
117
+ };
118
+ return n(e) === n(t);
119
+ }, le = (() => {
120
+ try {
121
+ let e = document.createElement("canvas").getContext("2d");
122
+ return e ? (e.filter = "invert(1)", e.filter === "invert(1)") : !1;
123
+ } catch {
124
+ return !1;
125
+ }
126
+ })(), j = class {
127
+ constructor(e) {
128
+ this.doc = null, this.page = null, this.pageW = 0, this.pageH = 0, this.inkCenter = {
129
+ x: 0,
130
+ y: 0
131
+ }, this.zoomValue = 1, this.centerValue = {
132
+ x: 0,
133
+ y: 0
134
+ }, this.presentedValue = {
135
+ zoom: 1,
136
+ center: {
137
+ x: 0,
138
+ y: 0
139
+ },
140
+ region: {
141
+ x: 0,
142
+ y: 0,
143
+ w: 0,
144
+ h: 0,
145
+ tiled: !1
146
+ },
147
+ offset: {
148
+ x: 0,
149
+ y: 0
150
+ }
151
+ }, this.unpresented = {
152
+ x: 0,
153
+ y: 0
154
+ }, this.dragExtra = {
155
+ x: 0,
156
+ y: 0
157
+ }, this.seq = 0, this.task = null, this.rafId = null, this.backgroundColor = "rgb(255,255,255)", this.offFillColor = "", this.invertColorsValue = !1, this.invertModeValue = "unblend", this.invertThresholdValue = 24, this.inverter = new k(), this.destroyed = !1, this.stageBox = {
158
+ left: 0,
159
+ top: 0,
160
+ w: 0,
161
+ h: 0
162
+ }, this.canvas = e.canvas, this.stage = e.stage, this.wrap = e.wrap ?? null, this.dprOf = e.dpr ?? (() => window.devicePixelRatio || 1), this.maxSide = e.maxSide ?? ie, this.prefetch = e.prefetch ?? ae, this.minZoom = e.minZoom ?? oe, this.maxZoomValue = e.maxZoom ?? se, 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;
163
+ let t = this.canvas.getContext("2d");
164
+ if (!t) throw Error("[PDF-CORE] 2d context 不可用");
165
+ this.ctx = t, this.off = document.createElement("canvas");
166
+ let n = this.off.getContext("2d");
167
+ if (!n) throw Error("[PDF-CORE] 离屏 2d context 不可用");
168
+ this.offCtx = n, this.canvas.style.position = "absolute", this.canvas.style.display = "block", this.canvas.style.transformOrigin = "0 0";
169
+ }
170
+ get zoom() {
171
+ return this.zoomValue;
172
+ }
173
+ get center() {
174
+ return { ...this.centerValue };
175
+ }
176
+ get size() {
177
+ return {
178
+ wPt: this.pageW,
179
+ hPt: this.pageH
180
+ };
181
+ }
182
+ get presented() {
183
+ return this.presentedValue;
184
+ }
185
+ get pageRef() {
186
+ return this.page;
187
+ }
188
+ async open(e) {
189
+ this.doc = e, this.page = await e.getPage(1);
190
+ let t = this.page.getViewport({ scale: 1 });
191
+ return this.pageW = t.width, this.pageH = t.height, this.inkCenter = await this.detectInkCenter(this.page), this.centerValue = { ...this.inkCenter }, {
192
+ wPt: this.pageW,
193
+ hPt: this.pageH
194
+ };
195
+ }
196
+ async detectInkCenter(e) {
197
+ let t = {
198
+ x: this.pageW / 2,
199
+ y: this.pageH / 2
200
+ };
201
+ try {
202
+ let n = e.getViewport({ scale: 1 }), r = 220 / Math.max(n.width, n.height), i = e.getViewport({ scale: r }), a = document.createElement("canvas");
203
+ a.width = Math.max(1, Math.floor(i.width)), a.height = Math.max(1, Math.floor(i.height));
204
+ let o = a.getContext("2d", { willReadFrequently: !0 });
205
+ if (!o) return t;
206
+ await e.render({
207
+ canvas: a,
208
+ canvasContext: o,
209
+ viewport: i
210
+ }).promise;
211
+ let s = o.getImageData(0, 0, a.width, a.height).data, c = Infinity, l = Infinity, u = -1, d = -1;
212
+ for (let e = 0; e < a.height; e += 3) for (let t = 0; t < a.width; t += 3) {
213
+ let n = (e * a.width + t) * 4;
214
+ (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));
215
+ }
216
+ return a.width = 0, a.height = 0, u < 0 ? t : {
217
+ x: (c + u) / 2 / r,
218
+ y: (l + d) / 2 / r
219
+ };
220
+ } catch {
221
+ return t;
222
+ }
223
+ }
224
+ destroy() {
225
+ 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;
226
+ }
227
+ unload() {
228
+ 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 = {
229
+ x: 0,
230
+ y: 0
231
+ }, this.dragExtra = {
232
+ x: 0,
233
+ y: 0
234
+ }, this.wrap && (this.wrap.style.width = "0px", this.wrap.style.height = "0px");
235
+ }
236
+ cancel() {
237
+ if (this.task) {
238
+ try {
239
+ this.task.cancel();
240
+ } catch {}
241
+ this.task = null;
242
+ }
243
+ }
244
+ setBackgroundColor(e) {
245
+ this.backgroundColor = e, this.canvas.style.background = e, !(!(!this.invertColorsValue && !ce(e, this.offFillColor)) && this.representCurrentBitmap()) && this.requestRender();
246
+ }
247
+ get invertColors() {
248
+ return this.invertColorsValue;
249
+ }
250
+ get invertMode() {
251
+ return this.invertModeValue;
252
+ }
253
+ setInvertColors(e) {
254
+ e !== this.invertColorsValue && (this.invertColorsValue = e, this.representCurrentBitmap() || this.requestRender());
255
+ }
256
+ setInvertMode(e, t) {
257
+ let n = t ?? this.invertThresholdValue;
258
+ e === this.invertModeValue && n === this.invertThresholdValue || (this.invertModeValue = e, this.invertThresholdValue = n, this.representCurrentBitmap() || this.requestRender());
259
+ }
260
+ get usingWebGLInvert() {
261
+ return this.inverter.usingWebGL;
262
+ }
263
+ get maxZoom() {
264
+ return this.maxZoomValue;
265
+ }
266
+ setMaxZoom(e) {
267
+ !(e > 0) || e === this.maxZoomValue || (this.maxZoomValue = e, this.zoomValue > e && (this.zoomValue = e, this.requestRender()));
268
+ }
269
+ setZoom(e) {
270
+ let t = A(e, this.minZoom, this.maxZoomValue);
271
+ t !== this.zoomValue && (this.zoomValue = t, this.requestRender());
272
+ }
273
+ anchorAt(e, t, n, r) {
274
+ let i = A(r, this.minZoom, this.maxZoomValue);
275
+ this.zoomValue = i;
276
+ let a = this.stageCenterOnScreen();
277
+ this.centerValue = {
278
+ x: n.x - (e - a.x) / i,
279
+ y: n.y - (t - a.y) / i
280
+ }, this.requestRender();
281
+ }
282
+ zoomAt(e, t, n) {
283
+ let r = A(this.zoomValue * n, this.minZoom, this.maxZoomValue);
284
+ if (r === this.zoomValue) return !1;
285
+ let i = this.screenToPt(e, t);
286
+ return this.anchorAt(e, t, i, r), !0;
287
+ }
288
+ setDragOffset(e, t) {
289
+ this.dragExtra = {
290
+ x: e,
291
+ y: t
292
+ }, this.applyBitmapOffset();
293
+ }
294
+ commitDrag(e, t) {
295
+ let n = this.presentedValue.zoom || 1;
296
+ this.centerValue = {
297
+ x: this.centerValue.x - e / n,
298
+ y: this.centerValue.y - t / n
299
+ }, this.unpresented = {
300
+ x: this.unpresented.x + e,
301
+ y: this.unpresented.y + t
302
+ }, this.dragExtra = {
303
+ x: 0,
304
+ y: 0
305
+ }, this.requestRender();
306
+ }
307
+ centerOnContent() {
308
+ this.centerValue = { ...this.inkCenter }, this.requestRender();
309
+ }
310
+ applyBitmapOffset() {
311
+ let e = this.unpresented.x + this.dragExtra.x, t = this.unpresented.y + this.dragExtra.y;
312
+ this.canvas.style.transform = e === 0 && t === 0 ? "" : `translate(${e}px, ${t}px)`;
313
+ }
314
+ screenToPt(e, t) {
315
+ let n = this.presentedValue, r = n.zoom || 1, i = this.stageCenterOnScreen(), a = {
316
+ x: this.unpresented.x + this.dragExtra.x,
317
+ y: this.unpresented.y + this.dragExtra.y
318
+ };
319
+ return {
320
+ x: n.center.x + (e - i.x - a.x) / r,
321
+ y: n.center.y + (t - i.y - a.y) / r
322
+ };
323
+ }
324
+ ptToScreen(e) {
325
+ let t = this.presentedValue, n = t.zoom || 1, r = this.stageCenterOnScreen(), i = {
326
+ x: this.unpresented.x + this.dragExtra.x,
327
+ y: this.unpresented.y + this.dragExtra.y
328
+ };
329
+ return {
330
+ x: r.x + (e.x - t.center.x) * n + i.x,
331
+ y: r.y + (e.y - t.center.y) * n + i.y
332
+ };
333
+ }
334
+ refreshStageBox() {
335
+ let e = this.stage.getBoundingClientRect(), t = this.stage.clientWidth || e.width, n = this.stage.clientHeight || e.height;
336
+ this.stageBox = {
337
+ left: e.left + (e.width - t) / 2,
338
+ top: e.top + (e.height - n) / 2,
339
+ w: t,
340
+ h: n
341
+ };
342
+ }
343
+ stageCenterOnScreen() {
344
+ return {
345
+ x: this.stageBox.left + this.stageBox.w / 2,
346
+ y: this.stageBox.top + this.stageBox.h / 2
347
+ };
348
+ }
349
+ computeRegion() {
350
+ let e = this.dprOf(), t = this.zoomValue * e, n = Math.min(this.maxSide, (this.stageBox.w || 1) * this.prefetch * e), r = Math.min(this.maxSide, (this.stageBox.h || 1) * this.prefetch * e);
351
+ if (this.pageW * t <= n && this.pageH * t <= r) return null;
352
+ let i = (this.stageBox.w || 1) / this.zoomValue * this.prefetch, a = (this.stageBox.h || 1) / this.zoomValue * this.prefetch, o = Math.min(i, this.pageW), s = Math.min(a, this.pageH);
353
+ return {
354
+ x: A(this.centerValue.x - o / 2, 0, Math.max(this.pageW - o, 0)),
355
+ y: A(this.centerValue.y - s / 2, 0, Math.max(this.pageH - s, 0)),
356
+ w: o,
357
+ h: s,
358
+ tiled: !0
359
+ };
360
+ }
361
+ layout(e, t, n) {
362
+ let r = t;
363
+ 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 * r)}px`, this.wrap.style.height = `${Math.round(this.pageH * r)}px`, this.wrap.style.transformOrigin = "0 0", this.wrap.style.transform = `translate(${this.stageBox.w / 2 - n.x * r}px, ${this.stageBox.h / 2 - n.y * r}px)`);
364
+ let i = this.wrap ? 0 : this.stageBox.w / 2 - n.x * r, a = this.wrap ? 0 : this.stageBox.h / 2 - n.y * r;
365
+ this.canvas.style.left = `${i + e.x * r}px`, this.canvas.style.top = `${a + e.y * r}px`, this.canvas.style.width = `${Math.round(e.w * r)}px`, this.canvas.style.height = `${Math.round(e.h * r)}px`, this.unpresented = {
366
+ x: 0,
367
+ y: 0
368
+ }, this.dragExtra = {
369
+ x: 0,
370
+ y: 0
371
+ }, this.canvas.style.transform = "";
372
+ }
373
+ requestRender() {
374
+ this.destroyed || this.rafId !== null || (this.rafId = requestAnimationFrame(() => {
375
+ this.rafId = null, this.render();
376
+ }));
377
+ }
378
+ async render() {
379
+ if (this.destroyed || !this.page || this.pageW <= 0) return;
380
+ let e = ++this.seq;
381
+ this.cancel(), this.refreshStageBox();
382
+ let t = this.zoomValue * this.dprOf(), n = this.computeRegion(), r = n ?? {
383
+ x: 0,
384
+ y: 0,
385
+ w: this.pageW,
386
+ h: this.pageH,
387
+ tiled: !1
388
+ }, i = this.zoomValue, a = { ...this.centerValue }, o = this.page.getViewport({ scale: t });
389
+ n && (o = o.clone({
390
+ offsetX: -n.x * t,
391
+ offsetY: -n.y * t
392
+ }));
393
+ let s = Math.max(1, Math.floor(r.w * t)), c = Math.max(1, Math.floor(r.h * t));
394
+ this.off.width = s, this.off.height = c, this.offCtx.setTransform(1, 0, 0, 1, 0, 0), this.offFillColor = this.invertColorsValue ? "#ffffff" : this.backgroundColor, this.offCtx.fillStyle = this.offFillColor, this.offCtx.fillRect(0, 0, s, c);
395
+ let l = null;
396
+ try {
397
+ l = this.page.render({
398
+ canvas: this.off,
399
+ canvasContext: this.offCtx,
400
+ viewport: o
401
+ }), this.task = l, await l.promise;
402
+ } catch (t) {
403
+ if (e !== this.seq || (t?.name ?? "") === "RenderingCancelledException") return;
404
+ throw t;
405
+ } finally {
406
+ this.task === l && (this.task = null);
407
+ }
408
+ e === this.seq && (this.presentBitmap(s, c), this.presentedValue = {
409
+ zoom: i,
410
+ center: { ...a },
411
+ region: r,
412
+ offset: {
413
+ x: 0,
414
+ y: 0
415
+ }
416
+ }, this.layout(r, i, a), this.onPresented?.(this.presentedValue));
417
+ }
418
+ presentBitmap(e, t) {
419
+ let n = this.invertColorsValue, r = this.invertModeValue, i = n && (r === "unblend" || r === "achromatic"), a = r === "all" ? D : ee, o = n && !i && le;
420
+ this.canvas.width = e, this.canvas.height = t, i ? this.inverter.presentPerPixel(this.off, this.offCtx, this.ctx, e, t, r, this.invertThresholdValue) : (this.ctx.setTransform(1, 0, 0, 1, 0, 0), o && (this.ctx.filter = a), this.ctx.drawImage(this.off, 0, 0), o && (this.ctx.filter = "none")), this.canvas.style.filter = n && !i && !o ? a : "", this.canvas.style.background = this.backgroundColor;
421
+ }
422
+ representCurrentBitmap() {
423
+ if (this.destroyed || !this.page) return !1;
424
+ let e = this.presentedValue, t = this.off.width, n = this.off.height;
425
+ if (!t || !n || this.task || this.unpresented.x !== 0 || this.unpresented.y !== 0 || this.dragExtra.x !== 0 || this.dragExtra.y !== 0 || e.zoom !== this.zoomValue || e.center.x !== this.centerValue.x || e.center.y !== this.centerValue.y) return !1;
426
+ let r = e.zoom * this.dprOf();
427
+ return t !== Math.max(1, Math.floor(e.region.w * r)) || n !== Math.max(1, Math.floor(e.region.h * r)) ? !1 : (this.presentBitmap(t, n), this.onPresented?.(e), !0);
428
+ }
429
+ }, M = class e {
25
430
  constructor(e = 100) {
26
431
  this.cache = /* @__PURE__ */ new Map(), this.capacity = e;
27
432
  }
@@ -57,20 +462,20 @@ var D = class e {
57
462
  get size() {
58
463
  return this.cache.size;
59
464
  }
60
- }, O = () => typeof navigator < "u" && /Mobi|Android|iPhone|iPad/i.test(navigator.userAgent);
61
- function k(e) {
465
+ }, ue = () => typeof navigator < "u" && /Mobi|Android|iPhone|iPad/i.test(navigator.userAgent);
466
+ function N(e) {
62
467
  let t = window.devicePixelRatio ?? 1;
63
468
  return e >= 32 ? 1 : e >= 16 ? Math.min(t, 2) : t;
64
469
  }
65
- function ee(e) {
470
+ function P(e) {
66
471
  return e ? 2048 : 4096;
67
472
  }
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)";
473
+ var de = 4096, F = 128;
474
+ async function I(e, t = {}) {
475
+ let n = t.scale ?? 1.5, r = ue(), i = t.backgroundColor ?? "rgb(255,255,255)";
71
476
  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 将按需渲染。`);
477
+ let a = N(n), o = e.getViewport({ scale: n * a }), s = o.width, c = o.height, l = P(r), u = Math.min(l, de, Math.max(s, c)), d = Math.ceil(s / u), f = Math.ceil(c / u), p = d * f;
478
+ p > F && console.warn(`[PDF-CORE] scale=${n} dpr=${a}, tile=${p} (${d}×${f}), tileSize=${u}px (physical). IntersectionObserver 将按需渲染。`);
74
479
  let m = s / a, h = c / a, g = document.createElement("div");
75
480
  g.style.cssText = [
76
481
  "position:relative",
@@ -115,7 +520,7 @@ async function M(e, t = {}) {
115
520
  root: null,
116
521
  rootMargin: w,
117
522
  threshold: 0
118
- }), M = [];
523
+ }), D = [];
119
524
  for (let t = 0; t < f; t++) for (let r = 0; r < d; r++) {
120
525
  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
526
  v.width = d, v.height = f;
@@ -127,7 +532,7 @@ async function M(e, t = {}) {
127
532
  `width:${h}px`,
128
533
  `height:${_}px`,
129
534
  `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({
535
+ ].join(";"), v.dataset.tileKey = M.makeKey(e.pageNumber, n, r, t), v.dataset.tilePos = `${r},${t}`, g.appendChild(v), E.observe(v), D.push({
131
536
  canvas: v,
132
537
  col: r,
133
538
  row: t,
@@ -142,14 +547,14 @@ async function M(e, t = {}) {
142
547
  container: g,
143
548
  pageWidth: m,
144
549
  pageHeight: h,
145
- tiles: M
550
+ tiles: D
146
551
  },
147
552
  observer: E
148
553
  };
149
554
  }
150
555
  //#endregion
151
556
  //#region src/core/coords/CoordTransformer.ts
152
- var te = class {
557
+ var L = class {
153
558
  constructor(e, t, n) {
154
559
  if (this.viewport = e, this.scale = t, this.pageSizePt = n, t <= 0) throw RangeError(`scale 必须大于 0,收到: ${t}`);
155
560
  }
@@ -195,7 +600,7 @@ var te = class {
195
600
  get pageSize() {
196
601
  return this.pageSizePt;
197
602
  }
198
- }, N = [
603
+ }, R = [
199
604
  5,
200
605
  10,
201
606
  25,
@@ -216,12 +621,18 @@ var te = class {
216
621
  1800,
217
622
  2e3,
218
623
  2200,
219
- 2800
624
+ 2800,
625
+ 3200,
626
+ 4e3,
627
+ 6e3,
628
+ 8e3,
629
+ 1e4,
630
+ 12800
220
631
  ];
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];
632
+ function z(e, t) {
633
+ return t === "in" ? R.find((t) => t > e) ?? R[R.length - 1] : [...R].reverse().find((t) => t < e) ?? R[0];
223
634
  }
224
- var F = class {
635
+ var B = class {
225
636
  constructor() {
226
637
  this.interaction = null, this.toolManager = null, this.drawCallback = null, this.domContainerId = null, this.zoomCtrl = null, this.initialScale = 1.5;
227
638
  }
@@ -259,12 +670,12 @@ var F = class {
259
670
  }
260
671
  zoomIn() {
261
672
  if (!this.zoomCtrl) return;
262
- let e = this.zoomCtrl.getScale(), t = P(Math.round(e * 100), "in");
673
+ let e = this.zoomCtrl.getScale(), t = z(Math.round(e * 100), "in");
263
674
  this.zoomCtrl.setScale(t / 100);
264
675
  }
265
676
  zoomOut() {
266
677
  if (!this.zoomCtrl) return;
267
- let e = this.zoomCtrl.getScale(), t = P(Math.round(e * 100), "out");
678
+ let e = this.zoomCtrl.getScale(), t = z(Math.round(e * 100), "out");
268
679
  this.zoomCtrl.setScale(t / 100);
269
680
  }
270
681
  setScale(e) {
@@ -325,7 +736,7 @@ var F = class {
325
736
  };
326
737
  //#endregion
327
738
  //#region src/annotations/utils.ts
328
- function I(e, t = 0, n = "px") {
739
+ function V(e, t = 0, n = "px") {
329
740
  return {
330
741
  id: `measure-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
331
742
  kind: "measure",
@@ -337,7 +748,7 @@ function I(e, t = 0, n = "px") {
337
748
  createdAt: Date.now()
338
749
  };
339
750
  }
340
- function L(e, t = "rectangle") {
751
+ function H(e, t = "rectangle") {
341
752
  return {
342
753
  id: `shape-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
343
754
  kind: "shape",
@@ -348,12 +759,12 @@ function L(e, t = "rectangle") {
348
759
  createdAt: Date.now()
349
760
  };
350
761
  }
351
- function R(e) {
762
+ function U(e) {
352
763
  return JSON.parse(JSON.stringify(e));
353
764
  }
354
765
  //#endregion
355
766
  //#region src/utils/EventTrigger.ts
356
- var z = class {
767
+ var W = class {
357
768
  constructor() {
358
769
  this._events = /* @__PURE__ */ new Map();
359
770
  }
@@ -391,107 +802,132 @@ var z = class {
391
802
  destroy() {
392
803
  this._events.clear();
393
804
  }
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;
805
+ };
806
+ //#endregion
807
+ //#region src/vue/usePdfCore.ts
808
+ function fe(e = {}) {
809
+ 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 W(), p = (i) => {
810
+ let { canvas: a, stage: u, wrap: d } = i;
811
+ if (!a || !u) return null;
812
+ n.value && n.value.destroy();
813
+ let p = new j({
814
+ canvas: a,
815
+ stage: u,
816
+ wrap: d ?? null,
817
+ maxSide: e.maxSide,
818
+ maxZoom: e.maxZoom,
819
+ backgroundColor: c.value,
820
+ invertColors: l.value,
821
+ invertMode: e.invertMode,
822
+ invertThreshold: e.invertThreshold ?? 24,
823
+ onPresented: (t) => {
824
+ s.value = t.zoom, f.emit("render_complete", {
825
+ pageNum: o.value,
826
+ scale: t.zoom
827
+ }), e.onPresented?.({
828
+ zoom: t.zoom,
829
+ pageNum: o.value,
830
+ tiled: t.region.tiled
831
+ });
832
+ }
833
+ });
834
+ p.refreshStageBox(), n.value = p, t.value = u;
835
+ let m = r.value;
836
+ return m && m.destroyed !== !0 && (async () => {
837
+ try {
838
+ if (n.value !== p || (await p.open(m), p.setZoom(s.value), n.value !== p)) return;
839
+ await p.render();
840
+ } catch (e) {
841
+ console.error("[PDF-CORE] 重新挂载后恢复渲染失败:", e);
842
+ }
843
+ })(), p;
844
+ }, m = () => {
845
+ n.value?.destroy(), n.value = null;
846
+ }, g = async (e) => {
847
+ u.value = !0, d.value = null;
398
848
  try {
399
849
  let t = await E(e);
400
- n.value = t.doc, i.value = t.pageCount, a.value = 1, await S(), u.emit("loaded", {
850
+ r.value = t.doc, a.value = t.pageCount, o.value = 1;
851
+ let c = n.value;
852
+ if (c) {
853
+ let e = await c.open(t.doc);
854
+ c.setZoom(s.value), c.refreshStageBox(), e.wPt > 0 && (i.value = c.pageRef);
855
+ }
856
+ await v(), f.emit("loaded", {
401
857
  pageCount: t.pageCount,
402
858
  currentPage: 1
403
859
  });
404
860
  } catch (e) {
405
861
  let t = e instanceof Error ? e.message : "Failed to load PDF";
406
- l.value = t, u.emit("error_occurred", { message: t });
862
+ d.value = t, f.emit("error_occurred", { message: t });
407
863
  } finally {
408
- c.value = !1;
864
+ u.value = !1;
409
865
  }
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
- }
866
+ }, v = async () => {
867
+ let e = n.value;
868
+ if (!(!e || !r.value)) try {
869
+ await e.render();
870
+ } catch (e) {
871
+ console.error("[PDF-CORE] render failed:", e), f.emit("error_occurred", { message: e instanceof Error ? e.message : "Render failed" });
441
872
  }
442
873
  };
443
874
  return {
444
875
  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
- }),
876
+ renderer: n,
877
+ doc: r,
878
+ page: i,
879
+ pageCount: a,
880
+ currentPageNum: o,
881
+ currentScale: s,
882
+ backgroundColor: c,
883
+ isLoading: u,
884
+ error: d,
885
+ events: f,
886
+ attach: p,
887
+ detach: m,
888
+ loadFile: g,
889
+ renderCurrentPage: v,
890
+ setScale: async (e) => {
891
+ let t = n.value;
892
+ if (!t || e <= 0) return;
893
+ let r = t.zoom;
894
+ t.setZoom(e), await t.render(), r !== t.zoom && f.emit("scale_changed", {
895
+ scale: t.zoom,
896
+ previousScale: r
897
+ });
898
+ },
899
+ setBackgroundColor: async (e) => {
900
+ c.value = e, n.value?.setBackgroundColor(e);
901
+ },
902
+ setInvertColors: (e) => {
903
+ l.value = e, n.value?.setInvertColors(e);
904
+ },
905
+ setInvertMode: (e, t) => {
906
+ n.value?.setInvertMode(e, t);
907
+ },
908
+ setMaxZoom: (e) => {
909
+ n.value?.setMaxZoom(e);
910
+ },
911
+ invertColors: l,
912
+ resetView: () => {
913
+ n.value?.centerOnContent(), n.value?.requestRender();
914
+ },
479
915
  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");
916
+ 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
917
  }
482
918
  };
483
919
  }
484
920
  //#endregion
485
921
  //#region src/vue/useAnnotations.ts
486
- function H() {
922
+ function G() {
487
923
  let e = h([]);
488
924
  return {
489
925
  annotations: e,
490
926
  addMeasureAnnotation: (t, n = 0, r = "px") => {
491
- e.value = [...e.value, I(t, n, r)];
927
+ e.value = [...e.value, V(t, n, r)];
492
928
  },
493
929
  addShapeAnnotation: (t, n = "rectangle") => {
494
- e.value = [...e.value, L(t, n)];
930
+ e.value = [...e.value, H(t, n)];
495
931
  },
496
932
  removeAnnotation: (t) => {
497
933
  e.value = e.value.filter((e) => e.id !== t);
@@ -500,13 +936,13 @@ function H() {
500
936
  e.value = [];
501
937
  },
502
938
  replaceAnnotations: (t) => {
503
- e.value = t.map(R);
939
+ e.value = t.map(U);
504
940
  }
505
941
  };
506
942
  }
507
943
  //#endregion
508
944
  //#region src/vue/useMeasurement.ts
509
- function U() {
945
+ function K() {
510
946
  let e = h([]);
511
947
  return {
512
948
  points: e,
@@ -525,8 +961,8 @@ function U() {
525
961
  }
526
962
  //#endregion
527
963
  //#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);
964
+ function pe() {
965
+ let { annotations: e, addMeasureAnnotation: t, clearAnnotations: n } = G(), { points: r, addPoint: i, clearPoints: a, distance: o } = K(), s = h(!1);
530
966
  return {
531
967
  points: r,
532
968
  annotations: e,
@@ -547,7 +983,7 @@ function W() {
547
983
  }
548
984
  //#endregion
549
985
  //#region src/components/interaction.ts
550
- function G() {
986
+ function me() {
551
987
  let e = [], t = [], n = "none", r = null;
552
988
  return {
553
989
  get points() {
@@ -567,11 +1003,11 @@ function G() {
567
1003
  },
568
1004
  addPoint(i) {
569
1005
  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));
1006
+ let n = V([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
1007
  return t = [...t, n], r = n.id, e = [], n;
572
1008
  }
573
1009
  if (n === "rectangle" && e.length >= 2) {
574
- let n = L([e[e.length - 2], e[e.length - 1]], "rectangle");
1010
+ let n = H([e[e.length - 2], e[e.length - 1]], "rectangle");
575
1011
  return t = [...t, n], r = n.id, e = [], n;
576
1012
  }
577
1013
  return null;
@@ -593,7 +1029,7 @@ function G() {
593
1029
  }
594
1030
  //#endregion
595
1031
  //#region src/components/useAnnotationCanvas.ts
596
- function K(e) {
1032
+ function he(e) {
597
1033
  let { annotationCanvas: t, rootRef: n, pdfLayerRef: r, interaction: i, previewPoint: a } = e, o = (e) => {
598
1034
  let t = e.currentTarget.getBoundingClientRect();
599
1035
  return {
@@ -657,7 +1093,7 @@ function K(e) {
657
1093
  }
658
1094
  //#endregion
659
1095
  //#region src/components/usePointerInteraction.ts
660
- function ne(e) {
1096
+ function ge(e) {
661
1097
  let { annotationCanvas: t, interaction: n, previewPoint: r, isRectangleDragging: i, getCanvasPoint: a, hitTestAnnotation: o, drawAnnotations: s, deleteSelectedAnnotation: c, emit: l } = e;
662
1098
  return {
663
1099
  handlePointerDown: (e) => {
@@ -722,158 +1158,110 @@ function ne(e) {
722
1158
  }
723
1159
  //#endregion
724
1160
  //#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(() => ({
1161
+ function _e(e) {
1162
+ let { viewerRef: t, renderer: r, zoomSpeed: i, theme: a, onViewChanged: o } = e, s = n(() => ({
771
1163
  width: "100%",
772
1164
  height: "100%",
773
- background: c.value === "dark" ? "#1e1e1e" : "#ffffff",
1165
+ background: a.value === "dark" ? "#000000" : "#ffffff",
774
1166
  overflow: "hidden",
775
- borderRadius: "8px",
776
- border: c.value === "dark" ? "1px solid #374151" : "1px solid #e2e8f0",
777
1167
  position: "relative",
778
1168
  touchAction: "none",
779
1169
  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));
1170
+ })), c = (e = !1) => {
1171
+ let t = r.value;
1172
+ t && (t.refreshStageBox(), e && t.centerOnContent(), t.requestRender(), o?.());
1173
+ }, 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) => ({
1174
+ x: (e.x + t.x) / 2,
1175
+ y: (e.y + t.y) / 2
1176
+ }), g = (e) => {
1177
+ try {
1178
+ t.value?.setPointerCapture?.(e);
1179
+ } catch {}
1180
+ }, _ = (e) => {
1181
+ try {
1182
+ t.value?.releasePointerCapture?.(e);
1183
+ } catch {}
1184
+ }, v = () => {
1185
+ f = null;
1186
+ }, y = (e) => {
1187
+ let t = r.value;
1188
+ if (t && !(e.pointerType === "mouse" && e.button !== 0)) {
1189
+ if (u.set(e.pointerId, {
1190
+ x: e.clientX,
1191
+ y: e.clientY
1192
+ }), g(e.pointerId), u.size === 1) {
1193
+ d = {
1194
+ id: e.pointerId,
1195
+ sx: e.clientX,
1196
+ sy: e.clientY
1197
+ }, l.value = !0, e.preventDefault();
1198
+ return;
848
1199
  }
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);
1200
+ if (u.size === 2) {
1201
+ if (d) {
1202
+ let e = u.get(d.id);
1203
+ e && t.commitDrag(e.x - d.sx, e.y - d.sy), d = null, l.value = !1;
862
1204
  }
863
- z = !0, B = 0, W = null, G = 0, F = e.touches[0].clientX, I = e.touches[0].clientY, L = d, R = f;
1205
+ let [n, r] = [...u.values()], i = m(n, r);
1206
+ f = {
1207
+ dist: Math.max(1, p(n, r)),
1208
+ zoom: t.zoom,
1209
+ pt: t.screenToPt(i.x, i.y)
1210
+ }, e.preventDefault();
1211
+ }
1212
+ }
1213
+ }, b = (e) => {
1214
+ let t = r.value;
1215
+ if (!(!t || !u.has(e.pointerId))) {
1216
+ if (u.set(e.pointerId, {
1217
+ x: e.clientX,
1218
+ y: e.clientY
1219
+ }), u.size >= 2 && f) {
1220
+ let [n, r] = [...u.values()], i = m(n, r), a = f.zoom * p(n, r) / f.dist;
1221
+ t.anchorAt(i.x, i.y, f.pt, a), e.preventDefault();
1222
+ return;
864
1223
  }
1224
+ d && e.pointerId === d.id && (t.setDragOffset(e.clientX - d.sx, e.clientY - d.sy), e.preventDefault());
1225
+ }
1226
+ }, x = (e) => {
1227
+ let t = r.value;
1228
+ 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)) {
1229
+ let [e, t] = [...u.entries()][0];
1230
+ d = {
1231
+ id: e,
1232
+ sx: t.x,
1233
+ sy: t.y
1234
+ }, l.value = !0;
1235
+ }
1236
+ };
1237
+ return {
1238
+ containerStyle: s,
1239
+ adjustLayout: c,
1240
+ handleWheel: (e) => {
1241
+ let t = r.value;
1242
+ if (!t) return;
1243
+ e.preventDefault();
1244
+ let n = Math.max(1, Math.round(i || 1)), a = (e.deltaY < 0 ? 1.12 : 1 / 1.12) ** n;
1245
+ t.zoomAt(e.clientX, e.clientY, a), o?.();
1246
+ },
1247
+ handlePointerDown: y,
1248
+ handlePointerMove: b,
1249
+ handlePointerUp: x,
1250
+ handlePointerCancel: (e) => {
1251
+ u.has(e.pointerId) ? x(e) : u.delete(e.pointerId);
865
1252
  },
866
- handleMouseDown: ee,
867
- isMouseDragging: C,
868
- cleanupMouseDrag: A
1253
+ isMouseDragging: l,
1254
+ cleanupMouseDrag: () => {
1255
+ u.clear(), d = null, v(), l.value = !1;
1256
+ }
869
1257
  };
870
1258
  }
871
1259
  //#endregion
872
1260
  //#region src/types/tools.ts
873
- var ie = {
1261
+ var ve = {
874
1262
  mode: "none",
875
1263
  measureSubType: "distance"
876
- }, Q = class {
1264
+ }, q = class {
877
1265
  constructor(e) {
878
1266
  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
1267
  scale: 1,
@@ -958,7 +1346,7 @@ var ie = {
958
1346
  destroy() {
959
1347
  this._measureList.clear(), this.resetState(), this._active = !1;
960
1348
  }
961
- }, ae = class extends Q {
1349
+ }, J = class extends q {
962
1350
  constructor(e) {
963
1351
  super(e), this.currentType = "distance", this._previewEnd = null;
964
1352
  }
@@ -1010,7 +1398,7 @@ var ie = {
1010
1398
  interrupt() {
1011
1399
  this._previewEnd = null, super.interrupt();
1012
1400
  }
1013
- }, oe = class extends Q {
1401
+ }, Y = class extends q {
1014
1402
  constructor(e) {
1015
1403
  super(e), this.currentType = "angle", this._secondPoint = null, this._thirdPoint = null;
1016
1404
  }
@@ -1040,7 +1428,7 @@ var ie = {
1040
1428
  let u = Math.max(-1, Math.min(1, s / (c * l)));
1041
1429
  return parseFloat((Math.acos(u) * 180 / Math.PI).toFixed(2));
1042
1430
  }
1043
- }, se = class extends Q {
1431
+ }, X = class extends q {
1044
1432
  constructor(e) {
1045
1433
  super(e), this.currentType = "area";
1046
1434
  }
@@ -1068,7 +1456,7 @@ var ie = {
1068
1456
  }
1069
1457
  return Math.abs(t) / 2;
1070
1458
  }
1071
- }, $ = class {
1459
+ }, Z = class {
1072
1460
  get currentType() {
1073
1461
  return this._currentSubType;
1074
1462
  }
@@ -1077,7 +1465,7 @@ var ie = {
1077
1465
  this._isCreating = !0;
1078
1466
  }, this._onMeasureCreated = (e) => {
1079
1467
  this._isCreating = !1, this._resultList.set(e.result.id, e.result);
1080
- }, this.events = e.eventTrigger ?? new z();
1468
+ }, this.events = e.eventTrigger ?? new W();
1081
1469
  let t = {
1082
1470
  coordProvider: e.coordProvider,
1083
1471
  calibration: e.calibration ?? {
@@ -1087,7 +1475,7 @@ var ie = {
1087
1475
  },
1088
1476
  eventTrigger: this.events
1089
1477
  };
1090
- this.distanceMeasure = new ae(t), this.angleMeasure = new oe(t), this.areaMeasure = new se(t), this._subTools = /* @__PURE__ */ new Map([
1478
+ this.distanceMeasure = new J(t), this.angleMeasure = new Y(t), this.areaMeasure = new X(t), this._subTools = /* @__PURE__ */ new Map([
1091
1479
  ["distance", this.distanceMeasure],
1092
1480
  ["angle", this.angleMeasure],
1093
1481
  ["area", this.areaMeasure]
@@ -1157,9 +1545,9 @@ var ie = {
1157
1545
  for (let e of this._subTools.values()) e.destroy();
1158
1546
  this._subTools.clear(), this._resultList.clear(), this._active = !1;
1159
1547
  }
1160
- }, ce = class {
1548
+ }, Q = class {
1161
1549
  constructor(e) {
1162
- this._activeTool = null, this._activeMode = "none", this._tools = /* @__PURE__ */ new Map(), this.events = new z(), this.measureTool = new $({
1550
+ this._activeTool = null, this._activeMode = "none", this._tools = /* @__PURE__ */ new Map(), this.events = new W(), this.measureTool = new Z({
1163
1551
  coordProvider: e.coordProvider,
1164
1552
  calibration: e.calibration,
1165
1553
  eventTrigger: this.events
@@ -1207,8 +1595,8 @@ var ie = {
1207
1595
  };
1208
1596
  //#endregion
1209
1597
  //#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: {
1598
+ function ye(e) {
1599
+ let { drawAnnotations: t, currentScale: n, setScale: r, viewerRef: i, adjustLayout: a, screenToScene: o, toggleTheme: s } = e, c = new Q({ coordProvider: {
1212
1600
  screenToScene: o,
1213
1601
  sceneToScreen: (e) => ({
1214
1602
  x: 0,
@@ -1275,7 +1663,7 @@ function le(e) {
1275
1663
  toggleTheme: () => {
1276
1664
  s();
1277
1665
  }
1278
- }, o = new F();
1666
+ }, o = new B();
1279
1667
  o.registerWithToolManager(c, t, e), window.pdfViewer = o;
1280
1668
  },
1281
1669
  unregisterManager: () => {
@@ -1285,10 +1673,10 @@ function le(e) {
1285
1673
  }
1286
1674
  //#endregion
1287
1675
  //#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 = {
1676
+ var be = { class: "mobile-console__title" }, xe = { class: "mobile-console__count" }, Se = { class: "mobile-console__actions" }, Ce = { class: "mobile-console__toggle" }, we = { class: "mobile-console__level" }, Te = { class: "mobile-console__msg" }, Ee = {
1289
1677
  key: 0,
1290
1678
  class: "mobile-console__empty"
1291
- }, _e = /*@__PURE__*/ c({
1679
+ }, $ = /*@__PURE__*/ c({
1292
1680
  __name: "MobileConsole",
1293
1681
  props: {
1294
1682
  visible: {
@@ -1343,7 +1731,7 @@ var ue = { class: "mobile-console__title" }, de = { class: "mobile-console__coun
1343
1731
  }, [a("div", {
1344
1732
  class: "mobile-console__header",
1345
1733
  onClick: E
1346
- }, [a("span", ue, [l[0] ||= o(" 📟 Console ", -1), a("span", de, v(s.value.length), 1)]), a("span", fe, [
1734
+ }, [a("span", be, [l[0] ||= o(" 📟 Console ", -1), a("span", xe, v(s.value.length), 1)]), a("span", Se, [
1347
1735
  a("button", {
1348
1736
  class: "mobile-console__btn",
1349
1737
  title: "清空",
@@ -1354,7 +1742,7 @@ var ue = { class: "mobile-console__title" }, de = { class: "mobile-console__coun
1354
1742
  title: "复制全部",
1355
1743
  onClick: C(T, ["stop"])
1356
1744
  }, "📋"),
1357
- a("span", pe, v(c.value ? "▲" : "▼"), 1)
1745
+ a("span", Ce, v(c.value ? "▲" : "▼"), 1)
1358
1746
  ])]), S(a("div", {
1359
1747
  ref_key: "logListRef",
1360
1748
  ref: d,
@@ -1362,13 +1750,13 @@ var ue = { class: "mobile-console__title" }, de = { class: "mobile-console__coun
1362
1750
  }, [(m(!0), i(t, null, g(s.value, (e, t) => (m(), i("div", {
1363
1751
  key: t,
1364
1752
  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);
1753
+ }, [a("span", we, v(e.level.toUpperCase()), 1), a("span", Te, v(e.message), 1)], 2))), 128)), s.value.length === 0 ? (m(), i("div", Ee, "暂无日志")) : r("", !0)], 512), [[b, !c.value]])], 2)) : r("", !0);
1366
1754
  }
1367
- }), ve = (e, t) => {
1755
+ }), De = (e, t) => {
1368
1756
  let n = e.__vccOpts || e;
1369
1757
  for (let [e, r] of t) n[e] = r;
1370
1758
  return n;
1371
- }, ye = /*#__PURE__*/ ve(_e, [["__scopeId", "data-v-ef8b578a"]]), be = /*#__PURE__*/ ve(/* @__PURE__ */ c({
1759
+ }, Oe = /*#__PURE__*/ De($, [["__scopeId", "data-v-ef8b578a"]]), ke = /*#__PURE__*/ De(/* @__PURE__ */ c({
1372
1760
  __name: "PdfViewer",
1373
1761
  props: {
1374
1762
  modelValue: { default: null },
@@ -1381,6 +1769,13 @@ var ue = { class: "mobile-console__title" }, de = { class: "mobile-console__coun
1381
1769
  default: !1
1382
1770
  },
1383
1771
  zoomSpeed: { default: 1 },
1772
+ invertDarkContent: {
1773
+ type: Boolean,
1774
+ default: !0
1775
+ },
1776
+ invertMode: { default: "unblend" },
1777
+ invertThreshold: { default: 24 },
1778
+ maxZoom: { default: 128 },
1384
1779
  showConsole: {
1385
1780
  type: Boolean,
1386
1781
  default: !1
@@ -1392,118 +1787,140 @@ var ue = { class: "mobile-console__title" }, de = { class: "mobile-console__coun
1392
1787
  "annotation-added"
1393
1788
  ],
1394
1789
  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 = () => {
1790
+ 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
1791
  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({
1792
+ }, { containerRef: T, renderer: E, loadFile: D, doc: ee, pageCount: te, currentPageNum: ne, error: re, currentScale: O, setScale: k, setBackgroundColor: ie, setInvertColors: ae, setInvertMode: oe, setMaxZoom: se, reset: A, resetView: ce, attach: le, detach: j, events: M } = fe({
1398
1793
  autoLoad: !1,
1399
1794
  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({
1795
+ backgroundColor: S.value,
1796
+ invertColors: C.value,
1797
+ invertMode: o.invertMode,
1798
+ invertThreshold: o.invertThreshold,
1799
+ maxZoom: o.maxZoom,
1800
+ onPresented: () => ue()
1801
+ });
1802
+ function ue() {
1803
+ I(), F();
1804
+ }
1805
+ let N = me(), P = h(null), de = h(!1), { drawAnnotations: F, syncCanvasSize: I, getCanvasPoint: L, hitTestAnnotation: R } = he({
1402
1806
  annotationCanvas: v,
1403
1807
  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({
1808
+ pdfLayerRef: g,
1809
+ interaction: N,
1810
+ previewPoint: P
1811
+ }), { containerStyle: z, adjustLayout: B, handleWheel: V, handlePointerDown: H, handlePointerMove: U, handlePointerUp: W, handlePointerCancel: G, isMouseDragging: K, cleanupMouseDrag: pe } = _e({
1408
1812
  viewerRef: u,
1409
- rootRef: g,
1410
- pdfLayerRef: _,
1411
- currentScale: A,
1412
- setScale: j,
1813
+ renderer: E,
1413
1814
  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,
1815
+ theme: b
1816
+ }), ve = (e) => {
1817
+ N.mode === "none" && H(e);
1818
+ }, q = n(() => ({
1819
+ ...z.value,
1820
+ cursor: K.value ? "grabbing" : "grab"
1821
+ })), { setMode: J, clearInteraction: Y, deleteSelectedAnnotation: X, selectAnnotation: Z, registerManager: Q, unregisterManager: be } = ye({
1822
+ drawAnnotations: F,
1823
+ currentScale: O,
1824
+ setScale: k,
1426
1825
  viewerRef: u,
1427
- adjustLayout: U,
1826
+ adjustLayout: B,
1428
1827
  screenToScene: (e) => {
1429
- let t = z(e);
1828
+ let t = L(e);
1430
1829
  return {
1431
1830
  x: t.x,
1432
1831
  y: t.y
1433
1832
  };
1434
1833
  },
1435
1834
  toggleTheme: w
1436
- }), { handlePointerDown: fe, handlePointerMove: pe, handlePointerUp: me, handleKeydown: he } = ne({
1835
+ }), { handlePointerDown: xe, handlePointerMove: Se, handlePointerUp: Ce, handleKeydown: we } = ge({
1437
1836
  annotationCanvas: v,
1438
- interaction: P,
1439
- previewPoint: F,
1440
- isRectangleDragging: I,
1441
- getCanvasPoint: z,
1442
- hitTestAnnotation: B,
1443
- drawAnnotations: L,
1444
- deleteSelectedAnnotation: $,
1837
+ interaction: N,
1838
+ previewPoint: P,
1839
+ isRectangleDragging: de,
1840
+ getCanvasPoint: L,
1841
+ hitTestAnnotation: R,
1842
+ drawAnnotations: F,
1843
+ deleteSelectedAnnotation: X,
1445
1844
  emit: c
1446
- });
1447
- return N.on("loaded", (e) => {
1845
+ }), Te = async (e) => {
1846
+ await D(e);
1847
+ }, Ee = () => {
1848
+ A();
1849
+ };
1850
+ M.on("loaded", (e) => {
1448
1851
  c("loaded", {
1449
1852
  pageCount: e.pageCount,
1450
1853
  currentPage: e.currentPage
1451
1854
  });
1452
- }), N.on("error_occurred", (e) => {
1855
+ }), M.on("error_occurred", (e) => {
1453
1856
  c("error", { message: e.message });
1454
- }), x(() => P.annotations.length, () => {
1455
- L();
1857
+ }), x(() => N.annotations.length, () => {
1858
+ F();
1456
1859
  }), x(() => o.scale, async (e) => {
1457
- e && e !== A.value && (await j(e), await l(), U());
1860
+ e && e !== O.value && (await k(e), await l(), B());
1458
1861
  }), x(() => o.modelValue, async (e) => {
1459
- e && (await E(e), await l(), U(!0));
1862
+ e && (await D(e), await l(), B(!0));
1460
1863
  }, {
1461
1864
  immediate: !0,
1462
1865
  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 }));
1866
+ }), x([b, C], async () => {
1867
+ ae(C.value), await ie(S.value);
1868
+ }), x([() => o.invertMode, () => o.invertThreshold], () => {
1869
+ oe(o.invertMode ?? "unblend", o.invertThreshold);
1870
+ }), x(() => o.maxZoom, (e) => {
1871
+ e && e > 0 && se(e);
1872
+ });
1873
+ let $ = null;
1874
+ return p(() => {
1875
+ le({
1876
+ canvas: _.value,
1877
+ stage: u.value,
1878
+ wrap: g.value
1879
+ }), I(), F(), window.addEventListener("keydown", we), Q(), $ = new ResizeObserver(() => {
1880
+ E.value?.refreshStageBox(), E.value?.requestRender();
1881
+ }), u.value && $.observe(u.value);
1467
1882
  }), 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();
1883
+ $?.disconnect(), $ = null, window.removeEventListener("keydown", we), pe(), be(), j();
1469
1884
  }), 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
1885
+ load: Te,
1886
+ clear: Ee,
1887
+ setMode: J,
1888
+ clearInteraction: Y,
1889
+ deleteSelectedAnnotation: X,
1890
+ selectAnnotation: Z,
1891
+ resetView: ce,
1892
+ zoomIn: () => k(E.value ? E.value.zoom * 1.25 : O.value),
1893
+ zoomOut: () => k(E.value ? E.value.zoom / 1.25 : O.value)
1480
1894
  }), (t, n) => (m(), i("div", {
1481
1895
  ref_key: "viewerRef",
1482
1896
  ref: u,
1483
1897
  class: "pdf-core-viewer",
1484
- style: d(ae.value),
1485
- onWheel: n[3] ||= C((...e) => y(W) && y(W)(...e), ["prevent"]),
1486
- onMousedown: Q
1898
+ style: d(q.value),
1899
+ onWheel: n[3] ||= (...e) => y(V) && y(V)(...e),
1900
+ onPointerdown: ve,
1901
+ onPointermove: n[4] ||= (...e) => y(U) && y(U)(...e),
1902
+ onPointerup: n[5] ||= (...e) => y(W) && y(W)(...e),
1903
+ onPointercancel: n[6] ||= (...e) => y(G) && y(G)(...e)
1487
1904
  }, [a("div", {
1488
1905
  ref_key: "rootRef",
1489
1906
  ref: g,
1490
- class: "pdf-core-canvas-wrapper"
1491
- }, [a("div", {
1492
- ref_key: "pdfLayerRef",
1907
+ class: "pdf-core-content"
1908
+ }, [a("canvas", {
1909
+ ref_key: "pageCanvas",
1493
1910
  ref: _,
1494
- class: "pdf-core-pdf-layer"
1911
+ class: "pdf-core-page-canvas"
1495
1912
  }, null, 512), a("div", {
1496
1913
  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));
1914
+ onPointerdown: n[0] ||= (...e) => y(xe) && y(xe)(...e),
1915
+ onPointerup: n[1] ||= (...e) => y(Ce) && y(Ce)(...e),
1916
+ onPointermove: n[2] ||= (...e) => y(Se) && y(Se)(...e)
1917
+ }, null, 32)], 512), s(Oe, { visible: e.showConsole }, null, 8, ["visible"])], 36));
1501
1918
  }
1502
- }), [["__scopeId", "data-v-58f287f7"]]);
1919
+ }), [["__scopeId", "data-v-affa757b"]]);
1503
1920
  //#endregion
1504
1921
  //#region src/vue/plugin.ts
1505
- function xe(e) {
1506
- e.component("PdfViewer", be);
1922
+ function Ae(e) {
1923
+ e.component("PdfViewer", ke);
1507
1924
  }
1508
1925
  //#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 };
1926
+ export { Y as AngleMeasure, X as AreaMeasure, k as ColorInverter, L as CoordTransformer, te as DEFAULT_ACHROMATIC_THRESHOLD, ve as DEFAULT_TOOL_STATE, J as DistanceMeasure, W as EventTrigger, D as INVERT_FILTER_ALL, ee as INVERT_FILTER_HUE, q as MeasureBase, Z as MeasureTool, j as PageCanvasRenderer, ke as PdfViewer, B as PdfViewerCore, M as TileLRUCache, Q as ToolManager, R as ZOOM_LEVELS, V as createMeasureAnnotation, H as createShapeAnnotation, z as getNextZoom, Ae as installPdfCore, E as loadPDF, I as renderPageTiledVirtual, w as setPDFWorkerSrc, G as useAnnotations, T as useDefaultWorker, pe as useInteraction, K as useMeasurement, fe as usePdfCore };