import { m as Q } from "./chunk-TMUBEWPD-BRIzn5gH-alZ9Sg3f.js";
import { e as X } from "./chunk-KFBOBJHC-nixdujtH-CrTZo7r-.js";
import { _ as $, aj as Z, ak as tt, a5 as rt, a6 as et, a7 as ot, a8 as nt, l as w, g as at, a9 as ct, ao as it, aB as st, aq as dt, ag as k, aC as ht, aD as mt, aE as $t, aF as lt } from "./index-CMZig9xg.js";
import { D as gt } from "./mermaid-parser.core-Ce96PX3Q-CV9ue_xr.js";
var x = {
  NORMAL: 0,
  REVERSE: 1,
  HIGHLIGHT: 2,
  MERGE: 3,
  CHERRY_PICK: 4
}, yt = $t.gitGraph, O = /* @__PURE__ */ $(() => ht({
  ...yt,
  ...mt().gitGraph
}), "getConfig"), s = new X(() => {
  const r = O(), t = r.mainBranchName, e = r.mainBranchOrder;
  return {
    mainBranchName: t,
    commits: /* @__PURE__ */ new Map(),
    head: null,
    branchConfig: /* @__PURE__ */ new Map([[t, { name: t, order: e }]]),
    branches: /* @__PURE__ */ new Map([[t, null]]),
    currBranch: t,
    direction: "LR",
    seq: 0,
    options: {}
  };
});
function S() {
  return lt({ length: 7 });
}
$(S, "getID");
function F(r, t) {
  const e = /* @__PURE__ */ Object.create(null);
  return r.reduce((a, c) => {
    const i = t(c);
    return e[i] || (e[i] = !0, a.push(c)), a;
  }, []);
}
$(F, "uniqBy");
var pt = /* @__PURE__ */ $(function(r) {
  s.records.direction = r;
}, "setDirection"), ft = /* @__PURE__ */ $(function(r) {
  w.debug("options str", r), r = r == null ? void 0 : r.trim(), r = r || "{}";
  try {
    s.records.options = JSON.parse(r);
  } catch (t) {
    w.error("error while parsing gitGraph options", t.message);
  }
}, "setOptions"), ut = /* @__PURE__ */ $(function() {
  return s.records.options;
}, "getOptions"), xt = /* @__PURE__ */ $(function(r) {
  let t = r.msg, e = r.id;
  const a = r.type;
  let c = r.tags;
  w.info("commit", t, e, a, c), w.debug("Entering commit:", t, e, a, c);
  const i = O();
  e = k.sanitizeText(e, i), t = k.sanitizeText(t, i), c = c == null ? void 0 : c.map((d) => k.sanitizeText(d, i));
  const h = {
    id: e || s.records.seq + "-" + S(),
    message: t,
    seq: s.records.seq++,
    type: a ?? x.NORMAL,
    tags: c ?? [],
    parents: s.records.head == null ? [] : [s.records.head.id],
    branch: s.records.currBranch
  };
  s.records.head = h, w.info("main branch", i.mainBranchName), s.records.commits.set(h.id, h), s.records.branches.set(s.records.currBranch, h.id), w.debug("in pushCommit " + h.id);
}, "commit"), bt = /* @__PURE__ */ $(function(r) {
  let t = r.name;
  const e = r.order;
  if (t = k.sanitizeText(t, O()), s.records.branches.has(t))
    throw new Error(
      `Trying to create an existing branch. (Help: Either use a new name if you want create a new branch or try using "checkout ${t}")`
    );
  s.records.branches.set(t, s.records.head != null ? s.records.head.id : null), s.records.branchConfig.set(t, { name: t, order: e }), K(t), w.debug("in createBranch");
}, "branch"), wt = /* @__PURE__ */ $((r) => {
  let t = r.branch, e = r.id;
  const a = r.type, c = r.tags, i = O();
  t = k.sanitizeText(t, i), e && (e = k.sanitizeText(e, i));
  const h = s.records.branches.get(s.records.currBranch), d = s.records.branches.get(t), l = h ? s.records.commits.get(h) : void 0, o = d ? s.records.commits.get(d) : void 0;
  if (l && o && l.branch === t)
    throw new Error(`Cannot merge branch '${t}' into itself.`);
  if (s.records.currBranch === t) {
    const m = new Error('Incorrect usage of "merge". Cannot merge a branch to itself');
    throw m.hash = {
      text: `merge ${t}`,
      token: `merge ${t}`,
      expected: ["branch abc"]
    }, m;
  }
  if (l === void 0 || !l) {
    const m = new Error(
      `Incorrect usage of "merge". Current branch (${s.records.currBranch})has no commits`
    );
    throw m.hash = {
      text: `merge ${t}`,
      token: `merge ${t}`,
      expected: ["commit"]
    }, m;
  }
  if (!s.records.branches.has(t)) {
    const m = new Error(
      'Incorrect usage of "merge". Branch to be merged (' + t + ") does not exist"
    );
    throw m.hash = {
      text: `merge ${t}`,
      token: `merge ${t}`,
      expected: [`branch ${t}`]
    }, m;
  }
  if (o === void 0 || !o) {
    const m = new Error(
      'Incorrect usage of "merge". Branch to be merged (' + t + ") has no commits"
    );
    throw m.hash = {
      text: `merge ${t}`,
      token: `merge ${t}`,
      expected: ['"commit"']
    }, m;
  }
  if (l === o) {
    const m = new Error('Incorrect usage of "merge". Both branches have same head');
    throw m.hash = {
      text: `merge ${t}`,
      token: `merge ${t}`,
      expected: ["branch abc"]
    }, m;
  }
  if (e && s.records.commits.has(e)) {
    const m = new Error(
      'Incorrect usage of "merge". Commit with id:' + e + " already exists, use different custom Id"
    );
    throw m.hash = {
      text: `merge ${t} ${e} ${a} ${c == null ? void 0 : c.join(" ")}`,
      token: `merge ${t} ${e} ${a} ${c == null ? void 0 : c.join(" ")}`,
      expected: [
        `merge ${t} ${e}_UNIQUE ${a} ${c == null ? void 0 : c.join(" ")}`
      ]
    }, m;
  }
  const n = d || "", u = {
    id: e || `${s.records.seq}-${S()}`,
    message: `merged branch ${t} into ${s.records.currBranch}`,
    seq: s.records.seq++,
    parents: s.records.head == null ? [] : [s.records.head.id, n],
    branch: s.records.currBranch,
    type: x.MERGE,
    customType: a,
    customId: !!e,
    tags: c ?? []
  };
  s.records.head = u, s.records.commits.set(u.id, u), s.records.branches.set(s.records.currBranch, u.id), w.debug(s.records.branches), w.debug("in mergeBranch");
}, "merge"), Bt = /* @__PURE__ */ $(function(r) {
  let t = r.id, e = r.targetId, a = r.tags, c = r.parent;
  w.debug("Entering cherryPick:", t, e, a);
  const i = O();
  if (t = k.sanitizeText(t, i), e = k.sanitizeText(e, i), a = a == null ? void 0 : a.map((l) => k.sanitizeText(l, i)), c = k.sanitizeText(c, i), !t || !s.records.commits.has(t)) {
    const l = new Error(
      'Incorrect usage of "cherryPick". Source commit id should exist and provided'
    );
    throw l.hash = {
      text: `cherryPick ${t} ${e}`,
      token: `cherryPick ${t} ${e}`,
      expected: ["cherry-pick abc"]
    }, l;
  }
  const h = s.records.commits.get(t);
  if (h === void 0 || !h)
    throw new Error('Incorrect usage of "cherryPick". Source commit id should exist and provided');
  if (c && !(Array.isArray(h.parents) && h.parents.includes(c)))
    throw new Error(
      "Invalid operation: The specified parent commit is not an immediate parent of the cherry-picked commit."
    );
  const d = h.branch;
  if (h.type === x.MERGE && !c)
    throw new Error(
      "Incorrect usage of cherry-pick: If the source commit is a merge commit, an immediate parent commit must be specified."
    );
  if (!e || !s.records.commits.has(e)) {
    if (d === s.records.currBranch) {
      const u = new Error(
        'Incorrect usage of "cherryPick". Source commit is already on current branch'
      );
      throw u.hash = {
        text: `cherryPick ${t} ${e}`,
        token: `cherryPick ${t} ${e}`,
        expected: ["cherry-pick abc"]
      }, u;
    }
    const l = s.records.branches.get(s.records.currBranch);
    if (l === void 0 || !l) {
      const u = new Error(
        `Incorrect usage of "cherry-pick". Current branch (${s.records.currBranch})has no commits`
      );
      throw u.hash = {
        text: `cherryPick ${t} ${e}`,
        token: `cherryPick ${t} ${e}`,
        expected: ["cherry-pick abc"]
      }, u;
    }
    const o = s.records.commits.get(l);
    if (o === void 0 || !o) {
      const u = new Error(
        `Incorrect usage of "cherry-pick". Current branch (${s.records.currBranch})has no commits`
      );
      throw u.hash = {
        text: `cherryPick ${t} ${e}`,
        token: `cherryPick ${t} ${e}`,
        expected: ["cherry-pick abc"]
      }, u;
    }
    const n = {
      id: s.records.seq + "-" + S(),
      message: `cherry-picked ${h == null ? void 0 : h.message} into ${s.records.currBranch}`,
      seq: s.records.seq++,
      parents: s.records.head == null ? [] : [s.records.head.id, h.id],
      branch: s.records.currBranch,
      type: x.CHERRY_PICK,
      tags: a ? a.filter(Boolean) : [
        `cherry-pick:${h.id}${h.type === x.MERGE ? `|parent:${c}` : ""}`
      ]
    };
    s.records.head = n, s.records.commits.set(n.id, n), s.records.branches.set(s.records.currBranch, n.id), w.debug(s.records.branches), w.debug("in cherryPick");
  }
}, "cherryPick"), K = /* @__PURE__ */ $(function(r) {
  if (r = k.sanitizeText(r, O()), s.records.branches.has(r)) {
    s.records.currBranch = r;
    const t = s.records.branches.get(s.records.currBranch);
    t === void 0 || !t ? s.records.head = null : s.records.head = s.records.commits.get(t) ?? null;
  } else {
    const t = new Error(
      `Trying to checkout branch which is not yet created. (Help try using "branch ${r}")`
    );
    throw t.hash = {
      text: `checkout ${r}`,
      token: `checkout ${r}`,
      expected: [`branch ${r}`]
    }, t;
  }
}, "checkout");
function N(r, t, e) {
  const a = r.indexOf(t);
  a === -1 ? r.push(e) : r.splice(a, 1, e);
}
$(N, "upsert");
function _(r) {
  const t = r.reduce((c, i) => c.seq > i.seq ? c : i, r[0]);
  let e = "";
  r.forEach(function(c) {
    c === t ? e += "	*" : e += "	|";
  });
  const a = [e, t.id, t.seq];
  for (const c in s.records.branches)
    s.records.branches.get(c) === t.id && a.push(c);
  if (w.debug(a.join(" ")), t.parents && t.parents.length == 2 && t.parents[0] && t.parents[1]) {
    const c = s.records.commits.get(t.parents[0]);
    N(r, t, c), t.parents[1] && r.push(s.records.commits.get(t.parents[1]));
  } else {
    if (t.parents.length == 0)
      return;
    if (t.parents[0]) {
      const c = s.records.commits.get(t.parents[0]);
      N(r, t, c);
    }
  }
  r = F(r, (c) => c.id), _(r);
}
$(_, "prettyPrintCommitHistory");
var Et = /* @__PURE__ */ $(function() {
  w.debug(s.records.commits);
  const r = Y()[0];
  _([r]);
}, "prettyPrint"), vt = /* @__PURE__ */ $(function() {
  s.reset(), dt();
}, "clear"), Ct = /* @__PURE__ */ $(function() {
  return [...s.records.branchConfig.values()].map((r, t) => r.order !== null && r.order !== void 0 ? r : {
    ...r,
    order: parseFloat(`0.${t}`)
  }).sort((r, t) => (r.order ?? 0) - (t.order ?? 0)).map(({ name: r }) => ({ name: r }));
}, "getBranchesAsObjArray"), kt = /* @__PURE__ */ $(function() {
  return s.records.branches;
}, "getBranches"), Tt = /* @__PURE__ */ $(function() {
  return s.records.commits;
}, "getCommits"), Y = /* @__PURE__ */ $(function() {
  const r = [...s.records.commits.values()];
  return r.forEach(function(t) {
    w.debug(t.id);
  }), r.sort((t, e) => t.seq - e.seq), r;
}, "getCommitsArray"), Lt = /* @__PURE__ */ $(function() {
  return s.records.currBranch;
}, "getCurrentBranch"), Mt = /* @__PURE__ */ $(function() {
  return s.records.direction;
}, "getDirection"), Pt = /* @__PURE__ */ $(function() {
  return s.records.head;
}, "getHead"), V = {
  commitType: x,
  getConfig: O,
  setDirection: pt,
  setOptions: ft,
  getOptions: ut,
  commit: xt,
  branch: bt,
  merge: wt,
  cherryPick: Bt,
  checkout: K,
  //reset,
  prettyPrint: Et,
  clear: vt,
  getBranchesAsObjArray: Ct,
  getBranches: kt,
  getCommits: Tt,
  getCommitsArray: Y,
  getCurrentBranch: Lt,
  getDirection: Mt,
  getHead: Pt,
  setAccTitle: nt,
  getAccTitle: ot,
  getAccDescription: et,
  setAccDescription: rt,
  setDiagramTitle: tt,
  getDiagramTitle: Z
}, Rt = /* @__PURE__ */ $((r, t) => {
  Q(r, t), r.dir && t.setDirection(r.dir);
  for (const e of r.statements)
    At(e, t);
}, "populate"), At = /* @__PURE__ */ $((r, t) => {
  const e = {
    Commit: /* @__PURE__ */ $((a) => t.commit(It(a)), "Commit"),
    Branch: /* @__PURE__ */ $((a) => t.branch(Gt(a)), "Branch"),
    Merge: /* @__PURE__ */ $((a) => t.merge(Ot(a)), "Merge"),
    Checkout: /* @__PURE__ */ $((a) => t.checkout(qt(a)), "Checkout"),
    CherryPicking: /* @__PURE__ */ $((a) => t.cherryPick(Dt(a)), "CherryPicking")
  }[r.$type];
  e ? e(r) : w.error(`Unknown statement type: ${r.$type}`);
}, "parseStatement"), It = /* @__PURE__ */ $((r) => ({
  id: r.id,
  msg: r.message ?? "",
  type: r.type !== void 0 ? x[r.type] : x.NORMAL,
  tags: r.tags ?? void 0
}), "parseCommit"), Gt = /* @__PURE__ */ $((r) => ({
  name: r.name,
  order: r.order ?? 0
}), "parseBranch"), Ot = /* @__PURE__ */ $((r) => ({
  branch: r.branch,
  id: r.id ?? "",
  type: r.type !== void 0 ? x[r.type] : void 0,
  tags: r.tags ?? void 0
}), "parseMerge"), qt = /* @__PURE__ */ $((r) => r.branch, "parseCheckout"), Dt = /* @__PURE__ */ $((r) => {
  var t;
  return {
    id: r.id,
    targetId: "",
    tags: ((t = r.tags) == null ? void 0 : t.length) === 0 ? void 0 : r.tags,
    parent: r.parent
  };
}, "parseCherryPicking"), Ht = {
  parse: /* @__PURE__ */ $(async (r) => {
    const t = await gt("gitGraph", r);
    w.debug(t), Rt(t, V);
  }, "parse")
}, W = at(), E = W == null ? void 0 : W.gitGraph, A = 10, I = 40, T = 4, M = 2, G = 8, v = /* @__PURE__ */ new Map(), C = /* @__PURE__ */ new Map(), H = 30, q = /* @__PURE__ */ new Map(), z = [], R = 0, f = "LR", zt = /* @__PURE__ */ $(() => {
  v.clear(), C.clear(), q.clear(), R = 0, z = [], f = "LR";
}, "clear"), U = /* @__PURE__ */ $((r) => {
  const t = document.createElementNS("http://www.w3.org/2000/svg", "text");
  return (typeof r == "string" ? r.split(/\\n|\n|<br\s*\/?>/gi) : r).forEach((e) => {
    const a = document.createElementNS("http://www.w3.org/2000/svg", "tspan");
    a.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:space", "preserve"), a.setAttribute("dy", "1em"), a.setAttribute("x", "0"), a.setAttribute("class", "row"), a.textContent = e.trim(), t.appendChild(a);
  }), t;
}, "drawText"), J = /* @__PURE__ */ $((r) => {
  let t, e, a;
  return f === "BT" ? (e = /* @__PURE__ */ $((c, i) => c <= i, "comparisonFunc"), a = 1 / 0) : (e = /* @__PURE__ */ $((c, i) => c >= i, "comparisonFunc"), a = 0), r.forEach((c) => {
    var i, h;
    const d = f === "TB" || f == "BT" ? (i = C.get(c)) == null ? void 0 : i.y : (h = C.get(c)) == null ? void 0 : h.x;
    d !== void 0 && e(d, a) && (t = c, a = d);
  }), t;
}, "findClosestParent"), St = /* @__PURE__ */ $((r) => {
  let t = "", e = 1 / 0;
  return r.forEach((a) => {
    const c = C.get(a).y;
    c <= e && (t = a, e = c);
  }), t || void 0;
}, "findClosestParentBT"), Nt = /* @__PURE__ */ $((r, t, e) => {
  let a = e, c = e;
  const i = [];
  r.forEach((h) => {
    const d = t.get(h);
    if (!d)
      throw new Error(`Commit not found for key ${h}`);
    d.parents.length ? (a = Wt(d), c = Math.max(a, c)) : i.push(d), jt(d, a);
  }), a = c, i.forEach((h) => {
    Ft(h, a, e);
  }), r.forEach((h) => {
    const d = t.get(h);
    if (d != null && d.parents.length) {
      const l = St(d.parents);
      a = C.get(l).y - I, a <= c && (c = a);
      const o = v.get(d.branch).pos, n = a - A;
      C.set(d.id, { x: o, y: n });
    }
  });
}, "setParallelBTPos"), _t = /* @__PURE__ */ $((r) => {
  var t;
  const e = J(r.parents.filter((c) => c !== null));
  if (!e)
    throw new Error(`Closest parent not found for commit ${r.id}`);
  const a = (t = C.get(e)) == null ? void 0 : t.y;
  if (a === void 0)
    throw new Error(`Closest parent position not found for commit ${r.id}`);
  return a;
}, "findClosestParentPos"), Wt = /* @__PURE__ */ $((r) => _t(r) + I, "calculateCommitPosition"), jt = /* @__PURE__ */ $((r, t) => {
  const e = v.get(r.branch);
  if (!e)
    throw new Error(`Branch not found for commit ${r.id}`);
  const a = e.pos, c = t + A;
  return C.set(r.id, { x: a, y: c }), { x: a, y: c };
}, "setCommitPosition"), Ft = /* @__PURE__ */ $((r, t, e) => {
  const a = v.get(r.branch);
  if (!a)
    throw new Error(`Branch not found for commit ${r.id}`);
  const c = t + e, i = a.pos;
  C.set(r.id, { x: i, y: c });
}, "setRootPosition"), Kt = /* @__PURE__ */ $((r, t, e, a, c, i) => {
  if (i === x.HIGHLIGHT)
    r.append("rect").attr("x", e.x - 10).attr("y", e.y - 10).attr("width", 20).attr("height", 20).attr(
      "class",
      `commit ${t.id} commit-highlight${c % G} ${a}-outer`
    ), r.append("rect").attr("x", e.x - 6).attr("y", e.y - 6).attr("width", 12).attr("height", 12).attr(
      "class",
      `commit ${t.id} commit${c % G} ${a}-inner`
    );
  else if (i === x.CHERRY_PICK)
    r.append("circle").attr("cx", e.x).attr("cy", e.y).attr("r", 10).attr("class", `commit ${t.id} ${a}`), r.append("circle").attr("cx", e.x - 3).attr("cy", e.y + 2).attr("r", 2.75).attr("fill", "#fff").attr("class", `commit ${t.id} ${a}`), r.append("circle").attr("cx", e.x + 3).attr("cy", e.y + 2).attr("r", 2.75).attr("fill", "#fff").attr("class", `commit ${t.id} ${a}`), r.append("line").attr("x1", e.x + 3).attr("y1", e.y + 1).attr("x2", e.x).attr("y2", e.y - 5).attr("stroke", "#fff").attr("class", `commit ${t.id} ${a}`), r.append("line").attr("x1", e.x - 3).attr("y1", e.y + 1).attr("x2", e.x).attr("y2", e.y - 5).attr("stroke", "#fff").attr("class", `commit ${t.id} ${a}`);
  else {
    const h = r.append("circle");
    if (h.attr("cx", e.x), h.attr("cy", e.y), h.attr("r", t.type === x.MERGE ? 9 : 10), h.attr("class", `commit ${t.id} commit${c % G}`), i === x.MERGE) {
      const d = r.append("circle");
      d.attr("cx", e.x), d.attr("cy", e.y), d.attr("r", 6), d.attr(
        "class",
        `commit ${a} ${t.id} commit${c % G}`
      );
    }
    i === x.REVERSE && r.append("path").attr(
      "d",
      `M ${e.x - 5},${e.y - 5}L${e.x + 5},${e.y + 5}M${e.x - 5},${e.y + 5}L${e.x + 5},${e.y - 5}`
    ).attr("class", `commit ${a} ${t.id} commit${c % G}`);
  }
}, "drawCommitBullet"), Yt = /* @__PURE__ */ $((r, t, e, a) => {
  var c;
  if (t.type !== x.CHERRY_PICK && (t.customId && t.type === x.MERGE || t.type !== x.MERGE) && E != null && E.showCommitLabel) {
    const i = r.append("g"), h = i.insert("rect").attr("class", "commit-label-bkg"), d = i.append("text").attr("x", a).attr("y", e.y + 25).attr("class", "commit-label").text(t.id), l = (c = d.node()) == null ? void 0 : c.getBBox();
    if (l && (h.attr("x", e.posWithOffset - l.width / 2 - M).attr("y", e.y + 13.5).attr("width", l.width + 2 * M).attr("height", l.height + 2 * M), f === "TB" || f === "BT" ? (h.attr("x", e.x - (l.width + 4 * T + 5)).attr("y", e.y - 12), d.attr("x", e.x - (l.width + 4 * T)).attr("y", e.y + l.height - 12)) : d.attr("x", e.posWithOffset - l.width / 2), E.rotateCommitLabel))
      if (f === "TB" || f === "BT")
        d.attr(
          "transform",
          "rotate(-45, " + e.x + ", " + e.y + ")"
        ), h.attr(
          "transform",
          "rotate(-45, " + e.x + ", " + e.y + ")"
        );
      else {
        const o = -7.5 - (l.width + 10) / 25 * 9.5, n = 10 + l.width / 25 * 8.5;
        i.attr(
          "transform",
          "translate(" + o + ", " + n + ") rotate(-45, " + a + ", " + e.y + ")"
        );
      }
  }
}, "drawCommitLabel"), Vt = /* @__PURE__ */ $((r, t, e, a) => {
  var c;
  if (t.tags.length > 0) {
    let i = 0, h = 0, d = 0;
    const l = [];
    for (const o of t.tags.reverse()) {
      const n = r.insert("polygon"), u = r.append("circle"), m = r.append("text").attr("y", e.y - 16 - i).attr("class", "tag-label").text(o), g = (c = m.node()) == null ? void 0 : c.getBBox();
      if (!g)
        throw new Error("Tag bbox not found");
      h = Math.max(h, g.width), d = Math.max(d, g.height), m.attr("x", e.posWithOffset - g.width / 2), l.push({
        tag: m,
        hole: u,
        rect: n,
        yOffset: i
      }), i += 20;
    }
    for (const { tag: o, hole: n, rect: u, yOffset: m } of l) {
      const g = d / 2, p = e.y - 19.2 - m;
      if (u.attr("class", "tag-label-bkg").attr(
        "points",
        `
      ${a - h / 2 - T / 2},${p + M}  
      ${a - h / 2 - T / 2},${p - M}
      ${e.posWithOffset - h / 2 - T},${p - g - M}
      ${e.posWithOffset + h / 2 + T},${p - g - M}
      ${e.posWithOffset + h / 2 + T},${p + g + M}
      ${e.posWithOffset - h / 2 - T},${p + g + M}`
      ), n.attr("cy", p).attr("cx", a - h / 2 + T / 2).attr("r", 1.5).attr("class", "tag-hole"), f === "TB" || f === "BT") {
        const y = a + m;
        u.attr("class", "tag-label-bkg").attr(
          "points",
          `
        ${e.x},${y + 2}
        ${e.x},${y - 2}
        ${e.x + A},${y - g - 2}
        ${e.x + A + h + 4},${y - g - 2}
        ${e.x + A + h + 4},${y + g + 2}
        ${e.x + A},${y + g + 2}`
        ).attr("transform", "translate(12,12) rotate(45, " + e.x + "," + a + ")"), n.attr("cx", e.x + T / 2).attr("cy", y).attr("transform", "translate(12,12) rotate(45, " + e.x + "," + a + ")"), o.attr("x", e.x + 5).attr("y", y + 3).attr("transform", "translate(14,14) rotate(45, " + e.x + "," + a + ")");
      }
    }
  }
}, "drawCommitTags"), Ut = /* @__PURE__ */ $((r) => {
  switch (r.customType ?? r.type) {
    case x.NORMAL:
      return "commit-normal";
    case x.REVERSE:
      return "commit-reverse";
    case x.HIGHLIGHT:
      return "commit-highlight";
    case x.MERGE:
      return "commit-merge";
    case x.CHERRY_PICK:
      return "commit-cherry-pick";
    default:
      return "commit-normal";
  }
}, "getCommitClassType"), Jt = /* @__PURE__ */ $((r, t, e, a) => {
  const c = { x: 0, y: 0 };
  if (r.parents.length > 0) {
    const i = J(r.parents);
    if (i) {
      const h = a.get(i) ?? c;
      return t === "TB" ? h.y + I : t === "BT" ? (a.get(r.id) ?? c).y - I : h.x + I;
    }
  } else
    return t === "TB" ? H : t === "BT" ? (a.get(r.id) ?? c).y - I : 0;
  return 0;
}, "calculatePosition"), Qt = /* @__PURE__ */ $((r, t, e) => {
  var a, c;
  const i = f === "BT" && e ? t : t + A, h = f === "TB" || f === "BT" ? i : (a = v.get(r.branch)) == null ? void 0 : a.pos, d = f === "TB" || f === "BT" ? (c = v.get(r.branch)) == null ? void 0 : c.pos : i;
  if (d === void 0 || h === void 0)
    throw new Error(`Position were undefined for commit ${r.id}`);
  return { x: d, y: h, posWithOffset: i };
}, "getCommitPosition"), j = /* @__PURE__ */ $((r, t, e) => {
  if (!E)
    throw new Error("GitGraph config not found");
  const a = r.append("g").attr("class", "commit-bullets"), c = r.append("g").attr("class", "commit-labels");
  let i = f === "TB" || f === "BT" ? H : 0;
  const h = [...t.keys()], d = (E == null ? void 0 : E.parallelCommits) ?? !1, l = /* @__PURE__ */ $((n, u) => {
    var m, g;
    const p = (m = t.get(n)) == null ? void 0 : m.seq, y = (g = t.get(u)) == null ? void 0 : g.seq;
    return p !== void 0 && y !== void 0 ? p - y : 0;
  }, "sortKeys");
  let o = h.sort(l);
  f === "BT" && (d && Nt(o, t, i), o = o.reverse()), o.forEach((n) => {
    var u;
    const m = t.get(n);
    if (!m)
      throw new Error(`Commit not found for key ${n}`);
    d && (i = Jt(m, f, i, C));
    const g = Qt(m, i, d);
    if (e) {
      const p = Ut(m), y = m.customType ?? m.type, L = ((u = v.get(m.branch)) == null ? void 0 : u.index) ?? 0;
      Kt(a, m, g, p, L, y), Yt(c, m, g, i), Vt(c, m, g, i);
    }
    f === "TB" || f === "BT" ? C.set(m.id, { x: g.x, y: g.posWithOffset }) : C.set(m.id, { x: g.posWithOffset, y: g.y }), i = f === "BT" && d ? i + I : i + I + A, i > R && (R = i);
  });
}, "drawCommits"), Xt = /* @__PURE__ */ $((r, t, e, a, c) => {
  const i = (f === "TB" || f === "BT" ? e.x < a.x : e.y < a.y) ? t.branch : r.branch, h = /* @__PURE__ */ $((l) => l.branch === i, "isOnBranchToGetCurve"), d = /* @__PURE__ */ $((l) => l.seq > r.seq && l.seq < t.seq, "isBetweenCommits");
  return [...c.values()].some((l) => d(l) && h(l));
}, "shouldRerouteArrow"), D = /* @__PURE__ */ $((r, t, e = 0) => {
  const a = r + Math.abs(r - t) / 2;
  if (e > 5)
    return a;
  if (z.every((i) => Math.abs(i - a) >= 10))
    return z.push(a), a;
  const c = Math.abs(r - t);
  return D(r, t - c / 5, e + 1);
}, "findLane"), Zt = /* @__PURE__ */ $((r, t, e, a) => {
  var c, i, h, d, l;
  const o = C.get(t.id), n = C.get(e.id);
  if (o === void 0 || n === void 0)
    throw new Error(`Commit positions not found for commits ${t.id} and ${e.id}`);
  const u = Xt(t, e, o, n, a);
  let m = "", g = "", p = 0, y = 0, L = (c = v.get(e.branch)) == null ? void 0 : c.index;
  e.type === x.MERGE && t.id !== e.parents[0] && (L = (i = v.get(t.branch)) == null ? void 0 : i.index);
  let b;
  if (u) {
    m = "A 10 10, 0, 0, 0,", g = "A 10 10, 0, 0, 1,", p = 10, y = 10;
    const P = o.y < n.y ? D(o.y, n.y) : D(n.y, o.y), B = o.x < n.x ? D(o.x, n.x) : D(n.x, o.x);
    f === "TB" ? o.x < n.x ? b = `M ${o.x} ${o.y} L ${B - p} ${o.y} ${g} ${B} ${o.y + y} L ${B} ${n.y - p} ${m} ${B + y} ${n.y} L ${n.x} ${n.y}` : (L = (h = v.get(t.branch)) == null ? void 0 : h.index, b = `M ${o.x} ${o.y} L ${B + p} ${o.y} ${m} ${B} ${o.y + y} L ${B} ${n.y - p} ${g} ${B - y} ${n.y} L ${n.x} ${n.y}`) : f === "BT" ? o.x < n.x ? b = `M ${o.x} ${o.y} L ${B - p} ${o.y} ${m} ${B} ${o.y - y} L ${B} ${n.y + p} ${g} ${B + y} ${n.y} L ${n.x} ${n.y}` : (L = (d = v.get(t.branch)) == null ? void 0 : d.index, b = `M ${o.x} ${o.y} L ${B + p} ${o.y} ${g} ${B} ${o.y - y} L ${B} ${n.y + p} ${m} ${B - y} ${n.y} L ${n.x} ${n.y}`) : o.y < n.y ? b = `M ${o.x} ${o.y} L ${o.x} ${P - p} ${m} ${o.x + y} ${P} L ${n.x - p} ${P} ${g} ${n.x} ${P + y} L ${n.x} ${n.y}` : (L = (l = v.get(t.branch)) == null ? void 0 : l.index, b = `M ${o.x} ${o.y} L ${o.x} ${P + p} ${g} ${o.x + y} ${P} L ${n.x - p} ${P} ${m} ${n.x} ${P - y} L ${n.x} ${n.y}`);
  } else
    m = "A 20 20, 0, 0, 0,", g = "A 20 20, 0, 0, 1,", p = 20, y = 20, f === "TB" ? (o.x < n.x && (e.type === x.MERGE && t.id !== e.parents[0] ? b = `M ${o.x} ${o.y} L ${o.x} ${n.y - p} ${m} ${o.x + y} ${n.y} L ${n.x} ${n.y}` : b = `M ${o.x} ${o.y} L ${n.x - p} ${o.y} ${g} ${n.x} ${o.y + y} L ${n.x} ${n.y}`), o.x > n.x && (m = "A 20 20, 0, 0, 0,", g = "A 20 20, 0, 0, 1,", p = 20, y = 20, e.type === x.MERGE && t.id !== e.parents[0] ? b = `M ${o.x} ${o.y} L ${o.x} ${n.y - p} ${g} ${o.x - y} ${n.y} L ${n.x} ${n.y}` : b = `M ${o.x} ${o.y} L ${n.x + p} ${o.y} ${m} ${n.x} ${o.y + y} L ${n.x} ${n.y}`), o.x === n.x && (b = `M ${o.x} ${o.y} L ${n.x} ${n.y}`)) : f === "BT" ? (o.x < n.x && (e.type === x.MERGE && t.id !== e.parents[0] ? b = `M ${o.x} ${o.y} L ${o.x} ${n.y + p} ${g} ${o.x + y} ${n.y} L ${n.x} ${n.y}` : b = `M ${o.x} ${o.y} L ${n.x - p} ${o.y} ${m} ${n.x} ${o.y - y} L ${n.x} ${n.y}`), o.x > n.x && (m = "A 20 20, 0, 0, 0,", g = "A 20 20, 0, 0, 1,", p = 20, y = 20, e.type === x.MERGE && t.id !== e.parents[0] ? b = `M ${o.x} ${o.y} L ${o.x} ${n.y + p} ${m} ${o.x - y} ${n.y} L ${n.x} ${n.y}` : b = `M ${o.x} ${o.y} L ${n.x - p} ${o.y} ${m} ${n.x} ${o.y - y} L ${n.x} ${n.y}`), o.x === n.x && (b = `M ${o.x} ${o.y} L ${n.x} ${n.y}`)) : (o.y < n.y && (e.type === x.MERGE && t.id !== e.parents[0] ? b = `M ${o.x} ${o.y} L ${n.x - p} ${o.y} ${g} ${n.x} ${o.y + y} L ${n.x} ${n.y}` : b = `M ${o.x} ${o.y} L ${o.x} ${n.y - p} ${m} ${o.x + y} ${n.y} L ${n.x} ${n.y}`), o.y > n.y && (e.type === x.MERGE && t.id !== e.parents[0] ? b = `M ${o.x} ${o.y} L ${n.x - p} ${o.y} ${m} ${n.x} ${o.y - y} L ${n.x} ${n.y}` : b = `M ${o.x} ${o.y} L ${o.x} ${n.y + p} ${g} ${o.x + y} ${n.y} L ${n.x} ${n.y}`), o.y === n.y && (b = `M ${o.x} ${o.y} L ${n.x} ${n.y}`));
  if (b === void 0)
    throw new Error("Line definition not found");
  r.append("path").attr("d", b).attr("class", "arrow arrow" + L % G);
}, "drawArrow"), tr = /* @__PURE__ */ $((r, t) => {
  const e = r.append("g").attr("class", "commit-arrows");
  [...t.keys()].forEach((a) => {
    const c = t.get(a);
    c.parents && c.parents.length > 0 && c.parents.forEach((i) => {
      Zt(e, t.get(i), c, t);
    });
  });
}, "drawArrows"), rr = /* @__PURE__ */ $((r, t) => {
  const e = r.append("g");
  t.forEach((a, c) => {
    var i;
    const h = c % G, d = (i = v.get(a.name)) == null ? void 0 : i.pos;
    if (d === void 0)
      throw new Error(`Position not found for branch ${a.name}`);
    const l = e.append("line");
    l.attr("x1", 0), l.attr("y1", d), l.attr("x2", R), l.attr("y2", d), l.attr("class", "branch branch" + h), f === "TB" ? (l.attr("y1", H), l.attr("x1", d), l.attr("y2", R), l.attr("x2", d)) : f === "BT" && (l.attr("y1", R), l.attr("x1", d), l.attr("y2", H), l.attr("x2", d)), z.push(d);
    const o = a.name, n = U(o), u = e.insert("rect"), m = e.insert("g").attr("class", "branchLabel").insert("g").attr("class", "label branch-label" + h);
    m.node().appendChild(n);
    const g = n.getBBox();
    u.attr("class", "branchLabelBkg label" + h).attr("rx", 4).attr("ry", 4).attr("x", -g.width - 4 - ((E == null ? void 0 : E.rotateCommitLabel) === !0 ? 30 : 0)).attr("y", -g.height / 2 + 8).attr("width", g.width + 18).attr("height", g.height + 4), m.attr(
      "transform",
      "translate(" + (-g.width - 14 - ((E == null ? void 0 : E.rotateCommitLabel) === !0 ? 30 : 0)) + ", " + (d - g.height / 2 - 1) + ")"
    ), f === "TB" ? (u.attr("x", d - g.width / 2 - 10).attr("y", 0), m.attr("transform", "translate(" + (d - g.width / 2 - 5) + ", 0)")) : f === "BT" ? (u.attr("x", d - g.width / 2 - 10).attr("y", R), m.attr("transform", "translate(" + (d - g.width / 2 - 5) + ", " + R + ")")) : u.attr("transform", "translate(-19, " + (d - g.height / 2) + ")");
  });
}, "drawBranches"), er = /* @__PURE__ */ $(function(r, t, e, a, c) {
  return v.set(r, { pos: t, index: e }), t += 50 + (c ? 40 : 0) + (f === "TB" || f === "BT" ? a.width / 2 : 0), t;
}, "setBranchPosition"), or = /* @__PURE__ */ $(function(r, t, e, a) {
  if (zt(), w.debug("in gitgraph renderer", r + `
`, "id:", t, e), !E)
    throw new Error("GitGraph config not found");
  const c = E.rotateCommitLabel ?? !1, i = a.db;
  q = i.getCommits();
  const h = i.getBranchesAsObjArray();
  f = i.getDirection();
  const d = ct(`[id="${t}"]`);
  let l = 0;
  h.forEach((o, n) => {
    var u;
    const m = U(o.name), g = d.append("g"), p = g.insert("g").attr("class", "branchLabel"), y = p.insert("g").attr("class", "label branch-label");
    (u = y.node()) == null || u.appendChild(m);
    const L = m.getBBox();
    l = er(o.name, l, n, L, c), y.remove(), p.remove(), g.remove();
  }), j(d, q, !1), E.showBranches && rr(d, h), tr(d, q), j(d, q, !0), it.insertTitle(
    d,
    "gitTitleText",
    E.titleTopMargin ?? 0,
    i.getDiagramTitle()
  ), st(
    void 0,
    d,
    E.diagramPadding,
    E.useMaxWidth
  );
}, "draw"), nr = {
  draw: or
}, ar = /* @__PURE__ */ $((r) => `
  .commit-id,
  .commit-msg,
  .branch-label {
    fill: lightgrey;
    color: lightgrey;
    font-family: 'trebuchet ms', verdana, arial, sans-serif;
    font-family: var(--mermaid-font-family);
  }
  ${[0, 1, 2, 3, 4, 5, 6, 7].map(
  (t) => `
        .branch-label${t} { fill: ${r["gitBranchLabel" + t]}; }
        .commit${t} { stroke: ${r["git" + t]}; fill: ${r["git" + t]}; }
        .commit-highlight${t} { stroke: ${r["gitInv" + t]}; fill: ${r["gitInv" + t]}; }
        .label${t}  { fill: ${r["git" + t]}; }
        .arrow${t} { stroke: ${r["git" + t]}; }
        `
).join(`
`)}

  .branch {
    stroke-width: 1;
    stroke: ${r.lineColor};
    stroke-dasharray: 2;
  }
  .commit-label { font-size: ${r.commitLabelFontSize}; fill: ${r.commitLabelColor};}
  .commit-label-bkg { font-size: ${r.commitLabelFontSize}; fill: ${r.commitLabelBackground}; opacity: 0.5; }
  .tag-label { font-size: ${r.tagLabelFontSize}; fill: ${r.tagLabelColor};}
  .tag-label-bkg { fill: ${r.tagLabelBackground}; stroke: ${r.tagLabelBorder}; }
  .tag-hole { fill: ${r.textColor}; }

  .commit-merge {
    stroke: ${r.primaryColor};
    fill: ${r.primaryColor};
  }
  .commit-reverse {
    stroke: ${r.primaryColor};
    fill: ${r.primaryColor};
    stroke-width: 3;
  }
  .commit-highlight-outer {
  }
  .commit-highlight-inner {
    stroke: ${r.primaryColor};
    fill: ${r.primaryColor};
  }

  .arrow { stroke-width: 8; stroke-linecap: round; fill: none}
  .gitTitleText {
    text-anchor: middle;
    font-size: 18px;
    fill: ${r.textColor};
  }
`, "getStyles"), cr = ar, mr = {
  parser: Ht,
  db: V,
  renderer: nr,
  styles: cr
};
export {
  mr as diagram
};
