import _regeneratorRuntime from '@babel/runtime/regenerator';
import { _ as __awaiter } from '../tslib.es6-848120af.js';

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 __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
    var data, blob;
    return _regeneratorRuntime.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);
  }));
}

export { consoleImage, getBase64FromUrl };
