datakeen-session-react 1.1.202-dev.17 → 1.1.202-dev.19
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/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/session/DocumentCheck.js +19 -2
- package/dist/cjs/components/start-flow/Start.js +4 -0
- package/dist/cjs/context/CardCaptureGuideContext.js +16 -0
- package/dist/cjs/i18n/en.json.js +29 -0
- package/dist/cjs/i18n/es.json.js +29 -0
- package/dist/cjs/i18n/fr.json.js +29 -0
- package/dist/cjs/index.css.js +1 -1
- package/dist/cjs/index.js +13 -0
- package/dist/cjs/services/sessionService.js +43 -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/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/session/DocumentCheck.js +19 -2
- package/dist/esm/components/start-flow/Start.js +4 -0
- package/dist/esm/context/CardCaptureGuideContext.js +13 -0
- package/dist/esm/i18n/en.json.js +28 -1
- package/dist/esm/i18n/es.json.js +28 -1
- package/dist/esm/i18n/fr.json.js +28 -1
- package/dist/esm/index.css.js +1 -1
- package/dist/esm/index.js +5 -0
- package/dist/esm/services/sessionService.js +42 -1
- 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 +6 -0
- package/dist/types/types/camera.d.ts +3 -0
- package/dist/types/types/session.d.ts +15 -1
- package/package.json +2 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tslib_es6 = require('../../node_modules/tslib/tslib.es6.js');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var guideCore = require('./guideCore.js');
|
|
6
|
+
var guidance = require('./guidance.js');
|
|
7
|
+
var guideRuntime = require('./guideRuntime.js');
|
|
8
|
+
|
|
9
|
+
var INFERENCE_INTERVAL_MS = 120; // ~8 fps is plenty for guidance and keeps the CPU/battery cost low
|
|
10
|
+
/** Drives the card guide on a <video>: model load, throttled inference loop, temporal tracking, guidance events. */
|
|
11
|
+
function useCardCaptureGuide(videoRef, _a) {
|
|
12
|
+
var _this = this;
|
|
13
|
+
var _b = _a === void 0 ? {} : _a, modelUrl = _b.modelUrl, wasmPaths = _b.wasmPaths, _c = _b.active, active = _c === void 0 ? true : _c, _d = _b.enabled, enabled = _d === void 0 ? true : _d, tracker = _b.tracker, resolveMessage = _b.resolveMessage, onGuidance = _b.onGuidance, onFrame = _b.onFrame, onReady = _b.onReady, onTiming = _b.onTiming;
|
|
14
|
+
var _e = React.useState(false), modelReady = _e[0], setModelReady = _e[1];
|
|
15
|
+
var _f = React.useState(null), guide = _f[0], setGuide = _f[1];
|
|
16
|
+
var _g = React.useState(null), event = _g[0], setEvent = _g[1];
|
|
17
|
+
var _h = React.useState(null), error = _h[0], setError = _h[1];
|
|
18
|
+
var runtimeRef = React.useRef(null);
|
|
19
|
+
var trackerRef = React.useRef(null);
|
|
20
|
+
if (!trackerRef.current)
|
|
21
|
+
trackerRef.current = new guideCore.GuideTracker(tracker);
|
|
22
|
+
// Server thresholds may arrive after mount: rebuild the tracker (it only holds a few frames of state).
|
|
23
|
+
var trackerKey = JSON.stringify(tracker !== null && tracker !== void 0 ? tracker : {});
|
|
24
|
+
var appliedTrackerKey = React.useRef(trackerKey);
|
|
25
|
+
React.useEffect(function () {
|
|
26
|
+
if (appliedTrackerKey.current === trackerKey)
|
|
27
|
+
return;
|
|
28
|
+
appliedTrackerKey.current = trackerKey;
|
|
29
|
+
trackerRef.current = new guideCore.GuideTracker(tracker);
|
|
30
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- trackerKey is the content of `tracker`
|
|
31
|
+
}, [trackerKey]);
|
|
32
|
+
var lastCode = React.useRef(null);
|
|
33
|
+
var cb = React.useRef({ resolveMessage: resolveMessage, onGuidance: onGuidance, onFrame: onFrame, onReady: onReady, onTiming: onTiming });
|
|
34
|
+
cb.current = { resolveMessage: resolveMessage, onGuidance: onGuidance, onFrame: onFrame, onReady: onReady, onTiming: onTiming };
|
|
35
|
+
React.useEffect(function () {
|
|
36
|
+
if (!active)
|
|
37
|
+
return;
|
|
38
|
+
var cancelled = false;
|
|
39
|
+
var loadStartedAt = performance.now();
|
|
40
|
+
guideRuntime.createGuideRuntime({ modelUrl: modelUrl, wasmPaths: wasmPaths })
|
|
41
|
+
.then(function (rt) {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
if (cancelled) {
|
|
44
|
+
rt.dispose();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
runtimeRef.current = rt;
|
|
48
|
+
(_b = (_a = cb.current).onTiming) === null || _b === void 0 ? void 0 : _b.call(_a, { kind: "load", ms: performance.now() - loadStartedAt });
|
|
49
|
+
setModelReady(true);
|
|
50
|
+
})
|
|
51
|
+
.catch(function (e) {
|
|
52
|
+
if (!cancelled)
|
|
53
|
+
setError(e instanceof Error ? e.message : String(e));
|
|
54
|
+
});
|
|
55
|
+
return function () {
|
|
56
|
+
var _a;
|
|
57
|
+
cancelled = true;
|
|
58
|
+
(_a = runtimeRef.current) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
59
|
+
runtimeRef.current = null;
|
|
60
|
+
setModelReady(false);
|
|
61
|
+
};
|
|
62
|
+
}, [active, modelUrl, wasmPaths]);
|
|
63
|
+
React.useEffect(function () {
|
|
64
|
+
if (!modelReady || !enabled)
|
|
65
|
+
return;
|
|
66
|
+
var busy = false;
|
|
67
|
+
var timer = setInterval(function () { return tslib_es6.__awaiter(_this, void 0, void 0, function () {
|
|
68
|
+
var video, rt, runStartedAt, _a, decoded, quality, frameBrightness, now, g, code, message, ev, e_1;
|
|
69
|
+
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
70
|
+
return tslib_es6.__generator(this, function (_k) {
|
|
71
|
+
switch (_k.label) {
|
|
72
|
+
case 0:
|
|
73
|
+
video = videoRef.current;
|
|
74
|
+
rt = runtimeRef.current;
|
|
75
|
+
if (busy || !rt || !video || video.videoWidth === 0)
|
|
76
|
+
return [2 /*return*/];
|
|
77
|
+
busy = true;
|
|
78
|
+
_k.label = 1;
|
|
79
|
+
case 1:
|
|
80
|
+
_k.trys.push([1, 3, 4, 5]);
|
|
81
|
+
runStartedAt = performance.now();
|
|
82
|
+
return [4 /*yield*/, rt.run(video)];
|
|
83
|
+
case 2:
|
|
84
|
+
_a = _k.sent(), decoded = _a.decoded, quality = _a.quality, frameBrightness = _a.frameBrightness;
|
|
85
|
+
now = performance.now();
|
|
86
|
+
(_c = (_b = cb.current).onTiming) === null || _c === void 0 ? void 0 : _c.call(_b, { kind: "inference", ms: now - runStartedAt });
|
|
87
|
+
g = trackerRef.current.update(decoded, video.videoWidth, video.videoHeight, now, quality, frameBrightness);
|
|
88
|
+
code = g.state;
|
|
89
|
+
message = cb.current.resolveMessage ? cb.current.resolveMessage(code) : guideCore.MESSAGES[code];
|
|
90
|
+
ev = guidance.toGuidanceEvent(g, lastCode.current, message, now);
|
|
91
|
+
setGuide(g);
|
|
92
|
+
setEvent(ev);
|
|
93
|
+
(_e = (_d = cb.current).onFrame) === null || _e === void 0 ? void 0 : _e.call(_d, ev);
|
|
94
|
+
if (code !== lastCode.current) {
|
|
95
|
+
lastCode.current = code;
|
|
96
|
+
(_g = (_f = cb.current).onGuidance) === null || _g === void 0 ? void 0 : _g.call(_f, ev);
|
|
97
|
+
}
|
|
98
|
+
if (g.readyNow)
|
|
99
|
+
(_j = (_h = cb.current).onReady) === null || _j === void 0 ? void 0 : _j.call(_h, g);
|
|
100
|
+
return [3 /*break*/, 5];
|
|
101
|
+
case 3:
|
|
102
|
+
e_1 = _k.sent();
|
|
103
|
+
setError(e_1 instanceof Error ? e_1.message : String(e_1));
|
|
104
|
+
return [3 /*break*/, 5];
|
|
105
|
+
case 4:
|
|
106
|
+
busy = false;
|
|
107
|
+
return [7 /*endfinally*/];
|
|
108
|
+
case 5: return [2 /*return*/];
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}); }, INFERENCE_INTERVAL_MS);
|
|
112
|
+
return function () { return clearInterval(timer); };
|
|
113
|
+
}, [modelReady, enabled, videoRef]);
|
|
114
|
+
return { modelReady: modelReady, guide: guide, event: event, error: error };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
exports.useCardCaptureGuide = useCardCaptureGuide;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns `value`, but keeps each shown value on screen for at least `minMs` so guidance text does not flicker.
|
|
7
|
+
* A value superseded during the wait is skipped: only the latest one is shown once the wait is over.
|
|
8
|
+
*/
|
|
9
|
+
function useMinDisplay(value, minMs) {
|
|
10
|
+
var _a = React.useState(value), shown = _a[0], setShown = _a[1];
|
|
11
|
+
var shownSince = React.useRef(Date.now());
|
|
12
|
+
React.useEffect(function () {
|
|
13
|
+
if (Object.is(value, shown))
|
|
14
|
+
return;
|
|
15
|
+
var apply = function () {
|
|
16
|
+
shownSince.current = Date.now();
|
|
17
|
+
setShown(value);
|
|
18
|
+
};
|
|
19
|
+
var wait = minMs - (Date.now() - shownSince.current);
|
|
20
|
+
if (wait <= 0) {
|
|
21
|
+
apply();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
var timer = setTimeout(apply, wait);
|
|
25
|
+
return function () { return clearTimeout(timer); };
|
|
26
|
+
}, [value, shown, minMs]);
|
|
27
|
+
return shown;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.useMinDisplay = useMinDisplay;
|
|
@@ -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
|
|
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
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
var
|
|
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
|
|
38
|
-
var
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
//
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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
|
-
}
|
|
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
|
|
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:
|
|
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;
|