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

1ceece2a885aa51d2bc5874dec1d0861e6c7a0d9
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}