import{i as B,d as $,q as u,S as j,D,j as f,ad as _,x as C,ax as N,P as R,E as T,L as P,g as n,n as d,t as b,m as z,T as U,bb as q,o as S,I as F,w as M}from"./index-bc617d61.js";const[O,t]=B("image"),V={src:String,alt:String,fit:String,position:String,round:Boolean,block:Boolean,width:d,height:d,radius:d,lazyLoad:Boolean,iconSize:d,showError:b,errorIcon:z("photo-fail"),iconPrefix:String,showLoading:b,loadingIcon:z("photo")};var A=$({name:O,props:V,emits:["load","error"],setup(a,{emit:v,slots:s}){const i=u(!1),o=u(!0),r=u(),{$Lazyload:l}=j().proxy,x=D(()=>{const e={width:f(a.width),height:f(a.height)};return _(a.radius)&&(e.overflow="hidden",e.borderRadius=f(a.radius)),e});C(()=>a.src,()=>{i.value=!1,o.value=!0});const g=e=>{o.value&&(o.value=!1,v("load",e))},m=()=>{const e=new Event("load");Object.defineProperty(e,"target",{value:r.value,enumerable:!0}),g(e)},h=e=>{i.value=!0,o.value=!1,v("error",e)},w=(e,c,I)=>I?I():n(F,{name:e,size:a.iconSize,class:c,classPrefix:a.iconPrefix},null),E=()=>{if(o.value&&a.showLoading)return n("div",{class:t("loading")},[w(a.loadingIcon,t("loading-icon"),s.loading)]);if(i.value&&a.showError)return n("div",{class:t("error")},[w(a.errorIcon,t("error-icon"),s.error)])},k=()=>{if(i.value||!a.src)return;const e={alt:a.alt,class:t("img"),style:{objectFit:a.fit,objectPosition:a.position}};return a.lazyLoad?U(n("img",S({ref:r},e),null),[[q("lazy"),a.src]]):n("img",S({ref:r,src:a.src,onLoad:g,onError:h},e),null)},L=({el:e})=>{const c=()=>{e===r.value&&o.value&&m()};r.value?c():P(c)},y=({el:e})=>{e===r.value&&!i.value&&h()};return l&&N&&(l.$on("loaded",L),l.$on("error",y),R(()=>{l.$off("loaded",L),l.$off("error",y)})),T(()=>{P(()=>{var e;(e=r.value)!=null&&e.complete&&!a.lazyLoad&&m()})}),()=>{var e;return n("div",{class:t({round:a.round,block:a.block}),style:x.value},[k(),E(),(e=s.default)==null?void 0:e.call(s)])}}});const H=M(A);export{H as I};
