{"version":3,"file":"AutoSizeImage.AtIzQRBS.mjs","names":["useState","useRef","useCallback","useMemo","_Fragment"],"sources":["https:/framerusercontent.com/modules/mpORr3ooYAPo32G9Wjkp/dpO6GkFK4HWwGSolX7SW/AutoSizeImage.js"],"sourcesContent":["/**\n * Auto Size Image V1.5\n * @ mattimelgarejo on X\n *\n */import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{useEffect,useState,useRef,useMemo,useCallback}from\"react\";import{RenderTarget}from\"framer\";/**\n * @framerDisableUnlink\n */export default function AutoSizeImage({imageUrl,sizeBasedOn,enableLazyLoading=true,style,link,newTab}){const[aspectRatio,setAspectRatio]=useState(1);const containerRef=useRef(null);const[containerSize,setContainerSize]=useState(100)// Valor inicial 100 (ajusta según necesidad)\n;const[loaded,setLoaded]=useState(false);const handleLoad=useCallback(()=>{setLoaded(true);},[]);useEffect(()=>{if(!imageUrl)return;const img=new Image;img.src=imageUrl;img.onload=()=>{setAspectRatio(img.naturalWidth/img.naturalHeight);};},[imageUrl]);useEffect(()=>{if(!containerRef.current)return;const observer=new ResizeObserver(entries=>{const entry=entries[0];const newSize=sizeBasedOn===\"Height\"?entry.contentRect.height:entry.contentRect.width;if(newSize!==containerSize){setContainerSize(newSize);}});observer.observe(containerRef.current);return()=>{observer.disconnect();};},[sizeBasedOn,containerSize]);useEffect(()=>{if(!imageUrl)return;const img=new Image;img.src=imageUrl;// Verificar si la imagen ya está en caché\nif(img.complete){handleLoad()// Actualiza el estado manualmente\n;}},[imageUrl,handleLoad]);const calculatedSize=useMemo(()=>{if(!containerSize)return\"100%\";return sizeBasedOn===\"Height\"?containerSize*aspectRatio:containerSize/aspectRatio;},[containerSize,aspectRatio,sizeBasedOn]);const isCanvas=RenderTarget.current()===RenderTarget.canvas;// Aplica la transición solo si el lazy loading está activado\nconst imageStyle=isCanvas?{}:{opacity:loaded?1:0,transition:enableLazyLoading?\"opacity 0.5s ease-in\":\"none\",transform:\"translateZ(0)\",backfaceVisibility:\"hidden\"};const handleDoubleClick=()=>{if(isCanvas){const selectionEvent=new Event(\"mousedown\",{bubbles:true,cancelable:true});containerRef.current?.dispatchEvent(selectionEvent);}};const getAbsoluteUrl=url=>{if(!url)return\"\";// Si ya es una URL absoluta (externa), retórnala tal cual\nif(url.startsWith(\"http://\")||url.startsWith(\"https://\")){return url;}// Si es una ruta interna (empieza con /), déjala sin cambios\nif(url.startsWith(\"/\")){return url;}// Si es una URL externa sin protocolo, agrega https://\nreturn`https://${url}`;};const isExternalLink=url=>{return url.startsWith(\"http://\")||url.startsWith(\"https://\")||url.includes(\"://\")// Para otros protocolos como mailto: o tel:\n;};return /*#__PURE__*/_jsx(\"div\",{ref:containerRef,onDoubleClick:handleDoubleClick,style:{display:\"flex\",alignItems:\"center\",justifyContent:\"center\",overflow:\"hidden\",position:\"relative\",backgroundColor:imageUrl?\"transparent\":\"rgba(146, 97, 241, 0.10)\",minWidth:imageUrl&&sizeBasedOn===\"Height\"?\"50px\":\"auto\",minHeight:imageUrl&&sizeBasedOn===\"Width\"?\"50px\":\"auto\",borderRadius:imageUrl&&loaded?style.borderRadius:0,boxShadow:imageUrl&&loaded?style.boxShadow:\"none\",...imageUrl?sizeBasedOn===\"Height\"?{width:calculatedSize,height:\"100%\"}:{width:\"100%\",height:calculatedSize}:{width:\"100%\",height:\"100%\",minWidth:260,minHeight:150,padding:\"50px 80px\",boxSizing:\"border-box\"}},children:imageUrl?/*#__PURE__*/_jsxs(_Fragment,{children:[link?/*#__PURE__*/_jsx(\"a\",{href:getAbsoluteUrl(link),target:newTab?\"_blank\":\"_self\",rel:isExternalLink(getAbsoluteUrl(link))&&newTab?\"noopener noreferrer\":\"\",children:/*#__PURE__*/_jsx(\"img\",{src:imageUrl,loading:enableLazyLoading?\"lazy\":\"eager\",style:{...imageStyle,width:\"100%\",height:\"100%\",objectFit:\"cover\"},onLoad:handleLoad},imageUrl)}):// Si no hay enlace, muestra la imagen sin <a>\n/*#__PURE__*/_jsx(\"img\",{src:imageUrl,loading:enableLazyLoading?\"lazy\":\"eager\",style:{...imageStyle,width:\"100%\",height:\"100%\",objectFit:\"cover\"},onLoad:handleLoad},imageUrl),/*#__PURE__*/_jsx(\"div\",{style:{position:\"absolute\",top:0,left:0,right:0,bottom:0,...style.border,borderRadius:imageUrl&&loaded?style.borderRadius:0,pointerEvents:\"none\",opacity:loaded?1:0,transition:\"opacity 0.3s ease-in\"}})]}):/*#__PURE__*/_jsxs(_Fragment,{children:[/*#__PURE__*/_jsxs(\"div\",{style:{textAlign:\"center\",color:\"#9261F1\",opacity:.7},children:[/*#__PURE__*/_jsx(\"div\",{style:{fontSize:40,margin:\"15px 0\"},children:\"🖼️\"}),/*#__PURE__*/_jsx(\"h2\",{style:{fontSize:12,margin:\"10px 0\"},children:\"Select an Image\"})]}),/*#__PURE__*/_jsx(\"div\",{style:{position:\"absolute\",top:0,left:0,right:0,bottom:0,border:\"1px solid #9261F1\",pointerEvents:\"none\"}})]})});}AutoSizeImage.displayName=\"Auto Size Image\";addPropertyControls(AutoSizeImage,{imageUrl:{type:ControlType.Image,title:\"Image\"},sizeBasedOn:{type:ControlType.Enum,options:[\"Height\",\"Width\"],optionTitles:[\"Height\",\"Width\"],title:\"Size Based On\"},enableLazyLoading:{type:ControlType.Boolean,title:\"Lazy Loading\",defaultValue:true,description:\"Lazy loading delays loading of images until they are needed, improving performance. Disable this if you want images to load immediately.\"},link:{type:ControlType.Link,title:\"Link\",defaultValue:\"\"},newTab:{type:ControlType.Boolean,title:\"New Tab\",defaultValue:true,hidden:props=>!props.link},style:{type:ControlType.Object,title:\"Style\",controls:{border:{type:ControlType.Border,title:\"Border\",defaultValue:{borderWidth:0,borderStyle:\"solid\",borderColor:\"#000000\"}},borderRadius:{type:ControlType.BorderRadius,title:\"Border Radius\",defaultValue:0},boxShadow:{type:ControlType.BoxShadow,title:\"Box Shadow\",defaultValue:\"0px 1px 2px 0px rgba(0,0,0,0.25)\"}},description:\"More components and templates at [kavajuresa.xyz](https://kavajuresa.lemonsqueezy.com/).\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"AutoSizeImage\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerDisableUnlink\":\"\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./AutoSizeImage.map"],"mappings":"2NAMG,SAAwB,EAAc,CAAC,WAAS,cAAY,oBAAkB,GAAK,QAAM,OAAK,UAAQ,CAAC,GAAK,CAAC,EAAY,GAAgBA,EAAS,EAAE,CAAO,EAAaC,EAAO,KAAK,CAAM,CAAC,EAAc,GAAkBD,EAAS,IAAI,CACrO,CAAC,EAAO,GAAWA,EAAS,GAAM,CAAO,EAAWE,MAAgB,CAAC,EAAU,GAAK,EAAG,EAAE,CAAC,CAAC,MAAc,CAAC,GAAG,CAAC,EAAS,OAAO,IAAM,EAAI,IAAI,MAAM,EAAI,IAAI,EAAS,EAAI,WAAW,CAAC,EAAe,EAAI,aAAa,EAAI,cAAc,GAAK,CAAC,EAAS,CAAC,CAAC,MAAc,CAAC,GAAG,CAAC,EAAa,QAAQ,OAAO,IAAM,EAAS,IAAI,eAAe,GAAS,CAAC,IAAM,EAAM,EAAQ,GAAS,EAAQ,IAAc,SAAS,EAAM,YAAY,OAAO,EAAM,YAAY,MAAS,IAAU,GAAe,EAAiB,EAAQ,EAAI,CAAwC,OAAvC,EAAS,QAAQ,EAAa,QAAQ,KAAW,CAAC,EAAS,YAAY,GAAK,CAAC,EAAY,EAAc,CAAC,CAAC,MAAc,CAAC,GAAG,CAAC,EAAS,OAAO,IAAM,EAAI,IAAI,MAAM,EAAI,IAAI,EACnqB,EAAI,UAAU,GAAY,EACzB,CAAC,EAAS,EAAW,CAAC,CAAC,IAAM,EAAeC,MAAiB,EAAkC,IAAc,SAAS,EAAc,EAAY,EAAc,EAA7E,OAA2F,CAAC,EAAc,EAAY,EAAY,CAAC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