shadow$provide.module$node_modules$pixi_DOT_js$lib$filters$CanvasFilterSystem = function(global, require, module, exports) {
  function isCanvasFilterCapable(filter) {
    return "function" === typeof filter.getCanvasFilterString;
  }
  global = require("module$node_modules$pixi_DOT_js$lib$extensions$Extensions");
  var canvasUtils = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$canvas$utils$canvasUtils"), CanvasPool = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$shared$texture$CanvasPool"), Bounds = require("module$node_modules$pixi_DOT_js$lib$scene$container$bounds$Bounds"), getRenderableBounds = require("module$node_modules$pixi_DOT_js$lib$scene$container$bounds$getRenderableBounds"), getPo2TextureFromSource = require("module$node_modules$pixi_DOT_js$lib$scene$text$utils$getPo2TextureFromSource");
  "use strict";
  class CanvasFilterFrame {
    constructor() {
      this.useClip = this.skip = !1;
      this.container = this.filters = null;
      this.bounds = new Bounds.Bounds();
      this.cssFilterString = "";
    }
  }
  class CanvasFilterSystem {
    constructor(renderer) {
      this._filterStack = [];
      this._filterStackIndex = 0;
      this._savedStates = [];
      this._alphaMultiplier = 1;
      this._warnedFilterTypes = new Set();
      this.renderer = renderer;
    }
    push(instruction) {
      const filterFrame = this._pushFilterFrame();
      var filters = instruction.filterEffect.filters;
      filterFrame.skip = !1;
      filterFrame.useClip = !1;
      filterFrame.filters = filters;
      filterFrame.container = instruction.container;
      filterFrame.cssFilterString = "";
      if (filters.every(filter => !filter.enabled)) {
        filterFrame.skip = !0;
      } else {
        var cssFilters = [];
        for (var filter of filters) {
          filter.enabled && (isCanvasFilterCapable(filter) ? (filters = filter.getCanvasFilterString(), null === filters ? this._warnUnsupportedFilter(filter) : filters && cssFilters.push(filters)) : this._warnUnsupportedFilter(filter));
        }
        0 === cssFilters.length ? filterFrame.skip = !0 : (filterFrame.cssFilterString = cssFilters.join(" "), this._calculateFilterArea(instruction, filterFrame.bounds), filterFrame.useClip = !!instruction.filterEffect.filterArea, instruction = this.renderer.canvasContext.activeContext, cssFilters = instruction.filter || "none", this._savedStates.push({filter:cssFilters, alphaMultiplier:this._alphaMultiplier}), filterFrame.useClip && Number.isFinite(filterFrame.bounds.width) && Number.isFinite(filterFrame.bounds.height) && 
        0 < filterFrame.bounds.width && 0 < filterFrame.bounds.height ? (filter = this.renderer.canvasContext.activeResolution || 1, instruction.save(), instruction.setTransform(1, 0, 0, 1, 0, 0), instruction.beginPath(), instruction.rect(filterFrame.bounds.x * filter, filterFrame.bounds.y * filter, filterFrame.bounds.width * filter, filterFrame.bounds.height * filter), instruction.clip()) : filterFrame.useClip = !1, filterFrame.cssFilterString && (instruction.filter = "none" !== cssFilters ? `${cssFilters} ${filterFrame.cssFilterString}` : 
        filterFrame.cssFilterString));
      }
    }
    pop() {
      const filterFrame = this._popFilterFrame();
      if (!filterFrame.skip) {
        var savedState = this._savedStates.pop();
        if (savedState) {
          var context = this.renderer.canvasContext.activeContext;
          filterFrame.useClip ? context.restore() : context.filter = savedState.filter;
          this._alphaMultiplier = savedState.alphaMultiplier;
        }
      }
    }
    generateFilteredTexture({texture, filters}) {
      if (!filters?.length || filters.every(filter => !filter.enabled)) {
        return texture;
      }
      var cssFilters = [];
      for (var filter of filters) {
        filter.enabled && (isCanvasFilterCapable(filter) ? (filters = filter.getCanvasFilterString(), null === filters ? this._warnUnsupportedFilter(filter) : filters && cssFilters.push(filters)) : this._warnUnsupportedFilter(filter));
      }
      if (0 === cssFilters.length) {
        return texture;
      }
      filter = canvasUtils.canvasUtils.getCanvasSource(texture);
      if (!filter) {
        return texture;
      }
      filters = texture.frame;
      texture = texture.source._resolution ?? texture.source.resolution ?? 1;
      const width = filters.width, height = filters.height;
      var canvasAndContext = CanvasPool.CanvasPool.getOptimalCanvasAndContext(width, height, texture);
      const {canvas, context} = canvasAndContext;
      context.setTransform(1, 0, 0, 1, 0, 0);
      context.clearRect(0, 0, canvas.width, canvas.height);
      cssFilters.length && (context.filter = cssFilters.join(" "));
      cssFilters = width * texture;
      canvasAndContext = height * texture;
      context.drawImage(filter, filters.x * texture, filters.y * texture, cssFilters, canvasAndContext, 0, 0, cssFilters, canvasAndContext);
      context.filter = "none";
      context.globalAlpha = 1;
      return getPo2TextureFromSource.getPo2TextureFromSource(canvas, width, height, texture);
    }
    _calculateFilterArea(instruction, bounds) {
      instruction.renderables ? getRenderableBounds.getGlobalRenderableBounds(instruction.renderables, bounds) : instruction.filterEffect.filterArea ? (bounds.clear(), bounds.addRect(instruction.filterEffect.filterArea), bounds.applyMatrix(instruction.container.worldTransform)) : instruction.container.getFastGlobalBounds(!0, bounds);
      instruction.container && (instruction = (instruction.container.renderGroup || instruction.container.parentRenderGroup)?.cacheToLocalTransform) && bounds.applyMatrix(instruction);
    }
    _warnUnsupportedFilter(filter) {
      filter = filter?.constructor?.name || "Filter";
      this._warnedFilterTypes.has(filter) || (this._warnedFilterTypes.add(filter), console.warn(`CanvasRenderer: filter "${filter}" is not supported in Canvas2D and will be skipped.`));
    }
    get alphaMultiplier() {
      return this._alphaMultiplier;
    }
    _pushFilterFrame() {
      let filterFrame = this._filterStack[this._filterStackIndex];
      filterFrame || (filterFrame = this._filterStack[this._filterStackIndex] = new CanvasFilterFrame());
      this._filterStackIndex++;
      return filterFrame;
    }
    _popFilterFrame() {
      if (0 >= this._filterStackIndex) {
        return this._filterStack[0];
      }
      this._filterStackIndex--;
      return this._filterStack[this._filterStackIndex];
    }
    destroy() {
      this._warnedFilterTypes = this._savedStates = this._filterStack = null;
      this._alphaMultiplier = 1;
    }
  }
  CanvasFilterSystem.extension = {type:[global.ExtensionType.CanvasSystem], name:"filter"};
  exports.CanvasFilterSystem = CanvasFilterSystem;
  exports.isCanvasFilterCapable = isCanvasFilterCapable;
};

//# sourceMappingURL=module$node_modules$pixi_DOT_js$lib$filters$CanvasFilterSystem.js.map
