{"version":3,"file":"text2.mjs","names":[],"sources":["../../../../../../packages/components/text/src/text.vue"],"sourcesContent":["<template>\n  <component\n    :is=\"tag\"\n    ref=\"textRef\"\n    :class=\"textKls\"\n    :title=\"$attrs.title ?? (isTruncated ? textRef?.textContent : undefined)\"\n    :style=\"{ '-webkit-line-clamp': lineClamp }\"\n  >\n    <slot />\n  </component>\n</template>\n\n<script lang=\"ts\" setup>\nimport { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'\nimport { useElementSize, useMutationObserver } from '@vueuse/core'\nimport { useNamespace } from '@element-plus/hooks'\nimport { useFormSize } from '@element-plus/components/form'\nimport { cAF, isUndefined, rAF } from '@element-plus/utils'\n\nimport type { TextProps } from './text'\n\ndefineOptions({\n  name: 'ElText',\n})\n\nconst props = withDefaults(defineProps<TextProps>(), {\n  type: '',\n  size: '',\n  tag: 'span',\n})\nconst textRef = ref<HTMLElement>()\n\nconst textSize = useFormSize()\nconst ns = useNamespace('text')\n\nconst textKls = computed(() => [\n  ns.b(),\n  ns.m(props.type),\n  ns.m(textSize.value),\n  ns.is('truncated', props.truncated),\n  ns.is('line-clamp', !isUndefined(props.lineClamp)),\n])\n\nconst { width, height } = useElementSize(textRef)\nconst isTruncated = ref(false)\nlet rafId: number | undefined\n\nconst bindTitle = () => {\n  if (rafId) {\n    cAF(rafId)\n  }\n\n  rafId = rAF(() => {\n    rafId = undefined\n    isTruncated.value = false\n\n    if (props.truncated) {\n      const width = textRef.value?.offsetWidth\n      const scrollWidth = textRef.value?.scrollWidth\n      if (width && scrollWidth && scrollWidth > width) {\n        isTruncated.value = true\n      }\n    } else if (!isUndefined(props.lineClamp)) {\n      const height = textRef.value?.offsetHeight\n      const scrollHeight = textRef.value?.scrollHeight\n      if (height && scrollHeight && scrollHeight > height) {\n        isTruncated.value = true\n      }\n    }\n  })\n}\n\nwatch(\n  () => [width.value, height.value, props.truncated, props.lineClamp],\n  bindTitle,\n  { flush: 'post' }\n)\n\nuseMutationObserver(textRef, bindTitle, {\n  attributes: true,\n  attributeFilter: ['class', 'style'],\n  subtree: true,\n  childList: true,\n  characterData: true,\n})\n\nonMounted(bindTitle)\nonBeforeUnmount(() => {\n  if (rafId) {\n    cAF(rafId)\n  }\n})\n\ndefineExpose({\n  /** @description whether the text is truncated */\n  isTruncated,\n})\n</script>\n"],"mappings":""}