@brndts/brndts-ads 1.13.6 → 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.js CHANGED
@@ -72180,19 +72180,6 @@ var StaticAdRegion = /*#__PURE__*/ function(Region) {
72180
72180
  return StaticAdRegion;
72181
72181
  }(Region);
72182
72182
  // src/Ads/StaticAds/StaticAds.ts
72183
- function debounce3(func) {
72184
- var timeout = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 100;
72185
- var timer;
72186
- return function() {
72187
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
72188
- args[_key] = arguments[_key];
72189
- }
72190
- clearTimeout(timer);
72191
- timer = setTimeout(function() {
72192
- func.apply(void 0, _to_consumable_array(args));
72193
- }, timeout);
72194
- };
72195
- }
72196
72183
  function isElementVisible(element) {
72197
72184
  if (!element) return false;
72198
72185
  if (!document.contains(element)) return false;
@@ -72209,7 +72196,6 @@ var StaticAds = /*#__PURE__*/ function() {
72209
72196
  this.handlePageMutation = this.handlePageMutation.bind(this);
72210
72197
  this.context = context;
72211
72198
  this.recorderFactory = new RecorderFactory(this.context);
72212
- this.observer = new MutationObserver(debounce3(this.handlePageMutation));
72213
72199
  }
72214
72200
  _create_class(StaticAds, [
72215
72201
  {
@@ -72311,16 +72297,11 @@ var StaticAds = /*#__PURE__*/ function() {
72311
72297
  value: function start() {
72312
72298
  this.context.logger.log("starting static ads");
72313
72299
  this.handleRegions();
72314
- this.observer.observe(document.body, {
72315
- childList: true,
72316
- subtree: true
72317
- });
72318
72300
  }
72319
72301
  },
72320
72302
  {
72321
72303
  key: "destroy",
72322
72304
  value: function destroy() {
72323
- this.observer.disconnect();
72324
72305
  this.context.logger.log("destroying static ads");
72325
72306
  this.regions.forEach(function(region) {
72326
72307
  region.destroy();
@@ -81292,41 +81273,6 @@ var MediaElementSizeController = /*#__PURE__*/ function(_import_events9_default)
81292
81273
  return updated;
81293
81274
  }
81294
81275
  },
81295
- {
81296
- key: "recalculate",
81297
- value: function recalculate() {
81298
- if (!this.isResized) {
81299
- return this.restore();
81300
- }
81301
- var updated = false;
81302
- if (this.context.media.view) {
81303
- var _this_context_elements_container, _this_context_elements_container1, _this_context_elements_container2, _this_context_elements_container3;
81304
- 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);
81305
- if (size.width !== this.size.width || size.height !== this.size.height) {
81306
- this.size = size;
81307
- this.context.media.view.style.width = "".concat(this.size.width, "px");
81308
- this.context.media.view.style.height = "".concat(this.size.height, "px");
81309
- this.context.media.setSize(this.size.width, this.size.height);
81310
- updated = true;
81311
- }
81312
- 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);
81313
- var marginValue = Math.min(adjustedPosition.width, adjustedPosition.height);
81314
- if (this.position.x !== marginValue || this.position.y !== marginValue) {
81315
- var _this_context_interface;
81316
- this.position.x = marginValue;
81317
- this.position.y = marginValue;
81318
- this.context.media.view.style.left = "".concat(this.position.x, "px");
81319
- this.context.media.view.style.top = "".concat(this.position.y, "px");
81320
- (_this_context_interface = this.context.interface) === null || _this_context_interface === void 0 ? void 0 : _this_context_interface.updatePosition(marginValue, marginValue);
81321
- updated = true;
81322
- }
81323
- }
81324
- if (updated) {
81325
- this.emit("UPDATED");
81326
- }
81327
- return updated;
81328
- }
81329
- },
81330
81276
  {
81331
81277
  key: "update",
81332
81278
  value: function update(percentage) {
@@ -81413,8 +81359,6 @@ var BasicPresentationMode = /*#__PURE__*/ function() {
81413
81359
  this.context = context;
81414
81360
  this.mediaElementSizeController = new MediaElementSizeController(context);
81415
81361
  this.packer = new RegionPacker(this.context);
81416
- this.mediaElementSizeController.on("UPDATED", function() {});
81417
- this.packer.on("PACKED", function() {});
81418
81362
  }
81419
81363
  _create_class(BasicPresentationMode, [
81420
81364
  {
@@ -81516,11 +81460,15 @@ var BasicPresentationMode = /*#__PURE__*/ function() {
81516
81460
  width: ((_this_mediaElementSizeController3 = this.mediaElementSizeController) === null || _this_mediaElementSizeController3 === void 0 ? void 0 : _this_mediaElementSizeController3.size.width) || 0,
81517
81461
  height: ((_this_mediaElementSizeController4 = this.mediaElementSizeController) === null || _this_mediaElementSizeController4 === void 0 ? void 0 : _this_mediaElementSizeController4.size.height) || 0
81518
81462
  }, fullscreen ? "fullscreen" : "default");
81519
- var updated = this.packer.repack();
81520
- if (updated) {
81463
+ this.packer.repack();
81464
+ if (this.packer.packed.length > 0) {
81521
81465
  var _this_regionsRenderer1, _this_regionsRenderer2;
81522
81466
  (_this_regionsRenderer1 = this.regionsRenderer) === null || _this_regionsRenderer1 === void 0 ? void 0 : _this_regionsRenderer1.addAreas(this.packer.areas);
81523
81467
  (_this_regionsRenderer2 = this.regionsRenderer) === null || _this_regionsRenderer2 === void 0 ? void 0 : _this_regionsRenderer2.render(this.packer.packed);
81468
+ } else {
81469
+ var _this_regionsRenderer3, _this_mediaElementSizeController5;
81470
+ (_this_regionsRenderer3 = this.regionsRenderer) === null || _this_regionsRenderer3 === void 0 ? void 0 : _this_regionsRenderer3.clear();
81471
+ (_this_mediaElementSizeController5 = this.mediaElementSizeController) === null || _this_mediaElementSizeController5 === void 0 ? void 0 : _this_mediaElementSizeController5.restore();
81524
81472
  }
81525
81473
  }
81526
81474
  }
@@ -82550,22 +82498,32 @@ var VideoAds = /*#__PURE__*/ function() {
82550
82498
  function VideoAds(context) {
82551
82499
  _class_call_check(this, VideoAds);
82552
82500
  this.videoAdElements = [];
82501
+ this.handlePageMutation = this.handlePageMutation.bind(this);
82553
82502
  this.context = context;
82554
82503
  }
82555
82504
  _create_class(VideoAds, [
82556
82505
  {
82557
- key: "start",
82558
- value: function start() {
82559
- if (!this.context.supports.api) {
82560
- this.context.logger.error("Setup failed: no support");
82561
- return;
82562
- }
82506
+ key: "handleMedias",
82507
+ value: function handleMedias() {
82563
82508
  try {
82509
+ var elements2 = [];
82510
+ for(var index = 0; index < this.videoAdElements.length; index++){
82511
+ var element = this.videoAdElements[index];
82512
+ if (element.media.view && document.body.contains(element.media.view)) {
82513
+ elements2.push(element);
82514
+ } else {
82515
+ element.destroy();
82516
+ }
82517
+ }
82518
+ this.videoAdElements = elements2;
82564
82519
  var medias = MediaElementFactory.getElements(this.context.selectors.targets);
82565
82520
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
82566
82521
  try {
82567
82522
  for(var _iterator = medias[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
82568
82523
  var media = _step.value;
82524
+ if (!media || media.closest("#BRNDTS_R") || media.querySelector("#BRNDTS_R")) {
82525
+ continue;
82526
+ }
82569
82527
  var videoAd = new VideoAd(this.context, media);
82570
82528
  this.videoAdElements.push(videoAd);
82571
82529
  videoAd.start();
@@ -82591,6 +82549,22 @@ var VideoAds = /*#__PURE__*/ function() {
82591
82549
  }
82592
82550
  }
82593
82551
  },
82552
+ {
82553
+ key: "start",
82554
+ value: function start() {
82555
+ if (!this.context.supports.api) {
82556
+ this.context.logger.error("Setup failed: no support");
82557
+ return;
82558
+ }
82559
+ this.handleMedias();
82560
+ }
82561
+ },
82562
+ {
82563
+ key: "handlePageMutation",
82564
+ value: function handlePageMutation() {
82565
+ this.handleMedias();
82566
+ }
82567
+ },
82594
82568
  {
82595
82569
  key: "updateSize",
82596
82570
  value: function updateSize() {
@@ -82643,16 +82617,28 @@ var VideoAds = /*#__PURE__*/ function() {
82643
82617
  var Ads = /*#__PURE__*/ function() {
82644
82618
  function Ads(context) {
82645
82619
  _class_call_check(this, Ads);
82620
+ this.handlePageMutation = functions_default.debounce(this.handlePageMutation.bind(this), 100);
82646
82621
  this.context = context;
82647
82622
  this.videoAds = new VideoAds(this.context);
82648
82623
  this.staticAds = new StaticAds(this.context);
82624
+ this.observer = new MutationObserver(this.handlePageMutation);
82649
82625
  }
82650
82626
  _create_class(Ads, [
82627
+ {
82628
+ key: "handlePageMutation",
82629
+ value: function handlePageMutation() {
82630
+ this.videoAds.handlePageMutation();
82631
+ this.staticAds.handlePageMutation();
82632
+ }
82633
+ },
82651
82634
  {
82652
82635
  key: "start",
82653
82636
  value: function start() {
82654
82637
  this.videoAds.start();
82655
82638
  this.staticAds.start();
82639
+ this.observer.observe(document.body, {
82640
+ childList: true
82641
+ });
82656
82642
  }
82657
82643
  },
82658
82644
  {
@@ -82665,6 +82651,7 @@ var Ads = /*#__PURE__*/ function() {
82665
82651
  key: "destroy",
82666
82652
  value: function destroy() {
82667
82653
  var _GooglePublisherTag_get;
82654
+ this.observer.disconnect();
82668
82655
  this.videoAds.destroy();
82669
82656
  this.staticAds.destroy();
82670
82657
  (_GooglePublisherTag_get = GooglePublisherTag.get()) === null || _GooglePublisherTag_get === void 0 ? void 0 : _GooglePublisherTag_get.destroy();