{"version":3,"file":"CursorFollower.CdIn08HQ.mjs","names":["useState","useRef","useCallback","_Fragment"],"sources":["https:/framerusercontent.com/modules/buz1mG6UGEHms1OIz7QS/0NMz0Bszfd9iKpJh2jY1/CursorFollower.js"],"sourcesContent":["// Component that allows child components to follow cursor position\nimport{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from\"react/jsx-runtime\";import{useEffect,useState,useRef,useCallback}from\"react\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";/**\n * Cursor Follower\n *\n * @framerIntrinsicWidth 200\n * @framerIntrinsicHeight 200\n *\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight any\n */export default function CursorFollower(props){const{children,smoothing,hoverSmoothing,followX,enableOffsetX,offsetX,style}=props;const[isReady,setIsReady]=useState(false);const isStatic=useIsStaticRenderer();const childRef=useRef(null);const containerRef=useRef(null);const[childDimensions,setChildDimensions]=useState({width:0,height:0});const[containerDimensions,setContainerDimensions]=useState({width:0,height:0});// Use refs for position to avoid re-renders\nconst positionRef=useRef({x:0,y:0});const targetPositionRef=useRef({x:0,y:0});const isHoveringRef=useRef(false);const centerPositionRef=useRef({x:0,y:0});const originalPositionRef=useRef({x:0,y:0});const animationFrameIdRef=useRef();// Initialize position to original child position\nuseEffect(()=>{if(typeof window===\"undefined\"||!containerRef.current||!childRef.current)return;const childWidth=childRef.current?.offsetWidth||0;const childHeight=childRef.current?.offsetHeight||0;const containerWidth=containerRef.current?.offsetWidth||0;const containerHeight=containerRef.current?.offsetHeight||0;// Skip if dimensions aren't ready yet\nif(childWidth===0||childHeight===0)return;setChildDimensions({width:childWidth,height:childHeight});setContainerDimensions({width:containerWidth,height:containerHeight});// Get the original position from the child's current position in the DOM\nconst childRect=childRef.current.getBoundingClientRect();const containerRect=containerRef.current.getBoundingClientRect();const originalX=childRect.left-containerRect.left;const originalY=childRect.top-containerRect.top;originalPositionRef.current={x:originalX,y:originalY};centerPositionRef.current={x:originalX,y:originalY};positionRef.current={x:originalX,y:originalY};targetPositionRef.current={x:originalX,y:originalY};// Set initial transform\nif(childRef.current){childRef.current.style.transform=`translate(${originalX}px, ${originalY}px)`;}setIsReady(true);},[followX,children]);// Update child and container dimensions when they change\nuseEffect(()=>{if(typeof window===\"undefined\"||!childRef.current||!containerRef.current)return;const updateDimensions=()=>{const childWidth=childRef.current?.offsetWidth||0;const childHeight=childRef.current?.offsetHeight||0;const containerWidth=containerRef.current?.offsetWidth||0;const containerHeight=containerRef.current?.offsetHeight||0;setChildDimensions({width:childWidth,height:childHeight});setContainerDimensions({width:containerWidth,height:containerHeight});// Keep original position reference, don't recalculate\nif(!isReady&&childWidth>0&&childHeight>0){const childRect=childRef.current?.getBoundingClientRect();const containerRect=containerRef.current?.getBoundingClientRect();if(childRect&&containerRect){const originalX=childRect.left-containerRect.left;originalPositionRef.current={x:originalX,y:originalPositionRef.current.y};centerPositionRef.current={x:originalX,y:centerPositionRef.current.y};}}};updateDimensions();const resizeObserver=new ResizeObserver(updateDimensions);if(childRef.current){resizeObserver.observe(childRef.current);}if(containerRef.current){resizeObserver.observe(containerRef.current);}return()=>{resizeObserver.disconnect();};},[children,isReady]);// Update center position on window resize\nuseEffect(()=>{if(typeof window===\"undefined\"||!containerRef.current)return;const handleResize=()=>{// Keep the original position on resize, don't recalculate\nif(originalPositionRef.current.x!==0){centerPositionRef.current={x:originalPositionRef.current.x,y:originalPositionRef.current.y};}};window.addEventListener(\"resize\",handleResize);return()=>window.removeEventListener(\"resize\",handleResize);},[]);// Memoize mouse move handler\nconst handleMouseMove=useCallback(e=>{if(!containerRef.current||!childRef.current)return;const containerRect=containerRef.current.getBoundingClientRect();const mouseXInContainer=e.clientX-containerRect.left;const childWidth=childRef.current.offsetWidth;const containerWidth=containerRef.current.offsetWidth;// Calculate target position with offset - center the child on cursor (X-axis only)\nif(followX){let targetX=mouseXInContainer-childWidth/2+(enableOffsetX?offsetX:0);targetX=Math.max(0,Math.min(targetX,containerWidth-childWidth));targetPositionRef.current.x=targetX;}else{// Lock to original position when followX is disabled\ntargetPositionRef.current.x=originalPositionRef.current.x;positionRef.current.x=originalPositionRef.current.x;}},[enableOffsetX,offsetX,followX]);useEffect(()=>{if(typeof window===\"undefined\")return;window.addEventListener(\"mousemove\",handleMouseMove);return()=>{window.removeEventListener(\"mousemove\",handleMouseMove);};},[handleMouseMove]);// Optimized animation loop - directly update DOM\nuseEffect(()=>{if(typeof window===\"undefined\"||!isReady)return;const animate=()=>{const currentSmoothing=isHoveringRef.current?hoverSmoothing:smoothing;// Only interpolate X-axis, keep Y fixed\nconst newX=followX?positionRef.current.x+(targetPositionRef.current.x-positionRef.current.x)*currentSmoothing:originalPositionRef.current.x;const newY=originalPositionRef.current.y;positionRef.current={x:newX,y:newY};// Directly update DOM for better performance\nif(childRef.current){childRef.current.style.transform=`translate(${newX}px, ${newY}px)`;}animationFrameIdRef.current=requestAnimationFrame(animate);};animationFrameIdRef.current=requestAnimationFrame(animate);return()=>{if(animationFrameIdRef.current){cancelAnimationFrame(animationFrameIdRef.current);}};},[smoothing,hoverSmoothing,isReady,followX]);// Memoize hover handlers\nconst handleMouseEnter=useCallback(()=>{isHoveringRef.current=true;},[]);const handleMouseLeave=useCallback(()=>{isHoveringRef.current=false;},[]);return /*#__PURE__*/_jsx(\"div\",{ref:containerRef,style:{...style,position:\"relative\",width:isStatic?\"fit-content\":\"100%\",height:isStatic?\"fit-content\":childDimensions.height,overflow:\"visible\"},children:isStatic?// Show child in normal position for static preview\n/*#__PURE__*/_jsx(\"div\",{ref:childRef,children:children}):/*#__PURE__*/_jsxs(_Fragment,{children:[/*#__PURE__*/_jsx(\"div\",{style:{width:childDimensions.width,height:childDimensions.height,visibility:\"hidden\",pointerEvents:\"none\"}}),/*#__PURE__*/_jsx(\"div\",{ref:childRef,style:{position:\"absolute\",left:0,top:0,pointerEvents:\"auto\",zIndex:9999,willChange:\"transform\"},onMouseEnter:handleMouseEnter,onMouseLeave:handleMouseLeave,children:children})]})});}addPropertyControls(CursorFollower,{children:{type:ControlType.Slot,title:\"Child\"},smoothing:{type:ControlType.Number,title:\"Smoothing\",defaultValue:.15,min:.01,max:1,step:.01},hoverSmoothing:{type:ControlType.Number,title:\"Hover Smoothing\",defaultValue:.25,min:.01,max:1,step:.01},followX:{type:ControlType.Boolean,title:\"Follow Cursor X\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\"},enableOffsetX:{type:ControlType.Boolean,title:\"Enable Offset X\",defaultValue:false,enabledTitle:\"On\",disabledTitle:\"Off\",hidden:({followX})=>!followX},offsetX:{type:ControlType.Number,title:\"Offset X\",defaultValue:0,min:-200,max:200,step:1,unit:\"px\",hidden:({enableOffsetX,followX})=>!enableOffsetX||!followX}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"CursorFollower\",\"slots\":[\"children\"],\"annotations\":{\"framerSupportedLayoutWidth\":\"any\",\"framerSupportedLayoutHeight\":\"any\",\"framerContractVersion\":\"1\",\"framerIntrinsicWidth\":\"200\",\"framerIntrinsicHeight\":\"200\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./CursorFollower.map"],"mappings":"mOASG,SAAwB,EAAe,EAAM,CAAC,GAAK,CAAC,WAAS,YAAU,iBAAe,UAAQ,gBAAc,UAAQ,SAAO,EAAW,CAAC,EAAQ,GAAYA,EAAS,GAAM,CAAO,EAAS,GAAqB,CAAO,EAASC,EAAO,KAAK,CAAO,EAAaA,EAAO,KAAK,CAAM,CAAC,EAAgB,GAAoBD,EAAS,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAM,CAAC,EAAoB,GAAwBA,EAAS,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAC9Z,EAAYC,EAAO,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAO,EAAkBA,EAAO,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAO,EAAcA,EAAO,GAAM,CAAO,EAAkBA,EAAO,CAAC,EAA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