@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.js CHANGED
@@ -75155,9 +75155,6 @@ function getProviderByUrl(url2) {
75155
75155
  if (/^(https?:\/\/)?(www\.)?(youtube\.com|youtube-nocookie\.com|youtu\.?be)\/.+$/.test(url2)) {
75156
75156
  return "YOUTUBE";
75157
75157
  }
75158
- if (/^https?:\/\/player.vimeo.com\/video\/\d{0,9}(?=\b|\/)/.test(url2)) {
75159
- return "VIMEO";
75160
- }
75161
75158
  if (/^https:\/\/geo\.dailymotion\.com\/player(?:\/[a-zA-Z0-9]+)?\.html\?video=([a-zA-Z0-9]+)/.test(url2)) {
75162
75159
  return "DAILYMOTION";
75163
75160
  }
@@ -75202,7 +75199,7 @@ var MediaElementFactory = /*#__PURE__*/ function() {
75202
75199
  if (hasSrc) {
75203
75200
  var _hasSrc = _sliced_to_array(hasSrc, 2), el = _hasSrc[0], value2 = _hasSrc[1];
75204
75201
  var provider2 = getProviderByUrl(value2);
75205
- if (provider2 && provider2 === "YOUTUBE") {
75202
+ if (provider2) {
75206
75203
  return el;
75207
75204
  }
75208
75205
  }
@@ -75281,15 +75278,17 @@ var VideoRegionsDataCollection = /*#__PURE__*/ function() {
75281
75278
  this.timestampList = [];
75282
75279
  this.totalLengthSeconds = 0;
75283
75280
  this.missingInfo = {};
75284
- this.missingInfo = {};
75285
75281
  this.totalLengthSeconds = totalLengthSeconds;
75286
75282
  if (frameInfo) {
75287
- this.frameInfo = frameInfo;
75288
- this.timestampList = Object.keys(this.frameInfo).sort(function(a, b) {
75289
- return parseFloat(a) - parseFloat(b);
75290
- });
75283
+ this.load(frameInfo);
75284
+ } else {
75285
+ this.missingInfo = {
75286
+ "0": {
75287
+ timestamp_start: 0,
75288
+ timestamp_end: totalLengthSeconds
75289
+ }
75290
+ };
75291
75291
  }
75292
- this.preProcessResults();
75293
75292
  }
75294
75293
  _create_class(VideoRegionsDataCollection, [
75295
75294
  {
@@ -75305,11 +75304,16 @@ var VideoRegionsDataCollection = /*#__PURE__*/ function() {
75305
75304
  }
75306
75305
  },
75307
75306
  {
75308
- key: "preProcessResults",
75309
- value: function preProcessResults() {
75310
- var timestamp;
75311
- var frameInfo;
75312
- var nextFrameInfo;
75307
+ key: "sortTimestamps",
75308
+ value: function sortTimestamps() {
75309
+ this.timestampList = Object.keys(this.frameInfo).sort(function(a, b) {
75310
+ return parseFloat(a) - parseFloat(b);
75311
+ });
75312
+ }
75313
+ },
75314
+ {
75315
+ key: "computeMissingIntervals",
75316
+ value: function computeMissingIntervals() {
75313
75317
  var missingIntervals = {};
75314
75318
  if (this.timestampList.length === 0) {
75315
75319
  missingIntervals["0"] = {
@@ -75319,103 +75323,68 @@ var VideoRegionsDataCollection = /*#__PURE__*/ function() {
75319
75323
  this.missingInfo = missingIntervals;
75320
75324
  return;
75321
75325
  }
75322
- for(var index = 0; index < this.timestampList.length; index++){
75323
- timestamp = this.timestampList[index];
75324
- frameInfo = this.frameInfo[timestamp];
75325
- nextFrameInfo = this.frameInfo[this.timestampList[index + 1]];
75326
- if (index === 0 && index === this.timestampList.length - 1) {
75327
- if (frameInfo.timestamp_start !== 0) {
75328
- missingIntervals[0] = {
75329
- timestamp_start: 0,
75330
- timestamp_end: frameInfo.timestamp_start
75331
- };
75332
- }
75333
- if (frameInfo.timestamp_end !== this.totalLengthSeconds) {
75334
- if (frameInfo.timestamp_end !== null) {
75335
- missingIntervals[frameInfo.timestamp_end] = {
75336
- timestamp_start: frameInfo.timestamp_end,
75337
- timestamp_end: this.totalLengthSeconds
75338
- };
75339
- } else {
75340
- missingIntervals[frameInfo.timestamp_start] = {
75341
- timestamp_start: frameInfo.timestamp_start,
75342
- timestamp_end: this.totalLengthSeconds
75343
- };
75344
- }
75345
- }
75346
- } else if (index === 0) {
75347
- if (frameInfo.timestamp_start !== 0) {
75348
- missingIntervals[0] = {
75349
- timestamp_start: 0,
75350
- timestamp_end: frameInfo.timestamp_start
75351
- };
75352
- }
75353
- } else if (index === this.timestampList.length - 1) {
75354
- if (frameInfo.timestamp_end !== this.totalLengthSeconds) {
75355
- if (frameInfo.timestamp_start !== this.totalLengthSeconds) {
75356
- if (frameInfo.timestamp_end == null) {
75357
- missingIntervals[frameInfo.timestamp_start] = {
75358
- timestamp_start: frameInfo.timestamp_start,
75359
- timestamp_end: this.totalLengthSeconds
75360
- };
75361
- } else {
75362
- missingIntervals[frameInfo.timestamp_end] = {
75363
- timestamp_start: frameInfo.timestamp_end,
75364
- timestamp_end: this.totalLengthSeconds
75365
- };
75366
- }
75367
- }
75368
- }
75369
- }
75370
- if (nextFrameInfo) {
75371
- if (frameInfo.timestamp_end !== nextFrameInfo.timestamp_start) {
75372
- missingIntervals[frameInfo.timestamp_end] = {
75373
- timestamp_start: frameInfo.timestamp_end,
75374
- timestamp_end: nextFrameInfo.timestamp_start
75375
- };
75376
- }
75326
+ var first = this.frameInfo[this.timestampList[0]];
75327
+ var last = this.frameInfo[this.timestampList[this.timestampList.length - 1]];
75328
+ if (first.timestamp_start > 0) {
75329
+ missingIntervals["0"] = {
75330
+ timestamp_start: 0,
75331
+ timestamp_end: first.timestamp_start
75332
+ };
75333
+ }
75334
+ for(var i = 0; i < this.timestampList.length - 1; i++){
75335
+ var current = this.frameInfo[this.timestampList[i]];
75336
+ var next = this.frameInfo[this.timestampList[i + 1]];
75337
+ if (current.timestamp_end !== next.timestamp_start) {
75338
+ missingIntervals[String(current.timestamp_end)] = {
75339
+ timestamp_start: current.timestamp_end,
75340
+ timestamp_end: next.timestamp_start
75341
+ };
75377
75342
  }
75378
75343
  }
75344
+ if (last.timestamp_end == null) {
75345
+ missingIntervals[String(last.timestamp_start)] = {
75346
+ timestamp_start: last.timestamp_start,
75347
+ timestamp_end: this.totalLengthSeconds
75348
+ };
75349
+ } else if (last.timestamp_end < this.totalLengthSeconds) {
75350
+ missingIntervals[String(last.timestamp_end)] = {
75351
+ timestamp_start: last.timestamp_end,
75352
+ timestamp_end: this.totalLengthSeconds
75353
+ };
75354
+ }
75379
75355
  this.missingInfo = missingIntervals;
75380
- return;
75381
75356
  }
75382
75357
  },
75383
75358
  {
75384
75359
  key: "isValidRegionForTimestamp",
75385
75360
  value: function isValidRegionForTimestamp(region, timestamp) {
75386
- if (region.timestamp_start < timestamp && region.timestamp_end > timestamp) {
75387
- return true;
75388
- }
75389
- if (region.timestamp_start === timestamp || region.timestamp_end === timestamp) {
75390
- return true;
75391
- }
75392
- return false;
75361
+ return timestamp >= region.timestamp_start && (region.timestamp_end == null || timestamp <= region.timestamp_end);
75393
75362
  }
75394
75363
  },
75395
75364
  {
75396
75365
  key: "findFrame",
75397
- value: function findFrame(target) {
75366
+ value: function findFrame(timestamp) {
75367
+ if (this.timestampList.length === 0) return null;
75398
75368
  var left = 0;
75399
- if (this.timestampList.length === 0) {
75400
- return null;
75401
- }
75402
75369
  var right = this.timestampList.length - 1;
75403
- var leftInterval = this.frameInfo[this.timestampList[left]];
75404
- var rightInterval = this.frameInfo[this.timestampList[right]];
75405
- if (rightInterval.timestamp_end === null) {
75406
- rightInterval = this.frameInfo[this.timestampList[right - 1 < 0 ? 0 : right - 1]];
75370
+ var leftRegion = this.frameInfo[this.timestampList[left]];
75371
+ var rightRegion = this.frameInfo[this.timestampList[right]];
75372
+ while(rightRegion.timestamp_end == null){
75373
+ right--;
75374
+ if (right < 0) {
75375
+ return null;
75376
+ }
75377
+ rightRegion = this.frameInfo[this.timestampList[right]];
75407
75378
  }
75408
- if (target < leftInterval.timestamp_start) {
75409
- return null;
75410
- } else if (target > rightInterval.timestamp_end) {
75379
+ if (timestamp < leftRegion.timestamp_start || timestamp > rightRegion.timestamp_end) {
75411
75380
  return null;
75412
75381
  }
75413
75382
  while(left <= right){
75414
75383
  var mid = Math.floor((left + right) / 2);
75415
- var midInterval = this.frameInfo[this.timestampList[mid]];
75416
- if (this.isValidRegionForTimestamp(midInterval, target)) {
75417
- return midInterval;
75418
- } else if (midInterval.timestamp_end < target) {
75384
+ var region = this.frameInfo[this.timestampList[mid]];
75385
+ if (this.isValidRegionForTimestamp(region, timestamp)) {
75386
+ return region;
75387
+ } else if (region.timestamp_end != null && region.timestamp_end < timestamp) {
75419
75388
  left = mid + 1;
75420
75389
  } else {
75421
75390
  right = mid - 1;
@@ -75427,23 +75396,17 @@ var VideoRegionsDataCollection = /*#__PURE__*/ function() {
75427
75396
  {
75428
75397
  key: "load",
75429
75398
  value: function load(frameInfo) {
75430
- if (frameInfo) {
75431
- this.frameInfo = frameInfo;
75432
- this.timestampList = Object.keys(this.frameInfo).sort(function(a, b) {
75433
- return parseFloat(a) - parseFloat(b);
75434
- });
75435
- }
75436
- this.preProcessResults();
75399
+ this.frameInfo = _object_spread({}, frameInfo);
75400
+ this.sortTimestamps();
75401
+ this.computeMissingIntervals();
75437
75402
  }
75438
75403
  },
75439
75404
  {
75440
75405
  key: "append",
75441
75406
  value: function append(frameInfo) {
75442
75407
  this.frameInfo = _object_spread({}, this.frameInfo, frameInfo);
75443
- this.timestampList = Object.keys(this.frameInfo).sort(function(a, b) {
75444
- return parseFloat(a) - parseFloat(b);
75445
- });
75446
- this.preProcessResults();
75408
+ this.sortTimestamps();
75409
+ this.computeMissingIntervals();
75447
75410
  }
75448
75411
  },
75449
75412
  {
@@ -75454,21 +75417,30 @@ var VideoRegionsDataCollection = /*#__PURE__*/ function() {
75454
75417
  },
75455
75418
  {
75456
75419
  key: "getRange",
75457
- value: function getRange(from, to) {
75458
- if (!from && !to) {
75459
- return this.frameInfo;
75460
- }
75461
- if (!from) {
75462
- from = 0;
75463
- }
75464
- if (!to) {
75465
- to = this.totalLengthSeconds;
75466
- }
75420
+ value: function getRange() {
75421
+ var from = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 0, to = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : this.totalLengthSeconds;
75467
75422
  var result = {};
75468
- for(var index = 0; index < this.timestampList.length; index++){
75469
- var element = +this.timestampList[index];
75470
- if (element >= from && element <= to) {
75471
- result[element] = this.frameInfo[element];
75423
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
75424
+ try {
75425
+ for(var _iterator = this.timestampList[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
75426
+ var key = _step.value;
75427
+ var ts = parseFloat(key);
75428
+ if (ts >= from && ts <= to) {
75429
+ result[key] = this.frameInfo[key];
75430
+ }
75431
+ }
75432
+ } catch (err) {
75433
+ _didIteratorError = true;
75434
+ _iteratorError = err;
75435
+ } finally{
75436
+ try {
75437
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
75438
+ _iterator.return();
75439
+ }
75440
+ } finally{
75441
+ if (_didIteratorError) {
75442
+ throw _iteratorError;
75443
+ }
75472
75444
  }
75473
75445
  }
75474
75446
  return result;
@@ -75478,17 +75450,28 @@ var VideoRegionsDataCollection = /*#__PURE__*/ function() {
75478
75450
  key: "getNextMissingDataInterval",
75479
75451
  value: function getNextMissingDataInterval(referenceTimestamp) {
75480
75452
  var keys = Object.keys(this.missingInfo);
75481
- if (!referenceTimestamp) {
75482
- return this.missingInfo[keys[0]];
75483
- }
75484
- var missingDataInterval;
75485
- for(var index = 0; index < keys.length; index++){
75486
- missingDataInterval = this.missingInfo[keys[index]];
75487
- if (missingDataInterval.timestamp_start <= referenceTimestamp && missingDataInterval.timestamp_end > referenceTimestamp) {
75488
- return missingDataInterval;
75453
+ if (keys.length === 0) return void 0;
75454
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
75455
+ try {
75456
+ for(var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
75457
+ var key = _step.value;
75458
+ var interval = this.missingInfo[key];
75459
+ if (!referenceTimestamp || interval.timestamp_start >= referenceTimestamp) {
75460
+ return interval;
75461
+ }
75489
75462
  }
75490
- if (missingDataInterval.timestamp_start > referenceTimestamp) {
75491
- return missingDataInterval;
75463
+ } catch (err) {
75464
+ _didIteratorError = true;
75465
+ _iteratorError = err;
75466
+ } finally{
75467
+ try {
75468
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
75469
+ _iterator.return();
75470
+ }
75471
+ } finally{
75472
+ if (_didIteratorError) {
75473
+ throw _iteratorError;
75474
+ }
75492
75475
  }
75493
75476
  }
75494
75477
  return this.missingInfo[keys[keys.length - 1]];
@@ -75508,12 +75491,12 @@ var VideoRegionsDataManager = /*#__PURE__*/ function(_import_events4_EventEmitte
75508
75491
  _this.options = options;
75509
75492
  _this.logger = deps.logger;
75510
75493
  _this.service = deps.service;
75494
+ _this.regionsData = new VideoRegionsDataCollection(_this.options.video.duration_s);
75511
75495
  _this.handlePredictionResult = _this.handlePredictionResult.bind(_this);
75512
- _this.handlePredictionConpleted = _this.handlePredictionConpleted.bind(_this);
75496
+ _this.handlePredictionCompleted = _this.handlePredictionCompleted.bind(_this);
75513
75497
  _this.handlePredictionAborted = _this.handlePredictionAborted.bind(_this);
75514
- _this.regionsData = new VideoRegionsDataCollection(_this.options.video.duration_s);
75515
75498
  _this.service.handle("result", _this.handlePredictionResult);
75516
- _this.service.handle("completed", _this.handlePredictionConpleted);
75499
+ _this.service.handle("completed", _this.handlePredictionCompleted);
75517
75500
  _this.service.handle("aborted", _this.handlePredictionAborted);
75518
75501
  return _this;
75519
75502
  }
@@ -75527,8 +75510,8 @@ var VideoRegionsDataManager = /*#__PURE__*/ function(_import_events4_EventEmitte
75527
75510
  }
75528
75511
  },
75529
75512
  {
75530
- key: "handlePredictionConpleted",
75531
- value: function handlePredictionConpleted() {
75513
+ key: "handlePredictionCompleted",
75514
+ value: function handlePredictionCompleted() {
75532
75515
  var _this_logger;
75533
75516
  (_this_logger = this.logger) === null || _this_logger === void 0 ? void 0 : _this_logger.log("Prediction completed!");
75534
75517
  }
@@ -75566,25 +75549,22 @@ var VideoRegionsDataManager = /*#__PURE__*/ function(_import_events4_EventEmitte
75566
75549
  return;
75567
75550
  }
75568
75551
  (_this_logger1 = this.logger) === null || _this_logger1 === void 0 ? void 0 : _this_logger1.log("Collection is incomplete.");
75569
- (_this_logger2 = this.logger) === null || _this_logger2 === void 0 ? void 0 : _this_logger2.log("Getting next missing data interval near : ", timestamp);
75552
+ (_this_logger2 = this.logger) === null || _this_logger2 === void 0 ? void 0 : _this_logger2.log("Getting next missing data interval near:", timestamp);
75570
75553
  var interval = this.regionsData.getNextMissingDataInterval(timestamp);
75571
75554
  if (interval) {
75572
- var _this_logger6;
75573
- (_this_logger6 = this.logger) === null || _this_logger6 === void 0 ? void 0 : _this_logger6.log("Found interval : ", interval);
75574
- var timestampToAdjust;
75575
- if (interval.timestamp_start < timestamp) {
75576
- var _this_logger7;
75577
- timestampToAdjust = timestamp;
75578
- (_this_logger7 = this.logger) === null || _this_logger7 === void 0 ? void 0 : _this_logger7.log("Adjusting frame to : ", timestampToAdjust);
75579
- this.service.send("adjust", {
75580
- timestamp: timestampToAdjust
75581
- });
75582
- } else {
75555
+ var _this_logger6, _this_logger7;
75556
+ (_this_logger6 = this.logger) === null || _this_logger6 === void 0 ? void 0 : _this_logger6.log("Found interval:", interval);
75557
+ var timestampToAdjust = timestamp;
75558
+ if (interval.timestamp_start >= timestamp) {
75583
75559
  timestampToAdjust = interval.timestamp_start;
75584
75560
  }
75561
+ (_this_logger7 = this.logger) === null || _this_logger7 === void 0 ? void 0 : _this_logger7.log("Adjusting frame to:", timestampToAdjust);
75562
+ this.service.send("adjust", {
75563
+ timestamp: timestampToAdjust
75564
+ });
75585
75565
  } else {
75586
75566
  var _this_logger8;
75587
- (_this_logger8 = this.logger) === null || _this_logger8 === void 0 ? void 0 : _this_logger8.log("Interval not found.", interval);
75567
+ (_this_logger8 = this.logger) === null || _this_logger8 === void 0 ? void 0 : _this_logger8.log("No interval found.");
75588
75568
  }
75589
75569
  (_this_logger3 = this.logger) === null || _this_logger3 === void 0 ? void 0 : _this_logger3.groupEnd("[REGIONS DATA] : SEEK");
75590
75570
  }
@@ -75606,12 +75586,12 @@ var VideoRegionsDataManager = /*#__PURE__*/ function(_import_events4_EventEmitte
75606
75586
  value: function dumps(from, to) {
75607
75587
  var a = document.createElement("a");
75608
75588
  var file = new Blob([
75609
- JSON.stringify(this.regionsData.getRange(from, to))
75589
+ JSON.stringify(this.regionsData.getRange(from, to), null, 2)
75610
75590
  ], {
75611
- type: "text/plain"
75591
+ type: "application/json"
75612
75592
  });
75613
75593
  a.href = URL.createObjectURL(file);
75614
- var name = "dumps_".concat(/* @__PURE__ */ new Date().toISOString()).concat(from !== void 0 ? "_s=" + from : "").concat(to !== void 0 ? "_e=" + to : "", ".json");
75594
+ var name = "dumps_".concat(/* @__PURE__ */ new Date().toISOString()).concat(from !== void 0 ? "_s=".concat(from) : "").concat(to !== void 0 ? "_e=".concat(to) : "", ".json");
75615
75595
  a.download = name;
75616
75596
  a.click();
75617
75597
  URL.revokeObjectURL(a.href);
@@ -75627,24 +75607,36 @@ var VideoRegionsDataManager = /*#__PURE__*/ function(_import_events4_EventEmitte
75627
75607
  this.service.destroy();
75628
75608
  this.regionsData.load(data);
75629
75609
  }
75610
+ if (typeof window === "undefined") {
75611
+ var _this_logger;
75612
+ (_this_logger = this.logger) === null || _this_logger === void 0 ? void 0 : _this_logger.error("File input not supported in this environment.");
75613
+ return;
75614
+ }
75630
75615
  var input = document.createElement("input");
75631
75616
  input.type = "file";
75632
- input === null || input === void 0 ? void 0 : input.addEventListener("change", function(event) {
75617
+ input.addEventListener("change", function() {
75633
75618
  var _input_files;
75634
- var file = input === null || input === void 0 ? void 0 : (_input_files = input.files) === null || _input_files === void 0 ? void 0 : _input_files[0];
75619
+ var file = (_input_files = input.files) === null || _input_files === void 0 ? void 0 : _input_files[0];
75635
75620
  if (!file) {
75636
- console.log("No file selected.");
75621
+ var _this_logger;
75622
+ (_this_logger = _this.logger) === null || _this_logger === void 0 ? void 0 : _this_logger.log("No file selected.");
75637
75623
  return;
75638
75624
  }
75639
75625
  var reader = new FileReader();
75640
- reader.onload = function(event2) {
75641
- var _event2_target;
75642
- var fileContent = event2 === null || event2 === void 0 ? void 0 : (_event2_target = event2.target) === null || _event2_target === void 0 ? void 0 : _event2_target.result;
75643
- if (fileContent) {
75644
- var parsedData = JSON.parse(fileContent);
75626
+ reader.onload = function(event) {
75627
+ try {
75628
+ var _event_target;
75629
+ var fileContent = event === null || event === void 0 ? void 0 : (_event_target = event.target) === null || _event_target === void 0 ? void 0 : _event_target.result;
75630
+ if (!fileContent || typeof fileContent !== "string") {
75631
+ throw new Error("Invalid file content.");
75632
+ }
75633
+ var parsed = JSON.parse(fileContent);
75645
75634
  _this.service.send("stop");
75646
75635
  _this.service.destroy();
75647
- _this.regionsData.load(parsedData);
75636
+ _this.regionsData.load(parsed);
75637
+ } catch (err) {
75638
+ var _this_logger;
75639
+ (_this_logger = _this.logger) === null || _this_logger === void 0 ? void 0 : _this_logger.error("Failed to load data:", err);
75648
75640
  }
75649
75641
  };
75650
75642
  reader.readAsText(file);
@@ -75668,34 +75660,32 @@ var VideoRegionsDataManager = /*#__PURE__*/ function(_import_events4_EventEmitte
75668
75660
  }).sort(function(a, b) {
75669
75661
  return a.start - b.start;
75670
75662
  });
75671
- if (appearanceTimestamps.length === 0) {
75672
- return [];
75673
- }
75674
75663
  var validPeriods = [];
75675
- var currentPeriodStart = appearanceTimestamps[0].start;
75676
- var currentPeriodEnd = appearanceTimestamps[0].end;
75664
+ if (appearanceTimestamps.length === 0) return validPeriods;
75665
+ var currentStart = appearanceTimestamps[0].start;
75666
+ var currentEnd = appearanceTimestamps[0].end;
75677
75667
  for(var i = 1; i < appearanceTimestamps.length; i++){
75678
- var current = appearanceTimestamps[i];
75679
- if (current.start <= currentPeriodEnd) {
75680
- currentPeriodEnd = Math.max(currentPeriodEnd, current.end);
75668
+ var _appearanceTimestamps_i = appearanceTimestamps[i], start = _appearanceTimestamps_i.start, end2 = _appearanceTimestamps_i.end;
75669
+ if (start <= currentEnd) {
75670
+ currentEnd = Math.max(currentEnd, end2);
75681
75671
  } else {
75682
- var duration = currentPeriodEnd - currentPeriodStart;
75672
+ var duration = currentEnd - currentStart;
75683
75673
  if (duration >= minDurationSeconds) {
75684
75674
  validPeriods.push({
75685
- start: currentPeriodStart,
75686
- end: currentPeriodEnd,
75675
+ start: currentStart,
75676
+ end: currentEnd,
75687
75677
  duration: duration
75688
75678
  });
75689
75679
  }
75690
- currentPeriodStart = current.start;
75691
- currentPeriodEnd = current.end;
75680
+ currentStart = start;
75681
+ currentEnd = end2;
75692
75682
  }
75693
75683
  }
75694
- var finalDuration = currentPeriodEnd - currentPeriodStart;
75684
+ var finalDuration = currentEnd - currentStart;
75695
75685
  if (finalDuration >= minDurationSeconds) {
75696
75686
  validPeriods.push({
75697
- start: currentPeriodStart,
75698
- end: currentPeriodEnd,
75687
+ start: currentStart,
75688
+ end: currentEnd,
75699
75689
  duration: finalDuration
75700
75690
  });
75701
75691
  }
@@ -75705,10 +75695,10 @@ var VideoRegionsDataManager = /*#__PURE__*/ function(_import_events4_EventEmitte
75705
75695
  {
75706
75696
  key: "destroy",
75707
75697
  value: function destroy() {
75708
- var _this_service_socket, _this_service_socket1, _this_service_socket2;
75709
- (_this_service_socket = this.service.socket) === null || _this_service_socket === void 0 ? void 0 : _this_service_socket.off("result", this.handlePredictionResult);
75710
- (_this_service_socket1 = this.service.socket) === null || _this_service_socket1 === void 0 ? void 0 : _this_service_socket1.off("completed", this.handlePredictionConpleted);
75711
- (_this_service_socket2 = this.service.socket) === null || _this_service_socket2 === void 0 ? void 0 : _this_service_socket2.off("aborted", this.handlePredictionAborted);
75698
+ var socket = this.service.socket;
75699
+ socket === null || socket === void 0 ? void 0 : socket.off("result", this.handlePredictionResult);
75700
+ socket === null || socket === void 0 ? void 0 : socket.off("completed", this.handlePredictionCompleted);
75701
+ socket === null || socket === void 0 ? void 0 : socket.off("aborted", this.handlePredictionAborted);
75712
75702
  this.service.destroy();
75713
75703
  }
75714
75704
  }
@@ -82543,47 +82533,62 @@ var VideoRegionsDurationDecorator = /*#__PURE__*/ function(VideoRegionsDataManag
82543
82533
  {
82544
82534
  key: "check",
82545
82535
  value: function check(timestamp) {
82546
- var totalDuration = 0;
82547
- var last;
82548
- var result;
82549
- var workingTimestamp = timestamp;
82550
- while(totalDuration < this.params.duration){
82551
- var regions2 = this.component.get(workingTimestamp);
82552
- if (!regions2 || !regions2.regions) {
82536
+ var accumulatedDuration = 0;
82537
+ var persistentRegionIds = null;
82538
+ var currentTimestamp = timestamp;
82539
+ var collectedRegions = /* @__PURE__ */ new Map();
82540
+ while(accumulatedDuration < this.params.duration){
82541
+ var frame = this.component.check(currentTimestamp);
82542
+ if (!frame || !frame.regions || frame.timestamp_end == null) {
82553
82543
  return null;
82554
82544
  }
82555
- if (!last) {
82556
- last = regions2.regions.map(function(r3) {
82557
- return r3.id;
82558
- });
82559
- result = _to_consumable_array(regions2.regions);
82560
- }
82561
- var validRegions = regions2.regions.filter(function(reg) {
82562
- return last === null || last === void 0 ? void 0 : last.includes(reg.id);
82545
+ var regionIds = frame.regions.map(function(r3) {
82546
+ return r3.id;
82563
82547
  });
82564
- if (validRegions.length <= 0) {
82565
- return null;
82566
- }
82567
- var duration = 0;
82568
- if (regions2.timestamp_start < workingTimestamp) {
82569
- duration = regions2.timestamp_end - workingTimestamp;
82548
+ if (persistentRegionIds === null) {
82549
+ persistentRegionIds = new Set(regionIds);
82550
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
82551
+ try {
82552
+ for(var _iterator = frame.regions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
82553
+ var r3 = _step.value;
82554
+ collectedRegions.set(r3.id, r3);
82555
+ }
82556
+ } catch (err) {
82557
+ _didIteratorError = true;
82558
+ _iteratorError = err;
82559
+ } finally{
82560
+ try {
82561
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
82562
+ _iterator.return();
82563
+ }
82564
+ } finally{
82565
+ if (_didIteratorError) {
82566
+ throw _iteratorError;
82567
+ }
82568
+ }
82569
+ }
82570
+ ;
82570
82571
  } else {
82571
- duration = regions2.timestamp_end - regions2.timestamp_start;
82572
+ persistentRegionIds = new Set(regionIds.filter(function(id) {
82573
+ return persistentRegionIds.has(id);
82574
+ }));
82572
82575
  }
82573
- totalDuration += duration;
82574
- workingTimestamp = regions2.timestamp_end + 0.01;
82575
- last = validRegions.map(function(r3) {
82576
- return r3.id;
82577
- });
82578
- result = _to_consumable_array(validRegions);
82579
- }
82580
- if (!result) {
82581
- return null;
82576
+ if (persistentRegionIds.size === 0) {
82577
+ return null;
82578
+ }
82579
+ var duration = frame.timestamp_end - frame.timestamp_start;
82580
+ accumulatedDuration += duration;
82581
+ currentTimestamp = frame.timestamp_end + 0.01;
82582
82582
  }
82583
+ var regionsToReturn = Array.from(persistentRegionIds || []).map(function(id) {
82584
+ return collectedRegions.get(id);
82585
+ }).filter(function(r3) {
82586
+ return !!r3;
82587
+ });
82583
82588
  return {
82584
82589
  timestamp_start: timestamp,
82585
- timestamp_end: timestamp + totalDuration,
82586
- regions: result
82590
+ timestamp_end: timestamp + accumulatedDuration,
82591
+ regions: regionsToReturn
82587
82592
  };
82588
82593
  }
82589
82594
  }
@@ -82605,47 +82610,63 @@ var VideoRegionsMaxDurationDecorator = /*#__PURE__*/ function(VideoRegionsDataMa
82605
82610
  {
82606
82611
  key: "check",
82607
82612
  value: function check(timestamp) {
82608
- var totalDuration = 0;
82609
- var last;
82610
- var result;
82611
- var workingTimestamp = timestamp;
82612
- do {
82613
- var regions2 = this.component.get(workingTimestamp);
82614
- if (!regions2 || !regions2.regions) {
82613
+ var accumulatedDuration = 0;
82614
+ var currentTimestamp = timestamp;
82615
+ var persistentRegionIds = null;
82616
+ var collectedRegions = /* @__PURE__ */ new Map();
82617
+ while(true){
82618
+ var frame = this.component.check(currentTimestamp);
82619
+ if (!frame || !frame.regions || frame.timestamp_end == null) {
82615
82620
  break;
82616
82621
  }
82617
- if (!last) {
82618
- last = regions2.regions.map(function(r3) {
82619
- return r3.id;
82620
- });
82621
- result = _to_consumable_array(regions2.regions);
82622
- }
82623
- var validRegions = regions2.regions.filter(function(reg) {
82624
- return last === null || last === void 0 ? void 0 : last.includes(reg.id);
82622
+ var regionIds = frame.regions.map(function(r3) {
82623
+ return r3.id;
82625
82624
  });
82626
- if (validRegions.length <= 0) {
82627
- break;
82628
- }
82629
- var duration = 0;
82630
- if (regions2.timestamp_start < workingTimestamp) {
82631
- duration = regions2.timestamp_end - workingTimestamp;
82625
+ if (persistentRegionIds === null) {
82626
+ persistentRegionIds = new Set(regionIds);
82627
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
82628
+ try {
82629
+ for(var _iterator = frame.regions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
82630
+ var region = _step.value;
82631
+ collectedRegions.set(region.id, region);
82632
+ }
82633
+ } catch (err) {
82634
+ _didIteratorError = true;
82635
+ _iteratorError = err;
82636
+ } finally{
82637
+ try {
82638
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
82639
+ _iterator.return();
82640
+ }
82641
+ } finally{
82642
+ if (_didIteratorError) {
82643
+ throw _iteratorError;
82644
+ }
82645
+ }
82646
+ }
82632
82647
  } else {
82633
- duration = regions2.timestamp_end - regions2.timestamp_start;
82648
+ persistentRegionIds = new Set(regionIds.filter(function(id) {
82649
+ return persistentRegionIds.has(id);
82650
+ }));
82634
82651
  }
82635
- totalDuration += duration;
82636
- workingTimestamp = regions2.timestamp_end + 0.01;
82637
- last = validRegions.map(function(r3) {
82638
- return r3.id;
82639
- });
82640
- result = _to_consumable_array(validRegions);
82641
- }while (true);
82642
- if (!result || totalDuration < this.params.minDuration) {
82652
+ if (persistentRegionIds.size === 0) {
82653
+ break;
82654
+ }
82655
+ accumulatedDuration += frame.timestamp_end - frame.timestamp_start;
82656
+ currentTimestamp = frame.timestamp_end + 1e-3;
82657
+ }
82658
+ if (!persistentRegionIds || persistentRegionIds.size === 0 || accumulatedDuration < this.params.minDuration) {
82643
82659
  return null;
82644
82660
  }
82661
+ var regionsToReturn = Array.from(persistentRegionIds).map(function(id) {
82662
+ return collectedRegions.get(id);
82663
+ }).filter(function(r3) {
82664
+ return !!r3;
82665
+ });
82645
82666
  return {
82646
82667
  timestamp_start: timestamp,
82647
- timestamp_end: timestamp + totalDuration,
82648
- regions: result
82668
+ timestamp_end: timestamp + accumulatedDuration,
82669
+ regions: regionsToReturn
82649
82670
  };
82650
82671
  }
82651
82672
  }