@brndts/brndts-ads 1.13.15 → 1.13.17

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
@@ -67891,6 +67891,7 @@ var AdsConfigsClass = /*#__PURE__*/ function(BRNDTSConfig) {
67891
67891
  adStrategies: strategies
67892
67892
  };
67893
67893
  _this.merge();
67894
+ console.log("Ads strategies fetched", _this.remote.adStrategies);
67894
67895
  })
67895
67896
  ];
67896
67897
  case 1:
@@ -71435,16 +71436,20 @@ var RegionBorderPlugin = /*#__PURE__*/ function() {
71435
71436
  {
71436
71437
  key: "beforeShow",
71437
71438
  value: function beforeShow(region) {
71438
- var _this_options;
71439
- if (!region.hasContent) {
71440
- return Promise.resolve();
71441
- }
71442
- if ((_this_options = this.options) === null || _this_options === void 0 ? void 0 : _this_options.useFeather) {
71443
- region.content.view.classList.toggle("BRNDTS_R_FTH", true);
71444
- } else {
71445
- region.content.view.classList.toggle("BRNDTS_R_B", true);
71446
- }
71447
- return Promise.resolve();
71439
+ var _this = this;
71440
+ if (!region.hasContent) return Promise.resolve();
71441
+ return new Promise(function(resolve) {
71442
+ requestAnimationFrame(function() {
71443
+ var _this_options;
71444
+ var view = region.content.view;
71445
+ if ((_this_options = _this.options) === null || _this_options === void 0 ? void 0 : _this_options.useFeather) {
71446
+ view.classList.toggle("BRNDTS_R_FTH", true);
71447
+ } else {
71448
+ view.classList.toggle("BRNDTS_R_B", true);
71449
+ }
71450
+ resolve();
71451
+ });
71452
+ });
71448
71453
  }
71449
71454
  },
71450
71455
  {
@@ -72918,10 +72923,15 @@ var YoutubeMediaElement = /*#__PURE__*/ function(GenericMediaElement) {
72918
72923
  key: "assurePlaybackState",
72919
72924
  value: function assurePlaybackState(play) {
72920
72925
  if (this.media && this.media.hasPlayed) {
72921
- var _this__source;
72922
- if (((_this__source = this._source) === null || _this__source === void 0 ? void 0 : _this__source.videoId) && this.videoId && this.videoId.length > 0 && this._source.videoId !== this.videoId) {
72923
- this._source.videoId = this.videoId;
72924
- this.emit("UPDATED_SOURCE", this._source.videoId);
72926
+ var _this_instance;
72927
+ var newVideoIndex = (_this_instance = this.instance) === null || _this_instance === void 0 ? void 0 : _this_instance.getPlaylistIndex();
72928
+ if (newVideoIndex !== this.currentVideoIndex) {
72929
+ this.currentVideoIndex = newVideoIndex;
72930
+ if (this._source && this._source.type === "playlist") {
72931
+ var _this__source;
72932
+ this._source.videoId = this.videoId;
72933
+ this.emit("UPDATED_SOURCE", (_this__source = this._source) === null || _this__source === void 0 ? void 0 : _this__source.videoId);
72934
+ }
72925
72935
  }
72926
72936
  }
72927
72937
  if (this.media && play && !this.media.hasPlayed) {
@@ -72957,11 +72967,13 @@ var YoutubeMediaElement = /*#__PURE__*/ function(GenericMediaElement) {
72957
72967
  key: "handleYTPlayerReady",
72958
72968
  value: function handleYTPlayerReady(event) {
72959
72969
  var _this = this;
72970
+ var _this_instance;
72960
72971
  if (this.instance) {
72961
72972
  this.context.logger.warn("Instance already found!");
72962
72973
  return;
72963
72974
  }
72964
72975
  this.instance = event.target;
72976
+ this.currentVideoIndex = (_this_instance = this.instance) === null || _this_instance === void 0 ? void 0 : _this_instance.getPlaylistIndex();
72965
72977
  this.ready = true;
72966
72978
  this.observeResize();
72967
72979
  this.context.store.dispatch({
@@ -75460,6 +75472,56 @@ var VideoRegionsDataManager = /*#__PURE__*/ function(_import_events4_EventEmitte
75460
75472
  input.click();
75461
75473
  }
75462
75474
  },
75475
+ {
75476
+ key: "findRegionAppearancePeriods",
75477
+ value: function findRegionAppearancePeriods(regionId, minDurationSeconds) {
75478
+ var data = this.regionsData.data;
75479
+ var appearanceTimestamps = Object.values(data).filter(function(info) {
75480
+ return info.regions.some(function(region) {
75481
+ return region.id === regionId;
75482
+ });
75483
+ }).map(function(info) {
75484
+ return {
75485
+ start: info.timestamp_start,
75486
+ end: info.timestamp_end
75487
+ };
75488
+ }).sort(function(a, b) {
75489
+ return a.start - b.start;
75490
+ });
75491
+ if (appearanceTimestamps.length === 0) {
75492
+ return [];
75493
+ }
75494
+ var validPeriods = [];
75495
+ var currentPeriodStart = appearanceTimestamps[0].start;
75496
+ var currentPeriodEnd = appearanceTimestamps[0].end;
75497
+ for(var i = 1; i < appearanceTimestamps.length; i++){
75498
+ var current = appearanceTimestamps[i];
75499
+ if (current.start <= currentPeriodEnd) {
75500
+ currentPeriodEnd = Math.max(currentPeriodEnd, current.end);
75501
+ } else {
75502
+ var duration = currentPeriodEnd - currentPeriodStart;
75503
+ if (duration >= minDurationSeconds) {
75504
+ validPeriods.push({
75505
+ start: currentPeriodStart,
75506
+ end: currentPeriodEnd,
75507
+ duration: duration
75508
+ });
75509
+ }
75510
+ currentPeriodStart = current.start;
75511
+ currentPeriodEnd = current.end;
75512
+ }
75513
+ }
75514
+ var finalDuration = currentPeriodEnd - currentPeriodStart;
75515
+ if (finalDuration >= minDurationSeconds) {
75516
+ validPeriods.push({
75517
+ start: currentPeriodStart,
75518
+ end: currentPeriodEnd,
75519
+ duration: finalDuration
75520
+ });
75521
+ }
75522
+ return validPeriods;
75523
+ }
75524
+ },
75463
75525
  {
75464
75526
  key: "destroy",
75465
75527
  value: function destroy() {
@@ -75473,236 +75535,6 @@ var VideoRegionsDataManager = /*#__PURE__*/ function(_import_events4_EventEmitte
75473
75535
  ]);
75474
75536
  return VideoRegionsDataManager;
75475
75537
  }(import_events4.EventEmitter);
75476
- // src/Ads/VideoAds/VideoRegionsData/VideoRegionsDataManagerDecorator.ts
75477
- var VideoRegionsDataManagerDecorator = /*#__PURE__*/ function() {
75478
- "use strict";
75479
- function VideoRegionsDataManagerDecorator(component) {
75480
- _class_call_check(this, VideoRegionsDataManagerDecorator);
75481
- this.component = component;
75482
- }
75483
- _create_class(VideoRegionsDataManagerDecorator, [
75484
- {
75485
- key: "data",
75486
- get: function get() {
75487
- return this.component.data;
75488
- }
75489
- },
75490
- {
75491
- key: "on",
75492
- value: function on(event, handler) {
75493
- return this.component.on(event, handler);
75494
- }
75495
- },
75496
- {
75497
- key: "fetch",
75498
- value: function fetch1() {
75499
- return this.component.fetch();
75500
- }
75501
- },
75502
- {
75503
- key: "seek",
75504
- value: function seek(timestamp) {
75505
- return this.component.seek(timestamp);
75506
- }
75507
- },
75508
- {
75509
- key: "check",
75510
- value: function check(timestamp) {
75511
- return this.component.check(timestamp);
75512
- }
75513
- },
75514
- {
75515
- key: "get",
75516
- value: function get(timestamp) {
75517
- return this.component.get(timestamp);
75518
- }
75519
- },
75520
- {
75521
- key: "destroy",
75522
- value: function destroy() {
75523
- return this.component.destroy();
75524
- }
75525
- },
75526
- {
75527
- key: "dumps",
75528
- value: function dumps(from, to) {
75529
- return this.component.dumps(from, to);
75530
- }
75531
- },
75532
- {
75533
- key: "loads",
75534
- value: function loads() {
75535
- return this.component.loads();
75536
- }
75537
- }
75538
- ]);
75539
- return VideoRegionsDataManagerDecorator;
75540
- }();
75541
- // src/Ads/VideoAds/VideoRegionsDurationDecorator.ts
75542
- var VideoRegionsDurationDecorator = /*#__PURE__*/ function(VideoRegionsDataManagerDecorator) {
75543
- "use strict";
75544
- _inherits(VideoRegionsDurationDecorator, VideoRegionsDataManagerDecorator);
75545
- function VideoRegionsDurationDecorator(component, params) {
75546
- _class_call_check(this, VideoRegionsDurationDecorator);
75547
- var _this;
75548
- _this = _call_super(this, VideoRegionsDurationDecorator, [
75549
- component
75550
- ]);
75551
- _this.params = params;
75552
- return _this;
75553
- }
75554
- _create_class(VideoRegionsDurationDecorator, [
75555
- {
75556
- key: "check",
75557
- value: function check(timestamp) {
75558
- var totalDuration = 0;
75559
- var last;
75560
- var result;
75561
- var workingTimestamp = timestamp;
75562
- while(totalDuration < this.params.duration){
75563
- var regions2 = this.component.get(workingTimestamp);
75564
- if (!regions2 || !regions2.regions) {
75565
- return null;
75566
- }
75567
- if (!last) {
75568
- last = regions2.regions.map(function(r3) {
75569
- return r3.id;
75570
- });
75571
- result = _to_consumable_array(regions2.regions);
75572
- return {
75573
- timestamp_start: timestamp,
75574
- timestamp_end: timestamp + totalDuration,
75575
- regions: result
75576
- };
75577
- }
75578
- var validRegions = regions2.regions.filter(function(reg) {
75579
- return last === null || last === void 0 ? void 0 : last.includes(reg.id);
75580
- });
75581
- if (validRegions.length <= 0) {
75582
- return null;
75583
- }
75584
- var duration = 0;
75585
- if (regions2.timestamp_start < workingTimestamp) {
75586
- duration = regions2.timestamp_end - workingTimestamp;
75587
- } else {
75588
- duration = regions2.timestamp_end - regions2.timestamp_start;
75589
- }
75590
- totalDuration += duration;
75591
- workingTimestamp = regions2.timestamp_end + 1e-3 + 1e3;
75592
- last = validRegions.map(function(r3) {
75593
- return r3.id;
75594
- });
75595
- result = _to_consumable_array(validRegions);
75596
- }
75597
- if (!result) {
75598
- return null;
75599
- }
75600
- return {
75601
- timestamp_start: timestamp,
75602
- timestamp_end: timestamp + totalDuration,
75603
- regions: result
75604
- };
75605
- }
75606
- }
75607
- ]);
75608
- return VideoRegionsDurationDecorator;
75609
- }(VideoRegionsDataManagerDecorator);
75610
- var VideoRegionsMaxDurationDecorator = /*#__PURE__*/ function(VideoRegionsDataManagerDecorator) {
75611
- "use strict";
75612
- _inherits(VideoRegionsMaxDurationDecorator, VideoRegionsDataManagerDecorator);
75613
- function VideoRegionsMaxDurationDecorator(component, params) {
75614
- _class_call_check(this, VideoRegionsMaxDurationDecorator);
75615
- var _this;
75616
- _this = _call_super(this, VideoRegionsMaxDurationDecorator, [
75617
- component
75618
- ]);
75619
- _this.params = params;
75620
- return _this;
75621
- }
75622
- _create_class(VideoRegionsMaxDurationDecorator, [
75623
- {
75624
- key: "check",
75625
- value: function check(timestamp) {
75626
- var totalDuration = 0;
75627
- var last;
75628
- var result;
75629
- var workingTimestamp = timestamp;
75630
- var filteredRegions = [];
75631
- do {
75632
- var regions2 = this.component.get(workingTimestamp);
75633
- if (!regions2 || !regions2.regions) {
75634
- break;
75635
- }
75636
- if (!last) {
75637
- last = regions2.regions.map(function(r3) {
75638
- return r3.id;
75639
- });
75640
- result = _to_consumable_array(regions2.regions);
75641
- continue;
75642
- }
75643
- filteredRegions = regions2.regions.filter(function(reg) {
75644
- if (last.includes(reg.id)) {
75645
- return true;
75646
- }
75647
- return false;
75648
- });
75649
- if (filteredRegions.length <= 0) {
75650
- break;
75651
- }
75652
- var duration = 0;
75653
- if (regions2.timestamp_start < workingTimestamp) {
75654
- duration = regions2.timestamp_end - workingTimestamp;
75655
- } else {
75656
- duration = regions2.timestamp_end - regions2.timestamp_start;
75657
- }
75658
- totalDuration += duration;
75659
- workingTimestamp = regions2.timestamp_end + 1e-3 + 1e3;
75660
- last = filteredRegions.map(function(r3) {
75661
- return r3.id;
75662
- });
75663
- result = _to_consumable_array(filteredRegions);
75664
- }while (true);
75665
- if (!result || totalDuration < this.params.minDuration) {
75666
- return null;
75667
- }
75668
- return {
75669
- timestamp_start: timestamp,
75670
- timestamp_end: timestamp + totalDuration,
75671
- regions: result
75672
- };
75673
- }
75674
- }
75675
- ]);
75676
- return VideoRegionsMaxDurationDecorator;
75677
- }(VideoRegionsDataManagerDecorator);
75678
- var VideoRegionsDecoratorFactory = /*#__PURE__*/ function() {
75679
- "use strict";
75680
- function VideoRegionsDecoratorFactory() {
75681
- _class_call_check(this, VideoRegionsDecoratorFactory);
75682
- }
75683
- _create_class(VideoRegionsDecoratorFactory, null, [
75684
- {
75685
- key: "decorate",
75686
- value: function decorate(component, params) {
75687
- if (!params) {
75688
- return component;
75689
- }
75690
- if (params.visibility_duration) {
75691
- return new VideoRegionsDurationDecorator(component, {
75692
- duration: params.visibility_duration.value
75693
- });
75694
- }
75695
- if (params.minimum_display_time) {
75696
- return new VideoRegionsMaxDurationDecorator(component, {
75697
- minDuration: params.minimum_display_time.value
75698
- });
75699
- }
75700
- return component;
75701
- }
75702
- }
75703
- ]);
75704
- return VideoRegionsDecoratorFactory;
75705
- }();
75706
75538
  // src/Ads/VideoAds/State/Store.ts
75707
75539
  function reducer(state, action) {
75708
75540
  switch(action.type){
@@ -76236,10 +76068,9 @@ var DynamicDurationPresentation = /*#__PURE__*/ function(AbstractPresentation) {
76236
76068
  this.stopRetry();
76237
76069
  this.startPacing();
76238
76070
  if (opts.expectedDuration && !this.presentationTimer.isPaused) {
76239
- this.presentationTimer.setDuration(opts.expectedDuration);
76240
- } else {
76241
- this.presentationTimer.resume();
76071
+ this.presentationTimer.setDuration(opts.expectedDuration * 1e3);
76242
76072
  }
76073
+ this.presentationTimer.resume();
76243
76074
  }
76244
76075
  },
76245
76076
  {
@@ -79768,6 +79599,8 @@ var Controls = /*#__PURE__*/ function() {
79768
79599
  this.context = context;
79769
79600
  this.container = document.createElement("div");
79770
79601
  this.container.id = "BRNDTS_CTL";
79602
+ this.container.style.width = "100%";
79603
+ this.container.style.height = "100%";
79771
79604
  this.buildControls();
79772
79605
  }
79773
79606
  _create_class(Controls, [
@@ -79869,6 +79702,8 @@ var Backdrop = /*#__PURE__*/ function() {
79869
79702
  this.context = context;
79870
79703
  this.container = document.createElement("div");
79871
79704
  this.container.id = "BRNDTS_BKD";
79705
+ this.container.style.width = "100%";
79706
+ this.container.style.height = "100%";
79872
79707
  }
79873
79708
  _create_class(Backdrop, [
79874
79709
  {
@@ -81699,7 +81534,6 @@ var BasicPresentationMode = /*#__PURE__*/ function() {
81699
81534
  var _this_adPresentationStrategy, _this_regionsRenderer;
81700
81535
  (_this_adPresentationStrategy = this.adPresentationStrategy) === null || _this_adPresentationStrategy === void 0 ? void 0 : _this_adPresentationStrategy.stop();
81701
81536
  (_this_regionsRenderer = this.regionsRenderer) === null || _this_regionsRenderer === void 0 ? void 0 : _this_regionsRenderer.clear();
81702
- this.context.logger.info("NotBasicPresentationMode has been stopped.");
81703
81537
  }
81704
81538
  },
81705
81539
  {
@@ -81809,6 +81643,7 @@ var RegionFactory = /*#__PURE__*/ function() {
81809
81643
  }));
81810
81644
  }
81811
81645
  plugins2.push(new RegionMaskPlugin());
81646
+ plugins2.push(new RegionAnimationPlugin("OPACITY"));
81812
81647
  }
81813
81648
  if (!((_this_deps2 = this.deps) === null || _this_deps2 === void 0 ? void 0 : (_this_deps_config1 = _this_deps2.config) === null || _this_deps_config1 === void 0 ? void 0 : (_this_deps_config_getAdsConfig_general1 = _this_deps_config1.getAdsConfig().general) === null || _this_deps_config_getAdsConfig_general1 === void 0 ? void 0 : (_this_deps_config_getAdsConfig_general_debug_mode1 = _this_deps_config_getAdsConfig_general1.debug_mode) === null || _this_deps_config_getAdsConfig_general_debug_mode1 === void 0 ? void 0 : _this_deps_config_getAdsConfig_general_debug_mode1.value) && (this.deps.strategy === "banner" || this.deps.strategy === "bannerv2" || this.deps.strategy === "bannerv2_ocr" || this.deps.strategy === "test")) {
81814
81649
  plugins2.push(new RegionBorderPlugin(), new RegionAnimationPlugin());
@@ -82398,8 +82233,10 @@ var NotBasicPresentationMode = /*#__PURE__*/ function() {
82398
82233
  expectedDuration: regions2.timestamp_end - regions2.timestamp_start
82399
82234
  });
82400
82235
  } else {
82401
- var _this_adPresentationStrategy1;
82236
+ var _this_adPresentationStrategy1, _this_regionsRenderer, _this_auxElementsRenderer;
82402
82237
  (_this_adPresentationStrategy1 = _this.adPresentationStrategy) === null || _this_adPresentationStrategy1 === void 0 ? void 0 : _this_adPresentationStrategy1.endedPresentation();
82238
+ (_this_regionsRenderer = _this.regionsRenderer) === null || _this_regionsRenderer === void 0 ? void 0 : _this_regionsRenderer.clear();
82239
+ (_this_auxElementsRenderer = _this.auxElementsRenderer) === null || _this_auxElementsRenderer === void 0 ? void 0 : _this_auxElementsRenderer.clear();
82403
82240
  }
82404
82241
  }).on("pace", function() {
82405
82242
  try {
@@ -82452,16 +82289,15 @@ var NotBasicPresentationMode = /*#__PURE__*/ function() {
82452
82289
  (_this_adPresentationStrategy = this.adPresentationStrategy) === null || _this_adPresentationStrategy === void 0 ? void 0 : _this_adPresentationStrategy.stop();
82453
82290
  (_this_regionsRenderer = this.regionsRenderer) === null || _this_regionsRenderer === void 0 ? void 0 : _this_regionsRenderer.clear();
82454
82291
  (_this_auxElementsRenderer = this.auxElementsRenderer) === null || _this_auxElementsRenderer === void 0 ? void 0 : _this_auxElementsRenderer.clear();
82455
- this.context.logger.info("NotBasicPresentationMode has been stopped.");
82456
82292
  }
82457
82293
  },
82458
82294
  {
82459
82295
  key: "destroy",
82460
82296
  value: function destroy() {
82461
- var _this_adPresentationStrategy, _this_regionsRenderer, _this_context_interface;
82297
+ var _this_adPresentationStrategy, _this_regionsRenderer, _this_context_recorder, _this_context_interface;
82462
82298
  (_this_adPresentationStrategy = this.adPresentationStrategy) === null || _this_adPresentationStrategy === void 0 ? void 0 : _this_adPresentationStrategy.destroy();
82463
82299
  (_this_regionsRenderer = this.regionsRenderer) === null || _this_regionsRenderer === void 0 ? void 0 : _this_regionsRenderer.destroy();
82464
- this.context.recorder.destroy();
82300
+ (_this_context_recorder = this.context.recorder) === null || _this_context_recorder === void 0 ? void 0 : _this_context_recorder.destroy();
82465
82301
  (_this_context_interface = this.context.interface) === null || _this_context_interface === void 0 ? void 0 : _this_context_interface.destroy();
82466
82302
  }
82467
82303
  }
@@ -82491,15 +82327,289 @@ var PresentationModeFactory = /*#__PURE__*/ function() {
82491
82327
  ]);
82492
82328
  return PresentationModeFactory;
82493
82329
  }();
82494
- // src/Ads/VideoAds/VideoAd.ts
82495
- var VideoAd = /*#__PURE__*/ function() {
82330
+ // src/Ads/VideoAds/VideoRegionsData/VideoRegionsDataManagerDecorator.ts
82331
+ var VideoRegionsDataManagerDecorator = /*#__PURE__*/ function() {
82496
82332
  "use strict";
82497
- function VideoAd(context, target) {
82498
- _class_call_check(this, VideoAd);
82499
- this.handleInfo = this.handleInfo.bind(this);
82500
- this.context = context;
82501
- var videoAdContext = {
82502
- config: context.config,
82333
+ function VideoRegionsDataManagerDecorator(component) {
82334
+ _class_call_check(this, VideoRegionsDataManagerDecorator);
82335
+ this.component = component;
82336
+ }
82337
+ _create_class(VideoRegionsDataManagerDecorator, [
82338
+ {
82339
+ key: "data",
82340
+ get: function get() {
82341
+ return this.component.data;
82342
+ }
82343
+ },
82344
+ {
82345
+ key: "on",
82346
+ value: function on(event, handler) {
82347
+ return this.component.on(event, handler);
82348
+ }
82349
+ },
82350
+ {
82351
+ key: "fetch",
82352
+ value: function fetch1() {
82353
+ return this.component.fetch();
82354
+ }
82355
+ },
82356
+ {
82357
+ key: "seek",
82358
+ value: function seek(timestamp) {
82359
+ return this.component.seek(timestamp);
82360
+ }
82361
+ },
82362
+ {
82363
+ key: "check",
82364
+ value: function check(timestamp) {
82365
+ return this.component.check(timestamp);
82366
+ }
82367
+ },
82368
+ {
82369
+ key: "get",
82370
+ value: function get(timestamp) {
82371
+ return this.component.get(timestamp);
82372
+ }
82373
+ },
82374
+ {
82375
+ key: "destroy",
82376
+ value: function destroy() {
82377
+ return this.component.destroy();
82378
+ }
82379
+ },
82380
+ {
82381
+ key: "dumps",
82382
+ value: function dumps(from, to) {
82383
+ return this.component.dumps(from, to);
82384
+ }
82385
+ },
82386
+ {
82387
+ key: "loads",
82388
+ value: function loads() {
82389
+ return this.component.loads();
82390
+ }
82391
+ }
82392
+ ]);
82393
+ return VideoRegionsDataManagerDecorator;
82394
+ }();
82395
+ // src/Ads/VideoAds/VideoRegionsData/VideoRegionsDecorators.ts
82396
+ var VideoRegionsDurationDecorator = /*#__PURE__*/ function(VideoRegionsDataManagerDecorator) {
82397
+ "use strict";
82398
+ _inherits(VideoRegionsDurationDecorator, VideoRegionsDataManagerDecorator);
82399
+ function VideoRegionsDurationDecorator(component, params) {
82400
+ _class_call_check(this, VideoRegionsDurationDecorator);
82401
+ var _this;
82402
+ _this = _call_super(this, VideoRegionsDurationDecorator, [
82403
+ component
82404
+ ]);
82405
+ _this.params = params;
82406
+ return _this;
82407
+ }
82408
+ _create_class(VideoRegionsDurationDecorator, [
82409
+ {
82410
+ key: "check",
82411
+ value: function check(timestamp) {
82412
+ var totalDuration = 0;
82413
+ var last;
82414
+ var result;
82415
+ var workingTimestamp = timestamp;
82416
+ while(totalDuration < this.params.duration){
82417
+ var regions2 = this.component.get(workingTimestamp);
82418
+ if (!regions2 || !regions2.regions) {
82419
+ return null;
82420
+ }
82421
+ if (!last) {
82422
+ last = regions2.regions.map(function(r3) {
82423
+ return r3.id;
82424
+ });
82425
+ result = _to_consumable_array(regions2.regions);
82426
+ }
82427
+ var validRegions = regions2.regions.filter(function(reg) {
82428
+ return last === null || last === void 0 ? void 0 : last.includes(reg.id);
82429
+ });
82430
+ if (validRegions.length <= 0) {
82431
+ return null;
82432
+ }
82433
+ var duration = 0;
82434
+ if (regions2.timestamp_start < workingTimestamp) {
82435
+ duration = regions2.timestamp_end - workingTimestamp;
82436
+ } else {
82437
+ duration = regions2.timestamp_end - regions2.timestamp_start;
82438
+ }
82439
+ totalDuration += duration;
82440
+ workingTimestamp = regions2.timestamp_end + 0.01;
82441
+ last = validRegions.map(function(r3) {
82442
+ return r3.id;
82443
+ });
82444
+ result = _to_consumable_array(validRegions);
82445
+ }
82446
+ if (!result) {
82447
+ return null;
82448
+ }
82449
+ return {
82450
+ timestamp_start: timestamp,
82451
+ timestamp_end: timestamp + totalDuration,
82452
+ regions: result
82453
+ };
82454
+ }
82455
+ }
82456
+ ]);
82457
+ return VideoRegionsDurationDecorator;
82458
+ }(VideoRegionsDataManagerDecorator);
82459
+ var VideoRegionsMaxDurationDecorator = /*#__PURE__*/ function(VideoRegionsDataManagerDecorator) {
82460
+ "use strict";
82461
+ _inherits(VideoRegionsMaxDurationDecorator, VideoRegionsDataManagerDecorator);
82462
+ function VideoRegionsMaxDurationDecorator(component, params) {
82463
+ _class_call_check(this, VideoRegionsMaxDurationDecorator);
82464
+ var _this;
82465
+ _this = _call_super(this, VideoRegionsMaxDurationDecorator, [
82466
+ component
82467
+ ]);
82468
+ _this.params = params;
82469
+ return _this;
82470
+ }
82471
+ _create_class(VideoRegionsMaxDurationDecorator, [
82472
+ {
82473
+ key: "check",
82474
+ value: function check(timestamp) {
82475
+ var totalDuration = 0;
82476
+ var last;
82477
+ var result;
82478
+ var workingTimestamp = timestamp;
82479
+ do {
82480
+ var regions2 = this.component.get(workingTimestamp);
82481
+ if (!regions2 || !regions2.regions) {
82482
+ break;
82483
+ }
82484
+ if (!last) {
82485
+ last = regions2.regions.map(function(r3) {
82486
+ return r3.id;
82487
+ });
82488
+ result = _to_consumable_array(regions2.regions);
82489
+ }
82490
+ var validRegions = regions2.regions.filter(function(reg) {
82491
+ return last === null || last === void 0 ? void 0 : last.includes(reg.id);
82492
+ });
82493
+ if (validRegions.length <= 0) {
82494
+ break;
82495
+ }
82496
+ var duration = 0;
82497
+ if (regions2.timestamp_start < workingTimestamp) {
82498
+ duration = regions2.timestamp_end - workingTimestamp;
82499
+ } else {
82500
+ duration = regions2.timestamp_end - regions2.timestamp_start;
82501
+ }
82502
+ totalDuration += duration;
82503
+ workingTimestamp = regions2.timestamp_end + 0.01;
82504
+ last = validRegions.map(function(r3) {
82505
+ return r3.id;
82506
+ });
82507
+ result = _to_consumable_array(validRegions);
82508
+ }while (true);
82509
+ if (!result || totalDuration < this.params.minDuration) {
82510
+ return null;
82511
+ }
82512
+ return {
82513
+ timestamp_start: timestamp,
82514
+ timestamp_end: timestamp + totalDuration,
82515
+ regions: result
82516
+ };
82517
+ }
82518
+ }
82519
+ ]);
82520
+ return VideoRegionsMaxDurationDecorator;
82521
+ }(VideoRegionsDataManagerDecorator);
82522
+ var VideoRegionsTypeFilterDecorator = /*#__PURE__*/ function(VideoRegionsDataManagerDecorator) {
82523
+ "use strict";
82524
+ _inherits(VideoRegionsTypeFilterDecorator, VideoRegionsDataManagerDecorator);
82525
+ function VideoRegionsTypeFilterDecorator(component, params) {
82526
+ _class_call_check(this, VideoRegionsTypeFilterDecorator);
82527
+ var _this;
82528
+ _this = _call_super(this, VideoRegionsTypeFilterDecorator, [
82529
+ component
82530
+ ]);
82531
+ if (params && params.value && Array.isArray(params.value)) {
82532
+ var _params_setting_constraints;
82533
+ var regionsMap = ((_params_setting_constraints = params.setting.constraints) === null || _params_setting_constraints === void 0 ? void 0 : _params_setting_constraints.mapped_allowed_values_ids) || {};
82534
+ _this.allowedRegions = params.value.map(function(r3) {
82535
+ return regionsMap[r3];
82536
+ }).filter(Boolean);
82537
+ }
82538
+ return _this;
82539
+ }
82540
+ _create_class(VideoRegionsTypeFilterDecorator, [
82541
+ {
82542
+ key: "check",
82543
+ value: function check(timestamp) {
82544
+ var _this = this;
82545
+ var data = this.component.check(timestamp);
82546
+ if (this.allowedRegions !== void 0 && data && data.regions) {
82547
+ data.regions = data.regions.filter(function(region) {
82548
+ var _this_allowedRegions;
82549
+ return (_this_allowedRegions = _this.allowedRegions) === null || _this_allowedRegions === void 0 ? void 0 : _this_allowedRegions.includes(region.id);
82550
+ });
82551
+ }
82552
+ return data;
82553
+ }
82554
+ },
82555
+ {
82556
+ key: "get",
82557
+ value: function get(timestamp) {
82558
+ var _this = this;
82559
+ var data = this.component.get(timestamp);
82560
+ if (this.allowedRegions !== void 0 && data && data.regions) {
82561
+ data.regions = data.regions.filter(function(region) {
82562
+ var _this_allowedRegions;
82563
+ return (_this_allowedRegions = _this.allowedRegions) === null || _this_allowedRegions === void 0 ? void 0 : _this_allowedRegions.includes(region.id);
82564
+ });
82565
+ }
82566
+ return data;
82567
+ }
82568
+ }
82569
+ ]);
82570
+ return VideoRegionsTypeFilterDecorator;
82571
+ }(VideoRegionsDataManagerDecorator);
82572
+ var VideoRegionsDecoratorFactory = /*#__PURE__*/ function() {
82573
+ "use strict";
82574
+ function VideoRegionsDecoratorFactory() {
82575
+ _class_call_check(this, VideoRegionsDecoratorFactory);
82576
+ }
82577
+ _create_class(VideoRegionsDecoratorFactory, null, [
82578
+ {
82579
+ key: "decorate",
82580
+ value: function decorate(component, params) {
82581
+ var _params_visibility_duration, _params_minimum_display_time, _params_ad_placements_and_sizes;
82582
+ var target = component;
82583
+ if (!params) {
82584
+ return target;
82585
+ }
82586
+ if ((_params_visibility_duration = params.visibility_duration) === null || _params_visibility_duration === void 0 ? void 0 : _params_visibility_duration.value) {
82587
+ target = new VideoRegionsDurationDecorator(target, {
82588
+ duration: params.visibility_duration.value
82589
+ });
82590
+ } else if ((_params_minimum_display_time = params.minimum_display_time) === null || _params_minimum_display_time === void 0 ? void 0 : _params_minimum_display_time.value) {
82591
+ target = new VideoRegionsMaxDurationDecorator(target, {
82592
+ minDuration: params.minimum_display_time.value
82593
+ });
82594
+ }
82595
+ if ((_params_ad_placements_and_sizes = params.ad_placements_and_sizes) === null || _params_ad_placements_and_sizes === void 0 ? void 0 : _params_ad_placements_and_sizes.value) {
82596
+ target = new VideoRegionsTypeFilterDecorator(target, params.ad_placements_and_sizes);
82597
+ }
82598
+ return target;
82599
+ }
82600
+ }
82601
+ ]);
82602
+ return VideoRegionsDecoratorFactory;
82603
+ }();
82604
+ // src/Ads/VideoAds/VideoAd.ts
82605
+ var VideoAd = /*#__PURE__*/ function() {
82606
+ "use strict";
82607
+ function VideoAd(context, target) {
82608
+ _class_call_check(this, VideoAd);
82609
+ this.handleInfo = this.handleInfo.bind(this);
82610
+ this.context = context;
82611
+ var videoAdContext = {
82612
+ config: context.config,
82503
82613
  elements: {
82504
82614
  container: null,
82505
82615
  original: null,
@@ -82568,7 +82678,8 @@ var VideoAd = /*#__PURE__*/ function() {
82568
82678
  }, {
82569
82679
  logger: this.videoAdContext.logger,
82570
82680
  // @ts-expect-error
82571
- service: this.videoAdContext.service.join("".concat(data.video, "-").concat(this.videoAdContext.config.getStrategy().code))
82681
+ service: this.videoAdContext.service.join("".concat(data.video, "-").concat(this.videoAdContext.config.getStrategy().code)),
82682
+ config: this.videoAdContext.config
82572
82683
  });
82573
82684
  this.videoAdContext.store.dispatch({
82574
82685
  type: "UPDATE_VIDEO_INFO",
@@ -82633,6 +82744,7 @@ var VideoAd = /*#__PURE__*/ function() {
82633
82744
  key: "updateRegionData",
82634
82745
  value: function updateRegionData() {
82635
82746
  var _this = this;
82747
+ var _this_presentation;
82636
82748
  if (this.videoRegions) {
82637
82749
  var _this_videoRegions;
82638
82750
  (_this_videoRegions = this.videoRegions) === null || _this_videoRegions === void 0 ? void 0 : _this_videoRegions.destroy();
@@ -82641,10 +82753,7 @@ var VideoAd = /*#__PURE__*/ function() {
82641
82753
  this.videoAdContext.recorder.destroy();
82642
82754
  this.videoAdContext.recorder = void 0;
82643
82755
  }
82644
- if (this.presentation) {
82645
- this.presentation.destroy();
82646
- this.presentation = void 0;
82647
- }
82756
+ (_this_presentation = this.presentation) === null || _this_presentation === void 0 ? void 0 : _this_presentation.stop();
82648
82757
  this.context.service.send("hs", {
82649
82758
  source: this.videoAdContext.media.source,
82650
82759
  strategy: this.videoAdContext.config.getStrategy().code
@@ -82662,7 +82771,8 @@ var VideoAd = /*#__PURE__*/ function() {
82662
82771
  }
82663
82772
  }, {
82664
82773
  logger: _this.videoAdContext.logger,
82665
- service: _this.context.service.join("".concat(data.video, "-").concat(_this.videoAdContext.config.getStrategy().code))
82774
+ service: _this.context.service.join("".concat(data.video, "-").concat(_this.videoAdContext.config.getStrategy().code)),
82775
+ config: _this.videoAdContext.config
82666
82776
  });
82667
82777
  _this.videoAdContext.store.dispatch({
82668
82778
  type: "UPDATE_VIDEO_INFO",
@@ -82673,15 +82783,12 @@ var VideoAd = /*#__PURE__*/ function() {
82673
82783
  }
82674
82784
  });
82675
82785
  _this.videoRegions = VideoRegionsDecoratorFactory.decorate(videoRegions, _this.videoAdContext.config.getStrategySettings());
82676
- _this.presentation = _this.presentationFactory.get({
82677
- strategy: _this.videoAdContext.config.getStrategy().code
82678
- });
82679
82786
  _this.videoAdContext.data = _this.videoRegions;
82680
82787
  _this.videoAdContext.recorder = _this.recorderFactory.create(_this.videoAdContext.media, {
82681
82788
  id: data.video,
82682
82789
  ts: 0
82683
82790
  });
82684
- (_this_presentation = _this.presentation) === null || _this_presentation === void 0 ? void 0 : _this_presentation.setup();
82791
+ (_this_presentation = _this.presentation) === null || _this_presentation === void 0 ? void 0 : _this_presentation.start();
82685
82792
  });
82686
82793
  }
82687
82794
  },
@@ -83197,8 +83304,157 @@ var Location = /*#__PURE__*/ function() {
83197
83304
  ]);
83198
83305
  return Location;
83199
83306
  }();
83200
- // src/Service/Realtime.ts
83307
+ // src/Service/LocalRealtime.ts
83201
83308
  var import_events10 = __toESM(require_events());
83309
+ var DATA_STORE = {
83310
+ "video1": {}
83311
+ };
83312
+ var VIDEO_LIBRARY = {
83313
+ "video1": {
83314
+ source: ""
83315
+ }
83316
+ };
83317
+ var BRNDTSLocalRealtime = /*#__PURE__*/ function(_import_events10_default) {
83318
+ "use strict";
83319
+ _inherits(BRNDTSLocalRealtime, _import_events10_default);
83320
+ function BRNDTSLocalRealtime(options, deps) {
83321
+ _class_call_check(this, BRNDTSLocalRealtime);
83322
+ var _this;
83323
+ _this = _call_super(this, BRNDTSLocalRealtime);
83324
+ _this.connected = new Changeable(false);
83325
+ _this.handlers = {
83326
+ info: [],
83327
+ result: [],
83328
+ completed: [],
83329
+ aborted: []
83330
+ };
83331
+ _this.options = options;
83332
+ _this.logger = deps.logger;
83333
+ if (!_this.options.ns) {
83334
+ window.__brndts_local_realtime = _this;
83335
+ }
83336
+ return _this;
83337
+ }
83338
+ _create_class(BRNDTSLocalRealtime, [
83339
+ {
83340
+ key: "handleOpen",
83341
+ value: function handleOpen() {
83342
+ this.connected.value = true;
83343
+ this.emit("connected");
83344
+ }
83345
+ },
83346
+ {
83347
+ key: "handleClose",
83348
+ value: function handleClose() {
83349
+ this.connected.value = false;
83350
+ this.emit("disconnected");
83351
+ }
83352
+ },
83353
+ {
83354
+ key: "connect",
83355
+ value: function connect() {
83356
+ this.handleOpen();
83357
+ }
83358
+ },
83359
+ {
83360
+ key: "respond",
83361
+ value: function respond(event, payload) {
83362
+ if (this.handlers[event]) {
83363
+ this.handlers[event].forEach(function(handler) {
83364
+ handler(payload);
83365
+ });
83366
+ }
83367
+ }
83368
+ },
83369
+ {
83370
+ key: "loads",
83371
+ value: function loads(videoId) {
83372
+ var _this = this;
83373
+ var _this_logger;
83374
+ (_this_logger = this.logger) === null || _this_logger === void 0 ? void 0 : _this_logger.log("[REALTIME LOCAL] Loading data for :", videoId);
83375
+ var input = document.createElement("input");
83376
+ input.type = "file";
83377
+ input === null || input === void 0 ? void 0 : input.addEventListener("change", function(event) {
83378
+ var _input_files;
83379
+ var file = input === null || input === void 0 ? void 0 : (_input_files = input.files) === null || _input_files === void 0 ? void 0 : _input_files[0];
83380
+ if (!file) {
83381
+ console.log("No file selected.");
83382
+ return;
83383
+ }
83384
+ var reader = new FileReader();
83385
+ reader.onload = function(event2) {
83386
+ var _event2_target;
83387
+ var fileContent = event2 === null || event2 === void 0 ? void 0 : (_event2_target = event2.target) === null || _event2_target === void 0 ? void 0 : _event2_target.result;
83388
+ if (fileContent) {
83389
+ var _this_logger;
83390
+ var parsedData = JSON.parse(fileContent);
83391
+ DATA_STORE[videoId] = parsedData;
83392
+ (_this_logger = _this.logger) === null || _this_logger === void 0 ? void 0 : _this_logger.log("[REALTIME LOCAL] Loaded data for :", videoId);
83393
+ _this.respond("result", DATA_STORE[videoId]);
83394
+ }
83395
+ };
83396
+ reader.readAsText(file);
83397
+ });
83398
+ input.click();
83399
+ }
83400
+ },
83401
+ {
83402
+ key: "send",
83403
+ value: function send(event) {
83404
+ for(var _len = arguments.length, payload = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
83405
+ payload[_key - 1] = arguments[_key];
83406
+ }
83407
+ var _this_logger;
83408
+ (_this_logger = this.logger) === null || _this_logger === void 0 ? void 0 : _this_logger.log("[REALTIME LOCAL] Received event :", event, payload);
83409
+ if (event === "hs") {
83410
+ var _this_logger1;
83411
+ (_this_logger1 = this.logger) === null || _this_logger1 === void 0 ? void 0 : _this_logger1.log("[REALTIME LOCAL] handling event :", event, payload);
83412
+ var _payload = _sliced_to_array(payload, 2), data = _payload[0], cb = _payload[1];
83413
+ var videoId = "video1";
83414
+ VIDEO_LIBRARY[videoId] = {
83415
+ // @ts-expect-error
83416
+ source: data.source
83417
+ };
83418
+ cb === null || cb === void 0 ? void 0 : cb({
83419
+ video: videoId
83420
+ });
83421
+ }
83422
+ }
83423
+ },
83424
+ {
83425
+ key: "handle",
83426
+ value: function handle(event, handler) {
83427
+ if (!this.handlers[event]) {
83428
+ this.handlers[event] = [];
83429
+ }
83430
+ this.handlers[event].push(handler);
83431
+ }
83432
+ },
83433
+ {
83434
+ key: "join",
83435
+ value: function join(ns) {
83436
+ var _this = this;
83437
+ setTimeout(function() {
83438
+ var _ref = _sliced_to_array(ns.match(/^([^-]+)-(.+)$/) || [], 2), video = _ref[0], strategy = _ref[1];
83439
+ if (video && DATA_STORE[video]) {
83440
+ var regions2 = DATA_STORE[video];
83441
+ _this.respond("result", regions2);
83442
+ }
83443
+ }, 150);
83444
+ return this;
83445
+ }
83446
+ },
83447
+ {
83448
+ key: "destroy",
83449
+ value: function destroy() {
83450
+ this.handleClose();
83451
+ }
83452
+ }
83453
+ ]);
83454
+ return BRNDTSLocalRealtime;
83455
+ }(import_events10.default);
83456
+ // src/Service/Realtime.ts
83457
+ var import_events11 = __toESM(require_events());
83202
83458
  // node_modules/engine.io-parser/build/esm/commons.js
83203
83459
  var PACKET_TYPES = /* @__PURE__ */ Object.create(null);
83204
83460
  PACKET_TYPES["open"] = "0";
@@ -87063,9 +87319,9 @@ Object.assign(lookup2, {
87063
87319
  connect: lookup2
87064
87320
  });
87065
87321
  // src/Service/Realtime.ts
87066
- var BRNDTSRealtime = /*#__PURE__*/ function(_import_events10_default) {
87322
+ var BRNDTSRealtime = /*#__PURE__*/ function(_import_events11_default) {
87067
87323
  "use strict";
87068
- _inherits(_BRNDTSRealtime, _import_events10_default);
87324
+ _inherits(_BRNDTSRealtime, _import_events11_default);
87069
87325
  function _BRNDTSRealtime(options, deps) {
87070
87326
  _class_call_check(this, _BRNDTSRealtime);
87071
87327
  var _this;
@@ -87163,9 +87419,37 @@ var BRNDTSRealtime = /*#__PURE__*/ function(_import_events10_default) {
87163
87419
  }
87164
87420
  ]);
87165
87421
  return _BRNDTSRealtime;
87166
- }(import_events10.default);
87167
- // src/Service/LocalRealtime.ts
87168
- var import_events11 = __toESM(require_events());
87422
+ }(import_events11.default);
87423
+ // src/Service/ServiceFactory.ts
87424
+ var ServiceFactory = /*#__PURE__*/ function() {
87425
+ "use strict";
87426
+ function ServiceFactory() {
87427
+ _class_call_check(this, ServiceFactory);
87428
+ }
87429
+ _create_class(ServiceFactory, null, [
87430
+ {
87431
+ key: "createService",
87432
+ value: function createService(context) {
87433
+ var serviceType = "remote";
87434
+ if (serviceType === "local") {
87435
+ return new BRNDTSLocalRealtime({
87436
+ host: context.config.get("host"),
87437
+ key: context.config.get("key")
87438
+ }, {
87439
+ logger: context.logger
87440
+ });
87441
+ }
87442
+ return new BRNDTSRealtime({
87443
+ host: context.config.get("host"),
87444
+ key: context.config.get("key")
87445
+ }, {
87446
+ logger: context.logger
87447
+ });
87448
+ }
87449
+ }
87450
+ ]);
87451
+ return ServiceFactory;
87452
+ }();
87169
87453
  // src/index.ts
87170
87454
  var BrndtsAds = /*#__PURE__*/ function() {
87171
87455
  "use strict";
@@ -87218,10 +87502,16 @@ var BrndtsAds = /*#__PURE__*/ function() {
87218
87502
  case 1:
87219
87503
  _state.trys.push([
87220
87504
  1,
87221
- 3,
87505
+ 4,
87222
87506
  ,
87223
- 4
87507
+ 5
87224
87508
  ]);
87509
+ if (!this.context.config.get("enabled")) {
87510
+ this.context.logger.error("Setup failed: disabled by config");
87511
+ return [
87512
+ 2
87513
+ ];
87514
+ }
87225
87515
  this.context.location = new Location();
87226
87516
  this.context.consent = ConsentFactory.get(this.context.logger);
87227
87517
  return [
@@ -87232,35 +87522,30 @@ var BrndtsAds = /*#__PURE__*/ function() {
87232
87522
  _state.sent();
87233
87523
  this.context.user = new User(this.context.config, this.context.consent);
87234
87524
  this.context.device = new Device();
87235
- this.context.device.collect();
87236
- if (!this.context.config.get("enabled")) {
87237
- this.context.logger.error("Setup failed: disabled by config");
87238
- return [
87239
- 2
87240
- ];
87241
- }
87242
- this.context.service = new BRNDTSRealtime({
87243
- host: this.context.config.get("host"),
87244
- key: this.context.config.get("key")
87245
- }, {
87246
- logger: this.context.logger
87247
- });
87525
+ return [
87526
+ 4,
87527
+ this.context.device.collect()
87528
+ ];
87529
+ case 3:
87530
+ _state.sent();
87531
+ console.log("BRNDTS Ads Presenter started with config");
87532
+ this.context.service = ServiceFactory.createService(this.context);
87248
87533
  this.context.service.on("connected", this.handleConnected);
87249
87534
  this.context.service.connect();
87250
87535
  return [
87251
87536
  3,
87252
- 4
87537
+ 5
87253
87538
  ];
87254
- case 3:
87539
+ case 4:
87255
87540
  error = _state.sent();
87256
87541
  if (_instanceof(error, Error)) {
87257
- this.context.logger.warn("Setup failed: no media element found!");
87542
+ console.log("Error during setup: ", error);
87258
87543
  }
87259
87544
  return [
87260
87545
  3,
87261
- 4
87546
+ 5
87262
87547
  ];
87263
- case 4:
87548
+ case 5:
87264
87549
  return [
87265
87550
  2
87266
87551
  ];