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

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 (187) hide show
  1. package/dist/_virtual/MathUtilsWorker.js +8 -1
  2. package/dist/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +35 -2
  3. package/dist/_virtual/filterBoxWorker.js +8 -1
  4. package/dist/_virtual/highlightWorker.js +8 -1
  5. package/dist/assets/attributeIcon/icon_canvasEdit0.svg.js +5 -1
  6. package/dist/assets/attributeIcon/icon_canvasEdit1.svg.js +5 -1
  7. package/dist/assets/attributeIcon/icon_canvasEdit2.svg.js +5 -1
  8. package/dist/assets/attributeIcon/icon_canvasEdit3.svg.js +5 -1
  9. package/dist/assets/attributeIcon/icon_canvasEdit4.svg.js +5 -1
  10. package/dist/assets/attributeIcon/icon_canvasEdit5.svg.js +5 -1
  11. package/dist/assets/attributeIcon/icon_canvasEdit6.svg.js +5 -1
  12. package/dist/assets/attributeIcon/icon_canvasEdit7.svg.js +5 -1
  13. package/dist/assets/attributeIcon/icon_canvasEdit8.svg.js +5 -1
  14. package/dist/assets/attributeIcon/icon_canvasEdit_miss.svg.js +5 -1
  15. package/dist/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -5
  16. package/dist/assets/attributeIcon/icon_cuboidLeft.svg.js +5 -7
  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 +5 -12
  20. package/dist/assets/attributeIcon/icon_editFEN.svg.js +5 -1
  21. package/dist/assets/attributeIcon/icon_editHUANG.svg.js +5 -1
  22. package/dist/assets/attributeIcon/icon_editLAN.svg.js +5 -1
  23. package/dist/assets/attributeIcon/icon_editLV.svg.js +5 -1
  24. package/dist/assets/attributeIcon/icon_editQING.svg.js +5 -1
  25. package/dist/constant/annotation.js +127 -1
  26. package/dist/constant/annotationTask.js +30 -1
  27. package/dist/constant/defaultConfig.js +266 -1
  28. package/dist/constant/keyCode.js +38 -1
  29. package/dist/constant/style.js +98 -1
  30. package/dist/constant/tool.js +236 -1
  31. package/dist/core/index.js +150 -1
  32. package/dist/core/pointCloud/OrbitControls.js +665 -1
  33. package/dist/core/pointCloud/PCDLoader.js +260 -2
  34. package/dist/core/pointCloud/annotation.js +215 -1
  35. package/dist/core/pointCloud/cache.js +53 -1
  36. package/dist/core/pointCloud/index.js +991 -5
  37. package/dist/core/pointCloud/matrix.js +138 -1
  38. package/dist/core/pointCloud/segmentation.js +144 -0
  39. package/dist/core/pointCloud/selector/Sse3dLassoSelector.js +26 -0
  40. package/dist/core/pointCloud/selector/Sse3dSelector.js +16 -0
  41. package/dist/core/scheduler.js +233 -1
  42. package/dist/core/toolOperation/LineToolOperation.js +1434 -1
  43. package/dist/core/toolOperation/ScribbleTool.js +292 -1
  44. package/dist/core/toolOperation/TextToolOperation.js +131 -1
  45. package/dist/core/toolOperation/ViewOperation.js +556 -1
  46. package/dist/core/toolOperation/basicToolOperation.js +881 -1
  47. package/dist/core/toolOperation/checkOperation.js +208 -1
  48. package/dist/core/toolOperation/cuboidOperation.js +754 -1
  49. package/dist/core/toolOperation/cuboidToggleButtonClass.js +152 -7
  50. package/dist/core/toolOperation/eventListener.js +37 -1
  51. package/dist/core/toolOperation/measureOperation.js +41 -1
  52. package/dist/core/toolOperation/pointCloud2dOperation.js +365 -1
  53. package/dist/core/toolOperation/pointOperation.js +696 -1
  54. package/dist/core/toolOperation/polygonOperation.js +1251 -1
  55. package/dist/core/toolOperation/rectOperation.js +1233 -1
  56. package/dist/core/toolOperation/segmentByRect.js +174 -1
  57. package/dist/core/toolOperation/tagOperation.js +201 -3
  58. package/dist/core/toolOperation/textAttributeClass.js +182 -16
  59. package/dist/index.js +185 -1
  60. package/dist/locales/constants.js +24 -1
  61. package/dist/locales/en_US/message.js +25 -1
  62. package/dist/locales/index.js +19 -1
  63. package/dist/locales/zh_CN/message.js +25 -1
  64. package/dist/newCore/CanvasScheduler.js +35 -1
  65. package/dist/types/core/pointCloud/segmentation.d.ts +0 -0
  66. package/dist/types/core/pointCloud/selector/Sse3dLassoSelector.d.ts +0 -0
  67. package/dist/types/core/pointCloud/selector/Sse3dSelector.d.ts +0 -0
  68. package/dist/utils/ActionsHistory.js +84 -1
  69. package/dist/utils/ImgUtils.js +23 -1
  70. package/dist/utils/MathUtils.js +385 -2
  71. package/dist/utils/VectorUtils.js +25 -1
  72. package/dist/utils/tool/AttributeUtils.js +218 -1
  73. package/dist/utils/tool/AxisUtils.js +340 -1
  74. package/dist/utils/tool/CanvasUtils.js +62 -1
  75. package/dist/utils/tool/CommonToolUtils.js +174 -1
  76. package/dist/utils/tool/CuboidUtils.js +704 -1
  77. package/dist/utils/tool/DblClickEventListener.js +102 -1
  78. package/dist/utils/tool/DrawUtils.js +492 -3
  79. package/dist/utils/tool/EnhanceCommonToolUtils.js +53 -1
  80. package/dist/utils/tool/ImgPosUtils.js +58 -1
  81. package/dist/utils/tool/LineToolUtils.js +261 -1
  82. package/dist/utils/tool/MarkerUtils.js +56 -1
  83. package/dist/utils/tool/PolygonUtils.js +460 -1
  84. package/dist/utils/tool/RectUtils.js +155 -1
  85. package/dist/utils/tool/RenderDomClass.js +57 -7
  86. package/dist/utils/tool/RenderDomUtils.js +21 -4
  87. package/dist/utils/tool/StyleUtils.js +31 -1
  88. package/dist/utils/tool/TagUtils.js +129 -1
  89. package/dist/utils/tool/UnitUtils.js +12 -1
  90. package/dist/utils/tool/ZoomUtils.js +72 -1
  91. package/dist/utils/tool/polygonTool.js +133 -1
  92. package/dist/utils/uuid.js +26 -1
  93. package/es/_virtual/MathUtilsWorker.js +6 -1
  94. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +12 -0
  95. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +7 -0
  96. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +31 -2
  97. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +11 -0
  98. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +18 -0
  99. package/es/_virtual/filterBoxWorker.js +6 -1
  100. package/es/_virtual/highlightWorker.js +6 -1
  101. package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +3 -1
  102. package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +3 -1
  103. package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +3 -1
  104. package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +3 -1
  105. package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +3 -1
  106. package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +3 -1
  107. package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +3 -1
  108. package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +3 -1
  109. package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +3 -1
  110. package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +3 -1
  111. package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +3 -5
  112. package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +3 -7
  113. package/es/assets/attributeIcon/icon_cuboidMore.svg.js +3 -5
  114. package/es/assets/attributeIcon/icon_cuboidRight.svg.js +3 -5
  115. package/es/assets/attributeIcon/icon_cuboidTop.svg.js +3 -12
  116. package/es/assets/attributeIcon/icon_editFEN.svg.js +3 -1
  117. package/es/assets/attributeIcon/icon_editHUANG.svg.js +3 -1
  118. package/es/assets/attributeIcon/icon_editLAN.svg.js +3 -1
  119. package/es/assets/attributeIcon/icon_editLV.svg.js +3 -1
  120. package/es/assets/attributeIcon/icon_editQING.svg.js +3 -1
  121. package/es/constant/annotation.js +113 -1
  122. package/es/constant/annotationTask.js +25 -1
  123. package/es/constant/defaultConfig.js +260 -1
  124. package/es/constant/keyCode.js +36 -1
  125. package/es/constant/style.js +74 -1
  126. package/es/constant/tool.js +220 -1
  127. package/es/core/index.js +148 -1
  128. package/es/core/pointCloud/OrbitControls.js +661 -1
  129. package/es/core/pointCloud/PCDLoader.js +256 -2
  130. package/es/core/pointCloud/annotation.js +211 -1
  131. package/es/core/pointCloud/cache.js +49 -1
  132. package/es/core/pointCloud/index.js +962 -5
  133. package/es/core/pointCloud/matrix.js +109 -1
  134. package/es/core/pointCloud/segmentation.js +120 -0
  135. package/es/core/pointCloud/selector/Sse3dLassoSelector.js +24 -0
  136. package/es/core/pointCloud/selector/Sse3dSelector.js +14 -0
  137. package/es/core/scheduler.js +228 -1
  138. package/es/core/toolOperation/LineToolOperation.js +1421 -1
  139. package/es/core/toolOperation/ScribbleTool.js +290 -1
  140. package/es/core/toolOperation/TextToolOperation.js +129 -1
  141. package/es/core/toolOperation/ViewOperation.js +549 -1
  142. package/es/core/toolOperation/basicToolOperation.js +877 -1
  143. package/es/core/toolOperation/checkOperation.js +206 -1
  144. package/es/core/toolOperation/cuboidOperation.js +752 -1
  145. package/es/core/toolOperation/cuboidToggleButtonClass.js +150 -7
  146. package/es/core/toolOperation/eventListener.js +35 -1
  147. package/es/core/toolOperation/measureOperation.js +39 -1
  148. package/es/core/toolOperation/pointCloud2dOperation.js +359 -1
  149. package/es/core/toolOperation/pointOperation.js +690 -1
  150. package/es/core/toolOperation/polygonOperation.js +1245 -1
  151. package/es/core/toolOperation/rectOperation.js +1228 -1
  152. package/es/core/toolOperation/scribbleTool2.js +249 -0
  153. package/es/core/toolOperation/segmentByRect.js +172 -1
  154. package/es/core/toolOperation/tagOperation.js +199 -3
  155. package/es/core/toolOperation/textAttributeClass.js +180 -16
  156. package/es/index.js +46 -1
  157. package/es/locales/constants.js +22 -1
  158. package/es/locales/en_US/message.js +23 -1
  159. package/es/locales/index.js +17 -1
  160. package/es/locales/zh_CN/message.js +23 -1
  161. package/es/newCore/CanvasScheduler.js +31 -1
  162. package/es/utils/ActionsHistory.js +78 -1
  163. package/es/utils/ImgUtils.js +21 -1
  164. package/es/utils/MathUtils.js +380 -2
  165. package/es/utils/VectorUtils.js +23 -1
  166. package/es/utils/tool/AttributeUtils.js +212 -1
  167. package/es/utils/tool/AxisUtils.js +335 -1
  168. package/es/utils/tool/CanvasUtils.js +60 -1
  169. package/es/utils/tool/CommonToolUtils.js +172 -1
  170. package/es/utils/tool/CuboidUtils.js +680 -1
  171. package/es/utils/tool/DblClickEventListener.js +100 -1
  172. package/es/utils/tool/DrawUtils.js +490 -3
  173. package/es/utils/tool/EnhanceCommonToolUtils.js +48 -1
  174. package/es/utils/tool/ImgPosUtils.js +56 -1
  175. package/es/utils/tool/LineToolUtils.js +255 -1
  176. package/es/utils/tool/MarkerUtils.js +54 -1
  177. package/es/utils/tool/PolygonUtils.js +458 -1
  178. package/es/utils/tool/RectUtils.js +153 -1
  179. package/es/utils/tool/RenderDomClass.js +55 -7
  180. package/es/utils/tool/RenderDomUtils.js +19 -4
  181. package/es/utils/tool/StyleUtils.js +29 -1
  182. package/es/utils/tool/TagUtils.js +127 -1
  183. package/es/utils/tool/UnitUtils.js +10 -1
  184. package/es/utils/tool/ZoomUtils.js +70 -1
  185. package/es/utils/tool/polygonTool.js +126 -1
  186. package/es/utils/uuid.js +24 -1
  187. package/package.json +7 -5
@@ -0,0 +1,249 @@
1
+ import { ImgConversionUtils } from '@labelbee/lb-utils';
2
+ import AxisUtils from '../../utils/tool/AxisUtils.js';
3
+ import DrawUtils from '../../utils/tool/DrawUtils.js';
4
+ import { EToolName, EScribblePattern } from '../../constant/tool.js';
5
+ import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
6
+ import AttributeUtils from '../../utils/tool/AttributeUtils.js';
7
+ import { BasicToolOperation } from './basicToolOperation.js';
8
+
9
+ const DEFAULT_PEN_SIZE = 20;
10
+ const DEFAULT_COLOR = "white";
11
+ class ScribbleTool extends BasicToolOperation {
12
+ constructor(props) {
13
+ super(props);
14
+ this.toolName = EToolName.ScribbleTool;
15
+ this.action = EScribblePattern.Scribble;
16
+ this.getOriginCoordinate = (e) => {
17
+ return AxisUtils.changePointByZoom(this.getCoordinateUnderZoom(e), 1 / this.zoom);
18
+ };
19
+ this.onMouseDown = (e) => {
20
+ if (super.onMouseDown(e) || this.forbidMouseOperation || !this.imgInfo) {
21
+ return void 0;
22
+ }
23
+ this.initCacheCanvas(this.imgNode);
24
+ this.mouseEvents("onMouseDown").call(this, e);
25
+ };
26
+ this.onMouseMove = (e) => {
27
+ if (super.onMouseMove(e) || this.forbidMouseOperation || !this.imgInfo) {
28
+ return void 0;
29
+ }
30
+ this.mouseEvents("onMouseMove").call(this, e);
31
+ };
32
+ this.onMouseUp = (e) => {
33
+ if (super.onMouseUp(e) || this.forbidMouseOperation || !this.imgInfo) {
34
+ return void 0;
35
+ }
36
+ this.mouseEvents("onMouseUp").call(this, e);
37
+ };
38
+ this.mouseEvents = (eventType) => {
39
+ const events = {
40
+ [EScribblePattern.Scribble]: {
41
+ onMouseMove: this.onScribbleMove,
42
+ onMouseUp: this.onScribbleEnd,
43
+ onMouseDown: this.onScribbleStart
44
+ },
45
+ [EScribblePattern.Erase]: {
46
+ onMouseMove: this.onEraseMove,
47
+ onMouseUp: this.onEraseEnd,
48
+ onMouseDown: this.onEraseStart
49
+ }
50
+ };
51
+ return events[this.action][eventType];
52
+ };
53
+ this.setPattern = (pattern) => {
54
+ this.action = pattern;
55
+ };
56
+ this.penSize = DEFAULT_PEN_SIZE;
57
+ }
58
+ get color() {
59
+ var _a, _b;
60
+ return (_b = (_a = this == null ? void 0 : this.defaultAttributeInfo) == null ? void 0 : _a.color) != null ? _b : DEFAULT_COLOR;
61
+ }
62
+ get penSizeWithZoom() {
63
+ return this.penSize / this.zoom;
64
+ }
65
+ setPenSize(size) {
66
+ this.penSize = size;
67
+ }
68
+ initCacheCanvas(imgNode) {
69
+ if (this.cacheCanvas || !imgNode) {
70
+ return;
71
+ }
72
+ const {canvas, ctx} = ImgConversionUtils.createCanvas(imgNode);
73
+ this.cacheCanvas = canvas;
74
+ this.cacheContext = ctx;
75
+ }
76
+ updateCacheCanvasSize(imgNode) {
77
+ if (this.cacheCanvas) {
78
+ this.cacheCanvas.width = imgNode.width;
79
+ this.cacheCanvas.height = imgNode.height;
80
+ }
81
+ }
82
+ updateUrl2CacheContext(url) {
83
+ ImgConversionUtils.createImgDom(url).then((img) => {
84
+ if (!this.cacheContext) {
85
+ this.initCacheCanvas(img);
86
+ }
87
+ if (this.cacheContext) {
88
+ this.cacheContext.save();
89
+ this.clearResult();
90
+ this.cacheContext.drawImage(img, 0, 0, img.width, img.height);
91
+ this.cacheContext.restore();
92
+ this.render();
93
+ }
94
+ });
95
+ }
96
+ setImgNode(imgNode, basicImgInfo) {
97
+ super.setImgNode(imgNode, basicImgInfo);
98
+ if (this.cacheCanvas) {
99
+ this.updateCacheCanvasSize(imgNode);
100
+ } else {
101
+ this.initCacheCanvas(imgNode);
102
+ }
103
+ }
104
+ setResult(data) {
105
+ var _a;
106
+ const {url} = (_a = data == null ? void 0 : data[0]) != null ? _a : {};
107
+ this.history.initRecord([url], !!url);
108
+ this.clearResult();
109
+ if (!url) {
110
+ this.render();
111
+ return;
112
+ }
113
+ this.updateUrl2CacheContext(url);
114
+ }
115
+ onKeyDown(e) {
116
+ if (!CommonToolUtils.hotkeyFilter(e) || super.onKeyDown(e) === false) {
117
+ return;
118
+ }
119
+ const {keyCode} = e;
120
+ const keyCode2Attribute = AttributeUtils.getAttributeByKeycode(keyCode, this.config.attributeList);
121
+ if (keyCode2Attribute !== void 0) {
122
+ this.setDefaultAttribute(keyCode2Attribute);
123
+ }
124
+ }
125
+ eventBinding() {
126
+ super.eventBinding();
127
+ }
128
+ setDefaultAttribute(attributeValue) {
129
+ const attributeInfo = this.config.attributeList.find((v) => v.value === attributeValue);
130
+ if (attributeInfo) {
131
+ this.defaultAttribute = attributeInfo.value;
132
+ this.defaultAttributeInfo = attributeInfo;
133
+ this.emit("changeAttributeSidebar");
134
+ this.render();
135
+ }
136
+ }
137
+ clearStatusAfterLeave() {
138
+ this.onScribbleEnd();
139
+ this.startPoint = void 0;
140
+ }
141
+ onMouseLeave() {
142
+ super.onMouseLeave();
143
+ this.clearStatusAfterLeave();
144
+ }
145
+ onScribbleStart(e) {
146
+ if (!this.cacheContext) {
147
+ return;
148
+ }
149
+ this.cacheContext.save();
150
+ this.cacheContext.beginPath();
151
+ this.cacheContext.strokeStyle = this.color;
152
+ this.cacheContext.lineWidth = this.penSizeWithZoom;
153
+ this.cacheContext.lineCap = "round";
154
+ this.cacheContext.lineJoin = "round";
155
+ const originCoordinate = AxisUtils.changePointByZoom(this.getCoordinateUnderZoom(e), 1 / this.zoom);
156
+ this.cacheContext.moveTo(originCoordinate.x, originCoordinate.y);
157
+ this.startPoint = originCoordinate;
158
+ }
159
+ onScribbleMove(e) {
160
+ if (e.buttons === 1 && this.cacheContext && this.startPoint) {
161
+ const originCoordinate = this.getOriginCoordinate(e);
162
+ this.cacheContext.lineTo(originCoordinate.x, originCoordinate.y);
163
+ this.cacheContext.stroke();
164
+ }
165
+ }
166
+ onScribbleEnd() {
167
+ var _a, _b, _c;
168
+ if (this.startPoint) {
169
+ (_a = this.cacheContext) == null ? void 0 : _a.closePath();
170
+ (_b = this.cacheContext) == null ? void 0 : _b.restore();
171
+ this.startPoint = void 0;
172
+ this.history.pushHistory((_c = this.cacheCanvas) == null ? void 0 : _c.toDataURL("image/png", 0));
173
+ }
174
+ }
175
+ eraseArc(e) {
176
+ var _a;
177
+ if (this.cacheContext) {
178
+ const originCoordinate = this.getOriginCoordinate(e);
179
+ this.cacheContext.save();
180
+ this.cacheContext.beginPath();
181
+ this.cacheContext.arc(originCoordinate.x, originCoordinate.y, this.penSizeWithZoom / 2, 0, Math.PI * 2, false);
182
+ this.cacheContext.clip();
183
+ this.cacheContext.clearRect(0, 0, this.cacheContext.canvas.width, this.cacheContext.canvas.height);
184
+ (_a = this.cacheContext) == null ? void 0 : _a.restore();
185
+ }
186
+ }
187
+ onEraseStart(e) {
188
+ if (!this.cacheContext || e.buttons !== 1) {
189
+ return;
190
+ }
191
+ this.eraseArc(e);
192
+ }
193
+ onEraseMove(e) {
194
+ if (!this.cacheContext || e.buttons !== 1) {
195
+ return;
196
+ }
197
+ this.eraseArc(e);
198
+ }
199
+ onEraseEnd() {
200
+ }
201
+ exportData() {
202
+ var _a;
203
+ const imgBase64 = (_a = this.cacheCanvas) == null ? void 0 : _a.toDataURL("image/png", 0);
204
+ return [[], this.basicImgInfo, {imgBase64}];
205
+ }
206
+ clearCacheCanvas() {
207
+ var _a;
208
+ (_a = this.cacheContext) == null ? void 0 : _a.clearRect(0, 0, this.cacheContext.canvas.width, this.cacheContext.canvas.height);
209
+ this.render();
210
+ }
211
+ clearResult() {
212
+ this.clearCacheCanvas();
213
+ }
214
+ renderPoint(radius) {
215
+ DrawUtils.drawCircleWithFill(this.canvas, this.coord, radius, {color: this.color});
216
+ }
217
+ render() {
218
+ super.render();
219
+ if (!this.ctx || !this.cacheCanvas) {
220
+ return;
221
+ }
222
+ this.ctx.save();
223
+ this.ctx.globalAlpha = 0.5;
224
+ DrawUtils.drawImg(this.canvas, this.cacheCanvas, {
225
+ zoom: this.zoom,
226
+ currentPos: this.currentPos,
227
+ rotate: this.rotate
228
+ });
229
+ this.ctx.restore();
230
+ if (this.forbidOperation || this.forbidCursorLine) {
231
+ return;
232
+ }
233
+ this.renderPoint(this.penSize / 2);
234
+ }
235
+ undo() {
236
+ const url = this.history.undo();
237
+ if (url && this.cacheCanvas) {
238
+ this.updateUrl2CacheContext(url);
239
+ }
240
+ }
241
+ redo() {
242
+ const url = this.history.redo();
243
+ if (url && this.cacheCanvas) {
244
+ this.updateUrl2CacheContext(url);
245
+ }
246
+ }
247
+ }
248
+
249
+ export { ScribbleTool as default };
@@ -1 +1,172 @@
1
- import{i18n as d}from"@labelbee/lb-utils";import m from"../../utils/tool/AxisUtils.js";import{RectOperation as g}from"./rectOperation.js";import f from"../../constant/keyCode.js";var p=(u,e,t)=>new Promise((i,c)=>{var r=s=>{try{o(t.next(s))}catch(h){c(h)}},n=s=>{try{o(t.throw(s))}catch(h){c(h)}},o=s=>s.done?i(s.value):Promise.resolve(s.value).then(r,n);o((t=t.apply(u,e)).next())});class y extends g{constructor(e){super(e);this.onKeydown=t=>{switch(t.keyCode){case f.Esc:t.preventDefault(),t.stopPropagation(),this.clearPredictionInfo();break;case f.Z:t.ctrlKey&&(t.preventDefault(),t.stopPropagation(),this.rectList=[],this.render());break}},this.segmentPrediction=t=>p(this,null,function*(){const i=this.getCoordinateUnderZoom(t);if(this.isRunSegment=!0,this.render(),!this.runPrediction){this.emit("messageError","You needs to set runPrediction function"),this.clearPredictionInfo();return}yield this.runPrediction({point:i,rect:{x:this.rectList[0].x,y:this.rectList[0].y,w:this.rectList[0].width,h:this.rectList[0].height}}),this.clearPredictionInfo()}),this.isRunSegment=!1,this.runPrediction=e.runPrediction}setRunPrediction(e){this.runPrediction=e}eventBinding(){document.addEventListener("keydown",e=>this.onKeydown(e)),super.eventBinding()}clearPredictionInfo(){this.rectList=[],this.isShowCursor=!1,this.coord={x:-1,y:-1},this.drawingRect=void 0,this.isRunSegment=!1,this.clearCanvas(),this.render()}onMouseUp(e){if(!this.isRunSegment){if(e.button===0&&this.rectList.length===1&&!this.isRunSegment){e.stopPropagation(),this.segmentPrediction(e),this.clearActiveStatus();return}super.onMouseUp(e)}}onMouseDown(e){this.isRunSegment||super.onMouseDown(e)}renderCursorLine(){var e;if(!this.ctx)return;const{ctx:t}=this,i=10,c=1,{x:r,y:n}=this.coord;t.save(),t.strokeStyle="white",t.setLineDash([6]),t.lineWidth=c,t.strokeRect(r-i,n-i,i*2,i*2),t.restore();let o=`\u2460 ${d.t("FramingOfObjectToBeDivided")}`;const s=d.language==="en";let h=s?326:186;if(((e=this.rectList)==null?void 0:e.length)===1){o=`\u2461 ${d.t("ClickOnTarget")}`,h=s?232:142;const a=2;t.save(),t.strokeStyle="white";const l=c+i;t.beginPath(),t.moveTo(r+l+a*2,n+l+a),t.arc(r+l+a,n+l+a,a,0,Math.PI*2,!0),t.stroke(),t.restore()}this.isRunSegment&&(h=s?316:136,o=d.t("SplittingAlgorithmPrediction")),t.save(),t.fillStyle=this.style.strokeColor,t.fillRect(r+i,n-i*4-1,h,32),t.restore(),t.save(),t.font="14px Source Han Sans CN",t.fillStyle="white",t.fillText(o,r+i+14,n-i*2),t.restore(),super.renderCursorLine()}renderDrawingRect(e,t,i=!1){if(this.ctx&&e){const c=m.changeRectByZoom(e,i?t:this.zoom,this.currentPos),{x:r,y:n,width:o,height:s}=c;this.ctx.save(),this.ctx.lineCap="butt",this.ctx.lineWidth=this.style.strokeWidth,this.ctx.strokeStyle="white",this.ctx.strokeRect(r,n,o,s),this.ctx.strokeStyle=this.style.strokeColor,this.ctx.setLineDash([6]),this.ctx.strokeRect(r,n,o,s),this.ctx.restore()}}renderTextAttribute(){}renderSelectedRect(){}}export{y as default};
1
+ import { i18n } from '@labelbee/lb-utils';
2
+ import AxisUtils from '../../utils/tool/AxisUtils.js';
3
+ import { RectOperation } from './rectOperation.js';
4
+ import EKeyCode from '../../constant/keyCode.js';
5
+
6
+ var __async = (__this, __arguments, generator) => {
7
+ return new Promise((resolve, reject) => {
8
+ var fulfilled = (value) => {
9
+ try {
10
+ step(generator.next(value));
11
+ } catch (e) {
12
+ reject(e);
13
+ }
14
+ };
15
+ var rejected = (value) => {
16
+ try {
17
+ step(generator.throw(value));
18
+ } catch (e) {
19
+ reject(e);
20
+ }
21
+ };
22
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
23
+ step((generator = generator.apply(__this, __arguments)).next());
24
+ });
25
+ };
26
+ class SegmentByRect extends RectOperation {
27
+ constructor(props) {
28
+ super(props);
29
+ this.onKeydown = (e) => {
30
+ switch (e.keyCode) {
31
+ case EKeyCode.Esc:
32
+ e.preventDefault();
33
+ e.stopPropagation();
34
+ this.clearPredictionInfo();
35
+ break;
36
+ case EKeyCode.Z:
37
+ if (e.ctrlKey) {
38
+ e.preventDefault();
39
+ e.stopPropagation();
40
+ this.rectList = [];
41
+ this.render();
42
+ }
43
+ break;
44
+ }
45
+ };
46
+ this.segmentPrediction = (e) => __async(this, null, function* () {
47
+ const coord = this.getCoordinateUnderZoom(e);
48
+ this.isRunSegment = true;
49
+ this.render();
50
+ if (!this.runPrediction) {
51
+ this.emit("messageError", "You needs to set runPrediction function");
52
+ this.clearPredictionInfo();
53
+ return;
54
+ }
55
+ yield this.runPrediction({
56
+ point: coord,
57
+ rect: {
58
+ x: this.rectList[0].x,
59
+ y: this.rectList[0].y,
60
+ w: this.rectList[0].width,
61
+ h: this.rectList[0].height
62
+ }
63
+ });
64
+ this.clearPredictionInfo();
65
+ });
66
+ this.isRunSegment = false;
67
+ this.runPrediction = props.runPrediction;
68
+ }
69
+ setRunPrediction(runPrediction) {
70
+ this.runPrediction = runPrediction;
71
+ }
72
+ eventBinding() {
73
+ document.addEventListener("keydown", (e) => this.onKeydown(e));
74
+ super.eventBinding();
75
+ }
76
+ clearPredictionInfo() {
77
+ this.rectList = [];
78
+ this.isShowCursor = false;
79
+ this.coord = {x: -1, y: -1};
80
+ this.drawingRect = void 0;
81
+ this.isRunSegment = false;
82
+ this.clearCanvas();
83
+ this.render();
84
+ }
85
+ onMouseUp(e) {
86
+ if (this.isRunSegment) {
87
+ return;
88
+ }
89
+ if (e.button === 0 && this.rectList.length === 1 && !this.isRunSegment) {
90
+ e.stopPropagation();
91
+ this.segmentPrediction(e);
92
+ this.clearActiveStatus();
93
+ return;
94
+ }
95
+ super.onMouseUp(e);
96
+ return void 0;
97
+ }
98
+ onMouseDown(e) {
99
+ if (this.isRunSegment) {
100
+ return;
101
+ }
102
+ super.onMouseDown(e);
103
+ return void 0;
104
+ }
105
+ renderCursorLine() {
106
+ var _a;
107
+ if (!this.ctx) {
108
+ return;
109
+ }
110
+ const {ctx} = this;
111
+ const padding = 10;
112
+ const lineWidth = 1;
113
+ const {x, y} = this.coord;
114
+ ctx.save();
115
+ ctx.strokeStyle = "white";
116
+ ctx.setLineDash([6]);
117
+ ctx.lineWidth = lineWidth;
118
+ ctx.strokeRect(x - padding, y - padding, padding * 2, padding * 2);
119
+ ctx.restore();
120
+ let text = `\u2460 ${i18n.t("FramingOfObjectToBeDivided")}`;
121
+ const isEn = i18n.language === "en";
122
+ let rectWidth = isEn ? 326 : 186;
123
+ if (((_a = this.rectList) == null ? void 0 : _a.length) === 1) {
124
+ text = `\u2461 ${i18n.t("ClickOnTarget")}`;
125
+ rectWidth = isEn ? 232 : 142;
126
+ const radius = 2;
127
+ ctx.save();
128
+ ctx.strokeStyle = "white";
129
+ const margin = lineWidth + padding;
130
+ ctx.beginPath();
131
+ ctx.moveTo(x + margin + radius * 2, y + margin + radius);
132
+ ctx.arc(x + margin + radius, y + margin + radius, radius, 0, Math.PI * 2, true);
133
+ ctx.stroke();
134
+ ctx.restore();
135
+ }
136
+ if (this.isRunSegment) {
137
+ rectWidth = isEn ? 316 : 136;
138
+ text = i18n.t("SplittingAlgorithmPrediction");
139
+ }
140
+ ctx.save();
141
+ ctx.fillStyle = this.style.strokeColor;
142
+ ctx.fillRect(x + padding, y - padding * 4 - 1, rectWidth, 32);
143
+ ctx.restore();
144
+ ctx.save();
145
+ ctx.font = "14px Source Han Sans CN";
146
+ ctx.fillStyle = "white";
147
+ ctx.fillText(text, x + padding + 14, y - padding * 2);
148
+ ctx.restore();
149
+ super.renderCursorLine();
150
+ }
151
+ renderDrawingRect(rect, zoom, isZoom = false) {
152
+ if (this.ctx && rect) {
153
+ const transformRect = AxisUtils.changeRectByZoom(rect, isZoom ? zoom : this.zoom, this.currentPos);
154
+ const {x, y, width, height} = transformRect;
155
+ this.ctx.save();
156
+ this.ctx.lineCap = "butt";
157
+ this.ctx.lineWidth = this.style.strokeWidth;
158
+ this.ctx.strokeStyle = "white";
159
+ this.ctx.strokeRect(x, y, width, height);
160
+ this.ctx.strokeStyle = this.style.strokeColor;
161
+ this.ctx.setLineDash([6]);
162
+ this.ctx.strokeRect(x, y, width, height);
163
+ this.ctx.restore();
164
+ }
165
+ }
166
+ renderTextAttribute() {
167
+ }
168
+ renderSelectedRect() {
169
+ }
170
+ }
171
+
172
+ export { SegmentByRect as default };
@@ -1,5 +1,184 @@
1
- import c from"../../utils/tool/CommonToolUtils.js";import m from"../../utils/tool/TagUtils.js";import T from"../../utils/uuid.js";import{BasicToolOperation as D}from"./basicToolOperation.js";class R extends D{constructor(t){super(t);this.getInitResultList=(e,s)=>!(e===0||e===void 0)&&s.length===0?[]:m.getDefaultTagResult(this.config.inputList,s),this.setLabel=(e,s)=>{var i,h;if(this.isImgError||!this.basicResult&&this.dependToolName)return;const l=this.config.inputList;if(!l[e])return;const{subSelected:o}=l[e];if(e<l.length&&l[e].subSelected&&o&&s<o.length){const d=l[e].value;let r=(i=o[s])==null?void 0:i.value;const g=(h=l[e])==null?void 0:h.isMulti,u=this.tagResult.filter(f=>{const n=`${f.sourceID}`;return c.isSameSourceID(n,this.sourceID)})[0];if(u){let f=0;const{result:n}=u;u.sourceID===0&&(u.sourceID="0");for(const p in u.result)if(p===l[e].value){if(f++,g===!0){const a=n[p].split(";").filter(I=>I!==""),b=a.indexOf(r);b===-1?a.push(r):a.splice(b,1),r=a.join(";")}r===""?Object.keys(n).length===1?this.tagResult=this.tagResult.filter(a=>{const b=`${a.sourceID}`;return c.isDifferSourceID(b,this.sourceID)}):Object.keys(n).length>1&&delete n[p]:n[p]=r}f===0&&Object.assign(u.result,{[d]:r})}else this.tagResult=[{sourceID:this.sourceID,id:T(8,62),result:{[d]:r}}];this.render()}},this.clearResult=(e=!0,s)=>{s?this.tagResult=this.tagResult.map(i=>((i==null?void 0:i.result[s])&&delete i.result[s],i)):this.tagResult=[],this.render()},this.config=c.jsonParser(t.config),this.tagResult=[],this.labelSelectedList=[],this.setShowDefaultCursor(!0)}destroy(){this.clearTag(),super.destroy()}setResult(t){this.tagResult=t,this.render()}get currentPageResult(){return[this.currentTagResult]}get currentTagResult(){var t;return(t=this.tagResult.filter(e=>{const s=`${e.sourceID}`;return c.isSameSourceID(s,this.sourceID)})[0])!=null?t:{}}get sourceID(){return c.getSourceID(this.basicResult)}onKeyDown(t){if(!c.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;let{keyCode:e}=t;if(e&&(e<=57&&e>=49||e<=105&&e>=97)){if(e>57?e-=97:e-=49,this.config.inputList.length===1){this.labelSelectedList=[0,e],this.setLabel(0,e),setTimeout(()=>{this.labelSelectedList=[],this.render()},500);return}this.labelSelectedList.length===1?(this.labelSelectedList=[this.labelSelectedList[0],e],this.setLabel(this.labelSelectedList[0],e),setTimeout(()=>{this.labelSelectedList=[],this.render()},500)):(this.labelSelectedList=[e],this.emit("expend"))}}clearTag(){var t;const e=(t=this.canvas)==null?void 0:t.parentNode,s=window.self.document.getElementById("tagToolTag");s&&e&&e.contains(s)&&(e==null||e.removeChild(s))}renderTag(){var t,e,s,i,h,l;if(this.clearTag(),!(((t=this.tagResult)==null?void 0:t.length)>0))return;const o=document.createElement("div"),d=m.getTagNameList((s=(e=this.currentTagResult)==null?void 0:e.result)!=null?s:{},this.config.inputList);o.innerHTML=(i=d.reduce((r,g)=>`${r}${g.keyName}: ${g.value.join(" \u3001 ")}
2
- `,""))!=null?i:"",o.setAttribute("id","tagToolTag"),o.setAttribute("style",`
1
+ import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
2
+ import TagUtil from '../../utils/tool/TagUtils.js';
3
+ import uuid from '../../utils/uuid.js';
4
+ import { BasicToolOperation } from './basicToolOperation.js';
5
+
6
+ class TagOperation extends BasicToolOperation {
7
+ constructor(props) {
8
+ super(props);
9
+ this.getInitResultList = (dataSourceStep, basicResultList) => {
10
+ if (!(dataSourceStep === 0 || dataSourceStep === void 0) && basicResultList.length === 0) {
11
+ return [];
12
+ }
13
+ return TagUtil.getDefaultTagResult(this.config.inputList, basicResultList);
14
+ };
15
+ this.setLabel = (i, j) => {
16
+ var _a, _b;
17
+ if (this.isImgError) {
18
+ return;
19
+ }
20
+ if (!this.basicResult && this.dependToolName) {
21
+ return;
22
+ }
23
+ const labelInfoSet = this.config.inputList;
24
+ if (!labelInfoSet[i]) {
25
+ return;
26
+ }
27
+ const {subSelected} = labelInfoSet[i];
28
+ if (i < labelInfoSet.length && labelInfoSet[i].subSelected && subSelected && j < subSelected.length) {
29
+ const key = labelInfoSet[i].value;
30
+ let value = (_a = subSelected[j]) == null ? void 0 : _a.value;
31
+ const isMulti = (_b = labelInfoSet[i]) == null ? void 0 : _b.isMulti;
32
+ const basicTagResult = this.tagResult.filter((v) => {
33
+ const basicSourceID = `${v.sourceID}`;
34
+ return CommonToolUtils.isSameSourceID(basicSourceID, this.sourceID);
35
+ })[0];
36
+ if (basicTagResult) {
37
+ let times = 0;
38
+ const {result} = basicTagResult;
39
+ if (basicTagResult.sourceID === 0) {
40
+ basicTagResult.sourceID = "0";
41
+ }
42
+ for (const oldKey in basicTagResult.result) {
43
+ if (oldKey === labelInfoSet[i].value) {
44
+ times++;
45
+ if (isMulti === true) {
46
+ const keyList = result[oldKey].split(";").filter((v) => v !== "");
47
+ const index = keyList.indexOf(value);
48
+ if (index === -1) {
49
+ keyList.push(value);
50
+ } else {
51
+ keyList.splice(index, 1);
52
+ }
53
+ value = keyList.join(";");
54
+ }
55
+ if (value === "") {
56
+ if (Object.keys(result).length === 1) {
57
+ this.tagResult = this.tagResult.filter((v) => {
58
+ const basicSourceID = `${v.sourceID}`;
59
+ return CommonToolUtils.isDifferSourceID(basicSourceID, this.sourceID);
60
+ });
61
+ } else if (Object.keys(result).length > 1) {
62
+ delete result[oldKey];
63
+ }
64
+ } else {
65
+ result[oldKey] = value;
66
+ }
67
+ }
68
+ }
69
+ if (times === 0) {
70
+ Object.assign(basicTagResult.result, {[key]: value});
71
+ }
72
+ } else {
73
+ this.tagResult = [
74
+ {
75
+ sourceID: this.sourceID,
76
+ id: uuid(8, 62),
77
+ result: {
78
+ [key]: value
79
+ }
80
+ }
81
+ ];
82
+ }
83
+ this.render();
84
+ }
85
+ };
86
+ this.clearResult = (sendMessage = true, value) => {
87
+ if (value) {
88
+ this.tagResult = this.tagResult.map((v) => {
89
+ if (v == null ? void 0 : v.result[value]) {
90
+ delete v.result[value];
91
+ }
92
+ return v;
93
+ });
94
+ } else {
95
+ this.tagResult = [];
96
+ }
97
+ this.render();
98
+ };
99
+ this.config = CommonToolUtils.jsonParser(props.config);
100
+ this.tagResult = [];
101
+ this.labelSelectedList = [];
102
+ this.setShowDefaultCursor(true);
103
+ }
104
+ destroy() {
105
+ this.clearTag();
106
+ super.destroy();
107
+ }
108
+ setResult(tagResult) {
109
+ this.tagResult = tagResult;
110
+ this.render();
111
+ }
112
+ get currentPageResult() {
113
+ return [this.currentTagResult];
114
+ }
115
+ get currentTagResult() {
116
+ var _a;
117
+ return (_a = this.tagResult.filter((v) => {
118
+ const basicSourceID = `${v.sourceID}`;
119
+ return CommonToolUtils.isSameSourceID(basicSourceID, this.sourceID);
120
+ })[0]) != null ? _a : {};
121
+ }
122
+ get sourceID() {
123
+ return CommonToolUtils.getSourceID(this.basicResult);
124
+ }
125
+ onKeyDown(e) {
126
+ if (!CommonToolUtils.hotkeyFilter(e) || super.onKeyDown(e) === false) {
127
+ return;
128
+ }
129
+ let {keyCode} = e;
130
+ if (keyCode) {
131
+ if (keyCode <= 57 && keyCode >= 49 || keyCode <= 105 && keyCode >= 97) {
132
+ if (keyCode > 57) {
133
+ keyCode -= 97;
134
+ } else {
135
+ keyCode -= 49;
136
+ }
137
+ if (this.config.inputList.length === 1) {
138
+ this.labelSelectedList = [0, keyCode];
139
+ this.setLabel(0, keyCode);
140
+ setTimeout(() => {
141
+ this.labelSelectedList = [];
142
+ this.render();
143
+ }, 500);
144
+ return;
145
+ }
146
+ if (this.labelSelectedList.length === 1) {
147
+ this.labelSelectedList = [this.labelSelectedList[0], keyCode];
148
+ this.setLabel(this.labelSelectedList[0], keyCode);
149
+ setTimeout(() => {
150
+ this.labelSelectedList = [];
151
+ this.render();
152
+ }, 500);
153
+ } else {
154
+ this.labelSelectedList = [keyCode];
155
+ this.emit("expend");
156
+ }
157
+ }
158
+ }
159
+ }
160
+ clearTag() {
161
+ var _a;
162
+ const parentNode = (_a = this.canvas) == null ? void 0 : _a.parentNode;
163
+ const oldDom = window.self.document.getElementById("tagToolTag");
164
+ if (oldDom && parentNode && parentNode.contains(oldDom)) {
165
+ parentNode == null ? void 0 : parentNode.removeChild(oldDom);
166
+ }
167
+ }
168
+ renderTag() {
169
+ var _a, _b, _c, _d, _e, _f;
170
+ this.clearTag();
171
+ if (!(((_a = this.tagResult) == null ? void 0 : _a.length) > 0)) {
172
+ return;
173
+ }
174
+ const dom = document.createElement("div");
175
+ const tagInfoList = TagUtil.getTagNameList((_c = (_b = this.currentTagResult) == null ? void 0 : _b.result) != null ? _c : {}, this.config.inputList);
176
+ dom.innerHTML = (_d = tagInfoList.reduce((acc, cur) => {
177
+ return `${acc}${cur.keyName}: ${cur.value.join(` \u3001 `)}
178
+ `;
179
+ }, "")) != null ? _d : "";
180
+ dom.setAttribute("id", "tagToolTag");
181
+ dom.setAttribute("style", `
3
182
  position: absolute;
4
183
  top: 0;
5
184
  right: 0;
@@ -16,4 +195,21 @@ import c from"../../utils/tool/CommonToolUtils.js";import m from"../../utils/too
16
195
  background: rgba(102, 111, 255, 1);
17
196
  opacity: 0.6;
18
197
  clear: both;
19
- `),(l=(h=this.canvas)==null?void 0:h.parentNode)==null||l.appendChild(o)}render(){this.renderTag(),super.render(),this.emit("render")}exportData(){let{tagResult:t}=this;return this.isImgError&&(t=[]),[t,this.basicImgInfo]}}export{R as default};
198
+ `);
199
+ (_f = (_e = this.canvas) == null ? void 0 : _e.parentNode) == null ? void 0 : _f.appendChild(dom);
200
+ }
201
+ render() {
202
+ this.renderTag();
203
+ super.render();
204
+ this.emit("render");
205
+ }
206
+ exportData() {
207
+ let {tagResult} = this;
208
+ if (this.isImgError) {
209
+ tagResult = [];
210
+ }
211
+ return [tagResult, this.basicImgInfo];
212
+ }
213
+ }
214
+
215
+ export { TagOperation as default };