react-native-rectangle-doc-scanner 0.24.0 → 0.25.0
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/DocScanner.js +7 -1
- package/dist/utils/overlay.d.ts +4 -0
- package/dist/utils/overlay.js +20 -6
- package/package.json +1 -1
- package/src/DocScanner.tsx +9 -1
- package/src/utils/overlay.tsx +25 -6
package/dist/DocScanner.js
CHANGED
|
@@ -123,10 +123,16 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
|
|
|
123
123
|
console.log('[DocScanner] stage', stage);
|
|
124
124
|
}
|
|
125
125
|
}, []);
|
|
126
|
+
const [frameSize, setFrameSize] = (0, react_1.useState)(null);
|
|
127
|
+
const updateFrameSize = (0, react_native_worklets_core_1.useRunOnJS)((width, height) => {
|
|
128
|
+
setFrameSize({ width, height });
|
|
129
|
+
}, []);
|
|
126
130
|
const frameProcessor = (0, react_native_vision_camera_1.useFrameProcessor)((frame) => {
|
|
127
131
|
'worklet';
|
|
128
132
|
let step = 'start';
|
|
129
133
|
try {
|
|
134
|
+
// Report frame size for coordinate transformation
|
|
135
|
+
updateFrameSize(frame.width, frame.height);
|
|
130
136
|
const ratio = 480 / frame.width;
|
|
131
137
|
const width = Math.floor(frame.width * ratio);
|
|
132
138
|
const height = Math.floor(frame.height * ratio);
|
|
@@ -314,7 +320,7 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
|
|
|
314
320
|
}
|
|
315
321
|
return (react_1.default.createElement(react_native_1.View, { style: { flex: 1 } },
|
|
316
322
|
react_1.default.createElement(react_native_vision_camera_1.Camera, { ref: handleCameraRef, style: react_native_1.StyleSheet.absoluteFillObject, device: resolvedDevice, isActive: true, photo: true, frameProcessor: frameProcessor, frameProcessorFps: 15, ...cameraRestProps }),
|
|
317
|
-
react_1.default.createElement(overlay_1.Overlay, { quad: quad, color: overlayColor }),
|
|
323
|
+
react_1.default.createElement(overlay_1.Overlay, { quad: quad, color: overlayColor, frameSize: frameSize }),
|
|
318
324
|
!autoCapture && (react_1.default.createElement(react_native_1.TouchableOpacity, { style: styles.button, onPress: async () => {
|
|
319
325
|
if (!camera.current) {
|
|
320
326
|
return;
|
package/dist/utils/overlay.d.ts
CHANGED
package/dist/utils/overlay.js
CHANGED
|
@@ -37,12 +37,12 @@ exports.Overlay = void 0;
|
|
|
37
37
|
const react_1 = __importStar(require("react"));
|
|
38
38
|
const react_native_1 = require("react-native");
|
|
39
39
|
const react_native_skia_1 = require("@shopify/react-native-skia");
|
|
40
|
-
const Overlay = ({ quad, color = '#e7a649' }) => {
|
|
40
|
+
const Overlay = ({ quad, color = '#e7a649', frameSize }) => {
|
|
41
41
|
const { width: screenWidth, height: screenHeight } = (0, react_native_1.useWindowDimensions)();
|
|
42
42
|
const path = (0, react_1.useMemo)(() => {
|
|
43
|
-
if (!quad) {
|
|
43
|
+
if (!quad || !frameSize) {
|
|
44
44
|
if (__DEV__) {
|
|
45
|
-
console.log('[Overlay] no quad');
|
|
45
|
+
console.log('[Overlay] no quad or frameSize', { quad, frameSize });
|
|
46
46
|
}
|
|
47
47
|
return null;
|
|
48
48
|
}
|
|
@@ -50,13 +50,27 @@ const Overlay = ({ quad, color = '#e7a649' }) => {
|
|
|
50
50
|
console.log('[Overlay] drawing quad:', quad);
|
|
51
51
|
console.log('[Overlay] color:', color);
|
|
52
52
|
console.log('[Overlay] screen dimensions:', screenWidth, 'x', screenHeight);
|
|
53
|
+
console.log('[Overlay] frame dimensions:', frameSize.width, 'x', frameSize.height);
|
|
54
|
+
}
|
|
55
|
+
// Transform coordinates from camera frame space to screen space
|
|
56
|
+
const scaleX = screenWidth / frameSize.width;
|
|
57
|
+
const scaleY = screenHeight / frameSize.height;
|
|
58
|
+
if (__DEV__) {
|
|
59
|
+
console.log('[Overlay] scale factors:', scaleX, 'x', scaleY);
|
|
60
|
+
}
|
|
61
|
+
const transformedQuad = quad.map((p) => ({
|
|
62
|
+
x: p.x * scaleX,
|
|
63
|
+
y: p.y * scaleY,
|
|
64
|
+
}));
|
|
65
|
+
if (__DEV__) {
|
|
66
|
+
console.log('[Overlay] transformed quad:', transformedQuad);
|
|
53
67
|
}
|
|
54
68
|
const skPath = react_native_skia_1.Skia.Path.Make();
|
|
55
|
-
skPath.moveTo(
|
|
56
|
-
|
|
69
|
+
skPath.moveTo(transformedQuad[0].x, transformedQuad[0].y);
|
|
70
|
+
transformedQuad.slice(1).forEach((p) => skPath.lineTo(p.x, p.y));
|
|
57
71
|
skPath.close();
|
|
58
72
|
return skPath;
|
|
59
|
-
}, [quad, color, screenWidth, screenHeight]);
|
|
73
|
+
}, [quad, color, screenWidth, screenHeight, frameSize]);
|
|
60
74
|
// Test path - always visible for debugging
|
|
61
75
|
const testPath = (0, react_1.useMemo)(() => {
|
|
62
76
|
const tp = react_native_skia_1.Skia.Path.Make();
|
package/package.json
CHANGED
package/src/DocScanner.tsx
CHANGED
|
@@ -133,12 +133,20 @@ export const DocScanner: React.FC<Props> = ({
|
|
|
133
133
|
}
|
|
134
134
|
}, []);
|
|
135
135
|
|
|
136
|
+
const [frameSize, setFrameSize] = useState<{ width: number; height: number } | null>(null);
|
|
137
|
+
const updateFrameSize = useRunOnJS((width: number, height: number) => {
|
|
138
|
+
setFrameSize({ width, height });
|
|
139
|
+
}, []);
|
|
140
|
+
|
|
136
141
|
const frameProcessor = useFrameProcessor((frame) => {
|
|
137
142
|
'worklet';
|
|
138
143
|
|
|
139
144
|
let step = 'start';
|
|
140
145
|
|
|
141
146
|
try {
|
|
147
|
+
// Report frame size for coordinate transformation
|
|
148
|
+
updateFrameSize(frame.width, frame.height);
|
|
149
|
+
|
|
142
150
|
const ratio = 480 / frame.width;
|
|
143
151
|
const width = Math.floor(frame.width * ratio);
|
|
144
152
|
const height = Math.floor(frame.height * ratio);
|
|
@@ -369,7 +377,7 @@ export const DocScanner: React.FC<Props> = ({
|
|
|
369
377
|
frameProcessorFps={15}
|
|
370
378
|
{...cameraRestProps}
|
|
371
379
|
/>
|
|
372
|
-
<Overlay quad={quad} color={overlayColor} />
|
|
380
|
+
<Overlay quad={quad} color={overlayColor} frameSize={frameSize} />
|
|
373
381
|
{!autoCapture && (
|
|
374
382
|
<TouchableOpacity
|
|
375
383
|
style={styles.button}
|
package/src/utils/overlay.tsx
CHANGED
|
@@ -6,15 +6,16 @@ import type { Point } from '../types';
|
|
|
6
6
|
type OverlayProps = {
|
|
7
7
|
quad: Point[] | null;
|
|
8
8
|
color?: string;
|
|
9
|
+
frameSize: { width: number; height: number } | null;
|
|
9
10
|
};
|
|
10
11
|
|
|
11
|
-
export const Overlay: React.FC<OverlayProps> = ({ quad, color = '#e7a649' }) => {
|
|
12
|
+
export const Overlay: React.FC<OverlayProps> = ({ quad, color = '#e7a649', frameSize }) => {
|
|
12
13
|
const { width: screenWidth, height: screenHeight } = useWindowDimensions();
|
|
13
14
|
|
|
14
15
|
const path = useMemo(() => {
|
|
15
|
-
if (!quad) {
|
|
16
|
+
if (!quad || !frameSize) {
|
|
16
17
|
if (__DEV__) {
|
|
17
|
-
console.log('[Overlay] no quad');
|
|
18
|
+
console.log('[Overlay] no quad or frameSize', { quad, frameSize });
|
|
18
19
|
}
|
|
19
20
|
return null;
|
|
20
21
|
}
|
|
@@ -23,14 +24,32 @@ export const Overlay: React.FC<OverlayProps> = ({ quad, color = '#e7a649' }) =>
|
|
|
23
24
|
console.log('[Overlay] drawing quad:', quad);
|
|
24
25
|
console.log('[Overlay] color:', color);
|
|
25
26
|
console.log('[Overlay] screen dimensions:', screenWidth, 'x', screenHeight);
|
|
27
|
+
console.log('[Overlay] frame dimensions:', frameSize.width, 'x', frameSize.height);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Transform coordinates from camera frame space to screen space
|
|
31
|
+
const scaleX = screenWidth / frameSize.width;
|
|
32
|
+
const scaleY = screenHeight / frameSize.height;
|
|
33
|
+
|
|
34
|
+
if (__DEV__) {
|
|
35
|
+
console.log('[Overlay] scale factors:', scaleX, 'x', scaleY);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const transformedQuad = quad.map((p) => ({
|
|
39
|
+
x: p.x * scaleX,
|
|
40
|
+
y: p.y * scaleY,
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
if (__DEV__) {
|
|
44
|
+
console.log('[Overlay] transformed quad:', transformedQuad);
|
|
26
45
|
}
|
|
27
46
|
|
|
28
47
|
const skPath = Skia.Path.Make();
|
|
29
|
-
skPath.moveTo(
|
|
30
|
-
|
|
48
|
+
skPath.moveTo(transformedQuad[0].x, transformedQuad[0].y);
|
|
49
|
+
transformedQuad.slice(1).forEach((p) => skPath.lineTo(p.x, p.y));
|
|
31
50
|
skPath.close();
|
|
32
51
|
return skPath;
|
|
33
|
-
}, [quad, color, screenWidth, screenHeight]);
|
|
52
|
+
}, [quad, color, screenWidth, screenHeight, frameSize]);
|
|
34
53
|
|
|
35
54
|
// Test path - always visible for debugging
|
|
36
55
|
const testPath = useMemo(() => {
|