/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
import{inherits as e,createSuper as t,classCallCheck as i,createClass as a,defineProperty as r,get as n,getPrototypeOf as d}from"./_virtual/_rollupPluginBabelHelpers.js";import o from"../../../_virtual/index.js";import s from"./utils/util.js";import u from"./utils/sniffer.js";import l,{ERROR_TYPE_MAP as c}from"./error.js";import{VIDEO_EVENTS as m,SOURCE_SUCCESS as h,SOURCE_ERROR as f,URL_CHANGE as v,WAITING as y}from"./events.js";function p(e,t){this&&this.emit&&("error"===e?this.errorHandler(e,t.error):this.emit(e,t))}var g=/* @__PURE__ */function(){e(_,o);var g=t(_);function _(e){var t;i(this,_),(t=g.call(this,e))._hasStart=!1,t._currentTime=0,t._duration=0,t._internalOp={},t._lastMuted=!1,t.vtype="MP4",t._rate=-1,t.mediaConfig=Object.assign({},{controls:!1,autoplay:e.autoplay,playsinline:e.playsinline,"x5-playsinline":e.playsinline,"webkit-playsinline":e.playsinline,"x5-video-player-fullscreen":e["x5-video-player-fullscreen"]||e.x5VideoPlayerFullscreen,"x5-video-orientation":e["x5-video-orientation"]||e.x5VideoOrientation,airplay:e.airplay,"webkit-airplay":e.airplay,tabindex:0|e.tabindex,mediaType:e.mediaType||"video","data-index":-1},e.videoConfig,e.videoAttributes);var a=e["x5-video-player-type"]||e.x5VideoPlayerType;return u.isWeixin&&u.os.isAndroid&&a&&(t.mediaConfig["x5-video-player-type"]=a,delete t.mediaConfig.playsinline,delete t.mediaConfig["webkit-playsinline"],delete t.mediaConfig["x5-playsinline"]),e.loop&&(t.mediaConfig.loop="loop"),e.autoplayMuted&&!Object.prototype.hasOwnProperty.call(t.mediaConfig,"muted")&&(t.mediaConfig.muted=!0),t.media=e.mediaEl instanceof HTMLMediaElement?e.mediaEl:"function"==typeof e.mediaEl?e.mediaEl(t.mediaConfig):s.createDom(t.mediaConfig.mediaType,"",t.mediaConfig,""),e.defaultPlaybackRate&&(t.media.defaultPlaybackRate=t.media.playbackRate=e.defaultPlaybackRate),"Number"===s.typeOf(e.volume)&&(t.volume=e.volume),e.autoplayMuted&&(t.media.muted=!0,t._lastMuted=!0),e.autoplay&&(t.media.autoplay=!0),e.playsinline&&(t.media.playsinline=!0),t._interval={},t.mediaEventMiddleware={},t.attachVideoEvents(),t}return a(_,[{key:"setEventsMiddleware",value:function(e){var t=this;Object.keys(e).map(function(i){t.mediaEventMiddleware[i]=e[i]})}},{key:"removeEventsMiddleware",value:function(e){var t=this;Object.keys(e).map(function(e){delete t.mediaEventMiddleware[e]})}},{key:"attachVideoEvents",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.media;this._evHandlers||(this._evHandlers=m.map(function(t){var i="on".concat(t.charAt(0).toUpperCase()).concat(t.slice(1));return"function"==typeof e[i]&&e.on(t,e[i]),r({},t,function(e,t){return function(i,a){var r={player:t,eventName:e,originalEvent:i,detail:i.detail||{},timeStamp:i.timeStamp,currentTime:t.currentTime,duration:t.duration,paused:t.paused,ended:t.ended,isInternalOp:!!t._internalOp[i.type],muted:t.muted,volume:t.volume,host:s.getHostFromUrl(t.currentSrc),vtype:t.vtype};if(t.removeInnerOP(i.type),"timeupdate"===e&&(t._currentTime=t.media&&t.media.currentTime),"ratechange"===e){var n=t.media?t.media.playbackRate:0;if(n&&t._rate===n)return;t._rate=t.media&&t.media.playbackRate}if("durationchange"===e&&(t._duration=t.media.duration),"volumechange"===e&&(r.isMutedChange=t._lastMuted!==t.muted,t._lastMuted=t.muted),"error"===e&&(r.error=a||t.video.error),t.mediaEventMiddleware[e]){var d=p.bind(t,e,r);try{t.mediaEventMiddleware[e].call(t,r,d)}catch(o){throw p.call(t,e,r),o}}else p.call(t,e,r)}}(t,e))})),this._evHandlers.forEach(function(e){var i=Object.keys(e)[0];t.addEventListener(i,e[i],!1)})}},{key:"detachVideoEvents",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.media;this._evHandlers.forEach(function(e){var i=Object.keys(e)[0];t.removeEventListener(i,e[i],!1)}),this._evHandlers.forEach(function(t){var i=Object.keys(t)[0],a="on".concat(i.charAt(0).toUpperCase()).concat(i.slice(1));"function"==typeof e[a]&&e.off(i,e[a])}),this._evHandlers=null}},{key:"_attachSourceEvents",value:function(e,t){var i=this;e.removeAttribute("src"),e.load(),t.forEach(function(e,t){i.media.appendChild(s.createDom("source","",{src:"".concat(e.src),type:"".concat(e.type||""),"data-index":t+1}))});var a=e.children;if(a){this._videoSourceCount=a.length,this._videoSourceIndex=a.length,this._vLoadeddata=function(e){i.emit(h,{src:e.target.currentSrc,host:s.getHostFromUrl(e.target.currentSrc)})};for(var r=null,n=0;n<this._evHandlers.length;n++)if("error"===Object.keys(this._evHandlers[n])[0]){r=this._evHandlers[n];break}!this._sourceError&&(this._sourceError=function(e){var t=parseInt(e.target.getAttribute("data-index"),10);if(i._videoSourceIndex--,0===i._videoSourceIndex||t>=i._videoSourceCount){var a={code:4,message:"sources_load_error"};r?r.error(e,a):i.errorHandler("error",a)}var n=c[4];i.emit(f,new l(i,{errorType:n,errorCode:4,errorMessage:"sources_load_error",mediaError:{code:4,message:"sources_load_error"},src:e.target.src}))});for(var d=0;d<a.length;d++)a[d].addEventListener("error",this._sourceError);e.addEventListener("loadeddata",this._vLoadeddata)}}},{key:"_detachSourceEvents",value:function(e){var t=e.children;if(t&&0!==t.length&&this._sourceError){for(var i=0;i<t.length;i++)t[i].removeEventListener("error",this._sourceError);for(;t.length>0;)e.removeChild(t[0]);this._vLoadeddata&&e.removeEventListener("loadeddata",this._vLoadeddata)}}},{key:"errorHandler",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(this.media&&(this.media.error||t)){var i=this.media.error||t,a=i.code?c[i.code]:"other";i.message;this.media.currentSrc||this.media.srcObject||(i={code:6,message:"empty_src"}),this.emit(e,new l(this,{errorType:a,errorCode:i.code,errorMessage:i.message||"",mediaError:i}))}}},{key:"destroy",value:function(){for(var e in this.media&&(this.media.pause&&(this.media.pause(),this.media.muted=!0),this.media.removeAttribute("src"),this.media.load()),this._currentTime=0,this._duration=0,this.mediaConfig=null,this._interval)Object.prototype.hasOwnProperty.call(this._interval,e)&&(clearInterval(this._interval[e]),this._interval[e]=null);this.detachVideoEvents(),this.media=null,this.mediaEventMiddleware={},this.removeAllListeners()}},{key:"video",get:function(){return this.media},set:function(e){this.media=e}},{key:"play",value:function(){return this.media?this.media.play():null}},{key:"pause",value:function(){this.media&&this.media.pause()}},{key:"load",value:function(){this.media&&this.media.load()}},{key:"canPlayType",value:function(e){return!!this.media&&this.media.canPlayType(e)}},{key:"getBufferedRange",value:function(e){var t=[0,0];if(!this.media)return t;e||(e=this.media.buffered);var i=this.media.currentTime;if(e)for(var a=0,r=e.length;a<r&&(t[0]=e.start(a),t[1]=e.end(a),!(t[0]<=i&&i<=t[1]));a++);return t[0]-i<=0&&i-t[1]<=0?t:[0,0]}},{key:"autoplay",get:function(){return!!this.media&&this.media.autoplay},set:function(e){this.media&&(this.media.autoplay=e)}},{key:"buffered",get:function(){return this.media?this.media.buffered:null}},{key:"buffered2",get:function(){return this.media&&this.media.buffered?s.getBuffered2(this.media.buffered):null}},{key:"bufferedPoint",get:function(){var e={start:0,end:0};if(!this.media)return e;var t=this.media.buffered;if(!t||0===t.length)return e;for(var i=0;i<t.length;i++)if((t.start(i)<=this.currentTime||t.start(i)<.1)&&t.end(i)>=this.currentTime)return{start:t.start(i),end:t.end(i)};return e}},{key:"crossOrigin",get:function(){return this.media?this.media.crossOrigin:""},set:function(e){this.media&&(this.media.crossOrigin=e)}},{key:"currentSrc",get:function(){return this.media?this.media.currentSrc:""},set:function(e){this.media&&(this.media.currentSrc=e)}},{key:"currentTime",get:function(){return this.media?void 0!==this.media.currentTime?this.media.currentTime:this._currentTime:0},set:function(e){this.media&&(this.media.currentTime=e)}},{key:"defaultMuted",get:function(){return!!this.media&&this.media.defaultMuted},set:function(e){this.media&&(this.media.defaultMuted=e)}},{key:"duration",get:function(){return this._duration}},{key:"ended",get:function(){return!!this.media&&this.media.ended}},{key:"error",get:function(){return this.media.error}},{key:"errorNote",get:function(){if(!this.media.error)return"";return["MEDIA_ERR_ABORTED","MEDIA_ERR_NETWORK","MEDIA_ERR_DECODE","MEDIA_ERR_SRC_NOT_SUPPORTED"][this.media.error.code-1]}},{key:"loop",get:function(){return!!this.media&&this.media.loop},set:function(e){this.media&&(this.media.loop=e)}},{key:"muted",get:function(){return!!this.media&&this.media.muted},set:function(e){this.media&&this.media.muted!==e&&(this._lastMuted=this.media.muted,this.media.muted=e)}},{key:"networkState",get:function(){return this.media.networkState}},{key:"paused",get:function(){return!this.media||this.media.paused}},{key:"playbackRate",get:function(){return this.media?this.media.playbackRate:0},set:function(e){this.media&&e!==1/0&&(this.media.defaultPlaybackRate=e,this.media.playbackRate=e)}},{key:"played",get:function(){return this.media?this.media.played:null}},{key:"preload",get:function(){return!!this.media&&this.media.preload},set:function(e){this.media&&(this.media.preload=e)}},{key:"readyState",get:function(){return this.media.readyState}},{key:"seekable",get:function(){return!!this.media&&this.media.seekable}},{key:"seeking",get:function(){return!!this.media&&this.media.seeking}},{key:"src",get:function(){return this.media?this.media.src:""},set:function(e){this.media&&(this.emit(v,e),this.emit(y),this._currentTime=0,this._duration=0,s.isMSE(this.media)?this.onWaiting():(this._detachSourceEvents(this.media),"Array"===s.typeOf(e)?this._attachSourceEvents(this.media,e):e?this.media.src=e:this.media.removeAttribute("src"),this.load()))}},{key:"volume",get:function(){return this.media?this.media.volume:0},set:function(e){e!==1/0&&this.media&&(this.media.volume=e)}},{key:"aspectRatio",get:function(){return this.media?this.media.videoWidth/this.media.videoHeight:0}},{key:"addInnerOP",value:function(e){this._internalOp[e]=!0}},{key:"removeInnerOP",value:function(e){delete this._internalOp[e]}},{key:"emit",value:function(e,t){for(var i,a=arguments.length,r=new Array(a>2?a-2:0),o=2;o<a;o++)r[o-2]=arguments[o];(i=n(d(_.prototype),"emit",this)).call.apply(i,[this,e,t].concat(r))}},{key:"on",value:function(e,t){for(var i,a=arguments.length,r=new Array(a>2?a-2:0),o=2;o<a;o++)r[o-2]=arguments[o];(i=n(d(_.prototype),"on",this)).call.apply(i,[this,e,t].concat(r))}},{key:"once",value:function(e,t){for(var i,a=arguments.length,r=new Array(a>2?a-2:0),o=2;o<a;o++)r[o-2]=arguments[o];(i=n(d(_.prototype),"once",this)).call.apply(i,[this,e,t].concat(r))}},{key:"off",value:function(e,t){for(var i,a=arguments.length,r=new Array(a>2?a-2:0),o=2;o<a;o++)r[o-2]=arguments[o];(i=n(d(_.prototype),"off",this)).call.apply(i,[this,e,t].concat(r))}},{key:"offAll",value:function(){n(d(_.prototype),"removeAllListeners",this).call(this)}}]),_}();export{g as default};