/** * Copies text to the clipboard using the async Clipboard API, falling back to * the legacy ``execCommand("copy")`` path for older browsers / insecure * contexts. * * @param {string} text - The text to copy to the clipboard. * @return {Promise} True when the copy succeeded, false otherwise. */ export async function copyToClipboard(text: string): Promise { try { await navigator.clipboard.writeText(text); return true; } catch { const textarea = document.createElement('textarea'); textarea.value = text; textarea.style.position = 'fixed'; textarea.style.opacity = '0'; document.body.appendChild(textarea); textarea.select(); try { document.execCommand('copy'); return true; } catch { return false; } finally { document.body.removeChild(textarea); } } }