import { splice as g } from "../../../../micromark-util-chunked@2.0.1/node_modules/micromark-util-chunked/index.es.js";
import { classifyCharacter as k } from "../../../../micromark-util-classify-character@2.0.1/node_modules/micromark-util-classify-character/index.es.js";
import { resolveAll as d } from "../../../../micromark-util-resolve-all@2.0.1/node_modules/micromark-util-resolve-all/index.es.js";
function j(m) {
  let l = (m || {}).singleTilde;
  const f = {
    name: "strikethrough",
    tokenize: S,
    resolveAll: y
  };
  return l == null && (l = !0), {
    text: {
      126: f
    },
    insideSpan: {
      null: [f]
    },
    attentionMarkers: {
      null: [126]
    }
  };
  function y(r, i) {
    let t = -1;
    for (; ++t < r.length; )
      if (r[t][0] === "enter" && r[t][1].type === "strikethroughSequenceTemporary" && r[t][1]._close) {
        let e = t;
        for (; e--; )
          if (r[e][0] === "exit" && r[e][1].type === "strikethroughSequenceTemporary" && r[e][1]._open && // If the sizes are the same:
          r[t][1].end.offset - r[t][1].start.offset === r[e][1].end.offset - r[e][1].start.offset) {
            r[t][1].type = "strikethroughSequence", r[e][1].type = "strikethroughSequence";
            const s = {
              type: "strikethrough",
              start: Object.assign({}, r[e][1].start),
              end: Object.assign({}, r[t][1].end)
            }, u = {
              type: "strikethroughText",
              start: Object.assign({}, r[e][1].end),
              end: Object.assign({}, r[t][1].start)
            }, o = [["enter", s, i], ["enter", r[e][1], i], ["exit", r[e][1], i], ["enter", u, i]], h = i.parser.constructs.insideSpan.null;
            h && g(o, o.length, 0, d(h, r.slice(e + 1, t), i)), g(o, o.length, 0, [["exit", u, i], ["enter", r[t][1], i], ["exit", r[t][1], i], ["exit", s, i]]), g(r, e - 1, t - e + 3, o), t = e + o.length - 2;
            break;
          }
      }
    for (t = -1; ++t < r.length; )
      r[t][1].type === "strikethroughSequenceTemporary" && (r[t][1].type = "data");
    return r;
  }
  function S(r, i, t) {
    const e = this.previous, s = this.events;
    let u = 0;
    return o;
    function o(n) {
      return e === 126 && s[s.length - 1][1].type !== "characterEscape" ? t(n) : (r.enter("strikethroughSequenceTemporary"), h(n));
    }
    function h(n) {
      const a = k(e);
      if (n === 126)
        return u > 1 ? t(n) : (r.consume(n), u++, h);
      if (u < 2 && !l) return t(n);
      const c = r.exit("strikethroughSequenceTemporary"), p = k(n);
      return c._open = !p || p === 2 && !!a, c._close = !a || a === 2 && !!p, i(n);
    }
  }
}
export {
  j as gfmStrikethrough
};
//# sourceMappingURL=syntax.es.js.map
