| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 | import { withDirectives as _withDirectives, createVNode as _createVNode, mergeProps as _mergeProps, vShow as _vShow } from "vue";import { ref, watch, computed, nextTick, defineComponent } from "vue";import { isDef, addUnit, addNumber, truthProp, resetScroll, numericProp, formatNumber, getSizeStyle, preventDefault, createNamespace, callInterceptor, makeNumericProp, HAPTICS_FEEDBACK } from "../utils/index.mjs";import { useCustomFieldValue } from "@vant/use";const [name, bem] = createNamespace("stepper");const LONG_PRESS_INTERVAL = 200;const LONG_PRESS_START_TIME = 600;const isEqual = (value1, value2) => String(value1) === String(value2);const stepperProps = {  min: makeNumericProp(1),  max: makeNumericProp(Infinity),  name: makeNumericProp(""),  step: makeNumericProp(1),  theme: String,  integer: Boolean,  disabled: Boolean,  showPlus: truthProp,  showMinus: truthProp,  showInput: truthProp,  longPress: truthProp,  allowEmpty: Boolean,  modelValue: numericProp,  inputWidth: numericProp,  buttonSize: numericProp,  placeholder: String,  disablePlus: Boolean,  disableMinus: Boolean,  disableInput: Boolean,  beforeChange: Function,  defaultValue: makeNumericProp(1),  decimalLength: numericProp};var stdin_default = defineComponent({  name,  props: stepperProps,  emits: ["plus", "blur", "minus", "focus", "change", "overlimit", "update:modelValue"],  setup(props, {    emit  }) {    const format = (value) => {      const {        min,        max,        allowEmpty,        decimalLength      } = props;      if (allowEmpty && value === "") {        return value;      }      value = formatNumber(String(value), !props.integer);      value = value === "" ? 0 : +value;      value = Number.isNaN(value) ? +min : value;      value = Math.max(Math.min(+max, value), +min);      if (isDef(decimalLength)) {        value = value.toFixed(+decimalLength);      }      return value;    };    const getInitialValue = () => {      var _a;      const defaultValue = (_a = props.modelValue) != null ? _a : props.defaultValue;      const value = format(defaultValue);      if (!isEqual(value, props.modelValue)) {        emit("update:modelValue", value);      }      return value;    };    let actionType;    const inputRef = ref();    const current = ref(getInitialValue());    const minusDisabled = computed(() => props.disabled || props.disableMinus || current.value <= +props.min);    const plusDisabled = computed(() => props.disabled || props.disablePlus || current.value >= +props.max);    const inputStyle = computed(() => ({      width: addUnit(props.inputWidth),      height: addUnit(props.buttonSize)    }));    const buttonStyle = computed(() => getSizeStyle(props.buttonSize));    const check = () => {      const value = format(current.value);      if (!isEqual(value, current.value)) {        current.value = value;      }    };    const setValue = (value) => {      if (props.beforeChange) {        callInterceptor(props.beforeChange, {          args: [value],          done() {            current.value = value;          }        });      } else {        current.value = value;      }    };    const onChange = () => {      if (actionType === "plus" && plusDisabled.value || actionType === "minus" && minusDisabled.value) {        emit("overlimit", actionType);        return;      }      const diff = actionType === "minus" ? -props.step : +props.step;      const value = format(addNumber(+current.value, diff));      setValue(value);      emit(actionType);    };    const onInput = (event) => {      const input = event.target;      const {        value      } = input;      const {        decimalLength      } = props;      let formatted = formatNumber(String(value), !props.integer);      if (isDef(decimalLength) && formatted.includes(".")) {        const pair = formatted.split(".");        formatted = `${pair[0]}.${pair[1].slice(0, +decimalLength)}`;      }      if (props.beforeChange) {        input.value = String(current.value);      } else if (!isEqual(value, formatted)) {        input.value = formatted;      }      const isNumeric = formatted === String(+formatted);      setValue(isNumeric ? +formatted : formatted);    };    const onFocus = (event) => {      var _a;      if (props.disableInput) {        (_a = inputRef.value) == null ? void 0 : _a.blur();      } else {        emit("focus", event);      }    };    const onBlur = (event) => {      const input = event.target;      const value = format(input.value);      input.value = String(value);      current.value = value;      nextTick(() => {        emit("blur", event);        resetScroll();      });    };    let isLongPress;    let longPressTimer;    const longPressStep = () => {      longPressTimer = setTimeout(() => {        onChange();        longPressStep();      }, LONG_PRESS_INTERVAL);    };    const onTouchStart = () => {      if (props.longPress) {        isLongPress = false;        clearTimeout(longPressTimer);        longPressTimer = setTimeout(() => {          isLongPress = true;          onChange();          longPressStep();        }, LONG_PRESS_START_TIME);      }    };    const onTouchEnd = (event) => {      if (props.longPress) {        clearTimeout(longPressTimer);        if (isLongPress) {          preventDefault(event);        }      }    };    const onMousedown = (event) => {      if (props.disableInput) {        preventDefault(event);      }    };    const createListeners = (type) => ({      onClick: (event) => {        preventDefault(event);        actionType = type;        onChange();      },      onTouchstartPassive: () => {        actionType = type;        onTouchStart();      },      onTouchend: onTouchEnd,      onTouchcancel: onTouchEnd    });    watch(() => [props.max, props.min, props.integer, props.decimalLength], check);    watch(() => props.modelValue, (value) => {      if (!isEqual(value, current.value)) {        current.value = format(value);      }    });    watch(current, (value) => {      emit("update:modelValue", value);      emit("change", value, {        name: props.name      });    });    useCustomFieldValue(() => props.modelValue);    return () => _createVNode("div", {      "role": "group",      "class": bem([props.theme])    }, [_withDirectives(_createVNode("button", _mergeProps({      "type": "button",      "style": buttonStyle.value,      "class": [bem("minus", {        disabled: minusDisabled.value      }), {        [HAPTICS_FEEDBACK]: !minusDisabled.value      }],      "aria-disabled": minusDisabled.value || void 0    }, createListeners("minus")), null), [[_vShow, props.showMinus]]), _withDirectives(_createVNode("input", {      "ref": inputRef,      "type": props.integer ? "tel" : "text",      "role": "spinbutton",      "class": bem("input"),      "value": current.value,      "style": inputStyle.value,      "disabled": props.disabled,      "readonly": props.disableInput,      "inputmode": props.integer ? "numeric" : "decimal",      "placeholder": props.placeholder,      "aria-valuemax": props.max,      "aria-valuemin": props.min,      "aria-valuenow": current.value,      "onBlur": onBlur,      "onInput": onInput,      "onFocus": onFocus,      "onMousedown": onMousedown    }, null), [[_vShow, props.showInput]]), _withDirectives(_createVNode("button", _mergeProps({      "type": "button",      "style": buttonStyle.value,      "class": [bem("plus", {        disabled: plusDisabled.value      }), {        [HAPTICS_FEEDBACK]: !plusDisabled.value      }],      "aria-disabled": plusDisabled.value || void 0    }, createListeners("plus")), null), [[_vShow, props.showPlus]])]);  }});export {  stdin_default as default};
 |