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