react-photo-view
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -13,2 +13,6 @@ import type React from 'react'; | ||
/** | ||
* 自定义覆盖节点 | ||
*/ | ||
overlay?: React.ReactNode; | ||
/** | ||
* 自定义渲染节点宽度 | ||
@@ -15,0 +19,0 @@ */ |
@@ -1,2 +0,2 @@ | ||
var e=require("react"),t=require("react-dom");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=/*#__PURE__*/n(e);function i(){return i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i.apply(this,arguments)}function o(e,t){if(null==e)return{};var n,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)t.indexOf(n=o[r])>=0||(i[n]=e[n]);return i}function a(t){var n=e.useRef({fn:t,curr:void 0}).current;if(n.fn=t,!n.curr){var r=Object.create(null);Object.keys(t).forEach(function(e){r[e]=function(){var t;return(t=n.fn[e]).call.apply(t,[n.fn].concat([].slice.call(arguments)))}}),n.curr=r}return n.curr}function u(t){return e.useReducer(function(e,t){return i({},e,"function"==typeof t?t(e):t)},t)}var c=e.createContext(void 0),l="undefined"!=typeof window&&"ontouchstart"in window,s=function(e,t,n){return Math.max(Math.min(e,n),t)},d=function(e,t,n){return void 0===t&&(t=0),void 0===n&&(n=0),s(e,1*(1-n),Math.max(6,t)*(1+n))},f="undefined"==typeof window||/ServerSideRendering/.test(navigator&&navigator.userAgent)?e.useEffect:e.useLayoutEffect;function v(t,n,r){var i=e.useRef(n);i.current=n,e.useEffect(function(){function e(e){i.current(e)}return t&&window.addEventListener(t,e,r),function(){t&&window.removeEventListener(t,e)}},[t])}var h=function(e){return t.createPortal(r.default.createElement("div",i({},e)),document.body)};function m(e){return r.default.createElement("svg",i({width:"44",height:"44",viewBox:"0 0 768 768"},e),r.default.createElement("path",{d:"M607.5 205.5l-178.5 178.5 178.5 178.5-45 45-178.5-178.5-178.5 178.5-45-45 178.5-178.5-178.5-178.5 45-45 178.5 178.5 178.5-178.5z"}))}function g(e){return r.default.createElement("svg",i({width:"44",height:"44",viewBox:"0 0 768 768"},e),r.default.createElement("path",{d:"M640.5 352.5v63h-390l178.5 180-45 45-256.5-256.5 256.5-256.5 45 45-178.5 180h390z"}))}function p(e){return r.default.createElement("svg",i({width:"44",height:"44",viewBox:"0 0 768 768"},e),r.default.createElement("path",{d:"M384 127.5l256.5 256.5-256.5 256.5-45-45 178.5-180h-390v-63h390l-178.5-180z"}))}function w(){return e.useEffect(function(){var e=document.body.style,t=e.overflow;return e.overflow="hidden",function(){e.overflow=t}},[]),null}function y(e){var t=e.touches[0],n=t.clientX,r=t.clientY;if(e.touches.length>=2){var i=e.touches[1],o=i.clientX,a=i.clientY;return[(n+o)/2,(r+a)/2,Math.sqrt(Math.pow(o-n,2)+Math.pow(a-r,2))]}return[n,r,0]}var x=function(e,t,n,r){var i=n*t,o=(i-r)/2,a=void 0,u=e;return i<=r?(a=1,u=0):e>0&&o-e<=0?(a=2,u=o):e<0&&o+e<=0&&(a=3,u=-o),[a,u]};function C(e,t,n,r,i,o,a,u,c,l){void 0===a&&(a=innerWidth/2),void 0===u&&(u=innerHeight/2),void 0===c&&(c=0),void 0===l&&(l=0);var s=x(e,o,n,innerWidth)[0],d=x(t,o,r,innerHeight),f=innerWidth/2,v=innerHeight/2;return{x:a-o/i*(a-(f+e))-f+(r/n>=3&&n*o===innerWidth?0:s?c/2:c),y:u-o/i*(u-(v+t))-v+(d[0]?l/2:l),lastCX:a,lastCY:u}}function E(e,t,n){var r=e%180!=0;return r?[n,t,r]:[t,n,r]}function b(e,t,n){var r=E(n,innerWidth,innerHeight),i=r[0],o=r[1],a=0,u=i,c=o,l=e/t*o,s=t/e*i;return e<i&&t<o?(u=e,c=t):e<i&&t>=o?u=l:e>=i&&t<o||e/t>i/o?c=s:t/e>=3&&!r[2]?a=((c=s)-o)/2:u=l,{width:u,height:c,x:0,y:a,pause:!0}}function k(t,n){var r=n.leading,i=void 0!==r&&r,o=n.maxWait,a=n.wait,u=void 0===a?o||0:a,c=e.useRef(t);c.current=t;var l=e.useRef(0),s=e.useRef(),d=function(){return s.current&&clearTimeout(s.current)},f=e.useCallback(function(){var e=[].slice.call(arguments),t=Date.now();function n(){l.current=t,d(),c.current.apply(null,e)}var r=l.current,a=t-r;if(0===r&&(i&&n(),l.current=t),void 0!==o){if(a>o)return void n()}else a<u&&(l.current=t);d(),s.current=setTimeout(function(){n(),l.current=0},u)},[u,o,i]);return f.cancel=d,f}var P=function(e,t,n){return R(e,t,n,100,function(e){return e},function(){return R(t,e,n)})},M=function(e){return 1-Math.pow(1-e,4)};function R(e,t,n,r,i,o){void 0===r&&(r=400),void 0===i&&(i=M);var a=t-e;if(0!==a){var u=Date.now(),c=0,l=function(){var t=Math.min(1,(Date.now()-u)/r);n(e+i(t)*a)&&t<1?s():(cancelAnimationFrame(c),t>=1&&o&&o())};s()}function s(){c=requestAnimationFrame(l)}}var _={T:0,L:0,W:0,H:0,FIT:void 0},Y=function(){var t=e.useRef(!1);return e.useEffect(function(){return t.current=!0,function(){t.current=!1}},[]),t},X=["className"];function N(e){var t=e.className,n=o(e,X);return r.default.createElement("div",i({className:"PhotoView__Spinner "+t},n),r.default.createElement("svg",{viewBox:"0 0 32 32",width:"36",height:"36",fill:"white"},r.default.createElement("path",{opacity:".25",d:"M16 0 A16 16 0 0 0 16 32 A16 16 0 0 0 16 0 M16 4 A12 12 0 0 1 16 28 A12 12 0 0 1 16 4"}),r.default.createElement("path",{d:"M16 0 A16 16 0 0 1 32 16 L28 16 A12 12 0 0 0 16 4z"})))}var S=["src","loaded","broken","className","onPhotoLoad","loadingElement","brokenElement"];function W(e){var t=e.src,n=e.loaded,a=e.broken,u=e.className,c=e.onPhotoLoad,l=e.loadingElement,s=e.brokenElement,d=o(e,S),f=Y();return t&&!a?r.default.createElement(r.default.Fragment,null,r.default.createElement("img",i({className:"PhotoView__Photo"+(u?" "+u:""),src:t,onLoad:function(e){var t=e.target;f.current&&c({loaded:!0,naturalWidth:t.naturalWidth,naturalHeight:t.naturalHeight})},onError:function(){f.current&&c({broken:!0})},alt:""},d)),!n&&(r.default.createElement("span",{className:"PhotoView__icon"},l)||r.default.createElement(N,{className:"PhotoView__icon"}))):s?r.default.createElement("span",{className:"PhotoView__icon"},"function"==typeof s?s({src:t}):s):null}var T={naturalWidth:void 0,naturalHeight:void 0,width:void 0,height:void 0,loaded:void 0,broken:!1,x:0,y:0,touched:!1,maskTouched:!1,rotate:0,scale:1,CX:0,CY:0,lastX:0,lastY:0,lastCX:0,lastCY:0,lastScale:1,touchTime:0,touchLength:0,pause:!0,stopRaf:!0,reach:void 0};function V(t){var n=t.item,o=n.src,c=n.render,s=n.width,h=void 0===s?0:s,m=n.height,g=void 0===m?0:m,p=n.originRef,w=t.visible,M=t.speed,X=t.easing,N=t.wrapClassName,S=t.className,V=t.style,A=t.loadingElement,I=t.brokenElement,L=t.onPhotoTap,H=t.onMaskTap,F=t.onReachMove,D=t.onReachUp,O=t.onPhotoResize,B=t.isActive,j=t.expose,z=u(T),q=z[0],K=z[1],U=e.useRef(0),G=Y(),J=q.naturalWidth,Q=void 0===J?h:J,Z=q.naturalHeight,$=void 0===Z?g:Z,ee=q.width,te=void 0===ee?h:ee,ne=q.height,re=void 0===ne?g:ne,ie=q.loaded,oe=void 0===ie?!o:ie,ae=q.broken,ue=q.x,ce=q.y,le=q.touched,se=q.stopRaf,de=q.maskTouched,fe=q.rotate,ve=q.scale,he=q.CX,me=q.CY,ge=q.lastX,pe=q.lastY,we=q.lastCX,ye=q.lastCY,xe=q.lastScale,Ce=q.touchTime,Ee=q.touchLength,be=q.pause,ke=q.reach,Pe=a({onScale:function(e){return Me(d(e))},onRotate:function(e){fe!==e&&(j({rotate:e}),K(i({rotate:e},b(Q,$,e))))}});function Me(e,t,n){ve!==e&&(j({scale:e}),K(i({scale:e},C(ue,ce,te,re,ve,e,t,n),e<=1&&{x:0,y:0})))}var Re=k(function(e,t,n){if(void 0===n&&(n=0),(le||de)&&B){var r=E(fe,te,re),o=r[0],a=r[1];if(0===n&&0===U.current){var u=Math.abs(e-he)<=20,c=Math.abs(t-me)<=20;if(u&&c)return void K({lastCX:e,lastCY:t});U.current=u?t>me?3:2:1}var l=e-we,s=t-ye,f=void 0;if(0===n){var v=x(l+ge,ve,o,innerWidth)[0],h=x(s+pe,ve,a,innerHeight);f=function(e,t,n,r){return t&&1===e||"x"===r?"x":n&&e>1||"y"===r?"y":void 0}(U.current,v,h[0],ke),void 0!==f&&F(f,e,t,ve)}if("x"===f||de)return void K({reach:"x"});var m=d(ve+(n-Ee)/100/2*ve,Q/te,.2);j({scale:m}),K(i({touchLength:n,reach:f,scale:m},C(ue,ce,te,re,ve,m,e,t,l,s)))}},{maxWait:8});function _e(e){return!se&&!le&&(G.current&&K(i({},e,{pause:w})),G.current)}var Ye,Xe,Ne,Se,We,Te,Ve,Ae,Ie=(We=function(e){return _e({x:e})},Te=function(e){return _e({y:e})},Ve=function(e){return G.current&&(j({scale:e}),K({scale:e})),!le&&G.current},Ae=a({X:function(e){return We(e)},Y:function(e){return Te(e)},S:function(e){return Ve(e)}}),function(e,t,n,r,i,o,a,u,c,l,s){var d=E(l,i,o),f=d[0],v=d[1],h=x(e,u,f,innerWidth),m=h[0],g=h[1],p=x(t,u,v,innerHeight),w=p[0],y=p[1],b=Date.now()-s;if(b>=200||u!=a||Math.abs(c-a)>1){var k=C(e,t,i,o,a,u),M=k.x,_=k.y,Y=m?g:M!==e?M:null,X=w?y:_!==t?_:null;return null!==Y&&R(e,Y,Ae.X),null!==X&&R(t,X,Ae.Y),void(u!=a&&R(a,u,Ae.S))}var N=(e-n)/b,S=(t-r)/b,W=Math.sqrt(Math.pow(N,2)+Math.pow(S,2)),T=!1,V=!1;!function(e,t){var n=e,r=0,i=void 0,o=0,a=function(o){i||(i=o);var a=o-i,l=Math.sign(e),s=-.001*l,d=Math.sign(-n)*Math.pow(n,2)*2e-4,f=n*a+(s+d)*Math.pow(a,2)/2;r+=f,i=o,l*(n+=(s+d)*a)<=0?c():t(r)?u():c()};function u(){o=requestAnimationFrame(a)}function c(){cancelAnimationFrame(o)}u()}(W,function(n){var r=e+n*(N/W),i=t+n*(S/W),o=x(r,a,f,innerWidth),u=o[0],c=o[1],l=x(i,a,v,innerHeight),s=l[0],d=l[1];if(u&&!T&&(T=!0,m?R(r,c,Ae.X):P(c,r+(r-c),Ae.X)),s&&!V&&(V=!0,w?R(i,d,Ae.Y):P(d,i+(i-d),Ae.Y)),T&&V)return!1;var h=T||Ae.X(c),g=V||Ae.Y(d);return h&&g})}),Le=(Ye=L,Xe=function(e,t){ke||Me(1!==ve?1:Math.max(2,Q/te),e,t)},Ne=e.useRef(0),Se=k(function(){Ne.current=0,Ye.apply(void 0,[].slice.call(arguments))},{wait:300}),function(){var e=[].slice.call(arguments);Ne.current+=1,Se.apply(void 0,e),Ne.current>=2&&(Se.cancel(),Ne.current=0,Xe.apply(void 0,e))});function He(e,t){if(U.current=0,(le||de)&&B){K({touched:!1,maskTouched:!1,pause:!1,stopRaf:!1,reach:void 0});var n=d(ve,Q/te);if(Ie(ue,ce,ge,pe,te,re,ve,n,xe,fe,Ce),D(e,t),he===e&&me===t){if(le)return void Le(e,t);de&&H(e,t)}}}function Fe(e,t,n){void 0===n&&(n=0),K({touched:!0,CX:e,CY:t,lastCX:e,lastCY:t,lastX:ue,lastY:ce,lastScale:ve,touchLength:n,touchTime:Date.now()})}function De(e){K({maskTouched:!0,CX:e.clientX,CY:e.clientY,lastX:ue,lastY:ce})}v(l?void 0:"mousemove",function(e){e.preventDefault(),Re(e.clientX,e.clientY)}),v(l?void 0:"mouseup",function(e){He(e.clientX,e.clientY)}),v(l?"touchmove":void 0,function(e){e.preventDefault();var t=y(e);Re.apply(void 0,t)},{passive:!1}),v(l?"touchend":void 0,function(e){var t=e.changedTouches[0];He(t.clientX,t.clientY)},{passive:!1}),v("resize",k(function(){oe&&!le&&(K(b(Q,$,fe)),O())},{maxWait:8})),f(function(){B&&j(i({scale:ve,rotate:fe},Pe))},[B]);var Oe=function(t,n,r,i,o,c,l,s,d,v){var h=function(t,n,r,i,o){var a=e.useRef(!1),c=u({lead:!0,scale:r}),l=c[0],s=l.lead,d=l.scale,v=c[1],h=k(function(e){try{return o(!0),v({lead:!1,scale:e}),Promise.resolve()}catch(e){return Promise.reject(e)}},{wait:i});return f(function(){a.current?(o(!1),v({lead:!0}),h(r)):a.current=!0},[r]),s?[t*d,n*d,r/d]:[t*r,n*r,1]}(c,l,s,d,v),m=h[0],g=h[1],p=h[2],w=function(t,n,r,i,o){var u=e.useState(_),c=u[0],l=u[1],s=e.useState(0),d=s[0],f=s[1],v=e.useRef(),h=a({OK:function(){return t&&f(4)}});function m(e){o(!1),f(e)}return e.useEffect(function(){if(v.current||(v.current=Date.now()),r){if(function(e,t){var n=e&&e.current;if(n&&1===n.nodeType){var r=n.getBoundingClientRect();t({T:r.top,L:r.left,W:r.width,H:r.height,FIT:"IMG"===n.tagName?getComputedStyle(n).objectFit:void 0})}}(n,l),t)return Date.now()-v.current<250?(f(1),requestAnimationFrame(function(){f(2),requestAnimationFrame(function(){return m(3)})}),void setTimeout(h.OK,i)):void f(4);m(5)}},[t,r]),[d,c]}(t,n,r,d,v),y=w[0],x=w[1],C=x.W,E=x.FIT,b=innerWidth/2,P=innerHeight/2,M=y<3||y>4;return[M?C?x.L:b:i+(b-c*s/2),M?C?x.T:P:o+(P-l*s/2),m,M&&E?m*(x.H/C):g,0===y?p:M?C/(c*s)||.01:p,M?E?1:0:1,y,E]}(w,p,oe,ue,ce,te,re,ve,M,function(e){return K({pause:e})}),Be=Oe[4],je=Oe[6],ze="transform "+M+"ms "+X,qe={className:S,onMouseDown:l?void 0:function(e){e.stopPropagation(),Fe(e.clientX,e.clientY,0)},onTouchStart:l?function(e){e.stopPropagation(),Fe.apply(void 0,y(e))}:void 0,onWheel:function(e){if(!ke){var t=d(ve-e.deltaY/100/2,Q/te);K({stopRaf:!0}),Me(t,e.clientX,e.clientY)}},style:{width:Oe[2],height:Oe[3],opacity:Oe[5],objectFit:4===je?void 0:Oe[7],transform:fe?"rotate("+fe+"deg)":void 0,transition:je>2?ze+", opacity "+M+"ms ease, height "+(je<4?M/2:je>4?M:0)+"ms "+X:void 0}};return r.default.createElement("div",{className:"PhotoView__PhotoWrap"+(N?" "+N:""),style:V,onMouseDown:!l&&B?De:void 0,onTouchStart:l&&B?function(e){return De(e.touches[0])}:void 0},r.default.createElement("div",{className:"PhotoView__PhotoBox",style:{transform:"matrix("+Be+", 0, 0, "+Be+", "+Oe[0]+", "+Oe[1]+")",transition:le||be?void 0:ze,willChange:B?"transform":void 0}},o?r.default.createElement(W,i({src:o,loaded:oe,broken:ae},qe,{onPhotoLoad:function(e){K(i({},e,e.loaded&&b(e.naturalWidth||0,e.naturalHeight||0,fe)))},loadingElement:A,brokenElement:I})):c&&c({attrs:qe,scale:Be,rotate:fe})))}var A={x:0,touched:!1,pause:!1,lastCX:void 0,lastCY:void 0,bg:void 0,lastBg:void 0,overlay:!0,minimal:!0,scale:1,rotate:0};function I(t){var n=t.loop,i=void 0===n?3:n,o=t.speed,c=t.easing,d=t.photoClosable,y=t.maskClosable,x=void 0===y||y,C=t.maskOpacity,E=void 0===C?1:C,b=t.pullClosable,k=void 0===b||b,P=t.bannerVisible,M=void 0===P||P,R=t.overlayRender,_=t.toolbarRender,Y=t.className,X=t.maskClassName,N=t.photoClassName,S=t.photoWrapClassName,W=t.loadingElement,T=t.brokenElement,I=t.images,L=t.index,H=void 0===L?0:L,F=t.onIndexChange,D=t.visible,O=t.onClose,B=t.afterClose,j=u(A),z=j[0],q=j[1],K=e.useState(0),U=K[0],G=K[1],J=z.x,Q=z.touched,Z=z.pause,$=z.lastCX,ee=z.lastCY,te=z.bg,ne=void 0===te?E:te,re=z.lastBg,ie=z.overlay,oe=z.minimal,ae=z.scale,ue=z.rotate,ce=z.onScale,le=z.onRotate,se=t.hasOwnProperty("index"),de=se?H:U,fe=se?F:G,ve=e.useRef(de),he=I.length,me=I[de],ge="boolean"==typeof i?i:he>i,pe=function(t,n){var r=e.useReducer(function(e){return!e},!1)[1],i=e.useRef(0),o=function(n,r){var o=e.useRef(n);function a(e){o.current=e}return e.useMemo(function(){!function(e){t?(e(t),i.current=1):i.current=2}(a)},[n]),[o.current,a]}(t),a=o[1];return[o[0],i.current,function(){r(),2===i.current&&(a(!1),n&&n()),i.current=0}]}(D,B),we=pe[0],ye=pe[1],xe=pe[2];f(function(){if(we)return q({pause:!0,x:de*-(innerWidth+20)}),void(ve.current=de);q(A)},[we]);var Ce=a({close:function(e){le&&le(0),q({overlay:!0,lastBg:ne}),O(e)},changeIndex:function(e,t){void 0===t&&(t=!1);var n=ge?ve.current+(e-de):e,r=he-1,i=s(n,0,r),o=ge?n:i,a=innerWidth+20;q({touched:!1,lastCX:void 0,lastCY:void 0,x:-a*o,pause:t}),ve.current=o,fe&&fe(ge?e<0?r:e>r?0:e:i)}}),Ee=Ce.close,be=Ce.changeIndex;function ke(e){return e?Ee():q({overlay:!ie})}function Pe(){q({x:-(innerWidth+20)*de,lastCX:void 0,lastCY:void 0,pause:!0}),ve.current=de}function Me(e,t,n,r){"x"===e?function(e){if(void 0!==$){var t=e-$,n=t;!ge&&(0===de&&t>0||de===he-1&&t<0)&&(n=t/2),q({touched:!0,lastCX:$,x:-(innerWidth+20)*ve.current+n,pause:!1})}else q({touched:!0,lastCX:e,x:J,pause:!1})}(t):"y"===e&&function(e,t){if(void 0!==ee){var n=s(E,0,E-Math.abs(e-ee)/100/4);q({touched:!0,lastCY:ee,bg:1===t?n:E,minimal:1===t})}else q({touched:!0,lastCY:e,bg:ne,minimal:!0})}(n,r)}function Re(e,t){var n=e-(null!=$?$:e),r=t-(null!=ee?ee:t),i=!1;if(n<-40)be(de+1);else if(n>40)be(de-1);else{var o=-(innerWidth+20)*ve.current;Math.abs(r)>100&&oe&&k&&(i=!0,Ee()),q({touched:!1,x:o,lastCX:void 0,lastCY:void 0,bg:E,overlay:!!i||ie})}}v("keydown",function(e){if(D)switch(e.key){case"ArrowLeft":be(de-1,!0);break;case"ArrowRight":be(de+1,!0);break;case"Escape":Ee()}});var _e=function(t,n,r){return e.useMemo(function(){var e=t.length;return r?t.concat(t).concat(t).slice(e+n-1,e+n+2):t.slice(Math.max(n-1,0),Math.min(n+2,e+1))},[t,n,r])}(I,de,ge);if(!we)return null;var Ye=ie&&!ye,Xe=D?ne:re,Ne=ce&&le&&{images:I,index:de,visible:D,onClose:Ee,onIndexChange:be,overlayVisible:Ye,scale:ae,rotate:ue,onScale:ce,onRotate:le},Se=o?o(ye):400,We=c?c(ye):"cubic-bezier(0.25, 0.8, 0.25, 1)",Te=o?o(3):600,Ve=c?c(3):"cubic-bezier(0.25, 0.8, 0.25, 1)";return r.default.createElement(h,{className:"PhotoView-Portal"+(Ye?"":" PhotoView-Slider__clean")+(D?"":" PhotoView-Slider__willClose")+(Y?" "+Y:""),role:"dialog",onClick:function(e){return e.stopPropagation()}},D&&r.default.createElement(w,null),r.default.createElement("div",{className:"PhotoView-Slider__Backdrop"+(X?" "+X:"")+(1===ye?" PhotoView-Slider__fadeIn":2===ye?" PhotoView-Slider__fadeOut":""),style:{background:"rgba(0, 0, 0, "+Xe+")",transitionTimingFunction:We,transitionDuration:(Q?0:Se)+"ms",animationDuration:Se+"ms"},onAnimationEnd:xe}),M&&r.default.createElement("div",{className:"PhotoView-Slider__BannerWrap"},r.default.createElement("div",{className:"PhotoView-Slider__Counter"},de+1," / ",he),r.default.createElement("div",{className:"PhotoView-Slider__BannerRight"},_&&Ne&&_(Ne),r.default.createElement(m,{className:"PhotoView-Slider__toolbarIcon",onClick:Ee}))),_e.map(function(e,t){var n=ge||0!==de?ve.current-1+t:de+t;return r.default.createElement(V,{key:ge?e.key+"/"+e.src+"/"+n:e.key,item:e,speed:Se,easing:We,visible:D,onReachMove:Me,onReachUp:Re,onPhotoTap:function(){return ke(d)},onMaskTap:function(){return ke(x)},wrapClassName:S,className:N,style:{left:(innerWidth+20)*n+"px",transform:"translate3d("+J+"px, 0px, 0)",transition:Q||Z?void 0:"transform "+Te+"ms "+Ve},loadingElement:W,brokenElement:T,onPhotoResize:Pe,isActive:(me&&me.key)===e.key,expose:q})}),!l&&M&&r.default.createElement(r.default.Fragment,null,(ge||0!==de)&&r.default.createElement("div",{className:"PhotoView-Slider__ArrowLeft",onClick:function(){return be(de-1,!0)}},r.default.createElement(g,null)),(ge||de+1<he)&&r.default.createElement("div",{className:"PhotoView-Slider__ArrowRight",onClick:function(){return be(de+1,!0)}},r.default.createElement(p,null))),R&&Ne&&r.default.createElement("div",{className:"PhotoView-Slider__Overlay"},R(Ne)))}var L=["children","onIndexChange","onVisibleChange"],H={images:[],visible:!1,index:0};exports.PhotoProvider=function(t){var n=t.children,l=t.onIndexChange,s=t.onVisibleChange,d=o(t,L),f=u(H),v=f[0],h=f[1],m=e.useRef(0),g=v.images,p=v.visible,w=v.index,y=a({nextId:function(){return m.current+=1},update:function(e){var t=g.findIndex(function(t){return t.key===e.key});if(t>-1){var n=g.slice();return n.splice(t,1,e),void h({images:n})}h(function(t){return{images:t.images.concat(e)}})},remove:function(e){var t=g.filter(function(t){return t.key!==e});h({images:t,index:Math.min(t.length-1,w)})},show:function(e){var t=g.findIndex(function(t){return t.key===e});h({visible:!0,index:t}),s&&s(!0,t,v)}}),x=a({close:function(){h({visible:!1}),s&&s(!1,w,v)},changeIndex:function(e){h({index:e}),l&&l(e,v)}}),C=e.useMemo(function(){return i({},v,y)},[v,y]);return r.default.createElement(c.Provider,{value:C},n,r.default.createElement(I,i({images:g,visible:p,index:w,onIndexChange:x.changeIndex,onClose:x.close},d)))},exports.PhotoSlider=I,exports.PhotoView=function(t){var n,r,i=t.src,o=t.render,u=t.width,l=t.height,s=t.children,d=e.useContext(c),f=(n=function(){return d.nextId()},(r=e.useRef({sign:!1,fn:void 0}).current).sign||(r.sign=!0,r.fn=n()),r.fn),v=e.useRef(null);e.useEffect(function(){return function(){d.remove(f)}},[]);var h=a({render:function(e){return o&&o(e)},click:function(e){d.show(f),function(e,t){if(s){var n=s.props.onClick;n&&n(t)}}(0,e)}});return e.useEffect(function(){d.update({key:f,src:i,originRef:v,render:h.render,width:u,height:l})},[i]),s?e.Children.only(e.cloneElement(s,{onClick:h.click,ref:v})):null}; | ||
var e=require("react"),t=require("react-dom");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=/*#__PURE__*/n(e);function i(){return i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},i.apply(this,arguments)}function o(e,t){if(null==e)return{};var n,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)t.indexOf(n=o[r])>=0||(i[n]=e[n]);return i}function a(t){var n=e.useRef({fn:t,curr:void 0}).current;if(n.fn=t,!n.curr){var r=Object.create(null);Object.keys(t).forEach(function(e){r[e]=function(){var t;return(t=n.fn[e]).call.apply(t,[n.fn].concat([].slice.call(arguments)))}}),n.curr=r}return n.curr}function u(t){return e.useReducer(function(e,t){return i({},e,"function"==typeof t?t(e):t)},t)}var c=e.createContext(void 0),l="undefined"!=typeof window&&"ontouchstart"in window,s=function(e,t,n){return Math.max(Math.min(e,n),t)},d=function(e,t,n){return void 0===t&&(t=0),void 0===n&&(n=0),s(e,1*(1-n),Math.max(6,t)*(1+n))},f="undefined"==typeof window||/ServerSideRendering/.test(navigator&&navigator.userAgent)?e.useEffect:e.useLayoutEffect;function v(t,n,r){var i=e.useRef(n);i.current=n,e.useEffect(function(){function e(e){i.current(e)}return t&&window.addEventListener(t,e,r),function(){t&&window.removeEventListener(t,e)}},[t])}var h=function(e){return t.createPortal(r.default.createElement("div",i({},e)),document.body)};function m(e){return r.default.createElement("svg",i({width:"44",height:"44",viewBox:"0 0 768 768"},e),r.default.createElement("path",{d:"M607.5 205.5l-178.5 178.5 178.5 178.5-45 45-178.5-178.5-178.5 178.5-45-45 178.5-178.5-178.5-178.5 45-45 178.5 178.5 178.5-178.5z"}))}function g(e){return r.default.createElement("svg",i({width:"44",height:"44",viewBox:"0 0 768 768"},e),r.default.createElement("path",{d:"M640.5 352.5v63h-390l178.5 180-45 45-256.5-256.5 256.5-256.5 45 45-178.5 180h390z"}))}function p(e){return r.default.createElement("svg",i({width:"44",height:"44",viewBox:"0 0 768 768"},e),r.default.createElement("path",{d:"M384 127.5l256.5 256.5-256.5 256.5-45-45 178.5-180h-390v-63h390l-178.5-180z"}))}function w(){return e.useEffect(function(){var e=document.body.style,t=e.overflow;return e.overflow="hidden",function(){e.overflow=t}},[]),null}function y(e){var t=e.touches[0],n=t.clientX,r=t.clientY;if(e.touches.length>=2){var i=e.touches[1],o=i.clientX,a=i.clientY;return[(n+o)/2,(r+a)/2,Math.sqrt(Math.pow(o-n,2)+Math.pow(a-r,2))]}return[n,r,0]}var x=function(e,t,n,r){var i=n*t,o=(i-r)/2,a=void 0,u=e;return i<=r?(a=1,u=0):e>0&&o-e<=0?(a=2,u=o):e<0&&o+e<=0&&(a=3,u=-o),[a,u]};function C(e,t,n,r,i,o,a,u,c,l){void 0===a&&(a=innerWidth/2),void 0===u&&(u=innerHeight/2),void 0===c&&(c=0),void 0===l&&(l=0);var s=x(e,o,n,innerWidth)[0],d=x(t,o,r,innerHeight),f=innerWidth/2,v=innerHeight/2;return{x:a-o/i*(a-(f+e))-f+(r/n>=3&&n*o===innerWidth?0:s?c/2:c),y:u-o/i*(u-(v+t))-v+(d[0]?l/2:l),lastCX:a,lastCY:u}}function b(e,t,n){var r=e%180!=0;return r?[n,t,r]:[t,n,r]}function E(e,t,n){var r=b(n,innerWidth,innerHeight),i=r[0],o=r[1],a=0,u=i,c=o,l=e/t*o,s=t/e*i;return e<i&&t<o?(u=e,c=t):e<i&&t>=o?u=l:e>=i&&t<o||e/t>i/o?c=s:t/e>=3&&!r[2]?a=((c=s)-o)/2:u=l,{width:u,height:c,x:0,y:a,pause:!0}}function k(t,n){var r=n.leading,i=void 0!==r&&r,o=n.maxWait,a=n.wait,u=void 0===a?o||0:a,c=e.useRef(t);c.current=t;var l=e.useRef(0),s=e.useRef(),d=function(){return s.current&&clearTimeout(s.current)},f=e.useCallback(function(){var e=[].slice.call(arguments),t=Date.now();function n(){l.current=t,d(),c.current.apply(null,e)}var r=l.current,a=t-r;if(0===r&&(i&&n(),l.current=t),void 0!==o){if(a>o)return void n()}else a<u&&(l.current=t);d(),s.current=setTimeout(function(){n(),l.current=0},u)},[u,o,i]);return f.cancel=d,f}var P=function(e,t,n){return R(e,t,n,100,function(e){return e},function(){return R(t,e,n)})},M=function(e){return 1-Math.pow(1-e,4)};function R(e,t,n,r,i,o){void 0===r&&(r=400),void 0===i&&(i=M);var a=t-e;if(0!==a){var u=Date.now(),c=0,l=function(){var t=Math.min(1,(Date.now()-u)/r);n(e+i(t)*a)&&t<1?s():(cancelAnimationFrame(c),t>=1&&o&&o())};s()}function s(){c=requestAnimationFrame(l)}}var _={T:0,L:0,W:0,H:0,FIT:void 0},Y=function(){var t=e.useRef(!1);return e.useEffect(function(){return t.current=!0,function(){t.current=!1}},[]),t},X=["className"];function N(e){var t=e.className,n=o(e,X);return r.default.createElement("div",i({className:"PhotoView__Spinner "+t},n),r.default.createElement("svg",{viewBox:"0 0 32 32",width:"36",height:"36",fill:"white"},r.default.createElement("path",{opacity:".25",d:"M16 0 A16 16 0 0 0 16 32 A16 16 0 0 0 16 0 M16 4 A12 12 0 0 1 16 28 A12 12 0 0 1 16 4"}),r.default.createElement("path",{d:"M16 0 A16 16 0 0 1 32 16 L28 16 A12 12 0 0 0 16 4z"})))}var S=["src","loaded","broken","className","onPhotoLoad","loadingElement","brokenElement"];function W(e){var t=e.src,n=e.loaded,a=e.broken,u=e.className,c=e.onPhotoLoad,l=e.loadingElement,s=e.brokenElement,d=o(e,S),f=Y();return t&&!a?r.default.createElement(r.default.Fragment,null,r.default.createElement("img",i({className:"PhotoView__Photo"+(u?" "+u:""),src:t,onLoad:function(e){var t=e.target;f.current&&c({loaded:!0,naturalWidth:t.naturalWidth,naturalHeight:t.naturalHeight})},onError:function(){f.current&&c({broken:!0})},alt:""},d)),!n&&(r.default.createElement("span",{className:"PhotoView__icon"},l)||r.default.createElement(N,{className:"PhotoView__icon"}))):s?r.default.createElement("span",{className:"PhotoView__icon"},"function"==typeof s?s({src:t}):s):null}var T={naturalWidth:void 0,naturalHeight:void 0,width:void 0,height:void 0,loaded:void 0,broken:!1,x:0,y:0,touched:!1,maskTouched:!1,rotate:0,scale:1,CX:0,CY:0,lastX:0,lastY:0,lastCX:0,lastCY:0,lastScale:1,touchTime:0,touchLength:0,pause:!0,stopRaf:!0,reach:void 0};function V(t){var n=t.item,o=n.src,c=n.render,s=n.width,h=void 0===s?0:s,m=n.height,g=void 0===m?0:m,p=n.originRef,w=t.visible,M=t.speed,X=t.easing,N=t.wrapClassName,S=t.className,V=t.style,A=t.loadingElement,I=t.brokenElement,L=t.onPhotoTap,H=t.onMaskTap,F=t.onReachMove,D=t.onReachUp,O=t.onPhotoResize,B=t.isActive,j=t.expose,z=u(T),q=z[0],K=z[1],U=e.useRef(0),G=Y(),J=q.naturalWidth,Q=void 0===J?h:J,Z=q.naturalHeight,$=void 0===Z?g:Z,ee=q.width,te=void 0===ee?h:ee,ne=q.height,re=void 0===ne?g:ne,ie=q.loaded,oe=void 0===ie?!o:ie,ae=q.broken,ue=q.x,ce=q.y,le=q.touched,se=q.stopRaf,de=q.maskTouched,fe=q.rotate,ve=q.scale,he=q.CX,me=q.CY,ge=q.lastX,pe=q.lastY,we=q.lastCX,ye=q.lastCY,xe=q.lastScale,Ce=q.touchTime,be=q.touchLength,Ee=q.pause,ke=q.reach,Pe=a({onScale:function(e){return Me(d(e))},onRotate:function(e){fe!==e&&(j({rotate:e}),K(i({rotate:e},E(Q,$,e))))}});function Me(e,t,n){ve!==e&&(j({scale:e}),K(i({scale:e},C(ue,ce,te,re,ve,e,t,n),e<=1&&{x:0,y:0})))}var Re=k(function(e,t,n){if(void 0===n&&(n=0),(le||de)&&B){var r=b(fe,te,re),o=r[0],a=r[1];if(0===n&&0===U.current){var u=Math.abs(e-he)<=20,c=Math.abs(t-me)<=20;if(u&&c)return void K({lastCX:e,lastCY:t});U.current=u?t>me?3:2:1}var l=e-we,s=t-ye,f=void 0;if(0===n){var v=x(l+ge,ve,o,innerWidth)[0],h=x(s+pe,ve,a,innerHeight);f=function(e,t,n,r){return t&&1===e||"x"===r?"x":n&&e>1||"y"===r?"y":void 0}(U.current,v,h[0],ke),void 0!==f&&F(f,e,t,ve)}if("x"===f||de)return void K({reach:"x"});var m=d(ve+(n-be)/100/2*ve,Q/te,.2);j({scale:m}),K(i({touchLength:n,reach:f,scale:m},C(ue,ce,te,re,ve,m,e,t,l,s)))}},{maxWait:8});function _e(e){return!se&&!le&&(G.current&&K(i({},e,{pause:w})),G.current)}var Ye,Xe,Ne,Se,We,Te,Ve,Ae,Ie=(We=function(e){return _e({x:e})},Te=function(e){return _e({y:e})},Ve=function(e){return G.current&&(j({scale:e}),K({scale:e})),!le&&G.current},Ae=a({X:function(e){return We(e)},Y:function(e){return Te(e)},S:function(e){return Ve(e)}}),function(e,t,n,r,i,o,a,u,c,l,s){var d=b(l,i,o),f=d[0],v=d[1],h=x(e,u,f,innerWidth),m=h[0],g=h[1],p=x(t,u,v,innerHeight),w=p[0],y=p[1],E=Date.now()-s;if(E>=200||u!=a||Math.abs(c-a)>1){var k=C(e,t,i,o,a,u),M=k.x,_=k.y,Y=m?g:M!==e?M:null,X=w?y:_!==t?_:null;return null!==Y&&R(e,Y,Ae.X),null!==X&&R(t,X,Ae.Y),void(u!=a&&R(a,u,Ae.S))}var N=(e-n)/E,S=(t-r)/E,W=Math.sqrt(Math.pow(N,2)+Math.pow(S,2)),T=!1,V=!1;!function(e,t){var n=e,r=0,i=void 0,o=0,a=function(o){i||(i=o);var a=o-i,l=Math.sign(e),s=-.001*l,d=Math.sign(-n)*Math.pow(n,2)*2e-4,f=n*a+(s+d)*Math.pow(a,2)/2;r+=f,i=o,l*(n+=(s+d)*a)<=0?c():t(r)?u():c()};function u(){o=requestAnimationFrame(a)}function c(){cancelAnimationFrame(o)}u()}(W,function(n){var r=e+n*(N/W),i=t+n*(S/W),o=x(r,a,f,innerWidth),u=o[0],c=o[1],l=x(i,a,v,innerHeight),s=l[0],d=l[1];if(u&&!T&&(T=!0,m?R(r,c,Ae.X):P(c,r+(r-c),Ae.X)),s&&!V&&(V=!0,w?R(i,d,Ae.Y):P(d,i+(i-d),Ae.Y)),T&&V)return!1;var h=T||Ae.X(c),g=V||Ae.Y(d);return h&&g})}),Le=(Ye=L,Xe=function(e,t){ke||Me(1!==ve?1:Math.max(2,Q/te),e,t)},Ne=e.useRef(0),Se=k(function(){Ne.current=0,Ye.apply(void 0,[].slice.call(arguments))},{wait:300}),function(){var e=[].slice.call(arguments);Ne.current+=1,Se.apply(void 0,e),Ne.current>=2&&(Se.cancel(),Ne.current=0,Xe.apply(void 0,e))});function He(e,t){if(U.current=0,(le||de)&&B){K({touched:!1,maskTouched:!1,pause:!1,stopRaf:!1,reach:void 0});var n=d(ve,Q/te);if(Ie(ue,ce,ge,pe,te,re,ve,n,xe,fe,Ce),D(e,t),he===e&&me===t){if(le)return void Le(e,t);de&&H(e,t)}}}function Fe(e,t,n){void 0===n&&(n=0),K({touched:!0,CX:e,CY:t,lastCX:e,lastCY:t,lastX:ue,lastY:ce,lastScale:ve,touchLength:n,touchTime:Date.now()})}function De(e){K({maskTouched:!0,CX:e.clientX,CY:e.clientY,lastX:ue,lastY:ce})}v(l?void 0:"mousemove",function(e){e.preventDefault(),Re(e.clientX,e.clientY)}),v(l?void 0:"mouseup",function(e){He(e.clientX,e.clientY)}),v(l?"touchmove":void 0,function(e){e.preventDefault();var t=y(e);Re.apply(void 0,t)},{passive:!1}),v(l?"touchend":void 0,function(e){var t=e.changedTouches[0];He(t.clientX,t.clientY)},{passive:!1}),v("resize",k(function(){oe&&!le&&(K(E(Q,$,fe)),O())},{maxWait:8})),f(function(){B&&j(i({scale:ve,rotate:fe},Pe))},[B]);var Oe=function(t,n,r,i,o,c,l,s,d,v){var h=function(t,n,r,i,o){var a=e.useRef(!1),c=u({lead:!0,scale:r}),l=c[0],s=l.lead,d=l.scale,v=c[1],h=k(function(e){try{return o(!0),v({lead:!1,scale:e}),Promise.resolve()}catch(e){return Promise.reject(e)}},{wait:i});return f(function(){a.current?(o(!1),v({lead:!0}),h(r)):a.current=!0},[r]),s?[t*d,n*d,r/d]:[t*r,n*r,1]}(c,l,s,d,v),m=h[0],g=h[1],p=h[2],w=function(t,n,r,i,o){var u=e.useState(_),c=u[0],l=u[1],s=e.useState(0),d=s[0],f=s[1],v=e.useRef(),h=a({OK:function(){return t&&f(4)}});function m(e){o(!1),f(e)}return e.useEffect(function(){if(v.current||(v.current=Date.now()),r){if(function(e,t){var n=e&&e.current;if(n&&1===n.nodeType){var r=n.getBoundingClientRect();t({T:r.top,L:r.left,W:r.width,H:r.height,FIT:"IMG"===n.tagName?getComputedStyle(n).objectFit:void 0})}}(n,l),t)return Date.now()-v.current<250?(f(1),requestAnimationFrame(function(){f(2),requestAnimationFrame(function(){return m(3)})}),void setTimeout(h.OK,i)):void f(4);m(5)}},[t,r]),[d,c]}(t,n,r,d,v),y=w[0],x=w[1],C=x.W,b=x.FIT,E=innerWidth/2,P=innerHeight/2,M=y<3||y>4;return[M?C?x.L:E:i+(E-c*s/2),M?C?x.T:P:o+(P-l*s/2),m,M&&b?m*(x.H/C):g,0===y?p:M?C/(c*s)||.01:p,M?b?1:0:1,y,b]}(w,p,oe,ue,ce,te,re,ve,M,function(e){return K({pause:e})}),Be=Oe[4],je=Oe[6],ze="transform "+M+"ms "+X,qe={className:S,onMouseDown:l?void 0:function(e){e.stopPropagation(),0===e.button&&Fe(e.clientX,e.clientY,0)},onTouchStart:l?function(e){e.stopPropagation(),Fe.apply(void 0,y(e))}:void 0,onWheel:function(e){if(!ke){var t=d(ve-e.deltaY/100/2,Q/te);K({stopRaf:!0}),Me(t,e.clientX,e.clientY)}},style:{width:Oe[2],height:Oe[3],opacity:Oe[5],objectFit:4===je?void 0:Oe[7],transform:fe?"rotate("+fe+"deg)":void 0,transition:je>2?ze+", opacity "+M+"ms ease, height "+(je<4?M/2:je>4?M:0)+"ms "+X:void 0}};return r.default.createElement("div",{className:"PhotoView__PhotoWrap"+(N?" "+N:""),style:V,onMouseDown:!l&&B?De:void 0,onTouchStart:l&&B?function(e){return De(e.touches[0])}:void 0},r.default.createElement("div",{className:"PhotoView__PhotoBox",style:{transform:"matrix("+Be+", 0, 0, "+Be+", "+Oe[0]+", "+Oe[1]+")",transition:le||Ee?void 0:ze,willChange:B?"transform":void 0}},o?r.default.createElement(W,i({src:o,loaded:oe,broken:ae},qe,{onPhotoLoad:function(e){K(i({},e,e.loaded&&E(e.naturalWidth||0,e.naturalHeight||0,fe)))},loadingElement:A,brokenElement:I})):c&&c({attrs:qe,scale:Be,rotate:fe})))}var A={x:0,touched:!1,pause:!1,lastCX:void 0,lastCY:void 0,bg:void 0,lastBg:void 0,overlay:!0,minimal:!0,scale:1,rotate:0};function I(t){var n=t.loop,i=void 0===n?3:n,o=t.speed,c=t.easing,d=t.photoClosable,y=t.maskClosable,x=void 0===y||y,C=t.maskOpacity,b=void 0===C?1:C,E=t.pullClosable,k=void 0===E||E,P=t.bannerVisible,M=void 0===P||P,R=t.overlayRender,_=t.toolbarRender,Y=t.className,X=t.maskClassName,N=t.photoClassName,S=t.photoWrapClassName,W=t.loadingElement,T=t.brokenElement,I=t.images,L=t.index,H=void 0===L?0:L,F=t.onIndexChange,D=t.visible,O=t.onClose,B=t.afterClose,j=u(A),z=j[0],q=j[1],K=e.useState(0),U=K[0],G=K[1],J=z.x,Q=z.touched,Z=z.pause,$=z.lastCX,ee=z.lastCY,te=z.bg,ne=void 0===te?b:te,re=z.lastBg,ie=z.overlay,oe=z.minimal,ae=z.scale,ue=z.rotate,ce=z.onScale,le=z.onRotate,se=t.hasOwnProperty("index"),de=se?H:U,fe=se?F:G,ve=e.useRef(de),he=I.length,me=I[de],ge="boolean"==typeof i?i:he>i,pe=function(t,n){var r=e.useReducer(function(e){return!e},!1)[1],i=e.useRef(0),o=function(n,r){var o=e.useRef(n);function a(e){o.current=e}return e.useMemo(function(){!function(e){t?(e(t),i.current=1):i.current=2}(a)},[n]),[o.current,a]}(t),a=o[1];return[o[0],i.current,function(){r(),2===i.current&&(a(!1),n&&n()),i.current=0}]}(D,B),we=pe[0],ye=pe[1],xe=pe[2];f(function(){if(we)return q({pause:!0,x:de*-(innerWidth+20)}),void(ve.current=de);q(A)},[we]);var Ce=a({close:function(e){le&&le(0),q({overlay:!0,lastBg:ne}),O(e)},changeIndex:function(e,t){void 0===t&&(t=!1);var n=ge?ve.current+(e-de):e,r=he-1,i=s(n,0,r),o=ge?n:i,a=innerWidth+20;q({touched:!1,lastCX:void 0,lastCY:void 0,x:-a*o,pause:t}),ve.current=o,fe&&fe(ge?e<0?r:e>r?0:e:i)}}),be=Ce.close,Ee=Ce.changeIndex;function ke(e){return e?be():q({overlay:!ie})}function Pe(){q({x:-(innerWidth+20)*de,lastCX:void 0,lastCY:void 0,pause:!0}),ve.current=de}function Me(e,t,n,r){"x"===e?function(e){if(void 0!==$){var t=e-$,n=t;!ge&&(0===de&&t>0||de===he-1&&t<0)&&(n=t/2),q({touched:!0,lastCX:$,x:-(innerWidth+20)*ve.current+n,pause:!1})}else q({touched:!0,lastCX:e,x:J,pause:!1})}(t):"y"===e&&function(e,t){if(void 0!==ee){var n=s(b,0,b-Math.abs(e-ee)/100/4);q({touched:!0,lastCY:ee,bg:1===t?n:b,minimal:1===t})}else q({touched:!0,lastCY:e,bg:ne,minimal:!0})}(n,r)}function Re(e,t){var n=e-(null!=$?$:e),r=t-(null!=ee?ee:t),i=!1;if(n<-40)Ee(de+1);else if(n>40)Ee(de-1);else{var o=-(innerWidth+20)*ve.current;Math.abs(r)>100&&oe&&k&&(i=!0,be()),q({touched:!1,x:o,lastCX:void 0,lastCY:void 0,bg:b,overlay:!!i||ie})}}v("keydown",function(e){if(D)switch(e.key){case"ArrowLeft":Ee(de-1,!0);break;case"ArrowRight":Ee(de+1,!0);break;case"Escape":be()}});var _e=function(t,n,r){return e.useMemo(function(){var e=t.length;return r?t.concat(t).concat(t).slice(e+n-1,e+n+2):t.slice(Math.max(n-1,0),Math.min(n+2,e+1))},[t,n,r])}(I,de,ge);if(!we)return null;var Ye=ie&&!ye,Xe=D?ne:re,Ne=ce&&le&&{images:I,index:de,visible:D,onClose:be,onIndexChange:Ee,overlayVisible:Ye,overlay:me.overlay,scale:ae,rotate:ue,onScale:ce,onRotate:le},Se=o?o(ye):400,We=c?c(ye):"cubic-bezier(0.25, 0.8, 0.25, 1)",Te=o?o(3):600,Ve=c?c(3):"cubic-bezier(0.25, 0.8, 0.25, 1)";return r.default.createElement(h,{className:"PhotoView-Portal"+(Ye?"":" PhotoView-Slider__clean")+(D?"":" PhotoView-Slider__willClose")+(Y?" "+Y:""),role:"dialog",onClick:function(e){return e.stopPropagation()}},D&&r.default.createElement(w,null),r.default.createElement("div",{className:"PhotoView-Slider__Backdrop"+(X?" "+X:"")+(1===ye?" PhotoView-Slider__fadeIn":2===ye?" PhotoView-Slider__fadeOut":""),style:{background:"rgba(0, 0, 0, "+Xe+")",transitionTimingFunction:We,transitionDuration:(Q?0:Se)+"ms",animationDuration:Se+"ms"},onAnimationEnd:xe}),M&&r.default.createElement("div",{className:"PhotoView-Slider__BannerWrap"},r.default.createElement("div",{className:"PhotoView-Slider__Counter"},de+1," / ",he),r.default.createElement("div",{className:"PhotoView-Slider__BannerRight"},_&&Ne&&_(Ne),r.default.createElement(m,{className:"PhotoView-Slider__toolbarIcon",onClick:be}))),_e.map(function(e,t){var n=ge||0!==de?ve.current-1+t:de+t;return r.default.createElement(V,{key:ge?e.key+"/"+e.src+"/"+n:e.key,item:e,speed:Se,easing:We,visible:D,onReachMove:Me,onReachUp:Re,onPhotoTap:function(){return ke(d)},onMaskTap:function(){return ke(x)},wrapClassName:S,className:N,style:{left:(innerWidth+20)*n+"px",transform:"translate3d("+J+"px, 0px, 0)",transition:Q||Z?void 0:"transform "+Te+"ms "+Ve},loadingElement:W,brokenElement:T,onPhotoResize:Pe,isActive:(me&&me.key)===e.key,expose:q})}),!l&&M&&r.default.createElement(r.default.Fragment,null,(ge||0!==de)&&r.default.createElement("div",{className:"PhotoView-Slider__ArrowLeft",onClick:function(){return Ee(de-1,!0)}},r.default.createElement(g,null)),(ge||de+1<he)&&r.default.createElement("div",{className:"PhotoView-Slider__ArrowRight",onClick:function(){return Ee(de+1,!0)}},r.default.createElement(p,null))),R&&Ne&&r.default.createElement("div",{className:"PhotoView-Slider__Overlay"},R(Ne)))}var L=["children","onIndexChange","onVisibleChange"],H={images:[],visible:!1,index:0};exports.PhotoProvider=function(t){var n=t.children,l=t.onIndexChange,s=t.onVisibleChange,d=o(t,L),f=u(H),v=f[0],h=f[1],m=e.useRef(0),g=v.images,p=v.visible,w=v.index,y=a({nextId:function(){return m.current+=1},update:function(e){var t=g.findIndex(function(t){return t.key===e.key});if(t>-1){var n=g.slice();return n.splice(t,1,e),void h({images:n})}h(function(t){return{images:t.images.concat(e)}})},remove:function(e){var t=g.filter(function(t){return t.key!==e});h({images:t,index:Math.min(t.length-1,w)})},show:function(e){var t=g.findIndex(function(t){return t.key===e});h({visible:!0,index:t}),s&&s(!0,t,v)}}),x=a({close:function(){h({visible:!1}),s&&s(!1,w,v)},changeIndex:function(e){h({index:e}),l&&l(e,v)}}),C=e.useMemo(function(){return i({},v,y)},[v,y]);return r.default.createElement(c.Provider,{value:C},n,r.default.createElement(I,i({images:g,visible:p,index:w,onIndexChange:x.changeIndex,onClose:x.close},d)))},exports.PhotoSlider=I,exports.PhotoView=function(t){var n,r,i=t.src,o=t.render,u=t.overlay,l=t.width,s=t.height,d=t.children,f=e.useContext(c),v=(n=function(){return f.nextId()},(r=e.useRef({sign:!1,fn:void 0}).current).sign||(r.sign=!0,r.fn=n()),r.fn),h=e.useRef(null);e.useEffect(function(){return function(){f.remove(v)}},[]);var m=a({render:function(e){return o&&o(e)},click:function(e){f.show(v),function(e,t){if(d){var n=d.props.onClick;n&&n(t)}}(0,e)}});return e.useEffect(function(){f.update({key:v,src:i,originRef:h,render:m.render,overlay:u,width:l,height:s})},[i]),d?e.Children.only(e.cloneElement(d,{onClick:m.click,ref:h})):null}; | ||
//# sourceMappingURL=react-photo-view.js.map |
@@ -1,2 +0,2 @@ | ||
import e,{useRef as t,useReducer as n,createContext as o,useEffect as i,useLayoutEffect as r,useMemo as a,useCallback as c,useState as s,useContext as l,Children as u,cloneElement as d}from"react";import{createPortal as h}from"react-dom";function m(){return m=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},m.apply(this,arguments)}function f(e,t){if(null==e)return{};var n,o,i={},r=Object.keys(e);for(o=0;o<r.length;o++)t.indexOf(n=r[o])>=0||(i[n]=e[n]);return i}function v(e){const{current:n}=t({fn:e,curr:void 0});if(n.fn=e,!n.curr){const t=Object.create(null);Object.keys(e).forEach(e=>{t[e]=(...t)=>n.fn[e].call(n.fn,...t)}),n.curr=t}return n.curr}function g(e){return n((e,t)=>m({},e,"function"==typeof t?t(e):t),e)}var p=o(void 0);const w=1,x="undefined"!=typeof window&&"ontouchstart"in window,C=(e,t,n)=>Math.max(Math.min(e,n),t),b=(e,t=0,n=0)=>C(e,1*(1-n),Math.max(6,t)*(1+n));var y="undefined"==typeof window||/ServerSideRendering/.test(navigator&&navigator.userAgent)?i:r;function E(e,n,o){const r=t(n);r.current=n,i(()=>{function t(e){r.current(e)}return e&&window.addEventListener(e,t,o),()=>{e&&window.removeEventListener(e,t)}},[e])}const k=t=>h(e.createElement("div",m({},t)),document.body);function _(t){return e.createElement("svg",m({width:"44",height:"44",viewBox:"0 0 768 768"},t),e.createElement("path",{d:"M607.5 205.5l-178.5 178.5 178.5 178.5-45 45-178.5-178.5-178.5 178.5-45-45 178.5-178.5-178.5-178.5 45-45 178.5 178.5 178.5-178.5z"}))}function P(t){return e.createElement("svg",m({width:"44",height:"44",viewBox:"0 0 768 768"},t),e.createElement("path",{d:"M640.5 352.5v63h-390l178.5 180-45 45-256.5-256.5 256.5-256.5 45 45-178.5 180h390z"}))}function Y(t){return e.createElement("svg",m({width:"44",height:"44",viewBox:"0 0 768 768"},t),e.createElement("path",{d:"M384 127.5l256.5 256.5-256.5 256.5-45-45 178.5-180h-390v-63h390l-178.5-180z"}))}function X(){return i(()=>{const{style:e}=document.body,t=e.overflow;return e.overflow="hidden",()=>{e.overflow=t}},[]),null}function M(e){const{clientX:t,clientY:n}=e.touches[0];if(e.touches.length>=2){const{clientX:o,clientY:i}=e.touches[1];return[(t+o)/2,(n+i)/2,Math.sqrt((o-t)**2+(i-n)**2)]}return[t,n,0]}const N=(e,t,n,o)=>{const i=n*t,r=(i-o)/2;let a,c=e;return i<=o?(a=1,c=0):e>0&&r-e<=0?(a=2,c=r):e<0&&r+e<=0&&(a=3,c=-r),[a,c]};function W(e,t,n,o,i,r,a=innerWidth/2,c=innerHeight/2,s=0,l=0){const[u]=N(e,r,n,innerWidth),[d]=N(t,r,o,innerHeight),h=innerWidth/2,m=innerHeight/2;return{x:a-r/i*(a-(h+e))-h+(o/n>=3&&n*r===innerWidth?0:u?s/2:s),y:c-r/i*(c-(m+t))-m+(d?l/2:l),lastCX:a,lastCY:c}}function $(e,t,n){const o=e%180!=0;return o?[n,t,o]:[t,n,o]}function S(e,t,n){const[o,i,r]=$(n,innerWidth,innerHeight);let a=0,c=o,s=i;const l=e/t*i,u=t/e*o;return e<o&&t<i?(c=e,s=t):e<o&&t>=i?c=l:e>=o&&t<i||e/t>o/i?s=u:t/e>=3&&!r?(s=u,a=(s-i)/2):c=l,{width:c,height:s,x:0,y:a,pause:!0}}function T(e,{leading:n=!1,maxWait:o,wait:i=o||0}){const r=t(e);r.current=e;const a=t(0),s=t(),l=()=>s.current&&clearTimeout(s.current),u=c((...e)=>{const t=Date.now();function c(){a.current=t,l(),r.current.apply(null,e)}const u=a.current,d=t-u;if(0===u&&(n&&c(),a.current=t),void 0!==o){if(d>o)return void c()}else d<i&&(a.current=t);l(),s.current=setTimeout(()=>{c(),a.current=0},i)},[i,o,n]);return u.cancel=l,u}const V=(e,t,n)=>A(e,t,n,100,e=>e,()=>A(t,e,n)),R=e=>1-(1-e)**4;function A(e,t,n,o=400,i=R,r){const a=t-e;if(0===a)return;const c=Date.now();let s=0;const l=()=>{const t=Math.min(1,(Date.now()-c)/o);n(e+i(t)*a)&&t<1?u():(cancelAnimationFrame(s),t>=1&&r&&r())};function u(){s=requestAnimationFrame(l)}u()}const I={T:0,L:0,W:0,H:0,FIT:void 0},H=()=>{const e=t(!1);return i(()=>(e.current=!0,()=>{e.current=!1}),[]),e},L=["className"];function F(t){let{className:n}=t,o=f(t,L);return e.createElement("div",m({className:`PhotoView__Spinner ${n}`},o),e.createElement("svg",{viewBox:"0 0 32 32",width:"36",height:"36",fill:"white"},e.createElement("path",{opacity:".25",d:"M16 0 A16 16 0 0 0 16 32 A16 16 0 0 0 16 0 M16 4 A12 12 0 0 1 16 28 A12 12 0 0 1 16 4"}),e.createElement("path",{d:"M16 0 A16 16 0 0 1 32 16 L28 16 A12 12 0 0 0 16 4z"})))}const D=["src","loaded","broken","className","onPhotoLoad","loadingElement","brokenElement"];function O(t){let{src:n,loaded:o,broken:i,className:r,onPhotoLoad:a,loadingElement:c,brokenElement:s}=t,l=f(t,D);const u=H();return n&&!i?e.createElement(e.Fragment,null,e.createElement("img",m({className:"PhotoView__Photo"+(r?` ${r}`:""),src:n,onLoad:function(e){const{naturalWidth:t,naturalHeight:n}=e.target;u.current&&a({loaded:!0,naturalWidth:t,naturalHeight:n})},onError:function(){u.current&&a({broken:!0})},alt:""},l)),!o&&(e.createElement("span",{className:"PhotoView__icon"},c)||e.createElement(F,{className:"PhotoView__icon"}))):s?e.createElement("span",{className:"PhotoView__icon"},"function"==typeof s?s({src:n}):s):null}const B={naturalWidth:void 0,naturalHeight:void 0,width:void 0,height:void 0,loaded:void 0,broken:!1,x:0,y:0,touched:!1,maskTouched:!1,rotate:0,scale:1,CX:0,CY:0,lastX:0,lastY:0,lastCX:0,lastCY:0,lastScale:1,touchTime:0,touchLength:0,pause:!0,stopRaf:!0,reach:void 0};function z({item:{src:n,render:o,width:r=0,height:a=0,originRef:c},visible:l,speed:u,easing:d,wrapClassName:h,className:f,style:p,loadingElement:w,brokenElement:C,onPhotoTap:k,onMaskTap:_,onReachMove:P,onReachUp:Y,onPhotoResize:X,isActive:R,expose:L}){const[F,D]=g(B),z=t(0),j=H(),{naturalWidth:q=r,naturalHeight:K=a,width:U=r,height:G=a,loaded:J=!n,broken:Q,x:Z,y:ee,touched:te,stopRaf:ne,maskTouched:oe,rotate:ie,scale:re,CX:ae,CY:ce,lastX:se,lastY:le,lastCX:ue,lastCY:de,lastScale:he,touchTime:me,touchLength:fe,pause:ve,reach:ge}=F,pe=v({onScale:e=>we(b(e)),onRotate(e){ie!==e&&(L({rotate:e}),D(m({rotate:e},S(q,K,e))))}});function we(e,t,n){re!==e&&(L({scale:e}),D(m({scale:e},W(Z,ee,U,G,re,e,t,n),e<=1&&{x:0,y:0})))}const xe=T((e,t,n=0)=>{if((te||oe)&&R){const[o,i]=$(ie,U,G);if(0===n&&0===z.current){const n=Math.abs(e-ae)<=20,o=Math.abs(t-ce)<=20;if(n&&o)return void D({lastCX:e,lastCY:t});z.current=n?t>ce?3:2:1}const r=e-ue,a=t-de;let c;if(0===n){const[n]=N(r+se,re,o,innerWidth),[s]=N(a+le,re,i,innerHeight);c=((e,t,n,o)=>t&&1===e||"x"===o?"x":n&&e>1||"y"===o?"y":void 0)(z.current,n,s,ge),void 0!==c&&P(c,e,t,re)}if("x"===c||oe)return void D({reach:"x"});const s=b(re+(n-fe)/100/2*re,q/U,.2);L({scale:s}),D(m({touchLength:n,reach:c,scale:s},W(Z,ee,U,G,re,s,e,t,r,a)))}},{maxWait:8});function Ce(e){return!ne&&!te&&(j.current&&D(m({},e,{pause:l})),j.current)}const be=function(e,t,n){const o=v({X:e=>Ce({x:e}),Y:e=>Ce({y:e}),S:e=>{return t=e,j.current&&(L({scale:t}),D({scale:t})),!te&&j.current;var t}});return(e,t,n,i,r,a,c,s,l,u,d)=>{const[h,m]=$(u,r,a),[f,v]=N(e,s,h,innerWidth),[g,p]=N(t,s,m,innerHeight),w=Date.now()-d;if(w>=200||s!=c||Math.abs(l-c)>1){const{x:n,y:i}=W(e,t,r,a,c,s),l=f?v:n!==e?n:null,u=g?p:i!==t?i:null;return null!==l&&A(e,l,o.X),null!==u&&A(t,u,o.Y),void(s!=c&&A(c,s,o.S))}const x=(e-n)/w,C=(t-i)/w,b=Math.sqrt(x**2+C**2);let y=!1,E=!1;!function(e,t){let n,o=e,i=0,r=0;const a=r=>{n||(n=r);const a=r-n,l=Math.sign(e),u=-.001*l,d=Math.sign(-o)*o**2*2e-4,h=o*a+(u+d)*a**2/2;o+=(u+d)*a,i+=h,n=r,l*o<=0?s():t(i)?c():s()};function c(){r=requestAnimationFrame(a)}function s(){cancelAnimationFrame(r)}c()}(b,n=>{const i=e+n*(x/b),r=t+n*(C/b),[a,s]=N(i,c,h,innerWidth),[l,u]=N(r,c,m,innerHeight);if(a&&!y&&(y=!0,f?A(i,s,o.X):V(s,i+(i-s),o.X)),l&&!E&&(E=!0,g?A(r,u,o.Y):V(u,r+(r-u),o.Y)),y&&E)return!1;const d=y||o.X(s),v=E||o.Y(u);return d&&v})}}(),ye=function(e,n){const o=t(0),i=T((...t)=>{o.current=0,e(...t)},{wait:300});return function(...e){o.current+=1,i(...e),o.current>=2&&(i.cancel(),o.current=0,((e,t)=>{ge||we(1!==re?1:Math.max(2,q/U),e,t)})(...e))}}(k);function Ee(e,t){if(z.current=0,(te||oe)&&R){D({touched:!1,maskTouched:!1,pause:!1,stopRaf:!1,reach:void 0});const n=b(re,q/U);if(be(Z,ee,se,le,U,G,re,n,he,ie,me),Y(e,t),ae===e&&ce===t){if(te)return void ye(e,t);oe&&_(e,t)}}}function ke(e,t,n=0){D({touched:!0,CX:e,CY:t,lastCX:e,lastCY:t,lastX:Z,lastY:ee,lastScale:re,touchLength:n,touchTime:Date.now()})}function _e(e){D({maskTouched:!0,CX:e.clientX,CY:e.clientY,lastX:Z,lastY:ee})}E(x?void 0:"mousemove",e=>{e.preventDefault(),xe(e.clientX,e.clientY)}),E(x?void 0:"mouseup",e=>{Ee(e.clientX,e.clientY)}),E(x?"touchmove":void 0,e=>{e.preventDefault();const t=M(e);xe(...t)},{passive:!1}),E(x?"touchend":void 0,({changedTouches:e})=>{const t=e[0];Ee(t.clientX,t.clientY)},{passive:!1}),E("resize",T(()=>{J&&!te&&(D(S(q,K,ie)),X())},{maxWait:8})),y(()=>{R&&L(m({scale:re,rotate:ie},pe))},[R]);const[Pe,Ye,Xe,Me,Ne,We,$e,Se]=function(e,n,o,r,a,c,l,u,d,h){const[m,f,p]=function(e,n,o,i,r){const a=t(!1),[{lead:c,scale:s},l]=g({lead:!0,scale:o}),u=T(async e=>{r(!0),l({lead:!1,scale:e})},{wait:i});return y(()=>{a.current?(r(!1),l({lead:!0}),u(o)):a.current=!0},[o]),c?[e*s,n*s,o/s]:[e*o,n*o,1]}(c,l,u,d,h),[w,x]=function(e,n,o,r,a){const[c,l]=s(I),[u,d]=s(0),h=t(),m=v({OK:()=>e&&d(4)});function f(e){a(!1),d(e)}return i(()=>{if(h.current||(h.current=Date.now()),o){if(function(e,t){const n=e&&e.current;if(n&&1===n.nodeType){const{top:e,left:o,width:i,height:r}=n.getBoundingClientRect();t({T:e,L:o,W:i,H:r,FIT:"IMG"===n.tagName?getComputedStyle(n).objectFit:void 0})}}(n,l),e)return Date.now()-h.current<250?(d(1),requestAnimationFrame(()=>{d(2),requestAnimationFrame(()=>f(3))}),void setTimeout(m.OK,r)):void d(4);f(5)}},[e,o]),[u,c]}(e,n,o,d,h),{T:C,L:b,W:E,H:k,FIT:_}=x,P=innerWidth/2,Y=innerHeight/2,X=w<3||w>4;return[X?E?b:P:r+(P-c*u/2),X?E?C:Y:a+(Y-l*u/2),m,X&&_?m*(k/E):f,0===w?p:X?E/(c*u)||.01:p,X?_?1:0:1,w,_]}(l,c,J,Z,ee,U,G,re,u,e=>D({pause:e})),Te=`transform ${u}ms ${d}`,Ve={className:f,onMouseDown:x?void 0:function(e){e.stopPropagation(),ke(e.clientX,e.clientY,0)},onTouchStart:x?function(e){e.stopPropagation(),ke(...M(e))}:void 0,onWheel:function(e){if(!ge){const t=b(re-e.deltaY/100/2,q/U);D({stopRaf:!0}),we(t,e.clientX,e.clientY)}},style:{width:Xe,height:Me,opacity:We,objectFit:4===$e?void 0:Se,transform:ie?`rotate(${ie}deg)`:void 0,transition:$e>2?`${Te}, opacity ${u}ms ease, height ${$e<4?u/2:$e>4?u:0}ms ${d}`:void 0}};return e.createElement("div",{className:"PhotoView__PhotoWrap"+(h?` ${h}`:""),style:p,onMouseDown:!x&&R?_e:void 0,onTouchStart:x&&R?e=>_e(e.touches[0]):void 0},e.createElement("div",{className:"PhotoView__PhotoBox",style:{transform:`matrix(${Ne}, 0, 0, ${Ne}, ${Pe}, ${Ye})`,transition:te||ve?void 0:Te,willChange:R?"transform":void 0}},n?e.createElement(O,m({src:n,loaded:J,broken:Q},Ve,{onPhotoLoad:function(e){D(m({},e,e.loaded&&S(e.naturalWidth||0,e.naturalHeight||0,ie)))},loadingElement:w,brokenElement:C})):o&&o({attrs:Ve,scale:Ne,rotate:ie})))}const j={x:0,touched:!1,pause:!1,lastCX:void 0,lastCY:void 0,bg:void 0,lastBg:void 0,overlay:!0,minimal:!0,scale:1,rotate:0};function q(o){const{loop:i=3,speed:r,easing:c,photoClosable:l,maskClosable:u=!0,maskOpacity:d=w,pullClosable:h=!0,bannerVisible:m=!0,overlayRender:f,toolbarRender:p,className:b,maskClassName:M,photoClassName:N,photoWrapClassName:W,loadingElement:$,brokenElement:S,images:T,index:V=0,onIndexChange:R,visible:A,onClose:I,afterClose:H}=o,[L,F]=g(j),[D,O]=s(0),{x:B,touched:q,pause:K,lastCX:U,lastCY:G,bg:J=d,lastBg:Q,overlay:Z,minimal:ee,scale:te,rotate:ne,onScale:oe,onRotate:ie}=L,re=o.hasOwnProperty("index"),ae=re?V:D,ce=re?R:O,se=t(ae),le=T.length,ue=T[ae],de="boolean"==typeof i?i:le>i,[he,me,fe]=function(e,o){const[,i]=n(e=>!e,!1),r=t(0),[c,s]=function(n,o){const i=t(n);function c(e){i.current=e}return a(()=>{(t=>{e?(t(e),r.current=1):r.current=2})(c)},[n]),[i.current,c]}(e);return[c,r.current,function(){i(),2===r.current&&(s(!1),o&&o()),r.current=0}]}(A,H);y(()=>{if(he)return F({pause:!0,x:ae*-(innerWidth+20)}),void(se.current=ae);F(j)},[he]);const{close:ve,changeIndex:ge}=v({close(e){ie&&ie(0),F({overlay:!0,lastBg:J}),I(e)},changeIndex(e,t=!1){const n=de?se.current+(e-ae):e,o=le-1,i=C(n,0,o),r=de?n:i,a=innerWidth+20;F({touched:!1,lastCX:void 0,lastCY:void 0,x:-a*r,pause:t}),se.current=r,ce&&ce(de?e<0?o:e>o?0:e:i)}});function pe(e){return e?ve():F({overlay:!Z})}function we(){F({x:-(innerWidth+20)*ae,lastCX:void 0,lastCY:void 0,pause:!0}),se.current=ae}function xe(e,t,n,o){"x"===e?function(e){if(void 0===U)return void F({touched:!0,lastCX:e,x:B,pause:!1});const t=e-U;let n=t;!de&&(0===ae&&t>0||ae===le-1&&t<0)&&(n=t/2),F({touched:!0,lastCX:U,x:-(innerWidth+20)*se.current+n,pause:!1})}(t):"y"===e&&function(e,t){if(void 0===G)return void F({touched:!0,lastCY:e,bg:J,minimal:!0});const n=C(d,0,d-Math.abs(e-G)/100/4);F({touched:!0,lastCY:G,bg:1===t?n:d,minimal:1===t})}(n,o)}function Ce(e,t){const n=e-(null!=U?U:e),o=t-(null!=G?G:t);let i=!1;if(n<-40)return void ge(ae+1);if(n>40)return void ge(ae-1);const r=-(innerWidth+20)*se.current;Math.abs(o)>100&&ee&&h&&(i=!0,ve()),F({touched:!1,x:r,lastCX:void 0,lastCY:void 0,bg:d,overlay:!!i||Z})}E("keydown",e=>{if(A)switch(e.key){case"ArrowLeft":ge(ae-1,!0);break;case"ArrowRight":ge(ae+1,!0);break;case"Escape":ve()}});const be=function(e,t,n){return a(()=>{const o=e.length;return n?e.concat(e).concat(e).slice(o+t-1,o+t+2):e.slice(Math.max(t-1,0),Math.min(t+2,o+1))},[e,t,n])}(T,ae,de);if(!he)return null;const ye=Z&&!me,Ee=A?J:Q,ke=oe&&ie&&{images:T,index:ae,visible:A,onClose:ve,onIndexChange:ge,overlayVisible:ye,scale:te,rotate:ne,onScale:oe,onRotate:ie},_e=r?r(me):400,Pe=c?c(me):"cubic-bezier(0.25, 0.8, 0.25, 1)",Ye=r?r(3):600,Xe=c?c(3):"cubic-bezier(0.25, 0.8, 0.25, 1)";return e.createElement(k,{className:`PhotoView-Portal${ye?"":" PhotoView-Slider__clean"}${A?"":" PhotoView-Slider__willClose"}${b?` ${b}`:""}`,role:"dialog",onClick:e=>e.stopPropagation()},A&&e.createElement(X,null),e.createElement("div",{className:`PhotoView-Slider__Backdrop${M?` ${M}`:""}${1===me?" PhotoView-Slider__fadeIn":2===me?" PhotoView-Slider__fadeOut":""}`,style:{background:`rgba(0, 0, 0, ${Ee})`,transitionTimingFunction:Pe,transitionDuration:`${q?0:_e}ms`,animationDuration:`${_e}ms`},onAnimationEnd:fe}),m&&e.createElement("div",{className:"PhotoView-Slider__BannerWrap"},e.createElement("div",{className:"PhotoView-Slider__Counter"},ae+1," / ",le),e.createElement("div",{className:"PhotoView-Slider__BannerRight"},p&&ke&&p(ke),e.createElement(_,{className:"PhotoView-Slider__toolbarIcon",onClick:ve}))),be.map((t,n)=>{const o=de||0!==ae?se.current-1+n:ae+n;return e.createElement(z,{key:de?`${t.key}/${t.src}/${o}`:t.key,item:t,speed:_e,easing:Pe,visible:A,onReachMove:xe,onReachUp:Ce,onPhotoTap:()=>pe(l),onMaskTap:()=>pe(u),wrapClassName:W,className:N,style:{left:(innerWidth+20)*o+"px",transform:`translate3d(${B}px, 0px, 0)`,transition:q||K?void 0:`transform ${Ye}ms ${Xe}`},loadingElement:$,brokenElement:S,onPhotoResize:we,isActive:(ue&&ue.key)===t.key,expose:F})}),!x&&m&&e.createElement(e.Fragment,null,(de||0!==ae)&&e.createElement("div",{className:"PhotoView-Slider__ArrowLeft",onClick:()=>ge(ae-1,!0)},e.createElement(P,null)),(de||ae+1<le)&&e.createElement("div",{className:"PhotoView-Slider__ArrowRight",onClick:()=>ge(ae+1,!0)},e.createElement(Y,null))),f&&ke&&e.createElement("div",{className:"PhotoView-Slider__Overlay"},f(ke)))}const K=["children","onIndexChange","onVisibleChange"],U={images:[],visible:!1,index:0};function G(n){let{children:o,onIndexChange:i,onVisibleChange:r}=n,c=f(n,K);const[s,l]=g(U),u=t(0),{images:d,visible:h,index:w}=s,x=v({nextId:()=>u.current+=1,update(e){const t=d.findIndex(t=>t.key===e.key);if(t>-1){const n=d.slice();return n.splice(t,1,e),void l({images:n})}l(t=>({images:t.images.concat(e)}))},remove(e){const t=d.filter(t=>t.key!==e);l({images:t,index:Math.min(t.length-1,w)})},show(e){const t=d.findIndex(t=>t.key===e);l({visible:!0,index:t}),r&&r(!0,t,s)}}),C=v({close(){l({visible:!1}),r&&r(!1,w,s)},changeIndex(e){l({index:e}),i&&i(e,s)}}),b=a(()=>m({},s,x),[s,x]);return e.createElement(p.Provider,{value:b},o,e.createElement(q,m({images:d,visible:h,index:w,onIndexChange:C.changeIndex,onClose:C.close},c)))}const J=({src:e,render:n,width:o,height:r,children:a})=>{const c=l(p),s=function(e){const{current:n}=t({sign:!1,fn:void 0});return n.sign||(n.sign=!0,n.fn=c.nextId()),n.fn}(),h=t(null);i(()=>()=>{c.remove(s)},[]);const m=v({render:e=>n&&n(e),click(e){c.show(s),function(e,t){if(a){const e=a.props.onClick;e&&e(t)}}(0,e)}});return i(()=>{c.update({key:s,src:e,originRef:h,render:m.render,width:o,height:r})},[e]),a?u.only(d(a,{onClick:m.click,ref:h})):null};export{G as PhotoProvider,q as PhotoSlider,J as PhotoView}; | ||
import e,{useRef as t,useReducer as n,createContext as o,useEffect as r,useLayoutEffect as i,useMemo as a,useCallback as c,useState as s,useContext as l,Children as u,cloneElement as d}from"react";import{createPortal as h}from"react-dom";function m(){return m=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},m.apply(this,arguments)}function f(e,t){if(null==e)return{};var n,o,r={},i=Object.keys(e);for(o=0;o<i.length;o++)t.indexOf(n=i[o])>=0||(r[n]=e[n]);return r}function v(e){const{current:n}=t({fn:e,curr:void 0});if(n.fn=e,!n.curr){const t=Object.create(null);Object.keys(e).forEach(e=>{t[e]=(...t)=>n.fn[e].call(n.fn,...t)}),n.curr=t}return n.curr}function g(e){return n((e,t)=>m({},e,"function"==typeof t?t(e):t),e)}var p=o(void 0);const w=1,y="undefined"!=typeof window&&"ontouchstart"in window,x=(e,t,n)=>Math.max(Math.min(e,n),t),C=(e,t=0,n=0)=>x(e,1*(1-n),Math.max(6,t)*(1+n));var b="undefined"==typeof window||/ServerSideRendering/.test(navigator&&navigator.userAgent)?r:i;function E(e,n,o){const i=t(n);i.current=n,r(()=>{function t(e){i.current(e)}return e&&window.addEventListener(e,t,o),()=>{e&&window.removeEventListener(e,t)}},[e])}const k=t=>h(e.createElement("div",m({},t)),document.body);function _(t){return e.createElement("svg",m({width:"44",height:"44",viewBox:"0 0 768 768"},t),e.createElement("path",{d:"M607.5 205.5l-178.5 178.5 178.5 178.5-45 45-178.5-178.5-178.5 178.5-45-45 178.5-178.5-178.5-178.5 45-45 178.5 178.5 178.5-178.5z"}))}function P(t){return e.createElement("svg",m({width:"44",height:"44",viewBox:"0 0 768 768"},t),e.createElement("path",{d:"M640.5 352.5v63h-390l178.5 180-45 45-256.5-256.5 256.5-256.5 45 45-178.5 180h390z"}))}function Y(t){return e.createElement("svg",m({width:"44",height:"44",viewBox:"0 0 768 768"},t),e.createElement("path",{d:"M384 127.5l256.5 256.5-256.5 256.5-45-45 178.5-180h-390v-63h390l-178.5-180z"}))}function X(){return r(()=>{const{style:e}=document.body,t=e.overflow;return e.overflow="hidden",()=>{e.overflow=t}},[]),null}function M(e){const{clientX:t,clientY:n}=e.touches[0];if(e.touches.length>=2){const{clientX:o,clientY:r}=e.touches[1];return[(t+o)/2,(n+r)/2,Math.sqrt((o-t)**2+(r-n)**2)]}return[t,n,0]}const N=(e,t,n,o)=>{const r=n*t,i=(r-o)/2;let a,c=e;return r<=o?(a=1,c=0):e>0&&i-e<=0?(a=2,c=i):e<0&&i+e<=0&&(a=3,c=-i),[a,c]};function W(e,t,n,o,r,i,a=innerWidth/2,c=innerHeight/2,s=0,l=0){const[u]=N(e,i,n,innerWidth),[d]=N(t,i,o,innerHeight),h=innerWidth/2,m=innerHeight/2;return{x:a-i/r*(a-(h+e))-h+(o/n>=3&&n*i===innerWidth?0:u?s/2:s),y:c-i/r*(c-(m+t))-m+(d?l/2:l),lastCX:a,lastCY:c}}function $(e,t,n){const o=e%180!=0;return o?[n,t,o]:[t,n,o]}function S(e,t,n){const[o,r,i]=$(n,innerWidth,innerHeight);let a=0,c=o,s=r;const l=e/t*r,u=t/e*o;return e<o&&t<r?(c=e,s=t):e<o&&t>=r?c=l:e>=o&&t<r||e/t>o/r?s=u:t/e>=3&&!i?(s=u,a=(s-r)/2):c=l,{width:c,height:s,x:0,y:a,pause:!0}}function T(e,{leading:n=!1,maxWait:o,wait:r=o||0}){const i=t(e);i.current=e;const a=t(0),s=t(),l=()=>s.current&&clearTimeout(s.current),u=c((...e)=>{const t=Date.now();function c(){a.current=t,l(),i.current.apply(null,e)}const u=a.current,d=t-u;if(0===u&&(n&&c(),a.current=t),void 0!==o){if(d>o)return void c()}else d<r&&(a.current=t);l(),s.current=setTimeout(()=>{c(),a.current=0},r)},[r,o,n]);return u.cancel=l,u}const V=(e,t,n)=>A(e,t,n,100,e=>e,()=>A(t,e,n)),R=e=>1-(1-e)**4;function A(e,t,n,o=400,r=R,i){const a=t-e;if(0===a)return;const c=Date.now();let s=0;const l=()=>{const t=Math.min(1,(Date.now()-c)/o);n(e+r(t)*a)&&t<1?u():(cancelAnimationFrame(s),t>=1&&i&&i())};function u(){s=requestAnimationFrame(l)}u()}const I={T:0,L:0,W:0,H:0,FIT:void 0},H=()=>{const e=t(!1);return r(()=>(e.current=!0,()=>{e.current=!1}),[]),e},L=["className"];function F(t){let{className:n}=t,o=f(t,L);return e.createElement("div",m({className:`PhotoView__Spinner ${n}`},o),e.createElement("svg",{viewBox:"0 0 32 32",width:"36",height:"36",fill:"white"},e.createElement("path",{opacity:".25",d:"M16 0 A16 16 0 0 0 16 32 A16 16 0 0 0 16 0 M16 4 A12 12 0 0 1 16 28 A12 12 0 0 1 16 4"}),e.createElement("path",{d:"M16 0 A16 16 0 0 1 32 16 L28 16 A12 12 0 0 0 16 4z"})))}const D=["src","loaded","broken","className","onPhotoLoad","loadingElement","brokenElement"];function O(t){let{src:n,loaded:o,broken:r,className:i,onPhotoLoad:a,loadingElement:c,brokenElement:s}=t,l=f(t,D);const u=H();return n&&!r?e.createElement(e.Fragment,null,e.createElement("img",m({className:"PhotoView__Photo"+(i?` ${i}`:""),src:n,onLoad:function(e){const{naturalWidth:t,naturalHeight:n}=e.target;u.current&&a({loaded:!0,naturalWidth:t,naturalHeight:n})},onError:function(){u.current&&a({broken:!0})},alt:""},l)),!o&&(e.createElement("span",{className:"PhotoView__icon"},c)||e.createElement(F,{className:"PhotoView__icon"}))):s?e.createElement("span",{className:"PhotoView__icon"},"function"==typeof s?s({src:n}):s):null}const B={naturalWidth:void 0,naturalHeight:void 0,width:void 0,height:void 0,loaded:void 0,broken:!1,x:0,y:0,touched:!1,maskTouched:!1,rotate:0,scale:1,CX:0,CY:0,lastX:0,lastY:0,lastCX:0,lastCY:0,lastScale:1,touchTime:0,touchLength:0,pause:!0,stopRaf:!0,reach:void 0};function z({item:{src:n,render:o,width:i=0,height:a=0,originRef:c},visible:l,speed:u,easing:d,wrapClassName:h,className:f,style:p,loadingElement:w,brokenElement:x,onPhotoTap:k,onMaskTap:_,onReachMove:P,onReachUp:Y,onPhotoResize:X,isActive:R,expose:L}){const[F,D]=g(B),z=t(0),j=H(),{naturalWidth:q=i,naturalHeight:K=a,width:U=i,height:G=a,loaded:J=!n,broken:Q,x:Z,y:ee,touched:te,stopRaf:ne,maskTouched:oe,rotate:re,scale:ie,CX:ae,CY:ce,lastX:se,lastY:le,lastCX:ue,lastCY:de,lastScale:he,touchTime:me,touchLength:fe,pause:ve,reach:ge}=F,pe=v({onScale:e=>we(C(e)),onRotate(e){re!==e&&(L({rotate:e}),D(m({rotate:e},S(q,K,e))))}});function we(e,t,n){ie!==e&&(L({scale:e}),D(m({scale:e},W(Z,ee,U,G,ie,e,t,n),e<=1&&{x:0,y:0})))}const ye=T((e,t,n=0)=>{if((te||oe)&&R){const[o,r]=$(re,U,G);if(0===n&&0===z.current){const n=Math.abs(e-ae)<=20,o=Math.abs(t-ce)<=20;if(n&&o)return void D({lastCX:e,lastCY:t});z.current=n?t>ce?3:2:1}const i=e-ue,a=t-de;let c;if(0===n){const[n]=N(i+se,ie,o,innerWidth),[s]=N(a+le,ie,r,innerHeight);c=((e,t,n,o)=>t&&1===e||"x"===o?"x":n&&e>1||"y"===o?"y":void 0)(z.current,n,s,ge),void 0!==c&&P(c,e,t,ie)}if("x"===c||oe)return void D({reach:"x"});const s=C(ie+(n-fe)/100/2*ie,q/U,.2);L({scale:s}),D(m({touchLength:n,reach:c,scale:s},W(Z,ee,U,G,ie,s,e,t,i,a)))}},{maxWait:8});function xe(e){return!ne&&!te&&(j.current&&D(m({},e,{pause:l})),j.current)}const Ce=function(e,t,n){const o=v({X:e=>xe({x:e}),Y:e=>xe({y:e}),S:e=>{return t=e,j.current&&(L({scale:t}),D({scale:t})),!te&&j.current;var t}});return(e,t,n,r,i,a,c,s,l,u,d)=>{const[h,m]=$(u,i,a),[f,v]=N(e,s,h,innerWidth),[g,p]=N(t,s,m,innerHeight),w=Date.now()-d;if(w>=200||s!=c||Math.abs(l-c)>1){const{x:n,y:r}=W(e,t,i,a,c,s),l=f?v:n!==e?n:null,u=g?p:r!==t?r:null;return null!==l&&A(e,l,o.X),null!==u&&A(t,u,o.Y),void(s!=c&&A(c,s,o.S))}const y=(e-n)/w,x=(t-r)/w,C=Math.sqrt(y**2+x**2);let b=!1,E=!1;!function(e,t){let n,o=e,r=0,i=0;const a=i=>{n||(n=i);const a=i-n,l=Math.sign(e),u=-.001*l,d=Math.sign(-o)*o**2*2e-4,h=o*a+(u+d)*a**2/2;o+=(u+d)*a,r+=h,n=i,l*o<=0?s():t(r)?c():s()};function c(){i=requestAnimationFrame(a)}function s(){cancelAnimationFrame(i)}c()}(C,n=>{const r=e+n*(y/C),i=t+n*(x/C),[a,s]=N(r,c,h,innerWidth),[l,u]=N(i,c,m,innerHeight);if(a&&!b&&(b=!0,f?A(r,s,o.X):V(s,r+(r-s),o.X)),l&&!E&&(E=!0,g?A(i,u,o.Y):V(u,i+(i-u),o.Y)),b&&E)return!1;const d=b||o.X(s),v=E||o.Y(u);return d&&v})}}(),be=function(e,n){const o=t(0),r=T((...t)=>{o.current=0,e(...t)},{wait:300});return function(...e){o.current+=1,r(...e),o.current>=2&&(r.cancel(),o.current=0,((e,t)=>{ge||we(1!==ie?1:Math.max(2,q/U),e,t)})(...e))}}(k);function Ee(e,t){if(z.current=0,(te||oe)&&R){D({touched:!1,maskTouched:!1,pause:!1,stopRaf:!1,reach:void 0});const n=C(ie,q/U);if(Ce(Z,ee,se,le,U,G,ie,n,he,re,me),Y(e,t),ae===e&&ce===t){if(te)return void be(e,t);oe&&_(e,t)}}}function ke(e,t,n=0){D({touched:!0,CX:e,CY:t,lastCX:e,lastCY:t,lastX:Z,lastY:ee,lastScale:ie,touchLength:n,touchTime:Date.now()})}function _e(e){D({maskTouched:!0,CX:e.clientX,CY:e.clientY,lastX:Z,lastY:ee})}E(y?void 0:"mousemove",e=>{e.preventDefault(),ye(e.clientX,e.clientY)}),E(y?void 0:"mouseup",e=>{Ee(e.clientX,e.clientY)}),E(y?"touchmove":void 0,e=>{e.preventDefault();const t=M(e);ye(...t)},{passive:!1}),E(y?"touchend":void 0,({changedTouches:e})=>{const t=e[0];Ee(t.clientX,t.clientY)},{passive:!1}),E("resize",T(()=>{J&&!te&&(D(S(q,K,re)),X())},{maxWait:8})),b(()=>{R&&L(m({scale:ie,rotate:re},pe))},[R]);const[Pe,Ye,Xe,Me,Ne,We,$e,Se]=function(e,n,o,i,a,c,l,u,d,h){const[m,f,p]=function(e,n,o,r,i){const a=t(!1),[{lead:c,scale:s},l]=g({lead:!0,scale:o}),u=T(async e=>{i(!0),l({lead:!1,scale:e})},{wait:r});return b(()=>{a.current?(i(!1),l({lead:!0}),u(o)):a.current=!0},[o]),c?[e*s,n*s,o/s]:[e*o,n*o,1]}(c,l,u,d,h),[w,y]=function(e,n,o,i,a){const[c,l]=s(I),[u,d]=s(0),h=t(),m=v({OK:()=>e&&d(4)});function f(e){a(!1),d(e)}return r(()=>{if(h.current||(h.current=Date.now()),o){if(function(e,t){const n=e&&e.current;if(n&&1===n.nodeType){const{top:e,left:o,width:r,height:i}=n.getBoundingClientRect();t({T:e,L:o,W:r,H:i,FIT:"IMG"===n.tagName?getComputedStyle(n).objectFit:void 0})}}(n,l),e)return Date.now()-h.current<250?(d(1),requestAnimationFrame(()=>{d(2),requestAnimationFrame(()=>f(3))}),void setTimeout(m.OK,i)):void d(4);f(5)}},[e,o]),[u,c]}(e,n,o,d,h),{T:x,L:C,W:E,H:k,FIT:_}=y,P=innerWidth/2,Y=innerHeight/2,X=w<3||w>4;return[X?E?C:P:i+(P-c*u/2),X?E?x:Y:a+(Y-l*u/2),m,X&&_?m*(k/E):f,0===w?p:X?E/(c*u)||.01:p,X?_?1:0:1,w,_]}(l,c,J,Z,ee,U,G,ie,u,e=>D({pause:e})),Te=`transform ${u}ms ${d}`,Ve={className:f,onMouseDown:y?void 0:function(e){e.stopPropagation(),0===e.button&&ke(e.clientX,e.clientY,0)},onTouchStart:y?function(e){e.stopPropagation(),ke(...M(e))}:void 0,onWheel:function(e){if(!ge){const t=C(ie-e.deltaY/100/2,q/U);D({stopRaf:!0}),we(t,e.clientX,e.clientY)}},style:{width:Xe,height:Me,opacity:We,objectFit:4===$e?void 0:Se,transform:re?`rotate(${re}deg)`:void 0,transition:$e>2?`${Te}, opacity ${u}ms ease, height ${$e<4?u/2:$e>4?u:0}ms ${d}`:void 0}};return e.createElement("div",{className:"PhotoView__PhotoWrap"+(h?` ${h}`:""),style:p,onMouseDown:!y&&R?_e:void 0,onTouchStart:y&&R?e=>_e(e.touches[0]):void 0},e.createElement("div",{className:"PhotoView__PhotoBox",style:{transform:`matrix(${Ne}, 0, 0, ${Ne}, ${Pe}, ${Ye})`,transition:te||ve?void 0:Te,willChange:R?"transform":void 0}},n?e.createElement(O,m({src:n,loaded:J,broken:Q},Ve,{onPhotoLoad:function(e){D(m({},e,e.loaded&&S(e.naturalWidth||0,e.naturalHeight||0,re)))},loadingElement:w,brokenElement:x})):o&&o({attrs:Ve,scale:Ne,rotate:re})))}const j={x:0,touched:!1,pause:!1,lastCX:void 0,lastCY:void 0,bg:void 0,lastBg:void 0,overlay:!0,minimal:!0,scale:1,rotate:0};function q(o){const{loop:r=3,speed:i,easing:c,photoClosable:l,maskClosable:u=!0,maskOpacity:d=w,pullClosable:h=!0,bannerVisible:m=!0,overlayRender:f,toolbarRender:p,className:C,maskClassName:M,photoClassName:N,photoWrapClassName:W,loadingElement:$,brokenElement:S,images:T,index:V=0,onIndexChange:R,visible:A,onClose:I,afterClose:H}=o,[L,F]=g(j),[D,O]=s(0),{x:B,touched:q,pause:K,lastCX:U,lastCY:G,bg:J=d,lastBg:Q,overlay:Z,minimal:ee,scale:te,rotate:ne,onScale:oe,onRotate:re}=L,ie=o.hasOwnProperty("index"),ae=ie?V:D,ce=ie?R:O,se=t(ae),le=T.length,ue=T[ae],de="boolean"==typeof r?r:le>r,[he,me,fe]=function(e,o){const[,r]=n(e=>!e,!1),i=t(0),[c,s]=function(n,o){const r=t(n);function c(e){r.current=e}return a(()=>{(t=>{e?(t(e),i.current=1):i.current=2})(c)},[n]),[r.current,c]}(e);return[c,i.current,function(){r(),2===i.current&&(s(!1),o&&o()),i.current=0}]}(A,H);b(()=>{if(he)return F({pause:!0,x:ae*-(innerWidth+20)}),void(se.current=ae);F(j)},[he]);const{close:ve,changeIndex:ge}=v({close(e){re&&re(0),F({overlay:!0,lastBg:J}),I(e)},changeIndex(e,t=!1){const n=de?se.current+(e-ae):e,o=le-1,r=x(n,0,o),i=de?n:r,a=innerWidth+20;F({touched:!1,lastCX:void 0,lastCY:void 0,x:-a*i,pause:t}),se.current=i,ce&&ce(de?e<0?o:e>o?0:e:r)}});function pe(e){return e?ve():F({overlay:!Z})}function we(){F({x:-(innerWidth+20)*ae,lastCX:void 0,lastCY:void 0,pause:!0}),se.current=ae}function ye(e,t,n,o){"x"===e?function(e){if(void 0===U)return void F({touched:!0,lastCX:e,x:B,pause:!1});const t=e-U;let n=t;!de&&(0===ae&&t>0||ae===le-1&&t<0)&&(n=t/2),F({touched:!0,lastCX:U,x:-(innerWidth+20)*se.current+n,pause:!1})}(t):"y"===e&&function(e,t){if(void 0===G)return void F({touched:!0,lastCY:e,bg:J,minimal:!0});const n=x(d,0,d-Math.abs(e-G)/100/4);F({touched:!0,lastCY:G,bg:1===t?n:d,minimal:1===t})}(n,o)}function xe(e,t){const n=e-(null!=U?U:e),o=t-(null!=G?G:t);let r=!1;if(n<-40)return void ge(ae+1);if(n>40)return void ge(ae-1);const i=-(innerWidth+20)*se.current;Math.abs(o)>100&&ee&&h&&(r=!0,ve()),F({touched:!1,x:i,lastCX:void 0,lastCY:void 0,bg:d,overlay:!!r||Z})}E("keydown",e=>{if(A)switch(e.key){case"ArrowLeft":ge(ae-1,!0);break;case"ArrowRight":ge(ae+1,!0);break;case"Escape":ve()}});const Ce=function(e,t,n){return a(()=>{const o=e.length;return n?e.concat(e).concat(e).slice(o+t-1,o+t+2):e.slice(Math.max(t-1,0),Math.min(t+2,o+1))},[e,t,n])}(T,ae,de);if(!he)return null;const be=Z&&!me,Ee=A?J:Q,ke=oe&&re&&{images:T,index:ae,visible:A,onClose:ve,onIndexChange:ge,overlayVisible:be,overlay:ue.overlay,scale:te,rotate:ne,onScale:oe,onRotate:re},_e=i?i(me):400,Pe=c?c(me):"cubic-bezier(0.25, 0.8, 0.25, 1)",Ye=i?i(3):600,Xe=c?c(3):"cubic-bezier(0.25, 0.8, 0.25, 1)";return e.createElement(k,{className:`PhotoView-Portal${be?"":" PhotoView-Slider__clean"}${A?"":" PhotoView-Slider__willClose"}${C?` ${C}`:""}`,role:"dialog",onClick:e=>e.stopPropagation()},A&&e.createElement(X,null),e.createElement("div",{className:`PhotoView-Slider__Backdrop${M?` ${M}`:""}${1===me?" PhotoView-Slider__fadeIn":2===me?" PhotoView-Slider__fadeOut":""}`,style:{background:`rgba(0, 0, 0, ${Ee})`,transitionTimingFunction:Pe,transitionDuration:`${q?0:_e}ms`,animationDuration:`${_e}ms`},onAnimationEnd:fe}),m&&e.createElement("div",{className:"PhotoView-Slider__BannerWrap"},e.createElement("div",{className:"PhotoView-Slider__Counter"},ae+1," / ",le),e.createElement("div",{className:"PhotoView-Slider__BannerRight"},p&&ke&&p(ke),e.createElement(_,{className:"PhotoView-Slider__toolbarIcon",onClick:ve}))),Ce.map((t,n)=>{const o=de||0!==ae?se.current-1+n:ae+n;return e.createElement(z,{key:de?`${t.key}/${t.src}/${o}`:t.key,item:t,speed:_e,easing:Pe,visible:A,onReachMove:ye,onReachUp:xe,onPhotoTap:()=>pe(l),onMaskTap:()=>pe(u),wrapClassName:W,className:N,style:{left:(innerWidth+20)*o+"px",transform:`translate3d(${B}px, 0px, 0)`,transition:q||K?void 0:`transform ${Ye}ms ${Xe}`},loadingElement:$,brokenElement:S,onPhotoResize:we,isActive:(ue&&ue.key)===t.key,expose:F})}),!y&&m&&e.createElement(e.Fragment,null,(de||0!==ae)&&e.createElement("div",{className:"PhotoView-Slider__ArrowLeft",onClick:()=>ge(ae-1,!0)},e.createElement(P,null)),(de||ae+1<le)&&e.createElement("div",{className:"PhotoView-Slider__ArrowRight",onClick:()=>ge(ae+1,!0)},e.createElement(Y,null))),f&&ke&&e.createElement("div",{className:"PhotoView-Slider__Overlay"},f(ke)))}const K=["children","onIndexChange","onVisibleChange"],U={images:[],visible:!1,index:0};function G(n){let{children:o,onIndexChange:r,onVisibleChange:i}=n,c=f(n,K);const[s,l]=g(U),u=t(0),{images:d,visible:h,index:w}=s,y=v({nextId:()=>u.current+=1,update(e){const t=d.findIndex(t=>t.key===e.key);if(t>-1){const n=d.slice();return n.splice(t,1,e),void l({images:n})}l(t=>({images:t.images.concat(e)}))},remove(e){const t=d.filter(t=>t.key!==e);l({images:t,index:Math.min(t.length-1,w)})},show(e){const t=d.findIndex(t=>t.key===e);l({visible:!0,index:t}),i&&i(!0,t,s)}}),x=v({close(){l({visible:!1}),i&&i(!1,w,s)},changeIndex(e){l({index:e}),r&&r(e,s)}}),C=a(()=>m({},s,y),[s,y]);return e.createElement(p.Provider,{value:C},o,e.createElement(q,m({images:d,visible:h,index:w,onIndexChange:x.changeIndex,onClose:x.close},c)))}const J=({src:e,render:n,overlay:o,width:i,height:a,children:c})=>{const s=l(p),h=function(e){const{current:n}=t({sign:!1,fn:void 0});return n.sign||(n.sign=!0,n.fn=s.nextId()),n.fn}(),m=t(null);r(()=>()=>{s.remove(h)},[]);const f=v({render:e=>n&&n(e),click(e){s.show(h),function(e,t){if(c){const e=c.props.onClick;e&&e(t)}}(0,e)}});return r(()=>{s.update({key:h,src:e,originRef:m,render:f.render,overlay:o,width:i,height:a})},[e]),c?u.only(d(c,{onClick:f.click,ref:m})):null};export{G as PhotoProvider,q as PhotoSlider,J as PhotoView}; | ||
//# sourceMappingURL=react-photo-view.modern.js.map |
@@ -1,2 +0,2 @@ | ||
import e,{useRef as n,useReducer as t,createContext as r,useEffect as i,useLayoutEffect as o,useMemo as a,useCallback as c,useState as u,useContext as l,Children as s,cloneElement as d}from"react";import{createPortal as v}from"react-dom";function f(){return f=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},f.apply(this,arguments)}function h(e,n){if(null==e)return{};var t,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)n.indexOf(t=o[r])>=0||(i[t]=e[t]);return i}function m(e){var t=n({fn:e,curr:void 0}).current;if(t.fn=e,!t.curr){var r=Object.create(null);Object.keys(e).forEach(function(e){r[e]=function(){var n;return(n=t.fn[e]).call.apply(n,[t.fn].concat([].slice.call(arguments)))}}),t.curr=r}return t.curr}function g(e){return t(function(e,n){return f({},e,"function"==typeof n?n(e):n)},e)}var p=r(void 0),w="undefined"!=typeof window&&"ontouchstart"in window,y=function(e,n,t){return Math.max(Math.min(e,t),n)},x=function(e,n,t){return void 0===n&&(n=0),void 0===t&&(t=0),y(e,1*(1-t),Math.max(6,n)*(1+t))},C="undefined"==typeof window||/ServerSideRendering/.test(navigator&&navigator.userAgent)?i:o;function b(e,t,r){var o=n(t);o.current=t,i(function(){function n(e){o.current(e)}return e&&window.addEventListener(e,n,r),function(){e&&window.removeEventListener(e,n)}},[e])}var E=function(n){return v(e.createElement("div",f({},n)),document.body)};function k(n){return e.createElement("svg",f({width:"44",height:"44",viewBox:"0 0 768 768"},n),e.createElement("path",{d:"M607.5 205.5l-178.5 178.5 178.5 178.5-45 45-178.5-178.5-178.5 178.5-45-45 178.5-178.5-178.5-178.5 45-45 178.5 178.5 178.5-178.5z"}))}function P(n){return e.createElement("svg",f({width:"44",height:"44",viewBox:"0 0 768 768"},n),e.createElement("path",{d:"M640.5 352.5v63h-390l178.5 180-45 45-256.5-256.5 256.5-256.5 45 45-178.5 180h390z"}))}function _(n){return e.createElement("svg",f({width:"44",height:"44",viewBox:"0 0 768 768"},n),e.createElement("path",{d:"M384 127.5l256.5 256.5-256.5 256.5-45-45 178.5-180h-390v-63h390l-178.5-180z"}))}function M(){return i(function(){var e=document.body.style,n=e.overflow;return e.overflow="hidden",function(){e.overflow=n}},[]),null}function Y(e){var n=e.touches[0],t=n.clientX,r=n.clientY;if(e.touches.length>=2){var i=e.touches[1],o=i.clientX,a=i.clientY;return[(t+o)/2,(r+a)/2,Math.sqrt(Math.pow(o-t,2)+Math.pow(a-r,2))]}return[t,r,0]}var X=function(e,n,t,r){var i=t*n,o=(i-r)/2,a=void 0,c=e;return i<=r?(a=1,c=0):e>0&&o-e<=0?(a=2,c=o):e<0&&o+e<=0&&(a=3,c=-o),[a,c]};function N(e,n,t,r,i,o,a,c,u,l){void 0===a&&(a=innerWidth/2),void 0===c&&(c=innerHeight/2),void 0===u&&(u=0),void 0===l&&(l=0);var s=X(e,o,t,innerWidth)[0],d=X(n,o,r,innerHeight),v=innerWidth/2,f=innerHeight/2;return{x:a-o/i*(a-(v+e))-v+(r/t>=3&&t*o===innerWidth?0:s?u/2:u),y:c-o/i*(c-(f+n))-f+(d[0]?l/2:l),lastCX:a,lastCY:c}}function W(e,n,t){var r=e%180!=0;return r?[t,n,r]:[n,t,r]}function S(e,n,t){var r=W(t,innerWidth,innerHeight),i=r[0],o=r[1],a=0,c=i,u=o,l=e/n*o,s=n/e*i;return e<i&&n<o?(c=e,u=n):e<i&&n>=o?c=l:e>=i&&n<o||e/n>i/o?u=s:n/e>=3&&!r[2]?a=((u=s)-o)/2:c=l,{width:c,height:u,x:0,y:a,pause:!0}}function T(e,t){var r=t.leading,i=void 0!==r&&r,o=t.maxWait,a=t.wait,u=void 0===a?o||0:a,l=n(e);l.current=e;var s=n(0),d=n(),v=function(){return d.current&&clearTimeout(d.current)},f=c(function(){var e=[].slice.call(arguments),n=Date.now();function t(){s.current=n,v(),l.current.apply(null,e)}var r=s.current,a=n-r;if(0===r&&(i&&t(),s.current=n),void 0!==o){if(a>o)return void t()}else a<u&&(s.current=n);v(),d.current=setTimeout(function(){t(),s.current=0},u)},[u,o,i]);return f.cancel=v,f}var V=function(e,n,t){return A(e,n,t,100,function(e){return e},function(){return A(n,e,t)})},R=function(e){return 1-Math.pow(1-e,4)};function A(e,n,t,r,i,o){void 0===r&&(r=400),void 0===i&&(i=R);var a=n-e;if(0!==a){var c=Date.now(),u=0,l=function(){var n=Math.min(1,(Date.now()-c)/r);t(e+i(n)*a)&&n<1?s():(cancelAnimationFrame(u),n>=1&&o&&o())};s()}function s(){u=requestAnimationFrame(l)}}var I={T:0,L:0,W:0,H:0,FIT:void 0},H=function(){var e=n(!1);return i(function(){return e.current=!0,function(){e.current=!1}},[]),e},L=["className"];function F(n){var t=n.className,r=h(n,L);return e.createElement("div",f({className:"PhotoView__Spinner "+t},r),e.createElement("svg",{viewBox:"0 0 32 32",width:"36",height:"36",fill:"white"},e.createElement("path",{opacity:".25",d:"M16 0 A16 16 0 0 0 16 32 A16 16 0 0 0 16 0 M16 4 A12 12 0 0 1 16 28 A12 12 0 0 1 16 4"}),e.createElement("path",{d:"M16 0 A16 16 0 0 1 32 16 L28 16 A12 12 0 0 0 16 4z"})))}var D=["src","loaded","broken","className","onPhotoLoad","loadingElement","brokenElement"];function O(n){var t=n.src,r=n.loaded,i=n.broken,o=n.className,a=n.onPhotoLoad,c=n.loadingElement,u=n.brokenElement,l=h(n,D),s=H();return t&&!i?e.createElement(e.Fragment,null,e.createElement("img",f({className:"PhotoView__Photo"+(o?" "+o:""),src:t,onLoad:function(e){var n=e.target;s.current&&a({loaded:!0,naturalWidth:n.naturalWidth,naturalHeight:n.naturalHeight})},onError:function(){s.current&&a({broken:!0})},alt:""},l)),!r&&(e.createElement("span",{className:"PhotoView__icon"},c)||e.createElement(F,{className:"PhotoView__icon"}))):u?e.createElement("span",{className:"PhotoView__icon"},"function"==typeof u?u({src:t}):u):null}var B={naturalWidth:void 0,naturalHeight:void 0,width:void 0,height:void 0,loaded:void 0,broken:!1,x:0,y:0,touched:!1,maskTouched:!1,rotate:0,scale:1,CX:0,CY:0,lastX:0,lastY:0,lastCX:0,lastCY:0,lastScale:1,touchTime:0,touchLength:0,pause:!0,stopRaf:!0,reach:void 0};function z(t){var r=t.item,o=r.src,a=r.render,c=r.width,l=void 0===c?0:c,s=r.height,d=void 0===s?0:s,v=r.originRef,h=t.visible,p=t.speed,y=t.easing,E=t.wrapClassName,k=t.className,P=t.style,_=t.loadingElement,M=t.brokenElement,R=t.onPhotoTap,L=t.onMaskTap,F=t.onReachMove,D=t.onReachUp,z=t.onPhotoResize,j=t.isActive,q=t.expose,K=g(B),U=K[0],G=K[1],J=n(0),Q=H(),Z=U.naturalWidth,$=void 0===Z?l:Z,ee=U.naturalHeight,ne=void 0===ee?d:ee,te=U.width,re=void 0===te?l:te,ie=U.height,oe=void 0===ie?d:ie,ae=U.loaded,ce=void 0===ae?!o:ae,ue=U.broken,le=U.x,se=U.y,de=U.touched,ve=U.stopRaf,fe=U.maskTouched,he=U.rotate,me=U.scale,ge=U.CX,pe=U.CY,we=U.lastX,ye=U.lastY,xe=U.lastCX,Ce=U.lastCY,be=U.lastScale,Ee=U.touchTime,ke=U.touchLength,Pe=U.pause,_e=U.reach,Me=m({onScale:function(e){return Ye(x(e))},onRotate:function(e){he!==e&&(q({rotate:e}),G(f({rotate:e},S($,ne,e))))}});function Ye(e,n,t){me!==e&&(q({scale:e}),G(f({scale:e},N(le,se,re,oe,me,e,n,t),e<=1&&{x:0,y:0})))}var Xe=T(function(e,n,t){if(void 0===t&&(t=0),(de||fe)&&j){var r=W(he,re,oe),i=r[0],o=r[1];if(0===t&&0===J.current){var a=Math.abs(e-ge)<=20,c=Math.abs(n-pe)<=20;if(a&&c)return void G({lastCX:e,lastCY:n});J.current=a?n>pe?3:2:1}var u=e-xe,l=n-Ce,s=void 0;if(0===t){var d=X(u+we,me,i,innerWidth)[0],v=X(l+ye,me,o,innerHeight);s=function(e,n,t,r){return n&&1===e||"x"===r?"x":t&&e>1||"y"===r?"y":void 0}(J.current,d,v[0],_e),void 0!==s&&F(s,e,n,me)}if("x"===s||fe)return void G({reach:"x"});var h=x(me+(t-ke)/100/2*me,$/re,.2);q({scale:h}),G(f({touchLength:t,reach:s,scale:h},N(le,se,re,oe,me,h,e,n,u,l)))}},{maxWait:8});function Ne(e){return!ve&&!de&&(Q.current&&G(f({},e,{pause:h})),Q.current)}var We,Se,Te,Ve,Re,Ae,Ie,He,Le=(Re=function(e){return Ne({x:e})},Ae=function(e){return Ne({y:e})},Ie=function(e){return Q.current&&(q({scale:e}),G({scale:e})),!de&&Q.current},He=m({X:function(e){return Re(e)},Y:function(e){return Ae(e)},S:function(e){return Ie(e)}}),function(e,n,t,r,i,o,a,c,u,l,s){var d=W(l,i,o),v=d[0],f=d[1],h=X(e,c,v,innerWidth),m=h[0],g=h[1],p=X(n,c,f,innerHeight),w=p[0],y=p[1],x=Date.now()-s;if(x>=200||c!=a||Math.abs(u-a)>1){var C=N(e,n,i,o,a,c),b=C.x,E=C.y,k=m?g:b!==e?b:null,P=w?y:E!==n?E:null;return null!==k&&A(e,k,He.X),null!==P&&A(n,P,He.Y),void(c!=a&&A(a,c,He.S))}var _=(e-t)/x,M=(n-r)/x,Y=Math.sqrt(Math.pow(_,2)+Math.pow(M,2)),S=!1,T=!1;!function(e,n){var t=e,r=0,i=void 0,o=0,a=function(o){i||(i=o);var a=o-i,l=Math.sign(e),s=-.001*l,d=Math.sign(-t)*Math.pow(t,2)*2e-4,v=t*a+(s+d)*Math.pow(a,2)/2;r+=v,i=o,l*(t+=(s+d)*a)<=0?u():n(r)?c():u()};function c(){o=requestAnimationFrame(a)}function u(){cancelAnimationFrame(o)}c()}(Y,function(t){var r=e+t*(_/Y),i=n+t*(M/Y),o=X(r,a,v,innerWidth),c=o[0],u=o[1],l=X(i,a,f,innerHeight),s=l[0],d=l[1];if(c&&!S&&(S=!0,m?A(r,u,He.X):V(u,r+(r-u),He.X)),s&&!T&&(T=!0,w?A(i,d,He.Y):V(d,i+(i-d),He.Y)),S&&T)return!1;var h=S||He.X(u),g=T||He.Y(d);return h&&g})}),Fe=(We=R,Se=function(e,n){_e||Ye(1!==me?1:Math.max(2,$/re),e,n)},Te=n(0),Ve=T(function(){Te.current=0,We.apply(void 0,[].slice.call(arguments))},{wait:300}),function(){var e=[].slice.call(arguments);Te.current+=1,Ve.apply(void 0,e),Te.current>=2&&(Ve.cancel(),Te.current=0,Se.apply(void 0,e))});function De(e,n){if(J.current=0,(de||fe)&&j){G({touched:!1,maskTouched:!1,pause:!1,stopRaf:!1,reach:void 0});var t=x(me,$/re);if(Le(le,se,we,ye,re,oe,me,t,be,he,Ee),D(e,n),ge===e&&pe===n){if(de)return void Fe(e,n);fe&&L(e,n)}}}function Oe(e,n,t){void 0===t&&(t=0),G({touched:!0,CX:e,CY:n,lastCX:e,lastCY:n,lastX:le,lastY:se,lastScale:me,touchLength:t,touchTime:Date.now()})}function Be(e){G({maskTouched:!0,CX:e.clientX,CY:e.clientY,lastX:le,lastY:se})}b(w?void 0:"mousemove",function(e){e.preventDefault(),Xe(e.clientX,e.clientY)}),b(w?void 0:"mouseup",function(e){De(e.clientX,e.clientY)}),b(w?"touchmove":void 0,function(e){e.preventDefault();var n=Y(e);Xe.apply(void 0,n)},{passive:!1}),b(w?"touchend":void 0,function(e){var n=e.changedTouches[0];De(n.clientX,n.clientY)},{passive:!1}),b("resize",T(function(){ce&&!de&&(G(S($,ne,he)),z())},{maxWait:8})),C(function(){j&&q(f({scale:me,rotate:he},Me))},[j]);var ze=function(e,t,r,o,a,c,l,s,d,v){var f=function(e,t,r,i,o){var a=n(!1),c=g({lead:!0,scale:r}),u=c[0],l=u.lead,s=u.scale,d=c[1],v=T(function(e){try{return o(!0),d({lead:!1,scale:e}),Promise.resolve()}catch(e){return Promise.reject(e)}},{wait:i});return C(function(){a.current?(o(!1),d({lead:!0}),v(r)):a.current=!0},[r]),l?[e*s,t*s,r/s]:[e*r,t*r,1]}(c,l,s,d,v),h=f[0],p=f[1],w=f[2],y=function(e,t,r,o,a){var c=u(I),l=c[0],s=c[1],d=u(0),v=d[0],f=d[1],h=n(),g=m({OK:function(){return e&&f(4)}});function p(e){a(!1),f(e)}return i(function(){if(h.current||(h.current=Date.now()),r){if(function(e,n){var t=e&&e.current;if(t&&1===t.nodeType){var r=t.getBoundingClientRect();n({T:r.top,L:r.left,W:r.width,H:r.height,FIT:"IMG"===t.tagName?getComputedStyle(t).objectFit:void 0})}}(t,s),e)return Date.now()-h.current<250?(f(1),requestAnimationFrame(function(){f(2),requestAnimationFrame(function(){return p(3)})}),void setTimeout(g.OK,o)):void f(4);p(5)}},[e,r]),[v,l]}(e,t,r,d,v),x=y[0],b=y[1],E=b.W,k=b.FIT,P=innerWidth/2,_=innerHeight/2,M=x<3||x>4;return[M?E?b.L:P:o+(P-c*s/2),M?E?b.T:_:a+(_-l*s/2),h,M&&k?h*(b.H/E):p,0===x?w:M?E/(c*s)||.01:w,M?k?1:0:1,x,k]}(h,v,ce,le,se,re,oe,me,p,function(e){return G({pause:e})}),je=ze[4],qe=ze[6],Ke="transform "+p+"ms "+y,Ue={className:k,onMouseDown:w?void 0:function(e){e.stopPropagation(),Oe(e.clientX,e.clientY,0)},onTouchStart:w?function(e){e.stopPropagation(),Oe.apply(void 0,Y(e))}:void 0,onWheel:function(e){if(!_e){var n=x(me-e.deltaY/100/2,$/re);G({stopRaf:!0}),Ye(n,e.clientX,e.clientY)}},style:{width:ze[2],height:ze[3],opacity:ze[5],objectFit:4===qe?void 0:ze[7],transform:he?"rotate("+he+"deg)":void 0,transition:qe>2?Ke+", opacity "+p+"ms ease, height "+(qe<4?p/2:qe>4?p:0)+"ms "+y:void 0}};return e.createElement("div",{className:"PhotoView__PhotoWrap"+(E?" "+E:""),style:P,onMouseDown:!w&&j?Be:void 0,onTouchStart:w&&j?function(e){return Be(e.touches[0])}:void 0},e.createElement("div",{className:"PhotoView__PhotoBox",style:{transform:"matrix("+je+", 0, 0, "+je+", "+ze[0]+", "+ze[1]+")",transition:de||Pe?void 0:Ke,willChange:j?"transform":void 0}},o?e.createElement(O,f({src:o,loaded:ce,broken:ue},Ue,{onPhotoLoad:function(e){G(f({},e,e.loaded&&S(e.naturalWidth||0,e.naturalHeight||0,he)))},loadingElement:_,brokenElement:M})):a&&a({attrs:Ue,scale:je,rotate:he})))}var j={x:0,touched:!1,pause:!1,lastCX:void 0,lastCY:void 0,bg:void 0,lastBg:void 0,overlay:!0,minimal:!0,scale:1,rotate:0};function q(r){var i=r.loop,o=void 0===i?3:i,c=r.speed,l=r.easing,s=r.photoClosable,d=r.maskClosable,v=void 0===d||d,f=r.maskOpacity,h=void 0===f?1:f,p=r.pullClosable,x=void 0===p||p,Y=r.bannerVisible,X=void 0===Y||Y,N=r.overlayRender,W=r.toolbarRender,S=r.className,T=r.maskClassName,V=r.photoClassName,R=r.photoWrapClassName,A=r.loadingElement,I=r.brokenElement,H=r.images,L=r.index,F=void 0===L?0:L,D=r.onIndexChange,O=r.visible,B=r.onClose,q=r.afterClose,K=g(j),U=K[0],G=K[1],J=u(0),Q=J[0],Z=J[1],$=U.x,ee=U.touched,ne=U.pause,te=U.lastCX,re=U.lastCY,ie=U.bg,oe=void 0===ie?h:ie,ae=U.lastBg,ce=U.overlay,ue=U.minimal,le=U.scale,se=U.rotate,de=U.onScale,ve=U.onRotate,fe=r.hasOwnProperty("index"),he=fe?F:Q,me=fe?D:Z,ge=n(he),pe=H.length,we=H[he],ye="boolean"==typeof o?o:pe>o,xe=function(e,r){var i=t(function(e){return!e},!1)[1],o=n(0),c=function(t,r){var i=n(t);function c(e){i.current=e}return a(function(){!function(n){e?(n(e),o.current=1):o.current=2}(c)},[t]),[i.current,c]}(e),u=c[1];return[c[0],o.current,function(){i(),2===o.current&&(u(!1),r&&r()),o.current=0}]}(O,q),Ce=xe[0],be=xe[1],Ee=xe[2];C(function(){if(Ce)return G({pause:!0,x:he*-(innerWidth+20)}),void(ge.current=he);G(j)},[Ce]);var ke=m({close:function(e){ve&&ve(0),G({overlay:!0,lastBg:oe}),B(e)},changeIndex:function(e,n){void 0===n&&(n=!1);var t=ye?ge.current+(e-he):e,r=pe-1,i=y(t,0,r),o=ye?t:i,a=innerWidth+20;G({touched:!1,lastCX:void 0,lastCY:void 0,x:-a*o,pause:n}),ge.current=o,me&&me(ye?e<0?r:e>r?0:e:i)}}),Pe=ke.close,_e=ke.changeIndex;function Me(e){return e?Pe():G({overlay:!ce})}function Ye(){G({x:-(innerWidth+20)*he,lastCX:void 0,lastCY:void 0,pause:!0}),ge.current=he}function Xe(e,n,t,r){"x"===e?function(e){if(void 0!==te){var n=e-te,t=n;!ye&&(0===he&&n>0||he===pe-1&&n<0)&&(t=n/2),G({touched:!0,lastCX:te,x:-(innerWidth+20)*ge.current+t,pause:!1})}else G({touched:!0,lastCX:e,x:$,pause:!1})}(n):"y"===e&&function(e,n){if(void 0!==re){var t=y(h,0,h-Math.abs(e-re)/100/4);G({touched:!0,lastCY:re,bg:1===n?t:h,minimal:1===n})}else G({touched:!0,lastCY:e,bg:oe,minimal:!0})}(t,r)}function Ne(e,n){var t=e-(null!=te?te:e),r=n-(null!=re?re:n),i=!1;if(t<-40)_e(he+1);else if(t>40)_e(he-1);else{var o=-(innerWidth+20)*ge.current;Math.abs(r)>100&&ue&&x&&(i=!0,Pe()),G({touched:!1,x:o,lastCX:void 0,lastCY:void 0,bg:h,overlay:!!i||ce})}}b("keydown",function(e){if(O)switch(e.key){case"ArrowLeft":_e(he-1,!0);break;case"ArrowRight":_e(he+1,!0);break;case"Escape":Pe()}});var We=function(e,n,t){return a(function(){var r=e.length;return t?e.concat(e).concat(e).slice(r+n-1,r+n+2):e.slice(Math.max(n-1,0),Math.min(n+2,r+1))},[e,n,t])}(H,he,ye);if(!Ce)return null;var Se=ce&&!be,Te=O?oe:ae,Ve=de&&ve&&{images:H,index:he,visible:O,onClose:Pe,onIndexChange:_e,overlayVisible:Se,scale:le,rotate:se,onScale:de,onRotate:ve},Re=c?c(be):400,Ae=l?l(be):"cubic-bezier(0.25, 0.8, 0.25, 1)",Ie=c?c(3):600,He=l?l(3):"cubic-bezier(0.25, 0.8, 0.25, 1)";return e.createElement(E,{className:"PhotoView-Portal"+(Se?"":" PhotoView-Slider__clean")+(O?"":" PhotoView-Slider__willClose")+(S?" "+S:""),role:"dialog",onClick:function(e){return e.stopPropagation()}},O&&e.createElement(M,null),e.createElement("div",{className:"PhotoView-Slider__Backdrop"+(T?" "+T:"")+(1===be?" PhotoView-Slider__fadeIn":2===be?" PhotoView-Slider__fadeOut":""),style:{background:"rgba(0, 0, 0, "+Te+")",transitionTimingFunction:Ae,transitionDuration:(ee?0:Re)+"ms",animationDuration:Re+"ms"},onAnimationEnd:Ee}),X&&e.createElement("div",{className:"PhotoView-Slider__BannerWrap"},e.createElement("div",{className:"PhotoView-Slider__Counter"},he+1," / ",pe),e.createElement("div",{className:"PhotoView-Slider__BannerRight"},W&&Ve&&W(Ve),e.createElement(k,{className:"PhotoView-Slider__toolbarIcon",onClick:Pe}))),We.map(function(n,t){var r=ye||0!==he?ge.current-1+t:he+t;return e.createElement(z,{key:ye?n.key+"/"+n.src+"/"+r:n.key,item:n,speed:Re,easing:Ae,visible:O,onReachMove:Xe,onReachUp:Ne,onPhotoTap:function(){return Me(s)},onMaskTap:function(){return Me(v)},wrapClassName:R,className:V,style:{left:(innerWidth+20)*r+"px",transform:"translate3d("+$+"px, 0px, 0)",transition:ee||ne?void 0:"transform "+Ie+"ms "+He},loadingElement:A,brokenElement:I,onPhotoResize:Ye,isActive:(we&&we.key)===n.key,expose:G})}),!w&&X&&e.createElement(e.Fragment,null,(ye||0!==he)&&e.createElement("div",{className:"PhotoView-Slider__ArrowLeft",onClick:function(){return _e(he-1,!0)}},e.createElement(P,null)),(ye||he+1<pe)&&e.createElement("div",{className:"PhotoView-Slider__ArrowRight",onClick:function(){return _e(he+1,!0)}},e.createElement(_,null))),N&&Ve&&e.createElement("div",{className:"PhotoView-Slider__Overlay"},N(Ve)))}var K=["children","onIndexChange","onVisibleChange"],U={images:[],visible:!1,index:0};function G(t){var r=t.children,i=t.onIndexChange,o=t.onVisibleChange,c=h(t,K),u=g(U),l=u[0],s=u[1],d=n(0),v=l.images,w=l.visible,y=l.index,x=m({nextId:function(){return d.current+=1},update:function(e){var n=v.findIndex(function(n){return n.key===e.key});if(n>-1){var t=v.slice();return t.splice(n,1,e),void s({images:t})}s(function(n){return{images:n.images.concat(e)}})},remove:function(e){var n=v.filter(function(n){return n.key!==e});s({images:n,index:Math.min(n.length-1,y)})},show:function(e){var n=v.findIndex(function(n){return n.key===e});s({visible:!0,index:n}),o&&o(!0,n,l)}}),C=m({close:function(){s({visible:!1}),o&&o(!1,y,l)},changeIndex:function(e){s({index:e}),i&&i(e,l)}}),b=a(function(){return f({},l,x)},[l,x]);return e.createElement(p.Provider,{value:b},r,e.createElement(q,f({images:v,visible:w,index:y,onIndexChange:C.changeIndex,onClose:C.close},c)))}var J=function(e){var t,r,o=e.src,a=e.render,c=e.width,u=e.height,v=e.children,f=l(p),h=(t=function(){return f.nextId()},(r=n({sign:!1,fn:void 0}).current).sign||(r.sign=!0,r.fn=t()),r.fn),g=n(null);i(function(){return function(){f.remove(h)}},[]);var w=m({render:function(e){return a&&a(e)},click:function(e){f.show(h),function(e,n){if(v){var t=v.props.onClick;t&&t(n)}}(0,e)}});return i(function(){f.update({key:h,src:o,originRef:g,render:w.render,width:c,height:u})},[o]),v?s.only(d(v,{onClick:w.click,ref:g})):null};export{G as PhotoProvider,q as PhotoSlider,J as PhotoView}; | ||
import e,{useRef as n,useReducer as t,createContext as r,useEffect as i,useLayoutEffect as o,useMemo as a,useCallback as c,useState as u,useContext as l,Children as s,cloneElement as d}from"react";import{createPortal as v}from"react-dom";function f(){return f=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},f.apply(this,arguments)}function h(e,n){if(null==e)return{};var t,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)n.indexOf(t=o[r])>=0||(i[t]=e[t]);return i}function m(e){var t=n({fn:e,curr:void 0}).current;if(t.fn=e,!t.curr){var r=Object.create(null);Object.keys(e).forEach(function(e){r[e]=function(){var n;return(n=t.fn[e]).call.apply(n,[t.fn].concat([].slice.call(arguments)))}}),t.curr=r}return t.curr}function g(e){return t(function(e,n){return f({},e,"function"==typeof n?n(e):n)},e)}var p=r(void 0),w="undefined"!=typeof window&&"ontouchstart"in window,y=function(e,n,t){return Math.max(Math.min(e,t),n)},x=function(e,n,t){return void 0===n&&(n=0),void 0===t&&(t=0),y(e,1*(1-t),Math.max(6,n)*(1+t))},C="undefined"==typeof window||/ServerSideRendering/.test(navigator&&navigator.userAgent)?i:o;function b(e,t,r){var o=n(t);o.current=t,i(function(){function n(e){o.current(e)}return e&&window.addEventListener(e,n,r),function(){e&&window.removeEventListener(e,n)}},[e])}var E=function(n){return v(e.createElement("div",f({},n)),document.body)};function k(n){return e.createElement("svg",f({width:"44",height:"44",viewBox:"0 0 768 768"},n),e.createElement("path",{d:"M607.5 205.5l-178.5 178.5 178.5 178.5-45 45-178.5-178.5-178.5 178.5-45-45 178.5-178.5-178.5-178.5 45-45 178.5 178.5 178.5-178.5z"}))}function P(n){return e.createElement("svg",f({width:"44",height:"44",viewBox:"0 0 768 768"},n),e.createElement("path",{d:"M640.5 352.5v63h-390l178.5 180-45 45-256.5-256.5 256.5-256.5 45 45-178.5 180h390z"}))}function _(n){return e.createElement("svg",f({width:"44",height:"44",viewBox:"0 0 768 768"},n),e.createElement("path",{d:"M384 127.5l256.5 256.5-256.5 256.5-45-45 178.5-180h-390v-63h390l-178.5-180z"}))}function M(){return i(function(){var e=document.body.style,n=e.overflow;return e.overflow="hidden",function(){e.overflow=n}},[]),null}function Y(e){var n=e.touches[0],t=n.clientX,r=n.clientY;if(e.touches.length>=2){var i=e.touches[1],o=i.clientX,a=i.clientY;return[(t+o)/2,(r+a)/2,Math.sqrt(Math.pow(o-t,2)+Math.pow(a-r,2))]}return[t,r,0]}var X=function(e,n,t,r){var i=t*n,o=(i-r)/2,a=void 0,c=e;return i<=r?(a=1,c=0):e>0&&o-e<=0?(a=2,c=o):e<0&&o+e<=0&&(a=3,c=-o),[a,c]};function N(e,n,t,r,i,o,a,c,u,l){void 0===a&&(a=innerWidth/2),void 0===c&&(c=innerHeight/2),void 0===u&&(u=0),void 0===l&&(l=0);var s=X(e,o,t,innerWidth)[0],d=X(n,o,r,innerHeight),v=innerWidth/2,f=innerHeight/2;return{x:a-o/i*(a-(v+e))-v+(r/t>=3&&t*o===innerWidth?0:s?u/2:u),y:c-o/i*(c-(f+n))-f+(d[0]?l/2:l),lastCX:a,lastCY:c}}function W(e,n,t){var r=e%180!=0;return r?[t,n,r]:[n,t,r]}function S(e,n,t){var r=W(t,innerWidth,innerHeight),i=r[0],o=r[1],a=0,c=i,u=o,l=e/n*o,s=n/e*i;return e<i&&n<o?(c=e,u=n):e<i&&n>=o?c=l:e>=i&&n<o||e/n>i/o?u=s:n/e>=3&&!r[2]?a=((u=s)-o)/2:c=l,{width:c,height:u,x:0,y:a,pause:!0}}function T(e,t){var r=t.leading,i=void 0!==r&&r,o=t.maxWait,a=t.wait,u=void 0===a?o||0:a,l=n(e);l.current=e;var s=n(0),d=n(),v=function(){return d.current&&clearTimeout(d.current)},f=c(function(){var e=[].slice.call(arguments),n=Date.now();function t(){s.current=n,v(),l.current.apply(null,e)}var r=s.current,a=n-r;if(0===r&&(i&&t(),s.current=n),void 0!==o){if(a>o)return void t()}else a<u&&(s.current=n);v(),d.current=setTimeout(function(){t(),s.current=0},u)},[u,o,i]);return f.cancel=v,f}var V=function(e,n,t){return A(e,n,t,100,function(e){return e},function(){return A(n,e,t)})},R=function(e){return 1-Math.pow(1-e,4)};function A(e,n,t,r,i,o){void 0===r&&(r=400),void 0===i&&(i=R);var a=n-e;if(0!==a){var c=Date.now(),u=0,l=function(){var n=Math.min(1,(Date.now()-c)/r);t(e+i(n)*a)&&n<1?s():(cancelAnimationFrame(u),n>=1&&o&&o())};s()}function s(){u=requestAnimationFrame(l)}}var I={T:0,L:0,W:0,H:0,FIT:void 0},H=function(){var e=n(!1);return i(function(){return e.current=!0,function(){e.current=!1}},[]),e},L=["className"];function F(n){var t=n.className,r=h(n,L);return e.createElement("div",f({className:"PhotoView__Spinner "+t},r),e.createElement("svg",{viewBox:"0 0 32 32",width:"36",height:"36",fill:"white"},e.createElement("path",{opacity:".25",d:"M16 0 A16 16 0 0 0 16 32 A16 16 0 0 0 16 0 M16 4 A12 12 0 0 1 16 28 A12 12 0 0 1 16 4"}),e.createElement("path",{d:"M16 0 A16 16 0 0 1 32 16 L28 16 A12 12 0 0 0 16 4z"})))}var D=["src","loaded","broken","className","onPhotoLoad","loadingElement","brokenElement"];function O(n){var t=n.src,r=n.loaded,i=n.broken,o=n.className,a=n.onPhotoLoad,c=n.loadingElement,u=n.brokenElement,l=h(n,D),s=H();return t&&!i?e.createElement(e.Fragment,null,e.createElement("img",f({className:"PhotoView__Photo"+(o?" "+o:""),src:t,onLoad:function(e){var n=e.target;s.current&&a({loaded:!0,naturalWidth:n.naturalWidth,naturalHeight:n.naturalHeight})},onError:function(){s.current&&a({broken:!0})},alt:""},l)),!r&&(e.createElement("span",{className:"PhotoView__icon"},c)||e.createElement(F,{className:"PhotoView__icon"}))):u?e.createElement("span",{className:"PhotoView__icon"},"function"==typeof u?u({src:t}):u):null}var B={naturalWidth:void 0,naturalHeight:void 0,width:void 0,height:void 0,loaded:void 0,broken:!1,x:0,y:0,touched:!1,maskTouched:!1,rotate:0,scale:1,CX:0,CY:0,lastX:0,lastY:0,lastCX:0,lastCY:0,lastScale:1,touchTime:0,touchLength:0,pause:!0,stopRaf:!0,reach:void 0};function z(t){var r=t.item,o=r.src,a=r.render,c=r.width,l=void 0===c?0:c,s=r.height,d=void 0===s?0:s,v=r.originRef,h=t.visible,p=t.speed,y=t.easing,E=t.wrapClassName,k=t.className,P=t.style,_=t.loadingElement,M=t.brokenElement,R=t.onPhotoTap,L=t.onMaskTap,F=t.onReachMove,D=t.onReachUp,z=t.onPhotoResize,j=t.isActive,q=t.expose,K=g(B),U=K[0],G=K[1],J=n(0),Q=H(),Z=U.naturalWidth,$=void 0===Z?l:Z,ee=U.naturalHeight,ne=void 0===ee?d:ee,te=U.width,re=void 0===te?l:te,ie=U.height,oe=void 0===ie?d:ie,ae=U.loaded,ce=void 0===ae?!o:ae,ue=U.broken,le=U.x,se=U.y,de=U.touched,ve=U.stopRaf,fe=U.maskTouched,he=U.rotate,me=U.scale,ge=U.CX,pe=U.CY,we=U.lastX,ye=U.lastY,xe=U.lastCX,Ce=U.lastCY,be=U.lastScale,Ee=U.touchTime,ke=U.touchLength,Pe=U.pause,_e=U.reach,Me=m({onScale:function(e){return Ye(x(e))},onRotate:function(e){he!==e&&(q({rotate:e}),G(f({rotate:e},S($,ne,e))))}});function Ye(e,n,t){me!==e&&(q({scale:e}),G(f({scale:e},N(le,se,re,oe,me,e,n,t),e<=1&&{x:0,y:0})))}var Xe=T(function(e,n,t){if(void 0===t&&(t=0),(de||fe)&&j){var r=W(he,re,oe),i=r[0],o=r[1];if(0===t&&0===J.current){var a=Math.abs(e-ge)<=20,c=Math.abs(n-pe)<=20;if(a&&c)return void G({lastCX:e,lastCY:n});J.current=a?n>pe?3:2:1}var u=e-xe,l=n-Ce,s=void 0;if(0===t){var d=X(u+we,me,i,innerWidth)[0],v=X(l+ye,me,o,innerHeight);s=function(e,n,t,r){return n&&1===e||"x"===r?"x":t&&e>1||"y"===r?"y":void 0}(J.current,d,v[0],_e),void 0!==s&&F(s,e,n,me)}if("x"===s||fe)return void G({reach:"x"});var h=x(me+(t-ke)/100/2*me,$/re,.2);q({scale:h}),G(f({touchLength:t,reach:s,scale:h},N(le,se,re,oe,me,h,e,n,u,l)))}},{maxWait:8});function Ne(e){return!ve&&!de&&(Q.current&&G(f({},e,{pause:h})),Q.current)}var We,Se,Te,Ve,Re,Ae,Ie,He,Le=(Re=function(e){return Ne({x:e})},Ae=function(e){return Ne({y:e})},Ie=function(e){return Q.current&&(q({scale:e}),G({scale:e})),!de&&Q.current},He=m({X:function(e){return Re(e)},Y:function(e){return Ae(e)},S:function(e){return Ie(e)}}),function(e,n,t,r,i,o,a,c,u,l,s){var d=W(l,i,o),v=d[0],f=d[1],h=X(e,c,v,innerWidth),m=h[0],g=h[1],p=X(n,c,f,innerHeight),w=p[0],y=p[1],x=Date.now()-s;if(x>=200||c!=a||Math.abs(u-a)>1){var C=N(e,n,i,o,a,c),b=C.x,E=C.y,k=m?g:b!==e?b:null,P=w?y:E!==n?E:null;return null!==k&&A(e,k,He.X),null!==P&&A(n,P,He.Y),void(c!=a&&A(a,c,He.S))}var _=(e-t)/x,M=(n-r)/x,Y=Math.sqrt(Math.pow(_,2)+Math.pow(M,2)),S=!1,T=!1;!function(e,n){var t=e,r=0,i=void 0,o=0,a=function(o){i||(i=o);var a=o-i,l=Math.sign(e),s=-.001*l,d=Math.sign(-t)*Math.pow(t,2)*2e-4,v=t*a+(s+d)*Math.pow(a,2)/2;r+=v,i=o,l*(t+=(s+d)*a)<=0?u():n(r)?c():u()};function c(){o=requestAnimationFrame(a)}function u(){cancelAnimationFrame(o)}c()}(Y,function(t){var r=e+t*(_/Y),i=n+t*(M/Y),o=X(r,a,v,innerWidth),c=o[0],u=o[1],l=X(i,a,f,innerHeight),s=l[0],d=l[1];if(c&&!S&&(S=!0,m?A(r,u,He.X):V(u,r+(r-u),He.X)),s&&!T&&(T=!0,w?A(i,d,He.Y):V(d,i+(i-d),He.Y)),S&&T)return!1;var h=S||He.X(u),g=T||He.Y(d);return h&&g})}),Fe=(We=R,Se=function(e,n){_e||Ye(1!==me?1:Math.max(2,$/re),e,n)},Te=n(0),Ve=T(function(){Te.current=0,We.apply(void 0,[].slice.call(arguments))},{wait:300}),function(){var e=[].slice.call(arguments);Te.current+=1,Ve.apply(void 0,e),Te.current>=2&&(Ve.cancel(),Te.current=0,Se.apply(void 0,e))});function De(e,n){if(J.current=0,(de||fe)&&j){G({touched:!1,maskTouched:!1,pause:!1,stopRaf:!1,reach:void 0});var t=x(me,$/re);if(Le(le,se,we,ye,re,oe,me,t,be,he,Ee),D(e,n),ge===e&&pe===n){if(de)return void Fe(e,n);fe&&L(e,n)}}}function Oe(e,n,t){void 0===t&&(t=0),G({touched:!0,CX:e,CY:n,lastCX:e,lastCY:n,lastX:le,lastY:se,lastScale:me,touchLength:t,touchTime:Date.now()})}function Be(e){G({maskTouched:!0,CX:e.clientX,CY:e.clientY,lastX:le,lastY:se})}b(w?void 0:"mousemove",function(e){e.preventDefault(),Xe(e.clientX,e.clientY)}),b(w?void 0:"mouseup",function(e){De(e.clientX,e.clientY)}),b(w?"touchmove":void 0,function(e){e.preventDefault();var n=Y(e);Xe.apply(void 0,n)},{passive:!1}),b(w?"touchend":void 0,function(e){var n=e.changedTouches[0];De(n.clientX,n.clientY)},{passive:!1}),b("resize",T(function(){ce&&!de&&(G(S($,ne,he)),z())},{maxWait:8})),C(function(){j&&q(f({scale:me,rotate:he},Me))},[j]);var ze=function(e,t,r,o,a,c,l,s,d,v){var f=function(e,t,r,i,o){var a=n(!1),c=g({lead:!0,scale:r}),u=c[0],l=u.lead,s=u.scale,d=c[1],v=T(function(e){try{return o(!0),d({lead:!1,scale:e}),Promise.resolve()}catch(e){return Promise.reject(e)}},{wait:i});return C(function(){a.current?(o(!1),d({lead:!0}),v(r)):a.current=!0},[r]),l?[e*s,t*s,r/s]:[e*r,t*r,1]}(c,l,s,d,v),h=f[0],p=f[1],w=f[2],y=function(e,t,r,o,a){var c=u(I),l=c[0],s=c[1],d=u(0),v=d[0],f=d[1],h=n(),g=m({OK:function(){return e&&f(4)}});function p(e){a(!1),f(e)}return i(function(){if(h.current||(h.current=Date.now()),r){if(function(e,n){var t=e&&e.current;if(t&&1===t.nodeType){var r=t.getBoundingClientRect();n({T:r.top,L:r.left,W:r.width,H:r.height,FIT:"IMG"===t.tagName?getComputedStyle(t).objectFit:void 0})}}(t,s),e)return Date.now()-h.current<250?(f(1),requestAnimationFrame(function(){f(2),requestAnimationFrame(function(){return p(3)})}),void setTimeout(g.OK,o)):void f(4);p(5)}},[e,r]),[v,l]}(e,t,r,d,v),x=y[0],b=y[1],E=b.W,k=b.FIT,P=innerWidth/2,_=innerHeight/2,M=x<3||x>4;return[M?E?b.L:P:o+(P-c*s/2),M?E?b.T:_:a+(_-l*s/2),h,M&&k?h*(b.H/E):p,0===x?w:M?E/(c*s)||.01:w,M?k?1:0:1,x,k]}(h,v,ce,le,se,re,oe,me,p,function(e){return G({pause:e})}),je=ze[4],qe=ze[6],Ke="transform "+p+"ms "+y,Ue={className:k,onMouseDown:w?void 0:function(e){e.stopPropagation(),0===e.button&&Oe(e.clientX,e.clientY,0)},onTouchStart:w?function(e){e.stopPropagation(),Oe.apply(void 0,Y(e))}:void 0,onWheel:function(e){if(!_e){var n=x(me-e.deltaY/100/2,$/re);G({stopRaf:!0}),Ye(n,e.clientX,e.clientY)}},style:{width:ze[2],height:ze[3],opacity:ze[5],objectFit:4===qe?void 0:ze[7],transform:he?"rotate("+he+"deg)":void 0,transition:qe>2?Ke+", opacity "+p+"ms ease, height "+(qe<4?p/2:qe>4?p:0)+"ms "+y:void 0}};return e.createElement("div",{className:"PhotoView__PhotoWrap"+(E?" "+E:""),style:P,onMouseDown:!w&&j?Be:void 0,onTouchStart:w&&j?function(e){return Be(e.touches[0])}:void 0},e.createElement("div",{className:"PhotoView__PhotoBox",style:{transform:"matrix("+je+", 0, 0, "+je+", "+ze[0]+", "+ze[1]+")",transition:de||Pe?void 0:Ke,willChange:j?"transform":void 0}},o?e.createElement(O,f({src:o,loaded:ce,broken:ue},Ue,{onPhotoLoad:function(e){G(f({},e,e.loaded&&S(e.naturalWidth||0,e.naturalHeight||0,he)))},loadingElement:_,brokenElement:M})):a&&a({attrs:Ue,scale:je,rotate:he})))}var j={x:0,touched:!1,pause:!1,lastCX:void 0,lastCY:void 0,bg:void 0,lastBg:void 0,overlay:!0,minimal:!0,scale:1,rotate:0};function q(r){var i=r.loop,o=void 0===i?3:i,c=r.speed,l=r.easing,s=r.photoClosable,d=r.maskClosable,v=void 0===d||d,f=r.maskOpacity,h=void 0===f?1:f,p=r.pullClosable,x=void 0===p||p,Y=r.bannerVisible,X=void 0===Y||Y,N=r.overlayRender,W=r.toolbarRender,S=r.className,T=r.maskClassName,V=r.photoClassName,R=r.photoWrapClassName,A=r.loadingElement,I=r.brokenElement,H=r.images,L=r.index,F=void 0===L?0:L,D=r.onIndexChange,O=r.visible,B=r.onClose,q=r.afterClose,K=g(j),U=K[0],G=K[1],J=u(0),Q=J[0],Z=J[1],$=U.x,ee=U.touched,ne=U.pause,te=U.lastCX,re=U.lastCY,ie=U.bg,oe=void 0===ie?h:ie,ae=U.lastBg,ce=U.overlay,ue=U.minimal,le=U.scale,se=U.rotate,de=U.onScale,ve=U.onRotate,fe=r.hasOwnProperty("index"),he=fe?F:Q,me=fe?D:Z,ge=n(he),pe=H.length,we=H[he],ye="boolean"==typeof o?o:pe>o,xe=function(e,r){var i=t(function(e){return!e},!1)[1],o=n(0),c=function(t,r){var i=n(t);function c(e){i.current=e}return a(function(){!function(n){e?(n(e),o.current=1):o.current=2}(c)},[t]),[i.current,c]}(e),u=c[1];return[c[0],o.current,function(){i(),2===o.current&&(u(!1),r&&r()),o.current=0}]}(O,q),Ce=xe[0],be=xe[1],Ee=xe[2];C(function(){if(Ce)return G({pause:!0,x:he*-(innerWidth+20)}),void(ge.current=he);G(j)},[Ce]);var ke=m({close:function(e){ve&&ve(0),G({overlay:!0,lastBg:oe}),B(e)},changeIndex:function(e,n){void 0===n&&(n=!1);var t=ye?ge.current+(e-he):e,r=pe-1,i=y(t,0,r),o=ye?t:i,a=innerWidth+20;G({touched:!1,lastCX:void 0,lastCY:void 0,x:-a*o,pause:n}),ge.current=o,me&&me(ye?e<0?r:e>r?0:e:i)}}),Pe=ke.close,_e=ke.changeIndex;function Me(e){return e?Pe():G({overlay:!ce})}function Ye(){G({x:-(innerWidth+20)*he,lastCX:void 0,lastCY:void 0,pause:!0}),ge.current=he}function Xe(e,n,t,r){"x"===e?function(e){if(void 0!==te){var n=e-te,t=n;!ye&&(0===he&&n>0||he===pe-1&&n<0)&&(t=n/2),G({touched:!0,lastCX:te,x:-(innerWidth+20)*ge.current+t,pause:!1})}else G({touched:!0,lastCX:e,x:$,pause:!1})}(n):"y"===e&&function(e,n){if(void 0!==re){var t=y(h,0,h-Math.abs(e-re)/100/4);G({touched:!0,lastCY:re,bg:1===n?t:h,minimal:1===n})}else G({touched:!0,lastCY:e,bg:oe,minimal:!0})}(t,r)}function Ne(e,n){var t=e-(null!=te?te:e),r=n-(null!=re?re:n),i=!1;if(t<-40)_e(he+1);else if(t>40)_e(he-1);else{var o=-(innerWidth+20)*ge.current;Math.abs(r)>100&&ue&&x&&(i=!0,Pe()),G({touched:!1,x:o,lastCX:void 0,lastCY:void 0,bg:h,overlay:!!i||ce})}}b("keydown",function(e){if(O)switch(e.key){case"ArrowLeft":_e(he-1,!0);break;case"ArrowRight":_e(he+1,!0);break;case"Escape":Pe()}});var We=function(e,n,t){return a(function(){var r=e.length;return t?e.concat(e).concat(e).slice(r+n-1,r+n+2):e.slice(Math.max(n-1,0),Math.min(n+2,r+1))},[e,n,t])}(H,he,ye);if(!Ce)return null;var Se=ce&&!be,Te=O?oe:ae,Ve=de&&ve&&{images:H,index:he,visible:O,onClose:Pe,onIndexChange:_e,overlayVisible:Se,overlay:we.overlay,scale:le,rotate:se,onScale:de,onRotate:ve},Re=c?c(be):400,Ae=l?l(be):"cubic-bezier(0.25, 0.8, 0.25, 1)",Ie=c?c(3):600,He=l?l(3):"cubic-bezier(0.25, 0.8, 0.25, 1)";return e.createElement(E,{className:"PhotoView-Portal"+(Se?"":" PhotoView-Slider__clean")+(O?"":" PhotoView-Slider__willClose")+(S?" "+S:""),role:"dialog",onClick:function(e){return e.stopPropagation()}},O&&e.createElement(M,null),e.createElement("div",{className:"PhotoView-Slider__Backdrop"+(T?" "+T:"")+(1===be?" PhotoView-Slider__fadeIn":2===be?" PhotoView-Slider__fadeOut":""),style:{background:"rgba(0, 0, 0, "+Te+")",transitionTimingFunction:Ae,transitionDuration:(ee?0:Re)+"ms",animationDuration:Re+"ms"},onAnimationEnd:Ee}),X&&e.createElement("div",{className:"PhotoView-Slider__BannerWrap"},e.createElement("div",{className:"PhotoView-Slider__Counter"},he+1," / ",pe),e.createElement("div",{className:"PhotoView-Slider__BannerRight"},W&&Ve&&W(Ve),e.createElement(k,{className:"PhotoView-Slider__toolbarIcon",onClick:Pe}))),We.map(function(n,t){var r=ye||0!==he?ge.current-1+t:he+t;return e.createElement(z,{key:ye?n.key+"/"+n.src+"/"+r:n.key,item:n,speed:Re,easing:Ae,visible:O,onReachMove:Xe,onReachUp:Ne,onPhotoTap:function(){return Me(s)},onMaskTap:function(){return Me(v)},wrapClassName:R,className:V,style:{left:(innerWidth+20)*r+"px",transform:"translate3d("+$+"px, 0px, 0)",transition:ee||ne?void 0:"transform "+Ie+"ms "+He},loadingElement:A,brokenElement:I,onPhotoResize:Ye,isActive:(we&&we.key)===n.key,expose:G})}),!w&&X&&e.createElement(e.Fragment,null,(ye||0!==he)&&e.createElement("div",{className:"PhotoView-Slider__ArrowLeft",onClick:function(){return _e(he-1,!0)}},e.createElement(P,null)),(ye||he+1<pe)&&e.createElement("div",{className:"PhotoView-Slider__ArrowRight",onClick:function(){return _e(he+1,!0)}},e.createElement(_,null))),N&&Ve&&e.createElement("div",{className:"PhotoView-Slider__Overlay"},N(Ve)))}var K=["children","onIndexChange","onVisibleChange"],U={images:[],visible:!1,index:0};function G(t){var r=t.children,i=t.onIndexChange,o=t.onVisibleChange,c=h(t,K),u=g(U),l=u[0],s=u[1],d=n(0),v=l.images,w=l.visible,y=l.index,x=m({nextId:function(){return d.current+=1},update:function(e){var n=v.findIndex(function(n){return n.key===e.key});if(n>-1){var t=v.slice();return t.splice(n,1,e),void s({images:t})}s(function(n){return{images:n.images.concat(e)}})},remove:function(e){var n=v.filter(function(n){return n.key!==e});s({images:n,index:Math.min(n.length-1,y)})},show:function(e){var n=v.findIndex(function(n){return n.key===e});s({visible:!0,index:n}),o&&o(!0,n,l)}}),C=m({close:function(){s({visible:!1}),o&&o(!1,y,l)},changeIndex:function(e){s({index:e}),i&&i(e,l)}}),b=a(function(){return f({},l,x)},[l,x]);return e.createElement(p.Provider,{value:b},r,e.createElement(q,f({images:v,visible:w,index:y,onIndexChange:C.changeIndex,onClose:C.close},c)))}var J=function(e){var t,r,o=e.src,a=e.render,c=e.overlay,u=e.width,v=e.height,f=e.children,h=l(p),g=(t=function(){return h.nextId()},(r=n({sign:!1,fn:void 0}).current).sign||(r.sign=!0,r.fn=t()),r.fn),w=n(null);i(function(){return function(){h.remove(g)}},[]);var y=m({render:function(e){return a&&a(e)},click:function(e){h.show(g),function(e,n){if(f){var t=f.props.onClick;t&&t(n)}}(0,e)}});return i(function(){h.update({key:g,src:o,originRef:w,render:y.render,overlay:c,width:u,height:v})},[o]),f?s.only(d(f,{onClick:y.click,ref:w})):null};export{G as PhotoProvider,q as PhotoSlider,J as PhotoView}; | ||
//# sourceMappingURL=react-photo-view.module.js.map |
@@ -19,2 +19,6 @@ import type React from 'react'; | ||
/** | ||
* 自定义覆盖节点 | ||
*/ | ||
overlay?: React.ReactNode; | ||
/** | ||
* 指定渲染节点宽度 | ||
@@ -133,2 +137,6 @@ */ | ||
/** | ||
* 自定义覆盖节点 | ||
*/ | ||
overlay?: React.ReactNode; | ||
/** | ||
* 当前旋转角度 | ||
@@ -135,0 +143,0 @@ */ |
{ | ||
"name": "react-photo-view", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "An exquisite React photo preview component", | ||
@@ -25,3 +25,3 @@ "author": "MinJieLiu", | ||
"scripts": { | ||
"build": "rimraf ./dist && microbundle --jsx React.createElement --external react,react-dom --format cjs,esm,modern", | ||
"build": "rimraf ./dist && microbundle --external react,react-dom --format cjs,esm,modern", | ||
"prepublishOnly": "npm run build" | ||
@@ -34,6 +34,6 @@ }, | ||
"devDependencies": { | ||
"@micro-web/microbundle": "^0.14.3", | ||
"@types/react": "^17.0.39", | ||
"@types/react-dom": "^17.0.11", | ||
"less": "^4.1.2", | ||
"microbundle": "^0.14.2", | ||
"react": "^17.0.2", | ||
@@ -40,0 +40,0 @@ "react-dom": "^17.0.2", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
359845
47
698