@labelbee/lb-annotation 1.8.0 → 1.9.0-alpha.2

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 (96) hide show
  1. package/README.md +65 -0
  2. package/dist/index.js +20 -9
  3. package/dist/types/constant/tool.d.ts +3 -1
  4. package/dist/types/core/index.d.ts +24 -4
  5. package/dist/types/core/pointCloud/OrbitControls.d.ts +60 -0
  6. package/dist/types/core/pointCloud/PCDLoader.d.ts +11 -0
  7. package/dist/types/core/pointCloud/annotation.d.ts +47 -0
  8. package/dist/types/core/pointCloud/cache.d.ts +16 -0
  9. package/dist/types/core/pointCloud/index.d.ts +325 -0
  10. package/dist/types/core/scheduler.d.ts +71 -0
  11. package/dist/types/core/toolOperation/basicToolOperation.d.ts +20 -2
  12. package/dist/types/core/toolOperation/eventListener.d.ts +2 -2
  13. package/dist/types/core/toolOperation/pointCloud2dOperation.d.ts +80 -0
  14. package/dist/types/core/toolOperation/polygonOperation.d.ts +21 -7
  15. package/dist/types/core/toolOperation/segmentByRect.d.ts +31 -0
  16. package/dist/types/index.d.ts +9 -3
  17. package/dist/types/newCore/CanvasScheduler.d.ts +31 -0
  18. package/dist/types/newCore/index.d.ts +1 -0
  19. package/dist/types/utils/MathUtils.d.ts +6 -0
  20. package/dist/types/utils/tool/CommonToolUtils.d.ts +0 -13
  21. package/dist/types/utils/tool/EnhanceCommonToolUtils.d.ts +20 -0
  22. package/dist/types/utils/tool/PolygonUtils.d.ts +1 -0
  23. package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +3 -0
  24. package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +3 -0
  25. package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +3 -0
  26. package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +3 -0
  27. package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +3 -0
  28. package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +3 -0
  29. package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +3 -0
  30. package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +3 -0
  31. package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +3 -0
  32. package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +3 -0
  33. package/es/assets/attributeIcon/icon_editFEN.svg.js +3 -0
  34. package/es/assets/attributeIcon/icon_editHUANG.svg.js +3 -0
  35. package/es/assets/attributeIcon/icon_editLAN.svg.js +3 -0
  36. package/es/assets/attributeIcon/icon_editLV.svg.js +3 -0
  37. package/es/assets/attributeIcon/icon_editQING.svg.js +3 -0
  38. package/es/constant/annotation.js +68 -0
  39. package/es/constant/annotationTask.js +25 -0
  40. package/es/constant/defaultConfig.js +260 -0
  41. package/es/constant/keyCode.js +36 -0
  42. package/es/constant/style.js +67 -0
  43. package/es/constant/tool.js +183 -0
  44. package/es/core/index.js +145 -0
  45. package/es/core/pointCloud/OrbitControls.js +661 -0
  46. package/es/core/pointCloud/PCDLoader.js +238 -0
  47. package/es/core/pointCloud/annotation.js +98 -0
  48. package/es/core/pointCloud/cache.js +42 -0
  49. package/es/core/pointCloud/index.js +771 -0
  50. package/es/core/scheduler.js +184 -0
  51. package/es/core/toolOperation/LineToolOperation.js +1369 -0
  52. package/es/core/toolOperation/TextToolOperation.js +129 -0
  53. package/es/core/toolOperation/ViewOperation.js +410 -0
  54. package/es/core/toolOperation/basicToolOperation.js +817 -0
  55. package/es/core/toolOperation/checkOperation.js +206 -0
  56. package/es/core/toolOperation/eventListener.js +35 -0
  57. package/es/core/toolOperation/measureOperation.js +39 -0
  58. package/es/core/toolOperation/pointCloud2dOperation.js +197 -0
  59. package/es/core/toolOperation/pointOperation.js +603 -0
  60. package/es/core/toolOperation/polygonOperation.js +1201 -0
  61. package/es/core/toolOperation/rectOperation.js +1170 -0
  62. package/es/core/toolOperation/segmentByRect.js +172 -0
  63. package/es/core/toolOperation/tagOperation.js +215 -0
  64. package/es/core/toolOperation/textAttributeClass.js +201 -0
  65. package/es/index.js +25 -14
  66. package/es/locales/constants.js +21 -0
  67. package/es/locales/en_US/message.js +22 -0
  68. package/es/locales/index.js +17 -0
  69. package/es/locales/zh_CN/message.js +22 -0
  70. package/es/newCore/CanvasScheduler.js +31 -0
  71. package/es/utils/ActionsHistory.js +78 -0
  72. package/es/utils/ImgUtils.js +20 -0
  73. package/es/utils/MathUtils.js +283 -0
  74. package/es/utils/VectorUtils.js +23 -0
  75. package/es/utils/tool/AttributeUtils.js +196 -0
  76. package/es/utils/tool/AxisUtils.js +254 -0
  77. package/es/utils/tool/CanvasUtils.js +60 -0
  78. package/es/utils/tool/CommonToolUtils.js +172 -0
  79. package/es/utils/tool/CurrentOperation.js +35 -0
  80. package/es/utils/tool/DblClickEventListener.js +100 -0
  81. package/es/utils/tool/DrawUtils.js +424 -0
  82. package/es/utils/tool/EnhanceCommonToolUtils.js +39 -0
  83. package/es/utils/tool/ImgPosUtils.js +56 -0
  84. package/es/utils/tool/LineToolUtils.js +255 -0
  85. package/es/utils/tool/MarkerUtils.js +9 -0
  86. package/es/utils/tool/PolygonUtils.js +458 -0
  87. package/es/utils/tool/RectUtils.js +153 -0
  88. package/es/utils/tool/RenderDomClass.js +68 -0
  89. package/es/utils/tool/RenderDomUtils.js +29 -0
  90. package/es/utils/tool/StyleUtils.js +29 -0
  91. package/es/utils/tool/TagUtils.js +127 -0
  92. package/es/utils/tool/UnitUtils.js +10 -0
  93. package/es/utils/tool/ZoomUtils.js +70 -0
  94. package/es/utils/tool/polygonTool.js +126 -0
  95. package/es/utils/uuid.js +24 -0
  96. package/package.json +6 -4
@@ -0,0 +1,1170 @@
1
+ import MathUtils from '../../utils/MathUtils.js';
2
+ import AxisUtils from '../../utils/tool/AxisUtils.js';
3
+ import RectUtils from '../../utils/tool/RectUtils.js';
4
+ import { EDragStatus, ESortDirection, DEFAULT_TEXT_SHADOW } from '../../constant/annotation.js';
5
+ import EKeyCode from '../../constant/keyCode.js';
6
+ import { EDragTarget } from '../../constant/tool.js';
7
+ import Locale from '../../locales/index.js';
8
+ import { EMessage } from '../../locales/constants.js';
9
+ import AttributeUtils from '../../utils/tool/AttributeUtils.js';
10
+ import CanvasUtils from '../../utils/tool/CanvasUtils.js';
11
+ import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
12
+ import DrawUtils from '../../utils/tool/DrawUtils.js';
13
+ import MarkerUtils from '../../utils/tool/MarkerUtils.js';
14
+ import { getPolygonPointUnderZoom } from '../../utils/tool/polygonTool.js';
15
+ import uuid from '../../utils/uuid.js';
16
+ import { BasicToolOperation } from './basicToolOperation.js';
17
+ import TextAttributeClass from './textAttributeClass.js';
18
+
19
+ var __defProp = Object.defineProperty;
20
+ var __defProps = Object.defineProperties;
21
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
22
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
23
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
24
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
25
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
26
+ var __spreadValues = (a, b) => {
27
+ for (var prop in b || (b = {}))
28
+ if (__hasOwnProp.call(b, prop))
29
+ __defNormalProp(a, prop, b[prop]);
30
+ if (__getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(b)) {
32
+ if (__propIsEnum.call(b, prop))
33
+ __defNormalProp(a, prop, b[prop]);
34
+ }
35
+ return a;
36
+ };
37
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
38
+ const scope = 6;
39
+ class RectOperation extends BasicToolOperation {
40
+ constructor(props) {
41
+ super(props);
42
+ this.setMarkerIndex = (markerIndex) => {
43
+ this.markerIndex = markerIndex;
44
+ };
45
+ this.setMarkerIndexAndSelect = (markerIndex) => {
46
+ if (!this.config.markerList) {
47
+ return;
48
+ }
49
+ this.markerIndex = markerIndex;
50
+ const markerValue = this.config.markerList[markerIndex].value;
51
+ const currentRect = this.currentPageResult.find((rect) => rect.label === markerValue);
52
+ if (currentRect) {
53
+ this.setSelectedID(currentRect.id);
54
+ if (this.config.attributeConfigurable === true) {
55
+ this.setDefaultAttribute(currentRect.attribute);
56
+ }
57
+ }
58
+ this.emit("markIndexChange");
59
+ };
60
+ this.getHoverRectID = (e) => {
61
+ const coordinate = this.getCoordinateUnderZoom(e);
62
+ const newScope = scope;
63
+ const {currentShowList} = this;
64
+ if (currentShowList.length > 0) {
65
+ if (this.selectedRectID) {
66
+ const {selectedRect} = this;
67
+ if (selectedRect) {
68
+ if (RectUtils.isInRect(coordinate, selectedRect, newScope, this.zoom)) {
69
+ return selectedRect.id;
70
+ }
71
+ }
72
+ }
73
+ const hoverList = currentShowList.filter((rect) => RectUtils.isInRect(coordinate, rect, newScope, this.zoom));
74
+ if (hoverList.length === 0) {
75
+ return "";
76
+ }
77
+ if (hoverList.length === 1) {
78
+ return hoverList[0].id;
79
+ }
80
+ if (hoverList.length > 1) {
81
+ const rectSizeList = hoverList.map((rect) => ({size: rect.width * rect.height, id: rect.id})).sort((a, b) => a.size - b.size);
82
+ return rectSizeList[0].id;
83
+ }
84
+ }
85
+ return "";
86
+ };
87
+ this.textChange = (v) => {
88
+ if (this.config.textConfigurable !== true || !this.selectedRectID) {
89
+ return;
90
+ }
91
+ this.setRectList(AttributeUtils.textChange(v, this.selectedRectID, this.rectList), true);
92
+ this.emit("selectedChange");
93
+ this.render();
94
+ };
95
+ this.drawOutSideTarget = props.drawOutSideTarget || false;
96
+ this.rectList = [];
97
+ this.isFlow = true;
98
+ this.config = CommonToolUtils.jsonParser(props.config);
99
+ this.hoverRectEdgeIndex = -1;
100
+ this.hoverRectPointIndex = -1;
101
+ this.markerIndex = 0;
102
+ this.setStyle(props.style);
103
+ this.createNewDrawingRect = this.createNewDrawingRect.bind(this);
104
+ this.getDrawingRectWithRectList = this.getDrawingRectWithRectList.bind(this);
105
+ this.setSelectedIdAfterAddingDrawingRect = this.setSelectedIdAfterAddingDrawingRect.bind(this);
106
+ this.getCurrentSelectedData = this.getCurrentSelectedData.bind(this);
107
+ this.updateSelectedRectTextAttribute = this.updateSelectedRectTextAttribute.bind(this);
108
+ this.setSelectedID = this.setSelectedID.bind(this);
109
+ }
110
+ setResult(rectList) {
111
+ this.clearActiveStatus();
112
+ this.setRectList(rectList);
113
+ if (this.hasMarkerConfig) {
114
+ const nextMarkerInfo = CommonToolUtils.getNextMarker(this.getCurrentPageResult(rectList), this.config.markerList);
115
+ if (nextMarkerInfo) {
116
+ this.setMarkerIndex(nextMarkerInfo.index);
117
+ }
118
+ }
119
+ this.render();
120
+ }
121
+ destroy() {
122
+ super.destroy();
123
+ if (this._textAttributInstance) {
124
+ this._textAttributInstance.clearTextAttribute();
125
+ }
126
+ }
127
+ setConfig(config, isClear = false) {
128
+ this.config = CommonToolUtils.jsonParser(config);
129
+ if (isClear === true) {
130
+ this.clearResult(false);
131
+ }
132
+ }
133
+ setRectList(rectList, isUpload = false) {
134
+ const oldLen = this.rectList.length;
135
+ this.rectList = rectList;
136
+ if (oldLen !== rectList.length) {
137
+ this.emit("updatePageNumber");
138
+ }
139
+ if (isUpload) {
140
+ this.emit("updateResult");
141
+ }
142
+ }
143
+ get selectedRect() {
144
+ return this.rectList.find((v) => v.id === this.selectedRectID);
145
+ }
146
+ get selectedID() {
147
+ return this.selectedRectID;
148
+ }
149
+ get selectedText() {
150
+ var _a;
151
+ return (_a = this.selectedRect) == null ? void 0 : _a.textAttribute;
152
+ }
153
+ get dataList() {
154
+ return this.rectList;
155
+ }
156
+ get currentShowList() {
157
+ let rect = [];
158
+ const [showingRect, selectedRect] = CommonToolUtils.getRenderResultList(this.rectList, CommonToolUtils.getSourceID(this.basicResult), this.attributeLockList, this.selectedID);
159
+ rect = showingRect;
160
+ if (this.isHidden) {
161
+ rect = [];
162
+ }
163
+ if (selectedRect) {
164
+ rect.push(selectedRect);
165
+ }
166
+ return rect;
167
+ }
168
+ get currentPageResult() {
169
+ const [showingRect] = CommonToolUtils.getRenderResultList(this.rectList, CommonToolUtils.getSourceID(this.basicResult), []);
170
+ return showingRect;
171
+ }
172
+ getCurrentPageResult(rectList) {
173
+ const [showingRect] = CommonToolUtils.getRenderResultList(rectList, CommonToolUtils.getSourceID(this.basicResult), []);
174
+ return showingRect;
175
+ }
176
+ setSelectedID(newID) {
177
+ this.setSelectedRectID(newID);
178
+ }
179
+ setSelectedRectID(newID) {
180
+ var _a, _b;
181
+ const oldID = this.selectedRectID;
182
+ if (newID !== oldID && oldID) {
183
+ (_a = this._textAttributInstance) == null ? void 0 : _a.changeSelected();
184
+ }
185
+ if (!newID) {
186
+ (_b = this._textAttributInstance) == null ? void 0 : _b.clearTextAttribute();
187
+ }
188
+ this.selectedRectID = newID;
189
+ this.render();
190
+ this.emit("selectedChange");
191
+ }
192
+ setStyle(toolStyle) {
193
+ var _a;
194
+ super.setStyle(toolStyle);
195
+ if (this._textAttributInstance && this.config.attributeConfigurable === false) {
196
+ (_a = this._textAttributInstance) == null ? void 0 : _a.updateIcon(this.getTextIconSvg());
197
+ }
198
+ }
199
+ updateSelectedRectTextAttribute(newTextAttribute) {
200
+ if (this._textAttributInstance && newTextAttribute) {
201
+ let textAttribute = newTextAttribute;
202
+ if (AttributeUtils.textAttributeValidate(this.config.textCheckType, "", textAttribute) === false) {
203
+ this.emit("messageError", AttributeUtils.getErrorNotice(this.config.textCheckType, this.lang));
204
+ textAttribute = "";
205
+ }
206
+ this.setRectList(this.rectList.map((v) => {
207
+ if (v.id === this.selectedRectID) {
208
+ return __spreadProps(__spreadValues({}, v), {
209
+ textAttribute
210
+ });
211
+ }
212
+ return v;
213
+ }), true);
214
+ this.emit("updateTextAttribute");
215
+ this.render();
216
+ }
217
+ }
218
+ getHoverRectPointIndex(e) {
219
+ if (!this.selectedRect) {
220
+ return -1;
221
+ }
222
+ return AxisUtils.returnClosePointIndex(this.getCoordinateUnderZoom(e), RectUtils.getRectPointList(this.selectedRect, this.zoom), scope + 2);
223
+ }
224
+ getHoverRectEdgeIndex(e) {
225
+ if (!this.selectedRect) {
226
+ return -1;
227
+ }
228
+ let edgeIndex = -1;
229
+ const {selectedRect} = this;
230
+ const edgeList = RectUtils.getRectEdgeList(selectedRect, this.zoom);
231
+ const coordinate = this.getCoordinateUnderZoom(e);
232
+ for (let i = 0; i < edgeList.length; i++) {
233
+ const edge = edgeList[i];
234
+ const {length} = MathUtils.getFootOfPerpendicular(coordinate, edge.begin, edge.end);
235
+ if (length < scope + 10) {
236
+ edgeIndex = i;
237
+ }
238
+ }
239
+ return edgeIndex;
240
+ }
241
+ getTextIconSvg(attribute = "") {
242
+ return AttributeUtils.getTextIconSvg(attribute, this.config.attributeList, this.config.attributeConfigurable, this.baseIcon);
243
+ }
244
+ onMouseDown(e) {
245
+ if (super.onMouseDown(e) || this.forbidMouseOperation || e.ctrlKey === true) {
246
+ return;
247
+ }
248
+ const dragStartCoord = this.getCoordinateUnderZoom(e);
249
+ const hoverRectID = this.getHoverRectID(e);
250
+ const firstRect = this.currentShowList.find((v) => v.id === this.selectedRectID);
251
+ if (!firstRect || e.button === 2 || e.button === 0 && this.isSpaceKey === true) {
252
+ return;
253
+ }
254
+ if (this.selectedRectID) {
255
+ if (this.getHoverRectPointIndex(e) > -1) {
256
+ const dragTarget = EDragTarget.Point;
257
+ this.dragInfo = {
258
+ dragStartCoord,
259
+ dragTarget,
260
+ startTime: +new Date(),
261
+ firstRect
262
+ };
263
+ this.dragStatus = EDragStatus.Start;
264
+ return;
265
+ }
266
+ if (this.getHoverRectEdgeIndex(e) > -1) {
267
+ const dragTarget = EDragTarget.Line;
268
+ this.dragInfo = {
269
+ dragStartCoord,
270
+ dragTarget,
271
+ startTime: +new Date(),
272
+ firstRect
273
+ };
274
+ this.dragStatus = EDragStatus.Start;
275
+ return;
276
+ }
277
+ }
278
+ if (hoverRectID === this.selectedRectID && !this.drawingRect) {
279
+ const dragTarget = EDragTarget.Plane;
280
+ this.dragInfo = {
281
+ dragStartCoord,
282
+ dragTarget,
283
+ firstRect,
284
+ startTime: +new Date()
285
+ };
286
+ this.dragStatus = EDragStatus.Start;
287
+ }
288
+ return void 0;
289
+ }
290
+ onDragMove(coordinate) {
291
+ var _a, _b, _c, _d, _e, _f;
292
+ if (!this.dragInfo) {
293
+ return;
294
+ }
295
+ this.dragStatus = EDragStatus.Move;
296
+ const dragRect = RectUtils.getRectUnderZoom(this.dragInfo.firstRect, this.zoom);
297
+ const {x, y, width, height} = dragRect;
298
+ const offset = {
299
+ x: coordinate.x - this.dragInfo.dragStartCoord.x,
300
+ y: coordinate.y - this.dragInfo.dragStartCoord.y
301
+ };
302
+ let selectedRect = this.rectList.filter((v) => v.id === this.selectedRectID)[0];
303
+ switch (this.dragInfo.dragTarget) {
304
+ case EDragTarget.Plane:
305
+ selectedRect = __spreadProps(__spreadValues({}, selectedRect), {
306
+ x: x + offset.x,
307
+ y: y + offset.y,
308
+ width,
309
+ height
310
+ });
311
+ break;
312
+ case EDragTarget.Point:
313
+ {
314
+ let newX = x;
315
+ let newY = y;
316
+ let newWidth = width;
317
+ let newHeight = height;
318
+ switch (this.hoverRectPointIndex) {
319
+ case 0: {
320
+ newX = width - offset.x < 0 ? x + width : x + offset.x;
321
+ newY = height - offset.y < 0 ? y + height : y + offset.y;
322
+ newWidth = Math.abs(offset.x - width);
323
+ newHeight = Math.abs(offset.y - height);
324
+ break;
325
+ }
326
+ case 1: {
327
+ newX = width + offset.x > 0 ? x : x + width + offset.x;
328
+ newY = height - offset.y < 0 ? y + height : y + offset.y;
329
+ newWidth = Math.abs(width + offset.x);
330
+ newHeight = Math.abs(height - offset.y);
331
+ break;
332
+ }
333
+ case 2: {
334
+ newX = width + offset.x > 0 ? x : x + width + offset.x;
335
+ newY = height + offset.y > 0 ? y : y + height + offset.y;
336
+ newWidth = Math.abs(width + offset.x);
337
+ newHeight = height + offset.y > 0 ? height + offset.y : Math.abs(height + offset.y);
338
+ break;
339
+ }
340
+ case 3: {
341
+ newX = width - offset.x < 0 ? x + width : x + offset.x;
342
+ newY = height + offset.y > 0 ? y : y + height + offset.y;
343
+ newWidth = Math.abs(offset.x - width);
344
+ newHeight = height + offset.y > 0 ? height + offset.y : Math.abs(height + offset.y);
345
+ break;
346
+ }
347
+ default: {
348
+ return;
349
+ }
350
+ }
351
+ selectedRect = __spreadProps(__spreadValues({}, selectedRect), {
352
+ x: newX,
353
+ y: newY,
354
+ width: newWidth,
355
+ height: newHeight
356
+ });
357
+ }
358
+ break;
359
+ case EDragTarget.Line: {
360
+ let newX = x;
361
+ let newY = y;
362
+ let newWidth = width;
363
+ let newHeight = height;
364
+ switch (this.hoverRectEdgeIndex) {
365
+ case 0: {
366
+ newY = height - offset.y < 0 ? y + height : y + offset.y;
367
+ newHeight = Math.abs(offset.y - height);
368
+ break;
369
+ }
370
+ case 1: {
371
+ newX = width + offset.x > 0 ? x : x + width + offset.x;
372
+ newWidth = Math.abs(width + offset.x);
373
+ break;
374
+ }
375
+ case 2: {
376
+ newY = height + offset.y > 0 ? y : y + height + offset.y;
377
+ newHeight = height + offset.y > 0 ? height + offset.y : Math.abs(height + offset.y);
378
+ break;
379
+ }
380
+ case 3: {
381
+ newX = width - offset.x < 0 ? x + width : x + offset.x;
382
+ newWidth = Math.abs(offset.x - width);
383
+ break;
384
+ }
385
+ default: {
386
+ return;
387
+ }
388
+ }
389
+ selectedRect = __spreadProps(__spreadValues({}, selectedRect), {
390
+ x: newX,
391
+ y: newY,
392
+ width: newWidth,
393
+ height: newHeight
394
+ });
395
+ break;
396
+ }
397
+ default: {
398
+ return;
399
+ }
400
+ }
401
+ if (this.config.drawOutsideTarget === false) {
402
+ if (this.basicResult) {
403
+ if (((_b = (_a = this.basicResult) == null ? void 0 : _a.pointList) == null ? void 0 : _b.length) > 0) {
404
+ if (RectUtils.isRectNotInPolygon(selectedRect, getPolygonPointUnderZoom(this.basicResult.pointList, this.zoom))) {
405
+ return;
406
+ }
407
+ }
408
+ const basicX = this.basicResult.x * this.zoom;
409
+ const basicY = this.basicResult.y * this.zoom;
410
+ const basicWidth = this.basicResult.width * this.zoom;
411
+ const basicHeight = this.basicResult.height * this.zoom;
412
+ if (this.dragInfo.dragTarget !== EDragTarget.Plane && (selectedRect.x < basicX - 0.01 || selectedRect.y < basicY - 0.01 || selectedRect.width > basicX + basicWidth - selectedRect.x + 0.01 || selectedRect.height > basicY + basicHeight - selectedRect.y + 0.01)) {
413
+ return;
414
+ }
415
+ if (selectedRect.x < basicX) {
416
+ selectedRect.x = basicX;
417
+ }
418
+ if (selectedRect.y < basicY) {
419
+ selectedRect.y = basicY;
420
+ }
421
+ if (selectedRect.width > basicX + basicWidth - selectedRect.x) {
422
+ switch (this.dragInfo.dragTarget) {
423
+ case EDragTarget.Plane:
424
+ selectedRect.x = basicX + basicWidth - width;
425
+ break;
426
+ case EDragTarget.Point:
427
+ case EDragTarget.Line:
428
+ if (offset.x > 0 && offset.y > 0) {
429
+ selectedRect.width = basicX + basicWidth - selectedRect.x;
430
+ }
431
+ break;
432
+ default: {
433
+ return;
434
+ }
435
+ }
436
+ }
437
+ if (selectedRect.height > basicY + basicHeight - selectedRect.y) {
438
+ switch (this.dragInfo.dragTarget) {
439
+ case EDragTarget.Plane:
440
+ selectedRect.y = basicY + basicHeight - height;
441
+ break;
442
+ }
443
+ }
444
+ } else {
445
+ if (selectedRect.x < 0) {
446
+ selectedRect.x = 0;
447
+ }
448
+ if (selectedRect.y < 0) {
449
+ selectedRect.y = 0;
450
+ }
451
+ if (this.imgInfo) {
452
+ switch (this.dragInfo.dragTarget) {
453
+ case EDragTarget.Plane:
454
+ if (selectedRect.x + selectedRect.width > ((_c = this.imgInfo) == null ? void 0 : _c.width)) {
455
+ selectedRect.x = this.imgInfo.width - width;
456
+ }
457
+ if (selectedRect.y + selectedRect.height > ((_d = this.imgInfo) == null ? void 0 : _d.height)) {
458
+ selectedRect.y = this.imgInfo.height - height;
459
+ }
460
+ break;
461
+ default: {
462
+ if (selectedRect.x + selectedRect.width > ((_e = this.imgInfo) == null ? void 0 : _e.width) + 0.01 || selectedRect.y + selectedRect.height > ((_f = this.imgInfo) == null ? void 0 : _f.height) + 0.01) {
463
+ return;
464
+ }
465
+ }
466
+ }
467
+ }
468
+ }
469
+ }
470
+ this.setRectList(this.rectList.map((v) => {
471
+ if (v.id === selectedRect.id) {
472
+ return RectUtils.getRectUnderZoom(selectedRect, 1 / this.zoom);
473
+ }
474
+ return v;
475
+ }));
476
+ this.render();
477
+ }
478
+ onMouseMove(e) {
479
+ var _a, _b;
480
+ if (super.onMouseMove(e) || this.forbidMouseOperation || !this.imgInfo) {
481
+ return;
482
+ }
483
+ const coordinateZoom = this.getCoordinateUnderZoom(e);
484
+ const coordinate = AxisUtils.changeDrawOutsideTarget(coordinateZoom, {x: 0, y: 0}, this.imgInfo, this.config.drawOutsideTarget, this.basicResult, this.zoom);
485
+ if (this.selectedRectID && this.dragInfo) {
486
+ this.onDragMove(coordinate);
487
+ return;
488
+ }
489
+ if (this.selectedRectID) {
490
+ const hoverRectPointIndex = this.getHoverRectPointIndex(e);
491
+ if (hoverRectPointIndex !== this.hoverRectPointIndex) {
492
+ this.hoverRectPointIndex = hoverRectPointIndex;
493
+ this.hoverRectEdgeIndex = -1;
494
+ this.render();
495
+ return;
496
+ }
497
+ if (this.hoverRectPointIndex === -1) {
498
+ const hoverRectEdgeIndex = this.getHoverRectEdgeIndex(e);
499
+ if (hoverRectEdgeIndex !== this.hoverRectEdgeIndex) {
500
+ this.hoverRectEdgeIndex = hoverRectEdgeIndex;
501
+ this.render();
502
+ return;
503
+ }
504
+ }
505
+ }
506
+ const hoverRectID = this.getHoverRectID(e);
507
+ const oldHoverRectID = this.hoverRectID;
508
+ this.hoverRectID = hoverRectID;
509
+ if (hoverRectID !== oldHoverRectID) {
510
+ this.render();
511
+ }
512
+ if (this.drawingRect && this.firstClickCoord) {
513
+ let {x, y} = this.firstClickCoord;
514
+ let {width, height} = this.drawingRect;
515
+ width = Math.abs(x - coordinate.x);
516
+ height = Math.abs(y - coordinate.y);
517
+ if (coordinate.x < x) {
518
+ x = coordinate.x;
519
+ }
520
+ if (coordinate.y < y) {
521
+ y = coordinate.y;
522
+ }
523
+ if (this.config.drawOutsideTarget === false) {
524
+ if (((_b = (_a = this.basicResult) == null ? void 0 : _a.pointList) == null ? void 0 : _b.length) > 0) {
525
+ if (RectUtils.isRectNotInPolygon(__spreadProps(__spreadValues({}, this.drawingRect), {
526
+ x,
527
+ y,
528
+ width,
529
+ height
530
+ }), getPolygonPointUnderZoom(this.basicResult.pointList, this.zoom))) {
531
+ return;
532
+ }
533
+ }
534
+ if (coordinate.x < 0) {
535
+ width = Math.abs(this.firstClickCoord.x);
536
+ x = 0;
537
+ }
538
+ if (coordinate.y < 0) {
539
+ height = Math.abs(this.firstClickCoord.y);
540
+ y = 0;
541
+ }
542
+ if (this.imgInfo) {
543
+ if (x + width > this.imgInfo.width) {
544
+ width = Math.abs(this.imgInfo.width - x);
545
+ }
546
+ if (y + height > this.imgInfo.height) {
547
+ height = Math.abs(this.imgInfo.height - y);
548
+ }
549
+ }
550
+ }
551
+ this.drawingRect = __spreadProps(__spreadValues({}, this.drawingRect), {
552
+ x,
553
+ y,
554
+ width,
555
+ height
556
+ });
557
+ this.render();
558
+ }
559
+ return void 0;
560
+ }
561
+ setAttributeLockList(attributeLockList) {
562
+ this.setSelectedRectID(void 0);
563
+ super.setAttributeLockList(attributeLockList);
564
+ }
565
+ setBasicResult(basicResult) {
566
+ super.setBasicResult(basicResult);
567
+ this.clearActiveStatus();
568
+ }
569
+ setRectValidAndRender(id) {
570
+ if (!id) {
571
+ return;
572
+ }
573
+ this.setRectList(this.rectList.map((rect) => {
574
+ if (rect.id === id) {
575
+ return __spreadProps(__spreadValues({}, rect), {
576
+ valid: !rect.valid
577
+ });
578
+ }
579
+ return rect;
580
+ }), true);
581
+ this.render();
582
+ this.emit("updateResult");
583
+ }
584
+ createNewDrawingRect(e, basicSourceID) {
585
+ if (!this.imgInfo) {
586
+ return;
587
+ }
588
+ const coordinateZoom = this.getCoordinateUnderZoom(e);
589
+ const coordinate = AxisUtils.changeDrawOutsideTarget(coordinateZoom, {x: 0, y: 0}, this.imgInfo, this.config.drawOutsideTarget, this.basicResult, this.zoom);
590
+ this.setSelectedRectID("");
591
+ this.hoverRectID = "";
592
+ if (this.drawOutSideTarget) {
593
+ if (coordinate.x < 0) {
594
+ coordinate.x = 0;
595
+ }
596
+ if (coordinate.y < 0) {
597
+ coordinate.y = 0;
598
+ }
599
+ }
600
+ this.drawingRect = __spreadProps(__spreadValues({}, coordinate), {
601
+ width: 0,
602
+ height: 0,
603
+ attribute: this.defaultAttribute,
604
+ valid: !e.ctrlKey,
605
+ id: uuid(8, 62),
606
+ sourceID: basicSourceID,
607
+ textAttribute: ""
608
+ });
609
+ if (this.hasMarkerConfig) {
610
+ const nextMarkInfo = CommonToolUtils.getNextMarker(this.currentPageResult, this.config.markerList, this.markerIndex);
611
+ if (nextMarkInfo) {
612
+ if (this.drawingRect) {
613
+ this.drawingRect = __spreadProps(__spreadValues({}, this.drawingRect), {
614
+ label: nextMarkInfo.label
615
+ });
616
+ }
617
+ this.markerIndex = nextMarkInfo.index;
618
+ this.emit("markIndexChange");
619
+ } else {
620
+ this.emit("messageInfo", Locale.getMessagesByLocale(EMessage.MarkerFinish, this.lang));
621
+ this.drawingRect = void 0;
622
+ return;
623
+ }
624
+ }
625
+ if (this.config.textConfigurable) {
626
+ let textAttribute = "";
627
+ textAttribute = AttributeUtils.getTextAttribute(this.rectList.filter((rect) => CommonToolUtils.isSameSourceID(rect.sourceID, basicSourceID)), this.config.textCheckType);
628
+ if (this.drawingRect) {
629
+ this.drawingRect = __spreadProps(__spreadValues({}, this.drawingRect), {
630
+ textAttribute
631
+ });
632
+ }
633
+ }
634
+ Object.assign(this.drawingRect, {
635
+ order: CommonToolUtils.getMaxOrder(this.rectList.filter((v) => CommonToolUtils.isSameSourceID(v.sourceID, basicSourceID))) + 1
636
+ });
637
+ this.firstClickCoord = __spreadValues({}, coordinate);
638
+ this.firstCurrentPos = __spreadValues({}, this.currentPos);
639
+ if (this.dataInjectionAtCreation) {
640
+ const data = this.dataInjectionAtCreation(this.drawingRect);
641
+ if (data) {
642
+ Object.assign(this.drawingRect, data);
643
+ }
644
+ }
645
+ }
646
+ addDrawingRectToRectList() {
647
+ if (!this.drawingRect) {
648
+ return;
649
+ }
650
+ let {width, height} = this.drawingRect;
651
+ width /= this.zoom;
652
+ height /= this.zoom;
653
+ if (Math.round(width) < this.config.minWidth || Math.round(height) < this.config.minHeight) {
654
+ this.emit("messageInfo", Locale.getMessagesByLocale(EMessage.RectErrorSizeNotice, this.lang));
655
+ this.drawingRect = void 0;
656
+ this.firstClickCoord = void 0;
657
+ this.dragInfo = void 0;
658
+ this.dragStatus = EDragStatus.Wait;
659
+ this.render();
660
+ return;
661
+ }
662
+ const newRectList = this.getDrawingRectWithRectList();
663
+ this.setRectList(newRectList, true);
664
+ this.history.pushHistory(this.rectList);
665
+ this.setSelectedIdAfterAddingDrawingRect();
666
+ this.firstClickCoord = void 0;
667
+ this.drawingRect = void 0;
668
+ this.dragInfo = void 0;
669
+ this.dragStatus = EDragStatus.Wait;
670
+ }
671
+ setSelectedIdAfterAddingDrawingRect() {
672
+ if (!this.drawingRect) {
673
+ return;
674
+ }
675
+ if (this.config.textConfigurable) {
676
+ this.setSelectedRectID(this.drawingRect.id);
677
+ } else {
678
+ this.setSelectedRectID();
679
+ }
680
+ }
681
+ getDrawingRectWithRectList() {
682
+ if (!this.drawingRect) {
683
+ return this.rectList;
684
+ }
685
+ let {x, y, width, height} = this.drawingRect;
686
+ x /= this.zoom;
687
+ y /= this.zoom;
688
+ width /= this.zoom;
689
+ height /= this.zoom;
690
+ return [
691
+ ...this.rectList,
692
+ __spreadProps(__spreadValues({}, this.drawingRect), {
693
+ x,
694
+ y,
695
+ width,
696
+ height
697
+ })
698
+ ];
699
+ }
700
+ rightMouseUp(e) {
701
+ const hoverRectID = this.getHoverRectID(e);
702
+ const hoverRect = this.rectList.find((v) => v.id === hoverRectID);
703
+ const {selectedRectID} = this;
704
+ this.setSelectedRectID(void 0);
705
+ if (hoverRect) {
706
+ this.setDefaultAttribute(hoverRect.attribute);
707
+ }
708
+ if (this.drawingRect) {
709
+ this.drawingRect = void 0;
710
+ this.firstClickCoord = void 0;
711
+ } else {
712
+ if (selectedRectID !== hoverRectID) {
713
+ this.dblClickListener.clearRightDblClick();
714
+ }
715
+ this.setSelectedRectID(hoverRectID);
716
+ this.hoverRectID = "";
717
+ if ((hoverRect == null ? void 0 : hoverRect.label) && this.hasMarkerConfig) {
718
+ const markerIndex = CommonToolUtils.getCurrentMarkerIndex(hoverRect.label, this.config.markerList);
719
+ if (markerIndex >= 0) {
720
+ this.setMarkerIndex(markerIndex);
721
+ this.emit("markIndexChange");
722
+ }
723
+ }
724
+ }
725
+ this.render();
726
+ }
727
+ shiftRightMouseUp(e) {
728
+ const hoverRectID = this.getHoverRectID(e);
729
+ this.emit("shiftRightMouseUp", hoverRectID);
730
+ }
731
+ onMouseUp(e) {
732
+ if (super.onMouseUp(e) || this.forbidMouseOperation || !this.imgInfo) {
733
+ return true;
734
+ }
735
+ if (this.dragInfo && this.dragStatus === EDragStatus.Move) {
736
+ this.dragInfo = void 0;
737
+ this.dragStatus = EDragStatus.Wait;
738
+ this.history.pushHistory(this.rectList);
739
+ this.emit("updateResult");
740
+ return;
741
+ }
742
+ if (e.button === 2 && e.shiftKey === true) {
743
+ this.shiftRightMouseUp(e);
744
+ return;
745
+ }
746
+ if (e.button === 2) {
747
+ this.rightMouseUp(e);
748
+ return;
749
+ }
750
+ const basicSourceID = CommonToolUtils.getSourceID(this.basicResult);
751
+ if (this.drawingRect) {
752
+ this.addDrawingRectToRectList();
753
+ return;
754
+ }
755
+ if (e.ctrlKey === true && e.button === 0 && this.hoverRectID) {
756
+ this.setRectValidAndRender(this.hoverRectID);
757
+ return;
758
+ }
759
+ this.createNewDrawingRect(e, basicSourceID);
760
+ this.render();
761
+ return void 0;
762
+ }
763
+ onRightDblClick(e) {
764
+ super.onRightDblClick(e);
765
+ const hoverRectID = this.getHoverRectID(e);
766
+ if (this.selectedRectID && this.selectedRectID === hoverRectID) {
767
+ this.deleteRect(hoverRectID);
768
+ }
769
+ }
770
+ onKeyDown(e) {
771
+ if (!CommonToolUtils.hotkeyFilter(e)) {
772
+ return;
773
+ }
774
+ if (super.onKeyDown(e) === false) {
775
+ return;
776
+ }
777
+ const {keyCode} = e;
778
+ switch (keyCode) {
779
+ case EKeyCode.Ctrl:
780
+ if (this.drawingRect) {
781
+ this.drawingRect = __spreadProps(__spreadValues({}, this.drawingRect), {
782
+ valid: !e.ctrlKey
783
+ });
784
+ this.render();
785
+ }
786
+ break;
787
+ case EKeyCode.F:
788
+ if (this.selectedRectID) {
789
+ this.setRectValidAndRender(this.selectedRectID);
790
+ }
791
+ break;
792
+ case EKeyCode.Z:
793
+ this.setIsHidden(!this.isHidden);
794
+ this.render();
795
+ break;
796
+ case EKeyCode.Delete:
797
+ this.deleteRect(this.selectedRectID);
798
+ break;
799
+ case EKeyCode.Tab: {
800
+ e.preventDefault();
801
+ if (this.drawingRect) {
802
+ return;
803
+ }
804
+ let sort = ESortDirection.ascend;
805
+ if (e.shiftKey) {
806
+ sort = ESortDirection.descend;
807
+ }
808
+ const [showingRect, selectedRect] = CommonToolUtils.getRenderResultList(this.rectList, CommonToolUtils.getSourceID(this.basicResult), this.attributeLockList, this.selectedRectID);
809
+ let rectList = [...showingRect];
810
+ if (selectedRect) {
811
+ rectList = [...rectList, selectedRect];
812
+ }
813
+ const viewPort = CanvasUtils.getViewPort(this.canvas, this.currentPos, this.zoom);
814
+ rectList = rectList.filter((rect) => CanvasUtils.inViewPort({x: rect.x, y: rect.y}, viewPort));
815
+ const nextSelectedRect = CommonToolUtils.getNextSelectedRectID(rectList, sort, this.selectedRectID);
816
+ if (nextSelectedRect) {
817
+ this.setSelectedRectID(nextSelectedRect.id);
818
+ if (this.config.attributeConfigurable === true) {
819
+ this.setDefaultAttribute(nextSelectedRect.attribute);
820
+ }
821
+ }
822
+ break;
823
+ }
824
+ default: {
825
+ if (this.config.attributeConfigurable) {
826
+ const keyCode2Attribute = AttributeUtils.getAttributeByKeycode(keyCode, this.config.attributeList);
827
+ if (keyCode2Attribute !== void 0) {
828
+ this.setDefaultAttribute(keyCode2Attribute);
829
+ }
830
+ }
831
+ break;
832
+ }
833
+ }
834
+ return true;
835
+ }
836
+ onKeyUp(e) {
837
+ super.onKeyUp(e);
838
+ switch (e.keyCode) {
839
+ case EKeyCode.Ctrl:
840
+ if (this.drawingRect) {
841
+ this.drawingRect = __spreadProps(__spreadValues({}, this.drawingRect), {
842
+ valid: true
843
+ });
844
+ this.render();
845
+ }
846
+ break;
847
+ }
848
+ }
849
+ onWheel(e) {
850
+ const oldZoom = this.zoom;
851
+ let newDrawingRect;
852
+ let newFirsClickCoord;
853
+ if (this.drawingRect && this.firstClickCoord) {
854
+ newDrawingRect = RectUtils.getRectUnderZoom(this.drawingRect, 1 / oldZoom);
855
+ newFirsClickCoord = AxisUtils.changePointByZoom(this.firstClickCoord, 1 / oldZoom);
856
+ }
857
+ super.onWheel(e, false);
858
+ if (newDrawingRect && newFirsClickCoord) {
859
+ this.drawingRect = RectUtils.getRectUnderZoom(newDrawingRect, this.zoom);
860
+ this.firstClickCoord = AxisUtils.changePointByZoom(newFirsClickCoord, this.zoom);
861
+ }
862
+ this.render();
863
+ }
864
+ getCurrentSelectedData() {
865
+ const {selectedRect} = this;
866
+ if (!selectedRect) {
867
+ return;
868
+ }
869
+ const toolColor = this.getColor(selectedRect.attribute);
870
+ const color = selectedRect.valid ? toolColor == null ? void 0 : toolColor.valid.stroke : toolColor == null ? void 0 : toolColor.invalid.stroke;
871
+ return {
872
+ width: selectedRect.width * this.zoom * 0.6,
873
+ textAttribute: selectedRect.textAttribute,
874
+ color
875
+ };
876
+ }
877
+ getRenderStyle(rect) {
878
+ const customStyle = this.customRenderStyle && this.customRenderStyle(rect);
879
+ if (customStyle) {
880
+ return customStyle;
881
+ }
882
+ const toolColor = this.getColor(rect.attribute);
883
+ let strokeColor;
884
+ let fillColor;
885
+ if (rect.valid === false) {
886
+ strokeColor = toolColor == null ? void 0 : toolColor.invalid.stroke;
887
+ fillColor = toolColor == null ? void 0 : toolColor.invalid.fill;
888
+ } else {
889
+ strokeColor = toolColor == null ? void 0 : toolColor.valid.stroke;
890
+ fillColor = toolColor == null ? void 0 : toolColor.valid.fill;
891
+ }
892
+ return {
893
+ strokeColor,
894
+ fillColor,
895
+ textColor: strokeColor,
896
+ toolColor
897
+ };
898
+ }
899
+ renderTextAttribute() {
900
+ var _a;
901
+ const {selectedRect} = this;
902
+ if (!this.ctx || this.config.textConfigurable !== true || !selectedRect) {
903
+ return;
904
+ }
905
+ const {x, y, width, height, attribute, valid} = selectedRect;
906
+ const newWidth = width * this.zoom * 0.6;
907
+ const coordinate = AxisUtils.getOffsetCoordinate({x, y: y + height}, this.currentPos, this.zoom);
908
+ const toolColor = this.getColor(attribute);
909
+ const color = valid ? toolColor == null ? void 0 : toolColor.valid.stroke : toolColor == null ? void 0 : toolColor.invalid.stroke;
910
+ const distance = 4;
911
+ if (!this._textAttributInstance) {
912
+ this._textAttributInstance = new TextAttributeClass({
913
+ width: newWidth,
914
+ container: this.container,
915
+ icon: this.getTextIconSvg(attribute),
916
+ color,
917
+ getCurrentSelectedData: this.getCurrentSelectedData,
918
+ updateSelectedTextAttribute: this.updateSelectedRectTextAttribute
919
+ });
920
+ }
921
+ if (this._textAttributInstance && !((_a = this._textAttributInstance) == null ? void 0 : _a.isExit)) {
922
+ this._textAttributInstance.appendToContainer();
923
+ }
924
+ this._textAttributInstance.update(`${selectedRect.textAttribute}`, {
925
+ left: coordinate.x,
926
+ top: coordinate.y + distance,
927
+ color,
928
+ width: newWidth
929
+ });
930
+ }
931
+ renderSelectedRect(rect) {
932
+ const {selectedRect} = this;
933
+ if (!this.ctx || !rect || !selectedRect) {
934
+ return;
935
+ }
936
+ const {ctx} = this;
937
+ let radius = 10;
938
+ const pointList = RectUtils.getRectPointList(selectedRect);
939
+ const len = pointList.length;
940
+ const toolColor = this.getColor(rect.attribute);
941
+ pointList.forEach((v, i) => {
942
+ var _a, _b;
943
+ ctx.save();
944
+ ctx.moveTo(v.x, v.y);
945
+ ctx.beginPath();
946
+ if (this.hoverRectPointIndex === i) {
947
+ radius = scope + 6;
948
+ } else {
949
+ radius = scope;
950
+ }
951
+ if (rect.valid === false) {
952
+ ctx.strokeStyle = toolColor == null ? void 0 : toolColor.invalid.stroke;
953
+ ctx.fillStyle = toolColor == null ? void 0 : toolColor.invalid.stroke;
954
+ } else {
955
+ ctx.strokeStyle = toolColor == null ? void 0 : toolColor.valid.stroke;
956
+ ctx.fillStyle = toolColor == null ? void 0 : toolColor.valid.stroke;
957
+ }
958
+ ctx.arc(v.x * this.zoom + this.currentPos.x, v.y * this.zoom + this.currentPos.y, radius, 0, 2 * Math.PI);
959
+ ctx.fill();
960
+ if (this.hoverRectEdgeIndex === i) {
961
+ ctx.beginPath();
962
+ ctx.lineWidth = 10;
963
+ const lineColor = this.getColor(rect.attribute);
964
+ const strokeStyle = rect.valid === false ? (_a = lineColor == null ? void 0 : lineColor.invalid) == null ? void 0 : _a.stroke : (_b = lineColor == null ? void 0 : lineColor.valid) == null ? void 0 : _b.stroke;
965
+ ctx.strokeStyle = strokeStyle;
966
+ ctx.moveTo(pointList[i].x * this.zoom + this.currentPos.x, pointList[i].y * this.zoom + this.currentPos.y);
967
+ ctx.lineTo(pointList[(i + 1) % len].x * this.zoom + this.currentPos.x, pointList[(i + 1) % len].y * this.zoom + this.currentPos.y);
968
+ ctx.stroke();
969
+ }
970
+ ctx.restore();
971
+ });
972
+ this.renderTextAttribute();
973
+ }
974
+ renderDrawingRect(rect, zoom = this.zoom, isZoom = false) {
975
+ var _a, _b, _c, _d;
976
+ if (this.ctx && rect) {
977
+ const {ctx, style} = this;
978
+ const {hiddenText = false} = style;
979
+ ctx.save();
980
+ const {strokeColor, fillColor, textColor} = this.getRenderStyle(rect);
981
+ ctx.font = "lighter 14px Arial";
982
+ let showText = "";
983
+ if (((_a = this.config) == null ? void 0 : _a.isShowOrder) && rect.order && (rect == null ? void 0 : rect.order) > 0) {
984
+ showText = `${rect.order}`;
985
+ }
986
+ if (rect.label && this.hasMarkerConfig) {
987
+ const order = CommonToolUtils.getCurrentMarkerIndex(rect.label, this.config.markerList) + 1;
988
+ showText = `${order}_${MarkerUtils.getMarkerShowText(rect.label, this.config.markerList)}`;
989
+ }
990
+ if (rect.attribute) {
991
+ showText = `${showText} ${AttributeUtils.getAttributeShowText(rect.attribute, (_b = this.config) == null ? void 0 : _b.attributeList)}`;
992
+ }
993
+ const transformRect = AxisUtils.changeRectByZoom(rect, isZoom ? zoom : this.zoom, this.currentPos);
994
+ if (!hiddenText) {
995
+ DrawUtils.drawText(this.canvas, {x: transformRect.x, y: transformRect.y - 6}, showText, __spreadProps(__spreadValues({
996
+ color: strokeColor,
997
+ font: "normal normal 900 14px SourceHanSansCN-Regular"
998
+ }, DEFAULT_TEXT_SHADOW), {
999
+ textMaxWidth: 300
1000
+ }));
1001
+ }
1002
+ const lineWidth = (_d = (_c = this.style) == null ? void 0 : _c.width) != null ? _d : 2;
1003
+ if (rect.id === this.hoverRectID || rect.id === this.selectedRectID) {
1004
+ DrawUtils.drawRectWithFill(this.canvas, transformRect, {color: fillColor});
1005
+ }
1006
+ DrawUtils.drawRect(this.canvas, transformRect, {color: strokeColor, thickness: lineWidth, hiddenText: true});
1007
+ ctx.restore();
1008
+ let rectSize = `${Math.round(rect.width)} * ${Math.round(rect.height)}`;
1009
+ if (isZoom === true) {
1010
+ rectSize = `${Math.round(rect.width / this.zoom)} * ${Math.round(transformRect.height / this.zoom)}`;
1011
+ }
1012
+ const textSizeWidth = rectSize.length * 7;
1013
+ if (!hiddenText) {
1014
+ DrawUtils.drawText(this.canvas, {x: transformRect.x + transformRect.width - textSizeWidth, y: transformRect.y + transformRect.height + 15}, rectSize, __spreadValues({
1015
+ color: textColor,
1016
+ font: "normal normal 600 14px Arial"
1017
+ }, DEFAULT_TEXT_SHADOW));
1018
+ }
1019
+ if (!hiddenText && rect.textAttribute && rect.id !== this.selectedRectID) {
1020
+ const marginTop = 0;
1021
+ const textWidth = Math.max(20, transformRect.width - textSizeWidth);
1022
+ DrawUtils.drawText(this.canvas, {x: transformRect.x, y: transformRect.y + transformRect.height + 20 + marginTop}, rect.textAttribute, __spreadValues({
1023
+ color: textColor,
1024
+ font: "italic normal 900 14px Arial",
1025
+ textMaxWidth: textWidth
1026
+ }, DEFAULT_TEXT_SHADOW));
1027
+ }
1028
+ }
1029
+ }
1030
+ renderStaticRect() {
1031
+ var _a;
1032
+ if (!(((_a = this.rectList) == null ? void 0 : _a.length) > 0 && JSON.stringify(this.rectList))) {
1033
+ return;
1034
+ }
1035
+ const {renderEnhance = {}} = this;
1036
+ const [showingRect, selectedRect] = CommonToolUtils.getRenderResultList(this.rectList, CommonToolUtils.getSourceID(this.basicResult), this.attributeLockList, this.selectedRectID);
1037
+ if (!this.isHidden) {
1038
+ showingRect == null ? void 0 : showingRect.forEach((rect) => {
1039
+ this.renderDrawingRect(rect);
1040
+ if (renderEnhance.staticRender) {
1041
+ renderEnhance.staticRender(this.canvas, AxisUtils.changeRectByZoom(rect, this.zoom, this.currentPos), this.getRenderStyle(rect));
1042
+ }
1043
+ });
1044
+ }
1045
+ if (selectedRect) {
1046
+ this.renderDrawingRect(selectedRect);
1047
+ this.renderSelectedRect(selectedRect);
1048
+ if (renderEnhance.selectedRender) {
1049
+ renderEnhance.selectedRender(this.canvas, AxisUtils.changeRectByZoom(selectedRect, this.zoom, this.currentPos), this.getRenderStyle(selectedRect));
1050
+ }
1051
+ }
1052
+ }
1053
+ renderCreatingRect() {
1054
+ if (!this.drawingRect) {
1055
+ return;
1056
+ }
1057
+ const {renderEnhance = {}} = this;
1058
+ this.renderDrawingRect(this.drawingRect, 1, true);
1059
+ if (renderEnhance.creatingRender) {
1060
+ renderEnhance.creatingRender(this.canvas, AxisUtils.changeRectByZoom(this.drawingRect, 1, this.currentPos), this.getRenderStyle(this.drawingRect));
1061
+ }
1062
+ }
1063
+ renderRect() {
1064
+ this.renderStaticRect();
1065
+ this.renderCreatingRect();
1066
+ }
1067
+ render() {
1068
+ if (!this.ctx) {
1069
+ return;
1070
+ }
1071
+ super.render();
1072
+ this.renderRect();
1073
+ this.renderCursorLine(this.getLineColor(this.defaultAttribute));
1074
+ }
1075
+ setDefaultAttribute(defaultAttribute) {
1076
+ const oldDefault = this.defaultAttribute;
1077
+ this.defaultAttribute = defaultAttribute != null ? defaultAttribute : "";
1078
+ if (oldDefault !== defaultAttribute) {
1079
+ this.changeStyle(defaultAttribute);
1080
+ this.emit("changeAttributeSidebar");
1081
+ const {selectedRect} = this;
1082
+ if (selectedRect) {
1083
+ this.setRectList(this.rectList.map((v) => {
1084
+ if (v.id === this.selectedID) {
1085
+ return __spreadProps(__spreadValues({}, v), {
1086
+ attribute: this.defaultAttribute
1087
+ });
1088
+ }
1089
+ return v;
1090
+ }), true);
1091
+ this.history.pushHistory(this.rectList);
1092
+ this.render();
1093
+ }
1094
+ if (this.drawingRect) {
1095
+ this.drawingRect = __spreadProps(__spreadValues({}, this.drawingRect), {
1096
+ attribute: this.defaultAttribute
1097
+ });
1098
+ this.render();
1099
+ }
1100
+ if (this._textAttributInstance) {
1101
+ if (this.attributeLockList.length > 0 && !this.attributeLockList.includes(this.defaultAttribute)) {
1102
+ this._textAttributInstance.clearTextAttribute();
1103
+ return;
1104
+ }
1105
+ this._textAttributInstance.updateIcon(this.getTextIconSvg(defaultAttribute));
1106
+ }
1107
+ }
1108
+ }
1109
+ setValid(valid) {
1110
+ super.setValid(valid);
1111
+ this.emit("updateResult");
1112
+ }
1113
+ clearActiveStatus() {
1114
+ this.drawingRect = void 0;
1115
+ this.firstClickCoord = void 0;
1116
+ this.dragInfo = void 0;
1117
+ this.dragStatus = EDragStatus.Wait;
1118
+ this.setSelectedRectID(void 0);
1119
+ }
1120
+ clearResult(sendMessage = true) {
1121
+ const newRectList = this.rectList.filter((rect) => rect.disableDelete === true);
1122
+ if (newRectList.length > 0 && sendMessage) {
1123
+ this.emit("messageInfo", Locale.getMessagesByLocale(EMessage.ClearPartialData, this.lang));
1124
+ }
1125
+ this.setRectList(newRectList, true);
1126
+ this.setSelectedRectID(void 0);
1127
+ }
1128
+ deleteRect(rectID) {
1129
+ var _a;
1130
+ if (!rectID) {
1131
+ return;
1132
+ }
1133
+ const selectedRect = this.rectList.find((v) => v.id === rectID);
1134
+ if ((selectedRect == null ? void 0 : selectedRect.disableDelete) === true) {
1135
+ this.emit("messageInfo", Locale.getMessagesByLocale(EMessage.DisableDelete, this.lang));
1136
+ return;
1137
+ }
1138
+ this.setRectList(this.rectList.filter((v) => v.id !== rectID), true);
1139
+ this.history.pushHistory(this.rectList);
1140
+ this.setSelectedRectID(void 0);
1141
+ (_a = this._textAttributInstance) == null ? void 0 : _a.clearTextAttribute();
1142
+ this.render();
1143
+ }
1144
+ exportData() {
1145
+ const {rectList} = this;
1146
+ return [rectList, this.basicImgInfo];
1147
+ }
1148
+ undo() {
1149
+ const rectList = this.history.undo();
1150
+ if (rectList) {
1151
+ if (rectList.length !== this.rectList.length) {
1152
+ this.setSelectedRectID("");
1153
+ }
1154
+ this.setRectList(rectList, true);
1155
+ this.render();
1156
+ }
1157
+ }
1158
+ redo() {
1159
+ const rectList = this.history.redo();
1160
+ if (rectList) {
1161
+ if (rectList.length !== this.rectList.length) {
1162
+ this.setSelectedRectID("");
1163
+ }
1164
+ this.setRectList(rectList, true);
1165
+ this.render();
1166
+ }
1167
+ }
1168
+ }
1169
+
1170
+ export { RectOperation, RectOperation as default };