idmission-web-sdk 2.2.47 → 2.2.49

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