idmission-web-sdk 2.0.2 → 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.
@@ -1,4 +1,5 @@
1
1
  import { BoundingBox } from '@mediapipe/tasks-vision';
2
+ import { MutableRefObject } from 'react';
2
3
  export declare function convertBoundingBox(box?: BoundingBox): {
3
4
  xMin: number;
4
5
  xMax: number;
@@ -7,3 +8,4 @@ export declare function convertBoundingBox(box?: BoundingBox): {
7
8
  width: number;
8
9
  height: number;
9
10
  };
11
+ export declare function waitForVideoReady(videoRef: MutableRefObject<HTMLVideoElement | null>, checkEveryMs?: number): Promise<void>;
@@ -49,7 +49,7 @@ var LanguageDetector__default = /*#__PURE__*/_interopDefaultLegacy(LanguageDetec
49
49
  var i18n__default = /*#__PURE__*/_interopDefaultLegacy(i18n);
50
50
  var SignatureCanvas__default = /*#__PURE__*/_interopDefaultLegacy(SignatureCanvas);
51
51
 
52
- var webSdkVersion = '2.0.2';
52
+ var webSdkVersion = '2.0.3';
53
53
 
54
54
  function getPlatform() {
55
55
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -2481,6 +2481,34 @@ function giveUpAfter(maxTime) {
2481
2481
  });
2482
2482
  }
2483
2483
 
2484
+ function convertBoundingBox(box) {
2485
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2486
+ return {
2487
+ xMin: (_a = box === null || box === void 0 ? void 0 : box.originX) !== null && _a !== void 0 ? _a : 0,
2488
+ 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),
2489
+ yMin: (_d = box === null || box === void 0 ? void 0 : box.originY) !== null && _d !== void 0 ? _d : 0,
2490
+ 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),
2491
+ width: (_g = box === null || box === void 0 ? void 0 : box.width) !== null && _g !== void 0 ? _g : 0,
2492
+ height: (_h = box === null || box === void 0 ? void 0 : box.height) !== null && _h !== void 0 ? _h : 0
2493
+ };
2494
+ }
2495
+ function waitForVideoReady(videoRef, checkEveryMs) {
2496
+ if (checkEveryMs === void 0) {
2497
+ checkEveryMs = 100;
2498
+ }
2499
+ return new Promise(function (resolve) {
2500
+ var _a;
2501
+ if (((_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.readyState) === 4) return resolve();
2502
+ var interval = setInterval(function () {
2503
+ var _a;
2504
+ if (((_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.readyState) === 4) {
2505
+ clearInterval(interval);
2506
+ resolve();
2507
+ }
2508
+ }, checkEveryMs);
2509
+ });
2510
+ }
2511
+
2484
2512
  var defaultFocusModelPath = "https://websdk-cdn-dev.idmission.com/assets/models/focusmp20240523/model_float16.tflite";
2485
2513
  var defaultFocusModelLoadTimeoutMs = 45000;
2486
2514
  var defaultFocusThresholds = {
@@ -2519,16 +2547,9 @@ function loadFocusModel(modelAssetPath) {
2519
2547
  delegate: modelCapabilities.delegate
2520
2548
  },
2521
2549
  runningMode: 'VIDEO'
2522
- }])
2523
- // const emptyFrame = document.createElement('canvas')
2524
- // models[id].classifyForVideo(emptyFrame, performance.now())
2525
- // emptyFrame.remove()
2526
- ];
2550
+ }])];
2527
2551
  case 3:
2528
2552
  _a[_b] = _e.sent();
2529
- // const emptyFrame = document.createElement('canvas')
2530
- // models[id].classifyForVideo(emptyFrame, performance.now())
2531
- // emptyFrame.remove()
2532
2553
  return [2 /*return*/, models[id]];
2533
2554
  }
2534
2555
  });
@@ -2550,7 +2571,9 @@ function useLoadFocusModel(_a) {
2550
2571
  var _f = React.useState(null),
2551
2572
  modelError = _f[0],
2552
2573
  setModelError = _f[1];
2574
+ var videoRef = React.useContext(CameraStateContext).videoRef;
2553
2575
  React.useEffect(function loadModel() {
2576
+ var _this = this;
2554
2577
  setReady(false);
2555
2578
  function handleDownloadProgress(event) {
2556
2579
  setModelDownloadProgress(progressToPercentage(event.detail));
@@ -2560,9 +2583,22 @@ function useLoadFocusModel(_a) {
2560
2583
  setModelError(new Error('Model loading time limit exceeded.'));
2561
2584
  }, modelLoadTimeoutMs);
2562
2585
  loadFocusModel(modelPath).then(function (loadedModel) {
2563
- model.current = loadedModel;
2564
- setModelDownloadProgress(100);
2565
- setReady(true);
2586
+ return tslib.__awaiter(_this, void 0, void 0, function () {
2587
+ return tslib.__generator(this, function (_a) {
2588
+ switch (_a.label) {
2589
+ case 0:
2590
+ model.current = loadedModel;
2591
+ setModelDownloadProgress(100);
2592
+ clearTimeout(modelLoadTimeout);
2593
+ return [4 /*yield*/, waitForVideoReady(videoRef)];
2594
+ case 1:
2595
+ _a.sent();
2596
+ loadedModel.classifyForVideo(videoRef.current, performance.now());
2597
+ setReady(true);
2598
+ return [2 /*return*/];
2599
+ }
2600
+ });
2601
+ });
2566
2602
  })["catch"](function (e) {
2567
2603
  setModelError(e);
2568
2604
  })["finally"](function () {
@@ -2572,7 +2608,7 @@ function useLoadFocusModel(_a) {
2572
2608
  clearTimeout(modelLoadTimeout);
2573
2609
  document.removeEventListener('idmission.preloadProgress.focus', handleDownloadProgress);
2574
2610
  };
2575
- }, [modelPath, modelLoadTimeoutMs]);
2611
+ }, [modelPath, modelLoadTimeoutMs, videoRef]);
2576
2612
  React.useEffect(function handleModelError() {
2577
2613
  modelError && (onModelError === null || onModelError === void 0 ? void 0 : onModelError(modelError));
2578
2614
  }, [modelError, onModelError]);
@@ -2752,18 +2788,6 @@ K("FACEDETECTION_TESSELATION",[[127,34],[34,139],[139,127],[11,0],[0,37],[37,11]
2752
2788
  [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,
2753
2789
  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);
2754
2790
 
2755
- function convertBoundingBox(box) {
2756
- var _a, _b, _c, _d, _e, _f, _g, _h;
2757
- return {
2758
- xMin: (_a = box === null || box === void 0 ? void 0 : box.originX) !== null && _a !== void 0 ? _a : 0,
2759
- 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),
2760
- yMin: (_d = box === null || box === void 0 ? void 0 : box.originY) !== null && _d !== void 0 ? _d : 0,
2761
- 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),
2762
- width: (_g = box === null || box === void 0 ? void 0 : box.width) !== null && _g !== void 0 ? _g : 0,
2763
- height: (_h = box === null || box === void 0 ? void 0 : box.height) !== null && _h !== void 0 ? _h : 0
2764
- };
2765
- }
2766
-
2767
2791
  var defaultFaceDetectorModelPath = 'https://websdk-cdn-dev.idmission.com/assets/models/blazeface20240207/blaze_face_short_range.tflite';
2768
2792
  var defaultSelfieCaptureModelLoadTimeoutMs = 45000;
2769
2793
  var detector;
@@ -2789,16 +2813,9 @@ function loadFaceDetector() {
2789
2813
  delegate: modelCapabilities.delegate
2790
2814
  },
2791
2815
  runningMode: 'VIDEO'
2792
- }])
2793
- // const emptyFrame = document.createElement('canvas')
2794
- // detector.detectForVideo(emptyFrame, performance.now())
2795
- // emptyFrame.remove()
2796
- ];
2816
+ }])];
2797
2817
  case 3:
2798
2818
  detector = _c.sent();
2799
- // const emptyFrame = document.createElement('canvas')
2800
- // detector.detectForVideo(emptyFrame, performance.now())
2801
- // emptyFrame.remove()
2802
2819
  return [2 /*return*/, detector];
2803
2820
  }
2804
2821
  });
@@ -2818,7 +2835,9 @@ function useLoadFaceDetector(_a) {
2818
2835
  var _e = React.useState(null),
2819
2836
  modelError = _e[0],
2820
2837
  setModelError = _e[1];
2838
+ var videoRef = React.useContext(CameraStateContext).videoRef;
2821
2839
  React.useEffect(function loadModel() {
2840
+ var _this = this;
2822
2841
  setReady(false);
2823
2842
  var modelLoadTimeout = setTimeout(function () {
2824
2843
  setModelError(new Error('Model loading time limit exceeded.'));
@@ -2828,9 +2847,22 @@ function useLoadFaceDetector(_a) {
2828
2847
  }
2829
2848
  document.addEventListener('idmission.preloadProgress.faceDetection', handleDownloadProgress);
2830
2849
  loadFaceDetector().then(function (model) {
2831
- detector.current = model;
2832
- setModelDownloadProgress(100);
2833
- setReady(true);
2850
+ return tslib.__awaiter(_this, void 0, void 0, function () {
2851
+ return tslib.__generator(this, function (_a) {
2852
+ switch (_a.label) {
2853
+ case 0:
2854
+ detector.current = model;
2855
+ setModelDownloadProgress(100);
2856
+ clearTimeout(modelLoadTimeout);
2857
+ return [4 /*yield*/, waitForVideoReady(videoRef)];
2858
+ case 1:
2859
+ _a.sent();
2860
+ model.detectForVideo(videoRef.current, performance.now());
2861
+ setReady(true);
2862
+ return [2 /*return*/];
2863
+ }
2864
+ });
2865
+ });
2834
2866
  })["catch"](function (e) {
2835
2867
  setModelError(e);
2836
2868
  })["finally"](function () {
@@ -2840,7 +2872,7 @@ function useLoadFaceDetector(_a) {
2840
2872
  clearTimeout(modelLoadTimeout);
2841
2873
  document.removeEventListener('idmission.preloadProgress.faceDetection', handleDownloadProgress);
2842
2874
  };
2843
- }, [modelLoadTimeoutMs]);
2875
+ }, [modelLoadTimeoutMs, videoRef]);
2844
2876
  React.useEffect(function handleModelError() {
2845
2877
  modelError && (onModelError === null || onModelError === void 0 ? void 0 : onModelError(modelError));
2846
2878
  }, [modelError, onModelError]);
@@ -3145,16 +3177,9 @@ function loadDocumentDetector(modelAssetPath, scoreThreshold) {
3145
3177
  },
3146
3178
  scoreThreshold: scoreThreshold,
3147
3179
  runningMode: 'VIDEO'
3148
- }])
3149
- // const emptyFrame = document.createElement('canvas')
3150
- // detectors[id].detectForVideo(emptyFrame, performance.now())
3151
- // emptyFrame.remove()
3152
- ];
3180
+ }])];
3153
3181
  case 3:
3154
3182
  _a[_b] = _e.sent();
3155
- // const emptyFrame = document.createElement('canvas')
3156
- // detectors[id].detectForVideo(emptyFrame, performance.now())
3157
- // emptyFrame.remove()
3158
3183
  return [2 /*return*/, detectors[id]];
3159
3184
  }
3160
3185
  });
@@ -3178,7 +3203,9 @@ function useLoadDocumentDetector(_a) {
3178
3203
  var _g = React.useState(null),
3179
3204
  modelError = _g[0],
3180
3205
  setModelError = _g[1];
3206
+ var videoRef = React.useContext(CameraStateContext).videoRef;
3181
3207
  React.useEffect(function loadModel() {
3208
+ var _this = this;
3182
3209
  setReady(false);
3183
3210
  function handleDownloadProgress(event) {
3184
3211
  setModelDownloadProgress(progressToPercentage(event.detail));
@@ -3188,9 +3215,22 @@ function useLoadDocumentDetector(_a) {
3188
3215
  setModelError(new Error('Model loading time limit exceeded.'));
3189
3216
  }, modelLoadTimeoutMs);
3190
3217
  loadDocumentDetector(modelPath, scoreThreshold).then(function (model) {
3191
- detector.current = model;
3192
- setModelDownloadProgress(100);
3193
- setReady(true);
3218
+ return tslib.__awaiter(_this, void 0, void 0, function () {
3219
+ return tslib.__generator(this, function (_a) {
3220
+ switch (_a.label) {
3221
+ case 0:
3222
+ detector.current = model;
3223
+ setModelDownloadProgress(100);
3224
+ clearTimeout(modelLoadTimeout);
3225
+ return [4 /*yield*/, waitForVideoReady(videoRef)];
3226
+ case 1:
3227
+ _a.sent();
3228
+ model.detectForVideo(videoRef.current, performance.now());
3229
+ setReady(true);
3230
+ return [2 /*return*/];
3231
+ }
3232
+ });
3233
+ });
3194
3234
  })["catch"](function (e) {
3195
3235
  setModelError(e);
3196
3236
  })["finally"](function () {
@@ -3200,7 +3240,7 @@ function useLoadDocumentDetector(_a) {
3200
3240
  clearTimeout(modelLoadTimeout);
3201
3241
  document.removeEventListener('idmission.preloadProgress.documentDetection', handleDownloadProgress);
3202
3242
  };
3203
- }, [modelLoadTimeoutMs, modelPath, scoreThreshold]);
3243
+ }, [modelLoadTimeoutMs, modelPath, scoreThreshold, videoRef]);
3204
3244
  React.useEffect(function handleModelError() {
3205
3245
  modelError && (onModelError === null || onModelError === void 0 ? void 0 : onModelError(modelError));
3206
3246
  }, [modelError, onModelError]);