"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var rect_utils_exports = {};
__export(rect_utils_exports, {
  getOverlayRects: () => getOverlayRects
});
module.exports = __toCommonJS(rect_utils_exports);
const mergeRectsByLine = (list) => {
  const rects = [];
  for (let i = 0; i < list.length; i++) {
    rects.push(list[i]);
  }
  const out = [];
  const sortedRects = rects.sort((a, b) => a.top - b.top || a.left - b.left);
  let line = null;
  for (const rect of sortedRects) {
    const centerY = rect.top + rect.height / 2;
    if (!line || centerY < line.top || centerY > line.bottom) {
      if (line) {
        out.push(new DOMRect(line.left, line.top, line.right - line.left, line.bottom - line.top));
      }
      line = { left: rect.left, top: rect.top, right: rect.right, bottom: rect.bottom };
      continue;
    }
    line.left = Math.min(line.left, rect.left);
    line.top = Math.min(line.top, rect.top);
    line.right = Math.max(line.right, rect.right);
    line.bottom = Math.max(line.bottom, rect.bottom);
  }
  if (line) {
    out.push(new DOMRect(line.left, line.top, line.right - line.left, line.bottom - line.top));
  }
  return out;
};
const mergeRectsToBoundingRect = (list) => {
  if (list.length === 0) {
    return [];
  }
  let left = Infinity;
  let top = Infinity;
  let right = -Infinity;
  let bottom = -Infinity;
  for (let i = 0; i < list.length; i++) {
    const rect = list[i];
    left = Math.min(left, rect.left);
    top = Math.min(top, rect.top);
    right = Math.max(right, rect.right);
    bottom = Math.max(bottom, rect.bottom);
  }
  return [new DOMRect(left, top, right - left, bottom - top)];
};
const getOverlayRects = (style, list) => {
  if (style === "BOX" || style === "CIRCLE") {
    return mergeRectsToBoundingRect(list);
  }
  return mergeRectsByLine(list);
};
//# sourceMappingURL=rect-utils.js.map
