-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
1 lines (1 loc) · 2.31 KB
/
index.js
1
'use strict';var _createClass=function(){function a(b,c){for(var f,d=0;d<c.length;d++)f=c[d],f.enumerable=f.enumerable||!1,f.configurable=!0,'value'in f&&(f.writable=!0),Object.defineProperty(b,f.key,f)}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),_react=require('react'),_react2=_interopRequireDefault(_react),_bpgDecoder=require('bpg-decoder'),_bpgDecoder2=_interopRequireDefault(_bpgDecoder);Object.defineProperty(exports,'__esModule',{value:!0});function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError('Cannot call a class as a function')}function _possibleConstructorReturn(a,b){if(!a)throw new ReferenceError('this hasn\'t been initialised - super() hasn\'t been called');return b&&('object'==typeof b||'function'==typeof b)?b:a}function _inherits(a,b){if('function'!=typeof b&&null!==b)throw new TypeError('Super expression must either be null or a function, not '+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),b&&(Object.setPrototypeOf?Object.setPrototypeOf(a,b):a.__proto__=b)}var ReactBPG=function(a){function b(c){_classCallCheck(this,b);var d=_possibleConstructorReturn(this,(b.__proto__||Object.getPrototypeOf(b)).call(this,c));switch(d.props.BPGDecoder){case'BPGDecoder8':d.BPGDecoder=_bpgDecoder2.default.BPGDecoder8;break;case'BPGDecoder':d.BPGDecoder=_bpgDecoder2.default.BPGDecoder;break;default:d.BPGDecoder=_bpgDecoder2.default.BPGDecoder8a;}return d}return _inherits(b,a),_createClass(b,[{key:'componentDidMount',value:function componentDidMount(){try{var c=this.refs.canvas.getContext('2d'),d=new this.BPGDecoder(c),f=this;d.onload=function(){f.refs.canvas.width=this.imageData.width,f.refs.canvas.height=this.imageData.height,c.putImageData(this.imageData,0,0)},d.load(this.props.src)}catch(c){if(this.props.onError)return this.props.onError.call(this);throw c}}},{key:'render',value:function render(){return _react2.default.createElement('canvas',{ref:'canvas',className:this.props.className,style:this.props.style})}}]),b}(_react.Component);ReactBPG.propTypes={src:_react.PropTypes.string.isRequired,onError:_react.PropTypes.func,BPGDecoder:_react.PropTypes.string,className:_react.PropTypes.string,style:_react.PropTypes.object},exports.default=ReactBPG;