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.
Files changed (197) hide show
  1. package/README.md +134 -0
  2. package/dist/module.d.mts +15 -0
  3. package/dist/module.json +9 -0
  4. package/dist/module.mjs +26 -0
  5. package/dist/runtime/annotation/engine/config.d.ts +52 -0
  6. package/dist/runtime/annotation/engine/config.js +283 -0
  7. package/dist/runtime/annotation/engine/const.d.ts +6 -0
  8. package/dist/runtime/annotation/engine/const.js +7 -0
  9. package/dist/runtime/annotation/engine/cursor-preview.d.ts +2 -0
  10. package/dist/runtime/annotation/engine/cursor-preview.js +88 -0
  11. package/dist/runtime/annotation/engine/editor/editor.d.ts +69 -0
  12. package/dist/runtime/annotation/engine/editor/editor.js +233 -0
  13. package/dist/runtime/annotation/engine/editor/selector.d.ts +74 -0
  14. package/dist/runtime/annotation/engine/editor/selector.js +594 -0
  15. package/dist/runtime/annotation/engine/import-normalize.d.ts +5 -0
  16. package/dist/runtime/annotation/engine/import-normalize.js +99 -0
  17. package/dist/runtime/annotation/engine/input-device.d.ts +53 -0
  18. package/dist/runtime/annotation/engine/input-device.js +64 -0
  19. package/dist/runtime/annotation/engine/painter.d.ts +97 -0
  20. package/dist/runtime/annotation/engine/painter.js +591 -0
  21. package/dist/runtime/annotation/engine/store.d.ts +11 -0
  22. package/dist/runtime/annotation/engine/store.js +47 -0
  23. package/dist/runtime/annotation/engine/tools/arrow.d.ts +22 -0
  24. package/dist/runtime/annotation/engine/tools/arrow.js +126 -0
  25. package/dist/runtime/annotation/engine/tools/circle.d.ts +45 -0
  26. package/dist/runtime/annotation/engine/tools/circle.js +148 -0
  27. package/dist/runtime/annotation/engine/tools/cloud.d.ts +50 -0
  28. package/dist/runtime/annotation/engine/tools/cloud.js +244 -0
  29. package/dist/runtime/annotation/engine/tools/free-highlight.d.ts +43 -0
  30. package/dist/runtime/annotation/engine/tools/free-highlight.js +165 -0
  31. package/dist/runtime/annotation/engine/tools/free-text.d.ts +27 -0
  32. package/dist/runtime/annotation/engine/tools/free-text.js +114 -0
  33. package/dist/runtime/annotation/engine/tools/freehand.d.ts +44 -0
  34. package/dist/runtime/annotation/engine/tools/freehand.js +151 -0
  35. package/dist/runtime/annotation/engine/tools/highlight.d.ts +87 -0
  36. package/dist/runtime/annotation/engine/tools/highlight.js +215 -0
  37. package/dist/runtime/annotation/engine/tools/note.d.ts +9 -0
  38. package/dist/runtime/annotation/engine/tools/note.js +34 -0
  39. package/dist/runtime/annotation/engine/tools/rectangle.d.ts +45 -0
  40. package/dist/runtime/annotation/engine/tools/rectangle.js +142 -0
  41. package/dist/runtime/annotation/engine/tools/signature.d.ts +16 -0
  42. package/dist/runtime/annotation/engine/tools/signature.js +74 -0
  43. package/dist/runtime/annotation/engine/tools/stamp.d.ts +18 -0
  44. package/dist/runtime/annotation/engine/tools/stamp.js +94 -0
  45. package/dist/runtime/annotation/engine/types.d.ts +170 -0
  46. package/dist/runtime/annotation/engine/types.js +67 -0
  47. package/dist/runtime/annotation/engine/utils.d.ts +40 -0
  48. package/dist/runtime/annotation/engine/utils.js +257 -0
  49. package/dist/runtime/annotation/parsers/parseFormFields.d.ts +9 -0
  50. package/dist/runtime/annotation/parsers/parseFormFields.js +101 -0
  51. package/dist/runtime/annotation/pdf-export/download.d.ts +1 -0
  52. package/dist/runtime/annotation/pdf-export/download.js +10 -0
  53. package/dist/runtime/annotation/pdf-export/export-form-fields.d.ts +9 -0
  54. package/dist/runtime/annotation/pdf-export/export-form-fields.js +90 -0
  55. package/dist/runtime/annotation/pdf-export/export.d.ts +15 -0
  56. package/dist/runtime/annotation/pdf-export/export.js +145 -0
  57. package/dist/runtime/annotation/pdf-export/parse.d.ts +10 -0
  58. package/dist/runtime/annotation/pdf-export/parse.js +19 -0
  59. package/dist/runtime/annotation/pdf-export/parse_circle.d.ts +4 -0
  60. package/dist/runtime/annotation/pdf-export/parse_circle.js +41 -0
  61. package/dist/runtime/annotation/pdf-export/parse_freetext.d.ts +4 -0
  62. package/dist/runtime/annotation/pdf-export/parse_freetext.js +54 -0
  63. package/dist/runtime/annotation/pdf-export/parse_highlight.d.ts +4 -0
  64. package/dist/runtime/annotation/pdf-export/parse_highlight.js +134 -0
  65. package/dist/runtime/annotation/pdf-export/parse_ink.d.ts +4 -0
  66. package/dist/runtime/annotation/pdf-export/parse_ink.js +124 -0
  67. package/dist/runtime/annotation/pdf-export/parse_line.d.ts +4 -0
  68. package/dist/runtime/annotation/pdf-export/parse_line.js +71 -0
  69. package/dist/runtime/annotation/pdf-export/parse_polyline.d.ts +4 -0
  70. package/dist/runtime/annotation/pdf-export/parse_polyline.js +93 -0
  71. package/dist/runtime/annotation/pdf-export/parse_square.d.ts +4 -0
  72. package/dist/runtime/annotation/pdf-export/parse_square.js +41 -0
  73. package/dist/runtime/annotation/pdf-export/parse_stamp.d.ts +4 -0
  74. package/dist/runtime/annotation/pdf-export/parse_stamp.js +195 -0
  75. package/dist/runtime/annotation/pdf-export/parse_strikeout.d.ts +4 -0
  76. package/dist/runtime/annotation/pdf-export/parse_strikeout.js +59 -0
  77. package/dist/runtime/annotation/pdf-export/parse_text.d.ts +4 -0
  78. package/dist/runtime/annotation/pdf-export/parse_text.js +42 -0
  79. package/dist/runtime/annotation/pdf-export/parse_underline.d.ts +4 -0
  80. package/dist/runtime/annotation/pdf-export/parse_underline.js +59 -0
  81. package/dist/runtime/assets/kviewer.css +1 -0
  82. package/dist/runtime/components/AnnotationToolbar.d.vue.ts +3 -0
  83. package/dist/runtime/components/AnnotationToolbar.vue +125 -0
  84. package/dist/runtime/components/AnnotationToolbar.vue.d.ts +3 -0
  85. package/dist/runtime/components/FloatingPageIndicator.d.vue.ts +6 -0
  86. package/dist/runtime/components/FloatingPageIndicator.vue +93 -0
  87. package/dist/runtime/components/FloatingPageIndicator.vue.d.ts +6 -0
  88. package/dist/runtime/components/FormFieldLayer.d.vue.ts +11 -0
  89. package/dist/runtime/components/FormFieldLayer.vue +40 -0
  90. package/dist/runtime/components/FormFieldLayer.vue.d.ts +11 -0
  91. package/dist/runtime/components/PdfPage.d.vue.ts +9 -0
  92. package/dist/runtime/components/PdfPage.vue +199 -0
  93. package/dist/runtime/components/PdfPage.vue.d.ts +9 -0
  94. package/dist/runtime/components/ToolButton.d.vue.ts +13 -0
  95. package/dist/runtime/components/ToolButton.vue +26 -0
  96. package/dist/runtime/components/ToolButton.vue.d.ts +13 -0
  97. package/dist/runtime/components/Toolbar.d.vue.ts +3 -0
  98. package/dist/runtime/components/Toolbar.vue +11 -0
  99. package/dist/runtime/components/Toolbar.vue.d.ts +3 -0
  100. package/dist/runtime/components/Viewer.d.vue.ts +45 -0
  101. package/dist/runtime/components/Viewer.vue +617 -0
  102. package/dist/runtime/components/Viewer.vue.d.ts +45 -0
  103. package/dist/runtime/components/ViewerBar.d.vue.ts +3 -0
  104. package/dist/runtime/components/ViewerBar.vue +91 -0
  105. package/dist/runtime/components/ViewerBar.vue.d.ts +3 -0
  106. package/dist/runtime/components/ViewerTabs.d.vue.ts +381 -0
  107. package/dist/runtime/components/ViewerTabs.vue +171 -0
  108. package/dist/runtime/components/ViewerTabs.vue.d.ts +381 -0
  109. package/dist/runtime/components/form-fields/FormButton.d.vue.ts +7 -0
  110. package/dist/runtime/components/form-fields/FormButton.vue +39 -0
  111. package/dist/runtime/components/form-fields/FormButton.vue.d.ts +7 -0
  112. package/dist/runtime/components/form-fields/FormCheckbox.d.vue.ts +7 -0
  113. package/dist/runtime/components/form-fields/FormCheckbox.vue +28 -0
  114. package/dist/runtime/components/form-fields/FormCheckbox.vue.d.ts +7 -0
  115. package/dist/runtime/components/form-fields/FormDropdown.d.vue.ts +7 -0
  116. package/dist/runtime/components/form-fields/FormDropdown.vue +112 -0
  117. package/dist/runtime/components/form-fields/FormDropdown.vue.d.ts +7 -0
  118. package/dist/runtime/components/form-fields/FormFieldWrapper.d.vue.ts +8 -0
  119. package/dist/runtime/components/form-fields/FormFieldWrapper.vue +41 -0
  120. package/dist/runtime/components/form-fields/FormFieldWrapper.vue.d.ts +8 -0
  121. package/dist/runtime/components/form-fields/FormRadioButton.d.vue.ts +7 -0
  122. package/dist/runtime/components/form-fields/FormRadioButton.vue +30 -0
  123. package/dist/runtime/components/form-fields/FormRadioButton.vue.d.ts +7 -0
  124. package/dist/runtime/components/form-fields/FormSignatureField.d.vue.ts +7 -0
  125. package/dist/runtime/components/form-fields/FormSignatureField.vue +54 -0
  126. package/dist/runtime/components/form-fields/FormSignatureField.vue.d.ts +7 -0
  127. package/dist/runtime/components/form-fields/FormTextField.d.vue.ts +7 -0
  128. package/dist/runtime/components/form-fields/FormTextField.vue +66 -0
  129. package/dist/runtime/components/form-fields/FormTextField.vue.d.ts +7 -0
  130. package/dist/runtime/components/modals/FreeTextModal.d.vue.ts +25 -0
  131. package/dist/runtime/components/modals/FreeTextModal.vue +89 -0
  132. package/dist/runtime/components/modals/FreeTextModal.vue.d.ts +25 -0
  133. package/dist/runtime/components/modals/SignatureDrawModal.d.vue.ts +14 -0
  134. package/dist/runtime/components/modals/SignatureDrawModal.vue +120 -0
  135. package/dist/runtime/components/modals/SignatureDrawModal.vue.d.ts +14 -0
  136. package/dist/runtime/components/panels/SignaturePicker.d.vue.ts +3 -0
  137. package/dist/runtime/components/panels/SignaturePicker.vue +85 -0
  138. package/dist/runtime/components/panels/SignaturePicker.vue.d.ts +3 -0
  139. package/dist/runtime/components/panels/StampPicker.d.vue.ts +3 -0
  140. package/dist/runtime/components/panels/StampPicker.vue +46 -0
  141. package/dist/runtime/components/panels/StampPicker.vue.d.ts +3 -0
  142. package/dist/runtime/components/tools/ActionTools.d.vue.ts +3 -0
  143. package/dist/runtime/components/tools/ActionTools.vue +32 -0
  144. package/dist/runtime/components/tools/ActionTools.vue.d.ts +3 -0
  145. package/dist/runtime/components/tools/DrawingTools.d.vue.ts +6 -0
  146. package/dist/runtime/components/tools/DrawingTools.vue +57 -0
  147. package/dist/runtime/components/tools/DrawingTools.vue.d.ts +6 -0
  148. package/dist/runtime/components/tools/HandTool.d.vue.ts +3 -0
  149. package/dist/runtime/components/tools/HandTool.vue +14 -0
  150. package/dist/runtime/components/tools/HandTool.vue.d.ts +3 -0
  151. package/dist/runtime/components/tools/MarqueeTool.d.vue.ts +3 -0
  152. package/dist/runtime/components/tools/MarqueeTool.vue +15 -0
  153. package/dist/runtime/components/tools/MarqueeTool.vue.d.ts +3 -0
  154. package/dist/runtime/components/tools/PageInfo.d.vue.ts +3 -0
  155. package/dist/runtime/components/tools/PageInfo.vue +10 -0
  156. package/dist/runtime/components/tools/PageInfo.vue.d.ts +3 -0
  157. package/dist/runtime/components/tools/PageSettings.d.vue.ts +3 -0
  158. package/dist/runtime/components/tools/PageSettings.vue +92 -0
  159. package/dist/runtime/components/tools/PageSettings.vue.d.ts +3 -0
  160. package/dist/runtime/components/tools/SearchTool.d.vue.ts +3 -0
  161. package/dist/runtime/components/tools/SearchTool.vue +149 -0
  162. package/dist/runtime/components/tools/SearchTool.vue.d.ts +3 -0
  163. package/dist/runtime/components/tools/ToolProperties.d.vue.ts +7 -0
  164. package/dist/runtime/components/tools/ToolProperties.vue +174 -0
  165. package/dist/runtime/components/tools/ToolProperties.vue.d.ts +7 -0
  166. package/dist/runtime/components/tools/ZoomControls.d.vue.ts +3 -0
  167. package/dist/runtime/components/tools/ZoomControls.vue +59 -0
  168. package/dist/runtime/components/tools/ZoomControls.vue.d.ts +3 -0
  169. package/dist/runtime/composables/search-utils.d.ts +20 -0
  170. package/dist/runtime/composables/search-utils.js +55 -0
  171. package/dist/runtime/composables/useAnnotationEngine.d.ts +7 -0
  172. package/dist/runtime/composables/useAnnotationEngine.js +70 -0
  173. package/dist/runtime/composables/useAnnotationHistory.d.ts +12 -0
  174. package/dist/runtime/composables/useAnnotationHistory.js +69 -0
  175. package/dist/runtime/composables/useFormFields.d.ts +26 -0
  176. package/dist/runtime/composables/useFormFields.js +112 -0
  177. package/dist/runtime/composables/usePageProxyCache.d.ts +8 -0
  178. package/dist/runtime/composables/usePageProxyCache.js +73 -0
  179. package/dist/runtime/composables/usePageSettings.d.ts +16 -0
  180. package/dist/runtime/composables/usePageSettings.js +66 -0
  181. package/dist/runtime/composables/usePageVirtualization.d.ts +19 -0
  182. package/dist/runtime/composables/usePageVirtualization.js +203 -0
  183. package/dist/runtime/composables/useSearchIndex.d.ts +11 -0
  184. package/dist/runtime/composables/useSearchIndex.js +71 -0
  185. package/dist/runtime/composables/useViewerSearch.d.ts +32 -0
  186. package/dist/runtime/composables/useViewerSearch.js +418 -0
  187. package/dist/runtime/composables/useViewerState.d.ts +62 -0
  188. package/dist/runtime/composables/useViewerState.js +189 -0
  189. package/dist/runtime/composables/viewMode.d.ts +11 -0
  190. package/dist/runtime/composables/viewMode.js +19 -0
  191. package/dist/runtime/plugin.d.ts +2 -0
  192. package/dist/runtime/plugin.js +3 -0
  193. package/dist/runtime/public-types.d.ts +2 -0
  194. package/dist/runtime/public-types.js +0 -0
  195. package/dist/runtime/server/tsconfig.json +3 -0
  196. package/dist/types.d.mts +5 -0
  197. package/package.json +64 -0
@@ -0,0 +1,126 @@
1
+ import Konva from "konva";
2
+ import { AnnotationType } from "../types.js";
3
+ import { Editor } from "../editor/editor.js";
4
+ export class EditorArrow extends Editor {
5
+ arrow;
6
+ // The arrow currently being drawn
7
+ startPoint;
8
+ // Start point coordinates
9
+ constructor(EditorOptions) {
10
+ super({ ...EditorOptions, editorType: AnnotationType.ARROW });
11
+ this.arrow = null;
12
+ this.startPoint = { x: 0, y: 0 };
13
+ }
14
+ mouseDownHandler(e) {
15
+ if (e.currentTarget !== this.konvaStage) return;
16
+ this.arrow = null;
17
+ this.isPainting = true;
18
+ this.currentShapeGroup = this.createShapeGroup();
19
+ this.getBgLayer().add(this.currentShapeGroup.konvaGroup);
20
+ const pos = this.konvaStage.getRelativePointerPosition();
21
+ this.startPoint = { x: pos.x, y: pos.y };
22
+ this.arrow = new Konva.Arrow({
23
+ points: [pos.x, pos.y, pos.x, pos.y],
24
+ stroke: this.currentAnnotation.style.color,
25
+ strokeWidth: this.currentAnnotation.style.strokeWidth,
26
+ fill: this.currentAnnotation.style.color,
27
+ pointerLength: 10,
28
+ pointerWidth: 10,
29
+ hitStrokeWidth: 20,
30
+ // Set the hit detection width
31
+ lineCap: "round",
32
+ lineJoin: "round",
33
+ strokeScaleEnabled: false,
34
+ visible: false,
35
+ opacity: this.currentAnnotation.style.opacity
36
+ });
37
+ this.currentShapeGroup.konvaGroup.add(this.arrow);
38
+ window.addEventListener("mouseup", this.globalPointerUpHandler);
39
+ }
40
+ mouseMoveHandler(e) {
41
+ if (!this.isPainting) return;
42
+ e.evt.preventDefault();
43
+ const pos = this.konvaStage.getRelativePointerPosition();
44
+ const points = [this.startPoint.x, this.startPoint.y, pos.x, pos.y];
45
+ this.arrow?.show();
46
+ this.arrow?.setAttrs({ points });
47
+ }
48
+ mouseUpHandler() {
49
+ if (!this.isPainting) return;
50
+ this.isPainting = false;
51
+ const group = this.arrow?.getParent();
52
+ if (!this.arrow?.isVisible() && group?.getType() === "Group") {
53
+ this.delShapeGroup(group.id());
54
+ return;
55
+ }
56
+ if (this.isTooShort()) {
57
+ this.arrow?.destroy();
58
+ this.delShapeGroup(group.id());
59
+ this.arrow = null;
60
+ return;
61
+ }
62
+ this.setShapeGroupDone({
63
+ id: group.id(),
64
+ color: this.currentAnnotation.style.color,
65
+ contentsObj: {
66
+ text: ""
67
+ }
68
+ });
69
+ this.arrow = null;
70
+ }
71
+ globalPointerUpHandler = (e) => {
72
+ if (e.button !== 0) return;
73
+ this.mouseUpHandler();
74
+ window.removeEventListener("mouseup", this.globalPointerUpHandler);
75
+ };
76
+ isTooShort() {
77
+ if (!this.arrow) return true;
78
+ const points = this.arrow.points();
79
+ if (points.length !== 4) return true;
80
+ const dx = points[2] - points[0];
81
+ const dy = points[3] - points[1];
82
+ return Math.hypot(dx, dy) < Editor.MinSize;
83
+ }
84
+ /**
85
+ * @description Update annotation styles
86
+ * @param annotationStore
87
+ * @param styles
88
+ */
89
+ changeStyle(annotationStore, styles) {
90
+ const id = annotationStore.id;
91
+ const group = this.getShapeGroupById(id);
92
+ if (group) {
93
+ group.getChildren().forEach((shape) => {
94
+ if (shape instanceof Konva.Arrow) {
95
+ if (styles.color !== void 0) {
96
+ shape.stroke(styles.color);
97
+ shape.fill(styles.color);
98
+ }
99
+ if (styles.strokeWidth !== void 0) {
100
+ const sw = styles.strokeWidth;
101
+ shape.strokeWidth(sw);
102
+ const ratio = 5;
103
+ const minSize = 6;
104
+ const maxSize = 30;
105
+ const pointerSize = Math.max(
106
+ minSize,
107
+ Math.min(maxSize, sw * ratio)
108
+ );
109
+ shape.pointerLength(pointerSize);
110
+ shape.pointerWidth(pointerSize);
111
+ }
112
+ if (styles.opacity !== void 0) {
113
+ shape.opacity(styles.opacity);
114
+ }
115
+ }
116
+ });
117
+ const changedPayload = {
118
+ konvaString: group.toJSON()
119
+ };
120
+ if (styles.color !== void 0) {
121
+ changedPayload.color = styles.color;
122
+ }
123
+ this.setChanged(id, changedPayload);
124
+ }
125
+ }
126
+ }
@@ -0,0 +1,45 @@
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
+ * Ellipse editor class that extends the base Editor and draws ellipses on the canvas.
6
+ */
7
+ export declare class EditorCircle extends Editor {
8
+ private ellipse;
9
+ private vertex;
10
+ /**
11
+ * Constructor that initializes the ellipse editor.
12
+ * @param EditorOptions Editor options interface
13
+ */
14
+ constructor(EditorOptions: IEditorOptions);
15
+ /**
16
+ * Handles mouse or touch pointer-down events and starts drawing an ellipse.
17
+ * @param e Konva event object
18
+ */
19
+ protected mouseDownHandler(e: KonvaEventObject<MouseEvent | TouchEvent>): void;
20
+ /**
21
+ * Handles mouse or touch pointer-move events and draws the ellipse.
22
+ * @param e Konva event object
23
+ */
24
+ protected mouseMoveHandler(e: KonvaEventObject<MouseEvent | TouchEvent>): void;
25
+ /**
26
+ * Handles mouse or touch pointer-up events and finishes drawing the ellipse.
27
+ */
28
+ protected mouseUpHandler(): void;
29
+ /**
30
+ * Global mouseup event handler that only handles left-button releases.
31
+ * @param e MouseEvent object
32
+ */
33
+ private globalPointerUpHandler;
34
+ /**
35
+ * Determines whether the ellipse is too small.
36
+ * @returns True if the ellipse width or height is smaller than the minimum size, otherwise false.
37
+ */
38
+ private isTooSmall;
39
+ /**
40
+ * @description Update annotation styles
41
+ * @param annotationStore
42
+ * @param styles
43
+ */
44
+ protected changeStyle(annotationStore: IAnnotationStore, styles: IAnnotationStyle): void;
45
+ }
@@ -0,0 +1,148 @@
1
+ import Konva from "konva";
2
+ import { AnnotationType } from "../types.js";
3
+ import { Editor } from "../editor/editor.js";
4
+ export class EditorCircle extends Editor {
5
+ ellipse;
6
+ // The ellipse currently being drawn
7
+ vertex;
8
+ // Stores the ellipse start point (vertex) coordinates
9
+ /**
10
+ * Constructor that initializes the ellipse editor.
11
+ * @param EditorOptions Editor options interface
12
+ */
13
+ constructor(EditorOptions) {
14
+ super({ ...EditorOptions, editorType: AnnotationType.CIRCLE });
15
+ this.ellipse = null;
16
+ this.vertex = { x: 0, y: 0 };
17
+ }
18
+ /**
19
+ * Handles mouse or touch pointer-down events and starts drawing an ellipse.
20
+ * @param e Konva event object
21
+ */
22
+ mouseDownHandler(e) {
23
+ if (e.currentTarget !== this.konvaStage) {
24
+ return;
25
+ }
26
+ this.ellipse = null;
27
+ this.isPainting = true;
28
+ this.currentShapeGroup = this.createShapeGroup();
29
+ this.getBgLayer().add(this.currentShapeGroup.konvaGroup);
30
+ const pos = this.konvaStage.getRelativePointerPosition();
31
+ this.vertex = { x: pos.x, y: pos.y };
32
+ this.ellipse = new Konva.Ellipse({
33
+ radiusX: 0,
34
+ radiusY: 0,
35
+ x: pos.x,
36
+ y: pos.y,
37
+ // do not scale strokes
38
+ strokeScaleEnabled: false,
39
+ visible: false,
40
+ // Start hidden
41
+ stroke: this.currentAnnotation.style.color,
42
+ // Set the ellipse stroke color
43
+ strokeWidth: this.currentAnnotation.style.strokeWidth,
44
+ // Set the ellipse stroke width
45
+ opacity: this.currentAnnotation.style.opacity
46
+ // Set the ellipse opacity
47
+ });
48
+ this.currentShapeGroup.konvaGroup.add(this.ellipse);
49
+ window.addEventListener("mouseup", this.globalPointerUpHandler);
50
+ }
51
+ /**
52
+ * Handles mouse or touch pointer-move events and draws the ellipse.
53
+ * @param e Konva event object
54
+ */
55
+ mouseMoveHandler(e) {
56
+ if (!this.isPainting) {
57
+ return;
58
+ }
59
+ e.evt.preventDefault();
60
+ this.ellipse.show();
61
+ const pos = this.konvaStage.getRelativePointerPosition();
62
+ const radiusX = Math.abs(pos.x - this.vertex.x) / 2;
63
+ const radiusY = Math.abs(pos.y - this.vertex.y) / 2;
64
+ const areaAttr = {
65
+ x: (pos.x - this.vertex.x) / 2 + this.vertex.x,
66
+ y: (pos.y - this.vertex.y) / 2 + this.vertex.y,
67
+ radiusX,
68
+ radiusY
69
+ };
70
+ this.ellipse.setAttrs(areaAttr);
71
+ }
72
+ /**
73
+ * Handles mouse or touch pointer-up events and finishes drawing the ellipse.
74
+ */
75
+ mouseUpHandler() {
76
+ if (!this.isPainting) {
77
+ return;
78
+ }
79
+ this.isPainting = false;
80
+ const group = this.ellipse.getParent();
81
+ if (!this.ellipse.isVisible() && group.getType() === "Group") {
82
+ this.delShapeGroup(group.id());
83
+ return;
84
+ }
85
+ if (this.isTooSmall()) {
86
+ this.ellipse.destroy();
87
+ this.delShapeGroup(group.id());
88
+ this.ellipse = null;
89
+ return;
90
+ }
91
+ this.setShapeGroupDone({
92
+ id: group.id(),
93
+ color: this.currentAnnotation.style.color,
94
+ contentsObj: {
95
+ text: ""
96
+ }
97
+ });
98
+ this.ellipse = null;
99
+ }
100
+ /**
101
+ * Global mouseup event handler that only handles left-button releases.
102
+ * @param e MouseEvent object
103
+ */
104
+ globalPointerUpHandler = (e) => {
105
+ if (e.button !== 0) return;
106
+ this.mouseUpHandler();
107
+ window.removeEventListener("mouseup", this.globalPointerUpHandler);
108
+ };
109
+ /**
110
+ * Determines whether the ellipse is too small.
111
+ * @returns True if the ellipse width or height is smaller than the minimum size, otherwise false.
112
+ */
113
+ isTooSmall() {
114
+ const { width, height } = this.ellipse.size();
115
+ return Math.max(width, height) < Editor.MinSize;
116
+ }
117
+ /**
118
+ * @description Update annotation styles
119
+ * @param annotationStore
120
+ * @param styles
121
+ */
122
+ changeStyle(annotationStore, styles) {
123
+ const id = annotationStore.id;
124
+ const group = this.getShapeGroupById(id);
125
+ if (group) {
126
+ group.getChildren().forEach((shape) => {
127
+ if (shape instanceof Konva.Ellipse) {
128
+ if (styles.color !== void 0) {
129
+ shape.stroke(styles.color);
130
+ }
131
+ if (styles.strokeWidth !== void 0) {
132
+ shape.strokeWidth(styles.strokeWidth);
133
+ }
134
+ if (styles.opacity !== void 0) {
135
+ shape.opacity(styles.opacity);
136
+ }
137
+ }
138
+ });
139
+ const changedPayload = {
140
+ konvaString: group.toJSON()
141
+ };
142
+ if (styles.color !== void 0) {
143
+ changedPayload.color = styles.color;
144
+ }
145
+ this.setChanged(id, changedPayload);
146
+ }
147
+ }
148
+ }
@@ -0,0 +1,50 @@
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
+ export declare class EditorCloud extends Editor {
5
+ private cloudPath;
6
+ private points;
7
+ private startRect;
8
+ private readonly startRectSize;
9
+ constructor(options: IEditorOptions);
10
+ private handleKeyUp;
11
+ private cancelDrawing;
12
+ protected mouseDownHandler(_e: KonvaEventObject<MouseEvent | TouchEvent>): void;
13
+ protected mouseMoveHandler(_e: KonvaEventObject<MouseEvent | TouchEvent>): void;
14
+ protected mouseUpHandler(_e?: KonvaEventObject<MouseEvent | TouchEvent>): void;
15
+ /**
16
+ * @description Handles double-click events and completes cloud drawing
17
+ */
18
+ private handleDoubleClick;
19
+ /**
20
+ * @description Updates the cloud preview path
21
+ * @param cursorPos - Cursor position with x and y coordinates
22
+ * @param cursorPos.x - X coordinate
23
+ * @param cursorPos.y - Y coordinate
24
+ */
25
+ private updateCloudPreview;
26
+ /**
27
+ * @description Generates cloud path data
28
+ * @param points - Array of points with x and y coordinates
29
+ */
30
+ private generateCloudPathData;
31
+ /**
32
+ * @description Calculates the centroid of a set of points
33
+ * @param points Array of points
34
+ * @returns Centroid coordinates
35
+ */
36
+ private computeCentroid;
37
+ /**
38
+ * @description Draws the start-point indicator rectangle
39
+ * @param pos - Start position
40
+ * @param pos.x - X coordinate
41
+ * @param pos.y - Y coordinate
42
+ */
43
+ private drawStartRect;
44
+ /**
45
+ * @description Update annotation styles
46
+ * @param annotationStore
47
+ * @param styles
48
+ */
49
+ protected changeStyle(annotationStore: IAnnotationStore, styles: IAnnotationStyle): void;
50
+ }
@@ -0,0 +1,244 @@
1
+ import Konva from "konva";
2
+ import { AnnotationType } from "../types.js";
3
+ import { Editor } from "../editor/editor.js";
4
+ export class EditorCloud extends Editor {
5
+ cloudPath = null;
6
+ points = [];
7
+ startRect = null;
8
+ startRectSize = 12;
9
+ constructor(options) {
10
+ super({ ...options, editorType: AnnotationType.CLOUD });
11
+ this.konvaStage.on("dblclick", this.handleDoubleClick);
12
+ window.addEventListener("keyup", this.handleKeyUp);
13
+ }
14
+ handleKeyUp = (e) => {
15
+ if (e.key === "Escape" && this.isPainting) {
16
+ this.cancelDrawing();
17
+ }
18
+ };
19
+ cancelDrawing() {
20
+ this.isPainting = false;
21
+ this.points = [];
22
+ if (this.cloudPath) {
23
+ this.cloudPath.destroy();
24
+ this.cloudPath = null;
25
+ }
26
+ if (this.startRect) {
27
+ this.startRect.destroy();
28
+ this.startRect = null;
29
+ }
30
+ if (this.currentShapeGroup) {
31
+ this.delShapeGroup(this.currentShapeGroup.konvaGroup.id());
32
+ this.currentShapeGroup = null;
33
+ }
34
+ this.getBgLayer().batchDraw();
35
+ }
36
+ mouseDownHandler(_e) {
37
+ const pos = this.konvaStage.getRelativePointerPosition();
38
+ this.points.push(pos);
39
+ if (!this.isPainting) {
40
+ this.isPainting = true;
41
+ this.currentShapeGroup = this.createShapeGroup();
42
+ this.getBgLayer().add(this.currentShapeGroup.konvaGroup);
43
+ this.cloudPath = new Konva.Path({
44
+ data: "",
45
+ stroke: this.currentAnnotation.style.color,
46
+ strokeWidth: this.currentAnnotation.style.strokeWidth,
47
+ fillEnabled: false,
48
+ lineJoin: "round",
49
+ lineCap: "round",
50
+ hitStrokeWidth: 20,
51
+ // Set the hit detection width
52
+ opacity: this.currentAnnotation.style.opacity
53
+ });
54
+ this.currentShapeGroup.konvaGroup.add(this.cloudPath);
55
+ this.drawStartRect(pos);
56
+ }
57
+ this.updateCloudPreview();
58
+ }
59
+ mouseMoveHandler(_e) {
60
+ if (!this.isPainting || !this.cloudPath) return;
61
+ const pos = this.konvaStage.getRelativePointerPosition();
62
+ this.updateCloudPreview(pos);
63
+ }
64
+ mouseUpHandler(_e) {
65
+ }
66
+ /**
67
+ * @description Handles double-click events and completes cloud drawing
68
+ */
69
+ handleDoubleClick = () => {
70
+ if (!this.isPainting || this.points.length < 3) return;
71
+ this.isPainting = false;
72
+ if (!this.cloudPath) return;
73
+ const closedPoints = [...this.points, this.points[0]];
74
+ const pathData = this.generateCloudPathData(closedPoints);
75
+ this.cloudPath.data(pathData);
76
+ this.setShapeGroupDone({
77
+ id: this.currentShapeGroup.konvaGroup.id(),
78
+ color: this.currentAnnotation.style.color,
79
+ contentsObj: { text: "" }
80
+ });
81
+ this.cloudPath = null;
82
+ this.points = [];
83
+ if (this.startRect) {
84
+ this.startRect.destroy();
85
+ this.startRect = null;
86
+ }
87
+ };
88
+ /**
89
+ * @description Updates the cloud preview path
90
+ * @param cursorPos - Cursor position with x and y coordinates
91
+ * @param cursorPos.x - X coordinate
92
+ * @param cursorPos.y - Y coordinate
93
+ */
94
+ updateCloudPreview(cursorPos) {
95
+ if (!this.cloudPath) return;
96
+ const pathPoints = [...this.points];
97
+ if (cursorPos) pathPoints.push(cursorPos);
98
+ const pathData = this.generateCloudPathData(pathPoints);
99
+ this.cloudPath.data(pathData);
100
+ }
101
+ /**
102
+ * @description Generates cloud path data
103
+ * @param points - Array of points with x and y coordinates
104
+ */
105
+ generateCloudPathData(points) {
106
+ if (points.length < 2) return "";
107
+ const radius = 12;
108
+ const waveStep = radius * 1.1;
109
+ const center = this.computeCentroid(points);
110
+ let path = "";
111
+ let fixedAngle = null;
112
+ for (let i = 0; i < points.length - 1; i++) {
113
+ const p1 = points[i];
114
+ const p2 = points[i + 1];
115
+ const dx = p2.x - p1.x;
116
+ const dy = p2.y - p1.y;
117
+ const length = Math.hypot(dx, dy);
118
+ let angle = Math.atan2(dy, dx);
119
+ if (i === 0 && !fixedAngle) fixedAngle = angle;
120
+ if (i === 0) angle = fixedAngle;
121
+ const normalX = Math.cos(angle + Math.PI / 2);
122
+ const normalY = Math.sin(angle + Math.PI / 2);
123
+ const segmentMidX = (p1.x + p2.x) / 2;
124
+ const segmentMidY = (p1.y + p2.y) / 2;
125
+ const toCenterX = center.x - segmentMidX;
126
+ const toCenterY = center.y - segmentMidY;
127
+ let normalSign = 1;
128
+ if (normalX * toCenterX + normalY * toCenterY > 0) normalSign = -1;
129
+ const steps = Math.max(2, Math.floor(length / waveStep));
130
+ for (let j = 0; j < steps; j++) {
131
+ const t1 = j / steps;
132
+ const t2 = (j + 1) / steps;
133
+ const x1 = p1.x + dx * t1;
134
+ const y1 = p1.y + dy * t1;
135
+ const x2 = p1.x + dx * t2;
136
+ const y2 = p1.y + dy * t2;
137
+ const midX = (x1 + x2) / 2;
138
+ const midY = (y1 + y2) / 2;
139
+ const controlX = midX + normalX * radius * normalSign;
140
+ const controlY = midY + normalY * radius * normalSign;
141
+ if (i === 0 && j === 0) {
142
+ path += `M ${x1} ${y1} `;
143
+ }
144
+ path += `Q ${controlX} ${controlY} ${x2} ${y2} `;
145
+ }
146
+ }
147
+ return path;
148
+ }
149
+ /**
150
+ * @description Calculates the centroid of a set of points
151
+ * @param points Array of points
152
+ * @returns Centroid coordinates
153
+ */
154
+ computeCentroid(points) {
155
+ const sum = points.reduce(
156
+ (acc, p) => {
157
+ acc.x += p.x;
158
+ acc.y += p.y;
159
+ return acc;
160
+ },
161
+ { x: 0, y: 0 }
162
+ );
163
+ return {
164
+ x: sum.x / points.length,
165
+ y: sum.y / points.length
166
+ };
167
+ }
168
+ /**
169
+ * @description Draws the start-point indicator rectangle
170
+ * @param pos - Start position
171
+ * @param pos.x - X coordinate
172
+ * @param pos.y - Y coordinate
173
+ */
174
+ drawStartRect(pos) {
175
+ this.startRect = new Konva.Rect({
176
+ x: pos.x - this.startRectSize / 2,
177
+ y: pos.y - this.startRectSize / 2,
178
+ width: this.startRectSize,
179
+ height: this.startRectSize,
180
+ stroke: "#000",
181
+ strokeWidth: 2,
182
+ fill: null,
183
+ cornerRadius: 2,
184
+ hitStrokeWidth: 10,
185
+ // Increase the hit detection area
186
+ draggable: false,
187
+ dash: [4, 2],
188
+ name: "startRect"
189
+ });
190
+ this.getBgLayer().add(this.startRect);
191
+ this.startRect.moveToTop();
192
+ this.startRect.on(
193
+ "mouseup",
194
+ (_e) => {
195
+ this.handleDoubleClick();
196
+ }
197
+ );
198
+ this.startRect.on(
199
+ "mousemove",
200
+ (_e) => {
201
+ this.startRect.stroke("#1677ff");
202
+ this.startRect.getLayer()?.batchDraw();
203
+ }
204
+ );
205
+ this.startRect.on(
206
+ "mouseout",
207
+ (_e) => {
208
+ this.startRect.stroke("#000");
209
+ this.startRect.getLayer()?.batchDraw();
210
+ }
211
+ );
212
+ }
213
+ /**
214
+ * @description Update annotation styles
215
+ * @param annotationStore
216
+ * @param styles
217
+ */
218
+ changeStyle(annotationStore, styles) {
219
+ const id = annotationStore.id;
220
+ const group = this.getShapeGroupById(id);
221
+ if (group) {
222
+ group.getChildren().forEach((shape) => {
223
+ if (shape instanceof Konva.Path) {
224
+ if (styles.color !== void 0) {
225
+ shape.stroke(styles.color);
226
+ }
227
+ if (styles.strokeWidth !== void 0) {
228
+ shape.strokeWidth(styles.strokeWidth);
229
+ }
230
+ if (styles.opacity !== void 0) {
231
+ shape.opacity(styles.opacity);
232
+ }
233
+ }
234
+ });
235
+ const changedPayload = {
236
+ konvaString: group.toJSON()
237
+ };
238
+ if (styles.color !== void 0) {
239
+ changedPayload.color = styles.color;
240
+ }
241
+ this.setChanged(id, changedPayload);
242
+ }
243
+ }
244
+ }
@@ -0,0 +1,43 @@
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
+ export declare class EditorFreeHighlight extends Editor {
5
+ private line;
6
+ constructor(EditorOptions: IEditorOptions);
7
+ /**
8
+ * Handles mouse or touch pointer-down events and starts drawing a freeform curve.
9
+ * @param e Konva event object
10
+ */
11
+ protected mouseDownHandler(e: KonvaEventObject<MouseEvent | TouchEvent>): void;
12
+ /**
13
+ * Handles mouse or touch pointer-move events and draws the freeform curve.
14
+ * @param e Konva event object
15
+ */
16
+ protected mouseMoveHandler(e: KonvaEventObject<MouseEvent | TouchEvent>): void;
17
+ /**
18
+ * Handles mouse or touch pointer-up events and finishes drawing the freeform curve.
19
+ */
20
+ protected mouseUpHandler(): void;
21
+ /**
22
+ * Global mouseup event handler that only handles left-button releases.
23
+ * @param e MouseEvent object
24
+ */
25
+ private globalPointerUpHandler;
26
+ /**
27
+ * Corrects lines that are close to horizontal or vertical so they become perfectly horizontal or vertical.
28
+ * @param points The line points
29
+ * @returns The corrected points
30
+ */
31
+ private correctLineIfStraight;
32
+ /**
33
+ * Determines whether the current line is too small.
34
+ * @returns True if the line point count is less than 5, otherwise false
35
+ */
36
+ private isTooSmall;
37
+ /**
38
+ * @description Update annotation styles
39
+ * @param annotationStore
40
+ * @param styles
41
+ */
42
+ protected changeStyle(annotationStore: IAnnotationStore, styles: IAnnotationStyle): void;
43
+ }