{"version":3,"file":"MagneticHover_Prod.BitH6uqa.mjs","names":["useRef","useMemo"],"sources":["https:/framerusercontent.com/modules/P3S2M04Yg53AO5F51mO2/nMehdyPB78SoY29OGNeL/MagneticHover_Prod.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";import{useEffect,useRef,useMemo}from\"react\";import{useMotionValue,useSpring,motion}from\"framer-motion\";/**\n * @framerSupportedLayoutWidth auto\n * @framerSupportedLayoutHeight auto\n *\n * @framerDisableUnlink\n */export default function MagneticHover(props){const{distance,smoothing,hoverArea,enabled}=props;const isCanvas=RenderTarget.current()===RenderTarget.canvas;const id=generateInstanceId();const transition={damping:100,stiffness:mapRange(smoothing,0,100,2e3,50)};const mouseX=useMotionValue(0);const mouseY=useMotionValue(0);const x=useMotionValue(0);const y=useMotionValue(0);const springX=useSpring(x,transition);const springY=useSpring(y,transition);const scale=useMotionValue(1);const springScale=useSpring(scale,transition);const ref=useRef(null);const containerRef=useRef(null);const parentRef=useRef(null);const isHoveringRef=useRef(false);const transformRef=useRef(null);const motionTransformRef=useRef(null);const styleRef=useRef(null);const hasSpringRef=useRef(smoothing!==0);useEffect(()=>{const unsubscribeX=mouseX.onChange(v=>x.set(enabled?v:0));const unsubscribeY=mouseY.onChange(v=>y.set(enabled?v:0));return()=>{unsubscribeX();unsubscribeY();};},[enabled,mouseX,mouseY,x,y]);useEffect(()=>{x.set(enabled?mouseX.get():0);y.set(enabled?mouseY.get():0);if(!enabled){scale.set(1);}else if(isHoveringRef.current&&props.children){scale.set(props.children.scale);}},[enabled]);useEffect(()=>{hasSpringRef.current=smoothing!==0;},[smoothing]);useEffect(()=>{let animationFrameId;const updateTransform=()=>{if(isCanvas){return;}animationFrameId=requestAnimationFrame(updateTransform);if(!parentRef.current||!styleRef.current){return;}const xValue=hasSpringRef.current?springX.get():x.get();const yValue=hasSpringRef.current?springY.get():y.get();const scaleValue=hasSpringRef.current?springScale.get():scale.get();// Get parent transform\nconst parentTransformValue=parentRef.current.style.transform;const parentTransform=`translate(${xValue.toFixed(3)}px, ${yValue.toFixed(3)}px)`;let newParentTransform=parentTransformValue;if(parentTransformValue===\"none\"){newParentTransform=parentTransform;}else{newParentTransform=`${parentTransform} ${parentTransformValue}`;}// Handle children transforms\nlet childrenStyles=\"\";if(props.children){const children=parentRef.current.children;for(let index=0;index<children.length;index++){const child=children[index];if(child===containerRef.current){continue;}const childTransformValue=child.style.transform;const magneticChildTransform=`translate(${(xValue*props.children.distance/distance).toFixed(3)}px, ${(yValue*props.children.distance/distance).toFixed(3)}px) scale(${scaleValue.toFixed(3)})`;let newChildTransform=magneticChildTransform;if(childTransformValue&&childTransformValue!==\"none\"){newChildTransform=`${magneticChildTransform} ${childTransformValue}`;}childrenStyles+=`\n\t\t\t\t\t\t[data-magnetichover=\"${id}\"] > :nth-child(${index+1}) { \n\t\t\t\t\t\t\ttransform: ${newChildTransform} !important \n\t\t\t\t\t\t}\n\t\t\t\t\t`;}}transformRef.current=newParentTransform;styleRef.current.textContent=`\n\t\t\t\t[data-magnetichover=\"${id}\"] { transform: ${newParentTransform} !important }\n\t\t\t\t${childrenStyles}\n\t\t\t`;};if(ref.current){const container=ref.current.parentElement;if(container){containerRef.current=container;const parent=container.parentElement;if(parent){parentRef.current=parent;parent.setAttribute(\"data-magnetichover\",id);motionTransformRef.current=motion(parent,\"transform\");}}}// Start the animation loop\nupdateTransform();// Cleanup function\nreturn()=>{if(animationFrameId){cancelAnimationFrame(animationFrameId);}};},[props.children]);useEffect(()=>{const handleMouseMove=event=>{if(!parentRef.current){return;}const element=parentRef.current;const rect=element.getBoundingClientRect();const mouseXPos=event.clientX;const mouseYPos=event.clientY;const isHovering=mouseXPos>=rect.left-hoverArea&&mouseXPos<=rect.right+hoverArea&&mouseYPos>=rect.top-hoverArea&&mouseYPos<=rect.bottom+hoverArea;isHoveringRef.current=isHovering;if(isHovering){const displacementX=mouseXPos-(rect.left+rect.width/2);const displacementY=mouseYPos-(rect.top+rect.height/2);const normalizedX=displacementX/(rect.width/2)*distance;const normalizedY=displacementY/(rect.height/2)*distance;mouseX.set(normalizedX);mouseY.set(normalizedY);scale.set(enabled&&props.children?props.children.scale:1);}else{mouseX.set(0);mouseY.set(0);scale.set(1);}};window.addEventListener(\"mousemove\",handleMouseMove);return()=>window.removeEventListener(\"mousemove\",handleMouseMove);},[distance,x,y,transition,enabled,props.children]);return /*#__PURE__*/_jsx(\"div\",{ref:ref,style:{...props.style},children:/*#__PURE__*/_jsx(\"style\",{ref:styleRef})});}MagneticHover.displayName=\"Magnetic Hover\";addPropertyControls(MagneticHover,{enabled:{type:ControlType.Boolean,defaultValue:true},distance:{type:ControlType.Number,defaultValue:10,min:0,step:1,hidden:props=>!props.enabled},hoverArea:{type:ControlType.Number,defaultValue:10,min:0,step:1,hidden:props=>!props.enabled},children:{type:ControlType.Object,optional:true,controls:{distance:{type:ControlType.Number,defaultValue:10,min:0,step:1},scale:{type:ControlType.Number,defaultValue:1,min:0,step:.01}},hidden:props=>!props.enabled},smoothing:{type:ControlType.Number,defaultValue:50,min:0,max:100,step:1,description:\"More components at [Framer University](https://frameruni.link/cc).\"}});const CHARACTERS=\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\";function generateInstanceId(){const id=useMemo(()=>{let result=\"\";for(let i=0;i<13;i++){result+=CHARACTERS.charAt(Math.floor(Math.random()*CHARACTERS.length));}return result;},[]);return id;}function mapRange(value,fromLow,fromHigh,toLow,toHigh){if(fromLow===fromHigh){return toLow;}const percentage=(value-fromLow)/(fromHigh-fromLow);return toLow+percentage*(toHigh-toLow);}\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"MagneticHover\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerDisableUnlink\":\"\",\"framerSupportedLayoutHeight\":\"auto\",\"framerSupportedLayoutWidth\":\"auto\"}},\"__FramerMetadata__\":{\"type\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