@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,881 +1 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var lbUtils = require('@labelbee/lb-utils');
6
- var _ = require('lodash');
7
- var tool = require('../../constant/tool.js');
8
- var MathUtils = require('../../utils/MathUtils.js');
9
- var AxisUtils = require('../../utils/tool/AxisUtils.js');
10
- var CanvasUtils = require('../../utils/tool/CanvasUtils.js');
11
- var CommonToolUtils = require('../../utils/tool/CommonToolUtils.js');
12
- var LineToolUtils = require('../../utils/tool/LineToolUtils.js');
13
- var annotation = require('../../constant/annotation.js');
14
- var keyCode = require('../../constant/keyCode.js');
15
- var style = require('../../constant/style.js');
16
- var index = require('../../locales/index.js');
17
- var constants = require('../../locales/constants.js');
18
- var ActionsHistory = require('../../utils/ActionsHistory.js');
19
- var AttributeUtils = require('../../utils/tool/AttributeUtils.js');
20
- var DblClickEventListener = require('../../utils/tool/DblClickEventListener.js');
21
- var DrawUtils = require('../../utils/tool/DrawUtils.js');
22
- var ImgPosUtils = require('../../utils/tool/ImgPosUtils.js');
23
- var RenderDomUtils = require('../../utils/tool/RenderDomUtils.js');
24
- var ZoomUtils = require('../../utils/tool/ZoomUtils.js');
25
- var eventListener = require('./eventListener.js');
26
-
27
- var __defProp = Object.defineProperty;
28
- var __defProps = Object.defineProperties;
29
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
30
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
31
- var __hasOwnProp = Object.prototype.hasOwnProperty;
32
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
33
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
34
- var __spreadValues = (a, b) => {
35
- for (var prop in b || (b = {}))
36
- if (__hasOwnProp.call(b, prop))
37
- __defNormalProp(a, prop, b[prop]);
38
- if (__getOwnPropSymbols)
39
- for (var prop of __getOwnPropSymbols(b)) {
40
- if (__propIsEnum.call(b, prop))
41
- __defNormalProp(a, prop, b[prop]);
42
- }
43
- return a;
44
- };
45
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
46
- var __async = (__this, __arguments, generator) => {
47
- return new Promise((resolve, reject) => {
48
- var fulfilled = (value) => {
49
- try {
50
- step(generator.next(value));
51
- } catch (e) {
52
- reject(e);
53
- }
54
- };
55
- var rejected = (value) => {
56
- try {
57
- step(generator.throw(value));
58
- } catch (e) {
59
- reject(e);
60
- }
61
- };
62
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
63
- step((generator = generator.apply(__this, __arguments)).next());
64
- });
65
- };
66
- const zoomInfo = {
67
- min: 0.2,
68
- max: 1e3,
69
- ratio: 0.4
70
- };
71
- class BasicToolOperation extends eventListener {
72
- constructor(props) {
73
- super();
74
- this.isDrag = false;
75
- this.isSpaceKey = false;
76
- this.operationMode = tool.EOperationMode.General;
77
- this.innerZoom = 1;
78
- this.basicZoom = 0.01;
79
- this.isSpaceClick = false;
80
- this.isDragStart = false;
81
- this.startTime = 0;
82
- this.initImgPos = () => __async(this, null, function* () {
83
- var _a, _b;
84
- if (!this.imgNode) {
85
- return;
86
- }
87
- const zoomRatio = (_a = this._imgAttribute) == null ? void 0 : _a.zoomRatio;
88
- const isOriginalSize = (_b = this._imgAttribute) == null ? void 0 : _b.isOriginalSize;
89
- const {currentPos, imgInfo, zoom} = ImgPosUtils.getInitImgPos(this.size, {width: this.imgNode.width, height: this.imgNode.height}, this.rotate, zoomRatio, isOriginalSize);
90
- this.setCurrentPos(currentPos);
91
- this.currentPosStorage = currentPos;
92
- this.setImgInfo(imgInfo);
93
- this.setZoom(zoom);
94
- this.render();
95
- this.renderBasicCanvas();
96
- this.emit("dependRender");
97
- this.emit("renderZoom", zoom, currentPos, imgInfo);
98
- });
99
- this.getCurrentPos = (coord) => {
100
- const {_firstClickCoordinate, currentPosStorage} = this;
101
- try {
102
- let currentPos;
103
- if (_firstClickCoordinate && currentPosStorage) {
104
- currentPos = {
105
- y: currentPosStorage.y + coord.y - _firstClickCoordinate.y,
106
- x: currentPosStorage.x + coord.x - _firstClickCoordinate.x
107
- };
108
- } else {
109
- currentPos = {
110
- x: 0,
111
- y: 0
112
- };
113
- }
114
- return currentPos;
115
- } catch (e) {
116
- console.error(e);
117
- return {
118
- x: 0,
119
- y: 0
120
- };
121
- }
122
- };
123
- this.wheelChangePos = (coord, operator, newZoom) => {
124
- const {currentPos, imgNode} = this;
125
- if (!imgNode) {
126
- console.error("unable to load image");
127
- return;
128
- }
129
- if (this.zoom === this.basicZoom && operator === -1) {
130
- return;
131
- }
132
- const pos = ZoomUtils.wheelChangePos(imgNode, coord, operator, currentPos, {
133
- zoom: newZoom || this.zoom,
134
- innerZoom: this.innerZoom,
135
- basicZoom: this.basicZoom,
136
- zoomMax: zoomInfo.max,
137
- rotate: this.rotate
138
- });
139
- if (!pos) {
140
- return;
141
- }
142
- const {currentPos: newCurrentPos, ratio, zoom, imgInfo} = pos;
143
- this.setZoom(zoom);
144
- this.setCurrentPos(newCurrentPos);
145
- this.currentPosStorage = newCurrentPos;
146
- this.setImgInfo(imgInfo);
147
- zoomInfo.ratio = ratio;
148
- this.emit("renderZoom", zoom, newCurrentPos, imgInfo);
149
- };
150
- this.zoomChanged = (isZoomIn, growthMode = annotation.EGrowthMode.Linear) => {
151
- const newZoom = ZoomUtils.zoomChanged(this.zoom, isZoomIn, growthMode);
152
- this.wheelChangePos(this.getGetCenterCoordinate(), newZoom > this.zoom ? 1 : -1, newZoom);
153
- this.render();
154
- this.renderBasicCanvas();
155
- };
156
- this.zoomChangeOnCenter = (newZoom) => {
157
- this.wheelChangePos(this.getGetCenterCoordinate(), 0, newZoom);
158
- this.render();
159
- this.renderBasicCanvas();
160
- };
161
- this.drawImg = () => {
162
- if (!this.imgNode || this.hiddenImg === true)
163
- return;
164
- DrawUtils.drawImg(this.basicCanvas, this.imgNode, {
165
- zoom: this.zoom,
166
- currentPos: this.currentPos,
167
- rotate: this.rotate,
168
- imgAttribute: this._imgAttribute
169
- });
170
- };
171
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
172
- this.container = props.container;
173
- this.config = CommonToolUtils.jsonParser(props.config);
174
- this.showDefaultCursor = props.showDefaultCursor || false;
175
- this.destroyCanvas();
176
- this.createCanvas(props.size, props.isAppend);
177
- this.imgNode = props.imgNode;
178
- this.isImgError = !props.imgNode;
179
- this.basicImgInfo = {
180
- width: (_b = (_a = props.imgNode) == null ? void 0 : _a.width) != null ? _b : 0,
181
- height: (_d = (_c = props.imgNode) == null ? void 0 : _c.height) != null ? _d : 0,
182
- valid: true,
183
- rotate: 0
184
- };
185
- this.forbidOperation = (_e = props.forbidOperation) != null ? _e : false;
186
- this.forbidBasicResultRender = (_f = props.forbidBasicResultRender) != null ? _f : false;
187
- this.size = props.size;
188
- this.currentPos = {
189
- x: 0,
190
- y: 0
191
- };
192
- this.zoom = 1;
193
- this.coord = {
194
- x: -1,
195
- y: -1
196
- };
197
- this.currentPosStorage = {
198
- x: 0,
199
- y: 0
200
- };
201
- this.isShowCursor = false;
202
- this.style = {
203
- strokeColor: style.COLORS_ARRAY[4],
204
- fillColor: style.COLORS_ARRAY[4],
205
- strokeWidth: 2,
206
- opacity: 1
207
- };
208
- this.attributeLockList = [];
209
- this.history = new ActionsHistory();
210
- this.style = (_g = props.style) != null ? _g : CommonToolUtils.jsonParser(style.styleString);
211
- this._imgAttribute = (_h = props.imgAttribute) != null ? _h : {};
212
- this.isHidden = false;
213
- this.dragStatus = annotation.EDragStatus.Wait;
214
- this.defaultAttribute = (_i = props == null ? void 0 : props.defaultAttribute) != null ? _i : "";
215
- this.forbidCursorLine = !!props.forbidCursorLine;
216
- this.lang = annotation.ELang.Zh;
217
- this.onMouseDown = this.onMouseDown.bind(this);
218
- this.onMouseMove = this.onMouseMove.bind(this);
219
- this.onMouseLeave = this.onMouseLeave.bind(this);
220
- this.onMouseUp = this.onMouseUp.bind(this);
221
- this.onKeyDown = this.onKeyDown.bind(this);
222
- this.onKeyUp = this.onKeyUp.bind(this);
223
- this.onWheel = this.onWheel.bind(this);
224
- this.onLeftDblClick = this.onLeftDblClick.bind(this);
225
- this.onRightDblClick = this.onRightDblClick.bind(this);
226
- this.onClick = this.onClick.bind(this);
227
- this.clearImgDrag = this.clearImgDrag.bind(this);
228
- this.dblClickListener = new DblClickEventListener(this.container, 200);
229
- this.coordUtils = new AxisUtils.CoordinateUtils(this);
230
- this.coordUtils.setBasicImgInfo(this.basicImgInfo);
231
- this.hiddenImg = props.hiddenImg || false;
232
- }
233
- onContextmenu(e) {
234
- e.preventDefault();
235
- }
236
- get ctx() {
237
- var _a;
238
- return this._ctx || ((_a = this.canvas) == null ? void 0 : _a.getContext("2d"));
239
- }
240
- get basicCtx() {
241
- var _a;
242
- return (_a = this.basicCanvas) == null ? void 0 : _a.getContext("2d");
243
- }
244
- get rotate() {
245
- var _a, _b;
246
- return (_b = (_a = this.basicImgInfo) == null ? void 0 : _a.rotate) != null ? _b : 0;
247
- }
248
- get valid() {
249
- var _a, _b;
250
- return (_b = (_a = this.basicImgInfo) == null ? void 0 : _a.valid) != null ? _b : true;
251
- }
252
- get baseIcon() {
253
- return style.BASE_ICON[this.style.color];
254
- }
255
- get defaultCursor() {
256
- return this.showDefaultCursor ? "default" : "none";
257
- }
258
- get dataList() {
259
- return [];
260
- }
261
- get innerPosAndZoom() {
262
- return {
263
- innerZoom: this.innerZoom,
264
- currentPosStorage: this.currentPosStorage
265
- };
266
- }
267
- get isShowDefaultCursor() {
268
- return this.showDefaultCursor;
269
- }
270
- get isMultiMoveMode() {
271
- return this.operationMode === tool.EOperationMode.MultiMove;
272
- }
273
- get hasMarkerConfig() {
274
- return this.config.markerConfigurable === true && this.config.markerList && this.config.markerList.length > 0;
275
- }
276
- setZoom(zoom) {
277
- this.zoom = zoom;
278
- this.innerZoom = zoom;
279
- this.coordUtils.setZoomAndCurrentPos(this.zoom, this.currentPos);
280
- }
281
- setCurrentPos(currentPos) {
282
- this.currentPos = currentPos;
283
- this.coordUtils.setZoomAndCurrentPos(this.zoom, this.currentPos);
284
- }
285
- setReferenceData(referenceData) {
286
- this.referenceData = referenceData;
287
- }
288
- setImgInfo(size) {
289
- this.imgInfo = size;
290
- }
291
- setCurrentPosStorage(currentPosStorage) {
292
- this.currentPosStorage = currentPosStorage;
293
- }
294
- setOperationMode(operationMode) {
295
- this.operationMode = operationMode;
296
- }
297
- recoverOperationMode() {
298
- if (this.operationMode === tool.EOperationMode.MultiMove) {
299
- this.setOperationMode(tool.EOperationMode.General);
300
- }
301
- }
302
- updatePosition(params) {
303
- const {zoom, currentPos} = params;
304
- this.setZoom(zoom);
305
- this.setCurrentPos(currentPos);
306
- this.currentPosStorage = currentPos;
307
- this.renderBasicCanvas();
308
- this.render();
309
- }
310
- setLang(lang) {
311
- this.lang = lang;
312
- }
313
- setShowDefaultCursor(showDefaultCursor) {
314
- this.showDefaultCursor = showDefaultCursor;
315
- this.container.style.cursor = this.defaultCursor;
316
- }
317
- setCustomCursor(cursor) {
318
- this.container.style.cursor = cursor;
319
- }
320
- get forbidMouseOperation() {
321
- return this.forbidOperation || this.valid === false;
322
- }
323
- get pixelRatio() {
324
- var _a;
325
- return CanvasUtils.getPixelRatio((_a = this.canvas) == null ? void 0 : _a.getContext("2d"));
326
- }
327
- init() {
328
- this.eventUnbinding();
329
- this.initPosition();
330
- this.eventBinding();
331
- this.render();
332
- this.renderBasicCanvas();
333
- }
334
- destroy() {
335
- this.destroyCanvas();
336
- this.eventUnbinding();
337
- }
338
- updateCanvasBasicStyle(canvas, size, zIndex) {
339
- const pixel = this.pixelRatio;
340
- canvas.style.position = "absolute";
341
- canvas.width = size.width * pixel;
342
- canvas.height = size.height * pixel;
343
- canvas.style.width = `${size.width}px`;
344
- canvas.style.height = `${size.height}px`;
345
- canvas.style.left = "0";
346
- canvas.style.top = "0";
347
- canvas.style.zIndex = `${zIndex} `;
348
- }
349
- createCanvas(size, isAppend = true) {
350
- var _a, _b;
351
- const pixel = this.pixelRatio;
352
- const basicCanvas = document.createElement("canvas");
353
- this.updateCanvasBasicStyle(basicCanvas, size, 0);
354
- this.basicCanvas = basicCanvas;
355
- const canvas = document.createElement("canvas");
356
- this.updateCanvasBasicStyle(canvas, size, 10);
357
- if (isAppend) {
358
- if (this.container.hasChildNodes()) {
359
- this.container.insertBefore(canvas, this.container.childNodes[0]);
360
- this.container.insertBefore(basicCanvas, this.container.childNodes[0]);
361
- } else {
362
- this.container.appendChild(basicCanvas);
363
- this.container.appendChild(canvas);
364
- }
365
- }
366
- this.canvas = canvas;
367
- this.container.style.cursor = this.defaultCursor;
368
- (_a = this.ctx) == null ? void 0 : _a.scale(pixel, pixel);
369
- (_b = this.basicCtx) == null ? void 0 : _b.scale(pixel, pixel);
370
- }
371
- destroyCanvas() {
372
- if (this.canvas && this.container.contains(this.canvas)) {
373
- this.container.removeChild(this.canvas);
374
- }
375
- if (this.basicCanvas && this.container.contains(this.basicCanvas)) {
376
- this.container.removeChild(this.basicCanvas);
377
- }
378
- this.clearInvalidPage();
379
- this.clearImgDrag();
380
- }
381
- setStyle(toolStyle) {
382
- this.style = toolStyle;
383
- this.render();
384
- }
385
- setImgNode(imgNode, basicImgInfo = {}) {
386
- this.imgNode = imgNode;
387
- this.setBasicImgInfo(__spreadValues({
388
- width: imgNode.width,
389
- height: imgNode.height,
390
- valid: true,
391
- rotate: 0
392
- }, basicImgInfo));
393
- if (this.isImgError === true) {
394
- this.isImgError = false;
395
- this.emit("changeAnnotationShow");
396
- }
397
- if (typeof basicImgInfo.valid === "boolean") {
398
- this.setValid(basicImgInfo.valid);
399
- }
400
- this.initImgPos();
401
- this.render();
402
- this.renderBasicCanvas();
403
- }
404
- setErrorImg() {
405
- const originIsImgError = this.isImgError;
406
- this.isImgError = true;
407
- this.imgNode = void 0;
408
- this.setBasicImgInfo({
409
- width: 0,
410
- height: 0,
411
- valid: true,
412
- rotate: 0
413
- });
414
- if (originIsImgError === false) {
415
- this.emit("changeAnnotationShow");
416
- }
417
- }
418
- setBasicImgInfo(basicImgInfo) {
419
- this.basicImgInfo = basicImgInfo;
420
- this.coordUtils.setBasicImgInfo(basicImgInfo);
421
- }
422
- setForbidOperation(forbidOperation) {
423
- this.forbidOperation = forbidOperation;
424
- this.setShowDefaultCursor(forbidOperation);
425
- this.render();
426
- }
427
- setForbidCursorLine(forbidCursorLine) {
428
- this.forbidCursorLine = forbidCursorLine;
429
- this.render();
430
- }
431
- setIsHidden(isHidden) {
432
- this.isHidden = isHidden;
433
- this.emit("hiddenChange");
434
- }
435
- setDefaultAttribute(attribute) {
436
- this.defaultAttribute = attribute;
437
- }
438
- getCoordinateInOrigin(e) {
439
- const bounding = this.canvas.getBoundingClientRect();
440
- return {
441
- x: (e.clientX - bounding.left - this.currentPos.x) / this.zoom,
442
- y: (e.clientY - bounding.top - this.currentPos.y) / this.zoom
443
- };
444
- }
445
- getTextIconSvg(attribute = "") {
446
- var _a;
447
- return AttributeUtils["default"].getTextIconSvg(attribute, (_a = this.config) == null ? void 0 : _a.attributeList, this.config.attributeConfigurable, this.baseIcon);
448
- }
449
- setIsShowOrder(isShowOrder) {
450
- this.config.isShowOrder = isShowOrder;
451
- this.render();
452
- }
453
- getCoordinate(e) {
454
- const bounding = this.canvas.getBoundingClientRect();
455
- return {
456
- x: e.clientX - bounding.left,
457
- y: e.clientY - bounding.top
458
- };
459
- }
460
- getCoordinateUnderZoom(e) {
461
- const bounding = this.canvas.getBoundingClientRect();
462
- return {
463
- x: e.clientX - bounding.left - this.currentPos.x,
464
- y: e.clientY - bounding.top - this.currentPos.y
465
- };
466
- }
467
- getCoordinateUnderZoomByRotate(e) {
468
- const {x, y} = this.getCoordinateUnderZoom(e);
469
- if (this.basicImgInfo.rotate === 90) {
470
- return {
471
- x: y,
472
- y: this.basicImgInfo.height * this.zoom - x
473
- };
474
- }
475
- if (this.basicImgInfo.rotate === 180) {
476
- return {
477
- x: this.basicImgInfo.width * this.zoom - x,
478
- y: this.basicImgInfo.height * this.zoom - y
479
- };
480
- }
481
- if (this.basicImgInfo.rotate === 270) {
482
- return {
483
- x: this.basicImgInfo.width * this.zoom - y,
484
- y: x
485
- };
486
- }
487
- return {
488
- x,
489
- y
490
- };
491
- }
492
- getGetCenterCoordinate() {
493
- return {
494
- x: this.size.width / 2,
495
- y: this.size.height / 2
496
- };
497
- }
498
- initPosition() {
499
- if (this.basicResult && this.imgInfo) {
500
- const {basicResult, size, imgNode, _imgAttribute, imgInfo, dependToolName} = this;
501
- if (basicResult && imgNode && dependToolName) {
502
- let newBoundry = basicResult;
503
- switch (dependToolName) {
504
- case tool.EToolName.Polygon:
505
- case tool.EToolName.Line: {
506
- if (basicResult.pointList) {
507
- const basicZone = MathUtils["default"].calcViewportBoundaries(basicResult.pointList);
508
- newBoundry = {
509
- x: basicZone.left,
510
- y: basicZone.top,
511
- width: basicZone.right - basicZone.left,
512
- height: basicZone.bottom - basicZone.top
513
- };
514
- }
515
- break;
516
- }
517
- }
518
- const pos = ImgPosUtils.getBasicRecPos(imgNode, newBoundry, size, void 0, _imgAttribute == null ? void 0 : _imgAttribute.zoomRatio, _imgAttribute == null ? void 0 : _imgAttribute.isOriginalSize);
519
- if (pos) {
520
- this.setCurrentPos(pos.currentPos);
521
- this.currentPosStorage = this.currentPos;
522
- this.setImgInfo(__spreadProps(__spreadValues({}, imgInfo), {
523
- width: imgInfo.width / this.innerZoom * pos.innerZoom,
524
- height: imgInfo.height / this.innerZoom * pos.innerZoom
525
- }));
526
- this.setZoom(pos.innerZoom);
527
- this.render();
528
- this.renderBasicCanvas();
529
- }
530
- }
531
- } else {
532
- this.initImgPos();
533
- }
534
- }
535
- undo() {
536
- this.history.undo();
537
- }
538
- redo() {
539
- this.history.redo();
540
- }
541
- clearCanvas() {
542
- var _a;
543
- (_a = this.ctx) == null ? void 0 : _a.clearRect(0, 0, this.size.width, this.size.height);
544
- }
545
- clearBasicCanvas() {
546
- var _a;
547
- (_a = this.basicCtx) == null ? void 0 : _a.clearRect(0, 0, this.size.width, this.size.height);
548
- }
549
- eventBinding() {
550
- this.dblClickListener.addEvent(() => {
551
- }, this.onLeftDblClick, this.onRightDblClick);
552
- this.container.addEventListener("mousedown", this.onMouseDown);
553
- this.container.addEventListener("mousemove", this.onMouseMove);
554
- this.container.addEventListener("mouseup", this.onMouseUp);
555
- this.container.addEventListener("mouseleave", this.onMouseLeave);
556
- this.container.addEventListener("click", this.onClick);
557
- this.container.addEventListener("wheel", this.onWheel);
558
- document.addEventListener("keydown", this.onKeyDown);
559
- document.addEventListener("keyup", this.onKeyUp);
560
- window.parent.document.addEventListener("contextmenu", this.onContextmenu, false);
561
- }
562
- eventUnbinding() {
563
- this.container.removeEventListener("mousedown", this.onMouseDown);
564
- this.container.removeEventListener("mousemove", this.onMouseMove);
565
- this.container.removeEventListener("mouseup", this.onMouseUp);
566
- this.container.removeEventListener("mouseleave", this.onMouseLeave);
567
- this.container.removeEventListener("wheel", this.onWheel);
568
- this.container.removeEventListener("click", this.onClick);
569
- document.removeEventListener("keydown", this.onKeyDown);
570
- document.removeEventListener("keyup", this.onKeyUp);
571
- window.parent.document.removeEventListener("contextmenu", this.onContextmenu, false);
572
- this.dblClickListener.removeEvent();
573
- }
574
- clearImgDrag() {
575
- this.isDrag = false;
576
- this.isDragStart = false;
577
- this.isSpaceClick = false;
578
- this.startTime = 0;
579
- this.container.style.cursor = this.defaultCursor;
580
- this.forbidCursorLine = false;
581
- }
582
- clearCursorLine() {
583
- this.coord = {
584
- x: -1,
585
- y: -1
586
- };
587
- }
588
- onMouseDown(e) {
589
- if (!this.canvas || this.isImgError) {
590
- return true;
591
- }
592
- const coord = this.getCoordinate(e);
593
- if (this.isSpaceKey && e.button === 0 || e.button === 2) {
594
- e.stopPropagation();
595
- this._firstClickCoordinate = coord;
596
- this.currentPosStorage = this.currentPos;
597
- this.isSpaceClick = true;
598
- this.isDragStart = true;
599
- this.startTime = new Date().getTime();
600
- }
601
- }
602
- onMouseMove(e) {
603
- if (!this.canvas || this.isImgError) {
604
- return true;
605
- }
606
- const coord = this.getCoordinate(e);
607
- if (this.isShowCursor) {
608
- this.coord = coord;
609
- }
610
- try {
611
- if (!coord || !_.isNumber(coord == null ? void 0 : coord.x) || !_.isNumber(coord == null ? void 0 : coord.y)) {
612
- throw new Error("coord error");
613
- }
614
- this.coord = coord;
615
- if ((this.isSpaceClick || this.isDragStart) && this._firstClickCoordinate) {
616
- const currentPos = this.getCurrentPos(coord);
617
- this.setCurrentPos(currentPos);
618
- this.isDrag = true;
619
- this.container.style.cursor = "grabbing";
620
- this.forbidCursorLine = true;
621
- this.renderBasicCanvas();
622
- this.emit("dependRender");
623
- this.emit("dragMove", {currentPos, zoom: this.zoom, imgInfo: this.imgInfo});
624
- }
625
- this.render();
626
- } catch (error) {
627
- console.error(error);
628
- }
629
- }
630
- onMouseUp(e) {
631
- if (!this.canvas || this.isImgError) {
632
- return true;
633
- }
634
- this.container.style.cursor = this.defaultCursor;
635
- this.forbidCursorLine = false;
636
- this.isDrag = false;
637
- this.isDragStart = false;
638
- this.isSpaceClick = false;
639
- if (this.startTime !== 0 && this._firstClickCoordinate) {
640
- const time = new Date().getTime();
641
- const currentCoord = this.getCoordinate(e);
642
- if (time - this.startTime > 1e3 || this.isSpaceKey === true || LineToolUtils["default"].calcTwoPointDistance(currentCoord, this._firstClickCoordinate) > 10) {
643
- e.stopPropagation();
644
- this.startTime = 0;
645
- this.render();
646
- return true;
647
- }
648
- }
649
- this.startTime = 0;
650
- this.render();
651
- }
652
- onMouseLeave() {
653
- this.clearImgDrag();
654
- }
655
- onClick(e) {
656
- }
657
- onLeftDblClick(e) {
658
- }
659
- onRightDblClick(e) {
660
- this.clearImgDrag();
661
- }
662
- onKeyDown(e) {
663
- if (e.keyCode === keyCode.Alt) {
664
- e.preventDefault();
665
- }
666
- switch (e.keyCode) {
667
- case keyCode.Space:
668
- this.isSpaceKey = true;
669
- break;
670
- case keyCode.Z:
671
- if (e.ctrlKey) {
672
- if (e.shiftKey) {
673
- this.redo();
674
- } else {
675
- this.undo();
676
- }
677
- return false;
678
- }
679
- break;
680
- }
681
- return true;
682
- }
683
- onKeyUp(e) {
684
- switch (e.keyCode) {
685
- case keyCode.Space:
686
- this.isSpaceKey = false;
687
- break;
688
- }
689
- }
690
- exportCustomData() {
691
- return {};
692
- }
693
- onWheel(e, isRender = true) {
694
- if (!this.imgNode || !this.coord) {
695
- return;
696
- }
697
- e.preventDefault();
698
- e.stopPropagation();
699
- const coord = this.getCoordinate(e);
700
- const delta = e.deltaY || e.wheelDelta;
701
- let operator = 0;
702
- if (delta > 0 && this.zoom > zoomInfo.min) {
703
- operator = -1;
704
- }
705
- if (delta < 0 && this.zoom < zoomInfo.max) {
706
- operator = 1;
707
- }
708
- this.wheelChangePos(coord, operator);
709
- this.emit("dependRender");
710
- if (isRender) {
711
- this.render();
712
- }
713
- this.renderBasicCanvas();
714
- }
715
- renderCursorLine(lineColor = ((_a) => (_a = this.style.lineColor[0]) != null ? _a : "")()) {
716
- if (!this.ctx || this.forbidCursorLine || this.forbidOperation) {
717
- return;
718
- }
719
- const {x, y} = this.coord;
720
- DrawUtils.drawLine(this.canvas, {x: 0, y}, {x: 1e4, y}, {color: lineColor});
721
- DrawUtils.drawLine(this.canvas, {x, y: 0}, {x, y: 1e4}, {color: lineColor});
722
- DrawUtils.drawCircleWithFill(this.canvas, {x, y}, 1, {color: "white"});
723
- }
724
- setSize(size) {
725
- var _a;
726
- this.size = size;
727
- if (this.container.contains(this.canvas)) {
728
- this.destroyCanvas();
729
- this.createCanvas(size);
730
- this.eventUnbinding();
731
- this.init();
732
- if (((_a = this.basicImgInfo) == null ? void 0 : _a.valid) === false) {
733
- this.renderInvalidPage();
734
- }
735
- }
736
- }
737
- setImgAttribute(imgAttribute) {
738
- const oldImgAttribute = this._imgAttribute;
739
- this._imgAttribute = imgAttribute;
740
- if ((oldImgAttribute == null ? void 0 : oldImgAttribute.zoomRatio) !== imgAttribute.zoomRatio || oldImgAttribute.isOriginalSize !== imgAttribute.isOriginalSize) {
741
- this.initImgPos();
742
- return;
743
- }
744
- this.renderBasicCanvas();
745
- this.render();
746
- }
747
- clearResult(sendMessage) {
748
- }
749
- setValid(valid) {
750
- this.basicImgInfo.valid = valid;
751
- if (valid === false) {
752
- this.renderInvalidPage();
753
- this.clearResult(false);
754
- } else {
755
- this.clearInvalidPage();
756
- }
757
- }
758
- setRotate(rotate) {
759
- this.basicImgInfo.rotate = rotate;
760
- }
761
- setBasicResult(basicResult) {
762
- this.basicResult = basicResult;
763
- this.coordUtils.setBasicResult(basicResult);
764
- this.initPosition();
765
- this.emit("dependRender");
766
- }
767
- setDependName(dependToolName, dependToolConfig) {
768
- this.dependToolName = dependToolName;
769
- this.coordUtils.setDependInfo(dependToolName, dependToolConfig);
770
- }
771
- setAttributeLockList(attributeLockList) {
772
- this.attributeLockList = attributeLockList;
773
- this.render();
774
- }
775
- setConfig(config) {
776
- this.config = CommonToolUtils.jsonParser(config);
777
- }
778
- setDataInjectionAtCreation(dataInjectionAtCreation) {
779
- this.dataInjectionAtCreation = dataInjectionAtCreation;
780
- }
781
- setRenderEnhance(renderEnhance) {
782
- this.renderEnhance = renderEnhance;
783
- }
784
- setCustomRenderStyle(customRenderStyle) {
785
- this.customRenderStyle = customRenderStyle;
786
- }
787
- updateRotate() {
788
- if (this.dependToolName) {
789
- this.emit("messageInfo", index.getMessagesByLocale(constants.EMessage.NoRotateInDependence, this.lang));
790
- return false;
791
- }
792
- if (this.dataList.length > 0) {
793
- this.emit("messageInfo", index.getMessagesByLocale(constants.EMessage.NoRotateNotice, this.lang));
794
- return false;
795
- }
796
- const rotate = MathUtils["default"].getRotate(this.basicImgInfo.rotate);
797
- this.basicImgInfo.rotate = rotate;
798
- this.initImgPos();
799
- this.emit("updateResult");
800
- }
801
- getColor(attribute = "", config = this.config) {
802
- return lbUtils.toolStyleConverter.getColorByConfig({attribute, config, style: this.style});
803
- }
804
- getLineColor(attribute = "") {
805
- var _a, _b, _c, _d, _e, _f, _g, _h;
806
- if (((_a = this.config) == null ? void 0 : _a.attributeConfigurable) === true) {
807
- const attributeIndex = AttributeUtils["default"].getAttributeIndex(attribute, (_c = (_b = this.config) == null ? void 0 : _b.attributeList) != null ? _c : []) + 1;
808
- const color2 = (_f = (_e = (_d = this.config) == null ? void 0 : _d.attributeList) == null ? void 0 : _e.find((i) => i.value === attribute)) == null ? void 0 : _f.color;
809
- if (color2) {
810
- return (_h = (_g = lbUtils.toolStyleConverter.getColorByConfig({attribute, config: this.config})) == null ? void 0 : _g.valid) == null ? void 0 : _h.stroke;
811
- }
812
- return this.style.attributeLineColor ? this.style.attributeLineColor[attributeIndex] : "";
813
- }
814
- const {color, lineColor} = this.style;
815
- if (color && lineColor) {
816
- return lineColor[color];
817
- }
818
- return "";
819
- }
820
- clearInvalidPage() {
821
- if (this._invalidDOM && this.container && this.container.contains(this._invalidDOM)) {
822
- this.container.removeChild(this._invalidDOM);
823
- this._invalidDOM = void 0;
824
- }
825
- }
826
- renderInvalidPage() {
827
- if (!this.container || this._invalidDOM) {
828
- return;
829
- }
830
- this._invalidDOM = RenderDomUtils.renderInvalidPage(this.container, this.size, this.lang);
831
- }
832
- renderBasicCanvas() {
833
- if (!this.basicCanvas) {
834
- return;
835
- }
836
- this.clearBasicCanvas();
837
- this.drawImg();
838
- const thickness = 3;
839
- if (this.forbidBasicResultRender) {
840
- return;
841
- }
842
- if (this.basicResult && this.dependToolName) {
843
- switch (this.dependToolName) {
844
- case tool.EToolName.Rect: {
845
- DrawUtils.drawRect(this.basicCanvas, AxisUtils["default"].changeRectByZoom(this.basicResult, this.zoom, this.currentPos), {
846
- color: "rgba(204,204,204,1.00)",
847
- thickness
848
- });
849
- break;
850
- }
851
- case tool.EToolName.Polygon: {
852
- DrawUtils.drawPolygonWithFillAndLine(this.basicCanvas, AxisUtils["default"].changePointListByZoom(this.basicResult.pointList, this.zoom, this.currentPos), {
853
- fillColor: "transparent",
854
- strokeColor: "rgba(204,204,204,1.00)",
855
- isClose: true,
856
- thickness
857
- });
858
- break;
859
- }
860
- case tool.EToolName.Line: {
861
- DrawUtils.drawLineWithPointList(this.basicCanvas, AxisUtils["default"].changePointListByZoom(this.basicResult.pointList, this.zoom, this.currentPos), {
862
- color: "rgba(204,204,204,1.00)",
863
- thickness
864
- });
865
- break;
866
- }
867
- }
868
- }
869
- }
870
- render() {
871
- if (!this.canvas || !this.ctx || !this.imgNode) {
872
- return;
873
- }
874
- this.clearCanvas();
875
- }
876
- changeStyle(newAttribute = this.defaultAttribute) {
877
- this.emit("changeStyle", {attribute: newAttribute});
878
- }
879
- }
880
-
881
- exports.BasicToolOperation = BasicToolOperation;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),_=require("lodash"),tool=require("../../constant/tool.js"),MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),LineToolUtils=require("../../utils/tool/LineToolUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),style=require("../../constant/style.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),DblClickEventListener=require("../../utils/tool/DblClickEventListener.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),ImgPosUtils=require("../../utils/tool/ImgPosUtils.js"),RenderDomUtils=require("../../utils/tool/RenderDomUtils.js"),ZoomUtils=require("../../utils/tool/ZoomUtils.js"),eventListener=require("./eventListener.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(d,t,e)=>t in d?__defProp(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,__spreadValues=(d,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(d,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(d,e,t[e]);return d},__spreadProps=(d,t)=>__defProps(d,__getOwnPropDescs(t)),__async=(d,t,e)=>new Promise((i,s)=>{var o=r=>{try{n(e.next(r))}catch(a){s(a)}},h=r=>{try{n(e.throw(r))}catch(a){s(a)}},n=r=>r.done?i(r.value):Promise.resolve(r.value).then(o,h);n((e=e.apply(d,t)).next())});const zoomInfo={min:.2,max:1e3,ratio:.4};class BasicToolOperation extends eventListener{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.operationMode=tool.EOperationMode.General,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.initImgPos=()=>__async(this,null,function*(){var l,c;if(!this.imgNode)return;const u=(l=this._imgAttribute)==null?void 0:l.zoomRatio,g=(c=this._imgAttribute)==null?void 0:c.isOriginalSize,{currentPos:m,imgInfo:C,zoom:v}=ImgPosUtils.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,u,g);this.setCurrentPos(m),this.currentPosStorage=m,this.setImgInfo(C),this.setZoom(v),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",v,m,C)}),this.getCurrentPos=l=>{const{_firstClickCoordinate:c,currentPosStorage:u}=this;try{let g;return c&&u?g={y:u.y+l.y-c.y,x:u.x+l.x-c.x}:g={x:0,y:0},g}catch(g){return console.error(g),{x:0,y:0}}},this.wheelChangePos=(l,c,u)=>{const{currentPos:g,imgNode:m}=this;if(!m){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&c===-1)return;const C=ZoomUtils.wheelChangePos(m,l,c,g,{zoom:u||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:zoomInfo.max,rotate:this.rotate});if(!C)return;const{currentPos:v,ratio:I,zoom:b,imgInfo:y}=C;this.setZoom(b),this.setCurrentPos(v),this.currentPosStorage=v,this.setImgInfo(y),zoomInfo.ratio=I,this.emit("renderZoom",b,v,y)},this.zoomChanged=(l,c=annotation.EGrowthMode.Linear)=>{const u=ZoomUtils.zoomChanged(this.zoom,l,c);this.wheelChangePos(this.getGetCenterCoordinate(),u>this.zoom?1:-1,u),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=l=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,l),this.render(),this.renderBasicCanvas()},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||DrawUtils.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute})};var e,i,s,o,h,n,r,a,f;this.container=t.container,this.config=CommonToolUtils.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.isImgError=!t.imgNode,this.basicImgInfo={width:(i=(e=t.imgNode)==null?void 0:e.width)!=null?i:0,height:(o=(s=t.imgNode)==null?void 0:s.height)!=null?o:0,valid:!0,rotate:0},this.forbidOperation=(h=t.forbidOperation)!=null?h:!1,this.forbidBasicResultRender=(n=t.forbidBasicResultRender)!=null?n:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.style={strokeColor:style.COLORS_ARRAY[4],fillColor:style.COLORS_ARRAY[4],strokeWidth:2,opacity:1},this.attributeLockList=[],this.history=new ActionsHistory,this.style=(r=t.style)!=null?r:CommonToolUtils.jsonParser(style.styleString),this._imgAttribute=(a=t.imgAttribute)!=null?a:{},this.isHidden=!1,this.dragStatus=annotation.EDragStatus.Wait,this.defaultAttribute=(f=t==null?void 0:t.defaultAttribute)!=null?f:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=annotation.ELang.Zh,this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new DblClickEventListener(this.container,200),this.coordUtils=new AxisUtils.CoordinateUtils(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,e;return(e=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?e:0}get valid(){var t,e;return(e=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?e:!0}get baseIcon(){return style.BASE_ICON[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get innerPosAndZoom(){return{innerZoom:this.innerZoom,currentPosStorage:this.currentPosStorage}}get isShowDefaultCursor(){return this.showDefaultCursor}get isMultiMoveMode(){return this.operationMode===tool.EOperationMode.MultiMove}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}setCurrentPosStorage(t){this.currentPosStorage=t}setOperationMode(t){this.operationMode=t}recoverOperationMode(){this.operationMode===tool.EOperationMode.MultiMove&&this.setOperationMode(tool.EOperationMode.General)}updatePosition(t){const{zoom:e,currentPos:i}=t;this.setZoom(e),this.setCurrentPos(i),this.currentPosStorage=i,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}setCustomCursor(t){this.container.style.cursor=t}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return CanvasUtils.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}updateCanvasBasicStyle(t,e,i){const s=this.pixelRatio;t.style.position="absolute",t.width=e.width*s,t.height=e.height*s,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${i} `}createCanvas(t,e=!0){var i,s;const o=this.pixelRatio,h=document.createElement("canvas");this.updateCanvasBasicStyle(h,t,0),this.basicCanvas=h;const n=document.createElement("canvas");this.updateCanvasBasicStyle(n,t,10),e&&(this.container.hasChildNodes()?(this.container.insertBefore(n,this.container.childNodes[0]),this.container.insertBefore(h,this.container.childNodes[0])):(this.container.appendChild(h),this.container.appendChild(n))),this.canvas=n,this.container.style.cursor=this.defaultCursor,(i=this.ctx)==null||i.scale(o,o),(s=this.basicCtx)==null||s.scale(o,o)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,e={}){this.imgNode=t,this.setBasicImgInfo(__spreadValues({width:t.width,height:t.height,valid:!0,rotate:0},e)),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof e.valid=="boolean"&&this.setValid(e.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(t),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setDefaultAttribute(t){this.defaultAttribute=t}getCoordinateInOrigin(t){const e=this.canvas.getBoundingClientRect();return{x:(t.clientX-e.left-this.currentPos.x)/this.zoom,y:(t.clientY-e.top-this.currentPos.y)/this.zoom}}getTextIconSvg(t=""){var e;return AttributeUtils.default.getTextIconSvg(t,(e=this.config)==null?void 0:e.attributeList,this.config.attributeConfigurable,this.baseIcon)}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left,y:t.clientY-e.top}}getCoordinateUnderZoom(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left-this.currentPos.x,y:t.clientY-e.top-this.currentPos.y}}getCoordinateUnderZoomByRotate(t){const{x:e,y:i}=this.getCoordinateUnderZoom(t);return this.basicImgInfo.rotate===90?{x:i,y:this.basicImgInfo.height*this.zoom-e}:this.basicImgInfo.rotate===180?{x:this.basicImgInfo.width*this.zoom-e,y:this.basicImgInfo.height*this.zoom-i}:this.basicImgInfo.rotate===270?{x:this.basicImgInfo.width*this.zoom-i,y:e}:{x:e,y:i}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:e,imgNode:i,_imgAttribute:s,imgInfo:o,dependToolName:h}=this;if(t&&i&&h){let n=t;switch(h){case tool.EToolName.Polygon:case tool.EToolName.Line:{if(t.pointList){const a=MathUtils.default.calcViewportBoundaries(t.pointList);n={x:a.left,y:a.top,width:a.right-a.left,height:a.bottom-a.top}}break}}const r=ImgPosUtils.getBasicRecPos(i,n,e,void 0,s==null?void 0:s.zoomRatio,s==null?void 0:s.isOriginalSize);r&&(this.setCurrentPos(r.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(__spreadProps(__spreadValues({},o),{width:o.width/this.innerZoom*r.innerZoom,height:o.height/this.innerZoom*r.innerZoom})),this.setZoom(r.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const e=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=e,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t){if(!this.canvas||this.isImgError)return!0;const e=this.getCoordinate(t);this.isShowCursor&&(this.coord=e);try{if(!e||!_.isNumber(e==null?void 0:e.x)||!_.isNumber(e==null?void 0:e.y))throw new Error("coord error");if(this.coord=e,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const i=this.getCurrentPos(e);this.setCurrentPos(i),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:i,zoom:this.zoom,imgInfo:this.imgInfo})}this.render()}catch(i){console.error(i)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const e=new Date().getTime(),i=this.getCoordinate(t);if(e-this.startTime>1e3||this.isSpaceKey===!0||LineToolUtils.default.calcTwoPointDistance(i,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch(t.keyCode===keyCode.Alt&&t.preventDefault(),t.keyCode){case keyCode.Space:this.isSpaceKey=!0;break;case keyCode.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case keyCode.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,e=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const i=this.getCoordinate(t),s=t.deltaY||t.wheelDelta;let o=0;s>0&&this.zoom>zoomInfo.min&&(o=-1),s<0&&this.zoom<zoomInfo.max&&(o=1),this.wheelChangePos(i,o),this.emit("dependRender"),e&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(e=>(e=this.style.lineColor[0])!=null?e:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:e,y:i}=this.coord;DrawUtils.drawLine(this.canvas,{x:0,y:i},{x:1e4,y:i},{color:t}),DrawUtils.drawLine(this.canvas,{x:e,y:0},{x:e,y:1e4},{color:t}),DrawUtils.drawCircleWithFill(this.canvas,{x:e,y:i},1,{color:"white"})}setSize(t){var e;this.size=t,this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((e=this.basicImgInfo)==null?void 0:e.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const e=this._imgAttribute;if(this._imgAttribute=t,(e==null?void 0:e.zoomRatio)!==t.zoomRatio||e.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,e){this.dependToolName=t,this.coordUtils.setDependInfo(t,e)}setAttributeLockList(t){this.attributeLockList=t,this.render()}setConfig(t){this.config=CommonToolUtils.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateNotice,this.lang)),!1;const t=MathUtils.default.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",e=this.config){return lbUtils.toolStyleConverter.getColorByConfig({attribute:t,config:e,style:this.style})}getLineColor(t=""){var e,i,s,o,h,n,r,a;if(((e=this.config)==null?void 0:e.attributeConfigurable)===!0){const c=AttributeUtils.default.getAttributeIndex(t,(s=(i=this.config)==null?void 0:i.attributeList)!=null?s:[])+1;return((n=(h=(o=this.config)==null?void 0:o.attributeList)==null?void 0:h.find(g=>g.value===t))==null?void 0:n.color)?(a=(r=lbUtils.toolStyleConverter.getColorByConfig({attribute:t,config:this.config}))==null?void 0:r.valid)==null?void 0:a.stroke:this.style.attributeLineColor?this.style.attributeLineColor[c]:""}const{color:f,lineColor:l}=this.style;return f&&l?l[f]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=RenderDomUtils.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case tool.EToolName.Rect:{DrawUtils.drawRect(this.basicCanvas,AxisUtils.default.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case tool.EToolName.Polygon:{DrawUtils.drawPolygonWithFillAndLine(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case tool.EToolName.Line:{DrawUtils.drawLineWithPointList(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}exports.BasicToolOperation=BasicToolOperation;