idmission-web-sdk 2.2.47 → 2.2.48

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 (64) hide show
  1. package/dist/components/CompositeWizard.d.ts +1 -2
  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/CameraVideoTag.d.ts +2 -4
  5. package/dist/components/camera/CameraVideoTag.d.ts.map +1 -1
  6. package/dist/components/camera/MicrophoneAccessDeniedOverlay.d.ts.map +1 -1
  7. package/dist/components/customer_flows/CustomerBiometricsEnrollment.d.ts.map +1 -1
  8. package/dist/components/customer_flows/CustomerIdAndBiometricsEnrollment.d.ts.map +1 -1
  9. package/dist/components/customer_flows/CustomerIdentification.d.ts.map +1 -1
  10. package/dist/components/customer_flows/CustomerVerification.d.ts.map +1 -1
  11. package/dist/components/customer_flows/DocumentCapture.d.ts.map +1 -1
  12. package/dist/components/customer_flows/FaceValidation.d.ts.map +1 -1
  13. package/dist/components/customer_flows/IdAndFaceValidation.d.ts.map +1 -1
  14. package/dist/components/customer_flows/IdValidation.d.ts.map +1 -1
  15. package/dist/components/customer_flows/VideoIdValidation.d.ts.map +1 -1
  16. package/dist/components/customer_identification/CustomerIdentificationWizard.d.ts +1 -1
  17. package/dist/components/customer_identification/CustomerIdentificationWizard.d.ts.map +1 -1
  18. package/dist/components/customer_verification/CustomerVerificationWizard.d.ts.map +1 -1
  19. package/dist/components/document_capture/DocumentCaptureScreen.d.ts.map +1 -1
  20. package/dist/components/document_capture/DocumentCaptureStateProvider.d.ts.map +1 -1
  21. package/dist/components/face_liveness/FaceLivenessWizard.d.ts.map +1 -1
  22. package/dist/components/id_capture/DocumentDetectionModelProvider.d.ts.map +1 -1
  23. package/dist/components/id_capture/FocusModelProvider.d.ts.map +1 -1
  24. package/dist/components/id_capture/IdCapture.d.ts.map +1 -1
  25. package/dist/components/id_capture/IdCaptureGuides.d.ts.map +1 -1
  26. package/dist/components/id_capture/IdCaptureLoadingOverlayDefault.d.ts.map +1 -1
  27. package/dist/components/id_capture/IdCaptureLoadingOverlayLegacy.d.ts.map +1 -1
  28. package/dist/components/id_capture/IdCaptureWizard.d.ts.map +1 -1
  29. package/dist/components/selfie_capture/SelfieCapture.d.ts.map +1 -1
  30. package/dist/components/selfie_capture/SelfieCaptureLoadingOverlayDefault.d.ts.map +1 -1
  31. package/dist/components/selfie_capture/SelfieCaptureLoadingOverlayLegacy.d.ts.map +1 -1
  32. package/dist/components/selfie_capture/SelfieGuidanceModelsProvider.d.ts.map +1 -1
  33. package/dist/components/video_id/IdVideoCapture.d.ts.map +1 -1
  34. package/dist/components/video_id/IdVideoCaptureFlipIdPrompt.d.ts.map +1 -1
  35. package/dist/components/video_id/IdVideoCaptureGuides.d.ts.map +1 -1
  36. package/dist/components/video_id/IdVideoCaptureWizard.d.ts.map +1 -1
  37. package/dist/components/video_signature_capture/VideoSignatureCapture.d.ts.map +1 -1
  38. package/dist/components/video_signature_capture/VideoSignatureWizard.d.ts.map +1 -1
  39. package/dist/lib/camera/Camera.d.ts +4 -0
  40. package/dist/lib/camera/Camera.d.ts.map +1 -1
  41. package/dist/lib/camera/cameraStore.d.ts +52 -0
  42. package/dist/lib/camera/cameraStore.d.ts.map +1 -0
  43. package/dist/lib/camera/videoRefStack.d.ts +6 -0
  44. package/dist/lib/camera/videoRefStack.d.ts.map +1 -0
  45. package/dist/lib/models/DocumentDetection.d.ts +3 -1
  46. package/dist/lib/models/DocumentDetection.d.ts.map +1 -1
  47. package/dist/lib/models/FaceDetection.d.ts +3 -1
  48. package/dist/lib/models/FaceDetection.d.ts.map +1 -1
  49. package/dist/lib/models/Focus.d.ts +3 -1
  50. package/dist/lib/models/Focus.d.ts.map +1 -1
  51. package/dist/sdk2.cjs.development.js +1132 -1073
  52. package/dist/sdk2.cjs.development.js.map +1 -1
  53. package/dist/sdk2.cjs.production.js +1 -1
  54. package/dist/sdk2.cjs.production.js.map +1 -1
  55. package/dist/sdk2.esm.js +1132 -1073
  56. package/dist/sdk2.esm.js.map +1 -1
  57. package/dist/sdk2.umd.development.js +1150 -1091
  58. package/dist/sdk2.umd.development.js.map +1 -1
  59. package/dist/sdk2.umd.production.js +1 -1
  60. package/dist/sdk2.umd.production.js.map +1 -1
  61. package/dist/version.d.ts +1 -1
  62. package/package.json +1 -1
  63. package/dist/components/camera/CameraProvider.d.ts +0 -17
  64. package/dist/components/camera/CameraProvider.d.ts.map +0 -1
@@ -232,7 +232,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
232
232
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
233
233
  };
234
234
 
235
- var webSdkVersion = '2.2.47';
235
+ var webSdkVersion = '2.2.48';
236
236
 
237
237
  function getPlatform() {
238
238
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -801,11 +801,11 @@ function setDefaultAuthUrl(url) {
801
801
  if (!allowedAuthUrls.includes(url)) throw new Error('invalid auth url');
802
802
  exports.defaultAuthUrl = url;
803
803
  }
804
- var initialState$5 = {
804
+ var initialState$6 = {
805
805
  authUrl: exports.defaultAuthUrl,
806
806
  sessionCheckState: 'READY'
807
807
  };
808
- var AuthStateContext = /*#__PURE__*/React.createContext(initialState$5);
808
+ var AuthStateContext = /*#__PURE__*/React.createContext(initialState$6);
809
809
  var AuthDispatchContext = /*#__PURE__*/React.createContext(function () {});
810
810
  var reducer$4 = function reducer(state, action) {
811
811
  switch (action.type) {
@@ -837,7 +837,7 @@ function useAuthReducer(authUrl, sessionId) {
837
837
  if (authUrl === void 0) {
838
838
  authUrl = exports.defaultAuthUrl;
839
839
  }
840
- var _a = React.useReducer(reducer$4, _assign(_assign({}, initialState$5), {
840
+ var _a = React.useReducer(reducer$4, _assign(_assign({}, initialState$6), {
841
841
  authUrl: authUrl
842
842
  })),
843
843
  state = _a[0],
@@ -1889,636 +1889,34 @@ function createUpload(blob, options) {
1889
1889
  typeof window.tus !== 'undefined' ? window.tus.Upload : tusJsClient.Upload;
1890
1890
  return new UploadType(blob, options);
1891
1891
  }
1892
- function convertBase64ToBlob(base64Image) {
1893
- // Split into two parts
1894
- var parts = base64Image.split(';base64,');
1895
- // Hold the content type
1896
- var imageType = parts[0].split(':')[1];
1897
- // Decode Base64 string
1898
- var decodedData = window.atob(parts[1]);
1899
- // Create UNIT8ARRAY of size same as row data length
1900
- var uInt8Array = new Uint8Array(decodedData.length);
1901
- // Insert all character code into uInt8Array
1902
- for (var i = 0; i < decodedData.length; ++i) {
1903
- uInt8Array[i] = decodedData.charCodeAt(i);
1904
- }
1905
- // Return BLOB image after conversion
1906
- return new Blob([uInt8Array], {
1907
- type: imageType
1908
- });
1909
- }
1910
- function calculateMd5(blob) {
1911
- return new Promise(function (resolve, reject) {
1912
- var reader = new FileReader();
1913
- reader.readAsArrayBuffer(blob);
1914
- reader.onloadend = function () {
1915
- if (!reader.result) return reject(new Error('Failed to read file'));
1916
- resolve(SparkMD5__default.default.ArrayBuffer.hash(reader.result));
1917
- };
1918
- });
1919
- }
1920
-
1921
- function getFrameDimensions(frame) {
1922
- var frameWidth = frame.width,
1923
- frameHeight = frame.height;
1924
- if (frame instanceof HTMLImageElement) {
1925
- frameWidth = frame.naturalWidth;
1926
- frameHeight = frame.naturalHeight;
1927
- }
1928
- if (frame instanceof HTMLVideoElement) {
1929
- frameWidth = frame.videoWidth;
1930
- frameHeight = frame.videoHeight;
1931
- }
1932
- return [frameWidth, frameHeight];
1933
- }
1934
-
1935
- var InvisibleCanvas = styled__default.default.canvas(templateObject_1$G || (templateObject_1$G = __makeTemplateObject(["\n display: none;\n"], ["\n display: none;\n"])));
1936
- function drawToCanvas(canvas, frame, width, height) {
1937
- if (!canvas) return;
1938
- var ctx = canvas.getContext('2d');
1939
- if (!ctx) return;
1940
- if (!width || !height) {
1941
- var _a = getFrameDimensions(frame),
1942
- frameWidth = _a[0],
1943
- frameHeight = _a[1];
1944
- width || (width = frameWidth);
1945
- height || (height = frameHeight);
1946
- }
1947
- canvas.width = width;
1948
- canvas.height = height;
1949
- ctx.drawImage(frame, 0, 0, width, height);
1950
- }
1951
- function clearCanvas(canvas) {
1952
- var _a;
1953
- (_a = canvas === null || canvas === void 0 ? void 0 : canvas.getContext('2d')) === null || _a === void 0 ? void 0 : _a.clearRect(0, 0, canvas === null || canvas === void 0 ? void 0 : canvas.width, canvas === null || canvas === void 0 ? void 0 : canvas.height);
1954
- }
1955
- var templateObject_1$G;
1956
-
1957
- function listAvailableCameras(facingMode_1) {
1958
- return __awaiter(this, arguments, void 0, function (facingMode, requestMicAccess) {
1959
- var cameraEnumerationStream, videoDevices;
1960
- if (requestMicAccess === void 0) {
1961
- requestMicAccess = false;
1962
- }
1963
- return __generator(this, function (_a) {
1964
- switch (_a.label) {
1965
- case 0:
1966
- return [4 /*yield*/, navigator.mediaDevices.getUserMedia({
1967
- video: {
1968
- facingMode: {
1969
- exact: facingMode
1970
- }
1971
- },
1972
- audio: requestMicAccess
1973
- })
1974
- // This lists all available cameras attached to the user's device.
1975
- ];
1976
- case 1:
1977
- cameraEnumerationStream = _a.sent();
1978
- return [4 /*yield*/, navigator.mediaDevices.enumerateDevices()];
1979
- case 2:
1980
- videoDevices = _a.sent().filter(function (_a) {
1981
- var kind = _a.kind;
1982
- return kind === 'videoinput';
1983
- });
1984
- // Release the access to the user's camera that we obtained for enumeration purposes.
1985
- cameraEnumerationStream.getVideoTracks().forEach(function (track) {
1986
- track.enabled = false;
1987
- track.stop();
1988
- });
1989
- cameraEnumerationStream = null;
1990
- return [2 /*return*/, videoDevices];
1991
- }
1992
- });
1993
- });
1994
- }
1995
- 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) {
1996
- return s.toLocaleLowerCase().split(' ').join('');
1997
- });
1998
- 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) {
1999
- return s.toLocaleLowerCase().split(' ').join('');
2000
- });
2001
- 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) {
2002
- return s.toLocaleLowerCase().split(' ').join('');
2003
- });
2004
- var labelMatches = function labelMatches(labelOrDevice, labelSetOrLabel) {
2005
- var label = labelOrDevice instanceof MediaDeviceInfo ? getDeviceLabel(labelOrDevice) : labelOrDevice;
2006
- var labelSet = typeof labelSetOrLabel === 'string' ? [labelSetOrLabel] : labelSetOrLabel;
2007
- return labelSet.some(function (l) {
2008
- return label.includes(l);
2009
- });
2010
- };
2011
- var getDeviceLabel = function getDeviceLabel(deviceInfo) {
2012
- return deviceInfo.label.toLocaleLowerCase().split(' ').join('');
2013
- };
2014
- var currentCamera;
2015
- var currentAudioStream;
2016
- function obtainCameraAccess(stream, deviceLabel, video) {
2017
- releaseCameraAccess();
2018
- log('obtaining camera access...');
2019
- var _a = stream.getVideoTracks()[0].getSettings(),
2020
- width = _a.width,
2021
- height = _a.height;
2022
- var label = deviceLabel.toLocaleLowerCase().split(' ').join('');
2023
- var isRearFacing = labelMatches(label, __spreadArray(__spreadArray(__spreadArray([], rearLabels, true), backUltraWideLabels, true), ['iphone'], false));
2024
- var release = function release() {
2025
- stream.getTracks().forEach(function (track) {
2026
- track.enabled = false;
2027
- track.stop();
2028
- });
2029
- if (video) {
2030
- video.pause();
2031
- video.srcObject = null;
2032
- video.src = '';
2033
- }
2034
- };
2035
- width || (width = 0);
2036
- height || (height = 0);
2037
- currentCamera = {
2038
- label: deviceLabel,
2039
- stream: stream,
2040
- width: width,
2041
- height: height,
2042
- isRearFacing: isRearFacing,
2043
- release: release
2044
- };
2045
- if (video) video.srcObject = stream;
2046
- return currentCamera;
2047
- }
2048
- function releaseCameraAccess() {
2049
- if (!currentCamera) return;
2050
- log('releasing camera access...');
2051
- currentCamera.release();
2052
- currentCamera = undefined;
2053
- }
2054
- function releaseMicrophoneAccess() {
2055
- var _a;
2056
- if (!currentAudioStream) return;
2057
- log('releasing microphone access...');
2058
- (_a = currentAudioStream.stop) === null || _a === void 0 ? void 0 : _a.call(currentAudioStream);
2059
- currentAudioStream.getAudioTracks().forEach(function (t) {
2060
- var _a;
2061
- (_a = t.stop) === null || _a === void 0 ? void 0 : _a.call(t);
2062
- });
2063
- currentAudioStream = undefined;
2064
- }
2065
- function usePreferredCaptureDevice(_a) {
2066
- var _b = _a === void 0 ? {} : _a,
2067
- _c = _b.requestAccessAutomatically,
2068
- requestAccessAutomatically = _c === void 0 ? true : _c,
2069
- _d = _b.preferFrontFacingCamera,
2070
- preferFrontFacingCamera = _d === void 0 ? false : _d,
2071
- _e = _b.preferContinuityCamera,
2072
- preferContinuityCamera = _e === void 0 ? true : _e,
2073
- _f = _b.requireMicrophoneAccess,
2074
- requireMicrophoneAccess = _f === void 0 ? false : _f,
2075
- _g = _b.maxVideoWidth,
2076
- maxVideoWidth = _g === void 0 ? 1920 : _g,
2077
- maxFps = _b.maxFps,
2078
- _h = _b.debugMode,
2079
- debugMode = _h === void 0 ? false : _h;
2080
- var videoRef = React.useRef(null);
2081
- var videoRefStack = React.useRef([]);
2082
- var cameraRef = React.useRef(null);
2083
- var _j = React.useState(false),
2084
- cameraReady = _j[0],
2085
- setCameraReady = _j[1];
2086
- var _k = React.useState(false),
2087
- microphoneReady = _k[0],
2088
- setMicrophoneReady = _k[1];
2089
- var _l = React.useState(null),
2090
- videoDevice = _l[0],
2091
- setVideoDevice = _l[1];
2092
- var _m = React.useState(null),
2093
- audioStream = _m[0],
2094
- setAudioStream = _m[1];
2095
- var _o = React.useState(false),
2096
- videoLoaded = _o[0],
2097
- setVideoLoaded = _o[1];
2098
- var _p = React.useState(false),
2099
- iphoneContinuityCameraAvailable = _p[0],
2100
- setIphoneContinuityCameraAvailable = _p[1];
2101
- var _q = React.useState(preferContinuityCamera),
2102
- iphoneContinuityCameraAllowed = _q[0],
2103
- setIphoneContinuityCameraAllowed = _q[1];
2104
- var _r = React.useState(false),
2105
- iphoneContinuityCameraDenied = _r[0],
2106
- setIphoneContinuityCameraDenied = _r[1];
2107
- var _s = React.useState(false),
2108
- cameraAccessDenied = _s[0],
2109
- setCameraAccessDenied = _s[1];
2110
- var _t = React.useState(false),
2111
- microphoneAccessDenied = _t[0],
2112
- setMicrophoneAccessDenied = _t[1];
2113
- var videoRefElement = videoRef.current;
2114
- React.useEffect(function pushVideoRefToStackWhenChanged() {
2115
- // proceed if the video element being mounted is not already at the top of the videoRefStack.
2116
- var topOfStack = videoRefStack.current.slice(-1)[0];
2117
- if (videoRefElement && videoRefElement !== topOfStack) {
2118
- log('adding video to stack', videoRefElement);
2119
- videoRefStack.current.push(videoRefElement);
2120
- }
2121
- }, [videoRefElement]);
2122
- var onVideoUnmounted = React.useCallback(function (videoElement) {
2123
- log('removing video from stack', videoElement);
2124
- videoRefStack.current = videoRefStack.current.filter(function (v) {
2125
- return v !== videoElement;
2126
- });
2127
- videoRef.current = videoRefStack.current.slice(-1)[0]; // top of stack.
2128
- log('new videoRef is', videoRef.current);
2129
- }, []);
2130
- React.useEffect(function resetCameraOnContinuityPreferenceChanged() {
2131
- if (debugMode) {
2132
- log('iphone continuity camera allowed changed', iphoneContinuityCameraAllowed);
2133
- }
2134
- releaseCameraAccess();
2135
- cameraRef.current = null;
2136
- setVideoLoaded(false);
2137
- }, [debugMode, iphoneContinuityCameraAllowed]);
2138
- // NOTE: the bound callback function here is called requestCameraAccess, because
2139
- // it initiates the useEffect chain that results in camera access being requested
2140
- // (requestCameraAccessAutomatically -> chooseFromAvailableCameras -> accessChosenCamera).
2141
- //
2142
- // We chose to title the inner function "chooseFromAvailableCameras" because
2143
- // that's all it literally does -- the available cameras are enumerated, and then
2144
- // the result is parsed to decide which one we like best, which is then passed to
2145
- // setVideoDevice, which causes accessChosenCamera to trigger.
2146
- //
2147
- // I am not a huge fan of getUserMedia's design -- you need to call it twice in order
2148
- // to select the "best" camera for your application's purposes.
2149
- var requestCameraAccess = React.useCallback(function chooseFromAvailableCameras() {
2150
- return __awaiter(this, void 0, void 0, function () {
2151
- var availableCameras, selectedCamera, platform_1, iphoneContinuityCamera, e_1;
2152
- var _a, _b;
2153
- return __generator(this, function (_c) {
2154
- switch (_c.label) {
2155
- case 0:
2156
- setCameraReady(false);
2157
- setCameraAccessDenied(false);
2158
- _c.label = 1;
2159
- case 1:
2160
- _c.trys.push([1, 3,, 4]);
2161
- return [4 /*yield*/, listAvailableCameras()];
2162
- case 2:
2163
- availableCameras = _c.sent();
2164
- selectedCamera = void 0;
2165
- if (debugMode) {
2166
- log('availableCameras', availableCameras);
2167
- }
2168
- platform_1 = getPlatform();
2169
- if (debugMode) {
2170
- log('platformDetails', platform_1);
2171
- }
2172
- if (!iphoneContinuityCameraDenied && (!(platform_1 === null || platform_1 === void 0 ? void 0 : platform_1.os) || platform_1.os.family === 'OS X')) {
2173
- iphoneContinuityCamera = availableCameras.find(function (deviceInfo) {
2174
- return labelMatches(deviceInfo, 'iphone');
2175
- });
2176
- setIphoneContinuityCameraAvailable(!!iphoneContinuityCamera);
2177
- if (iphoneContinuityCamera && iphoneContinuityCameraAllowed) {
2178
- selectedCamera = iphoneContinuityCamera;
2179
- }
2180
- } 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) {
2181
- return c.label.startsWith('camera2 ');
2182
- })) {
2183
- availableCameras = availableCameras.sort(function (a, b) {
2184
- return a.label.toLowerCase().localeCompare(b.label.toLowerCase());
2185
- });
2186
- if (debugMode) {
2187
- log('cameras have been sorted', availableCameras);
2188
- }
2189
- }
2190
- if (preferFrontFacingCamera) {
2191
- selectedCamera = availableCameras.find(function (deviceInfo) {
2192
- return labelMatches(deviceInfo, frontLabels);
2193
- });
2194
- }
2195
- selectedCamera || (selectedCamera = availableCameras.find(function (deviceInfo) {
2196
- return labelMatches(deviceInfo, 'backtriplecamera');
2197
- }));
2198
- selectedCamera || (selectedCamera = availableCameras.find(function (deviceInfo) {
2199
- return labelMatches(deviceInfo, 'backdualcamera');
2200
- }));
2201
- selectedCamera || (selectedCamera = availableCameras.find(function (deviceInfo) {
2202
- return labelMatches(deviceInfo, rearLabels) && !labelMatches(deviceInfo, backUltraWideLabels);
2203
- }));
2204
- selectedCamera || (selectedCamera = availableCameras.find(function (deviceInfo) {
2205
- return labelMatches(deviceInfo, rearLabels);
2206
- }));
2207
- // on iOS, the front facing camera always is at the first position in the list, so we skip it if all else fails.
2208
- 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) {
2209
- selectedCamera || (selectedCamera = availableCameras[1]);
2210
- }
2211
- selectedCamera || (selectedCamera = availableCameras[0]);
2212
- if (debugMode) log('selectedCamera', selectedCamera);
2213
- setVideoDevice(selectedCamera);
2214
- return [3 /*break*/, 4];
2215
- case 3:
2216
- e_1 = _c.sent();
2217
- if (e_1.name === 'NotAllowedError') {
2218
- error('camera access has been blocked by the user', e_1);
2219
- setCameraAccessDenied(true);
2220
- } else {
2221
- error('camera access encountered some other error', e_1);
2222
- throw e_1;
2223
- }
2224
- return [3 /*break*/, 4];
2225
- case 4:
2226
- return [2 /*return*/];
2227
- }
2228
- });
2229
- });
2230
- }, [debugMode, iphoneContinuityCameraAllowed, iphoneContinuityCameraDenied, preferFrontFacingCamera]);
2231
- React.useEffect(function requestCameraAccessAutomatically() {
2232
- if (requestAccessAutomatically && !cameraAccessDenied) {
2233
- requestCameraAccess()["catch"](error);
2234
- }
2235
- }, [cameraAccessDenied, requestAccessAutomatically, requestCameraAccess]);
2236
- React.useEffect(function accessChosenCamera() {
2237
- var _this = this;
2238
- var _a;
2239
- if (!videoDevice) return;
2240
- var cleanup = function cleanup() {
2241
- releaseCameraAccess();
2242
- cameraRef.current = null;
2243
- setVideoLoaded(false);
2244
- };
2245
- if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia)) return cleanup;
2246
- (function () {
2247
- return __awaiter(_this, void 0, void 0, function () {
2248
- var constraints, stream, e_2, handleStreamEnded;
2249
- var _a;
2250
- return __generator(this, function (_b) {
2251
- switch (_b.label) {
2252
- case 0:
2253
- constraints = {
2254
- audio: false,
2255
- video: {
2256
- deviceId: {
2257
- exact: videoDevice.deviceId
2258
- },
2259
- width: {
2260
- ideal: maxVideoWidth
2261
- },
2262
- aspectRatio: 1.777777778,
2263
- frameRate: {}
2264
- }
2265
- };
2266
- if (maxFps) {
2267
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2268
- // @ts-ignore
2269
- constraints.video.frameRate = {
2270
- max: maxFps
2271
- };
2272
- }
2273
- stream = null;
2274
- _b.label = 1;
2275
- case 1:
2276
- _b.trys.push([1, 3,, 4]);
2277
- return [4 /*yield*/, navigator.mediaDevices.getUserMedia(constraints)];
2278
- case 2:
2279
- stream = _b.sent();
2280
- return [3 /*break*/, 4];
2281
- case 3:
2282
- e_2 = _b.sent();
2283
- if (e_2.name === 'NotAllowedError') {
2284
- if (iphoneContinuityCameraAllowed) {
2285
- setIphoneContinuityCameraAvailable(false);
2286
- setIphoneContinuityCameraDenied(true);
2287
- } else {
2288
- setCameraAccessDenied(true);
2289
- }
2290
- return [2 /*return*/];
2291
- }
2292
- return [3 /*break*/, 4];
2293
- case 4:
2294
- if (!!stream) return [3 /*break*/, 8];
2295
- _b.label = 5;
2296
- case 5:
2297
- _b.trys.push([5, 7,, 8]);
2298
- return [4 /*yield*/, navigator.mediaDevices.getUserMedia({
2299
- audio: false,
2300
- video: true
2301
- })];
2302
- case 6:
2303
- stream = _b.sent();
2304
- log('opened stream with no width and height constraints');
2305
- return [3 /*break*/, 8];
2306
- case 7:
2307
- _b.sent();
2308
- log('cannot open stream at all');
2309
- return [3 /*break*/, 8];
2310
- case 8:
2311
- if (!stream) {
2312
- throw new Error('failed to open camera');
2313
- }
2314
- handleStreamEnded = function handleStreamEnded() {
2315
- if (iphoneContinuityCameraAvailable && iphoneContinuityCameraAllowed) {
2316
- log('someone unplugged the continuity camera');
2317
- releaseCameraAccess();
2318
- cameraRef.current = null;
2319
- setIphoneContinuityCameraAvailable(false);
2320
- setIphoneContinuityCameraDenied(true);
2321
- setVideoDevice(null);
2322
- } else {
2323
- log('someone unplugged the webcam');
2324
- releaseCameraAccess();
2325
- cameraRef.current = null;
2326
- setVideoLoaded(false);
2327
- setCameraAccessDenied(true);
2328
- }
2329
- };
2330
- (_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener('ended', handleStreamEnded);
2331
- stream.getVideoTracks().forEach(function (track) {
2332
- track.onended = handleStreamEnded;
2333
- });
2334
- cameraRef.current = obtainCameraAccess(stream, videoDevice.label, videoRef.current);
2335
- return [2 /*return*/];
2336
- }
2337
- });
2338
- });
2339
- })();
2340
- return cleanup;
2341
- }, [iphoneContinuityCameraAllowed, iphoneContinuityCameraAvailable, maxFps, maxVideoWidth, videoDevice]);
2342
- React.useEffect(function triggerCameraReady() {
2343
- // TODO: in the future let's evaluate whether we can simplify this to just
2344
- // setCameraReady(!!videoDevice && videoLoaded) -- we are wondering whether
2345
- // we somehow depend on this being set twice.
2346
- setCameraReady(false);
2347
- if (videoDevice && videoLoaded) {
2348
- setCameraReady(videoDevice && videoLoaded);
2349
- }
2350
- }, [videoLoaded, videoDevice]);
2351
- var requestMicrophoneAccess = React.useCallback(function _requestMicrophoneAccess() {
2352
- return __awaiter(this, void 0, void 0, function () {
2353
- var stream;
2354
- return __generator(this, function (_a) {
2355
- switch (_a.label) {
2356
- case 0:
2357
- setMicrophoneReady(false);
2358
- setMicrophoneAccessDenied(false);
2359
- _a.label = 1;
2360
- case 1:
2361
- _a.trys.push([1, 3,, 4]);
2362
- return [4 /*yield*/, navigator.mediaDevices.getUserMedia({
2363
- audio: true,
2364
- video: false
2365
- })];
2366
- case 2:
2367
- stream = _a.sent();
2368
- currentAudioStream = stream;
2369
- setAudioStream(stream);
2370
- setMicrophoneReady(true);
2371
- stream.getAudioTracks().forEach(function (track) {
2372
- track.onended = function () {
2373
- setMicrophoneAccessDenied(true);
2374
- };
2375
- });
2376
- return [3 /*break*/, 4];
2377
- case 3:
2378
- _a.sent();
2379
- setMicrophoneAccessDenied(true);
2380
- return [3 /*break*/, 4];
2381
- case 4:
2382
- return [2 /*return*/];
2383
- }
2384
- });
2385
- });
2386
- }, []);
2387
- React.useEffect(function requestMicrophoneAccessIfNeeded() {
2388
- if (!requireMicrophoneAccess || microphoneAccessDenied) return;
2389
- requestMicrophoneAccess()["catch"](error);
2390
- return function () {
2391
- releaseMicrophoneAccess();
2392
- setAudioStream(null);
2393
- setMicrophoneReady(false);
2394
- };
2395
- }, [microphoneAccessDenied, requestMicrophoneAccess, requireMicrophoneAccess]);
2396
- var takePhoto = React.useCallback(function _takePhoto() {
2397
- return __awaiter(this, void 0, void 0, function () {
2398
- var canvas;
2399
- return __generator(this, function (_a) {
2400
- switch (_a.label) {
2401
- case 0:
2402
- if (!cameraRef.current) return [2 /*return*/, null];
2403
- if (!(typeof ImageCapture !== 'undefined')) return [3 /*break*/, 2];
2404
- return [4 /*yield*/, new ImageCapture(cameraRef.current.stream.getTracks()[0]).takePhoto()];
2405
- case 1:
2406
- return [2 /*return*/, _a.sent()];
2407
- case 2:
2408
- if (!videoRef.current) return [2 /*return*/, null];
2409
- canvas = document.createElement('canvas');
2410
- drawToCanvas(canvas, videoRef.current);
2411
- return [2 /*return*/, new Promise(function (resolve) {
2412
- return canvas.toBlob(resolve);
2413
- })];
2414
- }
2415
- });
2416
- });
2417
- }, []);
2418
- return React.useMemo(function () {
2419
- return {
2420
- videoRef: videoRef,
2421
- videoDevice: videoDevice,
2422
- videoLoaded: videoLoaded,
2423
- setVideoLoaded: setVideoLoaded,
2424
- onVideoUnmounted: onVideoUnmounted,
2425
- cameraRef: cameraRef,
2426
- cameraReady: cameraReady,
2427
- cameraAccessDenied: cameraAccessDenied,
2428
- requestCameraAccess: requestCameraAccess,
2429
- releaseCameraAccess: releaseCameraAccess,
2430
- iphoneContinuityCameraAvailable: iphoneContinuityCameraAvailable,
2431
- iphoneContinuityCameraAllowed: iphoneContinuityCameraAllowed,
2432
- setIphoneContinuityCameraAllowed: setIphoneContinuityCameraAllowed,
2433
- takePhoto: takePhoto,
2434
- audioStream: audioStream,
2435
- microphoneReady: microphoneReady,
2436
- microphoneAccessDenied: microphoneAccessDenied,
2437
- requestMicrophoneAccess: requestMicrophoneAccess
2438
- };
2439
- }, [audioStream, cameraAccessDenied, cameraReady, iphoneContinuityCameraAllowed, iphoneContinuityCameraAvailable, microphoneAccessDenied, microphoneReady, onVideoUnmounted, requestCameraAccess, requestMicrophoneAccess, takePhoto, videoDevice, videoLoaded]);
2440
- }
2441
-
2442
- var CameraStateContext = /*#__PURE__*/React.createContext({
2443
- videoRef: {
2444
- current: null
2445
- },
2446
- videoDevice: null,
2447
- videoLoaded: false,
2448
- cameraRef: {
2449
- current: null
2450
- },
2451
- cameraReady: false,
2452
- cameraAccessDenied: false,
2453
- requestCameraAccess: function requestCameraAccess() {
2454
- return null;
2455
- },
2456
- releaseCameraAccess: function releaseCameraAccess() {
2457
- return null;
2458
- },
2459
- iphoneContinuityCameraAvailable: false,
2460
- iphoneContinuityCameraAllowed: true,
2461
- setIphoneContinuityCameraAllowed: function setIphoneContinuityCameraAllowed() {
2462
- return null;
2463
- },
2464
- takePhoto: function takePhoto() {
2465
- return Promise.resolve(null);
2466
- },
2467
- setVideoLoaded: function setVideoLoaded() {
2468
- return null;
2469
- },
2470
- onVideoUnmounted: function onVideoUnmounted() {
2471
- return null;
2472
- },
2473
- audioStream: null,
2474
- microphoneReady: false,
2475
- microphoneAccessDenied: false,
2476
- requestMicrophoneAccess: function requestMicrophoneAccess() {
2477
- return null;
2478
- }
2479
- });
2480
- var CameraProvider = function CameraProvider(_a) {
2481
- var children = _a.children,
2482
- _b = _a.requestAccessAutomatically,
2483
- requestAccessAutomatically = _b === void 0 ? true : _b,
2484
- _c = _a.preferFrontFacingCamera,
2485
- preferFrontFacingCamera = _c === void 0 ? false : _c,
2486
- _d = _a.preferContinuityCamera,
2487
- preferContinuityCamera = _d === void 0 ? true : _d,
2488
- _e = _a.requireMicrophoneAccess,
2489
- requireMicrophoneAccess = _e === void 0 ? false : _e,
2490
- _f = _a.maxVideoWidth,
2491
- maxVideoWidth = _f === void 0 ? 1920 : _f,
2492
- maxFps = _a.maxFps,
2493
- onCameraAccessDenied = _a.onCameraAccessDenied,
2494
- onMicrophoneAccessDenied = _a.onMicrophoneAccessDenied,
2495
- _g = _a.debugMode,
2496
- debugMode = _g === void 0 ? false : _g;
2497
- var captureDevice = usePreferredCaptureDevice({
2498
- requestAccessAutomatically: requestAccessAutomatically,
2499
- preferFrontFacingCamera: preferFrontFacingCamera,
2500
- preferContinuityCamera: preferContinuityCamera,
2501
- requireMicrophoneAccess: requireMicrophoneAccess,
2502
- maxVideoWidth: maxVideoWidth,
2503
- maxFps: maxFps,
2504
- debugMode: debugMode
1892
+ function convertBase64ToBlob(base64Image) {
1893
+ // Split into two parts
1894
+ var parts = base64Image.split(';base64,');
1895
+ // Hold the content type
1896
+ var imageType = parts[0].split(':')[1];
1897
+ // Decode Base64 string
1898
+ var decodedData = window.atob(parts[1]);
1899
+ // Create UNIT8ARRAY of size same as row data length
1900
+ var uInt8Array = new Uint8Array(decodedData.length);
1901
+ // Insert all character code into uInt8Array
1902
+ for (var i = 0; i < decodedData.length; ++i) {
1903
+ uInt8Array[i] = decodedData.charCodeAt(i);
1904
+ }
1905
+ // Return BLOB image after conversion
1906
+ return new Blob([uInt8Array], {
1907
+ type: imageType
2505
1908
  });
2506
- React.useEffect(function () {
2507
- if (captureDevice.cameraAccessDenied) onCameraAccessDenied === null || onCameraAccessDenied === void 0 ? void 0 : onCameraAccessDenied();
2508
- }, [captureDevice.cameraAccessDenied, onCameraAccessDenied]);
2509
- React.useEffect(function () {
2510
- if (captureDevice.microphoneAccessDenied) onMicrophoneAccessDenied === null || onMicrophoneAccessDenied === void 0 ? void 0 : onMicrophoneAccessDenied();
2511
- }, [captureDevice.microphoneAccessDenied, onMicrophoneAccessDenied]);
2512
- var releaseCameraAccess = captureDevice.releaseCameraAccess;
2513
- React.useEffect(function () {
2514
- return function () {
2515
- releaseCameraAccess();
1909
+ }
1910
+ function calculateMd5(blob) {
1911
+ return new Promise(function (resolve, reject) {
1912
+ var reader = new FileReader();
1913
+ reader.readAsArrayBuffer(blob);
1914
+ reader.onloadend = function () {
1915
+ if (!reader.result) return reject(new Error('Failed to read file'));
1916
+ resolve(SparkMD5__default.default.ArrayBuffer.hash(reader.result));
2516
1917
  };
2517
- }, [releaseCameraAccess]);
2518
- return /*#__PURE__*/React__namespace.default.createElement(CameraStateContext.Provider, {
2519
- value: captureDevice
2520
- }, children);
2521
- };
1918
+ });
1919
+ }
2522
1920
 
2523
1921
  var visionTasksBasePath = "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.7/wasm";
2524
1922
  var visionRuntimePreloading = false;
@@ -2562,6 +1960,42 @@ function preloadVisionRuntime() {
2562
1960
  });
2563
1961
  }
2564
1962
 
1963
+ function getFrameDimensions(frame) {
1964
+ var frameWidth = frame.width,
1965
+ frameHeight = frame.height;
1966
+ if (frame instanceof HTMLImageElement) {
1967
+ frameWidth = frame.naturalWidth;
1968
+ frameHeight = frame.naturalHeight;
1969
+ }
1970
+ if (frame instanceof HTMLVideoElement) {
1971
+ frameWidth = frame.videoWidth;
1972
+ frameHeight = frame.videoHeight;
1973
+ }
1974
+ return [frameWidth, frameHeight];
1975
+ }
1976
+
1977
+ var InvisibleCanvas = styled__default.default.canvas(templateObject_1$G || (templateObject_1$G = __makeTemplateObject(["\n display: none;\n"], ["\n display: none;\n"])));
1978
+ function drawToCanvas(canvas, frame, width, height) {
1979
+ if (!canvas) return;
1980
+ var ctx = canvas.getContext('2d');
1981
+ if (!ctx) return;
1982
+ if (!width || !height) {
1983
+ var _a = getFrameDimensions(frame),
1984
+ frameWidth = _a[0],
1985
+ frameHeight = _a[1];
1986
+ width || (width = frameWidth);
1987
+ height || (height = frameHeight);
1988
+ }
1989
+ canvas.width = width;
1990
+ canvas.height = height;
1991
+ ctx.drawImage(frame, 0, 0, width, height);
1992
+ }
1993
+ function clearCanvas(canvas) {
1994
+ var _a;
1995
+ (_a = canvas === null || canvas === void 0 ? void 0 : canvas.getContext('2d')) === null || _a === void 0 ? void 0 : _a.clearRect(0, 0, canvas === null || canvas === void 0 ? void 0 : canvas.width, canvas === null || canvas === void 0 ? void 0 : canvas.height);
1996
+ }
1997
+ var templateObject_1$G;
1998
+
2565
1999
  function cropToShoulders(rawCanvas, cropCanvas, resizeCanvas, frame, face, quality, maxHeight) {
2566
2000
  if (quality === void 0) {
2567
2001
  quality = 0.92;
@@ -2865,7 +2299,8 @@ function useLoadFocusModel(_a) {
2865
2299
  modelPath = _b === void 0 ? defaultFocusModelPath : _b,
2866
2300
  _c = _a.modelLoadTimeoutMs,
2867
2301
  modelLoadTimeoutMs = _c === void 0 ? defaultFocusModelLoadTimeoutMs : _c,
2868
- onModelError = _a.onModelError;
2302
+ onModelError = _a.onModelError,
2303
+ videoRef = _a.videoRef;
2869
2304
  var _d = React.useState(false),
2870
2305
  ready = _d[0],
2871
2306
  setReady = _d[1];
@@ -2875,7 +2310,6 @@ function useLoadFocusModel(_a) {
2875
2310
  var _f = React.useState(null),
2876
2311
  modelError = _f[0],
2877
2312
  setModelError = _f[1];
2878
- var videoRef = React.useContext(CameraStateContext).videoRef;
2879
2313
  React.useEffect(function loadModel() {
2880
2314
  var _this = this;
2881
2315
  setReady(false);
@@ -3013,7 +2447,8 @@ function closeFaceDetector() {
3013
2447
  function useLoadFaceDetector(_a) {
3014
2448
  var onModelError = _a.onModelError,
3015
2449
  _b = _a.modelLoadTimeoutMs,
3016
- modelLoadTimeoutMs = _b === void 0 ? defaultSelfieCaptureModelLoadTimeoutMs : _b;
2450
+ modelLoadTimeoutMs = _b === void 0 ? defaultSelfieCaptureModelLoadTimeoutMs : _b,
2451
+ videoRef = _a.videoRef;
3017
2452
  var _c = React.useState(false),
3018
2453
  ready = _c[0],
3019
2454
  setReady = _c[1];
@@ -3023,7 +2458,6 @@ function useLoadFaceDetector(_a) {
3023
2458
  var _e = React.useState(null),
3024
2459
  modelError = _e[0],
3025
2460
  setModelError = _e[1];
3026
- var videoRef = React.useContext(CameraStateContext).videoRef;
3027
2461
  React.useEffect(function loadModel() {
3028
2462
  var _this = this;
3029
2463
  setReady(false);
@@ -3504,7 +2938,8 @@ function useLoadDocumentDetector(_a) {
3504
2938
  modelLoadTimeoutMs = _c === void 0 ? defaultDocumentDetectionModelLoadTimeoutMs : _c,
3505
2939
  _d = _a.scoreThreshold,
3506
2940
  scoreThreshold = _d === void 0 ? defaultDocumentDetectionScoreThreshold : _d,
3507
- onModelError = _a.onModelError;
2941
+ onModelError = _a.onModelError,
2942
+ videoRef = _a.videoRef;
3508
2943
  var _e = React.useState(false),
3509
2944
  ready = _e[0],
3510
2945
  setReady = _e[1];
@@ -3514,7 +2949,6 @@ function useLoadDocumentDetector(_a) {
3514
2949
  var _g = React.useState(null),
3515
2950
  modelError = _g[0],
3516
2951
  setModelError = _g[1];
3517
- var videoRef = React.useContext(CameraStateContext).videoRef;
3518
2952
  React.useEffect(function loadModel() {
3519
2953
  var _this = this;
3520
2954
  setReady(false);
@@ -3795,32 +3229,576 @@ function useFrameLoop(fn, _a) {
3795
3229
  });
3796
3230
  });
3797
3231
  }
3798
- renderPrediction().then();
3232
+ renderPrediction().then();
3233
+ return function () {
3234
+ loopId.current += 1;
3235
+ frameId.current && cancelAnimationFrame(frameId.current);
3236
+ timer && clearTimeout(timer);
3237
+ };
3238
+ }, [fn, running, throttleMs]);
3239
+ var start = React.useCallback(function () {
3240
+ startedAtRef.current = new Date();
3241
+ setRunning(true);
3242
+ }, []);
3243
+ var stop = React.useCallback(function () {
3244
+ loopId.current += 1; // force the loop to stop immediately.
3245
+ setRunning(false);
3246
+ startedAtRef.current = null;
3247
+ }, []);
3248
+ React.useEffect(function startAutomatically() {
3249
+ if (autoStart) start();
3250
+ return function () {
3251
+ stop();
3252
+ };
3253
+ }, [autoStart, start, stop]);
3254
+ return {
3255
+ start: start,
3256
+ stop: stop
3257
+ };
3258
+ }
3259
+
3260
+ var createStoreImpl = function createStoreImpl(createState) {
3261
+ var state;
3262
+ var listeners = /* @__PURE__ */new Set();
3263
+ var setState = function setState(partial, replace) {
3264
+ var nextState = typeof partial === "function" ? partial(state) : partial;
3265
+ if (!Object.is(nextState, state)) {
3266
+ var previousState = state;
3267
+ state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
3268
+ listeners.forEach(function (listener) {
3269
+ return listener(state, previousState);
3270
+ });
3271
+ }
3272
+ };
3273
+ var getState = function getState() {
3274
+ return state;
3275
+ };
3276
+ var getInitialState = function getInitialState() {
3277
+ return initialState;
3278
+ };
3279
+ var subscribe = function subscribe(listener) {
3280
+ listeners.add(listener);
3281
+ return function () {
3282
+ return listeners["delete"](listener);
3283
+ };
3284
+ };
3285
+ var api = {
3286
+ setState: setState,
3287
+ getState: getState,
3288
+ getInitialState: getInitialState,
3289
+ subscribe: subscribe
3290
+ };
3291
+ var initialState = state = createState(setState, getState, api);
3292
+ return api;
3293
+ };
3294
+ var createStore = function createStore(createState) {
3295
+ return createState ? createStoreImpl(createState) : createStoreImpl;
3296
+ };
3297
+
3298
+ var identity = function identity(arg) {
3299
+ return arg;
3300
+ };
3301
+ function useStore(api, selector) {
3302
+ if (selector === void 0) {
3303
+ selector = identity;
3304
+ }
3305
+ var slice = React__namespace.default.useSyncExternalStore(api.subscribe, function () {
3306
+ return selector(api.getState());
3307
+ }, function () {
3308
+ return selector(api.getInitialState());
3309
+ });
3310
+ React__namespace.default.useDebugValue(slice);
3311
+ return slice;
3312
+ }
3313
+
3314
+ function listAvailableCameras(facingMode_1) {
3315
+ return __awaiter(this, arguments, void 0, function (facingMode, requestMicAccess) {
3316
+ var cameraEnumerationStream, videoDevices;
3317
+ if (requestMicAccess === void 0) {
3318
+ requestMicAccess = false;
3319
+ }
3320
+ return __generator(this, function (_a) {
3321
+ switch (_a.label) {
3322
+ case 0:
3323
+ return [4 /*yield*/, navigator.mediaDevices.getUserMedia({
3324
+ video: {
3325
+ facingMode: {
3326
+ exact: facingMode
3327
+ }
3328
+ },
3329
+ audio: requestMicAccess
3330
+ })
3331
+ // This lists all available cameras attached to the user's device.
3332
+ ];
3333
+ case 1:
3334
+ cameraEnumerationStream = _a.sent();
3335
+ return [4 /*yield*/, navigator.mediaDevices.enumerateDevices()];
3336
+ case 2:
3337
+ videoDevices = _a.sent().filter(function (_a) {
3338
+ var kind = _a.kind;
3339
+ return kind === 'videoinput';
3340
+ });
3341
+ // Release the access to the user's camera that we obtained for enumeration purposes.
3342
+ cameraEnumerationStream.getVideoTracks().forEach(function (track) {
3343
+ track.enabled = false;
3344
+ track.stop();
3345
+ });
3346
+ cameraEnumerationStream = null;
3347
+ return [2 /*return*/, videoDevices];
3348
+ }
3349
+ });
3350
+ });
3351
+ }
3352
+ 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) {
3353
+ return s.toLocaleLowerCase().split(' ').join('');
3354
+ });
3355
+ 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) {
3356
+ return s.toLocaleLowerCase().split(' ').join('');
3357
+ });
3358
+ 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) {
3359
+ return s.toLocaleLowerCase().split(' ').join('');
3360
+ });
3361
+ var cameraLabelMatches = function cameraLabelMatches(labelOrDevice, labelSetOrLabel) {
3362
+ var label = labelOrDevice instanceof MediaDeviceInfo ? getDeviceLabel(labelOrDevice) : labelOrDevice;
3363
+ var labelSet = typeof labelSetOrLabel === 'string' ? [labelSetOrLabel] : labelSetOrLabel;
3364
+ return labelSet.some(function (l) {
3365
+ return label.includes(l);
3366
+ });
3367
+ };
3368
+ var getDeviceLabel = function getDeviceLabel(deviceInfo) {
3369
+ return deviceInfo.label.toLocaleLowerCase().split(' ').join('');
3370
+ };
3371
+ var currentCamera;
3372
+ function obtainCameraAccess(stream, deviceLabel, video) {
3373
+ releaseCameraAccess();
3374
+ log('obtaining camera access...');
3375
+ var _a = stream.getVideoTracks()[0].getSettings(),
3376
+ width = _a.width,
3377
+ height = _a.height;
3378
+ log('camera dimensions', width, height);
3379
+ var label = deviceLabel.toLocaleLowerCase().split(' ').join('');
3380
+ log('camera label', label);
3381
+ var isRearFacing = cameraLabelMatches(label, __spreadArray(__spreadArray(__spreadArray([], rearCameraLabels, true), backUltraWideCameraLabels, true), ['iphone'], false));
3382
+ log('is rear facing?', isRearFacing);
3383
+ var release = function release() {
3384
+ stream.getTracks().forEach(function (track) {
3385
+ track.enabled = false;
3386
+ track.stop();
3387
+ });
3388
+ if (video) {
3389
+ video.pause();
3390
+ video.srcObject = null;
3391
+ video.src = '';
3392
+ }
3393
+ };
3394
+ width || (width = 0);
3395
+ height || (height = 0);
3396
+ currentCamera = {
3397
+ label: deviceLabel,
3398
+ stream: stream,
3399
+ width: width,
3400
+ height: height,
3401
+ isRearFacing: isRearFacing,
3402
+ release: release
3403
+ };
3404
+ log('camera access granted');
3405
+ if (video) video.srcObject = stream;
3406
+ log('video source initialized');
3407
+ return currentCamera;
3408
+ }
3409
+ function releaseCameraAccess() {
3410
+ if (!currentCamera) return;
3411
+ log('releasing camera access...');
3412
+ currentCamera.release();
3413
+ currentCamera = undefined;
3414
+ }
3415
+
3416
+ var initialState$5 = {
3417
+ videoRef: {
3418
+ current: null
3419
+ },
3420
+ videoLoaded: false,
3421
+ videoStream: null,
3422
+ videoDevice: null,
3423
+ isRearFacing: false,
3424
+ camera: null,
3425
+ cameraReady: false,
3426
+ cameraAccessDenied: false,
3427
+ iphoneContinuityCameraAvailable: false,
3428
+ iphoneContinuityCameraDenied: false,
3429
+ preferIphoneContinuityCamera: true,
3430
+ audioStream: null,
3431
+ microphoneReady: false,
3432
+ microphoneAccessDenied: false
3433
+ };
3434
+ var createCameraStore = function createCameraStore(config) {
3435
+ var store = createStore(function (set, get) {
3436
+ return _assign(_assign(_assign({}, initialState$5), config), {
3437
+ reset: function reset() {
3438
+ return set(_assign(_assign({}, initialState$5), config));
3439
+ },
3440
+ setConfig: function setConfig(config) {
3441
+ return set(config);
3442
+ },
3443
+ onVideoMounted: function onVideoMounted() {
3444
+ return set({
3445
+ videoLoaded: true
3446
+ });
3447
+ },
3448
+ setIphoneContinuityCameraAllowed: function setIphoneContinuityCameraAllowed(value) {
3449
+ return set({
3450
+ preferIphoneContinuityCamera: value
3451
+ });
3452
+ },
3453
+ requestCameraAccess: function requestCameraAccess() {
3454
+ return __awaiter(this, void 0, void 0, function () {
3455
+ 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;
3456
+ var _b, _c, _d;
3457
+ return __generator(this, function (_e) {
3458
+ switch (_e.label) {
3459
+ case 0:
3460
+ _a = get(), videoRef = _a.videoRef, releaseCameraAccess = _a.releaseCameraAccess, preferFrontFacingCamera = _a.preferFrontFacingCamera, preferIphoneContinuityCamera = _a.preferIphoneContinuityCamera, iphoneContinuityCameraDenied = _a.iphoneContinuityCameraDenied;
3461
+ releaseCameraAccess();
3462
+ _e.label = 1;
3463
+ case 1:
3464
+ _e.trys.push([1, 11,, 12]);
3465
+ return [4 /*yield*/, listAvailableCameras()];
3466
+ case 2:
3467
+ availableCameras = _e.sent();
3468
+ selectedCamera = void 0;
3469
+ debug('availableCameras', availableCameras);
3470
+ platform_1 = getPlatform();
3471
+ debug('platformDetails', platform_1);
3472
+ if (!iphoneContinuityCameraDenied && (!(platform_1 === null || platform_1 === void 0 ? void 0 : platform_1.os) || platform_1.os.family === 'OS X')) {
3473
+ iphoneContinuityCamera = availableCameras.find(function (deviceInfo) {
3474
+ return cameraLabelMatches(deviceInfo, 'iphone');
3475
+ });
3476
+ set({
3477
+ iphoneContinuityCameraAvailable: !!iphoneContinuityCamera
3478
+ });
3479
+ if (iphoneContinuityCamera && preferIphoneContinuityCamera) {
3480
+ selectedCamera = iphoneContinuityCamera;
3481
+ }
3482
+ } 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) {
3483
+ return c.label.startsWith('camera2 ');
3484
+ })) {
3485
+ availableCameras = availableCameras.sort(function (a, b) {
3486
+ return a.label.toLowerCase().localeCompare(b.label.toLowerCase());
3487
+ });
3488
+ debug('cameras have been sorted', availableCameras);
3489
+ }
3490
+ if (preferFrontFacingCamera) {
3491
+ selectedCamera = availableCameras.find(function (deviceInfo) {
3492
+ return cameraLabelMatches(deviceInfo, frontCameraLabels);
3493
+ });
3494
+ }
3495
+ selectedCamera || (selectedCamera = availableCameras.find(function (deviceInfo) {
3496
+ return cameraLabelMatches(deviceInfo, 'backtriplecamera');
3497
+ }));
3498
+ selectedCamera || (selectedCamera = availableCameras.find(function (deviceInfo) {
3499
+ return cameraLabelMatches(deviceInfo, 'backdualcamera');
3500
+ }));
3501
+ selectedCamera || (selectedCamera = availableCameras.find(function (deviceInfo) {
3502
+ return cameraLabelMatches(deviceInfo, rearCameraLabels) && !cameraLabelMatches(deviceInfo, backUltraWideCameraLabels);
3503
+ }));
3504
+ selectedCamera || (selectedCamera = availableCameras.find(function (deviceInfo) {
3505
+ return cameraLabelMatches(deviceInfo, rearCameraLabels);
3506
+ }));
3507
+ // on iOS, the front facing camera always is at the first position in the list, so we skip it if all else fails.
3508
+ 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) {
3509
+ selectedCamera || (selectedCamera = availableCameras[1]);
3510
+ }
3511
+ selectedCamera || (selectedCamera = availableCameras[0]);
3512
+ debug('selectedCamera', selectedCamera);
3513
+ set({
3514
+ videoDevice: selectedCamera
3515
+ });
3516
+ constraints = {
3517
+ audio: false,
3518
+ video: {
3519
+ deviceId: {
3520
+ exact: selectedCamera.deviceId
3521
+ },
3522
+ width: {
3523
+ ideal: config.maxVideoWidth
3524
+ },
3525
+ aspectRatio: 1.777777778,
3526
+ frameRate: {}
3527
+ }
3528
+ };
3529
+ if (config.maxFps) {
3530
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
3531
+ // @ts-ignore
3532
+ constraints.video.frameRate = {
3533
+ max: config.maxFps
3534
+ };
3535
+ }
3536
+ stream_1 = null;
3537
+ _e.label = 3;
3538
+ case 3:
3539
+ _e.trys.push([3, 5,, 6]);
3540
+ debug('obtaining camera access with constraints', constraints);
3541
+ return [4 /*yield*/, navigator.mediaDevices.getUserMedia(constraints)];
3542
+ case 4:
3543
+ stream_1 = _e.sent();
3544
+ return [3 /*break*/, 6];
3545
+ case 5:
3546
+ e_1 = _e.sent();
3547
+ if (e_1.name === 'NotAllowedError') {
3548
+ if (preferIphoneContinuityCamera) {
3549
+ set({
3550
+ iphoneContinuityCameraAvailable: false,
3551
+ iphoneContinuityCameraDenied: true
3552
+ });
3553
+ } else {
3554
+ set({
3555
+ cameraAccessDenied: true
3556
+ });
3557
+ }
3558
+ return [2 /*return*/];
3559
+ }
3560
+ return [3 /*break*/, 6];
3561
+ case 6:
3562
+ if (!!stream_1) return [3 /*break*/, 10];
3563
+ _e.label = 7;
3564
+ case 7:
3565
+ _e.trys.push([7, 9,, 10]);
3566
+ return [4 /*yield*/, navigator.mediaDevices.getUserMedia({
3567
+ audio: false,
3568
+ video: true
3569
+ })];
3570
+ case 8:
3571
+ stream_1 = _e.sent();
3572
+ debug('opened stream with no width and height constraints');
3573
+ return [3 /*break*/, 10];
3574
+ case 9:
3575
+ _e.sent();
3576
+ debug('cannot open stream at all');
3577
+ return [3 /*break*/, 10];
3578
+ case 10:
3579
+ if (!stream_1) {
3580
+ error('failed to open camera');
3581
+ throw new Error('failed to open camera');
3582
+ }
3583
+ debug('camera access granted with constraints', constraints);
3584
+ handleStreamEnded_1 = function handleStreamEnded_1() {
3585
+ if (preferIphoneContinuityCamera && get().iphoneContinuityCameraAvailable) {
3586
+ debug('someone unplugged the continuity camera');
3587
+ set({
3588
+ videoStream: null,
3589
+ videoDevice: null,
3590
+ cameraReady: false,
3591
+ iphoneContinuityCameraAvailable: false,
3592
+ iphoneContinuityCameraDenied: true
3593
+ });
3594
+ get().requestCameraAccess();
3595
+ } else {
3596
+ debug('someone unplugged the webcam');
3597
+ releaseCameraAccess();
3598
+ set({
3599
+ videoStream: null,
3600
+ videoDevice: null,
3601
+ videoLoaded: false,
3602
+ cameraReady: false,
3603
+ cameraAccessDenied: true
3604
+ });
3605
+ }
3606
+ };
3607
+ (_d = videoRef.current) === null || _d === void 0 ? void 0 : _d.addEventListener('ended', handleStreamEnded_1);
3608
+ videoTrack_1 = stream_1.getVideoTracks()[0];
3609
+ videoTrack_1.onended = handleStreamEnded_1;
3610
+ camera_1 = obtainCameraAccess(stream_1, selectedCamera.label, videoRef.current);
3611
+ setTimeout(function () {
3612
+ // iOS 17 has a strange behavior where the video track flickers between muted and unmuted
3613
+ // when the camera access is being requested. This delay is a workaround for that.
3614
+ videoTrack_1.onmute = handleStreamEnded_1;
3615
+ set({
3616
+ camera: camera_1,
3617
+ cameraReady: true,
3618
+ cameraAccessDenied: false,
3619
+ isRearFacing: camera_1.isRearFacing,
3620
+ videoStream: stream_1
3621
+ });
3622
+ }, 500);
3623
+ return [3 /*break*/, 12];
3624
+ case 11:
3625
+ e_3 = _e.sent();
3626
+ if (e_3.name === 'NotAllowedError') {
3627
+ error('camera access has been blocked by the user', e_3);
3628
+ set({
3629
+ cameraAccessDenied: true
3630
+ });
3631
+ } else {
3632
+ error('camera access encountered some other error', e_3);
3633
+ throw e_3;
3634
+ }
3635
+ return [3 /*break*/, 12];
3636
+ case 12:
3637
+ return [2 /*return*/];
3638
+ }
3639
+ });
3640
+ });
3641
+ },
3642
+ releaseCameraAccess: function releaseCameraAccess() {
3643
+ return __awaiter(this, void 0, void 0, function () {
3644
+ var camera;
3645
+ return __generator(this, function (_a) {
3646
+ camera = get().camera;
3647
+ if (!camera) return [2 /*return*/];
3648
+ camera.release();
3649
+ set({
3650
+ camera: null,
3651
+ cameraReady: false,
3652
+ cameraAccessDenied: false
3653
+ });
3654
+ return [2 /*return*/];
3655
+ });
3656
+ });
3657
+ },
3658
+ requestMicrophoneAccess: function requestMicrophoneAccess() {
3659
+ return __awaiter(this, void 0, void 0, function () {
3660
+ var stream_2;
3661
+ return __generator(this, function (_a) {
3662
+ switch (_a.label) {
3663
+ case 0:
3664
+ get().releaseMicrophoneAccess();
3665
+ _a.label = 1;
3666
+ case 1:
3667
+ _a.trys.push([1, 3,, 4]);
3668
+ return [4 /*yield*/, navigator.mediaDevices.getUserMedia({
3669
+ audio: true,
3670
+ video: false
3671
+ })
3672
+ // iOS 17 has a strange behavior where the video track flickers between muted and unmuted
3673
+ // when the camera access is being requested. This delay is a workaround for that.
3674
+ ];
3675
+ case 2:
3676
+ stream_2 = _a.sent();
3677
+ // iOS 17 has a strange behavior where the video track flickers between muted and unmuted
3678
+ // when the camera access is being requested. This delay is a workaround for that.
3679
+ setTimeout(function () {
3680
+ set({
3681
+ audioStream: stream_2,
3682
+ microphoneReady: true,
3683
+ microphoneAccessDenied: false
3684
+ });
3685
+ var track = stream_2.getAudioTracks()[0];
3686
+ track.onended = function () {
3687
+ return set({
3688
+ microphoneReady: false,
3689
+ microphoneAccessDenied: true
3690
+ });
3691
+ };
3692
+ track.onmute = function () {
3693
+ return set({
3694
+ microphoneReady: false,
3695
+ microphoneAccessDenied: true
3696
+ });
3697
+ };
3698
+ }, 500);
3699
+ return [3 /*break*/, 4];
3700
+ case 3:
3701
+ _a.sent();
3702
+ set({
3703
+ microphoneAccessDenied: true
3704
+ });
3705
+ return [3 /*break*/, 4];
3706
+ case 4:
3707
+ return [2 /*return*/];
3708
+ }
3709
+ });
3710
+ });
3711
+ },
3712
+ releaseMicrophoneAccess: function releaseMicrophoneAccess() {
3713
+ var _a;
3714
+ var audioStream = get().audioStream;
3715
+ (_a = audioStream === null || audioStream === void 0 ? void 0 : audioStream.stop) === null || _a === void 0 ? void 0 : _a.call(audioStream);
3716
+ audioStream === null || audioStream === void 0 ? void 0 : audioStream.getAudioTracks().forEach(function (track) {
3717
+ var _a;
3718
+ (_a = track.stop) === null || _a === void 0 ? void 0 : _a.call(track);
3719
+ });
3720
+ set({
3721
+ audioStream: null,
3722
+ microphoneReady: false,
3723
+ microphoneAccessDenied: false
3724
+ });
3725
+ }
3726
+ });
3727
+ });
3728
+ if (config.requestAccessAutomatically) {
3729
+ void store.getState().requestCameraAccess();
3730
+ }
3731
+ return _assign(_assign({}, store), {
3732
+ destroy: function destroy() {
3733
+ store.getState().releaseCameraAccess();
3734
+ store.getState().releaseMicrophoneAccess();
3735
+ }
3736
+ });
3737
+ };
3738
+ var CameraStoreContext = /*#__PURE__*/React.createContext(undefined);
3739
+ function CameraStoreProvider(_a) {
3740
+ var children = _a.children,
3741
+ _b = _a.requestAccessAutomatically,
3742
+ requestAccessAutomatically = _b === void 0 ? true : _b,
3743
+ _c = _a.preferIphoneContinuityCamera,
3744
+ preferIphoneContinuityCamera = _c === void 0 ? true : _c,
3745
+ _d = _a.preferFrontFacingCamera,
3746
+ preferFrontFacingCamera = _d === void 0 ? false : _d,
3747
+ _e = _a.maxVideoWidth,
3748
+ maxVideoWidth = _e === void 0 ? 1920 : _e,
3749
+ maxFps = _a.maxFps,
3750
+ onCameraAccessDenied = _a.onCameraAccessDenied,
3751
+ onMicrophoneAccessDenied = _a.onMicrophoneAccessDenied,
3752
+ _f = _a.requireMicrophoneAccess,
3753
+ requireMicrophoneAccess = _f === void 0 ? false : _f;
3754
+ var videoRef = React.useRef(null);
3755
+ var store = React.useRef();
3756
+ store.current || (store.current = createCameraStore({
3757
+ videoRef: videoRef,
3758
+ requestAccessAutomatically: requestAccessAutomatically,
3759
+ preferIphoneContinuityCamera: preferIphoneContinuityCamera,
3760
+ preferFrontFacingCamera: preferFrontFacingCamera,
3761
+ maxVideoWidth: maxVideoWidth,
3762
+ maxFps: maxFps,
3763
+ onCameraAccessDenied: onCameraAccessDenied,
3764
+ onMicrophoneAccessDenied: onMicrophoneAccessDenied,
3765
+ requireMicrophoneAccess: requireMicrophoneAccess
3766
+ }));
3767
+ React.useEffect(function () {
3768
+ var _a, _b, _c;
3769
+ var state = (_a = store.current) === null || _a === void 0 ? void 0 : _a.getState();
3770
+ if (!state) return;
3771
+ if (preferIphoneContinuityCamera !== (state === null || state === void 0 ? void 0 : state.preferIphoneContinuityCamera) || preferFrontFacingCamera !== (state === null || state === void 0 ? void 0 : state.preferFrontFacingCamera)) {
3772
+ (_b = store.current) === null || _b === void 0 ? void 0 : _b.setState({
3773
+ preferIphoneContinuityCamera: preferIphoneContinuityCamera,
3774
+ preferFrontFacingCamera: preferFrontFacingCamera
3775
+ });
3776
+ (_c = store.current) === null || _c === void 0 ? void 0 : _c.getState().requestCameraAccess();
3777
+ }
3778
+ }, [preferFrontFacingCamera, preferIphoneContinuityCamera]);
3779
+ React.useEffect(function () {
3780
+ var _a;
3781
+ if (!requireMicrophoneAccess) return;
3782
+ (_a = store.current) === null || _a === void 0 ? void 0 : _a.getState().requestMicrophoneAccess();
3799
3783
  return function () {
3800
- loopId.current += 1;
3801
- frameId.current && cancelAnimationFrame(frameId.current);
3802
- timer && clearTimeout(timer);
3784
+ var _a;
3785
+ return (_a = store.current) === null || _a === void 0 ? void 0 : _a.getState().releaseMicrophoneAccess();
3803
3786
  };
3804
- }, [fn, running, throttleMs]);
3805
- var start = React.useCallback(function () {
3806
- startedAtRef.current = new Date();
3807
- setRunning(true);
3808
- }, []);
3809
- var stop = React.useCallback(function () {
3810
- loopId.current += 1; // force the loop to stop immediately.
3811
- setRunning(false);
3812
- startedAtRef.current = null;
3813
- }, []);
3814
- React.useEffect(function startAutomatically() {
3815
- if (autoStart) start();
3787
+ }, [requireMicrophoneAccess]);
3788
+ React.useEffect(function () {
3816
3789
  return function () {
3817
- stop();
3790
+ var _a;
3791
+ return (_a = store.current) === null || _a === void 0 ? void 0 : _a.destroy();
3818
3792
  };
3819
- }, [autoStart, start, stop]);
3820
- return {
3821
- start: start,
3822
- stop: stop
3823
- };
3793
+ }, []);
3794
+ return /*#__PURE__*/React__namespace.default.createElement(CameraStoreContext.Provider, {
3795
+ value: store.current
3796
+ }, children);
3797
+ }
3798
+ function useCameraStore(selector) {
3799
+ var store = React.useContext(CameraStoreContext);
3800
+ if (!store) throw new Error('useCameraStore cannot be used without Provider');
3801
+ return useStore(store, selector);
3824
3802
  }
3825
3803
 
3826
3804
  var DocumentDetectionModelContext = /*#__PURE__*/React.createContext({
@@ -3868,7 +3846,7 @@ function DocumentDetectionModelProvider(_a) {
3868
3846
  _g = _a.documentDetectionModelLoadTimeoutMs,
3869
3847
  documentDetectionModelLoadTimeoutMs = _g === void 0 ? defaultDocumentDetectionModelLoadTimeoutMs : _g,
3870
3848
  onDocumentDetectionModelError = _a.onDocumentDetectionModelError;
3871
- var _h = React.useContext(CameraStateContext),
3849
+ var _h = useCameraStore(),
3872
3850
  videoRef = _h.videoRef,
3873
3851
  videoLoaded = _h.videoLoaded,
3874
3852
  cameraReady = _h.cameraReady;
@@ -3891,7 +3869,8 @@ function DocumentDetectionModelProvider(_a) {
3891
3869
  modelPath: documentDetectionModelPath,
3892
3870
  modelLoadTimeoutMs: documentDetectionModelLoadTimeoutMs,
3893
3871
  scoreThreshold: documentDetectionModelScoreThreshold,
3894
- onModelError: onDocumentDetectionModelError
3872
+ onModelError: onDocumentDetectionModelError,
3873
+ videoRef: videoRef
3895
3874
  }),
3896
3875
  ready = _o.ready,
3897
3876
  modelDownloadProgress = _o.modelDownloadProgress,
@@ -4008,10 +3987,12 @@ function FocusModelProvider(_a) {
4008
3987
  var _e = React.useState({}),
4009
3988
  focusThresholds = _e[0],
4010
3989
  setFocusThresholds = _e[1];
3990
+ var videoRef = useCameraStore().videoRef;
4011
3991
  var _f = useLoadFocusModel({
4012
3992
  modelPath: focusModelPath,
4013
3993
  modelLoadTimeoutMs: focusModelLoadTimeoutMs,
4014
- onModelError: onFocusModelError
3994
+ onModelError: onFocusModelError,
3995
+ videoRef: videoRef
4015
3996
  }),
4016
3997
  ready = _f.ready,
4017
3998
  modelDownloadProgress = _f.modelDownloadProgress,
@@ -5133,31 +5114,33 @@ var Button = styled__default.default(LoaderButton)(templateObject_5$b || (templa
5133
5114
  var templateObject_1$D, templateObject_2$w, templateObject_3$o, templateObject_4$i, templateObject_5$b;
5134
5115
 
5135
5116
  var IdCapture = function IdCapture(_a) {
5136
- var _b, _c, _d, _e, _f, _g, _h, _j;
5117
+ var _b, _c, _d, _e, _f, _g, _h;
5137
5118
  var requiredDocumentType = _a.requiredDocumentType,
5138
- _k = _a.thresholds,
5139
- thresholds = _k === void 0 ? defaultIdCaptureThresholds : _k,
5119
+ _j = _a.thresholds,
5120
+ thresholds = _j === void 0 ? defaultIdCaptureThresholds : _j,
5140
5121
  guidanceMessage = _a.guidanceMessage,
5141
5122
  guidanceSatisfied = _a.guidanceSatisfied,
5142
5123
  onCapture = _a.onCapture,
5143
- _l = _a.classNames,
5144
- classNames = _l === void 0 ? {} : _l,
5145
- _m = _a.colors,
5146
- colors = _m === void 0 ? {} : _m,
5147
- _o = _a.verbiage,
5148
- rawVerbiage = _o === void 0 ? {} : _o,
5149
- _p = _a.debugMode,
5150
- debugMode = _p === void 0 ? false : _p;
5151
- var _q = useResizeObserver__default.default(),
5152
- ref = _q.ref,
5153
- _r = _q.width,
5154
- width = _r === void 0 ? 1 : _r,
5155
- _s = _q.height,
5156
- height = _s === void 0 ? 1 : _s;
5157
- var _t = useIdCaptureState(),
5158
- state = _t[0],
5159
- dispatch = _t[1];
5160
- var cameraRef = React.useContext(CameraStateContext).cameraRef;
5124
+ _k = _a.classNames,
5125
+ classNames = _k === void 0 ? {} : _k,
5126
+ _l = _a.colors,
5127
+ colors = _l === void 0 ? {} : _l,
5128
+ _m = _a.verbiage,
5129
+ rawVerbiage = _m === void 0 ? {} : _m,
5130
+ _o = _a.debugMode,
5131
+ debugMode = _o === void 0 ? false : _o;
5132
+ var _p = useResizeObserver__default.default(),
5133
+ ref = _p.ref,
5134
+ _q = _p.width,
5135
+ width = _q === void 0 ? 1 : _q,
5136
+ _r = _p.height,
5137
+ height = _r === void 0 ? 1 : _r;
5138
+ var _s = useIdCaptureState(),
5139
+ state = _s[0],
5140
+ dispatch = _s[1];
5141
+ var _t = useCameraStore(),
5142
+ camera = _t.camera,
5143
+ isRearFacing = _t.isRearFacing;
5161
5144
  var _u = React.useContext(IdCaptureModelsContext),
5162
5145
  modelsReady = _u.ready,
5163
5146
  setThresholds = _u.setThresholds,
@@ -5269,17 +5252,16 @@ var IdCapture = function IdCapture(_a) {
5269
5252
  classNames: classNames.overrideWrongDocumentTypeGuidanceDialog,
5270
5253
  verbiage: rawVerbiage.overrideWrongDocumentTypeGuidanceDialog
5271
5254
  }))), debugMode && ( /*#__PURE__*/React__namespace.default.createElement(DebugBoundingBoxOverlay, {
5272
- "$flipX": !((_j = cameraRef.current) === null || _j === void 0 ? void 0 : _j.isRearFacing),
5255
+ "$flipX": !isRearFacing,
5273
5256
  scaling: debugScalingDetails
5274
5257
  }, state.detectedObjects.map(function (obj, i) {
5275
- var _a;
5276
5258
  return /*#__PURE__*/React__namespace.default.createElement(IdCaptureDetectedObjectDebugBox, {
5277
5259
  key: i,
5278
5260
  obj: obj,
5279
5261
  scaling: debugScalingDetails,
5280
- flipX: !((_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.isRearFacing)
5262
+ flipX: !isRearFacing
5281
5263
  });
5282
- }))), debugMode && ( /*#__PURE__*/React__namespace.default.createElement(DebugStatsPane, null, cameraRef.current ? ( /*#__PURE__*/React__namespace.default.createElement(React__namespace.default.Fragment, null, "\u2705 Camera: ", cameraRef.current.label, " (", cameraRef.current.width, "x", cameraRef.current.height, ")")) : '❌ Camera not ready', /*#__PURE__*/React__namespace.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__namespace.default.createElement("br", null), modelsReady ? ( /*#__PURE__*/React__namespace.default.createElement(React__namespace.default.Fragment, null, state.detectionThresholdMet ? '✅' : '❌', " Detected Document Type: ", state.detectedDocumentType, /*#__PURE__*/React__namespace.default.createElement("br", null), state.idCardFrontDetectionThresholdMet ? '✅' : '❌', " ID Card Front Score: ", state.idCardFrontDetectionScore.toFixed(3), /*#__PURE__*/React__namespace.default.createElement("br", null), state.idCardBackDetectionThresholdMet ? '✅' : '❌', " ID Card Back Score: ", state.idCardBackDetectionScore.toFixed(3), /*#__PURE__*/React__namespace.default.createElement("br", null), state.passportDetectionThresholdMet ? '✅' : '❌', " Passport Score: ", state.passportDetectionScore.toFixed(3), /*#__PURE__*/React__namespace.default.createElement("br", null), state.focusThresholdMet ? '✅' : '❌', " Focus Score:", ' ', state.focusScore.toFixed(3), /*#__PURE__*/React__namespace.default.createElement("br", null), state.documentInBounds ? '✅' : '❌', " Document In Bounds", /*#__PURE__*/React__namespace.default.createElement("br", null), state.documentIsStable ? '✅' : '❌', " Document Is Stable", /*#__PURE__*/React__namespace.default.createElement("br", null), state.goodFramesThresholdMet ? '✅' : '❌', " Good Frame Count:", ' ', state.goodFramesCount, "/", state.goodFramesThreshold)) : ( /*#__PURE__*/React__namespace.default.createElement(React__namespace.default.Fragment, null, "\u274C Models not ready")))));
5264
+ }))), debugMode && ( /*#__PURE__*/React__namespace.default.createElement(DebugStatsPane, null, camera ? ( /*#__PURE__*/React__namespace.default.createElement(React__namespace.default.Fragment, null, "\u2705 Camera: ", camera.label, " (", camera.width, "x", camera.height, ")")) : '❌ Camera not ready', /*#__PURE__*/React__namespace.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__namespace.default.createElement("br", null), modelsReady ? ( /*#__PURE__*/React__namespace.default.createElement(React__namespace.default.Fragment, null, state.detectionThresholdMet ? '✅' : '❌', " Detected Document Type: ", state.detectedDocumentType, /*#__PURE__*/React__namespace.default.createElement("br", null), state.idCardFrontDetectionThresholdMet ? '✅' : '❌', " ID Card Front Score: ", state.idCardFrontDetectionScore.toFixed(3), /*#__PURE__*/React__namespace.default.createElement("br", null), state.idCardBackDetectionThresholdMet ? '✅' : '❌', " ID Card Back Score: ", state.idCardBackDetectionScore.toFixed(3), /*#__PURE__*/React__namespace.default.createElement("br", null), state.passportDetectionThresholdMet ? '✅' : '❌', " Passport Score: ", state.passportDetectionScore.toFixed(3), /*#__PURE__*/React__namespace.default.createElement("br", null), state.focusThresholdMet ? '✅' : '❌', " Focus Score:", ' ', state.focusScore.toFixed(3), /*#__PURE__*/React__namespace.default.createElement("br", null), state.documentInBounds ? '✅' : '❌', " Document In Bounds", /*#__PURE__*/React__namespace.default.createElement("br", null), state.documentIsStable ? '✅' : '❌', " Document Is Stable", /*#__PURE__*/React__namespace.default.createElement("br", null), state.goodFramesThresholdMet ? '✅' : '❌', " Good Frame Count:", ' ', state.goodFramesCount, "/", state.goodFramesThreshold)) : ( /*#__PURE__*/React__namespace.default.createElement(React__namespace.default.Fragment, null, "\u274C Models not ready")))));
5283
5265
  };
5284
5266
  var timeSince = function timeSince(t) {
5285
5267
  if (!t) return 0;
@@ -5296,7 +5278,9 @@ var CameraAccessDeniedOverlay = function CameraAccessDeniedOverlay(_a) {
5296
5278
  colors = _e === void 0 ? {} : _e,
5297
5279
  _f = _a.verbiage,
5298
5280
  rawVerbiage = _f === void 0 ? {} : _f;
5299
- var requestCameraAccess = React.useContext(CameraStateContext).requestCameraAccess;
5281
+ var requestCameraAccess = useCameraStore(function (state) {
5282
+ return state.requestCameraAccess;
5283
+ });
5300
5284
  assets.imageUrl || (assets.imageUrl = DEFAULT_CDN_URL + '/camera-disable-icon.png');
5301
5285
  var verbiage = useTranslations(rawVerbiage, {
5302
5286
  headingText: 'Your camera permission is disabled',
@@ -5944,7 +5928,7 @@ var IdCaptureLoadingOverlayDefault = function IdCaptureLoadingOverlayDefault(_a)
5944
5928
  var _o = React.useContext(IdCaptureModelsContext),
5945
5929
  modelsReady = _o.ready,
5946
5930
  modelDownloadProgress = _o.modelDownloadProgress;
5947
- var _p = React.useContext(CameraStateContext),
5931
+ var _p = useCameraStore(),
5948
5932
  cameraReady = _p.cameraReady,
5949
5933
  cameraAccessDenied = _p.cameraAccessDenied,
5950
5934
  iphoneContinuityCameraAvailable = _p.iphoneContinuityCameraAvailable,
@@ -6122,6 +6106,71 @@ var ContinueButton$1 = styled__default.default(LoaderButton)(templateObject_18 |
6122
6106
  });
6123
6107
  var templateObject_1$y, templateObject_2$t, templateObject_3$l, templateObject_4$f, templateObject_5$a, templateObject_6$8, templateObject_7$5, templateObject_8$2, templateObject_9$2, templateObject_10$1, templateObject_11$1, templateObject_12$1, templateObject_13$1, templateObject_14$1, templateObject_15$1, templateObject_16, templateObject_17, templateObject_18;
6124
6108
 
6109
+ function _createForOfIteratorHelperLoose(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (t) return (t = t.call(r)).next.bind(t); if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { t && (r = t); var o = 0; return function () { return o >= r.length ? { done: !0 } : { done: !1, value: r[o++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6110
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
6111
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
6112
+ var isIterable = function isIterable(obj) {
6113
+ return Symbol.iterator in obj;
6114
+ };
6115
+ var compareMapLike = function compareMapLike(iterableA, iterableB) {
6116
+ var mapA = iterableA instanceof Map ? iterableA : new Map(iterableA);
6117
+ var mapB = iterableB instanceof Map ? iterableB : new Map(iterableB);
6118
+ if (mapA.size !== mapB.size) return false;
6119
+ for (var _iterator = _createForOfIteratorHelperLoose(mapA), _step; !(_step = _iterator()).done;) {
6120
+ var _step$value = _step.value,
6121
+ key = _step$value[0],
6122
+ value = _step$value[1];
6123
+ if (!Object.is(value, mapB.get(key))) {
6124
+ return false;
6125
+ }
6126
+ }
6127
+ return true;
6128
+ };
6129
+ function shallow(objA, objB) {
6130
+ if (Object.is(objA, objB)) {
6131
+ return true;
6132
+ }
6133
+ if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) {
6134
+ return false;
6135
+ }
6136
+ if (isIterable(objA) && isIterable(objB)) {
6137
+ var iteratorA = objA[Symbol.iterator]();
6138
+ var iteratorB = objB[Symbol.iterator]();
6139
+ var nextA = iteratorA.next();
6140
+ var nextB = iteratorB.next();
6141
+ if (Array.isArray(nextA.value) && Array.isArray(nextB.value) && nextA.value.length === 2 && nextB.value.length === 2) {
6142
+ return compareMapLike(objA, objB);
6143
+ }
6144
+ while (!nextA.done && !nextB.done) {
6145
+ if (!Object.is(nextA.value, nextB.value)) {
6146
+ return false;
6147
+ }
6148
+ nextA = iteratorA.next();
6149
+ nextB = iteratorB.next();
6150
+ }
6151
+ return !!nextA.done && !!nextB.done;
6152
+ }
6153
+ var keysA = Object.keys(objA);
6154
+ if (keysA.length !== Object.keys(objB).length) {
6155
+ return false;
6156
+ }
6157
+ for (var _i = 0, _keysA = keysA; _i < _keysA.length; _i++) {
6158
+ var keyA = _keysA[_i];
6159
+ if (!Object.hasOwn(objB, keyA) || !Object.is(objA[keyA], objB[keyA])) {
6160
+ return false;
6161
+ }
6162
+ }
6163
+ return true;
6164
+ }
6165
+
6166
+ function useShallow(selector) {
6167
+ var prev = React__namespace.default.useRef();
6168
+ return function (state) {
6169
+ var next = selector(state);
6170
+ return shallow(prev.current, next) ? prev.current : prev.current = next;
6171
+ };
6172
+ }
6173
+
6125
6174
  var ContinuityCameraCheckboxContainer = styled__default.default.div(templateObject_1$x || (templateObject_1$x = __makeTemplateObject(["\n margin-top: 15px;\n margin-bottom: 15px;\n"], ["\n margin-top: 15px;\n margin-bottom: 15px;\n"])));
6126
6175
  var ContinuityCameraCheckbox = styled__default.default.input(templateObject_2$s || (templateObject_2$s = __makeTemplateObject(["\n margin-right: 8px;\n"], ["\n margin-right: 8px;\n"])));
6127
6176
  var IdCaptureLoadingOverlayLegacy = function IdCaptureLoadingOverlayLegacy(_a) {
@@ -6142,7 +6191,14 @@ var IdCaptureLoadingOverlayLegacy = function IdCaptureLoadingOverlayLegacy(_a) {
6142
6191
  var _l = React.useContext(IdCaptureModelsContext),
6143
6192
  modelsReady = _l.ready,
6144
6193
  modelDownloadProgress = _l.modelDownloadProgress;
6145
- var _m = React.useContext(CameraStateContext),
6194
+ var _m = useCameraStore(useShallow(function (state) {
6195
+ return {
6196
+ cameraReady: state.cameraReady,
6197
+ cameraAccessDenied: state.cameraAccessDenied,
6198
+ iphoneContinuityCameraAvailable: state.iphoneContinuityCameraAvailable,
6199
+ setIphoneContinuityCameraAllowed: state.setIphoneContinuityCameraAllowed
6200
+ };
6201
+ })),
6146
6202
  cameraReady = _m.cameraReady,
6147
6203
  cameraAccessDenied = _m.cameraAccessDenied,
6148
6204
  iphoneContinuityCameraAvailable = _m.iphoneContinuityCameraAvailable,
@@ -6688,23 +6744,24 @@ function getOrientation(allowPortraitOnMobile) {
6688
6744
  }
6689
6745
 
6690
6746
  var IdVideoCaptureFlipIdPrompt = function IdVideoCaptureFlipIdPrompt(_a) {
6691
- var _b;
6692
- var _c = _a.idCaptureGuideImages,
6693
- idCaptureGuideImages = _c === void 0 ? defaultIdCaptureGuideImages : _c,
6694
- _d = _a.classNames,
6695
- classNames = _d === void 0 ? {} : _d,
6747
+ var _b = _a.idCaptureGuideImages,
6748
+ idCaptureGuideImages = _b === void 0 ? defaultIdCaptureGuideImages : _b,
6749
+ _c = _a.classNames,
6750
+ classNames = _c === void 0 ? {} : _c,
6696
6751
  borderWidth = _a.borderWidth,
6697
6752
  borderColor = _a.borderColor,
6698
6753
  borderRadius = _a.borderRadius,
6699
6754
  imageStyle = _a.imageStyle;
6700
- var cameraRef = React.useContext(CameraStateContext).cameraRef;
6701
- var isMirrored = !((_b = cameraRef.current) === null || _b === void 0 ? void 0 : _b.isRearFacing);
6702
- var _e = React.useState(1),
6703
- transitionTime = _e[0],
6704
- setTransitionTime = _e[1];
6705
- var _f = React.useState(0),
6706
- rotationAngle = _f[0],
6707
- setRotationAngle = _f[1];
6755
+ var isRearFacing = useCameraStore(function (state) {
6756
+ return state.isRearFacing;
6757
+ });
6758
+ var isMirrored = !isRearFacing;
6759
+ var _d = React.useState(1),
6760
+ transitionTime = _d[0],
6761
+ setTransitionTime = _d[1];
6762
+ var _e = React.useState(0),
6763
+ rotationAngle = _e[0],
6764
+ setRotationAngle = _e[1];
6708
6765
  var frontTransforms = ["rotateY(".concat(rotationAngle, "deg)")];
6709
6766
  if (isMirrored) frontTransforms.push('scaleX(-1)');
6710
6767
  var backTransforms = ["rotateY(".concat(180 - rotationAngle, "deg)")];
@@ -7228,29 +7285,30 @@ var Canvas$1 = styled__default.default.canvas(templateObject_2$n || (templateObj
7228
7285
  var templateObject_1$r, templateObject_2$n;
7229
7286
 
7230
7287
  function IdCaptureGuides(_a) {
7231
- var _b, _c;
7232
- var _d = _a.guideType,
7233
- guideType = _d === void 0 ? 'fit' : _d,
7234
- _e = _a.status,
7235
- status = _e === void 0 ? 'ready' : _e,
7236
- _f = _a.progress,
7237
- progress = _f === void 0 ? 0 : _f,
7238
- _g = _a.portraitGuidesOnMobile,
7239
- portraitGuidesOnMobile = _g === void 0 ? true : _g,
7240
- _h = _a.requestedAction,
7241
- requestedAction = _h === void 0 ? 'SHOW_ID_FRONT' : _h,
7242
- _j = _a.isBackToFront,
7243
- isBackToFront = _j === void 0 ? false : _j,
7244
- _k = _a.images,
7245
- images = _k === void 0 ? defaultIdCaptureGuideImages : _k,
7246
- _l = _a.classNames,
7247
- classNames = _l === void 0 ? {} : _l,
7248
- _m = _a.colors,
7249
- colors = _m === void 0 ? {} : _m,
7250
- _o = _a.verbiage,
7251
- rawVerbiage = _o === void 0 ? {} : _o;
7288
+ var _b = _a.guideType,
7289
+ guideType = _b === void 0 ? 'fit' : _b,
7290
+ _c = _a.status,
7291
+ status = _c === void 0 ? 'ready' : _c,
7292
+ _d = _a.progress,
7293
+ progress = _d === void 0 ? 0 : _d,
7294
+ _e = _a.portraitGuidesOnMobile,
7295
+ portraitGuidesOnMobile = _e === void 0 ? true : _e,
7296
+ _f = _a.requestedAction,
7297
+ requestedAction = _f === void 0 ? 'SHOW_ID_FRONT' : _f,
7298
+ _g = _a.isBackToFront,
7299
+ isBackToFront = _g === void 0 ? false : _g,
7300
+ _h = _a.images,
7301
+ images = _h === void 0 ? defaultIdCaptureGuideImages : _h,
7302
+ _j = _a.classNames,
7303
+ classNames = _j === void 0 ? {} : _j,
7304
+ _k = _a.colors,
7305
+ colors = _k === void 0 ? {} : _k,
7306
+ _l = _a.verbiage,
7307
+ rawVerbiage = _l === void 0 ? {} : _l;
7252
7308
  var state = useIdCaptureState()[0];
7253
- var cameraRef = React.useContext(CameraStateContext).cameraRef;
7309
+ var isRearFacing = useCameraStore(function (state) {
7310
+ return state.isRearFacing;
7311
+ });
7254
7312
  var verbiage = useTranslations(rawVerbiage, {
7255
7313
  instructionText: 'Scan the front of ID',
7256
7314
  capturingText: 'Capturing...',
@@ -7262,7 +7320,7 @@ function IdCaptureGuides(_a) {
7262
7320
  status: status,
7263
7321
  progress: progress,
7264
7322
  instruction: state.captureFailed ? verbiage.captureFailedText : state.capturing ? verbiage === null || verbiage === void 0 ? void 0 : verbiage.capturingText : verbiage.instructionText,
7265
- isMirrored: !((_b = cameraRef.current) === null || _b === void 0 ? void 0 : _b.isRearFacing),
7323
+ isMirrored: !isRearFacing,
7266
7324
  borderColor: state.isGoodFrame ? colors.guideBoxSatisfiedColor : colors.guideBoxUnsatisfiedColor,
7267
7325
  imageVisible: requestedAction === 'FLIP_ID' || !state.idCardFrontDetectionThresholdMet || !state.documentInBounds || state.documentTooClose
7268
7326
  })), guideType === 'fit' && ( /*#__PURE__*/React__namespace.default.createElement(IdCaptureFitGuide, {
@@ -7272,7 +7330,7 @@ function IdCaptureGuides(_a) {
7272
7330
  status: status,
7273
7331
  progress: progress,
7274
7332
  instruction: state.captureFailed ? verbiage.captureFailedText : state.capturing ? verbiage === null || verbiage === void 0 ? void 0 : verbiage.capturingText : verbiage.instructionText,
7275
- isMirrored: !((_c = cameraRef.current) === null || _c === void 0 ? void 0 : _c.isRearFacing),
7333
+ isMirrored: !isRearFacing,
7276
7334
  isBackToFront: isBackToFront,
7277
7335
  portraitGuidesOnMobile: portraitGuidesOnMobile,
7278
7336
  borderColor: state.isGoodFrame ? colors.guideBoxSatisfiedColor : colors.guideBoxUnsatisfiedColor,
@@ -7371,48 +7429,6 @@ var ImagePreviewText = styled__default.default.div(templateObject_3$h || (templa
7371
7429
  var ImagePreviewImageWrapper = styled__default.default.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"])));
7372
7430
  var templateObject_1$q, templateObject_2$m, templateObject_3$h, templateObject_4$b;
7373
7431
 
7374
- var CameraVideoTag = function CameraVideoTag(_a) {
7375
- var _b;
7376
- var className = _a.className;
7377
- var _c = React.useContext(CameraStateContext),
7378
- videoRef = _c.videoRef,
7379
- setVideoLoaded = _c.setVideoLoaded,
7380
- onVideoUnmounted = _c.onVideoUnmounted,
7381
- cameraRef = _c.cameraRef;
7382
- React.useEffect(function notifyCameraProviderOfUnmount() {
7383
- var videoElement = videoRef.current;
7384
- if (!videoElement) return;
7385
- return function () {
7386
- onVideoUnmounted(videoElement);
7387
- };
7388
- }, [onVideoUnmounted, videoRef]);
7389
- React.useEffect(function setVideoLoadedToFalseOnMount() {
7390
- setVideoLoaded(false);
7391
- }, [setVideoLoaded]);
7392
- React.useEffect(function attachCameraStreamToVideoTagWhenReady() {
7393
- var _a;
7394
- if (videoRef.current && ((_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.stream)) {
7395
- videoRef.current.srcObject = cameraRef.current.stream;
7396
- }
7397
- }, [cameraRef, videoRef]);
7398
- var onLoadedData = React.useCallback(function () {
7399
- setVideoLoaded(true);
7400
- }, [setVideoLoaded]);
7401
- return /*#__PURE__*/React__namespace.default.createElement(FullscreenVideoTag, {
7402
- className: className,
7403
- autoPlay: true,
7404
- playsInline: true,
7405
- muted: true,
7406
- ref: videoRef,
7407
- onLoadedData: onLoadedData,
7408
- "$isRearFacing": (_b = cameraRef.current) === null || _b === void 0 ? void 0 : _b.isRearFacing
7409
- });
7410
- };
7411
- var FullscreenVideoTag = styled__default.default.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) {
7412
- return props.$isRearFacing ? '' : 'scaleX(-1)';
7413
- });
7414
- var templateObject_1$p;
7415
-
7416
7432
  var documentCaptureInitialState = {
7417
7433
  documents: [],
7418
7434
  currentDocumentIndex: 0,
@@ -7531,8 +7547,8 @@ var DocumentCaptureStateProvider = function DocumentCaptureStateProvider(_a) {
7531
7547
  var _c = React.useReducer(documentCaptureStateReducer, documentCaptureInitialState),
7532
7548
  state = _c[0],
7533
7549
  dispatch = _c[1];
7534
- var _d = React.useContext(CameraStateContext),
7535
- cameraRef = _d.cameraRef,
7550
+ var _d = useCameraStore(),
7551
+ videoStream = _d.videoStream,
7536
7552
  videoRef = _d.videoRef;
7537
7553
  var uploadDocument = React.useContext(SubmissionContext).uploadDocument;
7538
7554
  var uploadCapturedDocument = React.useCallback(function (content, filetype) {
@@ -7623,8 +7639,7 @@ var DocumentCaptureStateProvider = function DocumentCaptureStateProvider(_a) {
7623
7639
  }, [onResize]);
7624
7640
  var videoTag = videoRef.current;
7625
7641
  React.useEffect(function () {
7626
- if (!state.capturing) return;
7627
- if (!cameraRef.current) return;
7642
+ if (!state.capturing || !(videoStream === null || videoStream === void 0 ? void 0 : videoStream.active)) return;
7628
7643
  function onComplete(content) {
7629
7644
  if (!content) return;
7630
7645
  var contentUrl = URL.createObjectURL(content);
@@ -7637,7 +7652,7 @@ var DocumentCaptureStateProvider = function DocumentCaptureStateProvider(_a) {
7637
7652
  });
7638
7653
  }
7639
7654
  if (typeof ImageCapture !== 'undefined') {
7640
- var tracks = cameraRef.current.stream.getTracks();
7655
+ var tracks = videoStream.getTracks();
7641
7656
  var videoCameraTrack = tracks.find(function (track) {
7642
7657
  return track.kind === 'video';
7643
7658
  });
@@ -7652,7 +7667,7 @@ var DocumentCaptureStateProvider = function DocumentCaptureStateProvider(_a) {
7652
7667
  drawToCanvas(canvas, videoTag);
7653
7668
  canvas.toBlob(onComplete);
7654
7669
  }
7655
- }, [cameraRef, state.capturing, videoTag]);
7670
+ }, [state.capturing, videoStream, videoTag]);
7656
7671
  var stateWithActions = React.useMemo(function () {
7657
7672
  return _assign(_assign({}, state), {
7658
7673
  uploadCapturedDocument: uploadCapturedDocument
@@ -7767,52 +7782,85 @@ var DocumentCaptureGuideOverlay = function DocumentCaptureGuideOverlay(_a) {
7767
7782
  ref: canvasRef
7768
7783
  }));
7769
7784
  };
7770
- var CanvasWrapper = styled__default.default.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) {
7785
+ var CanvasWrapper = styled__default.default.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) {
7771
7786
  return props.$maskColor;
7772
7787
  });
7773
7788
  var Canvas = styled__default.default.canvas(templateObject_2$l || (templateObject_2$l = __makeTemplateObject(["\n display: block;\n"], ["\n display: block;\n"])));
7774
- var templateObject_1$o, templateObject_2$l;
7789
+ var templateObject_1$p, templateObject_2$l;
7775
7790
 
7776
- var CameraFeedWrapper = styled__default.default.div(templateObject_1$n || (templateObject_1$n = __makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), function (props) {
7791
+ var CameraFeedWrapper = styled__default.default.div(templateObject_1$o || (templateObject_1$o = __makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), function (props) {
7777
7792
  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;") : "";
7778
7793
  });
7794
+ var templateObject_1$o;
7795
+
7796
+ var CameraVideoTag = function CameraVideoTag(props) {
7797
+ var _a = useCameraStore(useShallow(function (store) {
7798
+ return {
7799
+ videoRef: store.videoRef,
7800
+ videoStream: store.videoStream,
7801
+ onVideoMounted: store.onVideoMounted,
7802
+ isRearFacing: store.isRearFacing
7803
+ };
7804
+ })),
7805
+ videoRef = _a.videoRef,
7806
+ videoStream = _a.videoStream,
7807
+ onVideoMounted = _a.onVideoMounted,
7808
+ isRearFacing = _a.isRearFacing;
7809
+ React.useEffect(function attachCameraStreamToVideoTagWhenReady() {
7810
+ if (videoRef.current && videoStream) {
7811
+ debug('attaching camera stream to video tag');
7812
+ videoRef.current.srcObject = videoStream;
7813
+ }
7814
+ }, [videoStream, videoRef]);
7815
+ return /*#__PURE__*/React__namespace.default.createElement(FullscreenVideoTag, _assign({
7816
+ autoPlay: true,
7817
+ playsInline: true,
7818
+ muted: true,
7819
+ ref: videoRef,
7820
+ onLoadedData: onVideoMounted,
7821
+ "$isRearFacing": isRearFacing
7822
+ }, props));
7823
+ };
7824
+ var FullscreenVideoTag = styled__default.default.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) {
7825
+ return props.$isRearFacing ? '' : 'scaleX(-1)';
7826
+ });
7779
7827
  var templateObject_1$n;
7780
7828
 
7781
7829
  var DocumentCaptureScreen = function DocumentCaptureScreen(_a) {
7782
- var _b, _c, _d, _e, _f, _g, _h;
7830
+ var _b, _c, _d, _e, _f;
7783
7831
  var onCaptureClicked = _a.onCaptureClicked,
7784
- _j = _a.classNames,
7785
- classNames = _j === void 0 ? {} : _j,
7786
- _k = _a.verbiage,
7787
- rawVerbiage = _k === void 0 ? {} : _k;
7788
- var _l = useDocumentCaptureState(),
7789
- _m = _l[0],
7790
- documents = _m.documents,
7791
- currentDocumentIndex = _m.currentDocumentIndex,
7792
- rectX = _m.rectX,
7793
- rectY = _m.rectY,
7794
- rectWidth = _m.rectWidth,
7795
- rectHeight = _m.rectHeight,
7796
- rectOffsetTop = _m.rectOffsetTop,
7797
- capturing = _m.capturing,
7798
- uploadCapturedDocument = _m.uploadCapturedDocument,
7799
- dispatch = _l[1];
7800
- var _o = (_b = documents[currentDocumentIndex]) !== null && _b !== void 0 ? _b : {},
7801
- title = _o.title,
7802
- aspectRatio = _o.aspectRatio,
7803
- cameraFeedMode = _o.cameraFeedMode,
7804
- instructions = _o.instructions,
7805
- contentUrl = _o.contentUrl,
7806
- content = _o.content,
7807
- uploadState = _o.uploadState;
7808
- var _p = React.useContext(CameraStateContext),
7809
- cameraRef = _p.cameraRef,
7810
- cameraReady = _p.cameraReady,
7811
- cameraAccessDenied = _p.cameraAccessDenied,
7812
- requestCameraAccess = _p.requestCameraAccess;
7813
- var _q = React.useState(false),
7814
- cameraAccessRequested = _q[0],
7815
- setCameraAccessRequested = _q[1];
7832
+ _g = _a.classNames,
7833
+ classNames = _g === void 0 ? {} : _g,
7834
+ _h = _a.verbiage,
7835
+ rawVerbiage = _h === void 0 ? {} : _h;
7836
+ var _j = useDocumentCaptureState(),
7837
+ _k = _j[0],
7838
+ documents = _k.documents,
7839
+ currentDocumentIndex = _k.currentDocumentIndex,
7840
+ rectX = _k.rectX,
7841
+ rectY = _k.rectY,
7842
+ rectWidth = _k.rectWidth,
7843
+ rectHeight = _k.rectHeight,
7844
+ rectOffsetTop = _k.rectOffsetTop,
7845
+ capturing = _k.capturing,
7846
+ uploadCapturedDocument = _k.uploadCapturedDocument,
7847
+ dispatch = _j[1];
7848
+ var _l = (_b = documents[currentDocumentIndex]) !== null && _b !== void 0 ? _b : {},
7849
+ title = _l.title,
7850
+ aspectRatio = _l.aspectRatio,
7851
+ cameraFeedMode = _l.cameraFeedMode,
7852
+ instructions = _l.instructions,
7853
+ contentUrl = _l.contentUrl,
7854
+ content = _l.content,
7855
+ uploadState = _l.uploadState;
7856
+ var _m = useCameraStore(),
7857
+ videoStream = _m.videoStream,
7858
+ cameraReady = _m.cameraReady,
7859
+ cameraAccessDenied = _m.cameraAccessDenied,
7860
+ requestCameraAccess = _m.requestCameraAccess;
7861
+ var _o = React.useState(false),
7862
+ cameraAccessRequested = _o[0],
7863
+ setCameraAccessRequested = _o[1];
7816
7864
  var cameraAccessNeeded =
7817
7865
  // we should force the browser to ask for camera access if...
7818
7866
  uploadState === 'not_started' &&
@@ -7821,14 +7869,14 @@ var DocumentCaptureScreen = function DocumentCaptureScreen(_a) {
7821
7869
  // and the user hasn't passed a media blob for the current document...
7822
7870
  !cameraAccessRequested &&
7823
7871
  // and we haven't already tried to force a camera request...
7824
- !((_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.
7872
+ !(videoStream === null || videoStream === void 0 ? void 0 : videoStream.active); // and we don't already have camera access.
7825
7873
  React.useEffect(function requestCameraAccessIfNeeded() {
7826
7874
  if (!cameraAccessNeeded) return;
7827
7875
  setCameraAccessRequested(true);
7828
7876
  requestCameraAccess();
7829
7877
  }, [cameraAccessNeeded, requestCameraAccess]);
7830
7878
  var theme = styled.useTheme();
7831
- 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)";
7879
+ 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)";
7832
7880
  var verbiage = useTranslations(rawVerbiage, {
7833
7881
  headingText: title,
7834
7882
  loadingBtnText: 'Camera initializing...',
@@ -7861,7 +7909,7 @@ var DocumentCaptureScreen = function DocumentCaptureScreen(_a) {
7861
7909
  });
7862
7910
  }
7863
7911
  return /*#__PURE__*/React__namespace.default.createElement(PageContainer, {
7864
- className: "flex ".concat((_h = classNames.container) !== null && _h !== void 0 ? _h : '')
7912
+ className: "flex ".concat((_f = classNames.container) !== null && _f !== void 0 ? _f : '')
7865
7913
  }, /*#__PURE__*/React__namespace.default.createElement(CameraFeedWrapper, {
7866
7914
  className: classNames.cameraFeedWrapper,
7867
7915
  "$mode": cameraFeedMode !== null && cameraFeedMode !== void 0 ? cameraFeedMode : 'snapToGuides',
@@ -8286,7 +8334,7 @@ var IdCaptureWizard = function IdCaptureWizard(_a) {
8286
8334
  var _3 = useIdCaptureState(),
8287
8335
  state = _3[0],
8288
8336
  dispatch = _3[1];
8289
- var _4 = React.useContext(CameraStateContext),
8337
+ var _4 = useCameraStore(),
8290
8338
  cameraAccessDenied = _4.cameraAccessDenied,
8291
8339
  requestCameraAccess = _4.requestCameraAccess,
8292
8340
  releaseCameraAccess = _4.releaseCameraAccess;
@@ -8411,7 +8459,7 @@ var IdCaptureWizard = function IdCaptureWizard(_a) {
8411
8459
  type: 'resetWizard'
8412
8460
  });
8413
8461
  onExitCapture === null || onExitCapture === void 0 ? void 0 : onExitCapture();
8414
- requestCameraAccess();
8462
+ void requestCameraAccess();
8415
8463
  }, [dispatch, onExitCapture, releaseCameraAccess, requestCameraAccess]);
8416
8464
  React.useEffect(function () {
8417
8465
  if (submissionStatus !== SubmissionStatus.READY) {
@@ -9234,7 +9282,13 @@ function SelfieGuidanceModelsProvider(_a) {
9234
9282
  modelLoadTimeoutMs = _c === void 0 ? defaultSelfieCaptureModelLoadTimeoutMs : _c,
9235
9283
  _d = _a.requireVerticalFaceCentering,
9236
9284
  requireVerticalFaceCentering = _d === void 0 ? true : _d;
9237
- var _e = React.useContext(CameraStateContext),
9285
+ var _e = useCameraStore(useShallow(function (state) {
9286
+ return {
9287
+ videoRef: state.videoRef,
9288
+ videoLoaded: state.videoLoaded,
9289
+ cameraReady: state.cameraReady
9290
+ };
9291
+ })),
9238
9292
  videoRef = _e.videoRef,
9239
9293
  videoLoaded = _e.videoLoaded,
9240
9294
  cameraReady = _e.cameraReady;
@@ -9242,7 +9296,8 @@ function SelfieGuidanceModelsProvider(_a) {
9242
9296
  var onPredictionHandler = React.useRef();
9243
9297
  var _f = useLoadFaceDetector({
9244
9298
  onModelError: onModelError,
9245
- modelLoadTimeoutMs: modelLoadTimeoutMs
9299
+ modelLoadTimeoutMs: modelLoadTimeoutMs,
9300
+ videoRef: videoRef
9246
9301
  }),
9247
9302
  ready = _f.ready,
9248
9303
  modelDownloadProgress = _f.modelDownloadProgress,
@@ -9575,8 +9630,14 @@ var SelfieCapture = function SelfieCapture(_a) {
9575
9630
  prediction = _t.prediction,
9576
9631
  dispatch = _s[1];
9577
9632
  var lastPredictionCanvas = React.useRef(null);
9578
- var _u = React.useContext(CameraStateContext),
9579
- cameraRef = _u.cameraRef,
9633
+ var _u = useCameraStore(useShallow(function (state) {
9634
+ return {
9635
+ camera: state.camera,
9636
+ cameraReady: state.cameraReady,
9637
+ videoRef: state.videoRef
9638
+ };
9639
+ })),
9640
+ camera = _u.camera,
9580
9641
  videoRef = _u.videoRef;
9581
9642
  var _v = React.useContext(SelfieGuidanceModelsContext),
9582
9643
  onPredictionMade = _v.onPredictionMade,
@@ -9666,7 +9727,7 @@ var SelfieCapture = function SelfieCapture(_a) {
9666
9727
  face: prediction.face,
9667
9728
  scaling: debugScalingDetails,
9668
9729
  color: satisfied ? 'green' : 'red'
9669
- }))), debugMode && ( /*#__PURE__*/React__namespace.default.createElement(DebugStatsPane, null, cameraRef.current ? ( /*#__PURE__*/React__namespace.default.createElement(React__namespace.default.Fragment, null, "\u2705 Camera: ", cameraRef.current.label, " (", cameraRef.current.width, "x", cameraRef.current.height, ")")) : '❌ Camera not ready', /*#__PURE__*/React__namespace.default.createElement("br", null), !(prediction === null || prediction === void 0 ? void 0 : prediction.faceNotCentered) ? '✅' : '❌', " Face Centered", /*#__PURE__*/React__namespace.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__namespace.default.createElement("br", null), !(prediction === null || prediction === void 0 ? void 0 : prediction.faceLookingAway) ? '✅' : '❌', " Face Looking Forward", /*#__PURE__*/React__namespace.default.createElement("br", null), !(prediction === null || prediction === void 0 ? void 0 : prediction.faceIsStable) ? '✅' : '❌', " Face Is Stable", /*#__PURE__*/React__namespace.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__namespace.default.createElement(ExitCaptureButton, {
9730
+ }))), debugMode && ( /*#__PURE__*/React__namespace.default.createElement(DebugStatsPane, null, camera ? ( /*#__PURE__*/React__namespace.default.createElement(React__namespace.default.Fragment, null, "\u2705 Camera: ", camera.label, " (", camera.width, "x", camera.height, ")")) : '❌ Camera not ready', /*#__PURE__*/React__namespace.default.createElement("br", null), !(prediction === null || prediction === void 0 ? void 0 : prediction.faceNotCentered) ? '✅' : '❌', " Face Centered", /*#__PURE__*/React__namespace.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__namespace.default.createElement("br", null), !(prediction === null || prediction === void 0 ? void 0 : prediction.faceLookingAway) ? '✅' : '❌', " Face Looking Forward", /*#__PURE__*/React__namespace.default.createElement("br", null), !(prediction === null || prediction === void 0 ? void 0 : prediction.faceIsStable) ? '✅' : '❌', " Face Is Stable", /*#__PURE__*/React__namespace.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__namespace.default.createElement(ExitCaptureButton, {
9670
9731
  onClick: onExit,
9671
9732
  className: classNames.exitCaptureBtn
9672
9733
  }));
@@ -10122,7 +10183,9 @@ var MicrophoneAccessDeniedOverlay = function MicrophoneAccessDeniedOverlay(_a) {
10122
10183
  colors = _e === void 0 ? {} : _e,
10123
10184
  _f = _a.verbiage,
10124
10185
  rawVerbiage = _f === void 0 ? {} : _f;
10125
- var requestMicrophoneAccess = React.useContext(CameraStateContext).requestMicrophoneAccess;
10186
+ var requestMicrophoneAccess = useCameraStore(function (state) {
10187
+ return state.requestMicrophoneAccess;
10188
+ });
10126
10189
  assets.imageUrl || (assets.imageUrl = DEFAULT_CDN_URL + '/microphone-disable-icon.svg');
10127
10190
  var verbiage = useTranslations(rawVerbiage, {
10128
10191
  headingText: 'Your microphone permission is disabled',
@@ -10170,7 +10233,13 @@ var SelfieCaptureLoadingOverlayLegacy = function SelfieCaptureLoadingOverlayLega
10170
10233
  colors = _e === void 0 ? {} : _e,
10171
10234
  _f = _a.verbiage,
10172
10235
  rawVerbiage = _f === void 0 ? {} : _f;
10173
- var _g = React.useContext(CameraStateContext),
10236
+ var _g = useCameraStore(useShallow(function (state) {
10237
+ return {
10238
+ cameraReady: state.cameraReady,
10239
+ cameraAccessDenied: state.cameraAccessDenied,
10240
+ microphoneAccessDenied: state.microphoneAccessDenied
10241
+ };
10242
+ })),
10174
10243
  cameraReady = _g.cameraReady,
10175
10244
  cameraAccessDenied = _g.cameraAccessDenied,
10176
10245
  microphoneAccessDenied = _g.microphoneAccessDenied;
@@ -10257,7 +10326,13 @@ var SelfieCaptureLoadingOverlayDefault = function SelfieCaptureLoadingOverlayDef
10257
10326
  colors = _e === void 0 ? {} : _e,
10258
10327
  _f = _a.verbiage,
10259
10328
  rawVerbiage = _f === void 0 ? {} : _f;
10260
- var _g = React.useContext(CameraStateContext),
10329
+ var _g = useCameraStore(useShallow(function (state) {
10330
+ return {
10331
+ cameraReady: state.cameraReady,
10332
+ cameraAccessDenied: state.cameraAccessDenied,
10333
+ microphoneAccessDenied: state.microphoneAccessDenied
10334
+ };
10335
+ })),
10261
10336
  cameraReady = _g.cameraReady,
10262
10337
  cameraAccessDenied = _g.cameraAccessDenied,
10263
10338
  microphoneAccessDenied = _g.microphoneAccessDenied;
@@ -10474,7 +10549,13 @@ var FaceLivenessWizard = function FaceLivenessWizard(_a) {
10474
10549
  livenessCheckRequest = _t.livenessCheckRequest,
10475
10550
  setSelfieImage = _t.setSelfieImage,
10476
10551
  logSelfieCaptureAttempt = _t.logSelfieCaptureAttempt;
10477
- var _u = React.useContext(CameraStateContext),
10552
+ var _u = useCameraStore(useShallow(function (state) {
10553
+ return {
10554
+ cameraAccessDenied: state.cameraAccessDenied,
10555
+ requestCameraAccess: state.requestCameraAccess,
10556
+ releaseCameraAccess: state.releaseCameraAccess
10557
+ };
10558
+ })),
10478
10559
  cameraAccessDenied = _u.cameraAccessDenied,
10479
10560
  requestCameraAccess = _u.requestCameraAccess,
10480
10561
  releaseCameraAccess = _u.releaseCameraAccess;
@@ -11195,10 +11276,10 @@ function VideoSignatureContextProvider(_a) {
11195
11276
  setSignatureVideoUrl = _e[1];
11196
11277
  var signatureRecorder = React.useRef(null);
11197
11278
  var recordedChunks = React.useRef([]);
11198
- var _f = React.useContext(CameraStateContext),
11199
- cameraRef = _f.cameraRef,
11279
+ var _f = useCameraStore(),
11280
+ camera = _f.camera,
11200
11281
  videoRef = _f.videoRef;
11201
- var _g = useVideoRecorder(cameraRef.current),
11282
+ var _g = useVideoRecorder(camera),
11202
11283
  isRecordingVideo = _g.isRecordingVideo,
11203
11284
  startRecordingVideo = _g.startRecordingVideo,
11204
11285
  stopRecordingVideo = _g.stopRecordingVideo,
@@ -11266,8 +11347,8 @@ function VideoSignatureContextProvider(_a) {
11266
11347
  var animationFrame = React.useRef(0);
11267
11348
  React.useEffect(function () {
11268
11349
  var _a;
11269
- if (!signaturePad.current || !videoRef.current || !outputCanvas.current || !cameraRef.current || !isRecording || !isRecordingVideo) return;
11270
- var _b = [cameraRef.current.width, cameraRef.current.height],
11350
+ if (!signaturePad.current || !videoRef.current || !outputCanvas.current || !camera || !isRecording || !isRecordingVideo) return;
11351
+ var _b = [camera.width, camera.height],
11271
11352
  w = _b[0],
11272
11353
  h = _b[1];
11273
11354
  var isPortrait = typeof window !== 'undefined' && window.innerWidth < window.innerHeight;
@@ -11300,7 +11381,7 @@ function VideoSignatureContextProvider(_a) {
11300
11381
  return function () {
11301
11382
  cancelAnimationFrame(animationFrame.current);
11302
11383
  };
11303
- }, [cameraRef, isRecording, isRecordingVideo, videoRef]);
11384
+ }, [camera, isRecording, isRecordingVideo, videoRef]);
11304
11385
  var onAcceptClicked = React.useCallback(function () {
11305
11386
  return __awaiter(_this, void 0, void 0, function () {
11306
11387
  var imageUrl;
@@ -11429,27 +11510,29 @@ var AcceptBtn = styled__default.default(LoaderButton)(templateObject_7$1 || (tem
11429
11510
  var templateObject_1$9, templateObject_2$8, templateObject_3$8, templateObject_4$3, templateObject_5$2, templateObject_6$2, templateObject_7$1;
11430
11511
 
11431
11512
  var VideoSignatureCapture = function VideoSignatureCapture(_a) {
11432
- var _b, _c, _d;
11513
+ var _b;
11433
11514
  var onVideoCaptured = _a.onVideoCaptured,
11434
11515
  onFaceNotDetected = _a.onFaceNotDetected,
11435
11516
  onExit = _a.onExit,
11436
11517
  guidesComponent = _a.guidesComponent,
11437
- _e = _a.classNames,
11438
- classNames = _e === void 0 ? {} : _e,
11439
- _f = _a.colors,
11440
- colors = _f === void 0 ? {} : _f,
11441
- _g = _a.verbiage,
11442
- rawVerbiage = _g === void 0 ? {} : _g,
11443
- _h = _a.debugMode,
11444
- debugMode = _h === void 0 ? false : _h;
11445
- var cameraRef = React.useContext(CameraStateContext).cameraRef;
11518
+ _c = _a.classNames,
11519
+ classNames = _c === void 0 ? {} : _c,
11520
+ _d = _a.colors,
11521
+ colors = _d === void 0 ? {} : _d,
11522
+ _e = _a.verbiage,
11523
+ rawVerbiage = _e === void 0 ? {} : _e,
11524
+ _f = _a.debugMode,
11525
+ debugMode = _f === void 0 ? false : _f;
11526
+ var camera = useCameraStore(function (state) {
11527
+ return state.camera;
11528
+ });
11446
11529
  var onPredictionMade = React.useContext(SelfieGuidanceModelsContext).onPredictionMade;
11447
- var _j = useVideoSignatureContext(),
11448
- signatureData = _j.signatureData,
11449
- signatureDataUrl = _j.signatureDataUrl,
11450
- signatureVideoData = _j.signatureVideoData,
11451
- startRecording = _j.startRecording,
11452
- stopRecording = _j.stopRecording;
11530
+ var _g = useVideoSignatureContext(),
11531
+ signatureData = _g.signatureData,
11532
+ signatureDataUrl = _g.signatureDataUrl,
11533
+ signatureVideoData = _g.signatureVideoData,
11534
+ startRecording = _g.startRecording,
11535
+ stopRecording = _g.stopRecording;
11453
11536
  React.useEffect(function () {
11454
11537
  startRecording();
11455
11538
  return function () {
@@ -11466,9 +11549,9 @@ var VideoSignatureCapture = function VideoSignatureCapture(_a) {
11466
11549
  onVideoCaptured === null || onVideoCaptured === void 0 ? void 0 : onVideoCaptured(signatureVideoData, signatureData, signatureDataUrl);
11467
11550
  }
11468
11551
  }, [onVideoCaptured, signatureData, signatureDataUrl, signatureVideoData]);
11469
- var _k = React.useState(0),
11470
- numFramesWithoutFaces = _k[0],
11471
- setNumFramesWithoutFaces = _k[1];
11552
+ var _h = React.useState(0),
11553
+ numFramesWithoutFaces = _h[0],
11554
+ setNumFramesWithoutFaces = _h[1];
11472
11555
  React.useEffect(function () {
11473
11556
  onPredictionMade(function (_a) {
11474
11557
  var face = _a.face;
@@ -11495,7 +11578,7 @@ var VideoSignatureCapture = function VideoSignatureCapture(_a) {
11495
11578
  }, verbiage.guidanceMessageText))), /*#__PURE__*/React__namespace.default.createElement(GuidesComponent, {
11496
11579
  classNames: classNames.videoSignatureGuidesClassNames,
11497
11580
  status: "success"
11498
- }), debugMode && ( /*#__PURE__*/React__namespace.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__namespace.default.createElement(ExitCaptureButton, {
11581
+ }), debugMode && ( /*#__PURE__*/React__namespace.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__namespace.default.createElement(ExitCaptureButton, {
11499
11582
  onClick: onExit,
11500
11583
  className: classNames.exitCaptureBtn
11501
11584
  }));
@@ -11589,7 +11672,13 @@ var VideoSignatureWizard = function VideoSignatureWizard(_a) {
11589
11672
  setSignatureData = _l.setSignatureData,
11590
11673
  setSignatureVideoUrl = _l.setSignatureVideoUrl,
11591
11674
  logSelfieCaptureAttempt = _l.logSelfieCaptureAttempt;
11592
- var _m = React.useContext(CameraStateContext),
11675
+ var _m = useCameraStore(useShallow(function (state) {
11676
+ return {
11677
+ cameraAccessDenied: state.cameraAccessDenied,
11678
+ requestCameraAccess: state.requestCameraAccess,
11679
+ releaseCameraAccess: state.releaseCameraAccess
11680
+ };
11681
+ })),
11593
11682
  cameraAccessDenied = _m.cameraAccessDenied,
11594
11683
  requestCameraAccess = _m.requestCameraAccess,
11595
11684
  releaseCameraAccess = _m.releaseCameraAccess;
@@ -11749,27 +11838,29 @@ var VideoSignatureWizard = function VideoSignatureWizard(_a) {
11749
11838
  };
11750
11839
 
11751
11840
  var IdVideoCaptureGuides = function IdVideoCaptureGuides(_a) {
11752
- var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
11753
- var _0 = _a.requestedAction,
11754
- requestedAction = _0 === void 0 ? 'SHOW_ID_FRONT' : _0,
11755
- _1 = _a.satisfied,
11756
- satisfied = _1 === void 0 ? false : _1,
11757
- _2 = _a.faceGuideStatus,
11758
- faceGuideStatus = _2 === void 0 ? 'success' : _2,
11841
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
11842
+ var _z = _a.requestedAction,
11843
+ requestedAction = _z === void 0 ? 'SHOW_ID_FRONT' : _z,
11844
+ _0 = _a.satisfied,
11845
+ satisfied = _0 === void 0 ? false : _0,
11846
+ _1 = _a.faceGuideStatus,
11847
+ faceGuideStatus = _1 === void 0 ? 'success' : _1,
11759
11848
  faceGuideBorderWidth = _a.faceGuideBorderWidth,
11760
11849
  faceGuideBorderColor = _a.faceGuideBorderColor,
11761
- _3 = _a.idCardGuideStatus,
11762
- idCardGuideStatus = _3 === void 0 ? 'ready' : _3,
11850
+ _2 = _a.idCardGuideStatus,
11851
+ idCardGuideStatus = _2 === void 0 ? 'ready' : _2,
11763
11852
  idCardGuideBorderWidth = _a.idCardGuideBorderWidth,
11764
11853
  idCardGuideBorderColor = _a.idCardGuideBorderColor,
11765
11854
  idCardCaptureProgress = _a.idCardCaptureProgress,
11766
- _4 = _a.idCardCaptureGuideImages,
11767
- userSuppliedImages = _4 === void 0 ? defaultIdCaptureGuideImages : _4,
11768
- _5 = _a.classNames,
11769
- classNames = _5 === void 0 ? {} : _5,
11770
- _6 = _a.verbiage,
11771
- rawVerbiage = _6 === void 0 ? {} : _6;
11772
- var cameraRef = React.useContext(CameraStateContext).cameraRef;
11855
+ _3 = _a.idCardCaptureGuideImages,
11856
+ userSuppliedImages = _3 === void 0 ? defaultIdCaptureGuideImages : _3,
11857
+ _4 = _a.classNames,
11858
+ classNames = _4 === void 0 ? {} : _4,
11859
+ _5 = _a.verbiage,
11860
+ rawVerbiage = _5 === void 0 ? {} : _5;
11861
+ var isRearFacing = useCameraStore(function (state) {
11862
+ return state.isRearFacing;
11863
+ });
11773
11864
  var verbiage = useTranslations(rawVerbiage, {
11774
11865
  idFrontInstructionText: 'Display the front of your ID card...',
11775
11866
  idBackInstructionText: 'Display the back of your ID card...',
@@ -11782,17 +11873,17 @@ var IdVideoCaptureGuides = function IdVideoCaptureGuides(_a) {
11782
11873
  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';
11783
11874
  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;
11784
11875
  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';
11785
- var _7 = useResizeObserver__default.default(),
11786
- idCardGuideRef = _7.ref,
11787
- _8 = _7.width,
11788
- idCardGuideWidth = _8 === void 0 ? 0 : _8,
11789
- _9 = _7.height,
11790
- idCardGuideHeight = _9 === void 0 ? 0 : _9;
11876
+ var _6 = useResizeObserver__default.default(),
11877
+ idCardGuideRef = _6.ref,
11878
+ _7 = _6.width,
11879
+ idCardGuideWidth = _7 === void 0 ? 0 : _7,
11880
+ _8 = _6.height,
11881
+ idCardGuideHeight = _8 === void 0 ? 0 : _8;
11791
11882
  var idCaptureGuideImages = useGuideImages(userSuppliedImages);
11792
11883
  var idCaptureGuideImagesByUrl = useGuideImagesByUrl(idCaptureGuideImages);
11793
- var _10 = React.useState(undefined),
11794
- aspectRatio = _10[0],
11795
- setAspectRatio = _10[1];
11884
+ var _9 = React.useState(undefined),
11885
+ aspectRatio = _9[0],
11886
+ setAspectRatio = _9[1];
11796
11887
  var onImageLoaded = React.useCallback(function (e) {
11797
11888
  var _a, _b, _c, _d;
11798
11889
  var img = e.currentTarget;
@@ -11839,7 +11930,7 @@ var IdVideoCaptureGuides = function IdVideoCaptureGuides(_a) {
11839
11930
  }, /*#__PURE__*/React__namespace.default.createElement(IdCardGuideImage, {
11840
11931
  alt: "",
11841
11932
  className: classNames.idCardGuideImage,
11842
- "$isMirrored": !((_v = cameraRef.current) === null || _v === void 0 ? void 0 : _v.isRearFacing),
11933
+ "$isMirrored": !isRearFacing,
11843
11934
  style: idCardImageStyle,
11844
11935
  src: requestedAction === 'SHOW_ID_BACK' ? idCaptureGuideImages.landscape.SHOW_ID_BACK.url : idCaptureGuideImages.landscape.SHOW_ID_FRONT.url,
11845
11936
  onLoad: onImageLoaded
@@ -11853,8 +11944,8 @@ var IdVideoCaptureGuides = function IdVideoCaptureGuides(_a) {
11853
11944
  className: classNames.idCardGuideInstructionsContainer
11854
11945
  }, /*#__PURE__*/React__namespace.default.createElement(IdCardGuideInstructions, {
11855
11946
  className: classNames.idCardGuideInstructions,
11856
- "$textColor": (_x = (_w = theme.idVideoCapture) === null || _w === void 0 ? void 0 : _w.idCardGuides) === null || _x === void 0 ? void 0 : _x.instructionsTextColor,
11857
- "$background": (_z = (_y = theme.idVideoCapture) === null || _y === void 0 ? void 0 : _y.idCardGuides) === null || _z === void 0 ? void 0 : _z.instructionsBackgroundColor
11947
+ "$textColor": (_w = (_v = theme.idVideoCapture) === null || _v === void 0 ? void 0 : _v.idCardGuides) === null || _w === void 0 ? void 0 : _w.instructionsTextColor,
11948
+ "$background": (_y = (_x = theme.idVideoCapture) === null || _x === void 0 ? void 0 : _x.idCardGuides) === null || _y === void 0 ? void 0 : _y.instructionsBackgroundColor
11858
11949
  }, instructionText))))));
11859
11950
  };
11860
11951
  var Container = styled__default.default.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) {
@@ -11999,99 +12090,100 @@ var defaultVideoIdCaptureThresholds = {
11999
12090
  flipShortcutThreshold: 0.7
12000
12091
  };
12001
12092
  var IdVideoCapture = function IdVideoCapture(_a) {
12002
- var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
12093
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
12003
12094
  var onComplete = _a.onComplete,
12004
12095
  onIdFrontImageCaptured = _a.onIdFrontImageCaptured,
12005
12096
  onIdBackImageCaptured = _a.onIdBackImageCaptured,
12006
12097
  onFaceNotDetected = _a.onFaceNotDetected,
12007
12098
  onRecordingFailed = _a.onRecordingFailed,
12008
12099
  onExitCapture = _a.onExitCapture,
12009
- _x = _a.idCaptureModelsEnabled,
12010
- idCaptureModelsEnabled = _x === void 0 ? true : _x,
12011
- _y = _a.idCardCaptureGuideImages,
12012
- idCardCaptureGuideImages = _y === void 0 ? defaultIdCaptureGuideImages : _y,
12013
- _z = _a.idCardFrontDelay,
12014
- idCardFrontDelay = _z === void 0 ? 1000 : _z,
12015
- _0 = _a.videoIdCaptureThresholds,
12016
- videoIdCaptureThresholds = _0 === void 0 ? defaultVideoIdCaptureThresholds : _0,
12017
- _1 = _a.skipShowIdCardBack,
12018
- skipShowIdCardBack = _1 === void 0 ? false : _1,
12019
- _2 = _a.captureCountdownSeconds,
12020
- captureCountdownSeconds = _2 === void 0 ? 3 : _2,
12100
+ _w = _a.idCaptureModelsEnabled,
12101
+ idCaptureModelsEnabled = _w === void 0 ? true : _w,
12102
+ _x = _a.idCardCaptureGuideImages,
12103
+ idCardCaptureGuideImages = _x === void 0 ? defaultIdCaptureGuideImages : _x,
12104
+ _y = _a.idCardFrontDelay,
12105
+ idCardFrontDelay = _y === void 0 ? 1000 : _y,
12106
+ _z = _a.videoIdCaptureThresholds,
12107
+ videoIdCaptureThresholds = _z === void 0 ? defaultVideoIdCaptureThresholds : _z,
12108
+ _0 = _a.skipShowIdCardBack,
12109
+ skipShowIdCardBack = _0 === void 0 ? false : _0,
12110
+ _1 = _a.captureCountdownSeconds,
12111
+ captureCountdownSeconds = _1 === void 0 ? 3 : _1,
12021
12112
  readTextPrompt = _a.readTextPrompt,
12022
- _3 = _a.readTextTimeoutDurationMs,
12023
- readTextTimeoutDurationMs = _3 === void 0 ? 15000 : _3,
12024
- _4 = _a.readTextMinReadingMs,
12025
- readTextMinReadingMs = _4 === void 0 ? 10000 : _4,
12026
- _5 = _a.disableFaceDetectionWhileAudioCapture,
12027
- disableFaceDetectionWhileAudioCapture = _5 === void 0 ? false : _5,
12028
- _6 = _a.disableFaceDetectionWhileAudioCaptureMsDelay,
12029
- disableFaceDetectionWhileAudioCaptureMsDelay = _6 === void 0 ? 2000 : _6,
12030
- _7 = _a.mergeAVStreams,
12031
- mergeAVStreams = _7 === void 0 ? false : _7,
12032
- _8 = _a.classNames,
12033
- classNames = _8 === void 0 ? {} : _8,
12034
- _9 = _a.colors,
12035
- colors = _9 === void 0 ? {} : _9,
12036
- _10 = _a.verbiage,
12037
- rawVerbiage = _10 === void 0 ? {} : _10,
12038
- _11 = _a.debugMode,
12039
- debugMode = _11 === void 0 ? false : _11;
12040
- var _12 = useResizeObserver__default.default(),
12041
- ref = _12.ref,
12042
- _13 = _12.width,
12043
- width = _13 === void 0 ? 1 : _13,
12044
- _14 = _12.height,
12045
- height = _14 === void 0 ? 1 : _14;
12046
- var _15 = React.useContext(CameraStateContext),
12047
- cameraRef = _15.cameraRef,
12048
- videoRef = _15.videoRef,
12049
- videoLoaded = _15.videoLoaded,
12050
- cameraReady = _15.cameraReady,
12051
- microphoneReady = _15.microphoneReady,
12052
- audioStream = _15.audioStream,
12053
- setVideoLoaded = _15.setVideoLoaded;
12054
- var _16 = React.useState([]),
12055
- detectedObjects = _16[0],
12056
- setDetectedObjects = _16[1];
12057
- var _17 = React.useState(null),
12058
- face = _17[0],
12059
- setFace = _17[1];
12060
- var _18 = React.useContext(IdCaptureModelsContext),
12061
- idModelsReady = _18.ready,
12062
- startIdModels = _18.start,
12063
- stopIdModels = _18.stop,
12064
- onIdPredictionMade = _18.onPredictionMade,
12065
- setThresholds = _18.setThresholds,
12066
- setDocumentDetectionBoundaries = _18.setDocumentDetectionBoundaries,
12067
- bestFrameDetails = _18.bestFrameDetails,
12068
- resetBestFrame = _18.resetBestFrame,
12069
- idModelError = _18.modelError;
12070
- var _19 = React.useState(null),
12071
- videoStartsAt = _19[0],
12072
- setVideoStartsAt = _19[1];
12073
- var _20 = React.useContext(SubmissionContext),
12074
- setIdCaptureVideoAudioStartsAt = _20.setIdCaptureVideoAudioStartsAt,
12075
- setExpectedAudioText = _20.setExpectedAudioText;
12076
- var _21 = React.useContext(SelfieGuidanceModelsContext),
12077
- startSelfieGuidance = _21.start,
12078
- stopSelfieGuidance = _21.stop,
12079
- onSelfiePredictionMade = _21.onPredictionMade,
12080
- selfieModelError = _21.error;
12081
- var _22 = useVideoRecorder(cameraRef.current, audioStream, mergeAVStreams),
12082
- isRecordingVideo = _22.isRecordingVideo,
12083
- startRecordingVideo = _22.startRecordingVideo,
12084
- startRecordingAudio = _22.startRecordingAudio,
12085
- stopRecordingVideo = _22.stopRecordingVideo,
12086
- stopRecordingAudio = _22.stopRecordingAudio,
12087
- videoRecordingUnintentionallyStopped = _22.videoRecordingUnintentionallyStopped,
12088
- audioRecordingUnintentionallyStopped = _22.audioRecordingUnintentionallyStopped,
12089
- videoUrl = _22.videoUrl,
12090
- audioUrl = _22.audioUrl;
12113
+ _2 = _a.readTextTimeoutDurationMs,
12114
+ readTextTimeoutDurationMs = _2 === void 0 ? 15000 : _2,
12115
+ _3 = _a.readTextMinReadingMs,
12116
+ readTextMinReadingMs = _3 === void 0 ? 10000 : _3,
12117
+ _4 = _a.disableFaceDetectionWhileAudioCapture,
12118
+ disableFaceDetectionWhileAudioCapture = _4 === void 0 ? false : _4,
12119
+ _5 = _a.disableFaceDetectionWhileAudioCaptureMsDelay,
12120
+ disableFaceDetectionWhileAudioCaptureMsDelay = _5 === void 0 ? 2000 : _5,
12121
+ _6 = _a.mergeAVStreams,
12122
+ mergeAVStreams = _6 === void 0 ? false : _6,
12123
+ _7 = _a.classNames,
12124
+ classNames = _7 === void 0 ? {} : _7,
12125
+ _8 = _a.colors,
12126
+ colors = _8 === void 0 ? {} : _8,
12127
+ _9 = _a.verbiage,
12128
+ rawVerbiage = _9 === void 0 ? {} : _9,
12129
+ _10 = _a.debugMode,
12130
+ debugMode = _10 === void 0 ? false : _10;
12131
+ var _11 = useResizeObserver__default.default(),
12132
+ ref = _11.ref,
12133
+ _12 = _11.width,
12134
+ width = _12 === void 0 ? 1 : _12,
12135
+ _13 = _11.height,
12136
+ height = _13 === void 0 ? 1 : _13;
12137
+ var _14 = useCameraStore(),
12138
+ camera = _14.camera,
12139
+ videoRef = _14.videoRef,
12140
+ videoLoaded = _14.videoLoaded,
12141
+ cameraReady = _14.cameraReady,
12142
+ microphoneReady = _14.microphoneReady,
12143
+ audioStream = _14.audioStream,
12144
+ isRearFacing = _14.isRearFacing,
12145
+ releaseCameraAccess = _14.releaseCameraAccess;
12146
+ var _15 = React.useState([]),
12147
+ detectedObjects = _15[0],
12148
+ setDetectedObjects = _15[1];
12149
+ var _16 = React.useState(null),
12150
+ face = _16[0],
12151
+ setFace = _16[1];
12152
+ var _17 = React.useContext(IdCaptureModelsContext),
12153
+ idModelsReady = _17.ready,
12154
+ startIdModels = _17.start,
12155
+ stopIdModels = _17.stop,
12156
+ onIdPredictionMade = _17.onPredictionMade,
12157
+ setThresholds = _17.setThresholds,
12158
+ setDocumentDetectionBoundaries = _17.setDocumentDetectionBoundaries,
12159
+ bestFrameDetails = _17.bestFrameDetails,
12160
+ resetBestFrame = _17.resetBestFrame,
12161
+ idModelError = _17.modelError;
12162
+ var _18 = React.useState(null),
12163
+ videoStartsAt = _18[0],
12164
+ setVideoStartsAt = _18[1];
12165
+ var _19 = React.useContext(SubmissionContext),
12166
+ setIdCaptureVideoAudioStartsAt = _19.setIdCaptureVideoAudioStartsAt,
12167
+ setExpectedAudioText = _19.setExpectedAudioText;
12168
+ var _20 = React.useContext(SelfieGuidanceModelsContext),
12169
+ startSelfieGuidance = _20.start,
12170
+ stopSelfieGuidance = _20.stop,
12171
+ onSelfiePredictionMade = _20.onPredictionMade,
12172
+ selfieModelError = _20.error;
12173
+ var _21 = useVideoRecorder(camera, audioStream, mergeAVStreams),
12174
+ isRecordingVideo = _21.isRecordingVideo,
12175
+ startRecordingVideo = _21.startRecordingVideo,
12176
+ startRecordingAudio = _21.startRecordingAudio,
12177
+ stopRecordingVideo = _21.stopRecordingVideo,
12178
+ stopRecordingAudio = _21.stopRecordingAudio,
12179
+ videoRecordingUnintentionallyStopped = _21.videoRecordingUnintentionallyStopped,
12180
+ audioRecordingUnintentionallyStopped = _21.audioRecordingUnintentionallyStopped,
12181
+ videoUrl = _21.videoUrl,
12182
+ audioUrl = _21.audioUrl;
12091
12183
  var countdownTimeoutRef = React.useRef(undefined);
12092
- var _23 = React.useState(-1),
12093
- countdownRemaining = _23[0],
12094
- setCountdownRemaining = _23[1];
12184
+ var _22 = React.useState(-1),
12185
+ countdownRemaining = _22[0],
12186
+ setCountdownRemaining = _22[1];
12095
12187
  React.useEffect(function () {
12096
12188
  if (!isRecordingVideo && !videoUrl) {
12097
12189
  startRecordingVideo();
@@ -12102,24 +12194,24 @@ var IdVideoCapture = function IdVideoCapture(_a) {
12102
12194
  var needsAudio = !!readTextPrompt && !mergeAVStreams;
12103
12195
  var audioReady = !needsAudio || audioUrl;
12104
12196
  if (videoUrl && audioReady) {
12105
- setVideoLoaded(false);
12197
+ releaseCameraAccess();
12106
12198
  onComplete === null || onComplete === void 0 ? void 0 : onComplete(videoUrl, audioUrl);
12107
12199
  }
12108
- }, [audioUrl, isRecordingVideo, mergeAVStreams, onComplete, readTextPrompt, setVideoLoaded, startRecordingVideo, videoUrl]);
12200
+ }, [audioUrl, isRecordingVideo, mergeAVStreams, onComplete, readTextPrompt, releaseCameraAccess, startRecordingVideo, videoUrl]);
12109
12201
  React.useEffect(function () {
12110
- if (videoRecordingUnintentionallyStopped || audioRecordingUnintentionallyStopped) {
12202
+ if (videoRecordingUnintentionallyStopped || audioRecordingUnintentionallyStopped || !!readTextPrompt && !microphoneReady) {
12111
12203
  onRecordingFailed === null || onRecordingFailed === void 0 ? void 0 : onRecordingFailed();
12112
12204
  }
12113
- }, [audioRecordingUnintentionallyStopped, onRecordingFailed, videoRecordingUnintentionallyStopped]);
12114
- var _24 = React.useState('SHOW_ID_FRONT'),
12115
- requestedAction = _24[0],
12116
- setRequestedAction = _24[1];
12205
+ }, [audioRecordingUnintentionallyStopped, microphoneReady, onRecordingFailed, readTextPrompt, videoRecordingUnintentionallyStopped]);
12206
+ var _23 = React.useState('SHOW_ID_FRONT'),
12207
+ requestedAction = _23[0],
12208
+ setRequestedAction = _23[1];
12117
12209
  var shouldRunIdModels = idCaptureModelsEnabled && videoLoaded && cameraReady && idModelsReady && !idModelError && requestedAction !== 'READ_TEXT' && (!readTextPrompt || microphoneReady);
12118
12210
  React.useEffect(function startModelsWhenCapturing() {
12119
12211
  if (!shouldRunIdModels) return;
12120
12212
  startIdModels();
12121
12213
  return function () {
12122
- stopIdModels();
12214
+ return stopIdModels();
12123
12215
  };
12124
12216
  }, [shouldRunIdModels, startIdModels, stopIdModels]);
12125
12217
  React.useEffect(function () {
@@ -12133,18 +12225,18 @@ var IdVideoCapture = function IdVideoCapture(_a) {
12133
12225
  bottom: 1
12134
12226
  });
12135
12227
  }, [setDocumentDetectionBoundaries]);
12136
- var _25 = React.useState(0),
12137
- currentDetectionScore = _25[0],
12138
- setCurrentDetectionScore = _25[1];
12139
- var _26 = React.useState('none'),
12140
- currentDetectedDocumentType = _26[0],
12141
- setCurrentDetectedDocumentType = _26[1];
12228
+ var _24 = React.useState(0),
12229
+ currentDetectionScore = _24[0],
12230
+ setCurrentDetectionScore = _24[1];
12231
+ var _25 = React.useState('none'),
12232
+ currentDetectedDocumentType = _25[0],
12233
+ setCurrentDetectedDocumentType = _25[1];
12234
+ var _26 = React.useState(0),
12235
+ currentFocusScore = _26[0],
12236
+ setCurrentFocusScore = _26[1];
12142
12237
  var _27 = React.useState(0),
12143
- currentFocusScore = _27[0],
12144
- setCurrentFocusScore = _27[1];
12145
- var _28 = React.useState(0),
12146
- goodFramesCount = _28[0],
12147
- setGoodFramesCount = _28[1];
12238
+ goodFramesCount = _27[0],
12239
+ setGoodFramesCount = _27[1];
12148
12240
  var goodFramesThreshold = requestedAction === 'SHOW_ID_FRONT' ? videoIdCaptureThresholds.goodFrames.idCardFront : videoIdCaptureThresholds.goodFrames.idCardBack;
12149
12241
  var goodFramesThresholdMet = goodFramesCount >= goodFramesThreshold;
12150
12242
  React.useEffect(function () {
@@ -12165,9 +12257,9 @@ var IdVideoCapture = function IdVideoCapture(_a) {
12165
12257
  } : 0);
12166
12258
  });
12167
12259
  }, [idCaptureModelsEnabled, onIdPredictionMade, idModelError, requestedAction, videoIdCaptureThresholds.flipShortcutThreshold]);
12168
- var _29 = React.useState(null),
12169
- idFrontCaptureStartedAt = _29[0],
12170
- setFirstGoodFrameTime = _29[1];
12260
+ var _28 = React.useState(null),
12261
+ idFrontCaptureStartedAt = _28[0],
12262
+ setFirstGoodFrameTime = _28[1];
12171
12263
  React.useEffect(function () {
12172
12264
  if (goodFramesCount === 1) setFirstGoodFrameTime(new Date().getTime());
12173
12265
  }, [goodFramesCount]);
@@ -12188,9 +12280,9 @@ var IdVideoCapture = function IdVideoCapture(_a) {
12188
12280
  var frameHeight = (_e = (_d = videoRef.current) === null || _d === void 0 ? void 0 : _d.videoHeight) !== null && _e !== void 0 ? _e : 0;
12189
12281
  var faceBox = face === null || face === void 0 ? void 0 : face.box;
12190
12282
  var faceCentered = !faceBox || !frameWidth || faceBox.xMin > frameWidth * edgeBoundary && faceBox.yMin > frameHeight * edgeBoundary && faceBox.xMax < frameWidth * (1 - edgeBoundary) && faceBox.yMax < frameHeight * (1 - edgeBoundary);
12191
- var _30 = React.useState(),
12192
- countdownStartedAt = _30[0],
12193
- setCountdownStartedAt = _30[1];
12283
+ var _29 = React.useState(),
12284
+ countdownStartedAt = _29[0],
12285
+ setCountdownStartedAt = _29[1];
12194
12286
  var photoCanvas = React.useRef(null);
12195
12287
  var frameLock = React.useRef(false);
12196
12288
  var captureFrame = React.useCallback(function () {
@@ -12313,9 +12405,9 @@ var IdVideoCapture = function IdVideoCapture(_a) {
12313
12405
  stopSelfieGuidance();
12314
12406
  };
12315
12407
  }, [startSelfieGuidance, stopSelfieGuidance]);
12316
- var _31 = React.useState(0),
12317
- numFramesWithoutFaces = _31[0],
12318
- setNumFramesWithoutFaces = _31[1];
12408
+ var _30 = React.useState(0),
12409
+ numFramesWithoutFaces = _30[0],
12410
+ setNumFramesWithoutFaces = _30[1];
12319
12411
  onSelfiePredictionMade(useDebounce.useThrottledCallback(React.useCallback(function (_a) {
12320
12412
  var face = _a.face;
12321
12413
  if (selfieModelError) return;
@@ -12331,12 +12423,12 @@ var IdVideoCapture = function IdVideoCapture(_a) {
12331
12423
  }
12332
12424
  }, [disableFaceDetectionWhileAudioCapture, disableFaceDetectionWhileAudioCaptureMsDelay, numFramesWithoutFaces, onFaceNotDetected, timeoutStartedAt]);
12333
12425
  var theme = styled.useTheme();
12334
- var _32 = useTranslations(rawVerbiage, {
12426
+ var _31 = useTranslations(rawVerbiage, {
12335
12427
  faceNotCenteredText: 'Please move your face to the center...',
12336
12428
  captureBtnText: 'Capture'
12337
12429
  }),
12338
- captureBtnText = _32.captureBtnText,
12339
- faceNotCenteredText = _32.faceNotCenteredText;
12430
+ captureBtnText = _31.captureBtnText,
12431
+ faceNotCenteredText = _31.faceNotCenteredText;
12340
12432
  var debugScalingDetails = useDebugScalingDetails({
12341
12433
  enabled: debugMode,
12342
12434
  pageWidth: width,
@@ -12345,8 +12437,6 @@ var IdVideoCapture = function IdVideoCapture(_a) {
12345
12437
  videoHeight: (_j = (_h = videoRef.current) === null || _h === void 0 ? void 0 : _h.videoHeight) !== null && _j !== void 0 ? _j : 0
12346
12438
  });
12347
12439
  var capturingId = ['SHOW_ID_FRONT', 'SHOW_ID_BACK'].includes(requestedAction);
12348
- // const searchingForIdCard =
12349
- // idCaptureModelsEnabled && capturingId && !goodFramesThresholdMet
12350
12440
  var guidanceText = !faceCentered ? faceNotCenteredText : undefined;
12351
12441
  return /*#__PURE__*/React__namespace.default.createElement(PageContainer, {
12352
12442
  ref: ref,
@@ -12372,15 +12462,14 @@ var IdVideoCapture = function IdVideoCapture(_a) {
12372
12462
  faceGuideBorderColor: satisfied ? colors.guidesSatisfiedColor : colors.guidesUnsatisfiedColor,
12373
12463
  idCardGuideBorderColor: satisfied ? colors.guidesSatisfiedColor : colors.guidesUnsatisfiedColor
12374
12464
  }), debugMode && capturingId && ( /*#__PURE__*/React__namespace.default.createElement(React__namespace.default.Fragment, null, /*#__PURE__*/React__namespace.default.createElement(ObjectDetectionDebugOverlayDiv, {
12375
- "$flipX": !((_l = cameraRef.current) === null || _l === void 0 ? void 0 : _l.isRearFacing)
12465
+ "$flipX": !isRearFacing
12376
12466
  }, detectedObjects.map(function (obj, i) {
12377
- var _a;
12378
12467
  return /*#__PURE__*/React__namespace.default.createElement(IdCaptureDetectedObjectDebugBox, {
12379
12468
  key: i,
12380
12469
  obj: obj,
12381
12470
  scaling: debugScalingDetails,
12382
12471
  color: "blue",
12383
- flipX: !((_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.isRearFacing)
12472
+ flipX: !isRearFacing
12384
12473
  });
12385
12474
  })), /*#__PURE__*/React__namespace.default.createElement(DebugBoundingBoxOverlay, null, face && ( /*#__PURE__*/React__namespace.default.createElement(SelfieCaptureFaceDebugBox, {
12386
12475
  face: face,
@@ -12389,9 +12478,9 @@ var IdVideoCapture = function IdVideoCapture(_a) {
12389
12478
  className: classNames.guidanceMessageContainer
12390
12479
  }, /*#__PURE__*/React__namespace.default.createElement(GuidanceMessage, {
12391
12480
  className: classNames.guidanceMessage,
12392
- "$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',
12393
- "$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'
12394
- }, guidanceText))), debugMode && ( /*#__PURE__*/React__namespace.default.createElement(DebugStatsPane, null, cameraRef.current ? ( /*#__PURE__*/React__namespace.default.createElement(React__namespace.default.Fragment, null, "\u2705 Camera: ", cameraRef.current.label, " (", cameraRef.current.width, "x", cameraRef.current.height, ")")) : '❌ Camera not ready', /*#__PURE__*/React__namespace.default.createElement("br", null), isRecordingVideo ? '✅ Recording' : '❌ Not recording', /*#__PURE__*/React__namespace.default.createElement("br", null), goodFramesThresholdMet ? '✅' : '❌', " Good Frame Count:", ' ', goodFramesCount, "/", goodFramesThreshold, /*#__PURE__*/React__namespace.default.createElement("br", null), "Document Type: ", currentDetectedDocumentType, /*#__PURE__*/React__namespace.default.createElement("br", null), "Detection Score: ", currentDetectionScore, /*#__PURE__*/React__namespace.default.createElement("br", null), "Focus Score: ", currentFocusScore, /*#__PURE__*/React__namespace.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__namespace.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__namespace.default.createElement(CountdownContainer, {
12481
+ "$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',
12482
+ "$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'
12483
+ }, guidanceText))), debugMode && ( /*#__PURE__*/React__namespace.default.createElement(DebugStatsPane, null, camera ? ( /*#__PURE__*/React__namespace.default.createElement(React__namespace.default.Fragment, null, "\u2705 Camera: ", camera.label, " (", camera.width, "x", camera.height, ")")) : '❌ Camera not ready', /*#__PURE__*/React__namespace.default.createElement("br", null), isRecordingVideo ? '✅ Recording' : '❌ Not recording', /*#__PURE__*/React__namespace.default.createElement("br", null), goodFramesThresholdMet ? '✅' : '❌', " Good Frame Count:", ' ', goodFramesCount, "/", goodFramesThreshold, /*#__PURE__*/React__namespace.default.createElement("br", null), "Document Type: ", currentDetectedDocumentType, /*#__PURE__*/React__namespace.default.createElement("br", null), "Detection Score: ", currentDetectionScore, /*#__PURE__*/React__namespace.default.createElement("br", null), "Focus Score: ", currentFocusScore, /*#__PURE__*/React__namespace.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__namespace.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__namespace.default.createElement(CountdownContainer, {
12395
12484
  className: classNames.countdownContainer
12396
12485
  }, /*#__PURE__*/React__namespace.default.createElement(Countdown, {
12397
12486
  className: classNames.countdown
@@ -12400,7 +12489,7 @@ var IdVideoCapture = function IdVideoCapture(_a) {
12400
12489
  }, /*#__PURE__*/React__namespace.default.createElement(CaptureButton, {
12401
12490
  finished: true,
12402
12491
  onClick: function onClick() {
12403
- setCountdownStartedAt(new Date());
12492
+ return setCountdownStartedAt(new Date());
12404
12493
  },
12405
12494
  disabled: !!countdownStartedAt || frameLock.current,
12406
12495
  className: classNames.captureBtn
@@ -12688,16 +12777,14 @@ var VideoIdWizard = function VideoIdWizard(_a) {
12688
12777
  className: "flex"
12689
12778
  }, /*#__PURE__*/React__namespace.default.createElement(Spinner, null));
12690
12779
  }
12691
- return /*#__PURE__*/React__namespace.default.createElement(CameraProvider, {
12692
- key: "".concat(isCapturingId ? 'id' : 'selfie', "-camera-").concat(attempt),
12693
- preferContinuityCamera: isCapturingId,
12780
+ return /*#__PURE__*/React__namespace.default.createElement(CameraStoreProvider, {
12781
+ preferIphoneContinuityCamera: isCapturingId,
12694
12782
  preferFrontFacingCamera: !isCapturingId,
12695
12783
  requireMicrophoneAccess: !isCapturingId && !!readTextPrompt,
12696
12784
  maxVideoWidth: isCapturingId ? 1920 : 1280,
12697
12785
  maxFps: isCapturingId ? 60 : 30,
12698
12786
  onCameraAccessDenied: onCameraAccessDenied,
12699
- onMicrophoneAccessDenied: onMicrophoneAccessDenied,
12700
- debugMode: debugMode
12787
+ onMicrophoneAccessDenied: onMicrophoneAccessDenied
12701
12788
  }, /*#__PURE__*/React__namespace.default.createElement(IdCaptureModelsProvider, {
12702
12789
  autoStart: false,
12703
12790
  documentDetectionModelUrl: (_g = (_f = idCaptureProps.assets) === null || _f === void 0 ? void 0 : _f.documentDetectionModelUrl) !== null && _g !== void 0 ? _g : '',
@@ -12708,7 +12795,7 @@ var VideoIdWizard = function VideoIdWizard(_a) {
12708
12795
  autoStart: false,
12709
12796
  onModelError: faceLivenessProps === null || faceLivenessProps === void 0 ? void 0 : faceLivenessProps.onModelError,
12710
12797
  modelLoadTimeoutMs: faceLivenessProps === null || faceLivenessProps === void 0 ? void 0 : faceLivenessProps.modelLoadTimeoutMs,
12711
- requireVerticalFaceCentering: captureState === 'CHECKING_LIVENESS'
12798
+ requireVerticalFaceCentering: false
12712
12799
  }, /*#__PURE__*/React__namespace.default.createElement(PageContainer, {
12713
12800
  className: "flex ".concat((_k = classNames.container) !== null && _k !== void 0 ? _k : '')
12714
12801
  }, ['CHECKING_LIVENESS', 'CAPTURING_VIDEO'].includes(captureState) && /*#__PURE__*/React__namespace.default.createElement(CameraVideoTag, {
@@ -12823,17 +12910,15 @@ function CompositeWizard(_a) {
12823
12910
  _o = _a.captureSignatureVideo,
12824
12911
  captureSignatureVideo = _o === void 0 ? false : _o,
12825
12912
  onCameraAccessDenied = _a.onCameraAccessDenied,
12826
- onMicrophoneAccessDenied = _a.onMicrophoneAccessDenied,
12827
- _p = _a.debugMode,
12828
- debugMode = _p === void 0 ? false : _p;
12829
- var _q = React.useContext(SubmissionContext),
12830
- submit = _q.submit,
12831
- submissionStatus = _q.submissionStatus,
12832
- setSignatureData = _q.setSignatureData,
12833
- setAdditionalDocuments = _q.setAdditionalDocuments;
12834
- var _r = React.useState(0),
12835
- checkIndex = _r[0],
12836
- setCheckIndex = _r[1];
12913
+ onMicrophoneAccessDenied = _a.onMicrophoneAccessDenied;
12914
+ var _p = React.useContext(SubmissionContext),
12915
+ submit = _p.submit,
12916
+ submissionStatus = _p.submissionStatus,
12917
+ setSignatureData = _p.setSignatureData,
12918
+ setAdditionalDocuments = _p.setAdditionalDocuments;
12919
+ var _q = React.useState(0),
12920
+ checkIndex = _q[0],
12921
+ setCheckIndex = _q[1];
12837
12922
  var checks = React.useMemo(function () {
12838
12923
  var _a, _b;
12839
12924
  var checks = __spreadArray([], userChecks, true);
@@ -12911,16 +12996,6 @@ function CompositeWizard(_a) {
12911
12996
  return i + 1;
12912
12997
  });
12913
12998
  }, [onVideoSignatureCompleteProp]);
12914
- var _s = React.useState(0),
12915
- videoSignatureAttempts = _s[0],
12916
- setVideoSignatureAttempts = _s[1];
12917
- var onVideoSignatureRetryProp = videoSignatureCaptureProps.onRetryClicked;
12918
- var onVideoSignatureRetry = React.useCallback(function () {
12919
- onVideoSignatureRetryProp === null || onVideoSignatureRetryProp === void 0 ? void 0 : onVideoSignatureRetryProp();
12920
- setVideoSignatureAttempts(function (n) {
12921
- return n + 1;
12922
- });
12923
- }, [onVideoSignatureRetryProp]);
12924
12999
  var onAdditionalDocumentCaptureCompleteProp = additionalDocumentCaptureProps === null || additionalDocumentCaptureProps === void 0 ? void 0 : additionalDocumentCaptureProps.onComplete;
12925
13000
  var onAdditionalDocumentCaptureComplete = React.useCallback(function (uploadedDocuments) {
12926
13001
  setAdditionalDocuments(uploadedDocuments);
@@ -12949,11 +13024,9 @@ function CompositeWizard(_a) {
12949
13024
  }
12950
13025
  switch (checks[checkIndex]) {
12951
13026
  case 'IdCapture':
12952
- return /*#__PURE__*/React__namespace.default.createElement(CameraProvider, {
12953
- key: "IdCaptureCamera",
13027
+ return /*#__PURE__*/React__namespace.default.createElement(CameraStoreProvider, {
12954
13028
  onCameraAccessDenied: onCameraAccessDenied,
12955
- onMicrophoneAccessDenied: onMicrophoneAccessDenied,
12956
- debugMode: debugMode
13029
+ onMicrophoneAccessDenied: onMicrophoneAccessDenied
12957
13030
  }, /*#__PURE__*/React__namespace.default.createElement(IdCaptureModelsProvider, {
12958
13031
  autoStart: false,
12959
13032
  documentDetectionModelUrl: (_d = (_c = idCaptureProps.assets) === null || _c === void 0 ? void 0 : _c.documentDetectionModelUrl) !== null && _d !== void 0 ? _d : '',
@@ -12970,13 +13043,11 @@ function CompositeWizard(_a) {
12970
13043
  onMicrophoneAccessDenied: onMicrophoneAccessDenied
12971
13044
  }));
12972
13045
  case 'FaceLiveness':
12973
- return /*#__PURE__*/React__namespace.default.createElement(CameraProvider, {
12974
- key: "FaceLivenessCamera",
13046
+ return /*#__PURE__*/React__namespace.default.createElement(CameraStoreProvider, {
12975
13047
  preferFrontFacingCamera: true,
12976
- preferContinuityCamera: false,
13048
+ preferIphoneContinuityCamera: false,
12977
13049
  onCameraAccessDenied: onCameraAccessDenied,
12978
- onMicrophoneAccessDenied: onMicrophoneAccessDenied,
12979
- debugMode: debugMode
13050
+ onMicrophoneAccessDenied: onMicrophoneAccessDenied
12980
13051
  }, /*#__PURE__*/React__namespace.default.createElement(SelfieGuidanceModelsProvider, {
12981
13052
  autoStart: false,
12982
13053
  onModelError: faceLivenessProps.onModelError,
@@ -12989,15 +13060,13 @@ function CompositeWizard(_a) {
12989
13060
  onAccept: onSignatureCaptureSuccess
12990
13061
  }));
12991
13062
  case 'VideoSignatureCapture':
12992
- return /*#__PURE__*/React__namespace.default.createElement(CameraProvider, {
12993
- key: "SignatureKycCamera-".concat(videoSignatureAttempts),
12994
- preferContinuityCamera: false,
13063
+ return /*#__PURE__*/React__namespace.default.createElement(CameraStoreProvider, {
13064
+ preferIphoneContinuityCamera: false,
12995
13065
  preferFrontFacingCamera: true,
12996
13066
  maxVideoWidth: 1280,
12997
13067
  maxFps: 30,
12998
13068
  onCameraAccessDenied: onCameraAccessDenied,
12999
- onMicrophoneAccessDenied: onMicrophoneAccessDenied,
13000
- debugMode: debugMode
13069
+ onMicrophoneAccessDenied: onMicrophoneAccessDenied
13001
13070
  }, /*#__PURE__*/React__namespace.default.createElement(SelfieGuidanceModelsProvider, {
13002
13071
  autoStart: false,
13003
13072
  throttleMs: 250,
@@ -13005,8 +13074,7 @@ function CompositeWizard(_a) {
13005
13074
  modelLoadTimeoutMs: videoSignatureCaptureProps.modelLoadTimeoutMs,
13006
13075
  requireVerticalFaceCentering: false
13007
13076
  }, /*#__PURE__*/React__namespace.default.createElement(VideoSignatureWizard, _assign({}, videoSignatureCaptureProps, {
13008
- onComplete: onVideoSignatureComplete,
13009
- onRetryClicked: onVideoSignatureRetry
13077
+ onComplete: onVideoSignatureComplete
13010
13078
  }))));
13011
13079
  case 'AdditionalDocumentCapture':
13012
13080
  return /*#__PURE__*/React__namespace.default.createElement(AdditionalDocumentCaptureWizard, _assign({}, additionalDocumentCaptureProps, {
@@ -13457,8 +13525,7 @@ var IdValidation = function IdValidation(_a) {
13457
13525
  videoSignatureCaptureProps: videoSignatureCaptureProps,
13458
13526
  captureSignature: captureSignature,
13459
13527
  captureSignatureVideo: captureSignatureVideo,
13460
- onCameraAccessDenied: onCameraAccessDenied,
13461
- debugMode: debugMode
13528
+ onCameraAccessDenied: onCameraAccessDenied
13462
13529
  }))));
13463
13530
  };
13464
13531
 
@@ -13564,8 +13631,7 @@ var FaceValidation = function FaceValidation(_a) {
13564
13631
  return ['FaceLiveness'];
13565
13632
  }, []),
13566
13633
  faceLivenessProps: faceLivenessProps,
13567
- onCameraAccessDenied: onCameraAccessDenied,
13568
- debugMode: debugMode
13634
+ onCameraAccessDenied: onCameraAccessDenied
13569
13635
  }))));
13570
13636
  };
13571
13637
 
@@ -13798,8 +13864,7 @@ var IdAndFaceValidation = function IdAndFaceValidation(_a) {
13798
13864
  additionalDocumentCaptureProps: additionalDocumentCaptureProps,
13799
13865
  captureSignature: captureSignature,
13800
13866
  captureSignatureVideo: captureSignatureVideo,
13801
- onCameraAccessDenied: onCameraAccessDenied,
13802
- debugMode: debugMode
13867
+ onCameraAccessDenied: onCameraAccessDenied
13803
13868
  }))));
13804
13869
  };
13805
13870
 
@@ -14054,8 +14119,7 @@ var CustomerIdAndBiometricsEnrollment = function CustomerIdAndBiometricsEnrollme
14054
14119
  videoSignatureCaptureProps: videoSignatureCaptureProps,
14055
14120
  captureSignature: captureSignature,
14056
14121
  captureSignatureVideo: captureSignatureVideo,
14057
- onCameraAccessDenied: onCameraAccessDenied,
14058
- debugMode: debugMode
14122
+ onCameraAccessDenied: onCameraAccessDenied
14059
14123
  }))));
14060
14124
  };
14061
14125
 
@@ -14387,7 +14451,7 @@ var CustomerVerificationWizard = function CustomerVerificationWizard(_a) {
14387
14451
  var _l = React.useState('LOADING'),
14388
14452
  captureState = _l[0],
14389
14453
  setCaptureState = _l[1];
14390
- var _m = React.useContext(CameraStateContext),
14454
+ var _m = useCameraStore(),
14391
14455
  cameraAccessDenied = _m.cameraAccessDenied,
14392
14456
  releaseCameraAccess = _m.releaseCameraAccess;
14393
14457
  var _o = React.useContext(SelfieGuidanceModelsContext),
@@ -14593,10 +14657,9 @@ var CustomerVerification = function CustomerVerification(_a) {
14593
14657
  onSubmit: onSubmit,
14594
14658
  geolocationEnabled: geolocationEnabled,
14595
14659
  geolocationRequired: geolocationRequired
14596
- }, /*#__PURE__*/React__namespace.default.createElement(CameraProvider, {
14660
+ }, /*#__PURE__*/React__namespace.default.createElement(CameraStoreProvider, {
14597
14661
  preferFrontFacingCamera: true,
14598
- onCameraAccessDenied: onCameraAccessDenied,
14599
- debugMode: debugMode
14662
+ onCameraAccessDenied: onCameraAccessDenied
14600
14663
  }, /*#__PURE__*/React__namespace.default.createElement(SelfieGuidanceModelsProvider, {
14601
14664
  autoStart: false,
14602
14665
  onModelError: onModelError,
@@ -14945,7 +15008,7 @@ var CustomerIdentificationWizard = function CustomerIdentificationWizard(_a) {
14945
15008
  var _l = React.useState('LOADING'),
14946
15009
  captureState = _l[0],
14947
15010
  setCaptureState = _l[1];
14948
- var _m = React.useContext(CameraStateContext),
15011
+ var _m = useCameraStore(),
14949
15012
  cameraAccessDenied = _m.cameraAccessDenied,
14950
15013
  releaseCameraAccess = _m.releaseCameraAccess;
14951
15014
  var _o = React.useContext(SelfieGuidanceModelsContext),
@@ -15149,10 +15212,9 @@ var CustomerIdentification = function CustomerIdentification(_a) {
15149
15212
  onSubmit: onSubmit,
15150
15213
  geolocationEnabled: geolocationEnabled,
15151
15214
  geolocationRequired: geolocationRequired
15152
- }, /*#__PURE__*/React__namespace.default.createElement(CameraProvider, {
15215
+ }, /*#__PURE__*/React__namespace.default.createElement(CameraStoreProvider, {
15153
15216
  preferFrontFacingCamera: true,
15154
- onCameraAccessDenied: onCameraAccessDenied,
15155
- debugMode: debugMode
15217
+ onCameraAccessDenied: onCameraAccessDenied
15156
15218
  }, /*#__PURE__*/React__namespace.default.createElement(SelfieGuidanceModelsProvider, {
15157
15219
  autoStart: false,
15158
15220
  modelLoadTimeoutMs: modelLoadTimeoutMs,
@@ -15479,8 +15541,7 @@ var VideoIdValidation = function VideoIdValidation(_a) {
15479
15541
  captureSignature: captureSignature,
15480
15542
  captureSignatureVideo: captureSignatureVideo,
15481
15543
  onCameraAccessDenied: onCameraAccessDenied,
15482
- onMicrophoneAccessDenied: onMicrophoneAccessDenied,
15483
- debugMode: debugMode
15544
+ onMicrophoneAccessDenied: onMicrophoneAccessDenied
15484
15545
  }))));
15485
15546
  };
15486
15547
 
@@ -15637,8 +15698,7 @@ var CustomerBiometricsEnrollment = function CustomerBiometricsEnrollment(_a) {
15637
15698
  videoSignatureCaptureProps: videoSignatureCaptureProps,
15638
15699
  captureSignature: captureSignature,
15639
15700
  captureSignatureVideo: captureSignatureVideo,
15640
- onCameraAccessDenied: onCameraAccessDenied,
15641
- debugMode: debugMode
15701
+ onCameraAccessDenied: onCameraAccessDenied
15642
15702
  }))));
15643
15703
  };
15644
15704
 
@@ -15696,11 +15756,10 @@ var DocumentCapture = function DocumentCapture(_a) {
15696
15756
  onDocumentUploadFailed: onDocumentUploadFailed,
15697
15757
  geolocationEnabled: geolocationEnabled,
15698
15758
  geolocationRequired: geolocationRequired
15699
- }, /*#__PURE__*/React__namespace.default.createElement(CameraProvider, {
15759
+ }, /*#__PURE__*/React__namespace.default.createElement(CameraStoreProvider, {
15700
15760
  requestAccessAutomatically: false,
15701
- preferContinuityCamera: true,
15702
- onCameraAccessDenied: onCameraAccessDenied,
15703
- debugMode: debugMode
15761
+ preferIphoneContinuityCamera: true,
15762
+ onCameraAccessDenied: onCameraAccessDenied
15704
15763
  }, /*#__PURE__*/React__namespace.default.createElement(DocumentCaptureWizard, {
15705
15764
  onSuccess: onComplete,
15706
15765
  onExitCapture: onExitCapture,