import{defineComponent as F,shallowRef as c,computed as H,watch as C,nextTick as S,onMounted as M,createVNode as u}from"vue";import D from"../_util/eagerComputed.mjs";import L from"../_util/hooks/useBreakpoint.mjs";import{getPropsSlot as V}from"../_util/props-util/index.mjs";import{responsiveArray as X}from"../_util/responsiveObserve.mjs";import q from"../_util/vue-types/index.mjs";import G from"../config-provider/hooks/useConfigInject.mjs";import J from"../vc-resize-observer/index.mjs";import{useAvatarInjectContext as K}from"./AvatarContext.mjs";import Q from"./style/index.mjs";const U=()=>({prefixCls:String,shape:{type:String,default:"circle"},size:{type:[Number,String,Object],default:()=>"default"},src:String,srcset:String,icon:q.any,alt:String,gap:Number,draggable:{type:Boolean,default:void 0},crossOrigin:String,loadError:{type:Function}}),le=F({compatConfig:{MODE:3},name:"AAvatar",inheritAttrs:!1,props:U(),slots:Object,setup(e,{slots:y,attrs:f}){const v=c(!0),$=c(!1),d=c(1),m=c(null),g=c(null),{prefixCls:x}=G("avatar",e),[R,A]=Q(x),z=K(),a=H(()=>e.size==="default"?z.size:e.size),E=L(),o=D(()=>{if(typeof e.size!="object")return;const t=X.find(s=>E.value[s]);return e.size[t]}),O=t=>o.value?{width:`${o.value}px`,height:`${o.value}px`,lineHeight:`${o.value}px`,fontSize:`${t?o.value/2:18}px`}:{},p=()=>{if(!m.value||!g.value)return;const t=m.value.offsetWidth,r=g.value.offsetWidth;if(t!==0&&r!==0){const{gap:s=4}=e;s*2<r&&(d.value=r-s*2<t?(r-s*2)/t:1)}},j=()=>{const{loadError:t}=e;t?.()!==!1&&(v.value=!1)};return C(()=>e.src,()=>{S(()=>{v.value=!0,d.value=1})}),C(()=>e.gap,()=>{S(()=>{p()})}),M(()=>{S(()=>{p(),$.value=!0})}),()=>{const{shape:t,src:r,alt:s,srcset:w,draggable:I,crossOrigin:T}=e,W=z.shape??t,l=V(y,e,"icon"),n=x.value,k={[`${f.class}`]:!!f.class,[n]:!0,[`${n}-lg`]:a.value==="large",[`${n}-sm`]:a.value==="small",[`${n}-${W}`]:!0,[`${n}-image`]:r&&v.value,[`${n}-icon`]:l,[A.value]:!0},N=typeof a.value=="number"?{width:`${a.value}px`,height:`${a.value}px`,lineHeight:`${a.value}px`,fontSize:l?`${a.value/2}px`:"18px"}:{},b=y.default?.();let i;if(r&&v.value)i=u("img",{draggable:I,src:r,srcset:w,onError:j,alt:s,crossorigin:T},null);else if(l)i=l;else if($.value||d.value!==1){const h=`scale(${d.value}) translateX(-50%)`,P={msTransform:h,WebkitTransform:h,transform:h},B=typeof a.value=="number"?{lineHeight:`${a.value}px`}:{};i=u(J,{onResize:p},{default:()=>[u("span",{class:`${n}-string`,ref:m,style:{...B,...P}},[b])]})}else i=u("span",{class:`${n}-string`,ref:m,style:{opacity:0}},[b]);return R(u("span",{...f,ref:g,class:k,style:[N,O(!!l),f.style]},[i]))}}});export{U as avatarProps,le as default};
