{"version":3,"file":"anchor-link2.mjs","names":[],"sources":["../../../../../../packages/components/anchor/src/anchor-link.vue"],"sourcesContent":["<template>\n  <div :class=\"ns.e('item')\">\n    <a ref=\"linkRef\" :class=\"cls\" :href=\"href\" @click=\"handleClick\">\n      <slot>{{ title }}</slot>\n    </a>\n    <div\n      v-if=\"$slots['sub-link'] && direction === 'vertical'\"\n      :class=\"ns.e('list')\"\n    >\n      <slot name=\"sub-link\" />\n    </div>\n  </div>\n</template>\n\n<script lang=\"ts\" setup>\nimport {\n  computed,\n  inject,\n  nextTick,\n  onBeforeUnmount,\n  onMounted,\n  ref,\n  watch,\n} from 'vue'\nimport { anchorKey } from './constants'\n\nimport type { AnchorLinkProps } from './anchor-link'\n\ndefineOptions({\n  name: 'ElAnchorLink',\n})\n\nconst props = withDefaults(defineProps<AnchorLinkProps>(), {\n  href: undefined,\n})\n\nconst linkRef = ref<HTMLElement | null>(null)\n\nconst {\n  ns,\n  direction,\n  currentAnchor,\n  addLink,\n  removeLink,\n  handleClick: contextHandleClick,\n} = inject(anchorKey)!\n\nconst cls = computed(() => [\n  ns.e('link'),\n  ns.is('active', currentAnchor.value === props.href),\n])\n\nconst handleClick = (e: MouseEvent) => {\n  contextHandleClick(e, props.href)\n}\n\nwatch(\n  () => props.href,\n  (val, oldVal) => {\n    nextTick(() => {\n      if (oldVal) removeLink(oldVal)\n      if (val) {\n        addLink({\n          href: val,\n          el: linkRef.value!,\n        })\n      }\n    })\n  }\n)\n\nonMounted(() => {\n  const { href } = props\n  if (href) {\n    addLink({\n      href,\n      el: linkRef.value!,\n    })\n  }\n})\n\nonBeforeUnmount(() => {\n  const { href } = props\n  if (href) {\n    removeLink(href)\n  }\n})\n</script>\n"],"mappings":""}