adgent-sdk 0.1.7 → 0.1.9

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/README.md CHANGED
@@ -27,6 +27,7 @@ Lightweight, framework-agnostic VAST Player SDK for Smart TV platforms.
27
27
  - [Configuration Options](#configuration-options)
28
28
  - [Events](#events)
29
29
  - [Platform Support](#platform-support)
30
+ - [Limitations](#limitations)
30
31
  - [Performance](#performance)
31
32
  - [Development](#development)
32
33
  - [License](#license)
@@ -363,6 +364,38 @@ sdk.destroy();
363
364
  - Naver Whale browser support
364
365
  - Whale-specific optimizations
365
366
 
367
+
368
+ ---
369
+
370
+ ## Limitations
371
+
372
+ ### No VPAID Support
373
+
374
+ Adgent SDK explicitly **does not support** VPAID (Video Player-Ad Interface Definition) executables. VPAID is deliberately excluded for Smart TV platforms due to:
375
+
376
+ 1. **Performance**: VPAID requires executing arbitrary JavaScript within the player context, which severely degrades performance on resource-constrained TV hardware.
377
+ 2. **Stability**: Third-party VPAID scripts are a common source of memory leaks and application crashes on long-running TV apps.
378
+ 3. **Security**: Executing unverified external code poses significant security risks.
379
+ 4. **Modern Alternatives**: The industry has moved towards VAST 4.x and OMID (Open Measurement Interface Definition) for measurement, rendering VPAID obsolete for most modern ad serving use cases.
380
+
381
+ The SDK automatically filters out VPAID media files and selects the best compatible video file (MP4/WebM).
382
+
383
+ ### Device Compatibility (Old TVs)
384
+
385
+ Smart TVs, especially older models (2016-2019), have strict hardware limitations. To ensure smooth playback across all devices, we recommend the following constraints:
386
+
387
+ 1. **Video Codec**: H.264 (AVC) Main Profile Level 4.1 or lower.
388
+ - HEVC (H.265) is supported on newer models but may fail on older ones.
389
+ - VP9 is widely supported but less reliable for ad insertion than H.264.
390
+ 2. **Resolution**: 1920x1080 (1080p) maximum.
391
+ - 4K (UHD) ads are **penalized** by the SDK's selection algorithm as they consume excessive memory and can cause UI stuttering or crashes on budget TVs.
392
+ 3. **Bitrate**: 1500-2500 kbps recommended.
393
+ - Bitrates > 4000 kbps may cause buffering on TV WiFi chips.
394
+ 4. **Audio Codec**: AAC-LC (Low Complexity).
395
+ 5. **Container**: MP4 (`video/mp4`) is preferred over all other containers for maximum compatibility.
396
+
397
+ The SDK's selection algorithm actively prioritizes streams matching these criteria to prevent playback failures on legacy hardware.
398
+
366
399
  ---
367
400
 
368
401
  ## Performance
@@ -754,10 +754,14 @@ var VASTParser = /* @__PURE__ */ function() {
754
754
  value: function selectBestMediaFile(mediaFiles) {
755
755
  var targetBitrate = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 2500;
756
756
  if (mediaFiles.length === 0) return null;
757
- var mp4Files = mediaFiles.filter(function(mf) {
757
+ var validFiles = mediaFiles.filter(function(mf) {
758
+ return mf.type.toLowerCase().startsWith("video/");
759
+ });
760
+ if (validFiles.length === 0) return null;
761
+ var mp4Files = validFiles.filter(function(mf) {
758
762
  return mf.type.includes("mp4") || mf.type.includes("video/mp4");
759
763
  });
760
- var candidates = mp4Files.length > 0 ? mp4Files : mediaFiles;
764
+ var candidates = mp4Files.length > 0 ? mp4Files : validFiles;
761
765
  var sorted = _toConsumableArray(candidates).sort(function(a, b) {
762
766
  var aBitrate = a.bitrate || 0;
763
767
  var bBitrate = b.bitrate || 0;
@@ -1835,6 +1839,7 @@ var AdPlayer = /* @__PURE__ */ function() {
1835
1839
  __publicField4(this, "quartilesFired", /* @__PURE__ */ new Set());
1836
1840
  __publicField4(this, "boundKeyHandler", null);
1837
1841
  __publicField4(this, "focusTrap", null);
1842
+ __publicField4(this, "hasStarted", false);
1838
1843
  this.config = __spreadValues4(__spreadValues4({}, DEFAULT_CONFIG), config);
1839
1844
  this.platform = getPlatformAdapter();
1840
1845
  this.parser = new VASTParser({
@@ -2130,6 +2135,7 @@ var AdPlayer = /* @__PURE__ */ function() {
2130
2135
  if (url) {
2131
2136
  this.log("Ad clicked. Opening: ".concat(url));
2132
2137
  (_b = this.videoElement) == null ? void 0 : _b.pause();
2138
+ this.showStartOverlay();
2133
2139
  var clickTracking = ((_c = linear.videoClicks) == null ? void 0 : _c.clickTracking) || [];
2134
2140
  clickTracking.forEach(function(tracking) {
2135
2141
  var _a2;
@@ -2152,7 +2158,7 @@ var AdPlayer = /* @__PURE__ */ function() {
2152
2158
  key: "onStartClick",
2153
2159
  value: function onStartClick() {
2154
2160
  return __async2(this, null, /* @__PURE__ */ _regenerator().m(function _callee3() {
2155
- var _t3;
2161
+ var _a, _t3;
2156
2162
  return _regenerator().w(function(_context3) {
2157
2163
  while (1) switch (_context3.p = _context3.n) {
2158
2164
  case 0:
@@ -2165,7 +2171,17 @@ var AdPlayer = /* @__PURE__ */ function() {
2165
2171
  _context3.n = 2;
2166
2172
  return this.videoElement.play();
2167
2173
  case 2:
2168
- this.handlePlaybackStart();
2174
+ if (this.hasStarted) {
2175
+ this.updateState({
2176
+ status: PlaybackStatus.Playing
2177
+ });
2178
+ this.emit({
2179
+ type: "resume"
2180
+ });
2181
+ (_a = this.tracker) == null ? void 0 : _a.track("resume");
2182
+ } else {
2183
+ this.handlePlaybackStart();
2184
+ }
2169
2185
  _context3.n = 4;
2170
2186
  break;
2171
2187
  case 3:
@@ -2196,6 +2212,7 @@ var AdPlayer = /* @__PURE__ */ function() {
2196
2212
  key: "handlePlaybackStart",
2197
2213
  value: function handlePlaybackStart() {
2198
2214
  var _a, _b, _c, _d, _e;
2215
+ this.hasStarted = true;
2199
2216
  this.updateState({
2200
2217
  status: PlaybackStatus.Playing
2201
2218
  });
@@ -1,3 +1,3 @@
1
1
  !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("fast-xml-parser")):"function"==typeof define&&define.amd?define(["exports","fast-xml-parser"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).AdgentSDK={},e.FastXMLParser)}(this,function(e,t){"use strict";function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t,n){return t&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,d(r.key),r)}}(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function a(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=p(e))||t){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function o(e,t,n){return(t=d(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function s(){
2
2
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
3
- var e,t,n="function"==typeof Symbol?Symbol:{},r=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function a(n,r,i,a){var s=r&&r.prototype instanceof u?r:u,c=Object.create(s.prototype);return l(c,"_invoke",function(n,r,i){var a,s,l,u=0,c=i||[],d=!1,f={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,n){return a=t,s=0,l=e,f.n=n,o}};function p(n,r){for(s=n,l=r,t=0;!d&&u&&!i&&t<c.length;t++){var i,a=c[t],p=f.p,h=a[2];n>3?(i=h===r)&&(l=a[(s=a[4])?5:(s=3,3)],a[4]=a[5]=e):a[0]<=p&&((i=n<2&&p<a[1])?(s=0,f.v=r,f.n=a[1]):p<h&&(i=n<3||a[0]>r||r>h)&&(a[4]=n,a[5]=r,f.n=h,s=0))}if(i||n>1)return o;throw d=!0,r}return function(i,c,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===c&&p(c,h),s=c,l=h;(t=s<2?e:l)||!d;){a||(s?s<3?(s>1&&(f.n=-1),p(s,l)):f.n=l:f.v=l);try{if(u=2,a){if(s||(i="next"),t=a[i]){if(!(t=t.call(a,l)))throw TypeError("iterator result is not an object");if(!t.done)return t;l=t.value,s<2&&(s=0)}else 1===s&&(t=a.return)&&t.call(a),s<2&&(l=TypeError("The iterator does not provide a '"+i+"' method"),s=1);a=e}else if((t=(d=f.n<0)?l:n.call(r,f))!==o)break}catch(v){a=e,s=1,l=v}finally{u=1}}return{value:t,done:d}}}(n,i,a),!0),c}var o={};function u(){}function c(){}function d(){}t=Object.getPrototypeOf;var f=[][r]?t(t([][r]())):(l(t={},r,function(){return this}),t),p=d.prototype=u.prototype=Object.create(f);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,d):(e.__proto__=d,l(e,i,"GeneratorFunction")),e.prototype=Object.create(p),e}return c.prototype=d,l(p,"constructor",d),l(d,"constructor",c),c.displayName="GeneratorFunction",l(d,i,"GeneratorFunction"),l(p),l(p,i,"Generator"),l(p,r,function(){return this}),l(p,"toString",function(){return"[object Generator]"}),(s=function(){return{w:a,m:h}})()}function l(e,t,n,r){var i=Object.defineProperty;try{i({},"",{})}catch(a){i=0}(l=function(e,t,n,r){function a(t,n){l(e,t,function(e){return this._invoke(t,n,e)})}t?i?i(e,t,{value:n,enumerable:!r,configurable:!r,writable:!r}):e[t]=n:(a("next",0),a("throw",1),a("return",2))})(e,t,n,r)}function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,i,a,o,s=[],l=!0,u=!1;try{if(a=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;l=!1}else for(;!(l=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);l=!0);}catch(c){u=!0,i=c}finally{try{if(!l&&null!=n.return&&(o=n.return(),Object(o)!==o))return}finally{if(u)throw i}}return s}}(e,t)||p(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(e){return function(e){if(Array.isArray(e))return n(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||p(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t);if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}function f(e){return(f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function p(e,t){if(e){if("string"==typeof e)return n(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}var h,v,y=function(e){return e.Idle="idle",e.Loading="loading",e.Ready="ready",e.Playing="playing",e.Paused="paused",e.Completed="completed",e.Error="error",e.WaitingForInteraction="waiting_for_interaction",e}(y||{}),m=function(e){return e[e.XML_PARSING_ERROR=100]="XML_PARSING_ERROR",e[e.VAST_SCHEMA_VALIDATION_ERROR=101]="VAST_SCHEMA_VALIDATION_ERROR",e[e.VAST_VERSION_NOT_SUPPORTED=102]="VAST_VERSION_NOT_SUPPORTED",e[e.GENERAL_WRAPPER_ERROR=300]="GENERAL_WRAPPER_ERROR",e[e.WRAPPER_TIMEOUT=301]="WRAPPER_TIMEOUT",e[e.WRAPPER_LIMIT_REACHED=302]="WRAPPER_LIMIT_REACHED",e[e.NO_VAST_RESPONSE=303]="NO_VAST_RESPONSE",e[e.GENERAL_LINEAR_ERROR=400]="GENERAL_LINEAR_ERROR",e[e.FILE_NOT_FOUND=401]="FILE_NOT_FOUND",e[e.MEDIA_TIMEOUT=402]="MEDIA_TIMEOUT",e[e.MEDIA_NOT_SUPPORTED=403]="MEDIA_NOT_SUPPORTED",e[e.GENERAL_COMPANION_ERROR=600]="GENERAL_COMPANION_ERROR",e[e.UNDEFINED_ERROR=900]="UNDEFINED_ERROR",e}(m||{}),g=Object.defineProperty,b=Object.defineProperties,k=Object.getOwnPropertyDescriptors,E=Object.getOwnPropertySymbols,w=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable,A=function(e,t,n){return t in e?g(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n},T=function(e,t){for(var n in t||(t={}))w.call(t,n)&&A(e,n,t[n]);if(E){var r,i=a(E(t));try{for(i.s();!(r=i.n()).done;){n=r.value;S.call(t,n)&&A(e,n,t[n])}}catch(o){i.e(o)}finally{i.f()}}return e},P=function(e,t){return b(e,k(t))},O=function(e,t,n){return A(e,"symbol"!==f(t)?t+"":t,n)},R=function(e,t,n){return new Promise(function(r,i){var a=function(e){try{s(n.next(e))}catch(t){i(t)}},o=function(e){try{s(n.throw(e))}catch(t){i(t)}},s=function(e){return e.done?r(e.value):Promise.resolve(e.value).then(a,o)};s((n=n.apply(e,t)).next())})},x=function(){return i(function e(){var n,i,a,o,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};r(this,e),O(this,"config"),O(this,"xmlParser"),this.config={maxWrapperDepth:null!=(n=s.maxWrapperDepth)?n:5,timeout:null!=(i=s.timeout)?i:1e4,debug:null!=(a=s.debug)&&a,fetchFn:null!=(o=s.fetchFn)?o:fetch.bind(globalThis)},this.xmlParser=new t.XMLParser({ignoreAttributes:!1,attributeNamePrefix:"@_",textNodeName:"#text",parseAttributeValue:!0,trimValues:!0})},[{key:"parse",value:function(e){return R(this,null,s().m(function t(){var n,r,i;return s().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,this.fetchAndParse(e,0);case 1:return n=t.v,t.a(2,{success:!0,response:n});case 2:return t.p=2,i=t.v,r=i instanceof Error?i.message:"Unknown error",t.a(2,{success:!1,error:{code:m.GENERAL_WRAPPER_ERROR,message:r}})}},t,this,[[0,2]])}))}},{key:"fetchAndParse",value:function(e,t){return R(this,null,s().m(function n(){var r,i,a,o=this;return s().w(function(n){for(;;)switch(n.n){case 0:if(!(t>=this.config.maxWrapperDepth)){n.n=1;break}throw new Error("Wrapper limit exceeded (max: ".concat(this.config.maxWrapperDepth,")"));case 1:return this.log("Fetching VAST (depth: ".concat(t,"): ").concat(e)),n.n=2,this.fetchWithTimeout(e);case 2:return r=n.v,i=this.parseXml(r),n.n=3,Promise.all(i.ads.map(function(e){return R(o,null,s().m(function n(){var r;return s().w(function(n){for(;;)switch(n.n){case 0:if(!(null==(r=e.wrapper)?void 0:r.vastAdTagURI)){n.n=1;break}return n.a(2,this.resolveWrapper(e,t+1));case 1:return n.a(2,e)}},n,this)}))}));case 3:return a=n.v,n.a(2,P(T({},i),{ads:a.flat()}))}},n,this)}))}},{key:"resolveWrapper",value:function(e,t){return R(this,null,s().m(function n(){var r,i,a,o=this;return s().w(function(n){for(;;)switch(n.p=n.n){case 0:if(null==(r=e.wrapper)?void 0:r.vastAdTagURI){n.n=1;break}return n.a(2,[e]);case 1:return n.p=1,n.n=2,this.fetchAndParse(e.wrapper.vastAdTagURI,t);case 2:return i=n.v,n.a(2,i.ads.map(function(t){return o.mergeWrapperTracking(e,t)}));case 3:if(n.p=3,a=n.v,this.log("Wrapper resolution failed: ".concat(a)),!e.wrapper.fallbackOnNoAd){n.n=4;break}return n.a(2,[]);case 4:throw a;case 5:return n.a(2)}},n,this,[[1,3]])}))}},{key:"mergeWrapperTracking",value:function(e,t){var n=this;return P(T({},t),{impressions:[].concat(c(e.impressions),c(t.impressions)),errors:[].concat(c(e.errors),c(t.errors)),creatives:t.creatives.map(function(t){return P(T({},t),{linear:t.linear?P(T({},t.linear),{trackingEvents:[].concat(c(n.getWrapperTrackingEvents(e)),c(t.linear.trackingEvents))}):void 0})})})}},{key:"getWrapperTrackingEvents",value:function(e){var t,n,r=[],i=a(e.creatives);try{for(i.s();!(n=i.n()).done;){var o=n.value;(null==(t=o.linear)?void 0:t.trackingEvents)&&r.push.apply(r,c(o.linear.trackingEvents))}}catch(s){i.e(s)}finally{i.f()}return r}},{key:"fetchWithTimeout",value:function(e){return R(this,null,s().m(function t(){var n,r,i;return s().w(function(t){for(;;)switch(t.p=t.n){case 0:return n=new AbortController,r=setTimeout(function(){return n.abort()},this.config.timeout),t.p=1,t.n=2,this.config.fetchFn(e,{signal:n.signal});case 2:if((i=t.v).ok){t.n=3;break}throw new Error("HTTP ".concat(i.status,": ").concat(i.statusText));case 3:return t.a(2,i.text());case 4:return t.p=4,clearTimeout(r),t.f(4);case 5:return t.a(2)}},t,this,[[1,,4,5]])}))}},{key:"parseXml",value:function(e){var t=this.xmlParser.parse(e).VAST;if(!t)throw new Error("Invalid VAST: missing VAST element");return{version:t["@_version"]||"4.0",ads:this.parseAds(t.Ad),errors:this.parseErrors(t.Error)}}},{key:"parseAds",value:function(e){var t=this;return e?(Array.isArray(e)?e:[e]).map(function(e){return t.parseAd(e)}):[]}},{key:"parseAd",value:function(e){var t,n,r,i=!!e.Wrapper,a=e.InLine||e.Wrapper;return{id:e["@_id"]||"",sequence:e["@_sequence"],adSystem:(null==a?void 0:a.AdSystem)?{name:"string"==typeof a.AdSystem?a.AdSystem:a.AdSystem["#text"]||"",version:null==(t=a.AdSystem)?void 0:t["@_version"]}:void 0,adTitle:null==a?void 0:a.AdTitle,impressions:this.parseImpressions(null==a?void 0:a.Impression),errors:this.parseErrors(null==a?void 0:a.Error),creatives:this.parseCreatives(null==(n=null==a?void 0:a.Creatives)?void 0:n.Creative),wrapper:i?{vastAdTagURI:a.VASTAdTagURI,followAdditionalWrappers:!1!==a["@_followAdditionalWrappers"],allowMultipleAds:a["@_allowMultipleAds"],fallbackOnNoAd:a["@_fallbackOnNoAd"]}:void 0,inLine:i?void 0:{adTitle:(null==a?void 0:a.AdTitle)||"",description:null==a?void 0:a.Description,advertiser:null==a?void 0:a.Advertiser,creatives:this.parseCreatives(null==(r=null==a?void 0:a.Creatives)?void 0:r.Creative)}}}},{key:"parseImpressions",value:function(e){return e?(Array.isArray(e)?e:[e]).map(function(e){return{id:e["@_id"],url:"string"==typeof e?e:e["#text"]||""}}):[]}},{key:"parseCreatives",value:function(e){var t=this;return e?(Array.isArray(e)?e:[e]).map(function(e){return{id:e["@_id"],sequence:e["@_sequence"],adId:e["@_adId"],linear:e.Linear?t.parseLinear(e.Linear):void 0}}):[]}},{key:"parseLinear",value:function(e){var t,n;return{duration:this.parseDuration(e.Duration),skipOffset:e["@_skipoffset"]?this.parseDuration(e["@_skipoffset"]):void 0,mediaFiles:this.parseMediaFiles(null==(t=e.MediaFiles)?void 0:t.MediaFile),trackingEvents:this.parseTrackingEvents(null==(n=e.TrackingEvents)?void 0:n.Tracking),videoClicks:e.VideoClicks?{clickThrough:e.VideoClicks.ClickThrough?{id:e.VideoClicks.ClickThrough["@_id"],url:"string"==typeof e.VideoClicks.ClickThrough?e.VideoClicks.ClickThrough:e.VideoClicks.ClickThrough["#text"]||""}:void 0}:void 0,adParameters:e.AdParameters}}},{key:"parseMediaFiles",value:function(e){return e?(Array.isArray(e)?e:[e]).map(function(e){return{id:e["@_id"],url:"string"==typeof e?e:e["#text"]||"",delivery:e["@_delivery"]||"progressive",type:e["@_type"]||"video/mp4",width:parseInt(e["@_width"],10)||0,height:parseInt(e["@_height"],10)||0,bitrate:e["@_bitrate"]?parseInt(e["@_bitrate"],10):void 0,codec:e["@_codec"],scalable:e["@_scalable"],maintainAspectRatio:e["@_maintainAspectRatio"]}}):[]}},{key:"parseTrackingEvents",value:function(e){var t=this;return e?(Array.isArray(e)?e:[e]).map(function(e){return{event:e["@_event"],url:"string"==typeof e?e:e["#text"]||"",offset:e["@_offset"]?t.parseDuration(e["@_offset"]):void 0}}):[]}},{key:"parseErrors",value:function(e){return e?(Array.isArray(e)?e:[e]).map(function(e){return"string"==typeof e?e:e["#text"]||""}):[]}},{key:"parseDuration",value:function(e){if("number"==typeof e)return e;if("string"!=typeof e)return 0;if(e.endsWith("%"))return parseFloat(e)/100;var t=e.match(/(\d+):(\d+):(\d+(?:\.\d+)?)/);if(t){var n=u(t,4),r=n[1],i=n[2],a=n[3];return 3600*parseInt(r,10)+60*parseInt(i,10)+parseFloat(a)}return parseFloat(e)||0}},{key:"selectBestMediaFile",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2500;if(0===e.length)return null;var n=e.filter(function(e){return e.type.includes("mp4")||e.type.includes("video/mp4")});return c(n.length>0?n:e).sort(function(e,n){var r=e.bitrate||0,i=n.bitrate||0,a=e.height>1080?1e4:0,o=n.height>1080?1e4:0;return Math.abs(r-t)+a-(Math.abs(i-t)+o)})[0]||null}},{key:"aggregateTrackingEvents",value:function(e){var t,n,r=[],i=a(e);try{for(i.s();!(n=i.n()).done;){var o,s=a(n.value.creatives);try{for(s.s();!(o=s.n()).done;){var l=o.value;(null==(t=l.linear)?void 0:t.trackingEvents)&&r.push.apply(r,c(l.linear.trackingEvents))}}catch(u){s.e(u)}finally{s.f()}}}catch(u){i.e(u)}finally{i.f()}return r}},{key:"aggregateImpressions",value:function(e){var t,n=[],r=a(e);try{for(r.s();!(t=r.n()).done;){var i,o=a(t.value.impressions);try{for(o.s();!(i=o.n()).done;){var s=i.value;n.push(s.url)}}catch(l){o.e(l)}finally{o.f()}}}catch(l){r.e(l)}finally{r.f()}return n}},{key:"log",value:function(e){this.config.debug&&console.log("[VASTParser] ".concat(e))}}])}();function C(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e;return n=(n=n.replace(/\[TIMESTAMP\]/g,Date.now().toString())).replace(/\[CACHEBUSTING\]/g,Math.random().toString(36).substring(2,15)),t.assetUri&&(n=n.replace(/\[ASSETURI\]/g,encodeURIComponent(t.assetUri))),void 0!==t.contentPlayhead&&(n=n.replace(/\[CONTENTPLAYHEAD\]/g,_(t.contentPlayhead))),void 0!==t.adPlayhead&&(n=n.replace(/\[ADPLAYHEAD\]/g,_(t.adPlayhead))),void 0!==t.errorCode&&(n=n.replace(/\[ERRORCODE\]/g,t.errorCode.toString())),void 0!==t.breakPosition&&(n=n.replace(/\[BREAKPOSITION\]/g,t.breakPosition.toString())),t.adType&&(n=n.replace(/\[ADTYPE\]/g,t.adType)),n}function _(e){var t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=Math.floor(e%60),i=Math.floor(e%1*1e3);return t.toString().padStart(2,"0")+":"+n.toString().padStart(2,"0")+":"+r.toString().padStart(2,"0")+"."+i.toString().padStart(3,"0")}var I=function(e){return e.WebOS="webos",e.Tizen="tizen",e.Vidaa="vidaa",e.WhaleOS="whaleos",e.FireTV="firetv",e.Roku="roku",e.Xbox="xbox",e.PlayStation="playstation",e.AndroidTV="androidtv",e.Vizio="vizio",e.Generic="generic",e}(I||{}),M=function(e){return e.Enter="enter",e.Back="back",e.Left="left",e.Right="right",e.Up="up",e.Down="down",e.Play="play",e.Pause="pause",e.PlayPause="playPause",e.Stop="stop",e.FastForward="fastForward",e.Rewind="rewind",e.Menu="menu",e.Info="info",e.Red="red",e.Green="green",e.Yellow="yellow",e.Blue="blue",e.ChannelUp="channelUp",e.ChannelDown="channelDown",e.VolumeUp="volumeUp",e.VolumeDown="volumeDown",e.Mute="mute",e}(M||{}),F=(o(o(o(o(o(o(o(o(o(o(h={},"webos",{13:"enter",461:"back",37:"left",38:"up",39:"right",40:"down",415:"play",19:"pause",413:"stop",417:"fastForward",412:"rewind",457:"info",403:"red",404:"green",405:"yellow",406:"blue",33:"channelUp",34:"channelDown"}),"tizen",{13:"enter",10009:"back",37:"left",38:"up",39:"right",40:"down",415:"play",19:"pause",10252:"playPause",413:"stop",417:"fastForward",412:"rewind",457:"info",403:"red",404:"green",405:"yellow",406:"blue",427:"channelUp",428:"channelDown",447:"volumeUp",448:"volumeDown",449:"mute"}),"vidaa",{13:"enter",8:"back",27:"back",37:"left",38:"up",39:"right",40:"down",415:"play",19:"pause",413:"stop",417:"fastForward",412:"rewind"}),"whaleos",{13:"enter",27:"back",37:"left",38:"up",39:"right",40:"down",415:"play",19:"pause",413:"stop"}),"firetv",{13:"enter",4:"back",27:"back",37:"left",38:"up",39:"right",40:"down",85:"playPause",126:"play",127:"pause",89:"rewind",90:"fastForward",82:"menu"}),"roku",{13:"enter",27:"back",8:"back",37:"left",38:"up",39:"right",40:"down",179:"playPause",178:"stop",228:"fastForward",227:"rewind"}),"xbox",{13:"enter",27:"back",37:"left",38:"up",39:"right",40:"down",195:"menu",196:"menu"}),"playstation",{13:"enter",27:"back",37:"left",38:"up",39:"right",40:"down"}),"androidtv",{13:"enter",4:"back",27:"back",37:"left",38:"up",39:"right",40:"down",85:"playPause",126:"play",127:"pause",89:"rewind",90:"fastForward",82:"menu"}),"vizio",{13:"enter",27:"back",8:"back",37:"left",38:"up",39:"right",40:"down",415:"play",19:"pause"}),o(h,"generic",{13:"enter",27:"back",8:"back",37:"left",38:"up",39:"right",40:"down",32:"playPause",80:"play",83:"stop",77:"mute"})),L=(o(o(o(o(o(o(o(o(o(o(v={},"tizen",[/Tizen/i,/SMART-TV.*Samsung/i]),"webos",[/Web0S/i,/WebOS/i,/LG.*NetCast/i,/LGE.*TV/i]),"vidaa",[/Vidaa/i,/VIDAA/i,/Hisense/i]),"whaleos",[/WhaleTV/i,/Whale/i]),"firetv",[/AFT/i,/AFTS/i,/AFTM/i,/Amazon.*Fire/i]),"roku",[/Roku/i]),"xbox",[/Xbox/i,/Edge.*Xbox/i]),"playstation",[/PlayStation/i,/PS4/i,/PS5/i]),"androidtv",[/Android.*TV/i,/Chromecast/i,/BRAVIA/i,/SHIELD/i]),"vizio",[/VIZIO/i,/SmartCast/i]),o(v,"generic",[])),N=Object.defineProperty,D=Object.defineProperties,V=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertySymbols,W=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,B=function(e,t,n){return t in e?N(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n},z=function(e,t){for(var n in t||(t={}))W.call(t,n)&&B(e,n,t[n]);if(j){var r,i=a(j(t));try{for(i.s();!(r=i.n()).done;){n=r.value;U.call(t,n)&&B(e,n,t[n])}}catch(o){i.e(o)}finally{i.f()}}return e},G=function(e,t){return D(e,V(t))},K=function(e,t,n){return B(e,"symbol"!==f(t)?t+"":t,n)},H=function(){return i(function e(){r(this,e),K(this,"platform"),K(this,"capabilities"),K(this,"deviceInfo"),K(this,"keyMap"),K(this,"reverseKeyMap"),this.platform=this.detectPlatform(),this.keyMap=F[this.platform],this.reverseKeyMap=this.buildReverseKeyMap(),this.capabilities=this.detectCapabilities(),this.deviceInfo=this.detectDeviceInfo()},[{key:"detectPlatform",value:function(){if("undefined"==typeof window||"undefined"==typeof navigator)return I.Generic;var e=navigator.userAgent,t=window;if(t.tizen)return I.Tizen;if(t.webOS||t.PalmSystem)return I.WebOS;for(var n=0,r=Object.entries(L);n<r.length;n++){var i=u(r[n],2),o=i[0],s=i[1];if(o!==I.Generic){var l,c=a(s);try{for(c.s();!(l=c.n()).done;){if(l.value.test(e))return o}}catch(d){c.e(d)}finally{c.f()}}}return I.Generic}},{key:"detectCapabilities",value:function(){var e="undefined"!=typeof navigator,t="undefined"!=typeof document,n="undefined"!=typeof window,r={sendBeacon:e&&"sendBeacon"in navigator,fetchKeepalive:"undefined"!=typeof fetch,mutedAutoplayRequired:!0,fullscreen:t&&("fullscreenEnabled"in document||"webkitFullscreenEnabled"in document),hardwareDecodeInfo:!1,hdr:!1,hdr10Plus:!1,dolbyVision:!1,dolbyAtmos:!1,hevc:this.isCodecSupported('video/mp4; codecs="hvc1"'),vp9:this.isCodecSupported('video/webm; codecs="vp9"'),av1:this.isCodecSupported('video/mp4; codecs="av01.0.05M.08"'),maxResolution:this.detectMaxResolution(),touch:n&&"ontouchstart"in window,voice:!1};switch(this.platform){case I.Tizen:return G(z({},r),{hardwareDecodeInfo:!0,hdr:!0,hevc:!0,voice:!0});case I.WebOS:return G(z({},r),{hardwareDecodeInfo:!0,hdr:!0,dolbyVision:!0,dolbyAtmos:!0,hevc:!0,voice:!0});case I.FireTV:return G(z({},r),{hdr:!0,hdr10Plus:!0,dolbyVision:!0,hevc:!0,voice:!0});case I.Roku:return G(z({},r),{hdr:!0,dolbyVision:!0,hevc:!0,voice:!0});case I.Xbox:return G(z({},r),{hdr:!0,dolbyVision:!0,dolbyAtmos:!0,hevc:!0,av1:!0,voice:!0});case I.PlayStation:return G(z({},r),{hdr:!0,hevc:!0});case I.AndroidTV:return G(z({},r),{hdr:!0,dolbyVision:!0,hevc:!0,vp9:!0,voice:!0});default:return r}}},{key:"detectDeviceInfo",value:function(){var e,t,n,r={platform:this.platform};"undefined"!=typeof window&&(r.screenWidth=null==(e=window.screen)?void 0:e.width,r.screenHeight=null==(t=window.screen)?void 0:t.height,r.devicePixelRatio=window.devicePixelRatio);var i=window;if(this.platform===I.Tizen&&(null==(n=i.tizen)?void 0:n.systeminfo))try{i.tizen.systeminfo.getPropertyValue("BUILD",function(e){r.model=e.model,r.manufacturer=e.manufacturer||"Samsung"})}catch(o){r.manufacturer="Samsung"}if(this.platform===I.WebOS&&i.webOSSystem)try{var a=i.webOSSystem.deviceInfo;r.model=null==a?void 0:a.modelName,r.manufacturer="LG",r.osVersion=null==a?void 0:a.version}catch(o){r.manufacturer="LG"}return r}},{key:"detectMaxResolution",value:function(){var e,t;if("undefined"==typeof window)return"unknown";var n=(null==(e=window.screen)?void 0:e.width)||0,r=(null==(t=window.screen)?void 0:t.height)||0,i=Math.max(n,r);return i>=3840?"4k":i>=1920?"1080p":i>=1280?"720p":"unknown"}},{key:"buildReverseKeyMap",value:function(){for(var e=new Map,t=0,n=Object.entries(this.keyMap);t<n.length;t++){var r=u(n[t],2),i=r[0],a=r[1],o=parseInt(i,10),s=e.get(a)||[];s.push(o),e.set(a,s)}return e}},{key:"normalizeKeyCode",value:function(e){var t;return null!=(t=this.keyMap[e])?t:null}},{key:"getKeyCodesForAction",value:function(e){return this.reverseKeyMap.get(e)||[]}},{key:"isCodecSupported",value:function(e){if("undefined"==typeof document)return!1;try{var t=document.createElement("video").canPlayType(e);return"probably"===t||"maybe"===t}catch(n){return!1}}},{key:"registerTizenKeys",value:function(){if(this.platform===I.Tizen){var e=window.tizen;if(null==e?void 0:e.tvinputdevice){["MediaPlay","MediaPause","MediaStop","MediaFastForward","MediaRewind","MediaPlayPause","ColorF0Red","ColorF1Green","ColorF2Yellow","ColorF3Blue","Info"].forEach(function(t){try{e.tvinputdevice.registerKey(t)}catch(n){}})}}}},{key:"registerWebOSKeys",value:function(){this.platform,I.WebOS}},{key:"getVideoAttributes",value:function(){var e={muted:!0,playsinline:!0,autoplay:!0,"webkit-playsinline":!0};switch(this.platform){case I.Tizen:e["data-samsung-immersive"]="true";break;case I.WebOS:e["data-lg-immersive"]="true";break;case I.FireTV:case I.AndroidTV:e["x-webkit-airplay"]="allow"}return e}},{key:"getRecommendedVideoSettings",value:function(){switch(this.platform){case I.Tizen:case I.WebOS:return{maxBitrate:15e3,preferredCodec:"hevc",maxResolution:"4k"};case I.FireTV:return{maxBitrate:1e4,preferredCodec:"hevc",maxResolution:"4k"};case I.Roku:return{maxBitrate:8e3,preferredCodec:"h264",maxResolution:"4k"};case I.Xbox:case I.PlayStation:return{maxBitrate:2e4,preferredCodec:"hevc",maxResolution:"4k"};default:return{maxBitrate:5e3,preferredCodec:"h264",maxResolution:"1080p"}}}},{key:"openExternalLink",value:function(e){if("undefined"!=typeof window)if(this.platform===I.Generic||this.platform===I.Tizen||this.platform===I.WebOS)try{window.open(e,"_blank"),this.debug("[Adgent] Opened external link: ".concat(e))}catch(t){this.debug("[Adgent] Failed to open external link: ".concat(t))}else this.debug("[Adgent] Opening external links not supported on ".concat(this.platform,": ").concat(e));else this.debug("[Adgent] Cannot open link (server-side): ".concat(e))}},{key:"debug",value:function(e){if(console.log("[Adgent] ".concat(e)),this.platform===I.WebOS&&"undefined"!=typeof window){var t=window;t.webOS&&t.webOS.service&&t.webOS.service.request("luna://com.webos.notification",{method:"createToast",parameters:{message:"[Adgent] ".concat(e)},onSuccess:function(){},onFailure:function(){}})}}}])}(),q=null;function X(){return q||(q=new H),q}var Q=Object.defineProperty,Y=Object.defineProperties,Z=Object.getOwnPropertyDescriptors,$=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,ee=Object.prototype.propertyIsEnumerable,te=function(e,t,n){return t in e?Q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n},ne=function(e,t){for(var n in t||(t={}))J.call(t,n)&&te(e,n,t[n]);if($){var r,i=a($(t));try{for(i.s();!(r=i.n()).done;){n=r.value;ee.call(t,n)&&te(e,n,t[n])}}catch(o){i.e(o)}finally{i.f()}}return e},re=function(e,t,n){return te(e,"symbol"!==f(t)?t+"":t,n)},ie=function(){return i(function e(){var t,n,i,a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};r(this,e),re(this,"config"),re(this,"trackingEvents"),re(this,"firedEvents"),re(this,"macroContext"),this.config={debug:null!=(t=o.debug)&&t,retry:null!=(n=o.retry)&&n,maxRetries:null!=(i=o.maxRetries)?i:3},this.trackingEvents=this.groupEventsByType(a),this.firedEvents=new Set,this.macroContext={}},[{key:"groupEventsByType",value:function(e){var t,n=new Map,r=a(e);try{for(r.s();!(t=r.n()).done;){var i=t.value,o=n.get(i.event)||[];o.push(i),n.set(i.event,o)}}catch(s){r.e(s)}finally{r.f()}return n}},{key:"updateMacroContext",value:function(e){this.macroContext=ne(ne({},this.macroContext),e)}},{key:"track",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=this.trackingEvents.get(e);if(n){var r,i=a(n);try{for(i.s();!(r=i.n()).done;){var o=r.value,s="".concat(e,":").concat(o.url);if(t&&this.firedEvents.has(s))this.log("Skipping duplicate event: ".concat(e));else{var l=C(o.url,this.macroContext);this.firePixel(l),t&&this.firedEvents.add(s)}}}catch(u){i.e(u)}finally{i.f()}}else this.log("No tracking URLs for event: ".concat(e))}},{key:"firePixel",value:function(e){var t=X();this.log("Firing pixel: ".concat(e));try{if(t.capabilities.sendBeacon&&navigator.sendBeacon(e))return;if(t.capabilities.fetchKeepalive)return void fetch(e,{method:"GET",keepalive:!0,mode:"no-cors",credentials:"omit"}).catch(function(){});this.fireImageBeacon(e)}catch(n){this.log("Failed to fire pixel: ".concat(e))}}},{key:"fireImageBeacon",value:function(e){new Image(1,1).src=e}},{key:"fireImpressions",value:function(e){var t,n=a(e);try{for(n.s();!(t=n.n()).done;){var r=C(t.value,this.macroContext);this.firePixel(r)}}catch(i){n.e(i)}finally{n.f()}}},{key:"fireError",value:function(e,t){var n,r,i=(n=ne({},this.macroContext),Y(n,Z({errorCode:t}))),o=a(e);try{for(o.s();!(r=o.n()).done;){var s=C(r.value,i);this.firePixel(s)}}catch(l){o.e(l)}finally{o.f()}}},{key:"reset",value:function(){this.firedEvents.clear()}},{key:"log",value:function(e){this.config.debug&&console.log("[AdTracker] ".concat(e))}}])}(),ae=Object.defineProperty,oe=Object.getOwnPropertySymbols,se=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable,ue=function(e,t,n){return t in e?ae(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n},ce=function(e,t){for(var n in t||(t={}))se.call(t,n)&&ue(e,n,t[n]);if(oe){var r,i=a(oe(t));try{for(i.s();!(r=i.n()).done;){n=r.value;le.call(t,n)&&ue(e,n,t[n])}}catch(o){i.e(o)}finally{i.f()}}return e},de=function(e,t,n){return ue(e,"symbol"!==f(t)?t+"":t,n)},fe=function(e,t,n){return new Promise(function(r,i){var a=function(e){try{s(n.next(e))}catch(t){i(t)}},o=function(e){try{s(n.throw(e))}catch(t){i(t)}},s=function(e){return e.done?r(e.value):Promise.resolve(e.value).then(a,o)};s((n=n.apply(e,t)).next())})},pe={targetBitrate:2500,maxWrapperDepth:5,timeout:1e4,debug:!1,skipButtonText:"Skip Ad"},he=function(){return i(function e(t){r(this,e),de(this,"config"),de(this,"platform"),de(this,"parser"),de(this,"videoElement",null),de(this,"overlayElement",null),de(this,"skipButtonElement",null),de(this,"progressElement",null),de(this,"tracker",null),de(this,"state"),de(this,"ads",[]),de(this,"listeners",new Set),de(this,"eventListeners",new Map),de(this,"quartilesFired",new Set),de(this,"boundKeyHandler",null),de(this,"focusTrap",null),this.config=ce(ce({},pe),t),this.platform=X(),this.parser=new x({maxWrapperDepth:this.config.maxWrapperDepth,timeout:this.config.timeout,debug:this.config.debug}),this.state={status:y.Idle,currentTime:0,duration:0,muted:!0,volume:1,canSkip:!1,skipCountdown:0,mediaFile:null,error:null},"tizen"===this.platform.platform&&this.platform.registerTizenKeys()},[{key:"init",value:function(){return fe(this,null,s().m(function e(){var t,n,r,i,a,o,l,u;return s().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.config.container){e.n=1;break}throw new Error("Container element not found");case 1:return this.updateState({status:y.Loading}),e.p=2,e.n=3,this.parser.parse(this.config.vastUrl);case 3:if((r=e.v).success&&r.response){e.n=4;break}throw this.createError((null==(t=r.error)?void 0:t.code)||m.NO_VAST_RESPONSE,(null==(n=r.error)?void 0:n.message)||"Failed to parse VAST");case 4:if(this.ads=r.response.ads,0!==this.ads.length){e.n=5;break}throw this.createError(m.NO_VAST_RESPONSE,"No ads in VAST response");case 5:if(i=this.getFirstLinearCreative()){e.n=6;break}throw this.createError(m.GENERAL_LINEAR_ERROR,"No linear creative found");case 6:if(a=this.parser.selectBestMediaFile(i.mediaFiles,this.config.targetBitrate)){e.n=7;break}throw this.createError(m.FILE_NOT_FOUND,"No suitable media file found");case 7:return this.updateState({mediaFile:a}),o=this.parser.aggregateTrackingEvents(this.ads),this.tracker=new ie(o,{debug:this.config.debug}),this.tracker.updateMacroContext({assetUri:a.url}),this.createVideoElement(a),this.setupFocusManagement(),e.n=8,this.attemptAutoplay();case 8:e.n=10;break;case 9:e.p=9,u=e.v,l=u instanceof Error?this.createError(m.UNDEFINED_ERROR,u.message):u,this.handleError(l);case 10:return e.a(2)}},e,this,[[2,9]])}))}},{key:"getFirstLinearCreative",value:function(){var e,t=a(this.ads);try{for(t.s();!(e=t.n()).done;){var n,r=a(e.value.creatives);try{for(r.s();!(n=r.n()).done;){var i=n.value;if(i.linear)return i.linear}}catch(o){r.e(o)}finally{r.f()}}}catch(o){t.e(o)}finally{t.f()}return null}},{key:"createVideoElement",value:function(e){var t=this,n=document.createElement("video"),r=this.platform.getVideoAttributes();Object.entries(r).forEach(function(e){var t=u(e,2),r=t[0],i=t[1];"boolean"==typeof i?i&&n.setAttribute(r,""):n.setAttribute(r,i)}),n.removeAttribute("src"),n.innerHTML="";var i=document.createElement("source");if(i.src=e.url,i.type=e.type||"video/mp4",n.appendChild(i),n.setAttribute("crossorigin","anonymous"),n.style.cssText="\n width: 100%;\n height: 100%;\n object-fit: contain;\n background: #000;\n ",n.addEventListener("loadedmetadata",function(){t.updateState({duration:n.duration,status:y.Ready}),t.emit({type:"loaded"})}),n.addEventListener("timeupdate",function(){t.handleTimeUpdate(n)}),n.addEventListener("ended",function(){t.handleComplete()}),n.addEventListener("error",function(){var e=n.error;t.handleError(t.createError(m.MEDIA_NOT_SUPPORTED,(null==e?void 0:e.message)||"Video playback error"))}),n.addEventListener("play",function(){t.updateState({status:y.Playing})}),n.addEventListener("pause",function(){var e;t.state.status!==y.Completed&&(t.updateState({status:y.Paused}),t.emit({type:"pause"}),null==(e=t.tracker)||e.track("pause"))}),this.config.container.appendChild(n),this.videoElement=n,this.config.debug){["loadstart","loadeddata","canplay","waiting","playing"].forEach(function(e){var r=function(){return t.log("Video ".concat(e))};n.addEventListener(e,r),t.eventListeners.set(e,r)});var a=function(){return t.log("Video play event")};n.addEventListener("play",a),this.eventListeners.set("play",a)}this.log("Video element created with src: ".concat(e.url)),n.addEventListener("click",function(){t.onAdClick()}),n.style.cursor="pointer"}},{key:"attemptAutoplay",value:function(){return fe(this,null,s().m(function e(){var t;return s().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.videoElement){e.n=1;break}return e.a(2);case 1:return e.p=1,e.n=2,this.videoElement.play();case 2:this.handlePlaybackStart(),e.n=4;break;case 3:e.p=3,t=e.v,console.error("[Adgent] Autoplay failed details:",t),this.log("Autoplay failed: ".concat(t)),this.showStartOverlay();case 4:return e.a(2)}},e,this,[[1,3]])}))}},{key:"showStartOverlay",value:function(){var e=this;if(this.updateState({status:y.WaitingForInteraction}),this.config.customStartOverlay)return this.overlayElement=this.config.customStartOverlay,void this.config.container.appendChild(this.overlayElement);var t=document.createElement("div");t.innerHTML='\n <div style="\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n display: table;\n background: rgba(0, 0, 0, 0.5);\n z-index: 100;\n ">\n <div style="display: table-cell; vertical-align: middle; text-align: center;">\n <button id="adgent-start-btn" style="\n width: 80px;\n height: 80px;\n background: rgba(0, 0, 0, 0.7);\n border: 3px solid #fff;\n border-radius: 50%;\n cursor: pointer;\n display: inline-block;\n line-height: 80px;\n text-align: center;\n color: #fff;\n font-size: 40px;\n padding: 0 0 0 8px; /* Optical center for triangle */\n ">\n ▶\n </button>\n </div>\n </div>\n ',t.style.cssText="position: absolute; top: 0; left: 0; width: 100%; height: 100%;";var n=t.querySelector("#adgent-start-btn");null==n||n.addEventListener("click",function(){return e.onStartClick()}),this.config.container.style.position="relative",this.config.container.appendChild(t),this.overlayElement=t,null==n||n.focus()}},{key:"onAdClick",value:function(){var e,t,n,r,i,a=this;if(this.state.status===y.Playing){var o=this.getFirstLinearCreative();if(o){var s=null==(e=o.videoClicks)?void 0:e.clickThrough,l=null==s?void 0:s.url;if(l)this.log("Ad clicked. Opening: ".concat(l)),null==(t=this.videoElement)||t.pause(),((null==(n=o.videoClicks)?void 0:n.clickTracking)||[]).forEach(function(e){var t;e.url&&(null==(t=a.tracker)||t.firePixel(e.url))}),this.platform.openExternalLink(l),this.emit({type:"click",data:{url:l}}),null==(i=(r=this.config).onClick)||i.call(r,l)}}}},{key:"onStartClick",value:function(){return fe(this,null,s().m(function e(){var t;return s().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.removeOverlay(),!this.videoElement){e.n=4;break}return e.p=1,e.n=2,this.videoElement.play();case 2:this.handlePlaybackStart(),e.n=4;break;case 3:e.p=3,t=e.v,this.handleError(this.createError(m.GENERAL_LINEAR_ERROR,"Playback failed: ".concat(t)));case 4:return e.a(2)}},e,this,[[1,3]])}))}},{key:"removeOverlay",value:function(){this.overlayElement&&(this.overlayElement.remove(),this.overlayElement=null)}},{key:"handlePlaybackStart",value:function(){var e,t,n,r,i;this.updateState({status:y.Playing}),this.emit({type:"start"}),null==(t=(e=this.config).onStart)||t.call(e);var a=this.parser.aggregateImpressions(this.ads);null==(n=this.tracker)||n.fireImpressions(a),null==(r=this.tracker)||r.track("start"),null==(i=this.tracker)||i.track("creativeView"),this.setupSkipButton(),this.setupProgressUI(),this.log("Playback started")}},{key:"handleTimeUpdate",value:function(e){var t,n,r,i=e.currentTime,a=e.duration;if(a&&!isNaN(a)){var o=i/a*100,s=this.calculateQuartile(o);this.updateState({currentTime:i,duration:a}),this.updateSkipCountdown(i),null==(t=this.tracker)||t.updateMacroContext({adPlayhead:i}),this.updateProgressUI(i,a);var l={currentTime:i,duration:a,percentage:o,quartile:s};this.emit({type:"progress",data:l}),null==(r=(n=this.config).onProgress)||r.call(n,l),this.fireQuartileEvents(o)}}},{key:"calculateQuartile",value:function(e){return e>=100?4:e>=75?3:e>=50?2:e>=25?1:0}},{key:"fireQuartileEvents",value:function(e){for(var t,n=0,r=[{threshold:25,event:"firstQuartile"},{threshold:50,event:"midpoint"},{threshold:75,event:"thirdQuartile"}];n<r.length;n++){var i=r[n],a=i.threshold,o=i.event;e>=a&&!this.quartilesFired.has(a)&&(this.quartilesFired.add(a),null==(t=this.tracker)||t.track(o),this.emit({type:"quartile",data:{quartile:o}}),this.log("Quartile fired: ".concat(o)))}}},{key:"setupSkipButton",value:function(){var e,t=this,n=this.getFirstLinearCreative(),r=null!=(e=this.config.skipOffset)?e:null==n?void 0:n.skipOffset;if(r&&!(r<=0)){this.updateState({skipCountdown:r,canSkip:!1});var i=document.createElement("button");i.id="adgent-skip-btn",i.style.cssText="\n position: absolute;\n bottom: 20px;\n right: 20px;\n padding: 12px 24px;\n font-size: 16px;\n background: rgba(0, 0, 0, 0.7);\n color: #fff;\n border: 2px solid #fff;\n border-radius: 4px;\n cursor: pointer;\n z-index: 101;\n transition: opacity 0.3s;\n ",i.textContent="Skip in ".concat(r,"s"),i.addEventListener("click",function(){return t.skip()}),this.config.container.appendChild(i),this.skipButtonElement=i}}},{key:"updateSkipCountdown",value:function(e){var t,n=this.getFirstLinearCreative(),r=null!=(t=this.config.skipOffset)?t:null==n?void 0:n.skipOffset;if(r&&this.skipButtonElement){var i=Math.max(0,r-e);this.updateState({skipCountdown:i}),i<=0&&!this.state.canSkip?(this.updateState({canSkip:!0}),this.skipButtonElement.textContent=this.config.skipButtonText,this.skipButtonElement.style.opacity="1",this.skipButtonElement.focus()):i>0&&(this.skipButtonElement.textContent="Skip in ".concat(Math.ceil(i),"s"),this.skipButtonElement.style.opacity="0.6")}}},{key:"skip",value:function(){var e,t,n;this.state.canSkip?(null==(e=this.tracker)||e.track("skip"),this.emit({type:"skip"}),null==(n=(t=this.config).onSkip)||n.call(t),this.destroy(),this.log("Ad skipped")):this.log("Skip not available yet")}},{key:"handleComplete",value:function(){var e,t,n;this.updateState({status:y.Completed}),null==(e=this.tracker)||e.track("complete"),this.emit({type:"complete"}),null==(n=(t=this.config).onComplete)||n.call(t),this.log("Ad completed")}},{key:"handleError",value:function(e){var t,n,r;this.updateState({status:y.Error,error:e});var i,o=[],s=a(this.ads);try{for(s.s();!(i=s.n()).done;){var l=i.value;o.push.apply(o,c(l.errors))}}catch(u){s.e(u)}finally{s.f()}null==(t=this.tracker)||t.fireError(o,e.code),this.emit({type:"error",data:e}),null==(r=(n=this.config).onError)||r.call(n,e),this.log("Error: ".concat(e.message))}},{key:"setupFocusManagement",value:function(){var e=this;this.focusTrap=document.createElement("div"),this.focusTrap.tabIndex=0,this.focusTrap.style.cssText="position: absolute; opacity: 0; width: 0; height: 0;",this.config.container.appendChild(this.focusTrap),this.focusTrap.focus(),this.boundKeyHandler=function(t){var n=e.platform.normalizeKeyCode(t.keyCode);n&&(t.preventDefault(),t.stopPropagation(),e.handleKeyAction(n))},document.addEventListener("keydown",this.boundKeyHandler,!0)}},{key:"setupProgressUI",value:function(){var e=document.createElement("div");e.style.cssText="\n position: absolute;\n top: 20px;\n left: 20px;\n background: rgba(0, 0, 0, 0.7);\n color: #fff;\n padding: 6px 12px;\n border-radius: 4px;\n font-size: 14px;\n font-family: sans-serif;\n z-index: 101;\n display: block;\n white-space: nowrap;\n ",e.innerHTML='\n <span style="display: inline-block; vertical-align: middle; margin-right: 8px; background: #f4b400; color: #000; padding: 2px 4px; border-radius: 2px; font-weight: bold; font-size: 12px;">Ad</span>\n <span id="adgent-progress-text" style="display: inline-block; vertical-align: middle;">1 of '.concat(this.ads.length," • 0:00</span>\n "),this.config.container.appendChild(e),this.progressElement=e}},{key:"updateProgressUI",value:function(e,t){if(this.progressElement){var n=Math.ceil(t-e),r=Math.floor(n/60),i=n%60,a="".concat(r,":").concat(i.toString().padStart(2,"0")),o=this.progressElement.querySelector("#adgent-progress-text");if(o){o.textContent="".concat(1," of ").concat(this.ads.length," • ").concat(a)}}}},{key:"handleKeyAction",value:function(e){var t,n;switch(this.log("Key action: ".concat(e)),e){case M.Enter:this.state.status===y.WaitingForInteraction?this.onStartClick():this.state.canSkip&&this.skip();break;case M.Back:this.config.onClose?(this.log("Back pressed - user cancelling"),this.config.onClose(),this.destroy()):(this.log("Back pressed - skipping"),this.emit({type:"skip"}),this.config.onSkip&&this.config.onSkip(),this.destroy());break;case M.Play:null==(t=this.videoElement)||t.play();break;case M.Pause:null==(n=this.videoElement)||n.pause();case M.Left:case M.Right:case M.Up:case M.Down:}}},{key:"unmute",value:function(){var e;this.videoElement&&(this.videoElement.muted=!1,this.updateState({muted:!1}),null==(e=this.tracker)||e.track("unmute"),this.emit({type:"unmute"}))}},{key:"mute",value:function(){var e;this.videoElement&&(this.videoElement.muted=!0,this.updateState({muted:!0}),null==(e=this.tracker)||e.track("mute"),this.emit({type:"mute"}))}},{key:"on",value:function(e){var t=this;return this.listeners.add(e),function(){return t.listeners.delete(e)}}},{key:"getState",value:function(){return ce({},this.state)}},{key:"destroy",value:function(){var e,t,n,r,i,a=this;this.boundKeyHandler&&(document.removeEventListener("keydown",this.boundKeyHandler,!0),this.boundKeyHandler=null),this.videoElement&&(this.eventListeners.forEach(function(e,t){var n;null==(n=a.videoElement)||n.removeEventListener(t,e)}),this.eventListeners.clear(),this.videoElement.remove()),null==(e=this.overlayElement)||e.remove(),null==(t=this.skipButtonElement)||t.remove(),null==(n=this.progressElement)||n.remove(),null==(r=this.focusTrap)||r.remove(),this.videoElement=null,this.overlayElement=null,this.skipButtonElement=null,this.progressElement=null,this.focusTrap=null,null==(i=this.tracker)||i.reset(),this.quartilesFired.clear(),this.listeners.clear(),this.ads=[],this.emit({type:"destroy"}),this.log("Player destroyed")}},{key:"updateState",value:function(e){this.state=ce(ce({},this.state),e)}},{key:"emit",value:function(e){var t,n=a(this.listeners);try{for(n.s();!(t=n.n()).done;){var r=t.value;try{r(e)}catch(i){this.log("Listener error: ".concat(i))}}}catch(o){n.e(o)}finally{n.f()}}},{key:"createError",value:function(e,t){return{code:e,message:t,recoverable:arguments.length>2&&void 0!==arguments[2]&&arguments[2]}}},{key:"log",value:function(e){this.config.debug&&this.platform.debug(e)}}])}();e.AdPlayer=he,e.AdTracker=ie,e.AdgentSDK=he,e.DEFAULT_KEY_CODES=F,e.KeyAction=M,e.PLATFORM_DETECTION_PATTERNS=L,e.Platform=I,e.PlatformAdapter=H,e.PlaybackStatus=y,e.VASTErrorCode=m,e.VASTParser=x,e.getPlatformAdapter=X,e.replaceMacros=C,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
3
+ var e,t,n="function"==typeof Symbol?Symbol:{},r=n.iterator||"@@iterator",i=n.toStringTag||"@@toStringTag";function a(n,r,i,a){var s=r&&r.prototype instanceof u?r:u,c=Object.create(s.prototype);return l(c,"_invoke",function(n,r,i){var a,s,l,u=0,c=i||[],d=!1,f={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,n){return a=t,s=0,l=e,f.n=n,o}};function p(n,r){for(s=n,l=r,t=0;!d&&u&&!i&&t<c.length;t++){var i,a=c[t],p=f.p,h=a[2];n>3?(i=h===r)&&(l=a[(s=a[4])?5:(s=3,3)],a[4]=a[5]=e):a[0]<=p&&((i=n<2&&p<a[1])?(s=0,f.v=r,f.n=a[1]):p<h&&(i=n<3||a[0]>r||r>h)&&(a[4]=n,a[5]=r,f.n=h,s=0))}if(i||n>1)return o;throw d=!0,r}return function(i,c,h){if(u>1)throw TypeError("Generator is already running");for(d&&1===c&&p(c,h),s=c,l=h;(t=s<2?e:l)||!d;){a||(s?s<3?(s>1&&(f.n=-1),p(s,l)):f.n=l:f.v=l);try{if(u=2,a){if(s||(i="next"),t=a[i]){if(!(t=t.call(a,l)))throw TypeError("iterator result is not an object");if(!t.done)return t;l=t.value,s<2&&(s=0)}else 1===s&&(t=a.return)&&t.call(a),s<2&&(l=TypeError("The iterator does not provide a '"+i+"' method"),s=1);a=e}else if((t=(d=f.n<0)?l:n.call(r,f))!==o)break}catch(v){a=e,s=1,l=v}finally{u=1}}return{value:t,done:d}}}(n,i,a),!0),c}var o={};function u(){}function c(){}function d(){}t=Object.getPrototypeOf;var f=[][r]?t(t([][r]())):(l(t={},r,function(){return this}),t),p=d.prototype=u.prototype=Object.create(f);function h(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,d):(e.__proto__=d,l(e,i,"GeneratorFunction")),e.prototype=Object.create(p),e}return c.prototype=d,l(p,"constructor",d),l(d,"constructor",c),c.displayName="GeneratorFunction",l(d,i,"GeneratorFunction"),l(p),l(p,i,"Generator"),l(p,r,function(){return this}),l(p,"toString",function(){return"[object Generator]"}),(s=function(){return{w:a,m:h}})()}function l(e,t,n,r){var i=Object.defineProperty;try{i({},"",{})}catch(a){i=0}(l=function(e,t,n,r){function a(t,n){l(e,t,function(e){return this._invoke(t,n,e)})}t?i?i(e,t,{value:n,enumerable:!r,configurable:!r,writable:!r}):e[t]=n:(a("next",0),a("throw",1),a("return",2))})(e,t,n,r)}function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,i,a,o,s=[],l=!0,u=!1;try{if(a=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;l=!1}else for(;!(l=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);l=!0);}catch(c){u=!0,i=c}finally{try{if(!l&&null!=n.return&&(o=n.return(),Object(o)!==o))return}finally{if(u)throw i}}return s}}(e,t)||p(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(e){return function(e){if(Array.isArray(e))return n(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||p(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t);if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}function f(e){return(f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function p(e,t){if(e){if("string"==typeof e)return n(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}var h,v,y=function(e){return e.Idle="idle",e.Loading="loading",e.Ready="ready",e.Playing="playing",e.Paused="paused",e.Completed="completed",e.Error="error",e.WaitingForInteraction="waiting_for_interaction",e}(y||{}),m=function(e){return e[e.XML_PARSING_ERROR=100]="XML_PARSING_ERROR",e[e.VAST_SCHEMA_VALIDATION_ERROR=101]="VAST_SCHEMA_VALIDATION_ERROR",e[e.VAST_VERSION_NOT_SUPPORTED=102]="VAST_VERSION_NOT_SUPPORTED",e[e.GENERAL_WRAPPER_ERROR=300]="GENERAL_WRAPPER_ERROR",e[e.WRAPPER_TIMEOUT=301]="WRAPPER_TIMEOUT",e[e.WRAPPER_LIMIT_REACHED=302]="WRAPPER_LIMIT_REACHED",e[e.NO_VAST_RESPONSE=303]="NO_VAST_RESPONSE",e[e.GENERAL_LINEAR_ERROR=400]="GENERAL_LINEAR_ERROR",e[e.FILE_NOT_FOUND=401]="FILE_NOT_FOUND",e[e.MEDIA_TIMEOUT=402]="MEDIA_TIMEOUT",e[e.MEDIA_NOT_SUPPORTED=403]="MEDIA_NOT_SUPPORTED",e[e.GENERAL_COMPANION_ERROR=600]="GENERAL_COMPANION_ERROR",e[e.UNDEFINED_ERROR=900]="UNDEFINED_ERROR",e}(m||{}),g=Object.defineProperty,b=Object.defineProperties,k=Object.getOwnPropertyDescriptors,E=Object.getOwnPropertySymbols,w=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable,A=function(e,t,n){return t in e?g(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n},T=function(e,t){for(var n in t||(t={}))w.call(t,n)&&A(e,n,t[n]);if(E){var r,i=a(E(t));try{for(i.s();!(r=i.n()).done;){n=r.value;S.call(t,n)&&A(e,n,t[n])}}catch(o){i.e(o)}finally{i.f()}}return e},P=function(e,t){return b(e,k(t))},O=function(e,t,n){return A(e,"symbol"!==f(t)?t+"":t,n)},R=function(e,t,n){return new Promise(function(r,i){var a=function(e){try{s(n.next(e))}catch(t){i(t)}},o=function(e){try{s(n.throw(e))}catch(t){i(t)}},s=function(e){return e.done?r(e.value):Promise.resolve(e.value).then(a,o)};s((n=n.apply(e,t)).next())})},x=function(){return i(function e(){var n,i,a,o,s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};r(this,e),O(this,"config"),O(this,"xmlParser"),this.config={maxWrapperDepth:null!=(n=s.maxWrapperDepth)?n:5,timeout:null!=(i=s.timeout)?i:1e4,debug:null!=(a=s.debug)&&a,fetchFn:null!=(o=s.fetchFn)?o:fetch.bind(globalThis)},this.xmlParser=new t.XMLParser({ignoreAttributes:!1,attributeNamePrefix:"@_",textNodeName:"#text",parseAttributeValue:!0,trimValues:!0})},[{key:"parse",value:function(e){return R(this,null,s().m(function t(){var n,r,i;return s().w(function(t){for(;;)switch(t.p=t.n){case 0:return t.p=0,t.n=1,this.fetchAndParse(e,0);case 1:return n=t.v,t.a(2,{success:!0,response:n});case 2:return t.p=2,i=t.v,r=i instanceof Error?i.message:"Unknown error",t.a(2,{success:!1,error:{code:m.GENERAL_WRAPPER_ERROR,message:r}})}},t,this,[[0,2]])}))}},{key:"fetchAndParse",value:function(e,t){return R(this,null,s().m(function n(){var r,i,a,o=this;return s().w(function(n){for(;;)switch(n.n){case 0:if(!(t>=this.config.maxWrapperDepth)){n.n=1;break}throw new Error("Wrapper limit exceeded (max: ".concat(this.config.maxWrapperDepth,")"));case 1:return this.log("Fetching VAST (depth: ".concat(t,"): ").concat(e)),n.n=2,this.fetchWithTimeout(e);case 2:return r=n.v,i=this.parseXml(r),n.n=3,Promise.all(i.ads.map(function(e){return R(o,null,s().m(function n(){var r;return s().w(function(n){for(;;)switch(n.n){case 0:if(!(null==(r=e.wrapper)?void 0:r.vastAdTagURI)){n.n=1;break}return n.a(2,this.resolveWrapper(e,t+1));case 1:return n.a(2,e)}},n,this)}))}));case 3:return a=n.v,n.a(2,P(T({},i),{ads:a.flat()}))}},n,this)}))}},{key:"resolveWrapper",value:function(e,t){return R(this,null,s().m(function n(){var r,i,a,o=this;return s().w(function(n){for(;;)switch(n.p=n.n){case 0:if(null==(r=e.wrapper)?void 0:r.vastAdTagURI){n.n=1;break}return n.a(2,[e]);case 1:return n.p=1,n.n=2,this.fetchAndParse(e.wrapper.vastAdTagURI,t);case 2:return i=n.v,n.a(2,i.ads.map(function(t){return o.mergeWrapperTracking(e,t)}));case 3:if(n.p=3,a=n.v,this.log("Wrapper resolution failed: ".concat(a)),!e.wrapper.fallbackOnNoAd){n.n=4;break}return n.a(2,[]);case 4:throw a;case 5:return n.a(2)}},n,this,[[1,3]])}))}},{key:"mergeWrapperTracking",value:function(e,t){var n=this;return P(T({},t),{impressions:[].concat(c(e.impressions),c(t.impressions)),errors:[].concat(c(e.errors),c(t.errors)),creatives:t.creatives.map(function(t){return P(T({},t),{linear:t.linear?P(T({},t.linear),{trackingEvents:[].concat(c(n.getWrapperTrackingEvents(e)),c(t.linear.trackingEvents))}):void 0})})})}},{key:"getWrapperTrackingEvents",value:function(e){var t,n,r=[],i=a(e.creatives);try{for(i.s();!(n=i.n()).done;){var o=n.value;(null==(t=o.linear)?void 0:t.trackingEvents)&&r.push.apply(r,c(o.linear.trackingEvents))}}catch(s){i.e(s)}finally{i.f()}return r}},{key:"fetchWithTimeout",value:function(e){return R(this,null,s().m(function t(){var n,r,i;return s().w(function(t){for(;;)switch(t.p=t.n){case 0:return n=new AbortController,r=setTimeout(function(){return n.abort()},this.config.timeout),t.p=1,t.n=2,this.config.fetchFn(e,{signal:n.signal});case 2:if((i=t.v).ok){t.n=3;break}throw new Error("HTTP ".concat(i.status,": ").concat(i.statusText));case 3:return t.a(2,i.text());case 4:return t.p=4,clearTimeout(r),t.f(4);case 5:return t.a(2)}},t,this,[[1,,4,5]])}))}},{key:"parseXml",value:function(e){var t=this.xmlParser.parse(e).VAST;if(!t)throw new Error("Invalid VAST: missing VAST element");return{version:t["@_version"]||"4.0",ads:this.parseAds(t.Ad),errors:this.parseErrors(t.Error)}}},{key:"parseAds",value:function(e){var t=this;return e?(Array.isArray(e)?e:[e]).map(function(e){return t.parseAd(e)}):[]}},{key:"parseAd",value:function(e){var t,n,r,i=!!e.Wrapper,a=e.InLine||e.Wrapper;return{id:e["@_id"]||"",sequence:e["@_sequence"],adSystem:(null==a?void 0:a.AdSystem)?{name:"string"==typeof a.AdSystem?a.AdSystem:a.AdSystem["#text"]||"",version:null==(t=a.AdSystem)?void 0:t["@_version"]}:void 0,adTitle:null==a?void 0:a.AdTitle,impressions:this.parseImpressions(null==a?void 0:a.Impression),errors:this.parseErrors(null==a?void 0:a.Error),creatives:this.parseCreatives(null==(n=null==a?void 0:a.Creatives)?void 0:n.Creative),wrapper:i?{vastAdTagURI:a.VASTAdTagURI,followAdditionalWrappers:!1!==a["@_followAdditionalWrappers"],allowMultipleAds:a["@_allowMultipleAds"],fallbackOnNoAd:a["@_fallbackOnNoAd"]}:void 0,inLine:i?void 0:{adTitle:(null==a?void 0:a.AdTitle)||"",description:null==a?void 0:a.Description,advertiser:null==a?void 0:a.Advertiser,creatives:this.parseCreatives(null==(r=null==a?void 0:a.Creatives)?void 0:r.Creative)}}}},{key:"parseImpressions",value:function(e){return e?(Array.isArray(e)?e:[e]).map(function(e){return{id:e["@_id"],url:"string"==typeof e?e:e["#text"]||""}}):[]}},{key:"parseCreatives",value:function(e){var t=this;return e?(Array.isArray(e)?e:[e]).map(function(e){return{id:e["@_id"],sequence:e["@_sequence"],adId:e["@_adId"],linear:e.Linear?t.parseLinear(e.Linear):void 0}}):[]}},{key:"parseLinear",value:function(e){var t,n;return{duration:this.parseDuration(e.Duration),skipOffset:e["@_skipoffset"]?this.parseDuration(e["@_skipoffset"]):void 0,mediaFiles:this.parseMediaFiles(null==(t=e.MediaFiles)?void 0:t.MediaFile),trackingEvents:this.parseTrackingEvents(null==(n=e.TrackingEvents)?void 0:n.Tracking),videoClicks:e.VideoClicks?{clickThrough:e.VideoClicks.ClickThrough?{id:e.VideoClicks.ClickThrough["@_id"],url:"string"==typeof e.VideoClicks.ClickThrough?e.VideoClicks.ClickThrough:e.VideoClicks.ClickThrough["#text"]||""}:void 0}:void 0,adParameters:e.AdParameters}}},{key:"parseMediaFiles",value:function(e){return e?(Array.isArray(e)?e:[e]).map(function(e){return{id:e["@_id"],url:"string"==typeof e?e:e["#text"]||"",delivery:e["@_delivery"]||"progressive",type:e["@_type"]||"video/mp4",width:parseInt(e["@_width"],10)||0,height:parseInt(e["@_height"],10)||0,bitrate:e["@_bitrate"]?parseInt(e["@_bitrate"],10):void 0,codec:e["@_codec"],scalable:e["@_scalable"],maintainAspectRatio:e["@_maintainAspectRatio"]}}):[]}},{key:"parseTrackingEvents",value:function(e){var t=this;return e?(Array.isArray(e)?e:[e]).map(function(e){return{event:e["@_event"],url:"string"==typeof e?e:e["#text"]||"",offset:e["@_offset"]?t.parseDuration(e["@_offset"]):void 0}}):[]}},{key:"parseErrors",value:function(e){return e?(Array.isArray(e)?e:[e]).map(function(e){return"string"==typeof e?e:e["#text"]||""}):[]}},{key:"parseDuration",value:function(e){if("number"==typeof e)return e;if("string"!=typeof e)return 0;if(e.endsWith("%"))return parseFloat(e)/100;var t=e.match(/(\d+):(\d+):(\d+(?:\.\d+)?)/);if(t){var n=u(t,4),r=n[1],i=n[2],a=n[3];return 3600*parseInt(r,10)+60*parseInt(i,10)+parseFloat(a)}return parseFloat(e)||0}},{key:"selectBestMediaFile",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2500;if(0===e.length)return null;var n=e.filter(function(e){return e.type.toLowerCase().startsWith("video/")});if(0===n.length)return null;var r=n.filter(function(e){return e.type.includes("mp4")||e.type.includes("video/mp4")});return c(r.length>0?r:n).sort(function(e,n){var r=e.bitrate||0,i=n.bitrate||0,a=e.height>1080?1e4:0,o=n.height>1080?1e4:0;return Math.abs(r-t)+a-(Math.abs(i-t)+o)})[0]||null}},{key:"aggregateTrackingEvents",value:function(e){var t,n,r=[],i=a(e);try{for(i.s();!(n=i.n()).done;){var o,s=a(n.value.creatives);try{for(s.s();!(o=s.n()).done;){var l=o.value;(null==(t=l.linear)?void 0:t.trackingEvents)&&r.push.apply(r,c(l.linear.trackingEvents))}}catch(u){s.e(u)}finally{s.f()}}}catch(u){i.e(u)}finally{i.f()}return r}},{key:"aggregateImpressions",value:function(e){var t,n=[],r=a(e);try{for(r.s();!(t=r.n()).done;){var i,o=a(t.value.impressions);try{for(o.s();!(i=o.n()).done;){var s=i.value;n.push(s.url)}}catch(l){o.e(l)}finally{o.f()}}}catch(l){r.e(l)}finally{r.f()}return n}},{key:"log",value:function(e){this.config.debug&&console.log("[VASTParser] ".concat(e))}}])}();function C(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=e;return n=(n=n.replace(/\[TIMESTAMP\]/g,Date.now().toString())).replace(/\[CACHEBUSTING\]/g,Math.random().toString(36).substring(2,15)),t.assetUri&&(n=n.replace(/\[ASSETURI\]/g,encodeURIComponent(t.assetUri))),void 0!==t.contentPlayhead&&(n=n.replace(/\[CONTENTPLAYHEAD\]/g,_(t.contentPlayhead))),void 0!==t.adPlayhead&&(n=n.replace(/\[ADPLAYHEAD\]/g,_(t.adPlayhead))),void 0!==t.errorCode&&(n=n.replace(/\[ERRORCODE\]/g,t.errorCode.toString())),void 0!==t.breakPosition&&(n=n.replace(/\[BREAKPOSITION\]/g,t.breakPosition.toString())),t.adType&&(n=n.replace(/\[ADTYPE\]/g,t.adType)),n}function _(e){var t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=Math.floor(e%60),i=Math.floor(e%1*1e3);return t.toString().padStart(2,"0")+":"+n.toString().padStart(2,"0")+":"+r.toString().padStart(2,"0")+"."+i.toString().padStart(3,"0")}var I=function(e){return e.WebOS="webos",e.Tizen="tizen",e.Vidaa="vidaa",e.WhaleOS="whaleos",e.FireTV="firetv",e.Roku="roku",e.Xbox="xbox",e.PlayStation="playstation",e.AndroidTV="androidtv",e.Vizio="vizio",e.Generic="generic",e}(I||{}),M=function(e){return e.Enter="enter",e.Back="back",e.Left="left",e.Right="right",e.Up="up",e.Down="down",e.Play="play",e.Pause="pause",e.PlayPause="playPause",e.Stop="stop",e.FastForward="fastForward",e.Rewind="rewind",e.Menu="menu",e.Info="info",e.Red="red",e.Green="green",e.Yellow="yellow",e.Blue="blue",e.ChannelUp="channelUp",e.ChannelDown="channelDown",e.VolumeUp="volumeUp",e.VolumeDown="volumeDown",e.Mute="mute",e}(M||{}),F=(o(o(o(o(o(o(o(o(o(o(h={},"webos",{13:"enter",461:"back",37:"left",38:"up",39:"right",40:"down",415:"play",19:"pause",413:"stop",417:"fastForward",412:"rewind",457:"info",403:"red",404:"green",405:"yellow",406:"blue",33:"channelUp",34:"channelDown"}),"tizen",{13:"enter",10009:"back",37:"left",38:"up",39:"right",40:"down",415:"play",19:"pause",10252:"playPause",413:"stop",417:"fastForward",412:"rewind",457:"info",403:"red",404:"green",405:"yellow",406:"blue",427:"channelUp",428:"channelDown",447:"volumeUp",448:"volumeDown",449:"mute"}),"vidaa",{13:"enter",8:"back",27:"back",37:"left",38:"up",39:"right",40:"down",415:"play",19:"pause",413:"stop",417:"fastForward",412:"rewind"}),"whaleos",{13:"enter",27:"back",37:"left",38:"up",39:"right",40:"down",415:"play",19:"pause",413:"stop"}),"firetv",{13:"enter",4:"back",27:"back",37:"left",38:"up",39:"right",40:"down",85:"playPause",126:"play",127:"pause",89:"rewind",90:"fastForward",82:"menu"}),"roku",{13:"enter",27:"back",8:"back",37:"left",38:"up",39:"right",40:"down",179:"playPause",178:"stop",228:"fastForward",227:"rewind"}),"xbox",{13:"enter",27:"back",37:"left",38:"up",39:"right",40:"down",195:"menu",196:"menu"}),"playstation",{13:"enter",27:"back",37:"left",38:"up",39:"right",40:"down"}),"androidtv",{13:"enter",4:"back",27:"back",37:"left",38:"up",39:"right",40:"down",85:"playPause",126:"play",127:"pause",89:"rewind",90:"fastForward",82:"menu"}),"vizio",{13:"enter",27:"back",8:"back",37:"left",38:"up",39:"right",40:"down",415:"play",19:"pause"}),o(h,"generic",{13:"enter",27:"back",8:"back",37:"left",38:"up",39:"right",40:"down",32:"playPause",80:"play",83:"stop",77:"mute"})),L=(o(o(o(o(o(o(o(o(o(o(v={},"tizen",[/Tizen/i,/SMART-TV.*Samsung/i]),"webos",[/Web0S/i,/WebOS/i,/LG.*NetCast/i,/LGE.*TV/i]),"vidaa",[/Vidaa/i,/VIDAA/i,/Hisense/i]),"whaleos",[/WhaleTV/i,/Whale/i]),"firetv",[/AFT/i,/AFTS/i,/AFTM/i,/Amazon.*Fire/i]),"roku",[/Roku/i]),"xbox",[/Xbox/i,/Edge.*Xbox/i]),"playstation",[/PlayStation/i,/PS4/i,/PS5/i]),"androidtv",[/Android.*TV/i,/Chromecast/i,/BRAVIA/i,/SHIELD/i]),"vizio",[/VIZIO/i,/SmartCast/i]),o(v,"generic",[])),N=Object.defineProperty,D=Object.defineProperties,V=Object.getOwnPropertyDescriptors,W=Object.getOwnPropertySymbols,j=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,B=function(e,t,n){return t in e?N(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n},z=function(e,t){for(var n in t||(t={}))j.call(t,n)&&B(e,n,t[n]);if(W){var r,i=a(W(t));try{for(i.s();!(r=i.n()).done;){n=r.value;U.call(t,n)&&B(e,n,t[n])}}catch(o){i.e(o)}finally{i.f()}}return e},G=function(e,t){return D(e,V(t))},K=function(e,t,n){return B(e,"symbol"!==f(t)?t+"":t,n)},H=function(){return i(function e(){r(this,e),K(this,"platform"),K(this,"capabilities"),K(this,"deviceInfo"),K(this,"keyMap"),K(this,"reverseKeyMap"),this.platform=this.detectPlatform(),this.keyMap=F[this.platform],this.reverseKeyMap=this.buildReverseKeyMap(),this.capabilities=this.detectCapabilities(),this.deviceInfo=this.detectDeviceInfo()},[{key:"detectPlatform",value:function(){if("undefined"==typeof window||"undefined"==typeof navigator)return I.Generic;var e=navigator.userAgent,t=window;if(t.tizen)return I.Tizen;if(t.webOS||t.PalmSystem)return I.WebOS;for(var n=0,r=Object.entries(L);n<r.length;n++){var i=u(r[n],2),o=i[0],s=i[1];if(o!==I.Generic){var l,c=a(s);try{for(c.s();!(l=c.n()).done;){if(l.value.test(e))return o}}catch(d){c.e(d)}finally{c.f()}}}return I.Generic}},{key:"detectCapabilities",value:function(){var e="undefined"!=typeof navigator,t="undefined"!=typeof document,n="undefined"!=typeof window,r={sendBeacon:e&&"sendBeacon"in navigator,fetchKeepalive:"undefined"!=typeof fetch,mutedAutoplayRequired:!0,fullscreen:t&&("fullscreenEnabled"in document||"webkitFullscreenEnabled"in document),hardwareDecodeInfo:!1,hdr:!1,hdr10Plus:!1,dolbyVision:!1,dolbyAtmos:!1,hevc:this.isCodecSupported('video/mp4; codecs="hvc1"'),vp9:this.isCodecSupported('video/webm; codecs="vp9"'),av1:this.isCodecSupported('video/mp4; codecs="av01.0.05M.08"'),maxResolution:this.detectMaxResolution(),touch:n&&"ontouchstart"in window,voice:!1};switch(this.platform){case I.Tizen:return G(z({},r),{hardwareDecodeInfo:!0,hdr:!0,hevc:!0,voice:!0});case I.WebOS:return G(z({},r),{hardwareDecodeInfo:!0,hdr:!0,dolbyVision:!0,dolbyAtmos:!0,hevc:!0,voice:!0});case I.FireTV:return G(z({},r),{hdr:!0,hdr10Plus:!0,dolbyVision:!0,hevc:!0,voice:!0});case I.Roku:return G(z({},r),{hdr:!0,dolbyVision:!0,hevc:!0,voice:!0});case I.Xbox:return G(z({},r),{hdr:!0,dolbyVision:!0,dolbyAtmos:!0,hevc:!0,av1:!0,voice:!0});case I.PlayStation:return G(z({},r),{hdr:!0,hevc:!0});case I.AndroidTV:return G(z({},r),{hdr:!0,dolbyVision:!0,hevc:!0,vp9:!0,voice:!0});default:return r}}},{key:"detectDeviceInfo",value:function(){var e,t,n,r={platform:this.platform};"undefined"!=typeof window&&(r.screenWidth=null==(e=window.screen)?void 0:e.width,r.screenHeight=null==(t=window.screen)?void 0:t.height,r.devicePixelRatio=window.devicePixelRatio);var i=window;if(this.platform===I.Tizen&&(null==(n=i.tizen)?void 0:n.systeminfo))try{i.tizen.systeminfo.getPropertyValue("BUILD",function(e){r.model=e.model,r.manufacturer=e.manufacturer||"Samsung"})}catch(o){r.manufacturer="Samsung"}if(this.platform===I.WebOS&&i.webOSSystem)try{var a=i.webOSSystem.deviceInfo;r.model=null==a?void 0:a.modelName,r.manufacturer="LG",r.osVersion=null==a?void 0:a.version}catch(o){r.manufacturer="LG"}return r}},{key:"detectMaxResolution",value:function(){var e,t;if("undefined"==typeof window)return"unknown";var n=(null==(e=window.screen)?void 0:e.width)||0,r=(null==(t=window.screen)?void 0:t.height)||0,i=Math.max(n,r);return i>=3840?"4k":i>=1920?"1080p":i>=1280?"720p":"unknown"}},{key:"buildReverseKeyMap",value:function(){for(var e=new Map,t=0,n=Object.entries(this.keyMap);t<n.length;t++){var r=u(n[t],2),i=r[0],a=r[1],o=parseInt(i,10),s=e.get(a)||[];s.push(o),e.set(a,s)}return e}},{key:"normalizeKeyCode",value:function(e){var t;return null!=(t=this.keyMap[e])?t:null}},{key:"getKeyCodesForAction",value:function(e){return this.reverseKeyMap.get(e)||[]}},{key:"isCodecSupported",value:function(e){if("undefined"==typeof document)return!1;try{var t=document.createElement("video").canPlayType(e);return"probably"===t||"maybe"===t}catch(n){return!1}}},{key:"registerTizenKeys",value:function(){if(this.platform===I.Tizen){var e=window.tizen;if(null==e?void 0:e.tvinputdevice){["MediaPlay","MediaPause","MediaStop","MediaFastForward","MediaRewind","MediaPlayPause","ColorF0Red","ColorF1Green","ColorF2Yellow","ColorF3Blue","Info"].forEach(function(t){try{e.tvinputdevice.registerKey(t)}catch(n){}})}}}},{key:"registerWebOSKeys",value:function(){this.platform,I.WebOS}},{key:"getVideoAttributes",value:function(){var e={muted:!0,playsinline:!0,autoplay:!0,"webkit-playsinline":!0};switch(this.platform){case I.Tizen:e["data-samsung-immersive"]="true";break;case I.WebOS:e["data-lg-immersive"]="true";break;case I.FireTV:case I.AndroidTV:e["x-webkit-airplay"]="allow"}return e}},{key:"getRecommendedVideoSettings",value:function(){switch(this.platform){case I.Tizen:case I.WebOS:return{maxBitrate:15e3,preferredCodec:"hevc",maxResolution:"4k"};case I.FireTV:return{maxBitrate:1e4,preferredCodec:"hevc",maxResolution:"4k"};case I.Roku:return{maxBitrate:8e3,preferredCodec:"h264",maxResolution:"4k"};case I.Xbox:case I.PlayStation:return{maxBitrate:2e4,preferredCodec:"hevc",maxResolution:"4k"};default:return{maxBitrate:5e3,preferredCodec:"h264",maxResolution:"1080p"}}}},{key:"openExternalLink",value:function(e){if("undefined"!=typeof window)if(this.platform===I.Generic||this.platform===I.Tizen||this.platform===I.WebOS)try{window.open(e,"_blank"),this.debug("[Adgent] Opened external link: ".concat(e))}catch(t){this.debug("[Adgent] Failed to open external link: ".concat(t))}else this.debug("[Adgent] Opening external links not supported on ".concat(this.platform,": ").concat(e));else this.debug("[Adgent] Cannot open link (server-side): ".concat(e))}},{key:"debug",value:function(e){if(console.log("[Adgent] ".concat(e)),this.platform===I.WebOS&&"undefined"!=typeof window){var t=window;t.webOS&&t.webOS.service&&t.webOS.service.request("luna://com.webos.notification",{method:"createToast",parameters:{message:"[Adgent] ".concat(e)},onSuccess:function(){},onFailure:function(){}})}}}])}(),q=null;function X(){return q||(q=new H),q}var Q=Object.defineProperty,Y=Object.defineProperties,Z=Object.getOwnPropertyDescriptors,$=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,ee=Object.prototype.propertyIsEnumerable,te=function(e,t,n){return t in e?Q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n},ne=function(e,t){for(var n in t||(t={}))J.call(t,n)&&te(e,n,t[n]);if($){var r,i=a($(t));try{for(i.s();!(r=i.n()).done;){n=r.value;ee.call(t,n)&&te(e,n,t[n])}}catch(o){i.e(o)}finally{i.f()}}return e},re=function(e,t,n){return te(e,"symbol"!==f(t)?t+"":t,n)},ie=function(){return i(function e(){var t,n,i,a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};r(this,e),re(this,"config"),re(this,"trackingEvents"),re(this,"firedEvents"),re(this,"macroContext"),this.config={debug:null!=(t=o.debug)&&t,retry:null!=(n=o.retry)&&n,maxRetries:null!=(i=o.maxRetries)?i:3},this.trackingEvents=this.groupEventsByType(a),this.firedEvents=new Set,this.macroContext={}},[{key:"groupEventsByType",value:function(e){var t,n=new Map,r=a(e);try{for(r.s();!(t=r.n()).done;){var i=t.value,o=n.get(i.event)||[];o.push(i),n.set(i.event,o)}}catch(s){r.e(s)}finally{r.f()}return n}},{key:"updateMacroContext",value:function(e){this.macroContext=ne(ne({},this.macroContext),e)}},{key:"track",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=this.trackingEvents.get(e);if(n){var r,i=a(n);try{for(i.s();!(r=i.n()).done;){var o=r.value,s="".concat(e,":").concat(o.url);if(t&&this.firedEvents.has(s))this.log("Skipping duplicate event: ".concat(e));else{var l=C(o.url,this.macroContext);this.firePixel(l),t&&this.firedEvents.add(s)}}}catch(u){i.e(u)}finally{i.f()}}else this.log("No tracking URLs for event: ".concat(e))}},{key:"firePixel",value:function(e){var t=X();this.log("Firing pixel: ".concat(e));try{if(t.capabilities.sendBeacon&&navigator.sendBeacon(e))return;if(t.capabilities.fetchKeepalive)return void fetch(e,{method:"GET",keepalive:!0,mode:"no-cors",credentials:"omit"}).catch(function(){});this.fireImageBeacon(e)}catch(n){this.log("Failed to fire pixel: ".concat(e))}}},{key:"fireImageBeacon",value:function(e){new Image(1,1).src=e}},{key:"fireImpressions",value:function(e){var t,n=a(e);try{for(n.s();!(t=n.n()).done;){var r=C(t.value,this.macroContext);this.firePixel(r)}}catch(i){n.e(i)}finally{n.f()}}},{key:"fireError",value:function(e,t){var n,r,i=(n=ne({},this.macroContext),Y(n,Z({errorCode:t}))),o=a(e);try{for(o.s();!(r=o.n()).done;){var s=C(r.value,i);this.firePixel(s)}}catch(l){o.e(l)}finally{o.f()}}},{key:"reset",value:function(){this.firedEvents.clear()}},{key:"log",value:function(e){this.config.debug&&console.log("[AdTracker] ".concat(e))}}])}(),ae=Object.defineProperty,oe=Object.getOwnPropertySymbols,se=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable,ue=function(e,t,n){return t in e?ae(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n},ce=function(e,t){for(var n in t||(t={}))se.call(t,n)&&ue(e,n,t[n]);if(oe){var r,i=a(oe(t));try{for(i.s();!(r=i.n()).done;){n=r.value;le.call(t,n)&&ue(e,n,t[n])}}catch(o){i.e(o)}finally{i.f()}}return e},de=function(e,t,n){return ue(e,"symbol"!==f(t)?t+"":t,n)},fe=function(e,t,n){return new Promise(function(r,i){var a=function(e){try{s(n.next(e))}catch(t){i(t)}},o=function(e){try{s(n.throw(e))}catch(t){i(t)}},s=function(e){return e.done?r(e.value):Promise.resolve(e.value).then(a,o)};s((n=n.apply(e,t)).next())})},pe={targetBitrate:2500,maxWrapperDepth:5,timeout:1e4,debug:!1,skipButtonText:"Skip Ad"},he=function(){return i(function e(t){r(this,e),de(this,"config"),de(this,"platform"),de(this,"parser"),de(this,"videoElement",null),de(this,"overlayElement",null),de(this,"skipButtonElement",null),de(this,"progressElement",null),de(this,"tracker",null),de(this,"state"),de(this,"ads",[]),de(this,"listeners",new Set),de(this,"eventListeners",new Map),de(this,"quartilesFired",new Set),de(this,"boundKeyHandler",null),de(this,"focusTrap",null),de(this,"hasStarted",!1),this.config=ce(ce({},pe),t),this.platform=X(),this.parser=new x({maxWrapperDepth:this.config.maxWrapperDepth,timeout:this.config.timeout,debug:this.config.debug}),this.state={status:y.Idle,currentTime:0,duration:0,muted:!0,volume:1,canSkip:!1,skipCountdown:0,mediaFile:null,error:null},"tizen"===this.platform.platform&&this.platform.registerTizenKeys()},[{key:"init",value:function(){return fe(this,null,s().m(function e(){var t,n,r,i,a,o,l,u;return s().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.config.container){e.n=1;break}throw new Error("Container element not found");case 1:return this.updateState({status:y.Loading}),e.p=2,e.n=3,this.parser.parse(this.config.vastUrl);case 3:if((r=e.v).success&&r.response){e.n=4;break}throw this.createError((null==(t=r.error)?void 0:t.code)||m.NO_VAST_RESPONSE,(null==(n=r.error)?void 0:n.message)||"Failed to parse VAST");case 4:if(this.ads=r.response.ads,0!==this.ads.length){e.n=5;break}throw this.createError(m.NO_VAST_RESPONSE,"No ads in VAST response");case 5:if(i=this.getFirstLinearCreative()){e.n=6;break}throw this.createError(m.GENERAL_LINEAR_ERROR,"No linear creative found");case 6:if(a=this.parser.selectBestMediaFile(i.mediaFiles,this.config.targetBitrate)){e.n=7;break}throw this.createError(m.FILE_NOT_FOUND,"No suitable media file found");case 7:return this.updateState({mediaFile:a}),o=this.parser.aggregateTrackingEvents(this.ads),this.tracker=new ie(o,{debug:this.config.debug}),this.tracker.updateMacroContext({assetUri:a.url}),this.createVideoElement(a),this.setupFocusManagement(),e.n=8,this.attemptAutoplay();case 8:e.n=10;break;case 9:e.p=9,u=e.v,l=u instanceof Error?this.createError(m.UNDEFINED_ERROR,u.message):u,this.handleError(l);case 10:return e.a(2)}},e,this,[[2,9]])}))}},{key:"getFirstLinearCreative",value:function(){var e,t=a(this.ads);try{for(t.s();!(e=t.n()).done;){var n,r=a(e.value.creatives);try{for(r.s();!(n=r.n()).done;){var i=n.value;if(i.linear)return i.linear}}catch(o){r.e(o)}finally{r.f()}}}catch(o){t.e(o)}finally{t.f()}return null}},{key:"createVideoElement",value:function(e){var t=this,n=document.createElement("video"),r=this.platform.getVideoAttributes();Object.entries(r).forEach(function(e){var t=u(e,2),r=t[0],i=t[1];"boolean"==typeof i?i&&n.setAttribute(r,""):n.setAttribute(r,i)}),n.removeAttribute("src"),n.innerHTML="";var i=document.createElement("source");if(i.src=e.url,i.type=e.type||"video/mp4",n.appendChild(i),n.setAttribute("crossorigin","anonymous"),n.style.cssText="\n width: 100%;\n height: 100%;\n object-fit: contain;\n background: #000;\n ",n.addEventListener("loadedmetadata",function(){t.updateState({duration:n.duration,status:y.Ready}),t.emit({type:"loaded"})}),n.addEventListener("timeupdate",function(){t.handleTimeUpdate(n)}),n.addEventListener("ended",function(){t.handleComplete()}),n.addEventListener("error",function(){var e=n.error;t.handleError(t.createError(m.MEDIA_NOT_SUPPORTED,(null==e?void 0:e.message)||"Video playback error"))}),n.addEventListener("play",function(){t.updateState({status:y.Playing})}),n.addEventListener("pause",function(){var e;t.state.status!==y.Completed&&(t.updateState({status:y.Paused}),t.emit({type:"pause"}),null==(e=t.tracker)||e.track("pause"))}),this.config.container.appendChild(n),this.videoElement=n,this.config.debug){["loadstart","loadeddata","canplay","waiting","playing"].forEach(function(e){var r=function(){return t.log("Video ".concat(e))};n.addEventListener(e,r),t.eventListeners.set(e,r)});var a=function(){return t.log("Video play event")};n.addEventListener("play",a),this.eventListeners.set("play",a)}this.log("Video element created with src: ".concat(e.url)),n.addEventListener("click",function(){t.onAdClick()}),n.style.cursor="pointer"}},{key:"attemptAutoplay",value:function(){return fe(this,null,s().m(function e(){var t;return s().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.videoElement){e.n=1;break}return e.a(2);case 1:return e.p=1,e.n=2,this.videoElement.play();case 2:this.handlePlaybackStart(),e.n=4;break;case 3:e.p=3,t=e.v,console.error("[Adgent] Autoplay failed details:",t),this.log("Autoplay failed: ".concat(t)),this.showStartOverlay();case 4:return e.a(2)}},e,this,[[1,3]])}))}},{key:"showStartOverlay",value:function(){var e=this;if(this.updateState({status:y.WaitingForInteraction}),this.config.customStartOverlay)return this.overlayElement=this.config.customStartOverlay,void this.config.container.appendChild(this.overlayElement);var t=document.createElement("div");t.innerHTML='\n <div style="\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n display: table;\n background: rgba(0, 0, 0, 0.5);\n z-index: 100;\n ">\n <div style="display: table-cell; vertical-align: middle; text-align: center;">\n <button id="adgent-start-btn" style="\n width: 80px;\n height: 80px;\n background: rgba(0, 0, 0, 0.7);\n border: 3px solid #fff;\n border-radius: 50%;\n cursor: pointer;\n display: inline-block;\n line-height: 80px;\n text-align: center;\n color: #fff;\n font-size: 40px;\n padding: 0 0 0 8px; /* Optical center for triangle */\n ">\n ▶\n </button>\n </div>\n </div>\n ',t.style.cssText="position: absolute; top: 0; left: 0; width: 100%; height: 100%;";var n=t.querySelector("#adgent-start-btn");null==n||n.addEventListener("click",function(){return e.onStartClick()}),this.config.container.style.position="relative",this.config.container.appendChild(t),this.overlayElement=t,null==n||n.focus()}},{key:"onAdClick",value:function(){var e,t,n,r,i,a=this;if(this.state.status===y.Playing){var o=this.getFirstLinearCreative();if(o){var s=null==(e=o.videoClicks)?void 0:e.clickThrough,l=null==s?void 0:s.url;if(l)this.log("Ad clicked. Opening: ".concat(l)),null==(t=this.videoElement)||t.pause(),this.showStartOverlay(),((null==(n=o.videoClicks)?void 0:n.clickTracking)||[]).forEach(function(e){var t;e.url&&(null==(t=a.tracker)||t.firePixel(e.url))}),this.platform.openExternalLink(l),this.emit({type:"click",data:{url:l}}),null==(i=(r=this.config).onClick)||i.call(r,l)}}}},{key:"onStartClick",value:function(){return fe(this,null,s().m(function e(){var t,n;return s().w(function(e){for(;;)switch(e.p=e.n){case 0:if(this.removeOverlay(),!this.videoElement){e.n=4;break}return e.p=1,e.n=2,this.videoElement.play();case 2:this.hasStarted?(this.updateState({status:y.Playing}),this.emit({type:"resume"}),null==(t=this.tracker)||t.track("resume")):this.handlePlaybackStart(),e.n=4;break;case 3:e.p=3,n=e.v,this.handleError(this.createError(m.GENERAL_LINEAR_ERROR,"Playback failed: ".concat(n)));case 4:return e.a(2)}},e,this,[[1,3]])}))}},{key:"removeOverlay",value:function(){this.overlayElement&&(this.overlayElement.remove(),this.overlayElement=null)}},{key:"handlePlaybackStart",value:function(){var e,t,n,r,i;this.hasStarted=!0,this.updateState({status:y.Playing}),this.emit({type:"start"}),null==(t=(e=this.config).onStart)||t.call(e);var a=this.parser.aggregateImpressions(this.ads);null==(n=this.tracker)||n.fireImpressions(a),null==(r=this.tracker)||r.track("start"),null==(i=this.tracker)||i.track("creativeView"),this.setupSkipButton(),this.setupProgressUI(),this.log("Playback started")}},{key:"handleTimeUpdate",value:function(e){var t,n,r,i=e.currentTime,a=e.duration;if(a&&!isNaN(a)){var o=i/a*100,s=this.calculateQuartile(o);this.updateState({currentTime:i,duration:a}),this.updateSkipCountdown(i),null==(t=this.tracker)||t.updateMacroContext({adPlayhead:i}),this.updateProgressUI(i,a);var l={currentTime:i,duration:a,percentage:o,quartile:s};this.emit({type:"progress",data:l}),null==(r=(n=this.config).onProgress)||r.call(n,l),this.fireQuartileEvents(o)}}},{key:"calculateQuartile",value:function(e){return e>=100?4:e>=75?3:e>=50?2:e>=25?1:0}},{key:"fireQuartileEvents",value:function(e){for(var t,n=0,r=[{threshold:25,event:"firstQuartile"},{threshold:50,event:"midpoint"},{threshold:75,event:"thirdQuartile"}];n<r.length;n++){var i=r[n],a=i.threshold,o=i.event;e>=a&&!this.quartilesFired.has(a)&&(this.quartilesFired.add(a),null==(t=this.tracker)||t.track(o),this.emit({type:"quartile",data:{quartile:o}}),this.log("Quartile fired: ".concat(o)))}}},{key:"setupSkipButton",value:function(){var e,t=this,n=this.getFirstLinearCreative(),r=null!=(e=this.config.skipOffset)?e:null==n?void 0:n.skipOffset;if(r&&!(r<=0)){this.updateState({skipCountdown:r,canSkip:!1});var i=document.createElement("button");i.id="adgent-skip-btn",i.style.cssText="\n position: absolute;\n bottom: 20px;\n right: 20px;\n padding: 12px 24px;\n font-size: 16px;\n background: rgba(0, 0, 0, 0.7);\n color: #fff;\n border: 2px solid #fff;\n border-radius: 4px;\n cursor: pointer;\n z-index: 101;\n transition: opacity 0.3s;\n ",i.textContent="Skip in ".concat(r,"s"),i.addEventListener("click",function(){return t.skip()}),this.config.container.appendChild(i),this.skipButtonElement=i}}},{key:"updateSkipCountdown",value:function(e){var t,n=this.getFirstLinearCreative(),r=null!=(t=this.config.skipOffset)?t:null==n?void 0:n.skipOffset;if(r&&this.skipButtonElement){var i=Math.max(0,r-e);this.updateState({skipCountdown:i}),i<=0&&!this.state.canSkip?(this.updateState({canSkip:!0}),this.skipButtonElement.textContent=this.config.skipButtonText,this.skipButtonElement.style.opacity="1",this.skipButtonElement.focus()):i>0&&(this.skipButtonElement.textContent="Skip in ".concat(Math.ceil(i),"s"),this.skipButtonElement.style.opacity="0.6")}}},{key:"skip",value:function(){var e,t,n;this.state.canSkip?(null==(e=this.tracker)||e.track("skip"),this.emit({type:"skip"}),null==(n=(t=this.config).onSkip)||n.call(t),this.destroy(),this.log("Ad skipped")):this.log("Skip not available yet")}},{key:"handleComplete",value:function(){var e,t,n;this.updateState({status:y.Completed}),null==(e=this.tracker)||e.track("complete"),this.emit({type:"complete"}),null==(n=(t=this.config).onComplete)||n.call(t),this.log("Ad completed")}},{key:"handleError",value:function(e){var t,n,r;this.updateState({status:y.Error,error:e});var i,o=[],s=a(this.ads);try{for(s.s();!(i=s.n()).done;){var l=i.value;o.push.apply(o,c(l.errors))}}catch(u){s.e(u)}finally{s.f()}null==(t=this.tracker)||t.fireError(o,e.code),this.emit({type:"error",data:e}),null==(r=(n=this.config).onError)||r.call(n,e),this.log("Error: ".concat(e.message))}},{key:"setupFocusManagement",value:function(){var e=this;this.focusTrap=document.createElement("div"),this.focusTrap.tabIndex=0,this.focusTrap.style.cssText="position: absolute; opacity: 0; width: 0; height: 0;",this.config.container.appendChild(this.focusTrap),this.focusTrap.focus(),this.boundKeyHandler=function(t){var n=e.platform.normalizeKeyCode(t.keyCode);n&&(t.preventDefault(),t.stopPropagation(),e.handleKeyAction(n))},document.addEventListener("keydown",this.boundKeyHandler,!0)}},{key:"setupProgressUI",value:function(){var e=document.createElement("div");e.style.cssText="\n position: absolute;\n top: 20px;\n left: 20px;\n background: rgba(0, 0, 0, 0.7);\n color: #fff;\n padding: 6px 12px;\n border-radius: 4px;\n font-size: 14px;\n font-family: sans-serif;\n z-index: 101;\n display: block;\n white-space: nowrap;\n ",e.innerHTML='\n <span style="display: inline-block; vertical-align: middle; margin-right: 8px; background: #f4b400; color: #000; padding: 2px 4px; border-radius: 2px; font-weight: bold; font-size: 12px;">Ad</span>\n <span id="adgent-progress-text" style="display: inline-block; vertical-align: middle;">1 of '.concat(this.ads.length," • 0:00</span>\n "),this.config.container.appendChild(e),this.progressElement=e}},{key:"updateProgressUI",value:function(e,t){if(this.progressElement){var n=Math.ceil(t-e),r=Math.floor(n/60),i=n%60,a="".concat(r,":").concat(i.toString().padStart(2,"0")),o=this.progressElement.querySelector("#adgent-progress-text");if(o){o.textContent="".concat(1," of ").concat(this.ads.length," • ").concat(a)}}}},{key:"handleKeyAction",value:function(e){var t,n;switch(this.log("Key action: ".concat(e)),e){case M.Enter:this.state.status===y.WaitingForInteraction?this.onStartClick():this.state.canSkip&&this.skip();break;case M.Back:this.config.onClose?(this.log("Back pressed - user cancelling"),this.config.onClose(),this.destroy()):(this.log("Back pressed - skipping"),this.emit({type:"skip"}),this.config.onSkip&&this.config.onSkip(),this.destroy());break;case M.Play:null==(t=this.videoElement)||t.play();break;case M.Pause:null==(n=this.videoElement)||n.pause();case M.Left:case M.Right:case M.Up:case M.Down:}}},{key:"unmute",value:function(){var e;this.videoElement&&(this.videoElement.muted=!1,this.updateState({muted:!1}),null==(e=this.tracker)||e.track("unmute"),this.emit({type:"unmute"}))}},{key:"mute",value:function(){var e;this.videoElement&&(this.videoElement.muted=!0,this.updateState({muted:!0}),null==(e=this.tracker)||e.track("mute"),this.emit({type:"mute"}))}},{key:"on",value:function(e){var t=this;return this.listeners.add(e),function(){return t.listeners.delete(e)}}},{key:"getState",value:function(){return ce({},this.state)}},{key:"destroy",value:function(){var e,t,n,r,i,a=this;this.boundKeyHandler&&(document.removeEventListener("keydown",this.boundKeyHandler,!0),this.boundKeyHandler=null),this.videoElement&&(this.eventListeners.forEach(function(e,t){var n;null==(n=a.videoElement)||n.removeEventListener(t,e)}),this.eventListeners.clear(),this.videoElement.remove()),null==(e=this.overlayElement)||e.remove(),null==(t=this.skipButtonElement)||t.remove(),null==(n=this.progressElement)||n.remove(),null==(r=this.focusTrap)||r.remove(),this.videoElement=null,this.overlayElement=null,this.skipButtonElement=null,this.progressElement=null,this.focusTrap=null,null==(i=this.tracker)||i.reset(),this.quartilesFired.clear(),this.listeners.clear(),this.ads=[],this.emit({type:"destroy"}),this.log("Player destroyed")}},{key:"updateState",value:function(e){this.state=ce(ce({},this.state),e)}},{key:"emit",value:function(e){var t,n=a(this.listeners);try{for(n.s();!(t=n.n()).done;){var r=t.value;try{r(e)}catch(i){this.log("Listener error: ".concat(i))}}}catch(o){n.e(o)}finally{n.f()}}},{key:"createError",value:function(e,t){return{code:e,message:t,recoverable:arguments.length>2&&void 0!==arguments[2]&&arguments[2]}}},{key:"log",value:function(e){this.config.debug&&this.platform.debug(e)}}])}();e.AdPlayer=he,e.AdTracker=ie,e.AdgentSDK=he,e.DEFAULT_KEY_CODES=F,e.KeyAction=M,e.PLATFORM_DETECTION_PATTERNS=L,e.Platform=I,e.PlatformAdapter=H,e.PlaybackStatus=y,e.VASTErrorCode=m,e.VASTParser=x,e.getPlatformAdapter=X,e.replaceMacros=C,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
package/dist/index.d.ts CHANGED
@@ -45,6 +45,7 @@ declare class AdPlayer {
45
45
  private quartilesFired;
46
46
  private boundKeyHandler;
47
47
  private focusTrap;
48
+ private hasStarted;
48
49
  constructor(config: AdPlayerConfig);
49
50
  /**
50
51
  * Initialize the SDK: fetch VAST, create video element, attempt autoplay
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adgent-sdk",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Lightweight, framework-agnostic VAST Player SDK for Smart TV platforms",
5
5
  "type": "module",
6
6
  "main": "./dist/adgent-sdk.umd.js",
@@ -37,7 +37,7 @@
37
37
  "author": "Asadbek Omonboyev",
38
38
  "license": "MIT",
39
39
  "dependencies": {
40
- "fast-xml-parser": "^4.3.4"
40
+ "fast-xml-parser": "^5.3.4"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@babel/core": "^7.28.6",