"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_selection_as_html_exports = {};
__export(get_selection_as_html_exports, {
  getSelectionAsHTML: () => getSelectionAsHTML
});
module.exports = __toCommonJS(get_selection_as_html_exports);
var import_model = require("./../../tiptap/pm/model.js");
const getSelectionAsHTML = (editor) => {
  const {
    state: {
      doc,
      selection: { from, to, $from, $to }
    }
  } = editor;
  const schema = editor.schema;
  const fragment = $from.sameParent($to) ? $from.parent.cut($from.parentOffset, $to.parentOffset).toJSON() : doc.cut(from, to).toJSON();
  const contentNode = import_model.Node.fromJSON(schema, fragment);
  return getHTMLFromFragment(contentNode.content, schema);
};
function getHTMLFromFragment(fragment, schema) {
  const documentFragment = import_model.DOMSerializer.fromSchema(schema).serializeFragment(fragment);
  const temporaryDocument = document.implementation.createHTMLDocument();
  const container = temporaryDocument.createElement("div");
  container.appendChild(documentFragment);
  removeAllAttributes(container);
  return container.innerHTML;
}
function removeAllAttributes(node) {
  if (node instanceof Element && node.attributes) {
    while (node.attributes.length > 0) {
      node.removeAttribute(node.attributes[0].name);
    }
  }
  for (let i = 0; i < node.childNodes.length; i++) {
    removeAllAttributes(node.childNodes[i]);
  }
}
//# sourceMappingURL=get-selection-as-html.js.map
