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

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