@glodon-aiot/dataset-annotation 3.14.0-alpha.31 → 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.
- package/dist/es/components/VLMAnnotation/RegionItem.mjs +1 -1
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useAIButtonHover.mjs +193 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasDrag.mjs +18 -18
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDrawingMode.mjs +345 -238
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionSelection.mjs +158 -56
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/index.mjs +424 -397
- package/dist/es/components/VLMAnnotation/components/AIErrorTooltip/AIErrorTooltip.less.mjs +4 -0
- package/dist/es/components/VLMAnnotation/components/AIErrorTooltip/index.mjs +24 -0
- package/dist/es/components/VLMAnnotation/components/ZoomControls.mjs +1 -1
- package/dist/es/components/VLMAnnotation/constants.mjs +1 -1
- package/dist/es/index.mjs +1 -1
- package/dist/lib/index.js +4 -4
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useAIButtonHover.d.ts +16 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDrawingMode.d.ts +2 -1
- package/dist/src/components/VLMAnnotation/components/AIErrorTooltip/index.d.ts +8 -0
- package/dist/src/components/VLMAnnotation/constants.d.ts +2 -2
- package/package.json +2 -2
|
@@ -1,57 +1,58 @@
|
|
|
1
|
-
import { useCallback as
|
|
2
|
-
import { fabric as
|
|
3
|
-
import { CROSSHAIR_LINE_COLOR as
|
|
4
|
-
const
|
|
1
|
+
import { useCallback as Ae, useRef as ne, useEffect as se } from "react";
|
|
2
|
+
import { fabric as T } from "fabric";
|
|
3
|
+
import { CROSSHAIR_LINE_COLOR as Ye, CROSSHAIR_LINE_DASH_ARRAY as Ce, CROSSHAIR_LINE_WIDTH as Xe, TEMP_RECT_FILL_COLOR as Se, RECT_STROKE_COLOR as ie, TEMP_RECT_STROKE_DASH_ARRAY as je, TRANSPARENT_FILL as Be, REGION_NAME_PREFIX as Ue, BASE_STROKE_WIDTH as le } from "../../constants.mjs";
|
|
4
|
+
const Ge = ({
|
|
5
5
|
canvas: e,
|
|
6
|
-
drawingMode:
|
|
7
|
-
draggable:
|
|
8
|
-
setDrawingMode:
|
|
9
|
-
canvasToImageCoords:
|
|
10
|
-
labelDefinitions:
|
|
11
|
-
onChange:
|
|
12
|
-
cropRegionImage:
|
|
13
|
-
updateRegionShapeAndImage:
|
|
14
|
-
performOCRIfNeeded:
|
|
15
|
-
createDeleteControl:
|
|
16
|
-
createOCRControl:
|
|
17
|
-
updateRegionNameText:
|
|
18
|
-
onRegionChange:
|
|
19
|
-
onRegionSelect:
|
|
20
|
-
rectMapRef:
|
|
21
|
-
textLayersMapRef:
|
|
22
|
-
|
|
6
|
+
drawingMode: y,
|
|
7
|
+
draggable: ce,
|
|
8
|
+
setDrawingMode: de,
|
|
9
|
+
canvasToImageCoords: ue,
|
|
10
|
+
labelDefinitions: J,
|
|
11
|
+
onChange: I,
|
|
12
|
+
cropRegionImage: fe,
|
|
13
|
+
updateRegionShapeAndImage: D,
|
|
14
|
+
performOCRIfNeeded: he,
|
|
15
|
+
createDeleteControl: me,
|
|
16
|
+
createOCRControl: ge,
|
|
17
|
+
updateRegionNameText: be,
|
|
18
|
+
onRegionChange: Q,
|
|
19
|
+
onRegionSelect: P,
|
|
20
|
+
rectMapRef: x,
|
|
21
|
+
textLayersMapRef: ke,
|
|
22
|
+
regionNameTextMapRef: v,
|
|
23
|
+
setupBoundaryCheck: pe
|
|
23
24
|
}) => {
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const V = Ae(() => {
|
|
26
|
+
const L = /* @__PURE__ */ new Set();
|
|
27
|
+
return ke.current.forEach((w) => {
|
|
28
|
+
w.forEach((z) => {
|
|
29
|
+
L.add(z);
|
|
29
30
|
});
|
|
30
|
-
}),
|
|
31
|
-
}, [
|
|
31
|
+
}), L;
|
|
32
|
+
}, [ke]), i = ne({
|
|
32
33
|
horizontal: null,
|
|
33
34
|
vertical: null
|
|
34
|
-
}),
|
|
35
|
+
}), N = ne(null), Oe = ne({
|
|
35
36
|
dleft: -1,
|
|
36
37
|
dtop: -1,
|
|
37
38
|
dw: 0,
|
|
38
39
|
dh: 0,
|
|
39
40
|
rect: null
|
|
40
|
-
}),
|
|
41
|
+
}), G = Ae(() => {
|
|
41
42
|
e && (e.skipTargetFind = !1);
|
|
42
43
|
}, [e]);
|
|
43
|
-
return
|
|
44
|
-
if (!e || !
|
|
45
|
-
if (
|
|
46
|
-
|
|
44
|
+
return se(() => {
|
|
45
|
+
if (!e || !y || ce) {
|
|
46
|
+
if (G(), e && !y) {
|
|
47
|
+
i.current.horizontal && e.getObjects().includes(i.current.horizontal) && e.remove(i.current.horizontal), i.current.vertical && e.getObjects().includes(i.current.vertical) && e.remove(i.current.vertical), i.current = {
|
|
47
48
|
horizontal: null,
|
|
48
49
|
vertical: null
|
|
49
50
|
};
|
|
50
51
|
const o = e.getActiveObject();
|
|
51
52
|
e.selection = !1, e.skipTargetFind = !1;
|
|
52
|
-
const r =
|
|
53
|
-
e.getObjects().forEach((
|
|
54
|
-
|
|
53
|
+
const s = V(), r = new Set(v.current.values());
|
|
54
|
+
e.getObjects().forEach((n) => {
|
|
55
|
+
n instanceof T.Rect && s.has(n) ? n.set({
|
|
55
56
|
evented: !0,
|
|
56
57
|
selectable: !1,
|
|
57
58
|
lockMovementX: !0,
|
|
@@ -59,131 +60,198 @@ const Te = ({
|
|
|
59
60
|
lockScalingX: !0,
|
|
60
61
|
lockScalingY: !0,
|
|
61
62
|
lockRotation: !0
|
|
62
|
-
}) :
|
|
63
|
-
|
|
63
|
+
}) : r.has(n) ? n.set({
|
|
64
|
+
evented: !1,
|
|
65
|
+
selectable: !1,
|
|
66
|
+
lockMovementX: !0,
|
|
67
|
+
lockMovementY: !0,
|
|
68
|
+
lockScalingX: !1,
|
|
69
|
+
// 允许缩放,用于抵消画布缩放
|
|
70
|
+
lockScalingY: !1,
|
|
71
|
+
// 允许缩放,用于抵消画布缩放
|
|
72
|
+
lockRotation: !0,
|
|
73
|
+
hasControls: !1,
|
|
74
|
+
hasBorders: !1
|
|
75
|
+
}) : (n.set("evented", !0), n.set("selectable", !0), n instanceof T.Rect && n.set("hasControls", !0));
|
|
76
|
+
}), o && e.getObjects().includes(o) && (e.setActiveObject(o), e.renderAll()), e.defaultCursor = "default";
|
|
64
77
|
}
|
|
65
78
|
return;
|
|
66
79
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
80
|
+
G(), e.selection = !1, e.skipTargetFind = !0, e.getActiveObject() && (e.discardActiveObject(), e.renderAll());
|
|
81
|
+
const w = new Set(v.current.values());
|
|
82
|
+
e.getObjects().forEach((o) => {
|
|
83
|
+
w.has(o) ? o.set({
|
|
84
|
+
evented: !1,
|
|
85
|
+
selectable: !1,
|
|
86
|
+
lockMovementX: !0,
|
|
87
|
+
lockMovementY: !0,
|
|
88
|
+
lockScalingX: !1,
|
|
89
|
+
// 允许缩放,用于抵消画布缩放
|
|
90
|
+
lockScalingY: !1,
|
|
91
|
+
// 允许缩放,用于抵消画布缩放
|
|
92
|
+
lockRotation: !0,
|
|
93
|
+
hasControls: !1,
|
|
94
|
+
hasBorders: !1
|
|
95
|
+
}) : (o.set("evented", !1), o.set("selectable", !1), o instanceof T.Rect && o.hasControls && o.set("hasControls", !1));
|
|
96
|
+
}), e.defaultCursor = "crosshair", e.setCursor("crosshair"), i.current.horizontal && e.getObjects().includes(i.current.horizontal) && e.remove(i.current.horizontal), i.current.vertical && e.getObjects().includes(i.current.vertical) && e.remove(i.current.vertical), i.current = {
|
|
70
97
|
horizontal: null,
|
|
71
98
|
vertical: null
|
|
72
99
|
};
|
|
73
|
-
const
|
|
74
|
-
stroke:
|
|
75
|
-
strokeWidth:
|
|
76
|
-
strokeDashArray:
|
|
100
|
+
const z = e.getWidth(), S = e.getHeight(), E = e.getZoom(), j = z / E, $ = S / E, _ = Math.max(j, $) * 3, K = Xe / E, F = new T.Line([-_, 0, _, 0], {
|
|
101
|
+
stroke: Ye,
|
|
102
|
+
strokeWidth: K,
|
|
103
|
+
strokeDashArray: Ce,
|
|
77
104
|
selectable: !1,
|
|
78
105
|
evented: !1,
|
|
79
106
|
excludeFromExport: !0,
|
|
80
107
|
// 导出时不包含此线
|
|
81
108
|
strokeUniform: !0,
|
|
82
109
|
// 设置为 true,使线宽随缩放调整以保持视觉一致
|
|
83
|
-
visible: !
|
|
84
|
-
//
|
|
85
|
-
}),
|
|
86
|
-
stroke:
|
|
87
|
-
strokeWidth:
|
|
88
|
-
strokeDashArray:
|
|
110
|
+
visible: !0
|
|
111
|
+
// 画框模式下常显辅助线
|
|
112
|
+
}), Z = new T.Line([0, -_, 0, _], {
|
|
113
|
+
stroke: Ye,
|
|
114
|
+
strokeWidth: K,
|
|
115
|
+
strokeDashArray: Ce,
|
|
89
116
|
selectable: !1,
|
|
90
117
|
evented: !1,
|
|
91
118
|
excludeFromExport: !0,
|
|
92
119
|
// 导出时不包含此线
|
|
93
120
|
strokeUniform: !0,
|
|
94
121
|
// 设置为 true,使线宽随缩放调整以保持视觉一致
|
|
95
|
-
visible: !
|
|
96
|
-
//
|
|
122
|
+
visible: !0
|
|
123
|
+
// 画框模式下常显辅助线
|
|
97
124
|
});
|
|
98
|
-
|
|
99
|
-
horizontal:
|
|
100
|
-
vertical:
|
|
101
|
-
}, e.add(
|
|
102
|
-
const
|
|
103
|
-
const
|
|
104
|
-
if (!
|
|
125
|
+
i.current = {
|
|
126
|
+
horizontal: F,
|
|
127
|
+
vertical: Z
|
|
128
|
+
}, e.add(F), e.add(Z), F.sendToBack(), Z.sendToBack();
|
|
129
|
+
const R = (o, s) => {
|
|
130
|
+
const r = i.current.horizontal, n = i.current.vertical;
|
|
131
|
+
if (!r || !n)
|
|
105
132
|
return;
|
|
106
|
-
const u = e.getZoom(),
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
133
|
+
const u = e.getZoom(), b = e.getWidth(), l = e.getHeight(), h = b / u, f = l / u, m = e.viewportTransform || [1, 0, 0, 1, 0, 0];
|
|
134
|
+
m[4] / u, m[5] / u;
|
|
135
|
+
const k = e.backgroundImage;
|
|
136
|
+
let g = h, p = f;
|
|
137
|
+
if (k) {
|
|
138
|
+
const a = k.getElement();
|
|
139
|
+
if (a != null && a.width && (a != null && a.height)) {
|
|
140
|
+
const re = k, Fe = re.scaleX || 1, Ze = re.scaleY || 1;
|
|
141
|
+
g = a.width * Fe, p = a.height * Ze;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const A = Math.max(h, f, g, p) * 10, M = m[3] || u, Y = m[5] || 0, d = 0, C = l, X = (d - Y) / M, H = (C - Y) / M;
|
|
145
|
+
let W = s;
|
|
146
|
+
s < X ? W = X : s > H && (W = H);
|
|
147
|
+
const q = m[0] || u, oe = m[4] || 0, We = 0, ye = b, Re = (We - oe) / q, Te = (ye - oe) / q;
|
|
148
|
+
let U = o;
|
|
149
|
+
isNaN(o) || !isFinite(o) ? U = (b / 2 - oe) / q : o < Re ? U = Re : o > Te && (U = Te);
|
|
150
|
+
const ze = -A, _e = h + A, He = -A, Ie = f + A;
|
|
151
|
+
r.set({
|
|
152
|
+
x1: ze,
|
|
153
|
+
y1: W,
|
|
154
|
+
x2: _e,
|
|
155
|
+
y2: W,
|
|
112
156
|
visible: !0
|
|
113
157
|
// 显示辅助线
|
|
114
|
-
}),
|
|
115
|
-
x1:
|
|
116
|
-
y1:
|
|
117
|
-
x2:
|
|
118
|
-
y2:
|
|
158
|
+
}), r.setCoords(), n.set({
|
|
159
|
+
x1: U,
|
|
160
|
+
y1: He,
|
|
161
|
+
x2: U,
|
|
162
|
+
y2: Ie,
|
|
119
163
|
visible: !0
|
|
120
164
|
// 显示辅助线
|
|
121
|
-
}),
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
165
|
+
}), n.setCoords(), r.sendToBack(), n.sendToBack(), e.renderAll();
|
|
166
|
+
const O = Oe.current, Pe = O.rect && e.getObjects().includes(O.rect);
|
|
167
|
+
if (O.rect && !e.getObjects().includes(O.rect) && O.dleft !== -1 && O.dtop !== -1 && O.dw > 0 && O.dh > 0 && e.add(O.rect), Pe && O.rect) {
|
|
168
|
+
const a = Math.min(e.getObjects().indexOf(r), e.getObjects().indexOf(n));
|
|
169
|
+
e.getObjects().indexOf(O.rect) <= a && e.moveTo(O.rect, a + 1);
|
|
170
|
+
}
|
|
171
|
+
e.renderAll();
|
|
172
|
+
};
|
|
173
|
+
if (N.current) {
|
|
174
|
+
const s = e.getElement().getBoundingClientRect(), {
|
|
175
|
+
clientX: r,
|
|
176
|
+
clientY: n
|
|
177
|
+
} = N.current;
|
|
178
|
+
if (r >= s.left && r <= s.right && n >= s.top && n <= s.bottom) {
|
|
179
|
+
const b = new MouseEvent("mousemove", {
|
|
180
|
+
bubbles: !0,
|
|
181
|
+
cancelable: !0,
|
|
182
|
+
clientX: r,
|
|
183
|
+
clientY: n
|
|
184
|
+
}), l = e.getPointer(b);
|
|
185
|
+
R(l.x, l.y);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const t = Oe.current, B = (o) => {
|
|
130
189
|
if (e.skipTargetFind && (t.dleft === -1 || t.dtop === -1)) {
|
|
131
|
-
const
|
|
132
|
-
t.dleft =
|
|
190
|
+
const s = e.getPointer(o.e);
|
|
191
|
+
t.dleft = s.x, t.dtop = s.y;
|
|
133
192
|
}
|
|
134
|
-
},
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
},
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
193
|
+
}, Me = (o) => {
|
|
194
|
+
const s = e.getPointer(o.e);
|
|
195
|
+
R(s.x, s.y);
|
|
196
|
+
}, ee = (o) => {
|
|
197
|
+
const s = e.getPointer(o.e);
|
|
198
|
+
if (t.dleft !== -1 && t.dtop !== -1) {
|
|
199
|
+
let r = s.x, n = s.y;
|
|
200
|
+
if (t.dw = Math.abs(r - t.dleft), t.dh = Math.abs(n - t.dtop), t.dw > 0 && t.dh > 0) {
|
|
201
|
+
let u = t.dtop > n ? n : t.dtop, b = t.dleft > r ? r : t.dleft, l = t.dw, h = t.dh;
|
|
202
|
+
if (!t.rect || t.rect.left !== b || t.rect.top !== u || t.rect.width !== l || t.rect.height !== h || !e.getObjects().includes(t.rect)) {
|
|
203
|
+
t.rect && e.getObjects().includes(t.rect) && e.remove(t.rect);
|
|
204
|
+
const g = e.getZoom(), p = le / g;
|
|
205
|
+
t.rect = new T.Rect({
|
|
206
|
+
left: b,
|
|
207
|
+
top: u,
|
|
208
|
+
width: l,
|
|
209
|
+
height: h,
|
|
210
|
+
fill: Se,
|
|
211
|
+
stroke: ie,
|
|
212
|
+
strokeWidth: p,
|
|
213
|
+
strokeUniform: !0,
|
|
214
|
+
// 边框宽度不受缩放影响
|
|
215
|
+
strokeDashArray: je,
|
|
216
|
+
selectable: !1,
|
|
217
|
+
evented: !1,
|
|
218
|
+
objectCaching: !1,
|
|
219
|
+
// 禁用缓存,避免缩放时边框变虚
|
|
220
|
+
statefullCache: !1,
|
|
221
|
+
noScaleCache: !1
|
|
222
|
+
}), e.add(t.rect);
|
|
223
|
+
}
|
|
224
|
+
const m = i.current.horizontal, k = i.current.vertical;
|
|
225
|
+
if (t.rect && m && k && e.getObjects().includes(m) && e.getObjects().includes(k) && e.getObjects().includes(t.rect)) {
|
|
226
|
+
const g = Math.min(e.getObjects().indexOf(m), e.getObjects().indexOf(k));
|
|
227
|
+
e.getObjects().indexOf(t.rect) <= g && e.moveTo(t.rect, g + 1);
|
|
228
|
+
}
|
|
229
|
+
} else
|
|
230
|
+
t.rect && e.getObjects().includes(t.rect) && (e.remove(t.rect), t.rect = null);
|
|
231
|
+
}
|
|
232
|
+
Me(o);
|
|
233
|
+
}, te = (o) => {
|
|
166
234
|
if (t.dleft === -1 || t.dtop === -1) {
|
|
167
235
|
t.dtop = -1, t.dleft = -1;
|
|
168
236
|
return;
|
|
169
237
|
}
|
|
170
|
-
const
|
|
171
|
-
let
|
|
172
|
-
if (t.dw = Math.abs(
|
|
238
|
+
const s = e.getPointer(o.e);
|
|
239
|
+
let r = s.x, n = s.y;
|
|
240
|
+
if (t.dw = Math.abs(r - t.dleft), t.dh = Math.abs(n - t.dtop), t.dw === 0 || t.dh === 0) {
|
|
173
241
|
t.rect && (e.remove(t.rect), e.renderAll()), t.dtop = -1, t.dleft = -1;
|
|
174
242
|
return;
|
|
175
243
|
}
|
|
176
|
-
let u = t.dtop >
|
|
244
|
+
let u = t.dtop > n ? n : t.dtop, b = t.dleft > r ? r : t.dleft, l = t.dw, h = t.dh;
|
|
177
245
|
t.rect && (e.remove(t.rect), t.rect = null);
|
|
178
|
-
const
|
|
179
|
-
left:
|
|
246
|
+
const f = ue(b, u), m = l, k = h, g = e.getZoom(), p = le / g, c = new T.Rect({
|
|
247
|
+
left: b,
|
|
180
248
|
top: u,
|
|
181
|
-
width:
|
|
182
|
-
height:
|
|
183
|
-
fill:
|
|
249
|
+
width: l,
|
|
250
|
+
height: h,
|
|
251
|
+
fill: Be,
|
|
184
252
|
// 无填充色
|
|
185
|
-
stroke:
|
|
186
|
-
strokeWidth:
|
|
253
|
+
stroke: ie,
|
|
254
|
+
strokeWidth: p,
|
|
187
255
|
strokeUniform: !0,
|
|
188
256
|
// 边框宽度不受缩放影响
|
|
189
257
|
selectable: !0,
|
|
@@ -203,131 +271,146 @@ const Te = ({
|
|
|
203
271
|
hasControls: !0
|
|
204
272
|
// 启用控件
|
|
205
273
|
});
|
|
206
|
-
e.add(
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
274
|
+
e.add(c), c.controls.deleteControl = me(), c.controls.ocrControl = ge(), c.set("hasControls", !1);
|
|
275
|
+
const A = x.current.size, M = {};
|
|
276
|
+
J == null || J.forEach((d) => {
|
|
277
|
+
M[d.id] = "";
|
|
210
278
|
});
|
|
211
|
-
const
|
|
279
|
+
const Y = {
|
|
212
280
|
id: `region-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
213
|
-
name: `${
|
|
281
|
+
name: `${Ue}${A + 1}`,
|
|
214
282
|
// 设置名称:区域+(索引+1)
|
|
215
283
|
shape: {
|
|
216
284
|
name: "rect",
|
|
217
|
-
x: Math.max(0,
|
|
218
|
-
y: Math.max(0,
|
|
219
|
-
width:
|
|
220
|
-
height:
|
|
285
|
+
x: Math.max(0, f.x),
|
|
286
|
+
y: Math.max(0, f.y),
|
|
287
|
+
width: m,
|
|
288
|
+
height: k
|
|
221
289
|
},
|
|
222
|
-
content:
|
|
290
|
+
content: M
|
|
223
291
|
};
|
|
224
|
-
if (
|
|
225
|
-
const
|
|
226
|
-
|
|
292
|
+
if (x.current.set(c, Y), be(c, Y), D(c), Q) {
|
|
293
|
+
const d = x.current.get(c);
|
|
294
|
+
d && Q(d, "create");
|
|
227
295
|
}
|
|
228
|
-
|
|
229
|
-
if (
|
|
230
|
-
const
|
|
231
|
-
if (
|
|
232
|
-
if (
|
|
233
|
-
const
|
|
234
|
-
|
|
296
|
+
fe(Y).then((d) => {
|
|
297
|
+
if (d) {
|
|
298
|
+
const C = x.current.get(c);
|
|
299
|
+
if (C) {
|
|
300
|
+
if (C.image = d, delete C.textLayouts, I) {
|
|
301
|
+
const X = Array.from(x.current.values());
|
|
302
|
+
I(X);
|
|
235
303
|
}
|
|
236
|
-
|
|
304
|
+
he(C, "create");
|
|
237
305
|
}
|
|
238
306
|
}
|
|
239
|
-
}).catch((
|
|
240
|
-
console.error("Failed to crop region image:",
|
|
241
|
-
}), e.setActiveObject(
|
|
242
|
-
if (
|
|
243
|
-
const
|
|
244
|
-
|
|
307
|
+
}).catch((d) => {
|
|
308
|
+
console.error("Failed to crop region image:", d);
|
|
309
|
+
}), e.setActiveObject(c), e.renderAll(), setTimeout(() => {
|
|
310
|
+
if (P) {
|
|
311
|
+
const d = x.current.get(c);
|
|
312
|
+
d && P(d);
|
|
245
313
|
}
|
|
246
314
|
setTimeout(() => {
|
|
247
|
-
if (e &&
|
|
248
|
-
const
|
|
249
|
-
|
|
315
|
+
if (e && c && e.getObjects().includes(c) && (e.setActiveObject(c), e.renderAll(), P)) {
|
|
316
|
+
const d = x.current.get(c);
|
|
317
|
+
d && P(d);
|
|
250
318
|
}
|
|
251
319
|
}, 0);
|
|
252
|
-
}, 0),
|
|
253
|
-
|
|
254
|
-
}),
|
|
255
|
-
|
|
320
|
+
}, 0), pe(c), c.on("modified", () => {
|
|
321
|
+
D(c);
|
|
322
|
+
}), c.on("moved", () => {
|
|
323
|
+
D(c);
|
|
256
324
|
}), setTimeout(() => {
|
|
257
|
-
if (
|
|
258
|
-
const
|
|
259
|
-
|
|
325
|
+
if (I) {
|
|
326
|
+
const d = Array.from(x.current.values());
|
|
327
|
+
I(d);
|
|
260
328
|
}
|
|
261
|
-
}, 0), t.dtop = -1, t.dleft = -1, e.selection = !1,
|
|
262
|
-
},
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
B({
|
|
329
|
+
}, 0), t.dtop = -1, t.dleft = -1, e.selection = !1, de(!1);
|
|
330
|
+
}, ae = (o) => {
|
|
331
|
+
N.current = {
|
|
332
|
+
clientX: o.clientX,
|
|
333
|
+
clientY: o.clientY
|
|
334
|
+
};
|
|
335
|
+
const r = e.getElement().getBoundingClientRect(), n = o.clientX, u = o.clientY, b = n >= r.left && n <= r.right && u >= r.top && u <= r.bottom;
|
|
336
|
+
if (t.dleft !== -1 && t.dtop !== -1)
|
|
337
|
+
if (b) {
|
|
338
|
+
const l = e.getPointer(o);
|
|
339
|
+
ee({
|
|
273
340
|
e: o,
|
|
274
|
-
pointer:
|
|
341
|
+
pointer: l
|
|
275
342
|
});
|
|
276
343
|
} else {
|
|
277
|
-
const
|
|
278
|
-
let
|
|
279
|
-
if (
|
|
344
|
+
const l = e.getZoom(), h = e.viewportTransform ? e.viewportTransform[4] / l : 0, f = e.viewportTransform ? e.viewportTransform[5] / l : 0, m = e.getWidth() / l, k = e.getHeight() / l;
|
|
345
|
+
let g = (n - r.left) / l - h, p = (u - r.top) / l - f;
|
|
346
|
+
if (g = Math.max(0, Math.min(g, m)), p = Math.max(0, Math.min(p, k)), t.dw = Math.abs(g - t.dleft), t.dh = Math.abs(p - t.dtop), t.dw === 0 || t.dh === 0)
|
|
280
347
|
return;
|
|
281
|
-
let
|
|
348
|
+
let c = t.dtop > p ? p : t.dtop, A = t.dleft > g ? g : t.dleft, M = t.dw, Y = t.dh;
|
|
282
349
|
t.rect && e.remove(t.rect);
|
|
283
|
-
const
|
|
284
|
-
t.rect = new
|
|
285
|
-
left:
|
|
286
|
-
top:
|
|
287
|
-
width:
|
|
288
|
-
height:
|
|
289
|
-
fill:
|
|
290
|
-
stroke:
|
|
291
|
-
strokeWidth:
|
|
350
|
+
const d = e.getZoom(), C = le / d;
|
|
351
|
+
t.rect = new T.Rect({
|
|
352
|
+
left: A,
|
|
353
|
+
top: c,
|
|
354
|
+
width: M,
|
|
355
|
+
height: Y,
|
|
356
|
+
fill: Se,
|
|
357
|
+
stroke: ie,
|
|
358
|
+
strokeWidth: C,
|
|
292
359
|
strokeUniform: !0,
|
|
293
|
-
strokeDashArray:
|
|
360
|
+
strokeDashArray: je,
|
|
294
361
|
selectable: !1,
|
|
295
362
|
evented: !1,
|
|
296
363
|
objectCaching: !1,
|
|
297
364
|
statefullCache: !1,
|
|
298
365
|
noScaleCache: !1
|
|
299
|
-
}), e.add(t.rect)
|
|
366
|
+
}), e.add(t.rect);
|
|
367
|
+
const X = i.current.horizontal, H = i.current.vertical;
|
|
368
|
+
if (X && H && e.getObjects().includes(X) && e.getObjects().includes(H)) {
|
|
369
|
+
const W = Math.min(e.getObjects().indexOf(X), e.getObjects().indexOf(H));
|
|
370
|
+
e.getObjects().indexOf(t.rect) < W && e.moveTo(t.rect, W + 1);
|
|
371
|
+
}
|
|
372
|
+
e.renderAll();
|
|
300
373
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
374
|
+
if (t.dleft === -1 || t.dtop === -1) {
|
|
375
|
+
let l, h;
|
|
376
|
+
if (b) {
|
|
377
|
+
const f = e.getPointer(o);
|
|
378
|
+
l = f.x, h = f.y;
|
|
379
|
+
} else {
|
|
380
|
+
const f = e.getZoom(), m = e.viewportTransform ? e.viewportTransform[4] / f : 0, k = e.viewportTransform ? e.viewportTransform[5] / f : 0;
|
|
381
|
+
l = (n - r.left) / f - m, h = (u - r.top) / f - k;
|
|
382
|
+
}
|
|
383
|
+
R(l, h);
|
|
384
|
+
}
|
|
385
|
+
}, xe = () => {
|
|
386
|
+
}, Le = (o) => {
|
|
387
|
+
const s = e.getPointer(o.e);
|
|
388
|
+
R(s.x, s.y);
|
|
389
|
+
}, we = (o) => {
|
|
390
|
+
if (!y)
|
|
308
391
|
return;
|
|
309
392
|
e.skipTargetFind = !0, e.getActiveObject() && (e.discardActiveObject(), e.renderAll()), t.dtop = -1, t.dleft = -1, t.dw = 0, t.dh = 0;
|
|
310
|
-
const
|
|
311
|
-
t.dleft =
|
|
393
|
+
const r = e.getPointer(o.e);
|
|
394
|
+
t.dleft = r.x, t.dtop = r.y;
|
|
312
395
|
};
|
|
313
|
-
e.on("mouse:down:before",
|
|
314
|
-
const
|
|
396
|
+
e.on("mouse:down:before", we), e.on("mouse:down", B), e.on("mouse:move", ee), e.on("mouse:up", te), e.on("mouse:out", xe), e.on("mouse:over", Le), document.addEventListener("mousemove", ae);
|
|
397
|
+
const Ee = (o) => {
|
|
315
398
|
if (t.dleft === -1 || t.dtop === -1)
|
|
316
399
|
return;
|
|
317
|
-
const
|
|
318
|
-
|
|
400
|
+
const s = e.getPointer(o);
|
|
401
|
+
te({
|
|
319
402
|
e: o,
|
|
320
|
-
pointer:
|
|
403
|
+
pointer: s
|
|
321
404
|
});
|
|
322
405
|
};
|
|
323
|
-
return document.addEventListener("mouseup",
|
|
324
|
-
e.off("mouse:down:before",
|
|
406
|
+
return document.addEventListener("mouseup", Ee), () => {
|
|
407
|
+
e.off("mouse:down:before", we), e.off("mouse:down", B), e.off("mouse:move", ee), e.off("mouse:up", te), e.off("mouse:out", xe), e.off("mouse:over", Le), document.removeEventListener("mousemove", ae), document.removeEventListener("mouseup", Ee), t.rect && (e.remove(t.rect), e.renderAll()), i.current.horizontal && e.getObjects().includes(i.current.horizontal) && e.remove(i.current.horizontal), i.current.vertical && e.getObjects().includes(i.current.vertical) && e.remove(i.current.vertical), i.current = {
|
|
325
408
|
horizontal: null,
|
|
326
409
|
vertical: null
|
|
327
|
-
}, e.skipTargetFind = !1;
|
|
328
|
-
const o =
|
|
410
|
+
}, e.skipTargetFind = !1, e.defaultCursor = "default";
|
|
411
|
+
const o = V(), s = new Set(v.current.values());
|
|
329
412
|
e.getObjects().forEach((r) => {
|
|
330
|
-
r instanceof
|
|
413
|
+
r instanceof T.Rect && o.has(r) ? r.set({
|
|
331
414
|
evented: !0,
|
|
332
415
|
selectable: !1,
|
|
333
416
|
lockMovementX: !0,
|
|
@@ -335,43 +418,67 @@ const Te = ({
|
|
|
335
418
|
lockScalingX: !0,
|
|
336
419
|
lockScalingY: !0,
|
|
337
420
|
lockRotation: !0
|
|
421
|
+
}) : s.has(r) ? r.set({
|
|
422
|
+
evented: !1,
|
|
423
|
+
selectable: !1,
|
|
424
|
+
lockMovementX: !0,
|
|
425
|
+
lockMovementY: !0,
|
|
426
|
+
lockScalingX: !1,
|
|
427
|
+
// 允许缩放,用于抵消画布缩放
|
|
428
|
+
lockScalingY: !1,
|
|
429
|
+
// 允许缩放,用于抵消画布缩放
|
|
430
|
+
lockRotation: !0,
|
|
431
|
+
hasControls: !1,
|
|
432
|
+
hasBorders: !1
|
|
338
433
|
}) : (r.set("evented", !0), r.set("selectable", !0));
|
|
339
434
|
});
|
|
340
435
|
};
|
|
341
|
-
}, [e,
|
|
342
|
-
if (!e
|
|
436
|
+
}, [e, y, ce, G, ue, I, fe, D, he, me, ge, be, Q, P, de, x, V, v, pe]), se(() => {
|
|
437
|
+
if (!e)
|
|
438
|
+
return;
|
|
439
|
+
const L = (w) => {
|
|
440
|
+
N.current = {
|
|
441
|
+
clientX: w.clientX,
|
|
442
|
+
clientY: w.clientY
|
|
443
|
+
};
|
|
444
|
+
};
|
|
445
|
+
return document.addEventListener("mousemove", L), () => {
|
|
446
|
+
document.removeEventListener("mousemove", L);
|
|
447
|
+
};
|
|
448
|
+
}, [e]), se(() => {
|
|
449
|
+
if (!e || !y)
|
|
343
450
|
return;
|
|
344
|
-
let
|
|
345
|
-
const
|
|
346
|
-
const
|
|
347
|
-
if (!
|
|
451
|
+
let L = e.getZoom();
|
|
452
|
+
const w = () => {
|
|
453
|
+
const S = i.current.horizontal, E = i.current.vertical;
|
|
454
|
+
if (!S || !E)
|
|
348
455
|
return;
|
|
349
|
-
const
|
|
350
|
-
if (Math.abs(
|
|
456
|
+
const j = e.getZoom();
|
|
457
|
+
if (Math.abs(j - L) < 1e-3)
|
|
351
458
|
return;
|
|
352
|
-
|
|
353
|
-
const
|
|
354
|
-
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
strokeWidth:
|
|
358
|
-
x1: t -
|
|
359
|
-
x2: t +
|
|
360
|
-
}),
|
|
361
|
-
strokeWidth:
|
|
362
|
-
y1:
|
|
363
|
-
y2:
|
|
459
|
+
L = j;
|
|
460
|
+
const $ = Xe / j, _ = e.getWidth(), K = e.getHeight(), F = _ / j, Z = K / j, R = Math.max(F, Z) * 3, t = (S.x1 + S.x2) / 2;
|
|
461
|
+
S.y1, E.x1;
|
|
462
|
+
const B = (E.y1 + E.y2) / 2;
|
|
463
|
+
S.set({
|
|
464
|
+
strokeWidth: $,
|
|
465
|
+
x1: t - R,
|
|
466
|
+
x2: t + R
|
|
467
|
+
}), E.set({
|
|
468
|
+
strokeWidth: $,
|
|
469
|
+
y1: B - R,
|
|
470
|
+
y2: B + R
|
|
364
471
|
}), e.renderAll();
|
|
365
|
-
},
|
|
366
|
-
|
|
472
|
+
}, z = () => {
|
|
473
|
+
w();
|
|
367
474
|
};
|
|
368
|
-
return e.on("after:render",
|
|
369
|
-
e.off("after:render",
|
|
475
|
+
return e.on("after:render", z), w(), () => {
|
|
476
|
+
e.off("after:render", z);
|
|
370
477
|
};
|
|
371
|
-
}, [e,
|
|
372
|
-
stopDraw:
|
|
478
|
+
}, [e, y]), {
|
|
479
|
+
stopDraw: G
|
|
373
480
|
};
|
|
374
481
|
};
|
|
375
482
|
export {
|
|
376
|
-
|
|
483
|
+
Ge as useDrawingMode
|
|
377
484
|
};
|