@glodon-aiot/dataset-annotation 3.14.0-alpha.33 → 3.15.0-alpha.2

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 (119) 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/useAIButtonHover.mjs +0 -193
  31. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasDrag.mjs +0 -116
  32. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasSetup.mjs +0 -115
  33. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasZoom.mjs +0 -42
  34. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCropRegionImage.mjs +0 -55
  35. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteControl.mjs +0 -51
  36. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteRegion.mjs +0 -62
  37. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDrawingMode.mjs +0 -484
  38. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRControl.mjs +0 -100
  39. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRLoadingIcon.mjs +0 -106
  40. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRRecognition.mjs +0 -101
  41. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionBoundaryCheck.mjs +0 -103
  42. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionHover.mjs +0 -38
  43. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionLoader.mjs +0 -173
  44. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionNameText.mjs +0 -72
  45. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionSelection.mjs +0 -218
  46. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionUpdate.mjs +0 -98
  47. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useTextLayouts.mjs +0 -156
  48. package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/ai.svg.mjs +0 -4
  49. package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/del.png.mjs +0 -4
  50. package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/error.svg.mjs +0 -4
  51. package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/loading.svg.mjs +0 -4
  52. package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/star.svg.mjs +0 -4
  53. package/dist/es/components/VLMAnnotation/VLMLabelMaker/index.mjs +0 -678
  54. package/dist/es/components/VLMAnnotation/VLMLabelMaker/style.less.mjs +0 -4
  55. package/dist/es/components/VLMAnnotation/VLMLabelMaker/utils/coordinateUtils.mjs +0 -33
  56. package/dist/es/components/VLMAnnotation/components/AIErrorTooltip/AIErrorTooltip.less.mjs +0 -4
  57. package/dist/es/components/VLMAnnotation/components/AIErrorTooltip/index.mjs +0 -24
  58. package/dist/es/components/VLMAnnotation/components/DragButton.mjs +0 -18
  59. package/dist/es/components/VLMAnnotation/components/FitToScreenButton.mjs +0 -16
  60. package/dist/es/components/VLMAnnotation/components/RectangleButton.mjs +0 -30
  61. package/dist/es/components/VLMAnnotation/components/Toolbar.mjs +0 -40
  62. package/dist/es/components/VLMAnnotation/components/ZoomControls.mjs +0 -44
  63. package/dist/es/components/VLMAnnotation/constants.mjs +0 -57
  64. package/dist/es/components/VLMAnnotation/index.mjs +0 -279
  65. package/dist/es/components/VLMAnnotation/style.less.mjs +0 -4
  66. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/AttributeDetail/index.mjs +0 -343
  67. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/AttributeDetail/style.less.mjs +0 -4
  68. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/QAGenerationConfig.mjs +0 -240
  69. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/index.mjs +0 -201
  70. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/style.less.mjs +0 -4
  71. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/index.mjs +0 -455
  72. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/style.less.mjs +0 -4
  73. package/dist/es/components/VLMAnnotationDetail/VlmModal/index.mjs +0 -149
  74. package/dist/es/components/VLMAnnotationDetail/VlmModal/style.less.mjs +0 -4
  75. package/dist/es/components/VLMAnnotationDetail/index.mjs +0 -449
  76. package/dist/es/components/VLMAnnotationDetail/style.less.mjs +0 -4
  77. package/dist/es/createVlmtasetAnnotation/index.mjs +0 -131
  78. package/dist/src/components/DetectionAnnotation/components/ImageModal/index.d.ts +0 -34
  79. package/dist/src/components/Iconfont/font_4439177_tgvowh6bmlb.d.ts +0 -0
  80. package/dist/src/components/PicZipImportModal/config.d.ts +0 -23
  81. package/dist/src/components/VLMAnnotation/ImageAnnotationDebugger.d.ts +0 -4
  82. package/dist/src/components/VLMAnnotation/RegionItem.d.ts +0 -4
  83. package/dist/src/components/VLMAnnotation/TextAnnotationPanel.d.ts +0 -4
  84. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useAIButtonHover.d.ts +0 -16
  85. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasDrag.d.ts +0 -13
  86. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasSetup.d.ts +0 -38
  87. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasZoom.d.ts +0 -18
  88. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCropRegionImage.d.ts +0 -7
  89. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteControl.d.ts +0 -13
  90. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteRegion.d.ts +0 -22
  91. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDrawingMode.d.ts +0 -35
  92. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRControl.d.ts +0 -16
  93. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRLoadingIcon.d.ts +0 -11
  94. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRRecognition.d.ts +0 -29
  95. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionBoundaryCheck.d.ts +0 -31
  96. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionHover.d.ts +0 -13
  97. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionLoader.d.ts +0 -41
  98. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionNameText.d.ts +0 -12
  99. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionSelection.d.ts +0 -16
  100. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionUpdate.d.ts +0 -32
  101. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useTextLayouts.d.ts +0 -25
  102. package/dist/src/components/VLMAnnotation/VLMLabelMaker/index.d.ts +0 -4
  103. package/dist/src/components/VLMAnnotation/VLMLabelMaker/utils/coordinateUtils.d.ts +0 -32
  104. package/dist/src/components/VLMAnnotation/components/AIErrorTooltip/index.d.ts +0 -8
  105. package/dist/src/components/VLMAnnotation/components/DragButton.d.ts +0 -7
  106. package/dist/src/components/VLMAnnotation/components/FitToScreenButton.d.ts +0 -6
  107. package/dist/src/components/VLMAnnotation/components/RectangleButton.d.ts +0 -7
  108. package/dist/src/components/VLMAnnotation/components/Toolbar.d.ts +0 -4
  109. package/dist/src/components/VLMAnnotation/components/ZoomControls.d.ts +0 -4
  110. package/dist/src/components/VLMAnnotation/constants.d.ts +0 -113
  111. package/dist/src/components/VLMAnnotation/index.d.ts +0 -6
  112. package/dist/src/components/VLMAnnotation/types.d.ts +0 -187
  113. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/AttributeDetail/index.d.ts +0 -14
  114. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/QAGenerationConfig.d.ts +0 -12
  115. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/index.d.ts +0 -12
  116. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/index.d.ts +0 -12
  117. package/dist/src/components/VLMAnnotationDetail/VlmModal/index.d.ts +0 -17
  118. package/dist/src/components/VLMAnnotationDetail/index.d.ts +0 -6
  119. package/dist/src/createVlmtasetAnnotation/index.d.ts +0 -16
@@ -1,100 +0,0 @@
1
- import { useRef as a, useEffect as X, useCallback as H } from "react";
2
- import { fabric as Y } from "fabric";
3
- import { AI_CONTROL_OFFSET_X as P, AI_CONTROL_OFFSET_Y as U, AI_ICON_SIZE as y } from "../../constants.mjs";
4
- import W from "../icons/ai.svg.mjs";
5
- import Z from "../icons/star.svg.mjs";
6
- import B from "../icons/error.svg.mjs";
7
- import G from "../icons/loading.svg.mjs";
8
- const nr = ({
9
- performOCR: O,
10
- ocrRecognizingRef: s,
11
- ocrErrorRef: S,
12
- rectMapRef: w
13
- }) => {
14
- const f = (r) => !(!r.complete || r.naturalWidth === 0), g = a(null), A = a(null), v = a(null), h = a(null), d = a(/* @__PURE__ */ new Set()), t = a(null), C = a(null);
15
- return X(() => {
16
- if (!g.current) {
17
- const r = document.createElement("img");
18
- r.src = W, g.current = r;
19
- }
20
- if (!A.current) {
21
- const r = document.createElement("img");
22
- r.src = Z, A.current = r;
23
- }
24
- if (!v.current) {
25
- const r = document.createElement("img");
26
- r.src = B, v.current = r;
27
- }
28
- if (!h.current) {
29
- const r = document.createElement("img");
30
- r.src = G, h.current = r;
31
- }
32
- }, []), X(() => {
33
- const r = () => {
34
- s.current.size > 0 ? (d.current.forEach((o) => {
35
- o.renderAll();
36
- }), t.current = requestAnimationFrame(r)) : t.current = null;
37
- };
38
- C.current = r, s.current.size > 0 && (t.current = requestAnimationFrame(r));
39
- const m = setInterval(() => {
40
- const c = s.current.size > 0, o = t.current !== null;
41
- c && !o && (t.current = requestAnimationFrame(r));
42
- }, 100);
43
- return () => {
44
- t.current !== null && cancelAnimationFrame(t.current), clearInterval(m);
45
- };
46
- }, [s]), {
47
- createOCRControl: H(() => {
48
- const r = y, l = g.current, m = A.current, c = v.current, o = h.current, n = 14, N = (e, p, F, M, I) => {
49
- if (!l)
50
- return;
51
- const D = I, _ = w.current.get(D);
52
- if (!_)
53
- return;
54
- const z = _.id, T = s.current.has(z), k = S.current.has(z), q = () => {
55
- e.save(), e.translate(p, F), e.rotate(Y.util.degreesToRadians(I.angle || 0)), e.drawImage(l, -r / 2, -r / 2, r, r);
56
- const u = r / 2 - n / 2 + 8, E = -r / 2 + n / 2 - 8;
57
- if (T) {
58
- if (o && f(o)) {
59
- e.save(), e.translate(u, E);
60
- const L = Date.now() / 500 % (Math.PI * 2);
61
- e.rotate(L), e.drawImage(o, -n / 2, -n / 2, n, n), e.restore();
62
- }
63
- const i = I.canvas;
64
- i && (d.current.has(i), d.current.add(i), s.current.size > 0 && !t.current && C.current && (t.current = requestAnimationFrame(C.current)));
65
- } else {
66
- const i = I.canvas;
67
- i && s.current.size === 0 && d.current.delete(i), k && c && f(c) ? e.drawImage(c, u - n / 2, E - n / 2, n, n) : !T && !k && m && f(m) && e.drawImage(m, u - n / 2, E - n / 2, n, n);
68
- }
69
- e.restore();
70
- };
71
- f(l) ? q() : l.onload = () => {
72
- q();
73
- const u = I.canvas;
74
- u && u.renderAll();
75
- };
76
- }, R = (e, p) => {
77
- const F = p.target;
78
- return O(F), !1;
79
- };
80
- return new Y.Control({
81
- x: 0.5,
82
- // 右侧(0 = 左边,0.5 = 中间,1 = 右边)
83
- y: -0.5,
84
- // 顶部(0 = 顶部,0.5 = 中间,1 = 底部)
85
- offsetX: P,
86
- // 与删除按钮相同的X偏移
87
- offsetY: U + y + 4,
88
- // 向下偏移,放在删除按钮下方(删除按钮的offsetY + 删除按钮大小 + 间距)
89
- cursorStyle: "pointer",
90
- mouseUpHandler: R,
91
- render: N,
92
- sizeX: r,
93
- sizeY: r
94
- });
95
- }, [O, s, S, w])
96
- };
97
- };
98
- export {
99
- nr as useOCRControl
100
- };
@@ -1,106 +0,0 @@
1
- import { useRef as h, useCallback as W, useEffect as X } from "react";
2
- import { fabric as l } from "fabric";
3
- import { OCR_SCAN_LINE_GLOW_MULTIPLIER as Y, OCR_SCAN_LINE_GLOW_COLOR as k, OCR_SCAN_LINE_BRIGHT_COLOR as G, OCR_SCAN_LINE_CORE_POSITION_MULTIPLIER as P, OCR_SCAN_LINE_CORE_HEIGHT_MULTIPLIER as Z, OCR_SCAN_LINE_CORE_COLOR as j, OCR_SCAN_LINE_BASE_HEIGHT as B, OCR_SCAN_ANIMATION_SPEED as F } from "../../constants.mjs";
4
- const v = (t) => {
5
- const o = h(/* @__PURE__ */ new Map()), c = h(null), L = W((e, U, C) => {
6
- if (!t)
7
- return;
8
- const _ = o.current.get(e);
9
- if (_ && (t.remove(_), o.current.delete(e)), !C)
10
- return;
11
- const s = t.getZoom(), O = e.left || 0, p = e.top || 0, I = e.getScaledWidth();
12
- e.getScaledHeight();
13
- const i = B, a = I * s, m = new l.Rect({
14
- left: 0,
15
- top: 0,
16
- width: a,
17
- height: i * Y,
18
- // 光晕层更宽
19
- fill: k,
20
- // 紫色光晕
21
- selectable: !1,
22
- evented: !1,
23
- originX: "left",
24
- originY: "top"
25
- }), E = new l.Rect({
26
- left: 0,
27
- top: i,
28
- width: a,
29
- height: i,
30
- fill: G,
31
- // 紫色较亮层
32
- selectable: !1,
33
- evented: !1,
34
- originX: "left",
35
- originY: "top"
36
- }), S = new l.Rect({
37
- left: 0,
38
- top: i * P,
39
- width: a,
40
- height: i * Z,
41
- fill: j,
42
- // 紫色核心线条
43
- selectable: !1,
44
- evented: !1,
45
- originX: "left",
46
- originY: "top"
47
- }), r = new l.Group([m, E, S], {
48
- left: O,
49
- top: p,
50
- // 初始位置在顶部
51
- originX: "left",
52
- originY: "top",
53
- selectable: !1,
54
- evented: !1,
55
- lockMovementX: !0,
56
- lockMovementY: !0,
57
- lockScalingX: !1,
58
- lockScalingY: !1,
59
- lockRotation: !0,
60
- hasControls: !1,
61
- hasBorders: !1,
62
- objectCaching: !1,
63
- statefullCache: !1,
64
- noScaleCache: !1,
65
- scaleX: 1 / s,
66
- // 反向缩放,抵消画布缩放,保持固定视觉粗细
67
- scaleY: 1 / s
68
- // 反向缩放,抵消画布缩放,保持固定视觉粗细
69
- });
70
- t.add(r), o.current.set(e, r);
71
- let n = 0, f = 1;
72
- const N = F, d = () => {
73
- if (!o.current.has(e) || !t)
74
- return;
75
- const A = e.left || 0, b = e.top || 0, H = e.getScaledWidth(), T = e.getScaledHeight(), g = t.getZoom();
76
- n += N * f, n >= 1 ? (n = 1, f = -1) : n <= 0 && (n = 0, f = 1);
77
- const w = b + n * T;
78
- r.set({
79
- left: A,
80
- top: w,
81
- scaleX: 1 / g,
82
- // 反向缩放,抵消画布缩放,保持固定视觉粗细
83
- scaleY: 1 / g
84
- // 反向缩放,抵消画布缩放,保持固定视觉粗细
85
- });
86
- const u = r.getObjects();
87
- if (u && u.length > 0) {
88
- const M = H * g;
89
- u.forEach((R) => {
90
- R instanceof l.Rect && R.set("width", M);
91
- });
92
- }
93
- t.renderAll(), c.current = requestAnimationFrame(d);
94
- };
95
- d();
96
- }, [t]);
97
- return X(() => () => {
98
- c.current !== null && (cancelAnimationFrame(c.current), c.current = null);
99
- }, []), {
100
- updateOCRLoadingIcon: L,
101
- ocrLoadingIconMapRef: o
102
- };
103
- };
104
- export {
105
- v as useOCRLoadingIcon
106
- };
@@ -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
- };