el-image-viewer-8d62bae1.js 5.7 KB

1
  1. import{bv as ve,b as me,aD as be,aE as pe,bk as ge,bl as Y,d as V,bw as W,bx as ke,by as we,bm as _e,aF as xe,bz as ye,r as h,bA as Ie,be as ze,L as w,M as j,ao as he,l as Ce,o as C,x as q,g as i,w as p,h as m,a0 as f,a,az as J,aw as Ne,Q as N,ay as _,aN as Oe,c as F,F as Q,bB as Te,bC as Ae,bD as Ee,bE as Le,N as Re,bF as Xe,bG as Ye,v as Fe,y as Se,a6 as Be,aG as De,a1 as $e,bH as Me,aH as Ge,bs as E,bI as z,bJ as He,aI as Pe,__tla as Ve}from"./index-52b99925.js";let U,O,We=Promise.all([(()=>{try{return Ve}catch{}})()]).then(async()=>{O=function(g,T,v){var l=!0,b=!0;if(typeof g!="function")throw new TypeError("Expected a function");return ve(v)&&(l="leading"in v?!!v.leading:l,b="trailing"in v?!!v.trailing:b),me(g,T,{leading:l,maxWait:T,trailing:b})};const Z=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}}),K={close:()=>!0,switch:g=>Y(g),rotate:g=>Y(g)},ee=["src"],ae=V({name:"ElImageViewer"});U=Pe(Ge(V({...ae,props:Z,emits:K,setup(g,{expose:T,emit:v}){const l=g,b={CONTAIN:{name:"contain",icon:W(ke)},ORIGINAL:{name:"original",icon:W(we)}},{t:se}=_e(),n=xe("image-viewer"),{nextZIndex:le}=ye(),L=h(),S=h([]),B=Ie(),y=h(!0),k=h(l.initialIndex),A=ze(b.CONTAIN),t=h({scale:1,deg:0,offsetX:0,offsetY:0,enableTransition:!1}),ne=w(()=>{const{urlList:e}=l;return e.length<=1}),D=w(()=>k.value===0),$=w(()=>k.value===l.urlList.length-1),te=w(()=>l.urlList[k.value]),oe=w(()=>[n.e("btn"),n.e("prev"),n.is("disabled",!l.infinite&&D.value)]),ie=w(()=>[n.e("btn"),n.e("next"),n.is("disabled",!l.infinite&&$.value)]),ce=w(()=>{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 I={transform:`scale(${e}) rotate(${s}deg) translate(${r}px, ${d}px)`,transition:c?"transform .3s":""};return A.value.name===b.CONTAIN.name&&(I.maxWidth=I.maxHeight="100%"),I}),ue=w(()=>Y(l.zIndex)?l.zIndex:le());function R(){B.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||!L.value)return;t.value.enableTransition=!1;const{offsetX:s,offsetY:o}=t.value,u=e.pageX,c=e.pageY,r=O(I=>{t.value={...t.value,offsetX:s+I.pageX-u,offsetY:o+I.pageY-c}}),d=E(document,"mousemove",r);E(document,"mouseup",()=>{d()}),e.preventDefault()}function M(){t.value={scale:1,deg:0,offsetX:0,offsetY:0,enableTransition:!1}}function G(){if(y.value)return;const e=He(b),s=Object.values(b),o=A.value.name,u=(s.findIndex(c=>c.name===o)+1)%e.length;A.value=b[e[u]],M()}function X(e){const s=l.urlList.length;k.value=(e+s)%s}function H(){D.value&&!l.infinite||X(k.value-1)}function P(){$.value&&!l.infinite||X(k.value+1)}function x(e,s={}){if(y.value)return;const{minScale:o,maxScale:u}=l,{zoomRate:c,rotateDeg:r,enableTransition:d}={zoomRate:l.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=S.value[0];e!=null&&e.complete||(y.value=!0)})}),j(k,e=>{M(),v("switch",e)}),Ce(()=>{var e,s;(function(){const o=O(c=>{switch(c.code){case z.esc:l.closeOnPressEscape&&R();break;case z.space:G();break;case z.left:H();break;case z.up:x("zoomIn");break;case z.right:P();break;case z.down:x("zoomOut")}}),u=O(c=>{x((c.deltaY||c.deltaX)<0?"zoomIn":"zoomOut",{zoomRate:l.zoomRate,enableTransition:!1})});B.run(()=>{E(document,"keydown",o),E(document,"wheel",u)})})(),(s=(e=L.value)==null?void 0:e.focus)==null||s.call(e)}),T({setActiveItem:X}),(e,s)=>(C(),q(Me,{to:"body",disabled:!e.teleported},[i($e,{name:"viewer-fade",appear:""},{default:p(()=>[m("div",{ref_key:"wrapper",ref:L,tabindex:-1,class:f(a(n).e("wrapper")),style:J({zIndex:a(ue)})},[m("div",{class:f(a(n).e("mask")),onClick:s[0]||(s[0]=Ne(o=>e.hideOnClickModal&&R(),["self"]))},null,2),N(" CLOSE "),m("span",{class:f([a(n).e("btn"),a(n).e("close")]),onClick:R},[i(a(_),null,{default:p(()=>[i(a(Oe))]),_:1})],2),N(" ARROW "),a(ne)?N("v-if",!0):(C(),F(Q,{key:0},[m("span",{class:f(a(oe)),onClick:H},[i(a(_),null,{default:p(()=>[i(a(Te))]),_:1})],2),m("span",{class:f(a(ie)),onClick:P},[i(a(_),null,{default:p(()=>[i(a(Ae))]),_:1})],2)],64)),N(" ACTIONS "),m("div",{class:f([a(n).e("btn"),a(n).e("actions")])},[m("div",{class:f(a(n).e("actions__inner"))},[i(a(_),{onClick:s[1]||(s[1]=o=>x("zoomOut"))},{default:p(()=>[i(a(Ee))]),_:1}),i(a(_),{onClick:s[2]||(s[2]=o=>x("zoomIn"))},{default:p(()=>[i(a(Le))]),_:1}),m("i",{class:f(a(n).e("actions__divider"))},null,2),i(a(_),{onClick:G},{default:p(()=>[(C(),q(Re(a(A).icon)))]),_:1}),m("i",{class:f(a(n).e("actions__divider"))},null,2),i(a(_),{onClick:s[3]||(s[3]=o=>x("anticlockwise"))},{default:p(()=>[i(a(Xe))]),_:1}),i(a(_),{onClick:s[4]||(s[4]=o=>x("clockwise"))},{default:p(()=>[i(a(Ye))]),_:1})],2)],2),N(" CANVAS "),m("div",{class:f(a(n).e("canvas"))},[(C(!0),F(Q,null,Fe(e.urlList,(o,u)=>Se((C(),F("img",{ref_for:!0,ref:c=>S.value[u]=c,key:o,src:o,style:J(a(ce)),class:f(a(n).e("img")),onLoad:re,onError:de,onMousedown:fe},null,46,ee)),[[Be,u===k.value]])),128))],2),De(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,We as __tla,O as t};