import { splice as I } from "../../../micromark-util-chunked@2.0.1/node_modules/micromark-util-chunked/index.js";
import { SpliceBuffer as _ } from "./lib/splice-buffer.js";
function b(u) {
  const c = {};
  let e = -1, p, o, n, s, f, l, g;
  const r = new _(u);
  for (; ++e < r.length; ) {
    for (; e in c; )
      e = c[e];
    if (p = r.get(e), e && p[1].type === "chunkFlow" && r.get(e - 1)[1].type === "listItemPrefix" && (l = p[1]._tokenizer.events, n = 0, n < l.length && l[n][1].type === "lineEndingBlank" && (n += 2), n < l.length && l[n][1].type === "content"))
      for (; ++n < l.length && l[n][1].type !== "content"; )
        l[n][1].type === "chunkText" && (l[n][1]._isInFirstContentOfListItem = !0, n++);
    if (p[0] === "enter")
      p[1].contentType && (Object.assign(c, x(r, e)), e = c[e], g = !0);
    else if (p[1]._container) {
      for (n = e, o = void 0; n--; )
        if (s = r.get(n), s[1].type === "lineEnding" || s[1].type === "lineEndingBlank")
          s[0] === "enter" && (o && (r.get(o)[1].type = "lineEndingBlank"), s[1].type = "lineEnding", o = n);
        else if (!(s[1].type === "linePrefix" || s[1].type === "listItemIndent")) break;
      o && (p[1].end = {
        ...r.get(o)[1].start
      }, f = r.slice(o, e), f.unshift(p), r.splice(o, e - o + 1, f));
    }
  }
  return I(u, 0, Number.POSITIVE_INFINITY, r.slice(0)), !g;
}
function x(u, c) {
  const e = u.get(c)[1], p = u.get(c)[2];
  let o = c - 1;
  const n = [];
  let s = e._tokenizer;
  s || (s = p.parser[e.contentType](e.start), e._contentTypeTextTrailing && (s._contentTypeTextTrailing = !0));
  const f = s.events, l = [], g = {};
  let r, k, i = -1, t = e, a = 0, d = 0;
  const h = [d];
  for (; t; ) {
    for (; u.get(++o)[1] !== t; )
      ;
    n.push(o), t._tokenizer || (r = p.sliceStream(t), t.next || r.push(null), k && s.defineSkip(t.start), t._isInFirstContentOfListItem && (s._gfmTasklistFirstContentOfListItem = !0), s.write(r), t._isInFirstContentOfListItem && (s._gfmTasklistFirstContentOfListItem = void 0)), k = t, t = t.next;
  }
  for (t = e; ++i < f.length; )
    // Find a void token that includes a break.
    f[i][0] === "exit" && f[i - 1][0] === "enter" && f[i][1].type === f[i - 1][1].type && f[i][1].start.line !== f[i][1].end.line && (d = i + 1, h.push(d), t._tokenizer = void 0, t.previous = void 0, t = t.next);
  for (s.events = [], t ? (t._tokenizer = void 0, t.previous = void 0) : h.pop(), i = h.length; i--; ) {
    const y = f.slice(h[i], h[i + 1]), m = n.pop();
    l.push([m, m + y.length - 1]), u.splice(m, 2, y);
  }
  for (l.reverse(), i = -1; ++i < l.length; )
    g[a + l[i][0]] = a + l[i][1], a += l[i][1] - l[i][0] - 1;
  return g;
}
export {
  _ as SpliceBuffer,
  b as subtokenize
};
//# sourceMappingURL=index.js.map
