datakeen-session-react 1.1.202-dev.16 → 1.1.202-dev.18

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 (108) hide show
  1. package/dist/cjs/components/DatakeenSession.js +17 -16
  2. package/dist/cjs/components/card-capture-guide/CardCaptureGuide.js +139 -0
  3. package/dist/cjs/components/card-capture-guide/captureTelemetry.js +81 -0
  4. package/dist/cjs/components/card-capture-guide/guidance.js +48 -0
  5. package/dist/cjs/components/card-capture-guide/guideCore.js +389 -0
  6. package/dist/cjs/components/card-capture-guide/guideRuntime.js +118 -0
  7. package/dist/cjs/components/card-capture-guide/modelLoader.js +46 -0
  8. package/dist/cjs/components/card-capture-guide/useCaptureGuideThresholds.js +33 -0
  9. package/dist/cjs/components/card-capture-guide/useCardCaptureGuide.js +117 -0
  10. package/dist/cjs/components/card-capture-guide/useMinDisplay.js +30 -0
  11. package/dist/cjs/components/document-collection/DocumentCollection.js +9 -0
  12. package/dist/cjs/components/id-check/Photo.js +230 -122
  13. package/dist/cjs/components/id-check/card-capture/CardCapture.js +270 -0
  14. package/dist/cjs/components/id-check/card-capture/DynamicCardMask.js +85 -0
  15. package/dist/cjs/components/id-check/card-capture/geometry.js +119 -0
  16. package/dist/cjs/components/id-check/card-capture/guideTone.js +15 -0
  17. package/dist/cjs/components/jdi/JDIDocumentSelection.js +9 -0
  18. package/dist/cjs/components/selfie/Video.js +2 -2
  19. package/dist/cjs/components/selfie/selfie-flow/SelfieFlow.js +4 -2
  20. package/dist/cjs/components/session/DocumentCheck.js +37 -2
  21. package/dist/cjs/components/session/EndFlow.js +4 -0
  22. package/dist/cjs/components/session/Selfie.js +1 -1
  23. package/dist/cjs/components/signature-electronic/SignatureElectronic.js +9 -2
  24. package/dist/cjs/components/start-flow/Start.js +4 -0
  25. package/dist/cjs/components/template/TemplateNodeRenderer.js +3 -1
  26. package/dist/cjs/components/ui/Button.js +3 -3
  27. package/dist/cjs/context/CardCaptureGuideContext.js +16 -0
  28. package/dist/cjs/hooks/useClientInfo.js +7 -0
  29. package/dist/cjs/hooks/useUserInputForm.js +3 -1
  30. package/dist/cjs/i18n/en.json.js +57 -1
  31. package/dist/cjs/i18n/es.json.js +57 -1
  32. package/dist/cjs/i18n/fr.json.js +57 -1
  33. package/dist/cjs/index.css.js +1 -1
  34. package/dist/cjs/index.js +15 -0
  35. package/dist/cjs/preview/DatakeenJourneyPreview.js +257 -0
  36. package/dist/cjs/preview/PreviewAutomaticStep.js +23 -0
  37. package/dist/cjs/preview/PreviewBranchPicker.js +54 -0
  38. package/dist/cjs/preview/PreviewCaptureDisabled.js +19 -0
  39. package/dist/cjs/preview/previewAdapter.js +27 -0
  40. package/dist/cjs/preview/previewMode.js +21 -0
  41. package/dist/cjs/preview/previewNavigation.js +105 -0
  42. package/dist/cjs/services/api.js +5 -0
  43. package/dist/cjs/services/cameraService.js +6 -0
  44. package/dist/cjs/services/realtime/sseClient.js +4 -0
  45. package/dist/cjs/services/sessionService.js +50 -0
  46. package/dist/cjs/utils/cssLoader.js +6 -4
  47. package/dist/cjs/utils/isMobileDevice.js +8 -0
  48. package/dist/esm/components/DatakeenSession.js +17 -16
  49. package/dist/esm/components/card-capture-guide/CardCaptureGuide.js +135 -0
  50. package/dist/esm/components/card-capture-guide/captureTelemetry.js +78 -0
  51. package/dist/esm/components/card-capture-guide/guidance.js +44 -0
  52. package/dist/esm/components/card-capture-guide/guideCore.js +372 -0
  53. package/dist/esm/components/card-capture-guide/guideRuntime.js +115 -0
  54. package/dist/esm/components/card-capture-guide/modelLoader.js +42 -0
  55. package/dist/esm/components/card-capture-guide/useCaptureGuideThresholds.js +31 -0
  56. package/dist/esm/components/card-capture-guide/useCardCaptureGuide.js +115 -0
  57. package/dist/esm/components/card-capture-guide/useMinDisplay.js +28 -0
  58. package/dist/esm/components/document-collection/DocumentCollection.js +10 -1
  59. package/dist/esm/components/id-check/Photo.js +232 -124
  60. package/dist/esm/components/id-check/card-capture/CardCapture.js +266 -0
  61. package/dist/esm/components/id-check/card-capture/DynamicCardMask.js +81 -0
  62. package/dist/esm/components/id-check/card-capture/geometry.js +110 -0
  63. package/dist/esm/components/id-check/card-capture/guideTone.js +13 -0
  64. package/dist/esm/components/jdi/JDIDocumentSelection.js +9 -0
  65. package/dist/esm/components/selfie/Video.js +2 -2
  66. package/dist/esm/components/selfie/selfie-flow/SelfieFlow.js +4 -2
  67. package/dist/esm/components/session/DocumentCheck.js +37 -2
  68. package/dist/esm/components/session/EndFlow.js +4 -0
  69. package/dist/esm/components/session/Selfie.js +1 -1
  70. package/dist/esm/components/signature-electronic/SignatureElectronic.js +9 -2
  71. package/dist/esm/components/start-flow/Start.js +4 -0
  72. package/dist/esm/components/template/TemplateNodeRenderer.js +3 -1
  73. package/dist/esm/components/ui/Button.js +3 -3
  74. package/dist/esm/context/CardCaptureGuideContext.js +13 -0
  75. package/dist/esm/hooks/useClientInfo.js +7 -0
  76. package/dist/esm/hooks/useUserInputForm.js +3 -1
  77. package/dist/esm/i18n/en.json.js +55 -2
  78. package/dist/esm/i18n/es.json.js +55 -2
  79. package/dist/esm/i18n/fr.json.js +55 -2
  80. package/dist/esm/index.css.js +1 -1
  81. package/dist/esm/index.js +6 -0
  82. package/dist/esm/preview/DatakeenJourneyPreview.js +253 -0
  83. package/dist/esm/preview/PreviewAutomaticStep.js +19 -0
  84. package/dist/esm/preview/PreviewBranchPicker.js +48 -0
  85. package/dist/esm/preview/PreviewCaptureDisabled.js +15 -0
  86. package/dist/esm/preview/previewAdapter.js +25 -0
  87. package/dist/esm/preview/previewMode.js +15 -0
  88. package/dist/esm/preview/previewNavigation.js +98 -0
  89. package/dist/esm/services/api.js +5 -0
  90. package/dist/esm/services/cameraService.js +6 -0
  91. package/dist/esm/services/realtime/sseClient.js +4 -0
  92. package/dist/esm/services/sessionService.js +49 -1
  93. package/dist/esm/utils/cssLoader.js +6 -4
  94. package/dist/esm/utils/isMobileDevice.js +8 -0
  95. package/dist/types/components/card-capture-guide/CardCaptureGuide.d.ts +46 -0
  96. package/dist/types/components/card-capture-guide/guidance.d.ts +45 -0
  97. package/dist/types/components/card-capture-guide/guideCore.d.ts +96 -0
  98. package/dist/types/components/card-capture-guide/guideRuntime.d.ts +13 -0
  99. package/dist/types/components/card-capture-guide/modelLoader.d.ts +13 -0
  100. package/dist/types/components/card-capture-guide/useCardCaptureGuide.d.ts +38 -0
  101. package/dist/types/index.d.ts +8 -0
  102. package/dist/types/preview/DatakeenJourneyPreview.d.ts +6 -0
  103. package/dist/types/preview/types.d.ts +77 -0
  104. package/dist/types/services/documentTemplate.d.ts +13 -0
  105. package/dist/types/types/camera.d.ts +3 -0
  106. package/dist/types/types/session.d.ts +268 -1
  107. package/dist/types/utils/cssLoader.d.ts +0 -4
  108. package/package.json +2 -1
@@ -1,4 +1,4 @@
1
- import { __awaiter, __generator } from '../../node_modules/tslib/tslib.es6.js';
1
+ import { __awaiter, __generator, __spreadArray } from '../../node_modules/tslib/tslib.es6.js';
2
2
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
3
3
  import { useRef, useState, useCallback, useEffect } from 'react';
4
4
  import { cameraService } from '../../services/cameraService.js';
@@ -8,30 +8,48 @@ import CameraMask from './CameraMask.js';
8
8
  import OrientationToggle from './OrientationToggle.js';
9
9
  import { useI18n } from '../../hooks/useI18n.js';
10
10
  import { isBelowHd } from '../../utils/cameraResolution.js';
11
- import { reportCaptureDiagnostics } from '../../services/sessionService.js';
11
+ import { reportCaptureTelemetry, reportCaptureDiagnostics } from '../../services/sessionService.js';
12
12
  import useIsMobile from '../../hooks/useIsMobile.js';
13
+ import { useCardCaptureGuide } from '../card-capture-guide/useCardCaptureGuide.js';
14
+ import { useMinDisplay } from '../card-capture-guide/useMinDisplay.js';
15
+ import { CaptureTelemetryCollector, detectDeviceType } from '../card-capture-guide/captureTelemetry.js';
13
16
 
17
+ // FR fallbacks, same as fr.json "card_capture_guide.*"
18
+ var GUIDE_FALLBACK = {
19
+ no_card: "Placez votre pièce d'identité dans le cadre",
20
+ too_far: "Rapprochez la carte",
21
+ too_dark: "Augmenter la luminosité",
22
+ card_detected: "Carte détectée — gardez-la dans le cadre",
23
+ hold_still: "Ne bougez plus…",
24
+ too_blurry: "Ajuster la focalisation",
25
+ bright_spot: "Éviter les reflets",
26
+ ready: "Parfait — capture en cours",
27
+ };
28
+ var GUIDE_TRACKING_CODES = new Set(["card_detected", "hold_still", "ready"]);
29
+ var GUIDE_MESSAGE_MIN_MS = 700;
30
+ var CAPTURE_VIBRATION_MS = 60;
14
31
  var Photo = function (_a) {
15
- var onCapture = _a.onCapture, sessionId = _a.sessionId, nodeId = _a.nodeId, _b = _a.automaticCapture, automaticCapture = _b === void 0 ? false : _b, _c = _a.maskType, maskType = _c === void 0 ? "id" : _c;
32
+ var _b, _c, _d, _e;
33
+ var onCapture = _a.onCapture, sessionId = _a.sessionId, nodeId = _a.nodeId, _f = _a.automaticCapture, automaticCapture = _f === void 0 ? false : _f, _g = _a.maskType, maskType = _g === void 0 ? "id" : _g, _h = _a.cardGuide, cardGuide = _h === void 0 ? false : _h, _j = _a.captureSide, captureSide = _j === void 0 ? "recto" : _j, documentType = _a.documentType;
16
34
  var isMobile = useIsMobile(768);
17
35
  var videoRef = useRef(null);
18
- var _d = useState(false), lowResolution = _d[0], setLowResolution = _d[1];
19
- var _e = useState(0), cameraAttempt = _e[0], setCameraAttempt = _e[1];
20
- var _f = useState(false), isDetecting = _f[0], setIsDetecting = _f[1];
21
- var _g = useState("environment"), facingMode = _g[0], setFacingMode = _g[1];
22
- var _h = useState(null), cameraError = _h[0], setCameraError = _h[1];
23
- var _j = useState(window.matchMedia("(orientation: portrait)").matches), isPortrait = _j[0], setIsPortrait = _j[1];
24
- var _k = useState(false), isCountingDown = _k[0], setIsCountingDown = _k[1];
25
- var _l = useState(0), countdown = _l[0], setCountdown = _l[1];
26
- var _m = useState(false), documentDetected = _m[0], setDocumentDetected = _m[1];
27
- var _o = useState(undefined), qualityHint = _o[0], setQualityHint = _o[1];
28
- var _p = useState(true), isInitializing = _p[0], setIsInitializing = _p[1];
29
- var _q = useState(false), isProcessing = _q[0], setIsProcessing = _q[1];
30
- var _r = useState(null), captureError = _r[0], setCaptureError = _r[1];
31
- var _s = useState(false), showCaptureFlash = _s[0], setShowCaptureFlash = _s[1];
36
+ var _k = useState(false), lowResolution = _k[0], setLowResolution = _k[1];
37
+ var _l = useState(0), cameraAttempt = _l[0], setCameraAttempt = _l[1];
38
+ var _m = useState(false), isDetecting = _m[0], setIsDetecting = _m[1];
39
+ var _o = useState("environment"), facingMode = _o[0], setFacingMode = _o[1];
40
+ var _p = useState(null), cameraError = _p[0], setCameraError = _p[1];
41
+ var _q = useState(window.matchMedia("(orientation: portrait)").matches), isPortrait = _q[0], setIsPortrait = _q[1];
42
+ var _r = useState(false), isCountingDown = _r[0], setIsCountingDown = _r[1];
43
+ var _s = useState(0), countdown = _s[0], setCountdown = _s[1];
44
+ var _t = useState(false), documentDetected = _t[0], setDocumentDetected = _t[1];
45
+ var _u = useState(undefined), qualityHint = _u[0], setQualityHint = _u[1];
46
+ var _v = useState(true), isInitializing = _v[0], setIsInitializing = _v[1];
47
+ var _w = useState(false), isProcessing = _w[0], setIsProcessing = _w[1];
48
+ var _x = useState(null), captureError = _x[0], setCaptureError = _x[1];
49
+ var _y = useState(false), showCaptureFlash = _y[0], setShowCaptureFlash = _y[1];
32
50
  var t = useI18n().t;
33
- var _t = useState(null); _t[0]; var setLastCaptureMeta = _t[1];
34
- var _u = useState(null), maskRect = _u[0], setMaskRect = _u[1];
51
+ var _z = useState(null); _z[0]; var setLastCaptureMeta = _z[1];
52
+ var _0 = useState(null), maskRect = _0[0], setMaskRect = _0[1];
35
53
  var countdownIntervalRef = useRef(null);
36
54
  var detectionHandlerRef = useRef(null);
37
55
  var flashTimeoutRef = useRef(null);
@@ -72,109 +90,173 @@ var Photo = function (_a) {
72
90
  }
73
91
  documentEdgeDetectionService.stopDocumentDetection();
74
92
  }, []);
75
- var captureDocument = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
76
- var video, cropArea, videoRect, videoAspect, displayAspect, displayedWidth, displayedHeight, offsetX, offsetY, scaleX, scaleY, cropX, cropY, cropWidth, cropHeight, result, error_1;
77
- return __generator(this, function (_a) {
78
- switch (_a.label) {
79
- case 0:
80
- if (!videoRef.current) {
81
- throw new Error(t("id_check.photo.errors.video_unavailable", "Le flux vidéo n'est pas disponible"));
82
- }
83
- video = videoRef.current;
84
- if (!video.videoWidth || !video.videoHeight) {
85
- throw new Error(t("id_check.photo.errors.video_dimensions_unavailable", "Dimensions vidéo indisponibles pour la capture"));
86
- }
87
- cropArea = null;
88
- if (maskRect) {
89
- videoRect = video.getBoundingClientRect();
90
- videoAspect = video.videoWidth / video.videoHeight;
91
- displayAspect = videoRect.width / videoRect.height;
92
- displayedWidth = void 0, displayedHeight = void 0, offsetX = void 0, offsetY = void 0;
93
- if (videoAspect > displayAspect) {
94
- // Video is wider than container - scaled to match height, sides cropped
95
- displayedHeight = videoRect.height;
96
- displayedWidth = videoRect.height * videoAspect;
97
- offsetY = 0;
98
- offsetX = (videoRect.width - displayedWidth) / 2;
93
+ // Guide telemetry (APP3-2119): filled by the guide callbacks, sent once after a successful capture.
94
+ var telemetryRef = useRef(null);
95
+ // Read by the camera effect without restarting the camera when these props change.
96
+ var telemetryInitRef = useRef({ enabled: !!cardGuide, side: captureSide, documentType: documentType });
97
+ telemetryInitRef.current = { enabled: !!cardGuide, side: captureSide, documentType: documentType };
98
+ var sendTelemetryRef = useRef(function () { });
99
+ var captureDocument = useCallback(function () {
100
+ var args_1 = [];
101
+ for (var _i = 0; _i < arguments.length; _i++) {
102
+ args_1[_i] = arguments[_i];
103
+ }
104
+ return __awaiter(void 0, __spreadArray([], args_1, true), void 0, function (trigger) {
105
+ var video, cropArea, videoRect, videoAspect, displayAspect, displayedWidth, displayedHeight, offsetX, offsetY, scaleX, scaleY, cropX, cropY, cropWidth, cropHeight, result, error_1;
106
+ if (trigger === void 0) { trigger = "manual"; }
107
+ return __generator(this, function (_a) {
108
+ switch (_a.label) {
109
+ case 0:
110
+ if (!videoRef.current) {
111
+ throw new Error(t("id_check.photo.errors.video_unavailable", "Le flux vidéo n'est pas disponible"));
112
+ }
113
+ video = videoRef.current;
114
+ if (!video.videoWidth || !video.videoHeight) {
115
+ throw new Error(t("id_check.photo.errors.video_dimensions_unavailable", "Dimensions vidéo indisponibles pour la capture"));
116
+ }
117
+ cropArea = null;
118
+ if (maskRect) {
119
+ videoRect = video.getBoundingClientRect();
120
+ videoAspect = video.videoWidth / video.videoHeight;
121
+ displayAspect = videoRect.width / videoRect.height;
122
+ displayedWidth = void 0, displayedHeight = void 0, offsetX = void 0, offsetY = void 0;
123
+ if (videoAspect > displayAspect) {
124
+ // Video is wider than container - scaled to match height, sides cropped
125
+ displayedHeight = videoRect.height;
126
+ displayedWidth = videoRect.height * videoAspect;
127
+ offsetY = 0;
128
+ offsetX = (videoRect.width - displayedWidth) / 2;
129
+ }
130
+ else {
131
+ // Video is taller than container - scaled to match width, top/bottom cropped
132
+ displayedWidth = videoRect.width;
133
+ displayedHeight = videoRect.width / videoAspect;
134
+ offsetX = 0;
135
+ offsetY = (videoRect.height - displayedHeight) / 2;
136
+ }
137
+ scaleX = video.videoWidth / displayedWidth;
138
+ scaleY = video.videoHeight / displayedHeight;
139
+ cropX = (maskRect.left - videoRect.left - offsetX) * scaleX;
140
+ cropY = (maskRect.top - videoRect.top - offsetY) * scaleY;
141
+ cropWidth = maskRect.width * scaleX;
142
+ cropHeight = maskRect.height * scaleY;
143
+ // Ensure crop area is within video bounds
144
+ cropArea = {
145
+ x: Math.max(0, Math.round(cropX)),
146
+ y: Math.max(0, Math.round(cropY)),
147
+ width: Math.min(video.videoWidth - Math.max(0, cropX), Math.round(cropWidth)),
148
+ height: Math.min(video.videoHeight - Math.max(0, cropY), Math.round(cropHeight)),
149
+ };
150
+ console.debug("[Photo] Calculated crop area from mask", {
151
+ maskRect: maskRect,
152
+ videoRect: { left: videoRect.left, top: videoRect.top, width: videoRect.width, height: videoRect.height },
153
+ videoDimensions: { width: video.videoWidth, height: video.videoHeight },
154
+ displayedDimensions: { width: displayedWidth, height: displayedHeight },
155
+ offset: { x: offsetX, y: offsetY },
156
+ scale: { x: scaleX, y: scaleY },
157
+ cropArea: cropArea,
158
+ });
99
159
  }
100
160
  else {
101
- // Video is taller than container - scaled to match width, top/bottom cropped
102
- displayedWidth = videoRect.width;
103
- displayedHeight = videoRect.width / videoAspect;
104
- offsetX = 0;
105
- offsetY = (videoRect.height - displayedHeight) / 2;
161
+ console.debug("[Photo] No mask rect available, capturing full frame");
106
162
  }
107
- scaleX = video.videoWidth / displayedWidth;
108
- scaleY = video.videoHeight / displayedHeight;
109
- cropX = (maskRect.left - videoRect.left - offsetX) * scaleX;
110
- cropY = (maskRect.top - videoRect.top - offsetY) * scaleY;
111
- cropWidth = maskRect.width * scaleX;
112
- cropHeight = maskRect.height * scaleY;
113
- // Ensure crop area is within video bounds
114
- cropArea = {
115
- x: Math.max(0, Math.round(cropX)),
116
- y: Math.max(0, Math.round(cropY)),
117
- width: Math.min(video.videoWidth - Math.max(0, cropX), Math.round(cropWidth)),
118
- height: Math.min(video.videoHeight - Math.max(0, cropY), Math.round(cropHeight)),
119
- };
120
- console.debug("[Photo] Calculated crop area from mask", {
121
- maskRect: maskRect,
122
- videoRect: { left: videoRect.left, top: videoRect.top, width: videoRect.width, height: videoRect.height },
123
- videoDimensions: { width: video.videoWidth, height: video.videoHeight },
124
- displayedDimensions: { width: displayedWidth, height: displayedHeight },
125
- offset: { x: offsetX, y: offsetY },
126
- scale: { x: scaleX, y: scaleY },
127
- cropArea: cropArea,
163
+ setCaptureError(null);
164
+ setIsDetecting(false);
165
+ // Reste vrai jusqu'au démontage du composant (changement d'étape côté
166
+ // DocumentCheck) en cas de succès : le traitement post-capture côté
167
+ // parent (redimensionnement, conversion) continue pendant que ce
168
+ // composant est encore affiché, donc l'overlay doit rester visible
169
+ // jusqu'à ce que l'écran change réellement — jamais un écran figé sans
170
+ // feedback.
171
+ setIsProcessing(true);
172
+ triggerCaptureFeedback();
173
+ _a.label = 1;
174
+ case 1:
175
+ _a.trys.push([1, 3, , 4]);
176
+ return [4 /*yield*/, cameraService.captureDocument(video, cropArea, {
177
+ facingMode: facingMode,
178
+ format: "jpeg",
179
+ jpegQuality: 0.95,
180
+ // Copy the current video frame synchronously: takePhoto() can delay the
181
+ // shutter (or fall back to a later frame after an asynchronous failure).
182
+ preferImageCapture: false,
183
+ })];
184
+ case 2:
185
+ result = _a.sent();
186
+ setLastCaptureMeta(result);
187
+ stopDetection();
188
+ setDocumentDetected(false);
189
+ console.debug("Document captured", {
190
+ method: result.method,
191
+ analysis: result.analysis,
192
+ source: result.sourceDimensions,
193
+ crop: result.cropDimensions,
128
194
  });
129
- }
130
- else {
131
- console.debug("[Photo] No mask rect available, capturing full frame");
132
- }
133
- setCaptureError(null);
134
- setIsDetecting(false);
135
- // Reste vrai jusqu'au démontage du composant (changement d'étape côté
136
- // DocumentCheck) en cas de succès : le traitement post-capture côté
137
- // parent (redimensionnement, conversion) continue pendant que ce
138
- // composant est encore affiché, donc l'overlay doit rester visible
139
- // jusqu'à ce que l'écran change réellement — jamais un écran figé sans
140
- // feedback.
141
- setIsProcessing(true);
142
- triggerCaptureFeedback();
143
- _a.label = 1;
144
- case 1:
145
- _a.trys.push([1, 3, , 4]);
146
- return [4 /*yield*/, cameraService.captureDocument(video, cropArea, {
147
- facingMode: facingMode,
148
- format: "jpeg",
149
- jpegQuality: 0.95,
150
- // Copy the current video frame synchronously: takePhoto() can delay the
151
- // shutter (or fall back to a later frame after an asynchronous failure).
152
- preferImageCapture: false,
153
- })];
154
- case 2:
155
- result = _a.sent();
156
- setLastCaptureMeta(result);
157
- stopDetection();
158
- setDocumentDetected(false);
159
- console.debug("Document captured", {
160
- method: result.method,
161
- analysis: result.analysis,
162
- source: result.sourceDimensions,
163
- crop: result.cropDimensions,
164
- });
165
- onCapture(result.dataUrl);
166
- return [3 /*break*/, 4];
167
- case 3:
168
- error_1 = _a.sent();
169
- console.error("Document capture failed", error_1);
170
- setCaptureError(t("id_check.photo.capture_failed", "La capture a échoué. Veuillez réessayer."));
171
- setIsDetecting(true);
172
- setIsProcessing(false);
173
- throw error_1;
174
- case 4: return [2 /*return*/];
175
- }
195
+ onCapture(result.dataUrl);
196
+ sendTelemetryRef.current(trigger);
197
+ return [3 /*break*/, 4];
198
+ case 3:
199
+ error_1 = _a.sent();
200
+ console.error("Document capture failed", error_1);
201
+ setCaptureError(t("id_check.photo.capture_failed", "La capture a échoué. Veuillez réessayer."));
202
+ setIsDetecting(true);
203
+ setIsProcessing(false);
204
+ throw error_1;
205
+ case 4: return [2 /*return*/];
206
+ }
207
+ });
208
+ });
209
+ }, [facingMode, onCapture, stopDetection, maskRect, t, triggerCaptureFeedback]);
210
+ var guideConfig = typeof cardGuide === "object" ? cardGuide : {};
211
+ var autoCaptureFiredRef = useRef(false);
212
+ var handleGuideReady = useCallback(function () {
213
+ if (autoCaptureFiredRef.current)
214
+ return;
215
+ autoCaptureFiredRef.current = true;
216
+ if (typeof navigator.vibrate === "function")
217
+ navigator.vibrate(CAPTURE_VIBRATION_MS);
218
+ captureDocument("auto").catch(function () {
219
+ // captureDocument already sets the error state; allow the next "ready" to capture again
220
+ autoCaptureFiredRef.current = false;
221
+ });
222
+ }, [captureDocument]);
223
+ var cardGuideState = useCardCaptureGuide(videoRef, {
224
+ active: !!cardGuide,
225
+ modelUrl: guideConfig.modelUrl,
226
+ wasmPaths: guideConfig.wasmPaths,
227
+ enabled: isDetecting && !isProcessing,
228
+ tracker: guideConfig.tracker,
229
+ onReady: handleGuideReady,
230
+ onGuidance: function (event) { var _a; return (_a = telemetryRef.current) === null || _a === void 0 ? void 0 : _a.guidance(event.code, performance.now()); },
231
+ onTiming: function (_a) {
232
+ var _b, _c;
233
+ var kind = _a.kind, ms = _a.ms;
234
+ if (kind === "load")
235
+ (_b = telemetryRef.current) === null || _b === void 0 ? void 0 : _b.modelLoaded(ms);
236
+ else
237
+ (_c = telemetryRef.current) === null || _c === void 0 ? void 0 : _c.inference(ms);
238
+ },
239
+ });
240
+ var guideFailed = !!cardGuide && !!cardGuideState.error;
241
+ sendTelemetryRef.current = function (trigger) {
242
+ var collector = telemetryRef.current;
243
+ if (!collector || !sessionId)
244
+ return;
245
+ telemetryRef.current = null;
246
+ var payload = collector.build({ trigger: trigger, guideStatus: guideFailed ? "fallback" : "active", at: performance.now() });
247
+ reportCaptureTelemetry(sessionId, payload).catch(function () {
248
+ // telemetry is best effort: never surface it to the end user
176
249
  });
177
- }); }, [facingMode, onCapture, stopDetection, maskRect, t, triggerCaptureFeedback]);
250
+ };
251
+ var guideActive = !!cardGuide && cardGuideState.modelReady && !guideFailed;
252
+ var guideLoading = !!cardGuide && !cardGuideState.modelReady && !guideFailed;
253
+ var legacyDetectionOn = !cardGuide || guideFailed;
254
+ var guideCode = useMinDisplay(guideActive ? ((_c = (_b = cardGuideState.event) === null || _b === void 0 ? void 0 : _b.code) !== null && _c !== void 0 ? _c : "no_card") : "no_card", GUIDE_MESSAGE_MIN_MS);
255
+ useEffect(function () {
256
+ if (guideFailed) {
257
+ console.warn("[CardCaptureGuide] model unavailable, falling back to the historical capture aid:", cardGuideState.error);
258
+ }
259
+ }, [guideFailed, cardGuideState.error]);
178
260
  var startCountdown = useCallback(function () {
179
261
  if (isCountingDown)
180
262
  return;
@@ -190,7 +272,7 @@ var Photo = function (_a) {
190
272
  countdownIntervalRef.current = null;
191
273
  }
192
274
  setIsCountingDown(false);
193
- captureDocument().catch(function () {
275
+ captureDocument("auto").catch(function () {
194
276
  // Error is handled inside captureDocument, but keep the promise chain quiet
195
277
  });
196
278
  }
@@ -220,7 +302,7 @@ var Photo = function (_a) {
220
302
  useEffect(function () {
221
303
  var isCancelled = false;
222
304
  var initCamera = function () { return __awaiter(void 0, void 0, void 0, function () {
223
- var result, belowHd;
305
+ var result, belowHd, telemetryInit;
224
306
  var _a, _b, _c, _d;
225
307
  return __generator(this, function (_e) {
226
308
  switch (_e.label) {
@@ -254,6 +336,16 @@ var Photo = function (_a) {
254
336
  }).catch(function () { });
255
337
  }
256
338
  setLastCaptureMeta(null);
339
+ telemetryInit = telemetryInitRef.current;
340
+ if (telemetryInit.enabled && sessionId && nodeId && !telemetryRef.current) {
341
+ telemetryRef.current = new CaptureTelemetryCollector({
342
+ nodeId: nodeId,
343
+ side: telemetryInit.side,
344
+ documentType: telemetryInit.documentType,
345
+ deviceType: detectDeviceType(),
346
+ startedAt: performance.now(),
347
+ });
348
+ }
257
349
  // Detection also runs in manual mode: it only drives the visual
258
350
  // feedback on the mask (documentDetected), it never starts the
259
351
  // auto-capture countdown unless automaticCapture is true (see
@@ -282,7 +374,7 @@ var Photo = function (_a) {
282
374
  };
283
375
  }, [facingMode, cameraAttempt, sessionId, nodeId, clearCountdown, stopDetection]);
284
376
  useEffect(function () {
285
- if (!isDetecting || !videoRef.current) {
377
+ if (!isDetecting || !legacyDetectionOn || !videoRef.current) {
286
378
  return;
287
379
  }
288
380
  var cancelled = false;
@@ -310,7 +402,7 @@ var Photo = function (_a) {
310
402
  detectionHandlerRef.current = null;
311
403
  }
312
404
  };
313
- }, [handleDetectionChange, isDetecting]);
405
+ }, [handleDetectionChange, isDetecting, legacyDetectionOn]);
314
406
  var toggleCamera = function () {
315
407
  setFacingMode(function (prev) { return (prev === "environment" ? "user" : "environment"); });
316
408
  cancelCaptureTimer();
@@ -334,22 +426,38 @@ var Photo = function (_a) {
334
426
  // captureDocument already logs and sets error state
335
427
  });
336
428
  };
337
- var statusMessage = qualityHint === "too_dark"
429
+ var legacyStatusMessage = qualityHint === "too_dark"
338
430
  ? t("id_check.photo.hint.too_dark", "Trop sombre, cherchez plus de lumière")
339
431
  : qualityHint === "too_bright"
340
432
  ? t("id_check.photo.hint.too_bright", "Trop de reflets, évitez la lumière directe")
341
433
  : automaticCapture
342
434
  ? t("id_check.photo.automatic_instruction", "Capture automatique active ou appuyez sur le bouton")
343
435
  : t("id_check.photo.manual_instruction", "Appuyez sur le bouton pour capturer");
436
+ var statusMessage = guideActive
437
+ ? t("card_capture_guide.".concat(guideCode), GUIDE_FALLBACK[guideCode])
438
+ : guideLoading
439
+ ? t("card_capture_guide.loading", "Chargement du guide…")
440
+ : legacyStatusMessage;
441
+ var showAutoCapture = automaticCapture || guideActive;
442
+ var maskDocumentDetected = guideActive
443
+ ? GUIDE_TRACKING_CODES.has((_e = (_d = cardGuideState.event) === null || _d === void 0 ? void 0 : _d.code) !== null && _e !== void 0 ? _e : "no_card")
444
+ : documentDetected;
445
+ var maskQualityHint = guideActive
446
+ ? guideCode === "too_dark"
447
+ ? "too_dark"
448
+ : guideCode === "bright_spot"
449
+ ? "too_bright"
450
+ : undefined
451
+ : qualityHint;
344
452
  return (jsxs("div", { className: "flex flex-col", style: {
345
453
  position: isMobile ? "fixed" : "relative",
346
454
  inset: isMobile ? 0 : "auto",
347
455
  zIndex: isMobile ? 50 : "auto",
348
456
  height: "100%",
349
457
  width: "100%",
350
- }, children: [jsx("div", { className: "flex-1 relative overflow-hidden bg-black", children: cameraError ? (jsx("div", { className: "flex items-center justify-center h-full px-4 py-6", children: jsx(CameraError, { errorMessage: cameraError, onRetry: handleRetry }) })) : (jsxs(Fragment, { children: [isInitializing && (jsxs("div", { "data-testid": "camera-initializing", className: "absolute inset-0 z-30 flex flex-col items-center justify-center gap-3 bg-black", children: [jsx("div", { className: "w-10 h-10 border-4 border-white border-t-transparent rounded-full animate-spin" }), jsx("span", { className: "text-white text-sm", children: t("id_check.photo.initializing", "Ouverture de la caméra…") })] })), isProcessing && (jsxs("div", { "data-testid": "camera-processing", className: "absolute inset-0 z-30 flex flex-col items-center justify-center gap-3 bg-black bg-opacity-70", children: [jsx("div", { className: "w-10 h-10 border-4 border-white border-t-transparent rounded-full animate-spin" }), jsx("span", { className: "text-white text-sm", children: t("id_check.photo.processing", "Traitement de l'image…") })] })), jsx("video", { ref: videoRef, autoPlay: true, playsInline: true, muted: true, className: "absolute inset-0 w-full h-full object-cover z-0 bg-black ".concat(facingMode === "user" ? "scale-x-[-1]" : "") }), jsx("div", { className: "absolute top-4 left-1/2 transform -translate-x-1/2 z-50", children: jsx("span", { className: "text-white z-50 text-sm font-semibold drop-shadow-lg", children: automaticCapture ? (jsx("span", { className: "animate-pulse", children: t("id_check.photo.mode_autocapture", "Autocapture activée") })) : (jsx("span", { className: "bg-orange-500 px-2 py-1 rounded hidden", children: t("id_check.photo.mode_manual", "Mode manuel") })) }) }), jsx(CameraMask, { isDetecting: isDetecting, isPortrait: isPortrait, facingMode: facingMode, isCountingDown: isCountingDown, countdown: countdown, maskType: maskType, documentDetected: documentDetected, qualityHint: qualityHint, onMaskRectChange: setMaskRect }), jsx("div", { className: "absolute bottom-20 left-0 right-0 z-20 pointer-events-none", children: jsx("div", { className: "text-center px-4", children: jsx("div", { className: "bg-black bg-opacity-60 text-white text-sm px-4 py-2 rounded-lg inline-block", children: t("id_check.photo.position_document", "Posez le document à plat ou tenez-le dans le cadre") }) }) }), jsx(OrientationToggle, { onCameraToggle: toggleCamera }), lowResolution && !cameraError && (jsx("div", { role: "status", className: "absolute inset-x-3 z-30 ".concat(automaticCapture ? "top-12" : "top-3"), children: jsx("div", { className: "rounded-xl bg-black/75 text-white shadow-lg backdrop-blur-sm", children: jsxs("details", { className: "group", children: [jsxs("summary", { className: "flex min-h-11 cursor-pointer list-none items-center gap-2 rounded-xl px-3 py-2 text-sm font-medium focus-visible:outline focus-visible:outline-2 focus-visible:outline-white [&::-webkit-details-marker]:hidden", children: [jsx("svg", { "aria-hidden": "true", className: "h-5 w-5 shrink-0 text-amber-400", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: 2, children: jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M12 9v4m0 4h.01M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0Z" }) }), jsx("span", { className: "min-w-0 flex-1", children: t("id_check.camera.low_resolution.title") }), jsx("svg", { "aria-hidden": "true", className: "h-4 w-4 shrink-0 transition-transform group-open:rotate-180 motion-reduce:transition-none", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: 2, children: jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "m6 9 6 6 6-6" }) })] }), jsxs("div", { className: "space-y-2 px-3 pb-3 text-sm leading-relaxed text-white/85", children: [jsx("p", { children: t("id_check.camera.low_resolution.body") }), jsx("p", { children: t("id_check.camera.low_resolution.tips") }), jsx("button", { type: "button", onClick: handleRetry, disabled: isProcessing, className: "min-h-11 w-full rounded-lg bg-white px-4 font-medium text-gray-900 hover:bg-white/90 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white disabled:opacity-50", children: t("id_check.camera.low_resolution.retry") })] })] }) }) })), showCaptureFlash && (jsx("div", { "data-testid": "capture-flash", className: "absolute inset-0 z-40 bg-white pointer-events-none animate-pulse" }))] })) }), jsx("div", { className: "relative z-20 bg-black bg-opacity-80 p-4", children: jsxs("div", { className: "flex flex-col items-center space-y-4", children: [jsx("button", { onClick: handleManualCapture, className: "w-16 h-16 rounded-full border-4 border-white flex items-center justify-center transition-all duration-150 bg-transparent hover:bg-white hover:bg-opacity-20 cursor-pointer ".concat(showCaptureFlash ? "scale-90 ring-4 ring-[#11E5C5]" : ""), children: jsx("div", { className: "w-8 h-8 bg-white rounded-full" }) }), jsxs("div", { className: "text-white text-center text-sm", children: [jsxs("div", { className: "flex items-center justify-center space-x-2", children: [jsx("div", { className: "w-2 h-2 rounded-full ".concat(automaticCapture
458
+ }, children: [jsx("div", { className: "flex-1 relative overflow-hidden bg-black", children: cameraError ? (jsx("div", { className: "flex items-center justify-center h-full px-4 py-6", children: jsx(CameraError, { errorMessage: cameraError, onRetry: handleRetry }) })) : (jsxs(Fragment, { children: [isInitializing && (jsxs("div", { "data-testid": "camera-initializing", className: "absolute inset-0 z-30 flex flex-col items-center justify-center gap-3 bg-black", children: [jsx("div", { className: "w-10 h-10 border-4 border-white border-t-transparent rounded-full animate-spin" }), jsx("span", { className: "text-white text-sm", children: t("id_check.photo.initializing", "Ouverture de la caméra…") })] })), isProcessing && (jsxs("div", { "data-testid": "camera-processing", className: "absolute inset-0 z-30 flex flex-col items-center justify-center gap-3 bg-black bg-opacity-70", children: [jsx("div", { className: "w-10 h-10 border-4 border-white border-t-transparent rounded-full animate-spin" }), jsx("span", { className: "text-white text-sm", children: t("id_check.photo.processing", "Traitement de l'image…") })] })), jsx("video", { ref: videoRef, autoPlay: true, playsInline: true, muted: true, className: "absolute inset-0 w-full h-full object-cover z-0 bg-black ".concat(facingMode === "user" ? "scale-x-[-1]" : "") }), jsx("div", { className: "absolute top-4 left-1/2 transform -translate-x-1/2 z-50", children: jsx("span", { className: "text-white z-50 text-sm font-semibold drop-shadow-lg", children: showAutoCapture ? (jsx("span", { className: "animate-pulse", children: t("id_check.photo.mode_autocapture", "Autocapture activée") })) : (jsx("span", { className: "bg-orange-500 px-2 py-1 rounded hidden", children: t("id_check.photo.mode_manual", "Mode manuel") })) }) }), jsx(CameraMask, { isDetecting: isDetecting, isPortrait: isPortrait, facingMode: facingMode, isCountingDown: isCountingDown, countdown: countdown, maskType: maskType, documentDetected: maskDocumentDetected, qualityHint: maskQualityHint, onMaskRectChange: setMaskRect }), jsx("div", { className: "absolute bottom-20 left-0 right-0 z-20 pointer-events-none", children: jsx("div", { className: "text-center px-4", children: jsx("div", { className: "bg-black bg-opacity-60 text-white text-sm px-4 py-2 rounded-lg inline-block", children: t("id_check.photo.position_document", "Posez le document à plat ou tenez-le dans le cadre") }) }) }), jsx(OrientationToggle, { onCameraToggle: toggleCamera }), lowResolution && !cameraError && (jsx("div", { role: "status", className: "absolute inset-x-3 z-30 ".concat(showAutoCapture ? "top-12" : "top-3"), children: jsx("div", { className: "rounded-xl bg-black/75 text-white shadow-lg backdrop-blur-sm", children: jsxs("details", { className: "group", children: [jsxs("summary", { className: "flex min-h-11 cursor-pointer list-none items-center gap-2 rounded-xl px-3 py-2 text-sm font-medium focus-visible:outline focus-visible:outline-2 focus-visible:outline-white [&::-webkit-details-marker]:hidden", children: [jsx("svg", { "aria-hidden": "true", className: "h-5 w-5 shrink-0 text-amber-400", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: 2, children: jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M12 9v4m0 4h.01M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0Z" }) }), jsx("span", { className: "min-w-0 flex-1", children: t("id_check.camera.low_resolution.title") }), jsx("svg", { "aria-hidden": "true", className: "h-4 w-4 shrink-0 transition-transform group-open:rotate-180 motion-reduce:transition-none", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: 2, children: jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "m6 9 6 6 6-6" }) })] }), jsxs("div", { className: "space-y-2 px-3 pb-3 text-sm leading-relaxed text-white/85", children: [jsx("p", { children: t("id_check.camera.low_resolution.body") }), jsx("p", { children: t("id_check.camera.low_resolution.tips") }), jsx("button", { type: "button", onClick: handleRetry, disabled: isProcessing, className: "min-h-11 w-full rounded-lg bg-white px-4 font-medium text-gray-900 hover:bg-white/90 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white disabled:opacity-50", children: t("id_check.camera.low_resolution.retry") })] })] }) }) })), showCaptureFlash && (jsx("div", { "data-testid": "capture-flash", className: "absolute inset-0 z-40 bg-white pointer-events-none animate-pulse" }))] })) }), jsx("div", { className: "relative z-20 bg-black bg-opacity-80 p-4", children: jsxs("div", { className: "flex flex-col items-center space-y-4", children: [jsx("button", { onClick: handleManualCapture, className: "w-16 h-16 rounded-full border-4 border-white flex items-center justify-center transition-all duration-150 bg-transparent hover:bg-white hover:bg-opacity-20 cursor-pointer ".concat(showCaptureFlash ? "scale-90 ring-4 ring-[#11E5C5]" : ""), children: jsx("div", { className: "w-8 h-8 bg-white rounded-full" }) }), jsxs("div", { className: "text-white text-center text-sm", children: [jsxs("div", { className: "flex items-center justify-center space-x-2", children: [jsx("div", { className: "w-2 h-2 rounded-full ".concat(showAutoCapture
351
459
  ? "bg-[#11E5C5] animate-pulse"
352
- : "bg-orange-500") }), jsx("span", { children: statusMessage })] }), captureError && (jsx("p", { className: "text-red-400 text-xs mt-2 text-center", children: captureError }))] })] }) })] }));
460
+ : "bg-orange-500") }), jsx("span", { "aria-live": "polite", "aria-atomic": "true", children: statusMessage })] }), captureError && (jsx("p", { className: "text-red-400 text-xs mt-2 text-center", children: captureError }))] })] }) })] }));
353
461
  };
354
462
 
355
463
  export { Photo as default };