{"version":3,"file":"share-card.js","names":["root","pageUrl","base","post","endpoint","data","native","copy","input","done","fallback","dl","cta"],"sources":["src/share-card.ts"],"sourcesContent":["(() => {\n  const root = document.querySelector<HTMLElement>('[data-share-page]');\n  if (!root) return;\n  const pageUrl = root.dataset.shareUrl || '';\n  const base = root.dataset.shareBase || '';\n  const post = (endpoint: string, data: Record<string, string>): void => {\n    fetch(`${base}/${endpoint}`, {\n      method: 'POST',\n      body: new URLSearchParams(data),\n      keepalive: true,\n    }).catch(() => { /* metrics are best effort */ });\n  };\n\n  const native = document.getElementById('share-native');\n  if (native && navigator.share) {\n    native.hidden = false;\n    native.addEventListener('click', () => {\n      // Record only when the sheet completes: dismissing it is not a share.\n      navigator.share({ url: pageUrl, title: document.title })\n        .then(() => post('share-action', { channel: 'native' }))\n        .catch(() => {});\n    });\n  }\n\n  const copy = document.getElementById('share-copy') as HTMLButtonElement | null;\n  const input = document.getElementById('share-url') as HTMLInputElement | null;\n  if (copy && input) {\n    const done = (): void => {\n      post('share-action', { channel: 'copy' });\n      copy.textContent = 'Copied!';\n      setTimeout(() => { copy.textContent = 'Copy Link'; }, 1500);\n    };\n    const fallback = (): void => {\n      input.focus();\n      input.select();\n      // execCommand signals failure by returning false, not by throwing;\n      // a failed copy is not a share action.\n      try {\n        if (document.execCommand('copy')) done();\n      } catch (_) { /* copy failed; nothing to record */ }\n    };\n    copy.addEventListener('click', () => {\n      if (navigator.clipboard && navigator.clipboard.writeText) {\n        navigator.clipboard.writeText(input.value).then(done, fallback);\n      } else {\n        fallback();\n      }\n    });\n  }\n\n  // Card and clip downloads both count as the download share action.\n  for (const dl of document.querySelectorAll<HTMLAnchorElement>('[data-share-download]')) {\n    dl.addEventListener('click', () => post('share-action', { channel: 'download' }));\n  }\n\n  for (const cta of document.querySelectorAll<HTMLAnchorElement>('[data-share-cta]')) {\n    cta.addEventListener('click', () => post('cta-click', { cta: cta.dataset.shareCta || '' }));\n  }\n})();\n"],"mappings":"C,gBAAO,CACL,IA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