import { EmbedBlot as o } from "../../../../parchment@3.0.0/node_modules/parchment/dist/parchment.mjs";
import a from "./text.mjs";
const i = "\uFEFF";
class c extends o {
  constructor(e, r) {
    super(e, r), this.contentNode = document.createElement("span"), this.contentNode.setAttribute("contenteditable", "false"), Array.from(this.domNode.childNodes).forEach((t) => {
      this.contentNode.appendChild(t);
    }), this.leftGuard = document.createTextNode(i), this.rightGuard = document.createTextNode(i), this.domNode.appendChild(this.leftGuard), this.domNode.appendChild(this.contentNode), this.domNode.appendChild(this.rightGuard);
  }
  index(e, r) {
    return e === this.leftGuard ? 0 : e === this.rightGuard ? 1 : super.index(e, r);
  }
  restore(e) {
    let r = null, t;
    const s = e.data.split(i).join("");
    if (e === this.leftGuard)
      if (this.prev instanceof a) {
        const d = this.prev.length();
        this.prev.insertAt(d, s), r = {
          startNode: this.prev.domNode,
          startOffset: d + s.length
        };
      } else
        t = document.createTextNode(s), this.parent.insertBefore(this.scroll.create(t), this), r = {
          startNode: t,
          startOffset: s.length
        };
    else
      e === this.rightGuard && (this.next instanceof a ? (this.next.insertAt(0, s), r = {
        startNode: this.next.domNode,
        startOffset: s.length
      }) : (t = document.createTextNode(s), this.parent.insertBefore(this.scroll.create(t), this.next), r = {
        startNode: t,
        startOffset: s.length
      }));
    return e.data = i, r;
  }
  update(e, r) {
    e.forEach((t) => {
      if (t.type === "characterData" && (t.target === this.leftGuard || t.target === this.rightGuard)) {
        const s = this.restore(t.target);
        s && (r.range = s);
      }
    });
  }
}
export {
  c as default
};
