idmission-web-sdk 2.1.36 → 2.1.38

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.
@@ -38,6 +38,8 @@ export type IdCaptureState = {
38
38
  idCardBackDetectionThresholdMet: boolean;
39
39
  passportDetectionScore: number;
40
40
  passportDetectionThresholdMet: boolean;
41
+ singlePageDetectionScore: number;
42
+ singlePageDetectionThresholdMet: boolean;
41
43
  focusScore: number;
42
44
  focusThresholdMet: boolean;
43
45
  isGoodFrame: boolean;
@@ -1,16 +1,17 @@
1
1
  import { ObjectDetector, ObjectDetectorResult } from '@mediapipe/tasks-vision';
2
- export declare const defaultDocumentDetectorModelPath = "https://websdk-cdn-dev.idmission.com/assets/models/docdetectmp20240825/model_fp16.tflite";
2
+ export declare const defaultDocumentDetectorModelPath = "https://websdk-cdn-dev.idmission.com/assets/models/docdetectmp20240830/model_fp16.tflite";
3
3
  export declare const defaultDocumentDetectionScoreThreshold = 0.1;
4
4
  export declare const defaultDocumentDetectionModelLoadTimeoutMs = 45000;
5
5
  export declare const defaultDocumentDetectionThresholds: DocumentDetectionThresholds;
6
- export type DocumentType = 'none' | 'idCardFront' | 'idCardBack' | 'passport';
6
+ export type DocumentType = 'none' | 'idCardFront' | 'idCardBack' | 'passport' | 'singlePage';
7
7
  export declare const documentTypeDisplayNames: {
8
8
  idCardFront: string;
9
9
  idCardBack: string;
10
10
  passport: string;
11
+ singlePage: string;
11
12
  none: string;
12
13
  };
13
- export type Label = 'Document' | 'Document back' | 'MRZ' | 'PDF417' | 'Primary face' | 'Secondary face' | 'Glare' | 'Punch Hole' | 'Passport page';
14
+ export type Label = 'Document' | 'Document back' | 'MRZ' | 'PDF417' | 'Primary face' | 'Secondary face' | 'Glare' | 'Punch Hole' | 'Passport page' | 'Single page';
14
15
  export type DetectedObjectBox = {
15
16
  xMin: number;
16
17
  xMax: number;
@@ -28,6 +29,7 @@ export type DocumentDetectionThresholds = {
28
29
  idCardFront?: number;
29
30
  idCardBack?: number;
30
31
  passport?: number;
32
+ singlePage?: number;
31
33
  };
32
34
  export declare function loadDocumentDetector(modelAssetPath?: string, scoreThreshold?: number): Promise<ObjectDetector>;
33
35
  export declare function useLoadDocumentDetector({ modelPath, modelLoadTimeoutMs, scoreThreshold, onModelError, }: {
@@ -54,6 +56,8 @@ export type DocumentDetectionPrediction = {
54
56
  idCardBackDetectionThresholdMet: boolean;
55
57
  passportDetectionScore: number;
56
58
  passportDetectionThresholdMet: boolean;
59
+ singlePageDetectionScore: number;
60
+ singlePageDetectionThresholdMet: boolean;
57
61
  bestDocument: DetectedObject | undefined;
58
62
  documentInBounds: boolean;
59
63
  documentTooClose: boolean;
@@ -20,6 +20,10 @@ export type FocusThresholds = {
20
20
  desktop?: number;
21
21
  mobile?: number;
22
22
  };
23
+ singlePage?: {
24
+ desktop?: number;
25
+ mobile?: number;
26
+ };
23
27
  };
24
28
  export declare const defaultFocusThresholds: FocusThresholds;
25
29
  export declare function loadFocusModel(modelAssetPath: string): Promise<ImageClassifier>;
@@ -234,7 +234,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
234
234
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
235
235
  };
236
236
 
237
- var webSdkVersion = '2.1.36';
237
+ var webSdkVersion = '2.1.38';
238
238
 
239
239
  function getPlatform() {
240
240
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -2696,6 +2696,10 @@ var defaultFocusThresholds = {
2696
2696
  passport: {
2697
2697
  desktop: 0,
2698
2698
  mobile: 0.3
2699
+ },
2700
+ singlePage: {
2701
+ desktop: 0,
2702
+ mobile: 0.3
2699
2703
  }
2700
2704
  };
2701
2705
  var models = {};
@@ -5359,18 +5363,20 @@ function sumUpProgressForDependencies(dependencies) {
5359
5363
  });
5360
5364
  }
5361
5365
 
5362
- var defaultDocumentDetectorModelPath = "https://websdk-cdn-dev.idmission.com/assets/models/docdetectmp20240825/model_fp16.tflite";
5366
+ var defaultDocumentDetectorModelPath = "https://websdk-cdn-dev.idmission.com/assets/models/docdetectmp20240830/model_fp16.tflite";
5363
5367
  var defaultDocumentDetectionScoreThreshold = 0.1;
5364
5368
  var defaultDocumentDetectionModelLoadTimeoutMs = 45000;
5365
5369
  var defaultDocumentDetectionThresholds = {
5366
5370
  idCardFront: 0.6,
5367
5371
  idCardBack: 0.6,
5368
- passport: 0.4
5372
+ passport: 0.4,
5373
+ singlePage: 0.6
5369
5374
  };
5370
5375
  var documentTypeDisplayNames = {
5371
5376
  idCardFront: 'ID card front',
5372
5377
  idCardBack: 'ID card back',
5373
5378
  passport: 'Passport',
5379
+ singlePage: 'Single page',
5374
5380
  none: 'None'
5375
5381
  };
5376
5382
  var detectors = {};
@@ -5506,7 +5512,7 @@ function makeDocumentDetectorPrediction(detector, frame) {
5506
5512
  });
5507
5513
  }
5508
5514
  function processDocumentDetectorPrediction(prediction, thresholds) {
5509
- var _a, _b, _c, _d, _e, _f, _g;
5515
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
5510
5516
  var detections = prediction.detections,
5511
5517
  frameWidth = prediction.frameWidth,
5512
5518
  frameHeight = prediction.frameHeight,
@@ -5535,19 +5541,26 @@ function processDocumentDetectorPrediction(prediction, thresholds) {
5535
5541
  var bestPassportPage = detectedObjects.find(function (obj) {
5536
5542
  return obj.label === 'Passport page';
5537
5543
  });
5544
+ var bestSinglePage = detectedObjects.find(function (obj) {
5545
+ return obj.label === 'Single page';
5546
+ });
5538
5547
  var idCardFrontDetectionScore = (_a = bestIdCardFront === null || bestIdCardFront === void 0 ? void 0 : bestIdCardFront.score) !== null && _a !== void 0 ? _a : 0;
5539
5548
  var idCardBackDetectionScore = (_b = bestIdCardBack === null || bestIdCardBack === void 0 ? void 0 : bestIdCardBack.score) !== null && _b !== void 0 ? _b : 0;
5540
5549
  var passportDetectionScore = (_c = bestPassportPage === null || bestPassportPage === void 0 ? void 0 : bestPassportPage.score) !== null && _c !== void 0 ? _c : 0;
5541
- var idCardFrontDetectionThresholdMet = idCardFrontDetectionScore >= ((_d = thresholds.idCardFront) !== null && _d !== void 0 ? _d : 0);
5542
- var idCardBackDetectionThresholdMet = idCardBackDetectionScore >= ((_e = thresholds.idCardBack) !== null && _e !== void 0 ? _e : 0);
5543
- var passportDetectionThresholdMet = passportDetectionScore >= ((_f = thresholds.passport) !== null && _f !== void 0 ? _f : 0);
5544
- var bestDocument = passportDetectionThresholdMet ? bestPassportPage : idCardBackDetectionThresholdMet ? bestIdCardBack : bestIdCardFront;
5545
- var detectionThreshold = passportDetectionThresholdMet ? thresholds.passport : idCardBackDetectionThresholdMet ? thresholds.idCardBack : thresholds.idCardFront;
5546
- var detectionScore = (_g = bestDocument === null || bestDocument === void 0 ? void 0 : bestDocument.score) !== null && _g !== void 0 ? _g : 0;
5550
+ var singlePageDetectionScore = (_d = bestSinglePage === null || bestSinglePage === void 0 ? void 0 : bestSinglePage.score) !== null && _d !== void 0 ? _d : 0;
5551
+ var idCardFrontDetectionThresholdMet = idCardFrontDetectionScore >= ((_e = thresholds.idCardFront) !== null && _e !== void 0 ? _e : 0);
5552
+ var idCardBackDetectionThresholdMet = idCardBackDetectionScore >= ((_f = thresholds.idCardBack) !== null && _f !== void 0 ? _f : 0);
5553
+ var passportDetectionThresholdMet = passportDetectionScore >= ((_g = thresholds.passport) !== null && _g !== void 0 ? _g : 0);
5554
+ var singlePageDetectionThresholdMet = singlePageDetectionScore >= ((_h = thresholds.singlePage) !== null && _h !== void 0 ? _h : 0);
5555
+ var bestDocument = passportDetectionThresholdMet ? bestPassportPage : singlePageDetectionThresholdMet ? bestSinglePage : idCardBackDetectionThresholdMet ? bestIdCardBack : bestIdCardFront;
5556
+ var detectionThreshold = passportDetectionThresholdMet ? thresholds.passport : singlePageDetectionThresholdMet ? thresholds.singlePage : idCardBackDetectionThresholdMet ? thresholds.idCardBack : thresholds.idCardFront;
5557
+ var detectionScore = (_j = bestDocument === null || bestDocument === void 0 ? void 0 : bestDocument.score) !== null && _j !== void 0 ? _j : 0;
5547
5558
  var detectionThresholdMet = detectionScore >= (detectionThreshold !== null && detectionThreshold !== void 0 ? detectionThreshold : 0);
5548
5559
  var detectedDocumentType = 'none';
5549
5560
  if (passportDetectionThresholdMet) {
5550
5561
  detectedDocumentType = 'passport';
5562
+ } else if (singlePageDetectionThresholdMet) {
5563
+ detectedDocumentType = 'singlePage';
5551
5564
  } else if (idCardBackDetectionThresholdMet) {
5552
5565
  detectedDocumentType = 'idCardBack';
5553
5566
  } else if (detectionThresholdMet) {
@@ -5556,11 +5569,11 @@ function processDocumentDetectorPrediction(prediction, thresholds) {
5556
5569
  var documentInBounds = false;
5557
5570
  if (bestDocument) {
5558
5571
  var boundaryPx = 20;
5559
- var _h = bestDocument.box,
5560
- boundaryX = _h.xMin,
5561
- boundaryY = _h.yMin,
5562
- boundaryWidth = _h.width,
5563
- boundaryHeight = _h.height;
5572
+ var _k = bestDocument.box,
5573
+ boundaryX = _k.xMin,
5574
+ boundaryY = _k.yMin,
5575
+ boundaryWidth = _k.width,
5576
+ boundaryHeight = _k.height;
5564
5577
  documentInBounds = boundaryY > boundaryPx &&
5565
5578
  // Is it valid top edge of ID detected?
5566
5579
  boundaryY + boundaryHeight + boundaryPx < frameHeight && (
@@ -5571,9 +5584,9 @@ function processDocumentDetectorPrediction(prediction, thresholds) {
5571
5584
  }
5572
5585
  var documentTooClose = false;
5573
5586
  if (bestDocument) {
5574
- var _j = [bestDocument.box.width / frameWidth, bestDocument.box.height / frameHeight],
5575
- docWidth = _j[0],
5576
- docHeight = _j[1];
5587
+ var _l = [bestDocument.box.width / frameWidth, bestDocument.box.height / frameHeight],
5588
+ docWidth = _l[0],
5589
+ docHeight = _l[1];
5577
5590
  documentTooClose = docWidth > 0.85 || docHeight > 0.85;
5578
5591
  }
5579
5592
  return {
@@ -5588,6 +5601,8 @@ function processDocumentDetectorPrediction(prediction, thresholds) {
5588
5601
  idCardBackDetectionThresholdMet: idCardBackDetectionThresholdMet,
5589
5602
  passportDetectionScore: passportDetectionScore,
5590
5603
  passportDetectionThresholdMet: passportDetectionThresholdMet,
5604
+ singlePageDetectionScore: singlePageDetectionScore,
5605
+ singlePageDetectionThresholdMet: singlePageDetectionThresholdMet,
5591
5606
  bestDocument: bestDocument,
5592
5607
  documentInBounds: documentInBounds,
5593
5608
  documentTooClose: documentTooClose,
@@ -6002,20 +6017,24 @@ function IdCaptureModelsProviderInner(_a) {
6002
6017
  var _this = this;
6003
6018
  onDocumentDetected(function (prediction) {
6004
6019
  return __awaiter(_this, void 0, void 0, function () {
6005
- var stopDetectionAtStart, focusPredictionTime, focusScore, focusThresholdMet, isRequiredDocumentType, focusPrediction, focusThresholdSet, focusThreshold;
6020
+ var stopDetectionAtStart, focusPredictionTime, focusScore, focusThresholdMet, detectedDocumentType, isRequiredDocumentType, focusPrediction, focusThresholdSet, focusThreshold;
6006
6021
  var _a, _b, _c, _d, _e, _f;
6007
6022
  return __generator(this, function (_g) {
6008
6023
  if (!lastPredictionCanvas.current) return [2 /*return*/];
6009
6024
  stopDetectionAtStart = stopDetection.current;
6010
6025
  focusPredictionTime = 0, focusScore = 0, focusThresholdMet = false;
6011
- isRequiredDocumentType = requiredDocumentType === 'none' || prediction.detectedDocumentType === requiredDocumentType || ((_a = requiredDocumentType.includes) === null || _a === void 0 ? void 0 : _a.call(requiredDocumentType, prediction.detectedDocumentType));
6012
- if (isRequiredDocumentType && prediction.detectedDocumentType !== 'none' && prediction.detectionThresholdMet && prediction.documentInBounds && !prediction.documentTooClose) {
6026
+ detectedDocumentType = prediction.detectedDocumentType;
6027
+ if (detectedDocumentType === 'singlePage') {
6028
+ detectedDocumentType = 'passport';
6029
+ }
6030
+ isRequiredDocumentType = requiredDocumentType === 'none' || detectedDocumentType === requiredDocumentType || ((_a = requiredDocumentType.includes) === null || _a === void 0 ? void 0 : _a.call(requiredDocumentType, detectedDocumentType));
6031
+ if (isRequiredDocumentType && detectedDocumentType !== 'none' && prediction.detectionThresholdMet && prediction.documentInBounds && !prediction.documentTooClose) {
6013
6032
  focusPrediction = makeFocusPrediction(lastPredictionCanvas.current, (_b = prediction.bestDocument) === null || _b === void 0 ? void 0 : _b.box);
6014
6033
  if (focusPrediction) {
6015
6034
  focusScore = focusPrediction.score;
6016
6035
  focusPredictionTime = focusPrediction.predictionTime;
6017
6036
  }
6018
- focusThresholdSet = (_c = thresholds.focus) === null || _c === void 0 ? void 0 : _c[prediction.detectedDocumentType];
6037
+ focusThresholdSet = (_c = thresholds.focus) === null || _c === void 0 ? void 0 : _c[detectedDocumentType];
6019
6038
  focusThreshold = (_d = onMobile ? focusThresholdSet === null || focusThresholdSet === void 0 ? void 0 : focusThresholdSet.mobile : focusThresholdSet === null || focusThresholdSet === void 0 ? void 0 : focusThresholdSet.desktop) !== null && _d !== void 0 ? _d : 0;
6020
6039
  focusThresholdMet = focusScore >= focusThreshold;
6021
6040
  if (bestFocusScore.current <= focusScore && stopDetectionAtStart === stopDetection.current) {
@@ -6023,7 +6042,7 @@ function IdCaptureModelsProviderInner(_a) {
6023
6042
  drawToCanvas(bestPredictionCanvas.current, lastPredictionCanvas.current);
6024
6043
  setBestFrameDetails({
6025
6044
  boundingBox: (_e = prediction.bestDocument) === null || _e === void 0 ? void 0 : _e.box,
6026
- documentType: prediction.detectedDocumentType,
6045
+ documentType: detectedDocumentType,
6027
6046
  detectionScore: prediction.detectionScore,
6028
6047
  focusScore: focusScore
6029
6048
  });
@@ -6151,6 +6170,8 @@ var initialState$4 = {
6151
6170
  idCardBackDetectionThresholdMet: false,
6152
6171
  passportDetectionScore: 0,
6153
6172
  passportDetectionThresholdMet: false,
6173
+ singlePageDetectionScore: 0,
6174
+ singlePageDetectionThresholdMet: false,
6154
6175
  focusScore: 0,
6155
6176
  focusThresholdMet: false,
6156
6177
  isGoodFrame: false,
@@ -6251,6 +6272,8 @@ var _reducer = function reducer(state, action) {
6251
6272
  idCardBackDetectionThresholdMet = _d.idCardBackDetectionThresholdMet,
6252
6273
  passportDetectionScore = _d.passportDetectionScore,
6253
6274
  passportDetectionThresholdMet = _d.passportDetectionThresholdMet,
6275
+ singlePageDetectionScore = _d.singlePageDetectionScore,
6276
+ singlePageDetectionThresholdMet = _d.singlePageDetectionThresholdMet,
6254
6277
  bestDocument = _d.bestDocument,
6255
6278
  documentInBounds = _d.documentInBounds,
6256
6279
  documentTooClose = _d.documentTooClose,
@@ -6288,10 +6311,10 @@ var _reducer = function reducer(state, action) {
6288
6311
  }
6289
6312
  }
6290
6313
  if (state.captureRequirement === 'idCardOrPassport') {
6291
- if (detectedDocumentType === 'passport' && state.requestedDocumentType !== 'passport') {
6314
+ if ((detectedDocumentType === 'passport' || detectedDocumentType === 'singlePage') && state.requestedDocumentType !== 'passport') {
6292
6315
  requestedDocumentType = 'passport';
6293
6316
  }
6294
- if (requestedDocumentType === 'passport' && passportDetectionScore < 0.3) {
6317
+ if (requestedDocumentType === 'passport' && !passportDetectionThresholdMet && !singlePageDetectionThresholdMet) {
6295
6318
  requestedDocumentType = 'idCardFront' in state.capturedDocuments ? 'idCardBack' : 'idCardFront';
6296
6319
  }
6297
6320
  }
@@ -6318,6 +6341,8 @@ var _reducer = function reducer(state, action) {
6318
6341
  idCardBackDetectionThresholdMet: idCardBackDetectionThresholdMet,
6319
6342
  passportDetectionScore: passportDetectionScore,
6320
6343
  passportDetectionThresholdMet: passportDetectionThresholdMet,
6344
+ singlePageDetectionScore: singlePageDetectionScore,
6345
+ singlePageDetectionThresholdMet: singlePageDetectionThresholdMet,
6321
6346
  focusScore: focusScore,
6322
6347
  focusThresholdMet: focusThresholdMet,
6323
6348
  isGoodFrame: isGoodFrame,
@@ -7082,7 +7107,7 @@ var IdCapture = function IdCapture(_a) {
7082
7107
  scaling: debugScalingDetails,
7083
7108
  flipX: !((_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.isRearFacing)
7084
7109
  });
7085
- }))), debugMode && ( /*#__PURE__*/React__namespace.default.createElement(DebugStatsPane, null, cameraRef.current ? ( /*#__PURE__*/React__namespace.default.createElement(React__namespace.default.Fragment, null, "\u2705 Camera: ", cameraRef.current.label, " (", cameraRef.current.width, "x", cameraRef.current.height, ")")) : '❌ Camera not ready', /*#__PURE__*/React__namespace.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__namespace.default.createElement("br", null), modelsReady ? ( /*#__PURE__*/React__namespace.default.createElement(React__namespace.default.Fragment, null, state.detectionThresholdMet ? '✅' : '❌', " Detected Document Type: ", state.detectedDocumentType, /*#__PURE__*/React__namespace.default.createElement("br", null), state.idCardFrontDetectionThresholdMet ? '✅' : '❌', " ID Card Front Score: ", state.idCardFrontDetectionScore.toFixed(3), /*#__PURE__*/React__namespace.default.createElement("br", null), state.idCardBackDetectionThresholdMet ? '✅' : '❌', " ID Card Back Score: ", state.idCardBackDetectionScore.toFixed(3), /*#__PURE__*/React__namespace.default.createElement("br", null), state.passportDetectionThresholdMet ? '✅' : '❌', " Passport Score: ", state.passportDetectionScore.toFixed(3), /*#__PURE__*/React__namespace.default.createElement("br", null), state.focusThresholdMet ? '✅' : '❌', " Focus Score:", ' ', state.focusScore.toFixed(3), /*#__PURE__*/React__namespace.default.createElement("br", null), state.documentInBounds ? '✅' : '❌', " Document In Bounds", /*#__PURE__*/React__namespace.default.createElement("br", null), state.goodFramesThresholdMet ? '✅' : '❌', " Good Frame Count:", ' ', state.goodFramesCount, "/", state.goodFramesThreshold)) : ( /*#__PURE__*/React__namespace.default.createElement(React__namespace.default.Fragment, null, "\u274C Models not ready")))));
7110
+ }))), debugMode && ( /*#__PURE__*/React__namespace.default.createElement(DebugStatsPane, null, cameraRef.current ? ( /*#__PURE__*/React__namespace.default.createElement(React__namespace.default.Fragment, null, "\u2705 Camera: ", cameraRef.current.label, " (", cameraRef.current.width, "x", cameraRef.current.height, ")")) : '❌ Camera not ready', /*#__PURE__*/React__namespace.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__namespace.default.createElement("br", null), modelsReady ? ( /*#__PURE__*/React__namespace.default.createElement(React__namespace.default.Fragment, null, state.detectionThresholdMet ? '✅' : '❌', " Detected Document Type: ", state.detectedDocumentType, /*#__PURE__*/React__namespace.default.createElement("br", null), state.idCardFrontDetectionThresholdMet ? '✅' : '❌', " ID Card Front Score: ", state.idCardFrontDetectionScore.toFixed(3), /*#__PURE__*/React__namespace.default.createElement("br", null), state.idCardBackDetectionThresholdMet ? '✅' : '❌', " ID Card Back Score: ", state.idCardBackDetectionScore.toFixed(3), /*#__PURE__*/React__namespace.default.createElement("br", null), state.passportDetectionThresholdMet ? '✅' : '❌', " Passport Score: ", state.passportDetectionScore.toFixed(3), /*#__PURE__*/React__namespace.default.createElement("br", null), state.singlePageDetectionThresholdMet ? '✅' : '❌', " Single Page Score: ", state.singlePageDetectionScore.toFixed(3), /*#__PURE__*/React__namespace.default.createElement("br", null), state.focusThresholdMet ? '✅' : '❌', " Focus Score:", ' ', state.focusScore.toFixed(3), /*#__PURE__*/React__namespace.default.createElement("br", null), state.documentInBounds ? '✅' : '❌', " Document In Bounds", /*#__PURE__*/React__namespace.default.createElement("br", null), state.goodFramesThresholdMet ? '✅' : '❌', " Good Frame Count:", ' ', state.goodFramesCount, "/", state.goodFramesThreshold)) : ( /*#__PURE__*/React__namespace.default.createElement(React__namespace.default.Fragment, null, "\u274C Models not ready")))));
7086
7111
  };
7087
7112
  var timeSince = function timeSince(t) {
7088
7113
  if (!t) return 0;