"use client"; /** * Copy text to the clipboard. * * `navigator.clipboard` only exists in a secure context, and Freezmo is often * used over plain http on a LAN, so fall back to the classic hidden-textarea * trick. Returns false when neither path works (the caller can then tell the * user to copy manually). */ export async function copyText(text: string): Promise { try { if (typeof navigator !== "undefined" && navigator.clipboard && window.isSecureContext) { await navigator.clipboard.writeText(text); return true; } } catch { /* fall through to the legacy path */ } try { const area = document.createElement("textarea"); area.value = text; area.setAttribute("readonly", ""); area.style.position = "fixed"; area.style.top = "0"; area.style.opacity = "0"; document.body.appendChild(area); area.focus(); area.select(); const ok = document.execCommand("copy"); area.remove(); return ok; } catch { return false; } }