import{c as q,b as w,n as z,d as G,r as V,u as J,e as B,o as Q,aa as W,a3 as Z,a as S,bF as I,a4 as M,p,s as ee,bO as te,aA as ae,a5 as ne,k as re}from"./index-7945cc5d.js";const[le,g]=q("slider"),ie={min:w(0),max:w(100),step:w(1),range:Boolean,reverse:Boolean,disabled:Boolean,readonly:Boolean,vertical:Boolean,barHeight:z,buttonSize:z,activeColor:String,inactiveColor:String,modelValue:{type:[Number,Array],default:0}};var oe=G({name:le,props:ie,emits:["change","dragEnd","dragStart","update:modelValue"],setup(t,{emit:b,slots:N}){let m,o,c;const C=V(),k=[V(),V()],u=V(),v=J(),f=B(()=>Number(t.max)-Number(t.min)),R=B(()=>{const e=t.vertical?"width":"height";return{background:t.inactiveColor,[e]:Q(t.barHeight)}}),s=e=>t.range&&Array.isArray(e),X=()=>{const{modelValue:e,min:a}=t;return s(e)?`${(e[1]-e[0])*100/f.value}%`:`${(e-Number(a))*100/f.value}%`},Y=()=>{const{modelValue:e,min:a}=t;return s(e)?`${(e[0]-Number(a))*100/f.value}%`:"0%"},_=B(()=>{const a={[t.vertical?"height":"width"]:X(),background:t.activeColor};u.value&&(a.transition="none");const n=()=>t.vertical?t.reverse?"bottom":"top":t.reverse?"right":"left";return a[n()]=Y(),a}),h=e=>{const a=+t.min,n=+t.max,l=+t.step;e=ne(e,a,n);const r=Math.round((e-a)/l)*l;return te(a,r)},x=()=>{const e=t.modelValue;s(e)?c=e.map(h):c=h(e)},$=e=>{var a,n;const l=(a=e[0])!=null?a:Number(t.min),r=(n=e[1])!=null?n:Number(t.max);return l>r?[r,l]:[l,r]},d=(e,a)=>{s(e)?e=$(e).map(h):e=h(e),I(e,t.modelValue)||b("update:modelValue",e),a&&!I(e,c)&&b("change",e)},D=e=>{if(e.stopPropagation(),t.disabled||t.readonly)return;x();const{min:a,reverse:n,vertical:l,modelValue:r}=t,i=M(C),L=()=>l?n?i.bottom-e.clientY:e.clientY-i.top:n?i.right-e.clientX:e.clientX-i.left,U=l?i.height:i.width,y=Number(a)+L()/U*f.value;if(s(r)){const[T,E]=r,j=(T+E)/2;y<=j?d([y,E],!0):d([T,y],!0)}else d(y,!0)},F=e=>{t.disabled||t.readonly||(v.start(e),o=t.modelValue,x(),u.value="start")},H=e=>{if(t.disabled||t.readonly)return;u.value==="start"&&b("dragStart",e),p(e,!0),v.move(e),u.value="dragging";const a=M(C),n=t.vertical?v.deltaY.value:v.deltaX.value,l=t.vertical?a.height:a.width;let r=n/l*f.value;if(t.reverse&&(r=-r),s(c)){const i=t.reverse?1-m:m;o[i]=c[i]+r}else o=c+r;d(o)},P=e=>{t.disabled||t.readonly||(u.value==="dragging"&&(d(o,!0),b("dragEnd",e)),u.value="")},O=e=>typeof e=="number"?g("button-wrapper",["left","right"][e]):g("button-wrapper",t.reverse?"left":"right"),K=(e,a)=>{const n=u.value==="dragging";if(typeof a=="number"){const l=N[a===0?"left-button":"right-button"];let r;if(n&&Array.isArray(o)&&(r=o[0]>o[1]?m^1:m),l)return l({value:e,dragging:n,dragIndex:r})}return N.button?N.button({value:e,dragging:n}):S("div",{class:g("button"),style:ae(t.buttonSize)},null)},A=e=>{const a=typeof e=="number"?t.modelValue[e]:t.modelValue;return S("div",{ref:k[e!=null?e:0],role:"slider",class:O(e),tabindex:t.disabled?void 0:0,"aria-valuemin":t.min,"aria-valuenow":a,"aria-valuemax":t.max,"aria-disabled":t.disabled||void 0,"aria-readonly":t.readonly||void 0,"aria-orientation":t.vertical?"vertical":"horizontal",onTouchstartPassive:n=>{typeof e=="number"&&(m=e),F(n)},onTouchend:P,onTouchcancel:P,onClick:ee},[K(a,e)])};return d(t.modelValue),W(()=>t.modelValue),k.forEach(e=>{Z("touchmove",H,{target:e})}),()=>S("div",{ref:C,style:R.value,class:g({vertical:t.vertical,disabled:t.disabled}),onClick:D},[S("div",{class:g("bar"),style:_.value},[t.range?[A(0),A(1)]:A()])])}});const ce=re(oe);export{ce as S};
