@x-cmd/draw 0.4.7 → 0.5.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 (205) hide show
  1. package/README.md +3 -3
  2. package/dist/client.d.ts +44 -0
  3. package/dist/client.js +285 -0
  4. package/dist/core.d.ts +86 -0
  5. package/dist/core.js +132 -0
  6. package/dist/draw-client.iife.js +51 -0
  7. package/dist/draw-echarts.iife.js +1 -0
  8. package/dist/echarts-client.d.ts +34 -0
  9. package/dist/echarts-client.js +109 -0
  10. package/dist/globe.d.ts +4 -0
  11. package/dist/globe.js +6 -0
  12. package/dist/layout/cluster.d.ts +2 -0
  13. package/dist/layout/cluster.js +228 -0
  14. package/dist/layout/index.d.ts +2 -0
  15. package/dist/layout/index.js +6 -0
  16. package/dist/layout/layered.d.ts +51 -0
  17. package/dist/layout/layered.js +433 -0
  18. package/dist/layout/portsize.d.ts +18 -0
  19. package/dist/layout/portsize.js +34 -0
  20. package/dist/lib.d.ts +17 -4
  21. package/dist/lib.js +20 -4
  22. package/dist/node/cmd.d.ts +1 -0
  23. package/dist/node/cmd.js +3 -0
  24. package/dist/render/abc-parse.d.ts +75 -0
  25. package/dist/render/abc-parse.js +345 -0
  26. package/dist/render/abcjs.d.ts +10 -0
  27. package/dist/render/abcjs.js +90 -0
  28. package/dist/render/anno.d.ts +48 -2
  29. package/dist/render/anno.js +171 -17
  30. package/dist/render/ansi.d.ts +15 -0
  31. package/dist/render/ansi.js +142 -0
  32. package/dist/render/arch.js +8 -3
  33. package/dist/render/arch3d.d.ts +31 -0
  34. package/dist/render/arch3d.js +294 -0
  35. package/dist/render/archmap.js +2 -2
  36. package/dist/render/area.js +42 -11
  37. package/dist/render/bar-grid.js +1 -1
  38. package/dist/render/bar-grouped.js +25 -7
  39. package/dist/render/bar-stacked.js +22 -6
  40. package/dist/render/bar.js +27 -6
  41. package/dist/render/block.d.ts +56 -0
  42. package/dist/render/block.js +361 -0
  43. package/dist/render/butterfly.js +4 -1
  44. package/dist/render/calendar.js +49 -14
  45. package/dist/render/center.d.ts +26 -0
  46. package/dist/render/center.js +108 -0
  47. package/dist/render/chem.d.ts +22 -0
  48. package/dist/render/chem.js +205 -0
  49. package/dist/render/chord.d.ts +17 -0
  50. package/dist/render/chord.js +141 -0
  51. package/dist/render/combo.js +7 -7
  52. package/dist/render/compass.js +59 -13
  53. package/dist/render/echarts-ssr.d.ts +40 -2
  54. package/dist/render/echarts-ssr.js +80 -20
  55. package/dist/render/gauge.js +17 -9
  56. package/dist/render/gitgraph.d.ts +53 -0
  57. package/dist/render/gitgraph.js +324 -0
  58. package/dist/render/globe-areas.d.ts +21 -0
  59. package/dist/render/globe-areas.js +40 -0
  60. package/dist/render/globe-earth.d.ts +78 -0
  61. package/dist/render/globe-earth.js +464 -0
  62. package/dist/render/globe-keys.d.ts +34 -0
  63. package/dist/render/globe-keys.js +71 -0
  64. package/dist/render/globe-proj.d.ts +103 -0
  65. package/dist/render/globe-proj.js +332 -0
  66. package/dist/render/globe-regions.d.ts +23 -0
  67. package/dist/render/globe-regions.js +60 -0
  68. package/dist/render/globe.d.ts +15 -0
  69. package/dist/render/globe.js +306 -0
  70. package/dist/render/globe3d.d.ts +113 -0
  71. package/dist/render/globe3d.js +285 -0
  72. package/dist/render/hbar-spec.js +23 -10
  73. package/dist/render/hbar.js +30 -11
  74. package/dist/render/jianpu.d.ts +10 -0
  75. package/dist/render/jianpu.js +190 -0
  76. package/dist/render/journey.d.ts +54 -0
  77. package/dist/render/journey.js +277 -0
  78. package/dist/render/kanban.d.ts +50 -0
  79. package/dist/render/kanban.js +240 -0
  80. package/dist/render/kinds.js +19 -0
  81. package/dist/render/line-multi.js +27 -8
  82. package/dist/render/line.js +32 -14
  83. package/dist/render/maps.js +4 -2
  84. package/dist/render/mermaid/block.d.ts +2 -0
  85. package/dist/render/mermaid/block.js +256 -0
  86. package/dist/render/mermaid/c4.d.ts +3 -0
  87. package/dist/render/mermaid/c4.js +165 -0
  88. package/dist/render/mermaid/class.d.ts +2 -0
  89. package/dist/render/mermaid/class.js +185 -0
  90. package/dist/render/mermaid/common.d.ts +34 -0
  91. package/dist/render/mermaid/common.js +81 -0
  92. package/dist/render/mermaid/erd.d.ts +2 -0
  93. package/dist/render/mermaid/erd.js +103 -0
  94. package/dist/render/mermaid/gitgraph.d.ts +2 -0
  95. package/dist/render/mermaid/gitgraph.js +139 -0
  96. package/dist/render/mermaid/journey.d.ts +7 -0
  97. package/dist/render/mermaid/journey.js +68 -0
  98. package/dist/render/mermaid/kanban.d.ts +2 -0
  99. package/dist/render/mermaid/kanban.js +86 -0
  100. package/dist/render/mermaid/mindmap.d.ts +7 -0
  101. package/dist/render/mermaid/mindmap.js +74 -0
  102. package/dist/render/mermaid/packet.d.ts +2 -0
  103. package/dist/render/mermaid/packet.js +35 -0
  104. package/dist/render/mermaid/pie.d.ts +7 -0
  105. package/dist/render/mermaid/pie.js +58 -0
  106. package/dist/render/mermaid/quadrant.d.ts +8 -0
  107. package/dist/render/mermaid/quadrant.js +137 -0
  108. package/dist/render/mermaid/radar.d.ts +8 -0
  109. package/dist/render/mermaid/radar.js +69 -0
  110. package/dist/render/mermaid/requirement.d.ts +2 -0
  111. package/dist/render/mermaid/requirement.js +100 -0
  112. package/dist/render/mermaid/sankey.d.ts +7 -0
  113. package/dist/render/mermaid/sankey.js +54 -0
  114. package/dist/render/mermaid/seq.d.ts +2 -0
  115. package/dist/render/mermaid/seq.js +147 -0
  116. package/dist/render/mermaid/state.d.ts +2 -0
  117. package/dist/render/mermaid/state.js +168 -0
  118. package/dist/render/mermaid/timeline.d.ts +7 -0
  119. package/dist/render/mermaid/timeline.js +63 -0
  120. package/dist/render/mermaid/xychart.d.ts +7 -0
  121. package/dist/render/mermaid/xychart.js +94 -0
  122. package/dist/render/mermaid.d.ts +22 -4
  123. package/dist/render/mermaid.js +173 -7
  124. package/dist/render/mindmap.js +12 -2
  125. package/dist/render/nomnoml.d.ts +8 -0
  126. package/dist/render/nomnoml.js +47 -0
  127. package/dist/render/packet.d.ts +39 -0
  128. package/dist/render/packet.js +232 -0
  129. package/dist/render/params-dispatch.d.ts +20 -0
  130. package/dist/render/params-dispatch.js +192 -0
  131. package/dist/render/pie.js +29 -22
  132. package/dist/render/quadrant.js +38 -9
  133. package/dist/render/query.d.ts +11 -1
  134. package/dist/render/query.js +92 -16
  135. package/dist/render/radar.js +7 -6
  136. package/dist/render/requirement.d.ts +61 -0
  137. package/dist/render/requirement.js +355 -0
  138. package/dist/render/sankey.js +4 -4
  139. package/dist/render/scatter.js +25 -9
  140. package/dist/render/scene3d.d.ts +188 -0
  141. package/dist/render/scene3d.js +433 -0
  142. package/dist/render/seq.js +13 -8
  143. package/dist/render/simplify.d.ts +12 -0
  144. package/dist/render/simplify.js +105 -0
  145. package/dist/render/source-theme.d.ts +104 -0
  146. package/dist/render/source-theme.js +261 -0
  147. package/dist/render/svg.d.ts +81 -1
  148. package/dist/render/svg.js +259 -2
  149. package/dist/render/svgdom.d.ts +74 -0
  150. package/dist/render/svgdom.js +198 -0
  151. package/dist/render/timeline.d.ts +54 -0
  152. package/dist/render/timeline.js +290 -0
  153. package/dist/render/tty.d.ts +17 -0
  154. package/dist/render/tty.js +173 -0
  155. package/dist/render/ttycmd.d.ts +7 -0
  156. package/dist/render/ttycmd.js +152 -0
  157. package/dist/render/vendor/au.js +1 -1
  158. package/dist/render/vendor/br.js +1 -1
  159. package/dist/render/vendor/china-counties.d.ts +32 -0
  160. package/dist/render/vendor/china-counties.js +8 -0
  161. package/dist/render/vendor/china-provinces.d.ts +16 -0
  162. package/dist/render/vendor/china-provinces.js +8 -0
  163. package/dist/render/vendor/china.js +1 -1
  164. package/dist/render/vendor/country-aliases.d.ts +207 -0
  165. package/dist/render/vendor/country-aliases.js +7 -0
  166. package/dist/render/vendor/de.js +1 -1
  167. package/dist/render/vendor/eu.js +1 -1
  168. package/dist/render/vendor/japan.js +1 -1
  169. package/dist/render/vendor/kr.js +1 -1
  170. package/dist/render/vendor/world-geo.js +1 -1
  171. package/dist/render/vendor/world-ne.d.ts +18 -0
  172. package/dist/render/vendor/world-ne.js +8 -0
  173. package/dist/render/vendor/world.js +1 -1
  174. package/dist/render/vexflow.d.ts +10 -0
  175. package/dist/render/vexflow.js +189 -0
  176. package/dist/render/wavedrom.d.ts +14 -0
  177. package/dist/render/wavedrom.js +113 -0
  178. package/dist/source.d.ts +20 -0
  179. package/dist/source.js +27 -0
  180. package/dist/specs/base.js +9 -4
  181. package/dist/specs/combo.d.ts +1 -0
  182. package/dist/specs/combo.js +8 -1
  183. package/dist/specs/gauge.d.ts +1 -0
  184. package/dist/specs/gauge.js +14 -2
  185. package/dist/specs/multi.d.ts +3 -0
  186. package/dist/specs/multi.js +29 -3
  187. package/dist/specs/quadrant.js +5 -4
  188. package/dist/specs/scatter.d.ts +1 -0
  189. package/dist/specs/scatter.js +7 -0
  190. package/dist/styles/bar.js +3 -0
  191. package/dist/styles/baseline.d.ts +47 -0
  192. package/dist/styles/baseline.js +48 -0
  193. package/dist/styles/hbar.js +3 -0
  194. package/dist/styles/index.d.ts +1 -1
  195. package/dist/styles/index.js +16 -4
  196. package/dist/styles/line.js +9 -0
  197. package/dist/styles/pie.js +4 -0
  198. package/dist/styles/sankey.js +4 -0
  199. package/dist/styles/skins.d.ts +23 -0
  200. package/dist/styles/skins.js +349 -0
  201. package/dist/styles/types.d.ts +20 -0
  202. package/dist/styles/types.js +17 -1
  203. package/dist/world-data.d.ts +12 -0
  204. package/dist/world-data.js +192 -0
  205. package/package.json +44 -6
@@ -0,0 +1,324 @@
1
+ // /draw/gitgraph —— 提交图:分支是泳道,提交是泳道上的点,时间往下走。
2
+ //
3
+ // 模型(扁平 URL 参数,手写也能写对):
4
+ // branch=<名字> 可重复 —— 分支(泳道),按出现顺序自上而下排
5
+ // commit=<id>|<lane>|<label>|<p1>|<p2> 可重复 —— 一个提交
6
+ // id 提交 id(可省,省了自动编号)
7
+ // lane 所在分支(必须是某个 branch= 的名字)
8
+ // label 提交信息(可省)
9
+ // p1/p2 父提交的 id(可省;两个都有 = 合并提交)
10
+ // title= / subtitle= 图题与副题
11
+ //
12
+ // 画法:每个分支一条横向泳道(带名字的框),提交画成点;
13
+ // 普通父子关系 = 竖线;合并的第二父 = 一条弯过去的曲线(虚线 + 箭头),
14
+ // 一眼能看出「谁并进了谁」。
15
+ import { ApiError } from '../specs/index.js';
16
+ import { BASELINE } from '../styles/baseline.js';
17
+ import { resolveSkin } from '../styles/index.js';
18
+ import { clampInt, schemeParam } from './query.js';
19
+ import { card } from '../theme.js';
20
+ import { esc, r2, subtitleBlock, svgDoc, textW, titleBlock } from './svg.js';
21
+ const PAD = 26;
22
+ const LANE_H = 76; // 一条泳道(一个分支)的高度
23
+ const HEAD_H = 34; // 泳道名字条的高度
24
+ const DOT_R = 7; // 提交点的半径
25
+ const ROW_GAP = 14; // 同一泳道里两个提交点之间的额外间距
26
+ const LABEL_FS = BASELINE.pointName;
27
+ const LABEL_GAP = 12; // 提交文字离点的距离
28
+ const CHANNEL_MIN = 26; // 绕行通道的最小宽度(跨泳道的曲线走这里)
29
+ const EXAMPLE = 'branch=main&branch=develop&commit=one|main|First commit||&commit=two|develop|Feature work||&commit=three|main|Merge develop|one|two';
30
+ function bad(detail) {
31
+ throw new ApiError(400, `${detail}. Example: /draw/gitgraph?${EXAMPLE}`);
32
+ }
33
+ /** 从扁平 URL 参数造规格(参数已 decode) */
34
+ export function gitGraphSpecFromParams(params) {
35
+ const branches = params.getAll('branch').map((b) => b.trim()).filter((b) => b !== '');
36
+ const commits = [];
37
+ params.getAll('commit').forEach((raw, i) => {
38
+ const f = raw.split('|').map((x) => x.trim());
39
+ if (f.length < 2) {
40
+ bad(`"commit" #${i + 1} must be "id|lane[|label][|parent][|parent2]"`);
41
+ }
42
+ commits.push({
43
+ id: f[0] || `c${i + 1}`,
44
+ lane: f[1],
45
+ ...(f[2] ? { label: f[2] } : {}),
46
+ ...(f[3] ? { parent: f[3] } : {}),
47
+ ...(f[4] ? { parent2: f[4] } : {}),
48
+ });
49
+ });
50
+ const title = params.get('title')?.trim() || undefined;
51
+ const subtitle = params.get('subtitle')?.trim() || undefined;
52
+ return { ...(title ? { title } : {}), ...(subtitle ? { subtitle } : {}), branches, commits };
53
+ }
54
+ /**
55
+ * 解析并校验提交图规格(JSON 形态,给 ?d= 用)。
56
+ *
57
+ * @throws ApiError(400) with a corrective example on bad input
58
+ */
59
+ export function parseGitGraphSpec(raw) {
60
+ if (raw === null || raw === '') {
61
+ bad(`missing data. Use /draw/gitgraph?${EXAMPLE}`);
62
+ }
63
+ let obj;
64
+ try {
65
+ obj = JSON.parse(raw);
66
+ }
67
+ catch {
68
+ bad(`"d" is not valid JSON. Use {"branches":["main"],"commits":[{"id":"a","lane":"main"}]}`);
69
+ }
70
+ const o = obj;
71
+ if (!Array.isArray(o.branches) || o.branches.length === 0) {
72
+ bad(`"branches" must be a non-empty array of branch names`);
73
+ }
74
+ const branches = [];
75
+ for (const b of o.branches) {
76
+ if (typeof b !== 'string' || b.trim() === '')
77
+ bad(`"branches" entries must be non-empty strings`);
78
+ branches.push(b.trim());
79
+ }
80
+ if (!Array.isArray(o.commits) || o.commits.length === 0) {
81
+ bad(`"commits" must be a non-empty array of commits`);
82
+ }
83
+ const commits = o.commits.map((c, i) => {
84
+ if (typeof c !== 'object' || c === null)
85
+ bad(`"commits"[${i}] must be an object`);
86
+ const cc = c;
87
+ const id = typeof cc.id === 'string' && cc.id !== '' ? cc.id : `c${i + 1}`;
88
+ const lane = typeof cc.lane === 'string' ? cc.lane : '';
89
+ if (!lane)
90
+ bad(`"commits"[${i}].lane is required (a branch name)`);
91
+ if (!branches.includes(lane))
92
+ bad(`"commits"[${i}].lane "${lane}" is not one of the branches`);
93
+ const label = typeof cc.label === 'string' && cc.label !== '' ? cc.label : undefined;
94
+ const parent = typeof cc.parent === 'string' && cc.parent !== '' ? cc.parent : undefined;
95
+ const parent2 = typeof cc.parent2 === 'string' && cc.parent2 !== '' ? cc.parent2 : undefined;
96
+ return { id, lane, ...(label ? { label } : {}), ...(parent ? { parent } : {}), ...(parent2 ? { parent2 } : {}) };
97
+ });
98
+ const ids = new Set(commits.map((c) => c.id));
99
+ for (const c of commits) {
100
+ for (const p of [c.parent, c.parent2]) {
101
+ if (p && !ids.has(p))
102
+ bad(`commit "${c.id}" references unknown parent "${p}"`);
103
+ }
104
+ }
105
+ const title = typeof o.title === 'string' && o.title !== '' ? o.title : undefined;
106
+ const subtitle = typeof o.subtitle === 'string' && o.subtitle !== '' ? o.subtitle : undefined;
107
+ return { ...(title ? { title } : {}), ...(subtitle ? { subtitle } : {}), branches, commits };
108
+ }
109
+ const LANE_COLORS = ['var(--d-s1)', 'var(--d-s2)', 'var(--d-s3)', 'var(--d-s4)', 'var(--d-s5)', 'var(--d-s6)', 'var(--d-s7)', 'var(--d-s8)', 'var(--d-s9)', 'var(--d-s10)'];
110
+ /** 文字截到能放进 maxW(超了就加省略号)—— 标题不许压到右上角的 Edit 角标 */
111
+ function fitText(s, fs, maxW) {
112
+ if (!s)
113
+ return s;
114
+ if (textW(s, fs) <= maxW)
115
+ return s;
116
+ let t = s;
117
+ while (t.length > 1 && textW(`${t}…`, fs) > maxW)
118
+ t = t.slice(0, -1);
119
+ return `${t}…`;
120
+ }
121
+ /**
122
+ * 右上角 Edit 角标占掉的宽度(照 svg.ts 里 editTag 的算法算)。
123
+ * 标题是左对齐的,只要不撞上角标就行 —— 不用留满 TAG_RESERVE 那 150px。
124
+ */
125
+ function editTagReserve(width) {
126
+ const fs = Math.max(10, Math.min(18, Math.round(width / 55)));
127
+ const tw = textW('Edit @X-CMD', fs);
128
+ const padX = Math.max(6, Math.round(fs * 0.55));
129
+ return Math.round(tw + padX * 2 + 2) + 8 + PAD;
130
+ }
131
+ /**
132
+ * 渲染提交图。
133
+ */
134
+ export function renderGitGraph(spec, o) {
135
+ if (!spec.branches.length)
136
+ bad('at least one branch is required');
137
+ if (!spec.commits.length)
138
+ bad('at least one commit is required');
139
+ const laneNames = new Set(spec.branches);
140
+ for (const c of spec.commits) {
141
+ if (!laneNames.has(c.lane))
142
+ bad(`commit "${c.id}" is on unknown branch "${c.lane}"`);
143
+ }
144
+ // 泳道高度:每个分支里最多几个提交 → 决定这条泳道要多高
145
+ const perLane = new Map();
146
+ for (const c of spec.commits) {
147
+ const arr = perLane.get(c.lane) ?? [];
148
+ arr.push(c);
149
+ perLane.set(c.lane, arr);
150
+ }
151
+ const titleH = spec.title || spec.subtitle ? 44 : 30; // 没标题也留一条带:右上角那枚角标在那儿
152
+ const hasTitle = !!spec.title;
153
+ // 泳道的左右留白:
154
+ // 左边 = 分支名槽(名字贴在最左)
155
+ // 再往右 = 「绕行通道」(合并曲线走这里,不压文字)
156
+ // 再往右 = 提交轴(点在这一列) + 提交文字
157
+ const laneNameW = Math.max(56, ...spec.branches.map((b) => textW(b, 12) + 26));
158
+ const laneTextW = Math.max(0, ...spec.commits.map((c) => (c.label ? textW(c.label, LABEL_FS) : 0)));
159
+ const gutterR = PAD + laneNameW; // 名字槽的右缘
160
+ // 绕行通道要站得下几条曲线:先数一数有几条「跨泳道」的边(普通边 + 合并边),
161
+ // 通道按条数加宽,每条曲线在通道里各占一格(不压在彼此身上)。
162
+ const crossEdges = spec.commits.filter((c) => {
163
+ const from = c.parent ? spec.commits.find((x) => x.id === c.parent) : undefined;
164
+ return !!from && from.lane !== c.lane;
165
+ }).length + spec.commits.filter((c) => !!c.parent2).length;
166
+ const channelSlots = Math.max(1, crossEdges);
167
+ const channelW = Math.max(CHANNEL_MIN, channelSlots * 11 + 8);
168
+ const channelX = gutterR + channelW / 2; // 绕行通道的中线
169
+ const axisX = gutterR + channelW + DOT_R;
170
+ const laneW = Math.max(220, axisX + DOT_R + LABEL_GAP + laneTextW + PAD);
171
+ const lanes = [];
172
+ let y = PAD + titleH;
173
+ spec.branches.forEach((name, i) => {
174
+ const n = perLane.get(name)?.length ?? 0;
175
+ const h = HEAD_H + Math.max(n, 1) * (DOT_R * 2 + ROW_GAP) + 10;
176
+ lanes.push({
177
+ name,
178
+ index: i,
179
+ y,
180
+ h,
181
+ axisX,
182
+ color: LANE_COLORS[i % LANE_COLORS.length],
183
+ });
184
+ y += h + 12;
185
+ });
186
+ const bodyBottom = y - 12;
187
+ // 提交点:每个泳道里自上而下排
188
+ const placed = [];
189
+ for (const lane of lanes) {
190
+ const list = perLane.get(lane.name) ?? [];
191
+ list.forEach((c, row) => {
192
+ placed.push({
193
+ ...c,
194
+ x: lane.axisX,
195
+ y: lane.y + HEAD_H + DOT_R + 6 + row * (DOT_R * 2 + ROW_GAP),
196
+ row,
197
+ });
198
+ });
199
+ }
200
+ const posOf = new Map(placed.map((p) => [p.id, p]));
201
+ const laneOf = new Map(lanes.map((l) => [l.name, l]));
202
+ // 画布:?w=/?h= 给了就按它画(内容仍是自然尺寸,摆在左上角);
203
+ // 没给就用自然尺寸。
204
+ let width = o.width !== undefined ? o.width : PAD * 2 + laneW;
205
+ let height = o.height !== undefined ? o.height : bodyBottom + PAD;
206
+ width = Math.max(width, PAD * 2 + laneW, o.minW ?? 0);
207
+ height = Math.max(height, bodyBottom + PAD, o.minH ?? 0);
208
+ const parts = [];
209
+ // 泳道:淡底 + 边框 + 左侧的名字槽
210
+ for (const lane of lanes) {
211
+ const lw = laneNameW - 16;
212
+ parts.push(`<g data-lane="${esc(lane.name)}">` +
213
+ `<rect x="${r2(PAD)}" y="${r2(lane.y)}" width="${r2(laneW)}" height="${r2(lane.h)}" rx="12" fill="${lane.color}" fill-opacity="0.05" stroke="${lane.color}" stroke-opacity="0.42" stroke-width="1.2"/>` +
214
+ // 名字槽:一条竖线分界,名字在竖线左边(线只画上半截 —— 名字在那儿)
215
+ `<line x1="${r2(gutterR)}" y1="${r2(lane.y + 8)}" x2="${r2(gutterR)}" y2="${r2(lane.y + 34)}" stroke="${lane.color}" stroke-opacity="0.32" stroke-width="1"/>` +
216
+ `<rect x="${r2(PAD + 8)}" y="${r2(lane.y + 9)}" width="${r2(lw)}" height="21" rx="6" fill="${lane.color}" fill-opacity="0.16"/>` +
217
+ `<text x="${r2(PAD + 8 + lw / 2)}" y="${r2(lane.y + 24)}" text-anchor="middle" font-size="12" font-weight="600" fill="${lane.color}">${esc(lane.name)}</text>` +
218
+ `</g>`);
219
+ }
220
+ // 跨泳道的曲线各占通道里的一格(两条线不许压在同一条道上)。
221
+ // 按「垂直跨度」分格:不相交的曲线可以共用一格,相交的才分开。
222
+ const slots = [];
223
+ const slotW = channelSlots > 1 ? (channelW - 16) / (channelSlots - 1) : 0;
224
+ const slotLeft = channelX - (channelSlots > 1 ? (channelSlots - 1) * slotW : 0) / 2;
225
+ /** 给一条跨泳道曲线找一格:找一条与它垂直跨度不相交的现成格,没有就新开一格 */
226
+ const slotX = (y0, y1) => {
227
+ const lo = Math.min(y0, y1);
228
+ const hi = Math.max(y0, y1);
229
+ for (const s of slots) {
230
+ if (hi < s.y0 - 4 || lo > s.y1 + 4)
231
+ return s.x; // 垂直跨度不相交 → 共用
232
+ }
233
+ const x = slotLeft + slotW * slots.length;
234
+ slots.push({ y0: lo, y1: hi, x });
235
+ return x;
236
+ };
237
+ // 合并边(第二父):先画,压在普通边下面。
238
+ // 走「绕行通道」:从源点左侧出发、贴着通道往下走、再从目标点左边进箭头。
239
+ // 通道是专属的空档 —— 从点与点之间直穿会把竖线和文字全划乱。
240
+ for (const c of placed) {
241
+ if (!c.parent2)
242
+ continue;
243
+ const from = posOf.get(c.parent2);
244
+ const lane = laneOf.get(c.lane);
245
+ if (!from)
246
+ continue;
247
+ const to = c;
248
+ const cx = slotX(from.y, to.y);
249
+ const d = `M${r2(from.x - DOT_R - 1)} ${r2(from.y)}` +
250
+ `C${r2(cx)} ${r2(from.y)},${r2(cx)} ${r2(to.y)},${r2(to.x - DOT_R - 4)} ${r2(to.y)}`;
251
+ const stroke = lane.color;
252
+ const ia = ` data-from="${esc(from.id)}" data-to="${esc(to.id)}" data-merge="1"`;
253
+ parts.push(`<path d="${d}" fill="none" stroke="${stroke}" stroke-opacity="0.9" stroke-width="1.8" stroke-dasharray="7 4" stroke-linecap="round"${ia}/>`,
254
+ // 箭头(指向目标)
255
+ `<path d="M${r2(to.x - DOT_R - 5)} ${r2(to.y)}L${r2(to.x - DOT_R)} ${r2(to.y - 4)}M${r2(to.x - DOT_R - 5)} ${r2(to.y)}L${r2(to.x - DOT_R)} ${r2(to.y + 4)}" fill="none" stroke="${stroke}" stroke-opacity="0.9" stroke-width="1.6"/>`);
256
+ }
257
+ // 普通父子边:同泳道内是竖线,跨泳道是走通道的曲线(避开右侧的文字)
258
+ for (const c of placed) {
259
+ if (!c.parent)
260
+ continue;
261
+ const from = posOf.get(c.parent);
262
+ if (!from)
263
+ continue;
264
+ const lane = laneOf.get(c.lane);
265
+ const stroke = lane.color;
266
+ const ia = o.interactive ? ` data-from="${esc(from.id)}" data-to="${esc(c.id)}"` : '';
267
+ if (from.lane === c.lane) {
268
+ parts.push(`<line x1="${r2(from.x)}" y1="${r2(from.y + DOT_R)}" x2="${r2(c.x)}" y2="${r2(c.y - DOT_R)}" stroke="${stroke}" stroke-opacity="0.8" stroke-width="1.6"${ia}/>`);
269
+ }
270
+ else {
271
+ const cx = slotX(from.y, c.y);
272
+ const d = `M${r2(from.x - DOT_R - 1)} ${r2(from.y)}C${r2(cx)} ${r2(from.y)},${r2(cx)} ${r2(c.y)},${r2(c.x - DOT_R - 4)} ${r2(c.y)}`;
273
+ parts.push(`<path d="${d}" fill="none" stroke="${stroke}" stroke-opacity="0.7" stroke-width="1.4" stroke-linecap="round"${ia}/>`, `<path d="M${r2(c.x - DOT_R - 5)} ${r2(c.y)}L${r2(c.x - DOT_R)} ${r2(c.y - 4)}M${r2(c.x - DOT_R - 5)} ${r2(c.y)}L${r2(c.x - DOT_R)} ${r2(c.y + 4)}" fill="none" stroke="${stroke}" stroke-opacity="0.7" stroke-width="1.4"/>`);
274
+ }
275
+ }
276
+ // 提交点 + 文字
277
+ for (const c of placed) {
278
+ const lane = laneOf.get(c.lane);
279
+ const isMerge = !!c.parent2;
280
+ const tip = [c.id, c.label, c.lane].filter(Boolean).join(' · ');
281
+ const ia = o.interactive ? ` data-node="${esc(c.id)}" data-tip="${esc(tip)}" tabindex="0" style="cursor:pointer"` : '';
282
+ parts.push(`<g${ia}>` +
283
+ `<circle cx="${r2(c.x)}" cy="${r2(c.y)}" r="${DOT_R}" fill="${lane.color}" stroke="var(--d-card)" stroke-width="2"/>` +
284
+ (isMerge ? `<circle cx="${r2(c.x)}" cy="${r2(c.y)}" r="${DOT_R - 3.5}" fill="var(--d-card)"/>` : '') +
285
+ `</g>`);
286
+ if (c.label) {
287
+ parts.push(`<text x="${r2(c.x + DOT_R + LABEL_GAP)}" y="${r2(c.y + 4)}" font-size="${LABEL_FS}" fill="var(--d-text)"${o.interactive ? ` data-node="${esc(c.id)}" style="cursor:pointer"` : ''}>${esc(c.label)}</text>`);
288
+ }
289
+ }
290
+ const titleMax = Math.max(60, width - PAD - editTagReserve(width));
291
+ const head = titleBlock(fitText(spec.title, 18, titleMax), PAD)
292
+ + subtitleBlock(fitText(spec.subtitle, 13, titleMax), PAD, hasTitle);
293
+ const meta = o.interactive
294
+ ? `<metadata id="gcommits">${esc(JSON.stringify(spec.commits))}</metadata>`
295
+ : '';
296
+ const bg = card(width, height, o.skin.rules.canvas === 'plain');
297
+ const svg = svgDoc(width, height, 'gitgraph', o.version, spec.title ?? `git graph, ${spec.branches.length} branches, ${spec.commits.length} commits`, { type: 'gitgraph', ...spec }, o.skin, bg + meta + `<g id="gg">${head + parts.join('')}</g>`, o.tagQuery, 'gitgraph');
298
+ return { svg, version: o.version, cacheControl: o.cacheControl };
299
+ }
300
+ /**
301
+ * `/draw/gitgraph` 入口:GET ?branch=…&commit=…&title=…
302
+ */
303
+ export function renderGitGraphFromUrl(url, interactive = false) {
304
+ const params = url.searchParams;
305
+ const d = params.get('d');
306
+ const spec = d !== null && d !== ''
307
+ ? parseGitGraphSpec(d)
308
+ : gitGraphSpecFromParams(params);
309
+ const v = Number.parseInt(params.get('v') ?? '', 10);
310
+ const version = Number.isInteger(v) && v >= 1 ? v : 1;
311
+ const skin = resolveSkin('sankey', params.get('t'), schemeParam(params));
312
+ const hasW = params.get('w') !== null && params.get('w') !== '';
313
+ const hasH = params.get('h') !== null && params.get('h') !== '';
314
+ return renderGitGraph(spec, {
315
+ spec,
316
+ interactive,
317
+ version,
318
+ cacheControl: 'public, max-age=300',
319
+ skin,
320
+ ...(hasW ? { width: clampInt(params, 'w', 0, 200, 2400) } : {}),
321
+ ...(hasH ? { height: clampInt(params, 'h', 0, 140, 2400) } : {}),
322
+ tagQuery: url.search,
323
+ });
324
+ }
@@ -0,0 +1,21 @@
1
+ /** 球面上可着色的一块地 */
2
+ export interface GlobeArea {
3
+ /** 国家还是一级区划 ✓ */
4
+ kind: 'country' | 'region';
5
+ /** 规范化后的键(国家 `US` ✓ / 区划 `CN-44` ✓) */
6
+ key: string;
7
+ /** 显示名 ✓ */
8
+ name: string;
9
+ /** 几何(经纬度 ✓;[多边形][环][点] ✓) */
10
+ polygon: number[][][][];
11
+ }
12
+ /**
13
+ * 找一块地 ✓
14
+ *
15
+ * 顺序:先当国家查(`US` ✓)· 再当一级区划查(`CN-44` ✓)——
16
+ * ⚠️ **先国家后区划**:只给两位码(`44`)时,区划表里能查到 ✓;
17
+ * 而 `CN` 这种两字母的永远是国家 ✓(不会撞 ✓)。
18
+ */
19
+ export declare function resolveGlobeArea(key: string): GlobeArea | null;
20
+ /** 全部可着色的地(国家 + 区划 ✓)—— 图例/下拉用 ✓ */
21
+ export declare function allGlobeAreas(): GlobeArea[];
@@ -0,0 +1,40 @@
1
+ // 球面图上「能着色的一块地」:国家 或 一级区划 —— 统一查找 ✓。
2
+ //
3
+ // 为什么要有这一层:URL 里的键有两种形状 ——
4
+ // 国家 `US` / `USA` / `United States` ⇒ ISO 3166-1 ✓
5
+ // 一级区划 `CN-44` / `广东` / `44` ⇒ ISO 3166-2 ✓
6
+ // ⇒ 画的时候只关心「这块地的多边形」✓ ⇒ 合成一个类型 ✓(服务端与浏览器端同一份 ✓)。
7
+ import { GLOBE_COUNTRIES } from './globe-proj.js';
8
+ import { resolveCountry } from './globe-keys.js';
9
+ import { GLOBE_REGIONS, resolveRegion } from './globe-regions.js';
10
+ /**
11
+ * 找一块地 ✓
12
+ *
13
+ * 顺序:先当国家查(`US` ✓)· 再当一级区划查(`CN-44` ✓)——
14
+ * ⚠️ **先国家后区划**:只给两位码(`44`)时,区划表里能查到 ✓;
15
+ * 而 `CN` 这种两字母的永远是国家 ✓(不会撞 ✓)。
16
+ */
17
+ export function resolveGlobeArea(key) {
18
+ const k = key.trim();
19
+ if (!k)
20
+ return null;
21
+ const c = resolveCountry(k);
22
+ if (c && c.iso2) {
23
+ return { kind: 'country', key: c.iso2, name: c.name, polygon: c.polygon };
24
+ }
25
+ const r = resolveRegion(k);
26
+ if (r) {
27
+ return { kind: 'region', key: r.key, name: r.name, polygon: r.polygon };
28
+ }
29
+ return null;
30
+ }
31
+ /** 全部可着色的地(国家 + 区划 ✓)—— 图例/下拉用 ✓ */
32
+ export function allGlobeAreas() {
33
+ const countries = GLOBE_COUNTRIES
34
+ .filter((c) => c.iso2)
35
+ .map((c) => ({ kind: 'country', key: c.iso2, name: c.name, polygon: c.polygon }));
36
+ const regions = GLOBE_REGIONS.map((r) => ({
37
+ kind: 'region', key: r.key, name: r.name, polygon: r.polygon,
38
+ }));
39
+ return countries.concat(regions);
40
+ }
@@ -0,0 +1,78 @@
1
+ import { type GlobeView } from '@x-cmd/draw/globe';
2
+ /**
3
+ * 分段色标 —— **跟平面世界地图那套 visualMap 同一套** ✓
4
+ *
5
+ * 为什么要同一套:同一个数据在平面图与球面上得是同一个颜色 ⇒
6
+ * 「3D 视图」切过去才认得出是同一张图 ✓(explore 页的页内切换就靠这个 ✓)。
7
+ * (之前球面用琥珀→红 ⇒ 跟平面图的蓝对不上 ⇒ 看着像两张不同的图 ✗)
8
+ */
9
+ export interface ScalePiece {
10
+ min: number;
11
+ max: number;
12
+ color: string;
13
+ label: string;
14
+ }
15
+ /** 分段色标:值 → 那一段的颜色 ✓ */
16
+ export declare function rampAt(t: number, pieces: ScalePiece[]): string;
17
+ /** 地球上的一个点(城市)✓ */
18
+ export interface EarthNode {
19
+ id: string;
20
+ label: string;
21
+ sub?: string;
22
+ /** 类型(db/cloud/ext/… ⇒ 点的颜色 ✓)—— 侧栏改完要重写 URL ⇒ 得留着 ✓ */
23
+ kind?: string;
24
+ lat: number;
25
+ lon: number;
26
+ /** 量值(来自 val= ✓) */
27
+ value?: number;
28
+ color: string;
29
+ hl?: boolean;
30
+ }
31
+ /** 地球上的连线(两端可以是节点 id,也可以是国家码 ✓) */
32
+ export interface EarthLink {
33
+ from: string;
34
+ to: string;
35
+ label?: string;
36
+ /** 两端的经纬度 ✓ */
37
+ a: [number, number];
38
+ b: [number, number];
39
+ }
40
+ /**
41
+ * 有值的一块地(要上色的 ✓)
42
+ *
43
+ * 键有两种形状 ✓:国家(`US` ✓)或一级区划(`CN-44` ✓)——
44
+ * 主键一律 ISO ✓(ISO 3166-1 / ISO 3166-2 ✓);老名字也认 ✓。
45
+ */
46
+ export interface EarthCountry {
47
+ /** ISO 键(国家 alpha-2 ✓ / 区划 `<alpha2>-<code>` ✓) */
48
+ key: string;
49
+ /** ISO alpha-3(国家才有 ✓;区划为空 ✓) */
50
+ iso3: string;
51
+ /** 显示名 ✓ */
52
+ name: string;
53
+ value: number;
54
+ /** 上好的色(量值越大越暖 ✓)—— 客户端补画背面的国家时用同一个色 ✓ */
55
+ color: string;
56
+ }
57
+ /** 地球的场景(视角也是场景的一部分 ✓) */
58
+ export interface EarthScene {
59
+ mode: 'earth';
60
+ nodes: EarthNode[];
61
+ links: EarthLink[];
62
+ countries: EarthCountry[];
63
+ view: GlobeView;
64
+ legend?: {
65
+ title: string;
66
+ min: string;
67
+ max: string;
68
+ pieces?: ScalePiece[];
69
+ };
70
+ }
71
+ /** URL → 地球场景 ✓ */
72
+ export declare function earthSceneFromUrl(url: URL): EarthScene;
73
+ export interface EarthOpts {
74
+ interactive?: boolean;
75
+ width?: number;
76
+ }
77
+ /** 地球场景 → SVG ✓(正射投影 ✓) */
78
+ export declare function renderEarthGlobe(scene: EarthScene, opts?: EarthOpts): string;