import{E as q,ab as w,G as P,d as F,U as z,ai as G,W as x,a2 as K,bf as W,j as y,Y as O,bu as L,bg as Q,aq as Z,be as p,as as ee,O as te}from"./ResizeObserver.es.b7226882.js";const[ae,f]=q("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=F({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=G(),m=x(()=>Number(t.max)-Number(t.min)),Y=x(()=>{const e=t.vertical?"width":"height";return{background:t.inactiveColor,[e]:K(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}%`},R=()=>{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"]:M(),background:t.activeColor};c.value&&(a.transition="none");const n=()=>t.vertical?t.reverse?"bottom":"top":t.reverse?"right":"left";return a[n()]=R(),a}),v=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 Q(a,r)},B=(e,a)=>JSON.stringify(e)===JSON.stringify(a),_=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=_(e).map(v):e=v(e),B(e,t.modelValue)||b("update:modelValue",e),a&&!B(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=O(S),J=()=>i?n?l.bottom-e.clientY:e.clientY-l.top:n?l.right-e.clientX:e.clientX-l.left,U=i?l.height:l.width,h=Number(a)+J()/U*m.value;if(s(r)){const[A,k]=r,j=(A+k)/2;h<=j?d([h,k],!0):d([A,h],!0)}else d(h,!0)},D=e=>{t.disabled||t.readonly||(g.start(e),o=t.modelValue,s(o)?u=o.map(v):u=v(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=O(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)},T=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:T,onTouchcancel:T,onClick:L},[I(a,e)])};return d(t.modelValue),W(()=>t.modelValue),()=>y("div",{ref:S,style:Y.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 le=te(re);export{le as S};