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,165 @@
|
|
|
1
|
+
import Konva from "konva";
|
|
2
|
+
import { AnnotationType } from "../types.js";
|
|
3
|
+
import { Editor } from "../editor/editor.js";
|
|
4
|
+
export class EditorFreeHighlight extends Editor {
|
|
5
|
+
line;
|
|
6
|
+
// The freeform line currently being drawn
|
|
7
|
+
constructor(EditorOptions) {
|
|
8
|
+
super({ ...EditorOptions, editorType: AnnotationType.FREE_HIGHLIGHT });
|
|
9
|
+
this.line = null;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Handles mouse or touch pointer-down events and starts drawing a freeform curve.
|
|
13
|
+
* @param e Konva event object
|
|
14
|
+
*/
|
|
15
|
+
mouseDownHandler(e) {
|
|
16
|
+
if (e.currentTarget !== this.konvaStage) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
this.line = null;
|
|
20
|
+
this.isPainting = true;
|
|
21
|
+
this.currentShapeGroup = this.createShapeGroup();
|
|
22
|
+
this.getBgLayer().add(this.currentShapeGroup.konvaGroup);
|
|
23
|
+
const pos = this.konvaStage.getRelativePointerPosition();
|
|
24
|
+
this.line = new Konva.Line({
|
|
25
|
+
// do not scale strokes
|
|
26
|
+
strokeScaleEnabled: false,
|
|
27
|
+
stroke: this.currentAnnotation.style.color,
|
|
28
|
+
strokeWidth: this.currentAnnotation.style.strokeWidth,
|
|
29
|
+
opacity: this.currentAnnotation.style.opacity,
|
|
30
|
+
hitStrokeWidth: this.currentAnnotation.style.strokeWidth,
|
|
31
|
+
lineCap: "round",
|
|
32
|
+
lineJoin: "round",
|
|
33
|
+
visible: false,
|
|
34
|
+
globalCompositeOperation: "source-over",
|
|
35
|
+
points: [pos.x, pos.y]
|
|
36
|
+
// Initialize the starting point
|
|
37
|
+
});
|
|
38
|
+
this.currentShapeGroup.konvaGroup.add(this.line);
|
|
39
|
+
window.addEventListener("mouseup", this.globalPointerUpHandler);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Handles mouse or touch pointer-move events and draws the freeform curve.
|
|
43
|
+
* @param e Konva event object
|
|
44
|
+
*/
|
|
45
|
+
mouseMoveHandler(e) {
|
|
46
|
+
if (!this.isPainting) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
e.evt.preventDefault();
|
|
50
|
+
this.line.show();
|
|
51
|
+
const pos = this.konvaStage.getRelativePointerPosition();
|
|
52
|
+
const newPoints = this.line.points().concat([pos.x, pos.y]);
|
|
53
|
+
this.line.points(newPoints);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Handles mouse or touch pointer-up events and finishes drawing the freeform curve.
|
|
57
|
+
*/
|
|
58
|
+
mouseUpHandler() {
|
|
59
|
+
if (!this.isPainting) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
this.isPainting = false;
|
|
63
|
+
const group = this.line?.getParent();
|
|
64
|
+
if (group && !this.line.isVisible() && group.getType() === "Group") {
|
|
65
|
+
this.delShapeGroup(group.id());
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (this.isTooSmall()) {
|
|
69
|
+
this.line?.destroy();
|
|
70
|
+
if (group) {
|
|
71
|
+
this.delShapeGroup(group.id());
|
|
72
|
+
}
|
|
73
|
+
this.line = null;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (this.line) {
|
|
77
|
+
const originalPoints = this.line.points();
|
|
78
|
+
const correctedPoints = this.correctLineIfStraight(originalPoints);
|
|
79
|
+
this.line.points(correctedPoints);
|
|
80
|
+
this.setShapeGroupDone({
|
|
81
|
+
id: group.id(),
|
|
82
|
+
color: this.currentAnnotation.style.color,
|
|
83
|
+
contentsObj: {
|
|
84
|
+
text: ""
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
this.line = null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Global mouseup event handler that only handles left-button releases.
|
|
92
|
+
* @param e MouseEvent object
|
|
93
|
+
*/
|
|
94
|
+
globalPointerUpHandler = (e) => {
|
|
95
|
+
if (e.button !== 0) return;
|
|
96
|
+
this.mouseUpHandler();
|
|
97
|
+
window.removeEventListener("mouseup", this.globalPointerUpHandler);
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Corrects lines that are close to horizontal or vertical so they become perfectly horizontal or vertical.
|
|
101
|
+
* @param points The line points
|
|
102
|
+
* @returns The corrected points
|
|
103
|
+
*/
|
|
104
|
+
correctLineIfStraight(points) {
|
|
105
|
+
const THRESHOLD_ANGLE_DEGREES = 2;
|
|
106
|
+
const startX = points[0];
|
|
107
|
+
const startY = points[1];
|
|
108
|
+
const endX = points[points.length - 2];
|
|
109
|
+
const endY = points[points.length - 1];
|
|
110
|
+
const deltaX = endX - startX;
|
|
111
|
+
const deltaY = endY - startY;
|
|
112
|
+
const angleRad = Math.atan2(deltaY, deltaX);
|
|
113
|
+
const angleDeg = Math.abs(angleRad * (180 / Math.PI));
|
|
114
|
+
const isCloseToHorizontal = angleDeg <= THRESHOLD_ANGLE_DEGREES || angleDeg >= 180 - THRESHOLD_ANGLE_DEGREES;
|
|
115
|
+
const isCloseToVertical = Math.abs(angleDeg - 90) <= THRESHOLD_ANGLE_DEGREES;
|
|
116
|
+
if (isCloseToHorizontal) {
|
|
117
|
+
return points.map(
|
|
118
|
+
(value, index) => index % 2 === 0 ? value : startY
|
|
119
|
+
);
|
|
120
|
+
} else if (isCloseToVertical) {
|
|
121
|
+
return points.map(
|
|
122
|
+
(value, index) => index % 2 === 0 ? startX : value
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
return points;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Determines whether the current line is too small.
|
|
129
|
+
* @returns True if the line point count is less than 5, otherwise false
|
|
130
|
+
*/
|
|
131
|
+
isTooSmall() {
|
|
132
|
+
return (this.line?.points().length || 0) < 5;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* @description Update annotation styles
|
|
136
|
+
* @param annotationStore
|
|
137
|
+
* @param styles
|
|
138
|
+
*/
|
|
139
|
+
changeStyle(annotationStore, styles) {
|
|
140
|
+
const id = annotationStore.id;
|
|
141
|
+
const group = this.getShapeGroupById(id);
|
|
142
|
+
if (group) {
|
|
143
|
+
group.getChildren().forEach((shape) => {
|
|
144
|
+
if (shape instanceof Konva.Line) {
|
|
145
|
+
if (styles.color !== void 0) {
|
|
146
|
+
shape.stroke(styles.color);
|
|
147
|
+
}
|
|
148
|
+
if (styles.strokeWidth !== void 0) {
|
|
149
|
+
shape.strokeWidth(styles.strokeWidth);
|
|
150
|
+
}
|
|
151
|
+
if (styles.opacity !== void 0) {
|
|
152
|
+
shape.opacity(styles.opacity);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
const changedPayload = {
|
|
157
|
+
konvaString: group.toJSON()
|
|
158
|
+
};
|
|
159
|
+
if (styles.color !== void 0) {
|
|
160
|
+
changedPayload.color = styles.color;
|
|
161
|
+
}
|
|
162
|
+
this.setChanged(id, changedPayload);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { KonvaEventObject } from 'konva/lib/Node';
|
|
2
|
+
import { type IAnnotationStore, type IAnnotationStyle } from '../types.js';
|
|
3
|
+
import { Editor, type IEditorOptions } from '../editor/editor.js';
|
|
4
|
+
export interface TextInputResult {
|
|
5
|
+
inputValue: string;
|
|
6
|
+
color: string;
|
|
7
|
+
fontSize: number;
|
|
8
|
+
cancelled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface IEditorFreeTextOptions extends IEditorOptions {
|
|
11
|
+
onRequestTextInput: (opts: {
|
|
12
|
+
defaultColor: string;
|
|
13
|
+
defaultFontSize: number;
|
|
14
|
+
initialText?: string;
|
|
15
|
+
}) => Promise<TextInputResult>;
|
|
16
|
+
}
|
|
17
|
+
export declare class EditorFreeText extends Editor {
|
|
18
|
+
private onRequestTextInput;
|
|
19
|
+
constructor(editorOptions: IEditorFreeTextOptions);
|
|
20
|
+
protected mouseDownHandler(): void;
|
|
21
|
+
protected mouseMoveHandler(): void;
|
|
22
|
+
protected mouseUpHandler(e: KonvaEventObject<PointerEvent>): Promise<void>;
|
|
23
|
+
private static measureText;
|
|
24
|
+
private inputDoneHandler;
|
|
25
|
+
applyTextContent(id: string, text: string, color: string, fontSize: number): void;
|
|
26
|
+
protected changeStyle(annotationStore: IAnnotationStore, styles: IAnnotationStyle): void;
|
|
27
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import Konva from "konva";
|
|
2
|
+
import { AnnotationType } from "../types.js";
|
|
3
|
+
import { Editor } from "../editor/editor.js";
|
|
4
|
+
export class EditorFreeText extends Editor {
|
|
5
|
+
onRequestTextInput;
|
|
6
|
+
constructor(editorOptions) {
|
|
7
|
+
super({ ...editorOptions, editorType: AnnotationType.FREETEXT });
|
|
8
|
+
this.onRequestTextInput = editorOptions.onRequestTextInput;
|
|
9
|
+
}
|
|
10
|
+
mouseDownHandler() {
|
|
11
|
+
}
|
|
12
|
+
mouseMoveHandler() {
|
|
13
|
+
}
|
|
14
|
+
async mouseUpHandler(e) {
|
|
15
|
+
const pos = this.konvaStage.getRelativePointerPosition();
|
|
16
|
+
const { x, y } = this.konvaStage.scale();
|
|
17
|
+
if (e.currentTarget !== this.konvaStage || !pos) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
this.isPainting = true;
|
|
21
|
+
this.currentShapeGroup = this.createShapeGroup();
|
|
22
|
+
this.getBgLayer().add(this.currentShapeGroup.konvaGroup);
|
|
23
|
+
const result = await this.onRequestTextInput({
|
|
24
|
+
defaultColor: this.currentAnnotation.style.color,
|
|
25
|
+
defaultFontSize: this.currentAnnotation.style.fontSize
|
|
26
|
+
});
|
|
27
|
+
if (result.cancelled) {
|
|
28
|
+
this.delShapeGroup(this.currentShapeGroup.id);
|
|
29
|
+
this.currentShapeGroup = null;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
this.inputDoneHandler(result.inputValue, { x, y }, pos, result.color, result.fontSize);
|
|
33
|
+
}
|
|
34
|
+
static measureText(value, fontSize) {
|
|
35
|
+
const maxWidth = 300;
|
|
36
|
+
const temp = new Konva.Text({ text: value, fontSize, padding: 2 });
|
|
37
|
+
const textWidth = temp.width();
|
|
38
|
+
return {
|
|
39
|
+
finalWidth: textWidth > maxWidth ? maxWidth : textWidth,
|
|
40
|
+
wrap: textWidth > maxWidth ? "word" : "none"
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
inputDoneHandler(inputValue, _scale, pos, color, fontSize) {
|
|
44
|
+
const value = inputValue.trim();
|
|
45
|
+
if (value === "") {
|
|
46
|
+
this.delShapeGroup(this.currentShapeGroup.id);
|
|
47
|
+
this.currentShapeGroup = null;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const { finalWidth, wrap } = EditorFreeText.measureText(value, fontSize);
|
|
51
|
+
const text = new Konva.Text({
|
|
52
|
+
x: pos.x,
|
|
53
|
+
y: pos.y + 2,
|
|
54
|
+
text: value,
|
|
55
|
+
width: finalWidth,
|
|
56
|
+
fontSize,
|
|
57
|
+
fill: color,
|
|
58
|
+
wrap
|
|
59
|
+
});
|
|
60
|
+
this.currentShapeGroup.konvaGroup.add(text);
|
|
61
|
+
const id = this.currentShapeGroup.konvaGroup.id();
|
|
62
|
+
this.setShapeGroupDone({
|
|
63
|
+
id,
|
|
64
|
+
contentsObj: { text: value },
|
|
65
|
+
color,
|
|
66
|
+
fontSize
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
applyTextContent(id, text, color, fontSize) {
|
|
70
|
+
const group = this.getShapeGroupById(id);
|
|
71
|
+
if (!group) return;
|
|
72
|
+
const value = text.trim();
|
|
73
|
+
if (!value) return;
|
|
74
|
+
const { finalWidth, wrap } = EditorFreeText.measureText(value, fontSize);
|
|
75
|
+
group.getChildren().forEach((shape) => {
|
|
76
|
+
if (shape instanceof Konva.Text) {
|
|
77
|
+
shape.setAttrs({ text: value, fill: color, fontSize, width: finalWidth, wrap });
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
this.setChanged(id, {
|
|
81
|
+
konvaString: group.toJSON(),
|
|
82
|
+
color,
|
|
83
|
+
fontSize,
|
|
84
|
+
contentsObj: { text: value }
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
changeStyle(annotationStore, styles) {
|
|
88
|
+
const id = annotationStore.id;
|
|
89
|
+
const group = this.getShapeGroupById(id);
|
|
90
|
+
if (group) {
|
|
91
|
+
group.getChildren().forEach((shape) => {
|
|
92
|
+
if (shape instanceof Konva.Text) {
|
|
93
|
+
if (styles.color !== void 0) {
|
|
94
|
+
shape.fill(styles.color);
|
|
95
|
+
}
|
|
96
|
+
if (styles.opacity !== void 0) {
|
|
97
|
+
shape.opacity(styles.opacity);
|
|
98
|
+
}
|
|
99
|
+
if (styles.fontSize !== void 0) {
|
|
100
|
+
const currentText = shape.text();
|
|
101
|
+
const { finalWidth, wrap } = EditorFreeText.measureText(currentText, styles.fontSize);
|
|
102
|
+
shape.setAttrs({ fontSize: styles.fontSize, width: finalWidth, wrap });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
const changedPayload = {
|
|
107
|
+
konvaString: group.toJSON()
|
|
108
|
+
};
|
|
109
|
+
if (styles.color !== void 0) changedPayload.color = styles.color;
|
|
110
|
+
if (styles.fontSize !== void 0) changedPayload.fontSize = styles.fontSize;
|
|
111
|
+
this.setChanged(id, changedPayload);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { KonvaEventObject } from 'konva/lib/Node';
|
|
2
|
+
import type { IAnnotationStore, IAnnotationStyle } from '../types.js';
|
|
3
|
+
import { Editor, type IEditorOptions } from '../editor/editor.js';
|
|
4
|
+
/**
|
|
5
|
+
* Freehand editor class that extends the base Editor and draws freeform curves on the canvas.
|
|
6
|
+
*/
|
|
7
|
+
export declare class EditorFreeHand extends Editor {
|
|
8
|
+
private line;
|
|
9
|
+
/**
|
|
10
|
+
* Constructor that initializes the freehand editor.
|
|
11
|
+
* @param EditorOptions Editor options interface
|
|
12
|
+
*/
|
|
13
|
+
constructor(EditorOptions: IEditorOptions);
|
|
14
|
+
/**
|
|
15
|
+
* Handles mouse or touch pointer-down events and starts drawing a freeform curve.
|
|
16
|
+
* @param e Konva event object
|
|
17
|
+
*/
|
|
18
|
+
protected mouseDownHandler(e: KonvaEventObject<MouseEvent | TouchEvent>): void;
|
|
19
|
+
/**
|
|
20
|
+
* Handles mouse or touch pointer-move events and draws the freeform curve.
|
|
21
|
+
* @param e Konva event object
|
|
22
|
+
*/
|
|
23
|
+
protected mouseMoveHandler(e: KonvaEventObject<MouseEvent | TouchEvent>): void;
|
|
24
|
+
/**
|
|
25
|
+
* Handles mouse or touch pointer-up events and finishes drawing the freeform curve.
|
|
26
|
+
*/
|
|
27
|
+
protected mouseUpHandler(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Global mouseup event handler that only handles left-button releases.
|
|
30
|
+
* @param e MouseEvent object
|
|
31
|
+
*/
|
|
32
|
+
private globalPointerUpHandler;
|
|
33
|
+
/**
|
|
34
|
+
* Determines whether the current line is too small.
|
|
35
|
+
* @returns True if the line point count is less than 5, otherwise false
|
|
36
|
+
*/
|
|
37
|
+
private isTooSmall;
|
|
38
|
+
/**
|
|
39
|
+
* @description Update annotation styles
|
|
40
|
+
* @param annotationStore
|
|
41
|
+
* @param styles
|
|
42
|
+
*/
|
|
43
|
+
protected changeStyle(annotationStore: IAnnotationStore, styles: IAnnotationStyle): void;
|
|
44
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import Konva from "konva";
|
|
2
|
+
import { AnnotationType } from "../types.js";
|
|
3
|
+
import { Editor } from "../editor/editor.js";
|
|
4
|
+
export class EditorFreeHand extends Editor {
|
|
5
|
+
line;
|
|
6
|
+
// The freeform line currently being drawn
|
|
7
|
+
/**
|
|
8
|
+
* Constructor that initializes the freehand editor.
|
|
9
|
+
* @param EditorOptions Editor options interface
|
|
10
|
+
*/
|
|
11
|
+
constructor(EditorOptions) {
|
|
12
|
+
super({ ...EditorOptions, editorType: AnnotationType.FREEHAND });
|
|
13
|
+
this.line = null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Handles mouse or touch pointer-down events and starts drawing a freeform curve.
|
|
17
|
+
* @param e Konva event object
|
|
18
|
+
*/
|
|
19
|
+
mouseDownHandler(e) {
|
|
20
|
+
if (e.currentTarget !== this.konvaStage) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
Editor.TimerClear(this.pageNumber);
|
|
24
|
+
this.line = null;
|
|
25
|
+
this.isPainting = true;
|
|
26
|
+
if (!this.currentShapeGroup) {
|
|
27
|
+
this.currentShapeGroup = this.createShapeGroup();
|
|
28
|
+
this.getBgLayer().add(this.currentShapeGroup.konvaGroup);
|
|
29
|
+
}
|
|
30
|
+
const pos = this.konvaStage.getRelativePointerPosition();
|
|
31
|
+
this.line = new Konva.Line({
|
|
32
|
+
// do not scale strokes
|
|
33
|
+
strokeScaleEnabled: false,
|
|
34
|
+
stroke: this.currentAnnotation.style.color,
|
|
35
|
+
// Set the line color
|
|
36
|
+
strokeWidth: this.currentAnnotation.style.strokeWidth,
|
|
37
|
+
// Set the line width
|
|
38
|
+
opacity: this.currentAnnotation.style.opacity,
|
|
39
|
+
// Set the line opacity
|
|
40
|
+
lineCap: "round",
|
|
41
|
+
// Set rounded line caps
|
|
42
|
+
lineJoin: "round",
|
|
43
|
+
// Set rounded line joins
|
|
44
|
+
hitStrokeWidth: 20,
|
|
45
|
+
// Set the hit detection width
|
|
46
|
+
visible: false,
|
|
47
|
+
// Initialize as hidden
|
|
48
|
+
globalCompositeOperation: "source-over",
|
|
49
|
+
points: [pos.x, pos.y, pos.x, pos.y]
|
|
50
|
+
// Initialize the starting point
|
|
51
|
+
});
|
|
52
|
+
this.currentShapeGroup.konvaGroup.add(this.line);
|
|
53
|
+
window.addEventListener("mouseup", this.globalPointerUpHandler);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Handles mouse or touch pointer-move events and draws the freeform curve.
|
|
57
|
+
* @param e Konva event object
|
|
58
|
+
*/
|
|
59
|
+
mouseMoveHandler(e) {
|
|
60
|
+
if (!this.isPainting) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
e.evt.preventDefault();
|
|
64
|
+
this.line.show();
|
|
65
|
+
const pos = this.konvaStage.getRelativePointerPosition();
|
|
66
|
+
const newPoints = this.line.points().concat([pos.x, pos.y]);
|
|
67
|
+
this.line.points(newPoints);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Handles mouse or touch pointer-up events and finishes drawing the freeform curve.
|
|
71
|
+
*/
|
|
72
|
+
mouseUpHandler() {
|
|
73
|
+
if (!this.isPainting) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
this.isPainting = false;
|
|
77
|
+
const group = this.line.getParent();
|
|
78
|
+
if (this.isTooSmall()) {
|
|
79
|
+
this.line.destroy();
|
|
80
|
+
Editor.TimerStart(this.pageNumber, () => {
|
|
81
|
+
this.setShapeGroupDone({
|
|
82
|
+
id: group.id(),
|
|
83
|
+
color: this.currentAnnotation.style.color,
|
|
84
|
+
contentsObj: {
|
|
85
|
+
text: ""
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
this.currentShapeGroup = null;
|
|
89
|
+
});
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
Editor.TimerStart(this.pageNumber, () => {
|
|
93
|
+
this.setShapeGroupDone({
|
|
94
|
+
id: group.id(),
|
|
95
|
+
color: this.currentAnnotation.style.color,
|
|
96
|
+
contentsObj: {
|
|
97
|
+
text: ""
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
this.currentShapeGroup = null;
|
|
101
|
+
});
|
|
102
|
+
this.line = null;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Global mouseup event handler that only handles left-button releases.
|
|
106
|
+
* @param e MouseEvent object
|
|
107
|
+
*/
|
|
108
|
+
globalPointerUpHandler = (e) => {
|
|
109
|
+
if (e.button !== 0) return;
|
|
110
|
+
this.mouseUpHandler();
|
|
111
|
+
window.removeEventListener("mouseup", this.globalPointerUpHandler);
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Determines whether the current line is too small.
|
|
115
|
+
* @returns True if the line point count is less than 5, otherwise false
|
|
116
|
+
*/
|
|
117
|
+
isTooSmall() {
|
|
118
|
+
return this.line.points().length < Editor.MinSize;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* @description Update annotation styles
|
|
122
|
+
* @param annotationStore
|
|
123
|
+
* @param styles
|
|
124
|
+
*/
|
|
125
|
+
changeStyle(annotationStore, styles) {
|
|
126
|
+
const id = annotationStore.id;
|
|
127
|
+
const group = this.getShapeGroupById(id);
|
|
128
|
+
if (group) {
|
|
129
|
+
group.getChildren().forEach((shape) => {
|
|
130
|
+
if (shape instanceof Konva.Line) {
|
|
131
|
+
if (styles.color !== void 0) {
|
|
132
|
+
shape.stroke(styles.color);
|
|
133
|
+
}
|
|
134
|
+
if (styles.strokeWidth !== void 0) {
|
|
135
|
+
shape.strokeWidth(styles.strokeWidth);
|
|
136
|
+
}
|
|
137
|
+
if (styles.opacity !== void 0) {
|
|
138
|
+
shape.opacity(styles.opacity);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
const changedPayload = {
|
|
143
|
+
konvaString: group.toJSON()
|
|
144
|
+
};
|
|
145
|
+
if (styles.color !== void 0) {
|
|
146
|
+
changedPayload.color = styles.color;
|
|
147
|
+
}
|
|
148
|
+
this.setChanged(id, changedPayload);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { IAnnotationStore, IAnnotationStyle } from '../types.js';
|
|
2
|
+
import { AnnotationType } from '../types.js';
|
|
3
|
+
import { Editor, type IEditorOptions } from '../editor/editor.js';
|
|
4
|
+
/**
|
|
5
|
+
* EditorHighLight is a highlight editor class that extends Editor.
|
|
6
|
+
*/
|
|
7
|
+
export declare class EditorHighLight extends Editor {
|
|
8
|
+
/**
|
|
9
|
+
* Creates an EditorHighLight instance.
|
|
10
|
+
* @param EditorOptions Options used to initialize the editor
|
|
11
|
+
* @param editorType Annotation type
|
|
12
|
+
*/
|
|
13
|
+
constructor(EditorOptions: IEditorOptions, editorType: AnnotationType);
|
|
14
|
+
/**
|
|
15
|
+
* Converts selected text areas on the page into shapes and draws them on the canvas.
|
|
16
|
+
* @param elements HTMLSpanElement array containing the elements to draw
|
|
17
|
+
* @param fixElement Element used as the positioning reference
|
|
18
|
+
*/
|
|
19
|
+
convertTextSelection(elements: HTMLSpanElement[], fixElement: HTMLDivElement): void;
|
|
20
|
+
/**
|
|
21
|
+
* Gets the text content of all elements.
|
|
22
|
+
* @param elements HTMLSpanElement array
|
|
23
|
+
* @returns String containing the text content of all elements
|
|
24
|
+
*/
|
|
25
|
+
private getElementOuterText;
|
|
26
|
+
/**
|
|
27
|
+
* Calculates the relative position and size of an element for the canvas coordinate system.
|
|
28
|
+
* @param elementBounding Element bounding box
|
|
29
|
+
* @param fixBounding Reference element bounding box
|
|
30
|
+
* @returns Relative position and size object { x, y, width, height }
|
|
31
|
+
*/
|
|
32
|
+
private calculateRelativePosition;
|
|
33
|
+
/**
|
|
34
|
+
* Creates the corresponding shape for the current annotation type.
|
|
35
|
+
* @param x Shape X coordinate
|
|
36
|
+
* @param y Shape Y coordinate
|
|
37
|
+
* @param width Shape width
|
|
38
|
+
* @param height Shape height
|
|
39
|
+
* @returns A concrete Konva.Shape instance
|
|
40
|
+
*/
|
|
41
|
+
private createShape;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a highlight shape.
|
|
44
|
+
* @param x Shape X coordinate
|
|
45
|
+
* @param y Shape Y coordinate
|
|
46
|
+
* @param width Shape width
|
|
47
|
+
* @param height Shape height
|
|
48
|
+
* @returns Konva.Rect highlight shape instance
|
|
49
|
+
*/
|
|
50
|
+
private createHighlightShape;
|
|
51
|
+
/**
|
|
52
|
+
* Creates an underline shape.
|
|
53
|
+
* @param x Shape X coordinate
|
|
54
|
+
* @param y Shape Y coordinate
|
|
55
|
+
* @param width Shape width
|
|
56
|
+
* @param height Shape height
|
|
57
|
+
* @returns Konva.Rect underline shape instance
|
|
58
|
+
*/
|
|
59
|
+
private createUnderlineShape;
|
|
60
|
+
/**
|
|
61
|
+
* Creates a strikeout shape.
|
|
62
|
+
* @param x Shape X coordinate
|
|
63
|
+
* @param y Shape Y coordinate
|
|
64
|
+
* @param width Shape width
|
|
65
|
+
* @param height Shape height
|
|
66
|
+
* @returns Konva.Rect strikeout shape instance
|
|
67
|
+
*/
|
|
68
|
+
private createStrikeoutShape;
|
|
69
|
+
/**
|
|
70
|
+
* Handles mouse-down events. No specific logic is implemented yet.
|
|
71
|
+
*/
|
|
72
|
+
protected mouseDownHandler(): void;
|
|
73
|
+
/**
|
|
74
|
+
* Handles mouse-move events. No specific logic is implemented yet.
|
|
75
|
+
*/
|
|
76
|
+
protected mouseMoveHandler(): void;
|
|
77
|
+
/**
|
|
78
|
+
* Handles mouse-up events. No specific logic is implemented yet.
|
|
79
|
+
*/
|
|
80
|
+
protected mouseUpHandler(): void;
|
|
81
|
+
/**
|
|
82
|
+
* @description Update annotation styles
|
|
83
|
+
* @param annotationStore
|
|
84
|
+
* @param styles
|
|
85
|
+
*/
|
|
86
|
+
protected changeStyle(annotationStore: IAnnotationStore, styles: IAnnotationStyle): void;
|
|
87
|
+
}
|