datakeen-session-react 1.1.202-dev.17 → 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 (60) 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/id-check/Photo.js +230 -122
  12. package/dist/cjs/components/id-check/card-capture/CardCapture.js +270 -0
  13. package/dist/cjs/components/id-check/card-capture/DynamicCardMask.js +85 -0
  14. package/dist/cjs/components/id-check/card-capture/geometry.js +119 -0
  15. package/dist/cjs/components/id-check/card-capture/guideTone.js +15 -0
  16. package/dist/cjs/components/jdi/JDIDocumentSelection.js +9 -0
  17. package/dist/cjs/components/session/DocumentCheck.js +19 -2
  18. package/dist/cjs/components/start-flow/Start.js +4 -0
  19. package/dist/cjs/context/CardCaptureGuideContext.js +16 -0
  20. package/dist/cjs/i18n/en.json.js +29 -0
  21. package/dist/cjs/i18n/es.json.js +29 -0
  22. package/dist/cjs/i18n/fr.json.js +29 -0
  23. package/dist/cjs/index.css.js +1 -1
  24. package/dist/cjs/index.js +13 -0
  25. package/dist/cjs/services/sessionService.js +43 -0
  26. package/dist/esm/components/DatakeenSession.js +17 -16
  27. package/dist/esm/components/card-capture-guide/CardCaptureGuide.js +135 -0
  28. package/dist/esm/components/card-capture-guide/captureTelemetry.js +78 -0
  29. package/dist/esm/components/card-capture-guide/guidance.js +44 -0
  30. package/dist/esm/components/card-capture-guide/guideCore.js +372 -0
  31. package/dist/esm/components/card-capture-guide/guideRuntime.js +115 -0
  32. package/dist/esm/components/card-capture-guide/modelLoader.js +42 -0
  33. package/dist/esm/components/card-capture-guide/useCaptureGuideThresholds.js +31 -0
  34. package/dist/esm/components/card-capture-guide/useCardCaptureGuide.js +115 -0
  35. package/dist/esm/components/card-capture-guide/useMinDisplay.js +28 -0
  36. package/dist/esm/components/id-check/Photo.js +232 -124
  37. package/dist/esm/components/id-check/card-capture/CardCapture.js +266 -0
  38. package/dist/esm/components/id-check/card-capture/DynamicCardMask.js +81 -0
  39. package/dist/esm/components/id-check/card-capture/geometry.js +110 -0
  40. package/dist/esm/components/id-check/card-capture/guideTone.js +13 -0
  41. package/dist/esm/components/jdi/JDIDocumentSelection.js +9 -0
  42. package/dist/esm/components/session/DocumentCheck.js +19 -2
  43. package/dist/esm/components/start-flow/Start.js +4 -0
  44. package/dist/esm/context/CardCaptureGuideContext.js +13 -0
  45. package/dist/esm/i18n/en.json.js +28 -1
  46. package/dist/esm/i18n/es.json.js +28 -1
  47. package/dist/esm/i18n/fr.json.js +28 -1
  48. package/dist/esm/index.css.js +1 -1
  49. package/dist/esm/index.js +5 -0
  50. package/dist/esm/services/sessionService.js +42 -1
  51. package/dist/types/components/card-capture-guide/CardCaptureGuide.d.ts +46 -0
  52. package/dist/types/components/card-capture-guide/guidance.d.ts +45 -0
  53. package/dist/types/components/card-capture-guide/guideCore.d.ts +96 -0
  54. package/dist/types/components/card-capture-guide/guideRuntime.d.ts +13 -0
  55. package/dist/types/components/card-capture-guide/modelLoader.d.ts +13 -0
  56. package/dist/types/components/card-capture-guide/useCardCaptureGuide.d.ts +38 -0
  57. package/dist/types/index.d.ts +6 -0
  58. package/dist/types/types/camera.d.ts +3 -0
  59. package/dist/types/types/session.d.ts +15 -1
  60. package/package.json +2 -1
@@ -14,6 +14,7 @@ var SessionAbandoned = require('./session/SessionAbandoned.js');
14
14
  var useRouteCSS = require('../hooks/useRouteCSS.js');
15
15
  var DocumentContext = require('../context/DocumentContext.js');
16
16
  var ConfigContext = require('../context/ConfigContext.js');
17
+ var CardCaptureGuideContext = require('../context/CardCaptureGuideContext.js');
17
18
  var SessionContext = require('../context/SessionContext.js');
18
19
  var useSessionData = require('../hooks/useSessionData.js');
19
20
  var useStepNavigation = require('../hooks/useStepNavigation.js');
@@ -231,22 +232,22 @@ var DatakeenSession = function (_a) {
231
232
  (currentTemplateNode === null || currentTemplateNode === void 0 ? void 0 : currentTemplateNode.type) === "controle-jdi";
232
233
  var btnBg = (_h = (_g = session === null || session === void 0 ? void 0 : session.template) === null || _g === void 0 ? void 0 : _g.buttonBgColor) !== null && _h !== void 0 ? _h : "#11E5C5";
233
234
  var btnText = (_k = (_j = session === null || session === void 0 ? void 0 : session.template) === null || _j === void 0 ? void 0 : _j.buttonTextColor) !== null && _k !== void 0 ? _k : "#3C3C40";
234
- return (jsxRuntime.jsx(ConfigContext.ConfigProvider, { apiBaseUrl: apiBaseUrl, children: jsxRuntime.jsx(DocumentContext.DocumentProvider, { children: jsxRuntime.jsx("div", { className: "sdk-session notranslate flex-1 flex flex-col", lang: currentLanguage, translate: "no", style: tslib_es6.__assign((_c = {}, _c["--dk-btn-bg"] = btnBg, _c["--dk-btn-text"] = btnText, _c), (isMobile
235
- ? (_d = {},
236
- _d["--dk-mobile-scroll-padding"] = mobileScrollPadding,
237
- _d) : undefined)), children: isMobile ? (jsxRuntime.jsxs("div", { className: "flex h-full w-full flex-col bg-white", style: mobileRootStyle, children: [jsxRuntime.jsx("div", { className: "flex flex-1 min-h-0 flex-col ".concat(isCaptureStep ? "" : "overflow-y-auto"), style: {
238
- paddingBottom: isCaptureStep
239
- ? "0"
240
- : "var(--dk-mobile-scroll-padding, env(safe-area-inset-bottom, 0px))",
241
- }, children: jsxRuntime.jsx("div", { className: "flex flex-1 flex-col min-h-0", children: renderSessionContent() }) }), showMobilePoweredBy && (jsxRuntime.jsx("div", { className: "bg-white px-4 pt-3 pb-4 sm:px-6 sm:pt-6 sm:pb-6", style: {
242
- paddingBottom: "calc(env(safe-area-inset-bottom, 0px) + 0.5rem)",
243
- }, ref: poweredByRef, children: jsxRuntime.jsx(PoweredBy.default, { logo: (_l = session === null || session === void 0 ? void 0 : session.template) === null || _l === void 0 ? void 0 : _l.logo, text: ((_m = session === null || session === void 0 ? void 0 : session.template) === null || _m === void 0 ? void 0 : _m.logo) ? "par" : undefined }) }))] })) : (jsxRuntime.jsx("div", { className: "flex items-center justify-center w-full min-h-screen bg-gray-100 py-12", children: jsxRuntime.jsxs("div", { className: "flex flex-col items-center justify-center", children: [jsxRuntime.jsx(Paper.default, { className: "dk-session-paper flex flex-col h-[800px] px-8 py-10 bg-white rounded-2xl shadow-xl z-10 ".concat(isRecordingSelfie
244
- ? ""
245
- : shouldUseWideDesktopLayout
246
- ? "w-[98vw] max-w-[1500px]"
247
- : "w-[600px]"), style: isRecordingSelfie
248
- ? { width: "min(66vw, 942px)" }
249
- : undefined, children: jsxRuntime.jsx("div", { className: "flex-1 w-full h-full overflow-y-auto", children: renderSessionContent() }) }), showDesktopPoweredBy && (jsxRuntime.jsx("div", { className: "pt-6 text-center", children: jsxRuntime.jsx(PoweredBy.default, { logo: (_o = session === null || session === void 0 ? void 0 : session.template) === null || _o === void 0 ? void 0 : _o.logo, text: ((_p = session === null || session === void 0 ? void 0 : session.template) === null || _p === void 0 ? void 0 : _p.logo) ? "par" : undefined }) }))] }) })) }) }) }));
235
+ return (jsxRuntime.jsx(ConfigContext.ConfigProvider, { apiBaseUrl: apiBaseUrl, children: jsxRuntime.jsx(CardCaptureGuideContext.CardCaptureGuideConfigProvider, { value: sessionConfig === null || sessionConfig === void 0 ? void 0 : sessionConfig.cardCaptureGuide, children: jsxRuntime.jsx(DocumentContext.DocumentProvider, { children: jsxRuntime.jsx("div", { className: "sdk-session notranslate flex-1 flex flex-col", lang: currentLanguage, translate: "no", style: tslib_es6.__assign((_c = {}, _c["--dk-btn-bg"] = btnBg, _c["--dk-btn-text"] = btnText, _c), (isMobile
236
+ ? (_d = {},
237
+ _d["--dk-mobile-scroll-padding"] = mobileScrollPadding,
238
+ _d) : undefined)), children: isMobile ? (jsxRuntime.jsxs("div", { className: "flex h-full w-full flex-col bg-white", style: mobileRootStyle, children: [jsxRuntime.jsx("div", { className: "flex flex-1 min-h-0 flex-col ".concat(isCaptureStep ? "" : "overflow-y-auto"), style: {
239
+ paddingBottom: isCaptureStep
240
+ ? "0"
241
+ : "var(--dk-mobile-scroll-padding, env(safe-area-inset-bottom, 0px))",
242
+ }, children: jsxRuntime.jsx("div", { className: "flex flex-1 flex-col min-h-0", children: renderSessionContent() }) }), showMobilePoweredBy && (jsxRuntime.jsx("div", { className: "bg-white px-4 pt-3 pb-4 sm:px-6 sm:pt-6 sm:pb-6", style: {
243
+ paddingBottom: "calc(env(safe-area-inset-bottom, 0px) + 0.5rem)",
244
+ }, ref: poweredByRef, children: jsxRuntime.jsx(PoweredBy.default, { logo: (_l = session === null || session === void 0 ? void 0 : session.template) === null || _l === void 0 ? void 0 : _l.logo, text: ((_m = session === null || session === void 0 ? void 0 : session.template) === null || _m === void 0 ? void 0 : _m.logo) ? "par" : undefined }) }))] })) : (jsxRuntime.jsx("div", { className: "flex items-center justify-center w-full min-h-screen bg-gray-100 py-12", children: jsxRuntime.jsxs("div", { className: "flex flex-col items-center justify-center", children: [jsxRuntime.jsx(Paper.default, { className: "dk-session-paper flex flex-col h-[800px] px-8 py-10 bg-white rounded-2xl shadow-xl z-10 ".concat(isRecordingSelfie
245
+ ? ""
246
+ : shouldUseWideDesktopLayout
247
+ ? "w-[98vw] max-w-[1500px]"
248
+ : "w-[600px]"), style: isRecordingSelfie
249
+ ? { width: "min(66vw, 942px)" }
250
+ : undefined, children: jsxRuntime.jsx("div", { className: "flex-1 w-full h-full overflow-y-auto", children: renderSessionContent() }) }), showDesktopPoweredBy && (jsxRuntime.jsx("div", { className: "pt-6 text-center", children: jsxRuntime.jsx(PoweredBy.default, { logo: (_o = session === null || session === void 0 ? void 0 : session.template) === null || _o === void 0 ? void 0 : _o.logo, text: ((_p = session === null || session === void 0 ? void 0 : session.template) === null || _p === void 0 ? void 0 : _p.logo) ? "par" : undefined }) }))] }) })) }) }) }) }));
250
251
  };
251
252
 
252
253
  exports.default = DatakeenSession;
@@ -0,0 +1,139 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var tslib_es6 = require('../../node_modules/tslib/tslib.es6.js');
6
+ var jsxRuntime = require('react/jsx-runtime');
7
+ var React = require('react');
8
+ var cameraService = require('../../services/cameraService.js');
9
+ var useI18n = require('../../hooks/useI18n.js');
10
+ var guideCore = require('./guideCore.js');
11
+ var useCardCaptureGuide = require('./useCardCaptureGuide.js');
12
+
13
+ var _a;
14
+ var COLORS = (_a = {},
15
+ _a[guideCore.State.CARD_DETECTED] = "#FFD400",
16
+ _a[guideCore.State.TOO_FAR] = "#FFD400",
17
+ _a[guideCore.State.HOLD_STILL] = "#7CFC00",
18
+ _a[guideCore.State.READY] = "#7CFC00",
19
+ _a[guideCore.State.TOO_BLURRY] = "#FF8A00",
20
+ _a[guideCore.State.TOO_DARK] = "#FF8A00",
21
+ _a[guideCore.State.BRIGHT_SPOT] = "#FF4D4D",
22
+ _a);
23
+ /**
24
+ * Live ID-card capture guide: camera preview + tracked card outline + guidance messages (move closer, hold still, blurry,
25
+ * reflection) and automatic capture once the card is steady, sharp and free of bright spots. Runs fully client-side.
26
+ */
27
+ var CardCaptureGuide = function (_a) {
28
+ var _b, _c;
29
+ var onCapture = _a.onCapture, _d = _a.autoCapture, autoCapture = _d === void 0 ? true : _d, _e = _a.facingMode, facingMode = _e === void 0 ? "environment" : _e, modelUrl = _a.modelUrl, wasmPaths = _a.wasmPaths, tracker = _a.tracker, onGuidance = _a.onGuidance, onFrame = _a.onFrame, messages = _a.messages, _f = _a.showMessage, showMessage = _f === void 0 ? true : _f, onError = _a.onError, className = _a.className;
30
+ var t = useI18n.useI18n().t;
31
+ var videoRef = React.useRef(null);
32
+ var canvasRef = React.useRef(null);
33
+ var _g = React.useState(false), cameraReady = _g[0], setCameraReady = _g[1];
34
+ var _h = React.useState(null), cameraError = _h[0], setCameraError = _h[1];
35
+ var _j = React.useState(false), captured = _j[0], setCaptured = _j[1];
36
+ var lastGuide = React.useRef(null);
37
+ var capturing = React.useRef(false);
38
+ var capture = React.useCallback(function (automatic) { return tslib_es6.__awaiter(void 0, void 0, void 0, function () {
39
+ var result, e_1, message_1;
40
+ var _a, _b, _c, _d;
41
+ return tslib_es6.__generator(this, function (_e) {
42
+ switch (_e.label) {
43
+ case 0:
44
+ if (capturing.current)
45
+ return [2 /*return*/];
46
+ capturing.current = true;
47
+ _e.label = 1;
48
+ case 1:
49
+ _e.trys.push([1, 3, , 4]);
50
+ return [4 /*yield*/, cameraService.cameraService.captureDocument(videoRef.current, null, { facingMode: facingMode, format: "jpeg", jpegQuality: 0.92 })];
51
+ case 2:
52
+ result = _e.sent();
53
+ setCaptured(true);
54
+ onCapture(result.dataUrl, { corners: (_b = (_a = lastGuide.current) === null || _a === void 0 ? void 0 : _a.corners) !== null && _b !== void 0 ? _b : null, quality: (_d = (_c = lastGuide.current) === null || _c === void 0 ? void 0 : _c.quality) !== null && _d !== void 0 ? _d : null, automatic: automatic });
55
+ return [3 /*break*/, 4];
56
+ case 3:
57
+ e_1 = _e.sent();
58
+ capturing.current = false;
59
+ message_1 = e_1 instanceof Error ? e_1.message : String(e_1);
60
+ setCameraError(message_1);
61
+ onError === null || onError === void 0 ? void 0 : onError(message_1);
62
+ return [3 /*break*/, 4];
63
+ case 4: return [2 /*return*/];
64
+ }
65
+ });
66
+ }); }, [facingMode, onCapture, onError]);
67
+ var _k = useCardCaptureGuide.useCardCaptureGuide(videoRef, {
68
+ modelUrl: modelUrl,
69
+ wasmPaths: wasmPaths,
70
+ tracker: tracker,
71
+ resolveMessage: function (code) { var _a; return (_a = messages === null || messages === void 0 ? void 0 : messages[code]) !== null && _a !== void 0 ? _a : t("card_capture_guide.".concat(code)); },
72
+ onGuidance: onGuidance,
73
+ onFrame: onFrame,
74
+ enabled: cameraReady && !captured,
75
+ onReady: function () {
76
+ if (autoCapture)
77
+ void capture(true);
78
+ },
79
+ }), modelReady = _k.modelReady, guide = _k.guide, event = _k.event, error = _k.error;
80
+ lastGuide.current = guide;
81
+ React.useEffect(function () {
82
+ var cancelled = false;
83
+ cameraService.cameraService
84
+ .startCamera(videoRef.current, { facingMode: facingMode, idealResolution: { width: 1920, height: 1080 }, preferImageCapture: true })
85
+ .then(function (r) {
86
+ var _a, _b;
87
+ if (cancelled)
88
+ return;
89
+ if (r.success)
90
+ setCameraReady(true);
91
+ else {
92
+ setCameraError((_a = r.error) !== null && _a !== void 0 ? _a : "camera");
93
+ onError === null || onError === void 0 ? void 0 : onError((_b = r.error) !== null && _b !== void 0 ? _b : "camera");
94
+ }
95
+ });
96
+ return function () {
97
+ cancelled = true;
98
+ cameraService.cameraService.stopCamera();
99
+ };
100
+ }, [facingMode]);
101
+ React.useEffect(function () {
102
+ if (error)
103
+ onError === null || onError === void 0 ? void 0 : onError(error);
104
+ }, [error]);
105
+ React.useEffect(function () {
106
+ var _a;
107
+ var canvas = canvasRef.current;
108
+ var video = videoRef.current;
109
+ if (!canvas || !video)
110
+ return;
111
+ canvas.width = video.clientWidth;
112
+ canvas.height = video.clientHeight;
113
+ var ctx = canvas.getContext("2d");
114
+ if (!ctx)
115
+ return;
116
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
117
+ if (!(guide === null || guide === void 0 ? void 0 : guide.corners) || captured)
118
+ return;
119
+ ctx.strokeStyle = (_a = COLORS[guide.state]) !== null && _a !== void 0 ? _a : "#FFD400";
120
+ ctx.lineWidth = 4;
121
+ ctx.beginPath();
122
+ guide.corners.forEach(function (_a, i) {
123
+ var x = _a[0], y = _a[1];
124
+ return (i === 0 ? ctx.moveTo(x * canvas.width, y * canvas.height) : ctx.lineTo(x * canvas.width, y * canvas.height));
125
+ });
126
+ ctx.closePath();
127
+ ctx.stroke();
128
+ }, [guide, captured]);
129
+ var message = cameraError
130
+ ? t("card_capture_guide.camera_error")
131
+ : error
132
+ ? t("card_capture_guide.model_error")
133
+ : !modelReady
134
+ ? t("card_capture_guide.loading")
135
+ : ((_c = (_b = event === null || event === void 0 ? void 0 : event.message) !== null && _b !== void 0 ? _b : messages === null || messages === void 0 ? void 0 : messages.no_card) !== null && _c !== void 0 ? _c : t("card_capture_guide.".concat(guideCore.State.NO_CARD)));
136
+ return (jsxRuntime.jsxs("div", { className: className, style: { position: "relative", width: "100%" }, "data-testid": "card-capture-guide", children: [jsxRuntime.jsx("video", { ref: videoRef, style: { width: "100%", display: "block" }, muted: true, playsInline: true, autoPlay: true }), jsxRuntime.jsx("canvas", { ref: canvasRef, style: { position: "absolute", top: 0, left: 0, width: "100%", height: "100%", pointerEvents: "none" } }), showMessage && (jsxRuntime.jsx("p", { role: "status", "aria-live": "polite", "data-testid": "card-capture-guide-message", style: { textAlign: "center", margin: "8px 0" }, children: message })), !autoCapture && (jsxRuntime.jsx("button", { type: "button", onClick: function () { return void capture(false); }, disabled: !cameraReady || captured, children: t("photo.capture", { defaultValue: "Capture" }) }))] }));
137
+ };
138
+
139
+ exports.default = CardCaptureGuide;
@@ -0,0 +1,81 @@
1
+ 'use strict';
2
+
3
+ var tslib_es6 = require('../../node_modules/tslib/tslib.es6.js');
4
+
5
+ /**
6
+ * Builds the per-capture telemetry of the card guide (APP3-2119): how long each guidance code was shown,
7
+ * time to capture, model and inference timings. It only ever receives codes and durations, so nothing else
8
+ * (image, corners, metrics) can end up in the payload.
9
+ */
10
+ var CaptureTelemetryCollector = /** @class */ (function () {
11
+ function CaptureTelemetryCollector(init) {
12
+ this.init = init;
13
+ this.order = [];
14
+ this.totals = new Map();
15
+ this.current = null;
16
+ this.inferenceTotalMs = 0;
17
+ this.inferenceCount = 0;
18
+ }
19
+ CaptureTelemetryCollector.prototype.guidance = function (code, at) {
20
+ this.close(at);
21
+ var entry = this.totals.get(code);
22
+ if (entry)
23
+ entry.count += 1;
24
+ else {
25
+ this.totals.set(code, { count: 1, totalMs: 0 });
26
+ this.order.push(code);
27
+ }
28
+ this.current = { code: code, since: at };
29
+ };
30
+ CaptureTelemetryCollector.prototype.modelLoaded = function (ms) {
31
+ this.modelLoadMs = Math.max(0, Math.round(ms));
32
+ };
33
+ CaptureTelemetryCollector.prototype.inference = function (ms) {
34
+ this.inferenceTotalMs += Math.max(0, ms);
35
+ this.inferenceCount += 1;
36
+ };
37
+ CaptureTelemetryCollector.prototype.build = function (_a) {
38
+ var _this = this;
39
+ var trigger = _a.trigger, guideStatus = _a.guideStatus, at = _a.at;
40
+ this.close(at);
41
+ var payload = {
42
+ nodeId: this.init.nodeId,
43
+ side: this.init.side,
44
+ trigger: trigger,
45
+ guideStatus: guideStatus,
46
+ timeToCaptureMs: Math.round(Math.abs(at - this.init.startedAt)),
47
+ inferenceCount: this.inferenceCount,
48
+ deviceType: this.init.deviceType,
49
+ guidance: this.order.map(function (code) { return (tslib_es6.__assign({ code: code }, _this.totals.get(code))); }),
50
+ };
51
+ if (this.init.documentType)
52
+ payload.documentType = this.init.documentType;
53
+ if (this.modelLoadMs !== undefined)
54
+ payload.modelLoadMs = this.modelLoadMs;
55
+ if (this.inferenceCount > 0)
56
+ payload.meanInferenceMs = Math.round(this.inferenceTotalMs / this.inferenceCount);
57
+ return payload;
58
+ };
59
+ CaptureTelemetryCollector.prototype.close = function (at) {
60
+ if (!this.current)
61
+ return;
62
+ var entry = this.totals.get(this.current.code);
63
+ entry.totalMs += Math.max(0, Math.round(at - this.current.since));
64
+ this.current = null;
65
+ };
66
+ return CaptureTelemetryCollector;
67
+ }());
68
+ /** Coarse device class from the user agent and the viewport; no fingerprinting detail is kept. */
69
+ function detectDeviceType() {
70
+ if (typeof navigator === "undefined")
71
+ return "desktop";
72
+ var ua = navigator.userAgent || "";
73
+ if (/iPad|Tablet/i.test(ua) || (/Macintosh/i.test(ua) && navigator.maxTouchPoints > 1))
74
+ return "tablet";
75
+ if (/Mobi|Android|iPhone/i.test(ua))
76
+ return "mobile";
77
+ return "desktop";
78
+ }
79
+
80
+ exports.CaptureTelemetryCollector = CaptureTelemetryCollector;
81
+ exports.detectDeviceType = detectDeviceType;
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * The guidance channel of CardCaptureGuide: one machine-readable CODE per situation, pushed in real time through
5
+ * `onGuidance` (on every change) and `onFrame` (every inference, ~8/s). Map the codes to your own UI/copy:
6
+ *
7
+ * too_blurry -> "Ajuster la focalisation" too_dark -> "Augmenter la luminosité" bright_spot -> "Éviter les reflets"
8
+ */
9
+ var GUIDANCE_CODES = [
10
+ "no_card", // nothing that looks like a card in view
11
+ "too_far", // card found but too small / too few camera pixels -> move closer
12
+ "too_dark", // not enough light (card or whole scene)
13
+ "card_detected", // card in view, still moving
14
+ "hold_still", // card steady, capture about to fire
15
+ "too_blurry", // card steady but out of focus
16
+ "bright_spot", // reflection / glare on the card
17
+ "ready", // steady + sharp + lit + no glare: the capture fires (once)
18
+ ];
19
+ /** "warning" = the user must change something; "info" = progress; "success" = capture. */
20
+ var GUIDANCE_SEVERITY = {
21
+ no_card: "info",
22
+ too_far: "warning",
23
+ too_dark: "warning",
24
+ card_detected: "info",
25
+ hold_still: "info",
26
+ too_blurry: "warning",
27
+ bright_spot: "warning",
28
+ ready: "success",
29
+ };
30
+ function toGuidanceEvent(g, previousCode, message, timestamp) {
31
+ var code = g.state;
32
+ var q = g.quality;
33
+ return {
34
+ code: code,
35
+ previousCode: previousCode,
36
+ severity: GUIDANCE_SEVERITY[code],
37
+ message: message,
38
+ presence: g.presence,
39
+ corners: g.corners,
40
+ metrics: q ? { blur: q.blur, brightness: q.brightness, glare: q.blob, cardSizePx: q.nativeLong } : null,
41
+ frameBrightness: g.frameBrightness,
42
+ timestamp: timestamp,
43
+ };
44
+ }
45
+
46
+ exports.GUIDANCE_CODES = GUIDANCE_CODES;
47
+ exports.GUIDANCE_SEVERITY = GUIDANCE_SEVERITY;
48
+ exports.toGuidanceEvent = toGuidanceEvent;