{"version":3,"file":"MouseParallax.DoaUdJwT.mjs","names":["useRef","__esmMin","init_ssg_sandbox_shims","init_npm_react_18_3_1","de","c","init_jsx_runtime","ce","window","useInView","useSpring","useMotionValue","init_framer_motion_DhsWWWsN","init_framer_B1b760uK","ControlType","useIsStaticRenderer","addPropertyControls","MouseParallax","props","ref","isStatic","parentRef","x","y","floatY","rotationX","rotationY","prevRef","springX","xSpring","springY","ySpring","springRotationX","rotationXSpring","springRotationY","rotationYSpring","isInViewRef","getSpringValues","updateValues","parent","transform","rotY","rotX","inView","enabled","handleMouseMove","offsetX","xOffset","offsetY","yOffset","unsubscribeX","speed","latest","xAngleRotation","unsubscribeY","yAngleRotation","raf","start","animate","elapsed","t","offset","floatingSpeed","yOffsetFloating","sx","sy","rx","ry","init_MouseParallax"],"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":"A,sQAMG,SAAwBiB,EAAc,EAAM,CAAC,GAAK,CAAC,UAAQ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