{"version":3,"file":"share-or-download.cjs","names":[],"sources":["../../src/share/share-or-download.ts"],"sourcesContent":["import { share } from \"./share\";\n\n/** Options for {@link shareOrDownloadBlob}. */\nexport interface ShareOrDownloadOptions {\n    /** Title passed to the Web Share dialog. Defaults to the file name. */\n    title?: string;\n}\n\n/**\n * Try the Web Share API with the given `Blob` as a file; fall back to a\n * download anchor when the browser cannot share files (desktop Firefox, older\n * iOS Safari, etc.).\n *\n * A companion to {@link share} for the common \"export a generated artifact\"\n * flow: on mobile it opens the native share sheet, and everywhere else it\n * triggers a plain download. Returns early when the user shares or cancels the\n * dialog; otherwise it downloads.\n *\n * @param blob - The binary payload to share or download.\n * @param fileName - The file name presented to the user.\n * @param options - Optional `title` for the share dialog.\n * @returns A promise that resolves once the share or download completes.\n *\n * @example\n * const zip = new Blob([bytes], { type: \"application/zip\" });\n * await shareOrDownloadBlob(zip, \"export.zip\");\n */\nexport async function shareOrDownloadBlob(\n    blob: Blob,\n    fileName: string,\n    options: ShareOrDownloadOptions = {},\n): Promise<void> {\n    const file = new File([blob], fileName, { type: blob.type });\n    const result = await share({ title: options.title ?? fileName, files: [file] });\n    if (result.shared || result.cancelled) return;\n\n    const url = URL.createObjectURL(blob);\n    const anchor = document.createElement(\"a\");\n    anchor.href = url;\n    anchor.download = fileName;\n    document.body.appendChild(anchor);\n    anchor.click();\n    anchor.remove();\n    URL.revokeObjectURL(url);\n}\n"],"mappings":"+BA2BA,eAAsB,EAClB,EACA,EACA,EAAkC,CAAC,EACtB,CACb,IAAM,EAAO,IAAI,KAAK,CAAC,CAAI,EAAG,EAAU,CAAE,KAAM,EAAK,IAAK,CAAC,EACrD,EAAS,MAAM,EAAA,MAAM,CAAE,MAAO,EAAQ,OAAS,EAAU,MAAO,CAAC,CAAI,CAAE,CAAC,EAC9E,GAAI,EAAO,QAAU,EAAO,UAAW,OAEvC,IAAM,EAAM,IAAI,gBAAgB,CAAI,EAC9B,EAAS,SAAS,cAAc,GAAG,EACzC,EAAO,KAAO,EACd,EAAO,SAAW,EAClB,SAAS,KAAK,YAAY,CAAM,EAChC,EAAO,MAAM,EACb,EAAO,OAAO,EACd,IAAI,gBAAgB,CAAG,CAC3B"}