(function(M,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],r):(M=typeof globalThis<"u"?globalThis:M||self,r(M["vue3-image-viewer"]={},M.Vue))})(this,function(M,r){"use strict";const A=new IntersectionObserver(e=>{for(const t of e)if(t.isIntersecting){const o=t.target;o&&o.dataset&&(o.src=o.dataset.src,o.dispatchEvent(new Event("startLoad")),A.unobserve(o))}},{threshold:[0]}),ee={mounted(e,t){if(!t.value)return;const{src:o,active:s}=t.value;s?(e.dataset.src=o,A.observe(e)):e&&(e.src=o,e.dispatchEvent(new Event("startLoad")))}},ht="",x=(e,t)=>{const o=e.__vccOpts||e;for(const[s,i]of t)o[s]=i;return o},te={directives:{lazyLoad:ee},props:{src:{type:String,default:""},aspectRatio:{type:Number,default:0},fit:{type:String,default:""},lazy:{type:Boolean,default:!1},bgColor:{type:String,default:"black"},alt:{type:String,default:""},referrerPolicy:{type:String,default:""}},data(){return{loading:!1,failure:!1,success:!1}},computed:{imgRatioWrapStyle(){const{bgColor:e,aspectRatio:t}=this,o={position:"relative"};return o.backgroundColor=e,t?(o.width="100%",o.paddingBottom=`${t*100}%`):(o.width="100%",o.height="100%"),o}},methods:{onStartLoad(e){this.loading=!0,this.failure=!1,this.$emit("startLoad",e)},onLoaded(e){this.loading=!1,this.failure=!1,this.success=!0,this.$emit("load",e)},onError(e){this.loading=!1,this.failure=!0,this.success=!1,this.$emit("error",e)},handleImageClick(e){this.$emit("click",e)}}},oe={key:0,class:"v3iv-status-slot"},re={key:1,class:"v3iv-status-slot"},ne={class:"v3iv-slot-footer"},ie=["alt","referrer-policy"];function se(e,t,o,s,i,n){const a=r.resolveDirective("lazy-load");return r.openBlock(),r.createElementBlock("div",{style:r.normalizeStyle(n.imgRatioWrapStyle),onClick:t[3]||(t[3]=(...l)=>n.handleImageClick&&n.handleImageClick(...l))},[r.createElementVNode("div",{class:r.normalizeClass(["v3iv-img-wrap",{"v3iv-fix-ratio":o.aspectRatio,"v3iv-loading":i.loading,"v3iv-failure":i.failure}])},[i.failure?(r.openBlock(),r.createElementBlock("div",oe,[r.renderSlot(e.$slots,"error",{},void 0,!0)])):r.createCommentVNode("",!0),i.loading?(r.openBlock(),r.createElementBlock("div",re,[r.renderSlot(e.$slots,"loading",{},void 0,!0)])):r.createCommentVNode("",!0),r.createElementVNode("div",ne,[r.renderSlot(e.$slots,"footer",{},void 0,!0)]),r.withDirectives((r.openBlock(),r.createElementBlock("img",{class:r.normalizeClass(["v3iv-image",{"object-fit-style":!!o.fit}]),style:r.normalizeStyle({objectFit:o.fit}),alt:o.alt,"referrer-policy":o.referrerPolicy,onLoad:t[0]||(t[0]=(...l)=>n.onLoaded&&n.onLoaded(...l)),onError:t[1]||(t[1]=(...l)=>n.onError&&n.onError(...l)),"on:startLoad":t[2]||(t[2]=(...l)=>n.onStartLoad&&n.onStartLoad(...l)),key:o.src},null,46,ie)),[[a,{src:o.src,active:o.lazy}]])],2)],4)}const ae=x(te,[["render",se],["__scopeId","data-v-111e47d2"]]),mt="",le={inject:["jointUrl","closePreview"],props:{preload:{type:Array||Boolean,default(){return[0,2]}},images:{type:Array,default(){return[]}},curIndex:{type:Number,default:0},loop:{type:Boolean,default:!1}},data(){return{loading:!1,failure:!1,success:!1}},watch:{src:{handler(e){this.loading=!0,this.failure=!1,this.success=!1},immediate:!0}},computed:{src(){return this.currentItem.url||""},currentItem(){const{images:e,curIndex:t}=this;return e[t]||{}},preloadList(){const{images:e,preload:t,curIndex:o}=this;if(!t)return[];const s=e.length,i=o,n=t[0],a=t[1],l=Math.max(i-n,0),c=Math.min(i+a,s-1);return e.slice(l,c+1).map(m=>m.url)}},methods:{onPreviewKeydown(e){e.code==="Escape"&&this.closePreview(!0),(e.code==="ArrowLeft"||e.code==="KeyA")&&this.handleSwitch(-1),(e.code==="ArrowRight"||e.code==="KeyD")&&this.handleSwitch(1)},handleSwitch(e){if(!this.switchClickable(e))return;const{loop:t,curIndex:o,images:s}=this;let i=o+e;const n=s.length-1;t?(i<0&&(i=n),i>n&&(i=0)):(i=Math.max(0,i),i=Math.min(n,i)),this.$emit("switch",i)},switchClickable(e){const{loop:t,curIndex:o,images:s}=this;if(t)return!0;if(e==-1&&!o)return!1;const i=s.length-1;return!(e==1&&o==i)},getPreloadKey(e,t){return`${e}-${t}`},onPreviewLoad(){this.loading=!1,this.failure=!1,this.success=!0},onPreviewError(){this.loading=!1,this.failure=!0,this.success=!1}}},P=e=>(r.pushScopeId("data-v-c45b7d24"),e=e(),r.popScopeId(),e),ce={class:"v3iv-image-preview"},de={key:0,class:"v3iv-preview-error"},he={key:1,class:"v3iv-preview-loading"},me=["src"],fe=["src"],ue={class:"v3iv-img-append"},pe={class:"v3iv-title"},ge={class:"v3iv-desc"},ve=[P(()=>r.createElementVNode("i",{class:"zlhiconfont v3iv-icon icon-v3iv-guanbi"},null,-1))],ye=[P(()=>r.createElementVNode("i",{class:"zlhiconfont v3iv-icon icon-v3iv-left-arrow"},null,-1))],we=[P(()=>r.createElementVNode("i",{class:"zlhiconfont v3iv-icon icon-v3iv-right-arrow"},null,-1))];function be(e,t,o,s,i,n){return r.openBlock(),r.createElementBlock("div",ce,[r.createElementVNode("div",{class:r.normalizeClass(["v3iv-preview-center",{"v3iv-loading":i.loading,"v3iv-failure":i.failure}])},[i.failure?(r.openBlock(),r.createElementBlock("div",de,[r.renderSlot(e.$slots,"error",{},void 0,!0)])):r.createCommentVNode("",!0),i.loading?(r.openBlock(),r.createElementBlock("div",he,[r.renderSlot(e.$slots,"loading",{},void 0,!0)])):r.createCommentVNode("",!0),r.withDirectives(r.createElementVNode("img",{class:"v3iv-preview-img",onLoad:t[0]||(t[0]=(...a)=>n.onPreviewLoad&&n.onPreviewLoad(...a)),onError:t[1]||(t[1]=(...a)=>n.onPreviewError&&n.onPreviewError(...a)),src:n.src},null,40,me),[[r.vShow,!i.loading&&!i.failure]]),(r.openBlock(!0),r.createElementBlock(r.Fragment,null,r.renderList(n.preloadList,(a,l)=>r.withDirectives((r.openBlock(),r.createElementBlock("div",{key:n.getPreloadKey(a,l)},[r.createElementVNode("img",{src:n.jointUrl(a)},null,8,fe)])),[[r.vShow,!1]])),128)),r.createElementVNode("div",ue,[r.createElementVNode("div",pe,r.toDisplayString(n.currentItem.title),1),r.createElementVNode("div",ge,r.toDisplayString(n.currentItem.desc),1)])],2),r.createElementVNode("div",{class:"v3iv-preview-close",onClick:t[2]||(t[2]=r.withModifiers(a=>n.closePreview(!0),["stop"]))},ve),r.createElementVNode("div",{class:"v3iv-preview-sl",onClick:t[3]||(t[3]=r.withModifiers(a=>n.handleSwitch(-1),["stop"]))},ye),r.createElementVNode("div",{class:"v3iv-preview-sr",onClick:t[4]||(t[4]=r.withModifiers(a=>n.handleSwitch(1),["stop"]))},we)])}const ke=x(le,[["render",be],["__scopeId","data-v-c45b7d24"]]),gt="",_e={emits:["switch","close","load","error"],provide(){return{jointUrl:this.jointUrl,closePreview:this.closePreview}},components:{Image:ae,Preview:ke},props:{base:{type:String,default:""},src:{type:String,default:""},token:{type:String,default:""},width:{type:String,default:""},height:{type:String,default:""},fit:{type:String,default:"cover"},aspectRatio:{type:Number},lazy:{type:Boolean},bgColor:{type:String},alt:{type:String},referrerPolicy:{type:String},hideOnClickModal:{type:Boolean,default:!1},images:{type:Array,default(){return[]}},loop:{type:Boolean,default:!1},preload:{type:Array||Boolean,default(){return[0,2]}},initialIndex:{type:Number,default:0},preview:{type:Boolean,default:!1}},data(){return{previewVisible:!1,previewIndex:this.initialIndex}},computed:{wrapStyle(){const{width:e,height:t}=this,o={};return e&&(o.width=e),t&&(o.height=t),o},_src(){const{src:e}=this;return this.jointUrl(e)}},methods:{handleSwitch(e){this.previewIndex=e,this.$emit("switch",e)},closePreview(e){e&&(this.$emit("close"),this.previewVisible=!1)},onLoaded(e){this.$emit("load",e)},onError(e){this.$emit("error",e)},handleImageClick(){!this.preview||(this.previewVisible=!0,this.previewIndex=this.initialIndex)},jointUrl(e){if(!e)return"";const{base:t,token:o}=this,s=o?`?token=${o}`:"";return e.startsWith("data:")||e.startsWith("http:")||e.startsWith("https:")||e.startsWith("blob:")?`${e}${s}`:`${t}${e}${s}`}}};function xe(e,t,o,s,i,n){const a=r.resolveComponent("Image"),l=r.resolveComponent("Preview");return r.openBlock(),r.createElementBlock("div",{style:r.normalizeStyle(n.wrapStyle),class:r.normalizeClass(["v3iv-image-wrap",{"v3iv-preview-active":i.previewVisible}])},[r.createVNode(a,{src:n._src,aspectRatio:o.aspectRatio,fit:o.fit,lazy:o.lazy,bgColor:o.bgColor,alt:o.alt,referrerPolicy:o.referrerPolicy,onClick:n.handleImageClick,onLoad:n.onLoaded,onError:n.onError,style:{"{\r\n cursor":`preview ? 'pointer' : 'default',\r }`},class:r.normalizeClass({"v3iv-clickable":o.preview})},{loading:r.withCtx(()=>[r.renderSlot(e.$slots,"loading",{},void 0,!0)]),error:r.withCtx(()=>[r.renderSlot(e.$slots,"error",{},void 0,!0)]),footer:r.withCtx(()=>[r.renderSlot(e.$slots,"footer",{},void 0,!0)]),_:3},8,["src","aspectRatio","fit","lazy","bgColor","alt","referrerPolicy","onClick","onLoad","onError","class"]),i.previewVisible?(r.openBlock(),r.createBlock(l,{key:0,class:r.normalizeClass({"v3iv-clickable":o.hideOnClickModal}),onClick:t[0]||(t[0]=c=>n.closePreview(o.hideOnClickModal)),preload:o.preload,images:o.images,curIndex:i.previewIndex,loop:o.loop,onSwitch:n.handleSwitch},{loading:r.withCtx(()=>[r.renderSlot(e.$slots,"loading",{},void 0,!0)]),error:r.withCtx(()=>[r.renderSlot(e.$slots,"error",{},void 0,!0)]),_:3},8,["class","preload","images","curIndex","loop","onSwitch"])):r.createCommentVNode("",!0)],6)}const R=x(_e,[["render",xe],["__scopeId","data-v-5031655d"]]),vt="",Me={inject:["getMarkStyle"],props:{drawable:{type:Boolean,default:!1},drawMark:{type:Object,default:()=>({})}},computed:{drawStyle(){const{drawable:e,drawMark:t}=this;return!e||!t.active?{display:"none"}:this.getMarkStyle(t,"lightpink")}}};function ze(e,t,o,s,i,n){return r.openBlock(),r.createElementBlock("div",{class:"v3iv-draw-mark",style:r.normalizeStyle(n.drawStyle)},null,4)}const Se=x(Me,[["render",ze],["__scopeId","data-v-8723b5c7"]]),_={minSize:-1/0,maxSize:1/0,disabled:!1,enabled:!0},u=2;let N=[],W=!1,B=null;class Ee{constructor(){}init(t){if(!t.initialized)return this.addAnchors(t)}addAnchors(t){const s=Object.keys(X).map(i=>{const n=De(i);return n.key=i,n});for(const i of s)Ve(i),t.appendChild(i);return t.initialized=!0,s}}const Ce=new Ee;let z=null,I=null;const k={startX:0,startY:0,target:null,started:!1},T=5,E="DeepPink",Ie="icondrag1",L=10,V=T/2,X={lt:{dirX:-1,dirY:-1,fixed:1,style:{left:`-${u}px`,top:`-${u}px`,cursor:"se-resize",zIndex:50}},mt:{dirX:0,dirY:-1,fixed:1,style:{left:"50%",transform:`translateX(-${V}px)`,top:`-${u}px`,cursor:"s-resize",zIndex:50}},rt:{dirX:1,dirY:-1,fixed:1,style:{right:`-${u}px`,top:`-${u}px`,cursor:"sw-resize",zIndex:50}},lm:{dirX:-1,dirY:0,fixed:1,style:{left:`-${u}px`,top:"50%",transform:`translateY(-${V}px)`,cursor:"e-resize",zIndex:50}},rm:{dirX:1,dirY:0,fixed:1,style:{right:`-${u}px`,top:"50%",transform:`translateY(-${V}px)`,cursor:"w-resize",zIndex:50}},lb:{dirX:-1,dirY:1,fixed:1,style:{left:`-${u}px`,bottom:`-${u}px`,cursor:"ne-resize",zIndex:50}},mb:{dirX:0,dirY:1,fixed:1,style:{left:"50%",transform:`translateX(-${V}px)`,bottom:`-${u}px`,cursor:"n-resize",zIndex:50}},rb:{dirX:1,dirY:1,fixed:1,style:{right:`-${u}px`,bottom:`-${u}px`,cursor:"nw-resize",zIndex:50}},mm:{dirX:-1,dirY:-1,fixed:0,style:{left:"50%",top:"50%",transform:`translate(-${L/2}px,-${L/2}px)`,cursor:"move",zIndex:50,backgroundColor:E,borderRadius:"1px"}}},Be=[{height:"100%",width:`${u}px`,left:`-${u}px`,top:0,bottom:0},{height:"100%",width:`${u}px`,right:`-${u}px`,top:0,bottom:0},{width:"100%",height:`${u}px`,left:0,top:`-${u}px`,right:0},{width:"100%",height:`${u}px`,left:0,bottom:`-${u}px`,right:0}],H="gray";function Le(e){const t=e.querySelectorAll(".v3iv-drag-border");for(const s of t)e.initialized=!1,j(s),e.removeChild(s);const o=e.querySelectorAll(".v3iv-drag-anchor");for(const s of o)O(s),e.removeChild(s)}function Y(){if(D(),!!N.length){if(W){W=!1;return}N=N.filter(e=>{F(e);const t=e.querySelectorAll(".v3iv-drag-anchor");for(const s of t)O(s),e.removeChild(s);const o=e.querySelector(".v3iv-mark-delete");return o&&(o.style.display="block"),!1})}}function F(e){const t=[];for(const o of Be){const{width:s,height:i,left:n,right:a,top:l,bottom:c}=o,d=document.createElement("DIV");d.style.width=s,d.style.height=i,d.style.opacity=.5,d.style.position="absolute",d.style.cursor="move",d.style.userSelect="none",d.style.touchAction="none",d.style.pointerEvents="auto",d.classList.add("v3iv-drag-border"),n!==void 0&&(d.style.left=n),a!==void 0&&(d.style.right=a),l!==void 0&&(d.style.top=l),c!==void 0&&(d.style.bottom=c),t.push(d)}for(const o of t)He(o),e.appendChild(o)}function Re(){!z||(z.addEventListener("mousewheel",b),z.addEventListener("click",b),document.addEventListener("mousemove",K,{passive:!1}),document.addEventListener("mouseup",q))}function Ne(){!z||(z.removeEventListener("mousewheel",b),z.removeEventListener("click",b),document.removeEventListener("mousemove",K),document.removeEventListener("mouseup",q))}function Ve(e){e.addEventListener("mousewheel",b),e.addEventListener("mousedown",b),e.addEventListener("mousedown",Z)}function O(e){e.removeEventListener("mousewheel",b),e.removeEventListener("mousedown",b),e.removeEventListener("mousedown",Z)}function He(e){e.addEventListener("click",$),e.addEventListener("mousewheel",b),e.addEventListener("mousedown",b)}function j(e){e.removeEventListener("click",$),e.removeEventListener("mousewheel",b),e.removeEventListener("mousedown",b)}function $(e){e.stopPropagation(),e.preventDefault();const t=e.target.parentNode;Ce.init(t);const o=t.querySelectorAll(".v3iv-drag-border");for(const i of o)t.initialized=!1,j(i),t.removeChild(i);const s=t.querySelector(".v3iv-mark-delete");s&&(s.style.display="none"),N.push(t)}function b(e){e.stopPropagation(),e.preventDefault()}function Z(e){const{which:t}=e;if(t!=1)return;e.stopPropagation(),e.preventDefault();const o=e.target,s=o.parentNode,i=new CustomEvent("resize-start");s.dispatchEvent(i),z=s.parentNode,Re(),e.preventDefault(),e.stopPropagation(),I&&(I.style.zIndex=30),I=s,I.style.zIndex=40,k.started=!0,k.target=o,k.startX=e.pageX,k.startY=e.pageY}function K(e){B||(B=setTimeout(()=>{if(!k.started){D();return}e.preventDefault(),e.stopPropagation();const{key:t}=k.target,{dirX:o,dirY:s}=X[t],i=o*(e.pageX-k.startX),n=s*(e.pageY-k.startY),a=["lt","lm","lb"],l=["lt","mt","rt"],c=["rt","rm","rb"],d=["lb","mb","rb"];let m=0,f=0,h=0,p=0;a.includes(t)&&(m=-i),l.includes(t)&&(f=-n),c.includes(t)&&(h=i),d.includes(t)&&(p=n),t==="mm"&&(m=-i,h=-i,f=-n,p=-n);const w=new CustomEvent("resize-move",{detail:{left:m,top:f,right:h,bottom:p,key:t}});I.dispatchEvent(w),D()},20))}function D(){B&&(clearTimeout(B),B=null)}function q(e){if(e.preventDefault(),e.stopPropagation(),!k.started)return;D(),k.started=!1,k.target=null,W=!0;const t=new CustomEvent("resize-end");I.dispatchEvent(t),Ne(),z=null}function De(e){const{style:t,fixed:o}=X[e],s=document.createElement("DIV");s.style.height=`${T}px`,s.style.width=`${T}px`,s.style.backgroundColor=E,s.style.position="absolute",s.style.userSelect="none",s.style.touchAction="none",s.style.pointerEvents="auto",s.classList.add("v3iv-drag-anchor"),o||(s.classList.add("zlhiconfont",Ie),s.style.height=`${L}px`,s.style.width=`${L}px`,s.style.fontSize=`${L}px`,s.style.color=E,s.style.backgroundColor="transparent");for(const i of Object.keys(t)){const n=t[i];s.style[i]=n}return s}function U(e,t){t?(e.style.pointerEvents="none",e.style.backgroundColor=e.style.backgroundColor==E&&H,e.style.color=e.style.color==E&&H,e.style.display="none"):(e.style.pointerEvents="auto",e.style.backgroundColor=e.style.backgroundColor==H&&E,e.style.color=e.style.color==H&&E,e.style.display="block")}function G(e){const t=e.value||{},{maxSize:o=_.maxSize,minSize:s=_.minSize,disabled:i=_.disabled,enabled:n=_.enabled}=t;_.maxSize=o,_.minSize=s,_.disabled=i,_.enabled=n}const Pe={mounted(e,t){if(e){G(t);const{enabled:o}=_;if(!o)return;F(e),document.addEventListener("click",Y)}},unmounted(e,t){Y(),Le(e),document.removeEventListener("click",Y)},updated(e,t){G(t);const{disabled:o,enabled:s}=_;if(!s)return;const i=e.querySelectorAll(".v3iv-drag-anchor"),n=e.querySelectorAll(".v3iv-drag-border");for(const a of i)U(a,o);for(const a of n)U(a,o)}},yt="",We={inject:["getMarkStyle","getMarkLRTBWH"],emits:["resize","delete"],directives:{dragResize:Pe},props:{marks:{type:Array,default:()=>[]},drawing:{type:Boolean,default:!1},focus:{type:Boolean,default:!1},deleteable:{type:Boolean,default:!1},location:{type:Object,default:()=>({})},renderRecord:{type:Object,default:()=>({})}},data(){return{}},computed:{},watch:{},created(){},mounted(){},methods:{getMarkKey(e,t){return`${e.id}-${t}`},resizeStart(e){},resizeMove(e,t){let{left:o,top:s,right:i,bottom:n,key:a}=t.detail;const{curScale:l}=this.location,{scale:c}=this.renderRecord;o=o/l/c,s=s/l/c,i=i/l/c,n=n/l/c;const[d,m,f,h]=e.storage,{trueImgW:p,trueImgH:w}=this.renderRecord;let g=d+o,v=m+s,y=f+i,S=h+n;if(a==="mm"){const J=e.right-e.left,Q=e.bottom-e.top;g>0&&yp&&(e.left=p-J,e.right=p),v>0&&Sw&&(e.top=w-Q,e.bottom=w);return}g=Math.max(0,g),v=Math.max(0,v),y=Math.max(0,y),S=Math.max(0,S),g=Math.min(p,g),v=Math.min(w,v),y=Math.min(p,y),S=Math.min(w,S),e.left=g,e.top=v,e.right=y,e.bottom=S},resizeEnd(e){const t=this.getMarkLRTBWH(e),{left:o,top:s,right:i,bottom:n}=t,{target:a}=e;e.left=o,e.top=s,e.right=i,e.bottom=n,e.storage=[o,s,i,n],this.$emit("resize",{target:a,detail:t})},deleteMark(e){this.$emit("delete",e)}}},Te=e=>(r.pushScopeId("data-v-e199aa50"),e=e(),r.popScopeId(),e),Xe=["onResizeStart","onResizeMove","onResizeEnd"],Ye=["onClick"],Ae=[Te(()=>r.createElementVNode("svg",{t:"1655567649321",class:"icon",viewBox:"0 0 1024 1024",version:"1.1",xmlns:"http://www.w3.org/2000/svg","p-id":"17221",width:"16",height:"16"},[r.createElementVNode("path",{d:"M512 1255.489906","p-id":"17222",fill:"#ffffff"}),r.createElementVNode("path",{d:"M718.519288 688.227064 543.827304 513.637418l174.180292-174.180292c8.801119-8.801119 8.801119-23.128523 0-31.827304-8.801119-8.801119-23.128523-8.801119-31.827304 0L512 481.810114 337.819708 307.629822c-8.801119-8.801119-23.230861-8.596442-31.929642 0.102339l0.102339-0.102339c-8.801119 8.801119-8.698781 23.026184 0.102339 31.827304l174.180292 174.180292L305.58305 688.227064c-8.801119 8.801119-8.801119 23.128523 0 31.827304 8.801119 8.801119 23.128523 8.801119 31.827304 0L512 545.464721 686.691985 720.054367c8.801119 8.801119 22.923846 8.903458 31.724965 0.102339l0.102339-0.102339C727.218069 711.355587 727.218069 697.028183 718.519288 688.227064z","p-id":"17223",fill:"#ffffff"})],-1))];function Fe(e,t,o,s,i,n){const a=r.resolveDirective("drag-resize");return r.openBlock(!0),r.createElementBlock(r.Fragment,null,r.renderList(o.marks,(l,c)=>r.withDirectives((r.openBlock(),r.createElementBlock("div",{class:"v3iv-mark-item",key:n.getMarkKey(l,c),style:r.normalizeStyle(n.getMarkStyle(l)),onResizeStart:d=>n.resizeStart(l),onResizeMove:d=>{n.resizeMove(l,d)},onResizeEnd:d=>n.resizeEnd(l)},[o.deleteable&&!o.focus?(r.openBlock(),r.createElementBlock("div",{key:0,class:"v3iv-mark-delete",onMousewheel:t[0]||(t[0]=r.withModifiers(()=>{},["stop"])),onMousedown:t[1]||(t[1]=r.withModifiers(()=>{},["stop"])),onClick:d=>n.deleteMark(l)},Ae,40,Ye)):r.createCommentVNode("",!0)],44,Xe)),[[a,{disabled:o.drawing||o.focus}]])),128)}const Oe=x(We,[["render",Fe],["__scopeId","data-v-e199aa50"]]),bt="",je={components:{Image:R},props:{currentIndex:{type:Number,default:0},images:{type:Array,default:()=>[]},base:{type:String,default:""},token:{type:String,default:""}},data(){return{}},computed:{drawerStyle(){return{"margin-left":`-${this.currentIndex*30+15}px`}}},methods:{switchIndex(e){this.$emit("switch",e)},getKey(e,t){return`${e.thumbnail}-v3iv-thumbnail-${t}`}}},$e=e=>(r.pushScopeId("data-v-5a273606"),e=e(),r.popScopeId(),e),Ze={class:"v3iv-navigation-bar"},Ke=["onClick"],qe=$e(()=>r.createElementVNode("i",{class:"zlhiconfont icon-v3iv-error"},null,-1));function Ue(e,t,o,s,i,n){const a=r.resolveComponent("Image");return r.openBlock(),r.createElementBlock("div",Ze,[r.createElementVNode("div",{class:"v3iv-navigation-drawer",style:r.normalizeStyle(n.drawerStyle)},[(r.openBlock(!0),r.createElementBlock(r.Fragment,null,r.renderList(o.images,(l,c)=>(r.openBlock(),r.createElementBlock("div",{class:r.normalizeClass(["v3iv-navigation-item",{"v3iv-active":c==o.currentIndex}]),key:n.getKey(l,c),onClick:d=>n.switchIndex(c),onMousedown:t[0]||(t[0]=r.withModifiers(()=>{},["stop"])),onMousewheel:t[1]||(t[1]=r.withModifiers(()=>{},["stop"]))},[r.createVNode(a,{height:"100%",width:"100%",base:o.base,src:l.thumbnail,token:o.token,fit:"cover",lazy:""},{loading:r.withCtx(()=>[r.createTextVNode(" ... ")]),error:r.withCtx(()=>[qe]),_:2},1032,["base","src","token"])],42,Ke))),128))],4)])}const Ge=x(je,[["render",Ue],["__scopeId","data-v-5a273606"]]),kt="",Je={emits:["switchMode","prev","zoomOut","zoomIn","next","reset"],props:{fitMode:{type:Object,default:()=>({})},scaleFit:{type:Number,default:1},imgRecord:{type:Object,default:()=>({})}},methods:{containOrCover(){this.$emit("switchMode")},prev(){this.$emit("prev")},zoomOut(){this.$emit("zoomOut")},zoomIn(){this.$emit("zoomIn")},next(){this.$emit("next")},reset(){this.$emit("reset")},download(){const{trueSrc:e}=this.imgRecord,t=document.createElement("a");t.href=e,name||(name=e.split("/").pop()||"download"),t.setAttribute("target","_blank"),t.setAttribute("download",name),document.body.appendChild(t),t.click(),document.body.removeChild(t)}}},Qe={class:"v3iv-toolbar"},et={key:0,class:"icon-v3iv-quanping"},tt={key:1,class:"icon-v3iv-fullfill"};function ot(e,t,o,s,i,n){return r.openBlock(),r.createElementBlock("div",Qe,[r.renderSlot(e.$slots,"toolbar",{},()=>[r.createElementVNode("div",{onClick:t[0]||(t[0]=(...a)=>n.containOrCover&&n.containOrCover(...a)),class:"zlhiconfont"},[o.scaleFit==o.fitMode.contain?(r.openBlock(),r.createElementBlock("span",et)):(r.openBlock(),r.createElementBlock("span",tt))]),r.createElementVNode("div",{onClick:t[1]||(t[1]=(...a)=>n.prev&&n.prev(...a)),class:"zlhiconfont icon-v3iv-zhixiang-zuo"}),r.createElementVNode("div",{onClick:t[2]||(t[2]=(...a)=>n.zoomOut&&n.zoomOut(...a)),class:"zlhiconfont icon-v3iv-jian"}),r.createElementVNode("div",{onClick:t[3]||(t[3]=(...a)=>n.zoomIn&&n.zoomIn(...a)),class:"zlhiconfont icon-v3iv-jia"}),r.createElementVNode("div",{onClick:t[4]||(t[4]=(...a)=>n.next&&n.next(...a)),class:"zlhiconfont icon-v3iv-zhixiang-you"}),r.createElementVNode("div",{onClick:t[5]||(t[5]=(...a)=>n.reset&&n.reset(...a)),class:"zlhiconfont icon-v3iv-zhongzhi-circle"}),r.createElementVNode("div",{onClick:t[6]||(t[6]=a=>n.download()),class:"zlhiconfont icon-v3iv-xiazai"})],!0)])}const rt=x(Je,[["render",ot],["__scopeId","data-v-649125f0"]]),nt={components:{Image:R},props:{base:{type:String,default:""},token:{type:String,default:""},preload:{type:Array,default:()=>[0,2]},images:{type:Array,default:()=>[]},currentIndex:{type:Number,default:0}},computed:{preloadList(){const{preload:e,images:t,currentIndex:o}=this;if(!e)return[];const s=t.length,i=e[0],n=e[1],a=Math.max(o-i,0),l=Math.min(o+n,s-1);return t.slice(a,l+1).map(d=>d?d.url:"")}},methods:{getKey(e,t){return`${e}-v3iv-preload-${t}`}}};function it(e,t,o,s,i,n){const a=r.resolveComponent("Image");return r.openBlock(!0),r.createElementBlock(r.Fragment,null,r.renderList(n.preloadList,(l,c)=>r.withDirectives((r.openBlock(),r.createElementBlock("div",{key:n.getKey(l,c)},[r.createVNode(a,{base:o.base,src:l,token:o.token},null,8,["base","src","token"])])),[[r.vShow,!1]])),128)}const st=x(nt,[["render",it]]),_t="",C={contain:1,cover:2},at={emits:["resize","delete","load","drawEnd","zoom","error","switch"],provide(){return{getMarkStyle:this.getMarkStyle,getMarkLRTBWH:this.getMarkLRTBWH}},components:{Image:R,DrawRect:Se,ImgMarks:Oe,Navigation:Ge,ToolBar:rt,Preload:st},props:{base:{type:String,default:""},token:{type:String,default:""},fit:{type:String,default:"contain"},loop:{type:Boolean,default:!1},initialIndex:{type:Number,default:0},preload:{type:Array||Boolean,default:[0,2]},scaleMax:{type:Number,default:15},scaleMin:{type:Number,default:1},scaleStep:{type:Number,default:1.2},initialScale:{type:Number,default:1},imageList:{type:Array,default:null},markList:{type:Array,default:null},navigation:{type:Boolean,default:!1},toolbar:{type:Boolean,default:!1},keyboard:{type:Array,default:["A","D","Space","Esc"]},fixed:{type:Boolean,default:!1},focus:{type:Boolean,default:!1},drawable:{type:Boolean,default:!1},deleteable:{type:Boolean,default:!1},image:{type:Object,default:null},mark:{type:Object,default:null}},data(){return{fitMode:C,loadStatus:{loading:!1,failure:!1,success:!1},currentIndex:this.initialIndex,focusIndex:0,drawing:!1,drag:{dragPreX:0,dragPreY:0,active:!1},location:{translateX:0,translateY:0,curScale:this.initialScale},imgRecord:{wrapW:0,wrapH:0,imgSizeW:0,imgSizeH:0,trueSrc:""},drawMark:{left:0,right:0,top:0,bottom:0,active:!1},scaleFit:C.contain,resizeTimer:null,marksFormat:[]}},computed:{URL(){const{current:e}=this;return e.url},currentMarks(){const{current:e}=this;return e.marks||[]},images(){const{imageList:e,image:t}=this;return e||(t?[t]:[])},marks(){const{markList:e,mark:t,currentMarks:o}=this;return e||(t?[t]:o||[])},wrapStyle(){let{translateX:e,translateY:t,curScale:o}=this.location;return{transform:`translate(${e}px,${t}px) scale(${o})`}},mouseActive(){const{drawing:e}=this,{active:t}=this.drag;return e||t},current(){const{images:e,currentIndex:t}=this;return e[t]||{}},renderRecord(){const{imgSizeW:e,imgSizeH:t,wrapW:o,wrapH:s}=this.imgRecord;if(!e||!t||!o||!s)return null;const{imgW:i,imgH:n}=this.current,a=i||e,l=n||t,c={TDEdge:0,LREdge:0,imgW:0,imgH:0,scale:0,containScale:0,trueImgW:a,trueImgH:l},d=l/a,m=s/o;return d>m?(c.scale=this.toFixed(s/l,5),c.imgH=s,c.imgW=Math.round(c.imgH/d),c.LREdge=(o-c.imgW)/2,c.containScale=this.toFixed(o/(c.imgW-1),5)):(c.scale=this.toFixed(o/a,5),c.imgW=o,c.imgH=Math.round(c.imgW*d),c.TDEdge=(s-c.imgH)/2,c.containScale=this.toFixed(s/(c.imgH-1),5)),c}},watch:{marks:{handler(e){this.marksFormat=e.map(t=>{const{left:o,top:s,width:i,height:n,id:a}=t,l=o,c=s,d=o+i,m=s+n;return{id:a,storage:[l,c,d,m],left:l,top:c,right:d,bottom:m,target:t}})},immediate:!0,deep:!0},URL:{handler(){this.loadStatus={loading:!0,failure:!1,success:!1}},immediate:!0},drawable(){this.drawMark.active=!1,this.drawing=!1},"location.curScale"(e){e!==this.renderRecord.containScale&&(this.scaleFit=C.contain)},currentIndex(){this.onReset()}},mounted(){window.addEventListener("keyup",this.handleKeyboard),window.addEventListener("resize",this.handleResize)},beforeUnmount(){window.removeEventListener("keyup",this.handleKeyboard),window.removeEventListener("resize",this.handleResize)},methods:{zoomOut(){this.onZoomOut()},zoomIn(){this.onZoomIn()},onMarkDelete(e){this.$emit("delete",e)},onMarkResize(e){this.$emit("resize",e)},handleResize(){this.resizeTimer||(this.resizeTimer=setTimeout(()=>{this.freshWrapWH(),this.resizeTimer=null},100))},handleKeyboard(e){const{code:t}=e,{keyboard:o}=this;switch(o.includes("Space")&&t==="Space"&&e.preventDefault(),o.includes("Esc")&&t==="Escape"&&e.preventDefault(),t){case"Space":o.includes("Space")&&this.focusMark();break;case"Escape":o.includes("Esc")&&this.unFocusMark();break;case"KeyA":o.includes("A")&&this.onPrev();break;case"KeyD":o.includes("D")&&this.onNext();break}},getMarkStyle(e,t="lightblue"){this.focus&&this.focusMark();const{width:o,height:s,left:i,top:n}=this.getRenderMark(e);let{translateX:a,translateY:l,curScale:c}=this.location;const{wrapW:d,wrapH:m}=this.imgRecord,f=d/2,h=m/2,p=f-c*f+c*i,w=h-c*h+c*n;return{width:`${o*c}px`,height:`${s*c}px`,border:`2px solid ${t}`,left:`${p}px`,top:`${w}px`,transform:`translate(${a}px,${l}px)`}},getRenderMark(e){let{left:t,top:o,width:s,height:i}=this.getMarkLRTBWH(e);const{scale:n,TDEdge:a,LREdge:l}=this.renderRecord||{};return s=s*n,i=i*n,t=t*n+l,o=o*n+a,{left:t,top:o,width:s,height:i}},toFixed(e,t){const o=Math.pow(10,t);return Math.round(e*o)/o},limitBoundary(e,t){e=this.toFixed(e,2);const{wrapW:o,wrapH:s}=this.imgRecord,{curScale:i}=this.location;let n=0;return t==="horizontal"&&(n=o*(i-1)/2),t==="vertical"&&(n=s*(i-1)/2),n=Math.abs(n),e=Math.max(-n,e),e=Math.min(n,e),e},getMarkLRTBWH(e){const{left:t,right:o,top:s,bottom:i}=e,n=Math.floor(Math.min(t,o)),a=Math.floor(Math.min(s,i)),l=Math.floor(Math.max(t,o)),c=Math.floor(Math.max(s,i)),d=l-n,m=c-a;return{left:n,top:a,right:l,bottom:c,width:d,height:m}},unFocusMark(){this.onReset()},focusMark(e){if(!this.loadStatus.success)return;e!==void 0&&(this.focusIndex=e);const t=this.marksFormat[this.focusIndex]||null;if(!t||!this.renderRecord)return;this.focusIndex>=this.marksFormat.length-1?this.focusIndex=0:this.focusIndex++;const{width:o,height:s,left:i,top:n}=this.getRenderMark(t),{wrapW:a,wrapH:l}=this.imgRecord,{imgW:c,imgH:d,TDEdge:m,LREdge:f}=this.renderRecord,h=l/a;let p=i+o/2,w=n+s/2,g=0;if(s/oi||d<0||d>n||(this.drawMark={left:c,right:c,top:d,bottom:d,active:!0},this.drawing=!0)},onDrawMove(e){if(!this.drawing)return;const{trueImgW:t,trueImgH:o}=this.renderRecord,{layerX:s,layerY:i}=e,{x:n,y:a}=this.convertCoords(s,i);n<0||n>t||a<0||a>o||(this.drawMark.right=n,this.drawMark.bottom=a)},onDrawEnd(e){if(e.preventDefault(),!this.drawing)return;this.drawing=!1;const t=this.getMarkLRTBWH(this.drawMark);this.$emit("drawEnd",t),this.clearDraw()},clearDraw(){this.drawMark.active=!1,this.drawing=!1},convertCoords(e,t){const{wrapW:o,wrapH:s}=this.imgRecord,{scale:i,TDEdge:n,LREdge:a}=this.renderRecord,{translateX:l,translateY:c,curScale:d}=this.location,m=o*(d-1)/2-l+e-a*d,f=s*(d-1)/2-c+t-n*d,h=m/d/i,p=f/d/i;return{x:h,y:p}},onMousedown(e){if(e.preventDefault(),this.fixed||this.focus)return;const{which:t,layerX:o,layerY:s}=e;t==1&&(this.drag.dragPreX=o,this.drag.dragPreY=s,this.drag.active=!0)},onMousemove(e){const{active:t,dragPreX:o,dragPreY:s}=this.drag;if(!t)return;const{layerX:i,layerY:n}=e,{translateX:a,translateY:l}=this.location;let c=i-o,d=n-s;this.drag.dragPreX=i,this.drag.dragPreY=n,c=a+c,d=l+d,this.location.translateX=this.limitBoundary(c,"horizontal"),this.location.translateY=this.limitBoundary(d,"vertical")},onMouseup(e){this.drag.active=!1},onMouseleave(e){this.drag.active=!1},toggleFit(){this.onSwitchMode()},prev(){this.onPrev()},next(){this.onNext()},reset(){this.onReset()},download(){this.$refs.toolbar.download()},onSwitchMode(){this.location.translateX=0,this.location.translateY=0,this.scaleFit===C.contain?(this.scaleFit=C.cover,this.renderRecord&&(this.location.curScale=this.renderRecord.containScale)):(this.location.curScale=this.initialScale,this.scaleFit=C.contain)},onPrev(){this.switchIndex(this.currentIndex-1)},onNext(){this.switchIndex(this.currentIndex+1)},onZoomIn(){const e=this.handleZoom(1),{wrapW:t,wrapH:o}=this.imgRecord;this.flollowTheMouse(t/2,o/2,e)},onZoomOut(){const e=this.handleZoom(-1),{wrapW:t,wrapH:o}=this.imgRecord;this.flollowTheMouse(t/2,o/2,e)},onReset(){this.location.translateX=0,this.location.translateY=0,this.location.curScale=this.initialScale,this.scaleFit=C.contain,this.focusIndex=0,this.drawMark.active=!1},switchIndex(e){const{images:t}=this,o=t.length-1;this.loop?(e<0&&(e=o),e>o&&(e=0)):(e=Math.max(0,e),e=Math.min(o,e)),this.$emit("switch",e),this.currentIndex=e},flollowTheMouse(e,t,o){const{wrapW:s,wrapH:i}=this.imgRecord,{translateX:n,translateY:a,curScale:l}=this.location,c=s/2+n,d=i/2+a;let m=c-e,f=d-t;m=m/l,f=f/l,m=m*(o-l),f=f*(o-l),m=n+m,f=a+f,this.location.curScale=o,this.location.translateX=this.limitBoundary(m,"horizontal"),this.location.translateY=this.limitBoundary(f,"vertical")},handleZoom(e){const{scaleMax:t,scaleMin:o,scaleStep:s}=this;let i=this.location.curScale;return e>0?i=i*s:i=i/s,i=Math.min(i,t),i=Math.max(i,o),i=this.toFixed(i,3),this.$emit("zoom",i),Number(i)},onWheel(e){if(!this.loadStatus.success||this.fixed||this.focus)return;e.preventDefault(),e.stopPropagation();const{wheelDelta:t,layerX:o,layerY:s}=e;let i=this.location.curScale;t>0?i=this.handleZoom(1):i=this.handleZoom(-1),this.flollowTheMouse(o,s,i)},onLoad(e){const{naturalWidth:t,naturalHeight:o,src:s}=e.target;this.loadStatus={loading:!1,failure:!1,success:!0},this.imgRecord.imgSizeW=t,this.imgRecord.imgSizeH=o,this.imgRecord.trueSrc=s,this.$nextTick(()=>{this.freshWrapWH(),this.imageLoaded()}),this.$emit("load",e)},onError(e){this.loadStatus={loading:!1,failure:!0,success:!1},this.$emit("error",e)},freshWrapWH(){const e=this.$refs.clipper;if(e){const{clientWidth:t,clientHeight:o}=e;this.imgRecord.wrapW=t,this.imgRecord.wrapH=o}else console.error("DOM not found")},imageLoaded(){this.focus&&this.focusMark()}}},lt={class:"v3iv-viewer-clip",ref:"clipper"};function ct(e,t,o,s,i,n){const a=r.resolveComponent("Image"),l=r.resolveComponent("DrawRect"),c=r.resolveComponent("ImgMarks"),d=r.resolveComponent("Navigation"),m=r.resolveComponent("ToolBar"),f=r.resolveComponent("Preload");return r.openBlock(),r.createElementBlock("div",{class:r.normalizeClass(["v3iv-viewer",{"v3iv-has-toolbar":o.toolbar,"v3iv-mousedown":n.mouseActive}]),onMousewheel:t[1]||(t[1]=(...h)=>n.onWheel&&n.onWheel(...h)),onMousedown:t[2]||(t[2]=(...h)=>n.onMousedown&&n.onMousedown(...h)),onMouseup:t[3]||(t[3]=(...h)=>n.onMouseup&&n.onMouseup(...h)),onMousemove:t[4]||(t[4]=(...h)=>n.onMousemove&&n.onMousemove(...h)),onMouseleave:t[5]||(t[5]=(...h)=>n.onMouseleave&&n.onMouseleave(...h)),onContextmenu:t[6]||(t[6]=r.withModifiers(()=>{},["stop","prevent"]))},[r.createElementVNode("div",lt,[r.createElementVNode("div",{class:"v3iv-viewer-img-wrap",style:r.normalizeStyle(n.wrapStyle)},[r.createVNode(a,{height:"100%",width:"100%",base:o.base,src:n.URL,token:o.token,onMousedown:n.onDrawStart,onMouseup:n.onDrawEnd,onMousemove:n.onDrawMove,onMouseleave:n.onDrawEnd,onContextmenu:t[0]||(t[0]=r.withModifiers(()=>{},["stop","prevent"])),onLoad:n.onLoad,onError:n.onError,fit:o.fit},{loading:r.withCtx(()=>[r.renderSlot(e.$slots,"loading",{},void 0,!0)]),error:r.withCtx(()=>[r.renderSlot(e.$slots,"error",{},void 0,!0)]),_:3},8,["base","src","token","onMousedown","onMouseup","onMousemove","onMouseleave","onLoad","onError","fit"])],4),r.createVNode(l,{drawable:o.drawable,drawMark:i.drawMark},null,8,["drawable","drawMark"]),i.loadStatus.success?(r.openBlock(),r.createBlock(c,{key:0,marks:i.marksFormat,drawing:i.drawing,focus:o.focus,deleteable:o.deleteable,location:i.location,renderRecord:n.renderRecord,onResize:n.onMarkResize,onDelete:n.onMarkDelete},null,8,["marks","drawing","focus","deleteable","location","renderRecord","onResize","onDelete"])):r.createCommentVNode("",!0),o.navigation?(r.openBlock(),r.createBlock(d,{key:1,currentIndex:i.currentIndex,images:n.images,base:o.base,token:o.token,onSwitch:n.switchIndex},null,8,["currentIndex","images","base","token","onSwitch"])):r.createCommentVNode("",!0)],512),o.toolbar?(r.openBlock(),r.createBlock(m,{key:0,fitMode:i.fitMode,scaleFit:i.scaleFit,imgRecord:i.imgRecord,onSwitchMode:n.onSwitchMode,onPrev:n.onPrev,onNext:n.onNext,onZoomOut:n.onZoomOut,onZoomIn:n.onZoomIn,onReset:n.onReset,ref:"toolbar"},null,8,["fitMode","scaleFit","imgRecord","onSwitchMode","onPrev","onNext","onZoomOut","onZoomIn","onReset"])):r.createCommentVNode("",!0),r.createVNode(f,{base:o.base,token:o.token,preload:o.preload,images:n.images,currentIndex:i.currentIndex},null,8,["base","token","preload","images","currentIndex"])],34)}const dt=x(at,[["render",ct],["__scopeId","data-v-bcd88bb2"]]);window._iconfont_svg_string_3113478='',function(e){var o=(o=document.getElementsByTagName("script"))[o.length-1],t=o.getAttribute("data-injectcss"),o=o.getAttribute("data-disable-injectsvg");if(!o){var s,i,n,a,l,c=function(f,h){h.parentNode.insertBefore(f,h)};if(t&&!e.__iconfont__svg__cssinject__){e.__iconfont__svg__cssinject__=!0;try{document.write("")}catch(f){console&&console.log(f)}}s=function(){var f,h=document.createElement("div");h.innerHTML=e._iconfont_svg_string_3113478,(h=h.getElementsByTagName("svg")[0])&&(h.setAttribute("aria-hidden","true"),h.style.position="absolute",h.style.width=0,h.style.height=0,h.style.overflow="hidden",h=h,(f=document.body).firstChild?c(h,f.firstChild):f.appendChild(h))},document.addEventListener?~["complete","loaded","interactive"].indexOf(document.readyState)?setTimeout(s,0):(i=function(){document.removeEventListener("DOMContentLoaded",i,!1),s()},document.addEventListener("DOMContentLoaded",i,!1)):document.attachEvent&&(n=s,a=e.document,l=!1,m(),a.onreadystatechange=function(){a.readyState=="complete"&&(a.onreadystatechange=null,d())})}function d(){l||(l=!0,n())}function m(){try{a.documentElement.doScroll("left")}catch{return void setTimeout(m,50)}d()}}(window);const xt="";M.Image=R,M.Viewer=dt,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})});