idmission-web-sdk 1.0.183 → 1.0.185

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.
@@ -20,6 +20,7 @@ export type IdVideoCaptureColors = {
20
20
  export type IdVideoCaptureVerbiage = {
21
21
  guides?: IdVideoCaptureGuidesVerbiage;
22
22
  readTextPrompt?: ReadTextPromptVerbiage;
23
+ faceNotCenteredText?: CustomerSuppliedVerbiage;
23
24
  };
24
25
  export type IdVideoCaptureProps = {
25
26
  onComplete?: (videoUrl: string) => void;
@@ -65,6 +65,7 @@ declare const _default: {
65
65
  'Upload succeeded!': string;
66
66
  'Display the front of your ID card...': string;
67
67
  'Display the back of your ID card...': string;
68
+ 'Please move your face to the center...': string;
68
69
  'Please read the following text aloud': string;
69
70
  'Video ID has been successfully captured!': string;
70
71
  };
@@ -73,6 +73,7 @@ export declare const resources: {
73
73
  'Upload succeeded!': string;
74
74
  'Display the front of your ID card...': string;
75
75
  'Display the back of your ID card...': string;
76
+ 'Please move your face to the center...': string;
76
77
  'Please read the following text aloud': string;
77
78
  'Video ID has been successfully captured!': string;
78
79
  };
@@ -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.183';
51
+ var webSdkVersion = '1.0.185';
52
52
 
53
53
  function getPlatform() {
54
54
  if (typeof window === 'undefined') return;
@@ -8795,7 +8795,7 @@ var IdCaptureModelsProvider = function IdCaptureModelsProvider(_a) {
8795
8795
  working.current = true;
8796
8796
  (function () {
8797
8797
  return tslib.__awaiter(void 0, void 0, void 0, function () {
8798
- var canvases, prediction;
8798
+ var canvases, prediction, e_1;
8799
8799
  var _a, _b, _c;
8800
8800
  return tslib.__generator(this, function (_d) {
8801
8801
  switch (_d.label) {
@@ -8806,8 +8806,11 @@ var IdCaptureModelsProvider = function IdCaptureModelsProvider(_a) {
8806
8806
  cropCanvas: cropCanvas.current,
8807
8807
  rotateCanvas: rotateCanvas.current
8808
8808
  };
8809
- return [4 /*yield*/, makePredictions(frame, thresholds, canvases, logPredictions)];
8809
+ _d.label = 1;
8810
8810
  case 1:
8811
+ _d.trys.push([1, 3,, 4]);
8812
+ return [4 /*yield*/, makePredictions(frame, thresholds, canvases, logPredictions)];
8813
+ case 2:
8811
8814
  prediction = _d.sent();
8812
8815
  setDetectionTime(prediction.detectionTime);
8813
8816
  setFocusPredictionTime(prediction.focusPredictionTime);
@@ -8816,12 +8819,18 @@ var IdCaptureModelsProvider = function IdCaptureModelsProvider(_a) {
8816
8819
  setBestFrameBoundingBox((_b = (_a = prediction.bestDocumentOrPassport) === null || _a === void 0 ? void 0 : _a.bbox) !== null && _b !== void 0 ? _b : []);
8817
8820
  setBestFrameDetectionScore(prediction.detectionScore);
8818
8821
  setBestFrameFocusScore(prediction.focusScore);
8819
- drawToCanvas(bestPredictionCanvas.current, frame);
8822
+ drawToCanvas(bestPredictionCanvas.current, lastPredictionCanvas.current);
8820
8823
  }
8821
8824
  if (prediction.allZero) setTimesAllZero(function (n) {
8822
8825
  return n + 1;
8823
8826
  });
8824
8827
  (_c = onPredictionHandler.current) === null || _c === void 0 ? void 0 : _c.call(onPredictionHandler, prediction);
8828
+ return [3 /*break*/, 4];
8829
+ case 3:
8830
+ e_1 = _d.sent();
8831
+ console.log('caught an error while predicting!', e_1);
8832
+ return [3 /*break*/, 4];
8833
+ case 4:
8825
8834
  working.current = false;
8826
8835
  return [2 /*return*/];
8827
8836
  }
@@ -9003,7 +9012,7 @@ function makeDocumentDetectionPredictions(image, logPredictions) {
9003
9012
  logPredictions = false;
9004
9013
  }
9005
9014
  return tslib.__awaiter(this, void 0, void 0, function () {
9006
- var startedAt, tfImg, tfResize, tfInt32, tf4d_, _a, _b, _c, _d, tf4d, result, predictions, boxes, scores, labels, time, e_1;
9015
+ var startedAt, tfImg, tfResize, tfInt32, tf4d_, _a, _b, _c, _d, tf4d, result, predictions, boxes, scores, labels, time, e_2;
9007
9016
  return tslib.__generator(this, function (_e) {
9008
9017
  switch (_e.label) {
9009
9018
  case 0:
@@ -9064,8 +9073,8 @@ function makeDocumentDetectionPredictions(image, logPredictions) {
9064
9073
  time: time
9065
9074
  }];
9066
9075
  case 7:
9067
- e_1 = _e.sent();
9068
- console.error('caught error in makeDocumentDetectionPredictions', e_1);
9076
+ e_2 = _e.sent();
9077
+ console.error('caught error in makeDocumentDetectionPredictions', e_2);
9069
9078
  return [2 /*return*/, {
9070
9079
  boxes: [],
9071
9080
  scores: [],
@@ -9666,6 +9675,7 @@ var esTranslation = {
9666
9675
  'Upload succeeded!': 'Proceso completo!',
9667
9676
  'Display the front of your ID card...': 'Hay que mostrar el frente de la identificación...',
9668
9677
  'Display the back of your ID card...': 'Hay que mostrar el reverso de la identificación...',
9678
+ 'Please move your face to the center...': 'Por favor, hay que mover la cabeza hacia el centro...',
9669
9679
  'Please read the following text aloud': 'Hay que leer el siguiente texto en voz alta',
9670
9680
  'Video ID has been successfully captured!': 'Video ID capturado exitosamente!'
9671
9681
  };
@@ -14013,71 +14023,75 @@ var ReadTextPromptTimeRemaining = styled__default['default'].div(templateObject_
14013
14023
  var DoneButton = styled__default['default'](LoaderButton)(templateObject_6$1 || (templateObject_6$1 = tslib.__makeTemplateObject(["\n margin: auto 0;\n"], ["\n margin: auto 0;\n"])));
14014
14024
  var templateObject_1$7, templateObject_2$6, templateObject_3$5, templateObject_4$1, templateObject_5$1, templateObject_6$1;
14015
14025
 
14026
+ var edgeBoundary = 0.05;
14016
14027
  var IdVideoCapture = function IdVideoCapture(_a) {
14017
- var _b, _c, _d, _e, _f, _g, _h;
14028
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
14018
14029
  var onComplete = _a.onComplete,
14019
14030
  onIdFrontImageCaptured = _a.onIdFrontImageCaptured,
14020
14031
  onIdBackImageCaptured = _a.onIdBackImageCaptured,
14021
14032
  onFaceNotDetected = _a.onFaceNotDetected,
14022
- _j = _a.idCardFrontDetectionThreshold,
14023
- idCardFrontDetectionThreshold = _j === void 0 ? 0.6 : _j,
14024
- _k = _a.idCardFrontFocusThreshold,
14025
- idCardFrontFocusThreshold = _k === void 0 ? 0 : _k,
14026
- _l = _a.goodIdCardFrontFramesThreshold,
14027
- goodIdCardFrontFramesThreshold = _l === void 0 ? 3 : _l,
14028
- _m = _a.idCardBackDetectionThreshold,
14029
- idCardBackDetectionThreshold = _m === void 0 ? 0.6 : _m,
14030
- _o = _a.idCardBackFocusThreshold,
14031
- idCardBackFocusThreshold = _o === void 0 ? 0 : _o,
14032
- _p = _a.goodIdCardBackFramesThreshold,
14033
- goodIdCardBackFramesThreshold = _p === void 0 ? 3 : _p,
14034
- _q = _a.skipShowIdCardBack,
14035
- skipShowIdCardBack = _q === void 0 ? false : _q,
14033
+ _u = _a.idCardFrontDetectionThreshold,
14034
+ idCardFrontDetectionThreshold = _u === void 0 ? 0.6 : _u,
14035
+ _v = _a.idCardFrontFocusThreshold,
14036
+ idCardFrontFocusThreshold = _v === void 0 ? 0 : _v,
14037
+ _w = _a.goodIdCardFrontFramesThreshold,
14038
+ goodIdCardFrontFramesThreshold = _w === void 0 ? 3 : _w,
14039
+ _x = _a.idCardBackDetectionThreshold,
14040
+ idCardBackDetectionThreshold = _x === void 0 ? 0.6 : _x,
14041
+ _y = _a.idCardBackFocusThreshold,
14042
+ idCardBackFocusThreshold = _y === void 0 ? 0 : _y,
14043
+ _z = _a.goodIdCardBackFramesThreshold,
14044
+ goodIdCardBackFramesThreshold = _z === void 0 ? 3 : _z,
14045
+ _0 = _a.skipShowIdCardBack,
14046
+ skipShowIdCardBack = _0 === void 0 ? false : _0,
14036
14047
  readTextPrompt = _a.readTextPrompt,
14037
- _r = _a.readTextTimeoutDurationMs,
14038
- readTextTimeoutDurationMs = _r === void 0 ? 15000 : _r,
14039
- _s = _a.assets,
14040
- assets = _s === void 0 ? {} : _s,
14041
- _t = _a.classNames,
14042
- classNames = _t === void 0 ? {} : _t,
14043
- _u = _a.colors,
14044
- colors = _u === void 0 ? {} : _u,
14045
- _v = _a.verbiage,
14046
- rawVerbiage = _v === void 0 ? {} : _v,
14047
- _w = _a.debugMode,
14048
- debugMode = _w === void 0 ? false : _w;
14049
- var _x = useResizeObserver__default['default'](),
14050
- ref = _x.ref,
14051
- _y = _x.width,
14052
- width = _y === void 0 ? 1 : _y,
14053
- _z = _x.height,
14054
- height = _z === void 0 ? 1 : _z;
14055
- var _0 = React.useContext(CameraStateContext),
14056
- cameraRef = _0.cameraRef,
14057
- videoRef = _0.videoRef,
14058
- videoLoaded = _0.videoLoaded,
14059
- cameraReady = _0.cameraReady;
14060
- var _1 = React.useState([]),
14061
- detectedObjects = _1[0],
14062
- setDetectedObjects = _1[1];
14063
- var _2 = React.useState([]),
14064
- faces = _2[0],
14065
- setFaces = _2[1];
14066
- var _3 = React.useContext(IdCaptureModelsContext),
14067
- idModelsReady = _3.ready,
14068
- idModelsWorking = _3.working,
14069
- makeIdPrediction = _3.makePrediction,
14070
- onIdPredictionMade = _3.onPredictionMade,
14071
- setThresholds = _3.setThresholds,
14072
- bestFrameDetectionScore = _3.bestFrameDetectionScore,
14073
- bestFrameFocusScore = _3.bestFrameFocusScore,
14074
- resetBestFrame = _3.resetBestFrame;
14048
+ _1 = _a.readTextTimeoutDurationMs,
14049
+ readTextTimeoutDurationMs = _1 === void 0 ? 15000 : _1,
14050
+ _2 = _a.assets,
14051
+ assets = _2 === void 0 ? {} : _2,
14052
+ _3 = _a.classNames,
14053
+ classNames = _3 === void 0 ? {} : _3,
14054
+ _4 = _a.colors,
14055
+ colors = _4 === void 0 ? {} : _4,
14056
+ _5 = _a.verbiage,
14057
+ rawVerbiage = _5 === void 0 ? {} : _5,
14058
+ _6 = _a.debugMode,
14059
+ debugMode = _6 === void 0 ? false : _6;
14060
+ var _7 = useResizeObserver__default['default'](),
14061
+ ref = _7.ref,
14062
+ _8 = _7.width,
14063
+ width = _8 === void 0 ? 1 : _8,
14064
+ _9 = _7.height,
14065
+ height = _9 === void 0 ? 1 : _9;
14066
+ var _10 = React.useContext(CameraStateContext),
14067
+ cameraRef = _10.cameraRef,
14068
+ videoRef = _10.videoRef,
14069
+ videoLoaded = _10.videoLoaded,
14070
+ cameraReady = _10.cameraReady;
14071
+ var _11 = React.useState([]),
14072
+ detectedObjects = _11[0],
14073
+ setDetectedObjects = _11[1];
14074
+ var _12 = React.useState([]),
14075
+ faces = _12[0],
14076
+ setFaces = _12[1];
14077
+ var _13 = React.useState(true),
14078
+ faceCentered = _13[0],
14079
+ setFaceCentered = _13[1];
14080
+ var _14 = React.useContext(IdCaptureModelsContext),
14081
+ idModelsReady = _14.ready,
14082
+ idModelsWorking = _14.working,
14083
+ makeIdPrediction = _14.makePrediction,
14084
+ onIdPredictionMade = _14.onPredictionMade,
14085
+ setThresholds = _14.setThresholds,
14086
+ bestFrameDetectionScore = _14.bestFrameDetectionScore,
14087
+ bestFrameFocusScore = _14.bestFrameFocusScore,
14088
+ resetBestFrame = _14.resetBestFrame;
14075
14089
  var onSelfiePredictionMade = React.useContext(HighPerformanceSelfieGuidanceModelsContext).onPredictionMade;
14076
- var _4 = useVideoRecorder(cameraRef.current),
14077
- isRecording = _4.isRecording,
14078
- startRecording = _4.startRecording,
14079
- stopRecording = _4.stopRecording,
14080
- videoUrl = _4.videoUrl;
14090
+ var _15 = useVideoRecorder(cameraRef.current),
14091
+ isRecording = _15.isRecording,
14092
+ startRecording = _15.startRecording,
14093
+ stopRecording = _15.stopRecording,
14094
+ videoUrl = _15.videoUrl;
14081
14095
  React.useEffect(function () {
14082
14096
  if (!isRecording && !videoUrl) startRecording();
14083
14097
  if (videoUrl) onComplete === null || onComplete === void 0 ? void 0 : onComplete(videoUrl);
@@ -14087,9 +14101,9 @@ var IdVideoCapture = function IdVideoCapture(_a) {
14087
14101
  React.useEffect(function () {
14088
14102
  shouldCaptureFrames.current = videoLoaded && cameraReady && idModelsReady;
14089
14103
  }, [cameraReady, idModelsReady, videoLoaded]);
14090
- var _5 = React.useState('SHOW_ID_FRONT'),
14091
- requestedAction = _5[0],
14092
- setRequestedAction = _5[1];
14104
+ var _16 = React.useState('SHOW_ID_FRONT'),
14105
+ requestedAction = _16[0],
14106
+ setRequestedAction = _16[1];
14093
14107
  React.useEffect(function () {
14094
14108
  if (requestedAction !== 'SHOW_ID_FRONT' && requestedAction !== 'SHOW_ID_BACK') return;
14095
14109
  if (!idModelsReady || !cameraReady || !videoLoaded) return;
@@ -14117,15 +14131,15 @@ var IdVideoCapture = function IdVideoCapture(_a) {
14117
14131
  }
14118
14132
  });
14119
14133
  }, [idCardBackDetectionThreshold, idCardBackFocusThreshold, idCardFrontDetectionThreshold, idCardFrontFocusThreshold, requestedAction, setThresholds]);
14120
- var _6 = React.useState(0),
14121
- currentDetectionScore = _6[0],
14122
- setCurrentDetectionScore = _6[1];
14123
- var _7 = React.useState(0),
14124
- currentFocusScore = _7[0],
14125
- setCurrentFocusScore = _7[1];
14126
- var _8 = React.useState(0),
14127
- goodFramesCount = _8[0],
14128
- setGoodFramesCount = _8[1];
14134
+ var _17 = React.useState(0),
14135
+ currentDetectionScore = _17[0],
14136
+ setCurrentDetectionScore = _17[1];
14137
+ var _18 = React.useState(0),
14138
+ currentFocusScore = _18[0],
14139
+ setCurrentFocusScore = _18[1];
14140
+ var _19 = React.useState(0),
14141
+ goodFramesCount = _19[0],
14142
+ setGoodFramesCount = _19[1];
14129
14143
  var goodFramesThreshold = requestedAction === 'SHOW_ID_FRONT' ? goodIdCardFrontFramesThreshold : goodIdCardBackFramesThreshold;
14130
14144
  var goodFramesThresholdMet = goodFramesCount >= goodFramesThreshold;
14131
14145
  React.useEffect(function () {
@@ -14210,17 +14224,25 @@ var IdVideoCapture = function IdVideoCapture(_a) {
14210
14224
  stopRecording();
14211
14225
  }, [stopRecording]);
14212
14226
  var timeoutStartedAt = useTimeout(readTextTimeoutDurationMs, onReadTextTimeout, requestedAction !== 'READ_TEXT', false, requestedAction === 'READ_TEXT').timeoutStartedAt;
14213
- var _9 = React.useState(0),
14214
- numFramesWithoutFaces = _9[0],
14215
- setNumFramesWithoutFaces = _9[1];
14227
+ var frameWidth = (_c = (_b = videoRef.current) === null || _b === void 0 ? void 0 : _b.videoWidth) !== null && _c !== void 0 ? _c : 0;
14228
+ var frameHeight = (_e = (_d = videoRef.current) === null || _d === void 0 ? void 0 : _d.videoHeight) !== null && _e !== void 0 ? _e : 0;
14229
+ var _20 = React.useState(0),
14230
+ numFramesWithoutFaces = _20[0],
14231
+ setNumFramesWithoutFaces = _20[1];
14216
14232
  React.useEffect(function () {
14217
14233
  onSelfiePredictionMade(function (faces) {
14218
14234
  setFaces(faces);
14219
14235
  setNumFramesWithoutFaces(function (n) {
14220
14236
  return faces.length === 0 ? n + 1 : 0;
14221
14237
  });
14238
+ if (faces.length > 0) {
14239
+ var box = faces[0].box;
14240
+ setFaceCentered(box.xMin > frameWidth * edgeBoundary && box.yMin > frameHeight * edgeBoundary && box.xMax < frameWidth * (1 - edgeBoundary) && box.yMax < frameWidth * (1 - edgeBoundary));
14241
+ } else {
14242
+ setFaceCentered(false);
14243
+ }
14222
14244
  });
14223
- }, [onSelfiePredictionMade]);
14245
+ }, [frameHeight, frameWidth, onSelfiePredictionMade]);
14224
14246
  React.useEffect(function () {
14225
14247
  if (numFramesWithoutFaces >= 2) {
14226
14248
  onFaceNotDetected === null || onFaceNotDetected === void 0 ? void 0 : onFaceNotDetected();
@@ -14228,17 +14250,21 @@ var IdVideoCapture = function IdVideoCapture(_a) {
14228
14250
  }, [numFramesWithoutFaces, onFaceNotDetected]);
14229
14251
  colors.guidesSatisfiedColor || (colors.guidesSatisfiedColor = 'green');
14230
14252
  colors.guidesUnsatisfiedColor || (colors.guidesUnsatisfiedColor = 'white');
14253
+ var theme = styled.useTheme();
14254
+ var faceNotCenteredText = useTranslations(rawVerbiage, {
14255
+ faceNotCenteredText: 'Please move your face to the center...'
14256
+ }).faceNotCenteredText;
14231
14257
  var debugScalingDetails = useDebugScalingDetails({
14232
14258
  enabled: debugMode,
14233
14259
  pageWidth: width,
14234
14260
  pageHeight: height,
14235
- videoWidth: (_c = (_b = videoRef.current) === null || _b === void 0 ? void 0 : _b.videoWidth) !== null && _c !== void 0 ? _c : 0,
14236
- videoHeight: (_e = (_d = videoRef.current) === null || _d === void 0 ? void 0 : _d.videoHeight) !== null && _e !== void 0 ? _e : 0
14261
+ videoWidth: (_g = (_f = videoRef.current) === null || _f === void 0 ? void 0 : _f.videoWidth) !== null && _g !== void 0 ? _g : 0,
14262
+ videoHeight: (_j = (_h = videoRef.current) === null || _h === void 0 ? void 0 : _h.videoHeight) !== null && _j !== void 0 ? _j : 0
14237
14263
  });
14238
- var satisfied = goodFramesCount > 0;
14264
+ var satisfied = goodFramesCount > 0 && faceCentered;
14239
14265
  return /*#__PURE__*/React__default['default'].createElement(PageContainer, {
14240
14266
  ref: ref,
14241
- className: "flex ".concat((_f = classNames.container) !== null && _f !== void 0 ? _f : '')
14267
+ className: "flex ".concat((_k = classNames.container) !== null && _k !== void 0 ? _k : '')
14242
14268
  }, /*#__PURE__*/React__default['default'].createElement(CameraVideoTag, {
14243
14269
  className: classNames.cameraFeed
14244
14270
  }), /*#__PURE__*/React__default['default'].createElement(InvisibleCanvas, {
@@ -14255,8 +14281,11 @@ var IdVideoCapture = function IdVideoCapture(_a) {
14255
14281
  verbiage: rawVerbiage.guides,
14256
14282
  requestedAction: requestedAction,
14257
14283
  borderColor: satisfied ? colors.guidesSatisfiedColor : colors.guidesUnsatisfiedColor
14258
- }), debugMode && ['SHOW_ID_FRONT', 'SHOW_ID_BACK'].includes(requestedAction) && ( /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, /*#__PURE__*/React__default['default'].createElement(ObjectDetectionDebugOverlayDiv, {
14259
- "$flipX": !((_g = cameraRef.current) === null || _g === void 0 ? void 0 : _g.isRearFacing)
14284
+ }), !faceCentered && ( /*#__PURE__*/React__default['default'].createElement(GuidanceMessageContainer, null, /*#__PURE__*/React__default['default'].createElement(GuidanceMessage, {
14285
+ "$background": (_o = (_m = (_l = theme.guidanceMessages) === null || _l === void 0 ? void 0 : _l.negative) === null || _m === void 0 ? void 0 : _m.backgroundColor) !== null && _o !== void 0 ? _o : 'red',
14286
+ "$textColor": (_r = (_q = (_p = theme.guidanceMessages) === null || _p === void 0 ? void 0 : _p.negative) === null || _q === void 0 ? void 0 : _q.textColor) !== null && _r !== void 0 ? _r : 'white'
14287
+ }, faceNotCenteredText))), debugMode && ['SHOW_ID_FRONT', 'SHOW_ID_BACK'].includes(requestedAction) && ( /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, /*#__PURE__*/React__default['default'].createElement(ObjectDetectionDebugOverlayDiv, {
14288
+ "$flipX": !((_s = cameraRef.current) === null || _s === void 0 ? void 0 : _s.isRearFacing)
14260
14289
  }, detectedObjects.map(function (obj, i) {
14261
14290
  var _a;
14262
14291
  return /*#__PURE__*/React__default['default'].createElement(IdCaptureDetectedObjectDebugBox, {
@@ -14267,7 +14296,7 @@ var IdVideoCapture = function IdVideoCapture(_a) {
14267
14296
  flipX: !((_a = cameraRef.current) === null || _a === void 0 ? void 0 : _a.isRearFacing)
14268
14297
  });
14269
14298
  })), /*#__PURE__*/React__default['default'].createElement(DebugBoundingBoxOverlay, {
14270
- "$flipX": !((_h = cameraRef.current) === null || _h === void 0 ? void 0 : _h.isRearFacing)
14299
+ "$flipX": !((_t = cameraRef.current) === null || _t === void 0 ? void 0 : _t.isRearFacing)
14271
14300
  }, faces.map(function (face, i) {
14272
14301
  var _a;
14273
14302
  return /*#__PURE__*/React__default['default'].createElement(SelfieCaptureFaceDebugBox, {