'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _regeneratorRuntime = require('@babel/runtime/regenerator');
var tslib_es6 = require('../tslib.es6-0d92ef81.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);

var consoleImage = function consoleImage(url) {
  var image = new Image();
  image.onload = function () {
    // @ts-ignore
    var isChromium = navigator.userAgent.match(/chrome|chromium|crios/i) && !!window.chrome;
    var style = ['font-size: 0px;', !isChromium ? "line-height: ".concat(this.height, "px;") : '', "padding: ".concat(this.height / 2, "px ").concat(this.width / 2, "px;"), "background: url(".concat(url, ") center center no-repeat;"), 'background-size: contain;'].join(' ');
    console.log('%c ', style);
  };
  image.src = url;
};
/**
 * 获取图片，并转 base64
 *
 * @param url 图片链接
 * @returns 获取结果
 * @example
 * ```ts
 * getBase64FromUrl(imgUrl).then(consoleImage);
 * ```
 */
function getBase64FromUrl(url) {
  return tslib_es6.__awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
    var data, blob;
    return _regeneratorRuntime__default["default"].wrap(function (_context) {
      while (1) switch (_context.prev = _context.next) {
        case 0:
          _context.next = 1;
          return fetch(url);
        case 1:
          data = _context.sent;
          _context.next = 2;
          return data.blob();
        case 2:
          blob = _context.sent;
          return _context.abrupt("return", new Promise(function (resolve, reject) {
            var reader = new FileReader();
            reader.readAsDataURL(blob);
            reader.onloadend = function () {
              var base64data = reader.result;
              resolve(base64data);
            };
            reader.onerror = reject;
          }));
        case 3:
        case "end":
          return _context.stop();
      }
    }, _callee);
  }));
}

exports.consoleImage = consoleImage;
exports.getBase64FromUrl = getBase64FromUrl;
