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

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