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