@gx-design-vue/image 0.0.9 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/image.umd.js CHANGED
@@ -1 +1 @@
1
- (function(v,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@ant-design/icons-vue"),require("@gx-design-vue/pro-utils"),require("@gx-design-vue/pro-hooks"),require("vue-types"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","@ant-design/icons-vue","@gx-design-vue/pro-utils","@gx-design-vue/pro-hooks","vue-types","@vueuse/core"],e):(v=typeof globalThis<"u"?globalThis:v||self,e(v.GImage={},v.vue,v.iconsVue,v.proUtils,v.proHooks,v.vueTypes,v.core))})(this,function(v,e,O,w,J,oe,W){"use strict";const de="",ue="";var Q=oe.createTypes({func:void 0,bool:void 0,string:void 0,number:void 0,array:void 0,object:void 0,integer:void 0});Q.extend([{name:"looseBool",getter:!0,type:Boolean,default:void 0},{name:"style",getter:!0,type:[String,Object],default:void 0},{name:"VueNode",getter:!0,type:null}]);const H=Q,j={appendToBody:{type:Boolean,default:!1},hideOnClickModal:{type:Boolean,default:!0},src:{type:String,default:""},fit:{type:String,default:""},lazy:H.bool,scrollContainer:{type:[String,Object]},placeholder:{type:[Function,Object],default:()=>{}},fallback:{type:[Function,Object],default:()=>{}},onError:{type:Function},onClick:{type:Function},disablePreview:H.bool,previewSrcList:{type:Array,default:()=>[]},width:H.number,height:H.number,zIndex:{type:Number,default:2e3}},re={urlList:{type:Array,default:()=>[]},zIndex:j.zIndex,initialIndex:{type:Number,default:0},infinite:{type:Boolean,default:!0},onHideOnClickModal:j.hideOnClickModal},T={tab:"Tab",enter:"Enter",space:"Space",left:"ArrowLeft",up:"ArrowUp",right:"ArrowRight",down:"ArrowDown",esc:"Escape",delete:"Delete",backspace:"Backspace"},R=function(t,l,u,N=!1){t&&l&&u&&t.addEventListener(l,u,N)},q=function(t,l,u,N=!1){t&&l&&u&&t.removeEventListener(l,u,N)},A={CONTAIN:{name:"contain",icon:e.createVNode(O.ExpandOutlined,null,null)},ORIGINAL:{name:"original",icon:e.createVNode(O.OneToOneOutlined,null,null)}},U=function(){return!w.isServer&&!!window.navigator.userAgent.match(/firefox/i)}()?"DOMMouseScroll":"mousewheel";function B(t){let l=!1;return function(...u){l||(l=!0,window.requestAnimationFrame(()=>{t.apply(this,u),l=!1}))}}const X=e.defineComponent({props:re,emits:["close","switch"],setup:function(t,{emit:l}){let u=null,N=null,b=null;const r=w.getPrefixCls({suffixCls:"image-viewer"}),f=e.ref(!0),h=e.ref(t.initialIndex),I=e.ref(null),x=e.ref(null),p=e.ref(A.CONTAIN),i=e.ref({scale:1,deg:0,offsetX:0,offsetY:0,enableTransition:!1}),c=e.computed(()=>{const{urlList:a}=t;return a.length<=1}),d=e.computed(()=>h.value===0),m=e.computed(()=>h.value===t.urlList.length-1),k=e.computed(()=>t.urlList[h.value]),S=e.ref("viewer-fade-enter-active"),E=e.computed(()=>{const{scale:a,deg:y,offsetX:n,offsetY:o,enableTransition:s}=i.value,g={transform:`scale(${a}) rotate(${y}deg)`,transition:s?"transform .3s":"",marginLeft:`${n}px`,marginTop:`${o}px`};return p.value.name===A.CONTAIN.name&&(g.maxWidth=g.maxHeight="100%"),g}),z=()=>{Z(),setTimeout(()=>{l("close")},200)},L=()=>{S.value="viewer-fade-enter-active",u=B(a=>{switch(a.code){case T.esc:z();break;case T.space:D();break;case T.left:G();break;case T.up:C("zoomIn");break;case T.right:Y();break;case T.down:C("zoomOut");break}}),N=B(a=>{(a.wheelDelta?a.wheelDelta:-a.detail)>0?C("zoomIn",{zoomRate:.015,enableTransition:!1}):C("zoomOut",{zoomRate:.015,enableTransition:!1})}),R(document,"keydown",u),R(document,U,N)},Z=()=>{S.value="viewer-fade-leave-active",q(document,"keydown",u),q(document,U,N),u=null,N=null},F=()=>{f.value=!1},_=a=>{f.value=!1,a.target.alt="\u52A0\u8F7D\u5931\u8D25"},P=a=>{if(f.value||a.button!==0)return;const{offsetX:y,offsetY:n}=i.value,o=a.pageX,s=a.pageY;b=B(g=>{i.value={...i.value,offsetX:y+g.pageX-o,offsetY:n+g.pageY-s}}),R(document,"mousemove",b),R(document,"mouseup",()=>{q(document,"mousemove",b)}),a.preventDefault()},M=()=>{i.value={scale:1,deg:0,offsetX:0,offsetY:0,enableTransition:!1}},D=()=>{if(f.value)return;const a=Object.keys(A),y=Object.values(A),n=p.value.name,s=(y.findIndex(g=>g.name===n)+1)%a.length;p.value=A[a[s]],M()},G=()=>{if(d.value&&!t.infinite)return;const a=t.urlList.length;h.value=(h.value-1+a)%a},Y=()=>{if(m.value&&!t.infinite)return;const a=t.urlList.length;h.value=(h.value+1)%a},C=(a,y={})=>{if(f.value)return;const{zoomRate:n,rotateDeg:o,enableTransition:s}={zoomRate:.2,rotateDeg:90,enableTransition:!0,...y};switch(a){case"zoomOut":i.value.scale>.2&&(i.value.scale=parseFloat((i.value.scale-n).toFixed(3)));break;case"zoomIn":i.value.scale=parseFloat((i.value.scale+n).toFixed(3));break;case"clocelise":i.value.deg+=o;break;case"anticlocelise":i.value.deg-=o;break}i.value.enableTransition=s};return e.watch(k,()=>{e.nextTick(()=>{x.value.complete||(f.value=!0)})}),e.watch(h,a=>{M(),l("switch",a)}),J.onMountedOrActivated(()=>{var a,y;L(),(y=(a=I.value)==null?void 0:a.focus)==null||y.call(a)}),()=>e.createVNode("div",{ref:a=>I.value=a,tabindex:1,class:[`${r}-wrapper`,`${S.value}`],style:{zIndex:t.zIndex}},[e.createVNode("div",{class:`${r}-mask`,onClick:()=>t.onHideOnClickModal&&z()},null),e.createVNode("span",{class:[`${r}-btn`,`${r}-close`],onClick:()=>z()},[e.createVNode(O.CloseOutlined,null,null)]),!c.value&&e.createVNode(e.Fragment,null,[e.createVNode("span",{class:{[`${r}-btn`]:!0,[`${r}-prev`]:!0,["is-disabled"]:!t.infinite&&d.value},onClick:()=>G()},[e.createVNode(O.LeftOutlined,null,null)]),e.createVNode("span",{class:{[`${r}-btn`]:!0,[`${r}-next`]:!0,["is-disabled"]:!t.infinite&&d.value},onClick:()=>Y()},[e.createVNode(O.RightOutlined,null,null)])]),e.createVNode("div",{class:[`${r}-btn`,`${r}-actions`]},[e.createVNode("div",{class:`${r}-actions-inner`},[e.createVNode(O.ZoomOutOutlined,{onClick:()=>C("zoomOut")},null),e.createVNode(O.ZoomInOutlined,{onClick:()=>C("zoomIn")},null),e.createVNode("i",{class:`${r}-actions-divider`},null),e.createVNode("i",{onClick:()=>D()},[p.value.icon]),e.createVNode("i",{class:`${r}-actions-divider`},null),e.createVNode(O.RotateLeftOutlined,{onClick:()=>C("anticlocelise")},null),e.createVNode(O.RotateRightOutlined,{onClick:()=>C("clocelise")},null)])]),f.value&&e.createVNode("div",{class:`${r}-canvas`},[e.createVNode(e.resolveComponent("a-spin"),{indicator:e.createVNode(O.LoadingOutlined,{style:{color:"#fff",fontSize:"40px"}},null)},null)]),e.createVNode("div",{class:`${r}-canvas`},[t.urlList.map((a,y)=>e.createVNode("img",{ref:n=>x.value=n,class:`${r}-img`,key:a,style:{...E.value,display:y===h.value?"block":"none"},src:a,onLoad:()=>F(),onError:n=>_(n),onMousedown:n=>P(n)},null))])])}});function ie(t){return typeof t=="function"||Object.prototype.toString.call(t)==="[object Object]"&&!e.isVNode(t)}let ee="";const ce=e.defineComponent({props:{hideOnClickModal:j.hideOnClickModal},setup(t,{slots:l}){const u=w.getPrefixCls({suffixCls:"image-viewer-group"}),N=e.ref(!1),b=e.ref(""),r=e.computed(()=>{var c,d,m,k,S;return((c=l.default)==null?void 0:c.call(l).length)===1&&(String((d=l.default)==null?void 0:d.call(l)[0].type)===String(Symbol("Fragment"))||String((m=l.default)==null?void 0:m.call(l)[0].type)===String(Symbol()))?((k=l.default)==null?void 0:k.call(l)[0].children)||[]:((S=l.default)==null?void 0:S.call(l))||[]}),f=e.computed(()=>r.value.filter(m=>I(m)).map(m=>m.props.src).filter(m=>m)||[]),h=e.computed(()=>Array.isArray(f.value)&&f.value.length>0),I=c=>c&&c.type&&(c.type.isGImage||c.type.name==="GImage"),x=()=>{let c=0;const d=f.value.findIndex(m=>m===b.value);return d>=0&&(c=d),c},p=c=>{!h.value||!c||(b.value=c,ee=document.body.style.overflow,document.body.style.overflow="hidden",N.value=!0)},i=()=>{document.body.style.overflow=ee,N.value=!1};return()=>{let c;return e.createVNode("div",{class:`${u}`},[e.createVNode(e.resolveComponent("a-space"),{size:15},ie(c=r.value.map((d,m)=>I(d)?e.createVNode("div",{key:m,class:`${u}-item`,onClick:()=>{var k;return p(((k=d.props)==null?void 0:k.src)||"")}},[e.cloneVNode(d,{disablePreview:!0})]):null))?c:{default:()=>[c]}),e.createVNode(e.Teleport,{to:"body"},{default:()=>[h.value&&N.value&&e.createVNode(X,{initialIndex:x(),urlList:f.value,onHideOnClickModal:t.hideOnClickModal,onClose:()=>i()},null)]})])}}}),se=t=>t&&t.nodeType===Node.ELEMENT_NODE,te=()=>document.documentElement.style.objectFit!==void 0;let ne="";const V={NONE:"none",CONTAIN:"contain",COVER:"cover",FILL:"fill",SCALE_DOWN:"scale-down"},$=e.defineComponent({props:j,name:"GImage",inheritAttrs:!1,emits:["error","click"],setup(t,{slots:l,emit:u,attrs:N}){const b=w.getPrefixCls({suffixCls:"image"}),r=e.ref(!1),f=e.ref(!0),h=e.ref(0),I=e.ref(0),x=e.ref(!1),p=e.ref(null),i=e.ref();let c,d;const m=e.computed(()=>({width:t.width?`${t.width}px`:void 0,height:t.height?`${t.height}px`:void 0})),k=e.computed(()=>{const{fit:n}=t;return!w.isServer&&n?te()?{"object-fit":n,...m.value}:{...Z(n),...m.value}:m.value}),S=e.computed(()=>{const{fit:n}=t;return!w.isServer&&!te()&&n!==V.FILL}),E=e.computed(()=>{const{previewSrcList:n}=t;return Array.isArray(n)&&n.length>0}),z=e.computed(()=>{const{src:n,previewSrcList:o}=t;let s=0;const g=o.indexOf(n);return g>=0&&(s=g),s}),L=e.computed(()=>N),Z=n=>{const o=t.width||h.value,s=t.height||I.value;if(!p.value)return{};const{clientWidth:g,clientHeight:K}=p.value;if(!o||!s||!g||!K)return{};const ae=o/s,le=g/K;switch(n===V.SCALE_DOWN&&(n=o<g&&s<K?V.NONE:V.CONTAIN),n){case V.NONE:return{width:"auto",height:"auto"};case V.CONTAIN:return ae<le?{width:"auto"}:{height:"auto"};case V.COVER:return ae<le?{height:"auto"}:{width:"auto"};default:return{}}},F=()=>{if(w.isServer)return;const n=L.value;f.value=!0,r.value=!1;const o=new Image;o.onload=s=>G(s,o),o.onerror=Y,Object.keys(n).forEach(s=>{if(s.toLowerCase()==="onload")return;const g=n[s];o.setAttribute(s,g)}),o.src=t.src};function _(){w.isInContainer(p.value,i.value)&&(F(),D())}const P=W.useThrottleFn(_,200),M=async()=>{var o;if(w.isServer)return;await e.nextTick();const{scrollContainer:n}=t;se(n)?i.value=n:w.isString(n)&&n!==""?i.value=(o=document.querySelector(n))!=null?o:void 0:p.value&&(i.value=w.getScrollContainer(p.value)),i.value&&(c=W.useEventListener(i,"scroll",P),setTimeout(()=>_(),200))},D=()=>{w.isServer||!i.value||!P||(c(),i.value=void 0)},G=(n,o)=>{h.value=o.width,I.value=o.height,f.value=!1,r.value=!1},Y=n=>{f.value=!1,r.value=!0,u("error",n)},C=n=>{if(!!n.ctrlKey){if(n.deltaY<0)return n.preventDefault(),!1;if(n.deltaY>0)return n.preventDefault(),!1}},a=()=>{!E.value||t.disablePreview||(d=W.useEventListener("wheel",C,{passive:!1}),ne=document.body.style.overflow,document.body.style.overflow="hidden",x.value=!0)},y=()=>{d==null||d(),document.body.style.overflow=ne,x.value=!1};return e.watch(()=>t.src,()=>{t.lazy?(f.value=!0,r.value=!1,D(),M()):F()}),J.onMountedOrActivated(()=>{t.lazy?M():F()}),()=>{const n=w.getSlotVNode(l,t,"fallback"),o=w.getSlotVNode(l,t,"placeholder");return e.createVNode(e.Fragment,null,[e.createVNode("div",{class:{[`${b}`]:!0,[`${L.value.class}`]:L.value.class},ref:s=>p.value=s,style:{...L.value.style||{},display:t.lazy?"block":void 0},onClick:()=>{u("click")}},[f.value?o||e.createVNode("div",{class:`${b}-placeholder`},null):r.value?n||e.createVNode("div",{class:`${b}-error`},[e.createTextVNode("\u52A0\u8F7D\u5931\u8D25")]):e.createVNode("img",e.mergeProps({class:{[`${b}-inner`]:!0,[`${b}-inner-center`]:S.value,[`${b}-preview`]:E.value}},L.value,{src:t.src,style:k.value,onClick:()=>a()}),null),e.createVNode(e.Teleport,{to:"body",disabled:!t.appendToBody},{default:()=>[E.value&&x.value&&e.createVNode(X,{zIndex:t.zIndex,initialIndex:z.value,urlList:t.previewSrcList,onHideOnClickModal:t.hideOnClickModal,onClose:()=>y()},null)]})])])}}});$.isWImage=!0,$.install=t=>(t.component($.name,$),t),v.GImage=$,v.ImageViewer=X,v.ImageViewerGroup=ce,v.default=$,Object.defineProperties(v,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(v,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("vue"),require("@ant-design/icons-vue"),require("@gx-design-vue/pro-utils"),require("@gx-design-vue/pro-hooks"),require("vue-types"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","@ant-design/icons-vue","@gx-design-vue/pro-utils","@gx-design-vue/pro-hooks","vue-types","@vueuse/core"],e):(v=typeof globalThis!="undefined"?globalThis:v||self,e(v.GImage={},v.vue,v.iconsVue,v.proUtils,v.proHooks,v.vueTypes,v.core))})(this,function(v,e,O,w,J,oe,W){"use strict";var de="",ue="",Q=oe.createTypes({func:void 0,bool:void 0,string:void 0,number:void 0,array:void 0,object:void 0,integer:void 0});Q.extend([{name:"looseBool",getter:!0,type:Boolean,default:void 0},{name:"style",getter:!0,type:[String,Object],default:void 0},{name:"VueNode",getter:!0,type:null}]);var H=Q;const j={appendToBody:{type:Boolean,default:!1},hideOnClickModal:{type:Boolean,default:!0},src:{type:String,default:""},fit:{type:String,default:""},lazy:H.bool,scrollContainer:{type:[String,Object]},placeholder:{type:[Function,Object],default:()=>{}},fallback:{type:[Function,Object],default:()=>{}},onError:{type:Function},onClick:{type:Function},disablePreview:H.bool,previewSrcList:{type:Array,default:()=>[]},width:H.number,height:H.number,zIndex:{type:Number,default:2e3}},re={urlList:{type:Array,default:()=>[]},zIndex:j.zIndex,initialIndex:{type:Number,default:0},infinite:{type:Boolean,default:!0},onHideOnClickModal:j.hideOnClickModal},T={tab:"Tab",enter:"Enter",space:"Space",left:"ArrowLeft",up:"ArrowUp",right:"ArrowRight",down:"ArrowDown",esc:"Escape",delete:"Delete",backspace:"Backspace"},R=function(t,l,u,N=!1){t&&l&&u&&t.addEventListener(l,u,N)},q=function(t,l,u,N=!1){t&&l&&u&&t.removeEventListener(l,u,N)},A={CONTAIN:{name:"contain",icon:e.createVNode(O.ExpandOutlined,null,null)},ORIGINAL:{name:"original",icon:e.createVNode(O.OneToOneOutlined,null,null)}},U=function(){return!w.isServer&&!!window.navigator.userAgent.match(/firefox/i)}()?"DOMMouseScroll":"mousewheel";function B(t){let l=!1;return function(...u){l||(l=!0,window.requestAnimationFrame(()=>{t.apply(this,u),l=!1}))}}const X=e.defineComponent({props:re,emits:["close","switch"],setup:function(t,{emit:l}){let u=null,N=null,b=null;const r=w.getPrefixCls({suffixCls:"image-viewer"}),f=e.ref(!0),h=e.ref(t.initialIndex),I=e.ref(null),x=e.ref(null),p=e.ref(A.CONTAIN),i=e.ref({scale:1,deg:0,offsetX:0,offsetY:0,enableTransition:!1}),c=e.computed(()=>{const{urlList:a}=t;return a.length<=1}),d=e.computed(()=>h.value===0),m=e.computed(()=>h.value===t.urlList.length-1),k=e.computed(()=>t.urlList[h.value]),S=e.ref("viewer-fade-enter-active"),E=e.computed(()=>{const{scale:a,deg:y,offsetX:n,offsetY:o,enableTransition:s}=i.value,g={transform:`scale(${a}) rotate(${y}deg)`,transition:s?"transform .3s":"",marginLeft:`${n}px`,marginTop:`${o}px`};return p.value.name===A.CONTAIN.name&&(g.maxWidth=g.maxHeight="100%"),g}),z=()=>{Z(),setTimeout(()=>{l("close")},200)},L=()=>{S.value="viewer-fade-enter-active",u=B(a=>{switch(a.code){case T.esc:z();break;case T.space:D();break;case T.left:G();break;case T.up:C("zoomIn");break;case T.right:Y();break;case T.down:C("zoomOut");break}}),N=B(a=>{(a.wheelDelta?a.wheelDelta:-a.detail)>0?C("zoomIn",{zoomRate:.015,enableTransition:!1}):C("zoomOut",{zoomRate:.015,enableTransition:!1})}),R(document,"keydown",u),R(document,U,N)},Z=()=>{S.value="viewer-fade-leave-active",q(document,"keydown",u),q(document,U,N),u=null,N=null},F=()=>{f.value=!1},_=a=>{f.value=!1,a.target.alt="\u52A0\u8F7D\u5931\u8D25"},P=a=>{if(f.value||a.button!==0)return;const{offsetX:y,offsetY:n}=i.value,o=a.pageX,s=a.pageY;b=B(g=>{i.value={...i.value,offsetX:y+g.pageX-o,offsetY:n+g.pageY-s}}),R(document,"mousemove",b),R(document,"mouseup",()=>{q(document,"mousemove",b)}),a.preventDefault()},M=()=>{i.value={scale:1,deg:0,offsetX:0,offsetY:0,enableTransition:!1}},D=()=>{if(f.value)return;const a=Object.keys(A),y=Object.values(A),n=p.value.name,s=(y.findIndex(g=>g.name===n)+1)%a.length;p.value=A[a[s]],M()},G=()=>{if(d.value&&!t.infinite)return;const a=t.urlList.length;h.value=(h.value-1+a)%a},Y=()=>{if(m.value&&!t.infinite)return;const a=t.urlList.length;h.value=(h.value+1)%a},C=(a,y={})=>{if(f.value)return;const{zoomRate:n,rotateDeg:o,enableTransition:s}={zoomRate:.2,rotateDeg:90,enableTransition:!0,...y};switch(a){case"zoomOut":i.value.scale>.2&&(i.value.scale=parseFloat((i.value.scale-n).toFixed(3)));break;case"zoomIn":i.value.scale=parseFloat((i.value.scale+n).toFixed(3));break;case"clocelise":i.value.deg+=o;break;case"anticlocelise":i.value.deg-=o;break}i.value.enableTransition=s};return e.watch(k,()=>{e.nextTick(()=>{x.value.complete||(f.value=!0)})}),e.watch(h,a=>{M(),l("switch",a)}),J.onMountedOrActivated(()=>{var a,y;L(),(y=(a=I.value)==null?void 0:a.focus)==null||y.call(a)}),()=>e.createVNode("div",{ref:a=>I.value=a,tabindex:1,class:[`${r}-wrapper`,`${S.value}`],style:{zIndex:t.zIndex}},[e.createVNode("div",{class:`${r}-mask`,onClick:()=>t.onHideOnClickModal&&z()},null),e.createVNode("span",{class:[`${r}-btn`,`${r}-close`],onClick:()=>z()},[e.createVNode(O.CloseOutlined,null,null)]),!c.value&&e.createVNode(e.Fragment,null,[e.createVNode("span",{class:{[`${r}-btn`]:!0,[`${r}-prev`]:!0,["is-disabled"]:!t.infinite&&d.value},onClick:()=>G()},[e.createVNode(O.LeftOutlined,null,null)]),e.createVNode("span",{class:{[`${r}-btn`]:!0,[`${r}-next`]:!0,["is-disabled"]:!t.infinite&&d.value},onClick:()=>Y()},[e.createVNode(O.RightOutlined,null,null)])]),e.createVNode("div",{class:[`${r}-btn`,`${r}-actions`]},[e.createVNode("div",{class:`${r}-actions-inner`},[e.createVNode(O.ZoomOutOutlined,{onClick:()=>C("zoomOut")},null),e.createVNode(O.ZoomInOutlined,{onClick:()=>C("zoomIn")},null),e.createVNode("i",{class:`${r}-actions-divider`},null),e.createVNode("i",{onClick:()=>D()},[p.value.icon]),e.createVNode("i",{class:`${r}-actions-divider`},null),e.createVNode(O.RotateLeftOutlined,{onClick:()=>C("anticlocelise")},null),e.createVNode(O.RotateRightOutlined,{onClick:()=>C("clocelise")},null)])]),f.value&&e.createVNode("div",{class:`${r}-canvas`},[e.createVNode(e.resolveComponent("a-spin"),{indicator:e.createVNode(O.LoadingOutlined,{style:{color:"#fff",fontSize:"40px"}},null)},null)]),e.createVNode("div",{class:`${r}-canvas`},[t.urlList.map((a,y)=>e.createVNode("img",{ref:n=>x.value=n,class:`${r}-img`,key:a,style:{...E.value,display:y===h.value?"block":"none"},src:a,onLoad:()=>F(),onError:n=>_(n),onMousedown:n=>P(n)},null))])])}});function ie(t){return typeof t=="function"||Object.prototype.toString.call(t)==="[object Object]"&&!e.isVNode(t)}let ee="";const ce=e.defineComponent({props:{hideOnClickModal:j.hideOnClickModal},setup(t,{slots:l}){const u=w.getPrefixCls({suffixCls:"image-viewer-group"}),N=e.ref(!1),b=e.ref(""),r=e.computed(()=>{var c,d,m,k,S;return((c=l.default)==null?void 0:c.call(l).length)===1&&(String((d=l.default)==null?void 0:d.call(l)[0].type)===String(Symbol("Fragment"))||String((m=l.default)==null?void 0:m.call(l)[0].type)===String(Symbol()))?((k=l.default)==null?void 0:k.call(l)[0].children)||[]:((S=l.default)==null?void 0:S.call(l))||[]}),f=e.computed(()=>r.value.filter(m=>I(m)).map(m=>m.props.src).filter(m=>m)||[]),h=e.computed(()=>Array.isArray(f.value)&&f.value.length>0),I=c=>c&&c.type&&(c.type.isGImage||c.type.name==="GImage"),x=()=>{let c=0;const d=f.value.findIndex(m=>m===b.value);return d>=0&&(c=d),c},p=c=>{!h.value||!c||(b.value=c,ee=document.body.style.overflow,document.body.style.overflow="hidden",N.value=!0)},i=()=>{document.body.style.overflow=ee,N.value=!1};return()=>{let c;return e.createVNode("div",{class:`${u}`},[e.createVNode(e.resolveComponent("a-space"),{size:15},ie(c=r.value.map((d,m)=>I(d)?e.createVNode("div",{key:m,class:`${u}-item`,onClick:()=>{var k;return p(((k=d.props)==null?void 0:k.src)||"")}},[e.cloneVNode(d,{disablePreview:!0})]):null))?c:{default:()=>[c]}),e.createVNode(e.Teleport,{to:"body"},{default:()=>[h.value&&N.value&&e.createVNode(X,{initialIndex:x(),urlList:f.value,onHideOnClickModal:t.hideOnClickModal,onClose:()=>i()},null)]})])}}}),se=t=>t&&t.nodeType===Node.ELEMENT_NODE,te=()=>document.documentElement.style.objectFit!==void 0;let ne="";const V={NONE:"none",CONTAIN:"contain",COVER:"cover",FILL:"fill",SCALE_DOWN:"scale-down"},$=e.defineComponent({props:j,name:"GImage",inheritAttrs:!1,emits:["error","click"],setup(t,{slots:l,emit:u,attrs:N}){const b=w.getPrefixCls({suffixCls:"image"}),r=e.ref(!1),f=e.ref(!0),h=e.ref(0),I=e.ref(0),x=e.ref(!1),p=e.ref(null),i=e.ref();let c,d;const m=e.computed(()=>({width:t.width?`${t.width}px`:void 0,height:t.height?`${t.height}px`:void 0})),k=e.computed(()=>{const{fit:n}=t;return!w.isServer&&n?te()?{"object-fit":n,...m.value}:{...Z(n),...m.value}:m.value}),S=e.computed(()=>{const{fit:n}=t;return!w.isServer&&!te()&&n!==V.FILL}),E=e.computed(()=>{const{previewSrcList:n}=t;return Array.isArray(n)&&n.length>0}),z=e.computed(()=>{const{src:n,previewSrcList:o}=t;let s=0;const g=o.indexOf(n);return g>=0&&(s=g),s}),L=e.computed(()=>N),Z=n=>{const o=t.width||h.value,s=t.height||I.value;if(!p.value)return{};const{clientWidth:g,clientHeight:K}=p.value;if(!o||!s||!g||!K)return{};const ae=o/s,le=g/K;switch(n===V.SCALE_DOWN&&(n=o<g&&s<K?V.NONE:V.CONTAIN),n){case V.NONE:return{width:"auto",height:"auto"};case V.CONTAIN:return ae<le?{width:"auto"}:{height:"auto"};case V.COVER:return ae<le?{height:"auto"}:{width:"auto"};default:return{}}},F=()=>{if(w.isServer)return;const n=L.value;f.value=!0,r.value=!1;const o=new Image;o.onload=s=>G(s,o),o.onerror=Y,Object.keys(n).forEach(s=>{if(s.toLowerCase()==="onload")return;const g=n[s];o.setAttribute(s,g)}),o.src=t.src};function _(){w.isInContainer(p.value,i.value)&&(F(),D())}const P=W.useThrottleFn(_,200),M=async()=>{var o;if(w.isServer)return;await e.nextTick();const{scrollContainer:n}=t;se(n)?i.value=n:w.isString(n)&&n!==""?i.value=(o=document.querySelector(n))!=null?o:void 0:p.value&&(i.value=w.getScrollContainer(p.value)),i.value&&(c=W.useEventListener(i,"scroll",P),setTimeout(()=>_(),200))},D=()=>{w.isServer||!i.value||!P||(c(),i.value=void 0)},G=(n,o)=>{h.value=o.width,I.value=o.height,f.value=!1,r.value=!1},Y=n=>{f.value=!1,r.value=!0,u("error",n)},C=n=>{if(!!n.ctrlKey){if(n.deltaY<0)return n.preventDefault(),!1;if(n.deltaY>0)return n.preventDefault(),!1}},a=()=>{!E.value||t.disablePreview||(d=W.useEventListener("wheel",C,{passive:!1}),ne=document.body.style.overflow,document.body.style.overflow="hidden",x.value=!0)},y=()=>{d==null||d(),document.body.style.overflow=ne,x.value=!1};return e.watch(()=>t.src,()=>{t.lazy?(f.value=!0,r.value=!1,D(),M()):F()}),J.onMountedOrActivated(()=>{t.lazy?M():F()}),()=>{const n=w.getSlotVNode(l,t,"fallback"),o=w.getSlotVNode(l,t,"placeholder");return e.createVNode(e.Fragment,null,[e.createVNode("div",{class:{[`${b}`]:!0,[`${L.value.class}`]:L.value.class},ref:s=>p.value=s,style:{...L.value.style||{},display:t.lazy?"block":void 0},onClick:()=>{u("click")}},[f.value?o||e.createVNode("div",{class:`${b}-placeholder`},null):r.value?n||e.createVNode("div",{class:`${b}-error`},[e.createTextVNode("\u52A0\u8F7D\u5931\u8D25")]):e.createVNode("img",e.mergeProps({class:{[`${b}-inner`]:!0,[`${b}-inner-center`]:S.value,[`${b}-preview`]:E.value}},L.value,{src:t.src,style:k.value,onClick:()=>a()}),null),e.createVNode(e.Teleport,{to:"body",disabled:!t.appendToBody},{default:()=>[E.value&&x.value&&e.createVNode(X,{zIndex:t.zIndex,initialIndex:z.value,urlList:t.previewSrcList,onHideOnClickModal:t.hideOnClickModal,onClose:()=>y()},null)]})])])}}});$.isWImage=!0,$.install=t=>(t.component($.name,$),t),v.GImage=$,v.ImageViewer=X,v.ImageViewerGroup=ce,v.default=$,Object.defineProperties(v,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gx-design-vue/image",
3
- "version": "0.0.9",
3
+ "version": "0.1.1",
4
4
  "scripts": {
5
5
  "dev": "vite",
6
6
  "build": "vite build",
@@ -26,9 +26,9 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@vueuse/core": "^9.10.0",
29
- "@gx-design-vue/pro-utils": "^0.0.34",
30
- "@gx-design-vue/pro-hooks": "^0.0.12",
31
- "ant-design-vue": "^3.2.15",
29
+ "@gx-design-vue/pro-utils": "^0.1.3",
30
+ "@gx-design-vue/pro-hooks": "^0.1.4",
31
+ "ant-design-vue": "^3.2.17",
32
32
  "vue": "^3.2.45",
33
33
  "vue-types": "^4.1.1"
34
34
  },
@@ -39,11 +39,10 @@
39
39
  "@types/lodash-es": "^4.17.6",
40
40
  "@types/jsdom": "^16.2.14",
41
41
  "@types/node": "^16.11.26",
42
- "@vitejs/plugin-vue": "^4.0.0",
43
- "@vitejs/plugin-vue-jsx": "^3.0.0",
42
+ "@vitejs/plugin-vue": "^2.3.1",
43
+ "@vitejs/plugin-vue-jsx": "^1.3.10",
44
44
  "@vue/eslint-config-prettier": "^7.0.0",
45
45
  "@vue/eslint-config-typescript": "^10.0.0",
46
- "@vue/test-utils": "^2.0.0-rc.18",
47
46
  "@vue/tsconfig": "^0.1.3",
48
47
  "eslint": "^8.13.0",
49
48
  "eslint-plugin-prettier": "^4.0.0",
@@ -62,9 +61,9 @@
62
61
  "stylelint-config-standard": "^25.0.0",
63
62
  "stylelint-order": "^5.0.0",
64
63
  "typescript": "^4.6.4",
65
- "vite": "^4.0.4",
64
+ "vite": "^2.9.14",
66
65
  "vue-eslint-parser": "^9.0.3",
67
- "vue-tsc": "0.39.4"
66
+ "vue-tsc": "^1.0.24"
68
67
  },
69
68
  "description": "Gx Design"
70
69
  }
package/dist/image.mjs DELETED
@@ -1,592 +0,0 @@
1
- import { createVNode as l, defineComponent as Z, ref as g, computed as b, watch as U, nextTick as oe, Fragment as re, resolveComponent as ue, cloneVNode as ve, Teleport as ce, isVNode as me, createTextVNode as ge, mergeProps as he } from "vue";
2
- import { ExpandOutlined as ye, OneToOneOutlined as we, CloseOutlined as be, LeftOutlined as pe, RightOutlined as Oe, ZoomOutOutlined as Ce, ZoomInOutlined as Ie, RotateLeftOutlined as ke, RotateRightOutlined as xe, LoadingOutlined as Le } from "@ant-design/icons-vue";
3
- import { getPrefixCls as K, isServer as T, getSlotVNode as ee, isInContainer as Se, isString as Ne, getScrollContainer as $e } from "@gx-design-vue/pro-utils";
4
- import { onMountedOrActivated as se } from "@gx-design-vue/pro-hooks";
5
- import { createTypes as Te } from "vue-types";
6
- import { useThrottleFn as Ae, useEventListener as te } from "@vueuse/core";
7
- var de = Te({
8
- func: void 0,
9
- bool: void 0,
10
- string: void 0,
11
- number: void 0,
12
- array: void 0,
13
- object: void 0,
14
- integer: void 0
15
- });
16
- de.extend([{
17
- name: "looseBool",
18
- getter: !0,
19
- type: Boolean,
20
- default: void 0
21
- }, {
22
- name: "style",
23
- getter: !0,
24
- type: [String, Object],
25
- default: void 0
26
- }, {
27
- name: "VueNode",
28
- getter: !0,
29
- type: null
30
- }]);
31
- const _ = de, P = {
32
- appendToBody: {
33
- type: Boolean,
34
- default: !1
35
- },
36
- hideOnClickModal: {
37
- type: Boolean,
38
- default: !0
39
- },
40
- src: {
41
- type: String,
42
- default: ""
43
- },
44
- fit: {
45
- type: String,
46
- default: ""
47
- },
48
- lazy: _.bool,
49
- scrollContainer: {
50
- type: [String, Object]
51
- },
52
- placeholder: {
53
- type: [Function, Object],
54
- default: () => {
55
- }
56
- },
57
- fallback: {
58
- type: [Function, Object],
59
- default: () => {
60
- }
61
- },
62
- onError: {
63
- type: Function
64
- },
65
- onClick: {
66
- type: Function
67
- },
68
- disablePreview: _.bool,
69
- previewSrcList: {
70
- type: Array,
71
- default: () => []
72
- },
73
- width: _.number,
74
- height: _.number,
75
- zIndex: {
76
- type: Number,
77
- default: 2e3
78
- }
79
- }, ze = {
80
- urlList: {
81
- type: Array,
82
- default: () => []
83
- },
84
- zIndex: P.zIndex,
85
- initialIndex: {
86
- type: Number,
87
- default: 0
88
- },
89
- infinite: {
90
- type: Boolean,
91
- default: !0
92
- },
93
- onHideOnClickModal: P.hideOnClickModal
94
- }, $ = {
95
- tab: "Tab",
96
- enter: "Enter",
97
- space: "Space",
98
- left: "ArrowLeft",
99
- up: "ArrowUp",
100
- right: "ArrowRight",
101
- down: "ArrowDown",
102
- esc: "Escape",
103
- delete: "Delete",
104
- backspace: "Backspace"
105
- }, Y = function(e, a, d, w = !1) {
106
- e && a && d && e.addEventListener(a, d, w);
107
- }, X = function(e, a, d, w = !1) {
108
- e && a && d && e.removeEventListener(a, d, w);
109
- }, V = {
110
- CONTAIN: {
111
- name: "contain",
112
- icon: l(ye, null, null)
113
- },
114
- ORIGINAL: {
115
- name: "original",
116
- icon: l(we, null, null)
117
- }
118
- }, Ee = function() {
119
- return !T && !!window.navigator.userAgent.match(/firefox/i);
120
- }, ne = Ee() ? "DOMMouseScroll" : "mousewheel";
121
- function q(e) {
122
- let a = !1;
123
- return function(...d) {
124
- a || (a = !0, window.requestAnimationFrame(() => {
125
- e.apply(this, d), a = !1;
126
- }));
127
- };
128
- }
129
- const fe = Z({
130
- props: ze,
131
- emits: ["close", "switch"],
132
- setup: function(e, {
133
- emit: a
134
- }) {
135
- let d = null, w = null, p = null;
136
- const o = K({
137
- suffixCls: "image-viewer"
138
- }), f = g(!0), h = g(e.initialIndex), k = g(null), x = g(null), O = g(V.CONTAIN), r = g({
139
- scale: 1,
140
- deg: 0,
141
- offsetX: 0,
142
- offsetY: 0,
143
- enableTransition: !1
144
- }), u = b(() => {
145
- const {
146
- urlList: n
147
- } = e;
148
- return n.length <= 1;
149
- }), s = b(() => h.value === 0), v = b(() => h.value === e.urlList.length - 1), I = b(() => e.urlList[h.value]), L = g("viewer-fade-enter-active"), A = b(() => {
150
- const {
151
- scale: n,
152
- deg: y,
153
- offsetX: t,
154
- offsetY: i,
155
- enableTransition: c
156
- } = r.value, m = {
157
- transform: `scale(${n}) rotate(${y}deg)`,
158
- transition: c ? "transform .3s" : "",
159
- marginLeft: `${t}px`,
160
- marginTop: `${i}px`
161
- };
162
- return O.value.name === V.CONTAIN.name && (m.maxWidth = m.maxHeight = "100%"), m;
163
- }), z = () => {
164
- W(), setTimeout(() => {
165
- a("close");
166
- }, 200);
167
- }, S = () => {
168
- L.value = "viewer-fade-enter-active", d = q((n) => {
169
- switch (n.code) {
170
- case $.esc:
171
- z();
172
- break;
173
- case $.space:
174
- M();
175
- break;
176
- case $.left:
177
- R();
178
- break;
179
- case $.up:
180
- C("zoomIn");
181
- break;
182
- case $.right:
183
- j();
184
- break;
185
- case $.down:
186
- C("zoomOut");
187
- break;
188
- }
189
- }), w = q((n) => {
190
- (n.wheelDelta ? n.wheelDelta : -n.detail) > 0 ? C("zoomIn", {
191
- zoomRate: 0.015,
192
- enableTransition: !1
193
- }) : C("zoomOut", {
194
- zoomRate: 0.015,
195
- enableTransition: !1
196
- });
197
- }), Y(document, "keydown", d), Y(document, ne, w);
198
- }, W = () => {
199
- L.value = "viewer-fade-leave-active", X(document, "keydown", d), X(document, ne, w), d = null, w = null;
200
- }, E = () => {
201
- f.value = !1;
202
- }, D = (n) => {
203
- f.value = !1, n.target.alt = "\u52A0\u8F7D\u5931\u8D25";
204
- }, H = (n) => {
205
- if (f.value || n.button !== 0)
206
- return;
207
- const {
208
- offsetX: y,
209
- offsetY: t
210
- } = r.value, i = n.pageX, c = n.pageY;
211
- p = q((m) => {
212
- r.value = {
213
- ...r.value,
214
- offsetX: y + m.pageX - i,
215
- offsetY: t + m.pageY - c
216
- };
217
- }), Y(document, "mousemove", p), Y(document, "mouseup", () => {
218
- X(document, "mousemove", p);
219
- }), n.preventDefault();
220
- }, F = () => {
221
- r.value = {
222
- scale: 1,
223
- deg: 0,
224
- offsetX: 0,
225
- offsetY: 0,
226
- enableTransition: !1
227
- };
228
- }, M = () => {
229
- if (f.value)
230
- return;
231
- const n = Object.keys(V), y = Object.values(V), t = O.value.name, c = (y.findIndex((m) => m.name === t) + 1) % n.length;
232
- O.value = V[n[c]], F();
233
- }, R = () => {
234
- if (s.value && !e.infinite)
235
- return;
236
- const n = e.urlList.length;
237
- h.value = (h.value - 1 + n) % n;
238
- }, j = () => {
239
- if (v.value && !e.infinite)
240
- return;
241
- const n = e.urlList.length;
242
- h.value = (h.value + 1) % n;
243
- }, C = (n, y = {}) => {
244
- if (f.value)
245
- return;
246
- const {
247
- zoomRate: t,
248
- rotateDeg: i,
249
- enableTransition: c
250
- } = {
251
- zoomRate: 0.2,
252
- rotateDeg: 90,
253
- enableTransition: !0,
254
- ...y
255
- };
256
- switch (n) {
257
- case "zoomOut":
258
- r.value.scale > 0.2 && (r.value.scale = parseFloat((r.value.scale - t).toFixed(3)));
259
- break;
260
- case "zoomIn":
261
- r.value.scale = parseFloat((r.value.scale + t).toFixed(3));
262
- break;
263
- case "clocelise":
264
- r.value.deg += i;
265
- break;
266
- case "anticlocelise":
267
- r.value.deg -= i;
268
- break;
269
- }
270
- r.value.enableTransition = c;
271
- };
272
- return U(I, () => {
273
- oe(() => {
274
- x.value.complete || (f.value = !0);
275
- });
276
- }), U(h, (n) => {
277
- F(), a("switch", n);
278
- }), se(() => {
279
- var n, y;
280
- S(), (y = (n = k.value) == null ? void 0 : n.focus) == null || y.call(n);
281
- }), () => l("div", {
282
- ref: (n) => k.value = n,
283
- tabindex: 1,
284
- class: [`${o}-wrapper`, `${L.value}`],
285
- style: {
286
- zIndex: e.zIndex
287
- }
288
- }, [l("div", {
289
- class: `${o}-mask`,
290
- onClick: () => e.onHideOnClickModal && z()
291
- }, null), l("span", {
292
- class: [`${o}-btn`, `${o}-close`],
293
- onClick: () => z()
294
- }, [l(be, null, null)]), !u.value && l(re, null, [l("span", {
295
- class: {
296
- [`${o}-btn`]: !0,
297
- [`${o}-prev`]: !0,
298
- ["is-disabled"]: !e.infinite && s.value
299
- },
300
- onClick: () => R()
301
- }, [l(pe, null, null)]), l("span", {
302
- class: {
303
- [`${o}-btn`]: !0,
304
- [`${o}-next`]: !0,
305
- ["is-disabled"]: !e.infinite && s.value
306
- },
307
- onClick: () => j()
308
- }, [l(Oe, null, null)])]), l("div", {
309
- class: [`${o}-btn`, `${o}-actions`]
310
- }, [l("div", {
311
- class: `${o}-actions-inner`
312
- }, [l(Ce, {
313
- onClick: () => C("zoomOut")
314
- }, null), l(Ie, {
315
- onClick: () => C("zoomIn")
316
- }, null), l("i", {
317
- class: `${o}-actions-divider`
318
- }, null), l("i", {
319
- onClick: () => M()
320
- }, [O.value.icon]), l("i", {
321
- class: `${o}-actions-divider`
322
- }, null), l(ke, {
323
- onClick: () => C("anticlocelise")
324
- }, null), l(xe, {
325
- onClick: () => C("clocelise")
326
- }, null)])]), f.value && l("div", {
327
- class: `${o}-canvas`
328
- }, [l(ue("a-spin"), {
329
- indicator: l(Le, {
330
- style: {
331
- color: "#fff",
332
- fontSize: "40px"
333
- }
334
- }, null)
335
- }, null)]), l("div", {
336
- class: `${o}-canvas`
337
- }, [e.urlList.map((n, y) => l("img", {
338
- ref: (t) => x.value = t,
339
- class: `${o}-img`,
340
- key: n,
341
- style: {
342
- ...A.value,
343
- display: y === h.value ? "block" : "none"
344
- },
345
- src: n,
346
- onLoad: () => E(),
347
- onError: (t) => D(t),
348
- onMousedown: (t) => H(t)
349
- }, null))])]);
350
- }
351
- });
352
- function Fe(e) {
353
- return typeof e == "function" || Object.prototype.toString.call(e) === "[object Object]" && !me(e);
354
- }
355
- let le = "";
356
- const Ge = Z({
357
- props: {
358
- hideOnClickModal: P.hideOnClickModal
359
- },
360
- setup(e, {
361
- slots: a
362
- }) {
363
- const d = K({
364
- suffixCls: "image-viewer-group"
365
- }), w = g(!1), p = g(""), o = b(() => {
366
- var u, s, v, I, L;
367
- return ((u = a.default) == null ? void 0 : u.call(a).length) === 1 && (String((s = a.default) == null ? void 0 : s.call(a)[0].type) === String(Symbol("Fragment")) || String((v = a.default) == null ? void 0 : v.call(a)[0].type) === String(Symbol())) ? ((I = a.default) == null ? void 0 : I.call(a)[0].children) || [] : ((L = a.default) == null ? void 0 : L.call(a)) || [];
368
- }), f = b(() => o.value.filter((v) => k(v)).map((v) => v.props.src).filter((v) => v) || []), h = b(() => Array.isArray(f.value) && f.value.length > 0), k = (u) => u && u.type && (u.type.isGImage || u.type.name === "GImage"), x = () => {
369
- let u = 0;
370
- const s = f.value.findIndex((v) => v === p.value);
371
- return s >= 0 && (u = s), u;
372
- }, O = (u) => {
373
- !h.value || !u || (p.value = u, le = document.body.style.overflow, document.body.style.overflow = "hidden", w.value = !0);
374
- }, r = () => {
375
- document.body.style.overflow = le, w.value = !1;
376
- };
377
- return () => {
378
- let u;
379
- return l("div", {
380
- class: `${d}`
381
- }, [l(ue("a-space"), {
382
- size: 15
383
- }, Fe(u = o.value.map((s, v) => k(s) ? l("div", {
384
- key: v,
385
- class: `${d}-item`,
386
- onClick: () => {
387
- var I;
388
- return O(((I = s.props) == null ? void 0 : I.src) || "");
389
- }
390
- }, [ve(s, {
391
- disablePreview: !0
392
- })]) : null)) ? u : {
393
- default: () => [u]
394
- }), l(ce, {
395
- to: "body"
396
- }, {
397
- default: () => [h.value && w.value && l(fe, {
398
- initialIndex: x(),
399
- urlList: f.value,
400
- onHideOnClickModal: e.hideOnClickModal,
401
- onClose: () => r()
402
- }, null)]
403
- })]);
404
- };
405
- }
406
- }), Me = (e) => e && e.nodeType === Node.ELEMENT_NODE, ae = () => document.documentElement.style.objectFit !== void 0;
407
- let ie = "";
408
- const N = {
409
- NONE: "none",
410
- CONTAIN: "contain",
411
- COVER: "cover",
412
- FILL: "fill",
413
- SCALE_DOWN: "scale-down"
414
- }, G = Z({
415
- props: P,
416
- name: "GImage",
417
- inheritAttrs: !1,
418
- emits: ["error", "click"],
419
- setup(e, {
420
- slots: a,
421
- emit: d,
422
- attrs: w
423
- }) {
424
- const p = K({
425
- suffixCls: "image"
426
- }), o = g(!1), f = g(!0), h = g(0), k = g(0), x = g(!1), O = g(null), r = g();
427
- let u, s;
428
- const v = b(() => ({
429
- width: e.width ? `${e.width}px` : void 0,
430
- height: e.height ? `${e.height}px` : void 0
431
- })), I = b(() => {
432
- const {
433
- fit: t
434
- } = e;
435
- return !T && t ? ae() ? {
436
- "object-fit": t,
437
- ...v.value
438
- } : {
439
- ...W(t),
440
- ...v.value
441
- } : v.value;
442
- }), L = b(() => {
443
- const {
444
- fit: t
445
- } = e;
446
- return !T && !ae() && t !== N.FILL;
447
- }), A = b(() => {
448
- const {
449
- previewSrcList: t
450
- } = e;
451
- return Array.isArray(t) && t.length > 0;
452
- }), z = b(() => {
453
- const {
454
- src: t,
455
- previewSrcList: i
456
- } = e;
457
- let c = 0;
458
- const m = i.indexOf(t);
459
- return m >= 0 && (c = m), c;
460
- }), S = b(() => w), W = (t) => {
461
- const i = e.width || h.value, c = e.height || k.value;
462
- if (!O.value)
463
- return {};
464
- const {
465
- clientWidth: m,
466
- clientHeight: B
467
- } = O.value;
468
- if (!i || !c || !m || !B)
469
- return {};
470
- const J = i / c, Q = m / B;
471
- switch (t === N.SCALE_DOWN && (t = i < m && c < B ? N.NONE : N.CONTAIN), t) {
472
- case N.NONE:
473
- return {
474
- width: "auto",
475
- height: "auto"
476
- };
477
- case N.CONTAIN:
478
- return J < Q ? {
479
- width: "auto"
480
- } : {
481
- height: "auto"
482
- };
483
- case N.COVER:
484
- return J < Q ? {
485
- height: "auto"
486
- } : {
487
- width: "auto"
488
- };
489
- default:
490
- return {};
491
- }
492
- }, E = () => {
493
- if (T)
494
- return;
495
- const t = S.value;
496
- f.value = !0, o.value = !1;
497
- const i = new Image();
498
- i.onload = (c) => R(c, i), i.onerror = j, Object.keys(t).forEach((c) => {
499
- if (c.toLowerCase() === "onload")
500
- return;
501
- const m = t[c];
502
- i.setAttribute(c, m);
503
- }), i.src = e.src;
504
- };
505
- function D() {
506
- Se(O.value, r.value) && (E(), M());
507
- }
508
- const H = Ae(D, 200), F = async () => {
509
- var i;
510
- if (T)
511
- return;
512
- await oe();
513
- const {
514
- scrollContainer: t
515
- } = e;
516
- Me(t) ? r.value = t : Ne(t) && t !== "" ? r.value = (i = document.querySelector(t)) != null ? i : void 0 : O.value && (r.value = $e(O.value)), r.value && (u = te(r, "scroll", H), setTimeout(() => D(), 200));
517
- }, M = () => {
518
- T || !r.value || !H || (u(), r.value = void 0);
519
- }, R = (t, i) => {
520
- h.value = i.width, k.value = i.height, f.value = !1, o.value = !1;
521
- }, j = (t) => {
522
- f.value = !1, o.value = !0, d("error", t);
523
- }, C = (t) => {
524
- if (!!t.ctrlKey) {
525
- if (t.deltaY < 0)
526
- return t.preventDefault(), !1;
527
- if (t.deltaY > 0)
528
- return t.preventDefault(), !1;
529
- }
530
- }, n = () => {
531
- !A.value || e.disablePreview || (s = te("wheel", C, {
532
- passive: !1
533
- }), ie = document.body.style.overflow, document.body.style.overflow = "hidden", x.value = !0);
534
- }, y = () => {
535
- s == null || s(), document.body.style.overflow = ie, x.value = !1;
536
- };
537
- return U(() => e.src, () => {
538
- e.lazy ? (f.value = !0, o.value = !1, M(), F()) : E();
539
- }), se(() => {
540
- e.lazy ? F() : E();
541
- }), () => {
542
- const t = ee(a, e, "fallback"), i = ee(a, e, "placeholder");
543
- return l(re, null, [l("div", {
544
- class: {
545
- [`${p}`]: !0,
546
- [`${S.value.class}`]: S.value.class
547
- },
548
- ref: (c) => O.value = c,
549
- style: {
550
- ...S.value.style || {},
551
- display: e.lazy ? "block" : void 0
552
- },
553
- onClick: () => {
554
- d("click");
555
- }
556
- }, [f.value ? i || l("div", {
557
- class: `${p}-placeholder`
558
- }, null) : o.value ? t || l("div", {
559
- class: `${p}-error`
560
- }, [ge("\u52A0\u8F7D\u5931\u8D25")]) : l("img", he({
561
- class: {
562
- [`${p}-inner`]: !0,
563
- [`${p}-inner-center`]: L.value,
564
- [`${p}-preview`]: A.value
565
- }
566
- }, S.value, {
567
- src: e.src,
568
- style: I.value,
569
- onClick: () => n()
570
- }), null), l(ce, {
571
- to: "body",
572
- disabled: !e.appendToBody
573
- }, {
574
- default: () => [A.value && x.value && l(fe, {
575
- zIndex: e.zIndex,
576
- initialIndex: z.value,
577
- urlList: e.previewSrcList,
578
- onHideOnClickModal: e.hideOnClickModal,
579
- onClose: () => y()
580
- }, null)]
581
- })])]);
582
- };
583
- }
584
- });
585
- G.isWImage = !0;
586
- G.install = (e) => (e.component(G.name, G), e);
587
- export {
588
- G as GImage,
589
- fe as ImageViewer,
590
- Ge as ImageViewerGroup,
591
- G as default
592
- };