@glodon-aiot/dataset-annotation 3.14.0-alpha.31 → 3.15.0-alpha.1

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.
Files changed (114) hide show
  1. package/dist/es/DatasetContext/index.mjs +3 -6
  2. package/dist/es/components/DetectionAnnotation/components/ImageDetail/index.mjs +91 -94
  3. package/dist/es/components/DetectionAnnotation/components/LabelMaker/Drawable.mjs +28 -37
  4. package/dist/es/components/DetectionAnnotation/components/LabelMaker/RectLabel.mjs +101 -145
  5. package/dist/es/components/DetectionAnnotation/components/LabelMaker/index.mjs +195 -256
  6. package/dist/es/components/DetectionAnnotation/index.mjs +424 -456
  7. package/dist/es/components/Iconfont/index.mjs +2 -2
  8. package/dist/es/components/OcrAnnotation/MarkKVOCRModal/KVOCRLabelMaker/index.mjs +1 -1
  9. package/dist/es/components/OcrAnnotation/MarkOCRBoxModal/OCRBoxMaker/index.mjs +1 -1
  10. package/dist/es/components/OcrAnnotation/OcrModal/index.mjs +45 -43
  11. package/dist/es/components/PicZipImportModal/index.mjs +293 -308
  12. package/dist/es/components/PreLabelOCR/index.mjs +1 -1
  13. package/dist/es/constant.mjs +3 -3
  14. package/dist/es/featuresConfig.mjs +9 -13
  15. package/dist/es/index.mjs +7 -11
  16. package/dist/lib/index.js +3 -4
  17. package/dist/src/DatasetContext/index.d.ts +0 -2
  18. package/dist/src/components/DetectionAnnotation/components/ImageDetail/index.d.ts +0 -1
  19. package/dist/src/constant.d.ts +1 -1
  20. package/dist/src/featuresConfig.d.ts +0 -4
  21. package/dist/src/index.d.ts +0 -3
  22. package/package.json +2 -2
  23. package/dist/es/components/DetectionAnnotation/components/ImageModal/index.mjs +0 -129
  24. package/dist/es/components/DetectionAnnotation/components/ImageModal/style.less.mjs +0 -4
  25. package/dist/es/components/PicZipImportModal/config.mjs +0 -47
  26. package/dist/es/components/PicZipImportModal/pic_vlm_json_zip.svg.mjs +0 -4
  27. package/dist/es/components/PicZipImportModal/pic_vlm_zip.svg.mjs +0 -4
  28. package/dist/es/components/VLMAnnotation/RegionItem.mjs +0 -170
  29. package/dist/es/components/VLMAnnotation/TextAnnotationPanel.mjs +0 -94
  30. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasDrag.mjs +0 -116
  31. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasSetup.mjs +0 -115
  32. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasZoom.mjs +0 -42
  33. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCropRegionImage.mjs +0 -55
  34. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteControl.mjs +0 -51
  35. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteRegion.mjs +0 -62
  36. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDrawingMode.mjs +0 -377
  37. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRControl.mjs +0 -100
  38. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRLoadingIcon.mjs +0 -106
  39. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRRecognition.mjs +0 -101
  40. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionBoundaryCheck.mjs +0 -103
  41. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionHover.mjs +0 -38
  42. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionLoader.mjs +0 -173
  43. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionNameText.mjs +0 -72
  44. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionSelection.mjs +0 -116
  45. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionUpdate.mjs +0 -98
  46. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useTextLayouts.mjs +0 -156
  47. package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/ai.svg.mjs +0 -4
  48. package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/del.png.mjs +0 -4
  49. package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/error.svg.mjs +0 -4
  50. package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/loading.svg.mjs +0 -4
  51. package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/star.svg.mjs +0 -4
  52. package/dist/es/components/VLMAnnotation/VLMLabelMaker/index.mjs +0 -651
  53. package/dist/es/components/VLMAnnotation/VLMLabelMaker/style.less.mjs +0 -4
  54. package/dist/es/components/VLMAnnotation/VLMLabelMaker/utils/coordinateUtils.mjs +0 -33
  55. package/dist/es/components/VLMAnnotation/components/DragButton.mjs +0 -18
  56. package/dist/es/components/VLMAnnotation/components/FitToScreenButton.mjs +0 -16
  57. package/dist/es/components/VLMAnnotation/components/RectangleButton.mjs +0 -30
  58. package/dist/es/components/VLMAnnotation/components/Toolbar.mjs +0 -40
  59. package/dist/es/components/VLMAnnotation/components/ZoomControls.mjs +0 -44
  60. package/dist/es/components/VLMAnnotation/constants.mjs +0 -57
  61. package/dist/es/components/VLMAnnotation/index.mjs +0 -279
  62. package/dist/es/components/VLMAnnotation/style.less.mjs +0 -4
  63. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/AttributeDetail/index.mjs +0 -343
  64. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/AttributeDetail/style.less.mjs +0 -4
  65. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/QAGenerationConfig.mjs +0 -240
  66. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/index.mjs +0 -201
  67. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/style.less.mjs +0 -4
  68. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/index.mjs +0 -455
  69. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/style.less.mjs +0 -4
  70. package/dist/es/components/VLMAnnotationDetail/VlmModal/index.mjs +0 -149
  71. package/dist/es/components/VLMAnnotationDetail/VlmModal/style.less.mjs +0 -4
  72. package/dist/es/components/VLMAnnotationDetail/index.mjs +0 -449
  73. package/dist/es/components/VLMAnnotationDetail/style.less.mjs +0 -4
  74. package/dist/es/createVlmtasetAnnotation/index.mjs +0 -131
  75. package/dist/src/components/DetectionAnnotation/components/ImageModal/index.d.ts +0 -34
  76. package/dist/src/components/Iconfont/font_4439177_tgvowh6bmlb.d.ts +0 -0
  77. package/dist/src/components/PicZipImportModal/config.d.ts +0 -23
  78. package/dist/src/components/VLMAnnotation/ImageAnnotationDebugger.d.ts +0 -4
  79. package/dist/src/components/VLMAnnotation/RegionItem.d.ts +0 -4
  80. package/dist/src/components/VLMAnnotation/TextAnnotationPanel.d.ts +0 -4
  81. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasDrag.d.ts +0 -13
  82. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasSetup.d.ts +0 -38
  83. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasZoom.d.ts +0 -18
  84. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCropRegionImage.d.ts +0 -7
  85. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteControl.d.ts +0 -13
  86. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteRegion.d.ts +0 -22
  87. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDrawingMode.d.ts +0 -34
  88. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRControl.d.ts +0 -16
  89. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRLoadingIcon.d.ts +0 -11
  90. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRRecognition.d.ts +0 -29
  91. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionBoundaryCheck.d.ts +0 -31
  92. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionHover.d.ts +0 -13
  93. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionLoader.d.ts +0 -41
  94. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionNameText.d.ts +0 -12
  95. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionSelection.d.ts +0 -16
  96. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionUpdate.d.ts +0 -32
  97. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useTextLayouts.d.ts +0 -25
  98. package/dist/src/components/VLMAnnotation/VLMLabelMaker/index.d.ts +0 -4
  99. package/dist/src/components/VLMAnnotation/VLMLabelMaker/utils/coordinateUtils.d.ts +0 -32
  100. package/dist/src/components/VLMAnnotation/components/DragButton.d.ts +0 -7
  101. package/dist/src/components/VLMAnnotation/components/FitToScreenButton.d.ts +0 -6
  102. package/dist/src/components/VLMAnnotation/components/RectangleButton.d.ts +0 -7
  103. package/dist/src/components/VLMAnnotation/components/Toolbar.d.ts +0 -4
  104. package/dist/src/components/VLMAnnotation/components/ZoomControls.d.ts +0 -4
  105. package/dist/src/components/VLMAnnotation/constants.d.ts +0 -113
  106. package/dist/src/components/VLMAnnotation/index.d.ts +0 -6
  107. package/dist/src/components/VLMAnnotation/types.d.ts +0 -187
  108. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/AttributeDetail/index.d.ts +0 -14
  109. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/QAGenerationConfig.d.ts +0 -12
  110. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/index.d.ts +0 -12
  111. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/index.d.ts +0 -12
  112. package/dist/src/components/VLMAnnotationDetail/VlmModal/index.d.ts +0 -17
  113. package/dist/src/components/VLMAnnotationDetail/index.d.ts +0 -6
  114. package/dist/src/createVlmtasetAnnotation/index.d.ts +0 -16
@@ -1,101 +0,0 @@
1
- var F = (f, m, i) => new Promise((s, n) => {
2
- var S = (r) => {
3
- try {
4
- c(i.next(r));
5
- } catch (u) {
6
- n(u);
7
- }
8
- }, y = (r) => {
9
- try {
10
- c(i.throw(r));
11
- } catch (u) {
12
- n(u);
13
- }
14
- }, c = (r) => r.done ? s(r.value) : Promise.resolve(r.value).then(S, y);
15
- c((i = i.apply(f, m)).next());
16
- });
17
- import { useRef as k, useCallback as N } from "react";
18
- const H = ({
19
- ocrRecognize: f,
20
- onChange: m,
21
- updateTextLayers: i,
22
- canvas: s,
23
- rectMapRef: n,
24
- textLayersMapRef: S,
25
- textLayoutContentMapRef: y
26
- }) => {
27
- const c = k(/* @__PURE__ */ new Set()), r = k(/* @__PURE__ */ new Set()), u = k(/* @__PURE__ */ new Map()), v = N((e, o) => F(void 0, null, function* () {
28
- var t;
29
- if (o !== "create" && o !== "update" || !f || !e.image)
30
- return;
31
- const l = (t = Array.from(n.current.entries()).find(([, d]) => d.id === e.id)) == null ? void 0 : t[0];
32
- if (!l)
33
- return;
34
- const A = S.current.get(l);
35
- A && s && (A.forEach((d) => {
36
- d.off("mousedown"), d.off("mouseover"), d.off("mouseout"), y.current.delete(d), s.remove(d);
37
- }), S.current.delete(l), s.renderAll());
38
- const q = n.current.get(l);
39
- q && q.textLayouts && delete q.textLayouts;
40
- const a = (u.current.get(e.id) || 0) + 1;
41
- u.current.set(e.id, a), r.current.delete(e.id), c.current.add(e.id);
42
- try {
43
- const d = yield f(e.image);
44
- if (u.current.get(e.id) !== a)
45
- return;
46
- c.current.delete(e.id), r.current.delete(e.id);
47
- const E = n.current.get(l);
48
- if (E && u.current.get(e.id) === a && (E.textLayouts = d, i(l, E), m)) {
49
- const B = Array.from(n.current.values());
50
- m(B);
51
- }
52
- } catch (d) {
53
- if (u.current.get(e.id) !== a)
54
- return;
55
- c.current.delete(e.id), r.current.add(e.id), console.error("Failed to perform OCR recognition:", d);
56
- }
57
- }), [f, m, i, s, n, S, y]), x = N((e) => F(void 0, null, function* () {
58
- var a;
59
- if (!f || !e.image)
60
- return;
61
- const o = (a = Array.from(n.current.entries()).find(([, t]) => t.id === e.id)) == null ? void 0 : a[0];
62
- if (!o)
63
- return;
64
- const l = S.current.get(o);
65
- l && s && (l.forEach((t) => {
66
- t.off("mousedown"), t.off("mouseover"), t.off("mouseout"), y.current.delete(t), s.remove(t);
67
- }), S.current.delete(o), s.renderAll());
68
- const A = n.current.get(o);
69
- A && A.textLayouts && delete A.textLayouts;
70
- const q = (u.current.get(e.id) || 0) + 1;
71
- u.current.set(e.id, q), r.current.delete(e.id), c.current.add(e.id);
72
- try {
73
- const t = yield f(e.image);
74
- if (u.current.get(e.id) !== q)
75
- return;
76
- if (!t || !Array.isArray(t)) {
77
- c.current.delete(e.id), r.current.add(e.id), console.error("OCR returned invalid result:", t);
78
- return;
79
- }
80
- c.current.delete(e.id), r.current.delete(e.id);
81
- const w = n.current.get(o);
82
- if (w && u.current.get(e.id) === q && (w.textLayouts = t, i(o, w), m)) {
83
- const I = Array.from(n.current.values());
84
- m(I);
85
- }
86
- } catch (t) {
87
- if (u.current.get(e.id) !== q)
88
- return;
89
- c.current.delete(e.id), r.current.add(e.id), console.error("Failed to perform OCR recognition:", t);
90
- }
91
- }), [f, m, i, s, n, S, y]);
92
- return {
93
- performOCRIfNeeded: v,
94
- performOCR: x,
95
- ocrRecognizingRef: c,
96
- ocrErrorRef: r
97
- };
98
- };
99
- export {
100
- H as useOCRRecognition
101
- };
@@ -1,103 +0,0 @@
1
- import { useCallback as q, useEffect as D } from "react";
2
- const G = ({
3
- canvas: n,
4
- image: y,
5
- canvasToImageCoords: S,
6
- imageToCanvasCoords: b,
7
- bgImagePositionRef: k,
8
- bgImageSizeRef: A,
9
- regionNameTextMapRef: Y
10
- }) => {
11
- const O = q((h) => {
12
- if (!n || !y)
13
- return;
14
- const r = y.getElement();
15
- if (!(r != null && r.width) || !(r != null && r.height))
16
- return;
17
- const i = r.width, u = r.height, d = (w) => {
18
- const t = h, g = t.left || 0, p = t.top || 0, a = t.getScaledWidth(), m = t.getScaledHeight(), l = S(g, p);
19
- let e = l.x, o = l.y, c = a, s = m;
20
- const W = e, H = o;
21
- if (e < 0 && (e = 0), o < 0 && (o = 0), e + c > i && (e = i - c), o + s > u && (o = u - s), c <= 0 || s <= 0)
22
- return;
23
- const L = b(e, o);
24
- (e !== W || o !== H) && t.set({
25
- left: L.x,
26
- top: L.y
27
- });
28
- const Z = Y.current.get(t);
29
- if (Z) {
30
- const f = n.getZoom(), x = t.left || 0, X = t.top || 0;
31
- Z.set({
32
- left: x,
33
- top: X,
34
- scaleX: 1 / f,
35
- scaleY: 1 / f
36
- }), n.renderAll();
37
- }
38
- }, M = (w) => {
39
- const t = h, g = t.left || 0, p = t.top || 0, a = t.getScaledWidth(), m = t.getScaledHeight(), l = S(g, p);
40
- let e = l.x, o = l.y, c = a, s = m;
41
- e < 0 && (c = c + e, e = 0), o < 0 && (s = s + o, o = 0), e + c > i && (c = i - e), o + s > u && (s = u - o), c = Math.max(1, c), s = Math.max(1, s);
42
- const W = Math.abs(c - a) > 1e-3, H = Math.abs(s - m) > 1e-3, L = Math.abs(e - l.x) > 1e-3, Z = Math.abs(o - l.y) > 1e-3;
43
- if (W || H || L || Z) {
44
- const f = b(e, o), x = t.width || 1, X = t.height || 1, B = W ? Math.max(0.01, c / x) : t.scaleX || 1, U = H ? Math.max(0.01, s / X) : t.scaleY || 1;
45
- t.set({
46
- left: f.x,
47
- top: f.y,
48
- scaleX: B,
49
- scaleY: U
50
- });
51
- const C = Y.current.get(t);
52
- if (C) {
53
- const T = n.getZoom(), _ = t.left || 0, j = t.top || 0;
54
- C.set({
55
- left: _,
56
- top: j,
57
- scaleX: 1 / T,
58
- scaleY: 1 / T
59
- }), n.renderAll();
60
- }
61
- } else {
62
- const f = Y.current.get(t);
63
- if (f) {
64
- const x = n.getZoom(), X = t.left || 0, B = t.top || 0;
65
- f.set({
66
- left: X,
67
- top: B,
68
- scaleX: 1 / x,
69
- scaleY: 1 / x
70
- }), n.renderAll();
71
- }
72
- }
73
- };
74
- return h.on("moving", d), h.on("scaling", M), () => {
75
- h.off("moving", d), h.off("scaling", M);
76
- };
77
- }, [n, y, S, b, Y]);
78
- return D(() => {
79
- if (!n || !y)
80
- return;
81
- const h = (r) => {
82
- const i = n, u = i == null ? void 0 : i._currentTransform;
83
- if (!u)
84
- return;
85
- const d = u.action;
86
- if (!d || d !== "move" && !d.startsWith("scale"))
87
- return;
88
- const M = n.getPointer(r.e), w = M.x, t = M.y, g = k.current.left, p = k.current.top, a = g + A.current.width, m = p + A.current.height;
89
- if (w < g || w > a || t < p || t > m) {
90
- const e = i == null ? void 0 : i._onMouseUp;
91
- typeof e == "function" && e(r.e);
92
- }
93
- };
94
- return n.on("mouse:move", h), () => {
95
- n.off("mouse:move", h);
96
- };
97
- }, [n, y, k, A]), {
98
- setupBoundaryCheck: O
99
- };
100
- };
101
- export {
102
- G as useRegionBoundaryCheck
103
- };
@@ -1,38 +0,0 @@
1
- import { useEffect as m } from "react";
2
- import { fabric as R } from "fabric";
3
- import { HOVER_RECT_FILL_COLOR as L, TRANSPARENT_FILL as l } from "../../constants.mjs";
4
- const x = ({
5
- canvas: e,
6
- drawingMode: c,
7
- draggable: u,
8
- textLayersMapRef: n
9
- }) => {
10
- m(() => {
11
- if (!e || c || u)
12
- return;
13
- const f = () => {
14
- const o = /* @__PURE__ */ new Set();
15
- return n.current.forEach((t) => {
16
- t.forEach((r) => {
17
- o.add(r);
18
- });
19
- }), o;
20
- }, i = (o) => {
21
- const t = o.target;
22
- !t || !(t instanceof R.Rect) || f().has(t) || e.getActiveObject() === t || (t.set({
23
- fill: L
24
- }), e.renderAll());
25
- }, s = (o) => {
26
- const t = o.target;
27
- !t || !(t instanceof R.Rect) || f().has(t) || e.getActiveObject() === t || (t.set({
28
- fill: l
29
- }), e.renderAll());
30
- };
31
- return e.on("mouse:over", i), e.on("mouse:out", s), () => {
32
- e.off("mouse:over", i), e.off("mouse:out", s);
33
- };
34
- }, [e, c, u, n]);
35
- };
36
- export {
37
- x as useRegionHover
38
- };
@@ -1,173 +0,0 @@
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;
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,
17
- sample: t,
18
- image: n,
19
- bgImagePosition: Y,
20
- canvasInitializedRef: v,
21
- bgImagePositionRef: m,
22
- sampleRef: y,
23
- labelsLoadedRef: E,
24
- rectMapRef: u,
25
- textLayersMapRef: _,
26
- textLayoutContentMapRef: G,
27
- regionNameTextMapRef: x,
28
- ocrLoadingIconMapRef: F,
29
- imageToCanvasCoords: A,
30
- updateRegionShapeAndImage: k,
31
- createDeleteControl: W,
32
- createOCRControl: U,
33
- updateRegionNameText: Z,
34
- updateTextLayers: $,
35
- setupBoundaryCheck: K,
36
- cropRegionImage: N,
37
- onChange: w
38
- }) => {
39
- O(() => {
40
- if (!o || !(t != null && t.labels) || !n || !v.current || m.current.left === 0 && m.current.top === 0)
41
- return;
42
- y.current !== t ? (y.current = t, E.current = !1, u.current.forEach((i, s) => {
43
- const f = _.current.get(s);
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")
53
- return;
54
- const f = A(i.shape.x, i.shape.y), h = o.getZoom(), d = Q / h, e = new j.Rect({
55
- left: f.x,
56
- top: f.y,
57
- width: i.shape.width,
58
- height: i.shape.height,
59
- fill: q,
60
- // 无填充色
61
- stroke: J,
62
- strokeWidth: d,
63
- strokeUniform: !0,
64
- // 边框宽度不受缩放影响
65
- selectable: !0,
66
- evented: !0,
67
- hasRotatingPoint: !1,
68
- // 隐藏旋转点
69
- lockRotation: !0,
70
- // 锁定旋转
71
- lockUniScaling: !1,
72
- // 允许非等比缩放,控制点跟随鼠标
73
- lockScalingFlip: !0,
74
- // 禁止缩放时翻转
75
- objectCaching: !1,
76
- // 禁用缓存,避免缩放时边框变虚
77
- statefullCache: !1,
78
- noScaleCache: !1
79
- });
80
- e.on("modified", () => {
81
- k(e);
82
- }), e.on("moved", () => {
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
- }
93
- }
94
- }).catch((c) => {
95
- console.error("Failed to crop region image:", c);
96
- });
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))
99
- 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,
106
- // 无填充色
107
- stroke: J,
108
- strokeWidth: e,
109
- strokeUniform: !0,
110
- // 边框宽度不受缩放影响
111
- selectable: !0,
112
- evented: !0,
113
- hasRotatingPoint: !1,
114
- // 隐藏旋转点
115
- lockRotation: !0,
116
- // 锁定旋转
117
- lockUniScaling: !1,
118
- // 允许非等比缩放,控制点跟随鼠标
119
- lockScalingFlip: !0,
120
- // 禁止缩放时翻转
121
- objectCaching: !1,
122
- // 禁用缓存,避免缩放时边框变虚
123
- statefullCache: !1,
124
- noScaleCache: !1
125
- });
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) => {
133
- 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
- }
139
- }
140
- }).catch((l) => {
141
- console.error("Failed to crop region image:", l);
142
- });
143
- }), E.current = !0, o.renderAll());
144
- }, [
145
- o,
146
- t,
147
- t == null ? void 0 : t.labels,
148
- n,
149
- Y,
150
- N,
151
- w,
152
- // 添加 bgImagePosition 作为依赖,确保在位置设置后触发加载
153
- A,
154
- k,
155
- $,
156
- Z,
157
- W,
158
- U,
159
- v,
160
- m,
161
- y,
162
- E,
163
- u,
164
- _,
165
- G,
166
- x,
167
- F,
168
- K
169
- ]);
170
- };
171
- export {
172
- a as useRegionLoader
173
- };
@@ -1,72 +0,0 @@
1
- import { useRef as u, useCallback as N } from "react";
2
- import { fabric as T } from "fabric";
3
- import { DEFAULT_REGION_NAME as R, REGION_NAME_FONT_FAMILY as E, REGION_NAME_TEXT_COLOR as _, REGION_NAME_FONT_SIZE as x, REGION_NAME_PADDING as A } from "../../constants.mjs";
4
- const b = (o) => {
5
- const n = u(/* @__PURE__ */ new Map());
6
- return {
7
- updateRegionNameText: N((e, s) => {
8
- if (!o)
9
- return;
10
- const a = n.current.get(e);
11
- a && (o.remove(a), n.current.delete(e));
12
- const d = e.left || 0, m = e.top || 0;
13
- e.getScaledWidth(), e.getScaledHeight();
14
- const f = o.getZoom(), c = x, g = A, l = new T.Text(s.name || R, {
15
- left: d,
16
- // 与标注框左边对齐
17
- top: m,
18
- // 下边缘与标注框上边缘对齐(因为 originY 是 'bottom')
19
- fontSize: c,
20
- // 使用固定的基础字体大小
21
- fontFamily: E,
22
- fill: _,
23
- // 主题色文字
24
- textAlign: "left",
25
- originX: "left",
26
- originY: "bottom",
27
- // 从底部对齐,这样文本在rect上方
28
- selectable: !1,
29
- // 不可选中
30
- evented: !1,
31
- // 不接收事件,避免干扰rect的操作
32
- lockMovementX: !0,
33
- lockMovementY: !0,
34
- lockScalingX: !1,
35
- // 允许缩放,用于抵消画布缩放
36
- lockScalingY: !1,
37
- // 允许缩放,用于抵消画布缩放
38
- lockRotation: !0,
39
- hasControls: !1,
40
- hasBorders: !1,
41
- objectCaching: !1,
42
- statefullCache: !1,
43
- noScaleCache: !1,
44
- padding: g,
45
- // 使用固定的基础内边距
46
- scaleX: 1 / f,
47
- // 反向缩放,抵消画布缩放
48
- scaleY: 1 / f
49
- // 反向缩放,抵消画布缩放
50
- });
51
- o.add(l), n.current.set(e, l);
52
- const t = () => {
53
- const r = e.left || 0, p = e.top || 0, i = o.getZoom();
54
- l.set({
55
- left: r,
56
- // 与标注框左边对齐
57
- top: p,
58
- // 下边缘与标注框上边缘对齐(因为 originY 是 'bottom')
59
- scaleX: 1 / i,
60
- // 反向缩放,抵消画布缩放
61
- scaleY: 1 / i
62
- // 反向缩放,抵消画布缩放
63
- }), o.renderAll();
64
- };
65
- e.off("moving", t), e.off("moved", t), e.off("modified", t), e.on("moving", t), e.on("moved", t), e.on("modified", t);
66
- }, [o]),
67
- regionNameTextMapRef: n
68
- };
69
- };
70
- export {
71
- b as useRegionNameText
72
- };
@@ -1,116 +0,0 @@
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
11
- }) => {
12
- E(() => {
13
- if (!e)
14
- return;
15
- const f = () => {
16
- const t = /* @__PURE__ */ new Set();
17
- return h.current.forEach((r) => {
18
- r.forEach((l) => {
19
- t.add(l);
20
- });
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
27
- // 移除填充色
28
- });
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();
36
- return;
37
- }
38
- const l = e.getZoom(), u = R / l;
39
- t.set({
40
- hasRotatingPoint: !1,
41
- lockRotation: !0,
42
- lockUniScaling: !1,
43
- // 允许非等比缩放,控制点跟随鼠标
44
- fill: L,
45
- // 选中时添加填充色
46
- strokeUniform: !0,
47
- // 确保边框宽度不受缩放影响
48
- strokeWidth: u,
49
- // 确保边框宽度一致
50
- objectCaching: !1,
51
- // 禁用缓存,避免缩放时边框变虚
52
- statefullCache: !1,
53
- noScaleCache: !1,
54
- cornerStyle: "circle",
55
- // 设置控制点为圆形
56
- cornerColor: g,
57
- // 设置控制点为紫色(填充色)
58
- cornerSize: A,
59
- // 设置控制点大小(默认12,这里设置为6使其更小)
60
- transparentCorners: !1
61
- // 不透明,显示填充颜色
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);
65
- }
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();
72
- return;
73
- }
74
- const l = e.getZoom(), u = R / l;
75
- t.set({
76
- hasRotatingPoint: !1,
77
- lockRotation: !0,
78
- lockUniScaling: !1,
79
- // 允许非等比缩放,控制点跟随鼠标
80
- lockScalingFlip: !0,
81
- // 禁止缩放时翻转
82
- fill: L,
83
- // 选中时添加填充色
84
- strokeUniform: !0,
85
- // 确保边框宽度不受缩放影响
86
- strokeWidth: u,
87
- // 确保边框宽度一致
88
- objectCaching: !1,
89
- // 禁用缓存,避免缩放时边框变虚
90
- statefullCache: !1,
91
- noScaleCache: !1,
92
- cornerStyle: "circle",
93
- // 设置控制点为圆形
94
- cornerColor: g,
95
- // 设置控制点为紫色(填充色)
96
- cornerSize: A,
97
- // 设置控制点大小(默认12,这里设置为6使其更小)
98
- transparentCorners: !1
99
- // 不透明,显示填充颜色
100
- });
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);
105
- }
106
- }, O = () => {
107
- d(), e.renderAll(), o && o(null);
108
- };
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);
111
- };
112
- }, [e, o, n, s, h, i]);
113
- };
114
- export {
115
- b as useRegionSelection
116
- };