{"version":3,"file":"VideoPlayerAutoplay.BYLtjInt.mjs","names":["useRef"],"sources":["https:/framerusercontent.com/modules/YD32K57aEimHrY8nPLje/PWcMDPNT81YA0cvPMR0Z/VideoPlayerAutoplay.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useRef,useEffect}from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";import{Message}from\"https://framerusercontent.com/modules/bWuIUhIQLpjdL0ydQqRy/3nMJlk7029Qui8lmEzG8/Message.js\";/**\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight any-prefer-fixed\n */export default function VideoPlayerAutoplay({standardVideoUrl,hlsVideoUrl,videoType,muted,loop,loopSeconds,backgroundColor,lockAspectRatio,minHeight}){/* Checks */const currentTarget=RenderTarget.current();const isCanvas=currentTarget===RenderTarget.canvas||currentTarget===RenderTarget.export;const videoRef=useRef(null);const loopHandlerRef=useRef(null);const hlsRef=useRef(null);const videoUrl=videoType===\"standard\"?standardVideoUrl:hlsVideoUrl;useEffect(()=>{if(isCanvas)return;const video=videoRef.current;if(!video||!videoUrl)return;const handleVideoReady=()=>{const observer=new IntersectionObserver(([entry])=>{if(entry.isIntersecting){video.play().catch(e=>{console.log(\"caught\",e);});}else{video.pause();}},{threshold:.05});observer.observe(video);video.style.opacity=1;};video.addEventListener(\"canplay\",handleVideoReady);const enableLoop=()=>{if(!loop)return;if(loopSeconds>0){const handler=()=>{if(video.currentTime>=loopSeconds){video.currentTime=0;video.play().catch(e=>{console.log(\"caught\",e);});}};video.addEventListener(\"timeupdate\",handler);loopHandlerRef.current=handler;}else{video.loop=true;}};const disableLoop=()=>{if(loopHandlerRef.current){video.removeEventListener(\"timeupdate\",loopHandlerRef.current);loopHandlerRef.current=null;}video.loop=false;};const setupStandardVideo=()=>{video.src=videoUrl;// Video should be played here but the observer will handle play\nenableLoop();};const setupHLSVideo=async()=>{if(video.canPlayType(\"application/vnd.apple.mpegurl\")){video.src=videoUrl;// Video should be played here but the observer will handle play\nenableLoop();}else{try{await loadHlsScriptAndWait();const hls=new window.Hls;hls.loadSource(videoUrl);hls.attachMedia(video);hlsRef.current=hls;hls.on(window.Hls.Events.MANIFEST_PARSED,()=>{// Video should be played here but the observer will handle play\nenableLoop();});}catch(err){console.warn(\"HLS.js failed to load or is unsupported.\");}}};if(videoType===\"hls\"){setupHLSVideo();}else{setupStandardVideo();}// const observer = new IntersectionObserver(\n//     ([entry]) => {\n//         if (entry.isIntersecting) {\n//             video.play().catch((e) => {\n//                 console.log(\"caught\", e)\n//             })\n//         } else {\n//             video.pause()\n//             console.log(\"pausing video\")\n//         }\n//     },\n//     { threshold: 0.05 }\n// )\n// observer.observe(video)\nreturn()=>{disableLoop();video.removeEventListener(\"canplay\",handleVideoReady);if(hlsRef.current){hlsRef.current.destroy();hlsRef.current=null;}};},[videoUrl,videoType,loop,loopSeconds]);if(isCanvas){return /*#__PURE__*/_jsx(Message,{title:\"Video preview disabled in editor\",subtitle:\"To save bandwidth, the video player is disabled while editing. Preview or publish your site to see it in action.\"});}return /*#__PURE__*/_jsx(\"div\",{style:{width:\"100%\",height:\"100%\",position:\"relative\",overflow:\"hidden\",background:backgroundColor},children:/*#__PURE__*/_jsx(\"video\",{ref:videoRef,autoPlay:true,muted:muted,playsInline:true,style:{width:\"100%\",height:\"100%\",position:lockAspectRatio?\"relative\":\"absolute\",inset:0,objectFit:lockAspectRatio?\"contain\":\"cover\",display:\"block\",opacity:0,transition:\"opacity 0.8s ease\",minHeight:minHeight}})});}function waitForHlsReady(maxWait=1e3){return new Promise((resolve,reject)=>{const interval=50;let waited=0;const check=()=>{if(window.Hls&&typeof window.Hls.isSupported===\"function\"){resolve();}else if(waited>=maxWait){reject(new Error(\"HLS.js did not initialize in time\"));}else{waited+=interval;setTimeout(check,interval);}};check();});}async function loadHlsScriptAndWait(){const src=\"https://cdn.jsdelivr.net/npm/hls.js@latest\";if(!document.querySelector(`script[src=\"${src}\"]`)){const script=document.createElement(\"script\");script.src=src;script.async=true;document.body.appendChild(script);await new Promise((resolve,reject)=>{script.onload=()=>resolve();script.onerror=()=>reject(new Error(`Failed to load script: ${src}`));});}await waitForHlsReady();}addPropertyControls(VideoPlayerAutoplay,{videoType:{type:ControlType.Enum,title:\"Video Type\",options:[\"standard\",\"hls\"],optionTitles:[\"MP4 (.mp4)\",\"HLS (.m3u8)\"],defaultValue:\"standard\"},standardVideoUrl:{type:ControlType.String,title:\"MP4 Video URL\",placeholder:\"Paste .mp4 link\",hidden(props){return props.videoType!==\"standard\";}},hlsVideoUrl:{type:ControlType.String,title:\"HLS Video URL\",placeholder:\"Paste .m3u8 link\",hidden(props){return props.videoType!==\"hls\";}},muted:{type:ControlType.Boolean,title:\"Muted\",defaultValue:true},loop:{type:ControlType.Boolean,title:\"Loop\",defaultValue:true},loopSeconds:{type:ControlType.Number,title:\"Loop Seconds\",min:0,max:60,step:.1,defaultValue:0,displayStepper:true,hidden(props){return!props.loop;},description:\"Set to 0 to loop the entire video\"},backgroundColor:{type:ControlType.Color,title:\"Background Color Before Video Loads\",defaultValue:\"#000000\"},lockAspectRatio:{type:ControlType.Boolean,title:\"Lock Aspect Ratio\",defaultValue:false},minHeight:{type:ControlType.String,title:\"Video Min Height\",defaultValue:\"200px\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"VideoPlayerAutoplay\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerSupportedLayoutHeight\":\"any-prefer-fixed\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./VideoPlayerAutoplay.map"],"mappings":"uYAGG,SAAwB,EAAoB,CAAC,mBAAiB,cAAY,YAAU,QAAM,OAAK,cAAY,kBAAgB,kBAAgB,YAAU,CAAC,CAAa,IAAM,EAAc,EAAa,UAAgB,EAAS,IAAgB,EAAa,QAAQ,IAAgB,EAAa,OAAa,EAASA,EAA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