@glodon-aiot/dataset-annotation 3.16.0-alpha.41 → 3.16.0-alpha.43
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,17 +1,17 @@
|
|
|
1
|
-
var
|
|
2
|
-
import { jsx as f, jsxs as
|
|
3
|
-
import { useRef as
|
|
1
|
+
var V = Math.pow;
|
|
2
|
+
import { jsx as f, jsxs as ee } from "react/jsx-runtime";
|
|
3
|
+
import { useRef as te, useState as I, useEffect as h } from "react";
|
|
4
4
|
import { fabric as X } from "fabric";
|
|
5
5
|
import { useKeyPress as R } from "ahooks";
|
|
6
6
|
import "./style.less.mjs";
|
|
7
7
|
import le from "react-dom";
|
|
8
8
|
import { Spin as fe, Space as de, Tooltip as A, Button as L } from "antd";
|
|
9
|
-
import
|
|
9
|
+
import oe from "./RectLabel.mjs";
|
|
10
10
|
import { drawable as ue } from "./Drawable.mjs";
|
|
11
11
|
import { ZoomInOutlined as me, ZoomOutOutlined as ge, DragOutlined as he, ClearOutlined as pe } from "@ant-design/icons";
|
|
12
12
|
import be from "classnames";
|
|
13
13
|
import { approxeq as S } from "../../../../utils/index.mjs";
|
|
14
|
-
const
|
|
14
|
+
const B = (a) => {
|
|
15
15
|
a.off("mouse:down"), a.off("mouse:up");
|
|
16
16
|
}, O = (a) => {
|
|
17
17
|
var c, E, l;
|
|
@@ -31,7 +31,7 @@ const oe = (a) => {
|
|
|
31
31
|
box: (d == null ? void 0 : d.map((y) => [S(y.x - m.x, 0) ? 0 : S(y.x - m.x, p.width) ? p.width : y.x - m.x, S(y.y - m.y, 0) ? 0 : S(y.y - m.y, p.height) ? p.height : y.y - m.y])) || []
|
|
32
32
|
};
|
|
33
33
|
}, Ae = (a) => {
|
|
34
|
-
const d =
|
|
34
|
+
const d = te(null), {
|
|
35
35
|
labels: m,
|
|
36
36
|
imageUrl: p,
|
|
37
37
|
pen: c,
|
|
@@ -40,31 +40,31 @@ const oe = (a) => {
|
|
|
40
40
|
isPreLabel: y,
|
|
41
41
|
disabled: k,
|
|
42
42
|
renderLabelItem: N
|
|
43
|
-
} = a, [z,
|
|
43
|
+
} = a, [z, Z] = I(!0), [e, K] = I(), [ye, ne] = I({}), [j, W] = I(), [H, re] = I({
|
|
44
44
|
left: 0,
|
|
45
45
|
top: 0
|
|
46
|
-
}), [ie, U] =
|
|
46
|
+
}), [ie, U] = I([1, 1]), [M, q] = I(), [x, v] = I([]), w = te(/* @__PURE__ */ new Set()), [b, P] = I(k || !1), Y = (n, t) => {
|
|
47
47
|
if (!e)
|
|
48
48
|
return;
|
|
49
49
|
t || (t = {
|
|
50
50
|
x: e.getCenter().left,
|
|
51
51
|
y: e.getCenter().top
|
|
52
52
|
});
|
|
53
|
-
let
|
|
54
|
-
|
|
53
|
+
let o = e.getZoom();
|
|
54
|
+
o *= V(0.999, n), o > 20 && (o = 20), o < 0.01 && (o = 0.01), e.zoomToPoint(
|
|
55
55
|
t,
|
|
56
|
-
|
|
56
|
+
o
|
|
57
57
|
// 传入修改后的缩放级别
|
|
58
|
-
), U([
|
|
58
|
+
), U([o, o]);
|
|
59
59
|
};
|
|
60
60
|
h(() => {
|
|
61
|
-
x.forEach((
|
|
62
|
-
|
|
61
|
+
x.forEach((n) => {
|
|
62
|
+
n.renderLabel();
|
|
63
63
|
});
|
|
64
64
|
}, [ie, x, e]);
|
|
65
|
-
const
|
|
66
|
-
var
|
|
67
|
-
if (((
|
|
65
|
+
const F = (n) => {
|
|
66
|
+
var o;
|
|
67
|
+
if (((o = n.target) == null ? void 0 : o.tagName) === "INPUT" || !e)
|
|
68
68
|
return;
|
|
69
69
|
const t = e == null ? void 0 : e.getActiveObject();
|
|
70
70
|
t && v((r) => {
|
|
@@ -79,8 +79,8 @@ const oe = (a) => {
|
|
|
79
79
|
}, 100);
|
|
80
80
|
} else if (t && e) {
|
|
81
81
|
const s = r.findIndex((i) => {
|
|
82
|
-
const
|
|
83
|
-
return
|
|
82
|
+
const D = i._fabricRect;
|
|
83
|
+
return D && D === t;
|
|
84
84
|
});
|
|
85
85
|
if (s >= 0 && r[s]) {
|
|
86
86
|
const i = r[s];
|
|
@@ -93,7 +93,7 @@ const oe = (a) => {
|
|
|
93
93
|
return [...r];
|
|
94
94
|
});
|
|
95
95
|
};
|
|
96
|
-
R("Delete",
|
|
96
|
+
R("Delete", F), R("Backspace", F), R("ctrl", () => {
|
|
97
97
|
P(!0);
|
|
98
98
|
}, {
|
|
99
99
|
events: ["keydown"]
|
|
@@ -104,71 +104,71 @@ const oe = (a) => {
|
|
|
104
104
|
}), h(() => {
|
|
105
105
|
P(k || !1);
|
|
106
106
|
}, [k]);
|
|
107
|
-
const
|
|
108
|
-
e &&
|
|
109
|
-
const
|
|
110
|
-
return
|
|
107
|
+
const G = (n) => {
|
|
108
|
+
e && B(e), v((t) => {
|
|
109
|
+
const o = t.findIndex((r) => r === n);
|
|
110
|
+
return o > -1 && (t.splice(o, 1), l && l(t.map(O)), T()), [...t];
|
|
111
111
|
});
|
|
112
|
-
},
|
|
112
|
+
}, J = (n) => {
|
|
113
113
|
v((t) => {
|
|
114
|
-
const
|
|
115
|
-
return
|
|
114
|
+
const o = t.findIndex((r) => r === n);
|
|
115
|
+
return o > -1 && (t[o] = n, l && l(t.map(O))), [...t];
|
|
116
116
|
});
|
|
117
117
|
};
|
|
118
118
|
h(() => {
|
|
119
119
|
if (!e)
|
|
120
120
|
return;
|
|
121
|
-
const
|
|
121
|
+
const n = [];
|
|
122
122
|
return m.filter((t) => t.color).forEach((t) => {
|
|
123
|
-
|
|
123
|
+
n.push(new oe({
|
|
124
124
|
id: t.id,
|
|
125
125
|
name: t.label,
|
|
126
126
|
color: t.color,
|
|
127
|
-
points: t.box.map((
|
|
127
|
+
points: t.box.map((o) => [o[0] + H.left, o[1] + H.top]),
|
|
128
128
|
hideDelete: y
|
|
129
129
|
}, e, {
|
|
130
|
-
onChange:
|
|
131
|
-
onDelete:
|
|
132
|
-
renderLabelItem: N ? (
|
|
130
|
+
onChange: J,
|
|
131
|
+
onDelete: G,
|
|
132
|
+
renderLabelItem: N ? (o) => N ? N(t) : o.name : void 0
|
|
133
133
|
}));
|
|
134
|
-
}), v(
|
|
134
|
+
}), v(n), n.forEach((t) => {
|
|
135
135
|
t.render(e);
|
|
136
136
|
}), () => {
|
|
137
|
-
|
|
137
|
+
n.forEach((t) => {
|
|
138
138
|
t.canvas !== e && t.destroy();
|
|
139
139
|
});
|
|
140
140
|
};
|
|
141
141
|
}, [e, p]);
|
|
142
142
|
const T = () => {
|
|
143
|
-
e && ue(e, (
|
|
144
|
-
const t = new
|
|
145
|
-
id: (c == null ? void 0 : c.id) ||
|
|
146
|
-
name: (c == null ? void 0 : c.label) ||
|
|
147
|
-
color: (c == null ? void 0 : c.color) ||
|
|
148
|
-
points:
|
|
143
|
+
e && ue(e, (n) => {
|
|
144
|
+
const t = new oe({
|
|
145
|
+
id: (c == null ? void 0 : c.id) || n.id,
|
|
146
|
+
name: (c == null ? void 0 : c.label) || n.label,
|
|
147
|
+
color: (c == null ? void 0 : c.color) || n.color,
|
|
148
|
+
points: n.box.map((o) => [o[0], o[1]]),
|
|
149
149
|
hideDelete: y
|
|
150
150
|
}, e, {
|
|
151
|
-
onChange:
|
|
152
|
-
onDelete:
|
|
151
|
+
onChange: J,
|
|
152
|
+
onDelete: G
|
|
153
153
|
});
|
|
154
|
-
t.active = !0, v((
|
|
155
|
-
const r = [...
|
|
154
|
+
t.active = !0, v((o) => {
|
|
155
|
+
const r = [...o, t];
|
|
156
156
|
return l && l(r.map(O)), setTimeout(() => {
|
|
157
157
|
e && !b && T();
|
|
158
158
|
}, 0), r;
|
|
159
159
|
});
|
|
160
160
|
}, y);
|
|
161
161
|
}, se = () => {
|
|
162
|
-
let
|
|
162
|
+
let n = !1;
|
|
163
163
|
e && (e.on("mouse:down", (t) => {
|
|
164
|
-
|
|
164
|
+
n = !0, e.selection = !1;
|
|
165
165
|
}), e.on("mouse:move", (t) => {
|
|
166
|
-
if (
|
|
167
|
-
const
|
|
168
|
-
e.relativePan(
|
|
166
|
+
if (n && t && t.e) {
|
|
167
|
+
const o = new X.Point(t.e.movementX, t.e.movementY);
|
|
168
|
+
e.relativePan(o);
|
|
169
169
|
}
|
|
170
170
|
}), e.on("mouse:up", (t) => {
|
|
171
|
-
|
|
171
|
+
n = !1, e.selection = !0;
|
|
172
172
|
}));
|
|
173
173
|
}, ae = () => {
|
|
174
174
|
e && (e.off("mouse:down"), e.off("mouse:move"), e.off("mouse:up"));
|
|
@@ -176,8 +176,8 @@ const oe = (a) => {
|
|
|
176
176
|
h(() => {
|
|
177
177
|
if (!e)
|
|
178
178
|
return;
|
|
179
|
-
const
|
|
180
|
-
const
|
|
179
|
+
const n = (t) => {
|
|
180
|
+
const o = e, r = o == null ? void 0 : o._currentTransform;
|
|
181
181
|
if (!r)
|
|
182
182
|
return;
|
|
183
183
|
const u = r.action;
|
|
@@ -186,27 +186,27 @@ const oe = (a) => {
|
|
|
186
186
|
const s = e.backgroundImage, i = s == null ? void 0 : s.aCoords;
|
|
187
187
|
if (!i)
|
|
188
188
|
return;
|
|
189
|
-
const
|
|
190
|
-
if (
|
|
191
|
-
const C =
|
|
189
|
+
const D = e.getPointer(t.e);
|
|
190
|
+
if (D.x < i.tl.x || D.x > i.br.x || D.y < i.tl.y || D.y > i.br.y) {
|
|
191
|
+
const C = o == null ? void 0 : o._onMouseUp;
|
|
192
192
|
typeof C == "function" && C(t.e);
|
|
193
193
|
}
|
|
194
194
|
};
|
|
195
|
-
return e.on("mouse:move",
|
|
196
|
-
e.off("mouse:move",
|
|
195
|
+
return e.on("mouse:move", n), () => {
|
|
196
|
+
e.off("mouse:move", n);
|
|
197
197
|
};
|
|
198
198
|
}, [e]), h(() => {
|
|
199
199
|
if (!e)
|
|
200
200
|
return;
|
|
201
|
-
const
|
|
202
|
-
const
|
|
203
|
-
if (!!!(
|
|
201
|
+
const n = (t) => {
|
|
202
|
+
const o = e;
|
|
203
|
+
if (!!!(o != null && o._currentTransform))
|
|
204
204
|
return;
|
|
205
|
-
const u =
|
|
205
|
+
const u = o == null ? void 0 : o._onMouseUp;
|
|
206
206
|
typeof u == "function" && u(t.e);
|
|
207
207
|
};
|
|
208
|
-
return e.on("mouse:out",
|
|
209
|
-
e.off("mouse:out",
|
|
208
|
+
return e.on("mouse:out", n), () => {
|
|
209
|
+
e.off("mouse:out", n);
|
|
210
210
|
};
|
|
211
211
|
}, [e]), h(() => {
|
|
212
212
|
if (e)
|
|
@@ -214,38 +214,38 @@ const oe = (a) => {
|
|
|
214
214
|
e.setCursor("grabbing");
|
|
215
215
|
}), e.on("mouse:up", () => {
|
|
216
216
|
e.defaultCursor = "grab";
|
|
217
|
-
}), e.getObjects(), v((
|
|
218
|
-
var
|
|
219
|
-
return (
|
|
220
|
-
}),
|
|
221
|
-
var
|
|
222
|
-
return (
|
|
223
|
-
}),
|
|
217
|
+
}), e.getObjects(), v((n) => (n.forEach((t) => {
|
|
218
|
+
var o;
|
|
219
|
+
return (o = t.object) == null ? void 0 : o.set("evented", !1);
|
|
220
|
+
}), n))) : (e.defaultCursor = "default", e.off("mouse:down:before"), e.off("mouse:up"), e.setCursor("default"), v((n) => (n.forEach((t) => {
|
|
221
|
+
var o;
|
|
222
|
+
return (o = t.object) == null ? void 0 : o.set("evented", !0);
|
|
223
|
+
}), n)), T()), () => {
|
|
224
224
|
ae();
|
|
225
225
|
};
|
|
226
226
|
}, [e, b]), h(() => {
|
|
227
|
-
if (e == null || e.on("mouse:wheel", (
|
|
228
|
-
const t =
|
|
227
|
+
if (e == null || e.on("mouse:wheel", (n) => {
|
|
228
|
+
const t = n.e.deltaY;
|
|
229
229
|
Y(t, {
|
|
230
|
-
x:
|
|
231
|
-
y:
|
|
232
|
-
}), x.forEach((
|
|
233
|
-
|
|
230
|
+
x: n.e.offsetX,
|
|
231
|
+
y: n.e.offsetY
|
|
232
|
+
}), x.forEach((o) => {
|
|
233
|
+
o.renderLabel();
|
|
234
234
|
});
|
|
235
235
|
}), !b)
|
|
236
236
|
return T(), () => {
|
|
237
|
-
e && (
|
|
237
|
+
e && (B(e), e.off("mouse:wheel"));
|
|
238
238
|
};
|
|
239
239
|
}, [e, c, x, b]);
|
|
240
240
|
const ce = () => {
|
|
241
|
-
ne({}),
|
|
241
|
+
ne({}), W(void 0), U([1, 1]), e == null || e.dispose(), K(void 0);
|
|
242
242
|
};
|
|
243
243
|
return h(() => {
|
|
244
|
-
|
|
245
|
-
|
|
244
|
+
Z(!0), ce(), !(!d.current || !p) && X.Image.fromURL(p, (n) => {
|
|
245
|
+
n.set({
|
|
246
246
|
originX: "center",
|
|
247
247
|
originY: "center"
|
|
248
|
-
}),
|
|
248
|
+
}), W(n), Z(!1);
|
|
249
249
|
}, {
|
|
250
250
|
crossOrigin: "anonymous"
|
|
251
251
|
});
|
|
@@ -259,35 +259,35 @@ const oe = (a) => {
|
|
|
259
259
|
}
|
|
260
260
|
if (!d.current || !d.current.parentElement)
|
|
261
261
|
return;
|
|
262
|
-
const
|
|
263
|
-
if (!(
|
|
262
|
+
const n = j == null ? void 0 : j.getElement();
|
|
263
|
+
if (!(n != null && n.width) || !(n != null && n.height))
|
|
264
264
|
return;
|
|
265
|
-
const t =
|
|
266
|
-
let i = [
|
|
267
|
-
u > s ? i = [r * t, r] : i = [
|
|
268
|
-
const
|
|
265
|
+
const t = n.width / n.height, o = d.current.parentElement.offsetWidth, r = d.current.parentElement.offsetHeight, u = o / n.width, s = r / n.height;
|
|
266
|
+
let i = [o, r];
|
|
267
|
+
u > s ? i = [r * t, r] : i = [o, o / t];
|
|
268
|
+
const D = i[0] / n.width, Q = i[1] / n.height, C = Math.min(D, Q);
|
|
269
269
|
U([C, C]);
|
|
270
270
|
const g = new X.Canvas(d.current, {
|
|
271
271
|
containerClass: "marking-canvas",
|
|
272
|
-
width:
|
|
272
|
+
width: o,
|
|
273
273
|
height: r
|
|
274
274
|
});
|
|
275
275
|
if (g.uniScaleKey = "", g.uniformScaling = !1, g == null || g.setZoom(C), g == null || g.renderAll(), g && j) {
|
|
276
|
-
const _ = (
|
|
276
|
+
const _ = (o - i[0]) / C / 2, $ = (r - i[1]) / C / 2;
|
|
277
277
|
g.setBackgroundImage(
|
|
278
278
|
j,
|
|
279
279
|
() => {
|
|
280
280
|
g.renderAll(), re({
|
|
281
281
|
left: _,
|
|
282
|
-
top:
|
|
283
|
-
}),
|
|
282
|
+
top: $
|
|
283
|
+
}), K(g), E && E();
|
|
284
284
|
},
|
|
285
285
|
// 刷新画布
|
|
286
286
|
{
|
|
287
287
|
originX: "left",
|
|
288
288
|
originY: "top",
|
|
289
289
|
left: _,
|
|
290
|
-
top:
|
|
290
|
+
top: $
|
|
291
291
|
}
|
|
292
292
|
);
|
|
293
293
|
}
|
|
@@ -296,27 +296,27 @@ const oe = (a) => {
|
|
|
296
296
|
if (w.current.size > 0)
|
|
297
297
|
return;
|
|
298
298
|
x.forEach((t) => {
|
|
299
|
-
const
|
|
300
|
-
!m.find((s) => s.id === t.config.id) && !r && !
|
|
299
|
+
const o = w.current.has(t.config.id), r = t._isDestroying;
|
|
300
|
+
!m.find((s) => s.id === t.config.id) && !r && !o && t.destroy();
|
|
301
301
|
});
|
|
302
302
|
}
|
|
303
303
|
}, [m.length]), h(() => {
|
|
304
|
-
e && (b || v((
|
|
305
|
-
const t = e == null ? void 0 : e.getActiveObject(),
|
|
306
|
-
return
|
|
304
|
+
e && (b || v((n) => {
|
|
305
|
+
const t = e == null ? void 0 : e.getActiveObject(), o = n.find((r) => r.object === t);
|
|
306
|
+
return o && c && (o.labelConfig = {
|
|
307
307
|
id: c.id,
|
|
308
308
|
name: c.label,
|
|
309
309
|
color: c.color
|
|
310
|
-
}, l && l(
|
|
310
|
+
}, l && l(n.map(O))), e && (c ? e.defaultCursor = "copy" : e.defaultCursor = "default"), [...n];
|
|
311
311
|
}));
|
|
312
312
|
}, [c, e, b]), h(() => {
|
|
313
|
-
var
|
|
313
|
+
var n;
|
|
314
314
|
if (z && d.current && !M) {
|
|
315
315
|
const t = document.createElement("div");
|
|
316
|
-
t.setAttribute("style", "width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; position: absolute;top: 0;"), (
|
|
316
|
+
t.setAttribute("style", "width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; position: absolute;top: 0;"), (n = d.current.parentElement) == null || n.appendChild(t), le.render(/* @__PURE__ */ f(fe, {}), t), q(t);
|
|
317
317
|
} else
|
|
318
|
-
!z && M && (M.remove(),
|
|
319
|
-
}, [z, d.current, M]), /* @__PURE__ */
|
|
318
|
+
!z && M && (M.remove(), q(null));
|
|
319
|
+
}, [z, d.current, M]), /* @__PURE__ */ ee("div", {
|
|
320
320
|
style: {
|
|
321
321
|
width: "100%",
|
|
322
322
|
height: "100%",
|
|
@@ -326,7 +326,7 @@ const oe = (a) => {
|
|
|
326
326
|
className: "marker-toolbar",
|
|
327
327
|
children: /* @__PURE__ */ f("div", {
|
|
328
328
|
className: "create-mode-select",
|
|
329
|
-
children: /* @__PURE__ */
|
|
329
|
+
children: /* @__PURE__ */ ee(de, {
|
|
330
330
|
direction: "vertical",
|
|
331
331
|
size: 16,
|
|
332
332
|
children: [/* @__PURE__ */ f(A, {
|
|
@@ -367,15 +367,15 @@ const oe = (a) => {
|
|
|
367
367
|
onClick: () => {
|
|
368
368
|
if (!e)
|
|
369
369
|
return;
|
|
370
|
-
v((t) => (t.forEach((
|
|
371
|
-
w.current.add(
|
|
372
|
-
|
|
373
|
-
|
|
370
|
+
B(e), e.discardActiveObject(), v((t) => (t.forEach((o) => {
|
|
371
|
+
w.current.add(o.config.id);
|
|
372
|
+
const r = o.handlers.onDelete;
|
|
373
|
+
o.handlers.onDelete = void 0, o.destroy(), o.handlers.onDelete = r;
|
|
374
374
|
}), setTimeout(() => {
|
|
375
375
|
w.current.clear();
|
|
376
|
-
}, 100), [])), e.
|
|
376
|
+
}, 100), [])), e.getObjects().forEach((t) => {
|
|
377
377
|
t !== e.backgroundImage && e.remove(t);
|
|
378
|
-
}),
|
|
378
|
+
}), l && l([]), e.renderAll(), setTimeout(() => {
|
|
379
379
|
e && !b && T();
|
|
380
380
|
}, 0);
|
|
381
381
|
}
|
|
@@ -388,8 +388,8 @@ const oe = (a) => {
|
|
|
388
388
|
"label-maker-wrap": !0,
|
|
389
389
|
draggable: b
|
|
390
390
|
}),
|
|
391
|
-
onContextMenu: (
|
|
392
|
-
|
|
391
|
+
onContextMenu: (n) => {
|
|
392
|
+
n.preventDefault();
|
|
393
393
|
},
|
|
394
394
|
children: /* @__PURE__ */ f("canvas", {
|
|
395
395
|
className: "label-maker-canvas",
|