"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));

/** 在表格的单元格的渲染过程中，先渲染的单元格的 colSpan/rowSpan 会影响到后续单元格是否被渲染
 * `SpanManager` 会在内部维护一份状态来记录最近渲染单元格的 colSpan/rowSpan，
 * 方便后续的单元格快速判断 "是否需要跳过渲染" */
var SpanManager = /*#__PURE__*/function () {
  function SpanManager() {
    (0, _classCallCheck2.default)(this, SpanManager);
    this.rects = [];
  }

  (0, _createClass2.default)(SpanManager, [{
    key: "testSkip",
    value: function testSkip(rowIndex, colIndex) {
      return this.rects.some(function (_ref) {
        var left = _ref.left,
            right = _ref.right,
            top = _ref.top,
            bottom = _ref.bottom;
        return left <= colIndex && colIndex < right && top <= rowIndex && rowIndex < bottom;
      });
    }
  }, {
    key: "stripUpwards",
    value: function stripUpwards(rowIndex) {
      var _context;

      this.rects = (0, _filter.default)(_context = this.rects).call(_context, function (rect) {
        return rect.bottom > rowIndex;
      });
    }
  }, {
    key: "add",
    value: function add(rowIndex, colIndex, colSpan, rowSpan) {
      this.rects.push({
        left: colIndex,
        right: colIndex + (colSpan < 1 ? 1 : colSpan),
        top: rowIndex,
        bottom: rowIndex + rowSpan
      });
    }
  }]);
  return SpanManager;
}();

exports.default = SpanManager;