{"version":3,"file":"SmartVideo.B5fBMXGL.mjs","names":["useState","useRef"],"sources":["https:/framerusercontent.com/modules/udrpFurzkjtcXhgrt2rM/eD5XA8afsX4f99EtFotK/SmartVideo.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useRef,useState}from\"react\";import{addPropertyControls,ControlType}from\"framer\";function getYouTubeId(value){if(!value)return null;try{const url=new URL(value.trim());const host=url.hostname.toLowerCase().replace(/^www\\./,\"\");let id=\"\";if(host===\"youtu.be\"){id=url.pathname.split(\"/\").filter(Boolean)[0]||\"\";}else if(host===\"youtube.com\"||host===\"m.youtube.com\"||host===\"youtube-nocookie.com\"){const parts=url.pathname.split(\"/\").filter(Boolean);if(url.pathname===\"/watch\")id=url.searchParams.get(\"v\")||\"\";else if([\"embed\",\"shorts\",\"live\"].includes(parts[0]))id=parts[1]||\"\";}return/^[A-Za-z0-9_-]{6,}$/.test(id)?id:null;}catch{return null;}}/**\n * Framer renders one copy of this component per breakpoint and hides the\n * inactive ones with CSS. A hidden <video> still downloads, so every visitor\n * would pull every breakpoint's file. The src is therefore only attached once\n * the element is really laid out and near the viewport.\n */function useShouldLoad(ref){const[shouldLoad,setShouldLoad]=useState(false);useEffect(()=>{const el=ref.current;if(!el)return;let observer;// display:none (the inactive breakpoint copy) reports no offsetParent\n// and a zero-sized rect.\nconst isRendered=()=>{if(el.offsetParent===null&&getComputedStyle(el).position!==\"fixed\")return false;const rect=el.getBoundingClientRect();return rect.width>0&&rect.height>0;};const evaluate=()=>{if(!isRendered())return;if(typeof IntersectionObserver===\"undefined\"){setShouldLoad(true);return;}observer?.disconnect();observer=new IntersectionObserver(entries=>{if(entries.some(entry=>entry.isIntersecting)){setShouldLoad(true);observer?.disconnect();}},{rootMargin:\"200px\"});observer.observe(el);};evaluate();// The active breakpoint changes on resize, so re-check.\nwindow.addEventListener(\"resize\",evaluate);return()=>{window.removeEventListener(\"resize\",evaluate);observer?.disconnect();};},[ref]);return shouldLoad;}/**\n * @framerIntrinsicWidth 800\n * @framerIntrinsicHeight 450\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight any-prefer-fixed\n */export default function SmartVideo(props){const{url=\"\",autoplay=true,loop=true,muted=true,controls=true,fit=\"cover\",radius=\"0px\",background=\"#000000\",poster=\"\",preload=\"metadata\",style}=props;const rootRef=useRef(null);const shouldLoad=useShouldLoad(rootRef);const youtubeId=getYouTubeId(url);const rootStyle={...style,position:\"relative\",width:\"100%\",height:\"100%\",overflow:\"hidden\",borderRadius:radius,background};if(!url)return /*#__PURE__*/_jsx(\"div\",{ref:rootRef,style:{...rootStyle,background:\"transparent\"}});if(youtubeId){const params=new URLSearchParams({autoplay:autoplay?\"1\":\"0\",mute:muted?\"1\":\"0\",controls:controls?\"1\":\"0\",playsinline:\"1\",rel:\"0\"});if(loop){params.set(\"loop\",\"1\");params.set(\"playlist\",youtubeId);}return /*#__PURE__*/_jsx(\"div\",{ref:rootRef,style:rootStyle,children:shouldLoad?/*#__PURE__*/_jsx(\"iframe\",{src:`https://www.youtube.com/embed/${youtubeId}?${params.toString()}`,title:\"Video\",allow:\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\",allowFullScreen:true,referrerPolicy:\"strict-origin-when-cross-origin\",style:{width:\"100%\",height:\"100%\",border:0,display:\"block\"}}):null});}return /*#__PURE__*/_jsx(\"div\",{ref:rootRef,style:rootStyle,children:/*#__PURE__*/_jsx(\"video\",{src:shouldLoad?url:undefined,autoPlay:autoplay,loop:loop,muted:muted,controls:controls,playsInline:true,poster:poster||undefined,preload:preload,style:{width:\"100%\",height:\"100%\",objectFit:fit,display:\"block\"}})});}SmartVideo.displayName=\"Smart Video\";addPropertyControls(SmartVideo,{url:{type:ControlType.String,title:\"Video URL\",defaultValue:\"\",placeholder:\"YouTube or MP4 URL…\"},autoplay:{type:ControlType.Boolean,title:\"Autoplay\",defaultValue:true},loop:{type:ControlType.Boolean,title:\"Loop\",defaultValue:true},muted:{type:ControlType.Boolean,title:\"Muted\",defaultValue:true},controls:{type:ControlType.Boolean,title:\"Controls\",defaultValue:true},fit:{type:ControlType.Enum,title:\"MP4 Fit\",options:[\"cover\",\"contain\"],optionTitles:[\"Cover\",\"Contain\"],defaultValue:\"cover\",displaySegmentedControl:true},radius:{type:ControlType.BorderRadius,title:\"Radius\",defaultValue:\"0px\"},background:{type:ControlType.Color,title:\"Background\",defaultValue:\"#000000\"},poster:{type:ControlType.String,title:\"Poster URL\",defaultValue:\"\",placeholder:\"Still shown before playback…\",description:\"MP4 only. Prevents a blank frame while the video loads.\"},preload:{type:ControlType.Enum,title:\"Preload\",options:[\"none\",\"metadata\",\"auto\"],optionTitles:[\"None\",\"Metadata\",\"Auto\"],defaultValue:\"metadata\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"SmartVideo\",\"slots\":[],\"annotations\":{\"framerIntrinsicWidth\":\"800\",\"framerIntrinsicHeight\":\"450\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerSupportedLayoutHeight\":\"any-prefer-fixed\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./SmartVideo.map"],"mappings":"uMAA4I,SAAS,EAAa,EAAM,CAAC,GAAG,CAAC,EAAM,OAAO,KAAK,GAAG,CAAC,IAAM,EAAI,IAAI,IAAI,EAAM,KAAK,CAAC,EAAQ,EAAK,EAAI,SAAS,YAAY,CAAC,CAAC,QAAQ,SAAS,EAAE,EAAM,EAAG,GAAG,GAAG,IAAO,WAAY,EAAG,EAAI,SAAS,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,IAAI,QAAS,GAAG,IAAO,eAAe,IAAO,iBAAiB,IAAO,uBAAuB,CAAC,IAAM,EAAM,EAAI,SAAS,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO,EAAK,EAAI,WAAW,SAAS,EAAG,EAAI,aAA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