shadow$provide.module$node_modules$pixi_DOT_js$lib$assets$loader$Loader = function(global, require, module, exports) {
  var warn = require("module$node_modules$pixi_DOT_js$lib$utils$logging$warn"), path = require("module$node_modules$pixi_DOT_js$lib$utils$path"), convertToList = require("module$node_modules$pixi_DOT_js$lib$assets$utils$convertToList"), isSingleItem = require("module$node_modules$pixi_DOT_js$lib$assets$utils$isSingleItem");
  "use strict";
  const node_modules$pixi_DOT_js$lib$assets$loader$Loader$classdecl$var37 = class {
    constructor() {
      this.loadOptions = {...node_modules$pixi_DOT_js$lib$assets$loader$Loader$classdecl$var37.defaultOptions};
      this._parsers = [];
      this._parsersValidated = !1;
      this.parsers = new Proxy(this._parsers, {set:(target, key, value) => {
        this._parsersValidated = !1;
        target[key] = value;
        return !0;
      }});
      this.promiseCache = {};
    }
    reset() {
      this._parsersValidated = !1;
      this.promiseCache = {};
    }
    _getLoadPromiseAndParser(url, data) {
      const result = {promise:null, parser:null};
      result.promise = (async() => {
        var asset, parser = null;
        if (data.parser || data.loadParser) {
          parser = this._parserHash[data.parser || data.loadParser], data.loadParser && warn.warn(`[Assets] "loadParser" is deprecated, use "parser" instead for ${url}`), parser || warn.warn(`[Assets] specified load parser "${data.parser || data.loadParser}" not found while loading ${url}`);
        }
        if (!parser) {
          for (asset = 0; asset < this.parsers.length; asset++) {
            var parserX = this.parsers[asset];
            if (parserX.load && parserX.test?.(url, data, this)) {
              parser = parserX;
              break;
            }
          }
          if (!parser) {
            return warn.warn(`[Assets] ${url} could not be loaded as we don't know how to parse it, ensure the correct parser has been added`), null;
          }
        }
        asset = await parser.load(url, data, this);
        result.parser = parser;
        for (parser = 0; parser < this.parsers.length; parser++) {
          parserX = this.parsers[parser], parserX.parse && parserX.parse && await parserX.testParse?.(asset, data, this) && (asset = await parserX.parse(asset, data, this) || asset, result.parser = parserX);
        }
        return asset;
      })();
      return result;
    }
    async load(assetsToLoadIn, onProgressOrOptions) {
      this._parsersValidated || this._validateParsers();
      const {onProgress, onError, strategy, retryCount, retryDelay} = "function" === typeof onProgressOrOptions ? {...node_modules$pixi_DOT_js$lib$assets$loader$Loader$classdecl$var37.defaultOptions, ...this.loadOptions, onProgress:onProgressOrOptions} : {...node_modules$pixi_DOT_js$lib$assets$loader$Loader$classdecl$var37.defaultOptions, ...this.loadOptions, ...(onProgressOrOptions || {})};
      let count = 0;
      const assets = {};
      onProgressOrOptions = isSingleItem.isSingleItem(assetsToLoadIn);
      assetsToLoadIn = convertToList.convertToList(assetsToLoadIn, item => ({alias:[item], src:item, data:{}}));
      const total = assetsToLoadIn.reduce((sum, asset) => sum + (asset.progressSize || 1), 0), promises = assetsToLoadIn.map(async asset => {
        const url = path.path.toAbsolute(asset.src);
        assets[asset.src] || (await this._loadAssetWithRetry(url, asset, {onProgress, onError, strategy, retryCount, retryDelay}, assets), count += asset.progressSize || 1, onProgress && onProgress(count / total));
      });
      await Promise.all(promises);
      return onProgressOrOptions ? assets[assetsToLoadIn[0].src] : assets;
    }
    async unload(assetsToUnloadIn) {
      assetsToUnloadIn = convertToList.convertToList(assetsToUnloadIn, item => ({alias:[item], src:item})).map(async asset => {
        const url = path.path.toAbsolute(asset.src), loadPromise = this.promiseCache[url];
        if (loadPromise) {
          const loadedAsset = await loadPromise.promise;
          delete this.promiseCache[url];
          await loadPromise.parser?.unload?.(loadedAsset, asset, this);
        }
      });
      await Promise.all(assetsToUnloadIn);
    }
    _validateParsers() {
      this._parsersValidated = !0;
      this._parserHash = this._parsers.filter(parser => parser.name || parser.id).reduce((hash, parser) => {
        parser.name || parser.id ? (hash[parser.name] || hash[parser.id]) && warn.warn(`[Assets] parser id conflict "${parser.id}"`) : warn.warn("[Assets] parser should have an id");
        hash[parser.name] = parser;
        parser.id && (hash[parser.id] = parser);
        return hash;
      }, {});
    }
    async _loadAssetWithRetry(url, asset, options, assets) {
      let attempt = 0;
      const {onError, strategy, retryCount, retryDelay} = options;
      for (options = ms => new Promise(r => setTimeout(r, ms));;) {
        try {
          this.promiseCache[url] || (this.promiseCache[url] = this._getLoadPromiseAndParser(url, asset));
          assets[asset.src] = await this.promiseCache[url].promise;
          break;
        } catch (e) {
          delete this.promiseCache[url];
          delete assets[asset.src];
          attempt++;
          const isLast = "retry" !== strategy || attempt > retryCount;
          if ("retry" !== strategy || isLast) {
            if ("skip" === strategy) {
              onError && onError(e, asset);
              break;
            }
            onError && onError(e, asset);
            url = Error(`[Loader.load] Failed to load ${url}.
${e}`);
            e instanceof Error && e.stack && (url.stack = e.stack);
            throw url;
          }
          onError && onError(e, asset);
          await options(retryDelay);
        }
      }
    }
  };
  global = node_modules$pixi_DOT_js$lib$assets$loader$Loader$classdecl$var37;
  global.defaultOptions = {onProgress:void 0, onError:void 0, strategy:"throw", retryCount:3, retryDelay:250};
  exports.Loader = global;
};

//# sourceMappingURL=module$node_modules$pixi_DOT_js$lib$assets$loader$Loader.js.map
