import { asClipboardError, CLIPBOARD_CODES, ClipboardError, } from "../errors/errors.js"; import type { ClipboardResult } from "../types/clipboard.types.js"; /** * Stage a hidden textarea for the `execCommand` fallback. Off-screen and * non-interactive so it can never steal focus visibly. Caller is * responsible for removing it via the returned cleanup. */ function stageTextarea(value: string): { textarea: HTMLTextAreaElement; cleanup: () => void; } { const textarea = document.createElement("textarea"); textarea.value = value; textarea.setAttribute("aria-hidden", "true"); textarea.style.position = "fixed"; textarea.style.left = "-9999px"; textarea.style.top = "-9999px"; textarea.style.opacity = "0"; document.body.appendChild(textarea); textarea.select(); return { textarea, cleanup: (): void => { textarea.remove(); }, }; } /** * Copy `text` via the legacy `