import { iconPropType } from "./chunk-R665FMDM.js"; import { ElIcon, addUnit } from "./chunk-3DJYPQW6.js"; import { CHANGE_EVENT, INPUT_EVENT, UPDATE_MODEL_EVENT, useAriaProps } from "./chunk-6VHTGKN7.js"; import { useFormItem, useFormItemInputId } from "./chunk-DIGHH22S.js"; import { useFormDisabled, useFormSize } from "./chunk-FYPMSKES.js"; import { componentSizes, debugWarn, isBoolean, isNumber, throwError } from "./chunk-UFIWN4M6.js"; import { _export_sfc } from "./chunk-MUJDDH7P.js"; import { buildProps, definePropType, useNamespace, withInstall } from "./chunk-R2OGZABH.js"; import { loading_default } from "./chunk-3C23FNYW.js"; import { computed, createBaseVNode, createBlock, createCommentVNode, createElementBlock, createVNode, defineComponent, nextTick, onMounted, openBlock, ref, renderSlot, resolveDynamicComponent, shallowRef, unref, watch, withCtx, withKeys, withModifiers } from "./chunk-AAHVYXXY.js"; import { init_shared_esm_bundler, isPromise, isString, normalizeClass, normalizeStyle, toDisplayString } 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/utils/vue/validator.mjs var isValidComponentSize = (val) => ["", ...componentSizes].includes(val); // ../node_modules/.pnpm/element-plus@2.11.7_vue@3.5.24_typescript@5.9.3_/node_modules/element-plus/es/components/switch/src/switch.mjs init_shared_esm_bundler(); var switchProps = buildProps({ modelValue: { type: [Boolean, String, Number], default: false }, disabled: Boolean, loading: Boolean, size: { type: String, validator: isValidComponentSize }, width: { type: [String, Number], default: "" }, inlinePrompt: Boolean, inactiveActionIcon: { type: iconPropType }, activeActionIcon: { type: iconPropType }, activeIcon: { type: iconPropType }, inactiveIcon: { type: iconPropType }, activeText: { type: String, default: "" }, inactiveText: { type: String, default: "" }, activeValue: { type: [Boolean, String, Number], default: true }, inactiveValue: { type: [Boolean, String, Number], default: false }, name: { type: String, default: "" }, validateEvent: { type: Boolean, default: true }, beforeChange: { type: definePropType(Function) }, id: String, tabindex: { type: [String, Number] }, ...useAriaProps(["ariaLabel"]) }); var switchEmits = { [UPDATE_MODEL_EVENT]: (val) => isBoolean(val) || isString(val) || isNumber(val), [CHANGE_EVENT]: (val) => isBoolean(val) || isString(val) || isNumber(val), [INPUT_EVENT]: (val) => isBoolean(val) || isString(val) || isNumber(val) }; // ../node_modules/.pnpm/element-plus@2.11.7_vue@3.5.24_typescript@5.9.3_/node_modules/element-plus/es/components/switch/src/switch2.mjs init_shared_esm_bundler(); var COMPONENT_NAME = "ElSwitch"; var __default__ = defineComponent({ name: COMPONENT_NAME }); var _sfc_main = defineComponent({ ...__default__, props: switchProps, emits: switchEmits, setup(__props, { expose, emit }) { const props = __props; const { formItem } = useFormItem(); const switchSize = useFormSize(); const ns = useNamespace("switch"); const { inputId } = useFormItemInputId(props, { formItemContext: formItem }); const switchDisabled = useFormDisabled(computed(() => props.loading)); const isControlled = ref(props.modelValue !== false); const input = shallowRef(); const switchKls = computed(() => [ ns.b(), ns.m(switchSize.value), ns.is("disabled", switchDisabled.value), ns.is("checked", checked.value) ]); const labelLeftKls = computed(() => [ ns.e("label"), ns.em("label", "left"), ns.is("active", !checked.value) ]); const labelRightKls = computed(() => [ ns.e("label"), ns.em("label", "right"), ns.is("active", checked.value) ]); const coreStyle = computed(() => ({ width: addUnit(props.width) })); watch(() => props.modelValue, () => { isControlled.value = true; }); const actualValue = computed(() => { return isControlled.value ? props.modelValue : false; }); const checked = computed(() => actualValue.value === props.activeValue); if (![props.activeValue, props.inactiveValue].includes(actualValue.value)) { emit(UPDATE_MODEL_EVENT, props.inactiveValue); emit(CHANGE_EVENT, props.inactiveValue); emit(INPUT_EVENT, props.inactiveValue); } watch(checked, (val) => { var _a; input.value.checked = val; if (props.validateEvent) { (_a = formItem == null ? void 0 : formItem.validate) == null ? void 0 : _a.call(formItem, "change").catch((err) => debugWarn(err)); } }); const handleChange = () => { const val = checked.value ? props.inactiveValue : props.activeValue; emit(UPDATE_MODEL_EVENT, val); emit(CHANGE_EVENT, val); emit(INPUT_EVENT, val); nextTick(() => { input.value.checked = checked.value; }); }; const switchValue = () => { if (switchDisabled.value) return; const { beforeChange } = props; if (!beforeChange) { handleChange(); return; } const shouldChange = beforeChange(); const isPromiseOrBool = [ isPromise(shouldChange), isBoolean(shouldChange) ].includes(true); if (!isPromiseOrBool) { throwError(COMPONENT_NAME, "beforeChange must return type `Promise` or `boolean`"); } if (isPromise(shouldChange)) { shouldChange.then((result) => { if (result) { handleChange(); } }).catch((e) => { debugWarn(COMPONENT_NAME, `some error occurred: ${e}`); }); } else if (shouldChange) { handleChange(); } }; const focus = () => { var _a, _b; (_b = (_a = input.value) == null ? void 0 : _a.focus) == null ? void 0 : _b.call(_a); }; onMounted(() => { input.value.checked = checked.value; }); expose({ focus, checked }); return (_ctx, _cache) => { return openBlock(), createElementBlock("div", { class: normalizeClass(unref(switchKls)), onClick: withModifiers(switchValue, ["prevent"]) }, [ createBaseVNode("input", { id: unref(inputId), ref_key: "input", ref: input, class: normalizeClass(unref(ns).e("input")), type: "checkbox", role: "switch", "aria-checked": unref(checked), "aria-disabled": unref(switchDisabled), "aria-label": _ctx.ariaLabel, name: _ctx.name, "true-value": _ctx.activeValue, "false-value": _ctx.inactiveValue, disabled: unref(switchDisabled), tabindex: _ctx.tabindex, onChange: handleChange, onKeydown: withKeys(switchValue, ["enter"]) }, null, 42, ["id", "aria-checked", "aria-disabled", "aria-label", "name", "true-value", "false-value", "disabled", "tabindex", "onKeydown"]), !_ctx.inlinePrompt && (_ctx.inactiveIcon || _ctx.inactiveText) ? (openBlock(), createElementBlock("span", { key: 0, class: normalizeClass(unref(labelLeftKls)) }, [ _ctx.inactiveIcon ? (openBlock(), createBlock(unref(ElIcon), { key: 0 }, { default: withCtx(() => [ (openBlock(), createBlock(resolveDynamicComponent(_ctx.inactiveIcon))) ]), _: 1 })) : createCommentVNode("v-if", true), !_ctx.inactiveIcon && _ctx.inactiveText ? (openBlock(), createElementBlock("span", { key: 1, "aria-hidden": unref(checked) }, toDisplayString(_ctx.inactiveText), 9, ["aria-hidden"])) : createCommentVNode("v-if", true) ], 2)) : createCommentVNode("v-if", true), createBaseVNode("span", { class: normalizeClass(unref(ns).e("core")), style: normalizeStyle(unref(coreStyle)) }, [ _ctx.inlinePrompt ? (openBlock(), createElementBlock("div", { key: 0, class: normalizeClass(unref(ns).e("inner")) }, [ _ctx.activeIcon || _ctx.inactiveIcon ? (openBlock(), createBlock(unref(ElIcon), { key: 0, class: normalizeClass(unref(ns).is("icon")) }, { default: withCtx(() => [ (openBlock(), createBlock(resolveDynamicComponent(unref(checked) ? _ctx.activeIcon : _ctx.inactiveIcon))) ]), _: 1 }, 8, ["class"])) : _ctx.activeText || _ctx.inactiveText ? (openBlock(), createElementBlock("span", { key: 1, class: normalizeClass(unref(ns).is("text")), "aria-hidden": !unref(checked) }, toDisplayString(unref(checked) ? _ctx.activeText : _ctx.inactiveText), 11, ["aria-hidden"])) : createCommentVNode("v-if", true) ], 2)) : createCommentVNode("v-if", true), createBaseVNode("div", { class: normalizeClass(unref(ns).e("action")) }, [ _ctx.loading ? (openBlock(), createBlock(unref(ElIcon), { key: 0, class: normalizeClass(unref(ns).is("loading")) }, { default: withCtx(() => [ createVNode(unref(loading_default)) ]), _: 1 }, 8, ["class"])) : unref(checked) ? renderSlot(_ctx.$slots, "active-action", { key: 1 }, () => [ _ctx.activeActionIcon ? (openBlock(), createBlock(unref(ElIcon), { key: 0 }, { default: withCtx(() => [ (openBlock(), createBlock(resolveDynamicComponent(_ctx.activeActionIcon))) ]), _: 1 })) : createCommentVNode("v-if", true) ]) : !unref(checked) ? renderSlot(_ctx.$slots, "inactive-action", { key: 2 }, () => [ _ctx.inactiveActionIcon ? (openBlock(), createBlock(unref(ElIcon), { key: 0 }, { default: withCtx(() => [ (openBlock(), createBlock(resolveDynamicComponent(_ctx.inactiveActionIcon))) ]), _: 1 })) : createCommentVNode("v-if", true) ]) : createCommentVNode("v-if", true) ], 2) ], 6), !_ctx.inlinePrompt && (_ctx.activeIcon || _ctx.activeText) ? (openBlock(), createElementBlock("span", { key: 1, class: normalizeClass(unref(labelRightKls)) }, [ _ctx.activeIcon ? (openBlock(), createBlock(unref(ElIcon), { key: 0 }, { default: withCtx(() => [ (openBlock(), createBlock(resolveDynamicComponent(_ctx.activeIcon))) ]), _: 1 })) : createCommentVNode("v-if", true), !_ctx.activeIcon && _ctx.activeText ? (openBlock(), createElementBlock("span", { key: 1, "aria-hidden": !unref(checked) }, toDisplayString(_ctx.activeText), 9, ["aria-hidden"])) : createCommentVNode("v-if", true) ], 2)) : createCommentVNode("v-if", true) ], 10, ["onClick"]); }; } }); var Switch = _export_sfc(_sfc_main, [["__file", "switch.vue"]]); // ../node_modules/.pnpm/element-plus@2.11.7_vue@3.5.24_typescript@5.9.3_/node_modules/element-plus/es/components/switch/index.mjs var ElSwitch = withInstall(Switch); export { isValidComponentSize, switchProps, switchEmits, ElSwitch }; //# sourceMappingURL=chunk-D6CONENK.js.map