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.
@@ -3212,7 +3212,7 @@
3212
3212
  return (_b = (_a = url.match(/^(data:.*;base64),/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : '';
3213
3213
  }
3214
3214
 
3215
- var PageContainerDiv = styled__default['default'].div(templateObject_1$4 || (templateObject_1$4 = __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) {
3215
+ var PageContainerDiv = styled__default['default'].div(templateObject_1$7 || (templateObject_1$7 = __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) {
3216
3216
  var $heightOffset = _a.$heightOffset;
3217
3217
  return $heightOffset !== null && $heightOffset !== void 0 ? $heightOffset : 0;
3218
3218
  });
@@ -3244,13 +3244,13 @@
3244
3244
  }, children);
3245
3245
  });
3246
3246
  PageContainer.displayName = 'PageContainer';
3247
- var templateObject_1$4;
3247
+ var templateObject_1$7;
3248
3248
 
3249
- var OverlayContainer = styled__default['default'](PageContainer)(templateObject_1$3 || (templateObject_1$3 = __makeTemplateObject(["\n background: white;\n z-index: 10000;\n"], ["\n background: white;\n z-index: 10000;\n"])));
3250
- var OverlayInner = styled__default['default'].div(templateObject_2 || (templateObject_2 = __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"])));
3251
- var OverlayImageWrapper = styled__default['default'].div(templateObject_3 || (templateObject_3 = __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"])));
3252
- var OverlayImageMultiContainer = styled__default['default'].div(templateObject_4 || (templateObject_4 = __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"])));
3253
- var templateObject_1$3, templateObject_2, templateObject_3, templateObject_4;
3249
+ var OverlayContainer = styled__default['default'](PageContainer)(templateObject_1$6 || (templateObject_1$6 = __makeTemplateObject(["\n background: white;\n z-index: 10000;\n"], ["\n background: white;\n z-index: 10000;\n"])));
3250
+ var OverlayInner = styled__default['default'].div(templateObject_2$3 || (templateObject_2$3 = __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"])));
3251
+ var OverlayImageWrapper = styled__default['default'].div(templateObject_3$2 || (templateObject_3$2 = __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"])));
3252
+ var OverlayImageMultiContainer = styled__default['default'].div(templateObject_4$2 || (templateObject_4$2 = __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"])));
3253
+ var templateObject_1$6, templateObject_2$3, templateObject_3$2, templateObject_4$2;
3254
3254
 
3255
3255
  var __assign = (undefined && undefined.__assign) || function () {
3256
3256
  __assign = Object.assign || function(t) {
@@ -11261,16 +11261,8 @@
11261
11261
  working: {
11262
11262
  current: false
11263
11263
  },
11264
- documentDetectionThreshold: 1,
11265
- setDocumentDetectionThreshold: function setDocumentDetectionThreshold() {
11266
- return null;
11267
- },
11268
- passportDetectionThreshold: 1,
11269
- setPassportDetectionThreshold: function setPassportDetectionThreshold() {
11270
- return null;
11271
- },
11272
- focusThreshold: 1,
11273
- setFocusThreshold: function setFocusThreshold() {
11264
+ thresholds: {},
11265
+ setThresholds: function setThresholds() {
11274
11266
  return null;
11275
11267
  },
11276
11268
  makePrediction: function makePrediction() {
@@ -11288,6 +11280,8 @@
11288
11280
  return null;
11289
11281
  }
11290
11282
  });
11283
+ var defaultDocumentDetectionModelUrl = "".concat(DEFAULT_CDN_URL, "/models/documentdetection448/model.json");
11284
+ var defaultFocusModelUrl = "".concat(DEFAULT_CDN_URL, "/models/focus/model.json");
11291
11285
  var IdCaptureModelsProvider = function IdCaptureModelsProvider(_a) {
11292
11286
  var children = _a.children,
11293
11287
  documentDetectionModelUrl = _a.documentDetectionModelUrl,
@@ -11295,35 +11289,39 @@
11295
11289
  var _b = React.useState(false),
11296
11290
  ready = _b[0],
11297
11291
  setReady = _b[1];
11298
- var _c = React.useState(1),
11292
+ var _c = React.useState(0),
11299
11293
  documentDetectionThreshold = _c[0],
11300
11294
  setDocumentDetectionThreshold = _c[1];
11301
- var _d = React.useState(1),
11295
+ var _d = React.useState(0),
11302
11296
  passportDetectionThreshold = _d[0],
11303
11297
  setPassportDetectionThreshold = _d[1];
11304
- var _e = React.useState(1),
11305
- focusThreshold = _e[0],
11306
- setFocusThreshold = _e[1];
11307
- var working = React.useRef(false);
11308
- var onPredictionHandler = React.useRef();
11309
- var canvas2d = React.useRef(null);
11310
- var canvasGl = React.useRef(null);
11298
+ var _e = React.useState(0),
11299
+ mrzDetectionThreshold = _e[0],
11300
+ setMrzDetectionThreshold = _e[1];
11311
11301
  var _f = React.useState(0),
11312
- detectionTime = _f[0],
11313
- setDetectionTime = _f[1];
11302
+ pdf417DetectionThreshold = _f[0],
11303
+ setPdf417DetectionThreshold = _f[1];
11314
11304
  var _g = React.useState(0),
11315
- focusPredictionTime = _g[0],
11316
- setFocusPredictionTime = _g[1];
11317
- documentDetectionModelUrl = documentDetectionModelUrl || "".concat(DEFAULT_CDN_URL, "/models/documentdetection448/model.json");
11318
- focusModelUrl = focusModelUrl || "".concat(DEFAULT_CDN_URL, "/models/focus/model.json");
11305
+ focusThreshold = _g[0],
11306
+ setFocusThreshold = _g[1];
11307
+ var working = React.useRef(false);
11308
+ var onPredictionHandler = React.useRef();
11309
+ var lastPredictionCanvas = React.useRef(null);
11310
+ var _h = React.useState(0),
11311
+ detectionTime = _h[0],
11312
+ setDetectionTime = _h[1];
11313
+ var _j = React.useState(0),
11314
+ focusPredictionTime = _j[0],
11315
+ setFocusPredictionTime = _j[1];
11319
11316
  React.useEffect(function () {
11320
- (function () {
11321
- return __awaiter(void 0, void 0, void 0, function () {
11317
+ setReady(false);
11318
+ var ddmUrl = documentDetectionModelUrl || defaultDocumentDetectionModelUrl;
11319
+ var fmUrl = focusModelUrl || defaultFocusModelUrl;
11320
+ function loadModels() {
11321
+ return __awaiter(this, void 0, void 0, function () {
11322
11322
  return __generator(this, function (_a) {
11323
11323
  switch (_a.label) {
11324
11324
  case 0:
11325
- if (!documentDetectionModelUrl || !focusModelUrl) return [2];
11326
- setReady(false);
11327
11325
  tf__namespace.ENV.set('WEBGL_DELETE_TEXTURE_THRESHOLD', 50 * 1024 * 1024);
11328
11326
  return [4, tf__namespace.setBackend('webgl')];
11329
11327
  case 1:
@@ -11331,54 +11329,67 @@
11331
11329
  return [4, tf__namespace.ready()];
11332
11330
  case 2:
11333
11331
  _a.sent();
11334
- return [4, Promise.all([loadDocumentDetectionModel(documentDetectionModelUrl), loadFocusModel(focusModelUrl)])];
11332
+ return [4, Promise.all([loadDocumentDetectionModel(ddmUrl), loadFocusModel(fmUrl)])];
11335
11333
  case 3:
11336
11334
  _a.sent();
11337
- getWebGLContext(2).canvas.addEventListener('webglcontextlost', function () {
11338
- return __awaiter(void 0, void 0, void 0, function () {
11339
- var newCtx;
11340
- var _a;
11341
- return __generator(this, function (_b) {
11342
- switch (_b.label) {
11343
- case 0:
11344
- setReady(false);
11345
- unloadDocumentDetectionModel();
11346
- unloadFocusModel();
11347
- clearWebGLContext(2);
11348
- newCtx = (_a = canvasGl.current) === null || _a === void 0 ? void 0 : _a.getContext('webgl2');
11349
- if (!(newCtx && documentDetectionModelUrl && focusModelUrl)) return [3, 4];
11350
- tf.setWebGLContext(2, newCtx);
11351
- try {
11352
- tf__namespace.backend().dispose();
11353
- } catch (e) {
11354
- console.error('failed to dispose backend');
11355
- }
11356
- return [4, tf__namespace.setBackend('webgl')];
11357
- case 1:
11358
- _b.sent();
11359
- return [4, tf__namespace.ready()];
11360
- case 2:
11361
- _b.sent();
11362
- return [4, Promise.all([loadDocumentDetectionModel(documentDetectionModelUrl), loadFocusModel(focusModelUrl)])];
11363
- case 3:
11364
- _b.sent();
11365
- setReady(true);
11366
- _b.label = 4;
11367
- case 4:
11368
- return [2];
11369
- }
11370
- });
11371
- });
11372
- });
11335
+ return [2];
11336
+ }
11337
+ });
11338
+ });
11339
+ }
11340
+ function reloadModels() {
11341
+ return __awaiter(this, void 0, void 0, function () {
11342
+ var ctx;
11343
+ return __generator(this, function (_a) {
11344
+ switch (_a.label) {
11345
+ case 0:
11346
+ setReady(false);
11347
+ unloadDocumentDetectionModel();
11348
+ unloadFocusModel();
11349
+ clearWebGLContext(2);
11350
+ ctx = document.createElement('canvas').getContext('webgl2');
11351
+ if (!(ctx && ddmUrl && fmUrl)) return [3, 2];
11352
+ tf.setWebGLContext(2, ctx);
11353
+ disposeTfBackend();
11354
+ return [4, loadModels()];
11355
+ case 1:
11356
+ _a.sent();
11373
11357
  setReady(true);
11358
+ _a.label = 2;
11359
+ case 2:
11374
11360
  return [2];
11375
11361
  }
11376
11362
  });
11377
11363
  });
11378
- })();
11364
+ }
11365
+ loadModels().then(function () {
11366
+ setReady(true);
11367
+ });
11368
+ var webGLCanvas = getWebGLContext(2).canvas;
11369
+ webGLCanvas.addEventListener('webglcontextlost', reloadModels);
11370
+ return function () {
11371
+ var _a;
11372
+ (_a = webGLCanvas.removeEventListener) === null || _a === void 0 ? void 0 : _a.call(webGLCanvas, 'webglcontextlost', reloadModels);
11373
+ };
11379
11374
  }, [documentDetectionModelUrl, focusModelUrl]);
11375
+ var thresholds = React.useMemo(function () {
11376
+ return {
11377
+ document: documentDetectionThreshold,
11378
+ passport: passportDetectionThreshold,
11379
+ mrz: mrzDetectionThreshold,
11380
+ pdf417: pdf417DetectionThreshold,
11381
+ focus: focusThreshold
11382
+ };
11383
+ }, [documentDetectionThreshold, focusThreshold, mrzDetectionThreshold, passportDetectionThreshold, pdf417DetectionThreshold]);
11384
+ var setThresholds = React.useCallback(function (thresholds) {
11385
+ if (thresholds.document) setDocumentDetectionThreshold(thresholds.document);
11386
+ if (thresholds.passport) setPassportDetectionThreshold(thresholds.passport);
11387
+ if (thresholds.mrz) setMrzDetectionThreshold(thresholds.mrz);
11388
+ if (thresholds.pdf417) setPdf417DetectionThreshold(thresholds.pdf417);
11389
+ if (thresholds.focus) setFocusThreshold(thresholds.focus);
11390
+ }, []);
11380
11391
  var bestPredictionCanvas = React.useRef(null);
11381
- var bestPredictionScore = React.useRef(0);
11392
+ var bestFocusScore = React.useRef(0);
11382
11393
  var makePrediction = React.useCallback(function (frame) {
11383
11394
  working.current = true;
11384
11395
  (function () {
@@ -11388,14 +11399,14 @@
11388
11399
  return __generator(this, function (_b) {
11389
11400
  switch (_b.label) {
11390
11401
  case 0:
11391
- if (!documentDetectionModel || !focusModel || !canvas2d.current) return [2];
11392
- return [4, makePredictions(frame, canvas2d.current, documentDetectionThreshold, passportDetectionThreshold, focusThreshold)];
11402
+ if (!documentDetectionModel || !focusModel || !lastPredictionCanvas.current) return [2];
11403
+ return [4, makePredictions(frame, lastPredictionCanvas.current, thresholds)];
11393
11404
  case 1:
11394
11405
  prediction = _b.sent();
11395
11406
  setDetectionTime(prediction.detectionTime);
11396
11407
  setFocusPredictionTime(prediction.focusPredictionTime);
11397
- if (bestPredictionScore.current <= prediction.detectionScore) {
11398
- bestPredictionScore.current = prediction.detectionScore;
11408
+ if (bestFocusScore.current <= prediction.focusScore) {
11409
+ bestFocusScore.current = prediction.focusScore;
11399
11410
  drawToCanvas(bestPredictionCanvas.current, frame);
11400
11411
  }
11401
11412
  (_a = onPredictionHandler.current) === null || _a === void 0 ? void 0 : _a.call(onPredictionHandler, prediction);
@@ -11405,7 +11416,7 @@
11405
11416
  });
11406
11417
  });
11407
11418
  })();
11408
- }, [documentDetectionThreshold, focusThreshold, passportDetectionThreshold]);
11419
+ }, [thresholds]);
11409
11420
  var onPredictionMade = React.useCallback(function (handler) {
11410
11421
  onPredictionHandler.current = handler;
11411
11422
  }, []);
@@ -11428,54 +11439,45 @@
11428
11439
  });
11429
11440
  }, []);
11430
11441
  var resetBestFrame = React.useCallback(function () {
11431
- bestPredictionScore.current = 0;
11442
+ bestFocusScore.current = 0;
11432
11443
  clearCanvas(bestPredictionCanvas.current);
11433
11444
  }, []);
11434
- var value = {
11435
- ready: ready,
11436
- working: working,
11437
- documentDetectionThreshold: documentDetectionThreshold,
11438
- setDocumentDetectionThreshold: setDocumentDetectionThreshold,
11439
- passportDetectionThreshold: passportDetectionThreshold,
11440
- setPassportDetectionThreshold: setPassportDetectionThreshold,
11441
- focusThreshold: focusThreshold,
11442
- setFocusThreshold: setFocusThreshold,
11443
- makePrediction: makePrediction,
11444
- onPredictionMade: onPredictionMade,
11445
- detectionTime: detectionTime,
11446
- focusPredictionTime: focusPredictionTime,
11447
- getBestFrame: getBestFrame,
11448
- resetBestFrame: resetBestFrame
11449
- };
11445
+ var value = React.useMemo(function () {
11446
+ return {
11447
+ ready: ready,
11448
+ working: working,
11449
+ thresholds: thresholds,
11450
+ setThresholds: setThresholds,
11451
+ makePrediction: makePrediction,
11452
+ onPredictionMade: onPredictionMade,
11453
+ detectionTime: detectionTime,
11454
+ focusPredictionTime: focusPredictionTime,
11455
+ getBestFrame: getBestFrame,
11456
+ resetBestFrame: resetBestFrame
11457
+ };
11458
+ }, [detectionTime, focusPredictionTime, getBestFrame, makePrediction, onPredictionMade, ready, resetBestFrame, setThresholds, thresholds]);
11450
11459
  return /*#__PURE__*/React__default['default'].createElement(IdCaptureModelsContext.Provider, {
11451
11460
  value: value
11452
- }, children, /*#__PURE__*/React__default['default'].createElement("canvas", {
11453
- ref: canvas2d,
11454
- style: {
11455
- display: 'none'
11456
- }
11457
- }), /*#__PURE__*/React__default['default'].createElement("canvas", {
11458
- ref: canvasGl,
11459
- style: {
11460
- display: 'none'
11461
- }
11462
- }), /*#__PURE__*/React__default['default'].createElement("canvas", {
11463
- ref: bestPredictionCanvas,
11464
- style: {
11465
- display: 'none'
11466
- }
11461
+ }, children, /*#__PURE__*/React__default['default'].createElement(InvisibleCanvas, {
11462
+ ref: lastPredictionCanvas
11463
+ }), /*#__PURE__*/React__default['default'].createElement(InvisibleCanvas, {
11464
+ ref: bestPredictionCanvas
11467
11465
  }));
11468
11466
  };
11469
- function drawToCanvas(canvas, frame) {
11467
+ function drawToCanvas(canvas, frame, width, height) {
11470
11468
  if (!canvas) return;
11471
11469
  var ctx = canvas.getContext('2d');
11472
11470
  if (!ctx) return;
11473
- var _a = getFrameDimensions(frame),
11474
- frameWidth = _a[0],
11475
- frameHeight = _a[1];
11476
- canvas.width = frameWidth;
11477
- canvas.height = frameHeight;
11478
- ctx.drawImage(frame, 0, 0, frameWidth, frameHeight);
11471
+ if (!width || !height) {
11472
+ var _a = getFrameDimensions(frame),
11473
+ frameWidth = _a[0],
11474
+ frameHeight = _a[1];
11475
+ width || (width = frameWidth);
11476
+ height || (height = frameHeight);
11477
+ }
11478
+ canvas.width = width;
11479
+ canvas.height = height;
11480
+ ctx.drawImage(frame, 0, 0, width, height);
11479
11481
  }
11480
11482
  function clearCanvas(canvas) {
11481
11483
  if (!canvas) return;
@@ -11483,21 +11485,19 @@
11483
11485
  if (!ctx) return;
11484
11486
  ctx.clearRect(0, 0, canvas.width, canvas.height);
11485
11487
  }
11486
- function makePredictions(frame, canvas, documentDetectionThreshold, passportDetectionThreshold, focusThreshold) {
11487
- var _a, _b, _c, _d;
11488
+ function makePredictions(frame, lastPredictionCanvas, thresholds) {
11489
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
11488
11490
  return __awaiter(this, void 0, void 0, function () {
11489
- var _e, frameWidth, frameHeight, _f, _g, boxes, scores, labels, detectionTime, detectedObjects, bestDocument, bestPassportPage, bestDocumentScore, passportDetectionScore, passportDetectionThresholdMet, bestDocumentOrPassport, detectionScore, detectionThresholdMet, focusPrediction, focusPredictionTime, focusScore, focusThresholdMet;
11490
- var _h;
11491
- return __generator(this, function (_j) {
11492
- switch (_j.label) {
11491
+ 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;
11492
+ var _p;
11493
+ return __generator(this, function (_q) {
11494
+ switch (_q.label) {
11493
11495
  case 0:
11494
- _e = getFrameDimensions(frame), frameWidth = _e[0], frameHeight = _e[1];
11495
- {
11496
- drawToCanvas(canvas, frame);
11497
- }
11496
+ _l = getFrameDimensions(frame), frameWidth = _l[0], frameHeight = _l[1];
11497
+ drawToCanvas(lastPredictionCanvas, frame);
11498
11498
  return [4, makeDocumentDetectionPredictions(frame)];
11499
11499
  case 1:
11500
- _f = _j.sent(), _g = _f[0], boxes = _g.boxes, scores = _g.scores, labels = _g.labels, detectionTime = _f[1];
11500
+ _o = _q.sent(), boxes = _o.boxes, scores = _o.scores, labels = _o.labels, time = _o.time;
11501
11501
  detectedObjects = applyNonMaxSuppression(boxes.map(function (box, i) {
11502
11502
  return bboxToDetectedObjectUnscaled(box, scores[i], labels[i]);
11503
11503
  }));
@@ -11509,18 +11509,28 @@
11509
11509
  });
11510
11510
  bestDocumentScore = (_a = bestDocument === null || bestDocument === void 0 ? void 0 : bestDocument.score) !== null && _a !== void 0 ? _a : 0;
11511
11511
  passportDetectionScore = (_b = bestPassportPage === null || bestPassportPage === void 0 ? void 0 : bestPassportPage.score) !== null && _b !== void 0 ? _b : 0;
11512
- passportDetectionThresholdMet = passportDetectionScore >= passportDetectionThreshold;
11512
+ passportDetectionThresholdMet = passportDetectionScore >= ((_c = thresholds.passport) !== null && _c !== void 0 ? _c : 0);
11513
11513
  bestDocumentOrPassport = bestDocumentScore > passportDetectionScore ? bestDocument : bestPassportPage;
11514
- detectionScore = passportDetectionThresholdMet ? passportDetectionScore : (_c = bestDocument === null || bestDocument === void 0 ? void 0 : bestDocument.score) !== null && _c !== void 0 ? _c : 0;
11515
- detectionThresholdMet = detectionScore >= documentDetectionThreshold;
11514
+ detectionScore = passportDetectionThresholdMet ? passportDetectionScore : bestDocumentScore;
11515
+ detectionThresholdMet = detectionScore >= ((_d = thresholds.document) !== null && _d !== void 0 ? _d : 0);
11516
+ bestMrz = detectedObjects.find(function (obj) {
11517
+ return obj.label === 'MRZ';
11518
+ });
11519
+ mrzDetectionScore = (_e = bestMrz === null || bestMrz === void 0 ? void 0 : bestMrz.score) !== null && _e !== void 0 ? _e : 0;
11520
+ mrzDetectionThresholdMet = mrzDetectionScore >= ((_f = thresholds.mrz) !== null && _f !== void 0 ? _f : 0);
11521
+ bestPdf417 = detectedObjects.find(function (obj) {
11522
+ return obj.label === 'PDF417';
11523
+ });
11524
+ pdf417DetectionScore = (_g = bestPdf417 === null || bestPdf417 === void 0 ? void 0 : bestPdf417.score) !== null && _g !== void 0 ? _g : 0;
11525
+ pdf417DetectionThresholdMet = pdf417DetectionScore >= ((_h = thresholds.pdf417) !== null && _h !== void 0 ? _h : 0);
11516
11526
  focusPrediction = null, focusPredictionTime = 0, focusScore = 0, focusThresholdMet = false;
11517
11527
  if (!detectionThresholdMet) return [3, 3];
11518
11528
  return [4, makeFocusPrediction(frame, bestDocumentOrPassport === null || bestDocumentOrPassport === void 0 ? void 0 : bestDocumentOrPassport.bbox)];
11519
11529
  case 2:
11520
- _h = _j.sent(), focusPrediction = _h[0], focusPredictionTime = _h[1];
11521
- focusScore = (_d = focusPrediction === null || focusPrediction === void 0 ? void 0 : focusPrediction[1]) !== null && _d !== void 0 ? _d : 0;
11522
- focusThresholdMet = focusScore >= focusThreshold;
11523
- _j.label = 3;
11530
+ _p = _q.sent(), focusPrediction = _p[0], focusPredictionTime = _p[1];
11531
+ focusScore = (_j = focusPrediction === null || focusPrediction === void 0 ? void 0 : focusPrediction[1]) !== null && _j !== void 0 ? _j : 0;
11532
+ focusThresholdMet = focusScore >= ((_k = thresholds.focus) !== null && _k !== void 0 ? _k : 0);
11533
+ _q.label = 3;
11524
11534
  case 3:
11525
11535
  return [2, {
11526
11536
  detectedObjects: detectedObjects,
@@ -11528,11 +11538,17 @@
11528
11538
  detectionThresholdMet: detectionThresholdMet,
11529
11539
  passportDetectionScore: passportDetectionScore,
11530
11540
  passportDetectionThresholdMet: passportDetectionThresholdMet,
11531
- detectionTime: detectionTime,
11541
+ mrzDetectionScore: mrzDetectionScore,
11542
+ mrzDetectionThresholdMet: mrzDetectionThresholdMet,
11543
+ pdf417DetectionScore: pdf417DetectionScore,
11544
+ pdf417DetectionThresholdMet: pdf417DetectionThresholdMet,
11545
+ detectionTime: time,
11532
11546
  bestDocumentOrPassport: bestDocumentOrPassport,
11533
- focusPredictionTime: focusPredictionTime,
11547
+ bestMrz: bestMrz,
11548
+ bestPdf417: bestPdf417,
11534
11549
  focusScore: focusScore,
11535
11550
  focusThresholdMet: focusThresholdMet,
11551
+ focusPredictionTime: focusPredictionTime,
11536
11552
  frameWidth: frameWidth,
11537
11553
  frameHeight: frameHeight
11538
11554
  }];
@@ -11542,7 +11558,7 @@
11542
11558
  }
11543
11559
  function makeDocumentDetectionPredictions(image) {
11544
11560
  return __awaiter(this, void 0, void 0, function () {
11545
- var startedAt, tfImg, tfResize, tfInt32, tf4d_, _a, _b, _c, _d, tf4d, result, predictions, boxes, scores, labels, predictionTime, e_1;
11561
+ var startedAt, tfImg, tfResize, tfInt32, tf4d_, _a, _b, _c, _d, tf4d, result, predictions, boxes, scores, labels, time, e_1;
11546
11562
  return __generator(this, function (_e) {
11547
11563
  switch (_e.label) {
11548
11564
  case 0:
@@ -11584,20 +11600,22 @@
11584
11600
  return Math.round(l);
11585
11601
  });
11586
11602
  tf__namespace.dispose(result);
11587
- predictionTime = new Date().getTime() - startedAt.getTime();
11588
- return [2, [{
11603
+ time = new Date().getTime() - startedAt.getTime();
11604
+ return [2, {
11589
11605
  boxes: boxes,
11590
11606
  scores: scores,
11591
- labels: labels
11592
- }, predictionTime]];
11607
+ labels: labels,
11608
+ time: time
11609
+ }];
11593
11610
  case 7:
11594
11611
  e_1 = _e.sent();
11595
11612
  console.error('caught error in makeDocumentDetectionPredictions', e_1);
11596
- return [2, [{
11613
+ return [2, {
11597
11614
  boxes: [],
11598
11615
  scores: [],
11599
- labels: []
11600
- }, 0]];
11616
+ labels: [],
11617
+ time: 0
11618
+ }];
11601
11619
  case 8:
11602
11620
  return [2];
11603
11621
  }
@@ -11668,29 +11686,229 @@
11668
11686
  return !!obj;
11669
11687
  });
11670
11688
  }
11689
+ function disposeTfBackend() {
11690
+ try {
11691
+ tf__namespace.backend().dispose();
11692
+ } catch (e) {
11693
+ console.error('failed to dispose backend', e);
11694
+ }
11695
+ }
11696
+ var InvisibleCanvas = styled__default['default'].canvas(templateObject_1$5 || (templateObject_1$5 = __makeTemplateObject(["\n display: none;\n"], ["\n display: none;\n"])));
11697
+ var templateObject_1$5;
11698
+
11699
+ var DebugStatsPane = styled__default['default'].span(templateObject_1$4 || (templateObject_1$4 = __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"])));
11700
+ var ObjectDetectionDebugOverlay = styled__default['default'].div(templateObject_2$2 || (templateObject_2$2 = __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) {
11701
+ var $flipX = _a.$flipX;
11702
+ return $flipX ? 'transform: scaleX(-1);' : '';
11703
+ });
11704
+ var ObjectDetectionDebugBox = styled__default['default'].div(templateObject_3$1 || (templateObject_3$1 = __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) {
11705
+ var $top = _a.$top;
11706
+ return $top;
11707
+ }, function (_a) {
11708
+ var $left = _a.$left;
11709
+ return $left;
11710
+ }, function (_a) {
11711
+ var $width = _a.$width;
11712
+ return $width;
11713
+ }, function (_a) {
11714
+ var $height = _a.$height;
11715
+ return $height;
11716
+ }, function (_a) {
11717
+ var $color = _a.$color;
11718
+ return $color !== null && $color !== void 0 ? $color : 'green';
11719
+ }, function (_a) {
11720
+ var $color = _a.$color;
11721
+ return $color !== null && $color !== void 0 ? $color : 'green';
11722
+ }, function (_a) {
11723
+ var $flipX = _a.$flipX;
11724
+ return $flipX ? 'transform: scaleX(-1);' : '';
11725
+ });
11726
+ var FaceDetectionKeypointMarker = styled__default['default'].div(templateObject_4$1 || (templateObject_4$1 = __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) {
11727
+ var $top = _a.$top,
11728
+ $height = _a.$height;
11729
+ return $top - $height / 2;
11730
+ }, function (_a) {
11731
+ var $left = _a.$left,
11732
+ $width = _a.$width;
11733
+ return $left - $width / 2;
11734
+ }, function (_a) {
11735
+ var $width = _a.$width;
11736
+ return $width;
11737
+ }, function (_a) {
11738
+ var $height = _a.$height;
11739
+ return $height;
11740
+ }, function (_a) {
11741
+ var $width = _a.$width;
11742
+ return $width / 2;
11743
+ }, function (_a) {
11744
+ var $color = _a.$color;
11745
+ return $color !== null && $color !== void 0 ? $color : 'red';
11746
+ }, function (_a) {
11747
+ var $color = _a.$color;
11748
+ return $color !== null && $color !== void 0 ? $color : 'red';
11749
+ }, function (_a) {
11750
+ var $flipX = _a.$flipX;
11751
+ return $flipX ? 'transform: scaleX(-1);' : '';
11752
+ });
11753
+ function useDebugScalingDetails(_a) {
11754
+ var _b = _a.enabled,
11755
+ enabled = _b === void 0 ? true : _b,
11756
+ pageWidth = _a.pageWidth,
11757
+ pageHeight = _a.pageHeight,
11758
+ videoWidth = _a.videoWidth,
11759
+ videoHeight = _a.videoHeight;
11760
+ return React.useMemo(function () {
11761
+ var horizontal = false,
11762
+ scaledWidth = 0,
11763
+ scaledHeight = 0,
11764
+ xOffset = 0,
11765
+ yOffset = 0;
11766
+ if (enabled) {
11767
+ horizontal = pageWidth / pageHeight < videoWidth / videoHeight;
11768
+ if (horizontal) {
11769
+ scaledWidth = videoWidth * (pageHeight / videoHeight);
11770
+ xOffset = (scaledWidth - pageWidth) / 2;
11771
+ } else {
11772
+ scaledHeight = videoHeight * (pageWidth / videoWidth);
11773
+ yOffset = (scaledHeight - pageHeight) / 2;
11774
+ }
11775
+ }
11776
+ return {
11777
+ horizontal: horizontal,
11778
+ pageWidth: pageWidth,
11779
+ pageHeight: pageHeight,
11780
+ videoWidth: videoWidth,
11781
+ videoHeight: videoHeight,
11782
+ scaledWidth: scaledWidth,
11783
+ scaledHeight: scaledHeight,
11784
+ xOffset: xOffset,
11785
+ yOffset: yOffset
11786
+ };
11787
+ }, [enabled, pageHeight, pageWidth, videoHeight, videoWidth]);
11788
+ }
11789
+ function IdCaptureDetectedObjectDebugBox(_a) {
11790
+ var obj = _a.obj,
11791
+ flipX = _a.flipX,
11792
+ _b = _a.scaling,
11793
+ horizontal = _b.horizontal,
11794
+ pageWidth = _b.pageWidth,
11795
+ pageHeight = _b.pageHeight,
11796
+ scaledWidth = _b.scaledWidth,
11797
+ scaledHeight = _b.scaledHeight,
11798
+ xOffset = _b.xOffset,
11799
+ yOffset = _b.yOffset;
11800
+ var top = obj.bbox[1] * (horizontal ? pageHeight : scaledHeight - yOffset);
11801
+ var left = obj.bbox[0] * (horizontal ? scaledWidth - xOffset : pageWidth);
11802
+ var width = obj.bbox[2] * (horizontal ? scaledWidth : pageWidth);
11803
+ var height = obj.bbox[3] * (horizontal ? pageHeight : scaledHeight);
11804
+ return /*#__PURE__*/React__default['default'].createElement(ObjectDetectionDebugBox, {
11805
+ "$top": top,
11806
+ "$left": left,
11807
+ "$width": width,
11808
+ "$height": height,
11809
+ "$flipX": flipX
11810
+ }, obj.label, " (", obj.score.toFixed(3), ")");
11811
+ }
11812
+ function SelfieCaptureFaceDebugBox(_a) {
11813
+ var face = _a.face,
11814
+ flipX = _a.flipX,
11815
+ _b = _a.color,
11816
+ color = _b === void 0 ? 'green' : _b,
11817
+ scaling = _a.scaling;
11818
+ var horizontal = scaling.horizontal,
11819
+ pageWidth = scaling.pageWidth,
11820
+ pageHeight = scaling.pageHeight,
11821
+ videoWidth = scaling.videoWidth,
11822
+ videoHeight = scaling.videoHeight,
11823
+ scaledWidth = scaling.scaledWidth,
11824
+ scaledHeight = scaling.scaledHeight,
11825
+ xOffset = scaling.xOffset,
11826
+ yOffset = scaling.yOffset;
11827
+ var top;
11828
+ var left;
11829
+ var width;
11830
+ var height;
11831
+ if (horizontal) {
11832
+ top = face.box.yMin / videoHeight * pageHeight;
11833
+ left = face.box.xMin / videoWidth * scaledWidth - xOffset;
11834
+ width = face.box.width / videoWidth * scaledWidth;
11835
+ height = face.box.height / videoHeight * pageHeight;
11836
+ } else {
11837
+ top = face.box.yMin / videoHeight * scaledHeight - yOffset;
11838
+ left = face.box.xMin / videoWidth * pageWidth;
11839
+ width = face.box.width / videoWidth * pageWidth;
11840
+ height = face.box.height / videoHeight * scaledHeight;
11841
+ }
11842
+ return /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, /*#__PURE__*/React__default['default'].createElement(ObjectDetectionDebugBox, {
11843
+ "$top": top,
11844
+ "$left": left,
11845
+ "$width": width,
11846
+ "$height": height,
11847
+ "$flipX": flipX,
11848
+ "$color": color
11849
+ }), face.keypoints.map(function (point, ii) {
11850
+ return /*#__PURE__*/React__default['default'].createElement(SelfieCaptureFaceKeypoint, {
11851
+ key: ii,
11852
+ point: point,
11853
+ scaling: scaling,
11854
+ flipX: flipX
11855
+ });
11856
+ }));
11857
+ }
11858
+ function SelfieCaptureFaceKeypoint(_a) {
11859
+ var point = _a.point,
11860
+ flipX = _a.flipX,
11861
+ _b = _a.color,
11862
+ color = _b === void 0 ? 'red' : _b,
11863
+ _c = _a.scaling,
11864
+ horizontal = _c.horizontal,
11865
+ pageWidth = _c.pageWidth,
11866
+ pageHeight = _c.pageHeight,
11867
+ videoWidth = _c.videoWidth,
11868
+ videoHeight = _c.videoHeight,
11869
+ scaledWidth = _c.scaledWidth,
11870
+ scaledHeight = _c.scaledHeight,
11871
+ xOffset = _c.xOffset,
11872
+ yOffset = _c.yOffset;
11873
+ var left, top;
11874
+ if (horizontal) {
11875
+ left = point.x / videoWidth * scaledWidth - xOffset;
11876
+ top = point.y / videoHeight * pageHeight;
11877
+ } else {
11878
+ left = point.x / videoWidth * pageWidth;
11879
+ top = point.y / videoHeight * scaledHeight - yOffset;
11880
+ }
11881
+ return /*#__PURE__*/React__default['default'].createElement(FaceDetectionKeypointMarker, {
11882
+ "$top": top,
11883
+ "$left": left,
11884
+ "$width": 4,
11885
+ "$height": 4,
11886
+ "$flipX": flipX,
11887
+ "$color": color
11888
+ });
11889
+ }
11890
+ var templateObject_1$4, templateObject_2$2, templateObject_3$1, templateObject_4$1;
11671
11891
 
11672
11892
  var initialState$5 = {
11673
11893
  videoWidth: 0,
11674
11894
  videoHeight: 0,
11675
11895
  captureStartedAt: null,
11676
11896
  detectedObjects: [],
11677
- bestDocument: null,
11678
- bestMrz: null,
11679
- bestPdf417: null,
11897
+ bestDocument: undefined,
11898
+ bestMrz: undefined,
11899
+ bestPdf417: undefined,
11680
11900
  documentType: DocumentType.NONE,
11681
11901
  documentInBounds: false,
11682
11902
  documentDetectionScore: 0,
11683
11903
  documentDetectionThresholdMet: false,
11684
- mrzDetectionScore: 0,
11685
- mrzDetectionThreshold: 0.5,
11686
- mrzDetectionThresholdMet: false,
11687
- focusScore: 0,
11688
- focusThresholdMet: false,
11689
11904
  passportPageDetectionScore: 0,
11690
11905
  passportPageDetectionThresholdMet: false,
11906
+ mrzDetectionScore: 0,
11907
+ mrzDetectionThresholdMet: false,
11691
11908
  pdf417DetectionScore: 0,
11692
- pdf417DetectionThreshold: 0.15,
11693
11909
  pdf417DetectionThresholdMet: false,
11910
+ focusScore: 0,
11911
+ focusThresholdMet: false,
11694
11912
  barcodeScanningEnabled: false,
11695
11913
  barcodeResult: null,
11696
11914
  waitingForBarcodeScan: false,
@@ -11709,7 +11927,6 @@
11709
11927
  captureFailed: false
11710
11928
  };
11711
11929
  var reducer$5 = function reducer(state, action) {
11712
- var _a, _b, _c, _d;
11713
11930
  switch (action.type) {
11714
11931
  case 'configure':
11715
11932
  return __assign$1(__assign$1(__assign$1({}, state), action.payload), {
@@ -11720,17 +11937,23 @@
11720
11937
  captureFailed: false
11721
11938
  });
11722
11939
  case 'objectsDetected':
11723
- var _e = action.payload.prediction,
11724
- detectedObjects = _e.detectedObjects,
11725
- detectionScore = _e.detectionScore,
11726
- detectionThresholdMet = _e.detectionThresholdMet,
11727
- passportDetectionScore = _e.passportDetectionScore,
11728
- passportDetectionThresholdMet = _e.passportDetectionThresholdMet,
11729
- bestDocumentOrPassport = _e.bestDocumentOrPassport,
11730
- focusScore = _e.focusScore,
11731
- focusThresholdMet = _e.focusThresholdMet,
11732
- frameWidth = _e.frameWidth,
11733
- frameHeight = _e.frameHeight;
11940
+ var _a = action.payload.prediction,
11941
+ detectedObjects = _a.detectedObjects,
11942
+ detectionScore = _a.detectionScore,
11943
+ detectionThresholdMet = _a.detectionThresholdMet,
11944
+ passportDetectionScore = _a.passportDetectionScore,
11945
+ passportDetectionThresholdMet = _a.passportDetectionThresholdMet,
11946
+ mrzDetectionScore = _a.mrzDetectionScore,
11947
+ mrzDetectionThresholdMet = _a.mrzDetectionThresholdMet,
11948
+ pdf417DetectionScore = _a.pdf417DetectionScore,
11949
+ pdf417DetectionThresholdMet = _a.pdf417DetectionThresholdMet,
11950
+ bestDocumentOrPassport = _a.bestDocumentOrPassport,
11951
+ bestMrz = _a.bestMrz,
11952
+ bestPdf417 = _a.bestPdf417,
11953
+ focusScore = _a.focusScore,
11954
+ focusThresholdMet = _a.focusThresholdMet,
11955
+ frameWidth = _a.frameWidth,
11956
+ frameHeight = _a.frameHeight;
11734
11957
  var frameCapturedAt = new Date();
11735
11958
  var frameCaptureRate = 0;
11736
11959
  var goodFramesThreshold = state.goodFramesThreshold;
@@ -11740,16 +11963,6 @@
11740
11963
  goodFramesThreshold = Math.ceil(3 * frameCaptureRate);
11741
11964
  }
11742
11965
  }
11743
- var bestMrz = (_a = detectedObjects.find(function (obj) {
11744
- return obj.label === 'MRZ';
11745
- })) !== null && _a !== void 0 ? _a : null;
11746
- var mrzDetectionScore = (_b = bestMrz === null || bestMrz === void 0 ? void 0 : bestMrz.score) !== null && _b !== void 0 ? _b : 0;
11747
- var mrzDetectionThresholdMet = mrzDetectionScore >= state.mrzDetectionThreshold;
11748
- var bestPdf417 = (_c = detectedObjects.find(function (obj) {
11749
- return obj.label === 'PDF417';
11750
- })) !== null && _c !== void 0 ? _c : null;
11751
- var pdf417DetectionScore = (_d = bestPdf417 === null || bestPdf417 === void 0 ? void 0 : bestPdf417.score) !== null && _d !== void 0 ? _d : 0;
11752
- var pdf417DetectionThresholdMet = pdf417DetectionScore >= state.pdf417DetectionThreshold;
11753
11966
  var documentType = DocumentType.NONE;
11754
11967
  if (passportDetectionThresholdMet) {
11755
11968
  documentType = DocumentType.PASSPORT;
@@ -11758,11 +11971,11 @@
11758
11971
  }
11759
11972
  var documentInBounds = false;
11760
11973
  if (bestDocumentOrPassport) {
11761
- var _f = bestDocumentOrPassport.bbox,
11762
- boundaryX = _f[0],
11763
- boundaryY = _f[1],
11764
- boundaryWidth = _f[2],
11765
- boundaryHeight = _f[3];
11974
+ var _b = bestDocumentOrPassport.bbox,
11975
+ boundaryX = _b[0],
11976
+ boundaryY = _b[1],
11977
+ boundaryWidth = _b[2],
11978
+ boundaryHeight = _b[3];
11766
11979
  boundaryX *= frameWidth;
11767
11980
  boundaryWidth *= frameWidth;
11768
11981
  boundaryY *= frameHeight;
@@ -11781,7 +11994,7 @@
11781
11994
  videoWidth: frameWidth,
11782
11995
  videoHeight: frameHeight,
11783
11996
  detectedObjects: detectedObjects,
11784
- bestDocument: bestDocumentOrPassport !== null && bestDocumentOrPassport !== void 0 ? bestDocumentOrPassport : null,
11997
+ bestDocument: bestDocumentOrPassport,
11785
11998
  bestMrz: bestMrz,
11786
11999
  bestPdf417: bestPdf417,
11787
12000
  documentType: documentType,
@@ -11906,9 +12119,7 @@
11906
12119
  var _3 = React.useContext(IdCaptureModelsContext),
11907
12120
  modelsReady = _3.ready,
11908
12121
  modelsWorking = _3.working,
11909
- setDocumentDetectionThreshold = _3.setDocumentDetectionThreshold,
11910
- setPassportDetectionThreshold = _3.setPassportDetectionThreshold,
11911
- setFocusThreshold = _3.setFocusThreshold,
12122
+ setThresholds = _3.setThresholds,
11912
12123
  makePrediction = _3.makePrediction,
11913
12124
  onPredictionMade = _3.onPredictionMade,
11914
12125
  detectionTime = _3.detectionTime,
@@ -11923,19 +12134,21 @@
11923
12134
  type: 'configure',
11924
12135
  payload: {
11925
12136
  requiredDocumentType: requiredDocumentType,
11926
- mrzDetectionThreshold: mrzDetectionScoreThreshold,
11927
12137
  goodFramesThreshold: autoCaptureGoodFramesRequired,
11928
12138
  autoCaptureBarcodeRequired: autoCaptureBarcodeRequired,
11929
12139
  barcodeScanningEnabled: barcodeScanningEnabled,
11930
- maxBarcodeScanAttempts: maxBarcodeScanAttempts,
11931
- pdf417DetectionThreshold: pdf417DetectionThreshold
12140
+ maxBarcodeScanAttempts: maxBarcodeScanAttempts
11932
12141
  }
11933
12142
  });
11934
12143
  resetBestFrame();
11935
- setDocumentDetectionThreshold(autoCaptureScoreThreshold);
11936
- setPassportDetectionThreshold(passportPageDetectionThreshold);
11937
- setFocusThreshold(focusScoreThreshold);
11938
- }, [requiredDocumentType, autoCaptureScoreThreshold, focusScoreThreshold, mrzDetectionScoreThreshold, autoCaptureGoodFramesRequired, autoCaptureBarcodeRequired, barcodeScanningEnabled, maxBarcodeScanAttempts, passportPageDetectionThreshold, pdf417DetectionThreshold, resetBestFrame, setDocumentDetectionThreshold, setPassportDetectionThreshold, setFocusThreshold]);
12144
+ setThresholds({
12145
+ document: autoCaptureScoreThreshold,
12146
+ passport: passportPageDetectionThreshold,
12147
+ mrz: mrzDetectionScoreThreshold,
12148
+ pdf417: pdf417DetectionThreshold,
12149
+ focus: focusScoreThreshold
12150
+ });
12151
+ }, [requiredDocumentType, autoCaptureScoreThreshold, focusScoreThreshold, mrzDetectionScoreThreshold, autoCaptureGoodFramesRequired, autoCaptureBarcodeRequired, barcodeScanningEnabled, maxBarcodeScanAttempts, passportPageDetectionThreshold, pdf417DetectionThreshold, resetBestFrame, setThresholds]);
11939
12152
  var animationFrame = React.useRef(0);
11940
12153
  var shouldCaptureFrames = React.useRef(false);
11941
12154
  React.useEffect(function () {
@@ -12108,6 +12321,13 @@
12108
12321
  });
12109
12322
  })();
12110
12323
  }, [getBestFrame, onCapture, processingDelay, shouldCapture, state.barcodeResult]);
12324
+ var debugScalingDetails = useDebugScalingDetails({
12325
+ enabled: debugMode,
12326
+ pageWidth: width,
12327
+ pageHeight: height,
12328
+ videoWidth: state.videoWidth,
12329
+ videoHeight: state.videoHeight
12330
+ });
12111
12331
  if (processingFrame) {
12112
12332
  return processingScreen || /*#__PURE__*/React__default['default'].createElement("div", null, "Processing...");
12113
12333
  }
@@ -12135,64 +12355,17 @@
12135
12355
  landscapeGuidesImageUrl: assets.landscapeGuidesImageUrl,
12136
12356
  isMirrored: !((_c = cameraRef.current) === null || _c === void 0 ? void 0 : _c.isRearFacing),
12137
12357
  borderColor: state.isGoodFrame ? 'green' : 'white'
12138
- }), debugMode && state.detectedObjects.length > 0 && /*#__PURE__*/React__default['default'].createElement("div", {
12139
- style: {
12140
- position: 'absolute',
12141
- zIndex: 1001,
12142
- width: '100%',
12143
- height: '100%',
12144
- maxWidth: '100%',
12145
- maxHeight: '100%',
12146
- transform: ((_d = cameraRef.current) === null || _d === void 0 ? void 0 : _d.isRearFacing) ? '' : 'scaleX(-1)',
12147
- overflow: 'hidden'
12148
- }
12358
+ }), debugMode && state.detectedObjects.length > 0 && /*#__PURE__*/React__default['default'].createElement(ObjectDetectionDebugOverlay, {
12359
+ "$flipX": !((_d = cameraRef.current) === null || _d === void 0 ? void 0 : _d.isRearFacing)
12149
12360
  }, state.detectedObjects.map(function (obj, i) {
12150
12361
  var _a;
12151
- var wrapperAspectRatio = width / height;
12152
- var videoAspectRatio = state.videoWidth / state.videoHeight;
12153
- var left = obj.bbox[0] * width;
12154
- var top = obj.bbox[1] * height;
12155
- var boxWidth = obj.bbox[2] * width;
12156
- var boxHeight = obj.bbox[3] * height;
12157
- if (wrapperAspectRatio < videoAspectRatio) {
12158
- var xScalar = height / state.videoHeight;
12159
- var scaledWidth = state.videoWidth * xScalar;
12160
- var xOffset = (scaledWidth - width) / 2;
12161
- left = obj.bbox[0] * scaledWidth - xOffset;
12162
- boxWidth = obj.bbox[2] * scaledWidth;
12163
- } else {
12164
- var yScalar = width / state.videoWidth;
12165
- var scaledHeight = state.videoHeight * yScalar;
12166
- var yOffset = (scaledHeight - height) / 2;
12167
- top = obj.bbox[1] * scaledHeight - yOffset;
12168
- boxHeight = obj.bbox[3] * scaledHeight;
12169
- }
12170
- return /*#__PURE__*/React__default['default'].createElement("div", {
12362
+ return /*#__PURE__*/React__default['default'].createElement(IdCaptureDetectedObjectDebugBox, {
12171
12363
  key: i,
12172
- style: {
12173
- position: 'absolute',
12174
- left: left,
12175
- top: top,
12176
- width: boxWidth,
12177
- height: boxHeight,
12178
- border: '3px solid green',
12179
- font: '10px monospace',
12180
- color: 'green',
12181
- transform: ((_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.isRearFacing) ? '' : 'scaleX(-1)'
12182
- }
12183
- }, obj.label, " (", obj.score.toFixed(3), ")");
12184
- })), debugMode && /*#__PURE__*/React__default['default'].createElement("span", {
12185
- style: {
12186
- fontSize: 16,
12187
- fontFamily: 'monospace',
12188
- position: 'absolute',
12189
- left: 20,
12190
- bottom: 20,
12191
- color: 'limegreen',
12192
- background: 'rgba(0,0,0,0.5)',
12193
- zIndex: 1001
12194
- }
12195
- }, 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")));
12364
+ obj: obj,
12365
+ scaling: debugScalingDetails,
12366
+ flipX: !((_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.isRearFacing)
12367
+ });
12368
+ })), 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")));
12196
12369
  };
12197
12370
  var timeSince = function timeSince(t) {
12198
12371
  if (!t) return 0;
@@ -12690,10 +12863,10 @@
12690
12863
  "$isRearFacing": (_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.isRearFacing
12691
12864
  });
12692
12865
  };
12693
- var FullscreenVideoTag = styled__default['default'].video(templateObject_1$2 || (templateObject_1$2 = __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) {
12866
+ var FullscreenVideoTag = styled__default['default'].video(templateObject_1$3 || (templateObject_1$3 = __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) {
12694
12867
  return props.$isRearFacing ? '' : 'scaleX(-1)';
12695
12868
  });
12696
- var templateObject_1$2;
12869
+ var templateObject_1$3;
12697
12870
 
12698
12871
  var CaptureState;
12699
12872
  (function (CaptureState) {
@@ -13362,11 +13535,6 @@
13362
13535
  var isMobile = state.videoWidth < state.videoHeight;
13363
13536
  var tooCloseMultiple = isMobile ? 2 : 4.5;
13364
13537
  var tooFarMultiple = isMobile ? 6 : 7;
13365
- console.log({
13366
- faceBoxWidth: face.box.width,
13367
- videoWidth: state.videoWidth,
13368
- tooCloseMultiple: tooCloseMultiple
13369
- });
13370
13538
  faceTooClose = face.box.width > state.videoWidth / tooCloseMultiple;
13371
13539
  faceTooFar = face.box.width < state.videoWidth / tooFarMultiple;
13372
13540
  }
@@ -13504,6 +13672,13 @@
13504
13672
  React.useEffect(function () {
13505
13673
  if (timedOut) onTimeout === null || onTimeout === void 0 ? void 0 : onTimeout();
13506
13674
  }, [onTimeout, timedOut]);
13675
+ var debugScalingDetails = useDebugScalingDetails({
13676
+ enabled: debugMode,
13677
+ pageWidth: width,
13678
+ pageHeight: height,
13679
+ videoWidth: state.videoWidth,
13680
+ videoHeight: state.videoHeight
13681
+ });
13507
13682
  if (!guidanceMessage) {
13508
13683
  verbiage.guidanceHoldStillText = verbiage.guidanceHoldStillText || t('Hold still for a few seconds...');
13509
13684
  verbiage.guidanceLookStraightText = verbiage.guidanceLookStraightText || t('Look straight into the camera...');
@@ -13534,100 +13709,18 @@
13534
13709
  padding: '10px 12px 8px',
13535
13710
  borderRadius: 8
13536
13711
  }
13537
- }, guidanceMessage)), debugMode && state.faces.length > 0 && /*#__PURE__*/React__default['default'].createElement("div", {
13538
- style: {
13539
- position: 'absolute',
13540
- zIndex: 1001,
13541
- width: '100%',
13542
- height: '100%',
13543
- maxWidth: '100%',
13544
- maxHeight: '100%',
13545
- transform: ((_b = cameraRef.current) === null || _b === void 0 ? void 0 : _b.isRearFacing) ? '' : 'scaleX(-1)',
13546
- overflow: 'hidden'
13547
- }
13712
+ }, guidanceMessage)), debugMode && state.faces.length > 0 && /*#__PURE__*/React__default['default'].createElement(ObjectDetectionDebugOverlay, {
13713
+ "$flipX": !((_b = cameraRef.current) === null || _b === void 0 ? void 0 : _b.isRearFacing)
13548
13714
  }, state.faces.map(function (face, i) {
13549
13715
  var _a;
13550
- var wrapperAspectRatio = width / height;
13551
- var videoAspectRatio = state.videoWidth / state.videoHeight;
13552
- var left = face.box.xMin / state.videoWidth;
13553
- var top = face.box.yMin / state.videoHeight;
13554
- var boxWidth = face.box.width / state.videoWidth;
13555
- var boxHeight = face.box.height / state.videoHeight;
13556
- if (wrapperAspectRatio < videoAspectRatio) {
13557
- var xScalar = height / state.videoHeight;
13558
- var scaledWidth = state.videoWidth * xScalar;
13559
- var xOffset = (scaledWidth - width) / 2;
13560
- left = left * scaledWidth - xOffset;
13561
- top *= height;
13562
- boxWidth *= scaledWidth;
13563
- boxHeight *= height;
13564
- } else {
13565
- var yScalar = width / state.videoWidth;
13566
- var scaledHeight = state.videoHeight * yScalar;
13567
- var yOffset = (scaledHeight - height) / 2;
13568
- left *= width;
13569
- top = top * scaledHeight - yOffset;
13570
- boxWidth *= width;
13571
- boxHeight *= scaledHeight;
13572
- }
13573
- return /*#__PURE__*/React__default['default'].createElement("div", {
13574
- key: i
13575
- }, /*#__PURE__*/React__default['default'].createElement("div", {
13576
- style: {
13577
- position: 'absolute',
13578
- left: left,
13579
- top: top,
13580
- width: boxWidth,
13581
- height: boxHeight,
13582
- border: "3px solid ".concat(state.faceReady ? 'green' : 'red'),
13583
- font: '10px monospace',
13584
- transform: ((_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.isRearFacing) ? '' : 'scaleX(-1)'
13585
- }
13586
- }), face.keypoints.map(function (point, ii) {
13587
- var _a;
13588
- var left = point.x / state.videoWidth;
13589
- var top = point.y / state.videoHeight;
13590
- if (wrapperAspectRatio < videoAspectRatio) {
13591
- var xScalar = height / state.videoHeight;
13592
- var scaledWidth = state.videoWidth * xScalar;
13593
- var xOffset = (scaledWidth - width) / 2;
13594
- left = left * scaledWidth - xOffset;
13595
- top *= height;
13596
- } else {
13597
- var yScalar = width / state.videoWidth;
13598
- var scaledHeight = state.videoHeight * yScalar;
13599
- var yOffset = (scaledHeight - height) / 2;
13600
- left *= width;
13601
- top = top * scaledHeight - yOffset;
13602
- }
13603
- return /*#__PURE__*/React__default['default'].createElement("div", {
13604
- key: ii,
13605
- style: {
13606
- position: 'absolute',
13607
- left: left - 2,
13608
- top: top - 2,
13609
- width: 4,
13610
- height: 4,
13611
- border: '2px solid red',
13612
- font: '10px monospace',
13613
- color: 'green',
13614
- transform: ((_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.isRearFacing) ? '' : 'scaleX(-1)',
13615
- borderRadius: '50%'
13616
- }
13617
- }, ii);
13618
- }));
13619
- })), debugMode && /*#__PURE__*/React__default['default'].createElement("span", {
13620
- style: {
13621
- fontSize: 16,
13622
- fontFamily: 'monospace',
13623
- position: 'absolute',
13624
- left: 20,
13625
- bottom: 20,
13626
- color: 'limegreen',
13627
- background: 'rgba(0,0,0,0.5)',
13628
- zIndex: 1001
13629
- }
13630
- }, 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"));
13716
+ return /*#__PURE__*/React__default['default'].createElement(SelfieCaptureFaceDebugBox, {
13717
+ key: i,
13718
+ face: face,
13719
+ scaling: debugScalingDetails,
13720
+ flipX: !((_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.isRearFacing),
13721
+ color: state.faceReady ? 'green' : 'red'
13722
+ });
13723
+ })), 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"));
13631
13724
  };
13632
13725
 
13633
13726
  var initialState$2 = {
@@ -14700,8 +14793,8 @@
14700
14793
  return truncated;
14701
14794
  }
14702
14795
 
14703
- var Spinner = styled__default['default'].div(templateObject_1$1 || (templateObject_1$1 = __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"])));
14704
- var templateObject_1$1;
14796
+ var Spinner = styled__default['default'].div(templateObject_1$2 || (templateObject_1$2 = __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"])));
14797
+ var templateObject_1$2;
14705
14798
 
14706
14799
  var AdditionalDocumentCapture = function AdditionalDocumentCapture(_a) {
14707
14800
  var document = _a.document,
@@ -14927,7 +15020,7 @@
14927
15020
  };
14928
15021
  }
14929
15022
 
14930
- function SignaturePad(canvas, options) {
15023
+ function SignaturePad$1(canvas, options) {
14931
15024
  var self = this;
14932
15025
  var opts = options || {};
14933
15026
 
@@ -14938,9 +15031,9 @@
14938
15031
  this.minDistance = 'minDistance' in opts ? opts.minDistance : 5;
14939
15032
 
14940
15033
  if (this.throttle) {
14941
- this._strokeMoveUpdate = throttle(SignaturePad.prototype._strokeUpdate, this.throttle);
15034
+ this._strokeMoveUpdate = throttle(SignaturePad$1.prototype._strokeUpdate, this.throttle);
14942
15035
  } else {
14943
- this._strokeMoveUpdate = SignaturePad.prototype._strokeUpdate;
15036
+ this._strokeMoveUpdate = SignaturePad$1.prototype._strokeUpdate;
14944
15037
  }
14945
15038
 
14946
15039
  this.dotSize = opts.dotSize || function () {
@@ -15005,7 +15098,7 @@
15005
15098
  }
15006
15099
 
15007
15100
  // Public methods
15008
- SignaturePad.prototype.clear = function () {
15101
+ SignaturePad$1.prototype.clear = function () {
15009
15102
  var ctx = this._ctx;
15010
15103
  var canvas = this._canvas;
15011
15104
 
@@ -15018,7 +15111,7 @@
15018
15111
  this._isEmpty = true;
15019
15112
  };
15020
15113
 
15021
- SignaturePad.prototype.fromDataURL = function (dataUrl) {
15114
+ SignaturePad$1.prototype.fromDataURL = function (dataUrl) {
15022
15115
  var _this = this;
15023
15116
 
15024
15117
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -15036,7 +15129,7 @@
15036
15129
  this._isEmpty = false;
15037
15130
  };
15038
15131
 
15039
- SignaturePad.prototype.toDataURL = function (type) {
15132
+ SignaturePad$1.prototype.toDataURL = function (type) {
15040
15133
  var _canvas;
15041
15134
 
15042
15135
  switch (type) {
@@ -15051,12 +15144,12 @@
15051
15144
  }
15052
15145
  };
15053
15146
 
15054
- SignaturePad.prototype.on = function () {
15147
+ SignaturePad$1.prototype.on = function () {
15055
15148
  this._handleMouseEvents();
15056
15149
  this._handleTouchEvents();
15057
15150
  };
15058
15151
 
15059
- SignaturePad.prototype.off = function () {
15152
+ SignaturePad$1.prototype.off = function () {
15060
15153
  this._canvas.removeEventListener('mousedown', this._handleMouseDown);
15061
15154
  this._canvas.removeEventListener('mousemove', this._handleMouseMove);
15062
15155
  document.removeEventListener('mouseup', this._handleMouseUp);
@@ -15066,12 +15159,12 @@
15066
15159
  this._canvas.removeEventListener('touchend', this._handleTouchEnd);
15067
15160
  };
15068
15161
 
15069
- SignaturePad.prototype.isEmpty = function () {
15162
+ SignaturePad$1.prototype.isEmpty = function () {
15070
15163
  return this._isEmpty;
15071
15164
  };
15072
15165
 
15073
15166
  // Private methods
15074
- SignaturePad.prototype._strokeBegin = function (event) {
15167
+ SignaturePad$1.prototype._strokeBegin = function (event) {
15075
15168
  this._data.push([]);
15076
15169
  this._reset();
15077
15170
  this._strokeUpdate(event);
@@ -15081,7 +15174,7 @@
15081
15174
  }
15082
15175
  };
15083
15176
 
15084
- SignaturePad.prototype._strokeUpdate = function (event) {
15177
+ SignaturePad$1.prototype._strokeUpdate = function (event) {
15085
15178
  var x = event.clientX;
15086
15179
  var y = event.clientY;
15087
15180
 
@@ -15109,7 +15202,7 @@
15109
15202
  }
15110
15203
  };
15111
15204
 
15112
- SignaturePad.prototype._strokeEnd = function (event) {
15205
+ SignaturePad$1.prototype._strokeEnd = function (event) {
15113
15206
  var canDrawCurve = this.points.length > 2;
15114
15207
  var point = this.points[0]; // Point instance
15115
15208
 
@@ -15138,7 +15231,7 @@
15138
15231
  }
15139
15232
  };
15140
15233
 
15141
- SignaturePad.prototype._handleMouseEvents = function () {
15234
+ SignaturePad$1.prototype._handleMouseEvents = function () {
15142
15235
  this._mouseButtonDown = false;
15143
15236
 
15144
15237
  this._canvas.addEventListener('mousedown', this._handleMouseDown);
@@ -15146,7 +15239,7 @@
15146
15239
  document.addEventListener('mouseup', this._handleMouseUp);
15147
15240
  };
15148
15241
 
15149
- SignaturePad.prototype._handleTouchEvents = function () {
15242
+ SignaturePad$1.prototype._handleTouchEvents = function () {
15150
15243
  // Pass touch events to canvas element on mobile IE11 and Edge.
15151
15244
  this._canvas.style.msTouchAction = 'none';
15152
15245
  this._canvas.style.touchAction = 'none';
@@ -15156,20 +15249,20 @@
15156
15249
  this._canvas.addEventListener('touchend', this._handleTouchEnd);
15157
15250
  };
15158
15251
 
15159
- SignaturePad.prototype._reset = function () {
15252
+ SignaturePad$1.prototype._reset = function () {
15160
15253
  this.points = [];
15161
15254
  this._lastVelocity = 0;
15162
15255
  this._lastWidth = (this.minWidth + this.maxWidth) / 2;
15163
15256
  this._ctx.fillStyle = this.penColor;
15164
15257
  };
15165
15258
 
15166
- SignaturePad.prototype._createPoint = function (x, y, time) {
15259
+ SignaturePad$1.prototype._createPoint = function (x, y, time) {
15167
15260
  var rect = this._canvas.getBoundingClientRect();
15168
15261
 
15169
15262
  return new Point(x - rect.left, y - rect.top, time || new Date().getTime());
15170
15263
  };
15171
15264
 
15172
- SignaturePad.prototype._addPoint = function (point) {
15265
+ SignaturePad$1.prototype._addPoint = function (point) {
15173
15266
  var points = this.points;
15174
15267
  var tmp = void 0;
15175
15268
 
@@ -15197,7 +15290,7 @@
15197
15290
  return {};
15198
15291
  };
15199
15292
 
15200
- SignaturePad.prototype._calculateCurveControlPoints = function (s1, s2, s3) {
15293
+ SignaturePad$1.prototype._calculateCurveControlPoints = function (s1, s2, s3) {
15201
15294
  var dx1 = s1.x - s2.x;
15202
15295
  var dy1 = s1.y - s2.y;
15203
15296
  var dx2 = s2.x - s3.x;
@@ -15224,7 +15317,7 @@
15224
15317
  };
15225
15318
  };
15226
15319
 
15227
- SignaturePad.prototype._calculateCurveWidths = function (curve) {
15320
+ SignaturePad$1.prototype._calculateCurveWidths = function (curve) {
15228
15321
  var startPoint = curve.startPoint;
15229
15322
  var endPoint = curve.endPoint;
15230
15323
  var widths = { start: null, end: null };
@@ -15242,11 +15335,11 @@
15242
15335
  return widths;
15243
15336
  };
15244
15337
 
15245
- SignaturePad.prototype._strokeWidth = function (velocity) {
15338
+ SignaturePad$1.prototype._strokeWidth = function (velocity) {
15246
15339
  return Math.max(this.maxWidth / (velocity + 1), this.minWidth);
15247
15340
  };
15248
15341
 
15249
- SignaturePad.prototype._drawPoint = function (x, y, size) {
15342
+ SignaturePad$1.prototype._drawPoint = function (x, y, size) {
15250
15343
  var ctx = this._ctx;
15251
15344
 
15252
15345
  ctx.moveTo(x, y);
@@ -15254,7 +15347,7 @@
15254
15347
  this._isEmpty = false;
15255
15348
  };
15256
15349
 
15257
- SignaturePad.prototype._drawCurve = function (curve, startWidth, endWidth) {
15350
+ SignaturePad$1.prototype._drawCurve = function (curve, startWidth, endWidth) {
15258
15351
  var ctx = this._ctx;
15259
15352
  var widthDelta = endWidth - startWidth;
15260
15353
  var drawSteps = Math.floor(curve.length());
@@ -15288,7 +15381,7 @@
15288
15381
  ctx.fill();
15289
15382
  };
15290
15383
 
15291
- SignaturePad.prototype._drawDot = function (point) {
15384
+ SignaturePad$1.prototype._drawDot = function (point) {
15292
15385
  var ctx = this._ctx;
15293
15386
  var width = typeof this.dotSize === 'function' ? this.dotSize() : this.dotSize;
15294
15387
 
@@ -15298,7 +15391,7 @@
15298
15391
  ctx.fill();
15299
15392
  };
15300
15393
 
15301
- SignaturePad.prototype._fromData = function (pointGroups, drawCurve, drawDot) {
15394
+ SignaturePad$1.prototype._fromData = function (pointGroups, drawCurve, drawDot) {
15302
15395
  for (var i = 0; i < pointGroups.length; i += 1) {
15303
15396
  var group = pointGroups[i];
15304
15397
 
@@ -15336,7 +15429,7 @@
15336
15429
  }
15337
15430
  };
15338
15431
 
15339
- SignaturePad.prototype._toSVG = function () {
15432
+ SignaturePad$1.prototype._toSVG = function () {
15340
15433
  var _this2 = this;
15341
15434
 
15342
15435
  var pointGroups = this._data;
@@ -15402,7 +15495,7 @@
15402
15495
  return prefix + btoa(data);
15403
15496
  };
15404
15497
 
15405
- SignaturePad.prototype.fromData = function (pointGroups) {
15498
+ SignaturePad$1.prototype.fromData = function (pointGroups) {
15406
15499
  var _this3 = this;
15407
15500
 
15408
15501
  this.clear();
@@ -15416,13 +15509,13 @@
15416
15509
  this._data = pointGroups;
15417
15510
  };
15418
15511
 
15419
- SignaturePad.prototype.toData = function () {
15512
+ SignaturePad$1.prototype.toData = function () {
15420
15513
  return this._data;
15421
15514
  };
15422
15515
 
15423
15516
  var signature_pad = /*#__PURE__*/Object.freeze({
15424
15517
  __proto__: null,
15425
- 'default': SignaturePad
15518
+ 'default': SignaturePad$1
15426
15519
  });
15427
15520
 
15428
15521
  var build$1 = createCommonjsModule(function (module, exports) {
@@ -15467,55 +15560,43 @@
15467
15560
  return signatureData;
15468
15561
  }
15469
15562
 
15563
+ var SignatureCanvasContainer = styled__default['default'].div(templateObject_1$1 || (templateObject_1$1 = __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"])));
15564
+ var SignaturePad = styled__default['default'].div(templateObject_2$1 || (templateObject_2$1 = __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"])));
15565
+ var SignatureButtonsContainer = styled__default['default'].div(templateObject_3 || (templateObject_3 = __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"])));
15566
+ var SignaturePaperBacking = styled__default['default'].div(templateObject_4 || (templateObject_4 = __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"])));
15567
+ var templateObject_1$1, templateObject_2$1, templateObject_3, templateObject_4;
15568
+
15569
+ var GuidanceMessageContainer = styled__default['default'].div(templateObject_1 || (templateObject_1 = __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) {
15570
+ var $top = _a.$top;
15571
+ return $top !== null && $top !== void 0 ? $top : '10vh';
15572
+ });
15573
+ var GuidanceMessage = styled__default['default'].div(templateObject_2 || (templateObject_2 = __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"])));
15574
+ var templateObject_1, templateObject_2;
15575
+
15470
15576
  var SignatureCapture = function SignatureCapture(_a) {
15471
15577
  var onAccept = _a.onAccept,
15472
- _b = _a.background,
15473
- background = _b === void 0 ? 'white' : _b,
15474
- _c = _a.verbiage,
15475
- verbiage = _c === void 0 ? {} : _c;
15578
+ _b = _a.verbiage,
15579
+ verbiage = _b === void 0 ? {} : _b;
15476
15580
  var t = useTranslation().t;
15477
- var _d = useResizeObserver(),
15478
- ref = _d.ref,
15479
- width = _d.width,
15480
- height = _d.height;
15581
+ var _c = useResizeObserver(),
15582
+ ref = _c.ref,
15583
+ width = _c.width,
15584
+ height = _c.height;
15481
15585
  var signaturePad = React.useRef(null);
15482
15586
  verbiage.headingText = verbiage.headingText || t('Please sign the box below');
15483
15587
  verbiage.acceptBtnText = verbiage.acceptBtnText || t('Accept');
15484
15588
  verbiage.clearBtnText = verbiage.clearBtnText || t('Clear');
15485
- return /*#__PURE__*/React__default['default'].createElement(OverlayContainer, {
15486
- style: {
15487
- background: background
15488
- }
15489
- }, /*#__PURE__*/React__default['default'].createElement(OverlayInner, null, /*#__PURE__*/React__default['default'].createElement("div", {
15490
- style: {
15491
- flexGrow: 0,
15492
- paddingBottom: 12
15493
- }
15494
- }, /*#__PURE__*/React__default['default'].createElement("h3", {
15495
- style: {
15496
- margin: 0
15497
- }
15498
- }, verbiage.headingText)), /*#__PURE__*/React__default['default'].createElement("div", {
15499
- ref: ref,
15500
- style: {
15501
- position: 'relative',
15502
- border: '3px solid #888',
15503
- flexGrow: 1,
15504
- zIndex: '100'
15505
- }
15589
+ return /*#__PURE__*/React__default['default'].createElement(PageContainer, null, /*#__PURE__*/React__default['default'].createElement(SignaturePaperBacking, null, /*#__PURE__*/React__default['default'].createElement(GuidanceMessageContainer, {
15590
+ "$top": "5vh"
15591
+ }, /*#__PURE__*/React__default['default'].createElement(GuidanceMessage, null, verbiage.headingText)), /*#__PURE__*/React__default['default'].createElement(SignatureCanvasContainer, null, /*#__PURE__*/React__default['default'].createElement(SignaturePad, {
15592
+ ref: ref
15506
15593
  }, /*#__PURE__*/React__default['default'].createElement(SignatureCanvas, {
15507
15594
  ref: signaturePad,
15508
15595
  canvasProps: {
15509
15596
  width: width,
15510
- height: (height !== null && height !== void 0 ? height : 500) - 4
15511
- }
15512
- })), /*#__PURE__*/React__default['default'].createElement("div", {
15513
- style: {
15514
- flexGrow: 0,
15515
- paddingTop: 12,
15516
- display: 'flex'
15597
+ height: height
15517
15598
  }
15518
- }, /*#__PURE__*/React__default['default'].createElement("button", {
15599
+ })), /*#__PURE__*/React__default['default'].createElement(SignatureButtonsContainer, null, /*#__PURE__*/React__default['default'].createElement("button", {
15519
15600
  onClick: function onClick(e) {
15520
15601
  var _a;
15521
15602
  e.preventDefault();
@@ -15531,7 +15612,7 @@
15531
15612
  var signatureData = signatureDataToIdmissionFormat(signaturePad.current);
15532
15613
  onAccept === null || onAccept === void 0 ? void 0 : onAccept(signatureData, signaturePad.current.toDataURL());
15533
15614
  }
15534
- }, verbiage.acceptBtnText))));
15615
+ }, verbiage.acceptBtnText)))));
15535
15616
  };
15536
15617
 
15537
15618
  var useVideoRecorder = function useVideoRecorder(camera) {
@@ -15575,7 +15656,6 @@
15575
15656
  };
15576
15657
  };
15577
15658
 
15578
- var SignatureCanvasContainer = styled__default['default'].div(templateObject_1 || (templateObject_1 = __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"])));
15579
15659
  var VideoSignatureCapture = function VideoSignatureCapture(_a) {
15580
15660
  var _b, _c;
15581
15661
  var onComplete = _a.onComplete,
@@ -15718,47 +15798,17 @@
15718
15798
  var guidanceMessage = t('Please sign the box below');
15719
15799
  return /*#__PURE__*/React__default['default'].createElement(PageContainer, {
15720
15800
  className: "flex"
15721
- }, /*#__PURE__*/React__default['default'].createElement(CameraVideoTag, null), guidanceMessage !== '' && /*#__PURE__*/React__default['default'].createElement("div", {
15722
- style: {
15723
- position: 'absolute',
15724
- top: 'calc(5vh)',
15725
- fontWeight: 'bold',
15726
- width: '100%',
15727
- display: 'flex'
15728
- }
15729
- }, /*#__PURE__*/React__default['default'].createElement("div", {
15730
- style: {
15731
- marginLeft: 'auto',
15732
- marginRight: 'auto',
15733
- background: '#ccc',
15734
- padding: '10px 12px 8px',
15735
- borderRadius: 8
15736
- }
15737
- }, guidanceMessage)), /*#__PURE__*/React__default['default'].createElement(SignatureCanvasContainer, null, /*#__PURE__*/React__default['default'].createElement("div", {
15738
- ref: ref,
15739
- style: {
15740
- position: 'relative',
15741
- background: 'rgba(255,255,255,0.5)',
15742
- borderRadius: 16,
15743
- flexGrow: 1,
15744
- zIndex: '100',
15745
- height: '100%'
15746
- }
15801
+ }, /*#__PURE__*/React__default['default'].createElement(CameraVideoTag, null), guidanceMessage !== '' && /*#__PURE__*/React__default['default'].createElement(GuidanceMessageContainer, {
15802
+ "$top": "5vh"
15803
+ }, /*#__PURE__*/React__default['default'].createElement(GuidanceMessage, null, guidanceMessage)), /*#__PURE__*/React__default['default'].createElement(SignatureCanvasContainer, null, /*#__PURE__*/React__default['default'].createElement(SignaturePad, {
15804
+ ref: ref
15747
15805
  }, /*#__PURE__*/React__default['default'].createElement(SignatureCanvas, {
15748
15806
  ref: signaturePad,
15749
15807
  canvasProps: {
15750
15808
  width: width,
15751
15809
  height: height
15752
15810
  }
15753
- })), /*#__PURE__*/React__default['default'].createElement("div", {
15754
- style: {
15755
- flexGrow: 0,
15756
- paddingTop: 12,
15757
- display: 'flex',
15758
- zIndex: 1000,
15759
- position: 'relative'
15760
- }
15761
- }, /*#__PURE__*/React__default['default'].createElement("button", {
15811
+ })), /*#__PURE__*/React__default['default'].createElement(SignatureButtonsContainer, null, /*#__PURE__*/React__default['default'].createElement("button", {
15762
15812
  onClick: function onClick(e) {
15763
15813
  var _a;
15764
15814
  e.preventDefault();
@@ -15790,7 +15840,6 @@
15790
15840
  }
15791
15841
  })));
15792
15842
  };
15793
- var templateObject_1;
15794
15843
 
15795
15844
  var SignatureKYCLoadingOverlay = function SignatureKYCLoadingOverlay(_a) {
15796
15845
  var headingText = _a.headingText,