{"version":3,"sources":["../src/anchorClick.ts"],"sourcesContent":["// The click contract the link primitives share (`components/Link.tsx`, `platformLink.tsx`).\n//\n// Both spelled this out inline until it became one named contract, which is how they\n// drifted apart once already; R3-568 added a third spelling in `PlatformLink` and drifted\n// again (it ignored a caller-supplied `target`), so the contract and its guard now live in\n// one module that every primitive imports.\nimport { useCallback } from 'react';\nimport type { DependencyList, MouseEvent, MouseEventHandler } from 'react';\n\n/**\n * True when the click is the browser's to handle, not ours: a modified click or a\n * non-primary button means \"open this somewhere else\", and the sandbox permits that\n * (`allow-popups`) even where it forbids moving the top-level window.\n *\n * Intercepting these would take away open-in-new-tab, which is one of the two things\n * (with copy-link) that make an `href` worth rendering at all.\n */\nexport const isBrowserGestureClick = (event: MouseEvent<HTMLAnchorElement>): boolean =>\n  event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || event.button !== 0;\n\n/**\n * Compose a consumer-supplied `onClick` with an interception: the consumer handler runs\n * FIRST, and calling `preventDefault()` in it opts the click out of the interception\n * entirely; otherwise `intercept` runs.\n *\n * `intercept` is re-created on every render, so it is deliberately NOT a dependency:\n * `interceptDeps` names the values it closes over, and the memo is invalidated exactly when\n * those change.\n */\nexport const useComposedAnchorClick = (\n  onClick: MouseEventHandler<HTMLAnchorElement> | undefined,\n  intercept: (e: MouseEvent<HTMLAnchorElement>) => void,\n  interceptDeps: DependencyList,\n): MouseEventHandler<HTMLAnchorElement> =>\n  useCallback(\n    (e: MouseEvent<HTMLAnchorElement>) => {\n      onClick?.(e);\n      if (e.defaultPrevented) return;\n      intercept(e);\n    },\n    [onClick, ...interceptDeps],\n  );\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,mBAA4B;AAWrB,MAAM,wBAAwB,CAAC,UACpC,MAAM,WAAW,MAAM,WAAW,MAAM,YAAY,MAAM,UAAU,MAAM,WAAW;AAWhF,MAAM,yBAAyB,CACpC,SACA,WACA,sBAEA;AAAA,EACE,CAAC,MAAqC;AACpC,cAAU,CAAC;AACX,QAAI,EAAE,iBAAkB;AACxB,cAAU,CAAC;AAAA,EACb;AAAA,EACA,CAAC,SAAS,GAAG,aAAa;AAC5B;","names":[]}