el-image-viewer-9d1c7d33.js 5.7 KB

1
  1. import{bL as ve,ax as me,aB as be,aC as pe,aL as ge,bq as X,d as V,bM as Z,bN as ke,bO as _e,aY as xe,aD as we,bP as ye,r as z,bQ as Ie,aO as he,K as _,L as G,an as ze,l as Ce,o as C,v as K,f as i,w as p,g as m,Z as f,a,au as U,aT as Oe,P as O,aU as x,a_ as Ne,c as S,F as j,bR as Te,bS as Le,bT as Ae,bU as Re,M as Ye,bV as Ee,bW as Xe,q as Se,x as Fe,a4 as $e,aE as Be,$ as Me,bX as Pe,aF as De,bY as A,bZ as h,b_ as We,aG as qe,__tla as Ve}from"./index-e3afde76.js";let H,N,Ze=Promise.all([(()=>{try{return Ve}catch{}})()]).then(async()=>{N=function(g,T,v){var n=!0,b=!0;if(typeof g!="function")throw new TypeError("Expected a function");return ve(v)&&(n="leading"in v?!!v.leading:n,b="trailing"in v?!!v.trailing:b),me(g,T,{leading:n,maxWait:T,trailing:b})};const J=be({urlList:{type:pe(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}}),Q={close:()=>!0,switch:g=>X(g),rotate:g=>X(g)},ee=["src"],ae=V({name:"ElImageViewer"});H=qe(De(V({...ae,props:J,emits:Q,setup(g,{expose:T,emit:v}){const n=g,b={CONTAIN:{name:"contain",icon:Z(ke)},ORIGINAL:{name:"original",icon:Z(_e)}},{t:se}=xe(),l=we("image-viewer"),{nextZIndex:ne}=ye(),R=z(),F=z([]),$=Ie(),y=z(!0),k=z(n.initialIndex),L=he(b.CONTAIN),t=z({scale:1,deg:0,offsetX:0,offsetY:0,enableTransition:!1}),le=_(()=>{const{urlList:e}=n;return e.length<=1}),B=_(()=>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&&B.value)]),ie=_(()=>[l.e("btn"),l.e("next"),l.is("disabled",!n.infinite&&M.value)]),ue=_(()=>{const{scale:e,deg:s,offsetX:o,offsetY:c,enableTransition:u}=t.value;let r=o/e,d=c/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 I={transform:`scale(${e}) rotate(${s}deg) translate(${r}px, ${d}px)`,transition:u?"transform .3s":""};return L.value.name===b.CONTAIN.name&&(I.maxWidth=I.maxHeight="100%"),I}),ce=_(()=>X(n.zIndex)?n.zIndex:ne());function Y(){$.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,c=e.pageX,u=e.pageY,r=N(I=>{t.value={...t.value,offsetX:s+I.pageX-c,offsetY:o+I.pageY-u}}),d=A(document,"mousemove",r);A(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=We(b),s=Object.values(b),o=L.value.name,c=(s.findIndex(u=>u.name===o)+1)%e.length;L.value=b[e[c]],P()}function E(e){const s=n.urlList.length;k.value=(e+s)%s}function W(){B.value&&!n.infinite||E(k.value-1)}function q(){M.value&&!n.infinite||E(k.value+1)}function w(e,s={}){if(y.value)return;const{minScale:o,maxScale:c}=n,{zoomRate:u,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/u).toFixed(3)));break;case"zoomIn":t.value.scale<c&&(t.value.scale=Number.parseFloat((t.value.scale*u).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 G(te,()=>{ze(()=>{const e=F.value[0];e!=null&&e.complete||(y.value=!0)})}),G(k,e=>{P(),v("switch",e)}),Ce(()=>{var e,s;(function(){const o=N(u=>{switch(u.code){case h.esc:n.closeOnPressEscape&&Y();break;case h.space:D();break;case h.left:W();break;case h.up:w("zoomIn");break;case h.right:q();break;case h.down:w("zoomOut")}}),c=N(u=>{w((u.deltaY||u.deltaX)<0?"zoomIn":"zoomOut",{zoomRate:n.zoomRate,enableTransition:!1})});$.run(()=>{A(document,"keydown",o),A(document,"wheel",c)})})(),(s=(e=R.value)==null?void 0:e.focus)==null||s.call(e)}),T({setActiveItem:E}),(e,s)=>(C(),K(Pe,{to:"body",disabled:!e.teleported},[i(Me,{name:"viewer-fade",appear:""},{default:p(()=>[m("div",{ref_key:"wrapper",ref:R,tabindex:-1,class:f(a(l).e("wrapper")),style:U({zIndex:a(ce)})},[m("div",{class:f(a(l).e("mask")),onClick:s[0]||(s[0]=Oe(o=>e.hideOnClickModal&&Y(),["self"]))},null,2),O(" CLOSE "),m("span",{class:f([a(l).e("btn"),a(l).e("close")]),onClick:Y},[i(a(x),null,{default:p(()=>[i(a(Ne))]),_:1})],2),O(" ARROW "),a(le)?O("v-if",!0):(C(),S(j,{key:0},[m("span",{class:f(a(oe)),onClick:W},[i(a(x),null,{default:p(()=>[i(a(Te))]),_:1})],2),m("span",{class:f(a(ie)),onClick:q},[i(a(x),null,{default:p(()=>[i(a(Le))]),_:1})],2)],64)),O(" ACTIONS "),m("div",{class:f([a(l).e("btn"),a(l).e("actions")])},[m("div",{class:f(a(l).e("actions__inner"))},[i(a(x),{onClick:s[1]||(s[1]=o=>w("zoomOut"))},{default:p(()=>[i(a(Ae))]),_:1}),i(a(x),{onClick:s[2]||(s[2]=o=>w("zoomIn"))},{default:p(()=>[i(a(Re))]),_:1}),m("i",{class:f(a(l).e("actions__divider"))},null,2),i(a(x),{onClick:D},{default:p(()=>[(C(),K(Ye(a(L).icon)))]),_:1}),m("i",{class:f(a(l).e("actions__divider"))},null,2),i(a(x),{onClick:s[3]||(s[3]=o=>w("anticlockwise"))},{default:p(()=>[i(a(Ee))]),_:1}),i(a(x),{onClick:s[4]||(s[4]=o=>w("clockwise"))},{default:p(()=>[i(a(Xe))]),_:1})],2)],2),O(" CANVAS "),m("div",{class:f(a(l).e("canvas"))},[(C(!0),S(j,null,Se(e.urlList,(o,c)=>Fe((C(),S("img",{ref_for:!0,ref:u=>F.value[c]=u,key:o,src:o,style:U(a(ue)),class:f(a(l).e("img")),onLoad:re,onError:de,onMousedown:fe},null,46,ee)),[[$e,c===k.value]])),128))],2),Be(e.$slots,"default")],6)]),_:3})],8,["disabled"]))}}),[["__file","/home/runner/work/element-plus/element-plus/packages/components/image-viewer/src/image-viewer.vue"]]))});export{H as E,Ze as __tla,N as t};