{"release_id":"01a1998d-9802-0000-b0f7-33a23307f4ed","chunk_id":"01a1998d-992f-7950-8953-be63e04cc0c0","file":"DOHdSWWf.mjs","mappings":"qTA6BO,SAASA,EAAYC,EAAuC,CAIlE,GAAI,OAAO,UAAc,KAAe,OAAO,UAAU,OAAU,WAClE,GAAI,CAEH,OAAO,UACL,MAAM,CAAE,IAAKA,EAAK,IAAK,MAAOA,EAAK,MAAO,KAAMA,EAAK,IAAA,CAAM,EAC3D,KAAK,IAAM,QAAuB,EAClC,MAAOC,GAIHA,GAAK,OAAS,aAAqB,SAGhCC,EAAgBF,EAAK,GAAG,CAC/B,CACH,MAAQ,CAEP,OAAOE,EAAgBF,EAAK,GAAG,CAChC,CAED,OAAOE,EAAgBF,EAAK,GAAG,CAChC,CAEA,eAAeE,EAAgBC,EAAmC,CACjE,GAAI,CACH,GAAI,OAAO,UAAc,KAAe,UAAU,WAAW,UAC5D,aAAM,UAAU,UAAU,UAAUA,CAAG,EAChC,QAET,MAAQ,CAER,CACA,MAAO,QACR","names":["shareOrCopy","opts","err","copyToClipboard","url"],"sources":["../../../../../../src/lib/share.ts"],"sourcesContent":["/**\n * RAT-272 follow-up: unified share-or-copy helper.\n *\n * Centralizes the Web Share API → clipboard fallback decision so every\n * share entry point (niche page, duel, rate result, beat, post deeplinks)\n * behaves consistently.\n *\n * IMPORTANT: this function must be called SYNCHRONOUSLY inside the click\n * handler. iOS Safari invalidates the user-activation token across any\n * preceding `await`, so the navigator.share call would silently be\n * rejected if the caller did any async work first. The function itself\n * returns a Promise the caller can ignore — the share UI opens\n * synchronously, the promise resolves once the user dismisses it.\n *\n * Returns:\n *   'shared'  — the native share sheet opened (user may still cancel)\n *   'copied'  — fallback path, link is on the clipboard\n *   'failed'  — neither worked (no clipboard support, user agent quirk)\n */\nexport type ShareResult = 'shared' | 'copied' | 'failed';\n\nexport interface ShareOpts {\n\turl: string;\n\t/** Optional title — Web Share API uses this in some target apps. */\n\ttitle?: string;\n\t/** Optional body text — included alongside the link in the share payload. */\n\ttext?: string;\n}\n\nexport function shareOrCopy(opts: ShareOpts): Promise<ShareResult> {\n\t// Browser support gate. canShare with a text-only payload is sometimes\n\t// rejected on macOS Safari (treats it as unsupported) so we attempt\n\t// navigator.share unconditionally and let it throw on failure.\n\tif (typeof navigator !== 'undefined' && typeof navigator.share === 'function') {\n\t\ttry {\n\t\t\t// SYNCHRONOUS call here — the activation chain carries through.\n\t\t\treturn navigator\n\t\t\t\t.share({ url: opts.url, title: opts.title, text: opts.text })\n\t\t\t\t.then(() => 'shared' as ShareResult)\n\t\t\t\t.catch((err) => {\n\t\t\t\t\t// AbortError = user cancelled. Treat as a successful share\n\t\t\t\t\t// from a UX standpoint — they SAW the sheet, they chose\n\t\t\t\t\t// not to send. Don't fall back to clipboard.\n\t\t\t\t\tif (err?.name === 'AbortError') return 'shared' as ShareResult;\n\t\t\t\t\t// Other failures (NotAllowedError, etc.) fall through to\n\t\t\t\t\t// clipboard so the link is still useful.\n\t\t\t\t\treturn copyToClipboard(opts.url);\n\t\t\t\t});\n\t\t} catch {\n\t\t\t// Synchronous throw — same fallback path.\n\t\t\treturn copyToClipboard(opts.url);\n\t\t}\n\t}\n\treturn copyToClipboard(opts.url);\n}\n\nasync function copyToClipboard(url: string): Promise<ShareResult> {\n\ttry {\n\t\tif (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) {\n\t\t\tawait navigator.clipboard.writeText(url);\n\t\t\treturn 'copied';\n\t\t}\n\t} catch {\n\t\t/* fall through */\n\t}\n\treturn 'failed';\n}\n"],"version":3}