{"version":3,"file":"HoverForce_Prod.BPyhdbdz.mjs","names":["useRef","useState","useCallback"],"sources":["https:/framerusercontent.com/modules/jRryFWxgo35JJliJ71gH/Hq7semBIqdrUFKRJpcU9/HoverForce_Prod.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{ControlType,addPropertyControls,RenderTarget}from\"framer\";import{useEffect,useRef,useCallback,useState}from\"react\";import{animate,useMotionValue,useTransform}from\"framer-motion\";// ------------------------------------------------------------ //\n// PROPERTY CONTROLS\n// ------------------------------------------------------------ //\naddPropertyControls(HoverForce,{threshold:{type:ControlType.Number,defaultValue:200,min:0,max:800,title:\"Area\",unit:\"px\",hidden:props=>!props.enabled},animationDistance:{type:ControlType.Number,defaultValue:200,min:0,max:800,title:\"Movement\",unit:\"px\",hidden:props=>!props.enabled},mode:{type:ControlType.Enum,defaultValue:\"repel\",options:[\"attract\",\"repel\"],optionTitles:[\"Attract\",\"Repel\"],title:\"Mode\",displaySegmentedControl:true,segmentedControlDirection:\"vertical\",hidden:props=>!props.enabled},direction:{type:ControlType.Enum,defaultValue:\"vertical\",options:[\"vertical\",\"horizontal\",\"both\"],displaySegmentedControl:true,hidden:props=>!props.enabled},smoothness:{type:ControlType.Number,defaultValue:10,min:0,max:20,step:1,title:\"Smoothing\",hidden:props=>!props.enabled},enabled:{type:ControlType.Boolean,defaultValue:true,title:\"Enabled\",description:\"More components at [Framer University](https://frameruni.link/cc).\"}});// ------------------------------------------------------------ //\n// DEFAULT PROPS\n// ------------------------------------------------------------ //\nHoverForce.defaultProps={enabled:true,threshold:200,animationDistance:200,mode:\"repel\",direction:\"vertical\",smoothness:10};// ------------------------------------------------------------ //\n// MAIN COMPONENT\n// ------------------------------------------------------------ //\n/**\n * @framerSupportedLayoutWidth auto\n * @framerSupportedLayoutHeight auto\n * @framerDisableUnlink\n */export default function HoverForce(props){const isOnFramerCanvas=RenderTarget.hasRestrictions();const id=useRef(generateRandomId());const mainRef=useRef(null);const parentRef=useRef(null);const subparentRef=useRef(null);const anchorRef=useRef(null);const breakpoint=useBreakpoint();const isMobile=breakpoint===\"mobile\";// Constants\nconst ANIMATION_CONFIG=getAnimationConfig(props.smoothness);const ANIMATION_CONFIG_2={type:\"spring\",stiffness:1e3,damping:100,mass:1};const THROTTLE_INTERVAL=16// ~60fps\n;// Motion values\nconst distance=useMotionValue(props.threshold);const yDirection=useMotionValue(1);const xDirection=useMotionValue(1);const modeMultiplier=props.mode===\"attract\"?1:-1;// Transform functions\nconst yPosition=useTransform([distance,yDirection],([dist,dir])=>{if(props.direction===\"horizontal\")return 0;if(props.direction===\"both\"){if(!anchorRef.current)return 0;const mouseY=window.mouseY||0;const progress=Math.max(0,1-dist/props.threshold);const targetY=mouseY-anchorRef.current.y;return targetY*progress*modeMultiplier;}const progress=Math.max(0,1-dist/props.threshold);const baseMovement=progress*props.animationDistance;return baseMovement*dir*modeMultiplier;});const xPosition=useTransform([distance,xDirection],([dist,dir])=>{if(props.direction===\"vertical\")return 0;if(props.direction===\"both\"){if(!anchorRef.current)return 0;const mouseX=window.mouseX||0;const progress=Math.max(0,1-dist/props.threshold);const targetX=mouseX-anchorRef.current.x;return targetX*progress*modeMultiplier;}const progress=Math.max(0,1-dist/props.threshold);const baseMovement=progress*props.animationDistance;return baseMovement*dir*modeMultiplier;});// Add window mouse position tracking\nconst[mousePos,setMousePos]=useState({x:0,y:0});// ------------------------------------------------------------ //\n// CALLBACKS\n// ------------------------------------------------------------ //\nconst initializeParent=useCallback(()=>{if(!mainRef.current||!props.enabled||isMobile)return;const subparent=mainRef.current.parentElement;if(!subparent)return;subparentRef.current=subparent;const parent=subparent.parentElement;if(!parent)return;parentRef.current=parent;parent.setAttribute(\"data-hover-force\",id.current);const rect=parent.getBoundingClientRect();anchorRef.current={x:rect.left+rect.width/2,y:rect.top+rect.height/2};// Remove the initial transform and transition\nparent.style.willChange=\"transform\";parent.style.transform=\"none\";// Don't set initial transition to allow Framer Motion to handle it\n},[]);const handleMouseMove=useCallback(e=>{if(!anchorRef.current||!props.enabled||isMobile||!window)return;window.mouseX=e.clientX;window.mouseY=e.clientY;const mousePoint={x:e.clientX,y:e.clientY};const newDistance=calculateDistance(mousePoint,anchorRef.current);if(props.direction===\"both\"){// For \"both\" direction, we only need the distance for threshold calculation\nanimate(distance,// @ts-expect-error want motion value, but don't work with it\nMath.min(newDistance,props.threshold),ANIMATION_CONFIG_2);}else{// Original behavior for vertical/horizontal\nconst newYDirection=e.clientY>anchorRef.current.y?1:-1;const newXDirection=e.clientX>anchorRef.current.x?1:-1;// @ts-expect-error want motion value, but don't work with it\nanimate(yDirection,newYDirection,ANIMATION_CONFIG_2);// @ts-expect-error want motion value, but don't work with it\nanimate(xDirection,newXDirection,ANIMATION_CONFIG_2);animate(distance,// @ts-expect-error want motion value, but don't work with it\nMath.min(newDistance,props.threshold),ANIMATION_CONFIG_2);}},[props.threshold,props.direction]);const createThrottledMouseHandler=useCallback(()=>{let timeout=null;return e=>{if(timeout)return;timeout=setTimeout(()=>{handleMouseMove(e);timeout=null;},THROTTLE_INTERVAL);};},[handleMouseMove]);// ------------------------------------------------------------ //\n// EFFECTS\n// ------------------------------------------------------------ //\n// Initialize parent element\nuseEffect(()=>{initializeParent();},[initializeParent]);// Setup mouse move handler\nuseEffect(()=>{if(isOnFramerCanvas||!anchorRef.current||!props.enabled||isMobile)return;const throttledHandler=createThrottledMouseHandler();window.addEventListener(\"mousemove\",throttledHandler);// Update parent transform based on positions\nconst unsubscribe=()=>{const yUnsub=yPosition.on(\"change\",latestY=>{const latestX=xPosition.get();if(parentRef.current){animate(parentRef.current,// @ts-expect-error overloads\n{x:latestX,y:latestY},{...ANIMATION_CONFIG,immediate:true});}});const xUnsub=xPosition.on(\"change\",latestX=>{const latestY=yPosition.get();if(parentRef.current){animate(parentRef.current,// @ts-expect-error overloads\n{x:latestX,y:latestY},{...ANIMATION_CONFIG,immediate:true});}});return()=>{yUnsub();xUnsub();};};const cleanup=unsubscribe();return()=>{window.removeEventListener(\"mousemove\",throttledHandler);if(cleanup)cleanup();};},[props.threshold,props.animationDistance,props.mode,props.direction,isOnFramerCanvas,createThrottledMouseHandler,yPosition,xPosition]);return /*#__PURE__*/_jsx(\"div\",{ref:mainRef,style:{width:\"0px\",height:\"0px\"}});}// ------------------------------------------------------------ //\n// UTILITY FUNCTIONS\n// ------------------------------------------------------------ //\nconst generateRandomId=()=>Math.random().toString(36).substring(2,15);const calculateDistance=(point1,point2)=>{return Math.sqrt(Math.pow(point2.x-point1.x,2)+Math.pow(point2.y-point1.y,2));};const getAnimationConfig=smoothness=>{const stiffness=800+smoothness*20;const damping=50+smoothness*10;const mass=1;return{type:\"spring\",stiffness,damping,mass};};function useBreakpoint(){// const [isMobile, setIsMobile] = useState(false);\nconst[breakpoint,setBreakpoint]=useState(null);useEffect(()=>{const checkBreakpoint=()=>{if(window.innerWidth<=809){setBreakpoint(\"mobile\");}else if(window.innerWidth<=1199){setBreakpoint(\"tablet\");}else{setBreakpoint(\"desktop\");}};checkBreakpoint();window.addEventListener(\"resize\",checkBreakpoint);return()=>window.removeEventListener(\"resize\",checkBreakpoint);},[]);return breakpoint;}HoverForce.displayName=\"Hover Force\";\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"HoverForce\",\"slots\":[],\"annotations\":{\"framerDisableUnlink\":\"\",\"framerSupportedLayoutWidth\":\"auto\",\"framerSupportedLayoutHeight\":\"auto\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./HoverForce_Prod.map"],"mappings":"8QAaG,SAAwB,EAAW,EAAM,CAAC,IAAM,EAAiB,EAAa,gBAAgB,EAAQ,EAAGA,EAAO,EAAiB,CAAC,EAAQ,EAAQA,EAAO,IAAI,EAAQ,EAAUA,EAAO,IAAI,EAAQ,EAAaA,EAAO,IAAI,EAAQ,EAAUA,EAAO,IAAI,EAAyC,EAAtB,EAAwC,IAAI,SACnT,EAAiB,EAAmB,EAAM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