@glodon-aiot/dataset-annotation 3.10.0-alpha.21 → 3.10.0-alpha.22

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,65 +1,83 @@
1
- import { useCallback as V, useEffect as a } from "react";
2
- import { fabric as X } from "fabric";
3
- import { TEMP_RECT_FILL_COLOR as I, RECT_STROKE_COLOR as Y, TEMP_RECT_STROKE_DASH_ARRAY as J, TRANSPARENT_FILL as v, REGION_NAME_PREFIX as ee, BASE_STROKE_WIDTH as Z } from "../../constants.mjs";
4
- const le = ({
1
+ import { useCallback as Q, useEffect as te } from "react";
2
+ import { fabric as j } from "fabric";
3
+ import { TEMP_RECT_FILL_COLOR as V, RECT_STROKE_COLOR as U, TEMP_RECT_STROKE_DASH_ARRAY as v, TRANSPARENT_FILL as oe, REGION_NAME_PREFIX as re, BASE_STROKE_WIDTH as a } from "../../constants.mjs";
4
+ const ne = ({
5
5
  canvas: e,
6
6
  drawingMode: x,
7
- draggable: U,
8
- setDrawingMode: H,
9
- canvasToImageCoords: $,
7
+ draggable: H,
8
+ setDrawingMode: $,
9
+ canvasToImageCoords: G,
10
10
  labelDefinitions: y,
11
- onChange: j,
12
- cropRegionImage: G,
13
- updateRegionShapeAndImage: _,
14
- performOCRIfNeeded: K,
15
- createDeleteControl: B,
16
- updateRegionNameText: D,
17
- onRegionChange: P,
18
- onRegionSelect: T,
19
- rectMapRef: h
11
+ onChange: T,
12
+ cropRegionImage: K,
13
+ updateRegionShapeAndImage: L,
14
+ performOCRIfNeeded: B,
15
+ createDeleteControl: D,
16
+ updateRegionNameText: N,
17
+ onRegionChange: S,
18
+ onRegionSelect: w,
19
+ rectMapRef: h,
20
+ textLayersMapRef: z
20
21
  }) => {
21
- const M = V(() => {
22
+ const X = Q(() => {
23
+ const Y = /* @__PURE__ */ new Set();
24
+ return z.current.forEach((r) => {
25
+ r.forEach((l) => {
26
+ Y.add(l);
27
+ });
28
+ }), Y;
29
+ }, [z]), R = Q(() => {
22
30
  e && (e.skipTargetFind = !1);
23
31
  }, [e]);
24
- return a(() => {
25
- if (!e || !x || U) {
26
- if (M(), e && !x) {
27
- const t = e.getActiveObject();
28
- e.selection = !1, e.skipTargetFind = !1, e.getObjects().forEach((u) => {
29
- u.set("evented", !0), u.set("selectable", !0);
30
- }), t && e.getObjects().includes(t) && (e.setActiveObject(t), e.renderAll()), e.defaultCursor = "default", e.setCursor("default");
32
+ return te(() => {
33
+ if (!e || !x || H) {
34
+ if (R(), e && !x) {
35
+ const o = e.getActiveObject();
36
+ e.selection = !1, e.skipTargetFind = !1;
37
+ const n = X();
38
+ e.getObjects().forEach((t) => {
39
+ t instanceof j.Rect && n.has(t) ? t.set({
40
+ evented: !0,
41
+ selectable: !1,
42
+ lockMovementX: !0,
43
+ lockMovementY: !0,
44
+ lockScalingX: !0,
45
+ lockScalingY: !0,
46
+ lockRotation: !0
47
+ }) : (t.set("evented", !0), t.set("selectable", !0));
48
+ }), o && e.getObjects().includes(o) && (e.setActiveObject(o), e.renderAll()), e.defaultCursor = "default", e.setCursor("default");
31
49
  }
32
50
  return;
33
51
  }
34
- M(), e.selection = !1, e.skipTargetFind = !0, e.getActiveObject() && (e.discardActiveObject(), e.renderAll()), e.getObjects().forEach((t) => {
35
- t.set("evented", !1), t.set("selectable", !1);
52
+ R(), e.selection = !1, e.skipTargetFind = !0, e.getActiveObject() && (e.discardActiveObject(), e.renderAll()), e.getObjects().forEach((o) => {
53
+ o.set("evented", !1), o.set("selectable", !1);
36
54
  }), e.defaultCursor = "crosshair", e.setCursor("crosshair");
37
- let i = -1, l = -1, c = 0, m = 0, f = null;
38
- const N = (t) => {
39
- e.getActiveObject() && (e.discardActiveObject(), e.renderAll()), i = -1, l = -1, c = 0, m = 0;
40
- const s = e.getPointer(t.e);
41
- l = s.x, i = s.y, e.skipTargetFind = !0;
42
- }, W = (t) => {
43
- if (l === -1 || i === -1)
55
+ let r = -1, l = -1, d = 0, m = 0, f = null;
56
+ const q = (o) => {
57
+ e.getActiveObject() && (e.discardActiveObject(), e.renderAll()), r = -1, l = -1, d = 0, m = 0;
58
+ const t = e.getPointer(o.e);
59
+ l = t.x, r = t.y, e.skipTargetFind = !0;
60
+ }, P = (o) => {
61
+ if (l === -1 || r === -1)
44
62
  return;
45
- const u = e.getPointer(t.e);
46
- let s = u.x, d = u.y;
47
- if (c = Math.abs(s - l), m = Math.abs(d - i), c === 0 || m === 0)
63
+ const n = e.getPointer(o.e);
64
+ let t = n.x, c = n.y;
65
+ if (d = Math.abs(t - l), m = Math.abs(c - r), d === 0 || m === 0)
48
66
  return;
49
- let g = i > d ? d : i, p = l > s ? s : l, n = c, b = m;
67
+ let g = r > c ? c : r, C = l > t ? t : l, u = d, k = m;
50
68
  f && e.remove(f);
51
- const A = e.getZoom(), C = Z / A;
52
- f = new X.Rect({
53
- left: p,
69
+ const A = e.getZoom(), p = a / A;
70
+ f = new j.Rect({
71
+ left: C,
54
72
  top: g,
55
- width: n,
56
- height: b,
57
- fill: I,
58
- stroke: Y,
59
- strokeWidth: C,
73
+ width: u,
74
+ height: k,
75
+ fill: V,
76
+ stroke: U,
77
+ strokeWidth: p,
60
78
  strokeUniform: !0,
61
79
  // 边框宽度不受缩放影响
62
- strokeDashArray: J,
80
+ strokeDashArray: v,
63
81
  selectable: !1,
64
82
  evented: !1,
65
83
  objectCaching: !1,
@@ -67,28 +85,28 @@ const le = ({
67
85
  statefullCache: !1,
68
86
  noScaleCache: !1
69
87
  }), e.add(f), e.renderAll();
70
- }, F = (t) => {
71
- if (l === -1 || i === -1) {
72
- i = -1, l = -1;
88
+ }, W = (o) => {
89
+ if (l === -1 || r === -1) {
90
+ r = -1, l = -1;
73
91
  return;
74
92
  }
75
- const u = e.getPointer(t.e);
76
- let s = u.x, d = u.y;
77
- if (c = Math.abs(s - l), m = Math.abs(d - i), c === 0 || m === 0) {
78
- f && (e.remove(f), e.renderAll()), i = -1, l = -1;
93
+ const n = e.getPointer(o.e);
94
+ let t = n.x, c = n.y;
95
+ if (d = Math.abs(t - l), m = Math.abs(c - r), d === 0 || m === 0) {
96
+ f && (e.remove(f), e.renderAll()), r = -1, l = -1;
79
97
  return;
80
98
  }
81
- let g = i > d ? d : i, p = l > s ? s : l, n = c, b = m;
99
+ let g = r > c ? c : r, C = l > t ? t : l, u = d, k = m;
82
100
  f && (e.remove(f), f = null);
83
- const A = $(p, g), C = n, R = b, E = e.getZoom(), k = Z / E, o = new X.Rect({
84
- left: p,
101
+ const A = G(C, g), p = u, F = k, E = e.getZoom(), b = a / E, s = new j.Rect({
102
+ left: C,
85
103
  top: g,
86
- width: n,
87
- height: b,
88
- fill: v,
104
+ width: u,
105
+ height: k,
106
+ fill: oe,
89
107
  // 无填充色
90
- stroke: Y,
91
- strokeWidth: k,
108
+ stroke: U,
109
+ strokeWidth: b,
92
110
  strokeUniform: !0,
93
111
  // 边框宽度不受缩放影响
94
112
  selectable: !0,
@@ -104,90 +122,90 @@ const le = ({
104
122
  statefullCache: !1,
105
123
  noScaleCache: !1
106
124
  });
107
- e.add(o), o.controls.deleteControl = B();
108
- const S = h.current.size, L = {};
109
- y == null || y.forEach((r) => {
110
- L[r.id] = "";
125
+ e.add(s), s.controls.deleteControl = D();
126
+ const Z = h.current.size, _ = {};
127
+ y == null || y.forEach((i) => {
128
+ _[i.id] = "";
111
129
  });
112
- const w = {
130
+ const M = {
113
131
  id: `region-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
114
- name: `${ee}${S + 1}`,
132
+ name: `${re}${Z + 1}`,
115
133
  // 设置名称:区域+(索引+1)
116
134
  shape: {
117
135
  name: "rect",
118
136
  x: Math.max(0, A.x),
119
137
  y: Math.max(0, A.y),
120
- width: C,
121
- height: R
138
+ width: p,
139
+ height: F
122
140
  },
123
- content: L
141
+ content: _
124
142
  };
125
- if (h.current.set(o, w), D(o, w), _(o), P) {
126
- const r = h.current.get(o);
127
- r && P(r, "create");
143
+ if (h.current.set(s, M), N(s, M), L(s), S) {
144
+ const i = h.current.get(s);
145
+ i && S(i, "create");
128
146
  }
129
- G(w).then((r) => {
130
- if (r) {
131
- const O = h.current.get(o);
147
+ K(M).then((i) => {
148
+ if (i) {
149
+ const O = h.current.get(s);
132
150
  if (O) {
133
- if (O.image = r, delete O.textLayouts, j) {
134
- const Q = Array.from(h.current.values());
135
- j(Q);
151
+ if (O.image = i, delete O.textLayouts, T) {
152
+ const ee = Array.from(h.current.values());
153
+ T(ee);
136
154
  }
137
- K(O, "create");
155
+ B(O, "create");
138
156
  }
139
157
  }
140
- }).catch((r) => {
141
- console.error("Failed to crop region image:", r);
142
- }), e.setActiveObject(o), e.renderAll(), setTimeout(() => {
143
- if (T) {
144
- const r = h.current.get(o);
145
- r && T(r);
158
+ }).catch((i) => {
159
+ console.error("Failed to crop region image:", i);
160
+ }), e.setActiveObject(s), e.renderAll(), setTimeout(() => {
161
+ if (w) {
162
+ const i = h.current.get(s);
163
+ i && w(i);
146
164
  }
147
165
  setTimeout(() => {
148
- if (e && o && e.getObjects().includes(o) && (e.setActiveObject(o), e.renderAll(), T)) {
149
- const r = h.current.get(o);
150
- r && T(r);
166
+ if (e && s && e.getObjects().includes(s) && (e.setActiveObject(s), e.renderAll(), w)) {
167
+ const i = h.current.get(s);
168
+ i && w(i);
151
169
  }
152
170
  }, 0);
153
- }, 0), o.on("modified", () => {
154
- _(o);
155
- }), o.on("moved", () => {
156
- _(o);
171
+ }, 0), s.on("modified", () => {
172
+ L(s);
173
+ }), s.on("moved", () => {
174
+ L(s);
157
175
  }), setTimeout(() => {
158
- if (j) {
159
- const r = Array.from(h.current.values());
160
- j(r);
176
+ if (T) {
177
+ const i = Array.from(h.current.values());
178
+ T(i);
161
179
  }
162
- }, 0), i = -1, l = -1, e.selection = !1, H(!1);
163
- }, z = (t) => {
164
- if (l === -1 || i === -1)
180
+ }, 0), r = -1, l = -1, e.selection = !1, $(!1);
181
+ }, I = (o) => {
182
+ if (l === -1 || r === -1)
165
183
  return;
166
- const s = e.getElement().getBoundingClientRect(), d = t.clientX, g = t.clientY;
167
- if (d >= s.left && d <= s.right && g >= s.top && g <= s.bottom) {
168
- const n = e.getPointer(t);
169
- W({
170
- e: t,
171
- pointer: n
184
+ const t = e.getElement().getBoundingClientRect(), c = o.clientX, g = o.clientY;
185
+ if (c >= t.left && c <= t.right && g >= t.top && g <= t.bottom) {
186
+ const u = e.getPointer(o);
187
+ P({
188
+ e: o,
189
+ pointer: u
172
190
  });
173
191
  } else {
174
- const n = e.getZoom(), b = e.viewportTransform ? e.viewportTransform[4] / n : 0, A = e.viewportTransform ? e.viewportTransform[5] / n : 0, C = e.getWidth() / n, R = e.getHeight() / n;
175
- let E = (d - s.left) / n - b, k = (g - s.top) / n - A;
176
- if (E = Math.max(0, Math.min(E, C)), k = Math.max(0, Math.min(k, R)), c = Math.abs(E - l), m = Math.abs(k - i), c === 0 || m === 0)
192
+ const u = e.getZoom(), k = e.viewportTransform ? e.viewportTransform[4] / u : 0, A = e.viewportTransform ? e.viewportTransform[5] / u : 0, p = e.getWidth() / u, F = e.getHeight() / u;
193
+ let E = (c - t.left) / u - k, b = (g - t.top) / u - A;
194
+ if (E = Math.max(0, Math.min(E, p)), b = Math.max(0, Math.min(b, F)), d = Math.abs(E - l), m = Math.abs(b - r), d === 0 || m === 0)
177
195
  return;
178
- let o = i > k ? k : i, S = l > E ? E : l, L = c, w = m;
196
+ let s = r > b ? b : r, Z = l > E ? E : l, _ = d, M = m;
179
197
  f && e.remove(f);
180
- const r = e.getZoom(), O = Z / r;
181
- f = new X.Rect({
182
- left: S,
183
- top: o,
184
- width: L,
185
- height: w,
186
- fill: I,
187
- stroke: Y,
198
+ const i = e.getZoom(), O = a / i;
199
+ f = new j.Rect({
200
+ left: Z,
201
+ top: s,
202
+ width: _,
203
+ height: M,
204
+ fill: V,
205
+ stroke: U,
188
206
  strokeWidth: O,
189
207
  strokeUniform: !0,
190
- strokeDashArray: J,
208
+ strokeDashArray: v,
191
209
  selectable: !1,
192
210
  evented: !1,
193
211
  objectCaching: !1,
@@ -196,25 +214,35 @@ const le = ({
196
214
  }), e.add(f), e.renderAll();
197
215
  }
198
216
  };
199
- e.on("mouse:down", N), e.on("mouse:move", W), e.on("mouse:up", F), document.addEventListener("mousemove", z);
200
- const q = (t) => {
201
- if (l === -1 || i === -1)
217
+ e.on("mouse:down", q), e.on("mouse:move", P), e.on("mouse:up", W), document.addEventListener("mousemove", I);
218
+ const J = (o) => {
219
+ if (l === -1 || r === -1)
202
220
  return;
203
- const u = e.getPointer(t);
204
- F({
205
- e: t,
206
- pointer: u
221
+ const n = e.getPointer(o);
222
+ W({
223
+ e: o,
224
+ pointer: n
207
225
  });
208
226
  };
209
- return document.addEventListener("mouseup", q), () => {
210
- e.off("mouse:down", N), e.off("mouse:move", W), e.off("mouse:up", F), document.removeEventListener("mousemove", z), document.removeEventListener("mouseup", q), f && (e.remove(f), e.renderAll()), e.skipTargetFind = !1, e.getObjects().forEach((t) => {
211
- t.set("evented", !0), t.set("selectable", !0);
227
+ return document.addEventListener("mouseup", J), () => {
228
+ e.off("mouse:down", q), e.off("mouse:move", P), e.off("mouse:up", W), document.removeEventListener("mousemove", I), document.removeEventListener("mouseup", J), f && (e.remove(f), e.renderAll()), e.skipTargetFind = !1;
229
+ const o = X();
230
+ e.getObjects().forEach((n) => {
231
+ n instanceof j.Rect && o.has(n) ? n.set({
232
+ evented: !0,
233
+ selectable: !1,
234
+ lockMovementX: !0,
235
+ lockMovementY: !0,
236
+ lockScalingX: !0,
237
+ lockScalingY: !0,
238
+ lockRotation: !0
239
+ }) : (n.set("evented", !0), n.set("selectable", !0));
212
240
  });
213
241
  };
214
- }, [e, x, U, M, $, j, G, _, K, B, D, P, T, H, h]), {
215
- stopDraw: M
242
+ }, [e, x, H, R, G, T, K, L, B, D, N, S, w, $, h, X]), {
243
+ stopDraw: R
216
244
  };
217
245
  };
218
246
  export {
219
- le as useDrawingMode
247
+ ne as useDrawingMode
220
248
  };
@@ -1,43 +1,50 @@
1
1
  import { useEffect as g } from "react";
2
- import { fabric as f } from "fabric";
3
- import { SELECTED_RECT_FILL_COLOR as m, CONTROL_POINT_COLOR as O, CONTROL_POINT_SIZE as S, TRANSPARENT_FILL as k, BASE_STROKE_WIDTH as E } from "../../constants.mjs";
4
- const L = ({
5
- canvas: t,
6
- onRegionSelect: r,
7
- createDeleteControl: c,
8
- textLayersMapRef: d,
9
- rectMapRef: i
2
+ import { fabric as u } from "fabric";
3
+ import { SELECTED_RECT_FILL_COLOR as L, CONTROL_POINT_COLOR as R, CONTROL_POINT_SIZE as S, TRANSPARENT_FILL as E, BASE_STROKE_WIDTH as A } from "../../constants.mjs";
4
+ const j = ({
5
+ canvas: e,
6
+ onRegionSelect: o,
7
+ createDeleteControl: n,
8
+ textLayersMapRef: a,
9
+ rectMapRef: s
10
10
  }) => {
11
11
  g(() => {
12
- if (!t)
12
+ if (!e)
13
13
  return;
14
- const s = () => {
15
- const e = /* @__PURE__ */ new Set();
16
- d.current.forEach((o) => {
17
- o.forEach((l) => {
18
- e.add(l);
14
+ const i = () => {
15
+ const t = /* @__PURE__ */ new Set();
16
+ return a.current.forEach((r) => {
17
+ r.forEach((l) => {
18
+ t.add(l);
19
19
  });
20
- }), t.getObjects().forEach((o) => {
21
- o instanceof f.Rect && !e.has(o) && o.set({
22
- fill: k
20
+ }), t;
21
+ }, f = () => {
22
+ const t = i();
23
+ e.getObjects().forEach((r) => {
24
+ r instanceof u.Rect && !t.has(r) && r.set({
25
+ fill: E
23
26
  // 移除填充色
24
27
  });
25
28
  });
26
- }, a = () => {
27
- s();
28
- const e = t.getActiveObject();
29
- if (e && e instanceof f.Rect) {
30
- const o = t.getZoom(), l = E / o;
31
- e.set({
29
+ }, h = () => {
30
+ f();
31
+ const t = e.getActiveObject();
32
+ if (t && t instanceof u.Rect) {
33
+ if (i().has(t)) {
34
+ e.discardActiveObject(), e.renderAll();
35
+ return;
36
+ }
37
+ const l = e.getZoom(), d = A / l;
38
+ t.set({
32
39
  hasRotatingPoint: !1,
33
40
  lockRotation: !0,
34
41
  lockUniScaling: !1,
35
42
  // 允许非等比缩放,控制点跟随鼠标
36
- fill: m,
43
+ fill: L,
37
44
  // 选中时添加填充色
38
45
  strokeUniform: !0,
39
46
  // 确保边框宽度不受缩放影响
40
- strokeWidth: l,
47
+ strokeWidth: d,
41
48
  // 确保边框宽度一致
42
49
  objectCaching: !1,
43
50
  // 禁用缓存,避免缩放时边框变虚
@@ -45,31 +52,35 @@ const L = ({
45
52
  noScaleCache: !1,
46
53
  cornerStyle: "circle",
47
54
  // 设置控制点为圆形
48
- cornerColor: O,
55
+ cornerColor: R,
49
56
  // 设置控制点为紫色(填充色)
50
57
  cornerSize: S,
51
58
  // 设置控制点大小(默认12,这里设置为6使其更小)
52
59
  transparentCorners: !1
53
60
  // 不透明,显示填充颜色
54
- }), e.controls && e.controls.mtr && delete e.controls.mtr, e.controls.deleteControl || (e.controls.deleteControl = c()), t.renderAll();
55
- const n = i.current.get(e);
56
- n && r && r(n);
61
+ }), t.controls && t.controls.mtr && delete t.controls.mtr, t.controls.deleteControl || (t.controls.deleteControl = n()), e.renderAll();
62
+ const c = s.current.get(t);
63
+ c && o && o(c);
57
64
  }
58
- }, u = () => {
59
- s();
60
- const e = t.getActiveObject();
61
- if (e && e instanceof f.Rect) {
62
- const o = t.getZoom(), l = E / o;
63
- e.set({
65
+ }, C = () => {
66
+ f();
67
+ const t = e.getActiveObject();
68
+ if (t && t instanceof u.Rect) {
69
+ if (i().has(t)) {
70
+ e.discardActiveObject(), e.renderAll();
71
+ return;
72
+ }
73
+ const l = e.getZoom(), d = A / l;
74
+ t.set({
64
75
  hasRotatingPoint: !1,
65
76
  lockRotation: !0,
66
77
  lockUniScaling: !1,
67
78
  // 允许非等比缩放,控制点跟随鼠标
68
- fill: m,
79
+ fill: L,
69
80
  // 选中时添加填充色
70
81
  strokeUniform: !0,
71
82
  // 确保边框宽度不受缩放影响
72
- strokeWidth: l,
83
+ strokeWidth: d,
73
84
  // 确保边框宽度一致
74
85
  objectCaching: !1,
75
86
  // 禁用缓存,避免缩放时边框变虚
@@ -77,26 +88,26 @@ const L = ({
77
88
  noScaleCache: !1,
78
89
  cornerStyle: "circle",
79
90
  // 设置控制点为圆形
80
- cornerColor: O,
91
+ cornerColor: R,
81
92
  // 设置控制点为紫色(填充色)
82
93
  cornerSize: S,
83
94
  // 设置控制点大小(默认12,这里设置为6使其更小)
84
95
  transparentCorners: !1
85
96
  // 不透明,显示填充颜色
86
97
  });
87
- const n = e;
88
- n.uniformScaling = !1, e.controls && e.controls.mtr && delete e.controls.mtr, e.controls.deleteControl || (e.controls.deleteControl = c()), t.renderAll();
89
- const h = i.current.get(e);
90
- h && r && r(h);
98
+ const c = t;
99
+ c.uniformScaling = !1, t.controls && t.controls.mtr && delete t.controls.mtr, t.controls.deleteControl || (t.controls.deleteControl = n()), e.renderAll();
100
+ const m = s.current.get(t);
101
+ m && o && o(m);
91
102
  }
92
- }, C = () => {
93
- s(), t.renderAll(), r && r(null);
103
+ }, O = () => {
104
+ f(), e.renderAll(), o && o(null);
94
105
  };
95
- return t.on("selection:created", a), t.on("selection:updated", u), t.on("selection:cleared", C), () => {
96
- t.off("selection:created", a), t.off("selection:updated", u), t.off("selection:cleared", C);
106
+ return e.on("selection:created", h), e.on("selection:updated", C), e.on("selection:cleared", O), () => {
107
+ e.off("selection:created", h), e.off("selection:updated", C), e.off("selection:cleared", O);
97
108
  };
98
- }, [t, r, c, d, i]);
109
+ }, [e, o, n, a, s]);
99
110
  };
100
111
  export {
101
- L as useRegionSelection
112
+ j as useRegionSelection
102
113
  };