/*!
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,defineProperty as n,assertThisInitialized as o,createClass as s,objectSpread2 as r,typeof as a}from"../../_virtual/_rollupPluginBabelHelpers.js";import u from"../../utils/util.js";import l from"../../utils/sniffer.js";import{DURATION_CHANGE as c,TIME_UPDATE as h,SEEKED as d,PROGRESS as m,ENDED as v,EMPTIED as p,VIDEO_RESIZE as f}from"../../events.js";import g,{POSITIONS as y}from"../../plugin/plugin.js";import k from"./innerList.js";var M={POINT:"inner-focus-point",HIGHLIGHT:"inner-focus-highlight"},b=/* @__PURE__ */function(){e(C,g);var b=t(C);function C(e){var t;return i(this,C),t=b.call(this,e),n(o(t),"onMoveOnly",function(e,i){var n=o(t),s=n.pos,r=n.config,a=n.player,l=i;if(e){u.event(e);var c=u.getEventPos(e,a.zoom),h=90===a.rotateDeg?c.clientY:c.clientX;if(s.moving&&Math.abs(s.x-h)<r.miniMoveStep)return;s.moving=!0,s.x=h,l=t.computeTime(e,h)}t.triggerCallbacks("dragmove",l,e),t._updateInnerFocus(l)}),n(o(t),"onBodyClick",function(e){t.pos.isLocked&&(t.pos.isLocked=!1,e.preventDefault(),e.stopPropagation())}),n(o(t),"_mouseDownHandler",function(e,i){t._state.time=i.currentTime,t.updateWidth(i.currentTime,i.seekTime,i.percent,0),t._updateInnerFocus(i)}),n(o(t),"_mouseUpHandler",function(e,i){o(t).pos.moving&&t.updateWidth(i.currentTime,i.seekTime,i.percent,2)}),n(o(t),"_mouseMoveHandler",function(e,i){var n=o(t),s=n._state,r=n.pos,a=n.config,u=n.player;s.time<i.currentTime?i.forward=!0:i.forward=!1,s.time=i.currentTime,r.isDown&&!r.moving&&(r.moving=!0,a.isPauseMoving&&u.pause(),t.triggerCallbacks("dragstart",i,e),t.emitUserAction("drag","dragstart",i)),t.updateWidth(i.currentTime,i.seekTime,i.percent,1),t.triggerCallbacks("dragmove",i,e),t._updateInnerFocus(i)}),n(o(t),"onMouseDown",function(e){var i=o(t),n=i._state,s=i.player,r=i.pos,a=i.config,l=i.playerConfig,c=u.getEventPos(e,s.zoom),h=90===s.rotateDeg?c.clientY:c.clientX;if(!(s.isMini||a.closeMoveSeek||!l.allowSeekAfterEnded&&s.ended)){if(s.duration||s.isPlaying){e.stopPropagation(),t.focus(),u.checkIsFunction(l.disableSwipeHandler)&&l.disableSwipeHandler(),u.checkIsFunction(a.onMoveStart)&&a.onMoveStart(),u.event(e),r.x=h,r.isDown=!0,r.moving=!1,n.prePlayTime=s.currentTime,s.focus({autoHide:!1}),t.isProgressMoving=!0,u.addClass(t.progressBtn,"active");var d=t.computeTime(e,h);return d.prePlayTime=n.prePlayTime,t._mouseDownHandlerHook(e,d),"touchstart"===e.type?(t.root.addEventListener("touchmove",t.onMouseMove),t.root.addEventListener("touchend",t.onMouseUp),t.root.addEventListener("touchcancel",t.onMouseUp)):(t.unbind("mousemove",t.onMoveOnly),document.addEventListener("mousemove",t.onMouseMove,!1),document.addEventListener("mouseup",t.onMouseUp,!1)),!0}s.play()}}),n(o(t),"onMouseUp",function(e){var i=o(t),n=i.player,s=i.config,r=i.pos,a=i.playerConfig,l=i._state;if(r){e.stopPropagation(),e.preventDefault(),u.checkIsFunction(a.enableSwipeHandler)&&a.enableSwipeHandler(),u.checkIsFunction(s.onMoveEnd)&&s.onMoveEnd(),u.event(e),u.removeClass(t.progressBtn,"active");var c=t.computeTime(e,r.x);c.prePlayTime=l.prePlayTime,r.moving?(t.triggerCallbacks("dragend",c,e),t.emitUserAction("drag","dragend",c)):(t.triggerCallbacks("click",c,e),t.emitUserAction("click","click",c)),t._mouseUpHandlerHook(e,c),r.moving=!1,r.isDown=!1,r.x=0,r.y=0,r.isLocked=!0,l.prePlayTime=0,l.time=0;var h=e.type;"touchend"===h||"touchcancel"===h?(t.root.removeEventListener("touchmove",t.onMouseMove),t.root.removeEventListener("touchend",t.onMouseUp),t.root.removeEventListener("touchcancel",t.onMouseUp),t.blur()):(document.removeEventListener("mousemove",t.onMouseMove,!1),document.removeEventListener("mouseup",t.onMouseUp,!1),r.isEnter?"mobile"!==a.isMobileSimulateMode&&t.bind("mousemove",t.onMoveOnly):t.onMouseLeave(e)),u.setTimeout(o(t),function(){t.resetSeekState()},1),n.focus()}}),n(o(t),"onMouseMove",function(e){var i=o(t),n=i._state,s=i.pos,r=i.player,a=i.config;u.checkTouchSupport()&&e.preventDefault(),u.event(e);var l=u.getEventPos(e,r.zoom),c=90===r.rotateDeg?l.clientY:l.clientX,h=Math.abs(s.x-c);if(!(s.moving&&h<a.miniMoveStep||!s.moving&&h<a.miniStartStep)){s.x=c;var d=t.computeTime(e,c);d.prePlayTime=n.prePlayTime,t._mouseMoveHandlerHook(e,d)}}),n(o(t),"onMouseOut",function(e){t.triggerCallbacks("mouseout",null,e)}),n(o(t),"onMouseOver",function(e){t.triggerCallbacks("mouseover",null,e)}),n(o(t),"onMouseEnter",function(e){var i=o(t),n=i.player,s=i.pos;if(!(s.isDown||s.isEnter||n.isMini||!n.config.allowSeekAfterEnded&&n.ended)){s.isEnter=!0,t.bind("mousemove",t.onMoveOnly),t.bind("mouseleave",t.onMouseLeave),u.event(e);var r=u.getEventPos(e,n.zoom),a=90===n.rotateDeg?r.clientY:r.clientX,l=t.computeTime(e,a);t.triggerCallbacks("mouseenter",l,e),t.focus()}}),n(o(t),"onMouseLeave",function(e){t.triggerCallbacks("mouseleave",null,e),t.unlock(),t._updateInnerFocus(null)}),n(o(t),"onVideoResize",function(){var e=t.pos,i=e.x,n=e.isDown;if(e.isEnter&&!n){var o=t.computeTime(null,i);t.onMoveOnly(null,o)}}),t.useable=!1,t.isProgressMoving=!1,t.__dragCallBacks=[],t._state={now:-1,direc:0,time:0,prePlayTime:-1},t._disableBlur=!1,"boolean"==typeof t.config.isDragingSeek&&(console.warn("[XGPLAYER] 'isDragingSeek' is deprecated, please use 'isDraggingSeek' instead"),t.config.isDraggingSeek=t.config.isDragingSeek),t}return s(C,[{key:"offsetDuration",get:function(){return this.playerConfig.customDuration||this.player.offsetDuration||this.player.duration}},{key:"duration",get:function(){return this.playerConfig.customDuration||this.player.duration}},{key:"timeOffset",get:function(){return this.playerConfig.timeOffset||0}},{key:"currentTime",get:function(){var e=this.player,t=e.offsetCurrentTime,i=e.currentTime;return t>=0?t:i+this.timeOffset}},{key:"changeState",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.useable=e}},{key:"show",value:function(e){this.root&&(this.root.style.display="flex")}},{key:"_initInner",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t&&0!==t.length||(t=[{percent:1}]);var n=r(r({fragments:t},i),{},{actionCallback:function(t){e.emitUserAction("fragment_focus","fragment_focus",t)}});this.innerList?this.innerList.reset(n):(this.innerList=new k(n),this.outer.insertBefore(this.innerList.render(),this.outer.children[0]),["findHightLight","unHightLight","setHightLight","findFragment"].map(function(t){e[t]=e.innerList[t].bind(e.innerList)}))}},{key:"_updateInnerFocus",value:function(e){this.innerList&&this.innerList.updateFocus(e)}},{key:"afterCreate",value:function(){if(!this.config.disable&&!this.playerConfig.isLive){this.pos={x:0,y:0,moving:!1,isDown:!1,isEnter:!1,isLocked:!1},this.outer=this.find("xg-outer");var e=this.config,t=e.fragFocusClass,i=e.fragAutoFocus,n=e.fragClass;this._initInner(this.config.fragments,{fragFocusClass:t,fragAutoFocus:i,fragClass:n,style:this.playerConfig.commonStyle||{}}),"mobile"===l.device&&(this.config.isDraggingSeek=!1,this.isMobile=!0),this.progressBtn=this.find(".xgplayer-progress-btn"),this.listenEvents(),this.bindDomEvents(),this.initCustomStyle()}}},{key:"listenEvents",value:function(){var e=this;this.on(c,function(){e.onMouseLeave()}),this.on(h,function(){e.onTimeupdate()}),this.on(d,function(){e.onTimeupdate(),e.onCacheUpdate()}),this.on(m,function(){e.onCacheUpdate()}),this.on(v,function(){e.onCacheUpdate(!0),e.onTimeupdate(!0),e._state.now=0}),this.on(p,function(){e.onReset()}),this.on(f,function(){e.onVideoResize()})}},{key:"setConfig",value:function(e){var t=this,i=null;Object.keys(e).forEach(function(n){t.config[n]=e[n],"fragments"===n&&(i=e[n])}),i&&this._initInner(i,e)}},{key:"initCustomStyle",value:function(){var e=(this.playerConfig||{}).commonStyle.sliderBtnStyle,t=this.progressBtn;e&&("string"==typeof e?t.style.boxShadow=e:"object"===a(e)&&Object.keys(e).map(function(i){t.style[i]=e[i]}))}},{key:"triggerCallbacks",value:function(e,t,i){this.__dragCallBacks.length>0&&this.__dragCallBacks.map(function(n){if(n&&n.handler&&n.type===e)try{n.handler(t,i)}catch(o){console.error("[XGPLAYER][triggerCallbacks] ".concat(n," error"),o)}})}},{key:"addCallBack",value:function(e,t){t&&"function"==typeof t&&this.__dragCallBacks.push({type:e,handler:t})}},{key:"removeCallBack",value:function(e,t){var i=this.__dragCallBacks,n=-1;i.map(function(i,o){i&&i.type===e&&i.handler===t&&(n=o)}),n>-1&&i.splice(n,1)}},{key:"unlock",value:function(){var e=this.player,t=this.pos;t.isEnter=!1,t.isLocked=!1,e.isMini||(this.unbind("mousemove",this.onMoveOnly),t.isDown?this.unbind("mouseleave",this.onMouseLeave):this.blur())}},{key:"bindDomEvents",value:function(){var e=this.player.config;this._mouseDownHandlerHook=this.hook("dragstart",this._mouseDownHandler),this._mouseUpHandlerHook=this.hook("dragend",this._mouseUpHandler),this._mouseMoveHandlerHook=this.hook("drag",this._mouseMoveHandler),"touch"!==this.domEventType&&"compatible"!==this.domEventType||this.root.addEventListener("touchstart",this.onMouseDown),"mouse"!==this.domEventType&&"compatible"!==this.domEventType||(this.bind("mousedown",this.onMouseDown),"mobile"!==e.isMobileSimulateMode&&this.bind("mouseenter",this.onMouseEnter),this.bind("mouseover",this.onMouseOver),this.bind("mouseout",this.onMouseOut),this.player.root.addEventListener("click",this.onBodyClick,!0))}},{key:"focus",value:function(){this.player.controls.pauseAutoHide(),u.addClass(this.root,"active")}},{key:"blur",value:function(){this._disableBlur||(this.player.controls.recoverAutoHide(),u.removeClass(this.root,"active"))}},{key:"disableBlur",value:function(){this._disableBlur=!0}},{key:"enableBlur",value:function(){this._disableBlur=!1}},{key:"updateWidth",value:function(e,t,i,n){var o=this.config,s=this.player;if(!o.isCloseClickSeek||0!==n){var r=t=t>=s.duration?s.duration-o.endedDiff:Number(t).toFixed(1);this.updatePercent(i),this.updateTime(e),(1!==n||o.isDraggingSeek&&"audio"!==s.config.mediaType)&&(this._state.now=r,this._state.direc=r>s.currentTime?0:1,s.seek(r))}}},{key:"computeTime",value:function(e,t){var i,n,o=this.player,s=this.root.getBoundingClientRect(),r=s.width,a=s.height,l=s.top,c=s.left,h=t;90===o.rotateDeg?(i=a,n=l):(i=r,n=c);var d=h-n,m=(d=d>i?i:d<0?0:d)/i;m=m<0?0:m>1?1:m,Number.isNaN(m)&&(m=this.player.currentTime/this.offsetDuration);var v=parseInt(m*this.offsetDuration*1e3,10)/1e3;return{percent:m,currentTime:v,seekTime:u.getCurrentTimeByOffset(v,o.timeSegments),offset:d,width:i,left:n,e:e}}},{key:"updateTime",value:function(e){var t=this.player,i=this.duration;e>i?e=i:e<0&&(e=0);var n=t.plugins.time;n&&n.updateTime(e)}},{key:"resetSeekState",value:function(){this.isProgressMoving=!1;var e=this.player.plugins.time;e&&e.resetActive()}},{key:"updatePercent",value:function(e,t){if(this.isProgressMoving=!0,!this.config.disable){e=e>1?1:e<0?0:e,this.progressBtn.style.left="".concat(100*e,"%"),this.innerList.update({played:e*this.offsetDuration},this.offsetDuration);var i=this.player.plugins.miniprogress;i&&i.update({played:e*this.offsetDuration},this.offsetDuration)}}},{key:"onTimeupdate",value:function(e){var t=this.player,i=this._state,n=this.offsetDuration;if(!(t.isSeeking&&t.media.seeking||this.isProgressMoving)&&t.hasStart){if(i.now>-1){var o=parseInt(1e3*i.now,10)-parseInt(1e3*t.currentTime,10);if(0===i.direc&&o>300||1===i.direc&&o>-300)return void(i.now=-1);i.now=-1}var s=this.currentTime;s=u.adjustTimeByDuration(s,n,e),this.innerList.update({played:s},n),this.progressBtn.style.left="".concat(s/n*100,"%")}}},{key:"onCacheUpdate",value:function(e){var t=this.player,i=this.duration;if(t){var n=t.bufferedPoint.end;n=u.adjustTimeByDuration(n,i,e),this.innerList.update({cached:n},i)}}},{key:"onReset",value:function(){this.innerList.update({played:0,cached:0},0),this.progressBtn.style.left="0%"}},{key:"destroy",value:function(){var e=this.player;this.thumbnailPlugin=null,this.innerList.destroy(),this.innerList=null;var t=this.domEventType;"touch"!==t&&"compatible"!==t||(this.root.removeEventListener("touchstart",this.onMouseDown),this.root.removeEventListener("touchmove",this.onMouseMove),this.root.removeEventListener("touchend",this.onMouseUp),this.root.removeEventListener("touchcancel",this.onMouseUp)),"mouse"!==t&&"compatible"!==t||(this.unbind("mousedown",this.onMouseDown),this.unbind("mouseenter",this.onMouseEnter),this.unbind("mousemove",this.onMoveOnly),this.unbind("mouseleave",this.onMouseLeave),document.removeEventListener("mousemove",this.onMouseMove,!1),document.removeEventListener("mouseup",this.onMouseUp,!1),e.root.removeEventListener("click",this.onBodyClick,!0))}},{key:"render",value:function(){if(!this.config.disable&&!this.playerConfig.isLive){var e=this.player.controls?this.player.controls.config.mode:"";return'\n    <xg-progress class="xgplayer-progress '.concat("bottom"===e?"xgplayer-progress-bottom":"",'">\n      <xg-outer class="xgplayer-progress-outer">\n        <xg-progress-btn class="xgplayer-progress-btn"></xg-progress-btn>\n      </xg-outer>\n    </xg-progress>\n    ')}}}],[{key:"pluginName",get:function(){return"progress"}},{key:"defaultConfig",get:function(){return{position:y.CONTROLS_CENTER,index:0,disable:!1,isDraggingSeek:!0,closeMoveSeek:!1,isPauseMoving:!1,isCloseClickSeek:!1,fragments:[{percent:1}],fragFocusClass:M.POINT,fragClass:"",fragAutoFocus:!1,miniMoveStep:5,miniStartStep:2,onMoveStart:function(){},onMoveEnd:function(){},endedDiff:.2}}},{key:"FRAGMENT_FOCUS_CLASS",get:function(){return M}}]),C}();export{b as default};