@brndts/brndts-ads 1.13.22 → 1.13.23

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/index.mjs CHANGED
@@ -75234,9 +75234,6 @@ function getProviderByUrl(url2) {
75234
75234
  if (/^(https?:\/\/)?(www\.)?(youtube\.com|youtube-nocookie\.com|youtu\.?be)\/.+$/.test(url2)) {
75235
75235
  return "YOUTUBE";
75236
75236
  }
75237
- if (/^https?:\/\/player.vimeo.com\/video\/\d{0,9}(?=\b|\/)/.test(url2)) {
75238
- return "VIMEO";
75239
- }
75240
75237
  if (/^https:\/\/geo\.dailymotion\.com\/player(?:\/[a-zA-Z0-9]+)?\.html\?video=([a-zA-Z0-9]+)/.test(url2)) {
75241
75238
  return "DAILYMOTION";
75242
75239
  }
@@ -75282,7 +75279,7 @@ var MediaElementFactory = /*#__PURE__*/ function() {
75282
75279
  if (hasSrc) {
75283
75280
  var _hasSrc = _sliced_to_array(hasSrc, 2), el = _hasSrc[0], value2 = _hasSrc[1];
75284
75281
  var provider2 = getProviderByUrl(value2);
75285
- if (provider2 && provider2 === "YOUTUBE") {
75282
+ if (provider2) {
75286
75283
  return el;
75287
75284
  }
75288
75285
  }
@@ -75362,15 +75359,17 @@ var VideoRegionsDataCollection = /*#__PURE__*/ function() {
75362
75359
  this.timestampList = [];
75363
75360
  this.totalLengthSeconds = 0;
75364
75361
  this.missingInfo = {};
75365
- this.missingInfo = {};
75366
75362
  this.totalLengthSeconds = totalLengthSeconds;
75367
75363
  if (frameInfo) {
75368
- this.frameInfo = frameInfo;
75369
- this.timestampList = Object.keys(this.frameInfo).sort(function(a, b) {
75370
- return parseFloat(a) - parseFloat(b);
75371
- });
75364
+ this.load(frameInfo);
75365
+ } else {
75366
+ this.missingInfo = {
75367
+ "0": {
75368
+ timestamp_start: 0,
75369
+ timestamp_end: totalLengthSeconds
75370
+ }
75371
+ };
75372
75372
  }
75373
- this.preProcessResults();
75374
75373
  }
75375
75374
  _create_class(VideoRegionsDataCollection, [
75376
75375
  {
@@ -75386,11 +75385,16 @@ var VideoRegionsDataCollection = /*#__PURE__*/ function() {
75386
75385
  }
75387
75386
  },
75388
75387
  {
75389
- key: "preProcessResults",
75390
- value: function preProcessResults() {
75391
- var timestamp;
75392
- var frameInfo;
75393
- var nextFrameInfo;
75388
+ key: "sortTimestamps",
75389
+ value: function sortTimestamps() {
75390
+ this.timestampList = Object.keys(this.frameInfo).sort(function(a, b) {
75391
+ return parseFloat(a) - parseFloat(b);
75392
+ });
75393
+ }
75394
+ },
75395
+ {
75396
+ key: "computeMissingIntervals",
75397
+ value: function computeMissingIntervals() {
75394
75398
  var missingIntervals = {};
75395
75399
  if (this.timestampList.length === 0) {
75396
75400
  missingIntervals["0"] = {
@@ -75400,103 +75404,68 @@ var VideoRegionsDataCollection = /*#__PURE__*/ function() {
75400
75404
  this.missingInfo = missingIntervals;
75401
75405
  return;
75402
75406
  }
75403
- for(var index = 0; index < this.timestampList.length; index++){
75404
- timestamp = this.timestampList[index];
75405
- frameInfo = this.frameInfo[timestamp];
75406
- nextFrameInfo = this.frameInfo[this.timestampList[index + 1]];
75407
- if (index === 0 && index === this.timestampList.length - 1) {
75408
- if (frameInfo.timestamp_start !== 0) {
75409
- missingIntervals[0] = {
75410
- timestamp_start: 0,
75411
- timestamp_end: frameInfo.timestamp_start
75412
- };
75413
- }
75414
- if (frameInfo.timestamp_end !== this.totalLengthSeconds) {
75415
- if (frameInfo.timestamp_end !== null) {
75416
- missingIntervals[frameInfo.timestamp_end] = {
75417
- timestamp_start: frameInfo.timestamp_end,
75418
- timestamp_end: this.totalLengthSeconds
75419
- };
75420
- } else {
75421
- missingIntervals[frameInfo.timestamp_start] = {
75422
- timestamp_start: frameInfo.timestamp_start,
75423
- timestamp_end: this.totalLengthSeconds
75424
- };
75425
- }
75426
- }
75427
- } else if (index === 0) {
75428
- if (frameInfo.timestamp_start !== 0) {
75429
- missingIntervals[0] = {
75430
- timestamp_start: 0,
75431
- timestamp_end: frameInfo.timestamp_start
75432
- };
75433
- }
75434
- } else if (index === this.timestampList.length - 1) {
75435
- if (frameInfo.timestamp_end !== this.totalLengthSeconds) {
75436
- if (frameInfo.timestamp_start !== this.totalLengthSeconds) {
75437
- if (frameInfo.timestamp_end == null) {
75438
- missingIntervals[frameInfo.timestamp_start] = {
75439
- timestamp_start: frameInfo.timestamp_start,
75440
- timestamp_end: this.totalLengthSeconds
75441
- };
75442
- } else {
75443
- missingIntervals[frameInfo.timestamp_end] = {
75444
- timestamp_start: frameInfo.timestamp_end,
75445
- timestamp_end: this.totalLengthSeconds
75446
- };
75447
- }
75448
- }
75449
- }
75450
- }
75451
- if (nextFrameInfo) {
75452
- if (frameInfo.timestamp_end !== nextFrameInfo.timestamp_start) {
75453
- missingIntervals[frameInfo.timestamp_end] = {
75454
- timestamp_start: frameInfo.timestamp_end,
75455
- timestamp_end: nextFrameInfo.timestamp_start
75456
- };
75457
- }
75407
+ var first = this.frameInfo[this.timestampList[0]];
75408
+ var last = this.frameInfo[this.timestampList[this.timestampList.length - 1]];
75409
+ if (first.timestamp_start > 0) {
75410
+ missingIntervals["0"] = {
75411
+ timestamp_start: 0,
75412
+ timestamp_end: first.timestamp_start
75413
+ };
75414
+ }
75415
+ for(var i = 0; i < this.timestampList.length - 1; i++){
75416
+ var current = this.frameInfo[this.timestampList[i]];
75417
+ var next = this.frameInfo[this.timestampList[i + 1]];
75418
+ if (current.timestamp_end !== next.timestamp_start) {
75419
+ missingIntervals[String(current.timestamp_end)] = {
75420
+ timestamp_start: current.timestamp_end,
75421
+ timestamp_end: next.timestamp_start
75422
+ };
75458
75423
  }
75459
75424
  }
75425
+ if (last.timestamp_end == null) {
75426
+ missingIntervals[String(last.timestamp_start)] = {
75427
+ timestamp_start: last.timestamp_start,
75428
+ timestamp_end: this.totalLengthSeconds
75429
+ };
75430
+ } else if (last.timestamp_end < this.totalLengthSeconds) {
75431
+ missingIntervals[String(last.timestamp_end)] = {
75432
+ timestamp_start: last.timestamp_end,
75433
+ timestamp_end: this.totalLengthSeconds
75434
+ };
75435
+ }
75460
75436
  this.missingInfo = missingIntervals;
75461
- return;
75462
75437
  }
75463
75438
  },
75464
75439
  {
75465
75440
  key: "isValidRegionForTimestamp",
75466
75441
  value: function isValidRegionForTimestamp(region, timestamp) {
75467
- if (region.timestamp_start < timestamp && region.timestamp_end > timestamp) {
75468
- return true;
75469
- }
75470
- if (region.timestamp_start === timestamp || region.timestamp_end === timestamp) {
75471
- return true;
75472
- }
75473
- return false;
75442
+ return timestamp >= region.timestamp_start && (region.timestamp_end == null || timestamp <= region.timestamp_end);
75474
75443
  }
75475
75444
  },
75476
75445
  {
75477
75446
  key: "findFrame",
75478
- value: function findFrame(target) {
75447
+ value: function findFrame(timestamp) {
75448
+ if (this.timestampList.length === 0) return null;
75479
75449
  var left = 0;
75480
- if (this.timestampList.length === 0) {
75481
- return null;
75482
- }
75483
75450
  var right = this.timestampList.length - 1;
75484
- var leftInterval = this.frameInfo[this.timestampList[left]];
75485
- var rightInterval = this.frameInfo[this.timestampList[right]];
75486
- if (rightInterval.timestamp_end === null) {
75487
- rightInterval = this.frameInfo[this.timestampList[right - 1 < 0 ? 0 : right - 1]];
75451
+ var leftRegion = this.frameInfo[this.timestampList[left]];
75452
+ var rightRegion = this.frameInfo[this.timestampList[right]];
75453
+ while(rightRegion.timestamp_end == null){
75454
+ right--;
75455
+ if (right < 0) {
75456
+ return null;
75457
+ }
75458
+ rightRegion = this.frameInfo[this.timestampList[right]];
75488
75459
  }
75489
- if (target < leftInterval.timestamp_start) {
75490
- return null;
75491
- } else if (target > rightInterval.timestamp_end) {
75460
+ if (timestamp < leftRegion.timestamp_start || timestamp > rightRegion.timestamp_end) {
75492
75461
  return null;
75493
75462
  }
75494
75463
  while(left <= right){
75495
75464
  var mid = Math.floor((left + right) / 2);
75496
- var midInterval = this.frameInfo[this.timestampList[mid]];
75497
- if (this.isValidRegionForTimestamp(midInterval, target)) {
75498
- return midInterval;
75499
- } else if (midInterval.timestamp_end < target) {
75465
+ var region = this.frameInfo[this.timestampList[mid]];
75466
+ if (this.isValidRegionForTimestamp(region, timestamp)) {
75467
+ return region;
75468
+ } else if (region.timestamp_end != null && region.timestamp_end < timestamp) {
75500
75469
  left = mid + 1;
75501
75470
  } else {
75502
75471
  right = mid - 1;
@@ -75508,23 +75477,17 @@ var VideoRegionsDataCollection = /*#__PURE__*/ function() {
75508
75477
  {
75509
75478
  key: "load",
75510
75479
  value: function load(frameInfo) {
75511
- if (frameInfo) {
75512
- this.frameInfo = frameInfo;
75513
- this.timestampList = Object.keys(this.frameInfo).sort(function(a, b) {
75514
- return parseFloat(a) - parseFloat(b);
75515
- });
75516
- }
75517
- this.preProcessResults();
75480
+ this.frameInfo = _object_spread({}, frameInfo);
75481
+ this.sortTimestamps();
75482
+ this.computeMissingIntervals();
75518
75483
  }
75519
75484
  },
75520
75485
  {
75521
75486
  key: "append",
75522
75487
  value: function append(frameInfo) {
75523
75488
  this.frameInfo = _object_spread({}, this.frameInfo, frameInfo);
75524
- this.timestampList = Object.keys(this.frameInfo).sort(function(a, b) {
75525
- return parseFloat(a) - parseFloat(b);
75526
- });
75527
- this.preProcessResults();
75489
+ this.sortTimestamps();
75490
+ this.computeMissingIntervals();
75528
75491
  }
75529
75492
  },
75530
75493
  {
@@ -75535,21 +75498,30 @@ var VideoRegionsDataCollection = /*#__PURE__*/ function() {
75535
75498
  },
75536
75499
  {
75537
75500
  key: "getRange",
75538
- value: function getRange(from, to) {
75539
- if (!from && !to) {
75540
- return this.frameInfo;
75541
- }
75542
- if (!from) {
75543
- from = 0;
75544
- }
75545
- if (!to) {
75546
- to = this.totalLengthSeconds;
75547
- }
75501
+ value: function getRange() {
75502
+ var from = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0, to = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : this.totalLengthSeconds;
75548
75503
  var result = {};
75549
- for(var index = 0; index < this.timestampList.length; index++){
75550
- var element = +this.timestampList[index];
75551
- if (element >= from && element <= to) {
75552
- result[element] = this.frameInfo[element];
75504
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
75505
+ try {
75506
+ for(var _iterator = this.timestampList[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
75507
+ var key = _step.value;
75508
+ var ts = parseFloat(key);
75509
+ if (ts >= from && ts <= to) {
75510
+ result[key] = this.frameInfo[key];
75511
+ }
75512
+ }
75513
+ } catch (err) {
75514
+ _didIteratorError = true;
75515
+ _iteratorError = err;
75516
+ } finally{
75517
+ try {
75518
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
75519
+ _iterator.return();
75520
+ }
75521
+ } finally{
75522
+ if (_didIteratorError) {
75523
+ throw _iteratorError;
75524
+ }
75553
75525
  }
75554
75526
  }
75555
75527
  return result;
@@ -75559,17 +75531,28 @@ var VideoRegionsDataCollection = /*#__PURE__*/ function() {
75559
75531
  key: "getNextMissingDataInterval",
75560
75532
  value: function getNextMissingDataInterval(referenceTimestamp) {
75561
75533
  var keys = Object.keys(this.missingInfo);
75562
- if (!referenceTimestamp) {
75563
- return this.missingInfo[keys[0]];
75564
- }
75565
- var missingDataInterval;
75566
- for(var index = 0; index < keys.length; index++){
75567
- missingDataInterval = this.missingInfo[keys[index]];
75568
- if (missingDataInterval.timestamp_start <= referenceTimestamp && missingDataInterval.timestamp_end > referenceTimestamp) {
75569
- return missingDataInterval;
75534
+ if (keys.length === 0) return void 0;
75535
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
75536
+ try {
75537
+ for(var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
75538
+ var key = _step.value;
75539
+ var interval = this.missingInfo[key];
75540
+ if (!referenceTimestamp || interval.timestamp_start >= referenceTimestamp) {
75541
+ return interval;
75542
+ }
75570
75543
  }
75571
- if (missingDataInterval.timestamp_start > referenceTimestamp) {
75572
- return missingDataInterval;
75544
+ } catch (err) {
75545
+ _didIteratorError = true;
75546
+ _iteratorError = err;
75547
+ } finally{
75548
+ try {
75549
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
75550
+ _iterator.return();
75551
+ }
75552
+ } finally{
75553
+ if (_didIteratorError) {
75554
+ throw _iteratorError;
75555
+ }
75573
75556
  }
75574
75557
  }
75575
75558
  return this.missingInfo[keys[keys.length - 1]];
@@ -75590,12 +75573,12 @@ var VideoRegionsDataManager = /*#__PURE__*/ function(_import_events4_EventEmitte
75590
75573
  _this.options = options;
75591
75574
  _this.logger = deps.logger;
75592
75575
  _this.service = deps.service;
75576
+ _this.regionsData = new VideoRegionsDataCollection(_this.options.video.duration_s);
75593
75577
  _this.handlePredictionResult = _this.handlePredictionResult.bind(_this);
75594
- _this.handlePredictionConpleted = _this.handlePredictionConpleted.bind(_this);
75578
+ _this.handlePredictionCompleted = _this.handlePredictionCompleted.bind(_this);
75595
75579
  _this.handlePredictionAborted = _this.handlePredictionAborted.bind(_this);
75596
- _this.regionsData = new VideoRegionsDataCollection(_this.options.video.duration_s);
75597
75580
  _this.service.handle("result", _this.handlePredictionResult);
75598
- _this.service.handle("completed", _this.handlePredictionConpleted);
75581
+ _this.service.handle("completed", _this.handlePredictionCompleted);
75599
75582
  _this.service.handle("aborted", _this.handlePredictionAborted);
75600
75583
  return _this;
75601
75584
  }
@@ -75609,8 +75592,8 @@ var VideoRegionsDataManager = /*#__PURE__*/ function(_import_events4_EventEmitte
75609
75592
  }
75610
75593
  },
75611
75594
  {
75612
- key: "handlePredictionConpleted",
75613
- value: function handlePredictionConpleted() {
75595
+ key: "handlePredictionCompleted",
75596
+ value: function handlePredictionCompleted() {
75614
75597
  var _this_logger;
75615
75598
  (_this_logger = this.logger) === null || _this_logger === void 0 ? void 0 : _this_logger.log("Prediction completed!");
75616
75599
  }
@@ -75648,25 +75631,22 @@ var VideoRegionsDataManager = /*#__PURE__*/ function(_import_events4_EventEmitte
75648
75631
  return;
75649
75632
  }
75650
75633
  (_this_logger1 = this.logger) === null || _this_logger1 === void 0 ? void 0 : _this_logger1.log("Collection is incomplete.");
75651
- (_this_logger2 = this.logger) === null || _this_logger2 === void 0 ? void 0 : _this_logger2.log("Getting next missing data interval near : ", timestamp);
75634
+ (_this_logger2 = this.logger) === null || _this_logger2 === void 0 ? void 0 : _this_logger2.log("Getting next missing data interval near:", timestamp);
75652
75635
  var interval = this.regionsData.getNextMissingDataInterval(timestamp);
75653
75636
  if (interval) {
75654
- var _this_logger6;
75655
- (_this_logger6 = this.logger) === null || _this_logger6 === void 0 ? void 0 : _this_logger6.log("Found interval : ", interval);
75656
- var timestampToAdjust;
75657
- if (interval.timestamp_start < timestamp) {
75658
- var _this_logger7;
75659
- timestampToAdjust = timestamp;
75660
- (_this_logger7 = this.logger) === null || _this_logger7 === void 0 ? void 0 : _this_logger7.log("Adjusting frame to : ", timestampToAdjust);
75661
- this.service.send("adjust", {
75662
- timestamp: timestampToAdjust
75663
- });
75664
- } else {
75637
+ var _this_logger6, _this_logger7;
75638
+ (_this_logger6 = this.logger) === null || _this_logger6 === void 0 ? void 0 : _this_logger6.log("Found interval:", interval);
75639
+ var timestampToAdjust = timestamp;
75640
+ if (interval.timestamp_start >= timestamp) {
75665
75641
  timestampToAdjust = interval.timestamp_start;
75666
75642
  }
75643
+ (_this_logger7 = this.logger) === null || _this_logger7 === void 0 ? void 0 : _this_logger7.log("Adjusting frame to:", timestampToAdjust);
75644
+ this.service.send("adjust", {
75645
+ timestamp: timestampToAdjust
75646
+ });
75667
75647
  } else {
75668
75648
  var _this_logger8;
75669
- (_this_logger8 = this.logger) === null || _this_logger8 === void 0 ? void 0 : _this_logger8.log("Interval not found.", interval);
75649
+ (_this_logger8 = this.logger) === null || _this_logger8 === void 0 ? void 0 : _this_logger8.log("No interval found.");
75670
75650
  }
75671
75651
  (_this_logger3 = this.logger) === null || _this_logger3 === void 0 ? void 0 : _this_logger3.groupEnd("[REGIONS DATA] : SEEK");
75672
75652
  }
@@ -75688,12 +75668,12 @@ var VideoRegionsDataManager = /*#__PURE__*/ function(_import_events4_EventEmitte
75688
75668
  value: function dumps(from, to) {
75689
75669
  var a = document.createElement("a");
75690
75670
  var file = new Blob([
75691
- JSON.stringify(this.regionsData.getRange(from, to))
75671
+ JSON.stringify(this.regionsData.getRange(from, to), null, 2)
75692
75672
  ], {
75693
- type: "text/plain"
75673
+ type: "application/json"
75694
75674
  });
75695
75675
  a.href = URL.createObjectURL(file);
75696
- var name = "dumps_".concat(/* @__PURE__ */ new Date().toISOString()).concat(from !== void 0 ? "_s=" + from : "").concat(to !== void 0 ? "_e=" + to : "", ".json");
75676
+ var name = "dumps_".concat(/* @__PURE__ */ new Date().toISOString()).concat(from !== void 0 ? "_s=".concat(from) : "").concat(to !== void 0 ? "_e=".concat(to) : "", ".json");
75697
75677
  a.download = name;
75698
75678
  a.click();
75699
75679
  URL.revokeObjectURL(a.href);
@@ -75709,24 +75689,36 @@ var VideoRegionsDataManager = /*#__PURE__*/ function(_import_events4_EventEmitte
75709
75689
  this.service.destroy();
75710
75690
  this.regionsData.load(data);
75711
75691
  }
75692
+ if (typeof window === "undefined") {
75693
+ var _this_logger;
75694
+ (_this_logger = this.logger) === null || _this_logger === void 0 ? void 0 : _this_logger.error("File input not supported in this environment.");
75695
+ return;
75696
+ }
75712
75697
  var input = document.createElement("input");
75713
75698
  input.type = "file";
75714
- input === null || input === void 0 ? void 0 : input.addEventListener("change", function(event) {
75699
+ input.addEventListener("change", function() {
75715
75700
  var _input_files;
75716
- var file = input === null || input === void 0 ? void 0 : (_input_files = input.files) === null || _input_files === void 0 ? void 0 : _input_files[0];
75701
+ var file = (_input_files = input.files) === null || _input_files === void 0 ? void 0 : _input_files[0];
75717
75702
  if (!file) {
75718
- console.log("No file selected.");
75703
+ var _this_logger;
75704
+ (_this_logger = _this.logger) === null || _this_logger === void 0 ? void 0 : _this_logger.log("No file selected.");
75719
75705
  return;
75720
75706
  }
75721
75707
  var reader = new FileReader();
75722
- reader.onload = function(event2) {
75723
- var _event2_target;
75724
- var fileContent = event2 === null || event2 === void 0 ? void 0 : (_event2_target = event2.target) === null || _event2_target === void 0 ? void 0 : _event2_target.result;
75725
- if (fileContent) {
75726
- var parsedData = JSON.parse(fileContent);
75708
+ reader.onload = function(event) {
75709
+ try {
75710
+ var _event_target;
75711
+ var fileContent = event === null || event === void 0 ? void 0 : (_event_target = event.target) === null || _event_target === void 0 ? void 0 : _event_target.result;
75712
+ if (!fileContent || typeof fileContent !== "string") {
75713
+ throw new Error("Invalid file content.");
75714
+ }
75715
+ var parsed = JSON.parse(fileContent);
75727
75716
  _this.service.send("stop");
75728
75717
  _this.service.destroy();
75729
- _this.regionsData.load(parsedData);
75718
+ _this.regionsData.load(parsed);
75719
+ } catch (err) {
75720
+ var _this_logger;
75721
+ (_this_logger = _this.logger) === null || _this_logger === void 0 ? void 0 : _this_logger.error("Failed to load data:", err);
75730
75722
  }
75731
75723
  };
75732
75724
  reader.readAsText(file);
@@ -75750,34 +75742,32 @@ var VideoRegionsDataManager = /*#__PURE__*/ function(_import_events4_EventEmitte
75750
75742
  }).sort(function(a, b) {
75751
75743
  return a.start - b.start;
75752
75744
  });
75753
- if (appearanceTimestamps.length === 0) {
75754
- return [];
75755
- }
75756
75745
  var validPeriods = [];
75757
- var currentPeriodStart = appearanceTimestamps[0].start;
75758
- var currentPeriodEnd = appearanceTimestamps[0].end;
75746
+ if (appearanceTimestamps.length === 0) return validPeriods;
75747
+ var currentStart = appearanceTimestamps[0].start;
75748
+ var currentEnd = appearanceTimestamps[0].end;
75759
75749
  for(var i = 1; i < appearanceTimestamps.length; i++){
75760
- var current = appearanceTimestamps[i];
75761
- if (current.start <= currentPeriodEnd) {
75762
- currentPeriodEnd = Math.max(currentPeriodEnd, current.end);
75750
+ var _appearanceTimestamps_i = appearanceTimestamps[i], start = _appearanceTimestamps_i.start, end2 = _appearanceTimestamps_i.end;
75751
+ if (start <= currentEnd) {
75752
+ currentEnd = Math.max(currentEnd, end2);
75763
75753
  } else {
75764
- var duration = currentPeriodEnd - currentPeriodStart;
75754
+ var duration = currentEnd - currentStart;
75765
75755
  if (duration >= minDurationSeconds) {
75766
75756
  validPeriods.push({
75767
- start: currentPeriodStart,
75768
- end: currentPeriodEnd,
75757
+ start: currentStart,
75758
+ end: currentEnd,
75769
75759
  duration: duration
75770
75760
  });
75771
75761
  }
75772
- currentPeriodStart = current.start;
75773
- currentPeriodEnd = current.end;
75762
+ currentStart = start;
75763
+ currentEnd = end2;
75774
75764
  }
75775
75765
  }
75776
- var finalDuration = currentPeriodEnd - currentPeriodStart;
75766
+ var finalDuration = currentEnd - currentStart;
75777
75767
  if (finalDuration >= minDurationSeconds) {
75778
75768
  validPeriods.push({
75779
- start: currentPeriodStart,
75780
- end: currentPeriodEnd,
75769
+ start: currentStart,
75770
+ end: currentEnd,
75781
75771
  duration: finalDuration
75782
75772
  });
75783
75773
  }
@@ -75787,10 +75777,10 @@ var VideoRegionsDataManager = /*#__PURE__*/ function(_import_events4_EventEmitte
75787
75777
  {
75788
75778
  key: "destroy",
75789
75779
  value: function destroy() {
75790
- var _this_service_socket, _this_service_socket1, _this_service_socket2;
75791
- (_this_service_socket = this.service.socket) === null || _this_service_socket === void 0 ? void 0 : _this_service_socket.off("result", this.handlePredictionResult);
75792
- (_this_service_socket1 = this.service.socket) === null || _this_service_socket1 === void 0 ? void 0 : _this_service_socket1.off("completed", this.handlePredictionConpleted);
75793
- (_this_service_socket2 = this.service.socket) === null || _this_service_socket2 === void 0 ? void 0 : _this_service_socket2.off("aborted", this.handlePredictionAborted);
75780
+ var socket = this.service.socket;
75781
+ socket === null || socket === void 0 ? void 0 : socket.off("result", this.handlePredictionResult);
75782
+ socket === null || socket === void 0 ? void 0 : socket.off("completed", this.handlePredictionCompleted);
75783
+ socket === null || socket === void 0 ? void 0 : socket.off("aborted", this.handlePredictionAborted);
75794
75784
  this.service.destroy();
75795
75785
  }
75796
75786
  }
@@ -82671,47 +82661,62 @@ var VideoRegionsDurationDecorator = /*#__PURE__*/ function(VideoRegionsDataManag
82671
82661
  {
82672
82662
  key: "check",
82673
82663
  value: function check(timestamp) {
82674
- var totalDuration = 0;
82675
- var last;
82676
- var result;
82677
- var workingTimestamp = timestamp;
82678
- while(totalDuration < this.params.duration){
82679
- var regions2 = this.component.get(workingTimestamp);
82680
- if (!regions2 || !regions2.regions) {
82664
+ var accumulatedDuration = 0;
82665
+ var persistentRegionIds = null;
82666
+ var currentTimestamp = timestamp;
82667
+ var collectedRegions = /* @__PURE__ */ new Map();
82668
+ while(accumulatedDuration < this.params.duration){
82669
+ var frame = this.component.check(currentTimestamp);
82670
+ if (!frame || !frame.regions || frame.timestamp_end == null) {
82681
82671
  return null;
82682
82672
  }
82683
- if (!last) {
82684
- last = regions2.regions.map(function(r3) {
82685
- return r3.id;
82686
- });
82687
- result = _to_consumable_array(regions2.regions);
82688
- }
82689
- var validRegions = regions2.regions.filter(function(reg) {
82690
- return last === null || last === void 0 ? void 0 : last.includes(reg.id);
82673
+ var regionIds = frame.regions.map(function(r3) {
82674
+ return r3.id;
82691
82675
  });
82692
- if (validRegions.length <= 0) {
82693
- return null;
82694
- }
82695
- var duration = 0;
82696
- if (regions2.timestamp_start < workingTimestamp) {
82697
- duration = regions2.timestamp_end - workingTimestamp;
82676
+ if (persistentRegionIds === null) {
82677
+ persistentRegionIds = new Set(regionIds);
82678
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
82679
+ try {
82680
+ for(var _iterator = frame.regions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
82681
+ var r3 = _step.value;
82682
+ collectedRegions.set(r3.id, r3);
82683
+ }
82684
+ } catch (err) {
82685
+ _didIteratorError = true;
82686
+ _iteratorError = err;
82687
+ } finally{
82688
+ try {
82689
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
82690
+ _iterator.return();
82691
+ }
82692
+ } finally{
82693
+ if (_didIteratorError) {
82694
+ throw _iteratorError;
82695
+ }
82696
+ }
82697
+ }
82698
+ ;
82698
82699
  } else {
82699
- duration = regions2.timestamp_end - regions2.timestamp_start;
82700
+ persistentRegionIds = new Set(regionIds.filter(function(id) {
82701
+ return persistentRegionIds.has(id);
82702
+ }));
82700
82703
  }
82701
- totalDuration += duration;
82702
- workingTimestamp = regions2.timestamp_end + 0.01;
82703
- last = validRegions.map(function(r3) {
82704
- return r3.id;
82705
- });
82706
- result = _to_consumable_array(validRegions);
82707
- }
82708
- if (!result) {
82709
- return null;
82704
+ if (persistentRegionIds.size === 0) {
82705
+ return null;
82706
+ }
82707
+ var duration = frame.timestamp_end - frame.timestamp_start;
82708
+ accumulatedDuration += duration;
82709
+ currentTimestamp = frame.timestamp_end + 0.01;
82710
82710
  }
82711
+ var regionsToReturn = Array.from(persistentRegionIds || []).map(function(id) {
82712
+ return collectedRegions.get(id);
82713
+ }).filter(function(r3) {
82714
+ return !!r3;
82715
+ });
82711
82716
  return {
82712
82717
  timestamp_start: timestamp,
82713
- timestamp_end: timestamp + totalDuration,
82714
- regions: result
82718
+ timestamp_end: timestamp + accumulatedDuration,
82719
+ regions: regionsToReturn
82715
82720
  };
82716
82721
  }
82717
82722
  }
@@ -82734,47 +82739,63 @@ var VideoRegionsMaxDurationDecorator = /*#__PURE__*/ function(VideoRegionsDataMa
82734
82739
  {
82735
82740
  key: "check",
82736
82741
  value: function check(timestamp) {
82737
- var totalDuration = 0;
82738
- var last;
82739
- var result;
82740
- var workingTimestamp = timestamp;
82741
- do {
82742
- var regions2 = this.component.get(workingTimestamp);
82743
- if (!regions2 || !regions2.regions) {
82742
+ var accumulatedDuration = 0;
82743
+ var currentTimestamp = timestamp;
82744
+ var persistentRegionIds = null;
82745
+ var collectedRegions = /* @__PURE__ */ new Map();
82746
+ while(true){
82747
+ var frame = this.component.check(currentTimestamp);
82748
+ if (!frame || !frame.regions || frame.timestamp_end == null) {
82744
82749
  break;
82745
82750
  }
82746
- if (!last) {
82747
- last = regions2.regions.map(function(r3) {
82748
- return r3.id;
82749
- });
82750
- result = _to_consumable_array(regions2.regions);
82751
- }
82752
- var validRegions = regions2.regions.filter(function(reg) {
82753
- return last === null || last === void 0 ? void 0 : last.includes(reg.id);
82751
+ var regionIds = frame.regions.map(function(r3) {
82752
+ return r3.id;
82754
82753
  });
82755
- if (validRegions.length <= 0) {
82756
- break;
82757
- }
82758
- var duration = 0;
82759
- if (regions2.timestamp_start < workingTimestamp) {
82760
- duration = regions2.timestamp_end - workingTimestamp;
82754
+ if (persistentRegionIds === null) {
82755
+ persistentRegionIds = new Set(regionIds);
82756
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
82757
+ try {
82758
+ for(var _iterator = frame.regions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
82759
+ var region = _step.value;
82760
+ collectedRegions.set(region.id, region);
82761
+ }
82762
+ } catch (err) {
82763
+ _didIteratorError = true;
82764
+ _iteratorError = err;
82765
+ } finally{
82766
+ try {
82767
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
82768
+ _iterator.return();
82769
+ }
82770
+ } finally{
82771
+ if (_didIteratorError) {
82772
+ throw _iteratorError;
82773
+ }
82774
+ }
82775
+ }
82761
82776
  } else {
82762
- duration = regions2.timestamp_end - regions2.timestamp_start;
82777
+ persistentRegionIds = new Set(regionIds.filter(function(id) {
82778
+ return persistentRegionIds.has(id);
82779
+ }));
82763
82780
  }
82764
- totalDuration += duration;
82765
- workingTimestamp = regions2.timestamp_end + 0.01;
82766
- last = validRegions.map(function(r3) {
82767
- return r3.id;
82768
- });
82769
- result = _to_consumable_array(validRegions);
82770
- }while (true);
82771
- if (!result || totalDuration < this.params.minDuration) {
82781
+ if (persistentRegionIds.size === 0) {
82782
+ break;
82783
+ }
82784
+ accumulatedDuration += frame.timestamp_end - frame.timestamp_start;
82785
+ currentTimestamp = frame.timestamp_end + 1e-3;
82786
+ }
82787
+ if (!persistentRegionIds || persistentRegionIds.size === 0 || accumulatedDuration < this.params.minDuration) {
82772
82788
  return null;
82773
82789
  }
82790
+ var regionsToReturn = Array.from(persistentRegionIds).map(function(id) {
82791
+ return collectedRegions.get(id);
82792
+ }).filter(function(r3) {
82793
+ return !!r3;
82794
+ });
82774
82795
  return {
82775
82796
  timestamp_start: timestamp,
82776
- timestamp_end: timestamp + totalDuration,
82777
- regions: result
82797
+ timestamp_end: timestamp + accumulatedDuration,
82798
+ regions: regionsToReturn
82778
82799
  };
82779
82800
  }
82780
82801
  }