@glodon-aiot/dataset-annotation 3.14.0-alpha.32 → 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.
@@ -1,51 +1,90 @@
1
- import { useEffect as E } from "react";
2
- import { fabric as a } from "fabric";
3
- import { SELECTED_RECT_FILL_COLOR as L, CONTROL_POINT_COLOR as g, CONTROL_POINT_SIZE as A, TRANSPARENT_FILL as k, BASE_STROKE_WIDTH as R } from "../../constants.mjs";
4
- const b = ({
5
- canvas: e,
6
- onRegionSelect: o,
7
- createDeleteControl: n,
8
- createOCRControl: s,
9
- textLayersMapRef: h,
10
- rectMapRef: i
1
+ import { useEffect as W } from "react";
2
+ import { fabric as f } from "fabric";
3
+ import { SELECTED_RECT_FILL_COLOR as k, RECT_STROKE_COLOR as X, CONTROL_POINT_COLOR as j, CONTROL_POINT_SIZE as N, TRANSPARENT_FILL as Y, BASE_STROKE_WIDTH as F, AI_CONTROL_OFFSET_X as q, AI_CONTROL_OFFSET_Y as z, AI_ICON_SIZE as D } from "../../constants.mjs";
4
+ const G = ({
5
+ canvas: o,
6
+ onRegionSelect: l,
7
+ createDeleteControl: h,
8
+ createOCRControl: g,
9
+ textLayersMapRef: O,
10
+ rectMapRef: y
11
11
  }) => {
12
- E(() => {
13
- if (!e)
12
+ W(() => {
13
+ if (!o)
14
14
  return;
15
- const f = () => {
15
+ const C = () => {
16
16
  const t = /* @__PURE__ */ new Set();
17
- return h.current.forEach((r) => {
18
- r.forEach((l) => {
19
- t.add(l);
17
+ return O.current.forEach((n) => {
18
+ n.forEach((c) => {
19
+ t.add(c);
20
20
  });
21
21
  }), t;
22
- }, d = () => {
23
- const t = f();
24
- e.getObjects().forEach((r) => {
25
- r instanceof a.Rect && !t.has(r) && r.set({
26
- fill: k
22
+ }, m = () => {
23
+ const t = C();
24
+ o.getObjects().forEach((n) => {
25
+ n instanceof f.Rect && !t.has(n) && n.set({
26
+ fill: Y
27
27
  // 移除填充色
28
28
  });
29
29
  });
30
- }, C = () => {
31
- d();
32
- const t = e.getActiveObject();
33
- if (t && t instanceof a.Rect) {
34
- if (f().has(t)) {
35
- e.discardActiveObject(), e.renderAll();
30
+ }, S = (t) => {
31
+ const n = t.getCoords();
32
+ if (!n || n.length < 4)
33
+ return null;
34
+ const c = q, u = z + D + 4, a = n[0], i = n[1], d = n[2], s = i, e = {
35
+ x: d.x - i.x,
36
+ y: d.y - i.y
37
+ }, r = {
38
+ x: a.x - i.x,
39
+ y: a.y - i.y
40
+ }, p = Math.sqrt(e.x * e.x + e.y * e.y), x = Math.sqrt(r.x * r.x + r.y * r.y), T = p > 1e-3 ? {
41
+ x: e.x / p,
42
+ y: e.y / p
43
+ } : {
44
+ x: 1,
45
+ y: 0
46
+ }, L = x > 1e-3 ? {
47
+ x: r.x / x,
48
+ y: r.y / x
49
+ } : {
50
+ x: 0,
51
+ y: -1
52
+ }, b = s.x + T.x * c - L.x * u, E = s.y + T.y * c - L.y * u, _ = o.viewportTransform;
53
+ if (!_)
54
+ return null;
55
+ const U = new f.Point(b, E), P = f.util.transformPoint(U, _), Z = o.getElement().getBoundingClientRect(), w = Z.left + P.x, B = Z.top + P.y;
56
+ return {
57
+ canvasCoords: {
58
+ x: b,
59
+ y: E
60
+ },
61
+ screenCoords: {
62
+ x: w,
63
+ y: B
64
+ }
65
+ };
66
+ }, R = () => {
67
+ var n, c;
68
+ m();
69
+ const t = o.getActiveObject();
70
+ if (t && t instanceof f.Rect) {
71
+ if (C().has(t)) {
72
+ o.discardActiveObject(), o.renderAll();
36
73
  return;
37
74
  }
38
- const l = e.getZoom(), u = R / l;
75
+ const a = o.getZoom(), i = F / a;
39
76
  t.set({
40
77
  hasRotatingPoint: !1,
41
78
  lockRotation: !0,
42
79
  lockUniScaling: !1,
43
80
  // 允许非等比缩放,控制点跟随鼠标
44
- fill: L,
81
+ fill: k,
45
82
  // 选中时添加填充色
83
+ stroke: X,
84
+ // 选中时取消高亮,使用普通边框颜色
46
85
  strokeUniform: !0,
47
86
  // 确保边框宽度不受缩放影响
48
- strokeWidth: u,
87
+ strokeWidth: i,
49
88
  // 确保边框宽度一致
50
89
  objectCaching: !1,
51
90
  // 禁用缓存,避免缩放时边框变虚
@@ -53,25 +92,57 @@ const b = ({
53
92
  noScaleCache: !1,
54
93
  cornerStyle: "circle",
55
94
  // 设置控制点为圆形
56
- cornerColor: g,
95
+ cornerColor: j,
57
96
  // 设置控制点为紫色(填充色)
58
- cornerSize: A,
97
+ cornerSize: N,
59
98
  // 设置控制点大小(默认12,这里设置为6使其更小)
60
99
  transparentCorners: !1
61
100
  // 不透明,显示填充颜色
62
- }), t.controls && t.controls.mtr && delete t.controls.mtr, t.controls.deleteControl || (t.controls.deleteControl = n()), t.controls.ocrControl || (t.controls.ocrControl = s()), e.renderAll();
63
- const c = i.current.get(t);
64
- c && o && o(c);
101
+ }), t.controls && t.controls.mtr && delete t.controls.mtr, t.controls.deleteControl || (t.controls.deleteControl = h()), t.controls.ocrControl || (t.controls.ocrControl = g()), o.renderAll();
102
+ const d = S(t), s = y.current.get(t);
103
+ fetch("http://127.0.0.1:7243/ingest/f03da105-26de-4a72-9802-7a749afbd310", {
104
+ method: "POST",
105
+ headers: {
106
+ "Content-Type": "application/json"
107
+ },
108
+ body: JSON.stringify({
109
+ location: "useRegionSelection.ts:handleSelectionCreated",
110
+ message: "AI button position when region selected",
111
+ data: {
112
+ regionId: s == null ? void 0 : s.id,
113
+ aiButtonPosition: d,
114
+ rectCoords: (n = t.getCoords()) == null ? void 0 : n.map((e) => ({
115
+ x: e.x,
116
+ y: e.y
117
+ })),
118
+ canvasZoom: o.getZoom()
119
+ },
120
+ timestamp: Date.now(),
121
+ sessionId: "debug-session",
122
+ runId: "run1",
123
+ hypothesisId: "A"
124
+ })
125
+ }).catch(() => {
126
+ }), console.log("[useRegionSelection] Region selected - AI button position:", {
127
+ regionId: s == null ? void 0 : s.id,
128
+ aiButtonPosition: d,
129
+ rectCoords: (c = t.getCoords()) == null ? void 0 : c.map((e) => ({
130
+ x: e.x,
131
+ y: e.y
132
+ })),
133
+ canvasZoom: o.getZoom()
134
+ }), s && l && l(s);
65
135
  }
66
- }, m = () => {
67
- d();
68
- const t = e.getActiveObject();
69
- if (t && t instanceof a.Rect) {
70
- if (f().has(t)) {
71
- e.discardActiveObject(), e.renderAll();
136
+ }, I = () => {
137
+ var n, c;
138
+ m();
139
+ const t = o.getActiveObject();
140
+ if (t && t instanceof f.Rect) {
141
+ if (C().has(t)) {
142
+ o.discardActiveObject(), o.renderAll();
72
143
  return;
73
144
  }
74
- const l = e.getZoom(), u = R / l;
145
+ const a = o.getZoom(), i = F / a;
75
146
  t.set({
76
147
  hasRotatingPoint: !1,
77
148
  lockRotation: !0,
@@ -79,11 +150,11 @@ const b = ({
79
150
  // 允许非等比缩放,控制点跟随鼠标
80
151
  lockScalingFlip: !0,
81
152
  // 禁止缩放时翻转
82
- fill: L,
153
+ fill: k,
83
154
  // 选中时添加填充色
84
155
  strokeUniform: !0,
85
156
  // 确保边框宽度不受缩放影响
86
- strokeWidth: u,
157
+ strokeWidth: i,
87
158
  // 确保边框宽度一致
88
159
  objectCaching: !1,
89
160
  // 禁用缓存,避免缩放时边框变虚
@@ -91,26 +162,57 @@ const b = ({
91
162
  noScaleCache: !1,
92
163
  cornerStyle: "circle",
93
164
  // 设置控制点为圆形
94
- cornerColor: g,
165
+ cornerColor: j,
95
166
  // 设置控制点为紫色(填充色)
96
- cornerSize: A,
167
+ cornerSize: N,
97
168
  // 设置控制点大小(默认12,这里设置为6使其更小)
98
169
  transparentCorners: !1
99
170
  // 不透明,显示填充颜色
100
171
  });
101
- const c = t;
102
- c.uniformScaling = !1, t.controls && t.controls.mtr && delete t.controls.mtr, t.controls.deleteControl || (t.controls.deleteControl = n()), t.controls.ocrControl || (t.controls.ocrControl = s()), e.renderAll();
103
- const S = i.current.get(t);
104
- S && o && o(S);
172
+ const d = t;
173
+ d.uniformScaling = !1, t.controls && t.controls.mtr && delete t.controls.mtr, t.controls.deleteControl || (t.controls.deleteControl = h()), t.controls.ocrControl || (t.controls.ocrControl = g()), o.renderAll();
174
+ const s = S(t), e = y.current.get(t);
175
+ fetch("http://127.0.0.1:7243/ingest/f03da105-26de-4a72-9802-7a749afbd310", {
176
+ method: "POST",
177
+ headers: {
178
+ "Content-Type": "application/json"
179
+ },
180
+ body: JSON.stringify({
181
+ location: "useRegionSelection.ts:handleSelectionUpdated",
182
+ message: "AI button position when region updated",
183
+ data: {
184
+ regionId: e == null ? void 0 : e.id,
185
+ aiButtonPosition: s,
186
+ rectCoords: (n = t.getCoords()) == null ? void 0 : n.map((r) => ({
187
+ x: r.x,
188
+ y: r.y
189
+ })),
190
+ canvasZoom: o.getZoom()
191
+ },
192
+ timestamp: Date.now(),
193
+ sessionId: "debug-session",
194
+ runId: "run1",
195
+ hypothesisId: "A"
196
+ })
197
+ }).catch(() => {
198
+ }), console.log("[useRegionSelection] Region updated - AI button position:", {
199
+ regionId: e == null ? void 0 : e.id,
200
+ aiButtonPosition: s,
201
+ rectCoords: (c = t.getCoords()) == null ? void 0 : c.map((r) => ({
202
+ x: r.x,
203
+ y: r.y
204
+ })),
205
+ canvasZoom: o.getZoom()
206
+ }), e && l && l(e);
105
207
  }
106
- }, O = () => {
107
- d(), e.renderAll(), o && o(null);
208
+ }, A = () => {
209
+ m(), o.renderAll(), l && l(null);
108
210
  };
109
- return e.on("selection:created", C), e.on("selection:updated", m), e.on("selection:cleared", O), () => {
110
- e.off("selection:created", C), e.off("selection:updated", m), e.off("selection:cleared", O);
211
+ return o.on("selection:created", R), o.on("selection:updated", I), o.on("selection:cleared", A), () => {
212
+ o.off("selection:created", R), o.off("selection:updated", I), o.off("selection:cleared", A);
111
213
  };
112
- }, [e, o, n, s, h, i]);
214
+ }, [o, l, h, g, O, y]);
113
215
  };
114
216
  export {
115
- b as useRegionSelection
217
+ G as useRegionSelection
116
218
  };