import { p as V } from "./chunk-4BX2VUAB-C9R2rIjS.js";
import { I as X } from "./chunk-QZHKN3VN-Q3PAlxxo.js";
import { p as J, o as Q, s as Z, g as rr, a as er, b as tr, _ as $, l as m, u as ar, C as sr, y as nr, j as E, D as or, E as cr, F as ir, G as dr } from "./mermaid.core-CYBWUA0z.js";
import { p as hr } from "./mermaid-parser.core-Df9ZUR77.js";
import { s as lr } from "./transform-QfIdy88w.js";
var p = {
  NORMAL: 0,
  REVERSE: 1,
  HIGHLIGHT: 2,
  MERGE: 3,
  CHERRY_PICK: 4
}, $r = cr.gitGraph, q = /* @__PURE__ */ $(() => or({
  ...$r,
  ...ir().gitGraph
}), "getConfig"), i = new X(() => {
  const t = q(), r = t.mainBranchName, a = t.mainBranchOrder;
  return {
    mainBranchName: r,
    commits: /* @__PURE__ */ new Map(),
    head: null,
    branchConfig: /* @__PURE__ */ new Map([[r, { name: r, order: a }]]),
    branches: /* @__PURE__ */ new Map([[r, null]]),
    currBranch: r,
    direction: "LR",
    seq: 0,
    options: {}
  };
});
function z() {
  return dr({ length: 7 });
}
$(z, "getID");
function W(t, r) {
  const a = /* @__PURE__ */ Object.create(null);
  return t.reduce((n, e) => {
    const s = r(e);
    return a[s] || (a[s] = !0, n.push(e)), n;
  }, []);
}
$(W, "uniqBy");
var fr = /* @__PURE__ */ $(function(t) {
  i.records.direction = t;
}, "setDirection"), yr = /* @__PURE__ */ $(function(t) {
  m.debug("options str", t), t = t == null ? void 0 : t.trim(), t = t || "{}";
  try {
    i.records.options = JSON.parse(t);
  } catch (r) {
    m.error("error while parsing gitGraph options", r.message);
  }
}, "setOptions"), gr = /* @__PURE__ */ $(function() {
  return i.records.options;
}, "getOptions"), xr = /* @__PURE__ */ $(function(t) {
  let r = t.msg, a = t.id;
  const n = t.type;
  let e = t.tags;
  m.info("commit", r, a, n, e), m.debug("Entering commit:", r, a, n, e);
  const s = q();
  a = E.sanitizeText(a, s), r = E.sanitizeText(r, s), e = e == null ? void 0 : e.map((c) => E.sanitizeText(c, s));
  const o = {
    id: a || i.records.seq + "-" + z(),
    message: r,
    seq: i.records.seq++,
    type: n ?? p.NORMAL,
    tags: e ?? [],
    parents: i.records.head == null ? [] : [i.records.head.id],
    branch: i.records.currBranch
  };
  i.records.head = o, m.info("main branch", s.mainBranchName), i.records.commits.has(o.id) && m.warn(`Commit ID ${o.id} already exists`), i.records.commits.set(o.id, o), i.records.branches.set(i.records.currBranch, o.id), m.debug("in pushCommit " + o.id);
}, "commit"), ur = /* @__PURE__ */ $(function(t) {
  let r = t.name;
  const a = t.order;
  if (r = E.sanitizeText(r, q()), i.records.branches.has(r))
    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 ${r}")`
    );
  i.records.branches.set(r, i.records.head != null ? i.records.head.id : null), i.records.branchConfig.set(r, { name: r, order: a }), j(r), m.debug("in createBranch");
}, "branch"), pr = /* @__PURE__ */ $((t) => {
  let r = t.branch, a = t.id;
  const n = t.type, e = t.tags, s = q();
  r = E.sanitizeText(r, s), a && (a = E.sanitizeText(a, s));
  const o = i.records.branches.get(i.records.currBranch), c = i.records.branches.get(r), d = o ? i.records.commits.get(o) : void 0, h = c ? i.records.commits.get(c) : void 0;
  if (d && h && d.branch === r)
    throw new Error(`Cannot merge branch '${r}' into itself.`);
  if (i.records.currBranch === r) {
    const l = new Error('Incorrect usage of "merge". Cannot merge a branch to itself');
    throw l.hash = {
      text: `merge ${r}`,
      token: `merge ${r}`,
      expected: ["branch abc"]
    }, l;
  }
  if (d === void 0 || !d) {
    const l = new Error(
      `Incorrect usage of "merge". Current branch (${i.records.currBranch})has no commits`
    );
    throw l.hash = {
      text: `merge ${r}`,
      token: `merge ${r}`,
      expected: ["commit"]
    }, l;
  }
  if (!i.records.branches.has(r)) {
    const l = new Error(
      'Incorrect usage of "merge". Branch to be merged (' + r + ") does not exist"
    );
    throw l.hash = {
      text: `merge ${r}`,
      token: `merge ${r}`,
      expected: [`branch ${r}`]
    }, l;
  }
  if (h === void 0 || !h) {
    const l = new Error(
      'Incorrect usage of "merge". Branch to be merged (' + r + ") has no commits"
    );
    throw l.hash = {
      text: `merge ${r}`,
      token: `merge ${r}`,
      expected: ['"commit"']
    }, l;
  }
  if (d === h) {
    const l = new Error('Incorrect usage of "merge". Both branches have same head');
    throw l.hash = {
      text: `merge ${r}`,
      token: `merge ${r}`,
      expected: ["branch abc"]
    }, l;
  }
  if (a && i.records.commits.has(a)) {
    const l = new Error(
      'Incorrect usage of "merge". Commit with id:' + a + " already exists, use different custom id"
    );
    throw l.hash = {
      text: `merge ${r} ${a} ${n} ${e == null ? void 0 : e.join(" ")}`,
      token: `merge ${r} ${a} ${n} ${e == null ? void 0 : e.join(" ")}`,
      expected: [
        `merge ${r} ${a}_UNIQUE ${n} ${e == null ? void 0 : e.join(" ")}`
      ]
    }, l;
  }
  const f = c || "", y = {
    id: a || `${i.records.seq}-${z()}`,
    message: `merged branch ${r} into ${i.records.currBranch}`,
    seq: i.records.seq++,
    parents: i.records.head == null ? [] : [i.records.head.id, f],
    branch: i.records.currBranch,
    type: p.MERGE,
    customType: n,
    customId: !!a,
    tags: e ?? []
  };
  i.records.head = y, i.records.commits.set(y.id, y), i.records.branches.set(i.records.currBranch, y.id), m.debug(i.records.branches), m.debug("in mergeBranch");
}, "merge"), br = /* @__PURE__ */ $(function(t) {
  let r = t.id, a = t.targetId, n = t.tags, e = t.parent;
  m.debug("Entering cherryPick:", r, a, n);
  const s = q();
  if (r = E.sanitizeText(r, s), a = E.sanitizeText(a, s), n = n == null ? void 0 : n.map((d) => E.sanitizeText(d, s)), e = E.sanitizeText(e, s), !r || !i.records.commits.has(r)) {
    const d = new Error(
      'Incorrect usage of "cherryPick". Source commit id should exist and provided'
    );
    throw d.hash = {
      text: `cherryPick ${r} ${a}`,
      token: `cherryPick ${r} ${a}`,
      expected: ["cherry-pick abc"]
    }, d;
  }
  const o = i.records.commits.get(r);
  if (o === void 0 || !o)
    throw new Error('Incorrect usage of "cherryPick". Source commit id should exist and provided');
  if (e && !(Array.isArray(o.parents) && o.parents.includes(e)))
    throw new Error(
      "Invalid operation: The specified parent commit is not an immediate parent of the cherry-picked commit."
    );
  const c = o.branch;
  if (o.type === p.MERGE && !e)
    throw new Error(
      "Incorrect usage of cherry-pick: If the source commit is a merge commit, an immediate parent commit must be specified."
    );
  if (!a || !i.records.commits.has(a)) {
    if (c === i.records.currBranch) {
      const y = new Error(
        'Incorrect usage of "cherryPick". Source commit is already on current branch'
      );
      throw y.hash = {
        text: `cherryPick ${r} ${a}`,
        token: `cherryPick ${r} ${a}`,
        expected: ["cherry-pick abc"]
      }, y;
    }
    const d = i.records.branches.get(i.records.currBranch);
    if (d === void 0 || !d) {
      const y = new Error(
        `Incorrect usage of "cherry-pick". Current branch (${i.records.currBranch})has no commits`
      );
      throw y.hash = {
        text: `cherryPick ${r} ${a}`,
        token: `cherryPick ${r} ${a}`,
        expected: ["cherry-pick abc"]
      }, y;
    }
    const h = i.records.commits.get(d);
    if (h === void 0 || !h) {
      const y = new Error(
        `Incorrect usage of "cherry-pick". Current branch (${i.records.currBranch})has no commits`
      );
      throw y.hash = {
        text: `cherryPick ${r} ${a}`,
        token: `cherryPick ${r} ${a}`,
        expected: ["cherry-pick abc"]
      }, y;
    }
    const f = {
      id: i.records.seq + "-" + z(),
      message: `cherry-picked ${o == null ? void 0 : o.message} into ${i.records.currBranch}`,
      seq: i.records.seq++,
      parents: i.records.head == null ? [] : [i.records.head.id, o.id],
      branch: i.records.currBranch,
      type: p.CHERRY_PICK,
      tags: n ? n.filter(Boolean) : [
        `cherry-pick:${o.id}${o.type === p.MERGE ? `|parent:${e}` : ""}`
      ]
    };
    i.records.head = f, i.records.commits.set(f.id, f), i.records.branches.set(i.records.currBranch, f.id), m.debug(i.records.branches), m.debug("in cherryPick");
  }
}, "cherryPick"), j = /* @__PURE__ */ $(function(t) {
  if (t = E.sanitizeText(t, q()), i.records.branches.has(t)) {
    i.records.currBranch = t;
    const r = i.records.branches.get(i.records.currBranch);
    r === void 0 || !r ? i.records.head = null : i.records.head = i.records.commits.get(r) ?? null;
  } else {
    const r = new Error(
      `Trying to checkout branch which is not yet created. (Help try using "branch ${t}")`
    );
    throw r.hash = {
      text: `checkout ${t}`,
      token: `checkout ${t}`,
      expected: [`branch ${t}`]
    }, r;
  }
}, "checkout");
function D(t, r, a) {
  const n = t.indexOf(r);
  n === -1 ? t.push(a) : t.splice(n, 1, a);
}
$(D, "upsert");
function F(t) {
  const r = t.reduce((e, s) => e.seq > s.seq ? e : s, t[0]);
  let a = "";
  t.forEach(function(e) {
    e === r ? a += "	*" : a += "	|";
  });
  const n = [a, r.id, r.seq];
  for (const e in i.records.branches)
    i.records.branches.get(e) === r.id && n.push(e);
  if (m.debug(n.join(" ")), r.parents && r.parents.length == 2 && r.parents[0] && r.parents[1]) {
    const e = i.records.commits.get(r.parents[0]);
    D(t, r, e), r.parents[1] && t.push(i.records.commits.get(r.parents[1]));
  } else {
    if (r.parents.length == 0)
      return;
    if (r.parents[0]) {
      const e = i.records.commits.get(r.parents[0]);
      D(t, r, e);
    }
  }
  t = W(t, (e) => e.id), F(t);
}
$(F, "prettyPrintCommitHistory");
var mr = /* @__PURE__ */ $(function() {
  m.debug(i.records.commits);
  const t = S()[0];
  F([t]);
}, "prettyPrint"), wr = /* @__PURE__ */ $(function() {
  i.reset(), nr();
}, "clear"), vr = /* @__PURE__ */ $(function() {
  return [...i.records.branchConfig.values()].map((r, a) => r.order !== null && r.order !== void 0 ? r : {
    ...r,
    order: parseFloat(`0.${a}`)
  }).sort((r, a) => (r.order ?? 0) - (a.order ?? 0)).map(({ name: r }) => ({ name: r }));
}, "getBranchesAsObjArray"), Cr = /* @__PURE__ */ $(function() {
  return i.records.branches;
}, "getBranches"), Er = /* @__PURE__ */ $(function() {
  return i.records.commits;
}, "getCommits"), S = /* @__PURE__ */ $(function() {
  const t = [...i.records.commits.values()];
  return t.forEach(function(r) {
    m.debug(r.id);
  }), t.sort((r, a) => r.seq - a.seq), t;
}, "getCommitsArray"), Br = /* @__PURE__ */ $(function() {
  return i.records.currBranch;
}, "getCurrentBranch"), Tr = /* @__PURE__ */ $(function() {
  return i.records.direction;
}, "getDirection"), Lr = /* @__PURE__ */ $(function() {
  return i.records.head;
}, "getHead"), Y = {
  commitType: p,
  getConfig: q,
  setDirection: fr,
  setOptions: yr,
  getOptions: gr,
  commit: xr,
  branch: ur,
  merge: pr,
  cherryPick: br,
  checkout: j,
  //reset,
  prettyPrint: mr,
  clear: wr,
  getBranchesAsObjArray: vr,
  getBranches: Cr,
  getCommits: Er,
  getCommitsArray: S,
  getCurrentBranch: Br,
  getDirection: Tr,
  getHead: Lr,
  setAccTitle: tr,
  getAccTitle: er,
  getAccDescription: rr,
  setAccDescription: Z,
  setDiagramTitle: Q,
  getDiagramTitle: J
}, kr = /* @__PURE__ */ $((t, r) => {
  V(t, r), t.dir && r.setDirection(t.dir);
  for (const a of t.statements)
    Mr(a, r);
}, "populate"), Mr = /* @__PURE__ */ $((t, r) => {
  const n = {
    Commit: /* @__PURE__ */ $((e) => r.commit(Ir(e)), "Commit"),
    Branch: /* @__PURE__ */ $((e) => r.branch(Rr(e)), "Branch"),
    Merge: /* @__PURE__ */ $((e) => r.merge(Gr(e)), "Merge"),
    Checkout: /* @__PURE__ */ $((e) => r.checkout(Or(e)), "Checkout"),
    CherryPicking: /* @__PURE__ */ $((e) => r.cherryPick(qr(e)), "CherryPicking")
  }[t.$type];
  n ? n(t) : m.error(`Unknown statement type: ${t.$type}`);
}, "parseStatement"), Ir = /* @__PURE__ */ $((t) => ({
  id: t.id,
  msg: t.message ?? "",
  type: t.type !== void 0 ? p[t.type] : p.NORMAL,
  tags: t.tags ?? void 0
}), "parseCommit"), Rr = /* @__PURE__ */ $((t) => ({
  name: t.name,
  order: t.order ?? 0
}), "parseBranch"), Gr = /* @__PURE__ */ $((t) => ({
  branch: t.branch,
  id: t.id ?? "",
  type: t.type !== void 0 ? p[t.type] : void 0,
  tags: t.tags ?? void 0
}), "parseMerge"), Or = /* @__PURE__ */ $((t) => t.branch, "parseCheckout"), qr = /* @__PURE__ */ $((t) => {
  var a;
  return {
    id: t.id,
    targetId: "",
    tags: ((a = t.tags) == null ? void 0 : a.length) === 0 ? void 0 : t.tags,
    parent: t.parent
  };
}, "parseCherryPicking"), Ar = {
  parse: /* @__PURE__ */ $(async (t) => {
    const r = await hr("gitGraph", t);
    m.debug(r), kr(r, Y);
  }, "parse")
}, I = 10, R = 40, B = 4, L = 2, O = 8, v = /* @__PURE__ */ new Map(), C = /* @__PURE__ */ new Map(), P = 30, A = /* @__PURE__ */ new Map(), _ = [], M = 0, x = "LR", Hr = /* @__PURE__ */ $(() => {
  v.clear(), C.clear(), A.clear(), M = 0, _ = [], x = "LR";
}, "clear"), K = /* @__PURE__ */ $((t) => {
  const r = document.createElementNS("http://www.w3.org/2000/svg", "text");
  return (typeof t == "string" ? t.split(/\\n|\n|<br\s*\/?>/gi) : t).forEach((n) => {
    const e = document.createElementNS("http://www.w3.org/2000/svg", "tspan");
    e.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:space", "preserve"), e.setAttribute("dy", "1em"), e.setAttribute("x", "0"), e.setAttribute("class", "row"), e.textContent = n.trim(), r.appendChild(e);
  }), r;
}, "drawText"), U = /* @__PURE__ */ $((t) => {
  let r, a, n;
  return x === "BT" ? (a = /* @__PURE__ */ $((e, s) => e <= s, "comparisonFunc"), n = 1 / 0) : (a = /* @__PURE__ */ $((e, s) => e >= s, "comparisonFunc"), n = 0), t.forEach((e) => {
    var o, c;
    const s = x === "TB" || x == "BT" ? (o = C.get(e)) == null ? void 0 : o.y : (c = C.get(e)) == null ? void 0 : c.x;
    s !== void 0 && a(s, n) && (r = e, n = s);
  }), r;
}, "findClosestParent"), Pr = /* @__PURE__ */ $((t) => {
  let r = "", a = 1 / 0;
  return t.forEach((n) => {
    const e = C.get(n).y;
    e <= a && (r = n, a = e);
  }), r || void 0;
}, "findClosestParentBT"), _r = /* @__PURE__ */ $((t, r, a) => {
  let n = a, e = a;
  const s = [];
  t.forEach((o) => {
    const c = r.get(o);
    if (!c)
      throw new Error(`Commit not found for key ${o}`);
    c.parents.length ? (n = Dr(c), e = Math.max(n, e)) : s.push(c), Fr(c, n);
  }), n = e, s.forEach((o) => {
    Nr(o, n, a);
  }), t.forEach((o) => {
    const c = r.get(o);
    if (c != null && c.parents.length) {
      const d = Pr(c.parents);
      n = C.get(d).y - R, n <= e && (e = n);
      const h = v.get(c.branch).pos, f = n - I;
      C.set(c.id, { x: h, y: f });
    }
  });
}, "setParallelBTPos"), zr = /* @__PURE__ */ $((t) => {
  var n;
  const r = U(t.parents.filter((e) => e !== null));
  if (!r)
    throw new Error(`Closest parent not found for commit ${t.id}`);
  const a = (n = C.get(r)) == null ? void 0 : n.y;
  if (a === void 0)
    throw new Error(`Closest parent position not found for commit ${t.id}`);
  return a;
}, "findClosestParentPos"), Dr = /* @__PURE__ */ $((t) => zr(t) + R, "calculateCommitPosition"), Fr = /* @__PURE__ */ $((t, r) => {
  const a = v.get(t.branch);
  if (!a)
    throw new Error(`Branch not found for commit ${t.id}`);
  const n = a.pos, e = r + I;
  return C.set(t.id, { x: n, y: e }), { x: n, y: e };
}, "setCommitPosition"), Nr = /* @__PURE__ */ $((t, r, a) => {
  const n = v.get(t.branch);
  if (!n)
    throw new Error(`Branch not found for commit ${t.id}`);
  const e = r + a, s = n.pos;
  C.set(t.id, { x: s, y: e });
}, "setRootPosition"), Wr = /* @__PURE__ */ $((t, r, a, n, e, s) => {
  if (s === p.HIGHLIGHT)
    t.append("rect").attr("x", a.x - 10).attr("y", a.y - 10).attr("width", 20).attr("height", 20).attr(
      "class",
      `commit ${r.id} commit-highlight${e % O} ${n}-outer`
    ), t.append("rect").attr("x", a.x - 6).attr("y", a.y - 6).attr("width", 12).attr("height", 12).attr(
      "class",
      `commit ${r.id} commit${e % O} ${n}-inner`
    );
  else if (s === p.CHERRY_PICK)
    t.append("circle").attr("cx", a.x).attr("cy", a.y).attr("r", 10).attr("class", `commit ${r.id} ${n}`), t.append("circle").attr("cx", a.x - 3).attr("cy", a.y + 2).attr("r", 2.75).attr("fill", "#fff").attr("class", `commit ${r.id} ${n}`), t.append("circle").attr("cx", a.x + 3).attr("cy", a.y + 2).attr("r", 2.75).attr("fill", "#fff").attr("class", `commit ${r.id} ${n}`), t.append("line").attr("x1", a.x + 3).attr("y1", a.y + 1).attr("x2", a.x).attr("y2", a.y - 5).attr("stroke", "#fff").attr("class", `commit ${r.id} ${n}`), t.append("line").attr("x1", a.x - 3).attr("y1", a.y + 1).attr("x2", a.x).attr("y2", a.y - 5).attr("stroke", "#fff").attr("class", `commit ${r.id} ${n}`);
  else {
    const o = t.append("circle");
    if (o.attr("cx", a.x), o.attr("cy", a.y), o.attr("r", r.type === p.MERGE ? 9 : 10), o.attr("class", `commit ${r.id} commit${e % O}`), s === p.MERGE) {
      const c = t.append("circle");
      c.attr("cx", a.x), c.attr("cy", a.y), c.attr("r", 6), c.attr(
        "class",
        `commit ${n} ${r.id} commit${e % O}`
      );
    }
    s === p.REVERSE && t.append("path").attr(
      "d",
      `M ${a.x - 5},${a.y - 5}L${a.x + 5},${a.y + 5}M${a.x - 5},${a.y + 5}L${a.x + 5},${a.y - 5}`
    ).attr("class", `commit ${n} ${r.id} commit${e % O}`);
  }
}, "drawCommitBullet"), jr = /* @__PURE__ */ $((t, r, a, n, e) => {
  var s;
  if (r.type !== p.CHERRY_PICK && (r.customId && r.type === p.MERGE || r.type !== p.MERGE) && e.showCommitLabel) {
    const o = t.append("g"), c = o.insert("rect").attr("class", "commit-label-bkg"), d = o.append("text").attr("x", n).attr("y", a.y + 25).attr("class", "commit-label").text(r.id), h = (s = d.node()) == null ? void 0 : s.getBBox();
    if (h && (c.attr("x", a.posWithOffset - h.width / 2 - L).attr("y", a.y + 13.5).attr("width", h.width + 2 * L).attr("height", h.height + 2 * L), x === "TB" || x === "BT" ? (c.attr("x", a.x - (h.width + 4 * B + 5)).attr("y", a.y - 12), d.attr("x", a.x - (h.width + 4 * B)).attr("y", a.y + h.height - 12)) : d.attr("x", a.posWithOffset - h.width / 2), e.rotateCommitLabel))
      if (x === "TB" || x === "BT")
        d.attr(
          "transform",
          "rotate(-45, " + a.x + ", " + a.y + ")"
        ), c.attr(
          "transform",
          "rotate(-45, " + a.x + ", " + a.y + ")"
        );
      else {
        const f = -7.5 - (h.width + 10) / 25 * 9.5, y = 10 + h.width / 25 * 8.5;
        o.attr(
          "transform",
          "translate(" + f + ", " + y + ") rotate(-45, " + n + ", " + a.y + ")"
        );
      }
  }
}, "drawCommitLabel"), Sr = /* @__PURE__ */ $((t, r, a, n) => {
  var e;
  if (r.tags.length > 0) {
    let s = 0, o = 0, c = 0;
    const d = [];
    for (const h of r.tags.reverse()) {
      const f = t.insert("polygon"), y = t.append("circle"), l = t.append("text").attr("y", a.y - 16 - s).attr("class", "tag-label").text(h), g = (e = l.node()) == null ? void 0 : e.getBBox();
      if (!g)
        throw new Error("Tag bbox not found");
      o = Math.max(o, g.width), c = Math.max(c, g.height), l.attr("x", a.posWithOffset - g.width / 2), d.push({
        tag: l,
        hole: y,
        rect: f,
        yOffset: s
      }), s += 20;
    }
    for (const { tag: h, hole: f, rect: y, yOffset: l } of d) {
      const g = c / 2, u = a.y - 19.2 - l;
      if (y.attr("class", "tag-label-bkg").attr(
        "points",
        `
      ${n - o / 2 - B / 2},${u + L}  
      ${n - o / 2 - B / 2},${u - L}
      ${a.posWithOffset - o / 2 - B},${u - g - L}
      ${a.posWithOffset + o / 2 + B},${u - g - L}
      ${a.posWithOffset + o / 2 + B},${u + g + L}
      ${a.posWithOffset - o / 2 - B},${u + g + L}`
      ), f.attr("cy", u).attr("cx", n - o / 2 + B / 2).attr("r", 1.5).attr("class", "tag-hole"), x === "TB" || x === "BT") {
        const b = n + l;
        y.attr("class", "tag-label-bkg").attr(
          "points",
          `
        ${a.x},${b + 2}
        ${a.x},${b - 2}
        ${a.x + I},${b - g - 2}
        ${a.x + I + o + 4},${b - g - 2}
        ${a.x + I + o + 4},${b + g + 2}
        ${a.x + I},${b + g + 2}`
        ).attr("transform", "translate(12,12) rotate(45, " + a.x + "," + n + ")"), f.attr("cx", a.x + B / 2).attr("cy", b).attr("transform", "translate(12,12) rotate(45, " + a.x + "," + n + ")"), h.attr("x", a.x + 5).attr("y", b + 3).attr("transform", "translate(14,14) rotate(45, " + a.x + "," + n + ")");
      }
    }
  }
}, "drawCommitTags"), Yr = /* @__PURE__ */ $((t) => {
  switch (t.customType ?? t.type) {
    case p.NORMAL:
      return "commit-normal";
    case p.REVERSE:
      return "commit-reverse";
    case p.HIGHLIGHT:
      return "commit-highlight";
    case p.MERGE:
      return "commit-merge";
    case p.CHERRY_PICK:
      return "commit-cherry-pick";
    default:
      return "commit-normal";
  }
}, "getCommitClassType"), Kr = /* @__PURE__ */ $((t, r, a, n) => {
  const e = { x: 0, y: 0 };
  if (t.parents.length > 0) {
    const s = U(t.parents);
    if (s) {
      const o = n.get(s) ?? e;
      return r === "TB" ? o.y + R : r === "BT" ? (n.get(t.id) ?? e).y - R : o.x + R;
    }
  } else
    return r === "TB" ? P : r === "BT" ? (n.get(t.id) ?? e).y - R : 0;
  return 0;
}, "calculatePosition"), Ur = /* @__PURE__ */ $((t, r, a) => {
  var o, c;
  const n = x === "BT" && a ? r : r + I, e = x === "TB" || x === "BT" ? n : (o = v.get(t.branch)) == null ? void 0 : o.pos, s = x === "TB" || x === "BT" ? (c = v.get(t.branch)) == null ? void 0 : c.pos : n;
  if (s === void 0 || e === void 0)
    throw new Error(`Position were undefined for commit ${t.id}`);
  return { x: s, y: e, posWithOffset: n };
}, "getCommitPosition"), N = /* @__PURE__ */ $((t, r, a, n) => {
  const e = t.append("g").attr("class", "commit-bullets"), s = t.append("g").attr("class", "commit-labels");
  let o = x === "TB" || x === "BT" ? P : 0;
  const c = [...r.keys()], d = n.parallelCommits ?? !1, h = /* @__PURE__ */ $((y, l) => {
    var b, T;
    const g = (b = r.get(y)) == null ? void 0 : b.seq, u = (T = r.get(l)) == null ? void 0 : T.seq;
    return g !== void 0 && u !== void 0 ? g - u : 0;
  }, "sortKeys");
  let f = c.sort(h);
  x === "BT" && (d && _r(f, r, o), f = f.reverse()), f.forEach((y) => {
    var u;
    const l = r.get(y);
    if (!l)
      throw new Error(`Commit not found for key ${y}`);
    d && (o = Kr(l, x, o, C));
    const g = Ur(l, o, d);
    if (a) {
      const b = Yr(l), T = l.customType ?? l.type, G = ((u = v.get(l.branch)) == null ? void 0 : u.index) ?? 0;
      Wr(e, l, g, b, G, T), jr(s, l, g, o, n), Sr(s, l, g, o);
    }
    x === "TB" || x === "BT" ? C.set(l.id, { x: g.x, y: g.posWithOffset }) : C.set(l.id, { x: g.posWithOffset, y: g.y }), o = x === "BT" && d ? o + R : o + R + I, o > M && (M = o);
  });
}, "drawCommits"), Vr = /* @__PURE__ */ $((t, r, a, n, e) => {
  const o = (x === "TB" || x === "BT" ? a.x < n.x : a.y < n.y) ? r.branch : t.branch, c = /* @__PURE__ */ $((h) => h.branch === o, "isOnBranchToGetCurve"), d = /* @__PURE__ */ $((h) => h.seq > t.seq && h.seq < r.seq, "isBetweenCommits");
  return [...e.values()].some((h) => d(h) && c(h));
}, "shouldRerouteArrow"), H = /* @__PURE__ */ $((t, r, a = 0) => {
  const n = t + Math.abs(t - r) / 2;
  if (a > 5)
    return n;
  if (_.every((o) => Math.abs(o - n) >= 10))
    return _.push(n), n;
  const s = Math.abs(t - r);
  return H(t, r - s / 5, a + 1);
}, "findLane"), Xr = /* @__PURE__ */ $((t, r, a, n) => {
  var g, u, b, T, G;
  const e = C.get(r.id), s = C.get(a.id);
  if (e === void 0 || s === void 0)
    throw new Error(`Commit positions not found for commits ${r.id} and ${a.id}`);
  const o = Vr(r, a, e, s, n);
  let c = "", d = "", h = 0, f = 0, y = (g = v.get(a.branch)) == null ? void 0 : g.index;
  a.type === p.MERGE && r.id !== a.parents[0] && (y = (u = v.get(r.branch)) == null ? void 0 : u.index);
  let l;
  if (o) {
    c = "A 10 10, 0, 0, 0,", d = "A 10 10, 0, 0, 1,", h = 10, f = 10;
    const k = e.y < s.y ? H(e.y, s.y) : H(s.y, e.y), w = e.x < s.x ? H(e.x, s.x) : H(s.x, e.x);
    x === "TB" ? e.x < s.x ? l = `M ${e.x} ${e.y} L ${w - h} ${e.y} ${d} ${w} ${e.y + f} L ${w} ${s.y - h} ${c} ${w + f} ${s.y} L ${s.x} ${s.y}` : (y = (b = v.get(r.branch)) == null ? void 0 : b.index, l = `M ${e.x} ${e.y} L ${w + h} ${e.y} ${c} ${w} ${e.y + f} L ${w} ${s.y - h} ${d} ${w - f} ${s.y} L ${s.x} ${s.y}`) : x === "BT" ? e.x < s.x ? l = `M ${e.x} ${e.y} L ${w - h} ${e.y} ${c} ${w} ${e.y - f} L ${w} ${s.y + h} ${d} ${w + f} ${s.y} L ${s.x} ${s.y}` : (y = (T = v.get(r.branch)) == null ? void 0 : T.index, l = `M ${e.x} ${e.y} L ${w + h} ${e.y} ${d} ${w} ${e.y - f} L ${w} ${s.y + h} ${c} ${w - f} ${s.y} L ${s.x} ${s.y}`) : e.y < s.y ? l = `M ${e.x} ${e.y} L ${e.x} ${k - h} ${c} ${e.x + f} ${k} L ${s.x - h} ${k} ${d} ${s.x} ${k + f} L ${s.x} ${s.y}` : (y = (G = v.get(r.branch)) == null ? void 0 : G.index, l = `M ${e.x} ${e.y} L ${e.x} ${k + h} ${d} ${e.x + f} ${k} L ${s.x - h} ${k} ${c} ${s.x} ${k - f} L ${s.x} ${s.y}`);
  } else
    c = "A 20 20, 0, 0, 0,", d = "A 20 20, 0, 0, 1,", h = 20, f = 20, x === "TB" ? (e.x < s.x && (a.type === p.MERGE && r.id !== a.parents[0] ? l = `M ${e.x} ${e.y} L ${e.x} ${s.y - h} ${c} ${e.x + f} ${s.y} L ${s.x} ${s.y}` : l = `M ${e.x} ${e.y} L ${s.x - h} ${e.y} ${d} ${s.x} ${e.y + f} L ${s.x} ${s.y}`), e.x > s.x && (c = "A 20 20, 0, 0, 0,", d = "A 20 20, 0, 0, 1,", h = 20, f = 20, a.type === p.MERGE && r.id !== a.parents[0] ? l = `M ${e.x} ${e.y} L ${e.x} ${s.y - h} ${d} ${e.x - f} ${s.y} L ${s.x} ${s.y}` : l = `M ${e.x} ${e.y} L ${s.x + h} ${e.y} ${c} ${s.x} ${e.y + f} L ${s.x} ${s.y}`), e.x === s.x && (l = `M ${e.x} ${e.y} L ${s.x} ${s.y}`)) : x === "BT" ? (e.x < s.x && (a.type === p.MERGE && r.id !== a.parents[0] ? l = `M ${e.x} ${e.y} L ${e.x} ${s.y + h} ${d} ${e.x + f} ${s.y} L ${s.x} ${s.y}` : l = `M ${e.x} ${e.y} L ${s.x - h} ${e.y} ${c} ${s.x} ${e.y - f} L ${s.x} ${s.y}`), e.x > s.x && (c = "A 20 20, 0, 0, 0,", d = "A 20 20, 0, 0, 1,", h = 20, f = 20, a.type === p.MERGE && r.id !== a.parents[0] ? l = `M ${e.x} ${e.y} L ${e.x} ${s.y + h} ${c} ${e.x - f} ${s.y} L ${s.x} ${s.y}` : l = `M ${e.x} ${e.y} L ${s.x + h} ${e.y} ${d} ${s.x} ${e.y - f} L ${s.x} ${s.y}`), e.x === s.x && (l = `M ${e.x} ${e.y} L ${s.x} ${s.y}`)) : (e.y < s.y && (a.type === p.MERGE && r.id !== a.parents[0] ? l = `M ${e.x} ${e.y} L ${s.x - h} ${e.y} ${d} ${s.x} ${e.y + f} L ${s.x} ${s.y}` : l = `M ${e.x} ${e.y} L ${e.x} ${s.y - h} ${c} ${e.x + f} ${s.y} L ${s.x} ${s.y}`), e.y > s.y && (a.type === p.MERGE && r.id !== a.parents[0] ? l = `M ${e.x} ${e.y} L ${s.x - h} ${e.y} ${c} ${s.x} ${e.y - f} L ${s.x} ${s.y}` : l = `M ${e.x} ${e.y} L ${e.x} ${s.y + h} ${d} ${e.x + f} ${s.y} L ${s.x} ${s.y}`), e.y === s.y && (l = `M ${e.x} ${e.y} L ${s.x} ${s.y}`));
  if (l === void 0)
    throw new Error("Line definition not found");
  t.append("path").attr("d", l).attr("class", "arrow arrow" + y % O);
}, "drawArrow"), Jr = /* @__PURE__ */ $((t, r) => {
  const a = t.append("g").attr("class", "commit-arrows");
  [...r.keys()].forEach((n) => {
    const e = r.get(n);
    e.parents && e.parents.length > 0 && e.parents.forEach((s) => {
      Xr(a, r.get(s), e, r);
    });
  });
}, "drawArrows"), Qr = /* @__PURE__ */ $((t, r, a) => {
  const n = t.append("g");
  r.forEach((e, s) => {
    var b;
    const o = s % O, c = (b = v.get(e.name)) == null ? void 0 : b.pos;
    if (c === void 0)
      throw new Error(`Position not found for branch ${e.name}`);
    const d = n.append("line");
    d.attr("x1", 0), d.attr("y1", c), d.attr("x2", M), d.attr("y2", c), d.attr("class", "branch branch" + o), x === "TB" ? (d.attr("y1", P), d.attr("x1", c), d.attr("y2", M), d.attr("x2", c)) : x === "BT" && (d.attr("y1", M), d.attr("x1", c), d.attr("y2", P), d.attr("x2", c)), _.push(c);
    const h = e.name, f = K(h), y = n.insert("rect"), g = n.insert("g").attr("class", "branchLabel").insert("g").attr("class", "label branch-label" + o);
    g.node().appendChild(f);
    const u = f.getBBox();
    y.attr("class", "branchLabelBkg label" + o).attr("rx", 4).attr("ry", 4).attr("x", -u.width - 4 - (a.rotateCommitLabel === !0 ? 30 : 0)).attr("y", -u.height / 2 + 8).attr("width", u.width + 18).attr("height", u.height + 4), g.attr(
      "transform",
      "translate(" + (-u.width - 14 - (a.rotateCommitLabel === !0 ? 30 : 0)) + ", " + (c - u.height / 2 - 1) + ")"
    ), x === "TB" ? (y.attr("x", c - u.width / 2 - 10).attr("y", 0), g.attr("transform", "translate(" + (c - u.width / 2 - 5) + ", 0)")) : x === "BT" ? (y.attr("x", c - u.width / 2 - 10).attr("y", M), g.attr("transform", "translate(" + (c - u.width / 2 - 5) + ", " + M + ")")) : y.attr("transform", "translate(-19, " + (c - u.height / 2) + ")");
  });
}, "drawBranches"), Zr = /* @__PURE__ */ $(function(t, r, a, n, e) {
  return v.set(t, { pos: r, index: a }), r += 50 + (e ? 40 : 0) + (x === "TB" || x === "BT" ? n.width / 2 : 0), r;
}, "setBranchPosition"), re = /* @__PURE__ */ $(function(t, r, a, n) {
  Hr(), m.debug("in gitgraph renderer", t + `
`, "id:", r, a);
  const e = n.db;
  if (!e.getConfig) {
    m.error("getConfig method is not available on db");
    return;
  }
  const s = e.getConfig(), o = s.rotateCommitLabel ?? !1;
  A = e.getCommits();
  const c = e.getBranchesAsObjArray();
  x = e.getDirection();
  const d = lr(`[id="${r}"]`);
  let h = 0;
  c.forEach((f, y) => {
    var G;
    const l = K(f.name), g = d.append("g"), u = g.insert("g").attr("class", "branchLabel"), b = u.insert("g").attr("class", "label branch-label");
    (G = b.node()) == null || G.appendChild(l);
    const T = l.getBBox();
    h = Zr(f.name, h, y, T, o), b.remove(), u.remove(), g.remove();
  }), N(d, A, !1, s), s.showBranches && Qr(d, c, s), Jr(d, A), N(d, A, !0, s), ar.insertTitle(
    d,
    "gitTitleText",
    s.titleTopMargin ?? 0,
    e.getDiagramTitle()
  ), sr(void 0, d, s.diagramPadding, s.useMaxWidth);
}, "draw"), ee = {
  draw: re
}, te = /* @__PURE__ */ $((t) => `
  .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(
  (r) => `
        .branch-label${r} { fill: ${t["gitBranchLabel" + r]}; }
        .commit${r} { stroke: ${t["git" + r]}; fill: ${t["git" + r]}; }
        .commit-highlight${r} { stroke: ${t["gitInv" + r]}; fill: ${t["gitInv" + r]}; }
        .label${r}  { fill: ${t["git" + r]}; }
        .arrow${r} { stroke: ${t["git" + r]}; }
        `
).join(`
`)}

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

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

  .arrow { stroke-width: 8; stroke-linecap: round; fill: none}
  .gitTitleText {
    text-anchor: middle;
    font-size: 18px;
    fill: ${t.textColor};
  }
`, "getStyles"), ae = te, de = {
  parser: Ar,
  db: Y,
  renderer: ee,
  styles: ae
};
export {
  de as diagram
};
