react-native-rectangle-doc-scanner 0.34.0 → 0.36.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.
@@ -91,37 +91,19 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
91
91
  (0, react_1.useEffect)(() => {
92
92
  requestPermission();
93
93
  }, [requestPermission]);
94
- const lastQuadRef = (0, react_1.useRef)(null);
95
- const noQuadFramesRef = (0, react_1.useRef)(0);
96
94
  const updateQuad = (0, react_native_worklets_core_1.useRunOnJS)((value) => {
97
95
  if (__DEV__) {
98
96
  console.log('[DocScanner] quad', value);
99
97
  }
100
- if (value) {
101
- // Found a quad, reset counter and update
102
- noQuadFramesRef.current = 0;
103
- lastQuadRef.current = value;
104
- setQuad(value);
105
- }
106
- else {
107
- // No quad found, keep the last one for a few frames
108
- noQuadFramesRef.current += 1;
109
- // Keep the last quad for up to 3 frames
110
- if (noQuadFramesRef.current > 3) {
111
- lastQuadRef.current = null;
112
- setQuad(null);
113
- }
114
- // Otherwise, keep showing the last quad
115
- }
98
+ // Always update immediately for real-time tracking
99
+ setQuad(value);
116
100
  }, []);
117
101
  const reportError = (0, react_native_worklets_core_1.useRunOnJS)((step, error) => {
118
102
  const message = error instanceof Error ? error.message : `${error}`;
119
103
  console.warn(`[DocScanner] frame error at ${step}: ${message}`);
120
104
  }, []);
121
- const reportStage = (0, react_native_worklets_core_1.useRunOnJS)((stage) => {
122
- if (__DEV__) {
123
- console.log('[DocScanner] stage', stage);
124
- }
105
+ const reportStage = (0, react_native_worklets_core_1.useRunOnJS)((_stage) => {
106
+ // Disabled for performance
125
107
  }, []);
126
108
  const [frameSize, setFrameSize] = (0, react_1.useState)(null);
127
109
  const updateFrameSize = (0, react_native_worklets_core_1.useRunOnJS)((width, height) => {
@@ -197,7 +179,7 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
197
179
  console.log('[DocScanner] area', area, 'ratio', areaRatio);
198
180
  }
199
181
  // Skip if area ratio is too small or too large
200
- if (areaRatio < 0.01 || areaRatio > 0.95) {
182
+ if (areaRatio < 0.02 || areaRatio > 0.95) {
201
183
  continue;
202
184
  }
203
185
  step = `contour_${i}_arcLength`;
@@ -205,9 +187,8 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
205
187
  const { value: perimeter } = react_native_fast_opencv_1.OpenCV.invoke('arcLength', contour, true);
206
188
  const approx = react_native_fast_opencv_1.OpenCV.createObject(react_native_fast_opencv_1.ObjectType.PointVector);
207
189
  let approxArray = [];
208
- // Start with smaller epsilon for more accurate corner detection
209
- // Try epsilon values from 0.5% to 5% of perimeter
210
- const epsilonValues = [0.005, 0.01, 0.015, 0.02, 0.025, 0.03, 0.035, 0.04, 0.045, 0.05];
190
+ // Try epsilon values from 0.2% to 8% of perimeter
191
+ const epsilonValues = [0.002, 0.004, 0.006, 0.008, 0.01, 0.015, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08];
211
192
  for (let attempt = 0; attempt < epsilonValues.length; attempt += 1) {
212
193
  const epsilon = epsilonValues[attempt] * perimeter;
213
194
  step = `contour_${i}_approxPolyDP_attempt_${attempt}`;
@@ -95,25 +95,13 @@ const Overlay = ({ quad, color = '#e7a649', frameSize }) => {
95
95
  skPath.close();
96
96
  return skPath;
97
97
  }, [quad, color, screenWidth, screenHeight, frameSize]);
98
- // Test path - always visible for debugging
99
- const testPath = (0, react_1.useMemo)(() => {
100
- const tp = react_native_skia_1.Skia.Path.Make();
101
- tp.moveTo(100, 100);
102
- tp.lineTo(300, 100);
103
- tp.lineTo(300, 300);
104
- tp.lineTo(100, 300);
105
- tp.close();
106
- return tp;
107
- }, []);
108
98
  if (__DEV__) {
109
99
  console.log('[Overlay] rendering Canvas with dimensions:', screenWidth, 'x', screenHeight);
110
100
  }
111
101
  return (react_1.default.createElement(react_native_1.View, { style: styles.container, pointerEvents: "none" },
112
- react_1.default.createElement(react_native_skia_1.Canvas, { style: { width: screenWidth, height: screenHeight } },
113
- react_1.default.createElement(react_native_skia_1.Path, { path: testPath, color: "red", style: "stroke", strokeWidth: 4 }),
114
- path && (react_1.default.createElement(react_1.default.Fragment, null,
115
- react_1.default.createElement(react_native_skia_1.Path, { path: path, color: color, style: "stroke", strokeWidth: 8 }),
116
- react_1.default.createElement(react_native_skia_1.Path, { path: path, color: "rgba(231, 166, 73, 0.2)", style: "fill" }))))));
102
+ react_1.default.createElement(react_native_skia_1.Canvas, { style: { width: screenWidth, height: screenHeight } }, path && (react_1.default.createElement(react_1.default.Fragment, null,
103
+ react_1.default.createElement(react_native_skia_1.Path, { path: path, color: color, style: "stroke", strokeWidth: 8 }),
104
+ react_1.default.createElement(react_native_skia_1.Path, { path: path, color: "rgba(231, 166, 73, 0.2)", style: "fill" }))))));
117
105
  };
118
106
  exports.Overlay = Overlay;
119
107
  const styles = react_native_1.StyleSheet.create({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "0.34.0",
3
+ "version": "0.36.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {
@@ -96,30 +96,13 @@ export const DocScanner: React.FC<Props> = ({
96
96
  requestPermission();
97
97
  }, [requestPermission]);
98
98
 
99
- const lastQuadRef = useRef<Point[] | null>(null);
100
- const noQuadFramesRef = useRef(0);
101
-
102
99
  const updateQuad = useRunOnJS((value: Point[] | null) => {
103
100
  if (__DEV__) {
104
101
  console.log('[DocScanner] quad', value);
105
102
  }
106
103
 
107
- if (value) {
108
- // Found a quad, reset counter and update
109
- noQuadFramesRef.current = 0;
110
- lastQuadRef.current = value;
111
- setQuad(value);
112
- } else {
113
- // No quad found, keep the last one for a few frames
114
- noQuadFramesRef.current += 1;
115
-
116
- // Keep the last quad for up to 3 frames
117
- if (noQuadFramesRef.current > 3) {
118
- lastQuadRef.current = null;
119
- setQuad(null);
120
- }
121
- // Otherwise, keep showing the last quad
122
- }
104
+ // Always update immediately for real-time tracking
105
+ setQuad(value);
123
106
  }, []);
124
107
 
125
108
  const reportError = useRunOnJS((step: string, error: unknown) => {
@@ -127,10 +110,8 @@ export const DocScanner: React.FC<Props> = ({
127
110
  console.warn(`[DocScanner] frame error at ${step}: ${message}`);
128
111
  }, []);
129
112
 
130
- const reportStage = useRunOnJS((stage: string) => {
131
- if (__DEV__) {
132
- console.log('[DocScanner] stage', stage);
133
- }
113
+ const reportStage = useRunOnJS((_stage: string) => {
114
+ // Disabled for performance
134
115
  }, []);
135
116
 
136
117
  const [frameSize, setFrameSize] = useState<{ width: number; height: number } | null>(null);
@@ -225,7 +206,7 @@ export const DocScanner: React.FC<Props> = ({
225
206
  }
226
207
 
227
208
  // Skip if area ratio is too small or too large
228
- if (areaRatio < 0.01 || areaRatio > 0.95) {
209
+ if (areaRatio < 0.02 || areaRatio > 0.95) {
229
210
  continue;
230
211
  }
231
212
 
@@ -236,9 +217,8 @@ export const DocScanner: React.FC<Props> = ({
236
217
 
237
218
  let approxArray: Array<{ x: number; y: number }> = [];
238
219
 
239
- // Start with smaller epsilon for more accurate corner detection
240
- // Try epsilon values from 0.5% to 5% of perimeter
241
- const epsilonValues = [0.005, 0.01, 0.015, 0.02, 0.025, 0.03, 0.035, 0.04, 0.045, 0.05];
220
+ // Try epsilon values from 0.2% to 8% of perimeter
221
+ const epsilonValues = [0.002, 0.004, 0.006, 0.008, 0.01, 0.015, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08];
242
222
 
243
223
  for (let attempt = 0; attempt < epsilonValues.length; attempt += 1) {
244
224
  const epsilon = epsilonValues[attempt] * perimeter;
@@ -79,17 +79,6 @@ export const Overlay: React.FC<OverlayProps> = ({ quad, color = '#e7a649', frame
79
79
  return skPath;
80
80
  }, [quad, color, screenWidth, screenHeight, frameSize]);
81
81
 
82
- // Test path - always visible for debugging
83
- const testPath = useMemo(() => {
84
- const tp = Skia.Path.Make();
85
- tp.moveTo(100, 100);
86
- tp.lineTo(300, 100);
87
- tp.lineTo(300, 300);
88
- tp.lineTo(100, 300);
89
- tp.close();
90
- return tp;
91
- }, []);
92
-
93
82
  if (__DEV__) {
94
83
  console.log('[Overlay] rendering Canvas with dimensions:', screenWidth, 'x', screenHeight);
95
84
  }
@@ -97,10 +86,6 @@ export const Overlay: React.FC<OverlayProps> = ({ quad, color = '#e7a649', frame
97
86
  return (
98
87
  <View style={styles.container} pointerEvents="none">
99
88
  <Canvas style={{ width: screenWidth, height: screenHeight }}>
100
- {/* Debug: always show a test rectangle */}
101
- <Path path={testPath} color="red" style="stroke" strokeWidth={4} />
102
-
103
- {/* Actual quad overlay */}
104
89
  {path && (
105
90
  <>
106
91
  <Path path={path} color={color} style="stroke" strokeWidth={8} />