{"version":3,"file":"index49.cjs","sources":["../src/hooks/useHorizontalSwipe.ts"],"sourcesContent":["import { useState, useRef, useCallback } from 'react';\n\ninterface UseHorizontalSwipeProps {\n  threshold?: number;\n  initialState?: boolean;\n}\n\n/**\n * A minimal hook for horizontal swipe detection\n * \n * @param threshold Minimum distance in pixels to trigger a swipe (default: 40)\n * @param initialState Initial state of the swipe (default: false)\n * @returns Object containing swipe state and handlers\n */\nexport const useHorizontalSwipe = ({\n  threshold = 40,\n  initialState = false,\n}: UseHorizontalSwipeProps = {}) => {\n  // Single state to track if swiped\n  const [isSwiped, setIsSwiped] = useState(initialState);\n  \n  // Refs to track swipe coordinates\n  const startXRef = useRef(0);\n  const currentXRef = useRef(0);\n  const isSwiping = useRef(false);\n\n  // Reset swipe state\n  const resetSwipe = useCallback(() => {\n    setIsSwiped(false);\n  }, []);\n\n  // Set swipe state manually\n  const setSwipeState = useCallback((state: boolean) => {\n    setIsSwiped(state);\n  }, []);\n\n  // Handle swipe detection\n  const detectSwipe = useCallback((endX: number) => {\n    if (!isSwiping.current) return;\n    \n    const diff = startXRef.current - endX;\n    \n    // Swipe left to open\n    if (diff > threshold && !isSwiped) {\n      setIsSwiped(true);\n    } \n    // Swipe right to close\n    else if (diff < -threshold && isSwiped) {\n      setIsSwiped(false);\n    }\n    \n    isSwiping.current = false;\n  }, [threshold, isSwiped]);\n\n  // Touch event handlers\n  const handleTouchStart = useCallback((e: React.TouchEvent) => {\n    startXRef.current = e.touches[0].clientX;\n    currentXRef.current = e.touches[0].clientX;\n    isSwiping.current = true;\n  }, []);\n\n  const handleTouchMove = useCallback((e: React.TouchEvent) => {\n    if (!isSwiping.current) return;\n    currentXRef.current = e.touches[0].clientX;\n  }, []);\n\n  const handleTouchEnd = useCallback((e: React.TouchEvent) => {\n    const endX = e.changedTouches.length > 0 \n      ? e.changedTouches[0].clientX \n      : currentXRef.current;\n    detectSwipe(endX);\n  }, [detectSwipe]);\n\n  // Mouse event handlers\n  const handleMouseDown = useCallback((e: React.MouseEvent) => {\n    e.preventDefault(); // Prevent text selection\n    startXRef.current = e.clientX;\n    currentXRef.current = e.clientX;\n    isSwiping.current = true;\n  }, []);\n\n  const handleMouseMove = useCallback((e: React.MouseEvent) => {\n    if (!isSwiping.current) return;\n    currentXRef.current = e.clientX;\n    e.preventDefault();\n  }, []);\n\n  const handleMouseUp = useCallback((e: React.MouseEvent) => {\n    detectSwipe(currentXRef.current || e.clientX);\n  }, [detectSwipe]);\n\n  // Combine all handlers\n  const swipeHandlers = {\n    onTouchStart: handleTouchStart,\n    onTouchMove: handleTouchMove,\n    onTouchEnd: handleTouchEnd,\n    onMouseDown: handleMouseDown,\n    onMouseMove: handleMouseMove,\n    onMouseUp: handleMouseUp,\n    onMouseLeave: handleMouseUp, // Handle case when mouse leaves the element\n  };\n\n  return {\n    isSwiped,\n    resetSwipe,\n    setIsSwiped: setSwipeState,\n    swipeHandlers,\n  };\n};\n"],"names":["useState","useRef","useCallback"],"mappings":";;;AAcO,MAAM,qBAAqB,CAAC;AAAA,EACjC,YAAY;AAAA,EACZ,eAAe;AACjB,IAA6B,OAAO;AAElC,QAAM,CAAC,UAAU,WAAW,IAAIA,MAAAA,SAAS,YAAY;AAG/C,QAAA,YAAYC,aAAO,CAAC;AACpB,QAAA,cAAcA,aAAO,CAAC;AACtB,QAAA,YAAYA,aAAO,KAAK;AAGxB,QAAA,aAAaC,MAAAA,YAAY,MAAM;AACnC,gBAAY,KAAK;AAAA,EACnB,GAAG,EAAE;AAGC,QAAA,gBAAgBA,kBAAY,CAAC,UAAmB;AACpD,gBAAY,KAAK;AAAA,EACnB,GAAG,EAAE;AAGC,QAAA,cAAcA,kBAAY,CAAC,SAAiB;AAC5C,QAAA,CAAC,UAAU,QAAS;AAElB,UAAA,OAAO,UAAU,UAAU;AAG7B,QAAA,OAAO,aAAa,CAAC,UAAU;AACjC,kBAAY,IAAI;AAAA,IAGT,WAAA,OAAO,CAAC,aAAa,UAAU;AACtC,kBAAY,KAAK;AAA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