import{x as U,a6 as c,z as g,y as h,d as Z,O as D,Q as f,Y as F,bc as j,Z as w,aY as J,i as v,a1 as I,aA as x,a3 as z,aV as A,aK as R,I as k,S as X,aM as p,al as y,ax as ee,bd as te,K as ae}from"./index.afa1b71c.js";const[ne,S]=U("stepper"),le=200,ie=600,P=(t,u)=>String(t)===String(u),ue={min:c(1),max:c(1/0),name:c(""),step:c(1),theme:String,integer:Boolean,disabled:Boolean,showPlus:g,showMinus:g,showInput:g,longPress:g,allowEmpty:Boolean,modelValue:h,inputWidth:h,buttonSize:h,placeholder:String,disablePlus:Boolean,disableMinus:Boolean,disableInput:Boolean,beforeChange:Function,defaultValue:c(1),decimalLength:h};var se=Z({name:ne,props:ue,emits:["plus","blur","minus","focus","change","overlimit","update:modelValue"],setup(t,{emit:u}){const o=e=>{const{min:a,max:i,allowEmpty:b,decimalLength:l}=t;return b&&e===""||(e=R(String(e),!t.integer),e=e===""?0:+e,e=Number.isNaN(e)?+a:e,e=Math.max(Math.min(+i,e),+a),k(l)&&(e=e.toFixed(+l))),e},K=()=>{var e;const a=(e=t.modelValue)!=null?e:t.defaultValue,i=o(a);return P(i,t.modelValue)||u("update:modelValue",i),i};let s;const N=D(),n=D(K()),d=f(()=>t.disabled||t.disableMinus||n.value<=+t.min),r=f(()=>t.disabled||t.disablePlus||n.value>=+t.max),O=f(()=>({width:F(t.inputWidth),height:F(t.buttonSize)})),C=f(()=>j(t.buttonSize)),G=()=>{const e=o(n.value);P(e,n.value)||(n.value=e)},E=e=>{t.beforeChange?ee(t.beforeChange,{args:[e],done(){n.value=e}}):n.value=e},T=()=>{if(s==="plus"&&r.value||s==="minus"&&d.value){u("overlimit",s);return}const e=s==="minus"?-t.step:+t.step,a=o(te(+n.value,e));E(a),u(s)},W=e=>{const a=e.target,{value:i}=a,{decimalLength:b}=t;let l=R(String(i),!t.integer);if(k(b)&&l.includes(".")){const _=l.split(".");l=`${_[0]}.${_[1].slice(0,+b)}`}t.beforeChange?a.value=String(n.value):P(i,l)||(a.value=l);const Q=l===String(+l);E(Q?+l:l)},Y=e=>{var a;t.disableInput?(a=N.value)==null||a.blur():u("focus",e)},$=e=>{const a=e.target,i=o(a.value);a.value=String(i),n.value=i,X(()=>{u("blur",e),p()})};let V,m;const M=()=>{m=setTimeout(()=>{T(),M()},le)},q=()=>{t.longPress&&(V=!1,clearTimeout(m),m=setTimeout(()=>{V=!0,T(),M()},ie))},B=e=>{t.longPress&&(clearTimeout(m),V&&y(e))},H=e=>{t.disableInput&&y(e)},L=e=>({onClick:a=>{y(a),s=e,T()},onTouchstart:()=>{s=e,q()},onTouchend:B,onTouchcancel:B});return w(()=>[t.max,t.min,t.integer,t.decimalLength],G),w(()=>t.modelValue,e=>{P(e,n.value)||(n.value=o(e))}),w(n,e=>{u("update:modelValue",e),u("change",e,{name:t.name})}),J(()=>t.modelValue),()=>v("div",{role:"group",class:S([t.theme])},[I(v("button",z({type:"button",style:C.value,class:[S("minus",{disabled:d.value}),{[A]:!d.value}],"aria-disabled":d.value||void 0},L("minus")),null),[[x,t.showMinus]]),I(v("input",{ref:N,type:t.integer?"tel":"text",role:"spinbutton",class:S("input"),value:n.value,style:O.value,disabled:t.disabled,readonly:t.disableInput,inputmode:t.integer?"numeric":"decimal",placeholder:t.placeholder,"aria-valuemax":t.max,"aria-valuemin":t.min,"aria-valuenow":n.value,onBlur:$,onInput:W,onFocus:Y,onMousedown:H},null),[[x,t.showInput]]),I(v("button",z({type:"button",style:C.value,class:[S("plus",{disabled:r.value}),{[A]:!r.value}],"aria-disabled":r.value||void 0},L("plus")),null),[[x,t.showPlus]])])}});const ce=ae(se);export{ce as S};
