{"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    :style=\"{ '-webkit-line-clamp': lineClamp }\"\n  >\n    <slot />\n  </component>\n</template>\n\n<script lang=\"ts\" setup>\nimport { computed, onMounted, onUpdated, ref, useAttrs } from 'vue'\nimport { useNamespace } from '@element-plus/hooks'\nimport { useFormSize } from '@element-plus/components/form'\nimport { isUndefined } 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 bindTitle = () => {\n  const inheritTitle = useAttrs().title\n\n  if (inheritTitle) return\n  let shouldAddTitle = false\n  const text = textRef.value?.textContent || ''\n\n  if (props.truncated) {\n    const width = textRef.value?.offsetWidth\n    const scrollWidth = textRef.value?.scrollWidth\n    if (width && scrollWidth && scrollWidth > width) {\n      shouldAddTitle = 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      shouldAddTitle = true\n    }\n  }\n\n  if (shouldAddTitle) {\n    textRef.value?.setAttribute('title', text)\n  } else {\n    textRef.value?.removeAttribute('title')\n  }\n}\n\nonMounted(bindTitle)\nonUpdated(bindTitle)\n</script>\n"],"mappings":""}