{"version":3,"file":"MouseParallax.C837v_5R.mjs","names":["useRef"],"sources":["https:/framerusercontent.com/modules/kuZHg52HUWYSn30bn9Nj/Z9sEp2zn9baidSP2S7LT/MouseParallax.js"],"sourcesContent":["// MouseParallax component that applies mouse parallax effect to its parent container\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useRef}from\"react\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";import{useSpring,useMotionValue,useInView}from\"framer-motion\";/**\n * @framerSupportedLayoutWidth auto\n * @framerSupportedLayoutHeight auto\n *\n * @framerDisableUnlink\n */export default function MouseParallax(props){const{enabled=true,speed=1,xSpring,ySpring,xOffset,yOffset,rotationXSpring,rotationYSpring,xAngleRotation,yAngleRotation,floatingSpeed,yOffsetFloating}=props;const ref=useRef(null);const isStatic=useIsStaticRenderer();// LOGIC\nconst parentRef=useRef(null);const x=useMotionValue(0);const y=useMotionValue(0);const floatY=useMotionValue(0);const floatYFactor=useMotionValue(0);const rotationX=useMotionValue(0);const rotationY=useMotionValue(0);const prevRef=useRef({x:0,y:0});const bounds=useRef({x:0,y:0});const springX=useSpring(x,xSpring);const springY=useSpring(y,ySpring);const springFloatYFactor=useSpring(floatYFactor,{stiffness:160,damping:30});const springRotationX=useSpring(rotationX,rotationXSpring);const springRotationY=useSpring(rotationY,rotationYSpring);const isInViewRef=useRef(false);const getSpringValues=()=>{const currentSpringX=springX.get();const currentSpringY=springY.get()+floatY.get()*springFloatYFactor.get();const currentRotationX=springRotationX.get();const currentRotationY=springRotationY.get();return[currentSpringX,currentSpringY,currentRotationX,currentRotationY];};const updateValues=(x,y,rotY,rotX)=>{const parent=parentRef.current;const transform=`\n                perspective(800px)\n                translateX(${x}px)\n                translateY(${y}px)\n                rotateX(${rotY}deg)\n                rotateZ(${rotX}deg)\n            `;if(parent){parent.style.transform=transform;}};// SAVE PARENT\nuseEffect(()=>{parentRef.current=ref.current.parentElement.parentElement;},[]);// DETECT IN VIEW\nconst inView=useInView(parentRef);useEffect(()=>{isInViewRef.current=inView;},[inView]);// HANDLE ANIMATION\nuseEffect(()=>{const parent=parentRef.current;if(!parent)return;if(isStatic)return;let raf=undefined;let start=performance.now();// Mouse move handler\nconst handleMouseMove=e=>{if(!isInViewRef.current||!enabled)return;const vw=window.innerWidth;const vh=window.innerHeight;const dx=bounds.current.x;const dy=bounds.current.y;const offsetX=(e.clientX-vw*.5-(dx-vw*.5))*xOffset;const offsetY=(e.clientY-vh*.5-(dy-vh*.5))*yOffset;x.set(offsetX);y.set(offsetY);};// Spring change listeners\nconst unsubscribeX=springX.on(\"change\",latest=>{if(!enabled)return;const speed=latest-prevRef.current.x;prevRef.current.x=latest;springRotationX.set(speed*xAngleRotation);});const unsubscribeY=springY.on(\"change\",latest=>{if(!enabled)return;const speed=latest-prevRef.current.y;prevRef.current.y=latest;springRotationY.set(-speed*yAngleRotation);});// Set initial spring values based on enabled state\nif(enabled){updateValues(0,0,0,0)// RESET TO CALC BOUNDS\n;const b=parent.getBoundingClientRect();bounds.current.x=b.x+b.width*.5;bounds.current.y=b.y+b.height*.5;springFloatYFactor.set(1);}else{springFloatYFactor.set(0);springX.set(0);springY.set(0);springRotationX.set(0);springRotationY.set(0);}// Single RAF loop for both states\nconst animate=t=>{raf=requestAnimationFrame(animate);if(!isInViewRef.current)return;// Only update floating animation when enabled\nif(enabled){const elapsed=(t-start)/1e3;const offset=Math.sin(elapsed*floatingSpeed)*yOffsetFloating;floatY.set(offset);}// Always update transform (springs will animate to target values)\nconst[sx,sy,rx,ry]=getSpringValues();updateValues(sx,sy,ry,rx);};raf=requestAnimationFrame(animate);window.addEventListener(\"mousemove\",handleMouseMove);return()=>{unsubscribeX();unsubscribeY();cancelAnimationFrame(raf);window.removeEventListener(\"mousemove\",handleMouseMove);};},[enabled]);return /*#__PURE__*/_jsx(\"div\",{ref:ref,style:{position:\"absolute\",top:0,left:0,pointerEvents:\"none\",opacity:0,zIndex:-1}});}addPropertyControls(MouseParallax,{enabled:{type:ControlType.Boolean,title:\"Enabled\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\",description:\"Toggle the enabled will smoothly set back to origin. This component will target the parent.\"},xSpring:{type:ControlType.Transition,defaultValue:{type:\"spring\",stiffness:60,damping:20}},ySpring:{type:ControlType.Transition,defaultValue:{type:\"spring\",stiffness:60,damping:20}},rotationXSpring:{type:ControlType.Transition,defaultValue:{type:\"spring\",stiffness:160,damping:30}},rotationYSpring:{type:ControlType.Transition,defaultValue:{type:\"spring\",stiffness:160,damping:30}},xOffset:{type:ControlType.Number,defaultValue:.125,min:-1,max:1,step:.01},yOffset:{type:ControlType.Number,defaultValue:.125,min:-1,max:1,step:.01},xAngleRotation:{type:ControlType.Number,title:\"X Angle rotation\",defaultValue:.55,min:0,max:10,step:.01},yAngleRotation:{type:ControlType.Number,title:\"Y Angle rotation\",defaultValue:3,min:0,max:10,step:.01},floatingSpeed:{type:ControlType.Number,defaultValue:1.5,min:0,max:4,step:.01},yOffsetFloating:{type:ControlType.Number,defaultValue:10,min:0,max:100,step:1,description:\"Made with love by [Gustave Flowbert](https://x.com/flowbertgustave).\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"MouseParallax\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"auto\",\"framerDisableUnlink\":\"\",\"framerSupportedLayoutHeight\":\"auto\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./MouseParallax.map"],"mappings":"sQAMG,SAAwB,EAAc,EAAM,CAAC,GAAK,CAAC,UAAQ,GAAK,QAAM,EAAE,UAAQ,UAAQ,UAAQ,UAAQ,kBAAgB,kBAAgB,iBAAe,iBAAe,gBAAc,mBAAiB,EAAY,EAAIA,EAAO,IAAI,EAAQ,EAAS,EAAoB,EAClQ,EAAUA,EAAO,IAAI,EAAQ,EAAE,EAAe,CAAC,EAAQ,EAAE,EAAe,CAAC,EAAQ,EAAO,EAAe,C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