{"version":3,"file":"ScrollMedia_Prod.DIleizuk.mjs","names":["React.useState","React.useRef","React.useMemo","React.useCallback"],"sources":["https:/framerusercontent.com/modules/WFMQfiowoJrd5LLDWzbw/J7PDwmIuDSKZi6lvb4o3/ScrollMedia_Prod.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import*as React from\"react\";import{addPropertyControls,ControlType}from\"framer\";import{useMotionValue}from\"framer-motion\";import{ComponentMessage}from\"https://framerusercontent.com/modules/aej5zpwxBpkMdzOteBwy/DWeAZ5wauvGM5oFwVdgS/Utils.js\";const MediaRenderer=/*#__PURE__*/React.memo(({mode,media,currentTime,imageFit,videoRef,display,poster,posterEnabled})=>{const commonStyle={width:\"100%\",height:\"100%\",objectFit:imageFit,position:\"absolute\",top:0,left:0,display};React.useEffect(()=>{if(mode===\"video\"&&videoRef?.current&&currentTime!==undefined){const video=videoRef.current;if(Math.abs(video.currentTime-currentTime)>.1){video.currentTime=currentTime;}}},[mode,videoRef,currentTime]);if(mode===\"image\"){return /*#__PURE__*/_jsx(\"img\",{src:media.src,style:commonStyle,alt:\"\"});}else{return /*#__PURE__*/_jsx(\"video\",{ref:videoRef,src:media,style:commonStyle,preload:\"auto\",muted:true,playsInline:true,poster:posterEnabled?poster:undefined});}});/**\n * @framerIntrinsicWidth 400\n * @framerIntrinsicHeight 200\n *\n * @framerDisableUnlink\n *\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight fixed\n */export default function ScrollMedia({mode,images,video,scrollAreaHeight,imageFit,frameRate=30,sequenceStartOffset=0,triggerPosition=\"text-align-top\",poster,posterEnabled}){const[mediaState,setMediaState]=React.useState({loadedMedia:[],currentTime:0,videoDuration:0,isVideoMetadataLoaded:false});const videoRef=React.useRef(null);const componentRef=React.useRef(null);const scrollY=useMotionValue(0);const lastUpdateTime=React.useRef(0);const frameInterval=React.useMemo(()=>1e3/frameRate,[frameRate]);const startPositionRef=React.useRef(null);React.useEffect(()=>{if(mode===\"image\"){const preloadedImages=images.map(src=>{const img=new Image;img.src=src;return img;});setMediaState(prev=>({...prev,loadedMedia:preloadedImages}));}else{setMediaState(prev=>({...prev,loadedMedia:[],isVideoMetadataLoaded:false}));}},[images,mode]);React.useEffect(()=>{if(mode===\"video\"&&videoRef.current){const handleLoadedMetadata=()=>{setMediaState(prev=>({...prev,videoDuration:videoRef.current.duration,isVideoMetadataLoaded:true}));};videoRef.current.addEventListener(\"loadedmetadata\",handleLoadedMetadata);videoRef.current.load();return()=>{videoRef.current?.removeEventListener(\"loadedmetadata\",handleLoadedMetadata);};}},[mode,video]);const getOriginalPosition=element=>{// Find sticky parent or use the element itself if no sticky parent\nconst findStickyParent=el=>{let currentElement=el;while(currentElement&&currentElement!==document.body){const position=window.getComputedStyle(currentElement).position;if(position===\"sticky\"){return currentElement;}currentElement=currentElement.parentElement;}return null;};const stickyElement=findStickyParent(element);const targetElement=stickyElement||element;// Store original position\nconst originalPosition=targetElement.style.position;// Temporarily remove positioning\ntargetElement.style.position=\"static\";// Get position\nconst rect=targetElement.getBoundingClientRect();const scrollTop=window.pageYOffset||document.documentElement.scrollTop;const top=rect.top+scrollTop;// Restore original position\ntargetElement.style.position=originalPosition;return top;};const updateMediaPosition=React.useCallback(scrollPosition=>{if(!componentRef.current)return;const now=performance.now();if(mode===\"video\"&&now-lastUpdateTime.current<frameInterval)return;const rect=componentRef.current.getBoundingClientRect();const viewportHeight=window.innerHeight;const documentHeight=document.documentElement.scrollHeight;let triggerPoint=0;switch(triggerPosition){case\"text-align-middle\":triggerPoint=viewportHeight/2;break;case\"text-align-bottom\":triggerPoint=viewportHeight;break;default:triggerPoint=0;}let element=componentRef.current;if(startPositionRef.current===null&&rect.top<=triggerPoint){startPositionRef.current=getOriginalPosition(componentRef.current);}if(startPositionRef.current!==null){const scrollDistance=scrollPosition-startPositionRef.current;const totalScrollDistance=documentHeight-startPositionRef.current;const effectiveScrollArea=Math.min(scrollAreaHeight,totalScrollDistance);const progress=Math.max(0,Math.min(scrollDistance/effectiveScrollArea,1));if(mode===\"image\"){const newIndex=Math.floor(progress*(mediaState.loadedMedia.length-1));setMediaState(prev=>({...prev,currentTime:Math.min(newIndex,prev.loadedMedia.length-1)}));}else if(mode===\"video\"&&mediaState.videoDuration>0){const newTime=progress*mediaState.videoDuration;setMediaState(prev=>({...prev,currentTime:Math.min(newTime,prev.videoDuration)}));}}lastUpdateTime.current=now;},[mode,triggerPosition,scrollAreaHeight,mediaState.loadedMedia.length,mediaState.videoDuration,frameInterval]);const handleScroll=React.useCallback(()=>{requestAnimationFrame(()=>{const scrollPosition=window.scrollY;scrollY.set(scrollPosition);updateMediaPosition(scrollPosition);});},[scrollY,updateMediaPosition]);React.useEffect(()=>{window.addEventListener(\"scroll\",handleScroll,{passive:true});return()=>{window.removeEventListener(\"scroll\",handleScroll);startPositionRef.current=null;};},[handleScroll,video]);React.useEffect(()=>{const initialScrollPosition=window.scrollY;if(mode===\"video\"&&mediaState.isVideoMetadataLoaded){const initialScrollPosition=window.scrollY;scrollY.set(initialScrollPosition);updateMediaPosition(initialScrollPosition);}if(mode===\"image\"){scrollY.set(initialScrollPosition);updateMediaPosition(initialScrollPosition);}},[mode,mediaState.isVideoMetadataLoaded,updateMediaPosition]);const isEmptyState=React.useMemo(()=>{return mode===\"image\"&&images.length===0||mode===\"video\"&&!video;},[mode,images,video]);if(isEmptyState){return /*#__PURE__*/_jsx(ComponentMessage,{title:\"Scroll Media Component\",subtitle:mode===\"video\"?\"Upload a video file on the right properties panel.\":\"Upload your images/video on the right properties panel.\"});}return /*#__PURE__*/_jsx(\"div\",{ref:componentRef,style:{width:\"100%\",height:\"100%\",position:\"relative\"},children:mode===\"image\"?mediaState.loadedMedia.map((img,index)=>/*#__PURE__*/_jsx(MediaRenderer,{mode:\"image\",media:img,imageFit:imageFit,display:index===Math.floor(mediaState.currentTime)?\"block\":\"none\"},index)):/*#__PURE__*/_jsx(MediaRenderer,{mode:\"video\",media:video,currentTime:mediaState.currentTime,imageFit:imageFit,videoRef:videoRef,display:\"block\",poster:poster,posterEnabled:posterEnabled})});}ScrollMedia.displayName=\"Scroll Media\";ScrollMedia.defaultProps={mode:\"image\",images:[],video:\"\",scrollAreaHeight:5e3,imageFit:\"cover\",frameRate:30,sequenceStartOffset:0,triggerPosition:\"text-align-top\",posterEnabled:false,poster:\"\"};addPropertyControls(ScrollMedia,{mode:{type:ControlType.Enum,title:\"Mode\",options:[\"image\",\"video\"],optionTitles:[\"Image\",\"Video\"],displaySegmentedControl:true,segmentedControlDirection:\"vertical\"},images:{type:ControlType.Array,title:\"Images\",propertyControl:{type:ControlType.Image},hidden:({mode})=>mode!==\"image\"},video:{type:ControlType.File,title:\"Video\",allowedFileTypes:[\"mp4\"],hidden:({mode})=>mode!==\"video\"},imageFit:{type:ControlType.Enum,title:\"Media Fit\",options:[\"cover\",\"contain\"],optionTitles:[\"Cover\",\"Contain\"],displaySegmentedControl:true,segmentedControlDirection:\"horizontal\"},posterEnabled:{type:ControlType.Boolean,title:\"Poster\",enabledTitle:\"Yes\",disabledTitle:\"No\",description:\"I recommend adding a poster. [Learn more](https://framer.com/help/articles/how-are-videos-optimized-in-framer/).\",hidden:({mode})=>mode!==\"video\"},poster:{type:ControlType.Image,title:\" \",hidden:({mode,posterEnabled})=>mode!==\"video\"||!posterEnabled},triggerPosition:{type:ControlType.Enum,title:\"Start\",options:[\"text-align-top\",\"text-align-middle\",\"text-align-bottom\"],optionTitles:[\"Top\",\"Center\",\"Bottom\"],optionIcons:[\"text-align-top\",\"text-align-middle\",\"text-align-bottom\"],displaySegmentedControl:true,segmentedControlDirection:\"horizontal\"},scrollAreaHeight:{type:ControlType.Number,title:\"Length\",description:\"Rule of thumb: 500 for each second of the video. So for a 10s video, set length to 5000.\",min:10,max:1e5,step:100},frameRate:{type:ControlType.Number,title:\"FPS\",min:1,max:60,step:1,hidden:({mode})=>mode!==\"video\"},sequenceStartOffset:{type:ControlType.Number,title:\"Offset\",min:0,max:1e4,step:100,description:\"More components at [Framer University](https://frameruni.link/cc).\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"ScrollMedia\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"fixed\",\"framerContractVersion\":\"1\",\"framerIntrinsicHeight\":\"200\",\"framerDisableUnlink\":\"*\",\"framerSupportedLayoutWidth\":\"fixed\",\"framerIntrinsicWidth\":\"400\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ScrollMedia_Prod.map"],"mappings":"6TAQG,SAAwB,EAAY,CAAC,OAAK,SAAO,QAAM,mBAAiB,WAAS,YAAU,GAAG,sBAAoB,EAAE,kBAAgB,iBAAiB,SAAO,iBAAe,CAAC,GAAK,CAAC,EAAW,GAAeA,EAAe,CAAC,YAAY,CAAC,EAAE,YAAY,EAAE,cAAc,EAAE,sBAAsB,EAAK,CAAC,EAAQ,EAASC,EAAa,IAAI,EAAQ,EAAaA,EAAa,IAAI,EAAQ,EAAQ,EAAe,CAAC,EAAQ,EAAeA,EAAa,CAAC,EAAQ,EAAcC,MAAkB,IAAI,EAAU,CAAC,CAAS,CAAC,EAAQ,EAAiBD,EAAa,IAAI,EAAE,MAAoB,CAAC,GAAG,IAAO,QAAQ,CAAC,IAAM,EAAgB,EAAO,IAAI,GAAK,CAAC,IAAM,EAAI,IAAI,MAAkB,MAAZ,GAAI,IAAI,EAAW,CAAI,CAAC,EAAE,EAAc,IAAO,CAAC,GAAG,EAAK,YAAY,CAAe,EAAE,CAAE,MAAM,EAAc,IAAO,CAAC,GAAG,EAAK,YAAY,CAAC,EAAE,sBAAsB,EAAK,EAAE,CAAG,EAAE,CAAC,EAAO,CAAI,CAAC,EAAE,MAAoB,CAAC,GAAG,IAAO,SAAS,EAAS,QAAQ,CAAC,IAAM,MAAyB,CAAC,EAAc,IAAO,CAAC,GAAG,EAAK,cAAc,EAAS,QAAQ,SAAS,sBAAsB,EAAI,EAAE,CAAE,EAAmG,OAAjG,EAAS,Q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