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