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.
- package/dist/cjs/components/DatakeenSession.js +17 -16
- package/dist/cjs/components/card-capture-guide/CardCaptureGuide.js +139 -0
- package/dist/cjs/components/card-capture-guide/captureTelemetry.js +81 -0
- package/dist/cjs/components/card-capture-guide/guidance.js +48 -0
- package/dist/cjs/components/card-capture-guide/guideCore.js +389 -0
- package/dist/cjs/components/card-capture-guide/guideRuntime.js +118 -0
- package/dist/cjs/components/card-capture-guide/modelLoader.js +46 -0
- package/dist/cjs/components/card-capture-guide/useCaptureGuideThresholds.js +33 -0
- package/dist/cjs/components/card-capture-guide/useCardCaptureGuide.js +117 -0
- package/dist/cjs/components/card-capture-guide/useMinDisplay.js +30 -0
- package/dist/cjs/components/document-collection/DocumentCollection.js +9 -0
- package/dist/cjs/components/id-check/Photo.js +230 -122
- package/dist/cjs/components/id-check/card-capture/CardCapture.js +270 -0
- package/dist/cjs/components/id-check/card-capture/DynamicCardMask.js +85 -0
- package/dist/cjs/components/id-check/card-capture/geometry.js +119 -0
- package/dist/cjs/components/id-check/card-capture/guideTone.js +15 -0
- package/dist/cjs/components/jdi/JDIDocumentSelection.js +9 -0
- package/dist/cjs/components/selfie/Video.js +2 -2
- package/dist/cjs/components/selfie/selfie-flow/SelfieFlow.js +4 -2
- package/dist/cjs/components/session/DocumentCheck.js +37 -2
- package/dist/cjs/components/session/EndFlow.js +4 -0
- package/dist/cjs/components/session/Selfie.js +1 -1
- package/dist/cjs/components/signature-electronic/SignatureElectronic.js +9 -2
- package/dist/cjs/components/start-flow/Start.js +4 -0
- package/dist/cjs/components/template/TemplateNodeRenderer.js +3 -1
- package/dist/cjs/components/ui/Button.js +3 -3
- package/dist/cjs/context/CardCaptureGuideContext.js +16 -0
- package/dist/cjs/hooks/useClientInfo.js +7 -0
- package/dist/cjs/hooks/useUserInputForm.js +3 -1
- package/dist/cjs/i18n/en.json.js +57 -1
- package/dist/cjs/i18n/es.json.js +57 -1
- package/dist/cjs/i18n/fr.json.js +57 -1
- package/dist/cjs/index.css.js +1 -1
- package/dist/cjs/index.js +15 -0
- package/dist/cjs/preview/DatakeenJourneyPreview.js +257 -0
- package/dist/cjs/preview/PreviewAutomaticStep.js +23 -0
- package/dist/cjs/preview/PreviewBranchPicker.js +54 -0
- package/dist/cjs/preview/PreviewCaptureDisabled.js +19 -0
- package/dist/cjs/preview/previewAdapter.js +27 -0
- package/dist/cjs/preview/previewMode.js +21 -0
- package/dist/cjs/preview/previewNavigation.js +105 -0
- package/dist/cjs/services/api.js +5 -0
- package/dist/cjs/services/cameraService.js +6 -0
- package/dist/cjs/services/realtime/sseClient.js +4 -0
- package/dist/cjs/services/sessionService.js +50 -0
- package/dist/cjs/utils/cssLoader.js +6 -4
- package/dist/cjs/utils/isMobileDevice.js +8 -0
- package/dist/esm/components/DatakeenSession.js +17 -16
- package/dist/esm/components/card-capture-guide/CardCaptureGuide.js +135 -0
- package/dist/esm/components/card-capture-guide/captureTelemetry.js +78 -0
- package/dist/esm/components/card-capture-guide/guidance.js +44 -0
- package/dist/esm/components/card-capture-guide/guideCore.js +372 -0
- package/dist/esm/components/card-capture-guide/guideRuntime.js +115 -0
- package/dist/esm/components/card-capture-guide/modelLoader.js +42 -0
- package/dist/esm/components/card-capture-guide/useCaptureGuideThresholds.js +31 -0
- package/dist/esm/components/card-capture-guide/useCardCaptureGuide.js +115 -0
- package/dist/esm/components/card-capture-guide/useMinDisplay.js +28 -0
- package/dist/esm/components/document-collection/DocumentCollection.js +10 -1
- package/dist/esm/components/id-check/Photo.js +232 -124
- package/dist/esm/components/id-check/card-capture/CardCapture.js +266 -0
- package/dist/esm/components/id-check/card-capture/DynamicCardMask.js +81 -0
- package/dist/esm/components/id-check/card-capture/geometry.js +110 -0
- package/dist/esm/components/id-check/card-capture/guideTone.js +13 -0
- package/dist/esm/components/jdi/JDIDocumentSelection.js +9 -0
- package/dist/esm/components/selfie/Video.js +2 -2
- package/dist/esm/components/selfie/selfie-flow/SelfieFlow.js +4 -2
- package/dist/esm/components/session/DocumentCheck.js +37 -2
- package/dist/esm/components/session/EndFlow.js +4 -0
- package/dist/esm/components/session/Selfie.js +1 -1
- package/dist/esm/components/signature-electronic/SignatureElectronic.js +9 -2
- package/dist/esm/components/start-flow/Start.js +4 -0
- package/dist/esm/components/template/TemplateNodeRenderer.js +3 -1
- package/dist/esm/components/ui/Button.js +3 -3
- package/dist/esm/context/CardCaptureGuideContext.js +13 -0
- package/dist/esm/hooks/useClientInfo.js +7 -0
- package/dist/esm/hooks/useUserInputForm.js +3 -1
- package/dist/esm/i18n/en.json.js +55 -2
- package/dist/esm/i18n/es.json.js +55 -2
- package/dist/esm/i18n/fr.json.js +55 -2
- package/dist/esm/index.css.js +1 -1
- package/dist/esm/index.js +6 -0
- package/dist/esm/preview/DatakeenJourneyPreview.js +253 -0
- package/dist/esm/preview/PreviewAutomaticStep.js +19 -0
- package/dist/esm/preview/PreviewBranchPicker.js +48 -0
- package/dist/esm/preview/PreviewCaptureDisabled.js +15 -0
- package/dist/esm/preview/previewAdapter.js +25 -0
- package/dist/esm/preview/previewMode.js +15 -0
- package/dist/esm/preview/previewNavigation.js +98 -0
- package/dist/esm/services/api.js +5 -0
- package/dist/esm/services/cameraService.js +6 -0
- package/dist/esm/services/realtime/sseClient.js +4 -0
- package/dist/esm/services/sessionService.js +49 -1
- package/dist/esm/utils/cssLoader.js +6 -4
- package/dist/esm/utils/isMobileDevice.js +8 -0
- package/dist/types/components/card-capture-guide/CardCaptureGuide.d.ts +46 -0
- package/dist/types/components/card-capture-guide/guidance.d.ts +45 -0
- package/dist/types/components/card-capture-guide/guideCore.d.ts +96 -0
- package/dist/types/components/card-capture-guide/guideRuntime.d.ts +13 -0
- package/dist/types/components/card-capture-guide/modelLoader.d.ts +13 -0
- package/dist/types/components/card-capture-guide/useCardCaptureGuide.d.ts +38 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/preview/DatakeenJourneyPreview.d.ts +6 -0
- package/dist/types/preview/types.d.ts +77 -0
- package/dist/types/services/documentTemplate.d.ts +13 -0
- package/dist/types/types/camera.d.ts +3 -0
- package/dist/types/types/session.d.ts +268 -1
- package/dist/types/utils/cssLoader.d.ts +0 -4
- 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
|
|
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
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
var
|
|
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
|
|
34
|
-
var
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
}
|
|
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
|
|
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:
|
|
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 };
|