{"version":3,"file":"guardAccidentalSelection.helper.cjs","sources":["../../../../src/hooks/use-viewport-shift/helpers/guardAccidentalSelection.helper.ts"],"sourcesContent":["/**\r\n * Prevents the accidental selection caused by sliding an item under the cursor.\r\n *\r\n * Radix selects an item by synthesizing a click on `pointerup` when the press\r\n * did **not** start on it (`@radix-ui/react-menu`: `onPointerUp` →\r\n * `currentTarget.click()` while `!isPointerDownRef.current`). Once shifted, the\r\n * `pointerup` releasing the *opening* click lands on an item and triggers it.\r\n *\r\n * We enforce the invariant *a pointer selection requires a `pointerdown` inside\r\n * the panel*: a press-less `pointerup` is stopped in the capture phase, so the\r\n * synthetic click never fires. It self-scopes (a `pointerup` only reaches the\r\n * panel once moved under the cursor) and leaves genuine clicks and keyboard\r\n * navigation untouched. Returns a cleanup that detaches the listeners.\r\n */\r\nexport const guardAccidentalSelection = (content: HTMLElement) => {\r\n    let pointerDownInside = false\r\n\r\n    const onPointerDown = () => { pointerDownInside = true }\r\n    const onPointerUp = (event: PointerEvent) => {\r\n        if (!pointerDownInside) { event.stopImmediatePropagation() }\r\n        pointerDownInside = false\r\n    }\r\n\r\n    content.addEventListener('pointerdown', onPointerDown, true)\r\n    content.addEventListener('pointerup', onPointerUp, true)\r\n\r\n    return () => {\r\n        content.removeEventListener('pointerdown', onPointerDown, true)\r\n        content.removeEventListener('pointerup', onPointerUp, true)\r\n    }\r\n}\r\n"],"names":["guardAccidentalSelection","content","pointerDownInside","onPointerDown","onPointerUp","event"],"mappings":"gFAcO,MAAMA,EAA4BC,GAAyB,CAC9D,IAAIC,EAAoB,GAExB,MAAMC,EAAgB,IAAM,CAAED,EAAoB,EAAK,EACjDE,EAAeC,GAAwB,CACpCH,GAAqBG,EAAM,yBAAA,EAChCH,EAAoB,EACxB,EAEA,OAAAD,EAAQ,iBAAiB,cAAeE,EAAe,EAAI,EAC3DF,EAAQ,iBAAiB,YAAaG,EAAa,EAAI,EAEhD,IAAM,CACTH,EAAQ,oBAAoB,cAAeE,EAAe,EAAI,EAC9DF,EAAQ,oBAAoB,YAAaG,EAAa,EAAI,CAC9D,CACJ"}