@zettelgeist/cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +64 -0
  3. package/dist/bin.js +2211 -0
  4. package/dist/bin.js.map +7 -0
  5. package/dist/templates/export.html +27 -0
  6. package/dist/templates/skill/SKILL.md +220 -0
  7. package/dist/viewer-bundle/architecture-YZFGNWBL-W2K3EQOM.js +14 -0
  8. package/dist/viewer-bundle/architecture-YZFGNWBL-W2K3EQOM.js.map +7 -0
  9. package/dist/viewer-bundle/architectureDiagram-Q4EWVU46-LCGRUEWT.js +8884 -0
  10. package/dist/viewer-bundle/architectureDiagram-Q4EWVU46-LCGRUEWT.js.map +7 -0
  11. package/dist/viewer-bundle/base.css +248 -0
  12. package/dist/viewer-bundle/blockDiagram-DXYQGD6D-KAM7BOAP.js +3777 -0
  13. package/dist/viewer-bundle/blockDiagram-DXYQGD6D-KAM7BOAP.js.map +7 -0
  14. package/dist/viewer-bundle/board.css +370 -0
  15. package/dist/viewer-bundle/c4Diagram-AHTNJAMY-C3FIQYXA.js +2596 -0
  16. package/dist/viewer-bundle/c4Diagram-AHTNJAMY-C3FIQYXA.js.map +7 -0
  17. package/dist/viewer-bundle/chunk-2QXGXAO5.js +68 -0
  18. package/dist/viewer-bundle/chunk-2QXGXAO5.js.map +7 -0
  19. package/dist/viewer-bundle/chunk-5PZT7VUU.js +67 -0
  20. package/dist/viewer-bundle/chunk-5PZT7VUU.js.map +7 -0
  21. package/dist/viewer-bundle/chunk-5YJCJF2C.js +112 -0
  22. package/dist/viewer-bundle/chunk-5YJCJF2C.js.map +7 -0
  23. package/dist/viewer-bundle/chunk-6LYV7PBV.js +1011 -0
  24. package/dist/viewer-bundle/chunk-6LYV7PBV.js.map +7 -0
  25. package/dist/viewer-bundle/chunk-6VW7D5WX.js +48 -0
  26. package/dist/viewer-bundle/chunk-6VW7D5WX.js.map +7 -0
  27. package/dist/viewer-bundle/chunk-76C5OSD4.js +2048 -0
  28. package/dist/viewer-bundle/chunk-76C5OSD4.js.map +7 -0
  29. package/dist/viewer-bundle/chunk-7NZMPQDX.js +6957 -0
  30. package/dist/viewer-bundle/chunk-7NZMPQDX.js.map +7 -0
  31. package/dist/viewer-bundle/chunk-A634GTZN.js +122 -0
  32. package/dist/viewer-bundle/chunk-A634GTZN.js.map +7 -0
  33. package/dist/viewer-bundle/chunk-AJQJUKMU.js +133 -0
  34. package/dist/viewer-bundle/chunk-AJQJUKMU.js.map +7 -0
  35. package/dist/viewer-bundle/chunk-BM2KPNFW.js +5556 -0
  36. package/dist/viewer-bundle/chunk-BM2KPNFW.js.map +7 -0
  37. package/dist/viewer-bundle/chunk-CIDUOCCG.js +25 -0
  38. package/dist/viewer-bundle/chunk-CIDUOCCG.js.map +7 -0
  39. package/dist/viewer-bundle/chunk-CZHJHAOR.js +6397 -0
  40. package/dist/viewer-bundle/chunk-CZHJHAOR.js.map +7 -0
  41. package/dist/viewer-bundle/chunk-D5RLIWY4.js +125 -0
  42. package/dist/viewer-bundle/chunk-D5RLIWY4.js.map +7 -0
  43. package/dist/viewer-bundle/chunk-DI52DQAC.js +44 -0
  44. package/dist/viewer-bundle/chunk-DI52DQAC.js.map +7 -0
  45. package/dist/viewer-bundle/chunk-EXJQLTIV.js +51 -0
  46. package/dist/viewer-bundle/chunk-EXJQLTIV.js.map +7 -0
  47. package/dist/viewer-bundle/chunk-G3PPZWPW.js +96 -0
  48. package/dist/viewer-bundle/chunk-G3PPZWPW.js.map +7 -0
  49. package/dist/viewer-bundle/chunk-GTW4IDD4.js +30297 -0
  50. package/dist/viewer-bundle/chunk-GTW4IDD4.js.map +7 -0
  51. package/dist/viewer-bundle/chunk-GVE7OA3Z.js +59 -0
  52. package/dist/viewer-bundle/chunk-GVE7OA3Z.js.map +7 -0
  53. package/dist/viewer-bundle/chunk-JBUVKVPY.js +2042 -0
  54. package/dist/viewer-bundle/chunk-JBUVKVPY.js.map +7 -0
  55. package/dist/viewer-bundle/chunk-JQLVOAQB.js +20 -0
  56. package/dist/viewer-bundle/chunk-JQLVOAQB.js.map +7 -0
  57. package/dist/viewer-bundle/chunk-LQMQSYLO.js +101 -0
  58. package/dist/viewer-bundle/chunk-LQMQSYLO.js.map +7 -0
  59. package/dist/viewer-bundle/chunk-MBFAQ3IK.js +34 -0
  60. package/dist/viewer-bundle/chunk-MBFAQ3IK.js.map +7 -0
  61. package/dist/viewer-bundle/chunk-N7G7IIKG.js +25 -0
  62. package/dist/viewer-bundle/chunk-N7G7IIKG.js.map +7 -0
  63. package/dist/viewer-bundle/chunk-NW4YG3NS.js +171 -0
  64. package/dist/viewer-bundle/chunk-NW4YG3NS.js.map +7 -0
  65. package/dist/viewer-bundle/chunk-ODEP5TKB.js +61 -0
  66. package/dist/viewer-bundle/chunk-ODEP5TKB.js.map +7 -0
  67. package/dist/viewer-bundle/chunk-OGKINV23.js +1050 -0
  68. package/dist/viewer-bundle/chunk-OGKINV23.js.map +7 -0
  69. package/dist/viewer-bundle/chunk-OGMSNDVH.js +1994 -0
  70. package/dist/viewer-bundle/chunk-OGMSNDVH.js.map +7 -0
  71. package/dist/viewer-bundle/chunk-QJVSDNAW.js +25 -0
  72. package/dist/viewer-bundle/chunk-QJVSDNAW.js.map +7 -0
  73. package/dist/viewer-bundle/chunk-RBTT26R4.js +2721 -0
  74. package/dist/viewer-bundle/chunk-RBTT26R4.js.map +7 -0
  75. package/dist/viewer-bundle/chunk-RQIPIIE2.js +48 -0
  76. package/dist/viewer-bundle/chunk-RQIPIIE2.js.map +7 -0
  77. package/dist/viewer-bundle/chunk-SRTYTXTX.js +22 -0
  78. package/dist/viewer-bundle/chunk-SRTYTXTX.js.map +7 -0
  79. package/dist/viewer-bundle/chunk-TRL7YIZG.js +1663 -0
  80. package/dist/viewer-bundle/chunk-TRL7YIZG.js.map +7 -0
  81. package/dist/viewer-bundle/chunk-U5T7X4BV.js +172 -0
  82. package/dist/viewer-bundle/chunk-U5T7X4BV.js.map +7 -0
  83. package/dist/viewer-bundle/chunk-UCAW6C6C.js +48 -0
  84. package/dist/viewer-bundle/chunk-UCAW6C6C.js.map +7 -0
  85. package/dist/viewer-bundle/chunk-UEAG4BJQ.js +93 -0
  86. package/dist/viewer-bundle/chunk-UEAG4BJQ.js.map +7 -0
  87. package/dist/viewer-bundle/chunk-UVRE3R6A.js +1039 -0
  88. package/dist/viewer-bundle/chunk-UVRE3R6A.js.map +7 -0
  89. package/dist/viewer-bundle/chunk-VODO7SV4.js +25029 -0
  90. package/dist/viewer-bundle/chunk-VODO7SV4.js.map +7 -0
  91. package/dist/viewer-bundle/chunk-YEU62MVS.js +682 -0
  92. package/dist/viewer-bundle/chunk-YEU62MVS.js.map +7 -0
  93. package/dist/viewer-bundle/chunk-YFQT7PPW.js +987 -0
  94. package/dist/viewer-bundle/chunk-YFQT7PPW.js.map +7 -0
  95. package/dist/viewer-bundle/chunk-Z4G7FG27.js +48 -0
  96. package/dist/viewer-bundle/chunk-Z4G7FG27.js.map +7 -0
  97. package/dist/viewer-bundle/chunk-ZW4Y7DIF.js +2044 -0
  98. package/dist/viewer-bundle/chunk-ZW4Y7DIF.js.map +7 -0
  99. package/dist/viewer-bundle/classDiagram-6PBFFD2Q-7VKYXLUX.js +46 -0
  100. package/dist/viewer-bundle/classDiagram-6PBFFD2Q-7VKYXLUX.js.map +7 -0
  101. package/dist/viewer-bundle/classDiagram-v2-HSJHXN6E-ACCNN7EN.js +46 -0
  102. package/dist/viewer-bundle/classDiagram-v2-HSJHXN6E-ACCNN7EN.js.map +7 -0
  103. package/dist/viewer-bundle/cose-bilkent-S5V4N54A-MUJHAA34.js +5009 -0
  104. package/dist/viewer-bundle/cose-bilkent-S5V4N54A-MUJHAA34.js.map +7 -0
  105. package/dist/viewer-bundle/dagre-KV5264BT-YC5VV3WF.js +739 -0
  106. package/dist/viewer-bundle/dagre-KV5264BT-YC5VV3WF.js.map +7 -0
  107. package/dist/viewer-bundle/dark.css +13 -0
  108. package/dist/viewer-bundle/detail.css +539 -0
  109. package/dist/viewer-bundle/diagram-5BDNPKRD-RXFPVFYK.js +214 -0
  110. package/dist/viewer-bundle/diagram-5BDNPKRD-RXFPVFYK.js.map +7 -0
  111. package/dist/viewer-bundle/diagram-G4DWMVQ6-KN7CBNBQ.js +578 -0
  112. package/dist/viewer-bundle/diagram-G4DWMVQ6-KN7CBNBQ.js.map +7 -0
  113. package/dist/viewer-bundle/diagram-MMDJMWI5-ZN6TQ7ZC.js +345 -0
  114. package/dist/viewer-bundle/diagram-MMDJMWI5-ZN6TQ7ZC.js.map +7 -0
  115. package/dist/viewer-bundle/diagram-TYMM5635-MMTUJ4KA.js +255 -0
  116. package/dist/viewer-bundle/diagram-TYMM5635-MMTUJ4KA.js.map +7 -0
  117. package/dist/viewer-bundle/docs.css +88 -0
  118. package/dist/viewer-bundle/edit-modal-BEGC2AO6.js +176 -0
  119. package/dist/viewer-bundle/edit-modal-BEGC2AO6.js.map +7 -0
  120. package/dist/viewer-bundle/erDiagram-SMLLAGMA-TBHMLD2E.js +1349 -0
  121. package/dist/viewer-bundle/erDiagram-SMLLAGMA-TBHMLD2E.js.map +7 -0
  122. package/dist/viewer-bundle/flowDiagram-DWJPFMVM-BZHLK6QB.js +2501 -0
  123. package/dist/viewer-bundle/flowDiagram-DWJPFMVM-BZHLK6QB.js.map +7 -0
  124. package/dist/viewer-bundle/ganttDiagram-T4ZO3ILL-YBARPTQR.js +2654 -0
  125. package/dist/viewer-bundle/ganttDiagram-T4ZO3ILL-YBARPTQR.js.map +7 -0
  126. package/dist/viewer-bundle/gitGraph-7Q5UKJZL-HENKIQDX.js +14 -0
  127. package/dist/viewer-bundle/gitGraph-7Q5UKJZL-HENKIQDX.js.map +7 -0
  128. package/dist/viewer-bundle/gitGraphDiagram-UUTBAWPF-M4VV3YVA.js +1946 -0
  129. package/dist/viewer-bundle/gitGraphDiagram-UUTBAWPF-M4VV3YVA.js.map +7 -0
  130. package/dist/viewer-bundle/index.html +28 -0
  131. package/dist/viewer-bundle/info-OMHHGYJF-E773USRS.js +14 -0
  132. package/dist/viewer-bundle/info-OMHHGYJF-E773USRS.js.map +7 -0
  133. package/dist/viewer-bundle/infoDiagram-42DDH7IO-C7JGUXKK.js +59 -0
  134. package/dist/viewer-bundle/infoDiagram-42DDH7IO-C7JGUXKK.js.map +7 -0
  135. package/dist/viewer-bundle/ishikawaDiagram-UXIWVN3A-YBC4X4VB.js +1012 -0
  136. package/dist/viewer-bundle/ishikawaDiagram-UXIWVN3A-YBC4X4VB.js.map +7 -0
  137. package/dist/viewer-bundle/journeyDiagram-VCZTEJTY-6WKVEOOO.js +1303 -0
  138. package/dist/viewer-bundle/journeyDiagram-VCZTEJTY-6WKVEOOO.js.map +7 -0
  139. package/dist/viewer-bundle/kanban-definition-6JOO6SKY-URTTHHO4.js +1131 -0
  140. package/dist/viewer-bundle/kanban-definition-6JOO6SKY-URTTHHO4.js.map +7 -0
  141. package/dist/viewer-bundle/katex-QN5266ZE.js +14318 -0
  142. package/dist/viewer-bundle/katex-QN5266ZE.js.map +7 -0
  143. package/dist/viewer-bundle/light.css +15 -0
  144. package/dist/viewer-bundle/main.js +4816 -0
  145. package/dist/viewer-bundle/main.js.map +7 -0
  146. package/dist/viewer-bundle/mermaid.core-AEBXU2JK.js +1708 -0
  147. package/dist/viewer-bundle/mermaid.core-AEBXU2JK.js.map +7 -0
  148. package/dist/viewer-bundle/mindmap-definition-QFDTVHPH-KUMAMRSF.js +1277 -0
  149. package/dist/viewer-bundle/mindmap-definition-QFDTVHPH-KUMAMRSF.js.map +7 -0
  150. package/dist/viewer-bundle/packet-4T2RLAQJ-IRYWWA66.js +14 -0
  151. package/dist/viewer-bundle/packet-4T2RLAQJ-IRYWWA66.js.map +7 -0
  152. package/dist/viewer-bundle/pico.classless.min.css +4 -0
  153. package/dist/viewer-bundle/pie-ZZUOXDRM-JYO4VL5N.js +14 -0
  154. package/dist/viewer-bundle/pie-ZZUOXDRM-JYO4VL5N.js.map +7 -0
  155. package/dist/viewer-bundle/pieDiagram-DEJITSTG-QOEHQN3N.js +238 -0
  156. package/dist/viewer-bundle/pieDiagram-DEJITSTG-QOEHQN3N.js.map +7 -0
  157. package/dist/viewer-bundle/prompt-modal-C4LHI7BS.js +12 -0
  158. package/dist/viewer-bundle/prompt-modal-C4LHI7BS.js.map +7 -0
  159. package/dist/viewer-bundle/quadrantDiagram-34T5L4WZ-SJNPUU5N.js +1409 -0
  160. package/dist/viewer-bundle/quadrantDiagram-34T5L4WZ-SJNPUU5N.js.map +7 -0
  161. package/dist/viewer-bundle/radar-PYXPWWZC-45BRYQSB.js +14 -0
  162. package/dist/viewer-bundle/radar-PYXPWWZC-45BRYQSB.js.map +7 -0
  163. package/dist/viewer-bundle/reason-modal-MK34MQ73.js +68 -0
  164. package/dist/viewer-bundle/reason-modal-MK34MQ73.js.map +7 -0
  165. package/dist/viewer-bundle/requirementDiagram-MS252O5E-UOMT3FCC.js +1311 -0
  166. package/dist/viewer-bundle/requirementDiagram-MS252O5E-UOMT3FCC.js.map +7 -0
  167. package/dist/viewer-bundle/sankeyDiagram-XADWPNL6-LAVJ5C6A.js +1263 -0
  168. package/dist/viewer-bundle/sankeyDiagram-XADWPNL6-LAVJ5C6A.js.map +7 -0
  169. package/dist/viewer-bundle/sequenceDiagram-FGHM5R23-3IWTOUNQ.js +4655 -0
  170. package/dist/viewer-bundle/sequenceDiagram-FGHM5R23-3IWTOUNQ.js.map +7 -0
  171. package/dist/viewer-bundle/stateDiagram-FHFEXIEX-S2OVQQON.js +495 -0
  172. package/dist/viewer-bundle/stateDiagram-FHFEXIEX-S2OVQQON.js.map +7 -0
  173. package/dist/viewer-bundle/stateDiagram-v2-QKLJ7IA2-XNZ3XXSV.js +44 -0
  174. package/dist/viewer-bundle/stateDiagram-v2-QKLJ7IA2-XNZ3XXSV.js.map +7 -0
  175. package/dist/viewer-bundle/timeline-definition-GMOUNBTQ-FHVZ7MHE.js +1646 -0
  176. package/dist/viewer-bundle/timeline-definition-GMOUNBTQ-FHVZ7MHE.js.map +7 -0
  177. package/dist/viewer-bundle/treeView-SZITEDCU-RXZXNYAM.js +14 -0
  178. package/dist/viewer-bundle/treeView-SZITEDCU-RXZXNYAM.js.map +7 -0
  179. package/dist/viewer-bundle/treemap-W4RFUUIX-2IGOFSJM.js +14 -0
  180. package/dist/viewer-bundle/treemap-W4RFUUIX-2IGOFSJM.js.map +7 -0
  181. package/dist/viewer-bundle/vennDiagram-DHZGUBPP-HEAOEXEZ.js +2544 -0
  182. package/dist/viewer-bundle/vennDiagram-DHZGUBPP-HEAOEXEZ.js.map +7 -0
  183. package/dist/viewer-bundle/wardley-RL74JXVD-VSPCLOX2.js +14 -0
  184. package/dist/viewer-bundle/wardley-RL74JXVD-VSPCLOX2.js.map +7 -0
  185. package/dist/viewer-bundle/wardleyDiagram-NUSXRM2D-EBY4FG3X.js +938 -0
  186. package/dist/viewer-bundle/wardleyDiagram-NUSXRM2D-EBY4FG3X.js.map +7 -0
  187. package/dist/viewer-bundle/xychartDiagram-5P7HB3ND-SSMUQEXK.js +1952 -0
  188. package/dist/viewer-bundle/xychartDiagram-5P7HB3ND-SSMUQEXK.js.map +7 -0
  189. package/package.json +51 -0
@@ -0,0 +1,1946 @@
1
+ import {
2
+ ImperativeState
3
+ } from "./chunk-QJVSDNAW.js";
4
+ import {
5
+ populateCommonDb
6
+ } from "./chunk-SRTYTXTX.js";
7
+ import {
8
+ parse
9
+ } from "./chunk-UEAG4BJQ.js";
10
+ import "./chunk-Z4G7FG27.js";
11
+ import "./chunk-D5RLIWY4.js";
12
+ import "./chunk-EXJQLTIV.js";
13
+ import "./chunk-RQIPIIE2.js";
14
+ import "./chunk-6VW7D5WX.js";
15
+ import "./chunk-GVE7OA3Z.js";
16
+ import "./chunk-ODEP5TKB.js";
17
+ import "./chunk-2QXGXAO5.js";
18
+ import "./chunk-UCAW6C6C.js";
19
+ import "./chunk-VODO7SV4.js";
20
+ import "./chunk-YFQT7PPW.js";
21
+ import "./chunk-A634GTZN.js";
22
+ import {
23
+ cleanAndMerge,
24
+ random,
25
+ utils_default
26
+ } from "./chunk-UVRE3R6A.js";
27
+ import "./chunk-G3PPZWPW.js";
28
+ import {
29
+ clear,
30
+ common_default,
31
+ defaultConfig_default,
32
+ getAccDescription,
33
+ getAccTitle,
34
+ getConfig,
35
+ getConfig2,
36
+ getDiagramTitle,
37
+ setAccDescription,
38
+ setAccTitle,
39
+ setDiagramTitle,
40
+ setupGraphViewbox2
41
+ } from "./chunk-7NZMPQDX.js";
42
+ import "./chunk-YEU62MVS.js";
43
+ import {
44
+ __name,
45
+ log,
46
+ select_default
47
+ } from "./chunk-CZHJHAOR.js";
48
+ import "./chunk-DI52DQAC.js";
49
+
50
+ // ../../node_modules/.pnpm/mermaid@11.14.0/node_modules/mermaid/dist/chunks/mermaid.core/gitGraphDiagram-UUTBAWPF.mjs
51
+ var commitType = {
52
+ NORMAL: 0,
53
+ REVERSE: 1,
54
+ HIGHLIGHT: 2,
55
+ MERGE: 3,
56
+ CHERRY_PICK: 4
57
+ };
58
+ var DEFAULT_GITGRAPH_CONFIG = defaultConfig_default.gitGraph;
59
+ var getConfig3 = /* @__PURE__ */ __name(() => {
60
+ const config = cleanAndMerge({
61
+ ...DEFAULT_GITGRAPH_CONFIG,
62
+ ...getConfig().gitGraph
63
+ });
64
+ return config;
65
+ }, "getConfig");
66
+ var state = new ImperativeState(() => {
67
+ const config = getConfig3();
68
+ const mainBranchName = config.mainBranchName;
69
+ const mainBranchOrder = config.mainBranchOrder;
70
+ return {
71
+ mainBranchName,
72
+ commits: /* @__PURE__ */ new Map(),
73
+ head: null,
74
+ branchConfig: /* @__PURE__ */ new Map([[mainBranchName, { name: mainBranchName, order: mainBranchOrder }]]),
75
+ branches: /* @__PURE__ */ new Map([[mainBranchName, null]]),
76
+ currBranch: mainBranchName,
77
+ direction: "LR",
78
+ seq: 0,
79
+ options: {}
80
+ };
81
+ });
82
+ function getID() {
83
+ return random({ length: 7 });
84
+ }
85
+ __name(getID, "getID");
86
+ function uniqBy(list, fn) {
87
+ const recordMap = /* @__PURE__ */ Object.create(null);
88
+ return list.reduce((out, item) => {
89
+ const key = fn(item);
90
+ if (!recordMap[key]) {
91
+ recordMap[key] = true;
92
+ out.push(item);
93
+ }
94
+ return out;
95
+ }, []);
96
+ }
97
+ __name(uniqBy, "uniqBy");
98
+ var setDirection = /* @__PURE__ */ __name(function(dir2) {
99
+ state.records.direction = dir2;
100
+ }, "setDirection");
101
+ var setOptions = /* @__PURE__ */ __name(function(rawOptString) {
102
+ log.debug("options str", rawOptString);
103
+ rawOptString = rawOptString?.trim();
104
+ rawOptString = rawOptString || "{}";
105
+ try {
106
+ state.records.options = JSON.parse(rawOptString);
107
+ } catch (e) {
108
+ log.error("error while parsing gitGraph options", e.message);
109
+ }
110
+ }, "setOptions");
111
+ var getOptions = /* @__PURE__ */ __name(function() {
112
+ return state.records.options;
113
+ }, "getOptions");
114
+ var commit = /* @__PURE__ */ __name(function(commitDB) {
115
+ let msg = commitDB.msg;
116
+ let id = commitDB.id;
117
+ const type = commitDB.type;
118
+ let tags = commitDB.tags;
119
+ log.info("commit", msg, id, type, tags);
120
+ log.debug("Entering commit:", msg, id, type, tags);
121
+ const config = getConfig3();
122
+ id = common_default.sanitizeText(id, config);
123
+ msg = common_default.sanitizeText(msg, config);
124
+ tags = tags?.map((tag) => common_default.sanitizeText(tag, config));
125
+ const newCommit = {
126
+ id: id ? id : state.records.seq + "-" + getID(),
127
+ message: msg,
128
+ seq: state.records.seq++,
129
+ type: type ?? commitType.NORMAL,
130
+ tags: tags ?? [],
131
+ parents: state.records.head == null ? [] : [state.records.head.id],
132
+ branch: state.records.currBranch
133
+ };
134
+ state.records.head = newCommit;
135
+ log.info("main branch", config.mainBranchName);
136
+ if (state.records.commits.has(newCommit.id)) {
137
+ log.warn(`Commit ID ${newCommit.id} already exists`);
138
+ }
139
+ state.records.commits.set(newCommit.id, newCommit);
140
+ state.records.branches.set(state.records.currBranch, newCommit.id);
141
+ log.debug("in pushCommit " + newCommit.id);
142
+ }, "commit");
143
+ var branch = /* @__PURE__ */ __name(function(branchDB) {
144
+ let name = branchDB.name;
145
+ const order = branchDB.order;
146
+ name = common_default.sanitizeText(name, getConfig3());
147
+ if (state.records.branches.has(name)) {
148
+ throw new Error(
149
+ `Trying to create an existing branch. (Help: Either use a new name if you want create a new branch or try using "checkout ${name}")`
150
+ );
151
+ }
152
+ state.records.branches.set(name, state.records.head != null ? state.records.head.id : null);
153
+ state.records.branchConfig.set(name, { name, order });
154
+ checkout(name);
155
+ log.debug("in createBranch");
156
+ }, "branch");
157
+ var merge = /* @__PURE__ */ __name((mergeDB) => {
158
+ let otherBranch = mergeDB.branch;
159
+ let customId = mergeDB.id;
160
+ const overrideType = mergeDB.type;
161
+ const customTags = mergeDB.tags;
162
+ const config = getConfig3();
163
+ otherBranch = common_default.sanitizeText(otherBranch, config);
164
+ if (customId) {
165
+ customId = common_default.sanitizeText(customId, config);
166
+ }
167
+ const currentBranchCheck = state.records.branches.get(state.records.currBranch);
168
+ const otherBranchCheck = state.records.branches.get(otherBranch);
169
+ const currentCommit = currentBranchCheck ? state.records.commits.get(currentBranchCheck) : void 0;
170
+ const otherCommit = otherBranchCheck ? state.records.commits.get(otherBranchCheck) : void 0;
171
+ if (currentCommit && otherCommit && currentCommit.branch === otherBranch) {
172
+ throw new Error(`Cannot merge branch '${otherBranch}' into itself.`);
173
+ }
174
+ if (state.records.currBranch === otherBranch) {
175
+ const error = new Error('Incorrect usage of "merge". Cannot merge a branch to itself');
176
+ error.hash = {
177
+ text: `merge ${otherBranch}`,
178
+ token: `merge ${otherBranch}`,
179
+ expected: ["branch abc"]
180
+ };
181
+ throw error;
182
+ }
183
+ if (currentCommit === void 0 || !currentCommit) {
184
+ const error = new Error(
185
+ `Incorrect usage of "merge". Current branch (${state.records.currBranch})has no commits`
186
+ );
187
+ error.hash = {
188
+ text: `merge ${otherBranch}`,
189
+ token: `merge ${otherBranch}`,
190
+ expected: ["commit"]
191
+ };
192
+ throw error;
193
+ }
194
+ if (!state.records.branches.has(otherBranch)) {
195
+ const error = new Error(
196
+ 'Incorrect usage of "merge". Branch to be merged (' + otherBranch + ") does not exist"
197
+ );
198
+ error.hash = {
199
+ text: `merge ${otherBranch}`,
200
+ token: `merge ${otherBranch}`,
201
+ expected: [`branch ${otherBranch}`]
202
+ };
203
+ throw error;
204
+ }
205
+ if (otherCommit === void 0 || !otherCommit) {
206
+ const error = new Error(
207
+ 'Incorrect usage of "merge". Branch to be merged (' + otherBranch + ") has no commits"
208
+ );
209
+ error.hash = {
210
+ text: `merge ${otherBranch}`,
211
+ token: `merge ${otherBranch}`,
212
+ expected: ['"commit"']
213
+ };
214
+ throw error;
215
+ }
216
+ if (currentCommit === otherCommit) {
217
+ const error = new Error('Incorrect usage of "merge". Both branches have same head');
218
+ error.hash = {
219
+ text: `merge ${otherBranch}`,
220
+ token: `merge ${otherBranch}`,
221
+ expected: ["branch abc"]
222
+ };
223
+ throw error;
224
+ }
225
+ if (customId && state.records.commits.has(customId)) {
226
+ const error = new Error(
227
+ 'Incorrect usage of "merge". Commit with id:' + customId + " already exists, use different custom id"
228
+ );
229
+ error.hash = {
230
+ text: `merge ${otherBranch} ${customId} ${overrideType} ${customTags?.join(" ")}`,
231
+ token: `merge ${otherBranch} ${customId} ${overrideType} ${customTags?.join(" ")}`,
232
+ expected: [
233
+ `merge ${otherBranch} ${customId}_UNIQUE ${overrideType} ${customTags?.join(" ")}`
234
+ ]
235
+ };
236
+ throw error;
237
+ }
238
+ const verifiedBranch = otherBranchCheck ? otherBranchCheck : "";
239
+ const commit2 = {
240
+ id: customId || `${state.records.seq}-${getID()}`,
241
+ message: `merged branch ${otherBranch} into ${state.records.currBranch}`,
242
+ seq: state.records.seq++,
243
+ parents: state.records.head == null ? [] : [state.records.head.id, verifiedBranch],
244
+ branch: state.records.currBranch,
245
+ type: commitType.MERGE,
246
+ customType: overrideType,
247
+ customId: customId ? true : false,
248
+ tags: customTags ?? []
249
+ };
250
+ state.records.head = commit2;
251
+ state.records.commits.set(commit2.id, commit2);
252
+ state.records.branches.set(state.records.currBranch, commit2.id);
253
+ log.debug(state.records.branches);
254
+ log.debug("in mergeBranch");
255
+ }, "merge");
256
+ var cherryPick = /* @__PURE__ */ __name(function(cherryPickDB) {
257
+ let sourceId = cherryPickDB.id;
258
+ let targetId = cherryPickDB.targetId;
259
+ let tags = cherryPickDB.tags;
260
+ let parentCommitId = cherryPickDB.parent;
261
+ log.debug("Entering cherryPick:", sourceId, targetId, tags);
262
+ const config = getConfig3();
263
+ sourceId = common_default.sanitizeText(sourceId, config);
264
+ targetId = common_default.sanitizeText(targetId, config);
265
+ tags = tags?.map((tag) => common_default.sanitizeText(tag, config));
266
+ parentCommitId = common_default.sanitizeText(parentCommitId, config);
267
+ if (!sourceId || !state.records.commits.has(sourceId)) {
268
+ const error = new Error(
269
+ 'Incorrect usage of "cherryPick". Source commit id should exist and provided'
270
+ );
271
+ error.hash = {
272
+ text: `cherryPick ${sourceId} ${targetId}`,
273
+ token: `cherryPick ${sourceId} ${targetId}`,
274
+ expected: ["cherry-pick abc"]
275
+ };
276
+ throw error;
277
+ }
278
+ const sourceCommit = state.records.commits.get(sourceId);
279
+ if (sourceCommit === void 0 || !sourceCommit) {
280
+ throw new Error('Incorrect usage of "cherryPick". Source commit id should exist and provided');
281
+ }
282
+ if (parentCommitId && !(Array.isArray(sourceCommit.parents) && sourceCommit.parents.includes(parentCommitId))) {
283
+ const error = new Error(
284
+ "Invalid operation: The specified parent commit is not an immediate parent of the cherry-picked commit."
285
+ );
286
+ throw error;
287
+ }
288
+ const sourceCommitBranch = sourceCommit.branch;
289
+ if (sourceCommit.type === commitType.MERGE && !parentCommitId) {
290
+ const error = new Error(
291
+ "Incorrect usage of cherry-pick: If the source commit is a merge commit, an immediate parent commit must be specified."
292
+ );
293
+ throw error;
294
+ }
295
+ if (!targetId || !state.records.commits.has(targetId)) {
296
+ if (sourceCommitBranch === state.records.currBranch) {
297
+ const error = new Error(
298
+ 'Incorrect usage of "cherryPick". Source commit is already on current branch'
299
+ );
300
+ error.hash = {
301
+ text: `cherryPick ${sourceId} ${targetId}`,
302
+ token: `cherryPick ${sourceId} ${targetId}`,
303
+ expected: ["cherry-pick abc"]
304
+ };
305
+ throw error;
306
+ }
307
+ const currentCommitId = state.records.branches.get(state.records.currBranch);
308
+ if (currentCommitId === void 0 || !currentCommitId) {
309
+ const error = new Error(
310
+ `Incorrect usage of "cherry-pick". Current branch (${state.records.currBranch})has no commits`
311
+ );
312
+ error.hash = {
313
+ text: `cherryPick ${sourceId} ${targetId}`,
314
+ token: `cherryPick ${sourceId} ${targetId}`,
315
+ expected: ["cherry-pick abc"]
316
+ };
317
+ throw error;
318
+ }
319
+ const currentCommit = state.records.commits.get(currentCommitId);
320
+ if (currentCommit === void 0 || !currentCommit) {
321
+ const error = new Error(
322
+ `Incorrect usage of "cherry-pick". Current branch (${state.records.currBranch})has no commits`
323
+ );
324
+ error.hash = {
325
+ text: `cherryPick ${sourceId} ${targetId}`,
326
+ token: `cherryPick ${sourceId} ${targetId}`,
327
+ expected: ["cherry-pick abc"]
328
+ };
329
+ throw error;
330
+ }
331
+ const commit2 = {
332
+ id: state.records.seq + "-" + getID(),
333
+ message: `cherry-picked ${sourceCommit?.message} into ${state.records.currBranch}`,
334
+ seq: state.records.seq++,
335
+ parents: state.records.head == null ? [] : [state.records.head.id, sourceCommit.id],
336
+ branch: state.records.currBranch,
337
+ type: commitType.CHERRY_PICK,
338
+ tags: tags ? tags.filter(Boolean) : [
339
+ `cherry-pick:${sourceCommit.id}${sourceCommit.type === commitType.MERGE ? `|parent:${parentCommitId}` : ""}`
340
+ ]
341
+ };
342
+ state.records.head = commit2;
343
+ state.records.commits.set(commit2.id, commit2);
344
+ state.records.branches.set(state.records.currBranch, commit2.id);
345
+ log.debug(state.records.branches);
346
+ log.debug("in cherryPick");
347
+ }
348
+ }, "cherryPick");
349
+ var checkout = /* @__PURE__ */ __name(function(branch2) {
350
+ branch2 = common_default.sanitizeText(branch2, getConfig3());
351
+ if (!state.records.branches.has(branch2)) {
352
+ const error = new Error(
353
+ `Trying to checkout branch which is not yet created. (Help try using "branch ${branch2}")`
354
+ );
355
+ error.hash = {
356
+ text: `checkout ${branch2}`,
357
+ token: `checkout ${branch2}`,
358
+ expected: [`branch ${branch2}`]
359
+ };
360
+ throw error;
361
+ } else {
362
+ state.records.currBranch = branch2;
363
+ const id = state.records.branches.get(state.records.currBranch);
364
+ if (id === void 0 || !id) {
365
+ state.records.head = null;
366
+ } else {
367
+ state.records.head = state.records.commits.get(id) ?? null;
368
+ }
369
+ }
370
+ }, "checkout");
371
+ function upsert(arr, key, newVal) {
372
+ const index = arr.indexOf(key);
373
+ if (index === -1) {
374
+ arr.push(newVal);
375
+ } else {
376
+ arr.splice(index, 1, newVal);
377
+ }
378
+ }
379
+ __name(upsert, "upsert");
380
+ function prettyPrintCommitHistory(commitArr) {
381
+ const commit2 = commitArr.reduce((out, commit3) => {
382
+ if (out.seq > commit3.seq) {
383
+ return out;
384
+ }
385
+ return commit3;
386
+ }, commitArr[0]);
387
+ let line = "";
388
+ commitArr.forEach(function(c) {
389
+ if (c === commit2) {
390
+ line += " *";
391
+ } else {
392
+ line += " |";
393
+ }
394
+ });
395
+ const label = [line, commit2.id, commit2.seq];
396
+ for (const branch2 in state.records.branches) {
397
+ if (state.records.branches.get(branch2) === commit2.id) {
398
+ label.push(branch2);
399
+ }
400
+ }
401
+ log.debug(label.join(" "));
402
+ if (commit2.parents && commit2.parents.length == 2 && commit2.parents[0] && commit2.parents[1]) {
403
+ const newCommit = state.records.commits.get(commit2.parents[0]);
404
+ upsert(commitArr, commit2, newCommit);
405
+ if (commit2.parents[1]) {
406
+ commitArr.push(state.records.commits.get(commit2.parents[1]));
407
+ }
408
+ } else if (commit2.parents.length == 0) {
409
+ return;
410
+ } else {
411
+ if (commit2.parents[0]) {
412
+ const newCommit = state.records.commits.get(commit2.parents[0]);
413
+ upsert(commitArr, commit2, newCommit);
414
+ }
415
+ }
416
+ commitArr = uniqBy(commitArr, (c) => c.id);
417
+ prettyPrintCommitHistory(commitArr);
418
+ }
419
+ __name(prettyPrintCommitHistory, "prettyPrintCommitHistory");
420
+ var prettyPrint = /* @__PURE__ */ __name(function() {
421
+ log.debug(state.records.commits);
422
+ const node = getCommitsArray()[0];
423
+ prettyPrintCommitHistory([node]);
424
+ }, "prettyPrint");
425
+ var clear2 = /* @__PURE__ */ __name(function() {
426
+ state.reset();
427
+ clear();
428
+ }, "clear");
429
+ var getBranchesAsObjArray = /* @__PURE__ */ __name(function() {
430
+ const branchesArray = [...state.records.branchConfig.values()].map((branchConfig, i) => {
431
+ if (branchConfig.order !== null && branchConfig.order !== void 0) {
432
+ return branchConfig;
433
+ }
434
+ return {
435
+ ...branchConfig,
436
+ order: parseFloat(`0.${i}`)
437
+ };
438
+ }).sort((a, b) => (a.order ?? 0) - (b.order ?? 0)).map(({ name }) => ({ name }));
439
+ return branchesArray;
440
+ }, "getBranchesAsObjArray");
441
+ var getBranches = /* @__PURE__ */ __name(function() {
442
+ return state.records.branches;
443
+ }, "getBranches");
444
+ var getCommits = /* @__PURE__ */ __name(function() {
445
+ return state.records.commits;
446
+ }, "getCommits");
447
+ var getCommitsArray = /* @__PURE__ */ __name(function() {
448
+ const commitArr = [...state.records.commits.values()];
449
+ commitArr.forEach(function(o) {
450
+ log.debug(o.id);
451
+ });
452
+ commitArr.sort((a, b) => a.seq - b.seq);
453
+ return commitArr;
454
+ }, "getCommitsArray");
455
+ var getCurrentBranch = /* @__PURE__ */ __name(function() {
456
+ return state.records.currBranch;
457
+ }, "getCurrentBranch");
458
+ var getDirection = /* @__PURE__ */ __name(function() {
459
+ return state.records.direction;
460
+ }, "getDirection");
461
+ var getHead = /* @__PURE__ */ __name(function() {
462
+ return state.records.head;
463
+ }, "getHead");
464
+ var db = {
465
+ commitType,
466
+ getConfig: getConfig3,
467
+ setDirection,
468
+ setOptions,
469
+ getOptions,
470
+ commit,
471
+ branch,
472
+ merge,
473
+ cherryPick,
474
+ checkout,
475
+ //reset,
476
+ prettyPrint,
477
+ clear: clear2,
478
+ getBranchesAsObjArray,
479
+ getBranches,
480
+ getCommits,
481
+ getCommitsArray,
482
+ getCurrentBranch,
483
+ getDirection,
484
+ getHead,
485
+ setAccTitle,
486
+ getAccTitle,
487
+ getAccDescription,
488
+ setAccDescription,
489
+ setDiagramTitle,
490
+ getDiagramTitle
491
+ };
492
+ var populate = /* @__PURE__ */ __name((ast, db2) => {
493
+ populateCommonDb(ast, db2);
494
+ if (ast.dir) {
495
+ db2.setDirection(ast.dir);
496
+ }
497
+ for (const statement of ast.statements) {
498
+ parseStatement(statement, db2);
499
+ }
500
+ }, "populate");
501
+ var parseStatement = /* @__PURE__ */ __name((statement, db2) => {
502
+ const parsers = {
503
+ Commit: /* @__PURE__ */ __name((stmt) => db2.commit(parseCommit(stmt)), "Commit"),
504
+ Branch: /* @__PURE__ */ __name((stmt) => db2.branch(parseBranch(stmt)), "Branch"),
505
+ Merge: /* @__PURE__ */ __name((stmt) => db2.merge(parseMerge(stmt)), "Merge"),
506
+ Checkout: /* @__PURE__ */ __name((stmt) => db2.checkout(parseCheckout(stmt)), "Checkout"),
507
+ CherryPicking: /* @__PURE__ */ __name((stmt) => db2.cherryPick(parseCherryPicking(stmt)), "CherryPicking")
508
+ };
509
+ const parser2 = parsers[statement.$type];
510
+ if (parser2) {
511
+ parser2(statement);
512
+ } else {
513
+ log.error(`Unknown statement type: ${statement.$type}`);
514
+ }
515
+ }, "parseStatement");
516
+ var parseCommit = /* @__PURE__ */ __name((commit2) => {
517
+ const commitDB = {
518
+ id: commit2.id,
519
+ msg: commit2.message ?? "",
520
+ type: commit2.type !== void 0 ? commitType[commit2.type] : commitType.NORMAL,
521
+ tags: commit2.tags ?? void 0
522
+ };
523
+ return commitDB;
524
+ }, "parseCommit");
525
+ var parseBranch = /* @__PURE__ */ __name((branch2) => {
526
+ const branchDB = {
527
+ name: branch2.name,
528
+ order: branch2.order ?? 0
529
+ };
530
+ return branchDB;
531
+ }, "parseBranch");
532
+ var parseMerge = /* @__PURE__ */ __name((merge2) => {
533
+ const mergeDB = {
534
+ branch: merge2.branch,
535
+ id: merge2.id ?? "",
536
+ type: merge2.type !== void 0 ? commitType[merge2.type] : void 0,
537
+ tags: merge2.tags ?? void 0
538
+ };
539
+ return mergeDB;
540
+ }, "parseMerge");
541
+ var parseCheckout = /* @__PURE__ */ __name((checkout2) => {
542
+ const branch2 = checkout2.branch;
543
+ return branch2;
544
+ }, "parseCheckout");
545
+ var parseCherryPicking = /* @__PURE__ */ __name((cherryPicking) => {
546
+ const cherryPickDB = {
547
+ id: cherryPicking.id,
548
+ targetId: "",
549
+ tags: cherryPicking.tags?.length === 0 ? void 0 : cherryPicking.tags,
550
+ parent: cherryPicking.parent
551
+ };
552
+ return cherryPickDB;
553
+ }, "parseCherryPicking");
554
+ var parser = {
555
+ parse: /* @__PURE__ */ __name(async (input) => {
556
+ const ast = await parse("gitGraph", input);
557
+ log.debug(ast);
558
+ populate(ast, db);
559
+ }, "parse")
560
+ };
561
+ if (void 0) {
562
+ const { it, expect, describe } = void 0;
563
+ const mockDB = {
564
+ commitType,
565
+ setDirection: vi.fn(),
566
+ commit: vi.fn(),
567
+ branch: vi.fn(),
568
+ merge: vi.fn(),
569
+ cherryPick: vi.fn(),
570
+ checkout: vi.fn()
571
+ };
572
+ describe("GitGraph Parser", () => {
573
+ it("should parse a commit statement", () => {
574
+ const commit2 = {
575
+ $type: "Commit",
576
+ id: "1",
577
+ message: "test",
578
+ tags: ["tag1", "tag2"],
579
+ type: "NORMAL"
580
+ };
581
+ parseStatement(commit2, mockDB);
582
+ expect(mockDB.commit).toHaveBeenCalledWith({
583
+ id: "1",
584
+ msg: "test",
585
+ tags: ["tag1", "tag2"],
586
+ type: 0
587
+ });
588
+ });
589
+ it("should parse a branch statement", () => {
590
+ const branch2 = {
591
+ $type: "Branch",
592
+ name: "newBranch",
593
+ order: 1
594
+ };
595
+ parseStatement(branch2, mockDB);
596
+ expect(mockDB.branch).toHaveBeenCalledWith({ name: "newBranch", order: 1 });
597
+ });
598
+ it("should parse a checkout statement", () => {
599
+ const checkout2 = {
600
+ $type: "Checkout",
601
+ branch: "newBranch"
602
+ };
603
+ parseStatement(checkout2, mockDB);
604
+ expect(mockDB.checkout).toHaveBeenCalledWith("newBranch");
605
+ });
606
+ it("should parse a merge statement", () => {
607
+ const merge2 = {
608
+ $type: "Merge",
609
+ branch: "newBranch",
610
+ id: "1",
611
+ tags: ["tag1", "tag2"],
612
+ type: "NORMAL"
613
+ };
614
+ parseStatement(merge2, mockDB);
615
+ expect(mockDB.merge).toHaveBeenCalledWith({
616
+ branch: "newBranch",
617
+ id: "1",
618
+ tags: ["tag1", "tag2"],
619
+ type: 0
620
+ });
621
+ });
622
+ it("should parse a cherry picking statement", () => {
623
+ const cherryPick2 = {
624
+ $type: "CherryPicking",
625
+ id: "1",
626
+ tags: ["tag1", "tag2"],
627
+ parent: "2"
628
+ };
629
+ parseStatement(cherryPick2, mockDB);
630
+ expect(mockDB.cherryPick).toHaveBeenCalledWith({
631
+ id: "1",
632
+ targetId: "",
633
+ parent: "2",
634
+ tags: ["tag1", "tag2"]
635
+ });
636
+ });
637
+ it("should parse a langium generated gitGraph ast", () => {
638
+ const dummy = {
639
+ $type: "GitGraph",
640
+ statements: [],
641
+ accDescr: "",
642
+ accTitle: "",
643
+ title: ""
644
+ };
645
+ const gitGraphAst = {
646
+ $type: "GitGraph",
647
+ statements: [
648
+ {
649
+ $container: dummy,
650
+ $type: "Commit",
651
+ id: "1",
652
+ message: "test",
653
+ tags: ["tag1", "tag2"],
654
+ type: "NORMAL"
655
+ },
656
+ {
657
+ $container: dummy,
658
+ $type: "Branch",
659
+ name: "newBranch",
660
+ order: 1
661
+ },
662
+ {
663
+ $container: dummy,
664
+ $type: "Merge",
665
+ branch: "newBranch",
666
+ id: "1",
667
+ tags: ["tag1", "tag2"],
668
+ type: "NORMAL"
669
+ },
670
+ {
671
+ $container: dummy,
672
+ $type: "Checkout",
673
+ branch: "newBranch"
674
+ },
675
+ {
676
+ $container: dummy,
677
+ $type: "CherryPicking",
678
+ id: "1",
679
+ tags: ["tag1", "tag2"],
680
+ parent: "2"
681
+ }
682
+ ],
683
+ accDescr: "",
684
+ accTitle: "",
685
+ title: ""
686
+ };
687
+ populate(gitGraphAst, mockDB);
688
+ expect(mockDB.commit).toHaveBeenCalledWith({
689
+ id: "1",
690
+ msg: "test",
691
+ tags: ["tag1", "tag2"],
692
+ type: 0
693
+ });
694
+ expect(mockDB.branch).toHaveBeenCalledWith({ name: "newBranch", order: 1 });
695
+ expect(mockDB.merge).toHaveBeenCalledWith({
696
+ branch: "newBranch",
697
+ id: "1",
698
+ tags: ["tag1", "tag2"],
699
+ type: 0
700
+ });
701
+ expect(mockDB.checkout).toHaveBeenCalledWith("newBranch");
702
+ });
703
+ });
704
+ }
705
+ var LAYOUT_OFFSET = 10;
706
+ var COMMIT_STEP = 40;
707
+ var PX = 4;
708
+ var PY = 2;
709
+ var THEME_COLOR_LIMIT = 8;
710
+ var REDUX_GEOMETRY_THEMES = /* @__PURE__ */ new Set(["redux", "redux-dark", "redux-color", "redux-dark-color"]);
711
+ var REDUX_BRANCH_LABEL_PADDING_Y = 12;
712
+ var COLOR_THEMES = /* @__PURE__ */ new Set(["redux-color", "redux-dark-color"]);
713
+ var DARK_THEMES = /* @__PURE__ */ new Set(["dark", "redux-dark", "redux-dark-color", "neo-dark"]);
714
+ var calcColorIndex = /* @__PURE__ */ __name((rawIndex, limit, avoidDefaultColor = false) => {
715
+ if (avoidDefaultColor && rawIndex > 0) {
716
+ return (rawIndex - 1) % (limit - 1) + 1;
717
+ }
718
+ return rawIndex % limit;
719
+ }, "calcColorIndex");
720
+ var branchPos = /* @__PURE__ */ new Map();
721
+ var commitPos = /* @__PURE__ */ new Map();
722
+ var defaultPos = 30;
723
+ var allCommitsDict = /* @__PURE__ */ new Map();
724
+ var lanes = [];
725
+ var maxPos = 0;
726
+ var dir = "LR";
727
+ var clear3 = /* @__PURE__ */ __name(() => {
728
+ branchPos.clear();
729
+ commitPos.clear();
730
+ allCommitsDict.clear();
731
+ maxPos = 0;
732
+ lanes = [];
733
+ dir = "LR";
734
+ }, "clear");
735
+ var drawText = /* @__PURE__ */ __name((txt) => {
736
+ const svgLabel = document.createElementNS("http://www.w3.org/2000/svg", "text");
737
+ const rows = typeof txt === "string" ? txt.split(/\\n|\n|<br\s*\/?>/gi) : txt;
738
+ rows.forEach((row) => {
739
+ const tspan = document.createElementNS("http://www.w3.org/2000/svg", "tspan");
740
+ tspan.setAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:space", "preserve");
741
+ tspan.setAttribute("dy", "1em");
742
+ tspan.setAttribute("x", "0");
743
+ tspan.setAttribute("class", "row");
744
+ tspan.textContent = row.trim();
745
+ svgLabel.appendChild(tspan);
746
+ });
747
+ return svgLabel;
748
+ }, "drawText");
749
+ var findClosestParent = /* @__PURE__ */ __name((parents) => {
750
+ let closestParent;
751
+ let comparisonFunc;
752
+ let targetPosition;
753
+ if (dir === "BT") {
754
+ comparisonFunc = /* @__PURE__ */ __name((a, b) => a <= b, "comparisonFunc");
755
+ targetPosition = Infinity;
756
+ } else {
757
+ comparisonFunc = /* @__PURE__ */ __name((a, b) => a >= b, "comparisonFunc");
758
+ targetPosition = 0;
759
+ }
760
+ parents.forEach((parent) => {
761
+ const parentPosition = dir === "TB" || dir == "BT" ? commitPos.get(parent)?.y : commitPos.get(parent)?.x;
762
+ if (parentPosition !== void 0 && comparisonFunc(parentPosition, targetPosition)) {
763
+ closestParent = parent;
764
+ targetPosition = parentPosition;
765
+ }
766
+ });
767
+ return closestParent;
768
+ }, "findClosestParent");
769
+ var findClosestParentBT = /* @__PURE__ */ __name((parents) => {
770
+ let closestParent = "";
771
+ let maxPosition = Infinity;
772
+ parents.forEach((parent) => {
773
+ const parentPosition = commitPos.get(parent).y;
774
+ if (parentPosition <= maxPosition) {
775
+ closestParent = parent;
776
+ maxPosition = parentPosition;
777
+ }
778
+ });
779
+ return closestParent || void 0;
780
+ }, "findClosestParentBT");
781
+ var setParallelBTPos = /* @__PURE__ */ __name((sortedKeys, commits, defaultPos2) => {
782
+ let curPos = defaultPos2;
783
+ let maxPosition = defaultPos2;
784
+ const roots = [];
785
+ sortedKeys.forEach((key) => {
786
+ const commit2 = commits.get(key);
787
+ if (!commit2) {
788
+ throw new Error(`Commit not found for key ${key}`);
789
+ }
790
+ if (commit2.parents.length) {
791
+ curPos = calculateCommitPosition(commit2);
792
+ maxPosition = Math.max(curPos, maxPosition);
793
+ } else {
794
+ roots.push(commit2);
795
+ }
796
+ setCommitPosition(commit2, curPos);
797
+ });
798
+ curPos = maxPosition;
799
+ roots.forEach((commit2) => {
800
+ setRootPosition(commit2, curPos, defaultPos2);
801
+ });
802
+ sortedKeys.forEach((key) => {
803
+ const commit2 = commits.get(key);
804
+ if (commit2?.parents.length) {
805
+ const closestParent = findClosestParentBT(commit2.parents);
806
+ curPos = commitPos.get(closestParent).y - COMMIT_STEP;
807
+ if (curPos <= maxPosition) {
808
+ maxPosition = curPos;
809
+ }
810
+ const x = branchPos.get(commit2.branch).pos;
811
+ const y = curPos - LAYOUT_OFFSET;
812
+ commitPos.set(commit2.id, { x, y });
813
+ }
814
+ });
815
+ }, "setParallelBTPos");
816
+ var findClosestParentPos = /* @__PURE__ */ __name((commit2) => {
817
+ const closestParent = findClosestParent(commit2.parents.filter((p) => p !== null));
818
+ if (!closestParent) {
819
+ throw new Error(`Closest parent not found for commit ${commit2.id}`);
820
+ }
821
+ const closestParentPos = commitPos.get(closestParent)?.y;
822
+ if (closestParentPos === void 0) {
823
+ throw new Error(`Closest parent position not found for commit ${commit2.id}`);
824
+ }
825
+ return closestParentPos;
826
+ }, "findClosestParentPos");
827
+ var calculateCommitPosition = /* @__PURE__ */ __name((commit2) => {
828
+ const closestParentPos = findClosestParentPos(commit2);
829
+ return closestParentPos + COMMIT_STEP;
830
+ }, "calculateCommitPosition");
831
+ var setCommitPosition = /* @__PURE__ */ __name((commit2, curPos) => {
832
+ const branch2 = branchPos.get(commit2.branch);
833
+ if (!branch2) {
834
+ throw new Error(`Branch not found for commit ${commit2.id}`);
835
+ }
836
+ const x = branch2.pos;
837
+ const y = curPos + LAYOUT_OFFSET;
838
+ commitPos.set(commit2.id, { x, y });
839
+ return { x, y };
840
+ }, "setCommitPosition");
841
+ var setRootPosition = /* @__PURE__ */ __name((commit2, curPos, defaultPos2) => {
842
+ const branch2 = branchPos.get(commit2.branch);
843
+ if (!branch2) {
844
+ throw new Error(`Branch not found for commit ${commit2.id}`);
845
+ }
846
+ const y = curPos + defaultPos2;
847
+ const x = branch2.pos;
848
+ commitPos.set(commit2.id, { x, y });
849
+ }, "setRootPosition");
850
+ var drawCommitBullet = /* @__PURE__ */ __name((gBullets, commit2, commitPosition, typeClass, branchIndex, commitSymbolType) => {
851
+ const { theme } = getConfig2();
852
+ const useReduxGeometry = REDUX_GEOMETRY_THEMES.has(theme ?? "");
853
+ const useColorTheme = COLOR_THEMES.has(theme ?? "");
854
+ const isDark = DARK_THEMES.has(theme ?? "");
855
+ if (commitSymbolType === commitType.HIGHLIGHT) {
856
+ gBullets.append("rect").attr("x", commitPosition.x - 10 + (useReduxGeometry ? 3 : 0)).attr("y", commitPosition.y - 10 + (useReduxGeometry ? 3 : 0)).attr("width", useReduxGeometry ? 14 : 20).attr("height", useReduxGeometry ? 14 : 20).attr(
857
+ "class",
858
+ `commit ${commit2.id} commit-highlight${calcColorIndex(branchIndex, THEME_COLOR_LIMIT, useColorTheme)} ${typeClass}-outer`
859
+ );
860
+ gBullets.append("rect").attr("x", commitPosition.x - 6 + (useReduxGeometry ? 2 : 0)).attr("y", commitPosition.y - 6 + (useReduxGeometry ? 2 : 0)).attr("width", useReduxGeometry ? 8 : 12).attr("height", useReduxGeometry ? 8 : 12).attr(
861
+ "class",
862
+ `commit ${commit2.id} commit${calcColorIndex(branchIndex, THEME_COLOR_LIMIT, useColorTheme)} ${typeClass}-inner`
863
+ );
864
+ } else if (commitSymbolType === commitType.CHERRY_PICK) {
865
+ gBullets.append("circle").attr("cx", commitPosition.x).attr("cy", commitPosition.y).attr("r", useReduxGeometry ? 7 : 10).attr("class", `commit ${commit2.id} ${typeClass}`);
866
+ gBullets.append("circle").attr("cx", commitPosition.x - 3).attr("cy", commitPosition.y + 2).attr("r", useReduxGeometry ? 2.5 : 2.75).attr("fill", isDark ? "#000000" : "#fff").attr("class", `commit ${commit2.id} ${typeClass}`);
867
+ gBullets.append("circle").attr("cx", commitPosition.x + 3).attr("cy", commitPosition.y + 2).attr("r", useReduxGeometry ? 2.5 : 2.75).attr("fill", isDark ? "#000000" : "#fff").attr("class", `commit ${commit2.id} ${typeClass}`);
868
+ gBullets.append("line").attr("x1", commitPosition.x + 3).attr("y1", commitPosition.y + 1).attr("x2", commitPosition.x).attr("y2", commitPosition.y - 5).attr("stroke", isDark ? "#000000" : "#fff").attr("class", `commit ${commit2.id} ${typeClass}`);
869
+ gBullets.append("line").attr("x1", commitPosition.x - 3).attr("y1", commitPosition.y + 1).attr("x2", commitPosition.x).attr("y2", commitPosition.y - 5).attr("stroke", isDark ? "#000000" : "#fff").attr("class", `commit ${commit2.id} ${typeClass}`);
870
+ } else {
871
+ const circle = gBullets.append("circle");
872
+ circle.attr("cx", commitPosition.x);
873
+ circle.attr("cy", commitPosition.y);
874
+ circle.attr("r", useReduxGeometry ? 7 : 10);
875
+ circle.attr(
876
+ "class",
877
+ `commit ${commit2.id} commit${calcColorIndex(branchIndex, THEME_COLOR_LIMIT, useColorTheme)}`
878
+ );
879
+ if (commitSymbolType === commitType.MERGE) {
880
+ const circle2 = gBullets.append("circle");
881
+ circle2.attr("cx", commitPosition.x);
882
+ circle2.attr("cy", commitPosition.y);
883
+ circle2.attr("r", useReduxGeometry ? 5 : 6);
884
+ circle2.attr(
885
+ "class",
886
+ `commit ${typeClass} ${commit2.id} commit${calcColorIndex(branchIndex, THEME_COLOR_LIMIT, useColorTheme)}`
887
+ );
888
+ }
889
+ if (commitSymbolType === commitType.REVERSE) {
890
+ const cross = gBullets.append("path");
891
+ const constValue = useReduxGeometry ? 4 : 5;
892
+ cross.attr(
893
+ "d",
894
+ `M ${commitPosition.x - constValue},${commitPosition.y - constValue}L${commitPosition.x + constValue},${commitPosition.y + constValue}M${commitPosition.x - constValue},${commitPosition.y + constValue}L${commitPosition.x + constValue},${commitPosition.y - constValue}`
895
+ ).attr(
896
+ "class",
897
+ `commit ${typeClass} ${commit2.id} commit${calcColorIndex(branchIndex, THEME_COLOR_LIMIT, useColorTheme)}`
898
+ );
899
+ }
900
+ }
901
+ }, "drawCommitBullet");
902
+ var drawCommitLabel = /* @__PURE__ */ __name((gLabels, commit2, commitPosition, pos, gitGraphConfig) => {
903
+ if (commit2.type !== commitType.CHERRY_PICK && (commit2.customId && commit2.type === commitType.MERGE || commit2.type !== commitType.MERGE) && gitGraphConfig.showCommitLabel) {
904
+ const wrapper = gLabels.append("g");
905
+ const labelBkg = wrapper.insert("rect").attr("class", "commit-label-bkg");
906
+ const text = wrapper.append("text").attr("x", pos).attr("y", commitPosition.y + 25).attr("class", "commit-label").text(commit2.id);
907
+ const bbox = text.node()?.getBBox();
908
+ if (bbox) {
909
+ 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);
910
+ if (dir === "TB" || dir === "BT") {
911
+ labelBkg.attr("x", commitPosition.x - (bbox.width + 4 * PX + 5)).attr("y", commitPosition.y - 12);
912
+ text.attr("x", commitPosition.x - (bbox.width + 4 * PX)).attr("y", commitPosition.y + bbox.height - 12);
913
+ } else {
914
+ text.attr("x", commitPosition.posWithOffset - bbox.width / 2);
915
+ }
916
+ if (gitGraphConfig.rotateCommitLabel) {
917
+ if (dir === "TB" || dir === "BT") {
918
+ text.attr(
919
+ "transform",
920
+ "rotate(-45, " + commitPosition.x + ", " + commitPosition.y + ")"
921
+ );
922
+ labelBkg.attr(
923
+ "transform",
924
+ "rotate(-45, " + commitPosition.x + ", " + commitPosition.y + ")"
925
+ );
926
+ } else {
927
+ const r_x = -7.5 - (bbox.width + 10) / 25 * 9.5;
928
+ const r_y = 10 + bbox.width / 25 * 8.5;
929
+ wrapper.attr(
930
+ "transform",
931
+ "translate(" + r_x + ", " + r_y + ") rotate(-45, " + pos + ", " + commitPosition.y + ")"
932
+ );
933
+ }
934
+ }
935
+ }
936
+ }
937
+ }, "drawCommitLabel");
938
+ var drawCommitTags = /* @__PURE__ */ __name((gLabels, commit2, commitPosition, pos) => {
939
+ if (commit2.tags.length > 0) {
940
+ let yOffset = 0;
941
+ let maxTagBboxWidth = 0;
942
+ let maxTagBboxHeight = 0;
943
+ const tagElements = [];
944
+ for (const tagValue of commit2.tags.reverse()) {
945
+ const rect = gLabels.insert("polygon");
946
+ const hole = gLabels.append("circle");
947
+ const tag = gLabels.append("text").attr("y", commitPosition.y - 16 - yOffset).attr("class", "tag-label").text(tagValue);
948
+ const tagBbox = tag.node()?.getBBox();
949
+ if (!tagBbox) {
950
+ throw new Error("Tag bbox not found");
951
+ }
952
+ maxTagBboxWidth = Math.max(maxTagBboxWidth, tagBbox.width);
953
+ maxTagBboxHeight = Math.max(maxTagBboxHeight, tagBbox.height);
954
+ tag.attr("x", commitPosition.posWithOffset - tagBbox.width / 2);
955
+ tagElements.push({
956
+ tag,
957
+ hole,
958
+ rect,
959
+ yOffset
960
+ });
961
+ yOffset += 20;
962
+ }
963
+ for (const { tag, hole, rect, yOffset: yOffset2 } of tagElements) {
964
+ const h2 = maxTagBboxHeight / 2;
965
+ const ly = commitPosition.y - 19.2 - yOffset2;
966
+ rect.attr("class", "tag-label-bkg").attr(
967
+ "points",
968
+ `
969
+ ${pos - maxTagBboxWidth / 2 - PX / 2},${ly + PY}
970
+ ${pos - maxTagBboxWidth / 2 - PX / 2},${ly - PY}
971
+ ${commitPosition.posWithOffset - maxTagBboxWidth / 2 - PX},${ly - h2 - PY}
972
+ ${commitPosition.posWithOffset + maxTagBboxWidth / 2 + PX},${ly - h2 - PY}
973
+ ${commitPosition.posWithOffset + maxTagBboxWidth / 2 + PX},${ly + h2 + PY}
974
+ ${commitPosition.posWithOffset - maxTagBboxWidth / 2 - PX},${ly + h2 + PY}`
975
+ );
976
+ hole.attr("cy", ly).attr("cx", pos - maxTagBboxWidth / 2 + PX / 2).attr("r", 1.5).attr("class", "tag-hole");
977
+ if (dir === "TB" || dir === "BT") {
978
+ const yOrigin = pos + yOffset2;
979
+ rect.attr("class", "tag-label-bkg").attr(
980
+ "points",
981
+ `
982
+ ${commitPosition.x},${yOrigin + 2}
983
+ ${commitPosition.x},${yOrigin - 2}
984
+ ${commitPosition.x + LAYOUT_OFFSET},${yOrigin - h2 - 2}
985
+ ${commitPosition.x + LAYOUT_OFFSET + maxTagBboxWidth + 4},${yOrigin - h2 - 2}
986
+ ${commitPosition.x + LAYOUT_OFFSET + maxTagBboxWidth + 4},${yOrigin + h2 + 2}
987
+ ${commitPosition.x + LAYOUT_OFFSET},${yOrigin + h2 + 2}`
988
+ ).attr("transform", "translate(12,12) rotate(45, " + commitPosition.x + "," + pos + ")");
989
+ hole.attr("cx", commitPosition.x + PX / 2).attr("cy", yOrigin).attr("transform", "translate(12,12) rotate(45, " + commitPosition.x + "," + pos + ")");
990
+ tag.attr("x", commitPosition.x + 5).attr("y", yOrigin + 3).attr("transform", "translate(14,14) rotate(45, " + commitPosition.x + "," + pos + ")");
991
+ }
992
+ }
993
+ }
994
+ }, "drawCommitTags");
995
+ var getCommitClassType = /* @__PURE__ */ __name((commit2) => {
996
+ const commitSymbolType = commit2.customType ?? commit2.type;
997
+ switch (commitSymbolType) {
998
+ case commitType.NORMAL:
999
+ return "commit-normal";
1000
+ case commitType.REVERSE:
1001
+ return "commit-reverse";
1002
+ case commitType.HIGHLIGHT:
1003
+ return "commit-highlight";
1004
+ case commitType.MERGE:
1005
+ return "commit-merge";
1006
+ case commitType.CHERRY_PICK:
1007
+ return "commit-cherry-pick";
1008
+ default:
1009
+ return "commit-normal";
1010
+ }
1011
+ }, "getCommitClassType");
1012
+ var calculatePosition = /* @__PURE__ */ __name((commit2, dir2, pos, commitPos2) => {
1013
+ const defaultCommitPosition = { x: 0, y: 0 };
1014
+ if (commit2.parents.length > 0) {
1015
+ const closestParent = findClosestParent(commit2.parents);
1016
+ if (closestParent) {
1017
+ const parentPosition = commitPos2.get(closestParent) ?? defaultCommitPosition;
1018
+ if (dir2 === "TB") {
1019
+ return parentPosition.y + COMMIT_STEP;
1020
+ } else if (dir2 === "BT") {
1021
+ const currentPosition = commitPos2.get(commit2.id) ?? defaultCommitPosition;
1022
+ return currentPosition.y - COMMIT_STEP;
1023
+ } else {
1024
+ return parentPosition.x + COMMIT_STEP;
1025
+ }
1026
+ }
1027
+ } else {
1028
+ if (dir2 === "TB") {
1029
+ return defaultPos;
1030
+ } else if (dir2 === "BT") {
1031
+ const currentPosition = commitPos2.get(commit2.id) ?? defaultCommitPosition;
1032
+ return currentPosition.y - COMMIT_STEP;
1033
+ } else {
1034
+ return 0;
1035
+ }
1036
+ }
1037
+ return 0;
1038
+ }, "calculatePosition");
1039
+ var getCommitPosition = /* @__PURE__ */ __name((commit2, pos, isParallelCommits) => {
1040
+ const posWithOffset = dir === "BT" && isParallelCommits ? pos : pos + LAYOUT_OFFSET;
1041
+ const branchY = branchPos.get(commit2.branch)?.pos;
1042
+ const x = dir === "TB" || dir === "BT" ? branchPos.get(commit2.branch)?.pos : posWithOffset;
1043
+ if (x === void 0 || branchY === void 0) {
1044
+ throw new Error(`Position were undefined for commit ${commit2.id}`);
1045
+ }
1046
+ const useReduxGeometry = REDUX_GEOMETRY_THEMES.has(getConfig2().theme ?? "");
1047
+ const y = dir === "TB" || dir === "BT" ? posWithOffset : branchY + (useReduxGeometry ? REDUX_BRANCH_LABEL_PADDING_Y / 2 + 1 : -2);
1048
+ return { x, y, posWithOffset };
1049
+ }, "getCommitPosition");
1050
+ var drawCommits = /* @__PURE__ */ __name((svg, commits, modifyGraph, gitGraphConfig) => {
1051
+ const gBullets = svg.append("g").attr("class", "commit-bullets");
1052
+ const gLabels = svg.append("g").attr("class", "commit-labels");
1053
+ let pos = dir === "TB" || dir === "BT" ? defaultPos : 0;
1054
+ const keys = [...commits.keys()];
1055
+ const isParallelCommits = gitGraphConfig.parallelCommits ?? false;
1056
+ const sortKeys = /* @__PURE__ */ __name((a, b) => {
1057
+ const seqA = commits.get(a)?.seq;
1058
+ const seqB = commits.get(b)?.seq;
1059
+ return seqA !== void 0 && seqB !== void 0 ? seqA - seqB : 0;
1060
+ }, "sortKeys");
1061
+ let sortedKeys = keys.sort(sortKeys);
1062
+ if (dir === "BT") {
1063
+ if (isParallelCommits) {
1064
+ setParallelBTPos(sortedKeys, commits, pos);
1065
+ }
1066
+ sortedKeys = sortedKeys.reverse();
1067
+ }
1068
+ sortedKeys.forEach((key) => {
1069
+ const commit2 = commits.get(key);
1070
+ if (!commit2) {
1071
+ throw new Error(`Commit not found for key ${key}`);
1072
+ }
1073
+ if (isParallelCommits) {
1074
+ pos = calculatePosition(commit2, dir, pos, commitPos);
1075
+ }
1076
+ const commitPosition = getCommitPosition(commit2, pos, isParallelCommits);
1077
+ if (modifyGraph) {
1078
+ const typeClass = getCommitClassType(commit2);
1079
+ const commitSymbolType = commit2.customType ?? commit2.type;
1080
+ const branchIndex = branchPos.get(commit2.branch)?.index ?? 0;
1081
+ drawCommitBullet(gBullets, commit2, commitPosition, typeClass, branchIndex, commitSymbolType);
1082
+ drawCommitLabel(gLabels, commit2, commitPosition, pos, gitGraphConfig);
1083
+ drawCommitTags(gLabels, commit2, commitPosition, pos);
1084
+ }
1085
+ if (dir === "TB" || dir === "BT") {
1086
+ commitPos.set(commit2.id, { x: commitPosition.x, y: commitPosition.posWithOffset });
1087
+ } else {
1088
+ commitPos.set(commit2.id, { x: commitPosition.posWithOffset, y: commitPosition.y });
1089
+ }
1090
+ pos = dir === "BT" && isParallelCommits ? pos + COMMIT_STEP : pos + COMMIT_STEP + LAYOUT_OFFSET;
1091
+ if (pos > maxPos) {
1092
+ maxPos = pos;
1093
+ }
1094
+ });
1095
+ }, "drawCommits");
1096
+ var shouldRerouteArrow = /* @__PURE__ */ __name((commitA, commitB, p1, p2, allCommits) => {
1097
+ const commitBIsFurthest = dir === "TB" || dir === "BT" ? p1.x < p2.x : p1.y < p2.y;
1098
+ const branchToGetCurve = commitBIsFurthest ? commitB.branch : commitA.branch;
1099
+ const isOnBranchToGetCurve = /* @__PURE__ */ __name((x) => x.branch === branchToGetCurve, "isOnBranchToGetCurve");
1100
+ const isBetweenCommits = /* @__PURE__ */ __name((x) => x.seq > commitA.seq && x.seq < commitB.seq, "isBetweenCommits");
1101
+ return [...allCommits.values()].some((commitX) => {
1102
+ return isBetweenCommits(commitX) && isOnBranchToGetCurve(commitX);
1103
+ });
1104
+ }, "shouldRerouteArrow");
1105
+ var findLane = /* @__PURE__ */ __name((y1, y2, depth = 0) => {
1106
+ const candidate = y1 + Math.abs(y1 - y2) / 2;
1107
+ if (depth > 5) {
1108
+ return candidate;
1109
+ }
1110
+ const ok = lanes.every((lane) => Math.abs(lane - candidate) >= 10);
1111
+ if (ok) {
1112
+ lanes.push(candidate);
1113
+ return candidate;
1114
+ }
1115
+ const diff = Math.abs(y1 - y2);
1116
+ return findLane(y1, y2 - diff / 5, depth + 1);
1117
+ }, "findLane");
1118
+ var drawArrow = /* @__PURE__ */ __name((svg, commitA, commitB, allCommits) => {
1119
+ const { theme: arrowTheme } = getConfig2();
1120
+ const useColorTheme = COLOR_THEMES.has(arrowTheme ?? "");
1121
+ const p1 = commitPos.get(commitA.id);
1122
+ const p2 = commitPos.get(commitB.id);
1123
+ if (p1 === void 0 || p2 === void 0) {
1124
+ throw new Error(`Commit positions not found for commits ${commitA.id} and ${commitB.id}`);
1125
+ }
1126
+ const arrowNeedsRerouting = shouldRerouteArrow(commitA, commitB, p1, p2, allCommits);
1127
+ let arc = "";
1128
+ let arc2 = "";
1129
+ let radius = 0;
1130
+ let offset = 0;
1131
+ let colorClassNum = branchPos.get(commitB.branch)?.index;
1132
+ if (commitB.type === commitType.MERGE && commitA.id !== commitB.parents[0]) {
1133
+ colorClassNum = branchPos.get(commitA.branch)?.index;
1134
+ }
1135
+ let lineDef;
1136
+ if (arrowNeedsRerouting) {
1137
+ arc = "A 10 10, 0, 0, 0,";
1138
+ arc2 = "A 10 10, 0, 0, 1,";
1139
+ radius = 10;
1140
+ offset = 10;
1141
+ const lineY = p1.y < p2.y ? findLane(p1.y, p2.y) : findLane(p2.y, p1.y);
1142
+ const lineX = p1.x < p2.x ? findLane(p1.x, p2.x) : findLane(p2.x, p1.x);
1143
+ if (dir === "TB") {
1144
+ if (p1.x < p2.x) {
1145
+ 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}`;
1146
+ } else {
1147
+ colorClassNum = branchPos.get(commitA.branch)?.index;
1148
+ 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}`;
1149
+ }
1150
+ } else if (dir === "BT") {
1151
+ if (p1.x < p2.x) {
1152
+ 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}`;
1153
+ } else {
1154
+ colorClassNum = branchPos.get(commitA.branch)?.index;
1155
+ 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}`;
1156
+ }
1157
+ } else {
1158
+ if (p1.y < p2.y) {
1159
+ 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}`;
1160
+ } else {
1161
+ colorClassNum = branchPos.get(commitA.branch)?.index;
1162
+ 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}`;
1163
+ }
1164
+ }
1165
+ } else {
1166
+ arc = "A 20 20, 0, 0, 0,";
1167
+ arc2 = "A 20 20, 0, 0, 1,";
1168
+ radius = 20;
1169
+ offset = 20;
1170
+ if (dir === "TB") {
1171
+ if (p1.x < p2.x) {
1172
+ if (commitB.type === commitType.MERGE && commitA.id !== commitB.parents[0]) {
1173
+ lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y - radius} ${arc} ${p1.x + offset} ${p2.y} L ${p2.x} ${p2.y}`;
1174
+ } else {
1175
+ lineDef = `M ${p1.x} ${p1.y} L ${p2.x - radius} ${p1.y} ${arc2} ${p2.x} ${p1.y + offset} L ${p2.x} ${p2.y}`;
1176
+ }
1177
+ }
1178
+ if (p1.x > p2.x) {
1179
+ arc = "A 20 20, 0, 0, 0,";
1180
+ arc2 = "A 20 20, 0, 0, 1,";
1181
+ radius = 20;
1182
+ offset = 20;
1183
+ if (commitB.type === commitType.MERGE && commitA.id !== commitB.parents[0]) {
1184
+ lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y - radius} ${arc2} ${p1.x - offset} ${p2.y} L ${p2.x} ${p2.y}`;
1185
+ } else {
1186
+ lineDef = `M ${p1.x} ${p1.y} L ${p2.x + radius} ${p1.y} ${arc} ${p2.x} ${p1.y + offset} L ${p2.x} ${p2.y}`;
1187
+ }
1188
+ }
1189
+ if (p1.x === p2.x) {
1190
+ lineDef = `M ${p1.x} ${p1.y} L ${p2.x} ${p2.y}`;
1191
+ }
1192
+ } else if (dir === "BT") {
1193
+ if (p1.x < p2.x) {
1194
+ if (commitB.type === commitType.MERGE && commitA.id !== commitB.parents[0]) {
1195
+ lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y + radius} ${arc2} ${p1.x + offset} ${p2.y} L ${p2.x} ${p2.y}`;
1196
+ } else {
1197
+ lineDef = `M ${p1.x} ${p1.y} L ${p2.x - radius} ${p1.y} ${arc} ${p2.x} ${p1.y - offset} L ${p2.x} ${p2.y}`;
1198
+ }
1199
+ }
1200
+ if (p1.x > p2.x) {
1201
+ arc = "A 20 20, 0, 0, 0,";
1202
+ arc2 = "A 20 20, 0, 0, 1,";
1203
+ radius = 20;
1204
+ offset = 20;
1205
+ if (commitB.type === commitType.MERGE && commitA.id !== commitB.parents[0]) {
1206
+ lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y + radius} ${arc} ${p1.x - offset} ${p2.y} L ${p2.x} ${p2.y}`;
1207
+ } else {
1208
+ lineDef = `M ${p1.x} ${p1.y} L ${p2.x + radius} ${p1.y} ${arc2} ${p2.x} ${p1.y - offset} L ${p2.x} ${p2.y}`;
1209
+ }
1210
+ }
1211
+ if (p1.x === p2.x) {
1212
+ lineDef = `M ${p1.x} ${p1.y} L ${p2.x} ${p2.y}`;
1213
+ }
1214
+ } else {
1215
+ if (p1.y < p2.y) {
1216
+ if (commitB.type === commitType.MERGE && commitA.id !== commitB.parents[0]) {
1217
+ lineDef = `M ${p1.x} ${p1.y} L ${p2.x - radius} ${p1.y} ${arc2} ${p2.x} ${p1.y + offset} L ${p2.x} ${p2.y}`;
1218
+ } else {
1219
+ lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y - radius} ${arc} ${p1.x + offset} ${p2.y} L ${p2.x} ${p2.y}`;
1220
+ }
1221
+ }
1222
+ if (p1.y > p2.y) {
1223
+ if (commitB.type === commitType.MERGE && commitA.id !== commitB.parents[0]) {
1224
+ lineDef = `M ${p1.x} ${p1.y} L ${p2.x - radius} ${p1.y} ${arc} ${p2.x} ${p1.y - offset} L ${p2.x} ${p2.y}`;
1225
+ } else {
1226
+ lineDef = `M ${p1.x} ${p1.y} L ${p1.x} ${p2.y + radius} ${arc2} ${p1.x + offset} ${p2.y} L ${p2.x} ${p2.y}`;
1227
+ }
1228
+ }
1229
+ if (p1.y === p2.y) {
1230
+ lineDef = `M ${p1.x} ${p1.y} L ${p2.x} ${p2.y}`;
1231
+ }
1232
+ }
1233
+ }
1234
+ if (lineDef === void 0) {
1235
+ throw new Error("Line definition not found");
1236
+ }
1237
+ svg.append("path").attr("d", lineDef).attr(
1238
+ "class",
1239
+ "arrow arrow" + calcColorIndex(colorClassNum, THEME_COLOR_LIMIT, useColorTheme)
1240
+ );
1241
+ }, "drawArrow");
1242
+ var drawArrows = /* @__PURE__ */ __name((svg, commits) => {
1243
+ const gArrows = svg.append("g").attr("class", "commit-arrows");
1244
+ [...commits.keys()].forEach((key) => {
1245
+ const commit2 = commits.get(key);
1246
+ if (commit2.parents && commit2.parents.length > 0) {
1247
+ commit2.parents.forEach((parent) => {
1248
+ drawArrow(gArrows, commits.get(parent), commit2, commits);
1249
+ });
1250
+ }
1251
+ });
1252
+ }, "drawArrows");
1253
+ var drawBranches = /* @__PURE__ */ __name((svg, branches, gitGraphConfig, id) => {
1254
+ const { look, theme, themeVariables } = getConfig2();
1255
+ const { dropShadow, THEME_COLOR_LIMIT: themeColorLimit } = themeVariables;
1256
+ const useReduxGeometry = REDUX_GEOMETRY_THEMES.has(theme ?? "");
1257
+ const useColorTheme = COLOR_THEMES.has(theme ?? "");
1258
+ const g = svg.append("g");
1259
+ branches.forEach((branch2, index) => {
1260
+ const adjustIndexForTheme = calcColorIndex(
1261
+ index,
1262
+ useReduxGeometry ? themeColorLimit : THEME_COLOR_LIMIT,
1263
+ useColorTheme
1264
+ );
1265
+ const pos = branchPos.get(branch2.name)?.pos;
1266
+ if (pos === void 0) {
1267
+ throw new Error(`Position not found for branch ${branch2.name}`);
1268
+ }
1269
+ const spineY = dir === "TB" || dir === "BT" ? pos : useReduxGeometry ? pos + REDUX_BRANCH_LABEL_PADDING_Y / 2 + 1 : pos - 2;
1270
+ const line = g.append("line");
1271
+ line.attr("x1", 0);
1272
+ line.attr("y1", spineY);
1273
+ line.attr("x2", maxPos);
1274
+ line.attr("y2", spineY);
1275
+ line.attr("class", "branch branch" + adjustIndexForTheme);
1276
+ if (dir === "TB") {
1277
+ line.attr("y1", defaultPos);
1278
+ line.attr("x1", pos);
1279
+ line.attr("y2", maxPos);
1280
+ line.attr("x2", pos);
1281
+ } else if (dir === "BT") {
1282
+ line.attr("y1", maxPos);
1283
+ line.attr("x1", pos);
1284
+ line.attr("y2", defaultPos);
1285
+ line.attr("x2", pos);
1286
+ }
1287
+ lanes.push(spineY);
1288
+ const name = branch2.name;
1289
+ const labelElement = drawText(name);
1290
+ const bkg = g.insert("rect");
1291
+ const branchLabel = g.insert("g").attr("class", "branchLabel");
1292
+ const label = branchLabel.insert("g").attr("class", "label branch-label" + adjustIndexForTheme);
1293
+ label.node().appendChild(labelElement);
1294
+ const bbox = labelElement.getBBox();
1295
+ const borderRadius = useReduxGeometry ? 0 : 4;
1296
+ const labelPaddingX = useReduxGeometry ? 16 : 0;
1297
+ const labelPaddingY = useReduxGeometry ? REDUX_BRANCH_LABEL_PADDING_Y : 0;
1298
+ if (look === "neo") {
1299
+ bkg.attr("data-look", `neo`);
1300
+ }
1301
+ bkg.attr("class", "branchLabelBkg label" + adjustIndexForTheme).attr(
1302
+ "style",
1303
+ look === "neo" ? `filter:${useReduxGeometry ? `url(#${id}-drop-shadow)` : dropShadow}` : ""
1304
+ ).attr("rx", borderRadius).attr("ry", borderRadius).attr("x", -bbox.width - 4 - (gitGraphConfig.rotateCommitLabel === true ? 30 : 0)).attr("y", -bbox.height / 2 + 10).attr("width", bbox.width + 18 + labelPaddingX).attr("height", bbox.height + 4 + labelPaddingY);
1305
+ label.attr(
1306
+ "transform",
1307
+ "translate(" + (-bbox.width - 14 - (gitGraphConfig.rotateCommitLabel === true ? 30 : 0) + labelPaddingX / 2) + ", " + (spineY - bbox.height / 2 - 2) + ")"
1308
+ );
1309
+ if (dir === "TB") {
1310
+ bkg.attr("x", pos - bbox.width / 2 - 10).attr("y", 0);
1311
+ label.attr("transform", "translate(" + (pos - bbox.width / 2 - 5) + ", 0)");
1312
+ if (useReduxGeometry) {
1313
+ bkg.attr("transform", `translate(${-labelPaddingX / 2 - 3}, ${-labelPaddingY - 10})`);
1314
+ label.attr(
1315
+ "transform",
1316
+ "translate(" + (pos - bbox.width / 2 - 5) + ", " + (-labelPaddingY * 2 + 7) + ")"
1317
+ );
1318
+ }
1319
+ } else if (dir === "BT") {
1320
+ bkg.attr("x", pos - bbox.width / 2 - 10).attr("y", maxPos);
1321
+ label.attr("transform", "translate(" + (pos - bbox.width / 2 - 5) + ", " + maxPos + ")");
1322
+ if (useReduxGeometry) {
1323
+ bkg.attr("transform", `translate(${-labelPaddingX / 2 - 3}, ${labelPaddingY + 10})`);
1324
+ label.attr(
1325
+ "transform",
1326
+ "translate(" + (pos - bbox.width / 2 - 5) + ", " + (maxPos + labelPaddingY * 2 + 4) + ")"
1327
+ );
1328
+ }
1329
+ } else {
1330
+ bkg.attr("transform", "translate(-19, " + (spineY - 12 - labelPaddingY / 2) + ")");
1331
+ }
1332
+ });
1333
+ }, "drawBranches");
1334
+ var setBranchPosition = /* @__PURE__ */ __name(function(name, pos, index, bbox, rotateCommitLabel) {
1335
+ branchPos.set(name, { pos, index });
1336
+ pos += 50 + (rotateCommitLabel ? 40 : 0) + (dir === "TB" || dir === "BT" ? bbox.width / 2 : 0);
1337
+ return pos;
1338
+ }, "setBranchPosition");
1339
+ var draw = /* @__PURE__ */ __name(function(txt, id, ver, diagObj) {
1340
+ clear3();
1341
+ log.debug("in gitgraph renderer", txt + "\n", "id:", id, ver);
1342
+ const db2 = diagObj.db;
1343
+ if (!db2.getConfig) {
1344
+ log.error("getConfig method is not available on db");
1345
+ return;
1346
+ }
1347
+ const gitGraphConfig = db2.getConfig();
1348
+ const rotateCommitLabel = gitGraphConfig.rotateCommitLabel ?? false;
1349
+ allCommitsDict = db2.getCommits();
1350
+ const branches = db2.getBranchesAsObjArray();
1351
+ dir = db2.getDirection();
1352
+ const diagram2 = select_default(`[id="${id}"]`);
1353
+ const { look, theme, themeVariables } = getConfig2();
1354
+ const { useGradient, gradientStart, gradientStop, filterColor } = themeVariables;
1355
+ if (useGradient) {
1356
+ const gradient = diagram2.append("defs").append("linearGradient").attr("id", id + "-gradient").attr("gradientUnits", "objectBoundingBox").attr("x1", "0%").attr("y1", "0%").attr("x2", "100%").attr("y2", "0%");
1357
+ gradient.append("stop").attr("offset", "0%").attr("stop-color", gradientStart).attr("stop-opacity", 1);
1358
+ gradient.append("stop").attr("offset", "100%").attr("stop-color", gradientStop).attr("stop-opacity", 1);
1359
+ }
1360
+ if (look === "neo" && REDUX_GEOMETRY_THEMES.has(theme ?? "")) {
1361
+ diagram2.append("defs").append("filter").attr("id", id + "-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", filterColor);
1362
+ }
1363
+ let pos = 0;
1364
+ branches.forEach((branch2, index) => {
1365
+ const labelElement = drawText(branch2.name);
1366
+ const g = diagram2.append("g");
1367
+ const branchLabel = g.insert("g").attr("class", "branchLabel");
1368
+ const label = branchLabel.insert("g").attr("class", "label branch-label");
1369
+ label.node()?.appendChild(labelElement);
1370
+ const bbox = labelElement.getBBox();
1371
+ pos = setBranchPosition(branch2.name, pos, index, bbox, rotateCommitLabel);
1372
+ label.remove();
1373
+ branchLabel.remove();
1374
+ g.remove();
1375
+ });
1376
+ drawCommits(diagram2, allCommitsDict, false, gitGraphConfig);
1377
+ if (gitGraphConfig.showBranches) {
1378
+ drawBranches(diagram2, branches, gitGraphConfig, id);
1379
+ }
1380
+ drawArrows(diagram2, allCommitsDict);
1381
+ drawCommits(diagram2, allCommitsDict, true, gitGraphConfig);
1382
+ utils_default.insertTitle(
1383
+ diagram2,
1384
+ "gitTitleText",
1385
+ gitGraphConfig.titleTopMargin ?? 0,
1386
+ db2.getDiagramTitle()
1387
+ );
1388
+ setupGraphViewbox2(void 0, diagram2, gitGraphConfig.diagramPadding, gitGraphConfig.useMaxWidth);
1389
+ }, "draw");
1390
+ var gitGraphRenderer_default = {
1391
+ draw
1392
+ };
1393
+ if (void 0) {
1394
+ const { it, expect, describe } = void 0;
1395
+ describe("drawText", () => {
1396
+ it("should drawText", () => {
1397
+ const svgLabel = drawText("main");
1398
+ expect(svgLabel).toBeDefined();
1399
+ expect(svgLabel.children[0].innerHTML).toBe("main");
1400
+ });
1401
+ });
1402
+ describe("branchPosition", () => {
1403
+ const bbox = {
1404
+ x: 0,
1405
+ y: 0,
1406
+ width: 10,
1407
+ height: 10,
1408
+ top: 0,
1409
+ right: 0,
1410
+ bottom: 0,
1411
+ left: 0,
1412
+ toJSON: /* @__PURE__ */ __name(() => "", "toJSON")
1413
+ };
1414
+ it("should setBranchPositions LR with two branches", () => {
1415
+ dir = "LR";
1416
+ const pos = setBranchPosition("main", 0, 0, bbox, true);
1417
+ expect(pos).toBe(90);
1418
+ expect(branchPos.get("main")).toEqual({ pos: 0, index: 0 });
1419
+ const posNext = setBranchPosition("develop", pos, 1, bbox, true);
1420
+ expect(posNext).toBe(180);
1421
+ expect(branchPos.get("develop")).toEqual({ pos, index: 1 });
1422
+ });
1423
+ it("should setBranchPositions TB with two branches", () => {
1424
+ dir = "TB";
1425
+ bbox.width = 34.9921875;
1426
+ const pos = setBranchPosition("main", 0, 0, bbox, true);
1427
+ expect(pos).toBe(107.49609375);
1428
+ expect(branchPos.get("main")).toEqual({ pos: 0, index: 0 });
1429
+ bbox.width = 56.421875;
1430
+ const posNext = setBranchPosition("develop", pos, 1, bbox, true);
1431
+ expect(posNext).toBe(225.70703125);
1432
+ expect(branchPos.get("develop")).toEqual({ pos, index: 1 });
1433
+ });
1434
+ });
1435
+ describe("commitPosition", () => {
1436
+ const commits = /* @__PURE__ */ new Map([
1437
+ [
1438
+ "commitZero",
1439
+ {
1440
+ id: "ZERO",
1441
+ message: "",
1442
+ seq: 0,
1443
+ type: commitType.NORMAL,
1444
+ tags: [],
1445
+ parents: [],
1446
+ branch: "main"
1447
+ }
1448
+ ],
1449
+ [
1450
+ "commitA",
1451
+ {
1452
+ id: "A",
1453
+ message: "",
1454
+ seq: 1,
1455
+ type: commitType.NORMAL,
1456
+ tags: [],
1457
+ parents: ["ZERO"],
1458
+ branch: "feature"
1459
+ }
1460
+ ],
1461
+ [
1462
+ "commitB",
1463
+ {
1464
+ id: "B",
1465
+ message: "",
1466
+ seq: 2,
1467
+ type: commitType.NORMAL,
1468
+ tags: [],
1469
+ parents: ["A"],
1470
+ branch: "feature"
1471
+ }
1472
+ ],
1473
+ [
1474
+ "commitM",
1475
+ {
1476
+ id: "M",
1477
+ message: "merged branch feature into main",
1478
+ seq: 3,
1479
+ type: commitType.MERGE,
1480
+ tags: [],
1481
+ parents: ["ZERO", "B"],
1482
+ branch: "main",
1483
+ customId: true
1484
+ }
1485
+ ],
1486
+ [
1487
+ "commitC",
1488
+ {
1489
+ id: "C",
1490
+ message: "",
1491
+ seq: 4,
1492
+ type: commitType.NORMAL,
1493
+ tags: [],
1494
+ parents: ["ZERO"],
1495
+ branch: "release"
1496
+ }
1497
+ ],
1498
+ [
1499
+ "commit5_8928ea0",
1500
+ {
1501
+ id: "5-8928ea0",
1502
+ message: "cherry-picked [object Object] into release",
1503
+ seq: 5,
1504
+ type: commitType.CHERRY_PICK,
1505
+ tags: [],
1506
+ parents: ["C", "M"],
1507
+ branch: "release"
1508
+ }
1509
+ ],
1510
+ [
1511
+ "commitD",
1512
+ {
1513
+ id: "D",
1514
+ message: "",
1515
+ seq: 6,
1516
+ type: commitType.NORMAL,
1517
+ tags: [],
1518
+ parents: ["5-8928ea0"],
1519
+ branch: "release"
1520
+ }
1521
+ ],
1522
+ [
1523
+ "commit7_ed848ba",
1524
+ {
1525
+ id: "7-ed848ba",
1526
+ message: "cherry-picked [object Object] into release",
1527
+ seq: 7,
1528
+ type: commitType.CHERRY_PICK,
1529
+ tags: [],
1530
+ parents: ["D", "M"],
1531
+ branch: "release"
1532
+ }
1533
+ ]
1534
+ ]);
1535
+ let pos = 0;
1536
+ branchPos.set("main", { pos: 0, index: 0 });
1537
+ branchPos.set("feature", { pos: 107.49609375, index: 1 });
1538
+ branchPos.set("release", { pos: 224.03515625, index: 2 });
1539
+ describe("TB", () => {
1540
+ pos = 30;
1541
+ dir = "TB";
1542
+ const expectedCommitPositionTB = /* @__PURE__ */ new Map([
1543
+ ["commitZero", { x: 0, y: 40, posWithOffset: 40 }],
1544
+ ["commitA", { x: 107.49609375, y: 90, posWithOffset: 90 }],
1545
+ ["commitB", { x: 107.49609375, y: 140, posWithOffset: 140 }],
1546
+ ["commitM", { x: 0, y: 190, posWithOffset: 190 }],
1547
+ ["commitC", { x: 224.03515625, y: 240, posWithOffset: 240 }],
1548
+ ["commit5_8928ea0", { x: 224.03515625, y: 290, posWithOffset: 290 }],
1549
+ ["commitD", { x: 224.03515625, y: 340, posWithOffset: 340 }],
1550
+ ["commit7_ed848ba", { x: 224.03515625, y: 390, posWithOffset: 390 }]
1551
+ ]);
1552
+ commits.forEach((commit2, key) => {
1553
+ it(`should give the correct position for commit ${key}`, () => {
1554
+ const position = getCommitPosition(commit2, pos, false);
1555
+ expect(position).toEqual(expectedCommitPositionTB.get(key));
1556
+ pos += 50;
1557
+ });
1558
+ });
1559
+ });
1560
+ describe("LR", () => {
1561
+ let pos2 = 30;
1562
+ dir = "LR";
1563
+ const expectedCommitPositionLR = /* @__PURE__ */ new Map([
1564
+ ["commitZero", { x: 0, y: 40, posWithOffset: 40 }],
1565
+ ["commitA", { x: 107.49609375, y: 90, posWithOffset: 90 }],
1566
+ ["commitB", { x: 107.49609375, y: 140, posWithOffset: 140 }],
1567
+ ["commitM", { x: 0, y: 190, posWithOffset: 190 }],
1568
+ ["commitC", { x: 224.03515625, y: 240, posWithOffset: 240 }],
1569
+ ["commit5_8928ea0", { x: 224.03515625, y: 290, posWithOffset: 290 }],
1570
+ ["commitD", { x: 224.03515625, y: 340, posWithOffset: 340 }],
1571
+ ["commit7_ed848ba", { x: 224.03515625, y: 390, posWithOffset: 390 }]
1572
+ ]);
1573
+ commits.forEach((commit2, key) => {
1574
+ it(`should give the correct position for commit ${key}`, () => {
1575
+ const position = getCommitPosition(commit2, pos2, false);
1576
+ expect(position).toEqual(expectedCommitPositionLR.get(key));
1577
+ pos2 += 50;
1578
+ });
1579
+ });
1580
+ });
1581
+ describe("getCommitClassType", () => {
1582
+ const expectedCommitClassType = /* @__PURE__ */ new Map([
1583
+ ["commitZero", "commit-normal"],
1584
+ ["commitA", "commit-normal"],
1585
+ ["commitB", "commit-normal"],
1586
+ ["commitM", "commit-merge"],
1587
+ ["commitC", "commit-normal"],
1588
+ ["commit5_8928ea0", "commit-cherry-pick"],
1589
+ ["commitD", "commit-normal"],
1590
+ ["commit7_ed848ba", "commit-cherry-pick"]
1591
+ ]);
1592
+ commits.forEach((commit2, key) => {
1593
+ it(`should give the correct class type for commit ${key}`, () => {
1594
+ const classType = getCommitClassType(commit2);
1595
+ expect(classType).toBe(expectedCommitClassType.get(key));
1596
+ });
1597
+ });
1598
+ });
1599
+ });
1600
+ describe("building BT parallel commit diagram", () => {
1601
+ const commits = /* @__PURE__ */ new Map([
1602
+ [
1603
+ "1-abcdefg",
1604
+ {
1605
+ id: "1-abcdefg",
1606
+ message: "",
1607
+ seq: 0,
1608
+ type: 0,
1609
+ tags: [],
1610
+ parents: [],
1611
+ branch: "main"
1612
+ }
1613
+ ],
1614
+ [
1615
+ "2-abcdefg",
1616
+ {
1617
+ id: "2-abcdefg",
1618
+ message: "",
1619
+ seq: 1,
1620
+ type: 0,
1621
+ tags: [],
1622
+ parents: ["1-abcdefg"],
1623
+ branch: "main"
1624
+ }
1625
+ ],
1626
+ [
1627
+ "3-abcdefg",
1628
+ {
1629
+ id: "3-abcdefg",
1630
+ message: "",
1631
+ seq: 2,
1632
+ type: 0,
1633
+ tags: [],
1634
+ parents: ["2-abcdefg"],
1635
+ branch: "develop"
1636
+ }
1637
+ ],
1638
+ [
1639
+ "4-abcdefg",
1640
+ {
1641
+ id: "4-abcdefg",
1642
+ message: "",
1643
+ seq: 3,
1644
+ type: 0,
1645
+ tags: [],
1646
+ parents: ["3-abcdefg"],
1647
+ branch: "develop"
1648
+ }
1649
+ ],
1650
+ [
1651
+ "5-abcdefg",
1652
+ {
1653
+ id: "5-abcdefg",
1654
+ message: "",
1655
+ seq: 4,
1656
+ type: 0,
1657
+ tags: [],
1658
+ parents: ["2-abcdefg"],
1659
+ branch: "feature"
1660
+ }
1661
+ ],
1662
+ [
1663
+ "6-abcdefg",
1664
+ {
1665
+ id: "6-abcdefg",
1666
+ message: "",
1667
+ seq: 5,
1668
+ type: 0,
1669
+ tags: [],
1670
+ parents: ["5-abcdefg"],
1671
+ branch: "feature"
1672
+ }
1673
+ ],
1674
+ [
1675
+ "7-abcdefg",
1676
+ {
1677
+ id: "7-abcdefg",
1678
+ message: "",
1679
+ seq: 6,
1680
+ type: 0,
1681
+ tags: [],
1682
+ parents: ["2-abcdefg"],
1683
+ branch: "main"
1684
+ }
1685
+ ],
1686
+ [
1687
+ "8-abcdefg",
1688
+ {
1689
+ id: "8-abcdefg",
1690
+ message: "",
1691
+ seq: 7,
1692
+ type: 0,
1693
+ tags: [],
1694
+ parents: ["7-abcdefg"],
1695
+ branch: "main"
1696
+ }
1697
+ ]
1698
+ ]);
1699
+ const expectedCommitPosition = /* @__PURE__ */ new Map([
1700
+ ["1-abcdefg", { x: 0, y: 40 }],
1701
+ ["2-abcdefg", { x: 0, y: 90 }],
1702
+ ["3-abcdefg", { x: 107.49609375, y: 140 }],
1703
+ ["4-abcdefg", { x: 107.49609375, y: 190 }],
1704
+ ["5-abcdefg", { x: 225.70703125, y: 140 }],
1705
+ ["6-abcdefg", { x: 225.70703125, y: 190 }],
1706
+ ["7-abcdefg", { x: 0, y: 140 }],
1707
+ ["8-abcdefg", { x: 0, y: 190 }]
1708
+ ]);
1709
+ const expectedCommitPositionAfterParallel = /* @__PURE__ */ new Map([
1710
+ ["1-abcdefg", { x: 0, y: 210 }],
1711
+ ["2-abcdefg", { x: 0, y: 160 }],
1712
+ ["3-abcdefg", { x: 107.49609375, y: 110 }],
1713
+ ["4-abcdefg", { x: 107.49609375, y: 60 }],
1714
+ ["5-abcdefg", { x: 225.70703125, y: 110 }],
1715
+ ["6-abcdefg", { x: 225.70703125, y: 60 }],
1716
+ ["7-abcdefg", { x: 0, y: 110 }],
1717
+ ["8-abcdefg", { x: 0, y: 60 }]
1718
+ ]);
1719
+ const expectedCommitCurrentPosition = /* @__PURE__ */ new Map([
1720
+ ["1-abcdefg", 30],
1721
+ ["2-abcdefg", 80],
1722
+ ["3-abcdefg", 130],
1723
+ ["4-abcdefg", 180],
1724
+ ["5-abcdefg", 130],
1725
+ ["6-abcdefg", 180],
1726
+ ["7-abcdefg", 130],
1727
+ ["8-abcdefg", 180]
1728
+ ]);
1729
+ const sortedKeys = [...expectedCommitPosition.keys()];
1730
+ it("should get the correct commit position and current position", () => {
1731
+ dir = "BT";
1732
+ let curPos = 30;
1733
+ commitPos.clear();
1734
+ branchPos.clear();
1735
+ branchPos.set("main", { pos: 0, index: 0 });
1736
+ branchPos.set("develop", { pos: 107.49609375, index: 1 });
1737
+ branchPos.set("feature", { pos: 225.70703125, index: 2 });
1738
+ commits.forEach((commit2, key) => {
1739
+ if (commit2.parents.length > 0) {
1740
+ curPos = calculateCommitPosition(commit2);
1741
+ }
1742
+ const position = setCommitPosition(commit2, curPos);
1743
+ expect(position).toEqual(expectedCommitPosition.get(key));
1744
+ expect(curPos).toEqual(expectedCommitCurrentPosition.get(key));
1745
+ });
1746
+ });
1747
+ it("should get the correct commit position after parallel commits", () => {
1748
+ commitPos.clear();
1749
+ branchPos.clear();
1750
+ dir = "BT";
1751
+ const curPos = 30;
1752
+ commitPos.clear();
1753
+ branchPos.clear();
1754
+ branchPos.set("main", { pos: 0, index: 0 });
1755
+ branchPos.set("develop", { pos: 107.49609375, index: 1 });
1756
+ branchPos.set("feature", { pos: 225.70703125, index: 2 });
1757
+ setParallelBTPos(sortedKeys, commits, curPos);
1758
+ sortedKeys.forEach((commit2) => {
1759
+ const position = commitPos.get(commit2);
1760
+ expect(position).toEqual(expectedCommitPositionAfterParallel.get(commit2));
1761
+ });
1762
+ });
1763
+ });
1764
+ it("add", () => {
1765
+ commitPos.set("parent1", { x: 1, y: 1 });
1766
+ commitPos.set("parent2", { x: 2, y: 2 });
1767
+ commitPos.set("parent3", { x: 3, y: 3 });
1768
+ dir = "LR";
1769
+ const parents = ["parent1", "parent2", "parent3"];
1770
+ const closestParent = findClosestParent(parents);
1771
+ expect(closestParent).toBe("parent3");
1772
+ commitPos.clear();
1773
+ });
1774
+ }
1775
+ var GIT_NAMED_COLOR_COUNT = 8;
1776
+ var REDUX_GEOMETRY_THEMES2 = /* @__PURE__ */ new Set(["redux", "redux-dark", "redux-color", "redux-dark-color"]);
1777
+ var COLOR_THEMES2 = /* @__PURE__ */ new Set(["redux-color", "redux-dark-color"]);
1778
+ var NEO_THEMES = /* @__PURE__ */ new Set(["neo", "neo-dark"]);
1779
+ var DARK_THEMES2 = /* @__PURE__ */ new Set(["dark", "redux-dark", "redux-dark-color", "neo-dark"]);
1780
+ var NEO_COLOR_GEN_THEMES = /* @__PURE__ */ new Set([
1781
+ "redux",
1782
+ "redux-dark",
1783
+ "redux-color",
1784
+ "redux-dark-color",
1785
+ "neo",
1786
+ "neo-dark"
1787
+ ]);
1788
+ var genGitGraphGradient = /* @__PURE__ */ __name((options) => {
1789
+ const { svgId } = options;
1790
+ let sections = "";
1791
+ if (options.useGradient && svgId) {
1792
+ for (let i = 0; i < options.THEME_COLOR_LIMIT; i++) {
1793
+ sections += `
1794
+ .label${i} { fill: ${options.mainBkg}; stroke: url(${svgId}-gradient); stroke-width: ${options.strokeWidth};}
1795
+ `;
1796
+ }
1797
+ }
1798
+ return sections;
1799
+ }, "genGitGraphGradient");
1800
+ var genColor = /* @__PURE__ */ __name((options) => {
1801
+ const config = getConfig();
1802
+ const { theme, themeVariables } = config;
1803
+ const { borderColorArray } = themeVariables;
1804
+ const useReduxGeometry = REDUX_GEOMETRY_THEMES2.has(theme);
1805
+ if (NEO_THEMES.has(theme)) {
1806
+ let sections = "";
1807
+ for (let i = 0; i < options.THEME_COLOR_LIMIT; i++) {
1808
+ if (i === 0) {
1809
+ sections += `
1810
+ .branch-label${i} { fill: ${options.nodeBorder};}
1811
+ .commit${i} { stroke: ${options.nodeBorder}; }
1812
+ .commit-highlight${i} { stroke: ${options.nodeBorder}; fill: ${options.nodeBorder}; }
1813
+ .arrow${i} { stroke: ${options.nodeBorder}; }
1814
+ .commit-bullets { fill: ${options.nodeBorder}; }
1815
+ .commit-cherry-pick${i} { stroke: ${options.nodeBorder}; }
1816
+ ${genGitGraphGradient(options)}`;
1817
+ } else {
1818
+ const ci = i % GIT_NAMED_COLOR_COUNT;
1819
+ sections += `
1820
+ .branch-label${i} { fill: ${options["gitBranchLabel" + ci]}; }
1821
+ .commit${i} { stroke: ${options["git" + ci]}; fill: ${options["git" + ci]}; }
1822
+ .commit-highlight${i} { stroke: ${options["gitInv" + ci]}; fill: ${options["gitInv" + ci]}; }
1823
+ .arrow${i} { stroke: ${options["git" + ci]}; }
1824
+ `;
1825
+ }
1826
+ }
1827
+ return sections;
1828
+ } else if (!COLOR_THEMES2.has(theme)) {
1829
+ let sections = "";
1830
+ for (let i = 0; i < options.THEME_COLOR_LIMIT; i++) {
1831
+ sections += `
1832
+ .branch-label${i} { fill: ${options.nodeBorder}; ${useReduxGeometry ? `font-weight:${options.noteFontWeight}` : ""} }
1833
+ .commit${i} { stroke: ${options.nodeBorder}; }
1834
+ .commit-highlight${i} { stroke: ${options.nodeBorder}; fill: ${options.nodeBorder}; }
1835
+ .label${i} { fill: ${options.mainBkg}; stroke: ${options.nodeBorder}; stroke-width: ${options.strokeWidth}; ${useReduxGeometry ? `font-weight:${options.noteFontWeight}` : ""}}
1836
+ .arrow${i} { stroke: ${options.nodeBorder}; }
1837
+ .commit-bullets { fill: ${options.nodeBorder}; }
1838
+ .commit-cherry-pick${i} { stroke: ${options.nodeBorder}; }
1839
+ `;
1840
+ }
1841
+ return sections;
1842
+ } else {
1843
+ let sections = "";
1844
+ for (let i = 0; i < options.THEME_COLOR_LIMIT; i++) {
1845
+ if (i === 0) {
1846
+ sections += `
1847
+ .branch-label${i} { fill: ${options.nodeBorder}; ${useReduxGeometry ? `font-weight:${options.noteFontWeight}` : ""} }
1848
+ .commit${i} { stroke: ${options.nodeBorder}; }
1849
+ .commit-highlight${i} { stroke: ${options.nodeBorder}; fill: ${options.mainBkg}; }
1850
+ .label${i} { fill: ${options.mainBkg}; stroke: ${options.nodeBorder}; stroke-width: ${options.strokeWidth}; ${useReduxGeometry ? `font-weight:${options.noteFontWeight}` : ""} }
1851
+ .arrow${i} { stroke: ${options.nodeBorder}; }
1852
+ .commit-bullets { fill: ${options.nodeBorder}; }
1853
+ `;
1854
+ } else {
1855
+ const colorIndex = i % borderColorArray.length;
1856
+ sections += `
1857
+ .branch-label${i} { fill: ${options.nodeBorder}; ${useReduxGeometry ? `font-weight:${options.noteFontWeight}` : ""} }
1858
+ .commit${i} { stroke: ${borderColorArray[colorIndex]}; fill: ${borderColorArray[colorIndex]}; }
1859
+ .commit-highlight${i} { stroke: ${borderColorArray[colorIndex]}; fill: ${borderColorArray[colorIndex]}; }
1860
+ .label${i} { fill: ${DARK_THEMES2.has(theme) ? options.mainBkg : borderColorArray[colorIndex]}; stroke: ${borderColorArray[colorIndex]}; stroke-width: ${options.strokeWidth}; }
1861
+ .arrow${i} { stroke: ${borderColorArray[colorIndex]}; }
1862
+ `;
1863
+ }
1864
+ }
1865
+ return sections;
1866
+ }
1867
+ }, "genColor");
1868
+ var normalTheme = /* @__PURE__ */ __name((options) => {
1869
+ return `${Array.from({ length: options.THEME_COLOR_LIMIT }, (_, i) => i).map((i) => {
1870
+ const ci = i % GIT_NAMED_COLOR_COUNT;
1871
+ return `
1872
+ .branch-label${i} { fill: ${options["gitBranchLabel" + ci]}; }
1873
+ .commit${i} { stroke: ${options["git" + ci]}; fill: ${options["git" + ci]}; }
1874
+ .commit-highlight${i} { stroke: ${options["gitInv" + ci]}; fill: ${options["gitInv" + ci]}; }
1875
+ .label${i} { fill: ${options["git" + ci]}; }
1876
+ .arrow${i} { stroke: ${options["git" + ci]}; }
1877
+ `;
1878
+ }).join("\n")}`;
1879
+ }, "normalTheme");
1880
+ var getStyles = /* @__PURE__ */ __name((options) => {
1881
+ const config = getConfig();
1882
+ const { theme } = config;
1883
+ const useNeoColorGen = NEO_COLOR_GEN_THEMES.has(theme);
1884
+ return `
1885
+ .commit-id,
1886
+ .commit-msg,
1887
+ .branch-label {
1888
+ fill: lightgrey;
1889
+ color: lightgrey;
1890
+ font-family: 'trebuchet ms', verdana, arial, sans-serif;
1891
+ font-family: var(--mermaid-font-family);
1892
+ }
1893
+
1894
+ ${useNeoColorGen ? genColor(options) : normalTheme(options)}
1895
+
1896
+ .branch {
1897
+ stroke-width: ${options.strokeWidth};
1898
+ stroke: ${options.commitLineColor ?? options.lineColor};
1899
+ stroke-dasharray: ${useNeoColorGen ? "4 2" : "2"};
1900
+ }
1901
+ .commit-label { font-size: ${options.commitLabelFontSize}; fill: ${useNeoColorGen ? options.nodeBorder : options.commitLabelColor}; ${useNeoColorGen ? `font-weight:${options.noteFontWeight};` : ""}}
1902
+ .commit-label-bkg { font-size: ${options.commitLabelFontSize}; fill: ${useNeoColorGen ? "transparent" : options.commitLabelBackground}; opacity: ${useNeoColorGen ? "" : 0.5}; }
1903
+ .tag-label { font-size: ${options.tagLabelFontSize}; fill: ${options.tagLabelColor};}
1904
+ .tag-label-bkg { fill: ${useNeoColorGen ? options.mainBkg : options.tagLabelBackground}; stroke: ${useNeoColorGen ? options.nodeBorder : options.tagLabelBorder}; ${useNeoColorGen ? `filter:${options.dropShadow}` : ""} }
1905
+ .tag-hole { fill: ${options.textColor}; }
1906
+
1907
+ .commit-merge {
1908
+ stroke: ${useNeoColorGen ? options.mainBkg : options.primaryColor};
1909
+ fill: ${useNeoColorGen ? options.mainBkg : options.primaryColor};
1910
+ }
1911
+ .commit-reverse {
1912
+ stroke: ${useNeoColorGen ? options.mainBkg : options.primaryColor};
1913
+ fill: ${useNeoColorGen ? options.mainBkg : options.primaryColor};
1914
+ stroke-width: ${useNeoColorGen ? options.strokeWidth : 3};
1915
+ }
1916
+ .commit-highlight-outer {
1917
+ }
1918
+ .commit-highlight-inner {
1919
+ stroke: ${useNeoColorGen ? options.mainBkg : options.primaryColor};
1920
+ fill: ${useNeoColorGen ? options.mainBkg : options.primaryColor};
1921
+ }
1922
+
1923
+ .arrow {
1924
+ /* Intentional: neo themes keep the bold 8px arrow (like classic themes); only redux-geometry themes use the thinner options.strokeWidth. */
1925
+ stroke-width: ${REDUX_GEOMETRY_THEMES2.has(theme) ? options.strokeWidth : 8};
1926
+ stroke-linecap: round;
1927
+ fill: none
1928
+ }
1929
+ .gitTitleText {
1930
+ text-anchor: middle;
1931
+ font-size: 18px;
1932
+ fill: ${options.textColor};
1933
+ }
1934
+ `;
1935
+ }, "getStyles");
1936
+ var styles_default = getStyles;
1937
+ var diagram = {
1938
+ parser,
1939
+ db,
1940
+ renderer: gitGraphRenderer_default,
1941
+ styles: styles_default
1942
+ };
1943
+ export {
1944
+ diagram
1945
+ };
1946
+ //# sourceMappingURL=gitGraphDiagram-UUTBAWPF-M4VV3YVA.js.map