import{t as O,d as W,R as w,aq as j,D as x,U as G,b5 as J,a0 as Q,c as y,z as B,E as z,aW as E,an as M,a4 as Z,bM as p,b6 as ee,b4 as te,aU as ae,x as ne}from"./index.8f93de0e.js";const[re,f]=O("slider"),ie={min:B(0),max:B(100),step:B(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 le=W({name:re,props:ie,emits:["change","dragEnd","dragStart","update:modelValue"],setup(t,{emit:b,slots:V}){let S,o,u;const N=w(),A=w(),c=w(),g=j(),m=x(()=>Number(t.max)-Number(t.min)),R=x(()=>{const e=t.vertical?"width":"height";return{background:t.inactiveColor,[e]:G(t.barHeight)}}),s=e=>t.range&&Array.isArray(e),D=()=>{const{modelValue:e,min:a}=t;return s(e)?`${(e[1]-e[0])*100/m.value}%`:`${(e-Number(a))*100/m.value}%`},U=()=>{const{modelValue:e,min:a}=t;return s(e)?`${(e[0]-Number(a))*100/m.value}%`:"0%"},X=x(()=>{const a={[t.vertical?"height":"width"]:D(),background:t.activeColor};c.value&&(a.transition="none");const n=()=>t.vertical?t.reverse?"bottom":"top":t.reverse?"right":"left";return a[n()]=U(),a}),v=e=>{const a=+t.min,n=+t.max,i=+t.step;e=ae(e,a,n);const r=Math.round((e-a)/i)*i;return ee(a,r)},Y=e=>{var a,n;const i=(a=e[0])!=null?a:Number(t.min),r=(n=e[1])!=null?n:Number(t.max);return i>r?[r,i]:[i,r]},d=(e,a)=>{s(e)?e=Y(e).map(v):e=v(e),E(e,t.modelValue)||b("update:modelValue",e),a&&!E(e,u)&&b("change",e)},_=e=>{if(e.stopPropagation(),t.disabled||t.readonly)return;const{min:a,reverse:n,vertical:i,modelValue:r}=t,l=M(N),F=()=>i?n?l.bottom-e.clientY:e.clientY-l.top:n?l.right-e.clientX:e.clientX-l.left,K=i?l.height:l.width,h=Number(a)+F()/K*m.value;if(s(r)){const[T,k]=r,L=(T+k)/2;h<=L?d([h,k],!0):d([T,h],!0)}else d(h,!0)},$=e=>{t.disabled||t.readonly||(g.start(e),o=t.modelValue,s(o)?u=o.map(v):u=v(o),c.value="start")},H=e=>{if(t.disabled||t.readonly)return;c.value==="start"&&b("dragStart",e),Z(e,!0),g.move(e),c.value="dragging";const a=M(N),n=t.vertical?g.deltaY.value:g.deltaX.value,i=t.vertical?a.height:a.width;let r=n/i*m.value;if(t.reverse&&(r=-r),s(u)){const l=t.reverse?1-S:S;o[l]=u[l]+r}else o=u+r;d(o)},P=e=>{t.disabled||t.readonly||(c.value==="dragging"&&(d(o,!0),b("dragEnd",e)),c.value="")},I=e=>typeof e=="number"?f("button-wrapper",["left","right"][e]):f("button-wrapper",t.reverse?"left":"right"),q=(e,a)=>{if(typeof a=="number"){const n=V[a===0?"left-button":"right-button"];if(n)return n({value:e})}return V.button?V.button({value:e}):y("div",{class:f("button"),style:te(t.buttonSize)},null)},C=e=>{const a=typeof e=="number"?t.modelValue[e]:t.modelValue;return y("div",{ref:A,role:"slider",class:I(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"&&(S=e),$(n)},onTouchend:P,onTouchcancel:P,onClick:p},[q(a,e)])};return d(t.modelValue),J(()=>t.modelValue),Q("touchmove",H,{target:A}),()=>y("div",{ref:N,style:R.value,class:f({vertical:t.vertical,disabled:t.disabled}),onClick:_},[y("div",{class:f("bar"),style:X.value},[t.range?[C(0),C(1)]:C()])])}});const ue=ne(le);export{ue as S};
