idmission-web-sdk 1.0.103 → 1.0.104

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.
@@ -16,6 +16,7 @@ export type IdCapturePrediction = {
16
16
  bestDocumentOrPassport: DetectedObject | undefined;
17
17
  bestMrz: DetectedObject | undefined;
18
18
  bestPdf417: DetectedObject | undefined;
19
+ documentInBounds: boolean;
19
20
  focusScore: number;
20
21
  focusThresholdMet: boolean;
21
22
  focusPredictionTime: number;
@@ -28,7 +29,10 @@ export type IdCaptureThresholds = {
28
29
  passport?: number;
29
30
  mrz?: number;
30
31
  pdf417?: number;
31
- focus?: number;
32
+ focus?: {
33
+ desktop?: number;
34
+ mobile?: number;
35
+ };
32
36
  };
33
37
  export declare const PREDICTION_POSITIONS: {
34
38
  boxes: number;
@@ -46,7 +46,7 @@ var LanguageDetector__default = /*#__PURE__*/_interopDefaultLegacy(LanguageDetec
46
46
  var i18n__default = /*#__PURE__*/_interopDefaultLegacy(i18n);
47
47
  var SignatureCanvas__default = /*#__PURE__*/_interopDefaultLegacy(SignatureCanvas);
48
48
 
49
- var webSdkVersion = '1.0.103';
49
+ var webSdkVersion = '1.0.104';
50
50
 
51
51
  function getPlatform() {
52
52
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -8781,39 +8781,27 @@ var IdCaptureModelsProvider = function IdCaptureModelsProvider(_a) {
8781
8781
  var _c = React.useState(false),
8782
8782
  ready = _c[0],
8783
8783
  setReady = _c[1];
8784
- var _d = React.useState(0),
8785
- documentDetectionThreshold = _d[0],
8786
- setDocumentDetectionThreshold = _d[1];
8787
- var _e = React.useState(0),
8788
- passportDetectionThreshold = _e[0],
8789
- setPassportDetectionThreshold = _e[1];
8790
- var _f = React.useState(0),
8791
- mrzDetectionThreshold = _f[0],
8792
- setMrzDetectionThreshold = _f[1];
8793
- var _g = React.useState(0),
8794
- pdf417DetectionThreshold = _g[0],
8795
- setPdf417DetectionThreshold = _g[1];
8796
- var _h = React.useState(0),
8797
- focusThreshold = _h[0],
8798
- setFocusThreshold = _h[1];
8784
+ var _d = React.useState({}),
8785
+ thresholds = _d[0],
8786
+ setThresholds = _d[1];
8799
8787
  var working = React.useRef(false);
8800
8788
  var onPredictionHandler = React.useRef();
8801
8789
  var lastPredictionCanvas = React.useRef(null);
8790
+ var _e = React.useState(0),
8791
+ detectionTime = _e[0],
8792
+ setDetectionTime = _e[1];
8793
+ var _f = React.useState(0),
8794
+ focusPredictionTime = _f[0],
8795
+ setFocusPredictionTime = _f[1];
8796
+ var _g = React.useState(null),
8797
+ loadingError = _g[0],
8798
+ setLoadingError = _g[1];
8799
+ var _h = React.useState(0),
8800
+ bestFrameDetectionScore = _h[0],
8801
+ setBestFrameDetectionScore = _h[1];
8802
8802
  var _j = React.useState(0),
8803
- detectionTime = _j[0],
8804
- setDetectionTime = _j[1];
8805
- var _k = React.useState(0),
8806
- focusPredictionTime = _k[0],
8807
- setFocusPredictionTime = _k[1];
8808
- var _l = React.useState(null),
8809
- loadingError = _l[0],
8810
- setLoadingError = _l[1];
8811
- var _m = React.useState(0),
8812
- bestFrameDetectionScore = _m[0],
8813
- setBestFrameDetectionScore = _m[1];
8814
- var _o = React.useState(0),
8815
- bestFrameFocusScore = _o[0],
8816
- setBestFrameFocusScore = _o[1];
8803
+ bestFrameFocusScore = _j[0],
8804
+ setBestFrameFocusScore = _j[1];
8817
8805
  React.useEffect(function () {
8818
8806
  setReady(false);
8819
8807
  var ddmUrl = documentDetectionModelUrl || defaultDocumentDetectionModelUrl;
@@ -8875,25 +8863,9 @@ var IdCaptureModelsProvider = function IdCaptureModelsProvider(_a) {
8875
8863
  (_a = webGLCanvas.removeEventListener) === null || _a === void 0 ? void 0 : _a.call(webGLCanvas, 'webglcontextlost', reloadModels);
8876
8864
  };
8877
8865
  }, [documentDetectionModelUrl, focusModelUrl]);
8878
- var thresholds = React.useMemo(function () {
8879
- return {
8880
- document: documentDetectionThreshold,
8881
- passport: passportDetectionThreshold,
8882
- mrz: mrzDetectionThreshold,
8883
- pdf417: pdf417DetectionThreshold,
8884
- focus: focusThreshold
8885
- };
8886
- }, [documentDetectionThreshold, focusThreshold, mrzDetectionThreshold, passportDetectionThreshold, pdf417DetectionThreshold]);
8887
- var setThresholds = React.useCallback(function (thresholds) {
8888
- if (thresholds.document) setDocumentDetectionThreshold(thresholds.document);
8889
- if (thresholds.passport) setPassportDetectionThreshold(thresholds.passport);
8890
- if (thresholds.mrz) setMrzDetectionThreshold(thresholds.mrz);
8891
- if (thresholds.pdf417) setPdf417DetectionThreshold(thresholds.pdf417);
8892
- if (thresholds.focus) setFocusThreshold(thresholds.focus);
8893
- }, []);
8894
- var _p = React.useState(0),
8895
- timesAllZero = _p[0],
8896
- setTimesAllZero = _p[1];
8866
+ var _k = React.useState(0),
8867
+ timesAllZero = _k[0],
8868
+ setTimesAllZero = _k[1];
8897
8869
  var bestPredictionCanvas = React.useRef(null);
8898
8870
  var bestFocusScore = React.useRef(0);
8899
8871
  var makePrediction = React.useCallback(function (frame) {
@@ -8977,22 +8949,23 @@ var IdCaptureModelsProvider = function IdCaptureModelsProvider(_a) {
8977
8949
  ref: bestPredictionCanvas
8978
8950
  }));
8979
8951
  };
8952
+ var onMobile = isMobile();
8980
8953
  function makePredictions(frame, lastPredictionCanvas, thresholds, logPredictions) {
8981
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
8954
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
8982
8955
  if (logPredictions === void 0) {
8983
8956
  logPredictions = false;
8984
8957
  }
8985
8958
  return tslib.__awaiter(this, void 0, void 0, function () {
8986
- var _l, frameWidth, frameHeight, _o, boxes, scores, labels, time, allZero, detectedObjects, bestDocument, bestPassportPage, bestDocumentScore, passportDetectionScore, passportDetectionThresholdMet, bestDocumentOrPassport, detectionScore, detectionThresholdMet, detectedDocumentType, bestMrz, mrzDetectionScore, mrzDetectionThresholdMet, bestPdf417, pdf417DetectionScore, pdf417DetectionThresholdMet, focusPrediction, focusPredictionTime, focusScore, focusThresholdMet;
8987
- var _p;
8988
- return tslib.__generator(this, function (_q) {
8989
- switch (_q.label) {
8959
+ var _o, frameWidth, frameHeight, _q, boxes, scores, labels, time, allZero, detectedObjects, bestDocument, bestPassportPage, bestDocumentScore, passportDetectionScore, passportDetectionThresholdMet, bestDocumentOrPassport, detectionScore, detectionThresholdMet, detectedDocumentType, bestMrz, mrzDetectionScore, mrzDetectionThresholdMet, bestPdf417, pdf417DetectionScore, pdf417DetectionThresholdMet, documentInBounds, boundaryPx, _r, boundaryX, boundaryY, boundaryWidth, boundaryHeight, focusPrediction, focusPredictionTime, focusScore, focusThresholdMet, focusThreshold;
8960
+ var _s;
8961
+ return tslib.__generator(this, function (_t) {
8962
+ switch (_t.label) {
8990
8963
  case 0:
8991
- _l = getFrameDimensions(frame), frameWidth = _l[0], frameHeight = _l[1];
8964
+ _o = getFrameDimensions(frame), frameWidth = _o[0], frameHeight = _o[1];
8992
8965
  drawToCanvas(lastPredictionCanvas, frame);
8993
8966
  return [4 /*yield*/, makeDocumentDetectionPredictions(frame, logPredictions)];
8994
8967
  case 1:
8995
- _o = _q.sent(), boxes = _o.boxes, scores = _o.scores, labels = _o.labels, time = _o.time;
8968
+ _q = _t.sent(), boxes = _q.boxes, scores = _q.scores, labels = _q.labels, time = _q.time;
8996
8969
  allZero = boxes.length > 0 && !boxes.some(function (box) {
8997
8970
  return box.some(function (n) {
8998
8971
  return n > 0;
@@ -9029,14 +9002,31 @@ function makePredictions(frame, lastPredictionCanvas, thresholds, logPredictions
9029
9002
  });
9030
9003
  pdf417DetectionScore = (_g = bestPdf417 === null || bestPdf417 === void 0 ? void 0 : bestPdf417.score) !== null && _g !== void 0 ? _g : 0;
9031
9004
  pdf417DetectionThresholdMet = pdf417DetectionScore >= ((_h = thresholds.pdf417) !== null && _h !== void 0 ? _h : 0);
9005
+ documentInBounds = false;
9006
+ if (bestDocumentOrPassport) {
9007
+ boundaryPx = 20;
9008
+ _r = bestDocumentOrPassport.bbox, boundaryX = _r[0], boundaryY = _r[1], boundaryWidth = _r[2], boundaryHeight = _r[3];
9009
+ boundaryX *= frameWidth;
9010
+ boundaryWidth *= frameWidth;
9011
+ boundaryY *= frameHeight;
9012
+ boundaryHeight *= frameHeight;
9013
+ documentInBounds = boundaryY > boundaryPx &&
9014
+ // Is it valid top edge of ID detected?
9015
+ boundaryY + boundaryHeight + boundaryPx < frameHeight && (
9016
+ // Is it valid bottom edge less than max video height
9017
+ boundaryX > boundaryPx || boundaryX < boundaryPx && boundaryX + boundaryWidth > frameWidth * 0.8) &&
9018
+ // If either the left side visible or if not, right edge of ID should be more than 80% of width.
9019
+ boundaryX + boundaryWidth + boundaryPx < frameWidth; // Valid right edge if it's less than video width.
9020
+ }
9032
9021
  focusPrediction = null, focusPredictionTime = 0, focusScore = 0, focusThresholdMet = false;
9033
- if (!detectionThresholdMet) return [3 /*break*/, 3];
9022
+ if (!(detectionThresholdMet && documentInBounds)) return [3 /*break*/, 3];
9034
9023
  return [4 /*yield*/, makeFocusPrediction(frame, bestDocumentOrPassport === null || bestDocumentOrPassport === void 0 ? void 0 : bestDocumentOrPassport.bbox, logPredictions)];
9035
9024
  case 2:
9036
- _p = _q.sent(), focusPrediction = _p[0], focusPredictionTime = _p[1];
9025
+ _s = _t.sent(), focusPrediction = _s[0], focusPredictionTime = _s[1];
9037
9026
  focusScore = (_j = focusPrediction === null || focusPrediction === void 0 ? void 0 : focusPrediction[1]) !== null && _j !== void 0 ? _j : 0;
9038
- focusThresholdMet = focusScore >= ((_k = thresholds.focus) !== null && _k !== void 0 ? _k : 0);
9039
- _q.label = 3;
9027
+ focusThreshold = (_m = onMobile ? (_k = thresholds.focus) === null || _k === void 0 ? void 0 : _k.mobile : (_l = thresholds.focus) === null || _l === void 0 ? void 0 : _l.desktop) !== null && _m !== void 0 ? _m : 0;
9028
+ focusThresholdMet = focusScore >= focusThreshold;
9029
+ _t.label = 3;
9040
9030
  case 3:
9041
9031
  return [2 /*return*/, {
9042
9032
  detectedObjects: detectedObjects,
@@ -9053,6 +9043,7 @@ function makePredictions(frame, lastPredictionCanvas, thresholds, logPredictions
9053
9043
  bestDocumentOrPassport: bestDocumentOrPassport,
9054
9044
  bestMrz: bestMrz,
9055
9045
  bestPdf417: bestPdf417,
9046
+ documentInBounds: documentInBounds,
9056
9047
  focusScore: focusScore,
9057
9048
  focusThresholdMet: focusThresholdMet,
9058
9049
  focusPredictionTime: focusPredictionTime,
@@ -9722,6 +9713,7 @@ var reducer$5 = function reducer(state, action) {
9722
9713
  bestDocumentOrPassport = _a.bestDocumentOrPassport,
9723
9714
  bestMrz = _a.bestMrz,
9724
9715
  bestPdf417 = _a.bestPdf417,
9716
+ documentInBounds = _a.documentInBounds,
9725
9717
  focusScore = _a.focusScore,
9726
9718
  focusThresholdMet = _a.focusThresholdMet,
9727
9719
  frameWidth = _a.frameWidth,
@@ -9735,26 +9727,6 @@ var reducer$5 = function reducer(state, action) {
9735
9727
  goodFramesThreshold = Math.ceil(3 * frameCaptureRate);
9736
9728
  }
9737
9729
  }
9738
- var documentInBounds = false;
9739
- if (bestDocumentOrPassport) {
9740
- var boundaryPx = 20;
9741
- var _b = bestDocumentOrPassport.bbox,
9742
- boundaryX = _b[0],
9743
- boundaryY = _b[1],
9744
- boundaryWidth = _b[2],
9745
- boundaryHeight = _b[3];
9746
- boundaryX *= frameWidth;
9747
- boundaryWidth *= frameWidth;
9748
- boundaryY *= frameHeight;
9749
- boundaryHeight *= frameHeight;
9750
- documentInBounds = boundaryY > boundaryPx &&
9751
- // Is it valid top edge of ID detected?
9752
- boundaryY + boundaryHeight + boundaryPx < frameHeight && (
9753
- // Is it valid bottom edge less than max video height
9754
- boundaryX > boundaryPx || boundaryX < boundaryPx && boundaryX + boundaryWidth > frameWidth * 0.8) &&
9755
- // If either the left side visible or if not, right edge of ID should be more than 80% of width.
9756
- boundaryX + boundaryWidth + boundaryPx < frameWidth; // Valid right edge if it's less than video width.
9757
- }
9758
9730
  var barcodeScanRequired = state.autoCaptureBarcodeRequired === true || state.autoCaptureBarcodeRequired === 'mobile' && isMobile();
9759
9731
  var shouldScanBarcode = state.barcodeScanningEnabled && pdf417DetectionThresholdMet && barcodeScanRequired;
9760
9732
  var waitingForBarcodeScan = shouldScanBarcode && !state.barcodeResult;
@@ -9925,7 +9897,9 @@ var IdCapture = function IdCapture(_a) {
9925
9897
  passport: passportPageDetectionThreshold,
9926
9898
  mrz: mrzDetectionScoreThreshold,
9927
9899
  pdf417: pdf417DetectionThreshold,
9928
- focus: focusScoreThreshold
9900
+ focus: {
9901
+ mobile: focusScoreThreshold
9902
+ }
9929
9903
  });
9930
9904
  }, [requiredDocumentType, autoCaptureScoreThreshold, focusScoreThreshold, mrzDetectionScoreThreshold, autoCaptureGoodFramesRequired, autoCaptureBarcodeRequired, barcodeScanningEnabled, maxBarcodeScanAttempts, passportPageDetectionThreshold, pdf417DetectionThreshold, resetBestFrame, setThresholds]);
9931
9905
  var animationFrame = React.useRef(0);
@@ -13592,7 +13566,9 @@ var IdVideoCapture = function IdVideoCapture(_a) {
13592
13566
  setThresholds({
13593
13567
  document: idCardFrontDetectionThreshold,
13594
13568
  passport: 1,
13595
- focus: idCardFrontFocusThreshold
13569
+ focus: {
13570
+ mobile: idCardFrontFocusThreshold
13571
+ }
13596
13572
  });
13597
13573
  }, [idCardFrontDetectionThreshold, idCardFrontFocusThreshold, setThresholds]);
13598
13574
  var _4 = React.useState(0),