@gx-design-vue/image 0.2.0-beta.26 → 0.2.0-beta.27
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.d.ts +36 -22
- package/dist/ImagePreview/hooks/getFixScaleEleTransPosition.d.ts +16 -0
- package/dist/ImagePreview/hooks/useImageTransform.d.ts +35 -0
- package/dist/ImagePreview/hooks/useMouseEvent.d.ts +10 -0
- package/dist/ImagePreview/hooks/useTouchEvent.d.ts +8 -0
- package/dist/ImagePreview/index.d.ts +88 -9
- package/dist/ImagePreview/props.d.ts +29 -2
- package/dist/ImagePreview/typings.d.ts +0 -1
- package/dist/ImagePreview/utils/util.d.ts +4 -12
- package/dist/image.js +838 -1154
- package/dist/image.umd.cjs +1 -1
- package/dist/props.d.ts +12 -7
- package/dist/style.d.ts +2 -0
- package/dist/typings.d.ts +2 -0
- package/dist/utils/util.d.ts +1 -0
- package/package.json +2 -2
package/dist/image.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(v,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("@gx-design-vue/pro-hooks"),require("@gx-design-vue/pro-provider"),require("@gx-design-vue/pro-utils"),require("@vueuse/core"),require("lodash-es"),require("@ant-design/icons-vue"),require("@ctrl/tinycolor")):typeof define=="function"&&define.amd?define(["exports","vue","@gx-design-vue/pro-hooks","@gx-design-vue/pro-provider","@gx-design-vue/pro-utils","@vueuse/core","lodash-es","@ant-design/icons-vue","@ctrl/tinycolor"],t):(v=typeof globalThis<"u"?globalThis:v||self,t(v.GImage={},v.vue,v.proHooks,v.proProvider,v.proUtils,v.core,v.lodashEs,v.iconsVue,v.tinycolor))})(this,function(v,t,oe,y,u,ie,we,L,_){"use strict";function Le(e,n){process.env.NODE_ENV!=="production"&&!e&&console!==void 0&&console.error(`Warning: ${n}`)}let ve=e=>setTimeout(e,16),he=e=>clearTimeout(e);typeof window<"u"&&"requestAnimationFrame"in window&&(ve=e=>window.requestAnimationFrame(e),he=e=>window.cancelAnimationFrame(e));let Se=0;const ae=new Map;function Ne(e){ae.delete(e)}function re(e,n=1){Se+=1;const a=Se;function l(i){if(i===0)Ne(a),e();else{const g=ve(()=>{l(i-1)});ae.set(a,g)}}return l(n),a}re.cancel=e=>{const n=ae.get(e);return Ne(n),he(n)};function Te(e){const n=t.ref(null),a=t.reactive({...e}),l=t.ref([]),i=g=>{n.value===null&&(l.value=[],n.value=re(()=>{let c;l.value.forEach(f=>{c={...c,...f}}),Object.assign(a,c),n.value=null})),l.value.push(g)};return t.onMounted(()=>{n.value&&re.cancel(n.value)}),[a,i]}const F={infinite:{type:Boolean,default:!0},zIndex:{type:Number,default:2e3},current:{type:Number,default:0},getContainer:{type:String}},le={preview:{type:Object,default:()=>({current:0,infinite:!0,onHideOnClickModal:!0})},showPreview:{type:Boolean,default:!0},src:{type:String,default:""},alt:{type:String,default:""},fit:{type:String,default:"contain"},lazy:Boolean,scrollContainer:{type:[String,Object]},placeholder:{type:[Function,Object],default:()=>{}},fallback:{type:[Function,Object],default:()=>{}},onLoad:{type:Function},onError:{type:Function},onClick:{type:Function},imageClassName:String,imageStyle:Object,width:Number,height:Number,zIndex:F.zIndex,getContainer:F.getContainer},V={previewUrls:{type:Array,default:()=>[]},disabled:Boolean,zIndex:F.zIndex,current:F.current,infinite:F.infinite,getContainer:le.getContainer,onHideOnClickModal:{type:Boolean,default:!0},countRender:[Function,Array,Object],icons:{type:Object,default:()=>({})}},be=t.defineComponent({name:"Operations",inheritAttrs:!1,props:{open:Boolean,count:{type:Number,default:0},current:{type:Number,default:0},showSwitch:Boolean,showProgress:Boolean,prefixCls:String,hashId:String,zIndex:V.zIndex,icons:V.icons,infinite:V.infinite,getContainer:V.getContainer,countRender:V.countRender,tools:Array,onClose:Function,onActive:Function},setup(e){const n=(a,l)=>{var i;a.preventDefault(),a.stopPropagation(),(i=e.onActive)==null||i.call(e,l)};return()=>{const{prefixCls:a,hashId:l,tools:i}=e,g=y.getTransitionProps(`${e.prefixCls}-fade`),c=`${a}-operations-operation`,f=`${a}-operations-icon`;return t.createVNode(t.Teleport,{to:e.getContainer||"body"},{default:()=>[t.createVNode(t.Transition,g,{default:()=>{var p,h,I,M;return[t.withDirectives(t.createVNode("div",{class:u.classNames(`${a}-operations-wrapper`,l),style:{zIndex:e.zIndex}},[((p=e.icons)==null?void 0:p.close)===null?null:t.createVNode("button",{class:`${a}-close ${l}`,onClick:e.onClose},[((h=e.icons)==null?void 0:h.close)||t.createVNode(L.CloseOutlined,null,null)]),e.showSwitch&&t.createVNode(t.Fragment,null,[t.createVNode("div",{class:u.classNames(`${a}-switch-left ${l}`,{[`${a}-switch-left-disabled`]:e.infinite?!1:e.current===0}),onClick:m=>n(m,-1)},[((I=e.icons)==null?void 0:I.left)||t.createVNode(L.LeftOutlined,null,null)]),t.createVNode("div",{class:u.classNames(`${a}-switch-right ${l}`,{[`${a}-switch-right-disabled`]:e.infinite?!1:e.current===e.count-1}),onClick:m=>n(m,1)},[((M=e.icons)==null?void 0:M.right)||t.createVNode(L.RightOutlined,null,null)])]),t.createVNode("div",{class:`${a}-footer ${l}`},[e.showProgress&&t.createVNode("div",{class:`${a}-progress`},[e.countRender?e.countRender(e.current+1,e.count):`${e.current+1} / ${e.count}`]),t.createVNode("div",{class:`${e.prefixCls}-operations`},[i==null?void 0:i.map(({icon:m,onClick:d,type:O,disabled:S})=>t.createVNode("div",{class:u.classNames(c,{[`${e.prefixCls}-operations-operation-disabled`]:S&&(S==null?void 0:S.value)}),onClick:d,key:O},[t.cloneVNode(m,{class:f})]))])])]),[[t.vShow,e.open]])]}})]})}}}),Pe=new y.Keyframe("viewFadeIn",{"0%":{opacity:0},"100%":{opacity:1}}),Re=new y.Keyframe("viewFadeOut",{"0%":{opacity:1},"100%":{opacity:0}}),$e=new y.Keyframe("viewZoomBadgeIn",{"0%":{transform:"scale(0.2)",opacity:0},"100%":{transform:"scale(1)",opacity:1}}),De=new y.Keyframe("viewZoomBadgeOut",{"0%":{transform:"scale(1)"},"100%":{transform:"scale(0.2)",opacity:0}}),Ie=e=>({position:e||"absolute",inset:0});function se(e){return{position:e,top:0,insetInlineEnd:0,bottom:0,insetInlineStart:0}}const ze=e=>{const{previewCls:n,modalMaskBg:a,paddingSM:l,marginXL:i,margin:g,paddingLG:c,previewOperationColorDisabled:f,previewOperationHoverColor:p,motionDurationSlow:h,iconCls:I,colorTextLightSolid:M}=e,m=new _.TinyColor(a).setAlpha(.1),d=m.clone().setAlpha(.2);return{[`${n}-footer`]:{position:"fixed",bottom:i,left:{_skip_check_:!0,value:"50%"},display:"flex",flexDirection:"column",alignItems:"center",color:e.previewOperationColor,transform:"translateX(-50%)"},[`${n}-progress`]:{marginBottom:g},[`${n}-close`]:{position:"fixed",top:i,right:{_skip_check_:!0,value:i},display:"flex",color:M,backgroundColor:m.toRgbString(),borderRadius:"50%",padding:l,outline:0,border:0,cursor:"pointer",transition:`all ${h}`,"&:hover":{backgroundColor:d.toRgbString()},[`& > ${I}`]:{fontSize:e.previewOperationSize}},[`${n}-operations`]:{display:"flex",alignItems:"center",padding:`0 ${y.unit(c)}`,backgroundColor:m.toRgbString(),borderRadius:100,"&-operation":{marginInlineStart:l,padding:l,cursor:"pointer",transition:`all ${h}`,userSelect:"none",[`&:not(${n}-operations-operation-disabled):hover > ${I}`]:{color:p},"&-disabled":{color:f,cursor:"not-allowed"},"&:first-of-type":{marginInlineStart:0},[`& > ${I}`]:{fontSize:e.previewOperationSize}}}}},_e=e=>{const{modalMaskBg:n,iconCls:a,previewOperationColorDisabled:l,previewCls:i,zIndexPopup:g,motionDurationSlow:c}=e,f=new _.TinyColor(n).setAlpha(.1),p=f.clone().setAlpha(.2);return{[`${i}-switch-left, ${i}-switch-right`]:{position:"fixed",insetBlockStart:"50%",zIndex:e.calc(g).add(1).equal(),display:"flex",alignItems:"center",justifyContent:"center",width:e.imagePreviewSwitchSize,height:e.imagePreviewSwitchSize,marginTop:e.calc(e.imagePreviewSwitchSize).mul(-1).div(2).equal(),color:e.previewOperationColor,background:f.toRgbString(),borderRadius:"50%",transform:"translateY(-50%)",cursor:"pointer",transition:`all ${c}`,userSelect:"none","&:hover":{background:p.toRgbString()},"&-disabled":{"&, &:hover":{color:l,background:"transparent",cursor:"not-allowed",[`> ${a}`]:{cursor:"not-allowed"}}},[`> ${a}`]:{fontSize:e.previewOperationSize}},[`${i}-switch-left`]:{insetInlineStart:e.marginSM},[`${i}-switch-right`]:{insetInlineEnd:e.marginSM}}},Fe=e=>({[e.componentCls]:{height:"100%",textAlign:"center",pointerEvents:"none","&-root":{...se("fixed"),zIndex:e.zIndexPopup,overflow:"auto",outline:0,WebkitOverflowScrolling:"touch"},"&-wrap":{...se("fixed"),zIndex:e.zIndexPopup,overflow:"auto",outline:0,WebkitOverflowScrolling:"touch"},"&-mask":{...se("fixed"),zIndex:e.zIndexPopupBase,height:"100%",backgroundColor:e.colorBgMask},"&-body":{...Ie(),overflow:"hidden"},"&-img":{maxWidth:"100%",maxHeight:"100%",verticalAlign:"middle",transform:"scale3d(1, 1, 1)",cursor:"grab",transition:`transform ${e.motionDurationSlow} ${e.motionEaseOut} 0s`,userSelect:"none",pointerEvents:"auto","&-wrapper":{...Ie(),display:"flex",justifyContent:"center",alignItems:"center",transition:`transform ${e.motionDurationSlow} ${e.motionEaseOut} 0s`,"&::before":{display:"inline-block",width:1,height:"50%",marginInlineEnd:-1,content:'""'}}},"&-fade-appear, &-fade-enter":{animationName:Pe,animationDuration:e.motionDurationSlow,animationTimingFunction:"linear"},"&-fade-leave":{animationName:Re,animationDuration:e.motionDurationSlow,animationTimingFunction:"linear"},"&-zoom-appear, &-zoom-enter":{animationName:$e,opacity:0,animationTimingFunction:e.motionEaseOutCirc,animationFillMode:"both",transform:"none",animationDuration:e.motionDurationSlow,userSelect:"none"},"&-zoom-enter-active":{animationPlayState:"running"},"&-zoom-leave":{animationName:De,animationDuration:e.motionDurationSlow,animationTimingFunction:e.motionEaseOutBack,animationFillMode:"both"}},[`${e.componentCls}-root`]:{[`${e.componentCls}-wrapper`]:{zIndex:e.zIndexPopup}},[`${e.componentCls}-operations-wrapper`]:{position:"fixed",insetBlockStart:0,insetInlineEnd:0,zIndex:e.zIndexPopup+1,width:"100%"},"&":[ze(e),_e(e)]});function Ve(e){return y.useStyle("ImageViewer",n=>{const a=y.mergeToken(n,{zIndexPopup:n.zIndexPopupBase+80,previewOperationColorDisabled:new _.TinyColor(n.colorTextLightSolid).setAlpha(.25).toRgbString(),previewOperationHoverColor:new _.TinyColor(n.colorTextLightSolid).setAlpha(.85).toRgbString(),modalMaskBg:new _.TinyColor("#000").setAlpha(.45).toRgbString(),previewOperationColor:new _.TinyColor(n.colorTextLightSolid).toRgbString(),previewOperationSize:n.fontSizeIcon*1.5,imagePreviewSwitchSize:n.controlHeightLG,iconCls:"anticon",previewCls:n.componentCls});return[Fe(a)]},e)}let Ce=!1;try{const e=Object.defineProperty({},"passive",{get(){Ce=!0}});window.addEventListener("testPassive",null,e),window.removeEventListener("testPassive",null,e)}catch{}function U(e,n,a,l){if(e&&e.addEventListener){let i=l;i===void 0&&Ce&&(n==="touchstart"||n==="touchmove"||n==="wheel")&&(i={passive:!1}),e.addEventListener(n,a,i)}return{remove:()=>{e&&e.removeEventListener&&e.removeEventListener(n,a)}}}const r={MAC_ENTER:3,BACKSPACE:8,TAB:9,NUM_CENTER:12,ENTER:13,SHIFT:16,CTRL:17,ALT:18,PAUSE:19,CAPS_LOCK:20,ESC:27,SPACE:32,PAGE_UP:33,PAGE_DOWN:34,END:35,HOME:36,LEFT:37,UP:38,RIGHT:39,DOWN:40,PRINT_SCREEN:44,INSERT:45,DELETE:46,ZERO:48,ONE:49,TWO:50,THREE:51,FOUR:52,FIVE:53,SIX:54,SEVEN:55,EIGHT:56,NINE:57,QUESTION_MARK:63,A:65,B:66,C:67,D:68,E:69,F:70,G:71,H:72,I:73,J:74,K:75,L:76,M:77,N:78,O:79,P:80,Q:81,R:82,S:83,T:84,U:85,V:86,W:87,X:88,Y:89,Z:90,META:91,WIN_KEY_RIGHT:92,CONTEXT_MENU:93,NUM_ZERO:96,NUM_ONE:97,NUM_TWO:98,NUM_THREE:99,NUM_FOUR:100,NUM_FIVE:101,NUM_SIX:102,NUM_SEVEN:103,NUM_EIGHT:104,NUM_NINE:105,NUM_MULTIPLY:106,NUM_PLUS:107,NUM_MINUS:109,NUM_PERIOD:110,NUM_DIVISION:111,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123,NUMLOCK:144,SEMICOLON:186,DASH:189,EQUALS:187,COMMA:188,PERIOD:190,SLASH:191,APOSTROPHE:192,SINGLE_QUOTE:222,OPEN_SQUARE_BRACKET:219,BACKSLASH:220,CLOSE_SQUARE_BRACKET:221,WIN_KEY:224,MAC_FF_META:224,WIN_IME:229,isTextModifyingKeyEvent:function(n){const{keyCode:a}=n;if(n.altKey&&!n.ctrlKey||n.metaKey||a>=r.F1&&a<=r.F12)return!1;switch(a){case r.ALT:case r.CAPS_LOCK:case r.CONTEXT_MENU:case r.CTRL:case r.DOWN:case r.END:case r.ESC:case r.HOME:case r.INSERT:case r.LEFT:case r.MAC_FF_META:case r.META:case r.NUMLOCK:case r.NUM_CENTER:case r.PAGE_DOWN:case r.PAGE_UP:case r.PAUSE:case r.PRINT_SCREEN:case r.RIGHT:case r.SHIFT:case r.UP:case r.WIN_KEY:case r.WIN_KEY_RIGHT:return!1;default:return!0}},isCharacterKey:function(n){if(n>=r.ZERO&&n<=r.NINE||n>=r.NUM_ZERO&&n<=r.NUM_MULTIPLY||n>=r.A&&n<=r.Z||window.navigator.userAgent.includes("WebKit")&&n===0)return!0;switch(n){case r.SPACE:case r.QUESTION_MARK:case r.NUM_PLUS:case r.NUM_MINUS:case r.NUM_PERIOD:case r.NUM_DIVISION:case r.SEMICOLON:case r.DASH:case r.EQUALS:case r.COMMA:case r.PERIOD:case r.SLASH:case r.APOSTROPHE:case r.SINGLE_QUOTE:case r.OPEN_SQUARE_BRACKET:case r.BACKSLASH:case r.CLOSE_SQUARE_BRACKET:return!0;default:return!1}}};function Ue(e){const n=e.getBoundingClientRect(),a=document.documentElement;return{left:n.left+(window.scrollX||a.scrollLeft)-(a.clientLeft||document.body.clientLeft||0),top:n.top+(window.scrollY||a.scrollTop)-(a.clientTop||document.body.clientTop||0)}}function je(){const e=document.documentElement.clientWidth,n=window.innerHeight||document.documentElement.clientHeight;return{width:e,height:n}}function Ee(e,n,a,l){const i=n+a,g=(a-l)/2;if(a>l){if(n>0)return{[e]:g};if(n<0&&i<l)return{[e]:-g}}else if(n<0||i>l)return{[e]:n<0?g:-g};return{}}function Be(e,n,a,l){const{width:i,height:g}=je();let c=null;return e<=i&&n<=g?c={x:0,y:0}:(e>i||n>g)&&(c={...Ee("x",a,e,i),...Ee("y",l,n,g)}),c}const $={x:0,y:0},j={rotateLeft:t.createVNode(L.RotateLeftOutlined,null,null),rotateRight:t.createVNode(L.RotateRightOutlined,null,null),zoomIn:t.createVNode(L.ZoomInOutlined,null,null),zoomOut:t.createVNode(L.ZoomOutOutlined,null,null),flipX:t.createVNode(L.SwapOutlined,null,null),flipY:t.createVNode(L.SwapOutlined,{rotate:90},null)},pe=["close","left","right","rotateRight","rotateRight","zoomOut","flipX","flipY","rotateLeft"],ye=t.defineComponent({name:"GImagePreview",props:V,inheritAttrs:!1,emits:["close","switch","afterClose"],emit:Object,setup:(e,{emit:n,expose:a,slots:l})=>{const i=u.getPrefixCls({suffixCls:"image-view"}),{wrapSSR:g,hashId:c}=Ve(i),[f,p]=oe.useState(!1),[h,I]=oe.useState(!1),M=t.ref(null),m=t.ref(e.current),d=t.shallowRef(1),O=t.shallowRef(0),S=t.shallowRef(!1),x=t.reactive({x:1,y:1}),[C,b]=Te($),G=t.shallowRef({wheelDirection:0}),D=t.shallowRef(),A=t.reactive({originX:0,originY:0,deltaX:0,deltaY:0}),z=t.reactive(new Map),H=t.computed(()=>new Map(Array.from(z).map(([o,{url:w}])=>[o,w]))),Q=t.computed(()=>H.value.get(m.value)),K=t.computed(()=>H.value.size),W=t.computed(()=>Array.from(H.value.keys())),P=t.computed(()=>W.value.indexOf(m.value)),k=t.computed(()=>K.value>1),X=t.computed(()=>K.value>=1);t.watch(f,o=>{o&&(h.value=!0)});const s=o=>{m.value=o};t.watch(()=>e.current,o=>{u.isNumber(o)&&s(o)});function N(o,w){z.set(o,{url:w,loading:!0,canPreview:!1})}const T=()=>{I(!1),m.value=e.current},ue=()=>{d.value=1,O.value=0,x.x=1,x.y=1,b($),n("close")},de=o=>{S.value||M.value===(o==null?void 0:o.target)&&T()},fe=()=>{const o=z.get(m.value);o&&(o.loading=!1,o.canPreview=!0)},q=o=>{const w=z.get(m.value);w&&(w.loading=!1,w.canPreview=!1),o.target.alt="加载失败"},J=()=>{if(P.value>0||e.infinite){const o=P.value-1<0?e.previewUrls.length-1:P.value-1;s(W.value[o])}},ee=()=>{if(P.value<K.value-1||e.infinite){const o=P.value+1>e.previewUrls.length-1?0:P.value+1;s(W.value[o])}},Y=o=>{o?d.value+=.5:d.value++,b($)},Z=o=>{d.value>1&&(o?d.value-=.5:d.value--),b($)},ge=()=>{O.value+=90},We=()=>{O.value-=90},Xe=()=>{x.x=-x.x},Ze=()=>{x.y=-x.y},Oe=[{icon:u.getSlotVNode(l,e.icons,"zoomIn")||j.zoomIn,onClick:()=>Y(),type:"zoomIn"},{icon:u.getSlotVNode(l,e.icons,"zoomOut")||j.zoomOut,onClick:()=>Z(),type:"zoomOut",disabled:t.computed(()=>d.value===1)},{icon:u.getSlotVNode(l,e.icons,"rotateRight")||j.rotateRight,onClick:ge,type:"rotateRight"},{icon:u.getSlotVNode(l,e.icons,"rotateLeft")||j.rotateLeft,onClick:We,type:"rotateLeft"},{icon:u.getSlotVNode(l,e.icons,"flipX")||j.flipX,onClick:Xe,type:"flipX"},{icon:u.getSlotVNode(l,e.icons,"flipY")||j.flipY,onClick:Ze,type:"flipY"}],xe=()=>{if(f.value&&S.value&&D.value){const o=D.value.offsetWidth*d.value,w=D.value.offsetHeight*d.value,{left:R,top:E}=Ue(D.value),te=O.value%180!==0;S.value=!1;const ne=Be(te?w:o,te?o:w,R,E);ne&&b({...ne})}},Qe=o=>{o.button===0&&(o.preventDefault(),o.stopPropagation(),A.deltaX=o.pageX-C.x,A.deltaY=o.pageY-C.y,A.originX=C.x,A.originY=C.y,S.value=!0)},Ae=o=>{f.value&&S.value&&b({x:o.pageX-A.deltaX,y:o.pageY-A.deltaY})},ke=o=>{if(!f.value)return;o.preventDefault();const w=o.deltaY;G.value={wheelDirection:w}},qe=o=>{!f.value||!k.value||(o.keyCode===r.LEFT?J():o.keyCode===r.RIGHT&&ee())},Je=()=>{f.value&&(d.value!==1&&(d.value=1),(C.x!==$.x||C.y!==$.y)&&b($))};let me=()=>{};return t.onMounted(()=>{t.watch(()=>e.previewUrls,o=>{u.isArray(o)&&o.forEach((w,R)=>{N(R,w)})},{flush:"post",immediate:!0}),t.watch([()=>f.value,S],()=>{me();let o,w;const R=U(window,"mouseup",xe,!1),E=U(window,"mousemove",Ae,!1),te=U(window,"wheel",ke,{passive:!1}),ne=U(window,"keydown",qe,!1);try{window.top!==window.self&&(o=U(window.top,"mouseup",xe,!1),w=U(window.top,"mousemove",Ae,!1))}catch(et){Le(!1,`[vc-image] ${et}`)}me=()=>{R.remove(),E.remove(),te.remove(),ne.remove(),o&&o.remove(),w&&w.remove()}},{flush:"post",immediate:!0}),t.watch([G],()=>{const{wheelDirection:o}=G.value;o>0?Z(!0):o<0&&Y(!0)})}),t.onUnmounted(()=>{me()}),a({setOpen:p}),()=>{const o=y.getTransitionProps(`${i}-fade`),w=y.getTransitionProps(`${i}-zoom`),R={};for(const E in e.icons)R[E]=u.getSlotVNode(l,e.icons,E);return g(t.createVNode(t.Fragment,null,[t.createVNode(t.Teleport,{to:e.getContainer||"body"},{default:()=>[f.value&&t.createVNode(t.Fragment,null,[t.createVNode("div",{class:`${i}-root ${c.value}`},[t.createVNode(t.Transition,o,{default:()=>[t.withDirectives(t.createVNode("div",{class:`${i}-mask ${c.value}`},null),[[t.vShow,f.value&&h.value]])]}),t.createVNode("div",{ref:M,tabindex:-1,class:[`${i}-wrap`,`${c.value}`],onClick:E=>e.onHideOnClickModal&&de(E)},[t.createVNode(t.Transition,t.mergeProps(w,{onAfterLeave:()=>ue()}),{default:()=>[t.withDirectives(t.createVNode("div",{role:"dialog",class:`${i} ${c.value}`},[t.createVNode("div",{class:`${i}-content ${c.value}`},[t.createVNode("div",{class:`${i}-body ${c.value}`},[t.createVNode("div",{class:`${i}-img-wrapper ${c.value}`,style:{transform:`translate3d(${C.x}px, ${C.y}px, 0)`}},[t.createVNode("img",{onMousedown:Qe,onDblclick:Je,ref:D,class:`${i}-img ${c.value}`,src:Q.value,onLoad:()=>fe(),onError:E=>q(E),style:{transform:`scale3d(${x.x*d.value}, ${x.y*d.value}, 1) rotate(${O.value}deg)`}},null)])])])]),[[t.vShow,f.value&&h.value]])]})])])])]}),f.value&&h.value&&t.createVNode(be,{open:f.value&&h.value,hashId:c.value,count:e.previewUrls.length,current:m.value,zIndex:e.zIndex+1,getContainer:e.getContainer,prefixCls:i,icons:we.omit(R,Oe.map(({type:E})=>E)),tools:Oe,infinite:e.infinite,countRender:u.getSlot(l,e,"countRenders"),showSwitch:k.value,showProgress:X.value,onClose:T,onActive:E=>E>0?ee():J()},null)]))}}}),ce={width:"100%",height:"100%"},He=()=>({position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",opacity:0}),Ke=e=>({[e.componentCls]:{display:"inline-block",position:"relative",overflow:"hidden","&-inner":{...ce,verticalAlign:"top",opacity:1,[`&${e.componentCls}-inner-preview`]:{userSelect:"none"}},"&-placeholder":{...ce,backgroundColor:e.colorBgContainerDisabled,backgroundImage:"url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNMTQuNSAyLjVoLTEzQS41LjUgMCAwIDAgMSAzdjEwYS41LjUgMCAwIDAgLjUuNWgxM2EuNS41IDAgMCAwIC41LS41VjNhLjUuNSAwIDAgMC0uNS0uNXpNNS4yODEgNC43NWExIDEgMCAwIDEgMCAyIDEgMSAwIDAgMSAwLTJ6bTguMDMgNi44M2EuMTI3LjEyNyAwIDAgMS0uMDgxLjAzSDIuNzY5YS4xMjUuMTI1IDAgMCAxLS4wOTYtLjIwN2wyLjY2MS0zLjE1NmEuMTI2LjEyNiAwIDAgMSAuMTc3LS4wMTZsLjAxNi4wMTZMNy4wOCAxMC4wOWwyLjQ3LTIuOTNhLjEyNi4xMjYgMCAwIDEgLjE3Ny0uMDE2bC4wMTUuMDE2IDMuNTg4IDQuMjQ0YS4xMjcuMTI3IDAgMCAxLS4wMi4xNzV6IiBmaWxsPSIjOEM4QzhDIiBmaWxsLXJ1bGU9Im5vbnplcm8iLz48L3N2Zz4=')",backgroundRepeat:"no-repeat",backgroundPosition:"center center",backgroundSize:"30%"},"&-error":{...ce,display:"flex",alignItems:"center",justifyContent:"center",color:e.colorText,backgroundColor:e.colorBgContainerDisabled},"&-preview":He()}}),Ye=e=>e&&e.nodeType===Node.ELEMENT_NODE;let Me="";const Ge=[...pe,"fallback","placeholder"],B=t.defineComponent({props:le,name:"GImage",emits:["error","click","load"],slots:Object,setup(e,{slots:n,emit:a,attrs:l}){const i=u.getPrefixCls({suffixCls:"image"}),{wrapSSR:g,hashId:c}=y.useProStyle("Image",[Ke],i),f=t.ref(),p=t.ref(""),h=t.ref(!1),I=t.ref(!0),M=t.ref(!1),m=t.ref(null),d=t.ref();let O,S;const x=t.computed(()=>!u.isServer&&e.fit?{"object-fit":e.fit}:{}),C=t.computed(()=>{const{previewUrls:s}=e.preview;return u.isArray(s)&&s.length>0||e.showPreview}),b=t.computed(()=>{const{previewUrls:s=[],current:N=0}=e.preview;if(u.isNumber(N))return s.length>=N?N:0;const T=s.indexOf(e.src);return T>=0?T:0}),G=s=>{p.value=e.src,I.value=!1,h.value=!1,a("load",s)},D=s=>{I.value=!1,h.value=!0,a("error",s)},A=()=>{if(u.isServer)return;I.value=!0,h.value=!1;const s=new Image;s.onload=N=>G(N),s.onerror=D,Object.keys(l||{}).forEach(N=>{if(N.toLowerCase()==="onload")return;const T=(l||{})[N];s.setAttribute(N,T)}),s.src=e.src},z=ie.useThrottleFn(Q,200),H=()=>{u.isServer||!d.value||!z||(O(),d.value=void 0)};function Q(){u.isInContainer(m.value,d.value)&&(A(),H())}const K=async()=>{if(u.isServer)return;await t.nextTick();const{scrollContainer:s}=e;Ye(s)?d.value=s:u.isString(s)&&s!==""?d.value=document.querySelector(s)??void 0:m.value&&(d.value=u.getScrollContainer(m.value)),d.value&&(O=ie.useEventListener(d,"scroll",z),setTimeout(()=>Q(),200))},W=s=>{if(s.ctrlKey){if(s.deltaY<0)return s.preventDefault(),!1;if(s.deltaY>0)return s.preventDefault(),!1}},P=()=>{C.value&&(S=ie.useEventListener("wheel",W,{passive:!1}),Me=document.body.style.overflow,document.body.style.overflow="hidden",M.value=!0)},k=()=>{S==null||S(),document.body.style.overflow=Me,M.value=!1};t.watch(()=>e.src,()=>{e.lazy?(I.value=!0,h.value=!1,H(),K()):A()}),t.watchEffect(()=>{var s,N;C.value&&M.value?(s=f.value)==null||s.setOpen(!0):(N=f.value)==null||N.setOpen(!1)});const X=s=>u.isNumber(s)?s+"px":s;return oe.onMountedOrActivated(()=>{e.lazy?K():A()}),()=>{var Z;const{crossorigin:s,decoding:N,alt:T,sizes:ue,srcset:de,usemap:fe,class:q,style:J={}}=l,ee={crossorigin:s,decoding:N,alt:T,sizes:ue,srcset:de,usemap:fe,style:{...x.value,height:e.height?X(e.height):void 0}},Y=u.getSlotsProps(Ge,n,e,{render:!0});return g(t.createVNode("div",{class:{[`${c.value}`]:!0,[`${i}`]:!0,[`${q}`]:!!q},ref:ge=>m.value=ge,style:{width:e.width?X(e.width):void 0,height:e.height?X(e.height):void 0,display:e.lazy?"block":void 0,...J},onClick:()=>{a("click")}},[I.value?Y.placeholder||t.createVNode("div",{class:`${i}-placeholder ${c.value}`},null):h.value?Y.fallback||t.createVNode("div",{class:`${i}-error ${c.value}`},[t.createTextVNode("加载失败")]):p.value&&t.createVNode("img",t.mergeProps(ee,{class:{[`${c.value}`]:!0,[`${e.imageClassName}`]:!!e.imageClassName,[`${i}-inner`]:!0,[`${i}-inner-preview`]:C.value},alt:e.alt,src:p.value}),null),C.value&&t.createVNode("div",{class:`${i}-preview ${c.value}`,onClick:()=>P()},null),C.value&&t.createVNode(ye,t.mergeProps({ref:f},e.preview,we.pick(Y,pe),{previewUrls:((Z=e.preview)==null?void 0:Z.previewUrls)||[e.src],current:b.value,onClose:()=>k()}),null)]))}}});B.isGImage=!0,B.install=e=>(e.component(B.name,B),e),v.GImage=B,v.GImagePreview=ye,v.baseProps=F,v.default=B,v.imageProps=le,Object.defineProperties(v,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
1
|
+
(function(I,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("@gx-design-vue/pro-provider"),require("@gx-design-vue/pro-utils"),require("@vueuse/core"),require("lodash-es"),require("@ant-design/icons-vue"),require("@gx-design-vue/pro-hooks"),require("@ctrl/tinycolor")):typeof define=="function"&&define.amd?define(["exports","vue","@gx-design-vue/pro-provider","@gx-design-vue/pro-utils","@vueuse/core","lodash-es","@ant-design/icons-vue","@gx-design-vue/pro-hooks","@ctrl/tinycolor"],t):(I=typeof globalThis<"u"?globalThis:I||self,t(I.GImage={},I.vue,I.proProvider,I.proUtils,I.core,I.lodashEs,I.iconsVue,I.proHooks,I.tinycolor))})(this,function(I,t,L,S,E,k,V,j,W){"use strict";let fe=e=>setTimeout(e,16),ge=e=>clearTimeout(e);typeof window<"u"&&"requestAnimationFrame"in window&&(fe=e=>window.requestAnimationFrame(e),ge=e=>window.cancelAnimationFrame(e));let me=0;const le=new Map;function ve(e){le.delete(e)}function he(e,o=1){me+=1;const i=me;function r(n){if(n===0)ve(i),e();else{const s=fe(()=>{r(n-1)});le.set(i,s)}}return r(o),i}he.cancel=e=>{const o=le.get(e);return ve(o),ge(o)};const te={x:0,y:0,rotate:0,scale:1,flipX:!1,flipY:!1};function $e(e,o,i,r){const n=t.ref(null),s=t.ref([]),[u,h]=j.useState(te),y=v=>{h(te),k.isEqual(te,u.value)||r==null||r({transform:te,action:v})},d=(v,w)=>{n.value===null&&(s.value=[],n.value=he(()=>{let x=k.cloneDeep(u.value);s.value.forEach(l=>{x={...x,...l}}),n.value=null,r==null||r({transform:x,action:w}),h(x)})),s.value.push({...u.value,...v})};return{transform:u,resetTransform:y,updateTransform:d,dispatchZoomChange:(v,w,x,l,a)=>{const{width:p,height:f,offsetWidth:C,offsetHeight:b,offsetLeft:z,offsetTop:R}=e.value;let M=v,N=u.value.scale*v;N>i.value?(N=i.value,M=i.value/u.value.scale):N<o.value&&(N=a?N:o.value,M=N/u.value.scale);const _=x??innerWidth/2,U=l??innerHeight/2,X=M-1,T=X*p*.5,Y=X*f*.5,F=X*(_-u.value.x-z),ee=X*(U-u.value.y-R);let B=u.value.x-(F-T),Z=u.value.y-(ee-Y);if(v<1&&N===1){const D=C*N,g=b*N,{width:O,height:A}=E.useWindowSize();D<=O.value&&g<=A.value&&(B=0,Z=0)}d({x:B,y:Z,scale:N},w)}}}function Le(e,o){process.env.NODE_ENV!=="production"&&console!==void 0&&console.error(`Warning: ${o}`)}let we=!1;try{const e=Object.defineProperty({},"passive",{get(){we=!0}});window.addEventListener("testPassive",null,e),window.removeEventListener("testPassive",null,e)}catch{}function H(e,o,i,r){if(e&&e.addEventListener){let n=r;n===void 0&&we&&(o==="touchstart"||o==="touchmove"||o==="wheel")&&(n={passive:!1}),e.addEventListener(o,i,n)}return{remove:()=>{e&&e.removeEventListener&&e.removeEventListener(o,i)}}}const G=1,Me=1;function pe(e,o,i,r){const n=o+i,s=(i-r)/2;if(i>r){if(o>0)return{[e]:s};if(o<0&&n<r)return{[e]:-s}}else if(o<0||n>r)return{[e]:o<0?s:-s};return{}}function ye(e,o,i,r){const{width:n,height:s}=E.useWindowSize();let u=null;return e<=n.value&&o<=s.value?u={x:0,y:0}:(e>n.value||o>s.value)&&(u={...pe("x",i,e,n.value),...pe("y",r,o,s.value)}),u}function Te(e,o,i,r,n,s,u){const[h,y]=j.useState(!1),d=t.ref({diffX:0,diffY:0,transformX:0,transformY:0}),m=l=>{!o||l.button!==0||(l.preventDefault(),l.stopPropagation(),d.value={diffX:l.pageX-n.value.x,diffY:l.pageY-n.value.y,transformX:n.value.x,transformY:n.value.y},y(!0))},v=l=>{i&&h.value&&s({x:l.pageX-d.value.diffX,y:l.pageY-d.value.diffY},"move")},w=()=>{if(i&&h.value){y(!1);const{transformX:l,transformY:a}=d.value;if(!(n.value.x!==l&&n.value.y!==a))return;const f=e.value.offsetWidth*n.value.scale,C=e.value.offsetHeight*n.value.scale,{left:b,top:z}=e.value.getBoundingClientRect(),R=n.value.rotate%180!==0,M=ye(R?C:f,R?f:C,b,z);M&&s({...M},"dragRebound")}},x=l=>{if(!i||l.deltaY===0)return;const a=Math.abs(l.deltaY/100),p=Math.min(a,Me);let f=G+p*r.value;l.deltaY>0&&(f=G/f),u(f,"wheel",l.clientX,l.clientY)};return j.useEffect(()=>{let l,a,p,f;if(o){p=H(window,"mouseup",w,!1),f=H(window,"mousemove",v,!1);try{window.top!==window.self&&(l=H(window.top,"mouseup",w,!1),a=H(window.top,"mousemove",v,!1))}catch(C){Le(!1,`[rc-image] ${C}`)}}return()=>{p==null||p.remove(),f==null||f.remove(),l==null||l.remove(),a==null||a.remove()}},[i,h,()=>n.value.x,()=>n.value.y,()=>n.value.rotate,o]),{isMoving:h,onMouseDown:m,onMouseMove:v,onMouseUp:w,onWheel:x}}function ne(e,o){const i=e.x-o.x,r=e.y-o.y;return Math.hypot(i,r)}function Oe(e,o,i,r){const n=ne(e,i),s=ne(o,r);if(n===0&&s===0)return[e.x,e.y];const u=n/(n+s),h=e.x+u*(o.x-e.x),y=e.y+u*(o.y-e.y);return[h,y]}function Ae(e,o,i,r,n,s,u){const[h,y]=j.useState(!1),d=t.ref({point1:{x:0,y:0},point2:{x:0,y:0},eventType:"none"}),m=l=>{d.value={...d.value,...l}},v=l=>{if(!o.value)return;l.stopPropagation(),y(!0);const{touches:a=[]}=l;a.length>1?m({point1:{x:a[0].clientX,y:a[0].clientY},point2:{x:a[1].clientX,y:a[1].clientY},eventType:"touchZoom"}):m({point1:{x:a[0].clientX-n.value.x,y:a[0].clientY-n.value.y},eventType:"move"})},w=l=>{const{touches:a=[]}=l,{point1:p,point2:f,eventType:C}=d.value;if(a.length>1&&C==="touchZoom"){const b={x:a[0].clientX,y:a[0].clientY},z={x:a[1].clientX,y:a[1].clientY},[R,M]=Oe(p,f,b,z),N=ne(b,z)/ne(p,f);u(N,"touchZoom",R,M,!0),m({point1:b,point2:z,eventType:"touchZoom"})}else C==="move"&&(s({x:a[0].clientX-p.x,y:a[0].clientY-p.y},"move"),m({eventType:"move"}))},x=()=>{if(!i.value)return;if(h&&y(!1),m({eventType:"none"}),r.value>n.value.scale)return s({x:0,y:0,scale:r.value},"touchZoom");const l=e.value.offsetWidth*n.value.scale,a=e.value.offsetHeight*n.value.scale,{left:p,top:f}=e.value.getBoundingClientRect(),C=n.value.rotate%180!==0,b=ye(C?a:l,C?l:a,p,f);b&&s({...b},"dragRebound")};return j.useEffect(()=>{let l;return i.value&&o.value&&(l=H(window,"touchmove",a=>a.preventDefault(),{passive:!1})),()=>{l==null||l.remove()}},[i,o]),{isTouching:h,onTouchStart:v,onTouchMove:w,onTouchEnd:x}}const q={infinite:{type:Boolean,default:!0},zIndex:{type:Number,default:2e3},current:{type:Number,default:0},getContainer:{type:String}},re={preview:{type:[Object,Boolean],default:!0},src:{type:String,default:""},alt:{type:String,default:""},loading:{type:String},fit:{type:String,default:"contain"},crossorigin:{type:String},lazy:Boolean,scrollContainer:{type:[String,Object]},placeholder:{type:[Function,Object,Boolean],default:()=>{}},fallback:{type:[Function,Object],default:()=>{}},onLoad:{type:Function},onError:{type:Function},onClick:{type:Function},wrapperStyle:{type:Object,default:()=>({})},wrapperClass:String,width:Number,height:Number,zIndex:q.zIndex,getContainer:q.getContainer},K={urls:{type:Array,default:()=>[]},open:{type:Boolean,default:!1},scaleStep:{type:Number,default:.5},minScale:{type:Number,default:.32},maxScale:{type:Number,default:32},movable:{type:Boolean,default:!0},disabled:Boolean,zIndex:q.zIndex,current:q.current,infinite:q.infinite,getContainer:re.getContainer,onHideOnClickModal:{type:Boolean,default:!0},countRender:[Function,Array,Object],icons:{type:Object,default:()=>({})},onTransform:Function,onOpenChange:Function,"onUpdate:open":Function},Ee=t.defineComponent({name:"Operations",inheritAttrs:!1,props:{open:Boolean,count:{type:Number,default:0},current:{type:Number,default:0},showSwitch:Boolean,showProgress:Boolean,prefixCls:String,hashId:String,zIndex:K.zIndex,icons:K.icons,infinite:K.infinite,getContainer:K.getContainer,countRender:K.countRender,tools:Array,onClose:Function,onActive:Function},setup(e){const o=(i,r)=>{var n;i.preventDefault(),i.stopPropagation(),(n=e.onActive)==null||n.call(e,r)};return()=>{const{prefixCls:i,hashId:r,tools:n}=e,s=L.getTransitionProps(`${e.prefixCls}-fade`),u=`${i}-operations-operation`,h=`${i}-operations-icon`;return t.createVNode(t.Teleport,{to:e.getContainer||"body"},{default:()=>[t.createVNode(t.Transition,s,{default:()=>{var y,d,m,v;return[t.withDirectives(t.createVNode("div",{class:S.classNames(`${i}-operations-wrapper`,r),style:{zIndex:e.zIndex}},[((y=e.icons)==null?void 0:y.close)===null?null:t.createVNode("button",{class:`${i}-close ${r}`,onClick:e.onClose},[((d=e.icons)==null?void 0:d.close)||t.createVNode(V.CloseOutlined,null,null)]),e.showSwitch&&t.createVNode(t.Fragment,null,[t.createVNode("div",{class:S.classNames(`${i}-switch-left ${r}`,{[`${i}-switch-left-disabled`]:e.infinite?!1:e.current===0}),onClick:w=>o(w,-1)},[((m=e.icons)==null?void 0:m.left)||t.createVNode(V.LeftOutlined,null,null)]),t.createVNode("div",{class:S.classNames(`${i}-switch-right ${r}`,{[`${i}-switch-right-disabled`]:e.infinite?!1:e.current===e.count-1}),onClick:w=>o(w,1)},[((v=e.icons)==null?void 0:v.right)||t.createVNode(V.RightOutlined,null,null)])]),t.createVNode("div",{class:`${i}-footer ${r}`},[e.showProgress&&t.createVNode("div",{class:`${i}-progress`},[e.countRender?e.countRender(e.current+1,e.count):`${e.current+1} / ${e.count}`]),t.createVNode("div",{class:`${e.prefixCls}-operations`},[n==null?void 0:n.map(({icon:w,onClick:x,type:l,disabled:a})=>t.createVNode("div",{class:S.classNames(u,{[`${e.prefixCls}-operations-operation-disabled`]:a&&(a==null?void 0:a.value)}),onClick:x,key:l},[t.cloneVNode(w,{class:h})]))])])]),[[t.vShow,e.open]])]}})]})}}}),Re=new L.Keyframe("viewFadeIn",{"0%":{opacity:0},"100%":{opacity:1}}),De=new L.Keyframe("viewFadeOut",{"0%":{opacity:1},"100%":{opacity:0}}),Pe=new L.Keyframe("viewZoomBadgeIn",{"0%":{transform:"scale(0)",opacity:0},"100%":{transform:"scale(1)",opacity:1}}),Ve=new L.Keyframe("viewZoomBadgeOut",{"0%":{transform:"scale(1)"},"100%":{transform:"scale(0)",opacity:0}}),Se=e=>({position:e||"absolute",inset:0});function ce(e){return{position:e,top:0,insetInlineEnd:0,bottom:0,insetInlineStart:0}}const je=e=>{const{previewCls:o,modalMaskBg:i,marginXL:r,margin:n,colorTextLightSolid:s,previewOperationColorDisabled:u,previewOperationHoverColor:h,motionDurationSlow:y,iconCls:d}=e,m=new W.TinyColor(i).setAlpha(.1),v=m.clone().setAlpha(.2),w=new W.TinyColor(i).setAlpha(.06);return{[`${o}-footer`]:{position:"fixed",bottom:r,left:{_skip_check_:!0,value:"50%"},display:"flex",flexDirection:"column",alignItems:"center",color:e.previewOperationColor,transform:"translateX(-50%)"},[`${o}-progress`]:{marginBottom:n},[`${o}-close`]:{position:"fixed",top:r,right:{_skip_check_:!0,value:r},display:"flex",alignItems:"center",justifyContent:"center",color:s,backgroundColor:m.toRgbString(),borderRadius:e.borderRadiusLG,backdropFilter:"saturate(180%) blur(10px)",width:e.sizeXL,height:e.sizeXL,outline:0,border:0,cursor:"pointer",transition:`all ${y}`,"&:hover":{backgroundColor:v.toRgbString()},[`& > ${d}`]:{fontSize:e.previewOperationSize}},[`${o}-operations`]:{display:"flex",alignItems:"center",gap:e.sizeXXS,padding:e.paddingXXS,backgroundColor:m.toRgbString(),borderRadius:e.borderRadiusLG,backdropFilter:"saturate(180%) blur(10px)","&-operation":{display:"flex",alignItems:"center",justifyContent:"center",width:e.sizeXL+4,height:e.sizeXL+4,cursor:"pointer",color:s,borderRadius:e.borderRadiusSM,transition:`all ${y}`,userSelect:"none",[`&:not(${o}-operations-operation-disabled):hover > ${d}`]:{color:h},"&:hover":{backgroundColor:w.toRgbString()},"&-disabled":{color:u,cursor:"not-allowed"},"&:first-of-type":{marginInlineStart:0},[`& > ${d}`]:{fontSize:e.previewOperationSize}}}}},Xe=e=>{const{modalMaskBg:o,iconCls:i,previewOperationColorDisabled:r,previewCls:n,zIndexPopup:s,motionDurationSlow:u,colorTextLightSolid:h}=e,y=new W.TinyColor(o).setAlpha(.1),d=y.clone().setAlpha(.2);return{[`${n}-switch-left, ${n}-switch-right`]:{position:"fixed",insetBlockStart:"50%",zIndex:e.calc(s).add(1).equal(),display:"flex",alignItems:"center",justifyContent:"center",borderRadius:e.borderRadius,backdropFilter:"saturate(180%) blur(10px)",width:e.imagePreviewSwitchSize,height:e.imagePreviewSwitchSize,marginTop:e.calc(e.imagePreviewSwitchSize).mul(-1).div(2).equal(),color:h,background:y.toRgbString(),transform:"translateY(-50%)",cursor:"pointer",transition:`all ${u}`,userSelect:"none","&:hover":{background:d.toRgbString()},"&-disabled":{"&, &:hover":{color:r,background:"transparent",cursor:"not-allowed",[`> ${i}`]:{cursor:"not-allowed"}}},[`> ${i}`]:{fontSize:e.previewOperationSize}},[`${n}-switch-left`]:{insetInlineStart:e.marginSM},[`${n}-switch-right`]:{insetInlineEnd:e.marginSM}}},Ye=e=>{const{motionEaseOut:o,motionDurationSlow:i}=e;return{[e.componentCls]:{height:"100%",textAlign:"center",pointerEvents:"none","&-root":{...ce("fixed"),zIndex:e.zIndexPopup,overflow:"auto",outline:0,WebkitOverflowScrolling:"touch"},"&-wrap":{...ce("fixed"),zIndex:e.zIndexPopup,overflow:"auto",outline:0,WebkitOverflowScrolling:"touch"},"&-mask":{...ce("fixed"),zIndex:e.zIndexPopupBase,height:"100%",backgroundColor:e.colorBgMask,backdropFilter:"blur(2px)"},"&-body":{...Se(),overflow:"hidden"},"&-img":{maxWidth:"100%",maxHeight:"70%",verticalAlign:"middle",transform:"scale3d(1, 1, 1)",cursor:"grab",transition:`transform ${i} ${o} 0s`,userSelect:"none","&-wrapper":{...Se(),transition:`transform ${i} ${o} 0s`,display:"flex",justifyContent:"center",alignItems:"center","& > *":{pointerEvents:"auto"},"&::before":{display:"inline-block",width:1,height:"50%",marginInlineEnd:-1,content:'""'}}},"&-moving":{[`${e.componentCls}-view-img`]:{cursor:"grabbing","&-wrapper":{transitionDuration:"0s"}}},"&-mask-zoom-appear, &-mask-zoom-enter":{animationName:Re,animationDuration:e.motionDurationSlow,animationTimingFunction:"linear",userSelect:"none"},"&-mask-zoom-leave":{animationName:De,animationDuration:e.motionDurationSlow,animationTimingFunction:"linear",pointerEvents:"none"},"&-zoom-appear, &-zoom-enter":{animationName:Pe,opacity:0,animationTimingFunction:e.motionEaseOutCirc,animationFillMode:"both",transform:"none",animationDuration:e.motionDurationMid,userSelect:"none"},"&-zoom-enter-active":{animationPlayState:"running"},"&-zoom-leave":{animationName:Ve,animationDuration:e.motionDurationSlow,animationTimingFunction:e.motionEaseInOutCirc,animationFillMode:"both"}},[`${e.componentCls}-root`]:{[`${e.componentCls}-wrapper`]:{zIndex:e.zIndexPopup}},[`${e.componentCls}-operations-wrapper`]:{position:"fixed",insetBlockStart:0,insetInlineEnd:0,zIndex:e.calc(e.zIndexPopup).add(1).equal(),width:"100%"},"&":[je(e),Xe(e)]}};function Fe(e){return L.useStyle("ImageViewer",o=>{const i=L.mergeToken(o,{zIndexPopup:o.zIndexPopupBase+80,previewOperationColor:new W.TinyColor(o.colorTextLightSolid).setAlpha(.65).toRgbString(),previewOperationHoverColor:new W.TinyColor(o.colorTextLightSolid).setAlpha(.85).toRgbString(),previewOperationColorDisabled:new W.TinyColor(o.colorTextLightSolid).setAlpha(.25).toRgbString(),imagePreviewSwitchSize:o.sizeXL,modalMaskBg:new W.TinyColor("#000").setAlpha(.45).toRgbString(),previewOperationSize:o.fontSizeIcon*1.5,iconCls:".anticon",previewCls:o.componentCls});return[Ye(i)]},e)}const se={ESC:27,LEFT:37,RIGHT:39},Q={rotateLeft:t.createVNode(V.RotateLeftOutlined,null,null),rotateRight:t.createVNode(V.RotateRightOutlined,null,null),zoomIn:t.createVNode(V.ZoomInOutlined,null,null),zoomOut:t.createVNode(V.ZoomOutOutlined,null,null),flipX:t.createVNode(V.SwapOutlined,null,null),flipY:t.createVNode(V.SwapOutlined,{rotate:90},null)},Ce=["close","left","right","rotateRight","rotateRight","zoomOut","flipX","flipY","rotateLeft"],xe=t.defineComponent({name:"GImagePreview",props:K,inheritAttrs:!1,slots:Object,emits:{close:()=>!0,transform:e=>!0,"update:open":e=>!0},setup:(e,{emit:o,expose:i,slots:r})=>{const n=S.getPrefixCls({suffixCls:"image-view"}),{wrapSSR:s,hashId:u}=Fe(n),[h,y,d]=j.useMergedState(e.open,{value:t.toRef(e,"open"),onChange:c=>{var $;($=e.onOpenChange)==null||$.call(e,c),o("update:open",c)}}),[m,v]=j.useState(!1),[w,x]=j.useState(!0),l=t.ref(),{transform:a,resetTransform:p,updateTransform:f,dispatchZoomChange:C}=$e(l,t.toRef(e,"minScale"),t.toRef(e,"maxScale"),e.onTransform),{isMoving:b,onMouseDown:z,onWheel:R}=Te(l,t.toRef(e,"movable"),d,t.toRef(e,"scaleStep"),a,f,C),{isTouching:M,onTouchStart:N,onTouchMove:_,onTouchEnd:U}=Ae(l,t.toRef(e,"movable"),d,t.toRef(e,"minScale"),a,f,C);j.useEffect(()=>{w.value||x(!0)},[w]);const X=t.ref(null),T=t.ref(e.current),Y=t.reactive(new Map),F=t.computed(()=>new Map(Array.from(Y).map(([c,{url:$}])=>[c,$]))),ee=t.computed(()=>F.value.get(T.value)),B=t.computed(()=>F.value.size),Z=t.computed(()=>Array.from(F.value.keys())),D=t.computed(()=>Z.value.indexOf(T.value)),g=t.computed(()=>B.value>1),O=t.computed(()=>B.value>=1);t.watch(d,c=>{c&&(m.value=!0)});const A=c=>{T.value=c};t.watch(()=>e.current,c=>{S.isNumber(c)&&A(c)});function ie(c,$){Y.set(c,{url:$,loading:!0,canPreview:!1})}const ue=()=>{v(!1)},He=()=>{p("close"),o("close")},Ge=c=>{b.value||X.value===(c==null?void 0:c.target)&&ue()},qe=()=>{const c=Y.get(T.value);c&&(c.loading=!1,c.canPreview=!0)},Ke=c=>{const $=Y.get(T.value);$&&($.loading=!1,$.canPreview=!1),c.target.alt="加载失败"},be=()=>{if(D.value>0||e.infinite){const c=D.value-1<0?e.urls.length-1:D.value-1;A(Z.value[c]),p("prev")}},Ne=()=>{if(D.value<B.value-1||e.infinite){const c=D.value+1>e.urls.length-1?0:D.value+1;A(Z.value[c]),p("next")}},Qe=()=>{C(G+e.scaleStep,"zoomIn")},Je=()=>{C(G/(G+e.scaleStep),"zoomOut")},Ue=()=>{f({rotate:a.value.rotate+90},"rotateRight")},et=()=>{f({rotate:a.value.rotate-90},"rotateLeft")},tt=()=>{f({flipX:!a.value.flipX},"flipX")},nt=()=>{f({flipY:!a.value.flipY},"flipY")},ze=[{icon:S.getSlotVNode(r,e.icons,"flipY")||Q.flipY,onClick:nt,type:"flipY"},{icon:S.getSlotVNode(r,e.icons,"flipX")||Q.flipX,onClick:tt,type:"flipX"},{icon:S.getSlotVNode(r,e.icons,"rotateLeft")||Q.rotateLeft,onClick:et,type:"rotateLeft"},{icon:S.getSlotVNode(r,e.icons,"rotateRight")||Q.rotateRight,onClick:Ue,type:"rotateRight"},{icon:S.getSlotVNode(r,e.icons,"zoomOut")||Q.zoomOut,onClick:()=>Je(),type:"zoomOut",disabled:t.computed(()=>a.value.scale<=e.minScale)},{icon:S.getSlotVNode(r,e.icons,"zoomIn")||Q.zoomIn,onClick:()=>Qe(),type:"zoomIn",disabled:t.computed(()=>a.value.scale===e.maxScale)}],ot=c=>{d.value&&(a.value.scale!==1?f({x:0,y:0,scale:1},"doubleClick"):C(G+e.scaleStep,"doubleClick",c.clientX,c.clientY))},it=c=>{c.keyCode===se.ESC&&ue(),!(!d.value||!g.value)&&(c.keyCode===se.LEFT?be():c.keyCode===se.RIGHT&&Ne())};let de=()=>{};return t.onMounted(()=>{t.watch(()=>e.urls,c=>{S.isArray(c)&&c.forEach(($,ae)=>{ie(ae,$)})},{flush:"post",immediate:!0}),t.watch([()=>d.value,()=>b.value],()=>{de();const c=H(window,"keydown",it,!1);de=()=>{c.remove()}},{flush:"post",immediate:!0})}),t.onUnmounted(()=>{de()}),i({setOpen:c=>{y(c),T.value=e.current}}),()=>{const c=L.getTransitionProps(`${n}-mask-zoom`),$=L.getTransitionProps(`${n}-zoom`),ae={};for(const P in e.icons)ae[P]=S.getSlotVNode(r,e.icons,P);return s(t.createVNode(t.Fragment,null,[t.createVNode(t.Teleport,{to:e.getContainer||"body"},{default:()=>[d.value&&t.createVNode(t.Fragment,null,[t.createVNode("div",{class:`${n}-root ${u.value}`},[t.createVNode(t.Transition,c,{default:()=>[t.withDirectives(t.createVNode("div",{class:`${n}-mask ${u.value}`},null),[[t.vShow,d.value&&m.value]])]}),t.createVNode("div",{ref:X,tabindex:-1,class:[`${n}-wrap`,`${u.value}`,b.value&&`${n}-moving`],onClick:P=>e.onHideOnClickModal&&Ge(P)},[t.createVNode(t.Transition,t.mergeProps($,{onAfterLeave:()=>He()}),{default:()=>[t.withDirectives(t.createVNode("div",{role:"dialog",class:`${n} ${u.value}`},[t.createVNode("div",{class:`${n}-content ${u.value}`},[t.createVNode("div",{class:`${n}-body ${u.value}`},[t.createVNode("div",{class:`${n}-img-wrapper ${u.value}`},[t.createVNode("img",{ref:l,class:`${n}-img ${u.value}`,src:ee.value,onLoad:()=>qe(),onError:P=>Ke(P),style:{transform:`translate3d(${a.value.x}px, ${a.value.y}px, 0) scale3d(${a.value.flipX?"-":""}${a.value.scale}, ${a.value.flipY?"-":""}${a.value.scale}, 1) rotate(${a.value.rotate}deg)`,transitionDuration:!w.value||M.value?"0s":void 0},onWheel:R,onMousedown:z,onDblclick:ot,onTouchstart:N,onTouchmove:_,onTouchend:U,onTouchcancel:U},null)])])])]),[[t.vShow,d.value&&m.value]])]})])])])]}),d.value&&m.value&&t.createVNode(Ee,{open:d.value&&m.value,hashId:u.value,count:e.urls.length,current:T.value,zIndex:e.zIndex+1,getContainer:e.getContainer,prefixCls:n,icons:k.omit(ae,ze.map(({type:P})=>P)),tools:ze,infinite:e.infinite,countRender:S.getSlot(r,e,"countRenders"),showSwitch:g.value,showProgress:O.value,onClose:ue,onActive:P=>P>0?Ne():be()},null)]))}}}),oe={width:"100%",height:"100%"},Be=()=>({position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",opacity:0}),Ze=e=>({position:e||"absolute",inset:0}),We=e=>({[e.componentCls]:{display:"inline-block",position:"relative",overflow:"hidden","&-inner":{...oe,verticalAlign:"top",opacity:1,[`&${e.componentCls}-inner-preview`]:{userSelect:"none",cursor:"pointer"}},"&-wrapper":{...oe,...Ze()},"&-placeholder":{...oe,backgroundColor:e.colorBgContainerDisabled,backgroundImage:"url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNMTQuNSAyLjVoLTEzQS41LjUgMCAwIDAgMSAzdjEwYS41LjUgMCAwIDAgLjUuNWgxM2EuNS41IDAgMCAwIC41LS41VjNhLjUuNSAwIDAgMC0uNS0uNXpNNS4yODEgNC43NWExIDEgMCAwIDEgMCAyIDEgMSAwIDAgMSAwLTJ6bTguMDMgNi44M2EuMTI3LjEyNyAwIDAgMS0uMDgxLjAzSDIuNzY5YS4xMjUuMTI1IDAgMCAxLS4wOTYtLjIwN2wyLjY2MS0zLjE1NmEuMTI2LjEyNiAwIDAgMSAuMTc3LS4wMTZsLjAxNi4wMTZMNy4wOCAxMC4wOWwyLjQ3LTIuOTNhLjEyNi4xMjYgMCAwIDEgLjE3Ny0uMDE2bC4wMTUuMDE2IDMuNTg4IDQuMjQ0YS4xMjcuMTI3IDAgMCAxLS4wMi4xNzV6IiBmaWxsPSIjOEM4QzhDIiBmaWxsLXJ1bGU9Im5vbnplcm8iLz48L3N2Zz4=')",backgroundRepeat:"no-repeat",backgroundPosition:"center center",backgroundSize:"30%"},"&-error":{...oe,display:"flex",alignItems:"center",justifyContent:"center",color:e.colorText,backgroundColor:e.colorBgContainerDisabled},"&-preview":Be()}}),_e=e=>typeof Element>"u"?!1:e instanceof Element;let Ie="";const ke=[...Ce,"fallback","placeholder"],J=t.defineComponent({props:re,name:"GImage",inheritAttrs:!1,emits:{click:()=>!0,load:e=>!0,error:e=>!0},slots:Object,setup(e,{slots:o,emit:i,attrs:r}){const n=E.isClient&&"loading"in HTMLImageElement.prototype,s=S.getPrefixCls({suffixCls:"image"}),{wrapSSR:u,hashId:h}=L.useProStyle("Image",[We],s),y=t.ref(),d=t.ref(),m=t.ref(!1),v=t.ref(!0),w=t.ref(!1),x=t.ref(),l=t.ref();let a,p;const f=t.computed(()=>e.loading==="eager"?!1:!n&&e.loading==="lazy"||e.lazy),C=t.computed(()=>E.isClient&&e.fit?{objectFit:e.fit}:{}),b=t.computed(()=>typeof e.preview=="object"?e.preview:{}),z=t.computed(()=>!!e.preview),R=t.computed(()=>{const{urls:g=[],current:O=0}=b.value;if(S.isNumber(O))return g.length>=O?O:0;const A=g.indexOf(e.src);return A>=0?A:0}),M=t.computed(()=>L.unit(e.width)),N=t.computed(()=>L.unit(e.height)),_=()=>{E.isClient&&(v.value=!0,m.value=!1,d.value=e.src)};function U(g){v.value=!1,m.value=!1,i("load",g)}function X(g){v.value=!1,m.value=!0,i("error",g)}function T(){S.isInContainer(x.value,l.value)&&(_(),ee())}const Y=E.useThrottleFn(T,200,!0);async function F(){if(!E.isClient)return;await t.nextTick();const{scrollContainer:g}=e;_e(g)?l.value=g:S.isString(g)&&g!==""?l.value=document.querySelector(g)??void 0:x.value&&(l.value=S.getScrollContainer(x.value)),l.value&&(a=E.useEventListener(l,"scroll",Y),setTimeout(()=>T(),100))}function ee(){!E.isClient||!l.value||!Y||(a==null||a(),l.value=void 0)}function B(g){if(g.ctrlKey){if(g.deltaY<0)return g.preventDefault(),!1;if(g.deltaY>0)return g.preventDefault(),!1}}const Z=()=>{i("click"),!(v.value||m.value)&&z.value&&(p=E.useEventListener("wheel",B,{passive:!1}),Ie=document.body.style.overflow,document.body.style.overflow="hidden",w.value=!0)},D=()=>{p==null||p(),document.body.style.overflow=Ie,w.value=!1};return t.watch(()=>e.src,()=>{f.value?(v.value=!0,m.value=!1,ee(),F()):_()}),t.watchEffect(()=>{var g,O;z.value&&w.value?(g=y.value)==null||g.setOpen(!0):(O=y.value)==null||O.setOpen(!1)}),t.onMounted(()=>{f.value?F():_()}),()=>{const g=k.fromPairs(Object.entries(r).filter(([ie])=>/^(?:data-|on[A-Z])/i.test(ie)||["id","style"].includes(ie))),O=k.omit(r,Object.keys(g)),A=S.getSlotsProps(ke,o,e,{render:!0});return u(t.createVNode("div",t.mergeProps({class:{[`${h.value}`]:!0,[`${s}`]:!0,[`${r.class}`]:!!r.class},ref:x},g),[m.value?A.fallback||t.createVNode("div",{"aria-hidden":"true",class:`${s}-error ${h.value}`},[t.createTextVNode("加载失败")]):t.createVNode(t.Fragment,null,[d.value!==void 0&&t.createVNode("img",t.mergeProps(O,{src:d.value,loading:e.loading,style:C.value,class:{[`${h.value}`]:!0,[`${s}-placeholder`]:v.value,[`${s}-inner`]:!0,[`${s}-inner-preview`]:z.value},crossorigin:e.crossorigin,width:M.value,height:N.value,onClick:Z,onLoad:U,onError:X}),null),v.value&&t.createVNode("div",{class:S.classNames(`${s}-wrapper`,h.value)},[A.placeholder||t.createVNode("div",{"aria-hidden":"true",class:`${s}-placeholder ${h.value}`},null)])]),z.value&&t.createVNode(xe,t.mergeProps({ref:y},b.value,k.pick(A,Ce),{urls:b.value.urls||[e.src],current:R.value,onClose:()=>D()}),null)]))}}});J.isGImage=!0,J.install=e=>(e.component(J.name,J),e),I.GImage=J,I.GImagePreview=xe,I.baseProps=q,I.default=J,I.imageProps=re,Object.defineProperties(I,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/props.d.ts
CHANGED
|
@@ -20,11 +20,7 @@ export declare const baseProps: {
|
|
|
20
20
|
};
|
|
21
21
|
export declare const imageProps: {
|
|
22
22
|
preview: {
|
|
23
|
-
type: PropType<BaseImagePreviewProps>;
|
|
24
|
-
default: () => BaseImagePreviewProps;
|
|
25
|
-
};
|
|
26
|
-
showPreview: {
|
|
27
|
-
type: PropType<boolean>;
|
|
23
|
+
type: PropType<BaseImagePreviewProps | boolean>;
|
|
28
24
|
default: boolean;
|
|
29
25
|
};
|
|
30
26
|
src: {
|
|
@@ -35,10 +31,16 @@ export declare const imageProps: {
|
|
|
35
31
|
type: PropType<string>;
|
|
36
32
|
default: string;
|
|
37
33
|
};
|
|
34
|
+
loading: {
|
|
35
|
+
type: PropType<"eager" | "lazy">;
|
|
36
|
+
};
|
|
38
37
|
fit: {
|
|
39
38
|
type: PropType<"fill" | "contain" | "cover" | "none" | "scale-down">;
|
|
40
39
|
default: string;
|
|
41
40
|
};
|
|
41
|
+
crossorigin: {
|
|
42
|
+
type: PropType<"anonymous" | "use-credentials" | "">;
|
|
43
|
+
};
|
|
42
44
|
lazy: PropType<boolean>;
|
|
43
45
|
scrollContainer: {
|
|
44
46
|
type: PropType<string | HTMLElement | undefined>;
|
|
@@ -60,8 +62,11 @@ export declare const imageProps: {
|
|
|
60
62
|
onClick: {
|
|
61
63
|
type: PropType<(info: any) => void>;
|
|
62
64
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
wrapperStyle: {
|
|
66
|
+
type: PropType<CSSProperties>;
|
|
67
|
+
default: () => {};
|
|
68
|
+
};
|
|
69
|
+
wrapperClass: PropType<string>;
|
|
65
70
|
width: PropType<number>;
|
|
66
71
|
height: PropType<number>;
|
|
67
72
|
zIndex: {
|
package/dist/style.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { ProAliasToken } from '@gx-design-vue/pro-provider';
|
|
2
2
|
import type { CSSObject } from 'ant-design-vue';
|
|
3
3
|
import type { GenerateStyle } from 'ant-design-vue/es/theme/internal';
|
|
4
|
+
export type PositionType = 'static' | 'relative' | 'fixed' | 'absolute' | 'sticky' | undefined;
|
|
4
5
|
export declare const genImageMaskStyle: () => CSSObject;
|
|
6
|
+
export declare const genBoxStyle: (position?: PositionType) => CSSObject;
|
|
5
7
|
export declare const genImageStyle: GenerateStyle<ProAliasToken>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isElement: (e: unknown) => e is Element;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gx-design-vue/image",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.0-beta.
|
|
4
|
+
"version": "0.2.0-beta.27",
|
|
5
5
|
"description": "Gx Design Image",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@gx-design-vue/pro-hooks": "^0.2.0-beta.44",
|
|
33
|
-
"@gx-design-vue/pro-provider": "^0.1.0-beta.
|
|
33
|
+
"@gx-design-vue/pro-provider": "^0.1.0-beta.108",
|
|
34
34
|
"@gx-design-vue/pro-utils": "^0.2.0-beta.62",
|
|
35
35
|
"@vueuse/core": "^9.10.0",
|
|
36
36
|
"lodash-es": "^4.17.21"
|