"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("vue"),c=require("../_util/classNames.js"),p=require("../_util/createRef.js"),u=require("../_util/raf.js"),o=require("../_util/supportsPassive.js"),m=20;function g(e){return"touches"in e?e.touches[0].pageY:e.pageY}const b=r.defineComponent({compatConfig:{MODE:3},name:"ScrollBar",inheritAttrs:!1,props:{prefixCls:String,scrollTop:Number,scrollHeight:Number,height:Number,count:Number,onScroll:{type:Function},onStartMove:{type:Function},onStopMove:{type:Function}},setup(){return{moveRaf:null,scrollbarRef:p.default(),thumbRef:p.default(),visibleTimeout:null,state:r.reactive({dragging:!1,pageY:null,startTop:null,visible:!1})}},watch:{scrollTop:{handler(){this.delayHidden()},flush:"post"}},mounted(){this.scrollbarRef.current?.addEventListener("touchstart",this.onScrollbarTouchStart,o.default?{passive:!1}:!1),this.thumbRef.current?.addEventListener("touchstart",this.onMouseDown,o.default?{passive:!1}:!1)},beforeUnmount(){this.removeEvents(),clearTimeout(this.visibleTimeout)},methods:{delayHidden(){clearTimeout(this.visibleTimeout),this.state.visible=!0,this.visibleTimeout=setTimeout(()=>{this.state.visible=!1},2e3)},onScrollbarTouchStart(e){e.preventDefault()},onContainerMouseDown(e){e.stopPropagation(),e.preventDefault()},patchEvents(){window.addEventListener("mousemove",this.onMouseMove),window.addEventListener("mouseup",this.onMouseUp),this.thumbRef.current.addEventListener("touchmove",this.onMouseMove,o.default?{passive:!1}:!1),this.thumbRef.current.addEventListener("touchend",this.onMouseUp)},removeEvents(){window.removeEventListener("mousemove",this.onMouseMove),window.removeEventListener("mouseup",this.onMouseUp),this.scrollbarRef.current.removeEventListener("touchstart",this.onScrollbarTouchStart,o.default?{passive:!1}:!1),this.thumbRef.current&&(this.thumbRef.current.removeEventListener("touchstart",this.onMouseDown,o.default?{passive:!1}:!1),this.thumbRef.current.removeEventListener("touchmove",this.onMouseMove,o.default?{passive:!1}:!1),this.thumbRef.current.removeEventListener("touchend",this.onMouseUp)),u.default.cancel(this.moveRaf)},onMouseDown(e){const{onStartMove:t}=this.$props;Object.assign(this.state,{dragging:!0,pageY:g(e),startTop:this.getTop()}),t(),this.patchEvents(),e.stopPropagation(),e.preventDefault()},onMouseMove(e){const{dragging:t,pageY:s,startTop:n}=this.state,{onScroll:a}=this.$props;if(u.default.cancel(this.moveRaf),t){const i=g(e)-s,l=n+i,f=this.getEnableScrollRange(),h=this.getEnableHeightRange(),d=h?l/h:0,v=Math.ceil(d*f);this.moveRaf=u.default(()=>{a(v)})}},onMouseUp(){const{onStopMove:e}=this.$props;this.state.dragging=!1,e(),this.removeEvents()},getSpinHeight(){const{height:e,scrollHeight:t}=this.$props;let s=e/t*100;return s=Math.max(s,m),s=Math.min(s,e/2),Math.floor(s)},getEnableScrollRange(){const{scrollHeight:e,height:t}=this.$props;return e-t||0},getEnableHeightRange(){const{height:e}=this.$props,t=this.getSpinHeight();return e-t||0},getTop(){const{scrollTop:e}=this.$props,t=this.getEnableScrollRange(),s=this.getEnableHeightRange();return e===0||t===0?0:e/t*s},showScroll(){const{height:e,scrollHeight:t}=this.$props;return t>e}},render(){const{dragging:e,visible:t}=this.state,{prefixCls:s}=this.$props,n=`${this.getSpinHeight()}px`,a=`${this.getTop()}px`,i=this.showScroll(),l=i&&t;return r.createVNode("div",{ref:this.scrollbarRef,class:c.default(`${s}-scrollbar`,{[`${s}-scrollbar-show`]:i}),style:{width:"8px",top:0,bottom:0,right:0,position:"absolute",display:l?void 0:"none"},onMousedown:this.onContainerMouseDown,onMousemove:this.delayHidden},[r.createVNode("div",{ref:this.thumbRef,class:c.default(`${s}-scrollbar-thumb`,{[`${s}-scrollbar-thumb-moving`]:e}),style:{width:"100%",height:n,top:a,left:0,position:"absolute",background:"rgba(0, 0, 0, 0.5)",borderRadius:"99px",cursor:"pointer",userSelect:"none"},onMousedown:this.onMouseDown},null)])}});exports.default=b;
