@glodon-aiot/dataset-annotation 3.13.0-alpha.29 → 3.14.0-alpha.31

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