@brndts/brndts-ads 1.13.12 → 1.13.14

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
@@ -71410,9 +71410,14 @@ var RegionMaskPlugin = /*#__PURE__*/ function() {
71410
71410
  {
71411
71411
  key: "afterRender",
71412
71412
  value: function afterRender(region) {
71413
- this.countours.update(region.regionContours.points);
71414
- this.mask.render(region.referencePlane, region.boundingBox, this.countours.points);
71415
- region.content.view.style.maskImage = this.mask.maskUrl;
71413
+ if (region.regionContours.points.length > 0) {
71414
+ this.countours.update(region.regionContours.points);
71415
+ this.mask.render(region.referencePlane, region.boundingBox, this.countours.points);
71416
+ region.content.view.style.maskImage = this.mask.maskUrl;
71417
+ } else {
71418
+ this.mask.clear();
71419
+ region.content.view.style.maskImage = "none";
71420
+ }
71416
71421
  return Promise.resolve();
71417
71422
  }
71418
71423
  }
@@ -71636,6 +71641,7 @@ var Region = /*#__PURE__*/ function() {
71636
71641
  this.container.classList.add("BRNDTS_R");
71637
71642
  this.container.style.position = "absolute";
71638
71643
  this.container.style.display = "none";
71644
+ this.container.style.pointerEvents = "none";
71639
71645
  if ((_this_deps_config = this.deps.config) === null || _this_deps_config === void 0 ? void 0 : (_this_deps_config_getAdsConfig_general = _this_deps_config.getAdsConfig().general) === null || _this_deps_config_getAdsConfig_general === void 0 ? void 0 : (_this_deps_config_getAdsConfig_general_clickability = _this_deps_config_getAdsConfig_general.clickability) === null || _this_deps_config_getAdsConfig_general_clickability === void 0 ? void 0 : _this_deps_config_getAdsConfig_general_clickability.value) {
71640
71646
  this.container.style.pointerEvents = "all";
71641
71647
  }
@@ -72764,6 +72770,49 @@ var elements = {
72764
72770
  var elements_default = elements;
72765
72771
  // src/Ads/VideoAds/Media/YoutubeMediaElements.ts
72766
72772
  var DEFAULT_SEEK_INTERVAL = 10;
72773
+ var YTAPIReady = new Awaitable(false);
72774
+ var YTAPILoading = false;
72775
+ var YoutubeIframeAPILoader = /*#__PURE__*/ function() {
72776
+ "use strict";
72777
+ function YoutubeIframeAPILoader() {
72778
+ _class_call_check(this, YoutubeIframeAPILoader);
72779
+ }
72780
+ _create_class(YoutubeIframeAPILoader, null, [
72781
+ {
72782
+ key: "isLoaded",
72783
+ value: function isLoaded() {
72784
+ return YTAPIReady;
72785
+ }
72786
+ },
72787
+ {
72788
+ key: "load",
72789
+ value: function load() {
72790
+ if (YTAPIReady.value === true) {
72791
+ return YTAPIReady;
72792
+ }
72793
+ if (is_default.object(window.YT) && is_default.function(window.YT.Player)) {
72794
+ YTAPIReady.resolve(true);
72795
+ } else {
72796
+ if (YTAPILoading) {
72797
+ return YTAPIReady;
72798
+ }
72799
+ var callback = window.onYouTubeIframeAPIReady;
72800
+ window.onYouTubeIframeAPIReady = function() {
72801
+ if (callback && is_default.function(callback)) {
72802
+ callback();
72803
+ }
72804
+ YTAPIReady.resolve(true);
72805
+ };
72806
+ loadScript("https://www.youtube.com/iframe_api").catch(function(error) {
72807
+ console.warn("YouTube API failed to load", error);
72808
+ });
72809
+ }
72810
+ return YTAPIReady;
72811
+ }
72812
+ }
72813
+ ]);
72814
+ return YoutubeIframeAPILoader;
72815
+ }();
72767
72816
  function generateId(prefix) {
72768
72817
  return "".concat(prefix, "-").concat(Math.floor(Math.random() * 1e4));
72769
72818
  }
@@ -72836,24 +72885,13 @@ var YoutubeMediaElement = /*#__PURE__*/ function(GenericMediaElement) {
72836
72885
  key: "setMediaElement",
72837
72886
  value: function setMediaElement(target) {
72838
72887
  var _this = this;
72839
- this.context.logger.log("Checking YT API");
72840
- if (is_default.object(window.YT) && is_default.function(window.YT.Player)) {
72841
- this.context.logger.log("YT API is already loaded");
72842
- this.YTAPIReady(target);
72843
- } else {
72844
- var callback = window.onYouTubeIframeAPIReady;
72845
- window.onYouTubeIframeAPIReady = function() {
72846
- if (callback && is_default.function(callback)) {
72847
- callback();
72848
- }
72849
- _this.context.logger.log("YT API is loaded");
72850
- _this.YTAPIReady(target);
72851
- };
72852
- this.context.logger.log("YT API is not loaded");
72853
- loadScript("https://www.youtube.com/iframe_api").catch(function(error) {
72854
- _this.context.logger.warn("YouTube API failed to load", error);
72855
- });
72856
- }
72888
+ YoutubeIframeAPILoader.load().promise.then(function() {
72889
+ _this.YTAPIReady(target);
72890
+ }).catch(function(error) {
72891
+ _this.context.logger.error("YouTube API failed to load", error);
72892
+ _this.error = new InternalError("YouTube API failed to load");
72893
+ _this.emit("ERROR", _this.error);
72894
+ });
72857
72895
  }
72858
72896
  },
72859
72897
  {
@@ -73035,7 +73073,14 @@ var YoutubeMediaElement = /*#__PURE__*/ function(GenericMediaElement) {
73035
73073
  });
73036
73074
  this.context.elements.original = media;
73037
73075
  media = elements_default.replaceElement(container, media);
73038
- var ytPlayer = new window.YT.Player(media, params);
73076
+ var ytPlayer;
73077
+ try {
73078
+ ytPlayer = new window.YT.Player(media, params);
73079
+ } catch (error) {
73080
+ this.error = error;
73081
+ this.emit("ERROR", this.error);
73082
+ return;
73083
+ }
73039
73084
  this.media = ytPlayer.getIframe();
73040
73085
  }
73041
73086
  },
@@ -80187,6 +80232,10 @@ var Interface = /*#__PURE__*/ function(_import_events7_default) {
80187
80232
  value: function setupControls() {
80188
80233
  var _this = this;
80189
80234
  this.controls = new Controls(this.context);
80235
+ var existingControls = this.container.querySelector("#".concat(this.controls.view.id));
80236
+ if (existingControls) {
80237
+ this.container.removeChild(existingControls);
80238
+ }
80190
80239
  this.container.appendChild(this.controls.view);
80191
80240
  this.controls.events.on("TOGGLE_FULLSCREEN", function() {
80192
80241
  _this.fullscreen.toggleFullscreen();
@@ -80232,6 +80281,7 @@ var Interface = /*#__PURE__*/ function(_import_events7_default) {
80232
80281
  if (!this.context.elements.original) {
80233
80282
  var _this_context_elements_container;
80234
80283
  (_this_context_elements_container = this.context.elements.container) === null || _this_context_elements_container === void 0 ? void 0 : _this_context_elements_container.remove();
80284
+ this.context.elements.container = null;
80235
80285
  return;
80236
80286
  }
80237
80287
  (_this_container_parentElement = this.container.parentElement) === null || _this_container_parentElement === void 0 ? void 0 : _this_container_parentElement.replaceChild(this.context.elements.original, this.container);
@@ -81151,7 +81201,8 @@ var AdRegionsArea = /*#__PURE__*/ function() {
81151
81201
  }, {
81152
81202
  provider: provider,
81153
81203
  plugins: plugins2,
81154
- recorder: this.context.recorder
81204
+ recorder: this.context.recorder,
81205
+ config: this.context.config
81155
81206
  });
81156
81207
  this.regionsObjects.push(newRegion);
81157
81208
  this.regionsContainerView.append(newRegion.view);
@@ -81172,6 +81223,14 @@ var AdRegionsArea = /*#__PURE__*/ function() {
81172
81223
  key: "clear",
81173
81224
  value: function clear() {
81174
81225
  var _this = this;
81226
+ this.updateSize({
81227
+ width: 0,
81228
+ height: 0
81229
+ }, this.context.media.aspectRatio);
81230
+ this.updatePosition({
81231
+ x: 0,
81232
+ y: 0
81233
+ });
81175
81234
  this.regionsObjects.forEach(function(region) {
81176
81235
  region.clear();
81177
81236
  });
@@ -81743,12 +81802,13 @@ var RegionFactory = /*#__PURE__*/ function() {
81743
81802
  ];
81744
81803
  }
81745
81804
  if (this.deps.strategy === "blend_with_similarity") {
81746
- return [
81747
- new RegionMaskPlugin(),
81748
- new RegionBorderPlugin({
81805
+ var _this_deps_config_getAdsConfig_general_debug_mode2, _this_deps_config_getAdsConfig_general2, _this_deps_config2, _this_deps3;
81806
+ if (!((_this_deps3 = this.deps) === null || _this_deps3 === void 0 ? void 0 : (_this_deps_config2 = _this_deps3.config) === null || _this_deps_config2 === void 0 ? void 0 : (_this_deps_config_getAdsConfig_general2 = _this_deps_config2.getAdsConfig().general) === null || _this_deps_config_getAdsConfig_general2 === void 0 ? void 0 : (_this_deps_config_getAdsConfig_general_debug_mode2 = _this_deps_config_getAdsConfig_general2.debug_mode) === null || _this_deps_config_getAdsConfig_general_debug_mode2 === void 0 ? void 0 : _this_deps_config_getAdsConfig_general_debug_mode2.value)) {
81807
+ plugins2.push(new RegionBorderPlugin({
81749
81808
  useFeather: true
81750
- })
81751
- ];
81809
+ }));
81810
+ }
81811
+ plugins2.push(new RegionMaskPlugin());
81752
81812
  }
81753
81813
  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")) {
81754
81814
  plugins2.push(new RegionBorderPlugin(), new RegionAnimationPlugin());
@@ -82632,6 +82692,12 @@ var VideoAd = /*#__PURE__*/ function() {
82632
82692
  (_this_presentation = this.presentation) === null || _this_presentation === void 0 ? void 0 : _this_presentation.updateSize();
82633
82693
  }
82634
82694
  },
82695
+ {
82696
+ key: "isBroken",
82697
+ value: function isBroken() {
82698
+ return !this.media.view || document.body.contains(this.media.view) || !this.media.view.closest("#BRNDTS_R") || !this.media.view.querySelector("#BRNDTS_R");
82699
+ }
82700
+ },
82635
82701
  {
82636
82702
  key: "destroy",
82637
82703
  value: function destroy() {
@@ -82660,39 +82726,21 @@ var VideoAds = /*#__PURE__*/ function() {
82660
82726
  var elements2 = [];
82661
82727
  for(var index = 0; index < this.videoAdElements.length; index++){
82662
82728
  var element = this.videoAdElements[index];
82663
- if (element.media.view && document.body.contains(element.media.view)) {
82664
- elements2.push(element);
82665
- } else {
82729
+ if (element.isBroken()) {
82666
82730
  element.destroy();
82731
+ } else {
82732
+ elements2.push(element);
82667
82733
  }
82668
82734
  }
82669
82735
  this.videoAdElements = elements2;
82670
82736
  var medias = MediaElementFactory.getElements(this.context.selectors.targets);
82671
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
82672
- try {
82673
- for(var _iterator = medias[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
82674
- var media = _step.value;
82675
- if (!media || media.closest("#BRNDTS_R") || media.querySelector("#BRNDTS_R") || media.dataset.b_I !== void 0) {
82676
- continue;
82677
- }
82678
- media.dataset.b_I = "".concat(this.videoAdElements.length);
82679
- var videoAd = new VideoAd(this.context, media);
82680
- this.videoAdElements.push(videoAd);
82681
- videoAd.start();
82682
- }
82683
- } catch (err) {
82684
- _didIteratorError = true;
82685
- _iteratorError = err;
82686
- } finally{
82687
- try {
82688
- if (!_iteratorNormalCompletion && _iterator.return != null) {
82689
- _iterator.return();
82690
- }
82691
- } finally{
82692
- if (_didIteratorError) {
82693
- throw _iteratorError;
82694
- }
82737
+ for(var index1 = 0; index1 < medias.length; index1++){
82738
+ if (!medias[index1] || medias[index1].closest("#BRNDTS_R") || medias[index1].querySelector("#BRNDTS_R")) {
82739
+ continue;
82695
82740
  }
82741
+ var videoAd = new VideoAd(this.context, medias[index1]);
82742
+ this.videoAdElements.push(videoAd);
82743
+ videoAd.start();
82696
82744
  }
82697
82745
  } catch (error) {
82698
82746
  if (_instanceof(error, Error)) {
@@ -82713,9 +82761,7 @@ var VideoAds = /*#__PURE__*/ function() {
82713
82761
  },
82714
82762
  {
82715
82763
  key: "handlePageMutation",
82716
- value: function handlePageMutation() {
82717
- this.handleMedias();
82718
- }
82764
+ value: function handlePageMutation() {}
82719
82765
  },
82720
82766
  {
82721
82767
  key: "updateSize",