/*! * artplayer-plugin-vast.js v1.2.0 * Github: https://github.com/zhw2590582/ArtPlayer * (c) 2017-2026 Harvey Zhao * Released under the MIT License. */ !function(t,e){"object"===typeof exports&&"undefined"!==typeof module?module.exports=e():"function"==typeof define&&define.amd?(t.artplayerPluginVast=e(),define(function(){return t.artplayerPluginVast})):(t="undefined"!==typeof globalThis?globalThis:t||self).artplayerPluginVast=e()}(this,function(){"use strict";var t=null,e=function(){t=null};function i(t,e,i){return e&&function(t,e){for(var i=0;it.length)&&(e=t.length);for(var i=0,n=new Array(e);i-1&&(v(this,q)[q].splice(e,1),this.g(v(this,q)[q]))},n.resizeAd=function(t,e){v(this,j)[j]=t,v(this,N)[N]=e,v(this,M)[M]&&v(this,M)[M].resize(t,e,this.k()),v(this,_)[_].style.width=t+"px",v(this,_)[_].style.height=e+"px"},n.reset=function(t){void 0===t&&(t=!1),t&&(v(this,F)[F]=!1,v(this,G)[G]=!1,v(this,W)[W]=!1),this.C(),v(this,q)[q]=[],v(this,Z)[Z]=!1,v(this,$)[$]=void 0,v(this,M)[M]&&v(this,M)[M].destroy(),v(this,M)[M]=void 0,v(this,I)[I].settings.setAutoPlayAdBreaks(!0),t&&this.P(),v(this,_)[_].style.display="none"},n.P=function(){v(this,U)[U]&&(v(this,U)[U].removeEventListener(v(this,I)[I].AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,this.u,!1),v(this,U)[U].removeEventListener(v(this,I)[I].AdErrorEvent.Type.AD_ERROR,this.l,!1),v(this,U)[U].destroy()),v(this,L)[L]&&v(this,L)[L].destroy()},n.destroy=function(){var t,e,i,n,s=this;this.reset(!0),v(this,C)[C].destroy(),P.forEach(function(t){v(s,D)[D].removeEventListener(t,s.o)}),null==(t=v(this,U)[U])||t.removeEventListener(v(this,I)[I].AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,this.u,!1),null==(e=v(this,L)[L])||e.destroy(),null==(i=v(this,U)[U])||i.destroy(),v(this,F)[F]=!1,v(this,W)[W]=!1,v(this,G)[G]=!1,null==(n=v(this,z)[z])||n.disconnect()},n.isCustomPlaybackUsed=function(){return!1===v(this,I)[I].settings.getDisableCustomPlaybackForIOS10Plus()&&!v(this,_)[_].querySelector("video")},n.C=function(){window.clearTimeout(v(this,Y)[Y]),window.clearTimeout(v(this,X)[X]),v(this,Y)[Y]=void 0,v(this,X)[X]=void 0,v(this,x)[x]=void 0,v(this,Q)[Q]=void 0,v(this,K)[K]=void 0,v(this,_)[_].style.display="none",v(this,_)[_].classList.remove("nonlinear"),v(this,M)[M]&&this.R()},n.o=function(t){var e=this;if(v(this,C)[C].enabled||"volumechange"===t.type){if("timeupdate"===t.type){if(v(this,M)[M]){var i=v(this,M)[M].getCuePoints().filter(function(t){return t>=0&&t=.5&&(this.dispatchEvent(new A(R.MEDIA_IMPRESSION)),v(this,F)[F]=!0)}if("play"!==t.type||v(this,G)[G]||v(this,H)[H]||(this.dispatchEvent(new A(R.MEDIA_START)),v(this,G)[G]=!0),"ended"===t.type&&(this.isCustomPlaybackUsed()&&v(this,D)[D].currentTime===v(this,D)[D].duration&&v(this,q)[q].indexOf(-1)>-1&&(v(this,D)[D].currentTime=v(this,D)[D].duration-1e-5,v(this,W)[W]=!0),v(this,U)[U].contentComplete(),v(this,M)[M]||this.T()),!window.ResizeObserver&&v(this,B)[B].autoResize&&"loadedmetadata"===t.type){var n=v(this,D)[D],s=n.offsetHeight,r=n.offsetWidth;v(this,j)[j]=r,v(this,N)[N]=s,this.R()}v(this,H)[H]&&"volumechange"!==t.type||this.dispatchEvent(new A(t.type))}},n.S=function(t){var e=this,i=v(this,I)[I].AdEvent;switch(t.type){case i.Type.LOADED:var n=t.getAd();v(this,$)[$]&&0===v(this,q)[q].length?v(this,$)[$]({ad:n,start:function(){e.M(),v(e,$)[$]=void 0},startWithoutReset:function(){e.M()}}):v(this,V)[V]=n;break;case i.Type.AD_BREAK_READY:this.C(),v(this,$)[$]?(v(this,$)[$]({ad:v(this,V)[V],adBreakTime:t.getAdData().adBreakTime,start:function(){e.M(),v(e,$)[$]=void 0},startWithoutReset:function(){e.M()}}),v(this,V)[V]=void 0):this.M();break;case i.Type.STARTED:var s=v(this,x)[x]=t.getAd();s.getAdPodInfo().getAdPosition()>1&&v(this,M)[M].setVolume(v(this,M)[M].getVolume()),v(this,_)[_].classList.remove("nonlinear"),this.R(),s.isLinear()?(v(this,C)[C].disable(),v(this,K)[K]=s.getDuration(),v(this,Q)[Q]=0):(v(this,_)[_].classList.add("nonlinear"),this.I()),v(this,_)[_].style.display="",v(this,Z)[Z]&&(v(this,Z)[Z]=!1,v(this,M)[M].pause());break;case i.Type.ALL_ADS_COMPLETED:if(v(this,W)[W])return;this.isCustomPlaybackUsed()&&Boolean(v(this,x)[x])&&-1!==v(this,x)[x].getAdPodInfo().getTimeOffset()&&this.I(),this.reset();break;case i.Type.CONTENT_PAUSE_REQUESTED:this.C(),v(this,x)[x]=t.getAd(),v(this,_)[_].style.display="",v(this,D)[D].pause(),this.R(),v(this,x)[x]&&this.A(v(this,x)[x].getAdPodInfo().getTimeOffset()),v(this,M)[M].setVolume(v(this,D)[D].muted?0:v(this,D)[D].volume),v(this,C)[C].disable(),v(this,K)[K]=v(this,x)[x].getDuration(),v(this,Q)[Q]=0;break;case i.Type.CONTENT_RESUME_REQUESTED:var r=Boolean(v(this,x)[x]);if(r){var o=v(this,M)[M].getVolume();v(this,D)[D].muted=0===o,v(this,D)[D].volume=v(this,J)[J]}v(this,W)[W]&&(v(this,D)[D].currentTime=v(this,D)[D].duration+1,v(this,W)[W]=!1),v(this,D)[D].ended?(this.reset(),this.T()):this.C(),r&&(v(this,Z)[Z]=!1,this.I());break;case i.Type.AD_METADATA:this.g(v(this,M)[M].getCuePoints()),-1===v(this,q)[q].indexOf(0)&&(v(this,$)[$]?v(this,$)[$]({start:function(){e.I(),v(e,$)[$]=void 0},startWithoutReset:function(){e.I()}}):this.I());break;case i.Type.AD_PROGRESS:var a=t.getAdData();v(this,Q)[Q]=a.currentTime,v(this,K)[K]=a.duration;break;case i.Type.LOG:var d=t.getAdData();v(this,$)[$]?v(this,$)[$]({start:function(){e.I(),v(e,$)[$]=void 0},startWithoutReset:function(){e.I()}}):d.adError&&!v(this,x)[x]&&this.I();break;case i.Type.VOLUME_CHANGED:var h=v(this,M)[M].getVolume();h>0&&(v(this,J)[J]=h)}},n.l=function(t){this.j(this.B(t))},n.u=function(t){var e=this,i=v(this,I)[I],n=i.AdEvent,s=i.AdErrorEvent.Type.AD_ERROR;window.clearTimeout(v(this,Y)[Y]);var r=v(this,M)[M]=t.getAdsManager(v(this,C)[C],v(this,k)[k]);Object.keys(n.Type).forEach(function(t){r.addEventListener(n.Type[t],function(i){if(e.S(i),R[t]){var n=["LOG","AD_PROGRESS"].indexOf(t)>-1;e.dispatchEvent(new A(R[t],{detail:{ad:i.getAd()||v(e,x)[x],adData:n?i.getAdData():{}}}))}})}),r.addEventListener(s,function(t){return e.j(e.B(t))});try{var o;r.init(v(this,j)[j],v(this,N)[N],this.k()),r.setVolume(v(this,D)[D].muted?0:v(this,D)[D].volume),null==(o=v(this,L)[L])||o.initialize(),v(this,$)[$]||this.M()}catch(a){this.j(new S(a.message))}},n.M=function(){if(v(this,G)[G]||(this.dispatchEvent(new A(R.MEDIA_START)),v(this,G)[G]=!0),v(this,M)[M])try{v(this,M)[M].start()}catch(t){this.j(new S(t.message))}else this.I()},n.T=function(){var t=this;setTimeout(function(){v(t,F)[F]=!1,v(t,G)[G]=!1,v(t,W)[W]=!1,t.dispatchEvent(new A(R.MEDIA_STOP))},1)},n.v=function(t){for(var e,i=function(t){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(e)return(e=e.call(t)).next.bind(e);if(Array.isArray(t)||(e=function(t,e){if(t){if("string"==typeof t)return u(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?u(t,e):void 0}}(t))){e&&(t=e);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[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.")}(t);!(e=i()).done;){var n=e.value;n.contentBoxSize&&1===n.contentBoxSize.length?(v(this,j)[j]=n.contentBoxSize[0].inlineSize,v(this,N)[N]=n.contentBoxSize[0].blockSize):n.contentBoxSize&&n.contentBoxSize.inlineSize?(v(this,j)[j]=n.contentBoxSize.inlineSize,v(this,N)[N]=n.contentBoxSize.blockSize):(v(this,j)[j]=n.contentRect.width,v(this,N)[N]=n.contentRect.height)}this.R()},n.R=function(){if(v(this,B)[B].autoResize&&v(this,M)[M]){var t=v(this,x)[x],e=this.k();t&&!t.isLinear()?t&&(t.getWidth()>v(this,j)[j]||t.getHeight()>v(this,N)[N]?this.resizeAd(v(this,j)[j],v(this,N)[N]):(v(this,M)[M].resize(t.getWidth(),t.getHeight()+20,e),v(this,_)[_].style.width=t.getWidth()+"px",v(this,_)[_].style.height=t.getHeight()+20+"px")):this.resizeAd(v(this,j)[j],v(this,N)[N])}},n.k=function(){return document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement||v(this,D)[D].webkitDisplayingFullscreen?v(this,I)[I].ViewMode.FULLSCREEN:v(this,I)[I].ViewMode.NORMAL},n.I=function(){var t=this;v(this,_)[_].style.display="none",v(this,D)[D].ended||(v(this,C)[C].enable(),v(this,Z)[Z]?(v(this,D)[D].pause(),this.dispatchEvent(new A("pause"))):(this.p().then(function(){}).catch(function(){t.dispatchEvent(new A("pause"))}),this.dispatchEvent(new A("play")),this.dispatchEvent(new A(R.MEDIA_RESUMED))),v(this,Z)[Z]=!1)},n.B=function(t){var e=t.getError(),i=new S(e.getMessage());return i.type=e.getType(),i.errorCode=e.getErrorCode(),i.vastErrorCode=e.getVastErrorCode&&e.getVastErrorCode(),i.innerError=e.getInnerError(),i},n.j=function(t){var e=this;this.dispatchEvent(new A(R.AD_ERROR,{detail:{error:t}})),this.C(),v(this,$)[$]?v(this,$)[$]({start:function(){e.I(),v(e,$)[$]=void 0},startWithoutReset:function(){e.I()}}):this.I()},i(e,[{key:"volume",get:function(){return!v(this,C)[C].enabled&&v(this,M)[M]?v(this,M)[M].getVolume():v(this,D)[D].volume},set:function(t){!v(this,C)[C].enabled&&v(this,M)[M]&&v(this,M)[M].setVolume(t),v(this,D)[D].volume=t}},{key:"muted",get:function(){return!v(this,C)[C].enabled&&v(this,M)[M]?0===v(this,M)[M].getVolume():v(this,D)[D].muted},set:function(t){!v(this,C)[C].enabled&&v(this,M)[M]&&v(this,M)[M].setVolume(t?0:v(this,J)[J]),v(this,D)[D].muted=t}},{key:"currentTime",get:function(){return void 0!==v(this,Q)[Q]?v(this,Q)[Q]:v(this,D)[D].currentTime},set:function(t){v(this,C)[C].enabled&&(v(this,D)[D].currentTime=t)}},{key:"duration",get:function(){return void 0!==v(this,K)[K]?v(this,K)[K]:v(this,D)[D].duration}},{key:"cuePoints",get:function(){return[].concat(v(this,q)[q])}}]),e}(w);return function(i){return n=>{return s=null,r=null,o=function*(){const{template:s,constructor:r}=n,{createElement:o,setStyles:a}=r.utils,{$video:d,$player:h}=s;yield function(){var i=window;return i.google&&i.google.ima?Promise.resolve(i.google.ima):t||((t=new Promise(function(t,e){var i=document.createElement("script");i.async=!0,i.src="https://imasdk.googleapis.com/js/sdkloader/ima3.js",i.onload=t,i.onerror=e,document.body.appendChild(i)}).then(function(){return i.google.ima})).then(e).catch(e),t)}();const u=window.google.ima,l=new u.AdsRenderingSettings;l.restoreCustomPlaybackStateOnAdBreakComplete=!0,l.enablePreloading=!0;const c=new T;let v=!1,f=null,p=null;function y(){return f||(p=function(){const t=o("div"),e=`art-vast-${Date.now()}`;return t.id=e,a(t,{position:"absolute",inset:"0",width:"100%",height:"100%",zIndex:"150",backgroundColor:"black",display:"none",pointerEvents:"auto"}),t}(),h.appendChild(p),f=new et(u,d,p,l,c),f.addEventListener("AdContentPauseRequested",()=>{v=!0,p.style.display="block"}),f.addEventListener("AdContentResumeRequested",()=>{v=!1,p.style.display="none"}),f.addEventListener("AdStarted",()=>{v=!0,p.style.display="block"}),f.addEventListener("AdError",t=>{console.error("VAST Ad Error:",t.detail),v=!1,p.style.display="none"}),f)}return"function"===typeof i&&(yield i({art:n,playUrl:function(t,e={}){if(v)return;f||y();const i=new u.AdsRequest;i.adTagUrl=t;for(const n in e)i[n]=e[n];f.playAds(i)},playRes:function(t,e={}){if(v)return;f||y();const i=new u.AdsRequest;i.adsResponse=t;for(const n in e)i[n]=e[n];f.playAds(i)},init:y,ima:u,adsRenderingSettings:l,playerOptions:c,get imaPlayer(){return f},get container(){return p}})),{name:"artplayerPluginVast",destroy:function(){(null==f?void 0:f.destroy)&&f.destroy(),(null==p?void 0:p.parentNode)&&p.parentNode.removeChild(p),p=null,f=null}}},new Promise((t,e)=>{var i=t=>{try{a(o.next(t))}catch(i){e(i)}},n=t=>{try{a(o.throw(t))}catch(i){e(i)}},a=e=>e.done?t(e.value):Promise.resolve(e.value).then(i,n);a((o=o.apply(s,r)).next())});var s,r,o}}});