kviewer 0.0.9 → 0.0.10
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/module.json +1 -1
- package/dist/runtime/annotation/engine/editor/editor.d.ts +6 -3
- package/dist/runtime/annotation/engine/editor/editor.js +22 -9
- package/dist/runtime/annotation/engine/editor/selector.d.ts +9 -1
- package/dist/runtime/annotation/engine/editor/selector.js +72 -30
- package/dist/runtime/annotation/engine/painter.d.ts +2 -1
- package/dist/runtime/annotation/engine/painter.js +16 -4
- package/dist/runtime/components/PdfPage.d.vue.ts +6 -1
- package/dist/runtime/components/PdfPage.vue +51 -18
- package/dist/runtime/components/PdfPage.vue.d.ts +6 -1
- package/dist/runtime/components/ToolButton.d.vue.ts +4 -2
- package/dist/runtime/components/ToolButton.vue.d.ts +4 -2
- package/dist/runtime/components/Viewer.vue +213 -164
- package/dist/runtime/components/modals/FreeTextModal.vue +27 -3
- package/dist/runtime/components/tools/ActionTools.vue +4 -5
- package/dist/runtime/composables/useAnnotationEngine.d.ts +1 -0
- package/dist/runtime/composables/useAnnotationEngine.js +4 -1
- package/dist/runtime/composables/useAnnotationHistory.d.ts +1 -0
- package/dist/runtime/composables/useAnnotationHistory.js +10 -3
- package/dist/runtime/composables/useInertiaPanzoom.d.ts +40 -0
- package/dist/runtime/composables/useInertiaPanzoom.js +472 -0
- package/dist/runtime/composables/usePageVirtualization.d.ts +3 -0
- package/dist/runtime/composables/usePageVirtualization.js +23 -0
- package/dist/runtime/composables/useViewerSearch.d.ts +1 -0
- package/dist/runtime/composables/useViewerSearch.js +15 -5
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -64,9 +64,12 @@ export declare abstract class Editor {
|
|
|
64
64
|
addSerializedGroupToLayer(konvaStage: Konva.Stage, konvaString: string): void;
|
|
65
65
|
deleteGroup(id: string, konvaStage: Konva.Stage): void;
|
|
66
66
|
updateStyle(annotationStore: IAnnotationStore, style: IAnnotationStyle): void;
|
|
67
|
-
static Timer: {
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
static Timer: Map<number, {
|
|
68
|
+
id: number;
|
|
69
|
+
callback: (pageNumber: number) => void;
|
|
70
|
+
}>;
|
|
70
71
|
static TimerClear(pageNumber: number): void;
|
|
71
72
|
static TimerStart(pageNumber: number, callback: (pageNumber: number) => void, delay?: number): void;
|
|
73
|
+
/** Immediately execute and clear all pending timers (e.g. before export). */
|
|
74
|
+
static flushAllTimers(): void;
|
|
72
75
|
}
|
|
@@ -231,18 +231,31 @@ export class Editor {
|
|
|
231
231
|
updateStyle(annotationStore, style) {
|
|
232
232
|
this.changeStyle(annotationStore, style);
|
|
233
233
|
}
|
|
234
|
-
static Timer =
|
|
234
|
+
static Timer = /* @__PURE__ */ new Map();
|
|
235
235
|
static TimerClear(pageNumber) {
|
|
236
|
-
const
|
|
237
|
-
if (
|
|
238
|
-
window.clearTimeout(
|
|
236
|
+
const entry = Editor.Timer.get(pageNumber);
|
|
237
|
+
if (entry) {
|
|
238
|
+
window.clearTimeout(entry.id);
|
|
239
|
+
Editor.Timer.delete(pageNumber);
|
|
239
240
|
}
|
|
240
241
|
}
|
|
241
242
|
static TimerStart(pageNumber, callback, delay = 1e3) {
|
|
242
|
-
Editor.Timer
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
243
|
+
Editor.Timer.set(pageNumber, {
|
|
244
|
+
callback,
|
|
245
|
+
id: window.setTimeout(() => {
|
|
246
|
+
Editor.Timer.delete(pageNumber);
|
|
247
|
+
if (typeof callback === "function") {
|
|
248
|
+
callback(pageNumber);
|
|
249
|
+
}
|
|
250
|
+
}, delay)
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
/** Immediately execute and clear all pending timers (e.g. before export). */
|
|
254
|
+
static flushAllTimers() {
|
|
255
|
+
for (const [pageNumber, entry] of Editor.Timer) {
|
|
256
|
+
window.clearTimeout(entry.id);
|
|
257
|
+
Editor.Timer.delete(pageNumber);
|
|
258
|
+
entry.callback(pageNumber);
|
|
259
|
+
}
|
|
247
260
|
}
|
|
248
261
|
}
|
|
@@ -13,6 +13,13 @@ export interface ISelectorOptions {
|
|
|
13
13
|
onFreeTextDoubleClick?: (id: string) => void;
|
|
14
14
|
/** When provided and returns true, only pen/mouse input can interact. */
|
|
15
15
|
getStylusModeEnabled?: () => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Toggle external gesture handlers (e.g. panzoom) off while an annotation
|
|
18
|
+
* is being dragged/transformed. Without this, on mobile the panzoom
|
|
19
|
+
* single-finger pan runs in parallel with Konva's shape drag and both
|
|
20
|
+
* CSS transforms compete every frame, causing visible lag.
|
|
21
|
+
*/
|
|
22
|
+
setExternalGesturesEnabled?: (enabled: boolean) => void;
|
|
16
23
|
}
|
|
17
24
|
export declare class Selector {
|
|
18
25
|
readonly onSelected: (id: string, isClick: boolean, clientRect: IRect) => void;
|
|
@@ -23,6 +30,7 @@ export declare class Selector {
|
|
|
23
30
|
private onRequestDeleteConfirm?;
|
|
24
31
|
private onFreeTextDoubleClick?;
|
|
25
32
|
private getStylusModeEnabled?;
|
|
33
|
+
private setExternalGesturesEnabled?;
|
|
26
34
|
private transformerStore;
|
|
27
35
|
private getAnnotationStore;
|
|
28
36
|
private konvaCanvasStore;
|
|
@@ -32,7 +40,7 @@ export declare class Selector {
|
|
|
32
40
|
private marqueeRect;
|
|
33
41
|
private marqueeStartPos;
|
|
34
42
|
private marqueeStage;
|
|
35
|
-
constructor({ konvaCanvasStore, getAnnotationStore, onDelete, onSelected, onMultiSelected, onCancel, onChanged, onRequestDeleteConfirm, onFreeTextDoubleClick, getStylusModeEnabled, }: ISelectorOptions);
|
|
43
|
+
constructor({ konvaCanvasStore, getAnnotationStore, onDelete, onSelected, onMultiSelected, onCancel, onChanged, onRequestDeleteConfirm, onFreeTextDoubleClick, getStylusModeEnabled, setExternalGesturesEnabled, }: ISelectorOptions);
|
|
36
44
|
/** Returns true if this event should be rejected (finger touch in stylus mode). */
|
|
37
45
|
private isStylusRejected;
|
|
38
46
|
private handleKeyDown;
|
|
@@ -12,6 +12,7 @@ export class Selector {
|
|
|
12
12
|
onRequestDeleteConfirm;
|
|
13
13
|
onFreeTextDoubleClick;
|
|
14
14
|
getStylusModeEnabled;
|
|
15
|
+
setExternalGesturesEnabled;
|
|
15
16
|
transformerStore = /* @__PURE__ */ new Map();
|
|
16
17
|
getAnnotationStore;
|
|
17
18
|
konvaCanvasStore;
|
|
@@ -31,7 +32,8 @@ export class Selector {
|
|
|
31
32
|
onChanged,
|
|
32
33
|
onRequestDeleteConfirm,
|
|
33
34
|
onFreeTextDoubleClick,
|
|
34
|
-
getStylusModeEnabled
|
|
35
|
+
getStylusModeEnabled,
|
|
36
|
+
setExternalGesturesEnabled
|
|
35
37
|
}) {
|
|
36
38
|
this.konvaCanvasStore = konvaCanvasStore;
|
|
37
39
|
this.getAnnotationStore = getAnnotationStore;
|
|
@@ -43,6 +45,7 @@ export class Selector {
|
|
|
43
45
|
this.onRequestDeleteConfirm = onRequestDeleteConfirm;
|
|
44
46
|
this.onFreeTextDoubleClick = onFreeTextDoubleClick;
|
|
45
47
|
this.getStylusModeEnabled = getStylusModeEnabled;
|
|
48
|
+
this.setExternalGesturesEnabled = setExternalGesturesEnabled;
|
|
46
49
|
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
47
50
|
window.addEventListener("keydown", this.handleKeyDown);
|
|
48
51
|
}
|
|
@@ -188,6 +191,7 @@ export class Selector {
|
|
|
188
191
|
const transformer = new Konva.Transformer({
|
|
189
192
|
resizeEnabled: rawAnnotationStore.resizable,
|
|
190
193
|
rotateEnabled: false,
|
|
194
|
+
enabledAnchors: ["top-left", "top-right", "bottom-left", "bottom-right"],
|
|
191
195
|
borderStrokeWidth: defaultOptions.chooseSetting.STROKEWIDTH,
|
|
192
196
|
borderStroke: defaultOptions.chooseSetting.COLOR,
|
|
193
197
|
anchorFill: defaultOptions.chooseSetting.COLOR,
|
|
@@ -223,7 +227,34 @@ export class Selector {
|
|
|
223
227
|
}
|
|
224
228
|
transformer.off("transformend");
|
|
225
229
|
transformer.off("transformstart");
|
|
230
|
+
let dragLayer = null;
|
|
231
|
+
const moveToDragLayer = () => {
|
|
232
|
+
if (dragLayer) return;
|
|
233
|
+
const bg = this.getBackgroundLayer(konvaStage);
|
|
234
|
+
dragLayer = new Konva.Layer();
|
|
235
|
+
konvaStage.add(dragLayer);
|
|
236
|
+
group.moveTo(dragLayer);
|
|
237
|
+
transformer.moveTo(dragLayer);
|
|
238
|
+
bg.batchDraw();
|
|
239
|
+
dragLayer.batchDraw();
|
|
240
|
+
};
|
|
241
|
+
const restoreFromDragLayer = () => {
|
|
242
|
+
if (!dragLayer) return;
|
|
243
|
+
const bg = this.getBackgroundLayer(konvaStage);
|
|
244
|
+
group.moveTo(bg);
|
|
245
|
+
transformer.moveTo(bg);
|
|
246
|
+
dragLayer.destroy();
|
|
247
|
+
dragLayer = null;
|
|
248
|
+
bg.batchDraw();
|
|
249
|
+
};
|
|
250
|
+
transformer.on("transformstart", () => {
|
|
251
|
+
this.setExternalGesturesEnabled?.(false);
|
|
252
|
+
moveToDragLayer();
|
|
253
|
+
this.onCancel();
|
|
254
|
+
});
|
|
226
255
|
transformer.on("transformend", () => {
|
|
256
|
+
this.setExternalGesturesEnabled?.(true);
|
|
257
|
+
restoreFromDragLayer();
|
|
227
258
|
this.onChanged(
|
|
228
259
|
group.id(),
|
|
229
260
|
group.toJSON(),
|
|
@@ -232,13 +263,22 @@ export class Selector {
|
|
|
232
263
|
transformer.getClientRect()
|
|
233
264
|
);
|
|
234
265
|
});
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
});
|
|
266
|
+
let dragStartRect = null;
|
|
267
|
+
let dragAnchorPos = null;
|
|
238
268
|
transformer.on("dragstart", () => {
|
|
269
|
+
this.setExternalGesturesEnabled?.(false);
|
|
270
|
+
moveToDragLayer();
|
|
239
271
|
this.onCancel();
|
|
272
|
+
const boxes = transformer.nodes().map((node) => node.getClientRect());
|
|
273
|
+
dragStartRect = this.getTotalBox(boxes);
|
|
274
|
+
const firstNode = transformer.nodes()[0];
|
|
275
|
+
dragAnchorPos = firstNode ? firstNode.getAbsolutePosition() : null;
|
|
240
276
|
});
|
|
241
277
|
transformer.on("dragend", () => {
|
|
278
|
+
this.setExternalGesturesEnabled?.(true);
|
|
279
|
+
restoreFromDragLayer();
|
|
280
|
+
dragStartRect = null;
|
|
281
|
+
dragAnchorPos = null;
|
|
242
282
|
this.onChanged(
|
|
243
283
|
group.id(),
|
|
244
284
|
group.toJSON(),
|
|
@@ -248,29 +288,32 @@ export class Selector {
|
|
|
248
288
|
);
|
|
249
289
|
});
|
|
250
290
|
transformer.on("dragmove", () => {
|
|
251
|
-
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
291
|
+
if (!dragStartRect || !dragAnchorPos) return;
|
|
292
|
+
const nodes = transformer.nodes();
|
|
293
|
+
const firstNode = nodes[0];
|
|
294
|
+
if (!firstNode) return;
|
|
295
|
+
const currentPos = firstNode.getAbsolutePosition();
|
|
296
|
+
const dx = currentPos.x - dragAnchorPos.x;
|
|
297
|
+
const dy = currentPos.y - dragAnchorPos.y;
|
|
298
|
+
const boxX = dragStartRect.x + dx;
|
|
299
|
+
const boxY = dragStartRect.y + dy;
|
|
300
|
+
const halfWidth = dragStartRect.width / 2;
|
|
301
|
+
const halfHeight = dragStartRect.height / 2;
|
|
302
|
+
const stageW = konvaStage.width();
|
|
303
|
+
const stageH = konvaStage.height();
|
|
304
|
+
let clampDx = 0;
|
|
305
|
+
let clampDy = 0;
|
|
306
|
+
if (boxX + halfWidth < 0) clampDx = -(boxX + halfWidth);
|
|
307
|
+
else if (boxX + halfWidth > stageW) clampDx = stageW - (boxX + halfWidth);
|
|
308
|
+
if (boxY + halfHeight < 0) clampDy = -(boxY + halfHeight);
|
|
309
|
+
else if (boxY + halfHeight > stageH) clampDy = stageH - (boxY + halfHeight);
|
|
310
|
+
if (clampDx !== 0 || clampDy !== 0) {
|
|
311
|
+
nodes.forEach((shape) => {
|
|
312
|
+
const pos = shape.getAbsolutePosition();
|
|
313
|
+
shape.setAbsolutePosition({ x: pos.x + clampDx, y: pos.y + clampDy });
|
|
314
|
+
});
|
|
315
|
+
dragAnchorPos = firstNode.getAbsolutePosition();
|
|
316
|
+
}
|
|
274
317
|
});
|
|
275
318
|
transformer.nodes([group]);
|
|
276
319
|
this.getBackgroundLayer(konvaStage).add(transformer);
|
|
@@ -507,12 +550,11 @@ export class Selector {
|
|
|
507
550
|
this.transformerStore.set("__multi__", transformer);
|
|
508
551
|
nodes.forEach((node) => {
|
|
509
552
|
node.on("dragstart.marquee", () => {
|
|
553
|
+
this.setExternalGesturesEnabled?.(false);
|
|
510
554
|
this.onCancel();
|
|
511
555
|
});
|
|
512
|
-
node.on("dragmove.marquee", () => {
|
|
513
|
-
this.onMultiSelected(matchedIds, transformer.getClientRect());
|
|
514
|
-
});
|
|
515
556
|
node.on("dragend.marquee", () => {
|
|
557
|
+
this.setExternalGesturesEnabled?.(true);
|
|
516
558
|
this.onMultiSelected(matchedIds, transformer.getClientRect());
|
|
517
559
|
});
|
|
518
560
|
});
|
|
@@ -33,12 +33,13 @@ export declare class Painter {
|
|
|
33
33
|
private getStylusModeEnabled?;
|
|
34
34
|
private getReadonly?;
|
|
35
35
|
private freehandGroupingDelay;
|
|
36
|
-
constructor({ userName, callbacks, getStylusModeEnabled, getReadonly, freehandGroupingDelay, }: {
|
|
36
|
+
constructor({ userName, callbacks, getStylusModeEnabled, getReadonly, freehandGroupingDelay, setExternalGesturesEnabled, }: {
|
|
37
37
|
userName: string;
|
|
38
38
|
callbacks: PainterCallbacks;
|
|
39
39
|
getStylusModeEnabled?: () => boolean;
|
|
40
40
|
getReadonly?: () => boolean;
|
|
41
41
|
freehandGroupingDelay?: number;
|
|
42
|
+
setExternalGesturesEnabled?: (enabled: boolean) => void;
|
|
42
43
|
});
|
|
43
44
|
private editFreeText;
|
|
44
45
|
private bindGlobalEvents;
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
PAINTER_PAINTING_TYPE
|
|
11
11
|
} from "./const.js";
|
|
12
12
|
import { hideCursorPreview } from "./cursor-preview.js";
|
|
13
|
+
import { Editor } from "./editor/editor.js";
|
|
13
14
|
import { EditorCircle } from "./tools/circle.js";
|
|
14
15
|
import { EditorFreeHand } from "./tools/freehand.js";
|
|
15
16
|
import { EditorFreeHighlight } from "./tools/free-highlight.js";
|
|
@@ -23,6 +24,10 @@ import { EditorArrow } from "./tools/arrow.js";
|
|
|
23
24
|
import { EditorCloud } from "./tools/cloud.js";
|
|
24
25
|
import { Selector } from "./editor/selector.js";
|
|
25
26
|
import { Store } from "./store.js";
|
|
27
|
+
import { isIPad } from "./input-device.js";
|
|
28
|
+
if (typeof window !== "undefined" && isIPad()) {
|
|
29
|
+
Konva.pixelRatio = 1;
|
|
30
|
+
}
|
|
26
31
|
export class Painter {
|
|
27
32
|
userName;
|
|
28
33
|
konvaCanvasStore = /* @__PURE__ */ new Map();
|
|
@@ -40,7 +45,8 @@ export class Painter {
|
|
|
40
45
|
callbacks,
|
|
41
46
|
getStylusModeEnabled,
|
|
42
47
|
getReadonly,
|
|
43
|
-
freehandGroupingDelay
|
|
48
|
+
freehandGroupingDelay,
|
|
49
|
+
setExternalGesturesEnabled
|
|
44
50
|
}) {
|
|
45
51
|
this.userName = userName;
|
|
46
52
|
this.callbacks = callbacks;
|
|
@@ -86,7 +92,8 @@ export class Painter {
|
|
|
86
92
|
onFreeTextDoubleClick: (id) => {
|
|
87
93
|
void this.editFreeText(id);
|
|
88
94
|
},
|
|
89
|
-
getStylusModeEnabled: this.getStylusModeEnabled
|
|
95
|
+
getStylusModeEnabled: this.getStylusModeEnabled,
|
|
96
|
+
setExternalGesturesEnabled
|
|
90
97
|
});
|
|
91
98
|
this.bindGlobalEvents();
|
|
92
99
|
}
|
|
@@ -138,7 +145,9 @@ export class Painter {
|
|
|
138
145
|
}
|
|
139
146
|
applyStylusTouchAction(stage) {
|
|
140
147
|
stage.preventDefault(false);
|
|
141
|
-
|
|
148
|
+
if (!isIPad()) {
|
|
149
|
+
Konva.pixelRatio = window.devicePixelRatio || 1;
|
|
150
|
+
}
|
|
142
151
|
const content = stage.content;
|
|
143
152
|
if (content) content.style.touchAction = "pan-x pan-y";
|
|
144
153
|
stage.container().querySelectorAll("canvas").forEach((c) => {
|
|
@@ -147,7 +156,9 @@ export class Painter {
|
|
|
147
156
|
}
|
|
148
157
|
removeStylusTouchAction(stage) {
|
|
149
158
|
stage.preventDefault(true);
|
|
150
|
-
|
|
159
|
+
if (!isIPad()) {
|
|
160
|
+
Konva.pixelRatio = window.devicePixelRatio || 1;
|
|
161
|
+
}
|
|
151
162
|
const content = stage.content;
|
|
152
163
|
if (content) content.style.touchAction = "";
|
|
153
164
|
stage.container().querySelectorAll("canvas").forEach((c) => {
|
|
@@ -551,6 +562,7 @@ export class Painter {
|
|
|
551
562
|
return this.store.annotations;
|
|
552
563
|
}
|
|
553
564
|
getExportContext() {
|
|
565
|
+
Editor.flushAllTimers();
|
|
554
566
|
const originalIds = this.store.originalIds;
|
|
555
567
|
const modifiedIds = this.store.modifiedOriginals;
|
|
556
568
|
const changedAnnotations = this.store.annotations.filter(
|
|
@@ -3,7 +3,12 @@ type __VLS_Props = {
|
|
|
3
3
|
pageNumber: number;
|
|
4
4
|
pageMeta: PageMeta;
|
|
5
5
|
scale: number;
|
|
6
|
+
/** Canvas internal resolution multiplier (CSS size unchanged).
|
|
7
|
+
* Used by panzoom to sharpen the PDF when visually zoomed in. */
|
|
8
|
+
renderQuality?: number;
|
|
6
9
|
};
|
|
7
|
-
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
10
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
11
|
+
renderQuality: number;
|
|
12
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
8
13
|
declare const _default: typeof __VLS_export;
|
|
9
14
|
export default _default;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div
|
|
3
|
-
class="kviewer-page"
|
|
3
|
+
class="kviewer-page shadow-lg"
|
|
4
4
|
:style="{
|
|
5
5
|
position: 'relative',
|
|
6
6
|
width: cssWidth + 'px',
|
|
@@ -63,7 +63,8 @@ const PDFJS_ANNOTATION_MODE_DISABLE = 0;
|
|
|
63
63
|
const props = defineProps({
|
|
64
64
|
pageNumber: { type: Number, required: true },
|
|
65
65
|
pageMeta: { type: Object, required: true },
|
|
66
|
-
scale: { type: Number, required: true }
|
|
66
|
+
scale: { type: Number, required: true },
|
|
67
|
+
renderQuality: { type: Number, required: false, default: 1 }
|
|
67
68
|
});
|
|
68
69
|
const canvasRef = ref(null);
|
|
69
70
|
const textLayerRef = ref(null);
|
|
@@ -141,7 +142,14 @@ watch(
|
|
|
141
142
|
}
|
|
142
143
|
}
|
|
143
144
|
);
|
|
144
|
-
|
|
145
|
+
watch(
|
|
146
|
+
() => props.renderQuality,
|
|
147
|
+
async () => {
|
|
148
|
+
if (!pageProxy.value) return;
|
|
149
|
+
await renderCanvas({ doubleBuffer: true });
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
async function renderCanvas(opts) {
|
|
145
153
|
const canvas = canvasRef.value;
|
|
146
154
|
const proxy = pageProxy.value;
|
|
147
155
|
if (!canvas || !proxy) return;
|
|
@@ -150,23 +158,48 @@ async function renderCanvas() {
|
|
|
150
158
|
currentRenderTask = null;
|
|
151
159
|
}
|
|
152
160
|
const dpr = window.devicePixelRatio || 1;
|
|
161
|
+
const quality = props.renderQuality ?? 1;
|
|
153
162
|
const viewport = proxy.getViewport({
|
|
154
|
-
scale: props.scale * dpr
|
|
163
|
+
scale: props.scale * quality * dpr
|
|
155
164
|
});
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
165
|
+
if (opts?.doubleBuffer) {
|
|
166
|
+
const tmp = document.createElement("canvas");
|
|
167
|
+
tmp.width = viewport.width;
|
|
168
|
+
tmp.height = viewport.height;
|
|
169
|
+
try {
|
|
170
|
+
currentRenderTask = proxy.render({
|
|
171
|
+
canvasContext: tmp.getContext("2d"),
|
|
172
|
+
viewport,
|
|
173
|
+
annotationMode: PDFJS_ANNOTATION_MODE_DISABLE
|
|
174
|
+
});
|
|
175
|
+
await currentRenderTask.promise;
|
|
176
|
+
canvas.width = viewport.width;
|
|
177
|
+
canvas.height = viewport.height;
|
|
178
|
+
canvas.getContext("2d").drawImage(tmp, 0, 0);
|
|
179
|
+
} catch (e) {
|
|
180
|
+
if (e instanceof Error && e.message?.includes("Rendering cancelled")) return;
|
|
181
|
+
throw e;
|
|
182
|
+
} finally {
|
|
183
|
+
currentRenderTask = null;
|
|
184
|
+
tmp.width = 0;
|
|
185
|
+
tmp.height = 0;
|
|
186
|
+
}
|
|
187
|
+
} else {
|
|
188
|
+
canvas.width = viewport.width;
|
|
189
|
+
canvas.height = viewport.height;
|
|
190
|
+
try {
|
|
191
|
+
currentRenderTask = proxy.render({
|
|
192
|
+
canvasContext: canvas.getContext("2d"),
|
|
193
|
+
viewport,
|
|
194
|
+
annotationMode: PDFJS_ANNOTATION_MODE_DISABLE
|
|
195
|
+
});
|
|
196
|
+
await currentRenderTask.promise;
|
|
197
|
+
} catch (e) {
|
|
198
|
+
if (e instanceof Error && e.message?.includes("Rendering cancelled")) return;
|
|
199
|
+
throw e;
|
|
200
|
+
} finally {
|
|
201
|
+
currentRenderTask = null;
|
|
202
|
+
}
|
|
170
203
|
}
|
|
171
204
|
}
|
|
172
205
|
function initKonva() {
|
|
@@ -3,7 +3,12 @@ type __VLS_Props = {
|
|
|
3
3
|
pageNumber: number;
|
|
4
4
|
pageMeta: PageMeta;
|
|
5
5
|
scale: number;
|
|
6
|
+
/** Canvas internal resolution multiplier (CSS size unchanged).
|
|
7
|
+
* Used by panzoom to sharpen the PDF when visually zoomed in. */
|
|
8
|
+
renderQuality?: number;
|
|
6
9
|
};
|
|
7
|
-
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
10
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
11
|
+
renderQuality: number;
|
|
12
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
8
13
|
declare const _default: typeof __VLS_export;
|
|
9
14
|
export default _default;
|