{"version":3,"file":"InViewVideo.BiyiCI11.mjs","names":["useRef","useState","useEffect","_jsx","__esmMin","init_ssg_sandbox_shims","init_npm_react_18_3_1","window","navigator","ce","init_jsx_runtime","_e","de","addPropertyControls","useIsStaticRenderer","ControlType","init_framer_ChujFWHC","isAppleWebKit","ua","InViewVideo","props","file","safariFile","poster","loop","playOnce","threshold","fit","radius","background","style","ref","isStatic","src","setSrc","el","played","inView","pending","lastScrollTry","tryPlay","p","retryOnScroll","now","retryEvents","type","io","entries","entry","box","c","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,SAASiB,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,EAAYC,EAAM,CAAC,GAAK,CAACC,OAAKC,aAAWC,SAAOC,OAAKC,WAASC,YAAUC,MAAIC,SAAOC,aAAWC,SAAOV,EAAYW,EAAI/B,EAAO,IAAI,EAAQgC,EAASlB,EAAoB,EAC3L,CAACmB,EAAIC,GAAQjC,EAAS,EAAE,EAAEC,MAAc,CAACgC,EAAOZ,GAAYL,EAAc,EAAEK,EAAWD,CAAI,CAAE,EAAE,CAACA,EAAKC,CAAU,CAAC,EAAEpB,MAAc,CAAC,IAAMiC,EAAGJ,EAAI,QAA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