/*!
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{defineProperty as e,inherits as t,createSuper as i,classCallCheck as s,assertThisInitialized as n,possibleConstructorReturn as o,createClass as r,get as a,getPrototypeOf as l,objectSpread2 as u}from"./_virtual/_rollupPluginBabelHelpers.js";import c from"./mediaProxy.js";import h,{checkIsCurrentVideo as f}from"./utils/util.js";import d from"./utils/sniffer.js";import g from"./utils/database.js";import v from"./error.js";import{CANPLAY as p,USER_ACTION as m,FULLSCREEN_CHANGE as y,READY as _,ERROR as k,LOADED_DATA as E,PLAY as T,URL_NULL as C,COMPLETE as S,AUTOPLAY_STARTED as P,AUTOPLAY_PREVENTED as A,SEEKED as N,DEFINITION_CHANGE as R,AFTER_DEFINITION_CHANGE as F,RESET as b,DESTROY as I,REPLAY as L,CSS_FULLSCREEN_CHANGE as O,PLAYER_FOCUS as w,PLAYER_BLUR as D,DURATION_CHANGE as x,LOADING as U,PLAYNEXT as B,VIDEO_RESIZE as j}from"./events.js";import*as H from"./events.js";import{PLATER_ID as W,FULLSCREEN_EVENTS as G,GET_FULLSCREEN_API as z,EXIT_FULLSCREEN_API as M}from"./constant.js";import{POSITIONS as V}from"./plugin/plugin.js";import{default as Y}from"./plugin/plugin.js";import K from"./plugin/basePlugin.js";import q from"./plugin/pluginsManager.js";import Q from"./stateClassMap.js";import X from"./defaultConfig.js";import{usePreset as J}from"./plugin/preset.js";import Z,{runHooks as $,delHooksDescriptor as ee,hook as te,useHooks as ie,removeHooks as se,usePluginHooks as ne,removePluginHooks as oe}from"./plugin/hooksDescriptor.js";import re from"./plugins/controls/index.js";import ae,{bindDebug as le}from"./utils/debug.js";import ue from"./lang/i18n.js";import ce from"./version.js";import{STATES as he,STATE_ARRAY as fe}from"./state.js";import{InstManager as de,checkPlayerRoot as ge}from"./instManager.js";var ve=["play","pause","replay","retry"],pe=0,me=0,ye=null,_e=/* @__PURE__ */function(){t(Y,c);var H=i(Y);function Y(t){var i;s(this,Y);var r=h.deepMerge(X(),t);i=H.call(this,r),e(n(i),"canPlayFunc",function(){if(i.config){var e=i.config,t=e.autoplay,s=e.defaultPlaybackRate;ae.logInfo("player","canPlayFunc, startTime",i.__startTime),i._seekToStartTime(),i.playbackRate=s,(t||i._useAutoplay)&&i.mediaPlay(),i.off(p,i.canPlayFunc),i.removeClass(Q.ENTER)}}),e(n(i),"onFullscreenChange",function(e,t){var s=function(){h.setTimeout(n(i),function(){i.resize()},100)},o=h.getFullScreenEl();i._fullActionFrom?i._fullActionFrom="":i.emit(m,{eventType:"system",action:"switch_fullscreen",pluginName:"player",currentTime:i.currentTime,duration:i.duration,props:[{prop:"fullscreen",from:!0,to:!1}]});var r=f(o,i.playerId,W);if(t||o&&(o===i._fullscreenEl||r))s(),!i.config.closeFocusVideoFocus&&i.media.focus(),i.fullscreen=!0,i.changeFullStyle(i.root,o,Q.FULLSCREEN),i.emit(y,!0,i._fullScreenOffset),i.cssfullscreen&&i.exitCssFullscreen();else if(i.fullscreen){s();var a=n(i),l=a._fullScreenOffset;if(a.config.needFullscreenScroll?(window.scrollTo(l.left,l.top),h.setTimeout(n(i),function(){i.fullscreen=!1,i._fullScreenOffset=null},100)):(!i.config.closeFocusVideoFocus&&i.media.focus(),i.fullscreen=!1,i._fullScreenOffset=null),i.cssfullscreen)i.removeClass(Q.FULLSCREEN);else{var u=i._fullscreenEl;u||!i.root.contains(e.target)&&e.target!==i.root||(u=e.target),i.recoverFullStyle(i.root,u,Q.FULLSCREEN)}i._fullscreenEl=null,i.emit(y,!1)}}),e(n(i),"_onWebkitbeginfullscreen",function(e){i._fullscreenEl=i.media,i.onFullscreenChange(e,!0)}),e(n(i),"_onWebkitendfullscreen",function(e){i.onFullscreenChange(e,!1)}),Z(n(i),ve),i.config=r,i._pluginInfoId=h.generateSessionId(),le(n(i));var a=i.constructor.defaultPreset;if(i.config.presets.length){var l=i.config.presets.indexOf("default");l>=0&&a&&(i.config.presets[l]=a)}else a&&i.config.presets.push(a);if(i.userTimer=null,i.waitTimer=null,i.handleSource=!0,i._state=he.INITIAL,i.isAd=!1,i.isError=!1,i._hasStart=!1,i.isSeeking=!1,i.isCanplay=!1,i._useAutoplay=!1,i.__startTime=-1,i.rotateDeg=0,i.isActive=!1,i.fullscreen=!1,i.cssfullscreen=!1,i.isRotateFullscreen=!1,i._fullscreenEl=null,i.timeSegments=[],i._cssfullscreenEl=null,i.curDefinition=null,i._orgCss="",i._fullScreenOffset=null,i._videoHeight=0,i._videoWidth=0,i.videoPos={pi:1,scale:0,rotate:-1,x:0,y:0,h:-1,w:-1,vy:0,vx:0},i.sizeInfo={width:0,height:0,left:0,top:0},i._accPlayed={t:0,acc:0,loopAcc:0},i._offsetInfo={currentTime:-1,duration:0},i.innerContainer=null,i.controls=null,i.topBar=null,i.root=null,i.__i18n=ue.init(i._pluginInfoId),d.os.isAndroid&&d.osVersion>0&&d.osVersion<6&&(i.config.autoplay=!1),i.database=new g,i.isUserActive=!1,i._onceSeekCanplay=null,i._isPauseBeforeSeek=0,i.innerStates={isActiveLocked:!1},i.instManager=ye,!i._initDOM())return console.error(new Error("can't find the dom which id is ".concat(i.config.id," or this.config.el does not exist"))),o(i);var u=i.config,c=u.definition,v=void 0===c?{}:c;if(!u.url&&v.list&&v.list.length>0){var k=v.list.find(function(e){return e.definition&&e.definition===v.defaultDefinition});k||(v.defaultDefinition=v.list[0].definition,k=v.list[0]),i.config.url=k.url,i.curDefinition=k}return i._bindEvents(),i._registerPresets(),i._registerPlugins(),q.onPluginsReady(n(i)),i.getInitDefinition(),i.setState(he.READY),h.setTimeout(n(i),function(){i.emit(_)},0),i.onReady&&i.onReady(),(i.config.videoInit||i.config.autoplay)&&(!i.hasStart||i.state<he.ATTACHED)&&i.start(),i}return r(Y,[{key:"_initDOM",value:function(){var e,t=this;if(this.root=this.config.id?document.getElementById(this.config.id):null,!this.root){var i=this.config.el;if(!i||1!==i.nodeType)return this.emit(k,new v("use",this.config.vid,{line:32,handle:"Constructor",msg:"container id can't be empty"})),console.error("this.confg.id or this.config.el can't be empty"),!1;this.root=i}var s=ge(this.root);if(s&&(ae.logWarn("The is an Player instance already exists in this.root, destroy it and reinitialize"),s.destroy()),this.root.setAttribute(W,this.playerId),this.media.setAttribute(W,this.playerId),null===(e=ye)||void 0===e||e.add(this),q.init(this),this._initBaseDoms(),this.config.controls){var n=this.config.controls.root||null,o=q.register(this,re,{root:n});this.controls=o}var r="mobile"===this.config.isMobileSimulateMode?"mobile":d.device;if(this.addClass("".concat(Q.DEFAULT," ").concat(Q.INACTIVE," xgplayer-").concat(r," ").concat(this.config.controls?"":Q.NO_CONTROLS)),this.config.autoplay?this.addClass(Q.ENTER):this.addClass(Q.NO_START),this.config.fluid){var a=this.config,l=a.width,u=a.height;"number"==typeof l&&"number"==typeof u||(l=600,u=337.5);var c={width:"100%",height:"0","max-width":"100%","padding-top":"".concat(100*u/l,"%")};Object.keys(c).forEach(function(e){t.root.style[e]=c[e]})}else["width","height"].forEach(function(e){t.config[e]&&("number"!=typeof t.config[e]?t.root.style[e]=t.config[e]:t.root.style[e]="".concat(t.config[e],"px"))});var h=this.root.getBoundingClientRect(),f=h.width,g=h.height,p=h.left,m=h.top;return this.sizeInfo.width=f,this.sizeInfo.height=g,this.sizeInfo.left=p,this.sizeInfo.top=m,!0}},{key:"_initBaseDoms",value:function(){this.topBar=null,this.leftBar=null,this.rightBar=null,this.config.marginControls&&(this.innerContainer=h.createDom("xg-video-container","",{"data-index":-1},"xg-video-container"),this.root.appendChild(this.innerContainer))}},{key:"_bindEvents",value:function(){var e=this;["focus","blur"].forEach(function(t){e.on(t,e["on"+t.charAt(0).toUpperCase()+t.slice(1)])}),G.forEach(function(t){document&&document.addEventListener(t,e.onFullscreenChange)}),d.os.isIos&&(this.media.addEventListener("webkitbeginfullscreen",this._onWebkitbeginfullscreen),this.media.addEventListener("webkitendfullscreen",this._onWebkitendfullscreen)),this.once(E,this.resize),this.playFunc=function(){e.config.closeFocusVideoFocus||e.media.focus()},this.once(T,this.playFunc)}},{key:"_unbindEvents",value:function(){var e=this;this.root.removeEventListener("mousemove",this.mousemoveFunc),G.forEach(function(t){document.removeEventListener(t,e.onFullscreenChange)}),this.playFunc&&this.off(T,this.playFunc),this.off(p,this.canPlayFunc),this.media.removeEventListener("webkitbeginfullscreen",this._onWebkitbeginfullscreen),this.media.removeEventListener("webkitendfullscreen",this._onWebkitendfullscreen)}},{key:"_clearUserTimer",value:function(){this.userTimer&&(h.clearTimeout(this,this.userTimer),this.userTimer=null)}},{key:"_startInit",value:function(e){var t=this,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.media&&(e&&""!==e&&("Array"!==h.typeOf(e)||0!==e.length)||(e="",this.emit(C),ae.logWarn("config.url is null, please get url and run player._startInit(url)"),!this.config.nullUrlStart))){h.isNotNull(i.playSessionId)&&(this._playSessionId=i.playSessionId),this.handleSource&&(this._detachSourceEvents(this.media),"Array"===h.typeOf(e)&&e.length>0?this._attachSourceEvents(this.media,e):this.media.src&&this.media.src===e?e||this.media.removeAttribute("src"):this.media.src=e),"Number"===h.typeOf(this.config.volume)&&(this.volume=this.config.volume);var s=this.innerContainer?this.innerContainer:this.root;this.media instanceof window.Element&&!s.contains(this.media)&&s.insertBefore(this.media,s.firstChild);var n=this.media.readyState;ae.logInfo("_startInit readyState",n),this.config.autoplay&&(!h.isMSE(this.media)&&this.load(),(d.os.isIpad||d.os.isPhone)&&this.mediaPlay());var o=this.config.startTime;this.__startTime=o>0?o:-1,this.config.startTime=0,n>=2&&this.duration>0?this.canPlayFunc():this.on(p,this.canPlayFunc),(!this.hasStart||this.state<he.ATTACHED)&&q.afterInit(this),this.hasStart=!0,this.setState(he.ATTACHED),h.setTimeout(this,function(){t.emit(S)},0)}}},{key:"_registerPlugins",value:function(){var e=this,t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this._loadingPlugins=[];var i=this.config.ignores||[],s=this.config.plugins||[],n=this.config.i18n||[];t&&ue.extend(n,this.__i18n);var o=i.join("||").toLowerCase().split("||"),r=this.plugins;s.forEach(function(i){try{var s=i.plugin?i.plugin.pluginName:i.pluginName;if(s&&o.indexOf(s.toLowerCase())>-1)return null;if(!t&&r[s.toLowerCase()])return;if(i.lazy&&i.loader){var n=q.lazyRegister(e,i);return void(i.forceBeforeInit&&(n.then(function(){e._loadingPlugins.splice(e._loadingPlugins.indexOf(n),1)}).catch(function(t){ae.logError("_registerPlugins:loadingPlugin",t),e._loadingPlugins.splice(e._loadingPlugins.indexOf(n),1)}),e._loadingPlugins.push(n)))}return e.registerPlugin(i)}catch(a){ae.logError("_registerPlugins:",a)}})}},{key:"_registerPresets",value:function(){var e=this;this.config.presets.forEach(function(t){J(e,t)})}},{key:"_getRootByPosition",value:function(e){var t=null;switch(e){case V.ROOT_RIGHT:this.rightBar||(this.rightBar=h.createPositionBar("xg-right-bar",this.root)),t=this.rightBar;break;case V.ROOT_LEFT:this.leftBar||(this.leftBar=h.createPositionBar("xg-left-bar",this.root)),t=this.leftBar;break;case V.ROOT_TOP:this.topBar||(this.topBar=h.createPositionBar("xg-top-bar",this.root),this.config.topBarAutoHide&&h.addClass(this.topBar,Q.TOP_BAR_AUTOHIDE)),t=this.topBar;break;default:t=this.innerContainer||this.root}return t}},{key:"registerPlugin",value:function(e,t){var i=q.formatPluginInfo(e,t),s=i.PLUFGIN,n=i.options,o=this.config.plugins;!q.checkPluginIfExits(s.pluginName,o)&&o.push(s);var r=q.getRootByConfig(s.pluginName,this.config);r.root&&(n.root=r.root),r.position&&(n.position=r.position);var a,l=n.position?n.position:n.config&&n.config.position||s.defaultConfig&&s.defaultConfig.position;return!n.root&&"string"==typeof l&&l.indexOf("controls")>-1?null===(a=this.controls)||void 0===a?void 0:a.registerPlugin(s,n,s.pluginName):(n.root||(n.root=this._getRootByPosition(l)),q.register(this,s,n))}},{key:"deregister",value:function(e){"string"==typeof e?q.unRegister(this,e):e instanceof K&&q.unRegister(this,e.pluginName)}},{key:"unRegisterPlugin",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.deregister(e),t&&this.removePluginFromConfig(e)}},{key:"removePluginFromConfig",value:function(e){var t;if("string"==typeof e?t=e:e instanceof K&&(t=e.pluginName),t)for(var i=this.config.plugins.length-1;i>-1;i--){if(this.config.plugins[i].pluginName.toLowerCase()===t.toLowerCase()){this.config.plugins.splice(i,1);break}}}},{key:"plugins",get:function(){return q.getPlugins(this)}},{key:"getPlugin",value:function(e){var t=q.findPlugin(this,e);return t&&t.pluginName?t:null}},{key:"addClass",value:function(e){this.root&&(h.hasClass(this.root,e)||h.addClass(this.root,e))}},{key:"removeClass",value:function(e){this.root&&h.removeClass(this.root,e)}},{key:"hasClass",value:function(e){if(this.root)return h.hasClass(this.root,e)}},{key:"setAttribute",value:function(e,t){this.root&&this.root.setAttribute(e,t)}},{key:"removeAttribute",value:function(e,t){this.root&&this.root.removeAttribute(e,t)}},{key:"start",value:function(e){var t=this;if(!(this.state>he.ATTACHING)){var i=this._playSessionId;return h.isNotNull(i)&&(this._playSessionId=void 0),e||this.config.url||this.getInitDefinition(),this.hasStart=!0,this.setState(he.ATTACHING),this._registerPlugins(!1),q.beforeInit(this).then(function(){if(t.config){e||(e=t.url||t.config.url);var s=t.preProcessUrl(e);return t._startInit(s.url,{playSessionId:i})}}).catch(function(e){throw e.fileName="player",e.lineNumber="236",ae.logError("start:beforeInit:",e),e})}}},{key:"switchURL",value:function(e,t){var i=this,s=e;"Object"===h.typeOf(e)&&(s=e.url),s=this.preProcessUrl(s).url;var n=this.currentTime;this.__startTime=n;var o=this.paused&&!this.isError;return this.src=s,new Promise(function(e,t){var n=function(e){i.off("timeupdate",r),i.off("canplay",r),t(e)},r=function(){i._seekToStartTime(),o&&i.pause(),i.off("error",n),e(!0)};i.once("error",n),s?(d.os.isAndroid?i.once("timeupdate",r):i.once("canplay",r),i.play()):i.errorHandler("error",{code:6,message:"empty_src"})})}},{key:"videoPlay",value:function(){this.mediaPlay()}},{key:"mediaPlay",value:function(){var e=this;if(!this.hasStart&&this.state<he.ATTACHED)return this.removeClass(Q.NO_START),this.addClass(Q.ENTER),this.start(),void(this._useAutoplay=!0);this.state<he.RUNNING&&(this.removeClass(Q.NO_START),!this.isCanplay&&this.addClass(Q.ENTER));var t=a(l(Y.prototype),"play",this).call(this);return void 0!==t&&t&&t.then?t.then(function(){e.removeClass(Q.NOT_ALLOW_AUTOPLAY),e.addClass(Q.PLAYING),e.state<he.RUNNING&&(ae.logInfo(">>>>playPromise.then"),e.setState(he.RUNNING),e.emit(P))}).catch(function(t){if(ae.logWarn(">>>>playPromise.catch",t.name),e.media&&e.media.error)return e.onError(),void e.removeClass(Q.ENTER);"NotAllowedError"===t.name&&(e._errorTimer=h.setTimeout(e,function(){e._errorTimer=null,e.emit(A),e.addClass(Q.NOT_ALLOW_AUTOPLAY),e.removeClass(Q.ENTER),e.pause(),e.setState(he.NOTALLOW)},0))}):(ae.logWarn("video.play not return promise"),this.state<he.RUNNING&&(this.setState(he.RUNNING),this.removeClass(Q.NOT_ALLOW_AUTOPLAY),this.removeClass(Q.NO_START),this.removeClass(Q.ENTER),this.addClass(Q.PLAYING),this.emit(P))),t}},{key:"mediaPause",value:function(){a(l(Y.prototype),"pause",this).call(this)}},{key:"videoPause",value:function(){a(l(Y.prototype),"pause",this).call(this)}},{key:"play",value:function(){var e=this;return this.removeClass(Q.PAUSED),$(this,"play",function(){return e.mediaPlay()})}},{key:"pause",value:function(){var e=this;$(this,"pause",function(){a(l(Y.prototype),"pause",e).call(e)})}},{key:"seek",value:function(e,t){var i=this;if(this.media&&!Number.isNaN(Number(e))&&this.hasStart){var s=this.config,n=s.isSeekedPlay,o=s.seekedStatus,r=t||(n?"play":o);e=e<0?0:e>this.duration?parseInt(this.duration,10):e,!this._isPauseBeforeSeek&&(this._isPauseBeforeSeek=this.paused?2:1),this._onceSeekCanplay&&this.off(N,this._onceSeekCanplay),this._onceSeekCanplay=function(){switch(i.removeClass(Q.ENTER),i.isSeeking=!1,r){case"play":i.play();break;case"pause":i.pause();break;default:i._isPauseBeforeSeek>1||i.paused?i.pause():i.play()}i._isPauseBeforeSeek=0,i._onceSeekCanplay=null},this.once(N,this._onceSeekCanplay),this.state<he.RUNNING?(this.removeClass(Q.NO_START),this.currentTime=e,this.play()):this.currentTime=e}}},{key:"getInitDefinition",value:function(){var e=this,t=this.config,i=t.definition;!t.url&&i&&i.list&&i.list.length>0&&i.defaultDefinition&&i.list.map(function(t){t.definition===i.defaultDefinition&&(e.config.url=t.url,e.curDefinition=t)})}},{key:"changeDefinition",value:function(e,t){var i=this,s=this.config.definition;if(Array.isArray(null==s?void 0:s.list)&&s.list.forEach(function(t){(null==e?void 0:e.definition)===t.definition&&(i.curDefinition=t)}),null!=e&&e.bitrate&&"number"!=typeof e.bitrate&&(e.bitrate=parseInt(e.bitrate,10)||0),this.emit(R,{from:t,to:e}),this.hasStart){var n=this.switchURL(e.url,u({seamless:!1!==s.seamless&&"undefined"!=typeof MediaSource&&"function"==typeof MediaSource.isTypeSupported},e));n&&n.then?n.then(function(){i.emit(F,{from:t,to:e})}):this.emit(F,{from:t,to:e})}else this.config.url=e.url}},{key:"reload",value:function(){this.load(),this.reloadFunc=function(){this.play()},this.once(E,this.reloadFunc)}},{key:"resetState",value:function(){var e=this,t=[Q.NOT_ALLOW_AUTOPLAY,Q.PLAYING,Q.NO_START,Q.PAUSED,Q.REPLAY,Q.ENTER,Q.ENDED,Q.ERROR,Q.LOADING];this.hasStart=!1,this.isError=!1,this._useAutoplay=!1,this.mediaPause(),this._accPlayed.acc=0,this._accPlayed.t=0,this._accPlayed.loopAcc=0,t.forEach(function(t){e.removeClass(t)}),this.addClass(Q.NO_START),this.emit(b)}},{key:"reset",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],i=arguments.length>1?arguments[1]:void 0;if(this.resetState(),this.plugins&&(t.map(function(t){e.deregister(t)}),i)){var s=X();Object.keys(this.config).forEach(function(t){"undefined"===e.config[t]||"plugins"!==t&&"presets"!==t&&"el"!==t&&"id"!==t||(e.config[t]=s[t])})}}},{key:"destroy",value:function(){var e,t=this,i=this.innerContainer,s=this.root,n=this.media;if(s&&n){if(this.hasStart=!1,this._useAutoplay=!1,s.removeAttribute(W),n.removeAttribute(W),this.updateAcc("destroy"),this._unbindEvents(),this._detachSourceEvents(this.media),h.clearAllTimers(this),this.emit(I),null===(e=ye)||void 0===e||e.remove(this),q.destroy(this),ee(this),a(l(Y.prototype),"destroy",this).call(this),this.fullscreen&&this._fullscreenEl===this.root&&this.exitFullscreen(),i)for(var o=i.children,r=0;r<o.length;r++)i.removeChild(o[r]);!i&&n instanceof window.Node&&s.contains(n)&&!this.config.remainMediaAfterDestroy&&s.removeChild(n),["topBar","leftBar","rightBar","innerContainer"].map(function(e){t[e]&&s.removeChild(t[e]),t[e]=null});var u=s.className.split(" ");u.length>0?s.className=u.filter(function(e){return e.indexOf("xgplayer")<0}).join(" "):s.className="",this.removeAttribute("data-xgfill"),["isSeeking","isCanplay","isActive","cssfullscreen","fullscreen"].forEach(function(e){t[e]=!1})}}},{key:"replay",value:function(){var e=this;this.removeClass(Q.ENDED),this.currentTime=0,this.isSeeking=!1,$(this,"replay",function(){e.once(N,function(){var t=e.mediaPlay();t&&t.catch&&t.catch(function(e){console.log(e)})}),e.emit(L),e.onPlay()})}},{key:"retry",value:function(){var e=this;this.removeClass(Q.ERROR),this.addClass(Q.LOADING),$(this,"retry",function(){var t=e.currentTime,i=e.config.url,s=h.isMSE(e.media)?{url:i}:e.preProcessUrl(i);e.src=s.url,!e.config.isLive&&(e.currentTime=t),e.once(p,function(){e.mediaPlay()})})}},{key:"changeFullStyle",value:function(e,t,i,s){e&&(s||(s=Q.PARENT_FULLSCREEN),this._orgCss||(this._orgCss=h.filterStyleFromText(e)),h.addClass(e,i),t&&t!==e&&!this._orgPCss&&(this._orgPCss=h.filterStyleFromText(t),h.addClass(t,s),t.setAttribute(W,this.playerId)))}},{key:"recoverFullStyle",value:function(e,t,i,s){s||(s=Q.PARENT_FULLSCREEN),this._orgCss&&(h.setStyleFromCsstext(e,this._orgCss),this._orgCss=""),h.removeClass(e,i),t&&t!==e&&this._orgPCss&&(h.setStyleFromCsstext(t,this._orgPCss),this._orgPCss="",h.removeClass(t,s),t.removeAttribute(W))}},{key:"getFullscreen",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.config.fullscreenTarget,t=this.root,i=this.media;if("video"!==e&&"media"!==e||(e=this[e]),e||(e=t),this._fullScreenOffset={top:h.scrollTop(),left:h.scrollLeft()},this._fullscreenEl=e,this._fullActionFrom="get",h.getFullScreenEl()===this._fullscreenEl)return this.onFullscreenChange(),Promise.resolve();try{for(var s=0;s<z.length;s++){var n=z[s];if(e[n]){var o="webkitRequestFullscreen"===n?e.webkitRequestFullscreen(window.Element.ALLOW_KEYBOARD_INPUT):e[n]();return o&&o.then?o:Promise.resolve()}}return i.fullscreenEnabled||i.webkitSupportsFullscreen?(i.webkitEnterFullscreen(),Promise.resolve()):Promise.reject(new Error("call getFullscreen fail"))}catch(r){return Promise.reject(new Error("call getFullscreen fail"))}}},{key:"exitFullscreen",value:function(e){if(this.isRotateFullscreen&&this.exitRotateFullscreen(),this._fullscreenEl||h.getFullScreenEl()){this.root;var t=this.media;this._fullActionFrom="exit";try{for(var i=0;i<M.length;i++){var s=M[i];if(document[s]){var n=document[s]();return n&&n.then?n:Promise.resolve()}}return t&&t.webkitSupportsFullscreen?(t.webkitExitFullScreen(),Promise.resolve()):Promise.reject(new Error("call exitFullscreen fail"))}catch(o){return Promise.reject(new Error("call exitFullscreen fail"))}}}},{key:"getCssFullscreen",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.config.fullscreenTarget;this.isRotateFullscreen?this.exitRotateFullscreen():this.fullscreen&&this.exitFullscreen();var t=e?"".concat(Q.INNER_FULLSCREEN," ").concat(Q.CSS_FULLSCREEN):Q.CSS_FULLSCREEN;this.changeFullStyle(this.root,e,t);var i=this.config.fullscreen,s=void 0===i?{}:i;(!0===s.useCssFullscreen||"function"==typeof s.useCssFullscreen&&s.useCssFullscreen())&&(this.fullscreen=!0,this.emit(y,!0)),this._cssfullscreenEl=e,this.cssfullscreen=!0,this.emit(O,!0)}},{key:"exitCssFullscreen",value:function(){var e=this._cssfullscreenEl?"".concat(Q.INNER_FULLSCREEN," ").concat(Q.CSS_FULLSCREEN):Q.CSS_FULLSCREEN;if(this.fullscreen){var t=this.config.fullscreen,i=void 0===t?{}:t;!0===i.useCssFullscreen||"function"==typeof i.useCssFullscreen&&i.useCssFullscreen()?(this.recoverFullStyle(this.root,this._cssfullscreenEl,e),this.fullscreen=!1,this.emit(y,!1)):this.removeClass(e)}else this.recoverFullStyle(this.root,this._cssfullscreenEl,e);this._cssfullscreenEl=null,this.cssfullscreen=!1,this.emit(O,!1)}},{key:"getRotateFullscreen",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.config.fullscreenTarget;this.cssfullscreen&&this.exitCssFullscreen(e);var t=e?"".concat(Q.INNER_FULLSCREEN," ").concat(Q.ROTATE_FULLSCREEN):Q.ROTATE_FULLSCREEN;this._fullscreenEl=e||this.root,this.changeFullStyle(this.root,e,t,Q.PARENT_ROTATE_FULLSCREEN),this.isRotateFullscreen=!0,this.fullscreen=!0,this.setRotateDeg(90),this._rootStyle=this.root.getAttribute("style");var i=90===Math.abs(window.orientation)||90===Math.abs(screen.orientation.angle);this.root.style.width="".concat(i?window.innerWidth:window.innerHeight,"px"),this.emit(y,!0)}},{key:"exitRotateFullscreen",value:function(e){var t=this._fullscreenEl!==this.root?"".concat(Q.INNER_FULLSCREEN," ").concat(Q.ROTATE_FULLSCREEN):Q.ROTATE_FULLSCREEN;this.recoverFullStyle(this.root,this._fullscreenEl,t,Q.PARENT_ROTATE_FULLSCREEN),this.isRotateFullscreen=!1,this.fullscreen=!1,this.setRotateDeg(0),this.emit(y,!1),this._rootStyle&&(this.root.style.style=this._rootStyle,this._rootStyle=!1)}},{key:"setRotateDeg",value:function(e){90===window.orientation||-90===window.orientation?this.rotateDeg=0:this.rotateDeg=e}},{key:"focus",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{autoHide:!this.config.closeDelayBlur,delay:this.config.inactive};this.isActive?this.onFocus(e):this.emit(w,u({paused:this.paused,ended:this.ended},e))}},{key:"blur",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{ignorePaused:!1};this.isActive?(this._clearUserTimer(),this.emit(D,u({paused:this.paused,ended:this.ended},e))):this.onBlur(e)}},{key:"onFocus",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{autoHide:!0,delay:3e3},i=this.innerStates;if(this.isActive=!0,this.removeClass(Q.INACTIVE),this._clearUserTimer(),void 0!==t.isLock&&(i.isActiveLocked=t.isLock),!1===t.autoHide||!0===t.isLock||i.isActiveLocked)this._clearUserTimer();else{var s=t&&t.delay?t.delay:this.config.inactive;this.userTimer=h.setTimeout(this,function(){e.userTimer=null,e.blur()},s)}}},{key:"onBlur",value:function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).ignorePaused,t=void 0!==e&&e;if(!this.innerStates.isActiveLocked){var i=this.config.closePauseVideoFocus;this.isActive=!1,(t||i||!this.paused&&!this.ended)&&this.addClass(Q.INACTIVE)}}},{key:"onEmptied",value:function(){this.updateAcc("emptied")}},{key:"onCanplay",value:function(){this.removeClass(Q.ENTER),this.removeClass(Q.ERROR),this.removeClass(Q.LOADING),this.isCanplay=!0,this.waitTimer&&h.clearTimeout(this,this.waitTimer)}},{key:"onLoadeddata",value:function(){var e=this;this.isError=!1,this.isSeeking=!1,this.__startTime>0&&(this.duration>0?this._seekToStartTime():this.once(x,function(){e._seekToStartTime()}))}},{key:"onLoadstart",value:function(){this.removeClass(Q.ERROR),this.isCanplay=!1}},{key:"onPlay",value:function(){this.state===he.ENDED&&this.setState(he.RUNNING),this.removeClass(Q.PAUSED),this.ended&&this.removeClass(Q.ENDED),!this.config.closePlayVideoFocus&&this.focus()}},{key:"onPause",value:function(){this.addClass(Q.PAUSED),this.updateAcc("pause"),this.config.closePauseVideoFocus||(this._clearUserTimer(),this.focus())}},{key:"onEnded",value:function(){this.updateAcc("ended"),this.addClass(Q.ENDED),this.setState(he.ENDED)}},{key:"onError",value:function(){this.isError=!0,this.updateAcc("error"),this.removeClass(Q.NOT_ALLOW_AUTOPLAY),this.removeClass(Q.NO_START),this.removeClass(Q.ENTER),this.removeClass(Q.LOADING),this.addClass(Q.ERROR)}},{key:"onSeeking",value:function(){this.isSeeking||this.updateAcc("seeking"),this.isSeeking=!0,this.addClass(Q.SEEKING)}},{key:"onSeeked",value:function(){this.isSeeking=!1,this.waitTimer&&h.clearTimeout(this,this.waitTimer),this.removeClass(Q.LOADING),this.removeClass(Q.SEEKING)}},{key:"onWaiting",value:function(){var e=this;this.waitTimer&&h.clearTimeout(this,this.waitTimer),this.updateAcc("waiting"),this.waitTimer=h.setTimeout(this,function(){e.addClass(Q.LOADING),e.emit(U),h.clearTimeout(e,e.waitTimer),e.waitTimer=null},this.config.minWaitDelay)}},{key:"onPlaying",value:function(){var e=this;this.isError=!1,[Q.NO_START,Q.PAUSED,Q.ENDED,Q.ERROR,Q.REPLAY,Q.LOADING].forEach(function(t){e.removeClass(t)}),this._accPlayed.t||this.paused||this.ended||(this._accPlayed.t=/* @__PURE__ */(new Date).getTime())}},{key:"onTimeupdate",value:function(){!this._videoHeight&&this.media.videoHeight&&this.resize(),(this.waitTimer||this.hasClass(Q.LOADING))&&this.media.readyState>2&&(this.removeClass(Q.LOADING),h.clearTimeout(this,this.waitTimer),this.waitTimer=null),!this.paused&&this.state===he.NOTALLOW&&this.duration&&(this.setState(he.RUNNING),this.emit(P)),this._accPlayed.t||this.paused||this.ended||(this._accPlayed.t=/* @__PURE__ */(new Date).getTime())}},{key:"onVolumechange",value:function(){"Number"===h.typeOf(this.config.volume)&&(this.config.volume=this.volume)}},{key:"onRatechange",value:function(){this.config.defaultPlaybackRate=this.playbackRate}},{key:"emitUserAction",value:function(e,t,i){if(this.media&&t&&e){var s="String"===h.typeOf(e)?e:e.type||"";i.props&&"Array"!==h.typeOf(i.props)&&(i.props=[i.props]),this.emit(m,u({eventType:s,action:t,currentTime:this.currentTime,duration:this.duration,ended:this.ended,event:e},i))}}},{key:"updateAcc",value:function(e){if(this._accPlayed.t){var t=/* @__PURE__ */(new Date).getTime()-this._accPlayed.t;this._accPlayed.acc+=t,this._accPlayed.t=0,("ended"===e||this.ended)&&(this._accPlayed.loopAcc=this._accPlayed.acc)}}},{key:"checkBuffer",value:function(e){var t=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{startDiff:0,endDiff:0})||{},i=t.startDiff,s=void 0===i?0:i,n=t.endDiff,o=void 0===n?0:n,r=this.media.buffered;if(!r||0===r.length||!this.duration)return!0;for(var a=e||this.media.currentTime||.2,l=r.length,u=0;u<l;u++)if(r.start(u)+s<=a&&r.end(u)-o>a)return!0;return!1}},{key:"resizePosition",value:function(){var e=this,t=this.videoPos,i=t.vy,s=t.vx,n=t.h,o=t.w,r=this.videoPos.rotate;if(!(r<0&&n<0&&o<0)){var a=this.videoPos._pi;if(!a&&this.media.videoHeight&&(a=this.media.videoWidth/this.media.videoHeight*100),a){this.videoPos.pi=a;var l={rotate:r=r<0?0:r},u=0,c=0,f=1,d=Math.abs(r/90),g=this.root,v=this.innerContainer,p=g.offsetWidth,m=v?v.offsetHeight:g.offsetHeight,y={},_=m,k=p;if(d%2==0)f=n>0?100/n:o>0?100/o:1,l.scale=f,u=i>0?(100-n)/2-i:0,l.y=2===d?0-u:u,c=s>0?(100-o)/2-s:0,l.x=2===d?0-c:c,y.width="".concat(k,"px"),y.height="".concat(_,"px"),y.maxWidth="",y.maxHeight="";else if(d%2==1){_=p;var E=m-p;c=-E/2/(k=m)*100,l.x=3===d?c+i/2:c-i/2,u=E/2/_*100,l.y=3===d?u+s/2:u-s/2,l.scale=f,y.width="".concat(k,"px"),y.maxWidth="".concat(k,"px"),y.height="".concat(_,"px"),y.maxHeight="".concat(_,"px")}var T=h.getTransformStyle(l,this.media.style.transform||this.media.style.webkitTransform);y.transform=T,y.webkitTransform=T,Object.keys(y).map(function(t){e.media.style[t]=y[t]})}}}},{key:"position",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{h:0,y:0,x:0,w:0};if(this.media&&e&&e.h){var t=this.videoPos;t.h=100*e.h||0,t.w=100*e.w||0,t.vx=100*e.x||0,t.vy=100*e.y||0,this.resizePosition()}}},{key:"setConfig",value:function(e){var t=this;e&&Object.keys(e).map(function(i){if("plugins"!==i){t.config[i]=e[i];var s=t.plugins[i.toLowerCase()];s&&"Function"===h.typeOf(s.setConfig)&&s.setConfig(e[i])}})}},{key:"playNext",value:function(e){var t=this;this.resetState(),this.setConfig(e),this._currentTime=0,this._duration=0,$(this,"playnext",function(){t.start(),t.emit(B,e)})}},{key:"resize",value:function(){var e=this;if(this.media&&this.root){var t=this.root.getBoundingClientRect();this.sizeInfo.width=t.width,this.sizeInfo.height=t.height,this.sizeInfo.left=t.left,this.sizeInfo.top=t.top;var i=this.media,s=i.videoWidth,n=i.videoHeight,o=this.config,r=o.fitVideoSize,a=o.videoFillMode;if("fill"!==a&&"cover"!==a&&"contain"!==a||this.setAttribute("data-xgfill",a),n&&s){this._videoHeight=n,this._videoWidth=s;var l=this.controls&&this.innerContainer?this.controls.root.getBoundingClientRect().height:0,u=t.width,c=t.height-l,h=parseInt(s/n*1e3,10),f=parseInt(u/c*1e3,10),d=u,g=c,v={};"auto"===r&&f>h||"fixWidth"===r?(g=u/h*1e3,this.config.fluid?v.paddingTop="".concat(100*g/d,"%"):v.height="".concat(g+l,"px")):("auto"===r&&f<h||"fixHeight"===r)&&(d=h*c/1e3,v.width="".concat(d,"px")),this.fullscreen||this.cssfullscreen||Object.keys(v).forEach(function(t){e.root.style[t]=v[t]}),("fillHeight"===a&&f<h||"fillWidth"===a&&f>h)&&this.setAttribute("data-xgfill","cover");var p={videoScale:h,vWidth:d,vHeight:g,cWidth:d,cHeight:g+l};this.resizePosition(),this.emit(j,p)}}}},{key:"updateObjectPosition",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;this.media.updateObjectPosition?this.media.updateObjectPosition(e,t):this.media.style.objectPosition="".concat(100*e,"% ").concat(100*t,"%")}},{key:"setState",value:function(e){ae.logInfo("setState","state from:".concat(fe[this.state]," to:").concat(fe[e])),this._state=e}},{key:"preProcessUrl",value:function(e,t){var i=this.config,s=i.preProcessUrl,n=i.preProcessUrlOptions,o=Object.assign({},n,t);return h.isBlob(e)||"function"!=typeof s?{url:e}:s(e,o)}},{key:"_seekToStartTime",value:function(){this.__startTime>0&&this.duration>0&&(this.currentTime=this.__startTime>this.duration?this.duration:this.__startTime,this.__startTime=-1)}},{key:"state",get:function(){return this._state}},{key:"isFullscreen",get:function(){return this.fullscreen}},{key:"isCssfullScreen",get:function(){return this.cssfullscreen}},{key:"hasStart",get:function(){return this._hasStart},set:function(e){"boolean"==typeof e&&(this._hasStart=e,!1===e&&this.setState(he.READY),this.emit("hasstart"))}},{key:"isPlaying",get:function(){return this._state===he.RUNNING||this._state===he.ENDED},set:function(e){e?this.setState(he.RUNNING):this._state>=he.RUNNING&&this.setState(he.ATTACHED)}},{key:"definitionList",get:function(){return this.config&&this.config.definition&&this.config.definition.list||[]},set:function(e){var t=this,i=this.config.definition,s=null,n=null;i.list=e,this.emit("resourceReady",e),e.forEach(function(e){var o;(null===(o=t.curDefinition)||void 0===o?void 0:o.definition)===e.definition&&(s=e),i.defaultDefinition===e.definition&&(n=e)}),!n&&e.length>0&&(n=e[0]),s?this.changeDefinition(s):n&&this.changeDefinition(n)}},{key:"videoFrameInfo",get:function(){var e={total:0,dropped:0,corrupted:0,droppedRate:0,droppedDuration:0};if(!this.media||!this.media.getVideoPlaybackQuality)return e;var t=this.media.getVideoPlaybackQuality();return e.dropped=t.droppedVideoFrames||0,e.total=t.totalVideoFrames||0,e.corrupted=t.corruptedVideoFrames||0,e.total>0&&(e.droppedRate=e.dropped/e.total*100,e.droppedDuration=parseInt(this.cumulateTime/e.total*e.dropped,0)),e}},{key:"lang",get:function(){return this.config.lang},set:function(e){0!==ue.langKeys.filter(function(t){return t===e}).length||"zh"===e?(this.config.lang=e,q.setLang(e,this)):console.error("Sorry, set lang fail, because the language [".concat(e,"] is not supported now, list of all supported languages is [").concat(ue.langKeys.join(),"] "))}},{key:"i18n",get:function(){var e=this.config.lang;return"zh"===e&&(e="zh-cn"),this.__i18n.lang[e]||this.__i18n.lang.en}},{key:"i18nKeys",get:function(){return this.__i18n.textKeys||{}}},{key:"version",get:function(){return ce}},{key:"playerId",get:function(){return this._pluginInfoId}},{key:"url",get:function(){return this.__url||this.config.url},set:function(e){this.__url=e}},{key:"poster",get:function(){return this.plugins.poster?this.plugins.poster.config.poster:this.config.poster},set:function(e){this.plugins.poster&&this.plugins.poster.update(e)}},{key:"readyState",get:function(){return a(l(Y.prototype),"readyState",this)}},{key:"error",get:function(){var e=a(l(Y.prototype),"error",this);return this.i18n[e]||e}},{key:"networkState",get:function(){return a(l(Y.prototype),"networkState",this)}},{key:"fullscreenChanging",get:function(){return!(null===this._fullScreenOffset)}},{key:"cumulateTime",get:function(){var e=this._accPlayed,t=e.acc,i=e.t;return i?/* @__PURE__ */(new Date).getTime()-i+t:t}},{key:"zoom",get:function(){return this.config.zoom},set:function(e){this.config.zoom=e}},{key:"videoRotateDeg",get:function(){return this.videoPos.rotate},set:function(e){(e=h.convertDeg(e))%90==0&&e!==this.videoPos.rotate&&(this.videoPos.rotate=e,this.resizePosition())}},{key:"avgSpeed",get:function(){return me},set:function(e){me=e}},{key:"realTimeSpeed",get:function(){return pe},set:function(e){pe=e}},{key:"offsetCurrentTime",get:function(){return this._offsetInfo.currentTime||0},set:function(e){this._offsetInfo.currentTime=e}},{key:"offsetDuration",get:function(){return this._offsetInfo.duration||0},set:function(e){this._offsetInfo.duration=e||0}},{key:"hook",value:function(e,t){return te.call.apply(te,[this].concat(Array.prototype.slice.call(arguments)))}},{key:"useHooks",value:function(e,t){return ie.call.apply(ie,[this].concat(Array.prototype.slice.call(arguments)))}},{key:"removeHooks",value:function(e,t){return se.call.apply(se,[this].concat(Array.prototype.slice.call(arguments)))}},{key:"usePluginHooks",value:function(e,t,i){for(var s=arguments.length,n=new Array(s>3?s-3:0),o=3;o<s;o++)n[o-3]=arguments[o];return ne.call.apply(ne,[this].concat(Array.prototype.slice.call(arguments)))}},{key:"removePluginHooks",value:function(e,t,i){for(var s=arguments.length,n=new Array(s>3?s-3:0),o=3;o<s;o++)n[o-3]=arguments[o];return oe.call.apply(oe,[this].concat(Array.prototype.slice.call(arguments)))}},{key:"setUserActive",value:function(e,t){var i;"boolean"==typeof t&&t!==this.muted&&(this.addInnerOP("volumechange"),h.typeOf(t)===Boolean&&(this.muted=t)),null===(i=ye)||void 0===i||i.setActive(this.playerId,e)}}],[{key:"debugger",get:function(){return ae.config.debug},set:function(e){ae.config.debug=e}},{key:"instManager",get:function(){return ye},set:function(e){ye=e}},{key:"getCurrentUserActivePlayerId",value:function(){var e;return null===(e=ye)||void 0===e?void 0:e.getActiveId()}},{key:"setCurrentUserActive",value:function(e,t){var i;null===(i=ye)||void 0===i||i.setActive(e,t)}},{key:"isHevcSupported",value:function(){return d.isHevcSupported()}},{key:"probeConfigSupported",value:function(e){return d.probeConfigSupported(e)}},{key:"install",value:function(e,t){Y.plugins||(Y.plugins={}),Y.plugins[e]||(Y.plugins[e]=t)}},{key:"use",value:function(e,t){Y.plugins||(Y.plugins={}),Y.plugins[e]=t}}]),Y}();e(_e,"defaultPreset",null),e(_e,"XgVideoProxy",null),_e.instManager=de.getInstance();export{K as BasePlugin,v as Errors,H as Events,ue as I18N,Y as Plugin,Q as STATE_CLASS,d as Sniffer,h as Util,_e as default};