react-photo-view
Advanced tools
Comparing version 1.2.3 to 1.2.4
@@ -1,2 +0,2 @@ | ||
import type React from 'react'; | ||
import React from 'react'; | ||
import type { PhotoRenderParams } from './types'; | ||
@@ -3,0 +3,0 @@ export interface PhotoViewProps { |
@@ -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=["container"];function m(e){var n=e.container,a=void 0===n?document.body:n,u=o(e,h);return t.createPortal(r.default.createElement("div",i({},u)),a)}function g(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 p(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 w(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 y(){return e.useEffect(function(){var e=document.body.style,t=e.overflow;return e.overflow="hidden",function(){e.overflow=t}},[]),null}function x(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 C=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 b(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=C(e,o,n,innerWidth)[0],d=C(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 k(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 P(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 M=function(e,t,n){return _(e,t,n,100,function(e){return e},function(){return _(t,e,n)})},R=function(e){return 1-Math.pow(1-e,4)};function _(e,t,n,r,i,o){void 0===r&&(r=400),void 0===i&&(i=R);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 Y={T:0,L:0,W:0,H:0,FIT:void 0},X=function(){var t=e.useRef(!1);return e.useEffect(function(){return t.current=!0,function(){t.current=!1}},[]),t},N=["className"];function S(e){var t=e.className,n=o(e,N);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 W=["src","loaded","broken","className","onPhotoLoad","loadingElement","brokenElement"];function T(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,W),f=X();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(S,{className:"PhotoView__icon"}))):s?r.default.createElement("span",{className:"PhotoView__icon"},"function"==typeof s?s({src:t}):s):null}var V={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 A(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,y=t.speed,R=t.easing,N=t.wrapClassName,S=t.className,W=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(V),q=z[0],K=z[1],U=e.useRef(0),G=X(),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},k(Q,$,e))))}});function Me(e,t,n){ve!==e&&(j({scale:e}),K(i({scale:e},b(ue,ce,te,re,ve,e,t,n),e<=1&&{x:0,y:0})))}var Re=P(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=C(l+ge,ve,o,innerWidth)[0],h=C(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},b(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=C(e,u,f,innerWidth),m=h[0],g=h[1],p=C(t,u,v,innerHeight),w=p[0],y=p[1],x=Date.now()-s;if(x>=200||u!=a||Math.abs(c-a)>1){var k=b(e,t,i,o,a,u),P=k.x,R=k.y,Y=m?g:P!==e?P:null,X=w?y:R!==t?R:null;return null!==Y&&_(e,Y,Ae.X),null!==X&&_(t,X,Ae.Y),void(u!=a&&_(a,u,Ae.S))}var N=(e-n)/x,S=(t-r)/x,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=C(r,a,f,innerWidth),u=o[0],c=o[1],l=C(i,a,v,innerHeight),s=l[0],d=l[1];if(u&&!T&&(T=!0,m?_(r,c,Ae.X):M(c,r+(r-c),Ae.X)),s&&!V&&(V=!0,w?_(i,d,Ae.Y):M(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=P(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=x(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",P(function(){oe&&!le&&(K(k(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=P(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(Y),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,k=innerHeight/2,M=y<3||y>4;return[M?C?x.L:E:i+(E-c*s/2),M?C?x.T:k:o+(k-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,y,function(e){return K({pause:e})}),Be=Oe[4],je=Oe[6],ze="transform "+y+"ms "+R,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,x(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 "+y+"ms ease, height "+(je<4?y/2:je>4?y:0)+"ms "+R:void 0}};return r.default.createElement("div",{className:"PhotoView__PhotoWrap"+(N?" "+N:""),style:W,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(T,i({src:o,loaded:oe,broken:ae},qe,{onPhotoLoad:function(e){K(i({},e,e.loaded&&k(e.naturalWidth||0,e.naturalHeight||0,fe)))},loadingElement:A,brokenElement:I})):c&&c({attrs:qe,scale:Be,rotate:fe})))}var I={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 L(t){var n=t.loop,i=void 0===n?3:n,o=t.speed,c=t.easing,d=t.photoClosable,h=t.maskClosable,x=void 0===h||h,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,V=t.images,L=t.index,H=void 0===L?0:L,F=t.onIndexChange,D=t.visible,O=t.onClose,B=t.afterClose,j=t.portalContainer,z=u(I),q=z[0],K=z[1],U=e.useState(0),G=U[0],J=U[1],Q=q.x,Z=q.touched,$=q.pause,ee=q.lastCX,te=q.lastCY,ne=q.bg,re=void 0===ne?b:ne,ie=q.lastBg,oe=q.overlay,ae=q.minimal,ue=q.scale,ce=q.rotate,le=q.onScale,se=q.onRotate,de=t.hasOwnProperty("index"),fe=de?H:G,ve=de?F:J,he=e.useRef(fe),me=V.length,ge=V[fe],pe="boolean"==typeof i?i:me>i,we=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),ye=we[0],xe=we[1],Ce=we[2];f(function(){if(ye)return K({pause:!0,x:fe*-(innerWidth+20)}),void(he.current=fe);K(I)},[ye]);var be=a({close:function(e){se&&se(0),K({overlay:!0,lastBg:re}),O(e)},changeIndex:function(e,t){void 0===t&&(t=!1);var n=pe?he.current+(e-fe):e,r=me-1,i=s(n,0,r),o=pe?n:i,a=innerWidth+20;K({touched:!1,lastCX:void 0,lastCY:void 0,x:-a*o,pause:t}),he.current=o,ve&&ve(pe?e<0?r:e>r?0:e:i)}}),Ee=be.close,ke=be.changeIndex;function Pe(e){return e?Ee():K({overlay:!oe})}function Me(){K({x:-(innerWidth+20)*fe,lastCX:void 0,lastCY:void 0,pause:!0}),he.current=fe}function Re(e,t,n,r){"x"===e?function(e){if(void 0!==ee){var t=e-ee,n=t;!pe&&(0===fe&&t>0||fe===me-1&&t<0)&&(n=t/2),K({touched:!0,lastCX:ee,x:-(innerWidth+20)*he.current+n,pause:!1})}else K({touched:!0,lastCX:e,x:Q,pause:!1})}(t):"y"===e&&function(e,t){if(void 0!==te){var n=null===b?null:s(b,.01,b-Math.abs(e-te)/100/4);K({touched:!0,lastCY:te,bg:1===t?n:b,minimal:1===t})}else K({touched:!0,lastCY:e,bg:re,minimal:!0})}(n,r)}function _e(e,t){var n=e-(null!=ee?ee:e),r=t-(null!=te?te:t),i=!1;if(n<-40)ke(fe+1);else if(n>40)ke(fe-1);else{var o=-(innerWidth+20)*he.current;Math.abs(r)>100&&ae&&k&&(i=!0,Ee()),K({touched:!1,x:o,lastCX:void 0,lastCY:void 0,bg:b,overlay:!!i||oe})}}v("keydown",function(e){if(D)switch(e.key){case"ArrowLeft":ke(fe-1,!0);break;case"ArrowRight":ke(fe+1,!0);break;case"Escape":Ee()}});var Ye=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])}(V,fe,pe);if(!ye)return null;var Xe=oe&&!xe,Ne=D?re:ie,Se=le&&se&&{images:V,index:fe,visible:D,onClose:Ee,onIndexChange:ke,overlayVisible:Xe,overlay:ge&&ge.overlay,scale:ue,rotate:ce,onScale:le,onRotate:se},We=o?o(xe):400,Te=c?c(xe):"cubic-bezier(0.25, 0.8, 0.25, 1)",Ve=o?o(3):600,Ae=c?c(3):"cubic-bezier(0.25, 0.8, 0.25, 1)";return r.default.createElement(m,{className:"PhotoView-Portal"+(Xe?"":" PhotoView-Slider__clean")+(D?"":" PhotoView-Slider__willClose")+(Y?" "+Y:""),role:"dialog",onClick:function(e){return e.stopPropagation()},container:j},D&&r.default.createElement(y,null),r.default.createElement("div",{className:"PhotoView-Slider__Backdrop"+(X?" "+X:"")+(1===xe?" PhotoView-Slider__fadeIn":2===xe?" PhotoView-Slider__fadeOut":""),style:{background:Ne?"rgba(0, 0, 0, "+Ne+")":void 0,transitionTimingFunction:Te,transitionDuration:(Z?0:We)+"ms",animationDuration:We+"ms"},onAnimationEnd:Ce}),M&&r.default.createElement("div",{className:"PhotoView-Slider__BannerWrap"},r.default.createElement("div",{className:"PhotoView-Slider__Counter"},fe+1," / ",me),r.default.createElement("div",{className:"PhotoView-Slider__BannerRight"},_&&Se&&_(Se),r.default.createElement(g,{className:"PhotoView-Slider__toolbarIcon",onClick:Ee}))),Ye.map(function(e,t){var n=pe||0!==fe?he.current-1+t:fe+t;return r.default.createElement(A,{key:pe?e.key+"/"+e.src+"/"+n:e.key,item:e,speed:We,easing:Te,visible:D,onReachMove:Re,onReachUp:_e,onPhotoTap:function(){return Pe(d)},onMaskTap:function(){return Pe(x)},wrapClassName:S,className:N,style:{left:(innerWidth+20)*n+"px",transform:"translate3d("+Q+"px, 0px, 0)",transition:Z||$?void 0:"transform "+Ve+"ms "+Ae},loadingElement:W,brokenElement:T,onPhotoResize:Me,isActive:(ge&&ge.key)===e.key,expose:K})}),!l&&M&&r.default.createElement(r.default.Fragment,null,(pe||0!==fe)&&r.default.createElement("div",{className:"PhotoView-Slider__ArrowLeft",onClick:function(){return ke(fe-1,!0)}},r.default.createElement(p,null)),(pe||fe+1<me)&&r.default.createElement("div",{className:"PhotoView-Slider__ArrowRight",onClick:function(){return ke(fe+1,!0)}},r.default.createElement(w,null))),R&&Se&&r.default.createElement("div",{className:"PhotoView-Slider__Overlay"},R(Se)))}var H=["children","onIndexChange","onVisibleChange"],F={images:[],visible:!1,index:0};exports.PhotoProvider=function(t){var n=t.children,l=t.onIndexChange,s=t.onVisibleChange,d=o(t,H),f=u(F),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){h(function(t){var n=t.images.filter(function(t){return t.key!==e});return{images:n,index:Math.min(n.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(L,i({images:g,visible:p,index:w,onIndexChange:x.changeIndex,onClose:x.close},d)))},exports.PhotoSlider=L,exports.PhotoView=function(t){var n,r,o=t.src,u=t.render,l=t.overlay,s=t.width,d=t.height,f=t.triggers,v=void 0===f?["onClick"]:f,h=t.children,m=e.useContext(c),g=(n=function(){return m.nextId()},(r=e.useRef({sign:!1,fn:void 0}).current).sign||(r.sign=!0,r.fn=n()),r.fn),p=e.useRef(null);e.useEffect(function(){return function(){m.remove(g)}},[]);var w=a({render:function(e){return u&&u(e)},show:function(e,t){m.show(g),function(e,t){if(h){var n=h.props[e];n&&n(t)}}(e,t)}}),y=e.useMemo(function(){var e={};return v.forEach(function(t){e[t]=w.show.bind(null,t)}),e},[]);return e.useEffect(function(){m.update({key:g,src:o,originRef:p,render:w.render,overlay:l,width:s,height:d})},[o]),h?e.Children.only(e.cloneElement(h,i({},y,{ref:p}))):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=["container"];function m(e){var n=e.container,a=void 0===n?document.body:n,u=o(e,h);return t.createPortal(r.default.createElement("div",i({},u)),a)}function g(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 p(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 w(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 y(){return e.useEffect(function(){var e=document.body.style,t=e.overflow;return e.overflow="hidden",function(){e.overflow=t}},[]),null}function x(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 C=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 b(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=C(e,o,n,innerWidth)[0],d=C(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 P(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 M=function(e,t,n){return _(e,t,n,100,function(e){return e},function(){return _(t,e,n)})},R=function(e){return 1-Math.pow(1-e,4)};function _(e,t,n,r,i,o){void 0===r&&(r=400),void 0===i&&(i=R);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 Y={T:0,L:0,W:0,H:0,FIT:void 0},X=function(){var t=e.useRef(!1);return e.useEffect(function(){return t.current=!0,function(){t.current=!1}},[]),t},N=["className"];function S(e){var t=e.className,n=o(e,N);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 W=["src","loaded","broken","className","onPhotoLoad","loadingElement","brokenElement"];function T(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,W),f=X();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(S,{className:"PhotoView__icon"}))):s?r.default.createElement("span",{className:"PhotoView__icon"},"function"==typeof s?s({src:t}):s):null}var V={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 A(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,y=t.speed,R=t.easing,N=t.wrapClassName,S=t.className,W=t.style,A=t.loadingElement,I=t.brokenElement,H=t.onPhotoTap,L=t.onMaskTap,F=t.onReachMove,D=t.onReachUp,O=t.onPhotoResize,B=t.isActive,j=t.expose,z=u(V),q=z[0],K=z[1],U=e.useRef(0),G=X(),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,Pe=q.reach,ke=a({onScale:function(e){return Me(d(e))},onRotate:function(e){fe!==e&&(j({rotate:e}),K(i({rotate:e},P(Q,$,e))))}});function Me(e,t,n){ve!==e&&(j({scale:e}),K(i({scale:e},b(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=C(l+ge,ve,o,innerWidth)[0],h=C(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],Pe),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},b(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=C(e,u,f,innerWidth),m=h[0],g=h[1],p=C(t,u,v,innerHeight),w=p[0],y=p[1],x=Date.now()-s;if(x>=200||u!=a||Math.abs(c-a)>1){var P=b(e,t,i,o,a,u),k=P.x,R=P.y,Y=m?g:k!==e?k:null,X=w?y:R!==t?R:null;return null!==Y&&_(e,Y,Ae.X),null!==X&&_(t,X,Ae.Y),void(u!=a&&_(a,u,Ae.S))}var N=(e-n)/x,S=(t-r)/x,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=C(r,a,f,innerWidth),u=o[0],c=o[1],l=C(i,a,v,innerHeight),s=l[0],d=l[1];if(u&&!T&&(T=!0,m?_(r,c,Ae.X):M(c,r+(r-c),Ae.X)),s&&!V&&(V=!0,w?_(i,d,Ae.Y):M(d,i+(i-d),Ae.Y)),T&&V)return!1;var h=T||Ae.X(c),g=V||Ae.Y(d);return h&&g})}),He=(Ye=H,Xe=function(e,t){Pe||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 Le(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 He(e,t);de&&L(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){Le(e.clientX,e.clientY)}),v(l?"touchmove":void 0,function(e){e.preventDefault();var t=x(e);Re.apply(void 0,t)},{passive:!1}),v(l?"touchend":void 0,function(e){var t=e.changedTouches[0];Le(t.clientX,t.clientY)},{passive:!1}),v("resize",k(function(){oe&&!le&&(K(P(Q,$,fe)),O())},{maxWait:8})),f(function(){B&&j(i({scale:ve,rotate:fe},ke))},[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(Y),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,y,function(e){return K({pause:e})}),Be=Oe[4],je=Oe[6],ze="transform "+y+"ms "+R,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,x(e))}:void 0,onWheel:function(e){if(!Pe){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 "+y+"ms ease, height "+(je<4?y/2:je>4?y:0)+"ms "+R:void 0}};return r.default.createElement("div",{className:"PhotoView__PhotoWrap"+(N?" "+N:""),style:W,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(T,i({src:o,loaded:oe,broken:ae},qe,{onPhotoLoad:function(e){K(i({},e,e.loaded&&P(e.naturalWidth||0,e.naturalHeight||0,fe)))},loadingElement:A,brokenElement:I})):c&&c({attrs:qe,scale:Be,rotate:fe})))}var I={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 H(t){var n=t.loop,i=void 0===n?3:n,o=t.speed,c=t.easing,d=t.photoClosable,h=t.maskClosable,x=void 0===h||h,C=t.maskOpacity,b=void 0===C?1:C,E=t.pullClosable,P=void 0===E||E,k=t.bannerVisible,M=void 0===k||k,R=t.overlayRender,_=t.toolbarRender,Y=t.className,X=t.maskClassName,N=t.photoClassName,S=t.photoWrapClassName,W=t.loadingElement,T=t.brokenElement,V=t.images,H=t.index,L=void 0===H?0:H,F=t.onIndexChange,D=t.visible,O=t.onClose,B=t.afterClose,j=t.portalContainer,z=u(I),q=z[0],K=z[1],U=e.useState(0),G=U[0],J=U[1],Q=q.x,Z=q.touched,$=q.pause,ee=q.lastCX,te=q.lastCY,ne=q.bg,re=void 0===ne?b:ne,ie=q.lastBg,oe=q.overlay,ae=q.minimal,ue=q.scale,ce=q.rotate,le=q.onScale,se=q.onRotate,de=t.hasOwnProperty("index"),fe=de?L:G,ve=de?F:J,he=e.useRef(fe),me=V.length,ge=V[fe],pe="boolean"==typeof i?i:me>i,we=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),ye=we[0],xe=we[1],Ce=we[2];f(function(){if(ye)return K({pause:!0,x:fe*-(innerWidth+20)}),void(he.current=fe);K(I)},[ye]);var be=a({close:function(e){se&&se(0),K({overlay:!0,lastBg:re}),O(e)},changeIndex:function(e,t){void 0===t&&(t=!1);var n=pe?he.current+(e-fe):e,r=me-1,i=s(n,0,r),o=pe?n:i,a=innerWidth+20;K({touched:!1,lastCX:void 0,lastCY:void 0,x:-a*o,pause:t}),he.current=o,ve&&ve(pe?e<0?r:e>r?0:e:i)}}),Ee=be.close,Pe=be.changeIndex;function ke(e){return e?Ee():K({overlay:!oe})}function Me(){K({x:-(innerWidth+20)*fe,lastCX:void 0,lastCY:void 0,pause:!0}),he.current=fe}function Re(e,t,n,r){"x"===e?function(e){if(void 0!==ee){var t=e-ee,n=t;!pe&&(0===fe&&t>0||fe===me-1&&t<0)&&(n=t/2),K({touched:!0,lastCX:ee,x:-(innerWidth+20)*he.current+n,pause:!1})}else K({touched:!0,lastCX:e,x:Q,pause:!1})}(t):"y"===e&&function(e,t){if(void 0!==te){var n=null===b?null:s(b,.01,b-Math.abs(e-te)/100/4);K({touched:!0,lastCY:te,bg:1===t?n:b,minimal:1===t})}else K({touched:!0,lastCY:e,bg:re,minimal:!0})}(n,r)}function _e(e,t){var n=e-(null!=ee?ee:e),r=t-(null!=te?te:t),i=!1;if(n<-40)Pe(fe+1);else if(n>40)Pe(fe-1);else{var o=-(innerWidth+20)*he.current;Math.abs(r)>100&&ae&&P&&(i=!0,Ee()),K({touched:!1,x:o,lastCX:void 0,lastCY:void 0,bg:b,overlay:!!i||oe})}}v("keydown",function(e){if(D)switch(e.key){case"ArrowLeft":Pe(fe-1,!0);break;case"ArrowRight":Pe(fe+1,!0);break;case"Escape":Ee()}});var Ye=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])}(V,fe,pe);if(!ye)return null;var Xe=oe&&!xe,Ne=D?re:ie,Se=le&&se&&{images:V,index:fe,visible:D,onClose:Ee,onIndexChange:Pe,overlayVisible:Xe,overlay:ge&&ge.overlay,scale:ue,rotate:ce,onScale:le,onRotate:se},We=o?o(xe):400,Te=c?c(xe):"cubic-bezier(0.25, 0.8, 0.25, 1)",Ve=o?o(3):600,Ae=c?c(3):"cubic-bezier(0.25, 0.8, 0.25, 1)";return r.default.createElement(m,{className:"PhotoView-Portal"+(Xe?"":" PhotoView-Slider__clean")+(D?"":" PhotoView-Slider__willClose")+(Y?" "+Y:""),role:"dialog",onClick:function(e){return e.stopPropagation()},container:j},D&&r.default.createElement(y,null),r.default.createElement("div",{className:"PhotoView-Slider__Backdrop"+(X?" "+X:"")+(1===xe?" PhotoView-Slider__fadeIn":2===xe?" PhotoView-Slider__fadeOut":""),style:{background:Ne?"rgba(0, 0, 0, "+Ne+")":void 0,transitionTimingFunction:Te,transitionDuration:(Z?0:We)+"ms",animationDuration:We+"ms"},onAnimationEnd:Ce}),M&&r.default.createElement("div",{className:"PhotoView-Slider__BannerWrap"},r.default.createElement("div",{className:"PhotoView-Slider__Counter"},fe+1," / ",me),r.default.createElement("div",{className:"PhotoView-Slider__BannerRight"},_&&Se&&_(Se),r.default.createElement(g,{className:"PhotoView-Slider__toolbarIcon",onClick:Ee}))),Ye.map(function(e,t){var n=pe||0!==fe?he.current-1+t:fe+t;return r.default.createElement(A,{key:pe?e.key+"/"+e.src+"/"+n:e.key,item:e,speed:We,easing:Te,visible:D,onReachMove:Re,onReachUp:_e,onPhotoTap:function(){return ke(d)},onMaskTap:function(){return ke(x)},wrapClassName:S,className:N,style:{left:(innerWidth+20)*n+"px",transform:"translate3d("+Q+"px, 0px, 0)",transition:Z||$?void 0:"transform "+Ve+"ms "+Ae},loadingElement:W,brokenElement:T,onPhotoResize:Me,isActive:he.current===n,expose:K})}),!l&&M&&r.default.createElement(r.default.Fragment,null,(pe||0!==fe)&&r.default.createElement("div",{className:"PhotoView-Slider__ArrowLeft",onClick:function(){return Pe(fe-1,!0)}},r.default.createElement(p,null)),(pe||fe+1<me)&&r.default.createElement("div",{className:"PhotoView-Slider__ArrowRight",onClick:function(){return Pe(fe+1,!0)}},r.default.createElement(w,null))),R&&Se&&r.default.createElement("div",{className:"PhotoView-Slider__Overlay"},R(Se)))}var L=["children","onIndexChange","onVisibleChange"],F={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(F),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){h(function(t){var n=t.images.filter(function(t){return t.key!==e});return{images:n,index:Math.min(n.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(H,i({images:g,visible:p,index:w,onIndexChange:x.changeIndex,onClose:x.close},d)))},exports.PhotoSlider=H,exports.PhotoView=function(t){var n,r,o=t.src,u=t.render,l=t.overlay,s=t.width,d=t.height,f=t.triggers,v=void 0===f?["onClick"]:f,h=t.children,m=e.useContext(c),g=(n=function(){return m.nextId()},(r=e.useRef({sign:!1,fn:void 0}).current).sign||(r.sign=!0,r.fn=n()),r.fn),p=e.useRef(null);e.useImperativeHandle(null==h?void 0:h.ref,function(){return p.current}),e.useEffect(function(){return function(){m.remove(g)}},[]);var w=a({render:function(e){return u&&u(e)},show:function(e,t){m.show(g),function(e,t){if(h){var n=h.props[e];n&&n(t)}}(e,t)}}),y=e.useMemo(function(){var e={};return v.forEach(function(t){e[t]=w.show.bind(null,t)}),e},[]);return e.useEffect(function(){m.update({key:g,src:o,originRef:p,render:w.render,overlay:l,width:s,height:d})},[o]),h?e.Children.only(e.cloneElement(h,i({},y,{ref:p}))):null}; | ||
//# sourceMappingURL=react-photo-view.js.map |
@@ -1,2 +0,2 @@ | ||
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=["container"];function _(t){let{container:n=document.body}=t,o=f(t,k);return h(e.createElement("div",m({},o)),n)}function P(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 Y(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 X(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 M(){return r(()=>{const{style:e}=document.body,t=e.overflow;return e.overflow="hidden",()=>{e.overflow=t}},[]),null}function N(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 W=(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 $(e,t,n,o,r,i,a=innerWidth/2,c=innerHeight/2,s=0,l=0){const[u]=W(e,i,n,innerWidth),[d]=W(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 S(e,t,n){const o=e%180!=0;return o?[n,t,o]:[t,n,o]}function T(e,t,n){const[o,r,i]=S(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 V(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 R=(e,t,n)=>I(e,t,n,100,e=>e,()=>I(t,e,n)),A=e=>1-(1-e)**4;function I(e,t,n,o=400,r=A,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 H={T:0,L:0,W:0,H:0,FIT:void 0},L=()=>{const e=t(!1);return r(()=>(e.current=!0,()=>{e.current=!1}),[]),e},F=["className"];function D(t){let{className:n}=t,o=f(t,F);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 O=["src","loaded","broken","className","onPhotoLoad","loadingElement","brokenElement"];function B(t){let{src:n,loaded:o,broken:r,className:i,onPhotoLoad:a,loadingElement:c,brokenElement:s}=t,l=f(t,O);const u=L();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(D,{className:"PhotoView__icon"}))):s?e.createElement("span",{className:"PhotoView__icon"},"function"==typeof s?s({src:n}):s):null}const z={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 j({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:M,expose:A}){const[F,D]=g(z),O=t(0),j=L(),{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&&(A({rotate:e}),D(m({rotate:e},T(q,K,e))))}});function we(e,t,n){ie!==e&&(A({scale:e}),D(m({scale:e},$(Z,ee,U,G,ie,e,t,n),e<=1&&{x:0,y:0})))}const ye=V((e,t,n=0)=>{if((te||oe)&&M){const[o,r]=S(re,U,G);if(0===n&&0===O.current){const n=Math.abs(e-ae)<=20,o=Math.abs(t-ce)<=20;if(n&&o)return void D({lastCX:e,lastCY:t});O.current=n?t>ce?3:2:1}const i=e-ue,a=t-de;let c;if(0===n){const[n]=W(i+se,ie,o,innerWidth),[s]=W(a+le,ie,r,innerHeight);c=((e,t,n,o)=>t&&1===e||"x"===o?"x":n&&e>1||"y"===o?"y":void 0)(O.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);A({scale:s}),D(m({touchLength:n,reach:c,scale:s},$(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&&(A({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]=S(u,i,a),[f,v]=W(e,s,h,innerWidth),[g,p]=W(t,s,m,innerHeight),w=Date.now()-d;if(w>=200||s!=c||Math.abs(l-c)>1){const{x:n,y:r}=$(e,t,i,a,c,s),l=f?v:n!==e?n:null,u=g?p:r!==t?r:null;return null!==l&&I(e,l,o.X),null!==u&&I(t,u,o.Y),void(s!=c&&I(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]=W(r,c,h,innerWidth),[l,u]=W(i,c,m,innerHeight);if(a&&!b&&(b=!0,f?I(r,s,o.X):R(s,r+(r-s),o.X)),l&&!E&&(E=!0,g?I(i,u,o.Y):R(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=V((...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(O.current=0,(te||oe)&&M){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=N(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",V(()=>{J&&!te&&(D(T(q,K,re)),X())},{maxWait:8})),b(()=>{M&&A(m({scale:ie,rotate:re},pe))},[M]);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=V(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(H),[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(...N(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&&M?_e:void 0,onTouchStart:y&&M?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:M?"transform":void 0}},n?e.createElement(B,m({src:n,loaded:J,broken:Q},Ve,{onPhotoLoad:function(e){D(m({},e,e.loaded&&T(e.naturalWidth||0,e.naturalHeight||0,re)))},loadingElement:w,brokenElement:x})):o&&o({attrs:Ve,scale:Ne,rotate:re})))}const q={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 K(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:k,photoClassName:N,photoWrapClassName:W,loadingElement:$,brokenElement:S,images:T,index:V=0,onIndexChange:R,visible:A,onClose:I,afterClose:H,portalContainer:L}=o,[F,D]=g(q),[O,B]=s(0),{x:z,touched:K,pause:U,lastCX:G,lastCY:J,bg:Q=d,lastBg:Z,overlay:ee,minimal:te,scale:ne,rotate:oe,onScale:re,onRotate:ie}=F,ae=o.hasOwnProperty("index"),ce=ae?V:O,se=ae?R:B,le=t(ce),ue=T.length,de=T[ce],he="boolean"==typeof r?r:ue>r,[me,fe,ve]=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(me)return D({pause:!0,x:ce*-(innerWidth+20)}),void(le.current=ce);D(q)},[me]);const{close:ge,changeIndex:pe}=v({close(e){ie&&ie(0),D({overlay:!0,lastBg:Q}),I(e)},changeIndex(e,t=!1){const n=he?le.current+(e-ce):e,o=ue-1,r=x(n,0,o),i=he?n:r,a=innerWidth+20;D({touched:!1,lastCX:void 0,lastCY:void 0,x:-a*i,pause:t}),le.current=i,se&&se(he?e<0?o:e>o?0:e:r)}});function we(e){return e?ge():D({overlay:!ee})}function ye(){D({x:-(innerWidth+20)*ce,lastCX:void 0,lastCY:void 0,pause:!0}),le.current=ce}function xe(e,t,n,o){"x"===e?function(e){if(void 0===G)return void D({touched:!0,lastCX:e,x:z,pause:!1});const t=e-G;let n=t;!he&&(0===ce&&t>0||ce===ue-1&&t<0)&&(n=t/2),D({touched:!0,lastCX:G,x:-(innerWidth+20)*le.current+n,pause:!1})}(t):"y"===e&&function(e,t){if(void 0===J)return void D({touched:!0,lastCY:e,bg:Q,minimal:!0});const n=null===d?null:x(d,.01,d-Math.abs(e-J)/100/4);D({touched:!0,lastCY:J,bg:1===t?n:d,minimal:1===t})}(n,o)}function Ce(e,t){const n=e-(null!=G?G:e),o=t-(null!=J?J:t);let r=!1;if(n<-40)return void pe(ce+1);if(n>40)return void pe(ce-1);const i=-(innerWidth+20)*le.current;Math.abs(o)>100&&te&&h&&(r=!0,ge()),D({touched:!1,x:i,lastCX:void 0,lastCY:void 0,bg:d,overlay:!!r||ee})}E("keydown",e=>{if(A)switch(e.key){case"ArrowLeft":pe(ce-1,!0);break;case"ArrowRight":pe(ce+1,!0);break;case"Escape":ge()}});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,ce,he);if(!me)return null;const Ee=ee&&!fe,ke=A?Q:Z,_e=re&&ie&&{images:T,index:ce,visible:A,onClose:ge,onIndexChange:pe,overlayVisible:Ee,overlay:de&&de.overlay,scale:ne,rotate:oe,onScale:re,onRotate:ie},Pe=i?i(fe):400,Ye=c?c(fe):"cubic-bezier(0.25, 0.8, 0.25, 1)",Xe=i?i(3):600,Me=c?c(3):"cubic-bezier(0.25, 0.8, 0.25, 1)";return e.createElement(_,{className:`PhotoView-Portal${Ee?"":" PhotoView-Slider__clean"}${A?"":" PhotoView-Slider__willClose"}${C?` ${C}`:""}`,role:"dialog",onClick:e=>e.stopPropagation(),container:L},A&&e.createElement(M,null),e.createElement("div",{className:`PhotoView-Slider__Backdrop${k?` ${k}`:""}${1===fe?" PhotoView-Slider__fadeIn":2===fe?" PhotoView-Slider__fadeOut":""}`,style:{background:ke?`rgba(0, 0, 0, ${ke})`:void 0,transitionTimingFunction:Ye,transitionDuration:`${K?0:Pe}ms`,animationDuration:`${Pe}ms`},onAnimationEnd:ve}),m&&e.createElement("div",{className:"PhotoView-Slider__BannerWrap"},e.createElement("div",{className:"PhotoView-Slider__Counter"},ce+1," / ",ue),e.createElement("div",{className:"PhotoView-Slider__BannerRight"},p&&_e&&p(_e),e.createElement(P,{className:"PhotoView-Slider__toolbarIcon",onClick:ge}))),be.map((t,n)=>{const o=he||0!==ce?le.current-1+n:ce+n;return e.createElement(j,{key:he?`${t.key}/${t.src}/${o}`:t.key,item:t,speed:Pe,easing:Ye,visible:A,onReachMove:xe,onReachUp:Ce,onPhotoTap:()=>we(l),onMaskTap:()=>we(u),wrapClassName:W,className:N,style:{left:(innerWidth+20)*o+"px",transform:`translate3d(${z}px, 0px, 0)`,transition:K||U?void 0:`transform ${Xe}ms ${Me}`},loadingElement:$,brokenElement:S,onPhotoResize:ye,isActive:(de&&de.key)===t.key,expose:D})}),!y&&m&&e.createElement(e.Fragment,null,(he||0!==ce)&&e.createElement("div",{className:"PhotoView-Slider__ArrowLeft",onClick:()=>pe(ce-1,!0)},e.createElement(Y,null)),(he||ce+1<ue)&&e.createElement("div",{className:"PhotoView-Slider__ArrowRight",onClick:()=>pe(ce+1,!0)},e.createElement(X,null))),f&&_e&&e.createElement("div",{className:"PhotoView-Slider__Overlay"},f(_e)))}const U=["children","onIndexChange","onVisibleChange"],G={images:[],visible:!1,index:0};function J(n){let{children:o,onIndexChange:r,onVisibleChange:i}=n,c=f(n,U);const[s,l]=g(G),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){l(t=>{const n=t.images.filter(t=>t.key!==e);return{images:n,index:Math.min(n.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(K,m({images:d,visible:h,index:w,onIndexChange:x.changeIndex,onClose:x.close},c)))}const Q=({src:e,render:n,overlay:o,width:i,height:c,triggers:s=["onClick"],children:h})=>{const f=l(p),g=function(e){const{current:n}=t({sign:!1,fn:void 0});return n.sign||(n.sign=!0,n.fn=f.nextId()),n.fn}(),w=t(null);r(()=>()=>{f.remove(g)},[]);const y=v({render:e=>n&&n(e),show(e,t){f.show(g),function(e,t){if(h){const n=h.props[e];n&&n(t)}}(e,t)}}),x=a(()=>{const e={};return s.forEach(t=>{e[t]=y.show.bind(null,t)}),e},[]);return r(()=>{f.update({key:g,src:e,originRef:w,render:y.render,overlay:o,width:i,height:c})},[e]),h?u.only(d(h,m({},x,{ref:w}))):null};export{J as PhotoProvider,K as PhotoSlider,Q 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,useImperativeHandle as u,Children as d,cloneElement as h}from"react";import{createPortal as m}from"react-dom";function f(){return f=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},f.apply(this,arguments)}function v(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 g(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 p(e){return n((e,t)=>f({},e,"function"==typeof t?t(e):t),e)}var w=o(void 0);const x=1,C="undefined"!=typeof window&&"ontouchstart"in window,b=(e,t,n)=>Math.max(Math.min(e,n),t),y=(e,t=0,n=0)=>b(e,1*(1-n),Math.max(6,t)*(1+n));var E="undefined"==typeof window||/ServerSideRendering/.test(navigator&&navigator.userAgent)?r:i;function k(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 _=["container"];function P(t){let{container:n=document.body}=t,o=v(t,_);return m(e.createElement("div",f({},o)),n)}function Y(t){return e.createElement("svg",f({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 X(t){return e.createElement("svg",f({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 M(t){return e.createElement("svg",f({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 N(){return r(()=>{const{style:e}=document.body,t=e.overflow;return e.overflow="hidden",()=>{e.overflow=t}},[]),null}function W(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 $=(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 S(e,t,n,o,r,i,a=innerWidth/2,c=innerHeight/2,s=0,l=0){const[u]=$(e,i,n,innerWidth),[d]=$(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 T(e,t,n){const o=e%180!=0;return o?[n,t,o]:[t,n,o]}function V(e,t,n){const[o,r,i]=T(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 R(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 A=(e,t,n)=>H(e,t,n,100,e=>e,()=>H(t,e,n)),I=e=>1-(1-e)**4;function H(e,t,n,o=400,r=I,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 L={T:0,L:0,W:0,H:0,FIT:void 0},F=()=>{const e=t(!1);return r(()=>(e.current=!0,()=>{e.current=!1}),[]),e},D=["className"];function O(t){let{className:n}=t,o=v(t,D);return e.createElement("div",f({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 B=["src","loaded","broken","className","onPhotoLoad","loadingElement","brokenElement"];function z(t){let{src:n,loaded:o,broken:r,className:i,onPhotoLoad:a,loadingElement:c,brokenElement:s}=t,l=v(t,B);const u=F();return n&&!r?e.createElement(e.Fragment,null,e.createElement("img",f({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(O,{className:"PhotoView__icon"}))):s?e.createElement("span",{className:"PhotoView__icon"},"function"==typeof s?s({src:n}):s):null}const j={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 q({item:{src:n,render:o,width:i=0,height:a=0,originRef:c},visible:l,speed:u,easing:d,wrapClassName:h,className:m,style:v,loadingElement:w,brokenElement:x,onPhotoTap:b,onMaskTap:_,onReachMove:P,onReachUp:Y,onPhotoResize:X,isActive:M,expose:N}){const[I,D]=p(j),O=t(0),B=F(),{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}=I,pe=g({onScale:e=>we(y(e)),onRotate(e){re!==e&&(N({rotate:e}),D(f({rotate:e},V(q,K,e))))}});function we(e,t,n){ie!==e&&(N({scale:e}),D(f({scale:e},S(Z,ee,U,G,ie,e,t,n),e<=1&&{x:0,y:0})))}const xe=R((e,t,n=0)=>{if((te||oe)&&M){const[o,r]=T(re,U,G);if(0===n&&0===O.current){const n=Math.abs(e-ae)<=20,o=Math.abs(t-ce)<=20;if(n&&o)return void D({lastCX:e,lastCY:t});O.current=n?t>ce?3:2:1}const i=e-ue,a=t-de;let c;if(0===n){const[n]=$(i+se,ie,o,innerWidth),[s]=$(a+le,ie,r,innerHeight);c=((e,t,n,o)=>t&&1===e||"x"===o?"x":n&&e>1||"y"===o?"y":void 0)(O.current,n,s,ge),void 0!==c&&P(c,e,t,ie)}if("x"===c||oe)return void D({reach:"x"});const s=y(ie+(n-fe)/100/2*ie,q/U,.2);N({scale:s}),D(f({touchLength:n,reach:c,scale:s},S(Z,ee,U,G,ie,s,e,t,i,a)))}},{maxWait:8});function Ce(e){return!ne&&!te&&(B.current&&D(f({},e,{pause:l})),B.current)}const be=function(e,t,n){const o=g({X:e=>Ce({x:e}),Y:e=>Ce({y:e}),S:e=>{return t=e,B.current&&(N({scale:t}),D({scale:t})),!te&&B.current;var t}});return(e,t,n,r,i,a,c,s,l,u,d)=>{const[h,m]=T(u,i,a),[f,v]=$(e,s,h,innerWidth),[g,p]=$(t,s,m,innerHeight),w=Date.now()-d;if(w>=200||s!=c||Math.abs(l-c)>1){const{x:n,y:r}=S(e,t,i,a,c,s),l=f?v:n!==e?n:null,u=g?p:r!==t?r:null;return null!==l&&H(e,l,o.X),null!==u&&H(t,u,o.Y),void(s!=c&&H(c,s,o.S))}const x=(e-n)/w,C=(t-r)/w,b=Math.sqrt(x**2+C**2);let y=!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()}(b,n=>{const r=e+n*(x/b),i=t+n*(C/b),[a,s]=$(r,c,h,innerWidth),[l,u]=$(i,c,m,innerHeight);if(a&&!y&&(y=!0,f?H(r,s,o.X):A(s,r+(r-s),o.X)),l&&!E&&(E=!0,g?H(i,u,o.Y):A(u,i+(i-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),r=R((...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))}}(b);function Ee(e,t){if(O.current=0,(te||oe)&&M){D({touched:!1,maskTouched:!1,pause:!1,stopRaf:!1,reach:void 0});const n=y(ie,q/U);if(be(Z,ee,se,le,U,G,ie,n,he,re,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:ie,touchLength:n,touchTime:Date.now()})}function _e(e){D({maskTouched:!0,CX:e.clientX,CY:e.clientY,lastX:Z,lastY:ee})}k(C?void 0:"mousemove",e=>{e.preventDefault(),xe(e.clientX,e.clientY)}),k(C?void 0:"mouseup",e=>{Ee(e.clientX,e.clientY)}),k(C?"touchmove":void 0,e=>{e.preventDefault();const t=W(e);xe(...t)},{passive:!1}),k(C?"touchend":void 0,({changedTouches:e})=>{const t=e[0];Ee(t.clientX,t.clientY)},{passive:!1}),k("resize",R(()=>{J&&!te&&(D(V(q,K,re)),X())},{maxWait:8})),E(()=>{M&&N(f({scale:ie,rotate:re},pe))},[M]);const[Pe,Ye,Xe,Me,Ne,We,$e,Se]=function(e,n,o,i,a,c,l,u,d,h){const[m,f,v]=function(e,n,o,r,i){const a=t(!1),[{lead:c,scale:s},l]=p({lead:!0,scale:o}),u=R(async e=>{i(!0),l({lead:!1,scale:e})},{wait:r});return E(()=>{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,x]=function(e,n,o,i,a){const[c,l]=s(L),[u,d]=s(0),h=t(),m=g({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:C,L:b,W:y,H:k,FIT:_}=x,P=innerWidth/2,Y=innerHeight/2,X=w<3||w>4;return[X?y?b:P:i+(P-c*u/2),X?y?C:Y:a+(Y-l*u/2),m,X&&_?m*(k/y):f,0===w?v:X?y/(c*u)||.01:v,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:m,onMouseDown:C?void 0:function(e){e.stopPropagation(),0===e.button&&ke(e.clientX,e.clientY,0)},onTouchStart:C?function(e){e.stopPropagation(),ke(...W(e))}:void 0,onWheel:function(e){if(!ge){const t=y(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:v,onMouseDown:!C&&M?_e:void 0,onTouchStart:C&&M?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:M?"transform":void 0}},n?e.createElement(z,f({src:n,loaded:J,broken:Q},Ve,{onPhotoLoad:function(e){D(f({},e,e.loaded&&V(e.naturalWidth||0,e.naturalHeight||0,re)))},loadingElement:w,brokenElement:x})):o&&o({attrs:Ve,scale:Ne,rotate:re})))}const K={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 U(o){const{loop:r=3,speed:i,easing:c,photoClosable:l,maskClosable:u=!0,maskOpacity:d=x,pullClosable:h=!0,bannerVisible:m=!0,overlayRender:f,toolbarRender:v,className:w,maskClassName:y,photoClassName:_,photoWrapClassName:W,loadingElement:$,brokenElement:S,images:T,index:V=0,onIndexChange:R,visible:A,onClose:I,afterClose:H,portalContainer:L}=o,[F,D]=p(K),[O,B]=s(0),{x:z,touched:j,pause:U,lastCX:G,lastCY:J,bg:Q=d,lastBg:Z,overlay:ee,minimal:te,scale:ne,rotate:oe,onScale:re,onRotate:ie}=F,ae=o.hasOwnProperty("index"),ce=ae?V:O,se=ae?R:B,le=t(ce),ue=T.length,de=T[ce],he="boolean"==typeof r?r:ue>r,[me,fe,ve]=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);E(()=>{if(me)return D({pause:!0,x:ce*-(innerWidth+20)}),void(le.current=ce);D(K)},[me]);const{close:ge,changeIndex:pe}=g({close(e){ie&&ie(0),D({overlay:!0,lastBg:Q}),I(e)},changeIndex(e,t=!1){const n=he?le.current+(e-ce):e,o=ue-1,r=b(n,0,o),i=he?n:r,a=innerWidth+20;D({touched:!1,lastCX:void 0,lastCY:void 0,x:-a*i,pause:t}),le.current=i,se&&se(he?e<0?o:e>o?0:e:r)}});function we(e){return e?ge():D({overlay:!ee})}function xe(){D({x:-(innerWidth+20)*ce,lastCX:void 0,lastCY:void 0,pause:!0}),le.current=ce}function Ce(e,t,n,o){"x"===e?function(e){if(void 0===G)return void D({touched:!0,lastCX:e,x:z,pause:!1});const t=e-G;let n=t;!he&&(0===ce&&t>0||ce===ue-1&&t<0)&&(n=t/2),D({touched:!0,lastCX:G,x:-(innerWidth+20)*le.current+n,pause:!1})}(t):"y"===e&&function(e,t){if(void 0===J)return void D({touched:!0,lastCY:e,bg:Q,minimal:!0});const n=null===d?null:b(d,.01,d-Math.abs(e-J)/100/4);D({touched:!0,lastCY:J,bg:1===t?n:d,minimal:1===t})}(n,o)}function be(e,t){const n=e-(null!=G?G:e),o=t-(null!=J?J:t);let r=!1;if(n<-40)return void pe(ce+1);if(n>40)return void pe(ce-1);const i=-(innerWidth+20)*le.current;Math.abs(o)>100&&te&&h&&(r=!0,ge()),D({touched:!1,x:i,lastCX:void 0,lastCY:void 0,bg:d,overlay:!!r||ee})}k("keydown",e=>{if(A)switch(e.key){case"ArrowLeft":pe(ce-1,!0);break;case"ArrowRight":pe(ce+1,!0);break;case"Escape":ge()}});const ye=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,ce,he);if(!me)return null;const Ee=ee&&!fe,ke=A?Q:Z,_e=re&&ie&&{images:T,index:ce,visible:A,onClose:ge,onIndexChange:pe,overlayVisible:Ee,overlay:de&&de.overlay,scale:ne,rotate:oe,onScale:re,onRotate:ie},Pe=i?i(fe):400,Ye=c?c(fe):"cubic-bezier(0.25, 0.8, 0.25, 1)",Xe=i?i(3):600,Me=c?c(3):"cubic-bezier(0.25, 0.8, 0.25, 1)";return e.createElement(P,{className:`PhotoView-Portal${Ee?"":" PhotoView-Slider__clean"}${A?"":" PhotoView-Slider__willClose"}${w?` ${w}`:""}`,role:"dialog",onClick:e=>e.stopPropagation(),container:L},A&&e.createElement(N,null),e.createElement("div",{className:`PhotoView-Slider__Backdrop${y?` ${y}`:""}${1===fe?" PhotoView-Slider__fadeIn":2===fe?" PhotoView-Slider__fadeOut":""}`,style:{background:ke?`rgba(0, 0, 0, ${ke})`:void 0,transitionTimingFunction:Ye,transitionDuration:`${j?0:Pe}ms`,animationDuration:`${Pe}ms`},onAnimationEnd:ve}),m&&e.createElement("div",{className:"PhotoView-Slider__BannerWrap"},e.createElement("div",{className:"PhotoView-Slider__Counter"},ce+1," / ",ue),e.createElement("div",{className:"PhotoView-Slider__BannerRight"},v&&_e&&v(_e),e.createElement(Y,{className:"PhotoView-Slider__toolbarIcon",onClick:ge}))),ye.map((t,n)=>{const o=he||0!==ce?le.current-1+n:ce+n;return e.createElement(q,{key:he?`${t.key}/${t.src}/${o}`:t.key,item:t,speed:Pe,easing:Ye,visible:A,onReachMove:Ce,onReachUp:be,onPhotoTap:()=>we(l),onMaskTap:()=>we(u),wrapClassName:W,className:_,style:{left:(innerWidth+20)*o+"px",transform:`translate3d(${z}px, 0px, 0)`,transition:j||U?void 0:`transform ${Xe}ms ${Me}`},loadingElement:$,brokenElement:S,onPhotoResize:xe,isActive:le.current===o,expose:D})}),!C&&m&&e.createElement(e.Fragment,null,(he||0!==ce)&&e.createElement("div",{className:"PhotoView-Slider__ArrowLeft",onClick:()=>pe(ce-1,!0)},e.createElement(X,null)),(he||ce+1<ue)&&e.createElement("div",{className:"PhotoView-Slider__ArrowRight",onClick:()=>pe(ce+1,!0)},e.createElement(M,null))),f&&_e&&e.createElement("div",{className:"PhotoView-Slider__Overlay"},f(_e)))}const G=["children","onIndexChange","onVisibleChange"],J={images:[],visible:!1,index:0};function Q(n){let{children:o,onIndexChange:r,onVisibleChange:i}=n,c=v(n,G);const[s,l]=p(J),u=t(0),{images:d,visible:h,index:m}=s,x=g({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){l(t=>{const n=t.images.filter(t=>t.key!==e);return{images:n,index:Math.min(n.length-1,m)}})},show(e){const t=d.findIndex(t=>t.key===e);l({visible:!0,index:t}),i&&i(!0,t,s)}}),C=g({close(){l({visible:!1}),i&&i(!1,m,s)},changeIndex(e){l({index:e}),r&&r(e,s)}}),b=a(()=>f({},s,x),[s,x]);return e.createElement(w.Provider,{value:b},o,e.createElement(U,f({images:d,visible:h,index:m,onIndexChange:C.changeIndex,onClose:C.close},c)))}const Z=({src:e,render:n,overlay:o,width:i,height:c,triggers:s=["onClick"],children:m})=>{const v=l(w),p=function(e){const{current:n}=t({sign:!1,fn:void 0});return n.sign||(n.sign=!0,n.fn=v.nextId()),n.fn}(),x=t(null);u(null==m?void 0:m.ref,()=>x.current),r(()=>()=>{v.remove(p)},[]);const C=g({render:e=>n&&n(e),show(e,t){v.show(p),function(e,t){if(m){const n=m.props[e];n&&n(t)}}(e,t)}}),b=a(()=>{const e={};return s.forEach(t=>{e[t]=C.show.bind(null,t)}),e},[]);return r(()=>{v.update({key:p,src:e,originRef:x,render:C.render,overlay:o,width:i,height:c})},[e]),m?d.only(h(m,f({},b,{ref:x}))):null};export{Q as PhotoProvider,U as PhotoSlider,Z 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=["container"];function k(n){var t=n.container,r=void 0===t?document.body:t,i=h(n,E);return v(e.createElement("div",f({},i)),r)}function P(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 _(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 M(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 Y(){return i(function(){var e=document.body.style,n=e.overflow;return e.overflow="hidden",function(){e.overflow=n}},[]),null}function X(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 N=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 W(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=N(e,o,t,innerWidth)[0],d=N(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 S(e,n,t){var r=e%180!=0;return r?[t,n,r]:[n,t,r]}function T(e,n,t){var r=S(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 V(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 R=function(e,n,t){return I(e,n,t,100,function(e){return e},function(){return I(n,e,t)})},A=function(e){return 1-Math.pow(1-e,4)};function I(e,n,t,r,i,o){void 0===r&&(r=400),void 0===i&&(i=A);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 H={T:0,L:0,W:0,H:0,FIT:void 0},L=function(){var e=n(!1);return i(function(){return e.current=!0,function(){e.current=!1}},[]),e},F=["className"];function D(n){var t=n.className,r=h(n,F);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 O=["src","loaded","broken","className","onPhotoLoad","loadingElement","brokenElement"];function B(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,O),s=L();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(D,{className:"PhotoView__icon"}))):u?e.createElement("span",{className:"PhotoView__icon"},"function"==typeof u?u({src:t}):u):null}var z={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 j(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,Y=t.onPhotoTap,A=t.onMaskTap,F=t.onReachMove,D=t.onReachUp,O=t.onPhotoResize,j=t.isActive,q=t.expose,K=g(z),U=K[0],G=K[1],J=n(0),Q=L(),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},T($,ne,e))))}});function Ye(e,n,t){me!==e&&(q({scale:e}),G(f({scale:e},W(le,se,re,oe,me,e,n,t),e<=1&&{x:0,y:0})))}var Xe=V(function(e,n,t){if(void 0===t&&(t=0),(de||fe)&&j){var r=S(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=N(u+we,me,i,innerWidth)[0],v=N(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},W(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=S(l,i,o),v=d[0],f=d[1],h=N(e,c,v,innerWidth),m=h[0],g=h[1],p=N(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=W(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&&I(e,k,He.X),null!==P&&I(n,P,He.Y),void(c!=a&&I(a,c,He.S))}var _=(e-t)/x,M=(n-r)/x,Y=Math.sqrt(Math.pow(_,2)+Math.pow(M,2)),X=!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=N(r,a,v,innerWidth),c=o[0],u=o[1],l=N(i,a,f,innerHeight),s=l[0],d=l[1];if(c&&!X&&(X=!0,m?I(r,u,He.X):R(u,r+(r-u),He.X)),s&&!T&&(T=!0,w?I(i,d,He.Y):R(d,i+(i-d),He.Y)),X&&T)return!1;var h=X||He.X(u),g=T||He.Y(d);return h&&g})}),Fe=(We=Y,Se=function(e,n){_e||Ye(1!==me?1:Math.max(2,$/re),e,n)},Te=n(0),Ve=V(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&&A(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=X(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",V(function(){ce&&!de&&(G(T($,ne,he)),O())},{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=V(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(H),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,X(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(B,f({src:o,loaded:ce,broken:ue},Ue,{onPhotoLoad:function(e){G(f({},e,e.loaded&&T(e.naturalWidth||0,e.naturalHeight||0,he)))},loadingElement:_,brokenElement:M})):a&&a({attrs:Ue,scale:je,rotate:he})))}var q={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 K(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,E=r.bannerVisible,X=void 0===E||E,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,z=r.afterClose,K=r.portalContainer,U=g(q),G=U[0],J=U[1],Q=u(0),Z=Q[0],$=Q[1],ee=G.x,ne=G.touched,te=G.pause,re=G.lastCX,ie=G.lastCY,oe=G.bg,ae=void 0===oe?h:oe,ce=G.lastBg,ue=G.overlay,le=G.minimal,se=G.scale,de=G.rotate,ve=G.onScale,fe=G.onRotate,he=r.hasOwnProperty("index"),me=he?F:Z,ge=he?D:$,pe=n(me),we=H.length,ye=H[me],xe="boolean"==typeof o?o:we>o,Ce=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,z),be=Ce[0],Ee=Ce[1],ke=Ce[2];C(function(){if(be)return J({pause:!0,x:me*-(innerWidth+20)}),void(pe.current=me);J(q)},[be]);var Pe=m({close:function(e){fe&&fe(0),J({overlay:!0,lastBg:ae}),B(e)},changeIndex:function(e,n){void 0===n&&(n=!1);var t=xe?pe.current+(e-me):e,r=we-1,i=y(t,0,r),o=xe?t:i,a=innerWidth+20;J({touched:!1,lastCX:void 0,lastCY:void 0,x:-a*o,pause:n}),pe.current=o,ge&&ge(xe?e<0?r:e>r?0:e:i)}}),_e=Pe.close,Me=Pe.changeIndex;function Ye(e){return e?_e():J({overlay:!ue})}function Xe(){J({x:-(innerWidth+20)*me,lastCX:void 0,lastCY:void 0,pause:!0}),pe.current=me}function Ne(e,n,t,r){"x"===e?function(e){if(void 0!==re){var n=e-re,t=n;!xe&&(0===me&&n>0||me===we-1&&n<0)&&(t=n/2),J({touched:!0,lastCX:re,x:-(innerWidth+20)*pe.current+t,pause:!1})}else J({touched:!0,lastCX:e,x:ee,pause:!1})}(n):"y"===e&&function(e,n){if(void 0!==ie){var t=null===h?null:y(h,.01,h-Math.abs(e-ie)/100/4);J({touched:!0,lastCY:ie,bg:1===n?t:h,minimal:1===n})}else J({touched:!0,lastCY:e,bg:ae,minimal:!0})}(t,r)}function We(e,n){var t=e-(null!=re?re:e),r=n-(null!=ie?ie:n),i=!1;if(t<-40)Me(me+1);else if(t>40)Me(me-1);else{var o=-(innerWidth+20)*pe.current;Math.abs(r)>100&&le&&x&&(i=!0,_e()),J({touched:!1,x:o,lastCX:void 0,lastCY:void 0,bg:h,overlay:!!i||ue})}}b("keydown",function(e){if(O)switch(e.key){case"ArrowLeft":Me(me-1,!0);break;case"ArrowRight":Me(me+1,!0);break;case"Escape":_e()}});var Se=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,me,xe);if(!be)return null;var Te=ue&&!Ee,Ve=O?ae:ce,Re=ve&&fe&&{images:H,index:me,visible:O,onClose:_e,onIndexChange:Me,overlayVisible:Te,overlay:ye&&ye.overlay,scale:se,rotate:de,onScale:ve,onRotate:fe},Ae=c?c(Ee):400,Ie=l?l(Ee):"cubic-bezier(0.25, 0.8, 0.25, 1)",He=c?c(3):600,Le=l?l(3):"cubic-bezier(0.25, 0.8, 0.25, 1)";return e.createElement(k,{className:"PhotoView-Portal"+(Te?"":" PhotoView-Slider__clean")+(O?"":" PhotoView-Slider__willClose")+(S?" "+S:""),role:"dialog",onClick:function(e){return e.stopPropagation()},container:K},O&&e.createElement(Y,null),e.createElement("div",{className:"PhotoView-Slider__Backdrop"+(T?" "+T:"")+(1===Ee?" PhotoView-Slider__fadeIn":2===Ee?" PhotoView-Slider__fadeOut":""),style:{background:Ve?"rgba(0, 0, 0, "+Ve+")":void 0,transitionTimingFunction:Ie,transitionDuration:(ne?0:Ae)+"ms",animationDuration:Ae+"ms"},onAnimationEnd:ke}),X&&e.createElement("div",{className:"PhotoView-Slider__BannerWrap"},e.createElement("div",{className:"PhotoView-Slider__Counter"},me+1," / ",we),e.createElement("div",{className:"PhotoView-Slider__BannerRight"},W&&Re&&W(Re),e.createElement(P,{className:"PhotoView-Slider__toolbarIcon",onClick:_e}))),Se.map(function(n,t){var r=xe||0!==me?pe.current-1+t:me+t;return e.createElement(j,{key:xe?n.key+"/"+n.src+"/"+r:n.key,item:n,speed:Ae,easing:Ie,visible:O,onReachMove:Ne,onReachUp:We,onPhotoTap:function(){return Ye(s)},onMaskTap:function(){return Ye(v)},wrapClassName:R,className:V,style:{left:(innerWidth+20)*r+"px",transform:"translate3d("+ee+"px, 0px, 0)",transition:ne||te?void 0:"transform "+He+"ms "+Le},loadingElement:A,brokenElement:I,onPhotoResize:Xe,isActive:(ye&&ye.key)===n.key,expose:J})}),!w&&X&&e.createElement(e.Fragment,null,(xe||0!==me)&&e.createElement("div",{className:"PhotoView-Slider__ArrowLeft",onClick:function(){return Me(me-1,!0)}},e.createElement(_,null)),(xe||me+1<we)&&e.createElement("div",{className:"PhotoView-Slider__ArrowRight",onClick:function(){return Me(me+1,!0)}},e.createElement(M,null))),N&&Re&&e.createElement("div",{className:"PhotoView-Slider__Overlay"},N(Re)))}var U=["children","onIndexChange","onVisibleChange"],G={images:[],visible:!1,index:0};function J(t){var r=t.children,i=t.onIndexChange,o=t.onVisibleChange,c=h(t,U),u=g(G),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){s(function(n){var t=n.images.filter(function(n){return n.key!==e});return{images:t,index:Math.min(t.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(K,f({images:v,visible:w,index:y,onIndexChange:C.changeIndex,onClose:C.close},c)))}var Q=function(e){var t,r,o=e.src,c=e.render,u=e.overlay,v=e.width,h=e.height,g=e.triggers,w=void 0===g?["onClick"]:g,y=e.children,x=l(p),C=(t=function(){return x.nextId()},(r=n({sign:!1,fn:void 0}).current).sign||(r.sign=!0,r.fn=t()),r.fn),b=n(null);i(function(){return function(){x.remove(C)}},[]);var E=m({render:function(e){return c&&c(e)},show:function(e,n){x.show(C),function(e,n){if(y){var t=y.props[e];t&&t(n)}}(e,n)}}),k=a(function(){var e={};return w.forEach(function(n){e[n]=E.show.bind(null,n)}),e},[]);return i(function(){x.update({key:C,src:o,originRef:b,render:E.render,overlay:u,width:v,height:h})},[o]),y?s.only(d(y,f({},k,{ref:b}))):null};export{J as PhotoProvider,K as PhotoSlider,Q 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,useImperativeHandle as s,Children as d,cloneElement as v}from"react";import{createPortal as f}from"react-dom";function h(){return h=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},h.apply(this,arguments)}function m(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 g(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 p(e){return t(function(e,n){return h({},e,"function"==typeof n?n(e):n)},e)}var w=r(void 0),y="undefined"!=typeof window&&"ontouchstart"in window,x=function(e,n,t){return Math.max(Math.min(e,t),n)},C=function(e,n,t){return void 0===n&&(n=0),void 0===t&&(t=0),x(e,1*(1-t),Math.max(6,n)*(1+t))},b="undefined"==typeof window||/ServerSideRendering/.test(navigator&&navigator.userAgent)?i:o;function E(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 k=["container"];function P(n){var t=n.container,r=void 0===t?document.body:t,i=m(n,k);return f(e.createElement("div",h({},i)),r)}function _(n){return e.createElement("svg",h({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 M(n){return e.createElement("svg",h({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 Y(n){return e.createElement("svg",h({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 X(){return i(function(){var e=document.body.style,n=e.overflow;return e.overflow="hidden",function(){e.overflow=n}},[]),null}function N(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 W=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 S(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=W(e,o,t,innerWidth)[0],d=W(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 T(e,n,t){var r=e%180!=0;return r?[t,n,r]:[n,t,r]}function V(e,n,t){var r=T(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 R(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 A=function(e,n,t){return H(e,n,t,100,function(e){return e},function(){return H(n,e,t)})},I=function(e){return 1-Math.pow(1-e,4)};function H(e,n,t,r,i,o){void 0===r&&(r=400),void 0===i&&(i=I);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 L={T:0,L:0,W:0,H:0,FIT:void 0},F=function(){var e=n(!1);return i(function(){return e.current=!0,function(){e.current=!1}},[]),e},D=["className"];function O(n){var t=n.className,r=m(n,D);return e.createElement("div",h({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 B=["src","loaded","broken","className","onPhotoLoad","loadingElement","brokenElement"];function z(n){var t=n.src,r=n.loaded,i=n.broken,o=n.className,a=n.onPhotoLoad,c=n.loadingElement,u=n.brokenElement,l=m(n,B),s=F();return t&&!i?e.createElement(e.Fragment,null,e.createElement("img",h({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(O,{className:"PhotoView__icon"}))):u?e.createElement("span",{className:"PhotoView__icon"},"function"==typeof u?u({src:t}):u):null}var j={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 q(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,f=t.visible,m=t.speed,w=t.easing,x=t.wrapClassName,k=t.className,P=t.style,_=t.loadingElement,M=t.brokenElement,Y=t.onPhotoTap,X=t.onMaskTap,I=t.onReachMove,D=t.onReachUp,O=t.onPhotoResize,B=t.isActive,q=t.expose,K=p(j),U=K[0],G=K[1],J=n(0),Q=F(),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=g({onScale:function(e){return Ye(C(e))},onRotate:function(e){he!==e&&(q({rotate:e}),G(h({rotate:e},V($,ne,e))))}});function Ye(e,n,t){me!==e&&(q({scale:e}),G(h({scale:e},S(le,se,re,oe,me,e,n,t),e<=1&&{x:0,y:0})))}var Xe=R(function(e,n,t){if(void 0===t&&(t=0),(de||fe)&&B){var r=T(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=W(u+we,me,i,innerWidth)[0],v=W(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&&I(s,e,n,me)}if("x"===s||fe)return void G({reach:"x"});var f=C(me+(t-ke)/100/2*me,$/re,.2);q({scale:f}),G(h({touchLength:t,reach:s,scale:f},S(le,se,re,oe,me,f,e,n,u,l)))}},{maxWait:8});function Ne(e){return!ve&&!de&&(Q.current&&G(h({},e,{pause:f})),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=g({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=T(l,i,o),v=d[0],f=d[1],h=W(e,c,v,innerWidth),m=h[0],g=h[1],p=W(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=S(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&&H(e,k,He.X),null!==P&&H(n,P,He.Y),void(c!=a&&H(a,c,He.S))}var _=(e-t)/x,M=(n-r)/x,Y=Math.sqrt(Math.pow(_,2)+Math.pow(M,2)),X=!1,N=!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=W(r,a,v,innerWidth),c=o[0],u=o[1],l=W(i,a,f,innerHeight),s=l[0],d=l[1];if(c&&!X&&(X=!0,m?H(r,u,He.X):A(u,r+(r-u),He.X)),s&&!N&&(N=!0,w?H(i,d,He.Y):A(d,i+(i-d),He.Y)),X&&N)return!1;var h=X||He.X(u),g=N||He.Y(d);return h&&g})}),Fe=(We=Y,Se=function(e,n){_e||Ye(1!==me?1:Math.max(2,$/re),e,n)},Te=n(0),Ve=R(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)&&B){G({touched:!1,maskTouched:!1,pause:!1,stopRaf:!1,reach:void 0});var t=C(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&&X(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})}E(y?void 0:"mousemove",function(e){e.preventDefault(),Xe(e.clientX,e.clientY)}),E(y?void 0:"mouseup",function(e){De(e.clientX,e.clientY)}),E(y?"touchmove":void 0,function(e){e.preventDefault();var n=N(e);Xe.apply(void 0,n)},{passive:!1}),E(y?"touchend":void 0,function(e){var n=e.changedTouches[0];De(n.clientX,n.clientY)},{passive:!1}),E("resize",R(function(){ce&&!de&&(G(V($,ne,he)),O())},{maxWait:8})),b(function(){B&&q(h({scale:me,rotate:he},Me))},[B]);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=p({lead:!0,scale:r}),u=c[0],l=u.lead,s=u.scale,d=c[1],v=R(function(e){try{return o(!0),d({lead:!1,scale:e}),Promise.resolve()}catch(e){return Promise.reject(e)}},{wait:i});return b(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],m=f[1],w=f[2],y=function(e,t,r,o,a){var c=u(L),l=c[0],s=c[1],d=u(0),v=d[0],f=d[1],h=n(),m=g({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(m.OK,o)):void f(4);p(5)}},[e,r]),[v,l]}(e,t,r,d,v),x=y[0],C=y[1],E=C.W,k=C.FIT,P=innerWidth/2,_=innerHeight/2,M=x<3||x>4;return[M?E?C.L:P:o+(P-c*s/2),M?E?C.T:_:a+(_-l*s/2),h,M&&k?h*(C.H/E):m,0===x?w:M?E/(c*s)||.01:w,M?k?1:0:1,x,k]}(f,v,ce,le,se,re,oe,me,m,function(e){return G({pause:e})}),je=ze[4],qe=ze[6],Ke="transform "+m+"ms "+w,Ue={className:k,onMouseDown:y?void 0:function(e){e.stopPropagation(),0===e.button&&Oe(e.clientX,e.clientY,0)},onTouchStart:y?function(e){e.stopPropagation(),Oe.apply(void 0,N(e))}:void 0,onWheel:function(e){if(!_e){var n=C(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 "+m+"ms ease, height "+(qe<4?m/2:qe>4?m:0)+"ms "+w:void 0}};return e.createElement("div",{className:"PhotoView__PhotoWrap"+(x?" "+x:""),style:P,onMouseDown:!y&&B?Be:void 0,onTouchStart:y&&B?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:B?"transform":void 0}},o?e.createElement(z,h({src:o,loaded:ce,broken:ue},Ue,{onPhotoLoad:function(e){G(h({},e,e.loaded&&V(e.naturalWidth||0,e.naturalHeight||0,he)))},loadingElement:_,brokenElement:M})):a&&a({attrs:Ue,scale:je,rotate:he})))}var K={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 U(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,m=r.pullClosable,w=void 0===m||m,C=r.bannerVisible,k=void 0===C||C,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,z=r.afterClose,j=r.portalContainer,U=p(K),G=U[0],J=U[1],Q=u(0),Z=Q[0],$=Q[1],ee=G.x,ne=G.touched,te=G.pause,re=G.lastCX,ie=G.lastCY,oe=G.bg,ae=void 0===oe?h:oe,ce=G.lastBg,ue=G.overlay,le=G.minimal,se=G.scale,de=G.rotate,ve=G.onScale,fe=G.onRotate,he=r.hasOwnProperty("index"),me=he?F:Z,ge=he?D:$,pe=n(me),we=H.length,ye=H[me],xe="boolean"==typeof o?o:we>o,Ce=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,z),be=Ce[0],Ee=Ce[1],ke=Ce[2];b(function(){if(be)return J({pause:!0,x:me*-(innerWidth+20)}),void(pe.current=me);J(K)},[be]);var Pe=g({close:function(e){fe&&fe(0),J({overlay:!0,lastBg:ae}),B(e)},changeIndex:function(e,n){void 0===n&&(n=!1);var t=xe?pe.current+(e-me):e,r=we-1,i=x(t,0,r),o=xe?t:i,a=innerWidth+20;J({touched:!1,lastCX:void 0,lastCY:void 0,x:-a*o,pause:n}),pe.current=o,ge&&ge(xe?e<0?r:e>r?0:e:i)}}),_e=Pe.close,Me=Pe.changeIndex;function Ye(e){return e?_e():J({overlay:!ue})}function Xe(){J({x:-(innerWidth+20)*me,lastCX:void 0,lastCY:void 0,pause:!0}),pe.current=me}function Ne(e,n,t,r){"x"===e?function(e){if(void 0!==re){var n=e-re,t=n;!xe&&(0===me&&n>0||me===we-1&&n<0)&&(t=n/2),J({touched:!0,lastCX:re,x:-(innerWidth+20)*pe.current+t,pause:!1})}else J({touched:!0,lastCX:e,x:ee,pause:!1})}(n):"y"===e&&function(e,n){if(void 0!==ie){var t=null===h?null:x(h,.01,h-Math.abs(e-ie)/100/4);J({touched:!0,lastCY:ie,bg:1===n?t:h,minimal:1===n})}else J({touched:!0,lastCY:e,bg:ae,minimal:!0})}(t,r)}function We(e,n){var t=e-(null!=re?re:e),r=n-(null!=ie?ie:n),i=!1;if(t<-40)Me(me+1);else if(t>40)Me(me-1);else{var o=-(innerWidth+20)*pe.current;Math.abs(r)>100&&le&&w&&(i=!0,_e()),J({touched:!1,x:o,lastCX:void 0,lastCY:void 0,bg:h,overlay:!!i||ue})}}E("keydown",function(e){if(O)switch(e.key){case"ArrowLeft":Me(me-1,!0);break;case"ArrowRight":Me(me+1,!0);break;case"Escape":_e()}});var Se=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,me,xe);if(!be)return null;var Te=ue&&!Ee,Ve=O?ae:ce,Re=ve&&fe&&{images:H,index:me,visible:O,onClose:_e,onIndexChange:Me,overlayVisible:Te,overlay:ye&&ye.overlay,scale:se,rotate:de,onScale:ve,onRotate:fe},Ae=c?c(Ee):400,Ie=l?l(Ee):"cubic-bezier(0.25, 0.8, 0.25, 1)",He=c?c(3):600,Le=l?l(3):"cubic-bezier(0.25, 0.8, 0.25, 1)";return e.createElement(P,{className:"PhotoView-Portal"+(Te?"":" PhotoView-Slider__clean")+(O?"":" PhotoView-Slider__willClose")+(S?" "+S:""),role:"dialog",onClick:function(e){return e.stopPropagation()},container:j},O&&e.createElement(X,null),e.createElement("div",{className:"PhotoView-Slider__Backdrop"+(T?" "+T:"")+(1===Ee?" PhotoView-Slider__fadeIn":2===Ee?" PhotoView-Slider__fadeOut":""),style:{background:Ve?"rgba(0, 0, 0, "+Ve+")":void 0,transitionTimingFunction:Ie,transitionDuration:(ne?0:Ae)+"ms",animationDuration:Ae+"ms"},onAnimationEnd:ke}),k&&e.createElement("div",{className:"PhotoView-Slider__BannerWrap"},e.createElement("div",{className:"PhotoView-Slider__Counter"},me+1," / ",we),e.createElement("div",{className:"PhotoView-Slider__BannerRight"},W&&Re&&W(Re),e.createElement(_,{className:"PhotoView-Slider__toolbarIcon",onClick:_e}))),Se.map(function(n,t){var r=xe||0!==me?pe.current-1+t:me+t;return e.createElement(q,{key:xe?n.key+"/"+n.src+"/"+r:n.key,item:n,speed:Ae,easing:Ie,visible:O,onReachMove:Ne,onReachUp:We,onPhotoTap:function(){return Ye(s)},onMaskTap:function(){return Ye(v)},wrapClassName:R,className:V,style:{left:(innerWidth+20)*r+"px",transform:"translate3d("+ee+"px, 0px, 0)",transition:ne||te?void 0:"transform "+He+"ms "+Le},loadingElement:A,brokenElement:I,onPhotoResize:Xe,isActive:pe.current===r,expose:J})}),!y&&k&&e.createElement(e.Fragment,null,(xe||0!==me)&&e.createElement("div",{className:"PhotoView-Slider__ArrowLeft",onClick:function(){return Me(me-1,!0)}},e.createElement(M,null)),(xe||me+1<we)&&e.createElement("div",{className:"PhotoView-Slider__ArrowRight",onClick:function(){return Me(me+1,!0)}},e.createElement(Y,null))),N&&Re&&e.createElement("div",{className:"PhotoView-Slider__Overlay"},N(Re)))}var G=["children","onIndexChange","onVisibleChange"],J={images:[],visible:!1,index:0};function Q(t){var r=t.children,i=t.onIndexChange,o=t.onVisibleChange,c=m(t,G),u=p(J),l=u[0],s=u[1],d=n(0),v=l.images,f=l.visible,y=l.index,x=g({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){s(function(n){var t=n.images.filter(function(n){return n.key!==e});return{images:t,index:Math.min(t.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=g({close:function(){s({visible:!1}),o&&o(!1,y,l)},changeIndex:function(e){s({index:e}),i&&i(e,l)}}),b=a(function(){return h({},l,x)},[l,x]);return e.createElement(w.Provider,{value:b},r,e.createElement(U,h({images:v,visible:f,index:y,onIndexChange:C.changeIndex,onClose:C.close},c)))}var Z=function(e){var t,r,o=e.src,c=e.render,u=e.overlay,f=e.width,m=e.height,p=e.triggers,y=void 0===p?["onClick"]:p,x=e.children,C=l(w),b=(t=function(){return C.nextId()},(r=n({sign:!1,fn:void 0}).current).sign||(r.sign=!0,r.fn=t()),r.fn),E=n(null);s(null==x?void 0:x.ref,function(){return E.current}),i(function(){return function(){C.remove(b)}},[]);var k=g({render:function(e){return c&&c(e)},show:function(e,n){C.show(b),function(e,n){if(x){var t=x.props[e];t&&t(n)}}(e,n)}}),P=a(function(){var e={};return y.forEach(function(n){e[n]=k.show.bind(null,n)}),e},[]);return i(function(){C.update({key:b,src:o,originRef:E,render:k.render,overlay:u,width:f,height:m})},[o]),x?d.only(v(x,h({},P,{ref:E}))):null};export{Q as PhotoProvider,U as PhotoSlider,Z as PhotoView}; | ||
//# sourceMappingURL=react-photo-view.module.js.map |
{ | ||
"name": "react-photo-view", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "An exquisite React photo preview component", | ||
@@ -5,0 +5,0 @@ "author": "MinJieLiu", |
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
364780