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

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

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

  .arrow {
    /* Intentional: neo themes keep the bold 8px arrow (like classic themes); only redux-geometry themes use the thinner options.strokeWidth. */
    stroke-width: ${dt.has(r) ? t.strokeWidth : 8};
    stroke-linecap: round;
    fill: none
  }
  .gitTitleText {
    text-anchor: middle;
    font-size: 18px;
    fill: ${t.textColor};
  }
`;
  }, "getStyles")
};
export {
  Er as diagram
};
