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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,174 +0,0 @@
1
- import { ECuboidDirection } from '../../constant/annotation.js';
2
- import cuboidFAB from '../../assets/attributeIcon/icon_cuboidFAB.svg.js';
3
- import cuboidMore from '../../assets/attributeIcon/icon_cuboidMore.svg.js';
4
- import cuboidRight from '../../assets/attributeIcon/icon_cuboidRight.svg.js';
5
- import cuboidLeft from '../../assets/attributeIcon/icon_cuboidLeft.svg.js';
6
- import cuboidTop from '../../assets/attributeIcon/icon_cuboidTop.svg.js';
7
-
8
- const MORE_ICON_LISTS = [
9
- {
10
- icon: cuboidRight,
11
- id: "cuboidRight"
12
- },
13
- {
14
- icon: cuboidLeft,
15
- id: "cuboidLeft"
16
- },
17
- {
18
- icon: cuboidTop,
19
- id: "cuboidTop"
20
- }
21
- ];
22
- class CuboidToggleButtonClass {
23
- constructor(props) {
24
- const {container, cuboidButtonMove, toggleDirection} = props;
25
- this.container = container;
26
- this.direction = ECuboidDirection.Front;
27
- this.isFrontSide = true;
28
- this.cuboidButtonMove = cuboidButtonMove;
29
- this.onToggleDirection = toggleDirection;
30
- this._cuboidButtonDOM = this.initCuboidButtonDOM();
31
- this._cuboidFABDOM = this.initcuboidFABDOM(cuboidFAB);
32
- this._cuboidMoreDOM = this.initcuboidMoreDOM(cuboidMore);
33
- this._cuboidMoreListDOM = this.initcuboidMoreListDOM();
34
- this.appendToContainer();
35
- }
36
- appendToContainer() {
37
- if (!this._cuboidButtonDOM || !this._cuboidFABDOM || !this._cuboidMoreDOM) {
38
- return;
39
- }
40
- this.container.appendChild(this._cuboidButtonDOM);
41
- this._cuboidButtonDOM.appendChild(this._cuboidFABDOM);
42
- this._cuboidButtonDOM.appendChild(this._cuboidMoreDOM);
43
- }
44
- initCuboidButtonDOM() {
45
- const _cuboidButtonDOM = document.createElement("div");
46
- _cuboidButtonDOM.setAttribute("id", "LABELBEE_CUBOID_BUTTON_BOX");
47
- _cuboidButtonDOM.setAttribute("style", `
48
- width: 40px;
49
- height: 74px;
50
- border-radius: 10px;
51
- background-color: #FFFFFF;
52
- z-index: 10;
53
- `);
54
- _cuboidButtonDOM.addEventListener("mouseover", (e) => {
55
- e.stopPropagation();
56
- setTimeout(() => {
57
- this.cuboidButtonMove("in");
58
- }, 100);
59
- });
60
- _cuboidButtonDOM.addEventListener("mouseleave", (e) => {
61
- e.stopPropagation();
62
- setTimeout(() => {
63
- this.cuboidButtonMove("out");
64
- }, 100);
65
- });
66
- return _cuboidButtonDOM;
67
- }
68
- initcuboidFABDOM(icon) {
69
- const _cuboidFAB = document.createElement("div");
70
- _cuboidFAB.setAttribute("id", "CUBOID_FORWARD_AND_BACK_SWITCH");
71
- _cuboidFAB.innerHTML = icon;
72
- _cuboidFAB.addEventListener("mouseup", (e) => {
73
- e.stopPropagation();
74
- this.isFrontSide = !this.isFrontSide;
75
- this.direction = this.isFrontSide ? ECuboidDirection.Front : ECuboidDirection.Back;
76
- this.onToggleDirection(this.direction);
77
- });
78
- return _cuboidFAB;
79
- }
80
- initcuboidMoreDOM(icon) {
81
- const _iconDOM = document.createElement("div");
82
- _iconDOM.setAttribute("id", "CUBOID_MORE_ICON");
83
- _iconDOM.innerHTML = icon;
84
- _iconDOM.addEventListener("mouseup", (e) => {
85
- if (this._cuboidButtonDOM && this._cuboidMoreListDOM) {
86
- if (this._cuboidButtonDOM.contains(this._cuboidMoreListDOM)) {
87
- this.clearCuboidMoreListDOM();
88
- } else {
89
- this._cuboidButtonDOM.appendChild(this._cuboidMoreListDOM);
90
- }
91
- }
92
- e.stopPropagation();
93
- });
94
- _iconDOM.addEventListener("mousedown", (e) => {
95
- e.stopPropagation();
96
- });
97
- _iconDOM.addEventListener("contextmenu", (e) => {
98
- e.stopPropagation();
99
- });
100
- return _iconDOM;
101
- }
102
- initcuboidMoreListDOM() {
103
- const cuboidMoreListDOM = document.createElement("div");
104
- cuboidMoreListDOM.setAttribute("id", "CUBOID_MORE_LIST_ICON");
105
- cuboidMoreListDOM.setAttribute("style", `
106
- height: 36px;
107
- border-radius: 10px;
108
- background-color: #FFFFFF;
109
- z-index: 10;
110
- padding: 8px 10px;
111
- position: absolute;
112
- bottom: 0px;
113
- left: 44px;
114
- display: flex;
115
- `);
116
- let str = "";
117
- const iconStyle = `margin-left:4px;margin-right:4px;display:flex;align-items:center;`;
118
- MORE_ICON_LISTS.forEach((i, index) => {
119
- const lastIconStyle = index === MORE_ICON_LISTS.length - 1 ? "margin-left:0px;margin-right:0px;" : "";
120
- str += `<span id=${i.id} key=${index} style=${iconStyle}${lastIconStyle}>${i.icon}</span>`;
121
- });
122
- cuboidMoreListDOM.innerHTML = str;
123
- cuboidMoreListDOM.childNodes.forEach((item) => {
124
- item.addEventListener("click", (e) => {
125
- e.stopPropagation();
126
- switch (item == null ? void 0 : item.id) {
127
- case "cuboidLeft":
128
- this.onToggleDirection(ECuboidDirection.Left);
129
- break;
130
- case "cuboidRight":
131
- this.onToggleDirection(ECuboidDirection.Right);
132
- break;
133
- case "cuboidTop":
134
- this.onToggleDirection(ECuboidDirection.Top);
135
- break;
136
- }
137
- this.clearCuboidMoreListDOM();
138
- this.cuboidButtonMove("out");
139
- });
140
- });
141
- return cuboidMoreListDOM;
142
- }
143
- update(position) {
144
- var _a;
145
- const {left, top, color} = position;
146
- (_a = this._cuboidButtonDOM) == null ? void 0 : _a.setAttribute("style", `
147
- position: absolute;
148
- font-size: 14px;
149
- left:${left}px;
150
- top: ${top}px;
151
- color: ${color};
152
- width: 41px;
153
- height: 74px;
154
- border-radius: 10px;
155
- background-color: #FFFFFF;
156
- cursor: pointer;
157
- text-align: center;
158
- padding-top: 10px;
159
- z-index: 10;
160
- `);
161
- }
162
- clearCuboidButtonDOM() {
163
- if (this._cuboidButtonDOM && this.container.contains(this._cuboidButtonDOM)) {
164
- this.container.removeChild(this._cuboidButtonDOM);
165
- }
166
- }
167
- clearCuboidMoreListDOM() {
168
- if (this._cuboidButtonDOM && this._cuboidMoreListDOM && this._cuboidButtonDOM.contains(this._cuboidMoreListDOM)) {
169
- this._cuboidButtonDOM.removeChild(this._cuboidMoreListDOM);
170
- }
171
- }
172
- }
173
-
174
- export { CuboidToggleButtonClass as default };
@@ -1,249 +0,0 @@
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 };