{"version":3,"file":"ParallaxImage.DCcD6Uc9.mjs","names":["useRef","useState","useCallback"],"sources":["https:/framerusercontent.com/modules/gRhAfrk6pPODYgDFRXz2/JaDxsmn5piiOba28zcjG/ParallaxImage.js"],"sourcesContent":["// Update Workshop/ParallaxImage.tsx to add a video poster image control and fallback behavior while preserving existing API/parallax behavior.\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useCallback,useEffect,useRef,useState,startTransition}from\"react\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";/**\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight fixed\n */export default function ParallaxImage(props){const{mediaType=\"image\",image={src:\"https://framerusercontent.com/images/GfGkADagM4KEibNcIiRUWlfrR0.jpg\",alt:\"Gradient 1 - Blue\"},video=\"https://framerusercontent.com/assets/MLWPbW1dUQawJLhhun3dBwpgJak.mp4\",posterImage,speed,scale,direction}=props;const containerRef=useRef(null);const imageRef=useRef(null);const videoRef=useRef(null);const hasTriggeredPosterFallbackRef=useRef(false);const isMountedRef=useRef(true);const isStatic=useIsStaticRenderer();const[showPosterFallback,setShowPosterFallback]=useState(false);const posterSrc=posterImage?.src||\"\";const posterIsAvailable=mediaType===\"video\"&&posterSrc.length>0;const triggerPosterFallback=useCallback(()=>{if(!posterIsAvailable||hasTriggeredPosterFallbackRef.current)return;hasTriggeredPosterFallbackRef.current=true;startTransition(()=>{if(isMountedRef.current)setShowPosterFallback(true);});},[posterIsAvailable]);useEffect(()=>{isMountedRef.current=true;return()=>{isMountedRef.current=false;};},[]);useEffect(()=>{hasTriggeredPosterFallbackRef.current=false;startTransition(()=>{if(isMountedRef.current)setShowPosterFallback(false);});},[mediaType,video,posterSrc]);useEffect(()=>{if(isStatic)return;const handleScroll=()=>{if(!containerRef.current||!imageRef.current)return;const rect=containerRef.current.getBoundingClientRect();const windowHeight=window.innerHeight;// Only animate if in view\nif(rect.bottom<0||rect.top>windowHeight)return;const scrollProgress=(windowHeight-rect.top)/(windowHeight+rect.height);// Center the progress around 0.5 so the image is centered when the container is centered\nconst parallaxOffset=(scrollProgress-.5)*speed*100;const finalOffset=direction===\"down\"?parallaxOffset:-parallaxOffset;imageRef.current.style.transform=`translateY(${finalOffset}px) scale(${scale})`;};if(typeof window!==\"undefined\"){window.addEventListener(\"scroll\",handleScroll,{passive:true});// Initial calculation\nrequestAnimationFrame(handleScroll);}return()=>{if(typeof window!==\"undefined\"){window.removeEventListener(\"scroll\",handleScroll);}};},[speed,scale,direction,isStatic]);return /*#__PURE__*/_jsx(\"div\",{ref:containerRef,style:{width:\"100%\",height:\"100%\",overflow:\"hidden\",position:\"relative\"},children:/*#__PURE__*/_jsx(\"div\",{ref:imageRef,style:{width:\"100%\",height:\"100%\",transform:`scale(${scale})`,willChange:\"transform\"},children:mediaType===\"image\"?/*#__PURE__*/_jsx(\"img\",{src:image.src,alt:image.alt||\"Parallax image\",style:{width:\"100%\",height:\"100%\",objectFit:\"cover\",display:\"block\"}}):showPosterFallback&&posterIsAvailable?/*#__PURE__*/_jsx(\"img\",{src:posterImage?.src,srcSet:posterImage?.srcSet,alt:posterImage?.alt||\"Video poster\",style:{width:\"100%\",height:\"100%\",objectFit:\"cover\",display:\"block\"}}):/*#__PURE__*/_jsx(\"video\",{ref:videoRef,src:video,poster:posterIsAvailable?posterSrc:undefined,autoPlay:true,loop:true,muted:true,playsInline:true,onError:triggerPosterFallback,onLoadedData:()=>{const videoElement=videoRef.current;if(!videoElement)return;const playPromise=videoElement.play();if(playPromise&&typeof playPromise.catch===\"function\"){playPromise.catch(()=>{triggerPosterFallback();});}},style:{width:\"100%\",height:\"100%\",objectFit:\"cover\",display:\"block\"}})})});}addPropertyControls(ParallaxImage,{mediaType:{type:ControlType.Enum,title:\"Media Type\",options:[\"image\",\"video\"],optionTitles:[\"Image\",\"Video\"],defaultValue:\"image\",displaySegmentedControl:true},image:{type:ControlType.ResponsiveImage,title:\"Image\",hidden:({mediaType})=>mediaType!==\"image\"},video:{type:ControlType.File,title:\"Video\",allowedFileTypes:[\"mp4\",\"webm\",\"mov\"],hidden:({mediaType})=>mediaType!==\"video\"},posterImage:{type:ControlType.ResponsiveImage,title:\"Poster Image\",hidden:({mediaType})=>mediaType!==\"video\"},direction:{type:ControlType.Enum,title:\"Direction\",options:[\"up\",\"down\"],optionTitles:[\"↑ Up\",\"↓ Down\"],defaultValue:\"down\",displaySegmentedControl:true},speed:{type:ControlType.Number,title:\"Speed\",defaultValue:.5,min:-2,max:2,step:.01,displayStepper:true},scale:{type:ControlType.Number,title:\"Scale\",defaultValue:1.2,min:1,max:2,step:.1,displayStepper:true}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"ParallaxImage\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"fixed\",\"framerSupportedLayoutWidth\":\"fixed\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ParallaxImage.map"],"mappings":"4NAIG,SAAwB,EAAc,EAAM,CAAC,GAAK,CAAC,YAAU,QAAQ,QAAM,CAAC,IAAI,sEAAsE,IAAI,mBAAmB,EAAE,QAAM,uEAAuE,cAAY,QAAM,QAAM,aAAW,EAAY,EAAaA,EAAO,IAAI,EAAQ,EAASA,EAAO,IAAI,EAAQ,EAASA,EAAO,IAAI,EAAQ,EAA8BA,EAAO,EAAK,EAAQ,EAAaA,EAAO,EAAI,EAAQ,EAAS,EAAoB,EAAO,CAAC,EAAmB,GAAuBC,EAAS,EAAK,EAAQ,EAAU,GAAa,KAAK,GAAS,EAAkB,IAAY,SAAS,EAAU,OAAO,EAAQ,EAAsBC,MAAgB,CAAI,CAAC,GAAmB,EAA8B,UAAe,EAA8B,QAAQ,GAAK,MAAoB,CAAI,EAAa,SAAQ,EAAsB,EAAI,CAAE,CAAC,EAAE,EAAE,CAAC,CAAiB,CAAC,EAGhvB,OAHkvB,OAAe,EAAa,QAAQ,OAAe,CAAC,EAAa,QAAQ,EA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