"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 get_dom_at_pos_or_parent_exports = {};
__export(get_dom_at_pos_or_parent_exports, {
  getDomAtPosOrParent: () => getDomAtPosOrParent
});
module.exports = __toCommonJS(get_dom_at_pos_or_parent_exports);
var import_helpers = require("./../../tiptap/helpers/index.js");
const getDomAtPosOrParent = (doc, view, from) => {
  try {
    const domAtCurrentPos = view.nodeDOM(from);
    let element;
    if (domAtCurrentPos) {
      element = domAtCurrentPos;
    } else {
      try {
        const { node } = view.domAtPos(from);
        element = node instanceof HTMLElement ? node : node.parentElement;
      } catch {
      }
      if (!element) {
        const parent = doc.resolve(from).parent;
        const parentNodeWithPos = (0, import_helpers.findChildren)(doc, (node) => node.attrs.id === parent.attrs.id)[0];
        if (parentNodeWithPos) {
          element = view.nodeDOM(parentNodeWithPos.pos);
        }
      }
    }
    if (!element) {
      return void 0;
    }
    const elementToReturn = element.nodeType === Node.TEXT_NODE ? element.parentElement : element;
    return elementToReturn ?? void 0;
  } catch (e) {
    console.error("Failed to get parent node:", e);
    return void 0;
  }
};
//# sourceMappingURL=get-dom-at-pos-or-parent.js.map
