1 |
- import{A as X,aa as c,G as g,E as h,d as J,S as D,V as f,a1 as F,bc as Q,a2 as w,a_ as Y,j as v,a5 as I,aE as y,a7 as A,aX as R,aM as k,L as z,W as Z,aO as p,ap as N,aB as ee,bd as te,N as ae}from"./index.e6d6174e.js";const[ne,S]=X("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=J({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=k(String(e),!t.integer),e=e===""?0:+e,e=Number.isNaN(e)?+a:e,e=Math.max(Math.min(+i,e),+a),z(l)&&(e=e.toFixed(+l))),e},G=()=>{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 x=D(),n=D(G()),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)})),E=f(()=>Q(t.buttonSize)),W=()=>{const e=o(n.value);P(e,n.value)||(n.value=e)},B=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));B(a),u(s)},$=e=>{const a=e.target,{value:i}=a,{decimalLength:b}=t;let l=k(String(i),!t.integer);if(z(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 U=l===String(+l);B(U?+l:l)},j=e=>{var a;t.disableInput?(a=x.value)==null||a.blur():u("focus",e)},q=e=>{const a=e.target,i=o(a.value);a.value=String(i),n.value=i,Z(()=>{u("blur",e),p()})};let V,m;const C=()=>{m=setTimeout(()=>{T(),C()},le)},H=()=>{t.longPress&&(V=!1,clearTimeout(m),m=setTimeout(()=>{V=!0,T(),C()},ie))},L=e=>{t.longPress&&(clearTimeout(m),V&&N(e))},K=e=>{t.disableInput&&N(e)},M=e=>({onClick:a=>{N(a),s=e,T()},onTouchstart:()=>{s=e,H()},onTouchend:L,onTouchcancel:L});return w(()=>[t.max,t.min,t.integer,t.decimalLength],W),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})}),Y(()=>t.modelValue),()=>v("div",{role:"group",class:S([t.theme])},[I(v("button",A({type:"button",style:E.value,class:[S("minus",{disabled:d.value}),{[R]:!d.value}],"aria-disabled":d.value||void 0},M("minus")),null),[[y,t.showMinus]]),I(v("input",{ref:x,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:q,onInput:$,onFocus:j,onMousedown:K},null),[[y,t.showInput]]),I(v("button",A({type:"button",style:E.value,class:[S("plus",{disabled:r.value}),{[R]:!r.value}],"aria-disabled":r.value||void 0},M("plus")),null),[[y,t.showPlus]])])}});const ce=ae(se);export{ce as S};
|