@xtctwins/tctwins-pdf-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -0
- package/dist/PdfViewer.d.ts +81 -0
- package/dist/PdfViewer.d.ts.map +1 -0
- package/dist/annotations/index.d.ts +3 -0
- package/dist/annotations/index.d.ts.map +1 -0
- package/dist/annotations/types.d.ts +3 -0
- package/dist/annotations/types.d.ts.map +1 -0
- package/dist/annotations/utils.d.ts +11 -0
- package/dist/annotations/utils.d.ts.map +1 -0
- package/dist/components/PdfViewer.d.ts +65 -0
- package/dist/components/PdfViewer.d.ts.map +1 -0
- package/dist/components/PdfViewer.vue.d.ts +44 -0
- package/dist/components/PdfViewer.vue.d.ts.map +1 -0
- package/dist/components/interaction.d.ts +15 -0
- package/dist/components/interaction.d.ts.map +1 -0
- package/dist/components/types.d.ts +3 -0
- package/dist/components/types.d.ts.map +1 -0
- package/dist/components/useAnnotationCanvas.d.ts +49 -0
- package/dist/components/useAnnotationCanvas.d.ts.map +1 -0
- package/dist/components/usePointerInteraction.d.ts +51 -0
- package/dist/components/usePointerInteraction.d.ts.map +1 -0
- package/dist/components/useViewerLayout.d.ts +46 -0
- package/dist/components/useViewerLayout.d.ts.map +1 -0
- package/dist/components/useViewerManager.d.ts +46 -0
- package/dist/components/useViewerManager.d.ts.map +1 -0
- package/dist/core/PDFLoader.d.ts +15 -0
- package/dist/core/PDFLoader.d.ts.map +1 -0
- package/dist/core/TileCache.d.ts +18 -0
- package/dist/core/TileCache.d.ts.map +1 -0
- package/dist/core/TileRenderer.d.ts +29 -0
- package/dist/core/TileRenderer.d.ts.map +1 -0
- package/dist/core/coords/CoordTransformer.d.ts +19 -0
- package/dist/core/coords/CoordTransformer.d.ts.map +1 -0
- package/dist/core/coords/Types.d.ts +3 -0
- package/dist/core/coords/Types.d.ts.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/pdf-core.js +1308 -0
- package/dist/style.css +2 -0
- package/dist/tools/MeasureTool.d.ts +59 -0
- package/dist/tools/MeasureTool.d.ts.map +1 -0
- package/dist/tools/ToolManager.d.ts +42 -0
- package/dist/tools/ToolManager.d.ts.map +1 -0
- package/dist/tools/index.d.ts +8 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/measure/AngleMeasure.d.ts +23 -0
- package/dist/tools/measure/AngleMeasure.d.ts.map +1 -0
- package/dist/tools/measure/AreaMeasure.d.ts +22 -0
- package/dist/tools/measure/AreaMeasure.d.ts.map +1 -0
- package/dist/tools/measure/DistanceMeasure.d.ts +22 -0
- package/dist/tools/measure/DistanceMeasure.d.ts.map +1 -0
- package/dist/tools/measure/MeasureBase.d.ts +87 -0
- package/dist/tools/measure/MeasureBase.d.ts.map +1 -0
- package/dist/tools/measure/index.d.ts +5 -0
- package/dist/tools/measure/index.d.ts.map +1 -0
- package/dist/tools/types.d.ts +4 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/types/annotations.d.ts +29 -0
- package/dist/types/annotations.d.ts.map +1 -0
- package/dist/types/components.d.ts +28 -0
- package/dist/types/components.d.ts.map +1 -0
- package/dist/types/coords.d.ts +28 -0
- package/dist/types/coords.d.ts.map +1 -0
- package/dist/types/core.d.ts +44 -0
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/tools.d.ts +113 -0
- package/dist/types/tools.d.ts.map +1 -0
- package/dist/utils/EventTrigger.d.ts +45 -0
- package/dist/utils/EventTrigger.d.ts.map +1 -0
- package/dist/vue/index.d.ts +2 -0
- package/dist/vue/index.d.ts.map +1 -0
- package/dist/vue/plugin.d.ts +5 -0
- package/dist/vue/plugin.d.ts.map +1 -0
- package/dist/vue/useAnnotations.d.ts +12 -0
- package/dist/vue/useAnnotations.d.ts.map +1 -0
- package/dist/vue/useInteraction.d.ts +13 -0
- package/dist/vue/useInteraction.d.ts.map +1 -0
- package/dist/vue/useMeasurement.d.ts +10 -0
- package/dist/vue/useMeasurement.d.ts.map +1 -0
- package/dist/vue/usePdfCore.d.ts +28 -0
- package/dist/vue/usePdfCore.d.ts.map +1 -0
- package/package.json +61 -0
package/dist/pdf-core.js
ADDED
|
@@ -0,0 +1,1308 @@
|
|
|
1
|
+
import * as e from "pdfjs-dist";
|
|
2
|
+
import { computed as t, createElementBlock as n, createElementVNode as r, defineComponent as i, nextTick as a, normalizeStyle as o, onBeforeUnmount as s, onMounted as c, openBlock as l, ref as u, shallowRef as d, unref as f, watch as p } from "vue";
|
|
3
|
+
//#region src/core/PDFLoader.ts
|
|
4
|
+
function m(t) {
|
|
5
|
+
t && (e.GlobalWorkerOptions.workerSrc = t);
|
|
6
|
+
}
|
|
7
|
+
function h(t = "/pdf.worker.min.mjs") {
|
|
8
|
+
e.GlobalWorkerOptions.workerSrc = t, fetch(t, { method: "HEAD" }).catch(() => {
|
|
9
|
+
e.GlobalWorkerOptions.workerSrc = "https://unpkg.com/pdfjs-dist@5.7.284/legacy/build/pdf.worker.min.mjs";
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
async function g(t, n = {}) {
|
|
13
|
+
let r = t instanceof File ? await t.arrayBuffer() : t, i = r.slice(0);
|
|
14
|
+
n.workerSrc && m(n.workerSrc);
|
|
15
|
+
let a = await e.getDocument({ data: i }).promise;
|
|
16
|
+
return {
|
|
17
|
+
arrayBuffer: r,
|
|
18
|
+
doc: a,
|
|
19
|
+
pageCount: a.numPages
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/core/TileCache.ts
|
|
24
|
+
var _ = class e {
|
|
25
|
+
constructor(e = 100) {
|
|
26
|
+
this.cache = /* @__PURE__ */ new Map(), this.capacity = e;
|
|
27
|
+
}
|
|
28
|
+
static quantizeScale(e) {
|
|
29
|
+
return Math.round(e * 4) / 4;
|
|
30
|
+
}
|
|
31
|
+
static makeKey(t, n, r, i) {
|
|
32
|
+
return `${t}-${e.quantizeScale(n)}-${r}-${i}`;
|
|
33
|
+
}
|
|
34
|
+
get(e) {
|
|
35
|
+
if (!this.cache.has(e)) return null;
|
|
36
|
+
let t = this.cache.get(e);
|
|
37
|
+
return this.cache.delete(e), this.cache.set(e, t), t;
|
|
38
|
+
}
|
|
39
|
+
set(e, t) {
|
|
40
|
+
if (this.cache.has(e)) this.cache.delete(e);
|
|
41
|
+
else if (this.cache.size >= this.capacity) {
|
|
42
|
+
let e = this.cache.keys().next().value;
|
|
43
|
+
if (e === void 0) return;
|
|
44
|
+
let t = this.cache.get(e);
|
|
45
|
+
t.width = 0, t.height = 0, this.cache.delete(e);
|
|
46
|
+
}
|
|
47
|
+
this.cache.set(e, t);
|
|
48
|
+
}
|
|
49
|
+
has(e) {
|
|
50
|
+
return this.cache.has(e);
|
|
51
|
+
}
|
|
52
|
+
clear() {
|
|
53
|
+
this.cache.forEach((e) => {
|
|
54
|
+
e.width = 0, e.height = 0;
|
|
55
|
+
}), this.cache.clear();
|
|
56
|
+
}
|
|
57
|
+
get size() {
|
|
58
|
+
return this.cache.size;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/core/TileRenderer.ts
|
|
63
|
+
function v(e) {
|
|
64
|
+
return e >= 32 ? 1 : e >= 8 ? Math.min(window.devicePixelRatio, 1.5) : window.devicePixelRatio;
|
|
65
|
+
}
|
|
66
|
+
var y = 16384, b = 256;
|
|
67
|
+
async function x(e, t = {}) {
|
|
68
|
+
let n = t.scale ?? 1.5, r = t.tileSize ?? 4096;
|
|
69
|
+
t.cache;
|
|
70
|
+
let i = t.backgroundColor ?? "rgb(255,255,255)", a = v(n), o = e.getViewport({ scale: n * a }), s = o.width, c = o.height, l = Math.ceil(s / r), u = Math.ceil(c / r), d = l * u;
|
|
71
|
+
d > b && console.warn(`[PDF-CORE] 缩放比例较大 (scale=${n}),共 ${d} 个 tile(${l}×${u}),IntersectionObserver 将仅渲染可见区域。建议降低缩放比例以获得更好体验。`);
|
|
72
|
+
let f = Math.round(Math.min(r, Math.max(s, c)));
|
|
73
|
+
if (f > y) {
|
|
74
|
+
console.warn(`[PDF-CORE] 缩放比例过大 (scale=${n}),单个 tile canvas 将达到 ${f}px,超过浏览器安全上限 ${y}px。已自动将 tileSize 缩小至安全范围。`);
|
|
75
|
+
let i = Math.min(r, Math.floor(y * .9));
|
|
76
|
+
return x(e, {
|
|
77
|
+
...t,
|
|
78
|
+
tileSize: i
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
let p = document.createElement("div");
|
|
82
|
+
p.style.cssText = `position:relative; width:${s / a}px; height:${c / a}px; overflow:hidden; background:${i};`;
|
|
83
|
+
let m = /* @__PURE__ */ new Set(), h = /* @__PURE__ */ new Set(), g = new IntersectionObserver((t) => {
|
|
84
|
+
t.forEach((t) => {
|
|
85
|
+
let o = t.target;
|
|
86
|
+
if (t.isIntersecting) {
|
|
87
|
+
let t = o.dataset.tileKey;
|
|
88
|
+
if (m.has(t) || h.has(t)) return;
|
|
89
|
+
h.add(t);
|
|
90
|
+
let [s, c] = t.split(",").map(Number), l = s * r, u = c * r, d = e.getViewport({ scale: n * a }), f = o.getContext("2d");
|
|
91
|
+
f.setTransform(1, 0, 0, 1, 0, 0), f.translate(-l, -u), e.render({
|
|
92
|
+
canvas: o,
|
|
93
|
+
canvasContext: f,
|
|
94
|
+
viewport: d,
|
|
95
|
+
background: i
|
|
96
|
+
}).promise.then(() => {
|
|
97
|
+
m.add(t), h.delete(t);
|
|
98
|
+
}).catch(() => {
|
|
99
|
+
h.delete(t);
|
|
100
|
+
});
|
|
101
|
+
} else {
|
|
102
|
+
let e = o.dataset.tileKey;
|
|
103
|
+
n > 8 && m.has(e) && (o.getContext("2d").clearRect(0, 0, o.width, o.height), m.delete(e));
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}, {
|
|
107
|
+
root: null,
|
|
108
|
+
rootMargin: "512px",
|
|
109
|
+
threshold: 0
|
|
110
|
+
}), _ = [];
|
|
111
|
+
for (let e = 0; e < u; e++) for (let t = 0; t < l; t++) {
|
|
112
|
+
let n = t * r, o = e * r, l = Math.min(r, s - n), u = Math.min(r, c - o), d = document.createElement("canvas");
|
|
113
|
+
d.width = Math.round(l), d.height = Math.round(u), d.style.cssText = `position:absolute; left:${n / a}px; top:${o / a}px; width:${l / a}px; height:${u / a}px; background:${i};`, d.dataset.tileKey = `${t},${e}`, p.appendChild(d), g.observe(d), _.push({
|
|
114
|
+
canvas: d,
|
|
115
|
+
col: t,
|
|
116
|
+
row: e,
|
|
117
|
+
x: n,
|
|
118
|
+
y: o,
|
|
119
|
+
cssWidth: l,
|
|
120
|
+
cssHeight: u
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
tiledPage: {
|
|
125
|
+
container: p,
|
|
126
|
+
pageWidth: s / a,
|
|
127
|
+
pageHeight: c / a,
|
|
128
|
+
tiles: _
|
|
129
|
+
},
|
|
130
|
+
observer: g
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/core/coords/CoordTransformer.ts
|
|
135
|
+
var S = class {
|
|
136
|
+
constructor(e, t, n) {
|
|
137
|
+
if (this.viewport = e, this.scale = t, this.pageSizePt = n, t <= 0) throw RangeError(`scale 必须大于 0,收到: ${t}`);
|
|
138
|
+
}
|
|
139
|
+
pageToScreen(e, t) {
|
|
140
|
+
let [n, r] = typeof e == "object" ? [e.x, e.y] : [e, t], [i, a] = this.viewport.convertToViewportPoint(n, r);
|
|
141
|
+
return {
|
|
142
|
+
x: i * this.scale,
|
|
143
|
+
y: a * this.scale
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
screenToPage(e, t) {
|
|
147
|
+
let [n, r] = typeof e == "object" ? [e.x, e.y] : [e, t], [i, a] = this.viewport.convertToPdfPoint(n / this.scale, r / this.scale);
|
|
148
|
+
return {
|
|
149
|
+
x: i,
|
|
150
|
+
y: a
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
pagePointToPdfLib(e) {
|
|
154
|
+
return {
|
|
155
|
+
x: e.x,
|
|
156
|
+
y: e.y
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
pdfLibToPagePoint(e) {
|
|
160
|
+
return {
|
|
161
|
+
x: e.x,
|
|
162
|
+
y: e.y
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
screenToPdfLib(e, t) {
|
|
166
|
+
let n = typeof e == "object" ? e : {
|
|
167
|
+
x: e,
|
|
168
|
+
y: t
|
|
169
|
+
};
|
|
170
|
+
return this.pagePointToPdfLib(this.screenToPage(n));
|
|
171
|
+
}
|
|
172
|
+
pdfLibToScreen(e) {
|
|
173
|
+
return this.pageToScreen(this.pdfLibToPagePoint(e));
|
|
174
|
+
}
|
|
175
|
+
get currentScale() {
|
|
176
|
+
return this.scale;
|
|
177
|
+
}
|
|
178
|
+
get pageSize() {
|
|
179
|
+
return this.pageSizePt;
|
|
180
|
+
}
|
|
181
|
+
}, C = [
|
|
182
|
+
5,
|
|
183
|
+
10,
|
|
184
|
+
25,
|
|
185
|
+
33,
|
|
186
|
+
50,
|
|
187
|
+
67,
|
|
188
|
+
75,
|
|
189
|
+
100,
|
|
190
|
+
125,
|
|
191
|
+
150,
|
|
192
|
+
200,
|
|
193
|
+
300,
|
|
194
|
+
400,
|
|
195
|
+
600,
|
|
196
|
+
800,
|
|
197
|
+
1200,
|
|
198
|
+
1600,
|
|
199
|
+
2400,
|
|
200
|
+
3200
|
|
201
|
+
];
|
|
202
|
+
function w(e, t) {
|
|
203
|
+
return t === "in" ? C.find((t) => t > e) ?? C[C.length - 1] : [...C].reverse().find((t) => t < e) ?? C[0];
|
|
204
|
+
}
|
|
205
|
+
var T = class {
|
|
206
|
+
constructor() {
|
|
207
|
+
this.interaction = null, this.toolManager = null, this.drawCallback = null, this.domContainerId = null, this.zoomCtrl = null, this.initialScale = 1.5;
|
|
208
|
+
}
|
|
209
|
+
register(e, t, n, r) {
|
|
210
|
+
this.interaction = e, this.drawCallback = t, this.zoomCtrl = n ?? null, this.domContainerId = r ?? null, n && (this.initialScale = n.getScale());
|
|
211
|
+
}
|
|
212
|
+
registerWithToolManager(e, t, n, r) {
|
|
213
|
+
this.toolManager = e, this.drawCallback = t, this.zoomCtrl = n ?? null, this.domContainerId = r ?? null, n && (this.initialScale = n.getScale());
|
|
214
|
+
}
|
|
215
|
+
unregister() {
|
|
216
|
+
this.interaction = null, this.toolManager = null, this.drawCallback = null, this.zoomCtrl = null, this.domContainerId = null;
|
|
217
|
+
}
|
|
218
|
+
setMeasureMode() {
|
|
219
|
+
if (this.toolManager) {
|
|
220
|
+
this.toolManager.setMode("measure"), this.drawCallback?.();
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
this.interaction?.setMode("measure"), this.drawCallback?.();
|
|
224
|
+
}
|
|
225
|
+
setMeasureSubType(e) {
|
|
226
|
+
this.toolManager?.measureTool.setSubType(e);
|
|
227
|
+
}
|
|
228
|
+
setRectangleMode() {
|
|
229
|
+
this.interaction?.setMode("rectangle"), this.drawCallback?.();
|
|
230
|
+
}
|
|
231
|
+
cancelTool() {
|
|
232
|
+
if (this.toolManager) {
|
|
233
|
+
this.toolManager.setMode("none"), this.drawCallback?.();
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
this.interaction?.setMode("none"), this.drawCallback?.();
|
|
237
|
+
}
|
|
238
|
+
getMode() {
|
|
239
|
+
return this.toolManager?.activeMode ?? this.interaction?.mode ?? "none";
|
|
240
|
+
}
|
|
241
|
+
zoomIn() {
|
|
242
|
+
if (!this.zoomCtrl) return;
|
|
243
|
+
let e = this.zoomCtrl.getScale(), t = w(Math.round(e * 100), "in");
|
|
244
|
+
this.zoomCtrl.setScale(t / 100);
|
|
245
|
+
}
|
|
246
|
+
zoomOut() {
|
|
247
|
+
if (!this.zoomCtrl) return;
|
|
248
|
+
let e = this.zoomCtrl.getScale(), t = w(Math.round(e * 100), "out");
|
|
249
|
+
this.zoomCtrl.setScale(t / 100);
|
|
250
|
+
}
|
|
251
|
+
setScale(e) {
|
|
252
|
+
this.zoomCtrl?.setScale(e);
|
|
253
|
+
}
|
|
254
|
+
getScale() {
|
|
255
|
+
return this.zoomCtrl?.getScale() ?? 1;
|
|
256
|
+
}
|
|
257
|
+
getScalePercent() {
|
|
258
|
+
return Math.round((this.zoomCtrl?.getScale() ?? 1) * 100);
|
|
259
|
+
}
|
|
260
|
+
resetView() {
|
|
261
|
+
this.zoomCtrl && this.zoomCtrl.setScale(this.initialScale);
|
|
262
|
+
let e = this.zoomCtrl?.getContainerEl();
|
|
263
|
+
e && (e.scrollTop = 0, e.scrollLeft = 0);
|
|
264
|
+
}
|
|
265
|
+
getAnnotations() {
|
|
266
|
+
return this.toolManager ? this.toolManager.measureTool.getResults().map((e) => ({
|
|
267
|
+
id: e.id,
|
|
268
|
+
kind: "measure",
|
|
269
|
+
points: e.points.map((e) => ({
|
|
270
|
+
x: e.x,
|
|
271
|
+
y: e.y
|
|
272
|
+
})),
|
|
273
|
+
value: e.value,
|
|
274
|
+
unit: e.unit,
|
|
275
|
+
label: e.label,
|
|
276
|
+
color: "#10b981",
|
|
277
|
+
strokeWidth: 2,
|
|
278
|
+
createdAt: e.createdAt
|
|
279
|
+
})) : this.interaction?.annotations ?? [];
|
|
280
|
+
}
|
|
281
|
+
clearAnnotations() {
|
|
282
|
+
this.toolManager?.measureTool.clearResults(), this.interaction?.clear(), this.drawCallback?.();
|
|
283
|
+
}
|
|
284
|
+
deleteSelectedAnnotation() {
|
|
285
|
+
this.interaction?.deleteSelectedAnnotation(), this.drawCallback?.();
|
|
286
|
+
}
|
|
287
|
+
selectAnnotation(e) {
|
|
288
|
+
this.interaction?.selectAnnotation(e), this.drawCallback?.();
|
|
289
|
+
}
|
|
290
|
+
getSelectedAnnotationId() {
|
|
291
|
+
return this.interaction?.selectedAnnotationId ?? null;
|
|
292
|
+
}
|
|
293
|
+
getToolManager() {
|
|
294
|
+
return this.toolManager;
|
|
295
|
+
}
|
|
296
|
+
getMeasureTool() {
|
|
297
|
+
return this.toolManager?.measureTool ?? null;
|
|
298
|
+
}
|
|
299
|
+
closeAll() {
|
|
300
|
+
this.toolManager?.setMode("none"), this.toolManager?.measureTool.clearResults(), this.interaction?.clear(), this.drawCallback?.();
|
|
301
|
+
}
|
|
302
|
+
getContainerId() {
|
|
303
|
+
return this.domContainerId;
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region src/annotations/utils.ts
|
|
308
|
+
function E(e, t = 0, n = "px") {
|
|
309
|
+
return {
|
|
310
|
+
id: `measure-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
311
|
+
kind: "measure",
|
|
312
|
+
points: e,
|
|
313
|
+
value: t,
|
|
314
|
+
unit: n,
|
|
315
|
+
color: "#3b82f6",
|
|
316
|
+
strokeWidth: 2,
|
|
317
|
+
createdAt: Date.now()
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
function D(e, t = "rectangle") {
|
|
321
|
+
return {
|
|
322
|
+
id: `shape-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
323
|
+
kind: "shape",
|
|
324
|
+
points: e,
|
|
325
|
+
shapeType: t,
|
|
326
|
+
color: "#ef4444",
|
|
327
|
+
strokeWidth: 2,
|
|
328
|
+
createdAt: Date.now()
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
function O(e) {
|
|
332
|
+
return JSON.parse(JSON.stringify(e));
|
|
333
|
+
}
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/utils/EventTrigger.ts
|
|
336
|
+
var k = class {
|
|
337
|
+
constructor() {
|
|
338
|
+
this._events = /* @__PURE__ */ new Map();
|
|
339
|
+
}
|
|
340
|
+
on(e, t) {
|
|
341
|
+
let n = this._events.get(e);
|
|
342
|
+
return n ? n.push(t) : this._events.set(e, [t]), t;
|
|
343
|
+
}
|
|
344
|
+
once(e, t) {
|
|
345
|
+
let n = ((...r) => {
|
|
346
|
+
this.off(e, n), t(...r);
|
|
347
|
+
});
|
|
348
|
+
this.on(e, n);
|
|
349
|
+
}
|
|
350
|
+
off(e, t) {
|
|
351
|
+
let n = this._events.get(e);
|
|
352
|
+
if (n) {
|
|
353
|
+
let r = n.filter((e) => e !== t);
|
|
354
|
+
r.length === 0 ? this._events.delete(e) : this._events.set(e, r);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
emit(e, ...t) {
|
|
358
|
+
let n = this._events.get(e);
|
|
359
|
+
if (n) for (let r of n) try {
|
|
360
|
+
r(...t);
|
|
361
|
+
} catch (t) {
|
|
362
|
+
console.error(`[EventTrigger] Error in event "${e}":`, t);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
removeAllListeners(e) {
|
|
366
|
+
e ? this._events.delete(e) : this._events.clear();
|
|
367
|
+
}
|
|
368
|
+
listenerCount(e) {
|
|
369
|
+
return this._events.get(e)?.length ?? 0;
|
|
370
|
+
}
|
|
371
|
+
destroy() {
|
|
372
|
+
this._events.clear();
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region src/vue/usePdfCore.ts
|
|
377
|
+
function A(e = {}) {
|
|
378
|
+
let t = u(null), n = d(null), r = d(null), i = u(0), a = u(1), o = u(e.scale ?? 1.5), s = e.backgroundColor ?? "rgb(255,255,255)", c = u(!1), l = u(null), f = new k(), p = new _(100), m = !1, h = null, v = null, y = null, b = null, S = async (e) => {
|
|
379
|
+
c.value = !0, l.value = null;
|
|
380
|
+
try {
|
|
381
|
+
let t = await g(e);
|
|
382
|
+
n.value = t.doc, i.value = t.pageCount, a.value = 1, await C(), f.emit("loaded", {
|
|
383
|
+
pageCount: t.pageCount,
|
|
384
|
+
currentPage: 1
|
|
385
|
+
});
|
|
386
|
+
} catch (e) {
|
|
387
|
+
let t = e instanceof Error ? e.message : "Failed to load PDF";
|
|
388
|
+
l.value = t, f.emit("error_occurred", { message: t });
|
|
389
|
+
} finally {
|
|
390
|
+
c.value = !1;
|
|
391
|
+
}
|
|
392
|
+
}, C = async () => {
|
|
393
|
+
if (!(!n.value || !t.value) && !m) {
|
|
394
|
+
m = !0;
|
|
395
|
+
try {
|
|
396
|
+
h &&= (h.disconnect(), null);
|
|
397
|
+
let e = await n.value.getPage(a.value);
|
|
398
|
+
r.value = e;
|
|
399
|
+
let { tiledPage: i, observer: c } = await x(e, {
|
|
400
|
+
scale: o.value,
|
|
401
|
+
cache: p,
|
|
402
|
+
backgroundColor: s
|
|
403
|
+
});
|
|
404
|
+
h = c, t.value.replaceChildren(i.container), f.emit("render_complete", {
|
|
405
|
+
pageNum: a.value,
|
|
406
|
+
scale: o.value
|
|
407
|
+
});
|
|
408
|
+
} catch (e) {
|
|
409
|
+
console.error("[PDF-CORE] renderCurrentPage failed:", e), f.emit("error_occurred", { message: e instanceof Error ? e.message : "Render failed" });
|
|
410
|
+
} finally {
|
|
411
|
+
m = !1;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
return e.autoLoad, {
|
|
416
|
+
containerRef: t,
|
|
417
|
+
doc: n,
|
|
418
|
+
page: r,
|
|
419
|
+
pageCount: i,
|
|
420
|
+
currentPageNum: a,
|
|
421
|
+
currentScale: o,
|
|
422
|
+
isLoading: c,
|
|
423
|
+
error: l,
|
|
424
|
+
events: f,
|
|
425
|
+
loadFile: S,
|
|
426
|
+
renderCurrentPage: C,
|
|
427
|
+
setScale: (e) => new Promise((t) => {
|
|
428
|
+
if (e <= 0) {
|
|
429
|
+
t();
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
y = e, v !== null && (clearTimeout(v), b?.()), b = t, v = setTimeout(async () => {
|
|
433
|
+
v = null;
|
|
434
|
+
let e = y, t = b;
|
|
435
|
+
if (y = null, b = null, e === null || e === o.value) {
|
|
436
|
+
t?.();
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
o.value = e, n.value && await C(), t?.(), f.emit("scale_changed", {
|
|
440
|
+
scale: e,
|
|
441
|
+
previousScale: o.value
|
|
442
|
+
});
|
|
443
|
+
}, 60);
|
|
444
|
+
}),
|
|
445
|
+
reset: () => {
|
|
446
|
+
n.value = null, r.value = null, i.value = 0, a.value = 1, l.value = null, c.value = !1, t.value && t.value.replaceChildren(), f.emit("cleared");
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
//#endregion
|
|
451
|
+
//#region src/vue/useAnnotations.ts
|
|
452
|
+
function j() {
|
|
453
|
+
let e = u([]);
|
|
454
|
+
return {
|
|
455
|
+
annotations: e,
|
|
456
|
+
addMeasureAnnotation: (t, n = 0, r = "px") => {
|
|
457
|
+
e.value = [...e.value, E(t, n, r)];
|
|
458
|
+
},
|
|
459
|
+
addShapeAnnotation: (t, n = "rectangle") => {
|
|
460
|
+
e.value = [...e.value, D(t, n)];
|
|
461
|
+
},
|
|
462
|
+
removeAnnotation: (t) => {
|
|
463
|
+
e.value = e.value.filter((e) => e.id !== t);
|
|
464
|
+
},
|
|
465
|
+
clearAnnotations: () => {
|
|
466
|
+
e.value = [];
|
|
467
|
+
},
|
|
468
|
+
replaceAnnotations: (t) => {
|
|
469
|
+
e.value = t.map(O);
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
//#endregion
|
|
474
|
+
//#region src/vue/useMeasurement.ts
|
|
475
|
+
function M() {
|
|
476
|
+
let e = u([]);
|
|
477
|
+
return {
|
|
478
|
+
points: e,
|
|
479
|
+
addPoint: (t) => {
|
|
480
|
+
e.value = [...e.value, t];
|
|
481
|
+
},
|
|
482
|
+
clearPoints: () => {
|
|
483
|
+
e.value = [];
|
|
484
|
+
},
|
|
485
|
+
distance: t(() => {
|
|
486
|
+
if (e.value.length < 2) return 0;
|
|
487
|
+
let [t, n] = e.value.slice(-2);
|
|
488
|
+
return Math.hypot(n.x - t.x, n.y - t.y);
|
|
489
|
+
})
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
//#endregion
|
|
493
|
+
//#region src/vue/useInteraction.ts
|
|
494
|
+
function N() {
|
|
495
|
+
let { annotations: e, addMeasureAnnotation: t, clearAnnotations: n } = j(), { points: r, addPoint: i, clearPoints: a, distance: o } = M(), s = u(!1);
|
|
496
|
+
return {
|
|
497
|
+
points: r,
|
|
498
|
+
annotations: e,
|
|
499
|
+
isMeasuring: s,
|
|
500
|
+
startMeasure: () => {
|
|
501
|
+
s.value = !0, a();
|
|
502
|
+
},
|
|
503
|
+
addPoint: (e) => {
|
|
504
|
+
i(e), s.value && r.value.length >= 2 && t(r.value, o.value);
|
|
505
|
+
},
|
|
506
|
+
finishMeasure: (e) => {
|
|
507
|
+
r.value.length >= 2 && t(r.value, o.value, e || "px"), s.value = !1, a();
|
|
508
|
+
},
|
|
509
|
+
clear: () => {
|
|
510
|
+
n(), a(), s.value = !1;
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
//#endregion
|
|
515
|
+
//#region src/components/interaction.ts
|
|
516
|
+
function P() {
|
|
517
|
+
let e = [], t = [], n = "none", r = null;
|
|
518
|
+
return {
|
|
519
|
+
get points() {
|
|
520
|
+
return e;
|
|
521
|
+
},
|
|
522
|
+
get annotations() {
|
|
523
|
+
return t;
|
|
524
|
+
},
|
|
525
|
+
get mode() {
|
|
526
|
+
return n;
|
|
527
|
+
},
|
|
528
|
+
get selectedAnnotationId() {
|
|
529
|
+
return r;
|
|
530
|
+
},
|
|
531
|
+
setMode(t) {
|
|
532
|
+
n = t, t === "none" && (e = []);
|
|
533
|
+
},
|
|
534
|
+
addPoint(i) {
|
|
535
|
+
if (e = [...e, i], n === "measure" && e.length >= 2) {
|
|
536
|
+
let n = E([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));
|
|
537
|
+
return t = [...t, n], r = n.id, e = [], n;
|
|
538
|
+
}
|
|
539
|
+
if (n === "rectangle" && e.length >= 2) {
|
|
540
|
+
let n = D([e[e.length - 2], e[e.length - 1]], "rectangle");
|
|
541
|
+
return t = [...t, n], r = n.id, e = [], n;
|
|
542
|
+
}
|
|
543
|
+
return null;
|
|
544
|
+
},
|
|
545
|
+
selectAnnotation(e) {
|
|
546
|
+
r = e;
|
|
547
|
+
},
|
|
548
|
+
deleteAnnotation(e) {
|
|
549
|
+
let n = t.find((t) => t.id === e);
|
|
550
|
+
return n ? (t = t.filter((t) => t.id !== e), r === e && (r = null), n) : null;
|
|
551
|
+
},
|
|
552
|
+
deleteSelectedAnnotation() {
|
|
553
|
+
return r ? this.deleteAnnotation(r) : null;
|
|
554
|
+
},
|
|
555
|
+
clear() {
|
|
556
|
+
e = [], t = [], n = "none", r = null;
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
//#endregion
|
|
561
|
+
//#region src/components/useAnnotationCanvas.ts
|
|
562
|
+
function F(e) {
|
|
563
|
+
let { annotationCanvas: t, rootRef: n, interaction: r, previewPoint: i } = e, a = (e) => {
|
|
564
|
+
let t = e.currentTarget.getBoundingClientRect();
|
|
565
|
+
return {
|
|
566
|
+
x: e.clientX - t.left,
|
|
567
|
+
y: e.clientY - t.top
|
|
568
|
+
};
|
|
569
|
+
}, o = (e, t, n) => {
|
|
570
|
+
let r = n.x - t.x, i = n.y - t.y, a = r * r + i * i;
|
|
571
|
+
if (a === 0) return Math.hypot(e.x - t.x, e.y - t.y);
|
|
572
|
+
let o = Math.max(0, Math.min(1, ((e.x - t.x) * r + (e.y - t.y) * i) / a)), s = t.x + o * r, c = t.y + o * i;
|
|
573
|
+
return Math.hypot(e.x - s, e.y - c);
|
|
574
|
+
}, s = (e, t) => {
|
|
575
|
+
if (t.kind === "measure") {
|
|
576
|
+
let [n, r] = t.points;
|
|
577
|
+
return o(e, n, r) <= 8;
|
|
578
|
+
}
|
|
579
|
+
if (t.kind === "shape" && t.shapeType === "rectangle") {
|
|
580
|
+
let [n, r] = t.points, i = Math.min(n.x, r.x), a = Math.min(n.y, r.y), o = Math.abs(n.x - r.x), s = Math.abs(n.y - r.y);
|
|
581
|
+
return e.x >= i - 4 && e.x <= i + o + 4 && e.y >= a - 4 && e.y <= a + s + 4;
|
|
582
|
+
}
|
|
583
|
+
return !1;
|
|
584
|
+
}, c = () => {
|
|
585
|
+
if (!t.value) return;
|
|
586
|
+
let e = t.value.getContext("2d");
|
|
587
|
+
e && (e.clearRect(0, 0, t.value.width, t.value.height), r.annotations.forEach((t) => {
|
|
588
|
+
let n = t.id === r.selectedAnnotationId, i = t.color ?? (t.kind === "measure" ? "#10b981" : "#3b82f6"), a = (t.strokeWidth ?? 2) + (n ? 2 : 0);
|
|
589
|
+
t.kind === "measure" && l(e, t, n, i, a), t.kind === "shape" && t.shapeType === "rectangle" && u(e, t, n, i, a);
|
|
590
|
+
}), i.value && r.points.length === 1 && d(e));
|
|
591
|
+
}, l = (e, t, n, r, i) => {
|
|
592
|
+
let [a, o] = t.points;
|
|
593
|
+
e.save(), e.strokeStyle = n ? "#ef4444" : r, e.lineWidth = i, e.setLineDash(n ? [6, 4] : []), e.beginPath(), e.moveTo(a.x, a.y), e.lineTo(o.x, o.y), e.stroke(), e.setLineDash([]), e.fillStyle = n ? "#ef4444" : r, e.beginPath(), e.arc(a.x, a.y, n ? 4 : 3, 0, Math.PI * 2), e.arc(o.x, o.y, n ? 4 : 3, 0, Math.PI * 2), e.fill(), e.font = "12px sans-serif", e.fillText(t.label ?? `${t.value?.toFixed(1) ?? 0}`, o.x + 6, o.y - 6), e.restore();
|
|
594
|
+
}, u = (e, t, n, r, i) => {
|
|
595
|
+
let [a, o] = t.points, s = Math.min(a.x, o.x), c = Math.min(a.y, o.y), l = Math.abs(a.x - o.x), u = Math.abs(a.y - o.y);
|
|
596
|
+
e.save(), e.strokeStyle = n ? "#ef4444" : r, e.lineWidth = i, e.setLineDash(n ? [6, 4] : []), e.strokeRect(s, c, l, u), e.fillStyle = n ? "rgba(239, 68, 68, 0.12)" : "rgba(59, 130, 246, 0.12)", e.fillRect(s, c, l, u), e.setLineDash([]), e.fillStyle = n ? "#ef4444" : r, e.font = "12px sans-serif", e.fillText(t.label ?? "", s + 6, c + 16), e.restore();
|
|
597
|
+
}, d = (e) => {
|
|
598
|
+
let t = r.points[0], n = i.value;
|
|
599
|
+
if (e.save(), e.strokeStyle = r.mode === "measure" ? "#8b5cf6" : "#2563eb", e.lineWidth = 2, e.setLineDash([6, 4]), r.mode === "measure") e.beginPath(), e.moveTo(t.x, t.y), e.lineTo(n.x, n.y), e.stroke(), e.beginPath(), e.arc(t.x, t.y, 3, 0, Math.PI * 2), e.arc(n.x, n.y, 3, 0, Math.PI * 2), e.fillStyle = "#8b5cf6", e.fill();
|
|
600
|
+
else if (r.mode === "rectangle") {
|
|
601
|
+
let r = Math.min(t.x, n.x), i = Math.min(t.y, n.y), a = Math.abs(t.x - n.x), o = Math.abs(t.y - n.y);
|
|
602
|
+
e.strokeRect(r, i, a, o);
|
|
603
|
+
}
|
|
604
|
+
e.restore();
|
|
605
|
+
};
|
|
606
|
+
return {
|
|
607
|
+
getCanvasPoint: a,
|
|
608
|
+
getDistanceToSegment: o,
|
|
609
|
+
hitTestAnnotation: s,
|
|
610
|
+
drawAnnotations: c,
|
|
611
|
+
syncCanvasSize: () => {
|
|
612
|
+
if (!n.value || !t.value) return;
|
|
613
|
+
let e = n.value.getBoundingClientRect(), r = t.value;
|
|
614
|
+
r.width = e.width * window.devicePixelRatio, r.height = e.height * window.devicePixelRatio, r.style.width = `${e.width}px`, r.style.height = `${e.height}px`;
|
|
615
|
+
let i = r.getContext("2d");
|
|
616
|
+
i && i.setTransform(window.devicePixelRatio, 0, 0, window.devicePixelRatio, 0, 0);
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
//#endregion
|
|
621
|
+
//#region src/components/usePointerInteraction.ts
|
|
622
|
+
function I(e) {
|
|
623
|
+
let { annotationCanvas: t, interaction: n, previewPoint: r, isRectangleDragging: i, getCanvasPoint: a, hitTestAnnotation: o, drawAnnotations: s, deleteSelectedAnnotation: c, emit: l } = e;
|
|
624
|
+
return {
|
|
625
|
+
handlePointerDown: (e) => {
|
|
626
|
+
if (!t.value) return;
|
|
627
|
+
let c = a(e);
|
|
628
|
+
if (n.mode === "measure") {
|
|
629
|
+
if (n.points.length === 0) {
|
|
630
|
+
n.addPoint(c), r.value = c, s(), e.preventDefault();
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
if (n.points.length === 1) {
|
|
634
|
+
let t = n.addPoint(c);
|
|
635
|
+
r.value = null, s(), t && l("annotation-added", {
|
|
636
|
+
id: t.id,
|
|
637
|
+
kind: t.kind
|
|
638
|
+
}), e.preventDefault();
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
if (n.mode === "rectangle" && n.points.length === 0) {
|
|
643
|
+
n.addPoint(c), r.value = c, i.value = !0, s(), e.preventDefault();
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
if (n.mode === "none") {
|
|
647
|
+
let e = n.annotations.find((e) => o(c, e));
|
|
648
|
+
if (e) {
|
|
649
|
+
n.selectAnnotation(e.id), s();
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
n.selectAnnotation(null), s();
|
|
653
|
+
}
|
|
654
|
+
},
|
|
655
|
+
handlePointerMove: (e) => {
|
|
656
|
+
if (n.mode === "none" || !t.value || n.points.length !== 1) return;
|
|
657
|
+
let i = a(e);
|
|
658
|
+
r.value = i, s();
|
|
659
|
+
},
|
|
660
|
+
handlePointerUp: (e) => {
|
|
661
|
+
if (!t.value) return;
|
|
662
|
+
let c = a(e);
|
|
663
|
+
if (n.mode === "rectangle" && i.value && n.points.length === 1) {
|
|
664
|
+
let e = n.addPoint(c);
|
|
665
|
+
r.value = null, i.value = !1, s(), e && l("annotation-added", {
|
|
666
|
+
id: e.id,
|
|
667
|
+
kind: e.kind
|
|
668
|
+
});
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
if (n.mode === "none") {
|
|
672
|
+
let e = n.annotations.find((e) => o(c, e));
|
|
673
|
+
if (e) {
|
|
674
|
+
n.selectAnnotation(e.id), s();
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
n.selectAnnotation(null), s();
|
|
678
|
+
}
|
|
679
|
+
},
|
|
680
|
+
handleKeydown: (e) => {
|
|
681
|
+
(e.key === "Delete" || e.key === "Backspace") && n.selectedAnnotationId && (e.preventDefault(), c(), s());
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
//#endregion
|
|
686
|
+
//#region src/components/useViewerLayout.ts
|
|
687
|
+
var L = (e) => {
|
|
688
|
+
if (e.length < 2) return 0;
|
|
689
|
+
let t = e[0].clientX - e[1].clientX, n = e[0].clientY - e[1].clientY;
|
|
690
|
+
return Math.hypot(t, n);
|
|
691
|
+
}, R = (e) => ({
|
|
692
|
+
x: (e[0].clientX + e[1].clientX) / 2,
|
|
693
|
+
y: (e[0].clientY + e[1].clientY) / 2
|
|
694
|
+
}), z = (e) => {
|
|
695
|
+
let t = C[0], n = Math.abs(e - t);
|
|
696
|
+
for (let r = 1; r < C.length; r++) {
|
|
697
|
+
let i = Math.abs(e - C[r]);
|
|
698
|
+
i < n && (n = i, t = C[r]);
|
|
699
|
+
}
|
|
700
|
+
return t;
|
|
701
|
+
};
|
|
702
|
+
function B(e) {
|
|
703
|
+
let { viewerRef: n, rootRef: r, pdfLayerRef: i, currentScale: a, setScale: o, zoomSpeed: s, theme: c, syncCanvasSize: l, drawAnnotations: u } = e, d = 0, f = 1, p = null, m = 0;
|
|
704
|
+
return {
|
|
705
|
+
containerStyle: t(() => ({
|
|
706
|
+
width: "100%",
|
|
707
|
+
height: "100%",
|
|
708
|
+
background: c === "dark" ? "#1e1e1e" : "#ffffff",
|
|
709
|
+
overflow: "auto",
|
|
710
|
+
borderRadius: "8px",
|
|
711
|
+
border: c === "dark" ? "1px solid #374151" : "1px solid #e2e8f0",
|
|
712
|
+
position: "relative",
|
|
713
|
+
touchAction: "pan-x pan-y",
|
|
714
|
+
display: "flex"
|
|
715
|
+
})),
|
|
716
|
+
adjustLayout: (e = !1) => {
|
|
717
|
+
let t = n.value, a = r.value, o = i.value;
|
|
718
|
+
if (!t || !a || !o) return;
|
|
719
|
+
let s = t.clientWidth, c = t.clientHeight, d = o.scrollWidth || s, f = o.scrollHeight || c, p = Math.max(d, s * 1.5), m = Math.max(f, c * 1.5);
|
|
720
|
+
a.style.width = `${p}px`, a.style.height = `${m}px`, e && (t.scrollLeft = p - s, t.scrollTop = (m - c) / 2), l(), u();
|
|
721
|
+
},
|
|
722
|
+
handleWheel: (e) => {
|
|
723
|
+
e.preventDefault();
|
|
724
|
+
let t = n.value, c = r.value, l = i.value;
|
|
725
|
+
if (!t || !c || !l) return;
|
|
726
|
+
let u = e.deltaY < 0 ? "in" : "out", d = Math.max(1, s ?? 1), f = Math.round(a.value * 100);
|
|
727
|
+
for (let e = 0; e < d; e++) {
|
|
728
|
+
let e = w(f, u);
|
|
729
|
+
if (e === f) break;
|
|
730
|
+
f = e;
|
|
731
|
+
}
|
|
732
|
+
let p = f / 100;
|
|
733
|
+
if (p === a.value) return;
|
|
734
|
+
let m = a.value, h = p / m, g = t.getBoundingClientRect(), _ = e.clientX - g.left, v = e.clientY - g.top, y = _ + t.scrollLeft, b = v + t.scrollTop, x = l.scrollWidth, S = l.scrollHeight, C = x / m, T = S / m, E = C * p, D = T * p, O = t.clientWidth, k = t.clientHeight, A = y * h - _, j = b * h - v;
|
|
735
|
+
c.style.width = `${Math.max(E, A + O, O * 1.5)}px`, c.style.height = `${Math.max(D, j + k, k * 1.5)}px`, c.offsetWidth, t.scrollLeft = A, t.scrollTop = j, o(p);
|
|
736
|
+
},
|
|
737
|
+
handleTouchStart: (e) => {
|
|
738
|
+
e.touches.length === 2 && (d = L(e.touches), f = a.value, p = R(e.touches), m = a.value);
|
|
739
|
+
},
|
|
740
|
+
handleTouchMove: (e) => {
|
|
741
|
+
if (e.touches.length !== 2 || d === 0) return;
|
|
742
|
+
e.preventDefault();
|
|
743
|
+
let t = L(e.touches);
|
|
744
|
+
if (Math.abs(t - d) < 5) return;
|
|
745
|
+
let s = t / d, c = f * s, l = z(Math.round(Math.max(.05, Math.min(128, c)) * 100)) / 100;
|
|
746
|
+
if (l === m) return;
|
|
747
|
+
m = l;
|
|
748
|
+
let u = n.value;
|
|
749
|
+
if (u && p) {
|
|
750
|
+
let e = u.getBoundingClientRect(), t = p.x - e.left, n = p.y - e.top, s = t + u.scrollLeft, c = n + u.scrollTop, d = l / a.value, f = r.value, m = i.value;
|
|
751
|
+
if (f && m) {
|
|
752
|
+
let e = u.clientWidth, r = u.clientHeight, i = a.value, o = m.scrollWidth / i, p = m.scrollHeight / i, h = o * l, g = p * l, _ = s * d - t, v = c * d - n;
|
|
753
|
+
f.style.width = `${Math.max(h, _ + e, e * 1.5)}px`, f.style.height = `${Math.max(g, v + r, r * 1.5)}px`, f.offsetWidth;
|
|
754
|
+
}
|
|
755
|
+
u.scrollLeft = s * d - t, u.scrollTop = c * d - n, o(l);
|
|
756
|
+
}
|
|
757
|
+
},
|
|
758
|
+
handleTouchEnd: () => {
|
|
759
|
+
d = 0, p = null, m = 0;
|
|
760
|
+
}
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
//#endregion
|
|
764
|
+
//#region src/types/tools.ts
|
|
765
|
+
var V = {
|
|
766
|
+
mode: "none",
|
|
767
|
+
measureSubType: "distance"
|
|
768
|
+
}, H = class {
|
|
769
|
+
constructor(e) {
|
|
770
|
+
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 ?? {
|
|
771
|
+
scale: 1,
|
|
772
|
+
unit: "px",
|
|
773
|
+
precision: 2
|
|
774
|
+
}, this.eventTrigger = e.eventTrigger;
|
|
775
|
+
}
|
|
776
|
+
getActive() {
|
|
777
|
+
return this._active;
|
|
778
|
+
}
|
|
779
|
+
setActive(e) {
|
|
780
|
+
this._active !== e && (this._active = e, !e && this._isStart && this.interrupt());
|
|
781
|
+
}
|
|
782
|
+
getScenePoint(e) {
|
|
783
|
+
return this.coordProvider.screenToScene(e);
|
|
784
|
+
}
|
|
785
|
+
distance(e, t) {
|
|
786
|
+
return Math.hypot(t.x - e.x, t.y - e.y);
|
|
787
|
+
}
|
|
788
|
+
calibrate(e) {
|
|
789
|
+
let { scale: t, unit: n, precision: r } = this.calibration, i = e * t, a = parseFloat(i.toFixed(typeof r == "number" ? r : 2));
|
|
790
|
+
return {
|
|
791
|
+
value: a,
|
|
792
|
+
label: `${a} ${n}`
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
generateId() {
|
|
796
|
+
return `${this.currentType}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
797
|
+
}
|
|
798
|
+
buildResult(e, t) {
|
|
799
|
+
let { value: n, label: r } = this.calibrate(t);
|
|
800
|
+
return {
|
|
801
|
+
id: this.generateId(),
|
|
802
|
+
type: this.currentType,
|
|
803
|
+
points: e,
|
|
804
|
+
value: n,
|
|
805
|
+
unit: this.calibration.unit,
|
|
806
|
+
label: r,
|
|
807
|
+
createdAt: Date.now()
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
isDrag(e) {
|
|
811
|
+
if (!this._dragStart) return !1;
|
|
812
|
+
let t = e.clientX - this._dragStart.x, n = e.clientY - this._dragStart.y;
|
|
813
|
+
return Math.hypot(t, n) > this._dragThreshold;
|
|
814
|
+
}
|
|
815
|
+
emitMeasureStart() {
|
|
816
|
+
let e = { type: this.currentType };
|
|
817
|
+
this.eventTrigger.emit("measure_start", e);
|
|
818
|
+
}
|
|
819
|
+
emitMeasureCreated(e) {
|
|
820
|
+
let t = {
|
|
821
|
+
id: e.id,
|
|
822
|
+
type: this.currentType,
|
|
823
|
+
points: e.points,
|
|
824
|
+
value: e.value,
|
|
825
|
+
unit: e.unit,
|
|
826
|
+
label: e.label,
|
|
827
|
+
result: e
|
|
828
|
+
};
|
|
829
|
+
this.eventTrigger.emit("measure_created", t);
|
|
830
|
+
}
|
|
831
|
+
emitMeasureCancel() {
|
|
832
|
+
let e = { type: this.currentType };
|
|
833
|
+
this.eventTrigger.emit("measure_cancel", e);
|
|
834
|
+
}
|
|
835
|
+
interrupt() {
|
|
836
|
+
let e = this._isStart;
|
|
837
|
+
this.resetState(), e && this.emitMeasureCancel();
|
|
838
|
+
}
|
|
839
|
+
finalize(e) {
|
|
840
|
+
if (this._points.length < 2) return null;
|
|
841
|
+
let t = this.buildResult([...this._points], e);
|
|
842
|
+
return this._measureList.set(t.id, {
|
|
843
|
+
points: [...this._points],
|
|
844
|
+
result: t
|
|
845
|
+
}), this.emitMeasureCreated(t), this.resetState(), t;
|
|
846
|
+
}
|
|
847
|
+
resetState() {
|
|
848
|
+
this._startPoint = null, this._endPoint = null, this._points = [], this._dragStart = null, this._isStart = !1, this._isEnd = !1, this._isMeasuring = !1, this._isDragging = !1;
|
|
849
|
+
}
|
|
850
|
+
destroy() {
|
|
851
|
+
this._measureList.clear(), this.resetState(), this._active = !1;
|
|
852
|
+
}
|
|
853
|
+
}, U = class extends H {
|
|
854
|
+
constructor(e) {
|
|
855
|
+
super(e), this.currentType = "distance", this._previewEnd = null;
|
|
856
|
+
}
|
|
857
|
+
get previewEnd() {
|
|
858
|
+
return this._previewEnd;
|
|
859
|
+
}
|
|
860
|
+
onPointerDown(e) {
|
|
861
|
+
if (!this._active) return;
|
|
862
|
+
this._dragStart = {
|
|
863
|
+
x: e.clientX,
|
|
864
|
+
y: e.clientY
|
|
865
|
+
};
|
|
866
|
+
let t = this.getScenePoint(e);
|
|
867
|
+
if (!this._isStart) {
|
|
868
|
+
this._isStart = !0, this._startPoint = t, this._points = [t], this._previewEnd = null;
|
|
869
|
+
return;
|
|
870
|
+
}
|
|
871
|
+
this._isStart && !this._isEnd && (this._endPoint = t, this._points = [...this._points, t], this._isEnd = !0, this._isMeasuring = !0);
|
|
872
|
+
}
|
|
873
|
+
onPointerMove(e) {
|
|
874
|
+
if (this._active && !this._isEnd) {
|
|
875
|
+
if (this._isStart && !this._isMeasuring) {
|
|
876
|
+
if (this.isDrag(e)) {
|
|
877
|
+
this._isDragging = !0, this.interrupt();
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
return;
|
|
881
|
+
}
|
|
882
|
+
this._isStart && this._isMeasuring && (this._previewEnd = this.getScenePoint(e));
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
onPointerUp(e) {
|
|
886
|
+
if (this._active) {
|
|
887
|
+
if (this._dragStart = null, this._isStart && !this._isMeasuring) {
|
|
888
|
+
this._isDragging || (this._isMeasuring = !0, this.emitMeasureStart()), this._isDragging = !1;
|
|
889
|
+
return;
|
|
890
|
+
}
|
|
891
|
+
if (this._isEnd && this._isMeasuring) {
|
|
892
|
+
let e = this._startPoint, t = this._endPoint;
|
|
893
|
+
if (Math.abs(t.x - e.x) < .01 && Math.abs(t.y - e.y) < .01) {
|
|
894
|
+
this.interrupt();
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
let n = this.distance(e, t);
|
|
898
|
+
this.finalize(n), this._previewEnd = null;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
interrupt() {
|
|
903
|
+
this._previewEnd = null, super.interrupt();
|
|
904
|
+
}
|
|
905
|
+
}, W = class extends H {
|
|
906
|
+
constructor(e) {
|
|
907
|
+
super(e), this.currentType = "angle", this._secondPoint = null, this._thirdPoint = null;
|
|
908
|
+
}
|
|
909
|
+
onPointerDown(e) {
|
|
910
|
+
if (!this._active) return;
|
|
911
|
+
let t = this.getScenePoint(e);
|
|
912
|
+
if (!this._isStart) {
|
|
913
|
+
this._isStart = !0, this._startPoint = t, this._points = [t];
|
|
914
|
+
return;
|
|
915
|
+
}
|
|
916
|
+
if (this._points.length === 1) {
|
|
917
|
+
this._secondPoint = t, this._points = [...this._points, t];
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
this._points.length === 2 && (this._thirdPoint = t, this._points = [...this._points, t], this._endPoint = t, this._isEnd = !0);
|
|
921
|
+
}
|
|
922
|
+
onPointerMove(e) {}
|
|
923
|
+
onPointerUp(e) {
|
|
924
|
+
if (this._active && this._isEnd && this._points.length >= 3) {
|
|
925
|
+
let e = this._points[0], t = this._points[1], n = this._points[2], r = this.calcAngle(e, t, n);
|
|
926
|
+
this.finalize(r);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
calcAngle(e, t, n) {
|
|
930
|
+
let r = t.x - e.x, i = t.y - e.y, a = n.x - e.x, o = n.y - e.y, s = r * a + i * o, c = Math.hypot(r, i), l = Math.hypot(a, o);
|
|
931
|
+
if (c === 0 || l === 0) return 0;
|
|
932
|
+
let u = Math.max(-1, Math.min(1, s / (c * l)));
|
|
933
|
+
return parseFloat((Math.acos(u) * 180 / Math.PI).toFixed(2));
|
|
934
|
+
}
|
|
935
|
+
}, G = class extends H {
|
|
936
|
+
constructor(e) {
|
|
937
|
+
super(e), this.currentType = "area";
|
|
938
|
+
}
|
|
939
|
+
onPointerDown(e) {
|
|
940
|
+
if (!this._active) return;
|
|
941
|
+
let t = this.getScenePoint(e);
|
|
942
|
+
if (!this._isStart) {
|
|
943
|
+
this._isStart = !0, this._startPoint = t, this._points = [t];
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
this._points = [...this._points, t];
|
|
947
|
+
}
|
|
948
|
+
onPointerMove(e) {}
|
|
949
|
+
onPointerUp(e) {}
|
|
950
|
+
finish() {
|
|
951
|
+
if (this._points.length < 3) return;
|
|
952
|
+
let e = this.calcPolygonArea(this._points);
|
|
953
|
+
this.finalize(e);
|
|
954
|
+
}
|
|
955
|
+
calcPolygonArea(e) {
|
|
956
|
+
let t = 0, n = e.length;
|
|
957
|
+
for (let r = 0; r < n; r++) {
|
|
958
|
+
let i = (r + 1) % n;
|
|
959
|
+
t += e[r].x * e[i].y, t -= e[i].x * e[r].y;
|
|
960
|
+
}
|
|
961
|
+
return Math.abs(t) / 2;
|
|
962
|
+
}
|
|
963
|
+
}, K = class {
|
|
964
|
+
get currentType() {
|
|
965
|
+
return this._currentSubType;
|
|
966
|
+
}
|
|
967
|
+
constructor(e) {
|
|
968
|
+
this.TOOLNAME = "measure", this._currentSubType = "distance", this._active = !1, this._isCreating = !1, this._resultList = /* @__PURE__ */ new Map(), this._onMeasureStart = () => {
|
|
969
|
+
this._isCreating = !0;
|
|
970
|
+
}, this._onMeasureCreated = (e) => {
|
|
971
|
+
this._isCreating = !1, this._resultList.set(e.result.id, e.result);
|
|
972
|
+
}, this.events = e.eventTrigger ?? new k();
|
|
973
|
+
let t = {
|
|
974
|
+
coordProvider: e.coordProvider,
|
|
975
|
+
calibration: e.calibration ?? {
|
|
976
|
+
scale: 1,
|
|
977
|
+
unit: "px",
|
|
978
|
+
precision: 2
|
|
979
|
+
},
|
|
980
|
+
eventTrigger: this.events
|
|
981
|
+
};
|
|
982
|
+
this.distanceMeasure = new U(t), this.angleMeasure = new W(t), this.areaMeasure = new G(t), this._subTools = /* @__PURE__ */ new Map([
|
|
983
|
+
["distance", this.distanceMeasure],
|
|
984
|
+
["angle", this.angleMeasure],
|
|
985
|
+
["area", this.areaMeasure]
|
|
986
|
+
]), this.events.on("measure_start", this._onMeasureStart), this.events.on("measure_created", this._onMeasureCreated);
|
|
987
|
+
}
|
|
988
|
+
get subType() {
|
|
989
|
+
return this._currentSubType;
|
|
990
|
+
}
|
|
991
|
+
setSubType(e) {
|
|
992
|
+
if (this._currentSubType === e) return;
|
|
993
|
+
this._currentSubType, this._subTools.get(this._currentSubType)?.setActive(!1), this._currentSubType = e;
|
|
994
|
+
let t = {
|
|
995
|
+
previous: this.TOOLNAME,
|
|
996
|
+
current: this.TOOLNAME,
|
|
997
|
+
subType: e
|
|
998
|
+
};
|
|
999
|
+
this.events.emit("tool_mode_changed", t), this._active && this._subTools.get(e)?.setActive(!0);
|
|
1000
|
+
}
|
|
1001
|
+
getActive() {
|
|
1002
|
+
return this._active;
|
|
1003
|
+
}
|
|
1004
|
+
get isCreating() {
|
|
1005
|
+
return this._isCreating;
|
|
1006
|
+
}
|
|
1007
|
+
setActive(e) {
|
|
1008
|
+
if (this._active === e) return;
|
|
1009
|
+
if (this._active = e, e) this._subTools.get(this._currentSubType)?.setActive(e);
|
|
1010
|
+
else for (let e of this._subTools.values()) e.setActive(!1);
|
|
1011
|
+
let t = {
|
|
1012
|
+
active: e,
|
|
1013
|
+
toolName: this.TOOLNAME
|
|
1014
|
+
};
|
|
1015
|
+
this.events.emit("tool_active", t);
|
|
1016
|
+
}
|
|
1017
|
+
onPointerDown(e) {
|
|
1018
|
+
this._active && this._subTools.get(this._currentSubType)?.onPointerDown(e);
|
|
1019
|
+
}
|
|
1020
|
+
onPointerMove(e) {
|
|
1021
|
+
this._active && this._subTools.get(this._currentSubType)?.onPointerMove(e);
|
|
1022
|
+
}
|
|
1023
|
+
onPointerUp(e) {
|
|
1024
|
+
this._active && this._subTools.get(this._currentSubType)?.onPointerUp(e);
|
|
1025
|
+
}
|
|
1026
|
+
getResults() {
|
|
1027
|
+
return Array.from(this._resultList.values());
|
|
1028
|
+
}
|
|
1029
|
+
getResult(e) {
|
|
1030
|
+
return this._resultList.get(e);
|
|
1031
|
+
}
|
|
1032
|
+
removeResult(e) {
|
|
1033
|
+
return this._resultList.delete(e);
|
|
1034
|
+
}
|
|
1035
|
+
clearResults() {
|
|
1036
|
+
this._resultList.clear();
|
|
1037
|
+
}
|
|
1038
|
+
get previewDistanceEnd() {
|
|
1039
|
+
return this.distanceMeasure.previewEnd;
|
|
1040
|
+
}
|
|
1041
|
+
get currentPoints() {
|
|
1042
|
+
return this._subTools.get(this._currentSubType)?._points ?? [];
|
|
1043
|
+
}
|
|
1044
|
+
interrupt() {
|
|
1045
|
+
this._subTools.get(this._currentSubType)?.interrupt();
|
|
1046
|
+
}
|
|
1047
|
+
destroy() {
|
|
1048
|
+
this.events.off("measure_start", this._onMeasureStart), this.events.off("measure_created", this._onMeasureCreated);
|
|
1049
|
+
for (let e of this._subTools.values()) e.destroy();
|
|
1050
|
+
this._subTools.clear(), this._resultList.clear(), this._active = !1;
|
|
1051
|
+
}
|
|
1052
|
+
}, q = class {
|
|
1053
|
+
constructor(e) {
|
|
1054
|
+
this._activeTool = null, this._activeMode = "none", this._tools = /* @__PURE__ */ new Map(), this.events = new k(), this.measureTool = new K({
|
|
1055
|
+
coordProvider: e.coordProvider,
|
|
1056
|
+
calibration: e.calibration,
|
|
1057
|
+
eventTrigger: this.events
|
|
1058
|
+
}), this._tools.set("measure", this.measureTool);
|
|
1059
|
+
}
|
|
1060
|
+
get activeMode() {
|
|
1061
|
+
return this._activeMode;
|
|
1062
|
+
}
|
|
1063
|
+
setMode(e) {
|
|
1064
|
+
if (this._activeMode === e) return;
|
|
1065
|
+
let t = this._activeMode;
|
|
1066
|
+
if (this._activeTool && this._activeTool.setActive(!1), this._activeMode = e, e === "none") this._activeTool = null;
|
|
1067
|
+
else {
|
|
1068
|
+
let t = this._tools.get(e);
|
|
1069
|
+
t ? (this._activeTool = t, t.setActive(!0)) : (console.warn(`[ToolManager] 未注册的工具模式: ${e}`), this._activeTool = null);
|
|
1070
|
+
}
|
|
1071
|
+
let n = {
|
|
1072
|
+
previous: t,
|
|
1073
|
+
current: e
|
|
1074
|
+
};
|
|
1075
|
+
this.events.emit("tool_mode_changed", n);
|
|
1076
|
+
}
|
|
1077
|
+
getActiveTool() {
|
|
1078
|
+
return this._activeTool;
|
|
1079
|
+
}
|
|
1080
|
+
registerTool(e, t) {
|
|
1081
|
+
this._tools.set(e, t);
|
|
1082
|
+
}
|
|
1083
|
+
onPointerDown(e) {
|
|
1084
|
+
this._activeTool?.onPointerDown(e);
|
|
1085
|
+
}
|
|
1086
|
+
onPointerMove(e) {
|
|
1087
|
+
this._activeTool?.onPointerMove(e);
|
|
1088
|
+
}
|
|
1089
|
+
onPointerUp(e) {
|
|
1090
|
+
this._activeTool?.onPointerUp(e);
|
|
1091
|
+
}
|
|
1092
|
+
interrupt() {
|
|
1093
|
+
this._activeTool?.interrupt();
|
|
1094
|
+
}
|
|
1095
|
+
destroy() {
|
|
1096
|
+
for (let e of this._tools.values()) e.destroy();
|
|
1097
|
+
this._tools.clear(), this.events.destroy(), this._activeTool = null, this._activeMode = "none";
|
|
1098
|
+
}
|
|
1099
|
+
};
|
|
1100
|
+
//#endregion
|
|
1101
|
+
//#region src/components/useViewerManager.ts
|
|
1102
|
+
function ee(e) {
|
|
1103
|
+
let { drawAnnotations: t, currentScale: n, setScale: r, viewerRef: i, adjustLayout: o, screenToScene: s } = e, c = new q({ coordProvider: {
|
|
1104
|
+
screenToScene: s,
|
|
1105
|
+
sceneToScreen: (e) => ({
|
|
1106
|
+
x: 0,
|
|
1107
|
+
y: 0
|
|
1108
|
+
})
|
|
1109
|
+
} }), l = d([]), u = d(null), f = () => {
|
|
1110
|
+
let e = c.measureTool.getResults().map((e) => ({
|
|
1111
|
+
id: e.id,
|
|
1112
|
+
kind: "measure",
|
|
1113
|
+
points: e.points.map((e) => ({
|
|
1114
|
+
x: e.x,
|
|
1115
|
+
y: e.y
|
|
1116
|
+
})),
|
|
1117
|
+
value: e.value,
|
|
1118
|
+
unit: e.unit,
|
|
1119
|
+
label: e.label,
|
|
1120
|
+
color: "#10b981",
|
|
1121
|
+
strokeWidth: 2,
|
|
1122
|
+
createdAt: e.createdAt
|
|
1123
|
+
}));
|
|
1124
|
+
l.value = e, t();
|
|
1125
|
+
};
|
|
1126
|
+
c.events.on("measure_created", (e) => {
|
|
1127
|
+
f();
|
|
1128
|
+
}), c.events.on("measure_cancel", () => {
|
|
1129
|
+
t();
|
|
1130
|
+
});
|
|
1131
|
+
let p = d("none");
|
|
1132
|
+
return {
|
|
1133
|
+
toolManager: c,
|
|
1134
|
+
mode: p,
|
|
1135
|
+
annotations: l,
|
|
1136
|
+
selectedAnnotationId: u,
|
|
1137
|
+
setMode: (e) => {
|
|
1138
|
+
let n = {
|
|
1139
|
+
measure: "measure",
|
|
1140
|
+
rectangle: "none",
|
|
1141
|
+
none: "none"
|
|
1142
|
+
}[e] ?? "none";
|
|
1143
|
+
p.value = e, c.setMode(n), t();
|
|
1144
|
+
},
|
|
1145
|
+
setMeasureSubType: (e) => {
|
|
1146
|
+
c.measureTool.setSubType(e);
|
|
1147
|
+
},
|
|
1148
|
+
clearInteraction: () => {
|
|
1149
|
+
c.interrupt(), c.measureTool.clearResults(), l.value = [], u.value = null, t();
|
|
1150
|
+
},
|
|
1151
|
+
deleteSelectedAnnotation: () => {
|
|
1152
|
+
u.value && (c.measureTool.removeResult(u.value), u.value = null, f());
|
|
1153
|
+
},
|
|
1154
|
+
selectAnnotation: (e) => {
|
|
1155
|
+
u.value = e, t();
|
|
1156
|
+
},
|
|
1157
|
+
registerManager: () => {
|
|
1158
|
+
let e = {
|
|
1159
|
+
setScale: async (e) => {
|
|
1160
|
+
await r(e), await a(), o(!1);
|
|
1161
|
+
},
|
|
1162
|
+
getScale: () => n.value,
|
|
1163
|
+
getContainerEl: () => i.value
|
|
1164
|
+
}, s = new T();
|
|
1165
|
+
s.registerWithToolManager(c, t, e), window.pdfViewer = s;
|
|
1166
|
+
},
|
|
1167
|
+
unregisterManager: () => {
|
|
1168
|
+
window.pdfViewer?.unregister(), window.pdfViewer = null, c.destroy();
|
|
1169
|
+
}
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
//#endregion
|
|
1173
|
+
//#region src/components/PdfViewer.vue
|
|
1174
|
+
var J = /*#__PURE__*/ ((e, t) => {
|
|
1175
|
+
let n = e.__vccOpts || e;
|
|
1176
|
+
for (let [e, r] of t) n[e] = r;
|
|
1177
|
+
return n;
|
|
1178
|
+
})(/* @__PURE__ */ i({
|
|
1179
|
+
__name: "PdfViewer",
|
|
1180
|
+
props: {
|
|
1181
|
+
modelValue: { default: null },
|
|
1182
|
+
scale: { default: 1.5 },
|
|
1183
|
+
width: { default: "100%" },
|
|
1184
|
+
height: { default: "100%" },
|
|
1185
|
+
theme: { default: "light" },
|
|
1186
|
+
toolbar: {
|
|
1187
|
+
type: Boolean,
|
|
1188
|
+
default: !1
|
|
1189
|
+
},
|
|
1190
|
+
zoomSpeed: { default: 1 }
|
|
1191
|
+
},
|
|
1192
|
+
emits: [
|
|
1193
|
+
"loaded",
|
|
1194
|
+
"error",
|
|
1195
|
+
"annotation-added"
|
|
1196
|
+
],
|
|
1197
|
+
setup(e, { expose: t, emit: i }) {
|
|
1198
|
+
let d = e, m = i, h = u(null), g = u(null), _ = u(null), v = u(null), { containerRef: y, loadFile: b, doc: x, pageCount: S, currentPageNum: C, error: w, currentScale: T, setScale: E, reset: D, events: O } = A({
|
|
1199
|
+
autoLoad: !1,
|
|
1200
|
+
scale: d.scale,
|
|
1201
|
+
backgroundColor: d.theme === "dark" ? "#1e1e1e" : "rgb(255,255,255)"
|
|
1202
|
+
}), k = P(), j = u(null), M = u(!1), { drawAnnotations: N, syncCanvasSize: L, getCanvasPoint: R, hitTestAnnotation: z } = F({
|
|
1203
|
+
annotationCanvas: v,
|
|
1204
|
+
rootRef: g,
|
|
1205
|
+
interaction: k,
|
|
1206
|
+
previewPoint: j
|
|
1207
|
+
}), { containerStyle: V, adjustLayout: H, handleWheel: U, handleTouchStart: W, handleTouchMove: G, handleTouchEnd: K } = B({
|
|
1208
|
+
viewerRef: h,
|
|
1209
|
+
rootRef: g,
|
|
1210
|
+
pdfLayerRef: _,
|
|
1211
|
+
currentScale: T,
|
|
1212
|
+
setScale: E,
|
|
1213
|
+
zoomSpeed: d.zoomSpeed ?? 1,
|
|
1214
|
+
theme: d.theme,
|
|
1215
|
+
syncCanvasSize: L,
|
|
1216
|
+
drawAnnotations: N
|
|
1217
|
+
}), { setMode: q, clearInteraction: J, deleteSelectedAnnotation: Y, selectAnnotation: te, registerManager: ne, unregisterManager: re } = ee({
|
|
1218
|
+
drawAnnotations: N,
|
|
1219
|
+
currentScale: T,
|
|
1220
|
+
setScale: E,
|
|
1221
|
+
viewerRef: h,
|
|
1222
|
+
adjustLayout: H,
|
|
1223
|
+
screenToScene: (e) => {
|
|
1224
|
+
let t = R(e);
|
|
1225
|
+
return {
|
|
1226
|
+
x: t.x,
|
|
1227
|
+
y: t.y
|
|
1228
|
+
};
|
|
1229
|
+
}
|
|
1230
|
+
}), { handlePointerDown: X, handlePointerMove: Z, handlePointerUp: Q, handleKeydown: $ } = I({
|
|
1231
|
+
annotationCanvas: v,
|
|
1232
|
+
interaction: k,
|
|
1233
|
+
previewPoint: j,
|
|
1234
|
+
isRectangleDragging: M,
|
|
1235
|
+
getCanvasPoint: R,
|
|
1236
|
+
hitTestAnnotation: z,
|
|
1237
|
+
drawAnnotations: N,
|
|
1238
|
+
deleteSelectedAnnotation: Y,
|
|
1239
|
+
emit: m
|
|
1240
|
+
});
|
|
1241
|
+
return O.on("loaded", (e) => {
|
|
1242
|
+
m("loaded", {
|
|
1243
|
+
pageCount: e.pageCount,
|
|
1244
|
+
currentPage: e.currentPage
|
|
1245
|
+
});
|
|
1246
|
+
}), O.on("error_occurred", (e) => {
|
|
1247
|
+
m("error", { message: e.message });
|
|
1248
|
+
}), p(() => k.annotations.length, () => {
|
|
1249
|
+
N();
|
|
1250
|
+
}), p(() => d.scale, async (e) => {
|
|
1251
|
+
e && e !== T.value && (await E(e), await a(), H());
|
|
1252
|
+
}), p(() => d.modelValue, async (e) => {
|
|
1253
|
+
e && (await b(e), await a(), H(!0));
|
|
1254
|
+
}, {
|
|
1255
|
+
immediate: !0,
|
|
1256
|
+
flush: "post"
|
|
1257
|
+
}), c(() => {
|
|
1258
|
+
y.value = _.value, L(), N(), window.addEventListener("keydown", $), ne(), h.value && (h.value.addEventListener("touchstart", W, { passive: !0 }), h.value.addEventListener("touchmove", G, { passive: !1 }), h.value.addEventListener("touchend", K));
|
|
1259
|
+
}), s(() => {
|
|
1260
|
+
window.removeEventListener("keydown", $), h.value && (h.value.removeEventListener("touchstart", W), h.value.removeEventListener("touchmove", G), h.value.removeEventListener("touchend", K)), re();
|
|
1261
|
+
}), t({
|
|
1262
|
+
load: async (e) => {
|
|
1263
|
+
await b(e);
|
|
1264
|
+
},
|
|
1265
|
+
clear: () => {
|
|
1266
|
+
D();
|
|
1267
|
+
},
|
|
1268
|
+
setMode: q,
|
|
1269
|
+
clearInteraction: J,
|
|
1270
|
+
deleteSelectedAnnotation: Y,
|
|
1271
|
+
selectAnnotation: te
|
|
1272
|
+
}), (e, t) => (l(), n("div", {
|
|
1273
|
+
ref_key: "viewerRef",
|
|
1274
|
+
ref: h,
|
|
1275
|
+
class: "pdf-core-viewer",
|
|
1276
|
+
style: o(f(V)),
|
|
1277
|
+
onWheel: t[3] ||= (...e) => f(U) && f(U)(...e)
|
|
1278
|
+
}, [r("div", {
|
|
1279
|
+
ref_key: "rootRef",
|
|
1280
|
+
ref: g,
|
|
1281
|
+
class: "pdf-core-canvas-wrapper"
|
|
1282
|
+
}, [
|
|
1283
|
+
r("div", {
|
|
1284
|
+
ref_key: "pdfLayerRef",
|
|
1285
|
+
ref: _,
|
|
1286
|
+
class: "pdf-core-pdf-layer"
|
|
1287
|
+
}, null, 512),
|
|
1288
|
+
r("canvas", {
|
|
1289
|
+
ref_key: "annotationCanvas",
|
|
1290
|
+
ref: v,
|
|
1291
|
+
class: "pdf-core-annotation-canvas"
|
|
1292
|
+
}, null, 512),
|
|
1293
|
+
r("div", {
|
|
1294
|
+
class: "pdf-core-overlay",
|
|
1295
|
+
onPointerdown: t[0] ||= (...e) => f(X) && f(X)(...e),
|
|
1296
|
+
onPointerup: t[1] ||= (...e) => f(Q) && f(Q)(...e),
|
|
1297
|
+
onPointermove: t[2] ||= (...e) => f(Z) && f(Z)(...e)
|
|
1298
|
+
}, null, 32)
|
|
1299
|
+
], 512)], 36));
|
|
1300
|
+
}
|
|
1301
|
+
}), [["__scopeId", "data-v-0e4941dc"]]);
|
|
1302
|
+
//#endregion
|
|
1303
|
+
//#region src/vue/plugin.ts
|
|
1304
|
+
function Y(e) {
|
|
1305
|
+
e.component("PdfViewer", J);
|
|
1306
|
+
}
|
|
1307
|
+
//#endregion
|
|
1308
|
+
export { W as AngleMeasure, G as AreaMeasure, S as CoordTransformer, V as DEFAULT_TOOL_STATE, U as DistanceMeasure, k as EventTrigger, H as MeasureBase, K as MeasureTool, J as PdfViewer, T as PdfViewerCore, _ as TileLRUCache, q as ToolManager, C as ZOOM_LEVELS, E as createMeasureAnnotation, D as createShapeAnnotation, w as getNextZoom, Y as installPdfCore, g as loadPDF, x as renderPageTiledVirtual, m as setPDFWorkerSrc, j as useAnnotations, h as useDefaultWorker, N as useInteraction, M as useMeasurement, A as usePdfCore };
|