@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.
@@ -69,7 +69,7 @@ const F = ({
69
69
  }), /* @__PURE__ */ i("div", {
70
70
  className: "vlm-text-region-actions",
71
71
  children: [!d && M && /* @__PURE__ */ e(V, {
72
- title: p ? "识别中..." : w ? "识别失败,点击重试" : "OCR识别",
72
+ title: p ? "识别中..." : w ? "预置服务调用失败" : "OCR识别",
73
73
  children: /* @__PURE__ */ e("span", {
74
74
  className: `vlm-text-region-ocr-btn ${p ? "vlm-text-region-ocr-btn-loading" : ""} ${w ? "vlm-text-region-ocr-btn-error" : ""}`,
75
75
  onClick: (t) => {
@@ -0,0 +1,193 @@
1
+ import { useRef as rt, useEffect as ft } from "react";
2
+ import { fabric as Z } from "fabric";
3
+ import { AI_CONTROL_OFFSET_X as ut, AI_CONTROL_OFFSET_Y as Ct, AI_ICON_SIZE as st } from "../../constants.mjs";
4
+ const Ft = ({
5
+ canvas: l,
6
+ ocrErrorRef: k,
7
+ rectMapRef: D,
8
+ onAIButtonHover: n
9
+ }) => {
10
+ const G = rt(null), J = rt(null);
11
+ ft(() => {
12
+ if (!l || !n)
13
+ return;
14
+ const O = /* @__PURE__ */ new Map(), lt = (S) => {
15
+ var h;
16
+ const a = (h = S.controls) == null ? void 0 : h.ocrControl;
17
+ if (!a)
18
+ return;
19
+ const E = a.render;
20
+ E && !a._intercepted && (a.render = (q, F, c, i, _) => {
21
+ O.set(S, {
22
+ x: F,
23
+ y: c
24
+ }), E && E(q, F, c, i, _);
25
+ }, a._intercepted = !0);
26
+ }, K = (S) => {
27
+ var et;
28
+ const a = S.e, h = l.getElement().getBoundingClientRect(), q = a.clientX - h.left, F = a.clientY - h.top;
29
+ let c = null, i = null;
30
+ const _ = l.getActiveObject();
31
+ if (!_ || !(_ instanceof Z.Rect)) {
32
+ n(null, null);
33
+ return;
34
+ }
35
+ const o = _, W = D.current.get(o);
36
+ if (!W) {
37
+ n(null, null);
38
+ return;
39
+ }
40
+ const $ = W.id;
41
+ if (!k.current.has($)) {
42
+ n(null, null);
43
+ return;
44
+ }
45
+ const y = (et = o.controls) == null ? void 0 : et.ocrControl;
46
+ if (!y) {
47
+ n(null, null);
48
+ return;
49
+ }
50
+ const U = ut, V = Ct + st + 4;
51
+ lt(o);
52
+ let x = O.get(o);
53
+ if (!x) {
54
+ try {
55
+ if (o._calcControlPosition && typeof o._calcControlPosition == "function") {
56
+ const t = o._calcControlPosition(y);
57
+ t && (x = {
58
+ x: t.x,
59
+ y: t.y
60
+ }, O.set(o, x));
61
+ }
62
+ } catch (t) {
63
+ }
64
+ if (!x)
65
+ try {
66
+ const t = o.getCoords();
67
+ if (t && t.length >= 4) {
68
+ const e = t[1], L = t[2], f = t[0], M = e, u = {
69
+ x: L.x - e.x,
70
+ y: L.y - e.y
71
+ }, C = {
72
+ x: f.x - e.x,
73
+ y: f.y - e.y
74
+ }, r = Math.sqrt(u.x * u.x + u.y * u.y), s = Math.sqrt(C.x * C.x + C.y * C.y), b = r > 1e-3 ? {
75
+ x: u.x / r,
76
+ y: u.y / r
77
+ } : {
78
+ x: 1,
79
+ y: 0
80
+ }, P = s > 1e-3 ? {
81
+ x: C.x / s,
82
+ y: C.y / s
83
+ } : {
84
+ x: 0,
85
+ y: -1
86
+ }, T = M.x + b.x * U - P.x * V, z = M.y + b.y * U - P.y * V;
87
+ x = {
88
+ x: T,
89
+ y: z
90
+ }, O.set(o, x);
91
+ }
92
+ } catch (t) {
93
+ console.warn("[useAIButtonHover] Failed to calculate control position:", t);
94
+ }
95
+ }
96
+ const d = o.getCoords();
97
+ if (!d || d.length < 4) {
98
+ n(null, null);
99
+ return;
100
+ }
101
+ const A = d[0], R = d[1], H = d[2];
102
+ d[3];
103
+ const B = R, p = {
104
+ x: H.x - R.x,
105
+ y: H.y - R.y
106
+ }, m = {
107
+ x: A.x - R.x,
108
+ y: A.y - R.y
109
+ }, I = Math.sqrt(p.x * p.x + p.y * p.y), N = Math.sqrt(m.x * m.x + m.y * m.y), tt = I > 1e-3 ? {
110
+ x: p.x / I,
111
+ y: p.y / I
112
+ } : {
113
+ x: 1,
114
+ y: 0
115
+ }, ot = N > 1e-3 ? {
116
+ x: m.x / N,
117
+ y: m.y / N
118
+ } : {
119
+ x: 0,
120
+ y: -1
121
+ }, it = B.x + tt.x * U - ot.x * V, yt = B.y + tt.y * U - ot.y * V, v = st / 2, w = 8;
122
+ let g = null;
123
+ try {
124
+ if (o._calcControlPosition && typeof o._calcControlPosition == "function") {
125
+ const t = o._calcControlPosition(y);
126
+ t && (g = {
127
+ x: t.x,
128
+ y: t.y
129
+ });
130
+ }
131
+ if (!g && o.calcCoords) {
132
+ const t = o.calcCoords();
133
+ if (t && y.x !== void 0 && y.y !== void 0) {
134
+ const e = y.x, L = y.y, f = y.offsetX || 0, M = y.offsetY || 0, u = t.tr.x, C = t.tr.y, r = {
135
+ x: t.br.x - t.tr.x,
136
+ y: t.br.y - t.tr.y
137
+ }, s = {
138
+ x: t.tl.x - t.tr.x,
139
+ y: t.tl.y - t.tr.y
140
+ }, b = Math.sqrt(r.x * r.x + r.y * r.y), P = Math.sqrt(s.x * s.x + s.y * s.y), T = b > 1e-3 ? {
141
+ x: r.x / b,
142
+ y: r.y / b
143
+ } : {
144
+ x: 1,
145
+ y: 0
146
+ }, z = P > 1e-3 ? {
147
+ x: s.x / P,
148
+ y: s.y / P
149
+ } : {
150
+ x: 0,
151
+ y: -1
152
+ }, xt = u + T.x * f - z.x * M, at = C + T.y * f - z.y * M;
153
+ g = {
154
+ x: xt,
155
+ y: at
156
+ };
157
+ }
158
+ }
159
+ } catch (t) {
160
+ console.warn("[useAIButtonHover] Failed to calculate fabric control position:", t);
161
+ }
162
+ const nt = l.viewportTransform;
163
+ if (!nt) {
164
+ n(null, null);
165
+ return;
166
+ }
167
+ let X, Y;
168
+ if (x)
169
+ X = x.x, Y = x.y;
170
+ else {
171
+ const t = g ? g.x : it, e = g ? g.y : yt, L = new Z.Point(t, e), f = Z.util.transformPoint(L, nt);
172
+ X = f.x, Y = f.y;
173
+ }
174
+ if (q >= X - v - w && q <= X + v + w && F >= Y - v - w && F <= Y + v + w) {
175
+ const t = h.left + X, e = h.top + Y;
176
+ c = $, i = {
177
+ x: t,
178
+ y: e
179
+ };
180
+ }
181
+ const ct = G.current, j = J.current;
182
+ (c !== ct || c && i && (!j || j.x !== i.x || j.y !== i.y) || !c && ct !== null) && (c && i ? n(c, i) : n(null, null), G.current = c, J.current = i);
183
+ }, Q = () => {
184
+ n && n(null, null);
185
+ };
186
+ return l.on("mouse:move", K), l.on("mouse:out", Q), () => {
187
+ l.off("mouse:move", K), l.off("mouse:out", Q);
188
+ };
189
+ }, [l, k, D, n]);
190
+ };
191
+ export {
192
+ Ft as useAIButtonHover
193
+ };
@@ -1,26 +1,26 @@
1
1
  import { useEffect as b } from "react";
2
- import { fabric as u } from "fabric";
2
+ import { fabric as c } from "fabric";
3
3
  const O = ({
4
4
  canvas: e,
5
5
  draggable: i,
6
6
  drawingMode: f,
7
7
  textLayersMapRef: n
8
8
  }) => {
9
- const s = () => {
10
- const c = /* @__PURE__ */ new Set();
9
+ const u = () => {
10
+ const s = /* @__PURE__ */ new Set();
11
11
  return n.current.forEach((l) => {
12
12
  l.forEach((r) => {
13
- c.add(r);
13
+ s.add(r);
14
14
  });
15
- }), c;
15
+ }), s;
16
16
  };
17
17
  b(() => {
18
18
  if (!e || f) {
19
19
  if (e) {
20
20
  e.selection = !1, e.skipTargetFind = !1;
21
- const o = s();
21
+ const o = u();
22
22
  e.getObjects().forEach((t) => {
23
- t instanceof u.Rect && o.has(t) ? t.set({
23
+ t instanceof c.Rect && o.has(t) ? t.set({
24
24
  evented: !0,
25
25
  selectable: !1,
26
26
  lockMovementX: !0,
@@ -36,15 +36,15 @@ const O = ({
36
36
  lockScalingX: !1,
37
37
  lockScalingY: !1
38
38
  });
39
- }), e.defaultCursor = "default", e.setCursor("default");
39
+ }), e.defaultCursor = "default";
40
40
  }
41
41
  return;
42
42
  }
43
43
  if (!i) {
44
44
  e.selection = !1, e.skipTargetFind = !1;
45
- const o = s();
45
+ const o = u();
46
46
  e.getObjects().forEach((t) => {
47
- t instanceof u.Rect && o.has(t) ? t.set({
47
+ t instanceof c.Rect && o.has(t) ? t.set({
48
48
  evented: !0,
49
49
  selectable: !1,
50
50
  lockMovementX: !0,
@@ -60,7 +60,7 @@ const O = ({
60
60
  lockScalingX: !1,
61
61
  lockScalingY: !1
62
62
  });
63
- }), e.defaultCursor = "default", e.setCursor("default");
63
+ }), e.defaultCursor = "default";
64
64
  return;
65
65
  }
66
66
  e.selection = !1, e.skipTargetFind = !0, e.getActiveObject() && (e.discardActiveObject(), e.renderAll()), e.getObjects().forEach((o) => {
@@ -77,21 +77,21 @@ const O = ({
77
77
  let l = !1;
78
78
  const r = (o) => {
79
79
  e.getActiveObject() && (e.discardActiveObject(), e.renderAll()), l = !0, e.selection = !1, e.skipTargetFind = !0, e.setCursor("grabbing");
80
- }, d = (o) => {
80
+ }, k = (o) => {
81
81
  if (l && o && o.e) {
82
- const t = o.e, m = new u.Point(t.movementX, t.movementY);
82
+ const t = o.e, m = new c.Point(t.movementX, t.movementY);
83
83
  e.relativePan(m);
84
84
  }
85
- }, k = () => {
85
+ }, d = () => {
86
86
  l = !1, e.selection = !1, e.skipTargetFind = !0, e.defaultCursor = "grab", e.setCursor("grab"), e.getActiveObject() && (e.discardActiveObject(), e.renderAll());
87
87
  }, g = () => {
88
88
  e.setCursor("grabbing");
89
89
  };
90
- return e.on("mouse:down", r), e.on("mouse:move", d), e.on("mouse:up", k), e.on("mouse:down:before", g), () => {
91
- e.off("mouse:down", r), e.off("mouse:move", d), e.off("mouse:up", k), e.off("mouse:down:before", g), e.selection = !1, e.skipTargetFind = !1;
92
- const o = s();
90
+ return e.on("mouse:down", r), e.on("mouse:move", k), e.on("mouse:up", d), e.on("mouse:down:before", g), () => {
91
+ e.off("mouse:down", r), e.off("mouse:move", k), e.off("mouse:up", d), e.off("mouse:down:before", g), e.selection = !1, e.skipTargetFind = !1;
92
+ const o = u();
93
93
  e.getObjects().forEach((t) => {
94
- t instanceof u.Rect && o.has(t) ? t.set({
94
+ t instanceof c.Rect && o.has(t) ? t.set({
95
95
  evented: !0,
96
96
  selectable: !1,
97
97
  lockMovementX: !0,