@fengwk/kchart 0.0.0-stage → 0.1.1

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 (201) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +21 -0
  3. package/NOTICE.md +11 -0
  4. package/README.md +68 -2
  5. package/README.zh-CN.md +69 -0
  6. package/dist/LICENSE +21 -0
  7. package/dist/NOTICE.md +11 -0
  8. package/dist/assets/ICONS-LICENSE.txt +53 -0
  9. package/dist/assets/maps/LICENSE.md +75 -0
  10. package/dist/assets/maps/METADATA.md +9 -0
  11. package/dist/assets/maps/REGIONS.md +28 -0
  12. package/dist/assets/maps/us-states.geojson +1 -0
  13. package/dist/assets/maps/world.geojson +1 -0
  14. package/dist/esm/_virtual/_kchart-families.js +48 -0
  15. package/dist/esm/_virtual/_rolldown/runtime.js +12 -0
  16. package/dist/esm/assets/icons.js +11 -0
  17. package/dist/esm/assets/maps/us-states.js +3 -0
  18. package/dist/esm/assets/maps/world.js +3 -0
  19. package/dist/esm/assets/themes/claude.js +69 -0
  20. package/dist/esm/assets/themes/cloudmusic.js +62 -0
  21. package/dist/esm/assets/themes/kanagawa.js +67 -0
  22. package/dist/esm/assets/themes/obsidian.js +67 -0
  23. package/dist/esm/assets/themes/paper.js +61 -0
  24. package/dist/esm/assets/themes/terminal.js +60 -0
  25. package/dist/esm/assets/themes/tokyo.js +62 -0
  26. package/dist/esm/chart/basic.js +1313 -0
  27. package/dist/esm/chart/catalog.js +476 -0
  28. package/dist/esm/chart/composition.js +844 -0
  29. package/dist/esm/chart/context.js +189 -0
  30. package/dist/esm/chart/distribution.js +442 -0
  31. package/dist/esm/chart/fields.js +67 -0
  32. package/dist/esm/chart/maps.js +563 -0
  33. package/dist/esm/chart/mindmap.js +629 -0
  34. package/dist/esm/chart/multivariate.js +1229 -0
  35. package/dist/esm/chart/registry.js +108 -0
  36. package/dist/esm/chart/relations.js +949 -0
  37. package/dist/esm/chart/spec.js +1415 -0
  38. package/dist/esm/chart/stat-compare.js +302 -0
  39. package/dist/esm/chart/stat-trend.js +181 -0
  40. package/dist/esm/chart/statistics.js +1007 -0
  41. package/dist/esm/chart/unit-variants.js +645 -0
  42. package/dist/esm/chart/variants.js +552 -0
  43. package/dist/esm/core/color.js +197 -0
  44. package/dist/esm/core/context.js +256 -0
  45. package/dist/esm/core/diagnostics.js +23 -0
  46. package/dist/esm/core/format.js +167 -0
  47. package/dist/esm/core/geometry.js +130 -0
  48. package/dist/esm/core/icon-data.js +5 -0
  49. package/dist/esm/core/icons.js +173 -0
  50. package/dist/esm/core/scale.js +112 -0
  51. package/dist/esm/core/scene.js +234 -0
  52. package/dist/esm/core/svg.js +89 -0
  53. package/dist/esm/core/text.js +184 -0
  54. package/dist/esm/core/theme.js +318 -0
  55. package/dist/esm/diagram/agentflow.js +596 -0
  56. package/dist/esm/diagram/architecture.js +729 -0
  57. package/dist/esm/diagram/block.js +988 -0
  58. package/dist/esm/diagram/blocks.js +687 -0
  59. package/dist/esm/diagram/c4.js +1002 -0
  60. package/dist/esm/diagram/class.js +1158 -0
  61. package/dist/esm/diagram/cynefin.js +749 -0
  62. package/dist/esm/diagram/emphasis.js +7 -0
  63. package/dist/esm/diagram/er.js +657 -0
  64. package/dist/esm/diagram/eventmodeling.js +948 -0
  65. package/dist/esm/diagram/gantt-date.js +323 -0
  66. package/dist/esm/diagram/gantt.js +661 -0
  67. package/dist/esm/diagram/gitgraph.js +472 -0
  68. package/dist/esm/diagram/graph-layout.js +4046 -0
  69. package/dist/esm/diagram/graph-parse.js +1366 -0
  70. package/dist/esm/diagram/graph-route.js +490 -0
  71. package/dist/esm/diagram/graph.js +553 -0
  72. package/dist/esm/diagram/ishikawa.js +496 -0
  73. package/dist/esm/diagram/journey.js +512 -0
  74. package/dist/esm/diagram/kanban.js +280 -0
  75. package/dist/esm/diagram/label.js +56 -0
  76. package/dist/esm/diagram/layers.js +385 -0
  77. package/dist/esm/diagram/map-label.js +44 -0
  78. package/dist/esm/diagram/mindmap.js +277 -0
  79. package/dist/esm/diagram/numeric-composition.js +78 -0
  80. package/dist/esm/diagram/numeric-model.js +86 -0
  81. package/dist/esm/diagram/numeric-parse.js +205 -0
  82. package/dist/esm/diagram/numeric-radar.js +355 -0
  83. package/dist/esm/diagram/numeric-sankey.js +201 -0
  84. package/dist/esm/diagram/numeric-xy.js +422 -0
  85. package/dist/esm/diagram/packet.js +175 -0
  86. package/dist/esm/diagram/presentation.js +252 -0
  87. package/dist/esm/diagram/quadrant.js +297 -0
  88. package/dist/esm/diagram/railroad-parse.js +465 -0
  89. package/dist/esm/diagram/railroad.js +294 -0
  90. package/dist/esm/diagram/registry.js +296 -0
  91. package/dist/esm/diagram/relations.js +966 -0
  92. package/dist/esm/diagram/requirement.js +341 -0
  93. package/dist/esm/diagram/sequence.js +1228 -0
  94. package/dist/esm/diagram/shapes.js +366 -0
  95. package/dist/esm/diagram/source.js +538 -0
  96. package/dist/esm/diagram/support.js +153 -0
  97. package/dist/esm/diagram/swimlane-mermaid.js +140 -0
  98. package/dist/esm/diagram/swimlane.js +1186 -0
  99. package/dist/esm/diagram/time.js +748 -0
  100. package/dist/esm/diagram/timeline.js +376 -0
  101. package/dist/esm/diagram/tree-family-icon.js +22 -0
  102. package/dist/esm/diagram/treeview.js +293 -0
  103. package/dist/esm/diagram/usecase.js +852 -0
  104. package/dist/esm/diagram/venn.js +1038 -0
  105. package/dist/esm/diagram/wardley.js +838 -0
  106. package/dist/esm/index.d.ts +133 -0
  107. package/dist/esm/index.js +92 -0
  108. package/dist/esm/interaction.js +561 -0
  109. package/dist/esm/mermaid.d.ts +28 -0
  110. package/dist/esm/mermaid.js +70 -0
  111. package/dist/esm/node.d.ts +68 -0
  112. package/dist/esm/node.js +373 -0
  113. package/dist/esm/package.json +1 -0
  114. package/dist/esm/page-api.js +65 -0
  115. package/dist/esm/runtime.js +352 -0
  116. package/dist/esm/src/families.js +209 -0
  117. package/dist/page-api.js +1 -0
  118. package/dist/units/chart/basic.js +1 -0
  119. package/dist/units/chart/catalog.js +1 -0
  120. package/dist/units/chart/composition.js +1 -0
  121. package/dist/units/chart/context.js +1 -0
  122. package/dist/units/chart/distribution.js +1 -0
  123. package/dist/units/chart/fields.js +1 -0
  124. package/dist/units/chart/maps.js +1 -0
  125. package/dist/units/chart/mindmap.js +1 -0
  126. package/dist/units/chart/multivariate.js +1 -0
  127. package/dist/units/chart/registry.js +1 -0
  128. package/dist/units/chart/relations.js +1 -0
  129. package/dist/units/chart/spec.js +3 -0
  130. package/dist/units/chart/stat-compare.js +1 -0
  131. package/dist/units/chart/stat-trend.js +1 -0
  132. package/dist/units/chart/statistics.js +1 -0
  133. package/dist/units/chart/unit-variants.js +1 -0
  134. package/dist/units/chart/variants.js +1 -0
  135. package/dist/units/core/color.js +1 -0
  136. package/dist/units/core/context.js +1 -0
  137. package/dist/units/core/diagnostics.js +1 -0
  138. package/dist/units/core/format.js +1 -0
  139. package/dist/units/core/geometry.js +1 -0
  140. package/dist/units/core/icon-data.js +1 -0
  141. package/dist/units/core/icons.js +1 -0
  142. package/dist/units/core/scale.js +1 -0
  143. package/dist/units/core/scene.js +1 -0
  144. package/dist/units/core/svg.js +1 -0
  145. package/dist/units/core/text.js +2 -0
  146. package/dist/units/core/theme.js +1 -0
  147. package/dist/units/diagram/agentflow.js +12 -0
  148. package/dist/units/diagram/architecture.js +4 -0
  149. package/dist/units/diagram/block.js +2 -0
  150. package/dist/units/diagram/blocks.js +2 -0
  151. package/dist/units/diagram/c4.js +6 -0
  152. package/dist/units/diagram/class.js +5 -0
  153. package/dist/units/diagram/cynefin.js +4 -0
  154. package/dist/units/diagram/emphasis.js +1 -0
  155. package/dist/units/diagram/er.js +9 -0
  156. package/dist/units/diagram/eventmodeling.js +5 -0
  157. package/dist/units/diagram/gantt-date.js +1 -0
  158. package/dist/units/diagram/gantt.js +3 -0
  159. package/dist/units/diagram/gitgraph.js +2 -0
  160. package/dist/units/diagram/graph-layout.js +4 -0
  161. package/dist/units/diagram/graph-parse.js +9 -0
  162. package/dist/units/diagram/graph-route.js +1 -0
  163. package/dist/units/diagram/graph.js +1 -0
  164. package/dist/units/diagram/ishikawa.js +2 -0
  165. package/dist/units/diagram/journey.js +5 -0
  166. package/dist/units/diagram/kanban.js +2 -0
  167. package/dist/units/diagram/label.js +4 -0
  168. package/dist/units/diagram/layers.js +1 -0
  169. package/dist/units/diagram/map-label.js +1 -0
  170. package/dist/units/diagram/mindmap.js +2 -0
  171. package/dist/units/diagram/numeric-composition.js +1 -0
  172. package/dist/units/diagram/numeric-model.js +1 -0
  173. package/dist/units/diagram/numeric-parse.js +2 -0
  174. package/dist/units/diagram/numeric-radar.js +3 -0
  175. package/dist/units/diagram/numeric-sankey.js +2 -0
  176. package/dist/units/diagram/numeric-xy.js +2 -0
  177. package/dist/units/diagram/packet.js +2 -0
  178. package/dist/units/diagram/presentation.js +2 -0
  179. package/dist/units/diagram/quadrant.js +2 -0
  180. package/dist/units/diagram/railroad-parse.js +4 -0
  181. package/dist/units/diagram/railroad.js +1 -0
  182. package/dist/units/diagram/registry.js +2 -0
  183. package/dist/units/diagram/relations.js +3 -0
  184. package/dist/units/diagram/requirement.js +3 -0
  185. package/dist/units/diagram/sequence.js +2 -0
  186. package/dist/units/diagram/shapes.js +60 -0
  187. package/dist/units/diagram/source.js +20 -0
  188. package/dist/units/diagram/support.js +3 -0
  189. package/dist/units/diagram/swimlane-mermaid.js +3 -0
  190. package/dist/units/diagram/swimlane.js +2 -0
  191. package/dist/units/diagram/time.js +3 -0
  192. package/dist/units/diagram/timeline.js +2 -0
  193. package/dist/units/diagram/tree-family-icon.js +1 -0
  194. package/dist/units/diagram/treeview.js +2 -0
  195. package/dist/units/diagram/usecase.js +3 -0
  196. package/dist/units/diagram/venn.js +2 -0
  197. package/dist/units/diagram/wardley.js +4 -0
  198. package/dist/units/interaction.js +1 -0
  199. package/dist/units/runtime.js +1 -0
  200. package/dist/units.json +712 -0
  201. package/package.json +30 -4
@@ -0,0 +1,472 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
+ import { normalizeLabel } from "./label.js";
3
+ import { presentation } from "./presentation.js";
4
+ import { FONT, appearance, error, textBlock, warning } from "./support.js";
5
+ // src/diagram/gitgraph.js
6
+ var gitgraph_exports = /* @__PURE__ */ __exportAll({ implementations: () => implementations });
7
+ var optionMode = "raw";
8
+ var honoredConfig = [
9
+ "showBranches",
10
+ "showCommitLabel",
11
+ "mainBranchName",
12
+ "mainBranchOrder",
13
+ "parallelCommits",
14
+ "diagramPadding",
15
+ "titleTopMargin",
16
+ "rotateCommitLabel"
17
+ ].map((key) => `gitGraph.${key}`);
18
+ var quoted = /^(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')$/;
19
+ var valueOf = (token) => quoted.test(token) ? token.slice(1, -1).replace(/\\(.)/g, "$1") : token;
20
+ var ref = (token) => token && (quoted.test(token) || /^\w(?:[-./\w]*[-\w])?$/.test(token));
21
+ function attributes(command, tokens) {
22
+ const attrs = { tags: [] };
23
+ const allowed = {
24
+ commit: [
25
+ "id",
26
+ "msg",
27
+ "type",
28
+ "tag"
29
+ ],
30
+ merge: [
31
+ "id",
32
+ "type",
33
+ "tag"
34
+ ],
35
+ "cherry-pick": [
36
+ "id",
37
+ "parent",
38
+ "tag"
39
+ ]
40
+ }[command];
41
+ for (let i = 0; i < tokens.length;) {
42
+ const key = quoted.test(tokens[i]) ? "msg" : tokens[i++];
43
+ if (!allowed.includes(key)) return null;
44
+ if (tokens[i] === ":") i++;
45
+ else if (key !== "msg") return null;
46
+ const val = tokens[i++];
47
+ if (key === "type" ? ![
48
+ "NORMAL",
49
+ "REVERSE",
50
+ "HIGHLIGHT"
51
+ ].includes(val) : !quoted.test(val ?? "")) return null;
52
+ if (key === "tag") attrs.tags.push(valueOf(val));
53
+ else attrs[key] = valueOf(val);
54
+ }
55
+ return attrs;
56
+ }
57
+ function parse(body, { lang, firstLine = 2, headerLine = firstLine - 1, title = "", params = "", config }) {
58
+ const errors = [], commits = [], byId = /* @__PURE__ */ new Map(), assets = /* @__PURE__ */ new Set(), duplicateIds = /* @__PURE__ */ new Set();
59
+ const look = presentation({ lang });
60
+ const clean = (value, line) => {
61
+ const { text, icon, diagnostics } = normalizeLabel(value, {
62
+ lang,
63
+ line
64
+ });
65
+ if (icon) diagnostics.push(warning("IGNORED_ASSET", lang, line, "Git 标签仅显示文本", "Git labels display text only"));
66
+ for (const d of diagnostics) if (!assets.has(d.message)) {
67
+ assets.add(d.message);
68
+ errors.push(d);
69
+ }
70
+ return text;
71
+ };
72
+ config = config?.gitGraph || {};
73
+ const main = typeof config.mainBranchName === "string" && config.mainBranchName || "main";
74
+ const branches = /* @__PURE__ */ new Map([[main, {
75
+ name: main,
76
+ label: clean(main, headerLine),
77
+ order: Number(config.mainBranchOrder) || 0
78
+ }]]);
79
+ let current = branches.get(main);
80
+ const fail = (line, zh, en) => errors.push(error(lang, line, zh, en, "修正提交或分支声明", "Fix the commit or branch declaration"));
81
+ const direction = /^(?:(LR|TB|BT)\s*:|:)?$/i.exec(params);
82
+ if (!direction) fail(headerLine, "方向必须为 LR:、TB: 或 BT:", "Expected header direction LR:, TB: or BT:");
83
+ if (config.rotateCommitLabel === true) errors.push(warning("IGNORED_CONFIG", lang, headerLine, "提交标签保持水平", "Commit labels remain horizontal", "无需旋转设置", "Remove the rotation setting"));
84
+ let branchIndex = 0;
85
+ for (const [i, raw] of body.split("\n").entries()) {
86
+ const s = raw.trim(), line = firstLine + i;
87
+ if (!s || s.startsWith("%%") || look.accept(s, line)) continue;
88
+ const heading = /^title(?:\s*:\s*|\s+)(.+)/i.exec(s);
89
+ if (heading) {
90
+ title = clean(heading[1], line);
91
+ continue;
92
+ }
93
+ const tokens = [];
94
+ for (const [token] of s.matchAll(/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|%%.*|:|[^\s:"']+/g)) {
95
+ if (token.startsWith("%%")) break;
96
+ tokens.push(token);
97
+ }
98
+ const command = tokens.shift();
99
+ if ([
100
+ "branch",
101
+ "checkout",
102
+ "switch",
103
+ "merge"
104
+ ].includes(command)) {
105
+ const name = valueOf(tokens[0]);
106
+ if (!ref(tokens.shift())) {
107
+ fail(line, "缺少有效的分支名", "Expected a valid branch name");
108
+ continue;
109
+ }
110
+ if (command === "branch") {
111
+ const order = tokens.length === 3 && tokens[0] === "order" && tokens[1] === ":" && /^\d+$/.test(tokens[2]) ? Number(tokens[2]) : null;
112
+ if (branches.has(name) || tokens.length && !Number.isSafeInteger(order)) {
113
+ fail(line, "重复的分支或无效的顺序", "Duplicate branch or invalid order");
114
+ continue;
115
+ }
116
+ if (branches.size === 2e3) {
117
+ fail(line, "分支超过 2000 个,请拆分图表", "More than 2000 branches; split the diagram");
118
+ break;
119
+ }
120
+ const seq = ++branchIndex;
121
+ branches.set(name, current = {
122
+ name,
123
+ label: clean(name, line),
124
+ order: order ?? Number(`0.${seq}`),
125
+ head: current.head
126
+ });
127
+ continue;
128
+ }
129
+ const other = branches.get(name);
130
+ if (!other) {
131
+ fail(line, `未知分支:${name}`, `Unknown branch: ${name}`);
132
+ continue;
133
+ }
134
+ if (command !== "merge") {
135
+ if (tokens.length) fail(line, "切换分支不接受额外参数", "Unexpected checkout option");
136
+ else current = other;
137
+ continue;
138
+ }
139
+ if (!current.head || !other.head || current.head === other.head || current.head.branch === name || current === other) {
140
+ fail(line, "合并要求两个不同的分支有不同的提交头", "Merge requires different branches with distinct commit heads");
141
+ continue;
142
+ }
143
+ tokens.unshift(other.head);
144
+ }
145
+ if (![
146
+ "commit",
147
+ "merge",
148
+ "cherry-pick"
149
+ ].includes(command)) {
150
+ fail(line, "未知的 Git 命令", "Unknown Git command");
151
+ continue;
152
+ }
153
+ const other = command === "merge" ? tokens.shift() : null;
154
+ const attrs = attributes(command, tokens);
155
+ if (!attrs) {
156
+ fail(line, "无效的提交属性", "Invalid commit attributes");
157
+ continue;
158
+ }
159
+ const seq = commits.length;
160
+ if (seq === 2e3) {
161
+ fail(line, "提交超过 2000 个,请拆分图表", "More than 2000 commits; split the diagram");
162
+ break;
163
+ }
164
+ const parents = current.head ? [current.head.seq] : [];
165
+ if (other) parents.push(other.seq);
166
+ const customId = command !== "cherry-pick" && Boolean(attrs.id);
167
+ const id = customId ? attrs.id : void 0;
168
+ if (customId && byId.has(id)) {
169
+ if (command === "merge") {
170
+ fail(line, `重复的合并提交 ID:${id}`, `Duplicate merge commit ID: ${id}`);
171
+ continue;
172
+ }
173
+ if (!duplicateIds.has(id)) errors.push(warning("DIAGRAM_HINT", lang, line, `重复的提交 ID:${id}`, `Duplicate commit ID: ${id}`, "使用不同的 ID", "Use distinct IDs"));
174
+ duplicateIds.add(id);
175
+ }
176
+ let cherryOf;
177
+ if (command === "cherry-pick") {
178
+ const source = byId.get(attrs.id), parent = byId.get(attrs.parent);
179
+ if (!source || !current.head || source.branch === current.name || attrs.parent && (!parent || !source.parents.includes(parent.seq)) || source.merge && !attrs.parent) {
180
+ fail(line, "拣选需要另一分支的提交和当前分支的提交头;拣选合并提交还需指定直接父提交", "Cherry-pick needs a source on another branch and a current head; a merge source requires an immediate parent");
181
+ continue;
182
+ }
183
+ parents.push(source.seq);
184
+ cherryOf = source.id;
185
+ if (!attrs.tags.length) attrs.tags.push(`cherry-pick:${source.id}${source.merge ? `|parent:${attrs.parent}` : ""}`);
186
+ }
187
+ const commit = {
188
+ id,
189
+ label: id && clean(id, line),
190
+ seq,
191
+ branch: current.name,
192
+ parents,
193
+ type: attrs.type,
194
+ tags: attrs.tags.map((tag) => clean(tag, line)),
195
+ msg: clean(attrs.msg, line),
196
+ merge: command === "merge",
197
+ cherryOf
198
+ };
199
+ commits.push(commit);
200
+ if (customId) byId.set(id, commit);
201
+ current.head = commit;
202
+ }
203
+ const presentationOf = (id) => ({
204
+ status: look.statusOf(id),
205
+ link: look.linkOf(id)
206
+ });
207
+ const ordered = [...branches.values()].sort((a, b) => a.order - b.order).map(({ name, label, order }) => ({
208
+ name,
209
+ label,
210
+ order,
211
+ ...presentationOf(name)
212
+ }));
213
+ let edge = 0;
214
+ for (const commit of commits) {
215
+ Object.assign(commit, presentationOf(commit.id ?? String(commit.seq + 1)));
216
+ commit.edgeStatuses = commit.parents.map(() => look.edgeStatusOf(edge++));
217
+ }
218
+ errors.push(...look.diagnostics());
219
+ return {
220
+ model: {
221
+ type: "gitGraph",
222
+ commits,
223
+ branches: ordered,
224
+ title,
225
+ direction: direction?.[1]?.toUpperCase() || "LR",
226
+ config
227
+ },
228
+ errors
229
+ };
230
+ }
231
+ function roundedRoute(points) {
232
+ let d = `M${points[0].join(" ")}`;
233
+ const toward = (p, q, d) => {
234
+ const len = Math.hypot(q[0] - p[0], q[1] - p[1]);
235
+ return len ? p.map((v, i) => v + (q[i] - v) * d / len) : p;
236
+ };
237
+ for (let i = 1; i < points.length - 1; i++) {
238
+ const p = points[i], a = points[i - 1], b = points[i + 1];
239
+ const r = Math.min(8, Math.hypot(p[0] - a[0], p[1] - a[1]) / 2, Math.hypot(b[0] - p[0], b[1] - p[1]) / 2);
240
+ d += ` L${toward(p, a, r).join(" ")} Q${p.join(" ")} ${toward(p, b, r).join(" ")}`;
241
+ }
242
+ return `${d} L${points.at(-1).join(" ")}`;
243
+ }
244
+ function layout(model, { ctx, width, renderOptions }, info = {}) {
245
+ const { title, commits, branches, direction, config } = model, t = appearance(ctx);
246
+ const vertical = direction !== "LR", reverse = direction === "BT";
247
+ const showBranches = config.showBranches !== false, showLabels = config.showCommitLabel !== false;
248
+ const pad = Math.max(12, Math.min(60, Number(config.diagramPadding) || 18));
249
+ const titleInline = title && !renderOptions?.frame, heading = titleInline ? Math.max(30, Math.min(100, Number(config.titleTopMargin) || 30)) : 0;
250
+ const W = (lines) => Math.max(0, ...lines.map((s) => ctx.measure(s, FONT.label.size)));
251
+ const laneOf = new Map(branches.map(({ name }, i) => [name, i]));
252
+ const branchNames = branches.map(({ label }) => ctx.wrap(label, 128, FONT.label.size));
253
+ const branchW = showBranches ? Math.max(...branchNames.map(W)) + 20 : 0;
254
+ const branchH = showBranches ? Math.max(...branchNames.map((lines) => lines.length)) * 16 + 10 : 0;
255
+ const slots = [];
256
+ const nodes = commits.map((c) => {
257
+ const label = showLabels ? ctx.wrap(c.id ? c.label : !c.merge && c.cherryOf == null ? `${c.seq + 1}` : "", 130, FONT.label.size).filter(Boolean) : [];
258
+ const msg = c.msg ? ctx.wrap(c.msg, 130, FONT.label.size) : [];
259
+ const tags = c.tags.map((tag) => ctx.wrap(tag, 130, FONT.label.size));
260
+ const slot = config.parallelCommits ? Math.max(-1, ...c.parents.map((p) => slots[p])) + 1 : c.seq;
261
+ slots.push(slot);
262
+ return {
263
+ ...c,
264
+ lane: laneOf.get(c.branch),
265
+ label: [...label, ...msg],
266
+ tags
267
+ };
268
+ });
269
+ const labelH = Math.max(0, ...nodes.map((n) => n.label.length * 16));
270
+ const tagH = Math.max(0, ...nodes.map((n) => n.tags.reduce((sum, lines) => sum + lines.length * 16 + 8, 0)));
271
+ const textW = Math.max(14, ...nodes.flatMap((n) => [W(n.label), ...n.tags.map(W)]));
272
+ const beforeLane = vertical ? Math.max(branchW / 2 + 14, textW + 32) : tagH + 24;
273
+ const afterLane = vertical ? Math.max(branchW / 2 + 14, textW + 26) : labelH + 20;
274
+ const cross = nodes.flatMap((n) => n.parents.filter((p) => nodes[p].lane !== n.lane).map((p) => ({
275
+ from: p,
276
+ to: n.seq
277
+ })));
278
+ const crossOf = new Map(cross.map((edge, index) => [`${edge.from}:${edge.to}`, index]));
279
+ const slotCount = Math.max(0, ...slots) + 1;
280
+ const slotGaps = Array.from({ length: slotCount }, () => ({
281
+ incoming: [],
282
+ outgoing: []
283
+ }));
284
+ cross.forEach((edge, i) => {
285
+ slotGaps[slots[edge.from]].outgoing.push(i);
286
+ slotGaps[slots[edge.to]].incoming.push(i);
287
+ });
288
+ const slotWidth = Array(slotCount).fill(14);
289
+ nodes.forEach((n, i) => {
290
+ slotWidth[slots[i]] = Math.max(slotWidth[slots[i]], W(n.label), ...n.tags.map((lines) => W(lines) + 12));
291
+ });
292
+ const times = [], depart = /* @__PURE__ */ new Map(), arrive = /* @__PURE__ */ new Map();
293
+ let pos = pad + (vertical ? branchH : branchW) + 8;
294
+ for (const [index, gap] of slotGaps.entries()) {
295
+ const stepHalf = vertical ? Math.max(tagH, labelH) / 2 + 20 : slotWidth[index] / 2 + 18;
296
+ for (const id of gap.incoming) {
297
+ pos += 6;
298
+ arrive.set(id, pos);
299
+ }
300
+ times.push(pos += stepHalf);
301
+ pos += stepHalf;
302
+ for (const id of gap.outgoing) {
303
+ pos += 6;
304
+ depart.set(id, pos);
305
+ }
306
+ }
307
+ const timeline = pos + pad;
308
+ const laneCenters = [], tracks = /* @__PURE__ */ new Map();
309
+ pos = pad;
310
+ for (let i = 0; i < branches.length; i++) {
311
+ laneCenters.push(pos += beforeLane);
312
+ pos += afterLane;
313
+ cross.forEach((edge, j) => {
314
+ if (nodes[edge.from].lane === i) {
315
+ tracks.set(j, pos);
316
+ pos += 6;
317
+ }
318
+ });
319
+ }
320
+ const breadth = pos + (vertical ? pad : Math.max(0, pad - 12));
321
+ const w = Math.max(width, vertical ? breadth : timeline), height = heading + (vertical ? timeline : breadth);
322
+ const offset = (w - (vertical ? breadth : timeline)) / 2;
323
+ const coords = (u, v) => vertical ? [offset + v, heading + (reverse ? timeline - u : u)] : [offset + u, heading + v];
324
+ const centered = {
325
+ ...FONT.label,
326
+ anchor: "middle",
327
+ "dominant-baseline": "central"
328
+ };
329
+ const children = [];
330
+ const tone = (lane) => ctx.color(`tone${lane % 6 + 1}`);
331
+ if (titleInline) children.push(ctx.text(w / 2, heading / 2, title, {
332
+ ...centered,
333
+ ...FONT.title,
334
+ fill: t.fg1
335
+ }));
336
+ if (showBranches) branches.forEach(({ name, status, link }, lane) => {
337
+ const v = laneCenters[lane], railStart = pad + (vertical ? branchH : branchW);
338
+ children.push(ctx.line(...coords(railStart, v), ...coords(timeline - pad, v), {
339
+ stroke: t.line,
340
+ meta: {
341
+ kind: "frame",
342
+ id: name
343
+ }
344
+ }));
345
+ const [x, y] = coords(pad + (vertical ? branchH : branchW) / 2, v);
346
+ const pw = vertical ? W(branchNames[lane]) + 20 : branchW, ph = vertical ? branchH : branchNames[lane].length * 16 + 10;
347
+ const plate = [ctx.rect(x - pw / 2, y - ph / 2, pw, ph, {
348
+ rx: t.smallRadius,
349
+ fill: ctx.tint(t.surface, t[status] || tone(lane), .1),
350
+ stroke: ctx.frameTone(t[status] || t.line)
351
+ }), textBlock(ctx, {
352
+ x,
353
+ y,
354
+ lines: branchNames[lane],
355
+ font: FONT.label,
356
+ lineHeight: 16
357
+ })];
358
+ children.push(...link ? [ctx.link(link.href, plate, link)] : plate);
359
+ });
360
+ for (const to of nodes) for (const [parentIndex, parent] of to.parents.entries()) {
361
+ const from = nodes[parent], a = times[slots[parent]], b = times[slots[to.seq]], av = laneCenters[from.lane], bv = laneCenters[to.lane];
362
+ let route;
363
+ if (av === bv) route = [[a + 6, av], [b - 7, bv]];
364
+ else {
365
+ const id = crossOf.get(`${parent}:${to.seq}`), out = depart.get(id), end = arrive.get(id), track = tracks.get(id);
366
+ if (slots[to.seq] === slots[parent] + 1) route = [
367
+ [a, av],
368
+ [out, av + (bv > av ? 9 : -9)],
369
+ [out, bv - (bv > av ? 9 : -9)],
370
+ [b, bv]
371
+ ];
372
+ else route = [
373
+ [a, av],
374
+ [out, av - 9],
375
+ [out, track],
376
+ [end, track],
377
+ [end, bv - 9],
378
+ [b, bv]
379
+ ];
380
+ }
381
+ const points = route.map((point) => coords(...point)), last = points.at(-1), prev = points.at(-2);
382
+ const distance = Math.hypot(last[0] - prev[0], last[1] - prev[1]);
383
+ const [dx, dy] = last.map((v, i) => (v - prev[i]) / distance);
384
+ if (av !== bv) points[points.length - 1] = [last[0] - dx * 7, last[1] - dy * 7];
385
+ const [x, y] = points.at(-1), stroke = t[to.edgeStatuses[parentIndex]] || tone(from.lane);
386
+ children.push(ctx.path(roundedRoute(points), {
387
+ fill: "none",
388
+ stroke,
389
+ "stroke-width": 1.5,
390
+ meta: {
391
+ kind: "edge",
392
+ from: parent,
393
+ to: to.seq
394
+ }
395
+ }));
396
+ children.push(ctx.path(`M${x - dx * 6 - dy * 3} ${y - dy * 6 + dx * 3} L${x} ${y} L${x - dx * 6 + dy * 3} ${y - dy * 6 - dx * 3} Z`, { fill: stroke }));
397
+ }
398
+ for (const n of nodes) {
399
+ const [x, y] = coords(times[slots[n.seq]], laneCenters[n.lane]);
400
+ const first = children.length;
401
+ const stroke = t[n.status] || tone(n.lane), meta = {
402
+ kind: "node",
403
+ id: n.seq
404
+ };
405
+ const highlight = n.type === "HIGHLIGHT";
406
+ children.push(highlight ? ctx.rect(x - 6, y - 6, 12, 12, {
407
+ rx: 2,
408
+ fill: stroke,
409
+ meta
410
+ }) : ctx.circle(x, y, 6, {
411
+ fill: t.surface,
412
+ stroke,
413
+ "stroke-width": 2,
414
+ meta
415
+ }));
416
+ if (n.merge) children.push(ctx.circle(x, y, 3, { fill: highlight ? t.surface : stroke }));
417
+ if (n.type === "REVERSE") children.push(ctx.path(`M${x - 3} ${y - 3} l6 6 m0 -6 l-6 6`, {
418
+ fill: "none",
419
+ stroke
420
+ }));
421
+ if (n.cherryOf != null) {
422
+ children.push(ctx.line(x - 3, y - 2, x + 3, y + 2, { stroke }));
423
+ for (const d of [-2, 2]) children.push(ctx.circle(x + d, y + d, 1.3, { fill: stroke }));
424
+ }
425
+ n.label.forEach((text, i) => children.push(ctx.text(vertical ? x + 16 : x, vertical ? y + (i - (n.label.length - 1) / 2) * 16 : y + 19 + i * 16, text, {
426
+ ...centered,
427
+ anchor: vertical ? "start" : "middle",
428
+ fill: t.fg1
429
+ })));
430
+ let tagY = vertical ? y + n.tags.reduce((sum, lines) => sum + lines.length * 16 + 8, 0) / 2 : y - 14;
431
+ if (n.tags.length) children.push(vertical ? ctx.line(x - 7, y, x - 16, y, { stroke }) : ctx.line(x, y - 7, x, tagY, { stroke }));
432
+ for (const lines of n.tags) {
433
+ const h = lines.length * 16 + 6, tw = W(lines) + 12;
434
+ const tx = vertical ? x - 16 - tw / 2 : x;
435
+ children.push(ctx.rect(tx - tw / 2, tagY - h, tw, h, {
436
+ rx: t.smallRadius,
437
+ fill: ctx.tint(t.surface, stroke, .12),
438
+ stroke: t.line
439
+ }));
440
+ children.push(textBlock(ctx, {
441
+ x: tx,
442
+ y: tagY - h / 2,
443
+ lines,
444
+ font: FONT.label,
445
+ lineHeight: 16
446
+ }));
447
+ tagY -= h + 2;
448
+ }
449
+ if (n.link) children.push(ctx.link(n.link.href, children.splice(first), n.link));
450
+ }
451
+ const errors = w > width * 2 || commits.length + branches.length > 60 ? [warning("LARGE_DIAGRAM", ctx.lang, info.headerLine || 1, "Git 历史较大", "Large Git history", "考虑拆分图表", "Consider splitting the diagram")] : [];
452
+ return {
453
+ width: w,
454
+ height,
455
+ scene: {
456
+ width: w,
457
+ height,
458
+ children,
459
+ title,
460
+ heading: title
461
+ },
462
+ errors
463
+ };
464
+ }
465
+ var implementations = { gitGraph: {
466
+ parse,
467
+ layout,
468
+ optionMode,
469
+ honoredConfig,
470
+ acceptsPresentation: true
471
+ } };
472
+ export { gitgraph_exports, implementations };