/** * Copy text to clipboard with execCommand fallback for older browsers. * Returns true on success. */ export async function copyToClipboard(text: string): Promise { if (navigator.clipboard) { try { await navigator.clipboard.writeText(text); return true; } catch { // Clipboard API failed — fall through to fallback } } // Fallback: hidden textarea + execCommand const ta = document.createElement("textarea"); ta.value = text; ta.style.position = "fixed"; ta.style.left = "-9999px"; document.body.appendChild(ta); ta.select(); const ok = document.execCommand("copy"); document.body.removeChild(ta); return ok; }