idmission-web-sdk 2.2.46 → 2.2.47

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 (65) hide show
  1. package/dist/components/CompositeWizard.d.ts +2 -1
  2. package/dist/components/CompositeWizard.d.ts.map +1 -1
  3. package/dist/components/camera/CameraAccessDeniedOverlay.d.ts.map +1 -1
  4. package/dist/components/camera/CameraProvider.d.ts +17 -0
  5. package/dist/components/camera/CameraProvider.d.ts.map +1 -0
  6. package/dist/components/camera/CameraVideoTag.d.ts +4 -2
  7. package/dist/components/camera/CameraVideoTag.d.ts.map +1 -1
  8. package/dist/components/camera/MicrophoneAccessDeniedOverlay.d.ts.map +1 -1
  9. package/dist/components/customer_flows/CustomerBiometricsEnrollment.d.ts.map +1 -1
  10. package/dist/components/customer_flows/CustomerIdAndBiometricsEnrollment.d.ts.map +1 -1
  11. package/dist/components/customer_flows/CustomerIdentification.d.ts.map +1 -1
  12. package/dist/components/customer_flows/CustomerVerification.d.ts.map +1 -1
  13. package/dist/components/customer_flows/DocumentCapture.d.ts.map +1 -1
  14. package/dist/components/customer_flows/FaceValidation.d.ts.map +1 -1
  15. package/dist/components/customer_flows/IdAndFaceValidation.d.ts.map +1 -1
  16. package/dist/components/customer_flows/IdValidation.d.ts.map +1 -1
  17. package/dist/components/customer_flows/VideoIdValidation.d.ts.map +1 -1
  18. package/dist/components/customer_identification/CustomerIdentificationWizard.d.ts +1 -1
  19. package/dist/components/customer_identification/CustomerIdentificationWizard.d.ts.map +1 -1
  20. package/dist/components/customer_verification/CustomerVerificationWizard.d.ts.map +1 -1
  21. package/dist/components/document_capture/DocumentCaptureScreen.d.ts.map +1 -1
  22. package/dist/components/document_capture/DocumentCaptureStateProvider.d.ts.map +1 -1
  23. package/dist/components/face_liveness/FaceLivenessWizard.d.ts.map +1 -1
  24. package/dist/components/id_capture/DocumentDetectionModelProvider.d.ts.map +1 -1
  25. package/dist/components/id_capture/FocusModelProvider.d.ts.map +1 -1
  26. package/dist/components/id_capture/IdCapture.d.ts.map +1 -1
  27. package/dist/components/id_capture/IdCaptureGuides.d.ts.map +1 -1
  28. package/dist/components/id_capture/IdCaptureLoadingOverlayDefault.d.ts.map +1 -1
  29. package/dist/components/id_capture/IdCaptureLoadingOverlayLegacy.d.ts.map +1 -1
  30. package/dist/components/id_capture/IdCaptureWizard.d.ts.map +1 -1
  31. package/dist/components/selfie_capture/SelfieCapture.d.ts.map +1 -1
  32. package/dist/components/selfie_capture/SelfieCaptureLoadingOverlayDefault.d.ts.map +1 -1
  33. package/dist/components/selfie_capture/SelfieCaptureLoadingOverlayLegacy.d.ts.map +1 -1
  34. package/dist/components/selfie_capture/SelfieGuidanceModelsProvider.d.ts.map +1 -1
  35. package/dist/components/submission/SubmissionProvider.d.ts.map +1 -1
  36. package/dist/components/video_id/IdVideoCapture.d.ts.map +1 -1
  37. package/dist/components/video_id/IdVideoCaptureFlipIdPrompt.d.ts.map +1 -1
  38. package/dist/components/video_id/IdVideoCaptureGuides.d.ts.map +1 -1
  39. package/dist/components/video_id/IdVideoCaptureWizard.d.ts.map +1 -1
  40. package/dist/components/video_signature_capture/VideoSignatureCapture.d.ts.map +1 -1
  41. package/dist/components/video_signature_capture/VideoSignatureWizard.d.ts.map +1 -1
  42. package/dist/lib/camera/Camera.d.ts +0 -4
  43. package/dist/lib/camera/Camera.d.ts.map +1 -1
  44. package/dist/lib/models/DocumentDetection.d.ts +1 -3
  45. package/dist/lib/models/DocumentDetection.d.ts.map +1 -1
  46. package/dist/lib/models/FaceDetection.d.ts +1 -3
  47. package/dist/lib/models/FaceDetection.d.ts.map +1 -1
  48. package/dist/lib/models/Focus.d.ts +1 -3
  49. package/dist/lib/models/Focus.d.ts.map +1 -1
  50. package/dist/sdk2.cjs.development.js +1301 -1242
  51. package/dist/sdk2.cjs.development.js.map +1 -1
  52. package/dist/sdk2.cjs.production.js +1 -1
  53. package/dist/sdk2.cjs.production.js.map +1 -1
  54. package/dist/sdk2.esm.js +1301 -1242
  55. package/dist/sdk2.esm.js.map +1 -1
  56. package/dist/sdk2.umd.development.js +1244 -1302
  57. package/dist/sdk2.umd.development.js.map +1 -1
  58. package/dist/sdk2.umd.production.js +1 -1
  59. package/dist/sdk2.umd.production.js.map +1 -1
  60. package/dist/version.d.ts +1 -1
  61. package/package.json +2 -3
  62. package/dist/lib/camera/cameraStore.d.ts +0 -52
  63. package/dist/lib/camera/cameraStore.d.ts.map +0 -1
  64. package/dist/lib/camera/videoRefStack.d.ts +0 -6
  65. package/dist/lib/camera/videoRefStack.d.ts.map +0 -1
package/dist/sdk2.esm.js CHANGED
@@ -8,12 +8,10 @@ import { Upload } from 'tus-js-client';
8
8
  import SparkMD5 from 'spark-md5';
9
9
  import useResizeObserver from 'use-resize-observer';
10
10
  import { ImageSegmenter, FilesetResolver, ImageClassifier, FaceDetector, ObjectDetector } from '@mediapipe/tasks-vision';
11
- import { createStore, useStore } from 'zustand';
12
11
  import { useDebouncedCallback, useThrottledCallback } from 'use-debounce';
13
12
  import { createPortal } from 'react-dom';
14
13
  import LanguageDetector from 'i18next-browser-languagedetector';
15
14
  import i18n from 'i18next';
16
- import { useShallow } from 'zustand/react/shallow';
17
15
  import SignatureCanvas from 'react-signature-canvas';
18
16
 
19
17
  /******************************************************************************
@@ -203,7 +201,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
203
201
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
204
202
  };
205
203
 
206
- var webSdkVersion = '2.2.46';
204
+ var webSdkVersion = '2.2.47';
207
205
 
208
206
  function getPlatform() {
209
207
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -772,11 +770,11 @@ function setDefaultAuthUrl(url) {
772
770
  if (!allowedAuthUrls.includes(url)) throw new Error('invalid auth url');
773
771
  defaultAuthUrl = url;
774
772
  }
775
- var initialState$6 = {
773
+ var initialState$5 = {
776
774
  authUrl: defaultAuthUrl,
777
775
  sessionCheckState: 'READY'
778
776
  };
779
- var AuthStateContext = /*#__PURE__*/createContext(initialState$6);
777
+ var AuthStateContext = /*#__PURE__*/createContext(initialState$5);
780
778
  var AuthDispatchContext = /*#__PURE__*/createContext(function () {});
781
779
  var reducer$4 = function reducer(state, action) {
782
780
  switch (action.type) {
@@ -808,7 +806,7 @@ function useAuthReducer(authUrl, sessionId) {
808
806
  if (authUrl === void 0) {
809
807
  authUrl = defaultAuthUrl;
810
808
  }
811
- var _a = useReducer(reducer$4, _assign(_assign({}, initialState$6), {
809
+ var _a = useReducer(reducer$4, _assign(_assign({}, initialState$5), {
812
810
  authUrl: authUrl
813
811
  })),
814
812
  state = _a[0],
@@ -1321,7 +1319,8 @@ var SubmissionProvider = function SubmissionProvider(_a) {
1321
1319
  }
1322
1320
  };
1323
1321
  _e = {
1324
- filetype: blob.type
1322
+ filetype: blob.type,
1323
+ contentType: blob.type
1325
1324
  };
1326
1325
  return [4 /*yield*/, calculateMd5(blob)];
1327
1326
  case 3:
@@ -1888,48 +1887,6 @@ function calculateMd5(blob) {
1888
1887
  });
1889
1888
  }
1890
1889
 
1891
- var visionTasksBasePath = "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.7/wasm";
1892
- var visionRuntimePreloading = false;
1893
- function preloadVisionRuntime() {
1894
- return __awaiter(this, void 0, void 0, function () {
1895
- function handleDownloadProgress(event) {
1896
- var detail = event.detail;
1897
- if (detail.url !== url) return;
1898
- progressByUseCase.visionRuntime = sumUpProgressForDependencies([url]);
1899
- document.dispatchEvent(new CustomEvent('idmission.preloadProgress.visionRuntime', {
1900
- detail: progressByUseCase.visionRuntime
1901
- }));
1902
- }
1903
- var url;
1904
- return __generator(this, function (_a) {
1905
- switch (_a.label) {
1906
- case 0:
1907
- if (visionRuntimePreloading) return [2 /*return*/, new Promise(function (resolve) {
1908
- setInterval(function () {
1909
- if (!visionRuntimePreloading) resolve();
1910
- }, 100);
1911
- })];
1912
- visionRuntimePreloading = true;
1913
- url = "".concat(visionTasksBasePath, "/vision_wasm_internal.wasm");
1914
- document.addEventListener('idmission.preloadProgress', handleDownloadProgress);
1915
- _a.label = 1;
1916
- case 1:
1917
- _a.trys.push([1,, 3, 4]);
1918
- return [4 /*yield*/, preloadDependency(url)];
1919
- case 2:
1920
- _a.sent();
1921
- return [3 /*break*/, 4];
1922
- case 3:
1923
- document.removeEventListener('idmission.preloadProgress', handleDownloadProgress);
1924
- visionRuntimePreloading = false;
1925
- return [7 /*endfinally*/];
1926
- case 4:
1927
- return [2 /*return*/];
1928
- }
1929
- });
1930
- });
1931
- }
1932
-
1933
1890
  function getFrameDimensions(frame) {
1934
1891
  var frameWidth = frame.width,
1935
1892
  frameHeight = frame.height;
@@ -1966,219 +1923,827 @@ function clearCanvas(canvas) {
1966
1923
  }
1967
1924
  var templateObject_1$G;
1968
1925
 
1969
- function cropToShoulders(rawCanvas, cropCanvas, resizeCanvas, frame, face, quality, maxHeight) {
1970
- if (quality === void 0) {
1971
- quality = 0.92;
1972
- }
1973
- if (!rawCanvas || !cropCanvas || !resizeCanvas) return '';
1974
- var rawCtx = rawCanvas.getContext('2d');
1975
- var cropCtx = cropCanvas.getContext('2d');
1976
- var resizeCtx = resizeCanvas.getContext('2d');
1977
- if (!rawCtx || !cropCtx || !resizeCtx) throw new Error('could not get 2d context');
1978
- rawCanvas.width = frame.width;
1979
- rawCanvas.height = frame.height;
1980
- rawCtx.putImageData(frame, 0, 0);
1981
- if (frame.height > frame.width) {
1982
- cropCanvas.width = frame.width;
1983
- cropCanvas.height = frame.height;
1984
- cropCtx.drawImage(rawCanvas, 0, 0, cropCanvas.width, cropCanvas.height);
1985
- } else {
1986
- var _a = face.box,
1987
- xMin = _a.xMin,
1988
- width = _a.width;
1989
- var desiredWidth = frame.height * 0.6;
1990
- var faceCenterX = xMin + width / 2;
1991
- var xPos = Math.max(0, faceCenterX - desiredWidth / 2);
1992
- cropCanvas.width = desiredWidth;
1993
- cropCanvas.height = frame.height;
1994
- cropCtx.drawImage(rawCanvas, xPos, 0, cropCanvas.width, cropCanvas.height, 0, 0, cropCanvas.width, cropCanvas.height);
1995
- }
1996
- resizeCanvas.height = maxHeight !== null && maxHeight !== void 0 ? maxHeight : cropCanvas.height;
1997
- resizeCanvas.width = cropCanvas.width * (resizeCanvas.height / cropCanvas.height);
1998
- resizeCtx === null || resizeCtx === void 0 ? void 0 : resizeCtx.drawImage(cropCanvas, 0, 0, resizeCanvas.width, resizeCanvas.height);
1999
- var dataURL = resizeCanvas.toDataURL('image/jpeg', quality);
2000
- log('cropToShoulders size', new TextEncoder().encode(dataURL).length);
2001
- clearCanvas(rawCanvas);
2002
- clearCanvas(cropCanvas);
2003
- clearCanvas(resizeCanvas);
2004
- return dataURL;
2005
- }
2006
- function cropToDetectedObjectBox(frame, box, canvas) {
2007
- canvas || (canvas = document.createElement('canvas'));
2008
- var ctx = canvas.getContext('2d');
2009
- if (!ctx) throw new Error('could not get 2d context');
2010
- var xMin = box.xMin,
2011
- yMin = box.yMin,
2012
- width = box.width,
2013
- height = box.height;
2014
- canvas.width = width;
2015
- canvas.height = height;
2016
- ctx.drawImage(frame, xMin, yMin, width, height, 0, 0, width, height);
2017
- return canvas;
2018
- }
2019
-
2020
- var defaultImageSegmenterModelPath = 'https://websdk-cdn-dev.idmission.com/assets/models/selfiesegmenter20240524/selfie_segmenter.tflite';
2021
- var imageSegmenterModelSizeInBytes = 256440.32;
2022
- // The idea here is that we globally set a cache key based on the time at page load. That way our built-in speed test
2023
- // isn't fooled by cache times, but subsequent downloads of the vision runtime still do load from the cache.
2024
- var tinyModelCacheKey = new Date().getTime();
2025
- var initialModelCapabilities = {
2026
- probeState: 'notProbed',
2027
- delegate: 'GPU',
2028
- networkTier: 'untested',
2029
- networkSpeed: 0,
2030
- networkTestTime: 0
2031
- };
2032
- var modelCapabilities = _assign({}, initialModelCapabilities);
2033
- function probeModelCapabilities() {
2034
- return __awaiter(this, void 0, void 0, function () {
2035
- var error_1, error_2;
1926
+ function listAvailableCameras(facingMode_1) {
1927
+ return __awaiter(this, arguments, void 0, function (facingMode, requestMicAccess) {
1928
+ var cameraEnumerationStream, videoDevices;
1929
+ if (requestMicAccess === void 0) {
1930
+ requestMicAccess = false;
1931
+ }
2036
1932
  return __generator(this, function (_a) {
2037
1933
  switch (_a.label) {
2038
1934
  case 0:
2039
- if (modelCapabilities.probeState === 'probed') return [2 /*return*/];
2040
- if (modelCapabilities.probeState === 'probing') return [2 /*return*/, new Promise(function (resolve) {
2041
- setInterval(function () {
2042
- if (modelCapabilities.probeState === 'probed') resolve();
2043
- }, 100);
2044
- })];
2045
- modelCapabilities.probeState = 'probing';
2046
- return [4 /*yield*/, preloadVisionRuntime()];
1935
+ return [4 /*yield*/, navigator.mediaDevices.getUserMedia({
1936
+ video: {
1937
+ facingMode: {
1938
+ exact: facingMode
1939
+ }
1940
+ },
1941
+ audio: requestMicAccess
1942
+ })
1943
+ // This lists all available cameras attached to the user's device.
1944
+ ];
2047
1945
  case 1:
2048
- _a.sent();
2049
- _a.label = 2;
1946
+ cameraEnumerationStream = _a.sent();
1947
+ return [4 /*yield*/, navigator.mediaDevices.enumerateDevices()];
2050
1948
  case 2:
2051
- _a.trys.push([2, 4, 9, 10]);
2052
- log('Model Probing: testing GPU capabilities...');
2053
- return [4 /*yield*/, loadTinyModel('GPU')];
2054
- case 3:
2055
- _a.sent();
2056
- log('Model Probing: GPU is capable.');
2057
- return [3 /*break*/, 10];
2058
- case 4:
2059
- error_1 = _a.sent();
2060
- warn('Model Probing: GPU delegate could not be loaded', error_1);
2061
- modelCapabilities.delegate = 'CPU';
2062
- _a.label = 5;
2063
- case 5:
2064
- _a.trys.push([5, 7,, 8]);
2065
- log('Model Probing: testing CPU capabilities...');
2066
- return [4 /*yield*/, loadTinyModel('CPU')];
2067
- case 6:
2068
- _a.sent();
2069
- log('Model Probing: CPU is capable.');
2070
- return [3 /*break*/, 8];
2071
- case 7:
2072
- error_2 = _a.sent();
2073
- warn('Model Probing: CPU delegate could not be loaded', error_2);
2074
- modelCapabilities.delegate = 'NONE';
2075
- return [3 /*break*/, 8];
2076
- case 8:
2077
- return [3 /*break*/, 10];
2078
- case 9:
2079
- modelCapabilities.probeState = 'probed';
2080
- return [7 /*endfinally*/];
2081
- case 10:
2082
- return [2 /*return*/];
1949
+ videoDevices = _a.sent().filter(function (_a) {
1950
+ var kind = _a.kind;
1951
+ return kind === 'videoinput';
1952
+ });
1953
+ // Release the access to the user's camera that we obtained for enumeration purposes.
1954
+ cameraEnumerationStream.getVideoTracks().forEach(function (track) {
1955
+ track.enabled = false;
1956
+ track.stop();
1957
+ });
1958
+ cameraEnumerationStream = null;
1959
+ return [2 /*return*/, videoDevices];
2083
1960
  }
2084
1961
  });
2085
1962
  });
2086
1963
  }
2087
- function loadTinyModel() {
2088
- return __awaiter(this, arguments, void 0, function (delegate, maxTime) {
2089
- var modelAssetPath, startedAt, e_1, time, speedMbps, model, _a, _b, emptyFrame;
2090
- if (delegate === void 0) {
2091
- delegate = 'GPU';
1964
+ var frontLabels = ['front', 'avant', 'anteriore', 'cameraaanvoorzijde', 'kamerapåframsidan', 'forsidekamera', 'kamerapåforsiden', 'aparatprzedni', 'etukamera', 'kameradepan', 'ÖnKamera', 'cameramặttrước', 'camerăfață', 'prednákamera', 'prednjakamera', 'előlapikamera', 'přednífotoaparát', 'μπροστινήκάμερα', 'переднякамера', 'передняякамера', 'преднакамера', 'алдыңғыкамера', 'מצלמה קדמית', 'الكاميرا الأمامية', 'फ़्रंटकैमरा', '前置相机', '前置鏡頭', '前面カメラ', '전면카메라', 'กล้องด้านหน้า'].map(function (s) {
1965
+ return s.toLocaleLowerCase().split(' ').join('');
1966
+ });
1967
+ var rearLabels = ['back', 'rear', 'posterior', 'trasera', 'traseira', 'arrière', 'rückkamera', 'fotocamera(posteriore)', 'cameraaanachterzijde', 'kamerapåbaksidan', 'kamerapåbaksiden', 'bagsidekamera', 'aparattylny', 'takakamera', 'arkakamera', 'kamerabelakang', 'cameramặtsau', 'camerăspate', 'stražnjakamera', 'zadnákamera', 'hátoldalikamera', 'zadnífotoaparát', 'πίσωκάμερα', 'заднякамера', 'Задняякамера', 'заднакамера', 'артқыкамера', 'מצלמה אחורית', 'الكاميرا الخلفية', 'बैककैमरा', '后置相机', '後置鏡頭', '背面カメラ', '후면카메라', 'กล้องด้านหลัง'].map(function (s) {
1968
+ return s.toLocaleLowerCase().split(' ').join('');
1969
+ });
1970
+ var backUltraWideLabels = ['backdualwidecamera', 'backultrawidecamera', 'ultraampliaposterior', 'ultra-angulartraseira', 'ultragrandeangulartraseira', 'ultragrandangle', 'ultragranangular', 'ultra-weitwinkelkamera', 'ultra-grandangolo', 'ultrabredecameraaanachterzijde', 'ultravidvinkelkamerapåbaksidan', 'ultravidvinkelkameraetpåbagsiden', 'ultravidvinkelkamerabak', 'ultragenişkameraarkayüzü', 'ultralaajakulmainentakakamera', 'tylnyaparatultraszerokokątny', 'cameracựcrộngmặtsau', 'camerăcuobiectivultra‑superangularspate', 'ultraszéleslátószögűkamera', 'kameraultralebarbelakang', 'stražnjaultraširokakamera', 'zadníultraširokoúhlýfotoaparát', 'ultraširokouhlá', 'πίσωυπερευρείακάμερα', 'заднянадширококутнакамера', 'Задняясверхширокоугольнаякамера', 'Задна свръх широкоъгълна камера', 'артқыультракеңбұрыштыкамера', 'מצלמה אולטרה רחבה אחורית', 'كاميرا خلفية عريضة جدًا', 'बैकअल्ट्रावाइडकैमरा', '后置超广角相机', '後置超廣角鏡頭相機', '背面超広角カメラ', '후면울트라와이드카메라', 'กล้องด้านหลังอัลตร้าไวด์'].map(function (s) {
1971
+ return s.toLocaleLowerCase().split(' ').join('');
1972
+ });
1973
+ var labelMatches = function labelMatches(labelOrDevice, labelSetOrLabel) {
1974
+ var label = labelOrDevice instanceof MediaDeviceInfo ? getDeviceLabel(labelOrDevice) : labelOrDevice;
1975
+ var labelSet = typeof labelSetOrLabel === 'string' ? [labelSetOrLabel] : labelSetOrLabel;
1976
+ return labelSet.some(function (l) {
1977
+ return label.includes(l);
1978
+ });
1979
+ };
1980
+ var getDeviceLabel = function getDeviceLabel(deviceInfo) {
1981
+ return deviceInfo.label.toLocaleLowerCase().split(' ').join('');
1982
+ };
1983
+ var currentCamera;
1984
+ var currentAudioStream;
1985
+ function obtainCameraAccess(stream, deviceLabel, video) {
1986
+ releaseCameraAccess();
1987
+ log('obtaining camera access...');
1988
+ var _a = stream.getVideoTracks()[0].getSettings(),
1989
+ width = _a.width,
1990
+ height = _a.height;
1991
+ var label = deviceLabel.toLocaleLowerCase().split(' ').join('');
1992
+ var isRearFacing = labelMatches(label, __spreadArray(__spreadArray(__spreadArray([], rearLabels, true), backUltraWideLabels, true), ['iphone'], false));
1993
+ var release = function release() {
1994
+ stream.getTracks().forEach(function (track) {
1995
+ track.enabled = false;
1996
+ track.stop();
1997
+ });
1998
+ if (video) {
1999
+ video.pause();
2000
+ video.srcObject = null;
2001
+ video.src = '';
2092
2002
  }
2093
- if (maxTime === void 0) {
2094
- maxTime = 10000;
2003
+ };
2004
+ width || (width = 0);
2005
+ height || (height = 0);
2006
+ currentCamera = {
2007
+ label: deviceLabel,
2008
+ stream: stream,
2009
+ width: width,
2010
+ height: height,
2011
+ isRearFacing: isRearFacing,
2012
+ release: release
2013
+ };
2014
+ if (video) video.srcObject = stream;
2015
+ return currentCamera;
2016
+ }
2017
+ function releaseCameraAccess() {
2018
+ if (!currentCamera) return;
2019
+ log('releasing camera access...');
2020
+ currentCamera.release();
2021
+ currentCamera = undefined;
2022
+ }
2023
+ function releaseMicrophoneAccess() {
2024
+ var _a;
2025
+ if (!currentAudioStream) return;
2026
+ log('releasing microphone access...');
2027
+ (_a = currentAudioStream.stop) === null || _a === void 0 ? void 0 : _a.call(currentAudioStream);
2028
+ currentAudioStream.getAudioTracks().forEach(function (t) {
2029
+ var _a;
2030
+ (_a = t.stop) === null || _a === void 0 ? void 0 : _a.call(t);
2031
+ });
2032
+ currentAudioStream = undefined;
2033
+ }
2034
+ function usePreferredCaptureDevice(_a) {
2035
+ var _b = _a === void 0 ? {} : _a,
2036
+ _c = _b.requestAccessAutomatically,
2037
+ requestAccessAutomatically = _c === void 0 ? true : _c,
2038
+ _d = _b.preferFrontFacingCamera,
2039
+ preferFrontFacingCamera = _d === void 0 ? false : _d,
2040
+ _e = _b.preferContinuityCamera,
2041
+ preferContinuityCamera = _e === void 0 ? true : _e,
2042
+ _f = _b.requireMicrophoneAccess,
2043
+ requireMicrophoneAccess = _f === void 0 ? false : _f,
2044
+ _g = _b.maxVideoWidth,
2045
+ maxVideoWidth = _g === void 0 ? 1920 : _g,
2046
+ maxFps = _b.maxFps,
2047
+ _h = _b.debugMode,
2048
+ debugMode = _h === void 0 ? false : _h;
2049
+ var videoRef = useRef(null);
2050
+ var videoRefStack = useRef([]);
2051
+ var cameraRef = useRef(null);
2052
+ var _j = useState(false),
2053
+ cameraReady = _j[0],
2054
+ setCameraReady = _j[1];
2055
+ var _k = useState(false),
2056
+ microphoneReady = _k[0],
2057
+ setMicrophoneReady = _k[1];
2058
+ var _l = useState(null),
2059
+ videoDevice = _l[0],
2060
+ setVideoDevice = _l[1];
2061
+ var _m = useState(null),
2062
+ audioStream = _m[0],
2063
+ setAudioStream = _m[1];
2064
+ var _o = useState(false),
2065
+ videoLoaded = _o[0],
2066
+ setVideoLoaded = _o[1];
2067
+ var _p = useState(false),
2068
+ iphoneContinuityCameraAvailable = _p[0],
2069
+ setIphoneContinuityCameraAvailable = _p[1];
2070
+ var _q = useState(preferContinuityCamera),
2071
+ iphoneContinuityCameraAllowed = _q[0],
2072
+ setIphoneContinuityCameraAllowed = _q[1];
2073
+ var _r = useState(false),
2074
+ iphoneContinuityCameraDenied = _r[0],
2075
+ setIphoneContinuityCameraDenied = _r[1];
2076
+ var _s = useState(false),
2077
+ cameraAccessDenied = _s[0],
2078
+ setCameraAccessDenied = _s[1];
2079
+ var _t = useState(false),
2080
+ microphoneAccessDenied = _t[0],
2081
+ setMicrophoneAccessDenied = _t[1];
2082
+ var videoRefElement = videoRef.current;
2083
+ useEffect(function pushVideoRefToStackWhenChanged() {
2084
+ // proceed if the video element being mounted is not already at the top of the videoRefStack.
2085
+ var topOfStack = videoRefStack.current.slice(-1)[0];
2086
+ if (videoRefElement && videoRefElement !== topOfStack) {
2087
+ log('adding video to stack', videoRefElement);
2088
+ videoRefStack.current.push(videoRefElement);
2089
+ }
2090
+ }, [videoRefElement]);
2091
+ var onVideoUnmounted = useCallback(function (videoElement) {
2092
+ log('removing video from stack', videoElement);
2093
+ videoRefStack.current = videoRefStack.current.filter(function (v) {
2094
+ return v !== videoElement;
2095
+ });
2096
+ videoRef.current = videoRefStack.current.slice(-1)[0]; // top of stack.
2097
+ log('new videoRef is', videoRef.current);
2098
+ }, []);
2099
+ useEffect(function resetCameraOnContinuityPreferenceChanged() {
2100
+ if (debugMode) {
2101
+ log('iphone continuity camera allowed changed', iphoneContinuityCameraAllowed);
2095
2102
  }
2096
- return __generator(this, function (_c) {
2097
- switch (_c.label) {
2098
- case 0:
2099
- modelAssetPath = "".concat(defaultImageSegmenterModelPath, "?_=").concat(tinyModelCacheKey);
2100
- startedAt = new Date();
2101
- _c.label = 1;
2103
+ releaseCameraAccess();
2104
+ cameraRef.current = null;
2105
+ setVideoLoaded(false);
2106
+ }, [debugMode, iphoneContinuityCameraAllowed]);
2107
+ // NOTE: the bound callback function here is called requestCameraAccess, because
2108
+ // it initiates the useEffect chain that results in camera access being requested
2109
+ // (requestCameraAccessAutomatically -> chooseFromAvailableCameras -> accessChosenCamera).
2110
+ //
2111
+ // We chose to title the inner function "chooseFromAvailableCameras" because
2112
+ // that's all it literally does -- the available cameras are enumerated, and then
2113
+ // the result is parsed to decide which one we like best, which is then passed to
2114
+ // setVideoDevice, which causes accessChosenCamera to trigger.
2115
+ //
2116
+ // I am not a huge fan of getUserMedia's design -- you need to call it twice in order
2117
+ // to select the "best" camera for your application's purposes.
2118
+ var requestCameraAccess = useCallback(function chooseFromAvailableCameras() {
2119
+ return __awaiter(this, void 0, void 0, function () {
2120
+ var availableCameras, selectedCamera, platform_1, iphoneContinuityCamera, e_1;
2121
+ var _a, _b;
2122
+ return __generator(this, function (_c) {
2123
+ switch (_c.label) {
2124
+ case 0:
2125
+ setCameraReady(false);
2126
+ setCameraAccessDenied(false);
2127
+ _c.label = 1;
2128
+ case 1:
2129
+ _c.trys.push([1, 3,, 4]);
2130
+ return [4 /*yield*/, listAvailableCameras()];
2131
+ case 2:
2132
+ availableCameras = _c.sent();
2133
+ selectedCamera = void 0;
2134
+ if (debugMode) {
2135
+ log('availableCameras', availableCameras);
2136
+ }
2137
+ platform_1 = getPlatform();
2138
+ if (debugMode) {
2139
+ log('platformDetails', platform_1);
2140
+ }
2141
+ if (!iphoneContinuityCameraDenied && (!(platform_1 === null || platform_1 === void 0 ? void 0 : platform_1.os) || platform_1.os.family === 'OS X')) {
2142
+ iphoneContinuityCamera = availableCameras.find(function (deviceInfo) {
2143
+ return labelMatches(deviceInfo, 'iphone');
2144
+ });
2145
+ setIphoneContinuityCameraAvailable(!!iphoneContinuityCamera);
2146
+ if (iphoneContinuityCamera && iphoneContinuityCameraAllowed) {
2147
+ selectedCamera = iphoneContinuityCamera;
2148
+ }
2149
+ } else if (((_a = platform_1 === null || platform_1 === void 0 ? void 0 : platform_1.os) === null || _a === void 0 ? void 0 : _a.family) === 'Android' || availableCameras.every(function (c) {
2150
+ return c.label.startsWith('camera2 ');
2151
+ })) {
2152
+ availableCameras = availableCameras.sort(function (a, b) {
2153
+ return a.label.toLowerCase().localeCompare(b.label.toLowerCase());
2154
+ });
2155
+ if (debugMode) {
2156
+ log('cameras have been sorted', availableCameras);
2157
+ }
2158
+ }
2159
+ if (preferFrontFacingCamera) {
2160
+ selectedCamera = availableCameras.find(function (deviceInfo) {
2161
+ return labelMatches(deviceInfo, frontLabels);
2162
+ });
2163
+ }
2164
+ selectedCamera || (selectedCamera = availableCameras.find(function (deviceInfo) {
2165
+ return labelMatches(deviceInfo, 'backtriplecamera');
2166
+ }));
2167
+ selectedCamera || (selectedCamera = availableCameras.find(function (deviceInfo) {
2168
+ return labelMatches(deviceInfo, 'backdualcamera');
2169
+ }));
2170
+ selectedCamera || (selectedCamera = availableCameras.find(function (deviceInfo) {
2171
+ return labelMatches(deviceInfo, rearLabels) && !labelMatches(deviceInfo, backUltraWideLabels);
2172
+ }));
2173
+ selectedCamera || (selectedCamera = availableCameras.find(function (deviceInfo) {
2174
+ return labelMatches(deviceInfo, rearLabels);
2175
+ }));
2176
+ // on iOS, the front facing camera always is at the first position in the list, so we skip it if all else fails.
2177
+ if (!preferFrontFacingCamera && ((_b = platform_1 === null || platform_1 === void 0 ? void 0 : platform_1.os) === null || _b === void 0 ? void 0 : _b.family) === 'iOS' && availableCameras.length > 0) {
2178
+ selectedCamera || (selectedCamera = availableCameras[1]);
2179
+ }
2180
+ selectedCamera || (selectedCamera = availableCameras[0]);
2181
+ if (debugMode) log('selectedCamera', selectedCamera);
2182
+ setVideoDevice(selectedCamera);
2183
+ return [3 /*break*/, 4];
2184
+ case 3:
2185
+ e_1 = _c.sent();
2186
+ if (e_1.name === 'NotAllowedError') {
2187
+ error('camera access has been blocked by the user', e_1);
2188
+ setCameraAccessDenied(true);
2189
+ } else {
2190
+ error('camera access encountered some other error', e_1);
2191
+ throw e_1;
2192
+ }
2193
+ return [3 /*break*/, 4];
2194
+ case 4:
2195
+ return [2 /*return*/];
2196
+ }
2197
+ });
2198
+ });
2199
+ }, [debugMode, iphoneContinuityCameraAllowed, iphoneContinuityCameraDenied, preferFrontFacingCamera]);
2200
+ useEffect(function requestCameraAccessAutomatically() {
2201
+ if (requestAccessAutomatically && !cameraAccessDenied) {
2202
+ requestCameraAccess()["catch"](error);
2203
+ }
2204
+ }, [cameraAccessDenied, requestAccessAutomatically, requestCameraAccess]);
2205
+ useEffect(function accessChosenCamera() {
2206
+ var _this = this;
2207
+ var _a;
2208
+ if (!videoDevice) return;
2209
+ var cleanup = function cleanup() {
2210
+ releaseCameraAccess();
2211
+ cameraRef.current = null;
2212
+ setVideoLoaded(false);
2213
+ };
2214
+ if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia)) return cleanup;
2215
+ (function () {
2216
+ return __awaiter(_this, void 0, void 0, function () {
2217
+ var constraints, stream, e_2, handleStreamEnded;
2218
+ var _a;
2219
+ return __generator(this, function (_b) {
2220
+ switch (_b.label) {
2221
+ case 0:
2222
+ constraints = {
2223
+ audio: false,
2224
+ video: {
2225
+ deviceId: {
2226
+ exact: videoDevice.deviceId
2227
+ },
2228
+ width: {
2229
+ ideal: maxVideoWidth
2230
+ },
2231
+ aspectRatio: 1.777777778,
2232
+ frameRate: {}
2233
+ }
2234
+ };
2235
+ if (maxFps) {
2236
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2237
+ // @ts-ignore
2238
+ constraints.video.frameRate = {
2239
+ max: maxFps
2240
+ };
2241
+ }
2242
+ stream = null;
2243
+ _b.label = 1;
2244
+ case 1:
2245
+ _b.trys.push([1, 3,, 4]);
2246
+ return [4 /*yield*/, navigator.mediaDevices.getUserMedia(constraints)];
2247
+ case 2:
2248
+ stream = _b.sent();
2249
+ return [3 /*break*/, 4];
2250
+ case 3:
2251
+ e_2 = _b.sent();
2252
+ if (e_2.name === 'NotAllowedError') {
2253
+ if (iphoneContinuityCameraAllowed) {
2254
+ setIphoneContinuityCameraAvailable(false);
2255
+ setIphoneContinuityCameraDenied(true);
2256
+ } else {
2257
+ setCameraAccessDenied(true);
2258
+ }
2259
+ return [2 /*return*/];
2260
+ }
2261
+ return [3 /*break*/, 4];
2262
+ case 4:
2263
+ if (!!stream) return [3 /*break*/, 8];
2264
+ _b.label = 5;
2265
+ case 5:
2266
+ _b.trys.push([5, 7,, 8]);
2267
+ return [4 /*yield*/, navigator.mediaDevices.getUserMedia({
2268
+ audio: false,
2269
+ video: true
2270
+ })];
2271
+ case 6:
2272
+ stream = _b.sent();
2273
+ log('opened stream with no width and height constraints');
2274
+ return [3 /*break*/, 8];
2275
+ case 7:
2276
+ _b.sent();
2277
+ log('cannot open stream at all');
2278
+ return [3 /*break*/, 8];
2279
+ case 8:
2280
+ if (!stream) {
2281
+ throw new Error('failed to open camera');
2282
+ }
2283
+ handleStreamEnded = function handleStreamEnded() {
2284
+ if (iphoneContinuityCameraAvailable && iphoneContinuityCameraAllowed) {
2285
+ log('someone unplugged the continuity camera');
2286
+ releaseCameraAccess();
2287
+ cameraRef.current = null;
2288
+ setIphoneContinuityCameraAvailable(false);
2289
+ setIphoneContinuityCameraDenied(true);
2290
+ setVideoDevice(null);
2291
+ } else {
2292
+ log('someone unplugged the webcam');
2293
+ releaseCameraAccess();
2294
+ cameraRef.current = null;
2295
+ setVideoLoaded(false);
2296
+ setCameraAccessDenied(true);
2297
+ }
2298
+ };
2299
+ (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener('ended', handleStreamEnded);
2300
+ stream.getVideoTracks().forEach(function (track) {
2301
+ track.onended = handleStreamEnded;
2302
+ });
2303
+ cameraRef.current = obtainCameraAccess(stream, videoDevice.label, videoRef.current);
2304
+ return [2 /*return*/];
2305
+ }
2306
+ });
2307
+ });
2308
+ })();
2309
+ return cleanup;
2310
+ }, [iphoneContinuityCameraAllowed, iphoneContinuityCameraAvailable, maxFps, maxVideoWidth, videoDevice]);
2311
+ useEffect(function triggerCameraReady() {
2312
+ // TODO: in the future let's evaluate whether we can simplify this to just
2313
+ // setCameraReady(!!videoDevice && videoLoaded) -- we are wondering whether
2314
+ // we somehow depend on this being set twice.
2315
+ setCameraReady(false);
2316
+ if (videoDevice && videoLoaded) {
2317
+ setCameraReady(videoDevice && videoLoaded);
2318
+ }
2319
+ }, [videoLoaded, videoDevice]);
2320
+ var requestMicrophoneAccess = useCallback(function _requestMicrophoneAccess() {
2321
+ return __awaiter(this, void 0, void 0, function () {
2322
+ var stream;
2323
+ return __generator(this, function (_a) {
2324
+ switch (_a.label) {
2325
+ case 0:
2326
+ setMicrophoneReady(false);
2327
+ setMicrophoneAccessDenied(false);
2328
+ _a.label = 1;
2329
+ case 1:
2330
+ _a.trys.push([1, 3,, 4]);
2331
+ return [4 /*yield*/, navigator.mediaDevices.getUserMedia({
2332
+ audio: true,
2333
+ video: false
2334
+ })];
2335
+ case 2:
2336
+ stream = _a.sent();
2337
+ currentAudioStream = stream;
2338
+ setAudioStream(stream);
2339
+ setMicrophoneReady(true);
2340
+ stream.getAudioTracks().forEach(function (track) {
2341
+ track.onended = function () {
2342
+ setMicrophoneAccessDenied(true);
2343
+ };
2344
+ });
2345
+ return [3 /*break*/, 4];
2346
+ case 3:
2347
+ _a.sent();
2348
+ setMicrophoneAccessDenied(true);
2349
+ return [3 /*break*/, 4];
2350
+ case 4:
2351
+ return [2 /*return*/];
2352
+ }
2353
+ });
2354
+ });
2355
+ }, []);
2356
+ useEffect(function requestMicrophoneAccessIfNeeded() {
2357
+ if (!requireMicrophoneAccess || microphoneAccessDenied) return;
2358
+ requestMicrophoneAccess()["catch"](error);
2359
+ return function () {
2360
+ releaseMicrophoneAccess();
2361
+ setAudioStream(null);
2362
+ setMicrophoneReady(false);
2363
+ };
2364
+ }, [microphoneAccessDenied, requestMicrophoneAccess, requireMicrophoneAccess]);
2365
+ var takePhoto = useCallback(function _takePhoto() {
2366
+ return __awaiter(this, void 0, void 0, function () {
2367
+ var canvas;
2368
+ return __generator(this, function (_a) {
2369
+ switch (_a.label) {
2370
+ case 0:
2371
+ if (!cameraRef.current) return [2 /*return*/, null];
2372
+ if (!(typeof ImageCapture !== 'undefined')) return [3 /*break*/, 2];
2373
+ return [4 /*yield*/, new ImageCapture(cameraRef.current.stream.getTracks()[0]).takePhoto()];
2374
+ case 1:
2375
+ return [2 /*return*/, _a.sent()];
2376
+ case 2:
2377
+ if (!videoRef.current) return [2 /*return*/, null];
2378
+ canvas = document.createElement('canvas');
2379
+ drawToCanvas(canvas, videoRef.current);
2380
+ return [2 /*return*/, new Promise(function (resolve) {
2381
+ return canvas.toBlob(resolve);
2382
+ })];
2383
+ }
2384
+ });
2385
+ });
2386
+ }, []);
2387
+ return useMemo(function () {
2388
+ return {
2389
+ videoRef: videoRef,
2390
+ videoDevice: videoDevice,
2391
+ videoLoaded: videoLoaded,
2392
+ setVideoLoaded: setVideoLoaded,
2393
+ onVideoUnmounted: onVideoUnmounted,
2394
+ cameraRef: cameraRef,
2395
+ cameraReady: cameraReady,
2396
+ cameraAccessDenied: cameraAccessDenied,
2397
+ requestCameraAccess: requestCameraAccess,
2398
+ releaseCameraAccess: releaseCameraAccess,
2399
+ iphoneContinuityCameraAvailable: iphoneContinuityCameraAvailable,
2400
+ iphoneContinuityCameraAllowed: iphoneContinuityCameraAllowed,
2401
+ setIphoneContinuityCameraAllowed: setIphoneContinuityCameraAllowed,
2402
+ takePhoto: takePhoto,
2403
+ audioStream: audioStream,
2404
+ microphoneReady: microphoneReady,
2405
+ microphoneAccessDenied: microphoneAccessDenied,
2406
+ requestMicrophoneAccess: requestMicrophoneAccess
2407
+ };
2408
+ }, [audioStream, cameraAccessDenied, cameraReady, iphoneContinuityCameraAllowed, iphoneContinuityCameraAvailable, microphoneAccessDenied, microphoneReady, onVideoUnmounted, requestCameraAccess, requestMicrophoneAccess, takePhoto, videoDevice, videoLoaded]);
2409
+ }
2410
+
2411
+ var CameraStateContext = /*#__PURE__*/createContext({
2412
+ videoRef: {
2413
+ current: null
2414
+ },
2415
+ videoDevice: null,
2416
+ videoLoaded: false,
2417
+ cameraRef: {
2418
+ current: null
2419
+ },
2420
+ cameraReady: false,
2421
+ cameraAccessDenied: false,
2422
+ requestCameraAccess: function requestCameraAccess() {
2423
+ return null;
2424
+ },
2425
+ releaseCameraAccess: function releaseCameraAccess() {
2426
+ return null;
2427
+ },
2428
+ iphoneContinuityCameraAvailable: false,
2429
+ iphoneContinuityCameraAllowed: true,
2430
+ setIphoneContinuityCameraAllowed: function setIphoneContinuityCameraAllowed() {
2431
+ return null;
2432
+ },
2433
+ takePhoto: function takePhoto() {
2434
+ return Promise.resolve(null);
2435
+ },
2436
+ setVideoLoaded: function setVideoLoaded() {
2437
+ return null;
2438
+ },
2439
+ onVideoUnmounted: function onVideoUnmounted() {
2440
+ return null;
2441
+ },
2442
+ audioStream: null,
2443
+ microphoneReady: false,
2444
+ microphoneAccessDenied: false,
2445
+ requestMicrophoneAccess: function requestMicrophoneAccess() {
2446
+ return null;
2447
+ }
2448
+ });
2449
+ var CameraProvider = function CameraProvider(_a) {
2450
+ var children = _a.children,
2451
+ _b = _a.requestAccessAutomatically,
2452
+ requestAccessAutomatically = _b === void 0 ? true : _b,
2453
+ _c = _a.preferFrontFacingCamera,
2454
+ preferFrontFacingCamera = _c === void 0 ? false : _c,
2455
+ _d = _a.preferContinuityCamera,
2456
+ preferContinuityCamera = _d === void 0 ? true : _d,
2457
+ _e = _a.requireMicrophoneAccess,
2458
+ requireMicrophoneAccess = _e === void 0 ? false : _e,
2459
+ _f = _a.maxVideoWidth,
2460
+ maxVideoWidth = _f === void 0 ? 1920 : _f,
2461
+ maxFps = _a.maxFps,
2462
+ onCameraAccessDenied = _a.onCameraAccessDenied,
2463
+ onMicrophoneAccessDenied = _a.onMicrophoneAccessDenied,
2464
+ _g = _a.debugMode,
2465
+ debugMode = _g === void 0 ? false : _g;
2466
+ var captureDevice = usePreferredCaptureDevice({
2467
+ requestAccessAutomatically: requestAccessAutomatically,
2468
+ preferFrontFacingCamera: preferFrontFacingCamera,
2469
+ preferContinuityCamera: preferContinuityCamera,
2470
+ requireMicrophoneAccess: requireMicrophoneAccess,
2471
+ maxVideoWidth: maxVideoWidth,
2472
+ maxFps: maxFps,
2473
+ debugMode: debugMode
2474
+ });
2475
+ useEffect(function () {
2476
+ if (captureDevice.cameraAccessDenied) onCameraAccessDenied === null || onCameraAccessDenied === void 0 ? void 0 : onCameraAccessDenied();
2477
+ }, [captureDevice.cameraAccessDenied, onCameraAccessDenied]);
2478
+ useEffect(function () {
2479
+ if (captureDevice.microphoneAccessDenied) onMicrophoneAccessDenied === null || onMicrophoneAccessDenied === void 0 ? void 0 : onMicrophoneAccessDenied();
2480
+ }, [captureDevice.microphoneAccessDenied, onMicrophoneAccessDenied]);
2481
+ var releaseCameraAccess = captureDevice.releaseCameraAccess;
2482
+ useEffect(function () {
2483
+ return function () {
2484
+ releaseCameraAccess();
2485
+ };
2486
+ }, [releaseCameraAccess]);
2487
+ return /*#__PURE__*/React__default.createElement(CameraStateContext.Provider, {
2488
+ value: captureDevice
2489
+ }, children);
2490
+ };
2491
+
2492
+ var visionTasksBasePath = "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.7/wasm";
2493
+ var visionRuntimePreloading = false;
2494
+ function preloadVisionRuntime() {
2495
+ return __awaiter(this, void 0, void 0, function () {
2496
+ function handleDownloadProgress(event) {
2497
+ var detail = event.detail;
2498
+ if (detail.url !== url) return;
2499
+ progressByUseCase.visionRuntime = sumUpProgressForDependencies([url]);
2500
+ document.dispatchEvent(new CustomEvent('idmission.preloadProgress.visionRuntime', {
2501
+ detail: progressByUseCase.visionRuntime
2502
+ }));
2503
+ }
2504
+ var url;
2505
+ return __generator(this, function (_a) {
2506
+ switch (_a.label) {
2507
+ case 0:
2508
+ if (visionRuntimePreloading) return [2 /*return*/, new Promise(function (resolve) {
2509
+ setInterval(function () {
2510
+ if (!visionRuntimePreloading) resolve();
2511
+ }, 100);
2512
+ })];
2513
+ visionRuntimePreloading = true;
2514
+ url = "".concat(visionTasksBasePath, "/vision_wasm_internal.wasm");
2515
+ document.addEventListener('idmission.preloadProgress', handleDownloadProgress);
2516
+ _a.label = 1;
2102
2517
  case 1:
2103
- _c.trys.push([1, 3,, 4]);
2104
- return [4 /*yield*/, Promise.race([preloadDependency(modelAssetPath), giveUpAfter(maxTime)])];
2518
+ _a.trys.push([1,, 3, 4]);
2519
+ return [4 /*yield*/, preloadDependency(url)];
2105
2520
  case 2:
2106
- _c.sent();
2521
+ _a.sent();
2107
2522
  return [3 /*break*/, 4];
2108
2523
  case 3:
2109
- e_1 = _c.sent();
2110
- error('speed test failed', e_1);
2111
- modelCapabilities.networkTier = 'unusable';
2112
- return [2 /*return*/];
2524
+ document.removeEventListener('idmission.preloadProgress', handleDownloadProgress);
2525
+ visionRuntimePreloading = false;
2526
+ return [7 /*endfinally*/];
2113
2527
  case 4:
2114
- time = (new Date().getTime() - startedAt.getTime()) / 1000.0;
2115
- modelCapabilities.networkTestTime || (modelCapabilities.networkTestTime = time);
2116
- modelCapabilities.networkSpeed || (modelCapabilities.networkSpeed = imageSegmenterModelSizeInBytes / time);
2117
- modelCapabilities.networkTier = time < 0.5 ? 'fast' : time < 2 ? 'medium' : 'slow';
2118
- speedMbps = modelCapabilities.networkSpeed / 1024 / 1024;
2119
- log('Model Probing: network speed', speedMbps.toFixed(3), 'Mbps');
2120
- log('Model Probing: network test took', time);
2121
- log('Model Probing: network tier', modelCapabilities.networkTier);
2122
- _b = (_a = ImageSegmenter).createFromOptions;
2123
- return [4 /*yield*/, FilesetResolver.forVisionTasks(visionTasksBasePath)];
2124
- case 5:
2125
- return [4 /*yield*/, _b.apply(_a, [_c.sent(), {
2126
- baseOptions: {
2127
- modelAssetPath: modelAssetPath,
2128
- delegate: delegate
2129
- }
2130
- }])];
2131
- case 6:
2132
- model = _c.sent();
2133
- emptyFrame = document.createElement('canvas');
2134
- model.segment(emptyFrame);
2135
- emptyFrame.remove();
2136
2528
  return [2 /*return*/];
2137
2529
  }
2138
2530
  });
2139
2531
  });
2140
2532
  }
2141
- function giveUpAfter(maxTime) {
2142
- return new Promise(function (_resolve, reject) {
2143
- setTimeout(function () {
2144
- reject(new Error('gave up after reaching maximum time allowed'));
2145
- }, maxTime);
2146
- });
2147
- }
2148
2533
 
2149
- function convertBoundingBox(box) {
2150
- var _a, _b, _c, _d, _e, _f, _g, _h;
2151
- return {
2152
- xMin: (_a = box === null || box === void 0 ? void 0 : box.originX) !== null && _a !== void 0 ? _a : 0,
2153
- xMax: ((_b = box === null || box === void 0 ? void 0 : box.originX) !== null && _b !== void 0 ? _b : 0) + ((_c = box === null || box === void 0 ? void 0 : box.width) !== null && _c !== void 0 ? _c : 0),
2154
- yMin: (_d = box === null || box === void 0 ? void 0 : box.originY) !== null && _d !== void 0 ? _d : 0,
2155
- yMax: ((_e = box === null || box === void 0 ? void 0 : box.originY) !== null && _e !== void 0 ? _e : 0) + ((_f = box === null || box === void 0 ? void 0 : box.height) !== null && _f !== void 0 ? _f : 0),
2156
- width: (_g = box === null || box === void 0 ? void 0 : box.width) !== null && _g !== void 0 ? _g : 0,
2157
- height: (_h = box === null || box === void 0 ? void 0 : box.height) !== null && _h !== void 0 ? _h : 0
2158
- };
2159
- }
2160
- function waitForVideoReady(videoRef, checkEveryMs) {
2161
- if (checkEveryMs === void 0) {
2162
- checkEveryMs = 100;
2534
+ function cropToShoulders(rawCanvas, cropCanvas, resizeCanvas, frame, face, quality, maxHeight) {
2535
+ if (quality === void 0) {
2536
+ quality = 0.92;
2163
2537
  }
2164
- return new Promise(function (resolve) {
2165
- var _a, _b, _c;
2166
- if (((_b = (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.readyState) !== null && _b !== void 0 ? _b : 0) >= 2) return resolve();
2167
- (_c = videoRef.current) === null || _c === void 0 ? void 0 : _c.load();
2168
- var interval = setInterval(function () {
2169
- var _a, _b;
2170
- if (((_b = (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.readyState) !== null && _b !== void 0 ? _b : 0) >= 2) {
2171
- clearInterval(interval);
2172
- resolve();
2173
- }
2174
- }, checkEveryMs);
2175
- });
2176
- }
2177
- function calculateIoU(boxA, boxB) {
2178
- var xA = Math.max(boxA.xMin, boxB.xMin);
2179
- var yA = Math.max(boxA.yMin, boxB.yMin);
2180
- var xB = Math.min(boxA.xMax, boxB.xMax);
2181
- var yB = Math.min(boxA.yMax, boxB.yMax);
2538
+ if (!rawCanvas || !cropCanvas || !resizeCanvas) return '';
2539
+ var rawCtx = rawCanvas.getContext('2d');
2540
+ var cropCtx = cropCanvas.getContext('2d');
2541
+ var resizeCtx = resizeCanvas.getContext('2d');
2542
+ if (!rawCtx || !cropCtx || !resizeCtx) throw new Error('could not get 2d context');
2543
+ rawCanvas.width = frame.width;
2544
+ rawCanvas.height = frame.height;
2545
+ rawCtx.putImageData(frame, 0, 0);
2546
+ if (frame.height > frame.width) {
2547
+ cropCanvas.width = frame.width;
2548
+ cropCanvas.height = frame.height;
2549
+ cropCtx.drawImage(rawCanvas, 0, 0, cropCanvas.width, cropCanvas.height);
2550
+ } else {
2551
+ var _a = face.box,
2552
+ xMin = _a.xMin,
2553
+ width = _a.width;
2554
+ var desiredWidth = frame.height * 0.6;
2555
+ var faceCenterX = xMin + width / 2;
2556
+ var xPos = Math.max(0, faceCenterX - desiredWidth / 2);
2557
+ cropCanvas.width = desiredWidth;
2558
+ cropCanvas.height = frame.height;
2559
+ cropCtx.drawImage(rawCanvas, xPos, 0, cropCanvas.width, cropCanvas.height, 0, 0, cropCanvas.width, cropCanvas.height);
2560
+ }
2561
+ resizeCanvas.height = maxHeight !== null && maxHeight !== void 0 ? maxHeight : cropCanvas.height;
2562
+ resizeCanvas.width = cropCanvas.width * (resizeCanvas.height / cropCanvas.height);
2563
+ resizeCtx === null || resizeCtx === void 0 ? void 0 : resizeCtx.drawImage(cropCanvas, 0, 0, resizeCanvas.width, resizeCanvas.height);
2564
+ var dataURL = resizeCanvas.toDataURL('image/jpeg', quality);
2565
+ log('cropToShoulders size', new TextEncoder().encode(dataURL).length);
2566
+ clearCanvas(rawCanvas);
2567
+ clearCanvas(cropCanvas);
2568
+ clearCanvas(resizeCanvas);
2569
+ return dataURL;
2570
+ }
2571
+ function cropToDetectedObjectBox(frame, box, canvas) {
2572
+ canvas || (canvas = document.createElement('canvas'));
2573
+ var ctx = canvas.getContext('2d');
2574
+ if (!ctx) throw new Error('could not get 2d context');
2575
+ var xMin = box.xMin,
2576
+ yMin = box.yMin,
2577
+ width = box.width,
2578
+ height = box.height;
2579
+ canvas.width = width;
2580
+ canvas.height = height;
2581
+ ctx.drawImage(frame, xMin, yMin, width, height, 0, 0, width, height);
2582
+ return canvas;
2583
+ }
2584
+
2585
+ var defaultImageSegmenterModelPath = 'https://websdk-cdn-dev.idmission.com/assets/models/selfiesegmenter20240524/selfie_segmenter.tflite';
2586
+ var imageSegmenterModelSizeInBytes = 256440.32;
2587
+ // The idea here is that we globally set a cache key based on the time at page load. That way our built-in speed test
2588
+ // isn't fooled by cache times, but subsequent downloads of the vision runtime still do load from the cache.
2589
+ var tinyModelCacheKey = new Date().getTime();
2590
+ var initialModelCapabilities = {
2591
+ probeState: 'notProbed',
2592
+ delegate: 'GPU',
2593
+ networkTier: 'untested',
2594
+ networkSpeed: 0,
2595
+ networkTestTime: 0
2596
+ };
2597
+ var modelCapabilities = _assign({}, initialModelCapabilities);
2598
+ function probeModelCapabilities() {
2599
+ return __awaiter(this, void 0, void 0, function () {
2600
+ var error_1, error_2;
2601
+ return __generator(this, function (_a) {
2602
+ switch (_a.label) {
2603
+ case 0:
2604
+ if (modelCapabilities.probeState === 'probed') return [2 /*return*/];
2605
+ if (modelCapabilities.probeState === 'probing') return [2 /*return*/, new Promise(function (resolve) {
2606
+ setInterval(function () {
2607
+ if (modelCapabilities.probeState === 'probed') resolve();
2608
+ }, 100);
2609
+ })];
2610
+ modelCapabilities.probeState = 'probing';
2611
+ return [4 /*yield*/, preloadVisionRuntime()];
2612
+ case 1:
2613
+ _a.sent();
2614
+ _a.label = 2;
2615
+ case 2:
2616
+ _a.trys.push([2, 4, 9, 10]);
2617
+ log('Model Probing: testing GPU capabilities...');
2618
+ return [4 /*yield*/, loadTinyModel('GPU')];
2619
+ case 3:
2620
+ _a.sent();
2621
+ log('Model Probing: GPU is capable.');
2622
+ return [3 /*break*/, 10];
2623
+ case 4:
2624
+ error_1 = _a.sent();
2625
+ warn('Model Probing: GPU delegate could not be loaded', error_1);
2626
+ modelCapabilities.delegate = 'CPU';
2627
+ _a.label = 5;
2628
+ case 5:
2629
+ _a.trys.push([5, 7,, 8]);
2630
+ log('Model Probing: testing CPU capabilities...');
2631
+ return [4 /*yield*/, loadTinyModel('CPU')];
2632
+ case 6:
2633
+ _a.sent();
2634
+ log('Model Probing: CPU is capable.');
2635
+ return [3 /*break*/, 8];
2636
+ case 7:
2637
+ error_2 = _a.sent();
2638
+ warn('Model Probing: CPU delegate could not be loaded', error_2);
2639
+ modelCapabilities.delegate = 'NONE';
2640
+ return [3 /*break*/, 8];
2641
+ case 8:
2642
+ return [3 /*break*/, 10];
2643
+ case 9:
2644
+ modelCapabilities.probeState = 'probed';
2645
+ return [7 /*endfinally*/];
2646
+ case 10:
2647
+ return [2 /*return*/];
2648
+ }
2649
+ });
2650
+ });
2651
+ }
2652
+ function loadTinyModel() {
2653
+ return __awaiter(this, arguments, void 0, function (delegate, maxTime) {
2654
+ var modelAssetPath, startedAt, e_1, time, speedMbps, model, _a, _b, emptyFrame;
2655
+ if (delegate === void 0) {
2656
+ delegate = 'GPU';
2657
+ }
2658
+ if (maxTime === void 0) {
2659
+ maxTime = 10000;
2660
+ }
2661
+ return __generator(this, function (_c) {
2662
+ switch (_c.label) {
2663
+ case 0:
2664
+ modelAssetPath = "".concat(defaultImageSegmenterModelPath, "?_=").concat(tinyModelCacheKey);
2665
+ startedAt = new Date();
2666
+ _c.label = 1;
2667
+ case 1:
2668
+ _c.trys.push([1, 3,, 4]);
2669
+ return [4 /*yield*/, Promise.race([preloadDependency(modelAssetPath), giveUpAfter(maxTime)])];
2670
+ case 2:
2671
+ _c.sent();
2672
+ return [3 /*break*/, 4];
2673
+ case 3:
2674
+ e_1 = _c.sent();
2675
+ error('speed test failed', e_1);
2676
+ modelCapabilities.networkTier = 'unusable';
2677
+ return [2 /*return*/];
2678
+ case 4:
2679
+ time = (new Date().getTime() - startedAt.getTime()) / 1000.0;
2680
+ modelCapabilities.networkTestTime || (modelCapabilities.networkTestTime = time);
2681
+ modelCapabilities.networkSpeed || (modelCapabilities.networkSpeed = imageSegmenterModelSizeInBytes / time);
2682
+ modelCapabilities.networkTier = time < 0.5 ? 'fast' : time < 2 ? 'medium' : 'slow';
2683
+ speedMbps = modelCapabilities.networkSpeed / 1024 / 1024;
2684
+ log('Model Probing: network speed', speedMbps.toFixed(3), 'Mbps');
2685
+ log('Model Probing: network test took', time);
2686
+ log('Model Probing: network tier', modelCapabilities.networkTier);
2687
+ _b = (_a = ImageSegmenter).createFromOptions;
2688
+ return [4 /*yield*/, FilesetResolver.forVisionTasks(visionTasksBasePath)];
2689
+ case 5:
2690
+ return [4 /*yield*/, _b.apply(_a, [_c.sent(), {
2691
+ baseOptions: {
2692
+ modelAssetPath: modelAssetPath,
2693
+ delegate: delegate
2694
+ }
2695
+ }])];
2696
+ case 6:
2697
+ model = _c.sent();
2698
+ emptyFrame = document.createElement('canvas');
2699
+ model.segment(emptyFrame);
2700
+ emptyFrame.remove();
2701
+ return [2 /*return*/];
2702
+ }
2703
+ });
2704
+ });
2705
+ }
2706
+ function giveUpAfter(maxTime) {
2707
+ return new Promise(function (_resolve, reject) {
2708
+ setTimeout(function () {
2709
+ reject(new Error('gave up after reaching maximum time allowed'));
2710
+ }, maxTime);
2711
+ });
2712
+ }
2713
+
2714
+ function convertBoundingBox(box) {
2715
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2716
+ return {
2717
+ xMin: (_a = box === null || box === void 0 ? void 0 : box.originX) !== null && _a !== void 0 ? _a : 0,
2718
+ xMax: ((_b = box === null || box === void 0 ? void 0 : box.originX) !== null && _b !== void 0 ? _b : 0) + ((_c = box === null || box === void 0 ? void 0 : box.width) !== null && _c !== void 0 ? _c : 0),
2719
+ yMin: (_d = box === null || box === void 0 ? void 0 : box.originY) !== null && _d !== void 0 ? _d : 0,
2720
+ yMax: ((_e = box === null || box === void 0 ? void 0 : box.originY) !== null && _e !== void 0 ? _e : 0) + ((_f = box === null || box === void 0 ? void 0 : box.height) !== null && _f !== void 0 ? _f : 0),
2721
+ width: (_g = box === null || box === void 0 ? void 0 : box.width) !== null && _g !== void 0 ? _g : 0,
2722
+ height: (_h = box === null || box === void 0 ? void 0 : box.height) !== null && _h !== void 0 ? _h : 0
2723
+ };
2724
+ }
2725
+ function waitForVideoReady(videoRef, checkEveryMs) {
2726
+ if (checkEveryMs === void 0) {
2727
+ checkEveryMs = 100;
2728
+ }
2729
+ return new Promise(function (resolve) {
2730
+ var _a, _b, _c;
2731
+ if (((_b = (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.readyState) !== null && _b !== void 0 ? _b : 0) >= 2) return resolve();
2732
+ (_c = videoRef.current) === null || _c === void 0 ? void 0 : _c.load();
2733
+ var interval = setInterval(function () {
2734
+ var _a, _b;
2735
+ if (((_b = (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.readyState) !== null && _b !== void 0 ? _b : 0) >= 2) {
2736
+ clearInterval(interval);
2737
+ resolve();
2738
+ }
2739
+ }, checkEveryMs);
2740
+ });
2741
+ }
2742
+ function calculateIoU(boxA, boxB) {
2743
+ var xA = Math.max(boxA.xMin, boxB.xMin);
2744
+ var yA = Math.max(boxA.yMin, boxB.yMin);
2745
+ var xB = Math.min(boxA.xMax, boxB.xMax);
2746
+ var yB = Math.min(boxA.yMax, boxB.yMax);
2182
2747
  var intersectWidth = Math.max(0, xB - xA);
2183
2748
  var intersectHeight = Math.max(0, yB - yA);
2184
2749
  var intersectionArea = intersectWidth * intersectHeight;
@@ -2269,8 +2834,7 @@ function useLoadFocusModel(_a) {
2269
2834
  modelPath = _b === void 0 ? defaultFocusModelPath : _b,
2270
2835
  _c = _a.modelLoadTimeoutMs,
2271
2836
  modelLoadTimeoutMs = _c === void 0 ? defaultFocusModelLoadTimeoutMs : _c,
2272
- onModelError = _a.onModelError,
2273
- videoRef = _a.videoRef;
2837
+ onModelError = _a.onModelError;
2274
2838
  var _d = useState(false),
2275
2839
  ready = _d[0],
2276
2840
  setReady = _d[1];
@@ -2280,6 +2844,7 @@ function useLoadFocusModel(_a) {
2280
2844
  var _f = useState(null),
2281
2845
  modelError = _f[0],
2282
2846
  setModelError = _f[1];
2847
+ var videoRef = useContext(CameraStateContext).videoRef;
2283
2848
  useEffect(function loadModel() {
2284
2849
  var _this = this;
2285
2850
  setReady(false);
@@ -2417,8 +2982,7 @@ function closeFaceDetector() {
2417
2982
  function useLoadFaceDetector(_a) {
2418
2983
  var onModelError = _a.onModelError,
2419
2984
  _b = _a.modelLoadTimeoutMs,
2420
- modelLoadTimeoutMs = _b === void 0 ? defaultSelfieCaptureModelLoadTimeoutMs : _b,
2421
- videoRef = _a.videoRef;
2985
+ modelLoadTimeoutMs = _b === void 0 ? defaultSelfieCaptureModelLoadTimeoutMs : _b;
2422
2986
  var _c = useState(false),
2423
2987
  ready = _c[0],
2424
2988
  setReady = _c[1];
@@ -2428,6 +2992,7 @@ function useLoadFaceDetector(_a) {
2428
2992
  var _e = useState(null),
2429
2993
  modelError = _e[0],
2430
2994
  setModelError = _e[1];
2995
+ var videoRef = useContext(CameraStateContext).videoRef;
2431
2996
  useEffect(function loadModel() {
2432
2997
  var _this = this;
2433
2998
  setReady(false);
@@ -2908,8 +3473,7 @@ function useLoadDocumentDetector(_a) {
2908
3473
  modelLoadTimeoutMs = _c === void 0 ? defaultDocumentDetectionModelLoadTimeoutMs : _c,
2909
3474
  _d = _a.scoreThreshold,
2910
3475
  scoreThreshold = _d === void 0 ? defaultDocumentDetectionScoreThreshold : _d,
2911
- onModelError = _a.onModelError,
2912
- videoRef = _a.videoRef;
3476
+ onModelError = _a.onModelError;
2913
3477
  var _e = useState(false),
2914
3478
  ready = _e[0],
2915
3479
  setReady = _e[1];
@@ -2919,6 +3483,7 @@ function useLoadDocumentDetector(_a) {
2919
3483
  var _g = useState(null),
2920
3484
  modelError = _g[0],
2921
3485
  setModelError = _g[1];
3486
+ var videoRef = useContext(CameraStateContext).videoRef;
2922
3487
  useEffect(function loadModel() {
2923
3488
  var _this = this;
2924
3489
  setReady(false);
@@ -3139,582 +3704,92 @@ function processDocumentDetectorPrediction(prediction, thresholds, boundaries) {
3139
3704
  passportDetectionThresholdMet: passportDetectionThresholdMet,
3140
3705
  bestDocument: bestDocument,
3141
3706
  documentInBounds: documentInBounds,
3142
- documentTooClose: documentTooClose,
3143
- documentIsStable: documentIsStable,
3144
- frameWidth: frameWidth,
3145
- frameHeight: frameHeight,
3146
- allZero: allZero
3147
- };
3148
- }
3149
- function applyNonMaxSuppression(detectedObjects, isGoodBox) {
3150
- var maxes = {};
3151
- detectedObjects.forEach(function (obj, i) {
3152
- if (obj) {
3153
- if (!maxes[obj.label]) maxes[obj.label] = [0, -1];
3154
- if (obj.score > maxes[obj.label][0] && (isGoodBox === null || isGoodBox === void 0 ? void 0 : isGoodBox(obj))) maxes[obj.label] = [obj.score, i];
3155
- }
3156
- });
3157
- return Object.keys(maxes).map(function (label) {
3158
- return detectedObjects[maxes[label][1]];
3159
- }).filter(function (obj) {
3160
- return !!obj;
3161
- });
3162
- }
3163
-
3164
- function useFrameLoop(fn, _a) {
3165
- var _b = _a.throttleMs,
3166
- throttleMs = _b === void 0 ? 0 : _b,
3167
- _c = _a.autoStart,
3168
- autoStart = _c === void 0 ? false : _c;
3169
- var _d = useState(false),
3170
- running = _d[0],
3171
- setRunning = _d[1];
3172
- var startedAtRef = useRef(null);
3173
- var loopId = useRef(0);
3174
- var frameId = useRef(0);
3175
- useEffect(function runFrameLoop() {
3176
- if (!running) return;
3177
- var timer;
3178
- var currentLoopId = loopId.current;
3179
- function renderPrediction() {
3180
- return __awaiter(this, void 0, void 0, function () {
3181
- var start, timeRunning, took, amountToThrottle;
3182
- var _a, _b;
3183
- return __generator(this, function (_c) {
3184
- switch (_c.label) {
3185
- case 0:
3186
- if (currentLoopId !== loopId.current) return [2 /*return*/];
3187
- start = new Date().getTime();
3188
- timeRunning = start - ((_b = (_a = startedAtRef.current) === null || _a === void 0 ? void 0 : _a.getTime()) !== null && _b !== void 0 ? _b : 0);
3189
- return [4 /*yield*/, fn(frameId.current, timeRunning)];
3190
- case 1:
3191
- _c.sent();
3192
- took = new Date().getTime() - start;
3193
- amountToThrottle = Math.max((throttleMs !== null && throttleMs !== void 0 ? throttleMs : 0) - took, 0);
3194
- timer = setTimeout(function () {
3195
- frameId.current = requestAnimationFrame(renderPrediction);
3196
- }, amountToThrottle);
3197
- return [2 /*return*/];
3198
- }
3199
- });
3200
- });
3201
- }
3202
- renderPrediction().then();
3203
- return function () {
3204
- loopId.current += 1;
3205
- frameId.current && cancelAnimationFrame(frameId.current);
3206
- timer && clearTimeout(timer);
3207
- };
3208
- }, [fn, running, throttleMs]);
3209
- var start = useCallback(function () {
3210
- startedAtRef.current = new Date();
3211
- setRunning(true);
3212
- }, []);
3213
- var stop = useCallback(function () {
3214
- loopId.current += 1; // force the loop to stop immediately.
3215
- setRunning(false);
3216
- startedAtRef.current = null;
3217
- }, []);
3218
- useEffect(function startAutomatically() {
3219
- if (autoStart) start();
3220
- return function () {
3221
- stop();
3222
- };
3223
- }, [autoStart, start, stop]);
3224
- return {
3225
- start: start,
3226
- stop: stop
3227
- };
3228
- }
3229
-
3230
- function listAvailableCameras(facingMode_1) {
3231
- return __awaiter(this, arguments, void 0, function (facingMode, requestMicAccess) {
3232
- var cameraEnumerationStream, videoDevices;
3233
- if (requestMicAccess === void 0) {
3234
- requestMicAccess = false;
3235
- }
3236
- return __generator(this, function (_a) {
3237
- switch (_a.label) {
3238
- case 0:
3239
- return [4 /*yield*/, navigator.mediaDevices.getUserMedia({
3240
- video: {
3241
- facingMode: {
3242
- exact: facingMode
3243
- }
3244
- },
3245
- audio: requestMicAccess
3246
- })
3247
- // This lists all available cameras attached to the user's device.
3248
- ];
3249
- case 1:
3250
- cameraEnumerationStream = _a.sent();
3251
- return [4 /*yield*/, navigator.mediaDevices.enumerateDevices()];
3252
- case 2:
3253
- videoDevices = _a.sent().filter(function (_a) {
3254
- var kind = _a.kind;
3255
- return kind === 'videoinput';
3256
- });
3257
- // Release the access to the user's camera that we obtained for enumeration purposes.
3258
- cameraEnumerationStream.getVideoTracks().forEach(function (track) {
3259
- track.enabled = false;
3260
- track.stop();
3261
- });
3262
- cameraEnumerationStream = null;
3263
- return [2 /*return*/, videoDevices];
3264
- }
3265
- });
3266
- });
3267
- }
3268
- var frontCameraLabels = ['front', 'avant', 'anteriore', 'cameraaanvoorzijde', 'kamerapåframsidan', 'forsidekamera', 'kamerapåforsiden', 'aparatprzedni', 'etukamera', 'kameradepan', 'ÖnKamera', 'cameramặttrước', 'camerăfață', 'prednákamera', 'prednjakamera', 'előlapikamera', 'přednífotoaparát', 'μπροστινήκάμερα', 'переднякамера', 'передняякамера', 'преднакамера', 'алдыңғыкамера', 'מצלמה קדמית', 'الكاميرا الأمامية', 'फ़्रंटकैमरा', '前置相机', '前置鏡頭', '前面カメラ', '전면카메라', 'กล้องด้านหน้า'].map(function (s) {
3269
- return s.toLocaleLowerCase().split(' ').join('');
3270
- });
3271
- var rearCameraLabels = ['back', 'rear', 'posterior', 'trasera', 'traseira', 'arrière', 'rückkamera', 'fotocamera(posteriore)', 'cameraaanachterzijde', 'kamerapåbaksidan', 'kamerapåbaksiden', 'bagsidekamera', 'aparattylny', 'takakamera', 'arkakamera', 'kamerabelakang', 'cameramặtsau', 'camerăspate', 'stražnjakamera', 'zadnákamera', 'hátoldalikamera', 'zadnífotoaparát', 'πίσωκάμερα', 'заднякамера', 'Задняякамера', 'заднакамера', 'артқыкамера', 'מצלמה אחורית', 'الكاميرا الخلفية', 'बैककैमरा', '后置相机', '後置鏡頭', '背面カメラ', '후면카메라', 'กล้องด้านหลัง'].map(function (s) {
3272
- return s.toLocaleLowerCase().split(' ').join('');
3273
- });
3274
- var backUltraWideCameraLabels = ['backdualwidecamera', 'backultrawidecamera', 'ultraampliaposterior', 'ultra-angulartraseira', 'ultragrandeangulartraseira', 'ultragrandangle', 'ultragranangular', 'ultra-weitwinkelkamera', 'ultra-grandangolo', 'ultrabredecameraaanachterzijde', 'ultravidvinkelkamerapåbaksidan', 'ultravidvinkelkameraetpåbagsiden', 'ultravidvinkelkamerabak', 'ultragenişkameraarkayüzü', 'ultralaajakulmainentakakamera', 'tylnyaparatultraszerokokątny', 'cameracựcrộngmặtsau', 'camerăcuobiectivultra‑superangularspate', 'ultraszéleslátószögűkamera', 'kameraultralebarbelakang', 'stražnjaultraširokakamera', 'zadníultraširokoúhlýfotoaparát', 'ultraširokouhlá', 'πίσωυπερευρείακάμερα', 'заднянадширококутнакамера', 'Задняясверхширокоугольнаякамера', 'Задна свръх широкоъгълна камера', 'артқыультракеңбұрыштыкамера', 'מצלמה אולטרה רחבה אחורית', 'كاميرا خلفية عريضة جدًا', 'बैकअल्ट्रावाइडकैमरा', '后置超广角相机', '後置超廣角鏡頭相機', '背面超広角カメラ', '후면울트라와이드카메라', 'กล้องด้านหลังอัลตร้าไวด์'].map(function (s) {
3275
- return s.toLocaleLowerCase().split(' ').join('');
3276
- });
3277
- var cameraLabelMatches = function cameraLabelMatches(labelOrDevice, labelSetOrLabel) {
3278
- var label = labelOrDevice instanceof MediaDeviceInfo ? getDeviceLabel(labelOrDevice) : labelOrDevice;
3279
- var labelSet = typeof labelSetOrLabel === 'string' ? [labelSetOrLabel] : labelSetOrLabel;
3280
- return labelSet.some(function (l) {
3281
- return label.includes(l);
3282
- });
3283
- };
3284
- var getDeviceLabel = function getDeviceLabel(deviceInfo) {
3285
- return deviceInfo.label.toLocaleLowerCase().split(' ').join('');
3286
- };
3287
- var currentCamera;
3288
- function obtainCameraAccess(stream, deviceLabel, video) {
3289
- releaseCameraAccess();
3290
- log('obtaining camera access...');
3291
- var _a = stream.getVideoTracks()[0].getSettings(),
3292
- width = _a.width,
3293
- height = _a.height;
3294
- log('camera dimensions', width, height);
3295
- var label = deviceLabel.toLocaleLowerCase().split(' ').join('');
3296
- log('camera label', label);
3297
- var isRearFacing = cameraLabelMatches(label, __spreadArray(__spreadArray(__spreadArray([], rearCameraLabels, true), backUltraWideCameraLabels, true), ['iphone'], false));
3298
- log('is rear facing?', isRearFacing);
3299
- var release = function release() {
3300
- stream.getTracks().forEach(function (track) {
3301
- track.enabled = false;
3302
- track.stop();
3303
- });
3304
- if (video) {
3305
- video.pause();
3306
- video.srcObject = null;
3307
- video.src = '';
3308
- }
3309
- };
3310
- width || (width = 0);
3311
- height || (height = 0);
3312
- currentCamera = {
3313
- label: deviceLabel,
3314
- stream: stream,
3315
- width: width,
3316
- height: height,
3317
- isRearFacing: isRearFacing,
3318
- release: release
3319
- };
3320
- log('camera access granted');
3321
- if (video) video.srcObject = stream;
3322
- log('video source initialized');
3323
- return currentCamera;
3324
- }
3325
- function releaseCameraAccess() {
3326
- if (!currentCamera) return;
3327
- log('releasing camera access...');
3328
- currentCamera.release();
3329
- currentCamera = undefined;
3330
- }
3331
-
3332
- var initialState$5 = {
3333
- videoRef: {
3334
- current: null
3335
- },
3336
- videoLoaded: false,
3337
- videoStream: null,
3338
- videoDevice: null,
3339
- isRearFacing: false,
3340
- camera: null,
3341
- cameraReady: false,
3342
- cameraAccessDenied: false,
3343
- iphoneContinuityCameraAvailable: false,
3344
- iphoneContinuityCameraDenied: false,
3345
- preferIphoneContinuityCamera: true,
3346
- audioStream: null,
3347
- microphoneReady: false,
3348
- microphoneAccessDenied: false
3349
- };
3350
- var createCameraStore = function createCameraStore(config) {
3351
- var store = createStore(function (set, get) {
3352
- return _assign(_assign(_assign({}, initialState$5), config), {
3353
- reset: function reset() {
3354
- return set(_assign(_assign({}, initialState$5), config));
3355
- },
3356
- setConfig: function setConfig(config) {
3357
- return set(config);
3358
- },
3359
- onVideoMounted: function onVideoMounted() {
3360
- return set({
3361
- videoLoaded: true
3362
- });
3363
- },
3364
- setIphoneContinuityCameraAllowed: function setIphoneContinuityCameraAllowed(value) {
3365
- return set({
3366
- preferIphoneContinuityCamera: value
3367
- });
3368
- },
3369
- requestCameraAccess: function requestCameraAccess() {
3370
- return __awaiter(this, void 0, void 0, function () {
3371
- var _a, videoRef, releaseCameraAccess, preferFrontFacingCamera, preferIphoneContinuityCamera, iphoneContinuityCameraDenied, availableCameras, selectedCamera, platform_1, iphoneContinuityCamera, constraints, stream_1, e_1, handleStreamEnded_1, videoTrack_1, camera_1, e_3;
3372
- var _b, _c, _d;
3373
- return __generator(this, function (_e) {
3374
- switch (_e.label) {
3375
- case 0:
3376
- _a = get(), videoRef = _a.videoRef, releaseCameraAccess = _a.releaseCameraAccess, preferFrontFacingCamera = _a.preferFrontFacingCamera, preferIphoneContinuityCamera = _a.preferIphoneContinuityCamera, iphoneContinuityCameraDenied = _a.iphoneContinuityCameraDenied;
3377
- releaseCameraAccess();
3378
- _e.label = 1;
3379
- case 1:
3380
- _e.trys.push([1, 11,, 12]);
3381
- return [4 /*yield*/, listAvailableCameras()];
3382
- case 2:
3383
- availableCameras = _e.sent();
3384
- selectedCamera = void 0;
3385
- debug('availableCameras', availableCameras);
3386
- platform_1 = getPlatform();
3387
- debug('platformDetails', platform_1);
3388
- if (!iphoneContinuityCameraDenied && (!(platform_1 === null || platform_1 === void 0 ? void 0 : platform_1.os) || platform_1.os.family === 'OS X')) {
3389
- iphoneContinuityCamera = availableCameras.find(function (deviceInfo) {
3390
- return cameraLabelMatches(deviceInfo, 'iphone');
3391
- });
3392
- set({
3393
- iphoneContinuityCameraAvailable: !!iphoneContinuityCamera
3394
- });
3395
- if (iphoneContinuityCamera && preferIphoneContinuityCamera) {
3396
- selectedCamera = iphoneContinuityCamera;
3397
- }
3398
- } else if (((_b = platform_1 === null || platform_1 === void 0 ? void 0 : platform_1.os) === null || _b === void 0 ? void 0 : _b.family) === 'Android' || availableCameras.every(function (c) {
3399
- return c.label.startsWith('camera2 ');
3400
- })) {
3401
- availableCameras = availableCameras.sort(function (a, b) {
3402
- return a.label.toLowerCase().localeCompare(b.label.toLowerCase());
3403
- });
3404
- debug('cameras have been sorted', availableCameras);
3405
- }
3406
- if (preferFrontFacingCamera) {
3407
- selectedCamera = availableCameras.find(function (deviceInfo) {
3408
- return cameraLabelMatches(deviceInfo, frontCameraLabels);
3409
- });
3410
- }
3411
- selectedCamera || (selectedCamera = availableCameras.find(function (deviceInfo) {
3412
- return cameraLabelMatches(deviceInfo, 'backtriplecamera');
3413
- }));
3414
- selectedCamera || (selectedCamera = availableCameras.find(function (deviceInfo) {
3415
- return cameraLabelMatches(deviceInfo, 'backdualcamera');
3416
- }));
3417
- selectedCamera || (selectedCamera = availableCameras.find(function (deviceInfo) {
3418
- return cameraLabelMatches(deviceInfo, rearCameraLabels) && !cameraLabelMatches(deviceInfo, backUltraWideCameraLabels);
3419
- }));
3420
- selectedCamera || (selectedCamera = availableCameras.find(function (deviceInfo) {
3421
- return cameraLabelMatches(deviceInfo, rearCameraLabels);
3422
- }));
3423
- // on iOS, the front facing camera always is at the first position in the list, so we skip it if all else fails.
3424
- if (!preferFrontFacingCamera && ((_c = platform_1 === null || platform_1 === void 0 ? void 0 : platform_1.os) === null || _c === void 0 ? void 0 : _c.family) === 'iOS' && availableCameras.length > 0) {
3425
- selectedCamera || (selectedCamera = availableCameras[1]);
3426
- }
3427
- selectedCamera || (selectedCamera = availableCameras[0]);
3428
- debug('selectedCamera', selectedCamera);
3429
- set({
3430
- videoDevice: selectedCamera
3431
- });
3432
- constraints = {
3433
- audio: false,
3434
- video: {
3435
- deviceId: {
3436
- exact: selectedCamera.deviceId
3437
- },
3438
- width: {
3439
- ideal: config.maxVideoWidth
3440
- },
3441
- aspectRatio: 1.777777778,
3442
- frameRate: {}
3443
- }
3444
- };
3445
- if (config.maxFps) {
3446
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3447
- // @ts-ignore
3448
- constraints.video.frameRate = {
3449
- max: config.maxFps
3450
- };
3451
- }
3452
- stream_1 = null;
3453
- _e.label = 3;
3454
- case 3:
3455
- _e.trys.push([3, 5,, 6]);
3456
- debug('obtaining camera access with constraints', constraints);
3457
- return [4 /*yield*/, navigator.mediaDevices.getUserMedia(constraints)];
3458
- case 4:
3459
- stream_1 = _e.sent();
3460
- return [3 /*break*/, 6];
3461
- case 5:
3462
- e_1 = _e.sent();
3463
- if (e_1.name === 'NotAllowedError') {
3464
- if (preferIphoneContinuityCamera) {
3465
- set({
3466
- iphoneContinuityCameraAvailable: false,
3467
- iphoneContinuityCameraDenied: true
3468
- });
3469
- } else {
3470
- set({
3471
- cameraAccessDenied: true
3472
- });
3473
- }
3474
- return [2 /*return*/];
3475
- }
3476
- return [3 /*break*/, 6];
3477
- case 6:
3478
- if (!!stream_1) return [3 /*break*/, 10];
3479
- _e.label = 7;
3480
- case 7:
3481
- _e.trys.push([7, 9,, 10]);
3482
- return [4 /*yield*/, navigator.mediaDevices.getUserMedia({
3483
- audio: false,
3484
- video: true
3485
- })];
3486
- case 8:
3487
- stream_1 = _e.sent();
3488
- debug('opened stream with no width and height constraints');
3489
- return [3 /*break*/, 10];
3490
- case 9:
3491
- _e.sent();
3492
- debug('cannot open stream at all');
3493
- return [3 /*break*/, 10];
3494
- case 10:
3495
- if (!stream_1) {
3496
- error('failed to open camera');
3497
- throw new Error('failed to open camera');
3498
- }
3499
- debug('camera access granted with constraints', constraints);
3500
- handleStreamEnded_1 = function handleStreamEnded_1() {
3501
- if (preferIphoneContinuityCamera && get().iphoneContinuityCameraAvailable) {
3502
- debug('someone unplugged the continuity camera');
3503
- set({
3504
- videoStream: null,
3505
- videoDevice: null,
3506
- cameraReady: false,
3507
- iphoneContinuityCameraAvailable: false,
3508
- iphoneContinuityCameraDenied: true
3509
- });
3510
- get().requestCameraAccess();
3511
- } else {
3512
- debug('someone unplugged the webcam');
3513
- releaseCameraAccess();
3514
- set({
3515
- videoStream: null,
3516
- videoDevice: null,
3517
- videoLoaded: false,
3518
- cameraReady: false,
3519
- cameraAccessDenied: true
3520
- });
3521
- }
3522
- };
3523
- (_d = videoRef.current) === null || _d === void 0 ? void 0 : _d.addEventListener('ended', handleStreamEnded_1);
3524
- videoTrack_1 = stream_1.getVideoTracks()[0];
3525
- videoTrack_1.onended = handleStreamEnded_1;
3526
- camera_1 = obtainCameraAccess(stream_1, selectedCamera.label, videoRef.current);
3527
- setTimeout(function () {
3528
- // iOS 17 has a strange behavior where the video track flickers between muted and unmuted
3529
- // when the camera access is being requested. This delay is a workaround for that.
3530
- videoTrack_1.onmute = handleStreamEnded_1;
3531
- set({
3532
- camera: camera_1,
3533
- cameraReady: true,
3534
- cameraAccessDenied: false,
3535
- isRearFacing: camera_1.isRearFacing,
3536
- videoStream: stream_1
3537
- });
3538
- }, 500);
3539
- return [3 /*break*/, 12];
3540
- case 11:
3541
- e_3 = _e.sent();
3542
- if (e_3.name === 'NotAllowedError') {
3543
- error('camera access has been blocked by the user', e_3);
3544
- set({
3545
- cameraAccessDenied: true
3546
- });
3547
- } else {
3548
- error('camera access encountered some other error', e_3);
3549
- throw e_3;
3550
- }
3551
- return [3 /*break*/, 12];
3552
- case 12:
3553
- return [2 /*return*/];
3554
- }
3555
- });
3556
- });
3557
- },
3558
- releaseCameraAccess: function releaseCameraAccess() {
3559
- return __awaiter(this, void 0, void 0, function () {
3560
- var camera;
3561
- return __generator(this, function (_a) {
3562
- camera = get().camera;
3563
- if (!camera) return [2 /*return*/];
3564
- camera.release();
3565
- set({
3566
- camera: null,
3567
- cameraReady: false,
3568
- cameraAccessDenied: false
3569
- });
3570
- return [2 /*return*/];
3571
- });
3572
- });
3573
- },
3574
- requestMicrophoneAccess: function requestMicrophoneAccess() {
3575
- return __awaiter(this, void 0, void 0, function () {
3576
- var stream_2;
3577
- return __generator(this, function (_a) {
3578
- switch (_a.label) {
3579
- case 0:
3580
- get().releaseMicrophoneAccess();
3581
- _a.label = 1;
3582
- case 1:
3583
- _a.trys.push([1, 3,, 4]);
3584
- return [4 /*yield*/, navigator.mediaDevices.getUserMedia({
3585
- audio: true,
3586
- video: false
3587
- })
3588
- // iOS 17 has a strange behavior where the video track flickers between muted and unmuted
3589
- // when the camera access is being requested. This delay is a workaround for that.
3590
- ];
3591
- case 2:
3592
- stream_2 = _a.sent();
3593
- // iOS 17 has a strange behavior where the video track flickers between muted and unmuted
3594
- // when the camera access is being requested. This delay is a workaround for that.
3595
- setTimeout(function () {
3596
- set({
3597
- audioStream: stream_2,
3598
- microphoneReady: true,
3599
- microphoneAccessDenied: false
3600
- });
3601
- var track = stream_2.getAudioTracks()[0];
3602
- track.onended = function () {
3603
- return set({
3604
- microphoneReady: false,
3605
- microphoneAccessDenied: true
3606
- });
3607
- };
3608
- track.onmute = function () {
3609
- return set({
3610
- microphoneReady: false,
3611
- microphoneAccessDenied: true
3612
- });
3613
- };
3614
- }, 500);
3615
- return [3 /*break*/, 4];
3616
- case 3:
3617
- _a.sent();
3618
- set({
3619
- microphoneAccessDenied: true
3620
- });
3621
- return [3 /*break*/, 4];
3622
- case 4:
3623
- return [2 /*return*/];
3624
- }
3625
- });
3626
- });
3627
- },
3628
- releaseMicrophoneAccess: function releaseMicrophoneAccess() {
3629
- var _a;
3630
- var audioStream = get().audioStream;
3631
- (_a = audioStream === null || audioStream === void 0 ? void 0 : audioStream.stop) === null || _a === void 0 ? void 0 : _a.call(audioStream);
3632
- audioStream === null || audioStream === void 0 ? void 0 : audioStream.getAudioTracks().forEach(function (track) {
3633
- var _a;
3634
- (_a = track.stop) === null || _a === void 0 ? void 0 : _a.call(track);
3635
- });
3636
- set({
3637
- audioStream: null,
3638
- microphoneReady: false,
3639
- microphoneAccessDenied: false
3640
- });
3641
- }
3642
- });
3643
- });
3644
- if (config.requestAccessAutomatically) {
3645
- void store.getState().requestCameraAccess();
3646
- }
3647
- return _assign(_assign({}, store), {
3648
- destroy: function destroy() {
3649
- store.getState().releaseCameraAccess();
3650
- store.getState().releaseMicrophoneAccess();
3707
+ documentTooClose: documentTooClose,
3708
+ documentIsStable: documentIsStable,
3709
+ frameWidth: frameWidth,
3710
+ frameHeight: frameHeight,
3711
+ allZero: allZero
3712
+ };
3713
+ }
3714
+ function applyNonMaxSuppression(detectedObjects, isGoodBox) {
3715
+ var maxes = {};
3716
+ detectedObjects.forEach(function (obj, i) {
3717
+ if (obj) {
3718
+ if (!maxes[obj.label]) maxes[obj.label] = [0, -1];
3719
+ if (obj.score > maxes[obj.label][0] && (isGoodBox === null || isGoodBox === void 0 ? void 0 : isGoodBox(obj))) maxes[obj.label] = [obj.score, i];
3651
3720
  }
3652
3721
  });
3653
- };
3654
- var CameraStoreContext = /*#__PURE__*/createContext(undefined);
3655
- function CameraStoreProvider(_a) {
3656
- var children = _a.children,
3657
- _b = _a.requestAccessAutomatically,
3658
- requestAccessAutomatically = _b === void 0 ? true : _b,
3659
- _c = _a.preferIphoneContinuityCamera,
3660
- preferIphoneContinuityCamera = _c === void 0 ? true : _c,
3661
- _d = _a.preferFrontFacingCamera,
3662
- preferFrontFacingCamera = _d === void 0 ? false : _d,
3663
- _e = _a.maxVideoWidth,
3664
- maxVideoWidth = _e === void 0 ? 1920 : _e,
3665
- maxFps = _a.maxFps,
3666
- onCameraAccessDenied = _a.onCameraAccessDenied,
3667
- onMicrophoneAccessDenied = _a.onMicrophoneAccessDenied,
3668
- _f = _a.requireMicrophoneAccess,
3669
- requireMicrophoneAccess = _f === void 0 ? false : _f;
3670
- var videoRef = useRef(null);
3671
- var store = useRef();
3672
- store.current || (store.current = createCameraStore({
3673
- videoRef: videoRef,
3674
- requestAccessAutomatically: requestAccessAutomatically,
3675
- preferIphoneContinuityCamera: preferIphoneContinuityCamera,
3676
- preferFrontFacingCamera: preferFrontFacingCamera,
3677
- maxVideoWidth: maxVideoWidth,
3678
- maxFps: maxFps,
3679
- onCameraAccessDenied: onCameraAccessDenied,
3680
- onMicrophoneAccessDenied: onMicrophoneAccessDenied,
3681
- requireMicrophoneAccess: requireMicrophoneAccess
3682
- }));
3683
- useEffect(function () {
3684
- var _a, _b, _c;
3685
- var state = (_a = store.current) === null || _a === void 0 ? void 0 : _a.getState();
3686
- if (!state) return;
3687
- if (preferIphoneContinuityCamera !== (state === null || state === void 0 ? void 0 : state.preferIphoneContinuityCamera) || preferFrontFacingCamera !== (state === null || state === void 0 ? void 0 : state.preferFrontFacingCamera)) {
3688
- (_b = store.current) === null || _b === void 0 ? void 0 : _b.setState({
3689
- preferIphoneContinuityCamera: preferIphoneContinuityCamera,
3690
- preferFrontFacingCamera: preferFrontFacingCamera
3722
+ return Object.keys(maxes).map(function (label) {
3723
+ return detectedObjects[maxes[label][1]];
3724
+ }).filter(function (obj) {
3725
+ return !!obj;
3726
+ });
3727
+ }
3728
+
3729
+ function useFrameLoop(fn, _a) {
3730
+ var _b = _a.throttleMs,
3731
+ throttleMs = _b === void 0 ? 0 : _b,
3732
+ _c = _a.autoStart,
3733
+ autoStart = _c === void 0 ? false : _c;
3734
+ var _d = useState(false),
3735
+ running = _d[0],
3736
+ setRunning = _d[1];
3737
+ var startedAtRef = useRef(null);
3738
+ var loopId = useRef(0);
3739
+ var frameId = useRef(0);
3740
+ useEffect(function runFrameLoop() {
3741
+ if (!running) return;
3742
+ var timer;
3743
+ var currentLoopId = loopId.current;
3744
+ function renderPrediction() {
3745
+ return __awaiter(this, void 0, void 0, function () {
3746
+ var start, timeRunning, took, amountToThrottle;
3747
+ var _a, _b;
3748
+ return __generator(this, function (_c) {
3749
+ switch (_c.label) {
3750
+ case 0:
3751
+ if (currentLoopId !== loopId.current) return [2 /*return*/];
3752
+ start = new Date().getTime();
3753
+ timeRunning = start - ((_b = (_a = startedAtRef.current) === null || _a === void 0 ? void 0 : _a.getTime()) !== null && _b !== void 0 ? _b : 0);
3754
+ return [4 /*yield*/, fn(frameId.current, timeRunning)];
3755
+ case 1:
3756
+ _c.sent();
3757
+ took = new Date().getTime() - start;
3758
+ amountToThrottle = Math.max((throttleMs !== null && throttleMs !== void 0 ? throttleMs : 0) - took, 0);
3759
+ timer = setTimeout(function () {
3760
+ frameId.current = requestAnimationFrame(renderPrediction);
3761
+ }, amountToThrottle);
3762
+ return [2 /*return*/];
3763
+ }
3764
+ });
3691
3765
  });
3692
- (_c = store.current) === null || _c === void 0 ? void 0 : _c.getState().requestCameraAccess();
3693
3766
  }
3694
- }, [preferFrontFacingCamera, preferIphoneContinuityCamera]);
3695
- useEffect(function () {
3696
- var _a;
3697
- if (!requireMicrophoneAccess) return;
3698
- (_a = store.current) === null || _a === void 0 ? void 0 : _a.getState().requestMicrophoneAccess();
3767
+ renderPrediction().then();
3699
3768
  return function () {
3700
- var _a;
3701
- return (_a = store.current) === null || _a === void 0 ? void 0 : _a.getState().releaseMicrophoneAccess();
3769
+ loopId.current += 1;
3770
+ frameId.current && cancelAnimationFrame(frameId.current);
3771
+ timer && clearTimeout(timer);
3702
3772
  };
3703
- }, [requireMicrophoneAccess]);
3704
- useEffect(function () {
3773
+ }, [fn, running, throttleMs]);
3774
+ var start = useCallback(function () {
3775
+ startedAtRef.current = new Date();
3776
+ setRunning(true);
3777
+ }, []);
3778
+ var stop = useCallback(function () {
3779
+ loopId.current += 1; // force the loop to stop immediately.
3780
+ setRunning(false);
3781
+ startedAtRef.current = null;
3782
+ }, []);
3783
+ useEffect(function startAutomatically() {
3784
+ if (autoStart) start();
3705
3785
  return function () {
3706
- var _a;
3707
- return (_a = store.current) === null || _a === void 0 ? void 0 : _a.destroy();
3786
+ stop();
3708
3787
  };
3709
- }, []);
3710
- return /*#__PURE__*/React__default.createElement(CameraStoreContext.Provider, {
3711
- value: store.current
3712
- }, children);
3713
- }
3714
- function useCameraStore(selector) {
3715
- var store = useContext(CameraStoreContext);
3716
- if (!store) throw new Error('useCameraStore cannot be used without Provider');
3717
- return useStore(store, selector);
3788
+ }, [autoStart, start, stop]);
3789
+ return {
3790
+ start: start,
3791
+ stop: stop
3792
+ };
3718
3793
  }
3719
3794
 
3720
3795
  var DocumentDetectionModelContext = /*#__PURE__*/createContext({
@@ -3762,7 +3837,7 @@ function DocumentDetectionModelProvider(_a) {
3762
3837
  _g = _a.documentDetectionModelLoadTimeoutMs,
3763
3838
  documentDetectionModelLoadTimeoutMs = _g === void 0 ? defaultDocumentDetectionModelLoadTimeoutMs : _g,
3764
3839
  onDocumentDetectionModelError = _a.onDocumentDetectionModelError;
3765
- var _h = useCameraStore(),
3840
+ var _h = useContext(CameraStateContext),
3766
3841
  videoRef = _h.videoRef,
3767
3842
  videoLoaded = _h.videoLoaded,
3768
3843
  cameraReady = _h.cameraReady;
@@ -3785,8 +3860,7 @@ function DocumentDetectionModelProvider(_a) {
3785
3860
  modelPath: documentDetectionModelPath,
3786
3861
  modelLoadTimeoutMs: documentDetectionModelLoadTimeoutMs,
3787
3862
  scoreThreshold: documentDetectionModelScoreThreshold,
3788
- onModelError: onDocumentDetectionModelError,
3789
- videoRef: videoRef
3863
+ onModelError: onDocumentDetectionModelError
3790
3864
  }),
3791
3865
  ready = _o.ready,
3792
3866
  modelDownloadProgress = _o.modelDownloadProgress,
@@ -3903,12 +3977,10 @@ function FocusModelProvider(_a) {
3903
3977
  var _e = useState({}),
3904
3978
  focusThresholds = _e[0],
3905
3979
  setFocusThresholds = _e[1];
3906
- var videoRef = useCameraStore().videoRef;
3907
3980
  var _f = useLoadFocusModel({
3908
3981
  modelPath: focusModelPath,
3909
3982
  modelLoadTimeoutMs: focusModelLoadTimeoutMs,
3910
- onModelError: onFocusModelError,
3911
- videoRef: videoRef
3983
+ onModelError: onFocusModelError
3912
3984
  }),
3913
3985
  ready = _f.ready,
3914
3986
  modelDownloadProgress = _f.modelDownloadProgress,
@@ -5030,33 +5102,31 @@ var Button = styled(LoaderButton)(templateObject_5$b || (templateObject_5$b = __
5030
5102
  var templateObject_1$D, templateObject_2$w, templateObject_3$o, templateObject_4$i, templateObject_5$b;
5031
5103
 
5032
5104
  var IdCapture = function IdCapture(_a) {
5033
- var _b, _c, _d, _e, _f, _g, _h;
5105
+ var _b, _c, _d, _e, _f, _g, _h, _j;
5034
5106
  var requiredDocumentType = _a.requiredDocumentType,
5035
- _j = _a.thresholds,
5036
- thresholds = _j === void 0 ? defaultIdCaptureThresholds : _j,
5107
+ _k = _a.thresholds,
5108
+ thresholds = _k === void 0 ? defaultIdCaptureThresholds : _k,
5037
5109
  guidanceMessage = _a.guidanceMessage,
5038
5110
  guidanceSatisfied = _a.guidanceSatisfied,
5039
5111
  onCapture = _a.onCapture,
5040
- _k = _a.classNames,
5041
- classNames = _k === void 0 ? {} : _k,
5042
- _l = _a.colors,
5043
- colors = _l === void 0 ? {} : _l,
5044
- _m = _a.verbiage,
5045
- rawVerbiage = _m === void 0 ? {} : _m,
5046
- _o = _a.debugMode,
5047
- debugMode = _o === void 0 ? false : _o;
5048
- var _p = useResizeObserver(),
5049
- ref = _p.ref,
5050
- _q = _p.width,
5051
- width = _q === void 0 ? 1 : _q,
5052
- _r = _p.height,
5053
- height = _r === void 0 ? 1 : _r;
5054
- var _s = useIdCaptureState(),
5055
- state = _s[0],
5056
- dispatch = _s[1];
5057
- var _t = useCameraStore(),
5058
- camera = _t.camera,
5059
- isRearFacing = _t.isRearFacing;
5112
+ _l = _a.classNames,
5113
+ classNames = _l === void 0 ? {} : _l,
5114
+ _m = _a.colors,
5115
+ colors = _m === void 0 ? {} : _m,
5116
+ _o = _a.verbiage,
5117
+ rawVerbiage = _o === void 0 ? {} : _o,
5118
+ _p = _a.debugMode,
5119
+ debugMode = _p === void 0 ? false : _p;
5120
+ var _q = useResizeObserver(),
5121
+ ref = _q.ref,
5122
+ _r = _q.width,
5123
+ width = _r === void 0 ? 1 : _r,
5124
+ _s = _q.height,
5125
+ height = _s === void 0 ? 1 : _s;
5126
+ var _t = useIdCaptureState(),
5127
+ state = _t[0],
5128
+ dispatch = _t[1];
5129
+ var cameraRef = useContext(CameraStateContext).cameraRef;
5060
5130
  var _u = useContext(IdCaptureModelsContext),
5061
5131
  modelsReady = _u.ready,
5062
5132
  setThresholds = _u.setThresholds,
@@ -5168,16 +5238,17 @@ var IdCapture = function IdCapture(_a) {
5168
5238
  classNames: classNames.overrideWrongDocumentTypeGuidanceDialog,
5169
5239
  verbiage: rawVerbiage.overrideWrongDocumentTypeGuidanceDialog
5170
5240
  }))), debugMode && ( /*#__PURE__*/React__default.createElement(DebugBoundingBoxOverlay, {
5171
- "$flipX": !isRearFacing,
5241
+ "$flipX": !((_j = cameraRef.current) === null || _j === void 0 ? void 0 : _j.isRearFacing),
5172
5242
  scaling: debugScalingDetails
5173
5243
  }, state.detectedObjects.map(function (obj, i) {
5244
+ var _a;
5174
5245
  return /*#__PURE__*/React__default.createElement(IdCaptureDetectedObjectDebugBox, {
5175
5246
  key: i,
5176
5247
  obj: obj,
5177
5248
  scaling: debugScalingDetails,
5178
- flipX: !isRearFacing
5249
+ flipX: !((_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.isRearFacing)
5179
5250
  });
5180
- }))), debugMode && ( /*#__PURE__*/React__default.createElement(DebugStatsPane, null, camera ? ( /*#__PURE__*/React__default.createElement(React__default.Fragment, null, "\u2705 Camera: ", camera.label, " (", camera.width, "x", camera.height, ")")) : '❌ Camera not ready', /*#__PURE__*/React__default.createElement("br", null), state.frameCaptureRate > 0.75 ? '✅' : '👎', " Frame Rate:", ' ', Math.round((state.frameCaptureRate + Number.EPSILON) * 1000) / 1000, ' ', "fps (", detectionTime, "ms doc detect, ", focusPredictionTime, "ms focus)", /*#__PURE__*/React__default.createElement("br", null), modelsReady ? ( /*#__PURE__*/React__default.createElement(React__default.Fragment, null, state.detectionThresholdMet ? '✅' : '❌', " Detected Document Type: ", state.detectedDocumentType, /*#__PURE__*/React__default.createElement("br", null), state.idCardFrontDetectionThresholdMet ? '✅' : '❌', " ID Card Front Score: ", state.idCardFrontDetectionScore.toFixed(3), /*#__PURE__*/React__default.createElement("br", null), state.idCardBackDetectionThresholdMet ? '✅' : '❌', " ID Card Back Score: ", state.idCardBackDetectionScore.toFixed(3), /*#__PURE__*/React__default.createElement("br", null), state.passportDetectionThresholdMet ? '✅' : '❌', " Passport Score: ", state.passportDetectionScore.toFixed(3), /*#__PURE__*/React__default.createElement("br", null), state.focusThresholdMet ? '✅' : '❌', " Focus Score:", ' ', state.focusScore.toFixed(3), /*#__PURE__*/React__default.createElement("br", null), state.documentInBounds ? '✅' : '❌', " Document In Bounds", /*#__PURE__*/React__default.createElement("br", null), state.documentIsStable ? '✅' : '❌', " Document Is Stable", /*#__PURE__*/React__default.createElement("br", null), state.goodFramesThresholdMet ? '✅' : '❌', " Good Frame Count:", ' ', state.goodFramesCount, "/", state.goodFramesThreshold)) : ( /*#__PURE__*/React__default.createElement(React__default.Fragment, null, "\u274C Models not ready")))));
5251
+ }))), debugMode && ( /*#__PURE__*/React__default.createElement(DebugStatsPane, null, cameraRef.current ? ( /*#__PURE__*/React__default.createElement(React__default.Fragment, null, "\u2705 Camera: ", cameraRef.current.label, " (", cameraRef.current.width, "x", cameraRef.current.height, ")")) : '❌ Camera not ready', /*#__PURE__*/React__default.createElement("br", null), state.frameCaptureRate > 0.75 ? '✅' : '👎', " Frame Rate:", ' ', Math.round((state.frameCaptureRate + Number.EPSILON) * 1000) / 1000, ' ', "fps (", detectionTime, "ms doc detect, ", focusPredictionTime, "ms focus)", /*#__PURE__*/React__default.createElement("br", null), modelsReady ? ( /*#__PURE__*/React__default.createElement(React__default.Fragment, null, state.detectionThresholdMet ? '✅' : '❌', " Detected Document Type: ", state.detectedDocumentType, /*#__PURE__*/React__default.createElement("br", null), state.idCardFrontDetectionThresholdMet ? '✅' : '❌', " ID Card Front Score: ", state.idCardFrontDetectionScore.toFixed(3), /*#__PURE__*/React__default.createElement("br", null), state.idCardBackDetectionThresholdMet ? '✅' : '❌', " ID Card Back Score: ", state.idCardBackDetectionScore.toFixed(3), /*#__PURE__*/React__default.createElement("br", null), state.passportDetectionThresholdMet ? '✅' : '❌', " Passport Score: ", state.passportDetectionScore.toFixed(3), /*#__PURE__*/React__default.createElement("br", null), state.focusThresholdMet ? '✅' : '❌', " Focus Score:", ' ', state.focusScore.toFixed(3), /*#__PURE__*/React__default.createElement("br", null), state.documentInBounds ? '✅' : '❌', " Document In Bounds", /*#__PURE__*/React__default.createElement("br", null), state.documentIsStable ? '✅' : '❌', " Document Is Stable", /*#__PURE__*/React__default.createElement("br", null), state.goodFramesThresholdMet ? '✅' : '❌', " Good Frame Count:", ' ', state.goodFramesCount, "/", state.goodFramesThreshold)) : ( /*#__PURE__*/React__default.createElement(React__default.Fragment, null, "\u274C Models not ready")))));
5181
5252
  };
5182
5253
  var timeSince = function timeSince(t) {
5183
5254
  if (!t) return 0;
@@ -5194,9 +5265,7 @@ var CameraAccessDeniedOverlay = function CameraAccessDeniedOverlay(_a) {
5194
5265
  colors = _e === void 0 ? {} : _e,
5195
5266
  _f = _a.verbiage,
5196
5267
  rawVerbiage = _f === void 0 ? {} : _f;
5197
- var requestCameraAccess = useCameraStore(function (state) {
5198
- return state.requestCameraAccess;
5199
- });
5268
+ var requestCameraAccess = useContext(CameraStateContext).requestCameraAccess;
5200
5269
  assets.imageUrl || (assets.imageUrl = DEFAULT_CDN_URL + '/camera-disable-icon.png');
5201
5270
  var verbiage = useTranslations(rawVerbiage, {
5202
5271
  headingText: 'Your camera permission is disabled',
@@ -5844,7 +5913,7 @@ var IdCaptureLoadingOverlayDefault = function IdCaptureLoadingOverlayDefault(_a)
5844
5913
  var _o = useContext(IdCaptureModelsContext),
5845
5914
  modelsReady = _o.ready,
5846
5915
  modelDownloadProgress = _o.modelDownloadProgress;
5847
- var _p = useCameraStore(),
5916
+ var _p = useContext(CameraStateContext),
5848
5917
  cameraReady = _p.cameraReady,
5849
5918
  cameraAccessDenied = _p.cameraAccessDenied,
5850
5919
  iphoneContinuityCameraAvailable = _p.iphoneContinuityCameraAvailable,
@@ -6042,14 +6111,7 @@ var IdCaptureLoadingOverlayLegacy = function IdCaptureLoadingOverlayLegacy(_a) {
6042
6111
  var _l = useContext(IdCaptureModelsContext),
6043
6112
  modelsReady = _l.ready,
6044
6113
  modelDownloadProgress = _l.modelDownloadProgress;
6045
- var _m = useCameraStore(useShallow(function (state) {
6046
- return {
6047
- cameraReady: state.cameraReady,
6048
- cameraAccessDenied: state.cameraAccessDenied,
6049
- iphoneContinuityCameraAvailable: state.iphoneContinuityCameraAvailable,
6050
- setIphoneContinuityCameraAllowed: state.setIphoneContinuityCameraAllowed
6051
- };
6052
- })),
6114
+ var _m = useContext(CameraStateContext),
6053
6115
  cameraReady = _m.cameraReady,
6054
6116
  cameraAccessDenied = _m.cameraAccessDenied,
6055
6117
  iphoneContinuityCameraAvailable = _m.iphoneContinuityCameraAvailable,
@@ -6595,24 +6657,23 @@ function getOrientation(allowPortraitOnMobile) {
6595
6657
  }
6596
6658
 
6597
6659
  var IdVideoCaptureFlipIdPrompt = function IdVideoCaptureFlipIdPrompt(_a) {
6598
- var _b = _a.idCaptureGuideImages,
6599
- idCaptureGuideImages = _b === void 0 ? defaultIdCaptureGuideImages : _b,
6600
- _c = _a.classNames,
6601
- classNames = _c === void 0 ? {} : _c,
6660
+ var _b;
6661
+ var _c = _a.idCaptureGuideImages,
6662
+ idCaptureGuideImages = _c === void 0 ? defaultIdCaptureGuideImages : _c,
6663
+ _d = _a.classNames,
6664
+ classNames = _d === void 0 ? {} : _d,
6602
6665
  borderWidth = _a.borderWidth,
6603
6666
  borderColor = _a.borderColor,
6604
6667
  borderRadius = _a.borderRadius,
6605
6668
  imageStyle = _a.imageStyle;
6606
- var isRearFacing = useCameraStore(function (state) {
6607
- return state.isRearFacing;
6608
- });
6609
- var isMirrored = !isRearFacing;
6610
- var _d = useState(1),
6611
- transitionTime = _d[0],
6612
- setTransitionTime = _d[1];
6613
- var _e = useState(0),
6614
- rotationAngle = _e[0],
6615
- setRotationAngle = _e[1];
6669
+ var cameraRef = useContext(CameraStateContext).cameraRef;
6670
+ var isMirrored = !((_b = cameraRef.current) === null || _b === void 0 ? void 0 : _b.isRearFacing);
6671
+ var _e = useState(1),
6672
+ transitionTime = _e[0],
6673
+ setTransitionTime = _e[1];
6674
+ var _f = useState(0),
6675
+ rotationAngle = _f[0],
6676
+ setRotationAngle = _f[1];
6616
6677
  var frontTransforms = ["rotateY(".concat(rotationAngle, "deg)")];
6617
6678
  if (isMirrored) frontTransforms.push('scaleX(-1)');
6618
6679
  var backTransforms = ["rotateY(".concat(180 - rotationAngle, "deg)")];
@@ -7136,30 +7197,29 @@ var Canvas$1 = styled.canvas(templateObject_2$n || (templateObject_2$n = __makeT
7136
7197
  var templateObject_1$r, templateObject_2$n;
7137
7198
 
7138
7199
  function IdCaptureGuides(_a) {
7139
- var _b = _a.guideType,
7140
- guideType = _b === void 0 ? 'fit' : _b,
7141
- _c = _a.status,
7142
- status = _c === void 0 ? 'ready' : _c,
7143
- _d = _a.progress,
7144
- progress = _d === void 0 ? 0 : _d,
7145
- _e = _a.portraitGuidesOnMobile,
7146
- portraitGuidesOnMobile = _e === void 0 ? true : _e,
7147
- _f = _a.requestedAction,
7148
- requestedAction = _f === void 0 ? 'SHOW_ID_FRONT' : _f,
7149
- _g = _a.isBackToFront,
7150
- isBackToFront = _g === void 0 ? false : _g,
7151
- _h = _a.images,
7152
- images = _h === void 0 ? defaultIdCaptureGuideImages : _h,
7153
- _j = _a.classNames,
7154
- classNames = _j === void 0 ? {} : _j,
7155
- _k = _a.colors,
7156
- colors = _k === void 0 ? {} : _k,
7157
- _l = _a.verbiage,
7158
- rawVerbiage = _l === void 0 ? {} : _l;
7200
+ var _b, _c;
7201
+ var _d = _a.guideType,
7202
+ guideType = _d === void 0 ? 'fit' : _d,
7203
+ _e = _a.status,
7204
+ status = _e === void 0 ? 'ready' : _e,
7205
+ _f = _a.progress,
7206
+ progress = _f === void 0 ? 0 : _f,
7207
+ _g = _a.portraitGuidesOnMobile,
7208
+ portraitGuidesOnMobile = _g === void 0 ? true : _g,
7209
+ _h = _a.requestedAction,
7210
+ requestedAction = _h === void 0 ? 'SHOW_ID_FRONT' : _h,
7211
+ _j = _a.isBackToFront,
7212
+ isBackToFront = _j === void 0 ? false : _j,
7213
+ _k = _a.images,
7214
+ images = _k === void 0 ? defaultIdCaptureGuideImages : _k,
7215
+ _l = _a.classNames,
7216
+ classNames = _l === void 0 ? {} : _l,
7217
+ _m = _a.colors,
7218
+ colors = _m === void 0 ? {} : _m,
7219
+ _o = _a.verbiage,
7220
+ rawVerbiage = _o === void 0 ? {} : _o;
7159
7221
  var state = useIdCaptureState()[0];
7160
- var isRearFacing = useCameraStore(function (state) {
7161
- return state.isRearFacing;
7162
- });
7222
+ var cameraRef = useContext(CameraStateContext).cameraRef;
7163
7223
  var verbiage = useTranslations(rawVerbiage, {
7164
7224
  instructionText: 'Scan the front of ID',
7165
7225
  capturingText: 'Capturing...',
@@ -7171,7 +7231,7 @@ function IdCaptureGuides(_a) {
7171
7231
  status: status,
7172
7232
  progress: progress,
7173
7233
  instruction: state.captureFailed ? verbiage.captureFailedText : state.capturing ? verbiage === null || verbiage === void 0 ? void 0 : verbiage.capturingText : verbiage.instructionText,
7174
- isMirrored: !isRearFacing,
7234
+ isMirrored: !((_b = cameraRef.current) === null || _b === void 0 ? void 0 : _b.isRearFacing),
7175
7235
  borderColor: state.isGoodFrame ? colors.guideBoxSatisfiedColor : colors.guideBoxUnsatisfiedColor,
7176
7236
  imageVisible: requestedAction === 'FLIP_ID' || !state.idCardFrontDetectionThresholdMet || !state.documentInBounds || state.documentTooClose
7177
7237
  })), guideType === 'fit' && ( /*#__PURE__*/React__default.createElement(IdCaptureFitGuide, {
@@ -7181,7 +7241,7 @@ function IdCaptureGuides(_a) {
7181
7241
  status: status,
7182
7242
  progress: progress,
7183
7243
  instruction: state.captureFailed ? verbiage.captureFailedText : state.capturing ? verbiage === null || verbiage === void 0 ? void 0 : verbiage.capturingText : verbiage.instructionText,
7184
- isMirrored: !isRearFacing,
7244
+ isMirrored: !((_c = cameraRef.current) === null || _c === void 0 ? void 0 : _c.isRearFacing),
7185
7245
  isBackToFront: isBackToFront,
7186
7246
  portraitGuidesOnMobile: portraitGuidesOnMobile,
7187
7247
  borderColor: state.isGoodFrame ? colors.guideBoxSatisfiedColor : colors.guideBoxUnsatisfiedColor,
@@ -7280,6 +7340,48 @@ var ImagePreviewText = styled.div(templateObject_3$h || (templateObject_3$h = __
7280
7340
  var ImagePreviewImageWrapper = styled.div(templateObject_4$b || (templateObject_4$b = __makeTemplateObject(["\n position: relative;\n height: calc(100% - 8px);\n padding: 4px;\n border-radius: 4px;\n background: white;\n\n & > img {\n border-radius: 4px;\n width: auto;\n max-height: 100%;\n }\n"], ["\n position: relative;\n height: calc(100% - 8px);\n padding: 4px;\n border-radius: 4px;\n background: white;\n\n & > img {\n border-radius: 4px;\n width: auto;\n max-height: 100%;\n }\n"])));
7281
7341
  var templateObject_1$q, templateObject_2$m, templateObject_3$h, templateObject_4$b;
7282
7342
 
7343
+ var CameraVideoTag = function CameraVideoTag(_a) {
7344
+ var _b;
7345
+ var className = _a.className;
7346
+ var _c = useContext(CameraStateContext),
7347
+ videoRef = _c.videoRef,
7348
+ setVideoLoaded = _c.setVideoLoaded,
7349
+ onVideoUnmounted = _c.onVideoUnmounted,
7350
+ cameraRef = _c.cameraRef;
7351
+ useEffect(function notifyCameraProviderOfUnmount() {
7352
+ var videoElement = videoRef.current;
7353
+ if (!videoElement) return;
7354
+ return function () {
7355
+ onVideoUnmounted(videoElement);
7356
+ };
7357
+ }, [onVideoUnmounted, videoRef]);
7358
+ useEffect(function setVideoLoadedToFalseOnMount() {
7359
+ setVideoLoaded(false);
7360
+ }, [setVideoLoaded]);
7361
+ useEffect(function attachCameraStreamToVideoTagWhenReady() {
7362
+ var _a;
7363
+ if (videoRef.current && ((_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.stream)) {
7364
+ videoRef.current.srcObject = cameraRef.current.stream;
7365
+ }
7366
+ }, [cameraRef, videoRef]);
7367
+ var onLoadedData = useCallback(function () {
7368
+ setVideoLoaded(true);
7369
+ }, [setVideoLoaded]);
7370
+ return /*#__PURE__*/React__default.createElement(FullscreenVideoTag, {
7371
+ className: className,
7372
+ autoPlay: true,
7373
+ playsInline: true,
7374
+ muted: true,
7375
+ ref: videoRef,
7376
+ onLoadedData: onLoadedData,
7377
+ "$isRearFacing": (_b = cameraRef.current) === null || _b === void 0 ? void 0 : _b.isRearFacing
7378
+ });
7379
+ };
7380
+ var FullscreenVideoTag = styled.video(templateObject_1$p || (templateObject_1$p = __makeTemplateObject(["\n transform: ", ";\n transform-style: preserve-3d;\n min-width: 100%;\n min-height: 100%;\n width: auto;\n height: auto;\n max-width: 100%;\n max-height: 100%;\n object-fit: cover;\n background: black;\n z-index: -2;\n"], ["\n transform: ", ";\n transform-style: preserve-3d;\n min-width: 100%;\n min-height: 100%;\n width: auto;\n height: auto;\n max-width: 100%;\n max-height: 100%;\n object-fit: cover;\n background: black;\n z-index: -2;\n"])), function (props) {
7381
+ return props.$isRearFacing ? '' : 'scaleX(-1)';
7382
+ });
7383
+ var templateObject_1$p;
7384
+
7283
7385
  var documentCaptureInitialState = {
7284
7386
  documents: [],
7285
7387
  currentDocumentIndex: 0,
@@ -7398,8 +7500,8 @@ var DocumentCaptureStateProvider = function DocumentCaptureStateProvider(_a) {
7398
7500
  var _c = useReducer(documentCaptureStateReducer, documentCaptureInitialState),
7399
7501
  state = _c[0],
7400
7502
  dispatch = _c[1];
7401
- var _d = useCameraStore(),
7402
- videoStream = _d.videoStream,
7503
+ var _d = useContext(CameraStateContext),
7504
+ cameraRef = _d.cameraRef,
7403
7505
  videoRef = _d.videoRef;
7404
7506
  var uploadDocument = useContext(SubmissionContext).uploadDocument;
7405
7507
  var uploadCapturedDocument = useCallback(function (content, filetype) {
@@ -7490,7 +7592,8 @@ var DocumentCaptureStateProvider = function DocumentCaptureStateProvider(_a) {
7490
7592
  }, [onResize]);
7491
7593
  var videoTag = videoRef.current;
7492
7594
  useEffect(function () {
7493
- if (!state.capturing || !(videoStream === null || videoStream === void 0 ? void 0 : videoStream.active)) return;
7595
+ if (!state.capturing) return;
7596
+ if (!cameraRef.current) return;
7494
7597
  function onComplete(content) {
7495
7598
  if (!content) return;
7496
7599
  var contentUrl = URL.createObjectURL(content);
@@ -7503,7 +7606,7 @@ var DocumentCaptureStateProvider = function DocumentCaptureStateProvider(_a) {
7503
7606
  });
7504
7607
  }
7505
7608
  if (typeof ImageCapture !== 'undefined') {
7506
- var tracks = videoStream.getTracks();
7609
+ var tracks = cameraRef.current.stream.getTracks();
7507
7610
  var videoCameraTrack = tracks.find(function (track) {
7508
7611
  return track.kind === 'video';
7509
7612
  });
@@ -7518,7 +7621,7 @@ var DocumentCaptureStateProvider = function DocumentCaptureStateProvider(_a) {
7518
7621
  drawToCanvas(canvas, videoTag);
7519
7622
  canvas.toBlob(onComplete);
7520
7623
  }
7521
- }, [state.capturing, videoStream, videoTag]);
7624
+ }, [cameraRef, state.capturing, videoTag]);
7522
7625
  var stateWithActions = useMemo(function () {
7523
7626
  return _assign(_assign({}, state), {
7524
7627
  uploadCapturedDocument: uploadCapturedDocument
@@ -7633,85 +7736,52 @@ var DocumentCaptureGuideOverlay = function DocumentCaptureGuideOverlay(_a) {
7633
7736
  ref: canvasRef
7634
7737
  }));
7635
7738
  };
7636
- var CanvasWrapper = styled.div(templateObject_1$p || (templateObject_1$p = __makeTemplateObject(["\n flex-grow: 1;\n background-clip: padding-box;\n box-shadow: inset 0 0 0 2px ", ";\n"], ["\n flex-grow: 1;\n background-clip: padding-box;\n box-shadow: inset 0 0 0 2px ", ";\n"])), function (props) {
7739
+ var CanvasWrapper = styled.div(templateObject_1$o || (templateObject_1$o = __makeTemplateObject(["\n flex-grow: 1;\n background-clip: padding-box;\n box-shadow: inset 0 0 0 2px ", ";\n"], ["\n flex-grow: 1;\n background-clip: padding-box;\n box-shadow: inset 0 0 0 2px ", ";\n"])), function (props) {
7637
7740
  return props.$maskColor;
7638
7741
  });
7639
7742
  var Canvas = styled.canvas(templateObject_2$l || (templateObject_2$l = __makeTemplateObject(["\n display: block;\n"], ["\n display: block;\n"])));
7640
- var templateObject_1$p, templateObject_2$l;
7743
+ var templateObject_1$o, templateObject_2$l;
7641
7744
 
7642
- var CameraFeedWrapper = styled.div(templateObject_1$o || (templateObject_1$o = __makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), function (props) {
7745
+ var CameraFeedWrapper = styled.div(templateObject_1$n || (templateObject_1$n = __makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), function (props) {
7643
7746
  return props.$mode === 'snapToGuides' ? "display: flex;\n position: absolute;\n left: ".concat(props.$x, "px;\n top: ").concat(props.$y, "px;\n width: ").concat(props.$w, "px;\n height: ").concat(props.$h, "px;") : "";
7644
7747
  });
7645
- var templateObject_1$o;
7646
-
7647
- var CameraVideoTag = function CameraVideoTag(props) {
7648
- var _a = useCameraStore(useShallow(function (store) {
7649
- return {
7650
- videoRef: store.videoRef,
7651
- videoStream: store.videoStream,
7652
- onVideoMounted: store.onVideoMounted,
7653
- isRearFacing: store.isRearFacing
7654
- };
7655
- })),
7656
- videoRef = _a.videoRef,
7657
- videoStream = _a.videoStream,
7658
- onVideoMounted = _a.onVideoMounted,
7659
- isRearFacing = _a.isRearFacing;
7660
- useEffect(function attachCameraStreamToVideoTagWhenReady() {
7661
- if (videoRef.current && videoStream) {
7662
- debug('attaching camera stream to video tag');
7663
- videoRef.current.srcObject = videoStream;
7664
- }
7665
- }, [videoStream, videoRef]);
7666
- return /*#__PURE__*/React__default.createElement(FullscreenVideoTag, _assign({
7667
- autoPlay: true,
7668
- playsInline: true,
7669
- muted: true,
7670
- ref: videoRef,
7671
- onLoadedData: onVideoMounted,
7672
- "$isRearFacing": isRearFacing
7673
- }, props));
7674
- };
7675
- var FullscreenVideoTag = styled.video(templateObject_1$n || (templateObject_1$n = __makeTemplateObject(["\n transform: ", ";\n transform-style: preserve-3d;\n min-width: 100%;\n min-height: 100%;\n width: auto;\n height: auto;\n max-width: 100%;\n max-height: 100%;\n object-fit: cover;\n background: black;\n z-index: -2;\n"], ["\n transform: ", ";\n transform-style: preserve-3d;\n min-width: 100%;\n min-height: 100%;\n width: auto;\n height: auto;\n max-width: 100%;\n max-height: 100%;\n object-fit: cover;\n background: black;\n z-index: -2;\n"])), function (props) {
7676
- return props.$isRearFacing ? '' : 'scaleX(-1)';
7677
- });
7678
7748
  var templateObject_1$n;
7679
7749
 
7680
7750
  var DocumentCaptureScreen = function DocumentCaptureScreen(_a) {
7681
- var _b, _c, _d, _e, _f;
7751
+ var _b, _c, _d, _e, _f, _g, _h;
7682
7752
  var onCaptureClicked = _a.onCaptureClicked,
7683
- _g = _a.classNames,
7684
- classNames = _g === void 0 ? {} : _g,
7685
- _h = _a.verbiage,
7686
- rawVerbiage = _h === void 0 ? {} : _h;
7687
- var _j = useDocumentCaptureState(),
7688
- _k = _j[0],
7689
- documents = _k.documents,
7690
- currentDocumentIndex = _k.currentDocumentIndex,
7691
- rectX = _k.rectX,
7692
- rectY = _k.rectY,
7693
- rectWidth = _k.rectWidth,
7694
- rectHeight = _k.rectHeight,
7695
- rectOffsetTop = _k.rectOffsetTop,
7696
- capturing = _k.capturing,
7697
- uploadCapturedDocument = _k.uploadCapturedDocument,
7698
- dispatch = _j[1];
7699
- var _l = (_b = documents[currentDocumentIndex]) !== null && _b !== void 0 ? _b : {},
7700
- title = _l.title,
7701
- aspectRatio = _l.aspectRatio,
7702
- cameraFeedMode = _l.cameraFeedMode,
7703
- instructions = _l.instructions,
7704
- contentUrl = _l.contentUrl,
7705
- content = _l.content,
7706
- uploadState = _l.uploadState;
7707
- var _m = useCameraStore(),
7708
- videoStream = _m.videoStream,
7709
- cameraReady = _m.cameraReady,
7710
- cameraAccessDenied = _m.cameraAccessDenied,
7711
- requestCameraAccess = _m.requestCameraAccess;
7712
- var _o = useState(false),
7713
- cameraAccessRequested = _o[0],
7714
- setCameraAccessRequested = _o[1];
7753
+ _j = _a.classNames,
7754
+ classNames = _j === void 0 ? {} : _j,
7755
+ _k = _a.verbiage,
7756
+ rawVerbiage = _k === void 0 ? {} : _k;
7757
+ var _l = useDocumentCaptureState(),
7758
+ _m = _l[0],
7759
+ documents = _m.documents,
7760
+ currentDocumentIndex = _m.currentDocumentIndex,
7761
+ rectX = _m.rectX,
7762
+ rectY = _m.rectY,
7763
+ rectWidth = _m.rectWidth,
7764
+ rectHeight = _m.rectHeight,
7765
+ rectOffsetTop = _m.rectOffsetTop,
7766
+ capturing = _m.capturing,
7767
+ uploadCapturedDocument = _m.uploadCapturedDocument,
7768
+ dispatch = _l[1];
7769
+ var _o = (_b = documents[currentDocumentIndex]) !== null && _b !== void 0 ? _b : {},
7770
+ title = _o.title,
7771
+ aspectRatio = _o.aspectRatio,
7772
+ cameraFeedMode = _o.cameraFeedMode,
7773
+ instructions = _o.instructions,
7774
+ contentUrl = _o.contentUrl,
7775
+ content = _o.content,
7776
+ uploadState = _o.uploadState;
7777
+ var _p = useContext(CameraStateContext),
7778
+ cameraRef = _p.cameraRef,
7779
+ cameraReady = _p.cameraReady,
7780
+ cameraAccessDenied = _p.cameraAccessDenied,
7781
+ requestCameraAccess = _p.requestCameraAccess;
7782
+ var _q = useState(false),
7783
+ cameraAccessRequested = _q[0],
7784
+ setCameraAccessRequested = _q[1];
7715
7785
  var cameraAccessNeeded =
7716
7786
  // we should force the browser to ask for camera access if...
7717
7787
  uploadState === 'not_started' &&
@@ -7720,14 +7790,14 @@ var DocumentCaptureScreen = function DocumentCaptureScreen(_a) {
7720
7790
  // and the user hasn't passed a media blob for the current document...
7721
7791
  !cameraAccessRequested &&
7722
7792
  // and we haven't already tried to force a camera request...
7723
- !(videoStream === null || videoStream === void 0 ? void 0 : videoStream.active); // and we don't already have camera access.
7793
+ !((_d = (_c = cameraRef.current) === null || _c === void 0 ? void 0 : _c.stream) === null || _d === void 0 ? void 0 : _d.active); // and we don't already have camera access.
7724
7794
  useEffect(function requestCameraAccessIfNeeded() {
7725
7795
  if (!cameraAccessNeeded) return;
7726
7796
  setCameraAccessRequested(true);
7727
7797
  requestCameraAccess();
7728
7798
  }, [cameraAccessNeeded, requestCameraAccess]);
7729
7799
  var theme = useTheme();
7730
- var maskColor = (_e = (_d = (_c = theme.documentCapture) === null || _c === void 0 ? void 0 : _c.guideBox) === null || _d === void 0 ? void 0 : _d.maskColor) !== null && _e !== void 0 ? _e : cameraFeedMode === 'snapToGuides' ? '#708090' : "rgba(0, 0, 0, 0.5)";
7800
+ var maskColor = (_g = (_f = (_e = theme.documentCapture) === null || _e === void 0 ? void 0 : _e.guideBox) === null || _f === void 0 ? void 0 : _f.maskColor) !== null && _g !== void 0 ? _g : cameraFeedMode === 'snapToGuides' ? '#708090' : "rgba(0, 0, 0, 0.5)";
7731
7801
  var verbiage = useTranslations(rawVerbiage, {
7732
7802
  headingText: title,
7733
7803
  loadingBtnText: 'Camera initializing...',
@@ -7760,7 +7830,7 @@ var DocumentCaptureScreen = function DocumentCaptureScreen(_a) {
7760
7830
  });
7761
7831
  }
7762
7832
  return /*#__PURE__*/React__default.createElement(PageContainer, {
7763
- className: "flex ".concat((_f = classNames.container) !== null && _f !== void 0 ? _f : '')
7833
+ className: "flex ".concat((_h = classNames.container) !== null && _h !== void 0 ? _h : '')
7764
7834
  }, /*#__PURE__*/React__default.createElement(CameraFeedWrapper, {
7765
7835
  className: classNames.cameraFeedWrapper,
7766
7836
  "$mode": cameraFeedMode !== null && cameraFeedMode !== void 0 ? cameraFeedMode : 'snapToGuides',
@@ -8185,7 +8255,7 @@ var IdCaptureWizard = function IdCaptureWizard(_a) {
8185
8255
  var _3 = useIdCaptureState(),
8186
8256
  state = _3[0],
8187
8257
  dispatch = _3[1];
8188
- var _4 = useCameraStore(),
8258
+ var _4 = useContext(CameraStateContext),
8189
8259
  cameraAccessDenied = _4.cameraAccessDenied,
8190
8260
  requestCameraAccess = _4.requestCameraAccess,
8191
8261
  releaseCameraAccess = _4.releaseCameraAccess;
@@ -8310,7 +8380,7 @@ var IdCaptureWizard = function IdCaptureWizard(_a) {
8310
8380
  type: 'resetWizard'
8311
8381
  });
8312
8382
  onExitCapture === null || onExitCapture === void 0 ? void 0 : onExitCapture();
8313
- void requestCameraAccess();
8383
+ requestCameraAccess();
8314
8384
  }, [dispatch, onExitCapture, releaseCameraAccess, requestCameraAccess]);
8315
8385
  useEffect(function () {
8316
8386
  if (submissionStatus !== SubmissionStatus.READY) {
@@ -9133,13 +9203,7 @@ function SelfieGuidanceModelsProvider(_a) {
9133
9203
  modelLoadTimeoutMs = _c === void 0 ? defaultSelfieCaptureModelLoadTimeoutMs : _c,
9134
9204
  _d = _a.requireVerticalFaceCentering,
9135
9205
  requireVerticalFaceCentering = _d === void 0 ? true : _d;
9136
- var _e = useCameraStore(useShallow(function (state) {
9137
- return {
9138
- videoRef: state.videoRef,
9139
- videoLoaded: state.videoLoaded,
9140
- cameraReady: state.cameraReady
9141
- };
9142
- })),
9206
+ var _e = useContext(CameraStateContext),
9143
9207
  videoRef = _e.videoRef,
9144
9208
  videoLoaded = _e.videoLoaded,
9145
9209
  cameraReady = _e.cameraReady;
@@ -9147,8 +9211,7 @@ function SelfieGuidanceModelsProvider(_a) {
9147
9211
  var onPredictionHandler = useRef();
9148
9212
  var _f = useLoadFaceDetector({
9149
9213
  onModelError: onModelError,
9150
- modelLoadTimeoutMs: modelLoadTimeoutMs,
9151
- videoRef: videoRef
9214
+ modelLoadTimeoutMs: modelLoadTimeoutMs
9152
9215
  }),
9153
9216
  ready = _f.ready,
9154
9217
  modelDownloadProgress = _f.modelDownloadProgress,
@@ -9481,14 +9544,8 @@ var SelfieCapture = function SelfieCapture(_a) {
9481
9544
  prediction = _t.prediction,
9482
9545
  dispatch = _s[1];
9483
9546
  var lastPredictionCanvas = useRef(null);
9484
- var _u = useCameraStore(useShallow(function (state) {
9485
- return {
9486
- camera: state.camera,
9487
- cameraReady: state.cameraReady,
9488
- videoRef: state.videoRef
9489
- };
9490
- })),
9491
- camera = _u.camera,
9547
+ var _u = useContext(CameraStateContext),
9548
+ cameraRef = _u.cameraRef,
9492
9549
  videoRef = _u.videoRef;
9493
9550
  var _v = useContext(SelfieGuidanceModelsContext),
9494
9551
  onPredictionMade = _v.onPredictionMade,
@@ -9578,7 +9635,7 @@ var SelfieCapture = function SelfieCapture(_a) {
9578
9635
  face: prediction.face,
9579
9636
  scaling: debugScalingDetails,
9580
9637
  color: satisfied ? 'green' : 'red'
9581
- }))), debugMode && ( /*#__PURE__*/React__default.createElement(DebugStatsPane, null, camera ? ( /*#__PURE__*/React__default.createElement(React__default.Fragment, null, "\u2705 Camera: ", camera.label, " (", camera.width, "x", camera.height, ")")) : '❌ Camera not ready', /*#__PURE__*/React__default.createElement("br", null), !(prediction === null || prediction === void 0 ? void 0 : prediction.faceNotCentered) ? '✅' : '❌', " Face Centered", /*#__PURE__*/React__default.createElement("br", null), !(prediction === null || prediction === void 0 ? void 0 : prediction.faceTooClose) && !(prediction === null || prediction === void 0 ? void 0 : prediction.faceTooFar) ? '✅' : '❌', ' ', "Face", ' ', (prediction === null || prediction === void 0 ? void 0 : prediction.faceTooClose) ? 'Too Close' : (prediction === null || prediction === void 0 ? void 0 : prediction.faceTooFar) ? 'Too Far' : 'Distance Correct', /*#__PURE__*/React__default.createElement("br", null), !(prediction === null || prediction === void 0 ? void 0 : prediction.faceLookingAway) ? '✅' : '❌', " Face Looking Forward", /*#__PURE__*/React__default.createElement("br", null), !(prediction === null || prediction === void 0 ? void 0 : prediction.faceIsStable) ? '✅' : '❌', " Face Is Stable", /*#__PURE__*/React__default.createElement("br", null), !timedOut ? '✅' : '❌', " Time Remaining:", ' ', Math.max(0, timeoutDurationMs - (new Date().getTime() - (timeoutStartedAt !== null && timeoutStartedAt !== void 0 ? timeoutStartedAt : new Date()).getTime())), "ms")), /*#__PURE__*/React__default.createElement(ExitCaptureButton, {
9638
+ }))), debugMode && ( /*#__PURE__*/React__default.createElement(DebugStatsPane, null, cameraRef.current ? ( /*#__PURE__*/React__default.createElement(React__default.Fragment, null, "\u2705 Camera: ", cameraRef.current.label, " (", cameraRef.current.width, "x", cameraRef.current.height, ")")) : '❌ Camera not ready', /*#__PURE__*/React__default.createElement("br", null), !(prediction === null || prediction === void 0 ? void 0 : prediction.faceNotCentered) ? '✅' : '❌', " Face Centered", /*#__PURE__*/React__default.createElement("br", null), !(prediction === null || prediction === void 0 ? void 0 : prediction.faceTooClose) && !(prediction === null || prediction === void 0 ? void 0 : prediction.faceTooFar) ? '✅' : '❌', ' ', "Face", ' ', (prediction === null || prediction === void 0 ? void 0 : prediction.faceTooClose) ? 'Too Close' : (prediction === null || prediction === void 0 ? void 0 : prediction.faceTooFar) ? 'Too Far' : 'Distance Correct', /*#__PURE__*/React__default.createElement("br", null), !(prediction === null || prediction === void 0 ? void 0 : prediction.faceLookingAway) ? '✅' : '❌', " Face Looking Forward", /*#__PURE__*/React__default.createElement("br", null), !(prediction === null || prediction === void 0 ? void 0 : prediction.faceIsStable) ? '✅' : '❌', " Face Is Stable", /*#__PURE__*/React__default.createElement("br", null), !timedOut ? '✅' : '❌', " Time Remaining:", ' ', Math.max(0, timeoutDurationMs - (new Date().getTime() - (timeoutStartedAt !== null && timeoutStartedAt !== void 0 ? timeoutStartedAt : new Date()).getTime())), "ms")), /*#__PURE__*/React__default.createElement(ExitCaptureButton, {
9582
9639
  onClick: onExit,
9583
9640
  className: classNames.exitCaptureBtn
9584
9641
  }));
@@ -10034,9 +10091,7 @@ var MicrophoneAccessDeniedOverlay = function MicrophoneAccessDeniedOverlay(_a) {
10034
10091
  colors = _e === void 0 ? {} : _e,
10035
10092
  _f = _a.verbiage,
10036
10093
  rawVerbiage = _f === void 0 ? {} : _f;
10037
- var requestMicrophoneAccess = useCameraStore(function (state) {
10038
- return state.requestMicrophoneAccess;
10039
- });
10094
+ var requestMicrophoneAccess = useContext(CameraStateContext).requestMicrophoneAccess;
10040
10095
  assets.imageUrl || (assets.imageUrl = DEFAULT_CDN_URL + '/microphone-disable-icon.svg');
10041
10096
  var verbiage = useTranslations(rawVerbiage, {
10042
10097
  headingText: 'Your microphone permission is disabled',
@@ -10084,13 +10139,7 @@ var SelfieCaptureLoadingOverlayLegacy = function SelfieCaptureLoadingOverlayLega
10084
10139
  colors = _e === void 0 ? {} : _e,
10085
10140
  _f = _a.verbiage,
10086
10141
  rawVerbiage = _f === void 0 ? {} : _f;
10087
- var _g = useCameraStore(useShallow(function (state) {
10088
- return {
10089
- cameraReady: state.cameraReady,
10090
- cameraAccessDenied: state.cameraAccessDenied,
10091
- microphoneAccessDenied: state.microphoneAccessDenied
10092
- };
10093
- })),
10142
+ var _g = useContext(CameraStateContext),
10094
10143
  cameraReady = _g.cameraReady,
10095
10144
  cameraAccessDenied = _g.cameraAccessDenied,
10096
10145
  microphoneAccessDenied = _g.microphoneAccessDenied;
@@ -10177,13 +10226,7 @@ var SelfieCaptureLoadingOverlayDefault = function SelfieCaptureLoadingOverlayDef
10177
10226
  colors = _e === void 0 ? {} : _e,
10178
10227
  _f = _a.verbiage,
10179
10228
  rawVerbiage = _f === void 0 ? {} : _f;
10180
- var _g = useCameraStore(useShallow(function (state) {
10181
- return {
10182
- cameraReady: state.cameraReady,
10183
- cameraAccessDenied: state.cameraAccessDenied,
10184
- microphoneAccessDenied: state.microphoneAccessDenied
10185
- };
10186
- })),
10229
+ var _g = useContext(CameraStateContext),
10187
10230
  cameraReady = _g.cameraReady,
10188
10231
  cameraAccessDenied = _g.cameraAccessDenied,
10189
10232
  microphoneAccessDenied = _g.microphoneAccessDenied;
@@ -10400,13 +10443,7 @@ var FaceLivenessWizard = function FaceLivenessWizard(_a) {
10400
10443
  livenessCheckRequest = _t.livenessCheckRequest,
10401
10444
  setSelfieImage = _t.setSelfieImage,
10402
10445
  logSelfieCaptureAttempt = _t.logSelfieCaptureAttempt;
10403
- var _u = useCameraStore(useShallow(function (state) {
10404
- return {
10405
- cameraAccessDenied: state.cameraAccessDenied,
10406
- requestCameraAccess: state.requestCameraAccess,
10407
- releaseCameraAccess: state.releaseCameraAccess
10408
- };
10409
- })),
10446
+ var _u = useContext(CameraStateContext),
10410
10447
  cameraAccessDenied = _u.cameraAccessDenied,
10411
10448
  requestCameraAccess = _u.requestCameraAccess,
10412
10449
  releaseCameraAccess = _u.releaseCameraAccess;
@@ -11127,10 +11164,10 @@ function VideoSignatureContextProvider(_a) {
11127
11164
  setSignatureVideoUrl = _e[1];
11128
11165
  var signatureRecorder = useRef(null);
11129
11166
  var recordedChunks = useRef([]);
11130
- var _f = useCameraStore(),
11131
- camera = _f.camera,
11167
+ var _f = useContext(CameraStateContext),
11168
+ cameraRef = _f.cameraRef,
11132
11169
  videoRef = _f.videoRef;
11133
- var _g = useVideoRecorder(camera),
11170
+ var _g = useVideoRecorder(cameraRef.current),
11134
11171
  isRecordingVideo = _g.isRecordingVideo,
11135
11172
  startRecordingVideo = _g.startRecordingVideo,
11136
11173
  stopRecordingVideo = _g.stopRecordingVideo,
@@ -11198,8 +11235,8 @@ function VideoSignatureContextProvider(_a) {
11198
11235
  var animationFrame = useRef(0);
11199
11236
  useEffect(function () {
11200
11237
  var _a;
11201
- if (!signaturePad.current || !videoRef.current || !outputCanvas.current || !camera || !isRecording || !isRecordingVideo) return;
11202
- var _b = [camera.width, camera.height],
11238
+ if (!signaturePad.current || !videoRef.current || !outputCanvas.current || !cameraRef.current || !isRecording || !isRecordingVideo) return;
11239
+ var _b = [cameraRef.current.width, cameraRef.current.height],
11203
11240
  w = _b[0],
11204
11241
  h = _b[1];
11205
11242
  var isPortrait = typeof window !== 'undefined' && window.innerWidth < window.innerHeight;
@@ -11232,7 +11269,7 @@ function VideoSignatureContextProvider(_a) {
11232
11269
  return function () {
11233
11270
  cancelAnimationFrame(animationFrame.current);
11234
11271
  };
11235
- }, [camera, isRecording, isRecordingVideo, videoRef]);
11272
+ }, [cameraRef, isRecording, isRecordingVideo, videoRef]);
11236
11273
  var onAcceptClicked = useCallback(function () {
11237
11274
  return __awaiter(_this, void 0, void 0, function () {
11238
11275
  var imageUrl;
@@ -11361,29 +11398,27 @@ var AcceptBtn = styled(LoaderButton)(templateObject_7$1 || (templateObject_7$1 =
11361
11398
  var templateObject_1$9, templateObject_2$8, templateObject_3$8, templateObject_4$3, templateObject_5$2, templateObject_6$2, templateObject_7$1;
11362
11399
 
11363
11400
  var VideoSignatureCapture = function VideoSignatureCapture(_a) {
11364
- var _b;
11401
+ var _b, _c, _d;
11365
11402
  var onVideoCaptured = _a.onVideoCaptured,
11366
11403
  onFaceNotDetected = _a.onFaceNotDetected,
11367
11404
  onExit = _a.onExit,
11368
11405
  guidesComponent = _a.guidesComponent,
11369
- _c = _a.classNames,
11370
- classNames = _c === void 0 ? {} : _c,
11371
- _d = _a.colors,
11372
- colors = _d === void 0 ? {} : _d,
11373
- _e = _a.verbiage,
11374
- rawVerbiage = _e === void 0 ? {} : _e,
11375
- _f = _a.debugMode,
11376
- debugMode = _f === void 0 ? false : _f;
11377
- var camera = useCameraStore(function (state) {
11378
- return state.camera;
11379
- });
11406
+ _e = _a.classNames,
11407
+ classNames = _e === void 0 ? {} : _e,
11408
+ _f = _a.colors,
11409
+ colors = _f === void 0 ? {} : _f,
11410
+ _g = _a.verbiage,
11411
+ rawVerbiage = _g === void 0 ? {} : _g,
11412
+ _h = _a.debugMode,
11413
+ debugMode = _h === void 0 ? false : _h;
11414
+ var cameraRef = useContext(CameraStateContext).cameraRef;
11380
11415
  var onPredictionMade = useContext(SelfieGuidanceModelsContext).onPredictionMade;
11381
- var _g = useVideoSignatureContext(),
11382
- signatureData = _g.signatureData,
11383
- signatureDataUrl = _g.signatureDataUrl,
11384
- signatureVideoData = _g.signatureVideoData,
11385
- startRecording = _g.startRecording,
11386
- stopRecording = _g.stopRecording;
11416
+ var _j = useVideoSignatureContext(),
11417
+ signatureData = _j.signatureData,
11418
+ signatureDataUrl = _j.signatureDataUrl,
11419
+ signatureVideoData = _j.signatureVideoData,
11420
+ startRecording = _j.startRecording,
11421
+ stopRecording = _j.stopRecording;
11387
11422
  useEffect(function () {
11388
11423
  startRecording();
11389
11424
  return function () {
@@ -11400,9 +11435,9 @@ var VideoSignatureCapture = function VideoSignatureCapture(_a) {
11400
11435
  onVideoCaptured === null || onVideoCaptured === void 0 ? void 0 : onVideoCaptured(signatureVideoData, signatureData, signatureDataUrl);
11401
11436
  }
11402
11437
  }, [onVideoCaptured, signatureData, signatureDataUrl, signatureVideoData]);
11403
- var _h = useState(0),
11404
- numFramesWithoutFaces = _h[0],
11405
- setNumFramesWithoutFaces = _h[1];
11438
+ var _k = useState(0),
11439
+ numFramesWithoutFaces = _k[0],
11440
+ setNumFramesWithoutFaces = _k[1];
11406
11441
  useEffect(function () {
11407
11442
  onPredictionMade(function (_a) {
11408
11443
  var face = _a.face;
@@ -11429,7 +11464,7 @@ var VideoSignatureCapture = function VideoSignatureCapture(_a) {
11429
11464
  }, verbiage.guidanceMessageText))), /*#__PURE__*/React__default.createElement(GuidesComponent, {
11430
11465
  classNames: classNames.videoSignatureGuidesClassNames,
11431
11466
  status: "success"
11432
- }), debugMode && ( /*#__PURE__*/React__default.createElement(DebugStatsPane, null, "Video: ", camera === null || camera === void 0 ? void 0 : camera.width, "x", camera === null || camera === void 0 ? void 0 : camera.height)), /*#__PURE__*/React__default.createElement(ExitCaptureButton, {
11467
+ }), debugMode && ( /*#__PURE__*/React__default.createElement(DebugStatsPane, null, "Video: ", (_c = cameraRef.current) === null || _c === void 0 ? void 0 : _c.width, "x", (_d = cameraRef.current) === null || _d === void 0 ? void 0 : _d.height)), /*#__PURE__*/React__default.createElement(ExitCaptureButton, {
11433
11468
  onClick: onExit,
11434
11469
  className: classNames.exitCaptureBtn
11435
11470
  }));
@@ -11523,13 +11558,7 @@ var VideoSignatureWizard = function VideoSignatureWizard(_a) {
11523
11558
  setSignatureData = _l.setSignatureData,
11524
11559
  setSignatureVideoUrl = _l.setSignatureVideoUrl,
11525
11560
  logSelfieCaptureAttempt = _l.logSelfieCaptureAttempt;
11526
- var _m = useCameraStore(useShallow(function (state) {
11527
- return {
11528
- cameraAccessDenied: state.cameraAccessDenied,
11529
- requestCameraAccess: state.requestCameraAccess,
11530
- releaseCameraAccess: state.releaseCameraAccess
11531
- };
11532
- })),
11561
+ var _m = useContext(CameraStateContext),
11533
11562
  cameraAccessDenied = _m.cameraAccessDenied,
11534
11563
  requestCameraAccess = _m.requestCameraAccess,
11535
11564
  releaseCameraAccess = _m.releaseCameraAccess;
@@ -11689,29 +11718,27 @@ var VideoSignatureWizard = function VideoSignatureWizard(_a) {
11689
11718
  };
11690
11719
 
11691
11720
  var IdVideoCaptureGuides = function IdVideoCaptureGuides(_a) {
11692
- var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
11693
- var _z = _a.requestedAction,
11694
- requestedAction = _z === void 0 ? 'SHOW_ID_FRONT' : _z,
11695
- _0 = _a.satisfied,
11696
- satisfied = _0 === void 0 ? false : _0,
11697
- _1 = _a.faceGuideStatus,
11698
- faceGuideStatus = _1 === void 0 ? 'success' : _1,
11721
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
11722
+ var _0 = _a.requestedAction,
11723
+ requestedAction = _0 === void 0 ? 'SHOW_ID_FRONT' : _0,
11724
+ _1 = _a.satisfied,
11725
+ satisfied = _1 === void 0 ? false : _1,
11726
+ _2 = _a.faceGuideStatus,
11727
+ faceGuideStatus = _2 === void 0 ? 'success' : _2,
11699
11728
  faceGuideBorderWidth = _a.faceGuideBorderWidth,
11700
11729
  faceGuideBorderColor = _a.faceGuideBorderColor,
11701
- _2 = _a.idCardGuideStatus,
11702
- idCardGuideStatus = _2 === void 0 ? 'ready' : _2,
11730
+ _3 = _a.idCardGuideStatus,
11731
+ idCardGuideStatus = _3 === void 0 ? 'ready' : _3,
11703
11732
  idCardGuideBorderWidth = _a.idCardGuideBorderWidth,
11704
11733
  idCardGuideBorderColor = _a.idCardGuideBorderColor,
11705
11734
  idCardCaptureProgress = _a.idCardCaptureProgress,
11706
- _3 = _a.idCardCaptureGuideImages,
11707
- userSuppliedImages = _3 === void 0 ? defaultIdCaptureGuideImages : _3,
11708
- _4 = _a.classNames,
11709
- classNames = _4 === void 0 ? {} : _4,
11710
- _5 = _a.verbiage,
11711
- rawVerbiage = _5 === void 0 ? {} : _5;
11712
- var isRearFacing = useCameraStore(function (state) {
11713
- return state.isRearFacing;
11714
- });
11735
+ _4 = _a.idCardCaptureGuideImages,
11736
+ userSuppliedImages = _4 === void 0 ? defaultIdCaptureGuideImages : _4,
11737
+ _5 = _a.classNames,
11738
+ classNames = _5 === void 0 ? {} : _5,
11739
+ _6 = _a.verbiage,
11740
+ rawVerbiage = _6 === void 0 ? {} : _6;
11741
+ var cameraRef = useContext(CameraStateContext).cameraRef;
11715
11742
  var verbiage = useTranslations(rawVerbiage, {
11716
11743
  idFrontInstructionText: 'Display the front of your ID card...',
11717
11744
  idBackInstructionText: 'Display the back of your ID card...',
@@ -11724,17 +11751,17 @@ var IdVideoCaptureGuides = function IdVideoCaptureGuides(_a) {
11724
11751
  if (faceGuideBorderColor === undefined) faceGuideBorderColor = (_j = satisfied ? (_f = (_e = theme.idVideoCapture) === null || _e === void 0 ? void 0 : _e.faceGuides) === null || _f === void 0 ? void 0 : _f.satisfiedColor : (_h = (_g = theme.idVideoCapture) === null || _g === void 0 ? void 0 : _g.faceGuides) === null || _h === void 0 ? void 0 : _h.unsatisfiedColor) !== null && _j !== void 0 ? _j : '#D6DCE7';
11725
11752
  if (idCardGuideBorderWidth === undefined) idCardGuideBorderWidth = (_m = (_l = (_k = theme.idVideoCapture) === null || _k === void 0 ? void 0 : _k.idCardGuides) === null || _l === void 0 ? void 0 : _l.borderWidth) !== null && _m !== void 0 ? _m : 20;
11726
11753
  if (idCardGuideBorderColor === undefined) idCardGuideBorderColor = (_s = satisfied ? (_p = (_o = theme.idVideoCapture) === null || _o === void 0 ? void 0 : _o.idCardGuides) === null || _p === void 0 ? void 0 : _p.satisfiedColor : (_r = (_q = theme.idVideoCapture) === null || _q === void 0 ? void 0 : _q.idCardGuides) === null || _r === void 0 ? void 0 : _r.unsatisfiedColor) !== null && _s !== void 0 ? _s : '#D6DCE7';
11727
- var _6 = useResizeObserver(),
11728
- idCardGuideRef = _6.ref,
11729
- _7 = _6.width,
11730
- idCardGuideWidth = _7 === void 0 ? 0 : _7,
11731
- _8 = _6.height,
11732
- idCardGuideHeight = _8 === void 0 ? 0 : _8;
11754
+ var _7 = useResizeObserver(),
11755
+ idCardGuideRef = _7.ref,
11756
+ _8 = _7.width,
11757
+ idCardGuideWidth = _8 === void 0 ? 0 : _8,
11758
+ _9 = _7.height,
11759
+ idCardGuideHeight = _9 === void 0 ? 0 : _9;
11733
11760
  var idCaptureGuideImages = useGuideImages(userSuppliedImages);
11734
11761
  var idCaptureGuideImagesByUrl = useGuideImagesByUrl(idCaptureGuideImages);
11735
- var _9 = useState(undefined),
11736
- aspectRatio = _9[0],
11737
- setAspectRatio = _9[1];
11762
+ var _10 = useState(undefined),
11763
+ aspectRatio = _10[0],
11764
+ setAspectRatio = _10[1];
11738
11765
  var onImageLoaded = useCallback(function (e) {
11739
11766
  var _a, _b, _c, _d;
11740
11767
  var img = e.currentTarget;
@@ -11781,7 +11808,7 @@ var IdVideoCaptureGuides = function IdVideoCaptureGuides(_a) {
11781
11808
  }, /*#__PURE__*/React__default.createElement(IdCardGuideImage, {
11782
11809
  alt: "",
11783
11810
  className: classNames.idCardGuideImage,
11784
- "$isMirrored": !isRearFacing,
11811
+ "$isMirrored": !((_v = cameraRef.current) === null || _v === void 0 ? void 0 : _v.isRearFacing),
11785
11812
  style: idCardImageStyle,
11786
11813
  src: requestedAction === 'SHOW_ID_BACK' ? idCaptureGuideImages.landscape.SHOW_ID_BACK.url : idCaptureGuideImages.landscape.SHOW_ID_FRONT.url,
11787
11814
  onLoad: onImageLoaded
@@ -11795,8 +11822,8 @@ var IdVideoCaptureGuides = function IdVideoCaptureGuides(_a) {
11795
11822
  className: classNames.idCardGuideInstructionsContainer
11796
11823
  }, /*#__PURE__*/React__default.createElement(IdCardGuideInstructions, {
11797
11824
  className: classNames.idCardGuideInstructions,
11798
- "$textColor": (_w = (_v = theme.idVideoCapture) === null || _v === void 0 ? void 0 : _v.idCardGuides) === null || _w === void 0 ? void 0 : _w.instructionsTextColor,
11799
- "$background": (_y = (_x = theme.idVideoCapture) === null || _x === void 0 ? void 0 : _x.idCardGuides) === null || _y === void 0 ? void 0 : _y.instructionsBackgroundColor
11825
+ "$textColor": (_x = (_w = theme.idVideoCapture) === null || _w === void 0 ? void 0 : _w.idCardGuides) === null || _x === void 0 ? void 0 : _x.instructionsTextColor,
11826
+ "$background": (_z = (_y = theme.idVideoCapture) === null || _y === void 0 ? void 0 : _y.idCardGuides) === null || _z === void 0 ? void 0 : _z.instructionsBackgroundColor
11800
11827
  }, instructionText))))));
11801
11828
  };
11802
11829
  var Container = styled.div(templateObject_1$7 || (templateObject_1$7 = __makeTemplateObject(["\n display: flex;\n max-height: 100%;\n position: absolute;\n z-index: 1000;\n width: 100dvw;\n height: 100dvh;\n font-family: ", ";\n box-sizing: border-box;\n overflow: hidden;\n padding: 40px;\n"], ["\n display: flex;\n max-height: 100%;\n position: absolute;\n z-index: 1000;\n width: 100dvw;\n height: 100dvh;\n font-family: ", ";\n box-sizing: border-box;\n overflow: hidden;\n padding: 40px;\n"])), function (props) {
@@ -11941,100 +11968,99 @@ var defaultVideoIdCaptureThresholds = {
11941
11968
  flipShortcutThreshold: 0.7
11942
11969
  };
11943
11970
  var IdVideoCapture = function IdVideoCapture(_a) {
11944
- var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
11971
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
11945
11972
  var onComplete = _a.onComplete,
11946
11973
  onIdFrontImageCaptured = _a.onIdFrontImageCaptured,
11947
11974
  onIdBackImageCaptured = _a.onIdBackImageCaptured,
11948
11975
  onFaceNotDetected = _a.onFaceNotDetected,
11949
11976
  onRecordingFailed = _a.onRecordingFailed,
11950
11977
  onExitCapture = _a.onExitCapture,
11951
- _w = _a.idCaptureModelsEnabled,
11952
- idCaptureModelsEnabled = _w === void 0 ? true : _w,
11953
- _x = _a.idCardCaptureGuideImages,
11954
- idCardCaptureGuideImages = _x === void 0 ? defaultIdCaptureGuideImages : _x,
11955
- _y = _a.idCardFrontDelay,
11956
- idCardFrontDelay = _y === void 0 ? 1000 : _y,
11957
- _z = _a.videoIdCaptureThresholds,
11958
- videoIdCaptureThresholds = _z === void 0 ? defaultVideoIdCaptureThresholds : _z,
11959
- _0 = _a.skipShowIdCardBack,
11960
- skipShowIdCardBack = _0 === void 0 ? false : _0,
11961
- _1 = _a.captureCountdownSeconds,
11962
- captureCountdownSeconds = _1 === void 0 ? 3 : _1,
11978
+ _x = _a.idCaptureModelsEnabled,
11979
+ idCaptureModelsEnabled = _x === void 0 ? true : _x,
11980
+ _y = _a.idCardCaptureGuideImages,
11981
+ idCardCaptureGuideImages = _y === void 0 ? defaultIdCaptureGuideImages : _y,
11982
+ _z = _a.idCardFrontDelay,
11983
+ idCardFrontDelay = _z === void 0 ? 1000 : _z,
11984
+ _0 = _a.videoIdCaptureThresholds,
11985
+ videoIdCaptureThresholds = _0 === void 0 ? defaultVideoIdCaptureThresholds : _0,
11986
+ _1 = _a.skipShowIdCardBack,
11987
+ skipShowIdCardBack = _1 === void 0 ? false : _1,
11988
+ _2 = _a.captureCountdownSeconds,
11989
+ captureCountdownSeconds = _2 === void 0 ? 3 : _2,
11963
11990
  readTextPrompt = _a.readTextPrompt,
11964
- _2 = _a.readTextTimeoutDurationMs,
11965
- readTextTimeoutDurationMs = _2 === void 0 ? 15000 : _2,
11966
- _3 = _a.readTextMinReadingMs,
11967
- readTextMinReadingMs = _3 === void 0 ? 10000 : _3,
11968
- _4 = _a.disableFaceDetectionWhileAudioCapture,
11969
- disableFaceDetectionWhileAudioCapture = _4 === void 0 ? false : _4,
11970
- _5 = _a.disableFaceDetectionWhileAudioCaptureMsDelay,
11971
- disableFaceDetectionWhileAudioCaptureMsDelay = _5 === void 0 ? 2000 : _5,
11972
- _6 = _a.mergeAVStreams,
11973
- mergeAVStreams = _6 === void 0 ? false : _6,
11974
- _7 = _a.classNames,
11975
- classNames = _7 === void 0 ? {} : _7,
11976
- _8 = _a.colors,
11977
- colors = _8 === void 0 ? {} : _8,
11978
- _9 = _a.verbiage,
11979
- rawVerbiage = _9 === void 0 ? {} : _9,
11980
- _10 = _a.debugMode,
11981
- debugMode = _10 === void 0 ? false : _10;
11982
- var _11 = useResizeObserver(),
11983
- ref = _11.ref,
11984
- _12 = _11.width,
11985
- width = _12 === void 0 ? 1 : _12,
11986
- _13 = _11.height,
11987
- height = _13 === void 0 ? 1 : _13;
11988
- var _14 = useCameraStore(),
11989
- camera = _14.camera,
11990
- videoRef = _14.videoRef,
11991
- videoLoaded = _14.videoLoaded,
11992
- cameraReady = _14.cameraReady,
11993
- microphoneReady = _14.microphoneReady,
11994
- audioStream = _14.audioStream,
11995
- isRearFacing = _14.isRearFacing,
11996
- releaseCameraAccess = _14.releaseCameraAccess;
11997
- var _15 = useState([]),
11998
- detectedObjects = _15[0],
11999
- setDetectedObjects = _15[1];
12000
- var _16 = useState(null),
12001
- face = _16[0],
12002
- setFace = _16[1];
12003
- var _17 = useContext(IdCaptureModelsContext),
12004
- idModelsReady = _17.ready,
12005
- startIdModels = _17.start,
12006
- stopIdModels = _17.stop,
12007
- onIdPredictionMade = _17.onPredictionMade,
12008
- setThresholds = _17.setThresholds,
12009
- setDocumentDetectionBoundaries = _17.setDocumentDetectionBoundaries,
12010
- bestFrameDetails = _17.bestFrameDetails,
12011
- resetBestFrame = _17.resetBestFrame,
12012
- idModelError = _17.modelError;
12013
- var _18 = useState(null),
12014
- videoStartsAt = _18[0],
12015
- setVideoStartsAt = _18[1];
12016
- var _19 = useContext(SubmissionContext),
12017
- setIdCaptureVideoAudioStartsAt = _19.setIdCaptureVideoAudioStartsAt,
12018
- setExpectedAudioText = _19.setExpectedAudioText;
12019
- var _20 = useContext(SelfieGuidanceModelsContext),
12020
- startSelfieGuidance = _20.start,
12021
- stopSelfieGuidance = _20.stop,
12022
- onSelfiePredictionMade = _20.onPredictionMade,
12023
- selfieModelError = _20.error;
12024
- var _21 = useVideoRecorder(camera, audioStream, mergeAVStreams),
12025
- isRecordingVideo = _21.isRecordingVideo,
12026
- startRecordingVideo = _21.startRecordingVideo,
12027
- startRecordingAudio = _21.startRecordingAudio,
12028
- stopRecordingVideo = _21.stopRecordingVideo,
12029
- stopRecordingAudio = _21.stopRecordingAudio,
12030
- videoRecordingUnintentionallyStopped = _21.videoRecordingUnintentionallyStopped,
12031
- audioRecordingUnintentionallyStopped = _21.audioRecordingUnintentionallyStopped,
12032
- videoUrl = _21.videoUrl,
12033
- audioUrl = _21.audioUrl;
11991
+ _3 = _a.readTextTimeoutDurationMs,
11992
+ readTextTimeoutDurationMs = _3 === void 0 ? 15000 : _3,
11993
+ _4 = _a.readTextMinReadingMs,
11994
+ readTextMinReadingMs = _4 === void 0 ? 10000 : _4,
11995
+ _5 = _a.disableFaceDetectionWhileAudioCapture,
11996
+ disableFaceDetectionWhileAudioCapture = _5 === void 0 ? false : _5,
11997
+ _6 = _a.disableFaceDetectionWhileAudioCaptureMsDelay,
11998
+ disableFaceDetectionWhileAudioCaptureMsDelay = _6 === void 0 ? 2000 : _6,
11999
+ _7 = _a.mergeAVStreams,
12000
+ mergeAVStreams = _7 === void 0 ? false : _7,
12001
+ _8 = _a.classNames,
12002
+ classNames = _8 === void 0 ? {} : _8,
12003
+ _9 = _a.colors,
12004
+ colors = _9 === void 0 ? {} : _9,
12005
+ _10 = _a.verbiage,
12006
+ rawVerbiage = _10 === void 0 ? {} : _10,
12007
+ _11 = _a.debugMode,
12008
+ debugMode = _11 === void 0 ? false : _11;
12009
+ var _12 = useResizeObserver(),
12010
+ ref = _12.ref,
12011
+ _13 = _12.width,
12012
+ width = _13 === void 0 ? 1 : _13,
12013
+ _14 = _12.height,
12014
+ height = _14 === void 0 ? 1 : _14;
12015
+ var _15 = useContext(CameraStateContext),
12016
+ cameraRef = _15.cameraRef,
12017
+ videoRef = _15.videoRef,
12018
+ videoLoaded = _15.videoLoaded,
12019
+ cameraReady = _15.cameraReady,
12020
+ microphoneReady = _15.microphoneReady,
12021
+ audioStream = _15.audioStream,
12022
+ setVideoLoaded = _15.setVideoLoaded;
12023
+ var _16 = useState([]),
12024
+ detectedObjects = _16[0],
12025
+ setDetectedObjects = _16[1];
12026
+ var _17 = useState(null),
12027
+ face = _17[0],
12028
+ setFace = _17[1];
12029
+ var _18 = useContext(IdCaptureModelsContext),
12030
+ idModelsReady = _18.ready,
12031
+ startIdModels = _18.start,
12032
+ stopIdModels = _18.stop,
12033
+ onIdPredictionMade = _18.onPredictionMade,
12034
+ setThresholds = _18.setThresholds,
12035
+ setDocumentDetectionBoundaries = _18.setDocumentDetectionBoundaries,
12036
+ bestFrameDetails = _18.bestFrameDetails,
12037
+ resetBestFrame = _18.resetBestFrame,
12038
+ idModelError = _18.modelError;
12039
+ var _19 = useState(null),
12040
+ videoStartsAt = _19[0],
12041
+ setVideoStartsAt = _19[1];
12042
+ var _20 = useContext(SubmissionContext),
12043
+ setIdCaptureVideoAudioStartsAt = _20.setIdCaptureVideoAudioStartsAt,
12044
+ setExpectedAudioText = _20.setExpectedAudioText;
12045
+ var _21 = useContext(SelfieGuidanceModelsContext),
12046
+ startSelfieGuidance = _21.start,
12047
+ stopSelfieGuidance = _21.stop,
12048
+ onSelfiePredictionMade = _21.onPredictionMade,
12049
+ selfieModelError = _21.error;
12050
+ var _22 = useVideoRecorder(cameraRef.current, audioStream, mergeAVStreams),
12051
+ isRecordingVideo = _22.isRecordingVideo,
12052
+ startRecordingVideo = _22.startRecordingVideo,
12053
+ startRecordingAudio = _22.startRecordingAudio,
12054
+ stopRecordingVideo = _22.stopRecordingVideo,
12055
+ stopRecordingAudio = _22.stopRecordingAudio,
12056
+ videoRecordingUnintentionallyStopped = _22.videoRecordingUnintentionallyStopped,
12057
+ audioRecordingUnintentionallyStopped = _22.audioRecordingUnintentionallyStopped,
12058
+ videoUrl = _22.videoUrl,
12059
+ audioUrl = _22.audioUrl;
12034
12060
  var countdownTimeoutRef = useRef(undefined);
12035
- var _22 = useState(-1),
12036
- countdownRemaining = _22[0],
12037
- setCountdownRemaining = _22[1];
12061
+ var _23 = useState(-1),
12062
+ countdownRemaining = _23[0],
12063
+ setCountdownRemaining = _23[1];
12038
12064
  useEffect(function () {
12039
12065
  if (!isRecordingVideo && !videoUrl) {
12040
12066
  startRecordingVideo();
@@ -12045,24 +12071,24 @@ var IdVideoCapture = function IdVideoCapture(_a) {
12045
12071
  var needsAudio = !!readTextPrompt && !mergeAVStreams;
12046
12072
  var audioReady = !needsAudio || audioUrl;
12047
12073
  if (videoUrl && audioReady) {
12048
- releaseCameraAccess();
12074
+ setVideoLoaded(false);
12049
12075
  onComplete === null || onComplete === void 0 ? void 0 : onComplete(videoUrl, audioUrl);
12050
12076
  }
12051
- }, [audioUrl, isRecordingVideo, mergeAVStreams, onComplete, readTextPrompt, releaseCameraAccess, startRecordingVideo, videoUrl]);
12077
+ }, [audioUrl, isRecordingVideo, mergeAVStreams, onComplete, readTextPrompt, setVideoLoaded, startRecordingVideo, videoUrl]);
12052
12078
  useEffect(function () {
12053
- if (videoRecordingUnintentionallyStopped || audioRecordingUnintentionallyStopped || !!readTextPrompt && !microphoneReady) {
12079
+ if (videoRecordingUnintentionallyStopped || audioRecordingUnintentionallyStopped) {
12054
12080
  onRecordingFailed === null || onRecordingFailed === void 0 ? void 0 : onRecordingFailed();
12055
12081
  }
12056
- }, [audioRecordingUnintentionallyStopped, microphoneReady, onRecordingFailed, readTextPrompt, videoRecordingUnintentionallyStopped]);
12057
- var _23 = useState('SHOW_ID_FRONT'),
12058
- requestedAction = _23[0],
12059
- setRequestedAction = _23[1];
12082
+ }, [audioRecordingUnintentionallyStopped, onRecordingFailed, videoRecordingUnintentionallyStopped]);
12083
+ var _24 = useState('SHOW_ID_FRONT'),
12084
+ requestedAction = _24[0],
12085
+ setRequestedAction = _24[1];
12060
12086
  var shouldRunIdModels = idCaptureModelsEnabled && videoLoaded && cameraReady && idModelsReady && !idModelError && requestedAction !== 'READ_TEXT' && (!readTextPrompt || microphoneReady);
12061
12087
  useEffect(function startModelsWhenCapturing() {
12062
12088
  if (!shouldRunIdModels) return;
12063
12089
  startIdModels();
12064
12090
  return function () {
12065
- return stopIdModels();
12091
+ stopIdModels();
12066
12092
  };
12067
12093
  }, [shouldRunIdModels, startIdModels, stopIdModels]);
12068
12094
  useEffect(function () {
@@ -12076,18 +12102,18 @@ var IdVideoCapture = function IdVideoCapture(_a) {
12076
12102
  bottom: 1
12077
12103
  });
12078
12104
  }, [setDocumentDetectionBoundaries]);
12079
- var _24 = useState(0),
12080
- currentDetectionScore = _24[0],
12081
- setCurrentDetectionScore = _24[1];
12082
- var _25 = useState('none'),
12083
- currentDetectedDocumentType = _25[0],
12084
- setCurrentDetectedDocumentType = _25[1];
12085
- var _26 = useState(0),
12086
- currentFocusScore = _26[0],
12087
- setCurrentFocusScore = _26[1];
12105
+ var _25 = useState(0),
12106
+ currentDetectionScore = _25[0],
12107
+ setCurrentDetectionScore = _25[1];
12108
+ var _26 = useState('none'),
12109
+ currentDetectedDocumentType = _26[0],
12110
+ setCurrentDetectedDocumentType = _26[1];
12088
12111
  var _27 = useState(0),
12089
- goodFramesCount = _27[0],
12090
- setGoodFramesCount = _27[1];
12112
+ currentFocusScore = _27[0],
12113
+ setCurrentFocusScore = _27[1];
12114
+ var _28 = useState(0),
12115
+ goodFramesCount = _28[0],
12116
+ setGoodFramesCount = _28[1];
12091
12117
  var goodFramesThreshold = requestedAction === 'SHOW_ID_FRONT' ? videoIdCaptureThresholds.goodFrames.idCardFront : videoIdCaptureThresholds.goodFrames.idCardBack;
12092
12118
  var goodFramesThresholdMet = goodFramesCount >= goodFramesThreshold;
12093
12119
  useEffect(function () {
@@ -12108,9 +12134,9 @@ var IdVideoCapture = function IdVideoCapture(_a) {
12108
12134
  } : 0);
12109
12135
  });
12110
12136
  }, [idCaptureModelsEnabled, onIdPredictionMade, idModelError, requestedAction, videoIdCaptureThresholds.flipShortcutThreshold]);
12111
- var _28 = useState(null),
12112
- idFrontCaptureStartedAt = _28[0],
12113
- setFirstGoodFrameTime = _28[1];
12137
+ var _29 = useState(null),
12138
+ idFrontCaptureStartedAt = _29[0],
12139
+ setFirstGoodFrameTime = _29[1];
12114
12140
  useEffect(function () {
12115
12141
  if (goodFramesCount === 1) setFirstGoodFrameTime(new Date().getTime());
12116
12142
  }, [goodFramesCount]);
@@ -12131,9 +12157,9 @@ var IdVideoCapture = function IdVideoCapture(_a) {
12131
12157
  var frameHeight = (_e = (_d = videoRef.current) === null || _d === void 0 ? void 0 : _d.videoHeight) !== null && _e !== void 0 ? _e : 0;
12132
12158
  var faceBox = face === null || face === void 0 ? void 0 : face.box;
12133
12159
  var faceCentered = !faceBox || !frameWidth || faceBox.xMin > frameWidth * edgeBoundary && faceBox.yMin > frameHeight * edgeBoundary && faceBox.xMax < frameWidth * (1 - edgeBoundary) && faceBox.yMax < frameHeight * (1 - edgeBoundary);
12134
- var _29 = useState(),
12135
- countdownStartedAt = _29[0],
12136
- setCountdownStartedAt = _29[1];
12160
+ var _30 = useState(),
12161
+ countdownStartedAt = _30[0],
12162
+ setCountdownStartedAt = _30[1];
12137
12163
  var photoCanvas = useRef(null);
12138
12164
  var frameLock = useRef(false);
12139
12165
  var captureFrame = useCallback(function () {
@@ -12256,9 +12282,9 @@ var IdVideoCapture = function IdVideoCapture(_a) {
12256
12282
  stopSelfieGuidance();
12257
12283
  };
12258
12284
  }, [startSelfieGuidance, stopSelfieGuidance]);
12259
- var _30 = useState(0),
12260
- numFramesWithoutFaces = _30[0],
12261
- setNumFramesWithoutFaces = _30[1];
12285
+ var _31 = useState(0),
12286
+ numFramesWithoutFaces = _31[0],
12287
+ setNumFramesWithoutFaces = _31[1];
12262
12288
  onSelfiePredictionMade(useThrottledCallback(useCallback(function (_a) {
12263
12289
  var face = _a.face;
12264
12290
  if (selfieModelError) return;
@@ -12274,12 +12300,12 @@ var IdVideoCapture = function IdVideoCapture(_a) {
12274
12300
  }
12275
12301
  }, [disableFaceDetectionWhileAudioCapture, disableFaceDetectionWhileAudioCaptureMsDelay, numFramesWithoutFaces, onFaceNotDetected, timeoutStartedAt]);
12276
12302
  var theme = useTheme();
12277
- var _31 = useTranslations(rawVerbiage, {
12303
+ var _32 = useTranslations(rawVerbiage, {
12278
12304
  faceNotCenteredText: 'Please move your face to the center...',
12279
12305
  captureBtnText: 'Capture'
12280
12306
  }),
12281
- captureBtnText = _31.captureBtnText,
12282
- faceNotCenteredText = _31.faceNotCenteredText;
12307
+ captureBtnText = _32.captureBtnText,
12308
+ faceNotCenteredText = _32.faceNotCenteredText;
12283
12309
  var debugScalingDetails = useDebugScalingDetails({
12284
12310
  enabled: debugMode,
12285
12311
  pageWidth: width,
@@ -12288,6 +12314,8 @@ var IdVideoCapture = function IdVideoCapture(_a) {
12288
12314
  videoHeight: (_j = (_h = videoRef.current) === null || _h === void 0 ? void 0 : _h.videoHeight) !== null && _j !== void 0 ? _j : 0
12289
12315
  });
12290
12316
  var capturingId = ['SHOW_ID_FRONT', 'SHOW_ID_BACK'].includes(requestedAction);
12317
+ // const searchingForIdCard =
12318
+ // idCaptureModelsEnabled && capturingId && !goodFramesThresholdMet
12291
12319
  var guidanceText = !faceCentered ? faceNotCenteredText : undefined;
12292
12320
  return /*#__PURE__*/React__default.createElement(PageContainer, {
12293
12321
  ref: ref,
@@ -12313,14 +12341,15 @@ var IdVideoCapture = function IdVideoCapture(_a) {
12313
12341
  faceGuideBorderColor: satisfied ? colors.guidesSatisfiedColor : colors.guidesUnsatisfiedColor,
12314
12342
  idCardGuideBorderColor: satisfied ? colors.guidesSatisfiedColor : colors.guidesUnsatisfiedColor
12315
12343
  }), debugMode && capturingId && ( /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(ObjectDetectionDebugOverlayDiv, {
12316
- "$flipX": !isRearFacing
12344
+ "$flipX": !((_l = cameraRef.current) === null || _l === void 0 ? void 0 : _l.isRearFacing)
12317
12345
  }, detectedObjects.map(function (obj, i) {
12346
+ var _a;
12318
12347
  return /*#__PURE__*/React__default.createElement(IdCaptureDetectedObjectDebugBox, {
12319
12348
  key: i,
12320
12349
  obj: obj,
12321
12350
  scaling: debugScalingDetails,
12322
12351
  color: "blue",
12323
- flipX: !isRearFacing
12352
+ flipX: !((_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.isRearFacing)
12324
12353
  });
12325
12354
  })), /*#__PURE__*/React__default.createElement(DebugBoundingBoxOverlay, null, face && ( /*#__PURE__*/React__default.createElement(SelfieCaptureFaceDebugBox, {
12326
12355
  face: face,
@@ -12329,9 +12358,9 @@ var IdVideoCapture = function IdVideoCapture(_a) {
12329
12358
  className: classNames.guidanceMessageContainer
12330
12359
  }, /*#__PURE__*/React__default.createElement(GuidanceMessage, {
12331
12360
  className: classNames.guidanceMessage,
12332
- "$background": (_o = (_m = (_l = theme.guidanceMessages) === null || _l === void 0 ? void 0 : _l.negative) === null || _m === void 0 ? void 0 : _m.backgroundColor) !== null && _o !== void 0 ? _o : 'red',
12333
- "$textColor": (_r = (_q = (_p = theme.guidanceMessages) === null || _p === void 0 ? void 0 : _p.negative) === null || _q === void 0 ? void 0 : _q.textColor) !== null && _r !== void 0 ? _r : 'white'
12334
- }, guidanceText))), debugMode && ( /*#__PURE__*/React__default.createElement(DebugStatsPane, null, camera ? ( /*#__PURE__*/React__default.createElement(React__default.Fragment, null, "\u2705 Camera: ", camera.label, " (", camera.width, "x", camera.height, ")")) : '❌ Camera not ready', /*#__PURE__*/React__default.createElement("br", null), isRecordingVideo ? '✅ Recording' : '❌ Not recording', /*#__PURE__*/React__default.createElement("br", null), goodFramesThresholdMet ? '✅' : '❌', " Good Frame Count:", ' ', goodFramesCount, "/", goodFramesThreshold, /*#__PURE__*/React__default.createElement("br", null), "Document Type: ", currentDetectedDocumentType, /*#__PURE__*/React__default.createElement("br", null), "Detection Score: ", currentDetectionScore, /*#__PURE__*/React__default.createElement("br", null), "Focus Score: ", currentFocusScore, /*#__PURE__*/React__default.createElement("br", null), "Best Frame Detection Score:", ' ', (_t = (_s = bestFrameDetails.current) === null || _s === void 0 ? void 0 : _s.detectionScore) !== null && _t !== void 0 ? _t : 0, /*#__PURE__*/React__default.createElement("br", null), "Best Frame Focus Score: ", (_v = (_u = bestFrameDetails.current) === null || _u === void 0 ? void 0 : _u.focusScore) !== null && _v !== void 0 ? _v : 0)), countdownRemaining > 0 && capturingId && ( /*#__PURE__*/React__default.createElement(CountdownContainer, {
12361
+ "$background": (_p = (_o = (_m = theme.guidanceMessages) === null || _m === void 0 ? void 0 : _m.negative) === null || _o === void 0 ? void 0 : _o.backgroundColor) !== null && _p !== void 0 ? _p : 'red',
12362
+ "$textColor": (_s = (_r = (_q = theme.guidanceMessages) === null || _q === void 0 ? void 0 : _q.negative) === null || _r === void 0 ? void 0 : _r.textColor) !== null && _s !== void 0 ? _s : 'white'
12363
+ }, guidanceText))), debugMode && ( /*#__PURE__*/React__default.createElement(DebugStatsPane, null, cameraRef.current ? ( /*#__PURE__*/React__default.createElement(React__default.Fragment, null, "\u2705 Camera: ", cameraRef.current.label, " (", cameraRef.current.width, "x", cameraRef.current.height, ")")) : '❌ Camera not ready', /*#__PURE__*/React__default.createElement("br", null), isRecordingVideo ? '✅ Recording' : '❌ Not recording', /*#__PURE__*/React__default.createElement("br", null), goodFramesThresholdMet ? '✅' : '❌', " Good Frame Count:", ' ', goodFramesCount, "/", goodFramesThreshold, /*#__PURE__*/React__default.createElement("br", null), "Document Type: ", currentDetectedDocumentType, /*#__PURE__*/React__default.createElement("br", null), "Detection Score: ", currentDetectionScore, /*#__PURE__*/React__default.createElement("br", null), "Focus Score: ", currentFocusScore, /*#__PURE__*/React__default.createElement("br", null), "Best Frame Detection Score:", ' ', (_u = (_t = bestFrameDetails.current) === null || _t === void 0 ? void 0 : _t.detectionScore) !== null && _u !== void 0 ? _u : 0, /*#__PURE__*/React__default.createElement("br", null), "Best Frame Focus Score: ", (_w = (_v = bestFrameDetails.current) === null || _v === void 0 ? void 0 : _v.focusScore) !== null && _w !== void 0 ? _w : 0)), countdownRemaining > 0 && capturingId && ( /*#__PURE__*/React__default.createElement(CountdownContainer, {
12335
12364
  className: classNames.countdownContainer
12336
12365
  }, /*#__PURE__*/React__default.createElement(Countdown, {
12337
12366
  className: classNames.countdown
@@ -12340,7 +12369,7 @@ var IdVideoCapture = function IdVideoCapture(_a) {
12340
12369
  }, /*#__PURE__*/React__default.createElement(CaptureButton, {
12341
12370
  finished: true,
12342
12371
  onClick: function onClick() {
12343
- return setCountdownStartedAt(new Date());
12372
+ setCountdownStartedAt(new Date());
12344
12373
  },
12345
12374
  disabled: !!countdownStartedAt || frameLock.current,
12346
12375
  className: classNames.captureBtn
@@ -12628,14 +12657,16 @@ var VideoIdWizard = function VideoIdWizard(_a) {
12628
12657
  className: "flex"
12629
12658
  }, /*#__PURE__*/React__default.createElement(Spinner, null));
12630
12659
  }
12631
- return /*#__PURE__*/React__default.createElement(CameraStoreProvider, {
12632
- preferIphoneContinuityCamera: isCapturingId,
12660
+ return /*#__PURE__*/React__default.createElement(CameraProvider, {
12661
+ key: "".concat(isCapturingId ? 'id' : 'selfie', "-camera-").concat(attempt),
12662
+ preferContinuityCamera: isCapturingId,
12633
12663
  preferFrontFacingCamera: !isCapturingId,
12634
12664
  requireMicrophoneAccess: !isCapturingId && !!readTextPrompt,
12635
12665
  maxVideoWidth: isCapturingId ? 1920 : 1280,
12636
12666
  maxFps: isCapturingId ? 60 : 30,
12637
12667
  onCameraAccessDenied: onCameraAccessDenied,
12638
- onMicrophoneAccessDenied: onMicrophoneAccessDenied
12668
+ onMicrophoneAccessDenied: onMicrophoneAccessDenied,
12669
+ debugMode: debugMode
12639
12670
  }, /*#__PURE__*/React__default.createElement(IdCaptureModelsProvider, {
12640
12671
  autoStart: false,
12641
12672
  documentDetectionModelUrl: (_g = (_f = idCaptureProps.assets) === null || _f === void 0 ? void 0 : _f.documentDetectionModelUrl) !== null && _g !== void 0 ? _g : '',
@@ -12646,7 +12677,7 @@ var VideoIdWizard = function VideoIdWizard(_a) {
12646
12677
  autoStart: false,
12647
12678
  onModelError: faceLivenessProps === null || faceLivenessProps === void 0 ? void 0 : faceLivenessProps.onModelError,
12648
12679
  modelLoadTimeoutMs: faceLivenessProps === null || faceLivenessProps === void 0 ? void 0 : faceLivenessProps.modelLoadTimeoutMs,
12649
- requireVerticalFaceCentering: false
12680
+ requireVerticalFaceCentering: captureState === 'CHECKING_LIVENESS'
12650
12681
  }, /*#__PURE__*/React__default.createElement(PageContainer, {
12651
12682
  className: "flex ".concat((_k = classNames.container) !== null && _k !== void 0 ? _k : '')
12652
12683
  }, ['CHECKING_LIVENESS', 'CAPTURING_VIDEO'].includes(captureState) && /*#__PURE__*/React__default.createElement(CameraVideoTag, {
@@ -12761,15 +12792,17 @@ function CompositeWizard(_a) {
12761
12792
  _o = _a.captureSignatureVideo,
12762
12793
  captureSignatureVideo = _o === void 0 ? false : _o,
12763
12794
  onCameraAccessDenied = _a.onCameraAccessDenied,
12764
- onMicrophoneAccessDenied = _a.onMicrophoneAccessDenied;
12765
- var _p = useContext(SubmissionContext),
12766
- submit = _p.submit,
12767
- submissionStatus = _p.submissionStatus,
12768
- setSignatureData = _p.setSignatureData,
12769
- setAdditionalDocuments = _p.setAdditionalDocuments;
12770
- var _q = useState(0),
12771
- checkIndex = _q[0],
12772
- setCheckIndex = _q[1];
12795
+ onMicrophoneAccessDenied = _a.onMicrophoneAccessDenied,
12796
+ _p = _a.debugMode,
12797
+ debugMode = _p === void 0 ? false : _p;
12798
+ var _q = useContext(SubmissionContext),
12799
+ submit = _q.submit,
12800
+ submissionStatus = _q.submissionStatus,
12801
+ setSignatureData = _q.setSignatureData,
12802
+ setAdditionalDocuments = _q.setAdditionalDocuments;
12803
+ var _r = useState(0),
12804
+ checkIndex = _r[0],
12805
+ setCheckIndex = _r[1];
12773
12806
  var checks = useMemo(function () {
12774
12807
  var _a, _b;
12775
12808
  var checks = __spreadArray([], userChecks, true);
@@ -12847,6 +12880,16 @@ function CompositeWizard(_a) {
12847
12880
  return i + 1;
12848
12881
  });
12849
12882
  }, [onVideoSignatureCompleteProp]);
12883
+ var _s = useState(0),
12884
+ videoSignatureAttempts = _s[0],
12885
+ setVideoSignatureAttempts = _s[1];
12886
+ var onVideoSignatureRetryProp = videoSignatureCaptureProps.onRetryClicked;
12887
+ var onVideoSignatureRetry = useCallback(function () {
12888
+ onVideoSignatureRetryProp === null || onVideoSignatureRetryProp === void 0 ? void 0 : onVideoSignatureRetryProp();
12889
+ setVideoSignatureAttempts(function (n) {
12890
+ return n + 1;
12891
+ });
12892
+ }, [onVideoSignatureRetryProp]);
12850
12893
  var onAdditionalDocumentCaptureCompleteProp = additionalDocumentCaptureProps === null || additionalDocumentCaptureProps === void 0 ? void 0 : additionalDocumentCaptureProps.onComplete;
12851
12894
  var onAdditionalDocumentCaptureComplete = useCallback(function (uploadedDocuments) {
12852
12895
  setAdditionalDocuments(uploadedDocuments);
@@ -12875,9 +12918,11 @@ function CompositeWizard(_a) {
12875
12918
  }
12876
12919
  switch (checks[checkIndex]) {
12877
12920
  case 'IdCapture':
12878
- return /*#__PURE__*/React__default.createElement(CameraStoreProvider, {
12921
+ return /*#__PURE__*/React__default.createElement(CameraProvider, {
12922
+ key: "IdCaptureCamera",
12879
12923
  onCameraAccessDenied: onCameraAccessDenied,
12880
- onMicrophoneAccessDenied: onMicrophoneAccessDenied
12924
+ onMicrophoneAccessDenied: onMicrophoneAccessDenied,
12925
+ debugMode: debugMode
12881
12926
  }, /*#__PURE__*/React__default.createElement(IdCaptureModelsProvider, {
12882
12927
  autoStart: false,
12883
12928
  documentDetectionModelUrl: (_d = (_c = idCaptureProps.assets) === null || _c === void 0 ? void 0 : _c.documentDetectionModelUrl) !== null && _d !== void 0 ? _d : '',
@@ -12894,11 +12939,13 @@ function CompositeWizard(_a) {
12894
12939
  onMicrophoneAccessDenied: onMicrophoneAccessDenied
12895
12940
  }));
12896
12941
  case 'FaceLiveness':
12897
- return /*#__PURE__*/React__default.createElement(CameraStoreProvider, {
12942
+ return /*#__PURE__*/React__default.createElement(CameraProvider, {
12943
+ key: "FaceLivenessCamera",
12898
12944
  preferFrontFacingCamera: true,
12899
- preferIphoneContinuityCamera: false,
12945
+ preferContinuityCamera: false,
12900
12946
  onCameraAccessDenied: onCameraAccessDenied,
12901
- onMicrophoneAccessDenied: onMicrophoneAccessDenied
12947
+ onMicrophoneAccessDenied: onMicrophoneAccessDenied,
12948
+ debugMode: debugMode
12902
12949
  }, /*#__PURE__*/React__default.createElement(SelfieGuidanceModelsProvider, {
12903
12950
  autoStart: false,
12904
12951
  onModelError: faceLivenessProps.onModelError,
@@ -12911,13 +12958,15 @@ function CompositeWizard(_a) {
12911
12958
  onAccept: onSignatureCaptureSuccess
12912
12959
  }));
12913
12960
  case 'VideoSignatureCapture':
12914
- return /*#__PURE__*/React__default.createElement(CameraStoreProvider, {
12915
- preferIphoneContinuityCamera: false,
12961
+ return /*#__PURE__*/React__default.createElement(CameraProvider, {
12962
+ key: "SignatureKycCamera-".concat(videoSignatureAttempts),
12963
+ preferContinuityCamera: false,
12916
12964
  preferFrontFacingCamera: true,
12917
12965
  maxVideoWidth: 1280,
12918
12966
  maxFps: 30,
12919
12967
  onCameraAccessDenied: onCameraAccessDenied,
12920
- onMicrophoneAccessDenied: onMicrophoneAccessDenied
12968
+ onMicrophoneAccessDenied: onMicrophoneAccessDenied,
12969
+ debugMode: debugMode
12921
12970
  }, /*#__PURE__*/React__default.createElement(SelfieGuidanceModelsProvider, {
12922
12971
  autoStart: false,
12923
12972
  throttleMs: 250,
@@ -12925,7 +12974,8 @@ function CompositeWizard(_a) {
12925
12974
  modelLoadTimeoutMs: videoSignatureCaptureProps.modelLoadTimeoutMs,
12926
12975
  requireVerticalFaceCentering: false
12927
12976
  }, /*#__PURE__*/React__default.createElement(VideoSignatureWizard, _assign({}, videoSignatureCaptureProps, {
12928
- onComplete: onVideoSignatureComplete
12977
+ onComplete: onVideoSignatureComplete,
12978
+ onRetryClicked: onVideoSignatureRetry
12929
12979
  }))));
12930
12980
  case 'AdditionalDocumentCapture':
12931
12981
  return /*#__PURE__*/React__default.createElement(AdditionalDocumentCaptureWizard, _assign({}, additionalDocumentCaptureProps, {
@@ -13376,7 +13426,8 @@ var IdValidation = function IdValidation(_a) {
13376
13426
  videoSignatureCaptureProps: videoSignatureCaptureProps,
13377
13427
  captureSignature: captureSignature,
13378
13428
  captureSignatureVideo: captureSignatureVideo,
13379
- onCameraAccessDenied: onCameraAccessDenied
13429
+ onCameraAccessDenied: onCameraAccessDenied,
13430
+ debugMode: debugMode
13380
13431
  }))));
13381
13432
  };
13382
13433
 
@@ -13482,7 +13533,8 @@ var FaceValidation = function FaceValidation(_a) {
13482
13533
  return ['FaceLiveness'];
13483
13534
  }, []),
13484
13535
  faceLivenessProps: faceLivenessProps,
13485
- onCameraAccessDenied: onCameraAccessDenied
13536
+ onCameraAccessDenied: onCameraAccessDenied,
13537
+ debugMode: debugMode
13486
13538
  }))));
13487
13539
  };
13488
13540
 
@@ -13715,7 +13767,8 @@ var IdAndFaceValidation = function IdAndFaceValidation(_a) {
13715
13767
  additionalDocumentCaptureProps: additionalDocumentCaptureProps,
13716
13768
  captureSignature: captureSignature,
13717
13769
  captureSignatureVideo: captureSignatureVideo,
13718
- onCameraAccessDenied: onCameraAccessDenied
13770
+ onCameraAccessDenied: onCameraAccessDenied,
13771
+ debugMode: debugMode
13719
13772
  }))));
13720
13773
  };
13721
13774
 
@@ -13970,7 +14023,8 @@ var CustomerIdAndBiometricsEnrollment = function CustomerIdAndBiometricsEnrollme
13970
14023
  videoSignatureCaptureProps: videoSignatureCaptureProps,
13971
14024
  captureSignature: captureSignature,
13972
14025
  captureSignatureVideo: captureSignatureVideo,
13973
- onCameraAccessDenied: onCameraAccessDenied
14026
+ onCameraAccessDenied: onCameraAccessDenied,
14027
+ debugMode: debugMode
13974
14028
  }))));
13975
14029
  };
13976
14030
 
@@ -14302,7 +14356,7 @@ var CustomerVerificationWizard = function CustomerVerificationWizard(_a) {
14302
14356
  var _l = useState('LOADING'),
14303
14357
  captureState = _l[0],
14304
14358
  setCaptureState = _l[1];
14305
- var _m = useCameraStore(),
14359
+ var _m = useContext(CameraStateContext),
14306
14360
  cameraAccessDenied = _m.cameraAccessDenied,
14307
14361
  releaseCameraAccess = _m.releaseCameraAccess;
14308
14362
  var _o = useContext(SelfieGuidanceModelsContext),
@@ -14508,9 +14562,10 @@ var CustomerVerification = function CustomerVerification(_a) {
14508
14562
  onSubmit: onSubmit,
14509
14563
  geolocationEnabled: geolocationEnabled,
14510
14564
  geolocationRequired: geolocationRequired
14511
- }, /*#__PURE__*/React__default.createElement(CameraStoreProvider, {
14565
+ }, /*#__PURE__*/React__default.createElement(CameraProvider, {
14512
14566
  preferFrontFacingCamera: true,
14513
- onCameraAccessDenied: onCameraAccessDenied
14567
+ onCameraAccessDenied: onCameraAccessDenied,
14568
+ debugMode: debugMode
14514
14569
  }, /*#__PURE__*/React__default.createElement(SelfieGuidanceModelsProvider, {
14515
14570
  autoStart: false,
14516
14571
  onModelError: onModelError,
@@ -14859,7 +14914,7 @@ var CustomerIdentificationWizard = function CustomerIdentificationWizard(_a) {
14859
14914
  var _l = useState('LOADING'),
14860
14915
  captureState = _l[0],
14861
14916
  setCaptureState = _l[1];
14862
- var _m = useCameraStore(),
14917
+ var _m = useContext(CameraStateContext),
14863
14918
  cameraAccessDenied = _m.cameraAccessDenied,
14864
14919
  releaseCameraAccess = _m.releaseCameraAccess;
14865
14920
  var _o = useContext(SelfieGuidanceModelsContext),
@@ -15063,9 +15118,10 @@ var CustomerIdentification = function CustomerIdentification(_a) {
15063
15118
  onSubmit: onSubmit,
15064
15119
  geolocationEnabled: geolocationEnabled,
15065
15120
  geolocationRequired: geolocationRequired
15066
- }, /*#__PURE__*/React__default.createElement(CameraStoreProvider, {
15121
+ }, /*#__PURE__*/React__default.createElement(CameraProvider, {
15067
15122
  preferFrontFacingCamera: true,
15068
- onCameraAccessDenied: onCameraAccessDenied
15123
+ onCameraAccessDenied: onCameraAccessDenied,
15124
+ debugMode: debugMode
15069
15125
  }, /*#__PURE__*/React__default.createElement(SelfieGuidanceModelsProvider, {
15070
15126
  autoStart: false,
15071
15127
  modelLoadTimeoutMs: modelLoadTimeoutMs,
@@ -15392,7 +15448,8 @@ var VideoIdValidation = function VideoIdValidation(_a) {
15392
15448
  captureSignature: captureSignature,
15393
15449
  captureSignatureVideo: captureSignatureVideo,
15394
15450
  onCameraAccessDenied: onCameraAccessDenied,
15395
- onMicrophoneAccessDenied: onMicrophoneAccessDenied
15451
+ onMicrophoneAccessDenied: onMicrophoneAccessDenied,
15452
+ debugMode: debugMode
15396
15453
  }))));
15397
15454
  };
15398
15455
 
@@ -15549,7 +15606,8 @@ var CustomerBiometricsEnrollment = function CustomerBiometricsEnrollment(_a) {
15549
15606
  videoSignatureCaptureProps: videoSignatureCaptureProps,
15550
15607
  captureSignature: captureSignature,
15551
15608
  captureSignatureVideo: captureSignatureVideo,
15552
- onCameraAccessDenied: onCameraAccessDenied
15609
+ onCameraAccessDenied: onCameraAccessDenied,
15610
+ debugMode: debugMode
15553
15611
  }))));
15554
15612
  };
15555
15613
 
@@ -15607,10 +15665,11 @@ var DocumentCapture = function DocumentCapture(_a) {
15607
15665
  onDocumentUploadFailed: onDocumentUploadFailed,
15608
15666
  geolocationEnabled: geolocationEnabled,
15609
15667
  geolocationRequired: geolocationRequired
15610
- }, /*#__PURE__*/React__default.createElement(CameraStoreProvider, {
15668
+ }, /*#__PURE__*/React__default.createElement(CameraProvider, {
15611
15669
  requestAccessAutomatically: false,
15612
- preferIphoneContinuityCamera: true,
15613
- onCameraAccessDenied: onCameraAccessDenied
15670
+ preferContinuityCamera: true,
15671
+ onCameraAccessDenied: onCameraAccessDenied,
15672
+ debugMode: debugMode
15614
15673
  }, /*#__PURE__*/React__default.createElement(DocumentCaptureWizard, {
15615
15674
  onSuccess: onComplete,
15616
15675
  onExitCapture: onExitCapture,