{"version":3,"file":"HeroVideoAlt.szthfdsB.mjs","names":["React.useState","React.useRef","React.useCallback"],"sources":["https:/framerusercontent.com/modules/Kb1kgT33TI0Ht9DP2NZM/vqYMWc7Wl2mD6jHPoO14/HeroVideoAlt.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import*as React from\"react\";import{addPropertyControls,ControlType}from\"framer\";/* -------------------------------------------------\n   HeroVideo component\n   ------------------------------------------------- */export function HeroVideo({videoUrl,showSubtitles,posterFile}){const[videoID,setVideoID]=React.useState(null);const[origin,setOrigin]=React.useState(\"\");const[showPoster,setShowPoster]=React.useState(true);// NEW – only load iframe once component is near viewport\nconst[shouldLoadVideo,setShouldLoadVideo]=React.useState(false);const wrapperRef=React.useRef(null);const iframeRef=React.useRef(null);const[playerReady,setPlayerReady]=React.useState(false);/* -------------------------------------------------\n     * 1️⃣  Get the page origin\n     * ------------------------------------------------- */React.useEffect(()=>{setOrigin(window.location.origin);},[]);/* -------------------------------------------------\n     * 2️⃣  Extract YouTube video ID\n     * ------------------------------------------------- */React.useEffect(()=>{if(!videoUrl)return;try{const parsed=new URL(videoUrl);let id=null;if(parsed.searchParams.get(\"v\")){id=parsed.searchParams.get(\"v\");}else if(parsed.hostname===\"youtu.be\"){id=parsed.pathname.slice(1);}else if(parsed.pathname.includes(\"/shorts/\")){id=parsed.pathname.split(\"/shorts/\")[1];}else if(parsed.pathname.includes(\"/embed/\")){id=parsed.pathname.split(\"/embed/\")[1];}if(id){id=id.split(\"?\")[0].split(\"#\")[0];setVideoID(id);}}catch{// invalid URL → keep videoID null\n}},[videoUrl]);/* -------------------------------------------------\n     * 3️⃣  Lazy load once near viewport\n     * ------------------------------------------------- */React.useEffect(()=>{if(!wrapperRef.current)return;const observer=new IntersectionObserver(([entry])=>{if(entry.isIntersecting){setShouldLoadVideo(true);observer.disconnect();}},{root:null,rootMargin:\"300px\",threshold:.01});observer.observe(wrapperRef.current);return()=>observer.disconnect();},[]);/* -------------------------------------------------\n     * 4️⃣  Reset \"ready\" state whenever the video changes\n     *     so the caption command re-applies to the new\n     *     iframe instance instead of silently no-op'ing.\n     * ------------------------------------------------- */React.useEffect(()=>{setPlayerReady(false);},[videoID]);/* -------------------------------------------------\n     * 5️⃣  Listen for the YouTube player's real \"onReady\"\n     *     event instead of relying purely on a timeout.\n     *     Falls back to the timeout below if the message\n     *     never arrives (e.g. blocked by an extension).\n     * ------------------------------------------------- */React.useEffect(()=>{function handleMessage(event){if(event.origin!==\"https://www.youtube.com\"&&event.origin!==\"https://www.youtube-nocookie.com\"){return;}try{const data=JSON.parse(event.data);if(data.event===\"onReady\"){setPlayerReady(true);}}catch{// non-JSON message from the player, ignore\n}}window.addEventListener(\"message\",handleMessage);return()=>window.removeEventListener(\"message\",handleMessage);},[]);/* -------------------------------------------------\n     * 6️⃣  Force captions on/off via the YouTube IFrame API\n     *     (overrides the viewer's own YouTube caption\n     *     preference, which cc_load_policy alone can't do)\n     * ------------------------------------------------- */const sendCaptionCommand=React.useCallback(()=>{if(!iframeRef.current||!iframeRef.current.contentWindow)return;const command=showSubtitles?{event:\"command\",func:\"loadModule\",args:[\"captions\"]}:{event:\"command\",func:\"unloadModule\",args:[\"captions\"]};iframeRef.current.contentWindow.postMessage(JSON.stringify(command),\"*\");},[showSubtitles]);React.useEffect(()=>{if(!playerReady)return;sendCaptionCommand();// send again shortly after — the captions module can take a\n// moment to finish initializing even once the player fires ready\nconst timeout=setTimeout(sendCaptionCommand,500);return()=>clearTimeout(timeout);},[playerReady,sendCaptionCommand]);// Fallback in case the postMessage \"onReady\" event never arrives\nReact.useEffect(()=>{if(!shouldLoadVideo||playerReady)return;const fallback=setTimeout(()=>setPlayerReady(true),1200);return()=>clearTimeout(fallback);},[shouldLoadVideo,videoID,playerReady]);/* -------------------------------------------------\n     * 7️⃣  Build the YouTube embed URL\n     * ------------------------------------------------- */const embedUrl=videoID&&origin?`https://www.youtube.com/embed/${videoID}`+`?autoplay=1`+`&mute=1`+`&controls=0`+`&disablekb=1`+`&fs=0`+`&iv_load_policy=3`+`&loop=1`+`&playlist=${videoID}`+`&playsinline=1`+`&modestbranding=1`+`&rel=0`+`&enablejsapi=1`+`&cc_load_policy=${showSubtitles?1:0}`+`&cc_lang_pref=en`+`&origin=${encodeURIComponent(origin)}`:\"\";/* -------------------------------------------------\n     * 8️⃣  Poster background\n     * ------------------------------------------------- */const wrapperMergedStyle={...wrapperStyle,...posterFile&&showPoster?{backgroundImage:`url(${posterFile})`,backgroundSize:\"cover\",backgroundPosition:\"center\"}:{}};return /*#__PURE__*/_jsx(\"div\",{ref:wrapperRef,style:wrapperMergedStyle,children:videoID&&origin&&shouldLoadVideo&&/*#__PURE__*/_jsx(\"iframe\",{ref:iframeRef,src:embedUrl,style:iframeStyle,frameBorder:\"0\",loading:\"lazy\",allow:\"autoplay; fullscreen; picture-in-picture\",allowFullScreen:true,onLoad:()=>{setShowPoster(false);}},videoID)});}/* -------------------------------------------------\n   Static styles\n   ------------------------------------------------- */const wrapperStyle={position:\"relative\",width:\"100%\",height:\"100vh\",overflow:\"hidden\",backgroundColor:\"#000\"};const iframeStyle={position:\"absolute\",top:\"50%\",left:\"50%\",width:\"max(100vw, 177.777778vh)\",height:\"max(100vh, 56.25vw)\",transform:\"translate(-50%, -50%)\",border:0,pointerEvents:\"none\"};/* -------------------------------------------------\n   Framer property controls\n   ------------------------------------------------- */addPropertyControls(HeroVideo,{videoUrl:{type:ControlType.String,title:\"YouTube URL\",defaultValue:\"\"},showSubtitles:{type:ControlType.Boolean,title:\"Subtitles\",defaultValue:false,enabledTitle:\"On\",disabledTitle:\"Off\"},posterFile:{type:ControlType.Image,title:\"Poster Image\",defaultValue:\"\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"HeroVideo\":{\"type\":\"reactComponent\",\"name\":\"HeroVideo\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./HeroVideoAlt.map"],"mappings":"y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