"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue");require("../config-provider/index.js");const T=require("./hooks/use-track.js"),P=require("./style/index.js"),p=require("./utils/index.js"),$=require("../config-provider/hooks/use-namespace.js"),q=e.defineComponent({__name:"internal",props:{direction:{default:"vertical"},scroll:{default:0},barLength:{default:35},width:{},barColor:{},trackColor:{},trackWidth:{},disabled:{type:Boolean,default:!1},showTrack:{type:Boolean,default:!0},trackSpeed:{default:2},onScrollStart:{},onScroll:{},onScrollEnd:{}},setup(r,{expose:y}){const n=r,b=e.shallowRef(),i=e.shallowRef(),a=e.shallowRef(),{b:R,e:k,m:E,em:s,cssVar:L}=$.useNamespace("scroll-bar"),C=P.default("scroll-bar"),l=e.ref(n.scroll),{handleMouseDown:v}=T.useTrack({currentScroll:l,track:i,bar:a,type:e.toRef(n,"direction"),trackSpeed:e.toRef(n,"trackSpeed"),barLength:e.toRef(n,"barLength"),disabled:e.toRef(n,"disabled"),onDown:t=>{n.onScrollStart?.(t)},onUp:t=>{n.onScrollEnd?.(t)},onScroll:t=>{n.onScroll?.(t)}});e.watch(()=>n.scroll,t=>{l.value=t}),e.watchEffect(()=>{if(!e.unref(a))return;const t=`${(100-n.barLength)*l.value/n.barLength}%`,o=`${n.barLength}%`;n.direction==="vertical"?(a.value.style.height=o,a.value.style.transform=`translate3d(0, ${t}, 0)`):(a.value.style.width=o,a.value.style.transform=`translate3d(${t}, 0, 0)`)});let h,u,d;function M(t){if(n.disabled||t.button!==0)return;t.preventDefault(),t.stopPropagation();const o=e.unref(i),c=e.unref(a);if(!o||!c)return;document.addEventListener("pointermove",m),document.addEventListener("pointerup",g);const f=o.getBoundingClientRect(),S=c.getBoundingClientRect();n.direction==="vertical"?(h=f.height,u=S.top-f.top,d=t.clientY):(h=f.width,u=S.left-f.left,d=t.clientX),n.onScrollStart?.(e.unref(l))}function m(t){t.stopPropagation(),t.preventDefault();let o;n.direction==="vertical"?o=u+t.clientY-d:o=u+t.clientX-d;const c=o/h/(100-n.barLength)*1e4;l.value=p.ensureRangeValue(c),n.onScroll?.(e.unref(l))}function g(t){t.preventDefault(),document.removeEventListener("pointermove",m),document.removeEventListener("pointerup",g),n.onScrollEnd?.(e.unref(l))}function w(t){t.cancelable&&(t.stopPropagation(),t.preventDefault())}function D(t){Math.abs(e.unref(l)-t)<=.001||(l.value=p.ensureRangeValue(t))}return y({currentScroll:l,container:b,bar:a,track:i,scroll:D}),(t,o)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"container",ref:b,class:e.normalizeClass([e.unref(R)(),e.unref(E)(r.direction),e.unref(C)]),style:e.normalizeStyle(e.unref(L)({"bar-color":r.barColor,"track-color":r.trackColor,"bar-width":r.width?`${r.width}px`:void 0,"track-width":r.trackWidth?`${r.trackWidth}px`:void 0},!1))},[e.createElementVNode("div",{ref_key:"track",ref:i,class:e.normalizeClass([e.unref(k)("track"),r.disabled?e.unref(s)("track","disabled"):null,r.showTrack?null:e.unref(s)("track","hidden")]),onPointerdown:o[0]||(o[0]=(...c)=>e.unref(v)&&e.unref(v)(...c)),onTouchstart:w},null,34),e.createElementVNode("div",{ref_key:"bar",ref:a,class:e.normalizeClass([e.unref(k)("bar"),e.unref(s)("bar",r.direction),r.disabled?e.unref(s)("bar","disabled"):null]),onPointerdown:M,onTouchstart:w},null,34)],6))}});exports.default=q;
