{"version":3,"file":"index.cjs","sources":[""],"sourcesContent":["import { getDocument, getWindow } from \"ssr-window\";\n\nexport type TCopyToClipboardArgs = Parameters<typeof copyToClipboard>;\n\nexport type TCopyToClipboardReturn = ReturnType<typeof copyToClipboard>;\n\n/**\n * Copies text to the clipboard using the Clipboard API with a legacy fallback.\n * Returns `false` when clipboard access is unavailable or denied.\n * @param {string} text Text to copy\n * @returns {Promise<boolean>} Whether copying succeeded\n * @throws {TypeError} copyToClipboard: text must be a string\n * @example\n * await copyToClipboard(\"https://example.com\");\n * @example\n * // Copy a share URL and show feedback only when it succeeds\n * const copied = await copyToClipboard(window.location.href);\n * if (copied) showToast(\"Link copied\");\n */\nexport const copyToClipboard = async (text: string): Promise<boolean> => {\n  if (typeof text !== \"string\") {\n    throw new TypeError(\"copyToClipboard: text must be a string\");\n  }\n  if (typeof window === \"undefined\") {\n    return false;\n  }\n\n  try {\n    const clipboard = getWindow().navigator?.clipboard;\n    if (clipboard?.writeText) {\n      await clipboard.writeText(text);\n      return true;\n    }\n\n    const document = getDocument();\n    if (!document.body || typeof document.execCommand !== \"function\") {\n      return false;\n    }\n    const textarea = document.createElement(\"textarea\");\n    textarea.value = text;\n    textarea.setAttribute(\"readonly\", \"\");\n    textarea.style.position = \"fixed\";\n    textarea.style.opacity = \"0\";\n    document.body.append(textarea);\n    try {\n      textarea.select();\n      return document.execCommand(\"copy\");\n    } finally {\n      textarea.remove();\n    }\n  } catch {\n    return false;\n  }\n};\n"],"names":["copyToClipboard","async","text","TypeError","window","clipboard","getWindow","navigator","writeText","document","getDocument","body","execCommand","textarea","createElement","value","setAttribute","style","position","opacity","append","select","remove"],"mappings":"6FAmBO,MAAMA,gBAAkBC,aAC7B,UAAWC,OAAS,SAClB,MAAM,IAAIC,UAAU,0CAEtB,UAAWC,SAAW,YACpB,OAAO,MAGT,IACE,MAAMC,UAAYC,UAAAA,YAAYC,WAAWF,UACzC,GAAIA,WAAWG,UAAW,OAClBH,UAAUG,UAAUN,MAC1B,OAAO,IACT,CAEA,MAAMO,SAAWC,UAAAA,cACjB,IAAKD,SAASE,aAAeF,SAASG,cAAgB,WACpD,OAAO,MAET,MAAMC,SAAWJ,SAASK,cAAc,YACxCD,SAASE,MAAQb,KACjBW,SAASG,aAAa,WAAY,IAClCH,SAASI,MAAMC,SAAW,QAC1BL,SAASI,MAAME,QAAU,IACzBV,SAASE,KAAKS,OAAOP,UACrB,IACEA,SAASQ,SACT,OAAOZ,SAASG,YAAY,OAC9B,CAAC,QACCC,SAASS,QACX,CACF,CAAE,MACA,OAAO,KACT"}