export async function writeClipboardText(text: string): Promise { if (navigator.clipboard?.writeText) { await navigator.clipboard.writeText(text); return; } const textarea = document.createElement('textarea'); textarea.value = text; textarea.setAttribute('readonly', 'true'); textarea.style.position = 'fixed'; textarea.style.top = '-1000px'; textarea.style.opacity = '0'; document.body.appendChild(textarea); textarea.select(); try { if (!document.execCommand('copy')) { throw new Error('copy failed'); } } finally { document.body.removeChild(textarea); } }