"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const index = require("../micromark-util-chunked/index.cjs");
const index$2 = require("../micromark-util-classify-character/index.cjs");
const index$1 = require("../micromark-util-resolve-all/index.cjs");
function gfmStrikethrough(options) {
  const options_ = options || {};
  let single = options_.singleTilde;
  const tokenizer = {
    name: "strikethrough",
    tokenize: tokenizeStrikethrough,
    resolveAll: resolveAllStrikethrough
  };
  if (single === null || single === void 0) {
    single = true;
  }
  return {
    text: {
      [126]: tokenizer
    },
    insideSpan: {
      null: [tokenizer]
    },
    attentionMarkers: {
      null: [126]
    }
  };
  function resolveAllStrikethrough(events, context) {
    let index$22 = -1;
    while (++index$22 < events.length) {
      if (events[index$22][0] === "enter" && events[index$22][1].type === "strikethroughSequenceTemporary" && events[index$22][1]._close) {
        let open = index$22;
        while (open--) {
          if (events[open][0] === "exit" && events[open][1].type === "strikethroughSequenceTemporary" && events[open][1]._open && // If the sizes are the same:
          events[index$22][1].end.offset - events[index$22][1].start.offset === events[open][1].end.offset - events[open][1].start.offset) {
            events[index$22][1].type = "strikethroughSequence";
            events[open][1].type = "strikethroughSequence";
            const strikethrough = {
              type: "strikethrough",
              start: Object.assign({}, events[open][1].start),
              end: Object.assign({}, events[index$22][1].end)
            };
            const text = {
              type: "strikethroughText",
              start: Object.assign({}, events[open][1].end),
              end: Object.assign({}, events[index$22][1].start)
            };
            const nextEvents = [["enter", strikethrough, context], ["enter", events[open][1], context], ["exit", events[open][1], context], ["enter", text, context]];
            const insideSpan = context.parser.constructs.insideSpan.null;
            if (insideSpan) {
              index.splice(nextEvents, nextEvents.length, 0, index$1.resolveAll(insideSpan, events.slice(open + 1, index$22), context));
            }
            index.splice(nextEvents, nextEvents.length, 0, [["exit", text, context], ["enter", events[index$22][1], context], ["exit", events[index$22][1], context], ["exit", strikethrough, context]]);
            index.splice(events, open - 1, index$22 - open + 3, nextEvents);
            index$22 = open + nextEvents.length - 2;
            break;
          }
        }
      }
    }
    index$22 = -1;
    while (++index$22 < events.length) {
      if (events[index$22][1].type === "strikethroughSequenceTemporary") {
        events[index$22][1].type = "data";
      }
    }
    return events;
  }
  function tokenizeStrikethrough(effects, ok, nok) {
    const previous = this.previous;
    const events = this.events;
    let size = 0;
    return start;
    function start(code) {
      if (previous === 126 && events[events.length - 1][1].type !== "characterEscape") {
        return nok(code);
      }
      effects.enter("strikethroughSequenceTemporary");
      return more(code);
    }
    function more(code) {
      const before = index$2.classifyCharacter(previous);
      if (code === 126) {
        if (size > 1) return nok(code);
        effects.consume(code);
        size++;
        return more;
      }
      if (size < 2 && !single) return nok(code);
      const token = effects.exit("strikethroughSequenceTemporary");
      const after = index$2.classifyCharacter(code);
      token._open = !after || after === 2 && Boolean(before);
      token._close = !before || before === 2 && Boolean(after);
      return ok(code);
    }
  }
}
exports.gfmStrikethrough = gfmStrikethrough;
//# sourceMappingURL=lib-syntax.cjs.map
