{"version":3,"file":"InViewVideo.DAKeBqTf.mjs","names":["useRef","useState","__esmMin","init_ssg_sandbox_shims","init_npm_react_18_3_1","window","navigator","ce","init_jsx_runtime","_e","de","addPropertyControls","useIsStaticRenderer","ControlType","init_framer_DKtAEkcX","isAppleWebKit","ua","InViewVideo","props","ref","isStatic","src","setSrc","safariFile","file","el","played","inView","pending","lastScrollTry","tryPlay","playOnce","p","retryOnScroll","now","retryEvents","type","io","entry","entries","threshold","box","fit","radius","style","poster","loop","init_InViewVideo"],"sources":["https:/framerusercontent.com/modules/X6qDcv9WZ9BVgpRbNpZu/iqLVsvF7vw7nbOaNGegQ/InViewVideo.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useRef,useState}from\"react\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";// iPhone/iPad browsers and desktop Safari show transparent WebM with a black\n// background, and iOS before 17.4 can't play WebM at all.\nfunction isAppleWebKit(){if(typeof navigator===\"undefined\")return false;const ua=navigator.userAgent;if(/iPad|iPhone|iPod/.test(ua))return true;if(/Macintosh/.test(ua)&&navigator.maxTouchPoints>1)return true;return/Safari\\//.test(ua)&&/Version\\//.test(ua)&&!/Chrome|Chromium|CriOS|FxiOS|Edg|OPR|Firefox|Android/.test(ua);}/**\n * Video that plays only while it is on screen and pauses when it leaves.\n * With \"Play once\" it starts the first time it scrolls into view and stops on its last frame.\n * If the browser blocks autoplay, it tries again on the next click, key press or scroll.\n * iPhone, iPad and Safari use the \"Safari video\" file when one is set.\n *\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight any-prefer-fixed\n */export default function InViewVideo(props){const{file,safariFile,poster,loop,playOnce,threshold,fit,radius,background,style}=props;const ref=useRef(null);const isStatic=useIsStaticRenderer();// Pick the source after mount so iPhones never download the WebM.\nconst[src,setSrc]=useState(\"\");useEffect(()=>{setSrc(safariFile&&isAppleWebKit()?safariFile:file);},[file,safariFile]);useEffect(()=>{const el=ref.current;if(!el||!src||isStatic||typeof IntersectionObserver===\"undefined\")return;el.muted=true;let played=false;let inView=false;let pending=false;let lastScrollTry=0;const tryPlay=()=>{if(!inView||pending||!el.paused)return;if(playOnce&&played)return;pending=true;const p=el.play();if(p&&typeof p.then===\"function\"){p.then(()=>{played=true;pending=false;},()=>{pending=false;});}else{played=true;pending=false;}};// Browsers that block autoplay (e.g. Firefox \"Block Audio and Video\")\n// reject play() until the visitor interacts, so retry on interaction.\nconst retryOnScroll=()=>{const now=Date.now();if(now-lastScrollTry<1e3)return;lastScrollTry=now;tryPlay();};const retryEvents=[\"pointerdown\",\"keydown\",\"touchend\"];for(const type of retryEvents)window.addEventListener(type,tryPlay,{passive:true,capture:true});window.addEventListener(\"scroll\",retryOnScroll,{passive:true,capture:true});document.addEventListener(\"visibilitychange\",tryPlay);const io=new IntersectionObserver(entries=>{for(const entry of entries){inView=entry.isIntersecting;if(inView)tryPlay();else if(!el.paused)el.pause();}},{threshold});io.observe(el);return()=>{io.disconnect();for(const type of retryEvents)window.removeEventListener(type,tryPlay,true);window.removeEventListener(\"scroll\",retryOnScroll,true);document.removeEventListener(\"visibilitychange\",tryPlay);};},[src,playOnce,threshold,isStatic]);const box={position:\"relative\",width:\"100%\",height:\"100%\",display:\"block\",objectFit:fit,borderRadius:radius,background,overflow:\"hidden\",...style};if(isStatic||!file){return poster?.src?/*#__PURE__*/_jsx(\"img\",{src:poster.src,alt:poster.alt||\"\",style:box}):/*#__PURE__*/_jsx(\"div\",{style:box});}return /*#__PURE__*/_jsx(\"video\",{ref:ref,src:src||undefined,poster:poster?.src,muted:true,playsInline:true,loop:loop&&!playOnce,preload:\"metadata\",\"aria-hidden\":\"true\",style:box});}addPropertyControls(InViewVideo,{file:{type:ControlType.File,title:\"Video\",allowedFileTypes:[\"mp4\",\"webm\",\"mov\"]},safariFile:{type:ControlType.File,title:\"Safari video\",allowedFileTypes:[\"mp4\",\"mov\"],description:\"Used on iPhone, iPad and Safari. Needed when the main video is a transparent WebM.\"},poster:{type:ControlType.ResponsiveImage,title:\"Poster\"},loop:{type:ControlType.Boolean,title:\"Loop\",defaultValue:true},playOnce:{type:ControlType.Boolean,title:\"Play once\",defaultValue:false},threshold:{type:ControlType.Number,title:\"In view at\",defaultValue:.35,min:0,max:1,step:.05},fit:{type:ControlType.Enum,title:\"Fit\",options:[\"cover\",\"contain\",\"fill\"],defaultValue:\"cover\"},radius:{type:ControlType.Number,title:\"Radius\",defaultValue:0,min:0,max:100},background:{type:ControlType.Color,title:\"Background\",defaultValue:\"rgba(0,0,0,0)\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"InViewVideo\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerSupportedLayoutHeight\":\"any-prefer-fixed\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./InViewVideo.map"],"mappings":"A,iNAEA,SAASe,GAAe,CAAC,GAAUT,IAAY,OAAY,MAAO,GAAM,IAAMU,EAAGV,EAAU,UAAqH,MAAxG,mBAAmB,KAAKU,CAAE,GAAiB,YAAY,KAAKA,CAAE,GAAGV,EAAU,eAAe,EAAS,GAAW,WAAW,KAAKU,CAAE,GAAG,YAAY,KAAKA,CAAE,GAAG,CAAC,sDAAsD,KAAKA,CAAE,CAAE,CAQ9T,SAAwBC,EAAY,EAAM,CAAC,GAAK,CAAC,OAAK,aAAW,SAAO,OAAK,WAAS,YAAU,MAAI,SAAO,aAAW,SAAOC,EAAYC,EAAInB,EAAO,IAAI,EAAQoB,EAASR,EAAoB,EAC3L,CAACS,EAAIC,GAAQrB,EAAS,EAAE,EAAEM,MAAc,CAACe,EAAOC,GAAYR,EAAc,EAAEQ,EAAWC,CAAI,CAAE,EAAE,CAACA,EAAKD,CAAU,CAAC,EAAEhB,MAAc,CAAC,IAAMkB,EAAGN,EAAI,QAAQ,GAAG,CAACM,GAAI,CAACJ,GAA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