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,EACC,CACDS,EAASR,EAAeC,EAAUF,CAAM,EAAGW,EAAO,SAAUE,EAAOb,CAAM,CAC1E,CAGO,SAASgB,EACfd,EACAW,EACAb,EACC,CACDS,EAASN,EAAcD,EAAUF,CAAM,EAAG,qBAAsB,cAAea,EAAOb,CAAM,CAC7F,CAEO,SAASiB,EAAWZ,EAAcM,EAAeE,EAA4B,CACnFJ,EAASL,EAAcC,CAAI,EAAGM,EAAO,eAAgBE,CAAK,CAC3D","names":["SCULPT_SHARE_UTM","CLASH_SHARE_UTM","DUET_SHARE_UTM","mediumOf","source","sculptShareUrl","nickname","duetInviteUrl","clashShareUrl","code","relayoutAfterSheet","x","y","shareUrl","url","title","contentType","toast","trackShare","shareSculpt","shareDuetInvite","shareClash"],"sources":["../../../../../../src/lib/sculpt/share.ts"],"sourcesContent":["// Sharing a sculpt link (/sculpt/[nickname]) or a clash link (/sculpt/clash/[code]). Call these straight\n// from the tap handler, before any await: iOS Safari drops user activation across an await and\n// navigator.share then rejects. Touch: the share sheet. Desktop: copy the link.\n// RAT-653: every shared link carries a utm_source, so a visit from it is attributable in PostHog, and\n// every share is captured as `share` (content_type sculpt / sculpt_clash / sculpt_duet). RAT-685: an\n// invite's utm_medium says where it was sent from (a picker, or the end of a test round).\n\nimport { trackShare } from '$lib/analytics';\n\n/** A shared sculpt is an invite: its page's \"Clash with mine\" plays before any sign-up. */\nexport const SCULPT_SHARE_UTM = 'clash_invite';\nexport const CLASH_SHARE_UTM = 'clash_share';\n/** RAT-685: straight into a duet with the sharer's sculpt, no account needed. */\nexport const DUET_SHARE_UTM = 'duet_invite';\n\n/** Where an invite started: the editor's share, a picker's link, or the end of a round against a\n *  built-in. */\nexport type InviteSource =\n\t| 'editor'\n\t| 'share_sheet'\n\t| 'clash_picker'\n\t| 'scissor_picker'\n\t| 'duet_picker'\n\t| 'test_clash'\n\t| 'test_scissor'\n\t| 'test_duet';\nconst mediumOf = (source?: InviteSource) =>\n\t!source\n\t\t? ''\n\t\t: source.endsWith('_picker')\n\t\t\t? '&utm_medium=picker'\n\t\t\t: source.startsWith('test_')\n\t\t\t\t? '&utm_medium=test_result'\n\t\t\t\t: '';\n\nexport const sculptShareUrl = (nickname: string, source?: InviteSource) =>\n\t`${location.origin}/sculpt/${encodeURIComponent(nickname)}?utm_source=${SCULPT_SHARE_UTM}${mediumOf(source)}`;\n\nexport const duetInviteUrl = (nickname: string, source?: InviteSource) =>\n\t`${location.origin}/sculpt/duet?with=${encodeURIComponent(nickname)}&utm_source=${DUET_SHARE_UTM}${mediumOf(source)}`;\n\nexport const clashShareUrl = (code: string) =>\n\t`${location.origin}/sculpt/clash/${encodeURIComponent(code)}?utm_source=${CLASH_SHARE_UTM}`;\n\n/** RAT-672: on iOS, closing the native share sheet (a tap beside it) can leave the fixed site nav\n *  stranded mid-page and the bottom nav gone, even after scrolling: WebKit keeps the layout viewport\n *  the sheet left behind. A one-pixel scroll there and back, once the sheet is gone, makes it place\n *  fixed elements again. Invisible: both moves land in the same frame. */\nfunction relayoutAfterSheet() {\n\trequestAnimationFrame(() => {\n\t\tconst x = window.scrollX;\n\t\tconst y = window.scrollY;\n\t\twindow.scrollTo(x, y + 1);\n\t\twindow.scrollTo(x, y);\n\t\twindow.dispatchEvent(new Event('resize'));\n\t});\n}\n\nfunction shareUrl(\n\turl: string,\n\ttitle: string,\n\tcontentType: 'sculpt' | 'sculpt_clash' | 'sculpt_duet',\n\ttoast: (s: string) => void,\n\tsource?: string\n) {\n\tif (window.matchMedia('(pointer: coarse)').matches && navigator.share) {\n\t\ttrackShare('native', contentType, source);\n\t\tnavigator\n\t\t\t.share({ url, title })\n\t\t\t.catch(() => {})\n\t\t\t.finally(relayoutAfterSheet);\n\t\treturn;\n\t}\n\ttrackShare('clipboard', contentType, source);\n\tnavigator.clipboard\n\t\t?.writeText(url)\n\t\t.then(() => toast('Link copied'))\n\t\t.catch(() => toast(url));\n}\n\n/** `source`: where the share started (e.g. 'clash_picker'), carried on the `share` event. */\nexport function shareSculpt(\n\tnickname: string,\n\ttitle: string,\n\ttoast: (s: string) => void,\n\tsource?: InviteSource\n) {\n\tshareUrl(sculptShareUrl(nickname, source), title, 'sculpt', toast, source);\n}\n\n/** The duet invite (RAT-685): opening it plays a round with `nickname`'s sculpt. */\nexport function shareDuetInvite(\n\tnickname: string,\n\ttoast: (s: string) => void,\n\tsource: InviteSource\n) {\n\tshareUrl(duetInviteUrl(nickname, source), 'Duet me on ratemyd', 'sculpt_duet', toast, source);\n}\n\nexport function shareClash(code: string, title: string, toast: (s: string) => void) {\n\tshareUrl(clashShareUrl(code), title, 'sculpt_clash', toast);\n}\n"],"version":3}