var w = Object.defineProperty;
var M = (h, i, t) => i in h ? w(h, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : h[i] = t;
var n = (h, i, t) => M(h, typeof i != "symbol" ? i + "" : i, t);
import { S as f, c as C, Q as D, R as q, j as F, A as N } from "./index-U54PFR25.js";
const g = {
  OVERLAY: "ql-image-resizer-overlay",
  HANDLE: "ql-image-resizer-handle",
  DISPLAY: "ql-image-resizer-display",
  TOOLBAR: "ql-image-resizer-toolbar",
  TOOLBAR_BUTTON: "ql-image-resizer-toolbar-button"
}, d = {
  BACKSPACE: 8,
  DELETE: 46,
  LEFT: 37,
  UP: 38,
  RIGHT: 39,
  DOWN: 40
};
function R(h) {
  switch (h.key) {
    case "Backspace":
      return d.BACKSPACE;
    case "Delete":
      return d.DELETE;
    case "ArrowLeft":
      return d.LEFT;
    case "ArrowUp":
      return d.UP;
    case "ArrowRight":
      return d.RIGHT;
    case "ArrowDown":
      return d.DOWN;
    default:
      return 0;
  }
}
const B = ["tl", "tr", "br", "bl"], k = 8;
function z(h) {
  var t;
  const i = new Uint32Array(h);
  if (typeof ((t = globalThis.crypto) == null ? void 0 : t.getRandomValues) == "function")
    globalThis.crypto.getRandomValues(i);
  else {
    let e = Date.now();
    for (let s = 0; s < h; s++)
      e = e * 1103515245 + 12345 & 2147483647, i[s] = e;
  }
  return Array.from(i, (e) => e % 62).join("");
}
const v = (h, i) => {
  const t = h ? "top" : "bottom", e = i ? "left" : "right", s = h === i ? "nwse-resize" : "nesw-resize";
  return {
    [t]: "-5px",
    [e]: "-5px",
    cursor: s
  };
}, I = {
  tl: v(!0, !0),
  tr: v(!0, !1),
  bl: v(!1, !0),
  br: v(!1, !1)
}, O = /* @__PURE__ */ new Map(), L = globalThis;
function U(h) {
  const i = O.get(h);
  if (i) return i;
  const t = q.renderToString(/* @__PURE__ */ F.jsx(N, { icon: h, size: "xs" }));
  return O.set(h, t), t;
}
const j = {
  modules: ["DisplaySize", "Toolbar", "Resize", "Keyboard"],
  embedTags: ["VIDEO", "IFRAME"],
  tools: ["left", "center", "right", "justify"],
  contentOptions: [{
    attribute: ["width"],
    limit: {
      minWidth: 100
    },
    blotName: "image"
  }, {
    attribute: ["width", "height"],
    limit: {
      minWidth: 200,
      ratio: 0.5625
    },
    blotName: "video"
  }]
}, H = D.import("formats/image");
class E extends H {
  static get ATTRIBUTES() {
    return ["alt", "height", "width", "class", "style", "data-align"];
  }
  static formats(i) {
    return this.ATTRIBUTES.reduce((t, e) => (i.hasAttribute(e) && (t[e] = i.getAttribute(e) ?? ""), t), {});
  }
  format(i, t) {
    this.constructor.ATTRIBUTES.includes(i) ? t ? this.domNode.setAttribute(i, t) : this.domNode.removeAttribute(i) : super.format(i, t);
  }
}
n(E, "blotName", "image"), n(E, "tagName", "img"), n(E, "scope", C.INLINE);
function W() {
  L.__AEDITOR_IMAGE_BLOT_REGISTERED__ || (D.register("formats/image", E, !0), L.__AEDITOR_IMAGE_BLOT_REGISTERED__ = !0);
}
class y {
  constructor(i) {
    n(this, "resizer");
    n(this, "quill");
    n(this, "overlay");
    n(this, "activeEle");
    n(this, "blot");
    n(this, "options");
    n(this, "requestUpdate");
    this.resizer = i, this.quill = i.quill, this.overlay = i.overlay, this.activeEle = i.activeEle, this.blot = i.blot, this.options = i.options, this.requestUpdate = () => i.scheduleUpdate(!0);
  }
  onCreate() {
  }
  onDestroy() {
  }
  onUpdate() {
  }
}
class _ extends y {
  constructor() {
    super(...arguments);
    n(this, "display");
  }
  onCreate() {
    var t;
    this.display = document.createElement("div"), this.display.className = f[g.DISPLAY], (t = this.overlay) == null || t.appendChild(this.display);
  }
  onUpdate() {
    if (!this.display || !this.activeEle) return;
    const [t, e] = [this.activeEle.offsetWidth, this.activeEle.offsetHeight];
    this.display.textContent = `${t} × ${e}`, this.positionDisplay(t, e);
  }
  positionDisplay(t, e) {
    var m;
    if (!this.display) return;
    const s = this.display.getBoundingClientRect(), o = t > 120 && e > 30, l = ((m = this.activeEle) == null ? void 0 : m.style.float) === "right";
    let r, a, c;
    o ? (r = "4px", a = "4px", c = "auto") : (a = `-${s.height + 4}px`, l ? (r = "auto", c = `-${s.width + 4}px`) : (r = `-${s.width + 4}px`, c = "auto")), Object.assign(this.display.style, {
      right: r,
      bottom: a,
      left: c
    });
  }
}
class $ extends y {
  constructor() {
    super(...arguments);
    n(this, "boxes", []);
    n(this, "dragBox", null);
    n(this, "dragStartX", 0);
    n(this, "dragStartY", 0);
    n(this, "contentOption");
    n(this, "preDragSize", {
      width: 0,
      height: 0
    });
    n(this, "naturalSize", [0, 0]);
    n(this, "handleDragProxy", null);
    n(this, "handleMouseupProxy", null);
    n(this, "dragAnimationFrame", null);
    n(this, "pendingDragEvent", null);
    n(this, "handleMousedown", (t) => {
      t.button !== 0 || !this.blot || !this.activeEle || (t.preventDefault(), t.stopPropagation(), this.cancelDragFrame(), this.removeEventListeners(), this.dragBox = t.target, this.dragStartX = t.clientX, this.dragStartY = t.clientY, this.preDragSize = {
        width: this.activeEle.offsetWidth,
        height: this.activeEle.offsetHeight
      }, this.naturalSize = this.getNaturalSize(), this.setCursor(globalThis.getComputedStyle(this.dragBox).cursor), this.handleDragProxy = this.handleDrag, this.handleMouseupProxy = this.handleMouseup, document.addEventListener("mousemove", this.handleDragProxy, !0), document.addEventListener("mouseup", this.handleMouseupProxy, !0));
    });
    n(this, "handleMouseup", (t) => {
      if (!this.activeEle || !this.blot || !this.contentOption) return;
      this.cancelDragFrame();
      const e = this.calcSize(t, this.contentOption.limit);
      Object.assign(this.activeEle, e), Object.assign(this.activeEle.style, {
        width: null,
        height: null
      }), this.setCursor(""), this.removeEventListeners();
    });
    n(this, "handleDrag", (t) => {
      !this.activeEle || !this.blot || !this.contentOption || (t.preventDefault(), this.pendingDragEvent = t, this.dragAnimationFrame === null && (this.dragAnimationFrame = requestAnimationFrame(() => {
        this.dragAnimationFrame = null;
        const e = this.pendingDragEvent;
        this.pendingDragEvent = null, !(!e || !this.activeEle || !this.contentOption) && (Object.assign(this.activeEle.style, this.calcSize(e, {
          ...this.contentOption.limit,
          unit: !0
        })), this.requestUpdate());
      })));
    });
    n(this, "handleDoubleClick", (t) => {
      if (!this.blot || !this.activeEle || !this.contentOption) return;
      t.stopPropagation();
      const [e, s] = this.naturalSize, o = {};
      this.contentOption.attribute.includes("width") && (o.width = e), this.contentOption.attribute.includes("height") && (o.height = s);
      const l = this.applyConstraints(o, this.contentOption.limit);
      Object.assign(this.activeEle, l), this.requestUpdate();
    });
  }
  onCreate() {
    !this.blot || !this.options.contentOptions || (this.contentOption = this.options.contentOptions.find((t) => t.blotName === this.blot.statics.blotName), this.boxes = [], B.forEach((t) => this.addBox(t)));
  }
  onDestroy() {
    this.setCursor(""), this.cancelDragFrame(), this.removeEventListeners(), this.boxes.forEach((t) => {
      t.removeEventListener("mousedown", this.handleMousedown, !1), t.removeEventListener("dblclick", this.handleDoubleClick, !1);
    }), this.boxes = [];
  }
  addBox(t) {
    var s;
    const e = document.createElement("div");
    e.className = `${f[g.HANDLE]} ${t}`, e.addEventListener("mousedown", this.handleMousedown, !1), e.addEventListener("dblclick", this.handleDoubleClick, !1), Object.assign(e.style, I[t]), (s = this.overlay) == null || s.appendChild(e), this.boxes.push(e);
  }
  removeEventListeners() {
    this.handleDragProxy && (document.removeEventListener("mousemove", this.handleDragProxy, !0), this.handleDragProxy = null), this.handleMouseupProxy && (document.removeEventListener("mouseup", this.handleMouseupProxy, !0), this.handleMouseupProxy = null);
  }
  calcSize(t, e = {}) {
    var a;
    if (!this.dragBox || !this.activeEle) return {};
    const s = t.clientX - this.dragStartX, o = t.clientY - this.dragStartY, l = this.dragBox === this.boxes[0] || this.dragBox === this.boxes[3] ? -1 : 1, r = {};
    return (a = this.contentOption) != null && a.attribute ? this.contentOption.attribute.forEach((c) => r[c] = this.preDragSize[c]) : r.width = this.preDragSize.width, r.width && (r.width = Math.round(this.preDragSize.width + s * l)), r.height && (r.height = Math.round(this.preDragSize.height + o * l)), this.applyConstraints(r, e);
  }
  constrainDimensionsWithRatio(t, e) {
    const s = e.ratio;
    let o = this.applyLimit(t, e.minWidth, e.maxWidth), l = o * s;
    const r = this.applyLimit(l, e.minHeight, e.maxHeight);
    return r !== l && (l = r, o = l / s), {
      rw: o,
      rh: l
    };
  }
  applyConstraints(t, e = {}) {
    const s = typeof t.width == "string" ? Number.parseInt(t.width, 10) : t.width || 0, o = typeof t.height == "string" ? Number.parseInt(t.height, 10) : t.height || 0;
    let l = s, r = o;
    e.ratio ? {
      rw: l,
      rh: r
    } = this.constrainDimensionsWithRatio(l, e) : (s && (l = this.applyLimit(l, e.minWidth, e.maxWidth)), o && (r = this.applyLimit(r, e.minHeight, e.maxHeight)));
    const a = {};
    return t.width !== void 0 && (a.width = e.unit ? `${l}px` : l), t.height !== void 0 && (a.height = e.unit ? `${r}px` : r), a;
  }
  applyLimit(t, e, s) {
    let o = t;
    return e !== void 0 && (o = Math.max(e, o)), s !== void 0 && (o = Math.min(s, o)), o;
  }
  getNaturalSize() {
    if (!this.activeEle) return [0, 0];
    const t = this.activeEle.dataset.size;
    if (!t) {
      const e = this.activeEle, s = [e.offsetWidth, e.offsetHeight];
      return e.dataset.size = s.join(","), s;
    }
    return t.split(",").map(Number);
  }
  setCursor(t) {
    [document.body, this.activeEle].forEach((e) => e && (e.style.cursor = t));
  }
  cancelDragFrame() {
    this.dragAnimationFrame !== null && (cancelAnimationFrame(this.dragAnimationFrame), this.dragAnimationFrame = null), this.pendingDragEvent = null;
  }
}
const u = class u extends y {
  constructor() {
    super(...arguments);
    n(this, "keyboardProxy", (t) => this.keyboardHandle(t));
  }
  static injectInit(t) {
    var s;
    if (u.injectedQuills.has(t)) return;
    const e = (s = t.keyboard) == null ? void 0 : s.bindings;
    e && ([u.keys.LEFT, u.keys.RIGHT].forEach((o) => (e[o] || []).unshift(u.makeArrowHandler(o))), u.injectedQuills.add(t));
  }
  static makeArrowHandler(t) {
    const e = t === u.keys.LEFT;
    return {
      key: t,
      shiftKey: !1,
      altKey: null,
      [e ? "prefix" : "suffix"]: /^$/,
      handler(s) {
        const o = this.quill;
        if (!o.resizer) return !0;
        let l = s.index;
        const r = t === u.keys.RIGHT, [a] = o.getLine(l + (e ? -1 : 0));
        if (!a) return !0;
        if (o.resizer.judgeShow(a)) return !1;
        const c = o.getIndex(a);
        if (r && c + a.length() - 1 === l) return !0;
        r && (l += s.length + 1);
        const [m] = o.getLeaf(l);
        if (!m) return !0;
        const x = m.offset(m.parent), P = m.constructor && "scope" in m.constructor && m.constructor.scope === C.BLOCK_BLOT;
        if (e && (P && l === x || l === 0 || l === c)) return !0;
        let S = m;
        if (e && x === 0) {
          const [T] = o.getLeaf(l - 1);
          T && (S = T);
        }
        return !S || !o.resizer.judgeShow(S);
      }
    };
  }
  onCreate() {
    document.addEventListener("keydown", this.keyboardProxy, !0);
  }
  onDestroy() {
    document.removeEventListener("keydown", this.keyboardProxy, !0);
  }
  keyboardHandle(t) {
    if (t.defaultPrevented || t.shiftKey || t.ctrlKey || t.altKey || !this.activeEle || !this.blot) return;
    const e = R(t);
    let s = this.blot.offset(this.quill.scroll), o = null, l = !1;
    e === d.BACKSPACE || e === d.DELETE ? (this.handleDelete(), l = !0) : e >= d.LEFT && e <= d.DOWN && ([s, o] = this.handleArrowKeys(e, s), l = !0), l && (t.stopPropagation(), t.preventDefault()), !(o && this.resizer.judgeShow(o, o.domNode)) && (this.quill.setSelection(s), this.resizer.hide());
  }
  handleDelete() {
    if (!this.blot) return;
    const t = this.blot.length();
    this.blot.deleteAt(0, t), this.blot = void 0, this.activeEle = void 0, this.resizer.hide();
  }
  handleArrowKeys(t, e) {
    let s = null;
    return t === d.RIGHT ? e += this.blot.length() || 1 : t === d.UP ? (e = this.getOtherLineIndex(-1), s = this.quill.getLeaf(e)[0]) : t === d.DOWN && (e = this.getOtherLineIndex(1), s = this.quill.getLeaf(e)[0]), [e, s];
  }
  getOtherLineIndex(t) {
    if (!this.blot) return 0;
    const e = this.blot.offset(this.quill.scroll), [s] = this.quill.getLine(e);
    if (!s) return e;
    const o = this.blot.offset(s) + 1, l = t > 0 ? s.next : s.prev;
    if (!l) return e;
    let r = l.length();
    return l.statics.blotName === "block" && r--, l.offset(this.quill.scroll) + Math.min(r, o);
  }
};
n(u, "keys", d), n(u, "injectedQuills", /* @__PURE__ */ new WeakSet());
let b = u;
const p = class p extends y {
  constructor(t) {
    super(t);
    n(this, "toolbar");
    n(this, "blot");
    n(this, "tools", {});
    n(this, "toolbarClickProxy", (t) => this.handleToolbarClick(t));
    this.blot = t.blot;
  }
  createStyleTool(t, e) {
    const s = {
      left: {
        float: "left"
      },
      right: {
        float: "right"
      },
      center: {
        display: "block",
        margin: "0 auto",
        float: "none"
      },
      justify: {
        display: "block",
        float: "none",
        margin: "0",
        width: "100%"
      }
    };
    return {
      icon: t,
      apply: (o) => {
        this.clearAlignmentStyles(o);
        const l = s[e];
        Object.assign(o.style, l), o.dataset.align = e;
      },
      isApplied: (o) => {
        const l = o.style;
        switch (e) {
          case "center":
            return l.float === "none";
          case "justify":
            return l.display === "block" && l.width === "100%";
          case "left":
          case "right":
            return l.float === e;
          default:
            return !1;
        }
      }
    };
  }
  clearAlignmentStyles(t) {
    const e = t.dataset.align;
    t.style.removeProperty("display"), t.style.removeProperty("float"), t.style.removeProperty("margin"), e === "justify" && t.style.removeProperty("width"), delete t.dataset.align;
  }
  onCreate() {
    var t;
    this.toolbar = document.createElement("div"), this.toolbar.className = f[g.TOOLBAR], this.toolbar.addEventListener("click", this.toolbarClickProxy), (t = this.overlay) == null || t.appendChild(this.toolbar), this.initializeTools(), this._addToolbarButtons();
  }
  onDestroy() {
    var t;
    (t = this.toolbar) == null || t.removeEventListener("click", this.toolbarClickProxy), this.toolbar = void 0;
  }
  initializeTools() {
    Object.keys(p.Tools).forEach((t) => {
      const e = t;
      this.tools[e] = this.createStyleTool(p.Tools[e].icon, e);
    });
  }
  _addToolbarButtons() {
    !this.toolbar || !this.activeEle || this.options.tools.forEach((t) => {
      const e = this.tools[t];
      if (!e) return;
      const s = document.createElement("button");
      s.type = "button", s.className = f[g.TOOLBAR_BUTTON], s.innerHTML = U(e.icon), s.dataset.tool = t, e.isApplied && this.activeEle && e.isApplied.call(this, this.activeEle) && (s.style.backgroundColor = "var(--AEditor_Addon_Secondary_color)"), this.toolbar.appendChild(s);
    });
  }
  handleToolbarClick(t) {
    var r, a;
    if (!this.activeEle || !this.blot || !this.toolbar) return;
    const e = (r = t.target) == null ? void 0 : r.closest("button[data-tool]");
    if (!e || !this.toolbar.contains(e)) return;
    const s = e.dataset.tool;
    if (!s) return;
    const o = this.tools[s];
    if (!o || (t.stopPropagation(), o.handler && o.handler.call(this, t, e, this.activeEle) !== !0)) return;
    const l = o.isApplied ? o.isApplied.call(this, this.activeEle) : !1;
    Array.from(this.toolbar.querySelectorAll("button")).forEach((c) => c.style.backgroundColor = ""), l ? this.clearAlignmentStyles(this.activeEle) : (e.style.backgroundColor = "var(--AEditor_Addon_Secondary_color)", (a = o.apply) == null || a.call(o, this.activeEle)), this.requestUpdate();
  }
};
n(p, "Tools", {
  left: {
    icon: "AlignLeft"
  },
  center: {
    icon: "AlignCenter"
  },
  right: {
    icon: "AlignRight"
  },
  justify: {
    icon: "AlignJustify"
  }
});
let A = p;
class K {
  constructor(i, t = {}) {
    n(this, "isDestroyed", !1);
    n(this, "quill");
    n(this, "options");
    n(this, "moduleClasses");
    n(this, "modules", []);
    n(this, "blot");
    n(this, "selectedBlots", []);
    n(this, "embedClassName", "");
    n(this, "activeEle");
    n(this, "overlay");
    n(this, "updateFromModule", !1);
    n(this, "hideProxy", null);
    n(this, "updateOverlayPositionProxy", null);
    n(this, "embedStyleElement", null);
    n(this, "updateAnimationFrame", null);
    n(this, "overlayScrollAnimationFrame", null);
    n(this, "pendingOverlayMarginTop", null);
    n(this, "scheduledFromModule", !1);
    n(this, "previousBodyUserSelect", null);
    n(this, "previousRootUserSelect", null);
    n(this, "handleClickProxy", (i) => this.handleClick(i));
    n(this, "handleChangeProxy", (i, t, e) => this.handleChange(i, t, e));
    n(this, "handleSelectionChangeProxy", (i) => this.addBlotsSelectedClass(i));
    var s;
    W(), i.resizer = this, this.isDestroyed = !1, this.quill = i;
    const e = t.modules ? [...t.modules] : null;
    this.options = {
      ...j,
      ...t
    }, e && (this.options.modules = e), this.moduleClasses = this.options.modules, this.quill.root.addEventListener("mousedown", this.handleClickProxy, !1), this.quill.on("text-change", this.handleChangeProxy), this.quill.container.style.position = this.quill.container.style.position || "relative", this.quill.on("selection-change", this.handleSelectionChangeProxy), b.injectInit(this.quill), (s = this.options.embedTags) != null && s.length && this.initializeEmbed();
  }
  destroy() {
    var i;
    this.isDestroyed || (this.isDestroyed = !0, this.updateAnimationFrame !== null && (cancelAnimationFrame(this.updateAnimationFrame), this.updateAnimationFrame = null), this.overlayScrollAnimationFrame !== null && (cancelAnimationFrame(this.overlayScrollAnimationFrame), this.overlayScrollAnimationFrame = null), this.pendingOverlayMarginTop = null, this.hide(), this.quill.root.removeEventListener("mousedown", this.handleClickProxy, !1), this.quill.off("text-change", this.handleChangeProxy), this.quill.off("selection-change", this.handleSelectionChangeProxy), (i = this.embedStyleElement) == null || i.remove(), this.embedStyleElement = null, this.embedClassName && this.quill.root.classList.remove(this.embedClassName));
  }
  initializeModules() {
    this.modules.forEach((i) => i.onDestroy()), this.modules = [], this.modules = this.moduleClasses.map((i) => new (this.constructor.Modules[i] || i)(this)), this.modules.forEach((i) => i.onCreate()), this.repositionElements(), this.modules.forEach((i) => i.onUpdate());
  }
  initializeEmbed() {
    if (!this.options.embedTags.length) return;
    this.embedClassName = `ql-${z(k)}`;
    const i = [""].concat(this.options.embedTags).join(`, .${this.embedClassName} `).slice(2) + "{pointer-events: none;}", t = document.createElement("style");
    t.textContent = i, this.embedStyleElement = t, this.quill.container.appendChild(t), this.quill.root.classList.add(this.embedClassName);
  }
  scheduleUpdate(i) {
    this.scheduledFromModule = this.scheduledFromModule || !!i, this.updateAnimationFrame === null && (this.updateAnimationFrame = requestAnimationFrame(() => {
      this.updateAnimationFrame = null;
      const t = this.scheduledFromModule;
      this.scheduledFromModule = !1, this.onUpdate(t);
    }));
  }
  onUpdate(i) {
    this.updateFromModule = !!i, this.repositionElements(), this.modules.forEach((t) => t.onUpdate());
  }
  resolveMediaTarget(i) {
    if (!(i instanceof HTMLElement)) return null;
    const t = ["img", "iframe", "video", ".ql-video"].join(", ");
    if (i.matches(t)) return i;
    const e = i.closest(t);
    return e || null;
  }
  handleClick(i) {
    if (this.overlay && (i.target === this.overlay || this.overlay.contains(i.target))) return;
    let t = i.target;
    if (t = this.getEventTarget(i, t), t != null && t.tagName) {
      const e = this.quill.scroll.find(t);
      if (e && this.judgeShow(e, t)) {
        i.preventDefault();
        return;
      }
    }
    this.activeEle && this.hide();
  }
  getEventTarget(i, t) {
    var l;
    const e = (l = this.options.embedTags) == null ? void 0 : l.join(), s = this.resolveMediaTarget(t);
    if (s) return s;
    if (typeof document.elementsFromPoint == "function") {
      const r = document.elementsFromPoint(i.clientX, i.clientY).map((a) => this.resolveMediaTarget(a)).find((a) => !!a && this.quill.root.contains(a));
      if (r) return r;
    }
    if (!e) return t;
    const o = this.quill.root;
    if (t === o || t.querySelectorAll(e).length) {
      o.classList.remove(this.embedClassName);
      const r = document.elementFromPoint(i.clientX, i.clientY);
      o.classList.add(this.embedClassName);
      const a = this.resolveMediaTarget(r);
      if (a && o.contains(a)) return a;
      r && (t = r);
    }
    return t;
  }
  judgeShow(i, t) {
    if (!i || !this.options.contentOptions) return !1;
    !t && i.domNode && (t = i.domNode);
    const e = this.options.contentOptions.find((o) => o.blotName === i.statics.blotName);
    if (!e) return !1;
    if (this.activeEle === t) return !0;
    const s = e.limit || {};
    return !s.minWidth || s.minWidth && t.offsetWidth >= s.minWidth ? (this.activeEle && this.hide(), this.activeEle = t, this.blot = i, this.showOverlay(), this.initializeModules(), !0) : !1;
  }
  handleChange(i, t, e) {
    if (this.updateFromModule) {
      this.updateFromModule = !1;
      return;
    }
    e !== "user" || !this.overlay || !this.activeEle || this.onUpdate();
  }
  showOverlay() {
    this.overlay && this.hideOverlay(), this.quill.setSelection(null), this.previousBodyUserSelect = document.body.style.userSelect, this.previousRootUserSelect = this.quill.root.style.userSelect, document.body.style.userSelect = "none", this.quill.root.style.userSelect = "none", this.overlay = document.createElement("div"), this.overlay.className = `${f[g.OVERLAY]}`, this.quill.container.appendChild(this.overlay), this.hideProxy = () => this.activeEle && this.hide(), this.updateOverlayPositionProxy = () => this.scheduleOverlayMarginSync(), this.quill.root.addEventListener("input", this.hideProxy, !0), this.quill.root.addEventListener("scroll", this.updateOverlayPositionProxy, {
      passive: !0
    }), this.repositionElements();
  }
  hideOverlay() {
    this.overlay && (this.overlayScrollAnimationFrame !== null && (cancelAnimationFrame(this.overlayScrollAnimationFrame), this.overlayScrollAnimationFrame = null), this.pendingOverlayMarginTop = null, this.overlay.remove(), this.overlay = void 0, this.hideProxy && this.quill.root.removeEventListener("input", this.hideProxy, !0), this.updateOverlayPositionProxy && this.quill.root.removeEventListener("scroll", this.updateOverlayPositionProxy), this.hideProxy = null, this.updateOverlayPositionProxy = null, this.previousBodyUserSelect !== null && (document.body.style.userSelect = this.previousBodyUserSelect, this.previousBodyUserSelect = null), this.previousRootUserSelect !== null && (this.quill.root.style.userSelect = this.previousRootUserSelect, this.previousRootUserSelect = null));
  }
  repositionElements() {
    if (!this.overlay || !this.activeEle) return;
    const i = this.quill.container, t = this.activeEle.getBoundingClientRect(), e = i.getBoundingClientRect();
    Object.assign(this.overlay.style, {
      left: `${t.left - e.left - 1 + i.scrollLeft}px`,
      top: `${t.top - e.top + this.quill.root.scrollTop}px`,
      width: `${t.width}px`,
      height: `${t.height}px`,
      marginTop: -1 * this.quill.root.scrollTop + "px"
    });
  }
  addBlotsSelectedClass(i) {
    if (!i) {
      this.selectedBlots = [];
      return;
    }
    try {
      const t = (s) => {
        var o;
        return ["image", "iframe", "video"].includes((o = s.statics) == null ? void 0 : o.blotName);
      }, e = this.quill.scroll.descendants(t, i.index, i.length);
      this.selectedBlots = e.filter((s) => !s.statics || !this.options.contentOptions ? !1 : this.options.contentOptions.some((o) => o.blotName === s.statics.blotName));
    } catch (t) {
      console.warn("Error during blot selection:", t);
    }
  }
  hide() {
    this.hideOverlay(), this.modules.forEach((i) => i.onDestroy()), this.modules = [], this.activeEle = void 0, this.blot = void 0;
  }
  scheduleOverlayMarginSync() {
    this.overlay && (this.pendingOverlayMarginTop = -1 * this.quill.root.scrollTop, this.overlayScrollAnimationFrame === null && (this.overlayScrollAnimationFrame = requestAnimationFrame(() => {
      this.overlayScrollAnimationFrame = null, !(!this.overlay || this.pendingOverlayMarginTop === null) && (this.overlay.style.marginTop = `${this.pendingOverlayMarginTop}px`, this.pendingOverlayMarginTop = null);
    })));
  }
}
n(K, "Modules", {
  Base: y,
  DisplaySize: _,
  Toolbar: A,
  Resize: $,
  Keyboard: b
});
export {
  K as default
};
