@labelbee/lb-annotation 1.14.0-alpha.3 → 1.14.0-alpha.5

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 (188) hide show
  1. package/dist/_virtual/MathUtilsWorker.js +1 -8
  2. package/dist/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +2 -35
  3. package/dist/_virtual/filterBoxWorker.js +1 -8
  4. package/dist/_virtual/highlightWorker.js +1 -8
  5. package/dist/assets/attributeIcon/icon_canvasEdit0.svg.js +1 -5
  6. package/dist/assets/attributeIcon/icon_canvasEdit1.svg.js +1 -5
  7. package/dist/assets/attributeIcon/icon_canvasEdit2.svg.js +1 -5
  8. package/dist/assets/attributeIcon/icon_canvasEdit3.svg.js +1 -5
  9. package/dist/assets/attributeIcon/icon_canvasEdit4.svg.js +1 -5
  10. package/dist/assets/attributeIcon/icon_canvasEdit5.svg.js +1 -5
  11. package/dist/assets/attributeIcon/icon_canvasEdit6.svg.js +1 -5
  12. package/dist/assets/attributeIcon/icon_canvasEdit7.svg.js +1 -5
  13. package/dist/assets/attributeIcon/icon_canvasEdit8.svg.js +1 -5
  14. package/dist/assets/attributeIcon/icon_canvasEdit_miss.svg.js +1 -5
  15. package/dist/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -5
  16. package/dist/assets/attributeIcon/icon_cuboidLeft.svg.js +7 -5
  17. package/dist/assets/attributeIcon/icon_cuboidMore.svg.js +5 -5
  18. package/dist/assets/attributeIcon/icon_cuboidRight.svg.js +5 -5
  19. package/dist/assets/attributeIcon/icon_cuboidTop.svg.js +12 -5
  20. package/dist/assets/attributeIcon/icon_editFEN.svg.js +1 -5
  21. package/dist/assets/attributeIcon/icon_editHUANG.svg.js +1 -5
  22. package/dist/assets/attributeIcon/icon_editLAN.svg.js +1 -5
  23. package/dist/assets/attributeIcon/icon_editLV.svg.js +1 -5
  24. package/dist/assets/attributeIcon/icon_editQING.svg.js +1 -5
  25. package/dist/constant/annotation.js +1 -127
  26. package/dist/constant/annotationTask.js +1 -30
  27. package/dist/constant/defaultConfig.js +1 -266
  28. package/dist/constant/keyCode.js +1 -38
  29. package/dist/constant/style.js +1 -98
  30. package/dist/constant/tool.js +1 -236
  31. package/dist/core/index.js +1 -150
  32. package/dist/core/pointCloud/OrbitControls.js +1 -665
  33. package/dist/core/pointCloud/PCDLoader.js +2 -260
  34. package/dist/core/pointCloud/annotation.js +1 -215
  35. package/dist/core/pointCloud/cache.js +1 -53
  36. package/dist/core/pointCloud/index.js +5 -991
  37. package/dist/core/pointCloud/matrix.js +1 -138
  38. package/dist/core/scheduler.js +1 -233
  39. package/dist/core/toolOperation/LineToolOperation.js +1 -1434
  40. package/dist/core/toolOperation/ScribbleTool.js +1 -292
  41. package/dist/core/toolOperation/TextToolOperation.js +1 -131
  42. package/dist/core/toolOperation/ViewOperation.js +1 -556
  43. package/dist/core/toolOperation/basicToolOperation.js +1 -881
  44. package/dist/core/toolOperation/checkOperation.js +1 -208
  45. package/dist/core/toolOperation/cuboidOperation.js +1 -754
  46. package/dist/core/toolOperation/cuboidToggleButtonClass.js +7 -152
  47. package/dist/core/toolOperation/eventListener.js +1 -37
  48. package/dist/core/toolOperation/measureOperation.js +1 -41
  49. package/dist/core/toolOperation/pointCloud2dOperation.js +1 -365
  50. package/dist/core/toolOperation/pointOperation.js +1 -696
  51. package/dist/core/toolOperation/polygonOperation.js +1 -1251
  52. package/dist/core/toolOperation/rectOperation.js +1 -1233
  53. package/dist/core/toolOperation/segmentByRect.js +1 -174
  54. package/dist/core/toolOperation/tagOperation.js +3 -201
  55. package/dist/core/toolOperation/textAttributeClass.js +16 -182
  56. package/dist/index.js +1 -185
  57. package/dist/locales/constants.js +1 -24
  58. package/dist/locales/en_US/message.js +1 -25
  59. package/dist/locales/index.js +1 -19
  60. package/dist/locales/zh_CN/message.js +1 -25
  61. package/dist/newCore/CanvasScheduler.js +1 -35
  62. package/dist/utils/ActionsHistory.js +1 -84
  63. package/dist/utils/ImgUtils.js +1 -23
  64. package/dist/utils/MathUtils.js +2 -385
  65. package/dist/utils/VectorUtils.js +1 -25
  66. package/dist/utils/tool/AttributeUtils.js +1 -218
  67. package/dist/utils/tool/AxisUtils.js +1 -340
  68. package/dist/utils/tool/CanvasUtils.js +1 -62
  69. package/dist/utils/tool/CommonToolUtils.js +1 -174
  70. package/dist/utils/tool/CuboidUtils.js +1 -704
  71. package/dist/utils/tool/DblClickEventListener.js +1 -102
  72. package/dist/utils/tool/DrawUtils.js +3 -492
  73. package/dist/utils/tool/EnhanceCommonToolUtils.js +1 -53
  74. package/dist/utils/tool/ImgPosUtils.js +1 -58
  75. package/dist/utils/tool/LineToolUtils.js +1 -261
  76. package/dist/utils/tool/MarkerUtils.js +1 -56
  77. package/dist/utils/tool/PolygonUtils.js +1 -460
  78. package/dist/utils/tool/RectUtils.js +1 -155
  79. package/dist/utils/tool/RenderDomClass.js +7 -57
  80. package/dist/utils/tool/RenderDomUtils.js +4 -21
  81. package/dist/utils/tool/StyleUtils.js +1 -31
  82. package/dist/utils/tool/TagUtils.js +1 -129
  83. package/dist/utils/tool/UnitUtils.js +1 -12
  84. package/dist/utils/tool/ZoomUtils.js +1 -72
  85. package/dist/utils/tool/polygonTool.js +1 -133
  86. package/dist/utils/uuid.js +1 -26
  87. package/es/_virtual/MathUtilsWorker.js +1 -6
  88. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +2 -31
  89. package/es/_virtual/filterBoxWorker.js +1 -6
  90. package/es/_virtual/highlightWorker.js +1 -6
  91. package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +1 -3
  92. package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +1 -3
  93. package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +1 -3
  94. package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +1 -3
  95. package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +1 -3
  96. package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +1 -3
  97. package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +1 -3
  98. package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +1 -3
  99. package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +1 -3
  100. package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +1 -3
  101. package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -3
  102. package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +7 -3
  103. package/es/assets/attributeIcon/icon_cuboidMore.svg.js +5 -3
  104. package/es/assets/attributeIcon/icon_cuboidRight.svg.js +5 -3
  105. package/es/assets/attributeIcon/icon_cuboidTop.svg.js +12 -3
  106. package/es/assets/attributeIcon/icon_editFEN.svg.js +1 -3
  107. package/es/assets/attributeIcon/icon_editHUANG.svg.js +1 -3
  108. package/es/assets/attributeIcon/icon_editLAN.svg.js +1 -3
  109. package/es/assets/attributeIcon/icon_editLV.svg.js +1 -3
  110. package/es/assets/attributeIcon/icon_editQING.svg.js +1 -3
  111. package/es/constant/annotation.js +1 -113
  112. package/es/constant/annotationTask.js +1 -25
  113. package/es/constant/defaultConfig.js +1 -260
  114. package/es/constant/keyCode.js +1 -36
  115. package/es/constant/style.js +1 -74
  116. package/es/constant/tool.js +1 -220
  117. package/es/core/index.js +1 -148
  118. package/es/core/pointCloud/OrbitControls.js +1 -661
  119. package/es/core/pointCloud/PCDLoader.js +2 -256
  120. package/es/core/pointCloud/annotation.js +1 -211
  121. package/es/core/pointCloud/cache.js +1 -49
  122. package/es/core/pointCloud/index.js +5 -962
  123. package/es/core/pointCloud/matrix.js +1 -109
  124. package/es/core/scheduler.js +1 -228
  125. package/es/core/toolOperation/LineToolOperation.js +1 -1421
  126. package/es/core/toolOperation/ScribbleTool.js +1 -290
  127. package/es/core/toolOperation/TextToolOperation.js +1 -129
  128. package/es/core/toolOperation/ViewOperation.js +1 -549
  129. package/es/core/toolOperation/basicToolOperation.js +1 -877
  130. package/es/core/toolOperation/checkOperation.js +1 -206
  131. package/es/core/toolOperation/cuboidOperation.js +1 -752
  132. package/es/core/toolOperation/cuboidToggleButtonClass.js +7 -150
  133. package/es/core/toolOperation/eventListener.js +1 -35
  134. package/es/core/toolOperation/measureOperation.js +1 -39
  135. package/es/core/toolOperation/pointCloud2dOperation.js +1 -359
  136. package/es/core/toolOperation/pointOperation.js +1 -690
  137. package/es/core/toolOperation/polygonOperation.js +1 -1245
  138. package/es/core/toolOperation/rectOperation.js +1 -1228
  139. package/es/core/toolOperation/segmentByRect.js +1 -172
  140. package/es/core/toolOperation/tagOperation.js +3 -199
  141. package/es/core/toolOperation/textAttributeClass.js +16 -180
  142. package/es/index.js +1 -46
  143. package/es/locales/constants.js +1 -22
  144. package/es/locales/en_US/message.js +1 -23
  145. package/es/locales/index.js +1 -17
  146. package/es/locales/zh_CN/message.js +1 -23
  147. package/es/newCore/CanvasScheduler.js +1 -31
  148. package/es/utils/ActionsHistory.js +1 -78
  149. package/es/utils/ImgUtils.js +1 -21
  150. package/es/utils/MathUtils.js +2 -380
  151. package/es/utils/VectorUtils.js +1 -23
  152. package/es/utils/tool/AttributeUtils.js +1 -212
  153. package/es/utils/tool/AxisUtils.js +1 -335
  154. package/es/utils/tool/CanvasUtils.js +1 -60
  155. package/es/utils/tool/CommonToolUtils.js +1 -172
  156. package/es/utils/tool/CuboidUtils.js +1 -680
  157. package/es/utils/tool/DblClickEventListener.js +1 -100
  158. package/es/utils/tool/DrawUtils.js +3 -490
  159. package/es/utils/tool/EnhanceCommonToolUtils.js +1 -48
  160. package/es/utils/tool/ImgPosUtils.js +1 -56
  161. package/es/utils/tool/LineToolUtils.js +1 -255
  162. package/es/utils/tool/MarkerUtils.js +1 -54
  163. package/es/utils/tool/PolygonUtils.js +1 -458
  164. package/es/utils/tool/RectUtils.js +1 -153
  165. package/es/utils/tool/RenderDomClass.js +7 -55
  166. package/es/utils/tool/RenderDomUtils.js +4 -19
  167. package/es/utils/tool/StyleUtils.js +1 -29
  168. package/es/utils/tool/TagUtils.js +1 -127
  169. package/es/utils/tool/UnitUtils.js +1 -10
  170. package/es/utils/tool/ZoomUtils.js +1 -70
  171. package/es/utils/tool/polygonTool.js +1 -126
  172. package/es/utils/uuid.js +1 -24
  173. package/package.json +3 -4
  174. package/LICENSE +0 -203
  175. package/dist/core/pointCloud/segmentation.js +0 -144
  176. package/dist/core/pointCloud/selector/Sse3dLassoSelector.js +0 -26
  177. package/dist/core/pointCloud/selector/Sse3dSelector.js +0 -16
  178. package/dist/types/core/pointCloud/segmentation.d.ts +0 -0
  179. package/dist/types/core/pointCloud/selector/Sse3dLassoSelector.d.ts +0 -0
  180. package/dist/types/core/pointCloud/selector/Sse3dSelector.d.ts +0 -0
  181. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +0 -12
  182. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +0 -7
  183. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +0 -11
  184. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +0 -18
  185. package/es/core/pointCloud/segmentation.js +0 -120
  186. package/es/core/pointCloud/selector/Sse3dLassoSelector.js +0 -24
  187. package/es/core/pointCloud/selector/Sse3dSelector.js +0 -14
  188. package/es/core/toolOperation/scribbleTool2.js +0 -249
@@ -1,696 +1 @@
1
- 'use strict';
2
-
3
- var tool = require('../../constant/tool.js');
4
- var RectUtils = require('../../utils/tool/RectUtils.js');
5
- var PolygonUtils = require('../../utils/tool/PolygonUtils.js');
6
- var MarkerUtils = require('../../utils/tool/MarkerUtils.js');
7
- var MathUtils = require('../../utils/MathUtils.js');
8
- var _ = require('lodash');
9
- var annotation = require('../../constant/annotation.js');
10
- var keyCode = require('../../constant/keyCode.js');
11
- var index = require('../../locales/index.js');
12
- var constants = require('../../locales/constants.js');
13
- var AttributeUtils = require('../../utils/tool/AttributeUtils.js');
14
- var AxisUtils = require('../../utils/tool/AxisUtils.js');
15
- var CommonToolUtils = require('../../utils/tool/CommonToolUtils.js');
16
- var DrawUtils = require('../../utils/tool/DrawUtils.js');
17
- var StyleUtils = require('../../utils/tool/StyleUtils.js');
18
- var uuid = require('../../utils/uuid.js');
19
- var basicToolOperation = require('./basicToolOperation.js');
20
- var textAttributeClass = require('./textAttributeClass.js');
21
-
22
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
23
-
24
- var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
25
-
26
- var __defProp = Object.defineProperty;
27
- var __defProps = Object.defineProperties;
28
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
29
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
30
- var __hasOwnProp = Object.prototype.hasOwnProperty;
31
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
32
- var __pow = Math.pow;
33
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
34
- var __spreadValues = (a, b) => {
35
- for (var prop in b || (b = {}))
36
- if (__hasOwnProp.call(b, prop))
37
- __defNormalProp(a, prop, b[prop]);
38
- if (__getOwnPropSymbols)
39
- for (var prop of __getOwnPropSymbols(b)) {
40
- if (__propIsEnum.call(b, prop))
41
- __defNormalProp(a, prop, b[prop]);
42
- }
43
- return a;
44
- };
45
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
46
- const TEXTAREA_WIDTH = 200;
47
- class PointOperation extends basicToolOperation.BasicToolOperation {
48
- constructor(props) {
49
- super(props);
50
- this.setMarkerIndex = (markerIndex) => {
51
- this.markerIndex = markerIndex;
52
- };
53
- this.setMarkerIndexAndSelect = (markerIndex) => {
54
- if (!this.config.markerList) {
55
- return;
56
- }
57
- this.markerIndex = markerIndex;
58
- const markerValue = this.config.markerList[markerIndex].value;
59
- const currentPoint = this.currentPageResult.find((point) => point.label === markerValue);
60
- if (currentPoint) {
61
- this.setSelectedID(currentPoint.id);
62
- if (this.config.attributeConfigurable === true) {
63
- this.setDefaultAttribute(currentPoint.attribute);
64
- }
65
- }
66
- this.emit("markIndexChange");
67
- };
68
- this.textChange = (v) => {
69
- if (this.config.textConfigurable !== true || !this.selectedID) {
70
- return;
71
- }
72
- this.setPointList(AttributeUtils["default"].textChange(v, this.selectedID, this.pointList));
73
- this.emit("selectedChange");
74
- this.render();
75
- };
76
- this.isMinDistance = (coord) => {
77
- const transformCoord = AxisUtils["default"].changePointByZoom(coord, this.zoom);
78
- return this.pointList.some((point) => {
79
- const transformPoint = AxisUtils["default"].changePointByZoom(point, this.zoom);
80
- return MathUtils["default"].getLineLength(transformPoint, transformCoord) < 0.2;
81
- });
82
- };
83
- var _a, _b;
84
- this.config = CommonToolUtils.jsonParser(props.config);
85
- this.pointList = [];
86
- this.markerIndex = 0;
87
- this.setStyle(props.style);
88
- this.createPoint = this.createPoint.bind(this);
89
- this.getCurrentSelectedData = this.getCurrentSelectedData.bind(this);
90
- this.updateSelectedTextAttribute = this.updateSelectedTextAttribute.bind(this);
91
- this.setSelectedID = this.setSelectedID.bind(this);
92
- this.forbidAddNew = (_a = props.forbidAddNew) != null ? _a : false;
93
- this.forbidDelete = (_b = props.forbidDelete) != null ? _b : false;
94
- }
95
- get dataList() {
96
- return this.pointList;
97
- }
98
- get drawOutsideTarget() {
99
- var _a;
100
- return (_a = this.config.drawOutsideTarget) != null ? _a : this.config.drawPointOut;
101
- }
102
- setNextMarker(pointList = this.pointList) {
103
- if (this.hasMarkerConfig) {
104
- const nextMarkerInfo = CommonToolUtils.getNextMarker(this.getCurrentPageResult(pointList), this.config.markerList);
105
- if (nextMarkerInfo) {
106
- this.setMarkerIndexAndSelect(nextMarkerInfo.index);
107
- }
108
- }
109
- }
110
- setResult(pointList) {
111
- this.clearActiveStatus();
112
- this.setPointList(pointList);
113
- this.setNextMarker(pointList);
114
- this.recoverOperationMode();
115
- this.render();
116
- }
117
- setPointList(pointList, isUpload = false) {
118
- const oldLen = this.pointList.length;
119
- this.pointList = pointList;
120
- if (oldLen !== pointList.length) {
121
- this.emit("updatePageNumber");
122
- }
123
- if (isUpload) {
124
- this.emit("updateResult");
125
- }
126
- }
127
- setConfig(config, isClear = false) {
128
- this.config = CommonToolUtils.jsonParser(config);
129
- if (isClear === true) {
130
- this.clearResult();
131
- }
132
- }
133
- clearResult() {
134
- this.setPointList([]);
135
- this.setSelectedID(void 0);
136
- this.history.pushHistory([]);
137
- this.hoverID = "";
138
- this.render();
139
- }
140
- setDefaultAttribute(defaultAttribute = "") {
141
- const oldDefault = this.defaultAttribute;
142
- this.defaultAttribute = defaultAttribute;
143
- if (oldDefault !== defaultAttribute) {
144
- this.changeStyle(defaultAttribute);
145
- this.emit("changeAttributeSidebar");
146
- const {selectedID} = this;
147
- if (selectedID) {
148
- this.pointList.forEach((point) => {
149
- if (point.id === selectedID) {
150
- point.attribute = defaultAttribute;
151
- }
152
- });
153
- this.history.pushHistory(this.pointList);
154
- this.render();
155
- }
156
- if (this._textAttributInstance) {
157
- if (this.attributeLockList.length > 0 && !this.attributeLockList.includes(defaultAttribute)) {
158
- this._textAttributInstance.clearTextAttribute();
159
- return;
160
- }
161
- this._textAttributInstance.updateIcon(this.getTextIconSvg(defaultAttribute));
162
- }
163
- }
164
- }
165
- get selectedText() {
166
- var _a;
167
- return (_a = this.pointList.find((item) => item.id === this.selectedID)) == null ? void 0 : _a.textAttribute;
168
- }
169
- setStyle(toolStyle) {
170
- var _a;
171
- super.setStyle(toolStyle);
172
- if (this._textAttributInstance && this.config.attributeConfigurable === false) {
173
- (_a = this._textAttributInstance) == null ? void 0 : _a.updateIcon(this.getTextIconSvg());
174
- }
175
- }
176
- setSelectedID(newID) {
177
- var _a, _b;
178
- const oldID = this.selectedID;
179
- if (newID !== oldID && oldID) {
180
- (_a = this._textAttributInstance) == null ? void 0 : _a.changeSelected();
181
- }
182
- if (!newID) {
183
- (_b = this._textAttributInstance) == null ? void 0 : _b.clearTextAttribute();
184
- }
185
- this.selectedID = newID;
186
- this.render();
187
- this.emit("selectedChange");
188
- }
189
- getTextIconSvg(attribute = "") {
190
- return AttributeUtils["default"].getTextIconSvg(attribute, this.config.attributeList, this.config.attributeConfigurable, this.baseIcon);
191
- }
192
- clearActiveStatus() {
193
- this.hoverID = void 0;
194
- this.dragStatus = annotation.EDragStatus.Wait;
195
- this.setSelectedID(void 0);
196
- }
197
- setBasicResult(basicResult) {
198
- super.setBasicResult(basicResult);
199
- this.setNextMarker();
200
- this.clearActiveStatus();
201
- }
202
- onDragMoveAll(offset) {
203
- var _a, _b;
204
- if (!((_b = (_a = this.dragInfo) == null ? void 0 : _a.originPointList) == null ? void 0 : _b.length)) {
205
- return;
206
- }
207
- this.setPointList(this.dragInfo.originPointList.map((point) => {
208
- const newRect = __spreadProps(__spreadValues({}, point), {
209
- x: point.x + offset.x / this.zoom,
210
- y: point.y + offset.y / this.zoom
211
- });
212
- return newRect;
213
- }));
214
- this.render();
215
- }
216
- onMouseDown(e) {
217
- if (super.onMouseDown(e) || this.forbidMouseOperation) {
218
- return;
219
- }
220
- if (e.button === 0 && !this.hoverID) {
221
- this.recoverOperationMode();
222
- this.createPoint(e);
223
- this.render();
224
- return;
225
- }
226
- if ((this.hoverID === this.selectedID || this.isMultiMoveMode && this.hoverID) && e.button === 0) {
227
- this.dragStatus = annotation.EDragStatus.Start;
228
- this.dragInfo = {
229
- dragStartCoord: this.getCoordinateUnderZoom(e),
230
- originPointList: ___default["default"].cloneDeep(this.pointList)
231
- };
232
- return;
233
- }
234
- this.render();
235
- return true;
236
- }
237
- onMouseMove(e) {
238
- if (super.onMouseMove(e) || this.forbidMouseOperation || !this.imgInfo) {
239
- return;
240
- }
241
- this.hoverID = this.getHoverId();
242
- if (this.dragStatus === annotation.EDragStatus.Start || this.dragStatus === annotation.EDragStatus.Move) {
243
- this.onDragMove(e);
244
- }
245
- if (this.hoverID) {
246
- this.render();
247
- }
248
- return void 0;
249
- }
250
- onMouseUp(e) {
251
- var _a;
252
- if (super.onMouseUp(e) || this.forbidMouseOperation || !this.imgInfo) {
253
- return true;
254
- }
255
- if (e.button === 2) {
256
- this.rightMouseUp();
257
- }
258
- if (this.dragStatus === annotation.EDragStatus.Move) {
259
- this.history.pushHistory(this.pointList);
260
- this.emit("updatePointByDrag", this.pointList.find((v) => (v == null ? void 0 : v.id) === this.selectedID), (_a = this.dragInfo) == null ? void 0 : _a.originPointList);
261
- this.dragInfo = void 0;
262
- }
263
- this.dragStatus = annotation.EDragStatus.Wait;
264
- this.render();
265
- }
266
- onDragMove(e) {
267
- var _a, _b;
268
- if (!this.imgInfo)
269
- return;
270
- this.dragStatus = annotation.EDragStatus.Move;
271
- const coordinateZoom = this.getCoordinateUnderZoom(e);
272
- if (this.isMultiMoveMode && this.dragInfo) {
273
- const offset = {
274
- x: coordinateZoom.x - this.dragInfo.dragStartCoord.x,
275
- y: coordinateZoom.y - this.dragInfo.dragStartCoord.y
276
- };
277
- this.onDragMoveAll(offset);
278
- return;
279
- }
280
- const zoomCoordinate = AxisUtils["default"].changeDrawOutsideTarget(coordinateZoom, {x: 0, y: 0}, this.imgInfo, this.drawOutsideTarget, this.basicResult, this.zoom);
281
- const coordinate = this.drawOutsideTarget ? AxisUtils["default"].getOriginCoordinateWithOffsetCoordinate(this.coord, this.zoom, this.currentPos) : AxisUtils["default"].changePointByZoom(zoomCoordinate, 1 / this.zoom);
282
- if (this.drawOutsideTarget === false) {
283
- if (this.dependToolName === tool.EToolName.Polygon && ((_b = (_a = this.basicResult) == null ? void 0 : _a.pointList) == null ? void 0 : _b.length) > 0 && !PolygonUtils.isInPolygon(coordinate, this.basicResult.pointList)) {
284
- return;
285
- }
286
- }
287
- this.pointList.forEach((point) => {
288
- if (point.id === this.selectedID) {
289
- point.x = coordinate.x;
290
- point.y = coordinate.y;
291
- }
292
- });
293
- this.render();
294
- }
295
- onKeyDown(e) {
296
- if (!CommonToolUtils.hotkeyFilter(e)) {
297
- return;
298
- }
299
- if (super.onKeyDown(e) === false) {
300
- return;
301
- }
302
- const {keyCode: keyCode$1} = e;
303
- switch (keyCode$1) {
304
- case keyCode.Delete:
305
- this.deletePoint();
306
- break;
307
- case keyCode.Tab: {
308
- this.onTabKeyDown(e);
309
- break;
310
- }
311
- case keyCode.Z:
312
- this.setIsHidden(!this.isHidden);
313
- this.render();
314
- break;
315
- default: {
316
- if (this.config.attributeConfigurable) {
317
- const keyCode2Attribute = AttributeUtils["default"].getAttributeByKeycode(keyCode$1, this.config.attributeList);
318
- if (keyCode2Attribute !== void 0) {
319
- this.setDefaultAttribute(keyCode2Attribute);
320
- }
321
- }
322
- break;
323
- }
324
- }
325
- }
326
- createPoint(e) {
327
- var _a, _b, _c, _d;
328
- if (!this.imgInfo)
329
- return;
330
- if (this.forbidAddNew)
331
- return;
332
- const {upperLimit} = this.config;
333
- if (upperLimit && this.currentPageResult.length >= upperLimit) {
334
- this.emit("messageInfo", `${index.getMessagesByLocale(constants.EMessage.LowerLimitPoint, this.lang)}`);
335
- return;
336
- }
337
- const basicSourceID = CommonToolUtils.getSourceID(this.basicResult);
338
- const coordinateZoom = this.getCoordinateUnderZoom(e);
339
- let coordinate = AxisUtils["default"].getOriginCoordinateWithOffsetCoordinate(this.coord, this.zoom, this.currentPos);
340
- if (this.config.edgeAdsorption && this.referenceData) {
341
- const isAllowEdgeAdsoption = [tool.EToolName.Polygon, tool.EToolName.Line].includes((_a = this.referenceData) == null ? void 0 : _a.toolName);
342
- if (isAllowEdgeAdsoption) {
343
- const isClose = ((_b = this.referenceData) == null ? void 0 : _b.toolName) === tool.EToolName.Polygon;
344
- const {dropFoot, hasClosed} = PolygonUtils.getClosestPoint(coordinate, this.referenceData.result, (_d = (_c = this.referenceData.config) == null ? void 0 : _c.lineType) != null ? _d : tool.ELineTypes.Line, tool.edgeAdsorptionScope / this.zoom, {isClose});
345
- if (dropFoot) {
346
- coordinate = dropFoot;
347
- }
348
- if (hasClosed) {
349
- this.emit("messageSuccess", `${index.getMessagesByLocale(constants.EMessage.SuccessfulEdgeAdsorption, this.lang)}`);
350
- }
351
- }
352
- }
353
- if (this.drawOutsideTarget === false) {
354
- if (this.dependToolName && this.basicCanvas) {
355
- let isOutSide = false;
356
- switch (this.dependToolName) {
357
- case tool.EToolName.Rect: {
358
- isOutSide = !RectUtils.isInRect(coordinate, this.basicResult);
359
- break;
360
- }
361
- case tool.EToolName.Polygon: {
362
- isOutSide = !PolygonUtils.isInPolygon(coordinate, this.basicResult.pointList);
363
- break;
364
- }
365
- }
366
- if (isOutSide) {
367
- return;
368
- }
369
- }
370
- if (coordinateZoom.x < 0 || coordinateZoom.y < 0 || coordinateZoom.x > this.imgInfo.width || coordinateZoom.y > this.imgInfo.height) {
371
- return;
372
- }
373
- }
374
- if (this.isMinDistance(coordinate)) {
375
- return;
376
- }
377
- let newDrawingPoint = __spreadProps(__spreadValues({}, coordinate), {
378
- attribute: this.defaultAttribute,
379
- valid: !e.ctrlKey,
380
- id: uuid(8, 62),
381
- sourceID: basicSourceID,
382
- textAttribute: "",
383
- order: CommonToolUtils.getMaxOrder(this.pointList.filter((v) => CommonToolUtils.isSameSourceID(v.sourceID, basicSourceID))) + 1
384
- });
385
- if (this.config.textConfigurable) {
386
- let textAttribute = "";
387
- textAttribute = AttributeUtils["default"].getTextAttribute(this.pointList.filter((point) => CommonToolUtils.isSameSourceID(point.sourceID, basicSourceID)), this.config.textCheckType);
388
- newDrawingPoint = __spreadProps(__spreadValues({}, newDrawingPoint), {
389
- textAttribute
390
- });
391
- }
392
- if (this.hasMarkerConfig) {
393
- const nextMarkInfo = CommonToolUtils.getNextMarker(this.currentPageResult, this.config.markerList, this.markerIndex);
394
- if (nextMarkInfo) {
395
- newDrawingPoint = __spreadProps(__spreadValues({}, newDrawingPoint), {
396
- label: nextMarkInfo.label
397
- });
398
- this.markerIndex = nextMarkInfo.index;
399
- this.emit("markIndexChange");
400
- } else {
401
- this.emit("messageInfo", index.getMessagesByLocale(constants.EMessage.MarkerFinish, this.lang));
402
- return;
403
- }
404
- }
405
- this.hoverID = newDrawingPoint.id;
406
- const newPointList = [...this.pointList, newDrawingPoint];
407
- this.setPointList(newPointList);
408
- this.emit("pointCreated", newDrawingPoint, this.zoom);
409
- this.history.pushHistory(newPointList);
410
- this.setSelectedID(newDrawingPoint.id);
411
- }
412
- isInPoint(pos, point, zoom = this.zoom) {
413
- return (this.style.width + 2) / zoom >= Math.sqrt(__pow(pos.x - point.x, 2) + __pow(pos.y - point.y, 2));
414
- }
415
- getHoverId() {
416
- var _a;
417
- const pos = AxisUtils["default"].getOriginCoordinateWithOffsetCoordinate(this.coord, this.zoom, this.currentPos);
418
- const selectPoint = (_a = this.pointList) == null ? void 0 : _a.find((print) => this.isInPoint(pos, print));
419
- return selectPoint == null ? void 0 : selectPoint.id;
420
- }
421
- get selectedPoint() {
422
- return this.pointList.find((v) => v.id === this.selectedID);
423
- }
424
- rightMouseUp() {
425
- this.recoverOperationMode();
426
- if (this.selectedID === this.hoverID) {
427
- if (this.forbidDelete)
428
- return;
429
- const pointList = this.pointList.filter((point) => point.id !== this.selectedID);
430
- this.setPointList(pointList);
431
- this.history.pushHistory(pointList);
432
- this.emit("pointDeleted", this.selectedID);
433
- this.setSelectedID("");
434
- this.hoverID = "";
435
- return;
436
- }
437
- const hoverPoint = this.pointList.find((point) => point.id === this.hoverID);
438
- this.setSelectedID(this.hoverID);
439
- this.emit("pointSelected", this.hoverID);
440
- this.setDefaultAttribute(hoverPoint == null ? void 0 : hoverPoint.attribute);
441
- if ((hoverPoint == null ? void 0 : hoverPoint.label) && this.hasMarkerConfig) {
442
- const markerIndex = CommonToolUtils.getCurrentMarkerIndex(hoverPoint.label, this.config.markerList);
443
- if (markerIndex >= 0) {
444
- this.setMarkerIndex(markerIndex);
445
- this.emit("markIndexChange");
446
- }
447
- }
448
- }
449
- onTabKeyDown(e) {
450
- e.preventDefault();
451
- if (this.dragStatus === annotation.EDragStatus.Move || this.dragStatus === annotation.EDragStatus.Start) {
452
- return;
453
- }
454
- let sort = annotation.ESortDirection.ascend;
455
- if (e.shiftKey) {
456
- sort = annotation.ESortDirection.descend;
457
- }
458
- const [showingResult, selectedResult] = CommonToolUtils.getRenderResultList(this.pointList, CommonToolUtils.getSourceID(this.basicResult), this.attributeLockList, this.selectedID);
459
- let pointList = [...showingResult];
460
- if (selectedResult) {
461
- pointList = [...pointList, selectedResult];
462
- }
463
- const nextSelectedRect = CommonToolUtils.getNextSelectedRectID(pointList, sort, this.selectedID);
464
- if (nextSelectedRect) {
465
- this.setSelectedID(nextSelectedRect.id);
466
- }
467
- }
468
- get currentPageResult() {
469
- const [showingPolygon] = CommonToolUtils.getRenderResultList(this.pointList, CommonToolUtils.getSourceID(this.basicResult), []);
470
- return showingPolygon;
471
- }
472
- getCurrentPageResult(pointList) {
473
- const [showingRect] = CommonToolUtils.getRenderResultList(pointList, CommonToolUtils.getSourceID(this.basicResult), []);
474
- return showingRect;
475
- }
476
- exportData() {
477
- const {pointList} = this;
478
- return [pointList, this.basicImgInfo];
479
- }
480
- deletePoint() {
481
- var _a;
482
- if (this.selectedID) {
483
- this.setPointList(this.pointList.filter((point) => point.id !== this.selectedID));
484
- this.history.pushHistory(this.pointList);
485
- (_a = this._textAttributInstance) == null ? void 0 : _a.clearTextAttribute();
486
- this.emit("selectedChange");
487
- this.emit("pointDeleted", this.selectedID);
488
- this.render();
489
- }
490
- }
491
- undoAndRedo(name) {
492
- var _a, _b;
493
- if (this.dragStatus === annotation.EDragStatus.Move || this.dragStatus === annotation.EDragStatus.Start) {
494
- return;
495
- }
496
- const rectList = (_b = (_a = this.history)[name]) == null ? void 0 : _b.call(_a);
497
- if (!(rectList == null ? void 0 : rectList.some((point) => point.id === this.selectedID))) {
498
- this.setSelectedID("");
499
- }
500
- if (rectList) {
501
- this.setPointList(rectList, true);
502
- this.render();
503
- }
504
- }
505
- undo() {
506
- this.undoAndRedo("undo");
507
- }
508
- redo() {
509
- this.undoAndRedo("redo");
510
- }
511
- getCurrentSelectedData() {
512
- var _a;
513
- if (!this.selectedID)
514
- return;
515
- const point = (_a = this.pointList) == null ? void 0 : _a.find((item) => item.id === this.selectedID);
516
- const toolColor = this.getColor(point == null ? void 0 : point.attribute);
517
- const color = (point == null ? void 0 : point.valid) ? toolColor == null ? void 0 : toolColor.valid.stroke : toolColor == null ? void 0 : toolColor.invalid.stroke;
518
- this.dragStatus = annotation.EDragStatus.Wait;
519
- return {
520
- width: TEXTAREA_WIDTH * this.zoom * 0.6,
521
- textAttribute: (point == null ? void 0 : point.textAttribute) || "",
522
- color
523
- };
524
- }
525
- updateSelectedTextAttribute(newTextAttribute) {
526
- if (this._textAttributInstance && newTextAttribute && this.selectedID) {
527
- let textAttribute = newTextAttribute;
528
- if (AttributeUtils["default"].textAttributeValidate(this.config.textCheckType, "", textAttribute) === false) {
529
- this.emit("messageError", AttributeUtils["default"].getErrorNotice(this.config.textCheckType, this.lang));
530
- textAttribute = "";
531
- }
532
- this.setPointList(AttributeUtils["default"].textChange(textAttribute, this.selectedID, this.pointList));
533
- this.emit("updateTextAttribute");
534
- this.render();
535
- }
536
- }
537
- renderTextAttribute() {
538
- var _a, _b;
539
- const point = (_a = this.pointList) == null ? void 0 : _a.find((item) => item.id === this.selectedID);
540
- if (!this.ctx || this.config.textConfigurable !== true || !point) {
541
- return;
542
- }
543
- const {x, y, attribute, valid} = point;
544
- const newWidth = TEXTAREA_WIDTH * this.zoom * 0.6;
545
- const coordinate = AxisUtils["default"].getOffsetCoordinate({x, y}, this.currentPos, this.zoom);
546
- const toolColor = this.getColor(attribute);
547
- const color = valid ? toolColor == null ? void 0 : toolColor.valid.stroke : toolColor == null ? void 0 : toolColor.invalid.stroke;
548
- const distance = 4;
549
- if (!this._textAttributInstance) {
550
- this._textAttributInstance = new textAttributeClass({
551
- width: newWidth,
552
- container: this.container,
553
- icon: this.getTextIconSvg(attribute),
554
- color,
555
- getCurrentSelectedData: this.getCurrentSelectedData,
556
- updateSelectedTextAttribute: this.updateSelectedTextAttribute
557
- });
558
- }
559
- if (this._textAttributInstance && !((_b = this._textAttributInstance) == null ? void 0 : _b.isExit)) {
560
- this._textAttributInstance.appendToContainer();
561
- }
562
- this._textAttributInstance.update(`${point.textAttribute}`, {
563
- left: coordinate.x,
564
- top: coordinate.y + distance,
565
- color,
566
- width: newWidth
567
- });
568
- }
569
- renderPoint(point, isSelected = false) {
570
- var _a, _b, _c;
571
- const {textAttribute = "", attribute} = point;
572
- const selected = isSelected || point.id === this.selectedID;
573
- const toolColor = this.getColor(attribute);
574
- const transformPoint = AxisUtils["default"].changePointByZoom(point, this.zoom, this.currentPos);
575
- const {width = 2, hiddenText = false} = this.style;
576
- const toolData = StyleUtils.getStrokeAndFill(toolColor, point.valid, {
577
- isSelected: selected || point.id === this.hoverID
578
- });
579
- DrawUtils.drawCircle(this.canvas, transformPoint, width, {
580
- startAngleDeg: 0,
581
- endAngleDeg: 360,
582
- thickness: 1,
583
- color: toolData.stroke,
584
- fill: toolData.fill
585
- });
586
- let showText = "";
587
- const isShowOrder = ((_a = this.config) == null ? void 0 : _a.isShowOrder) || ((_b = this.config) == null ? void 0 : _b.showOrder);
588
- if (isShowOrder && point.order && (point == null ? void 0 : point.order) > 0) {
589
- showText = `${point.order}`;
590
- }
591
- if (point.label && this.hasMarkerConfig) {
592
- const order = CommonToolUtils.getCurrentMarkerIndex(point.label, this.config.markerList) + 1;
593
- showText = `${order}_${MarkerUtils.getMarkerShowText(point.label, this.config.markerList)}`;
594
- }
595
- if (point.attribute && !this.config.hideAttribute) {
596
- showText = `${showText} ${AttributeUtils["default"].getAttributeShowText(point.attribute, (_c = this.config) == null ? void 0 : _c.attributeList)}`;
597
- }
598
- if (!hiddenText) {
599
- DrawUtils.drawText(this.canvas, {x: transformPoint.x + width / 2, y: transformPoint.y - width - 4}, showText, {
600
- textAlign: "center",
601
- color: toolData.stroke
602
- });
603
- }
604
- if (selected) {
605
- this.renderTextAttribute();
606
- } else if (!hiddenText) {
607
- DrawUtils.drawText(this.canvas, {x: transformPoint.x + width, y: transformPoint.y + width + 24}, textAttribute, __spreadValues({
608
- color: toolData.stroke
609
- }, annotation.DEFAULT_TEXT_OFFSET));
610
- }
611
- }
612
- renderMultiSelectedPoint() {
613
- if (!this.isMultiMoveMode) {
614
- return;
615
- }
616
- this.pointList.forEach((point) => {
617
- this.renderPoint(point, true);
618
- });
619
- }
620
- renderPointList() {
621
- switch (this.operationMode) {
622
- case tool.EOperationMode.MultiMove:
623
- this.renderMultiSelectedPoint();
624
- break;
625
- default: {
626
- const [showingPointList, selectedPoint] = CommonToolUtils.getRenderResultList(this.pointList, CommonToolUtils.getSourceID(this.basicResult), this.attributeLockList, this.selectedID);
627
- if (!this.isHidden) {
628
- showingPointList.forEach((point) => {
629
- this.renderPoint(point);
630
- });
631
- }
632
- if (selectedPoint) {
633
- this.renderPoint(selectedPoint);
634
- }
635
- }
636
- }
637
- }
638
- renderAuxiliaryLine() {
639
- var _a;
640
- if (!this.config.markerConfigurable || !((_a = this.config.markerList) == null ? void 0 : _a.length)) {
641
- return;
642
- }
643
- const [showingPointList, selectedPoint] = CommonToolUtils.getRenderResultList(this.pointList, CommonToolUtils.getSourceID(this.basicResult), this.attributeLockList, this.selectedID);
644
- const pointList = showingPointList;
645
- if (selectedPoint) {
646
- pointList.push(selectedPoint);
647
- }
648
- if (pointList.length < 2) {
649
- return;
650
- }
651
- const auxiliaryLines = MarkerUtils.getAuxiliaryLineByMarkerList(this.config.markerList, "value");
652
- const auxiliaryLinesCoord = MarkerUtils.getAuxiliaryLineCoord(auxiliaryLines, pointList);
653
- auxiliaryLinesCoord.forEach((item) => {
654
- const {start: startCoord, end: endCoord} = item;
655
- const pointListCoord = AxisUtils["default"].changePointListByZoom([startCoord, endCoord], this.zoom, this.currentPos);
656
- DrawUtils.drawLine(this.canvas, pointListCoord[0], pointListCoord[1], {
657
- color: "#C5C5C5"
658
- });
659
- });
660
- }
661
- renderTop() {
662
- var _a, _b, _c;
663
- const color = this.getLineColor(this.defaultAttribute);
664
- this.renderCursorLine(color);
665
- if (this.config.edgeAdsorption && this.referenceData) {
666
- let coordinate = AxisUtils["default"].getOriginCoordinateWithOffsetCoordinate(this.coord, this.zoom, this.currentPos);
667
- const isClose = ((_a = this.referenceData) == null ? void 0 : _a.toolName) === tool.EToolName.Polygon;
668
- const {dropFoot} = PolygonUtils.getClosestPoint(coordinate, this.referenceData.result, (_c = (_b = this.referenceData.config) == null ? void 0 : _b.lineType) != null ? _c : tool.ELineTypes.Line, tool.edgeAdsorptionScope / this.zoom, {
669
- isClose
670
- });
671
- if (dropFoot && coordinate !== dropFoot) {
672
- if (coordinate !== dropFoot) {
673
- coordinate = dropFoot;
674
- DrawUtils.drawCircle(this.canvas, AxisUtils["default"].changePointByZoom(coordinate, this.zoom, this.currentPos), 5, {
675
- color: "white",
676
- fill: "white"
677
- });
678
- DrawUtils.drawCircle(this.canvas, AxisUtils["default"].changePointByZoom(coordinate, this.zoom, this.currentPos), 3, {
679
- fill: color,
680
- color
681
- });
682
- }
683
- }
684
- }
685
- }
686
- render() {
687
- if (!this.ctx)
688
- return;
689
- super.render();
690
- this.renderAuxiliaryLine();
691
- this.renderPointList();
692
- this.renderTop();
693
- }
694
- }
695
-
696
- module.exports = PointOperation;
1
+ "use strict";var tool=require("../../constant/tool.js"),RectUtils=require("../../utils/tool/RectUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),MarkerUtils=require("../../utils/tool/MarkerUtils.js"),MathUtils=require("../../utils/MathUtils.js"),_=require("lodash"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js");function _interopDefaultLegacy(l){return l&&typeof l=="object"&&"default"in l?l:{default:l}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__pow=Math.pow,__defNormalProp=(l,t,e)=>t in l?__defProp(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e,__spreadValues=(l,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(l,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(l,e,t[e]);return l},__spreadProps=(l,t)=>__defProps(l,__getOwnPropDescs(t));const TEXTAREA_WIDTH=200;class PointOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.setMarkerIndex=s=>{this.markerIndex=s},this.setMarkerIndexAndSelect=s=>{if(!this.config.markerList)return;this.markerIndex=s;const r=this.config.markerList[s].value,n=this.currentPageResult.find(o=>o.label===r);n&&(this.setSelectedID(n.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(n.attribute)),this.emit("markIndexChange")},this.textChange=s=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(AttributeUtils.default.textChange(s,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=s=>{const r=AxisUtils.default.changePointByZoom(s,this.zoom);return this.pointList.some(n=>{const o=AxisUtils.default.changePointByZoom(n,this.zoom);return MathUtils.default.getLineLength(o,r)<.2})};var e,i;this.config=CommonToolUtils.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.setStyle(t.style),this.createPoint=this.createPoint.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.forbidAddNew=(e=t.forbidAddNew)!=null?e:!1,this.forbidDelete=(i=t.forbidDelete)!=null?i:!1}get dataList(){return this.pointList}get drawOutsideTarget(){var t;return(t=this.config.drawOutsideTarget)!=null?t:this.config.drawPointOut}setNextMarker(t=this.pointList){if(this.hasMarkerConfig){const e=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),this.recoverOperationMode(),this.render()}setPointList(t,e=!1){const i=this.pointList.length;this.pointList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}setConfig(t,e=!1){this.config=CommonToolUtils.jsonParser(t),e===!0&&this.clearResult()}clearResult(){this.setPointList([]),this.setSelectedID(void 0),this.history.pushHistory([]),this.hoverID="",this.render()}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.pointList.forEach(s=>{s.id===i&&(s.attribute=t)}),this.history.pushHistory(this.pointList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}get selectedText(){var t;return(t=this.pointList.find(e=>e.id===this.selectedID))==null?void 0:t.textAttribute}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setSelectedID(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originPointList)==null?void 0:i.length)||(this.setPointList(this.dragInfo.originPointList.map(s=>__spreadProps(__spreadValues({},s),{x:s.x+t.x/this.zoom,y:s.y+t.y/this.zoom}))),this.render())}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.recoverOperationMode(),this.createPoint(t),this.render();return}if((this.hoverID===this.selectedID||this.isMultiMoveMode&&this.hoverID)&&t.button===0){this.dragStatus=annotation.EDragStatus.Start,this.dragInfo={dragStartCoord:this.getCoordinateUnderZoom(t),originPointList:___default.default.cloneDeep(this.pointList)};return}return this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===annotation.EDragStatus.Start||this.dragStatus===annotation.EDragStatus.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){var e;if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;t.button===2&&this.rightMouseUp(),this.dragStatus===annotation.EDragStatus.Move&&(this.history.pushHistory(this.pointList),this.emit("updatePointByDrag",this.pointList.find(i=>(i==null?void 0:i.id)===this.selectedID),(e=this.dragInfo)==null?void 0:e.originPointList),this.dragInfo=void 0),this.dragStatus=annotation.EDragStatus.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=annotation.EDragStatus.Move;const s=this.getCoordinateUnderZoom(t);if(this.isMultiMoveMode&&this.dragInfo){const o={x:s.x-this.dragInfo.dragStartCoord.x,y:s.y-this.dragInfo.dragStartCoord.y};this.onDragMoveAll(o);return}const r=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),n=this.drawOutsideTarget?AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):AxisUtils.default.changePointByZoom(r,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===tool.EToolName.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!PolygonUtils.isInPolygon(n,this.basicResult.pointList)||(this.pointList.forEach(o=>{o.id===this.selectedID&&(o.x=n.x,o.y=n.y)}),this.render())}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case keyCode.Delete:this.deletePoint();break;case keyCode.Tab:{this.onTabKeyDown(t);break}case keyCode.Z:this.setIsHidden(!this.isHidden),this.render();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}createPoint(t){var e,i,s,r;if(!this.imgInfo||this.forbidAddNew)return;const{upperLimit:n}=this.config;if(n&&this.currentPageResult.length>=n){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.LowerLimitPoint,this.lang)}`);return}const o=CommonToolUtils.getSourceID(this.basicResult),u=this.getCoordinateUnderZoom(t);let d=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.config.edgeAdsorption&&this.referenceData&&[tool.EToolName.Polygon,tool.EToolName.Line].includes((e=this.referenceData)==null?void 0:e.toolName)){const f=((i=this.referenceData)==null?void 0:i.toolName)===tool.EToolName.Polygon,{dropFoot:g,hasClosed:v}=PolygonUtils.getClosestPoint(d,this.referenceData.result,(r=(s=this.referenceData.config)==null?void 0:s.lineType)!=null?r:tool.ELineTypes.Line,tool.edgeAdsorptionScope/this.zoom,{isClose:f});g&&(d=g),v&&this.emit("messageSuccess",`${index.getMessagesByLocale(constants.EMessage.SuccessfulEdgeAdsorption,this.lang)}`)}if(this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let h=!1;switch(this.dependToolName){case tool.EToolName.Rect:{h=!RectUtils.isInRect(d,this.basicResult);break}case tool.EToolName.Polygon:{h=!PolygonUtils.isInPolygon(d,this.basicResult.pointList);break}}if(h)return}if(u.x<0||u.y<0||u.x>this.imgInfo.width||u.y>this.imgInfo.height)return}if(this.isMinDistance(d))return;let a=__spreadProps(__spreadValues({},d),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:o,textAttribute:"",order:CommonToolUtils.getMaxOrder(this.pointList.filter(h=>CommonToolUtils.isSameSourceID(h.sourceID,o)))+1});if(this.config.textConfigurable){let h="";h=AttributeUtils.default.getTextAttribute(this.pointList.filter(f=>CommonToolUtils.isSameSourceID(f.sourceID,o)),this.config.textCheckType),a=__spreadProps(__spreadValues({},a),{textAttribute:h})}if(this.hasMarkerConfig){const h=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(h)a=__spreadProps(__spreadValues({},a),{label:h.label}),this.markerIndex=h.index,this.emit("markIndexChange");else{this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.MarkerFinish,this.lang));return}}this.hoverID=a.id;const c=[...this.pointList,a];this.setPointList(c),this.emit("pointCreated",a,this.zoom),this.history.pushHistory(c),this.setSelectedID(a.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(__pow(t.x-e.x,2)+__pow(t.y-e.y,2))}getHoverId(){var t;const e=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos),i=(t=this.pointList)==null?void 0:t.find(s=>this.isInPoint(e,s));return i==null?void 0:i.id}get selectedPoint(){return this.pointList.find(t=>t.id===this.selectedID)}rightMouseUp(){if(this.recoverOperationMode(),this.selectedID===this.hoverID){if(this.forbidDelete)return;const e=this.pointList.filter(i=>i.id!==this.selectedID);this.setPointList(e),this.history.pushHistory(e),this.emit("pointDeleted",this.selectedID),this.setSelectedID(""),this.hoverID="";return}const t=this.pointList.find(e=>e.id===this.hoverID);if(this.setSelectedID(this.hoverID),this.emit("pointSelected",this.hoverID),this.setDefaultAttribute(t==null?void 0:t.attribute),(t==null?void 0:t.label)&&this.hasMarkerConfig){const e=CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList);e>=0&&(this.setMarkerIndex(e),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===annotation.EDragStatus.Move||this.dragStatus===annotation.EDragStatus.Start)return;let e=annotation.ESortDirection.ascend;t.shiftKey&&(e=annotation.ESortDirection.descend);const[i,s]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let r=[...i];s&&(r=[...r,s]);const n=CommonToolUtils.getNextSelectedRectID(r,e,this.selectedID);n&&this.setSelectedID(n.id)}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.getSourceID(this.basicResult),[]);return e}exportData(){const{pointList:t}=this;return[t,this.basicImgInfo]}deletePoint(){var t;this.selectedID&&(this.setPointList(this.pointList.filter(e=>e.id!==this.selectedID)),this.history.pushHistory(this.pointList),(t=this._textAttributInstance)==null||t.clearTextAttribute(),this.emit("selectedChange"),this.emit("pointDeleted",this.selectedID),this.render())}undoAndRedo(t){var e,i;if(this.dragStatus===annotation.EDragStatus.Move||this.dragStatus===annotation.EDragStatus.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(r=>r.id===this.selectedID))||this.setSelectedID(""),s&&(this.setPointList(s,!0),this.render())}undo(){this.undoAndRedo("undo")}redo(){this.undoAndRedo("redo")}getCurrentSelectedData(){var t;if(!this.selectedID)return;const e=(t=this.pointList)==null?void 0:t.find(r=>r.id===this.selectedID),i=this.getColor(e==null?void 0:e.attribute),s=(e==null?void 0:e.valid)?i==null?void 0:i.valid.stroke:i==null?void 0:i.invalid.stroke;return this.dragStatus=annotation.EDragStatus.Wait,{width:TEXTAREA_WIDTH*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(AttributeUtils.default.textChange(e,this.selectedID,this.pointList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t,e;const i=(t=this.pointList)==null?void 0:t.find(f=>f.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:r,attribute:n,valid:o}=i,u=TEXTAREA_WIDTH*this.zoom*.6,d=AxisUtils.default.getOffsetCoordinate({x:s,y:r},this.currentPos,this.zoom),a=this.getColor(n),c=o?a==null?void 0:a.valid.stroke:a==null?void 0:a.invalid.stroke,h=4;this._textAttributInstance||(this._textAttributInstance=new textAttributeClass({width:u,container:this.container,icon:this.getTextIconSvg(n),color:c,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((e=this._textAttributInstance)==null?void 0:e.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${i.textAttribute}`,{left:d.x,top:d.y+h,color:c,width:u})}renderPoint(t,e=!1){var i,s,r;const{textAttribute:n="",attribute:o}=t,u=e||t.id===this.selectedID,d=this.getColor(o),a=AxisUtils.default.changePointByZoom(t,this.zoom,this.currentPos),{width:c=2,hiddenText:h=!1}=this.style,f=StyleUtils.getStrokeAndFill(d,t.valid,{isSelected:u||t.id===this.hoverID});DrawUtils.drawCircle(this.canvas,a,c,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:f.stroke,fill:f.fill});let g="";(((i=this.config)==null?void 0:i.isShowOrder)||((s=this.config)==null?void 0:s.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(g=`${t.order}`),t.label&&this.hasMarkerConfig&&(g=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&!this.config.hideAttribute&&(g=`${g} ${AttributeUtils.default.getAttributeShowText(t.attribute,(r=this.config)==null?void 0:r.attributeList)}`),h||DrawUtils.drawText(this.canvas,{x:a.x+c/2,y:a.y-c-4},g,{textAlign:"center",color:f.stroke}),u?this.renderTextAttribute():h||DrawUtils.drawText(this.canvas,{x:a.x+c,y:a.y+c+24},n,__spreadValues({color:f.stroke},annotation.DEFAULT_TEXT_OFFSET))}renderMultiSelectedPoint(){!this.isMultiMoveMode||this.pointList.forEach(t=>{this.renderPoint(t,!0)})}renderPointList(){switch(this.operationMode){case tool.EOperationMode.MultiMove:this.renderMultiSelectedPoint();break;default:{const[t,e]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&this.renderPoint(e)}}}renderAuxiliaryLine(){var t;if(!this.config.markerConfigurable||!((t=this.config.markerList)==null?void 0:t.length))return;const[e,i]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID),s=e;if(i&&s.push(i),s.length<2)return;const r=MarkerUtils.getAuxiliaryLineByMarkerList(this.config.markerList,"value");MarkerUtils.getAuxiliaryLineCoord(r,s).forEach(o=>{const{start:u,end:d}=o,a=AxisUtils.default.changePointListByZoom([u,d],this.zoom,this.currentPos);DrawUtils.drawLine(this.canvas,a[0],a[1],{color:"#C5C5C5"})})}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.referenceData){let r=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const n=((t=this.referenceData)==null?void 0:t.toolName)===tool.EToolName.Polygon,{dropFoot:o}=PolygonUtils.getClosestPoint(r,this.referenceData.result,(i=(e=this.referenceData.config)==null?void 0:e.lineType)!=null?i:tool.ELineTypes.Line,tool.edgeAdsorptionScope/this.zoom,{isClose:n});o&&r!==o&&r!==o&&(r=o,DrawUtils.drawCircle(this.canvas,AxisUtils.default.changePointByZoom(r,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),DrawUtils.drawCircle(this.canvas,AxisUtils.default.changePointByZoom(r,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderAuxiliaryLine(),this.renderPointList(),this.renderTop())}}module.exports=PointOperation;