@labelbee/lb-annotation 1.12.0 → 1.12.1

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.
@@ -0,0 +1,174 @@
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 };