@glodon-aiot/dataset-annotation 3.14.0-alpha.32 → 3.14.0-alpha.33

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,237 +1,239 @@
1
- var Ke = Object.defineProperty, $e = Object.defineProperties;
2
- var Ge = Object.getOwnPropertyDescriptors;
3
- var Se = Object.getOwnPropertySymbols;
4
- var qe = Object.prototype.hasOwnProperty, Je = Object.prototype.propertyIsEnumerable;
5
- var Ae = (c, g, l) => g in c ? Ke(c, g, { enumerable: !0, configurable: !0, writable: !0, value: l }) : c[g] = l, ne = (c, g) => {
6
- for (var l in g || (g = {}))
7
- qe.call(g, l) && Ae(c, l, g[l]);
8
- if (Se)
9
- for (var l of Se(g))
10
- Je.call(g, l) && Ae(c, l, g[l]);
11
- return c;
12
- }, we = (c, g) => $e(c, Ge(g));
13
- import { jsxs as Oe, jsx as b } from "react/jsx-runtime";
14
- import Qe, { useRef as C, useState as x, useCallback as w, useEffect as p, useImperativeHandle as Ve } from "react";
15
- import { fabric as P } from "fabric";
16
- import { useKeyPress as Y } from "ahooks";
17
- import et from "classnames";
1
+ var Qt = Object.defineProperty, Vt = Object.defineProperties;
2
+ var te = Object.getOwnPropertyDescriptors;
3
+ var wt = Object.getOwnPropertySymbols;
4
+ var ee = Object.prototype.hasOwnProperty, oe = Object.prototype.propertyIsEnumerable;
5
+ var Ot = (i, g, d) => g in i ? Qt(i, g, { enumerable: !0, configurable: !0, writable: !0, value: d }) : i[g] = d, it = (i, g) => {
6
+ for (var d in g || (g = {}))
7
+ ee.call(g, d) && Ot(i, d, g[d]);
8
+ if (wt)
9
+ for (var d of wt(g))
10
+ oe.call(g, d) && Ot(i, d, g[d]);
11
+ return i;
12
+ }, _t = (i, g) => Vt(i, te(g));
13
+ import { jsxs as Lt, jsx as L } from "react/jsx-runtime";
14
+ import re, { useRef as T, useState as S, useCallback as w, useEffect as E, useImperativeHandle as ne } from "react";
15
+ import { fabric as W } from "fabric";
16
+ import { useKeyPress as Z } from "ahooks";
17
+ import se from "classnames";
18
18
  import "./style.less.mjs";
19
- import tt from "../components/Toolbar.mjs";
20
- import { useOCRLoadingIcon as ot } from "./hooks/useOCRLoadingIcon.mjs";
21
- import { useRegionNameText as rt } from "./hooks/useRegionNameText.mjs";
22
- import { useCropRegionImage as nt } from "./hooks/useCropRegionImage.mjs";
23
- import { useDrawingMode as st } from "./hooks/useDrawingMode.mjs";
24
- import { useRegionLoader as ct } from "./hooks/useRegionLoader.mjs";
25
- import { useCanvasSetup as it } from "./hooks/useCanvasSetup.mjs";
26
- import { useTextLayouts as at } from "./hooks/useTextLayouts.mjs";
27
- import { useRegionUpdate as ft } from "./hooks/useRegionUpdate.mjs";
28
- import { useCanvasDrag as ut } from "./hooks/useCanvasDrag.mjs";
29
- import { useRegionSelection as dt } from "./hooks/useRegionSelection.mjs";
30
- import { useOCRRecognition as mt } from "./hooks/useOCRRecognition.mjs";
31
- import { useDeleteRegion as lt } from "./hooks/useDeleteRegion.mjs";
32
- import { useDeleteControl as ht } from "./hooks/useDeleteControl.mjs";
33
- import { useOCRControl as gt } from "./hooks/useOCRControl.mjs";
34
- import { useCanvasZoom as Rt } from "./hooks/useCanvasZoom.mjs";
35
- import { useRegionHover as Et } from "./hooks/useRegionHover.mjs";
36
- import { useRegionBoundaryCheck as pt } from "./hooks/useRegionBoundaryCheck.mjs";
37
- import { canvasToImageCoords as Ct, imageToCanvasCoords as Tt } from "./utils/coordinateUtils.mjs";
38
- import { REGION_NAME_PREFIX as vt, DEFAULT_REGION_NAME as It, ZOOM_PRECISION_ERROR as kt, TEXT_LAYOUT_RECT_FILL_COLOR as Nt, TEXT_LAYOUT_RECT_STROKE_COLOR as St, TRANSPARENT_FILL as _e, SELECTED_RECT_FILL_COLOR as At, BASE_STROKE_WIDTH as se, ACTIVE_RECT_STROKE_COLOR as wt, RECT_STROKE_COLOR as Ot } from "../constants.mjs";
39
- const _t = Qe.forwardRef(({
40
- sample: c,
19
+ import ie from "../components/Toolbar.mjs";
20
+ import { useOCRLoadingIcon as ce } from "./hooks/useOCRLoadingIcon.mjs";
21
+ import { useRegionNameText as ae } from "./hooks/useRegionNameText.mjs";
22
+ import { useCropRegionImage as fe } from "./hooks/useCropRegionImage.mjs";
23
+ import { useDrawingMode as ue } from "./hooks/useDrawingMode.mjs";
24
+ import { useRegionLoader as le } from "./hooks/useRegionLoader.mjs";
25
+ import { useCanvasSetup as me } from "./hooks/useCanvasSetup.mjs";
26
+ import { useTextLayouts as de } from "./hooks/useTextLayouts.mjs";
27
+ import { useRegionUpdate as he } from "./hooks/useRegionUpdate.mjs";
28
+ import { useCanvasDrag as ge } from "./hooks/useCanvasDrag.mjs";
29
+ import { useRegionSelection as Re } from "./hooks/useRegionSelection.mjs";
30
+ import { useOCRRecognition as pe } from "./hooks/useOCRRecognition.mjs";
31
+ import { useDeleteRegion as Ee } from "./hooks/useDeleteRegion.mjs";
32
+ import { useDeleteControl as Te } from "./hooks/useDeleteControl.mjs";
33
+ import { useOCRControl as Ce } from "./hooks/useOCRControl.mjs";
34
+ import { useCanvasZoom as ve } from "./hooks/useCanvasZoom.mjs";
35
+ import { useRegionHover as Ie } from "./hooks/useRegionHover.mjs";
36
+ import { useRegionBoundaryCheck as ke } from "./hooks/useRegionBoundaryCheck.mjs";
37
+ import { useAIButtonHover as Ae } from "./hooks/useAIButtonHover.mjs";
38
+ import Ne from "../components/AIErrorTooltip/index.mjs";
39
+ import { canvasToImageCoords as Se, imageToCanvasCoords as xe } from "./utils/coordinateUtils.mjs";
40
+ import { REGION_NAME_PREFIX as we, DEFAULT_REGION_NAME as Oe, ZOOM_PRECISION_ERROR as _e, TEXT_LAYOUT_RECT_FILL_COLOR as Le, TEXT_LAYOUT_RECT_STROKE_COLOR as ye, TRANSPARENT_FILL as yt, SELECTED_RECT_FILL_COLOR as Me, RECT_STROKE_COLOR as Mt, BASE_STROKE_WIDTH as ct, ACTIVE_RECT_STROKE_COLOR as De } from "../constants.mjs";
41
+ const be = re.forwardRef(({
42
+ sample: i,
41
43
  labelDefinitions: g,
42
- labels: l,
43
- onImageLoad: xe,
44
+ labels: d,
45
+ onImageLoad: Dt,
44
46
  onChange: O,
45
- onRegionSelect: ce,
47
+ onRegionSelect: at,
46
48
  onRegionChange: J,
47
- ocrRecognize: Le,
49
+ ocrRecognize: bt,
48
50
  activeLabelValue: R,
49
51
  onClearActive: Q,
50
- selectedRegion: T,
51
- onAppendTextToActive: Me,
52
+ selectedRegion: C,
53
+ onAppendTextToActive: Pt,
52
54
  readOnly: h
53
- }, De) => {
54
- var Ie, ke;
55
- const ie = C(null), k = C(null), [ye, Ue] = x(!0), [e, We] = x(), [L, be] = x(), [v, ae] = x(1), [N, j] = x(h || !1), [I, _] = x(!1), [V, Pe] = x({
55
+ }, Ut) => {
56
+ var Nt, St;
57
+ const ft = T(null), v = T(null), [Wt, Xt] = S(!0), [t, jt] = S(), [y, Ft] = S(), [I, ut] = S(1), [N, X] = S(h || !1), [k, _] = S(!1), [V, Bt] = S({
56
58
  left: 0,
57
59
  top: 0
58
- }), F = C({
60
+ }), [Ht, lt] = S(!1), [tt, mt] = S(null), j = T({
59
61
  left: 0,
60
62
  top: 0
61
- }), fe = C({
63
+ }), dt = T({
62
64
  width: 0,
63
65
  height: 0
64
- }), i = C(/* @__PURE__ */ new Map()), ue = C(null), de = C(void 0), me = C(!1), le = C(!1), z = C({
66
+ }), c = T(/* @__PURE__ */ new Map()), ht = T(null), gt = T(void 0), Rt = T(!1), pt = T(!1), Y = T({
65
67
  width: 0,
66
68
  height: 0
67
- }), he = C(!1), {
68
- updateOCRLoadingIcon: xt,
69
+ }), Et = T(!1), {
70
+ updateOCRLoadingIcon: Pe,
69
71
  ocrLoadingIconMapRef: M
70
- } = ot(e), {
71
- updateRegionNameText: B,
72
- regionNameTextMapRef: S
73
- } = rt(e), ee = nt(c == null ? void 0 : c.fileUrl), je = w((o) => {
74
- e && (S.current.forEach((t, r) => {
75
- const n = r.left || 0, m = r.top || 0;
76
- t.set({
72
+ } = ce(t), {
73
+ updateRegionNameText: z,
74
+ regionNameTextMapRef: A
75
+ } = ae(t), et = fe(i == null ? void 0 : i.fileUrl), Zt = w((o) => {
76
+ t && (A.current.forEach((e, r) => {
77
+ const n = r.left || 0, u = r.top || 0;
78
+ e.set({
77
79
  left: n,
78
80
  // 与标注框左边对齐
79
- top: m,
81
+ top: u,
80
82
  // 下边缘与标注框上边缘对齐(因为 originY 是 'bottom')
81
83
  scaleX: 1 / o,
82
84
  // 反向缩放,抵消画布缩放
83
85
  scaleY: 1 / o
84
86
  // 反向缩放,抵消画布缩放
85
87
  });
86
- }), e.renderAll());
87
- }, [e]), {
88
- updateCanvas: X
89
- } = it({
90
- sample: c,
91
- image: L,
92
- onImageLoad: xe,
93
- canvasRef: ie,
94
- containerRef: k,
95
- canvasInitializedRef: me,
96
- bgImagePositionRef: F,
97
- bgImageSizeRef: fe,
98
- rectMapRef: i,
99
- updateTextLayersRef: ue,
100
- onRectPositionUpdated: je,
101
- setCanvas: We,
102
- setImage: be,
103
- setScale: ae,
104
- setBgImagePosition: Pe,
105
- setLoading: Ue
106
- }), Fe = w(() => {
107
- const o = Array.from(i.current.values());
108
- o.forEach((t, r) => {
109
- t.name = `${vt}${r + 1}`;
110
- }), i.current.forEach((t, r) => {
111
- const n = S.current.get(r);
112
- n && (n.set("text", t.name || It), e == null || e.renderAll());
88
+ }), t.renderAll());
89
+ }, [t]), {
90
+ updateCanvas: F
91
+ } = me({
92
+ sample: i,
93
+ image: y,
94
+ onImageLoad: Dt,
95
+ canvasRef: ft,
96
+ containerRef: v,
97
+ canvasInitializedRef: Rt,
98
+ bgImagePositionRef: j,
99
+ bgImageSizeRef: dt,
100
+ rectMapRef: c,
101
+ updateTextLayersRef: ht,
102
+ onRectPositionUpdated: Zt,
103
+ setCanvas: jt,
104
+ setImage: Ft,
105
+ setScale: ut,
106
+ setBgImagePosition: Bt,
107
+ setLoading: Xt
108
+ }), Yt = w(() => {
109
+ const o = Array.from(c.current.values());
110
+ o.forEach((e, r) => {
111
+ e.name = `${we}${r + 1}`;
112
+ }), c.current.forEach((e, r) => {
113
+ const n = A.current.get(r);
114
+ n && (n.set("text", e.name || Oe), t == null || t.renderAll());
113
115
  }), O && O(o);
114
- }, [O, e]), {
115
- zoom: Xe
116
- } = Rt({
117
- canvas: e,
118
- setScale: ae,
119
- isZoomingRef: he
120
- }), Z = w(
121
- (o, t) => Ct(o, t, e, L, F),
122
- [e, L, V]
116
+ }, [O, t]), {
117
+ zoom: zt
118
+ } = ve({
119
+ canvas: t,
120
+ setScale: ut,
121
+ isZoomingRef: Et
122
+ }), B = w(
123
+ (o, e) => Se(o, e, t, y, j),
124
+ [t, y, V]
123
125
  // 添加 bgImagePosition 作为依赖,确保在图片位置更新后函数能正确工作
124
126
  ), K = w(
125
- (o, t) => Tt(o, t, e, F),
126
- [e, V]
127
+ (o, e) => xe(o, e, t, j),
128
+ [t, V]
127
129
  // 添加 bgImagePosition 作为依赖,确保在图片位置更新后函数能正确工作
128
130
  ), {
129
131
  updateTextLayers: $,
130
- textLayersMapRef: d,
132
+ textLayersMapRef: m,
131
133
  textLayoutContentMapRef: G
132
- } = at({
133
- canvas: e,
134
+ } = de({
135
+ canvas: t,
134
136
  imageToCanvasCoords: K,
135
137
  activeLabelValue: R,
136
- onAppendTextToActive: Me
138
+ onAppendTextToActive: Pt
137
139
  });
138
- ue.current = $;
140
+ ht.current = $;
139
141
  const {
140
- performOCRIfNeeded: ge,
142
+ performOCRIfNeeded: Tt,
141
143
  performOCR: q,
142
- ocrRecognizingRef: Re,
143
- ocrErrorRef: Ee
144
- } = mt({
145
- ocrRecognize: Le,
144
+ ocrRecognizingRef: Ct,
145
+ ocrErrorRef: ot
146
+ } = pe({
147
+ ocrRecognize: bt,
146
148
  onChange: O,
147
149
  updateTextLayers: $,
148
- canvas: e,
149
- rectMapRef: i,
150
- textLayersMapRef: d,
150
+ canvas: t,
151
+ rectMapRef: c,
152
+ textLayersMapRef: m,
151
153
  textLayoutContentMapRef: G
152
154
  }), {
153
- updateRegionShapeAndImage: pe
154
- } = ft({
155
- canvas: e,
156
- image: L,
155
+ updateRegionShapeAndImage: vt
156
+ } = he({
157
+ canvas: t,
158
+ image: y,
157
159
  draggable: N,
158
- canvasToImageCoords: Z,
160
+ canvasToImageCoords: B,
159
161
  imageToCanvasCoords: K,
160
- cropRegionImage: ee,
162
+ cropRegionImage: et,
161
163
  onChange: O,
162
164
  onRegionChange: J,
163
- performOCRIfNeeded: ge,
165
+ performOCRIfNeeded: Tt,
164
166
  updateTextLayers: $,
165
- rectMapRef: i,
166
- regionNameTextMapRef: S,
167
+ rectMapRef: c,
168
+ regionNameTextMapRef: A,
167
169
  ocrLoadingIconMapRef: M
168
170
  }), {
169
- setupBoundaryCheck: Ce
170
- } = pt({
171
- canvas: e,
172
- image: L,
173
- canvasToImageCoords: Z,
171
+ setupBoundaryCheck: It
172
+ } = ke({
173
+ canvas: t,
174
+ image: y,
175
+ canvasToImageCoords: B,
174
176
  imageToCanvasCoords: K,
175
- bgImagePositionRef: F,
176
- bgImageSizeRef: fe,
177
- regionNameTextMapRef: S
177
+ bgImagePositionRef: j,
178
+ bgImageSizeRef: dt,
179
+ regionNameTextMapRef: A
178
180
  });
179
- p(() => {
180
- X();
181
- }, [X]), p(() => {
182
- e && (d.current.forEach((o) => {
183
- o.forEach((t) => {
184
- t.off("mousedown"), t.off("mouseover"), t.off("mouseout"), e.remove(t), G.current.delete(t);
181
+ E(() => {
182
+ F();
183
+ }, [F]), E(() => {
184
+ t && (m.current.forEach((o) => {
185
+ o.forEach((e) => {
186
+ e.off("mousedown"), e.off("mouseover"), e.off("mouseout"), t.remove(e), G.current.delete(e);
185
187
  });
186
- }), d.current.clear(), S.current.forEach((o) => {
187
- e.remove(o);
188
- }), S.current.clear(), M.current.forEach((o) => {
189
- e.remove(o);
190
- }), M.current.clear(), i.current.forEach((o, t) => {
191
- t.off("modified"), t.off("moved"), e.remove(t);
192
- }), i.current.clear(), le.current = !1, de.current = void 0, e.renderAll());
193
- }, [e, c == null ? void 0 : c.id]), p(() => {
194
- if (!k.current)
188
+ }), m.current.clear(), A.current.forEach((o) => {
189
+ t.remove(o);
190
+ }), A.current.clear(), M.current.forEach((o) => {
191
+ t.remove(o);
192
+ }), M.current.clear(), c.current.forEach((o, e) => {
193
+ e.off("modified"), e.off("moved"), t.remove(e);
194
+ }), c.current.clear(), pt.current = !1, gt.current = void 0, t.renderAll());
195
+ }, [t, i == null ? void 0 : i.id]), E(() => {
196
+ if (!v.current)
195
197
  return;
196
- z.current = {
197
- width: k.current.offsetWidth,
198
- height: k.current.offsetHeight
198
+ Y.current = {
199
+ width: v.current.offsetWidth,
200
+ height: v.current.offsetHeight
199
201
  };
200
202
  const o = new ResizeObserver(() => {
201
- if (!k.current || he.current)
203
+ if (!v.current || Et.current)
202
204
  return;
203
- if (e) {
204
- const s = e.getZoom();
205
- if (Math.abs(s - v) > kt)
205
+ if (t) {
206
+ const s = t.getZoom();
207
+ if (Math.abs(s - I) > _e)
206
208
  return;
207
209
  }
208
- const t = k.current.offsetWidth, r = k.current.offsetHeight, n = z.current.width, m = z.current.height;
209
- (t !== n || r !== m) && (z.current = {
210
- width: t,
210
+ const e = v.current.offsetWidth, r = v.current.offsetHeight, n = Y.current.width, u = Y.current.height;
211
+ (e !== n || r !== u) && (Y.current = {
212
+ width: e,
211
213
  height: r
212
- }, X());
214
+ }, F());
213
215
  });
214
- return o.observe(k.current), () => {
216
+ return o.observe(v.current), () => {
215
217
  o.disconnect();
216
218
  };
217
- }, [X, e, v]), Y("ctrl", () => {
218
- h || (I && (_(!1), y()), j(!0));
219
+ }, [F, t, I]), Z("ctrl", () => {
220
+ h || (k && (_(!1), b()), X(!0));
219
221
  }, {
220
222
  events: ["keydown"]
221
- }), Y("ctrl", () => {
222
- h || j(!1);
223
+ }), Z("ctrl", () => {
224
+ h || X(!1);
223
225
  }, {
224
226
  events: ["keyup"]
225
- }), p(() => {
226
- if (!e)
227
+ }), E(() => {
228
+ if (!t)
227
229
  return;
228
- const o = se / v, t = /* @__PURE__ */ new Set();
229
- d.current.forEach((r) => {
230
+ const o = ct / I, e = /* @__PURE__ */ new Set();
231
+ m.current.forEach((r) => {
230
232
  r.forEach((n) => {
231
- t.add(n);
233
+ e.add(n);
232
234
  });
233
- }), e.getObjects().forEach((r) => {
234
- r instanceof P.Rect && !t.has(r) && r.set({
235
+ }), t.getObjects().forEach((r) => {
236
+ r instanceof W.Rect && !e.has(r) && r.set({
235
237
  strokeWidth: o,
236
238
  strokeUniform: !0,
237
239
  objectCaching: !1,
@@ -239,12 +241,12 @@ const _t = Qe.forwardRef(({
239
241
  statefullCache: !1,
240
242
  noScaleCache: !1
241
243
  });
242
- }), d.current.forEach((r) => {
244
+ }), m.current.forEach((r) => {
243
245
  r.forEach((n) => {
244
246
  n.set({
245
- fill: Nt,
247
+ fill: Le,
246
248
  // 确保填充色被保留
247
- stroke: St,
249
+ stroke: ye,
248
250
  // 确保边框色被保留
249
251
  strokeWidth: o,
250
252
  // 根据缩放调整边框宽度,保持视觉一致
@@ -255,135 +257,154 @@ const _t = Qe.forwardRef(({
255
257
  noScaleCache: !1
256
258
  });
257
259
  });
258
- }), S.current.forEach((r, n) => {
259
- const m = n.left || 0, s = n.top || 0;
260
+ }), A.current.forEach((r, n) => {
261
+ const u = n.left || 0, s = n.top || 0;
260
262
  r.set({
261
- left: m,
263
+ left: u,
262
264
  // 与标注框左边对齐
263
265
  top: s,
264
266
  // 下边缘与标注框上边缘对齐(因为 originY 是 'bottom')
265
- scaleX: 1 / v,
267
+ scaleX: 1 / I,
266
268
  // 反向缩放,抵消画布缩放
267
- scaleY: 1 / v
269
+ scaleY: 1 / I
268
270
  // 反向缩放,抵消画布缩放
269
271
  });
270
272
  const a = M.current.get(n);
271
273
  if (a) {
272
- const u = n.getScaledWidth();
274
+ const l = n.getScaledWidth();
273
275
  n.getScaledHeight(), a.set({
274
- left: m,
276
+ left: u,
275
277
  // top 位置由动画控制,这里不更新
276
- scaleX: 1 / v,
278
+ scaleX: 1 / I,
277
279
  // 反向缩放,抵消画布缩放,保持固定视觉粗细
278
- scaleY: 1 / v
280
+ scaleY: 1 / I
279
281
  // 反向缩放,抵消画布缩放,保持固定视觉粗细
280
282
  });
281
283
  const f = a.getObjects();
282
284
  if (f && f.length > 0) {
283
- const E = u * v;
284
- f.forEach((A) => {
285
- A instanceof P.Rect && A.set("width", E);
285
+ const p = l * I;
286
+ f.forEach((x) => {
287
+ x instanceof W.Rect && x.set("width", p);
286
288
  });
287
289
  }
288
290
  }
289
- }), e.renderAll();
290
- }, [e, v]), ut({
291
- canvas: e,
291
+ }), t.renderAll();
292
+ }, [t, I]), ge({
293
+ canvas: t,
292
294
  draggable: N,
293
- drawingMode: I,
294
- textLayersMapRef: d
295
+ drawingMode: k,
296
+ textLayersMapRef: m
295
297
  });
296
298
  const {
297
299
  performDelete: D,
298
- deleteDirectly: Ze
299
- } = lt({
300
- canvas: e,
300
+ deleteDirectly: Kt
301
+ } = Ee({
302
+ canvas: t,
301
303
  onRegionChange: J,
302
- updateRegionNames: Fe,
303
- rectMapRef: i,
304
- textLayersMapRef: d,
304
+ updateRegionNames: Yt,
305
+ rectMapRef: c,
306
+ textLayersMapRef: m,
305
307
  textLayoutContentMapRef: G,
306
- regionNameTextMapRef: S,
308
+ regionNameTextMapRef: A,
307
309
  ocrLoadingIconMapRef: M
308
310
  });
309
311
  w((o) => {
310
- if (!e)
312
+ if (!t)
311
313
  return;
312
- let t = null;
313
- i.current.forEach((r, n) => {
314
- r.id === o && (t = n);
315
- }), t && D(t);
316
- }, [e, D]);
317
- const He = w((o) => {
318
- if (!e)
314
+ let e = null;
315
+ c.current.forEach((r, n) => {
316
+ r.id === o && (e = n);
317
+ }), e && D(e);
318
+ }, [t, D]);
319
+ const $t = w((o) => {
320
+ if (!t)
319
321
  return;
320
- let t = null;
321
- i.current.forEach((r) => {
322
- r.id === o && (t = r);
323
- }), t && q(t);
324
- }, [e, q]), Ye = w((o) => {
325
- if (!e)
322
+ let e = null;
323
+ c.current.forEach((r) => {
324
+ r.id === o && (e = r);
325
+ }), e && q(e);
326
+ }, [t, q]), Gt = w((o) => {
327
+ if (!t)
326
328
  return;
327
- const t = i.current.get(o);
328
- t && q(t);
329
- }, [e, q]);
330
- Ve(De, () => ({
331
- performOCRById: He,
332
- ocrRecognizingRef: Re,
333
- ocrErrorRef: Ee
329
+ const e = c.current.get(o);
330
+ e && q(e);
331
+ }, [t, q]);
332
+ ne(Ut, () => ({
333
+ performOCRById: $t,
334
+ ocrRecognizingRef: Ct,
335
+ ocrErrorRef: ot
334
336
  }));
335
337
  const {
336
- createDeleteControl: te
337
- } = ht({
338
+ createDeleteControl: rt
339
+ } = Te({
338
340
  performDelete: D
339
341
  }), {
340
- createOCRControl: oe
341
- } = gt({
342
- performOCR: Ye,
343
- ocrRecognizingRef: Re,
344
- ocrErrorRef: Ee,
345
- rectMapRef: i
342
+ createOCRControl: nt
343
+ } = Ce({
344
+ performOCR: Gt,
345
+ ocrRecognizingRef: Ct,
346
+ ocrErrorRef: ot,
347
+ rectMapRef: c
346
348
  });
347
- dt({
348
- canvas: e,
349
- onRegionSelect: ce,
350
- createDeleteControl: te,
351
- createOCRControl: oe,
352
- textLayersMapRef: d,
353
- rectMapRef: i
349
+ Re({
350
+ canvas: t,
351
+ onRegionSelect: at,
352
+ createDeleteControl: rt,
353
+ createOCRControl: nt,
354
+ textLayersMapRef: m,
355
+ rectMapRef: c
356
+ }), Ae({
357
+ canvas: t,
358
+ ocrErrorRef: ot,
359
+ rectMapRef: c,
360
+ onAIButtonHover: (o, e) => {
361
+ var r;
362
+ if (o && e) {
363
+ const n = (r = v.current) == null ? void 0 : r.getBoundingClientRect();
364
+ if (n) {
365
+ const u = e.x - n.left, s = e.y - n.top;
366
+ lt(!0), mt({
367
+ x: u,
368
+ y: s
369
+ });
370
+ }
371
+ } else
372
+ lt(!1), mt(null);
373
+ }
354
374
  });
355
375
  const {
356
- stopDraw: y
357
- } = st({
358
- canvas: e,
359
- drawingMode: I,
376
+ stopDraw: b
377
+ } = ue({
378
+ canvas: t,
379
+ drawingMode: k,
360
380
  draggable: N,
361
381
  setDrawingMode: _,
362
- canvasToImageCoords: Z,
382
+ canvasToImageCoords: B,
363
383
  labelDefinitions: g,
364
384
  onChange: O,
365
- cropRegionImage: ee,
366
- updateRegionShapeAndImage: pe,
367
- performOCRIfNeeded: ge,
368
- createDeleteControl: te,
369
- createOCRControl: oe,
370
- updateRegionNameText: B,
385
+ cropRegionImage: et,
386
+ updateRegionShapeAndImage: vt,
387
+ performOCRIfNeeded: Tt,
388
+ createDeleteControl: rt,
389
+ createOCRControl: nt,
390
+ updateRegionNameText: z,
371
391
  onRegionChange: J,
372
- onRegionSelect: ce,
373
- rectMapRef: i,
374
- textLayersMapRef: d,
375
- setupBoundaryCheck: Ce
392
+ onRegionSelect: at,
393
+ rectMapRef: c,
394
+ textLayersMapRef: m,
395
+ regionNameTextMapRef: A,
396
+ setupBoundaryCheck: It
376
397
  });
377
- p(() => {
378
- R && (_(!1), y());
379
- }, [R, y]), p(() => {
380
- h && (j(!0), _(!1), y());
381
- }, [h, y]), p(() => {
382
- if (!e)
398
+ E(() => {
399
+ R && (_(!1), b());
400
+ }, [R, b]), E(() => {
401
+ h && (X(!0), _(!1), b());
402
+ }, [h, b]), E(() => {
403
+ if (!t)
383
404
  return;
384
405
  const o = () => {
385
- e.getObjects().forEach((t) => {
386
- t instanceof P.Rect && t.selectable && (t.set({
406
+ t.getObjects().forEach((e) => {
407
+ e instanceof W.Rect && e.selectable && (e.set({
387
408
  lockMovementX: h,
388
409
  lockMovementY: h,
389
410
  lockScalingX: h,
@@ -391,240 +412,242 @@ const _t = Qe.forwardRef(({
391
412
  hasControls: !h
392
413
  // 在只读模式下,如果有 activeLabelValue,我们可能希望它保持选中状态
393
414
  // 但不允许用户通过点击来取消选中或选中其他(这个由 canvas.selection 控制)
394
- }), h && t.controls);
395
- }), e.requestRenderAll();
415
+ }), h && e.controls);
416
+ }), t.requestRenderAll();
396
417
  };
397
- return o(), e.on("object:added", o), () => {
398
- e.off("object:added", o);
418
+ return o(), t.on("object:added", o), () => {
419
+ t.off("object:added", o);
399
420
  };
400
- }, [e, h]), ct({
401
- canvas: e,
402
- sample: c,
403
- image: L,
421
+ }, [t, h]), le({
422
+ canvas: t,
423
+ sample: i,
424
+ image: y,
404
425
  bgImagePosition: V,
405
- canvasInitializedRef: me,
406
- bgImagePositionRef: F,
407
- sampleRef: de,
408
- labelsLoadedRef: le,
409
- rectMapRef: i,
410
- textLayersMapRef: d,
426
+ canvasInitializedRef: Rt,
427
+ bgImagePositionRef: j,
428
+ sampleRef: gt,
429
+ labelsLoadedRef: pt,
430
+ rectMapRef: c,
431
+ textLayersMapRef: m,
411
432
  textLayoutContentMapRef: G,
412
- regionNameTextMapRef: S,
433
+ regionNameTextMapRef: A,
413
434
  ocrLoadingIconMapRef: M,
414
435
  imageToCanvasCoords: K,
415
- updateRegionShapeAndImage: pe,
416
- createDeleteControl: te,
417
- createOCRControl: oe,
418
- updateRegionNameText: B,
436
+ updateRegionShapeAndImage: vt,
437
+ createDeleteControl: rt,
438
+ createOCRControl: nt,
439
+ updateRegionNameText: z,
419
440
  updateTextLayers: $,
420
- setupBoundaryCheck: Ce,
421
- cropRegionImage: ee,
441
+ setupBoundaryCheck: It,
442
+ cropRegionImage: et,
422
443
  onChange: O
423
444
  });
424
- const Te = C([]);
425
- p(() => {
426
- if (!e)
445
+ const kt = T([]);
446
+ E(() => {
447
+ if (!t)
427
448
  return;
428
- const o = Te.current, t = l != null ? l : [], r = new Set(o.map((s) => s.id)), n = new Set(t.map((s) => s.id));
429
- if (t.length < o.length) {
449
+ const o = kt.current, e = d != null ? d : [], r = new Set(o.map((s) => s.id)), n = new Set(e.map((s) => s.id));
450
+ if (e.length < o.length) {
430
451
  const s = [];
431
- i.current.forEach((a, u) => {
432
- r.has(a.id) && !n.has(a.id) && s.push(u);
452
+ c.current.forEach((a, l) => {
453
+ r.has(a.id) && !n.has(a.id) && s.push(l);
433
454
  }), s.forEach((a) => {
434
- Ze(a);
455
+ Kt(a);
435
456
  });
436
457
  }
437
- if (Te.current = t, !l || l.length === 0)
458
+ if (kt.current = e, !d || d.length === 0)
438
459
  return;
439
- let m = !1;
440
- i.current.forEach((s, a) => {
441
- var E, A;
442
- const u = l.find((H) => H.id === s.id);
443
- if (!u)
460
+ let u = !1;
461
+ c.current.forEach((s, a) => {
462
+ var p, x;
463
+ const l = d.find((H) => H.id === s.id);
464
+ if (!l)
444
465
  return;
445
- const f = we(ne(ne({}, s), u), {
466
+ const f = _t(it(it({}, s), l), {
446
467
  // Keep shape from canvas to avoid desync
447
468
  shape: s.shape,
448
- image: (E = u.image) != null ? E : s.image,
449
- textLayouts: (A = u.textLayouts) != null ? A : s.textLayouts
469
+ image: (p = l.image) != null ? p : s.image,
470
+ textLayouts: (x = l.textLayouts) != null ? x : s.textLayouts
450
471
  });
451
- (f.name !== s.name || f.content !== s.content || f.image !== s.image || f.textLayouts !== s.textLayouts) && (i.current.set(a, f), f.name !== s.name && B(a, f), m = !0);
452
- }), m && (e == null || e.renderAll());
453
- }, [l, e, B, D]), Et({
454
- canvas: e,
455
- drawingMode: I,
472
+ (f.name !== s.name || f.content !== s.content || f.image !== s.image || f.textLayouts !== s.textLayouts) && (c.current.set(a, f), f.name !== s.name && z(a, f), u = !0);
473
+ }), u && (t == null || t.renderAll());
474
+ }, [d, t, z, D]), Ie({
475
+ canvas: t,
476
+ drawingMode: k,
456
477
  draggable: N,
457
- textLayersMapRef: d
458
- }), p(() => {
459
- if (e)
460
- if (T === null) {
478
+ textLayersMapRef: m
479
+ }), E(() => {
480
+ if (t)
481
+ if (C === null) {
461
482
  const o = /* @__PURE__ */ new Set();
462
- d.current.forEach((r) => {
483
+ m.current.forEach((r) => {
463
484
  r.forEach((n) => {
464
485
  o.add(n);
465
486
  });
466
- }), e.getObjects().forEach((r) => {
467
- r instanceof P.Rect && !o.has(r) && r.set({
468
- fill: _e
487
+ }), t.getObjects().forEach((r) => {
488
+ r instanceof W.Rect && !o.has(r) && r.set({
489
+ fill: yt
469
490
  // 移除填充色
470
491
  });
471
- }), e.getActiveObject() && (e.discardActiveObject(), e.renderAll());
492
+ }), t.getActiveObject() && (t.discardActiveObject(), t.renderAll());
472
493
  } else {
473
- const o = e.getActiveObject(), t = o ? i.current.get(o) : null;
474
- if ((t == null ? void 0 : t.id) === (T == null ? void 0 : T.id))
494
+ const o = t.getActiveObject(), e = o ? c.current.get(o) : null;
495
+ if ((e == null ? void 0 : e.id) === (C == null ? void 0 : C.id))
475
496
  return;
476
- if (T) {
497
+ if (C) {
477
498
  let r = null;
478
- if (i.current.forEach((n, m) => {
479
- n.id === T.id && (r = m);
499
+ if (c.current.forEach((n, u) => {
500
+ n.id === C.id && (r = u);
480
501
  }), r) {
481
502
  const n = /* @__PURE__ */ new Set();
482
- d.current.forEach((u) => {
483
- u.forEach((f) => {
503
+ m.current.forEach((l) => {
504
+ l.forEach((f) => {
484
505
  n.add(f);
485
506
  });
486
- }), e.getObjects().forEach((u) => {
487
- u instanceof P.Rect && !n.has(u) && u.set({
488
- fill: _e
507
+ }), t.getObjects().forEach((l) => {
508
+ l instanceof W.Rect && !n.has(l) && l.set({
509
+ fill: yt
489
510
  // 移除填充色
490
511
  });
491
512
  });
492
- const m = e.getZoom(), s = se / m, a = r;
513
+ const u = t.getZoom(), s = ct / u, a = r;
493
514
  a.set({
494
- fill: At,
515
+ fill: Me,
495
516
  // 选中时添加填充色
517
+ stroke: Mt,
518
+ // 选中时取消高亮,使用普通边框颜色
496
519
  strokeUniform: !0,
497
520
  strokeWidth: s,
498
521
  objectCaching: !1,
499
522
  statefullCache: !1,
500
523
  noScaleCache: !1
501
- }), e.setActiveObject(a), e.renderAll();
524
+ }), t.setActiveObject(a), t.renderAll();
502
525
  }
503
526
  }
504
527
  }
505
- }, [e, T, i, d]), p(() => {
528
+ }, [t, C, c, m]), E(() => {
506
529
  var a;
507
- if (!e)
530
+ if (!t)
508
531
  return;
509
- const o = (a = R == null ? void 0 : R.region) == null ? void 0 : a.id, t = T == null ? void 0 : T.id, r = /* @__PURE__ */ new Set();
510
- d.current.forEach((u) => {
511
- u.forEach((f) => {
532
+ const o = (a = R == null ? void 0 : R.region) == null ? void 0 : a.id, e = C == null ? void 0 : C.id, r = /* @__PURE__ */ new Set();
533
+ m.current.forEach((l) => {
534
+ l.forEach((f) => {
512
535
  r.add(f);
513
536
  });
514
537
  });
515
538
  let n = !1;
516
- const m = e.getZoom(), s = se / m;
517
- i.current.forEach((u, f) => {
539
+ const u = t.getZoom(), s = ct / u;
540
+ c.current.forEach((l, f) => {
518
541
  if (r.has(f))
519
542
  return;
520
- const E = o === u.id;
521
- if (t === u.id) {
522
- const W = d.current.get(f);
523
- W && W.length > 0 && W.forEach((Ne) => {
524
- Ne.visible !== E && (Ne.set({
525
- visible: E
543
+ const p = o === l.id;
544
+ if (e === l.id) {
545
+ const U = m.current.get(f);
546
+ U && U.length > 0 && U.forEach((xt) => {
547
+ xt.visible !== p && (xt.set({
548
+ visible: p
526
549
  }), n = !0);
527
550
  });
528
551
  return;
529
552
  }
530
- const H = f.stroke, re = E ? wt : Ot;
531
- H !== re && (f.set({
532
- stroke: re,
553
+ const H = f.stroke, st = p ? De : Mt;
554
+ H !== st && (f.set({
555
+ stroke: st,
533
556
  strokeWidth: s,
534
557
  strokeUniform: !0
535
558
  }), n = !0);
536
- const U = d.current.get(f);
537
- U && U.length > 0 && U.forEach((W) => {
538
- W.visible !== E && (W.set({
539
- visible: E
559
+ const P = m.current.get(f);
560
+ P && P.length > 0 && P.forEach((U) => {
561
+ U.visible !== p && (U.set({
562
+ visible: p
540
563
  }), n = !0);
541
564
  });
542
- }), n && e.renderAll();
543
- }, [e, R, T, d, i]), p(() => {
544
- var n, m;
545
- if (!e)
565
+ }), n && t.renderAll();
566
+ }, [t, R, C, m, c]), E(() => {
567
+ var n, u;
568
+ if (!t)
546
569
  return;
547
570
  const o = (n = R == null ? void 0 : R.region) == null ? void 0 : n.id;
548
571
  if (!o)
549
572
  return;
550
- let t = null;
551
- if (i.current.forEach((s, a) => {
552
- s.id === o && (t = a);
553
- }), !t)
573
+ let e = null;
574
+ if (c.current.forEach((s, a) => {
575
+ s.id === o && (e = a);
576
+ }), !e)
554
577
  return;
555
- t.bringToFront(), ((m = d.current.get(t)) != null ? m : []).forEach((s) => {
578
+ e.bringToFront(), ((u = m.current.get(e)) != null ? u : []).forEach((s) => {
556
579
  s.bringToFront();
557
- }), e.renderAll();
558
- }, [e, R, i, d]), p(() => {
559
- if (!e || !R || !Q)
580
+ }), t.renderAll();
581
+ }, [t, R, c, m]), E(() => {
582
+ if (!t || !R || !Q)
560
583
  return;
561
- const o = (t) => {
562
- var U;
563
- if (I)
584
+ const o = (e) => {
585
+ var P;
586
+ if (k)
564
587
  return;
565
- const r = (U = t.e) == null ? void 0 : U.target;
588
+ const r = (P = e.e) == null ? void 0 : P.target;
566
589
  if ((r == null ? void 0 : r.tagName) === "INPUT" || (r == null ? void 0 : r.tagName) === "TEXTAREA")
567
590
  return;
568
- const n = e.getPointer(t.e), m = n.x, s = n.y, a = Z(m, s), u = R.region, {
591
+ const n = t.getPointer(e.e), u = n.x, s = n.y, a = B(u, s), l = R.region, {
569
592
  x: f,
570
- y: E,
571
- width: A,
593
+ y: p,
594
+ width: x,
572
595
  height: H
573
- } = u.shape;
574
- a.x >= f && a.x <= f + A && a.y >= E && a.y <= E + H || Q();
596
+ } = l.shape;
597
+ a.x >= f && a.x <= f + x && a.y >= p && a.y <= p + H || Q();
575
598
  };
576
- return e.on("mouse:down", o), () => {
577
- e.off("mouse:down", o);
599
+ return t.on("mouse:down", o), () => {
600
+ t.off("mouse:down", o);
578
601
  };
579
- }, [e, R, Q, Z, I]);
580
- const ve = w((o) => {
581
- const t = o.target;
582
- if ((t == null ? void 0 : t.tagName) === "INPUT" || (t == null ? void 0 : t.tagName) === "TEXTAREA" || !e || h)
602
+ }, [t, R, Q, B, k]);
603
+ const At = w((o) => {
604
+ const e = o.target;
605
+ if ((e == null ? void 0 : e.tagName) === "INPUT" || (e == null ? void 0 : e.tagName) === "TEXTAREA" || !t || h)
583
606
  return;
584
- const r = e.getActiveObject();
585
- !r || !(r instanceof P.Rect) || D(r);
586
- }, [e, D]);
587
- Y("Delete", ve), Y("Backspace", ve), Y("r", (o) => {
588
- const t = o.target;
589
- (t == null ? void 0 : t.tagName) === "INPUT" || (t == null ? void 0 : t.tagName) === "TEXTAREA" || t != null && t.isContentEditable || h || !I && !N && _(!0);
607
+ const r = t.getActiveObject();
608
+ !r || !(r instanceof W.Rect) || D(r);
609
+ }, [t, D]);
610
+ Z("Delete", At), Z("Backspace", At), Z("r", (o) => {
611
+ const e = o.target;
612
+ (e == null ? void 0 : e.tagName) === "INPUT" || (e == null ? void 0 : e.tagName) === "TEXTAREA" || e != null && e.isContentEditable || h || !k && !N && _(!0);
590
613
  }, {
591
614
  exactMatch: !1
592
615
  // 允许大小写
593
616
  });
594
- const ze = () => {
595
- h || (I && (_(!1), y()), j(!N));
596
- }, Be = () => {
597
- h || (N && j(!1), _(!I));
617
+ const qt = () => {
618
+ h || (k && (_(!1), b()), X(!N));
619
+ }, Jt = () => {
620
+ h || (N && X(!1), _(!k));
598
621
  };
599
- return p(() => () => {
600
- e && e.dispose();
601
- }, []), /* @__PURE__ */ Oe("div", {
622
+ return E(() => () => {
623
+ t && t.dispose();
624
+ }, []), /* @__PURE__ */ Lt("div", {
602
625
  style: {
603
626
  width: "100%",
604
627
  height: "100%",
605
628
  display: "flex",
606
629
  position: "relative"
607
630
  },
608
- children: [ye && /* @__PURE__ */ b("div", {
631
+ children: [Wt && /* @__PURE__ */ L("div", {
609
632
  className: "vlm-loading-overlay",
610
- children: /* @__PURE__ */ b("div", {
633
+ children: /* @__PURE__ */ L("div", {
611
634
  className: "vlm-loading-spinner"
612
635
  })
613
- }), /* @__PURE__ */ b("div", {
636
+ }), /* @__PURE__ */ L("div", {
614
637
  className: "vlm-marker-toolbar",
615
- children: /* @__PURE__ */ b(tt, {
616
- drawingMode: I,
638
+ children: /* @__PURE__ */ L(ie, {
639
+ drawingMode: k,
617
640
  draggable: N,
618
- scale: v,
619
- onToggleDrawingMode: Be,
620
- onToggleDrag: ze,
621
- onZoom: Xe,
622
- onFitToScreen: X,
641
+ scale: I,
642
+ onToggleDrawingMode: Jt,
643
+ onToggleDrag: qt,
644
+ onZoom: zt,
645
+ onFitToScreen: F,
623
646
  readOnly: h
624
647
  })
625
- }), /* @__PURE__ */ Oe("div", {
626
- ref: k,
627
- className: et({
648
+ }), /* @__PURE__ */ Lt("div", {
649
+ ref: v,
650
+ className: se({
628
651
  "vlm-label-maker-wrap": !0,
629
652
  draggable: N
630
653
  }),
@@ -635,17 +658,21 @@ const _t = Qe.forwardRef(({
635
658
  flex: 1,
636
659
  position: "relative"
637
660
  },
638
- children: [(((Ie = c == null ? void 0 : c.sampleFileName) == null ? void 0 : Ie.originalName) || ((ke = c == null ? void 0 : c.sampleFileName) == null ? void 0 : ke.name)) && /* @__PURE__ */ b("div", {
661
+ children: [(((Nt = i == null ? void 0 : i.sampleFileName) == null ? void 0 : Nt.originalName) || ((St = i == null ? void 0 : i.sampleFileName) == null ? void 0 : St.name)) && /* @__PURE__ */ L("div", {
639
662
  className: "vlm-image-name",
640
- children: c.sampleFileName.originalName || c.sampleFileName.name
641
- }), /* @__PURE__ */ b("canvas", {
663
+ children: i.sampleFileName.originalName || i.sampleFileName.name
664
+ }), /* @__PURE__ */ L("canvas", {
642
665
  className: "vlm-label-maker-canvas",
643
- ref: ie
666
+ ref: ft
667
+ }), tt && /* @__PURE__ */ L(Ne, {
668
+ visible: Ht,
669
+ x: tt.x,
670
+ y: tt.y
644
671
  })]
645
672
  })]
646
673
  });
647
674
  });
648
- _t.displayName = "VLMLabelMaker";
675
+ be.displayName = "VLMLabelMaker";
649
676
  export {
650
- _t as default
677
+ be as default
651
678
  };