"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");

exports.__esModule = true;
exports.default = void 0;

var _promise = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/promise"));

/*
 * @Author: lijianzhang
 * @Date: 2018-10-31 10:53:46
 * @Last Modified by: lijianzhang
 * @Last Modified time: 2018-12-16 13:08:37
 */
var id = 0;

var GdFile =
/*#__PURE__*/
function () {
  function GdFile(file) {
    this.originFile = file;
    this.status = 'ready';
    this.lastModified = file.lastModified;
    this.lastModifiedDate = file.lastModifiedDate;
    this.id = ++id;
    this.src = '';
    this.name = file.name;
    this.size = file.size;
    this.type = file.type;
    this.percent = 0;
  }

  var _proto = GdFile.prototype;

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

    return new _promise.default(function (resolve, reject) {
      if (!/image\//.test(_this.type)) {
        reject(new Error('该文件不是图像文件'));
      }

      var image = new Image();
      image.src = _this.src;

      image.onload = function () {
        resolve({
          width: image.width,
          height: image.height
        });
      };

      image.onerror = function (error) {
        return reject(error);
      };
    });
  };

  _proto.toURL = function toURL() {
    return URL.createObjectURL(this.originFile);
  };

  return GdFile;
}();

exports.default = GdFile;