import { inject, type InjectionKey, type Ref, type ComputedRef } from "vue"; export type TabsKey = string | number; export interface TabBox { x: number; y: number; width: number; height: number; } export interface TabsContext { selected: ComputedRef; keyboardActivation: ComputedRef<"automatic" | "manual">; select: (value: TabsKey) => void; orientation: ComputedRef<"horizontal" | "vertical">; variant: ComputedRef<"primary" | "secondary">; dir: ComputedRef<"ltr" | "rtl">; disabled: (key: TabsKey) => boolean; domId: (kind: "tab" | "panel", key: TabsKey) => string; panels: Ref>; list: Ref; elements: Map; boxes: Ref>; ready: Ref; measure: () => void; } export const tabsKey: InjectionKey = Symbol("hv-tabs"); export function useTabs() { const ctx = inject(tabsKey); if (!ctx) throw new Error("Tabs parts require Tabs."); return ctx; } export const tabKey: InjectionKey> = Symbol("hv-tab"); export function useTabKey() { const value = inject(tabKey); if (!value) throw new Error("TabsIndicator requires TabsTab."); return value; } // An empty string is reserved for no selection. Encode user keys so Reka is // always controlled, even when an empty/disabled collection initially has no key. export function tabsWireKey(key: TabsKey | undefined): string { return key === undefined ? "" : `${typeof key === "number" ? "n" : "s"}:${key}`; }