import{A as K,aa as w,E as P,d as U,S as z,ah as q,V as x,a1 as G,a_ as L,j as y,X,bu as Q,be as W,ap as Z,bd as p,ar as ee,N as te}from"./index.3bfa6a0e.js";const[ae,f]=K("slider"),ne={min:w(0),max:w(100),step:w(1),range:Boolean,reverse:Boolean,disabled:Boolean,readonly:Boolean,vertical:Boolean,barHeight:P,buttonSize:P,activeColor:String,inactiveColor:String,modelValue:{type:[Number,Array],default:0}};var re=U({name:ae,props:ne,emits:["change","drag-end","drag-start","update:modelValue"],setup(t,{emit:b,slots:V}){let N,o,u;const S=z(),c=z(),g=q(),m=x(()=>Number(t.max)-Number(t.min)),_=x(()=>{const e=t.vertical?"width":"height";return{background:t.inactiveColor,[e]:G(t.barHeight)}}),s=e=>t.range&&Array.isArray(e),M=()=>{const{modelValue:e,min:a}=t;return s(e)?`${(e[1]-e[0])*100/m.value}%`:`${(e-Number(a))*100/m.value}%`},O=()=>{const{modelValue:e,min:a}=t;return s(e)?`${(e[0]-Number(a))*100/m.value}%`:"0%"},R=x(()=>{const a={[t.vertical?"height":"width"]:M(),background:t.activeColor};c.value&&(a.transition="none");const n=()=>t.vertical?t.reverse?"bottom":"top":t.reverse?"right":"left";return a[n()]=O(),a}),h=e=>{const a=+t.min,n=+t.max,i=+t.step;e=ee(e,a,n);const r=Math.round((e-a)/i)*i;return W(a,r)},A=(e,a)=>JSON.stringify(e)===JSON.stringify(a),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(h):e=h(e),A(e,t.modelValue)||b("update:modelValue",e),a&&!A(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=X(S),J=()=>i?n?l.bottom-e.clientY:e.clientY-l.top:n?l.right-e.clientX:e.clientX-l.left,j=i?l.height:l.width,v=Number(a)+J()/j*m.value;if(s(r)){const[T,k]=r,F=(T+k)/2;v<=F?d([v,k],!0):d([T,v],!0)}else d(v,!0)},D=e=>{t.disabled||t.readonly||(g.start(e),o=t.modelValue,s(o)?u=o.map(h):u=h(o),c.value="start")},E=e=>{if(t.disabled||t.readonly)return;c.value==="start"&&b("drag-start",e),Z(e,!0),g.move(e),c.value="dragging";const a=X(S),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-N:N;o[l]=u[l]+r}else o=u+r;d(o)},B=e=>{t.disabled||t.readonly||(c.value==="dragging"&&(d(o,!0),b("drag-end",e)),c.value="")},H=e=>typeof e=="number"?f("button-wrapper",["left","right"][e]):f("button-wrapper",t.reverse?"left":"right"),I=(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:p(t.buttonSize)},null)},C=e=>{const a=typeof e=="number"?t.modelValue[e]:t.modelValue;return y("div",{role:"slider",class:H(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",onTouchstart:n=>{typeof e=="number"&&(N=e),D(n)},onTouchmove:E,onTouchend:B,onTouchcancel:B,onClick:Q},[I(a,e)])};return d(t.modelValue),L(()=>t.modelValue),()=>y("div",{ref:S,style:_.value,class:f({vertical:t.vertical,disabled:t.disabled}),onClick:$},[y("div",{class:f("bar"),style:R.value},[t.range?[C(0),C(1)]:C()])])}});const le=te(re);export{le as S};
