class e {
  /**
   * Create a new edit map.
   */
  constructor() {
    this.map = [];
  }
  /**
   * Create an edit: a remove and/or add at a certain place.
   *
   * @param {number} index
   * @param {number} remove
   * @param {Array<Event>} add
   * @returns {undefined}
   */
  add(h, t, p) {
    m(this, h, t, p);
  }
  // To do: add this when moving to `micromark`.
  // /**
  //  * Create an edit: but insert `add` before existing additions.
  //  *
  //  * @param {number} index
  //  * @param {number} remove
  //  * @param {Array<Event>} add
  //  * @returns {undefined}
  //  */
  // addBefore(index, remove, add) {
  //   addImplementation(this, index, remove, add, true)
  // }
  /**
   * Done, change the events.
   *
   * @param {Array<Event>} events
   * @returns {undefined}
   */
  consume(h) {
    if (this.map.sort(function(n, l) {
      return n[0] - l[0];
    }), this.map.length === 0)
      return;
    let t = this.map.length;
    const p = [];
    for (; t > 0; )
      t -= 1, p.push(h.slice(this.map[t][0] + this.map[t][1]), this.map[t][2]), h.length = this.map[t][0];
    p.push(h.slice()), h.length = 0;
    let s = p.pop();
    for (; s; ) {
      for (const n of s)
        h.push(n);
      s = p.pop();
    }
    this.map.length = 0;
  }
}
function m(i, h, t, p) {
  let s = 0;
  if (!(t === 0 && p.length === 0)) {
    for (; s < i.map.length; ) {
      if (i.map[s][0] === h) {
        i.map[s][1] += t, i.map[s][2].push(...p);
        return;
      }
      s += 1;
    }
    i.map.push([h, t, p]);
  }
}
export {
  e as EditMap
};
//# sourceMappingURL=edit-map.js.map
