{"version":3,"file":"ScrollVideo.DUWEdEpV.mjs","names":["useRef"],"sources":["https:/framerusercontent.com/modules/rTce9tZWJ7lIZ3wdy1O6/o2wO3lTRM9XCgjAd8vJd/ScrollVideo.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useRef}from\"react\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";const DEFAULT_VIDEO=\"https://framerusercontent.com/assets/MLWPbW1dUQawJLhhun3dBwpgJak.mp4\";/**\n * Scroll Video\n *\n * Place it so it fills a tall section (e.g. 300vh). The video pins to the\n * viewport while the section scrolls past, and its playhead follows the\n * scroll position (\"scrub\") or simply plays while in view (\"autoplay\").\n *\n * @framerIntrinsicWidth 1200\n * @framerIntrinsicHeight 2400\n *\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight fixed\n */export default function ScrollVideo(props){const{video=DEFAULT_VIDEO,poster,mode=\"scrub\",smoothing=.15,startAt=0,endAt=100,overlay=.45,style}=props;const isStatic=useIsStaticRenderer();const trackRef=useRef(null);const videoRef=useRef(null);useEffect(()=>{if(isStatic||typeof window===\"undefined\")return;const track=trackRef.current;const el=videoRef.current;if(!track||!el)return;const reduceMotion=window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;const useScrub=mode===\"scrub\"&&!reduceMotion;let raf=0;let inView=false;let loaded=false;let current=0;// Only fetch the file once the section is within a screen or so.\nconst nearby=new IntersectionObserver(([entry])=>{if(!entry.isIntersecting||loaded)return;loaded=true;el.preload=\"auto\";el.load();nearby.disconnect();},{rootMargin:\"150% 0px\"});nearby.observe(track);// Progress of the pinned stretch: 0 when the section top hits the\n// viewport top, 1 when the section bottom reaches the viewport bottom.\nconst progress=()=>{const rect=track.getBoundingClientRect();const range=rect.height-window.innerHeight;if(range<=0)return 0;return Math.min(1,Math.max(0,-rect.top/range));};const tick=()=>{raf=0;if(!inView)return;const duration=el.duration;if(duration&&isFinite(duration)){const from=startAt/100*duration;const to=endAt/100*duration;const target=from+(to-from)*progress();const k=Math.min(1,Math.max(.02,1-smoothing));current+=(target-current)*k;if(Math.abs(target-current)<.01)current=target;if(Math.abs(el.currentTime-current)>.01){el.currentTime=current;}if(current!==target)raf=requestAnimationFrame(tick);}};const onScroll=()=>{if(inView&&!raf)raf=requestAnimationFrame(tick);};const io=new IntersectionObserver(([entry])=>{inView=entry.isIntersecting;if(useScrub){onScroll();}else if(inView){el.play().catch(()=>{});}else{el.pause();}},{rootMargin:\"200px 0px\"});io.observe(track);if(useScrub){el.pause();window.addEventListener(\"scroll\",onScroll,{passive:true});window.addEventListener(\"resize\",onScroll);el.addEventListener(\"loadedmetadata\",onScroll);}return()=>{nearby.disconnect();io.disconnect();window.removeEventListener(\"scroll\",onScroll);window.removeEventListener(\"resize\",onScroll);el.removeEventListener(\"loadedmetadata\",onScroll);if(raf)cancelAnimationFrame(raf);};},[isStatic,mode,smoothing,startAt,endAt,video]);return /*#__PURE__*/_jsx(\"div\",{ref:trackRef,style:{...style,...trackStyle},children:/*#__PURE__*/_jsxs(\"div\",{style:stickyStyle,children:[/*#__PURE__*/_jsx(\"video\",{ref:videoRef,src:isStatic?`${video}#t=0.1`:video,poster:poster?.src,muted:true,playsInline:true,loop:mode===\"autoplay\",preload:isStatic?\"auto\":\"none\",\"aria-hidden\":\"true\",style:videoStyle}),/*#__PURE__*/_jsx(\"div\",{style:{...overlayStyle,background:`linear-gradient(180deg, rgba(0,0,0,${overlay*.5}) 0%, rgba(0,0,0,${overlay*.2}) 40%, rgba(0,0,0,${overlay}) 100%)`}})]})});}const trackStyle={position:\"relative\",width:\"100%\",height:\"100%\",background:\"#0A0A0A\"};const stickyStyle={position:\"sticky\",top:0,width:\"100%\",height:\"100vh\",overflow:\"hidden\"};const videoStyle={position:\"absolute\",inset:0,width:\"100%\",height:\"100%\",objectFit:\"cover\",display:\"block\"};const overlayStyle={position:\"absolute\",inset:0,pointerEvents:\"none\"};addPropertyControls(ScrollVideo,{video:{type:ControlType.File,title:\"Video\",allowedFileTypes:[\"mp4\",\"webm\",\"mov\"]},poster:{type:ControlType.ResponsiveImage,title:\"Poster\"},mode:{type:ControlType.Enum,title:\"Mode\",options:[\"scrub\",\"autoplay\"],optionTitles:[\"Scroll scrub\",\"Autoplay\"],defaultValue:\"scrub\",displaySegmentedControl:true},smoothing:{type:ControlType.Number,title:\"Smoothing\",defaultValue:.15,min:0,max:.95,step:.05,hidden:props=>props.mode!==\"scrub\"},startAt:{type:ControlType.Number,title:\"Start\",defaultValue:0,min:0,max:100,unit:\"%\",hidden:props=>props.mode!==\"scrub\"},endAt:{type:ControlType.Number,title:\"End\",defaultValue:100,min:0,max:100,unit:\"%\",hidden:props=>props.mode!==\"scrub\"},overlay:{type:ControlType.Number,title:\"Darken\",defaultValue:.45,min:0,max:1,step:.05}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"ScrollVideo\",\"slots\":[],\"annotations\":{\"framerIntrinsicWidth\":\"1200\",\"framerSupportedLayoutWidth\":\"fixed\",\"framerSupportedLayoutHeight\":\"fixed\",\"framerContractVersion\":\"1\",\"framerIntrinsicHeight\":\"2400\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ScrollVideo.map"],"mappings":"8MAYG,SAAwB,EAAY,EAAM,CAAC,GAAK,CAAC,QAAM,EAAc,SAAO,OAAK,QAAQ,YAAU,IAAI,UAAQ,EAAE,QAAM,IAAI,UAAQ,IAAI,SAAO,EAAY,EAAS,EAAoB,EAAQ,EAASA,EAAO,IAAI,EAAQ,EAASA,EAAO,IAAI,EAGmkC,OAHjkC,MAAc,CAAC,GAAG,GAAiB,IAAS,OAAY,OAAO,IAAM,EAAM,EAAS,QAAc,EAAG,EAAS,QAAQ,GAAG,CAAC,GAAO,CAAC,EAAG,OAAO,IAAM,EAAa,EAAO,WAAW,kCAAkC,CAAC,CAAC,QAAc,EAAS,IAAO,SAAS,CAAC,EAAiB,EAAI,EA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