"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 pos_to_dom_rect_exports = {};
__export(pos_to_dom_rect_exports, {
  getFakeReferenceElement: () => getFakeReferenceElement,
  posToDOMRect: () => posToDOMRect
});
module.exports = __toCommonJS(pos_to_dom_rect_exports);
var import_tiptap = require("./../tiptap/index.js");
const posToDOMRect = (view, from, to) => {
  const rootLevelNodePosition = view.state.selection.$from.before(1);
  const nodeDOM = view.nodeDOM(rootLevelNodePosition);
  const referenceElement = nodeDOM instanceof Element ? nodeDOM : view.dom;
  const editorRect = referenceElement.getBoundingClientRect();
  const minPos = 0;
  const maxPos = view.state.doc.content.size;
  const resolvedFrom = (0, import_tiptap.minMax)(from, minPos, maxPos);
  const resolvedEnd = (0, import_tiptap.minMax)(to, minPos, maxPos);
  const start = view.coordsAtPos(resolvedFrom);
  const end = view.coordsAtPos(resolvedEnd, -1);
  const top = Math.min(start.top, end.top);
  const bottom = Math.max(start.bottom, end.bottom);
  const left = editorRect.left;
  const right = editorRect.right;
  const width = right - left;
  const height = bottom - top;
  const x = left;
  const y = top;
  const data = {
    top,
    bottom,
    left,
    right,
    width,
    height,
    x,
    y
  };
  return {
    ...data,
    toJSON: () => data
  };
};
const getFakeReferenceElement = (editor) => {
  const { view } = editor;
  const { from, to } = view.state.selection;
  return {
    getBoundingClientRect: () => posToDOMRect(view, from, to),
    focus: () => view.focus()
  };
};
//# sourceMappingURL=pos-to-dom-rect.js.map
