@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 $ = Math.pow;
2
- import { jsx as f, jsxs as V } from "react/jsx-runtime";
3
- import { useRef as ee, useState as D, useEffect as h } from "react";
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 te from "./RectLabel.mjs";
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 oe = (a) => {
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 = ee(null), {
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, B] = D(!0), [e, Z] = D(), [ye, ne] = D({}), [j, K] = D(), [W, re] = D({
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] = D([1, 1]), [M, H] = D(), [x, v] = D([]), w = ee(/* @__PURE__ */ new Set()), [b, P] = D(k || !1), Y = (o, t) => {
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 n = e.getZoom();
54
- n *= $(0.999, o), n > 20 && (n = 20), n < 0.01 && (n = 0.01), e.zoomToPoint(
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
- n
56
+ o
57
57
  // 传入修改后的缩放级别
58
- ), U([n, n]);
58
+ ), U([o, o]);
59
59
  };
60
60
  h(() => {
61
- x.forEach((o) => {
62
- o.renderLabel();
61
+ x.forEach((n) => {
62
+ n.renderLabel();
63
63
  });
64
64
  }, [ie, x, e]);
65
- const q = (o) => {
66
- var n;
67
- if (((n = o.target) == null ? void 0 : n.tagName) === "INPUT" || !e)
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 I = i._fabricRect;
83
- return I && I === t;
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", q), R("Backspace", q), R("ctrl", () => {
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 F = (o) => {
108
- e && oe(e), v((t) => {
109
- const n = t.findIndex((r) => r === o);
110
- return n > -1 && (t.splice(n, 1), l && l(t.map(O)), T()), [...t];
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
- }, G = (o) => {
112
+ }, J = (n) => {
113
113
  v((t) => {
114
- const n = t.findIndex((r) => r === o);
115
- return n > -1 && (t[n] = o, l && l(t.map(O))), [...t];
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 o = [];
121
+ const n = [];
122
122
  return m.filter((t) => t.color).forEach((t) => {
123
- o.push(new te({
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((n) => [n[0] + W.left, n[1] + W.top]),
127
+ points: t.box.map((o) => [o[0] + H.left, o[1] + H.top]),
128
128
  hideDelete: y
129
129
  }, e, {
130
- onChange: G,
131
- onDelete: F,
132
- renderLabelItem: N ? (n) => N ? N(t) : n.name : void 0
130
+ onChange: J,
131
+ onDelete: G,
132
+ renderLabelItem: N ? (o) => N ? N(t) : o.name : void 0
133
133
  }));
134
- }), v(o), o.forEach((t) => {
134
+ }), v(n), n.forEach((t) => {
135
135
  t.render(e);
136
136
  }), () => {
137
- o.forEach((t) => {
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, (o) => {
144
- const t = new te({
145
- id: (c == null ? void 0 : c.id) || o.id,
146
- name: (c == null ? void 0 : c.label) || o.label,
147
- color: (c == null ? void 0 : c.color) || o.color,
148
- points: o.box.map((n) => [n[0], n[1]]),
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: G,
152
- onDelete: F
151
+ onChange: J,
152
+ onDelete: G
153
153
  });
154
- t.active = !0, v((n) => {
155
- const r = [...n, t];
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 o = !1;
162
+ let n = !1;
163
163
  e && (e.on("mouse:down", (t) => {
164
- o = !0, e.selection = !1;
164
+ n = !0, e.selection = !1;
165
165
  }), e.on("mouse:move", (t) => {
166
- if (o && t && t.e) {
167
- const n = new X.Point(t.e.movementX, t.e.movementY);
168
- e.relativePan(n);
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
- o = !1, e.selection = !0;
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 o = (t) => {
180
- const n = e, r = n == null ? void 0 : n._currentTransform;
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 I = e.getPointer(t.e);
190
- if (I.x < i.tl.x || I.x > i.br.x || I.y < i.tl.y || I.y > i.br.y) {
191
- const C = n == null ? void 0 : n._onMouseUp;
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", o), () => {
196
- e.off("mouse:move", o);
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 o = (t) => {
202
- const n = e;
203
- if (!!!(n != null && n._currentTransform))
201
+ const n = (t) => {
202
+ const o = e;
203
+ if (!!!(o != null && o._currentTransform))
204
204
  return;
205
- const u = n == null ? void 0 : n._onMouseUp;
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", o), () => {
209
- e.off("mouse:out", o);
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((o) => (o.forEach((t) => {
218
- var n;
219
- return (n = t.object) == null ? void 0 : n.set("evented", !1);
220
- }), o))) : (e.defaultCursor = "default", e.off("mouse:down:before"), e.off("mouse:up"), e.setCursor("default"), v((o) => (o.forEach((t) => {
221
- var n;
222
- return (n = t.object) == null ? void 0 : n.set("evented", !0);
223
- }), o)), T()), () => {
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", (o) => {
228
- const t = o.e.deltaY;
227
+ if (e == null || e.on("mouse:wheel", (n) => {
228
+ const t = n.e.deltaY;
229
229
  Y(t, {
230
- x: o.e.offsetX,
231
- y: o.e.offsetY
232
- }), x.forEach((n) => {
233
- n.renderLabel();
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 && (oe(e), e.off("mouse:wheel"));
237
+ e && (B(e), e.off("mouse:wheel"));
238
238
  };
239
239
  }, [e, c, x, b]);
240
240
  const ce = () => {
241
- ne({}), K(void 0), U([1, 1]), e == null || e.dispose(), Z(void 0);
241
+ ne({}), W(void 0), U([1, 1]), e == null || e.dispose(), K(void 0);
242
242
  };
243
243
  return h(() => {
244
- B(!0), ce(), !(!d.current || !p) && X.Image.fromURL(p, (o) => {
245
- o.set({
244
+ Z(!0), ce(), !(!d.current || !p) && X.Image.fromURL(p, (n) => {
245
+ n.set({
246
246
  originX: "center",
247
247
  originY: "center"
248
- }), K(o), B(!1);
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 o = j == null ? void 0 : j.getElement();
263
- if (!(o != null && o.width) || !(o != null && o.height))
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 = o.width / o.height, n = d.current.parentElement.offsetWidth, r = d.current.parentElement.offsetHeight, u = n / o.width, s = r / o.height;
266
- let i = [n, r];
267
- u > s ? i = [r * t, r] : i = [n, n / t];
268
- const I = i[0] / o.width, J = i[1] / o.height, C = Math.min(I, J);
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: n,
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 _ = (n - i[0]) / C / 2, Q = (r - i[1]) / C / 2;
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: Q
283
- }), Z(g), E && E();
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: Q
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 n = w.current.has(t.config.id), r = t._isDestroying;
300
- !m.find((s) => s.id === t.config.id) && !r && !n && t.destroy();
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((o) => {
305
- const t = e == null ? void 0 : e.getActiveObject(), n = o.find((r) => r.object === t);
306
- return n && c && (n.labelConfig = {
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(o.map(O))), e && (c ? e.defaultCursor = "copy" : e.defaultCursor = "default"), [...o];
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 o;
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;"), (o = d.current.parentElement) == null || o.appendChild(t), le.render(/* @__PURE__ */ f(fe, {}), t), H(t);
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(), H(null));
319
- }, [z, d.current, M]), /* @__PURE__ */ V("div", {
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__ */ V(de, {
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((n) => {
371
- w.current.add(n.config.id);
372
- }), t.forEach((n) => {
373
- n.destroy();
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.discardActiveObject(), e.getObjects().forEach((t) => {
376
+ }, 100), [])), e.getObjects().forEach((t) => {
377
377
  t !== e.backgroundImage && e.remove(t);
378
- }), e.renderAll(), l && l([]), setTimeout(() => {
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: (o) => {
392
- o.preventDefault();
391
+ onContextMenu: (n) => {
392
+ n.preventDefault();
393
393
  },
394
394
  children: /* @__PURE__ */ f("canvas", {
395
395
  className: "label-maker-canvas",