@glodon-aiot/dataset-annotation 3.11.1-shapshot.1765331459 → 3.13.0-alpha.27

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 (118) hide show
  1. package/dist/es/DatasetContext/index.mjs +6 -3
  2. package/dist/es/components/DetectionAnnotation/components/ImageDetail/index.mjs +94 -91
  3. package/dist/es/components/DetectionAnnotation/components/ImageModal/index.mjs +129 -0
  4. package/dist/es/components/DetectionAnnotation/components/ImageModal/style.less.mjs +4 -0
  5. package/dist/es/components/DetectionAnnotation/components/LabelMaker/Drawable.mjs +37 -28
  6. package/dist/es/components/DetectionAnnotation/components/LabelMaker/RectLabel.mjs +136 -108
  7. package/dist/es/components/DetectionAnnotation/components/LabelMaker/index.mjs +197 -162
  8. package/dist/es/components/DetectionAnnotation/index.mjs +460 -434
  9. package/dist/es/components/Iconfont/index.mjs +2 -2
  10. package/dist/es/components/OcrAnnotation/MarkKVOCRModal/KVOCRLabelMaker/index.mjs +1 -1
  11. package/dist/es/components/OcrAnnotation/MarkOCRBoxModal/OCRBoxMaker/index.mjs +1 -1
  12. package/dist/es/components/OcrAnnotation/OcrModal/index.mjs +43 -45
  13. package/dist/es/components/PicZipImportModal/config.mjs +47 -0
  14. package/dist/es/components/PicZipImportModal/index.mjs +308 -293
  15. package/dist/es/components/PicZipImportModal/pic_vlm_json_zip.svg.mjs +4 -0
  16. package/dist/es/components/PicZipImportModal/pic_vlm_zip.svg.mjs +4 -0
  17. package/dist/es/components/PreLabelOCR/index.mjs +1 -1
  18. package/dist/es/components/VLMAnnotation/RegionItem.mjs +94 -0
  19. package/dist/es/components/VLMAnnotation/TextAnnotationPanel.mjs +83 -0
  20. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasDrag.mjs +116 -0
  21. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasSetup.mjs +115 -0
  22. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasZoom.mjs +42 -0
  23. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCropRegionImage.mjs +55 -0
  24. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteControl.mjs +51 -0
  25. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteRegion.mjs +47 -0
  26. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDrawingMode.mjs +248 -0
  27. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRLoadingIcon.mjs +106 -0
  28. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRRecognition.mjs +68 -0
  29. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionHover.mjs +38 -0
  30. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionLoader.mjs +141 -0
  31. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionNameText.mjs +72 -0
  32. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionSelection.mjs +113 -0
  33. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionUpdate.mjs +103 -0
  34. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useTextLayouts.mjs +156 -0
  35. package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/del.png.mjs +4 -0
  36. package/dist/es/components/VLMAnnotation/VLMLabelMaker/index.mjs +526 -0
  37. package/dist/es/components/VLMAnnotation/VLMLabelMaker/style.less.mjs +4 -0
  38. package/dist/es/components/VLMAnnotation/VLMLabelMaker/utils/coordinateUtils.mjs +33 -0
  39. package/dist/es/components/VLMAnnotation/components/DragButton.mjs +18 -0
  40. package/dist/es/components/VLMAnnotation/components/FitToScreenButton.mjs +16 -0
  41. package/dist/es/components/VLMAnnotation/components/RectangleButton.mjs +30 -0
  42. package/dist/es/components/VLMAnnotation/components/Toolbar.mjs +40 -0
  43. package/dist/es/components/VLMAnnotation/components/ZoomControls.mjs +44 -0
  44. package/dist/es/components/VLMAnnotation/constants.mjs +50 -0
  45. package/dist/es/components/VLMAnnotation/index.mjs +242 -0
  46. package/dist/es/components/VLMAnnotation/style.less.mjs +4 -0
  47. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/AttributeDetail/index.mjs +343 -0
  48. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/AttributeDetail/style.less.mjs +4 -0
  49. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/QAGenerationConfig.mjs +240 -0
  50. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/index.mjs +201 -0
  51. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/style.less.mjs +4 -0
  52. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/index.mjs +455 -0
  53. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/style.less.mjs +4 -0
  54. package/dist/es/components/VLMAnnotationDetail/VlmModal/index.mjs +149 -0
  55. package/dist/es/components/VLMAnnotationDetail/VlmModal/style.less.mjs +4 -0
  56. package/dist/es/components/VLMAnnotationDetail/index.mjs +449 -0
  57. package/dist/es/components/VLMAnnotationDetail/style.less.mjs +4 -0
  58. package/dist/es/constant.mjs +3 -3
  59. package/dist/es/createVlmtasetAnnotation/index.mjs +131 -0
  60. package/dist/es/featuresConfig.mjs +13 -9
  61. package/dist/es/index.mjs +11 -7
  62. package/dist/lib/index.js +4 -3
  63. package/dist/src/DatasetContext/index.d.ts +2 -0
  64. package/dist/src/components/DetectionAnnotation/components/ImageDetail/index.d.ts +1 -0
  65. package/dist/src/components/DetectionAnnotation/components/ImageModal/index.d.ts +35 -0
  66. package/dist/src/components/Iconfont/font_4439177_tgvowh6bmlb.d.ts +0 -0
  67. package/dist/src/components/PicZipImportModal/config.d.ts +23 -0
  68. package/dist/src/components/VLMAnnotation/ImageAnnotationDebugger.d.ts +4 -0
  69. package/dist/src/components/VLMAnnotation/RegionItem.d.ts +4 -0
  70. package/dist/src/components/VLMAnnotation/TextAnnotationPanel.d.ts +4 -0
  71. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasDrag.d.ts +13 -0
  72. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasSetup.d.ts +38 -0
  73. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasZoom.d.ts +18 -0
  74. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCropRegionImage.d.ts +7 -0
  75. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteControl.d.ts +13 -0
  76. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteRegion.d.ts +21 -0
  77. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDrawingMode.d.ts +32 -0
  78. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRLoadingIcon.d.ts +11 -0
  79. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRRecognition.d.ts +28 -0
  80. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionHover.d.ts +13 -0
  81. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionLoader.d.ts +37 -0
  82. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionNameText.d.ts +12 -0
  83. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionSelection.d.ts +15 -0
  84. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionUpdate.d.ts +32 -0
  85. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useTextLayouts.d.ts +25 -0
  86. package/dist/src/components/VLMAnnotation/VLMLabelMaker/index.d.ts +4 -0
  87. package/dist/src/components/VLMAnnotation/VLMLabelMaker/utils/coordinateUtils.d.ts +32 -0
  88. package/dist/src/components/VLMAnnotation/components/DragButton.d.ts +7 -0
  89. package/dist/src/components/VLMAnnotation/components/FitToScreenButton.d.ts +6 -0
  90. package/dist/src/components/VLMAnnotation/components/RectangleButton.d.ts +7 -0
  91. package/dist/src/components/VLMAnnotation/components/Toolbar.d.ts +4 -0
  92. package/dist/src/components/VLMAnnotation/components/ZoomControls.d.ts +4 -0
  93. package/dist/src/components/VLMAnnotation/constants.d.ts +97 -0
  94. package/dist/src/components/VLMAnnotation/index.d.ts +6 -0
  95. package/dist/src/components/VLMAnnotation/types.d.ts +172 -0
  96. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/AttributeDetail/index.d.ts +14 -0
  97. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/QAGenerationConfig.d.ts +12 -0
  98. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/index.d.ts +12 -0
  99. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/index.d.ts +12 -0
  100. package/dist/src/components/VLMAnnotationDetail/VlmModal/index.d.ts +17 -0
  101. package/dist/src/components/VLMAnnotationDetail/index.d.ts +6 -0
  102. package/dist/src/constant.d.ts +1 -1
  103. package/dist/src/createVlmtasetAnnotation/index.d.ts +16 -0
  104. package/dist/src/featuresConfig.d.ts +4 -0
  105. package/dist/src/index.d.ts +3 -0
  106. package/package.json +2 -2
  107. package/dist/dataset-annotation.js +0 -123598
  108. package/dist/dataset-annotation.umd.cjs +0 -1017
  109. package/dist/example/DatasetAnnotationDemo.d.ts +0 -3
  110. package/dist/example/DemoTabs.d.ts +0 -3
  111. package/dist/example/DetectionDatasetDemo.d.ts +0 -5
  112. package/dist/example/DetectionImageDemo.d.ts +0 -5
  113. package/dist/example/OcrDatasetDemo.d.ts +0 -5
  114. package/dist/example/OcrImageDemo.d.ts +0 -5
  115. package/dist/example/OcrkvcDatasetDemo.d.ts +0 -5
  116. package/dist/example/constant.local.d.ts +0 -6
  117. package/dist/example/index.d.ts +0 -1
  118. package/dist/src/utils/reactCompatibility.d.ts +0 -5
@@ -0,0 +1,68 @@
1
+ var N = (i, l, s) => new Promise((f, o) => {
2
+ var c = (t) => {
3
+ try {
4
+ d(s.next(t));
5
+ } catch (n) {
6
+ o(n);
7
+ }
8
+ }, m = (t) => {
9
+ try {
10
+ d(s.throw(t));
11
+ } catch (n) {
12
+ o(n);
13
+ }
14
+ }, d = (t) => t.done ? f(t.value) : Promise.resolve(t.value).then(c, m);
15
+ d((s = s.apply(i, l)).next());
16
+ });
17
+ import { useRef as k, useCallback as R } from "react";
18
+ const G = ({
19
+ ocrRecognize: i,
20
+ onChange: l,
21
+ updateTextLayers: s,
22
+ canvas: f,
23
+ updateOCRLoadingIcon: o,
24
+ rectMapRef: c,
25
+ textLayersMapRef: m,
26
+ textLayoutContentMapRef: d
27
+ }) => {
28
+ const t = k(/* @__PURE__ */ new Set()), n = k(/* @__PURE__ */ new Map());
29
+ return {
30
+ performOCRIfNeeded: R((e, a) => N(void 0, null, function* () {
31
+ var x;
32
+ if (a !== "create" && a !== "update" || !i || !e.image)
33
+ return;
34
+ const u = (x = Array.from(c.current.entries()).find(([, r]) => r.id === e.id)) == null ? void 0 : x[0];
35
+ if (!u)
36
+ return;
37
+ const w = m.current.get(u);
38
+ w && f && (w.forEach((r) => {
39
+ r.off("mousedown"), r.off("mouseover"), r.off("mouseout"), d.current.delete(r), f.remove(r);
40
+ }), m.current.delete(u), f.renderAll());
41
+ const S = c.current.get(u);
42
+ S && S.textLayouts && delete S.textLayouts;
43
+ const q = (n.current.get(e.id) || 0) + 1;
44
+ n.current.set(e.id, q), t.current.add(e.id);
45
+ const A = c.current.get(u);
46
+ A && o(u, A, !0);
47
+ try {
48
+ const r = yield i(e.image);
49
+ if (n.current.get(e.id) !== q)
50
+ return;
51
+ t.current.delete(e.id), o(u, e, !1);
52
+ const y = c.current.get(u);
53
+ if (y && n.current.get(e.id) === q && (y.textLayouts = r, s(u, y), l)) {
54
+ const F = Array.from(c.current.values());
55
+ l(F);
56
+ }
57
+ } catch (r) {
58
+ if (n.current.get(e.id) !== q)
59
+ return;
60
+ t.current.delete(e.id), o(u, e, !1), console.error("Failed to perform OCR recognition:", r);
61
+ }
62
+ }), [i, l, s, f, o, c, m, d]),
63
+ ocrRecognizingRef: t
64
+ };
65
+ };
66
+ export {
67
+ G as useOCRRecognition
68
+ };
@@ -0,0 +1,38 @@
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
+ };
@@ -0,0 +1,141 @@
1
+ var X = Object.defineProperty;
2
+ var F = Object.getOwnPropertySymbols;
3
+ var b = Object.prototype.hasOwnProperty, j = Object.prototype.propertyIsEnumerable;
4
+ var K = (e, t, s) => t in e ? X(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s, Z = (e, t) => {
5
+ for (var s in t || (t = {}))
6
+ b.call(t, s) && K(e, s, t[s]);
7
+ if (F)
8
+ for (var s of F(t))
9
+ j.call(t, s) && K(e, s, t[s]);
10
+ return e;
11
+ };
12
+ import { useEffect as q } from "react";
13
+ import { fabric as N } from "fabric";
14
+ import { TRANSPARENT_FILL as P, RECT_STROKE_COLOR as B, BASE_STROKE_WIDTH as G, REGION_NAME_PREFIX as H } from "../../constants.mjs";
15
+ const z = ({
16
+ canvas: e,
17
+ sample: t,
18
+ image: s,
19
+ bgImagePosition: O,
20
+ canvasInitializedRef: $,
21
+ bgImagePositionRef: w,
22
+ sampleRef: y,
23
+ labelsLoadedRef: d,
24
+ rectMapRef: f,
25
+ textLayersMapRef: S,
26
+ textLayoutContentMapRef: A,
27
+ regionNameTextMapRef: C,
28
+ ocrLoadingIconMapRef: _,
29
+ imageToCanvasCoords: x,
30
+ updateRegionShapeAndImage: E,
31
+ createDeleteControl: m,
32
+ updateRegionNameText: W,
33
+ updateTextLayers: U
34
+ }) => {
35
+ q(() => {
36
+ if (!e || !(t != null && t.labels) || !s || !$.current || w.current.left === 0 && w.current.top === 0)
37
+ return;
38
+ y.current !== t ? (y.current = t, d.current = !1, f.current.forEach((o, n) => {
39
+ const l = S.current.get(n);
40
+ l && (l.forEach((r) => {
41
+ r.off("mousedown"), r.off("mouseover"), r.off("mouseout"), A.current.delete(r), e.remove(r);
42
+ }), S.current.delete(n));
43
+ const u = C.current.get(n);
44
+ u && (n.off("moved"), n.off("modified"), e.remove(u), C.current.delete(n));
45
+ const i = _.current.get(n);
46
+ i && (e.remove(i), _.current.delete(n)), e.remove(n);
47
+ }), f.current.clear(), t.labels.forEach((o, n) => {
48
+ if (o.shape.name !== "rect")
49
+ return;
50
+ const l = x(o.shape.x, o.shape.y), u = e.getZoom(), i = G / u, r = new N.Rect({
51
+ left: l.x,
52
+ top: l.y,
53
+ width: o.shape.width,
54
+ height: o.shape.height,
55
+ fill: P,
56
+ // 无填充色
57
+ stroke: B,
58
+ strokeWidth: i,
59
+ strokeUniform: !0,
60
+ // 边框宽度不受缩放影响
61
+ selectable: !0,
62
+ evented: !0,
63
+ hasRotatingPoint: !1,
64
+ // 隐藏旋转点
65
+ lockRotation: !0,
66
+ // 锁定旋转
67
+ lockUniScaling: !1,
68
+ // 允许非等比缩放,控制点跟随鼠标
69
+ objectCaching: !1,
70
+ // 禁用缓存,避免缩放时边框变虚
71
+ statefullCache: !1,
72
+ noScaleCache: !1
73
+ });
74
+ r.on("modified", () => {
75
+ E(r);
76
+ }), r.on("moved", () => {
77
+ E(r);
78
+ }), e.add(r), r.controls.deleteControl = m();
79
+ const h = Z({}, o);
80
+ h.name || (h.name = `${H}${n + 1}`), f.current.set(r, h), W(r, h), h.textLayouts && h.textLayouts.length > 0 && U(r, h);
81
+ }), d.current = !0, e.renderAll()) : !d.current && t.labels.length > 0 && (t.labels.forEach((o, n) => {
82
+ if (o.shape.name !== "rect" || Array.from(f.current.values()).find((k) => k.shape.x === o.shape.x && k.shape.y === o.shape.y && k.shape.width === o.shape.width && k.shape.height === o.shape.height))
83
+ return;
84
+ const u = x(o.shape.x, o.shape.y), i = e.getZoom(), r = G / i, h = new N.Rect({
85
+ left: u.x,
86
+ top: u.y,
87
+ width: o.shape.width,
88
+ height: o.shape.height,
89
+ fill: P,
90
+ // 无填充色
91
+ stroke: B,
92
+ strokeWidth: r,
93
+ strokeUniform: !0,
94
+ // 边框宽度不受缩放影响
95
+ selectable: !0,
96
+ evented: !0,
97
+ hasRotatingPoint: !1,
98
+ // 隐藏旋转点
99
+ lockRotation: !0,
100
+ // 锁定旋转
101
+ lockUniScaling: !1,
102
+ // 允许非等比缩放,控制点跟随鼠标
103
+ objectCaching: !1,
104
+ // 禁用缓存,避免缩放时边框变虚
105
+ statefullCache: !1,
106
+ noScaleCache: !1
107
+ });
108
+ h.on("modified", () => {
109
+ E(h);
110
+ }), h.on("moved", () => {
111
+ E(h);
112
+ }), e.add(h), h.controls.deleteControl = m();
113
+ const c = Z({}, o);
114
+ c.name || (c.name = `${H}${n + 1}`), f.current.set(h, c), W(h, c), c.textLayouts && c.textLayouts.length > 0 && U(h, c);
115
+ }), d.current = !0, e.renderAll());
116
+ }, [
117
+ e,
118
+ t,
119
+ t == null ? void 0 : t.labels,
120
+ s,
121
+ O,
122
+ // 添加 bgImagePosition 作为依赖,确保在位置设置后触发加载
123
+ x,
124
+ E,
125
+ U,
126
+ W,
127
+ m,
128
+ $,
129
+ w,
130
+ y,
131
+ d,
132
+ f,
133
+ S,
134
+ A,
135
+ C,
136
+ _
137
+ ]);
138
+ };
139
+ export {
140
+ z as useRegionLoader
141
+ };
@@ -0,0 +1,72 @@
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
+ };
@@ -0,0 +1,113 @@
1
+ import { useEffect as g } from "react";
2
+ import { fabric as u } from "fabric";
3
+ import { SELECTED_RECT_FILL_COLOR as L, CONTROL_POINT_COLOR as R, CONTROL_POINT_SIZE as S, TRANSPARENT_FILL as E, BASE_STROKE_WIDTH as A } from "../../constants.mjs";
4
+ const j = ({
5
+ canvas: e,
6
+ onRegionSelect: o,
7
+ createDeleteControl: n,
8
+ textLayersMapRef: a,
9
+ rectMapRef: s
10
+ }) => {
11
+ g(() => {
12
+ if (!e)
13
+ return;
14
+ const i = () => {
15
+ const t = /* @__PURE__ */ new Set();
16
+ return a.current.forEach((r) => {
17
+ r.forEach((l) => {
18
+ t.add(l);
19
+ });
20
+ }), t;
21
+ }, f = () => {
22
+ const t = i();
23
+ e.getObjects().forEach((r) => {
24
+ r instanceof u.Rect && !t.has(r) && r.set({
25
+ fill: E
26
+ // 移除填充色
27
+ });
28
+ });
29
+ }, h = () => {
30
+ f();
31
+ const t = e.getActiveObject();
32
+ if (t && t instanceof u.Rect) {
33
+ if (i().has(t)) {
34
+ e.discardActiveObject(), e.renderAll();
35
+ return;
36
+ }
37
+ const l = e.getZoom(), d = A / l;
38
+ t.set({
39
+ hasRotatingPoint: !1,
40
+ lockRotation: !0,
41
+ lockUniScaling: !1,
42
+ // 允许非等比缩放,控制点跟随鼠标
43
+ fill: L,
44
+ // 选中时添加填充色
45
+ strokeUniform: !0,
46
+ // 确保边框宽度不受缩放影响
47
+ strokeWidth: d,
48
+ // 确保边框宽度一致
49
+ objectCaching: !1,
50
+ // 禁用缓存,避免缩放时边框变虚
51
+ statefullCache: !1,
52
+ noScaleCache: !1,
53
+ cornerStyle: "circle",
54
+ // 设置控制点为圆形
55
+ cornerColor: R,
56
+ // 设置控制点为紫色(填充色)
57
+ cornerSize: S,
58
+ // 设置控制点大小(默认12,这里设置为6使其更小)
59
+ transparentCorners: !1
60
+ // 不透明,显示填充颜色
61
+ }), t.controls && t.controls.mtr && delete t.controls.mtr, t.controls.deleteControl || (t.controls.deleteControl = n()), e.renderAll();
62
+ const c = s.current.get(t);
63
+ c && o && o(c);
64
+ }
65
+ }, C = () => {
66
+ f();
67
+ const t = e.getActiveObject();
68
+ if (t && t instanceof u.Rect) {
69
+ if (i().has(t)) {
70
+ e.discardActiveObject(), e.renderAll();
71
+ return;
72
+ }
73
+ const l = e.getZoom(), d = A / l;
74
+ t.set({
75
+ hasRotatingPoint: !1,
76
+ lockRotation: !0,
77
+ lockUniScaling: !1,
78
+ // 允许非等比缩放,控制点跟随鼠标
79
+ fill: L,
80
+ // 选中时添加填充色
81
+ strokeUniform: !0,
82
+ // 确保边框宽度不受缩放影响
83
+ strokeWidth: d,
84
+ // 确保边框宽度一致
85
+ objectCaching: !1,
86
+ // 禁用缓存,避免缩放时边框变虚
87
+ statefullCache: !1,
88
+ noScaleCache: !1,
89
+ cornerStyle: "circle",
90
+ // 设置控制点为圆形
91
+ cornerColor: R,
92
+ // 设置控制点为紫色(填充色)
93
+ cornerSize: S,
94
+ // 设置控制点大小(默认12,这里设置为6使其更小)
95
+ transparentCorners: !1
96
+ // 不透明,显示填充颜色
97
+ });
98
+ const c = t;
99
+ c.uniformScaling = !1, t.controls && t.controls.mtr && delete t.controls.mtr, t.controls.deleteControl || (t.controls.deleteControl = n()), e.renderAll();
100
+ const m = s.current.get(t);
101
+ m && o && o(m);
102
+ }
103
+ }, O = () => {
104
+ f(), e.renderAll(), o && o(null);
105
+ };
106
+ return e.on("selection:created", h), e.on("selection:updated", C), e.on("selection:cleared", O), () => {
107
+ e.off("selection:created", h), e.off("selection:updated", C), e.off("selection:cleared", O);
108
+ };
109
+ }, [e, o, n, a, s]);
110
+ };
111
+ export {
112
+ j as useRegionSelection
113
+ };
@@ -0,0 +1,103 @@
1
+ import { useCallback as B } from "react";
2
+ import { fabric as D } from "fabric";
3
+ import { BASE_STROKE_WIDTH as E } from "../../constants.mjs";
4
+ const z = ({
5
+ canvas: f,
6
+ image: r,
7
+ draggable: x,
8
+ canvasToImageCoords: S,
9
+ imageToCanvasCoords: y,
10
+ cropRegionImage: W,
11
+ onChange: a,
12
+ onRegionChange: g,
13
+ performOCRIfNeeded: w,
14
+ updateTextLayers: A,
15
+ rectMapRef: d,
16
+ regionNameTextMapRef: j,
17
+ ocrLoadingIconMapRef: k
18
+ }) => ({
19
+ updateRegionShapeAndImage: B((t) => {
20
+ if (!f || !r || x)
21
+ return;
22
+ const L = f.getZoom(), U = E / L;
23
+ t.set({
24
+ strokeUniform: !0,
25
+ strokeWidth: U,
26
+ objectCaching: !1,
27
+ statefullCache: !1,
28
+ noScaleCache: !1
29
+ });
30
+ const i = r.getElement();
31
+ if (!(i != null && i.width) || !(i != null && i.height))
32
+ return;
33
+ const H = i.width, X = i.height, Y = S(t.left, t.top), s = d.current.get(t);
34
+ if (s) {
35
+ let n = Y.x, l = Y.y, o = t.getScaledWidth(), c = t.getScaledHeight();
36
+ n < 0 && (o = o + n, n = 0), l < 0 && (c = c + l, l = 0), n + o > H && (o = H - n), l + c > X && (c = X - l), o = Math.max(0, o), c = Math.max(0, c), s.shape.x = n, s.shape.y = l, s.shape.width = o, s.shape.height = c;
37
+ const u = y(n, l);
38
+ t.scaleX, t.scaleY, t.set({
39
+ left: u.x,
40
+ top: u.y,
41
+ width: o,
42
+ height: c,
43
+ scaleX: 1,
44
+ // 重置缩放,使用实际尺寸
45
+ scaleY: 1
46
+ // 重置缩放,使用实际尺寸
47
+ });
48
+ const Z = j.current.get(t);
49
+ if (Z) {
50
+ const e = f.getZoom();
51
+ Z.set({
52
+ left: u.x,
53
+ // 与标注框左边对齐
54
+ top: u.y,
55
+ // 下边缘与标注框上边缘对齐(因为 originY 是 'bottom')
56
+ scaleX: 1 / e,
57
+ // 反向缩放,抵消画布缩放
58
+ scaleY: 1 / e
59
+ // 反向缩放,抵消画布缩放
60
+ });
61
+ const h = k.current.get(t);
62
+ if (h) {
63
+ const m = t.getScaledWidth();
64
+ t.getScaledHeight(), h.set({
65
+ left: u.x,
66
+ // top 位置由动画控制,这里不更新
67
+ scaleX: 1 / e,
68
+ // 反向缩放,抵消画布缩放,保持固定视觉粗细
69
+ scaleY: 1 / e
70
+ // 反向缩放,抵消画布缩放,保持固定视觉粗细
71
+ });
72
+ const p = h.getObjects();
73
+ if (p && p.length > 0) {
74
+ const _ = m * e;
75
+ p.forEach((b) => {
76
+ b instanceof D.Rect && b.set("width", _);
77
+ });
78
+ }
79
+ }
80
+ }
81
+ if (s.textLayouts && s.textLayouts.length > 0 && A(t, s), g && g(s, "update"), W(s).then((e) => {
82
+ if (e) {
83
+ const h = d.current.get(t);
84
+ if (h) {
85
+ if (h.image = e, delete h.textLayouts, a) {
86
+ const m = Array.from(d.current.values());
87
+ a(m);
88
+ }
89
+ w(h, "update");
90
+ }
91
+ }
92
+ }).catch((e) => {
93
+ console.error("Failed to crop region image:", e);
94
+ }), a) {
95
+ const e = Array.from(d.current.values());
96
+ a(e);
97
+ }
98
+ }
99
+ }, [f, r, x, S, y, W, a, g, w, A, d, j, k])
100
+ });
101
+ export {
102
+ z as useRegionUpdate
103
+ };
@@ -0,0 +1,156 @@
1
+ var S = (e, y, l) => new Promise((E, i) => {
2
+ var T = (o) => {
3
+ try {
4
+ u(l.next(o));
5
+ } catch (n) {
6
+ i(n);
7
+ }
8
+ }, c = (o) => {
9
+ try {
10
+ u(l.throw(o));
11
+ } catch (n) {
12
+ i(n);
13
+ }
14
+ }, u = (o) => o.done ? E(o.value) : Promise.resolve(o.value).then(T, c);
15
+ u((l = l.apply(e, y)).next());
16
+ });
17
+ import { useRef as A, useEffect as V, useCallback as q } from "react";
18
+ import { fabric as z } from "fabric";
19
+ import { TEXT_LAYOUT_RECT_FILL_COLOR as d, TEXT_LAYOUT_RECT_STROKE_COLOR as x, TEXT_LAYOUT_RECT_HOVER_STROKE_COLOR as G, TEXT_LAYOUT_RECT_CLICK_FEEDBACK_COLOR as m, TEXT_LAYOUT_RECT_FEEDBACK_DELAY as X, BASE_STROKE_WIDTH as J } from "../../constants.mjs";
20
+ const j = ({
21
+ canvas: e,
22
+ imageToCanvasCoords: y,
23
+ activeLabelValue: l,
24
+ onAppendTextToActive: E
25
+ }) => {
26
+ const i = A(/* @__PURE__ */ new Map()), T = A(/* @__PURE__ */ new Map()), c = A(null), u = A(void 0);
27
+ return V(() => {
28
+ c.current = l, u.current = E;
29
+ }, [l, E]), {
30
+ updateTextLayers: q((n, f) => {
31
+ var M;
32
+ if (!e)
33
+ return;
34
+ const b = i.current.get(n);
35
+ if (b && (b.forEach((r) => {
36
+ r.off("mousedown"), r.off("mouseover"), r.off("mouseout"), T.current.delete(r), e.remove(r);
37
+ }), i.current.delete(n)), !f.textLayouts || f.textLayouts.length === 0)
38
+ return;
39
+ const R = c.current, I = ((M = R == null ? void 0 : R.region) == null ? void 0 : M.id) === f.id, k = [], K = e.getZoom(), U = J / K;
40
+ f.textLayouts.forEach((r) => {
41
+ const O = r.bbox;
42
+ if (!O || O.length < 2)
43
+ return;
44
+ let _ = 1 / 0, C = 1 / 0, g = -1 / 0, Y = -1 / 0;
45
+ O.forEach(([L, p]) => {
46
+ _ = Math.min(_, L), C = Math.min(C, p), g = Math.max(g, L), Y = Math.max(Y, p);
47
+ });
48
+ const F = f.shape.x + _, B = f.shape.y + C, D = g - _, W = Y - C, w = y(F, B), t = new z.Rect({
49
+ left: w.x,
50
+ top: w.y,
51
+ width: D,
52
+ height: W,
53
+ fill: d,
54
+ stroke: x,
55
+ strokeWidth: U,
56
+ // 根据缩放调整边框宽度,保持视觉一致
57
+ strokeUniform: !0,
58
+ // 确保边框宽度随缩放调整
59
+ selectable: !1,
60
+ // 不可选中
61
+ evented: !0,
62
+ // 可以接收事件
63
+ visible: I,
64
+ // 只在对应的标注框active时显示
65
+ hoverCursor: "pointer",
66
+ // 鼠标悬停时显示 pointer 样式
67
+ originX: "left",
68
+ originY: "top",
69
+ lockMovementX: !0,
70
+ // 锁定 X 轴移动
71
+ lockMovementY: !0,
72
+ // 锁定 Y 轴移动
73
+ lockScalingX: !0,
74
+ // 锁定 X 轴缩放
75
+ lockScalingY: !0,
76
+ // 锁定 Y 轴缩放
77
+ lockRotation: !0,
78
+ // 锁定旋转
79
+ hasControls: !1,
80
+ // 不显示控制点
81
+ hasBorders: !1,
82
+ // 不显示边框控制点
83
+ objectCaching: !1,
84
+ statefullCache: !1,
85
+ noScaleCache: !1
86
+ }), h = r.content || "";
87
+ T.current.set(t, h), t.on("mouseover", () => {
88
+ t.set({
89
+ fill: d,
90
+ stroke: G
91
+ }), e == null || e.renderAll();
92
+ }), t.on("mouseout", () => {
93
+ t.set({
94
+ fill: d,
95
+ stroke: x
96
+ }), e == null || e.renderAll();
97
+ }), t.on("mousedown", () => S(void 0, null, function* () {
98
+ if (!h)
99
+ return;
100
+ const L = c.current, p = u.current;
101
+ if (L && p) {
102
+ p(h), t.set({
103
+ stroke: m,
104
+ // 点击时变为绿色
105
+ fill: m
106
+ }), e == null || e.renderAll(), setTimeout(() => {
107
+ t.set({
108
+ fill: d,
109
+ stroke: x
110
+ }), e == null || e.renderAll();
111
+ }, X);
112
+ return;
113
+ }
114
+ try {
115
+ yield navigator.clipboard.writeText(h), t.set({
116
+ stroke: m,
117
+ // 点击时变为绿色
118
+ fill: m
119
+ // 添加绿色半透明填充
120
+ }), e == null || e.renderAll(), setTimeout(() => {
121
+ t.set({
122
+ fill: d,
123
+ stroke: x
124
+ }), e == null || e.renderAll();
125
+ }, X);
126
+ } catch (H) {
127
+ console.error("Failed to copy text to clipboard:", H);
128
+ const s = document.createElement("textarea");
129
+ s.value = h, s.style.position = "fixed", s.style.opacity = "0", document.body.appendChild(s), s.select();
130
+ try {
131
+ document.execCommand("copy"), t.set({
132
+ stroke: m,
133
+ // 点击时变为绿色
134
+ fill: m
135
+ // 添加绿色半透明填充
136
+ }), e == null || e.renderAll(), setTimeout(() => {
137
+ t.set({
138
+ fill: d,
139
+ stroke: x
140
+ }), e == null || e.renderAll();
141
+ }, X);
142
+ } catch (Z) {
143
+ console.error("Failed to copy text:", Z);
144
+ }
145
+ document.body.removeChild(s);
146
+ }
147
+ })), e.add(t), k.push(t);
148
+ }), k.length > 0 && i.current.set(n, k);
149
+ }, [e, y]),
150
+ textLayersMapRef: i,
151
+ textLayoutContentMapRef: T
152
+ };
153
+ };
154
+ export {
155
+ j as useTextLayouts
156
+ };