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

4f6e93dc34e3532b786888bc81623dda7cb2a25e
wotaku/docs/.vitepress/theme/composables/useTooltips.ts history · blame · raw

32 lines · 860 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 { getTooltip, type TooltipData } from 'virtual:tooltips'
 9import { ref } from 'vue'
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}