idmission-web-sdk 2.1.87 → 2.1.89

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
@@ -204,7 +204,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
204
204
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
205
205
  };
206
206
 
207
- var webSdkVersion = '2.1.87';
207
+ var webSdkVersion = '2.1.89';
208
208
 
209
209
  function getPlatform() {
210
210
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -5558,7 +5558,6 @@ function makeDocumentDetectorPrediction(detector, frame) {
5558
5558
  });
5559
5559
  });
5560
5560
  }
5561
- var lastNBoxes = [];
5562
5561
  var lastDetectionAt = 0;
5563
5562
  var lastDetectionTime = 0;
5564
5563
  function setLastDetectionAt(time) {
@@ -5566,6 +5565,18 @@ function setLastDetectionAt(time) {
5566
5565
  lastDetectionAt = time;
5567
5566
  }
5568
5567
  var framesNeededSamples = [];
5568
+ function trackFramesNeeded(value) {
5569
+ framesNeededSamples.unshift(value);
5570
+ if (framesNeededSamples.length > 10) framesNeededSamples.length = 10;
5571
+ }
5572
+ var lastNBoxes = [];
5573
+ function trackBox(box, framesNeeded) {
5574
+ if (framesNeeded === void 0) {
5575
+ framesNeeded = 12;
5576
+ }
5577
+ lastNBoxes.unshift(box);
5578
+ if (lastNBoxes.length > framesNeeded) lastNBoxes.length = framesNeeded;
5579
+ }
5569
5580
  var defaultDocumentDetectionBoundaries = {
5570
5581
  top: 20,
5571
5582
  bottom: 20,
@@ -5651,14 +5662,10 @@ function processDocumentDetectorPrediction(prediction, thresholds, boundaries) {
5651
5662
  documentTooClose = docWidth > 0.85 || docHeight > 0.85;
5652
5663
  if (detectionThresholdMet && documentInBounds && !documentTooClose) {
5653
5664
  var threshold_1 = (_m = thresholds.stability) !== null && _m !== void 0 ? _m : defaultDocumentDetectionThresholds.stability;
5654
- framesNeededSamples.unshift(1000 / lastDetectionTime);
5655
- framesNeededSamples = framesNeededSamples.slice(0, 10);
5665
+ trackFramesNeeded(1000 / lastDetectionTime);
5656
5666
  var framesNeeded = Math.ceil(average(framesNeededSamples));
5657
- lastNBoxes.unshift(bestDocument.box);
5658
- lastNBoxes = lastNBoxes.slice(0, framesNeeded);
5659
- var numFramesToConsider = Math.min(framesNeeded, 12);
5660
- var framesToConsider = lastNBoxes.slice(0, numFramesToConsider);
5661
- documentIsStable = lastNBoxes.length >= framesNeeded - 1 && !createPairs(framesToConsider).some(function (_a) {
5667
+ trackBox(bestDocument.box, framesNeeded);
5668
+ documentIsStable = lastNBoxes.length >= framesNeeded && !createPairs(lastNBoxes, 12).some(function (_a) {
5662
5669
  var a = _a[0],
5663
5670
  b = _a[1];
5664
5671
  return calculateIoU(a, b) < threshold_1;
@@ -5700,9 +5707,10 @@ function applyNonMaxSuppression(detectedObjects) {
5700
5707
  return !!obj;
5701
5708
  });
5702
5709
  }
5703
- function createPairs(arr) {
5710
+ function createPairs(arr, maxPairs) {
5704
5711
  var pairs = [];
5705
- for (var i = 0; i < arr.length - 1; i++) {
5712
+ var end = maxPairs ;
5713
+ for (var i = 0; i < end; i++) {
5706
5714
  pairs.push([arr[i], arr[i + 1]]);
5707
5715
  }
5708
5716
  return pairs;
@@ -5723,6 +5731,7 @@ function calculateIoU(boxA, boxB) {
5723
5731
  }
5724
5732
  function average(arr) {
5725
5733
  var len = arr.length;
5734
+ if (len === 0) return 0;
5726
5735
  var sum = 0;
5727
5736
  for (var i = 0; i < len; i++) sum += arr[i];
5728
5737
  return sum / len;