react-viewer
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -10,3 +10,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
root["react-viewer"] = factory(root["React"], root["ReactDOM"]); | ||
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_9__) { | ||
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__, __WEBPACK_EXTERNAL_MODULE_10__) { | ||
return /******/ (function(modules) { // webpackBootstrap | ||
@@ -64,3 +64,3 @@ /******/ // The module cache | ||
var _Viewer = __webpack_require__(3); | ||
var _Viewer = __webpack_require__(4); | ||
@@ -153,7 +153,60 @@ var _Viewer2 = _interopRequireDefault(_Viewer); | ||
var _reactDom = __webpack_require__(9); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } | ||
var Loading = function (_React$Component) { | ||
_inherits(Loading, _React$Component); | ||
function Loading() { | ||
_classCallCheck(this, Loading); | ||
return _possibleConstructorReturn(this, _React$Component.call(this)); | ||
} | ||
Loading.prototype.render = function render() { | ||
var cls = 'spin spin-spinning'; | ||
return React.createElement( | ||
'div', | ||
{ className: 'spin-wrap', style: this.props.style }, | ||
React.createElement( | ||
'div', | ||
{ className: cls }, | ||
React.createElement('div', { className: 'spin-dot' }) | ||
) | ||
); | ||
}; | ||
return Loading; | ||
}(React.Component); | ||
exports.default = Loading; | ||
module.exports = exports['default']; | ||
/***/ }, | ||
/* 4 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = undefined; | ||
var _react = __webpack_require__(1); | ||
var React = _interopRequireWildcard(_react); | ||
var _reactDom = __webpack_require__(10); | ||
var ReactDOM = _interopRequireWildcard(_reactDom); | ||
var _ViewerCore = __webpack_require__(5); | ||
var _ViewerCore = __webpack_require__(6); | ||
@@ -246,3 +299,3 @@ var _ViewerCore2 = _interopRequireDefault(_ViewerCore); | ||
/***/ }, | ||
/* 4 */ | ||
/* 5 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -261,2 +314,8 @@ | ||
var _Loading = __webpack_require__(3); | ||
var _Loading2 = _interopRequireDefault(_Loading); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
@@ -303,2 +362,5 @@ | ||
ViewerCavans.prototype.handleMouseDown = function handleMouseDown(e) { | ||
if (!this.props.visible) { | ||
return; | ||
} | ||
e.preventDefault(); | ||
@@ -383,2 +445,8 @@ e.stopPropagation(); | ||
} | ||
if (this.props.loading) { | ||
imgNode = React.createElement(_Loading2.default, { style: { | ||
marginTop: this.props.top, | ||
marginLeft: this.props.left | ||
} }); | ||
} | ||
return React.createElement( | ||
@@ -398,3 +466,3 @@ 'div', | ||
/***/ }, | ||
/* 5 */ | ||
/* 6 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -415,13 +483,13 @@ | ||
__webpack_require__(8); | ||
__webpack_require__(9); | ||
var _ViewerCavans = __webpack_require__(4); | ||
var _ViewerCavans = __webpack_require__(5); | ||
var _ViewerCavans2 = _interopRequireDefault(_ViewerCavans); | ||
var _ViewerNav = __webpack_require__(6); | ||
var _ViewerNav = __webpack_require__(7); | ||
var _ViewerNav2 = _interopRequireDefault(_ViewerNav); | ||
var _ViewerToolbar = __webpack_require__(7); | ||
var _ViewerToolbar = __webpack_require__(8); | ||
@@ -471,3 +539,4 @@ var _ViewerToolbar2 = _interopRequireDefault(_ViewerToolbar); | ||
scaleX: 1, | ||
scaleY: 1 | ||
scaleY: 1, | ||
loading: false | ||
}; | ||
@@ -549,2 +618,15 @@ _this.handleChangeImg = _this.handleChangeImg.bind(_this); | ||
img.src = imgSrc; | ||
if (firstLoad) { | ||
this.setState({ | ||
activeIndex: activeIndex, | ||
width: 0, | ||
height: 0, | ||
left: this.containerWidth / 2, | ||
top: (this.containerHeight - this.footerHeight) / 2, | ||
rotate: 0, | ||
scaleX: 1, | ||
scaleY: 1, | ||
loading: true | ||
}); | ||
} | ||
img.onload = function () { | ||
@@ -554,15 +636,8 @@ var imgWidth = img.width; | ||
if (firstLoad) { | ||
_this3.setState({ | ||
activeIndex: activeIndex, | ||
width: 0, | ||
height: 0, | ||
left: _this3.containerWidth / 2, | ||
top: (_this3.containerHeight - _this3.footerHeight) / 2, | ||
rotate: 0, | ||
imageWidth: imgWidth, | ||
imageHeight: imgHeight, | ||
scaleX: 1, | ||
scaleY: 1 | ||
}); | ||
setTimeout(function () { | ||
_this3.setState({ | ||
activeIndex: activeIndex, | ||
imageWidth: imgWidth, | ||
imageHeight: imgHeight | ||
}); | ||
var imgCenterXY = _this3.getImageCenterXY(); | ||
@@ -587,5 +662,6 @@ _this3.handleZoom(imgCenterXY.x, imgCenterXY.y, 1, 1); | ||
top: top, | ||
rotate: 0, | ||
imageWidth: imgWidth, | ||
imageHeight: imgHeight, | ||
loading: false, | ||
rotate: 0, | ||
scaleX: 1, | ||
@@ -599,11 +675,5 @@ scaleY: 1 | ||
activeIndex: activeIndex, | ||
width: 0, | ||
height: 0, | ||
left: 0, | ||
top: 0, | ||
rotate: 0, | ||
imageWidth: 0, | ||
imageHeight: 0, | ||
scaleX: 1, | ||
scaleY: 1 | ||
loading: false | ||
}); | ||
@@ -614,9 +684,8 @@ }; | ||
ViewerCore.prototype.handleChangeImg = function handleChangeImg(newIndex) { | ||
var _this4 = this; | ||
var imgCenterXY2 = this.getImageCenterXY(); | ||
this.handleZoom(imgCenterXY2.x, imgCenterXY2.y, -1, 1); | ||
setTimeout(function () { | ||
_this4.loadImg(newIndex); | ||
}, transitionDuration); | ||
// let imgCenterXY2 = this.getImageCenterXY(); | ||
// this.handleZoom(imgCenterXY2.x, imgCenterXY2.y, -1, 1); | ||
// setTimeout(() => { | ||
// this.loadImg(newIndex); | ||
// }, transitionDuration); | ||
this.loadImg(newIndex); | ||
}; | ||
@@ -707,3 +776,4 @@ | ||
top: this.state.top + -diffHeight / 2 + -direct * diffY * scale, | ||
left: this.state.left + -diffWidth / 2 + -direct * diffX * scale | ||
left: this.state.left + -diffWidth / 2 + -direct * diffX * scale, | ||
loading: false | ||
}); | ||
@@ -804,3 +874,3 @@ }; | ||
ViewerCore.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { | ||
var _this5 = this; | ||
var _this4 = this; | ||
@@ -816,3 +886,3 @@ if (!this.props.visible && nextProps.visible) { | ||
setTimeout(function () { | ||
_this5.setState({ | ||
_this4.setState({ | ||
visible: false, | ||
@@ -867,3 +937,3 @@ transitionEnd: false | ||
), | ||
React.createElement(_ViewerCavans2.default, { prefixCls: this.prefixCls, imgSrc: activeImg.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: zIndex + 5, scaleX: this.state.scaleX, scaleY: this.state.scaleY }), | ||
React.createElement(_ViewerCavans2.default, { prefixCls: this.prefixCls, imgSrc: activeImg.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: zIndex + 5, scaleX: this.state.scaleX, scaleY: this.state.scaleY, loading: this.state.loading }), | ||
React.createElement( | ||
@@ -893,3 +963,3 @@ 'div', | ||
/***/ }, | ||
/* 6 */ | ||
/* 7 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -928,2 +998,5 @@ | ||
ViewerNav.prototype.handleChangeImg = function handleChangeImg(newIndex) { | ||
if (this.props.activeIndex === newIndex) { | ||
return; | ||
} | ||
this.props.onChangeImg(newIndex); | ||
@@ -967,3 +1040,3 @@ }; | ||
/***/ }, | ||
/* 7 */ | ||
/* 8 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1099,3 +1172,3 @@ | ||
/***/ }, | ||
/* 8 */ | ||
/* 9 */ | ||
/***/ function(module, exports) { | ||
@@ -1106,6 +1179,6 @@ | ||
/***/ }, | ||
/* 9 */ | ||
/* 10 */ | ||
/***/ function(module, exports) { | ||
module.exports = __WEBPACK_EXTERNAL_MODULE_9__; | ||
module.exports = __WEBPACK_EXTERNAL_MODULE_10__; | ||
@@ -1112,0 +1185,0 @@ /***/ } |
@@ -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(i){if(n[i])return n[i].exports;var o=n[i]={exports:{},id:i,loaded:!1};return e[i].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=n(3),r=i(o);t["default"]=r["default"],e.exports=t["default"]},function(t,n){t.exports=e},function(e,t,n){"use strict";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 o(e,t){for(var n=Object.getOwnPropertyNames(t),i=0;i<n.length;i++){var o=n[i],r=Object.getOwnPropertyDescriptor(t,o);r&&r.configurable&&void 0===e[o]&&Object.defineProperty(e,o,r)}return e}function r(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 s(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):o(e,t))}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=t.ActionType=void 0;var c=n(1),l=i(c),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"}(p||(t.ActionType=p={}));var h=function(e){function t(){return r(this,t),a(this,e.apply(this,arguments))}return s(t,e),t.prototype.render=function(){var e="react-viewer-icon";return l.createElement("i",{className:e+" "+e+"-"+p[this.props.type]})},t}(l.Component);t["default"]=h},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}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 r(e,t){for(var n=Object.getOwnPropertyNames(t),i=0;i<n.length;i++){var o=n[i],r=Object.getOwnPropertyDescriptor(t,o);r&&r.configurable&&void 0===e[o]&&Object.defineProperty(e,o,r)}return e}function a(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 c(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 l=n(1),p=o(l),h=n(9),u=o(h),f=n(5),d=i(f),y=function(e){function t(){a(this,t);var n=s(this,e.call(this));return n.container=null,n.component=null,n}return c(t,e),t.prototype.renderViewer=function(){var e=this;(this.props.visible||this.component)&&!function(){e.container||(e.props.container?e.container=e.props.container:(e.container=document.createElement("div"),document.body.appendChild(e.container)));var t=e;u.unstable_renderSubtreeIntoContainer(e,p.createElement(d["default"],e.props),e.container,function(){t.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.removeViewer()):this.removeViewer()},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 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 o(e,t){for(var n=Object.getOwnPropertyNames(t),i=0;i<n.length;i++){var o=n[i],r=Object.getOwnPropertyDescriptor(t,o);r&&r.configurable&&void 0===e[o]&&Object.defineProperty(e,o,r)}return e}function r(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 s(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):o(e,t))}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=void 0;var c=n(1),l=i(c),p=function(e){function t(){r(this,t);var n=a(this,e.call(this));return 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.handleResize=n.handleResize.bind(n),n}return s(t,e),t.prototype.componentDidMount=function(){this.bindEvent()},t.prototype.handleResize=function(e){this.props.onResize()},t.prototype.handleMouseDown=function(e){e.preventDefault(),e.stopPropagation(),this.setState({isMouseDown:!0,mouseX:e.nativeEvent.pageX,mouseY:e.nativeEvent.pageY})},t.prototype.handleMouseMove=function(e){if(this.state.isMouseDown){var t=e.x-this.state.mouseX,n=e.y-this.state.mouseY;this.setState({mouseX:e.x,mouseY:e.y}),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){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.pageX,i=e.pageY;this.props.onZoom(n,i,t,.05)}},t.prototype.bindEvent=function(e){var t="addEventListener";e&&(t="removeEventListener"),document[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){!this.props.visible&&e.visible&&this.bindEvent(),this.props.visible&&!e.visible&&this.bindEvent(!0)},t.prototype.render=function(){var e={width:this.props.width+"px",marginTop:this.props.top+"px",marginLeft:this.props.left?this.props.left+"px":"auto",transform:"rotate("+this.props.rotate+"deg) scaleX("+this.props.scaleX+") scaleY("+this.props.scaleY+")"},t="";this.state.isMouseDown||(t=this.props.prefixCls+"-image-transition");var n={zIndex:this.props.zIndex},i=null;return""!==this.props.imgSrc&&(i=l.createElement("img",{className:t,src:this.props.imgSrc,style:e,onMouseDown:this.handleMouseDown})),l.createElement("div",{className:this.props.prefixCls+"-cavans",onMouseDown:this.handleMouseDown,style:n},i)},t}(l.Component);t["default"]=p,e.exports=t["default"]},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}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 r(e,t){for(var n=Object.getOwnPropertyNames(t),i=0;i<n.length;i++){var o=n[i],r=Object.getOwnPropertyDescriptor(t,o);r&&r.configurable&&void 0===e[o]&&Object.defineProperty(e,o,r)}return e}function a(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 c(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 l(){}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=void 0;var p=function(){function e(e,t){var n=[],i=!0,o=!1,r=void 0;try{for(var a,s=e[Symbol.iterator]();!(i=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);i=!0);}catch(c){o=!0,r=c}finally{try{!i&&s["return"]&&s["return"]()}finally{if(o)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=o(h);n(8);var f=n(4),d=i(f),y=n(6),m=i(y),v=n(7),b=i(v),g=n(2),w=i(g),x=300,C=function(e){function t(n){a(this,t);var i=s(this,e.call(this,n));return i.prefixCls="react-viewer",i.state={visible:!1,visibleStart:!1,transitionEnd:!1,activeIndex:i.props.activeIndex,width:0,height:0,top:15,left:null,rotate:0,imageWidth:0,imageHeight:0,scaleX:1,scaleY:1},i.handleChangeImg=i.handleChangeImg.bind(i),i.handleChangeImgState=i.handleChangeImgState.bind(i),i.handleAction=i.handleAction.bind(i),i.handleResize=i.handleResize.bind(i),i.handleZoom=i.handleZoom.bind(i),i.handleRotate=i.handleRotate.bind(i),i.handleKeydown=i.handleKeydown.bind(i),i.handleScaleX=i.handleScaleX.bind(i),i.handleScaleY=i.handleScaleY.bind(i),i.getImageCenterXY=i.getImageCenterXY.bind(i),i.setContainerWidthHeight(),i.footerHeight=84,i}return c(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.setState({visibleStart:!0}),setTimeout(function(){t.setState({visible:!0}),setTimeout(function(){t.bindEvent(),t.loadImg(e,!0)},300)},10)},t.prototype.componentDidMount=function(){this.startVisible(this.state.activeIndex)},t.prototype.getImgWidthHeight=function(e,t){var n=0,i=0,o=e/t;return o>1?(n=Math.min(.8*this.containerWidth,e),i=n/e*t):(i=Math.min(.8*(this.containerHeight-this.footerHeight),t),n=i/t*e),[n,i]},t.prototype.loadImg=function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i="",o=this.props.images||[];o.length>0&&(i=o[e].src);var r=new Image;r.src=i,r.onload=function(){var i=r.width,o=r.height;if(n)t.setState({activeIndex:e,width:0,height:0,left:t.containerWidth/2,top:(t.containerHeight-t.footerHeight)/2,rotate:0,imageWidth:i,imageHeight:o,scaleX:1,scaleY:1}),setTimeout(function(){var e=t.getImageCenterXY();t.handleZoom(e.x,e.y,1,1)},50);else{var a=t.getImgWidthHeight(i,o),s=p(a,2),c=s[0],l=s[1],h=(t.containerWidth-c)/2,u=(t.containerHeight-l-t.footerHeight)/2;t.setState({activeIndex:e,width:c,height:l,left:h,top:u,rotate:0,imageWidth:i,imageHeight:o,scaleX:1,scaleY:1})}},r.onerror=function(){t.setState({activeIndex:e,width:0,height:0,left:0,top:0,rotate:0,imageWidth:0,imageHeight:0,scaleX:1,scaleY:1})}},t.prototype.handleChangeImg=function(e){var t=this,n=this.getImageCenterXY();this.handleZoom(n.x,n.y,-1,1),setTimeout(function(){t.loadImg(e)},x)},t.prototype.handleChangeImgState=function(e,t,n,i){this.setState({width:e,height:t,top:n,left:i})},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===this.state.scaleX?-1:1);break;case g.ActionType.scaleY:this.handleScaleY(1===this.state.scaleY?-1:1)}},t.prototype.handleScaleX=function(e){this.setState({scaleX:e})},t.prototype.handleScaleY=function(e){this.setState({scaleY:e})},t.prototype.handleZoom=function(e,t,n,i){var o=this.getImageCenterXY(),r=e-o.x,a=t-o.y,s=n*this.state.width*i,c=n*this.state.height*i;if(0===s){var l=this.getImgWidthHeight(this.state.imageWidth,this.state.imageHeight),h=p(l,2),u=h[0],f=h[1];s=u,c=f}this.setState({width:this.state.width+s,height:this.state.height+c,top:this.state.top+-c/2+-n*a*i,left:this.state.left+-s/2+-n*r*i})},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(){this.setContainerWidthHeight(),this.loadImg(this.state.activeIndex)},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.handleTransitionEnd=function(e){this.state.transitionEnd&&!this.state.visibleStart||this.setState({visibleStart:!1,transitionEnd:!0})},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.componentWillReceiveProps=function(e){var t=this;if(!this.props.visible&&e.visible)return void this.startVisible(e.activeIndex);if(this.props.visible&&!e.visible){this.bindEvent(!0);var n=this.getImageCenterXY();return this.handleZoom(n.x,n.y,-1,1),void setTimeout(function(){t.setState({visible:!1,transitionEnd:!1})},x)}return this.state.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};if(!this.state.visible&&this.state.transitionEnd&&(n.display="none"),!this.state.visible&&this.state.visibleStart&&(n.display="block"),this.state.visible&&this.state.transitionEnd){var i=this.props.images||[];i.length>0&&this.state.activeIndex>=0&&(e=i[this.state.activeIndex])}var o=this.prefixCls+" "+this.prefixCls+"-transition";return this.props.container&&(o+=" inline"),u.createElement("div",{className:o,style:n,onTransitionEnd:this.handleTransitionEnd.bind(this)},u.createElement("div",{className:this.prefixCls+"-mask",style:{zIndex:t}}),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(d["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}),u.createElement("div",{className:this.prefixCls+"-footer",style:{zIndex:t+5}},u.createElement(b["default"],{prefixCls:this.prefixCls,onAction:this.handleAction,alt:e.alt,width:this.state.imageWidth,height:this.state.imageHeight}),u.createElement(m["default"],{prefixCls:this.prefixCls,images:this.props.images,activeIndex:this.state.activeIndex,onChangeImg:this.handleChangeImg})))},t}(u.Component);t["default"]=C,C.defaultProps={visible:!1,onClose:l,images:[],activeIndex:0,zIndex:1e3},e.exports=t["default"]},function(e,t,n){"use strict";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 o(e,t){for(var n=Object.getOwnPropertyNames(t),i=0;i<n.length;i++){var o=n[i],r=Object.getOwnPropertyDescriptor(t,o);r&&r.configurable&&void 0===e[o]&&Object.defineProperty(e,o,r)}return e}function r(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 s(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):o(e,t))}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=void 0;var c=n(1),l=i(c),p=function(e){function t(){return r(this,t),a(this,e.apply(this,arguments))}return s(t,e),t.prototype.handleChangeImg=function(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 l.createElement("div",{className:this.props.prefixCls+"-navbar"},l.createElement("ul",{className:this.props.prefixCls+"-list "+this.props.prefixCls+"-list-transition",style:n},this.props.images.map(function(t,n){return l.createElement("li",{key:n,className:n===e.props.activeIndex?"active":"",onClick:e.handleChangeImg.bind(e,n)},l.createElement("img",{src:t.src,alt:t.alt}))})))},t}(l.Component);t["default"]=p,p.defaultProps={activeIndex:0},e.exports=t["default"]},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}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 r(e,t){for(var n=Object.getOwnPropertyNames(t),i=0;i<n.length;i++){var o=n[i],r=Object.getOwnPropertyDescriptor(t,o);r&&r.configurable&&void 0===e[o]&&Object.defineProperty(e,o,r)}return e}function a(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 c(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 l=n(1),p=o(l),h=n(2),u=i(h),f=function(e){function t(){return a(this,t),s(this,e.call(this))}return c(t,e),t.prototype.handleAction=function(e){this.props.onAction(e)},t.prototype.render=function(){var e=this;return p.createElement("div",null,p.createElement("p",{className:this.props.prefixCls+"-attribute"},this.props.alt+"("+this.props.width+" x "+this.props.height+")"),p.createElement("ul",{className:this.props.prefixCls+"-toolbar"},p.createElement("li",{className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.zoomIn)}},p.createElement(u["default"],{type:h.ActionType.zoomIn})),p.createElement("li",{className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.zoomOut)}},p.createElement(u["default"],{type:h.ActionType.zoomOut})),p.createElement("li",{className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.prev)}},p.createElement(u["default"],{type:h.ActionType.prev})),p.createElement("li",{className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.reset)}},p.createElement(u["default"],{type:h.ActionType.reset})),p.createElement("li",{className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.next)}},p.createElement(u["default"],{type:h.ActionType.next})),p.createElement("li",{className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.rotateLeft)}},p.createElement(u["default"],{type:h.ActionType.rotateLeft})),p.createElement("li",{className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.rotateRight)}},p.createElement(u["default"],{type:h.ActionType.rotateRight})),p.createElement("li",{className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.scaleX)}},p.createElement(u["default"],{type:h.ActionType.scaleX})),p.createElement("li",{className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.scaleY)}},p.createElement(u["default"],{type:h.ActionType.scaleY}))))},t}(p.Component);t["default"]=f,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(i){if(n[i])return n[i].exports;var o=n[i]={exports:{},id:i,loaded:!1};return e[i].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=n(4),r=i(o);t["default"]=r["default"],e.exports=t["default"]},function(t,n){t.exports=e},function(e,t,n){"use strict";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 o(e,t){for(var n=Object.getOwnPropertyNames(t),i=0;i<n.length;i++){var o=n[i],r=Object.getOwnPropertyDescriptor(t,o);r&&r.configurable&&void 0===e[o]&&Object.defineProperty(e,o,r)}return e}function r(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 s(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):o(e,t))}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=t.ActionType=void 0;var c=n(1),l=i(c),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"}(p||(t.ActionType=p={}));var h=function(e){function t(){return r(this,t),a(this,e.apply(this,arguments))}return s(t,e),t.prototype.render=function(){var e="react-viewer-icon";return l.createElement("i",{className:e+" "+e+"-"+p[this.props.type]})},t}(l.Component);t["default"]=h},function(e,t,n){"use strict";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 o(e,t){for(var n=Object.getOwnPropertyNames(t),i=0;i<n.length;i++){var o=n[i],r=Object.getOwnPropertyDescriptor(t,o);r&&r.configurable&&void 0===e[o]&&Object.defineProperty(e,o,r)}return e}function r(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 s(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):o(e,t))}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=void 0;var c=n(1),l=i(c),p=function(e){function t(){return r(this,t),a(this,e.call(this))}return s(t,e),t.prototype.render=function(){var e="spin spin-spinning";return l.createElement("div",{className:"spin-wrap",style:this.props.style},l.createElement("div",{className:e},l.createElement("div",{className:"spin-dot"})))},t}(l.Component);t["default"]=p,e.exports=t["default"]},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}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 r(e,t){for(var n=Object.getOwnPropertyNames(t),i=0;i<n.length;i++){var o=n[i],r=Object.getOwnPropertyDescriptor(t,o);r&&r.configurable&&void 0===e[o]&&Object.defineProperty(e,o,r)}return e}function a(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 c(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 l=n(1),p=o(l),h=n(10),u=o(h),f=n(6),d=i(f),y=function(e){function t(){a(this,t);var n=s(this,e.call(this));return n.container=null,n.component=null,n}return c(t,e),t.prototype.renderViewer=function(){var e=this;(this.props.visible||this.component)&&!function(){e.container||(e.props.container?e.container=e.props.container:(e.container=document.createElement("div"),document.body.appendChild(e.container)));var t=e;u.unstable_renderSubtreeIntoContainer(e,p.createElement(d["default"],e.props),e.container,function(){t.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.removeViewer()):this.removeViewer()},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 i(e){return e&&e.__esModule?e:{"default":e}}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 r(e,t){for(var n=Object.getOwnPropertyNames(t),i=0;i<n.length;i++){var o=n[i],r=Object.getOwnPropertyDescriptor(t,o);r&&r.configurable&&void 0===e[o]&&Object.defineProperty(e,o,r)}return e}function a(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 c(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 l=n(1),p=o(l),h=n(3),u=i(h),f=function(e){function t(){a(this,t);var n=s(this,e.call(this));return 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.handleResize=n.handleResize.bind(n),n}return c(t,e),t.prototype.componentDidMount=function(){this.bindEvent()},t.prototype.handleResize=function(e){this.props.onResize()},t.prototype.handleMouseDown=function(e){this.props.visible&&(e.preventDefault(),e.stopPropagation(),this.setState({isMouseDown:!0,mouseX:e.nativeEvent.pageX,mouseY:e.nativeEvent.pageY}))},t.prototype.handleMouseMove=function(e){if(this.state.isMouseDown){var t=e.x-this.state.mouseX,n=e.y-this.state.mouseY;this.setState({mouseX:e.x,mouseY:e.y}),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){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.pageX,i=e.pageY;this.props.onZoom(n,i,t,.05)}},t.prototype.bindEvent=function(e){var t="addEventListener";e&&(t="removeEventListener"),document[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){!this.props.visible&&e.visible&&this.bindEvent(),this.props.visible&&!e.visible&&this.bindEvent(!0)},t.prototype.render=function(){var e={width:this.props.width+"px",marginTop:this.props.top+"px",marginLeft:this.props.left?this.props.left+"px":"auto",transform:"rotate("+this.props.rotate+"deg) scaleX("+this.props.scaleX+") scaleY("+this.props.scaleY+")"},t="";this.state.isMouseDown||(t=this.props.prefixCls+"-image-transition");var n={zIndex:this.props.zIndex},i=null;return""!==this.props.imgSrc&&(i=p.createElement("img",{className:t,src:this.props.imgSrc,style:e,onMouseDown:this.handleMouseDown})),this.props.loading&&(i=p.createElement(u["default"],{style:{marginTop:this.props.top,marginLeft:this.props.left}})),p.createElement("div",{className:this.props.prefixCls+"-cavans",onMouseDown:this.handleMouseDown,style:n},i)},t}(p.Component);t["default"]=f,e.exports=t["default"]},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}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 r(e,t){for(var n=Object.getOwnPropertyNames(t),i=0;i<n.length;i++){var o=n[i],r=Object.getOwnPropertyDescriptor(t,o);r&&r.configurable&&void 0===e[o]&&Object.defineProperty(e,o,r)}return e}function a(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 c(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 l(){}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=void 0;var p=function(){function e(e,t){var n=[],i=!0,o=!1,r=void 0;try{for(var a,s=e[Symbol.iterator]();!(i=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);i=!0);}catch(c){o=!0,r=c}finally{try{!i&&s["return"]&&s["return"]()}finally{if(o)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=o(h);n(9);var f=n(5),d=i(f),y=n(7),m=i(y),v=n(8),b=i(v),g=n(2),w=i(g),x=300,O=function(e){function t(n){a(this,t);var i=s(this,e.call(this,n));return i.prefixCls="react-viewer",i.state={visible:!1,visibleStart:!1,transitionEnd:!1,activeIndex:i.props.activeIndex,width:0,height:0,top:15,left:null,rotate:0,imageWidth:0,imageHeight:0,scaleX:1,scaleY:1,loading:!1},i.handleChangeImg=i.handleChangeImg.bind(i),i.handleChangeImgState=i.handleChangeImgState.bind(i),i.handleAction=i.handleAction.bind(i),i.handleResize=i.handleResize.bind(i),i.handleZoom=i.handleZoom.bind(i),i.handleRotate=i.handleRotate.bind(i),i.handleKeydown=i.handleKeydown.bind(i),i.handleScaleX=i.handleScaleX.bind(i),i.handleScaleY=i.handleScaleY.bind(i),i.getImageCenterXY=i.getImageCenterXY.bind(i),i.setContainerWidthHeight(),i.footerHeight=84,i}return c(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.setState({visibleStart:!0}),setTimeout(function(){t.setState({visible:!0}),setTimeout(function(){t.bindEvent(),t.loadImg(e,!0)},300)},10)},t.prototype.componentDidMount=function(){this.startVisible(this.state.activeIndex)},t.prototype.getImgWidthHeight=function(e,t){var n=0,i=0,o=e/t;return o>1?(n=Math.min(.8*this.containerWidth,e),i=n/e*t):(i=Math.min(.8*(this.containerHeight-this.footerHeight),t),n=i/t*e),[n,i]},t.prototype.loadImg=function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i="",o=this.props.images||[];o.length>0&&(i=o[e].src);var r=new Image;r.src=i,n&&this.setState({activeIndex:e,width:0,height:0,left:this.containerWidth/2,top:(this.containerHeight-this.footerHeight)/2,rotate:0,scaleX:1,scaleY:1,loading:!0}),r.onload=function(){var i=r.width,o=r.height;if(n)setTimeout(function(){t.setState({activeIndex:e,imageWidth:i,imageHeight:o});var n=t.getImageCenterXY();t.handleZoom(n.x,n.y,1,1)},50);else{var a=t.getImgWidthHeight(i,o),s=p(a,2),c=s[0],l=s[1],h=(t.containerWidth-c)/2,u=(t.containerHeight-l-t.footerHeight)/2;t.setState({activeIndex:e,width:c,height:l,left:h,top:u,imageWidth:i,imageHeight:o,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,i){this.setState({width:e,height:t,top:n,left:i})},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===this.state.scaleX?-1:1);break;case g.ActionType.scaleY:this.handleScaleY(1===this.state.scaleY?-1:1)}},t.prototype.handleScaleX=function(e){this.setState({scaleX:e})},t.prototype.handleScaleY=function(e){this.setState({scaleY:e})},t.prototype.handleZoom=function(e,t,n,i){var o=this.getImageCenterXY(),r=e-o.x,a=t-o.y,s=n*this.state.width*i,c=n*this.state.height*i;if(0===s){var l=this.getImgWidthHeight(this.state.imageWidth,this.state.imageHeight),h=p(l,2),u=h[0],f=h[1];s=u,c=f}this.setState({width:this.state.width+s,height:this.state.height+c,top:this.state.top+-c/2+-n*a*i,left:this.state.left+-s/2+-n*r*i,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(){this.setContainerWidthHeight(),this.loadImg(this.state.activeIndex)},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.handleTransitionEnd=function(e){this.state.transitionEnd&&!this.state.visibleStart||this.setState({visibleStart:!1,transitionEnd:!0})},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.componentWillReceiveProps=function(e){var t=this;if(!this.props.visible&&e.visible)return void this.startVisible(e.activeIndex);if(this.props.visible&&!e.visible){this.bindEvent(!0);var n=this.getImageCenterXY();return this.handleZoom(n.x,n.y,-1,1),void setTimeout(function(){t.setState({visible:!1,transitionEnd:!1})},x)}return this.state.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};if(!this.state.visible&&this.state.transitionEnd&&(n.display="none"),!this.state.visible&&this.state.visibleStart&&(n.display="block"),this.state.visible&&this.state.transitionEnd){var i=this.props.images||[];i.length>0&&this.state.activeIndex>=0&&(e=i[this.state.activeIndex])}var o=this.prefixCls+" "+this.prefixCls+"-transition";return this.props.container&&(o+=" inline"),u.createElement("div",{className:o,style:n,onTransitionEnd:this.handleTransitionEnd.bind(this)},u.createElement("div",{className:this.prefixCls+"-mask",style:{zIndex:t}}),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(d["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}),u.createElement("div",{className:this.prefixCls+"-footer",style:{zIndex:t+5}},u.createElement(b["default"],{prefixCls:this.prefixCls,onAction:this.handleAction,alt:e.alt,width:this.state.imageWidth,height:this.state.imageHeight}),u.createElement(m["default"],{prefixCls:this.prefixCls,images:this.props.images,activeIndex:this.state.activeIndex,onChangeImg:this.handleChangeImg})))},t}(u.Component);t["default"]=O,O.defaultProps={visible:!1,onClose:l,images:[],activeIndex:0,zIndex:1e3},e.exports=t["default"]},function(e,t,n){"use strict";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 o(e,t){for(var n=Object.getOwnPropertyNames(t),i=0;i<n.length;i++){var o=n[i],r=Object.getOwnPropertyDescriptor(t,o);r&&r.configurable&&void 0===e[o]&&Object.defineProperty(e,o,r)}return e}function r(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 s(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):o(e,t))}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=void 0;var c=n(1),l=i(c),p=function(e){function t(){return r(this,t),a(this,e.apply(this,arguments))}return s(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 l.createElement("div",{className:this.props.prefixCls+"-navbar"},l.createElement("ul",{className:this.props.prefixCls+"-list "+this.props.prefixCls+"-list-transition",style:n},this.props.images.map(function(t,n){return l.createElement("li",{key:n,className:n===e.props.activeIndex?"active":"",onClick:e.handleChangeImg.bind(e,n)},l.createElement("img",{src:t.src,alt:t.alt}))})))},t}(l.Component);t["default"]=p,p.defaultProps={activeIndex:0},e.exports=t["default"]},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}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 r(e,t){for(var n=Object.getOwnPropertyNames(t),i=0;i<n.length;i++){var o=n[i],r=Object.getOwnPropertyDescriptor(t,o);r&&r.configurable&&void 0===e[o]&&Object.defineProperty(e,o,r)}return e}function a(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 c(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 l=n(1),p=o(l),h=n(2),u=i(h),f=function(e){function t(){return a(this,t),s(this,e.call(this))}return c(t,e),t.prototype.handleAction=function(e){this.props.onAction(e)},t.prototype.render=function(){var e=this;return p.createElement("div",null,p.createElement("p",{className:this.props.prefixCls+"-attribute"},this.props.alt+"("+this.props.width+" x "+this.props.height+")"),p.createElement("ul",{className:this.props.prefixCls+"-toolbar"},p.createElement("li",{className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.zoomIn)}},p.createElement(u["default"],{type:h.ActionType.zoomIn})),p.createElement("li",{className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.zoomOut)}},p.createElement(u["default"],{type:h.ActionType.zoomOut})),p.createElement("li",{className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.prev)}},p.createElement(u["default"],{type:h.ActionType.prev})),p.createElement("li",{className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.reset)}},p.createElement(u["default"],{type:h.ActionType.reset})),p.createElement("li",{className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.next)}},p.createElement(u["default"],{type:h.ActionType.next})),p.createElement("li",{className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.rotateLeft)}},p.createElement(u["default"],{type:h.ActionType.rotateLeft})),p.createElement("li",{className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.rotateRight)}},p.createElement(u["default"],{type:h.ActionType.rotateRight})),p.createElement("li",{className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.scaleX)}},p.createElement(u["default"],{type:h.ActionType.scaleX})),p.createElement("li",{className:this.props.prefixCls+"-btn",onClick:function(){e.handleAction(h.ActionType.scaleY)}},p.createElement(u["default"],{type:h.ActionType.scaleY}))))},t}(p.Component);t["default"]=f,e.exports=t["default"]},function(e,t){},function(e,n){e.exports=t}])}); |
@@ -18,2 +18,3 @@ /// <reference types="react" /> | ||
scaleY: 1 | -1; | ||
loading: boolean; | ||
} | ||
@@ -20,0 +21,0 @@ export interface ViewerCavansState { |
@@ -24,2 +24,6 @@ 'use strict'; | ||
var _Loading = require('./Loading'); | ||
var _Loading2 = _interopRequireDefault(_Loading); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
@@ -60,2 +64,5 @@ | ||
ViewerCavans.prototype.handleMouseDown = function handleMouseDown(e) { | ||
if (!this.props.visible) { | ||
return; | ||
} | ||
e.preventDefault(); | ||
@@ -140,2 +147,8 @@ e.stopPropagation(); | ||
} | ||
if (this.props.loading) { | ||
imgNode = React.createElement(_Loading2.default, { style: { | ||
marginTop: this.props.top, | ||
marginLeft: this.props.left | ||
} }); | ||
} | ||
return React.createElement( | ||
@@ -142,0 +155,0 @@ 'div', |
@@ -20,2 +20,3 @@ /// <reference types="react" /> | ||
scaleY?: 1 | -1; | ||
loading?: boolean; | ||
} | ||
@@ -22,0 +23,0 @@ export default class ViewerCore extends React.Component<ViewerProps, ViewerCoreState> { |
@@ -75,3 +75,4 @@ 'use strict'; | ||
scaleX: 1, | ||
scaleY: 1 | ||
scaleY: 1, | ||
loading: false | ||
}; | ||
@@ -153,2 +154,15 @@ _this.handleChangeImg = _this.handleChangeImg.bind(_this); | ||
img.src = imgSrc; | ||
if (firstLoad) { | ||
this.setState({ | ||
activeIndex: activeIndex, | ||
width: 0, | ||
height: 0, | ||
left: this.containerWidth / 2, | ||
top: (this.containerHeight - this.footerHeight) / 2, | ||
rotate: 0, | ||
scaleX: 1, | ||
scaleY: 1, | ||
loading: true | ||
}); | ||
} | ||
img.onload = function () { | ||
@@ -158,15 +172,8 @@ var imgWidth = img.width; | ||
if (firstLoad) { | ||
_this3.setState({ | ||
activeIndex: activeIndex, | ||
width: 0, | ||
height: 0, | ||
left: _this3.containerWidth / 2, | ||
top: (_this3.containerHeight - _this3.footerHeight) / 2, | ||
rotate: 0, | ||
imageWidth: imgWidth, | ||
imageHeight: imgHeight, | ||
scaleX: 1, | ||
scaleY: 1 | ||
}); | ||
setTimeout(function () { | ||
_this3.setState({ | ||
activeIndex: activeIndex, | ||
imageWidth: imgWidth, | ||
imageHeight: imgHeight | ||
}); | ||
var imgCenterXY = _this3.getImageCenterXY(); | ||
@@ -191,5 +198,6 @@ _this3.handleZoom(imgCenterXY.x, imgCenterXY.y, 1, 1); | ||
top: top, | ||
rotate: 0, | ||
imageWidth: imgWidth, | ||
imageHeight: imgHeight, | ||
loading: false, | ||
rotate: 0, | ||
scaleX: 1, | ||
@@ -203,11 +211,5 @@ scaleY: 1 | ||
activeIndex: activeIndex, | ||
width: 0, | ||
height: 0, | ||
left: 0, | ||
top: 0, | ||
rotate: 0, | ||
imageWidth: 0, | ||
imageHeight: 0, | ||
scaleX: 1, | ||
scaleY: 1 | ||
loading: false | ||
}); | ||
@@ -218,9 +220,8 @@ }; | ||
ViewerCore.prototype.handleChangeImg = function handleChangeImg(newIndex) { | ||
var _this4 = this; | ||
var imgCenterXY2 = this.getImageCenterXY(); | ||
this.handleZoom(imgCenterXY2.x, imgCenterXY2.y, -1, 1); | ||
setTimeout(function () { | ||
_this4.loadImg(newIndex); | ||
}, transitionDuration); | ||
// let imgCenterXY2 = this.getImageCenterXY(); | ||
// this.handleZoom(imgCenterXY2.x, imgCenterXY2.y, -1, 1); | ||
// setTimeout(() => { | ||
// this.loadImg(newIndex); | ||
// }, transitionDuration); | ||
this.loadImg(newIndex); | ||
}; | ||
@@ -311,3 +312,4 @@ | ||
top: this.state.top + -diffHeight / 2 + -direct * diffY * scale, | ||
left: this.state.left + -diffWidth / 2 + -direct * diffX * scale | ||
left: this.state.left + -diffWidth / 2 + -direct * diffX * scale, | ||
loading: false | ||
}); | ||
@@ -408,3 +410,3 @@ }; | ||
ViewerCore.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { | ||
var _this5 = this; | ||
var _this4 = this; | ||
@@ -420,3 +422,3 @@ if (!this.props.visible && nextProps.visible) { | ||
setTimeout(function () { | ||
_this5.setState({ | ||
_this4.setState({ | ||
visible: false, | ||
@@ -471,3 +473,3 @@ transitionEnd: false | ||
), | ||
React.createElement(_ViewerCavans2.default, { prefixCls: this.prefixCls, imgSrc: activeImg.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: zIndex + 5, scaleX: this.state.scaleX, scaleY: this.state.scaleY }), | ||
React.createElement(_ViewerCavans2.default, { prefixCls: this.prefixCls, imgSrc: activeImg.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: zIndex + 5, scaleX: this.state.scaleX, scaleY: this.state.scaleY, loading: this.state.loading }), | ||
React.createElement( | ||
@@ -474,0 +476,0 @@ 'div', |
@@ -37,2 +37,5 @@ 'use strict'; | ||
ViewerNav.prototype.handleChangeImg = function handleChangeImg(newIndex) { | ||
if (this.props.activeIndex === newIndex) { | ||
return; | ||
} | ||
this.props.onChangeImg(newIndex); | ||
@@ -39,0 +42,0 @@ }; |
{ | ||
"name": "react-viewer", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"description": "react image viewer", | ||
@@ -5,0 +5,0 @@ "main": "dist/index", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
170944
32
2356