idmission-web-sdk 1.0.195 → 1.0.197

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,8 +1,10 @@
1
1
  import React, { Dispatch, ReactNode } from 'react';
2
- import { CapturedDocumentType } from './CapturedDocuments';
2
+ import { CapturedDocument, CapturedDocuments, CapturedDocumentType } from './CapturedDocuments';
3
3
  import { IdCapturePrediction } from './IdCaptureModelsProvider';
4
4
  import { PDF417DetectionResult } from '../../lib/barcode/Native';
5
5
  import { DetectedObject, DocumentType } from '../../lib/models/DocumentDetection';
6
+ import { IdCaptureRequirementOption } from './IdCaptureRequirementOption';
7
+ export type CaptureState = 'capturing' | 'complete' | 'requestingFlip';
6
8
  export type IdCaptureState = {
7
9
  initialDrawComplete: boolean;
8
10
  redrawing: boolean;
@@ -52,9 +54,21 @@ export type IdCaptureState = {
52
54
  captured: boolean;
53
55
  captureFailed: boolean;
54
56
  imageUrl: string | null;
57
+ captureState: CaptureState;
58
+ capturedDocuments: CapturedDocuments;
59
+ captureRequirement: IdCaptureRequirementOption;
60
+ requestedDocumentType: CapturedDocumentType;
61
+ detectedDocumentType: DocumentType;
62
+ differentDocumentTypeDetections: number;
55
63
  };
56
64
  export type IdCaptureAction = {
57
- type: 'configure';
65
+ type: 'configureWizard';
66
+ payload: {
67
+ captureRequirement: IdCaptureRequirementOption;
68
+ precapturedDocuments?: CapturedDocuments;
69
+ };
70
+ } | {
71
+ type: 'configureCapture';
58
72
  payload: {
59
73
  requiredDocumentType?: CapturedDocumentType;
60
74
  goodFramesThreshold: number;
@@ -110,6 +124,21 @@ export type IdCaptureAction = {
110
124
  };
111
125
  } | {
112
126
  type: 'barcodeScanFailed';
127
+ } | {
128
+ type: 'predictionMade';
129
+ payload: IdCapturePrediction;
130
+ } | {
131
+ type: 'documentCaptured';
132
+ payload: CapturedDocument;
133
+ } | {
134
+ type: 'documentCapturedManually';
135
+ payload: {
136
+ imageData: string;
137
+ };
138
+ } | {
139
+ type: 'flipRequestCompleted';
140
+ } | {
141
+ type: 'resetWizard';
113
142
  };
114
143
  export type IdCaptureDispatch = Dispatch<IdCaptureAction>;
115
144
  export declare const IdCaptureStateContext: React.Context<IdCaptureState>;
@@ -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.195';
51
+ var webSdkVersion = '1.0.197';
52
52
 
53
53
  function getPlatform() {
54
54
  if (typeof window === 'undefined') return;
@@ -1910,30 +1910,31 @@ var CameraProvider = function CameraProvider(_a) {
1910
1910
  var documentDetectionModel;
1911
1911
  function loadDocumentDetectionModel(url) {
1912
1912
  return tslib.__awaiter(this, void 0, void 0, function () {
1913
- var zeroes, tfInt32, tf4d_, tf4d, outputKeys;
1914
- return tslib.__generator(this, function (_a) {
1915
- switch (_a.label) {
1913
+ var zeroes, tfInt32, tf4d_, tf4d, _a, _b, outputKeys;
1914
+ return tslib.__generator(this, function (_c) {
1915
+ switch (_c.label) {
1916
1916
  case 0:
1917
1917
  if (documentDetectionModel) return [2 /*return*/, documentDetectionModel];
1918
1918
  return [4 /*yield*/, tf__namespace.loadGraphModel(url)];
1919
1919
  case 1:
1920
- documentDetectionModel = _a.sent();
1921
- return [4 /*yield*/, tf__namespace.ready()];
1920
+ documentDetectionModel = _c.sent();
1921
+ return [4 /*yield*/, tf__namespace.ready()
1922
+ // warm the model by predicting on an empty image
1923
+ ];
1922
1924
  case 2:
1923
- _a.sent();
1924
- _a.label = 3;
1925
- case 3:
1926
- _a.trys.push([3,, 5, 6]);
1927
- tf__namespace.engine().startScope();
1925
+ _c.sent();
1928
1926
  zeroes = tf__namespace.zeros([448, 448, 3]);
1929
1927
  tfInt32 = tf__namespace.cast(zeroes, 'int32');
1930
1928
  tf4d_ = tf__namespace.tensor4d(Array.from(tfInt32.dataSync()), [1, 448, 448, 3]);
1931
1929
  tf4d = tf__namespace.cast(tf4d_, 'int32');
1932
- return [4 /*yield*/, documentDetectionModel.executeAsync(tf4d)
1933
- // interrogate the model to determine the output positions
1934
- ];
1935
- case 4:
1936
- _a.sent();
1930
+ _b = (_a = tf__namespace).dispose;
1931
+ return [4 /*yield*/, documentDetectionModel.executeAsync(tf4d)];
1932
+ case 3:
1933
+ _b.apply(_a, [_c.sent()]);
1934
+ tfInt32.dispose();
1935
+ tf4d.dispose();
1936
+ tf4d_.dispose();
1937
+ tf__namespace.dispose(zeroes);
1937
1938
  outputKeys = documentDetectionModel.outputs.map(function (o) {
1938
1939
  return o.name;
1939
1940
  });
@@ -1942,11 +1943,6 @@ function loadDocumentDetectionModel(url) {
1942
1943
  scores: outputKeys.indexOf('Identity_4'),
1943
1944
  labels: outputKeys.indexOf('Identity_2')
1944
1945
  };
1945
- return [3 /*break*/, 6];
1946
- case 5:
1947
- tf__namespace.engine().endScope();
1948
- return [7 /*endfinally*/];
1949
- case 6:
1950
1946
  return [2 /*return*/, documentDetectionModel];
1951
1947
  }
1952
1948
  });
@@ -1989,31 +1985,30 @@ function loadFocusModel(url) {
1989
1985
  return [4 /*yield*/, tf__namespace.loadLayersModel(url)];
1990
1986
  case 1:
1991
1987
  focusModel = _e.sent();
1992
- return [4 /*yield*/, tf__namespace.ready()];
1988
+ return [4 /*yield*/, tf__namespace.ready()
1989
+ // warm the model by predicting on an empty image...
1990
+ ];
1993
1991
  case 2:
1994
1992
  _e.sent();
1995
- _e.label = 3;
1996
- case 3:
1997
- _e.trys.push([3,, 6, 7]);
1998
- tf__namespace.engine().startScope();
1999
1993
  zeroes = tf__namespace.zeros([448, 448, 3]);
2000
1994
  tfInt32 = tf__namespace.cast(zeroes, 'float32');
2001
1995
  _b = (_a = tf__namespace).tensor4d;
2002
1996
  _d = (_c = Array).from;
2003
1997
  return [4 /*yield*/, tfInt32.data()];
2004
- case 4:
1998
+ case 3:
2005
1999
  tf4d_ = _b.apply(_a, [_d.apply(_c, [_e.sent()]), [1, 448, 448, 3]]);
2006
2000
  tf4d = tf__namespace.cast(tf4d_, 'float32');
2007
- warmupResult = focusModel.predict(tf4d);
2001
+ return [4 /*yield*/, focusModel.predict(tf4d)];
2002
+ case 4:
2003
+ warmupResult = _e.sent();
2008
2004
  return [4 /*yield*/, warmupResult.data()];
2009
2005
  case 5:
2010
2006
  _e.sent();
2011
2007
  tf__namespace.dispose(warmupResult);
2012
- return [3 /*break*/, 7];
2013
- case 6:
2014
- tf__namespace.engine().endScope();
2015
- return [7 /*endfinally*/];
2016
- case 7:
2008
+ tfInt32.dispose();
2009
+ tf4d.dispose();
2010
+ tf4d_.dispose();
2011
+ tf__namespace.dispose(zeroes);
2017
2012
  return [2 /*return*/, focusModel];
2018
2013
  }
2019
2014
  });
@@ -9037,7 +9032,6 @@ function makeDocumentDetectionPredictions(image, logPredictions) {
9037
9032
  _e.label = 1;
9038
9033
  case 1:
9039
9034
  _e.trys.push([1, 7, 8, 9]);
9040
- console.log(' Tensors before:', tf__namespace.memory().numTensors);
9041
9035
  tf__namespace.engine().startScope();
9042
9036
  tfImg = tf__namespace.browser.fromPixels(image);
9043
9037
  if (logPredictions) console.time('resize');
@@ -9093,8 +9087,6 @@ function makeDocumentDetectionPredictions(image, logPredictions) {
9093
9087
  }];
9094
9088
  case 8:
9095
9089
  tf__namespace.engine().endScope();
9096
- // tf.engine().disposeVariables()
9097
- console.log('Tensors afters:', tf__namespace.memory().numTensors);
9098
9090
  return [7 /*endfinally*/];
9099
9091
  case 9:
9100
9092
  return [2 /*return*/];
@@ -9193,7 +9185,20 @@ function disposeTfBackend() {
9193
9185
  }
9194
9186
  }
9195
9187
 
9196
- var initialState$5 = {
9188
+ var CapturedDocumentTypeValues = ['idCardFront', 'idCardBack', 'passport', 'selfie'];
9189
+
9190
+ var requiredDocumentsForOption = {
9191
+ passport: ['passport'],
9192
+ idCard: ['idCardFront', 'idCardBack'],
9193
+ idCardAndPassport: ['idCardFront', 'idCardBack', 'passport'],
9194
+ idCardOrPassport: ['idCardFront', 'idCardBack', 'passport'] // this one is so weird
9195
+ };
9196
+ function requiredImageCountForOption(idCaptureRequirement) {
9197
+ if (idCaptureRequirement === 'idCardOrPassport') return 1;
9198
+ return requiredDocumentsForOption[idCaptureRequirement].length;
9199
+ }
9200
+
9201
+ var initialState$4 = {
9197
9202
  initialDrawComplete: false,
9198
9203
  redrawing: false,
9199
9204
  guideRectX: 0,
@@ -9240,13 +9245,44 @@ var initialState$5 = {
9240
9245
  capturing: false,
9241
9246
  captured: false,
9242
9247
  captureFailed: false,
9243
- imageUrl: null
9248
+ imageUrl: null,
9249
+ captureState: 'capturing',
9250
+ capturedDocuments: {},
9251
+ captureRequirement: 'idCardOrPassport',
9252
+ requestedDocumentType: 'idCardFront',
9253
+ detectedDocumentType: 'none',
9254
+ differentDocumentTypeDetections: 0
9244
9255
  };
9245
- var IdCaptureStateContext = /*#__PURE__*/React.createContext(initialState$5);
9256
+ var IdCaptureStateContext = /*#__PURE__*/React.createContext(initialState$4);
9246
9257
  var IdCaptureDispatchContext = /*#__PURE__*/React.createContext(function () {});
9247
- var reducer$5 = function reducer(state, action) {
9258
+ var reducer$4 = function reducer(state, action) {
9259
+ var _a;
9248
9260
  switch (action.type) {
9249
- case 'configure':
9261
+ case 'configureWizard':
9262
+ {
9263
+ var _b = action.payload,
9264
+ captureRequirement = _b.captureRequirement,
9265
+ precapturedDocuments = _b.precapturedDocuments;
9266
+ var newState = tslib.__assign(tslib.__assign({}, state), {
9267
+ captureRequirement: captureRequirement
9268
+ });
9269
+ if (captureRequirement === 'passport') newState.requestedDocumentType = 'passport';
9270
+ if (precapturedDocuments) {
9271
+ for (var _i = 0, CapturedDocumentTypeValues_1 = CapturedDocumentTypeValues; _i < CapturedDocumentTypeValues_1.length; _i++) {
9272
+ var k = CapturedDocumentTypeValues_1[_i];
9273
+ var payload = precapturedDocuments[k];
9274
+ if (payload) {
9275
+ newState.requestedDocumentType = k;
9276
+ newState = reducer(newState, {
9277
+ type: 'documentCaptured',
9278
+ payload: payload
9279
+ });
9280
+ }
9281
+ }
9282
+ }
9283
+ return newState;
9284
+ }
9285
+ case 'configureCapture':
9250
9286
  return tslib.__assign(tslib.__assign(tslib.__assign({}, state), action.payload), {
9251
9287
  goodFramesCount: 0,
9252
9288
  capturing: false,
@@ -9283,26 +9319,26 @@ var reducer$5 = function reducer(state, action) {
9283
9319
  guideImageHeight: action.payload.height
9284
9320
  });
9285
9321
  case 'objectsDetected':
9286
- var _a = action.payload.prediction,
9287
- detectedObjects = _a.detectedObjects,
9288
- detectionScore = _a.detectionScore,
9289
- detectionThresholdMet = _a.detectionThresholdMet,
9290
- detectedDocumentType = _a.detectedDocumentType,
9291
- passportDetectionScore = _a.passportDetectionScore,
9292
- passportDetectionThresholdMet = _a.passportDetectionThresholdMet,
9293
- mrzDetectionScore = _a.mrzDetectionScore,
9294
- mrzDetectionThresholdMet = _a.mrzDetectionThresholdMet,
9295
- pdf417DetectionScore = _a.pdf417DetectionScore,
9296
- pdf417DetectionThresholdMet = _a.pdf417DetectionThresholdMet,
9297
- bestDocumentOrPassport = _a.bestDocumentOrPassport,
9298
- bestMrz = _a.bestMrz,
9299
- bestPdf417 = _a.bestPdf417,
9300
- documentInBounds = _a.documentInBounds,
9301
- documentTooClose = _a.documentTooClose,
9302
- focusScore = _a.focusScore,
9303
- focusThresholdMet = _a.focusThresholdMet,
9304
- frameWidth = _a.frameWidth,
9305
- frameHeight = _a.frameHeight;
9322
+ var _c = action.payload.prediction,
9323
+ detectedObjects = _c.detectedObjects,
9324
+ detectionScore = _c.detectionScore,
9325
+ detectionThresholdMet = _c.detectionThresholdMet,
9326
+ detectedDocumentType = _c.detectedDocumentType,
9327
+ passportDetectionScore = _c.passportDetectionScore,
9328
+ passportDetectionThresholdMet = _c.passportDetectionThresholdMet,
9329
+ mrzDetectionScore = _c.mrzDetectionScore,
9330
+ mrzDetectionThresholdMet = _c.mrzDetectionThresholdMet,
9331
+ pdf417DetectionScore = _c.pdf417DetectionScore,
9332
+ pdf417DetectionThresholdMet = _c.pdf417DetectionThresholdMet,
9333
+ bestDocumentOrPassport = _c.bestDocumentOrPassport,
9334
+ bestMrz = _c.bestMrz,
9335
+ bestPdf417 = _c.bestPdf417,
9336
+ documentInBounds = _c.documentInBounds,
9337
+ documentTooClose = _c.documentTooClose,
9338
+ focusScore = _c.focusScore,
9339
+ focusThresholdMet = _c.focusThresholdMet,
9340
+ frameWidth = _c.frameWidth,
9341
+ frameHeight = _c.frameHeight;
9306
9342
  var frameCapturedAt = new Date();
9307
9343
  var frameCaptureRate = 0;
9308
9344
  var goodFramesThreshold = state.goodFramesThreshold;
@@ -9349,6 +9385,29 @@ var reducer$5 = function reducer(state, action) {
9349
9385
  lastFrameCapturedAt: frameCapturedAt,
9350
9386
  frameCaptureRate: frameCaptureRate
9351
9387
  });
9388
+ case 'predictionMade':
9389
+ {
9390
+ var _d = action.payload,
9391
+ detectedDocumentType_1 = _d.detectedDocumentType,
9392
+ passportDetectionScore_1 = _d.passportDetectionScore;
9393
+ var requestedDocumentType = state.requestedDocumentType;
9394
+ var newState = tslib.__assign(tslib.__assign({}, state), {
9395
+ detectedDocumentType: detectedDocumentType_1
9396
+ });
9397
+ if (state.captureRequirement === 'idCardOrPassport') {
9398
+ var predictionIsRequestedType = requestedDocumentType.startsWith(detectedDocumentType_1);
9399
+ if (predictionIsRequestedType) {
9400
+ newState.differentDocumentTypeDetections = 0;
9401
+ }
9402
+ if (detectedDocumentType_1 === 'passport' && requestedDocumentType !== 'passport') {
9403
+ newState.requestedDocumentType = 'passport';
9404
+ }
9405
+ if (requestedDocumentType === 'passport' && passportDetectionScore_1 < 0.3) {
9406
+ newState.requestedDocumentType = 'idCardFront' in state.capturedDocuments ? 'idCardBack' : 'idCardFront';
9407
+ }
9408
+ }
9409
+ return newState;
9410
+ }
9352
9411
  case 'barcodeScanned':
9353
9412
  return tslib.__assign(tslib.__assign({}, state), {
9354
9413
  barcodeResult: action.payload.result,
@@ -9389,13 +9448,64 @@ var reducer$5 = function reducer(state, action) {
9389
9448
  captured: false,
9390
9449
  captureFailed: true
9391
9450
  });
9451
+ case 'documentCaptured':
9452
+ {
9453
+ var newState_1 = tslib.__assign(tslib.__assign({}, state), {
9454
+ capturedDocuments: tslib.__assign(tslib.__assign({}, state.capturedDocuments), (_a = {}, _a[state.requestedDocumentType] = action.payload, _a))
9455
+ });
9456
+ var remainingRequirements = requiredDocumentsForOption[state.captureRequirement].filter(function (v) {
9457
+ return !(v in newState_1.capturedDocuments);
9458
+ });
9459
+ if (state.captureRequirement === 'idCardOrPassport') {
9460
+ if (state.requestedDocumentType === 'passport') {
9461
+ remainingRequirements = [];
9462
+ } else {
9463
+ remainingRequirements = remainingRequirements.filter(function (v) {
9464
+ return v !== 'passport';
9465
+ });
9466
+ }
9467
+ }
9468
+ if (remainingRequirements.length === 0) {
9469
+ newState_1.captureState = 'complete';
9470
+ } else {
9471
+ newState_1.requestedDocumentType = remainingRequirements[0];
9472
+ if (state.requestedDocumentType === 'idCardFront' && newState_1.requestedDocumentType === 'idCardBack') {
9473
+ newState_1.captureState = 'requestingFlip';
9474
+ newState_1.documentDetectionThresholdMet = false;
9475
+ newState_1.passportPageDetectionThresholdMet = false;
9476
+ }
9477
+ }
9478
+ return newState_1;
9479
+ }
9480
+ case 'documentCapturedManually':
9481
+ {
9482
+ var newState = tslib.__assign({}, state);
9483
+ var capturedDocument = tslib.__assign(tslib.__assign({}, action.payload), {
9484
+ width: 0,
9485
+ height: 0
9486
+ });
9487
+ if (Object.keys(state.capturedDocuments).length === 0) {
9488
+ newState.capturedDocuments.passport = capturedDocument;
9489
+ } else {
9490
+ newState.capturedDocuments = {};
9491
+ newState.capturedDocuments.idCardFront = state.capturedDocuments.passport;
9492
+ newState.capturedDocuments.idCardBack = capturedDocument;
9493
+ }
9494
+ return newState;
9495
+ }
9496
+ case 'flipRequestCompleted':
9497
+ return tslib.__assign(tslib.__assign({}, state), {
9498
+ captureState: 'capturing'
9499
+ });
9500
+ case 'resetWizard':
9501
+ return tslib.__assign({}, initialState$4);
9392
9502
  default:
9393
9503
  return state;
9394
9504
  }
9395
9505
  };
9396
9506
  var IdCaptureStateProvider = function IdCaptureStateProvider(_a) {
9397
9507
  var children = _a.children;
9398
- var _b = React.useReducer(reducer$5, initialState$5),
9508
+ var _b = React.useReducer(reducer$4, initialState$4),
9399
9509
  state = _b[0],
9400
9510
  dispatch = _b[1];
9401
9511
  var onResize = useDebounce.useDebouncedCallback(function () {
@@ -9846,7 +9956,7 @@ var IdCapture = function IdCapture(_a) {
9846
9956
  }, []);
9847
9957
  React.useEffect(function () {
9848
9958
  dispatch({
9849
- type: 'configure',
9959
+ type: 'configureCapture',
9850
9960
  payload: {
9851
9961
  requiredDocumentType: requiredDocumentType,
9852
9962
  goodFramesThreshold: autoCaptureGoodFramesRequired,
@@ -10275,8 +10385,6 @@ var IdCaptureLoadingOverlay = function IdCaptureLoadingOverlay(_a) {
10275
10385
  };
10276
10386
  var templateObject_1$s, templateObject_2$i;
10277
10387
 
10278
- var CapturedDocumentTypeValues = ['idCardFront', 'idCardBack', 'passport', 'selfie'];
10279
-
10280
10388
  var ButtonsRow = styled__default['default'].div(templateObject_1$r || (templateObject_1$r = tslib.__makeTemplateObject(["\n display: flex;\n gap: 0 15px;\n justify-content: center;\n"], ["\n display: flex;\n gap: 0 15px;\n justify-content: center;\n"])));
10281
10389
  var templateObject_1$r;
10282
10390
 
@@ -10472,17 +10580,6 @@ function useShowSuccessScreen(skipSuccessScreen, successScreenReady, onDoneCallb
10472
10580
  return !skipSuccessScreen || skipSuccessScreenResolvedFalse;
10473
10581
  }
10474
10582
 
10475
- var requiredDocumentsForOption = {
10476
- passport: ['passport'],
10477
- idCard: ['idCardFront', 'idCardBack'],
10478
- idCardAndPassport: ['idCardFront', 'idCardBack', 'passport'],
10479
- idCardOrPassport: ['idCardFront', 'idCardBack', 'passport'] // this one is so weird
10480
- };
10481
- function requiredImageCountForOption(idCaptureRequirement) {
10482
- if (idCaptureRequirement === 'idCardOrPassport') return 1;
10483
- return requiredDocumentsForOption[idCaptureRequirement].length;
10484
- }
10485
-
10486
10583
  var IdCaptureFallback = function IdCaptureFallback(_a) {
10487
10584
  var _b = _a.idCaptureRequirement,
10488
10585
  idCaptureRequirement = _b === void 0 ? 'idCardOrPassport' : _b,
@@ -11191,120 +11288,6 @@ var ImagePreviewText = styled__default['default'].div(templateObject_3$9 || (tem
11191
11288
  var ImagePreviewImageWrapper = styled__default['default'].div(templateObject_4$5 || (templateObject_4$5 = tslib.__makeTemplateObject(["\n position: relative;\n height: calc(100% - 8px);\n padding: 4px;\n border-radius: 4px;\n background: white;\n\n & > img {\n border-radius: 4px;\n width: auto;\n max-height: 100%;\n }\n"], ["\n position: relative;\n height: calc(100% - 8px);\n padding: 4px;\n border-radius: 4px;\n background: white;\n\n & > img {\n border-radius: 4px;\n width: auto;\n max-height: 100%;\n }\n"])));
11192
11289
  var templateObject_1$i, templateObject_2$c, templateObject_3$9, templateObject_4$5;
11193
11290
 
11194
- var initialState$4 = {
11195
- captureState: 'capturing',
11196
- capturedDocuments: {},
11197
- captureRequirement: 'idCardOrPassport',
11198
- requestedDocumentType: 'idCardFront',
11199
- detectedDocumentType: 'none',
11200
- differentDocumentTypeDetections: 0,
11201
- barcodeResult: null
11202
- };
11203
- var reducer$4 = function reducer(state, action) {
11204
- var _a;
11205
- switch (action.type) {
11206
- case 'configure':
11207
- {
11208
- var _b = action.payload,
11209
- captureRequirement = _b.captureRequirement,
11210
- precapturedDocuments = _b.precapturedDocuments;
11211
- var newState = tslib.__assign(tslib.__assign({}, state), {
11212
- captureRequirement: captureRequirement
11213
- });
11214
- if (captureRequirement === 'passport') newState.requestedDocumentType = 'passport';
11215
- if (precapturedDocuments) {
11216
- for (var _i = 0, CapturedDocumentTypeValues_1 = CapturedDocumentTypeValues; _i < CapturedDocumentTypeValues_1.length; _i++) {
11217
- var k = CapturedDocumentTypeValues_1[_i];
11218
- var payload = precapturedDocuments[k];
11219
- if (payload) {
11220
- newState.requestedDocumentType = k;
11221
- newState = reducer(newState, {
11222
- type: 'imageCaptured',
11223
- payload: payload
11224
- });
11225
- }
11226
- }
11227
- }
11228
- return newState;
11229
- }
11230
- case 'predictionMade':
11231
- {
11232
- var _c = action.payload,
11233
- detectedDocumentType = _c.detectedDocumentType,
11234
- passportDetectionScore = _c.passportDetectionScore;
11235
- var requestedDocumentType = state.requestedDocumentType;
11236
- var newState = tslib.__assign(tslib.__assign({}, state), {
11237
- detectedDocumentType: detectedDocumentType
11238
- });
11239
- if (state.captureRequirement === 'idCardOrPassport') {
11240
- var predictionIsRequestedType = requestedDocumentType.startsWith(detectedDocumentType);
11241
- if (predictionIsRequestedType) {
11242
- newState.differentDocumentTypeDetections = 0;
11243
- }
11244
- if (detectedDocumentType === 'passport' && requestedDocumentType !== 'passport') {
11245
- newState.requestedDocumentType = 'passport';
11246
- }
11247
- if (requestedDocumentType === 'passport' && passportDetectionScore < 0.3) {
11248
- newState.requestedDocumentType = 'idCardFront' in state.capturedDocuments ? 'idCardBack' : 'idCardFront';
11249
- }
11250
- }
11251
- return newState;
11252
- }
11253
- case 'barcodeScanned':
11254
- return tslib.__assign(tslib.__assign({}, state), {
11255
- barcodeResult: action.payload.result
11256
- });
11257
- case 'imageCaptured':
11258
- {
11259
- var newState_1 = tslib.__assign(tslib.__assign({}, state), {
11260
- capturedDocuments: tslib.__assign(tslib.__assign({}, state.capturedDocuments), (_a = {}, _a[state.requestedDocumentType] = action.payload, _a))
11261
- });
11262
- var remainingRequirements = requiredDocumentsForOption[state.captureRequirement].filter(function (v) {
11263
- return !(v in newState_1.capturedDocuments);
11264
- });
11265
- if (state.captureRequirement === 'idCardOrPassport') {
11266
- if (state.requestedDocumentType === 'passport') {
11267
- remainingRequirements = [];
11268
- } else {
11269
- remainingRequirements = remainingRequirements.filter(function (v) {
11270
- return v !== 'passport';
11271
- });
11272
- }
11273
- }
11274
- if (remainingRequirements.length === 0) {
11275
- newState_1.captureState = 'complete';
11276
- } else {
11277
- newState_1.requestedDocumentType = remainingRequirements[0];
11278
- if (state.requestedDocumentType === 'idCardFront' && newState_1.requestedDocumentType === 'idCardBack') {
11279
- newState_1.captureState = 'requestingFlip';
11280
- }
11281
- }
11282
- return newState_1;
11283
- }
11284
- case 'imageCapturedManually':
11285
- {
11286
- var newState = tslib.__assign({}, state);
11287
- var capturedDocument = tslib.__assign(tslib.__assign({}, action.payload), {
11288
- width: 0,
11289
- height: 0
11290
- });
11291
- if (Object.keys(state.capturedDocuments).length === 0) {
11292
- newState.capturedDocuments.passport = capturedDocument;
11293
- } else {
11294
- newState.capturedDocuments = {};
11295
- newState.capturedDocuments.idCardFront = state.capturedDocuments.passport;
11296
- newState.capturedDocuments.idCardBack = capturedDocument;
11297
- }
11298
- return newState;
11299
- }
11300
- case 'flipRequestCompleted':
11301
- return tslib.__assign(tslib.__assign({}, state), {
11302
- captureState: 'capturing'
11303
- });
11304
- case 'reset':
11305
- return tslib.__assign({}, initialState$4);
11306
- }
11307
- };
11308
11291
  var IdCaptureWizard = function IdCaptureWizard(_a) {
11309
11292
  var _b, _c, _d, _e, _f, _g;
11310
11293
  var _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
@@ -11351,7 +11334,7 @@ var IdCaptureWizard = function IdCaptureWizard(_a) {
11351
11334
  verbiage = _10 === void 0 ? {} : _10,
11352
11335
  _11 = _a.debugMode,
11353
11336
  debugMode = _11 === void 0 ? false : _11;
11354
- var _12 = React.useReducer(reducer$4, initialState$4),
11337
+ var _12 = useIdCaptureState(),
11355
11338
  state = _12[0],
11356
11339
  dispatch = _12[1];
11357
11340
  var releaseCameraAccess = React.useContext(CameraStateContext).releaseCameraAccess;
@@ -11369,13 +11352,13 @@ var IdCaptureWizard = function IdCaptureWizard(_a) {
11369
11352
  var operationStartedAt = React.useRef();
11370
11353
  React.useEffect(function () {
11371
11354
  dispatch({
11372
- type: 'configure',
11355
+ type: 'configureWizard',
11373
11356
  payload: {
11374
11357
  captureRequirement: captureRequirement,
11375
11358
  precapturedDocuments: precapturedDocuments
11376
11359
  }
11377
11360
  });
11378
- }, [captureRequirement, precapturedDocuments]);
11361
+ }, [captureRequirement, dispatch, precapturedDocuments]);
11379
11362
  var documentCount = Object.keys(state.capturedDocuments).length;
11380
11363
  React.useEffect(function () {
11381
11364
  operationStartedAt.current = new Date();
@@ -11390,19 +11373,11 @@ var IdCaptureWizard = function IdCaptureWizard(_a) {
11390
11373
  type: 'predictionMade',
11391
11374
  payload: prediction
11392
11375
  });
11393
- }, []);
11394
- var onBarcodeScanned = React.useCallback(function (result) {
11395
- dispatch({
11396
- type: 'barcodeScanned',
11397
- payload: {
11398
- result: result
11399
- }
11400
- });
11401
- }, []);
11376
+ }, [dispatch]);
11402
11377
  var onCapture = React.useCallback(function (imageData, width, height, metadata) {
11403
11378
  logCaptureMetadata(metadata);
11404
11379
  dispatch({
11405
- type: 'imageCaptured',
11380
+ type: 'documentCaptured',
11406
11381
  payload: {
11407
11382
  imageData: imageData,
11408
11383
  width: width,
@@ -11410,7 +11385,7 @@ var IdCaptureWizard = function IdCaptureWizard(_a) {
11410
11385
  boundingBox: metadata.boundingBox
11411
11386
  }
11412
11387
  });
11413
- }, [logCaptureMetadata]);
11388
+ }, [dispatch, logCaptureMetadata]);
11414
11389
  var onSubmitClick = React.useCallback(function () {
11415
11390
  var _a = state.capturedDocuments,
11416
11391
  idCardFront = _a.idCardFront,
@@ -11434,9 +11409,9 @@ var IdCaptureWizard = function IdCaptureWizard(_a) {
11434
11409
  var showSuccessScreen = useShowSuccessScreen(skipSuccessScreen, state.captureState === 'complete', onSubmitClick);
11435
11410
  var onRetryClick = React.useCallback(function () {
11436
11411
  dispatch({
11437
- type: 'reset'
11412
+ type: 'resetWizard'
11438
11413
  });
11439
- }, []);
11414
+ }, [dispatch]);
11440
11415
  var _15 = React.useState(0),
11441
11416
  attempt = _15[0],
11442
11417
  setAttempt = _15[1];
@@ -11446,10 +11421,10 @@ var IdCaptureWizard = function IdCaptureWizard(_a) {
11446
11421
  return n + 1;
11447
11422
  });
11448
11423
  dispatch({
11449
- type: 'reset'
11424
+ type: 'resetWizard'
11450
11425
  });
11451
11426
  onExitCapture === null || onExitCapture === void 0 ? void 0 : onExitCapture();
11452
- }, [onExitCapture]);
11427
+ }, [dispatch, onExitCapture]);
11453
11428
  React.useEffect(function () {
11454
11429
  if (submissionStatus !== SubmissionStatus.READY) {
11455
11430
  releaseCameraAccessOnExit && releaseCameraAccess();
@@ -11498,14 +11473,14 @@ var IdCaptureWizard = function IdCaptureWizard(_a) {
11498
11473
  });
11499
11474
  }, 3500);
11500
11475
  }
11501
- }, [state.captureState]);
11476
+ }, [dispatch, state.captureState]);
11502
11477
  if (modelsError) {
11503
11478
  return /*#__PURE__*/React__default['default'].createElement(IdCaptureFallback, {
11504
11479
  idCaptureRequirement: captureRequirement,
11505
11480
  onFinished: onSubmitClick,
11506
11481
  onCapture: function onCapture(imageData) {
11507
11482
  dispatch({
11508
- type: 'imageCapturedManually',
11483
+ type: 'documentCapturedManually',
11509
11484
  payload: {
11510
11485
  imageData: imageData
11511
11486
  }
@@ -11560,7 +11535,6 @@ var IdCaptureWizard = function IdCaptureWizard(_a) {
11560
11535
  mrzDetectionScoreThreshold: mrzDetectionScoreThreshold,
11561
11536
  focusScoreThreshold: idCardFocusScoreThreshold,
11562
11537
  onPrediction: onPrediction,
11563
- onBarcodeScanned: onBarcodeScanned,
11564
11538
  onCapture: onCapture,
11565
11539
  assets: idCaptureAssets,
11566
11540
  classNames: classNames === null || classNames === void 0 ? void 0 : classNames.capture,
@@ -11580,7 +11554,6 @@ var IdCaptureWizard = function IdCaptureWizard(_a) {
11580
11554
  barcodeScanningEnabled: false,
11581
11555
  focusScoreThreshold: passportFocusScoreThreshold,
11582
11556
  onPrediction: onPrediction,
11583
- onBarcodeScanned: onBarcodeScanned,
11584
11557
  onCapture: onCapture,
11585
11558
  assets: idCaptureAssets,
11586
11559
  classNames: classNames === null || classNames === void 0 ? void 0 : classNames.capture,