{"version":3,"file":"ScrollParallax.B8MEVjO2.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,KAAK,CAAO,EAAS,GAAqB,CAAO,EAAUA,EAAO,EAAE,CAAO,EAAUA,EAAO,KAAK,CAAU,EAAO,EAAE,CAAC,IAAM,EAAKA,EAAO,CAAC,GAAG,EAAE,G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