docs/.vitepress/theme/composables/useTooltips.ts

4784f323dc1fdc3d63022069d9d0854676395960
wotaku/docs/.vitepress/theme/composables/useTooltips.ts

32 lines · 854 bytes

 1/**
 2*  All Rights Reserved
 3*
 4*  Copyright (c) 2025 taskylizard
 5*
 6*  All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
 7*/
 8import { ref } from 'vue'
 9import { getTooltip, type TooltipData } from 'virtual:tooltips'
10
11const tooltipCache = ref<Map<string, TooltipData>>(new Map())
12
13export function useTooltips() {
14  const getTooltipData = (id: string): TooltipData | null => {
15    if (tooltipCache.value.has(id)) {
16      return tooltipCache.value.get(id)!
17    }
18
19    const tooltip = getTooltip(id)
20    if (tooltip) {
21      tooltipCache.value.set(id, tooltip)
22      return tooltip
23    }
24
25    console.warn(`Tooltip with id "${id}" not found`)
26    return null
27  }
28
29  return {
30    getTooltipData
31  }
32}