{"version":3,"file":"HorizontalSnapDrag.CY6tDqYe.mjs","names":["useState"],"sources":["https:/framerusercontent.com/modules/9XiWiSvrr23kZ3sYJ387/d6I8AMg4KUzoobs5lk7z/HorizontalSnapDrag.js"],"sourcesContent":["// User request: Create a Framer code override export named HorizontalSnapDrag for an existing canvas track layer, enabling horizontal drag with runtime bounds measurement, clamping, nearest-card snapping, variant-change reconciliation, and grab/grabbing gesture UX while preserving canvas editability and existing interactions.\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useIsStaticRenderer}from\"framer\";import{animate,useMotionValue}from\"framer-motion\";import{forwardRef,startTransition,useCallback,useEffect,useMemo,useRef,useState}from\"react\";function clamp(value,min,max){return Math.min(Math.max(value,min),max);}function getMetrics(trackEl){const viewportEl=trackEl.parentElement;if(!viewportEl){return{minX:0,maxX:0,step:1,renderedX:0};}const viewportRect=viewportEl.getBoundingClientRect();const trackRect=trackEl.getBoundingClientRect();const viewportWidth=viewportRect.width;const trackWidth=trackRect.width;const minX=Math.min(viewportWidth-trackWidth,0);const maxX=0;const renderedX=trackRect.left-viewportRect.left;const children=Array.from(trackEl.children);let step=viewportWidth;if(children.length>1){const lefts=children.map(child=>child.getBoundingClientRect().left).sort((a,b)=>a-b);const gaps=[];for(let i=1;i<lefts.length;i++){const diff=lefts[i]-lefts[i-1];if(diff>0)gaps.push(diff);}if(gaps.length>0){step=gaps.reduce((sum,value)=>sum+value,0)/gaps.length;}}if(!Number.isFinite(step)||step<=0)step=Math.max(viewportWidth,1);return{minX,maxX,step,renderedX};}export function HorizontalSnapDrag(Component){return /*#__PURE__*/forwardRef(function HorizontalSnapDragOverride(props,ref){const isStatic=useIsStaticRenderer();const localRef=useRef(null);const[isDragging,setIsDragging]=useState(false);const[constraints,setConstraints]=useState({left:0,right:0});const x=useMotionValue(0);const animationRef=useRef(null);const isDraggingRef=useRef(false);const assignRef=useCallback(node=>{localRef.current=node;if(typeof ref===\"function\"){ref(node);}else if(ref&&\"current\"in ref){ref.current=node;}},[ref]);const reconcileToLayout=useCallback(snapToStep=>{const trackEl=localRef.current;if(!trackEl)return;const metrics=getMetrics(trackEl);let nextX=clamp(metrics.renderedX,metrics.minX,metrics.maxX);startTransition(()=>{setConstraints({left:metrics.minX,right:metrics.maxX});});if(snapToStep){const stepCount=Math.round(nextX/metrics.step);nextX=clamp(stepCount*metrics.step,metrics.minX,metrics.maxX);}animationRef.current?.stop();animationRef.current=animate(x,nextX,{duration:.22,ease:\"easeOut\"});},[x]);useEffect(()=>{if(typeof window===\"undefined\"||typeof ResizeObserver===\"undefined\"){return;}const trackEl=localRef.current;const viewportEl=trackEl?.parentElement;if(!trackEl||!viewportEl)return;const observer=new ResizeObserver(()=>{if(isDraggingRef.current)return;reconcileToLayout(false);});observer.observe(trackEl);observer.observe(viewportEl);Array.from(trackEl.children).forEach(child=>observer.observe(child));const raf=window.requestAnimationFrame(()=>{if(!isDraggingRef.current)reconcileToLayout(false);});return()=>{window.cancelAnimationFrame(raf);observer.disconnect();};},[reconcileToLayout]);useEffect(()=>{if(typeof window===\"undefined\")return;const raf=window.requestAnimationFrame(()=>{if(!isDraggingRef.current)reconcileToLayout(false);});return()=>window.cancelAnimationFrame(raf);},[props,reconcileToLayout]);useEffect(()=>{return()=>{animationRef.current?.stop();};},[]);const dragConstraints=useMemo(()=>constraints,[constraints]);const handleDragStart=useCallback((event,info)=>{isDraggingRef.current=true;startTransition(()=>setIsDragging(true));animationRef.current?.stop();props.onDragStart?.(event,info);},[props]);const handleDragEnd=useCallback((event,info)=>{isDraggingRef.current=false;startTransition(()=>setIsDragging(false));const trackEl=localRef.current;if(!trackEl){props.onDragEnd?.(event,info);return;}const metrics=getMetrics(trackEl);const clamped=clamp(x.get(),metrics.minX,metrics.maxX);const nearest=clamp(Math.round(clamped/metrics.step)*metrics.step,metrics.minX,metrics.maxX);animationRef.current?.stop();animationRef.current=animate(x,nearest,{type:\"spring\",stiffness:520,damping:48,mass:.45});props.onDragEnd?.(event,info);},[props,x]);return /*#__PURE__*/_jsx(Component,{...props,ref:assignRef,drag:isStatic?false:\"x\",dragDirectionLock:true,dragMomentum:false,dragElastic:0,dragConstraints:dragConstraints,onDragStart:isStatic?props.onDragStart:handleDragStart,onDragEnd:isStatic?props.onDragEnd:handleDragEnd,style:{...props.style,x,cursor:isDragging?\"grabbing\":\"grab\",userSelect:isDragging?\"none\":\"auto\",WebkitUserSelect:isDragging?\"none\":\"auto\",touchAction:\"pan-y\"}});});}export function HideUntilTargetExit(Component){return /*#__PURE__*/forwardRef(function HideUntilTargetExitOverride(props,ref){const[targetFound,setTargetFound]=useState(true);const[isTargetIntersecting,setIsTargetIntersecting]=useState(false);const[isScrollingUp,setIsScrollingUp]=useState(false);useEffect(()=>{if(typeof window===\"undefined\"||typeof document===\"undefined\"){return;}const target=document.getElementById(\"hero-nav\");if(!target){startTransition(()=>{setTargetFound(false);setIsTargetIntersecting(false);setIsScrollingUp(true);});return;}startTransition(()=>setTargetFound(true));let lastY=window.scrollY;const onScroll=()=>{const currentY=window.scrollY;const nextIsScrollingUp=currentY<lastY;lastY=currentY;startTransition(()=>setIsScrollingUp(nextIsScrollingUp));};const observer=new IntersectionObserver(([entry])=>{startTransition(()=>{setIsTargetIntersecting(entry.isIntersecting);});},{threshold:0});observer.observe(target);window.addEventListener(\"scroll\",onScroll,{passive:true});return()=>{observer.disconnect();window.removeEventListener(\"scroll\",onScroll);};},[]);const isVisible=targetFound?!isTargetIntersecting&&isScrollingUp:true;return /*#__PURE__*/_jsx(Component,{ref:ref,...props,style:{...props.style,opacity:isVisible?1:0,transform:`${props.style?.transform??\"\"} translateY(${isVisible?0:-50}px)`.trim(),transition:\"opacity 0.33s ease, transform 0.33s ease, visibility 0.33s ease\",visibility:isVisible?\"visible\":\"hidden\",pointerEvents:isVisible?\"auto\":\"none\",willChange:\"opacity, transform\"}});});}\nexport const __FramerMetadata__ = {\"exports\":{\"HorizontalSnapDrag\":{\"type\":\"reactHoc\",\"name\":\"HorizontalSnapDrag\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"HideUntilTargetExit\":{\"type\":\"reactHoc\",\"name\":\"HideUntilTargetExit\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./HorizontalSnapDrag.map"],"mappings":"yOAC2uI,SAAgB,EAAoB,EAAU,CAAC,OAAoB,EAAW,SAAqC,EAAM,EAAI,CAAC,GAAK,CAAC,EAAY,GAAgBA,EAAS,EAAI,EAAO,CAAC,EAAqB,GAAyBA,EAAS,EAAK,EAAO,CAAC,EAAc,GAAkBA,EAAS,EAAK,EAAE,MAAc,CAAC,GAAU,IAAS,QAAa,OAAO,SAAW,IAAa,OAAQ,IAAM,EAAO,SAAS,eAAe,UAAU,EAAE,GAAG,CAAC,EAAO,CAAC,MAAoB,CAAC,EAAe,EAAK,EAAE,EAAwB,EAAK,EAAE,EAAiB,EAAI,CAAE,CAAC,EAAE,MAAO,CAAC,MAAoB,EAAe,EAAI,CAAC,EAAE,IAAI,EAAM,EAAO,QAAc,MAAa,CAAC,IAAM,EAAS,EAAO,QAAc,EAAkB,EAAS,EAAM,EAAM,EAAS,MAAoB,EAAiB,CAAiB,CAAC,CAAE,EAAQ,EAAS,IAAI,sBAAsB,CAAC,KAAS,CAAC,MAAoB,CAAC,EAAwB,EAAM,cAAc,CAAE,CAAC,CAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAqF,OAAnF,EAAS,QAAQ,CAAM,EAAE,EAAO,iBAAiB,SAAS,EAAS,CAAC,QAAQ,EAAI,CAAC,MAAY,CAAC,EAAS,WAAW,EAAE,EAAO,oBAAoB,SAAS,CAAQ,CAAE,CAAE,EAAE,CAAC,CAAC,EAAE,IAAM,EAAU,IAAY,CAAC,GAAsB,EAAmB,OAAoB,EAAK,EAAU,CAAK,MAAI,GAAG,EAAM,MAAM,CAAC,GAAG,EAAM,MAAM,QAAQ,KAAc,UAAU,GAAG,EAAM,OAAO,WAAW,GAAG,cAAc,EAAU,EAAE,IAAI,KAAK,KAAK,EAAE,WAAW,kEAAkE,WAAW,EAAU,UAAU,SAAS,cAAc,EAAU,OAAO,OAAO,WAAW,oBAAoB,CAAC,CAAC,CAAE,CAAC,CAAE,qBAA9rL,IAAwC,IAAkD,IAA4F"}