UNPKG

4.02 kBJavaScriptView Raw
1var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
2
3var _class, _temp;
4
5function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
6
7function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
9function _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; }
10
11function _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) : subClass.__proto__ = superClass; }
12
13import React, { Component } from 'react';
14import PropTypes from 'prop-types';
15import Instance from './instance.js';
16
17var Handsign = (_temp = _class = function (_Component) {
18 _inherits(Handsign, _Component);
19
20 function Handsign(props) {
21 _classCallCheck(this, Handsign);
22
23 return _possibleConstructorReturn(this, _Component.call(this, props));
24 }
25
26 Handsign.prototype.componentDidUpdate = function componentDidUpdate(prevProps) {
27 if (this.instance) {
28 if (prevProps.strokeStyle !== this.props.strokeStyle) {
29 this.instance.setStrokeStyle(this.props.strokeStyle);
30 }
31 if (prevProps.lineWidth !== this.props.lineWidth) {
32 this.instance.setLineWidth(this.props.lineWidth);
33 }
34 if (prevProps.quality !== this.props.quality) {
35 this.instance.setQuality(this.props.quality);
36 }
37 if (prevProps.suffix !== this.props.suffix) {
38 this.instance.setSuffix(this.props.suffix);
39 }
40 }
41 };
42
43 Handsign.prototype.componentDidMount = function componentDidMount() {
44 if (this.instance) return;
45 var instance = new Instance(this.$el, {
46 strokeStyle: this.props.strokeStyle,
47 lineWidth: this.props.lineWidth,
48 quality: this.props.quality,
49 suffix: this.props.suffix
50 });
51 this.instance = instance;
52 };
53
54 Handsign.prototype.render = function render() {
55 var _this2 = this;
56
57 var _props = this.props,
58 strokeStyle = _props.strokeStyle,
59 lineWidth = _props.lineWidth,
60 quality = _props.quality,
61 width = _props.width,
62 height = _props.height,
63 style = _props.style,
64 className = _props.className,
65 others = _objectWithoutProperties(_props, ['strokeStyle', 'lineWidth', 'quality', 'width', 'height', 'style', 'className']);
66
67 return React.createElement(
68 'canvas',
69 _extends({ ref: function ref(el) {
70 _this2.$el = el;
71 }, className: className, style: style, width: width, height: height }, others),
72 'Canvas\u753B\u677F'
73 );
74 };
75
76 return Handsign;
77}(Component), _class.defaultProps = {
78 strokeStyle: '#000',
79 lineWidth: 3,
80 quality: 0.92,
81 width: 300,
82 height: 300
83}, _temp);
84export { Handsign as default };
85Handsign.propTypes = process.env.NODE_ENV !== "production" ? {
86 strokeStyle: PropTypes.string,
87 lineWidth: PropTypes.number,
88 quality: PropTypes.number,
89 suffix: PropTypes.string,
90 // 不能使用style制定宽高,canvas用style的width|height会导致绘图位置不正确
91 width: PropTypes.number, // 宽度
92 height: PropTypes.number, // 高度
93 style: PropTypes.object,
94 className: PropTypes.string
95} : {};
\No newline at end of file