@brndts/brndts-ads 1.13.5 → 1.13.7

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
@@ -67456,6 +67456,17 @@ var Awaitable = /*#__PURE__*/ function() {
67456
67456
  });
67457
67457
  }
67458
67458
  _create_class(Awaitable, [
67459
+ {
67460
+ key: "reset",
67461
+ value: function reset(value2) {
67462
+ var _this = this;
67463
+ this._value = value2;
67464
+ this._promise = new Promise(function(resolve, reject) {
67465
+ _this._resolve = resolve;
67466
+ _this._reject = reject;
67467
+ });
67468
+ }
67469
+ },
67459
67470
  {
67460
67471
  key: "value",
67461
67472
  get: function get() {
@@ -69821,6 +69832,7 @@ var AffiliateProvider = /*#__PURE__*/ function(ContentProvider1) {
69821
69832
  image.style.height = affiliate.size.h + "px";
69822
69833
  image.style.maxWidth = affiliate.size.w + "px";
69823
69834
  image.style.maxHeight = affiliate.size.h + "px";
69835
+ image.style.display = "block";
69824
69836
  image.setAttribute("src", affiliate.img);
69825
69837
  if (affiliate.url) {
69826
69838
  image.addEventListener("click", function() {
@@ -71293,10 +71305,16 @@ var RegionContent = /*#__PURE__*/ function() {
71293
71305
  this.container.dataset.state = this.box.area(this.plane.size) > 0 ? "visible" : "hidden";
71294
71306
  }
71295
71307
  },
71308
+ {
71309
+ key: "hide",
71310
+ value: function hide() {
71311
+ this.container.dataset.state = "hidden";
71312
+ }
71313
+ },
71296
71314
  {
71297
71315
  key: "clear",
71298
71316
  value: function clear() {
71299
- this.container.dataset.state = "hidden";
71317
+ this.hide();
71300
71318
  this.content = void 0;
71301
71319
  this.scale = null;
71302
71320
  }
@@ -71604,6 +71622,7 @@ var Region = /*#__PURE__*/ function() {
71604
71622
  this.onScreen = false;
71605
71623
  this.visible = false;
71606
71624
  this.plugins = [];
71625
+ this.hidden = new Awaitable(false);
71607
71626
  this.id = id;
71608
71627
  this.regionDescriptor = regionDescriptor;
71609
71628
  this.options = options;
@@ -72231,19 +72250,6 @@ var StaticAdRegion = /*#__PURE__*/ function(Region) {
72231
72250
  return StaticAdRegion;
72232
72251
  }(Region);
72233
72252
  // src/Ads/StaticAds/StaticAds.ts
72234
- function debounce3(func) {
72235
- var timeout = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 100;
72236
- var timer;
72237
- return function() {
72238
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
72239
- args[_key] = arguments[_key];
72240
- }
72241
- clearTimeout(timer);
72242
- timer = setTimeout(function() {
72243
- func.apply(void 0, _to_consumable_array(args));
72244
- }, timeout);
72245
- };
72246
- }
72247
72253
  function isElementVisible(element) {
72248
72254
  if (!element) return false;
72249
72255
  if (!document.contains(element)) return false;
@@ -72261,7 +72267,6 @@ var StaticAds = /*#__PURE__*/ function() {
72261
72267
  this.handlePageMutation = this.handlePageMutation.bind(this);
72262
72268
  this.context = context;
72263
72269
  this.recorderFactory = new RecorderFactory(this.context);
72264
- this.observer = new MutationObserver(debounce3(this.handlePageMutation));
72265
72270
  }
72266
72271
  _create_class(StaticAds, [
72267
72272
  {
@@ -72363,16 +72368,11 @@ var StaticAds = /*#__PURE__*/ function() {
72363
72368
  value: function start() {
72364
72369
  this.context.logger.log("starting static ads");
72365
72370
  this.handleRegions();
72366
- this.observer.observe(document.body, {
72367
- childList: true,
72368
- subtree: true
72369
- });
72370
72371
  }
72371
72372
  },
72372
72373
  {
72373
72374
  key: "destroy",
72374
72375
  value: function destroy() {
72375
- this.observer.disconnect();
72376
72376
  this.context.logger.log("destroying static ads");
72377
72377
  this.regions.forEach(function(region) {
72378
72378
  region.destroy();
@@ -80280,20 +80280,52 @@ var DefaultTemplate = /*#__PURE__*/ function() {
80280
80280
  "use strict";
80281
80281
  function DefaultTemplate() {
80282
80282
  _class_call_check(this, DefaultTemplate);
80283
+ this.margin = {
80284
+ t: 0,
80285
+ r: 0,
80286
+ b: 64,
80287
+ l: 0
80288
+ };
80283
80289
  }
80284
80290
  _create_class(DefaultTemplate, [
80285
80291
  {
80292
+ // get(plane: Plane.Descriptor, cutout: Cutout): PackingRegion[] {
80293
+ // const areas = [];
80294
+ // // Region A: Right strip (cutout height)
80295
+ // if (plane.width - (cutout.x + cutout.width) > 0) {
80296
+ // areas.push({
80297
+ // dimensions: new Dimensions(
80298
+ // { x: this.margin.l + cutout.x + cutout.width, y: this.margin.t + 0 },
80299
+ // { width: plane.width - (this.margin.l+this.margin.r) - (cutout.x + cutout.width), height: cutout.y + cutout.height }
80300
+ // ),
80301
+ // name: 'A',
80302
+ // maxSlots: 3, // Maximum slots for this region
80303
+ // });
80304
+ // }
80305
+ // // Region B: bottom-left strip (excluding cutout)
80306
+ // if (plane.height - (cutout.y + cutout.height) > 0) {
80307
+ // areas.push({
80308
+ // dimensions: new Dimensions(
80309
+ // { x: this.margin.l + 0, y: cutout.y + cutout.height },
80310
+ // { width: plane.width - (this.margin.l + this.margin.r), height: plane.height - (this.margin.t + this.margin.b) - (cutout.y + cutout.height) }
80311
+ // ),
80312
+ // name: 'B',
80313
+ // maxSlots: 1, // Maximum slots for this region
80314
+ // });
80315
+ // }
80316
+ // return areas;
80317
+ // }
80286
80318
  key: "get",
80287
80319
  value: function get(plane, cutout) {
80288
80320
  var areas = [];
80289
80321
  if (plane.width - (cutout.x + cutout.width) > 0) {
80290
80322
  areas.push({
80291
80323
  dimensions: new Dimensions({
80292
- x: cutout.x + cutout.width,
80293
- y: 0
80324
+ x: this.margin.l + cutout.x + cutout.width,
80325
+ y: this.margin.t + 0
80294
80326
  }, {
80295
80327
  width: plane.width - (cutout.x + cutout.width),
80296
- height: cutout.y + cutout.height
80328
+ height: plane.height - (this.margin.t + this.margin.b)
80297
80329
  }),
80298
80330
  name: "A",
80299
80331
  maxSlots: 3
@@ -80302,12 +80334,14 @@ var DefaultTemplate = /*#__PURE__*/ function() {
80302
80334
  if (plane.height - (cutout.y + cutout.height) > 0) {
80303
80335
  areas.push({
80304
80336
  dimensions: new Dimensions({
80305
- x: 0,
80306
- y: cutout.y + cutout.height
80337
+ x: this.margin.l + 0,
80338
+ y: this.margin.t + cutout.y + cutout.height
80307
80339
  }, {
80308
- width: plane.width,
80309
- height: plane.height - (cutout.y + cutout.height)
80340
+ width: cutout.x + cutout.width,
80341
+ height: plane.height - (this.margin.t + this.margin.b) - (cutout.y + cutout.height)
80310
80342
  }),
80343
+ available: {
80344
+ },
80311
80345
  name: "B",
80312
80346
  maxSlots: 1
80313
80347
  });
@@ -80322,6 +80356,12 @@ var FullscreenTemplate = /*#__PURE__*/ function() {
80322
80356
  "use strict";
80323
80357
  function FullscreenTemplate() {
80324
80358
  _class_call_check(this, FullscreenTemplate);
80359
+ this.margin = {
80360
+ t: 0,
80361
+ r: 0,
80362
+ b: 64,
80363
+ l: 0
80364
+ };
80325
80365
  }
80326
80366
  _create_class(FullscreenTemplate, [
80327
80367
  {
@@ -80331,11 +80371,11 @@ var FullscreenTemplate = /*#__PURE__*/ function() {
80331
80371
  if (plane.width - (cutout.x + cutout.width) > 0) {
80332
80372
  areas.push({
80333
80373
  dimensions: new Dimensions({
80334
- x: cutout.x + cutout.width,
80335
- y: 0
80374
+ x: this.margin.l + cutout.x + cutout.width,
80375
+ y: this.margin.t + 0
80336
80376
  }, {
80337
80377
  width: plane.width - (cutout.x + cutout.width),
80338
- height: plane.height
80378
+ height: plane.height - (this.margin.t + this.margin.b)
80339
80379
  }),
80340
80380
  name: "A",
80341
80381
  maxSlots: 3
@@ -80344,11 +80384,11 @@ var FullscreenTemplate = /*#__PURE__*/ function() {
80344
80384
  if (plane.height - (cutout.y + cutout.height) > 0) {
80345
80385
  areas.push({
80346
80386
  dimensions: new Dimensions({
80347
- x: 0,
80348
- y: cutout.y + cutout.height
80387
+ x: this.margin.l + 0,
80388
+ y: this.margin.t + cutout.y + cutout.height
80349
80389
  }, {
80350
80390
  width: cutout.x + cutout.width,
80351
- height: plane.height - (cutout.y + cutout.height)
80391
+ height: plane.height - (this.margin.t + this.margin.b) - (cutout.y + cutout.height)
80352
80392
  }),
80353
80393
  available: {
80354
80394
  w: 0.7
@@ -80725,10 +80765,11 @@ var BasicAdRegion = /*#__PURE__*/ function(Region) {
80725
80765
  key: "hideRegion",
80726
80766
  value: function hideRegion() {
80727
80767
  return _async_to_generator(function() {
80728
- var _this_deps_recorder;
80729
80768
  return _ts_generator(this, function(_state) {
80730
80769
  switch(_state.label){
80731
80770
  case 0:
80771
+ this.hidden.reset(false);
80772
+ this.content.hide();
80732
80773
  return [
80733
80774
  4,
80734
80775
  this.applyPlugins("beforeHide")
@@ -80741,7 +80782,7 @@ var BasicAdRegion = /*#__PURE__*/ function(Region) {
80741
80782
  this.content.clear();
80742
80783
  this.applyPlugins("afterHide");
80743
80784
  this.visible = false;
80744
- (_this_deps_recorder = this.deps.recorder) === null || _this_deps_recorder === void 0 ? void 0 : _this_deps_recorder.presentationStateChanged(this, true);
80785
+ this.hidden.resolve(true);
80745
80786
  return [
80746
80787
  2
80747
80788
  ];
@@ -80750,30 +80791,40 @@ var BasicAdRegion = /*#__PURE__*/ function(Region) {
80750
80791
  }).call(this);
80751
80792
  }
80752
80793
  },
80794
+ {
80795
+ key: "showRegion",
80796
+ value: function showRegion() {
80797
+ return _async_to_generator(function() {
80798
+ var _this_deps_recorder;
80799
+ return _ts_generator(this, function(_state) {
80800
+ this.applyPlugins("beforeShow");
80801
+ this.container.style.display = "block";
80802
+ this.container.style.position = "relative";
80803
+ this.container.style.width = "".concat(this.box.width(this.plane.size), "px");
80804
+ this.container.style.height = "".concat(this.box.height(this.plane.size), "px");
80805
+ this.content.render();
80806
+ this.applyPlugins("afterShow");
80807
+ this.visible = true;
80808
+ (_this_deps_recorder = this.deps.recorder) === null || _this_deps_recorder === void 0 ? void 0 : _this_deps_recorder.presentationStateChanged(this, true);
80809
+ return [
80810
+ 2
80811
+ ];
80812
+ });
80813
+ }).call(this);
80814
+ }
80815
+ },
80753
80816
  {
80754
80817
  key: "render",
80755
80818
  value: function render(contours, box) {
80756
80819
  return _async_to_generator(function() {
80757
- var _this_deps_recorder;
80758
80820
  return _ts_generator(this, function(_state) {
80759
80821
  this.applyPlugins("beforeRender");
80760
80822
  if (this.shouldPresent()) {
80761
- ;
80762
- this.applyPlugins("beforeShow");
80763
- this.container.style.display = "block";
80764
- this.container.style.position = "relative";
80765
- this.container.style.width = "".concat(this.box.width(this.plane.size), "px");
80766
- this.container.style.height = "".concat(this.box.height(this.plane.size), "px");
80767
- this.content.render();
80768
- this.applyPlugins("afterShow");
80769
- this.visible = true;
80770
- (_this_deps_recorder = this.deps.recorder) === null || _this_deps_recorder === void 0 ? void 0 : _this_deps_recorder.presentationStateChanged(this, true);
80823
+ this.showRegion();
80771
80824
  } else if (this.shouldHide()) {
80772
80825
  this.hideRegion();
80773
80826
  } else {
80774
80827
  if (this.visible) {
80775
- this.container.style.width = "".concat(this.box.width(this.plane.size), "px");
80776
- this.container.style.height = "".concat(this.box.height(this.plane.size), "px");
80777
80828
  this.applyPlugins("reRender");
80778
80829
  }
80779
80830
  }
@@ -80785,48 +80836,6 @@ var BasicAdRegion = /*#__PURE__*/ function(Region) {
80785
80836
  }).call(this);
80786
80837
  }
80787
80838
  },
80788
- {
80789
- key: "shouldRequestContent",
80790
- value: function shouldRequestContent(newBox) {
80791
- if (this.box.area({
80792
- width: 1,
80793
- height: 1
80794
- }) <= 0 && newBox.area({
80795
- width: 1,
80796
- height: 1
80797
- }) > 0) {
80798
- return true;
80799
- }
80800
- if (this.box.isEqual(newBox.coords)) {
80801
- return false;
80802
- }
80803
- if (newBox.area(this.plane.size) <= 0) {
80804
- return false;
80805
- }
80806
- if (newBox.area(this.plane.size) === this.box.area(this.plane.size)) {
80807
- return false;
80808
- }
80809
- if (Math.abs(newBox.area({
80810
- width: 1,
80811
- height: 1
80812
- }) - this.box.area({
80813
- width: 1,
80814
- height: 1
80815
- })) < 0.05) {
80816
- return false;
80817
- }
80818
- if (Math.abs(newBox.aspectRatio({
80819
- width: 1,
80820
- height: 1
80821
- }) - this.box.aspectRatio({
80822
- width: 1,
80823
- height: 1
80824
- })) > 0.05) {
80825
- return false;
80826
- }
80827
- return true;
80828
- }
80829
- },
80830
80839
  {
80831
80840
  key: "updateSize",
80832
80841
  value: function updateSize(width, height) {
@@ -80856,7 +80865,10 @@ var BasicAdRegion = /*#__PURE__*/ function(Region) {
80856
80865
  value: function clear() {
80857
80866
  var _this = this;
80858
80867
  this.hideRegion().then(function() {
80859
- _this.updateSize(0, 0);
80868
+ _this.plane.update({
80869
+ width: 0,
80870
+ height: 0
80871
+ });
80860
80872
  });
80861
80873
  }
80862
80874
  }
@@ -81049,83 +81061,116 @@ var AdRegionsArea = /*#__PURE__*/ function() {
81049
81061
  {
81050
81062
  key: "render",
81051
81063
  value: function render(regions2) {
81052
- if (!regions2 || !regions2.length) {
81053
- this.clear();
81054
- return;
81055
- }
81056
- var mapped = new MappedCollection();
81057
- mapped.load(regions2);
81058
- var visibleRegions = this.regionsObjects.getVisible();
81059
- var diffLeft = getDifferenceLeft(visibleRegions, regions2);
81060
- var diffRight = getDifferenceRight(visibleRegions, regions2);
81061
- var common = getIntersection(visibleRegions, regions2);
81062
- for(var index = 0; index < diffLeft.length; index++){
81063
- var existingObject = this.regionsObjects.getById(diffLeft[index].id);
81064
- if (existingObject) {
81065
- existingObject.clear();
81066
- }
81067
- }
81068
- if (common.length) {
81069
- for(var index1 = 0; index1 < common.length; index1++){
81070
- if (index1 < this.maxRegions) {
81071
- var pack = mapped.getById(common[index1].id);
81072
- if (pack) {
81073
- common[index1].updateSize(pack.width, pack.height);
81074
- }
81075
- } else {
81076
- common[index1].clear();
81077
- }
81078
- }
81079
- } else {
81080
- for(var index2 = 0; index2 < diffRight.length && index2 < this.maxRegions; index2++){
81081
- var existingObject1 = this.regionsObjects.getById(diffRight[index2].id);
81082
- if (existingObject1) {
81083
- var pack1 = mapped.getById(diffRight[index2].id);
81084
- if (pack1) {
81085
- existingObject1.updateSize(pack1.width, pack1.height);
81086
- }
81087
- } else {
81088
- var region = diffRight[index2];
81089
- var provider = ContentProviderFactory.getProvider(this.context, this.context.config.get("ads").provider);
81090
- var plugins2 = [
81091
- // new RegionBorderPlugin(),
81092
- new RegionAnimationPlugin("OPACITY")
81093
- ];
81094
- var newRegion = new BasicAdRegion(region.id, {
81095
- width: region.width,
81096
- height: region.height
81097
- }, {
81098
- ad: {
81099
- type: region.type,
81100
- name: region.region
81064
+ return _async_to_generator(function() {
81065
+ var mapped, visibleRegions, diffLeft, diffRight, pending, common, index, existingObject2, index1, pack, index2, existingObject21, pack1, region, provider, plugins2, newRegion;
81066
+ return _ts_generator(this, function(_state) {
81067
+ switch(_state.label){
81068
+ case 0:
81069
+ if (!regions2 || !regions2.length) {
81070
+ this.clear();
81071
+ return [
81072
+ 2
81073
+ ];
81101
81074
  }
81102
- }, {
81103
- provider: provider,
81104
- plugins: plugins2,
81105
- recorder: this.context.recorder
81106
- });
81107
- this.regionsObjects.push(newRegion);
81108
- this.regionsContainerView.append(newRegion.view);
81109
- this.intersectionObserver.observe(newRegion.view);
81075
+ mapped = new MappedCollection();
81076
+ mapped.load(regions2);
81077
+ visibleRegions = this.regionsObjects.getVisible();
81078
+ diffLeft = getDifferenceLeft(visibleRegions, regions2);
81079
+ diffRight = getDifferenceRight(visibleRegions, regions2);
81080
+ pending = [];
81081
+ common = getIntersection(visibleRegions, regions2);
81082
+ for(index = 0; index < diffLeft.length; index++){
81083
+ existingObject2 = this.regionsObjects.getById(diffLeft[index].id);
81084
+ if (existingObject2) {
81085
+ existingObject2.updateSize(0, 0);
81086
+ pending.push(existingObject2.hidden.promise);
81087
+ }
81088
+ }
81089
+ if (!common.length) return [
81090
+ 3,
81091
+ 1
81092
+ ];
81093
+ for(index1 = 0; index1 < common.length; index1++){
81094
+ if (index1 < this.maxRegions) {
81095
+ pack = mapped.getById(common[index1].id);
81096
+ if (pack) {
81097
+ common[index1].updateSize(pack.width, pack.height);
81098
+ }
81099
+ } else {
81100
+ common[index1].updateSize(0, 0);
81101
+ pending.push(existingObject.hidden.promise);
81102
+ }
81103
+ }
81104
+ return [
81105
+ 3,
81106
+ 3
81107
+ ];
81108
+ case 1:
81109
+ return [
81110
+ 4,
81111
+ Promise.all(pending)
81112
+ ];
81113
+ case 2:
81114
+ _state.sent();
81115
+ for(index2 = 0; index2 < diffRight.length && index2 < this.maxRegions; index2++){
81116
+ existingObject21 = this.regionsObjects.getById(diffRight[index2].id);
81117
+ if (existingObject21) {
81118
+ pack1 = mapped.getById(diffRight[index2].id);
81119
+ if (pack1) {
81120
+ existingObject21.updateSize(pack1.width, pack1.height);
81121
+ }
81122
+ } else {
81123
+ region = diffRight[index2];
81124
+ provider = ContentProviderFactory.getProvider(this.context, this.context.config.get("ads").provider);
81125
+ plugins2 = [
81126
+ new RegionBorderPlugin(),
81127
+ new RegionAnimationPlugin("OPACITY")
81128
+ ];
81129
+ newRegion = new BasicAdRegion(region.id, {
81130
+ width: region.width,
81131
+ height: region.height
81132
+ }, {
81133
+ ad: {
81134
+ type: region.type,
81135
+ name: region.region
81136
+ }
81137
+ }, {
81138
+ provider: provider,
81139
+ plugins: plugins2,
81140
+ recorder: this.context.recorder
81141
+ });
81142
+ this.regionsObjects.push(newRegion);
81143
+ this.regionsContainerView.append(newRegion.view);
81144
+ this.intersectionObserver.observe(newRegion.view);
81145
+ }
81146
+ }
81147
+ _state.label = 3;
81148
+ case 3:
81149
+ return [
81150
+ 2
81151
+ ];
81110
81152
  }
81111
- }
81112
- }
81153
+ });
81154
+ }).call(this);
81113
81155
  }
81114
81156
  },
81115
81157
  {
81116
81158
  key: "clear",
81117
81159
  value: function clear() {
81118
- this.updateSize({
81119
- width: 0,
81120
- height: 0
81121
- }, this.context.media.aspectRatio);
81122
- this.updatePosition({
81123
- x: 0,
81124
- y: 0
81125
- });
81160
+ var _this = this;
81126
81161
  this.regionsObjects.forEach(function(region) {
81127
81162
  region.clear();
81128
81163
  });
81164
+ setTimeout(function() {
81165
+ _this.updateSize({
81166
+ width: 0,
81167
+ height: 0
81168
+ }, _this.context.media.aspectRatio);
81169
+ _this.updatePosition({
81170
+ x: 0,
81171
+ y: 0
81172
+ });
81173
+ }, 500);
81129
81174
  }
81130
81175
  },
81131
81176
  {
@@ -81224,9 +81269,9 @@ var RegionRenderer = /*#__PURE__*/ function() {
81224
81269
  {
81225
81270
  key: "clear",
81226
81271
  value: function clear() {
81227
- var regions2 = Object.values(this.regionAreas);
81228
- for(var index = 0; index < regions2.length; index++){
81229
- regions2[index].clear();
81272
+ var areas = Object.values(this.regionAreas);
81273
+ for(var index = 0; index < areas.length; index++){
81274
+ areas[index].clear();
81230
81275
  }
81231
81276
  }
81232
81277
  },
@@ -81344,41 +81389,6 @@ var MediaElementSizeController = /*#__PURE__*/ function(_import_events9_default)
81344
81389
  return updated;
81345
81390
  }
81346
81391
  },
81347
- {
81348
- key: "recalculate",
81349
- value: function recalculate() {
81350
- if (!this.isResized) {
81351
- return this.restore();
81352
- }
81353
- var updated = false;
81354
- if (this.context.media.view) {
81355
- var _this_context_elements_container, _this_context_elements_container1, _this_context_elements_container2, _this_context_elements_container3;
81356
- var size = adjustSizeWithAspectRatio((((_this_context_elements_container = this.context.elements.container) === null || _this_context_elements_container === void 0 ? void 0 : _this_context_elements_container.getBoundingClientRect().width) || 0) * (this.sizePercentage / 100), (((_this_context_elements_container1 = this.context.elements.container) === null || _this_context_elements_container1 === void 0 ? void 0 : _this_context_elements_container1.getBoundingClientRect().height) || 0) * (this.sizePercentage / 100), this.context.media.aspectRatio);
81357
- if (size.width !== this.size.width || size.height !== this.size.height) {
81358
- this.size = size;
81359
- this.context.media.view.style.width = "".concat(this.size.width, "px");
81360
- this.context.media.view.style.height = "".concat(this.size.height, "px");
81361
- this.context.media.setSize(this.size.width, this.size.height);
81362
- updated = true;
81363
- }
81364
- var adjustedPosition = adjustSizeWithAspectRatio((((_this_context_elements_container2 = this.context.elements.container) === null || _this_context_elements_container2 === void 0 ? void 0 : _this_context_elements_container2.getBoundingClientRect().width) || 0) * (this.positionOffset / 100), (((_this_context_elements_container3 = this.context.elements.container) === null || _this_context_elements_container3 === void 0 ? void 0 : _this_context_elements_container3.getBoundingClientRect().height) || 0) * (this.positionOffset / 100), this.context.media.aspectRatio);
81365
- var marginValue = Math.min(adjustedPosition.width, adjustedPosition.height);
81366
- if (this.position.x !== marginValue || this.position.y !== marginValue) {
81367
- var _this_context_interface;
81368
- this.position.x = marginValue;
81369
- this.position.y = marginValue;
81370
- this.context.media.view.style.left = "".concat(this.position.x, "px");
81371
- this.context.media.view.style.top = "".concat(this.position.y, "px");
81372
- (_this_context_interface = this.context.interface) === null || _this_context_interface === void 0 ? void 0 : _this_context_interface.updatePosition(marginValue, marginValue);
81373
- updated = true;
81374
- }
81375
- }
81376
- if (updated) {
81377
- this.emit("UPDATED");
81378
- }
81379
- return updated;
81380
- }
81381
- },
81382
81392
  {
81383
81393
  key: "update",
81384
81394
  value: function update(percentage) {
@@ -81466,8 +81476,6 @@ var BasicPresentationMode = /*#__PURE__*/ function() {
81466
81476
  this.context = context;
81467
81477
  this.mediaElementSizeController = new MediaElementSizeController(context);
81468
81478
  this.packer = new RegionPacker(this.context);
81469
- this.mediaElementSizeController.on("UPDATED", function() {});
81470
- this.packer.on("PACKED", function() {});
81471
81479
  }
81472
81480
  _create_class(BasicPresentationMode, [
81473
81481
  {
@@ -81569,11 +81577,15 @@ var BasicPresentationMode = /*#__PURE__*/ function() {
81569
81577
  width: ((_this_mediaElementSizeController3 = this.mediaElementSizeController) === null || _this_mediaElementSizeController3 === void 0 ? void 0 : _this_mediaElementSizeController3.size.width) || 0,
81570
81578
  height: ((_this_mediaElementSizeController4 = this.mediaElementSizeController) === null || _this_mediaElementSizeController4 === void 0 ? void 0 : _this_mediaElementSizeController4.size.height) || 0
81571
81579
  }, fullscreen ? "fullscreen" : "default");
81572
- var updated = this.packer.repack();
81573
- if (updated) {
81580
+ this.packer.repack();
81581
+ if (this.packer.packed.length > 0) {
81574
81582
  var _this_regionsRenderer1, _this_regionsRenderer2;
81575
81583
  (_this_regionsRenderer1 = this.regionsRenderer) === null || _this_regionsRenderer1 === void 0 ? void 0 : _this_regionsRenderer1.addAreas(this.packer.areas);
81576
81584
  (_this_regionsRenderer2 = this.regionsRenderer) === null || _this_regionsRenderer2 === void 0 ? void 0 : _this_regionsRenderer2.render(this.packer.packed);
81585
+ } else {
81586
+ var _this_regionsRenderer3, _this_mediaElementSizeController5;
81587
+ (_this_regionsRenderer3 = this.regionsRenderer) === null || _this_regionsRenderer3 === void 0 ? void 0 : _this_regionsRenderer3.clear();
81588
+ (_this_mediaElementSizeController5 = this.mediaElementSizeController) === null || _this_mediaElementSizeController5 === void 0 ? void 0 : _this_mediaElementSizeController5.restore();
81577
81589
  }
81578
81590
  }
81579
81591
  }
@@ -82205,9 +82217,9 @@ var RegionRenderer2 = /*#__PURE__*/ function() {
82205
82217
  }
82206
82218
  } else {
82207
82219
  for(var index1 = 0; index1 < diffRight.length && index1 < this.maxRegions; index1++){
82208
- var existingObject = this.regionsObjects.getById(diffRight[index1].id);
82209
- if (existingObject) {
82210
- existingObject.updateRegion(mapped.getById(diffRight[index1].id));
82220
+ var existingObject2 = this.regionsObjects.getById(diffRight[index1].id);
82221
+ if (existingObject2) {
82222
+ existingObject2.updateRegion(mapped.getById(diffRight[index1].id));
82211
82223
  } else {
82212
82224
  var newRegion = this.regionFactory.get(diffRight[index1], {
82213
82225
  width: this.regionsContainerView.width,
@@ -82222,9 +82234,9 @@ var RegionRenderer2 = /*#__PURE__*/ function() {
82222
82234
  }
82223
82235
  }
82224
82236
  for(var index2 = 0; index2 < diffLeft.length; index2++){
82225
- var existingObject1 = this.regionsObjects.getById(diffLeft[index2].id);
82226
- if (existingObject1) {
82227
- existingObject1.clear();
82237
+ var existingObject21 = this.regionsObjects.getById(diffLeft[index2].id);
82238
+ if (existingObject21) {
82239
+ existingObject21.clear();
82228
82240
  }
82229
82241
  }
82230
82242
  this.regionsData = regions2;
@@ -82616,22 +82628,32 @@ var VideoAds = /*#__PURE__*/ function() {
82616
82628
  function VideoAds(context) {
82617
82629
  _class_call_check(this, VideoAds);
82618
82630
  this.videoAdElements = [];
82631
+ this.handlePageMutation = this.handlePageMutation.bind(this);
82619
82632
  this.context = context;
82620
82633
  }
82621
82634
  _create_class(VideoAds, [
82622
82635
  {
82623
- key: "start",
82624
- value: function start() {
82625
- if (!this.context.supports.api) {
82626
- this.context.logger.error("Setup failed: no support");
82627
- return;
82628
- }
82636
+ key: "handleMedias",
82637
+ value: function handleMedias() {
82629
82638
  try {
82639
+ var elements2 = [];
82640
+ for(var index = 0; index < this.videoAdElements.length; index++){
82641
+ var element = this.videoAdElements[index];
82642
+ if (element.media.view && document.body.contains(element.media.view)) {
82643
+ elements2.push(element);
82644
+ } else {
82645
+ element.destroy();
82646
+ }
82647
+ }
82648
+ this.videoAdElements = elements2;
82630
82649
  var medias = MediaElementFactory.getElements(this.context.selectors.targets);
82631
82650
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
82632
82651
  try {
82633
82652
  for(var _iterator = medias[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
82634
82653
  var media = _step.value;
82654
+ if (!media || media.closest("#BRNDTS_R") || media.querySelector("#BRNDTS_R")) {
82655
+ continue;
82656
+ }
82635
82657
  var videoAd = new VideoAd(this.context, media);
82636
82658
  this.videoAdElements.push(videoAd);
82637
82659
  videoAd.start();
@@ -82657,6 +82679,22 @@ var VideoAds = /*#__PURE__*/ function() {
82657
82679
  }
82658
82680
  }
82659
82681
  },
82682
+ {
82683
+ key: "start",
82684
+ value: function start() {
82685
+ if (!this.context.supports.api) {
82686
+ this.context.logger.error("Setup failed: no support");
82687
+ return;
82688
+ }
82689
+ this.handleMedias();
82690
+ }
82691
+ },
82692
+ {
82693
+ key: "handlePageMutation",
82694
+ value: function handlePageMutation() {
82695
+ this.handleMedias();
82696
+ }
82697
+ },
82660
82698
  {
82661
82699
  key: "updateSize",
82662
82700
  value: function updateSize() {
@@ -82710,16 +82748,28 @@ var Ads = /*#__PURE__*/ function() {
82710
82748
  "use strict";
82711
82749
  function Ads(context) {
82712
82750
  _class_call_check(this, Ads);
82751
+ this.handlePageMutation = functions_default.debounce(this.handlePageMutation.bind(this), 100);
82713
82752
  this.context = context;
82714
82753
  this.videoAds = new VideoAds(this.context);
82715
82754
  this.staticAds = new StaticAds(this.context);
82755
+ this.observer = new MutationObserver(this.handlePageMutation);
82716
82756
  }
82717
82757
  _create_class(Ads, [
82758
+ {
82759
+ key: "handlePageMutation",
82760
+ value: function handlePageMutation() {
82761
+ this.videoAds.handlePageMutation();
82762
+ this.staticAds.handlePageMutation();
82763
+ }
82764
+ },
82718
82765
  {
82719
82766
  key: "start",
82720
82767
  value: function start() {
82721
82768
  this.videoAds.start();
82722
82769
  this.staticAds.start();
82770
+ this.observer.observe(document.body, {
82771
+ childList: true
82772
+ });
82723
82773
  }
82724
82774
  },
82725
82775
  {
@@ -82732,6 +82782,7 @@ var Ads = /*#__PURE__*/ function() {
82732
82782
  key: "destroy",
82733
82783
  value: function destroy() {
82734
82784
  var _GooglePublisherTag_get;
82785
+ this.observer.disconnect();
82735
82786
  this.videoAds.destroy();
82736
82787
  this.staticAds.destroy();
82737
82788
  (_GooglePublisherTag_get = GooglePublisherTag.get()) === null || _GooglePublisherTag_get === void 0 ? void 0 : _GooglePublisherTag_get.destroy();