!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).VmaxGoogleAdsense=t()}(this,(function(){"use strict";function e(e,t,i,n){return new(i||(i=Promise))((function(s,r){function o(e){try{l(n.next(e))}catch(e){r(e)}}function a(e){try{l(n.throw(e))}catch(e){r(e)}}function l(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(o,a)}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,s){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?s.call(e,i):s?s.value=i:t.set(e,i),i}function n(...e){console.error.apply(console,e)}"function"==typeof SuppressedError&&SuppressedError;var s,r,o,a,l,d,c,u,h,f,p,E,v,m,A,I,T,g,S,w,_,D,b,k;class O{constructor(e){var n;(s.add(this),r.set(this,void 0),o.set(this,void 0),a.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),E.set(this,null),e instanceof HTMLElement)?(i(this,r,(n=t(this,s,"m",v).bind(this),new IntersectionObserver(n,{root:null,rootMargin:"0px",threshold:.5})),"f"),i(this,o,e,"f"),t(this,r,"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,s,"m",m).bind(this)),"f"),function(e){window.addEventListener("focus",e),window.addEventListener("pageshow",e)}(t(this,s,"m",A).bind(this)),function(e){window.addEventListener("blur",e),window.addEventListener("pagehide",e)}(t(this,s,"m",I).bind(this)),this.check()):function(...e){console.warn.apply(console,e)}("Container must be a valid HTMLElement")}destroy(){var e;null===(e=t(this,r,"f"))||void 0===e||e.unobserve(t(this,o,"f")),i(this,a,[],"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,E,"f"))}check(){t(this,s,"m",m).call(this)}enter(e){if("function"!=typeof e)throw new Error("Callback must be a function");return t(this,a,"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 y(e,t){const i=function(e,t){const i=navigator.userAgent.match(/Android/i),n=navigator.userAgent.match(/Chrome/i),s=e&&i&&n;if(!s)return!1;const r=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 r||!1}(e,t);return i||t}function R(e){if("number"==typeof e)return e;try{const[t,i,n]=e.split(":"),s=60*parseInt(t)*60,r=60*parseInt(i);return s+r+parseInt(n)}catch(e){return function(...e){console.debug.apply(console,e)}("videoInstreamVmaxAd: Wrong time specified in vast parser",e),0}}function C(e){var t,i,n,s,r,o;const{bid:a,vast:l,hasVideoAdElement:d=!1,imaCompanions:c={companions:[],companionResourceUrls:[]}}=e,{ext:u={},w:h=null,h:f=null}=a||{},p=null!==(t=null==u?void 0:u["ad-meta"])&&void 0!==t?t:{},{id:E=null,name:v=null,"campaign-meta":m={}}=p,{id:A=null,name:I=null,marketer:T={},order:g={}}=m,{id:S=null,name:w=null,agency:_=null,brand:D=null}=T||{},{id:b=null,name:k=null}=g,O=e=>"number"==typeof e&&e>=0?e:-1,C=function(e){try{return JSON.parse(e)}catch(e){return{}}}((null==a?void 0:a.adm)||"{}"),P=(null==C?void 0:C.title)||"",N=(null==C?void 0:C.ctaText)||"",U=!!(null==C?void 0:C.linkUrl)||!!(null==C?void 0:C.linkFallback),M=y((null==C?void 0:C.linkUrl)||"",(null==C?void 0:C.linkFallback)||""),L=(null==l?void 0:l.adSystem)||"",F=(null==l?void 0:l.adTitle)||"",W=(null==l?void 0:l.description)||"",V=(null===(i=null==l?void 0:l.linear)||void 0===i?void 0:i.skipoffset)||(null==l?void 0:l.skipOffset)?O(R((null===(n=null==l?void 0:l.linear)||void 0===n?void 0:n.skipoffset)||(null==l?void 0:l.skipOffset)||"")):"",x=(null==l?void 0:l.duration)?O(R(null==l?void 0:l.duration)):"",H=!!(null==l?void 0:l.deepLinkUrl)||!!(null==l?void 0:l.clickThrough);let K=(null==l?void 0:l.companions)||[],j=(null==l?void 0:l.companionResourceUrls)||[];const G=y((null==l?void 0:l.deepLinkUrl)||"",(null==l?void 0:l.clickThrough)||""),{companions:Y=[],companionResourceUrls:X=[]}=c;Y.length&&(K=[...Y],j=[...X]);return{adId:E,adName:v,campaignId:A,campaignName:I,marketerId:S,marketerName:w,brand:D,agency:_,orderId:b,orderName:k,qualifiedSignature:(null===(o=null===(r=null===(s=null==a?void 0:a.ext)||void 0===s?void 0:s.modules)||void 0===r?void 0:r.render)||void 0===o?void 0:o.signature)||"",width:h,height:f,adSystem:L,adTitle:P||F,adDescription:W,ctaText:N,skipOffset:V,adDuration:x,isCTAAvailable:U||H,adClickUrl:M||G,companionResourceUrls:j,hasVideoAdElement:d,companions:K}}r=new WeakMap,o=new WeakMap,a=new WeakMap,l=new WeakMap,d=new WeakMap,c=new WeakMap,u=new WeakMap,h=new WeakMap,f=new WeakMap,p=new WeakMap,E=new WeakMap,s=new WeakSet,v=function(e){var n;const r=null===(n=null==e?void 0:e[0])||void 0===n?void 0:n.isIntersecting;"boolean"==typeof r&&(i(this,h,!0===r,"f"),t(this,s,"m",T).call(this))},m=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,s,"m",T).call(this)},A=function(){i(this,f,!0,"f"),t(this,s,"m",T).call(this)},I=function(){const e=window.document;clearInterval(t(this,E,"f")),i(this,E,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,s,"m",T).call(this))}),1),"f")},T=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"),s=t(this,n?a:l,"f"),r=t(this,n?d:c,"f");s.forEach((e=>e())),r.forEach((e=>e())),i(this,n?d:c,[],"f"),i(this,p,e,"f")},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"}(g||(g={})),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"}(w||(w={})),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"}(_||(_={})),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"}(D||(D={})),function(e){e.PLAY_ONCE="play_once",e.REPEAT="repeat"}(b||(b={}));class P{constructor(){k.set(this,new Map)}static getInstance(){return P.instance}set(e,i){"object"!=typeof e?t(this,k,"f").set(e,i):Object.entries(e).forEach((([e,i])=>{t(this,k,"f").set(e,i)}))}get(e){var i;return"string"!=typeof e||0==e.length?t(this,k,"f"):null!==(i=t(this,k,"f").get(e))&&void 0!==i?i:null}get isSDKInitialized(){return Boolean(t(this,k,"f").get(_.SDK_INITIALIZED))}}k=new WeakMap,P.instance=new P;const N=P.getInstance();var U,M,L,F,W;!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]"}(U||(U={}));class V{static post(t){return e(this,void 0,void 0,(function*(){const{url:e,payload:i,headers:s={},credentials:r}=t||{};let o={method:"POST",body:JSON.stringify(i)};r&&(o.credentials=r),s&&(o.headers=s);const a=new AbortController;o.signal=a.signal;return[fetch(e,o).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)))),a]}))}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=N.get(_.ACCOUNT_KEY),t=N.get(_.DGS_ENDPOINT);N.get(_.DGS_XAUTH);const i=(t||"").replace("ACCOUNT_KEY",e);return M.get(i)}static UserProfileService(t){return e(this,void 0,void 0,(function*(){const e=N.get(_.ACCOUNT_KEY),i=N.get(_.UPS_ENDPOINT),n=N.get(_.UPS_XAUTH),s=(i||"").replace("ACCOUNT_KEY",e),[r]=yield M.post({url:s,headers:{"X-AUTH":n},payload:t});return r}))}static AdQuery(e){const{ACCOUNT_KEY:t,AS_ENDPOINT:i}=_,n=N.get(t)||"",s=N.get(i);return M.post({url:s.replace("ACCOUNT_KEY",n),payload:e,credentials:"include"})}static replaceAllMacros(e,t){const i=Object.keys(U);if(0===i.length)return e;const{ifa:n=""}=window.VmaxAdManager.getDevice().getPayload();return i.forEach((i=>{var s;const r=U[i];let o;o=r===U.randomCcb?Date.now().toString():r===U.deviceIFA?n:t&&(null===(s=t[r])||void 0===s?void 0:s.toString())||"";const a=new RegExp(this.escapeRegExp(r),"g");e=e.replace(a,o)})),t||i.forEach((t=>{const i=U[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(M,M,"m",L).call(M,e)}))}}M=V,L=function(t){return e(this,void 0,void 0,(function*(){try{const e=window.VmaxAdManager.getSite().getPayload(),{pageUrl:i,referrerUrl:s}=e,r=yield fetch(t,{method:"GET",headers:{Connection:"keep-alive","X-Requested-with":`${i}`},credentials:"include"});r.ok||n("Tracker request failed:",r.status,r.statusText)}catch(e){n("Error while firing the tracker:",e)}}))};class x{constructor(e=new Map){F.set(this,new Map),i(this,F,e,"f")}fireTracker(e,i){const n=t(this,F,"f").get(e);n&&V.FireTracker(n,i)}}F=new WeakMap,function(e){e.FILLED="filled",e.INS="ins",e.ATTRIBUTE_FILTER="data-ad-status",e.ATTRIBUTES="attributes"}(W||(W={}));var H,K=W;!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"}(H||(H={}));var j,G,Y,X,B,Q,$,z,q,J,Z,ee,te,ie,ne,se,re,oe,ae=H;return G=new WeakMap,Y=new WeakMap,X=new WeakMap,B=new WeakMap,Q=new WeakMap,$=new WeakMap,z=new WeakMap,q=new WeakMap,J=new WeakMap,Z=new WeakMap,ee=new WeakMap,te=new WeakMap,j=new WeakSet,ie=function(){const{IMPRESSION:e,NO_FILL:n,FILL:s}=ae,{burl:r,nurl:o,lurl:a}=t(this,G,"f")||{};r&&t(this,J,"f").set(e,[r]),o&&t(this,J,"f").set(s,[o]),a&&t(this,J,"f").set(n,[a]),i(this,Y,new x(t(this,J,"f")),"f")},ne=function(e,i,n){const s=null==e?void 0:e.querySelector(K.INS),r=new MutationObserver((s=>{s.forEach((s=>{if(s.type===K.ATTRIBUTES){const r=s.attributeName||"";if(s.target.getAttribute(r)===K.FILLED){console.debug("SDK: Adsense filled");try{t(this,j,"m",re).call(this,e),i()}catch(e){t(this,j,"m",se).call(this,"7"),console.error("Impression cannot be fired")}}else t(this,j,"m",se).call(this,"2"),this.destroy(),n("Adsense not filled")}}))}));s&&r.observe(s,{attributes:!0,attributeFilter:[K.ATTRIBUTE_FILTER]})},se=function(e){t(this,Y,"f").fireTracker(ae.NO_FILL,Object.assign(Object.assign({},t(this,te,"f")),{[U.noFill]:e,[U.noFillError]:e}))},re=function(e){t(this,Y,"f").fireTracker(ae.FILL,Object.assign({},t(this,te,"f"))),i(this,Z,new O(e),"f"),t(this,Z,"f").enter(t(this,Q,"f")),t(this,Z,"f").exit(t(this,$,"f")),t(this,Z,"f").enterOnce(t(this,j,"m",oe).bind(this))},oe=function(){var e;t(this,Y,"f").fireTracker(ae.IMPRESSION,Object.assign({},t(this,te,"f"))),null===(e=t(this,X,"f"))||void 0===e||e.AdImpression()},class{constructor(){j.add(this),G.set(this,void 0),Y.set(this,void 0),X.set(this,void 0),B.set(this,null),Q.set(this,(()=>{})),$.set(this,(()=>{})),z.set(this,(()=>{})),q.set(this,(()=>{})),J.set(this,new Map),this.canRefresh=!0,Z.set(this,void 0),ee.set(this,void 0),te.set(this,void 0)}getAllSignatures(){return"nw.adsense"}prepare(n){return e(this,void 0,void 0,(function*(){var e;const{bid:s,listeners:r}=n||{};i(this,G,s,"f");const o=(null===(e=t(this,G,"f"))||void 0===e?void 0:e.adm)||"";if(!o||""===o)return Promise.reject("No ad object found");const a=JSON.parse(o),{adnetwork_params:l}=a,{adunitid:d,htmladcode:c}=l;i(this,B,document.createRange().createContextualFragment(c),"f");const{AdPaused:u,AdResumed:h,AdClicked:f}=r||{};return"function"==typeof u&&i(this,$,u,"f"),"function"==typeof h&&i(this,Q,h,"f"),"function"==typeof f&&i(this,z,f,"f"),i(this,X,r,"f"),t(this,j,"m",ie).call(this),Promise.resolve()}))}validateElement(e){return e instanceof DocumentFragment}render(e){const{container:n}=e||{};return i(this,ee,document.createElement("div"),"f"),n&&t(this,B,"f")&&this.validateElement(t(this,B,"f"))?(n.appendChild(t(this,ee,"f")),t(this,ee,"f").appendChild(t(this,B,"f")),i(this,te,{[U.demandPartnerSDKVersion]:""},"f"),new Promise(((e,i)=>{t(this,j,"m",ne).call(this,t(this,ee,"f"),e,i)}))):(t(this,j,"m",se).call(this,"7"),Promise.reject("Invalid HTML ad code"))}destroy(){var e,n,s;null===(e=t(this,Z,"f"))||void 0===e||e.destroy(),i(this,Z,null,"f"),i(this,G,{},"f"),null===(s=null===(n=t(this,ee,"f"))||void 0===n?void 0:n.parentNode)||void 0===s||s.removeChild(t(this,ee,"f"))}closeAd(){t(this,X,"f").AdClosed(),this.canRefresh=!1,this.destroy()}getVmaxEventTracker(){return t(this,Y,"f")}getVmaxAdInfo(){const e=C({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)||""}}}));