@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,62 +0,0 @@
1
- import { useRef as X, useCallback as A } from "react";
2
- import { Modal as K } from "antd";
3
- import { DELETE_MODAL_TITLE as q, DELETE_MODAL_CONTENT as z, DELETE_MODAL_OK_TEXT as B, DELETE_MODAL_CANCEL_TEXT as F } from "../../constants.mjs";
4
- const O = ({
5
- canvas: l,
6
- onRegionChange: o,
7
- updateRegionNames: _,
8
- rectMapRef: f,
9
- textLayersMapRef: e,
10
- textLayoutContentMapRef: s,
11
- regionNameTextMapRef: m,
12
- ocrLoadingIconMapRef: d
13
- }) => {
14
- const E = X(!1), k = A((r) => {
15
- if (!l || E.current)
16
- return;
17
- const D = f.current.get(r);
18
- D && (E.current = !0, K.confirm({
19
- title: q,
20
- content: z,
21
- okText: B,
22
- cancelText: F,
23
- onOk: () => {
24
- const i = e.current.get(r);
25
- i && (i.forEach((u) => {
26
- u.off("mousedown"), u.off("mouseover"), u.off("mouseout"), s.current.delete(u), l.remove(u);
27
- }), e.current.delete(r));
28
- const T = m.current.get(r);
29
- T && (r.off("moved"), r.off("modified"), l.remove(T), m.current.delete(r));
30
- const n = d.current.get(r);
31
- n && (l.remove(n), d.current.delete(r)), l.remove(r), f.current.delete(r), _(), o && o(D, "delete"), l.renderAll(), E.current = !1;
32
- },
33
- onCancel: () => {
34
- E.current = !1;
35
- },
36
- afterClose: () => {
37
- E.current = !1;
38
- }
39
- }));
40
- }, [l, o, _, f, e, s, m, d]), w = A((r) => {
41
- if (!l)
42
- return;
43
- const D = f.current.get(r);
44
- if (!D)
45
- return;
46
- const i = e.current.get(r);
47
- i && (i.forEach((u) => {
48
- u.off("mousedown"), u.off("mouseover"), u.off("mouseout"), s.current.delete(u), l.remove(u);
49
- }), e.current.delete(r));
50
- const T = m.current.get(r);
51
- T && (r.off("moved"), r.off("modified"), l.remove(T), m.current.delete(r));
52
- const n = d.current.get(r);
53
- n && (l.remove(n), d.current.delete(r)), l.remove(r), f.current.delete(r), _(), o && o(D, "delete"), l.renderAll();
54
- }, [l, o, _, f, e, s, m, d]);
55
- return {
56
- performDelete: k,
57
- deleteDirectly: w
58
- };
59
- };
60
- export {
61
- O as useDeleteRegion
62
- };
@@ -1,377 +0,0 @@
1
- import { useCallback as ue, useRef as fe, useEffect as he } from "react";
2
- import { fabric as b } from "fabric";
3
- import { CROSSHAIR_LINE_COLOR as me, CROSSHAIR_LINE_DASH_ARRAY as ge, CROSSHAIR_LINE_WIDTH as ke, TEMP_RECT_FILL_COLOR as be, RECT_STROKE_COLOR as G, TEMP_RECT_STROKE_DASH_ARRAY as pe, TRANSPARENT_FILL as Ee, REGION_NAME_PREFIX as xe, BASE_STROKE_WIDTH as K } from "../../constants.mjs";
4
- const Te = ({
5
- canvas: e,
6
- drawingMode: C,
7
- draggable: q,
8
- setDrawingMode: J,
9
- canvasToImageCoords: Q,
10
- labelDefinitions: X,
11
- onChange: a,
12
- cropRegionImage: V,
13
- updateRegionShapeAndImage: P,
14
- performOCRIfNeeded: v,
15
- createDeleteControl: ee,
16
- createOCRControl: te,
17
- updateRegionNameText: oe,
18
- onRegionChange: U,
19
- onRegionSelect: M,
20
- rectMapRef: h,
21
- textLayersMapRef: re,
22
- setupBoundaryCheck: ie
23
- }) => {
24
- const D = ue(() => {
25
- const R = /* @__PURE__ */ new Set();
26
- return re.current.forEach((T) => {
27
- T.forEach((W) => {
28
- R.add(W);
29
- });
30
- }), R;
31
- }, [re]), l = fe({
32
- horizontal: null,
33
- vertical: null
34
- }), Le = fe({
35
- dleft: -1,
36
- dtop: -1,
37
- dw: 0,
38
- dh: 0,
39
- rect: null
40
- }), Z = ue(() => {
41
- e && (e.skipTargetFind = !1);
42
- }, [e]);
43
- return he(() => {
44
- if (!e || !C || q) {
45
- if (Z(), e && !C) {
46
- l.current.horizontal && e.getObjects().includes(l.current.horizontal) && e.remove(l.current.horizontal), l.current.vertical && e.getObjects().includes(l.current.vertical) && e.remove(l.current.vertical), l.current = {
47
- horizontal: null,
48
- vertical: null
49
- };
50
- const o = e.getActiveObject();
51
- e.selection = !1, e.skipTargetFind = !1;
52
- const r = D();
53
- e.getObjects().forEach((i) => {
54
- i instanceof b.Rect && r.has(i) ? i.set({
55
- evented: !0,
56
- selectable: !1,
57
- lockMovementX: !0,
58
- lockMovementY: !0,
59
- lockScalingX: !0,
60
- lockScalingY: !0,
61
- lockRotation: !0
62
- }) : (i.set("evented", !0), i.set("selectable", !0), i instanceof b.Rect && i.set("hasControls", !0));
63
- }), o && e.getObjects().includes(o) && (e.setActiveObject(o), e.renderAll()), e.defaultCursor = "default", e.setCursor("default");
64
- }
65
- return;
66
- }
67
- Z(), e.selection = !1, e.skipTargetFind = !0, e.getActiveObject() && (e.discardActiveObject(), e.renderAll()), e.getObjects().forEach((o) => {
68
- o.set("evented", !1), o.set("selectable", !1), o instanceof b.Rect && o.hasControls && o.set("hasControls", !1);
69
- }), e.defaultCursor = "crosshair", e.setCursor("crosshair"), l.current.horizontal && e.getObjects().includes(l.current.horizontal) && e.remove(l.current.horizontal), l.current.vertical && e.getObjects().includes(l.current.vertical) && e.remove(l.current.vertical), l.current = {
70
- horizontal: null,
71
- vertical: null
72
- };
73
- const T = e.getWidth(), W = e.getHeight(), m = e.getZoom(), L = T / m, A = W / m, O = Math.max(L, A) * 3, F = ke / m, S = new b.Line([-O, 0, O, 0], {
74
- stroke: me,
75
- strokeWidth: F,
76
- strokeDashArray: ge,
77
- selectable: !1,
78
- evented: !1,
79
- excludeFromExport: !0,
80
- // 导出时不包含此线
81
- strokeUniform: !0,
82
- // 设置为 true,使线宽随缩放调整以保持视觉一致
83
- visible: !1
84
- // 初始状态隐藏,只有鼠标进入画布时才显示
85
- }), _ = new b.Line([0, -O, 0, O], {
86
- stroke: me,
87
- strokeWidth: F,
88
- strokeDashArray: ge,
89
- selectable: !1,
90
- evented: !1,
91
- excludeFromExport: !0,
92
- // 导出时不包含此线
93
- strokeUniform: !0,
94
- // 设置为 true,使线宽随缩放调整以保持视觉一致
95
- visible: !1
96
- // 初始状态隐藏,只有鼠标进入画布时才显示
97
- });
98
- l.current = {
99
- horizontal: S,
100
- vertical: _
101
- }, e.add(S), e.add(_), S.sendToBack(), _.sendToBack();
102
- const z = (o, r) => {
103
- const i = l.current.horizontal, d = l.current.vertical;
104
- if (!i || !d)
105
- return;
106
- const u = e.getZoom(), g = e.getWidth(), c = e.getHeight(), k = g / u, p = c / u, f = Math.max(k, p) * 3;
107
- i.set({
108
- x1: o - f,
109
- y1: r,
110
- x2: o + f,
111
- y2: r,
112
- visible: !0
113
- // 显示辅助线
114
- }), d.set({
115
- x1: o,
116
- y1: r - f,
117
- x2: o,
118
- y2: r + f,
119
- visible: !0
120
- // 显示辅助线
121
- }), i.sendToBack(), d.sendToBack(), e.renderAll();
122
- }, E = () => {
123
- const o = l.current.horizontal, r = l.current.vertical;
124
- !o || !r || (o.set({
125
- visible: !1
126
- }), r.set({
127
- visible: !1
128
- }), e.renderAll());
129
- }, t = Le.current, H = (o) => {
130
- if (e.skipTargetFind && (t.dleft === -1 || t.dtop === -1)) {
131
- const r = e.getPointer(o.e);
132
- t.dleft = r.x, t.dtop = r.y;
133
- }
134
- }, Ae = (o) => {
135
- const r = e.getPointer(o.e);
136
- z(r.x, r.y);
137
- }, B = (o) => {
138
- if (Ae(o), t.dleft === -1 || t.dtop === -1)
139
- return;
140
- const r = e.getPointer(o.e);
141
- let i = r.x, d = r.y;
142
- if (t.dw = Math.abs(i - t.dleft), t.dh = Math.abs(d - t.dtop), t.dw === 0 || t.dh === 0)
143
- return;
144
- let u = t.dtop > d ? d : t.dtop, g = t.dleft > i ? i : t.dleft, c = t.dw, k = t.dh;
145
- t.rect && e.remove(t.rect);
146
- const p = e.getZoom(), f = K / p;
147
- t.rect = new b.Rect({
148
- left: g,
149
- top: u,
150
- width: c,
151
- height: k,
152
- fill: be,
153
- stroke: G,
154
- strokeWidth: f,
155
- strokeUniform: !0,
156
- // 边框宽度不受缩放影响
157
- strokeDashArray: pe,
158
- selectable: !1,
159
- evented: !1,
160
- objectCaching: !1,
161
- // 禁用缓存,避免缩放时边框变虚
162
- statefullCache: !1,
163
- noScaleCache: !1
164
- }), e.add(t.rect), e.renderAll();
165
- }, I = (o) => {
166
- if (t.dleft === -1 || t.dtop === -1) {
167
- t.dtop = -1, t.dleft = -1;
168
- return;
169
- }
170
- const r = e.getPointer(o.e);
171
- let i = r.x, d = r.y;
172
- if (t.dw = Math.abs(i - t.dleft), t.dh = Math.abs(d - t.dtop), t.dw === 0 || t.dh === 0) {
173
- t.rect && (e.remove(t.rect), e.renderAll()), t.dtop = -1, t.dleft = -1;
174
- return;
175
- }
176
- let u = t.dtop > d ? d : t.dtop, g = t.dleft > i ? i : t.dleft, c = t.dw, k = t.dh;
177
- t.rect && (e.remove(t.rect), t.rect = null);
178
- const p = Q(g, u), f = c, N = k, x = e.getZoom(), w = K / x, n = new b.Rect({
179
- left: g,
180
- top: u,
181
- width: c,
182
- height: k,
183
- fill: Ee,
184
- // 无填充色
185
- stroke: G,
186
- strokeWidth: w,
187
- strokeUniform: !0,
188
- // 边框宽度不受缩放影响
189
- selectable: !0,
190
- evented: !0,
191
- hasRotatingPoint: !1,
192
- // 隐藏旋转点
193
- lockRotation: !0,
194
- // 锁定旋转
195
- lockUniScaling: !1,
196
- // 允许非等比缩放,控制点跟随鼠标
197
- lockScalingFlip: !0,
198
- // 禁止缩放时翻转
199
- objectCaching: !1,
200
- // 禁用缓存,避免缩放时边框变虚
201
- statefullCache: !1,
202
- noScaleCache: !1,
203
- hasControls: !0
204
- // 启用控件
205
- });
206
- e.add(n), n.controls.deleteControl = ee(), n.controls.ocrControl = te(), n.set("hasControls", !1);
207
- const $ = h.current.size, Y = {};
208
- X == null || X.forEach((s) => {
209
- Y[s.id] = "";
210
- });
211
- const j = {
212
- id: `region-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
213
- name: `${xe}${$ + 1}`,
214
- // 设置名称:区域+(索引+1)
215
- shape: {
216
- name: "rect",
217
- x: Math.max(0, p.x),
218
- y: Math.max(0, p.y),
219
- width: f,
220
- height: N
221
- },
222
- content: Y
223
- };
224
- if (h.current.set(n, j), oe(n, j), P(n), U) {
225
- const s = h.current.get(n);
226
- s && U(s, "create");
227
- }
228
- V(j).then((s) => {
229
- if (s) {
230
- const y = h.current.get(n);
231
- if (y) {
232
- if (y.image = s, delete y.textLayouts, a) {
233
- const Oe = Array.from(h.current.values());
234
- a(Oe);
235
- }
236
- v(y, "create");
237
- }
238
- }
239
- }).catch((s) => {
240
- console.error("Failed to crop region image:", s);
241
- }), e.setActiveObject(n), e.renderAll(), setTimeout(() => {
242
- if (M) {
243
- const s = h.current.get(n);
244
- s && M(s);
245
- }
246
- setTimeout(() => {
247
- if (e && n && e.getObjects().includes(n) && (e.setActiveObject(n), e.renderAll(), M)) {
248
- const s = h.current.get(n);
249
- s && M(s);
250
- }
251
- }, 0);
252
- }, 0), ie(n), n.on("modified", () => {
253
- P(n);
254
- }), n.on("moved", () => {
255
- P(n);
256
- }), setTimeout(() => {
257
- if (a) {
258
- const s = Array.from(h.current.values());
259
- a(s);
260
- }
261
- }, 0), t.dtop = -1, t.dleft = -1, e.selection = !1, J(!1);
262
- }, le = (o) => {
263
- const i = e.getElement().getBoundingClientRect(), d = o.clientX, u = o.clientY, g = d >= i.left && d <= i.right && u >= i.top && u <= i.bottom;
264
- if (g) {
265
- const c = e.getPointer(o);
266
- z(c.x, c.y);
267
- } else
268
- E();
269
- if (!(t.dleft === -1 || t.dtop === -1))
270
- if (g) {
271
- const c = e.getPointer(o);
272
- B({
273
- e: o,
274
- pointer: c
275
- });
276
- } else {
277
- const c = e.getZoom(), k = e.viewportTransform ? e.viewportTransform[4] / c : 0, p = e.viewportTransform ? e.viewportTransform[5] / c : 0, f = e.getWidth() / c, N = e.getHeight() / c;
278
- let x = (d - i.left) / c - k, w = (u - i.top) / c - p;
279
- if (x = Math.max(0, Math.min(x, f)), w = Math.max(0, Math.min(w, N)), t.dw = Math.abs(x - t.dleft), t.dh = Math.abs(w - t.dtop), t.dw === 0 || t.dh === 0)
280
- return;
281
- let n = t.dtop > w ? w : t.dtop, $ = t.dleft > x ? x : t.dleft, Y = t.dw, j = t.dh;
282
- t.rect && e.remove(t.rect);
283
- const s = e.getZoom(), y = K / s;
284
- t.rect = new b.Rect({
285
- left: $,
286
- top: n,
287
- width: Y,
288
- height: j,
289
- fill: be,
290
- stroke: G,
291
- strokeWidth: y,
292
- strokeUniform: !0,
293
- strokeDashArray: pe,
294
- selectable: !1,
295
- evented: !1,
296
- objectCaching: !1,
297
- statefullCache: !1,
298
- noScaleCache: !1
299
- }), e.add(t.rect), e.renderAll();
300
- }
301
- }, ne = () => {
302
- E();
303
- }, se = (o) => {
304
- const r = e.getPointer(o.e);
305
- z(r.x, r.y);
306
- }, ce = (o) => {
307
- if (!C)
308
- return;
309
- e.skipTargetFind = !0, e.getActiveObject() && (e.discardActiveObject(), e.renderAll()), t.dtop = -1, t.dleft = -1, t.dw = 0, t.dh = 0;
310
- const i = e.getPointer(o.e);
311
- t.dleft = i.x, t.dtop = i.y;
312
- };
313
- e.on("mouse:down:before", ce), e.on("mouse:down", H), e.on("mouse:move", B), e.on("mouse:up", I), e.on("mouse:out", ne), e.on("mouse:over", se), document.addEventListener("mousemove", le);
314
- const de = (o) => {
315
- if (t.dleft === -1 || t.dtop === -1)
316
- return;
317
- const r = e.getPointer(o);
318
- I({
319
- e: o,
320
- pointer: r
321
- });
322
- };
323
- return document.addEventListener("mouseup", de), () => {
324
- e.off("mouse:down:before", ce), e.off("mouse:down", H), e.off("mouse:move", B), e.off("mouse:up", I), e.off("mouse:out", ne), e.off("mouse:over", se), document.removeEventListener("mousemove", le), document.removeEventListener("mouseup", de), t.rect && (e.remove(t.rect), e.renderAll()), l.current.horizontal && e.getObjects().includes(l.current.horizontal) && e.remove(l.current.horizontal), l.current.vertical && e.getObjects().includes(l.current.vertical) && e.remove(l.current.vertical), l.current = {
325
- horizontal: null,
326
- vertical: null
327
- }, e.skipTargetFind = !1;
328
- const o = D();
329
- e.getObjects().forEach((r) => {
330
- r instanceof b.Rect && o.has(r) ? r.set({
331
- evented: !0,
332
- selectable: !1,
333
- lockMovementX: !0,
334
- lockMovementY: !0,
335
- lockScalingX: !0,
336
- lockScalingY: !0,
337
- lockRotation: !0
338
- }) : (r.set("evented", !0), r.set("selectable", !0));
339
- });
340
- };
341
- }, [e, C, q, Z, Q, a, V, P, v, ee, te, oe, U, M, J, h, D, ie]), he(() => {
342
- if (!e || !C)
343
- return;
344
- let R = e.getZoom();
345
- const T = () => {
346
- const m = l.current.horizontal, L = l.current.vertical;
347
- if (!m || !L)
348
- return;
349
- const A = e.getZoom();
350
- if (Math.abs(A - R) < 1e-3)
351
- return;
352
- R = A;
353
- const O = ke / A, F = e.getWidth(), S = e.getHeight(), _ = F / A, z = S / A, E = Math.max(_, z) * 3, t = (m.x1 + m.x2) / 2;
354
- m.y1, L.x1;
355
- const H = (L.y1 + L.y2) / 2;
356
- m.set({
357
- strokeWidth: O,
358
- x1: t - E,
359
- x2: t + E
360
- }), L.set({
361
- strokeWidth: O,
362
- y1: H - E,
363
- y2: H + E
364
- }), e.renderAll();
365
- }, W = () => {
366
- T();
367
- };
368
- return e.on("after:render", W), T(), () => {
369
- e.off("after:render", W);
370
- };
371
- }, [e, C]), {
372
- stopDraw: Z
373
- };
374
- };
375
- export {
376
- Te as useDrawingMode
377
- };
@@ -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
- };