var n = Object.defineProperty;
var r = (s, t, i) => t in s ? n(s, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : s[t] = i;
var e = (s, t, i) => (r(s, typeof t != "symbol" ? t + "" : t, i), i);
import m from "../blots/embed.mjs";
import o from "./emitter.mjs";
class d {
  constructor(t, i) {
    e(this, "isComposing", !1);
    this.scroll = t, this.emitter = i, this.setupListeners();
  }
  setupListeners() {
    this.scroll.domNode.addEventListener("compositionstart", (t) => {
      this.isComposing || this.handleCompositionStart(t);
    }), this.scroll.domNode.addEventListener("compositionend", (t) => {
      this.isComposing && queueMicrotask(() => {
        this.handleCompositionEnd(t);
      });
    });
  }
  handleCompositionStart(t) {
    const i = t.target instanceof Node ? this.scroll.find(t.target, !0) : null;
    i && !(i instanceof m) && (this.emitter.emit(o.events.COMPOSITION_BEFORE_START, t), this.scroll.batchStart(), this.emitter.emit(o.events.COMPOSITION_START, t), this.isComposing = !0);
  }
  handleCompositionEnd(t) {
    this.emitter.emit(o.events.COMPOSITION_BEFORE_END, t), this.scroll.batchEnd(), this.emitter.emit(o.events.COMPOSITION_END, t), this.isComposing = !1;
  }
}
export {
  d as default
};
