{"version":3,"file":"MouseParallax.Cm0FSEUB.mjs","names":["useRef","__esmMin","init_npm_react_18_3_1","init_ssg_sandbox_shims","window","c","init_jsx_runtime","ce","de","useSpring","useMotionValue","useInView","init_framer_motion_DhsWWWsN","addPropertyControls","init_framer_CaDWdxiz","useIsStaticRenderer","ControlType","MouseParallax","props","ref","isStatic","parentRef","x","y","floatY","floatYFactor","rotationX","rotationY","prevRef","bounds","springX","xSpring","springY","ySpring","springFloatYFactor","springRotationX","rotationXSpring","springRotationY","rotationYSpring","isInViewRef","getSpringValues","updateValues","parent","transform","rotY","rotX","inView","raf","start","handleMouseMove","enabled","vw","vh","dx","dy","offsetX","xOffset","offsetY","yOffset","unsubscribeX","speed","latest","xAngleRotation","unsubscribeY","yAngleRotation","b","animate","elapsed","t","offset","floatingSpeed","yOffsetFloating","sx","sy","rx","ry","init_MouseParallax"],"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":"A,sQAMG,SAAwBiB,EAAc,EAAM,CAAC,GAAK,CAAC,UAAQ,GAAK,QAAM,EAAE,UAAQ,UAAQ,UAAQ,UAAQ,kBAAgB,kBAAgB,iBAAe,iBAAe,gBAAc,mBAAiBC,EAAYC,EAAInB,EAAO,IAAI,EAAQoB,EAASL,EAAoB,EAClQM,EAAUrB,EAAO,IAAI,EAAQsB,EAAEZ,EAAe,CAAC,EAAQa,EAAEb,EAAe,CAAC,EAAQc,EAAOd,EAAe,CAAC,EAAQe,EAAaf,EAAe,CAAC,EAAQgB,EAAUhB,EAAe,CAAC,EAAQiB,EAAUjB,EAAe,CAAC,EAAQkB,EAAQ5B,EAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAQ6B,EAAO7B,EAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAQ8B,EAAQrB,EAAUa,EAAES,CAAO,EAAQC,EAAQvB,EAAUc,EAAEU,CAAO,EAAQC,EAAmBzB,EAAUgB,EAAa,CAAC,UAAU,IAAI,QAAQ,EAAE,CAAC,EAAQU,EAAgB1B,EAAUiB,EAAUU,CAAe,EAAQC,EAAgB5B,EAAUkB,EAAUW,CAAe,EAAQC,EAAYvC,EAAO,EAAK,EAAQwC,MAAiO,CAAvLV,EAAQ,IAA6L,EAAlKE,EAAQ,IAAI,EAAER,EAAO,IAAI,EAAEU,EAAmB,IAAI,EAAyBC,EAAgB,IAAuG,EAA1EE,EAAgB,IAA2E,CAAC,EAAUI,GAAc,EAAE,EAAE,EAAK,IAAO,CAAC,IAAMC,EAAOrB,EAAU,QAAcsB,EAAU;;6BAEl6BrB,EAAE;6BACFC,EAAE;0BAC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