idmission-web-sdk 2.1.73 → 2.1.74

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.
@@ -215,7 +215,7 @@
215
215
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
216
216
  };
217
217
 
218
- var webSdkVersion = '2.1.73';
218
+ var webSdkVersion = '2.1.74';
219
219
 
220
220
  function getPlatform() {
221
221
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -11400,7 +11400,8 @@
11400
11400
  var defaultDocumentDetectionThresholds = {
11401
11401
  idCardFront: 0.6,
11402
11402
  idCardBack: 0.6,
11403
- passport: 0.4
11403
+ passport: 0.4,
11404
+ stability: 0.9
11404
11405
  };
11405
11406
  var documentTypeDisplayNames = {
11406
11407
  idCardFront: 'ID card front',
@@ -11542,6 +11543,13 @@
11542
11543
  });
11543
11544
  });
11544
11545
  }
11546
+ var lastNBoxes = [];
11547
+ var lastDetectionAt = 0;
11548
+ var lastDetectionTime = 0;
11549
+ function setLastDetectionAt(time) {
11550
+ lastDetectionTime = time - lastDetectionAt;
11551
+ lastDetectionAt = time;
11552
+ }
11545
11553
  var defaultDocumentDetectionBoundaries = {
11546
11554
  top: 20,
11547
11555
  bottom: 20,
@@ -11549,7 +11557,7 @@
11549
11557
  right: 20
11550
11558
  };
11551
11559
  function processDocumentDetectorPrediction(prediction, thresholds, boundaries) {
11552
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
11560
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
11553
11561
  if (boundaries === void 0) {
11554
11562
  boundaries = defaultDocumentDetectionBoundaries;
11555
11563
  }
@@ -11605,11 +11613,11 @@
11605
11613
  var boundaryLeft = (_j = boundaries.left) !== null && _j !== void 0 ? _j : 20;
11606
11614
  var boundaryRight = (_k = boundaries.right) !== null && _k !== void 0 ? _k : 20;
11607
11615
  var boundaryBottom = (_l = boundaries.bottom) !== null && _l !== void 0 ? _l : 20;
11608
- var _m = bestDocument.box,
11609
- xMin = _m.xMin,
11610
- yMin = _m.yMin,
11611
- width = _m.width,
11612
- height = _m.height;
11616
+ var _o = bestDocument.box,
11617
+ xMin = _o.xMin,
11618
+ yMin = _o.yMin,
11619
+ width = _o.width,
11620
+ height = _o.height;
11613
11621
  documentInBounds = yMin > boundaryTop &&
11614
11622
  // Is it valid top edge of ID detected?
11615
11623
  yMin + height + boundaryBottom < frameHeight && (
@@ -11618,12 +11626,23 @@
11618
11626
  // If either the left side visible or if not, right edge of ID should be more than 80% of width.
11619
11627
  xMin + width + boundaryRight < frameWidth; // Valid right edge if it's less than video width.
11620
11628
  }
11629
+ var documentIsStable = false;
11621
11630
  var documentTooClose = false;
11622
11631
  if (bestDocument) {
11623
- var _o = [bestDocument.box.width / frameWidth, bestDocument.box.height / frameHeight],
11624
- docWidth = _o[0],
11625
- docHeight = _o[1];
11632
+ var _p = [bestDocument.box.width / frameWidth, bestDocument.box.height / frameHeight],
11633
+ docWidth = _p[0],
11634
+ docHeight = _p[1];
11626
11635
  documentTooClose = docWidth > 0.85 || docHeight > 0.85;
11636
+ if (detectionThresholdMet) {
11637
+ var threshold_1 = (_m = thresholds.stability) !== null && _m !== void 0 ? _m : defaultDocumentDetectionThresholds.stability;
11638
+ var framesNeeded = Math.ceil(Math.min(1000 / lastDetectionTime, 12));
11639
+ lastNBoxes = __spreadArray([bestDocument.box], lastNBoxes, true).slice(0, framesNeeded);
11640
+ documentIsStable = lastNBoxes.length >= framesNeeded && !createPairs(lastNBoxes).some(function (_a) {
11641
+ var a = _a[0],
11642
+ b = _a[1];
11643
+ return calculateIoU(a, b) < threshold_1;
11644
+ });
11645
+ }
11627
11646
  }
11628
11647
  return {
11629
11648
  detectedObjects: detectedObjects,
@@ -11640,6 +11659,7 @@
11640
11659
  bestDocument: bestDocument,
11641
11660
  documentInBounds: documentInBounds,
11642
11661
  documentTooClose: documentTooClose,
11662
+ documentIsStable: documentIsStable,
11643
11663
  frameWidth: frameWidth,
11644
11664
  frameHeight: frameHeight,
11645
11665
  allZero: allZero
@@ -11659,6 +11679,27 @@
11659
11679
  return !!obj;
11660
11680
  });
11661
11681
  }
11682
+ function createPairs(arr) {
11683
+ var pairs = [];
11684
+ for (var i = 0; i < arr.length - 1; i++) {
11685
+ pairs.push([arr[i], arr[i + 1]]);
11686
+ }
11687
+ return pairs;
11688
+ }
11689
+ function calculateIoU(boxA, boxB) {
11690
+ var xA = Math.max(boxA.xMin, boxB.xMin);
11691
+ var yA = Math.max(boxA.yMin, boxB.yMin);
11692
+ var xB = Math.min(boxA.xMax, boxB.xMax);
11693
+ var yB = Math.min(boxA.yMax, boxB.yMax);
11694
+ var intersectWidth = Math.max(0, xB - xA);
11695
+ var intersectHeight = Math.max(0, yB - yA);
11696
+ var intersectionArea = intersectWidth * intersectHeight;
11697
+ var boxAArea = (boxA.xMax - boxA.xMin) * (boxA.yMax - boxA.yMin);
11698
+ var boxBArea = (boxB.xMax - boxB.xMin) * (boxB.yMax - boxB.yMin);
11699
+ var unionArea = boxAArea + boxBArea - intersectionArea;
11700
+ if (unionArea === 0) return 0;
11701
+ return intersectionArea / unionArea;
11702
+ }
11662
11703
 
11663
11704
  function useFrameLoop(fn, _a) {
11664
11705
  var _b = _a.throttleMs,
@@ -11676,16 +11717,20 @@
11676
11717
  var currentLoopId = loopId.current;
11677
11718
  function renderPrediction() {
11678
11719
  return __awaiter(this, void 0, void 0, function () {
11720
+ var start, took, amountToThrottle;
11679
11721
  return __generator(this, function (_a) {
11680
11722
  switch (_a.label) {
11681
11723
  case 0:
11682
11724
  if (currentLoopId !== loopId.current) return [2 /*return*/];
11725
+ start = new Date().getTime();
11683
11726
  return [4 /*yield*/, fn(frameId.current)];
11684
11727
  case 1:
11685
11728
  _a.sent();
11729
+ took = new Date().getTime() - start;
11730
+ amountToThrottle = Math.max((throttleMs !== null && throttleMs !== void 0 ? throttleMs : 0) - took, 0);
11686
11731
  timer = setTimeout(function () {
11687
11732
  frameId.current = requestAnimationFrame(renderPrediction);
11688
- }, throttleMs !== null && throttleMs !== void 0 ? throttleMs : 0);
11733
+ }, amountToThrottle);
11689
11734
  return [2 /*return*/];
11690
11735
  }
11691
11736
  });
@@ -11751,29 +11796,27 @@
11751
11796
  var _b = _a.autoStart,
11752
11797
  autoStart = _b === void 0 ? true : _b,
11753
11798
  children = _a.children,
11754
- throttleMs = _a.throttleMs,
11755
- _c = _a.documentDetectionModelPath,
11756
- documentDetectionModelPath = _c === void 0 ? defaultDocumentDetectorModelPath : _c,
11757
- _d = _a.documentDetectionModelScoreThreshold,
11758
- documentDetectionModelScoreThreshold = _d === void 0 ? defaultDocumentDetectionScoreThreshold : _d,
11759
- _e = _a.documentDetectionModelLoadTimeoutMs,
11760
- documentDetectionModelLoadTimeoutMs = _e === void 0 ? defaultDocumentDetectionModelLoadTimeoutMs : _e,
11799
+ _c = _a.throttleMs,
11800
+ throttleMs = _c === void 0 ? 16 : _c,
11801
+ _d = _a.documentDetectionModelPath,
11802
+ documentDetectionModelPath = _d === void 0 ? defaultDocumentDetectorModelPath : _d,
11803
+ _e = _a.documentDetectionModelScoreThreshold,
11804
+ documentDetectionModelScoreThreshold = _e === void 0 ? defaultDocumentDetectionScoreThreshold : _e,
11805
+ _f = _a.documentDetectionModelLoadTimeoutMs,
11806
+ documentDetectionModelLoadTimeoutMs = _f === void 0 ? defaultDocumentDetectionModelLoadTimeoutMs : _f,
11761
11807
  onDocumentDetectionModelError = _a.onDocumentDetectionModelError;
11762
- var _f = React.useContext(CameraStateContext),
11763
- videoRef = _f.videoRef,
11764
- videoLoaded = _f.videoLoaded,
11765
- cameraReady = _f.cameraReady;
11808
+ var _g = React.useContext(CameraStateContext),
11809
+ videoRef = _g.videoRef,
11810
+ videoLoaded = _g.videoLoaded,
11811
+ cameraReady = _g.cameraReady;
11766
11812
  var lastPredictionCanvas = React.useRef(null);
11767
11813
  var onPredictionHandler = React.useRef();
11768
- var _g = React.useState({}),
11769
- documentDetectionThresholds = _g[0],
11770
- setDocumentDetectionThresholds = _g[1];
11771
- var _h = React.useState(defaultDocumentDetectionBoundaries),
11772
- documentDetectionBoundaries = _h[0],
11773
- setDocumentDetectionBoundaries = _h[1];
11774
- var _j = React.useState(0),
11775
- detectionTime = _j[0],
11776
- setDetectionTime = _j[1];
11814
+ var _h = React.useState({}),
11815
+ documentDetectionThresholds = _h[0],
11816
+ setDocumentDetectionThresholds = _h[1];
11817
+ var _j = React.useState(defaultDocumentDetectionBoundaries),
11818
+ documentDetectionBoundaries = _j[0],
11819
+ setDocumentDetectionBoundaries = _j[1];
11777
11820
  var _k = React.useState(0),
11778
11821
  timesAllZero = _k[0],
11779
11822
  setTimesAllZero = _k[1];
@@ -11815,7 +11858,7 @@
11815
11858
  if (!prediction) return [3 /*break*/, 3];
11816
11859
  processedPrediction = processDocumentDetectorPrediction(prediction, documentDetectionThresholds, documentDetectionBoundaries);
11817
11860
  processedPrediction.frameId = frameId;
11818
- setDetectionTime(prediction.time);
11861
+ setLastDetectionAt(new Date().getTime());
11819
11862
  debug(processedPrediction);
11820
11863
  if (processedPrediction.allZero) setTimesAllZero(function (n) {
11821
11864
  return n + 1;
@@ -11858,7 +11901,7 @@
11858
11901
  documentDetectionModelError: modelError,
11859
11902
  documentDetectionModelDownloadProgress: modelDownloadProgress,
11860
11903
  onDocumentDetected: onDocumentDetected,
11861
- detectionTime: detectionTime,
11904
+ detectionTime: lastDetectionTime,
11862
11905
  documentDetectionThresholds: documentDetectionThresholds,
11863
11906
  setDocumentDetectionThresholds: setDocumentDetectionThresholds,
11864
11907
  documentDetectionBoundaries: documentDetectionBoundaries,
@@ -11866,7 +11909,7 @@
11866
11909
  documentDetectionLastPredictionCanvas: lastPredictionCanvas,
11867
11910
  clearDocumentDetectionLastPredictionCanvas: clearDocumentDetectionLastPredictionCanvas
11868
11911
  };
11869
- }, [start, stop, ready, modelError, modelDownloadProgress, onDocumentDetected, detectionTime, documentDetectionThresholds, documentDetectionBoundaries, clearDocumentDetectionLastPredictionCanvas]);
11912
+ }, [start, stop, ready, modelError, modelDownloadProgress, onDocumentDetected, documentDetectionThresholds, documentDetectionBoundaries, clearDocumentDetectionLastPredictionCanvas]);
11870
11913
  return /*#__PURE__*/React__namespace.createElement(DocumentDetectionModelContext.Provider, {
11871
11914
  value: value
11872
11915
  }, /*#__PURE__*/React__namespace.createElement(InvisibleCanvas, {
@@ -12287,6 +12330,7 @@
12287
12330
  detectionThresholdMet: false,
12288
12331
  documentInBounds: false,
12289
12332
  documentTooClose: false,
12333
+ documentIsStable: false,
12290
12334
  flipRequired: false,
12291
12335
  backDetectedFirst: false,
12292
12336
  idCardDetectedButNotAllowed: false,
@@ -12405,6 +12449,7 @@
12405
12449
  bestDocument = _d.bestDocument,
12406
12450
  documentInBounds = _d.documentInBounds,
12407
12451
  documentTooClose = _d.documentTooClose,
12452
+ documentIsStable = _d.documentIsStable,
12408
12453
  focusScore = _d.focusScore,
12409
12454
  focusThresholdMet = _d.focusThresholdMet,
12410
12455
  frameWidth = _d.frameWidth,
@@ -12426,7 +12471,7 @@
12426
12471
  if (state.captureState === 'capturing' && (flipRequired || backDetectedFirst)) {
12427
12472
  wrongDocumentTypePredictions += 1;
12428
12473
  }
12429
- var isGoodFrame = detectionThresholdMet && documentInBounds && !documentTooClose && !flipRequired && !backDetectedFirst && focusThresholdMet;
12474
+ var isGoodFrame = detectionThresholdMet && documentInBounds && !documentTooClose && !flipRequired && !backDetectedFirst && focusThresholdMet && documentIsStable;
12430
12475
  var goodFramesCount = state.goodFramesCount;
12431
12476
  if (isGoodFrame) {
12432
12477
  goodFramesCount += 1;
@@ -12461,6 +12506,7 @@
12461
12506
  detectionThresholdMet: detectionThresholdMet,
12462
12507
  documentInBounds: documentInBounds,
12463
12508
  documentTooClose: documentTooClose,
12509
+ documentIsStable: documentIsStable,
12464
12510
  flipRequired: flipRequired,
12465
12511
  backDetectedFirst: backDetectedFirst,
12466
12512
  idCardDetectedButNotAllowed: idCardDetectedButNotAllowed,
@@ -12880,6 +12926,7 @@
12880
12926
  'Document not detected': 'No se ha detectado el documento',
12881
12927
  'Document is not centered': 'Documento no centrado',
12882
12928
  'Document too close, please back up': 'Documento muy cerca, favor de alejarse',
12929
+ 'Please hold your ID document steady': 'Por favor, mantenga firme su documento de identidad',
12883
12930
  'Document out of focus – try improving the lighting': 'Documento no enfocado - hay que tratar de mejorar la iluminación',
12884
12931
  'ID card front detected - please flip your ID card': 'Anverso de ID detectado, por favor voltea tu identificación',
12885
12932
  'ID card back detected - please flip your ID card': 'Reverso de ID detectado, por favor voltea tu identificación',
@@ -15991,7 +16038,8 @@
15991
16038
  guidanceTooCloseText: 'Document too close, please back up',
15992
16039
  guidanceNotDetectedText: 'Document not detected',
15993
16040
  guidanceIdCardNotAllowedText: 'ID card detected, please scan a passport instead',
15994
- guidancePassportNotAllowedText: 'Passport detected, please scan an ID card instead'
16041
+ guidancePassportNotAllowedText: 'Passport detected, please scan an ID card instead',
16042
+ guidanceNotStableText: 'Please hold your ID document steady'
15995
16043
  });
15996
16044
  var debugScalingDetails = useDebugScalingDetails({
15997
16045
  enabled: debugMode,
@@ -16002,7 +16050,7 @@
16002
16050
  });
16003
16051
  var satisfied = state.isGoodFrame;
16004
16052
  if (typeof guidanceSatisfied === 'boolean') satisfied = guidanceSatisfied;
16005
- guidanceMessage || (guidanceMessage = satisfied ? verbiage.guidanceSatisfiedText : !state.detectionThresholdMet ? verbiage.guidanceNotDetectedText : state.backDetectedFirst ? verbiage.guidanceBackDetectedFirstText : state.flipRequired ? verbiage.guidancePleaseFlipText : state.idCardDetectedButNotAllowed ? verbiage.guidanceIdCardNotAllowedText : state.passportDetectedButNotAllowed ? verbiage.guidancePassportNotAllowedText : !state.documentInBounds ? verbiage.guidanceNotCenteredText : state.documentTooClose ? verbiage.guidanceTooCloseText : !state.focusThresholdMet ? verbiage.guidanceTooBlurryText : '');
16053
+ guidanceMessage || (guidanceMessage = satisfied ? verbiage.guidanceSatisfiedText : !state.detectionThresholdMet ? verbiage.guidanceNotDetectedText : state.backDetectedFirst ? verbiage.guidanceBackDetectedFirstText : state.flipRequired ? verbiage.guidancePleaseFlipText : state.idCardDetectedButNotAllowed ? verbiage.guidanceIdCardNotAllowedText : state.passportDetectedButNotAllowed ? verbiage.guidancePassportNotAllowedText : !state.documentInBounds ? verbiage.guidanceNotCenteredText : state.documentTooClose ? verbiage.guidanceTooCloseText : !state.focusThresholdMet ? verbiage.guidanceTooBlurryText : !state.documentIsStable ? verbiage.guidanceNotStableText : '');
16006
16054
  return /*#__PURE__*/React.createElement(PageContainer, {
16007
16055
  ref: ref,
16008
16056
  className: "flex ".concat((_h = classNames.container) !== null && _h !== void 0 ? _h : '')
@@ -16027,7 +16075,7 @@
16027
16075
  scaling: debugScalingDetails,
16028
16076
  flipX: !((_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.isRearFacing)
16029
16077
  });
16030
- }))), debugMode && ( /*#__PURE__*/React.createElement(DebugStatsPane, null, cameraRef.current ? ( /*#__PURE__*/React.createElement(React.Fragment, null, "\u2705 Camera: ", cameraRef.current.label, " (", cameraRef.current.width, "x", cameraRef.current.height, ")")) : '❌ Camera not ready', /*#__PURE__*/React.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.createElement("br", null), modelsReady ? ( /*#__PURE__*/React.createElement(React.Fragment, null, state.detectionThresholdMet ? '✅' : '❌', " Detected Document Type: ", state.detectedDocumentType, /*#__PURE__*/React.createElement("br", null), state.idCardFrontDetectionThresholdMet ? '✅' : '❌', " ID Card Front Score: ", state.idCardFrontDetectionScore.toFixed(3), /*#__PURE__*/React.createElement("br", null), state.idCardBackDetectionThresholdMet ? '✅' : '❌', " ID Card Back Score: ", state.idCardBackDetectionScore.toFixed(3), /*#__PURE__*/React.createElement("br", null), state.passportDetectionThresholdMet ? '✅' : '❌', " Passport Score: ", state.passportDetectionScore.toFixed(3), /*#__PURE__*/React.createElement("br", null), state.focusThresholdMet ? '✅' : '❌', " Focus Score:", ' ', state.focusScore.toFixed(3), /*#__PURE__*/React.createElement("br", null), state.documentInBounds ? '✅' : '❌', " Document In Bounds", /*#__PURE__*/React.createElement("br", null), state.goodFramesThresholdMet ? '✅' : '❌', " Good Frame Count:", ' ', state.goodFramesCount, "/", state.goodFramesThreshold)) : ( /*#__PURE__*/React.createElement(React.Fragment, null, "\u274C Models not ready")))));
16078
+ }))), debugMode && ( /*#__PURE__*/React.createElement(DebugStatsPane, null, cameraRef.current ? ( /*#__PURE__*/React.createElement(React.Fragment, null, "\u2705 Camera: ", cameraRef.current.label, " (", cameraRef.current.width, "x", cameraRef.current.height, ")")) : '❌ Camera not ready', /*#__PURE__*/React.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.createElement("br", null), modelsReady ? ( /*#__PURE__*/React.createElement(React.Fragment, null, state.detectionThresholdMet ? '✅' : '❌', " Detected Document Type: ", state.detectedDocumentType, /*#__PURE__*/React.createElement("br", null), state.idCardFrontDetectionThresholdMet ? '✅' : '❌', " ID Card Front Score: ", state.idCardFrontDetectionScore.toFixed(3), /*#__PURE__*/React.createElement("br", null), state.idCardBackDetectionThresholdMet ? '✅' : '❌', " ID Card Back Score: ", state.idCardBackDetectionScore.toFixed(3), /*#__PURE__*/React.createElement("br", null), state.passportDetectionThresholdMet ? '✅' : '❌', " Passport Score: ", state.passportDetectionScore.toFixed(3), /*#__PURE__*/React.createElement("br", null), state.focusThresholdMet ? '✅' : '❌', " Focus Score:", ' ', state.focusScore.toFixed(3), /*#__PURE__*/React.createElement("br", null), state.documentInBounds ? '✅' : '❌', " Document In Bounds", /*#__PURE__*/React.createElement("br", null), state.documentIsStable ? '✅' : '❌', " Document Is Stable", /*#__PURE__*/React.createElement("br", null), state.goodFramesThresholdMet ? '✅' : '❌', " Good Frame Count:", ' ', state.goodFramesCount, "/", state.goodFramesThreshold)) : ( /*#__PURE__*/React.createElement(React.Fragment, null, "\u274C Models not ready")))));
16031
16079
  };
16032
16080
  var timeSince = function timeSince(t) {
16033
16081
  if (!t) return 0;