import { markdownLineEnding as y } from "../../../../micromark-util-character@2.1.1/node_modules/micromark-util-character/index.es.js";
function k(e) {
  let a = (e || {}).singleDollarTextMath;
  return a == null && (a = !0), {
    tokenize: i,
    resolve: d,
    previous: q,
    name: "mathText"
  };
  function i(n, o, p) {
    let l = 0, x, m;
    return E;
    function E(t) {
      return n.enter("mathText"), n.enter("mathTextSequence"), T(t);
    }
    function T(t) {
      return t === 36 ? (n.consume(t), l++, T) : l < 2 && !a ? p(t) : (n.exit("mathTextSequence"), u(t));
    }
    function u(t) {
      return t === null ? p(t) : t === 36 ? (m = n.enter("mathTextSequence"), x = 0, g(t)) : t === 32 ? (n.enter("space"), n.consume(t), n.exit("space"), u) : y(t) ? (n.enter("lineEnding"), n.consume(t), n.exit("lineEnding"), u) : (n.enter("mathTextData"), h(t));
    }
    function h(t) {
      return t === null || t === 32 || t === 36 || y(t) ? (n.exit("mathTextData"), u(t)) : (n.consume(t), h);
    }
    function g(t) {
      return t === 36 ? (n.consume(t), x++, g) : x === l ? (n.exit("mathTextSequence"), n.exit("mathText"), o(t)) : (m.type = "mathTextData", h(t));
    }
  }
}
function d(e) {
  let r = e.length - 4, a = 3, i, n;
  if ((e[a][1].type === "lineEnding" || e[a][1].type === "space") && (e[r][1].type === "lineEnding" || e[r][1].type === "space")) {
    for (i = a; ++i < r; )
      if (e[i][1].type === "mathTextData") {
        e[r][1].type = "mathTextPadding", e[a][1].type = "mathTextPadding", a += 2, r -= 2;
        break;
      }
  }
  for (i = a - 1, r++; ++i <= r; )
    n === void 0 ? i !== r && e[i][1].type !== "lineEnding" && (n = i) : (i === r || e[i][1].type === "lineEnding") && (e[n][1].type = "mathTextData", i !== n + 2 && (e[n][1].end = e[i - 1][1].end, e.splice(n + 2, i - n - 2), r -= i - n - 2, i = n + 2), n = void 0);
  return e;
}
function q(e) {
  return e !== 36 || this.events[this.events.length - 1][1].type === "characterEscape";
}
export {
  k as mathText
};
//# sourceMappingURL=math-text.es.js.map
