"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 find_node_closest_to_selection_exports = {};
__export(find_node_closest_to_selection_exports, {
  findNodeClosestToSelection: () => findNodeClosestToSelection
});
module.exports = __toCommonJS(find_node_closest_to_selection_exports);
var import_core = require("./../../tiptap/core/index.js");
const findNodeClosestToSelection = (editor, nodeType) => {
  const { selection } = editor.state;
  const startNodePos = new import_core.NodePos(selection.$from, editor);
  const startNode = startNodePos.closest(nodeType);
  if (!startNode?.pos) {
    return null;
  }
  const isRangeSelection = selection.$from.pos !== selection.$to.pos;
  if (!isRangeSelection) {
    return startNode;
  }
  const endNodePos = new import_core.NodePos(selection.$to, editor);
  const endNode = endNodePos.closest(nodeType);
  if (!endNode?.pos || endNode.pos !== startNode.pos) {
    return null;
  }
  return startNode;
};
//# sourceMappingURL=find-node-closest-to-selection.js.map
