UNPKG

markdown-flow-ui

Version:

A React UI library for rendering markdown with interactive flow components, typewriter effects, and plugin support

1 lines 105 kB
{"version":3,"file":"gitGraphDiagram-OJR772UL-BgV0yMUS.mjs","sources":["../node_modules/mermaid/dist/chunks/mermaid.core/gitGraphDiagram-OJR772UL.mjs"],"sourcesContent":["import {\n populateCommonDb\n} from \"./chunk-ANTBXLJU.mjs\";\nimport {\n ImperativeState\n} from \"./chunk-FHKO5MBM.mjs\";\nimport {\n cleanAndMerge,\n random,\n utils_default\n} from \"./chunk-U37J5Y7L.mjs\";\nimport {\n __name,\n clear,\n common_default,\n defaultConfig_default,\n getAccDescription,\n getAccTitle,\n getConfig,\n getConfig2,\n getDiagramTitle,\n log,\n setAccDescription,\n setAccTitle,\n setDiagramTitle,\n setupGraphViewbox2 as setupGraphViewbox\n} from \"./chunk-VIW5F6AA.mjs\";\n\n// src/diagrams/git/gitGraphParser.ts\nimport { parse } from \"@mermaid-js/parser\";\n\n// src/diagrams/git/gitGraphTypes.ts\nvar commitType = {\n NORMAL: 0,\n REVERSE: 1,\n HIGHLIGHT: 2,\n MERGE: 3,\n CHERRY_PICK: 4\n};\n\n// src/diagrams/git/gitGraphAst.ts\nvar DEFAULT_GITGRAPH_CONFIG = defaultConfig_default.gitGraph;\nvar getConfig3 = /* @__PURE__ */ __name(() => {\n const config = cleanAndMerge({\n ...DEFAULT_GITGRAPH_CONFIG,\n ...getConfig().gitGraph\n });\n return config;\n}, \"getConfig\");\nvar state = new ImperativeState(() => {\n const config = getConfig3();\n const mainBranchName = config.mainBranchName;\n const mainBranchOrder = config.mainBranchOrder;\n return {\n mainBranchName,\n commits: /* @__PURE__ */ new Map(),\n head: null,\n branchConfig: /* @__PURE__ */ new Map([[mainBranchName, { name: mainBranchName, order: mainBranchOrder }]]),\n branches: /* @__PURE__ */ new Map([[mainBranchName, null]]),\n currBranch: mainBranchName,\n direction: \"LR\",\n seq: 0,\n options: {}\n };\n});\nfunction getID() {\n return random({ length: 7 });\n}\n__name(getID, \"getID\");\nfunction uniqBy(list, fn) {\n const recordMap = /* @__PURE__ */ Object.create(null);\n return list.reduce((out, item) => {\n const key = fn(item);\n if (!recordMap[key]) {\n recordMap[key] = true;\n out.push(item);\n }\n return out;\n }, []);\n}\n__name(uniqBy, \"uniqBy\");\nvar setDirection = /* @__PURE__ */ __name(function(dir2) {\n state.records.direction = dir2;\n}, \"setDirection\");\nvar setOptions = /* @__PURE__ */ __name(function(rawOptString) {\n log.debug(\"options str\", rawOptString);\n rawOptString = rawOptString?.trim();\n rawOptString = rawOptString || \"{}\";\n try {\n state.records.options = JSON.parse(rawOptString);\n } catch (e) {\n log.error(\"error while parsing gitGraph options\", e.message);\n }\n}, \"setOptions\");\nvar getOptions = /* @__PURE__ */ __name(function() {\n return state.records.options;\n}, \"getOptions\");\nvar commit = /* @__PURE__ */ __name(function(commitDB) {\n let msg = commitDB.msg;\n let id = commitDB.id;\n const type = commitDB.type;\n let tags = commitDB.tags;\n log.info(\"commit\", msg, id, type, tags);\n log.debug(\"Entering commit:\", msg, id, type, tags);\n const config = getConfig3();\n id = common_default.sanitizeText(id, config);\n msg = common_default.sanitizeText(msg, config);\n tags = tags?.map((tag) => common_default.sanitizeText(tag, config));\n const newCommit = {\n id: id ? id : state.records.seq + \"-\" + getID(),\n message: msg,\n seq: state.records.seq++,\n type: type ?? commitType.NORMAL,\n tags: tags ?? [],\n parents: state.records.head == null ? [] : [state.records.head.id],\n branch: state.records.currBranch\n };\n state.records.head = newCommit;\n log.info(\"main branch\", config.mainBranchName);\n if (state.records.commits.has(newCommit.id)) {\n log.warn(`Commit ID ${newCommit.id} already exists`);\n }\n state.records.commits.set(newCommit.id, newCommit);\n state.records.branches.set(state.records.currBranch, newCommit.id);\n log.debug(\"in pushCommit \" + newCommit.id);\n}, \"commit\");\nvar branch = /* @__PURE__ */ __name(function(branchDB) {\n let name = branchDB.name;\n const order = branchDB.order;\n name = common_default.sanitizeText(name, getConfig3());\n if (state.records.branches.has(name)) {\n throw new Error(\n `Trying to create an existing branch. (Help: Either use a new name if you want create a new branch or try using \"checkout ${name}\")`\n );\n }\n state.records.branches.set(name, state.records.head != null ? state.records.head.id : null);\n state.records.branchConfig.set(name, { name, order });\n checkout(name);\n log.debug(\"in createBranch\");\n}, \"branch\");\nvar merge = /* @__PURE__ */ __name((mergeDB) => {\n let otherBranch = mergeDB.branch;\n let customId = mergeDB.id;\n const overrideType = mergeDB.type;\n const customTags = mergeDB.tags;\n const config = getConfig3();\n otherBranch = common_default.sanitizeText(otherBranch, config);\n if (customId) {\n customId = common_default.sanitizeText(customId, config);\n }\n const currentBranchCheck = state.records.branches.get(state.records.currBranch);\n const otherBranchCheck = state.records.branches.get(otherBranch);\n const currentCommit = currentBranchCheck ? state.records.commits.get(currentBranchCheck) : void 0;\n const otherCommit = otherBranchCheck ? state.records.commits.get(otherBranchCheck) : void 0;\n if (currentCommit && otherCommit && currentCommit.branch === otherBranch) {\n throw new Error(`Cannot merge branch '${otherBranch}' into itself.`);\n }\n if (state.records.currBranch === otherBranch) {\n const error = new Error('Incorrect usage of \"merge\". Cannot merge a branch to itself');\n error.hash = {\n text: `merge ${otherBranch}`,\n token: `merge ${otherBranch}`,\n expected: [\"branch abc\"]\n };\n throw error;\n }\n if (currentCommit === void 0 || !currentCommit) {\n const error = new Error(\n `Incorrect usage of \"merge\". Current branch (${state.records.currBranch})has no commits`\n );\n error.hash = {\n text: `merge ${otherBranch}`,\n token: `merge ${otherBranch}`,\n expected: [\"commit\"]\n };\n throw error;\n }\n if (!state.records.branches.has(otherBranch)) {\n const error = new Error(\n 'Incorrect usage of \"merge\". Branch to be merged (' + otherBranch + \") does not exist\"\n );\n error.hash = {\n text: `merge ${otherBranch}`,\n token: `merge ${otherBranch}`,\n expected: [`branch ${otherBranch}`]\n };\n throw error;\n }\n if (otherCommit === void 0 || !otherCommit) {\n const error = new Error(\n 'Incorrect usage of \"merge\". Branch to be merged (' + otherBranch + \") has no commits\"\n );\n error.hash = {\n text: `merge ${otherBranch}`,\n token: `merge ${otherBranch}`,\n expected: ['\"commit\"']\n };\n throw error;\n }\n if (currentCommit === otherCommit) {\n const error = new Error('Incorrect usage of \"merge\". Both branches have same head');\n error.hash = {\n text: `merge ${otherBranch}`,\n token: `merge ${otherBranch}`,\n expected: [\"branch abc\"]\n };\n throw error;\n }\n if (customId && state.records.commits.has(customId)) {\n const error = new Error(\n 'Incorrect usage of \"merge\". Commit with id:' + customId + \" already exists, use different custom id\"\n );\n error.hash = {\n text: `merge ${otherBranch} ${customId} ${overrideType} ${customTags?.join(\" \")}`,\n token: `merge ${otherBranch} ${customId} ${overrideType} ${customTags?.join(\" \")}`,\n expected: [\n `merge ${otherBranch} ${customId}_UNIQUE ${overrideType} ${customTags?.join(\" \")}`\n ]\n };\n throw error;\n }\n const verifiedBranch = otherBranchCheck ? otherBranchCheck : \"\";\n const commit2 = {\n id: customId || `${state.records.seq}-${getID()}`,\n message: `merged branch ${otherBranch} into ${state.records.currBranch}`,\n seq: state.records.seq++,\n parents: state.records.head == null ? [] : [state.records.head.id, verifiedBranch],\n branch: state.records.currBranch,\n type: commitType.MERGE,\n customType: overrideType,\n customId: customId ? true : false,\n tags: customTags ?? []\n };\n state.records.head = commit2;\n state.records.commits.set(commit2.id, commit2);\n state.records.branches.set(state.records.currBranch, commit2.id);\n log.debug(state.records.branches);\n log.debug(\"in mergeBranch\");\n}, \"merge\");\nvar cherryPick = /* @__PURE__ */ __name(function(cherryPickDB) {\n let sourceId = cherryPickDB.id;\n let targetId = cherryPickDB.targetId;\n let tags = cherryPickDB.tags;\n let parentCommitId = cherryPickDB.parent;\n log.debug(\"Entering cherryPick:\", sourceId, targetId, tags);\n const config = getConfig3();\n sourceId = common_default.sanitizeText(sourceId, config);\n targetId = common_default.sanitizeText(targetId, config);\n tags = tags?.map((tag) => common_default.sanitizeText(tag, config));\n parentCommitId = common_default.sanitizeText(parentCommitId, config);\n if (!sourceId || !state.records.commits.has(sourceId)) {\n const error = new Error(\n 'Incorrect usage of \"cherryPick\". Source commit id should exist and provided'\n );\n error.hash = {\n text: `cherryPick ${sourceId} ${targetId}`,\n token: `cherryPick ${sourceId} ${targetId}`,\n expected: [\"cherry-pick abc\"]\n };\n throw error;\n }\n const sourceCommit = state.records.commits.get(sourceId);\n if (sourceCommit === void 0 || !sourceCommit) {\n throw new Error('Incorrect usage of \"cherryPick\". Source commit id should exist and provided');\n }\n if (parentCommitId && !(Array.isArray(sourceCommit.parents) && sourceCommit.parents.includes(parentCommitId))) {\n const error = new Error(\n \"Invalid operation: The specified parent commit is not an immediate parent of the cherry-picked commit.\"\n );\n throw error;\n }\n const sourceCommitBranch = sourceCommit.branch;\n if (sourceCommit.type === commitType.MERGE && !parentCommitId) {\n const error = new Error(\n \"Incorrect usage of cherry-pick: If the source commit is a merge commit, an immediate parent commit must be specified.\"\n );\n throw error;\n }\n if (!targetId || !state.records.commits.has(targetId)) {\n if (sourceCommitBranch === state.records.currBranch) {\n const error = new Error(\n 'Incorrect usage of \"cherryPick\". Source commit is already on current branch'\n );\n error.hash = {\n text: `cherryPick ${sourceId} ${targetId}`,\n token: `cherryPick ${sourceId} ${targetId}`,\n expected: [\"cherry-pick abc\"]\n };\n throw error;\n }\n const currentCommitId = state.records.branches.get(state.records.currBranch);\n if (currentCommitId === void 0 || !currentCommitId) {\n const error = new Error(\n `Incorrect usage of \"cherry-pick\". Current branch (${state.records.currBranch})has no commits`\n );\n error.hash = {\n text: `cherryPick ${sourceId} ${targetId}`,\n token: `cherryPick ${sourceId} ${targetId}`,\n expected: [\"cherry-pick abc\"]\n };\n throw error;\n }\n const currentCommit = state.records.commits.get(currentCommitId);\n if (currentCommit === void 0 || !currentCommit) {\n const error = new Error(\n `Incorrect usage of \"cherry-pick\". Current branch (${state.records.currBranch})has no commits`\n );\n error.hash = {\n text: `cherryPick ${sourceId} ${targetId}`,\n token: `cherryPick ${sourceId} ${targetId}`,\n expected: [\"cherry-pick abc\"]\n };\n throw error;\n }\n const commit2 = {\n id: state.records.seq + \"-\" + getID(),\n message: `cherry-picked ${sourceCommit?.message} into ${state.records.currBranch}`,\n seq: state.records.seq++,\n parents: state.records.head == null ? [] : [state.records.head.id, sourceCommit.id],\n branch: state.records.currBranch,\n type: commitType.CHERRY_PICK,\n tags: tags ? tags.filter(Boolean) : [\n `cherry-pick:${sourceCommit.id}${sourceCommit.type === commitType.MERGE ? `|parent:${parentCommitId}` : \"\"}`\n ]\n };\n state.records.head = commit2;\n state.records.commits.set(commit2.id, commit2);\n state.records.branches.set(state.records.currBranch, commit2.id);\n log.debug(state.records.branches);\n log.debug(\"in cherryPick\");\n }\n}, \"cherryPick\");\nvar checkout = /* @__PURE__ */ __name(function(branch2) {\n branch2 = common_default.sanitizeText(branch2, getConfig3());\n if (!state.records.branches.has(branch2)) {\n const error = new Error(\n `Trying to checkout branch which is not yet created. (Help try using \"branch ${branch2}\")`\n );\n error.hash = {\n text: `checkout ${branch2}`,\n token: `checkout ${branch2}`,\n expected: [`branch ${branch2}`]\n };\n throw error;\n } else {\n state.records.currBranch = branch2;\n const id = state.records.branches.get(state.records.currBranch);\n if (id === void 0 || !id) {\n state.records.head = null;\n } else {\n state.records.head = state.records.commits.get(id) ?? null;\n }\n }\n}, \"checkout\");\nfunction upsert(arr, key, newVal) {\n const index = arr.indexOf(key);\n if (index === -1) {\n arr.push(newVal);\n } else {\n arr.splice(index, 1, newVal);\n }\n}\n__name(upsert, \"upsert\");\nfunction prettyPrintCommitHistory(commitArr) {\n const commit2 = commitArr.reduce((out, commit3) => {\n if (out.seq > commit3.seq) {\n return out;\n }\n return commit3;\n }, commitArr[0]);\n let line = \"\";\n commitArr.forEach(function(c) {\n if (c === commit2) {\n line += \"\t*\";\n } else {\n line += \"\t|\";\n }\n });\n const label = [line, commit2.id, commit2.seq];\n for (const branch2 in state.records.branches) {\n if (state.records.branches.get(branch2) === commit2.id) {\n label.push(branch2);\n }\n }\n log.debug(label.join(\" \"));\n if (commit2.parents && commit2.parents.length == 2 && commit2.parents[0] && commit2.parents[1]) {\n const newCommit = state.records.commits.get(commit2.parents[0]);\n upsert(commitArr, commit2, newCommit);\n if (commit2.parents[1]) {\n commitArr.push(state.records.commits.get(commit2.parents[1]));\n }\n } else if (commit2.parents.length == 0) {\n return;\n } else {\n if (commit2.parents[0]) {\n const newCommit = state.records.commits.get(commit2.parents[0]);\n upsert(commitArr, commit2, newCommit);\n }\n }\n commitArr = uniqBy(commitArr, (c) => c.id);\n prettyPrintCommitHistory(commitArr);\n}\n__name(prettyPrintCommitHistory, \"prettyPrintCommitHistory\");\nvar prettyPrint = /* @__PURE__ */ __name(function() {\n log.debug(state.records.commits);\n const node = getCommitsArray()[0];\n prettyPrintCommitHistory([node]);\n}, \"prettyPrint\");\nvar clear2 = /* @__PURE__ */ __name(function() {\n state.reset();\n clear();\n}, \"clear\");\nvar getBranchesAsObjArray = /* @__PURE__ */ __name(function() {\n const branchesArray = [...state.records.branchConfig.values()].map((branchConfig, i) => {\n if (branchConfig.order !== null && branchConfig.order !== void 0) {\n return branchConfig;\n }\n return {\n ...branchConfig,\n order: parseFloat(`0.${i}`)\n };\n }).sort((a, b) => (a.order ?? 0) - (b.order ?? 0)).map(({ name }) => ({ name }));\n return branchesArray;\n}, \"getBranchesAsObjArray\");\nvar getBranches = /* @__PURE__ */ __name(function() {\n return state.records.branches;\n}, \"getBranches\");\nvar getCommits = /* @__PURE__ */ __name(function() {\n return state.records.commits;\n}, \"getCommits\");\nvar getCommitsArray = /* @__PURE__ */ __name(function() {\n const commitArr = [...state.records.commits.values()];\n commitArr.forEach(function(o) {\n log.debug(o.id);\n });\n commitArr.sort((a, b) => a.seq - b.seq);\n return commitArr;\n}, \"getCommitsArray\");\nvar getCurrentBranch = /* @__PURE__ */ __name(function() {\n return state.records.currBranch;\n}, \"getCurrentBranch\");\nvar getDirection = /* @__PURE__ */ __name(function() {\n return state.records.direction;\n}, \"getDirection\");\nvar getHead = /* @__PURE__ */ __name(function() {\n return state.records.head;\n}, \"getHead\");\nvar db = {\n commitType,\n getConfig: getConfig3,\n setDirection,\n setOptions,\n getOptions,\n commit,\n branch,\n merge,\n cherryPick,\n checkout,\n //reset,\n prettyPrint,\n clear: clear2,\n getBranchesAsObjArray,\n getBranches,\n getCommits,\n getCommitsArray,\n getCurrentBranch,\n getDirection,\n getHead,\n setAccTitle,\n getAccTitle,\n getAccDescription,\n setAccDescription,\n setDiagramTitle,\n getDiagramTitle\n};\n\n// src/diagrams/git/gitGraphParser.ts\nvar populate = /* @__PURE__ */ __name((ast, db2) => {\n populateCommonDb(ast, db2);\n if (ast.dir) {\n db2.setDirection(ast.dir);\n }\n for (const statement of ast.statements) {\n parseStatement(statement, db2);\n }\n}, \"populate\");\nvar parseStatement = /* @__PURE__ */ __name((statement, db2) => {\n const parsers = {\n Commit: /* @__PURE__ */ __name((stmt) => db2.commit(parseCommit(stmt)), \"Commit\"),\n Branch: /* @__PURE__ */ __name((stmt) => db2.branch(parseBranch(stmt)), \"Branch\"),\n Merge: /* @__PURE__ */ __name((stmt) => db2.merge(parseMerge(stmt)), \"Merge\"),\n Checkout: /* @__PURE__ */ __name((stmt) => db2.checkout(parseCheckout(stmt)), \"Checkout\"),\n CherryPicking: /* @__PURE__ */ __name((stmt) => db2.cherryPick(parseCherryPicking(stmt)), \"CherryPicking\")\n };\n const parser2 = parsers[statement.$type];\n if (parser2) {\n parser2(statement);\n } else {\n log.error(`Unknown statement type: ${statement.$type}`);\n }\n}, \"parseStatement\");\nvar parseCommit = /* @__PURE__ */ __name((commit2) => {\n const commitDB = {\n id: commit2.id,\n msg: commit2.message ?? \"\",\n type: commit2.type !== void 0 ? commitType[commit2.type] : commitType.NORMAL,\n tags: commit2.tags ?? void 0\n };\n return commitDB;\n}, \"parseCommit\");\nvar parseBranch = /* @__PURE__ */ __name((branch2) => {\n const branchDB = {\n name: branch2.name,\n order: branch2.order ?? 0\n };\n return branchDB;\n}, \"parseBranch\");\nvar parseMerge = /* @__PURE__ */ __name((merge2) => {\n const mergeDB = {\n branch: merge2.branch,\n id: merge2.id ?? \"\",\n type: merge2.type !== void 0 ? commitType[merge2.type] : void 0,\n tags: merge2.tags ?? void 0\n };\n return mergeDB;\n}, \"parseMerge\");\nvar parseCheckout = /* @__PURE__ */ __name((checkout2) => {\n const branch2 = checkout2.branch;\n return branch2;\n}, \"parseCheckout\");\nvar parseCherryPicking = /* @__PURE__ */ __name((cherryPicking) => {\n const cherryPickDB = {\n id: cherryPicking.id,\n targetId: \"\",\n tags: cherryPicking.tags?.length === 0 ? void 0 : cherryPicking.tags,\n parent: cherryPicking.parent\n };\n return cherryPickDB;\n}, \"parseCherryPicking\");\nvar parser = {\n parse: /* @__PURE__ */ __name(async (input) => {\n const ast = await parse(\"gitGraph\", input);\n log.debug(ast);\n populate(ast, db);\n }, \"parse\")\n};\nif (void 0) {\n const { it, expect, describe } = void 0;\n const mockDB = {\n commitType,\n setDirection: vi.fn(),\n commit: vi.fn(),\n branch: vi.fn(),\n merge: vi.fn(),\n cherryPick: vi.fn(),\n checkout: vi.fn()\n };\n describe(\"GitGraph Parser\", () => {\n it(\"should parse a commit statement\", () => {\n const commit2 = {\n $type: \"Commit\",\n id: \"1\",\n message: \"test\",\n tags: [\"tag1\", \"tag2\"],\n type: \"NORMAL\"\n };\n parseStatement(commit2, mockDB);\n expect(mockDB.commit).toHaveBeenCalledWith({\n id: \"1\",\n msg: \"test\",\n tags: [\"tag1\", \"tag2\"],\n type: 0\n });\n });\n it(\"should parse a branch statement\", () => {\n const branch2 = {\n $type: \"Branch\",\n name: \"newBranch\",\n order: 1\n };\n parseStatement(branch2, mockDB);\n expect(mockDB.branch).toHaveBeenCalledWith({ name: \"newBranch\", order: 1 });\n });\n it(\"should parse a checkout statement\", () => {\n const checkout2 = {\n $type: \"Checkout\",\n branch: \"newBranch\"\n };\n parseStatement(checkout2, mockDB);\n expect(mockDB.checkout).toHaveBeenCalledWith(\"newBranch\");\n });\n it(\"should parse a merge statement\", () => {\n const merge2 = {\n $type: \"Merge\",\n branch: \"newBranch\",\n id: \"1\",\n tags: [\"tag1\", \"tag2\"],\n type: \"NORMAL\"\n };\n parseStatement(merge2, mockDB);\n expect(mockDB.merge).toHaveBeenCalledWith({\n branch: \"newBranch\",\n id: \"1\",\n tags: [\"tag1\", \"tag2\"],\n type: 0\n });\n });\n it(\"should parse a cherry picking statement\", () => {\n const cherryPick2 = {\n $type: \"CherryPicking\",\n id: \"1\",\n tags: [\"tag1\", \"tag2\"],\n parent: \"2\"\n };\n parseStatement(cherryPick2, mockDB);\n expect(mockDB.cherryPick).toHaveBeenCalledWith({\n id: \"1\",\n targetId: \"\",\n parent: \"2\",\n tags: [\"tag1\", \"tag2\"]\n });\n });\n it(\"should parse a langium generated gitGraph ast\", () => {\n const dummy = {\n $type: \"GitGraph\",\n statements: []\n };\n const gitGraphAst = {\n $type: \"GitGraph\",\n statements: [\n {\n $container: dummy,\n $type: \"Commit\",\n id: \"1\",\n message: \"test\",\n tags: [\"tag1\", \"tag2\"],\n type: \"NORMAL\"\n },\n {\n $container: dummy,\n $type: \"Branch\",\n name: \"newBranch\",\n order: 1\n },\n {\n $container: dummy,\n $type: \"Merge\",\n branch: \"newBranch\",\n id: \"1\",\n tags: [\"tag1\", \"tag2\"],\n type: \"NORMAL\"\n },\n {\n $container: dummy,\n $type: \"Checkout\",\n branch: \"newBranch\"\n },\n {\n $container: dummy,\n $type: \"CherryPicking\",\n id: \"1\",\n tags: [\"tag1\", \"tag2\"],\n parent: \"2\"\n }\n ]\n };\n populate(gitGraphAst, mockDB);\n expect(mockDB.commit).toHaveBeenCalledWith({\n id: \"1\",\n msg: \"test\",\n tags: [\"tag1\", \"tag2\"],\n type: 0\n });\n expect(mockDB.branch).toHaveBeenCalledWith({ name: \"newBranch\", order: 1 });\n expect(mockDB.merge).toHaveBeenCalledWith({\n branch: \"newBranch\",\n id: \"1\",\n tags: [\"tag1\", \"tag2\"],\n type: 0\n });\n expect(mockDB.checkout).toHaveBeenCalledWith(\"newBranch\");\n });\n });\n}\n\n// src/diagrams/git/gitGraphRenderer.ts\nimport { select } from \"d3\";\nvar DEFAULT_CONFIG = getConfig2();\nvar DEFAULT_GITGRAPH_CONFIG2 = DEFAULT_CONFIG?.gitGraph;\nvar LAYOUT_OFFSET = 10;\nvar COMMIT_STEP = 40;\nvar PX = 4;\nvar PY = 2;\nvar THEME_COLOR_LIMIT = 8;\nvar branchPos = /* @__PURE__ */ new Map();\nvar commitPos = /* @__PURE__ */ new Map();\nvar defaultPos = 30;\nvar allCommitsDict = /* @__PURE__ */ new Map();\nvar lanes = [];\nvar maxPos = 0;\nvar dir = \"LR\";\nvar clear3 = /* @__PURE__ */ __name(() => {\n branchPos.clear();\n commitPos.clear();\n allCommitsDict.clear();\n maxPos = 0;\n lanes = [];\n dir = \"LR\";\n}, \"clear\");\nvar drawText = /* @__PURE__ */ __name((txt) => {\n const svgLabel = document.createElementNS(\"http://www.w3.org/2000/svg\", \"text\");\n const rows = typeof txt === \"string\" ? txt.split(/\\\\n|\\n|<br\\s*\\/?>/gi) : txt;\n rows.forEach((row) => {\n const tspan = document.createElementNS(\"http://www.w3.org/2000/svg\", \"tspan\");\n tspan.setAttributeNS(\"http://www.w3.org/XML/1998/namespace\", \"xml:space\", \"preserve\");\n tspan.setAttribute(\"dy\", \"1em\");\n tspan.setAttribute(\"x\", \"0\");\n tspan.setAttribute(\"class\", \"row\");\n tspan.textContent = row.trim();\n svgLabel.appendChild(tspan);\n });\n return svgLabel;\n}, \"drawText\");\nvar findClosestParent = /* @__PURE__ */ __name((parents) => {\n let closestParent;\n let comparisonFunc;\n let targetPosition;\n if (dir === \"BT\") {\n comparisonFunc = /* @__PURE__ */ __name((a, b) => a <= b, \"comparisonFunc\");\n targetPosition = Infinity;\n } else {\n comparisonFunc = /* @__PURE__ */ __name((a, b) => a >= b, \"comparisonFunc\");\n targetPosition = 0;\n }\n parents.forEach((parent) => {\n const parentPosition = dir === \"TB\" || dir == \"BT\" ? commitPos.get(parent)?.y : commitPos.get(parent)?.x;\n if (parentPosition !== void 0 && comparisonFunc(parentPosition, targetPosition)) {\n closestParent = parent;\n targetPosition = parentPosition;\n }\n });\n return closestParent;\n}, \"findClosestParent\");\nvar findClosestParentBT = /* @__PURE__ */ __name((parents) => {\n let closestParent = \"\";\n let maxPosition = Infinity;\n parents.forEach((parent) => {\n const parentPosition = commitPos.get(parent).y;\n if (parentPosition <= maxPosition) {\n closestParent = parent;\n maxPosition = parentPosition;\n }\n });\n return closestParent || void 0;\n}, \"findClosestParentBT\");\nvar setParallelBTPos = /* @__PURE__ */ __name((sortedKeys, commits, defaultPos2) => {\n let curPos = defaultPos2;\n let maxPosition = defaultPos2;\n const roots = [];\n sortedKeys.forEach((key) => {\n const commit2 = commits.get(key);\n if (!commit2) {\n throw new Error(`Commit not found for key ${key}`);\n }\n if (commit2.parents.length) {\n curPos = calculateCommitPosition(commit2);\n maxPosition = Math.max(curPos, maxPosition);\n } else {\n roots.push(commit2);\n }\n setCommitPosition(commit2, curPos);\n });\n curPos = maxPosition;\n roots.forEach((commit2) => {\n setRootPosition(commit2, curPos, defaultPos2);\n });\n sortedKeys.forEach((key) => {\n const commit2 = commits.get(key);\n if (commit2?.parents.length) {\n const closestParent = findClosestParentBT(commit2.parents);\n curPos = commitPos.get(closestParent).y - COMMIT_STEP;\n if (curPos <= maxPosition) {\n maxPosition = curPos;\n }\n const x = branchPos.get(commit2.branch).pos;\n const y = curPos - LAYOUT_OFFSET;\n commitPos.set(commit2.id, { x, y });\n }\n });\n}, \"setParallelBTPos\");\nvar findClosestParentPos = /* @__PURE__ */ __name((commit2) => {\n const closestParent = findClosestParent(commit2.parents.filter((p) => p !== null));\n if (!closestParent) {\n throw new Error(`Closest parent not found for commit ${commit2.id}`);\n }\n const closestParentPos = commitPos.get(closestParent)?.y;\n if (closestParentPos === void 0) {\n throw new Error(`Closest parent position not found for commit ${commit2.id}`);\n }\n return closestParentPos;\n}, \"findClosestParentPos\");\nvar calculateCommitPosition = /* @__PURE__ */ __name((commit2) => {\n const closestParentPos = findClosestParentPos(commit2);\n return closestParentPos + COMMIT_STEP;\n}, \"calculateCommitPosition\");\nvar setCommitPosition = /* @__PURE__ */ __name((commit2, curPos) => {\n const branch2 = branchPos.get(commit2.branch);\n if (!branch2) {\n throw new Error(`Branch not found for commit ${commit2.id}`);\n }\n const x = branch2.pos;\n const y = curPos + LAYOUT_OFFSET;\n commitPos.set(commit2.id, { x, y });\n return { x, y };\n}, \"setCommitPosition\");\nvar setRootPosition = /* @__PURE__ */ __name((commit2, curPos, defaultPos2) => {\n const branch2 = branchPos.get(commit2.branch);\n if (!branch2) {\n throw new Error(`Branch not found for commit ${commit2.id}`);\n }\n const y = curPos + defaultPos2;\n const x = branch2.pos;\n commitPos.set(commit2.id, { x, y });\n}, \"setRootPosition\");\nvar drawCommitBullet = /* @__PURE__ */ __name((gBullets, commit2, commitPosition, typeClass, branchIndex, commitSymbolType) => {\n if (commitSymbolType === commitType.HIGHLIGHT) {\n gBullets.append(\"rect\").attr(\"x\", commitPosition.x - 10).attr(\"y\", commitPosition.y - 10).attr(\"width\", 20).attr(\"height\", 20).attr(\n \"class\",\n `commit ${commit2.id} commit-highlight${branchIndex % THEME_COLOR_LIMIT} ${typeClass}-outer`\n );\n gBullets.append(\"rect\").attr(\"x\", commitPosition.x - 6).attr(\"y\", commitPosition.y - 6).attr(\"width\", 12).attr(\"height\", 12).attr(\n \"class\",\n `commit ${commit2.id} commit${branchIndex % THEME_COLOR_LIMIT} ${typeClass}-inner`\n );\n } else if (commitSymbolType === commitType.CHERRY_PICK) {\n gBullets.append(\"circle\").attr(\"cx\", commitPosition.x).attr(\"cy\", commitPosition.y).attr(\"r\", 10).attr(\"class\", `commit ${commit2.id} ${typeClass}`);\n gBullets.append(\"circle\").attr(\"cx\", commitPosition.x - 3).attr(\"cy\", commitPosition.y + 2).attr(\"r\", 2.75).attr(\"fill\", \"#fff\").attr(\"class\", `commit ${commit2.id} ${typeClass}`);\n gBullets.append(\"circle\").attr(\"cx\", commitPosition.x + 3).attr(\"cy\", commitPosition.y + 2).attr(\"r\", 2.75).attr(\"fill\", \"#fff\").attr(\"class\", `commit ${commit2.id} ${typeClass}`);\n gBullets.append(\"line\").attr(\"x1\", commitPosition.x + 3).attr(\"y1\", commitPosition.y + 1).attr(\"x2\", commitPosition.x).attr(\"y2\", commitPosition.y - 5).attr(\"stroke\", \"#fff\").attr(\"class\", `commit ${commit2.id} ${typeClass}`);\n gBullets.append(\"line\").attr(\"x1\", commitPosition.x - 3).attr(\"y1\", commitPosition.y + 1).attr(\"x2\", commitPosition.x).attr(\"y2\", commitPosition.y - 5).attr(\"stroke\", \"#fff\").attr(\"class\", `commit ${commit2.id} ${typeClass}`);\n } else {\n const circle = gBullets.append(\"circle\");\n circle.attr(\"cx\", commitPosition.x);\n circle.attr(\"cy\", commitPosition.y);\n circle.attr(\"r\", commit2.type === commitType.MERGE ? 9 : 10);\n circle.attr(\"class\", `commit ${commit2.id} commit${branchIndex % THEME_COLOR_LIMIT}`);\n if (commitSymbolType === commitType.MERGE) {\n const circle2 = gBullets.append(\"circle\");\n circle2.attr(\"cx\", commitPosition.x);\n circle2.attr(\"cy\", commitPosition.y);\n circle2.attr(\"r\", 6);\n circle2.attr(\n \"class\",\n `commit ${typeClass} ${commit2.id} commit${branchIndex % THEME_COLOR_LIMIT}`\n );\n }\n if (commitSymbolType === commitType.REVERSE) {\n const cross = gBullets.append(\"path\");\n cross.attr(\n \"d\",\n `M ${commitPosition.x - 5},${commitPosition.y - 5}L${commitPosition.x + 5},${commitPosition.y + 5}M${commitPosition.x - 5},${commitPosition.y + 5}L${commitPosition.x + 5},${commitPosition.y - 5}`\n ).attr(\"class\", `commit ${typeClass} ${commit2.id} commit${branchIndex % THEME_COLOR_LIMIT}`);\n }\n }\n}, \"drawCommitBullet\");\nvar drawCommitLabel = /* @__PURE__ */ __name((gLabels, commit2, commitPosition, pos) => {\n if (commit2.type !== commitType.CHERRY_PICK && (commit2.customId && commit2.type === commitType.MERGE || commit2.type !== commitType.MERGE) && DEFAULT_GITGRAPH_CONFIG2?.showCommitLabel) {\n const wrapper = gLabels.append(\"g\");\n const labelBkg = wrapper.insert(\"rect\").attr(\"class\", \"commit-label-bkg\");\n const text = wrapper.append(\"text\").attr(\"x\", pos).attr(\"y\", commitPosition.y + 25).attr(\"class\", \"commit-label\").text(commit2.id);\n const bbox = text.node()?.getBBox();\n if (bbox) {\n labelBkg.attr(\"x\", commitPosition.posWithOffset - bbox.width / 2 - PY).attr(\"y\", commitPosition.y + 13.5).attr(\"width\", bbox.width + 2 * PY).attr(\"height\", bbox.height + 2 * PY);\n if (dir === \"TB\" || dir === \"BT\") {\n labelBkg.attr(\"x\", commitPosition.x - (bbox.width + 4 * PX + 5)).attr(\"y\", commitPosition.y - 12);\n text.attr(\"x\", commitPosition.x - (bbox.width + 4 * PX)).attr(\"y\", commitPosition.y + bbox.height - 12);\n } else {\n text.attr(\"x\", commitPosition.posWithOffset - bbox.width / 2);\n }\n if (DEFAULT_GITGRAPH_CONFIG2.rotateCommitLabel) {\n if (dir === \"TB\" || dir === \"BT\") {\n text.attr(\n \"transform\",\n \"rotate(-45, \" + commitPosition.x + \", \" + commitPosition.y + \")\"\n );\n labelBkg.attr(\n \"transform\",\n \"rotate(-45, \" + commitPosition.x + \", \" + commitPosition.y + \")\"\n );\n } else {\n const r_x = -7.5 - (bbox.width + 10) / 25 * 9.5;\n const r_y = 10 + bbox.width / 25 * 8.5;\n wrapper.attr(\n \"transform\",\n \"translate(\" + r_x + \", \" + r_y + \") rotate(-45, \" + pos + \", \" + commitPosition.y + \")\"\n );\n }\n }\n }\n }\n}, \"drawCommitLabel\");\nvar drawCommitTags = /* @__PURE__ */ __name((gLabels, commit2, commitPosition, pos) => {\n if (commit2.tags.length > 0) {\n let yOffset = 0;\n let maxTagBboxWidth = 0;\n let maxTagBboxHeight = 0;\n const tagElements = [];\n for (const tagValue of commit2.tags.reverse()) {\n const rect = gLabels.insert(\"polygon\");\n const hole = gLabels.append(\"circle\");\n const tag = gLabels.append(\"text\").attr(\"y\", commitPosition.y - 16 - yOffset).attr(\"class\", \"tag-label\").text(tagValue);\n const tagBbox = tag.node()?.getBBox();\n if (!tagBbox) {\n throw new Error(\"Tag bbox not found\");\n }\n maxTagBboxWidth = Math.max(maxTagBboxWidth, tagBbox.width);\n maxTagBboxHeight = Math.max(maxTagBboxHeight, tagBbox.height);\n tag.attr(\"x\", commitPosition.posWithOffset - tagBbox.width / 2);\n tagElements.push({\n tag,\n hole,\n rect,\n yOffset\n });\n yOffset += 20;\n }\n for (const { tag, hole, rect, yOffset: yOffset2 } of tagElements) {\n const h2 = maxTagBboxHeight / 2;\n const ly = commitPosition.y - 19.2 - yOffset2;\n rect.attr(\"class\", \"tag-label-bkg\").attr(\n \"points\",\n `\n ${pos - maxTagBboxWidth / 2 - PX / 2},${ly + PY} \n ${pos - maxTagBboxWidth / 2 - PX / 2},${ly - PY}\n ${commitPosition.posWithOffset - maxTagBboxWidth / 2 - PX},${ly - h2 - PY}\n ${commitPosition.posWithOffset + maxTagBboxWidth / 2 + PX},${ly - h2 - PY}\n ${commitPosition.posWithOffset + maxTagBboxWidth / 2 + PX},${ly + h2 + PY}\n ${commitPosition.posWithOffset - maxTagBboxWidth / 2 - PX},${ly + h2 + PY}`\n );\n hole.attr(\"cy\", ly).attr(\"cx\", pos - maxTagBboxWidth / 2 + PX / 2).attr(\"r\", 1.5).attr(\"class\", \"tag-hole\");\n if (dir === \"TB\" || dir === \"BT\") {\n const yOrigin = pos + yOffset2;\n rect.attr(\"class\", \"tag-label-bkg\").attr(\n \"points\",\n `\n ${commitPosition.x},${yOrigin + 2}\n ${commitPosition.x},${yOrigin - 2}\n ${commitPosition.x + LAYOUT_OFFSET},${yOrigin - h2 - 2}\n ${commitPosition.x + LAYOUT_OFFSET + maxTagBboxWidth + 4},${yOrigin - h2 - 2}\n ${commitPosition.x + LAYOUT_OFFSET + maxTagBboxWidth + 4},${yOrigin + h2 + 2}\n ${commitPosition.x + LAYOUT_OFFSET},${yOrigin + h2 + 2}`\n ).attr(\"transform\", \"translate(12,12) rotate(45, \" + commitPosition.x + \",\" + pos + \")\");\n hole.attr(\"cx\", commitPosition.x + PX / 2).attr(\"cy\", yOrigin).attr(\"transform\", \"translate(12,12) rotate(45, \" + commitPosition.x + \",\" + pos + \")\");\n tag.attr(\"x\", commitPosition.x + 5).attr(\"y\", yOrigin + 3).attr(\"transform\", \"translate(14,14) rotate(45, \" + commitPosition.x + \",\" + pos + \")\");\n }\n }\n }\n}, \"drawCommitTags\");\nvar getCommitClassType = /* @__PURE__ */ __name((commit2) => {\n const commitSymbolType = commit2.customType ?? commit2.type;\n switch (commitSymbolType) {\n case commitType.NORMAL:\n return \"commit-normal\";\n case commitType.REVERSE:\n return \"commit-reverse\";\n case commitType.HIGHLIGHT:\n return \"commit-highlight\";\n case commitType.MERGE:\n return \"commit-merge\";\n case commitType.CHERRY_PICK:\n return \"commit-cherry-pick\";\n default:\n return \"commit-normal\";\n }\n}, \"getCommitClassType\");\nvar calculatePosition = /* @__PURE__ */ __name((commit2, dir2, pos, commitPos2) => {\n const defaultCommitPosition = { x: 0, y: 0 };\n if (commit2.parents.length > 0) {\n const closestParent = findClosestParent(commit2.parents);\n if (closestParent) {\n const parentPosition = commitPos2.get(closestParent) ?? defaultCommitPosition;\n if (dir2 === \"TB\") {\n return parentPosition.y + COMMIT_STEP;\n } else if (dir2 === \"BT\") {\n const currentPosition = commitPos2.get(commit2.id) ?? defaultCommitPosition;\n return currentPosition.y - COMMIT_STEP;\n } else {\n return parentPosition.x + COMMIT_STEP;\n }\n }\n } else {\n if (dir2 === \"TB\") {\n return defaultPos;\n } else if (dir2 === \"BT\") {\n const currentPosition = commitPos2.get(commit2.id) ?? defaultCommitPosition;\n return currentPosition.y - COMMIT_STEP;\n } else {\n return 0;\n }\n }\n return 0;\n}, \"calculatePosition\");\nvar getCommitPosition = /* @__PURE__ */ __name((commit2, pos, isParallelCommits) => {\n const posWithOffset = dir === \"BT\" && isParallelCommits ? pos : pos + LAYOUT_OFFSET;\n const y = dir === \"TB\" || dir === \"BT\" ? posWithOffset : branchPos.get(commit2.branch)?.pos;\n const x = dir === \"TB\" || dir === \"BT\" ? branchPos.get(commit2.branch)?.pos : posWithOffset;\n if (x === void 0 || y === void 0) {\n throw new Error(`Position were undefined for commit ${commit2.id}`);\n }\n return { x, y, posWithOffset };\n}, \"getCommitPosition\");\nvar drawCommits = /* @__PURE__ */ __name((svg, commits, modifyGraph) => {\n if (!DEFAULT_GITGRAPH_CONFIG2) {\n throw new Error(\"GitGraph config not found\");\n }\n const gBullets = svg.append(\"g\").attr(\"class\", \"commit-bullets\");\n const gLabels = svg.append(\"g\").attr(\"class\", \"commit-labels\");\n let pos = dir === \"TB\" || dir === \"BT\" ? defaultPos : 0;\n const keys = [...commits.keys()];\n const isParallelCommits = DEFAULT_GITGRAPH_CONFIG2?.parallelCommits ?? false;\n const sortKeys = /* @__PURE__ */ __name((a, b) => {\n const seqA = commits.get(a)?.seq;\n const seqB = commits.get(b)?.seq;\n return seqA !== void 0 && seqB !== void 0 ? seqA - seqB : 0;\n }, \"sortKeys\");\n let sortedKeys = keys.sort(sortKeys);\n if (dir === \"BT\") {\n if (isParallelCommits) {\n setParallelBTPos(sortedKeys, commits, pos);\n }\n sortedKeys = sortedKeys.reverse();\n }\n sortedKeys.forEach((key) => {\n const commit2 = commits.get(key);\n if (!commit2) {\n throw new Error(`Commit not found for key ${key}`);\n }\n if (isParallelCommits) {\n pos = calculatePosition(commit2, dir, pos, commitPos);\n }\n const commitPosition = getCommitPosition(commit2, pos, isParallelCommits);\n if (modifyGraph) {\n const typeClass = getCommitClassType(commit2);\n const commitSymbolType = commit2.customType ?? commit2.type;\n const branchIndex = branchPos.get(commit2.branch)?.index ?? 0;\n drawCommitBullet(gBullets, commit2, commitPosition, typeClass, branchIndex, commitSymbolType);\n drawCommitLabel(gLabels, commit2, commitPosition, pos);\n drawCommitTags(gLabels, commit2, commitPosition, pos);\n }\n if (dir === \"TB\" || dir === \"BT\") {\n commitPos.set(commit2.id, { x: commitPosition.x, y: commitPosition.posWithOffset });\n } else {\n commitPos.set(commit2.id, { x: commitPosition.posWithOffset, y: commitPosition.y });\n }\n pos = dir === \"BT\" && isParallelCommits ? pos + COMMIT_STEP : pos + COMMIT_STEP + LAYOUT_OFFSET;\n if (pos > maxPos) {\n maxPos = pos;\n }\n });\n}, \"drawCommits\");\nvar shouldRerouteArrow = /* @__PURE__ */ __name((commitA, commitB, p1, p2, allCommits) => {\n const commitBIsFurthest = dir === \"TB\" || dir === \"BT\" ? p1.x < p2.x : p1.y < p2.y;\n const branchToGetCurve = commitBIsFurthest ? commitB.branch : commitA.branch;\n const isOnBranchToGetCurve = /* @__PURE__ */ __name((x) => x.branch === branchToGetCurve, \"isOnBranchToGetCurve\");\n const isBetweenCommits = /* @__PURE__ */ __name((x) => x.seq > commitA.seq && x.seq < commitB.seq, \"isBetweenCommits\");\n return [...allCommits.values()].some((commitX) => {\n return isBetweenCommits(commitX) && isOnBranchToGetCurve(commitX);\n });\n}, \"shouldRerouteArrow\");\nvar findLane = /* @__PURE__ */ __name((y1, y2, depth = 0) => {\n const candidate = y1 + Math.abs(y1 - y2) / 2;\n if (depth > 5) {\n return candidate;\n }\n const ok = lanes.every((lane) => Math.abs(lane - candidate) >= 10);\n if (ok) {\n lanes.push(candidate);\n return candidate;\n }\n const diff = Math.abs(y1 - y2);\n return findLane(y1, y2 - diff / 5, depth + 1);\n}, \"findLane\");\nvar drawArrow = /* @__PURE__ */ __name((svg, commitA, commitB, allCommits) => {\n const p1 = commitPos.get(commitA.id);\n const p2 = commitPos.get(commitB.id);\n if (p1 === void 0 || p2 === void 0) {\n throw new Error(`Commit positions not found for commits ${commitA.id} and ${commitB.id}`);\n }\n const arrowNeedsRerouting = shouldRerouteArrow(commitA, commitB, p1, p2, allCommits);\n let arc = \"\";\n let arc2 = \"\";\n let radius = 0;\n let offset = 0;\n let colorClassNum = branchPos.get(commitB.branch)?.index;\n if (commitB.type === commitType.MERGE && commitA.id !== commitB.parents[0]) {\n colorClassNum = branchPos.get(commitA.branch)?.index;\n }\n let lineDef;\n if (arrowNeedsRerouting) {\n arc = \"A 10 10, 0, 0, 0,\";\n arc2 = \"A 10 10, 0, 0, 1,\";\n radius = 10;\n offset = 10;\n const lineY = p1.y < p2.y ? findLane(p1.y, p2.y) : findLane(p2.y, p1.y);\n const lineX = p1.x < p2.x ? findLane(p1.x, p2.x) : findLane(p2.x, p1.x);\n if (dir === \"TB\") {\n if (p1.x < p2.x) {\n lineDef = `M ${p1.x} ${p1.y} L ${lineX - radius} ${p1.y} ${arc2} ${lineX} ${p1.y + offset} L ${lineX} ${p2.y - radius} ${arc} ${lineX + offset} ${p2.y} L ${p2.x} ${p2.y}`;\n } else {\n colorClassNum = branchPos.get(commitA.branch)?.index;\n lineDef = `M ${p1.x} ${p1.y} L ${lineX + radius} ${p1.y} ${arc} ${lineX} ${p1.y + offset} L ${lineX} ${p2.y - radius} ${arc2} ${lineX - offset} ${p2.y} L ${p2.x} ${p2.y}`;\n }\n } else if (dir === \"BT\") {\n if (p1.x < p2.x) {\n lineDef = `M ${p1.x} ${p1.y} L ${lineX - radius} ${p1.y} ${arc} ${lineX} ${p1.y - offset} L ${lineX} ${p2.y + radius} ${arc2} ${lineX + offset} ${p2.y} L ${p2.x} ${p2.y}`;\n } else {\n colorClassNum = branchPos.get(commitA.branch)?.index;\n lineDef = `M ${p1.x} ${p1.y} L ${lineX + radius} ${p1.y} ${arc2} ${lineX} ${p1.y - offset} L ${lineX} ${p2.y + radius} ${arc} ${lineX - offset} ${p2.y} L ${p2.x} ${p2.y}`;\n }\n } else {\n if (p1.y < p2.y) {\n lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${lineY - radius} ${arc} ${p1.x + offset} ${lineY} L ${p2.x - radius} ${lineY} ${arc2} ${p2.x} ${lineY + offset} L ${p2.x} ${p2.y}`;\n } else {\n colorClassNum = branchPos.get(commitA.branch)?.index;\n lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${lineY + radius} ${arc2} ${p1.x + offset} ${lineY} L ${p2.x - radius} ${lineY} ${arc} ${p2.x} ${lineY - offset} L ${p2.x} ${p2.y}`;\n }\n }\n } else {\n arc = \"A 20 20, 0, 0, 0,\";\n arc2 = \"A 20 20, 0, 0, 1,\";\n radius = 20;\n offset = 20;\n if (dir === \"TB\") {\n if (p1.x < p2.x) {\n if (commitB.type === commitType.MERGE && commitA.id !== commitB.parents[0]) {\n lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y - radius} ${arc} ${p1.x + offset} ${p2.y} L ${p2.x} ${p2.y}`;\n } else {\n lineDef = `M ${p1.x} ${p1.y} L ${p2.x - radius} ${p1.y} ${arc2} ${p2.x} ${p1.y + offset} L ${p2.x} ${p2.y}`;\n }\n }\n if (p1.x > p2.x) {\n arc = \"A 20 20, 0, 0, 0,\";\n arc2 = \"A 20 20, 0, 0, 1,\";\n radius = 20;\n offset = 20;\n if (commitB.type === commitType.MERGE && commitA.id !== commitB.parents[0]) {\n lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y - radius} ${arc2} ${p1.x - offset} ${p2.y} L ${p2.x} ${p2.y}`;\n } else {\n lineDef = `M ${p1.x} ${p1.y} L ${p2.x + radius} ${p1.y} ${arc} ${p2.x} ${p1.y + offset} L ${p2.x} ${p2.y}`;\n }\n }\n if (p1.x === p2.x) {\n lineDef = `M ${p1.x} ${p1.y} L ${p2.x} ${p2.y}`;\n }\n } else if (dir === \"BT\") {\n if (p1.x < p2.x) {\n if (commitB.type === commitType.MERGE && commitA.id !== commitB.parents[0]) {\n lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y + radius} ${arc2} ${p1.x + offset} ${p2.y} L ${p2.x} ${p2.y}`;\n } else {\n lineDef = `M ${p1.x} ${p1.y} L ${p2.x - radius} ${p1.y} ${arc} ${p2.x} ${p1.y - offset} L ${p2.x} ${p2.y}`;\n }\n }\n if (p1.x > p2.x) {\n arc = \"A 20 20, 0, 0, 0,\";\n arc2 = \"A 20 20, 0, 0, 1,\";\n radius = 20;\n offset = 20;\n if (commitB.type === commitType.MERGE && commitA.id !== commitB.parents[0]) {\n lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y + radius} ${arc} ${p1.x - offset} ${p2.y} L ${p2.x} ${p2.y}`;\n } else {\n lineDef = `M ${p1.x} ${p1.y} L ${p2.x - radius} ${p1.y} ${arc} ${p2.x} ${p1.y - offset} L ${p2.x} ${p2.y}`;\n }\n }\n if (p1.x === p2.x) {\n lineDef = `M ${p1.x} ${p1.y} L ${p2.x} ${p2.y}`;\n }\n } else {\n if (p1.y < p2.y) {\n if (commitB.type === commitType.MERGE && commitA.id !== commitB.parents[0]) {\n lineDef = `M ${p1.x} ${p1.y} L ${p2.x - radius} ${p1.y} ${arc2} ${p2.x} ${p1.y + offset} L ${p2.x} ${p2.y}`;\n } else {\n lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y - radius} ${arc} ${p1.x + offset} ${p2.y} L ${p2.x} ${p2.y}`;\n }\n }\n if (p1.y > p2.y) {\n if (commitB.type === commitType.MERGE && commitA.id !== commitB.parents[0]) {\n lineDef = `M ${p1.x} ${p1.y} L ${p2.x - radius} ${p1.y} ${arc} ${p2.x} ${p1.y - offset} L ${p2.x} ${p2.y}`;\n } else {\n lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y + radius} ${arc2} ${p1.x + offset} ${p2.y} L ${p2.x} ${p2.y}`;\n }\n }\n if (p1.y === p2.y) {\n lineDef = `M ${p1.x} ${p1.y} L ${p2.x} ${p2.y}`;\n }\n }\n }\n if (lineDef === void 0) {\n throw new Error(\"Line definition not found\");\n }\n svg.append(\"path\").attr(\"d\", lineDef).attr(\"class\", \"arrow arrow\" + colorClassNum % THEME_COLOR_LIMIT);\n}, \"drawArrow\");\nvar drawArrows = /* @__PURE__ */ __name((svg, commits) => {\n const gArrows = svg.append(\"g\").attr(\"class\", \"commit-arrows\");\n [...commits.keys()].forEach((key) => {\n const commit2 = commits.get(key);\n if (commit2.parents && commit2.parents.length > 0) {\n commit2.parents.forEach((parent) => {\n drawArrow(gArrows, commits.get(parent), commit2, commits);\n });\n }\n });\n}, \"drawArrows\");\nvar drawBranches = /* @__PURE__ */ __name((svg, branches) => {\n const g = svg.append(\"g\");\n branches.forEach((branch2, index) => {\n const adjustIndexForTheme = index % THEME_COLOR_LIMIT;\n const pos = branchPos.get(branch2.name)?.pos;\n if (pos === void 0) {\n throw new Error(`Position not found for branch ${branch2.name}`);\n }\n const line = g.append(\"line\");\n line.attr(\"x1\", 0);\n line.attr(\"y1\", pos);\n line.attr(\"x2\", maxPos);\n line.attr(\"y2\", pos);\n line.attr(\"class\", \"branch branch\" + adjustIndexForTheme);\n if (dir === \"TB\") {\n line.attr(\"y1\", defaultPos);\n line.attr(\"x1\", pos);\n line.attr(\"y2\", maxPos);\n line.attr(\"x2\", pos);\n } else if (dir === \"BT\") {\n line.attr(\"y1\", maxPos);\n line.attr(\"x1\", pos);\n line.attr(\"y2\", defaultPos);\n line.attr(\"x2\", pos);\n }\n lanes.push(pos);\n const name = branch2.name;\n const labelElement = drawText(name);\n const bkg = g.insert(\"rect\");\n const branchLabel = g.insert(\"g\").attr(\"class\", \"branchLabel\");\n const label = branchLabel.insert(\"g\").attr(\"class\", \"label branch-label\" + adjustIndexForTheme);\n label.node().appendChild(labelElement);\n const bbox = labelElement.getBBox();\n bkg.attr(\"class\", \"branchLabelBkg label\" + adjustIndexForTheme).attr(\"rx\", 4).attr(\"ry\", 4).attr(\"x\", -bbox.width - 4 - (DEFAULT_GITGRAPH_CONFIG2?.rotateCommitLabel === true ? 30 : 0)).attr(\"y\", -bbox.height / 2 + 8).attr(\"width\", bbox.width + 18).attr(\"height\", bbox.height + 4);\n label.attr(\n \"transform\",\n \"translate(\" + (-bbox.width - 14 - (DEFAULT_GITGRAPH_CONFIG2?.rotateCommitLabel === true ? 30 : 0)) + \", \" + (pos - bbox.height / 2 - 1) + \")\"\n );\n if (dir === \"TB\") {\n bkg.attr(\"x\", pos - bbox.width / 2 - 10).attr(\"y\", 0);\n label.attr(\"transform\", \"translate(\" + (pos - bbox.width / 2 - 5) + \", 0)\");\n } else if (dir === \"BT\") {\n bkg.attr(\"x\", pos - bbox.width / 2 - 10).attr(\"y\", maxPos);\n label.attr(\"transform\", \"translate(\" + (pos - bbox.width / 2 - 5) + \", \" + maxPos + \")\");\n } else {\n bkg.attr(\"transform\", \"translate(-19, \" + (pos - bbox.height / 2) + \")\");\n }\n });\n}, \"drawBranches\");\nvar setBranchPosition = /* @__PURE__ */ __na