You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
28 KiB

1 month ago
  1. {"ast":null,"code":"import { defineComponent, inject, ref, computed, markRaw, watch, openBlock, createElementBlock, unref, normalizeClass, normalizeStyle, Fragment, renderList, createVNode, withCtx, withDirectives, createBlock, resolveDynamicComponent, vShow, createCommentVNode, toDisplayString } from 'vue';\nimport { ElIcon } from '../../icon/index.mjs';\nimport { rateProps, rateEmits } from './rate.mjs';\nimport _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';\nimport { formContextKey, formItemContextKey } from '../../form/src/constants.mjs';\nimport { useFormSize } from '../../form/src/hooks/use-form-common-props.mjs';\nimport { useNamespace } from '../../../hooks/use-namespace/index.mjs';\nimport { useFormItemInputId } from '../../form/src/hooks/use-form-item.mjs';\nimport { isArray, isObject, isString } from '@vue/shared';\nimport { UPDATE_MODEL_EVENT } from '../../../constants/event.mjs';\nimport { EVENT_CODE } from '../../../constants/aria.mjs';\nimport { hasClass } from '../../../utils/dom/style.mjs';\nconst __default__ = defineComponent({\n name: \"ElRate\"\n});\nconst _sfc_main = /* @__PURE__ */defineComponent({\n ...__default__,\n props: rateProps,\n emits: rateEmits,\n setup(__props, {\n expose,\n emit\n }) {\n const props = __props;\n function getValueFromMap(value, map) {\n const isExcludedObject = val => isObject(val);\n const matchedKeys = Object.keys(map).map(key => +key).filter(key => {\n const val = map[key];\n const excluded = isExcludedObject(val) ? val.excluded : false;\n return excluded ? value < key : value <= key;\n }).sort((a, b) => a - b);\n const matchedValue = map[matchedKeys[0]];\n return isExcludedObject(matchedValue) && matchedValue.value || matchedValue;\n }\n const formContext = inject(formContextKey, void 0);\n const formItemContext = inject(formItemContextKey, void 0);\n const rateSize = useFormSize();\n const ns = useNamespace(\"rate\");\n const {\n inputId,\n isLabeledByFormItem\n } = useFormItemInputId(props, {\n formItemContext\n });\n const currentValue = ref(props.modelValue);\n const hoverIndex = ref(-1);\n const pointerAtLeftHalf = ref(true);\n const rateClasses = computed(() => [ns.b(), ns.m(rateSize.value)]);\n const rateDisabled = computed(() => props.disabled || (formContext == null ? void 0 : formContext.disabled));\n const rateStyles = computed(() => {\n return ns.cssVarBlock({\n \"void-color\": props.voidColor,\n \"disabled-void-color\": props.disabledVoidColor,\n \"fill-color\": activeColor.value\n });\n });\n const text = computed(() => {\n let result = \"\";\n if (props.showScore) {\n result = props.scoreTemplate.replace(/\\{\\s*value\\s*\\}/, rateDisabled.value ? `${props.modelValue}` : `${currentValue.value}`);\n } else if (props.showText) {\n result = props.texts[Math.ceil(currentValue.value) - 1];\n }\n return result;\n });\n const valueDecimal = computed(() => props.modelValue * 100 - Math.floor(props.modelValue) * 100);\n const colorMap = computed(() => isArray(props.colors) ? {\n [props.lowThreshold]: props.colors[0],\n [props.highThreshold]: {\n value: props.colors[1],\n excluded: true\n },\n [props.max]: props.colors[2]\n } : props.colors);\n const activeColor = computed(() => {\n const color = getValueFromMap(currentValue.value, colorMap.value);\n return isObject(color) ? \"\" : color;\n });\n const decimalStyle = computed(() => {\n let width = \"\";\n if (rateDisabled.value) {\n width = `${valueDecimal.value}%`;\n } else if (props.allowHalf) {\n width = \"50%\";\n }\n return {\n color: activeColor.value,\n width\n };\n });\n const componentMap = computed(() => {\n let icons = isArray(props.icons) ? [...props.icons] : {\n ...props.icons\n };\n icons = markRaw(icons);\n return isArray(icons) ?