{"version":3,"file":"use-backtop.mjs","names":[],"sources":["../../../../../../packages/components/backtop/src/use-backtop.ts"],"sourcesContent":["import { onMounted, ref, shallowRef } from 'vue'\nimport { useEventListener, useThrottleFn } from '@vueuse/core'\nimport { throwError } from '@element-plus/utils'\n\nimport type { SetupContext } from 'vue'\nimport type { BacktopEmits, BacktopProps } from './backtop'\n\nexport const useBackTop = (\n  props: Required<BacktopProps>,\n  emit: SetupContext<BacktopEmits>['emit'],\n  componentName: string\n) => {\n  const el = shallowRef<HTMLElement>()\n  const container = shallowRef<Document | HTMLElement>()\n  const visible = ref(false)\n\n  const handleScroll = () => {\n    if (el.value) visible.value = el.value.scrollTop >= props.visibilityHeight\n  }\n\n  const handleClick = (event: MouseEvent) => {\n    el.value?.scrollTo({ top: 0, behavior: 'smooth' })\n    emit('click', event)\n  }\n\n  const handleScrollThrottled = useThrottleFn(handleScroll, 300, true)\n\n  useEventListener(container, 'scroll', handleScrollThrottled)\n  onMounted(() => {\n    container.value = document\n    el.value = document.documentElement\n\n    if (props.target) {\n      el.value = document.querySelector<HTMLElement>(props.target) ?? undefined\n      if (!el.value) {\n        throwError(componentName, `target does not exist: ${props.target}`)\n      }\n      container.value = el.value\n    }\n    // Give visible an initial value, fix #13066\n    handleScroll()\n  })\n\n  return {\n    visible,\n    handleClick,\n  }\n}\n"],"mappings":";;;;AAOA,MAAa,cACX,OACA,MACA,kBACG;CACH,MAAM,KAAK,YAAyB;CACpC,MAAM,YAAY,YAAoC;CACtD,MAAM,UAAU,IAAI,MAAM;CAE1B,MAAM,qBAAqB;EACzB,IAAI,GAAG,OAAO,QAAQ,QAAQ,GAAG,MAAM,aAAa,MAAM;;CAG5D,MAAM,eAAe,UAAsB;EACzC,GAAG,OAAO,SAAS;GAAE,KAAK;GAAG,UAAU;GAAU,CAAC;EAClD,KAAK,SAAS,MAAM;;CAKtB,iBAAiB,WAAW,UAFE,cAAc,cAAc,KAAK,KAEJ,CAAC;CAC5D,gBAAgB;EACd,UAAU,QAAQ;EAClB,GAAG,QAAQ,SAAS;EAEpB,IAAI,MAAM,QAAQ;GAChB,GAAG,QAAQ,SAAS,cAA2B,MAAM,OAAO,IAAI,KAAA;GAChE,IAAI,CAAC,GAAG,OACN,WAAW,eAAe,0BAA0B,MAAM,SAAS;GAErE,UAAU,QAAQ,GAAG;;EAGvB,cAAc;GACd;CAEF,OAAO;EACL;EACA;EACD"}