idmission-web-sdk 1.0.174 → 1.0.176

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.
@@ -1,5 +1,6 @@
1
1
  import React, { MutableRefObject, ReactElement, ReactNode } from 'react';
2
2
  import { DetectedObject, DocumentType } from '../../lib/models/DocumentDetection';
3
+ import { FocusPrediction } from '../../lib/models/Focus';
3
4
  import { Frame } from '../../lib/utils/getFrameDimensions';
4
5
  export type IdCapturePrediction = {
5
6
  detectedObjects: DetectedObject[];
@@ -63,4 +64,13 @@ export type IdCaptureModelsProviderProps = {
63
64
  focusModelUrl?: string | undefined;
64
65
  logPredictions?: boolean;
65
66
  };
67
+ export declare const defaultDocumentDetectionModelUrl: string;
68
+ export declare const defaultFocusModelUrl: string;
66
69
  export declare const IdCaptureModelsProvider: ({ children, documentDetectionModelUrl, focusModelUrl, logPredictions, }: IdCaptureModelsProviderProps) => ReactElement;
70
+ type Canvases = {
71
+ lastPredictionCanvas: HTMLCanvasElement;
72
+ cropCanvas: HTMLCanvasElement;
73
+ rotateCanvas: HTMLCanvasElement;
74
+ };
75
+ export declare function makeFocusPrediction(imageData: Frame, canvases: Canvases, bbox?: number[], logPredictions?: boolean): Promise<[FocusPrediction, number]>;
76
+ export {};
@@ -48,7 +48,7 @@ var LanguageDetector__default = /*#__PURE__*/_interopDefaultLegacy(LanguageDetec
48
48
  var i18n__default = /*#__PURE__*/_interopDefaultLegacy(i18n);
49
49
  var SignatureCanvas__default = /*#__PURE__*/_interopDefaultLegacy(SignatureCanvas);
50
50
 
51
- var webSdkVersion = '1.0.174';
51
+ var webSdkVersion = '1.0.176';
52
52
 
53
53
  function getPlatform() {
54
54
  if (typeof window === 'undefined') return;
@@ -8683,7 +8683,7 @@ var IdCaptureModelsContext = /*#__PURE__*/React.createContext({
8683
8683
  bestFrameFocusScore: 0
8684
8684
  });
8685
8685
  var defaultDocumentDetectionModelUrl = "".concat(DEFAULT_CDN_URL, "/models/docdetect20240207/model.json");
8686
- var defaultFocusModelUrl = "".concat(DEFAULT_CDN_URL, "/models/focus/model.json");
8686
+ var defaultFocusModelUrl = "".concat(DEFAULT_CDN_URL, "/models/focus20240212/model.json");
8687
8687
  var IdCaptureModelsProvider = function IdCaptureModelsProvider(_a) {
8688
8688
  var children = _a.children,
8689
8689
  documentDetectionModelUrl = _a.documentDetectionModelUrl,
@@ -8698,6 +8698,8 @@ var IdCaptureModelsProvider = function IdCaptureModelsProvider(_a) {
8698
8698
  setThresholds = _d[1];
8699
8699
  var working = React.useRef(false);
8700
8700
  var onPredictionHandler = React.useRef();
8701
+ var cropCanvas = React.useRef(null);
8702
+ var rotateCanvas = React.useRef(null);
8701
8703
  var lastPredictionCanvas = React.useRef(null);
8702
8704
  var _e = React.useState(0),
8703
8705
  detectionTime = _e[0],
@@ -8787,13 +8789,18 @@ var IdCaptureModelsProvider = function IdCaptureModelsProvider(_a) {
8787
8789
  working.current = true;
8788
8790
  (function () {
8789
8791
  return tslib.__awaiter(void 0, void 0, void 0, function () {
8790
- var prediction;
8792
+ var canvases, prediction;
8791
8793
  var _a, _b, _c;
8792
8794
  return tslib.__generator(this, function (_d) {
8793
8795
  switch (_d.label) {
8794
8796
  case 0:
8795
- if (!documentDetectionModel || !focusModel || !lastPredictionCanvas.current) return [2 /*return*/];
8796
- return [4 /*yield*/, makePredictions(frame, lastPredictionCanvas.current, thresholds, logPredictions)];
8797
+ if (!documentDetectionModel || !focusModel || !lastPredictionCanvas.current || !cropCanvas.current || !rotateCanvas.current) return [2 /*return*/];
8798
+ canvases = {
8799
+ lastPredictionCanvas: lastPredictionCanvas.current,
8800
+ cropCanvas: cropCanvas.current,
8801
+ rotateCanvas: rotateCanvas.current
8802
+ };
8803
+ return [4 /*yield*/, makePredictions(frame, thresholds, canvases, logPredictions)];
8797
8804
  case 1:
8798
8805
  prediction = _d.sent();
8799
8806
  setDetectionTime(prediction.detectionTime);
@@ -8864,25 +8871,29 @@ var IdCaptureModelsProvider = function IdCaptureModelsProvider(_a) {
8864
8871
  ref: lastPredictionCanvas
8865
8872
  }), /*#__PURE__*/React__default['default'].createElement(InvisibleCanvas, {
8866
8873
  ref: bestPredictionCanvas
8874
+ }), /*#__PURE__*/React__default['default'].createElement(InvisibleCanvas, {
8875
+ ref: cropCanvas
8876
+ }), /*#__PURE__*/React__default['default'].createElement(InvisibleCanvas, {
8877
+ ref: rotateCanvas
8867
8878
  }));
8868
8879
  };
8869
8880
  var onMobile = isMobile();
8870
- function makePredictions(frame, lastPredictionCanvas, thresholds, logPredictions) {
8881
+ function makePredictions(frame, thresholds, canvases, logPredictions) {
8871
8882
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
8872
8883
  if (logPredictions === void 0) {
8873
8884
  logPredictions = false;
8874
8885
  }
8875
8886
  return tslib.__awaiter(this, void 0, void 0, function () {
8876
- 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, documentTooClose, _s, docWidth, docHeight, focusPrediction, focusPredictionTime, focusScore, focusThresholdMet, focusThreshold;
8877
- var _t;
8878
- return tslib.__generator(this, function (_u) {
8879
- switch (_u.label) {
8887
+ var _o, frameWidth, frameHeight, _p, boxes, scores, labels, time, allZero, detectedObjects, bestDocument, bestPassportPage, bestDocumentScore, passportDetectionScore, passportDetectionThresholdMet, bestDocumentOrPassport, detectionScore, detectionThresholdMet, detectedDocumentType, bestMrz, mrzDetectionScore, mrzDetectionThresholdMet, bestPdf417, pdf417DetectionScore, pdf417DetectionThresholdMet, documentInBounds, boundaryPx, _q, boundaryX, boundaryY, boundaryWidth, boundaryHeight, documentTooClose, _r, docWidth, docHeight, focusPrediction, focusPredictionTime, focusScore, focusThresholdMet, focusThreshold;
8888
+ var _s;
8889
+ return tslib.__generator(this, function (_t) {
8890
+ switch (_t.label) {
8880
8891
  case 0:
8881
8892
  _o = getFrameDimensions(frame), frameWidth = _o[0], frameHeight = _o[1];
8882
- drawToCanvas(lastPredictionCanvas, frame);
8893
+ drawToCanvas(canvases.lastPredictionCanvas, frame);
8883
8894
  return [4 /*yield*/, makeDocumentDetectionPredictions(frame, logPredictions)];
8884
8895
  case 1:
8885
- _q = _u.sent(), boxes = _q.boxes, scores = _q.scores, labels = _q.labels, time = _q.time;
8896
+ _p = _t.sent(), boxes = _p.boxes, scores = _p.scores, labels = _p.labels, time = _p.time;
8886
8897
  allZero = boxes.length > 0 && !boxes.some(function (box) {
8887
8898
  return box.some(function (n) {
8888
8899
  return n > 0;
@@ -8922,7 +8933,7 @@ function makePredictions(frame, lastPredictionCanvas, thresholds, logPredictions
8922
8933
  documentInBounds = false;
8923
8934
  if (bestDocumentOrPassport) {
8924
8935
  boundaryPx = 20;
8925
- _r = bestDocumentOrPassport.bbox, boundaryX = _r[0], boundaryY = _r[1], boundaryWidth = _r[2], boundaryHeight = _r[3];
8936
+ _q = bestDocumentOrPassport.bbox, boundaryX = _q[0], boundaryY = _q[1], boundaryWidth = _q[2], boundaryHeight = _q[3];
8926
8937
  boundaryX *= frameWidth;
8927
8938
  boundaryWidth *= frameWidth;
8928
8939
  boundaryY *= frameHeight;
@@ -8937,18 +8948,18 @@ function makePredictions(frame, lastPredictionCanvas, thresholds, logPredictions
8937
8948
  }
8938
8949
  documentTooClose = false;
8939
8950
  if (bestDocumentOrPassport) {
8940
- _s = [bestDocumentOrPassport.bbox[2], bestDocumentOrPassport.bbox[3]], docWidth = _s[0], docHeight = _s[1];
8951
+ _r = [bestDocumentOrPassport.bbox[2], bestDocumentOrPassport.bbox[3]], docWidth = _r[0], docHeight = _r[1];
8941
8952
  documentTooClose = docWidth > 0.85 || docHeight > 0.85;
8942
8953
  }
8943
8954
  focusPrediction = null, focusPredictionTime = 0, focusScore = 0, focusThresholdMet = false;
8944
8955
  if (!(detectionThresholdMet && documentInBounds && !documentTooClose)) return [3 /*break*/, 3];
8945
- return [4 /*yield*/, makeFocusPrediction(frame, bestDocumentOrPassport === null || bestDocumentOrPassport === void 0 ? void 0 : bestDocumentOrPassport.bbox, logPredictions)];
8956
+ return [4 /*yield*/, makeFocusPrediction(frame, canvases, bestDocumentOrPassport === null || bestDocumentOrPassport === void 0 ? void 0 : bestDocumentOrPassport.bbox, logPredictions)];
8946
8957
  case 2:
8947
- _t = _u.sent(), focusPrediction = _t[0], focusPredictionTime = _t[1];
8958
+ _s = _t.sent(), focusPrediction = _s[0], focusPredictionTime = _s[1];
8948
8959
  focusScore = (_j = focusPrediction === null || focusPrediction === void 0 ? void 0 : focusPrediction[1]) !== null && _j !== void 0 ? _j : 0;
8949
8960
  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;
8950
8961
  focusThresholdMet = focusScore >= focusThreshold;
8951
- _u.label = 3;
8962
+ _t.label = 3;
8952
8963
  case 3:
8953
8964
  return [2 /*return*/, {
8954
8965
  detectedObjects: detectedObjects,
@@ -9058,7 +9069,7 @@ function makeDocumentDetectionPredictions(image, logPredictions) {
9058
9069
  });
9059
9070
  });
9060
9071
  }
9061
- function makeFocusPrediction(imageData, bbox, logPredictions) {
9072
+ function makeFocusPrediction(imageData, canvases, bbox, logPredictions) {
9062
9073
  if (logPredictions === void 0) {
9063
9074
  logPredictions = false;
9064
9075
  }
@@ -9076,19 +9087,19 @@ function makeFocusPrediction(imageData, bbox, logPredictions) {
9076
9087
  _g.trys.push([1, 5,, 6]);
9077
9088
  tfImg = void 0;
9078
9089
  if (bbox) {
9079
- cropped = cropToBoundingBox(imageData, bbox);
9090
+ cropped = cropToBoundingBox(imageData, bbox, canvases.cropCanvas);
9080
9091
  _a = getFrameDimensions(imageData), fw = _a[0], fh = _a[1];
9081
9092
  _b = [bbox[2] * fw, bbox[3] * fh], bw = _b[0], bh = _b[1];
9082
9093
  if (bh > bw) {
9083
- rotated = document.createElement('canvas');
9094
+ rotated = canvases.rotateCanvas;
9084
9095
  ctx = rotated.getContext('2d');
9085
9096
  if (ctx) {
9086
9097
  rotated.width = bh;
9087
9098
  rotated.height = bw;
9088
9099
  ctx.clearRect(0, 0, rotated.width, rotated.height);
9089
- ctx.translate(rotated.height / 2, rotated.width / 2);
9100
+ ctx.translate(rotated.width / 2, rotated.height / 2);
9090
9101
  ctx.rotate(1.5708); // 90 deg in radians
9091
- ctx.drawImage(cropped, -rotated.width / 2, -rotated.height / 2);
9102
+ ctx.drawImage(cropped, -bw / 2, -bh / 2);
9092
9103
  cropped = rotated;
9093
9104
  }
9094
9105
  }