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.
package/dist/sdk2.esm.js CHANGED
@@ -14,7 +14,7 @@ import LanguageDetector from 'i18next-browser-languagedetector';
14
14
  import i18n from 'i18next';
15
15
  import SignatureCanvas from 'react-signature-canvas';
16
16
 
17
- var webSdkVersion = '2.0.2';
17
+ var webSdkVersion = '2.0.3';
18
18
 
19
19
  function getPlatform() {
20
20
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -2446,6 +2446,34 @@ function giveUpAfter(maxTime) {
2446
2446
  });
2447
2447
  }
2448
2448
 
2449
+ function convertBoundingBox(box) {
2450
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2451
+ return {
2452
+ xMin: (_a = box === null || box === void 0 ? void 0 : box.originX) !== null && _a !== void 0 ? _a : 0,
2453
+ 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),
2454
+ yMin: (_d = box === null || box === void 0 ? void 0 : box.originY) !== null && _d !== void 0 ? _d : 0,
2455
+ 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),
2456
+ width: (_g = box === null || box === void 0 ? void 0 : box.width) !== null && _g !== void 0 ? _g : 0,
2457
+ height: (_h = box === null || box === void 0 ? void 0 : box.height) !== null && _h !== void 0 ? _h : 0
2458
+ };
2459
+ }
2460
+ function waitForVideoReady(videoRef, checkEveryMs) {
2461
+ if (checkEveryMs === void 0) {
2462
+ checkEveryMs = 100;
2463
+ }
2464
+ return new Promise(function (resolve) {
2465
+ var _a;
2466
+ if (((_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.readyState) === 4) return resolve();
2467
+ var interval = setInterval(function () {
2468
+ var _a;
2469
+ if (((_a = videoRef.current) === null || _a === void 0 ? void 0 : _a.readyState) === 4) {
2470
+ clearInterval(interval);
2471
+ resolve();
2472
+ }
2473
+ }, checkEveryMs);
2474
+ });
2475
+ }
2476
+
2449
2477
  var defaultFocusModelPath = "https://websdk-cdn-dev.idmission.com/assets/models/focusmp20240523/model_float16.tflite";
2450
2478
  var defaultFocusModelLoadTimeoutMs = 45000;
2451
2479
  var defaultFocusThresholds = {
@@ -2484,16 +2512,9 @@ function loadFocusModel(modelAssetPath) {
2484
2512
  delegate: modelCapabilities.delegate
2485
2513
  },
2486
2514
  runningMode: 'VIDEO'
2487
- }])
2488
- // const emptyFrame = document.createElement('canvas')
2489
- // models[id].classifyForVideo(emptyFrame, performance.now())
2490
- // emptyFrame.remove()
2491
- ];
2515
+ }])];
2492
2516
  case 3:
2493
2517
  _a[_b] = _e.sent();
2494
- // const emptyFrame = document.createElement('canvas')
2495
- // models[id].classifyForVideo(emptyFrame, performance.now())
2496
- // emptyFrame.remove()
2497
2518
  return [2 /*return*/, models[id]];
2498
2519
  }
2499
2520
  });
@@ -2515,7 +2536,9 @@ function useLoadFocusModel(_a) {
2515
2536
  var _f = useState(null),
2516
2537
  modelError = _f[0],
2517
2538
  setModelError = _f[1];
2539
+ var videoRef = useContext(CameraStateContext).videoRef;
2518
2540
  useEffect(function loadModel() {
2541
+ var _this = this;
2519
2542
  setReady(false);
2520
2543
  function handleDownloadProgress(event) {
2521
2544
  setModelDownloadProgress(progressToPercentage(event.detail));
@@ -2525,9 +2548,22 @@ function useLoadFocusModel(_a) {
2525
2548
  setModelError(new Error('Model loading time limit exceeded.'));
2526
2549
  }, modelLoadTimeoutMs);
2527
2550
  loadFocusModel(modelPath).then(function (loadedModel) {
2528
- model.current = loadedModel;
2529
- setModelDownloadProgress(100);
2530
- setReady(true);
2551
+ return __awaiter(_this, void 0, void 0, function () {
2552
+ return __generator(this, function (_a) {
2553
+ switch (_a.label) {
2554
+ case 0:
2555
+ model.current = loadedModel;
2556
+ setModelDownloadProgress(100);
2557
+ clearTimeout(modelLoadTimeout);
2558
+ return [4 /*yield*/, waitForVideoReady(videoRef)];
2559
+ case 1:
2560
+ _a.sent();
2561
+ loadedModel.classifyForVideo(videoRef.current, performance.now());
2562
+ setReady(true);
2563
+ return [2 /*return*/];
2564
+ }
2565
+ });
2566
+ });
2531
2567
  })["catch"](function (e) {
2532
2568
  setModelError(e);
2533
2569
  })["finally"](function () {
@@ -2537,7 +2573,7 @@ function useLoadFocusModel(_a) {
2537
2573
  clearTimeout(modelLoadTimeout);
2538
2574
  document.removeEventListener('idmission.preloadProgress.focus', handleDownloadProgress);
2539
2575
  };
2540
- }, [modelPath, modelLoadTimeoutMs]);
2576
+ }, [modelPath, modelLoadTimeoutMs, videoRef]);
2541
2577
  useEffect(function handleModelError() {
2542
2578
  modelError && (onModelError === null || onModelError === void 0 ? void 0 : onModelError(modelError));
2543
2579
  }, [modelError, onModelError]);
@@ -2717,18 +2753,6 @@ K("FACEDETECTION_TESSELATION",[[127,34],[34,139],[139,127],[11,0],[0,37],[37,11]
2717
2753
  [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,
2718
2754
  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);
2719
2755
 
2720
- function convertBoundingBox(box) {
2721
- var _a, _b, _c, _d, _e, _f, _g, _h;
2722
- return {
2723
- xMin: (_a = box === null || box === void 0 ? void 0 : box.originX) !== null && _a !== void 0 ? _a : 0,
2724
- 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),
2725
- yMin: (_d = box === null || box === void 0 ? void 0 : box.originY) !== null && _d !== void 0 ? _d : 0,
2726
- 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),
2727
- width: (_g = box === null || box === void 0 ? void 0 : box.width) !== null && _g !== void 0 ? _g : 0,
2728
- height: (_h = box === null || box === void 0 ? void 0 : box.height) !== null && _h !== void 0 ? _h : 0
2729
- };
2730
- }
2731
-
2732
2756
  var defaultFaceDetectorModelPath = 'https://websdk-cdn-dev.idmission.com/assets/models/blazeface20240207/blaze_face_short_range.tflite';
2733
2757
  var defaultSelfieCaptureModelLoadTimeoutMs = 45000;
2734
2758
  var detector;
@@ -2754,16 +2778,9 @@ function loadFaceDetector() {
2754
2778
  delegate: modelCapabilities.delegate
2755
2779
  },
2756
2780
  runningMode: 'VIDEO'
2757
- }])
2758
- // const emptyFrame = document.createElement('canvas')
2759
- // detector.detectForVideo(emptyFrame, performance.now())
2760
- // emptyFrame.remove()
2761
- ];
2781
+ }])];
2762
2782
  case 3:
2763
2783
  detector = _c.sent();
2764
- // const emptyFrame = document.createElement('canvas')
2765
- // detector.detectForVideo(emptyFrame, performance.now())
2766
- // emptyFrame.remove()
2767
2784
  return [2 /*return*/, detector];
2768
2785
  }
2769
2786
  });
@@ -2783,7 +2800,9 @@ function useLoadFaceDetector(_a) {
2783
2800
  var _e = useState(null),
2784
2801
  modelError = _e[0],
2785
2802
  setModelError = _e[1];
2803
+ var videoRef = useContext(CameraStateContext).videoRef;
2786
2804
  useEffect(function loadModel() {
2805
+ var _this = this;
2787
2806
  setReady(false);
2788
2807
  var modelLoadTimeout = setTimeout(function () {
2789
2808
  setModelError(new Error('Model loading time limit exceeded.'));
@@ -2793,9 +2812,22 @@ function useLoadFaceDetector(_a) {
2793
2812
  }
2794
2813
  document.addEventListener('idmission.preloadProgress.faceDetection', handleDownloadProgress);
2795
2814
  loadFaceDetector().then(function (model) {
2796
- detector.current = model;
2797
- setModelDownloadProgress(100);
2798
- setReady(true);
2815
+ return __awaiter(_this, void 0, void 0, function () {
2816
+ return __generator(this, function (_a) {
2817
+ switch (_a.label) {
2818
+ case 0:
2819
+ detector.current = model;
2820
+ setModelDownloadProgress(100);
2821
+ clearTimeout(modelLoadTimeout);
2822
+ return [4 /*yield*/, waitForVideoReady(videoRef)];
2823
+ case 1:
2824
+ _a.sent();
2825
+ model.detectForVideo(videoRef.current, performance.now());
2826
+ setReady(true);
2827
+ return [2 /*return*/];
2828
+ }
2829
+ });
2830
+ });
2799
2831
  })["catch"](function (e) {
2800
2832
  setModelError(e);
2801
2833
  })["finally"](function () {
@@ -2805,7 +2837,7 @@ function useLoadFaceDetector(_a) {
2805
2837
  clearTimeout(modelLoadTimeout);
2806
2838
  document.removeEventListener('idmission.preloadProgress.faceDetection', handleDownloadProgress);
2807
2839
  };
2808
- }, [modelLoadTimeoutMs]);
2840
+ }, [modelLoadTimeoutMs, videoRef]);
2809
2841
  useEffect(function handleModelError() {
2810
2842
  modelError && (onModelError === null || onModelError === void 0 ? void 0 : onModelError(modelError));
2811
2843
  }, [modelError, onModelError]);
@@ -3110,16 +3142,9 @@ function loadDocumentDetector(modelAssetPath, scoreThreshold) {
3110
3142
  },
3111
3143
  scoreThreshold: scoreThreshold,
3112
3144
  runningMode: 'VIDEO'
3113
- }])
3114
- // const emptyFrame = document.createElement('canvas')
3115
- // detectors[id].detectForVideo(emptyFrame, performance.now())
3116
- // emptyFrame.remove()
3117
- ];
3145
+ }])];
3118
3146
  case 3:
3119
3147
  _a[_b] = _e.sent();
3120
- // const emptyFrame = document.createElement('canvas')
3121
- // detectors[id].detectForVideo(emptyFrame, performance.now())
3122
- // emptyFrame.remove()
3123
3148
  return [2 /*return*/, detectors[id]];
3124
3149
  }
3125
3150
  });
@@ -3143,7 +3168,9 @@ function useLoadDocumentDetector(_a) {
3143
3168
  var _g = useState(null),
3144
3169
  modelError = _g[0],
3145
3170
  setModelError = _g[1];
3171
+ var videoRef = useContext(CameraStateContext).videoRef;
3146
3172
  useEffect(function loadModel() {
3173
+ var _this = this;
3147
3174
  setReady(false);
3148
3175
  function handleDownloadProgress(event) {
3149
3176
  setModelDownloadProgress(progressToPercentage(event.detail));
@@ -3153,9 +3180,22 @@ function useLoadDocumentDetector(_a) {
3153
3180
  setModelError(new Error('Model loading time limit exceeded.'));
3154
3181
  }, modelLoadTimeoutMs);
3155
3182
  loadDocumentDetector(modelPath, scoreThreshold).then(function (model) {
3156
- detector.current = model;
3157
- setModelDownloadProgress(100);
3158
- setReady(true);
3183
+ return __awaiter(_this, void 0, void 0, function () {
3184
+ return __generator(this, function (_a) {
3185
+ switch (_a.label) {
3186
+ case 0:
3187
+ detector.current = model;
3188
+ setModelDownloadProgress(100);
3189
+ clearTimeout(modelLoadTimeout);
3190
+ return [4 /*yield*/, waitForVideoReady(videoRef)];
3191
+ case 1:
3192
+ _a.sent();
3193
+ model.detectForVideo(videoRef.current, performance.now());
3194
+ setReady(true);
3195
+ return [2 /*return*/];
3196
+ }
3197
+ });
3198
+ });
3159
3199
  })["catch"](function (e) {
3160
3200
  setModelError(e);
3161
3201
  })["finally"](function () {
@@ -3165,7 +3205,7 @@ function useLoadDocumentDetector(_a) {
3165
3205
  clearTimeout(modelLoadTimeout);
3166
3206
  document.removeEventListener('idmission.preloadProgress.documentDetection', handleDownloadProgress);
3167
3207
  };
3168
- }, [modelLoadTimeoutMs, modelPath, scoreThreshold]);
3208
+ }, [modelLoadTimeoutMs, modelPath, scoreThreshold, videoRef]);
3169
3209
  useEffect(function handleModelError() {
3170
3210
  modelError && (onModelError === null || onModelError === void 0 ? void 0 : onModelError(modelError));
3171
3211
  }, [modelError, onModelError]);