@velion-la/onboarding-sdk-react-native 1.0.0-beta.8 → 1.0.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.
Files changed (83) hide show
  1. package/lib/commonjs/camera/DocumentCapture.js +78 -29
  2. package/lib/commonjs/camera/DocumentCapture.js.map +1 -1
  3. package/lib/commonjs/camera/LivenessCamera.js +18 -3
  4. package/lib/commonjs/camera/LivenessCamera.js.map +1 -1
  5. package/lib/commonjs/camera/MapAddressPicker.js +12 -22
  6. package/lib/commonjs/camera/MapAddressPicker.js.map +1 -1
  7. package/lib/commonjs/i18n/strings/en.js +3 -2
  8. package/lib/commonjs/i18n/strings/en.js.map +1 -1
  9. package/lib/commonjs/i18n/strings/es.js +3 -2
  10. package/lib/commonjs/i18n/strings/es.js.map +1 -1
  11. package/lib/commonjs/steps/DocumentsOcrStep.js +121 -23
  12. package/lib/commonjs/steps/DocumentsOcrStep.js.map +1 -1
  13. package/lib/commonjs/steps/PhoneContactStep.js +10 -4
  14. package/lib/commonjs/steps/PhoneContactStep.js.map +1 -1
  15. package/lib/commonjs/steps/PhoneOtpStep.js +17 -6
  16. package/lib/commonjs/steps/PhoneOtpStep.js.map +1 -1
  17. package/lib/commonjs/ui/StepShell.js +134 -9
  18. package/lib/commonjs/ui/StepShell.js.map +1 -1
  19. package/lib/commonjs/ui/VelionOnboardingScreen.js +52 -13
  20. package/lib/commonjs/ui/VelionOnboardingScreen.js.map +1 -1
  21. package/lib/commonjs/ui/overlays/ProgressBar.js +8 -2
  22. package/lib/commonjs/ui/overlays/ProgressBar.js.map +1 -1
  23. package/lib/commonjs/utils/documentCrop.js +115 -0
  24. package/lib/commonjs/utils/documentCrop.js.map +1 -0
  25. package/lib/commonjs/utils/useSafeAreaInsets.js +41 -0
  26. package/lib/commonjs/utils/useSafeAreaInsets.js.map +1 -0
  27. package/lib/module/camera/DocumentCapture.js +78 -29
  28. package/lib/module/camera/DocumentCapture.js.map +1 -1
  29. package/lib/module/camera/LivenessCamera.js +18 -3
  30. package/lib/module/camera/LivenessCamera.js.map +1 -1
  31. package/lib/module/camera/MapAddressPicker.js +12 -23
  32. package/lib/module/camera/MapAddressPicker.js.map +1 -1
  33. package/lib/module/i18n/strings/en.js +3 -2
  34. package/lib/module/i18n/strings/en.js.map +1 -1
  35. package/lib/module/i18n/strings/es.js +3 -2
  36. package/lib/module/i18n/strings/es.js.map +1 -1
  37. package/lib/module/steps/DocumentsOcrStep.js +121 -23
  38. package/lib/module/steps/DocumentsOcrStep.js.map +1 -1
  39. package/lib/module/steps/PhoneContactStep.js +10 -4
  40. package/lib/module/steps/PhoneContactStep.js.map +1 -1
  41. package/lib/module/steps/PhoneOtpStep.js +17 -6
  42. package/lib/module/steps/PhoneOtpStep.js.map +1 -1
  43. package/lib/module/ui/StepShell.js +134 -10
  44. package/lib/module/ui/StepShell.js.map +1 -1
  45. package/lib/module/ui/VelionOnboardingScreen.js +55 -14
  46. package/lib/module/ui/VelionOnboardingScreen.js.map +1 -1
  47. package/lib/module/ui/overlays/ProgressBar.js +8 -1
  48. package/lib/module/ui/overlays/ProgressBar.js.map +1 -1
  49. package/lib/module/utils/documentCrop.js +109 -0
  50. package/lib/module/utils/documentCrop.js.map +1 -0
  51. package/lib/module/utils/useSafeAreaInsets.js +37 -0
  52. package/lib/module/utils/useSafeAreaInsets.js.map +1 -0
  53. package/lib/typescript/camera/DocumentCapture.d.ts +20 -8
  54. package/lib/typescript/camera/DocumentCapture.d.ts.map +1 -1
  55. package/lib/typescript/camera/LivenessCamera.d.ts.map +1 -1
  56. package/lib/typescript/camera/MapAddressPicker.d.ts.map +1 -1
  57. package/lib/typescript/i18n/strings/en.d.ts.map +1 -1
  58. package/lib/typescript/i18n/strings/es.d.ts +1 -0
  59. package/lib/typescript/i18n/strings/es.d.ts.map +1 -1
  60. package/lib/typescript/steps/DocumentsOcrStep.d.ts +8 -6
  61. package/lib/typescript/steps/DocumentsOcrStep.d.ts.map +1 -1
  62. package/lib/typescript/ui/StepShell.d.ts.map +1 -1
  63. package/lib/typescript/ui/VelionOnboardingScreen.d.ts.map +1 -1
  64. package/lib/typescript/ui/overlays/ProgressBar.d.ts +6 -0
  65. package/lib/typescript/ui/overlays/ProgressBar.d.ts.map +1 -1
  66. package/lib/typescript/utils/documentCrop.d.ts +62 -0
  67. package/lib/typescript/utils/documentCrop.d.ts.map +1 -0
  68. package/lib/typescript/utils/useSafeAreaInsets.d.ts +26 -0
  69. package/lib/typescript/utils/useSafeAreaInsets.d.ts.map +1 -0
  70. package/package.json +2 -1
  71. package/src/camera/DocumentCapture.tsx +78 -28
  72. package/src/camera/LivenessCamera.tsx +10 -3
  73. package/src/camera/MapAddressPicker.tsx +12 -18
  74. package/src/i18n/strings/en.ts +3 -2
  75. package/src/i18n/strings/es.ts +3 -2
  76. package/src/steps/DocumentsOcrStep.tsx +145 -24
  77. package/src/steps/PhoneContactStep.tsx +9 -3
  78. package/src/steps/PhoneOtpStep.tsx +14 -4
  79. package/src/ui/StepShell.tsx +129 -10
  80. package/src/ui/VelionOnboardingScreen.tsx +53 -13
  81. package/src/ui/overlays/ProgressBar.tsx +8 -1
  82. package/src/utils/documentCrop.ts +138 -0
  83. package/src/utils/useSafeAreaInsets.ts +37 -0
@@ -0,0 +1,138 @@
1
+ /**
2
+ * @fileoverview Geometry for the document capture guide + crop.
3
+ *
4
+ * Two pure helpers, shared between the camera overlay and the post-capture
5
+ * crop so the pixels we keep are *exactly* the rectangle the user framed:
6
+ *
7
+ * - `computeCutout` — the on-screen ID-1 guide rectangle (screen px).
8
+ * - `computeGuideCropRect` — maps that guide rectangle into the captured
9
+ * photo's pixel space, compensating for the camera preview's `cover` fit
10
+ * (the preview center-crops the sensor frame to the screen aspect ratio).
11
+ *
12
+ * This is a *geometric* crop to a fixed guide, NOT edge detection / OpenCV —
13
+ * we never inspect pixels. The backend's Document AI still runs OCR and its
14
+ * own face crop on top, so we keep a safety margin around the guide to avoid
15
+ * clipping the document (or the portrait the backend needs).
16
+ */
17
+
18
+ import type { DocumentOrientation } from '../types';
19
+
20
+ export interface CutoutRect {
21
+ left: number;
22
+ top: number;
23
+ width: number;
24
+ height: number;
25
+ }
26
+
27
+ export interface PixelRect {
28
+ x: number;
29
+ y: number;
30
+ width: number;
31
+ height: number;
32
+ }
33
+
34
+ // ID-1 aspect ratios (width / height). Portrait ≈ 0.625 (held vertically),
35
+ // landscape ≈ 1.586 (the real ID-1 card ratio, 85.6 × 53.98 mm).
36
+ const PORTRAIT_ASPECT = 0.625;
37
+ const LANDSCAPE_ASPECT = 1.586;
38
+
39
+ // The guide is 85% of screen width, but never taller than 62% of screen height
40
+ // (portrait ID-1 on tall phones would otherwise overflow).
41
+ const CUTOUT_WIDTH_RATIO = 0.85;
42
+ const CUTOUT_MAX_HEIGHT_RATIO = 0.62;
43
+
44
+ /** Default crop margin: expand each side of the guide by this fraction of the
45
+ * guide size, so a document slightly overflowing the frame isn't clipped. */
46
+ export const DEFAULT_CROP_MARGIN = 0.07;
47
+
48
+ /**
49
+ * The on-screen guide rectangle, in screen pixels. Mirrors what the mask
50
+ * overlay draws so the crop matches the visible cutout exactly.
51
+ */
52
+ export function computeCutout(
53
+ screenW: number,
54
+ screenH: number,
55
+ orientation: DocumentOrientation,
56
+ ): CutoutRect {
57
+ const aspectRatio =
58
+ orientation === 'portrait' ? PORTRAIT_ASPECT : LANDSCAPE_ASPECT;
59
+
60
+ let width = screenW * CUTOUT_WIDTH_RATIO;
61
+ let height = width / aspectRatio;
62
+ const maxH = screenH * CUTOUT_MAX_HEIGHT_RATIO;
63
+ if (height > maxH) {
64
+ height = maxH;
65
+ width = height * aspectRatio;
66
+ }
67
+ return {
68
+ left: (screenW - width) / 2,
69
+ top: (screenH - height) / 2,
70
+ width,
71
+ height,
72
+ };
73
+ }
74
+
75
+ /**
76
+ * Map the on-screen guide rectangle into the captured photo's pixel space.
77
+ *
78
+ * The preview renders the photo with `cover` fit: the sensor frame is scaled
79
+ * up until it fills the screen and the overflow is center-cropped. So a screen
80
+ * point `(sx, sy)` maps to photo pixel `((W_img - W_screen/s)/2 + sx/s, …)`,
81
+ * where `s = max(W_screen/W_img, H_screen/H_img)`.
82
+ *
83
+ * `imageW`/`imageH` MUST be the photo's *display* (orientation-normalized)
84
+ * dimensions — i.e. portrait when the device is portrait — not the raw sensor
85
+ * dimensions, which are often landscape with an EXIF rotation flag.
86
+ *
87
+ * The result is expanded by `margin` (fraction of the mapped guide) and
88
+ * clamped to the image bounds, then rounded to integers (the manipulator
89
+ * rejects fractional crop rects).
90
+ */
91
+ export function computeGuideCropRect(params: {
92
+ screenW: number;
93
+ screenH: number;
94
+ imageW: number;
95
+ imageH: number;
96
+ cutout: CutoutRect;
97
+ margin?: number;
98
+ }): PixelRect {
99
+ const {
100
+ screenW,
101
+ screenH,
102
+ imageW,
103
+ imageH,
104
+ cutout,
105
+ margin = DEFAULT_CROP_MARGIN,
106
+ } = params;
107
+
108
+ const scale = Math.max(screenW / imageW, screenH / imageH);
109
+ // Image pixels hidden off each edge by the cover crop.
110
+ const offsetX = (imageW - screenW / scale) / 2;
111
+ const offsetY = (imageH - screenH / scale) / 2;
112
+
113
+ let x = offsetX + cutout.left / scale;
114
+ let y = offsetY + cutout.top / scale;
115
+ let width = cutout.width / scale;
116
+ let height = cutout.height / scale;
117
+
118
+ // Expand by the safety margin.
119
+ const mx = width * margin;
120
+ const my = height * margin;
121
+ x -= mx;
122
+ y -= my;
123
+ width += mx * 2;
124
+ height += my * 2;
125
+
126
+ // Clamp to image bounds.
127
+ x = Math.max(0, x);
128
+ y = Math.max(0, y);
129
+ width = Math.min(width, imageW - x);
130
+ height = Math.min(height, imageH - y);
131
+
132
+ return {
133
+ x: Math.round(x),
134
+ y: Math.round(y),
135
+ width: Math.round(width),
136
+ height: Math.round(height),
137
+ };
138
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @fileoverview Shared safe-area inset hook with a dynamic, fail-safe loader.
3
+ *
4
+ * `react-native-safe-area-context` is a transitive peer of Expo SDK 54+ (and is
5
+ * declared as a peerDependency of this SDK), but we never import it statically:
6
+ * hosts that strip optional native deps, or render the SDK outside a
7
+ * `SafeAreaProvider`, must still get a usable layout. So the hook is loaded with
8
+ * a `require` inside a try/catch and falls back to zero insets.
9
+ *
10
+ * The `require` result is deterministic for the lifetime of the bundle (the
11
+ * module is either installed or not), so the conditional hook call below does
12
+ * not change across renders — it does not violate the rules of hooks. Callers
13
+ * MUST still invoke this hook unconditionally (before any early return).
14
+ *
15
+ * Insets are applied to UI chrome (headers, CTAs, camera controls) — never to
16
+ * the full-bleed `<Camera>` / `<MapView>` preview, which must keep covering the
17
+ * whole screen so OCR / liveness framing is not cropped.
18
+ */
19
+
20
+ export interface EdgeInsets {
21
+ top: number;
22
+ bottom: number;
23
+ left: number;
24
+ right: number;
25
+ }
26
+
27
+ const ZERO_INSETS: EdgeInsets = { top: 0, bottom: 0, left: 0, right: 0 };
28
+
29
+ export function useSafeAreaInsets(): EdgeInsets {
30
+ try {
31
+ // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
32
+ const mod = require('react-native-safe-area-context');
33
+ return mod.useSafeAreaInsets() as EdgeInsets;
34
+ } catch {
35
+ return ZERO_INSETS;
36
+ }
37
+ }