{"version":3,"file":"use-title.mjs","sources":["../../../../../../packages/components/title/src/use-title.ts"],"sourcesContent":["import { useToggle } from '@vueuse/core'\nimport { onMounted } from 'vue'\nimport { getParentEl, getChildEl } from '@el-plus/utils'\nimport { ref, computed, useTemplateRef, type SetupContext } from 'vue'\nimport type { titleEmits } from './title'\nexport const useTitle = (emit: SetupContext<typeof titleEmits>['emit']) => {\n  const [value, toggle] = useToggle(true)\n  const expanded = value\n  const contentRef = useTemplateRef<HTMLElement>('contentRef')\n  onMounted(() => {\n    contentRef.value!.addEventListener('transitionend', (e) => {\n      if (e.propertyName === 'max-height') {\n        if (!expanded.value) {\n          // 收起动画结束后隐藏\n          contentRef.value!.style.display = 'none'\n        } else {\n          contentRef.value?.style.removeProperty('max-height')\n        }\n      }\n    })\n  })\n\n  const toggleState = (e: MouseEvent) => {\n    let contentHeight = getContentHeight(e.target as HTMLElement) + 'px'\n    if (expanded.value) {\n      contentRef.value!.style.maxHeight = contentHeight\n    } else {\n      contentRef.value?.style.removeProperty('display')\n      contentHeight = getContentHeight(e.target as HTMLElement) + 'px'\n    }\n    requestAnimationFrame(() => {\n      contentRef.value!.style.maxHeight = expanded.value ? '0' : contentHeight\n      toggle()\n      emit('toggle', expanded.value)\n    })\n  }\n  // 获取高度\n  const getContentHeight = (target: HTMLElement) => {\n    const parentEl = getParentEl(target, 'ep-title')!\n    const contentEl = getChildEl(parentEl, 'ep-title__content')\n    return contentEl?.scrollHeight || 0\n  }\n  return {\n    expanded,\n    toggleState,\n  }\n}\n"],"names":[],"mappings":";;;;AAKO,MAAM,QAAA,GAAW,CAAC,IAAA,KAAkD;AACzE,EAAA,MAAM,CAAC,KAAA,EAAO,MAAM,CAAA,GAAI,UAAU,IAAI,CAAA;AACtC,EAAA,MAAM,QAAA,GAAW,KAAA;AACjB,EAAA,MAAM,UAAA,GAAa,eAA4B,YAAY,CAAA;AAC3D,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,UAAA,CAAW,KAAA,CAAO,gBAA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