import{defineComponent as F,createVNode as T}from"vue";import k from"../../_util/BaseMixin.mjs";import{hasProp as H}from"../../_util/props-util/index.mjs";import o from"../../_util/vue-types/index.mjs";import L from"./common/Track.mjs";import N from"./common/createSlider.mjs";import{ensureValueInRange as O,ensureValuePrecision as M,getKeyboardValueMutator as A,pauseEvent as m,isValueOutOfRange as E}from"./utils.mjs";const w=F({compatConfig:{MODE:3},name:"Slider",mixins:[k],inheritAttrs:!1,props:{defaultValue:Number,value:Number,disabled:{type:Boolean,default:void 0},autofocus:{type:Boolean,default:void 0},tabindex:o.oneOfType([o.number,o.string]),reverse:{type:Boolean,default:void 0},min:Number,max:Number,ariaLabelForHandle:String,ariaLabelledByForHandle:String,ariaValueTextFormatterForHandle:String,startPoint:Number},emits:["beforeChange","afterChange","change"],data(){const e=this.defaultValue!==void 0?this.defaultValue:this.min,t=this.value!==void 0?this.value:e;return{sValue:this.trimAlignValue(t),dragging:!1}},watch:{value:{handler(e){this.setChangeValue(e)},deep:!0},min(){const{sValue:e}=this;this.setChangeValue(e)},max(){const{sValue:e}=this;this.setChangeValue(e)}},methods:{setChangeValue(e){const t=e!==void 0?e:this.sValue,a=this.trimAlignValue(t,this.$props);a!==this.sValue&&(this.setState({sValue:a}),E(t,this.$props)&&this.$emit("change",a))},onChange(e){const t=!H(this,"value"),a=e.sValue>this.max?{...e,sValue:this.max}:e;t&&this.setState(a);const s=a.sValue;this.$emit("change",s)},onStart(e){this.setState({dragging:!0});const{sValue:t}=this;this.$emit("beforeChange",t);const a=this.calcValueByPos(e);this.startValue=a,this.startPosition=e,a!==t&&(this.prevMovedHandleIndex=0,this.onChange({sValue:a}))},onEnd(e){const{dragging:t}=this;this.removeDocumentEvents(),(t||e)&&this.$emit("afterChange",this.sValue),this.setState({dragging:!1})},onMove(e,t){m(e);const{sValue:a}=this,s=this.calcValueByPos(t);s!==a&&this.onChange({sValue:s})},onKeyboard(e){const{reverse:t,vertical:a}=this.$props,s=A(e,a,t);if(s){m(e);const{sValue:i}=this,r=s(i,this.$props),n=this.trimAlignValue(r);if(n===i)return;this.onChange({sValue:n}),this.$emit("afterChange",n),this.onEnd()}},getLowerBound(){const e=this.$props.startPoint||this.$props.min;return this.$data.sValue>e?e:this.$data.sValue},getUpperBound(){return this.$data.sValue<this.$props.startPoint?this.$props.startPoint:this.$data.sValue},trimAlignValue(e,t={}){if(e===null)return null;const a={...this.$props,...t},s=O(e,a);return M(s,a)},getTrack({prefixCls:e,reverse:t,vertical:a,included:s,minimumTrackStyle:i,mergedTrackStyle:r,length:n,offset:l}){return T(L,{class:`${e}-track`,vertical:a,included:s,offset:l,reverse:t,length:n,style:{...i,...r}},null)},renderSlider(){const{prefixCls:e,vertical:t,included:a,disabled:s,minimumTrackStyle:i,trackStyle:r,handleStyle:n,tabindex:l,ariaLabelForHandle:g,ariaLabelledByForHandle:V,ariaValueTextFormatterForHandle:p,min:v,max:b,startPoint:u,reverse:h,handle:$,defaultHandle:x}=this,y=$||x,{sValue:d,dragging:S}=this,c=this.calcOffset(d),C=y({class:`${e}-handle`,prefixCls:e,vertical:t,offset:c,value:d,dragging:S,disabled:s,min:v,max:b,reverse:h,index:0,tabindex:l,ariaLabel:g,ariaLabelledBy:V,ariaValueTextFormatter:p,style:n[0]||n,ref:P=>this.saveHandle(0,P),onFocus:this.onFocus,onBlur:this.onBlur}),f=u!==void 0?this.calcOffset(u):0,B=r[0]||r;return{tracks:this.getTrack({prefixCls:e,reverse:h,vertical:t,included:a,offset:f,minimumTrackStyle:i,mergedTrackStyle:B,length:c-f}),handles:C}}}}),q=N(w);export{q as default};
