@glodon-aiot/dataset-annotation 3.9.0-beta.9 → 3.10.0-alpha.10

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 (110) hide show
  1. package/dist/dataset-annotation.js +123598 -0
  2. package/dist/dataset-annotation.umd.cjs +1017 -0
  3. package/dist/es/DatasetContext/index.mjs +6 -3
  4. package/dist/es/components/Iconfont/index.mjs +2 -2
  5. package/dist/es/components/PicZipImportModal/config.mjs +41 -0
  6. package/dist/es/components/PicZipImportModal/index.mjs +317 -301
  7. package/dist/es/components/PicZipImportModal/pic_vlm_json_zip.svg.mjs +4 -0
  8. package/dist/es/components/PicZipImportModal/pic_vlm_zip.svg.mjs +4 -0
  9. package/dist/es/components/VLMAnnotation/RegionItem.mjs +95 -0
  10. package/dist/es/components/VLMAnnotation/TextAnnotationPanel.mjs +83 -0
  11. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasDrag.mjs +75 -0
  12. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasSetup.mjs +115 -0
  13. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasZoom.mjs +42 -0
  14. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCropRegionImage.mjs +55 -0
  15. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteControl.mjs +51 -0
  16. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteRegion.mjs +47 -0
  17. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDrawingMode.mjs +220 -0
  18. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRLoadingIcon.mjs +106 -0
  19. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRRecognition.mjs +68 -0
  20. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionHover.mjs +38 -0
  21. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionLoader.mjs +141 -0
  22. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionNameText.mjs +72 -0
  23. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionSelection.mjs +102 -0
  24. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionUpdate.mjs +103 -0
  25. package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useTextLayouts.mjs +156 -0
  26. package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/del.png.mjs +4 -0
  27. package/dist/es/components/VLMAnnotation/VLMLabelMaker/index.mjs +507 -0
  28. package/dist/es/components/VLMAnnotation/VLMLabelMaker/style.less.mjs +4 -0
  29. package/dist/es/components/VLMAnnotation/VLMLabelMaker/utils/coordinateUtils.mjs +33 -0
  30. package/dist/es/components/VLMAnnotation/components/DragButton.mjs +18 -0
  31. package/dist/es/components/VLMAnnotation/components/FitToScreenButton.mjs +16 -0
  32. package/dist/es/components/VLMAnnotation/components/RectangleButton.mjs +30 -0
  33. package/dist/es/components/VLMAnnotation/components/Toolbar.mjs +40 -0
  34. package/dist/es/components/VLMAnnotation/components/ZoomControls.mjs +44 -0
  35. package/dist/es/components/VLMAnnotation/constants.mjs +50 -0
  36. package/dist/es/components/VLMAnnotation/index.mjs +242 -0
  37. package/dist/es/components/VLMAnnotation/style.less.mjs +4 -0
  38. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/AttributeDetail/index.mjs +345 -0
  39. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/AttributeDetail/style.less.mjs +4 -0
  40. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/QAGenerationConfig.mjs +240 -0
  41. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/index.mjs +201 -0
  42. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/style.less.mjs +4 -0
  43. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/index.mjs +399 -0
  44. package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/style.less.mjs +4 -0
  45. package/dist/es/components/VLMAnnotationDetail/VlmModal/index.mjs +139 -0
  46. package/dist/es/components/VLMAnnotationDetail/VlmModal/style.less.mjs +4 -0
  47. package/dist/es/components/VLMAnnotationDetail/index.mjs +446 -0
  48. package/dist/es/components/VLMAnnotationDetail/style.less.mjs +4 -0
  49. package/dist/es/constant.mjs +3 -3
  50. package/dist/es/createVlmtasetAnnotation/index.mjs +131 -0
  51. package/dist/es/featuresConfig.mjs +13 -9
  52. package/dist/es/index.mjs +11 -7
  53. package/dist/example/DatasetAnnotationDemo.d.ts +3 -0
  54. package/dist/example/DemoTabs.d.ts +3 -0
  55. package/dist/example/DetectionDatasetDemo.d.ts +5 -0
  56. package/dist/example/DetectionImageDemo.d.ts +5 -0
  57. package/dist/example/OcrDatasetDemo.d.ts +5 -0
  58. package/dist/example/OcrImageDemo.d.ts +5 -0
  59. package/dist/example/OcrkvcDatasetDemo.d.ts +5 -0
  60. package/dist/example/constant.local.d.ts +6 -0
  61. package/dist/example/index.d.ts +1 -0
  62. package/dist/lib/index.js +4 -3
  63. package/dist/src/DatasetContext/index.d.ts +2 -0
  64. package/dist/src/components/Iconfont/font_4439177_tgvowh6bmlb.d.ts +0 -0
  65. package/dist/src/components/PicZipImportModal/config.d.ts +20 -0
  66. package/dist/src/components/VLMAnnotation/ImageAnnotationDebugger.d.ts +4 -0
  67. package/dist/src/components/VLMAnnotation/RegionItem.d.ts +4 -0
  68. package/dist/src/components/VLMAnnotation/TextAnnotationPanel.d.ts +4 -0
  69. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasDrag.d.ts +12 -0
  70. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasSetup.d.ts +38 -0
  71. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasZoom.d.ts +18 -0
  72. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCropRegionImage.d.ts +7 -0
  73. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteControl.d.ts +13 -0
  74. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteRegion.d.ts +21 -0
  75. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDrawingMode.d.ts +31 -0
  76. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRLoadingIcon.d.ts +11 -0
  77. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRRecognition.d.ts +28 -0
  78. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionHover.d.ts +13 -0
  79. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionLoader.d.ts +37 -0
  80. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionNameText.d.ts +12 -0
  81. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionSelection.d.ts +15 -0
  82. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionUpdate.d.ts +32 -0
  83. package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useTextLayouts.d.ts +25 -0
  84. package/dist/src/components/VLMAnnotation/VLMLabelMaker/index.d.ts +4 -0
  85. package/dist/src/components/VLMAnnotation/VLMLabelMaker/utils/coordinateUtils.d.ts +32 -0
  86. package/dist/src/components/VLMAnnotation/components/DragButton.d.ts +7 -0
  87. package/dist/src/components/VLMAnnotation/components/FitToScreenButton.d.ts +6 -0
  88. package/dist/src/components/VLMAnnotation/components/RectangleButton.d.ts +7 -0
  89. package/dist/src/components/VLMAnnotation/components/Toolbar.d.ts +4 -0
  90. package/dist/src/components/VLMAnnotation/components/ZoomControls.d.ts +4 -0
  91. package/dist/src/components/VLMAnnotation/constants.d.ts +97 -0
  92. package/dist/src/components/VLMAnnotation/index.d.ts +6 -0
  93. package/dist/src/components/VLMAnnotation/types.d.ts +172 -0
  94. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/AttributeDetail/index.d.ts +14 -0
  95. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/ImageDetail/index.d.ts +16 -0
  96. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/OCRBoxMaker/LabelEditorInput.d.ts +12 -0
  97. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/OCRBoxMaker/LabelEditorItem.d.ts +21 -0
  98. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/OCRBoxMaker/LableEditor.d.ts +16 -0
  99. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/OCRBoxMaker/index.d.ts +19 -0
  100. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/QAGenerationConfig.d.ts +12 -0
  101. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/index.d.ts +12 -0
  102. package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/index.d.ts +12 -0
  103. package/dist/src/components/VLMAnnotationDetail/VlmModal/index.d.ts +16 -0
  104. package/dist/src/components/VLMAnnotationDetail/index.d.ts +6 -0
  105. package/dist/src/constant.d.ts +1 -1
  106. package/dist/src/createVlmtasetAnnotation/index.d.ts +16 -0
  107. package/dist/src/featuresConfig.d.ts +4 -0
  108. package/dist/src/index.d.ts +3 -0
  109. package/dist/src/utils/reactCompatibility.d.ts +5 -0
  110. package/package.json +2 -2
@@ -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,102 @@
1
+ import { useEffect as g } from "react";
2
+ import { fabric as f } from "fabric";
3
+ import { SELECTED_RECT_FILL_COLOR as m, CONTROL_POINT_COLOR as O, CONTROL_POINT_SIZE as S, TRANSPARENT_FILL as k, BASE_STROKE_WIDTH as E } from "../../constants.mjs";
4
+ const L = ({
5
+ canvas: t,
6
+ onRegionSelect: r,
7
+ createDeleteControl: c,
8
+ textLayersMapRef: d,
9
+ rectMapRef: i
10
+ }) => {
11
+ g(() => {
12
+ if (!t)
13
+ return;
14
+ const s = () => {
15
+ const e = /* @__PURE__ */ new Set();
16
+ d.current.forEach((o) => {
17
+ o.forEach((l) => {
18
+ e.add(l);
19
+ });
20
+ }), t.getObjects().forEach((o) => {
21
+ o instanceof f.Rect && !e.has(o) && o.set({
22
+ fill: k
23
+ // 移除填充色
24
+ });
25
+ });
26
+ }, a = () => {
27
+ s();
28
+ const e = t.getActiveObject();
29
+ if (e && e instanceof f.Rect) {
30
+ const o = t.getZoom(), l = E / o;
31
+ e.set({
32
+ hasRotatingPoint: !1,
33
+ lockRotation: !0,
34
+ lockUniScaling: !1,
35
+ // 允许非等比缩放,控制点跟随鼠标
36
+ fill: m,
37
+ // 选中时添加填充色
38
+ strokeUniform: !0,
39
+ // 确保边框宽度不受缩放影响
40
+ strokeWidth: l,
41
+ // 确保边框宽度一致
42
+ objectCaching: !1,
43
+ // 禁用缓存,避免缩放时边框变虚
44
+ statefullCache: !1,
45
+ noScaleCache: !1,
46
+ cornerStyle: "circle",
47
+ // 设置控制点为圆形
48
+ cornerColor: O,
49
+ // 设置控制点为紫色(填充色)
50
+ cornerSize: S,
51
+ // 设置控制点大小(默认12,这里设置为6使其更小)
52
+ transparentCorners: !1
53
+ // 不透明,显示填充颜色
54
+ }), e.controls && e.controls.mtr && delete e.controls.mtr, e.controls.deleteControl || (e.controls.deleteControl = c()), t.renderAll();
55
+ const n = i.current.get(e);
56
+ n && r && r(n);
57
+ }
58
+ }, u = () => {
59
+ s();
60
+ const e = t.getActiveObject();
61
+ if (e && e instanceof f.Rect) {
62
+ const o = t.getZoom(), l = E / o;
63
+ e.set({
64
+ hasRotatingPoint: !1,
65
+ lockRotation: !0,
66
+ lockUniScaling: !1,
67
+ // 允许非等比缩放,控制点跟随鼠标
68
+ fill: m,
69
+ // 选中时添加填充色
70
+ strokeUniform: !0,
71
+ // 确保边框宽度不受缩放影响
72
+ strokeWidth: l,
73
+ // 确保边框宽度一致
74
+ objectCaching: !1,
75
+ // 禁用缓存,避免缩放时边框变虚
76
+ statefullCache: !1,
77
+ noScaleCache: !1,
78
+ cornerStyle: "circle",
79
+ // 设置控制点为圆形
80
+ cornerColor: O,
81
+ // 设置控制点为紫色(填充色)
82
+ cornerSize: S,
83
+ // 设置控制点大小(默认12,这里设置为6使其更小)
84
+ transparentCorners: !1
85
+ // 不透明,显示填充颜色
86
+ });
87
+ const n = e;
88
+ n.uniformScaling = !1, e.controls && e.controls.mtr && delete e.controls.mtr, e.controls.deleteControl || (e.controls.deleteControl = c()), t.renderAll();
89
+ const h = i.current.get(e);
90
+ h && r && r(h);
91
+ }
92
+ }, C = () => {
93
+ s(), t.renderAll(), r && r(null);
94
+ };
95
+ return t.on("selection:created", a), t.on("selection:updated", u), t.on("selection:cleared", C), () => {
96
+ t.off("selection:created", a), t.off("selection:updated", u), t.off("selection:cleared", C);
97
+ };
98
+ }, [t, r, c, d, i]);
99
+ };
100
+ export {
101
+ L as useRegionSelection
102
+ };
@@ -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
+ };
@@ -0,0 +1,4 @@
1
+ const A = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAMP0lEQVR4Aeyd7XmrOBCFJf7n3ibSxya92HUkt451L8n24SY2+b9aDgoBbGLASIKZOTyRwVhIM+/M4UPEuHKcSIAEfiRAgfyIhh+QgHMUCLOABG4QoEBuwOFHJECBMAdI4AaBjAK50Ss/IgEhBCgQIYGimdsQoEC24c5ehRCgQIQEimZuQ4AC2YY7exVCQKZAhMClmfIJUCDyY0gPMhKgQDLCZdPyCVAg8mNIDzISoEAywmXT8glQIBcx5FsS6BOgQPo0uEwCFwQokAsgfEsCfQIUSJ8Gl0ngggAFcgGEb0mgT4AC6dPIu8zWBRKgQAQGjSaXI0CBlGPNngQSoEAEBo0mlyNAgZRjzZ4EEqBABAbt2mSuyUWAAslFlu2qIECBqAgjnchFgALJRZbtqiBAgagII53IRYACyUVWS7vG/aBAjCcA3b9NgAK5zYefGidAgWRKgL8fP59i+ff178dYTo+fb2tL21Y3/3zK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