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