shadow$provide.module$node_modules$pixi_DOT_js$lib$utils$canvas$getCanvasBoundingBox = function(global, require, module, exports) {
  function checkRow(data, width, y) {
    for (let x = 0, index = 4 * y * width; x < width; ++x, index += 4) {
      if (0 !== data[index + 3]) {
        return !1;
      }
    }
    return !0;
  }
  function checkColumn(data, width, x, top, bottom) {
    width *= 4;
    for (let y = top, index = top * width + 4 * x; y <= bottom; ++y, index += width) {
      if (0 !== data[index + 3]) {
        return !1;
      }
    }
    return !0;
  }
  var adapter = require("module$node_modules$pixi_DOT_js$lib$environment$adapter"), pow2 = require("module$node_modules$pixi_DOT_js$lib$maths$misc$pow2"), Rectangle = require("module$node_modules$pixi_DOT_js$lib$maths$shapes$Rectangle");
  "use strict";
  let _internalCanvas = null, _internalContext = null;
  exports.getCanvasBoundingBox = function(...args) {
    var options = args[0];
    options.canvas || (options = {canvas:args[0], resolution:args[1]});
    var {canvas} = options;
    args = Math.min(options.resolution ?? 1, 1);
    const width = options.width ?? canvas.width, height = options.height ?? canvas.height;
    options = options.output;
    _internalCanvas || (_internalCanvas = adapter.DOMAdapter.get().createCanvas(256, 128), _internalContext = _internalCanvas.getContext("2d", {willReadFrequently:!0}), _internalContext.globalCompositeOperation = "copy", _internalContext.globalAlpha = 1);
    if (_internalCanvas.width < width || _internalCanvas.height < height) {
      _internalCanvas.width = pow2.nextPow2(width), _internalCanvas.height = pow2.nextPow2(height);
    }
    if (!_internalContext) {
      throw new TypeError("Failed to get canvas 2D context");
    }
    _internalContext.drawImage(canvas, 0, 0, width, height, 0, 0, width * args, height * args);
    canvas = _internalContext.getImageData(0, 0, width, height).data;
    let left = 0, top = 0, right = width - 1, bottom = height - 1;
    for (; top < height && checkRow(canvas, width, top);) {
      ++top;
    }
    if (top === height) {
      return Rectangle.Rectangle.EMPTY;
    }
    for (; checkRow(canvas, width, bottom);) {
      --bottom;
    }
    for (; checkColumn(canvas, width, left, top, bottom);) {
      ++left;
    }
    for (; checkColumn(canvas, width, right, top, bottom);) {
      --right;
    }
    ++right;
    ++bottom;
    _internalContext.globalCompositeOperation = "source-over";
    _internalContext.strokeRect(left, top, right - left, bottom - top);
    _internalContext.globalCompositeOperation = "copy";
    options ?? (options = new Rectangle.Rectangle());
    options.set(left / args, top / args, (right - left) / args, (bottom - top) / args);
    return options;
  };
};

//# sourceMappingURL=module$node_modules$pixi_DOT_js$lib$utils$canvas$getCanvasBoundingBox.js.map
