!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).DisplayVmaxAd=t()}(this,(function(){"use strict";function e(e,t,i,n){return new(i||(i=Promise))((function(r,s){function a(e){try{l(n.next(e))}catch(e){s(e)}}function o(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}l((n=n.apply(e,t||[])).next())}))}function t(e,t,i,n){if("a"===i&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?n:"a"===i?n.call(e):n?n.value:t.get(e)}function i(e,t,i,n,r){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?r.call(e,i):r?r.value=i:t.set(e,i),i}function n(...e){console.error.apply(console,e)}"function"==typeof SuppressedError&&SuppressedError;var r,s,a,o,l,d,c,u,h,f,p,m,v,E,b,g,A,w,I,S,T,y,_,k,D;class C{constructor(e){var n;(r.add(this),s.set(this,void 0),a.set(this,void 0),o.set(this,[]),l.set(this,[]),d.set(this,[]),c.set(this,[]),u.set(this,"hidden"),h.set(this,null),f.set(this,null),p.set(this,!0),m.set(this,null),e instanceof HTMLElement)?(i(this,s,(n=t(this,r,"m",v).bind(this),new IntersectionObserver(n,{root:null,rootMargin:"0px",threshold:.5})),"f"),i(this,a,e,"f"),t(this,s,"f").observe(e),i(this,u,function(e){let t="hidden",i="visibilitychange";const n=window.document;return void 0!==n[t]?(t="hidden",i="visibilitychange"):void 0!==n.msHidden?(t="msHidden",i="msvisibilitychange"):void 0!==n.webkitHidden?(t="webkitHidden",i="webkitvisibilitychange"):void 0!==n.oHidden?(t="oHidden",i="ovisibilitychange"):void 0!==n.mozHidden?(t="mozHidden",i="mozvisibilitychange"):void 0!==n.khtmlHidden&&(t="khtmlHidden",i="khtmlvisibilitychange"),n.addEventListener(i,e,!0),t}(t(this,r,"m",E).bind(this)),"f"),function(e){window.addEventListener("focus",e),window.addEventListener("pageshow",e)}(t(this,r,"m",b).bind(this)),function(e){window.addEventListener("blur",e),window.addEventListener("pagehide",e)}(t(this,r,"m",g).bind(this)),this.check()):function(...e){console.warn.apply(console,e)}("Container must be a valid HTMLElement")}destroy(){var e;null===(e=t(this,s,"f"))||void 0===e||e.unobserve(t(this,a,"f")),i(this,o,[],"f"),i(this,l,[],"f"),i(this,d,[],"f"),i(this,c,[],"f"),i(this,h,null,"f"),i(this,f,null,"f"),i(this,p,null,"f"),clearInterval(t(this,m,"f"))}check(){t(this,r,"m",E).call(this)}enter(e){if("function"!=typeof e)throw new Error("Callback must be a function");return t(this,o,"f").push(e),this}exit(e){if("function"!=typeof e)throw new Error("Callback must be a function");return t(this,l,"f").push(e),this}enterOnce(e){if("function"!=typeof e)throw new Error("Callback must be a function");return t(this,d,"f").push(e),this}exitOnce(e){if("function"!=typeof e)throw new Error("Callback must be a function");return t(this,c,"f").push(e),this}}function O(e,t){const i=function(e,t){const i=navigator.userAgent.match(/Android/i),n=navigator.userAgent.match(/Chrome/i),r=e&&i&&n;if(!r)return!1;const s=function(e,t){try{const i=e.split("://"),n=i[0];return`intent://${i[1]}/#Intent;scheme=${n};S.browser_fallback_url=${t||""};end`}catch(e){return!1}}(e,t);return s||!1}(e,t);return i||t}function P(e){if("number"==typeof e)return e;try{const[t,i,n]=e.split(":"),r=60*parseInt(t)*60,s=60*parseInt(i);return r+s+parseInt(n)}catch(e){return function(...e){console.debug.apply(console,e)}("videoInstreamVmaxAd: Wrong time specified in vast parser",e),0}}function R(e){var t,i,n,r,s,a;const{bid:o,vast:l,hasVideoAdElement:d=!1,imaCompanions:c={companions:[],companionResourceUrls:[]}}=e,{ext:u={},w:h=null,h:f=null}=o||{},p=null!==(t=null==u?void 0:u["ad-meta"])&&void 0!==t?t:{},{id:m=null,name:v=null,"campaign-meta":E={}}=p,{id:b=null,name:g=null,marketer:A={},order:w={}}=E,{id:I=null,name:S=null,agency:T=null,brand:y=null}=A||{},{id:_=null,name:k=null}=w,D=e=>"number"==typeof e&&e>=0?e:-1,C=function(e){try{return JSON.parse(e)}catch(e){return{}}}((null==o?void 0:o.adm)||"{}"),R=(null==C?void 0:C.title)||"",N=(null==C?void 0:C.ctaText)||"",M=!!(null==C?void 0:C.linkUrl)||!!(null==C?void 0:C.linkFallback),U=O((null==C?void 0:C.linkUrl)||"",(null==C?void 0:C.linkFallback)||""),L=(null==l?void 0:l.adSystem)||"",x=(null==l?void 0:l.adTitle)||"",F=(null==l?void 0:l.description)||"",W=(null===(i=null==l?void 0:l.linear)||void 0===i?void 0:i.skipoffset)||(null==l?void 0:l.skipOffset)?D(P((null===(n=null==l?void 0:l.linear)||void 0===n?void 0:n.skipoffset)||(null==l?void 0:l.skipOffset)||"")):"",H=(null==l?void 0:l.duration)?D(P(null==l?void 0:l.duration)):"",V=!!(null==l?void 0:l.deepLinkUrl)||!!(null==l?void 0:l.clickThrough);let K=(null==l?void 0:l.companions)||[],G=(null==l?void 0:l.companionResourceUrls)||[];const Y=O((null==l?void 0:l.deepLinkUrl)||"",(null==l?void 0:l.clickThrough)||""),{companions:j=[],companionResourceUrls:X=[]}=c;j.length&&(K=[...j],G=[...X]);return{adId:m,adName:v,campaignId:b,campaignName:g,marketerId:I,marketerName:S,brand:y,agency:T,orderId:_,orderName:k,qualifiedSignature:(null===(a=null===(s=null===(r=null==o?void 0:o.ext)||void 0===r?void 0:r.modules)||void 0===s?void 0:s.render)||void 0===a?void 0:a.signature)||"",width:h,height:f,adSystem:L,adTitle:R||x,adDescription:F,ctaText:N,skipOffset:W,adDuration:H,isCTAAvailable:M||V,adClickUrl:U||Y,companionResourceUrls:G,hasVideoAdElement:d,companions:K}}s=new WeakMap,a=new WeakMap,o=new WeakMap,l=new WeakMap,d=new WeakMap,c=new WeakMap,u=new WeakMap,h=new WeakMap,f=new WeakMap,p=new WeakMap,m=new WeakMap,r=new WeakSet,v=function(e){var n;const s=null===(n=null==e?void 0:e[0])||void 0===n?void 0:n.isIntersecting;"boolean"==typeof s&&(i(this,h,!0===s,"f"),t(this,r,"m",A).call(this))},E=function(){const e=window.document;i(this,f,!1===(null==e?void 0:e[t(this,u,"f")])||"visible"===(null==e?void 0:e.visibilityState),"f"),t(this,r,"m",A).call(this)},b=function(){i(this,f,!0,"f"),t(this,r,"m",A).call(this)},g=function(){const e=window.document;clearInterval(t(this,m,"f")),i(this,m,setTimeout((()=>{!1===(!1===(null==e?void 0:e[t(this,u,"f")])||"visible"===(null==e?void 0:e.visibilityState))&&(i(this,f,!1,"f"),t(this,r,"m",A).call(this))}),1),"f")},A=function(){const e=t(this,h,"f")&&t(this,f,"f");if(t(this,p,"f")===e)return;const n=t(this,h,"f")&&t(this,f,"f"),r=t(this,n?o:l,"f"),s=t(this,n?d:c,"f");r.forEach((e=>e())),s.forEach((e=>e())),i(this,n?d:c,[],"f"),i(this,p,e,"f")},function(e){e.errorCode="{errorcode}",e.noFill="",e.noFillError="[nofill.error]",e.demandPartnerSDKVersion="[demand.partner.sdkversion]",e.eventName="[event.name]",e.vastErrorCode="[vast.error]",e.OmidSDKVersion="[omid.partner.sdkversion]",e.eventAttribute1="[event.attribute1]",e.eventAttribute2="[event.attribute2]",e.eventAttribute3="[event.attribute3]",e.randomCcb="[random.ccb]",e.deviceIFA="[device.ifa]"}(w||(w={})),function(e){e.AD_READY="adReady",e.AD_IMPRESSION="adImpression",e.AD_RENDERED="adRendered",e.AD_REFRESHED="adRefreshed",e.AD_ERROR="adError",e.AD_CLOSED="adClosed",e.AD_CLICKED="adClicked",e.AD_SKIPPED="adSkipped",e.AD_SKIPPABLE_STATE_CHANGE="adSkippableStateChange",e.AD_PAUSED="adPaused",e.AD_RESUMED="adResumed",e.AD_VIDEO_START="adVideoStart",e.AD_VIDEO_FIRST_QUARTILE="adVideoFirstQuartile",e.AD_VIDEO_MIDPOINT="adVideoMidpoint",e.AD_VIDEO_THIRD_QUARTILE="adVideoThirdQuartile",e.AD_VIDEO_COMPLETE="adVideoComplete",e.AD_VOLUME_CHANGED="adVolumeChanged",e.AD_MUTED="adMuted",e.AD_UNMUTED="adUnmuted",e.AD_PROGRESS="adProgress",e.AD_USER_CLOSE="adUserClose",e.AD_INSERTION_START="adInsertionStart",e.AD_INSERTION_END="adInsertionEnd",e.AD_MEDIA_EXPAND="onFullScreen",e.AD_MEDIA_COLLAPSE="onExitFullScreen"}(I||(I={})),function(e){e.PERSONAL_COMPUTER="2",e.CONNECTED_TV="3",e.PHONE="4",e.TABLET="5",e.CONNECTED_DEVICE="6",e.SET_TOP_BOX="7"}(S||(S={})),function(e){e.GEO_PROFILE="geoProfile",e.USER_PROFILE="userProfile"}(T||(T={})),function(e){e.APP_ID="appId",e.ACCOUNT_KEY="accountKey",e.SECRET_KEY="secretKey",e.SDK_INITIALIZED="sdkInitialized",e.GEO_PROFILE="geoProfile",e.USER_PROFILE="userProfile",e.IS_APP="isApp",e.SOURCE_CONFIG_DATA="sourceConfig",e.ABORT="abort",e.PRIVATE_KEY="privateKey",e.KEY_ID="keyId",e.UPS_ENDPOINT="upsEndpoint",e.UPS_XAUTH="upsXAuth",e.DGS_ENDPOINT="dgsEndpoint",e.DGS_XAUTH="dgsXAuth",e.AS_ENDPOINT="adspotEndpoint",e.AS_XAUTH="adspotXAuth",e.UPS_FIRST_FETCH_DONE="upsFirstFetchDone",e.UPS_SERVICE_CALL="UPSServiceCall",e.DGS_SERVICE_CALL="DGSServiceCall"}(y||(y={})),function(e){e.UID="uid",e.GENDER="gender",e.AGE="age",e.COUNTRY="country",e.REGION="region",e.CITY="city",e.ZIPCODE="zip",e.KEYWORDS="keywords"}(_||(_={})),function(e){e.PLAY_ONCE="play_once",e.REPEAT="repeat"}(k||(k={}));class N{constructor(){D.set(this,new Map)}static getInstance(){return N.instance}set(e,i){"object"!=typeof e?t(this,D,"f").set(e,i):Object.entries(e).forEach((([e,i])=>{t(this,D,"f").set(e,i)}))}get(e){var i;return"string"!=typeof e||0==e.length?t(this,D,"f"):null!==(i=t(this,D,"f").get(e))&&void 0!==i?i:null}get isSDKInitialized(){return Boolean(t(this,D,"f").get(y.SDK_INITIALIZED))}}D=new WeakMap,N.instance=new N;const M=N.getInstance();var U,L,x,F;class W{static post(t){return e(this,void 0,void 0,(function*(){const{url:e,payload:i,headers:r={},credentials:s}=t||{};let a={method:"POST",body:JSON.stringify(i)};s&&(a.credentials=s),r&&(a.headers=r);const o=new AbortController;a.signal=o.signal;return[fetch(e,a).then((e=>e.ok?e.json().catch((()=>Promise.reject(n("Invalid JSON response")))):e.text().then((t=>Promise.reject({message:`Error: ${e.status}`,status:e.status,body:t}))))).catch((e=>(function(...e){console.log.apply(console,e)}("Error in Fetch.post",e),Promise.reject(e)))),o]}))}static get(t){return e(this,arguments,void 0,(function*(e,t={}){return fetch(e,t).then((e=>e.json()))}))}static getPlainResponse(t){return e(this,arguments,void 0,(function*(e,t={}){return fetch(e,t)}))}static DeviceGeoService(){const e=M.get(y.ACCOUNT_KEY),t=M.get(y.DGS_ENDPOINT);M.get(y.DGS_XAUTH);const i=(t||"").replace("ACCOUNT_KEY",e);return U.get(i)}static UserProfileService(t){return e(this,void 0,void 0,(function*(){const e=M.get(y.ACCOUNT_KEY),i=M.get(y.UPS_ENDPOINT),n=M.get(y.UPS_XAUTH),r=(i||"").replace("ACCOUNT_KEY",e),[s]=yield U.post({url:r,headers:{"X-AUTH":n},payload:t});return s}))}static AdQuery(e){const{ACCOUNT_KEY:t,AS_ENDPOINT:i}=y,n=M.get(t)||"",r=M.get(i);return U.post({url:r.replace("ACCOUNT_KEY",n),payload:e,credentials:"include"})}static replaceAllMacros(e,t){const i=Object.keys(w);if(0===i.length)return e;const{ifa:n=""}=window.VmaxAdManager.getDevice().getPayload();return i.forEach((i=>{var r;const s=w[i];let a;a=s===w.randomCcb?Date.now().toString():s===w.deviceIFA?n:t&&(null===(r=t[s])||void 0===r?void 0:r.toString())||"";const o=new RegExp(this.escapeRegExp(s),"g");e=e.replace(o,a)})),t||i.forEach((t=>{const i=w[t],n=new RegExp(this.escapeRegExp(i),"g");e=e.replace(n,"")})),e}static escapeRegExp(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}static FireTracker(i,n){return e(this,void 0,void 0,(function*(){if(!(e=i,"string"==typeof e&&e.length>0||(e=>Array.isArray(e))(i)))return Promise.reject("No url to fire tracker");var e;for(let e of i)e=this.replaceAllMacros(e,n),yield t(U,U,"m",L).call(U,e)}))}}U=W,L=function(t){return e(this,void 0,void 0,(function*(){try{const e=window.VmaxAdManager.getSite().getPayload(),{pageUrl:i,referrerUrl:r}=e,s=yield fetch(t,{method:"GET",headers:{Connection:"keep-alive","X-Requested-with":`${i}`},credentials:"include"});s.ok||n("Tracker request failed:",s.status,s.statusText)}catch(e){n("Error while firing the tracker:",e)}}))};class H{constructor(e=new Map){x.set(this,new Map),i(this,x,e,"f")}fireTracker(e,i){const n=t(this,x,"f").get(e);n&&W.FireTracker(n,i)}}x=new WeakMap,function(e){e.IMPRESSION="impression",e.NO_FILL="nofill",e.FILL="fill",e.CLICK="click",e.ERROR="error",e.START="start",e.FIRST_QUARTILE="firstQuartile",e.MIDPOINT="midpoint",e.THIRD_QUARTILE="thirdQuartile",e.COMPLETE="complete",e.PAUSE="pause",e.RESUME="resume",e.SKIP="skip",e.MUTE="mute",e.UNMUTE="unmute",e.SKIPPABLE_STATE_CHANGE="skippableStateChange"}(F||(F={}));var V,K,G,Y,j,X,$,Q,z,B,q,J,Z,ee,te,ie,ne,re,se,ae,oe,le=F;class de{constructor(){V.add(this),G.set(this,void 0),Y.set(this,void 0),j.set(this,void 0),X.set(this,(()=>{})),$.set(this,(()=>{})),Q.set(this,(()=>{})),z.set(this,(()=>{})),B.set(this,void 0),q.set(this,new Map),this.shouldProcessRefresh=!0,J.set(this,void 0),Z.set(this,void 0),this.canRefresh=!0}static addCustomSignature(e){t(K,K,"f",ee).push(e)}getAllSignatures(){return t(K,K,"f",ee)}prepare(n){return e(this,void 0,void 0,(function*(){const{bid:e,listeners:r}=n||{};i(this,G,e,"f");const{AdPaused:s,AdResumed:a,AdClicked:o}=r||{};return"function"==typeof s&&i(this,$,s,"f"),"function"==typeof a&&i(this,X,a,"f"),"function"==typeof o&&i(this,Q,o,"f"),i(this,Z,r,"f"),t(this,V,"m",re).call(this),Promise.resolve()}))}render(n){return e(this,void 0,void 0,(function*(){const{container:e}=n||{};return e&&t(this,V,"m",ne).call(this,e)?(i(this,Y,e,"f"),i(this,J,t(this,V,"m",ie).call(this),"f"),e.appendChild(t(this,J,"f")),t(this,V,"m",se).call(this,t(this,J,"f")),Promise.resolve()):Promise.reject("Not a valid container")}))}destroy(){var e,n,r;null===(e=t(this,j,"f"))||void 0===e||e.destroy(),i(this,j,null,"f"),i(this,G,{},"f"),null===(r=null===(n=t(this,J,"f"))||void 0===n?void 0:n.parentNode)||void 0===r||r.removeChild(t(this,J,"f")),i(this,Y,{},"f"),i(this,X,(()=>{}),"f"),i(this,$,(()=>{}),"f"),i(this,Q,(()=>{}),"f"),i(this,B,{},"f"),i(this,q,new Map,"f")}closeAd(){var e;return null===(e=t(this,Z,"f"))||void 0===e||e.AdClosed(),this.canRefresh=!1,this.destroy(),Promise.resolve()}getVmaxEventTracker(){return t(this,B,"f")}getVmaxAdInfo(){const e=R({bid:t(this,G,"f")});return Object.assign({},e)}getAdMarkup(){var e;return(null===(e=t(this,G,"f"))||void 0===e?void 0:e.adm)||""}}return K=de,G=new WeakMap,Y=new WeakMap,j=new WeakMap,X=new WeakMap,$=new WeakMap,Q=new WeakMap,z=new WeakMap,B=new WeakMap,q=new WeakMap,J=new WeakMap,Z=new WeakMap,V=new WeakSet,te=function(){const{adm:e}=t(this,G,"f"),i=function(e,t){const i=Object.keys(w);return 0===i.length||i.forEach((i=>{var n;const r=w[i],s=r===w.randomCcb?Date.now().toString():t&&(null===(n=t[r])||void 0===n?void 0:n.toString())||"",a=new RegExp(r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g");e=e.replace(a,s)})),e}(e);return`${i}`},ie=function(){const{w:e,h:i}=t(this,G,"f"),n=document.createElement("iframe");return n.setAttribute("marginwidth","0"),n.setAttribute("marginheight","0"),n.setAttribute("scrolling","no"),n.setAttribute("frameborder","0"),n.setAttribute("hspace","0"),n.setAttribute("vspace","0"),n.style.border="none",n.style.margin="0",n.style.width=`${e}px`,n.style.height=`${i}px`,n.srcdoc=t(this,V,"m",te).call(this),n},ne=function(e){const t=e instanceof HTMLElement,i=null!==e.parentNode,n=e.ownerDocument===document;return t&&i&&n},re=function(){const{IMPRESSION:e,NO_FILL:n,FILL:r}=le,{burl:s,nurl:a,lurl:o}=t(this,G,"f")||{};s&&t(this,q,"f").set(e,[s]),a&&t(this,q,"f").set(n,[a]),o&&t(this,q,"f").set(r,[o]),i(this,B,new H(t(this,q,"f")),"f")},se=function(e){t(this,B,"f").fireTracker(le.FILL),i(this,j,new C(t(this,Y,"f")),"f"),t(this,j,"f").enter(t(this,X,"f")),t(this,j,"f").exit(t(this,$,"f")),t(this,j,"f").enterOnce(t(this,V,"m",ae).bind(this)),e.onload=t(this,V,"m",oe).bind(this,e)},ae=function(){var e;t(this,B,"f").fireTracker(le.IMPRESSION),null===(e=t(this,Z,"f"))||void 0===e||e.AdImpression()},oe=function(e){var i,n;null===(n=null===(i=e.contentWindow)||void 0===i?void 0:i.document)||void 0===n||n.body.addEventListener("click",t(this,Q,"f").bind(this))},ee={value:["iab.smartphonebanner","iab.mediumrectangle","iab.leaderboard","iab.superleaderboard","exp-21b9b4700dbabaf5","iab.mobilebanner","iab.smartphonebanner","iab.largemobilebanner","iab.banner","iab.square","iab.midsizemobilebanner","iab.mediumrectangle","iab.largerectangle","iab.billboard","iab.leaderboard","iab.superleaderboard","iab.halfpage","iab.potrait","iab.skyscraper","iab.wideskyscraper","iab.displaytabletinterstitial","iab.displaymobilephoneinterstitial","iab.rmmobilebanner","iab.rmsmartphonebanner","iab.rmlargemobilebanner","iab.rmbanner","iab.rmsquare","iab.rmmidsizemobilebanner","iab.rmmediumrectangle","iab.rmlargerectangle","iab.rmleaderboard","iab.rmsuperleaderboard","iab.rmbillboard","iab.rmhalfpage","iab.rmpotrait","iab.rmskyscraper","iab.rmwideskyscraper"]},de}));