const k = {
  resolveAll: g()
}, m = x("string"), y = x("text");
function x(r) {
  return {
    resolveAll: g(r === "text" ? p : void 0),
    tokenize: o
  };
  function o(t) {
    const i = this, e = this.parser.constructs[r], n = t.attempt(e, a, f);
    return a;
    function a(l) {
      return u(l) ? n(l) : f(l);
    }
    function f(l) {
      if (l === null) {
        t.consume(l);
        return;
      }
      return t.enter("data"), t.consume(l), s;
    }
    function s(l) {
      return u(l) ? (t.exit("data"), n(l)) : (t.consume(l), s);
    }
    function u(l) {
      if (l === null)
        return !0;
      const c = e[l];
      let d = -1;
      if (c)
        for (; ++d < c.length; ) {
          const h = c[d];
          if (!h.previous || h.previous.call(i, i.previous))
            return !0;
        }
      return !1;
    }
  }
}
function g(r) {
  return o;
  function o(t, i) {
    let e = -1, n;
    for (; ++e <= t.length; )
      n === void 0 ? t[e] && t[e][1].type === "data" && (n = e, e++) : (!t[e] || t[e][1].type !== "data") && (e !== n + 2 && (t[n][1].end = t[e - 1][1].end, t.splice(n + 2, e - n - 2), e = n + 2), n = void 0);
    return r ? r(t, i) : t;
  }
}
function p(r, o) {
  let t = 0;
  for (; ++t <= r.length; )
    if ((t === r.length || r[t][1].type === "lineEnding") && r[t - 1][1].type === "data") {
      const i = r[t - 1][1], e = o.sliceStream(i);
      let n = e.length, a = -1, f = 0, s;
      for (; n--; ) {
        const u = e[n];
        if (typeof u == "string") {
          for (a = u.length; u.charCodeAt(a - 1) === 32; )
            f++, a--;
          if (a) break;
          a = -1;
        } else if (u === -2)
          s = !0, f++;
        else if (u !== -1) {
          n++;
          break;
        }
      }
      if (o._contentTypeTextTrailing && t === r.length && (f = 0), f) {
        const u = {
          type: t === r.length || s || f < 2 ? "lineSuffix" : "hardBreakTrailing",
          start: {
            _bufferIndex: n ? a : i.start._bufferIndex + a,
            _index: i.start._index + n,
            line: i.end.line,
            column: i.end.column - f,
            offset: i.end.offset - f
          },
          end: {
            ...i.end
          }
        };
        i.end = {
          ...u.start
        }, i.start.offset === i.end.offset ? Object.assign(i, u) : (r.splice(t, 0, ["enter", u, o], ["exit", u, o]), t += 2);
      }
      t++;
    }
  return r;
}
export {
  k as resolver,
  m as string,
  y as text
};
//# sourceMappingURL=text.js.map
