idmission-web-sdk 2.2.30 → 2.2.32

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.
@@ -232,7 +232,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
232
232
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
233
233
  };
234
234
 
235
- var webSdkVersion = '2.2.30';
235
+ var webSdkVersion = '2.2.32';
236
236
 
237
237
  function getPlatform() {
238
238
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -2814,30 +2814,29 @@ var defaultFocusThresholds = {
2814
2814
  mobile: 0.3
2815
2815
  }
2816
2816
  };
2817
- var models = {};
2817
+ var classifier = null;
2818
+ var classifierSettings = null;
2818
2819
  function loadFocusModel() {
2819
2820
  return __awaiter(this, arguments, void 0, function (modelAssetPath) {
2820
- var id, _a, _b, _c, _d;
2821
+ var _a, _b;
2821
2822
  if (modelAssetPath === void 0) {
2822
2823
  modelAssetPath = defaultFocusModelPath;
2823
2824
  }
2824
- return __generator(this, function (_e) {
2825
- switch (_e.label) {
2825
+ return __generator(this, function (_c) {
2826
+ switch (_c.label) {
2826
2827
  case 0:
2827
- id = "".concat(modelAssetPath);
2828
- if (models[id]) return [2 /*return*/, models[id]];
2828
+ if (classifier && (classifierSettings === null || classifierSettings === void 0 ? void 0 : classifierSettings.modelAssetPath) === modelAssetPath) return [2 /*return*/, classifier];
2829
+ closeFocusModel();
2829
2830
  return [4 /*yield*/, preloadFocusModelDependencies()];
2830
2831
  case 1:
2831
- _e.sent();
2832
+ _c.sent();
2832
2833
  if (modelCapabilities.delegate === 'NONE') {
2833
2834
  throw new Error('No available delegate for focus detector.');
2834
2835
  }
2835
- _a = models;
2836
- _b = id;
2837
- _d = (_c = tasksVision.ImageClassifier).createFromOptions;
2836
+ _b = (_a = tasksVision.ImageClassifier).createFromOptions;
2838
2837
  return [4 /*yield*/, tasksVision.FilesetResolver.forVisionTasks(visionTasksBasePath)];
2839
2838
  case 2:
2840
- return [4 /*yield*/, _d.apply(_c, [_e.sent(), {
2839
+ return [4 /*yield*/, _b.apply(_a, [_c.sent(), {
2841
2840
  baseOptions: {
2842
2841
  modelAssetPath: modelAssetPath,
2843
2842
  delegate: modelCapabilities.delegate
@@ -2846,20 +2845,19 @@ function loadFocusModel() {
2846
2845
  runningMode: 'VIDEO'
2847
2846
  }])];
2848
2847
  case 3:
2849
- _a[_b] = _e.sent();
2850
- return [2 /*return*/, models[id]];
2848
+ classifier = _c.sent();
2849
+ classifierSettings = {
2850
+ modelAssetPath: modelAssetPath
2851
+ };
2852
+ return [2 /*return*/, classifier];
2851
2853
  }
2852
2854
  });
2853
2855
  });
2854
2856
  }
2855
- function closeFocusModel(modelAssetPath) {
2856
- if (modelAssetPath === void 0) {
2857
- modelAssetPath = defaultFocusModelPath;
2858
- }
2859
- var id = "".concat(modelAssetPath);
2860
- if (!models[id]) return;
2861
- models[id].close();
2862
- delete models[id];
2857
+ function closeFocusModel() {
2858
+ classifier === null || classifier === void 0 ? void 0 : classifier.close();
2859
+ classifier = null;
2860
+ classifierSettings = null;
2863
2861
  }
2864
2862
  function useLoadFocusModel(_a) {
2865
2863
  var _b = _a.modelPath,
@@ -2867,7 +2865,6 @@ function useLoadFocusModel(_a) {
2867
2865
  _c = _a.modelLoadTimeoutMs,
2868
2866
  modelLoadTimeoutMs = _c === void 0 ? defaultFocusModelLoadTimeoutMs : _c,
2869
2867
  onModelError = _a.onModelError;
2870
- var model = React.useRef(null);
2871
2868
  var _d = React.useState(false),
2872
2869
  ready = _d[0],
2873
2870
  setReady = _d[1];
@@ -2893,7 +2890,6 @@ function useLoadFocusModel(_a) {
2893
2890
  return __generator(this, function (_a) {
2894
2891
  switch (_a.label) {
2895
2892
  case 0:
2896
- model.current = loadedModel;
2897
2893
  setModelDownloadProgress(100);
2898
2894
  clearTimeout(modelLoadTimeout);
2899
2895
  return [4 /*yield*/, waitForVideoReady(videoRef)];
@@ -2913,9 +2909,8 @@ function useLoadFocusModel(_a) {
2913
2909
  clearTimeout(modelLoadTimeout);
2914
2910
  });
2915
2911
  return function () {
2916
- log('unloading focus model', model.current);
2917
- model.current = null;
2918
- closeFocusModel(modelPath);
2912
+ log('unloading focus model');
2913
+ closeFocusModel();
2919
2914
  clearTimeout(modelLoadTimeout);
2920
2915
  document.removeEventListener('idmission.preloadProgress.focus', handleDownloadProgress);
2921
2916
  };
@@ -2924,7 +2919,6 @@ function useLoadFocusModel(_a) {
2924
2919
  modelError && (onModelError === null || onModelError === void 0 ? void 0 : onModelError(modelError));
2925
2920
  }, [modelError, onModelError]);
2926
2921
  return {
2927
- model: model,
2928
2922
  ready: ready,
2929
2923
  modelDownloadProgress: modelDownloadProgress,
2930
2924
  modelError: modelError
@@ -2936,11 +2930,12 @@ function setLastFocusPredictionAt(time) {
2936
2930
  lastFocusPredictionTime = time - lastFocusPredictionAt;
2937
2931
  lastFocusPredictionAt = time;
2938
2932
  }
2939
- function makeFocusModelPrediction(model, imageData, cropCanvas, rotateCanvas, box) {
2933
+ function makeFocusModelPrediction(imageData, cropCanvas, rotateCanvas, box) {
2940
2934
  var _a, _b, _c, _d, _e;
2935
+ if (!classifier) return null;
2941
2936
  var startedAt = new Date();
2942
2937
  var image = cropIfNecessary(imageData, cropCanvas, rotateCanvas, box);
2943
- var result = model.classifyForVideo(image, performance.now());
2938
+ var result = classifier.classifyForVideo(image, performance.now());
2944
2939
  var score = (_e = (_d = (_c = (_b = (_a = result === null || result === void 0 ? void 0 : result.classifications) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.categories) === null || _c === void 0 ? void 0 : _c.find(function (c) {
2945
2940
  return c.categoryName === 'focused';
2946
2941
  })) === null || _d === void 0 ? void 0 : _d.score) !== null && _e !== void 0 ? _e : 0;
@@ -2969,30 +2964,29 @@ function cropIfNecessary(imageData, cropCanvas, rotateCanvas, box) {
2969
2964
  }
2970
2965
 
2971
2966
  var defaultSelfieCaptureModelLoadTimeoutMs = 45000;
2972
- var detectors$1 = {};
2967
+ var detector$1 = null;
2968
+ var detectorSettings$1 = null;
2973
2969
  function loadFaceDetector() {
2974
2970
  return __awaiter(this, arguments, void 0, function (modelAssetPath) {
2975
- var id, _a, _b, _c, _d;
2971
+ var _a, _b;
2976
2972
  if (modelAssetPath === void 0) {
2977
2973
  modelAssetPath = defaultFaceDetectorModelPath;
2978
2974
  }
2979
- return __generator(this, function (_e) {
2980
- switch (_e.label) {
2975
+ return __generator(this, function (_c) {
2976
+ switch (_c.label) {
2981
2977
  case 0:
2982
- id = "".concat(modelAssetPath);
2983
- if (detectors$1[id]) return [2 /*return*/, detectors$1[id]];
2978
+ if (detector$1 && (detectorSettings$1 === null || detectorSettings$1 === void 0 ? void 0 : detectorSettings$1.modelAssetPath) === modelAssetPath) return [2 /*return*/, detector$1];
2979
+ closeFaceDetector();
2984
2980
  return [4 /*yield*/, preloadFaceDetectorDependencies()];
2985
2981
  case 1:
2986
- _e.sent();
2982
+ _c.sent();
2987
2983
  if (modelCapabilities.delegate === 'NONE') {
2988
2984
  throw new Error('No available delegate for face detector.');
2989
2985
  }
2990
- _a = detectors$1;
2991
- _b = id;
2992
- _d = (_c = tasksVision.FaceDetector).createFromOptions;
2986
+ _b = (_a = tasksVision.FaceDetector).createFromOptions;
2993
2987
  return [4 /*yield*/, tasksVision.FilesetResolver.forVisionTasks(visionTasksBasePath)];
2994
2988
  case 2:
2995
- return [4 /*yield*/, _d.apply(_c, [_e.sent(), {
2989
+ return [4 /*yield*/, _b.apply(_a, [_c.sent(), {
2996
2990
  // canvas: document.createElement('canvas'),
2997
2991
  baseOptions: {
2998
2992
  modelAssetPath: modelAssetPath,
@@ -3001,26 +2995,24 @@ function loadFaceDetector() {
3001
2995
  runningMode: 'VIDEO'
3002
2996
  }])];
3003
2997
  case 3:
3004
- _a[_b] = _e.sent();
3005
- return [2 /*return*/, detectors$1[id]];
2998
+ detector$1 = _c.sent();
2999
+ detectorSettings$1 = {
3000
+ modelAssetPath: modelAssetPath
3001
+ };
3002
+ return [2 /*return*/, detector$1];
3006
3003
  }
3007
3004
  });
3008
3005
  });
3009
3006
  }
3010
- function closeFaceDetector(modelAssetPath) {
3011
- if (modelAssetPath === void 0) {
3012
- modelAssetPath = defaultFaceDetectorModelPath;
3013
- }
3014
- var id = "".concat(modelAssetPath);
3015
- if (!detectors$1[id]) return;
3016
- detectors$1[id].close();
3017
- delete detectors$1[id];
3007
+ function closeFaceDetector() {
3008
+ detector$1 === null || detector$1 === void 0 ? void 0 : detector$1.close();
3009
+ detector$1 = null;
3010
+ detectorSettings$1 = null;
3018
3011
  }
3019
3012
  function useLoadFaceDetector(_a) {
3020
3013
  var onModelError = _a.onModelError,
3021
3014
  _b = _a.modelLoadTimeoutMs,
3022
3015
  modelLoadTimeoutMs = _b === void 0 ? defaultSelfieCaptureModelLoadTimeoutMs : _b;
3023
- var detector = React.useRef(null);
3024
3016
  var _c = React.useState(false),
3025
3017
  ready = _c[0],
3026
3018
  setReady = _c[1];
@@ -3046,7 +3038,6 @@ function useLoadFaceDetector(_a) {
3046
3038
  return __generator(this, function (_a) {
3047
3039
  switch (_a.label) {
3048
3040
  case 0:
3049
- detector.current = model;
3050
3041
  setModelDownloadProgress(100);
3051
3042
  clearTimeout(modelLoadTimeout);
3052
3043
  return [4 /*yield*/, waitForVideoReady(videoRef)];
@@ -3064,8 +3055,7 @@ function useLoadFaceDetector(_a) {
3064
3055
  clearTimeout(modelLoadTimeout);
3065
3056
  });
3066
3057
  return function () {
3067
- log('unloading face detection model', detector.current);
3068
- detector.current = null;
3058
+ log('unloading face detection model');
3069
3059
  closeFaceDetector();
3070
3060
  clearTimeout(modelLoadTimeout);
3071
3061
  document.removeEventListener('idmission.preloadProgress.faceDetection', handleDownloadProgress);
@@ -3075,7 +3065,6 @@ function useLoadFaceDetector(_a) {
3075
3065
  modelError && (onModelError === null || onModelError === void 0 ? void 0 : onModelError(modelError));
3076
3066
  }, [modelError, onModelError]);
3077
3067
  return {
3078
- detector: detector,
3079
3068
  ready: ready,
3080
3069
  modelDownloadProgress: modelDownloadProgress,
3081
3070
  modelError: modelError
@@ -3114,8 +3103,9 @@ function trackFace(face, framesNeeded) {
3114
3103
  if (lastNPairs$1.length > framesNeeded - 1) lastNPairs$1.length = framesNeeded - 1;
3115
3104
  }
3116
3105
  }
3117
- function makeFaceDetectorPrediction(model, imageData) {
3118
- var prediction = model.detectForVideo(imageData, performance.now());
3106
+ function makeFaceDetectorPrediction(imageData) {
3107
+ if (!detector$1) return null;
3108
+ var prediction = detector$1.detectForVideo(imageData, performance.now());
3119
3109
  var faces = prediction.detections.map(function (d) {
3120
3110
  return {
3121
3111
  box: convertBoundingBox(d.boundingBox),
@@ -3251,11 +3241,10 @@ var progressByUseCase = {
3251
3241
  };
3252
3242
  function preloadDependency(url) {
3253
3243
  return __awaiter(this, void 0, void 0, function () {
3254
- var xhr;
3255
3244
  return __generator(this, function (_a) {
3256
- xhr = new XMLHttpRequest();
3257
- return [2 /*return*/, new Promise(function (resolve) {
3258
- xhr.addEventListener('progress', function (event) {
3245
+ return [2 /*return*/, new Promise(function (resolve, reject) {
3246
+ var req = new XMLHttpRequest();
3247
+ req.addEventListener('progress', function (event) {
3259
3248
  if (!event.lengthComputable) return;
3260
3249
  progressByUrl[url] = event;
3261
3250
  document.dispatchEvent(new CustomEvent('idmission.preloadProgress', {
@@ -3266,11 +3255,12 @@ function preloadDependency(url) {
3266
3255
  }
3267
3256
  }));
3268
3257
  });
3269
- xhr.addEventListener('loadend', function () {
3270
- resolve(xhr.readyState === 4 && xhr.status === 200);
3258
+ req.addEventListener('loadend', function () {
3259
+ resolve(req.readyState === 4 && req.status === 200);
3271
3260
  });
3272
- xhr.open('GET', url, true);
3273
- xhr.send();
3261
+ req.addEventListener('error', reject);
3262
+ req.open('GET', url, true);
3263
+ req.send();
3274
3264
  })];
3275
3265
  });
3276
3266
  });
@@ -3293,8 +3283,11 @@ function preloadDocumentDetectorDependencies() {
3293
3283
  switch (_a.label) {
3294
3284
  case 0:
3295
3285
  if (documentDetectorPreloading) return [2 /*return*/, new Promise(function (resolve) {
3296
- setInterval(function () {
3297
- if (!documentDetectorPreloading) resolve();
3286
+ var i = setInterval(function () {
3287
+ if (!documentDetectorPreloading) {
3288
+ clearInterval(i);
3289
+ resolve();
3290
+ }
3298
3291
  }, 100);
3299
3292
  })];
3300
3293
  documentDetectorPreloading = true;
@@ -3338,8 +3331,11 @@ function preloadFocusModelDependencies() {
3338
3331
  switch (_a.label) {
3339
3332
  case 0:
3340
3333
  if (focusModelPreloading) return [2 /*return*/, new Promise(function (resolve) {
3341
- setInterval(function () {
3342
- if (!focusModelPreloading) resolve();
3334
+ var i = setInterval(function () {
3335
+ if (!focusModelPreloading) {
3336
+ clearInterval(i);
3337
+ resolve();
3338
+ }
3343
3339
  }, 100);
3344
3340
  })];
3345
3341
  focusModelPreloading = true;
@@ -3383,8 +3379,11 @@ function preloadFaceDetectorDependencies() {
3383
3379
  switch (_a.label) {
3384
3380
  case 0:
3385
3381
  if (faceDetectorPreloading) return [2 /*return*/, new Promise(function (resolve) {
3386
- setInterval(function () {
3387
- if (!faceDetectorPreloading) resolve();
3382
+ var i = setInterval(function () {
3383
+ if (!faceDetectorPreloading) {
3384
+ clearInterval(i);
3385
+ resolve();
3386
+ }
3388
3387
  }, 100);
3389
3388
  })];
3390
3389
  faceDetectorPreloading = true;
@@ -3447,33 +3446,32 @@ var documentTypeDisplayNames = {
3447
3446
  passport: 'Passport',
3448
3447
  none: 'None'
3449
3448
  };
3450
- var detectors = {};
3449
+ var detector = null;
3450
+ var detectorSettings = null;
3451
3451
  function loadDocumentDetector() {
3452
3452
  return __awaiter(this, arguments, void 0, function (modelAssetPath, scoreThreshold) {
3453
- var id, _a, _b, _c, _d;
3453
+ var _a, _b;
3454
3454
  if (modelAssetPath === void 0) {
3455
3455
  modelAssetPath = defaultDocumentDetectorModelPath;
3456
3456
  }
3457
3457
  if (scoreThreshold === void 0) {
3458
3458
  scoreThreshold = defaultDocumentDetectionScoreThreshold;
3459
3459
  }
3460
- return __generator(this, function (_e) {
3461
- switch (_e.label) {
3460
+ return __generator(this, function (_c) {
3461
+ switch (_c.label) {
3462
3462
  case 0:
3463
- id = "".concat(modelAssetPath, ":").concat(scoreThreshold);
3464
- if (detectors[id]) return [2 /*return*/, detectors[id]];
3463
+ if (detector && (detectorSettings === null || detectorSettings === void 0 ? void 0 : detectorSettings.modelAssetPath) === modelAssetPath && (detectorSettings === null || detectorSettings === void 0 ? void 0 : detectorSettings.scoreThreshold) === scoreThreshold) return [2 /*return*/, detector];
3464
+ closeDocumentDetector();
3465
3465
  return [4 /*yield*/, preloadDocumentDetectorDependencies()];
3466
3466
  case 1:
3467
- _e.sent();
3467
+ _c.sent();
3468
3468
  if (modelCapabilities.delegate === 'NONE') {
3469
3469
  throw new Error('No available delegate for document detector.');
3470
3470
  }
3471
- _a = detectors;
3472
- _b = id;
3473
- _d = (_c = tasksVision.ObjectDetector).createFromOptions;
3471
+ _b = (_a = tasksVision.ObjectDetector).createFromOptions;
3474
3472
  return [4 /*yield*/, tasksVision.FilesetResolver.forVisionTasks(visionTasksBasePath)];
3475
3473
  case 2:
3476
- return [4 /*yield*/, _d.apply(_c, [_e.sent(), {
3474
+ return [4 /*yield*/, _b.apply(_a, [_c.sent(), {
3477
3475
  baseOptions: {
3478
3476
  modelAssetPath: modelAssetPath,
3479
3477
  delegate: modelCapabilities.delegate
@@ -3483,23 +3481,20 @@ function loadDocumentDetector() {
3483
3481
  runningMode: 'VIDEO'
3484
3482
  }])];
3485
3483
  case 3:
3486
- _a[_b] = _e.sent();
3487
- return [2 /*return*/, detectors[id]];
3484
+ detector = _c.sent();
3485
+ detectorSettings = {
3486
+ modelAssetPath: modelAssetPath,
3487
+ scoreThreshold: scoreThreshold
3488
+ };
3489
+ return [2 /*return*/, detector];
3488
3490
  }
3489
3491
  });
3490
3492
  });
3491
3493
  }
3492
- function closeDocumentDetector(modelAssetPath, scoreThreshold) {
3493
- if (modelAssetPath === void 0) {
3494
- modelAssetPath = defaultDocumentDetectorModelPath;
3495
- }
3496
- if (scoreThreshold === void 0) {
3497
- scoreThreshold = defaultDocumentDetectionScoreThreshold;
3498
- }
3499
- var id = "".concat(modelAssetPath, ":").concat(scoreThreshold);
3500
- if (!detectors[id]) return;
3501
- detectors[id].close();
3502
- delete detectors[id];
3494
+ function closeDocumentDetector() {
3495
+ detector === null || detector === void 0 ? void 0 : detector.close();
3496
+ detector = null;
3497
+ detectorSettings = null;
3503
3498
  }
3504
3499
  function useLoadDocumentDetector(_a) {
3505
3500
  var _b = _a.modelPath,
@@ -3509,7 +3504,6 @@ function useLoadDocumentDetector(_a) {
3509
3504
  _d = _a.scoreThreshold,
3510
3505
  scoreThreshold = _d === void 0 ? defaultDocumentDetectionScoreThreshold : _d,
3511
3506
  onModelError = _a.onModelError;
3512
- var detector = React.useRef(null);
3513
3507
  var _e = React.useState(false),
3514
3508
  ready = _e[0],
3515
3509
  setReady = _e[1];
@@ -3535,7 +3529,6 @@ function useLoadDocumentDetector(_a) {
3535
3529
  return __generator(this, function (_a) {
3536
3530
  switch (_a.label) {
3537
3531
  case 0:
3538
- detector.current = model;
3539
3532
  setModelDownloadProgress(100);
3540
3533
  clearTimeout(modelLoadTimeout);
3541
3534
  return [4 /*yield*/, waitForVideoReady(videoRef)];
@@ -3556,8 +3549,7 @@ function useLoadDocumentDetector(_a) {
3556
3549
  });
3557
3550
  return function () {
3558
3551
  log('unloading document detection model');
3559
- detector.current = null;
3560
- closeDocumentDetector(modelPath, scoreThreshold);
3552
+ closeDocumentDetector();
3561
3553
  clearTimeout(modelLoadTimeout);
3562
3554
  document.removeEventListener('idmission.preloadProgress.documentDetection', handleDownloadProgress);
3563
3555
  };
@@ -3566,17 +3558,17 @@ function useLoadDocumentDetector(_a) {
3566
3558
  modelError && (onModelError === null || onModelError === void 0 ? void 0 : onModelError(modelError));
3567
3559
  }, [modelError, onModelError]);
3568
3560
  return {
3569
- detector: detector,
3570
3561
  ready: ready,
3571
3562
  modelDownloadProgress: modelDownloadProgress,
3572
3563
  modelError: modelError,
3573
3564
  setModelError: setModelError
3574
3565
  };
3575
3566
  }
3576
- function makeDocumentDetectorPrediction(detector, frame) {
3567
+ function makeDocumentDetectorPrediction(frame) {
3577
3568
  return __awaiter(this, void 0, void 0, function () {
3578
3569
  var startedAt, prediction, time, frameWidth, frameHeight;
3579
3570
  return __generator(this, function (_a) {
3571
+ if (!detector) return [2 /*return*/, null];
3580
3572
  startedAt = new Date();
3581
3573
  // Detectors can throw errors, for example when using custom URLs that
3582
3574
  // contain a model that doesn't provide the expected output.
@@ -3900,7 +3892,6 @@ function DocumentDetectionModelProvider(_a) {
3900
3892
  scoreThreshold: documentDetectionModelScoreThreshold,
3901
3893
  onModelError: onDocumentDetectionModelError
3902
3894
  }),
3903
- detector = _o.detector,
3904
3895
  ready = _o.ready,
3905
3896
  modelDownloadProgress = _o.modelDownloadProgress,
3906
3897
  modelError = _o.modelError,
@@ -3912,7 +3903,7 @@ function DocumentDetectionModelProvider(_a) {
3912
3903
  return __generator(this, function (_b) {
3913
3904
  switch (_b.label) {
3914
3905
  case 0:
3915
- if (!videoLoaded || !cameraReady || !ready || !videoRef.current || !detector.current || !lastPredictionCanvas.current) return [2 /*return*/];
3906
+ if (!videoLoaded || !cameraReady || !ready || !videoRef.current || !lastPredictionCanvas.current) return [2 /*return*/];
3916
3907
  stopDetectionAtStart = stopDetection.current;
3917
3908
  vw = videoRef.current.videoWidth;
3918
3909
  vh = videoRef.current.videoHeight;
@@ -3922,7 +3913,7 @@ function DocumentDetectionModelProvider(_a) {
3922
3913
  if (!(ctx && videoRef.current.readyState === 4)) return [3 /*break*/, 3];
3923
3914
  if (stopDetectionAtStart !== stopDetection.current) return [2 /*return*/];
3924
3915
  ctx.drawImage(videoRef.current, 0, 0, vw, vh);
3925
- return [4 /*yield*/, makeDocumentDetectorPrediction(detector.current, lastPredictionCanvas.current)];
3916
+ return [4 /*yield*/, makeDocumentDetectorPrediction(lastPredictionCanvas.current)];
3926
3917
  case 1:
3927
3918
  prediction = _b.sent();
3928
3919
  if (!prediction) return [3 /*break*/, 3];
@@ -3944,7 +3935,7 @@ function DocumentDetectionModelProvider(_a) {
3944
3935
  }
3945
3936
  });
3946
3937
  });
3947
- }, [cameraReady, delayAfterStartMs, detector, documentDetectionBoundaries, documentDetectionThresholds, ready, videoLoaded, videoRef]), {
3938
+ }, [cameraReady, delayAfterStartMs, documentDetectionBoundaries, documentDetectionThresholds, ready, videoLoaded, videoRef]), {
3948
3939
  throttleMs: throttleMs,
3949
3940
  autoStart: autoStart
3950
3941
  }),
@@ -4021,16 +4012,16 @@ function FocusModelProvider(_a) {
4021
4012
  modelLoadTimeoutMs: focusModelLoadTimeoutMs,
4022
4013
  onModelError: onFocusModelError
4023
4014
  }),
4024
- model = _f.model,
4025
4015
  ready = _f.ready,
4026
4016
  modelDownloadProgress = _f.modelDownloadProgress,
4027
4017
  modelError = _f.modelError;
4028
4018
  var makeFocusPrediction = React.useCallback(function (imageData, box) {
4029
- if (!model.current) return null;
4030
- var prediction = makeFocusModelPrediction(model.current, imageData, cropCanvas.current, rotateCanvas.current, box);
4019
+ if (!ready) return null;
4020
+ var prediction = makeFocusModelPrediction(imageData, cropCanvas.current, rotateCanvas.current, box);
4021
+ if (!prediction) return null;
4031
4022
  setLastFocusPredictionAt(prediction.predictionTime);
4032
4023
  return prediction;
4033
- }, [model]);
4024
+ }, [ready]);
4034
4025
  var value = React.useMemo(function () {
4035
4026
  return {
4036
4027
  focusModelReady: ready,
@@ -9253,18 +9244,17 @@ function SelfieGuidanceModelsProvider(_a) {
9253
9244
  onModelError: onModelError,
9254
9245
  modelLoadTimeoutMs: modelLoadTimeoutMs
9255
9246
  }),
9256
- detector = _f.detector,
9257
9247
  ready = _f.ready,
9258
9248
  modelDownloadProgress = _f.modelDownloadProgress,
9259
9249
  modelError = _f.modelError;
9260
9250
  var _g = useFrameLoop(React.useCallback(function () {
9261
9251
  return __awaiter(_this, void 0, void 0, function () {
9262
- var vw, vh, ctx, faces, processed, e_1;
9263
- var _a;
9264
- return __generator(this, function (_b) {
9265
- switch (_b.label) {
9252
+ var vw, vh, ctx, prediction, processed, e_1;
9253
+ var _a, _b;
9254
+ return __generator(this, function (_c) {
9255
+ switch (_c.label) {
9266
9256
  case 0:
9267
- if (!videoLoaded || !cameraReady || !ready || modelError || !videoRef.current || !detector.current || !canvasRef.current) return [2 /*return*/];
9257
+ if (!videoLoaded || !cameraReady || !ready || modelError || !videoRef.current || !canvasRef.current) return [2 /*return*/];
9268
9258
  vw = videoRef.current.videoWidth;
9269
9259
  vh = videoRef.current.videoHeight;
9270
9260
  ctx = canvasRef.current.getContext('2d');
@@ -9274,23 +9264,23 @@ function SelfieGuidanceModelsProvider(_a) {
9274
9264
  ctx.translate(vw, 0);
9275
9265
  ctx.scale(-1, 1);
9276
9266
  ctx.drawImage(videoRef.current, 0, 0, vw, vh);
9277
- _b.label = 1;
9267
+ _c.label = 1;
9278
9268
  case 1:
9279
- _b.trys.push([1, 3,, 4]);
9280
- faces = makeFaceDetectorPrediction(detector.current, canvasRef.current).faces;
9269
+ _c.trys.push([1, 3,, 4]);
9270
+ prediction = makeFaceDetectorPrediction(canvasRef.current);
9281
9271
  processed = processFaceDetectorPrediction({
9282
- faces: faces,
9272
+ faces: (_a = prediction === null || prediction === void 0 ? void 0 : prediction.faces) !== null && _a !== void 0 ? _a : [],
9283
9273
  videoWidth: vw,
9284
9274
  videoHeight: vh,
9285
9275
  requireVerticalFaceCentering: requireVerticalFaceCentering
9286
9276
  });
9287
9277
  setLastFaceDetectionAt(new Date().getTime());
9288
- return [4 /*yield*/, (_a = onPredictionHandler.current) === null || _a === void 0 ? void 0 : _a.call(onPredictionHandler, processed)];
9278
+ return [4 /*yield*/, (_b = onPredictionHandler.current) === null || _b === void 0 ? void 0 : _b.call(onPredictionHandler, processed)];
9289
9279
  case 2:
9290
- _b.sent();
9280
+ _c.sent();
9291
9281
  return [3 /*break*/, 4];
9292
9282
  case 3:
9293
- e_1 = _b.sent();
9283
+ e_1 = _c.sent();
9294
9284
  error('caught face detection error', e_1);
9295
9285
  return [3 /*break*/, 4];
9296
9286
  case 4:
@@ -9298,7 +9288,7 @@ function SelfieGuidanceModelsProvider(_a) {
9298
9288
  }
9299
9289
  });
9300
9290
  });
9301
- }, [cameraReady, detector, modelError, ready, requireVerticalFaceCentering, videoLoaded, videoRef]), {
9291
+ }, [cameraReady, modelError, ready, requireVerticalFaceCentering, videoLoaded, videoRef]), {
9302
9292
  throttleMs: throttleMs,
9303
9293
  autoStart: autoStart
9304
9294
  }),