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