shadow$provide.module$node_modules$pixi_DOT_js$lib$rendering$renderers$shared$GCSystem = function(global, require, module, exports) {
  global = require("module$node_modules$pixi_DOT_js$lib$extensions$Extensions");
  var clean = require("module$node_modules$pixi_DOT_js$lib$utils$data$clean");
  "use strict";
  const node_modules$pixi_DOT_js$lib$rendering$renderers$shared$GCSystem$classdecl$var18 = class {
    constructor(renderer) {
      this._managedResources = [];
      this._managedResourceHashes = [];
      this._managedCollections = [];
      this._ready = !1;
      this._renderer = renderer;
    }
    init(options) {
      options = {...node_modules$pixi_DOT_js$lib$rendering$renderers$shared$GCSystem$classdecl$var18.defaultOptions, ...options};
      this.maxUnusedTime = options.gcMaxUnusedTime;
      this._frequency = options.gcFrequency;
      this.enabled = options.gcActive;
      this.now = performance.now();
    }
    get enabled() {
      return !!this._handler;
    }
    set enabled(value) {
      this.enabled !== value && (value ? (this._handler = this._renderer.scheduler.repeat(() => {
        this._ready = !0;
      }, this._frequency, !1), this._collectionsHandler = this._renderer.scheduler.repeat(() => {
        for (const hash of this._managedCollections) {
          const {context, collection, type} = hash;
          context[collection] = "hash" === type ? clean.cleanHash(context[collection]) : clean.cleanArray(context[collection]);
        }
      }, this._frequency)) : (this._renderer.scheduler.cancel(this._handler), this._renderer.scheduler.cancel(this._collectionsHandler), this._collectionsHandler = this._handler = 0));
    }
    prerender({container}) {
      this.now = performance.now();
      container.renderGroup.gcTick = this._renderer.tick++;
      this._updateInstructionGCTick(container.renderGroup, container.renderGroup.gcTick);
    }
    postrender() {
      this._ready && this.enabled && (this.run(), this._ready = !1);
    }
    _updateInstructionGCTick(renderGroup, gcTick) {
      renderGroup.instructionSet.gcTick = gcTick;
      renderGroup.gcTick = gcTick;
      for (const child of renderGroup.renderGroupChildren) {
        this._updateInstructionGCTick(child, gcTick);
      }
    }
    addCollection(context, collection, type) {
      this._managedCollections.push({context, collection, type});
    }
    addResource(resource, type) {
      -1 !== resource._gcLastUsed ? (resource._gcLastUsed = this.now, resource._onTouch?.(this.now)) : (resource._gcData = {index:this._managedResources.length, type}, resource._gcLastUsed = this.now, resource._onTouch?.(this.now), resource.once("unload", this.removeResource, this), this._managedResources.push(resource));
    }
    removeResource(resource) {
      var gcData = resource._gcData;
      if (gcData) {
        gcData = gcData.index;
        var last = this._managedResources.length - 1;
        gcData !== last && (last = this._managedResources[last], this._managedResources[gcData] = last, last._gcData.index = gcData);
        this._managedResources.length--;
        resource._gcData = null;
        resource._gcLastUsed = -1;
      }
    }
    addResourceHash(context, hash, type, priority = 0) {
      this._managedResourceHashes.push({context, hash, type, priority});
      this._managedResourceHashes.sort((a, b) => a.priority - b.priority);
    }
    run() {
      const now = performance.now();
      var managedResourceHashes = this._managedResourceHashes;
      for (var hashEntry of managedResourceHashes) {
        this.runOnHash(hashEntry, now);
      }
      managedResourceHashes = 0;
      for (hashEntry = 0; hashEntry < this._managedResources.length; hashEntry++) {
        managedResourceHashes = this.runOnResource(this._managedResources[hashEntry], now, managedResourceHashes);
      }
      this._managedResources.length = managedResourceHashes;
    }
    updateRenderableGCTick(renderable, now) {
      const renderGroup = renderable.renderGroup ?? renderable.parentRenderGroup;
      (renderGroup?.gcTick ?? 0) === (renderGroup?.instructionSet?.gcTick ?? -1) && (renderable._gcLastUsed = now, renderable._onTouch?.(now));
    }
    runOnResource(resource, now, writeIndex) {
      const gcData = resource._gcData;
      "renderable" === gcData.type && this.updateRenderableGCTick(resource, now);
      now - resource._gcLastUsed < this.maxUnusedTime || !resource.autoGarbageCollect ? (this._managedResources[writeIndex] = resource, gcData.index = writeIndex, writeIndex++) : (resource.unload(), resource._gcData = null, resource._gcLastUsed = -1, resource.off("unload", this.removeResource, this));
      return writeIndex;
    }
    _createHashClone(hashValue, stopKey) {
      const hashClone = Object.create(null);
      for (const k in hashValue) {
        if (k === stopKey) {
          break;
        }
        null !== hashValue[k] && (hashClone[k] = hashValue[k]);
      }
      return hashClone;
    }
    runOnHash(hashEntry, now) {
      const {context, hash, type} = hashEntry;
      hashEntry = context[hash];
      let hashClone = null, nullCount = 0;
      for (const key in hashEntry) {
        const resource = hashEntry[key];
        if (null === resource) {
          nullCount++, 1e4 !== nullCount || hashClone || (hashClone = this._createHashClone(hashEntry, key));
        } else {
          if (-1 === resource._gcLastUsed) {
            resource._gcLastUsed = now, resource._onTouch?.(now), hashClone && (hashClone[key] = resource);
          } else {
            if ("renderable" === type && this.updateRenderableGCTick(resource, now), now - resource._gcLastUsed < this.maxUnusedTime || !resource.autoGarbageCollect) {
              hashClone && (hashClone[key] = resource);
            } else {
              if ("renderable" === type) {
                var res = resource;
                if (res = res.renderGroup ?? res.parentRenderGroup) {
                  res.structureDidChange = !0;
                }
              }
              resource.unload();
              resource._gcData = null;
              resource._gcLastUsed = -1;
              hashClone || (1e4 !== nullCount + 1 ? (hashEntry[key] = null, nullCount++) : hashClone = this._createHashClone(hashEntry, key));
            }
          }
        }
      }
      hashClone && (context[hash] = hashClone);
    }
    destroy() {
      this.enabled = !1;
      this._managedResources.forEach(resource => {
        resource.off("unload", this.removeResource, this);
      });
      this._managedResources.length = 0;
      this._managedResourceHashes.length = 0;
      this._managedCollections.length = 0;
      this._renderer = null;
    }
  };
  require = node_modules$pixi_DOT_js$lib$rendering$renderers$shared$GCSystem$classdecl$var18;
  require.extension = {type:[global.ExtensionType.WebGLSystem, global.ExtensionType.WebGPUSystem, global.ExtensionType.CanvasSystem], name:"gc", priority:0};
  require.defaultOptions = {gcActive:!0, gcMaxUnusedTime:6e4, gcFrequency:3e4};
  exports.GCSystem = require;
};

//# sourceMappingURL=module$node_modules$pixi_DOT_js$lib$rendering$renderers$shared$GCSystem.js.map
