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
@@ -0,0 +1,266 @@
1
+ import { __assign } from '../../../node_modules/tslib/tslib.es6.js';
2
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
3
+ import { useRef, useState, useEffect, useCallback } from 'react';
4
+ import { SwitchCamera, LoaderCircle, Check, TriangleAlert, Hand, Info } from 'lucide-react';
5
+ import { cameraService } from '../../../services/cameraService.js';
6
+ import { reportCaptureDiagnostics, reportCaptureTelemetry } from '../../../services/sessionService.js';
7
+ import { useI18n } from '../../../hooks/useI18n.js';
8
+ import useIsMobile from '../../../hooks/useIsMobile.js';
9
+ import { isBelowHd } from '../../../utils/cameraResolution.js';
10
+ import { useCardCaptureGuide } from '../../card-capture-guide/useCardCaptureGuide.js';
11
+ import { useMinDisplay } from '../../card-capture-guide/useMinDisplay.js';
12
+ import { CaptureTelemetryCollector, detectDeviceType } from '../../card-capture-guide/captureTelemetry.js';
13
+ import CameraError from '../CameraError.js';
14
+ import DynamicCardMask from './DynamicCardMask.js';
15
+ import { guideTone } from './guideTone.js';
16
+ import { cropRectFromCorners, viewportRectToVideo, idCardFrameRect } from './geometry.js';
17
+
18
+ // FR fallbacks, same as fr.json
19
+ var GUIDE_FALLBACK = {
20
+ no_card: "Placez votre pièce d'identité dans le cadre",
21
+ too_far: "Rapprochez la carte",
22
+ too_dark: "Augmenter la luminosité",
23
+ card_detected: "Carte détectée — gardez-la dans le cadre",
24
+ hold_still: "Ne bougez plus…",
25
+ too_blurry: "Ajuster la focalisation",
26
+ bright_spot: "Éviter les reflets",
27
+ ready: "Parfait — capture en cours",
28
+ };
29
+ var PILL_CLASS = {
30
+ loading: "bg-black/70 text-white",
31
+ neutral: "bg-black/70 text-white",
32
+ warning: "bg-amber-100 text-amber-900",
33
+ progress: "bg-teal-50 text-teal-900",
34
+ success: "bg-teal-50 text-teal-900",
35
+ };
36
+ var MESSAGE_MIN_MS = 700;
37
+ var NUDGE_AFTER_MS = 8000;
38
+ var FLASH_MS = 150;
39
+ /** The spinner stays at least this long, even when the capture is instant: no flicker, the user sees it saved. */
40
+ var MIN_SAVING_MS = 1000;
41
+ /** Success check shown before leaving the screen. */
42
+ var SAVED_CONFIRM_MS = 400;
43
+ var VIBRATION_MS = 60;
44
+ var DEFAULT_HOLD_MS = 600;
45
+ var RING_RADIUS = 33;
46
+ var RING_LENGTH = 2 * Math.PI * RING_RADIUS;
47
+ var ToneIcon = function (_a) {
48
+ var tone = _a.tone;
49
+ var props = { className: "h-4 w-4 shrink-0", "aria-hidden": true };
50
+ if (tone === "loading")
51
+ return jsx(LoaderCircle, __assign({}, props, { className: "h-4 w-4 shrink-0 motion-safe:animate-spin" }));
52
+ if (tone === "warning")
53
+ return jsx(TriangleAlert, __assign({}, props));
54
+ if (tone === "progress")
55
+ return jsx(Hand, __assign({}, props));
56
+ if (tone === "success")
57
+ return jsx(Check, __assign({}, props));
58
+ return jsx(Info, __assign({}, props));
59
+ };
60
+ /**
61
+ * Live capture of a card-format identity document (APP3-2117): the mask follows the card detected by the
62
+ * on-device model, one guidance message at a time, automatic capture cropped to the card, manual capture
63
+ * always available, static ID-1 frame when the model is loading or unavailable.
64
+ */
65
+ var CardCapture = function (_a) {
66
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k;
67
+ var onCapture = _a.onCapture, sessionId = _a.sessionId, nodeId = _a.nodeId, _l = _a.captureSide, captureSide = _l === void 0 ? "recto" : _l, documentType = _a.documentType, guide = _a.guide;
68
+ var t = useI18n().t;
69
+ var isMobile = useIsMobile(768);
70
+ var videoRef = useRef(null);
71
+ var boxRef = useRef(null);
72
+ var _m = useState("environment"), facingMode = _m[0], setFacingMode = _m[1];
73
+ var _o = useState(0), cameraAttempt = _o[0], setCameraAttempt = _o[1];
74
+ var _p = useState(false), cameraReady = _p[0], setCameraReady = _p[1];
75
+ var _q = useState(null), cameraError = _q[0], setCameraError = _q[1];
76
+ var _r = useState(false), lowResolution = _r[0], setLowResolution = _r[1];
77
+ var _s = useState(false), isProcessing = _s[0], setIsProcessing = _s[1];
78
+ var _t = useState(null), captureError = _t[0], setCaptureError = _t[1];
79
+ var _u = useState(false), showFlash = _u[0], setShowFlash = _u[1];
80
+ var _v = useState(false), showNudge = _v[0], setShowNudge = _v[1];
81
+ /** null = live camera; "saving" = frozen frame + spinner; "saved" = frozen frame + check. */
82
+ var _w = useState(null), savePhase = _w[0], setSavePhase = _w[1];
83
+ var _x = useState(null), frozenCorners = _x[0], setFrozenCorners = _x[1];
84
+ var frozenRef = useRef(null);
85
+ var mountedRef = useRef(true);
86
+ useEffect(function () {
87
+ mountedRef.current = true;
88
+ return function () {
89
+ mountedRef.current = false;
90
+ };
91
+ }, []);
92
+ var processingRef = useRef(false);
93
+ var autoFiredRef = useRef(false);
94
+ var telemetryRef = useRef(null);
95
+ useEffect(function () {
96
+ var cancelled = false;
97
+ setCameraReady(false);
98
+ setCameraError(null);
99
+ cameraService
100
+ .startCamera(videoRef.current, { facingMode: facingMode, idealResolution: { width: 4096, height: 3072 }, preferImageCapture: true })
101
+ .then(function (result) {
102
+ var _a, _b, _c, _d, _e;
103
+ if (cancelled)
104
+ return;
105
+ if (!result.success) {
106
+ setCameraError((_a = result.error) !== null && _a !== void 0 ? _a : t("id_check.camera.error", "Impossible de démarrer la caméra"));
107
+ return;
108
+ }
109
+ var belowHd = isBelowHd(result.settings);
110
+ setLowResolution(belowHd);
111
+ if (sessionId && nodeId) {
112
+ reportCaptureDiagnostics(sessionId, nodeId, {
113
+ requested: result.requested,
114
+ obtained: { w: (_b = result.settings) === null || _b === void 0 ? void 0 : _b.width, h: (_c = result.settings) === null || _c === void 0 ? void 0 : _c.height, frameRate: (_d = result.settings) === null || _d === void 0 ? void 0 : _d.frameRate },
115
+ retriedWithHd: (_e = result.retriedWithHd) !== null && _e !== void 0 ? _e : false,
116
+ devicePixelRatio: window.devicePixelRatio,
117
+ cameraLabel: result.label,
118
+ lowResolutionWarningShown: belowHd,
119
+ facingMode: facingMode,
120
+ at: new Date().toISOString(),
121
+ }).catch(function () { });
122
+ if (!telemetryRef.current) {
123
+ telemetryRef.current = new CaptureTelemetryCollector({
124
+ nodeId: nodeId,
125
+ side: captureSide,
126
+ documentType: documentType,
127
+ deviceType: detectDeviceType(),
128
+ startedAt: performance.now(),
129
+ });
130
+ }
131
+ }
132
+ setCameraReady(true);
133
+ })
134
+ .catch(function () {
135
+ if (!cancelled)
136
+ setCameraError(t("id_check.camera.error", "Impossible de démarrer la caméra"));
137
+ });
138
+ return function () {
139
+ cancelled = true;
140
+ cameraService.stopCamera();
141
+ };
142
+ // The camera restarts only when the user switches camera or retries.
143
+ // eslint-disable-next-line react-hooks/exhaustive-deps
144
+ }, [facingMode, cameraAttempt]);
145
+ useEffect(function () {
146
+ if (!cameraReady || isProcessing)
147
+ return;
148
+ var timer = setTimeout(function () { return setShowNudge(true); }, NUDGE_AFTER_MS);
149
+ return function () { return clearTimeout(timer); };
150
+ }, [cameraReady, isProcessing]);
151
+ var captureRef = useRef(function () { });
152
+ var guideState = useCardCaptureGuide(videoRef, {
153
+ modelUrl: guide === null || guide === void 0 ? void 0 : guide.modelUrl,
154
+ wasmPaths: guide === null || guide === void 0 ? void 0 : guide.wasmPaths,
155
+ tracker: guide === null || guide === void 0 ? void 0 : guide.tracker,
156
+ enabled: cameraReady && !isProcessing,
157
+ onReady: function (update) {
158
+ if (autoFiredRef.current)
159
+ return;
160
+ autoFiredRef.current = true;
161
+ if (typeof navigator.vibrate === "function")
162
+ navigator.vibrate(VIBRATION_MS);
163
+ captureRef.current("auto", update.corners);
164
+ },
165
+ onGuidance: function (event) { var _a; return (_a = telemetryRef.current) === null || _a === void 0 ? void 0 : _a.guidance(event.code, performance.now()); },
166
+ onTiming: function (_a) {
167
+ var _b, _c;
168
+ var kind = _a.kind, ms = _a.ms;
169
+ if (kind === "load")
170
+ (_b = telemetryRef.current) === null || _b === void 0 ? void 0 : _b.modelLoaded(ms);
171
+ else
172
+ (_c = telemetryRef.current) === null || _c === void 0 ? void 0 : _c.inference(ms);
173
+ },
174
+ });
175
+ var guideFailed = !!guideState.error;
176
+ var guideActive = guideState.modelReady && !guideFailed;
177
+ var event = guideActive ? guideState.event : null;
178
+ var shownCode = useMinDisplay((_b = event === null || event === void 0 ? void 0 : event.code) !== null && _b !== void 0 ? _b : "no_card", MESSAGE_MIN_MS);
179
+ var trackedCorners = (_c = event === null || event === void 0 ? void 0 : event.corners) !== null && _c !== void 0 ? _c : null;
180
+ var tone = guideActive ? guideTone(shownCode) : "neutral";
181
+ var holding = (event === null || event === void 0 ? void 0 : event.code) === "hold_still";
182
+ var holdMs = (_e = (_d = guide === null || guide === void 0 ? void 0 : guide.tracker) === null || _d === void 0 ? void 0 : _d.holdMs) !== null && _e !== void 0 ? _e : DEFAULT_HOLD_MS;
183
+ var staticFrameCrop = function () {
184
+ var video = videoRef.current;
185
+ var box = boxRef.current;
186
+ if (!video || !box)
187
+ return null;
188
+ var boxWidth = box.clientWidth;
189
+ var boxHeight = box.clientHeight;
190
+ return viewportRectToVideo(idCardFrameRect(boxWidth, boxHeight), {
191
+ videoWidth: video.videoWidth,
192
+ videoHeight: video.videoHeight,
193
+ boxWidth: boxWidth,
194
+ boxHeight: boxHeight,
195
+ mirrored: facingMode === "user",
196
+ });
197
+ };
198
+ captureRef.current = function (trigger, corners) {
199
+ var _a, _b;
200
+ var video = videoRef.current;
201
+ if (processingRef.current || !video || !video.videoWidth || !video.videoHeight)
202
+ return;
203
+ processingRef.current = true;
204
+ // Freeze what the user saw at the shutter (synchronous: before any await), the card stays highlighted.
205
+ var frozen = frozenRef.current;
206
+ if (frozen) {
207
+ frozen.width = video.videoWidth;
208
+ frozen.height = video.videoHeight;
209
+ (_a = frozen.getContext("2d")) === null || _a === void 0 ? void 0 : _a.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
210
+ }
211
+ setFrozenCorners(corners);
212
+ setSavePhase("saving");
213
+ setIsProcessing(true);
214
+ setCaptureError(null);
215
+ setShowFlash(true);
216
+ window.setTimeout(function () { return setShowFlash(false); }, FLASH_MS);
217
+ var crop = (_b = (corners ? cropRectFromCorners(corners, video.videoWidth, video.videoHeight) : null)) !== null && _b !== void 0 ? _b : staticFrameCrop();
218
+ var minimumWait = new Promise(function (resolve) { return window.setTimeout(resolve, MIN_SAVING_MS); });
219
+ Promise.all([
220
+ cameraService.captureDocument(video, crop, { facingMode: facingMode, format: "jpeg", jpegQuality: 0.95, preferImageCapture: false }),
221
+ minimumWait,
222
+ ])
223
+ .then(function (_a) {
224
+ var result = _a[0];
225
+ if (!mountedRef.current)
226
+ return;
227
+ var collector = telemetryRef.current;
228
+ telemetryRef.current = null;
229
+ if (collector && sessionId) {
230
+ var payload = collector.build({ trigger: trigger, guideStatus: guideFailed ? "fallback" : "active", at: performance.now() });
231
+ reportCaptureTelemetry(sessionId, payload).catch(function () { });
232
+ }
233
+ setSavePhase("saved");
234
+ window.setTimeout(function () {
235
+ if (mountedRef.current)
236
+ onCapture(result.dataUrl);
237
+ }, SAVED_CONFIRM_MS);
238
+ })
239
+ .catch(function () {
240
+ if (!mountedRef.current)
241
+ return;
242
+ processingRef.current = false;
243
+ autoFiredRef.current = false;
244
+ setIsProcessing(false);
245
+ setSavePhase(null);
246
+ setFrozenCorners(null);
247
+ setCaptureError(t("id_check.photo.capture_failed", "La capture a échoué. Veuillez réessayer."));
248
+ });
249
+ };
250
+ var handleManualCapture = useCallback(function () {
251
+ captureRef.current("manual", trackedCorners);
252
+ }, [trackedCorners]);
253
+ var statusTone = guideFailed ? "neutral" : guideActive ? tone : "loading";
254
+ var statusMessage = guideFailed
255
+ ? t("card_capture.fallback", "Placez la carte dans le cadre puis appuyez sur le bouton")
256
+ : guideActive
257
+ ? t("card_capture_guide.".concat(shownCode), GUIDE_FALLBACK[shownCode])
258
+ : t("card_capture_guide.loading", "Chargement du guide…");
259
+ var sideLabel = captureSide === "verso" ? t("card_capture.side.verso", "Verso") : t("card_capture.side.recto", "Recto");
260
+ var shutterLabel = t("card_capture.shutter", "Prendre la photo");
261
+ return (jsxs("div", { className: "flex flex-col bg-black ".concat(isMobile ? "fixed inset-0 z-50" : "relative h-full w-full"), children: [jsx("div", { ref: boxRef, className: "relative flex-1 overflow-hidden bg-black", children: cameraError ? (jsx("div", { className: "flex h-full items-center justify-center px-4 py-6", children: jsx(CameraError, { errorMessage: cameraError, onRetry: function () { return setCameraAttempt(function (n) { return n + 1; }); } }) })) : (jsxs(Fragment, { children: [jsx("video", { ref: videoRef, autoPlay: true, playsInline: true, muted: true, className: "absolute inset-0 h-full w-full object-cover ".concat(facingMode === "user" ? "scale-x-[-1]" : "") }), jsx("canvas", { ref: frozenRef, "data-testid": "frozen-frame", hidden: !savePhase, "aria-hidden": "true", className: "absolute inset-0 h-full w-full object-cover ".concat(facingMode === "user" ? "scale-x-[-1]" : "") }), jsx(DynamicCardMask, { corners: savePhase ? frozenCorners : trackedCorners, videoWidth: (_g = (_f = videoRef.current) === null || _f === void 0 ? void 0 : _f.videoWidth) !== null && _g !== void 0 ? _g : 0, videoHeight: (_j = (_h = videoRef.current) === null || _h === void 0 ? void 0 : _h.videoHeight) !== null && _j !== void 0 ? _j : 0, mirrored: facingMode === "user", tone: savePhase ? "success" : tone }), jsxs("div", { className: "absolute inset-x-0 top-0 z-20 flex items-center justify-between px-4 pt-[max(env(safe-area-inset-top),16px)]", children: [jsx("span", { className: "rounded-full bg-black/60 px-3 py-1.5 text-sm font-medium text-white", children: sideLabel }), jsx("button", { type: "button", onClick: function () { return setFacingMode(function (m) { return (m === "environment" ? "user" : "environment"); }); }, "aria-label": t("card_capture.switch_camera", "Changer de caméra"), className: "flex h-11 w-11 cursor-pointer items-center justify-center rounded-full bg-black/60 text-white transition-transform active:scale-95 focus-visible:outline focus-visible:outline-2 focus-visible:outline-white", children: jsx(SwitchCamera, { className: "h-5 w-5", "aria-hidden": "true" }) })] }), savePhase ? null : (jsx("div", { className: "absolute inset-x-0 top-[calc(max(env(safe-area-inset-top),16px)+56px)] z-20 flex justify-center px-4", children: jsxs("p", { role: "status", "aria-live": "polite", "aria-atomic": "true", className: "flex max-w-md items-center gap-2 rounded-full px-4 py-2 text-sm font-medium shadow-sm transition-colors duration-200 ".concat(PILL_CLASS[statusTone]), children: [jsx(ToneIcon, { tone: statusTone }), jsx("span", { children: statusMessage })] }) })), lowResolution ? (jsx("div", { className: "absolute inset-x-4 bottom-36 z-20 rounded-xl bg-black/75 px-3 py-2 text-sm text-white", children: t("id_check.camera.low_resolution.title") })) : null, !cameraReady ? (jsxs("div", { className: "absolute inset-0 z-30 flex flex-col items-center justify-center gap-3 bg-black", children: [jsx(LoaderCircle, { className: "h-10 w-10 text-white motion-safe:animate-spin", "aria-hidden": "true" }), jsx("span", { className: "text-sm text-white", children: t("id_check.photo.initializing", "Ouverture de la caméra…") })] })) : null, savePhase ? (jsx("div", { "data-testid": "capture-processing", "aria-busy": savePhase === "saving", className: "absolute inset-0 z-30 flex items-center justify-center px-6", children: jsxs("div", { role: "status", "aria-live": "polite", className: "flex min-w-[220px] flex-col items-center gap-3 rounded-2xl bg-black/75 px-6 py-5 text-white shadow-lg", children: [savePhase === "saving" ? (jsx(LoaderCircle, { className: "h-9 w-9 motion-safe:animate-spin", "aria-hidden": "true" })) : (jsx("span", { className: "flex h-9 w-9 items-center justify-center rounded-full bg-[#11E5C5] text-black", children: jsx(Check, { className: "h-6 w-6", "aria-hidden": "true" }) })), jsx("span", { className: "text-base font-medium", children: savePhase === "saving"
262
+ ? t("card_capture.saving", "Enregistrement de la photo…")
263
+ : t("card_capture.saved", "Photo enregistrée") })] }) })) : null, showFlash ? jsx("div", { className: "pointer-events-none absolute inset-0 z-40 bg-white/70 motion-reduce:hidden" }) : null] })) }), jsxs("div", { className: "relative z-20 flex flex-col items-center gap-3 bg-black px-4 pb-[max(env(safe-area-inset-bottom),20px)] pt-4", children: [captureError ? (jsx("p", { role: "alert", className: "text-center text-sm text-red-300", children: captureError })) : showNudge ? (jsx("p", { className: "text-center text-sm text-white", children: t("card_capture.nudge", "Vous pouvez aussi prendre la photo vous-même") })) : null, jsxs("button", { type: "button", "data-testid": "shutter", "data-holding": holding ? "true" : "false", onClick: handleManualCapture, "aria-label": shutterLabel, className: "relative flex h-[76px] w-[76px] cursor-pointer items-center justify-center rounded-full transition-transform active:scale-95 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white", children: [jsxs("svg", { className: "absolute inset-0 h-full w-full -rotate-90", viewBox: "0 0 76 76", "aria-hidden": "true", children: [jsx("circle", { cx: "38", cy: "38", r: RING_RADIUS, fill: "none", stroke: "white", strokeOpacity: 0.9, strokeWidth: "3" }), holding ? (jsx("circle", { cx: "38", cy: "38", r: RING_RADIUS, fill: "none", stroke: "#11E5C5", strokeWidth: "5", strokeLinecap: "round", strokeDasharray: RING_LENGTH, strokeDashoffset: 0, children: jsx("animate", { attributeName: "stroke-dashoffset", from: RING_LENGTH, to: "0", dur: "".concat(holdMs, "ms"), fill: "freeze" }) }, "hold-".concat((_k = event === null || event === void 0 ? void 0 : event.timestamp) !== null && _k !== void 0 ? _k : 0))) : null] }), jsx("span", { className: "h-[58px] w-[58px] rounded-full bg-white" })] })] })] }));
264
+ };
265
+
266
+ export { CardCapture as default };
@@ -0,0 +1,81 @@
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import { useRef, useState, useEffect } from 'react';
3
+ import { idCardFrameRect, videoToViewport, rectToQuad, lerpQuad, quadPath } from './geometry.js';
4
+
5
+ var TONE_CLASS = {
6
+ neutral: "text-white",
7
+ warning: "text-amber-400",
8
+ progress: "text-[#11E5C5]",
9
+ success: "text-[#11E5C5]",
10
+ };
11
+ /** Share of the remaining distance covered per animation frame: smooths the ~8 model updates per second. */
12
+ var FOLLOW = 0.3;
13
+ var BRACKET = 22;
14
+ var prefersReducedMotion = function () {
15
+ return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
16
+ };
17
+ /**
18
+ * Darkened camera with a hole that follows the detected card (or the static ID-1 frame). The quad is animated
19
+ * in a requestAnimationFrame loop that writes the SVG paths directly: no React render per frame.
20
+ */
21
+ var DynamicCardMask = function (_a) {
22
+ var corners = _a.corners, videoWidth = _a.videoWidth, videoHeight = _a.videoHeight, mirrored = _a.mirrored, tone = _a.tone;
23
+ var rootRef = useRef(null);
24
+ var scrimRef = useRef(null);
25
+ var outlineRef = useRef(null);
26
+ var _b = useState({ width: 0, height: 0 }), box = _b[0], setBox = _b[1];
27
+ useEffect(function () {
28
+ var el = rootRef.current;
29
+ if (!el)
30
+ return;
31
+ var measure = function () { return setBox({ width: el.clientWidth, height: el.clientHeight }); };
32
+ measure();
33
+ if (typeof ResizeObserver === "undefined") {
34
+ window.addEventListener("resize", measure);
35
+ return function () { return window.removeEventListener("resize", measure); };
36
+ }
37
+ var observer = new ResizeObserver(measure);
38
+ observer.observe(el);
39
+ return function () { return observer.disconnect(); };
40
+ }, []);
41
+ var frame = idCardFrameRect(box.width, box.height);
42
+ var tracked = corners
43
+ ? videoToViewport(corners, { videoWidth: videoWidth, videoHeight: videoHeight, boxWidth: box.width, boxHeight: box.height, mirrored: mirrored })
44
+ : [];
45
+ var target = tracked.length === 4 ? tracked : rectToQuad(frame);
46
+ var targetRef = useRef(target);
47
+ targetRef.current = target;
48
+ var boxRef = useRef(box);
49
+ boxRef.current = box;
50
+ useEffect(function () {
51
+ if (!box.width || !box.height)
52
+ return;
53
+ var reduced = prefersReducedMotion();
54
+ var shown = targetRef.current;
55
+ var frameId = 0;
56
+ var draw = function () {
57
+ var _a, _b;
58
+ shown = reduced ? targetRef.current : lerpQuad(shown, targetRef.current, FOLLOW);
59
+ var _c = boxRef.current, width = _c.width, height = _c.height;
60
+ var hole = quadPath(shown);
61
+ (_a = scrimRef.current) === null || _a === void 0 ? void 0 : _a.setAttribute("d", "M0 0H".concat(width, "V").concat(height, "H0Z").concat(hole));
62
+ (_b = outlineRef.current) === null || _b === void 0 ? void 0 : _b.setAttribute("d", hole);
63
+ if (typeof requestAnimationFrame === "function")
64
+ frameId = requestAnimationFrame(draw);
65
+ };
66
+ draw();
67
+ return function () {
68
+ if (frameId && typeof cancelAnimationFrame === "function")
69
+ cancelAnimationFrame(frameId);
70
+ };
71
+ }, [box.width, box.height]);
72
+ // Mode follows the detection itself, not the projection (which needs a measured box).
73
+ var isTracking = !!corners && corners.length === 4;
74
+ var left = frame.left, top = frame.top, width = frame.width, height = frame.height;
75
+ var r = left + width;
76
+ var b = top + height;
77
+ var brackets = "M".concat(left, " ").concat(top + BRACKET, "V").concat(top, "H").concat(left + BRACKET, "M").concat(r - BRACKET, " ").concat(top, "H").concat(r, "V").concat(top + BRACKET, "M").concat(r, " ").concat(b - BRACKET, "V").concat(b, "H").concat(r - BRACKET, "M").concat(left + BRACKET, " ").concat(b, "H").concat(left, "V").concat(b - BRACKET);
78
+ return (jsx("div", { ref: rootRef, "data-testid": "card-mask", "data-mode": isTracking ? "tracking" : "frame", "data-tone": tone, "aria-hidden": "true", className: "pointer-events-none absolute inset-0 z-10 transition-colors duration-200 ".concat(TONE_CLASS[tone]), children: box.width > 0 && box.height > 0 ? (jsxs("svg", { className: "h-full w-full", viewBox: "0 0 ".concat(box.width, " ").concat(box.height), preserveAspectRatio: "none", children: [jsx("path", { ref: scrimRef, fill: "black", fillOpacity: 0.55, fillRule: "evenodd" }), jsx("path", { ref: outlineRef, fill: "none", stroke: "currentColor", strokeWidth: isTracking ? 3 : 1, strokeOpacity: isTracking ? 1 : 0.35, strokeLinejoin: "round" }), isTracking ? null : (jsx("path", { d: brackets, fill: "none", stroke: "currentColor", strokeWidth: 4, strokeLinecap: "round", strokeLinejoin: "round" }))] })) : null }));
79
+ };
80
+
81
+ export { DynamicCardMask as default };
@@ -0,0 +1,110 @@
1
+ /** Pure geometry of the dynamic capture screen: video frame <-> on-screen box (object-cover) and the crop. */
2
+ /** ID-1 card (CNI, residence permit, licence): 85.6 × 54 mm. */
3
+ var ID1_RATIO = 85.6 / 54;
4
+ var FRAME_WIDTH_SHARE = 0.88;
5
+ var FRAME_MAX_HEIGHT_SHARE = 0.6;
6
+ var MIN_CROP_PX = 16;
7
+ function coverTransform(_a) {
8
+ var videoWidth = _a.videoWidth, videoHeight = _a.videoHeight, boxWidth = _a.boxWidth, boxHeight = _a.boxHeight;
9
+ if (!videoWidth || !videoHeight || !boxWidth || !boxHeight)
10
+ return null;
11
+ var scale = Math.max(boxWidth / videoWidth, boxHeight / videoHeight);
12
+ var displayedWidth = videoWidth * scale;
13
+ var displayedHeight = videoHeight * scale;
14
+ return {
15
+ scale: scale,
16
+ displayedWidth: displayedWidth,
17
+ displayedHeight: displayedHeight,
18
+ offsetX: (boxWidth - displayedWidth) / 2,
19
+ offsetY: (boxHeight - displayedHeight) / 2,
20
+ };
21
+ }
22
+ /** Normalized points of the video frame -> pixels of the box showing it with `object-fit: cover`. */
23
+ function videoToViewport(points, layout) {
24
+ var t = coverTransform(layout);
25
+ if (!t)
26
+ return [];
27
+ return points.map(function (_a) {
28
+ var x = _a[0], y = _a[1];
29
+ var px = t.offsetX + x * t.displayedWidth;
30
+ return [layout.mirrored ? layout.boxWidth - px : px, t.offsetY + y * t.displayedHeight];
31
+ });
32
+ }
33
+ /** Box rectangle -> pixels of the raw video frame (crop of a manual capture without detection). */
34
+ function viewportRectToVideo(rect, layout) {
35
+ var t = coverTransform(layout);
36
+ if (!t)
37
+ return null;
38
+ var left = layout.mirrored ? layout.boxWidth - (rect.left + rect.width) : rect.left;
39
+ var x0 = Math.max(0, Math.round((left - t.offsetX) / t.scale));
40
+ var y0 = Math.max(0, Math.round((rect.top - t.offsetY) / t.scale));
41
+ var x1 = Math.min(layout.videoWidth, Math.round((left + rect.width - t.offsetX) / t.scale));
42
+ var y1 = Math.min(layout.videoHeight, Math.round((rect.top + rect.height - t.offsetY) / t.scale));
43
+ if (x1 - x0 < MIN_CROP_PX || y1 - y0 < MIN_CROP_PX)
44
+ return null;
45
+ return { x: x0, y: y0, width: x1 - x0, height: y1 - y0 };
46
+ }
47
+ /**
48
+ * Crop around the detected card in video pixels, with a margin proportional to the card so an edge is never cut
49
+ * by a slightly late corner estimate. Null for degenerate corners (the caller falls back to the static frame).
50
+ */
51
+ function cropRectFromCorners(corners, videoWidth, videoHeight, margin) {
52
+ if (margin === void 0) { margin = 0.06; }
53
+ if (corners.length !== 4 || !videoWidth || !videoHeight)
54
+ return null;
55
+ var minX = Infinity;
56
+ var minY = Infinity;
57
+ var maxX = -Infinity;
58
+ var maxY = -Infinity;
59
+ for (var _i = 0, corners_1 = corners; _i < corners_1.length; _i++) {
60
+ var _a = corners_1[_i], x = _a[0], y = _a[1];
61
+ minX = Math.min(minX, x * videoWidth);
62
+ maxX = Math.max(maxX, x * videoWidth);
63
+ minY = Math.min(minY, y * videoHeight);
64
+ maxY = Math.max(maxY, y * videoHeight);
65
+ }
66
+ var width = maxX - minX;
67
+ var height = maxY - minY;
68
+ if (width < MIN_CROP_PX || height < MIN_CROP_PX)
69
+ return null;
70
+ var m = margin * Math.max(width, height);
71
+ var x0 = Math.max(0, Math.floor(minX - m));
72
+ var y0 = Math.max(0, Math.floor(minY - m));
73
+ var x1 = Math.min(videoWidth, Math.ceil(maxX + m));
74
+ var y1 = Math.min(videoHeight, Math.ceil(maxY + m));
75
+ return { x: x0, y: y0, width: x1 - x0, height: y1 - y0 };
76
+ }
77
+ /** Static ID-1 frame centered in the box: 88 % of the width, at most 60 % of the height (landscape). */
78
+ function idCardFrameRect(boxWidth, boxHeight) {
79
+ var width = boxWidth * FRAME_WIDTH_SHARE;
80
+ var height = width / ID1_RATIO;
81
+ if (height > boxHeight * FRAME_MAX_HEIGHT_SHARE) {
82
+ height = boxHeight * FRAME_MAX_HEIGHT_SHARE;
83
+ width = height * ID1_RATIO;
84
+ }
85
+ return { left: (boxWidth - width) / 2, top: (boxHeight - height) / 2, width: width, height: height };
86
+ }
87
+ function rectToQuad(_a) {
88
+ var left = _a.left, top = _a.top, width = _a.width, height = _a.height;
89
+ return [[left, top], [left + width, top], [left + width, top + height], [left, top + height]];
90
+ }
91
+ function lerpQuad(from, to, t) {
92
+ return to.map(function (_a, i) {
93
+ var _b;
94
+ var x = _a[0], y = _a[1];
95
+ var _c = (_b = from[i]) !== null && _b !== void 0 ? _b : [x, y], fx = _c[0], fy = _c[1];
96
+ return [fx + (x - fx) * t, fy + (y - fy) * t];
97
+ });
98
+ }
99
+ var round1 = function (n) { return String(Number(n.toFixed(1))); };
100
+ /** Closed SVG path, one decimal (enough for pixels, smaller DOM updates). */
101
+ function quadPath(quad) {
102
+ if (quad.length === 0)
103
+ return "";
104
+ return "".concat(quad.map(function (_a, i) {
105
+ var x = _a[0], y = _a[1];
106
+ return "".concat(i === 0 ? "M" : "L").concat(round1(x), " ").concat(round1(y));
107
+ }).join(""), "Z");
108
+ }
109
+
110
+ export { ID1_RATIO, cropRectFromCorners, idCardFrameRect, lerpQuad, quadPath, rectToQuad, videoToViewport, viewportRectToVideo };
@@ -0,0 +1,13 @@
1
+ var TONES = {
2
+ no_card: "neutral",
3
+ card_detected: "neutral",
4
+ too_far: "warning",
5
+ too_dark: "warning",
6
+ too_blurry: "warning",
7
+ bright_spot: "warning",
8
+ hold_still: "progress",
9
+ ready: "success",
10
+ };
11
+ var guideTone = function (code) { return TONES[code]; };
12
+
13
+ export { guideTone };
@@ -8,6 +8,8 @@ import { Select } from '../ui/SelectComponent.js';
8
8
  import { useI18n } from '../../hooks/useI18n.js';
9
9
  import MobilePageLayout from '../ui/MobilePageLayout.js';
10
10
  import NfcOnboardingNotice from '../nfc-scan/NfcOnboardingNotice.js';
11
+ import { preloadCardGuideModel } from '../card-capture-guide/modelLoader.js';
12
+ import { useCardCaptureGuideConfig } from '../../context/CardCaptureGuideContext.js';
11
13
 
12
14
  var DOCUMENT_KEYS = [
13
15
  {
@@ -47,6 +49,13 @@ var JDIDocumentSelection = function (_a) {
47
49
  var _d = useState(""), error = _d[0], setError = _d[1];
48
50
  var _e = useState([]), documentOptions = _e[0], setDocumentOptions = _e[1];
49
51
  var t = useI18n().t;
52
+ // Start downloading the capture-guide model (13.5 MB) while the user picks the document.
53
+ var _f = useCardCaptureGuideConfig(), guideEnabled = _f.enabled, guideModelUrl = _f.modelUrl;
54
+ useEffect(function () {
55
+ if (guideEnabled === false)
56
+ return;
57
+ preloadCardGuideModel(guideModelUrl);
58
+ }, [guideEnabled, guideModelUrl]);
50
59
  // Récupérer les options de documents spécifiques à la session
51
60
  useEffect(function () {
52
61
  console.log("Retrieving document options for session:", sessionId);
@@ -6,7 +6,7 @@ import SelfieFlow from './selfie-flow/SelfieFlow.js';
6
6
  import VideoResetStyles from './VideoResetStyles.js';
7
7
 
8
8
  var Video = function (_a) {
9
- var setSelfieData = _a.setSelfieData, setStep = _a.setStep, sessionId = _a.sessionId, iad = _a.iad, btnBg = _a.btnBg, btnText = _a.btnText;
9
+ var setSelfieData = _a.setSelfieData, setStep = _a.setStep, sessionId = _a.sessionId, iad = _a.iad, btnBg = _a.btnBg, btnText = _a.btnText, onPreviewContinue = _a.onPreviewContinue;
10
10
  // Effet pour ajouter la classe au body lorsque le composant est monté
11
11
  useEffect(function () {
12
12
  // Empêcher le scroll sur le body lorsque la capture est active
@@ -28,7 +28,7 @@ var Video = function (_a) {
28
28
  setStep(1); // Move to the next step after selfie capture
29
29
  }, 300);
30
30
  };
31
- return (jsxs("div", { className: "w-full h-full overflow-hidden flex flex-col", children: [jsx(VideoResetStyles, {}), jsx(SelfieFlow, { handleSelfie: handleSelfie, sessionId: sessionId, iad: iad, btnBg: btnBg, btnText: btnText })] }));
31
+ return (jsxs("div", { className: "w-full h-full overflow-hidden flex flex-col", children: [jsx(VideoResetStyles, {}), jsx(SelfieFlow, { handleSelfie: handleSelfie, sessionId: sessionId, iad: iad, btnBg: btnBg, btnText: btnText, onPreviewContinue: onPreviewContinue })] }));
32
32
  };
33
33
 
34
34
  export { Video as default };
@@ -3,16 +3,18 @@ import { lazy, useState, Suspense } from 'react';
3
3
  import SelfiePreIntroduction from './SelfiePreIntroduction.js';
4
4
  import InstructionsSelfie from './InstructionsSelfie.js';
5
5
  import LoadingState from '../../states/LoadingState.js';
6
+ import { isPreviewMode } from '../../../preview/previewMode.js';
7
+ import PreviewCaptureDisabled from '../../../preview/PreviewCaptureDisabled.js';
6
8
 
7
9
  var SelfieRecorder = lazy(function () { return import('./SelfieRecorder.js'); });
8
10
  var SelfieFlow = function (_a) {
9
11
  var _b;
10
- var handleSelfie = _a.handleSelfie, sessionId = _a.sessionId, iad = _a.iad, btnBg = _a.btnBg, btnText = _a.btnText;
12
+ var handleSelfie = _a.handleSelfie, sessionId = _a.sessionId, iad = _a.iad, btnBg = _a.btnBg, btnText = _a.btnText, onPreviewContinue = _a.onPreviewContinue;
11
13
  var _c = useState(-1), internalStep = _c[0], setInternalStep = _c[1]; // Commencer à -1 pour la pré-introduction
12
14
  return (jsxs("div", { className: "h-full w-full flex flex-col", style: (_b = {},
13
15
  _b["--dk-btn-bg"] = btnBg !== null && btnBg !== void 0 ? btnBg : "#11E5C5",
14
16
  _b["--dk-btn-text"] = btnText !== null && btnText !== void 0 ? btnText : "#3C3C40",
15
- _b), children: [internalStep === -1 && (jsx("div", { className: "flex-1 flex flex-col h-full", children: jsx(SelfiePreIntroduction, { onContinue: function () { return setInternalStep(0); } }) })), internalStep === 0 && (jsx("div", { className: "flex-1 flex flex-col h-full", children: jsx(InstructionsSelfie, { setStep: setInternalStep, onBack: function () { return setInternalStep(-1); } }) })), internalStep === 1 && (jsx("div", { className: "flex-1 flex flex-col h-full overflow-hidden", children: jsx(Suspense, { fallback: jsx(LoadingState, {}), children: jsx(SelfieRecorder, { handleSelfie: handleSelfie, sessionId: sessionId, iad: iad, btnBg: btnBg, btnText: btnText }) }) }))] }));
17
+ _b), children: [internalStep === -1 && (jsx("div", { className: "flex-1 flex flex-col h-full", children: jsx(SelfiePreIntroduction, { onContinue: function () { return setInternalStep(0); } }) })), internalStep === 0 && (jsx("div", { className: "flex-1 flex flex-col h-full", children: jsx(InstructionsSelfie, { setStep: setInternalStep, onBack: function () { return setInternalStep(-1); } }) })), internalStep === 1 && isPreviewMode() && (jsx("div", { className: "flex-1 flex flex-col h-full", children: jsx(PreviewCaptureDisabled, { onContinue: onPreviewContinue }) })), internalStep === 1 && !isPreviewMode() && (jsx("div", { className: "flex-1 flex flex-col h-full overflow-hidden", children: jsx(Suspense, { fallback: jsx(LoadingState, {}), children: jsx(SelfieRecorder, { handleSelfie: handleSelfie, sessionId: sessionId, iad: iad, btnBg: btnBg, btnText: btnText }) }) }))] }));
16
18
  };
17
19
 
18
20
  export { SelfieFlow as default };
@@ -12,6 +12,9 @@ import JDIError from '../jdi/JDIError.js';
12
12
  import BeforePhoto from '../id-check/BeforePhoto.js';
13
13
  import BeforeVersoPhoto from '../id-check/BeforeVersoPhoto.js';
14
14
  import Photo from '../id-check/Photo.js';
15
+ import CardCapture from '../id-check/card-capture/CardCapture.js';
16
+ import { useCardCaptureGuideConfig } from '../../context/CardCaptureGuideContext.js';
17
+ import { useCaptureGuideThresholds } from '../card-capture-guide/useCaptureGuideThresholds.js';
15
18
  import PhotoConfirmation from '../id-check/PhotoConfirmation.js';
16
19
  import DocumentVideoCapture from '../document-video/DocumentVideoCapture.js';
17
20
  import { Camera, Upload } from 'lucide-react';
@@ -31,9 +34,13 @@ import { hasOutgoingEdgeForHandle, updateSessionUserInput, skipNfcWithReason } f
31
34
  import NfcScanStep from '../nfc-scan/NfcScanNode.js';
32
35
  import NfcChipGate from '../nfc-scan/NfcChipGate.js';
33
36
  import NfcFallbackSurvey from '../nfc-scan/NfcFallbackSurvey.js';
37
+ import { isPreviewMode } from '../../preview/previewMode.js';
38
+ import PreviewCaptureDisabled from '../../preview/PreviewCaptureDisabled.js';
34
39
  import { resolveControleJdiOutcomeRoute, normalizeMaxResubmissionAction, hasExceededResubmissionAttempts } from './controleJdiPolicy.js';
35
40
  import { EUROPEAN_COUNTRY_CODES } from '../../utils/europeanCountries.js';
36
41
 
42
+ /** Documents that are not ID-1 cards: the on-device capture guide stays off for them. */
43
+ var NON_CARD_DOCUMENT_TYPES = new Set(["passport", "pinkDriverLicense"]);
37
44
  var NFC_ELIGIBLE_DOCUMENT_TYPES = new Set([
38
45
  "passport",
39
46
  "idCard",
@@ -232,6 +239,18 @@ var DocumentCheck = function (_a) {
232
239
  var _5 = useState("before-recto"), currentPhotoStep = _5[0], setCurrentPhotoStep = _5[1];
233
240
  var _6 = useState("photo"), videoFlowPhase = _6[0], setVideoFlowPhase = _6[1];
234
241
  var _7 = useDocumentContext(), selectedDocumentType = _7.selectedDocumentType, setSelectedDocumentType = _7.setSelectedDocumentType;
242
+ // The on-device capture guide is trained on ID-1 cards only: not the passport or the old paper licence.
243
+ var isCardFormatDocument = !!(selectedDocumentType === null || selectedDocumentType === void 0 ? void 0 : selectedDocumentType.id) &&
244
+ !NON_CARD_DOCUMENT_TYPES.has(selectedDocumentType.id);
245
+ var cardGuideConfig = useCardCaptureGuideConfig();
246
+ // Read as soon as the node is shown, so the thresholds are there before the camera opens (APP3-2119).
247
+ var captureGuideThresholds = useCaptureGuideThresholds(cardGuideConfig.enabled === false ? undefined : sessionId);
248
+ // Card-format identity documents use the dynamic capture screen; the others keep Photo (APP3-2117).
249
+ var photoCardGuide = useMemo(function () {
250
+ return isCardFormatDocument && cardGuideConfig.enabled !== false
251
+ ? { modelUrl: cardGuideConfig.modelUrl, wasmPaths: cardGuideConfig.wasmPaths, tracker: captureGuideThresholds }
252
+ : false;
253
+ }, [isCardFormatDocument, cardGuideConfig.enabled, cardGuideConfig.modelUrl, cardGuideConfig.wasmPaths, captureGuideThresholds]);
235
254
  var finalAcceptedCountries = useMemo(function () {
236
255
  if (loadingTemplates)
237
256
  return acceptedCountries;
@@ -716,6 +735,17 @@ var DocumentCheck = function (_a) {
716
735
  setDocStep(function (prev) { return prev - 1; });
717
736
  }
718
737
  };
738
+ // APP3-2057 — aperçu du builder : ni caméra, ni upload, ni analyse, ni scan NFC. Les écrans
739
+ // d'introduction et de sélection restent les vrais ; la capture est remplacée par un écran neutre.
740
+ var renderPreviewCaptureDisabled = function () {
741
+ var previewTemplate = template;
742
+ return (jsx(PreviewCaptureDisabled, { onContinue: previewTemplate
743
+ ? function () { return stepObject.goToNextStep(node.id, previewTemplate); }
744
+ : undefined }));
745
+ };
746
+ if (isPreviewMode() && (docStep === 4 || docStep === 7)) {
747
+ return renderPreviewCaptureDisabled();
748
+ }
719
749
  switch (docStep) {
720
750
  case -1: {
721
751
  var hasIntroduction_1 = ((_f = node.introductionPage) === null || _f === void 0 ? void 0 : _f.title) !== undefined ||
@@ -758,6 +788,9 @@ var DocumentCheck = function (_a) {
758
788
  var activeMethod = selectedMethod ||
759
789
  (isPictureAllowed && isMobileCapture ? "picture" : "download");
760
790
  if (activeMethod === "picture" && isPictureAllowed) {
791
+ if (isPreviewMode() && currentPhotoStep !== "before-recto") {
792
+ return renderPreviewCaptureDisabled();
793
+ }
761
794
  var isSingleSided = (selectedDocumentType === null || selectedDocumentType === void 0 ? void 0 : selectedDocumentType.id) === "passport" ||
762
795
  (selectedDocumentType === null || selectedDocumentType === void 0 ? void 0 : selectedDocumentType.id) === "pinkDriverLicense";
763
796
  var onConfirm = node.withVideo
@@ -776,13 +809,13 @@ var DocumentCheck = function (_a) {
776
809
  return (jsx(BeforePhoto, { setStep: function () { return setCurrentPhotoStep("recto"); }, isSingleSided: isSingleSided, onBack: function () { return setDocStep(2); } }));
777
810
  }
778
811
  if (currentPhotoStep === "recto") {
779
- return (jsx(Photo, { sessionId: sessionId, nodeId: node.id, onCapture: function (imageData) { return handlePhotoCapture(imageData, "recto"); } }));
812
+ return (photoCardGuide ? (jsx(CardCapture, { sessionId: sessionId, nodeId: node.id, guide: photoCardGuide, captureSide: "recto", documentType: selectedDocumentType === null || selectedDocumentType === void 0 ? void 0 : selectedDocumentType.id, onCapture: function (imageData) { return handlePhotoCapture(imageData, "recto"); } }, "recto")) : (jsx(Photo, { sessionId: sessionId, nodeId: node.id, captureSide: "recto", documentType: selectedDocumentType === null || selectedDocumentType === void 0 ? void 0 : selectedDocumentType.id, onCapture: function (imageData) { return handlePhotoCapture(imageData, "recto"); } }, "recto")));
780
813
  }
781
814
  if (currentPhotoStep === "before-verso") {
782
815
  return (jsx(BeforeVersoPhoto, { setStep: function () { return setCurrentPhotoStep("verso"); } }));
783
816
  }
784
817
  if (currentPhotoStep === "verso") {
785
- return (jsx(Photo, { sessionId: sessionId, nodeId: node.id, onCapture: function (imageData) { return handlePhotoCapture(imageData, "verso"); } }));
818
+ return (photoCardGuide ? (jsx(CardCapture, { sessionId: sessionId, nodeId: node.id, guide: photoCardGuide, captureSide: "verso", documentType: selectedDocumentType === null || selectedDocumentType === void 0 ? void 0 : selectedDocumentType.id, onCapture: function (imageData) { return handlePhotoCapture(imageData, "verso"); } }, "verso")) : (jsx(Photo, { sessionId: sessionId, nodeId: node.id, captureSide: "verso", documentType: selectedDocumentType === null || selectedDocumentType === void 0 ? void 0 : selectedDocumentType.id, onCapture: function (imageData) { return handlePhotoCapture(imageData, "verso"); } }, "verso")));
786
819
  }
787
820
  if (currentPhotoStep === "confirmation") {
788
821
  return (jsx(PhotoConfirmation, { imageUrl: capturedImages.recto || "", versoImageUrl: capturedImages.verso, requiresTwoSides: !!capturedImages.verso, onConfirm: onConfirm, onRetry: function () { return setCurrentPhotoStep("before-recto"); }, onRetryAfterProcessing: function () { return setCurrentPhotoStep("before-recto"); }, fileUploaded: fileUploaded, isSingleSided: isSingleSided }));
@@ -790,6 +823,8 @@ var DocumentCheck = function (_a) {
790
823
  return (jsx(BeforePhoto, { setStep: function () { return setCurrentPhotoStep("recto"); }, isSingleSided: isSingleSided, onBack: function () { return setDocStep(2); } }));
791
824
  }
792
825
  else {
826
+ if (isPreviewMode())
827
+ return renderPreviewCaptureDisabled();
793
828
  return (jsx(JDIDocumentUpload, { title: (_p = node.documentUpload) === null || _p === void 0 ? void 0 : _p.title, description: (_q = node.documentUpload) === null || _q === void 0 ? void 0 : _q.description, documentType: (selectedDocumentType === null || selectedDocumentType === void 0 ? void 0 : selectedDocumentType.id) || documentTypeId, documentTypeId: documentTypeId, documentLabel: selectedDocumentType === null || selectedDocumentType === void 0 ? void 0 : selectedDocumentType.label, onUpload: handleDocumentUpload, onBack: function () {
794
829
  if (isPictureAllowed && isDownloadAllowed) {
795
830
  setSelectedMethod(null);