{"version":3,"file":"root2.js","sources":["../../../../../../packages/components/tooltip-v2/src/root.vue"],"sourcesContent":["<template>\n  <slot :open=\"open\" />\n</template>\n\n<script setup lang=\"ts\">\nimport {\n  computed,\n  onBeforeUnmount,\n  onMounted,\n  provide,\n  ref,\n  unref,\n  watch,\n} from 'vue'\nimport { useTimeoutFn } from '@vueuse/core'\nimport { useId, useNamespace } from '@element-plus/hooks'\nimport { isNumber, isPropAbsent } from '@element-plus/utils'\nimport { TOOLTIP_V2_OPEN, tooltipV2RootKey } from './constants'\nimport { tooltipV2RootProps } from './root'\n\ndefineOptions({\n  name: 'ElTooltipV2Root',\n})\n\nconst props = defineProps(tooltipV2RootProps)\n\n/**\n * internal open state, when no model value was provided, use this as indicator instead\n */\nconst _open = ref(props.defaultOpen)\nconst triggerRef = ref<HTMLElement | null>(null)\n\nconst open = computed<boolean>({\n  get: () => (isPropAbsent(props.open) ? _open.value : props.open),\n  set: (open) => {\n    _open.value = open\n    props['onUpdate:open']?.(open)\n  },\n})\n\nconst isOpenDelayed = computed(\n  () => isNumber(props.delayDuration) && props.delayDuration > 0\n)\n\nconst { start: onDelayedOpen, stop: clearTimer } = useTimeoutFn(\n  () => {\n    open.value = true\n  },\n  computed(() => props.delayDuration),\n  {\n    immediate: false,\n  }\n)\n\nconst ns = useNamespace('tooltip-v2')\n\nconst contentId = useId()\n\nconst onNormalOpen = () => {\n  clearTimer()\n  open.value = true\n}\n\nconst onDelayOpen = () => {\n  unref(isOpenDelayed) ? onDelayedOpen() : onNormalOpen()\n}\n\nconst onOpen = onNormalOpen\n\nconst onClose = () => {\n  clearTimer()\n  open.value = false\n}\n\nconst onChange = (open: boolean) => {\n  if (open) {\n    document.dispatchEvent(new CustomEvent(TOOLTIP_V2_OPEN))\n    onOpen()\n  }\n\n  props.onOpenChange?.(open)\n}\n\nwatch(open, onChange)\n\nonMounted(() => {\n  // Keeps only 1 tooltip open at a time\n  document.addEventListener(TOOLTIP_V2_OPEN, onClose)\n})\n\nonBeforeUnmount(() => {\n  clearTimer()\n  document.removeEventListener(TOOLTIP_V2_OPEN, onClose)\n})\n\nprovide(tooltipV2RootKey, {\n  contentId,\n  triggerRef,\n  ns,\n\n  onClose,\n  onDelayOpen,\n  onOpen,\n})\n\ndefineExpose({\n  /**\n   * @description open tooltip programmatically\n   */\n  onOpen,\n\n  /**\n   * @description close tooltip programmatically\n   */\n  onClose,\n})\n</script>\n"],"names":["ref","computed","isPropAbsent","isNumber","useTimeoutFn","unref","TOOLTIP_V2_OPEN","watch","onMounted","onBeforeUnmount","provide","tooltipV2RootKey"],"mappings":";;;;;;;;;;;;;;;uCAoBc,CAAA;AAAA,EACZ,IAAM,EAAA,iBAAA;AACR,CAAA,CAAA,CAAA;;;;;;AAOA,IAAM,MAAA,KAAA,GAAQA,OAAI,CAAA,KAAA,CAAM,WAAW,CAAA,CAAA;AACnC,IAAM,MAAA,UAAA,GAAaA,QAAwB,IAAI,CAAA,CAAA;AAE/C,IAAA,MAAM,OAAOC,YAAkB,CAAA;AAAA,MAC7B,GAAA,EAAK,MAAOC,kBAAa,CAAA,KAAA,CAAM,IAAI,CAAI,GAAA,KAAA,CAAM,QAAQ,KAAM,CAAA,IAAA;AAAA,MAC3D,GAAA,EAAK,CAAC,KAAS,KAAA;AACb,QAAA,IAAA,EAAM,CAAQ;AACd,QAAA,KAAA,CAAM;AAAuB,QAC/B,CAAA,EAAA,GAAA,KAAA,CAAA,eAAA,CAAA,KAAA,IAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,IAAA,CAAA,KAAA,EAAA,KAAA,CAAA,CAAA;AAAA,OACD;AAED,KAAM,CAAA,CAAA;AAIN,IAAA,MAAM,aAAS,GAAAD,YAAe,CAAM,MAAAE,cAAA,CAAA,KAAe,cAC3C,CAAA,IAAA,KAAA,CAAA,aAAA,GAAA,CAAA,CAAA,CAAA;AACJ,IAAA,MAAA,EAAa,KAAA,EAAA,aAAA,EAAA,IAAA,EAAA,UAAA,EAAA,GAAAC,iBAA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