import { ref } from "vue"; /** * Clipboard helper with a 1.5s "copied" flash for the UI. * * const { copy, copied } = useCopy(); * copy("hello"); // → fires navigator.clipboard.writeText * // copied.value flips to true for 1500ms */ export function useCopy(flashMs = 1500) { const copied = ref(false); let timeoutId: ReturnType | undefined; async function copy(text: string): Promise { try { if (typeof navigator !== "undefined" && navigator.clipboard?.writeText) { await navigator.clipboard.writeText(text); } copied.value = true; if (timeoutId) clearTimeout(timeoutId); timeoutId = setTimeout(() => { copied.value = false; }, flashMs); } catch { // Clipboard may be unavailable (iframe, insecure context, denied // permission). Silently fail — the chip just won't flash. } } return { copy, copied }; }