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.
@@ -211,7 +211,7 @@
211
211
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
212
212
  };
213
213
 
214
- var webSdkVersion = '2.2.30';
214
+ var webSdkVersion = '2.2.32';
215
215
 
216
216
  function getPlatform() {
217
217
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -8858,30 +8858,29 @@
8858
8858
  mobile: 0.3
8859
8859
  }
8860
8860
  };
8861
- var models = {};
8861
+ var classifier = null;
8862
+ var classifierSettings = null;
8862
8863
  function loadFocusModel() {
8863
8864
  return __awaiter(this, arguments, void 0, function (modelAssetPath) {
8864
- var id, _a, _b, _c, _d;
8865
+ var _a, _b;
8865
8866
  if (modelAssetPath === void 0) {
8866
8867
  modelAssetPath = defaultFocusModelPath;
8867
8868
  }
8868
- return __generator(this, function (_e) {
8869
- switch (_e.label) {
8869
+ return __generator(this, function (_c) {
8870
+ switch (_c.label) {
8870
8871
  case 0:
8871
- id = "".concat(modelAssetPath);
8872
- if (models[id]) return [2 /*return*/, models[id]];
8872
+ if (classifier && (classifierSettings === null || classifierSettings === void 0 ? void 0 : classifierSettings.modelAssetPath) === modelAssetPath) return [2 /*return*/, classifier];
8873
+ closeFocusModel();
8873
8874
  return [4 /*yield*/, preloadFocusModelDependencies()];
8874
8875
  case 1:
8875
- _e.sent();
8876
+ _c.sent();
8876
8877
  if (modelCapabilities.delegate === 'NONE') {
8877
8878
  throw new Error('No available delegate for focus detector.');
8878
8879
  }
8879
- _a = models;
8880
- _b = id;
8881
- _d = (_c = Ua).createFromOptions;
8880
+ _b = (_a = Ua).createFromOptions;
8882
8881
  return [4 /*yield*/, ao.forVisionTasks(visionTasksBasePath)];
8883
8882
  case 2:
8884
- return [4 /*yield*/, _d.apply(_c, [_e.sent(), {
8883
+ return [4 /*yield*/, _b.apply(_a, [_c.sent(), {
8885
8884
  baseOptions: {
8886
8885
  modelAssetPath: modelAssetPath,
8887
8886
  delegate: modelCapabilities.delegate
@@ -8890,20 +8889,19 @@
8890
8889
  runningMode: 'VIDEO'
8891
8890
  }])];
8892
8891
  case 3:
8893
- _a[_b] = _e.sent();
8894
- return [2 /*return*/, models[id]];
8892
+ classifier = _c.sent();
8893
+ classifierSettings = {
8894
+ modelAssetPath: modelAssetPath
8895
+ };
8896
+ return [2 /*return*/, classifier];
8895
8897
  }
8896
8898
  });
8897
8899
  });
8898
8900
  }
8899
- function closeFocusModel(modelAssetPath) {
8900
- if (modelAssetPath === void 0) {
8901
- modelAssetPath = defaultFocusModelPath;
8902
- }
8903
- var id = "".concat(modelAssetPath);
8904
- if (!models[id]) return;
8905
- models[id].close();
8906
- delete models[id];
8901
+ function closeFocusModel() {
8902
+ classifier === null || classifier === void 0 ? void 0 : classifier.close();
8903
+ classifier = null;
8904
+ classifierSettings = null;
8907
8905
  }
8908
8906
  function useLoadFocusModel(_a) {
8909
8907
  var _b = _a.modelPath,
@@ -8911,7 +8909,6 @@
8911
8909
  _c = _a.modelLoadTimeoutMs,
8912
8910
  modelLoadTimeoutMs = _c === void 0 ? defaultFocusModelLoadTimeoutMs : _c,
8913
8911
  onModelError = _a.onModelError;
8914
- var model = React.useRef(null);
8915
8912
  var _d = React.useState(false),
8916
8913
  ready = _d[0],
8917
8914
  setReady = _d[1];
@@ -8937,7 +8934,6 @@
8937
8934
  return __generator(this, function (_a) {
8938
8935
  switch (_a.label) {
8939
8936
  case 0:
8940
- model.current = loadedModel;
8941
8937
  setModelDownloadProgress(100);
8942
8938
  clearTimeout(modelLoadTimeout);
8943
8939
  return [4 /*yield*/, waitForVideoReady(videoRef)];
@@ -8957,9 +8953,8 @@
8957
8953
  clearTimeout(modelLoadTimeout);
8958
8954
  });
8959
8955
  return function () {
8960
- log('unloading focus model', model.current);
8961
- model.current = null;
8962
- closeFocusModel(modelPath);
8956
+ log('unloading focus model');
8957
+ closeFocusModel();
8963
8958
  clearTimeout(modelLoadTimeout);
8964
8959
  document.removeEventListener('idmission.preloadProgress.focus', handleDownloadProgress);
8965
8960
  };
@@ -8968,7 +8963,6 @@
8968
8963
  modelError && (onModelError === null || onModelError === void 0 ? void 0 : onModelError(modelError));
8969
8964
  }, [modelError, onModelError]);
8970
8965
  return {
8971
- model: model,
8972
8966
  ready: ready,
8973
8967
  modelDownloadProgress: modelDownloadProgress,
8974
8968
  modelError: modelError
@@ -8980,11 +8974,12 @@
8980
8974
  lastFocusPredictionTime = time - lastFocusPredictionAt;
8981
8975
  lastFocusPredictionAt = time;
8982
8976
  }
8983
- function makeFocusModelPrediction(model, imageData, cropCanvas, rotateCanvas, box) {
8977
+ function makeFocusModelPrediction(imageData, cropCanvas, rotateCanvas, box) {
8984
8978
  var _a, _b, _c, _d, _e;
8979
+ if (!classifier) return null;
8985
8980
  var startedAt = new Date();
8986
8981
  var image = cropIfNecessary(imageData, cropCanvas, rotateCanvas, box);
8987
- var result = model.classifyForVideo(image, performance.now());
8982
+ var result = classifier.classifyForVideo(image, performance.now());
8988
8983
  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) {
8989
8984
  return c.categoryName === 'focused';
8990
8985
  })) === null || _d === void 0 ? void 0 : _d.score) !== null && _e !== void 0 ? _e : 0;
@@ -9013,30 +9008,29 @@
9013
9008
  }
9014
9009
 
9015
9010
  var defaultSelfieCaptureModelLoadTimeoutMs = 45000;
9016
- var detectors$1 = {};
9011
+ var detector$1 = null;
9012
+ var detectorSettings$1 = null;
9017
9013
  function loadFaceDetector() {
9018
9014
  return __awaiter(this, arguments, void 0, function (modelAssetPath) {
9019
- var id, _a, _b, _c, _d;
9015
+ var _a, _b;
9020
9016
  if (modelAssetPath === void 0) {
9021
9017
  modelAssetPath = defaultFaceDetectorModelPath;
9022
9018
  }
9023
- return __generator(this, function (_e) {
9024
- switch (_e.label) {
9019
+ return __generator(this, function (_c) {
9020
+ switch (_c.label) {
9025
9021
  case 0:
9026
- id = "".concat(modelAssetPath);
9027
- if (detectors$1[id]) return [2 /*return*/, detectors$1[id]];
9022
+ if (detector$1 && (detectorSettings$1 === null || detectorSettings$1 === void 0 ? void 0 : detectorSettings$1.modelAssetPath) === modelAssetPath) return [2 /*return*/, detector$1];
9023
+ closeFaceDetector();
9028
9024
  return [4 /*yield*/, preloadFaceDetectorDependencies()];
9029
9025
  case 1:
9030
- _e.sent();
9026
+ _c.sent();
9031
9027
  if (modelCapabilities.delegate === 'NONE') {
9032
9028
  throw new Error('No available delegate for face detector.');
9033
9029
  }
9034
- _a = detectors$1;
9035
- _b = id;
9036
- _d = (_c = ya).createFromOptions;
9030
+ _b = (_a = ya).createFromOptions;
9037
9031
  return [4 /*yield*/, ao.forVisionTasks(visionTasksBasePath)];
9038
9032
  case 2:
9039
- return [4 /*yield*/, _d.apply(_c, [_e.sent(), {
9033
+ return [4 /*yield*/, _b.apply(_a, [_c.sent(), {
9040
9034
  // canvas: document.createElement('canvas'),
9041
9035
  baseOptions: {
9042
9036
  modelAssetPath: modelAssetPath,
@@ -9045,26 +9039,24 @@
9045
9039
  runningMode: 'VIDEO'
9046
9040
  }])];
9047
9041
  case 3:
9048
- _a[_b] = _e.sent();
9049
- return [2 /*return*/, detectors$1[id]];
9042
+ detector$1 = _c.sent();
9043
+ detectorSettings$1 = {
9044
+ modelAssetPath: modelAssetPath
9045
+ };
9046
+ return [2 /*return*/, detector$1];
9050
9047
  }
9051
9048
  });
9052
9049
  });
9053
9050
  }
9054
- function closeFaceDetector(modelAssetPath) {
9055
- if (modelAssetPath === void 0) {
9056
- modelAssetPath = defaultFaceDetectorModelPath;
9057
- }
9058
- var id = "".concat(modelAssetPath);
9059
- if (!detectors$1[id]) return;
9060
- detectors$1[id].close();
9061
- delete detectors$1[id];
9051
+ function closeFaceDetector() {
9052
+ detector$1 === null || detector$1 === void 0 ? void 0 : detector$1.close();
9053
+ detector$1 = null;
9054
+ detectorSettings$1 = null;
9062
9055
  }
9063
9056
  function useLoadFaceDetector(_a) {
9064
9057
  var onModelError = _a.onModelError,
9065
9058
  _b = _a.modelLoadTimeoutMs,
9066
9059
  modelLoadTimeoutMs = _b === void 0 ? defaultSelfieCaptureModelLoadTimeoutMs : _b;
9067
- var detector = React.useRef(null);
9068
9060
  var _c = React.useState(false),
9069
9061
  ready = _c[0],
9070
9062
  setReady = _c[1];
@@ -9090,7 +9082,6 @@
9090
9082
  return __generator(this, function (_a) {
9091
9083
  switch (_a.label) {
9092
9084
  case 0:
9093
- detector.current = model;
9094
9085
  setModelDownloadProgress(100);
9095
9086
  clearTimeout(modelLoadTimeout);
9096
9087
  return [4 /*yield*/, waitForVideoReady(videoRef)];
@@ -9108,8 +9099,7 @@
9108
9099
  clearTimeout(modelLoadTimeout);
9109
9100
  });
9110
9101
  return function () {
9111
- log('unloading face detection model', detector.current);
9112
- detector.current = null;
9102
+ log('unloading face detection model');
9113
9103
  closeFaceDetector();
9114
9104
  clearTimeout(modelLoadTimeout);
9115
9105
  document.removeEventListener('idmission.preloadProgress.faceDetection', handleDownloadProgress);
@@ -9119,7 +9109,6 @@
9119
9109
  modelError && (onModelError === null || onModelError === void 0 ? void 0 : onModelError(modelError));
9120
9110
  }, [modelError, onModelError]);
9121
9111
  return {
9122
- detector: detector,
9123
9112
  ready: ready,
9124
9113
  modelDownloadProgress: modelDownloadProgress,
9125
9114
  modelError: modelError
@@ -9158,8 +9147,9 @@
9158
9147
  if (lastNPairs$1.length > framesNeeded - 1) lastNPairs$1.length = framesNeeded - 1;
9159
9148
  }
9160
9149
  }
9161
- function makeFaceDetectorPrediction(model, imageData) {
9162
- var prediction = model.detectForVideo(imageData, performance.now());
9150
+ function makeFaceDetectorPrediction(imageData) {
9151
+ if (!detector$1) return null;
9152
+ var prediction = detector$1.detectForVideo(imageData, performance.now());
9163
9153
  var faces = prediction.detections.map(function (d) {
9164
9154
  return {
9165
9155
  box: convertBoundingBox(d.boundingBox),
@@ -9295,11 +9285,10 @@
9295
9285
  };
9296
9286
  function preloadDependency(url) {
9297
9287
  return __awaiter(this, void 0, void 0, function () {
9298
- var xhr;
9299
9288
  return __generator(this, function (_a) {
9300
- xhr = new XMLHttpRequest();
9301
- return [2 /*return*/, new Promise(function (resolve) {
9302
- xhr.addEventListener('progress', function (event) {
9289
+ return [2 /*return*/, new Promise(function (resolve, reject) {
9290
+ var req = new XMLHttpRequest();
9291
+ req.addEventListener('progress', function (event) {
9303
9292
  if (!event.lengthComputable) return;
9304
9293
  progressByUrl[url] = event;
9305
9294
  document.dispatchEvent(new CustomEvent('idmission.preloadProgress', {
@@ -9310,11 +9299,12 @@
9310
9299
  }
9311
9300
  }));
9312
9301
  });
9313
- xhr.addEventListener('loadend', function () {
9314
- resolve(xhr.readyState === 4 && xhr.status === 200);
9302
+ req.addEventListener('loadend', function () {
9303
+ resolve(req.readyState === 4 && req.status === 200);
9315
9304
  });
9316
- xhr.open('GET', url, true);
9317
- xhr.send();
9305
+ req.addEventListener('error', reject);
9306
+ req.open('GET', url, true);
9307
+ req.send();
9318
9308
  })];
9319
9309
  });
9320
9310
  });
@@ -9337,8 +9327,11 @@
9337
9327
  switch (_a.label) {
9338
9328
  case 0:
9339
9329
  if (documentDetectorPreloading) return [2 /*return*/, new Promise(function (resolve) {
9340
- setInterval(function () {
9341
- if (!documentDetectorPreloading) resolve();
9330
+ var i = setInterval(function () {
9331
+ if (!documentDetectorPreloading) {
9332
+ clearInterval(i);
9333
+ resolve();
9334
+ }
9342
9335
  }, 100);
9343
9336
  })];
9344
9337
  documentDetectorPreloading = true;
@@ -9382,8 +9375,11 @@
9382
9375
  switch (_a.label) {
9383
9376
  case 0:
9384
9377
  if (focusModelPreloading) return [2 /*return*/, new Promise(function (resolve) {
9385
- setInterval(function () {
9386
- if (!focusModelPreloading) resolve();
9378
+ var i = setInterval(function () {
9379
+ if (!focusModelPreloading) {
9380
+ clearInterval(i);
9381
+ resolve();
9382
+ }
9387
9383
  }, 100);
9388
9384
  })];
9389
9385
  focusModelPreloading = true;
@@ -9427,8 +9423,11 @@
9427
9423
  switch (_a.label) {
9428
9424
  case 0:
9429
9425
  if (faceDetectorPreloading) return [2 /*return*/, new Promise(function (resolve) {
9430
- setInterval(function () {
9431
- if (!faceDetectorPreloading) resolve();
9426
+ var i = setInterval(function () {
9427
+ if (!faceDetectorPreloading) {
9428
+ clearInterval(i);
9429
+ resolve();
9430
+ }
9432
9431
  }, 100);
9433
9432
  })];
9434
9433
  faceDetectorPreloading = true;
@@ -9491,33 +9490,32 @@
9491
9490
  passport: 'Passport',
9492
9491
  none: 'None'
9493
9492
  };
9494
- var detectors = {};
9493
+ var detector = null;
9494
+ var detectorSettings = null;
9495
9495
  function loadDocumentDetector() {
9496
9496
  return __awaiter(this, arguments, void 0, function (modelAssetPath, scoreThreshold) {
9497
- var id, _a, _b, _c, _d;
9497
+ var _a, _b;
9498
9498
  if (modelAssetPath === void 0) {
9499
9499
  modelAssetPath = defaultDocumentDetectorModelPath;
9500
9500
  }
9501
9501
  if (scoreThreshold === void 0) {
9502
9502
  scoreThreshold = defaultDocumentDetectionScoreThreshold;
9503
9503
  }
9504
- return __generator(this, function (_e) {
9505
- switch (_e.label) {
9504
+ return __generator(this, function (_c) {
9505
+ switch (_c.label) {
9506
9506
  case 0:
9507
- id = "".concat(modelAssetPath, ":").concat(scoreThreshold);
9508
- if (detectors[id]) return [2 /*return*/, detectors[id]];
9507
+ 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];
9508
+ closeDocumentDetector();
9509
9509
  return [4 /*yield*/, preloadDocumentDetectorDependencies()];
9510
9510
  case 1:
9511
- _e.sent();
9511
+ _c.sent();
9512
9512
  if (modelCapabilities.delegate === 'NONE') {
9513
9513
  throw new Error('No available delegate for document detector.');
9514
9514
  }
9515
- _a = detectors;
9516
- _b = id;
9517
- _d = (_c = lh).createFromOptions;
9515
+ _b = (_a = lh).createFromOptions;
9518
9516
  return [4 /*yield*/, ao.forVisionTasks(visionTasksBasePath)];
9519
9517
  case 2:
9520
- return [4 /*yield*/, _d.apply(_c, [_e.sent(), {
9518
+ return [4 /*yield*/, _b.apply(_a, [_c.sent(), {
9521
9519
  baseOptions: {
9522
9520
  modelAssetPath: modelAssetPath,
9523
9521
  delegate: modelCapabilities.delegate
@@ -9527,23 +9525,20 @@
9527
9525
  runningMode: 'VIDEO'
9528
9526
  }])];
9529
9527
  case 3:
9530
- _a[_b] = _e.sent();
9531
- return [2 /*return*/, detectors[id]];
9528
+ detector = _c.sent();
9529
+ detectorSettings = {
9530
+ modelAssetPath: modelAssetPath,
9531
+ scoreThreshold: scoreThreshold
9532
+ };
9533
+ return [2 /*return*/, detector];
9532
9534
  }
9533
9535
  });
9534
9536
  });
9535
9537
  }
9536
- function closeDocumentDetector(modelAssetPath, scoreThreshold) {
9537
- if (modelAssetPath === void 0) {
9538
- modelAssetPath = defaultDocumentDetectorModelPath;
9539
- }
9540
- if (scoreThreshold === void 0) {
9541
- scoreThreshold = defaultDocumentDetectionScoreThreshold;
9542
- }
9543
- var id = "".concat(modelAssetPath, ":").concat(scoreThreshold);
9544
- if (!detectors[id]) return;
9545
- detectors[id].close();
9546
- delete detectors[id];
9538
+ function closeDocumentDetector() {
9539
+ detector === null || detector === void 0 ? void 0 : detector.close();
9540
+ detector = null;
9541
+ detectorSettings = null;
9547
9542
  }
9548
9543
  function useLoadDocumentDetector(_a) {
9549
9544
  var _b = _a.modelPath,
@@ -9553,7 +9548,6 @@
9553
9548
  _d = _a.scoreThreshold,
9554
9549
  scoreThreshold = _d === void 0 ? defaultDocumentDetectionScoreThreshold : _d,
9555
9550
  onModelError = _a.onModelError;
9556
- var detector = React.useRef(null);
9557
9551
  var _e = React.useState(false),
9558
9552
  ready = _e[0],
9559
9553
  setReady = _e[1];
@@ -9579,7 +9573,6 @@
9579
9573
  return __generator(this, function (_a) {
9580
9574
  switch (_a.label) {
9581
9575
  case 0:
9582
- detector.current = model;
9583
9576
  setModelDownloadProgress(100);
9584
9577
  clearTimeout(modelLoadTimeout);
9585
9578
  return [4 /*yield*/, waitForVideoReady(videoRef)];
@@ -9600,8 +9593,7 @@
9600
9593
  });
9601
9594
  return function () {
9602
9595
  log('unloading document detection model');
9603
- detector.current = null;
9604
- closeDocumentDetector(modelPath, scoreThreshold);
9596
+ closeDocumentDetector();
9605
9597
  clearTimeout(modelLoadTimeout);
9606
9598
  document.removeEventListener('idmission.preloadProgress.documentDetection', handleDownloadProgress);
9607
9599
  };
@@ -9610,17 +9602,17 @@
9610
9602
  modelError && (onModelError === null || onModelError === void 0 ? void 0 : onModelError(modelError));
9611
9603
  }, [modelError, onModelError]);
9612
9604
  return {
9613
- detector: detector,
9614
9605
  ready: ready,
9615
9606
  modelDownloadProgress: modelDownloadProgress,
9616
9607
  modelError: modelError,
9617
9608
  setModelError: setModelError
9618
9609
  };
9619
9610
  }
9620
- function makeDocumentDetectorPrediction(detector, frame) {
9611
+ function makeDocumentDetectorPrediction(frame) {
9621
9612
  return __awaiter(this, void 0, void 0, function () {
9622
9613
  var startedAt, prediction, time, frameWidth, frameHeight;
9623
9614
  return __generator(this, function (_a) {
9615
+ if (!detector) return [2 /*return*/, null];
9624
9616
  startedAt = new Date();
9625
9617
  // Detectors can throw errors, for example when using custom URLs that
9626
9618
  // contain a model that doesn't provide the expected output.
@@ -9944,7 +9936,6 @@
9944
9936
  scoreThreshold: documentDetectionModelScoreThreshold,
9945
9937
  onModelError: onDocumentDetectionModelError
9946
9938
  }),
9947
- detector = _o.detector,
9948
9939
  ready = _o.ready,
9949
9940
  modelDownloadProgress = _o.modelDownloadProgress,
9950
9941
  modelError = _o.modelError,
@@ -9956,7 +9947,7 @@
9956
9947
  return __generator(this, function (_b) {
9957
9948
  switch (_b.label) {
9958
9949
  case 0:
9959
- if (!videoLoaded || !cameraReady || !ready || !videoRef.current || !detector.current || !lastPredictionCanvas.current) return [2 /*return*/];
9950
+ if (!videoLoaded || !cameraReady || !ready || !videoRef.current || !lastPredictionCanvas.current) return [2 /*return*/];
9960
9951
  stopDetectionAtStart = stopDetection.current;
9961
9952
  vw = videoRef.current.videoWidth;
9962
9953
  vh = videoRef.current.videoHeight;
@@ -9966,7 +9957,7 @@
9966
9957
  if (!(ctx && videoRef.current.readyState === 4)) return [3 /*break*/, 3];
9967
9958
  if (stopDetectionAtStart !== stopDetection.current) return [2 /*return*/];
9968
9959
  ctx.drawImage(videoRef.current, 0, 0, vw, vh);
9969
- return [4 /*yield*/, makeDocumentDetectorPrediction(detector.current, lastPredictionCanvas.current)];
9960
+ return [4 /*yield*/, makeDocumentDetectorPrediction(lastPredictionCanvas.current)];
9970
9961
  case 1:
9971
9962
  prediction = _b.sent();
9972
9963
  if (!prediction) return [3 /*break*/, 3];
@@ -9988,7 +9979,7 @@
9988
9979
  }
9989
9980
  });
9990
9981
  });
9991
- }, [cameraReady, delayAfterStartMs, detector, documentDetectionBoundaries, documentDetectionThresholds, ready, videoLoaded, videoRef]), {
9982
+ }, [cameraReady, delayAfterStartMs, documentDetectionBoundaries, documentDetectionThresholds, ready, videoLoaded, videoRef]), {
9992
9983
  throttleMs: throttleMs,
9993
9984
  autoStart: autoStart
9994
9985
  }),
@@ -10065,16 +10056,16 @@
10065
10056
  modelLoadTimeoutMs: focusModelLoadTimeoutMs,
10066
10057
  onModelError: onFocusModelError
10067
10058
  }),
10068
- model = _f.model,
10069
10059
  ready = _f.ready,
10070
10060
  modelDownloadProgress = _f.modelDownloadProgress,
10071
10061
  modelError = _f.modelError;
10072
10062
  var makeFocusPrediction = React.useCallback(function (imageData, box) {
10073
- if (!model.current) return null;
10074
- var prediction = makeFocusModelPrediction(model.current, imageData, cropCanvas.current, rotateCanvas.current, box);
10063
+ if (!ready) return null;
10064
+ var prediction = makeFocusModelPrediction(imageData, cropCanvas.current, rotateCanvas.current, box);
10065
+ if (!prediction) return null;
10075
10066
  setLastFocusPredictionAt(prediction.predictionTime);
10076
10067
  return prediction;
10077
- }, [model]);
10068
+ }, [ready]);
10078
10069
  var value = React.useMemo(function () {
10079
10070
  return {
10080
10071
  focusModelReady: ready,
@@ -18170,18 +18161,17 @@
18170
18161
  onModelError: onModelError,
18171
18162
  modelLoadTimeoutMs: modelLoadTimeoutMs
18172
18163
  }),
18173
- detector = _f.detector,
18174
18164
  ready = _f.ready,
18175
18165
  modelDownloadProgress = _f.modelDownloadProgress,
18176
18166
  modelError = _f.modelError;
18177
18167
  var _g = useFrameLoop(React.useCallback(function () {
18178
18168
  return __awaiter(_this, void 0, void 0, function () {
18179
- var vw, vh, ctx, faces, processed, e_1;
18180
- var _a;
18181
- return __generator(this, function (_b) {
18182
- switch (_b.label) {
18169
+ var vw, vh, ctx, prediction, processed, e_1;
18170
+ var _a, _b;
18171
+ return __generator(this, function (_c) {
18172
+ switch (_c.label) {
18183
18173
  case 0:
18184
- if (!videoLoaded || !cameraReady || !ready || modelError || !videoRef.current || !detector.current || !canvasRef.current) return [2 /*return*/];
18174
+ if (!videoLoaded || !cameraReady || !ready || modelError || !videoRef.current || !canvasRef.current) return [2 /*return*/];
18185
18175
  vw = videoRef.current.videoWidth;
18186
18176
  vh = videoRef.current.videoHeight;
18187
18177
  ctx = canvasRef.current.getContext('2d');
@@ -18191,23 +18181,23 @@
18191
18181
  ctx.translate(vw, 0);
18192
18182
  ctx.scale(-1, 1);
18193
18183
  ctx.drawImage(videoRef.current, 0, 0, vw, vh);
18194
- _b.label = 1;
18184
+ _c.label = 1;
18195
18185
  case 1:
18196
- _b.trys.push([1, 3,, 4]);
18197
- faces = makeFaceDetectorPrediction(detector.current, canvasRef.current).faces;
18186
+ _c.trys.push([1, 3,, 4]);
18187
+ prediction = makeFaceDetectorPrediction(canvasRef.current);
18198
18188
  processed = processFaceDetectorPrediction({
18199
- faces: faces,
18189
+ faces: (_a = prediction === null || prediction === void 0 ? void 0 : prediction.faces) !== null && _a !== void 0 ? _a : [],
18200
18190
  videoWidth: vw,
18201
18191
  videoHeight: vh,
18202
18192
  requireVerticalFaceCentering: requireVerticalFaceCentering
18203
18193
  });
18204
18194
  setLastFaceDetectionAt(new Date().getTime());
18205
- return [4 /*yield*/, (_a = onPredictionHandler.current) === null || _a === void 0 ? void 0 : _a.call(onPredictionHandler, processed)];
18195
+ return [4 /*yield*/, (_b = onPredictionHandler.current) === null || _b === void 0 ? void 0 : _b.call(onPredictionHandler, processed)];
18206
18196
  case 2:
18207
- _b.sent();
18197
+ _c.sent();
18208
18198
  return [3 /*break*/, 4];
18209
18199
  case 3:
18210
- e_1 = _b.sent();
18200
+ e_1 = _c.sent();
18211
18201
  error('caught face detection error', e_1);
18212
18202
  return [3 /*break*/, 4];
18213
18203
  case 4:
@@ -18215,7 +18205,7 @@
18215
18205
  }
18216
18206
  });
18217
18207
  });
18218
- }, [cameraReady, detector, modelError, ready, requireVerticalFaceCentering, videoLoaded, videoRef]), {
18208
+ }, [cameraReady, modelError, ready, requireVerticalFaceCentering, videoLoaded, videoRef]), {
18219
18209
  throttleMs: throttleMs,
18220
18210
  autoStart: autoStart
18221
18211
  }),