import { __exports as o } from "../../../../../../_virtual/OpIterator.mjs";
import "./Op.mjs";
import { __exports as f } from "../../../../../../_virtual/Op.mjs";
Object.defineProperty(o, "__esModule", { value: !0 });
const r = f;
class p {
  constructor(e) {
    this.ops = e, this.index = 0, this.offset = 0;
  }
  hasNext() {
    return this.peekLength() < 1 / 0;
  }
  next(e) {
    e || (e = 1 / 0);
    const t = this.ops[this.index];
    if (t) {
      const i = this.offset, n = r.default.length(t);
      if (e >= n - i ? (e = n - i, this.index += 1, this.offset = 0) : this.offset += e, typeof t.delete == "number")
        return { delete: e };
      {
        const s = {};
        return t.attributes && (s.attributes = t.attributes), typeof t.retain == "number" ? s.retain = e : typeof t.retain == "object" && t.retain !== null ? s.retain = t.retain : typeof t.insert == "string" ? s.insert = t.insert.substr(i, e) : s.insert = t.insert, s;
      }
    } else
      return { retain: 1 / 0 };
  }
  peek() {
    return this.ops[this.index];
  }
  peekLength() {
    return this.ops[this.index] ? r.default.length(this.ops[this.index]) - this.offset : 1 / 0;
  }
  peekType() {
    const e = this.ops[this.index];
    return e ? typeof e.delete == "number" ? "delete" : typeof e.retain == "number" || typeof e.retain == "object" && e.retain !== null ? "retain" : "insert" : "retain";
  }
  rest() {
    if (this.hasNext()) {
      if (this.offset === 0)
        return this.ops.slice(this.index);
      {
        const e = this.offset, t = this.index, i = this.next(), n = this.ops.slice(this.index);
        return this.offset = e, this.index = t, [i].concat(n);
      }
    } else
      return [];
  }
}
o.default = p;
