var N = -1, D = 1, I = 0;
function Q(r, l, n, g, e) {
  if (r === l)
    return r ? [[I, r]] : [];
  if (n != null) {
    var a = f(r, l, n);
    if (a)
      return a;
  }
  var h = O(r, l), v = r.substring(0, h);
  r = r.substring(h), l = l.substring(h), h = U(r, l);
  var i = r.substring(r.length - h);
  r = r.substring(0, r.length - h), l = l.substring(0, l.length - h);
  var c = X(r, l);
  return v && c.unshift([I, v]), i && c.push([I, i]), Z(c, e), g && T(c), c;
}
function X(r, l) {
  var n;
  if (!r)
    return [[D, l]];
  if (!l)
    return [[N, r]];
  var g = r.length > l.length ? r : l, e = r.length > l.length ? l : r, a = g.indexOf(e);
  if (a !== -1)
    return n = [
      [D, g.substring(0, a)],
      [I, e],
      [D, g.substring(a + e.length)]
    ], r.length > l.length && (n[0][0] = n[2][0] = N), n;
  if (e.length === 1)
    return [
      [N, r],
      [D, l]
    ];
  var h = B(r, l);
  if (h) {
    var v = h[0], i = h[1], c = h[2], b = h[3], u = h[4], _ = Q(v, c), t = Q(i, b);
    return _.concat([[I, u]], t);
  }
  return Y(r, l);
}
function Y(r, l) {
  for (var n = r.length, g = l.length, e = Math.ceil((n + g) / 2), a = e, h = 2 * e, v = new Array(h), i = new Array(h), c = 0; c < h; c++)
    v[c] = -1, i[c] = -1;
  v[a + 1] = 0, i[a + 1] = 0;
  for (var b = n - g, u = b % 2 !== 0, _ = 0, t = 0, A = 0, S = 0, F = 0; F < e; F++) {
    for (var s = -F + _; s <= F - t; s += 2) {
      var p = a + s, m;
      s === -F || s !== F && v[p - 1] < v[p + 1] ? m = v[p + 1] : m = v[p - 1] + 1;
      for (var M = m - s; m < n && M < g && r.charAt(m) === l.charAt(M); )
        m++, M++;
      if (v[p] = m, m > n)
        t += 2;
      else if (M > g)
        _ += 2;
      else if (u) {
        var w = a + b - s;
        if (w >= 0 && w < h && i[w] !== -1) {
          var R = n - i[w];
          if (m >= R)
            return $(r, l, m, M);
        }
      }
    }
    for (var E = -F + A; E <= F - S; E += 2) {
      var w = a + E, R;
      E === -F || E !== F && i[w - 1] < i[w + 1] ? R = i[w + 1] : R = i[w - 1] + 1;
      for (var P = R - E; R < n && P < g && r.charAt(n - R - 1) === l.charAt(g - P - 1); )
        R++, P++;
      if (i[w] = R, R > n)
        S += 2;
      else if (P > g)
        A += 2;
      else if (!u) {
        var p = a + b - E;
        if (p >= 0 && p < h && v[p] !== -1) {
          var m = v[p], M = a + m - p;
          if (R = n - R, m >= R)
            return $(r, l, m, M);
        }
      }
    }
  }
  return [
    [N, r],
    [D, l]
  ];
}
function $(r, l, n, g) {
  var e = r.substring(0, n), a = l.substring(0, g), h = r.substring(n), v = l.substring(g), i = Q(e, a), c = Q(h, v);
  return i.concat(c);
}
function O(r, l) {
  if (!r || !l || r.charAt(0) !== l.charAt(0))
    return 0;
  for (var n = 0, g = Math.min(r.length, l.length), e = g, a = 0; n < e; )
    r.substring(a, e) == l.substring(a, e) ? (n = e, a = n) : g = e, e = Math.floor((g - n) / 2 + n);
  return K(r.charCodeAt(e - 1)) && e--, e;
}
function k(r, l) {
  var n = r.length, g = l.length;
  if (n == 0 || g == 0)
    return 0;
  n > g ? r = r.substring(n - g) : n < g && (l = l.substring(0, n));
  var e = Math.min(n, g);
  if (r == l)
    return e;
  for (var a = 0, h = 1; ; ) {
    var v = r.substring(e - h), i = l.indexOf(v);
    if (i == -1)
      return a;
    h += i, (i == 0 || r.substring(e - h) == l.substring(0, h)) && (a = h, h++);
  }
}
function U(r, l) {
  if (!r || !l || r.slice(-1) !== l.slice(-1))
    return 0;
  for (var n = 0, g = Math.min(r.length, l.length), e = g, a = 0; n < e; )
    r.substring(r.length - e, r.length - a) == l.substring(l.length - e, l.length - a) ? (n = e, a = n) : g = e, e = Math.floor((g - n) / 2 + n);
  return L(r.charCodeAt(r.length - e)) && e--, e;
}
function B(r, l) {
  var n = r.length > l.length ? r : l, g = r.length > l.length ? l : r;
  if (n.length < 4 || g.length * 2 < n.length)
    return null;
  function e(t, A, S) {
    for (var F = t.substring(S, S + Math.floor(t.length / 4)), s = -1, p = "", m, M, w, R; (s = A.indexOf(F, s + 1)) !== -1; ) {
      var E = O(
        t.substring(S),
        A.substring(s)
      ), P = U(
        t.substring(0, S),
        A.substring(0, s)
      );
      p.length < P + E && (p = A.substring(s - P, s) + A.substring(s, s + E), m = t.substring(0, S - P), M = t.substring(S + E), w = A.substring(0, s - P), R = A.substring(s + E));
    }
    return p.length * 2 >= t.length ? [
      m,
      M,
      w,
      R,
      p
    ] : null;
  }
  var a = e(
    n,
    g,
    Math.ceil(n.length / 4)
  ), h = e(
    n,
    g,
    Math.ceil(n.length / 2)
  ), v;
  if (!a && !h)
    return null;
  h ? a ? v = a[4].length > h[4].length ? a : h : v = h : v = a;
  var i, c, b, u;
  r.length > l.length ? (i = v[0], c = v[1], b = v[2], u = v[3]) : (b = v[0], u = v[1], i = v[2], c = v[3]);
  var _ = v[4];
  return [i, c, b, u, _];
}
function T(r) {
  for (var l = !1, n = [], g = 0, e = null, a = 0, h = 0, v = 0, i = 0, c = 0; a < r.length; )
    r[a][0] == I ? (n[g++] = a, h = i, v = c, i = 0, c = 0, e = r[a][1]) : (r[a][0] == D ? i += r[a][1].length : c += r[a][1].length, e && e.length <= Math.max(h, v) && e.length <= Math.max(i, c) && (r.splice(n[g - 1], 0, [
      N,
      e
    ]), r[n[g - 1] + 1][0] = D, g--, g--, a = g > 0 ? n[g - 1] : -1, h = 0, v = 0, i = 0, c = 0, e = null, l = !0)), a++;
  for (l && Z(r), q(r), a = 1; a < r.length; ) {
    if (r[a - 1][0] == N && r[a][0] == D) {
      var b = r[a - 1][1], u = r[a][1], _ = k(b, u), t = k(u, b);
      _ >= t ? (_ >= b.length / 2 || _ >= u.length / 2) && (r.splice(a, 0, [
        I,
        u.substring(0, _)
      ]), r[a - 1][1] = b.substring(
        0,
        b.length - _
      ), r[a + 1][1] = u.substring(_), a++) : (t >= b.length / 2 || t >= u.length / 2) && (r.splice(a, 0, [
        I,
        b.substring(0, t)
      ]), r[a - 1][0] = D, r[a - 1][1] = u.substring(
        0,
        u.length - t
      ), r[a + 1][0] = N, r[a + 1][1] = b.substring(t), a++), a++;
    }
    a++;
  }
}
var G = /[^a-zA-Z0-9]/, H = /\s/, J = /[\r\n]/, C = /\n\r?\n$/, o = /^\r?\n\r?\n/;
function q(r) {
  function l(t, A) {
    if (!t || !A)
      return 6;
    var S = t.charAt(t.length - 1), F = A.charAt(0), s = S.match(G), p = F.match(G), m = s && S.match(H), M = p && F.match(H), w = m && S.match(J), R = M && F.match(J), E = w && t.match(C), P = R && A.match(o);
    return E || P ? 5 : w || R ? 4 : s && !m && M ? 3 : m || M ? 2 : s || p ? 1 : 0;
  }
  for (var n = 1; n < r.length - 1; ) {
    if (r[n - 1][0] == I && r[n + 1][0] == I) {
      var g = r[n - 1][1], e = r[n][1], a = r[n + 1][1], h = U(g, e);
      if (h) {
        var v = e.substring(e.length - h);
        g = g.substring(0, g.length - h), e = v + e.substring(0, e.length - h), a = v + a;
      }
      for (var i = g, c = e, b = a, u = l(g, e) + l(e, a); e.charAt(0) === a.charAt(0); ) {
        g += e.charAt(0), e = e.substring(1) + a.charAt(0), a = a.substring(1);
        var _ = l(g, e) + l(e, a);
        _ >= u && (u = _, i = g, c = e, b = a);
      }
      r[n - 1][1] != i && (i ? r[n - 1][1] = i : (r.splice(n - 1, 1), n--), r[n][1] = c, b ? r[n + 1][1] = b : (r.splice(n + 1, 1), n--));
    }
    n++;
  }
}
function Z(r, l) {
  r.push([I, ""]);
  for (var n = 0, g = 0, e = 0, a = "", h = "", v; n < r.length; ) {
    if (n < r.length - 1 && !r[n][1]) {
      r.splice(n, 1);
      continue;
    }
    switch (r[n][0]) {
      case D:
        e++, h += r[n][1], n++;
        break;
      case N:
        g++, a += r[n][1], n++;
        break;
      case I:
        var i = n - e - g - 1;
        if (l) {
          if (i >= 0 && W(r[i][1])) {
            var c = r[i][1].slice(-1);
            if (r[i][1] = r[i][1].slice(
              0,
              -1
            ), a = c + a, h = c + h, !r[i][1]) {
              r.splice(i, 1), n--;
              var b = i - 1;
              r[b] && r[b][0] === D && (e++, h = r[b][1] + h, b--), r[b] && r[b][0] === N && (g++, a = r[b][1] + a, b--), i = b;
            }
          }
          if (V(r[n][1])) {
            var c = r[n][1].charAt(0);
            r[n][1] = r[n][1].slice(1), a += c, h += c;
          }
        }
        if (n < r.length - 1 && !r[n][1]) {
          r.splice(n, 1);
          break;
        }
        if (a.length > 0 || h.length > 0) {
          a.length > 0 && h.length > 0 && (v = O(h, a), v !== 0 && (i >= 0 ? r[i][1] += h.substring(
            0,
            v
          ) : (r.splice(0, 0, [
            I,
            h.substring(0, v)
          ]), n++), h = h.substring(v), a = a.substring(v)), v = U(h, a), v !== 0 && (r[n][1] = h.substring(h.length - v) + r[n][1], h = h.substring(
            0,
            h.length - v
          ), a = a.substring(
            0,
            a.length - v
          )));
          var u = e + g;
          a.length === 0 && h.length === 0 ? (r.splice(n - u, u), n = n - u) : a.length === 0 ? (r.splice(n - u, u, [D, h]), n = n - u + 1) : h.length === 0 ? (r.splice(n - u, u, [N, a]), n = n - u + 1) : (r.splice(
            n - u,
            u,
            [N, a],
            [D, h]
          ), n = n - u + 2);
        }
        n !== 0 && r[n - 1][0] === I ? (r[n - 1][1] += r[n][1], r.splice(n, 1)) : n++, e = 0, g = 0, a = "", h = "";
        break;
    }
  }
  r[r.length - 1][1] === "" && r.pop();
  var _ = !1;
  for (n = 1; n < r.length - 1; )
    r[n - 1][0] === I && r[n + 1][0] === I && (r[n][1].substring(
      r[n][1].length - r[n - 1][1].length
    ) === r[n - 1][1] ? (r[n][1] = r[n - 1][1] + r[n][1].substring(
      0,
      r[n][1].length - r[n - 1][1].length
    ), r[n + 1][1] = r[n - 1][1] + r[n + 1][1], r.splice(n - 1, 1), _ = !0) : r[n][1].substring(0, r[n + 1][1].length) == r[n + 1][1] && (r[n - 1][1] += r[n + 1][1], r[n][1] = r[n][1].substring(r[n + 1][1].length) + r[n + 1][1], r.splice(n + 1, 1), _ = !0)), n++;
  _ && Z(r, l);
}
function K(r) {
  return r >= 55296 && r <= 56319;
}
function L(r) {
  return r >= 56320 && r <= 57343;
}
function V(r) {
  return L(r.charCodeAt(0));
}
function W(r) {
  return K(r.charCodeAt(r.length - 1));
}
function y(r) {
  for (var l = [], n = 0; n < r.length; n++)
    r[n][1].length > 0 && l.push(r[n]);
  return l;
}
function z(r, l, n, g) {
  return W(r) || V(g) ? null : y([
    [I, r],
    [N, l],
    [D, n],
    [I, g]
  ]);
}
function f(r, l, n) {
  var g = typeof n == "number" ? { index: n, length: 0 } : n.oldRange, e = typeof n == "number" ? null : n.newRange, a = r.length, h = l.length;
  if (g.length === 0 && (e === null || e.length === 0)) {
    var v = g.index, i = r.slice(0, v), c = r.slice(v), b = e ? e.index : null;
    r: {
      var u = v + h - a;
      if (b !== null && b !== u || u < 0 || u > h)
        break r;
      var _ = l.slice(0, u), t = l.slice(u);
      if (t !== c)
        break r;
      var A = Math.min(v, u), S = i.slice(0, A), F = _.slice(0, A);
      if (S !== F)
        break r;
      var s = i.slice(A), p = _.slice(A);
      return z(S, s, p, c);
    }
    r: {
      if (b !== null && b !== v)
        break r;
      var m = v, _ = l.slice(0, m), t = l.slice(m);
      if (_ !== i)
        break r;
      var M = Math.min(a - m, h - m), w = c.slice(c.length - M), R = t.slice(t.length - M);
      if (w !== R)
        break r;
      var s = c.slice(0, c.length - M), p = t.slice(0, t.length - M);
      return z(i, s, p, w);
    }
  }
  if (g.length > 0 && e && e.length === 0)
    r: {
      var S = r.slice(0, g.index), w = r.slice(g.index + g.length), A = S.length, M = w.length;
      if (h < A + M)
        break r;
      var F = l.slice(0, A), R = l.slice(h - M);
      if (S !== F || w !== R)
        break r;
      var s = r.slice(A, a - M), p = l.slice(A, h - M);
      return z(S, s, p, w);
    }
  return null;
}
function j(r, l, n, g) {
  return Q(r, l, n, g, !0);
}
j.INSERT = D;
j.DELETE = N;
j.EQUAL = I;
var x = j;
export {
  x as d
};
