@labelbee/lb-annotation 1.13.0-alpha.7 → 1.14.0-alpha.0

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 (59) hide show
  1. package/dist/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -0
  2. package/dist/assets/attributeIcon/icon_cuboidLeft.svg.js +7 -0
  3. package/dist/assets/attributeIcon/icon_cuboidMore.svg.js +5 -0
  4. package/dist/assets/attributeIcon/icon_cuboidRight.svg.js +5 -0
  5. package/dist/assets/attributeIcon/icon_cuboidTop.svg.js +12 -0
  6. package/dist/constant/annotation.js +1 -1
  7. package/dist/constant/tool.js +1 -1
  8. package/dist/core/pointCloud/annotation.js +1 -1
  9. package/dist/core/pointCloud/index.js +2 -2
  10. package/dist/core/scheduler.js +1 -1
  11. package/dist/core/toolOperation/ViewOperation.js +1 -1
  12. package/dist/core/toolOperation/basicToolOperation.js +1 -1
  13. package/dist/core/toolOperation/cuboidOperation.js +1 -0
  14. package/dist/core/toolOperation/cuboidToggleButtonClass.js +31 -0
  15. package/dist/types/constant/annotation.d.ts +45 -1
  16. package/dist/types/constant/tool.d.ts +6 -1
  17. package/dist/types/core/index.d.ts +1 -2
  18. package/dist/types/core/pointCloud/annotation.d.ts +11 -1
  19. package/dist/types/core/pointCloud/index.d.ts +11 -1
  20. package/dist/types/core/pointCloud/matrix.d.ts +1 -0
  21. package/dist/types/core/scheduler.d.ts +7 -2
  22. package/dist/types/core/toolOperation/ViewOperation.d.ts +3 -2
  23. package/dist/types/core/toolOperation/basicToolOperation.d.ts +11 -1
  24. package/dist/types/core/toolOperation/cuboidOperation.d.ts +155 -0
  25. package/dist/types/core/toolOperation/cuboidToggleButtonClass.d.ts +38 -0
  26. package/dist/types/utils/MathUtils.d.ts +1 -1
  27. package/dist/types/utils/tool/AttributeUtils.d.ts +7 -0
  28. package/dist/types/utils/tool/AxisUtils.d.ts +50 -1
  29. package/dist/types/utils/tool/CuboidUtils.d.ts +267 -0
  30. package/dist/types/utils/tool/DrawUtils.d.ts +12 -0
  31. package/dist/types/utils/tool/EnhanceCommonToolUtils.d.ts +4 -2
  32. package/dist/types/utils/tool/PolygonUtils.d.ts +5 -2
  33. package/dist/utils/MathUtils.js +2 -2
  34. package/dist/utils/tool/AttributeUtils.js +1 -1
  35. package/dist/utils/tool/AxisUtils.js +1 -1
  36. package/dist/utils/tool/CuboidUtils.js +1 -0
  37. package/dist/utils/tool/DrawUtils.js +3 -3
  38. package/dist/utils/tool/EnhanceCommonToolUtils.js +1 -1
  39. package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -3
  40. package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +7 -3
  41. package/es/assets/attributeIcon/icon_cuboidMore.svg.js +5 -3
  42. package/es/assets/attributeIcon/icon_cuboidRight.svg.js +5 -3
  43. package/es/assets/attributeIcon/icon_cuboidTop.svg.js +12 -3
  44. package/es/constant/annotation.js +1 -1
  45. package/es/constant/tool.js +1 -1
  46. package/es/core/pointCloud/annotation.js +1 -1
  47. package/es/core/pointCloud/index.js +2 -2
  48. package/es/core/scheduler.js +1 -1
  49. package/es/core/toolOperation/ViewOperation.js +1 -1
  50. package/es/core/toolOperation/basicToolOperation.js +1 -1
  51. package/es/core/toolOperation/cuboidOperation.js +1 -733
  52. package/es/core/toolOperation/cuboidToggleButtonClass.js +7 -150
  53. package/es/utils/MathUtils.js +2 -2
  54. package/es/utils/tool/AttributeUtils.js +1 -1
  55. package/es/utils/tool/AxisUtils.js +1 -1
  56. package/es/utils/tool/CuboidUtils.js +1 -663
  57. package/es/utils/tool/DrawUtils.js +3 -3
  58. package/es/utils/tool/EnhanceCommonToolUtils.js +1 -1
  59. package/package.json +3 -3
@@ -1,733 +1 @@
1
- import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
2
- import AxisUtils from '../../utils/tool/AxisUtils.js';
3
- import uuid from '../../utils/uuid.js';
4
- import { getCuboidHoverRange, getPlainPointsByDiagonalPoints, getPointsByBottomRightPoint, getCuboidDragMove, isCuboidWithInLimits, getHighlightPoints, getCuboidTextAttributeOffset, getToggleDirectionButtonOffset } from '../../utils/tool/CuboidUtils.js';
5
- import PolygonUtils from '../../utils/tool/PolygonUtils.js';
6
- import { EDragStatus, EDragTarget, ECuboidDirection } from '../../constant/annotation.js';
7
- import AttributeUtils from '../../utils/tool/AttributeUtils.js';
8
- import { DEFAULT_TEXT_MAX_WIDTH } from '../../constant/tool.js';
9
- import EKeyCode from '../../constant/keyCode.js';
10
- import { BasicToolOperation } from './basicToolOperation.js';
11
- import DrawUtils from '../../utils/tool/DrawUtils.js';
12
- import CuboidToggleButtonClass from './cuboidToggleButtonClass.js';
13
- import TextAttributeClass from './textAttributeClass.js';
14
- import Locale from '../../locales/index.js';
15
- import { EMessage } from '../../locales/constants.js';
16
-
17
- var __defProp = Object.defineProperty;
18
- var __defProps = Object.defineProperties;
19
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
20
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
21
- var __hasOwnProp = Object.prototype.hasOwnProperty;
22
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
23
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
24
- var __spreadValues = (a, b) => {
25
- for (var prop in b || (b = {}))
26
- if (__hasOwnProp.call(b, prop))
27
- __defNormalProp(a, prop, b[prop]);
28
- if (__getOwnPropSymbols)
29
- for (var prop of __getOwnPropSymbols(b)) {
30
- if (__propIsEnum.call(b, prop))
31
- __defNormalProp(a, prop, b[prop]);
32
- }
33
- return a;
34
- };
35
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
36
- var EDrawingStatus;
37
- (function(EDrawingStatus2) {
38
- EDrawingStatus2[EDrawingStatus2["Ready"] = 1] = "Ready";
39
- EDrawingStatus2[EDrawingStatus2["FirstPoint"] = 2] = "FirstPoint";
40
- EDrawingStatus2[EDrawingStatus2["Cuboid"] = 3] = "Cuboid";
41
- })(EDrawingStatus || (EDrawingStatus = {}));
42
- const TEXT_MAX_WIDTH = 164;
43
- class CuboidOperation extends BasicToolOperation {
44
- constructor(props) {
45
- super(props);
46
- this.drawingStatus = 1;
47
- this.cuboidList = [];
48
- this.hoverID = "";
49
- this.getHoverData = (e) => {
50
- const coordinate = this.getCoordinateUnderZoom(e);
51
- const {currentShowList} = this;
52
- if ((currentShowList == null ? void 0 : currentShowList.length) > 0) {
53
- const polygonList = currentShowList.map((cuboid) => {
54
- return {id: cuboid.id, pointList: AxisUtils.changePointListByZoom(getCuboidHoverRange(cuboid), this.zoom)};
55
- });
56
- const hoverID = PolygonUtils.getHoverPolygonID(coordinate, polygonList);
57
- if (hoverID) {
58
- return {
59
- hoverID,
60
- hoverCuboid: currentShowList.find((cuboid) => cuboid.id === hoverID)
61
- };
62
- }
63
- }
64
- return {};
65
- };
66
- this.textChange = (v) => {
67
- if (this.config.textConfigurable === false || !this.selectedID) {
68
- return;
69
- }
70
- this.setCuboidList(AttributeUtils.textChange(v, this.selectedID, this.cuboidList));
71
- this.emit("selectedChange");
72
- this.render();
73
- };
74
- this.config = CommonToolUtils.jsonParser(props.config);
75
- this.getCurrentSelectedData = this.getCurrentSelectedData.bind(this);
76
- this.updateSelectedTextAttribute = this.updateSelectedTextAttribute.bind(this);
77
- }
78
- destroy() {
79
- super.destroy();
80
- if (this._textAttributeInstance) {
81
- this._textAttributeInstance.clearTextAttribute();
82
- }
83
- }
84
- get currentShowList() {
85
- let cuboidList = [];
86
- const [showingCuboid, selectedCuboid] = CommonToolUtils.getRenderResultList(this.cuboidList, CommonToolUtils.getSourceID(this.basicResult), this.attributeLockList, this.selectedID);
87
- cuboidList = showingCuboid;
88
- if (this.isHidden) {
89
- cuboidList = [];
90
- }
91
- if (selectedCuboid) {
92
- cuboidList.push(selectedCuboid);
93
- }
94
- return cuboidList;
95
- }
96
- get selectedCuboid() {
97
- return this.cuboidList.find((v) => v.id === this.selectedID);
98
- }
99
- get dataList() {
100
- return this.cuboidList;
101
- }
102
- get isNeedCheckCuboidSize() {
103
- var _a, _b;
104
- return ((_a = this.config) == null ? void 0 : _a.minWidth) >= 0 && ((_b = this.config) == null ? void 0 : _b.minHeight) >= 0;
105
- }
106
- getIsHoverSelectedCuboid(e) {
107
- const currentCoord = this.getCoordinateUnderZoom(e);
108
- const {selectedCuboid} = this;
109
- return selectedCuboid && AxisUtils.isCloseCuboid(currentCoord, AxisUtils.changeCuboidByZoom(selectedCuboid, this.zoom));
110
- }
111
- isForbiddenMove(e, cuboid) {
112
- const coord = this.getCoordinateInOrigin(e);
113
- if (coord.y > cuboid.frontPoints.br.y) {
114
- return true;
115
- }
116
- return false;
117
- }
118
- updateSelectedCuboid(newCuboid) {
119
- this.cuboidList = this.cuboidList.map((cuboid) => {
120
- if (cuboid.id === this.selectedID) {
121
- return newCuboid;
122
- }
123
- return cuboid;
124
- });
125
- }
126
- getColorToRender(attribute, valid) {
127
- const toolColor = this.getColor(attribute);
128
- const strokeColor = valid ? toolColor == null ? void 0 : toolColor.valid.stroke : toolColor == null ? void 0 : toolColor.invalid.stroke;
129
- const fillColor = valid ? toolColor == null ? void 0 : toolColor.valid.fill : toolColor == null ? void 0 : toolColor.invalid.fill;
130
- return {strokeColor, toolColor, fillColor};
131
- }
132
- getCurrentSelectedData() {
133
- const {selectedCuboid} = this;
134
- if (!selectedCuboid) {
135
- return;
136
- }
137
- const {strokeColor: color} = this.getColorToRender(selectedCuboid.attribute, selectedCuboid.valid);
138
- return {
139
- width: TEXT_MAX_WIDTH,
140
- textAttribute: selectedCuboid.textAttribute,
141
- color
142
- };
143
- }
144
- updateSelectedTextAttribute(newTextAttribute) {
145
- if (this._textAttributeInstance && newTextAttribute && this.selectedID) {
146
- let textAttribute = newTextAttribute;
147
- if (AttributeUtils.textAttributeValidate(this.config.textCheckType, "", textAttribute) === false) {
148
- this.emit("messageError", AttributeUtils.getErrorNotice(this.config.textCheckType, this.lang));
149
- textAttribute = "";
150
- }
151
- this.setCuboidList(AttributeUtils.textChange(textAttribute, this.selectedID, this.cuboidList));
152
- this.history.pushHistory(this.cuboidList);
153
- this.emit("updateTextAttribute");
154
- this.render();
155
- }
156
- }
157
- setResult(cuboidList) {
158
- this.clearDrawingStatus();
159
- this.setCuboidList(cuboidList);
160
- this.render();
161
- }
162
- clearResult() {
163
- this.setCuboidList([], true);
164
- this.setSelectedID(void 0);
165
- }
166
- exportData() {
167
- const {cuboidList} = this;
168
- return [cuboidList, this.basicImgInfo];
169
- }
170
- setSelectedID(newID) {
171
- var _a, _b;
172
- const oldID = this.selectedID;
173
- if (newID !== oldID && oldID) {
174
- (_a = this._textAttributeInstance) == null ? void 0 : _a.changeSelected();
175
- }
176
- if (!newID) {
177
- (_b = this._textAttributeInstance) == null ? void 0 : _b.clearTextAttribute();
178
- }
179
- this.selectedID = newID;
180
- this.emit("selectedChange");
181
- }
182
- setSelectedIDAndRender(newID) {
183
- this.setSelectedID(newID);
184
- this.render();
185
- }
186
- setCuboidValidAndRender(id) {
187
- if (!id) {
188
- return;
189
- }
190
- const newPolygonList = this.cuboidList.map((cuboid) => {
191
- if (cuboid.id === id) {
192
- return __spreadProps(__spreadValues({}, cuboid), {
193
- valid: !cuboid.valid
194
- });
195
- }
196
- return cuboid;
197
- });
198
- this.setCuboidList(newPolygonList, true);
199
- this.history.pushHistory(this.cuboidList);
200
- this.render();
201
- }
202
- onRightDblClick(e) {
203
- super.onRightDblClick(e);
204
- const {hoverID} = this.getHoverData(e);
205
- if (this.selectedID && this.selectedID === hoverID) {
206
- this.deleteCuboid(hoverID);
207
- }
208
- }
209
- setCuboidList(cuboidList, isUpload = false) {
210
- const oldLen = this.cuboidList.length;
211
- this.cuboidList = cuboidList;
212
- if (oldLen !== cuboidList.length) {
213
- this.emit("updatePageNumber");
214
- }
215
- if (isUpload) {
216
- this.emit("updateResult");
217
- }
218
- }
219
- deleteCuboid(id) {
220
- var _a;
221
- if (!id) {
222
- return;
223
- }
224
- this.setCuboidList(this.cuboidList.filter((v) => v.id !== id));
225
- this.history.pushHistory(this.cuboidList);
226
- this.setSelectedID("");
227
- (_a = this._textAttributeInstance) == null ? void 0 : _a.clearTextAttribute();
228
- this.render();
229
- }
230
- onKeyDown(e) {
231
- if (!CommonToolUtils.hotkeyFilter(e)) {
232
- return;
233
- }
234
- if (super.onKeyDown(e) === false) {
235
- return;
236
- }
237
- const {keyCode} = e;
238
- switch (keyCode) {
239
- case EKeyCode.Ctrl:
240
- if (this.drawingCuboid) {
241
- this.drawingCuboid = __spreadProps(__spreadValues({}, this.drawingCuboid), {
242
- valid: false
243
- });
244
- this.render();
245
- }
246
- break;
247
- case EKeyCode.F:
248
- if (this.selectedID) {
249
- this.setCuboidValidAndRender(this.selectedID);
250
- }
251
- break;
252
- default: {
253
- if (this.config.attributeConfigurable) {
254
- const keyCode2Attribute = AttributeUtils.getAttributeByKeycode(keyCode, this.config.attributeList);
255
- if (keyCode2Attribute !== void 0) {
256
- this.setDefaultAttribute(keyCode2Attribute);
257
- }
258
- }
259
- }
260
- }
261
- }
262
- onKeyUp(e) {
263
- super.onKeyUp(e);
264
- switch (e.keyCode) {
265
- case EKeyCode.Ctrl:
266
- if (this.drawingCuboid) {
267
- this.drawingCuboid = __spreadProps(__spreadValues({}, this.drawingCuboid), {
268
- valid: true
269
- });
270
- this.render();
271
- }
272
- break;
273
- }
274
- }
275
- onMouseDown(e) {
276
- if (super.onMouseDown(e) || this.forbidMouseOperation || e.ctrlKey === true) {
277
- return;
278
- }
279
- const {selectedCuboid} = this;
280
- if (!selectedCuboid || e.button === 2 || e.button === 0 && this.isSpaceKey === true) {
281
- return;
282
- }
283
- if (!this.getIsHoverSelectedCuboid(e)) {
284
- return;
285
- }
286
- this.dragStatus = EDragStatus.Start;
287
- const dragStartCoord = this.getCoordinateUnderZoom(e);
288
- const DEFAULT_DRAG_INFO = {
289
- initCuboid: selectedCuboid,
290
- dragStartCoord
291
- };
292
- const highlightInfo = AxisUtils.returnClosePointOrLineInCuboid(dragStartCoord, AxisUtils.changeCuboidByZoom(selectedCuboid, this.zoom));
293
- const firstHighlightInfo = highlightInfo == null ? void 0 : highlightInfo[0];
294
- switch (firstHighlightInfo == null ? void 0 : firstHighlightInfo.type) {
295
- case "point":
296
- this.dragInfo = __spreadProps(__spreadValues({}, DEFAULT_DRAG_INFO), {
297
- dragTarget: EDragTarget.Point,
298
- positions: firstHighlightInfo.positions
299
- });
300
- break;
301
- case "line":
302
- this.dragInfo = __spreadProps(__spreadValues({}, DEFAULT_DRAG_INFO), {
303
- dragTarget: EDragTarget.Line,
304
- positions: firstHighlightInfo.positions
305
- });
306
- break;
307
- default: {
308
- this.dragInfo = __spreadProps(__spreadValues({}, DEFAULT_DRAG_INFO), {
309
- dragTarget: EDragTarget.Cuboid
310
- });
311
- }
312
- }
313
- }
314
- onMouseUp(e) {
315
- if (super.onMouseUp(e) || this.forbidMouseOperation || !this.imgInfo) {
316
- return void 0;
317
- }
318
- if (this.dragInfo && this.dragStatus === EDragStatus.Move) {
319
- this.dragInfo = void 0;
320
- this.dragStatus = EDragStatus.Wait;
321
- this.history.pushHistory(this.cuboidList);
322
- this.emit("updateResult");
323
- return;
324
- }
325
- const basicSourceID = CommonToolUtils.getSourceID(this.basicResult);
326
- if (e.button === 0) {
327
- if (this.hoverID && e.ctrlKey && !this.drawingCuboid) {
328
- this.setCuboidValidAndRender(this.hoverID);
329
- return;
330
- }
331
- if (!this.drawingCuboid) {
332
- this.createNewDrawingCuboid(e, basicSourceID);
333
- return;
334
- }
335
- if (this.drawingCuboid) {
336
- switch (this.drawingStatus) {
337
- case 2:
338
- this.closeNewDrawingFrontPlane();
339
- break;
340
- case 3:
341
- this.closeAndCreateNewCuboid();
342
- break;
343
- }
344
- }
345
- }
346
- if (e.button === 2) {
347
- this.rightMouseUp(e);
348
- }
349
- }
350
- onMouseMove(e) {
351
- var _a;
352
- if (super.onMouseMove(e) || this.forbidMouseOperation || !this.imgInfo) {
353
- return;
354
- }
355
- if (this.selectedID && this.dragInfo) {
356
- this.onDragMove(e);
357
- return;
358
- }
359
- if (this.drawingCuboid) {
360
- if (this.drawingFrontPlanesMove(e)) {
361
- return;
362
- }
363
- this.drawingBackPlaneMove(e);
364
- return;
365
- }
366
- this.hoverID = (_a = this.getHoverData(e).hoverID) != null ? _a : "";
367
- this.onHoverMove(e);
368
- }
369
- drawingFrontPlanesMove(e) {
370
- if (this.drawingCuboid && this.firstClickCoord && this.drawingStatus === 2) {
371
- const coord = this.getCoordinateInOrigin(e);
372
- this.drawingCuboid = __spreadProps(__spreadValues({}, this.drawingCuboid), {
373
- frontPoints: getPlainPointsByDiagonalPoints(this.firstClickCoord, coord)
374
- });
375
- this.render();
376
- return true;
377
- }
378
- }
379
- drawingBackPlaneMove(e) {
380
- if (this.drawingCuboid && this.firstClickCoord && this.drawingStatus === 3) {
381
- const coord = this.getCoordinateInOrigin(e);
382
- if (this.isForbiddenMove(e, this.drawingCuboid)) {
383
- return;
384
- }
385
- this.drawingCuboid = __spreadProps(__spreadValues({}, this.drawingCuboid), {
386
- backPoints: getPointsByBottomRightPoint({coord, points: this.drawingCuboid.frontPoints})
387
- });
388
- this.render();
389
- }
390
- }
391
- onDragMove(e) {
392
- if (!this.dragInfo || !this.selectedID) {
393
- return;
394
- }
395
- const {dragTarget, initCuboid, dragStartCoord, positions} = this.dragInfo;
396
- const coordinate = this.getCoordinateUnderZoom(e);
397
- const offset = {
398
- x: (coordinate.x - dragStartCoord.x) / this.zoom,
399
- y: (coordinate.y - dragStartCoord.y) / this.zoom
400
- };
401
- this.dragStatus = EDragStatus.Move;
402
- const newCuboid = getCuboidDragMove({offset, cuboid: initCuboid, dragTarget, positions});
403
- if ((newCuboid == null ? void 0 : newCuboid.backPoints) && (newCuboid == null ? void 0 : newCuboid.backPoints.br.y) > (newCuboid == null ? void 0 : newCuboid.frontPoints.br.y)) {
404
- return;
405
- }
406
- if (newCuboid) {
407
- this.updateSelectedCuboid(newCuboid);
408
- }
409
- this.render();
410
- }
411
- onHoverMove(e) {
412
- const {selectedCuboid} = this;
413
- if (selectedCuboid) {
414
- const currentCoord = this.getCoordinateUnderZoom(e);
415
- const highlightInfo = AxisUtils.returnClosePointOrLineInCuboid(currentCoord, AxisUtils.changeCuboidByZoom(selectedCuboid, this.zoom), {
416
- zoom: 1 / this.zoom,
417
- scope: 5
418
- });
419
- this.highlightInfo = highlightInfo;
420
- this.render();
421
- }
422
- }
423
- createNewDrawingCuboid(e, basicSourceID) {
424
- if (!this.imgInfo) {
425
- return;
426
- }
427
- const coordinate = this.getCoordinateInOrigin(e);
428
- this.drawingCuboid = {
429
- attribute: this.defaultAttribute,
430
- direction: ECuboidDirection.Front,
431
- valid: !e.ctrlKey,
432
- id: uuid(8, 62),
433
- sourceID: basicSourceID,
434
- textAttribute: "",
435
- order: CommonToolUtils.getMaxOrder(this.cuboidList.filter((v) => CommonToolUtils.isSameSourceID(v.sourceID, basicSourceID))) + 1,
436
- frontPoints: {
437
- tl: coordinate,
438
- bl: coordinate,
439
- tr: coordinate,
440
- br: coordinate
441
- }
442
- };
443
- this.firstClickCoord = __spreadValues({}, coordinate);
444
- this.drawingStatus = 2;
445
- }
446
- closeNewDrawingFrontPlane() {
447
- this.drawingStatus = 3;
448
- }
449
- closeAndCreateNewCuboid() {
450
- var _a, _b;
451
- if (!((_a = this.drawingCuboid) == null ? void 0 : _a.frontPoints) || !this.drawingCuboid.backPoints) {
452
- return;
453
- }
454
- if (this.isNeedCheckCuboidSize && isCuboidWithInLimits({cuboid: this.drawingCuboid, config: this.config}) === false) {
455
- this.emit("messageInfo", Locale.getMessagesByLocale(EMessage.RectErrorSizeNotice, this.lang));
456
- } else {
457
- this.setCuboidList([...this.cuboidList, this.drawingCuboid]);
458
- this.setSelectedID((_b = this.drawingCuboid) == null ? void 0 : _b.id);
459
- this.history.pushHistory(this.cuboidList);
460
- }
461
- this.clearDrawingStatus();
462
- this.render();
463
- }
464
- clearDrawingStatus() {
465
- if (this.drawingCuboid) {
466
- this.drawingCuboid = void 0;
467
- this.drawingStatus = 1;
468
- }
469
- }
470
- rightMouseUp(e) {
471
- const {hoverID, hoverCuboid} = this.getHoverData(e);
472
- this.setSelectedID(hoverID);
473
- if (hoverCuboid) {
474
- this.setDefaultAttribute(hoverCuboid.attribute);
475
- }
476
- if (this.drawingCuboid) {
477
- this.clearDrawingStatus();
478
- }
479
- this.render();
480
- }
481
- renderSingleCuboid(cuboid) {
482
- var _a, _b, _c, _d;
483
- const transformCuboid = AxisUtils.changeCuboidByZoom(cuboid, this.zoom, this.currentPos);
484
- const isHover = transformCuboid.id === this.hoverID;
485
- const isSelected = transformCuboid.id === this.selectedID;
486
- const {strokeColor, fillColor} = this.getColorToRender(transformCuboid.attribute, transformCuboid.valid);
487
- const textColor = strokeColor;
488
- const lineWidth = (_b = (_a = this.style) == null ? void 0 : _a.width) != null ? _b : 2;
489
- const {hiddenText = false} = this.style;
490
- const defaultStyle = {
491
- color: strokeColor,
492
- thickness: lineWidth
493
- };
494
- const {backPoints, frontPoints, textAttribute} = transformCuboid;
495
- const frontPointsSizeWidth = frontPoints.br.x - frontPoints.bl.x;
496
- DrawUtils.drawCuboid(this.canvas, transformCuboid, {strokeColor, fillColor, thickness: lineWidth});
497
- if (isHover || isSelected) {
498
- const hoverPointList = getHighlightPoints(transformCuboid);
499
- hoverPointList.forEach((data) => {
500
- DrawUtils.drawCircleWithFill(this.canvas, data.point, 5, __spreadValues({}, defaultStyle));
501
- });
502
- if (isSelected) {
503
- hoverPointList.forEach((data) => {
504
- DrawUtils.drawCircleWithFill(this.canvas, data.point, 3, {color: "white"});
505
- });
506
- }
507
- }
508
- let showText = "";
509
- if (((_c = this.config) == null ? void 0 : _c.isShowOrder) && transformCuboid.order && (transformCuboid == null ? void 0 : transformCuboid.order) > 0) {
510
- showText = `${transformCuboid.order}`;
511
- }
512
- if (transformCuboid.attribute) {
513
- showText = `${showText} ${AttributeUtils.getAttributeShowText(transformCuboid.attribute, (_d = this.config) == null ? void 0 : _d.attributeList)}`;
514
- }
515
- if (!hiddenText && backPoints) {
516
- DrawUtils.drawText(this.canvas, {x: backPoints.tl.x, y: backPoints.tl.y - 5}, showText, {
517
- color: strokeColor,
518
- textMaxWidth: 300
519
- });
520
- }
521
- const textPosition = getCuboidTextAttributeOffset({
522
- cuboid,
523
- currentPos: this.currentPos,
524
- zoom: this.zoom,
525
- topOffset: 16,
526
- leftOffset: 0
527
- });
528
- if (!hiddenText && textAttribute && cuboid.id !== this.selectedID) {
529
- const textWidth = Math.max(20, frontPointsSizeWidth * 0.8);
530
- DrawUtils.drawText(this.canvas, {x: textPosition.left, y: textPosition.top}, textAttribute, {
531
- color: textColor,
532
- textMaxWidth: textWidth
533
- });
534
- }
535
- this.renderTextAttribute();
536
- }
537
- setDefaultAttribute(defaultAttribute) {
538
- const oldDefault = this.defaultAttribute;
539
- this.defaultAttribute = defaultAttribute != null ? defaultAttribute : "";
540
- if (oldDefault !== defaultAttribute) {
541
- this.changeStyle(defaultAttribute);
542
- this.emit("changeAttributeSidebar");
543
- const {selectedCuboid} = this;
544
- if (selectedCuboid) {
545
- this.setCuboidList(this.cuboidList.map((v) => {
546
- if (v.id === this.selectedID) {
547
- return __spreadProps(__spreadValues({}, v), {
548
- attribute: this.defaultAttribute
549
- });
550
- }
551
- return v;
552
- }));
553
- this.history.pushHistory(this.cuboidList);
554
- this.render();
555
- }
556
- if (this.drawingCuboid) {
557
- this.drawingCuboid = __spreadProps(__spreadValues({}, this.drawingCuboid), {
558
- attribute: this.defaultAttribute
559
- });
560
- this.render();
561
- }
562
- if (this._textAttributeInstance) {
563
- if (this.attributeLockList.length > 0 && !this.attributeLockList.includes(this.defaultAttribute)) {
564
- this._textAttributeInstance.clearTextAttribute();
565
- return;
566
- }
567
- this._textAttributeInstance.updateIcon(this.getTextIconSvg(defaultAttribute));
568
- }
569
- }
570
- }
571
- renderToggleButton() {
572
- const {selectedCuboid} = this;
573
- if (!this.ctx || this.config.textConfigurable !== true || !selectedCuboid) {
574
- return;
575
- }
576
- const {attribute, valid} = selectedCuboid;
577
- const {strokeColor: color} = this.getColorToRender(attribute, valid);
578
- if (!this.toggleButtonInstance) {
579
- this.toggleButtonInstance = new CuboidToggleButtonClass({
580
- container: this.container,
581
- cuboidButtonMove: (type) => this.updateMouseOperation(type),
582
- toggleDirection: (direction) => this.toggleDirection(direction)
583
- });
584
- }
585
- const toggleOffset = getToggleDirectionButtonOffset({
586
- cuboid: selectedCuboid,
587
- zoom: this.zoom,
588
- currentPos: this.currentPos
589
- });
590
- this.toggleButtonInstance.update({
591
- left: toggleOffset.left,
592
- top: toggleOffset.top,
593
- color
594
- });
595
- }
596
- renderTextAttribute() {
597
- var _a;
598
- const {selectedCuboid} = this;
599
- if (!this.ctx || this.config.textConfigurable === false || !selectedCuboid) {
600
- return;
601
- }
602
- const {strokeColor: color} = this.getColorToRender(selectedCuboid.attribute, selectedCuboid.valid);
603
- const {attribute, textAttribute, frontPoints} = selectedCuboid;
604
- const offset = getCuboidTextAttributeOffset({
605
- cuboid: selectedCuboid,
606
- currentPos: this.currentPos,
607
- zoom: this.zoom
608
- });
609
- const newWidth = (frontPoints.br.x - frontPoints.bl.x) * this.zoom * 0.8;
610
- if (!this._textAttributeInstance) {
611
- this._textAttributeInstance = new TextAttributeClass({
612
- width: DEFAULT_TEXT_MAX_WIDTH,
613
- container: this.container,
614
- icon: this.getTextIconSvg(attribute),
615
- color,
616
- getCurrentSelectedData: this.getCurrentSelectedData,
617
- updateSelectedTextAttribute: this.updateSelectedTextAttribute
618
- });
619
- }
620
- if (this._textAttributeInstance && !((_a = this._textAttributeInstance) == null ? void 0 : _a.isExit)) {
621
- this._textAttributeInstance.appendToContainer();
622
- }
623
- this._textAttributeInstance.update(`${textAttribute}`, {
624
- left: offset.left,
625
- top: offset.top,
626
- color,
627
- width: newWidth
628
- });
629
- }
630
- renderDrawing() {
631
- if (this.drawingCuboid) {
632
- this.renderSingleCuboid(this.drawingCuboid);
633
- }
634
- }
635
- renderStatic() {
636
- this.cuboidList.forEach((cuboid) => this.renderSingleCuboid(cuboid));
637
- }
638
- renderSelected() {
639
- var _a;
640
- const {selectedCuboid} = this;
641
- if (selectedCuboid) {
642
- this.renderSingleCuboid(selectedCuboid);
643
- this.renderToggleButton();
644
- } else {
645
- (_a = this.toggleButtonInstance) == null ? void 0 : _a.clearCuboidButtonDOM();
646
- this.toggleButtonInstance = void 0;
647
- }
648
- }
649
- updateMouseOperation(type) {
650
- if (type === "in") {
651
- this.setForbidCursorLine(true);
652
- this.setForbidOperation(true);
653
- this.setShowDefaultCursor(true);
654
- } else {
655
- this.setForbidCursorLine(false);
656
- this.setShowDefaultCursor(false);
657
- this.setForbidOperation(false);
658
- }
659
- }
660
- toggleDirection(direction) {
661
- if (this.cuboidList && this.selectedCuboid) {
662
- this.setCuboidList(this.cuboidList.map((i) => {
663
- var _a;
664
- return i.id === ((_a = this.selectedCuboid) == null ? void 0 : _a.id) ? __spreadProps(__spreadValues({}, i), {direction}) : i;
665
- }));
666
- this.history.pushHistory(this.cuboidList);
667
- this.render();
668
- }
669
- }
670
- renderHover() {
671
- var _a;
672
- if (this.dragInfo) {
673
- return;
674
- }
675
- (_a = this.highlightInfo) == null ? void 0 : _a.forEach((data) => {
676
- var _a2, _b;
677
- const {strokeColor} = this.getColorToRender(data.originCuboid.attribute, data.originCuboid.valid);
678
- const thickness = 8;
679
- switch (data.type) {
680
- case "point":
681
- (_a2 = data.points) == null ? void 0 : _a2.forEach((point) => {
682
- DrawUtils.drawCircleWithFill(this.canvas, AxisUtils.changePointByZoom(point, this.zoom, this.currentPos), thickness, {
683
- color: strokeColor
684
- });
685
- });
686
- break;
687
- case "line": {
688
- const pointList = (_b = data.points) == null ? void 0 : _b.map((point) => AxisUtils.changePointByZoom(point, this.zoom, this.currentPos));
689
- if (pointList) {
690
- DrawUtils.drawLineWithPointList(this.canvas, pointList, {color: strokeColor, thickness});
691
- }
692
- break;
693
- }
694
- }
695
- });
696
- }
697
- renderCuboid() {
698
- this.renderStatic();
699
- this.renderDrawing();
700
- this.renderSelected();
701
- this.renderHover();
702
- }
703
- render() {
704
- if (!this.ctx) {
705
- return;
706
- }
707
- super.render();
708
- this.renderCuboid();
709
- this.renderCursorLine(this.getLineColor(this.defaultAttribute));
710
- }
711
- undo() {
712
- const cuboidList = this.history.undo();
713
- if (cuboidList) {
714
- if (cuboidList.length !== this.cuboidList.length) {
715
- this.setSelectedID("");
716
- }
717
- this.setCuboidList(cuboidList, true);
718
- this.render();
719
- }
720
- }
721
- redo() {
722
- const cuboidList = this.history.redo();
723
- if (cuboidList) {
724
- if (cuboidList.length !== this.cuboidList.length) {
725
- this.setSelectedID("");
726
- }
727
- this.setCuboidList(cuboidList, true);
728
- this.render();
729
- }
730
- }
731
- }
732
-
733
- export { CuboidOperation as default };
1
+ import c from"../../utils/tool/CommonToolUtils.js";import l from"../../utils/tool/AxisUtils.js";import H from"../../utils/uuid.js";import{getCuboidHoverRange as U,getPlainPointsByDiagonalPoints as z,getPointsByBottomRightPoint as F,getCuboidDragMove as j,isCuboidWithInLimits as E,getHighlightPoints as W,getCuboidTextAttributeOffset as A,getToggleDirectionButtonOffset as N}from"../../utils/tool/CuboidUtils.js";import Z from"../../utils/tool/PolygonUtils.js";import{EDragStatus as v,EDragTarget as w,ECuboidDirection as K}from"../../constant/annotation.js";import g from"../../utils/tool/AttributeUtils.js";import{DEFAULT_TEXT_MAX_WIDTH as V}from"../../constant/tool.js";import D from"../../constant/keyCode.js";import{BasicToolOperation as X}from"./basicToolOperation.js";import b from"../../utils/tool/DrawUtils.js";import $ from"./cuboidToggleButtonClass.js";import G from"./textAttributeClass.js";import q from"../../locales/index.js";import{EMessage as J}from"../../locales/constants.js";var Q=Object.defineProperty,Y=Object.defineProperties,tt=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,et=Object.prototype.propertyIsEnumerable,T=(n,t,i)=>t in n?Q(n,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):n[t]=i,u=(n,t)=>{for(var i in t||(t={}))it.call(t,i)&&T(n,i,t[i]);if(_)for(var i of _(t))et.call(t,i)&&T(n,i,t[i]);return n},a=(n,t)=>Y(n,tt(t)),k;(function(n){n[n.Ready=1]="Ready",n[n.FirstPoint=2]="FirstPoint",n[n.Cuboid=3]="Cuboid"})(k||(k={}));const ot=164;class st extends X{constructor(t){super(t);this.drawingStatus=1,this.cuboidList=[],this.hoverID="",this.getHoverData=i=>{const e=this.getCoordinateUnderZoom(i),{currentShowList:s}=this;if((s==null?void 0:s.length)>0){const r=s.map(d=>({id:d.id,pointList:l.changePointListByZoom(U(d),this.zoom)})),o=Z.getHoverPolygonID(e,r);if(o)return{hoverID:o,hoverCuboid:s.find(d=>d.id===o)}}return{}},this.textChange=i=>{this.config.textConfigurable===!1||!this.selectedID||(this.setCuboidList(g.textChange(i,this.selectedID,this.cuboidList)),this.emit("selectedChange"),this.render())},this.config=c.jsonParser(t.config),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}get currentShowList(){let t=[];const[i,e]=c.getRenderResultList(this.cuboidList,c.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=i,this.isHidden&&(t=[]),e&&t.push(e),t}get selectedCuboid(){return this.cuboidList.find(t=>t.id===this.selectedID)}get dataList(){return this.cuboidList}get isNeedCheckCuboidSize(){var t,i;return((t=this.config)==null?void 0:t.minWidth)>=0&&((i=this.config)==null?void 0:i.minHeight)>=0}getIsHoverSelectedCuboid(t){const i=this.getCoordinateUnderZoom(t),{selectedCuboid:e}=this;return e&&l.isCloseCuboid(i,l.changeCuboidByZoom(e,this.zoom))}isForbiddenMove(t,i){return this.getCoordinateInOrigin(t).y>i.frontPoints.br.y}updateSelectedCuboid(t){this.cuboidList=this.cuboidList.map(i=>i.id===this.selectedID?t:i)}getColorToRender(t,i){const e=this.getColor(t),s=i?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke,r=i?e==null?void 0:e.valid.fill:e==null?void 0:e.invalid.fill;return{strokeColor:s,toolColor:e,fillColor:r}}getCurrentSelectedData(){const{selectedCuboid:t}=this;if(!t)return;const{strokeColor:i}=this.getColorToRender(t.attribute,t.valid);return{width:ot,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let i=t;g.textAttributeValidate(this.config.textCheckType,"",i)===!1&&(this.emit("messageError",g.getErrorNotice(this.config.textCheckType,this.lang)),i=""),this.setCuboidList(g.textChange(i,this.selectedID,this.cuboidList)),this.history.pushHistory(this.cuboidList),this.emit("updateTextAttribute"),this.render()}}setResult(t){this.clearDrawingStatus(),this.setCuboidList(t),this.render()}get currentPageResult(){return this.cuboidList}clearResult(){this.setCuboidList([],!0),this.setSelectedID(void 0)}exportData(){const{cuboidList:t}=this;return[t,this.basicImgInfo]}setSelectedID(t){var i,e;const s=this.selectedID;t!==s&&s&&((i=this._textAttributeInstance)==null||i.changeSelected()),t||(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.selectedID=t,this.emit("selectedChange")}setSelectedIDAndRender(t){this.setSelectedID(t),this.render()}setCuboidValidAndRender(t){if(!t)return;const i=this.cuboidList.map(e=>e.id===t?a(u({},e),{valid:!e.valid}):e);this.setCuboidList(i,!0),this.history.pushHistory(this.cuboidList),this.render()}onRightDblClick(t){super.onRightDblClick(t);const{hoverID:i}=this.getHoverData(t);this.selectedID&&this.selectedID===i&&this.deleteCuboid(i)}setCuboidList(t,i=!1){const e=this.cuboidList.length;this.cuboidList=t,e!==t.length&&this.emit("updatePageNumber"),i&&this.emit("updateResult")}deleteCuboid(t){var i;!t||(this.setCuboidList(this.cuboidList.filter(e=>e.id!==t)),this.history.pushHistory(this.cuboidList),this.setSelectedID(""),(i=this._textAttributeInstance)==null||i.clearTextAttribute(),this.render())}onKeyDown(t){if(!c.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:i}=t;switch(i){case D.Ctrl:this.drawingCuboid&&(this.drawingCuboid=a(u({},this.drawingCuboid),{valid:!1}),this.render());break;case D.F:this.selectedID&&this.setCuboidValidAndRender(this.selectedID);break;default:if(this.config.attributeConfigurable){const e=g.getAttributeByKeycode(i,this.config.attributeList);e!==void 0&&this.setDefaultAttribute(e)}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case D.Ctrl:this.drawingCuboid&&(this.drawingCuboid=a(u({},this.drawingCuboid),{valid:!0}),this.render());break}}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const{selectedCuboid:i}=this;if(!i||t.button===2||t.button===0&&this.isSpaceKey===!0||!this.getIsHoverSelectedCuboid(t))return;this.dragStatus=v.Start;const e=this.getCoordinateUnderZoom(t),s={initCuboid:i,dragStartCoord:e},r=l.returnClosePointOrLineInCuboid(e,l.changeCuboidByZoom(i,this.zoom)),o=r==null?void 0:r[0];switch(o==null?void 0:o.type){case"point":this.dragInfo=a(u({},s),{dragTarget:w.Point,positions:o.positions});break;case"line":this.dragInfo=a(u({},s),{dragTarget:w.Line,positions:o.positions});break;default:this.dragInfo=a(u({},s),{dragTarget:w.Cuboid})}}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.dragInfo&&this.dragStatus===v.Move){this.dragInfo=void 0,this.dragStatus=v.Wait,this.history.pushHistory(this.cuboidList),this.emit("updateResult");return}const i=c.getSourceID(this.basicResult);if(t.button===0){if(this.hoverID&&t.ctrlKey&&!this.drawingCuboid){this.setCuboidValidAndRender(this.hoverID);return}if(!this.drawingCuboid){this.createNewDrawingCuboid(t,i);return}if(this.drawingCuboid)switch(this.drawingStatus){case 2:this.closeNewDrawingFrontPlane();break;case 3:this.closeAndCreateNewCuboid();break}}t.button===2&&this.rightMouseUp(t)}onMouseMove(t){var i;if(!(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.selectedID&&this.dragInfo){this.onDragMove(t);return}if(this.drawingCuboid){if(this.drawingFrontPlanesMove(t))return;this.drawingBackPlaneMove(t);return}this.hoverID=(i=this.getHoverData(t).hoverID)!=null?i:"",this.onHoverMove(t)}}drawingFrontPlanesMove(t){if(this.drawingCuboid&&this.firstClickCoord&&this.drawingStatus===2){const i=this.getCoordinateInOrigin(t);return this.drawingCuboid=a(u({},this.drawingCuboid),{frontPoints:z(this.firstClickCoord,i)}),this.render(),!0}}drawingBackPlaneMove(t){if(this.drawingCuboid&&this.firstClickCoord&&this.drawingStatus===3){const i=this.getCoordinateInOrigin(t);if(this.isForbiddenMove(t,this.drawingCuboid))return;this.drawingCuboid=a(u({},this.drawingCuboid),{backPoints:F({coord:i,points:this.drawingCuboid.frontPoints})}),this.render()}}onDragMove(t){if(!this.dragInfo||!this.selectedID)return;const{dragTarget:i,initCuboid:e,dragStartCoord:s,positions:r}=this.dragInfo,o=this.getCoordinateUnderZoom(t),d={x:(o.x-s.x)/this.zoom,y:(o.y-s.y)/this.zoom};this.dragStatus=v.Move;const h=j({offset:d,cuboid:e,dragTarget:i,positions:r});(h==null?void 0:h.backPoints)&&(h==null?void 0:h.backPoints.br.y)>(h==null?void 0:h.frontPoints.br.y)||(h&&this.updateSelectedCuboid(h),this.render())}onHoverMove(t){const{selectedCuboid:i}=this;if(i){const e=this.getCoordinateUnderZoom(t),s=l.returnClosePointOrLineInCuboid(e,l.changeCuboidByZoom(i,this.zoom),{zoom:1/this.zoom,scope:5});this.highlightInfo=s,this.render()}}createNewDrawingCuboid(t,i){if(!this.imgInfo)return;const e=this.getCoordinateInOrigin(t);this.drawingCuboid={attribute:this.defaultAttribute,direction:K.Front,valid:!t.ctrlKey,id:H(8,62),sourceID:i,textAttribute:"",order:c.getMaxOrder(this.cuboidList.filter(s=>c.isSameSourceID(s.sourceID,i)))+1,frontPoints:{tl:e,bl:e,tr:e,br:e}},this.firstClickCoord=u({},e),this.drawingStatus=2}closeNewDrawingFrontPlane(){this.drawingStatus=3}closeAndCreateNewCuboid(){var t,i;!((t=this.drawingCuboid)==null?void 0:t.frontPoints)||!this.drawingCuboid.backPoints||(this.isNeedCheckCuboidSize&&E({cuboid:this.drawingCuboid,config:this.config})===!1?this.emit("messageInfo",q.getMessagesByLocale(J.RectErrorSizeNotice,this.lang)):(this.setCuboidList([...this.cuboidList,this.drawingCuboid]),this.setSelectedID((i=this.drawingCuboid)==null?void 0:i.id),this.history.pushHistory(this.cuboidList)),this.clearDrawingStatus(),this.render())}clearDrawingStatus(){this.drawingCuboid&&(this.drawingCuboid=void 0,this.drawingStatus=1)}rightMouseUp(t){const{hoverID:i,hoverCuboid:e}=this.getHoverData(t);this.setSelectedID(i),e&&this.setDefaultAttribute(e.attribute),this.drawingCuboid&&this.clearDrawingStatus(),this.render()}renderSingleCuboid(t){var i,e,s,r;const o=l.changeCuboidByZoom(t,this.zoom,this.currentPos),d=o.id===this.hoverID,h=o.id===this.selectedID,{strokeColor:f,fillColor:M}=this.getColorToRender(o.attribute,o.valid),O=f,x=(e=(i=this.style)==null?void 0:i.width)!=null?e:2,{hiddenText:y=!1}=this.style,B={color:f,thickness:x},{backPoints:m,frontPoints:L,textAttribute:S}=o,R=L.br.x-L.bl.x;if(b.drawCuboid(this.canvas,o,{strokeColor:f,fillColor:M,thickness:x}),d||h){const p=W(o);p.forEach(I=>{b.drawCircleWithFill(this.canvas,I.point,5,u({},B))}),h&&p.forEach(I=>{b.drawCircleWithFill(this.canvas,I.point,3,{color:"white"})})}let C="";((s=this.config)==null?void 0:s.isShowOrder)&&o.order&&(o==null?void 0:o.order)>0&&(C=`${o.order}`),o.attribute&&(C=`${C} ${g.getAttributeShowText(o.attribute,(r=this.config)==null?void 0:r.attributeList)}`),!y&&m&&b.drawText(this.canvas,{x:m.tl.x,y:m.tl.y-5},C,{color:f,textMaxWidth:300});const P=A({cuboid:t,currentPos:this.currentPos,zoom:this.zoom,topOffset:16,leftOffset:0});if(!y&&S&&t.id!==this.selectedID){const p=Math.max(20,R*.8);b.drawText(this.canvas,{x:P.left,y:P.top},S,{color:O,textMaxWidth:p})}this.renderTextAttribute()}setDefaultAttribute(t){const i=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",i!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedCuboid:e}=this;if(e&&(this.setCuboidList(this.cuboidList.map(s=>s.id===this.selectedID?a(u({},s),{attribute:this.defaultAttribute}):s)),this.history.pushHistory(this.cuboidList),this.render()),this.drawingCuboid&&(this.drawingCuboid=a(u({},this.drawingCuboid),{attribute:this.defaultAttribute}),this.render()),this._textAttributeInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}}renderToggleButton(){const{selectedCuboid:t}=this;if(!this.ctx||this.config.textConfigurable!==!0||!t)return;const{attribute:i,valid:e}=t,{strokeColor:s}=this.getColorToRender(i,e);this.toggleButtonInstance||(this.toggleButtonInstance=new $({container:this.container,cuboidButtonMove:o=>this.updateMouseOperation(o),toggleDirection:o=>this.toggleDirection(o)}));const r=N({cuboid:t,zoom:this.zoom,currentPos:this.currentPos});this.toggleButtonInstance.update({left:r.left,top:r.top,color:s})}renderTextAttribute(){var t;const{selectedCuboid:i}=this;if(!this.ctx||this.config.textConfigurable===!1||!i)return;const{strokeColor:e}=this.getColorToRender(i.attribute,i.valid),{attribute:s,textAttribute:r,frontPoints:o}=i,d=A({cuboid:i,currentPos:this.currentPos,zoom:this.zoom}),h=(o.br.x-o.bl.x)*this.zoom*.8;this._textAttributeInstance||(this._textAttributeInstance=new G({width:V,container:this.container,icon:this.getTextIconSvg(s),color:e,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${r}`,{left:d.left,top:d.top,color:e,width:h})}renderDrawing(){this.drawingCuboid&&this.renderSingleCuboid(this.drawingCuboid)}renderStatic(){this.cuboidList.forEach(t=>this.renderSingleCuboid(t))}renderSelected(){var t;const{selectedCuboid:i}=this;i?(this.renderSingleCuboid(i),this.renderToggleButton()):((t=this.toggleButtonInstance)==null||t.clearCuboidButtonDOM(),this.toggleButtonInstance=void 0)}updateMouseOperation(t){t==="in"?(this.setForbidCursorLine(!0),this.setForbidOperation(!0),this.setShowDefaultCursor(!0)):(this.setForbidCursorLine(!1),this.setShowDefaultCursor(!1),this.setForbidOperation(!1))}toggleDirection(t){this.cuboidList&&this.selectedCuboid&&(this.setCuboidList(this.cuboidList.map(i=>{var e;return i.id===((e=this.selectedCuboid)==null?void 0:e.id)?a(u({},i),{direction:t}):i})),this.history.pushHistory(this.cuboidList),this.render())}renderHover(){var t;this.dragInfo||(t=this.highlightInfo)==null||t.forEach(i=>{var e,s;const{strokeColor:r}=this.getColorToRender(i.originCuboid.attribute,i.originCuboid.valid),o=8;switch(i.type){case"point":(e=i.points)==null||e.forEach(d=>{b.drawCircleWithFill(this.canvas,l.changePointByZoom(d,this.zoom,this.currentPos),o,{color:r})});break;case"line":{const d=(s=i.points)==null?void 0:s.map(h=>l.changePointByZoom(h,this.zoom,this.currentPos));d&&b.drawLineWithPointList(this.canvas,d,{color:r,thickness:o});break}}})}renderCuboid(){this.renderStatic(),this.renderDrawing(),this.renderSelected(),this.renderHover()}render(){!this.ctx||(super.render(),this.renderCuboid(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}undo(){const t=this.history.undo();t&&(t.length!==this.cuboidList.length&&this.setSelectedID(""),this.setCuboidList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.cuboidList.length&&this.setSelectedID(""),this.setCuboidList(t,!0),this.render())}}export{st as default};