react-panel-layout 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{FloatingPanelFrame-SgYLc6Ud.js → FloatingPanelFrame-3eU9AwPo.js} +2 -2
- package/dist/{FloatingPanelFrame-SgYLc6Ud.js.map → FloatingPanelFrame-3eU9AwPo.js.map} +1 -1
- package/dist/FloatingWindow-CUXnEtrb.js +827 -0
- package/dist/FloatingWindow-CUXnEtrb.js.map +1 -0
- package/dist/FloatingWindow-DMwyK0eK.cjs +2 -0
- package/dist/FloatingWindow-DMwyK0eK.cjs.map +1 -0
- package/dist/GridLayout-DKTg_N61.cjs +2 -0
- package/dist/{GridLayout-B4VRsC0r.cjs.map → GridLayout-DKTg_N61.cjs.map} +1 -1
- package/dist/{GridLayout-BltqeCPK.js → GridLayout-UWNxXw77.js} +34 -35
- package/dist/{GridLayout-BltqeCPK.js.map → GridLayout-UWNxXw77.js.map} +1 -1
- package/dist/{HorizontalDivider-WF1k_qND.js → HorizontalDivider-DdxzfV0l.js} +3 -3
- package/dist/{HorizontalDivider-WF1k_qND.js.map → HorizontalDivider-DdxzfV0l.js.map} +1 -1
- package/dist/{HorizontalDivider-B5Z-KZLk.cjs → HorizontalDivider-_pgV4Mcv.cjs} +2 -2
- package/dist/{HorizontalDivider-B5Z-KZLk.cjs.map → HorizontalDivider-_pgV4Mcv.cjs.map} +1 -1
- package/dist/{PanelSystem-Dr1TBhxM.js → PanelSystem-BqUzNtf2.js} +5 -5
- package/dist/{PanelSystem-Dr1TBhxM.js.map → PanelSystem-BqUzNtf2.js.map} +1 -1
- package/dist/{PanelSystem-Bs8bQwQF.cjs → PanelSystem-D603LKKv.cjs} +2 -2
- package/dist/{PanelSystem-Bs8bQwQF.cjs.map → PanelSystem-D603LKKv.cjs.map} +1 -1
- package/dist/ResizeHandle-CBcAS918.cjs +2 -0
- package/dist/{ResizeHandle-CScipO5l.cjs.map → ResizeHandle-CBcAS918.cjs.map} +1 -1
- package/dist/{ResizeHandle-CdA_JYfN.js → ResizeHandle-CXjc1meV.js} +28 -29
- package/dist/{ResizeHandle-CdA_JYfN.js.map → ResizeHandle-CXjc1meV.js.map} +1 -1
- package/dist/SwipePivotTabBar-DWrCuwEI.js +411 -0
- package/dist/SwipePivotTabBar-DWrCuwEI.js.map +1 -0
- package/dist/SwipePivotTabBar-fjjXkpj7.cjs +2 -0
- package/dist/SwipePivotTabBar-fjjXkpj7.cjs.map +1 -0
- package/dist/components/gesture/SwipeSafeZone.d.ts +40 -0
- package/dist/components/window/Drawer.d.ts +3 -1
- package/dist/components/window/DrawerLayers.d.ts +1 -1
- package/dist/components/window/drawerStyles.d.ts +69 -0
- package/dist/components/window/drawerSwipeConfig.d.ts +29 -0
- package/dist/components/window/useDrawerSwipeTransform.d.ts +23 -0
- package/dist/config.cjs +1 -1
- package/dist/config.js +3 -3
- package/dist/constants/styles.d.ts +17 -0
- package/dist/dialog/index.d.ts +69 -0
- package/dist/floating.js +1 -1
- package/dist/grid.cjs +1 -1
- package/dist/grid.js +2 -2
- package/dist/hooks/gesture/testing/createGestureSimulator.d.ts +7 -0
- package/dist/hooks/gesture/types.d.ts +48 -5
- package/dist/hooks/gesture/utils.d.ts +19 -0
- package/dist/hooks/useAnimationFrame.d.ts +2 -0
- package/dist/hooks/useOperationContinuity.d.ts +64 -0
- package/dist/hooks/useResizeObserver.d.ts +33 -1
- package/dist/hooks/useSharedElementTransition.d.ts +112 -0
- package/dist/hooks/useSwipeContentTransform.d.ts +9 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +7 -7
- package/dist/modules/dialog/AlertDialog.d.ts +9 -0
- package/dist/modules/dialog/DialogContainer.d.ts +37 -0
- package/dist/modules/dialog/Modal.d.ts +26 -0
- package/dist/modules/dialog/SwipeDialogContainer.d.ts +16 -0
- package/dist/modules/dialog/dialogAnimationUtils.d.ts +113 -0
- package/dist/modules/dialog/types.d.ts +183 -0
- package/dist/modules/dialog/useDialog.d.ts +39 -0
- package/dist/modules/dialog/useDialogContainer.d.ts +47 -0
- package/dist/modules/dialog/useDialogSwipeInput.d.ts +70 -0
- package/dist/modules/dialog/useDialogTransform.d.ts +82 -0
- package/dist/modules/drawer/types.d.ts +74 -0
- package/dist/modules/drawer/useDrawerSwipeInput.d.ts +24 -0
- package/dist/modules/pivot/SwipePivotTabBar.d.ts +3 -0
- package/dist/modules/stack/SwipeStackContent.d.ts +6 -3
- package/dist/modules/stack/SwipeStackOutlet.d.ts +4 -4
- package/dist/modules/stack/computeSwipeStackTransform.d.ts +1 -1
- package/dist/panels.cjs +1 -1
- package/dist/panels.js +1 -1
- package/dist/pivot.cjs +1 -1
- package/dist/pivot.js +1 -1
- package/dist/resizer.cjs +1 -1
- package/dist/resizer.js +2 -2
- package/dist/stack.cjs +1 -1
- package/dist/stack.cjs.map +1 -1
- package/dist/stack.js +503 -762
- package/dist/stack.js.map +1 -1
- package/dist/sticky-header/calculateStickyMetrics.d.ts +28 -0
- package/dist/sticky-header.cjs +1 -1
- package/dist/sticky-header.cjs.map +1 -1
- package/dist/sticky-header.js +59 -51
- package/dist/sticky-header.js.map +1 -1
- package/dist/{styles-DPPuJ0sf.js → styles-NkjuMOVS.js} +13 -13
- package/dist/{styles-DPPuJ0sf.js.map → styles-NkjuMOVS.js.map} +1 -1
- package/dist/styles-qf6ptVLD.cjs.map +1 -1
- package/dist/types.d.ts +16 -0
- package/dist/useDocumentPointerEvents-DXxw3qWj.js +54 -0
- package/dist/useDocumentPointerEvents-DXxw3qWj.js.map +1 -0
- package/dist/useDocumentPointerEvents-DxDSOtip.cjs +2 -0
- package/dist/useDocumentPointerEvents-DxDSOtip.cjs.map +1 -0
- package/dist/useNativeGestureGuard-C7TSqEkr.cjs +2 -0
- package/dist/useNativeGestureGuard-C7TSqEkr.cjs.map +1 -0
- package/dist/useNativeGestureGuard-CGYo6O0r.js +347 -0
- package/dist/useNativeGestureGuard-CGYo6O0r.js.map +1 -0
- package/dist/window/index.d.ts +2 -0
- package/dist/window.cjs +1 -1
- package/dist/window.cjs.map +1 -1
- package/dist/window.js +114 -103
- package/dist/window.js.map +1 -1
- package/package.json +6 -1
- package/src/components/gesture/SwipeSafeZone.tsx +69 -0
- package/src/components/window/Drawer.tsx +249 -162
- package/src/components/window/DrawerLayers.tsx +13 -3
- package/src/components/window/drawerStyles.spec.ts +263 -0
- package/src/components/window/drawerStyles.ts +228 -0
- package/src/components/window/drawerSwipeConfig.spec.ts +131 -0
- package/src/components/window/drawerSwipeConfig.ts +112 -0
- package/src/components/window/useDrawerSwipeTransform.spec.ts +234 -0
- package/src/components/window/useDrawerSwipeTransform.ts +129 -0
- package/src/constants/styles.ts +19 -0
- package/src/demo/pages/Dialog/alerts/index.tsx +22 -0
- package/src/demo/pages/Dialog/card/index.tsx +22 -0
- package/src/demo/pages/Dialog/components/AlertDialogDemo.tsx +124 -0
- package/src/demo/pages/Dialog/components/CardExpandDemo.module.css +243 -0
- package/src/demo/pages/Dialog/components/CardExpandDemo.tsx +204 -0
- package/src/demo/pages/Dialog/components/CustomAlertDialogDemo.tsx +219 -0
- package/src/demo/pages/Dialog/components/DialogDemos.module.css +77 -0
- package/src/demo/pages/Dialog/components/ModalBasics.tsx +45 -0
- package/src/demo/pages/Dialog/components/SwipeDialogDemo.module.css +77 -0
- package/src/demo/pages/Dialog/components/SwipeDialogDemo.tsx +181 -0
- package/src/demo/pages/Dialog/custom-alert/index.tsx +22 -0
- package/src/demo/pages/Dialog/modal/index.tsx +17 -0
- package/src/demo/pages/Dialog/swipe/index.tsx +22 -0
- package/src/demo/pages/Drawer/components/DrawerSwipe.module.css +316 -0
- package/src/demo/pages/Drawer/components/DrawerSwipe.tsx +178 -0
- package/src/demo/pages/Drawer/swipe/index.tsx +17 -0
- package/src/demo/pages/Pivot/components/SwipeTabsPivot.tsx +54 -23
- package/src/demo/pages/Pivot/swipe-debug/index.tsx +1 -1
- package/src/demo/pages/Stack/components/StackBasics.spec.tsx +152 -0
- package/src/demo/pages/Stack/components/StackBasics.tsx +179 -95
- package/src/demo/pages/Stack/components/StackTablet.spec.tsx +120 -0
- package/src/demo/pages/Stack/components/StackTablet.tsx +42 -21
- package/src/demo/routes.tsx +22 -1
- package/src/dialog/index.ts +85 -0
- package/src/hooks/gesture/testing/createGestureSimulator.spec.ts +68 -64
- package/src/hooks/gesture/testing/createGestureSimulator.ts +112 -37
- package/src/hooks/gesture/types.ts +83 -6
- package/src/hooks/gesture/useEdgeSwipeInput.spec.ts +22 -14
- package/src/hooks/gesture/useNativeGestureGuard.spec.ts +91 -31
- package/src/hooks/gesture/useNativeGestureGuard.ts +3 -1
- package/src/hooks/gesture/utils.ts +91 -0
- package/src/hooks/useAnimatedVisibility.spec.ts +44 -24
- package/src/hooks/useAnimatedVisibility.ts +28 -2
- package/src/hooks/useAnimationFrame.ts +8 -0
- package/src/hooks/useOperationContinuity.spec.ts +387 -0
- package/src/hooks/useOperationContinuity.ts +135 -0
- package/src/hooks/useResizeObserver.spec.tsx +277 -0
- package/src/hooks/useResizeObserver.tsx +108 -39
- package/src/hooks/useScrollContainer.ts +4 -10
- package/src/hooks/useSharedElementTransition.ts +333 -0
- package/src/hooks/useSwipeContentTransform.spec.ts +18 -18
- package/src/hooks/useSwipeContentTransform.ts +166 -28
- package/src/modules/dialog/AlertDialog.spec.tsx +387 -0
- package/src/modules/dialog/AlertDialog.tsx +221 -0
- package/src/modules/dialog/DialogContainer.spec.tsx +228 -0
- package/src/modules/dialog/DialogContainer.tsx +188 -0
- package/src/modules/dialog/Modal.spec.tsx +220 -0
- package/src/modules/dialog/Modal.tsx +182 -0
- package/src/modules/dialog/SwipeDialogContainer.tsx +208 -0
- package/src/modules/dialog/dialogAnimationUtils.spec.ts +253 -0
- package/src/modules/dialog/dialogAnimationUtils.ts +297 -0
- package/src/modules/dialog/types.ts +186 -0
- package/src/modules/dialog/useDialog.spec.tsx +447 -0
- package/src/modules/dialog/useDialog.ts +214 -0
- package/src/modules/dialog/useDialogContainer.spec.ts +331 -0
- package/src/modules/dialog/useDialogContainer.ts +150 -0
- package/src/modules/dialog/useDialogSwipeInput.spec.ts +157 -0
- package/src/modules/dialog/useDialogSwipeInput.ts +319 -0
- package/src/modules/dialog/useDialogTransform.spec.ts +370 -0
- package/src/modules/dialog/useDialogTransform.ts +407 -0
- package/src/modules/drawer/types.ts +102 -0
- package/src/modules/drawer/useDrawerSwipeInput.spec.ts +566 -0
- package/src/modules/drawer/useDrawerSwipeInput.ts +399 -0
- package/src/modules/panels/rendering/ContentRegistry.spec.tsx +21 -14
- package/src/modules/pivot/SwipePivotContent.position.spec.tsx +12 -8
- package/src/modules/pivot/SwipePivotContent.spec.tsx +55 -25
- package/src/modules/pivot/SwipePivotContent.tsx +2 -2
- package/src/modules/pivot/SwipePivotTabBar.spec.tsx +85 -68
- package/src/modules/pivot/SwipePivotTabBar.tsx +75 -15
- package/src/modules/pivot/scaleInputState.spec.ts +11 -2
- package/src/modules/pivot/usePivot.spec.ts +17 -3
- package/src/modules/pivot/usePivotSwipeInput.spec.ts +182 -123
- package/src/modules/stack/SwipeStackContent.spec.tsx +387 -100
- package/src/modules/stack/SwipeStackContent.tsx +43 -33
- package/src/modules/stack/SwipeStackOutlet.spec.tsx +14 -16
- package/src/modules/stack/SwipeStackOutlet.tsx +6 -6
- package/src/modules/stack/computeSwipeStackTransform.spec.ts +5 -5
- package/src/modules/stack/computeSwipeStackTransform.ts +3 -3
- package/src/modules/stack/swipeTransitionContinuity.spec.tsx +1133 -0
- package/src/modules/stack/useStackAnimationState.spec.ts +3 -1
- package/src/modules/stack/useStackAnimationState.ts +18 -13
- package/src/modules/stack/useStackNavigation.spec.ts +198 -3
- package/src/modules/stack/useStackNavigation.tsx +113 -56
- package/src/modules/stack/useStackSwipeInput.spec.ts +65 -32
- package/src/modules/stack/useStackSwipeInput.ts +1 -1
- package/src/sticky-header/StickyArea.tsx +29 -57
- package/src/sticky-header/calculateStickyMetrics.spec.ts +105 -0
- package/src/sticky-header/calculateStickyMetrics.ts +50 -0
- package/src/types.ts +18 -0
- package/src/window/index.ts +2 -0
- package/dist/FloatingWindow-BpdOpg_L.js +0 -400
- package/dist/FloatingWindow-BpdOpg_L.js.map +0 -1
- package/dist/FloatingWindow-TCDNY5gE.cjs +0 -2
- package/dist/FloatingWindow-TCDNY5gE.cjs.map +0 -1
- package/dist/GridLayout-B4VRsC0r.cjs +0 -2
- package/dist/ResizeHandle-CScipO5l.cjs +0 -2
- package/dist/SwipePivotTabBar-BGO9X94m.js +0 -407
- package/dist/SwipePivotTabBar-BGO9X94m.js.map +0 -1
- package/dist/SwipePivotTabBar-BrQismcZ.cjs +0 -2
- package/dist/SwipePivotTabBar-BrQismcZ.cjs.map +0 -1
- package/dist/useDocumentPointerEvents-CKdhGXd0.js +0 -46
- package/dist/useDocumentPointerEvents-CKdhGXd0.js.map +0 -1
- package/dist/useDocumentPointerEvents-ChqrKXDk.cjs +0 -2
- package/dist/useDocumentPointerEvents-ChqrKXDk.cjs.map +0 -1
- package/dist/useEffectEvent-Dp7HLCf0.js +0 -13
- package/dist/useEffectEvent-Dp7HLCf0.js.map +0 -1
- package/dist/useEffectEvent-huSsGUnl.cjs +0 -2
- package/dist/useEffectEvent-huSsGUnl.cjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDocumentPointerEvents-DXxw3qWj.js","sources":["../src/hooks/useEffectEvent.ts","../src/hooks/useDocumentPointerEvents.ts"],"sourcesContent":["/**\n * @file useEffectEvent hook - Stable event handler for Effects\n *\n * This hook allows you to extract event handlers from Effects without causing them to re-run.\n * The returned function is stable and can be safely used in effect dependencies.\n *\n * @see https://react.dev/learn/separating-events-from-effects#declaring-an-effect-event\n */\nimport * as React from \"react\";\n\n/**\n * Extract event handlers from Effects to avoid unnecessary re-runs\n *\n * @example\n * ```tsx\n * function Component({ onEvent }) {\n * const onEventHandler = useEffectEvent(onEvent);\n *\n * React.useEffect(() => {\n * // onEventHandler is stable, but always calls the latest onEvent\n * const cleanup = subscribe(onEventHandler);\n * return cleanup;\n * }, []); // No need to include onEvent in dependencies\n * }\n * ```\n */\nexport function useEffectEvent<Args extends unknown[], Return>(\n fn: ((...args: Args) => Return) | undefined,\n): (...args: Args) => Return | undefined {\n const ref = React.useRef<typeof fn>(fn);\n ref.current = fn;\n\n return React.useCallback((...args: Args): Return | undefined => {\n const currentFn = ref.current;\n if (currentFn) {\n return currentFn(...args);\n }\n return undefined;\n }, []);\n}\n","/**\n * @file Hooks for managing document-level pointer events with proper cleanup\n */\nimport * as React from \"react\";\nimport { useEffectEvent } from \"./useEffectEvent\";\n\nexport type UseDocumentPointerEventsOptions = {\n onMove?: (e: PointerEvent) => void;\n onUp?: (e: PointerEvent) => void;\n onCancel?: (e: PointerEvent) => void;\n};\n\n/**\n * Custom hook for managing document-level pointer events with proper cleanup\n * This pattern is commonly used for drag operations that need to continue\n * even when the pointer moves outside the original element\n */\nexport function useDocumentPointerEvents(enabled: boolean, handlers: UseDocumentPointerEventsOptions) {\n const handleMoveEvent = useEffectEvent(handlers.onMove);\n const handleUpEvent = useEffectEvent(handlers.onUp);\n const handleCancelEvent = useEffectEvent(handlers.onCancel);\n\n React.useEffect(() => {\n if (!enabled) {\n return;\n }\n\n if (handlers.onMove) {\n document.addEventListener(\"pointermove\", handleMoveEvent, { passive: false });\n }\n if (handlers.onUp) {\n document.addEventListener(\"pointerup\", handleUpEvent);\n }\n if (handlers.onCancel) {\n document.addEventListener(\"pointercancel\", handleCancelEvent);\n }\n\n // Cleanup function\n return () => {\n if (handlers.onMove) {\n document.removeEventListener(\"pointermove\", handleMoveEvent);\n }\n if (handlers.onUp) {\n document.removeEventListener(\"pointerup\", handleUpEvent);\n }\n if (handlers.onCancel) {\n document.removeEventListener(\"pointercancel\", handleCancelEvent);\n }\n };\n }, [enabled, handlers.onMove, handlers.onUp, handlers.onCancel, handleMoveEvent, handleUpEvent, handleCancelEvent]);\n}\n\n/**\n * Hook for capturing pointer during drag operations\n * This ensures that pointer events are delivered to the capturing element\n * even when the pointer moves outside its boundaries\n */\nexport function usePointerCapture(elementRef: React.RefObject<HTMLElement | null>, enabled: boolean, pointerId?: number) {\n React.useEffect(() => {\n const element = elementRef.current;\n if (!enabled || !element || pointerId === undefined) {\n return;\n }\n\n // Capture pointer\n element.setPointerCapture(pointerId);\n\n // Release capture on cleanup\n return () => {\n if (element.hasPointerCapture && element.hasPointerCapture(pointerId)) {\n element.releasePointerCapture(pointerId);\n }\n };\n }, [elementRef, enabled, pointerId]);\n}\n\n/**\n * Hook for preventing default pointer events during operations\n * Useful for preventing text selection, context menus, etc. during drag operations\n */\nexport function usePreventPointerDefaults(\n elementRef: React.RefObject<HTMLElement | null>,\n enabled: boolean,\n events: string[] = [\"pointerdown\", \"pointermove\", \"pointerup\"],\n) {\n React.useEffect(() => {\n const element = elementRef.current;\n if (!enabled || !element) {\n return;\n }\n\n const preventDefault = (e: Event) => {\n e.preventDefault();\n };\n\n // Add listeners\n events.forEach((eventType) => {\n element.addEventListener(eventType, preventDefault, { passive: false });\n });\n\n // Cleanup\n return () => {\n events.forEach((eventType) => {\n element.removeEventListener(eventType, preventDefault);\n });\n };\n }, [elementRef, enabled, events]);\n}\n\n/**\n * Hook that combines multiple pointer event patterns for drag operations\n */\nexport function useDragPointerEvents(\n elementRef: React.RefObject<HTMLElement | null>,\n enabled: boolean,\n options: {\n onMove?: (e: PointerEvent) => void;\n onUp?: (e: PointerEvent) => void;\n onCancel?: (e: PointerEvent) => void;\n pointerId?: number;\n capturePointer?: boolean;\n preventDefaults?: boolean;\n },\n) {\n const { onMove, onUp, onCancel, pointerId, capturePointer = true, preventDefaults = true } = options;\n\n // Document-level event handlers\n useDocumentPointerEvents(enabled, { onMove, onUp, onCancel });\n\n // Pointer capture\n const shouldCapturePointer = enabled ? capturePointer : false;\n usePointerCapture(elementRef, shouldCapturePointer, pointerId);\n\n // Prevent defaults\n const shouldPreventDefaults = enabled ? preventDefaults : false;\n usePreventPointerDefaults(elementRef, shouldPreventDefaults);\n}\n"],"names":["useEffectEvent","fn","ref","React","args","currentFn","useDocumentPointerEvents","enabled","handlers","handleMoveEvent","handleUpEvent","handleCancelEvent","usePointerCapture","elementRef","pointerId","element","usePreventPointerDefaults","events","preventDefault","e","eventType","useDragPointerEvents","options","onMove","onUp","onCancel","capturePointer","preventDefaults"],"mappings":";AA0BO,SAASA,EACdC,GACuC;AACvC,QAAMC,IAAMC,EAAM,OAAkBF,CAAE;AACtC,SAAAC,EAAI,UAAUD,GAEPE,EAAM,YAAY,IAAIC,MAAmC;AAC9D,UAAMC,IAAYH,EAAI;AACtB,QAAIG;AACF,aAAOA,EAAU,GAAGD,CAAI;AAAA,EAG5B,GAAG,CAAA,CAAE;AACP;ACtBO,SAASE,EAAyBC,GAAkBC,GAA2C;AACpG,QAAMC,IAAkBT,EAAeQ,EAAS,MAAM,GAChDE,IAAgBV,EAAeQ,EAAS,IAAI,GAC5CG,IAAoBX,EAAeQ,EAAS,QAAQ;AAE1D,EAAAL,EAAM,UAAU,MAAM;AACpB,QAAKI;AAIL,aAAIC,EAAS,UACX,SAAS,iBAAiB,eAAeC,GAAiB,EAAE,SAAS,IAAO,GAE1ED,EAAS,QACX,SAAS,iBAAiB,aAAaE,CAAa,GAElDF,EAAS,YACX,SAAS,iBAAiB,iBAAiBG,CAAiB,GAIvD,MAAM;AACX,QAAIH,EAAS,UACX,SAAS,oBAAoB,eAAeC,CAAe,GAEzDD,EAAS,QACX,SAAS,oBAAoB,aAAaE,CAAa,GAErDF,EAAS,YACX,SAAS,oBAAoB,iBAAiBG,CAAiB;AAAA,MAEnE;AAAA,EACF,GAAG,CAACJ,GAASC,EAAS,QAAQA,EAAS,MAAMA,EAAS,UAAUC,GAAiBC,GAAeC,CAAiB,CAAC;AACpH;AAOO,SAASC,EAAkBC,GAAiDN,GAAkBO,GAAoB;AACvH,EAAAX,EAAM,UAAU,MAAM;AACpB,UAAMY,IAAUF,EAAW;AAC3B,QAAI,GAACN,KAAW,CAACQ,KAAWD,MAAc;AAK1C,aAAAC,EAAQ,kBAAkBD,CAAS,GAG5B,MAAM;AACX,QAAIC,EAAQ,qBAAqBA,EAAQ,kBAAkBD,CAAS,KAClEC,EAAQ,sBAAsBD,CAAS;AAAA,MAE3C;AAAA,EACF,GAAG,CAACD,GAAYN,GAASO,CAAS,CAAC;AACrC;AAMO,SAASE,EACdH,GACAN,GACAU,IAAmB,CAAC,eAAe,eAAe,WAAW,GAC7D;AACA,EAAAd,EAAM,UAAU,MAAM;AACpB,UAAMY,IAAUF,EAAW;AAC3B,QAAI,CAACN,KAAW,CAACQ;AACf;AAGF,UAAMG,IAAiB,CAACC,MAAa;AACnC,MAAAA,EAAE,eAAA;AAAA,IACJ;AAGA,WAAAF,EAAO,QAAQ,CAACG,MAAc;AAC5B,MAAAL,EAAQ,iBAAiBK,GAAWF,GAAgB,EAAE,SAAS,IAAO;AAAA,IACxE,CAAC,GAGM,MAAM;AACX,MAAAD,EAAO,QAAQ,CAACG,MAAc;AAC5B,QAAAL,EAAQ,oBAAoBK,GAAWF,CAAc;AAAA,MACvD,CAAC;AAAA,IACH;AAAA,EACF,GAAG,CAACL,GAAYN,GAASU,CAAM,CAAC;AAClC;AAKO,SAASI,EACdR,GACAN,GACAe,GAQA;AACA,QAAM,EAAE,QAAAC,GAAQ,MAAAC,GAAM,UAAAC,GAAU,WAAAX,GAAW,gBAAAY,IAAiB,IAAM,iBAAAC,IAAkB,GAAA,IAASL;AAG7F,EAAAhB,EAAyBC,GAAS,EAAE,QAAAgB,GAAQ,MAAAC,GAAM,UAAAC,GAAU,GAI5Db,EAAkBC,GADWN,IAAUmB,IAAiB,IACJZ,CAAS,GAI7DE,EAA0BH,GADIN,IAAUoB,IAAkB,EACC;AAC7D;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const p=require("react");function E(o){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const t in o)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(o,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>o[t]})}}return e.default=o,Object.freeze(e)}const c=E(p);function i(o){const e=c.useRef(o);return e.current=o,c.useCallback((...t)=>{const n=e.current;if(n)return n(...t)},[])}function s(o,e){const t=i(e.onMove),n=i(e.onUp),r=i(e.onCancel);c.useEffect(()=>{if(o)return e.onMove&&document.addEventListener("pointermove",t,{passive:!1}),e.onUp&&document.addEventListener("pointerup",n),e.onCancel&&document.addEventListener("pointercancel",r),()=>{e.onMove&&document.removeEventListener("pointermove",t),e.onUp&&document.removeEventListener("pointerup",n),e.onCancel&&document.removeEventListener("pointercancel",r)}},[o,e.onMove,e.onUp,e.onCancel,t,n,r])}function l(o,e,t){c.useEffect(()=>{const n=o.current;if(!(!e||!n||t===void 0))return n.setPointerCapture(t),()=>{n.hasPointerCapture&&n.hasPointerCapture(t)&&n.releasePointerCapture(t)}},[o,e,t])}function m(o,e,t=["pointerdown","pointermove","pointerup"]){c.useEffect(()=>{const n=o.current;if(!e||!n)return;const r=u=>{u.preventDefault()};return t.forEach(u=>{n.addEventListener(u,r,{passive:!1})}),()=>{t.forEach(u=>{n.removeEventListener(u,r)})}},[o,e,t])}function P(o,e,t){const{onMove:n,onUp:r,onCancel:u,pointerId:f,capturePointer:a=!0,preventDefaults:v=!0}=t;s(e,{onMove:n,onUp:r,onCancel:u}),l(o,e?a:!1,f),m(o,e?v:!1)}exports.useDocumentPointerEvents=s;exports.useDragPointerEvents=P;exports.useEffectEvent=i;
|
|
2
|
+
//# sourceMappingURL=useDocumentPointerEvents-DxDSOtip.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDocumentPointerEvents-DxDSOtip.cjs","sources":["../src/hooks/useEffectEvent.ts","../src/hooks/useDocumentPointerEvents.ts"],"sourcesContent":["/**\n * @file useEffectEvent hook - Stable event handler for Effects\n *\n * This hook allows you to extract event handlers from Effects without causing them to re-run.\n * The returned function is stable and can be safely used in effect dependencies.\n *\n * @see https://react.dev/learn/separating-events-from-effects#declaring-an-effect-event\n */\nimport * as React from \"react\";\n\n/**\n * Extract event handlers from Effects to avoid unnecessary re-runs\n *\n * @example\n * ```tsx\n * function Component({ onEvent }) {\n * const onEventHandler = useEffectEvent(onEvent);\n *\n * React.useEffect(() => {\n * // onEventHandler is stable, but always calls the latest onEvent\n * const cleanup = subscribe(onEventHandler);\n * return cleanup;\n * }, []); // No need to include onEvent in dependencies\n * }\n * ```\n */\nexport function useEffectEvent<Args extends unknown[], Return>(\n fn: ((...args: Args) => Return) | undefined,\n): (...args: Args) => Return | undefined {\n const ref = React.useRef<typeof fn>(fn);\n ref.current = fn;\n\n return React.useCallback((...args: Args): Return | undefined => {\n const currentFn = ref.current;\n if (currentFn) {\n return currentFn(...args);\n }\n return undefined;\n }, []);\n}\n","/**\n * @file Hooks for managing document-level pointer events with proper cleanup\n */\nimport * as React from \"react\";\nimport { useEffectEvent } from \"./useEffectEvent\";\n\nexport type UseDocumentPointerEventsOptions = {\n onMove?: (e: PointerEvent) => void;\n onUp?: (e: PointerEvent) => void;\n onCancel?: (e: PointerEvent) => void;\n};\n\n/**\n * Custom hook for managing document-level pointer events with proper cleanup\n * This pattern is commonly used for drag operations that need to continue\n * even when the pointer moves outside the original element\n */\nexport function useDocumentPointerEvents(enabled: boolean, handlers: UseDocumentPointerEventsOptions) {\n const handleMoveEvent = useEffectEvent(handlers.onMove);\n const handleUpEvent = useEffectEvent(handlers.onUp);\n const handleCancelEvent = useEffectEvent(handlers.onCancel);\n\n React.useEffect(() => {\n if (!enabled) {\n return;\n }\n\n if (handlers.onMove) {\n document.addEventListener(\"pointermove\", handleMoveEvent, { passive: false });\n }\n if (handlers.onUp) {\n document.addEventListener(\"pointerup\", handleUpEvent);\n }\n if (handlers.onCancel) {\n document.addEventListener(\"pointercancel\", handleCancelEvent);\n }\n\n // Cleanup function\n return () => {\n if (handlers.onMove) {\n document.removeEventListener(\"pointermove\", handleMoveEvent);\n }\n if (handlers.onUp) {\n document.removeEventListener(\"pointerup\", handleUpEvent);\n }\n if (handlers.onCancel) {\n document.removeEventListener(\"pointercancel\", handleCancelEvent);\n }\n };\n }, [enabled, handlers.onMove, handlers.onUp, handlers.onCancel, handleMoveEvent, handleUpEvent, handleCancelEvent]);\n}\n\n/**\n * Hook for capturing pointer during drag operations\n * This ensures that pointer events are delivered to the capturing element\n * even when the pointer moves outside its boundaries\n */\nexport function usePointerCapture(elementRef: React.RefObject<HTMLElement | null>, enabled: boolean, pointerId?: number) {\n React.useEffect(() => {\n const element = elementRef.current;\n if (!enabled || !element || pointerId === undefined) {\n return;\n }\n\n // Capture pointer\n element.setPointerCapture(pointerId);\n\n // Release capture on cleanup\n return () => {\n if (element.hasPointerCapture && element.hasPointerCapture(pointerId)) {\n element.releasePointerCapture(pointerId);\n }\n };\n }, [elementRef, enabled, pointerId]);\n}\n\n/**\n * Hook for preventing default pointer events during operations\n * Useful for preventing text selection, context menus, etc. during drag operations\n */\nexport function usePreventPointerDefaults(\n elementRef: React.RefObject<HTMLElement | null>,\n enabled: boolean,\n events: string[] = [\"pointerdown\", \"pointermove\", \"pointerup\"],\n) {\n React.useEffect(() => {\n const element = elementRef.current;\n if (!enabled || !element) {\n return;\n }\n\n const preventDefault = (e: Event) => {\n e.preventDefault();\n };\n\n // Add listeners\n events.forEach((eventType) => {\n element.addEventListener(eventType, preventDefault, { passive: false });\n });\n\n // Cleanup\n return () => {\n events.forEach((eventType) => {\n element.removeEventListener(eventType, preventDefault);\n });\n };\n }, [elementRef, enabled, events]);\n}\n\n/**\n * Hook that combines multiple pointer event patterns for drag operations\n */\nexport function useDragPointerEvents(\n elementRef: React.RefObject<HTMLElement | null>,\n enabled: boolean,\n options: {\n onMove?: (e: PointerEvent) => void;\n onUp?: (e: PointerEvent) => void;\n onCancel?: (e: PointerEvent) => void;\n pointerId?: number;\n capturePointer?: boolean;\n preventDefaults?: boolean;\n },\n) {\n const { onMove, onUp, onCancel, pointerId, capturePointer = true, preventDefaults = true } = options;\n\n // Document-level event handlers\n useDocumentPointerEvents(enabled, { onMove, onUp, onCancel });\n\n // Pointer capture\n const shouldCapturePointer = enabled ? capturePointer : false;\n usePointerCapture(elementRef, shouldCapturePointer, pointerId);\n\n // Prevent defaults\n const shouldPreventDefaults = enabled ? preventDefaults : false;\n usePreventPointerDefaults(elementRef, shouldPreventDefaults);\n}\n"],"names":["useEffectEvent","fn","ref","React","args","currentFn","useDocumentPointerEvents","enabled","handlers","handleMoveEvent","handleUpEvent","handleCancelEvent","usePointerCapture","elementRef","pointerId","element","usePreventPointerDefaults","events","preventDefault","e","eventType","useDragPointerEvents","options","onMove","onUp","onCancel","capturePointer","preventDefaults"],"mappings":"gUA0BO,SAASA,EACdC,EACuC,CACvC,MAAMC,EAAMC,EAAM,OAAkBF,CAAE,EACtC,OAAAC,EAAI,QAAUD,EAEPE,EAAM,YAAY,IAAIC,IAAmC,CAC9D,MAAMC,EAAYH,EAAI,QACtB,GAAIG,EACF,OAAOA,EAAU,GAAGD,CAAI,CAG5B,EAAG,CAAA,CAAE,CACP,CCtBO,SAASE,EAAyBC,EAAkBC,EAA2C,CACpG,MAAMC,EAAkBT,EAAeQ,EAAS,MAAM,EAChDE,EAAgBV,EAAeQ,EAAS,IAAI,EAC5CG,EAAoBX,EAAeQ,EAAS,QAAQ,EAE1DL,EAAM,UAAU,IAAM,CACpB,GAAKI,EAIL,OAAIC,EAAS,QACX,SAAS,iBAAiB,cAAeC,EAAiB,CAAE,QAAS,GAAO,EAE1ED,EAAS,MACX,SAAS,iBAAiB,YAAaE,CAAa,EAElDF,EAAS,UACX,SAAS,iBAAiB,gBAAiBG,CAAiB,EAIvD,IAAM,CACPH,EAAS,QACX,SAAS,oBAAoB,cAAeC,CAAe,EAEzDD,EAAS,MACX,SAAS,oBAAoB,YAAaE,CAAa,EAErDF,EAAS,UACX,SAAS,oBAAoB,gBAAiBG,CAAiB,CAEnE,CACF,EAAG,CAACJ,EAASC,EAAS,OAAQA,EAAS,KAAMA,EAAS,SA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s");function q(o){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const n in o)if(n!=="default"){const t=Object.getOwnPropertyDescriptor(o,n);Object.defineProperty(e,n,t.get?t:{enumerable:!0,get:()=>o[n]})}}return e.default=o,Object.freeze(e)}const c=q(V),R={isDown:!1,start:null,current:null,pointerId:null,wasCanceled:!1},U=(o,e)=>({x:o,y:e,timestamp:performance.now()});function G(o){const{enabled:e,primaryOnly:n=!0}=o,[t,r]=c.useState(R),i=c.useCallback(()=>{r(R)},[]),l=D.useEffectEvent(a=>{if(!e||n&&!a.isPrimary||a.pointerType==="mouse"&&a.button!==0)return;const m=U(a.clientX,a.clientY);r({isDown:!0,start:m,current:m,pointerId:a.pointerId,wasCanceled:!1})}),f=D.useEffectEvent(a=>{if(t.pointerId!==a.pointerId)return;const m=U(a.clientX,a.clientY);r(w=>({...w,current:m}))}),d=D.useEffectEvent(()=>{r(R)}),h=D.useEffectEvent(()=>{r({...R,wasCanceled:!0})}),s=t.isDown?e:!1;return D.useDocumentPointerEvents(s,{onMove:f,onUp:d,onCancel:h}),c.useEffect(()=>{!e&&t.isDown&&i()},[e,t.isDown,i]),{state:t,onPointerDown:l,reset:i}}const K=10,Z=(o,e)=>{const n=Math.abs(o),t=Math.abs(e);return n===0&&t===0?null:n>t*1.5?"horizontal":t>n*1.5?"vertical":null};function J(o){const{tracking:e,lockThreshold:n=K}=o,[t,r]=c.useState(null),i=c.useCallback(()=>{r(null)},[]);return c.useEffect(()=>{if(!e.isDown){t!==null&&i();return}if(t!==null||!e.start||!e.current)return;const l=e.current.x-e.start.x,f=e.current.y-e.start.y;if(Math.max(Math.abs(l),Math.abs(f))<n)return;const h=Z(l,f);h!==null&&r(h)},[e.isDown,e.start,e.current,t,n,i]),{lockedAxis:t,isLocked:t!==null,reset:i}}const H=(o,e,n)=>{const t=n-e;return t<=0?0:o/t},_=o=>o>0?1:o<0?-1:0,Q=(...o)=>{const e={},n=[];for(const r of o)Object.assign(e,r.style),r.onPointerDown&&n.push(r.onPointerDown);return{onPointerDown:r=>{for(const i of n)i?.(r)},style:e}};function $(o,e,n,t){let r=o;for(;r!==null&&r!==e;){const i=getComputedStyle(r),l=n==="x",f=l?i.overflowX:i.overflowY;if(f==="scroll"||f==="auto"){const h=l?r.scrollWidth-r.clientWidth:r.scrollHeight-r.clientHeight;if(h>0){const s=l?r.scrollLeft:r.scrollTop;if(t===-1&&s>1||t===1&&s<h-1)return!0}}r=r.parentElement}return!1}const ee={phase:"idle",displacement:{x:0,y:0},velocity:{x:0,y:0}},B={distanceThreshold:100,velocityThreshold:.5,lockThreshold:10},F=20,x={phase:"idle",displacement:{x:0,y:0},velocity:{x:0,y:0},direction:0},te=150,N=(o,e,n,t,r)=>{const i=n==="horizontal"?o.x:o.y,l=n==="horizontal"?e.x:e.y,f=Math.abs(i),d=Math.abs(l);if(f>=t.distanceThreshold||d>=t.velocityThreshold){const s=_(i);r?.({phase:"ended",displacement:o,velocity:e,direction:s})}};function ne(o){const{containerRef:e,axis:n,enabled:t=!0,thresholds:r,onSwipeEnd:i,enableWheel:l=!0,pointerStartFilter:f}=o,d={...B,...r},h=D.useEffectEvent(i),{state:s,onPointerDown:a}=G({enabled:t}),m=c.useCallback(u=>{if(t){if(f){const p=e.current;if(!p||!f(u,p))return}a(u)}},[t,f,e,a]),{lockedAxis:w,isLocked:b}=J({tracking:s,lockThreshold:d.lockThreshold}),S=c.useRef(null),k=c.useRef(!1);c.useEffect(()=>{k.current=b?w===n:!1},[b,w,n]),c.useEffect(()=>{const u=e.current;if(!u||!t)return;const p=y=>{y.preventDefault()},E=y=>{k.current&&y.preventDefault(),document.addEventListener("touchmove",p,{passive:!1})},v=()=>{document.removeEventListener("touchmove",p)};return document.addEventListener("touchend",v),document.addEventListener("touchcancel",v),u.addEventListener("touchstart",E,{passive:!1}),()=>{u.removeEventListener("touchstart",E),document.removeEventListener("touchend",v),document.removeEventListener("touchcancel",v)}},[e,t]);const[I,C]=c.useState(x),g=c.useRef({x:0,y:0}),T=c.useRef(null),L=c.useRef(!1),O=c.useRef(null),A=c.useCallback(()=>{g.current={x:0,y:0},L.current=!1,O.current=null,C(x)},[]),X=c.useCallback(()=>{const u={...g.current};N(u,{x:0,y:0},n,d,h),A()},[n,d,h,A]),M=D.useEffectEvent(u=>{if(!t||!l||s.isDown)return;const{deltaX:p,deltaY:E}=u;if(!L.current){const W=Math.abs(p),z=Math.abs(E);(W>=d.lockThreshold||z>=d.lockThreshold)&&(L.current=!0,O.current=W>z?"horizontal":"vertical")}if(L.current&&O.current!==n)return;g.current.x-=p,g.current.y-=E;const v=g.current,y=n==="horizontal"?v.x:v.y;C({phase:"swiping",displacement:{...v},velocity:{x:0,y:0},direction:_(y)}),T.current!==null&&clearTimeout(T.current),T.current=setTimeout(X,te)});c.useEffect(()=>{const u=e.current;if(!u||!t||!l)return;const p=E=>{E.preventDefault(),M(E)};return u.addEventListener("wheel",p,{passive:!1}),()=>{u.removeEventListener("wheel",p),T.current!==null&&clearTimeout(T.current)}},[e,t,l,M]),c.useEffect(()=>()=>{T.current!==null&&clearTimeout(T.current)},[]);const P=c.useMemo(()=>{if(!s.isDown||!s.start||!s.current)return x;const u=s.current.x-s.start.x,p=s.current.y-s.start.y,E={x:u,y:p},v={x:H(u,s.start.timestamp,s.current.timestamp),y:H(p,s.start.timestamp,s.current.timestamp)};return!b||w!==n?{phase:"tracking",displacement:E,velocity:v,direction:0}:{phase:"swiping",displacement:E,velocity:v,direction:_(n==="horizontal"?u:p)}},[s.isDown,s.start,s.current,b,w,n]);c.useEffect(()=>{P.phase!=="idle"&&(S.current=P)},[P]),c.useEffect(()=>{if(s.isDown)return;const u=S.current;!u||u.phase!=="swiping"&&u.phase!=="tracking"||(S.current=null,!s.wasCanceled&&N(u.displacement,u.velocity,n,d,h))},[s.isDown,s.wasCanceled,n,d,h]);const Y=P.phase!=="idle"?P:I,j=c.useMemo(()=>({onPointerDown:m,style:{touchAction:n==="horizontal"?"pan-y pinch-zoom":"pan-x pinch-zoom",userSelect:"none",WebkitUserSelect:"none"}}),[n,m]);return{state:Y,containerProps:j}}const re=o=>o==="left"||o==="right"?"horizontal":"vertical",oe=(o,e,n,t,r)=>{const i=n.getBoundingClientRect();switch(t){case"left":return o>=i.left&&o<=i.left+r;case"right":return o>=i.right-r&&o<=i.right;case"top":return e>=i.top&&e<=i.top+r;case"bottom":return e>=i.bottom-r&&e<=i.bottom}};function se(o){const{containerRef:e,edge:n,edgeWidth:t=F,enabled:r=!0,thresholds:i,onSwipeEnd:l}=o,f={...B,...i},d=re(n),[h,s]=c.useState(!1),a=c.useCallback((S,k)=>{const I=oe(S.clientX,S.clientY,k,n,t);return s(I),I},[n,t]),{state:m,containerProps:w}=ne({containerRef:e,axis:d,enabled:r,thresholds:f,onSwipeEnd:l,enableWheel:!1,pointerStartFilter:a});return c.useEffect(()=>{m.phase==="idle"&&s(!1)},[m.phase]),{isEdgeGesture:h,state:h?m:x,containerProps:w}}const ce=(o,e,n)=>{const t=e.getBoundingClientRect();return o>=t.left&&o<=t.left+n};function ie(o){const{containerRef:e,active:n,preventEdgeBack:t=!0,preventOverscroll:r=!0,edgeWidth:i=F}=o,l=c.useRef(null),f=c.useCallback(()=>{if(!r)return;const s=document.documentElement;l.current===null&&(l.current=s.style.overscrollBehavior),s.style.overscrollBehavior="none"},[r]);c.useEffect(()=>{n||!r||l.current!==null&&(document.documentElement.style.overscrollBehavior=l.current,l.current=null)},[n,r]),c.useEffect(()=>()=>{l.current!==null&&(document.documentElement.style.overscrollBehavior=l.current,l.current=null)},[]);const d=c.useCallback(s=>{if(!t)return;const a=e.current;a&&s.pointerType==="touch"&&ce(s.clientX,a,i)&&(f(),s.preventDefault())},[t,e,i,f]);return{containerProps:c.useMemo(()=>({onPointerDown:t?d:void 0,style:{overscrollBehavior:r?"contain":void 0,WebkitOverflowScrolling:"touch"}}),[r,t,d])}}exports.IDLE_CONTINUOUS_OPERATION_STATE=ee;exports.IDLE_SWIPE_INPUT_STATE=x;exports.isScrollableInDirection=$;exports.mergeGestureContainerProps=Q;exports.useEdgeSwipeInput=se;exports.useNativeGestureGuard=ie;exports.usePointerTracking=G;
|
|
2
|
+
//# sourceMappingURL=useNativeGestureGuard-C7TSqEkr.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNativeGestureGuard-C7TSqEkr.cjs","sources":["../src/hooks/gesture/usePointerTracking.ts","../src/hooks/gesture/useDirectionalLock.ts","../src/hooks/gesture/utils.ts","../src/hooks/gesture/types.ts","../src/hooks/gesture/useSwipeInput.ts","../src/hooks/gesture/useEdgeSwipeInput.ts","../src/hooks/gesture/useNativeGestureGuard.ts"],"sourcesContent":["/**\n * @file Hook for tracking pointer state during gestures.\n *\n * Provides low-level pointer tracking with position, velocity, and timing.\n * This hook serves as the foundation for higher-level gesture hooks.\n */\nimport * as React from \"react\";\nimport { useDocumentPointerEvents } from \"../useDocumentPointerEvents.js\";\nimport { useEffectEvent } from \"../useEffectEvent.js\";\nimport type {\n PointerTrackingState,\n TimestampedPoint,\n UsePointerTrackingOptions,\n UsePointerTrackingResult,\n} from \"./types.js\";\n\n/**\n * Initial state for pointer tracking.\n */\nconst INITIAL_STATE: PointerTrackingState = {\n isDown: false,\n start: null,\n current: null,\n pointerId: null,\n wasCanceled: false,\n};\n\n/**\n * Creates a timestamped point from pointer event coordinates.\n */\nconst createTimestampedPoint = (clientX: number, clientY: number): TimestampedPoint => ({\n x: clientX,\n y: clientY,\n timestamp: performance.now(),\n});\n\n/**\n * Hook for tracking pointer state during gestures.\n *\n * Tracks pointer down/move/up events and provides position and timing data\n * that can be used by higher-level gesture detection hooks.\n *\n * @example\n * ```tsx\n * const { state, onPointerDown, reset } = usePointerTracking({\n * enabled: true,\n * primaryOnly: true,\n * });\n *\n * return (\n * <div onPointerDown={onPointerDown}>\n * {state.isDown && <span>Tracking...</span>}\n * </div>\n * );\n * ```\n */\nexport function usePointerTracking(options: UsePointerTrackingOptions): UsePointerTrackingResult {\n const { enabled, primaryOnly = true } = options;\n\n const [state, setState] = React.useState<PointerTrackingState>(INITIAL_STATE);\n\n const reset = React.useCallback(() => {\n setState(INITIAL_STATE);\n }, []);\n\n const handlePointerDown = useEffectEvent((event: React.PointerEvent) => {\n if (!enabled) {\n return;\n }\n\n // Filter non-primary pointers if primaryOnly is set\n if (primaryOnly && !event.isPrimary) {\n return;\n }\n\n // Only track left mouse button or touch/pen\n if (event.pointerType === \"mouse\" && event.button !== 0) {\n return;\n }\n\n const point = createTimestampedPoint(event.clientX, event.clientY);\n\n setState({\n isDown: true,\n start: point,\n current: point,\n pointerId: event.pointerId,\n wasCanceled: false,\n });\n });\n\n const handlePointerMove = useEffectEvent((event: PointerEvent) => {\n // Verify this is the tracked pointer\n if (state.pointerId !== event.pointerId) {\n return;\n }\n\n const point = createTimestampedPoint(event.clientX, event.clientY);\n\n setState((prev) => ({\n ...prev,\n current: point,\n }));\n });\n\n const handlePointerUp = useEffectEvent(() => {\n setState(INITIAL_STATE);\n });\n\n const handlePointerCancel = useEffectEvent(() => {\n setState({ ...INITIAL_STATE, wasCanceled: true });\n });\n\n // Use document-level pointer events for tracking after pointer down\n const shouldTrackDocument = state.isDown ? enabled : false;\n useDocumentPointerEvents(shouldTrackDocument, {\n onMove: handlePointerMove,\n onUp: handlePointerUp,\n onCancel: handlePointerCancel,\n });\n\n // Reset state when disabled\n React.useEffect(() => {\n if (!enabled && state.isDown) {\n reset();\n }\n }, [enabled, state.isDown, reset]);\n\n return {\n state,\n onPointerDown: handlePointerDown,\n reset,\n };\n}\n","/**\n * @file Hook for locking gesture direction after threshold is exceeded.\n *\n * Once the user moves beyond the lock threshold, the direction is locked\n * to either horizontal or vertical, preventing diagonal gestures from\n * triggering both scroll and swipe.\n */\nimport * as React from \"react\";\nimport type {\n GestureAxis,\n UseDirectionalLockOptions,\n UseDirectionalLockResult,\n} from \"./types.js\";\n\nconst DEFAULT_LOCK_THRESHOLD = 10;\n\n/**\n * Determines which axis the gesture is primarily moving along.\n *\n * @param deltaX - Horizontal displacement from start\n * @param deltaY - Vertical displacement from start\n * @returns The dominant axis, or null if movement is insufficient\n */\nconst determineAxis = (deltaX: number, deltaY: number): GestureAxis | null => {\n const absX = Math.abs(deltaX);\n const absY = Math.abs(deltaY);\n\n // Require at least some movement in one direction\n if (absX === 0 && absY === 0) {\n return null;\n }\n\n // Use a 1.5x ratio to ensure clear direction before locking\n // This prevents near-diagonal gestures from locking prematurely\n if (absX > absY * 1.5) {\n return \"horizontal\";\n }\n\n if (absY > absX * 1.5) {\n return \"vertical\";\n }\n\n // Still ambiguous\n return null;\n};\n\n/**\n * Hook for locking gesture direction after threshold is exceeded.\n *\n * This hook tracks pointer movement and locks to horizontal or vertical\n * direction once the movement exceeds the configured threshold. This\n * prevents diagonal gestures from triggering both scroll and swipe behaviors.\n *\n * @example\n * ```tsx\n * const { state: tracking, onPointerDown } = usePointerTracking({ enabled: true });\n * const { lockedAxis, isLocked } = useDirectionalLock({\n * tracking,\n * lockThreshold: 10,\n * });\n *\n * // lockedAxis will be \"horizontal\" or \"vertical\" once determined\n * ```\n */\nexport function useDirectionalLock(options: UseDirectionalLockOptions): UseDirectionalLockResult {\n const { tracking, lockThreshold = DEFAULT_LOCK_THRESHOLD } = options;\n\n const [lockedAxis, setLockedAxis] = React.useState<GestureAxis | null>(null);\n\n const reset = React.useCallback(() => {\n setLockedAxis(null);\n }, []);\n\n // Determine direction when tracking is active\n React.useEffect(() => {\n // Reset lock when pointer is released\n if (!tracking.isDown) {\n if (lockedAxis !== null) {\n reset();\n }\n return;\n }\n\n // Already locked, no need to recalculate\n if (lockedAxis !== null) {\n return;\n }\n\n // Need start and current positions\n if (!tracking.start || !tracking.current) {\n return;\n }\n\n const deltaX = tracking.current.x - tracking.start.x;\n const deltaY = tracking.current.y - tracking.start.y;\n\n // Check if we've exceeded the lock threshold\n const distance = Math.max(Math.abs(deltaX), Math.abs(deltaY));\n if (distance < lockThreshold) {\n return;\n }\n\n // Try to determine axis\n const axis = determineAxis(deltaX, deltaY);\n if (axis !== null) {\n setLockedAxis(axis);\n }\n }, [tracking.isDown, tracking.start, tracking.current, lockedAxis, lockThreshold, reset]);\n\n return {\n lockedAxis,\n isLocked: lockedAxis !== null,\n reset,\n };\n}\n","/**\n * @file Utility functions for gesture detection hooks.\n *\n * Contains shared calculations and helper functions used across\n * gesture-related hooks to avoid code duplication.\n */\nimport type * as React from \"react\";\n\n/**\n * Calculate velocity from displacement and time elapsed.\n *\n * @param displacement - Distance traveled in pixels\n * @param startTime - Start timestamp in milliseconds\n * @param currentTime - Current timestamp in milliseconds\n * @returns Velocity in pixels per millisecond\n */\nexport const calculateVelocity = (\n displacement: number,\n startTime: number,\n currentTime: number,\n): number => {\n const elapsed = currentTime - startTime;\n if (elapsed <= 0) {\n return 0;\n }\n return displacement / elapsed;\n};\n\n/**\n * Determine direction from displacement.\n *\n * @param displacement - Distance from start position\n * @returns -1 for backward (left/up), 0 for no movement, 1 for forward (right/down)\n */\nexport const determineDirection = (displacement: number): -1 | 0 | 1 => {\n if (displacement > 0) {\n return 1;\n }\n if (displacement < 0) {\n return -1;\n }\n return 0;\n};\n\n/**\n * Container props type for gesture handling.\n */\nexport type GestureContainerProps = React.HTMLAttributes<HTMLElement> & {\n style: React.CSSProperties;\n};\n\n/**\n * Merge multiple container props objects for gesture handling.\n *\n * Combines style objects and chains onPointerDown handlers.\n * Useful when combining multiple gesture hooks that each provide\n * their own container props (e.g., swipe input + native gesture guard).\n *\n * @param propsArray - Array of container props to merge\n * @returns Merged container props with combined styles and handlers\n */\nexport const mergeGestureContainerProps = (\n ...propsArray: GestureContainerProps[]\n): GestureContainerProps => {\n const mergedStyle: React.CSSProperties = {};\n const pointerDownHandlers: Array<\n ((event: React.PointerEvent<HTMLElement>) => void) | undefined\n > = [];\n\n for (const props of propsArray) {\n Object.assign(mergedStyle, props.style);\n if (props.onPointerDown) {\n pointerDownHandlers.push(props.onPointerDown);\n }\n }\n\n const handlePointerDown = (event: React.PointerEvent<HTMLElement>) => {\n for (const handler of pointerDownHandlers) {\n handler?.(event);\n }\n };\n\n return {\n onPointerDown: handlePointerDown,\n style: mergedStyle,\n };\n};\n\n// ============================================================================\n// Scroll Detection Utilities\n// ============================================================================\n\n/**\n * Check if an element is scrollable in any direction.\n */\nexport function isScrollableElement(element: HTMLElement): boolean {\n const style = getComputedStyle(element);\n\n const isScrollableX =\n (style.overflowX === \"scroll\" || style.overflowX === \"auto\") &&\n element.scrollWidth > element.clientWidth;\n\n const isScrollableY =\n (style.overflowY === \"scroll\" || style.overflowY === \"auto\") &&\n element.scrollHeight > element.clientHeight;\n\n return isScrollableX || isScrollableY;\n}\n\n/**\n * Check if we should start drag based on scroll state.\n * Returns false if the target is inside a scrollable element.\n */\nexport function shouldStartDrag(\n event: React.PointerEvent,\n container: HTMLElement,\n): boolean {\n // eslint-disable-next-line no-restricted-syntax -- loop variable requires let\n let current = event.target as HTMLElement | null;\n\n while (current !== null && current !== container) {\n if (isScrollableElement(current)) {\n return false;\n }\n current = current.parentElement;\n }\n\n return true;\n}\n\n/**\n * Check if an element or its ancestors are scrollable in the specified direction.\n * Returns true if scrolling is possible and would block the swipe gesture.\n *\n * @param element - The target element to check\n * @param container - The container boundary\n * @param axis - The axis to check (\"x\" or \"y\")\n * @param direction - The swipe direction (1 = right/down, -1 = left/up)\n */\nexport function isScrollableInDirection(\n element: HTMLElement,\n container: HTMLElement,\n axis: \"x\" | \"y\",\n direction: 1 | -1,\n): boolean {\n // eslint-disable-next-line no-restricted-syntax -- loop variable requires let\n let current: HTMLElement | null = element;\n\n while (current !== null && current !== container) {\n const style = getComputedStyle(current);\n const isHorizontal = axis === \"x\";\n\n const overflow = isHorizontal ? style.overflowX : style.overflowY;\n const isScrollable = overflow === \"scroll\" || overflow === \"auto\";\n\n if (isScrollable) {\n const scrollSize = isHorizontal\n ? current.scrollWidth - current.clientWidth\n : current.scrollHeight - current.clientHeight;\n\n if (scrollSize > 0) {\n const scrollPos = isHorizontal ? current.scrollLeft : current.scrollTop;\n\n // If swiping in close direction and not at boundary, block swipe\n if (direction === -1 && scrollPos > 1) {\n return true; // Can scroll left/up, block swipe\n }\n if (direction === 1 && scrollPos < scrollSize - 1) {\n return true; // Can scroll right/down, block swipe\n }\n }\n }\n\n current = current.parentElement;\n }\n\n return false;\n}\n","/**\n * @file Type definitions for gesture input detection hooks.\n *\n * These types support the separation of concerns:\n * - Operation: what to do (navigate, push, pop)\n * - Input: how to command (swipe, click, keyboard)\n * - Presentation: how to show (animation, transition)\n *\n * This file defines types for the Input layer, including the abstract\n * ContinuousOperationState that represents any continuous state transition\n * (whether controlled by human gesture or system animation).\n */\nimport type * as React from \"react\";\n\n/**\n * Axis for gesture detection.\n */\nexport type GestureAxis = \"horizontal\" | \"vertical\";\n\n/**\n * 2D vector for displacement and velocity.\n */\nexport type Vector2 = {\n x: number;\n y: number;\n};\n\n// ============================================================================\n// Continuous Operation State\n// ============================================================================\n// A continuous operation is any state transition that occurs over time,\n// where progress can be observed incrementally. The controlling agent\n// may be human (gesture) or system (animation).\n\n/**\n * Phase of a continuous operation lifecycle.\n * - \"idle\": No operation in progress\n * - \"operating\": Operation is in progress (human or system controlled)\n * - \"ended\": Operation has completed\n */\nexport type ContinuousOperationPhase = \"idle\" | \"operating\" | \"ended\";\n\n/**\n * State of a continuous operation.\n *\n * This is the abstract representation of any operation that occurs over time,\n * whether controlled by human gesture or system animation. Components that\n * accept this state can respond to both input types uniformly.\n */\nexport type ContinuousOperationState = {\n /** Current phase of the operation */\n phase: ContinuousOperationPhase;\n /** Displacement from start position in pixels */\n displacement: Vector2;\n /** Current velocity in pixels per millisecond */\n velocity: Vector2;\n};\n\n/**\n * Initial idle state for ContinuousOperationState.\n */\nexport const IDLE_CONTINUOUS_OPERATION_STATE: ContinuousOperationState = {\n phase: \"idle\",\n displacement: { x: 0, y: 0 },\n velocity: { x: 0, y: 0 },\n};\n\n/**\n * Convert SwipeInputPhase to ContinuousOperationPhase.\n * - \"idle\" → \"idle\"\n * - \"tracking\" | \"swiping\" → \"operating\"\n * - \"ended\" → \"ended\"\n */\nexport function toContinuousPhase(phase: SwipeInputPhase): ContinuousOperationPhase {\n if (phase === \"idle\") {\n return \"idle\";\n }\n if (phase === \"ended\") {\n return \"ended\";\n }\n return \"operating\";\n}\n\n/**\n * Convert SwipeInputState to ContinuousOperationState.\n */\nexport function toContinuousOperationState(state: SwipeInputState): ContinuousOperationState {\n return {\n phase: toContinuousPhase(state.phase),\n displacement: state.displacement,\n velocity: state.velocity,\n };\n}\n\n// ============================================================================\n// Swipe Input (concrete implementation of continuous operation)\n// ============================================================================\n\n/**\n * Phase of swipe input lifecycle.\n * - \"idle\": No swipe in progress\n * - \"tracking\": Pointer down, tracking movement (direction not yet locked)\n * - \"swiping\": Direction locked, actively swiping\n * - \"ended\": Swipe gesture completed\n */\nexport type SwipeInputPhase = \"idle\" | \"tracking\" | \"swiping\" | \"ended\";\n\n/**\n * Point with timestamp for velocity calculation.\n */\nexport type TimestampedPoint = {\n x: number;\n y: number;\n timestamp: number;\n};\n\n/**\n * Swipe input state during gesture.\n */\nexport type SwipeInputState = {\n /** Current phase of the swipe input */\n phase: SwipeInputPhase;\n /** Displacement from start position in pixels */\n displacement: Vector2;\n /** Current velocity in pixels per millisecond */\n velocity: Vector2;\n /**\n * Direction of movement as a number.\n * -1 = backward (left/up), 0 = no movement, 1 = forward (right/down)\n */\n direction: -1 | 0 | 1;\n};\n\n/**\n * Thresholds for swipe input recognition.\n */\nexport type SwipeInputThresholds = {\n /** Minimum distance in pixels to trigger swipe. @default 50 */\n distanceThreshold: number;\n /** Minimum velocity in px/ms to trigger swipe. @default 0.3 */\n velocityThreshold: number;\n /** Distance threshold before direction is locked. @default 10 */\n lockThreshold: number;\n};\n\n/**\n * Options for usePointerTracking hook.\n */\nexport type UsePointerTrackingOptions = {\n /** Whether tracking is enabled */\n enabled: boolean;\n /** Restrict to primary pointer only (ignore multitouch). @default true */\n primaryOnly?: boolean;\n};\n\n/**\n * Result from usePointerTracking hook.\n */\nexport type UsePointerTrackingResult = {\n /** Current tracking state */\n state: PointerTrackingState;\n /** Handler to attach to onPointerDown */\n onPointerDown: (event: React.PointerEvent) => void;\n /** Reset tracking state */\n reset: () => void;\n};\n\n/**\n * Internal pointer tracking state.\n */\nexport type PointerTrackingState = {\n /** Whether pointer is currently down */\n isDown: boolean;\n /** Start position and timestamp */\n start: TimestampedPoint | null;\n /** Current position and timestamp */\n current: TimestampedPoint | null;\n /** Active pointer ID */\n pointerId: number | null;\n /** Whether tracking ended via pointercancel (not pointerup) */\n wasCanceled: boolean;\n};\n\n/**\n * Options for useDirectionalLock hook.\n */\nexport type UseDirectionalLockOptions = {\n /** Pointer tracking state from usePointerTracking */\n tracking: PointerTrackingState;\n /** Lock threshold in pixels. @default 10 */\n lockThreshold?: number;\n};\n\n/**\n * Result from useDirectionalLock hook.\n */\nexport type UseDirectionalLockResult = {\n /** Locked axis, or null if not yet locked */\n lockedAxis: GestureAxis | null;\n /** Whether lock has been determined */\n isLocked: boolean;\n /** Reset the lock state */\n reset: () => void;\n};\n\n/**\n * Options for useScrollBoundary hook.\n */\nexport type UseScrollBoundaryOptions = {\n /** Scroll container ref. If null, checks document scroll. */\n containerRef: React.RefObject<HTMLElement | null>;\n /** Axis to monitor */\n axis: GestureAxis;\n /** Tolerance in pixels for \"at boundary\" detection. @default 1 */\n tolerance?: number;\n};\n\n/**\n * Result from useScrollBoundary hook.\n */\nexport type UseScrollBoundaryResult = {\n /** Whether at the start boundary (top/left) */\n atStart: boolean;\n /** Whether at the end boundary (bottom/right) */\n atEnd: boolean;\n /** Current scroll position */\n scrollPosition: number;\n /** Maximum scroll position */\n maxScrollPosition: number;\n};\n\n/**\n * Filter function to determine if a pointer event should start tracking.\n * Receives the pointer event and container element.\n * Return true to allow tracking, false to ignore the event.\n */\nexport type PointerStartFilter = (\n event: React.PointerEvent,\n container: HTMLElement,\n) => boolean;\n\n/**\n * Options for useSwipeInput hook.\n */\nexport type UseSwipeInputOptions = {\n /** Ref to the container element */\n containerRef: React.RefObject<HTMLElement | null>;\n /** Axis to detect swipes on */\n axis: GestureAxis;\n /** Whether swipe detection is enabled. @default true */\n enabled?: boolean;\n /** Swipe thresholds configuration */\n thresholds?: Partial<SwipeInputThresholds>;\n /** Callback when swipe is completed */\n onSwipeEnd?: (state: SwipeInputState) => void;\n /** Whether to enable trackpad two-finger swipe (wheel events). @default true */\n enableWheel?: boolean;\n /**\n * Optional filter to determine if a pointer event should start tracking.\n * If provided, only events that pass this filter will be tracked.\n * Useful for edge-based swipe detection.\n */\n pointerStartFilter?: PointerStartFilter;\n};\n\n/**\n * Result from useSwipeInput hook.\n */\nexport type UseSwipeInputResult = {\n /** Current swipe input state */\n state: SwipeInputState;\n /** Props to spread on the container element */\n containerProps: React.HTMLAttributes<HTMLElement> & {\n style: React.CSSProperties;\n };\n};\n\n/**\n * Edge for edge-originated gestures.\n */\nexport type GestureEdge = \"left\" | \"right\" | \"top\" | \"bottom\";\n\n/**\n * Options for useEdgeSwipeInput hook.\n */\nexport type UseEdgeSwipeInputOptions = {\n /** Ref to the container element */\n containerRef: React.RefObject<HTMLElement | null>;\n /** Which edge to detect swipes from */\n edge: GestureEdge;\n /** Width of the edge detection zone in pixels. @default 20 */\n edgeWidth?: number;\n /** Whether edge swipe detection is enabled. @default true */\n enabled?: boolean;\n /** Swipe thresholds configuration */\n thresholds?: Partial<SwipeInputThresholds>;\n /** Callback when edge swipe is completed */\n onSwipeEnd?: (state: SwipeInputState) => void;\n};\n\n/**\n * Result from useEdgeSwipeInput hook.\n */\nexport type UseEdgeSwipeInputResult = {\n /** Whether the current gesture started from the edge */\n isEdgeGesture: boolean;\n /** Current swipe input state */\n state: SwipeInputState;\n /** Props to spread on the container element */\n containerProps: React.HTMLAttributes<HTMLElement> & {\n style: React.CSSProperties;\n };\n};\n\n/**\n * Options for useNativeGestureGuard hook.\n */\nexport type UseNativeGestureGuardOptions = {\n /** Ref to the container element */\n containerRef: React.RefObject<HTMLElement | null>;\n /** Whether the guard is active */\n active: boolean;\n /** Prevent iOS/macOS edge back gesture. @default true */\n preventEdgeBack?: boolean;\n /** Prevent overscroll bounce effect. @default true */\n preventOverscroll?: boolean;\n /** Width of edge zone where back gesture is prevented. @default 20 */\n edgeWidth?: number;\n};\n\n/**\n * Result from useNativeGestureGuard hook.\n */\nexport type UseNativeGestureGuardResult = {\n /** Props to spread on the container element */\n containerProps: React.HTMLAttributes<HTMLElement> & {\n style: React.CSSProperties;\n };\n};\n\n/**\n * Default swipe input thresholds.\n *\n * - distanceThreshold: 100px is ~27% of a 375px mobile screen\n * - velocityThreshold: 0.5px/ms = 500px/s, a moderate flick speed\n * - lockThreshold: 10px before direction is locked\n */\nexport const DEFAULT_SWIPE_THRESHOLDS: SwipeInputThresholds = {\n distanceThreshold: 100,\n velocityThreshold: 0.5,\n lockThreshold: 10,\n};\n\n/**\n * Default edge width for edge gesture detection.\n */\nexport const DEFAULT_EDGE_WIDTH = 20;\n\n/**\n * Initial idle state for SwipeInputState.\n */\nexport const IDLE_SWIPE_INPUT_STATE: SwipeInputState = {\n phase: \"idle\",\n displacement: { x: 0, y: 0 },\n velocity: { x: 0, y: 0 },\n direction: 0,\n};\n","/**\n * @file Hook for detecting swipe gestures on a container element.\n *\n * Combines pointer tracking and directional locking to detect swipe gestures.\n * Also supports trackpad two-finger swipe via wheel events.\n * Returns swipe state and container props for gesture handling.\n */\nimport * as React from \"react\";\nimport { usePointerTracking } from \"./usePointerTracking.js\";\nimport { useDirectionalLock } from \"./useDirectionalLock.js\";\nimport { useEffectEvent } from \"../useEffectEvent.js\";\nimport { calculateVelocity, determineDirection } from \"./utils.js\";\nimport type {\n GestureAxis,\n SwipeInputState,\n SwipeInputThresholds,\n UseSwipeInputOptions,\n UseSwipeInputResult,\n Vector2,\n} from \"./types.js\";\nimport { DEFAULT_SWIPE_THRESHOLDS, IDLE_SWIPE_INPUT_STATE } from \"./types.js\";\n\n/** Idle timeout to reset wheel state after swipe stops */\nconst WHEEL_RESET_TIMEOUT = 150;\n\n/**\n * Evaluate swipe end and call callback if threshold is met.\n */\nconst evaluateSwipeEnd = (\n displacement: Vector2,\n velocity: Vector2,\n axis: GestureAxis,\n thresholds: SwipeInputThresholds,\n onSwipeEnd: ((state: SwipeInputState) => void) | undefined,\n): void => {\n const axisDisplacement = axis === \"horizontal\" ? displacement.x : displacement.y;\n const axisVelocity = axis === \"horizontal\" ? velocity.x : velocity.y;\n\n const absDisplacement = Math.abs(axisDisplacement);\n const absVelocity = Math.abs(axisVelocity);\n\n const triggered = absDisplacement >= thresholds.distanceThreshold || absVelocity >= thresholds.velocityThreshold;\n\n if (triggered) {\n const direction = determineDirection(axisDisplacement);\n const endState: SwipeInputState = {\n phase: \"ended\",\n displacement,\n velocity,\n direction,\n };\n onSwipeEnd?.(endState);\n }\n};\n\n/**\n * Hook for detecting swipe gestures on a container element.\n */\nexport function useSwipeInput(options: UseSwipeInputOptions): UseSwipeInputResult {\n const {\n containerRef,\n axis,\n enabled = true,\n thresholds: customThresholds,\n onSwipeEnd,\n enableWheel = true,\n pointerStartFilter,\n } = options;\n\n const thresholds: SwipeInputThresholds = {\n ...DEFAULT_SWIPE_THRESHOLDS,\n ...customThresholds,\n };\n\n // Stable callback for swipe end\n const handleSwipeEnd = useEffectEvent(onSwipeEnd);\n\n // ===== Pointer-based swipe tracking =====\n const { state: tracking, onPointerDown: baseOnPointerDown } = usePointerTracking({\n enabled,\n });\n\n // Wrap pointer down handler with optional filter\n const onPointerDown = React.useCallback(\n (event: React.PointerEvent) => {\n if (!enabled) {\n return;\n }\n if (pointerStartFilter) {\n const container = containerRef.current;\n if (!container) {\n return;\n }\n if (!pointerStartFilter(event, container)) {\n return;\n }\n }\n baseOnPointerDown(event);\n },\n [enabled, pointerStartFilter, containerRef, baseOnPointerDown],\n );\n\n const { lockedAxis, isLocked } = useDirectionalLock({\n tracking,\n lockThreshold: thresholds.lockThreshold,\n });\n\n const lastActiveStateRef = React.useRef<SwipeInputState | null>(null);\n\n // Prevent native scroll when swiping on iOS\n const isLockedToSwipeAxisRef = React.useRef(false);\n\n React.useEffect(() => {\n isLockedToSwipeAxisRef.current = isLocked ? lockedAxis === axis : false;\n }, [isLocked, lockedAxis, axis]);\n\n React.useEffect(() => {\n const container = containerRef.current;\n if (!container || !enabled) {\n return;\n }\n const disableTouchMove = (event: TouchEvent) => {\n event.preventDefault();\n };\n const handleTouchStart = (event: TouchEvent) => {\n if (isLockedToSwipeAxisRef.current) {\n event.preventDefault();\n }\n document.addEventListener(\"touchmove\", disableTouchMove, { passive: false });\n };\n const handleTouchEnd = () => {\n document.removeEventListener(\"touchmove\", disableTouchMove);\n };\n document.addEventListener(\"touchend\", handleTouchEnd);\n document.addEventListener(\"touchcancel\", handleTouchEnd);\n container.addEventListener(\"touchstart\", handleTouchStart, { passive: false });\n\n return () => {\n container.removeEventListener(\"touchstart\", handleTouchStart);\n document.removeEventListener(\"touchend\", handleTouchEnd);\n document.removeEventListener(\"touchcancel\", handleTouchEnd);\n };\n }, [containerRef, enabled]);\n\n // ===== Wheel-based swipe tracking =====\n const [wheelState, setWheelState] = React.useState<SwipeInputState>(IDLE_SWIPE_INPUT_STATE);\n const wheelAccumulatedRef = React.useRef({ x: 0, y: 0 });\n const wheelIdleTimerRef = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n const wheelLockedRef = React.useRef(false);\n const wheelLockedAxisRef = React.useRef<GestureAxis | null>(null);\n\n const resetWheelState = React.useCallback(() => {\n wheelAccumulatedRef.current = { x: 0, y: 0 };\n wheelLockedRef.current = false;\n wheelLockedAxisRef.current = null;\n setWheelState(IDLE_SWIPE_INPUT_STATE);\n }, []);\n\n const endWheelSwipe = React.useCallback(() => {\n const displacement = { ...wheelAccumulatedRef.current };\n evaluateSwipeEnd(displacement, { x: 0, y: 0 }, axis, thresholds, handleSwipeEnd);\n resetWheelState();\n }, [axis, thresholds, handleSwipeEnd, resetWheelState]);\n\n const handleWheel = useEffectEvent((event: WheelEvent) => {\n if (!enabled || !enableWheel || tracking.isDown) {\n return;\n }\n\n const { deltaX, deltaY } = event;\n\n // Direction lock\n if (!wheelLockedRef.current) {\n const absX = Math.abs(deltaX);\n const absY = Math.abs(deltaY);\n\n if (absX >= thresholds.lockThreshold || absY >= thresholds.lockThreshold) {\n wheelLockedRef.current = true;\n wheelLockedAxisRef.current = absX > absY ? \"horizontal\" : \"vertical\";\n }\n }\n\n // If locked to wrong axis, ignore\n if (wheelLockedRef.current && wheelLockedAxisRef.current !== axis) {\n return;\n }\n\n // Accumulate displacement (negate: wheel delta is scroll direction)\n wheelAccumulatedRef.current.x -= deltaX;\n wheelAccumulatedRef.current.y -= deltaY;\n\n const accumulated = wheelAccumulatedRef.current;\n const axisDisplacement = axis === \"horizontal\" ? accumulated.x : accumulated.y;\n\n setWheelState({\n phase: \"swiping\",\n displacement: { ...accumulated },\n velocity: { x: 0, y: 0 },\n direction: determineDirection(axisDisplacement),\n });\n\n // When wheel stops, treat as \"release\"\n if (wheelIdleTimerRef.current !== null) {\n clearTimeout(wheelIdleTimerRef.current);\n }\n wheelIdleTimerRef.current = setTimeout(endWheelSwipe, WHEEL_RESET_TIMEOUT);\n });\n\n // Set up wheel event listener\n React.useEffect(() => {\n const container = containerRef.current;\n if (!container || !enabled || !enableWheel) {\n return;\n }\n\n const listener = (event: WheelEvent) => {\n event.preventDefault();\n handleWheel(event);\n };\n\n container.addEventListener(\"wheel\", listener, { passive: false });\n\n return () => {\n container.removeEventListener(\"wheel\", listener);\n if (wheelIdleTimerRef.current !== null) {\n clearTimeout(wheelIdleTimerRef.current);\n }\n };\n }, [containerRef, enabled, enableWheel, handleWheel]);\n\n React.useEffect(() => {\n return () => {\n if (wheelIdleTimerRef.current !== null) {\n clearTimeout(wheelIdleTimerRef.current);\n }\n };\n }, []);\n\n // ===== Pointer swipe state =====\n const pointerState = React.useMemo<SwipeInputState>(() => {\n if (!tracking.isDown || !tracking.start || !tracking.current) {\n return IDLE_SWIPE_INPUT_STATE;\n }\n\n const deltaX = tracking.current.x - tracking.start.x;\n const deltaY = tracking.current.y - tracking.start.y;\n const displacement = { x: deltaX, y: deltaY };\n\n const velocity = {\n x: calculateVelocity(deltaX, tracking.start.timestamp, tracking.current.timestamp),\n y: calculateVelocity(deltaY, tracking.start.timestamp, tracking.current.timestamp),\n };\n\n if (!isLocked || lockedAxis !== axis) {\n return { phase: \"tracking\", displacement, velocity, direction: 0 };\n }\n\n const axisDisplacement = axis === \"horizontal\" ? deltaX : deltaY;\n return {\n phase: \"swiping\",\n displacement,\n velocity,\n direction: determineDirection(axisDisplacement),\n };\n }, [tracking.isDown, tracking.start, tracking.current, isLocked, lockedAxis, axis]);\n\n React.useEffect(() => {\n if (pointerState.phase !== \"idle\") {\n lastActiveStateRef.current = pointerState;\n }\n }, [pointerState]);\n\n // Handle pointer up (but not cancel)\n React.useEffect(() => {\n if (tracking.isDown) {\n return;\n }\n\n const lastState = lastActiveStateRef.current;\n if (!lastState || (lastState.phase !== \"swiping\" && lastState.phase !== \"tracking\")) {\n return;\n }\n\n lastActiveStateRef.current = null;\n\n // Skip navigation if the gesture was canceled (e.g., browser took over for native scroll)\n if (tracking.wasCanceled) {\n return;\n }\n\n evaluateSwipeEnd(lastState.displacement, lastState.velocity, axis, thresholds, handleSwipeEnd);\n }, [tracking.isDown, tracking.wasCanceled, axis, thresholds, handleSwipeEnd]);\n\n // Merge states\n const state = pointerState.phase !== \"idle\" ? pointerState : wheelState;\n\n const containerProps = React.useMemo(() => {\n const touchAction = axis === \"horizontal\" ? \"pan-y pinch-zoom\" : \"pan-x pinch-zoom\";\n return {\n onPointerDown,\n style: {\n touchAction,\n userSelect: \"none\" as const,\n WebkitUserSelect: \"none\" as const,\n },\n };\n }, [axis, onPointerDown]);\n\n return { state, containerProps };\n}\n","/**\n * @file Hook for detecting swipe gestures that originate from the edge of a container.\n *\n * Edge swipes are commonly used for \"swipe back\" navigation in mobile apps.\n * This hook detects swipes that start within a configurable edge zone.\n *\n * Built on top of useSwipeInput with edge zone filtering.\n */\nimport * as React from \"react\";\nimport { useSwipeInput } from \"./useSwipeInput.js\";\nimport type {\n GestureAxis,\n GestureEdge,\n SwipeInputState,\n UseEdgeSwipeInputOptions,\n UseEdgeSwipeInputResult,\n} from \"./types.js\";\nimport { DEFAULT_EDGE_WIDTH, DEFAULT_SWIPE_THRESHOLDS, IDLE_SWIPE_INPUT_STATE } from \"./types.js\";\n\n/**\n * Get the axis associated with an edge.\n */\nconst getAxisForEdge = (edge: GestureEdge): GestureAxis => {\n if (edge === \"left\" || edge === \"right\") {\n return \"horizontal\";\n }\n return \"vertical\";\n};\n\n/**\n * Check if a point is within the edge zone of a container.\n */\nconst isInEdgeZone = (\n clientX: number,\n clientY: number,\n container: HTMLElement,\n edge: GestureEdge,\n edgeWidth: number,\n): boolean => {\n const rect = container.getBoundingClientRect();\n\n switch (edge) {\n case \"left\":\n return clientX >= rect.left && clientX <= rect.left + edgeWidth;\n case \"right\":\n return clientX >= rect.right - edgeWidth && clientX <= rect.right;\n case \"top\":\n return clientY >= rect.top && clientY <= rect.top + edgeWidth;\n case \"bottom\":\n return clientY >= rect.bottom - edgeWidth && clientY <= rect.bottom;\n }\n};\n\n/**\n * Hook for detecting swipe gestures that originate from the edge of a container.\n *\n * This is useful for implementing \"swipe back\" navigation patterns where\n * the user must start their swipe from the edge of the screen.\n *\n * @example\n * ```tsx\n * const containerRef = useRef<HTMLDivElement>(null);\n * const { isEdgeGesture, state, containerProps } = useEdgeSwipeInput({\n * containerRef,\n * edge: \"left\",\n * edgeWidth: 20,\n * onSwipeEnd: (state) => {\n * if (state.direction === 1) goBack();\n * },\n * });\n *\n * return <div ref={containerRef} {...containerProps}>{children}</div>;\n * ```\n */\nexport function useEdgeSwipeInput(options: UseEdgeSwipeInputOptions): UseEdgeSwipeInputResult {\n const {\n containerRef,\n edge,\n edgeWidth = DEFAULT_EDGE_WIDTH,\n enabled = true,\n thresholds: customThresholds,\n onSwipeEnd,\n } = options;\n\n const thresholds = {\n ...DEFAULT_SWIPE_THRESHOLDS,\n ...customThresholds,\n };\n\n const axis = getAxisForEdge(edge);\n\n // Track whether the current gesture started from the edge\n const [isEdgeGesture, setIsEdgeGesture] = React.useState(false);\n\n // Create edge zone filter for pointer events\n const pointerStartFilter = React.useCallback(\n (event: React.PointerEvent, container: HTMLElement): boolean => {\n const inEdge = isInEdgeZone(event.clientX, event.clientY, container, edge, edgeWidth);\n setIsEdgeGesture(inEdge);\n return inEdge;\n },\n [edge, edgeWidth],\n );\n\n // Use base swipe input with edge filtering\n const { state, containerProps } = useSwipeInput({\n containerRef,\n axis,\n enabled,\n thresholds,\n onSwipeEnd,\n enableWheel: false, // Edge swipe doesn't use wheel events\n pointerStartFilter,\n });\n\n // Reset edge gesture state when swipe ends\n React.useEffect(() => {\n if (state.phase === \"idle\") {\n setIsEdgeGesture(false);\n }\n }, [state.phase]);\n\n // If not an edge gesture, return idle state\n const effectiveState: SwipeInputState = isEdgeGesture ? state : IDLE_SWIPE_INPUT_STATE;\n\n return {\n isEdgeGesture,\n state: effectiveState,\n containerProps,\n };\n}\n","/**\n * @file Hook for preventing conflicts with native OS gestures.\n *\n * This hook helps prevent conflicts with:\n * - iOS/macOS edge swipe back navigation\n * - Overscroll bounce effects\n *\n * It applies appropriate CSS properties and event handlers to the container.\n */\nimport * as React from \"react\";\nimport type {\n UseNativeGestureGuardOptions,\n UseNativeGestureGuardResult,\n} from \"./types.js\";\nimport { DEFAULT_EDGE_WIDTH } from \"./types.js\";\n\n/**\n * Check if a pointer event is within the left edge zone.\n */\nconst isInLeftEdge = (clientX: number, container: HTMLElement, edgeWidth: number): boolean => {\n const rect = container.getBoundingClientRect();\n return clientX >= rect.left && clientX <= rect.left + edgeWidth;\n};\n\n/**\n * Hook for preventing conflicts with native OS gestures.\n *\n * When active, this hook:\n * - Prevents iOS/macOS edge back gesture by capturing pointerdown events in the edge zone\n * - Prevents overscroll bounce effect using CSS overscroll-behavior\n * - Dynamically applies overscroll-behavior: none to html element during gesture\n *\n * @example\n * ```tsx\n * const containerRef = useRef<HTMLDivElement>(null);\n * const { containerProps } = useNativeGestureGuard({\n * containerRef,\n * active: isSwipeActive,\n * preventEdgeBack: true,\n * preventOverscroll: true,\n * });\n *\n * return <div ref={containerRef} {...containerProps}>{children}</div>;\n * ```\n */\nexport function useNativeGestureGuard(options: UseNativeGestureGuardOptions): UseNativeGestureGuardResult {\n const {\n containerRef,\n active,\n preventEdgeBack = true,\n preventOverscroll = true,\n edgeWidth = DEFAULT_EDGE_WIDTH,\n } = options;\n\n // Track previous html overscroll-behavior value for restoration\n const previousHtmlOverscrollRef = React.useRef<string | null>(null);\n\n // Apply overscroll-behavior to html synchronously (called from onPointerDown)\n const applyHtmlOverscroll = React.useCallback(() => {\n if (!preventOverscroll) {\n return;\n }\n\n const html = document.documentElement;\n if (previousHtmlOverscrollRef.current === null) {\n previousHtmlOverscrollRef.current = html.style.overscrollBehavior;\n }\n html.style.overscrollBehavior = \"none\";\n }, [preventOverscroll]);\n\n // Remove overscroll-behavior from html when gesture ends\n React.useEffect(() => {\n if (active || !preventOverscroll) {\n return;\n }\n\n // Cleanup: restore previous value when deactivated\n if (previousHtmlOverscrollRef.current !== null) {\n document.documentElement.style.overscrollBehavior = previousHtmlOverscrollRef.current;\n previousHtmlOverscrollRef.current = null;\n }\n }, [active, preventOverscroll]);\n\n // Cleanup on unmount\n React.useEffect(() => {\n return () => {\n if (previousHtmlOverscrollRef.current !== null) {\n document.documentElement.style.overscrollBehavior = previousHtmlOverscrollRef.current;\n previousHtmlOverscrollRef.current = null;\n }\n };\n }, []);\n\n // Pointer down handler that prevents edge back gesture\n // Note: This must run on EVERY pointerdown in edge zone, not just when active,\n // because browser gesture recognition starts immediately on first touch.\n const onPointerDown = React.useCallback((event: React.PointerEvent) => {\n if (!preventEdgeBack) {\n return;\n }\n\n const container = containerRef.current;\n if (!container) {\n return;\n }\n\n // Prevent for touch events in the left edge zone\n // This must happen immediately, before we know if it's \"our\" gesture\n if (event.pointerType === \"touch\" && isInLeftEdge(event.clientX, container, edgeWidth)) {\n // Apply html overscroll-behavior synchronously before browser can recognize gesture\n applyHtmlOverscroll();\n // Prevent the browser from handling this as a back gesture\n event.preventDefault();\n }\n }, [preventEdgeBack, containerRef, edgeWidth, applyHtmlOverscroll]);\n\n // Build container props\n // Styles are applied immediately (not waiting for active) to prevent browser gestures\n const containerProps = React.useMemo(() => {\n const style: React.CSSProperties = {\n // Always apply to prevent browser navigation gestures\n overscrollBehavior: preventOverscroll ? \"contain\" : undefined,\n WebkitOverflowScrolling: \"touch\",\n };\n\n return {\n onPointerDown: preventEdgeBack ? onPointerDown : undefined,\n style,\n };\n }, [preventOverscroll, preventEdgeBack, onPointerDown]);\n\n return {\n containerProps,\n };\n}\n"],"names":["INITIAL_STATE","createTimestampedPoint","clientX","clientY","usePointerTracking","options","enabled","primaryOnly","state","setState","React","reset","handlePointerDown","useEffectEvent","event","point","handlePointerMove","prev","handlePointerUp","handlePointerCancel","shouldTrackDocument","useDocumentPointerEvents","DEFAULT_LOCK_THRESHOLD","determineAxis","deltaX","deltaY","absX","absY","useDirectionalLock","tracking","lockThreshold","lockedAxis","setLockedAxis","axis","calculateVelocity","displacement","startTime","currentTime","elapsed","determineDirection","mergeGestureContainerProps","propsArray","mergedStyle","pointerDownHandlers","props","handler","isScrollableInDirection","element","container","direction","current","style","isHorizontal","overflow","scrollSize","scrollPos","IDLE_CONTINUOUS_OPERATION_STATE","DEFAULT_SWIPE_THRESHOLDS","DEFAULT_EDGE_WIDTH","IDLE_SWIPE_INPUT_STATE","WHEEL_RESET_TIMEOUT","evaluateSwipeEnd","velocity","thresholds","onSwipeEnd","axisDisplacement","axisVelocity","absDisplacement","absVelocity","useSwipeInput","containerRef","customThresholds","enableWheel","pointerStartFilter","handleSwipeEnd","baseOnPointerDown","onPointerDown","isLocked","lastActiveStateRef","isLockedToSwipeAxisRef","disableTouchMove","handleTouchStart","handleTouchEnd","wheelState","setWheelState","wheelAccumulatedRef","wheelIdleTimerRef","wheelLockedRef","wheelLockedAxisRef","resetWheelState","endWheelSwipe","handleWheel","accumulated","listener","pointerState","lastState","containerProps","getAxisForEdge","edge","isInEdgeZone","edgeWidth","rect","useEdgeSwipeInput","isEdgeGesture","setIsEdgeGesture","inEdge","isInLeftEdge","useNativeGestureGuard","active","preventEdgeBack","preventOverscroll","previousHtmlOverscrollRef","applyHtmlOverscroll","html"],"mappings":"qXAmBMA,EAAsC,CAC1C,OAAQ,GACR,MAAO,KACP,QAAS,KACT,UAAW,KACX,YAAa,EACf,EAKMC,EAAyB,CAACC,EAAiBC,KAAuC,CACtF,EAAGD,EACH,EAAGC,EACH,UAAW,YAAY,IAAA,CACzB,GAsBO,SAASC,EAAmBC,EAA8D,CAC/F,KAAM,CAAE,QAAAC,EAAS,YAAAC,EAAc,EAAA,EAASF,EAElC,CAACG,EAAOC,CAAQ,EAAIC,EAAM,SAA+BV,CAAa,EAEtEW,EAAQD,EAAM,YAAY,IAAM,CACpCD,EAAST,CAAa,CACxB,EAAG,CAAA,CAAE,EAECY,EAAoBC,iBAAgBC,GAA8B,CAWtE,GAVI,CAACR,GAKDC,GAAe,CAACO,EAAM,WAKtBA,EAAM,cAAgB,SAAWA,EAAM,SAAW,EACpD,OAGF,MAAMC,EAAQd,EAAuBa,EAAM,QAASA,EAAM,OAAO,EAEjEL,EAAS,CACP,OAAQ,GACR,MAAOM,EACP,QAASA,EACT,UAAWD,EAAM,UACjB,YAAa,EAAA,CACd,CACH,CAAC,EAEKE,EAAoBH,iBAAgBC,GAAwB,CAEhE,GAAIN,EAAM,YAAcM,EAAM,UAC5B,OAGF,MAAMC,EAAQd,EAAuBa,EAAM,QAASA,EAAM,OAAO,EAEjEL,EAAUQ,IAAU,CAClB,GAAGA,EACH,QAASF,CAAA,EACT,CACJ,CAAC,EAEKG,EAAkBL,EAAAA,eAAe,IAAM,CAC3CJ,EAAST,CAAa,CACxB,CAAC,EAEKmB,EAAsBN,EAAAA,eAAe,IAAM,CAC/CJ,EAAS,CAAE,GAAGT,EAAe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AKXC,EAA0B,UAAY,OACxC,SAAS,gBAAgB,MAAM,mBAAqBA,EAA0B,QAC9EA,EAA0B,QAAU,KAExC,EAAG,CAACH,EAAQE,CAAiB,CAAC,EAG9BpG,EAAM,UAAU,IACP,IAAM,CACPqG,EAA0B,UAAY,OACxC,SAAS,gBAAgB,MAAM,mBAAqBA,EAA0B,QAC9EA,EAA0B,QAAU,KAExC,EACC,CAAA,CAAE,EAKL,MAAMnC,EAAgBlE,EAAM,YAAaI,GAA8B,CACrE,GAAI,CAAC+F,EACH,OAGF,MAAM7D,EAAYsB,EAAa,QAC1BtB,GAMDlC,EAAM,cAAgB,SAAW4F,GAAa5F,EAAM,QAASkC,EAAWoD,CAAS,IAEnFY,EAAA,EAEAlG,EAAM,eAAA,EAEV,EAAG,CAAC+F,EAAiBvC,EAAc8B,EAAWY,CAAmB,CAAC,EAiBlE,MAAO,CACL,eAdqBtG,EAAM,QAAQ,KAO5B,CACL,cAAemG,EAAkBjC,EAAgB,OACjD,MARiC,CAEjC,mBAAoBkC,EAAoB,UAAY,OACpD,wBAAyB,OAAA,CAKzB,GAED,CAACA,EAAmBD,EAAiBjC,CAAa,CAAC,CAGpD,CAEJ"}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import * as c from "react";
|
|
2
|
+
import { u as S, b as V } from "./useDocumentPointerEvents-DXxw3qWj.js";
|
|
3
|
+
const I = {
|
|
4
|
+
isDown: !1,
|
|
5
|
+
start: null,
|
|
6
|
+
current: null,
|
|
7
|
+
pointerId: null,
|
|
8
|
+
wasCanceled: !1
|
|
9
|
+
}, H = (s, e) => ({
|
|
10
|
+
x: s,
|
|
11
|
+
y: e,
|
|
12
|
+
timestamp: performance.now()
|
|
13
|
+
});
|
|
14
|
+
function j(s) {
|
|
15
|
+
const { enabled: e, primaryOnly: r = !0 } = s, [t, n] = c.useState(I), l = c.useCallback(() => {
|
|
16
|
+
n(I);
|
|
17
|
+
}, []), i = S((u) => {
|
|
18
|
+
if (!e || r && !u.isPrimary || u.pointerType === "mouse" && u.button !== 0)
|
|
19
|
+
return;
|
|
20
|
+
const m = H(u.clientX, u.clientY);
|
|
21
|
+
n({
|
|
22
|
+
isDown: !0,
|
|
23
|
+
start: m,
|
|
24
|
+
current: m,
|
|
25
|
+
pointerId: u.pointerId,
|
|
26
|
+
wasCanceled: !1
|
|
27
|
+
});
|
|
28
|
+
}), f = S((u) => {
|
|
29
|
+
if (t.pointerId !== u.pointerId)
|
|
30
|
+
return;
|
|
31
|
+
const m = H(u.clientX, u.clientY);
|
|
32
|
+
n((v) => ({
|
|
33
|
+
...v,
|
|
34
|
+
current: m
|
|
35
|
+
}));
|
|
36
|
+
}), d = S(() => {
|
|
37
|
+
n(I);
|
|
38
|
+
}), h = S(() => {
|
|
39
|
+
n({ ...I, wasCanceled: !0 });
|
|
40
|
+
}), o = t.isDown ? e : !1;
|
|
41
|
+
return V(o, {
|
|
42
|
+
onMove: f,
|
|
43
|
+
onUp: d,
|
|
44
|
+
onCancel: h
|
|
45
|
+
}), c.useEffect(() => {
|
|
46
|
+
!e && t.isDown && l();
|
|
47
|
+
}, [e, t.isDown, l]), {
|
|
48
|
+
state: t,
|
|
49
|
+
onPointerDown: i,
|
|
50
|
+
reset: l
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const K = 10, Z = (s, e) => {
|
|
54
|
+
const r = Math.abs(s), t = Math.abs(e);
|
|
55
|
+
return r === 0 && t === 0 ? null : r > t * 1.5 ? "horizontal" : t > r * 1.5 ? "vertical" : null;
|
|
56
|
+
};
|
|
57
|
+
function q(s) {
|
|
58
|
+
const { tracking: e, lockThreshold: r = K } = s, [t, n] = c.useState(null), l = c.useCallback(() => {
|
|
59
|
+
n(null);
|
|
60
|
+
}, []);
|
|
61
|
+
return c.useEffect(() => {
|
|
62
|
+
if (!e.isDown) {
|
|
63
|
+
t !== null && l();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (t !== null || !e.start || !e.current)
|
|
67
|
+
return;
|
|
68
|
+
const i = e.current.x - e.start.x, f = e.current.y - e.start.y;
|
|
69
|
+
if (Math.max(Math.abs(i), Math.abs(f)) < r)
|
|
70
|
+
return;
|
|
71
|
+
const h = Z(i, f);
|
|
72
|
+
h !== null && n(h);
|
|
73
|
+
}, [e.isDown, e.start, e.current, t, r, l]), {
|
|
74
|
+
lockedAxis: t,
|
|
75
|
+
isLocked: t !== null,
|
|
76
|
+
reset: l
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const U = (s, e, r) => {
|
|
80
|
+
const t = r - e;
|
|
81
|
+
return t <= 0 ? 0 : s / t;
|
|
82
|
+
}, A = (s) => s > 0 ? 1 : s < 0 ? -1 : 0, re = (...s) => {
|
|
83
|
+
const e = {}, r = [];
|
|
84
|
+
for (const n of s)
|
|
85
|
+
Object.assign(e, n.style), n.onPointerDown && r.push(n.onPointerDown);
|
|
86
|
+
return {
|
|
87
|
+
onPointerDown: (n) => {
|
|
88
|
+
for (const l of r)
|
|
89
|
+
l?.(n);
|
|
90
|
+
},
|
|
91
|
+
style: e
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
function oe(s, e, r, t) {
|
|
95
|
+
let n = s;
|
|
96
|
+
for (; n !== null && n !== e; ) {
|
|
97
|
+
const l = getComputedStyle(n), i = r === "x", f = i ? l.overflowX : l.overflowY;
|
|
98
|
+
if (f === "scroll" || f === "auto") {
|
|
99
|
+
const h = i ? n.scrollWidth - n.clientWidth : n.scrollHeight - n.clientHeight;
|
|
100
|
+
if (h > 0) {
|
|
101
|
+
const o = i ? n.scrollLeft : n.scrollTop;
|
|
102
|
+
if (t === -1 && o > 1 || t === 1 && o < h - 1)
|
|
103
|
+
return !0;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
n = n.parentElement;
|
|
107
|
+
}
|
|
108
|
+
return !1;
|
|
109
|
+
}
|
|
110
|
+
const se = {
|
|
111
|
+
phase: "idle",
|
|
112
|
+
displacement: { x: 0, y: 0 },
|
|
113
|
+
velocity: { x: 0, y: 0 }
|
|
114
|
+
}, F = {
|
|
115
|
+
distanceThreshold: 100,
|
|
116
|
+
velocityThreshold: 0.5,
|
|
117
|
+
lockThreshold: 10
|
|
118
|
+
}, G = 20, R = {
|
|
119
|
+
phase: "idle",
|
|
120
|
+
displacement: { x: 0, y: 0 },
|
|
121
|
+
velocity: { x: 0, y: 0 },
|
|
122
|
+
direction: 0
|
|
123
|
+
}, J = 150, B = (s, e, r, t, n) => {
|
|
124
|
+
const l = r === "horizontal" ? s.x : s.y, i = r === "horizontal" ? e.x : e.y, f = Math.abs(l), d = Math.abs(i);
|
|
125
|
+
if (f >= t.distanceThreshold || d >= t.velocityThreshold) {
|
|
126
|
+
const o = A(l);
|
|
127
|
+
n?.({
|
|
128
|
+
phase: "ended",
|
|
129
|
+
displacement: s,
|
|
130
|
+
velocity: e,
|
|
131
|
+
direction: o
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
function Q(s) {
|
|
136
|
+
const {
|
|
137
|
+
containerRef: e,
|
|
138
|
+
axis: r,
|
|
139
|
+
enabled: t = !0,
|
|
140
|
+
thresholds: n,
|
|
141
|
+
onSwipeEnd: l,
|
|
142
|
+
enableWheel: i = !0,
|
|
143
|
+
pointerStartFilter: f
|
|
144
|
+
} = s, d = {
|
|
145
|
+
...F,
|
|
146
|
+
...n
|
|
147
|
+
}, h = S(l), { state: o, onPointerDown: u } = j({
|
|
148
|
+
enabled: t
|
|
149
|
+
}), m = c.useCallback(
|
|
150
|
+
(a) => {
|
|
151
|
+
if (t) {
|
|
152
|
+
if (f) {
|
|
153
|
+
const p = e.current;
|
|
154
|
+
if (!p || !f(a, p))
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
u(a);
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
[t, f, e, u]
|
|
161
|
+
), { lockedAxis: v, isLocked: b } = q({
|
|
162
|
+
tracking: o,
|
|
163
|
+
lockThreshold: d.lockThreshold
|
|
164
|
+
}), y = c.useRef(null), k = c.useRef(!1);
|
|
165
|
+
c.useEffect(() => {
|
|
166
|
+
k.current = b ? v === r : !1;
|
|
167
|
+
}, [b, v, r]), c.useEffect(() => {
|
|
168
|
+
const a = e.current;
|
|
169
|
+
if (!a || !t)
|
|
170
|
+
return;
|
|
171
|
+
const p = (T) => {
|
|
172
|
+
T.preventDefault();
|
|
173
|
+
}, E = (T) => {
|
|
174
|
+
k.current && T.preventDefault(), document.addEventListener("touchmove", p, { passive: !1 });
|
|
175
|
+
}, w = () => {
|
|
176
|
+
document.removeEventListener("touchmove", p);
|
|
177
|
+
};
|
|
178
|
+
return document.addEventListener("touchend", w), document.addEventListener("touchcancel", w), a.addEventListener("touchstart", E, { passive: !1 }), () => {
|
|
179
|
+
a.removeEventListener("touchstart", E), document.removeEventListener("touchend", w), document.removeEventListener("touchcancel", w);
|
|
180
|
+
};
|
|
181
|
+
}, [e, t]);
|
|
182
|
+
const [L, M] = c.useState(R), x = c.useRef({ x: 0, y: 0 }), D = c.useRef(null), P = c.useRef(!1), C = c.useRef(null), O = c.useCallback(() => {
|
|
183
|
+
x.current = { x: 0, y: 0 }, P.current = !1, C.current = null, M(R);
|
|
184
|
+
}, []), N = c.useCallback(() => {
|
|
185
|
+
const a = { ...x.current };
|
|
186
|
+
B(a, { x: 0, y: 0 }, r, d, h), O();
|
|
187
|
+
}, [r, d, h, O]), _ = S((a) => {
|
|
188
|
+
if (!t || !i || o.isDown)
|
|
189
|
+
return;
|
|
190
|
+
const { deltaX: p, deltaY: E } = a;
|
|
191
|
+
if (!P.current) {
|
|
192
|
+
const W = Math.abs(p), z = Math.abs(E);
|
|
193
|
+
(W >= d.lockThreshold || z >= d.lockThreshold) && (P.current = !0, C.current = W > z ? "horizontal" : "vertical");
|
|
194
|
+
}
|
|
195
|
+
if (P.current && C.current !== r)
|
|
196
|
+
return;
|
|
197
|
+
x.current.x -= p, x.current.y -= E;
|
|
198
|
+
const w = x.current, T = r === "horizontal" ? w.x : w.y;
|
|
199
|
+
M({
|
|
200
|
+
phase: "swiping",
|
|
201
|
+
displacement: { ...w },
|
|
202
|
+
velocity: { x: 0, y: 0 },
|
|
203
|
+
direction: A(T)
|
|
204
|
+
}), D.current !== null && clearTimeout(D.current), D.current = setTimeout(N, J);
|
|
205
|
+
});
|
|
206
|
+
c.useEffect(() => {
|
|
207
|
+
const a = e.current;
|
|
208
|
+
if (!a || !t || !i)
|
|
209
|
+
return;
|
|
210
|
+
const p = (E) => {
|
|
211
|
+
E.preventDefault(), _(E);
|
|
212
|
+
};
|
|
213
|
+
return a.addEventListener("wheel", p, { passive: !1 }), () => {
|
|
214
|
+
a.removeEventListener("wheel", p), D.current !== null && clearTimeout(D.current);
|
|
215
|
+
};
|
|
216
|
+
}, [e, t, i, _]), c.useEffect(() => () => {
|
|
217
|
+
D.current !== null && clearTimeout(D.current);
|
|
218
|
+
}, []);
|
|
219
|
+
const g = c.useMemo(() => {
|
|
220
|
+
if (!o.isDown || !o.start || !o.current)
|
|
221
|
+
return R;
|
|
222
|
+
const a = o.current.x - o.start.x, p = o.current.y - o.start.y, E = { x: a, y: p }, w = {
|
|
223
|
+
x: U(a, o.start.timestamp, o.current.timestamp),
|
|
224
|
+
y: U(p, o.start.timestamp, o.current.timestamp)
|
|
225
|
+
};
|
|
226
|
+
return !b || v !== r ? { phase: "tracking", displacement: E, velocity: w, direction: 0 } : {
|
|
227
|
+
phase: "swiping",
|
|
228
|
+
displacement: E,
|
|
229
|
+
velocity: w,
|
|
230
|
+
direction: A(r === "horizontal" ? a : p)
|
|
231
|
+
};
|
|
232
|
+
}, [o.isDown, o.start, o.current, b, v, r]);
|
|
233
|
+
c.useEffect(() => {
|
|
234
|
+
g.phase !== "idle" && (y.current = g);
|
|
235
|
+
}, [g]), c.useEffect(() => {
|
|
236
|
+
if (o.isDown)
|
|
237
|
+
return;
|
|
238
|
+
const a = y.current;
|
|
239
|
+
!a || a.phase !== "swiping" && a.phase !== "tracking" || (y.current = null, !o.wasCanceled && B(a.displacement, a.velocity, r, d, h));
|
|
240
|
+
}, [o.isDown, o.wasCanceled, r, d, h]);
|
|
241
|
+
const X = g.phase !== "idle" ? g : L, Y = c.useMemo(() => ({
|
|
242
|
+
onPointerDown: m,
|
|
243
|
+
style: {
|
|
244
|
+
touchAction: r === "horizontal" ? "pan-y pinch-zoom" : "pan-x pinch-zoom",
|
|
245
|
+
userSelect: "none",
|
|
246
|
+
WebkitUserSelect: "none"
|
|
247
|
+
}
|
|
248
|
+
}), [r, m]);
|
|
249
|
+
return { state: X, containerProps: Y };
|
|
250
|
+
}
|
|
251
|
+
const $ = (s) => s === "left" || s === "right" ? "horizontal" : "vertical", ee = (s, e, r, t, n) => {
|
|
252
|
+
const l = r.getBoundingClientRect();
|
|
253
|
+
switch (t) {
|
|
254
|
+
case "left":
|
|
255
|
+
return s >= l.left && s <= l.left + n;
|
|
256
|
+
case "right":
|
|
257
|
+
return s >= l.right - n && s <= l.right;
|
|
258
|
+
case "top":
|
|
259
|
+
return e >= l.top && e <= l.top + n;
|
|
260
|
+
case "bottom":
|
|
261
|
+
return e >= l.bottom - n && e <= l.bottom;
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
function ce(s) {
|
|
265
|
+
const {
|
|
266
|
+
containerRef: e,
|
|
267
|
+
edge: r,
|
|
268
|
+
edgeWidth: t = G,
|
|
269
|
+
enabled: n = !0,
|
|
270
|
+
thresholds: l,
|
|
271
|
+
onSwipeEnd: i
|
|
272
|
+
} = s, f = {
|
|
273
|
+
...F,
|
|
274
|
+
...l
|
|
275
|
+
}, d = $(r), [h, o] = c.useState(!1), u = c.useCallback(
|
|
276
|
+
(y, k) => {
|
|
277
|
+
const L = ee(y.clientX, y.clientY, k, r, t);
|
|
278
|
+
return o(L), L;
|
|
279
|
+
},
|
|
280
|
+
[r, t]
|
|
281
|
+
), { state: m, containerProps: v } = Q({
|
|
282
|
+
containerRef: e,
|
|
283
|
+
axis: d,
|
|
284
|
+
enabled: n,
|
|
285
|
+
thresholds: f,
|
|
286
|
+
onSwipeEnd: i,
|
|
287
|
+
enableWheel: !1,
|
|
288
|
+
// Edge swipe doesn't use wheel events
|
|
289
|
+
pointerStartFilter: u
|
|
290
|
+
});
|
|
291
|
+
return c.useEffect(() => {
|
|
292
|
+
m.phase === "idle" && o(!1);
|
|
293
|
+
}, [m.phase]), {
|
|
294
|
+
isEdgeGesture: h,
|
|
295
|
+
state: h ? m : R,
|
|
296
|
+
containerProps: v
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
const te = (s, e, r) => {
|
|
300
|
+
const t = e.getBoundingClientRect();
|
|
301
|
+
return s >= t.left && s <= t.left + r;
|
|
302
|
+
};
|
|
303
|
+
function le(s) {
|
|
304
|
+
const {
|
|
305
|
+
containerRef: e,
|
|
306
|
+
active: r,
|
|
307
|
+
preventEdgeBack: t = !0,
|
|
308
|
+
preventOverscroll: n = !0,
|
|
309
|
+
edgeWidth: l = G
|
|
310
|
+
} = s, i = c.useRef(null), f = c.useCallback(() => {
|
|
311
|
+
if (!n)
|
|
312
|
+
return;
|
|
313
|
+
const o = document.documentElement;
|
|
314
|
+
i.current === null && (i.current = o.style.overscrollBehavior), o.style.overscrollBehavior = "none";
|
|
315
|
+
}, [n]);
|
|
316
|
+
c.useEffect(() => {
|
|
317
|
+
r || !n || i.current !== null && (document.documentElement.style.overscrollBehavior = i.current, i.current = null);
|
|
318
|
+
}, [r, n]), c.useEffect(() => () => {
|
|
319
|
+
i.current !== null && (document.documentElement.style.overscrollBehavior = i.current, i.current = null);
|
|
320
|
+
}, []);
|
|
321
|
+
const d = c.useCallback((o) => {
|
|
322
|
+
if (!t)
|
|
323
|
+
return;
|
|
324
|
+
const u = e.current;
|
|
325
|
+
u && o.pointerType === "touch" && te(o.clientX, u, l) && (f(), o.preventDefault());
|
|
326
|
+
}, [t, e, l, f]);
|
|
327
|
+
return {
|
|
328
|
+
containerProps: c.useMemo(() => ({
|
|
329
|
+
onPointerDown: t ? d : void 0,
|
|
330
|
+
style: {
|
|
331
|
+
// Always apply to prevent browser navigation gestures
|
|
332
|
+
overscrollBehavior: n ? "contain" : void 0,
|
|
333
|
+
WebkitOverflowScrolling: "touch"
|
|
334
|
+
}
|
|
335
|
+
}), [n, t, d])
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
export {
|
|
339
|
+
R as I,
|
|
340
|
+
le as a,
|
|
341
|
+
j as b,
|
|
342
|
+
se as c,
|
|
343
|
+
oe as i,
|
|
344
|
+
re as m,
|
|
345
|
+
ce as u
|
|
346
|
+
};
|
|
347
|
+
//# sourceMappingURL=useNativeGestureGuard-CGYo6O0r.js.map
|