idmission-web-sdk 0.0.19 → 0.0.21

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.
@@ -191,7 +191,7 @@ function contentDispositionFromDataUrl(url) {
191
191
  return (_b = (_a = url.match(/^(data:.*;base64),/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : '';
192
192
  }
193
193
 
194
- var PageContainerDiv = styled__default['default'].div(templateObject_1$4 || (templateObject_1$4 = tslib.__makeTemplateObject(["\n position: fixed;\n top: 0;\n left: 0;\n width: var(--app-width);\n height: calc(\n var(--app-height) - ", "px\n );\n overflow-x: hidden;\n overflow-y: auto;\n font-family: Inter, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto,\n Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;\n\n &.flex {\n display: flex;\n }\n\n &.padded {\n box-sizing: border-box;\n padding: 16px 24px;\n }\n"], ["\n position: fixed;\n top: 0;\n left: 0;\n width: var(--app-width);\n height: calc(\n var(--app-height) - ", "px\n );\n overflow-x: hidden;\n overflow-y: auto;\n font-family: Inter, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto,\n Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;\n\n &.flex {\n display: flex;\n }\n\n &.padded {\n box-sizing: border-box;\n padding: 16px 24px;\n }\n"])), function (_a) {
194
+ var PageContainerDiv = styled__default['default'].div(templateObject_1$7 || (templateObject_1$7 = tslib.__makeTemplateObject(["\n position: fixed;\n top: 0;\n left: 0;\n width: var(--app-width);\n height: calc(\n var(--app-height) - ", "px\n );\n overflow-x: hidden;\n overflow-y: auto;\n font-family: Inter, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto,\n Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;\n\n &.flex {\n display: flex;\n }\n\n &.padded {\n box-sizing: border-box;\n padding: 16px 24px;\n }\n"], ["\n position: fixed;\n top: 0;\n left: 0;\n width: var(--app-width);\n height: calc(\n var(--app-height) - ", "px\n );\n overflow-x: hidden;\n overflow-y: auto;\n font-family: Inter, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto,\n Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;\n\n &.flex {\n display: flex;\n }\n\n &.padded {\n box-sizing: border-box;\n padding: 16px 24px;\n }\n"])), function (_a) {
195
195
  var $heightOffset = _a.$heightOffset;
196
196
  return $heightOffset !== null && $heightOffset !== void 0 ? $heightOffset : 0;
197
197
  });
@@ -223,13 +223,13 @@ var PageContainer = /*#__PURE__*/React.forwardRef(function (_a, ref) {
223
223
  }, children);
224
224
  });
225
225
  PageContainer.displayName = 'PageContainer';
226
- var templateObject_1$4;
226
+ var templateObject_1$7;
227
227
 
228
- var OverlayContainer = styled__default['default'](PageContainer)(templateObject_1$3 || (templateObject_1$3 = tslib.__makeTemplateObject(["\n background: white;\n z-index: 10000;\n"], ["\n background: white;\n z-index: 10000;\n"])));
229
- var OverlayInner = styled__default['default'].div(templateObject_2 || (templateObject_2 = tslib.__makeTemplateObject(["\n text-align: center;\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n padding: 25px;\n max-height: var(--app-height);\n height: 100%;\n box-sizing: border-box;\n"], ["\n text-align: center;\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n padding: 25px;\n max-height: var(--app-height);\n height: 100%;\n box-sizing: border-box;\n"])));
230
- var OverlayImageWrapper = styled__default['default'].div(templateObject_3 || (templateObject_3 = tslib.__makeTemplateObject(["\n position: relative;\n display: flex;\n flex-grow: 1;\n padding-bottom: 25px;\n max-width: var(--app-width);\n max-height: var(--app-height);\n overflow: hidden;\n\n & > img {\n margin: 0 auto;\n width: max-content;\n max-width: 100%;\n max-height: 100%;\n aspect-ratio: initial;\n object-fit: contain;\n display: block;\n }\n"], ["\n position: relative;\n display: flex;\n flex-grow: 1;\n padding-bottom: 25px;\n max-width: var(--app-width);\n max-height: var(--app-height);\n overflow: hidden;\n\n & > img {\n margin: 0 auto;\n width: max-content;\n max-width: 100%;\n max-height: 100%;\n aspect-ratio: initial;\n object-fit: contain;\n display: block;\n }\n"])));
231
- var OverlayImageMultiContainer = styled__default['default'].div(templateObject_4 || (templateObject_4 = tslib.__makeTemplateObject(["\n display: flex;\n margin: auto;\n\n & > div {\n max-height: calc(100vh - 320px);\n\n & > img {\n width: 100%;\n max-height: 100%;\n height: auto;\n object-fit: contain;\n }\n }\n"], ["\n display: flex;\n margin: auto;\n\n & > div {\n max-height: calc(100vh - 320px);\n\n & > img {\n width: 100%;\n max-height: 100%;\n height: auto;\n object-fit: contain;\n }\n }\n"])));
232
- var templateObject_1$3, templateObject_2, templateObject_3, templateObject_4;
228
+ var OverlayContainer = styled__default['default'](PageContainer)(templateObject_1$6 || (templateObject_1$6 = tslib.__makeTemplateObject(["\n background: white;\n z-index: 10000;\n"], ["\n background: white;\n z-index: 10000;\n"])));
229
+ var OverlayInner = styled__default['default'].div(templateObject_2$3 || (templateObject_2$3 = tslib.__makeTemplateObject(["\n text-align: center;\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n padding: 25px;\n max-height: var(--app-height);\n height: 100%;\n box-sizing: border-box;\n"], ["\n text-align: center;\n display: flex;\n flex-direction: column;\n flex-wrap: nowrap;\n padding: 25px;\n max-height: var(--app-height);\n height: 100%;\n box-sizing: border-box;\n"])));
230
+ var OverlayImageWrapper = styled__default['default'].div(templateObject_3$2 || (templateObject_3$2 = tslib.__makeTemplateObject(["\n position: relative;\n display: flex;\n flex-grow: 1;\n padding-bottom: 25px;\n max-width: var(--app-width);\n max-height: var(--app-height);\n overflow: hidden;\n\n & > img {\n margin: 0 auto;\n width: max-content;\n max-width: 100%;\n max-height: 100%;\n aspect-ratio: initial;\n object-fit: contain;\n display: block;\n }\n"], ["\n position: relative;\n display: flex;\n flex-grow: 1;\n padding-bottom: 25px;\n max-width: var(--app-width);\n max-height: var(--app-height);\n overflow: hidden;\n\n & > img {\n margin: 0 auto;\n width: max-content;\n max-width: 100%;\n max-height: 100%;\n aspect-ratio: initial;\n object-fit: contain;\n display: block;\n }\n"])));
231
+ var OverlayImageMultiContainer = styled__default['default'].div(templateObject_4$2 || (templateObject_4$2 = tslib.__makeTemplateObject(["\n display: flex;\n margin: auto;\n\n & > div {\n max-height: calc(100vh - 320px);\n\n & > img {\n width: 100%;\n max-height: 100%;\n height: auto;\n object-fit: contain;\n }\n }\n"], ["\n display: flex;\n margin: auto;\n\n & > div {\n max-height: calc(100vh - 320px);\n\n & > img {\n width: 100%;\n max-height: 100%;\n height: auto;\n object-fit: contain;\n }\n }\n"])));
232
+ var templateObject_1$6, templateObject_2$3, templateObject_3$2, templateObject_4$2;
233
233
 
234
234
  var GeolocationAccessDeniedOverlay = function GeolocationAccessDeniedOverlay(_a) {
235
235
  var accessBlockedImageUrl = _a.accessBlockedImageUrl;
@@ -7650,16 +7650,8 @@ var IdCaptureModelsContext = /*#__PURE__*/React.createContext({
7650
7650
  working: {
7651
7651
  current: false
7652
7652
  },
7653
- documentDetectionThreshold: 1,
7654
- setDocumentDetectionThreshold: function setDocumentDetectionThreshold() {
7655
- return null;
7656
- },
7657
- passportDetectionThreshold: 1,
7658
- setPassportDetectionThreshold: function setPassportDetectionThreshold() {
7659
- return null;
7660
- },
7661
- focusThreshold: 1,
7662
- setFocusThreshold: function setFocusThreshold() {
7653
+ thresholds: {},
7654
+ setThresholds: function setThresholds() {
7663
7655
  return null;
7664
7656
  },
7665
7657
  makePrediction: function makePrediction() {
@@ -7677,6 +7669,8 @@ var IdCaptureModelsContext = /*#__PURE__*/React.createContext({
7677
7669
  return null;
7678
7670
  }
7679
7671
  });
7672
+ var defaultDocumentDetectionModelUrl = "".concat(DEFAULT_CDN_URL, "/models/documentdetection448/model.json");
7673
+ var defaultFocusModelUrl = "".concat(DEFAULT_CDN_URL, "/models/focus/model.json");
7680
7674
  var IdCaptureModelsProvider = function IdCaptureModelsProvider(_a) {
7681
7675
  var children = _a.children,
7682
7676
  documentDetectionModelUrl = _a.documentDetectionModelUrl,
@@ -7684,35 +7678,39 @@ var IdCaptureModelsProvider = function IdCaptureModelsProvider(_a) {
7684
7678
  var _b = React.useState(false),
7685
7679
  ready = _b[0],
7686
7680
  setReady = _b[1];
7687
- var _c = React.useState(1),
7681
+ var _c = React.useState(0),
7688
7682
  documentDetectionThreshold = _c[0],
7689
7683
  setDocumentDetectionThreshold = _c[1];
7690
- var _d = React.useState(1),
7684
+ var _d = React.useState(0),
7691
7685
  passportDetectionThreshold = _d[0],
7692
7686
  setPassportDetectionThreshold = _d[1];
7693
- var _e = React.useState(1),
7694
- focusThreshold = _e[0],
7695
- setFocusThreshold = _e[1];
7696
- var working = React.useRef(false);
7697
- var onPredictionHandler = React.useRef();
7698
- var canvas2d = React.useRef(null);
7699
- var canvasGl = React.useRef(null);
7687
+ var _e = React.useState(0),
7688
+ mrzDetectionThreshold = _e[0],
7689
+ setMrzDetectionThreshold = _e[1];
7700
7690
  var _f = React.useState(0),
7701
- detectionTime = _f[0],
7702
- setDetectionTime = _f[1];
7691
+ pdf417DetectionThreshold = _f[0],
7692
+ setPdf417DetectionThreshold = _f[1];
7703
7693
  var _g = React.useState(0),
7704
- focusPredictionTime = _g[0],
7705
- setFocusPredictionTime = _g[1];
7706
- documentDetectionModelUrl = documentDetectionModelUrl || "".concat(DEFAULT_CDN_URL, "/models/documentdetection448/model.json");
7707
- focusModelUrl = focusModelUrl || "".concat(DEFAULT_CDN_URL, "/models/focus/model.json");
7694
+ focusThreshold = _g[0],
7695
+ setFocusThreshold = _g[1];
7696
+ var working = React.useRef(false);
7697
+ var onPredictionHandler = React.useRef();
7698
+ var lastPredictionCanvas = React.useRef(null);
7699
+ var _h = React.useState(0),
7700
+ detectionTime = _h[0],
7701
+ setDetectionTime = _h[1];
7702
+ var _j = React.useState(0),
7703
+ focusPredictionTime = _j[0],
7704
+ setFocusPredictionTime = _j[1];
7708
7705
  React.useEffect(function () {
7709
- (function () {
7710
- return tslib.__awaiter(void 0, void 0, void 0, function () {
7706
+ setReady(false);
7707
+ var ddmUrl = documentDetectionModelUrl || defaultDocumentDetectionModelUrl;
7708
+ var fmUrl = focusModelUrl || defaultFocusModelUrl;
7709
+ function loadModels() {
7710
+ return tslib.__awaiter(this, void 0, void 0, function () {
7711
7711
  return tslib.__generator(this, function (_a) {
7712
7712
  switch (_a.label) {
7713
7713
  case 0:
7714
- if (!documentDetectionModelUrl || !focusModelUrl) return [2];
7715
- setReady(false);
7716
7714
  tf__namespace.ENV.set('WEBGL_DELETE_TEXTURE_THRESHOLD', 50 * 1024 * 1024);
7717
7715
  return [4, tf__namespace.setBackend('webgl')];
7718
7716
  case 1:
@@ -7720,54 +7718,67 @@ var IdCaptureModelsProvider = function IdCaptureModelsProvider(_a) {
7720
7718
  return [4, tf__namespace.ready()];
7721
7719
  case 2:
7722
7720
  _a.sent();
7723
- return [4, Promise.all([loadDocumentDetectionModel(documentDetectionModelUrl), loadFocusModel(focusModelUrl)])];
7721
+ return [4, Promise.all([loadDocumentDetectionModel(ddmUrl), loadFocusModel(fmUrl)])];
7724
7722
  case 3:
7725
7723
  _a.sent();
7726
- getWebGLContext(2).canvas.addEventListener('webglcontextlost', function () {
7727
- return tslib.__awaiter(void 0, void 0, void 0, function () {
7728
- var newCtx;
7729
- var _a;
7730
- return tslib.__generator(this, function (_b) {
7731
- switch (_b.label) {
7732
- case 0:
7733
- setReady(false);
7734
- unloadDocumentDetectionModel();
7735
- unloadFocusModel();
7736
- clearWebGLContext(2);
7737
- newCtx = (_a = canvasGl.current) === null || _a === void 0 ? void 0 : _a.getContext('webgl2');
7738
- if (!(newCtx && documentDetectionModelUrl && focusModelUrl)) return [3, 4];
7739
- tf.setWebGLContext(2, newCtx);
7740
- try {
7741
- tf__namespace.backend().dispose();
7742
- } catch (e) {
7743
- console.error('failed to dispose backend');
7744
- }
7745
- return [4, tf__namespace.setBackend('webgl')];
7746
- case 1:
7747
- _b.sent();
7748
- return [4, tf__namespace.ready()];
7749
- case 2:
7750
- _b.sent();
7751
- return [4, Promise.all([loadDocumentDetectionModel(documentDetectionModelUrl), loadFocusModel(focusModelUrl)])];
7752
- case 3:
7753
- _b.sent();
7754
- setReady(true);
7755
- _b.label = 4;
7756
- case 4:
7757
- return [2];
7758
- }
7759
- });
7760
- });
7761
- });
7724
+ return [2];
7725
+ }
7726
+ });
7727
+ });
7728
+ }
7729
+ function reloadModels() {
7730
+ return tslib.__awaiter(this, void 0, void 0, function () {
7731
+ var ctx;
7732
+ return tslib.__generator(this, function (_a) {
7733
+ switch (_a.label) {
7734
+ case 0:
7735
+ setReady(false);
7736
+ unloadDocumentDetectionModel();
7737
+ unloadFocusModel();
7738
+ clearWebGLContext(2);
7739
+ ctx = document.createElement('canvas').getContext('webgl2');
7740
+ if (!(ctx && ddmUrl && fmUrl)) return [3, 2];
7741
+ tf.setWebGLContext(2, ctx);
7742
+ disposeTfBackend();
7743
+ return [4, loadModels()];
7744
+ case 1:
7745
+ _a.sent();
7762
7746
  setReady(true);
7747
+ _a.label = 2;
7748
+ case 2:
7763
7749
  return [2];
7764
7750
  }
7765
7751
  });
7766
7752
  });
7767
- })();
7753
+ }
7754
+ loadModels().then(function () {
7755
+ setReady(true);
7756
+ });
7757
+ var webGLCanvas = getWebGLContext(2).canvas;
7758
+ webGLCanvas.addEventListener('webglcontextlost', reloadModels);
7759
+ return function () {
7760
+ var _a;
7761
+ (_a = webGLCanvas.removeEventListener) === null || _a === void 0 ? void 0 : _a.call(webGLCanvas, 'webglcontextlost', reloadModels);
7762
+ };
7768
7763
  }, [documentDetectionModelUrl, focusModelUrl]);
7764
+ var thresholds = React.useMemo(function () {
7765
+ return {
7766
+ document: documentDetectionThreshold,
7767
+ passport: passportDetectionThreshold,
7768
+ mrz: mrzDetectionThreshold,
7769
+ pdf417: pdf417DetectionThreshold,
7770
+ focus: focusThreshold
7771
+ };
7772
+ }, [documentDetectionThreshold, focusThreshold, mrzDetectionThreshold, passportDetectionThreshold, pdf417DetectionThreshold]);
7773
+ var setThresholds = React.useCallback(function (thresholds) {
7774
+ if (thresholds.document) setDocumentDetectionThreshold(thresholds.document);
7775
+ if (thresholds.passport) setPassportDetectionThreshold(thresholds.passport);
7776
+ if (thresholds.mrz) setMrzDetectionThreshold(thresholds.mrz);
7777
+ if (thresholds.pdf417) setPdf417DetectionThreshold(thresholds.pdf417);
7778
+ if (thresholds.focus) setFocusThreshold(thresholds.focus);
7779
+ }, []);
7769
7780
  var bestPredictionCanvas = React.useRef(null);
7770
- var bestPredictionScore = React.useRef(0);
7781
+ var bestFocusScore = React.useRef(0);
7771
7782
  var makePrediction = React.useCallback(function (frame) {
7772
7783
  working.current = true;
7773
7784
  (function () {
@@ -7777,14 +7788,14 @@ var IdCaptureModelsProvider = function IdCaptureModelsProvider(_a) {
7777
7788
  return tslib.__generator(this, function (_b) {
7778
7789
  switch (_b.label) {
7779
7790
  case 0:
7780
- if (!documentDetectionModel || !focusModel || !canvas2d.current) return [2];
7781
- return [4, makePredictions(frame, canvas2d.current, documentDetectionThreshold, passportDetectionThreshold, focusThreshold)];
7791
+ if (!documentDetectionModel || !focusModel || !lastPredictionCanvas.current) return [2];
7792
+ return [4, makePredictions(frame, lastPredictionCanvas.current, thresholds)];
7782
7793
  case 1:
7783
7794
  prediction = _b.sent();
7784
7795
  setDetectionTime(prediction.detectionTime);
7785
7796
  setFocusPredictionTime(prediction.focusPredictionTime);
7786
- if (bestPredictionScore.current <= prediction.detectionScore) {
7787
- bestPredictionScore.current = prediction.detectionScore;
7797
+ if (bestFocusScore.current <= prediction.focusScore) {
7798
+ bestFocusScore.current = prediction.focusScore;
7788
7799
  drawToCanvas(bestPredictionCanvas.current, frame);
7789
7800
  }
7790
7801
  (_a = onPredictionHandler.current) === null || _a === void 0 ? void 0 : _a.call(onPredictionHandler, prediction);
@@ -7794,7 +7805,7 @@ var IdCaptureModelsProvider = function IdCaptureModelsProvider(_a) {
7794
7805
  });
7795
7806
  });
7796
7807
  })();
7797
- }, [documentDetectionThreshold, focusThreshold, passportDetectionThreshold]);
7808
+ }, [thresholds]);
7798
7809
  var onPredictionMade = React.useCallback(function (handler) {
7799
7810
  onPredictionHandler.current = handler;
7800
7811
  }, []);
@@ -7817,54 +7828,45 @@ var IdCaptureModelsProvider = function IdCaptureModelsProvider(_a) {
7817
7828
  });
7818
7829
  }, []);
7819
7830
  var resetBestFrame = React.useCallback(function () {
7820
- bestPredictionScore.current = 0;
7831
+ bestFocusScore.current = 0;
7821
7832
  clearCanvas(bestPredictionCanvas.current);
7822
7833
  }, []);
7823
- var value = {
7824
- ready: ready,
7825
- working: working,
7826
- documentDetectionThreshold: documentDetectionThreshold,
7827
- setDocumentDetectionThreshold: setDocumentDetectionThreshold,
7828
- passportDetectionThreshold: passportDetectionThreshold,
7829
- setPassportDetectionThreshold: setPassportDetectionThreshold,
7830
- focusThreshold: focusThreshold,
7831
- setFocusThreshold: setFocusThreshold,
7832
- makePrediction: makePrediction,
7833
- onPredictionMade: onPredictionMade,
7834
- detectionTime: detectionTime,
7835
- focusPredictionTime: focusPredictionTime,
7836
- getBestFrame: getBestFrame,
7837
- resetBestFrame: resetBestFrame
7838
- };
7834
+ var value = React.useMemo(function () {
7835
+ return {
7836
+ ready: ready,
7837
+ working: working,
7838
+ thresholds: thresholds,
7839
+ setThresholds: setThresholds,
7840
+ makePrediction: makePrediction,
7841
+ onPredictionMade: onPredictionMade,
7842
+ detectionTime: detectionTime,
7843
+ focusPredictionTime: focusPredictionTime,
7844
+ getBestFrame: getBestFrame,
7845
+ resetBestFrame: resetBestFrame
7846
+ };
7847
+ }, [detectionTime, focusPredictionTime, getBestFrame, makePrediction, onPredictionMade, ready, resetBestFrame, setThresholds, thresholds]);
7839
7848
  return /*#__PURE__*/React__default['default'].createElement(IdCaptureModelsContext.Provider, {
7840
7849
  value: value
7841
- }, children, /*#__PURE__*/React__default['default'].createElement("canvas", {
7842
- ref: canvas2d,
7843
- style: {
7844
- display: 'none'
7845
- }
7846
- }), /*#__PURE__*/React__default['default'].createElement("canvas", {
7847
- ref: canvasGl,
7848
- style: {
7849
- display: 'none'
7850
- }
7851
- }), /*#__PURE__*/React__default['default'].createElement("canvas", {
7852
- ref: bestPredictionCanvas,
7853
- style: {
7854
- display: 'none'
7855
- }
7850
+ }, children, /*#__PURE__*/React__default['default'].createElement(InvisibleCanvas, {
7851
+ ref: lastPredictionCanvas
7852
+ }), /*#__PURE__*/React__default['default'].createElement(InvisibleCanvas, {
7853
+ ref: bestPredictionCanvas
7856
7854
  }));
7857
7855
  };
7858
- function drawToCanvas(canvas, frame) {
7856
+ function drawToCanvas(canvas, frame, width, height) {
7859
7857
  if (!canvas) return;
7860
7858
  var ctx = canvas.getContext('2d');
7861
7859
  if (!ctx) return;
7862
- var _a = getFrameDimensions(frame),
7863
- frameWidth = _a[0],
7864
- frameHeight = _a[1];
7865
- canvas.width = frameWidth;
7866
- canvas.height = frameHeight;
7867
- ctx.drawImage(frame, 0, 0, frameWidth, frameHeight);
7860
+ if (!width || !height) {
7861
+ var _a = getFrameDimensions(frame),
7862
+ frameWidth = _a[0],
7863
+ frameHeight = _a[1];
7864
+ width || (width = frameWidth);
7865
+ height || (height = frameHeight);
7866
+ }
7867
+ canvas.width = width;
7868
+ canvas.height = height;
7869
+ ctx.drawImage(frame, 0, 0, width, height);
7868
7870
  }
7869
7871
  function clearCanvas(canvas) {
7870
7872
  if (!canvas) return;
@@ -7872,21 +7874,19 @@ function clearCanvas(canvas) {
7872
7874
  if (!ctx) return;
7873
7875
  ctx.clearRect(0, 0, canvas.width, canvas.height);
7874
7876
  }
7875
- function makePredictions(frame, canvas, documentDetectionThreshold, passportDetectionThreshold, focusThreshold) {
7876
- var _a, _b, _c, _d;
7877
+ function makePredictions(frame, lastPredictionCanvas, thresholds) {
7878
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
7877
7879
  return tslib.__awaiter(this, void 0, void 0, function () {
7878
- var _e, frameWidth, frameHeight, _f, _g, boxes, scores, labels, detectionTime, detectedObjects, bestDocument, bestPassportPage, bestDocumentScore, passportDetectionScore, passportDetectionThresholdMet, bestDocumentOrPassport, detectionScore, detectionThresholdMet, focusPrediction, focusPredictionTime, focusScore, focusThresholdMet;
7879
- var _h;
7880
- return tslib.__generator(this, function (_j) {
7881
- switch (_j.label) {
7880
+ var _l, frameWidth, frameHeight, _o, boxes, scores, labels, time, detectedObjects, bestDocument, bestPassportPage, bestDocumentScore, passportDetectionScore, passportDetectionThresholdMet, bestDocumentOrPassport, detectionScore, detectionThresholdMet, bestMrz, mrzDetectionScore, mrzDetectionThresholdMet, bestPdf417, pdf417DetectionScore, pdf417DetectionThresholdMet, focusPrediction, focusPredictionTime, focusScore, focusThresholdMet;
7881
+ var _p;
7882
+ return tslib.__generator(this, function (_q) {
7883
+ switch (_q.label) {
7882
7884
  case 0:
7883
- _e = getFrameDimensions(frame), frameWidth = _e[0], frameHeight = _e[1];
7884
- {
7885
- drawToCanvas(canvas, frame);
7886
- }
7885
+ _l = getFrameDimensions(frame), frameWidth = _l[0], frameHeight = _l[1];
7886
+ drawToCanvas(lastPredictionCanvas, frame);
7887
7887
  return [4, makeDocumentDetectionPredictions(frame)];
7888
7888
  case 1:
7889
- _f = _j.sent(), _g = _f[0], boxes = _g.boxes, scores = _g.scores, labels = _g.labels, detectionTime = _f[1];
7889
+ _o = _q.sent(), boxes = _o.boxes, scores = _o.scores, labels = _o.labels, time = _o.time;
7890
7890
  detectedObjects = applyNonMaxSuppression(boxes.map(function (box, i) {
7891
7891
  return bboxToDetectedObjectUnscaled(box, scores[i], labels[i]);
7892
7892
  }));
@@ -7898,18 +7898,28 @@ function makePredictions(frame, canvas, documentDetectionThreshold, passportDete
7898
7898
  });
7899
7899
  bestDocumentScore = (_a = bestDocument === null || bestDocument === void 0 ? void 0 : bestDocument.score) !== null && _a !== void 0 ? _a : 0;
7900
7900
  passportDetectionScore = (_b = bestPassportPage === null || bestPassportPage === void 0 ? void 0 : bestPassportPage.score) !== null && _b !== void 0 ? _b : 0;
7901
- passportDetectionThresholdMet = passportDetectionScore >= passportDetectionThreshold;
7901
+ passportDetectionThresholdMet = passportDetectionScore >= ((_c = thresholds.passport) !== null && _c !== void 0 ? _c : 0);
7902
7902
  bestDocumentOrPassport = bestDocumentScore > passportDetectionScore ? bestDocument : bestPassportPage;
7903
- detectionScore = passportDetectionThresholdMet ? passportDetectionScore : (_c = bestDocument === null || bestDocument === void 0 ? void 0 : bestDocument.score) !== null && _c !== void 0 ? _c : 0;
7904
- detectionThresholdMet = detectionScore >= documentDetectionThreshold;
7903
+ detectionScore = passportDetectionThresholdMet ? passportDetectionScore : bestDocumentScore;
7904
+ detectionThresholdMet = detectionScore >= ((_d = thresholds.document) !== null && _d !== void 0 ? _d : 0);
7905
+ bestMrz = detectedObjects.find(function (obj) {
7906
+ return obj.label === 'MRZ';
7907
+ });
7908
+ mrzDetectionScore = (_e = bestMrz === null || bestMrz === void 0 ? void 0 : bestMrz.score) !== null && _e !== void 0 ? _e : 0;
7909
+ mrzDetectionThresholdMet = mrzDetectionScore >= ((_f = thresholds.mrz) !== null && _f !== void 0 ? _f : 0);
7910
+ bestPdf417 = detectedObjects.find(function (obj) {
7911
+ return obj.label === 'PDF417';
7912
+ });
7913
+ pdf417DetectionScore = (_g = bestPdf417 === null || bestPdf417 === void 0 ? void 0 : bestPdf417.score) !== null && _g !== void 0 ? _g : 0;
7914
+ pdf417DetectionThresholdMet = pdf417DetectionScore >= ((_h = thresholds.pdf417) !== null && _h !== void 0 ? _h : 0);
7905
7915
  focusPrediction = null, focusPredictionTime = 0, focusScore = 0, focusThresholdMet = false;
7906
7916
  if (!detectionThresholdMet) return [3, 3];
7907
7917
  return [4, makeFocusPrediction(frame, bestDocumentOrPassport === null || bestDocumentOrPassport === void 0 ? void 0 : bestDocumentOrPassport.bbox)];
7908
7918
  case 2:
7909
- _h = _j.sent(), focusPrediction = _h[0], focusPredictionTime = _h[1];
7910
- focusScore = (_d = focusPrediction === null || focusPrediction === void 0 ? void 0 : focusPrediction[1]) !== null && _d !== void 0 ? _d : 0;
7911
- focusThresholdMet = focusScore >= focusThreshold;
7912
- _j.label = 3;
7919
+ _p = _q.sent(), focusPrediction = _p[0], focusPredictionTime = _p[1];
7920
+ focusScore = (_j = focusPrediction === null || focusPrediction === void 0 ? void 0 : focusPrediction[1]) !== null && _j !== void 0 ? _j : 0;
7921
+ focusThresholdMet = focusScore >= ((_k = thresholds.focus) !== null && _k !== void 0 ? _k : 0);
7922
+ _q.label = 3;
7913
7923
  case 3:
7914
7924
  return [2, {
7915
7925
  detectedObjects: detectedObjects,
@@ -7917,11 +7927,17 @@ function makePredictions(frame, canvas, documentDetectionThreshold, passportDete
7917
7927
  detectionThresholdMet: detectionThresholdMet,
7918
7928
  passportDetectionScore: passportDetectionScore,
7919
7929
  passportDetectionThresholdMet: passportDetectionThresholdMet,
7920
- detectionTime: detectionTime,
7930
+ mrzDetectionScore: mrzDetectionScore,
7931
+ mrzDetectionThresholdMet: mrzDetectionThresholdMet,
7932
+ pdf417DetectionScore: pdf417DetectionScore,
7933
+ pdf417DetectionThresholdMet: pdf417DetectionThresholdMet,
7934
+ detectionTime: time,
7921
7935
  bestDocumentOrPassport: bestDocumentOrPassport,
7922
- focusPredictionTime: focusPredictionTime,
7936
+ bestMrz: bestMrz,
7937
+ bestPdf417: bestPdf417,
7923
7938
  focusScore: focusScore,
7924
7939
  focusThresholdMet: focusThresholdMet,
7940
+ focusPredictionTime: focusPredictionTime,
7925
7941
  frameWidth: frameWidth,
7926
7942
  frameHeight: frameHeight
7927
7943
  }];
@@ -7931,7 +7947,7 @@ function makePredictions(frame, canvas, documentDetectionThreshold, passportDete
7931
7947
  }
7932
7948
  function makeDocumentDetectionPredictions(image) {
7933
7949
  return tslib.__awaiter(this, void 0, void 0, function () {
7934
- var startedAt, tfImg, tfResize, tfInt32, tf4d_, _a, _b, _c, _d, tf4d, result, predictions, boxes, scores, labels, predictionTime, e_1;
7950
+ var startedAt, tfImg, tfResize, tfInt32, tf4d_, _a, _b, _c, _d, tf4d, result, predictions, boxes, scores, labels, time, e_1;
7935
7951
  return tslib.__generator(this, function (_e) {
7936
7952
  switch (_e.label) {
7937
7953
  case 0:
@@ -7973,20 +7989,22 @@ function makeDocumentDetectionPredictions(image) {
7973
7989
  return Math.round(l);
7974
7990
  });
7975
7991
  tf__namespace.dispose(result);
7976
- predictionTime = new Date().getTime() - startedAt.getTime();
7977
- return [2, [{
7992
+ time = new Date().getTime() - startedAt.getTime();
7993
+ return [2, {
7978
7994
  boxes: boxes,
7979
7995
  scores: scores,
7980
- labels: labels
7981
- }, predictionTime]];
7996
+ labels: labels,
7997
+ time: time
7998
+ }];
7982
7999
  case 7:
7983
8000
  e_1 = _e.sent();
7984
8001
  console.error('caught error in makeDocumentDetectionPredictions', e_1);
7985
- return [2, [{
8002
+ return [2, {
7986
8003
  boxes: [],
7987
8004
  scores: [],
7988
- labels: []
7989
- }, 0]];
8005
+ labels: [],
8006
+ time: 0
8007
+ }];
7990
8008
  case 8:
7991
8009
  return [2];
7992
8010
  }
@@ -8057,29 +8075,229 @@ function applyNonMaxSuppression(detectedObjects) {
8057
8075
  return !!obj;
8058
8076
  });
8059
8077
  }
8078
+ function disposeTfBackend() {
8079
+ try {
8080
+ tf__namespace.backend().dispose();
8081
+ } catch (e) {
8082
+ console.error('failed to dispose backend', e);
8083
+ }
8084
+ }
8085
+ var InvisibleCanvas = styled__default['default'].canvas(templateObject_1$5 || (templateObject_1$5 = tslib.__makeTemplateObject(["\n display: none;\n"], ["\n display: none;\n"])));
8086
+ var templateObject_1$5;
8087
+
8088
+ var DebugStatsPane = styled__default['default'].span(templateObject_1$4 || (templateObject_1$4 = tslib.__makeTemplateObject(["\n font-size: 16px;\n font-family: monospace;\n position: absolute;\n left: 20px;\n bottom: 20px;\n color: limegreen;\n background: rgba(0, 0, 0, 0.5);\n z-index: 1001;\n"], ["\n font-size: 16px;\n font-family: monospace;\n position: absolute;\n left: 20px;\n bottom: 20px;\n color: limegreen;\n background: rgba(0, 0, 0, 0.5);\n z-index: 1001;\n"])));
8089
+ var ObjectDetectionDebugOverlay = styled__default['default'].div(templateObject_2$2 || (templateObject_2$2 = tslib.__makeTemplateObject(["\n position: absolute;\n z-index: 1001;\n width: 100%;\n height: 100%;\n max-width: 100%;\n max-height: 100%;\n overflow: hidden;\n ", "\n"], ["\n position: absolute;\n z-index: 1001;\n width: 100%;\n height: 100%;\n max-width: 100%;\n max-height: 100%;\n overflow: hidden;\n ", "\n"])), function (_a) {
8090
+ var $flipX = _a.$flipX;
8091
+ return $flipX ? 'transform: scaleX(-1);' : '';
8092
+ });
8093
+ var ObjectDetectionDebugBox = styled__default['default'].div(templateObject_3$1 || (templateObject_3$1 = tslib.__makeTemplateObject(["\n font: 10px monospace;\n position: absolute;\n top: ", "px;\n left: ", "px;\n width: ", "px;\n height: ", "px;\n border: 3px solid ", ";\n color: ", ";\n ", "\n"], ["\n font: 10px monospace;\n position: absolute;\n top: ", "px;\n left: ", "px;\n width: ", "px;\n height: ", "px;\n border: 3px solid ", ";\n color: ", ";\n ", "\n"])), function (_a) {
8094
+ var $top = _a.$top;
8095
+ return $top;
8096
+ }, function (_a) {
8097
+ var $left = _a.$left;
8098
+ return $left;
8099
+ }, function (_a) {
8100
+ var $width = _a.$width;
8101
+ return $width;
8102
+ }, function (_a) {
8103
+ var $height = _a.$height;
8104
+ return $height;
8105
+ }, function (_a) {
8106
+ var $color = _a.$color;
8107
+ return $color !== null && $color !== void 0 ? $color : 'green';
8108
+ }, function (_a) {
8109
+ var $color = _a.$color;
8110
+ return $color !== null && $color !== void 0 ? $color : 'green';
8111
+ }, function (_a) {
8112
+ var $flipX = _a.$flipX;
8113
+ return $flipX ? 'transform: scaleX(-1);' : '';
8114
+ });
8115
+ var FaceDetectionKeypointMarker = styled__default['default'].div(templateObject_4$1 || (templateObject_4$1 = tslib.__makeTemplateObject(["\n position: absolute;\n top: ", "px;\n left: ", "px;\n width: ", "px;\n height: ", "px;\n border: ", "px solid\n ", ";\n font: 10px monospace;\n color: ", ";\n border-radius: 50%;\n ", "\n"], ["\n position: absolute;\n top: ", "px;\n left: ", "px;\n width: ", "px;\n height: ", "px;\n border: ", "px solid\n ", ";\n font: 10px monospace;\n color: ", ";\n border-radius: 50%;\n ", "\n"])), function (_a) {
8116
+ var $top = _a.$top,
8117
+ $height = _a.$height;
8118
+ return $top - $height / 2;
8119
+ }, function (_a) {
8120
+ var $left = _a.$left,
8121
+ $width = _a.$width;
8122
+ return $left - $width / 2;
8123
+ }, function (_a) {
8124
+ var $width = _a.$width;
8125
+ return $width;
8126
+ }, function (_a) {
8127
+ var $height = _a.$height;
8128
+ return $height;
8129
+ }, function (_a) {
8130
+ var $width = _a.$width;
8131
+ return $width / 2;
8132
+ }, function (_a) {
8133
+ var $color = _a.$color;
8134
+ return $color !== null && $color !== void 0 ? $color : 'red';
8135
+ }, function (_a) {
8136
+ var $color = _a.$color;
8137
+ return $color !== null && $color !== void 0 ? $color : 'red';
8138
+ }, function (_a) {
8139
+ var $flipX = _a.$flipX;
8140
+ return $flipX ? 'transform: scaleX(-1);' : '';
8141
+ });
8142
+ function useDebugScalingDetails(_a) {
8143
+ var _b = _a.enabled,
8144
+ enabled = _b === void 0 ? true : _b,
8145
+ pageWidth = _a.pageWidth,
8146
+ pageHeight = _a.pageHeight,
8147
+ videoWidth = _a.videoWidth,
8148
+ videoHeight = _a.videoHeight;
8149
+ return React.useMemo(function () {
8150
+ var horizontal = false,
8151
+ scaledWidth = 0,
8152
+ scaledHeight = 0,
8153
+ xOffset = 0,
8154
+ yOffset = 0;
8155
+ if (enabled) {
8156
+ horizontal = pageWidth / pageHeight < videoWidth / videoHeight;
8157
+ if (horizontal) {
8158
+ scaledWidth = videoWidth * (pageHeight / videoHeight);
8159
+ xOffset = (scaledWidth - pageWidth) / 2;
8160
+ } else {
8161
+ scaledHeight = videoHeight * (pageWidth / videoWidth);
8162
+ yOffset = (scaledHeight - pageHeight) / 2;
8163
+ }
8164
+ }
8165
+ return {
8166
+ horizontal: horizontal,
8167
+ pageWidth: pageWidth,
8168
+ pageHeight: pageHeight,
8169
+ videoWidth: videoWidth,
8170
+ videoHeight: videoHeight,
8171
+ scaledWidth: scaledWidth,
8172
+ scaledHeight: scaledHeight,
8173
+ xOffset: xOffset,
8174
+ yOffset: yOffset
8175
+ };
8176
+ }, [enabled, pageHeight, pageWidth, videoHeight, videoWidth]);
8177
+ }
8178
+ function IdCaptureDetectedObjectDebugBox(_a) {
8179
+ var obj = _a.obj,
8180
+ flipX = _a.flipX,
8181
+ _b = _a.scaling,
8182
+ horizontal = _b.horizontal,
8183
+ pageWidth = _b.pageWidth,
8184
+ pageHeight = _b.pageHeight,
8185
+ scaledWidth = _b.scaledWidth,
8186
+ scaledHeight = _b.scaledHeight,
8187
+ xOffset = _b.xOffset,
8188
+ yOffset = _b.yOffset;
8189
+ var top = obj.bbox[1] * (horizontal ? pageHeight : scaledHeight - yOffset);
8190
+ var left = obj.bbox[0] * (horizontal ? scaledWidth - xOffset : pageWidth);
8191
+ var width = obj.bbox[2] * (horizontal ? scaledWidth : pageWidth);
8192
+ var height = obj.bbox[3] * (horizontal ? pageHeight : scaledHeight);
8193
+ return /*#__PURE__*/React__default['default'].createElement(ObjectDetectionDebugBox, {
8194
+ "$top": top,
8195
+ "$left": left,
8196
+ "$width": width,
8197
+ "$height": height,
8198
+ "$flipX": flipX
8199
+ }, obj.label, " (", obj.score.toFixed(3), ")");
8200
+ }
8201
+ function SelfieCaptureFaceDebugBox(_a) {
8202
+ var face = _a.face,
8203
+ flipX = _a.flipX,
8204
+ _b = _a.color,
8205
+ color = _b === void 0 ? 'green' : _b,
8206
+ scaling = _a.scaling;
8207
+ var horizontal = scaling.horizontal,
8208
+ pageWidth = scaling.pageWidth,
8209
+ pageHeight = scaling.pageHeight,
8210
+ videoWidth = scaling.videoWidth,
8211
+ videoHeight = scaling.videoHeight,
8212
+ scaledWidth = scaling.scaledWidth,
8213
+ scaledHeight = scaling.scaledHeight,
8214
+ xOffset = scaling.xOffset,
8215
+ yOffset = scaling.yOffset;
8216
+ var top;
8217
+ var left;
8218
+ var width;
8219
+ var height;
8220
+ if (horizontal) {
8221
+ top = face.box.yMin / videoHeight * pageHeight;
8222
+ left = face.box.xMin / videoWidth * scaledWidth - xOffset;
8223
+ width = face.box.width / videoWidth * scaledWidth;
8224
+ height = face.box.height / videoHeight * pageHeight;
8225
+ } else {
8226
+ top = face.box.yMin / videoHeight * scaledHeight - yOffset;
8227
+ left = face.box.xMin / videoWidth * pageWidth;
8228
+ width = face.box.width / videoWidth * pageWidth;
8229
+ height = face.box.height / videoHeight * scaledHeight;
8230
+ }
8231
+ return /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, /*#__PURE__*/React__default['default'].createElement(ObjectDetectionDebugBox, {
8232
+ "$top": top,
8233
+ "$left": left,
8234
+ "$width": width,
8235
+ "$height": height,
8236
+ "$flipX": flipX,
8237
+ "$color": color
8238
+ }), face.keypoints.map(function (point, ii) {
8239
+ return /*#__PURE__*/React__default['default'].createElement(SelfieCaptureFaceKeypoint, {
8240
+ key: ii,
8241
+ point: point,
8242
+ scaling: scaling,
8243
+ flipX: flipX
8244
+ });
8245
+ }));
8246
+ }
8247
+ function SelfieCaptureFaceKeypoint(_a) {
8248
+ var point = _a.point,
8249
+ flipX = _a.flipX,
8250
+ _b = _a.color,
8251
+ color = _b === void 0 ? 'red' : _b,
8252
+ _c = _a.scaling,
8253
+ horizontal = _c.horizontal,
8254
+ pageWidth = _c.pageWidth,
8255
+ pageHeight = _c.pageHeight,
8256
+ videoWidth = _c.videoWidth,
8257
+ videoHeight = _c.videoHeight,
8258
+ scaledWidth = _c.scaledWidth,
8259
+ scaledHeight = _c.scaledHeight,
8260
+ xOffset = _c.xOffset,
8261
+ yOffset = _c.yOffset;
8262
+ var left, top;
8263
+ if (horizontal) {
8264
+ left = point.x / videoWidth * scaledWidth - xOffset;
8265
+ top = point.y / videoHeight * pageHeight;
8266
+ } else {
8267
+ left = point.x / videoWidth * pageWidth;
8268
+ top = point.y / videoHeight * scaledHeight - yOffset;
8269
+ }
8270
+ return /*#__PURE__*/React__default['default'].createElement(FaceDetectionKeypointMarker, {
8271
+ "$top": top,
8272
+ "$left": left,
8273
+ "$width": 4,
8274
+ "$height": 4,
8275
+ "$flipX": flipX,
8276
+ "$color": color
8277
+ });
8278
+ }
8279
+ var templateObject_1$4, templateObject_2$2, templateObject_3$1, templateObject_4$1;
8060
8280
 
8061
8281
  var initialState$5 = {
8062
8282
  videoWidth: 0,
8063
8283
  videoHeight: 0,
8064
8284
  captureStartedAt: null,
8065
8285
  detectedObjects: [],
8066
- bestDocument: null,
8067
- bestMrz: null,
8068
- bestPdf417: null,
8286
+ bestDocument: undefined,
8287
+ bestMrz: undefined,
8288
+ bestPdf417: undefined,
8069
8289
  documentType: DocumentType.NONE,
8070
8290
  documentInBounds: false,
8071
8291
  documentDetectionScore: 0,
8072
8292
  documentDetectionThresholdMet: false,
8073
- mrzDetectionScore: 0,
8074
- mrzDetectionThreshold: 0.5,
8075
- mrzDetectionThresholdMet: false,
8076
- focusScore: 0,
8077
- focusThresholdMet: false,
8078
8293
  passportPageDetectionScore: 0,
8079
8294
  passportPageDetectionThresholdMet: false,
8295
+ mrzDetectionScore: 0,
8296
+ mrzDetectionThresholdMet: false,
8080
8297
  pdf417DetectionScore: 0,
8081
- pdf417DetectionThreshold: 0.15,
8082
8298
  pdf417DetectionThresholdMet: false,
8299
+ focusScore: 0,
8300
+ focusThresholdMet: false,
8083
8301
  barcodeScanningEnabled: false,
8084
8302
  barcodeResult: null,
8085
8303
  waitingForBarcodeScan: false,
@@ -8098,7 +8316,6 @@ var initialState$5 = {
8098
8316
  captureFailed: false
8099
8317
  };
8100
8318
  var reducer$5 = function reducer(state, action) {
8101
- var _a, _b, _c, _d;
8102
8319
  switch (action.type) {
8103
8320
  case 'configure':
8104
8321
  return tslib.__assign(tslib.__assign(tslib.__assign({}, state), action.payload), {
@@ -8109,17 +8326,23 @@ var reducer$5 = function reducer(state, action) {
8109
8326
  captureFailed: false
8110
8327
  });
8111
8328
  case 'objectsDetected':
8112
- var _e = action.payload.prediction,
8113
- detectedObjects = _e.detectedObjects,
8114
- detectionScore = _e.detectionScore,
8115
- detectionThresholdMet = _e.detectionThresholdMet,
8116
- passportDetectionScore = _e.passportDetectionScore,
8117
- passportDetectionThresholdMet = _e.passportDetectionThresholdMet,
8118
- bestDocumentOrPassport = _e.bestDocumentOrPassport,
8119
- focusScore = _e.focusScore,
8120
- focusThresholdMet = _e.focusThresholdMet,
8121
- frameWidth = _e.frameWidth,
8122
- frameHeight = _e.frameHeight;
8329
+ var _a = action.payload.prediction,
8330
+ detectedObjects = _a.detectedObjects,
8331
+ detectionScore = _a.detectionScore,
8332
+ detectionThresholdMet = _a.detectionThresholdMet,
8333
+ passportDetectionScore = _a.passportDetectionScore,
8334
+ passportDetectionThresholdMet = _a.passportDetectionThresholdMet,
8335
+ mrzDetectionScore = _a.mrzDetectionScore,
8336
+ mrzDetectionThresholdMet = _a.mrzDetectionThresholdMet,
8337
+ pdf417DetectionScore = _a.pdf417DetectionScore,
8338
+ pdf417DetectionThresholdMet = _a.pdf417DetectionThresholdMet,
8339
+ bestDocumentOrPassport = _a.bestDocumentOrPassport,
8340
+ bestMrz = _a.bestMrz,
8341
+ bestPdf417 = _a.bestPdf417,
8342
+ focusScore = _a.focusScore,
8343
+ focusThresholdMet = _a.focusThresholdMet,
8344
+ frameWidth = _a.frameWidth,
8345
+ frameHeight = _a.frameHeight;
8123
8346
  var frameCapturedAt = new Date();
8124
8347
  var frameCaptureRate = 0;
8125
8348
  var goodFramesThreshold = state.goodFramesThreshold;
@@ -8129,16 +8352,6 @@ var reducer$5 = function reducer(state, action) {
8129
8352
  goodFramesThreshold = Math.ceil(3 * frameCaptureRate);
8130
8353
  }
8131
8354
  }
8132
- var bestMrz = (_a = detectedObjects.find(function (obj) {
8133
- return obj.label === 'MRZ';
8134
- })) !== null && _a !== void 0 ? _a : null;
8135
- var mrzDetectionScore = (_b = bestMrz === null || bestMrz === void 0 ? void 0 : bestMrz.score) !== null && _b !== void 0 ? _b : 0;
8136
- var mrzDetectionThresholdMet = mrzDetectionScore >= state.mrzDetectionThreshold;
8137
- var bestPdf417 = (_c = detectedObjects.find(function (obj) {
8138
- return obj.label === 'PDF417';
8139
- })) !== null && _c !== void 0 ? _c : null;
8140
- var pdf417DetectionScore = (_d = bestPdf417 === null || bestPdf417 === void 0 ? void 0 : bestPdf417.score) !== null && _d !== void 0 ? _d : 0;
8141
- var pdf417DetectionThresholdMet = pdf417DetectionScore >= state.pdf417DetectionThreshold;
8142
8355
  var documentType = DocumentType.NONE;
8143
8356
  if (passportDetectionThresholdMet) {
8144
8357
  documentType = DocumentType.PASSPORT;
@@ -8147,11 +8360,11 @@ var reducer$5 = function reducer(state, action) {
8147
8360
  }
8148
8361
  var documentInBounds = false;
8149
8362
  if (bestDocumentOrPassport) {
8150
- var _f = bestDocumentOrPassport.bbox,
8151
- boundaryX = _f[0],
8152
- boundaryY = _f[1],
8153
- boundaryWidth = _f[2],
8154
- boundaryHeight = _f[3];
8363
+ var _b = bestDocumentOrPassport.bbox,
8364
+ boundaryX = _b[0],
8365
+ boundaryY = _b[1],
8366
+ boundaryWidth = _b[2],
8367
+ boundaryHeight = _b[3];
8155
8368
  boundaryX *= frameWidth;
8156
8369
  boundaryWidth *= frameWidth;
8157
8370
  boundaryY *= frameHeight;
@@ -8170,7 +8383,7 @@ var reducer$5 = function reducer(state, action) {
8170
8383
  videoWidth: frameWidth,
8171
8384
  videoHeight: frameHeight,
8172
8385
  detectedObjects: detectedObjects,
8173
- bestDocument: bestDocumentOrPassport !== null && bestDocumentOrPassport !== void 0 ? bestDocumentOrPassport : null,
8386
+ bestDocument: bestDocumentOrPassport,
8174
8387
  bestMrz: bestMrz,
8175
8388
  bestPdf417: bestPdf417,
8176
8389
  documentType: documentType,
@@ -8295,9 +8508,7 @@ var IdCapture = function IdCapture(_a) {
8295
8508
  var _3 = React.useContext(IdCaptureModelsContext),
8296
8509
  modelsReady = _3.ready,
8297
8510
  modelsWorking = _3.working,
8298
- setDocumentDetectionThreshold = _3.setDocumentDetectionThreshold,
8299
- setPassportDetectionThreshold = _3.setPassportDetectionThreshold,
8300
- setFocusThreshold = _3.setFocusThreshold,
8511
+ setThresholds = _3.setThresholds,
8301
8512
  makePrediction = _3.makePrediction,
8302
8513
  onPredictionMade = _3.onPredictionMade,
8303
8514
  detectionTime = _3.detectionTime,
@@ -8312,19 +8523,21 @@ var IdCapture = function IdCapture(_a) {
8312
8523
  type: 'configure',
8313
8524
  payload: {
8314
8525
  requiredDocumentType: requiredDocumentType,
8315
- mrzDetectionThreshold: mrzDetectionScoreThreshold,
8316
8526
  goodFramesThreshold: autoCaptureGoodFramesRequired,
8317
8527
  autoCaptureBarcodeRequired: autoCaptureBarcodeRequired,
8318
8528
  barcodeScanningEnabled: barcodeScanningEnabled,
8319
- maxBarcodeScanAttempts: maxBarcodeScanAttempts,
8320
- pdf417DetectionThreshold: pdf417DetectionThreshold
8529
+ maxBarcodeScanAttempts: maxBarcodeScanAttempts
8321
8530
  }
8322
8531
  });
8323
8532
  resetBestFrame();
8324
- setDocumentDetectionThreshold(autoCaptureScoreThreshold);
8325
- setPassportDetectionThreshold(passportPageDetectionThreshold);
8326
- setFocusThreshold(focusScoreThreshold);
8327
- }, [requiredDocumentType, autoCaptureScoreThreshold, focusScoreThreshold, mrzDetectionScoreThreshold, autoCaptureGoodFramesRequired, autoCaptureBarcodeRequired, barcodeScanningEnabled, maxBarcodeScanAttempts, passportPageDetectionThreshold, pdf417DetectionThreshold, resetBestFrame, setDocumentDetectionThreshold, setPassportDetectionThreshold, setFocusThreshold]);
8533
+ setThresholds({
8534
+ document: autoCaptureScoreThreshold,
8535
+ passport: passportPageDetectionThreshold,
8536
+ mrz: mrzDetectionScoreThreshold,
8537
+ pdf417: pdf417DetectionThreshold,
8538
+ focus: focusScoreThreshold
8539
+ });
8540
+ }, [requiredDocumentType, autoCaptureScoreThreshold, focusScoreThreshold, mrzDetectionScoreThreshold, autoCaptureGoodFramesRequired, autoCaptureBarcodeRequired, barcodeScanningEnabled, maxBarcodeScanAttempts, passportPageDetectionThreshold, pdf417DetectionThreshold, resetBestFrame, setThresholds]);
8328
8541
  var animationFrame = React.useRef(0);
8329
8542
  var shouldCaptureFrames = React.useRef(false);
8330
8543
  React.useEffect(function () {
@@ -8497,6 +8710,13 @@ var IdCapture = function IdCapture(_a) {
8497
8710
  });
8498
8711
  })();
8499
8712
  }, [getBestFrame, onCapture, processingDelay, shouldCapture, state.barcodeResult]);
8713
+ var debugScalingDetails = useDebugScalingDetails({
8714
+ enabled: debugMode,
8715
+ pageWidth: width,
8716
+ pageHeight: height,
8717
+ videoWidth: state.videoWidth,
8718
+ videoHeight: state.videoHeight
8719
+ });
8500
8720
  if (processingFrame) {
8501
8721
  return processingScreen || /*#__PURE__*/React__default['default'].createElement("div", null, "Processing...");
8502
8722
  }
@@ -8524,64 +8744,17 @@ var IdCapture = function IdCapture(_a) {
8524
8744
  landscapeGuidesImageUrl: assets.landscapeGuidesImageUrl,
8525
8745
  isMirrored: !((_c = cameraRef.current) === null || _c === void 0 ? void 0 : _c.isRearFacing),
8526
8746
  borderColor: state.isGoodFrame ? 'green' : 'white'
8527
- }), debugMode && state.detectedObjects.length > 0 && /*#__PURE__*/React__default['default'].createElement("div", {
8528
- style: {
8529
- position: 'absolute',
8530
- zIndex: 1001,
8531
- width: '100%',
8532
- height: '100%',
8533
- maxWidth: '100%',
8534
- maxHeight: '100%',
8535
- transform: ((_d = cameraRef.current) === null || _d === void 0 ? void 0 : _d.isRearFacing) ? '' : 'scaleX(-1)',
8536
- overflow: 'hidden'
8537
- }
8747
+ }), debugMode && state.detectedObjects.length > 0 && /*#__PURE__*/React__default['default'].createElement(ObjectDetectionDebugOverlay, {
8748
+ "$flipX": !((_d = cameraRef.current) === null || _d === void 0 ? void 0 : _d.isRearFacing)
8538
8749
  }, state.detectedObjects.map(function (obj, i) {
8539
8750
  var _a;
8540
- var wrapperAspectRatio = width / height;
8541
- var videoAspectRatio = state.videoWidth / state.videoHeight;
8542
- var left = obj.bbox[0] * width;
8543
- var top = obj.bbox[1] * height;
8544
- var boxWidth = obj.bbox[2] * width;
8545
- var boxHeight = obj.bbox[3] * height;
8546
- if (wrapperAspectRatio < videoAspectRatio) {
8547
- var xScalar = height / state.videoHeight;
8548
- var scaledWidth = state.videoWidth * xScalar;
8549
- var xOffset = (scaledWidth - width) / 2;
8550
- left = obj.bbox[0] * scaledWidth - xOffset;
8551
- boxWidth = obj.bbox[2] * scaledWidth;
8552
- } else {
8553
- var yScalar = width / state.videoWidth;
8554
- var scaledHeight = state.videoHeight * yScalar;
8555
- var yOffset = (scaledHeight - height) / 2;
8556
- top = obj.bbox[1] * scaledHeight - yOffset;
8557
- boxHeight = obj.bbox[3] * scaledHeight;
8558
- }
8559
- return /*#__PURE__*/React__default['default'].createElement("div", {
8751
+ return /*#__PURE__*/React__default['default'].createElement(IdCaptureDetectedObjectDebugBox, {
8560
8752
  key: i,
8561
- style: {
8562
- position: 'absolute',
8563
- left: left,
8564
- top: top,
8565
- width: boxWidth,
8566
- height: boxHeight,
8567
- border: '3px solid green',
8568
- font: '10px monospace',
8569
- color: 'green',
8570
- transform: ((_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.isRearFacing) ? '' : 'scaleX(-1)'
8571
- }
8572
- }, obj.label, " (", obj.score.toFixed(3), ")");
8573
- })), debugMode && /*#__PURE__*/React__default['default'].createElement("span", {
8574
- style: {
8575
- fontSize: 16,
8576
- fontFamily: 'monospace',
8577
- position: 'absolute',
8578
- left: 20,
8579
- bottom: 20,
8580
- color: 'limegreen',
8581
- background: 'rgba(0,0,0,0.5)',
8582
- zIndex: 1001
8583
- }
8584
- }, cameraRef.current ? /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, "\u2705 Camera: ", (_e = cameraRef.current) === null || _e === void 0 ? void 0 : _e.width, "x", (_f = cameraRef.current) === null || _f === void 0 ? void 0 : _f.height) : '❌ Camera not ready', /*#__PURE__*/React__default['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['default'].createElement("br", null), modelsReady ? /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, state.documentDetectionThresholdMet ? '✅' : '❌', " Document Score: ", state.documentDetectionScore, " (", state.documentType, ")", /*#__PURE__*/React__default['default'].createElement("br", null), state.documentInBounds ? '✅' : '❌', " Document In Bounds", /*#__PURE__*/React__default['default'].createElement("br", null), state.focusThresholdMet ? '✅' : '❌', " Focus Score:", ' ', state.focusScore, /*#__PURE__*/React__default['default'].createElement("br", null), state.goodFramesThresholdMet ? '✅' : '❌', " Good Frame Count:", ' ', state.goodFramesCount, "/", state.goodFramesThreshold, barcodeScanningEnabled && state.autoCaptureBarcodeRequired ? /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, /*#__PURE__*/React__default['default'].createElement("br", null), state.barcodeResult ? '✅' : '❌', " Barcode Scanned (", supportsNativeBarcodeScanning() ? 'Native' : 'ZXing', ",", ' ', state.barcodeScanFailedAttempts, "/", state.maxBarcodeScanAttempts, " failed attempts)") : null) : /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, "\u274C Models not ready")));
8753
+ obj: obj,
8754
+ scaling: debugScalingDetails,
8755
+ flipX: !((_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.isRearFacing)
8756
+ });
8757
+ })), debugMode && /*#__PURE__*/React__default['default'].createElement(DebugStatsPane, null, cameraRef.current ? /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, "\u2705 Camera: ", (_e = cameraRef.current) === null || _e === void 0 ? void 0 : _e.width, "x", (_f = cameraRef.current) === null || _f === void 0 ? void 0 : _f.height) : '❌ Camera not ready', /*#__PURE__*/React__default['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['default'].createElement("br", null), modelsReady ? /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, state.documentDetectionThresholdMet ? '✅' : '❌', " Document Score: ", state.documentDetectionScore, " (", state.documentType, ")", /*#__PURE__*/React__default['default'].createElement("br", null), state.documentInBounds ? '✅' : '❌', " Document In Bounds", /*#__PURE__*/React__default['default'].createElement("br", null), state.focusThresholdMet ? '✅' : '❌', " Focus Score:", ' ', state.focusScore, /*#__PURE__*/React__default['default'].createElement("br", null), state.goodFramesThresholdMet ? '✅' : '❌', " Good Frame Count:", ' ', state.goodFramesCount, "/", state.goodFramesThreshold, barcodeScanningEnabled && state.autoCaptureBarcodeRequired ? /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, /*#__PURE__*/React__default['default'].createElement("br", null), state.barcodeResult ? '✅' : '❌', " Barcode Scanned (", supportsNativeBarcodeScanning() ? 'Native' : 'ZXing', ",", ' ', state.barcodeScanFailedAttempts, "/", state.maxBarcodeScanAttempts, " failed attempts)") : null) : /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, "\u274C Models not ready")));
8585
8758
  };
8586
8759
  var timeSince = function timeSince(t) {
8587
8760
  if (!t) return 0;
@@ -9079,10 +9252,10 @@ var CameraVideoTag = function CameraVideoTag() {
9079
9252
  "$isRearFacing": (_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.isRearFacing
9080
9253
  });
9081
9254
  };
9082
- var FullscreenVideoTag = styled__default['default'].video(templateObject_1$2 || (templateObject_1$2 = tslib.__makeTemplateObject(["\n transform: ", ";\n min-width: 100%;\n min-height: 100%;\n width: auto;\n height: auto;\n object-fit: cover;\n"], ["\n transform: ", ";\n min-width: 100%;\n min-height: 100%;\n width: auto;\n height: auto;\n object-fit: cover;\n"])), function (props) {
9255
+ var FullscreenVideoTag = styled__default['default'].video(templateObject_1$3 || (templateObject_1$3 = tslib.__makeTemplateObject(["\n transform: ", ";\n min-width: 100%;\n min-height: 100%;\n width: auto;\n height: auto;\n object-fit: cover;\n"], ["\n transform: ", ";\n min-width: 100%;\n min-height: 100%;\n width: auto;\n height: auto;\n object-fit: cover;\n"])), function (props) {
9083
9256
  return props.$isRearFacing ? '' : 'scaleX(-1)';
9084
9257
  });
9085
- var templateObject_1$2;
9258
+ var templateObject_1$3;
9086
9259
 
9087
9260
  var CaptureState;
9088
9261
  (function (CaptureState) {
@@ -9749,11 +9922,6 @@ var reducer$3 = function reducer(state, action) {
9749
9922
  var isMobile = state.videoWidth < state.videoHeight;
9750
9923
  var tooCloseMultiple = isMobile ? 2 : 4.5;
9751
9924
  var tooFarMultiple = isMobile ? 6 : 7;
9752
- console.log({
9753
- faceBoxWidth: face.box.width,
9754
- videoWidth: state.videoWidth,
9755
- tooCloseMultiple: tooCloseMultiple
9756
- });
9757
9925
  faceTooClose = face.box.width > state.videoWidth / tooCloseMultiple;
9758
9926
  faceTooFar = face.box.width < state.videoWidth / tooFarMultiple;
9759
9927
  }
@@ -9891,6 +10059,13 @@ var SelfieCapture = function SelfieCapture(_a) {
9891
10059
  React.useEffect(function () {
9892
10060
  if (timedOut) onTimeout === null || onTimeout === void 0 ? void 0 : onTimeout();
9893
10061
  }, [onTimeout, timedOut]);
10062
+ var debugScalingDetails = useDebugScalingDetails({
10063
+ enabled: debugMode,
10064
+ pageWidth: width,
10065
+ pageHeight: height,
10066
+ videoWidth: state.videoWidth,
10067
+ videoHeight: state.videoHeight
10068
+ });
9894
10069
  if (!guidanceMessage) {
9895
10070
  verbiage.guidanceHoldStillText = verbiage.guidanceHoldStillText || t('Hold still for a few seconds...');
9896
10071
  verbiage.guidanceLookStraightText = verbiage.guidanceLookStraightText || t('Look straight into the camera...');
@@ -9921,100 +10096,18 @@ var SelfieCapture = function SelfieCapture(_a) {
9921
10096
  padding: '10px 12px 8px',
9922
10097
  borderRadius: 8
9923
10098
  }
9924
- }, guidanceMessage)), debugMode && state.faces.length > 0 && /*#__PURE__*/React__default['default'].createElement("div", {
9925
- style: {
9926
- position: 'absolute',
9927
- zIndex: 1001,
9928
- width: '100%',
9929
- height: '100%',
9930
- maxWidth: '100%',
9931
- maxHeight: '100%',
9932
- transform: ((_b = cameraRef.current) === null || _b === void 0 ? void 0 : _b.isRearFacing) ? '' : 'scaleX(-1)',
9933
- overflow: 'hidden'
9934
- }
10099
+ }, guidanceMessage)), debugMode && state.faces.length > 0 && /*#__PURE__*/React__default['default'].createElement(ObjectDetectionDebugOverlay, {
10100
+ "$flipX": !((_b = cameraRef.current) === null || _b === void 0 ? void 0 : _b.isRearFacing)
9935
10101
  }, state.faces.map(function (face, i) {
9936
10102
  var _a;
9937
- var wrapperAspectRatio = width / height;
9938
- var videoAspectRatio = state.videoWidth / state.videoHeight;
9939
- var left = face.box.xMin / state.videoWidth;
9940
- var top = face.box.yMin / state.videoHeight;
9941
- var boxWidth = face.box.width / state.videoWidth;
9942
- var boxHeight = face.box.height / state.videoHeight;
9943
- if (wrapperAspectRatio < videoAspectRatio) {
9944
- var xScalar = height / state.videoHeight;
9945
- var scaledWidth = state.videoWidth * xScalar;
9946
- var xOffset = (scaledWidth - width) / 2;
9947
- left = left * scaledWidth - xOffset;
9948
- top *= height;
9949
- boxWidth *= scaledWidth;
9950
- boxHeight *= height;
9951
- } else {
9952
- var yScalar = width / state.videoWidth;
9953
- var scaledHeight = state.videoHeight * yScalar;
9954
- var yOffset = (scaledHeight - height) / 2;
9955
- left *= width;
9956
- top = top * scaledHeight - yOffset;
9957
- boxWidth *= width;
9958
- boxHeight *= scaledHeight;
9959
- }
9960
- return /*#__PURE__*/React__default['default'].createElement("div", {
9961
- key: i
9962
- }, /*#__PURE__*/React__default['default'].createElement("div", {
9963
- style: {
9964
- position: 'absolute',
9965
- left: left,
9966
- top: top,
9967
- width: boxWidth,
9968
- height: boxHeight,
9969
- border: "3px solid ".concat(state.faceReady ? 'green' : 'red'),
9970
- font: '10px monospace',
9971
- transform: ((_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.isRearFacing) ? '' : 'scaleX(-1)'
9972
- }
9973
- }), face.keypoints.map(function (point, ii) {
9974
- var _a;
9975
- var left = point.x / state.videoWidth;
9976
- var top = point.y / state.videoHeight;
9977
- if (wrapperAspectRatio < videoAspectRatio) {
9978
- var xScalar = height / state.videoHeight;
9979
- var scaledWidth = state.videoWidth * xScalar;
9980
- var xOffset = (scaledWidth - width) / 2;
9981
- left = left * scaledWidth - xOffset;
9982
- top *= height;
9983
- } else {
9984
- var yScalar = width / state.videoWidth;
9985
- var scaledHeight = state.videoHeight * yScalar;
9986
- var yOffset = (scaledHeight - height) / 2;
9987
- left *= width;
9988
- top = top * scaledHeight - yOffset;
9989
- }
9990
- return /*#__PURE__*/React__default['default'].createElement("div", {
9991
- key: ii,
9992
- style: {
9993
- position: 'absolute',
9994
- left: left - 2,
9995
- top: top - 2,
9996
- width: 4,
9997
- height: 4,
9998
- border: '2px solid red',
9999
- font: '10px monospace',
10000
- color: 'green',
10001
- transform: ((_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.isRearFacing) ? '' : 'scaleX(-1)',
10002
- borderRadius: '50%'
10003
- }
10004
- }, ii);
10005
- }));
10006
- })), debugMode && /*#__PURE__*/React__default['default'].createElement("span", {
10007
- style: {
10008
- fontSize: 16,
10009
- fontFamily: 'monospace',
10010
- position: 'absolute',
10011
- left: 20,
10012
- bottom: 20,
10013
- color: 'limegreen',
10014
- background: 'rgba(0,0,0,0.5)',
10015
- zIndex: 1001
10016
- }
10017
- }, cameraRef.current ? /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, "\u2705 Camera: ", (_c = cameraRef.current) === null || _c === void 0 ? void 0 : _c.width, "x", (_d = cameraRef.current) === null || _d === void 0 ? void 0 : _d.height) : '❌ Camera not ready', /*#__PURE__*/React__default['default'].createElement("br", null), !state.faceNotCentered ? '✅' : '❌', " Face Centered", /*#__PURE__*/React__default['default'].createElement("br", null), !state.faceTooClose && !state.faceTooFar ? '✅' : '❌', " Face", ' ', state.faceTooClose ? 'Too Close' : state.faceTooFar ? 'Too Far' : 'Distance Correct', /*#__PURE__*/React__default['default'].createElement("br", null), !state.faceLookingAway ? '✅' : '❌', " Face Looking Forward", /*#__PURE__*/React__default['default'].createElement("br", null), state.goodFramesThresholdMet ? '✅' : '❌', " ", state.goodFramesCount, ' ', "Good Frames", /*#__PURE__*/React__default['default'].createElement("br", null), !timedOut ? '✅' : '❌', " Time Remaining:", ' ', Math.max(0, timeoutDurationMs - (new Date().getTime() - (timeoutStartedAt !== null && timeoutStartedAt !== void 0 ? timeoutStartedAt : new Date()).getTime())), "ms"));
10103
+ return /*#__PURE__*/React__default['default'].createElement(SelfieCaptureFaceDebugBox, {
10104
+ key: i,
10105
+ face: face,
10106
+ scaling: debugScalingDetails,
10107
+ flipX: !((_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.isRearFacing),
10108
+ color: state.faceReady ? 'green' : 'red'
10109
+ });
10110
+ })), debugMode && /*#__PURE__*/React__default['default'].createElement(DebugStatsPane, null, cameraRef.current ? /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, "\u2705 Camera: ", (_c = cameraRef.current) === null || _c === void 0 ? void 0 : _c.width, "x", (_d = cameraRef.current) === null || _d === void 0 ? void 0 : _d.height) : '❌ Camera not ready', /*#__PURE__*/React__default['default'].createElement("br", null), !state.faceNotCentered ? '✅' : '❌', " Face Centered", /*#__PURE__*/React__default['default'].createElement("br", null), !state.faceTooClose && !state.faceTooFar ? '✅' : '❌', " Face", ' ', state.faceTooClose ? 'Too Close' : state.faceTooFar ? 'Too Far' : 'Distance Correct', /*#__PURE__*/React__default['default'].createElement("br", null), !state.faceLookingAway ? '✅' : '❌', " Face Looking Forward", /*#__PURE__*/React__default['default'].createElement("br", null), state.goodFramesThresholdMet ? '✅' : '❌', " ", state.goodFramesCount, ' ', "Good Frames", /*#__PURE__*/React__default['default'].createElement("br", null), !timedOut ? '✅' : '❌', " Time Remaining:", ' ', Math.max(0, timeoutDurationMs - (new Date().getTime() - (timeoutStartedAt !== null && timeoutStartedAt !== void 0 ? timeoutStartedAt : new Date()).getTime())), "ms"));
10018
10111
  };
10019
10112
 
10020
10113
  var initialState$2 = {
@@ -11087,8 +11180,8 @@ function truncate(str, max_chars) {
11087
11180
  return truncated;
11088
11181
  }
11089
11182
 
11090
- var Spinner = styled__default['default'].div(templateObject_1$1 || (templateObject_1$1 = tslib.__makeTemplateObject(["\n display: inline-block;\n width: 80px;\n height: 80px;\n margin: auto;\n\n &:after {\n content: ' ';\n display: block;\n width: 64px;\n height: 64px;\n margin: 8px;\n border-radius: 50%;\n border: 6px solid #888;\n border-color: #888 transparent #888 transparent;\n animation: lds-dual-ring 1.2s linear infinite;\n }\n\n @keyframes lds-dual-ring {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n }\n"], ["\n display: inline-block;\n width: 80px;\n height: 80px;\n margin: auto;\n\n &:after {\n content: ' ';\n display: block;\n width: 64px;\n height: 64px;\n margin: 8px;\n border-radius: 50%;\n border: 6px solid #888;\n border-color: #888 transparent #888 transparent;\n animation: lds-dual-ring 1.2s linear infinite;\n }\n\n @keyframes lds-dual-ring {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n }\n"])));
11091
- var templateObject_1$1;
11183
+ var Spinner = styled__default['default'].div(templateObject_1$2 || (templateObject_1$2 = tslib.__makeTemplateObject(["\n display: inline-block;\n width: 80px;\n height: 80px;\n margin: auto;\n\n &:after {\n content: ' ';\n display: block;\n width: 64px;\n height: 64px;\n margin: 8px;\n border-radius: 50%;\n border: 6px solid #888;\n border-color: #888 transparent #888 transparent;\n animation: lds-dual-ring 1.2s linear infinite;\n }\n\n @keyframes lds-dual-ring {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n }\n"], ["\n display: inline-block;\n width: 80px;\n height: 80px;\n margin: auto;\n\n &:after {\n content: ' ';\n display: block;\n width: 64px;\n height: 64px;\n margin: 8px;\n border-radius: 50%;\n border: 6px solid #888;\n border-color: #888 transparent #888 transparent;\n animation: lds-dual-ring 1.2s linear infinite;\n }\n\n @keyframes lds-dual-ring {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n }\n"])));
11184
+ var templateObject_1$2;
11092
11185
 
11093
11186
  var AdditionalDocumentCapture = function AdditionalDocumentCapture(_a) {
11094
11187
  var document = _a.document,
@@ -11234,55 +11327,43 @@ function signatureDataToIdmissionFormat(signatureCanvas) {
11234
11327
  return signatureData;
11235
11328
  }
11236
11329
 
11330
+ var SignatureCanvasContainer = styled__default['default'].div(templateObject_1$1 || (templateObject_1$1 = tslib.__makeTemplateObject(["\n position: absolute;\n top: 25%;\n left: 15%;\n width: 70%;\n height: 50%;\n\n @media (max-width: 800px) {\n top: 15%;\n left: 2%;\n width: 96%;\n height: 70%;\n }\n"], ["\n position: absolute;\n top: 25%;\n left: 15%;\n width: 70%;\n height: 50%;\n\n @media (max-width: 800px) {\n top: 15%;\n left: 2%;\n width: 96%;\n height: 70%;\n }\n"])));
11331
+ var SignaturePad = styled__default['default'].div(templateObject_2$1 || (templateObject_2$1 = tslib.__makeTemplateObject(["\n position: relative;\n background: rgba(255, 255, 255, 0.5);\n border-radius: 16px;\n flex-grow: 1;\n z-index: 100;\n height: 100%;\n"], ["\n position: relative;\n background: rgba(255, 255, 255, 0.5);\n border-radius: 16px;\n flex-grow: 1;\n z-index: 100;\n height: 100%;\n"])));
11332
+ var SignatureButtonsContainer = styled__default['default'].div(templateObject_3 || (templateObject_3 = tslib.__makeTemplateObject(["\n flex-grow: 0;\n padding-top: 12px;\n display: flex;\n z-index: 1000;\n position: relative;\n"], ["\n flex-grow: 0;\n padding-top: 12px;\n display: flex;\n z-index: 1000;\n position: relative;\n"])));
11333
+ var SignaturePaperBacking = styled__default['default'].div(templateObject_4 || (templateObject_4 = tslib.__makeTemplateObject(["\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: column;\n background-color: #e5e5f7;\n opacity: 0.8;\n background-image: radial-gradient(#444cf7 0.5px, transparent 0.5px),\n radial-gradient(#444cf7 0.5px, #e5e5f7 0.5px);\n background-size: 20px 20px;\n background-position: 0 0, 10px 10px;\n"], ["\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: column;\n background-color: #e5e5f7;\n opacity: 0.8;\n background-image: radial-gradient(#444cf7 0.5px, transparent 0.5px),\n radial-gradient(#444cf7 0.5px, #e5e5f7 0.5px);\n background-size: 20px 20px;\n background-position: 0 0, 10px 10px;\n"])));
11334
+ var templateObject_1$1, templateObject_2$1, templateObject_3, templateObject_4;
11335
+
11336
+ var GuidanceMessageContainer = styled__default['default'].div(templateObject_1 || (templateObject_1 = tslib.__makeTemplateObject(["\n position: absolute;\n top: calc(", ");\n font-weight: bold;\n width: 100%;\n display: flex;\n"], ["\n position: absolute;\n top: calc(", ");\n font-weight: bold;\n width: 100%;\n display: flex;\n"])), function (_a) {
11337
+ var $top = _a.$top;
11338
+ return $top !== null && $top !== void 0 ? $top : '10vh';
11339
+ });
11340
+ var GuidanceMessage = styled__default['default'].div(templateObject_2 || (templateObject_2 = tslib.__makeTemplateObject(["\n margin-left: auto;\n margin-right: auto;\n background: #ccc;\n padding: 10px 12px 8px;\n border-radius: 8px;\n"], ["\n margin-left: auto;\n margin-right: auto;\n background: #ccc;\n padding: 10px 12px 8px;\n border-radius: 8px;\n"])));
11341
+ var templateObject_1, templateObject_2;
11342
+
11237
11343
  var SignatureCapture = function SignatureCapture(_a) {
11238
11344
  var onAccept = _a.onAccept,
11239
- _b = _a.background,
11240
- background = _b === void 0 ? 'white' : _b,
11241
- _c = _a.verbiage,
11242
- verbiage = _c === void 0 ? {} : _c;
11345
+ _b = _a.verbiage,
11346
+ verbiage = _b === void 0 ? {} : _b;
11243
11347
  var t = reactI18next.useTranslation().t;
11244
- var _d = useResizeObserver__default['default'](),
11245
- ref = _d.ref,
11246
- width = _d.width,
11247
- height = _d.height;
11348
+ var _c = useResizeObserver__default['default'](),
11349
+ ref = _c.ref,
11350
+ width = _c.width,
11351
+ height = _c.height;
11248
11352
  var signaturePad = React.useRef(null);
11249
11353
  verbiage.headingText = verbiage.headingText || t('Please sign the box below');
11250
11354
  verbiage.acceptBtnText = verbiage.acceptBtnText || t('Accept');
11251
11355
  verbiage.clearBtnText = verbiage.clearBtnText || t('Clear');
11252
- return /*#__PURE__*/React__default['default'].createElement(OverlayContainer, {
11253
- style: {
11254
- background: background
11255
- }
11256
- }, /*#__PURE__*/React__default['default'].createElement(OverlayInner, null, /*#__PURE__*/React__default['default'].createElement("div", {
11257
- style: {
11258
- flexGrow: 0,
11259
- paddingBottom: 12
11260
- }
11261
- }, /*#__PURE__*/React__default['default'].createElement("h3", {
11262
- style: {
11263
- margin: 0
11264
- }
11265
- }, verbiage.headingText)), /*#__PURE__*/React__default['default'].createElement("div", {
11266
- ref: ref,
11267
- style: {
11268
- position: 'relative',
11269
- border: '3px solid #888',
11270
- flexGrow: 1,
11271
- zIndex: '100'
11272
- }
11356
+ return /*#__PURE__*/React__default['default'].createElement(PageContainer, null, /*#__PURE__*/React__default['default'].createElement(SignaturePaperBacking, null, /*#__PURE__*/React__default['default'].createElement(GuidanceMessageContainer, {
11357
+ "$top": "5vh"
11358
+ }, /*#__PURE__*/React__default['default'].createElement(GuidanceMessage, null, verbiage.headingText)), /*#__PURE__*/React__default['default'].createElement(SignatureCanvasContainer, null, /*#__PURE__*/React__default['default'].createElement(SignaturePad, {
11359
+ ref: ref
11273
11360
  }, /*#__PURE__*/React__default['default'].createElement(SignatureCanvas__default['default'], {
11274
11361
  ref: signaturePad,
11275
11362
  canvasProps: {
11276
11363
  width: width,
11277
- height: (height !== null && height !== void 0 ? height : 500) - 4
11278
- }
11279
- })), /*#__PURE__*/React__default['default'].createElement("div", {
11280
- style: {
11281
- flexGrow: 0,
11282
- paddingTop: 12,
11283
- display: 'flex'
11364
+ height: height
11284
11365
  }
11285
- }, /*#__PURE__*/React__default['default'].createElement("button", {
11366
+ })), /*#__PURE__*/React__default['default'].createElement(SignatureButtonsContainer, null, /*#__PURE__*/React__default['default'].createElement("button", {
11286
11367
  onClick: function onClick(e) {
11287
11368
  var _a;
11288
11369
  e.preventDefault();
@@ -11298,7 +11379,7 @@ var SignatureCapture = function SignatureCapture(_a) {
11298
11379
  var signatureData = signatureDataToIdmissionFormat(signaturePad.current);
11299
11380
  onAccept === null || onAccept === void 0 ? void 0 : onAccept(signatureData, signaturePad.current.toDataURL());
11300
11381
  }
11301
- }, verbiage.acceptBtnText))));
11382
+ }, verbiage.acceptBtnText)))));
11302
11383
  };
11303
11384
 
11304
11385
  var useVideoRecorder = function useVideoRecorder(camera) {
@@ -11342,7 +11423,6 @@ var useVideoRecorder = function useVideoRecorder(camera) {
11342
11423
  };
11343
11424
  };
11344
11425
 
11345
- var SignatureCanvasContainer = styled__default['default'].div(templateObject_1 || (templateObject_1 = tslib.__makeTemplateObject(["\n position: absolute;\n top: 25%;\n left: 15%;\n width: 70%;\n height: 50%;\n\n @media (max-width: 800px) {\n top: 15%;\n left: 2%;\n width: 96%;\n height: 70%;\n }\n"], ["\n position: absolute;\n top: 25%;\n left: 15%;\n width: 70%;\n height: 50%;\n\n @media (max-width: 800px) {\n top: 15%;\n left: 2%;\n width: 96%;\n height: 70%;\n }\n"])));
11346
11426
  var VideoSignatureCapture = function VideoSignatureCapture(_a) {
11347
11427
  var _b, _c;
11348
11428
  var onComplete = _a.onComplete,
@@ -11485,47 +11565,17 @@ var VideoSignatureCapture = function VideoSignatureCapture(_a) {
11485
11565
  var guidanceMessage = t('Please sign the box below');
11486
11566
  return /*#__PURE__*/React__default['default'].createElement(PageContainer, {
11487
11567
  className: "flex"
11488
- }, /*#__PURE__*/React__default['default'].createElement(CameraVideoTag, null), guidanceMessage !== '' && /*#__PURE__*/React__default['default'].createElement("div", {
11489
- style: {
11490
- position: 'absolute',
11491
- top: 'calc(5vh)',
11492
- fontWeight: 'bold',
11493
- width: '100%',
11494
- display: 'flex'
11495
- }
11496
- }, /*#__PURE__*/React__default['default'].createElement("div", {
11497
- style: {
11498
- marginLeft: 'auto',
11499
- marginRight: 'auto',
11500
- background: '#ccc',
11501
- padding: '10px 12px 8px',
11502
- borderRadius: 8
11503
- }
11504
- }, guidanceMessage)), /*#__PURE__*/React__default['default'].createElement(SignatureCanvasContainer, null, /*#__PURE__*/React__default['default'].createElement("div", {
11505
- ref: ref,
11506
- style: {
11507
- position: 'relative',
11508
- background: 'rgba(255,255,255,0.5)',
11509
- borderRadius: 16,
11510
- flexGrow: 1,
11511
- zIndex: '100',
11512
- height: '100%'
11513
- }
11568
+ }, /*#__PURE__*/React__default['default'].createElement(CameraVideoTag, null), guidanceMessage !== '' && /*#__PURE__*/React__default['default'].createElement(GuidanceMessageContainer, {
11569
+ "$top": "5vh"
11570
+ }, /*#__PURE__*/React__default['default'].createElement(GuidanceMessage, null, guidanceMessage)), /*#__PURE__*/React__default['default'].createElement(SignatureCanvasContainer, null, /*#__PURE__*/React__default['default'].createElement(SignaturePad, {
11571
+ ref: ref
11514
11572
  }, /*#__PURE__*/React__default['default'].createElement(SignatureCanvas__default['default'], {
11515
11573
  ref: signaturePad,
11516
11574
  canvasProps: {
11517
11575
  width: width,
11518
11576
  height: height
11519
11577
  }
11520
- })), /*#__PURE__*/React__default['default'].createElement("div", {
11521
- style: {
11522
- flexGrow: 0,
11523
- paddingTop: 12,
11524
- display: 'flex',
11525
- zIndex: 1000,
11526
- position: 'relative'
11527
- }
11528
- }, /*#__PURE__*/React__default['default'].createElement("button", {
11578
+ })), /*#__PURE__*/React__default['default'].createElement(SignatureButtonsContainer, null, /*#__PURE__*/React__default['default'].createElement("button", {
11529
11579
  onClick: function onClick(e) {
11530
11580
  var _a;
11531
11581
  e.preventDefault();
@@ -11557,7 +11607,6 @@ var VideoSignatureCapture = function VideoSignatureCapture(_a) {
11557
11607
  }
11558
11608
  })));
11559
11609
  };
11560
- var templateObject_1;
11561
11610
 
11562
11611
  var SignatureKYCLoadingOverlay = function SignatureKYCLoadingOverlay(_a) {
11563
11612
  var headingText = _a.headingText,