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

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 (189) 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/types/core/pointCloud/index.d.ts +2 -2
  63. package/dist/utils/ActionsHistory.js +1 -84
  64. package/dist/utils/ImgUtils.js +1 -23
  65. package/dist/utils/MathUtils.js +2 -385
  66. package/dist/utils/VectorUtils.js +1 -25
  67. package/dist/utils/tool/AttributeUtils.js +1 -218
  68. package/dist/utils/tool/AxisUtils.js +1 -340
  69. package/dist/utils/tool/CanvasUtils.js +1 -62
  70. package/dist/utils/tool/CommonToolUtils.js +1 -174
  71. package/dist/utils/tool/CuboidUtils.js +1 -704
  72. package/dist/utils/tool/DblClickEventListener.js +1 -102
  73. package/dist/utils/tool/DrawUtils.js +3 -492
  74. package/dist/utils/tool/EnhanceCommonToolUtils.js +1 -53
  75. package/dist/utils/tool/ImgPosUtils.js +1 -58
  76. package/dist/utils/tool/LineToolUtils.js +1 -261
  77. package/dist/utils/tool/MarkerUtils.js +1 -56
  78. package/dist/utils/tool/PolygonUtils.js +1 -460
  79. package/dist/utils/tool/RectUtils.js +1 -155
  80. package/dist/utils/tool/RenderDomClass.js +7 -57
  81. package/dist/utils/tool/RenderDomUtils.js +4 -21
  82. package/dist/utils/tool/StyleUtils.js +1 -31
  83. package/dist/utils/tool/TagUtils.js +1 -129
  84. package/dist/utils/tool/UnitUtils.js +1 -12
  85. package/dist/utils/tool/ZoomUtils.js +1 -72
  86. package/dist/utils/tool/polygonTool.js +1 -133
  87. package/dist/utils/uuid.js +1 -26
  88. package/es/_virtual/MathUtilsWorker.js +1 -6
  89. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +2 -31
  90. package/es/_virtual/filterBoxWorker.js +1 -6
  91. package/es/_virtual/highlightWorker.js +1 -6
  92. package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +1 -3
  93. package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +1 -3
  94. package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +1 -3
  95. package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +1 -3
  96. package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +1 -3
  97. package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +1 -3
  98. package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +1 -3
  99. package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +1 -3
  100. package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +1 -3
  101. package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +1 -3
  102. package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -3
  103. package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +7 -3
  104. package/es/assets/attributeIcon/icon_cuboidMore.svg.js +5 -3
  105. package/es/assets/attributeIcon/icon_cuboidRight.svg.js +5 -3
  106. package/es/assets/attributeIcon/icon_cuboidTop.svg.js +12 -3
  107. package/es/assets/attributeIcon/icon_editFEN.svg.js +1 -3
  108. package/es/assets/attributeIcon/icon_editHUANG.svg.js +1 -3
  109. package/es/assets/attributeIcon/icon_editLAN.svg.js +1 -3
  110. package/es/assets/attributeIcon/icon_editLV.svg.js +1 -3
  111. package/es/assets/attributeIcon/icon_editQING.svg.js +1 -3
  112. package/es/constant/annotation.js +1 -113
  113. package/es/constant/annotationTask.js +1 -25
  114. package/es/constant/defaultConfig.js +1 -260
  115. package/es/constant/keyCode.js +1 -36
  116. package/es/constant/style.js +1 -74
  117. package/es/constant/tool.js +1 -220
  118. package/es/core/index.js +1 -148
  119. package/es/core/pointCloud/OrbitControls.js +1 -661
  120. package/es/core/pointCloud/PCDLoader.js +2 -256
  121. package/es/core/pointCloud/annotation.js +1 -211
  122. package/es/core/pointCloud/cache.js +1 -49
  123. package/es/core/pointCloud/index.js +5 -962
  124. package/es/core/pointCloud/matrix.js +1 -109
  125. package/es/core/scheduler.js +1 -228
  126. package/es/core/toolOperation/LineToolOperation.js +1 -1421
  127. package/es/core/toolOperation/ScribbleTool.js +1 -290
  128. package/es/core/toolOperation/TextToolOperation.js +1 -129
  129. package/es/core/toolOperation/ViewOperation.js +1 -549
  130. package/es/core/toolOperation/basicToolOperation.js +1 -877
  131. package/es/core/toolOperation/checkOperation.js +1 -206
  132. package/es/core/toolOperation/cuboidOperation.js +1 -752
  133. package/es/core/toolOperation/cuboidToggleButtonClass.js +7 -150
  134. package/es/core/toolOperation/eventListener.js +1 -35
  135. package/es/core/toolOperation/measureOperation.js +1 -39
  136. package/es/core/toolOperation/pointCloud2dOperation.js +1 -359
  137. package/es/core/toolOperation/pointOperation.js +1 -690
  138. package/es/core/toolOperation/polygonOperation.js +1 -1245
  139. package/es/core/toolOperation/rectOperation.js +1 -1228
  140. package/es/core/toolOperation/segmentByRect.js +1 -172
  141. package/es/core/toolOperation/tagOperation.js +3 -199
  142. package/es/core/toolOperation/textAttributeClass.js +16 -180
  143. package/es/index.js +1 -46
  144. package/es/locales/constants.js +1 -22
  145. package/es/locales/en_US/message.js +1 -23
  146. package/es/locales/index.js +1 -17
  147. package/es/locales/zh_CN/message.js +1 -23
  148. package/es/newCore/CanvasScheduler.js +1 -31
  149. package/es/utils/ActionsHistory.js +1 -78
  150. package/es/utils/ImgUtils.js +1 -21
  151. package/es/utils/MathUtils.js +2 -380
  152. package/es/utils/VectorUtils.js +1 -23
  153. package/es/utils/tool/AttributeUtils.js +1 -212
  154. package/es/utils/tool/AxisUtils.js +1 -335
  155. package/es/utils/tool/CanvasUtils.js +1 -60
  156. package/es/utils/tool/CommonToolUtils.js +1 -172
  157. package/es/utils/tool/CuboidUtils.js +1 -680
  158. package/es/utils/tool/DblClickEventListener.js +1 -100
  159. package/es/utils/tool/DrawUtils.js +3 -490
  160. package/es/utils/tool/EnhanceCommonToolUtils.js +1 -48
  161. package/es/utils/tool/ImgPosUtils.js +1 -56
  162. package/es/utils/tool/LineToolUtils.js +1 -255
  163. package/es/utils/tool/MarkerUtils.js +1 -54
  164. package/es/utils/tool/PolygonUtils.js +1 -458
  165. package/es/utils/tool/RectUtils.js +1 -153
  166. package/es/utils/tool/RenderDomClass.js +7 -55
  167. package/es/utils/tool/RenderDomUtils.js +4 -19
  168. package/es/utils/tool/StyleUtils.js +1 -29
  169. package/es/utils/tool/TagUtils.js +1 -127
  170. package/es/utils/tool/UnitUtils.js +1 -10
  171. package/es/utils/tool/ZoomUtils.js +1 -70
  172. package/es/utils/tool/polygonTool.js +1 -126
  173. package/es/utils/uuid.js +1 -24
  174. package/package.json +3 -4
  175. package/LICENSE +0 -203
  176. package/dist/core/pointCloud/segmentation.js +0 -144
  177. package/dist/core/pointCloud/selector/Sse3dLassoSelector.js +0 -26
  178. package/dist/core/pointCloud/selector/Sse3dSelector.js +0 -16
  179. package/dist/types/core/pointCloud/segmentation.d.ts +0 -0
  180. package/dist/types/core/pointCloud/selector/Sse3dLassoSelector.d.ts +0 -0
  181. package/dist/types/core/pointCloud/selector/Sse3dSelector.d.ts +0 -0
  182. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +0 -12
  183. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +0 -7
  184. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +0 -11
  185. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +0 -18
  186. package/es/core/pointCloud/segmentation.js +0 -120
  187. package/es/core/pointCloud/selector/Sse3dLassoSelector.js +0 -24
  188. package/es/core/pointCloud/selector/Sse3dSelector.js +0 -14
  189. package/es/core/toolOperation/scribbleTool2.js +0 -249
@@ -1,290 +1 @@
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.getCoordinateUnderZoomByRotate(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
- switch (pattern) {
56
- case EScribblePattern.Erase: {
57
- this.setCustomCursor(this.cursorErase);
58
- break;
59
- }
60
- default: {
61
- this.setCustomCursor("none");
62
- break;
63
- }
64
- }
65
- };
66
- var _a;
67
- this.penSize = DEFAULT_PEN_SIZE;
68
- if (((_a = this.config.attributeList) == null ? void 0 : _a.length) > 0) {
69
- const firstAttributeInfo = this.config.attributeList[0];
70
- this.setDefaultAttribute(firstAttributeInfo.value);
71
- }
72
- }
73
- get cursorErase() {
74
- const svgIcon = `<?xml version="1.0" encoding="UTF-8"?><svg width="24" heighst="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#icon-65e7e1747c11bad3)"><path d="M44.7818 24.1702L31.918 7.09935L14.1348 20.5L27.5 37L30.8556 34.6643L44.7818 24.1702Z" fill="#141414" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M27.4998 37L23.6613 40.0748L13.0978 40.074L10.4973 36.6231L4.06543 28.0876L14.4998 20.2248" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M13.2056 40.072L44.5653 40.072" stroke="#000000" stroke-width="4" stroke-linecap="round"/></g><defs><clipPath id="icon-65e7e1747c11bad3"><rect width="48" height="48" fill="#df4c4c"/></clipPath></defs></svg>`;
75
- const iconUrl = `data:image/svg+xml;base64,${window.btoa(unescape(encodeURIComponent(svgIcon)))}`;
76
- return `url(${iconUrl}) 0 0, auto`;
77
- }
78
- get defaultCursor() {
79
- if (this.action === EScribblePattern.Erase) {
80
- return this.cursorErase;
81
- }
82
- return this.isShowDefaultCursor ? "default" : "none";
83
- }
84
- get color() {
85
- var _a, _b;
86
- return (_b = (_a = this == null ? void 0 : this.defaultAttributeInfo) == null ? void 0 : _a.color) != null ? _b : DEFAULT_COLOR;
87
- }
88
- get penSizeWithZoom() {
89
- return this.penSize / this.zoom;
90
- }
91
- get cacheCanvasToDataUrl() {
92
- var _a;
93
- return (_a = this.cacheCanvas) == null ? void 0 : _a.toDataURL("image/png", 0);
94
- }
95
- setPenSize(size) {
96
- this.penSize = size;
97
- }
98
- initCacheCanvas(imgNode) {
99
- if (this.cacheCanvas || !imgNode) {
100
- return;
101
- }
102
- const {canvas, ctx} = ImgConversionUtils.createCanvas(imgNode);
103
- this.cacheCanvas = canvas;
104
- this.cacheContext = ctx;
105
- }
106
- updateCacheCanvasSize(imgNode) {
107
- if (this.cacheCanvas) {
108
- this.cacheCanvas.width = imgNode.width;
109
- this.cacheCanvas.height = imgNode.height;
110
- }
111
- }
112
- updateUrl2CacheContext(url) {
113
- ImgConversionUtils.createImgDom(url).then((img) => {
114
- if (!this.cacheContext) {
115
- this.initCacheCanvas(img);
116
- }
117
- if (this.cacheContext) {
118
- this.cacheContext.save();
119
- this.clearCacheCanvas();
120
- this.cacheContext.drawImage(img, 0, 0, img.width, img.height);
121
- this.cacheContext.restore();
122
- this.render();
123
- }
124
- });
125
- }
126
- setImgNode(imgNode, basicImgInfo) {
127
- super.setImgNode(imgNode, basicImgInfo);
128
- if (this.cacheCanvas) {
129
- this.updateCacheCanvasSize(imgNode);
130
- } else {
131
- this.initCacheCanvas(imgNode);
132
- }
133
- }
134
- setResult(data) {
135
- var _a, _b;
136
- let {url} = (_a = data == null ? void 0 : data[0]) != null ? _a : {};
137
- this.clearCacheCanvas();
138
- if (!url) {
139
- url = (_b = this.cacheCanvasToDataUrl) != null ? _b : "";
140
- }
141
- this.history.initRecord([url], true);
142
- if (!url) {
143
- this.render();
144
- return;
145
- }
146
- this.updateUrl2CacheContext(url);
147
- }
148
- onKeyDown(e) {
149
- if (!CommonToolUtils.hotkeyFilter(e) || super.onKeyDown(e) === false) {
150
- return;
151
- }
152
- const {keyCode} = e;
153
- const keyCode2Attribute = AttributeUtils.getAttributeByKeycode(keyCode, this.config.attributeList);
154
- if (keyCode2Attribute !== void 0) {
155
- this.setDefaultAttribute(keyCode2Attribute);
156
- }
157
- }
158
- eventBinding() {
159
- super.eventBinding();
160
- }
161
- setDefaultAttribute(attributeValue) {
162
- const attributeInfo = this.config.attributeList.find((v) => v.value === attributeValue);
163
- if (attributeInfo) {
164
- this.defaultAttribute = attributeInfo.value;
165
- this.defaultAttributeInfo = attributeInfo;
166
- this.emit("changeAttributeSidebar");
167
- this.render();
168
- }
169
- }
170
- clearStatusAfterLeave() {
171
- this.onScribbleEnd();
172
- this.startPoint = void 0;
173
- }
174
- onMouseLeave() {
175
- super.onMouseLeave();
176
- this.clearStatusAfterLeave();
177
- }
178
- onScribbleStart(e) {
179
- if (!this.cacheContext) {
180
- return;
181
- }
182
- this.cacheContext.save();
183
- this.cacheContext.beginPath();
184
- this.cacheContext.strokeStyle = this.color;
185
- this.cacheContext.lineWidth = this.penSizeWithZoom;
186
- this.cacheContext.lineCap = "round";
187
- this.cacheContext.lineJoin = "round";
188
- const originCoordinate = this.getOriginCoordinate(e);
189
- this.cacheContext.moveTo(originCoordinate.x, originCoordinate.y);
190
- this.startPoint = originCoordinate;
191
- }
192
- onScribbleMove(e) {
193
- if (e.buttons === 1 && this.cacheContext && this.startPoint) {
194
- const originCoordinate = this.getOriginCoordinate(e);
195
- this.cacheContext.lineTo(originCoordinate.x, originCoordinate.y);
196
- this.cacheContext.stroke();
197
- }
198
- }
199
- onScribbleEnd() {
200
- var _a, _b;
201
- if (this.startPoint) {
202
- (_a = this.cacheContext) == null ? void 0 : _a.closePath();
203
- (_b = this.cacheContext) == null ? void 0 : _b.restore();
204
- this.startPoint = void 0;
205
- this.history.pushHistory(this.cacheCanvasToDataUrl);
206
- }
207
- }
208
- eraseArc(e) {
209
- var _a;
210
- if (this.cacheContext) {
211
- const originCoordinate = this.getOriginCoordinate(e);
212
- this.cacheContext.save();
213
- this.cacheContext.beginPath();
214
- this.cacheContext.arc(originCoordinate.x, originCoordinate.y, this.penSizeWithZoom / 2, 0, Math.PI * 2, false);
215
- this.cacheContext.clip();
216
- this.cacheContext.clearRect(0, 0, this.cacheContext.canvas.width, this.cacheContext.canvas.height);
217
- (_a = this.cacheContext) == null ? void 0 : _a.restore();
218
- }
219
- }
220
- onEraseStart(e) {
221
- if (!this.cacheContext || e.buttons !== 1) {
222
- return;
223
- }
224
- this.eraseArc(e);
225
- }
226
- onEraseMove(e) {
227
- if (!this.cacheContext || e.buttons !== 1) {
228
- return;
229
- }
230
- this.eraseArc(e);
231
- }
232
- onEraseEnd() {
233
- }
234
- exportData() {
235
- const imgBase64 = this.cacheCanvasToDataUrl;
236
- return [[], this.basicImgInfo, {imgBase64}];
237
- }
238
- clearCacheCanvas() {
239
- var _a;
240
- (_a = this.cacheContext) == null ? void 0 : _a.clearRect(0, 0, this.cacheContext.canvas.width, this.cacheContext.canvas.height);
241
- this.render();
242
- }
243
- clearResult() {
244
- this.clearCacheCanvas();
245
- this.history.pushHistory(this.cacheCanvasToDataUrl);
246
- }
247
- renderPoint(radius) {
248
- DrawUtils.drawCircleWithFill(this.canvas, this.coord, radius, {color: this.color});
249
- }
250
- renderBorderPoint(radius) {
251
- DrawUtils.drawCircle(this.canvas, this.coord, radius, {color: "black"});
252
- }
253
- render() {
254
- super.render();
255
- if (!this.ctx || !this.cacheCanvas) {
256
- return;
257
- }
258
- this.ctx.save();
259
- this.ctx.globalAlpha = 0.5;
260
- DrawUtils.drawImg(this.canvas, this.cacheCanvas, {
261
- zoom: this.zoom,
262
- currentPos: this.currentPos,
263
- rotate: this.rotate
264
- });
265
- this.ctx.restore();
266
- if (this.forbidOperation || this.forbidCursorLine) {
267
- return;
268
- }
269
- const radius = this.penSize / 2;
270
- if (this.action === EScribblePattern.Erase) {
271
- this.renderBorderPoint(radius);
272
- } else {
273
- this.renderPoint(radius);
274
- }
275
- }
276
- undo() {
277
- const url = this.history.undo();
278
- if (url && this.cacheCanvas) {
279
- this.updateUrl2CacheContext(url);
280
- }
281
- }
282
- redo() {
283
- const url = this.history.redo();
284
- if (url && this.cacheCanvas) {
285
- this.updateUrl2CacheContext(url);
286
- }
287
- }
288
- }
289
-
290
- export { ScribbleTool as default };
1
+ import{ImgConversionUtils as n}from"@labelbee/lb-utils";import r from"../../utils/tool/AxisUtils.js";import a from"../../utils/tool/DrawUtils.js";import{EToolName as h,EScribblePattern as o}from"../../constant/tool.js";import c from"../../utils/tool/CommonToolUtils.js";import l from"../../utils/tool/AttributeUtils.js";import{BasicToolOperation as u}from"./basicToolOperation.js";const d=20,C="white";class v extends u{constructor(t){super(t);this.toolName=h.ScribbleTool,this.action=o.Scribble,this.getOriginCoordinate=i=>r.changePointByZoom(this.getCoordinateUnderZoomByRotate(i),1/this.zoom),this.onMouseDown=i=>{super.onMouseDown(i)||this.forbidMouseOperation||!this.imgInfo||(this.initCacheCanvas(this.imgNode),this.mouseEvents("onMouseDown").call(this,i))},this.onMouseMove=i=>{super.onMouseMove(i)||this.forbidMouseOperation||!this.imgInfo||this.mouseEvents("onMouseMove").call(this,i)},this.onMouseUp=i=>{super.onMouseUp(i)||this.forbidMouseOperation||!this.imgInfo||this.mouseEvents("onMouseUp").call(this,i)},this.mouseEvents=i=>({[o.Scribble]:{onMouseMove:this.onScribbleMove,onMouseUp:this.onScribbleEnd,onMouseDown:this.onScribbleStart},[o.Erase]:{onMouseMove:this.onEraseMove,onMouseUp:this.onEraseEnd,onMouseDown:this.onEraseStart}})[this.action][i],this.setPattern=i=>{switch(this.action=i,i){case o.Erase:{this.setCustomCursor(this.cursorErase);break}default:{this.setCustomCursor("none");break}}};var e;if(this.penSize=d,((e=this.config.attributeList)==null?void 0:e.length)>0){const i=this.config.attributeList[0];this.setDefaultAttribute(i.value)}}get cursorErase(){const t='<?xml version="1.0" encoding="UTF-8"?><svg width="24" heighst="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#icon-65e7e1747c11bad3)"><path d="M44.7818 24.1702L31.918 7.09935L14.1348 20.5L27.5 37L30.8556 34.6643L44.7818 24.1702Z" fill="#141414" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M27.4998 37L23.6613 40.0748L13.0978 40.074L10.4973 36.6231L4.06543 28.0876L14.4998 20.2248" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M13.2056 40.072L44.5653 40.072" stroke="#000000" stroke-width="4" stroke-linecap="round"/></g><defs><clipPath id="icon-65e7e1747c11bad3"><rect width="48" height="48" fill="#df4c4c"/></clipPath></defs></svg>';return`url(${`data:image/svg+xml;base64,${window.btoa(unescape(encodeURIComponent(t)))}`}) 0 0, auto`}get defaultCursor(){return this.action===o.Erase?this.cursorErase:this.isShowDefaultCursor?"default":"none"}get color(){var t,e;return(e=(t=this==null?void 0:this.defaultAttributeInfo)==null?void 0:t.color)!=null?e:C}get penSizeWithZoom(){return this.penSize/this.zoom}get cacheCanvasToDataUrl(){var t;return(t=this.cacheCanvas)==null?void 0:t.toDataURL("image/png",0)}setPenSize(t){this.penSize=t}initCacheCanvas(t){if(this.cacheCanvas||!t)return;const{canvas:e,ctx:i}=n.createCanvas(t);this.cacheCanvas=e,this.cacheContext=i}updateCacheCanvasSize(t){this.cacheCanvas&&(this.cacheCanvas.width=t.width,this.cacheCanvas.height=t.height)}updateUrl2CacheContext(t){n.createImgDom(t).then(e=>{this.cacheContext||this.initCacheCanvas(e),this.cacheContext&&(this.cacheContext.save(),this.clearCacheCanvas(),this.cacheContext.drawImage(e,0,0,e.width,e.height),this.cacheContext.restore(),this.render())})}setImgNode(t,e){super.setImgNode(t,e),this.cacheCanvas?this.updateCacheCanvasSize(t):this.initCacheCanvas(t)}setResult(t){var e,i;let{url:s}=(e=t==null?void 0:t[0])!=null?e:{};if(this.clearCacheCanvas(),s||(s=(i=this.cacheCanvasToDataUrl)!=null?i:""),this.history.initRecord([s],!0),!s){this.render();return}this.updateUrl2CacheContext(s)}onKeyDown(t){if(!c.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t,i=l.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}eventBinding(){super.eventBinding()}setDefaultAttribute(t){const e=this.config.attributeList.find(i=>i.value===t);e&&(this.defaultAttribute=e.value,this.defaultAttributeInfo=e,this.emit("changeAttributeSidebar"),this.render())}clearStatusAfterLeave(){this.onScribbleEnd(),this.startPoint=void 0}onMouseLeave(){super.onMouseLeave(),this.clearStatusAfterLeave()}onScribbleStart(t){if(!this.cacheContext)return;this.cacheContext.save(),this.cacheContext.beginPath(),this.cacheContext.strokeStyle=this.color,this.cacheContext.lineWidth=this.penSizeWithZoom,this.cacheContext.lineCap="round",this.cacheContext.lineJoin="round";const e=this.getOriginCoordinate(t);this.cacheContext.moveTo(e.x,e.y),this.startPoint=e}onScribbleMove(t){if(t.buttons===1&&this.cacheContext&&this.startPoint){const e=this.getOriginCoordinate(t);this.cacheContext.lineTo(e.x,e.y),this.cacheContext.stroke()}}onScribbleEnd(){var t,e;this.startPoint&&((t=this.cacheContext)==null||t.closePath(),(e=this.cacheContext)==null||e.restore(),this.startPoint=void 0,this.history.pushHistory(this.cacheCanvasToDataUrl))}eraseArc(t){var e;if(this.cacheContext){const i=this.getOriginCoordinate(t);this.cacheContext.save(),this.cacheContext.beginPath(),this.cacheContext.arc(i.x,i.y,this.penSizeWithZoom/2,0,Math.PI*2,!1),this.cacheContext.clip(),this.cacheContext.clearRect(0,0,this.cacheContext.canvas.width,this.cacheContext.canvas.height),(e=this.cacheContext)==null||e.restore()}}onEraseStart(t){!this.cacheContext||t.buttons!==1||this.eraseArc(t)}onEraseMove(t){!this.cacheContext||t.buttons!==1||this.eraseArc(t)}onEraseEnd(){}exportData(){const t=this.cacheCanvasToDataUrl;return[[],this.basicImgInfo,{imgBase64:t}]}clearCacheCanvas(){var t;(t=this.cacheContext)==null||t.clearRect(0,0,this.cacheContext.canvas.width,this.cacheContext.canvas.height),this.render()}clearResult(){this.clearCacheCanvas(),this.history.pushHistory(this.cacheCanvasToDataUrl)}renderPoint(t){a.drawCircleWithFill(this.canvas,this.coord,t,{color:this.color})}renderBorderPoint(t){a.drawCircle(this.canvas,this.coord,t,{color:"black"})}render(){if(super.render(),!this.ctx||!this.cacheCanvas||(this.ctx.save(),this.ctx.globalAlpha=.5,a.drawImg(this.canvas,this.cacheCanvas,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate}),this.ctx.restore(),this.forbidOperation||this.forbidCursorLine))return;const t=this.penSize/2;this.action===o.Erase?this.renderBorderPoint(t):this.renderPoint(t)}undo(){const t=this.history.undo();t&&this.cacheCanvas&&this.updateUrl2CacheContext(t)}redo(){const t=this.history.redo();t&&this.cacheCanvas&&this.updateUrl2CacheContext(t)}}export{v as default};
@@ -1,129 +1 @@
1
- import uuid from '../../utils/uuid.js';
2
- import EKeyCode from '../../constant/keyCode.js';
3
- import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
4
- import { BasicToolOperation } from './basicToolOperation.js';
5
-
6
- class TextToolOperation extends BasicToolOperation {
7
- constructor(props) {
8
- super(props);
9
- this.getSingleResult = (sourceID) => {
10
- const initValue = {};
11
- if (this.config.configList.length > 0) {
12
- this.config.configList.forEach((i) => {
13
- var _a;
14
- initValue[i.key] = (_a = i.default) != null ? _a : "";
15
- });
16
- }
17
- return {value: initValue, id: uuid(), sourceID: sourceID != null ? sourceID : CommonToolUtils.getSourceID()};
18
- };
19
- this.getInitResultList = (dataSourceStep, basicResultList) => {
20
- if (dataSourceStep > 0) {
21
- return basicResultList.map((i) => this.getSingleResult(i.id));
22
- }
23
- return [this.getSingleResult()];
24
- };
25
- this.textList = [];
26
- this.setShowDefaultCursor(true);
27
- this.setConfig(props.config);
28
- this.initTextDisplayContainer();
29
- }
30
- get dataList() {
31
- return this.textList;
32
- }
33
- get textValueContainerID() {
34
- return "textValueContainer";
35
- }
36
- get textValueContainer() {
37
- return document.getElementById(this.textValueContainerID);
38
- }
39
- get currentPageResult() {
40
- return this.textList;
41
- }
42
- setResult(textResultList) {
43
- var _a;
44
- this.textList = textResultList;
45
- this.toggleTextContainerVisible(true);
46
- const values = (_a = this.textList[0]) == null ? void 0 : _a.value;
47
- if (values) {
48
- Object.keys(values).forEach((k) => {
49
- this.renderText(k, values[k]);
50
- });
51
- }
52
- this.emit("valueUpdated");
53
- this.toggleTextContainerVisible(!!values);
54
- }
55
- updateTextValue(k, v) {
56
- this.textList[0].value[k] = v;
57
- this.renderText(k, v);
58
- this.emit("valueUpdated");
59
- }
60
- renderText(key, value) {
61
- const textDom = document.getElementById(`textKey${key}`);
62
- if (textDom) {
63
- textDom.innerText = value;
64
- }
65
- }
66
- getTextDomID(key) {
67
- return `textKey${key}`;
68
- }
69
- initTextDisplayContainer() {
70
- const dom = document.createElement("div");
71
- const domStyle = {
72
- position: "absolute",
73
- right: "0",
74
- top: "0",
75
- "z-index": "20",
76
- "max-width": "20%",
77
- "font-family": "SourceHanSansCN-Regular",
78
- background: "rgb(102, 230, 255)",
79
- color: "white",
80
- "word-break": "break-all",
81
- "line-height": "24px",
82
- "white-space": "pre-wrap",
83
- "max-height": "80%",
84
- "overflow-y": "auto",
85
- opacity: "0.6"
86
- };
87
- dom.setAttribute("style", Object.keys(domStyle).reduce((pre, key) => {
88
- pre += `${key}: ${domStyle[key]};`;
89
- return pre;
90
- }, ""));
91
- dom.setAttribute("id", this.textValueContainerID);
92
- this.config.configList.forEach((i) => {
93
- const div = document.createElement("div");
94
- const label = document.createElement("div");
95
- const value = document.createElement("div");
96
- div.setAttribute("style", "padding: 8px 16px");
97
- label.innerText = `${i.key}:`;
98
- value.innerText = "";
99
- value.setAttribute("id", this.getTextDomID(i.key));
100
- div.appendChild(label);
101
- div.appendChild(value);
102
- dom.appendChild(div);
103
- });
104
- this.container.appendChild(dom);
105
- }
106
- exportData() {
107
- return [this.textList, this.basicImgInfo];
108
- }
109
- destroyCanvas() {
110
- super.destroyCanvas();
111
- if (this.textValueContainer) {
112
- this.container.removeChild(this.textValueContainer);
113
- }
114
- }
115
- onKeyDown(e) {
116
- super.onKeyDown(e);
117
- if (e.keyCode === EKeyCode.Z) {
118
- this.toggleTextContainerVisible();
119
- }
120
- }
121
- toggleTextContainerVisible(isVisible) {
122
- if (this.textValueContainer) {
123
- const display = (isVisible !== void 0 ? !isVisible : this.textValueContainer.style.display === "block") ? "none" : "block";
124
- this.textValueContainer.style.display = display;
125
- }
126
- }
127
- }
128
-
129
- export { TextToolOperation as default };
1
+ import a from"../../utils/uuid.js";import r from"../../constant/keyCode.js";import l from"../../utils/tool/CommonToolUtils.js";import{BasicToolOperation as u}from"./basicToolOperation.js";class d extends u{constructor(t){super(t);this.getSingleResult=i=>{const e={};return this.config.configList.length>0&&this.config.configList.forEach(n=>{var o;e[n.key]=(o=n.default)!=null?o:""}),{value:e,id:a(),sourceID:i!=null?i:l.getSourceID()}},this.getInitResultList=(i,e)=>i>0?e.map(n=>this.getSingleResult(n.id)):[this.getSingleResult()],this.textList=[],this.setShowDefaultCursor(!0),this.setConfig(t.config),this.initTextDisplayContainer()}get dataList(){return this.textList}get textValueContainerID(){return"textValueContainer"}get textValueContainer(){return document.getElementById(this.textValueContainerID)}get currentPageResult(){return this.textList}setResult(t){var i;this.textList=t,this.toggleTextContainerVisible(!0);const e=(i=this.textList[0])==null?void 0:i.value;e&&Object.keys(e).forEach(n=>{this.renderText(n,e[n])}),this.emit("valueUpdated"),this.toggleTextContainerVisible(!!e)}updateTextValue(t,i){this.textList[0].value[t]=i,this.renderText(t,i),this.emit("valueUpdated")}renderText(t,i){const e=document.getElementById(`textKey${t}`);e&&(e.innerText=i)}getTextDomID(t){return`textKey${t}`}initTextDisplayContainer(){const t=document.createElement("div"),i={position:"absolute",right:"0",top:"0","z-index":"20","max-width":"20%","font-family":"SourceHanSansCN-Regular",background:"rgb(102, 230, 255)",color:"white","word-break":"break-all","line-height":"24px","white-space":"pre-wrap","max-height":"80%","overflow-y":"auto",opacity:"0.6"};t.setAttribute("style",Object.keys(i).reduce((e,n)=>(e+=`${n}: ${i[n]};`,e),"")),t.setAttribute("id",this.textValueContainerID),this.config.configList.forEach(e=>{const n=document.createElement("div"),o=document.createElement("div"),s=document.createElement("div");n.setAttribute("style","padding: 8px 16px"),o.innerText=`${e.key}:`,s.innerText="",s.setAttribute("id",this.getTextDomID(e.key)),n.appendChild(o),n.appendChild(s),t.appendChild(n)}),this.container.appendChild(t)}exportData(){return[this.textList,this.basicImgInfo]}destroyCanvas(){super.destroyCanvas(),this.textValueContainer&&this.container.removeChild(this.textValueContainer)}onKeyDown(t){super.onKeyDown(t),t.keyCode===r.Z&&this.toggleTextContainerVisible()}toggleTextContainerVisible(t){if(this.textValueContainer){const i=(t!==void 0?!t:this.textValueContainer.style.display==="block")?"none":"block";this.textValueContainer.style.display=i}}}export{d as default};