{"version":3,"file":"ScrollParallax.Beg6UXu2.mjs","names":["useRef"],"sources":["https:/framerusercontent.com/modules/5bshcyqeDyLlQxwY45u4/aMbEHB7DwZs7wT8G4QJn/ScrollParallax.js"],"sourcesContent":["// ScrollParallax component that applies scroll 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{useScroll,useMotionValueEvent}from\"framer-motion\";/**\n * @framerSupportedLayoutWidth auto\n * @framerSupportedLayoutHeight auto\n *\n * @framerDisableUnlink\n */export default function ScrollParallax(props){const{speed=1,enabled=true}=props;const ref=useRef(null);const isStatic=useIsStaticRenderer();const positionY=useRef(0);const parentRef=useRef(null);const vh=useRef(0);const size=useRef({vw:0,vh:0});const hasLenis=useRef(false);const normSpeed=speed-1;const{scrollYProgress}=useScroll();// MOTION SCROLL\nconst motionScroll=v=>{if(hasLenis.current)return;updateScroll(v);};// HANDLE PARALLAX\nconst updateScroll=latest=>{if(isStatic||!enabled)return;const parent=parentRef.current;if(!parent)return;const sh=document.documentElement.scrollHeight-size.current.vh;const scrollY=latest*sh;const finalY=positionY.current*normSpeed-scrollY*normSpeed;parent.style.transform=`translateY(${finalY}px)`;};// STORE VARIABLES\nuseEffect(()=>{const updateVars=()=>{parentRef.current=ref.current.parentElement.parentElement;if(size.current.vw!==window.innerWidth){size.current.vw=window.innerWidth;size.current.vh=window.innerHeight;}parentRef.current.style.transform=`translateY(${0}px)`// reset\n;const rect=parentRef.current.getBoundingClientRect();const scrollTop=window.scrollY;const y=rect.top+scrollTop-size.current.vh*.5;positionY.current=y;updateScroll(scrollYProgress.get());};updateVars();/*\n            DUE SOME USAGE IN MULTIPLE COMPONENTS, \n            TRIGGER A REFRESH EVERY x FRAMES\n        */let frames=0;let raf=null;let tick=60;const refreshLoop=()=>{if(frames%tick===0){updateVars();}frames++;raf=requestAnimationFrame(refreshLoop)// loop\n;};refreshLoop()// start\n;window.addEventListener(\"resize\",updateVars);return()=>{window.removeEventListener(\"resize\",updateVars);cancelAnimationFrame(raf);};},[]);// RESET POSITION ON DISABLE\nuseEffect(()=>{if(!enabled){parentRef.current.style.transform=`translateY(${0}px)`;}},[enabled]);// IF HAS LENIS (as it should) USE LENIS\nuseEffect(()=>{const cb=v=>{updateScroll(v.progress);};const lenis=window?.lenis;hasLenis.current=!!lenis;if(lenis){lenis.on(\"scroll\",cb);}return()=>{if(lenis){window?.lenis.off(\"scroll\",cb);}};},[]);// IF NOT LENIS USE MOTION\nuseMotionValueEvent(scrollYProgress,\"change\",motionScroll);return /*#__PURE__*/_jsx(\"div\",{ref:ref,style:{position:\"absolute\",top:0,left:0,pointerEvents:\"none\",opacity:0,zIndex:-1}});}addPropertyControls(ScrollParallax,{enabled:{type:ControlType.Boolean,title:\"Enabled\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\",description:`This will make the parent parallaxing on scroll, hitting default/idle position in center of the viewport. \n            \n            For smoother scroll we recommend to use [Lenis](https://lenis.framer.website/).`},speed:{type:ControlType.Number,title:\"Speed\",defaultValue:1,min:0,max:2,step:.01,description:\"Made with love by [Gustave Flowbert](https://x.com/flowbertgustave).\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"ScrollParallax\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"auto\",\"framerDisableUnlink\":\"\",\"framerSupportedLayoutHeight\":\"auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ScrollParallax.map"],"mappings":"+PAMG,SAAwB,EAAe,EAAM,CAAC,GAAK,CAAC,QAAM,EAAE,UAAQ,IAAM,EAAY,EAAIA,EAAO,IAAI,EAAQ,EAAS,EAAoB,EAAQ,EAAUA,EAAO,CAAC,EAAQ,EAAUA,EAAO,IAAI,EAAW,EAAO,CAAC,EAAE,IAAM,EAAKA,EAAO,CAAC,GAAG,EAA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