{"version":3,"file":"MouseParallax.BNaMu4Lo.mjs","names":["useRef","x","y","speed"],"sources":["https:/framerusercontent.com/modules/kuZHg52HUWYSn30bn9Nj/q5BTxMRdDgN90Ngoues5/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 rotationX=useMotionValue(0);const rotationY=useMotionValue(0);const prevRef=useRef({x:0,y:0});const springX=useSpring(x,xSpring);const springY=useSpring(y,ySpring);const springRotationX=useSpring(rotationX,rotationXSpring);const springRotationY=useSpring(rotationY,rotationYSpring);const isInViewRef=useRef(false);const getSpringValues=()=>{const currentSpringX=springX.get();const currentSpringY=springY.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]);useEffect(()=>{// STORE THE PARENT\nconst parent=parentRef.current;if(!parent)return;if(isStatic)return;if(!enabled)return;const r=Math.random();// MOUSE MOVE\nconst handleMouseMove=e=>{if(!isInViewRef.current)return;const offsetX=(e.clientX-window.innerWidth/2)*xOffset;const offsetY=(e.clientY-window.innerHeight/2)*yOffset;x.set(offsetX);y.set(offsetY);};const unsubscribeX=springX.on(\"change\",latest=>{const speed=latest-prevRef.current.x;prevRef.current.x=latest;springRotationX.set(speed*xAngleRotation);});const unsubscribeY=springY.on(\"change\",latest=>{const speed=latest-prevRef.current.y;prevRef.current.y=latest;springRotationY.set(-speed*yAngleRotation);});// RAF\nlet raf=undefined;const start=performance.now();const animate=t=>{raf=requestAnimationFrame(animate);if(!isInViewRef.current)return;const elapsed=(t-start)/1e3;const offset=Math.sin(elapsed*floatingSpeed)*yOffsetFloating;floatY.set(offset);// Get current values and update transform imperatively\nconst[sx,sy,rx,ry]=getSpringValues();updateValues(sx,sy+offset,ry,rx);};raf=requestAnimationFrame(animate);window.addEventListener(\"mousemove\",handleMouseMove);return()=>{unsubscribeX();unsubscribeY();cancelAnimationFrame(raf);window.removeEventListener(\"mousemove\",handleMouseMove);};},[enabled]);useEffect(()=>{const parent=parentRef.current;if(!parent)return;let raf=undefined;if(!enabled){springX.set(0);springY.set(0);springRotationX.set(0);springRotationY.set(0);const animate=()=>{const[sx,sy,rx,ry]=getSpringValues();updateValues(sx,sy,ry,rx);raf=requestAnimationFrame(animate);};raf=requestAnimationFrame(animate);}return()=>{cancelAnimationFrame(raf);};},[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\":{\"framerSupportedLayoutHeight\":\"auto\",\"framerDisableUnlink\":\"\",\"framerSupportedLayoutWidth\":\"auto\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./MouseParallax.map"],"mappings":"icAMG,SAAwB,EAAc,EAAM,CAAC,GAAK,CAAC,UAAQ,GAAK,QAAM,EAAE,UAAQ,UAAQ,UAAQ,UAAQ,kBAAgB,kBAAgB,iBAAe,iBAAe,gBAAc,mBAAiB,EAAY,EAAIA,EAAO,KAAK,CAAO,EAAS,GAAqB,CACnQ,EAAUA,EAAO,KAAK,CAAO,EAAE,EAAe,EAAE,CAAO,EAAE,EAAe,EAAE,CAAO,EAAO,EAAe,EAAE,CAAO,EAAU,EAAe,EAAE,CAAO,EAAU,EAAe,EAAE,CAAO,EAAQA,EAAO,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAO,EAAQ,EAAU,EAAE,EAAQ,CAAO,EAAQ,EAAU,EAAE,EAAQ,CAAO,EAAgB,EAAU,EAAU,EAAgB,CAAO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