text: import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
  import _regeneratorRuntime from "@babel/runtime/regenerator";
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
  
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  
  import assert from '../utils/assert';
  import parseImage from '../parsers/parse-image';
  import { getImageSize } from '../parsed-image-api/parsed-image-api';
  import { generateUrl } from './generate-url';
  import { deepLoad, shallowLoad } from './deep-load';
  export function loadImage(_x) {
    return _loadImage.apply(this, arguments);
  }
  
  function _loadImage() {
    _loadImage = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(getUrl) {
      var options,
          imageUrls,
          _args = arguments;
      return _regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
              _context.next = 3;
              return getImageUrls(getUrl, options);
  
            case 3:
              imageUrls = _context.sent;
              _context.next = 6;
              return deepLoad(imageUrls, parseImage, options);
  
            case 6:
              return _context.abrupt("return", _context.sent);
  
            case 7:
            case "end":
              return _context.stop();
          }
        }
      }, _callee);
    }));
    return _loadImage.apply(this, arguments);
  }
  
  export function getImageUrls(_x2, _x3) {
    return _getImageUrls.apply(this, arguments);
  }
  
  function _getImageUrls() {
    _getImageUrls = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2(getUrl, options) {
      var urlOptions,
          mipLevels,
          _args2 = arguments;
      return _regeneratorRuntime.wrap(function _callee2$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              urlOptions = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
              mipLevels = options && options.image && options.image.mipLevels || 0;
  
              if (!(mipLevels !== 0)) {
                _context2.next = 8;
                break;
              }
  
              _context2.next = 5;
              return getMipmappedImageUrls(getUrl, mipLevels, options, urlOptions);
  
            case 5:
              _context2.t0 = _context2.sent;
              _context2.next = 9;
              break;
  
            case 8:
              _context2.t0 = generateUrl(getUrl, options, urlOptions);
  
            case 9:
              return _context2.abrupt("return", _context2.t0);
  
            case 10:
            case "end":
              return _context2.stop();
          }
        }
      }, _callee2);
    }));
    return _getImageUrls.apply(this, arguments);
  }
  
  function getMipmappedImageUrls(_x4, _x5, _x6, _x7) {
    return _getMipmappedImageUrls.apply(this, arguments);
  }
  
  function _getMipmappedImageUrls() {
    _getMipmappedImageUrls = _asyncToGenerator(_regeneratorRuntime.mark(function _callee3(getUrl, mipLevels, options, urlOptions) {
      var urls, url, image, _getImageSize, width, height, mipLevel, _url;
  
      return _regeneratorRuntime.wrap(function _callee3$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              urls = [];
  
              if (!(mipLevels === 'auto')) {
                _context3.next = 9;
                break;
              }
  
              url = generateUrl(getUrl, options, _objectSpread({}, urlOptions, {
                lod: 0
              }));
              _context3.next = 5;
              return shallowLoad(url, parseImage, options);
  
            case 5:
              image = _context3.sent;
              _getImageSize = getImageSize(image), width = _getImageSize.width, height = _getImageSize.height;
              mipLevels = getMipLevels({
                width: width,
                height: height
              });
              urls.push(url);
  
            case 9:
              assert(mipLevels > 0);
  
              for (mipLevel = urls.length; mipLevel < mipLevels; ++mipLevel) {
                _url = generateUrl(getUrl, options, _objectSpread({}, urlOptions, {
                  lod: mipLevel
                }));
                urls.push(_url);
              }
  
              return _context3.abrupt("return", urls);
  
            case 12:
            case "end":
              return _context3.stop();
          }
        }
      }, _callee3);
    }));
    return _getMipmappedImageUrls.apply(this, arguments);
  }
  
  export function getMipLevels(_ref) {
    var width = _ref.width,
        height = _ref.height;
    return 1 + Math.floor(Math.log2(Math.max(width, height)));
  }
  //# sourceMappingURL=load-image.js.map