var A = Object.defineProperty;
var b = (s, r, t) => r in s ? A(s, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[r] = t;
var p = (s, r, t) => (b(s, typeof r != "symbol" ? r + "" : r, t), t);
import { EmbedBlot as d, Scope as f, BlockBlot as k, AttributorStore as C, LeafBlot as E } from "../../../../parchment@3.0.0/node_modules/parchment/dist/parchment.mjs";
import B from "../../../../quill-delta@5.1.0/node_modules/quill-delta/dist/Delta.mjs";
import m from "./break.mjs";
import L from "./inline.mjs";
import N from "./text.mjs";
const g = 1;
class o extends k {
  constructor() {
    super(...arguments);
    p(this, "cache", {});
  }
  delta() {
    return this.cache.delta == null && (this.cache.delta = v(this)), this.cache.delta;
  }
  deleteAt(t, e) {
    super.deleteAt(t, e), this.cache = {};
  }
  formatAt(t, e, i, n) {
    e <= 0 || (this.scroll.query(i, f.BLOCK) ? t + e === this.length() && this.format(i, n) : super.formatAt(t, Math.min(e, this.length() - t - 1), i, n), this.cache = {});
  }
  insertAt(t, e, i) {
    if (i != null) {
      super.insertAt(t, e, i), this.cache = {};
      return;
    }
    if (e.length === 0)
      return;
    const n = e.split(`
`), h = n.shift();
    h.length > 0 && (t < this.length() - 1 || this.children.tail == null ? super.insertAt(Math.min(t, this.length() - 1), h) : this.children.tail.insertAt(this.children.tail.length(), h), this.cache = {});
    let l = this;
    n.reduce((a, c) => (l = l.split(a, !0), l.insertAt(0, c), c.length), t + h.length);
  }
  insertBefore(t, e) {
    const {
      head: i
    } = this.children;
    super.insertBefore(t, e), i instanceof m && i.remove(), this.cache = {};
  }
  length() {
    return this.cache.length == null && (this.cache.length = super.length() + g), this.cache.length;
  }
  moveChildren(t, e) {
    super.moveChildren(t, e), this.cache = {};
  }
  optimize(t) {
    super.optimize(t), this.cache = {};
  }
  path(t) {
    return super.path(t, !0);
  }
  removeChild(t) {
    super.removeChild(t), this.cache = {};
  }
  split(t) {
    let e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !1;
    if (e && (t === 0 || t >= this.length() - g)) {
      const n = this.clone();
      return t === 0 ? (this.parent.insertBefore(n, this), this) : (this.parent.insertBefore(n, this.next), n);
    }
    const i = super.split(t, e);
    return this.cache = {}, i;
  }
}
o.blotName = "block";
o.tagName = "P";
o.defaultChild = m;
o.allowedChildren = [m, L, d, N];
class T extends d {
  attach() {
    super.attach(), this.attributes = new C(this.domNode);
  }
  delta() {
    return new B().insert(this.value(), {
      ...this.formats(),
      ...this.attributes.values()
    });
  }
  format(r, t) {
    const e = this.scroll.query(r, f.BLOCK_ATTRIBUTE);
    e != null && this.attributes.attribute(e, t);
  }
  formatAt(r, t, e, i) {
    this.format(e, i);
  }
  insertAt(r, t, e) {
    if (e != null) {
      super.insertAt(r, t, e);
      return;
    }
    const i = t.split(`
`), n = i.pop(), h = i.map((a) => {
      const c = this.scroll.create(o.blotName);
      return c.insertAt(0, a), c;
    }), l = this.split(r);
    h.forEach((a) => {
      this.parent.insertBefore(a, l);
    }), n && this.parent.insertBefore(this.scroll.create("text", n), l);
  }
}
T.scope = f.BLOCK_BLOT;
function v(s) {
  let r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !0;
  return s.descendants(E).reduce((t, e) => e.length() === 0 ? t : t.insert(e.value(), u(e, {}, r)), new B()).insert(`
`, u(s));
}
function u(s) {
  let r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, t = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : !0;
  return s == null || ("formats" in s && typeof s.formats == "function" && (r = {
    ...r,
    ...s.formats()
  }, t && delete r["code-token"]), s.parent == null || s.parent.statics.blotName === "scroll" || s.parent.statics.scope !== s.statics.scope) ? r : u(s.parent, r, t);
}
export {
  T as BlockEmbed,
  v as blockDelta,
  u as bubbleFormats,
  o as default
};
