{"version":3,"file":"PauseOffscreenVideos.CLDB4Isc.mjs","names":["useRef","__esmMin","init_npm_react_18_3_1","init_ssg_sandbox_shims","c","J","init_jsx_runtime","ce","de","window","isYouTube","src","isVimeo","stop","frame","win","next","withPauseOffscreenVideos","wrap","left","id","host","box","centre","el","r","Component","props","init_PauseOffscreenVideos"],"sources":["https:/framerusercontent.com/modules/0K5b8L5VcAYObyoSn0lS/Yi2O8ZMB1Z0bRyBuLk7k/PauseOffscreenVideos.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{forwardRef,useEffect,useRef}from\"react\";// Pauses YouTube/Vimeo embeds in a carousel when they leave the centre slot.\n// Polls positions instead of listening for scroll, so it works however the carousel moves.\nfunction isYouTube(src){return/youtube(-nocookie)?\\.com|youtu\\.be/.test(src);}function isVimeo(src){return/vimeo\\.com/.test(src);}function stop(frame){const src=frame.getAttribute(\"src\")||\"\";const win=frame.contentWindow;if(!src)return;if(isVimeo(src)){win?.postMessage(JSON.stringify({method:\"pause\"}),\"*\");win?.postMessage({method:\"pause\"},\"*\");return;}if(isYouTube(src)){if(/enablejsapi=1/.test(src)){win?.postMessage(JSON.stringify({event:\"command\",func:\"pauseVideo\",args:\"\"}),\"*\");}else{// No player API: reload the embed without autoplay. This always stops playback.\nlet next=src.replace(/([?&])autoplay=1/g,\"$1autoplay=0\");next+=(next.includes(\"?\")?\"&\":\"?\")+\"enablejsapi=1\";frame.setAttribute(\"src\",next);}}}export function withPauseOffscreenVideos(Component){return /*#__PURE__*/forwardRef(function PauseOffscreenVideos(props,ref){const wrap=useRef(null);useEffect(()=>{if(typeof window===\"undefined\")return;const left=new WeakSet// frames already stopped since leaving centre\n;const tick=()=>{const host=wrap.current?.firstElementChild;if(!host)return;const box=host.getBoundingClientRect();if(box.width===0)return;const centre=box.left+box.width/2;host.querySelectorAll(\"iframe\").forEach(el=>{const frame=el;const r=frame.getBoundingClientRect();const inCentre=r.width>0&&r.left<=centre&&r.right>=centre;if(inCentre){left.delete(frame);}else if(!left.has(frame)){left.add(frame);stop(frame);}});};const id=window.setInterval(tick,300);return()=>window.clearInterval(id);},[]);return /*#__PURE__*/_jsx(\"div\",{ref:wrap,style:{display:\"contents\"},children:/*#__PURE__*/_jsx(Component,{...props,ref:ref})});});}\nexport const __FramerMetadata__ = {\"exports\":{\"withPauseOffscreenVideos\":{\"type\":\"reactHoc\",\"name\":\"withPauseOffscreenVideos\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./PauseOffscreenVideos.map"],"mappings":"A,8IAEA,SAASU,EAAU,EAAI,CAAC,MAAM,qCAAqC,KAAKC,CAAG,CAAE,CAAC,SAASC,EAAQ,EAAI,CAAC,MAAM,aAAa,KAAKD,CAAG,CAAE,CAAC,SAASE,EAAK,EAAM,CAAC,IAAMF,EAAIG,EAAM,aAAa,KAAK,GAAG,GAASC,EAAID,EAAM,cAAc,GAAIH,EAAW,IAAGC,EAAQD,CAAG,EAAGI,GAAK,YAAY,KAAK,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,GAAG,EAAEA,GAAK,YAAY,CAAC,OAAO,OAAO,EAAE,GAAG,OAAU,GAAGL,EAAUC,CAAG,EAAE,CAAC,GAAG,gBAAgB,KAAKA,CAAG,EAAGI,GAAK,YAAY,KAAK,UAAU,CAAC,MAAM,UAAU,KAAK,aAAa,KAAK,EAAE,CAAC,EAAE,GAAG,MAAO,CAC3e,IAAIC,EAAKL,EAAI,QAAQ,oBAAoB,cAAc,EAAE,IAAOK,EAAK,SAAS,GAAG,EAAE,IAAI,KAAK,gBAAgBF,EAAM,aAAa,MAAME,CAAI,CAAE,CAAC,CADsN,CACrN,CAAC,SAAgBC,EAAyB,EAAU,CAAC,MAAoB,gBAAW,SAA8B,EAAM,EAAI,CAAC,IAAMC,EAAKlB,EAAO,IAAI,EACqN,OADnNO,MAAc,CAAC,GAAUE,IAAS,OAAY,OAAO,IAAMU,kBAAK,IAA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