Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-viewer

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-viewer - npm Package Compare versions

Comparing version 2.3.8 to 2.3.9

7

dist/index.js

@@ -567,3 +567,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

if (activeImage.downloadUrl) {
window.open(activeImage.downloadUrl);
location.href = activeImage.downloadUrl;
}

@@ -1048,3 +1048,3 @@ };

{ className: this.prefixCls + '-footer', style: { zIndex: zIndex + 5 } },
this.props.noToolbar || React.createElement(_ViewerToolbar2.default, { prefixCls: this.prefixCls, onAction: this.handleAction, alt: activeImg.alt, width: this.state.imageWidth, height: this.state.imageHeight, attribute: this.props.attribute, zoomable: this.props.zoomable, rotatable: this.props.rotatable, scalable: this.props.scalable, changeable: true, downloadable: this.props.downloadable, noImgDetails: this.props.noImgDetails }),
this.props.noToolbar || React.createElement(_ViewerToolbar2.default, { prefixCls: this.prefixCls, onAction: this.handleAction, alt: activeImg.alt, width: this.state.imageWidth, height: this.state.imageHeight, attribute: this.props.attribute, zoomable: this.props.zoomable, rotatable: this.props.rotatable, scalable: this.props.scalable, changeable: this.props.changeable, downloadable: this.props.downloadable, noImgDetails: this.props.noImgDetails }),
this.props.noNavbar || React.createElement(_ViewerNav2.default, { prefixCls: this.prefixCls, images: this.props.images, activeIndex: this.state.activeIndex, onChangeImg: this.handleChangeImg })

@@ -1071,3 +1071,4 @@ )

scalable: true,
onMaskClick: noop
onMaskClick: noop,
changeable: true
};

@@ -1074,0 +1075,0 @@ module.exports = exports['default'];

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["react","react-dom"],t):"object"==typeof exports?exports["react-viewer"]=t(require("react"),require("react-dom")):e["react-viewer"]=t(e.React,e.ReactDOM)}(this,function(e,t){return function(e){function t(o){if(n[o])return n[o].exports;var i=n[o]={exports:{},id:o,loaded:!1};return e[o].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var i=n(4),r=o(i);t.default=r.default,e.exports=t.default},function(t,n){t.exports=e},function(e,t,n){"use strict";function o(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function i(e,t){for(var n=Object.getOwnPropertyNames(t),o=0;o<n.length;o++){var i=n[o],r=Object.getOwnPropertyDescriptor(t,i);r&&r.configurable&&void 0===e[i]&&Object.defineProperty(e,i,r)}return e}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):i(e,t))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=t.ActionType=void 0;var l=n(1),c=o(l),p=t.ActionType=void 0;!function(e){e[e.zoomIn=1]="zoomIn",e[e.zoomOut=2]="zoomOut",e[e.prev=3]="prev",e[e.next=4]="next",e[e.rotateLeft=5]="rotateLeft",e[e.rotateRight=6]="rotateRight",e[e.reset=7]="reset",e[e.close=8]="close",e[e.scaleX=9]="scaleX",e[e.scaleY=10]="scaleY",e[e.download=11]="download"}(p||(t.ActionType=p={}));var h=function(e){function t(){return r(this,t),s(this,e.apply(this,arguments))}return a(t,e),t.prototype.render=function(){var e="react-viewer-icon";return c.createElement("i",{className:e+" "+e+"-"+p[this.props.type]})},t}(c.Component);t.default=h},function(e,t,n){"use strict";function o(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function i(e,t){for(var n=Object.getOwnPropertyNames(t),o=0;o<n.length;o++){var i=n[o],r=Object.getOwnPropertyDescriptor(t,i);r&&r.configurable&&void 0===e[i]&&Object.defineProperty(e,i,r)}return e}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):i(e,t))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var l=n(1),c=o(l),p=function(e){function t(){return r(this,t),s(this,e.call(this))}return a(t,e),t.prototype.render=function(){var e="spin spin-spinning";return c.createElement("div",{className:"spin-wrap",style:this.props.style},c.createElement("div",{className:e},c.createElement("div",{className:"spin-dot"})))},t}(c.Component);t.default=p,e.exports=t.default},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function r(e,t){for(var n=Object.getOwnPropertyNames(t),o=0;o<n.length;o++){var i=n[o],r=Object.getOwnPropertyDescriptor(t,i);r&&r.configurable&&void 0===e[i]&&Object.defineProperty(e,i,r)}return e}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):r(e,t))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var c=n(1),p=i(c),h=n(10),u=i(h),d=n(6),f=o(d),y=function(e){function t(){s(this,t);var n=a(this,e.call(this));return n.container=null,n.defaultContainer=document.createElement("div"),n.component=null,n}return l(t,e),t.prototype.renderViewer=function(){if(this.props.visible||this.component){this.container||(this.props.container?this.container=this.props.container:(this.container=this.defaultContainer,document.body.appendChild(this.container)));var e=this;u.unstable_renderSubtreeIntoContainer(this,p.createElement(f.default,this.props),this.container,function(){e.component=this})}},t.prototype.removeViewer=function(){if(this.container){var e=this.container;u.unmountComponentAtNode(e),e.parentNode.removeChild(e),this.container=null,this.component=null}},t.prototype.componentWillUnmount=function(){this.props.visible&&this.props.onClose&&this.props.onClose(),this.removeViewer()},t.prototype.componentWillReceiveProps=function(e){this.props.container!==e.container&&(this.component=null,e.container?(this.container&&document.body.removeChild(this.container),this.container=e.container):(this.container=this.defaultContainer,document.body.appendChild(this.container)))},t.prototype.componentDidMount=function(){this.renderViewer()},t.prototype.componentDidUpdate=function(){this.renderViewer()},t.prototype.render=function(){return null},t}(p.Component);t.default=y,e.exports=t.default},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function r(e,t){for(var n=Object.getOwnPropertyNames(t),o=0;o<n.length;o++){var i=n[o],r=Object.getOwnPropertyDescriptor(t,i);r&&r.configurable&&void 0===e[i]&&Object.defineProperty(e,i,r)}return e}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):r(e,t))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var c=n(1),p=i(c),h=n(3),u=o(h),d=function(e){function t(){s(this,t);var n=a(this,e.call(this));return n.handleResize=function(e){n.props.onResize()},n.handleCanvasMouseDown=function(e){n.props.onCanvasMouseDown(e),n.handleMouseDown(e)},n.state={isMouseDown:!1,mouseX:0,mouseY:0},n.handleMouseScroll=n.handleMouseScroll.bind(n),n.handleMouseDown=n.handleMouseDown.bind(n),n.bindEvent=n.bindEvent.bind(n),n.handleMouseMove=n.handleMouseMove.bind(n),n.handleMouseUp=n.handleMouseUp.bind(n),n}return l(t,e),t.prototype.componentDidMount=function(){this.props.drag&&this.bindEvent()},t.prototype.handleMouseDown=function(e){this.props.visible&&this.props.drag&&(e.preventDefault(),e.stopPropagation(),this.setState({isMouseDown:!0,mouseX:e.nativeEvent.clientX,mouseY:e.nativeEvent.clientY}))},t.prototype.handleMouseMove=function(e){if(this.state.isMouseDown){var t=e.clientX-this.state.mouseX,n=e.clientY-this.state.mouseY;this.setState({mouseX:e.clientX,mouseY:e.clientY}),this.props.onChangeImgState(this.props.width,this.props.height,this.props.top+n,this.props.left+t)}},t.prototype.handleMouseUp=function(e){this.setState({isMouseDown:!1})},t.prototype.handleMouseScroll=function(e){e.preventDefault();var t=0;if(e.wheelDelta?t=e.wheelDelta>0?1:-1:e.detail&&(t=e.detail>0?-1:1),0!==t){var n=e.clientX,o=e.clientY;if(this.props.container){var i=this.props.container.getBoundingClientRect();n-=i.left,o-=i.top}this.props.onZoom(n,o,t,.05)}},t.prototype.bindEvent=function(e){var t="addEventListener";e&&(t="removeEventListener");var n=document;this.props.container&&(n=this.props.container),n[t]("DOMMouseScroll",this.handleMouseScroll,!1),n[t]("mousewheel",this.handleMouseScroll,!1),document[t]("click",this.handleMouseUp,!1),document[t]("mousemove",this.handleMouseMove,!1),window[t]("resize",this.handleResize,!1)},t.prototype.componentWillReceiveProps=function(e){return!this.props.visible&&e.visible&&e.drag?this.bindEvent():this.props.visible&&!e.visible&&(this.handleMouseUp({}),e.drag)?this.bindEvent(!0):this.props.drag&&!e.drag?this.bindEvent(!0):!this.props.drag&&e.drag&&e.visible?this.bindEvent(!0):void 0},t.prototype.componentWillUnmount=function(){this.bindEvent(!0)},t.prototype.render=function(){var e={width:this.props.width+"px",height:this.props.height+"px",transform:"translateX("+(this.props.left?this.props.left+"px":"aoto")+") translateY("+this.props.top+"px)\n rotate("+this.props.rotate+"deg) scaleX("+this.props.scaleX+") scaleY("+this.props.scaleY+")"},t=this.props.drag?"drag":"";this.state.isMouseDown||(t+=" "+this.props.prefixCls+"-image-transition");var n={zIndex:this.props.zIndex},o=null;return""!==this.props.imgSrc&&(o=p.createElement("img",{className:t,src:this.props.imgSrc,style:e,onMouseDown:this.handleMouseDown})),this.props.loading&&(o=p.createElement("div",{style:{display:"flex",height:"100%",justifyContent:"center",alignItems:"center"}},p.createElement(u.default,null))),p.createElement("div",{className:this.props.prefixCls+"-canvas",onMouseDown:this.handleCanvasMouseDown,style:n},o)},t}(p.Component);t.default=d,e.exports=t.default},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function r(e,t){for(var n=Object.getOwnPropertyNames(t),o=0;o<n.length;o++){var i=n[o],r=Object.getOwnPropertyDescriptor(t,i);r&&r.configurable&&void 0===e[i]&&Object.defineProperty(e,i,r)}return e}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):r(e,t))}function c(){}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var p=function(){function e(e,t){var n=[],o=!0,i=!1,r=void 0;try{for(var s,a=e[Symbol.iterator]();!(o=(s=a.next()).done)&&(n.push(s.value),!t||n.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{!o&&a.return&&a.return()}finally{if(i)throw r}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),h=n(1),u=i(h);n(9);var d=n(5),f=o(d),y=n(7),m=o(y),v=n(8),b=o(v),g=n(2),w=o(g),C=300,x=function(e){function t(n){s(this,t);var o=a(this,e.call(this,n));return o.handleDownload=function(){var e=o.getActiveImage();e.downloadUrl&&window.open(e.downloadUrl)},o.handleTransitionEnd=function(e){o.state.transitionEnd&&!o.state.visibleStart||o.setState({visibleStart:!1,transitionEnd:!0})},o.handleCanvasMouseDown=function(e){o.props.onMaskClick(e)},o.getActiveImage=function(){var e={src:"",alt:"",downloadUrl:""},t=o.props.images||[];return t.length>0&&o.state.activeIndex>=0&&(e=t[o.state.activeIndex]),e},o.prefixCls="react-viewer",o.state={visible:!1,visibleStart:!1,transitionEnd:!1,activeIndex:o.props.activeIndex,width:0,height:0,top:15,left:null,rotate:0,imageWidth:0,imageHeight:0,scaleX:1,scaleY:1,loading:!1},o.handleChangeImg=o.handleChangeImg.bind(o),o.handleChangeImgState=o.handleChangeImgState.bind(o),o.handleAction=o.handleAction.bind(o),o.handleResize=o.handleResize.bind(o),o.handleZoom=o.handleZoom.bind(o),o.handleRotate=o.handleRotate.bind(o),o.handleKeydown=o.handleKeydown.bind(o),o.handleScaleX=o.handleScaleX.bind(o),o.handleScaleY=o.handleScaleY.bind(o),o.getImageCenterXY=o.getImageCenterXY.bind(o),o.setContainerWidthHeight(),o.footerHeight=84,o}return l(t,e),t.prototype.setContainerWidthHeight=function(){this.containerWidth=window.innerWidth,this.containerHeight=window.innerHeight,this.props.container&&(this.containerWidth=this.props.container.offsetWidth,this.containerHeight=this.props.container.offsetHeight)},t.prototype.handleClose=function(e){this.props.onClose()},t.prototype.startVisible=function(e){var t=this;this.props.container||(document.body.style.overflow="hidden",document.body.scrollHeight>document.body.clientHeight&&(document.body.style.paddingRight="15px")),this.setState({visibleStart:!0}),setTimeout(function(){t.setState({visible:!0}),setTimeout(function(){t.bindEvent(),t.loadImg(e,!0)},300)},10)},t.prototype.componentDidMount=function(){this.refs.viewerCore.addEventListener("transitionend",this.handleTransitionEnd,!1),this.startVisible(this.state.activeIndex)},t.prototype.getImgWidthHeight=function(e,t){var n=0,o=0,i=.8*this.containerWidth,r=.8*(this.containerHeight-this.footerHeight);return n=Math.min(i,e),o=n/e*t,o>r&&(o=r,n=o/t*e),[n,o]},t.prototype.loadImg=function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],o="",i=this.props.images||[];i.length>0&&(o=i[e].src);var r=new Image;r.src=o,n?this.setState({activeIndex:e,width:0,height:0,left:0,top:0,rotate:0,scaleX:1,scaleY:1,loading:!0}):this.setState({activeIndex:e,loading:!0}),r.onload=function(){var o=r.width,i=r.height;if(n)setTimeout(function(){t.setState({activeIndex:e,imageWidth:o,imageHeight:i});var n=t.getImageCenterXY();t.handleZoom(n.x,n.y,1,1)},50);else{var s=t.getImgWidthHeight(o,i),a=p(s,2),l=a[0],c=a[1],h=(t.containerWidth-l)/2,u=(t.containerHeight-c-t.footerHeight)/2;t.setState({activeIndex:e,width:l,height:c,left:h,top:u,imageWidth:o,imageHeight:i,loading:!1,rotate:0,scaleX:1,scaleY:1})}},r.onerror=function(){t.setState({activeIndex:e,imageWidth:0,imageHeight:0,loading:!1})}},t.prototype.handleChangeImg=function(e){this.loadImg(e)},t.prototype.handleChangeImgState=function(e,t,n,o){this.setState({width:e,height:t,top:n,left:o})},t.prototype.handleAction=function(e){switch(e){case g.ActionType.prev:this.state.activeIndex-1>=0&&this.handleChangeImg(this.state.activeIndex-1);break;case g.ActionType.next:this.state.activeIndex+1<this.props.images.length&&this.handleChangeImg(this.state.activeIndex+1);break;case g.ActionType.zoomIn:var t=this.getImageCenterXY();this.handleZoom(t.x,t.y,1,.05);break;case g.ActionType.zoomOut:var n=this.getImageCenterXY();this.handleZoom(n.x,n.y,-1,.05);break;case g.ActionType.rotateLeft:this.handleRotate();break;case g.ActionType.rotateRight:this.handleRotate(!0);break;case g.ActionType.reset:this.loadImg(this.state.activeIndex);break;case g.ActionType.scaleX:this.handleScaleX(-1);break;case g.ActionType.scaleY:this.handleScaleY(-1);break;case g.ActionType.download:this.handleDownload()}},t.prototype.handleScaleX=function(e){this.setState({scaleX:this.state.scaleX*e})},t.prototype.handleScaleY=function(e){this.setState({scaleY:this.state.scaleY*e})},t.prototype.handleZoom=function(e,t,n,o){var i=this.getImageCenterXY(),r=e-i.x,s=t-i.y,a=!1,l=0,c=0,h=0,u=0,d=0,f=0;if(0===this.state.width){var y=this.getImgWidthHeight(this.state.imageWidth,this.state.imageHeight),m=p(y,2),v=m[0],b=m[1];a=!0,c=(this.containerWidth-v)/2,l=(this.containerHeight-this.footerHeight-b)/2,h=this.state.width+v,u=this.state.height+b,d=f=1}else{var g=this.state.scaleX>0?1:-1,w=this.state.scaleY>0?1:-1;if(d=this.state.scaleX+o*n*g,f=this.state.scaleY+o*n*w,Math.abs(d)<.1||Math.abs(f)<.1)return;l=this.state.top+-n*s/this.state.scaleX*o*g,c=this.state.left+-n*r/this.state.scaleY*o*w,h=this.state.width,u=this.state.height}this.setState({width:h,scaleX:d,scaleY:f,height:u,top:l,left:c,loading:!1})},t.prototype.getImageCenterXY=function(){return{x:this.state.left+this.state.width/2,y:this.state.top+this.state.height/2}},t.prototype.handleRotate=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.setState({rotate:this.state.rotate+90*(e?1:-1)})},t.prototype.handleResize=function(){if(this.setContainerWidthHeight(),this.props.visible){var e=this.getImgWidthHeight(this.state.imageWidth,this.state.imageHeight),t=p(e,2),n=t[0],o=t[1],i=(this.containerWidth-n)/2,r=(this.containerHeight-o-this.footerHeight)/2;this.setState({width:n,height:o,left:i,top:r,rotate:0,scaleX:1,scaleY:1})}},t.prototype.handleKeydown=function(e){var t=e.keyCode||e.which||e.charCode,n=!1;switch(t){case 27:this.props.onClose(),n=!0;break;case 37:e.ctrlKey?this.handleAction(g.ActionType.rotateLeft):this.handleAction(g.ActionType.prev),n=!0;break;case 39:e.ctrlKey?this.handleAction(g.ActionType.rotateRight):this.handleAction(g.ActionType.next),n=!0;break;case 38:this.handleAction(g.ActionType.zoomIn),n=!0;break;case 40:this.handleAction(g.ActionType.zoomOut),n=!0;break;case 49:e.ctrlKey&&(this.loadImg(this.state.activeIndex),n=!0)}n&&e.preventDefault()},t.prototype.bindEvent=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t="addEventListener";e&&(t="removeEventListener"),document[t]("keydown",this.handleKeydown,!1)},t.prototype.componentWillUnmount=function(){this.bindEvent(!0),this.refs.viewerCore.removeEventListener("transitionend",this.handleTransitionEnd,!1)},t.prototype.componentWillReceiveProps=function(e){var t=this;return!this.props.visible&&e.visible?void this.startVisible(e.activeIndex):this.props.visible&&!e.visible?(this.bindEvent(!0),this.handleZoom(this.containerWidth/2,(this.containerHeight-this.footerHeight)/2,-1,(this.state.scaleX>0?1:-1)*this.state.scaleX-.11),void setTimeout(function(){document.body.style.overflow="",document.body.style.paddingRight="",t.setState({visible:!1,transitionEnd:!1,width:0,height:0})},C)):this.props.activeIndex!==e.activeIndex?void this.handleChangeImg(e.activeIndex):void 0},t.prototype.render=function(){var e={src:"",alt:""},t=1e3;this.props.zIndex&&(t=this.props.zIndex);var n={opacity:this.state.visible?1:0};!this.state.visible&&this.state.transitionEnd&&(n.display="none"),!this.state.visible&&this.state.visibleStart&&(n.display="block"),this.state.visible&&this.state.transitionEnd&&(e=this.getActiveImage());var o=this.prefixCls+" "+this.prefixCls+"-transition";return this.props.container&&(o+=" "+this.prefixCls+"-inline"),u.createElement("div",{ref:"viewerCore",className:o,style:n},u.createElement("div",{className:this.prefixCls+"-mask",style:{zIndex:t}}),this.props.noClose||u.createElement("div",{className:this.prefixCls+"-close "+this.prefixCls+"-btn",onClick:this.handleClose.bind(this),style:{zIndex:t+10}},u.createElement(w.default,{type:g.ActionType.close})),u.createElement(f.default,{prefixCls:this.prefixCls,imgSrc:e.src,visible:this.props.visible,width:this.state.width,height:this.state.height,top:this.state.top,left:this.state.left,rotate:this.state.rotate,onChangeImgState:this.handleChangeImgState,onResize:this.handleResize,onZoom:this.handleZoom,zIndex:t+5,scaleX:this.state.scaleX,scaleY:this.state.scaleY,loading:this.state.loading,drag:this.props.drag,container:this.props.container,onCanvasMouseDown:this.handleCanvasMouseDown}),this.props.noFooter||u.createElement("div",{className:this.prefixCls+"-footer",style:{zIndex:t+5}},this.props.noToolbar||u.createElement(b.default,{prefixCls:this.prefixCls,onAction:this.handleAction,alt:e.alt,width:this.state.imageWidth,height:this.state.imageHeight,attribute:this.props.attribute,zoomable:this.props.zoomable,rotatable:this.props.rotatable,scalable:this.props.scalable,changeable:!0,downloadable:this.props.downloadable,noImgDetails:this.props.noImgDetails}),this.props.noNavbar||u.createElement(m.default,{prefixCls:this.prefixCls,images:this.props.images,activeIndex:this.state.activeIndex,onChangeImg:this.handleChangeImg})))},t}(u.Component);t.default=x,x.defaultProps={visible:!1,onClose:c,images:[],activeIndex:0,zIndex:1e3,drag:!0,attribute:!0,zoomable:!0,rotatable:!0,scalable:!0,onMaskClick:c},e.exports=t.default},function(e,t,n){"use strict";function o(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function i(e,t){for(var n=Object.getOwnPropertyNames(t),o=0;o<n.length;o++){var i=n[o],r=Object.getOwnPropertyDescriptor(t,i);r&&r.configurable&&void 0===e[i]&&Object.defineProperty(e,i,r)}return e}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):i(e,t))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var l=n(1),c=o(l),p=function(e){function t(){return r(this,t),s(this,e.apply(this,arguments))}return a(t,e),t.prototype.handleChangeImg=function(e){this.props.activeIndex!==e&&this.props.onChangeImg(e)},t.prototype.render=function(){var e=this,t=1.5*(Math.ceil(this.props.images.length/2)-this.props.activeIndex-1)*30,n={marginLeft:t+"px"};return c.createElement("div",{className:this.props.prefixCls+"-navbar"},c.createElement("ul",{className:this.props.prefixCls+"-list "+this.props.prefixCls+"-list-transition",style:n},this.props.images.map(function(t,n){return c.createElement("li",{key:n,className:n===e.props.activeIndex?"active":"",onClick:e.handleChangeImg.bind(e,n)},c.createElement("img",{src:t.src,alt:t.alt}))})))},t}(c.Component);t.default=p,p.defaultProps={activeIndex:0},e.exports=t.default},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function r(e,t){for(var n=Object.getOwnPropertyNames(t),o=0;o<n.length;o++){var i=n[o],r=Object.getOwnPropertyDescriptor(t,i);r&&r.configurable&&void 0===e[i]&&Object.defineProperty(e,i,r)}return e}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):r(e,t))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var c=n(1),p=i(c),h=n(2),u=o(h),d=function(e){function t(){return s(this,t),a(this,e.call(this))}return l(t,e),t.prototype.handleAction=function(e){this.props.onAction(e)},t.prototype.render=function(){var e=this,t=this.props.attribute?p.createElement("p",{className:this.props.prefixCls+"-attribute"},this.props.alt&&""+this.props.alt,this.props.noImgDetails||"("+this.props.width+" x "+this.props.height+")"):null,n=[];return this.props.zoomable&&(n=n.concat([p.createElement("li",{key:"zoomIn",className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.zoomIn)}},p.createElement(u.default,{type:h.ActionType.zoomIn})),p.createElement("li",{key:"zoomOut",className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.zoomOut)}},p.createElement(u.default,{type:h.ActionType.zoomOut}))])),this.props.changeable&&(n=n.concat([p.createElement("li",{key:"prev",className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.prev)}},p.createElement(u.default,{type:h.ActionType.prev})),p.createElement("li",{key:"reset",className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.reset)}},p.createElement(u.default,{type:h.ActionType.reset})),p.createElement("li",{key:"next",className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.next)}},p.createElement(u.default,{type:h.ActionType.next}))])),this.props.rotatable&&(n=n.concat([p.createElement("li",{key:"rotateLeft",className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.rotateLeft)}},p.createElement(u.default,{type:h.ActionType.rotateLeft})),p.createElement("li",{key:"rotateRight",className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.rotateRight)}},p.createElement(u.default,{type:h.ActionType.rotateRight}))])),this.props.scalable&&(n=n.concat([p.createElement("li",{key:"scaleX",className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.scaleX)}},p.createElement(u.default,{type:h.ActionType.scaleX})),p.createElement("li",{key:"scaleY",className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.scaleY)}},p.createElement(u.default,{type:h.ActionType.scaleY}))])),this.props.downloadable&&(n=n.concat([p.createElement("li",{key:"download",className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.download)}},p.createElement(u.default,{type:h.ActionType.download}))])),p.createElement("div",null,t,p.createElement("ul",{className:this.props.prefixCls+"-toolbar"},n))},t}(p.Component);t.default=d,e.exports=t.default},function(e,t){},function(e,n){e.exports=t}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["react","react-dom"],t):"object"==typeof exports?exports["react-viewer"]=t(require("react"),require("react-dom")):e["react-viewer"]=t(e.React,e.ReactDOM)}(this,function(e,t){return function(e){function t(o){if(n[o])return n[o].exports;var i=n[o]={exports:{},id:o,loaded:!1};return e[o].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var i=n(4),r=o(i);t.default=r.default,e.exports=t.default},function(t,n){t.exports=e},function(e,t,n){"use strict";function o(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function i(e,t){for(var n=Object.getOwnPropertyNames(t),o=0;o<n.length;o++){var i=n[o],r=Object.getOwnPropertyDescriptor(t,i);r&&r.configurable&&void 0===e[i]&&Object.defineProperty(e,i,r)}return e}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):i(e,t))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=t.ActionType=void 0;var l=n(1),c=o(l),p=t.ActionType=void 0;!function(e){e[e.zoomIn=1]="zoomIn",e[e.zoomOut=2]="zoomOut",e[e.prev=3]="prev",e[e.next=4]="next",e[e.rotateLeft=5]="rotateLeft",e[e.rotateRight=6]="rotateRight",e[e.reset=7]="reset",e[e.close=8]="close",e[e.scaleX=9]="scaleX",e[e.scaleY=10]="scaleY",e[e.download=11]="download"}(p||(t.ActionType=p={}));var h=function(e){function t(){return r(this,t),s(this,e.apply(this,arguments))}return a(t,e),t.prototype.render=function(){var e="react-viewer-icon";return c.createElement("i",{className:e+" "+e+"-"+p[this.props.type]})},t}(c.Component);t.default=h},function(e,t,n){"use strict";function o(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function i(e,t){for(var n=Object.getOwnPropertyNames(t),o=0;o<n.length;o++){var i=n[o],r=Object.getOwnPropertyDescriptor(t,i);r&&r.configurable&&void 0===e[i]&&Object.defineProperty(e,i,r)}return e}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):i(e,t))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var l=n(1),c=o(l),p=function(e){function t(){return r(this,t),s(this,e.call(this))}return a(t,e),t.prototype.render=function(){var e="spin spin-spinning";return c.createElement("div",{className:"spin-wrap",style:this.props.style},c.createElement("div",{className:e},c.createElement("div",{className:"spin-dot"})))},t}(c.Component);t.default=p,e.exports=t.default},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function r(e,t){for(var n=Object.getOwnPropertyNames(t),o=0;o<n.length;o++){var i=n[o],r=Object.getOwnPropertyDescriptor(t,i);r&&r.configurable&&void 0===e[i]&&Object.defineProperty(e,i,r)}return e}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):r(e,t))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var c=n(1),p=i(c),h=n(10),u=i(h),d=n(6),f=o(d),y=function(e){function t(){s(this,t);var n=a(this,e.call(this));return n.container=null,n.defaultContainer=document.createElement("div"),n.component=null,n}return l(t,e),t.prototype.renderViewer=function(){if(this.props.visible||this.component){this.container||(this.props.container?this.container=this.props.container:(this.container=this.defaultContainer,document.body.appendChild(this.container)));var e=this;u.unstable_renderSubtreeIntoContainer(this,p.createElement(f.default,this.props),this.container,function(){e.component=this})}},t.prototype.removeViewer=function(){if(this.container){var e=this.container;u.unmountComponentAtNode(e),e.parentNode.removeChild(e),this.container=null,this.component=null}},t.prototype.componentWillUnmount=function(){this.props.visible&&this.props.onClose&&this.props.onClose(),this.removeViewer()},t.prototype.componentWillReceiveProps=function(e){this.props.container!==e.container&&(this.component=null,e.container?(this.container&&document.body.removeChild(this.container),this.container=e.container):(this.container=this.defaultContainer,document.body.appendChild(this.container)))},t.prototype.componentDidMount=function(){this.renderViewer()},t.prototype.componentDidUpdate=function(){this.renderViewer()},t.prototype.render=function(){return null},t}(p.Component);t.default=y,e.exports=t.default},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function r(e,t){for(var n=Object.getOwnPropertyNames(t),o=0;o<n.length;o++){var i=n[o],r=Object.getOwnPropertyDescriptor(t,i);r&&r.configurable&&void 0===e[i]&&Object.defineProperty(e,i,r)}return e}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):r(e,t))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var c=n(1),p=i(c),h=n(3),u=o(h),d=function(e){function t(){s(this,t);var n=a(this,e.call(this));return n.handleResize=function(e){n.props.onResize()},n.handleCanvasMouseDown=function(e){n.props.onCanvasMouseDown(e),n.handleMouseDown(e)},n.state={isMouseDown:!1,mouseX:0,mouseY:0},n.handleMouseScroll=n.handleMouseScroll.bind(n),n.handleMouseDown=n.handleMouseDown.bind(n),n.bindEvent=n.bindEvent.bind(n),n.handleMouseMove=n.handleMouseMove.bind(n),n.handleMouseUp=n.handleMouseUp.bind(n),n}return l(t,e),t.prototype.componentDidMount=function(){this.props.drag&&this.bindEvent()},t.prototype.handleMouseDown=function(e){this.props.visible&&this.props.drag&&(e.preventDefault(),e.stopPropagation(),this.setState({isMouseDown:!0,mouseX:e.nativeEvent.clientX,mouseY:e.nativeEvent.clientY}))},t.prototype.handleMouseMove=function(e){if(this.state.isMouseDown){var t=e.clientX-this.state.mouseX,n=e.clientY-this.state.mouseY;this.setState({mouseX:e.clientX,mouseY:e.clientY}),this.props.onChangeImgState(this.props.width,this.props.height,this.props.top+n,this.props.left+t)}},t.prototype.handleMouseUp=function(e){this.setState({isMouseDown:!1})},t.prototype.handleMouseScroll=function(e){e.preventDefault();var t=0;if(e.wheelDelta?t=e.wheelDelta>0?1:-1:e.detail&&(t=e.detail>0?-1:1),0!==t){var n=e.clientX,o=e.clientY;if(this.props.container){var i=this.props.container.getBoundingClientRect();n-=i.left,o-=i.top}this.props.onZoom(n,o,t,.05)}},t.prototype.bindEvent=function(e){var t="addEventListener";e&&(t="removeEventListener");var n=document;this.props.container&&(n=this.props.container),n[t]("DOMMouseScroll",this.handleMouseScroll,!1),n[t]("mousewheel",this.handleMouseScroll,!1),document[t]("click",this.handleMouseUp,!1),document[t]("mousemove",this.handleMouseMove,!1),window[t]("resize",this.handleResize,!1)},t.prototype.componentWillReceiveProps=function(e){return!this.props.visible&&e.visible&&e.drag?this.bindEvent():this.props.visible&&!e.visible&&(this.handleMouseUp({}),e.drag)?this.bindEvent(!0):this.props.drag&&!e.drag?this.bindEvent(!0):!this.props.drag&&e.drag&&e.visible?this.bindEvent(!0):void 0},t.prototype.componentWillUnmount=function(){this.bindEvent(!0)},t.prototype.render=function(){var e={width:this.props.width+"px",height:this.props.height+"px",transform:"translateX("+(this.props.left?this.props.left+"px":"aoto")+") translateY("+this.props.top+"px)\n rotate("+this.props.rotate+"deg) scaleX("+this.props.scaleX+") scaleY("+this.props.scaleY+")"},t=this.props.drag?"drag":"";this.state.isMouseDown||(t+=" "+this.props.prefixCls+"-image-transition");var n={zIndex:this.props.zIndex},o=null;return""!==this.props.imgSrc&&(o=p.createElement("img",{className:t,src:this.props.imgSrc,style:e,onMouseDown:this.handleMouseDown})),this.props.loading&&(o=p.createElement("div",{style:{display:"flex",height:"100%",justifyContent:"center",alignItems:"center"}},p.createElement(u.default,null))),p.createElement("div",{className:this.props.prefixCls+"-canvas",onMouseDown:this.handleCanvasMouseDown,style:n},o)},t}(p.Component);t.default=d,e.exports=t.default},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function r(e,t){for(var n=Object.getOwnPropertyNames(t),o=0;o<n.length;o++){var i=n[o],r=Object.getOwnPropertyDescriptor(t,i);r&&r.configurable&&void 0===e[i]&&Object.defineProperty(e,i,r)}return e}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):r(e,t))}function c(){}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var p=function(){function e(e,t){var n=[],o=!0,i=!1,r=void 0;try{for(var s,a=e[Symbol.iterator]();!(o=(s=a.next()).done)&&(n.push(s.value),!t||n.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{!o&&a.return&&a.return()}finally{if(i)throw r}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),h=n(1),u=i(h);n(9);var d=n(5),f=o(d),y=n(7),m=o(y),v=n(8),b=o(v),g=n(2),w=o(g),C=300,x=function(e){function t(n){s(this,t);var o=a(this,e.call(this,n));return o.handleDownload=function(){var e=o.getActiveImage();e.downloadUrl&&(location.href=e.downloadUrl)},o.handleTransitionEnd=function(e){o.state.transitionEnd&&!o.state.visibleStart||o.setState({visibleStart:!1,transitionEnd:!0})},o.handleCanvasMouseDown=function(e){o.props.onMaskClick(e)},o.getActiveImage=function(){var e={src:"",alt:"",downloadUrl:""},t=o.props.images||[];return t.length>0&&o.state.activeIndex>=0&&(e=t[o.state.activeIndex]),e},o.prefixCls="react-viewer",o.state={visible:!1,visibleStart:!1,transitionEnd:!1,activeIndex:o.props.activeIndex,width:0,height:0,top:15,left:null,rotate:0,imageWidth:0,imageHeight:0,scaleX:1,scaleY:1,loading:!1},o.handleChangeImg=o.handleChangeImg.bind(o),o.handleChangeImgState=o.handleChangeImgState.bind(o),o.handleAction=o.handleAction.bind(o),o.handleResize=o.handleResize.bind(o),o.handleZoom=o.handleZoom.bind(o),o.handleRotate=o.handleRotate.bind(o),o.handleKeydown=o.handleKeydown.bind(o),o.handleScaleX=o.handleScaleX.bind(o),o.handleScaleY=o.handleScaleY.bind(o),o.getImageCenterXY=o.getImageCenterXY.bind(o),o.setContainerWidthHeight(),o.footerHeight=84,o}return l(t,e),t.prototype.setContainerWidthHeight=function(){this.containerWidth=window.innerWidth,this.containerHeight=window.innerHeight,this.props.container&&(this.containerWidth=this.props.container.offsetWidth,this.containerHeight=this.props.container.offsetHeight)},t.prototype.handleClose=function(e){this.props.onClose()},t.prototype.startVisible=function(e){var t=this;this.props.container||(document.body.style.overflow="hidden",document.body.scrollHeight>document.body.clientHeight&&(document.body.style.paddingRight="15px")),this.setState({visibleStart:!0}),setTimeout(function(){t.setState({visible:!0}),setTimeout(function(){t.bindEvent(),t.loadImg(e,!0)},300)},10)},t.prototype.componentDidMount=function(){this.refs.viewerCore.addEventListener("transitionend",this.handleTransitionEnd,!1),this.startVisible(this.state.activeIndex)},t.prototype.getImgWidthHeight=function(e,t){var n=0,o=0,i=.8*this.containerWidth,r=.8*(this.containerHeight-this.footerHeight);return n=Math.min(i,e),o=n/e*t,o>r&&(o=r,n=o/t*e),[n,o]},t.prototype.loadImg=function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],o="",i=this.props.images||[];i.length>0&&(o=i[e].src);var r=new Image;r.src=o,n?this.setState({activeIndex:e,width:0,height:0,left:0,top:0,rotate:0,scaleX:1,scaleY:1,loading:!0}):this.setState({activeIndex:e,loading:!0}),r.onload=function(){var o=r.width,i=r.height;if(n)setTimeout(function(){t.setState({activeIndex:e,imageWidth:o,imageHeight:i});var n=t.getImageCenterXY();t.handleZoom(n.x,n.y,1,1)},50);else{var s=t.getImgWidthHeight(o,i),a=p(s,2),l=a[0],c=a[1],h=(t.containerWidth-l)/2,u=(t.containerHeight-c-t.footerHeight)/2;t.setState({activeIndex:e,width:l,height:c,left:h,top:u,imageWidth:o,imageHeight:i,loading:!1,rotate:0,scaleX:1,scaleY:1})}},r.onerror=function(){t.setState({activeIndex:e,imageWidth:0,imageHeight:0,loading:!1})}},t.prototype.handleChangeImg=function(e){this.loadImg(e)},t.prototype.handleChangeImgState=function(e,t,n,o){this.setState({width:e,height:t,top:n,left:o})},t.prototype.handleAction=function(e){switch(e){case g.ActionType.prev:this.state.activeIndex-1>=0&&this.handleChangeImg(this.state.activeIndex-1);break;case g.ActionType.next:this.state.activeIndex+1<this.props.images.length&&this.handleChangeImg(this.state.activeIndex+1);break;case g.ActionType.zoomIn:var t=this.getImageCenterXY();this.handleZoom(t.x,t.y,1,.05);break;case g.ActionType.zoomOut:var n=this.getImageCenterXY();this.handleZoom(n.x,n.y,-1,.05);break;case g.ActionType.rotateLeft:this.handleRotate();break;case g.ActionType.rotateRight:this.handleRotate(!0);break;case g.ActionType.reset:this.loadImg(this.state.activeIndex);break;case g.ActionType.scaleX:this.handleScaleX(-1);break;case g.ActionType.scaleY:this.handleScaleY(-1);break;case g.ActionType.download:this.handleDownload()}},t.prototype.handleScaleX=function(e){this.setState({scaleX:this.state.scaleX*e})},t.prototype.handleScaleY=function(e){this.setState({scaleY:this.state.scaleY*e})},t.prototype.handleZoom=function(e,t,n,o){var i=this.getImageCenterXY(),r=e-i.x,s=t-i.y,a=!1,l=0,c=0,h=0,u=0,d=0,f=0;if(0===this.state.width){var y=this.getImgWidthHeight(this.state.imageWidth,this.state.imageHeight),m=p(y,2),v=m[0],b=m[1];a=!0,c=(this.containerWidth-v)/2,l=(this.containerHeight-this.footerHeight-b)/2,h=this.state.width+v,u=this.state.height+b,d=f=1}else{var g=this.state.scaleX>0?1:-1,w=this.state.scaleY>0?1:-1;if(d=this.state.scaleX+o*n*g,f=this.state.scaleY+o*n*w,Math.abs(d)<.1||Math.abs(f)<.1)return;l=this.state.top+-n*s/this.state.scaleX*o*g,c=this.state.left+-n*r/this.state.scaleY*o*w,h=this.state.width,u=this.state.height}this.setState({width:h,scaleX:d,scaleY:f,height:u,top:l,left:c,loading:!1})},t.prototype.getImageCenterXY=function(){return{x:this.state.left+this.state.width/2,y:this.state.top+this.state.height/2}},t.prototype.handleRotate=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.setState({rotate:this.state.rotate+90*(e?1:-1)})},t.prototype.handleResize=function(){if(this.setContainerWidthHeight(),this.props.visible){var e=this.getImgWidthHeight(this.state.imageWidth,this.state.imageHeight),t=p(e,2),n=t[0],o=t[1],i=(this.containerWidth-n)/2,r=(this.containerHeight-o-this.footerHeight)/2;this.setState({width:n,height:o,left:i,top:r,rotate:0,scaleX:1,scaleY:1})}},t.prototype.handleKeydown=function(e){var t=e.keyCode||e.which||e.charCode,n=!1;switch(t){case 27:this.props.onClose(),n=!0;break;case 37:e.ctrlKey?this.handleAction(g.ActionType.rotateLeft):this.handleAction(g.ActionType.prev),n=!0;break;case 39:e.ctrlKey?this.handleAction(g.ActionType.rotateRight):this.handleAction(g.ActionType.next),n=!0;break;case 38:this.handleAction(g.ActionType.zoomIn),n=!0;break;case 40:this.handleAction(g.ActionType.zoomOut),n=!0;break;case 49:e.ctrlKey&&(this.loadImg(this.state.activeIndex),n=!0)}n&&e.preventDefault()},t.prototype.bindEvent=function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t="addEventListener";e&&(t="removeEventListener"),document[t]("keydown",this.handleKeydown,!1)},t.prototype.componentWillUnmount=function(){this.bindEvent(!0),this.refs.viewerCore.removeEventListener("transitionend",this.handleTransitionEnd,!1)},t.prototype.componentWillReceiveProps=function(e){var t=this;return!this.props.visible&&e.visible?void this.startVisible(e.activeIndex):this.props.visible&&!e.visible?(this.bindEvent(!0),this.handleZoom(this.containerWidth/2,(this.containerHeight-this.footerHeight)/2,-1,(this.state.scaleX>0?1:-1)*this.state.scaleX-.11),void setTimeout(function(){document.body.style.overflow="",document.body.style.paddingRight="",t.setState({visible:!1,transitionEnd:!1,width:0,height:0})},C)):this.props.activeIndex!==e.activeIndex?void this.handleChangeImg(e.activeIndex):void 0},t.prototype.render=function(){var e={src:"",alt:""},t=1e3;this.props.zIndex&&(t=this.props.zIndex);var n={opacity:this.state.visible?1:0};!this.state.visible&&this.state.transitionEnd&&(n.display="none"),!this.state.visible&&this.state.visibleStart&&(n.display="block"),this.state.visible&&this.state.transitionEnd&&(e=this.getActiveImage());var o=this.prefixCls+" "+this.prefixCls+"-transition";return this.props.container&&(o+=" "+this.prefixCls+"-inline"),u.createElement("div",{ref:"viewerCore",className:o,style:n},u.createElement("div",{className:this.prefixCls+"-mask",style:{zIndex:t}}),this.props.noClose||u.createElement("div",{className:this.prefixCls+"-close "+this.prefixCls+"-btn",onClick:this.handleClose.bind(this),style:{zIndex:t+10}},u.createElement(w.default,{type:g.ActionType.close})),u.createElement(f.default,{prefixCls:this.prefixCls,imgSrc:e.src,visible:this.props.visible,width:this.state.width,height:this.state.height,top:this.state.top,left:this.state.left,rotate:this.state.rotate,onChangeImgState:this.handleChangeImgState,onResize:this.handleResize,onZoom:this.handleZoom,zIndex:t+5,scaleX:this.state.scaleX,scaleY:this.state.scaleY,loading:this.state.loading,drag:this.props.drag,container:this.props.container,onCanvasMouseDown:this.handleCanvasMouseDown}),this.props.noFooter||u.createElement("div",{className:this.prefixCls+"-footer",style:{zIndex:t+5}},this.props.noToolbar||u.createElement(b.default,{prefixCls:this.prefixCls,onAction:this.handleAction,alt:e.alt,width:this.state.imageWidth,height:this.state.imageHeight,attribute:this.props.attribute,zoomable:this.props.zoomable,rotatable:this.props.rotatable,scalable:this.props.scalable,changeable:this.props.changeable,downloadable:this.props.downloadable,noImgDetails:this.props.noImgDetails}),this.props.noNavbar||u.createElement(m.default,{prefixCls:this.prefixCls,images:this.props.images,activeIndex:this.state.activeIndex,onChangeImg:this.handleChangeImg})))},t}(u.Component);t.default=x,x.defaultProps={visible:!1,onClose:c,images:[],activeIndex:0,zIndex:1e3,drag:!0,attribute:!0,zoomable:!0,rotatable:!0,scalable:!0,onMaskClick:c,changeable:!0},e.exports=t.default},function(e,t,n){"use strict";function o(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function i(e,t){for(var n=Object.getOwnPropertyNames(t),o=0;o<n.length;o++){var i=n[o],r=Object.getOwnPropertyDescriptor(t,i);r&&r.configurable&&void 0===e[i]&&Object.defineProperty(e,i,r)}return e}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):i(e,t))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var l=n(1),c=o(l),p=function(e){function t(){return r(this,t),s(this,e.apply(this,arguments))}return a(t,e),t.prototype.handleChangeImg=function(e){this.props.activeIndex!==e&&this.props.onChangeImg(e)},t.prototype.render=function(){var e=this,t=1.5*(Math.ceil(this.props.images.length/2)-this.props.activeIndex-1)*30,n={marginLeft:t+"px"};return c.createElement("div",{className:this.props.prefixCls+"-navbar"},c.createElement("ul",{className:this.props.prefixCls+"-list "+this.props.prefixCls+"-list-transition",style:n},this.props.images.map(function(t,n){return c.createElement("li",{key:n,className:n===e.props.activeIndex?"active":"",onClick:e.handleChangeImg.bind(e,n)},c.createElement("img",{src:t.src,alt:t.alt}))})))},t}(c.Component);t.default=p,p.defaultProps={activeIndex:0},e.exports=t.default},function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function r(e,t){for(var n=Object.getOwnPropertyNames(t),o=0;o<n.length;o++){var i=n[o],r=Object.getOwnPropertyDescriptor(t,i);r&&r.configurable&&void 0===e[i]&&Object.defineProperty(e,i,r)}return e}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):r(e,t))}Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var c=n(1),p=i(c),h=n(2),u=o(h),d=function(e){function t(){return s(this,t),a(this,e.call(this))}return l(t,e),t.prototype.handleAction=function(e){this.props.onAction(e)},t.prototype.render=function(){var e=this,t=this.props.attribute?p.createElement("p",{className:this.props.prefixCls+"-attribute"},this.props.alt&&""+this.props.alt,this.props.noImgDetails||"("+this.props.width+" x "+this.props.height+")"):null,n=[];return this.props.zoomable&&(n=n.concat([p.createElement("li",{key:"zoomIn",className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.zoomIn)}},p.createElement(u.default,{type:h.ActionType.zoomIn})),p.createElement("li",{key:"zoomOut",className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.zoomOut)}},p.createElement(u.default,{type:h.ActionType.zoomOut}))])),this.props.changeable&&(n=n.concat([p.createElement("li",{key:"prev",className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.prev)}},p.createElement(u.default,{type:h.ActionType.prev})),p.createElement("li",{key:"reset",className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.reset)}},p.createElement(u.default,{type:h.ActionType.reset})),p.createElement("li",{key:"next",className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.next)}},p.createElement(u.default,{type:h.ActionType.next}))])),this.props.rotatable&&(n=n.concat([p.createElement("li",{key:"rotateLeft",className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.rotateLeft)}},p.createElement(u.default,{type:h.ActionType.rotateLeft})),p.createElement("li",{key:"rotateRight",className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.rotateRight)}},p.createElement(u.default,{type:h.ActionType.rotateRight}))])),this.props.scalable&&(n=n.concat([p.createElement("li",{key:"scaleX",className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.scaleX)}},p.createElement(u.default,{type:h.ActionType.scaleX})),p.createElement("li",{key:"scaleY",className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.scaleY)}},p.createElement(u.default,{type:h.ActionType.scaleY}))])),this.props.downloadable&&(n=n.concat([p.createElement("li",{key:"download",className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.download)}},p.createElement(u.default,{type:h.ActionType.download}))])),p.createElement("div",null,t,p.createElement("ul",{className:this.props.prefixCls+"-toolbar"},n))},t}(p.Component);t.default=d,e.exports=t.default},function(e,t){},function(e,n){e.exports=t}])});

@@ -35,2 +35,3 @@ /// <reference types="react" />

onMaskClick: () => void;
changeable: boolean;
};

@@ -37,0 +38,0 @@ private prefixCls;

@@ -64,3 +64,3 @@ 'use strict';

if (activeImage.downloadUrl) {
window.open(activeImage.downloadUrl);
location.href = activeImage.downloadUrl;
}

@@ -545,3 +545,3 @@ };

{ className: this.prefixCls + '-footer', style: { zIndex: zIndex + 5 } },
this.props.noToolbar || React.createElement(_ViewerToolbar2.default, { prefixCls: this.prefixCls, onAction: this.handleAction, alt: activeImg.alt, width: this.state.imageWidth, height: this.state.imageHeight, attribute: this.props.attribute, zoomable: this.props.zoomable, rotatable: this.props.rotatable, scalable: this.props.scalable, changeable: true, downloadable: this.props.downloadable, noImgDetails: this.props.noImgDetails }),
this.props.noToolbar || React.createElement(_ViewerToolbar2.default, { prefixCls: this.prefixCls, onAction: this.handleAction, alt: activeImg.alt, width: this.state.imageWidth, height: this.state.imageHeight, attribute: this.props.attribute, zoomable: this.props.zoomable, rotatable: this.props.rotatable, scalable: this.props.scalable, changeable: this.props.changeable, downloadable: this.props.downloadable, noImgDetails: this.props.noImgDetails }),
this.props.noNavbar || React.createElement(_ViewerNav2.default, { prefixCls: this.prefixCls, images: this.props.images, activeIndex: this.state.activeIndex, onChangeImg: this.handleChangeImg })

@@ -568,4 +568,5 @@ )

scalable: true,
onMaskClick: noop
onMaskClick: noop,
changeable: true
};
module.exports = exports['default'];

@@ -39,3 +39,4 @@ /// <reference types="react" />

noFooter?: boolean;
changeable?: boolean;
}
export default ViewerProps;
{
"name": "react-viewer",
"version": "2.3.8",
"version": "2.3.9",
"description": "react image viewer",

@@ -5,0 +5,0 @@ "main": "dist/index",

@@ -63,3 +63,3 @@ # react-viewer

| onMaskClick | (e) => void | - | callback function when mask is clicked | false |
| download | boolean | false | whether to show 'download' | false |
| downloadable | boolean | false | whether to show 'download' | false |
| noClose | boolean | false | to not render close button | false |

@@ -70,2 +70,3 @@ | noNavbar | boolean | false | to not render the navbar | false |

| noFooter | boolean | false | to not render the entire footer | false |
| changeable | boolean | true | wheather to show change button | false |

@@ -72,0 +73,0 @@ ### ImageDecorator

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc