{"version":3,"file":"SmartVideo.CFHdUZRz.mjs","names":["useState","useRef"],"sources":["https:/framerusercontent.com/modules/rvygeiWoW7Hf1uaqcWXr/U9SFkvgicyik86u6zTO8/SmartVideo.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useState,useRef,useEffect}from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";export default function SmartVideo(props){const{videoFile,posterImage,posterAlt,style,playTrigger,playing,loop,objectFit,muted}=props;const[isActuallyPlaying,setIsActuallyPlaying]=useState(false);const[isReady,setIsReady]=useState(false);const[isInViewport,setIsInViewport]=useState(false);const[internalPlay,setInternalPlay]=useState(false);const[hasBeenTriggered,setHasBeenTriggered]=useState(false);const videoRef=useRef(null);const containerRef=useRef(null);const isCanvas=RenderTarget.current()===RenderTarget.canvas;useEffect(()=>{if(isCanvas)return;// Keeps your exact original -50% for existing instances, only changes to 0px for the new option\nconst margin=playTrigger===\"inViewBottom\"?\"0px\":\"0px 0px -50% 0px\";const observer=new IntersectionObserver(([entry])=>setIsInViewport(entry.isIntersecting),{rootMargin:margin,threshold:0});if(containerRef.current)observer.observe(containerRef.current);return()=>observer.disconnect();},[isCanvas,playTrigger]);useEffect(()=>{if(playTrigger===\"variant\"){setInternalPlay(isInViewport&&playing);}else if(playTrigger===\"inView\"||playTrigger===\"inViewBottom\"){// Both the original inView and the new inViewBottom trigger playback here\nsetInternalPlay(isInViewport);}},[isInViewport,playing,playTrigger]);useEffect(()=>{if(internalPlay)setHasBeenTriggered(true);},[internalPlay]);useEffect(()=>{if(!videoRef.current)return;if(internalPlay){videoRef.current.play().catch(()=>{});}else{videoRef.current.pause();}},[internalPlay]);return /*#__PURE__*/_jsxs(\"div\",{ref:containerRef,style:{...style,position:\"relative\",overflow:\"hidden\",backgroundColor:\"#000\"},children:[/*#__PURE__*/_jsx(\"style\",{children:` \n                video::-webkit-media-controls-start-playback-button { display: none !important; -webkit-appearance: none; } \n                video::-webkit-media-controls { display: none !important; } \n            `}),posterImage&&/*#__PURE__*/_jsx(\"img\",{src:posterImage,alt:posterAlt||\"\",style:{width:\"100%\",height:\"100%\",objectFit,position:\"absolute\",inset:0,zIndex:2,pointerEvents:\"none\",transition:\"opacity 0.5s ease\",opacity:isReady?0:1}}),videoFile&&/*#__PURE__*/_jsx(\"video\",{ref:videoRef,src:hasBeenTriggered?videoFile:\"\",muted:true,loop:loop,playsInline:true,autoPlay:true,preload:\"auto\",onLoadedData:()=>{if(videoRef.current){videoRef.current.currentTime=0;setIsReady(true);}},onPlaying:()=>setIsActuallyPlaying(true),onPause:()=>setIsActuallyPlaying(false),\"aria-hidden\":true,style:{width:\"100%\",height:\"100%\",objectFit,position:\"absolute\",zIndex:1}})]});}addPropertyControls(SmartVideo,{videoFile:{type:ControlType.File,title:\"Video\",allowedFileTypes:[\"mp4\",\"webm\"]},posterImage:{type:ControlType.Image,title:\"Poster\"},posterAlt:{type:ControlType.String,title:\"Poster Alt\",placeholder:\"Describe the image...\"},playTrigger:{type:ControlType.Enum,title:\"Trigger\",options:[\"variant\",\"inView\",\"inViewBottom\"],optionTitles:[\"Variant\",\"In View\",\"In View (Bottom)\"],defaultValue:\"variant\"},playing:{type:ControlType.Boolean,title:\"Play\",defaultValue:true,hidden:p=>p.playTrigger!==\"variant\"},loop:{type:ControlType.Boolean,title:\"Loop\",defaultValue:true},objectFit:{type:ControlType.Enum,title:\"Fit\",options:[\"cover\",\"contain\"]},muted:{type:ControlType.Boolean,title:\"Muted\",defaultValue:true}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"SmartVideo\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./SmartVideo.map"],"mappings":"iMAAuK,SAAwB,EAAW,EAAM,CAAC,GAAK,CAAC,YAAU,cAAY,YAAU,QAAM,cAAY,UAAQ,OAAK,YAAU,SAAO,EAAW,CAAC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