el-image-viewer-ec0edec4.js 5.7 KB

1
  1. import{d6 as ve,z as me,aL as pe,aM as be,bs as ge,ba as X,d as G,d7 as H,d8 as ke,d9 as _e,br as we,aN as xe,da as ye,r as h,db as ze,c_ as Ie,e as _,w as j,n as he,b as Ce,o as C,C as q,f as i,A as b,B as m,ad as f,a,aH as J,aE as Ne,a3 as N,aG as w,b1 as Oe,c as Y,F as Q,by as Te,bz as Ae,dc as Le,dd as Re,a0 as Ee,de as Se,df as Xe,R as Ye,k as Be,v as Fe,aO as $e,T as Me,q as Pe,aP as De,bT as L,bS as I,dg as Ve,aQ as We,__tla as Ge}from"./index-54aa57d8.js";let U,O,He=Promise.all([(()=>{try{return Ge}catch{}})()]).then(async()=>{O=function(g,T,v){var n=!0,p=!0;if(typeof g!="function")throw new TypeError("Expected a function");return ve(v)&&(n="leading"in v?!!v.leading:n,p="trailing"in v?!!v.trailing:p),me(g,T,{leading:n,maxWait:T,trailing:p})};const Z=pe({urlList:{type:be(Array),default:()=>ge([])},zIndex:{type:Number},initialIndex:{type:Number,default:0},infinite:{type:Boolean,default:!0},hideOnClickModal:Boolean,teleported:Boolean,closeOnPressEscape:{type:Boolean,default:!0},zoomRate:{type:Number,default:1.2},minScale:{type:Number,default:.2},maxScale:{type:Number,default:7}}),K={close:()=>!0,switch:g=>X(g),rotate:g=>X(g)},ee=["src"],ae=G({name:"ElImageViewer"});U=We(De(G({...ae,props:Z,emits:K,setup(g,{expose:T,emit:v}){const n=g,p={CONTAIN:{name:"contain",icon:H(ke)},ORIGINAL:{name:"original",icon:H(_e)}},{t:se}=we(),l=xe("image-viewer"),{nextZIndex:ne}=ye(),R=h(),B=h([]),F=ze(),y=h(!0),k=h(n.initialIndex),A=Ie(p.CONTAIN),t=h({scale:1,deg:0,offsetX:0,offsetY:0,enableTransition:!1}),le=_(()=>{const{urlList:e}=n;return e.length<=1}),$=_(()=>k.value===0),M=_(()=>k.value===n.urlList.length-1),te=_(()=>n.urlList[k.value]),oe=_(()=>[l.e("btn"),l.e("prev"),l.is("disabled",!n.infinite&&$.value)]),ie=_(()=>[l.e("btn"),l.e("next"),l.is("disabled",!n.infinite&&M.value)]),ce=_(()=>{const{scale:e,deg:s,offsetX:o,offsetY:u,enableTransition:c}=t.value;let r=o/e,d=u/e;switch(s%360){case 90:case-270:[r,d]=[d,-r];break;case 180:case-180:[r,d]=[-r,-d];break;case 270:case-90:[r,d]=[-d,r]}const z={transform:`scale(${e}) rotate(${s}deg) translate(${r}px, ${d}px)`,transition:c?"transform .3s":""};return A.value.name===p.CONTAIN.name&&(z.maxWidth=z.maxHeight="100%"),z}),ue=_(()=>X(n.zIndex)?n.zIndex:ne());function E(){F.stop(),v("close")}function re(){y.value=!1}function de(e){y.value=!1,e.target.alt=se("el.image.error")}function fe(e){if(y.value||e.button!==0||!R.value)return;t.value.enableTransition=!1;const{offsetX:s,offsetY:o}=t.value,u=e.pageX,c=e.pageY,r=O(z=>{t.value={...t.value,offsetX:s+z.pageX-u,offsetY:o+z.pageY-c}}),d=L(document,"mousemove",r);L(document,"mouseup",()=>{d()}),e.preventDefault()}function P(){t.value={scale:1,deg:0,offsetX:0,offsetY:0,enableTransition:!1}}function D(){if(y.value)return;const e=Ve(p),s=Object.values(p),o=A.value.name,u=(s.findIndex(c=>c.name===o)+1)%e.length;A.value=p[e[u]],P()}function S(e){const s=n.urlList.length;k.value=(e+s)%s}function V(){$.value&&!n.infinite||S(k.value-1)}function W(){M.value&&!n.infinite||S(k.value+1)}function x(e,s={}){if(y.value)return;const{minScale:o,maxScale:u}=n,{zoomRate:c,rotateDeg:r,enableTransition:d}={zoomRate:n.zoomRate,rotateDeg:90,enableTransition:!0,...s};switch(e){case"zoomOut":t.value.scale>o&&(t.value.scale=Number.parseFloat((t.value.scale/c).toFixed(3)));break;case"zoomIn":t.value.scale<u&&(t.value.scale=Number.parseFloat((t.value.scale*c).toFixed(3)));break;case"clockwise":t.value.deg+=r,v("rotate",t.value.deg);break;case"anticlockwise":t.value.deg-=r,v("rotate",t.value.deg)}t.value.enableTransition=d}return j(te,()=>{he(()=>{const e=B.value[0];e!=null&&e.complete||(y.value=!0)})}),j(k,e=>{P(),v("switch",e)}),Ce(()=>{var e,s;(function(){const o=O(c=>{switch(c.code){case I.esc:n.closeOnPressEscape&&E();break;case I.space:D();break;case I.left:V();break;case I.up:x("zoomIn");break;case I.right:W();break;case I.down:x("zoomOut")}}),u=O(c=>{x((c.deltaY||c.deltaX)<0?"zoomIn":"zoomOut",{zoomRate:n.zoomRate,enableTransition:!1})});F.run(()=>{L(document,"keydown",o),L(document,"wheel",u)})})(),(s=(e=R.value)==null?void 0:e.focus)==null||s.call(e)}),T({setActiveItem:S}),(e,s)=>(C(),q(Pe,{to:"body",disabled:!e.teleported},[i(Me,{name:"viewer-fade",appear:""},{default:b(()=>[m("div",{ref_key:"wrapper",ref:R,tabindex:-1,class:f(a(l).e("wrapper")),style:J({zIndex:a(ue)})},[m("div",{class:f(a(l).e("mask")),onClick:s[0]||(s[0]=Ne(o=>e.hideOnClickModal&&E(),["self"]))},null,2),N(" CLOSE "),m("span",{class:f([a(l).e("btn"),a(l).e("close")]),onClick:E},[i(a(w),null,{default:b(()=>[i(a(Oe))]),_:1})],2),N(" ARROW "),a(le)?N("v-if",!0):(C(),Y(Q,{key:0},[m("span",{class:f(a(oe)),onClick:V},[i(a(w),null,{default:b(()=>[i(a(Te))]),_:1})],2),m("span",{class:f(a(ie)),onClick:W},[i(a(w),null,{default:b(()=>[i(a(Ae))]),_:1})],2)],64)),N(" ACTIONS "),m("div",{class:f([a(l).e("btn"),a(l).e("actions")])},[m("div",{class:f(a(l).e("actions__inner"))},[i(a(w),{onClick:s[1]||(s[1]=o=>x("zoomOut"))},{default:b(()=>[i(a(Le))]),_:1}),i(a(w),{onClick:s[2]||(s[2]=o=>x("zoomIn"))},{default:b(()=>[i(a(Re))]),_:1}),m("i",{class:f(a(l).e("actions__divider"))},null,2),i(a(w),{onClick:D},{default:b(()=>[(C(),q(Ee(a(A).icon)))]),_:1}),m("i",{class:f(a(l).e("actions__divider"))},null,2),i(a(w),{onClick:s[3]||(s[3]=o=>x("anticlockwise"))},{default:b(()=>[i(a(Se))]),_:1}),i(a(w),{onClick:s[4]||(s[4]=o=>x("clockwise"))},{default:b(()=>[i(a(Xe))]),_:1})],2)],2),N(" CANVAS "),m("div",{class:f(a(l).e("canvas"))},[(C(!0),Y(Q,null,Ye(e.urlList,(o,u)=>Be((C(),Y("img",{ref_for:!0,ref:c=>B.value[u]=c,key:o,src:o,style:J(a(ce)),class:f(a(l).e("img")),onLoad:re,onError:de,onMousedown:fe},null,46,ee)),[[Fe,u===k.value]])),128))],2),$e(e.$slots,"default")],6)]),_:3})],8,["disabled"]))}}),[["__file","/home/runner/work/element-plus/element-plus/packages/components/image-viewer/src/image-viewer.vue"]]))});export{U as E,He as __tla,O as t};