"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 editor_rects_exports = {};
__export(editor_rects_exports, {
  buildRangesRects: () => buildRangesRects,
  collectRangeRects: () => collectRangeRects
});
module.exports = __toCommonJS(editor_rects_exports);
var import_rect_utils = require("./rect-utils.js");
const isNonEmptyRect = (rect) => rect.width > 0 || rect.height > 0;
const collectRangeRects = (view, from, to) => {
  try {
    const start = view.domAtPos(from, 1);
    const end = view.domAtPos(to, -1);
    const range = document.createRange();
    range.setStart(start.node, start.offset);
    range.setEnd(end.node, end.offset);
    return Array.from(range.getClientRects()).filter(isNonEmptyRect);
  } catch {
    return null;
  }
};
const buildRangesRects = (view, ranges, style) => {
  const rects = [];
  for (const range of ranges) {
    const rangeRects = collectRangeRects(view, range.from, range.to);
    if (!rangeRects) {
      return null;
    }
    rects.push(...rangeRects);
  }
  if (rects.length === 0) {
    return null;
  }
  return (0, import_rect_utils.getOverlayRects)(style, rects);
};
//# sourceMappingURL=editor-rects.js.map
