1 |
- import{G as U,ac as c,I as g,H as h,d as X,V as D,X as f,a3 as F,bd as Y,a4 as w,b0 as Z,j as v,a7 as I,aG as y,a9 as R,aZ as k,aO as z,N as A,Y as J,aQ as p,ar as N,aD as ee,be as te,P as ae}from"./index.c8a33855.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=X({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=z(String(e),!t.integer),e=e===""?0:+e,e=Number.isNaN(e)?+a:e,e=Math.max(Math.min(+i,e),+a),A(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)})),C=f(()=>Y(t.buttonSize)),H=()=>{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=z(String(i),!t.integer);if(A(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)},$=e=>{var a;t.disableInput?(a=x.value)==null||a.blur():u("focus",e)},j=e=>{const a=e.target,i=o(a.value);a.value=String(i),n.value=i,J(()=>{u("blur",e),p()})};let V,m;const B=()=>{m=setTimeout(()=>{T(),B()},le)},q=()=>{t.longPress&&(V=!1,clearTimeout(m),m=setTimeout(()=>{V=!0,T(),B()},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,q()},onTouchend:L,onTouchcancel:L});return w(()=>[t.max,t.min,t.integer,t.decimalLength],H),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})}),Z(()=>t.modelValue),()=>v("div",{role:"group",class:S([t.theme])},[I(v("button",R({type:"button",style:C.value,class:[S("minus",{disabled:d.value}),{[k]:!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:j,onInput:W,onFocus:$,onMousedown:K},null),[[y,t.showInput]]),I(v("button",R({type:"button",style:C.value,class:[S("plus",{disabled:r.value}),{[k]:!r.value}],"aria-disabled":r.value||void 0},M("plus")),null),[[y,t.showPlus]])])}});const ce=ae(se);export{ce as S};
|