index-2641c427.js 3.2 KB

1
  1. import{c as J,b as c,t as d,n as f,d as Q,r as D,e as v,o as k,a_ as X,w as I,a2 as Y,a as S,g as x,v as y,h as z,H as R,bd as A,W,z as Z,be as p,p as N,$ as ee,bf as te,b5 as ae,k as ne}from"./index-74aaacd7.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=Q({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:g,allowEmpty:i,decimalLength:h}=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(+g,e),+l):e,W(h)&&(e=e.toFixed(+h))),e},$=()=>{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($()),r=v(()=>t.disabled||t.disableMinus||+n.value<=+t.min),m=v(()=>t.disabled||t.disablePlus||+n.value>=+t.max),G=v(()=>({width:k(t.inputWidth),height:k(t.buttonSize)})),E=v(()=>X(t.buttonSize)),H=()=>{const e=o(n.value);w(e,n.value)||(n.value=e)},_=e=>{t.beforeChange?ee(t.beforeChange,{args:[e],done(){n.value=e}}):n.value=e},T=()=>{if(s==="plus"&&m.value||s==="minus"&&r.value){u("overlimit",s);return}const e=s==="minus"?-t.step:+t.step,a=o(te(+n.value,e));_(a),u(s)},O=e=>{const a=e.target,{value:l}=a,{decimalLength:g}=t;let i=A(String(l),!t.integer);if(W(g)&&i.includes(".")){const F=i.split(".");i=`${F[0]}.${F[1].slice(0,+g)}`}t.beforeChange?a.value=String(n.value):w(l,i)||(a.value=i);const h=i===String(+i);_(h?+i:i)},q=e=>{var a;t.disableInput?(a=C.value)==null||a.blur():u("focus",e)},K=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 B=()=>{b=setTimeout(()=>{T(),B()},ie)},U=()=>{t.longPress&&(V=!1,clearTimeout(b),b=setTimeout(()=>{V=!0,T(),B()},ae))},L=e=>{t.longPress&&(clearTimeout(b),V&&N(e))},j=e=>{t.disableInput&&N(e)},M=e=>({onClick:a=>{N(a),s=e,T()},onTouchstartPassive:()=>{s=e,U()},onTouchend:L,onTouchcancel:L});return I(()=>[t.max,t.min,t.integer,t.decimalLength],H),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})}),Y(()=>t.modelValue),()=>S("div",{role:"group",class:P([t.theme])},[x(S("button",z({type:"button",style:E.value,class:[P("minus",{disabled:r.value}),{[R]:!r.value}],"aria-disabled":r.value||void 0},M("minus")),null),[[y,t.showMinus]]),x(S("input",{ref:C,type:t.integer?"tel":"text",role:"spinbutton",class:P("input"),value:n.value,style:G.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:K,onInput:O,onFocus:q,onMousedown:j},null),[[y,t.showInput]]),x(S("button",z({type:"button",style:E.value,class:[P("plus",{disabled:m.value}),{[R]:!m.value}],"aria-disabled":m.value||void 0},M("plus")),null),[[y,t.showPlus]])])}});const ce=ne(se);export{ce as S};