"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),ue=require("lodash-es/isNumber"),$=require("../../_util/classNames.js"),ce=require("../../_util/hooks/useMergedState.js"),de=require("../../_util/vue-types/index.js"),ve=require("../../vc-util/Dom/css.js"),pe=require("./Preview.js"),O=require("./PreviewGroup.js"),j=()=>({src:String,wrapperClassName:String,wrapperStyle:{type:Object,default:void 0},rootClassName:String,prefixCls:String,previewPrefixCls:String,width:[Number,String],height:[Number,String],previewMask:{type:[Boolean,Function],default:void 0},placeholder:de.default.any,fallback:String,preview:{type:[Boolean,Object],default:!0},onClick:{type:Function},onError:{type:Function}}),E=(t,d)=>{const a={...t};return Object.keys(d).forEach(o=>{t[o]===void 0&&(a[o]=d[o])}),a};let fe=0;const G=e.defineComponent({compatConfig:{MODE:3},name:"VcImage",inheritAttrs:!1,props:j(),emits:["click","error"],setup(t,{attrs:d,slots:a,emit:o}){const I=e.computed(()=>t.prefixCls),F=e.computed(()=>`${I.value}-preview`),u=e.computed(()=>{const r={visible:void 0,onVisibleChange:()=>{},getContainer:void 0};return typeof t.preview=="object"?E(t.preview,r):r}),m=e.computed(()=>u.value.src??t.src),P=e.computed(()=>t.placeholder&&t.placeholder!==!0||a.placeholder),g=e.computed(()=>u.value.visible),D=e.computed(()=>u.value.getContainer),S=e.computed(()=>g.value!==void 0),z=(r,s)=>{u.value.onVisibleChange?.(r,s)},[b,N]=ce.default(!!g.value,{value:g,onChange:z}),i=e.ref(P.value?"loading":"normal");e.watch(()=>t.src,()=>{i.value=P.value?"loading":"normal"});const w=e.ref(null),v=e.computed(()=>i.value==="error"),B=O.context.inject(),{isPreviewGroup:p,setCurrent:_,setShowPreview:A,setMousePosition:H,registerImage:L}=B,x=e.ref(fe++),n=e.computed(()=>t.preview&&!v.value),y=()=>{i.value="normal"},R=r=>{i.value="error",o("error",r)},T=r=>{if(!S.value){const{left:s,top:l}=ve.getOffset(r.target);p.value?(_(x.value),H({x:s,y:l})):w.value={x:s,y:l}}p.value?A(!0):N(!0),o("click",r)},U=()=>{N(!1),S.value||(w.value=null)},c=e.ref(null);e.watch(()=>c,()=>{i.value==="loading"&&c.value.complete&&(c.value.naturalWidth||c.value.naturalHeight)&&y()});let f=()=>{};e.onMounted(()=>{e.watch([m,n],()=>{if(f(),!p.value)return()=>{};f=L(x.value,m.value,n.value),n.value||f()},{flush:"post",immediate:!0})}),e.onUnmounted(()=>{f()});const h=r=>ue(r)?`${r}px`:r;return()=>{const{prefixCls:r,wrapperClassName:s,fallback:l,src:W,placeholder:V,wrapperStyle:J,rootClassName:k,width:M,height:C,crossorigin:K,decoding:Q,alt:q,sizes:X,srcset:Y,usemap:Z,class:ee,style:re}={...t,...d},{icons:te,maskClassName:ae,...oe}=u.value,le=$.default(r,s,k,{[`${r}-error`]:v.value}),ie=v.value&&l?l:m.value,ne={crossorigin:K,decoding:Q,alt:q,sizes:X,srcset:Y,usemap:Z,width:M,height:C,class:$.default(`${r}-img`,{[`${r}-img-placeholder`]:V===!0},ee),style:{height:h(C),...re}};return e.createVNode(e.Fragment,null,[e.createVNode("div",{class:le,onClick:n.value?T:se=>{o("click",se)},style:{width:h(M),height:h(C),...J}},[e.createVNode("img",{...ne,...v.value&&l?{src:l}:{onLoad:y,onError:R,src:W},ref:c},null),i.value==="loading"&&e.createVNode("div",{"aria-hidden":"true",class:`${r}-placeholder`},[V||a.placeholder&&a.placeholder()]),a.previewMask&&n.value&&e.createVNode("div",{class:[`${r}-mask`,ae]},[a.previewMask()])]),!p.value&&n.value&&e.createVNode(pe.default,{...oe,"aria-hidden":!b.value,visible:b.value,prefixCls:F.value,onClose:U,mousePosition:w.value,src:ie,alt:q,getContainer:D.value,icons:te,rootClassName:k},null)])}}});G.PreviewGroup=O.default;exports.default=G;exports.imageProps=j;exports.mergeDefaultValue=E;
