@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.
- package/dist/dataset-annotation.js +123598 -0
- package/dist/dataset-annotation.umd.cjs +1017 -0
- package/dist/es/DatasetContext/index.mjs +6 -3
- package/dist/es/components/Iconfont/index.mjs +2 -2
- package/dist/es/components/PicZipImportModal/config.mjs +41 -0
- package/dist/es/components/PicZipImportModal/index.mjs +317 -301
- package/dist/es/components/PicZipImportModal/pic_vlm_json_zip.svg.mjs +4 -0
- package/dist/es/components/PicZipImportModal/pic_vlm_zip.svg.mjs +4 -0
- package/dist/es/components/VLMAnnotation/RegionItem.mjs +95 -0
- package/dist/es/components/VLMAnnotation/TextAnnotationPanel.mjs +83 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasDrag.mjs +75 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasSetup.mjs +115 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasZoom.mjs +42 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useCropRegionImage.mjs +55 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteControl.mjs +51 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteRegion.mjs +47 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useDrawingMode.mjs +220 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRLoadingIcon.mjs +106 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRRecognition.mjs +68 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionHover.mjs +38 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionLoader.mjs +141 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionNameText.mjs +72 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionSelection.mjs +102 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionUpdate.mjs +103 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/hooks/useTextLayouts.mjs +156 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/icons/del.png.mjs +4 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/index.mjs +507 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/style.less.mjs +4 -0
- package/dist/es/components/VLMAnnotation/VLMLabelMaker/utils/coordinateUtils.mjs +33 -0
- package/dist/es/components/VLMAnnotation/components/DragButton.mjs +18 -0
- package/dist/es/components/VLMAnnotation/components/FitToScreenButton.mjs +16 -0
- package/dist/es/components/VLMAnnotation/components/RectangleButton.mjs +30 -0
- package/dist/es/components/VLMAnnotation/components/Toolbar.mjs +40 -0
- package/dist/es/components/VLMAnnotation/components/ZoomControls.mjs +44 -0
- package/dist/es/components/VLMAnnotation/constants.mjs +50 -0
- package/dist/es/components/VLMAnnotation/index.mjs +242 -0
- package/dist/es/components/VLMAnnotation/style.less.mjs +4 -0
- package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/AttributeDetail/index.mjs +345 -0
- package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/AttributeDetail/style.less.mjs +4 -0
- package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/QAGenerationConfig.mjs +240 -0
- package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/index.mjs +201 -0
- package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/style.less.mjs +4 -0
- package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/index.mjs +399 -0
- package/dist/es/components/VLMAnnotationDetail/MarkVLMBoxModal/style.less.mjs +4 -0
- package/dist/es/components/VLMAnnotationDetail/VlmModal/index.mjs +139 -0
- package/dist/es/components/VLMAnnotationDetail/VlmModal/style.less.mjs +4 -0
- package/dist/es/components/VLMAnnotationDetail/index.mjs +446 -0
- package/dist/es/components/VLMAnnotationDetail/style.less.mjs +4 -0
- package/dist/es/constant.mjs +3 -3
- package/dist/es/createVlmtasetAnnotation/index.mjs +131 -0
- package/dist/es/featuresConfig.mjs +13 -9
- package/dist/es/index.mjs +11 -7
- package/dist/example/DatasetAnnotationDemo.d.ts +3 -0
- package/dist/example/DemoTabs.d.ts +3 -0
- package/dist/example/DetectionDatasetDemo.d.ts +5 -0
- package/dist/example/DetectionImageDemo.d.ts +5 -0
- package/dist/example/OcrDatasetDemo.d.ts +5 -0
- package/dist/example/OcrImageDemo.d.ts +5 -0
- package/dist/example/OcrkvcDatasetDemo.d.ts +5 -0
- package/dist/example/constant.local.d.ts +6 -0
- package/dist/example/index.d.ts +1 -0
- package/dist/lib/index.js +4 -3
- package/dist/src/DatasetContext/index.d.ts +2 -0
- package/dist/src/components/Iconfont/font_4439177_tgvowh6bmlb.d.ts +0 -0
- package/dist/src/components/PicZipImportModal/config.d.ts +20 -0
- package/dist/src/components/VLMAnnotation/ImageAnnotationDebugger.d.ts +4 -0
- package/dist/src/components/VLMAnnotation/RegionItem.d.ts +4 -0
- package/dist/src/components/VLMAnnotation/TextAnnotationPanel.d.ts +4 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasDrag.d.ts +12 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasSetup.d.ts +38 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCanvasZoom.d.ts +18 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useCropRegionImage.d.ts +7 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteControl.d.ts +13 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDeleteRegion.d.ts +21 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useDrawingMode.d.ts +31 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRLoadingIcon.d.ts +11 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useOCRRecognition.d.ts +28 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionHover.d.ts +13 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionLoader.d.ts +37 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionNameText.d.ts +12 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionSelection.d.ts +15 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useRegionUpdate.d.ts +32 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/hooks/useTextLayouts.d.ts +25 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/index.d.ts +4 -0
- package/dist/src/components/VLMAnnotation/VLMLabelMaker/utils/coordinateUtils.d.ts +32 -0
- package/dist/src/components/VLMAnnotation/components/DragButton.d.ts +7 -0
- package/dist/src/components/VLMAnnotation/components/FitToScreenButton.d.ts +6 -0
- package/dist/src/components/VLMAnnotation/components/RectangleButton.d.ts +7 -0
- package/dist/src/components/VLMAnnotation/components/Toolbar.d.ts +4 -0
- package/dist/src/components/VLMAnnotation/components/ZoomControls.d.ts +4 -0
- package/dist/src/components/VLMAnnotation/constants.d.ts +97 -0
- package/dist/src/components/VLMAnnotation/index.d.ts +6 -0
- package/dist/src/components/VLMAnnotation/types.d.ts +172 -0
- package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/AttributeDetail/index.d.ts +14 -0
- package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/ImageDetail/index.d.ts +16 -0
- package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/OCRBoxMaker/LabelEditorInput.d.ts +12 -0
- package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/OCRBoxMaker/LabelEditorItem.d.ts +21 -0
- package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/OCRBoxMaker/LableEditor.d.ts +16 -0
- package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/OCRBoxMaker/index.d.ts +19 -0
- package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/QAGenerationConfig.d.ts +12 -0
- package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/QADetail/index.d.ts +12 -0
- package/dist/src/components/VLMAnnotationDetail/MarkVLMBoxModal/index.d.ts +12 -0
- package/dist/src/components/VLMAnnotationDetail/VlmModal/index.d.ts +16 -0
- package/dist/src/components/VLMAnnotationDetail/index.d.ts +6 -0
- package/dist/src/constant.d.ts +1 -1
- package/dist/src/createVlmtasetAnnotation/index.d.ts +16 -0
- package/dist/src/featuresConfig.d.ts +4 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/utils/reactCompatibility.d.ts +5 -0
- package/package.json +2 -2
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var l = Math.pow;
|
|
2
|
+
import { useCallback as h, useEffect as C } from "react";
|
|
3
|
+
import { ZOOM_FACTOR as M, MAX_ZOOM as n, MIN_ZOOM as O } from "../../constants.mjs";
|
|
4
|
+
const w = ({
|
|
5
|
+
canvas: t,
|
|
6
|
+
setScale: m,
|
|
7
|
+
isZoomingRef: f
|
|
8
|
+
}) => {
|
|
9
|
+
const u = h((r, o) => {
|
|
10
|
+
if (!t)
|
|
11
|
+
return;
|
|
12
|
+
o || (o = {
|
|
13
|
+
x: t.getCenter().left,
|
|
14
|
+
y: t.getCenter().top
|
|
15
|
+
});
|
|
16
|
+
let e = t.getZoom();
|
|
17
|
+
e *= l(M, r), e > n && (e = n), e < O && (e = O), f.current = !0, t.zoomToPoint(o, e), m(e), requestAnimationFrame(() => {
|
|
18
|
+
requestAnimationFrame(() => {
|
|
19
|
+
f.current = !1;
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}, [t, m, f]);
|
|
23
|
+
return C(() => {
|
|
24
|
+
if (!t)
|
|
25
|
+
return;
|
|
26
|
+
const r = (o) => {
|
|
27
|
+
const e = o.e, i = e.deltaY;
|
|
28
|
+
u(i, {
|
|
29
|
+
x: e.offsetX,
|
|
30
|
+
y: e.offsetY
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
return t.on("mouse:wheel", r), () => {
|
|
34
|
+
t.off("mouse:wheel", r);
|
|
35
|
+
};
|
|
36
|
+
}, [t, u]), {
|
|
37
|
+
zoom: u
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export {
|
|
41
|
+
w as useCanvasZoom
|
|
42
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var f = (r, p, n) => new Promise((i, a) => {
|
|
2
|
+
var t = (o) => {
|
|
3
|
+
try {
|
|
4
|
+
c(n.next(o));
|
|
5
|
+
} catch (s) {
|
|
6
|
+
a(s);
|
|
7
|
+
}
|
|
8
|
+
}, e = (o) => {
|
|
9
|
+
try {
|
|
10
|
+
c(n.throw(o));
|
|
11
|
+
} catch (s) {
|
|
12
|
+
a(s);
|
|
13
|
+
}
|
|
14
|
+
}, c = (o) => o.done ? i(o.value) : Promise.resolve(o.value).then(t, e);
|
|
15
|
+
c((n = n.apply(r, p)).next());
|
|
16
|
+
});
|
|
17
|
+
import { useCallback as l } from "react";
|
|
18
|
+
import { IMAGE_EXPORT_FORMAT as A } from "../../constants.mjs";
|
|
19
|
+
const _ = (r) => l((n) => f(void 0, null, function* () {
|
|
20
|
+
if (r)
|
|
21
|
+
return new Promise((i, a) => {
|
|
22
|
+
const t = new Image();
|
|
23
|
+
t.crossOrigin = "anonymous", t.onload = () => {
|
|
24
|
+
try {
|
|
25
|
+
const {
|
|
26
|
+
x: e,
|
|
27
|
+
y: c,
|
|
28
|
+
width: o,
|
|
29
|
+
height: s
|
|
30
|
+
} = n.shape, x = e, M = e + o, w = c, I = c + s, T = 0, y = t.width, E = 0, L = t.height, d = Math.max(T, x), v = Math.min(y, M), u = Math.max(E, w), B = Math.min(L, I), m = Math.max(0, v - d), g = Math.max(0, B - u);
|
|
31
|
+
if (m <= 0 || g <= 0) {
|
|
32
|
+
i(void 0);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const C = d, O = u, h = document.createElement("canvas");
|
|
36
|
+
h.width = m, h.height = g;
|
|
37
|
+
const R = h.getContext("2d");
|
|
38
|
+
if (!R) {
|
|
39
|
+
i(void 0);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
R.drawImage(t, C, O, m, g, 0, 0, m, g);
|
|
43
|
+
const b = h.toDataURL(A);
|
|
44
|
+
i(b);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
a(e);
|
|
47
|
+
}
|
|
48
|
+
}, t.onerror = () => {
|
|
49
|
+
a(new Error("Failed to load image"));
|
|
50
|
+
}, t.src = r;
|
|
51
|
+
});
|
|
52
|
+
}), [r]);
|
|
53
|
+
export {
|
|
54
|
+
_ as useCropRegionImage
|
|
55
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useRef as E, useEffect as I, useCallback as g } from "react";
|
|
2
|
+
import { fabric as f } from "fabric";
|
|
3
|
+
import { DELETE_CONTROL_OFFSET_X as O, DELETE_CONTROL_OFFSET_Y as C, DELETE_ICON_SIZE as T } from "../../constants.mjs";
|
|
4
|
+
import _ from "../icons/del.png.mjs";
|
|
5
|
+
const S = ({
|
|
6
|
+
performDelete: a
|
|
7
|
+
}) => {
|
|
8
|
+
const i = (e) => !(!e.complete || e.naturalWidth === 0), n = E(null);
|
|
9
|
+
return I(() => {
|
|
10
|
+
if (!n.current) {
|
|
11
|
+
const e = document.createElement("img");
|
|
12
|
+
e.src = _, n.current = e;
|
|
13
|
+
}
|
|
14
|
+
}, []), {
|
|
15
|
+
createDeleteControl: g(() => {
|
|
16
|
+
const e = T, r = n.current, d = (t, o, s, D, l) => {
|
|
17
|
+
if (!r)
|
|
18
|
+
return;
|
|
19
|
+
const c = () => {
|
|
20
|
+
t.save(), t.translate(o, s), t.rotate(f.util.degreesToRadians(l.angle || 0)), t.drawImage(r, -e / 2, -e / 2, e, e), t.restore();
|
|
21
|
+
};
|
|
22
|
+
i(r) ? c() : r.onload = () => {
|
|
23
|
+
c();
|
|
24
|
+
const u = l.canvas;
|
|
25
|
+
u && u.renderAll();
|
|
26
|
+
};
|
|
27
|
+
}, m = (t, o) => {
|
|
28
|
+
const s = o.target;
|
|
29
|
+
return a(s), !1;
|
|
30
|
+
};
|
|
31
|
+
return new f.Control({
|
|
32
|
+
x: 0.5,
|
|
33
|
+
// 右侧(0 = 左边,0.5 = 中间,1 = 右边)
|
|
34
|
+
y: -0.5,
|
|
35
|
+
// 顶部(0 = 顶部,0.5 = 中间,1 = 底部)
|
|
36
|
+
offsetX: O,
|
|
37
|
+
// 向右偏移,让按钮更靠近矩形边缘
|
|
38
|
+
offsetY: C,
|
|
39
|
+
// 向上偏移,让按钮更靠近矩形边缘
|
|
40
|
+
cursorStyle: "pointer",
|
|
41
|
+
mouseUpHandler: m,
|
|
42
|
+
render: d,
|
|
43
|
+
sizeX: e,
|
|
44
|
+
sizeY: e
|
|
45
|
+
});
|
|
46
|
+
}, [a])
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
export {
|
|
50
|
+
S as useDeleteControl
|
|
51
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useRef as t, useCallback as A } from "react";
|
|
2
|
+
import { Modal as L } from "antd";
|
|
3
|
+
import { DELETE_MODAL_TITLE as O, DELETE_MODAL_CONTENT as c, DELETE_MODAL_OK_TEXT as k, DELETE_MODAL_CANCEL_TEXT as C } from "../../constants.mjs";
|
|
4
|
+
const v = ({
|
|
5
|
+
canvas: r,
|
|
6
|
+
onRegionChange: u,
|
|
7
|
+
updateRegionNames: T,
|
|
8
|
+
rectMapRef: f,
|
|
9
|
+
textLayersMapRef: n,
|
|
10
|
+
textLayoutContentMapRef: D,
|
|
11
|
+
regionNameTextMapRef: E,
|
|
12
|
+
ocrLoadingIconMapRef: m
|
|
13
|
+
}) => {
|
|
14
|
+
const o = t(!1);
|
|
15
|
+
return {
|
|
16
|
+
performDelete: A((e) => {
|
|
17
|
+
if (!r || o.current)
|
|
18
|
+
return;
|
|
19
|
+
const d = f.current.get(e);
|
|
20
|
+
d && (o.current = !0, L.confirm({
|
|
21
|
+
title: O,
|
|
22
|
+
content: c,
|
|
23
|
+
okText: k,
|
|
24
|
+
cancelText: C,
|
|
25
|
+
onOk: () => {
|
|
26
|
+
const i = n.current.get(e);
|
|
27
|
+
i && (i.forEach((l) => {
|
|
28
|
+
l.off("mousedown"), l.off("mouseover"), l.off("mouseout"), D.current.delete(l), r.remove(l);
|
|
29
|
+
}), n.current.delete(e));
|
|
30
|
+
const s = E.current.get(e);
|
|
31
|
+
s && (e.off("moved"), e.off("modified"), r.remove(s), E.current.delete(e));
|
|
32
|
+
const _ = m.current.get(e);
|
|
33
|
+
_ && (r.remove(_), m.current.delete(e)), r.remove(e), f.current.delete(e), T(), u && u(d, "delete"), r.renderAll(), o.current = !1;
|
|
34
|
+
},
|
|
35
|
+
onCancel: () => {
|
|
36
|
+
o.current = !1;
|
|
37
|
+
},
|
|
38
|
+
afterClose: () => {
|
|
39
|
+
o.current = !1;
|
|
40
|
+
}
|
|
41
|
+
}));
|
|
42
|
+
}, [r, u, T, f, n, D, E, m])
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export {
|
|
46
|
+
v as useDeleteRegion
|
|
47
|
+
};
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { useCallback as V, useEffect as a } from "react";
|
|
2
|
+
import { fabric as X } from "fabric";
|
|
3
|
+
import { TEMP_RECT_FILL_COLOR as I, RECT_STROKE_COLOR as Y, TEMP_RECT_STROKE_DASH_ARRAY as J, TRANSPARENT_FILL as v, REGION_NAME_PREFIX as ee, BASE_STROKE_WIDTH as Z } from "../../constants.mjs";
|
|
4
|
+
const le = ({
|
|
5
|
+
canvas: e,
|
|
6
|
+
drawingMode: x,
|
|
7
|
+
draggable: U,
|
|
8
|
+
setDrawingMode: H,
|
|
9
|
+
canvasToImageCoords: $,
|
|
10
|
+
labelDefinitions: y,
|
|
11
|
+
onChange: j,
|
|
12
|
+
cropRegionImage: G,
|
|
13
|
+
updateRegionShapeAndImage: _,
|
|
14
|
+
performOCRIfNeeded: K,
|
|
15
|
+
createDeleteControl: B,
|
|
16
|
+
updateRegionNameText: D,
|
|
17
|
+
onRegionChange: P,
|
|
18
|
+
onRegionSelect: T,
|
|
19
|
+
rectMapRef: h
|
|
20
|
+
}) => {
|
|
21
|
+
const M = V(() => {
|
|
22
|
+
e && (e.skipTargetFind = !1);
|
|
23
|
+
}, [e]);
|
|
24
|
+
return a(() => {
|
|
25
|
+
if (!e || !x || U) {
|
|
26
|
+
if (M(), e && !x) {
|
|
27
|
+
const t = e.getActiveObject();
|
|
28
|
+
e.selection = !1, e.skipTargetFind = !1, e.getObjects().forEach((u) => {
|
|
29
|
+
u.set("evented", !0), u.set("selectable", !0);
|
|
30
|
+
}), t && e.getObjects().includes(t) && (e.setActiveObject(t), e.renderAll()), e.defaultCursor = "default", e.setCursor("default");
|
|
31
|
+
}
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
M(), e.selection = !1, e.skipTargetFind = !0, e.getActiveObject() && (e.discardActiveObject(), e.renderAll()), e.getObjects().forEach((t) => {
|
|
35
|
+
t.set("evented", !1), t.set("selectable", !1);
|
|
36
|
+
}), e.defaultCursor = "crosshair", e.setCursor("crosshair");
|
|
37
|
+
let i = -1, l = -1, c = 0, m = 0, f = null;
|
|
38
|
+
const N = (t) => {
|
|
39
|
+
e.getActiveObject() && (e.discardActiveObject(), e.renderAll()), i = -1, l = -1, c = 0, m = 0;
|
|
40
|
+
const s = e.getPointer(t.e);
|
|
41
|
+
l = s.x, i = s.y, e.skipTargetFind = !0;
|
|
42
|
+
}, W = (t) => {
|
|
43
|
+
if (l === -1 || i === -1)
|
|
44
|
+
return;
|
|
45
|
+
const u = e.getPointer(t.e);
|
|
46
|
+
let s = u.x, d = u.y;
|
|
47
|
+
if (c = Math.abs(s - l), m = Math.abs(d - i), c === 0 || m === 0)
|
|
48
|
+
return;
|
|
49
|
+
let g = i > d ? d : i, p = l > s ? s : l, n = c, b = m;
|
|
50
|
+
f && e.remove(f);
|
|
51
|
+
const A = e.getZoom(), C = Z / A;
|
|
52
|
+
f = new X.Rect({
|
|
53
|
+
left: p,
|
|
54
|
+
top: g,
|
|
55
|
+
width: n,
|
|
56
|
+
height: b,
|
|
57
|
+
fill: I,
|
|
58
|
+
stroke: Y,
|
|
59
|
+
strokeWidth: C,
|
|
60
|
+
strokeUniform: !0,
|
|
61
|
+
// 边框宽度不受缩放影响
|
|
62
|
+
strokeDashArray: J,
|
|
63
|
+
selectable: !1,
|
|
64
|
+
evented: !1,
|
|
65
|
+
objectCaching: !1,
|
|
66
|
+
// 禁用缓存,避免缩放时边框变虚
|
|
67
|
+
statefullCache: !1,
|
|
68
|
+
noScaleCache: !1
|
|
69
|
+
}), e.add(f), e.renderAll();
|
|
70
|
+
}, F = (t) => {
|
|
71
|
+
if (l === -1 || i === -1) {
|
|
72
|
+
i = -1, l = -1;
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const u = e.getPointer(t.e);
|
|
76
|
+
let s = u.x, d = u.y;
|
|
77
|
+
if (c = Math.abs(s - l), m = Math.abs(d - i), c === 0 || m === 0) {
|
|
78
|
+
f && (e.remove(f), e.renderAll()), i = -1, l = -1;
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
let g = i > d ? d : i, p = l > s ? s : l, n = c, b = m;
|
|
82
|
+
f && (e.remove(f), f = null);
|
|
83
|
+
const A = $(p, g), C = n, R = b, E = e.getZoom(), k = Z / E, o = new X.Rect({
|
|
84
|
+
left: p,
|
|
85
|
+
top: g,
|
|
86
|
+
width: n,
|
|
87
|
+
height: b,
|
|
88
|
+
fill: v,
|
|
89
|
+
// 无填充色
|
|
90
|
+
stroke: Y,
|
|
91
|
+
strokeWidth: k,
|
|
92
|
+
strokeUniform: !0,
|
|
93
|
+
// 边框宽度不受缩放影响
|
|
94
|
+
selectable: !0,
|
|
95
|
+
evented: !0,
|
|
96
|
+
hasRotatingPoint: !1,
|
|
97
|
+
// 隐藏旋转点
|
|
98
|
+
lockRotation: !0,
|
|
99
|
+
// 锁定旋转
|
|
100
|
+
lockUniScaling: !1,
|
|
101
|
+
// 允许非等比缩放,控制点跟随鼠标
|
|
102
|
+
objectCaching: !1,
|
|
103
|
+
// 禁用缓存,避免缩放时边框变虚
|
|
104
|
+
statefullCache: !1,
|
|
105
|
+
noScaleCache: !1
|
|
106
|
+
});
|
|
107
|
+
e.add(o), o.controls.deleteControl = B();
|
|
108
|
+
const S = h.current.size, L = {};
|
|
109
|
+
y == null || y.forEach((r) => {
|
|
110
|
+
L[r.id] = "";
|
|
111
|
+
});
|
|
112
|
+
const w = {
|
|
113
|
+
id: `region-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
114
|
+
name: `${ee}${S + 1}`,
|
|
115
|
+
// 设置名称:区域+(索引+1)
|
|
116
|
+
shape: {
|
|
117
|
+
name: "rect",
|
|
118
|
+
x: Math.max(0, A.x),
|
|
119
|
+
y: Math.max(0, A.y),
|
|
120
|
+
width: C,
|
|
121
|
+
height: R
|
|
122
|
+
},
|
|
123
|
+
content: L
|
|
124
|
+
};
|
|
125
|
+
if (h.current.set(o, w), D(o, w), _(o), P) {
|
|
126
|
+
const r = h.current.get(o);
|
|
127
|
+
r && P(r, "create");
|
|
128
|
+
}
|
|
129
|
+
G(w).then((r) => {
|
|
130
|
+
if (r) {
|
|
131
|
+
const O = h.current.get(o);
|
|
132
|
+
if (O) {
|
|
133
|
+
if (O.image = r, delete O.textLayouts, j) {
|
|
134
|
+
const Q = Array.from(h.current.values());
|
|
135
|
+
j(Q);
|
|
136
|
+
}
|
|
137
|
+
K(O, "create");
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}).catch((r) => {
|
|
141
|
+
console.error("Failed to crop region image:", r);
|
|
142
|
+
}), e.setActiveObject(o), e.renderAll(), setTimeout(() => {
|
|
143
|
+
if (T) {
|
|
144
|
+
const r = h.current.get(o);
|
|
145
|
+
r && T(r);
|
|
146
|
+
}
|
|
147
|
+
setTimeout(() => {
|
|
148
|
+
if (e && o && e.getObjects().includes(o) && (e.setActiveObject(o), e.renderAll(), T)) {
|
|
149
|
+
const r = h.current.get(o);
|
|
150
|
+
r && T(r);
|
|
151
|
+
}
|
|
152
|
+
}, 0);
|
|
153
|
+
}, 0), o.on("modified", () => {
|
|
154
|
+
_(o);
|
|
155
|
+
}), o.on("moved", () => {
|
|
156
|
+
_(o);
|
|
157
|
+
}), setTimeout(() => {
|
|
158
|
+
if (j) {
|
|
159
|
+
const r = Array.from(h.current.values());
|
|
160
|
+
j(r);
|
|
161
|
+
}
|
|
162
|
+
}, 0), i = -1, l = -1, e.selection = !1, H(!1);
|
|
163
|
+
}, z = (t) => {
|
|
164
|
+
if (l === -1 || i === -1)
|
|
165
|
+
return;
|
|
166
|
+
const s = e.getElement().getBoundingClientRect(), d = t.clientX, g = t.clientY;
|
|
167
|
+
if (d >= s.left && d <= s.right && g >= s.top && g <= s.bottom) {
|
|
168
|
+
const n = e.getPointer(t);
|
|
169
|
+
W({
|
|
170
|
+
e: t,
|
|
171
|
+
pointer: n
|
|
172
|
+
});
|
|
173
|
+
} else {
|
|
174
|
+
const n = e.getZoom(), b = e.viewportTransform ? e.viewportTransform[4] / n : 0, A = e.viewportTransform ? e.viewportTransform[5] / n : 0, C = e.getWidth() / n, R = e.getHeight() / n;
|
|
175
|
+
let E = (d - s.left) / n - b, k = (g - s.top) / n - A;
|
|
176
|
+
if (E = Math.max(0, Math.min(E, C)), k = Math.max(0, Math.min(k, R)), c = Math.abs(E - l), m = Math.abs(k - i), c === 0 || m === 0)
|
|
177
|
+
return;
|
|
178
|
+
let o = i > k ? k : i, S = l > E ? E : l, L = c, w = m;
|
|
179
|
+
f && e.remove(f);
|
|
180
|
+
const r = e.getZoom(), O = Z / r;
|
|
181
|
+
f = new X.Rect({
|
|
182
|
+
left: S,
|
|
183
|
+
top: o,
|
|
184
|
+
width: L,
|
|
185
|
+
height: w,
|
|
186
|
+
fill: I,
|
|
187
|
+
stroke: Y,
|
|
188
|
+
strokeWidth: O,
|
|
189
|
+
strokeUniform: !0,
|
|
190
|
+
strokeDashArray: J,
|
|
191
|
+
selectable: !1,
|
|
192
|
+
evented: !1,
|
|
193
|
+
objectCaching: !1,
|
|
194
|
+
statefullCache: !1,
|
|
195
|
+
noScaleCache: !1
|
|
196
|
+
}), e.add(f), e.renderAll();
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
e.on("mouse:down", N), e.on("mouse:move", W), e.on("mouse:up", F), document.addEventListener("mousemove", z);
|
|
200
|
+
const q = (t) => {
|
|
201
|
+
if (l === -1 || i === -1)
|
|
202
|
+
return;
|
|
203
|
+
const u = e.getPointer(t);
|
|
204
|
+
F({
|
|
205
|
+
e: t,
|
|
206
|
+
pointer: u
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
return document.addEventListener("mouseup", q), () => {
|
|
210
|
+
e.off("mouse:down", N), e.off("mouse:move", W), e.off("mouse:up", F), document.removeEventListener("mousemove", z), document.removeEventListener("mouseup", q), f && (e.remove(f), e.renderAll()), e.skipTargetFind = !1, e.getObjects().forEach((t) => {
|
|
211
|
+
t.set("evented", !0), t.set("selectable", !0);
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
}, [e, x, U, M, $, j, G, _, K, B, D, P, T, H, h]), {
|
|
215
|
+
stopDraw: M
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
export {
|
|
219
|
+
le as useDrawingMode
|
|
220
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
};
|
|
@@ -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
|
+
};
|