idmission-web-sdk 2.0.1 → 2.0.3

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.
@@ -140,7 +140,7 @@
140
140
  return cooked;
141
141
  }
142
142
 
143
- var webSdkVersion = '2.0.1';
143
+ var webSdkVersion = '2.0.3';
144
144
 
145
145
  function getPlatform() {
146
146
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -3034,6 +3034,34 @@
3034
3034
  });
3035
3035
  }
3036
3036
 
3037
+ function convertBoundingBox(box) {
3038
+ var _a, _b, _c, _d, _e, _f, _g, _h;
3039
+ return {
3040
+ xMin: (_a = box === null || box === void 0 ? void 0 : box.originX) !== null && _a !== void 0 ? _a : 0,
3041
+ xMax: ((_b = box === null || box === void 0 ? void 0 : box.originX) !== null && _b !== void 0 ? _b : 0) + ((_c = box === null || box === void 0 ? void 0 : box.width) !== null && _c !== void 0 ? _c : 0),
3042
+ yMin: (_d = box === null || box === void 0 ? void 0 : box.originY) !== null && _d !== void 0 ? _d : 0,
3043
+ yMax: ((_e = box === null || box === void 0 ? void 0 : box.originY) !== null && _e !== void 0 ? _e : 0) + ((_f = box === null || box === void 0 ? void 0 : box.height) !== null && _f !== void 0 ? _f : 0),
3044
+ width: (_g = box === null || box === void 0 ? void 0 : box.width) !== null && _g !== void 0 ? _g : 0,
3045
+ height: (_h = box === null || box === void 0 ? void 0 : box.height) !== null && _h !== void 0 ? _h : 0
3046
+ };
3047
+ }
3048
+ function waitForVideoReady(videoRef, checkEveryMs) {
3049
+ if (checkEveryMs === void 0) {
3050
+ checkEveryMs = 100;
3051
+ }
3052
+ return new Promise(function (resolve) {
3053
+ var _a;
3054
+ if (((_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.readyState) === 4) return resolve();
3055
+ var interval = setInterval(function () {
3056
+ var _a;
3057
+ if (((_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.readyState) === 4) {
3058
+ clearInterval(interval);
3059
+ resolve();
3060
+ }
3061
+ }, checkEveryMs);
3062
+ });
3063
+ }
3064
+
3037
3065
  var defaultFocusModelPath = "https://websdk-cdn-dev.idmission.com/assets/models/focusmp20240523/model_float16.tflite";
3038
3066
  var defaultFocusModelLoadTimeoutMs = 45000;
3039
3067
  var defaultFocusThresholds = {
@@ -3049,7 +3077,7 @@
3049
3077
  var models = {};
3050
3078
  function loadFocusModel(modelAssetPath) {
3051
3079
  return __awaiter(this, void 0, void 0, function () {
3052
- var id, _a, _b, _c, _d, emptyFrame;
3080
+ var id, _a, _b, _c, _d;
3053
3081
  return __generator(this, function (_e) {
3054
3082
  switch (_e.label) {
3055
3083
  case 0:
@@ -3075,9 +3103,6 @@
3075
3103
  }])];
3076
3104
  case 3:
3077
3105
  _a[_b] = _e.sent();
3078
- emptyFrame = document.createElement('canvas');
3079
- models[id].classifyForVideo(emptyFrame, performance.now());
3080
- emptyFrame.remove();
3081
3106
  return [2 /*return*/, models[id]];
3082
3107
  }
3083
3108
  });
@@ -3099,7 +3124,9 @@
3099
3124
  var _f = React.useState(null),
3100
3125
  modelError = _f[0],
3101
3126
  setModelError = _f[1];
3127
+ var videoRef = React.useContext(CameraStateContext).videoRef;
3102
3128
  React.useEffect(function loadModel() {
3129
+ var _this = this;
3103
3130
  setReady(false);
3104
3131
  function handleDownloadProgress(event) {
3105
3132
  setModelDownloadProgress(progressToPercentage(event.detail));
@@ -3109,9 +3136,22 @@
3109
3136
  setModelError(new Error('Model loading time limit exceeded.'));
3110
3137
  }, modelLoadTimeoutMs);
3111
3138
  loadFocusModel(modelPath).then(function (loadedModel) {
3112
- model.current = loadedModel;
3113
- setModelDownloadProgress(100);
3114
- setReady(true);
3139
+ return __awaiter(_this, void 0, void 0, function () {
3140
+ return __generator(this, function (_a) {
3141
+ switch (_a.label) {
3142
+ case 0:
3143
+ model.current = loadedModel;
3144
+ setModelDownloadProgress(100);
3145
+ clearTimeout(modelLoadTimeout);
3146
+ return [4 /*yield*/, waitForVideoReady(videoRef)];
3147
+ case 1:
3148
+ _a.sent();
3149
+ loadedModel.classifyForVideo(videoRef.current, performance.now());
3150
+ setReady(true);
3151
+ return [2 /*return*/];
3152
+ }
3153
+ });
3154
+ });
3115
3155
  })["catch"](function (e) {
3116
3156
  setModelError(e);
3117
3157
  })["finally"](function () {
@@ -3121,7 +3161,7 @@
3121
3161
  clearTimeout(modelLoadTimeout);
3122
3162
  document.removeEventListener('idmission.preloadProgress.focus', handleDownloadProgress);
3123
3163
  };
3124
- }, [modelPath, modelLoadTimeoutMs]);
3164
+ }, [modelPath, modelLoadTimeoutMs, videoRef]);
3125
3165
  React.useEffect(function handleModelError() {
3126
3166
  modelError && (onModelError === null || onModelError === void 0 ? void 0 : onModelError(modelError));
3127
3167
  }, [modelError, onModelError]);
@@ -3299,24 +3339,12 @@
3299
3339
  [256,341],[341,452],[452,256],[414,413],[413,463],[463,414],[286,441],[441,414],[414,286],[286,258],[258,441],[441,286],[258,257],[257,442],[442,258],[257,259],[259,443],[443,257],[259,260],[260,444],[444,259],[260,467],[467,445],[445,260],[309,459],[459,250],[250,309],[305,289],[289,290],[290,305],[305,290],[290,460],[460,305],[401,376],[376,435],[435,401],[309,250],[250,392],[392,309],[376,411],[411,433],[433,376],[453,341],[341,464],[464,453],[357,453],[453,465],[465,357],[343,357],[357,412],[412,
3300
3340
  343],[437,343],[343,399],[399,437],[344,360],[360,440],[440,344],[420,437],[437,456],[456,420],[360,420],[420,363],[363,360],[361,401],[401,288],[288,361],[265,372],[372,353],[353,265],[390,339],[339,249],[249,390],[339,448],[448,255],[255,339]]);K("VERSION","0.4.1646425229");}).call(commonjsGlobal);
3301
3341
 
3302
- function convertBoundingBox(box) {
3303
- var _a, _b, _c, _d, _e, _f, _g, _h;
3304
- return {
3305
- xMin: (_a = box === null || box === void 0 ? void 0 : box.originX) !== null && _a !== void 0 ? _a : 0,
3306
- xMax: ((_b = box === null || box === void 0 ? void 0 : box.originX) !== null && _b !== void 0 ? _b : 0) + ((_c = box === null || box === void 0 ? void 0 : box.width) !== null && _c !== void 0 ? _c : 0),
3307
- yMin: (_d = box === null || box === void 0 ? void 0 : box.originY) !== null && _d !== void 0 ? _d : 0,
3308
- yMax: ((_e = box === null || box === void 0 ? void 0 : box.originY) !== null && _e !== void 0 ? _e : 0) + ((_f = box === null || box === void 0 ? void 0 : box.height) !== null && _f !== void 0 ? _f : 0),
3309
- width: (_g = box === null || box === void 0 ? void 0 : box.width) !== null && _g !== void 0 ? _g : 0,
3310
- height: (_h = box === null || box === void 0 ? void 0 : box.height) !== null && _h !== void 0 ? _h : 0
3311
- };
3312
- }
3313
-
3314
3342
  var defaultFaceDetectorModelPath = 'https://websdk-cdn-dev.idmission.com/assets/models/blazeface20240207/blaze_face_short_range.tflite';
3315
3343
  var defaultSelfieCaptureModelLoadTimeoutMs = 45000;
3316
3344
  var detector;
3317
3345
  function loadFaceDetector() {
3318
3346
  return __awaiter(this, void 0, void 0, function () {
3319
- var _a, _b, emptyFrame;
3347
+ var _a, _b;
3320
3348
  return __generator(this, function (_c) {
3321
3349
  switch (_c.label) {
3322
3350
  case 0:
@@ -3339,9 +3367,6 @@
3339
3367
  }])];
3340
3368
  case 3:
3341
3369
  detector = _c.sent();
3342
- emptyFrame = document.createElement('canvas');
3343
- detector.detectForVideo(emptyFrame, performance.now());
3344
- emptyFrame.remove();
3345
3370
  return [2 /*return*/, detector];
3346
3371
  }
3347
3372
  });
@@ -3361,7 +3386,9 @@
3361
3386
  var _e = React.useState(null),
3362
3387
  modelError = _e[0],
3363
3388
  setModelError = _e[1];
3389
+ var videoRef = React.useContext(CameraStateContext).videoRef;
3364
3390
  React.useEffect(function loadModel() {
3391
+ var _this = this;
3365
3392
  setReady(false);
3366
3393
  var modelLoadTimeout = setTimeout(function () {
3367
3394
  setModelError(new Error('Model loading time limit exceeded.'));
@@ -3371,9 +3398,22 @@
3371
3398
  }
3372
3399
  document.addEventListener('idmission.preloadProgress.faceDetection', handleDownloadProgress);
3373
3400
  loadFaceDetector().then(function (model) {
3374
- detector.current = model;
3375
- setModelDownloadProgress(100);
3376
- setReady(true);
3401
+ return __awaiter(_this, void 0, void 0, function () {
3402
+ return __generator(this, function (_a) {
3403
+ switch (_a.label) {
3404
+ case 0:
3405
+ detector.current = model;
3406
+ setModelDownloadProgress(100);
3407
+ clearTimeout(modelLoadTimeout);
3408
+ return [4 /*yield*/, waitForVideoReady(videoRef)];
3409
+ case 1:
3410
+ _a.sent();
3411
+ model.detectForVideo(videoRef.current, performance.now());
3412
+ setReady(true);
3413
+ return [2 /*return*/];
3414
+ }
3415
+ });
3416
+ });
3377
3417
  })["catch"](function (e) {
3378
3418
  setModelError(e);
3379
3419
  })["finally"](function () {
@@ -3383,7 +3423,7 @@
3383
3423
  clearTimeout(modelLoadTimeout);
3384
3424
  document.removeEventListener('idmission.preloadProgress.faceDetection', handleDownloadProgress);
3385
3425
  };
3386
- }, [modelLoadTimeoutMs]);
3426
+ }, [modelLoadTimeoutMs, videoRef]);
3387
3427
  React.useEffect(function handleModelError() {
3388
3428
  modelError && (onModelError === null || onModelError === void 0 ? void 0 : onModelError(modelError));
3389
3429
  }, [modelError, onModelError]);
@@ -3664,7 +3704,7 @@
3664
3704
  scoreThreshold = defaultDocumentDetectionScoreThreshold;
3665
3705
  }
3666
3706
  return __awaiter(this, void 0, void 0, function () {
3667
- var id, _a, _b, _c, _d, emptyFrame;
3707
+ var id, _a, _b, _c, _d;
3668
3708
  return __generator(this, function (_e) {
3669
3709
  switch (_e.label) {
3670
3710
  case 0:
@@ -3691,9 +3731,6 @@
3691
3731
  }])];
3692
3732
  case 3:
3693
3733
  _a[_b] = _e.sent();
3694
- emptyFrame = document.createElement('canvas');
3695
- detectors[id].detectForVideo(emptyFrame, performance.now());
3696
- emptyFrame.remove();
3697
3734
  return [2 /*return*/, detectors[id]];
3698
3735
  }
3699
3736
  });
@@ -3717,7 +3754,9 @@
3717
3754
  var _g = React.useState(null),
3718
3755
  modelError = _g[0],
3719
3756
  setModelError = _g[1];
3757
+ var videoRef = React.useContext(CameraStateContext).videoRef;
3720
3758
  React.useEffect(function loadModel() {
3759
+ var _this = this;
3721
3760
  setReady(false);
3722
3761
  function handleDownloadProgress(event) {
3723
3762
  setModelDownloadProgress(progressToPercentage(event.detail));
@@ -3727,9 +3766,22 @@
3727
3766
  setModelError(new Error('Model loading time limit exceeded.'));
3728
3767
  }, modelLoadTimeoutMs);
3729
3768
  loadDocumentDetector(modelPath, scoreThreshold).then(function (model) {
3730
- detector.current = model;
3731
- setModelDownloadProgress(100);
3732
- setReady(true);
3769
+ return __awaiter(_this, void 0, void 0, function () {
3770
+ return __generator(this, function (_a) {
3771
+ switch (_a.label) {
3772
+ case 0:
3773
+ detector.current = model;
3774
+ setModelDownloadProgress(100);
3775
+ clearTimeout(modelLoadTimeout);
3776
+ return [4 /*yield*/, waitForVideoReady(videoRef)];
3777
+ case 1:
3778
+ _a.sent();
3779
+ model.detectForVideo(videoRef.current, performance.now());
3780
+ setReady(true);
3781
+ return [2 /*return*/];
3782
+ }
3783
+ });
3784
+ });
3733
3785
  })["catch"](function (e) {
3734
3786
  setModelError(e);
3735
3787
  })["finally"](function () {
@@ -3739,7 +3791,7 @@
3739
3791
  clearTimeout(modelLoadTimeout);
3740
3792
  document.removeEventListener('idmission.preloadProgress.documentDetection', handleDownloadProgress);
3741
3793
  };
3742
- }, [modelLoadTimeoutMs, modelPath, scoreThreshold]);
3794
+ }, [modelLoadTimeoutMs, modelPath, scoreThreshold, videoRef]);
3743
3795
  React.useEffect(function handleModelError() {
3744
3796
  modelError && (onModelError === null || onModelError === void 0 ? void 0 : onModelError(modelError));
3745
3797
  }, [modelError, onModelError]);