import { vRepeatClick } from "./chunk-SMVFL2UA.js"; import { EVENT_CODE, getEventCode, getEventKey } from "./chunk-BUVJOKYK.js"; import { ElInput } from "./chunk-G7ZFAANB.js"; import { useLocale } from "./chunk-APPTXKCZ.js"; import { ElIcon } from "./chunk-3DJYPQW6.js"; import { CHANGE_EVENT, INPUT_EVENT, UPDATE_MODEL_EVENT, useAriaProps } from "./chunk-6VHTGKN7.js"; import { useFormItem } from "./chunk-DIGHH22S.js"; import { useFormDisabled, useFormSize, useSizeProp } from "./chunk-FYPMSKES.js"; import { debugWarn, isNumber, isUndefined, throwError } from "./chunk-UFIWN4M6.js"; import { _export_sfc } from "./chunk-MUJDDH7P.js"; import { buildProps, definePropType, isNil_default, useNamespace, withInstall } from "./chunk-R2OGZABH.js"; import { arrow_down_default, arrow_up_default, minus_default, plus_default } from "./chunk-3C23FNYW.js"; import { computed, createBlock, createCommentVNode, createElementBlock, createSlots, createVNode, defineComponent, onMounted, onUpdated, openBlock, reactive, ref, renderSlot, unref, watch, withCtx, withDirectives, withKeys, withModifiers } from "./chunk-AAHVYXXY.js"; import { init_shared_esm_bundler, isString, normalizeClass } from "./chunk-OWZYVOTZ.js"; // ../node_modules/.pnpm/element-plus@2.11.7_vue@3.5.24_typescript@5.9.3_/node_modules/element-plus/es/components/input-number/src/input-number.mjs var inputNumberProps = buildProps({ id: { type: String, default: void 0 }, step: { type: Number, default: 1 }, stepStrictly: Boolean, max: { type: Number, default: Number.MAX_SAFE_INTEGER }, min: { type: Number, default: Number.MIN_SAFE_INTEGER }, modelValue: { type: [Number, null] }, readonly: Boolean, disabled: Boolean, size: useSizeProp, controls: { type: Boolean, default: true }, controlsPosition: { type: String, default: "", values: ["", "right"] }, valueOnClear: { type: [String, Number, null], validator: (val) => val === null || isNumber(val) || ["min", "max"].includes(val), default: null }, name: String, placeholder: String, precision: { type: Number, validator: (val) => val >= 0 && val === Number.parseInt(`${val}`, 10) }, validateEvent: { type: Boolean, default: true }, ...useAriaProps(["ariaLabel"]), inputmode: { type: definePropType(String), default: void 0 }, align: { type: definePropType(String), default: "center" }, disabledScientific: Boolean }); var inputNumberEmits = { [CHANGE_EVENT]: (cur, prev) => prev !== cur, blur: (e) => e instanceof FocusEvent, focus: (e) => e instanceof FocusEvent, [INPUT_EVENT]: (val) => isNumber(val) || isNil_default(val), [UPDATE_MODEL_EVENT]: (val) => isNumber(val) || isNil_default(val) }; // ../node_modules/.pnpm/element-plus@2.11.7_vue@3.5.24_typescript@5.9.3_/node_modules/element-plus/es/components/input-number/src/input-number2.mjs init_shared_esm_bundler(); var __default__ = defineComponent({ name: "ElInputNumber" }); var _sfc_main = defineComponent({ ...__default__, props: inputNumberProps, emits: inputNumberEmits, setup(__props, { expose, emit }) { const props = __props; const { t } = useLocale(); const ns = useNamespace("input-number"); const input = ref(); const data = reactive({ currentValue: props.modelValue, userInput: null }); const { formItem } = useFormItem(); const minDisabled = computed(() => isNumber(props.modelValue) && props.modelValue <= props.min); const maxDisabled = computed(() => isNumber(props.modelValue) && props.modelValue >= props.max); const numPrecision = computed(() => { const stepPrecision = getPrecision(props.step); if (!isUndefined(props.precision)) { if (stepPrecision > props.precision) { debugWarn("InputNumber", "precision should not be less than the decimal places of step"); } return props.precision; } else { return Math.max(getPrecision(props.modelValue), stepPrecision); } }); const controlsAtRight = computed(() => { return props.controls && props.controlsPosition === "right"; }); const inputNumberSize = useFormSize(); const inputNumberDisabled = useFormDisabled(); const displayValue = computed(() => { if (data.userInput !== null) { return data.userInput; } let currentValue = data.currentValue; if (isNil_default(currentValue)) return ""; if (isNumber(currentValue)) { if (Number.isNaN(currentValue)) return ""; if (!isUndefined(props.precision)) { currentValue = currentValue.toFixed(props.precision); } } return currentValue; }); const toPrecision = (num, pre) => { if (isUndefined(pre)) pre = numPrecision.value; if (pre === 0) return Math.round(num); let snum = String(num); const pointPos = snum.indexOf("."); if (pointPos === -1) return num; const nums = snum.replace(".", "").split(""); const datum = nums[pointPos + pre]; if (!datum) return num; const length = snum.length; if (snum.charAt(length - 1) === "5") { snum = `${snum.slice(0, Math.max(0, length - 1))}6`; } return Number.parseFloat(Number(snum).toFixed(pre)); }; const getPrecision = (value) => { if (isNil_default(value)) return 0; const valueString = value.toString(); const dotPosition = valueString.indexOf("."); let precision = 0; if (dotPosition !== -1) { precision = valueString.length - dotPosition - 1; } return precision; }; const ensurePrecision = (val, coefficient = 1) => { if (!isNumber(val)) return data.currentValue; if (val >= Number.MAX_SAFE_INTEGER && coefficient === 1) { debugWarn("InputNumber", "The value has reached the maximum safe integer limit."); return val; } else if (val <= Number.MIN_SAFE_INTEGER && coefficient === -1) { debugWarn("InputNumber", "The value has reached the minimum safe integer limit."); return val; } return toPrecision(val + props.step * coefficient); }; const handleKeydown = (event) => { const code = getEventCode(event); const key = getEventKey(event); if (props.disabledScientific && ["e", "E"].includes(key)) { event.preventDefault(); return; } switch (code) { case EVENT_CODE.up: { event.preventDefault(); increase(); break; } case EVENT_CODE.down: { event.preventDefault(); decrease(); break; } } }; const increase = () => { if (props.readonly || inputNumberDisabled.value || maxDisabled.value) return; const value = Number(displayValue.value) || 0; const newVal = ensurePrecision(value); setCurrentValue(newVal); emit(INPUT_EVENT, data.currentValue); setCurrentValueToModelValue(); }; const decrease = () => { if (props.readonly || inputNumberDisabled.value || minDisabled.value) return; const value = Number(displayValue.value) || 0; const newVal = ensurePrecision(value, -1); setCurrentValue(newVal); emit(INPUT_EVENT, data.currentValue); setCurrentValueToModelValue(); }; const verifyValue = (value, update) => { const { max, min, step, precision, stepStrictly, valueOnClear } = props; if (max < min) { throwError("InputNumber", "min should not be greater than max."); } let newVal = Number(value); if (isNil_default(value) || Number.isNaN(newVal)) { return null; } if (value === "") { if (valueOnClear === null) { return null; } newVal = isString(valueOnClear) ? { min, max }[valueOnClear] : valueOnClear; } if (stepStrictly) { newVal = toPrecision(Math.round(toPrecision(newVal / step)) * step, precision); if (newVal !== value) { update && emit(UPDATE_MODEL_EVENT, newVal); } } if (!isUndefined(precision)) { newVal = toPrecision(newVal, precision); } if (newVal > max || newVal < min) { newVal = newVal > max ? max : min; update && emit(UPDATE_MODEL_EVENT, newVal); } return newVal; }; const setCurrentValue = (value, emitChange = true) => { var _a; const oldVal = data.currentValue; const newVal = verifyValue(value); if (!emitChange) { emit(UPDATE_MODEL_EVENT, newVal); return; } if (oldVal === newVal && value) return; data.userInput = null; emit(UPDATE_MODEL_EVENT, newVal); if (oldVal !== newVal) { emit(CHANGE_EVENT, newVal, oldVal); } if (props.validateEvent) { (_a = formItem == null ? void 0 : formItem.validate) == null ? void 0 : _a.call(formItem, "change").catch((err) => debugWarn(err)); } data.currentValue = newVal; }; const handleInput = (value) => { data.userInput = value; const newVal = value === "" ? null : Number(value); emit(INPUT_EVENT, newVal); setCurrentValue(newVal, false); }; const handleInputChange = (value) => { const newVal = value !== "" ? Number(value) : ""; if (isNumber(newVal) && !Number.isNaN(newVal) || value === "") { setCurrentValue(newVal); } setCurrentValueToModelValue(); data.userInput = null; }; const focus = () => { var _a, _b; (_b = (_a = input.value) == null ? void 0 : _a.focus) == null ? void 0 : _b.call(_a); }; const blur = () => { var _a, _b; (_b = (_a = input.value) == null ? void 0 : _a.blur) == null ? void 0 : _b.call(_a); }; const handleFocus = (event) => { emit("focus", event); }; const handleBlur = (event) => { var _a, _b; data.userInput = null; if (data.currentValue === null && ((_a = input.value) == null ? void 0 : _a.input)) { input.value.input.value = ""; } emit("blur", event); if (props.validateEvent) { (_b = formItem == null ? void 0 : formItem.validate) == null ? void 0 : _b.call(formItem, "blur").catch((err) => debugWarn(err)); } }; const setCurrentValueToModelValue = () => { if (data.currentValue !== props.modelValue) { data.currentValue = props.modelValue; } }; const handleWheel = (e) => { if (document.activeElement === e.target) e.preventDefault(); }; watch(() => props.modelValue, (value, oldValue) => { const newValue = verifyValue(value, true); if (data.userInput === null && newValue !== oldValue) { data.currentValue = newValue; } }, { immediate: true }); watch(() => props.precision, () => { data.currentValue = verifyValue(props.modelValue); }); onMounted(() => { var _a; const { min, max, modelValue } = props; const innerInput = (_a = input.value) == null ? void 0 : _a.input; innerInput.setAttribute("role", "spinbutton"); if (Number.isFinite(max)) { innerInput.setAttribute("aria-valuemax", String(max)); } else { innerInput.removeAttribute("aria-valuemax"); } if (Number.isFinite(min)) { innerInput.setAttribute("aria-valuemin", String(min)); } else { innerInput.removeAttribute("aria-valuemin"); } innerInput.setAttribute("aria-valuenow", data.currentValue || data.currentValue === 0 ? String(data.currentValue) : ""); innerInput.setAttribute("aria-disabled", String(inputNumberDisabled.value)); if (!isNumber(modelValue) && modelValue != null) { let val = Number(modelValue); if (Number.isNaN(val)) { val = null; } emit(UPDATE_MODEL_EVENT, val); } innerInput.addEventListener("wheel", handleWheel, { passive: false }); }); onUpdated(() => { var _a, _b; const innerInput = (_a = input.value) == null ? void 0 : _a.input; innerInput == null ? void 0 : innerInput.setAttribute("aria-valuenow", `${(_b = data.currentValue) != null ? _b : ""}`); }); expose({ focus, blur }); return (_ctx, _cache) => { return openBlock(), createElementBlock("div", { class: normalizeClass([ unref(ns).b(), unref(ns).m(unref(inputNumberSize)), unref(ns).is("disabled", unref(inputNumberDisabled)), unref(ns).is("without-controls", !_ctx.controls), unref(ns).is("controls-right", unref(controlsAtRight)), unref(ns).is(_ctx.align, !!_ctx.align) ]), onDragstart: withModifiers(() => { }, ["prevent"]) }, [ _ctx.controls ? withDirectives((openBlock(), createElementBlock("span", { key: 0, role: "button", "aria-label": unref(t)("el.inputNumber.decrease"), class: normalizeClass([unref(ns).e("decrease"), unref(ns).is("disabled", unref(minDisabled))]), onKeydown: withKeys(decrease, ["enter"]) }, [ renderSlot(_ctx.$slots, "decrease-icon", {}, () => [ createVNode(unref(ElIcon), null, { default: withCtx(() => [ unref(controlsAtRight) ? (openBlock(), createBlock(unref(arrow_down_default), { key: 0 })) : (openBlock(), createBlock(unref(minus_default), { key: 1 })) ]), _: 1 }) ]) ], 42, ["aria-label", "onKeydown"])), [ [unref(vRepeatClick), decrease] ]) : createCommentVNode("v-if", true), _ctx.controls ? withDirectives((openBlock(), createElementBlock("span", { key: 1, role: "button", "aria-label": unref(t)("el.inputNumber.increase"), class: normalizeClass([unref(ns).e("increase"), unref(ns).is("disabled", unref(maxDisabled))]), onKeydown: withKeys(increase, ["enter"]) }, [ renderSlot(_ctx.$slots, "increase-icon", {}, () => [ createVNode(unref(ElIcon), null, { default: withCtx(() => [ unref(controlsAtRight) ? (openBlock(), createBlock(unref(arrow_up_default), { key: 0 })) : (openBlock(), createBlock(unref(plus_default), { key: 1 })) ]), _: 1 }) ]) ], 42, ["aria-label", "onKeydown"])), [ [unref(vRepeatClick), increase] ]) : createCommentVNode("v-if", true), createVNode(unref(ElInput), { id: _ctx.id, ref_key: "input", ref: input, type: "number", step: _ctx.step, "model-value": unref(displayValue), placeholder: _ctx.placeholder, readonly: _ctx.readonly, disabled: unref(inputNumberDisabled), size: unref(inputNumberSize), max: _ctx.max, min: _ctx.min, name: _ctx.name, "aria-label": _ctx.ariaLabel, "validate-event": false, inputmode: _ctx.inputmode, onKeydown: handleKeydown, onBlur: handleBlur, onFocus: handleFocus, onInput: handleInput, onChange: handleInputChange }, createSlots({ _: 2 }, [ _ctx.$slots.prefix ? { name: "prefix", fn: withCtx(() => [ renderSlot(_ctx.$slots, "prefix") ]) } : void 0, _ctx.$slots.suffix ? { name: "suffix", fn: withCtx(() => [ renderSlot(_ctx.$slots, "suffix") ]) } : void 0 ]), 1032, ["id", "step", "model-value", "placeholder", "readonly", "disabled", "size", "max", "min", "name", "aria-label", "inputmode"]) ], 42, ["onDragstart"]); }; } }); var InputNumber = _export_sfc(_sfc_main, [["__file", "input-number.vue"]]); // ../node_modules/.pnpm/element-plus@2.11.7_vue@3.5.24_typescript@5.9.3_/node_modules/element-plus/es/components/input-number/index.mjs var ElInputNumber = withInstall(InputNumber); export { inputNumberProps, inputNumberEmits, ElInputNumber }; //# sourceMappingURL=chunk-QTR36KE6.js.map