var _excluded = ["strokeStyle", "lineWidth", "quality", "width", "height"];

function _extends() { _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; }; return _extends.apply(this, arguments); }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Instance from './instance.js';

var Handsign = /*#__PURE__*/function (_Component) {
  _inheritsLoose(Handsign, _Component);

  function Handsign(props) {
    return _Component.call(this, props) || this;
  }

  var _proto = Handsign.prototype;

  _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
    if (this.instance) {
      var params = {};

      if (prevProps.strokeStyle !== this.props.strokeStyle) {
        params.strokeStyle = this.props.strokeStyle;
      }

      if (prevProps.lineWidth !== this.props.lineWidth) {
        params.lineWidth = this.props.lineWidth;
      }

      if (prevProps.quality !== this.props.quality) {
        params.quality = this.props.quality;
      }

      if (prevProps.suffix !== this.props.suffix) {
        params.suffix = this.props.suffix;
      }

      if (Object.getOwnPropertyNames(params) && Object.getOwnPropertyNames(params).length) {
        this.instance.updateParams(params);
      }
    }
  };

  _proto.componentDidMount = function componentDidMount() {
    if (this.instance) return;
    var instance = new Instance(this.$el, {
      strokeStyle: this.props.strokeStyle,
      lineWidth: this.props.lineWidth,
      quality: this.props.quality,
      suffix: this.props.suffix
    });
    this.instance = instance;
  };

  _proto.render = function render() {
    var _this = this;

    var _this$props = this.props,
        strokeStyle = _this$props.strokeStyle,
        lineWidth = _this$props.lineWidth,
        quality = _this$props.quality,
        width = _this$props.width,
        height = _this$props.height,
        others = _objectWithoutPropertiesLoose(_this$props, _excluded);

    return /*#__PURE__*/React.createElement("canvas", _extends({
      ref: function ref(el) {
        _this.$el = el;
      }
    }, others, {
      width: width,
      height: height
    }), "Canvas\u753B\u677F");
  };

  return Handsign;
}(Component);

_defineProperty(Handsign, "defaultProps", {
  strokeStyle: '#000',
  lineWidth: 3,
  quality: 0.92,
  width: 300,
  height: 300
});

export { Handsign as default };
Handsign.propTypes = process.env.NODE_ENV !== "production" ? {
  strokeStyle: PropTypes.string,
  lineWidth: PropTypes.number,
  quality: PropTypes.number,
  suffix: PropTypes.string,
  // 不能使用style制定宽高,canvas用style的width|height会导致绘图位置不正确
  width: PropTypes.number,
  // 宽度
  height: PropTypes.number // 高度

} : {};