"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),T=require("../../_util/KeyCode.js"),N=require("../../_util/classNames.js"),fe=require("../../vc-dialog/DialogWrap.js"),ve=require("../../vc-dialog/IDialogPropTypes.js"),w=require("../../vc-util/Dom/addEventListener.js"),de=require("../../vc-util/Dom/css.js"),me=require("./PreviewGroup.js"),we=require("./getFixScaleEleTransPosition.js"),pe=require("./hooks/useFrameSetState.js"),r={x:0,y:0},V={...ve.default(),src:String,alt:String,rootClassName:String,icons:{type:Object,default:()=>({})}},Ce=t.defineComponent({compatConfig:{MODE:3},name:"Preview",inheritAttrs:!1,props:V,emits:["close","afterClose"],setup(o,{emit:P,attrs:I}){const{rotateLeft:U,rotateRight:z,zoomIn:F,zoomOut:W,close:E,left:G,right:K,flipX:j,flipY:A}=t.reactive(o.icons),l=t.shallowRef(1),p=t.shallowRef(0),s=t.reactive({x:1,y:1}),[n,c]=pe.default(r),R=()=>P("close"),h=t.shallowRef(),u=t.reactive({originX:0,originY:0,deltaX:0,deltaY:0}),f=t.shallowRef(!1),Z=me.context.inject(),{previewUrls:b,current:L,isPreviewGroup:S,setCurrent:y}=Z,x=t.computed(()=>b.value.size),C=t.computed(()=>Array.from(b.value.keys())),i=t.computed(()=>C.value.indexOf(L.value)),H=t.computed(()=>S.value?b.value.get(L.value):o.src),k=t.computed(()=>S.value&&x.value>1),D=t.shallowRef({wheelDirection:0}),_=()=>{l.value=1,p.value=0,s.x=1,s.y=1,c(r),P("afterClose")},Y=e=>{e?l.value+=.5:l.value++,c(r)},q=e=>{l.value>1&&(e?l.value-=.5:l.value--),c(r)},B=()=>{p.value+=90},J=()=>{p.value-=90},Q=()=>{s.x=-s.x},ee=()=>{s.y=-s.y},te=e=>{e.preventDefault(),e.stopPropagation(),i.value>0&&y(C.value[i.value-1])},oe=e=>{e.preventDefault(),e.stopPropagation(),i.value<x.value-1&&y(C.value[i.value+1])},le=N.default({[`${o.prefixCls}-moving`]:f.value}),ie=`${o.prefixCls}-operations-operation`,ae=`${o.prefixCls}-operations-icon`,se=[{icon:E,onClick:R,type:"close"},{icon:F,onClick:()=>Y(),type:"zoomIn"},{icon:W,onClick:()=>q(),type:"zoomOut",disabled:t.computed(()=>l.value===1)},{icon:z,onClick:B,type:"rotateRight"},{icon:U,onClick:J,type:"rotateLeft"},{icon:j,onClick:Q,type:"flipX"},{icon:A,onClick:ee,type:"flipY"}],X=()=>{if(o.visible&&f.value){const e=h.value.offsetWidth*l.value,a=h.value.offsetHeight*l.value,{left:v,top:g}=de.getOffset(h.value),d=p.value%180!==0;f.value=!1;const m=we.default(d?a:e,d?e:a,v,g);m&&c({...m})}},ne=e=>{e.button===0&&(e.preventDefault(),e.stopPropagation(),u.deltaX=e.pageX-n.x,u.deltaY=e.pageY-n.y,u.originX=n.x,u.originY=n.y,f.value=!0)},O=e=>{o.visible&&f.value&&c({x:e.pageX-u.deltaX,y:e.pageY-u.deltaY})},re=e=>{if(!o.visible)return;e.preventDefault();const a=e.deltaY;D.value={wheelDirection:a}},ce=e=>{!o.visible||!k.value||(e.preventDefault(),e.keyCode===T.default.LEFT?i.value>0&&y(C.value[i.value-1]):e.keyCode===T.default.RIGHT&&i.value<x.value-1&&y(C.value[i.value+1]))},ue=()=>{o.visible&&(l.value!==1&&(l.value=1),(n.x!==r.x||n.y!==r.y)&&c(r))};let M=()=>{};return t.onMounted(()=>{t.watch([()=>o.visible,f],()=>{M();let e,a;const v=w.default(window,"mouseup",X,!1),g=w.default(window,"mousemove",O,!1),d=w.default(window,"wheel",re,{passive:!1}),m=w.default(window,"keydown",ce,!1);try{window.top!==window.self&&(e=w.default(window.top,"mouseup",X,!1),a=w.default(window.top,"mousemove",O,!1))}catch{}M=()=>{v.remove(),g.remove(),d.remove(),m.remove(),e&&e.remove(),a&&a.remove()}},{flush:"post",immediate:!0}),t.watch([D],()=>{const{wheelDirection:e}=D.value;e>0?q(!0):e<0&&Y(!0)})}),t.onUnmounted(()=>{M()}),()=>{const{visible:e,prefixCls:a,rootClassName:v}=o;return t.createVNode(fe.default,{...I,transitionName:o.transitionName,maskTransitionName:o.maskTransitionName,closable:!1,keyboard:!0,prefixCls:a,onClose:R,afterClose:_,visible:e,wrapClassName:le,rootClassName:v,getContainer:o.getContainer},{default:()=>[t.createVNode("div",{class:[`${o.prefixCls}-operations-wrapper`,v]},[t.createVNode("ul",{class:`${o.prefixCls}-operations`},[se.map(({icon:g,onClick:d,type:m,disabled:$})=>t.createVNode("li",{class:N.default(ie,{[`${o.prefixCls}-operations-operation-disabled`]:$&&$?.value}),onClick:d,key:m},[t.cloneVNode(g,{class:ae})]))])]),t.createVNode("div",{class:`${o.prefixCls}-img-wrapper`,style:{transform:`translate3d(${n.x}px, ${n.y}px, 0)`}},[t.createVNode("img",{onMousedown:ne,onDblclick:ue,ref:h,class:`${o.prefixCls}-img`,src:H.value,alt:o.alt,style:{transform:`scale3d(${s.x*l.value}, ${s.y*l.value}, 1) rotate(${p.value}deg)`}},null)]),k.value&&t.createVNode("div",{class:N.default(`${o.prefixCls}-switch-left`,{[`${o.prefixCls}-switch-left-disabled`]:i.value<=0}),onClick:te},[G]),k.value&&t.createVNode("div",{class:N.default(`${o.prefixCls}-switch-right`,{[`${o.prefixCls}-switch-right-disabled`]:i.value>=x.value-1}),onClick:oe},[K])]})}}});exports.default=Ce;exports.previewProps=V;
