@glodon-aiot/dataset-annotation 3.13.0-alpha.29 → 3.14.0-alpha.30
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.
- package/dist/es/components/DetectionAnnotation/components/LabelMaker/RectLabel.mjs +151 -135
- package/dist/es/components/DetectionAnnotation/components/LabelMaker/index.mjs +244 -218
- package/dist/es/components/VLMAnnotation/RegionItem.mjs +135 -59
- package/dist/es/components/VLMAnnotation/TextAnnotationPanel.mjs +73 -62
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteRegion.mjs +55 -40
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDrawingMode.mjs +291 -162
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRControl.mjs +100 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRRecognition.mjs +88 -55
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionBoundaryCheck.mjs +103 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionLoader.mjs +123 -91
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionSelection.mjs +42 -39
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionUpdate.mjs +55 -60
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/ai.svg.mjs +4 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/error.svg.mjs +4 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/loading.svg.mjs +4 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/star.svg.mjs +4 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/index.mjs +512 -387
- package/dist/es/components/VLMAnnotation/constants.mjs +39 -32
- package/dist/es/components/VLMAnnotation/index.mjs +187 -150
- package/dist/es/index.mjs +1 -1
- package/dist/lib/index.js +4 -4
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteRegion.d.ts +1 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDrawingMode.d.ts +3 -1
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRControl.d.ts +16 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRRecognition.d.ts +3 -2
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionBoundaryCheck.d.ts +31 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionLoader.d.ts +5 -1
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionSelection.d.ts +2 -1
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/index.d.ts +2 -2
- package/dist/src/components/VLMAnnotation/constants.d.ts +19 -3
- package/dist/src/components/VLMAnnotation/index.d.ts +1 -1
- package/dist/src/components/VLMAnnotation/types.d.ts +15 -0
- package/package.json +2 -2
|
@@ -1,68 +1,101 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var F = (f, m, i) => new Promise((s, n) => {
|
|
2
|
+
var S = (r) => {
|
|
3
3
|
try {
|
|
4
|
-
|
|
5
|
-
} catch (
|
|
6
|
-
|
|
4
|
+
c(i.next(r));
|
|
5
|
+
} catch (u) {
|
|
6
|
+
n(u);
|
|
7
7
|
}
|
|
8
|
-
},
|
|
8
|
+
}, y = (r) => {
|
|
9
9
|
try {
|
|
10
|
-
|
|
11
|
-
} catch (
|
|
12
|
-
|
|
10
|
+
c(i.throw(r));
|
|
11
|
+
} catch (u) {
|
|
12
|
+
n(u);
|
|
13
13
|
}
|
|
14
|
-
},
|
|
15
|
-
|
|
14
|
+
}, c = (r) => r.done ? s(r.value) : Promise.resolve(r.value).then(S, y);
|
|
15
|
+
c((i = i.apply(f, m)).next());
|
|
16
16
|
});
|
|
17
|
-
import { useRef as k, useCallback as
|
|
18
|
-
const
|
|
19
|
-
ocrRecognize:
|
|
20
|
-
onChange:
|
|
21
|
-
updateTextLayers:
|
|
22
|
-
canvas:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
textLayoutContentMapRef: d
|
|
17
|
+
import { useRef as k, useCallback as N } from "react";
|
|
18
|
+
const H = ({
|
|
19
|
+
ocrRecognize: f,
|
|
20
|
+
onChange: m,
|
|
21
|
+
updateTextLayers: i,
|
|
22
|
+
canvas: s,
|
|
23
|
+
rectMapRef: n,
|
|
24
|
+
textLayersMapRef: S,
|
|
25
|
+
textLayoutContentMapRef: y
|
|
27
26
|
}) => {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
const c = k(/* @__PURE__ */ new Set()), r = k(/* @__PURE__ */ new Set()), u = k(/* @__PURE__ */ new Map()), v = N((e, o) => F(void 0, null, function* () {
|
|
28
|
+
var t;
|
|
29
|
+
if (o !== "create" && o !== "update" || !f || !e.image)
|
|
30
|
+
return;
|
|
31
|
+
const l = (t = Array.from(n.current.entries()).find(([, d]) => d.id === e.id)) == null ? void 0 : t[0];
|
|
32
|
+
if (!l)
|
|
33
|
+
return;
|
|
34
|
+
const A = S.current.get(l);
|
|
35
|
+
A && s && (A.forEach((d) => {
|
|
36
|
+
d.off("mousedown"), d.off("mouseover"), d.off("mouseout"), y.current.delete(d), s.remove(d);
|
|
37
|
+
}), S.current.delete(l), s.renderAll());
|
|
38
|
+
const q = n.current.get(l);
|
|
39
|
+
q && q.textLayouts && delete q.textLayouts;
|
|
40
|
+
const a = (u.current.get(e.id) || 0) + 1;
|
|
41
|
+
u.current.set(e.id, a), r.current.delete(e.id), c.current.add(e.id);
|
|
42
|
+
try {
|
|
43
|
+
const d = yield f(e.image);
|
|
44
|
+
if (u.current.get(e.id) !== a)
|
|
45
|
+
return;
|
|
46
|
+
c.current.delete(e.id), r.current.delete(e.id);
|
|
47
|
+
const E = n.current.get(l);
|
|
48
|
+
if (E && u.current.get(e.id) === a && (E.textLayouts = d, i(l, E), m)) {
|
|
49
|
+
const B = Array.from(n.current.values());
|
|
50
|
+
m(B);
|
|
51
|
+
}
|
|
52
|
+
} catch (d) {
|
|
53
|
+
if (u.current.get(e.id) !== a)
|
|
33
54
|
return;
|
|
34
|
-
|
|
35
|
-
|
|
55
|
+
c.current.delete(e.id), r.current.add(e.id), console.error("Failed to perform OCR recognition:", d);
|
|
56
|
+
}
|
|
57
|
+
}), [f, m, i, s, n, S, y]), x = N((e) => F(void 0, null, function* () {
|
|
58
|
+
var a;
|
|
59
|
+
if (!f || !e.image)
|
|
60
|
+
return;
|
|
61
|
+
const o = (a = Array.from(n.current.entries()).find(([, t]) => t.id === e.id)) == null ? void 0 : a[0];
|
|
62
|
+
if (!o)
|
|
63
|
+
return;
|
|
64
|
+
const l = S.current.get(o);
|
|
65
|
+
l && s && (l.forEach((t) => {
|
|
66
|
+
t.off("mousedown"), t.off("mouseover"), t.off("mouseout"), y.current.delete(t), s.remove(t);
|
|
67
|
+
}), S.current.delete(o), s.renderAll());
|
|
68
|
+
const A = n.current.get(o);
|
|
69
|
+
A && A.textLayouts && delete A.textLayouts;
|
|
70
|
+
const q = (u.current.get(e.id) || 0) + 1;
|
|
71
|
+
u.current.set(e.id, q), r.current.delete(e.id), c.current.add(e.id);
|
|
72
|
+
try {
|
|
73
|
+
const t = yield f(e.image);
|
|
74
|
+
if (u.current.get(e.id) !== q)
|
|
36
75
|
return;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
A && o(u, A, !0);
|
|
47
|
-
try {
|
|
48
|
-
const r = yield i(e.image);
|
|
49
|
-
if (n.current.get(e.id) !== q)
|
|
50
|
-
return;
|
|
51
|
-
t.current.delete(e.id), o(u, e, !1);
|
|
52
|
-
const y = c.current.get(u);
|
|
53
|
-
if (y && n.current.get(e.id) === q && (y.textLayouts = r, s(u, y), l)) {
|
|
54
|
-
const F = Array.from(c.current.values());
|
|
55
|
-
l(F);
|
|
56
|
-
}
|
|
57
|
-
} catch (r) {
|
|
58
|
-
if (n.current.get(e.id) !== q)
|
|
59
|
-
return;
|
|
60
|
-
t.current.delete(e.id), o(u, e, !1), console.error("Failed to perform OCR recognition:", r);
|
|
76
|
+
if (!t || !Array.isArray(t)) {
|
|
77
|
+
c.current.delete(e.id), r.current.add(e.id), console.error("OCR returned invalid result:", t);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
c.current.delete(e.id), r.current.delete(e.id);
|
|
81
|
+
const w = n.current.get(o);
|
|
82
|
+
if (w && u.current.get(e.id) === q && (w.textLayouts = t, i(o, w), m)) {
|
|
83
|
+
const I = Array.from(n.current.values());
|
|
84
|
+
m(I);
|
|
61
85
|
}
|
|
62
|
-
}
|
|
63
|
-
|
|
86
|
+
} catch (t) {
|
|
87
|
+
if (u.current.get(e.id) !== q)
|
|
88
|
+
return;
|
|
89
|
+
c.current.delete(e.id), r.current.add(e.id), console.error("Failed to perform OCR recognition:", t);
|
|
90
|
+
}
|
|
91
|
+
}), [f, m, i, s, n, S, y]);
|
|
92
|
+
return {
|
|
93
|
+
performOCRIfNeeded: v,
|
|
94
|
+
performOCR: x,
|
|
95
|
+
ocrRecognizingRef: c,
|
|
96
|
+
ocrErrorRef: r
|
|
64
97
|
};
|
|
65
98
|
};
|
|
66
99
|
export {
|
|
67
|
-
|
|
100
|
+
H as useOCRRecognition
|
|
68
101
|
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { useCallback as q, useEffect as D } from "react";
|
|
2
|
+
const G = ({
|
|
3
|
+
canvas: n,
|
|
4
|
+
image: y,
|
|
5
|
+
canvasToImageCoords: S,
|
|
6
|
+
imageToCanvasCoords: b,
|
|
7
|
+
bgImagePositionRef: k,
|
|
8
|
+
bgImageSizeRef: A,
|
|
9
|
+
regionNameTextMapRef: Y
|
|
10
|
+
}) => {
|
|
11
|
+
const O = q((h) => {
|
|
12
|
+
if (!n || !y)
|
|
13
|
+
return;
|
|
14
|
+
const r = y.getElement();
|
|
15
|
+
if (!(r != null && r.width) || !(r != null && r.height))
|
|
16
|
+
return;
|
|
17
|
+
const i = r.width, u = r.height, d = (w) => {
|
|
18
|
+
const t = h, g = t.left || 0, p = t.top || 0, a = t.getScaledWidth(), m = t.getScaledHeight(), l = S(g, p);
|
|
19
|
+
let e = l.x, o = l.y, c = a, s = m;
|
|
20
|
+
const W = e, H = o;
|
|
21
|
+
if (e < 0 && (e = 0), o < 0 && (o = 0), e + c > i && (e = i - c), o + s > u && (o = u - s), c <= 0 || s <= 0)
|
|
22
|
+
return;
|
|
23
|
+
const L = b(e, o);
|
|
24
|
+
(e !== W || o !== H) && t.set({
|
|
25
|
+
left: L.x,
|
|
26
|
+
top: L.y
|
|
27
|
+
});
|
|
28
|
+
const Z = Y.current.get(t);
|
|
29
|
+
if (Z) {
|
|
30
|
+
const f = n.getZoom(), x = t.left || 0, X = t.top || 0;
|
|
31
|
+
Z.set({
|
|
32
|
+
left: x,
|
|
33
|
+
top: X,
|
|
34
|
+
scaleX: 1 / f,
|
|
35
|
+
scaleY: 1 / f
|
|
36
|
+
}), n.renderAll();
|
|
37
|
+
}
|
|
38
|
+
}, M = (w) => {
|
|
39
|
+
const t = h, g = t.left || 0, p = t.top || 0, a = t.getScaledWidth(), m = t.getScaledHeight(), l = S(g, p);
|
|
40
|
+
let e = l.x, o = l.y, c = a, s = m;
|
|
41
|
+
e < 0 && (c = c + e, e = 0), o < 0 && (s = s + o, o = 0), e + c > i && (c = i - e), o + s > u && (s = u - o), c = Math.max(1, c), s = Math.max(1, s);
|
|
42
|
+
const W = Math.abs(c - a) > 1e-3, H = Math.abs(s - m) > 1e-3, L = Math.abs(e - l.x) > 1e-3, Z = Math.abs(o - l.y) > 1e-3;
|
|
43
|
+
if (W || H || L || Z) {
|
|
44
|
+
const f = b(e, o), x = t.width || 1, X = t.height || 1, B = W ? Math.max(0.01, c / x) : t.scaleX || 1, U = H ? Math.max(0.01, s / X) : t.scaleY || 1;
|
|
45
|
+
t.set({
|
|
46
|
+
left: f.x,
|
|
47
|
+
top: f.y,
|
|
48
|
+
scaleX: B,
|
|
49
|
+
scaleY: U
|
|
50
|
+
});
|
|
51
|
+
const C = Y.current.get(t);
|
|
52
|
+
if (C) {
|
|
53
|
+
const T = n.getZoom(), _ = t.left || 0, j = t.top || 0;
|
|
54
|
+
C.set({
|
|
55
|
+
left: _,
|
|
56
|
+
top: j,
|
|
57
|
+
scaleX: 1 / T,
|
|
58
|
+
scaleY: 1 / T
|
|
59
|
+
}), n.renderAll();
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
const f = Y.current.get(t);
|
|
63
|
+
if (f) {
|
|
64
|
+
const x = n.getZoom(), X = t.left || 0, B = t.top || 0;
|
|
65
|
+
f.set({
|
|
66
|
+
left: X,
|
|
67
|
+
top: B,
|
|
68
|
+
scaleX: 1 / x,
|
|
69
|
+
scaleY: 1 / x
|
|
70
|
+
}), n.renderAll();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return h.on("moving", d), h.on("scaling", M), () => {
|
|
75
|
+
h.off("moving", d), h.off("scaling", M);
|
|
76
|
+
};
|
|
77
|
+
}, [n, y, S, b, Y]);
|
|
78
|
+
return D(() => {
|
|
79
|
+
if (!n || !y)
|
|
80
|
+
return;
|
|
81
|
+
const h = (r) => {
|
|
82
|
+
const i = n, u = i == null ? void 0 : i._currentTransform;
|
|
83
|
+
if (!u)
|
|
84
|
+
return;
|
|
85
|
+
const d = u.action;
|
|
86
|
+
if (!d || d !== "move" && !d.startsWith("scale"))
|
|
87
|
+
return;
|
|
88
|
+
const M = n.getPointer(r.e), w = M.x, t = M.y, g = k.current.left, p = k.current.top, a = g + A.current.width, m = p + A.current.height;
|
|
89
|
+
if (w < g || w > a || t < p || t > m) {
|
|
90
|
+
const e = i == null ? void 0 : i._onMouseUp;
|
|
91
|
+
typeof e == "function" && e(r.e);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
return n.on("mouse:move", h), () => {
|
|
95
|
+
n.off("mouse:move", h);
|
|
96
|
+
};
|
|
97
|
+
}, [n, y, k, A]), {
|
|
98
|
+
setupBoundaryCheck: O
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
export {
|
|
102
|
+
G as useRegionBoundaryCheck
|
|
103
|
+
};
|
|
@@ -1,61 +1,65 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
for (var
|
|
6
|
-
|
|
7
|
-
if (
|
|
8
|
-
for (var
|
|
9
|
-
|
|
10
|
-
return
|
|
1
|
+
var B = Object.defineProperty;
|
|
2
|
+
var H = Object.getOwnPropertySymbols;
|
|
3
|
+
var C = Object.prototype.hasOwnProperty, D = Object.prototype.propertyIsEnumerable;
|
|
4
|
+
var X = (o, t, n) => t in o ? B(o, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : o[t] = n, P = (o, t) => {
|
|
5
|
+
for (var n in t || (t = {}))
|
|
6
|
+
C.call(t, n) && X(o, n, t[n]);
|
|
7
|
+
if (H)
|
|
8
|
+
for (var n of H(t))
|
|
9
|
+
D.call(t, n) && X(o, n, t[n]);
|
|
10
|
+
return o;
|
|
11
11
|
};
|
|
12
|
-
import { useEffect as
|
|
13
|
-
import { fabric as
|
|
14
|
-
import { TRANSPARENT_FILL as
|
|
15
|
-
const
|
|
16
|
-
canvas:
|
|
12
|
+
import { useEffect as O } from "react";
|
|
13
|
+
import { fabric as j } from "fabric";
|
|
14
|
+
import { TRANSPARENT_FILL as q, RECT_STROKE_COLOR as J, BASE_STROKE_WIDTH as Q, REGION_NAME_PREFIX as V } from "../../constants.mjs";
|
|
15
|
+
const a = ({
|
|
16
|
+
canvas: o,
|
|
17
17
|
sample: t,
|
|
18
|
-
image:
|
|
19
|
-
bgImagePosition:
|
|
20
|
-
canvasInitializedRef:
|
|
21
|
-
bgImagePositionRef:
|
|
18
|
+
image: n,
|
|
19
|
+
bgImagePosition: Y,
|
|
20
|
+
canvasInitializedRef: v,
|
|
21
|
+
bgImagePositionRef: m,
|
|
22
22
|
sampleRef: y,
|
|
23
|
-
labelsLoadedRef:
|
|
24
|
-
rectMapRef:
|
|
25
|
-
textLayersMapRef:
|
|
26
|
-
textLayoutContentMapRef:
|
|
27
|
-
regionNameTextMapRef:
|
|
28
|
-
ocrLoadingIconMapRef:
|
|
29
|
-
imageToCanvasCoords:
|
|
30
|
-
updateRegionShapeAndImage:
|
|
31
|
-
createDeleteControl:
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
labelsLoadedRef: E,
|
|
24
|
+
rectMapRef: u,
|
|
25
|
+
textLayersMapRef: _,
|
|
26
|
+
textLayoutContentMapRef: G,
|
|
27
|
+
regionNameTextMapRef: x,
|
|
28
|
+
ocrLoadingIconMapRef: F,
|
|
29
|
+
imageToCanvasCoords: A,
|
|
30
|
+
updateRegionShapeAndImage: k,
|
|
31
|
+
createDeleteControl: W,
|
|
32
|
+
createOCRControl: U,
|
|
33
|
+
updateRegionNameText: Z,
|
|
34
|
+
updateTextLayers: $,
|
|
35
|
+
setupBoundaryCheck: K,
|
|
36
|
+
cropRegionImage: N,
|
|
37
|
+
onChange: w
|
|
34
38
|
}) => {
|
|
35
|
-
|
|
36
|
-
if (!
|
|
39
|
+
O(() => {
|
|
40
|
+
if (!o || !(t != null && t.labels) || !n || !v.current || m.current.left === 0 && m.current.top === 0)
|
|
37
41
|
return;
|
|
38
|
-
y.current !== t ? (y.current = t,
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}),
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
}),
|
|
48
|
-
if (
|
|
42
|
+
y.current !== t ? (y.current = t, E.current = !1, u.current.forEach((i, s) => {
|
|
43
|
+
const f = _.current.get(s);
|
|
44
|
+
f && (f.forEach((e) => {
|
|
45
|
+
e.off("mousedown"), e.off("mouseover"), e.off("mouseout"), G.current.delete(e), o.remove(e);
|
|
46
|
+
}), _.current.delete(s));
|
|
47
|
+
const h = x.current.get(s);
|
|
48
|
+
h && (s.off("moved"), s.off("modified"), o.remove(h), x.current.delete(s));
|
|
49
|
+
const d = F.current.get(s);
|
|
50
|
+
d && (o.remove(d), F.current.delete(s)), o.remove(s);
|
|
51
|
+
}), u.current.clear(), t.labels.forEach((i, s) => {
|
|
52
|
+
if (i.shape.name !== "rect")
|
|
49
53
|
return;
|
|
50
|
-
const
|
|
51
|
-
left:
|
|
52
|
-
top:
|
|
53
|
-
width:
|
|
54
|
-
height:
|
|
55
|
-
fill:
|
|
54
|
+
const f = A(i.shape.x, i.shape.y), h = o.getZoom(), d = Q / h, e = new j.Rect({
|
|
55
|
+
left: f.x,
|
|
56
|
+
top: f.y,
|
|
57
|
+
width: i.shape.width,
|
|
58
|
+
height: i.shape.height,
|
|
59
|
+
fill: q,
|
|
56
60
|
// 无填充色
|
|
57
|
-
stroke:
|
|
58
|
-
strokeWidth:
|
|
61
|
+
stroke: J,
|
|
62
|
+
strokeWidth: d,
|
|
59
63
|
strokeUniform: !0,
|
|
60
64
|
// 边框宽度不受缩放影响
|
|
61
65
|
selectable: !0,
|
|
@@ -66,30 +70,42 @@ const z = ({
|
|
|
66
70
|
// 锁定旋转
|
|
67
71
|
lockUniScaling: !1,
|
|
68
72
|
// 允许非等比缩放,控制点跟随鼠标
|
|
73
|
+
lockScalingFlip: !0,
|
|
74
|
+
// 禁止缩放时翻转
|
|
69
75
|
objectCaching: !1,
|
|
70
76
|
// 禁用缓存,避免缩放时边框变虚
|
|
71
77
|
statefullCache: !1,
|
|
72
78
|
noScaleCache: !1
|
|
73
79
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}),
|
|
77
|
-
|
|
78
|
-
}),
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
e.on("modified", () => {
|
|
81
|
+
k(e);
|
|
82
|
+
}), e.on("moved", () => {
|
|
83
|
+
k(e);
|
|
84
|
+
}), o.add(e), K(e), e.controls.deleteControl = W(), e.controls.ocrControl = U();
|
|
85
|
+
const r = P({}, i);
|
|
86
|
+
r.name || (r.name = `${V}${s + 1}`), u.current.set(e, r), Z(e, r), r.textLayouts && r.textLayouts.length > 0 && $(e, r), r.image || N(r).then((c) => {
|
|
87
|
+
if (c) {
|
|
88
|
+
const l = u.current.get(e);
|
|
89
|
+
if (l && (l.image = c, w)) {
|
|
90
|
+
const S = Array.from(u.current.values());
|
|
91
|
+
w(S);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}).catch((c) => {
|
|
95
|
+
console.error("Failed to crop region image:", c);
|
|
96
|
+
});
|
|
97
|
+
}), E.current = !0, o.renderAll()) : !E.current && t.labels.length > 0 && (t.labels.forEach((i, s) => {
|
|
98
|
+
if (i.shape.name !== "rect" || Array.from(u.current.values()).find((l) => l.shape.x === i.shape.x && l.shape.y === i.shape.y && l.shape.width === i.shape.width && l.shape.height === i.shape.height))
|
|
83
99
|
return;
|
|
84
|
-
const
|
|
85
|
-
left:
|
|
86
|
-
top:
|
|
87
|
-
width:
|
|
88
|
-
height:
|
|
89
|
-
fill:
|
|
100
|
+
const h = A(i.shape.x, i.shape.y), d = o.getZoom(), e = Q / d, r = new j.Rect({
|
|
101
|
+
left: h.x,
|
|
102
|
+
top: h.y,
|
|
103
|
+
width: i.shape.width,
|
|
104
|
+
height: i.shape.height,
|
|
105
|
+
fill: q,
|
|
90
106
|
// 无填充色
|
|
91
|
-
stroke:
|
|
92
|
-
strokeWidth:
|
|
107
|
+
stroke: J,
|
|
108
|
+
strokeWidth: e,
|
|
93
109
|
strokeUniform: !0,
|
|
94
110
|
// 边框宽度不受缩放影响
|
|
95
111
|
selectable: !0,
|
|
@@ -100,42 +116,58 @@ const z = ({
|
|
|
100
116
|
// 锁定旋转
|
|
101
117
|
lockUniScaling: !1,
|
|
102
118
|
// 允许非等比缩放,控制点跟随鼠标
|
|
119
|
+
lockScalingFlip: !0,
|
|
120
|
+
// 禁止缩放时翻转
|
|
103
121
|
objectCaching: !1,
|
|
104
122
|
// 禁用缓存,避免缩放时边框变虚
|
|
105
123
|
statefullCache: !1,
|
|
106
124
|
noScaleCache: !1
|
|
107
125
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}),
|
|
111
|
-
|
|
112
|
-
}),
|
|
113
|
-
const c =
|
|
114
|
-
c.name || (c.name = `${
|
|
115
|
-
|
|
126
|
+
r.on("modified", () => {
|
|
127
|
+
k(r);
|
|
128
|
+
}), r.on("moved", () => {
|
|
129
|
+
k(r);
|
|
130
|
+
}), o.add(r), K(r), r.controls.deleteControl = W(), r.controls.ocrControl = U();
|
|
131
|
+
const c = P({}, i);
|
|
132
|
+
c.name || (c.name = `${V}${s + 1}`), u.current.set(r, c), Z(r, c), c.textLayouts && c.textLayouts.length > 0 && $(r, c), c.image || N(c).then((l) => {
|
|
133
|
+
if (l) {
|
|
134
|
+
const S = u.current.get(r);
|
|
135
|
+
if (S && (S.image = l, w)) {
|
|
136
|
+
const z = Array.from(u.current.values());
|
|
137
|
+
w(z);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}).catch((l) => {
|
|
141
|
+
console.error("Failed to crop region image:", l);
|
|
142
|
+
});
|
|
143
|
+
}), E.current = !0, o.renderAll());
|
|
116
144
|
}, [
|
|
117
|
-
|
|
145
|
+
o,
|
|
118
146
|
t,
|
|
119
147
|
t == null ? void 0 : t.labels,
|
|
120
|
-
|
|
121
|
-
|
|
148
|
+
n,
|
|
149
|
+
Y,
|
|
150
|
+
N,
|
|
151
|
+
w,
|
|
122
152
|
// 添加 bgImagePosition 作为依赖,确保在位置设置后触发加载
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
153
|
+
A,
|
|
154
|
+
k,
|
|
155
|
+
$,
|
|
156
|
+
Z,
|
|
126
157
|
W,
|
|
158
|
+
U,
|
|
159
|
+
v,
|
|
127
160
|
m,
|
|
128
|
-
$,
|
|
129
|
-
w,
|
|
130
161
|
y,
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
162
|
+
E,
|
|
163
|
+
u,
|
|
164
|
+
_,
|
|
165
|
+
G,
|
|
166
|
+
x,
|
|
167
|
+
F,
|
|
168
|
+
K
|
|
137
169
|
]);
|
|
138
170
|
};
|
|
139
171
|
export {
|
|
140
|
-
|
|
172
|
+
a as useRegionLoader
|
|
141
173
|
};
|