{"version":3,"file":"MouseFollowRealtime.CM0whm9F.mjs","names":["useMousePosition","useElementBoundingClientRect"],"sources":["https:/framerusercontent.com/modules/lo3S12N8iu5JibtCZk5J/dya0cK6x0FLBoIledw77/MouseFollow.js","https:/framerusercontent.com/modules/khnWw2e326fj4TimYWpK/2q9HsFeqBcpiMnNPc42K/MouseFollowRealtime.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useState,useEffect,useRef}from\"react\";import{useMotionValue,useSpring,useMotionValueEvent}from\"framer-motion\";// Apply this override to object you want to follow the mouse\nexport function withFollowMouse(Component){return props=>{const[rect,ref]=useElementBoundingClientRect();const[mouseX,mouseY]=useMousePosition();/* useSpring MotionValues */const springValue={stiffness:150,damping:30};const x=useSpring(mouseX,springValue);const y=useSpring(mouseY,springValue);return /*#__PURE__*/_jsx(Component,{...props,ref:ref,style:{...props.style,x,y,position:\"fixed\",// align center of component to mouse pointer\ntop:-rect.height/2,left:-rect.width/2,pointerEvents:\"none\"}});};}// Apply this override to object you want to follow the mouse\nexport function withFollowMouseHideOffScreen(Component){return props=>{const[rect,ref]=useElementBoundingClientRect();const[mouseX,mouseY]=useMousePosition();/* Hide if off screen */const[hidden,setHidden]=useState(true);const tolerance=50;useMotionValueEvent(mouseX,\"change\",latest=>{const y=mouseY.get();setHidden(latest<=tolerance||latest>=window.innerWidth-tolerance||y<=tolerance||y>=window.innerHeight-tolerance);});useMotionValueEvent(mouseY,\"change\",latest=>{const x=mouseX.get();setHidden(latest<=tolerance||latest>=window.innerHeight-tolerance||x<=tolerance||x>=window.innerWidth-tolerance);});return /*#__PURE__*/_jsx(Component,{...props,ref:ref,animate:{opacity:hidden?0:1},style:{...props.style,x:mouseX,y:mouseY,opacity:0,position:\"fixed\",top:-rect.height/2,left:-rect.width/2,pointerEvents:\"none\"}});};}function useMousePosition(){const mouseX=useMotionValue(0);const mouseY=useMotionValue(0);useEffect(()=>{const handleMouseMove=event=>{mouseX.set(event.clientX);mouseY.set(event.clientY);};window.addEventListener(\"mousemove\",handleMouseMove);return()=>{window.removeEventListener(\"mousemove\",handleMouseMove);};},[]);return[mouseX,mouseY];}function useElementBoundingClientRect(){const ref=useRef(null);const[rect,setRect]=useState({x:0,y:0,left:0,right:200,top:0,bottom:200,width:200,height:200});useEffect(()=>{if(ref.current){setRect(ref.current.getBoundingClientRect());}},[]);return[rect,ref];}\nexport const __FramerMetadata__ = {\"exports\":{\"withFollowMouse\":{\"type\":\"reactHoc\",\"name\":\"withFollowMouse\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withFollowMouseHideOffScreen\":{\"type\":\"reactHoc\",\"name\":\"withFollowMouseHideOffScreen\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./MouseFollow.map","import{jsx as _jsx}from\"react/jsx-runtime\";import{useState,useEffect,useRef}from\"react\";import{useMotionValue,useSpring,useMotionValueEvent}from\"framer-motion\";// Apply this override to object you want to follow the mouse\nexport function withFollowMouse(Component){return props=>{const[rect,ref]=useElementBoundingClientRect();const[mouseX,mouseY]=useMousePosition();/* useSpring MotionValues */const springValue={stiffness:400,damping:30};const x=useSpring(mouseX,springValue);const y=useSpring(mouseY,springValue);return /*#__PURE__*/_jsx(Component,{...props,ref:ref,style:{...props.style,x,y,position:\"fixed\",// align center of component to mouse pointer\ntop:-rect.height/2,left:-rect.width/2,pointerEvents:\"none\"}});};}// Apply this override to object you want to follow the mouse\nexport function withFollowMouseHideOffScreen(Component){return props=>{const[rect,ref]=useElementBoundingClientRect();const[mouseX,mouseY]=useMousePosition();/* Hide if off screen */const[hidden,setHidden]=useState(true);const tolerance=50;useMotionValueEvent(mouseX,\"change\",latest=>{const y=mouseY.get();setHidden(latest<=tolerance||latest>=window.innerWidth-tolerance||y<=tolerance||y>=window.innerHeight-tolerance);});useMotionValueEvent(mouseY,\"change\",latest=>{const x=mouseX.get();setHidden(latest<=tolerance||latest>=window.innerHeight-tolerance||x<=tolerance||x>=window.innerWidth-tolerance);});return /*#__PURE__*/_jsx(Component,{...props,ref:ref,animate:{opacity:hidden?0:1},style:{...props.style,x:mouseX,y:mouseY,opacity:0,position:\"fixed\",top:-rect.height/2,left:-rect.width/2,pointerEvents:\"none\"}});};}function useMousePosition(){const mouseX=useMotionValue(0);const mouseY=useMotionValue(0);useEffect(()=>{const handleMouseMove=event=>{mouseX.set(event.clientX);mouseY.set(event.clientY);};window.addEventListener(\"mousemove\",handleMouseMove);return()=>{window.removeEventListener(\"mousemove\",handleMouseMove);};},[]);return[mouseX,mouseY];}function useElementBoundingClientRect(){const ref=useRef(null);const[rect,setRect]=useState({x:0,y:0,left:0,right:200,top:0,bottom:200,width:200,height:200});useEffect(()=>{if(ref.current){setRect(ref.current.getBoundingClientRect());}},[]);return[rect,ref];}\nexport const __FramerMetadata__ = {\"exports\":{\"withFollowMouseHideOffScreen\":{\"type\":\"reactHoc\",\"name\":\"withFollowMouseHideOffScreen\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withFollowMouse\":{\"type\":\"reactHoc\",\"name\":\"withFollowMouse\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./MouseFollowRealtime.map"],"mappings":"mVACA,SAAgB,EAAgB,EAAU,CAAC,MAAO,CAAA,GAAO,CAAC,GAAK,CAAC,EAAK,EAAI,CAAC,GAA8B,CAAM,CAAC,EAAO,EAAO,CAAC,GAAkB,CAAmC,EAAY,CAAC,UAAU,IAAI,QAAQ,EAAG,EAAO,EAAE,EAAU,EAAO,EAAY,CAAO,EAAE,EAAU,EAAO,EAAY,CAAC,MAAoB,GAAK,EAAU,CAAC,GAAG,EAAU,MAAI,MAAM,CAAC,GAAG,EAAM,MAAM,IAAE,IAAE,SAAS,QAC9X,KAAK,EAAK,OAAO,EAAE,MAAM,EAAK,MAAM,EAAE,cAAc,MAAO,CAAC,EAAC,AAAE,CAAE,CACivB,SAASA,GAAkB,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