/*!
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 o,assertThisInitialized as s,createClass as n}from"../../_virtual/_rollupPluginBabelHelpers.js";import a from"../../utils/util.js";import l from"../../utils/sniffer.js";import{VOLUME_CHANGE as u,LOADED_DATA as r}from"../../events.js";import m,{POSITIONS as d}from"../../plugin/plugin.js";import h from"../assets/volumeLarge.js";import c from"../assets/volumeSmall.js";import v from"../assets/volumeMuted.js";var p=/* @__PURE__ */function(){e(g,m);var p=t(g);function g(){var e;i(this,g);for(var t=arguments.length,n=new Array(t),l=0;l<t;l++)n[l]=arguments[l];return e=p.call.apply(p,[this].concat(n)),o(s(e),"onBarMousedown",function(t){var i=s(e).player,o=e.find(".xgplayer-bar");a.event(t);var n=o.getBoundingClientRect(),l=a.getEventPos(t,i.zoom),u=n.height-(l.clientY-n.top);if(l.h=u,l.barH=n.height,e.pos=l,!(u<-2))return e.updateVolumePos(u,t),document.addEventListener("mouseup",e.onBarMouseUp),e._d.isStart=!0,!1}),o(s(e),"onBarMouseMove",function(t){var i=s(e)._d;if(i.isStart){var o=s(e),n=o.pos,l=o.player;t.preventDefault(),t.stopPropagation(),a.event(t);var u=a.getEventPos(t,l.zoom);i.isMoving=!0;var r=n.h-u.clientY+n.clientY;r>n.barH||e.updateVolumePos(r,t)}}),o(s(e),"onBarMouseUp",function(t){a.event(t),document.removeEventListener("mouseup",e.onBarMouseUp);var i=s(e)._d;i.isStart=!1,i.isMoving=!1}),o(s(e),"onMouseenter",function(t){e._d.isActive=!0,e.focus(),e.emit("icon_mouseenter",{pluginName:e.pluginName})}),o(s(e),"onMouseleave",function(t){e._d.isActive=!1,e.unFocus(100,!1,t),e.emit("icon_mouseleave",{pluginName:e.pluginName})}),o(s(e),"onVolumeChange",function(t){if(e.player){var i=e.player,o=i.muted,s=i.volume;e._d.isMoving||(e.find(".xgplayer-drag").style.height=o||0===s?"4px":"".concat(100*s,"%"),e.config.showValueLabel&&e.updateVolumeValue()),e.animate(o,s)}}),e}return n(g,[{key:"registerIcons",value:function(){return{volumeSmall:{icon:c,class:"xg-volume-small"},volumeLarge:{icon:h,class:"xg-volume"},volumeMuted:{icon:v,class:"xg-volume-mute"}}}},{key:"afterCreate",value:function(){var e=this;if(this._timerId=null,this._d={isStart:!1,isMoving:!1,isActive:!1},!this.config.disable){this.initIcons();var t=this.playerConfig,i=t.commonStyle,o=t.volume;i.volumeColor&&(this.find(".xgplayer-drag").style.backgroundColor=i.volumeColor),this.changeMutedHandler=this.hook("mutedChange",function(t){e.changeMuted(t)},{pre:function(e){e.preventDefault(),e.stopPropagation()}}),this._onMouseenterHandler=this.hook("mouseenter",this.onMouseenter),this._onMouseleaveHandler=this.hook("mouseleave",this.onMouseleave),"mobile"!==l.device&&"mobile"!==this.playerConfig.isMobileSimulateMode&&(this.bind("mouseenter",this._onMouseenterHandler),this.bind(["blur","mouseleave"],this._onMouseleaveHandler),this.bind(".xgplayer-slider","mousedown",this.onBarMousedown),this.bind(".xgplayer-slider","mousemove",this.onBarMouseMove),this.bind(".xgplayer-slider","mouseup",this.onBarMouseUp)),this.bind(".xgplayer-icon",["touchend","click"],this.changeMutedHandler),this.on(u,this.onVolumeChange),this.once(r,this.onVolumeChange),"Number"!==a.typeOf(o)&&(this.player.volume=this.config.default),this.onVolumeChange()}}},{key:"updateVolumePos",value:function(e,t){var i=this.player,o=this.find(".xgplayer-drag"),s=this.find(".xgplayer-bar");if(s&&o){var n=parseInt(e/s.getBoundingClientRect().height*1e3,10);o.style.height="".concat(e,"px");var a=Math.max(Math.min(n/1e3,1),0),l={volume:{from:i.volume,to:a}};i.muted&&(l.muted={from:!0,to:!1}),this.emitUserAction(t,"change_volume",{muted:i.muted,volume:i.volume,props:l}),i.volume=Math.max(Math.min(n/1e3,1),0),i.muted&&(i.muted=!1),this.config.showValueLabel&&this.updateVolumeValue()}}},{key:"updateVolumeValue",value:function(){var e=this.player,t=e.volume,i=e.muted,o=this.find(".xgplayer-value-label"),s=Math.max(Math.min(t,1),0);o.innerText=i?0:Math.round(100*s)}},{key:"focus",value:function(){this.player.focus({autoHide:!1}),this._timerId&&(a.clearTimeout(this,this._timerId),this._timerId=null),a.addClass(this.root,"slide-show")}},{key:"unFocus",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100,i=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],o=arguments.length>2?arguments[2]:void 0,s=this._d,n=this.player;s.isActive||(this._timerId&&(a.clearTimeout(this,this._timerId),this._timerId=null),this._timerId=a.setTimeout(this,function(){s.isActive||(i?n.blur():n.focus(),a.removeClass(e.root,"slide-show"),s.isStart&&e.onBarMouseUp(o)),e._timerId=null},t))}},{key:"changeMuted",value:function(e){e&&e.stopPropagation();var t=this.player;this._d.isStart&&this.onBarMouseUp(e),this.emitUserAction(e,"change_muted",{muted:t.muted,volume:t.volume,props:{muted:{from:t.muted,to:!t.muted}}}),t.volume>0&&(t.muted=!t.muted),t.volume<.01&&(t.volume=this.config.miniVolume)}},{key:"animate",value:function(e,t){e||0===t?this.setAttr("data-state","mute"):t<.5&&this.icons.volumeSmall?this.setAttr("data-state","small"):this.setAttr("data-state","normal")}},{key:"initIcons",value:function(){var e=this.icons;this.appendChild(".xgplayer-icon",e.volumeSmall),this.appendChild(".xgplayer-icon",e.volumeLarge),this.appendChild(".xgplayer-icon",e.volumeMuted)}},{key:"destroy",value:function(){this._timerId&&(a.clearTimeout(this,this._timerId),this._timerId=null),this.unbind("mouseenter",this.onMouseenter),this.unbind(["blur","mouseleave"],this.onMouseleave),this.unbind(".xgplayer-slider","mousedown",this.onBarMousedown),this.unbind(".xgplayer-slider","mousemove",this.onBarMouseMove),this.unbind(".xgplayer-slider","mouseup",this.onBarMouseUp),document.removeEventListener("mouseup",this.onBarMouseUp),this.unbind(".xgplayer-icon","mobile"===l.device?"touchend":"click",this.changeMutedHandler)}},{key:"render",value:function(){if(!this.config.disable){var e=this.config.default||this.player.volume,t=this.config.showValueLabel;return'\n    <xg-icon class="xgplayer-volume" data-state="normal">\n      <div class="xgplayer-icon">\n      </div>\n      <xg-slider class="xgplayer-slider">\n        '.concat(t?'<div class="xgplayer-value-label">'.concat(100*e,"</div>"):"",'\n        <div class="xgplayer-bar">\n          <xg-drag class="xgplayer-drag" style="height: ').concat(100*e,'%"></xg-drag>\n        </div>\n      </xg-slider>\n    </xg-icon>')}}}],[{key:"pluginName",get:function(){return"volume"}},{key:"defaultConfig",get:function(){return{position:d.CONTROLS_RIGHT,index:1,disable:!1,showValueLabel:!1,default:.6,miniVolume:.2}}}]),g}();export{p as default};