@glodon-aiot/dataset-annotation 3.10.0-alpha.21 → 3.10.0-alpha.23
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/Drawable.mjs +12 -12
- package/dist/es/components/DetectionAnnotation/components/LabelMaker/RectLabel.mjs +136 -108
- package/dist/es/components/DetectionAnnotation/components/LabelMaker/index.mjs +197 -162
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasDrag.mjs +75 -34
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDrawingMode.mjs +159 -131
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionSelection.mjs +59 -48
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/index.mjs +260 -241
- package/dist/es/index.mjs +1 -1
- package/dist/lib/index.js +3 -3
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasDrag.d.ts +2 -1
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDrawingMode.d.ts +2 -1
- package/package.json +2 -2
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var ge = (s,
|
|
6
|
-
for (var
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
for (var
|
|
10
|
-
We.call(
|
|
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
11
|
return s;
|
|
12
|
-
}, he = (s,
|
|
13
|
-
import { jsxs as Re, jsx as
|
|
14
|
-
import { useRef as
|
|
15
|
-
import { fabric as
|
|
16
|
-
import { useKeyPress as
|
|
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
17
|
import Oe from "classnames";
|
|
18
18
|
import "./style.less.mjs";
|
|
19
|
-
import
|
|
20
|
-
import { useOCRLoadingIcon as
|
|
21
|
-
import { useRegionNameText as
|
|
22
|
-
import { useCropRegionImage as
|
|
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
23
|
import { useDrawingMode as ze } from "./hooks/useDrawingMode.mjs";
|
|
24
24
|
import { useRegionLoader as He } from "./hooks/useRegionLoader.mjs";
|
|
25
25
|
import { useCanvasSetup as Ze } from "./hooks/useCanvasSetup.mjs";
|
|
@@ -36,42 +36,42 @@ import { canvasToImageCoords as tt, imageToCanvasCoords as ot } from "./utils/co
|
|
|
36
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
37
|
const Wt = ({
|
|
38
38
|
sample: s,
|
|
39
|
-
labelDefinitions:
|
|
40
|
-
labels:
|
|
39
|
+
labelDefinitions: l,
|
|
40
|
+
labels: u,
|
|
41
41
|
onImageLoad: pe,
|
|
42
|
-
onChange:
|
|
42
|
+
onChange: x,
|
|
43
43
|
onRegionSelect: J,
|
|
44
44
|
onRegionChange: H,
|
|
45
|
-
ocrRecognize:
|
|
46
|
-
activeLabelValue:
|
|
45
|
+
ocrRecognize: Te,
|
|
46
|
+
activeLabelValue: g,
|
|
47
47
|
onClearActive: Z,
|
|
48
48
|
selectedRegion: Q,
|
|
49
49
|
onAppendTextToActive: Ee,
|
|
50
50
|
readOnly: c
|
|
51
51
|
}) => {
|
|
52
52
|
var ue, me;
|
|
53
|
-
const V =
|
|
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({
|
|
54
54
|
left: 0,
|
|
55
55
|
top: 0
|
|
56
|
-
}),
|
|
56
|
+
}), F = R({
|
|
57
57
|
left: 0,
|
|
58
58
|
top: 0
|
|
59
|
-
}),
|
|
59
|
+
}), xe = R({
|
|
60
60
|
width: 0,
|
|
61
61
|
height: 0
|
|
62
|
-
}),
|
|
62
|
+
}), a = R(/* @__PURE__ */ new Map()), te = R(null), oe = R(void 0), re = R(!1), ne = R(!1), W = R({
|
|
63
63
|
width: 0,
|
|
64
64
|
height: 0
|
|
65
|
-
}), se =
|
|
66
|
-
updateOCRLoadingIcon:
|
|
67
|
-
ocrLoadingIconMapRef:
|
|
68
|
-
} =
|
|
69
|
-
updateRegionNameText:
|
|
65
|
+
}), se = R(!1), {
|
|
66
|
+
updateOCRLoadingIcon: ke,
|
|
67
|
+
ocrLoadingIconMapRef: k
|
|
68
|
+
} = be(t), {
|
|
69
|
+
updateRegionNameText: O,
|
|
70
70
|
regionNameTextMapRef: C
|
|
71
|
-
} =
|
|
72
|
-
|
|
71
|
+
} = Ye(t), ie = je(s == null ? void 0 : s.fileUrl), we = P((o) => {
|
|
72
|
+
t && (C.current.forEach((e, r) => {
|
|
73
73
|
const n = r.left || 0, i = r.top || 0;
|
|
74
|
-
|
|
74
|
+
e.set({
|
|
75
75
|
left: n,
|
|
76
76
|
// 与标注框左边对齐
|
|
77
77
|
top: i,
|
|
@@ -81,144 +81,144 @@ const Wt = ({
|
|
|
81
81
|
scaleY: 1 / o
|
|
82
82
|
// 反向缩放,抵消画布缩放
|
|
83
83
|
});
|
|
84
|
-
}),
|
|
85
|
-
}, [
|
|
86
|
-
updateCanvas:
|
|
84
|
+
}), t.renderAll());
|
|
85
|
+
}, [t]), {
|
|
86
|
+
updateCanvas: L
|
|
87
87
|
} = Ze({
|
|
88
88
|
sample: s,
|
|
89
|
-
image:
|
|
89
|
+
image: D,
|
|
90
90
|
onImageLoad: pe,
|
|
91
91
|
canvasRef: V,
|
|
92
|
-
containerRef:
|
|
92
|
+
containerRef: T,
|
|
93
93
|
canvasInitializedRef: re,
|
|
94
|
-
bgImagePositionRef:
|
|
95
|
-
bgImageSizeRef:
|
|
96
|
-
rectMapRef:
|
|
94
|
+
bgImagePositionRef: F,
|
|
95
|
+
bgImageSizeRef: xe,
|
|
96
|
+
rectMapRef: a,
|
|
97
97
|
updateTextLayersRef: te,
|
|
98
|
-
onRectPositionUpdated:
|
|
98
|
+
onRectPositionUpdated: we,
|
|
99
99
|
setCanvas: Ne,
|
|
100
100
|
setImage: Ie,
|
|
101
101
|
setScale: ee,
|
|
102
102
|
setBgImagePosition: Ae,
|
|
103
103
|
setLoading: Ce
|
|
104
|
-
}), Me =
|
|
105
|
-
const o = Array.from(
|
|
106
|
-
o.forEach((
|
|
107
|
-
|
|
108
|
-
}),
|
|
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
109
|
const n = C.current.get(r);
|
|
110
|
-
n && (n.set("text",
|
|
111
|
-
}),
|
|
112
|
-
}, [
|
|
110
|
+
n && (n.set("text", e.name || nt), t == null || t.renderAll());
|
|
111
|
+
}), x && x(o);
|
|
112
|
+
}, [x, t]), {
|
|
113
113
|
zoom: Se
|
|
114
114
|
} = Ve({
|
|
115
|
-
canvas:
|
|
115
|
+
canvas: t,
|
|
116
116
|
setScale: ee,
|
|
117
117
|
isZoomingRef: se
|
|
118
|
-
}),
|
|
119
|
-
(o,
|
|
120
|
-
[
|
|
118
|
+
}), y = P(
|
|
119
|
+
(o, e) => tt(o, e, t, D, F),
|
|
120
|
+
[t, D, K]
|
|
121
121
|
// 添加 bgImagePosition 作为依赖,确保在图片位置更新后函数能正确工作
|
|
122
|
-
), $ =
|
|
123
|
-
(o,
|
|
124
|
-
[
|
|
122
|
+
), $ = P(
|
|
123
|
+
(o, e) => ot(o, e, t, F),
|
|
124
|
+
[t, K]
|
|
125
125
|
// 添加 bgImagePosition 作为依赖,确保在图片位置更新后函数能正确工作
|
|
126
126
|
), {
|
|
127
|
-
updateTextLayers:
|
|
128
|
-
textLayersMapRef:
|
|
127
|
+
updateTextLayers: b,
|
|
128
|
+
textLayersMapRef: m,
|
|
129
129
|
textLayoutContentMapRef: Y
|
|
130
130
|
} = Ke({
|
|
131
|
-
canvas:
|
|
131
|
+
canvas: t,
|
|
132
132
|
imageToCanvasCoords: $,
|
|
133
|
-
activeLabelValue:
|
|
133
|
+
activeLabelValue: g,
|
|
134
134
|
onAppendTextToActive: Ee
|
|
135
135
|
});
|
|
136
|
-
te.current =
|
|
136
|
+
te.current = b;
|
|
137
137
|
const {
|
|
138
138
|
performOCRIfNeeded: ce,
|
|
139
139
|
ocrRecognizingRef: ut
|
|
140
140
|
} = qe({
|
|
141
|
-
ocrRecognize:
|
|
142
|
-
onChange:
|
|
143
|
-
updateTextLayers:
|
|
144
|
-
canvas:
|
|
145
|
-
updateOCRLoadingIcon:
|
|
146
|
-
rectMapRef:
|
|
147
|
-
textLayersMapRef:
|
|
141
|
+
ocrRecognize: Te,
|
|
142
|
+
onChange: x,
|
|
143
|
+
updateTextLayers: b,
|
|
144
|
+
canvas: t,
|
|
145
|
+
updateOCRLoadingIcon: ke,
|
|
146
|
+
rectMapRef: a,
|
|
147
|
+
textLayersMapRef: m,
|
|
148
148
|
textLayoutContentMapRef: Y
|
|
149
149
|
}), {
|
|
150
150
|
updateRegionShapeAndImage: ae
|
|
151
151
|
} = $e({
|
|
152
|
-
canvas:
|
|
153
|
-
image:
|
|
154
|
-
draggable:
|
|
155
|
-
canvasToImageCoords:
|
|
152
|
+
canvas: t,
|
|
153
|
+
image: D,
|
|
154
|
+
draggable: E,
|
|
155
|
+
canvasToImageCoords: y,
|
|
156
156
|
imageToCanvasCoords: $,
|
|
157
157
|
cropRegionImage: ie,
|
|
158
|
-
onChange:
|
|
158
|
+
onChange: x,
|
|
159
159
|
onRegionChange: H,
|
|
160
160
|
performOCRIfNeeded: ce,
|
|
161
|
-
updateTextLayers:
|
|
162
|
-
rectMapRef:
|
|
161
|
+
updateTextLayers: b,
|
|
162
|
+
rectMapRef: a,
|
|
163
163
|
regionNameTextMapRef: C,
|
|
164
|
-
ocrLoadingIconMapRef:
|
|
164
|
+
ocrLoadingIconMapRef: k
|
|
165
165
|
});
|
|
166
166
|
h(() => {
|
|
167
|
-
|
|
168
|
-
}, [
|
|
169
|
-
|
|
170
|
-
o.forEach((
|
|
171
|
-
|
|
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);
|
|
172
172
|
});
|
|
173
|
-
}),
|
|
174
|
-
|
|
175
|
-
}), C.current.clear(),
|
|
176
|
-
|
|
177
|
-
}),
|
|
178
|
-
|
|
179
|
-
}),
|
|
180
|
-
}, [
|
|
181
|
-
if (!
|
|
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)
|
|
182
182
|
return;
|
|
183
|
-
|
|
184
|
-
width:
|
|
185
|
-
height:
|
|
183
|
+
W.current = {
|
|
184
|
+
width: T.current.offsetWidth,
|
|
185
|
+
height: T.current.offsetHeight
|
|
186
186
|
};
|
|
187
187
|
const o = new ResizeObserver(() => {
|
|
188
|
-
if (!
|
|
188
|
+
if (!T.current || se.current)
|
|
189
189
|
return;
|
|
190
|
-
if (
|
|
191
|
-
const d =
|
|
192
|
-
if (Math.abs(d -
|
|
190
|
+
if (t) {
|
|
191
|
+
const d = t.getZoom();
|
|
192
|
+
if (Math.abs(d - p) > st)
|
|
193
193
|
return;
|
|
194
194
|
}
|
|
195
|
-
const
|
|
196
|
-
(
|
|
197
|
-
width:
|
|
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,
|
|
198
198
|
height: r
|
|
199
|
-
},
|
|
199
|
+
}, L());
|
|
200
200
|
});
|
|
201
|
-
return o.observe(
|
|
201
|
+
return o.observe(T.current), () => {
|
|
202
202
|
o.disconnect();
|
|
203
203
|
};
|
|
204
|
-
}, [
|
|
205
|
-
c || (
|
|
204
|
+
}, [L, t, p]), X("ctrl", () => {
|
|
205
|
+
c || (v && (I(!1), w()), _(!0));
|
|
206
206
|
}, {
|
|
207
207
|
events: ["keydown"]
|
|
208
|
-
}),
|
|
209
|
-
c ||
|
|
208
|
+
}), X("ctrl", () => {
|
|
209
|
+
c || _(!1);
|
|
210
210
|
}, {
|
|
211
211
|
events: ["keyup"]
|
|
212
212
|
}), h(() => {
|
|
213
|
-
if (!
|
|
213
|
+
if (!t)
|
|
214
214
|
return;
|
|
215
|
-
const o = ft /
|
|
216
|
-
|
|
215
|
+
const o = ft / p, e = /* @__PURE__ */ new Set();
|
|
216
|
+
m.current.forEach((r) => {
|
|
217
217
|
r.forEach((n) => {
|
|
218
|
-
|
|
218
|
+
e.add(n);
|
|
219
219
|
});
|
|
220
|
-
}),
|
|
221
|
-
r instanceof
|
|
220
|
+
}), t.getObjects().forEach((r) => {
|
|
221
|
+
r instanceof U.Rect && !e.has(r) && r.set({
|
|
222
222
|
strokeWidth: o,
|
|
223
223
|
strokeUniform: !0,
|
|
224
224
|
objectCaching: !1,
|
|
@@ -226,7 +226,7 @@ const Wt = ({
|
|
|
226
226
|
statefullCache: !1,
|
|
227
227
|
noScaleCache: !1
|
|
228
228
|
});
|
|
229
|
-
}),
|
|
229
|
+
}), m.current.forEach((r) => {
|
|
230
230
|
r.forEach((n) => {
|
|
231
231
|
n.set({
|
|
232
232
|
fill: it,
|
|
@@ -249,86 +249,90 @@ const Wt = ({
|
|
|
249
249
|
// 与标注框左边对齐
|
|
250
250
|
top: d,
|
|
251
251
|
// 下边缘与标注框上边缘对齐(因为 originY 是 'bottom')
|
|
252
|
-
scaleX: 1 /
|
|
252
|
+
scaleX: 1 / p,
|
|
253
253
|
// 反向缩放,抵消画布缩放
|
|
254
|
-
scaleY: 1 /
|
|
254
|
+
scaleY: 1 / p
|
|
255
255
|
// 反向缩放,抵消画布缩放
|
|
256
256
|
});
|
|
257
|
-
const
|
|
258
|
-
if (
|
|
257
|
+
const f = k.current.get(n);
|
|
258
|
+
if (f) {
|
|
259
259
|
const N = n.getScaledWidth();
|
|
260
|
-
n.getScaledHeight(),
|
|
260
|
+
n.getScaledHeight(), f.set({
|
|
261
261
|
left: i,
|
|
262
262
|
// top 位置由动画控制,这里不更新
|
|
263
|
-
scaleX: 1 /
|
|
263
|
+
scaleX: 1 / p,
|
|
264
264
|
// 反向缩放,抵消画布缩放,保持固定视觉粗细
|
|
265
|
-
scaleY: 1 /
|
|
265
|
+
scaleY: 1 / p
|
|
266
266
|
// 反向缩放,抵消画布缩放,保持固定视觉粗细
|
|
267
267
|
});
|
|
268
|
-
const
|
|
269
|
-
if (
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
z instanceof
|
|
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);
|
|
273
273
|
});
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
|
-
}),
|
|
277
|
-
}, [
|
|
278
|
-
canvas:
|
|
279
|
-
draggable:
|
|
280
|
-
drawingMode:
|
|
276
|
+
}), t.renderAll();
|
|
277
|
+
}, [t, p]), Be({
|
|
278
|
+
canvas: t,
|
|
279
|
+
draggable: E,
|
|
280
|
+
drawingMode: v,
|
|
281
|
+
textLayersMapRef: m
|
|
281
282
|
});
|
|
282
283
|
const {
|
|
283
284
|
performDelete: B
|
|
284
285
|
} = Je({
|
|
285
|
-
canvas:
|
|
286
|
+
canvas: t,
|
|
286
287
|
onRegionChange: H,
|
|
287
288
|
updateRegionNames: Me,
|
|
288
|
-
rectMapRef:
|
|
289
|
-
textLayersMapRef:
|
|
289
|
+
rectMapRef: a,
|
|
290
|
+
textLayersMapRef: m,
|
|
290
291
|
textLayoutContentMapRef: Y,
|
|
291
292
|
regionNameTextMapRef: C,
|
|
292
|
-
ocrLoadingIconMapRef:
|
|
293
|
+
ocrLoadingIconMapRef: k
|
|
293
294
|
}), {
|
|
294
295
|
createDeleteControl: G
|
|
295
296
|
} = Qe({
|
|
296
297
|
performDelete: B
|
|
297
298
|
});
|
|
298
299
|
Ge({
|
|
299
|
-
canvas:
|
|
300
|
+
canvas: t,
|
|
300
301
|
onRegionSelect: J,
|
|
301
302
|
createDeleteControl: G,
|
|
302
|
-
textLayersMapRef:
|
|
303
|
-
rectMapRef:
|
|
303
|
+
textLayersMapRef: m,
|
|
304
|
+
rectMapRef: a
|
|
304
305
|
});
|
|
305
306
|
const {
|
|
306
|
-
stopDraw:
|
|
307
|
+
stopDraw: w
|
|
307
308
|
} = ze({
|
|
308
|
-
canvas:
|
|
309
|
-
drawingMode:
|
|
310
|
-
draggable:
|
|
311
|
-
setDrawingMode:
|
|
312
|
-
canvasToImageCoords:
|
|
313
|
-
labelDefinitions:
|
|
314
|
-
onChange:
|
|
309
|
+
canvas: t,
|
|
310
|
+
drawingMode: v,
|
|
311
|
+
draggable: E,
|
|
312
|
+
setDrawingMode: I,
|
|
313
|
+
canvasToImageCoords: y,
|
|
314
|
+
labelDefinitions: l,
|
|
315
|
+
onChange: x,
|
|
315
316
|
cropRegionImage: ie,
|
|
316
317
|
updateRegionShapeAndImage: ae,
|
|
317
318
|
performOCRIfNeeded: ce,
|
|
318
319
|
createDeleteControl: G,
|
|
319
|
-
updateRegionNameText:
|
|
320
|
+
updateRegionNameText: O,
|
|
320
321
|
onRegionChange: H,
|
|
321
322
|
onRegionSelect: J,
|
|
322
|
-
rectMapRef:
|
|
323
|
+
rectMapRef: a,
|
|
324
|
+
textLayersMapRef: m
|
|
323
325
|
});
|
|
324
326
|
h(() => {
|
|
325
|
-
|
|
326
|
-
}, [
|
|
327
|
-
|
|
327
|
+
g && (I(!1), w());
|
|
328
|
+
}, [g, w]), h(() => {
|
|
329
|
+
c && (_(!0), I(!1), w());
|
|
330
|
+
}, [c, w]), h(() => {
|
|
331
|
+
if (!t)
|
|
328
332
|
return;
|
|
329
333
|
const o = () => {
|
|
330
|
-
|
|
331
|
-
|
|
334
|
+
t.getObjects().forEach((e) => {
|
|
335
|
+
e instanceof U.Rect && e.selectable && (e.set({
|
|
332
336
|
lockMovementX: c,
|
|
333
337
|
lockMovementY: c,
|
|
334
338
|
lockScalingX: c,
|
|
@@ -336,125 +340,140 @@ const Wt = ({
|
|
|
336
340
|
hasControls: !c
|
|
337
341
|
// 在只读模式下,如果有 activeLabelValue,我们可能希望它保持选中状态
|
|
338
342
|
// 但不允许用户通过点击来取消选中或选中其他(这个由 canvas.selection 控制)
|
|
339
|
-
}), c &&
|
|
340
|
-
}),
|
|
343
|
+
}), c && e.controls);
|
|
344
|
+
}), t.requestRenderAll();
|
|
341
345
|
};
|
|
342
|
-
return o(),
|
|
343
|
-
|
|
346
|
+
return o(), t.on("object:added", o), () => {
|
|
347
|
+
t.off("object:added", o);
|
|
344
348
|
};
|
|
345
|
-
}, [
|
|
346
|
-
canvas:
|
|
349
|
+
}, [t, c]), He({
|
|
350
|
+
canvas: t,
|
|
347
351
|
sample: s,
|
|
348
|
-
image:
|
|
352
|
+
image: D,
|
|
349
353
|
bgImagePosition: K,
|
|
350
354
|
canvasInitializedRef: re,
|
|
351
|
-
bgImagePositionRef:
|
|
355
|
+
bgImagePositionRef: F,
|
|
352
356
|
sampleRef: oe,
|
|
353
357
|
labelsLoadedRef: ne,
|
|
354
|
-
rectMapRef:
|
|
355
|
-
textLayersMapRef:
|
|
358
|
+
rectMapRef: a,
|
|
359
|
+
textLayersMapRef: m,
|
|
356
360
|
textLayoutContentMapRef: Y,
|
|
357
361
|
regionNameTextMapRef: C,
|
|
358
|
-
ocrLoadingIconMapRef:
|
|
362
|
+
ocrLoadingIconMapRef: k,
|
|
359
363
|
imageToCanvasCoords: $,
|
|
360
364
|
updateRegionShapeAndImage: ae,
|
|
361
365
|
createDeleteControl: G,
|
|
362
|
-
updateRegionNameText:
|
|
363
|
-
updateTextLayers:
|
|
366
|
+
updateRegionNameText: O,
|
|
367
|
+
updateTextLayers: b
|
|
364
368
|
}), h(() => {
|
|
365
|
-
if (!
|
|
369
|
+
if (!u || u.length === 0)
|
|
366
370
|
return;
|
|
367
371
|
let o = !1;
|
|
368
|
-
|
|
369
|
-
var d,
|
|
370
|
-
const n =
|
|
372
|
+
a.current.forEach((e, r) => {
|
|
373
|
+
var d, f;
|
|
374
|
+
const n = u.find((N) => N.id === e.id);
|
|
371
375
|
if (!n)
|
|
372
376
|
return;
|
|
373
|
-
const i = he(q(q({},
|
|
377
|
+
const i = he(q(q({}, e), n), {
|
|
374
378
|
// Keep shape from canvas to avoid desync
|
|
375
|
-
shape:
|
|
376
|
-
image: (d = n.image) != null ? d :
|
|
377
|
-
textLayouts: (
|
|
379
|
+
shape: e.shape,
|
|
380
|
+
image: (d = n.image) != null ? d : e.image,
|
|
381
|
+
textLayouts: (f = n.textLayouts) != null ? f : e.textLayouts
|
|
378
382
|
});
|
|
379
|
-
(i.name !==
|
|
380
|
-
}), o && (
|
|
381
|
-
}, [
|
|
382
|
-
canvas:
|
|
383
|
-
drawingMode:
|
|
384
|
-
draggable:
|
|
385
|
-
textLayersMapRef:
|
|
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
|
|
386
390
|
}), h(() => {
|
|
387
|
-
if (
|
|
391
|
+
if (t && Q === null) {
|
|
388
392
|
const o = /* @__PURE__ */ new Set();
|
|
389
|
-
|
|
393
|
+
m.current.forEach((r) => {
|
|
390
394
|
r.forEach((n) => {
|
|
391
395
|
o.add(n);
|
|
392
396
|
});
|
|
393
|
-
}),
|
|
394
|
-
r instanceof
|
|
397
|
+
}), t.getObjects().forEach((r) => {
|
|
398
|
+
r instanceof U.Rect && !o.has(r) && r.set({
|
|
395
399
|
fill: at
|
|
396
400
|
// 移除填充色
|
|
397
401
|
});
|
|
398
|
-
}),
|
|
402
|
+
}), t.getActiveObject() && (t.discardActiveObject(), t.renderAll());
|
|
399
403
|
}
|
|
400
|
-
}, [
|
|
404
|
+
}, [t, Q]), h(() => {
|
|
401
405
|
var r;
|
|
402
|
-
if (!
|
|
406
|
+
if (!t)
|
|
403
407
|
return;
|
|
404
|
-
const o = (r =
|
|
405
|
-
let
|
|
406
|
-
|
|
407
|
-
const d =
|
|
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);
|
|
408
412
|
if (d && n.length > 0) {
|
|
409
|
-
const
|
|
413
|
+
const f = o === d.id;
|
|
410
414
|
n.forEach((N) => {
|
|
411
|
-
N.visible !==
|
|
412
|
-
visible:
|
|
413
|
-
}),
|
|
415
|
+
N.visible !== f && (N.set({
|
|
416
|
+
visible: f
|
|
417
|
+
}), e = !0);
|
|
414
418
|
});
|
|
415
419
|
}
|
|
416
|
-
}),
|
|
417
|
-
}, [
|
|
418
|
-
|
|
420
|
+
}), e && t.renderAll();
|
|
421
|
+
}, [t, g]), h(() => {
|
|
422
|
+
var n, i;
|
|
423
|
+
if (!t)
|
|
419
424
|
return;
|
|
420
|
-
const o = (
|
|
421
|
-
|
|
422
|
-
|
|
425
|
+
const o = (n = g == null ? void 0 : g.region) == null ? void 0 : n.id;
|
|
426
|
+
if (!o)
|
|
427
|
+
return;
|
|
428
|
+
let e = null;
|
|
429
|
+
if (a.current.forEach((d, f) => {
|
|
430
|
+
d.id === o && (e = f);
|
|
431
|
+
}), !e)
|
|
432
|
+
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)
|
|
438
|
+
return;
|
|
439
|
+
const o = (e) => {
|
|
440
|
+
var de;
|
|
441
|
+
const r = (de = e.e) == null ? void 0 : de.target;
|
|
423
442
|
if ((r == null ? void 0 : r.tagName) === "INPUT" || (r == null ? void 0 : r.tagName) === "TEXTAREA")
|
|
424
443
|
return;
|
|
425
|
-
const n =
|
|
426
|
-
x,
|
|
427
|
-
y,
|
|
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,
|
|
428
447
|
width: z,
|
|
429
|
-
height:
|
|
448
|
+
height: Le
|
|
430
449
|
} = N.shape;
|
|
431
|
-
|
|
450
|
+
f.x >= M && f.x <= M + z && f.y >= j && f.y <= j + Le || Z();
|
|
432
451
|
};
|
|
433
|
-
return
|
|
434
|
-
|
|
452
|
+
return t.on("mouse:down", o), () => {
|
|
453
|
+
t.off("mouse:down", o);
|
|
435
454
|
};
|
|
436
|
-
}, [
|
|
437
|
-
const fe =
|
|
438
|
-
const
|
|
439
|
-
if ((
|
|
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)
|
|
440
459
|
return;
|
|
441
|
-
const r =
|
|
442
|
-
!r || !(r instanceof
|
|
443
|
-
}, [
|
|
444
|
-
|
|
445
|
-
const
|
|
446
|
-
(
|
|
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);
|
|
447
466
|
}, {
|
|
448
467
|
exactMatch: !1
|
|
449
468
|
// 允许大小写
|
|
450
469
|
});
|
|
451
|
-
const
|
|
452
|
-
c || (
|
|
453
|
-
},
|
|
454
|
-
c || (
|
|
470
|
+
const De = () => {
|
|
471
|
+
c || (v && (I(!1), w()), _(!E));
|
|
472
|
+
}, _e = () => {
|
|
473
|
+
c || (E && _(!1), I(!v));
|
|
455
474
|
};
|
|
456
475
|
return h(() => () => {
|
|
457
|
-
|
|
476
|
+
t && t.dispose();
|
|
458
477
|
}, []), /* @__PURE__ */ Re("div", {
|
|
459
478
|
style: {
|
|
460
479
|
width: "100%",
|
|
@@ -462,28 +481,28 @@ const Wt = ({
|
|
|
462
481
|
display: "flex",
|
|
463
482
|
position: "relative"
|
|
464
483
|
},
|
|
465
|
-
children: [
|
|
484
|
+
children: [ve && /* @__PURE__ */ S("div", {
|
|
466
485
|
className: "vlm-loading-overlay",
|
|
467
|
-
children: /* @__PURE__ */
|
|
486
|
+
children: /* @__PURE__ */ S("div", {
|
|
468
487
|
className: "vlm-loading-spinner"
|
|
469
488
|
})
|
|
470
|
-
}), /* @__PURE__ */
|
|
489
|
+
}), /* @__PURE__ */ S("div", {
|
|
471
490
|
className: "vlm-marker-toolbar",
|
|
472
|
-
children: /* @__PURE__ */
|
|
473
|
-
drawingMode:
|
|
474
|
-
draggable:
|
|
475
|
-
scale:
|
|
476
|
-
onToggleDrawingMode:
|
|
477
|
-
onToggleDrag:
|
|
491
|
+
children: /* @__PURE__ */ S(ye, {
|
|
492
|
+
drawingMode: v,
|
|
493
|
+
draggable: E,
|
|
494
|
+
scale: p,
|
|
495
|
+
onToggleDrawingMode: _e,
|
|
496
|
+
onToggleDrag: De,
|
|
478
497
|
onZoom: Se,
|
|
479
|
-
onFitToScreen:
|
|
498
|
+
onFitToScreen: L,
|
|
480
499
|
readOnly: c
|
|
481
500
|
})
|
|
482
501
|
}), /* @__PURE__ */ Re("div", {
|
|
483
|
-
ref:
|
|
502
|
+
ref: T,
|
|
484
503
|
className: Oe({
|
|
485
504
|
"vlm-label-maker-wrap": !0,
|
|
486
|
-
draggable:
|
|
505
|
+
draggable: E
|
|
487
506
|
}),
|
|
488
507
|
onContextMenu: (o) => {
|
|
489
508
|
o.preventDefault();
|
|
@@ -492,10 +511,10 @@ const Wt = ({
|
|
|
492
511
|
flex: 1,
|
|
493
512
|
position: "relative"
|
|
494
513
|
},
|
|
495
|
-
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__ */
|
|
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", {
|
|
496
515
|
className: "vlm-image-name",
|
|
497
516
|
children: s.sampleFileName.originalName || s.sampleFileName.name
|
|
498
|
-
}), /* @__PURE__ */
|
|
517
|
+
}), /* @__PURE__ */ S("canvas", {
|
|
499
518
|
className: "vlm-label-maker-canvas",
|
|
500
519
|
ref: V
|
|
501
520
|
})]
|