index.7e7497a9.js 3.2 KB

1
  1. import{E as X,ab as c,H as f,G as g,d as J,U as F,W as h,a2 as D,be as Q,a3 as V,a$ as Y,j as v,a6 as I,aF as y,a8 as R,aU as k,aO as z,M as A,X as Z,aP as p,aq as x,aC as ee,bf as te,O as ae}from"./ResizeObserver.es.f28023e0.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:f,showMinus:f,showInput:f,longPress:f,allowEmpty:Boolean,modelValue:g,inputWidth:g,buttonSize:g,placeholder:String,disablePlus:Boolean,disableMinus:Boolean,disableInput:Boolean,beforeChange:Function,defaultValue:c(1),decimalLength:g};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=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},O=()=>{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=F(),n=F(O()),d=h(()=>t.disabled||t.disableMinus||n.value<=+t.min),r=h(()=>t.disabled||t.disablePlus||n.value>=+t.max),G=h(()=>({width:D(t.inputWidth),height:D(t.buttonSize)})),C=h(()=>Q(t.buttonSize)),U=()=>{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 K=l===String(+l);E(K?+l:l)},$=e=>{var a;t.disableInput?(a=N.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 w,m;const M=()=>{m=setTimeout(()=>{T(),M()},le)},H=()=>{t.longPress&&(w=!1,clearTimeout(m),m=setTimeout(()=>{w=!0,T(),M()},ie))},B=e=>{t.longPress&&(clearTimeout(m),w&&x(e))},j=e=>{t.disableInput&&x(e)},L=e=>({onClick:a=>{x(a),s=e,T()},onTouchstart:()=>{s=e,H()},onTouchend:B,onTouchcancel:B});return V(()=>[t.max,t.min,t.integer,t.decimalLength],U),V(()=>t.modelValue,e=>{P(e,n.value)||(n.value=o(e))}),V(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",R({type:"button",style:C.value,class:[S("minus",{disabled:d.value}),{[k]:!d.value}],"aria-disabled":d.value||void 0},L("minus")),null),[[y,t.showMinus]]),I(v("input",{ref:N,type:t.integer?"tel":"text",role:"spinbutton",class:S("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:q,onInput:W,onFocus:$,onMousedown:j},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},L("plus")),null),[[y,t.showPlus]])])}});const ce=ae(se);export{ce as S};