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