react-native-rectangle-doc-scanner 0.63.0 → 0.65.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.
@@ -37,14 +37,18 @@ 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', frameSize }) => {
40
+ const lerp = (start, end, t) => ({
41
+ x: start.x + (end.x - start.x) * t,
42
+ y: start.y + (end.y - start.y) * t,
43
+ });
44
+ const Overlay = ({ quad, color = '#e7a649', frameSize, showGrid = true, gridColor = 'rgba(231, 166, 73, 0.35)', gridLineWidth = 2, }) => {
41
45
  const { width: screenWidth, height: screenHeight } = (0, react_native_1.useWindowDimensions)();
42
- const path = (0, react_1.useMemo)(() => {
46
+ const { outlinePath, gridPaths } = (0, react_1.useMemo)(() => {
43
47
  if (!quad || !frameSize) {
44
48
  if (__DEV__) {
45
49
  console.log('[Overlay] no quad or frameSize', { quad, frameSize });
46
50
  }
47
- return null;
51
+ return { outlinePath: null, gridPaths: [] };
48
52
  }
49
53
  if (__DEV__) {
50
54
  console.log('[Overlay] drawing quad:', quad);
@@ -93,15 +97,41 @@ const Overlay = ({ quad, color = '#e7a649', frameSize }) => {
93
97
  skPath.moveTo(transformedQuad[0].x, transformedQuad[0].y);
94
98
  transformedQuad.slice(1).forEach((p) => skPath.lineTo(p.x, p.y));
95
99
  skPath.close();
96
- return skPath;
97
- }, [quad, color, screenWidth, screenHeight, frameSize]);
100
+ const grid = [];
101
+ if (showGrid) {
102
+ const [topLeft, topRight, bottomRight, bottomLeft] = transformedQuad;
103
+ const steps = [1 / 3, 2 / 3];
104
+ steps.forEach((t) => {
105
+ const start = lerp(topLeft, topRight, t);
106
+ const end = lerp(bottomLeft, bottomRight, t);
107
+ const verticalPath = react_native_skia_1.Skia.Path.Make();
108
+ verticalPath.moveTo(start.x, start.y);
109
+ verticalPath.lineTo(end.x, end.y);
110
+ grid.push(verticalPath);
111
+ });
112
+ steps.forEach((t) => {
113
+ const start = lerp(topLeft, bottomLeft, t);
114
+ const end = lerp(topRight, bottomRight, t);
115
+ const horizontalPath = react_native_skia_1.Skia.Path.Make();
116
+ horizontalPath.moveTo(start.x, start.y);
117
+ horizontalPath.lineTo(end.x, end.y);
118
+ grid.push(horizontalPath);
119
+ });
120
+ }
121
+ return { outlinePath: skPath, gridPaths: grid };
122
+ }, [quad, screenWidth, screenHeight, frameSize, showGrid]);
98
123
  if (__DEV__) {
99
124
  console.log('[Overlay] rendering Canvas with dimensions:', screenWidth, 'x', screenHeight);
100
125
  }
101
126
  return (react_1.default.createElement(react_native_1.View, { style: styles.container, pointerEvents: "none" },
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" }))))));
127
+ react_1.default.createElement(react_native_skia_1.Canvas, { style: { width: screenWidth, height: screenHeight } }, outlinePath && (react_1.default.createElement(react_1.default.Fragment, null,
128
+ react_1.default.createElement(react_native_skia_1.Path, { path: outlinePath, color: color, style: "stroke", strokeWidth: 8 }),
129
+ react_1.default.createElement(react_native_skia_1.Path, { path: outlinePath, color: "rgba(231, 166, 73, 0.2)", style: "fill" }),
130
+ gridPaths.map((gridPath, index) => (react_1.default.createElement(react_native_skia_1.Path
131
+ // eslint-disable-next-line react/no-array-index-key
132
+ , {
133
+ // eslint-disable-next-line react/no-array-index-key
134
+ key: `grid-${index}`, path: gridPath, color: gridColor, style: "stroke", strokeWidth: gridLineWidth }))))))));
105
135
  };
106
136
  exports.Overlay = Overlay;
107
137
  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.63.0",
3
+ "version": "0.65.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {
@@ -18,13 +18,7 @@
18
18
  "peerDependencies": {
19
19
  "@shopify/react-native-skia": "*",
20
20
  "react": "*",
21
- "react-native": "*",
22
- "react-native-fast-opencv": "*",
23
- "react-native-perspective-image-cropper": "*",
24
- "react-native-reanimated": "*",
25
- "react-native-vision-camera": "*",
26
- "react-native-worklets-core": "*",
27
- "vision-camera-resize-plugin": "*"
21
+ "react-native": "*"
28
22
  },
29
23
  "devDependencies": {
30
24
  "@types/react": "^18.2.41",
@@ -32,7 +26,6 @@
32
26
  "typescript": "^5.3.3"
33
27
  },
34
28
  "dependencies": {
35
- "react-native-rectangle-doc-scanner": "^0.55.0",
36
- "react-native-worklets-core": "^1.6.2"
29
+ "react-native-document-scanner-plugin": "^1.6.3"
37
30
  }
38
31
  }