@glodon-aiot/dataset-annotation 3.17.0-alpha.4 → 3.17.0-beta.6

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,64 +1,64 @@
1
- var B = Object.defineProperty;
2
- var H = Object.getOwnPropertySymbols;
3
- var C = Object.prototype.hasOwnProperty, D = Object.prototype.propertyIsEnumerable;
4
- var X = (o, t, n) => t in o ? B(o, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : o[t] = n, P = (o, t) => {
5
- for (var n in t || (t = {}))
6
- C.call(t, n) && X(o, n, t[n]);
7
- if (H)
8
- for (var n of H(t))
9
- D.call(t, n) && X(o, n, t[n]);
10
- return o;
1
+ var Y = Object.defineProperty;
2
+ var G = Object.getOwnPropertySymbols;
3
+ var v = Object.prototype.hasOwnProperty, z = Object.prototype.propertyIsEnumerable;
4
+ var H = (r, t, i) => t in r ? Y(r, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : r[t] = i, C = (r, t) => {
5
+ for (var i in t || (t = {}))
6
+ v.call(t, i) && H(r, i, t[i]);
7
+ if (G)
8
+ for (var i of G(t))
9
+ z.call(t, i) && H(r, i, t[i]);
10
+ return r;
11
11
  };
12
- import { useEffect as O } from "react";
13
- import { fabric as j } from "fabric";
14
- import { TRANSPARENT_FILL as q, RECT_STROKE_COLOR as J, BASE_STROKE_WIDTH as Q, REGION_NAME_PREFIX as V } from "../../constants.mjs";
15
- const a = ({
16
- canvas: o,
12
+ import { useEffect as B } from "react";
13
+ import { fabric as X } from "fabric";
14
+ import { TRANSPARENT_FILL as g, RECT_STROKE_COLOR as j, BASE_STROKE_WIDTH as q, REGION_NAME_PREFIX as J } from "../../constants.mjs";
15
+ const I = ({
16
+ canvas: r,
17
17
  sample: t,
18
- image: n,
19
- bgImagePosition: Y,
20
- canvasInitializedRef: v,
21
- bgImagePositionRef: m,
22
- sampleRef: y,
18
+ image: i,
19
+ bgImagePosition: Q,
20
+ canvasInitializedRef: K,
21
+ bgImagePositionRef: w,
22
+ sampleRef: S,
23
23
  labelsLoadedRef: E,
24
- rectMapRef: u,
25
- textLayersMapRef: _,
26
- textLayoutContentMapRef: G,
27
- regionNameTextMapRef: x,
28
- ocrLoadingIconMapRef: F,
29
- imageToCanvasCoords: A,
24
+ rectMapRef: s,
25
+ textLayersMapRef: m,
26
+ textLayoutContentMapRef: N,
27
+ regionNameTextMapRef: y,
28
+ ocrLoadingIconMapRef: _,
29
+ imageToCanvasCoords: x,
30
30
  updateRegionShapeAndImage: k,
31
- createDeleteControl: W,
32
- createOCRControl: U,
33
- updateRegionNameText: Z,
34
- updateTextLayers: $,
35
- setupBoundaryCheck: K,
36
- cropRegionImage: N,
37
- onChange: w
31
+ createDeleteControl: F,
32
+ createOCRControl: W,
33
+ updateRegionNameText: U,
34
+ updateTextLayers: Z,
35
+ setupBoundaryCheck: $,
36
+ cropRegionImage: A,
37
+ onChange: V
38
38
  }) => {
39
- O(() => {
40
- if (!o || !(t != null && t.labels) || !n || !v.current || m.current.left === 0 && m.current.top === 0)
39
+ B(() => {
40
+ if (!r || !(t != null && t.labels) || !i || !K.current || w.current.left === 0 && w.current.top === 0)
41
41
  return;
42
- y.current !== t ? (y.current = t, E.current = !1, u.current.forEach((i, s) => {
43
- const f = _.current.get(s);
42
+ S.current !== t ? (S.current = t, E.current = !1, s.current.forEach((n, c) => {
43
+ const f = m.current.get(c);
44
44
  f && (f.forEach((e) => {
45
- e.off("mousedown"), e.off("mouseover"), e.off("mouseout"), G.current.delete(e), o.remove(e);
46
- }), _.current.delete(s));
47
- const h = x.current.get(s);
48
- h && (s.off("moved"), s.off("modified"), o.remove(h), x.current.delete(s));
49
- const d = F.current.get(s);
50
- d && (o.remove(d), F.current.delete(s)), o.remove(s);
51
- }), u.current.clear(), t.labels.forEach((i, s) => {
52
- if (i.shape.name !== "rect")
45
+ e.off("mousedown"), e.off("mouseover"), e.off("mouseout"), N.current.delete(e), r.remove(e);
46
+ }), m.current.delete(c));
47
+ const u = y.current.get(c);
48
+ u && (c.off("moved"), c.off("modified"), r.remove(u), y.current.delete(c));
49
+ const d = _.current.get(c);
50
+ d && (r.remove(d), _.current.delete(c)), r.remove(c);
51
+ }), s.current.clear(), t.labels.forEach((n, c) => {
52
+ if (n.shape.name !== "rect")
53
53
  return;
54
- const f = A(i.shape.x, i.shape.y), h = o.getZoom(), d = Q / h, e = new j.Rect({
54
+ const f = x(n.shape.x, n.shape.y), u = r.getZoom(), d = q / u, e = new X.Rect({
55
55
  left: f.x,
56
56
  top: f.y,
57
- width: i.shape.width,
58
- height: i.shape.height,
59
- fill: q,
57
+ width: n.shape.width,
58
+ height: n.shape.height,
59
+ fill: g,
60
60
  // 无填充色
61
- stroke: J,
61
+ stroke: j,
62
62
  strokeWidth: d,
63
63
  strokeUniform: !0,
64
64
  // 边框宽度不受缩放影响
@@ -81,30 +81,27 @@ const a = ({
81
81
  k(e);
82
82
  }), e.on("moved", () => {
83
83
  k(e);
84
- }), o.add(e), K(e), e.controls.deleteControl = W(), e.controls.ocrControl = U();
85
- const r = P({}, i);
86
- r.name || (r.name = `${V}${s + 1}`), u.current.set(e, r), Z(e, r), r.textLayouts && r.textLayouts.length > 0 && $(e, r), r.image || N(r).then((c) => {
87
- if (c) {
88
- const l = u.current.get(e);
89
- if (l && (l.image = c, w)) {
90
- const S = Array.from(u.current.values());
91
- w(S);
92
- }
84
+ }), r.add(e), $(e), e.controls.deleteControl = F(), e.controls.ocrControl = W();
85
+ const o = C({}, n);
86
+ o.name || (o.name = `${J}${c + 1}`), s.current.set(e, o), U(e, o), o.textLayouts && o.textLayouts.length > 0 && Z(e, o), o.image || A(o).then((h) => {
87
+ if (h) {
88
+ const l = s.current.get(e);
89
+ l && (l.image = h);
93
90
  }
94
- }).catch((c) => {
95
- console.error("Failed to crop region image:", c);
91
+ }).catch((h) => {
92
+ console.error("Failed to crop region image:", h);
96
93
  });
97
- }), E.current = !0, o.renderAll()) : !E.current && t.labels.length > 0 && (t.labels.forEach((i, s) => {
98
- if (i.shape.name !== "rect" || Array.from(u.current.values()).find((l) => l.shape.x === i.shape.x && l.shape.y === i.shape.y && l.shape.width === i.shape.width && l.shape.height === i.shape.height))
94
+ }), E.current = !0, r.renderAll()) : !E.current && t.labels.length > 0 && (t.labels.forEach((n, c) => {
95
+ if (n.shape.name !== "rect" || Array.from(s.current.values()).find((l) => l.shape.x === n.shape.x && l.shape.y === n.shape.y && l.shape.width === n.shape.width && l.shape.height === n.shape.height))
99
96
  return;
100
- const h = A(i.shape.x, i.shape.y), d = o.getZoom(), e = Q / d, r = new j.Rect({
101
- left: h.x,
102
- top: h.y,
103
- width: i.shape.width,
104
- height: i.shape.height,
105
- fill: q,
97
+ const u = x(n.shape.x, n.shape.y), d = r.getZoom(), e = q / d, o = new X.Rect({
98
+ left: u.x,
99
+ top: u.y,
100
+ width: n.shape.width,
101
+ height: n.shape.height,
102
+ fill: g,
106
103
  // 无填充色
107
- stroke: J,
104
+ stroke: j,
108
105
  strokeWidth: e,
109
106
  strokeUniform: !0,
110
107
  // 边框宽度不受缩放影响
@@ -123,51 +120,48 @@ const a = ({
123
120
  statefullCache: !1,
124
121
  noScaleCache: !1
125
122
  });
126
- r.on("modified", () => {
127
- k(r);
128
- }), r.on("moved", () => {
129
- k(r);
130
- }), o.add(r), K(r), r.controls.deleteControl = W(), r.controls.ocrControl = U();
131
- const c = P({}, i);
132
- c.name || (c.name = `${V}${s + 1}`), u.current.set(r, c), Z(r, c), c.textLayouts && c.textLayouts.length > 0 && $(r, c), c.image || N(c).then((l) => {
123
+ o.on("modified", () => {
124
+ k(o);
125
+ }), o.on("moved", () => {
126
+ k(o);
127
+ }), r.add(o), $(o), o.controls.deleteControl = F(), o.controls.ocrControl = W();
128
+ const h = C({}, n);
129
+ h.name || (h.name = `${J}${c + 1}`), s.current.set(o, h), U(o, h), h.textLayouts && h.textLayouts.length > 0 && Z(o, h), h.image || A(h).then((l) => {
133
130
  if (l) {
134
- const S = u.current.get(r);
135
- if (S && (S.image = l, w)) {
136
- const z = Array.from(u.current.values());
137
- w(z);
138
- }
131
+ const P = s.current.get(o);
132
+ P && (P.image = l);
139
133
  }
140
134
  }).catch((l) => {
141
135
  console.error("Failed to crop region image:", l);
142
136
  });
143
- }), E.current = !0, o.renderAll());
137
+ }), E.current = !0, r.renderAll());
144
138
  }, [
145
- o,
139
+ r,
146
140
  t,
147
141
  t == null ? void 0 : t.labels,
148
- n,
149
- Y,
150
- N,
151
- w,
152
- // 添加 bgImagePosition 作为依赖,确保在位置设置后触发加载
142
+ i,
143
+ Q,
153
144
  A,
145
+ V,
146
+ // 添加 bgImagePosition 作为依赖,确保在位置设置后触发加载
147
+ x,
154
148
  k,
155
- $,
156
149
  Z,
157
- W,
158
150
  U,
159
- v,
151
+ F,
152
+ W,
153
+ K,
154
+ w,
155
+ S,
156
+ E,
157
+ s,
160
158
  m,
159
+ N,
161
160
  y,
162
- E,
163
- u,
164
161
  _,
165
- G,
166
- x,
167
- F,
168
- K
162
+ $
169
163
  ]);
170
164
  };
171
165
  export {
172
- a as useRegionLoader
166
+ I as useRegionLoader
173
167
  };
@@ -1,90 +1,53 @@
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
1
+ import { useEffect as A } from "react";
2
+ import { fabric as a } from "fabric";
3
+ import { SELECTED_RECT_FILL_COLOR as L, RECT_STROKE_COLOR as T, CONTROL_POINT_COLOR as R, CONTROL_POINT_SIZE as E, TRANSPARENT_FILL as k, BASE_STROKE_WIDTH as g } from "../../constants.mjs";
4
+ const x = ({
5
+ canvas: e,
6
+ onRegionSelect: o,
7
+ createDeleteControl: n,
8
+ createOCRControl: s,
9
+ textLayersMapRef: C,
10
+ rectMapRef: i
11
11
  }) => {
12
- W(() => {
13
- if (!o)
12
+ A(() => {
13
+ if (!e)
14
14
  return;
15
- const C = () => {
15
+ const f = () => {
16
16
  const t = /* @__PURE__ */ new Set();
17
- return O.current.forEach((n) => {
18
- n.forEach((c) => {
19
- t.add(c);
17
+ return C.current.forEach((r) => {
18
+ r.forEach((l) => {
19
+ t.add(l);
20
20
  });
21
21
  }), t;
22
- }, m = () => {
23
- const t = C();
24
- o.getObjects().forEach((n) => {
25
- n instanceof f.Rect && !t.has(n) && n.set({
26
- fill: Y
22
+ }, d = () => {
23
+ const t = f();
24
+ e.getObjects().forEach((r) => {
25
+ r instanceof a.Rect && !t.has(r) && r.set({
26
+ fill: k
27
27
  // 移除填充色
28
28
  });
29
29
  });
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();
30
+ }, h = () => {
31
+ d();
32
+ const t = e.getActiveObject();
33
+ if (t && t instanceof a.Rect) {
34
+ if (f().has(t)) {
35
+ e.discardActiveObject(), e.renderAll();
73
36
  return;
74
37
  }
75
- const a = o.getZoom(), i = F / a;
38
+ const l = e.getZoom(), u = g / l;
76
39
  t.set({
77
40
  hasRotatingPoint: !1,
78
41
  lockRotation: !0,
79
42
  lockUniScaling: !1,
80
43
  // 允许非等比缩放,控制点跟随鼠标
81
- fill: k,
44
+ fill: L,
82
45
  // 选中时添加填充色
83
- stroke: X,
46
+ stroke: T,
84
47
  // 选中时取消高亮,使用普通边框颜色
85
48
  strokeUniform: !0,
86
49
  // 确保边框宽度不受缩放影响
87
- strokeWidth: i,
50
+ strokeWidth: u,
88
51
  // 确保边框宽度一致
89
52
  objectCaching: !1,
90
53
  // 禁用缓存,避免缩放时边框变虚
@@ -92,57 +55,25 @@ const G = ({
92
55
  noScaleCache: !1,
93
56
  cornerStyle: "circle",
94
57
  // 设置控制点为圆形
95
- cornerColor: j,
58
+ cornerColor: R,
96
59
  // 设置控制点为紫色(填充色)
97
- cornerSize: N,
60
+ cornerSize: E,
98
61
  // 设置控制点大小(默认12,这里设置为6使其更小)
99
62
  transparentCorners: !1
100
63
  // 不透明,显示填充颜色
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);
64
+ }), 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();
65
+ const c = i.current.get(t);
66
+ c && o && o(c);
135
67
  }
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();
68
+ }, O = () => {
69
+ d();
70
+ const t = e.getActiveObject();
71
+ if (t && t instanceof a.Rect) {
72
+ if (f().has(t)) {
73
+ e.discardActiveObject(), e.renderAll();
143
74
  return;
144
75
  }
145
- const a = o.getZoom(), i = F / a;
76
+ const l = e.getZoom(), u = g / l;
146
77
  t.set({
147
78
  hasRotatingPoint: !1,
148
79
  lockRotation: !0,
@@ -150,11 +81,11 @@ const G = ({
150
81
  // 允许非等比缩放,控制点跟随鼠标
151
82
  lockScalingFlip: !0,
152
83
  // 禁止缩放时翻转
153
- fill: k,
84
+ fill: L,
154
85
  // 选中时添加填充色
155
86
  strokeUniform: !0,
156
87
  // 确保边框宽度不受缩放影响
157
- strokeWidth: i,
88
+ strokeWidth: u,
158
89
  // 确保边框宽度一致
159
90
  objectCaching: !1,
160
91
  // 禁用缓存,避免缩放时边框变虚
@@ -162,57 +93,26 @@ const G = ({
162
93
  noScaleCache: !1,
163
94
  cornerStyle: "circle",
164
95
  // 设置控制点为圆形
165
- cornerColor: j,
96
+ cornerColor: R,
166
97
  // 设置控制点为紫色(填充色)
167
- cornerSize: N,
98
+ cornerSize: E,
168
99
  // 设置控制点大小(默认12,这里设置为6使其更小)
169
100
  transparentCorners: !1
170
101
  // 不透明,显示填充颜色
171
102
  });
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);
103
+ const c = t;
104
+ 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();
105
+ const S = i.current.get(t);
106
+ S && o && o(S);
207
107
  }
208
- }, A = () => {
209
- m(), o.renderAll(), l && l(null);
108
+ }, m = () => {
109
+ d(), e.renderAll(), o && o(null);
210
110
  };
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
+ return e.on("selection:created", h), e.on("selection:updated", O), e.on("selection:cleared", m), () => {
112
+ e.off("selection:created", h), e.off("selection:updated", O), e.off("selection:cleared", m);
213
113
  };
214
- }, [o, l, h, g, O, y]);
114
+ }, [e, o, n, s, C, i]);
215
115
  };
216
116
  export {
217
- G as useRegionSelection
117
+ x as useRegionSelection
218
118
  };