mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-09 03:46:16 -08:00
8 lines
25 KiB
JavaScript
8 lines
25 KiB
JavaScript
/*!
|
|
* 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;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}(t.prototype,e),t}function n(){return n=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},n.apply(this,arguments)}function r(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,o(t,e)}function s(t){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function o(t,e){return(o=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function a(t,e,i){return(a=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}()?Reflect.construct:function(t,e,i){var n=[null];n.push.apply(n,e);var r=new(Function.bind.apply(t,n));return i&&o(r,i.prototype),r}).apply(null,arguments)}function u(t){var e="function"==typeof Map?new Map:void 0;return u=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,i)}function i(){return a(t,arguments,s(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),o(i,t)},u(t)}function l(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function d(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}var h=0;function c(t){return"__private_"+h+++"_"+t}function f(t,e){if(!Object.prototype.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var p={};p.CustomEvent="function"==typeof CustomEvent?CustomEvent:function(t){return e[t]=new e("").constructor[t],e;function e(t,e){e||(e={});var i=document.createEvent("CustomEvent");return i.initCustomEvent(t,!!e.bubbles,!!e.cancelable,e.detail),i}}("prototype");var v,y,E,A=p.CustomEvent,m=c("mediaElement"),b=c("currentTime"),g=c("enabled"),O=function(){function t(t){Object.defineProperty(this,m,{writable:!0,value:void 0}),Object.defineProperty(this,b,{writable:!0,value:void 0}),Object.defineProperty(this,g,{writable:!0,value:void 0}),this.seeking=void 0,f(this,m)[m]=t,f(this,b)[b]=0,f(this,g)[g]=!1,this.seeking=!1,this.t=this.t.bind(this),this.i=this.i.bind(this),this.h=this.h.bind(this),this.enable()}var e=t.prototype;return e.i=function(){this.seeking=!0},e.h=function(){this.seeking=!1},e.t=function(){var t,e;this.seeking||null!=(t=f(this,m)[m])&&t.paused||(f(this,b)[b]=null==(e=f(this,m)[m])?void 0:e.currentTime)},e.enable=function(){var t,e,i;f(this,g)[g]||(null==(t=f(this,m)[m])||t.addEventListener("seeking",this.i),null==(e=f(this,m)[m])||e.addEventListener("seeked",this.h),null==(i=f(this,m)[m])||i.addEventListener("timeupdate",this.t),f(this,g)[g]=!0)},e.disable=function(){var t,e,i;f(this,g)[g]&&(null==(t=f(this,m)[m])||t.removeEventListener("seeking",this.i),null==(e=f(this,m)[m])||e.removeEventListener("seeked",this.h),null==(i=f(this,m)[m])||i.removeEventListener("timeupdate",this.t),f(this,g)[g]=!1)},e.play=function(){var t=this;return new Promise(function(e){var i;e(null==(i=f(t,m)[m])?void 0:i.play())})},e.pause=function(){var t;null==(t=f(this,m)[m])||t.pause()},e.reset=function(){f(this,b)[b]=0,f(this,g)[g]=!1,this.seeking=!1,this.enable()},e.destroy=function(){f(this,b)[b]=0,f(this,g)[g]=!1,this.seeking=!1,this.disable(),f(this,m)[m]=void 0},i(t,[{key:"enabled",get:function(){return f(this,g)[g]}},{key:"currentTime",get:function(){return f(this,b)[b]}},{key:"duration",get:function(){var t;return null==(t=f(this,m)[m])?void 0:t.duration}},{key:"muted",get:function(){var t;return null==(t=f(this,m)[m])?void 0:t.muted}},{key:"volume",get:function(){var t;return null==(t=f(this,m)[m])?void 0:t.volume}}]),t}(),w=function(){function t(){this.delegate=document.createDocumentFragment()}var e=t.prototype;return e.addEventListener=function(){this.delegate.addEventListener.apply(this.delegate,[].slice.call(arguments))},e.dispatchEvent=function(){return this.delegate.dispatchEvent.apply(this.delegate,[].slice.call(arguments))},e.removeEventListener=function(){return this.delegate.removeEventListener.apply(this.delegate,[].slice.call(arguments))},t}(),T=["abort","canplay","canplaythrough","durationchange","emptied","ended","error","loadeddata","loadedmetadata","loadstart","pause","play","playing","progress","ratechange","seeked","seeking","stalled","suspend","timeupdate","volumechange","waiting"];(E=v||(v={})).MEDIA_START="MediaStart",E.MEDIA_IMPRESSION="MediaImpression",E.MEDIA_STOP="MediaStop",E.MEDIA_CUE_POINTS_CHANGE="MediaCuePointsChange",E.MEDIA_RESUMED="MediaResumed",function(t){t.AD_ERROR="AdError",t.AD_BUFFERING="AdBuffering",t.LOADED="AdLoaded",t.IMPRESSION="AdImpression",t.STARTED="AdStarted",t.FIRST_QUARTILE="AdFirstQuartile",t.MIDPOINT="AdMidpoint",t.THIRD_QUARTILE="AdThirdQuartile",t.AD_PROGRESS="AdProgress",t.COMPLETE="AdComplete",t.CLICK="AdClick",t.PAUSED="AdPaused",t.RESUMED="AdResumed",t.SKIPPED="AdSkipped",t.SKIPPABLE_STATE_CHANGED="AdSkippableStateChanged",t.VOLUME_CHANGED="AdVolumeChanged",t.VOLUME_MUTED="AdMuted",t.AD_METADATA="AdMetadata",t.AD_BREAK_READY="AdBreakReady",t.CONTENT_PAUSE_REQUESTED="AdContentPauseRequested",t.CONTENT_RESUME_REQUESTED="AdContentResumeRequested",t.ALL_ADS_COMPLETED="AdAllAdsCompleted",t.DURATION_CHANGE="AdDurationChange",t.INTERACTION="AdInteraction",t.LINEAR_CHANGED="AdLinearChanged",t.LOG="AdLog",t.USER_CLOSE="AdUserClose",t.AD_CAN_PLAY="AdCanPlay",t.EXPANDED_CHANGED="AdExpandedChanged",t.VIEWABLE_IMPRESSION="AdViewableImpression"}(y||(y={}));var P=n({},y,v),R=function(){this.disableCustomPlaybackForIOS10Plus=!1,this.autoResize=!0,this.clickTrackingElement=void 0},S=function(t){function e(){var e;return(e=t.call.apply(t,[this].concat([].slice.call(arguments)))||this).errorCode=void 0,e.innerError=void 0,e.type=void 0,e.vastErrorCode=void 0,e}return r(e,t),e}(u(Error));S.ERROR_CODE_ADS_MANAGER_LOADED_TIMEOUT=9e3,S.ERROR_CODE_REQUEST_ADS_TIMEOUT=9001;var D=c("mediaElement"),_=c("adElement"),C=c("customPlayhead"),k=c("adsRenderingSettings"),I=c("ima"),L=c("adDisplayContainer"),M=c("adsManager"),j=c("width"),N=c("height"),U=c("adsLoader"),x=c("playerOptions"),z=c("resizeObserver"),B=c("currentAd"),V=c("loadedAd"),G=c("mediaStartTriggered"),F=c("mediaImpressionTriggered"),H=c("mediaInActivation"),W=c("customPlaybackTimeAdjustedOnEnded"),Q=c("cuePoints"),q=c("adCurrentTime"),$=c("adDuration"),K=c("startAdCallback"),Y=c("adsManagerLoadedTimeout"),X=c("requestAdsTimeout"),Z=c("wasExternallyPaused"),J=c("lastNonZeroAdVolume"),tt=c("activatePromise"),et=function(t){function e(e,i,n,r,s){var o;void 0===r&&(r=new e.AdsRenderingSettings),void 0===s&&(s=new R),o=t.call(this)||this,Object.defineProperty(l(o),D,{writable:!0,value:void 0}),Object.defineProperty(l(o),_,{writable:!0,value:void 0}),Object.defineProperty(l(o),C,{writable:!0,value:void 0}),Object.defineProperty(l(o),k,{writable:!0,value:void 0}),Object.defineProperty(l(o),I,{writable:!0,value:void 0}),Object.defineProperty(l(o),L,{writable:!0,value:void 0}),Object.defineProperty(l(o),M,{writable:!0,value:void 0}),Object.defineProperty(l(o),j,{writable:!0,value:void 0}),Object.defineProperty(l(o),N,{writable:!0,value:void 0}),Object.defineProperty(l(o),U,{writable:!0,value:void 0}),Object.defineProperty(l(o),x,{writable:!0,value:void 0}),Object.defineProperty(l(o),z,{writable:!0,value:void 0}),Object.defineProperty(l(o),B,{writable:!0,value:void 0}),Object.defineProperty(l(o),V,{writable:!0,value:void 0}),Object.defineProperty(l(o),G,{writable:!0,value:!1}),Object.defineProperty(l(o),F,{writable:!0,value:!1}),Object.defineProperty(l(o),H,{writable:!0,value:!1}),Object.defineProperty(l(o),W,{writable:!0,value:!1}),Object.defineProperty(l(o),Q,{writable:!0,value:[]}),Object.defineProperty(l(o),q,{writable:!0,value:void 0}),Object.defineProperty(l(o),$,{writable:!0,value:void 0}),Object.defineProperty(l(o),K,{writable:!0,value:void 0}),Object.defineProperty(l(o),Y,{writable:!0,value:void 0}),Object.defineProperty(l(o),X,{writable:!0,value:void 0}),Object.defineProperty(l(o),Z,{writable:!0,value:!1}),Object.defineProperty(l(o),J,{writable:!0,value:1}),Object.defineProperty(l(o),tt,{writable:!0,value:Promise.resolve()}),f(l(o),D)[D]=i,f(l(o),_)[_]=n,f(l(o),I)[I]=e,f(l(o),x)[x]=s,f(l(o),k)[k]=r,f(l(o),k)[k].restoreCustomPlaybackStateOnAdBreakComplete=!0,s.disableCustomPlaybackForIOS10Plus&&!f(l(o),D)[D].hasAttribute("playsinline")&&f(l(o),D)[D].setAttribute("playsinline",""),f(l(o),I)[I].settings.setDisableCustomPlaybackForIOS10Plus(s.disableCustomPlaybackForIOS10Plus),f(l(o),C)[C]=new O(f(l(o),D)[D]),o.o=o.o.bind(l(o)),T.forEach(function(t){f(l(o),D)[D].addEventListener(t,o.o)}),o.u=o.u.bind(l(o)),o.l=o.l.bind(l(o));var a=f(l(o),D)[D],u=a.offsetHeight,d=a.offsetWidth;return f(l(o),j)[j]=d,f(l(o),N)[N]=u,s.autoResize&&window.ResizeObserver&&(f(l(o),z)[z]=new window.ResizeObserver(function(t){return o.v(t)}),f(l(o),z)[z].observe(f(l(o),D)[D])),o}r(e,t);var n=e.prototype;return n.activate=function(){var t=this;if(!f(this,G)[G]&&!f(this,H)[H]&&(f(this,H)[H]=!0,f(this,D)[D].paused)){var e=function(){return f(t,D)[D].pause(),new Promise(function(e){setTimeout(function(){f(t,H)[H]=!1,e()},1)})};f(this,tt)[tt]=new Promise(function(e){return e(f(t,D)[D].play())}).then(e).catch(e)}},n.playAds=function(t){this.m(t)},n.loadAds=function(t,e){this.m(t,!1,e)},n.p=function(){var t=this;return f(this,tt)[tt].then(function(){return new Promise(function(e){return e(f(t,D)[D].play())})})},n.m=function(t,e,i){var n=this;void 0===e&&(e=!0),this.reset(),this.O(),f(this,I)[I].settings.setAutoPlayAdBreaks(e),f(this,D)[D].ended&&(f(this,C)[C].reset(),f(this,D)[D].currentTime=0),f(this,K)[K]=i,t.linearAdSlotWidth=f(this,j)[j],t.linearAdSlotHeight=f(this,N)[N],t.nonLinearAdSlotWidth=f(this,j)[j],t.nonLinearAdSlotHeight=f(this,N)[N],null==t.contentDuration&&(t.contentDuration=-3),f(this,Y)[Y]=window.setTimeout(function(){var t=new S("No adsManagerLoadedEvent within 5000ms.");t.errorCode=S.ERROR_CODE_ADS_MANAGER_LOADED_TIMEOUT,n.j(t)},5e3),f(this,X)[X]=window.setTimeout(function(){var t=new S("No response for ads-request within 10000ms.");t.errorCode=S.ERROR_CODE_REQUEST_ADS_TIMEOUT,n.j(t)},1e4),f(this,U)[U].requestAds(t)},n.O=function(){f(this,L)[L]=new(f(this,I)[I].AdDisplayContainer)(f(this,_)[_],f(this,x)[x].disableCustomPlaybackForIOS10Plus?void 0:f(this,D)[D],f(this,x)[x].clickTrackingElement),f(this,U)[U]=new(f(this,I)[I].AdsLoader)(f(this,L)[L]),f(this,U)[U].addEventListener(f(this,I)[I].AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,this.u,!1),f(this,U)[U].addEventListener(f(this,I)[I].AdErrorEvent.Type.AD_ERROR,this.l,!1)},n.skipAd=function(){f(this,M)[M]&&f(this,M)[M].skip()},n.discardAdBreak=function(){f(this,M)[M]&&f(this,M)[M].discardAdBreak()},n.play=function(){var t=this;f(this,Z)[Z]=!1,!f(this,C)[C].enabled&&f(this,M)[M]?f(this,M)[M].resume():f(this,Y)[Y]||this.p().then(function(){}).catch(function(){t.dispatchEvent(new A("pause"))})},n.pause=function(){f(this,Z)[Z]=!0,!f(this,C)[C].enabled&&f(this,M)[M]?f(this,M)[M].pause():f(this,D)[D].pause()},n.g=function(t){f(this,Q)[Q]=[].concat(t),this.dispatchEvent(new A(P.MEDIA_CUE_POINTS_CHANGE,{detail:{cuePoints:[].concat(f(this,Q)[Q])}}))},n.A=function(t){var e=this.cuePoints.indexOf(t);e>-1&&(f(this,Q)[Q].splice(e,1),this.g(f(this,Q)[Q]))},n.resizeAd=function(t,e){f(this,j)[j]=t,f(this,N)[N]=e,f(this,M)[M]&&f(this,M)[M].resize(t,e,this.k()),f(this,_)[_].style.width=t+"px",f(this,_)[_].style.height=e+"px"},n.reset=function(t){void 0===t&&(t=!1),t&&(f(this,F)[F]=!1,f(this,G)[G]=!1,f(this,W)[W]=!1),this.C(),f(this,Q)[Q]=[],f(this,Z)[Z]=!1,f(this,K)[K]=void 0,f(this,M)[M]&&f(this,M)[M].destroy(),f(this,M)[M]=void 0,f(this,I)[I].settings.setAutoPlayAdBreaks(!0),t&&this.P(),f(this,_)[_].style.display="none"},n.P=function(){f(this,U)[U]&&(f(this,U)[U].removeEventListener(f(this,I)[I].AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,this.u,!1),f(this,U)[U].removeEventListener(f(this,I)[I].AdErrorEvent.Type.AD_ERROR,this.l,!1),f(this,U)[U].destroy()),f(this,L)[L]&&f(this,L)[L].destroy()},n.destroy=function(){var t,e,i,n,r=this;this.reset(!0),f(this,C)[C].destroy(),T.forEach(function(t){f(r,D)[D].removeEventListener(t,r.o)}),null==(t=f(this,U)[U])||t.removeEventListener(f(this,I)[I].AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,this.u,!1),null==(e=f(this,L)[L])||e.destroy(),null==(i=f(this,U)[U])||i.destroy(),f(this,F)[F]=!1,f(this,W)[W]=!1,f(this,G)[G]=!1,null==(n=f(this,z)[z])||n.disconnect()},n.isCustomPlaybackUsed=function(){return!1===f(this,I)[I].settings.getDisableCustomPlaybackForIOS10Plus()&&!f(this,_)[_].querySelector("video")},n.C=function(){window.clearTimeout(f(this,Y)[Y]),window.clearTimeout(f(this,X)[X]),f(this,Y)[Y]=void 0,f(this,X)[X]=void 0,f(this,B)[B]=void 0,f(this,q)[q]=void 0,f(this,$)[$]=void 0,f(this,_)[_].style.display="none",f(this,_)[_].classList.remove("nonlinear"),f(this,M)[M]&&this.R()},n.o=function(t){var e=this;if(f(this,C)[C].enabled||"volumechange"===t.type){if("timeupdate"===t.type){if(f(this,M)[M]){var i=f(this,M)[M].getCuePoints().filter(function(t){return t>=0&&t<f(e,C)[C].currentTime}).pop();this.A(i)}!f(this,F)[F]&&f(this,G)[G]&&f(this,D)[D].currentTime>=.5&&(this.dispatchEvent(new A(P.MEDIA_IMPRESSION)),f(this,F)[F]=!0)}if("play"!==t.type||f(this,G)[G]||f(this,H)[H]||(this.dispatchEvent(new A(P.MEDIA_START)),f(this,G)[G]=!0),"ended"===t.type&&(this.isCustomPlaybackUsed()&&f(this,D)[D].currentTime===f(this,D)[D].duration&&f(this,Q)[Q].indexOf(-1)>-1&&(f(this,D)[D].currentTime=f(this,D)[D].duration-1e-5,f(this,W)[W]=!0),f(this,U)[U].contentComplete(),f(this,M)[M]||this.T()),!window.ResizeObserver&&f(this,x)[x].autoResize&&"loadedmetadata"===t.type){var n=f(this,D)[D],r=n.offsetHeight,s=n.offsetWidth;f(this,j)[j]=s,f(this,N)[N]=r,this.R()}f(this,H)[H]&&"volumechange"!==t.type||this.dispatchEvent(new A(t.type))}},n.S=function(t){var e=this,i=f(this,I)[I].AdEvent;switch(t.type){case i.Type.LOADED:var n=t.getAd();f(this,K)[K]&&0===f(this,Q)[Q].length?f(this,K)[K]({ad:n,start:function(){e.M(),f(e,K)[K]=void 0},startWithoutReset:function(){e.M()}}):f(this,V)[V]=n;break;case i.Type.AD_BREAK_READY:this.C(),f(this,K)[K]?(f(this,K)[K]({ad:f(this,V)[V],adBreakTime:t.getAdData().adBreakTime,start:function(){e.M(),f(e,K)[K]=void 0},startWithoutReset:function(){e.M()}}),f(this,V)[V]=void 0):this.M();break;case i.Type.STARTED:var r=f(this,B)[B]=t.getAd();r.getAdPodInfo().getAdPosition()>1&&f(this,M)[M].setVolume(f(this,M)[M].getVolume()),f(this,_)[_].classList.remove("nonlinear"),this.R(),r.isLinear()?(f(this,C)[C].disable(),f(this,$)[$]=r.getDuration(),f(this,q)[q]=0):(f(this,_)[_].classList.add("nonlinear"),this.I()),f(this,_)[_].style.display="",f(this,Z)[Z]&&(f(this,Z)[Z]=!1,f(this,M)[M].pause());break;case i.Type.ALL_ADS_COMPLETED:if(f(this,W)[W])return;this.isCustomPlaybackUsed()&&Boolean(f(this,B)[B])&&-1!==f(this,B)[B].getAdPodInfo().getTimeOffset()&&this.I(),this.reset();break;case i.Type.CONTENT_PAUSE_REQUESTED:this.C(),f(this,B)[B]=t.getAd(),f(this,_)[_].style.display="",f(this,D)[D].pause(),this.R(),f(this,B)[B]&&this.A(f(this,B)[B].getAdPodInfo().getTimeOffset()),f(this,M)[M].setVolume(f(this,D)[D].muted?0:f(this,D)[D].volume),f(this,C)[C].disable(),f(this,$)[$]=f(this,B)[B].getDuration(),f(this,q)[q]=0;break;case i.Type.CONTENT_RESUME_REQUESTED:var s=Boolean(f(this,B)[B]);if(s){var o=f(this,M)[M].getVolume();f(this,D)[D].muted=0===o,f(this,D)[D].volume=f(this,J)[J]}f(this,W)[W]&&(f(this,D)[D].currentTime=f(this,D)[D].duration+1,f(this,W)[W]=!1),f(this,D)[D].ended?(this.reset(),this.T()):this.C(),s&&(f(this,Z)[Z]=!1,this.I());break;case i.Type.AD_METADATA:this.g(f(this,M)[M].getCuePoints()),-1===f(this,Q)[Q].indexOf(0)&&(f(this,K)[K]?f(this,K)[K]({start:function(){e.I(),f(e,K)[K]=void 0},startWithoutReset:function(){e.I()}}):this.I());break;case i.Type.AD_PROGRESS:var a=t.getAdData();f(this,q)[q]=a.currentTime,f(this,$)[$]=a.duration;break;case i.Type.LOG:var u=t.getAdData();f(this,K)[K]?f(this,K)[K]({start:function(){e.I(),f(e,K)[K]=void 0},startWithoutReset:function(){e.I()}}):u.adError&&!f(this,B)[B]&&this.I();break;case i.Type.VOLUME_CHANGED:var l=f(this,M)[M].getVolume();l>0&&(f(this,J)[J]=l)}},n.l=function(t){this.j(this.B(t))},n.u=function(t){var e=this,i=f(this,I)[I],n=i.AdEvent,r=i.AdErrorEvent.Type.AD_ERROR;window.clearTimeout(f(this,Y)[Y]);var s=f(this,M)[M]=t.getAdsManager(f(this,C)[C],f(this,k)[k]);Object.keys(n.Type).forEach(function(t){s.addEventListener(n.Type[t],function(i){if(e.S(i),P[t]){var n=["LOG","AD_PROGRESS"].indexOf(t)>-1;e.dispatchEvent(new A(P[t],{detail:{ad:i.getAd()||f(e,B)[B],adData:n?i.getAdData():{}}}))}})}),s.addEventListener(r,function(t){return e.j(e.B(t))});try{var o;s.init(f(this,j)[j],f(this,N)[N],this.k()),s.setVolume(f(this,D)[D].muted?0:f(this,D)[D].volume),null==(o=f(this,L)[L])||o.initialize(),f(this,K)[K]||this.M()}catch(a){this.j(new S(a.message))}},n.M=function(){if(f(this,G)[G]||(this.dispatchEvent(new A(P.MEDIA_START)),f(this,G)[G]=!0),f(this,M)[M])try{f(this,M)[M].start()}catch(t){this.j(new S(t.message))}else this.I()},n.T=function(){var t=this;setTimeout(function(){f(t,F)[F]=!1,f(t,G)[G]=!1,f(t,W)[W]=!1,t.dispatchEvent(new A(P.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 d(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)?d(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?(f(this,j)[j]=n.contentBoxSize[0].inlineSize,f(this,N)[N]=n.contentBoxSize[0].blockSize):n.contentBoxSize&&n.contentBoxSize.inlineSize?(f(this,j)[j]=n.contentBoxSize.inlineSize,f(this,N)[N]=n.contentBoxSize.blockSize):(f(this,j)[j]=n.contentRect.width,f(this,N)[N]=n.contentRect.height)}this.R()},n.R=function(){if(f(this,x)[x].autoResize&&f(this,M)[M]){var t=f(this,B)[B],e=this.k();t&&!t.isLinear()?t&&(t.getWidth()>f(this,j)[j]||t.getHeight()>f(this,N)[N]?this.resizeAd(f(this,j)[j],f(this,N)[N]):(f(this,M)[M].resize(t.getWidth(),t.getHeight()+20,e),f(this,_)[_].style.width=t.getWidth()+"px",f(this,_)[_].style.height=t.getHeight()+20+"px")):this.resizeAd(f(this,j)[j],f(this,N)[N])}},n.k=function(){return document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement||f(this,D)[D].webkitDisplayingFullscreen?f(this,I)[I].ViewMode.FULLSCREEN:f(this,I)[I].ViewMode.NORMAL},n.I=function(){var t=this;f(this,_)[_].style.display="none",f(this,D)[D].ended||(f(this,C)[C].enable(),f(this,Z)[Z]?(f(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(P.MEDIA_RESUMED))),f(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(P.AD_ERROR,{detail:{error:t}})),this.C(),f(this,K)[K]?f(this,K)[K]({start:function(){e.I(),f(e,K)[K]=void 0},startWithoutReset:function(){e.I()}}):this.I()},i(e,[{key:"volume",get:function(){return!f(this,C)[C].enabled&&f(this,M)[M]?f(this,M)[M].getVolume():f(this,D)[D].volume},set:function(t){!f(this,C)[C].enabled&&f(this,M)[M]&&f(this,M)[M].setVolume(t),f(this,D)[D].volume=t}},{key:"muted",get:function(){return!f(this,C)[C].enabled&&f(this,M)[M]?0===f(this,M)[M].getVolume():f(this,D)[D].muted},set:function(t){!f(this,C)[C].enabled&&f(this,M)[M]&&f(this,M)[M].setVolume(t?0:f(this,J)[J]),f(this,D)[D].muted=t}},{key:"currentTime",get:function(){return void 0!==f(this,q)[q]?f(this,q)[q]:f(this,D)[D].currentTime},set:function(t){f(this,C)[C].enabled&&(f(this,D)[D].currentTime=t)}},{key:"duration",get:function(){return void 0!==f(this,$)[$]?f(this,$)[$]:f(this,D)[D].duration}},{key:"cuePoints",get:function(){return[].concat(f(this,Q)[Q])}}]),e}(w);let it=0;function nt(t,e){const i=t.createElement("div");return i.id=`${e?"art-vast-":"art-"}${Date.now()}-${++it}`,t.setStyles(i,{position:"absolute",inset:"0",width:"100%",height:"100%",zIndex:"150",display:"none"}),e&&t.setStyles(i,{backgroundColor:"black",pointerEvents:"auto"}),i}function rt(i,n={}){const r=n.compatibility;if(void 0!==r&&"workspace-1.2"!==r)throw new TypeError("Unsupported VAST compatibility mode");const s="workspace-1.2"===r;return n=>{return r=null,o=null,a=function*(){let r,o=!1;const a=()=>o||n.isDestroy,u={name:"artplayerPluginVast",destroy:()=>null==r?void 0:r.destroy()};function l(){if(!o){o=!0;try{n.off("destroy",l)}finally{null==r||r.destroy()}}}if(a())return u;n.on("destroy",l);try{if(a())return u;const o=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)}();if(a())return u;const d=n.constructor.utils;return r=function(t,e,i,n,r){const{$video:s,$player:o}=t.template,a=new e.AdsRenderingSettings;r&&(a.restoreCustomPlaybackStateOnAdBreakComplete=!0,a.enablePreloading=!0);const u=new R;let l=null,d=!1,h=0;const c={art:t,playUrl:(t,e={})=>y("adTagUrl",t,e),playRes:(t,e={})=>y("adsResponse",t,e),init:v,ima:e,adsRenderingSettings:a,playerOptions:u,imaPlayer:null,id:null,$container:null,get container(){return(null==l?void 0:l.container)||null}};r&&Object.defineProperties(c,{imaPlayer:{get:()=>(null==l?void 0:l.player)||null},id:{get:()=>(null==l?void 0:l.container.id)||null},$container:{get:()=>(null==l?void 0:l.container)||null}});const f=t=>l===t&&!t.released&&!n();function p(t){l===t&&(l=null),t.released=!0,t.playing=!1;const e=t.player;t.player=null;const i=t.listeners.splice(0);let n,r=!1;const s=t=>{try{t()}catch(e){r?console.error("VAST cleanup error:",e):(r=!0,n=e)}};h++;try{if(e){for(const[t,n]of i)s(()=>e.removeEventListener(t,n));s(()=>e.destroy())}s(()=>{t.container.parentNode&&t.container.parentNode.removeChild(t.container)})}finally{h--}if(r)throw n}function v(){if(n()||h)return null;if(d)throw new Error("VAST initialization is already in progress");if(null==l?void 0:l.player)return l.player;let t;d=!0;try{if(t={container:nt(i,r),player:null,listeners:[],playing:!1,released:!1},l=t,!f(t))return p(t),null;if(o.appendChild(t.container),!f(t))return p(t),null;if(t.player=new et(e,s,t.container,a,u),!f(t))return p(t),null;const n=t,d=r?[["AdContentPauseRequested",!0],["AdContentResumeRequested",!1],["AdStarted",!0],["AdError",!1]]:[];for(const[e,i]of d){const r=t=>{f(n)&&("AdError"===e&&console.error("VAST Ad Error:",t.detail),n.playing=i,n.container.style.display=i?"block":"none")};if(t.listeners.push([e,r]),t.player.addEventListener(e,r),!f(t))return p(t),null}return r||Object.defineProperties(c,{imaPlayer:{value:t.player},id:{value:t.container.id},$container:{value:t.container}}),t.player}catch(v){if(t)try{p(t)}catch(y){console.error("VAST cleanup error:",y)}throw v}finally{d=!1}}function y(t,i,s){if(n()||r&&(null==l?void 0:l.playing))return;const o=v(),a=l;if(!o||!a)return;const u=function(t,e,i,n){const r=new t.AdsRequest;r[e]=i;const s=r;for(const o in n)s[o]=n[o];return r}(e,t,i,s);f(a)&&a.player===o&&o.playAds(u)}return{context:c,destroy:function(){l&&p(l)}}}(n,o,d,a,s),a()?(l(),u):(!s&&(r.context.init(),a())||"function"===typeof i&&(yield i(r.context)),u)}catch(d){try{l()}catch(h){console.error("VAST cleanup error:",h)}throw d}},new Promise((t,e)=>{var i=t=>{try{s(a.next(t))}catch(i){e(i)}},n=t=>{try{s(a.throw(t))}catch(i){e(i)}},s=e=>e.done?t(e.value):Promise.resolve(e.value).then(i,n);s((a=a.apply(r,o)).next())});var r,o,a}}return rt.default=rt,rt});
|