import { p as le } from "./chunk-4BX2VUAB-DcVEQYu4.js";
import { I as he } from "./chunk-QZHKN3VN-KMehXdu1.js";
import { B as $e, A as fe, s as ge, g as ue, d as ye, e as xe, _ as h, O as Q, l as w, h as me, f as q, z as pe, P as be, I as we, p as B, Q as ke, R as ve, S as Ce } from "./mermaid-VLURNSYL-TtKCXHSS.js";
import { p as Ee } from "./wardley-RL74JXVD-DajqNh3l.js";
var m = {
  NORMAL: 0,
  REVERSE: 1,
  HIGHLIGHT: 2,
  MERGE: 3,
  CHERRY_PICK: 4
}, Be = ve.gitGraph, S = /* @__PURE__ */ h(() => ke({
  ...Be,
  ...Q().gitGraph
}), "getConfig"), d = new he(() => {
  const e = S(), r = e.mainBranchName, t = e.mainBranchOrder;
  return {
    mainBranchName: r,
    commits: /* @__PURE__ */ new Map(),
    head: null,
    branchConfig: /* @__PURE__ */ new Map([[r, { name: r, order: t }]]),
    branches: /* @__PURE__ */ new Map([[r, null]]),
    currBranch: r,
    direction: "LR",
    seq: 0,
    options: {}
  };
});
function Y() {
  return Ce({ length: 7 });
}
h(Y, "getID");
function te(e, r) {
  const t = /* @__PURE__ */ Object.create(null);
  return e.reduce((s, o) => {
    const i = r(o);
    return t[i] || (t[i] = !0, s.push(o)), s;
  }, []);
}
h(te, "uniqBy");
var Te = /* @__PURE__ */ h(function(e) {
  d.records.direction = e;
}, "setDirection"), Le = /* @__PURE__ */ h(function(e) {
  w.debug("options str", e), e = e?.trim(), e = e || "{}";
  try {
    d.records.options = JSON.parse(e);
  } catch (r) {
    w.error("error while parsing gitGraph options", r.message);
  }
}, "setOptions"), Me = /* @__PURE__ */ h(function() {
  return d.records.options;
}, "getOptions"), Re = /* @__PURE__ */ h(function(e) {
  let r = e.msg, t = e.id;
  const s = e.type;
  let o = e.tags;
  w.info("commit", r, t, s, o), w.debug("Entering commit:", r, t, s, o);
  const i = S();
  t = B.sanitizeText(t, i), r = B.sanitizeText(r, i), o = o?.map((a) => B.sanitizeText(a, i));
  const n = {
    id: t || d.records.seq + "-" + Y(),
    message: r,
    seq: d.records.seq++,
    type: s ?? m.NORMAL,
    tags: o ?? [],
    parents: d.records.head == null ? [] : [d.records.head.id],
    branch: d.records.currBranch
  };
  d.records.head = n, w.info("main branch", i.mainBranchName), d.records.commits.has(n.id) && w.warn(`Commit ID ${n.id} already exists`), d.records.commits.set(n.id, n), d.records.branches.set(d.records.currBranch, n.id), w.debug("in pushCommit " + n.id);
}, "commit"), Ie = /* @__PURE__ */ h(function(e) {
  let r = e.name;
  const t = e.order;
  if (r = B.sanitizeText(r, S()), d.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}")`
    );
  d.records.branches.set(r, d.records.head != null ? d.records.head.id : null), d.records.branchConfig.set(r, { name: r, order: t }), ae(r), w.debug("in createBranch");
}, "branch"), Oe = /* @__PURE__ */ h((e) => {
  let r = e.branch, t = e.id;
  const s = e.type, o = e.tags, i = S();
  r = B.sanitizeText(r, i), t && (t = B.sanitizeText(t, i));
  const n = d.records.branches.get(d.records.currBranch), a = d.records.branches.get(r), l = n ? d.records.commits.get(n) : void 0, f = a ? d.records.commits.get(a) : void 0;
  if (l && f && l.branch === r)
    throw new Error(`Cannot merge branch '${r}' into itself.`);
  if (d.records.currBranch === r) {
    const c = new Error('Incorrect usage of "merge". Cannot merge a branch to itself');
    throw c.hash = {
      text: `merge ${r}`,
      token: `merge ${r}`,
      expected: ["branch abc"]
    }, c;
  }
  if (l === void 0 || !l) {
    const c = new Error(
      `Incorrect usage of "merge". Current branch (${d.records.currBranch})has no commits`
    );
    throw c.hash = {
      text: `merge ${r}`,
      token: `merge ${r}`,
      expected: ["commit"]
    }, c;
  }
  if (!d.records.branches.has(r)) {
    const c = new Error(
      'Incorrect usage of "merge". Branch to be merged (' + r + ") does not exist"
    );
    throw c.hash = {
      text: `merge ${r}`,
      token: `merge ${r}`,
      expected: [`branch ${r}`]
    }, c;
  }
  if (f === void 0 || !f) {
    const c = new Error(
      'Incorrect usage of "merge". Branch to be merged (' + r + ") has no commits"
    );
    throw c.hash = {
      text: `merge ${r}`,
      token: `merge ${r}`,
      expected: ['"commit"']
    }, c;
  }
  if (l === f) {
    const c = new Error('Incorrect usage of "merge". Both branches have same head');
    throw c.hash = {
      text: `merge ${r}`,
      token: `merge ${r}`,
      expected: ["branch abc"]
    }, c;
  }
  if (t && d.records.commits.has(t)) {
    const c = new Error(
      'Incorrect usage of "merge". Commit with id:' + t + " already exists, use different custom id"
    );
    throw c.hash = {
      text: `merge ${r} ${t} ${s} ${o?.join(" ")}`,
      token: `merge ${r} ${t} ${s} ${o?.join(" ")}`,
      expected: [
        `merge ${r} ${t}_UNIQUE ${s} ${o?.join(" ")}`
      ]
    }, c;
  }
  const g = a || "", $ = {
    id: t || `${d.records.seq}-${Y()}`,
    message: `merged branch ${r} into ${d.records.currBranch}`,
    seq: d.records.seq++,
    parents: d.records.head == null ? [] : [d.records.head.id, g],
    branch: d.records.currBranch,
    type: m.MERGE,
    customType: s,
    customId: !!t,
    tags: o ?? []
  };
  d.records.head = $, d.records.commits.set($.id, $), d.records.branches.set(d.records.currBranch, $.id), w.debug(d.records.branches), w.debug("in mergeBranch");
}, "merge"), _e = /* @__PURE__ */ h(function(e) {
  let r = e.id, t = e.targetId, s = e.tags, o = e.parent;
  w.debug("Entering cherryPick:", r, t, s);
  const i = S();
  if (r = B.sanitizeText(r, i), t = B.sanitizeText(t, i), s = s?.map((l) => B.sanitizeText(l, i)), o = B.sanitizeText(o, i), !r || !d.records.commits.has(r)) {
    const l = new Error(
      'Incorrect usage of "cherryPick". Source commit id should exist and provided'
    );
    throw l.hash = {
      text: `cherryPick ${r} ${t}`,
      token: `cherryPick ${r} ${t}`,
      expected: ["cherry-pick abc"]
    }, l;
  }
  const n = d.records.commits.get(r);
  if (n === void 0 || !n)
    throw new Error('Incorrect usage of "cherryPick". Source commit id should exist and provided');
  if (o && !(Array.isArray(n.parents) && n.parents.includes(o)))
    throw new Error(
      "Invalid operation: The specified parent commit is not an immediate parent of the cherry-picked commit."
    );
  const a = n.branch;
  if (n.type === m.MERGE && !o)
    throw new Error(
      "Incorrect usage of cherry-pick: If the source commit is a merge commit, an immediate parent commit must be specified."
    );
  if (!t || !d.records.commits.has(t)) {
    if (a === d.records.currBranch) {
      const $ = new Error(
        'Incorrect usage of "cherryPick". Source commit is already on current branch'
      );
      throw $.hash = {
        text: `cherryPick ${r} ${t}`,
        token: `cherryPick ${r} ${t}`,
        expected: ["cherry-pick abc"]
      }, $;
    }
    const l = d.records.branches.get(d.records.currBranch);
    if (l === void 0 || !l) {
      const $ = new Error(
        `Incorrect usage of "cherry-pick". Current branch (${d.records.currBranch})has no commits`
      );
      throw $.hash = {
        text: `cherryPick ${r} ${t}`,
        token: `cherryPick ${r} ${t}`,
        expected: ["cherry-pick abc"]
      }, $;
    }
    const f = d.records.commits.get(l);
    if (f === void 0 || !f) {
      const $ = new Error(
        `Incorrect usage of "cherry-pick". Current branch (${d.records.currBranch})has no commits`
      );
      throw $.hash = {
        text: `cherryPick ${r} ${t}`,
        token: `cherryPick ${r} ${t}`,
        expected: ["cherry-pick abc"]
      }, $;
    }
    const g = {
      id: d.records.seq + "-" + Y(),
      message: `cherry-picked ${n?.message} into ${d.records.currBranch}`,
      seq: d.records.seq++,
      parents: d.records.head == null ? [] : [d.records.head.id, n.id],
      branch: d.records.currBranch,
      type: m.CHERRY_PICK,
      tags: s ? s.filter(Boolean) : [
        `cherry-pick:${n.id}${n.type === m.MERGE ? `|parent:${o}` : ""}`
      ]
    };
    d.records.head = g, d.records.commits.set(g.id, g), d.records.branches.set(d.records.currBranch, g.id), w.debug(d.records.branches), w.debug("in cherryPick");
  }
}, "cherryPick"), ae = /* @__PURE__ */ h(function(e) {
  if (e = B.sanitizeText(e, S()), d.records.branches.has(e)) {
    d.records.currBranch = e;
    const r = d.records.branches.get(d.records.currBranch);
    r === void 0 || !r ? d.records.head = null : d.records.head = d.records.commits.get(r) ?? null;
  } else {
    const r = new Error(
      `Trying to checkout branch which is not yet created. (Help try using "branch ${e}")`
    );
    throw r.hash = {
      text: `checkout ${e}`,
      token: `checkout ${e}`,
      expected: [`branch ${e}`]
    }, r;
  }
}, "checkout");
function V(e, r, t) {
  const s = e.indexOf(r);
  s === -1 ? e.push(t) : e.splice(s, 1, t);
}
h(V, "upsert");
function J(e) {
  const r = e.reduce((o, i) => o.seq > i.seq ? o : i, e[0]);
  let t = "";
  e.forEach(function(o) {
    o === r ? t += "	*" : t += "	|";
  });
  const s = [t, r.id, r.seq];
  for (const o in d.records.branches)
    d.records.branches.get(o) === r.id && s.push(o);
  if (w.debug(s.join(" ")), r.parents && r.parents.length == 2 && r.parents[0] && r.parents[1]) {
    const o = d.records.commits.get(r.parents[0]);
    V(e, r, o), r.parents[1] && e.push(d.records.commits.get(r.parents[1]));
  } else {
    if (r.parents.length == 0)
      return;
    if (r.parents[0]) {
      const o = d.records.commits.get(r.parents[0]);
      V(e, r, o);
    }
  }
  e = te(e, (o) => o.id), J(e);
}
h(J, "prettyPrintCommitHistory");
var Ge = /* @__PURE__ */ h(function() {
  w.debug(d.records.commits);
  const e = ne()[0];
  J([e]);
}, "prettyPrint"), He = /* @__PURE__ */ h(function() {
  d.reset(), we();
}, "clear"), Se = /* @__PURE__ */ h(function() {
  return [...d.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"), Ae = /* @__PURE__ */ h(function() {
  return d.records.branches;
}, "getBranches"), De = /* @__PURE__ */ h(function() {
  return d.records.commits;
}, "getCommits"), ne = /* @__PURE__ */ h(function() {
  const e = [...d.records.commits.values()];
  return e.forEach(function(r) {
    w.debug(r.id);
  }), e.sort((r, t) => r.seq - t.seq), e;
}, "getCommitsArray"), Pe = /* @__PURE__ */ h(function() {
  return d.records.currBranch;
}, "getCurrentBranch"), We = /* @__PURE__ */ h(function() {
  return d.records.direction;
}, "getDirection"), qe = /* @__PURE__ */ h(function() {
  return d.records.head;
}, "getHead"), se = {
  commitType: m,
  getConfig: S,
  setDirection: Te,
  setOptions: Le,
  getOptions: Me,
  commit: Re,
  branch: Ie,
  merge: Oe,
  cherryPick: _e,
  checkout: ae,
  //reset,
  prettyPrint: Ge,
  clear: He,
  getBranchesAsObjArray: Se,
  getBranches: Ae,
  getCommits: De,
  getCommitsArray: ne,
  getCurrentBranch: Pe,
  getDirection: We,
  getHead: qe,
  setAccTitle: xe,
  getAccTitle: ye,
  getAccDescription: ue,
  setAccDescription: ge,
  setDiagramTitle: fe,
  getDiagramTitle: $e
}, Ne = /* @__PURE__ */ h((e, r) => {
  le(e, r), e.dir && r.setDirection(e.dir);
  for (const t of e.statements)
    Fe(t, r);
}, "populate"), Fe = /* @__PURE__ */ h((e, r) => {
  const s = {
    Commit: /* @__PURE__ */ h((o) => r.commit(ze(o)), "Commit"),
    Branch: /* @__PURE__ */ h((o) => r.branch(Ye(o)), "Branch"),
    Merge: /* @__PURE__ */ h((o) => r.merge(je(o)), "Merge"),
    Checkout: /* @__PURE__ */ h((o) => r.checkout(Ue(o)), "Checkout"),
    CherryPicking: /* @__PURE__ */ h((o) => r.cherryPick(Ke(o)), "CherryPicking")
  }[e.$type];
  s ? s(e) : w.error(`Unknown statement type: ${e.$type}`);
}, "parseStatement"), ze = /* @__PURE__ */ h((e) => ({
  id: e.id,
  msg: e.message ?? "",
  type: e.type !== void 0 ? m[e.type] : m.NORMAL,
  tags: e.tags ?? void 0
}), "parseCommit"), Ye = /* @__PURE__ */ h((e) => ({
  name: e.name,
  order: e.order ?? 0
}), "parseBranch"), je = /* @__PURE__ */ h((e) => ({
  branch: e.branch,
  id: e.id ?? "",
  type: e.type !== void 0 ? m[e.type] : void 0,
  tags: e.tags ?? void 0
}), "parseMerge"), Ue = /* @__PURE__ */ h((e) => e.branch, "parseCheckout"), Ke = /* @__PURE__ */ h((e) => ({
  id: e.id,
  targetId: "",
  tags: e.tags?.length === 0 ? void 0 : e.tags,
  parent: e.parent
}), "parseCherryPicking"), Ve = {
  parse: /* @__PURE__ */ h(async (e) => {
    const r = await Ee("gitGraph", e);
    w.debug(r), Ne(r, se);
  }, "parse")
}, O = 10, _ = 40, L = 4, R = 2, G = 8, j = /* @__PURE__ */ new Set(["redux", "redux-dark", "redux-color", "redux-dark-color"]), X = 12, Z = /* @__PURE__ */ new Set(["redux-color", "redux-dark-color"]), Xe = /* @__PURE__ */ new Set(["dark", "redux-dark", "redux-dark-color", "neo-dark"]), H = /* @__PURE__ */ h((e, r, t = !1) => t && e > 0 ? (e - 1) % (r - 1) + 1 : e % r, "calcColorIndex"), C = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ new Map(), F = 30, P = /* @__PURE__ */ new Map(), z = [], I = 0, y = "LR", Qe = /* @__PURE__ */ h(() => {
  C.clear(), E.clear(), P.clear(), I = 0, z = [], y = "LR";
}, "clear"), oe = /* @__PURE__ */ h((e) => {
  const r = document.createElementNS("http://www.w3.org/2000/svg", "text");
  return (typeof e == "string" ? e.split(/\\n|\n|<br\s*\/?>/gi) : e).forEach((s) => {
    const o = document.createElementNS("http://www.w3.org/2000/svg", "tspan");
    o.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:space", "preserve"), o.setAttribute("dy", "1em"), o.setAttribute("x", "0"), o.setAttribute("class", "row"), o.textContent = s.trim(), r.appendChild(o);
  }), r;
}, "drawText"), ce = /* @__PURE__ */ h((e) => {
  let r, t, s;
  return y === "BT" ? (t = /* @__PURE__ */ h((o, i) => o <= i, "comparisonFunc"), s = 1 / 0) : (t = /* @__PURE__ */ h((o, i) => o >= i, "comparisonFunc"), s = 0), e.forEach((o) => {
    const i = y === "TB" || y == "BT" ? E.get(o)?.y : E.get(o)?.x;
    i !== void 0 && t(i, s) && (r = o, s = i);
  }), r;
}, "findClosestParent"), Je = /* @__PURE__ */ h((e) => {
  let r = "", t = 1 / 0;
  return e.forEach((s) => {
    const o = E.get(s).y;
    o <= t && (r = s, t = o);
  }), r || void 0;
}, "findClosestParentBT"), Ze = /* @__PURE__ */ h((e, r, t) => {
  let s = t, o = t;
  const i = [];
  e.forEach((n) => {
    const a = r.get(n);
    if (!a)
      throw new Error(`Commit not found for key ${n}`);
    a.parents.length ? (s = rr(a), o = Math.max(s, o)) : i.push(a), tr(a, s);
  }), s = o, i.forEach((n) => {
    ar(n, s, t);
  }), e.forEach((n) => {
    const a = r.get(n);
    if (a?.parents.length) {
      const l = Je(a.parents);
      s = E.get(l).y - _, s <= o && (o = s);
      const f = C.get(a.branch).pos, g = s - O;
      E.set(a.id, { x: f, y: g });
    }
  });
}, "setParallelBTPos"), er = /* @__PURE__ */ h((e) => {
  const r = ce(e.parents.filter((s) => s !== null));
  if (!r)
    throw new Error(`Closest parent not found for commit ${e.id}`);
  const t = E.get(r)?.y;
  if (t === void 0)
    throw new Error(`Closest parent position not found for commit ${e.id}`);
  return t;
}, "findClosestParentPos"), rr = /* @__PURE__ */ h((e) => er(e) + _, "calculateCommitPosition"), tr = /* @__PURE__ */ h((e, r) => {
  const t = C.get(e.branch);
  if (!t)
    throw new Error(`Branch not found for commit ${e.id}`);
  const s = t.pos, o = r + O;
  return E.set(e.id, { x: s, y: o }), { x: s, y: o };
}, "setCommitPosition"), ar = /* @__PURE__ */ h((e, r, t) => {
  const s = C.get(e.branch);
  if (!s)
    throw new Error(`Branch not found for commit ${e.id}`);
  const o = r + t, i = s.pos;
  E.set(e.id, { x: i, y: o });
}, "setRootPosition"), nr = /* @__PURE__ */ h((e, r, t, s, o, i) => {
  const { theme: n } = q(), a = j.has(n ?? ""), l = Z.has(n ?? ""), f = Xe.has(n ?? "");
  if (i === m.HIGHLIGHT)
    e.append("rect").attr("x", t.x - 10 + (a ? 3 : 0)).attr("y", t.y - 10 + (a ? 3 : 0)).attr("width", a ? 14 : 20).attr("height", a ? 14 : 20).attr(
      "class",
      `commit ${r.id} commit-highlight${H(o, G, l)} ${s}-outer`
    ), e.append("rect").attr("x", t.x - 6 + (a ? 2 : 0)).attr("y", t.y - 6 + (a ? 2 : 0)).attr("width", a ? 8 : 12).attr("height", a ? 8 : 12).attr(
      "class",
      `commit ${r.id} commit${H(o, G, l)} ${s}-inner`
    );
  else if (i === m.CHERRY_PICK)
    e.append("circle").attr("cx", t.x).attr("cy", t.y).attr("r", a ? 7 : 10).attr("class", `commit ${r.id} ${s}`), e.append("circle").attr("cx", t.x - 3).attr("cy", t.y + 2).attr("r", a ? 2.5 : 2.75).attr("fill", f ? "#000000" : "#fff").attr("class", `commit ${r.id} ${s}`), e.append("circle").attr("cx", t.x + 3).attr("cy", t.y + 2).attr("r", a ? 2.5 : 2.75).attr("fill", f ? "#000000" : "#fff").attr("class", `commit ${r.id} ${s}`), e.append("line").attr("x1", t.x + 3).attr("y1", t.y + 1).attr("x2", t.x).attr("y2", t.y - 5).attr("stroke", f ? "#000000" : "#fff").attr("class", `commit ${r.id} ${s}`), e.append("line").attr("x1", t.x - 3).attr("y1", t.y + 1).attr("x2", t.x).attr("y2", t.y - 5).attr("stroke", f ? "#000000" : "#fff").attr("class", `commit ${r.id} ${s}`);
  else {
    const g = e.append("circle");
    if (g.attr("cx", t.x), g.attr("cy", t.y), g.attr("r", a ? 7 : 10), g.attr(
      "class",
      `commit ${r.id} commit${H(o, G, l)}`
    ), i === m.MERGE) {
      const $ = e.append("circle");
      $.attr("cx", t.x), $.attr("cy", t.y), $.attr("r", a ? 5 : 6), $.attr(
        "class",
        `commit ${s} ${r.id} commit${H(o, G, l)}`
      );
    }
    if (i === m.REVERSE) {
      const $ = e.append("path"), c = a ? 4 : 5;
      $.attr(
        "d",
        `M ${t.x - c},${t.y - c}L${t.x + c},${t.y + c}M${t.x - c},${t.y + c}L${t.x + c},${t.y - c}`
      ).attr(
        "class",
        `commit ${s} ${r.id} commit${H(o, G, l)}`
      );
    }
  }
}, "drawCommitBullet"), sr = /* @__PURE__ */ h((e, r, t, s, o) => {
  if (r.type !== m.CHERRY_PICK && (r.customId && r.type === m.MERGE || r.type !== m.MERGE) && o.showCommitLabel) {
    const i = e.append("g"), n = i.insert("rect").attr("class", "commit-label-bkg"), a = i.append("text").attr("x", s).attr("y", t.y + 25).attr("class", "commit-label").text(r.id), l = a.node()?.getBBox();
    if (l && (n.attr("x", t.posWithOffset - l.width / 2 - R).attr("y", t.y + 13.5).attr("width", l.width + 2 * R).attr("height", l.height + 2 * R), y === "TB" || y === "BT" ? (n.attr("x", t.x - (l.width + 4 * L + 5)).attr("y", t.y - 12), a.attr("x", t.x - (l.width + 4 * L)).attr("y", t.y + l.height - 12)) : a.attr("x", t.posWithOffset - l.width / 2), o.rotateCommitLabel))
      if (y === "TB" || y === "BT")
        a.attr(
          "transform",
          "rotate(-45, " + t.x + ", " + t.y + ")"
        ), n.attr(
          "transform",
          "rotate(-45, " + t.x + ", " + t.y + ")"
        );
      else {
        const f = -7.5 - (l.width + 10) / 25 * 9.5, g = 10 + l.width / 25 * 8.5;
        i.attr(
          "transform",
          "translate(" + f + ", " + g + ") rotate(-45, " + s + ", " + t.y + ")"
        );
      }
  }
}, "drawCommitLabel"), or = /* @__PURE__ */ h((e, r, t, s) => {
  if (r.tags.length > 0) {
    let o = 0, i = 0, n = 0;
    const a = [];
    for (const l of r.tags.reverse()) {
      const f = e.insert("polygon"), g = e.append("circle"), $ = e.append("text").attr("y", t.y - 16 - o).attr("class", "tag-label").text(l), c = $.node()?.getBBox();
      if (!c)
        throw new Error("Tag bbox not found");
      i = Math.max(i, c.width), n = Math.max(n, c.height), $.attr("x", t.posWithOffset - c.width / 2), a.push({
        tag: $,
        hole: g,
        rect: f,
        yOffset: o
      }), o += 20;
    }
    for (const { tag: l, hole: f, rect: g, yOffset: $ } of a) {
      const c = n / 2, x = t.y - 19.2 - $;
      if (g.attr("class", "tag-label-bkg").attr(
        "points",
        `
      ${s - i / 2 - L / 2},${x + R}  
      ${s - i / 2 - L / 2},${x - R}
      ${t.posWithOffset - i / 2 - L},${x - c - R}
      ${t.posWithOffset + i / 2 + L},${x - c - R}
      ${t.posWithOffset + i / 2 + L},${x + c + R}
      ${t.posWithOffset - i / 2 - L},${x + c + R}`
      ), f.attr("cy", x).attr("cx", s - i / 2 + L / 2).attr("r", 1.5).attr("class", "tag-hole"), y === "TB" || y === "BT") {
        const u = s + $;
        g.attr("class", "tag-label-bkg").attr(
          "points",
          `
        ${t.x},${u + 2}
        ${t.x},${u - 2}
        ${t.x + O},${u - c - 2}
        ${t.x + O + i + 4},${u - c - 2}
        ${t.x + O + i + 4},${u + c + 2}
        ${t.x + O},${u + c + 2}`
        ).attr("transform", "translate(12,12) rotate(45, " + t.x + "," + s + ")"), f.attr("cx", t.x + L / 2).attr("cy", u).attr("transform", "translate(12,12) rotate(45, " + t.x + "," + s + ")"), l.attr("x", t.x + 5).attr("y", u + 3).attr("transform", "translate(14,14) rotate(45, " + t.x + "," + s + ")");
      }
    }
  }
}, "drawCommitTags"), cr = /* @__PURE__ */ h((e) => {
  switch (e.customType ?? e.type) {
    case m.NORMAL:
      return "commit-normal";
    case m.REVERSE:
      return "commit-reverse";
    case m.HIGHLIGHT:
      return "commit-highlight";
    case m.MERGE:
      return "commit-merge";
    case m.CHERRY_PICK:
      return "commit-cherry-pick";
    default:
      return "commit-normal";
  }
}, "getCommitClassType"), ir = /* @__PURE__ */ h((e, r, t, s) => {
  const o = { x: 0, y: 0 };
  if (e.parents.length > 0) {
    const i = ce(e.parents);
    if (i) {
      const n = s.get(i) ?? o;
      return r === "TB" ? n.y + _ : r === "BT" ? (s.get(e.id) ?? o).y - _ : n.x + _;
    }
  } else
    return r === "TB" ? F : r === "BT" ? (s.get(e.id) ?? o).y - _ : 0;
  return 0;
}, "calculatePosition"), dr = /* @__PURE__ */ h((e, r, t) => {
  const s = y === "BT" && t ? r : r + O, o = C.get(e.branch)?.pos, i = y === "TB" || y === "BT" ? C.get(e.branch)?.pos : s;
  if (i === void 0 || o === void 0)
    throw new Error(`Position were undefined for commit ${e.id}`);
  const n = j.has(q().theme ?? ""), a = y === "TB" || y === "BT" ? s : o + (n ? X / 2 + 1 : -2);
  return { x: i, y: a, posWithOffset: s };
}, "getCommitPosition"), re = /* @__PURE__ */ h((e, r, t, s) => {
  const o = e.append("g").attr("class", "commit-bullets"), i = e.append("g").attr("class", "commit-labels");
  let n = y === "TB" || y === "BT" ? F : 0;
  const a = [...r.keys()], l = s.parallelCommits ?? !1, f = /* @__PURE__ */ h(($, c) => {
    const x = r.get($)?.seq, u = r.get(c)?.seq;
    return x !== void 0 && u !== void 0 ? x - u : 0;
  }, "sortKeys");
  let g = a.sort(f);
  y === "BT" && (l && Ze(g, r, n), g = g.reverse()), g.forEach(($) => {
    const c = r.get($);
    if (!c)
      throw new Error(`Commit not found for key ${$}`);
    l && (n = ir(c, y, n, E));
    const x = dr(c, n, l);
    if (t) {
      const u = cr(c), p = c.customType ?? c.type, b = C.get(c.branch)?.index ?? 0;
      nr(o, c, x, u, b, p), sr(i, c, x, n, s), or(i, c, x, n);
    }
    y === "TB" || y === "BT" ? E.set(c.id, { x: x.x, y: x.posWithOffset }) : E.set(c.id, { x: x.posWithOffset, y: x.y }), n = y === "BT" && l ? n + _ : n + _ + O, n > I && (I = n);
  });
}, "drawCommits"), lr = /* @__PURE__ */ h((e, r, t, s, o) => {
  const n = (y === "TB" || y === "BT" ? t.x < s.x : t.y < s.y) ? r.branch : e.branch, a = /* @__PURE__ */ h((f) => f.branch === n, "isOnBranchToGetCurve"), l = /* @__PURE__ */ h((f) => f.seq > e.seq && f.seq < r.seq, "isBetweenCommits");
  return [...o.values()].some((f) => l(f) && a(f));
}, "shouldRerouteArrow"), W = /* @__PURE__ */ h((e, r, t = 0) => {
  const s = e + Math.abs(e - r) / 2;
  if (t > 5)
    return s;
  if (z.every((n) => Math.abs(n - s) >= 10))
    return z.push(s), s;
  const i = Math.abs(e - r);
  return W(e, r - i / 5, t + 1);
}, "findLane"), hr = /* @__PURE__ */ h((e, r, t, s) => {
  const { theme: o } = q(), i = Z.has(o ?? ""), n = E.get(r.id), a = E.get(t.id);
  if (n === void 0 || a === void 0)
    throw new Error(`Commit positions not found for commits ${r.id} and ${t.id}`);
  const l = lr(r, t, n, a, s);
  let f = "", g = "", $ = 0, c = 0, x = C.get(t.branch)?.index;
  t.type === m.MERGE && r.id !== t.parents[0] && (x = C.get(r.branch)?.index);
  let u;
  if (l) {
    f = "A 10 10, 0, 0, 0,", g = "A 10 10, 0, 0, 1,", $ = 10, c = 10;
    const p = n.y < a.y ? W(n.y, a.y) : W(a.y, n.y), b = n.x < a.x ? W(n.x, a.x) : W(a.x, n.x);
    y === "TB" ? n.x < a.x ? u = `M ${n.x} ${n.y} L ${b - $} ${n.y} ${g} ${b} ${n.y + c} L ${b} ${a.y - $} ${f} ${b + c} ${a.y} L ${a.x} ${a.y}` : (x = C.get(r.branch)?.index, u = `M ${n.x} ${n.y} L ${b + $} ${n.y} ${f} ${b} ${n.y + c} L ${b} ${a.y - $} ${g} ${b - c} ${a.y} L ${a.x} ${a.y}`) : y === "BT" ? n.x < a.x ? u = `M ${n.x} ${n.y} L ${b - $} ${n.y} ${f} ${b} ${n.y - c} L ${b} ${a.y + $} ${g} ${b + c} ${a.y} L ${a.x} ${a.y}` : (x = C.get(r.branch)?.index, u = `M ${n.x} ${n.y} L ${b + $} ${n.y} ${g} ${b} ${n.y - c} L ${b} ${a.y + $} ${f} ${b - c} ${a.y} L ${a.x} ${a.y}`) : n.y < a.y ? u = `M ${n.x} ${n.y} L ${n.x} ${p - $} ${f} ${n.x + c} ${p} L ${a.x - $} ${p} ${g} ${a.x} ${p + c} L ${a.x} ${a.y}` : (x = C.get(r.branch)?.index, u = `M ${n.x} ${n.y} L ${n.x} ${p + $} ${g} ${n.x + c} ${p} L ${a.x - $} ${p} ${f} ${a.x} ${p - c} L ${a.x} ${a.y}`);
  } else
    f = "A 20 20, 0, 0, 0,", g = "A 20 20, 0, 0, 1,", $ = 20, c = 20, y === "TB" ? (n.x < a.x && (t.type === m.MERGE && r.id !== t.parents[0] ? u = `M ${n.x} ${n.y} L ${n.x} ${a.y - $} ${f} ${n.x + c} ${a.y} L ${a.x} ${a.y}` : u = `M ${n.x} ${n.y} L ${a.x - $} ${n.y} ${g} ${a.x} ${n.y + c} L ${a.x} ${a.y}`), n.x > a.x && (f = "A 20 20, 0, 0, 0,", g = "A 20 20, 0, 0, 1,", $ = 20, c = 20, t.type === m.MERGE && r.id !== t.parents[0] ? u = `M ${n.x} ${n.y} L ${n.x} ${a.y - $} ${g} ${n.x - c} ${a.y} L ${a.x} ${a.y}` : u = `M ${n.x} ${n.y} L ${a.x + $} ${n.y} ${f} ${a.x} ${n.y + c} L ${a.x} ${a.y}`), n.x === a.x && (u = `M ${n.x} ${n.y} L ${a.x} ${a.y}`)) : y === "BT" ? (n.x < a.x && (t.type === m.MERGE && r.id !== t.parents[0] ? u = `M ${n.x} ${n.y} L ${n.x} ${a.y + $} ${g} ${n.x + c} ${a.y} L ${a.x} ${a.y}` : u = `M ${n.x} ${n.y} L ${a.x - $} ${n.y} ${f} ${a.x} ${n.y - c} L ${a.x} ${a.y}`), n.x > a.x && (f = "A 20 20, 0, 0, 0,", g = "A 20 20, 0, 0, 1,", $ = 20, c = 20, t.type === m.MERGE && r.id !== t.parents[0] ? u = `M ${n.x} ${n.y} L ${n.x} ${a.y + $} ${f} ${n.x - c} ${a.y} L ${a.x} ${a.y}` : u = `M ${n.x} ${n.y} L ${a.x + $} ${n.y} ${g} ${a.x} ${n.y - c} L ${a.x} ${a.y}`), n.x === a.x && (u = `M ${n.x} ${n.y} L ${a.x} ${a.y}`)) : (n.y < a.y && (t.type === m.MERGE && r.id !== t.parents[0] ? u = `M ${n.x} ${n.y} L ${a.x - $} ${n.y} ${g} ${a.x} ${n.y + c} L ${a.x} ${a.y}` : u = `M ${n.x} ${n.y} L ${n.x} ${a.y - $} ${f} ${n.x + c} ${a.y} L ${a.x} ${a.y}`), n.y > a.y && (t.type === m.MERGE && r.id !== t.parents[0] ? u = `M ${n.x} ${n.y} L ${a.x - $} ${n.y} ${f} ${a.x} ${n.y - c} L ${a.x} ${a.y}` : u = `M ${n.x} ${n.y} L ${n.x} ${a.y + $} ${g} ${n.x + c} ${a.y} L ${a.x} ${a.y}`), n.y === a.y && (u = `M ${n.x} ${n.y} L ${a.x} ${a.y}`));
  if (u === void 0)
    throw new Error("Line definition not found");
  e.append("path").attr("d", u).attr(
    "class",
    "arrow arrow" + H(x, G, i)
  );
}, "drawArrow"), $r = /* @__PURE__ */ h((e, r) => {
  const t = e.append("g").attr("class", "commit-arrows");
  [...r.keys()].forEach((s) => {
    const o = r.get(s);
    o.parents && o.parents.length > 0 && o.parents.forEach((i) => {
      hr(t, r.get(i), o, r);
    });
  });
}, "drawArrows"), fr = /* @__PURE__ */ h((e, r, t, s) => {
  const { look: o, theme: i, themeVariables: n } = q(), { dropShadow: a, THEME_COLOR_LIMIT: l } = n, f = j.has(i ?? ""), g = Z.has(i ?? ""), $ = e.append("g");
  r.forEach((c, x) => {
    const u = H(
      x,
      f ? l : G,
      g
    ), p = C.get(c.name)?.pos;
    if (p === void 0)
      throw new Error(`Position not found for branch ${c.name}`);
    const b = y === "TB" || y === "BT" ? p : f ? p + X / 2 + 1 : p - 2, k = $.append("line");
    k.attr("x1", 0), k.attr("y1", b), k.attr("x2", I), k.attr("y2", b), k.attr("class", "branch branch" + u), y === "TB" ? (k.attr("y1", F), k.attr("x1", p), k.attr("y2", I), k.attr("x2", p)) : y === "BT" && (k.attr("y1", I), k.attr("x1", p), k.attr("y2", F), k.attr("x2", p)), z.push(b);
    const U = c.name, D = oe(U), T = $.insert("rect"), M = $.insert("g").attr("class", "branchLabel").insert("g").attr("class", "label branch-label" + u);
    M.node().appendChild(D);
    const v = D.getBBox(), ee = f ? 0 : 4, N = f ? 16 : 0, A = f ? X : 0;
    o === "neo" && T.attr("data-look", "neo"), T.attr("class", "branchLabelBkg label" + u).attr(
      "style",
      o === "neo" ? `filter:${f ? `url(#${s}-drop-shadow)` : a}` : ""
    ).attr("rx", ee).attr("ry", ee).attr("x", -v.width - 4 - (t.rotateCommitLabel === !0 ? 30 : 0)).attr("y", -v.height / 2 + 10).attr("width", v.width + 18 + N).attr("height", v.height + 4 + A), M.attr(
      "transform",
      "translate(" + (-v.width - 14 - (t.rotateCommitLabel === !0 ? 30 : 0) + N / 2) + ", " + (b - v.height / 2 - 2) + ")"
    ), y === "TB" ? (T.attr("x", p - v.width / 2 - 10).attr("y", 0), M.attr("transform", "translate(" + (p - v.width / 2 - 5) + ", 0)"), f && (T.attr("transform", `translate(${-N / 2 - 3}, ${-A - 10})`), M.attr(
      "transform",
      "translate(" + (p - v.width / 2 - 5) + ", " + (-A * 2 + 7) + ")"
    ))) : y === "BT" ? (T.attr("x", p - v.width / 2 - 10).attr("y", I), M.attr("transform", "translate(" + (p - v.width / 2 - 5) + ", " + I + ")"), f && (T.attr("transform", `translate(${-N / 2 - 3}, ${A + 10})`), M.attr(
      "transform",
      "translate(" + (p - v.width / 2 - 5) + ", " + (I + A * 2 + 4) + ")"
    ))) : T.attr("transform", "translate(-19, " + (b - 12 - A / 2) + ")");
  });
}, "drawBranches"), gr = /* @__PURE__ */ h(function(e, r, t, s, o) {
  return C.set(e, { pos: r, index: t }), r += 50 + (o ? 40 : 0) + (y === "TB" || y === "BT" ? s.width / 2 : 0), r;
}, "setBranchPosition"), ur = /* @__PURE__ */ h(function(e, r, t, s) {
  Qe(), w.debug("in gitgraph renderer", e + `
`, "id:", r, t);
  const o = s.db;
  if (!o.getConfig) {
    w.error("getConfig method is not available on db");
    return;
  }
  const i = o.getConfig(), n = i.rotateCommitLabel ?? !1;
  P = o.getCommits();
  const a = o.getBranchesAsObjArray();
  y = o.getDirection();
  const l = me(`[id="${r}"]`), { look: f, theme: g, themeVariables: $ } = q(), { useGradient: c, gradientStart: x, gradientStop: u, filterColor: p } = $;
  if (c) {
    const k = l.append("defs").append("linearGradient").attr("id", r + "-gradient").attr("gradientUnits", "objectBoundingBox").attr("x1", "0%").attr("y1", "0%").attr("x2", "100%").attr("y2", "0%");
    k.append("stop").attr("offset", "0%").attr("stop-color", x).attr("stop-opacity", 1), k.append("stop").attr("offset", "100%").attr("stop-color", u).attr("stop-opacity", 1);
  }
  f === "neo" && j.has(g ?? "") && l.append("defs").append("filter").attr("id", r + "-drop-shadow").attr("height", "130%").attr("width", "130%").append("feDropShadow").attr("dx", "4").attr("dy", "4").attr("stdDeviation", 0).attr("flood-opacity", "0.06").attr("flood-color", p);
  let b = 0;
  a.forEach((k, U) => {
    const D = oe(k.name), T = l.append("g"), K = T.insert("g").attr("class", "branchLabel"), M = K.insert("g").attr("class", "label branch-label");
    M.node()?.appendChild(D);
    const v = D.getBBox();
    b = gr(k.name, b, U, v, n), M.remove(), K.remove(), T.remove();
  }), re(l, P, !1, i), i.showBranches && fr(l, a, i, r), $r(l, P), re(l, P, !0, i), pe.insertTitle(
    l,
    "gitTitleText",
    i.titleTopMargin ?? 0,
    o.getDiagramTitle()
  ), be(void 0, l, i.diagramPadding, i.useMaxWidth);
}, "draw"), yr = {
  draw: ur
}, ie = 8, de = /* @__PURE__ */ new Set(["redux", "redux-dark", "redux-color", "redux-dark-color"]), xr = /* @__PURE__ */ new Set(["redux-color", "redux-dark-color"]), mr = /* @__PURE__ */ new Set(["neo", "neo-dark"]), pr = /* @__PURE__ */ new Set(["dark", "redux-dark", "redux-dark-color", "neo-dark"]), br = /* @__PURE__ */ new Set([
  "redux",
  "redux-dark",
  "redux-color",
  "redux-dark-color",
  "neo",
  "neo-dark"
]), wr = /* @__PURE__ */ h((e) => {
  const { svgId: r } = e;
  let t = "";
  if (e.useGradient && r)
    for (let s = 0; s < e.THEME_COLOR_LIMIT; s++)
      t += `
      .label${s}  { fill: ${e.mainBkg}; stroke: url(${r}-gradient); stroke-width: ${e.strokeWidth};}
             `;
  return t;
}, "genGitGraphGradient"), kr = /* @__PURE__ */ h((e) => {
  const r = Q(), { theme: t, themeVariables: s } = r, { borderColorArray: o } = s, i = de.has(t);
  if (mr.has(t)) {
    let n = "";
    for (let a = 0; a < e.THEME_COLOR_LIMIT; a++)
      if (a === 0)
        n += `
        .branch-label${a} { fill: ${e.nodeBorder};}
        .commit${a} { stroke: ${e.nodeBorder};   }
        .commit-highlight${a} { stroke: ${e.nodeBorder}; fill: ${e.nodeBorder}; }
        .arrow${a} { stroke: ${e.nodeBorder}; }
        .commit-bullets { fill: ${e.nodeBorder}; }
        .commit-cherry-pick${a} { stroke: ${e.nodeBorder}; }
        ${wr(e)}`;
      else {
        const l = a % ie;
        n += `
        .branch-label${a} { fill: ${e["gitBranchLabel" + l]}; }
        .commit${a} { stroke: ${e["git" + l]}; fill: ${e["git" + l]}; }
        .commit-highlight${a} { stroke: ${e["gitInv" + l]}; fill: ${e["gitInv" + l]}; }
        .arrow${a} { stroke: ${e["git" + l]}; }
        `;
      }
    return n;
  } else if (xr.has(t)) {
    let n = "";
    for (let a = 0; a < e.THEME_COLOR_LIMIT; a++)
      if (a === 0)
        n += `
        .branch-label${a} { fill: ${e.nodeBorder}; ${i ? `font-weight:${e.noteFontWeight}` : ""} }
        .commit${a} { stroke: ${e.nodeBorder}; }
        .commit-highlight${a} { stroke: ${e.nodeBorder}; fill: ${e.mainBkg}; }
        .label${a}  { fill: ${e.mainBkg}; stroke: ${e.nodeBorder}; stroke-width: ${e.strokeWidth}; ${i ? `font-weight:${e.noteFontWeight}` : ""} }
        .arrow${a} { stroke: ${e.nodeBorder}; }
        .commit-bullets { fill: ${e.nodeBorder}; }
        `;
      else {
        const l = a % o.length;
        n += `
        .branch-label${a} { fill: ${e.nodeBorder}; ${i ? `font-weight:${e.noteFontWeight}` : ""} }
        .commit${a} { stroke: ${o[l]}; fill: ${o[l]}; }
        .commit-highlight${a} { stroke: ${o[l]}; fill: ${o[l]}; }
        .label${a}  { fill: ${pr.has(t) ? e.mainBkg : o[l]}; stroke: ${o[l]};  stroke-width: ${e.strokeWidth}; }
        .arrow${a} { stroke: ${o[l]}; }
        `;
      }
    return n;
  } else {
    let n = "";
    for (let a = 0; a < e.THEME_COLOR_LIMIT; a++)
      n += `
        .branch-label${a} { fill: ${e.nodeBorder}; ${i ? `font-weight:${e.noteFontWeight}` : ""} }
        .commit${a} { stroke: ${e.nodeBorder};   }
        .commit-highlight${a} { stroke: ${e.nodeBorder}; fill: ${e.nodeBorder}; }
        .label${a}  { fill: ${e.mainBkg}; stroke: ${e.nodeBorder}; stroke-width: ${e.strokeWidth}; ${i ? `font-weight:${e.noteFontWeight}` : ""}}
        .arrow${a} { stroke: ${e.nodeBorder}; }
        .commit-bullets { fill: ${e.nodeBorder}; }
        .commit-cherry-pick${a} { stroke: ${e.nodeBorder}; }
        `;
    return n;
  }
}, "genColor"), vr = /* @__PURE__ */ h((e) => `${Array.from({ length: e.THEME_COLOR_LIMIT }, (r, t) => t).map((r) => {
  const t = r % ie;
  return `
        .branch-label${r} { fill: ${e["gitBranchLabel" + t]}; }
        .commit${r} { stroke: ${e["git" + t]}; fill: ${e["git" + t]}; }
        .commit-highlight${r} { stroke: ${e["gitInv" + t]}; fill: ${e["gitInv" + t]}; }
        .label${r}  { fill: ${e["git" + t]}; }
        .arrow${r} { stroke: ${e["git" + t]}; }
        `;
}).join(`
`)}`, "normalTheme"), Cr = /* @__PURE__ */ h((e) => {
  const r = Q(), { theme: t } = r, s = br.has(t);
  return `
  .commit-id,
  .commit-msg,
  .branch-label {
    fill: lightgrey;
    color: lightgrey;
    font-family: 'trebuchet ms', verdana, arial, sans-serif;
    font-family: var(--mermaid-font-family);
  }
  
  ${s ? kr(e) : vr(e)}

  .branch {
    stroke-width: ${e.strokeWidth};
    stroke: ${e.commitLineColor ?? e.lineColor};
    stroke-dasharray:  ${s ? "4 2" : "2"};
  }
  .commit-label { font-size: ${e.commitLabelFontSize}; fill: ${s ? e.nodeBorder : e.commitLabelColor}; ${s ? `font-weight:${e.noteFontWeight};` : ""}}
  .commit-label-bkg { font-size: ${e.commitLabelFontSize}; fill: ${s ? "transparent" : e.commitLabelBackground}; opacity: ${s ? "" : 0.5};  }
  .tag-label { font-size: ${e.tagLabelFontSize}; fill: ${e.tagLabelColor};}
  .tag-label-bkg { fill: ${s ? e.mainBkg : e.tagLabelBackground}; stroke: ${s ? e.nodeBorder : e.tagLabelBorder}; ${s ? `filter:${e.dropShadow}` : ""}  }
  .tag-hole { fill: ${e.textColor}; }

  .commit-merge {
    stroke: ${s ? e.mainBkg : e.primaryColor};
    fill: ${s ? e.mainBkg : e.primaryColor};
  }
  .commit-reverse {
    stroke: ${s ? e.mainBkg : e.primaryColor};
    fill: ${s ? e.mainBkg : e.primaryColor};
    stroke-width: ${s ? e.strokeWidth : 3};
  }
  .commit-highlight-outer {
  }
  .commit-highlight-inner {
    stroke: ${s ? e.mainBkg : e.primaryColor};
    fill: ${s ? e.mainBkg : e.primaryColor};
  }

  .arrow {
    /* Intentional: neo themes keep the bold 8px arrow (like classic themes); only redux-geometry themes use the thinner options.strokeWidth. */
    stroke-width: ${de.has(t) ? e.strokeWidth : 8};
    stroke-linecap: round;
    fill: none
  }
  .gitTitleText {
    text-anchor: middle;
    font-size: 18px;
    fill: ${e.textColor};
  }
`;
}, "getStyles"), Er = Cr, Rr = {
  parser: Ve,
  db: se,
  renderer: yr,
  styles: Er
};
export {
  Rr as diagram
};
