index-62c45bca.js 3.2 KB

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