kviewer 0.0.1
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 +134 -0
- package/dist/module.d.mts +15 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +26 -0
- package/dist/runtime/annotation/engine/config.d.ts +52 -0
- package/dist/runtime/annotation/engine/config.js +283 -0
- package/dist/runtime/annotation/engine/const.d.ts +6 -0
- package/dist/runtime/annotation/engine/const.js +7 -0
- package/dist/runtime/annotation/engine/cursor-preview.d.ts +2 -0
- package/dist/runtime/annotation/engine/cursor-preview.js +88 -0
- package/dist/runtime/annotation/engine/editor/editor.d.ts +69 -0
- package/dist/runtime/annotation/engine/editor/editor.js +233 -0
- package/dist/runtime/annotation/engine/editor/selector.d.ts +74 -0
- package/dist/runtime/annotation/engine/editor/selector.js +594 -0
- package/dist/runtime/annotation/engine/import-normalize.d.ts +5 -0
- package/dist/runtime/annotation/engine/import-normalize.js +99 -0
- package/dist/runtime/annotation/engine/input-device.d.ts +53 -0
- package/dist/runtime/annotation/engine/input-device.js +64 -0
- package/dist/runtime/annotation/engine/painter.d.ts +97 -0
- package/dist/runtime/annotation/engine/painter.js +591 -0
- package/dist/runtime/annotation/engine/store.d.ts +11 -0
- package/dist/runtime/annotation/engine/store.js +47 -0
- package/dist/runtime/annotation/engine/tools/arrow.d.ts +22 -0
- package/dist/runtime/annotation/engine/tools/arrow.js +126 -0
- package/dist/runtime/annotation/engine/tools/circle.d.ts +45 -0
- package/dist/runtime/annotation/engine/tools/circle.js +148 -0
- package/dist/runtime/annotation/engine/tools/cloud.d.ts +50 -0
- package/dist/runtime/annotation/engine/tools/cloud.js +244 -0
- package/dist/runtime/annotation/engine/tools/free-highlight.d.ts +43 -0
- package/dist/runtime/annotation/engine/tools/free-highlight.js +165 -0
- package/dist/runtime/annotation/engine/tools/free-text.d.ts +27 -0
- package/dist/runtime/annotation/engine/tools/free-text.js +114 -0
- package/dist/runtime/annotation/engine/tools/freehand.d.ts +44 -0
- package/dist/runtime/annotation/engine/tools/freehand.js +151 -0
- package/dist/runtime/annotation/engine/tools/highlight.d.ts +87 -0
- package/dist/runtime/annotation/engine/tools/highlight.js +215 -0
- package/dist/runtime/annotation/engine/tools/note.d.ts +9 -0
- package/dist/runtime/annotation/engine/tools/note.js +34 -0
- package/dist/runtime/annotation/engine/tools/rectangle.d.ts +45 -0
- package/dist/runtime/annotation/engine/tools/rectangle.js +142 -0
- package/dist/runtime/annotation/engine/tools/signature.d.ts +16 -0
- package/dist/runtime/annotation/engine/tools/signature.js +74 -0
- package/dist/runtime/annotation/engine/tools/stamp.d.ts +18 -0
- package/dist/runtime/annotation/engine/tools/stamp.js +94 -0
- package/dist/runtime/annotation/engine/types.d.ts +170 -0
- package/dist/runtime/annotation/engine/types.js +67 -0
- package/dist/runtime/annotation/engine/utils.d.ts +40 -0
- package/dist/runtime/annotation/engine/utils.js +257 -0
- package/dist/runtime/annotation/parsers/parseFormFields.d.ts +9 -0
- package/dist/runtime/annotation/parsers/parseFormFields.js +101 -0
- package/dist/runtime/annotation/pdf-export/download.d.ts +1 -0
- package/dist/runtime/annotation/pdf-export/download.js +10 -0
- package/dist/runtime/annotation/pdf-export/export-form-fields.d.ts +9 -0
- package/dist/runtime/annotation/pdf-export/export-form-fields.js +90 -0
- package/dist/runtime/annotation/pdf-export/export.d.ts +15 -0
- package/dist/runtime/annotation/pdf-export/export.js +145 -0
- package/dist/runtime/annotation/pdf-export/parse.d.ts +10 -0
- package/dist/runtime/annotation/pdf-export/parse.js +19 -0
- package/dist/runtime/annotation/pdf-export/parse_circle.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_circle.js +41 -0
- package/dist/runtime/annotation/pdf-export/parse_freetext.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_freetext.js +54 -0
- package/dist/runtime/annotation/pdf-export/parse_highlight.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_highlight.js +134 -0
- package/dist/runtime/annotation/pdf-export/parse_ink.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_ink.js +124 -0
- package/dist/runtime/annotation/pdf-export/parse_line.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_line.js +71 -0
- package/dist/runtime/annotation/pdf-export/parse_polyline.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_polyline.js +93 -0
- package/dist/runtime/annotation/pdf-export/parse_square.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_square.js +41 -0
- package/dist/runtime/annotation/pdf-export/parse_stamp.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_stamp.js +195 -0
- package/dist/runtime/annotation/pdf-export/parse_strikeout.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_strikeout.js +59 -0
- package/dist/runtime/annotation/pdf-export/parse_text.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_text.js +42 -0
- package/dist/runtime/annotation/pdf-export/parse_underline.d.ts +4 -0
- package/dist/runtime/annotation/pdf-export/parse_underline.js +59 -0
- package/dist/runtime/assets/kviewer.css +1 -0
- package/dist/runtime/components/AnnotationToolbar.d.vue.ts +3 -0
- package/dist/runtime/components/AnnotationToolbar.vue +125 -0
- package/dist/runtime/components/AnnotationToolbar.vue.d.ts +3 -0
- package/dist/runtime/components/FloatingPageIndicator.d.vue.ts +6 -0
- package/dist/runtime/components/FloatingPageIndicator.vue +93 -0
- package/dist/runtime/components/FloatingPageIndicator.vue.d.ts +6 -0
- package/dist/runtime/components/FormFieldLayer.d.vue.ts +11 -0
- package/dist/runtime/components/FormFieldLayer.vue +40 -0
- package/dist/runtime/components/FormFieldLayer.vue.d.ts +11 -0
- package/dist/runtime/components/PdfPage.d.vue.ts +9 -0
- package/dist/runtime/components/PdfPage.vue +199 -0
- package/dist/runtime/components/PdfPage.vue.d.ts +9 -0
- package/dist/runtime/components/ToolButton.d.vue.ts +13 -0
- package/dist/runtime/components/ToolButton.vue +26 -0
- package/dist/runtime/components/ToolButton.vue.d.ts +13 -0
- package/dist/runtime/components/Toolbar.d.vue.ts +3 -0
- package/dist/runtime/components/Toolbar.vue +11 -0
- package/dist/runtime/components/Toolbar.vue.d.ts +3 -0
- package/dist/runtime/components/Viewer.d.vue.ts +45 -0
- package/dist/runtime/components/Viewer.vue +617 -0
- package/dist/runtime/components/Viewer.vue.d.ts +45 -0
- package/dist/runtime/components/ViewerBar.d.vue.ts +3 -0
- package/dist/runtime/components/ViewerBar.vue +91 -0
- package/dist/runtime/components/ViewerBar.vue.d.ts +3 -0
- package/dist/runtime/components/ViewerTabs.d.vue.ts +381 -0
- package/dist/runtime/components/ViewerTabs.vue +171 -0
- package/dist/runtime/components/ViewerTabs.vue.d.ts +381 -0
- package/dist/runtime/components/form-fields/FormButton.d.vue.ts +7 -0
- package/dist/runtime/components/form-fields/FormButton.vue +39 -0
- package/dist/runtime/components/form-fields/FormButton.vue.d.ts +7 -0
- package/dist/runtime/components/form-fields/FormCheckbox.d.vue.ts +7 -0
- package/dist/runtime/components/form-fields/FormCheckbox.vue +28 -0
- package/dist/runtime/components/form-fields/FormCheckbox.vue.d.ts +7 -0
- package/dist/runtime/components/form-fields/FormDropdown.d.vue.ts +7 -0
- package/dist/runtime/components/form-fields/FormDropdown.vue +112 -0
- package/dist/runtime/components/form-fields/FormDropdown.vue.d.ts +7 -0
- package/dist/runtime/components/form-fields/FormFieldWrapper.d.vue.ts +8 -0
- package/dist/runtime/components/form-fields/FormFieldWrapper.vue +41 -0
- package/dist/runtime/components/form-fields/FormFieldWrapper.vue.d.ts +8 -0
- package/dist/runtime/components/form-fields/FormRadioButton.d.vue.ts +7 -0
- package/dist/runtime/components/form-fields/FormRadioButton.vue +30 -0
- package/dist/runtime/components/form-fields/FormRadioButton.vue.d.ts +7 -0
- package/dist/runtime/components/form-fields/FormSignatureField.d.vue.ts +7 -0
- package/dist/runtime/components/form-fields/FormSignatureField.vue +54 -0
- package/dist/runtime/components/form-fields/FormSignatureField.vue.d.ts +7 -0
- package/dist/runtime/components/form-fields/FormTextField.d.vue.ts +7 -0
- package/dist/runtime/components/form-fields/FormTextField.vue +66 -0
- package/dist/runtime/components/form-fields/FormTextField.vue.d.ts +7 -0
- package/dist/runtime/components/modals/FreeTextModal.d.vue.ts +25 -0
- package/dist/runtime/components/modals/FreeTextModal.vue +89 -0
- package/dist/runtime/components/modals/FreeTextModal.vue.d.ts +25 -0
- package/dist/runtime/components/modals/SignatureDrawModal.d.vue.ts +14 -0
- package/dist/runtime/components/modals/SignatureDrawModal.vue +120 -0
- package/dist/runtime/components/modals/SignatureDrawModal.vue.d.ts +14 -0
- package/dist/runtime/components/panels/SignaturePicker.d.vue.ts +3 -0
- package/dist/runtime/components/panels/SignaturePicker.vue +85 -0
- package/dist/runtime/components/panels/SignaturePicker.vue.d.ts +3 -0
- package/dist/runtime/components/panels/StampPicker.d.vue.ts +3 -0
- package/dist/runtime/components/panels/StampPicker.vue +46 -0
- package/dist/runtime/components/panels/StampPicker.vue.d.ts +3 -0
- package/dist/runtime/components/tools/ActionTools.d.vue.ts +3 -0
- package/dist/runtime/components/tools/ActionTools.vue +32 -0
- package/dist/runtime/components/tools/ActionTools.vue.d.ts +3 -0
- package/dist/runtime/components/tools/DrawingTools.d.vue.ts +6 -0
- package/dist/runtime/components/tools/DrawingTools.vue +57 -0
- package/dist/runtime/components/tools/DrawingTools.vue.d.ts +6 -0
- package/dist/runtime/components/tools/HandTool.d.vue.ts +3 -0
- package/dist/runtime/components/tools/HandTool.vue +14 -0
- package/dist/runtime/components/tools/HandTool.vue.d.ts +3 -0
- package/dist/runtime/components/tools/MarqueeTool.d.vue.ts +3 -0
- package/dist/runtime/components/tools/MarqueeTool.vue +15 -0
- package/dist/runtime/components/tools/MarqueeTool.vue.d.ts +3 -0
- package/dist/runtime/components/tools/PageInfo.d.vue.ts +3 -0
- package/dist/runtime/components/tools/PageInfo.vue +10 -0
- package/dist/runtime/components/tools/PageInfo.vue.d.ts +3 -0
- package/dist/runtime/components/tools/PageSettings.d.vue.ts +3 -0
- package/dist/runtime/components/tools/PageSettings.vue +92 -0
- package/dist/runtime/components/tools/PageSettings.vue.d.ts +3 -0
- package/dist/runtime/components/tools/SearchTool.d.vue.ts +3 -0
- package/dist/runtime/components/tools/SearchTool.vue +149 -0
- package/dist/runtime/components/tools/SearchTool.vue.d.ts +3 -0
- package/dist/runtime/components/tools/ToolProperties.d.vue.ts +7 -0
- package/dist/runtime/components/tools/ToolProperties.vue +174 -0
- package/dist/runtime/components/tools/ToolProperties.vue.d.ts +7 -0
- package/dist/runtime/components/tools/ZoomControls.d.vue.ts +3 -0
- package/dist/runtime/components/tools/ZoomControls.vue +59 -0
- package/dist/runtime/components/tools/ZoomControls.vue.d.ts +3 -0
- package/dist/runtime/composables/search-utils.d.ts +20 -0
- package/dist/runtime/composables/search-utils.js +55 -0
- package/dist/runtime/composables/useAnnotationEngine.d.ts +7 -0
- package/dist/runtime/composables/useAnnotationEngine.js +70 -0
- package/dist/runtime/composables/useAnnotationHistory.d.ts +12 -0
- package/dist/runtime/composables/useAnnotationHistory.js +69 -0
- package/dist/runtime/composables/useFormFields.d.ts +26 -0
- package/dist/runtime/composables/useFormFields.js +112 -0
- package/dist/runtime/composables/usePageProxyCache.d.ts +8 -0
- package/dist/runtime/composables/usePageProxyCache.js +73 -0
- package/dist/runtime/composables/usePageSettings.d.ts +16 -0
- package/dist/runtime/composables/usePageSettings.js +66 -0
- package/dist/runtime/composables/usePageVirtualization.d.ts +19 -0
- package/dist/runtime/composables/usePageVirtualization.js +203 -0
- package/dist/runtime/composables/useSearchIndex.d.ts +11 -0
- package/dist/runtime/composables/useSearchIndex.js +71 -0
- package/dist/runtime/composables/useViewerSearch.d.ts +32 -0
- package/dist/runtime/composables/useViewerSearch.js +418 -0
- package/dist/runtime/composables/useViewerState.d.ts +62 -0
- package/dist/runtime/composables/useViewerState.js +189 -0
- package/dist/runtime/composables/viewMode.d.ts +11 -0
- package/dist/runtime/composables/viewMode.js +19 -0
- package/dist/runtime/plugin.d.ts +2 -0
- package/dist/runtime/plugin.js +3 -0
- package/dist/runtime/public-types.d.ts +2 -0
- package/dist/runtime/public-types.js +0 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/types.d.mts +5 -0
- package/package.json +64 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import Konva from "konva";
|
|
2
|
+
import { formatTimestamp, generateUUID } from "../utils.js";
|
|
3
|
+
import { SHAPE_GROUP_NAME } from "../const.js";
|
|
4
|
+
import { isStylusTouch } from "../input-device.js";
|
|
5
|
+
export class Editor {
|
|
6
|
+
userName;
|
|
7
|
+
id;
|
|
8
|
+
onAdd;
|
|
9
|
+
onChange;
|
|
10
|
+
konvaStage;
|
|
11
|
+
pageNumber;
|
|
12
|
+
currentAnnotation;
|
|
13
|
+
isPainting;
|
|
14
|
+
shapeGroupStore = /* @__PURE__ */ new Map();
|
|
15
|
+
currentShapeGroup;
|
|
16
|
+
getStylusModeEnabled;
|
|
17
|
+
static MinSize = 8;
|
|
18
|
+
constructor({
|
|
19
|
+
userName,
|
|
20
|
+
konvaStage,
|
|
21
|
+
pageNumber,
|
|
22
|
+
annotation,
|
|
23
|
+
onAdd,
|
|
24
|
+
editorType,
|
|
25
|
+
onChange,
|
|
26
|
+
getStylusModeEnabled
|
|
27
|
+
}) {
|
|
28
|
+
this.userName = userName;
|
|
29
|
+
this.id = `${pageNumber}_${editorType}`;
|
|
30
|
+
this.konvaStage = konvaStage;
|
|
31
|
+
this.pageNumber = pageNumber;
|
|
32
|
+
this.currentAnnotation = annotation;
|
|
33
|
+
this.isPainting = false;
|
|
34
|
+
this.currentShapeGroup = null;
|
|
35
|
+
this.onAdd = onAdd;
|
|
36
|
+
this.onChange = onChange || (() => {
|
|
37
|
+
});
|
|
38
|
+
this.getStylusModeEnabled = getStylusModeEnabled;
|
|
39
|
+
this.disableEditMode();
|
|
40
|
+
this.enableEditMode();
|
|
41
|
+
}
|
|
42
|
+
dispatchAddEvent({
|
|
43
|
+
shapeGroup,
|
|
44
|
+
contentsObj,
|
|
45
|
+
color,
|
|
46
|
+
fontSize
|
|
47
|
+
}) {
|
|
48
|
+
const { id, pageNumber, konvaGroup, annotation } = shapeGroup;
|
|
49
|
+
const annotationStore = {
|
|
50
|
+
id,
|
|
51
|
+
pageNumber,
|
|
52
|
+
konvaString: konvaGroup.toJSON(),
|
|
53
|
+
konvaClientRect: konvaGroup.getClientRect(),
|
|
54
|
+
title: this.userName,
|
|
55
|
+
type: annotation.type,
|
|
56
|
+
pdfjsType: annotation.pdfjsAnnotationType,
|
|
57
|
+
pdfjsEditorType: annotation.pdfjsEditorType,
|
|
58
|
+
subtype: annotation.subtype,
|
|
59
|
+
color,
|
|
60
|
+
fontSize,
|
|
61
|
+
date: formatTimestamp(Date.now()),
|
|
62
|
+
contentsObj,
|
|
63
|
+
comments: [],
|
|
64
|
+
resizable: annotation.resizable,
|
|
65
|
+
draggable: annotation.draggable
|
|
66
|
+
};
|
|
67
|
+
this.onAdd(annotationStore);
|
|
68
|
+
}
|
|
69
|
+
dispatchChangedEvent(id, updates) {
|
|
70
|
+
this.onChange(id, updates);
|
|
71
|
+
}
|
|
72
|
+
enableEditMode() {
|
|
73
|
+
const stylusEnabled = this.getStylusModeEnabled?.() ?? false;
|
|
74
|
+
this.konvaStage.on("mousedown", (e) => {
|
|
75
|
+
if (e.evt.button === 0) this.mouseDownHandler(e);
|
|
76
|
+
});
|
|
77
|
+
this.konvaStage.on("mousemove", (e) => {
|
|
78
|
+
this.mouseMoveHandler(e);
|
|
79
|
+
});
|
|
80
|
+
this.konvaStage.on("mouseup", (e) => {
|
|
81
|
+
if (e.evt.button === 0) this.mouseUpHandler(e);
|
|
82
|
+
});
|
|
83
|
+
this.konvaStage.on("touchstart", (e) => {
|
|
84
|
+
if (e.evt.touches.length !== 1) return;
|
|
85
|
+
if (stylusEnabled) {
|
|
86
|
+
if (!isStylusTouch(e.evt)) return;
|
|
87
|
+
e.evt.preventDefault();
|
|
88
|
+
}
|
|
89
|
+
this.mouseDownHandler(e);
|
|
90
|
+
});
|
|
91
|
+
this.konvaStage.on("touchmove", (e) => {
|
|
92
|
+
if (e.evt.touches.length !== 1) return;
|
|
93
|
+
if (stylusEnabled) {
|
|
94
|
+
if (!isStylusTouch(e.evt)) return;
|
|
95
|
+
if (this.isPainting) e.evt.preventDefault();
|
|
96
|
+
}
|
|
97
|
+
this.mouseMoveHandler(e);
|
|
98
|
+
});
|
|
99
|
+
this.konvaStage.on("touchend", (e) => {
|
|
100
|
+
if (stylusEnabled) {
|
|
101
|
+
const touch = e.evt.changedTouches?.[0];
|
|
102
|
+
const isStylus = touch && "touchType" in touch && touch.touchType === "stylus";
|
|
103
|
+
if (!isStylus) return;
|
|
104
|
+
}
|
|
105
|
+
this.mouseUpHandler(e);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
disableEditMode() {
|
|
109
|
+
this.isPainting = false;
|
|
110
|
+
this.konvaStage.off("click mousedown mousemove mouseup touchstart touchmove touchend");
|
|
111
|
+
}
|
|
112
|
+
getBgLayer(konvaStage) {
|
|
113
|
+
return konvaStage ? konvaStage.getLayers()[0] : this.konvaStage.getLayers()[0];
|
|
114
|
+
}
|
|
115
|
+
delShapeGroup(id) {
|
|
116
|
+
this.shapeGroupStore.delete(id);
|
|
117
|
+
const group = this.konvaStage.findOne(
|
|
118
|
+
(node) => node.getType() === "Group" && node.id() === id
|
|
119
|
+
);
|
|
120
|
+
if (group) {
|
|
121
|
+
group.destroy();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
getShapeGroupById(id) {
|
|
125
|
+
const group = this.konvaStage.findOne(
|
|
126
|
+
(node) => node.getType() === "Group" && node.id() === id
|
|
127
|
+
);
|
|
128
|
+
return group;
|
|
129
|
+
}
|
|
130
|
+
setShapeGroupDone({
|
|
131
|
+
id,
|
|
132
|
+
contentsObj,
|
|
133
|
+
color,
|
|
134
|
+
fontSize
|
|
135
|
+
}) {
|
|
136
|
+
const shapeGroup = this.shapeGroupStore.get(id);
|
|
137
|
+
if (shapeGroup) {
|
|
138
|
+
shapeGroup.isDone = true;
|
|
139
|
+
this.dispatchAddEvent({ shapeGroup, contentsObj, color, fontSize });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
setChanged(id, updates) {
|
|
143
|
+
this.dispatchChangedEvent(id, updates);
|
|
144
|
+
}
|
|
145
|
+
getNodesByClassName(className) {
|
|
146
|
+
const children = this.currentShapeGroup.konvaGroup.getChildren(
|
|
147
|
+
(node) => node.getClassName() === className
|
|
148
|
+
);
|
|
149
|
+
return children;
|
|
150
|
+
}
|
|
151
|
+
getGroupNodesByClassName(group, className) {
|
|
152
|
+
const children = group.getChildren(
|
|
153
|
+
(node) => node.getClassName() === className
|
|
154
|
+
);
|
|
155
|
+
return children;
|
|
156
|
+
}
|
|
157
|
+
updateKonvaGroup(id, newKonvaGroup) {
|
|
158
|
+
if (this.shapeGroupStore.has(id)) {
|
|
159
|
+
const shapeGroup = this.shapeGroupStore.get(id);
|
|
160
|
+
if (shapeGroup) {
|
|
161
|
+
shapeGroup.konvaGroup = newKonvaGroup;
|
|
162
|
+
this.shapeGroupStore.set(id, shapeGroup);
|
|
163
|
+
return shapeGroup;
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
console.warn(`ShapeGroup with id ${id} not found.`);
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
createShapeGroup() {
|
|
171
|
+
const id = generateUUID();
|
|
172
|
+
const group = new Konva.Group({
|
|
173
|
+
draggable: false,
|
|
174
|
+
name: SHAPE_GROUP_NAME,
|
|
175
|
+
id
|
|
176
|
+
});
|
|
177
|
+
const shapeGroup = {
|
|
178
|
+
id,
|
|
179
|
+
konvaGroup: group,
|
|
180
|
+
pageNumber: this.pageNumber,
|
|
181
|
+
annotation: this.currentAnnotation,
|
|
182
|
+
isDone: false
|
|
183
|
+
};
|
|
184
|
+
this.shapeGroupStore.set(id, shapeGroup);
|
|
185
|
+
return shapeGroup;
|
|
186
|
+
}
|
|
187
|
+
activate(konvaStage, annotation) {
|
|
188
|
+
this.konvaStage = konvaStage;
|
|
189
|
+
this.currentAnnotation = annotation;
|
|
190
|
+
this.isPainting = false;
|
|
191
|
+
this.disableEditMode();
|
|
192
|
+
this.enableEditMode();
|
|
193
|
+
}
|
|
194
|
+
rebindEvents() {
|
|
195
|
+
this.disableEditMode();
|
|
196
|
+
this.enableEditMode();
|
|
197
|
+
}
|
|
198
|
+
addSerializedGroupToLayer(konvaStage, konvaString) {
|
|
199
|
+
this.konvaStage = konvaStage;
|
|
200
|
+
const ghostGroup = Konva.Node.create(konvaString);
|
|
201
|
+
const id = ghostGroup.id();
|
|
202
|
+
this.getBgLayer(konvaStage).add(ghostGroup);
|
|
203
|
+
if (this.shapeGroupStore.has(id)) return;
|
|
204
|
+
const shapeGroup = {
|
|
205
|
+
id,
|
|
206
|
+
konvaGroup: ghostGroup,
|
|
207
|
+
pageNumber: this.pageNumber,
|
|
208
|
+
isDone: true
|
|
209
|
+
};
|
|
210
|
+
this.shapeGroupStore.set(id, shapeGroup);
|
|
211
|
+
}
|
|
212
|
+
deleteGroup(id, konvaStage) {
|
|
213
|
+
this.konvaStage = konvaStage;
|
|
214
|
+
this.delShapeGroup(id);
|
|
215
|
+
}
|
|
216
|
+
updateStyle(annotationStore, style) {
|
|
217
|
+
this.changeStyle(annotationStore, style);
|
|
218
|
+
}
|
|
219
|
+
static Timer = {};
|
|
220
|
+
static TimerClear(pageNumber) {
|
|
221
|
+
const timer = Editor.Timer[pageNumber];
|
|
222
|
+
if (timer) {
|
|
223
|
+
window.clearTimeout(timer);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
static TimerStart(pageNumber, callback) {
|
|
227
|
+
Editor.Timer[pageNumber] = window.setTimeout(() => {
|
|
228
|
+
if (typeof callback === "function") {
|
|
229
|
+
callback(pageNumber);
|
|
230
|
+
}
|
|
231
|
+
}, 1e3);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { IRect } from 'konva/lib/types';
|
|
2
|
+
import { type IAnnotationStore } from '../types.js';
|
|
3
|
+
import type { KonvaCanvas } from '../painter.js';
|
|
4
|
+
export interface ISelectorOptions {
|
|
5
|
+
konvaCanvasStore: Map<number, KonvaCanvas>;
|
|
6
|
+
getAnnotationStore: (id: string) => IAnnotationStore | undefined;
|
|
7
|
+
onSelected: (id: string, isClick: boolean, transformerRect: IRect) => void;
|
|
8
|
+
onMultiSelected: (ids: string[], combinedRect: IRect) => void;
|
|
9
|
+
onCancel: () => void;
|
|
10
|
+
onChanged: (id: string, konvaGroupString: string, rawAnnotationStore: IAnnotationStore, konvaClientRect: IRect, transformerRect: IRect) => void;
|
|
11
|
+
onDelete: (id: string) => void;
|
|
12
|
+
onRequestDeleteConfirm?: (id: string) => Promise<boolean>;
|
|
13
|
+
onFreeTextDoubleClick?: (id: string) => void;
|
|
14
|
+
/** When provided and returns true, only pen/mouse input can interact. */
|
|
15
|
+
getStylusModeEnabled?: () => boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare class Selector {
|
|
18
|
+
readonly onSelected: (id: string, isClick: boolean, clientRect: IRect) => void;
|
|
19
|
+
readonly onChanged: (id: string, konvaGroupString: string, rawAnnotationStore: IAnnotationStore, konvaClientRect: IRect, transformerRect: IRect) => void;
|
|
20
|
+
readonly onDelete: (id: string) => void;
|
|
21
|
+
readonly onCancel: () => void;
|
|
22
|
+
readonly onMultiSelected: (ids: string[], combinedRect: IRect) => void;
|
|
23
|
+
private onRequestDeleteConfirm?;
|
|
24
|
+
private onFreeTextDoubleClick?;
|
|
25
|
+
private getStylusModeEnabled?;
|
|
26
|
+
private transformerStore;
|
|
27
|
+
private getAnnotationStore;
|
|
28
|
+
private konvaCanvasStore;
|
|
29
|
+
private _currentTransformerId;
|
|
30
|
+
private selectedId;
|
|
31
|
+
private selectedIds;
|
|
32
|
+
private marqueeRect;
|
|
33
|
+
private marqueeStartPos;
|
|
34
|
+
private marqueeStage;
|
|
35
|
+
constructor({ konvaCanvasStore, getAnnotationStore, onDelete, onSelected, onMultiSelected, onCancel, onChanged, onRequestDeleteConfirm, onFreeTextDoubleClick, getStylusModeEnabled, }: ISelectorOptions);
|
|
36
|
+
/** Returns true if this event should be rejected (finger touch in stylus mode). */
|
|
37
|
+
private isStylusRejected;
|
|
38
|
+
private handleKeyDown;
|
|
39
|
+
get currentTransformerId(): string | null;
|
|
40
|
+
set currentTransformerId(id: string | null);
|
|
41
|
+
private disableStageEvents;
|
|
42
|
+
private bindStageEvents;
|
|
43
|
+
private getBackgroundLayer;
|
|
44
|
+
private getPageShapeGroups;
|
|
45
|
+
private getGroupById;
|
|
46
|
+
private getFirstShapeInGroup;
|
|
47
|
+
private enableShapeGroups;
|
|
48
|
+
private disableShapeGroups;
|
|
49
|
+
private bindShapeEvents;
|
|
50
|
+
private removeShapeEvents;
|
|
51
|
+
private handleShapeClick;
|
|
52
|
+
private createTransformer;
|
|
53
|
+
private flashNodeWithTransformer;
|
|
54
|
+
private getTotalBox;
|
|
55
|
+
private toggleCursorStyle;
|
|
56
|
+
private handleShapeMouseover;
|
|
57
|
+
private handleShapeMouseout;
|
|
58
|
+
private clearTransformers;
|
|
59
|
+
private deactivateTransformer;
|
|
60
|
+
private selectedShape;
|
|
61
|
+
clear(): void;
|
|
62
|
+
activate(pageNumber: number): void;
|
|
63
|
+
select(id: string): void;
|
|
64
|
+
refreshCurrentSelection(): IRect | null;
|
|
65
|
+
delete(): void;
|
|
66
|
+
activateMarquee(pageNumber: number): void;
|
|
67
|
+
private bindMarqueeEvents;
|
|
68
|
+
private rectsIntersect;
|
|
69
|
+
activateEraser(pageNumber: number): void;
|
|
70
|
+
private eraserLine;
|
|
71
|
+
private eraserStage;
|
|
72
|
+
private bindEraserEvents;
|
|
73
|
+
destroy(): void;
|
|
74
|
+
}
|