@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
@@ -1,5 +1,5 @@
1
1
  import { card } from '../theme.js';
2
- import { esc, fmtFull, fmtNum, niceTicks, r2, trunc, svgDoc, titleBlock, yAxisGrid, pushBarLabelsAllOrNothing, labelStride, textW, LabelPlacer, reserveBands, markPoints, marksLayer } from './svg.js';
2
+ import { axisTitleY, colorRef, esc, fmtFull, fmtNum, LabelPlacer, labelStride, markPoints, marksLayer, niceTicks, pushBarLabelsAllOrNothing, r2, refLabelReserve, refLineLayer, refLinesOf, reserveBands, scaleMeta, subtitleBlock, svgDoc, textW, titleBlock, trunc, yAxisGrid } from './svg.js';
3
3
  import { yTickInset } from './measure.js';
4
4
  /**
5
5
  * Single-series bar chart.
@@ -11,7 +11,7 @@ export function renderBar(spec, o) {
11
11
  const max = Math.max(...values);
12
12
  const peakIdx = values.indexOf(max);
13
13
  const pad = 24;
14
- const contentTop = pad + (spec.title ? 32 : 0) + (spec.unit ? 18 : 0) + 20;
14
+ const contentTop = pad + (spec.title || spec.subtitle ? 32 : 0) + (spec.unit ? 18 : 0) + 20;
15
15
  // 柱宽不足以容纳数值标签时自动加宽画布(封顶 2.5×),让数字留在柱内
16
16
  const nBars = spec.data.length;
17
17
  // 按缩字号下限(7px)估标签宽:只有"扩了真能装进柱"才扩宽(封顶 1.5×),
@@ -33,7 +33,9 @@ export function renderBar(spec, o) {
33
33
  if (need < width)
34
34
  width = Math.round(Math.max(320, need));
35
35
  }
36
- const right = width - pad;
36
+ // 参考线文案在绘图区右边 —— 先给它腾出位置(否则只能翻到左边跟刻度叠字)
37
+ const refReserve = refLabelReserve(refLinesOf(o));
38
+ const right = width - pad - refReserve;
37
39
  const bottom = height - pad - 30;
38
40
  const yMax = ticks[ticks.length - 1];
39
41
  const y = (v) => bottom - (v / yMax) * (bottom - contentTop);
@@ -46,6 +48,21 @@ export function renderBar(spec, o) {
46
48
  ];
47
49
  // 网格线 + 刻度 + 基线
48
50
  yAxisGrid(parts, ticks, y, left, right, bottom, skin.rules.grid, skin.rules.gridDash);
51
+ // 单位:显式给了 unit= 就画出来(柱图早就给它留了空位 ✓)
52
+ if (spec.unit)
53
+ parts.push(axisTitleY(spec.unit, (contentTop + bottom) / 2, left - 26));
54
+ // 参考线画在柱之下:它是参照,不是数据
55
+ if (refLinesOf(o).length) {
56
+ refLineLayer(parts, {
57
+ refs: refLinesOf(o),
58
+ toPixel: y,
59
+ plot: { start: bottom, end: contentTop },
60
+ span: { from: left, to: right },
61
+ orient: 'h',
62
+ width,
63
+ height,
64
+ });
65
+ }
49
66
  // 柱体:墨色、仅顶角圆角 4px
50
67
  const n = spec.data.length;
51
68
  const step = (right - left) / n;
@@ -61,7 +78,9 @@ export function renderBar(spec, o) {
61
78
  const path = `M${r2(x)} ${r2(bottom)}V${r2(yt + m)}Q${r2(x)} ${r2(yt)} ${r2(x + m)} ${r2(yt)}` +
62
79
  `H${r2(x + barW - m)}Q${r2(x + barW)} ${r2(yt)} ${r2(x + barW)} ${r2(yt + m)}V${r2(bottom)}Z`;
63
80
  const tip = o.interactive ? ` data-tip="${esc(`${d.label} · ${fmtFull(d.value)}${spec.unit ? ' ' + spec.unit : ''}`)}"` : '';
64
- parts.push(`<path d="${path}" fill="url(#dg-bar)"${tip}/>`);
81
+ // 逐点色(colors= 指定了某个类目的颜色):那个类目用自己的颜色,其余仍是主题渐变
82
+ const fill = colorRef(d.color, 'url(#dg-bar)');
83
+ parts.push(`<path d="${path}" fill="${fill}"${tip}/>`);
65
84
  const isPeak = i === peakIdx;
66
85
  // 零值不标:没有柱子的"0"是噪音(标注克制原则)
67
86
  if (d.value > 0 && (num === 'all' || (num === 'peak' && isPeak))) {
@@ -69,7 +88,7 @@ export function renderBar(spec, o) {
69
88
  numItems.push({ x, yt, w: barW, hAvail: bottom - yt, text: fmtNum(d.value), fs: isPeak ? 13 : 11, peak: isPeak, fill: labelColor, haloColor: 'var(--d-s1)' });
70
89
  }
71
90
  if (i % xStride === 0)
72
- parts.push(`<text x="${r2(x + barW / 2)}" y="${r2(bottom + 20)}" text-anchor="middle" font-size="12" fill="var(--d-muted)">${esc(trunc(d.label, 12))}</text>`);
91
+ parts.push(`<text x="${r2(x + barW / 2)}" y="${r2(bottom + 20)}" text-anchor="middle" font-size="13" fill="var(--d-muted)">${d.label.length > 12 ? `<title>${esc(d.label)}</title>` : ''}${esc(trunc(d.label, 12))}</text>`);
73
92
  });
74
93
  const placer = new LabelPlacer();
75
94
  // 预留 Y 刻度带与 X 标签带:数值标签不得压刻度
@@ -79,5 +98,7 @@ export function renderBar(spec, o) {
79
98
  const mpts = markPoints(o.marks, spec.data.map((d) => d.label), (i) => left + step * i + step / 2, y, [contentTop, bottom]);
80
99
  if (mpts.length > 0)
81
100
  parts.push(marksLayer(mpts, width));
82
- return svgDoc(width, height, 'bar', version, spec.title ?? 'bar chart', spec, skin, bg + titleBlock(spec.title) + parts.join(''));
101
+ // 交互模式:像素↔值的映射(编辑器把参考线吸附到数据值上)
102
+ const dscale = o.interactive ? scaleMeta(0, bottom, yMax, contentTop, values) : '';
103
+ return svgDoc(width, height, 'bar', version, spec.title ?? 'bar chart', spec, skin, bg + titleBlock(spec.title) + subtitleBlock(spec.subtitle) + dscale + parts.join(''));
83
104
  }
@@ -0,0 +1,56 @@
1
+ import { resolveSkin } from '../styles/index.js';
2
+ import { type DrawResult } from './query.js';
3
+ /** 一块方块 */
4
+ export interface BlockItem {
5
+ id: string;
6
+ /** 所在列(从 0 起) */
7
+ col: number;
8
+ /** 显示的名字 */
9
+ label: string;
10
+ /** 属于哪个组(空 = 不在组里) */
11
+ group?: string;
12
+ }
13
+ /** 一个组(罩住几列) */
14
+ export interface BlockGroup {
15
+ id: string;
16
+ /** 罩住的列(从 0 起,升序) */
17
+ cols: number[];
18
+ /** 组的名字(挂在上沿) */
19
+ label: string;
20
+ }
21
+ /** 一条箭头 */
22
+ export interface BlockEdge {
23
+ from: string;
24
+ to: string;
25
+ }
26
+ /** 方块图的规格 */
27
+ export interface BlockSpec {
28
+ title?: string;
29
+ subtitle?: string;
30
+ /** 列数(每行放几块) */
31
+ cols: number;
32
+ items: BlockItem[];
33
+ groups: BlockGroup[];
34
+ edges: BlockEdge[];
35
+ }
36
+ /** 规格的 JSON 形态 → 规格 */
37
+ export declare function parseBlockSpec(raw: string): BlockSpec;
38
+ /** URL 参数 → 规格 */
39
+ export declare function blockSpecFromParams(params: URLSearchParams): BlockSpec;
40
+ /**
41
+ * 画一张方块图。
42
+ *
43
+ * 格子按 item= 的列号摆(同一列的方块上下排一行 —— 作者说了算,引擎不挪)。
44
+ * 每列的宽度按那一列最宽的标签算;组的框罩住它那几列。
45
+ */
46
+ export declare function renderBlock(spec: BlockSpec, o: {
47
+ width: number;
48
+ height: number;
49
+ version: number;
50
+ skin: ReturnType<typeof resolveSkin>;
51
+ interactive?: boolean;
52
+ }): string;
53
+ /**
54
+ * `/draw/block` 入口:GET ?cols=…&item=…&block=…&edge=…
55
+ */
56
+ export declare function renderBlockFromUrl(url: URL, interactive?: boolean): DrawResult;
@@ -0,0 +1,361 @@
1
+ // /draw/block —— 方块图(block-beta):一格一格的方块,箭头从一块指向另一块。
2
+ //
3
+ // 方块图不是流程图:没有自动布局引擎,作者摆好格子,引擎照着画。
4
+ // cols=<列数> 每行放几块(超过就换行)
5
+ // item=<id>|<col>|<label>|<groupId> 一块:在哪一列(从 0 起)、叫什么、属于哪个组
6
+ // block=<id>|<col>|<col>|…|<label> 一个组:罩住哪几列、叫什么
7
+ // edge=<from>|<to> 一条箭头
8
+ // title=<标题>
9
+ //
10
+ // 组的框罩在它罩住的那几列上(横跨整行的格子),标签挂在上沿。
11
+ // 组的框会盖住箭头 —— 所以框画在箭头底下,箭头压在上面。
12
+ import { ApiError } from '../specs/index.js';
13
+ import { resolveVersion } from '../version.js';
14
+ import { resolveSkin } from '../styles/index.js';
15
+ import { card } from '../theme.js';
16
+ import { clampInt, schemeParam } from './query.js';
17
+ import { esc, r2, sVar, svgDoc, subtitleBlock, textW, titleBlock, trunc } from './svg.js';
18
+ const PAD = 24;
19
+ const CELL_W = 132; // 一格的自然宽(标签比这宽就撑开)
20
+ const CELL_H = 52; // 一格的高
21
+ const GAP_X = 28; // 列间距
22
+ const GAP_Y = 40; // 行间距
23
+ const GROUP_PAD = 16; // 组的框离成员格的空当
24
+ // 组的标签牌骑在框的上沿(一半在框里、一半在框外)——
25
+ // 框的上沿只比成员高 GROUP_PAD,所以牌子不会碰到上面那一行的方块。
26
+ const CHIP_H = 20;
27
+ const N_EXAMPLE = 'cols=3&item=a|0|A&item=b|1|B&item=c|2|C&edge=a|b';
28
+ function bad(detail) {
29
+ throw new ApiError(400, `${detail} Example: /draw/block?${N_EXAMPLE}`);
30
+ }
31
+ /** 切 item= 的一段:`id|col|label|groupId`(groupId 可省) */
32
+ function parseItem(raw, i) {
33
+ const f = raw.split('|');
34
+ if (f.length < 3) {
35
+ bad(`"item" #${i + 1} must be "id|col|label[|groupId]", got ${JSON.stringify(raw)}`);
36
+ }
37
+ const id = f[0].trim();
38
+ const col = Number(f[1].trim());
39
+ const label = f[2].trim();
40
+ const group = f.length > 3 ? f[3].trim() : '';
41
+ if (!id)
42
+ bad(`"item" #${i + 1}: id is required`);
43
+ if (!Number.isInteger(col) || col < 0) {
44
+ bad(`"item" #${i + 1}: col must be a non-negative integer, got ${JSON.stringify(f[1])}`);
45
+ }
46
+ if (!label)
47
+ bad(`"item" #${i + 1}: label is required`);
48
+ return { id, col, label, ...(group ? { group } : {}) };
49
+ }
50
+ /** 切 block= 的一段:`id|col|col|…|label`(至少一列 + 一个名字) */
51
+ function parseGroup(raw, i) {
52
+ const f = raw.split('|');
53
+ if (f.length < 3) {
54
+ bad(`"block" #${i + 1} must be "id|col|col|…|label" (the columns it spans and a label), got ${JSON.stringify(raw)}`);
55
+ }
56
+ const id = f[0].trim();
57
+ const label = f[f.length - 1].trim();
58
+ const cols = f.slice(1, -1).map((c) => Number(c.trim()));
59
+ if (!id)
60
+ bad(`"block" #${i + 1}: id is required`);
61
+ if (!label)
62
+ bad(`"block" #${i + 1}: label is required`);
63
+ if (!cols.length || cols.some((c) => !Number.isInteger(c) || c < 0)) {
64
+ bad(`"block" #${i + 1}: the columns must be non-negative integers, got ${JSON.stringify(f.slice(1, -1).join(','))}`);
65
+ }
66
+ return { id, cols: [...new Set(cols)].sort((a, b) => a - b), label };
67
+ }
68
+ /** 规格的 JSON 形态 → 规格 */
69
+ export function parseBlockSpec(raw) {
70
+ let obj;
71
+ try {
72
+ obj = JSON.parse(raw);
73
+ }
74
+ catch {
75
+ bad(`block spec must be JSON, got ${JSON.stringify(raw.slice(0, 60))}`);
76
+ }
77
+ const o = (obj ?? {});
78
+ const items = Array.isArray(o.items) ? o.items : [];
79
+ if (!items.length)
80
+ bad('block spec needs at least one item');
81
+ const cols = Number(o.cols ?? 0) || Math.max(...items.map((it) => Number(it.col) + 1));
82
+ return {
83
+ ...(typeof o.title === 'string' && o.title.trim() ? { title: o.title.trim() } : {}),
84
+ ...(typeof o.subtitle === 'string' && o.subtitle.trim() ? { subtitle: o.subtitle.trim() } : {}),
85
+ cols,
86
+ items: items.map((it, i) => {
87
+ const id = String(it.id ?? '').trim();
88
+ const col = Number(it.col);
89
+ const label = String(it.label ?? '').trim();
90
+ const group = String(it.group ?? '').trim();
91
+ if (!id)
92
+ bad(`item #${i + 1}: id is required`);
93
+ if (!Number.isInteger(col) || col < 0)
94
+ bad(`item #${i + 1}: col must be a non-negative integer`);
95
+ if (!label)
96
+ bad(`item #${i + 1}: label is required`);
97
+ return { id, col, label, ...(group ? { group } : {}) };
98
+ }),
99
+ groups: (Array.isArray(o.groups) ? o.groups : []).map((g, i) => {
100
+ const id = String(g.id ?? '').trim();
101
+ const label = String(g.label ?? '').trim();
102
+ const cs = (g.cols ?? []).map(Number);
103
+ if (!id)
104
+ bad(`group #${i + 1}: id is required`);
105
+ if (!label)
106
+ bad(`group #${i + 1}: label is required`);
107
+ if (!cs.length || cs.some((c) => !Number.isInteger(c) || c < 0))
108
+ bad(`group #${i + 1}: cols must be non-negative integers`);
109
+ return { id, cols: [...new Set(cs)].sort((a, b) => a - b), label };
110
+ }),
111
+ edges: (Array.isArray(o.edges) ? o.edges : []).map((e, i) => {
112
+ const from = String(e.from ?? '').trim();
113
+ const to = String(e.to ?? '').trim();
114
+ if (!from || !to)
115
+ bad(`edge #${i + 1}: from and to are required`);
116
+ return { from, to };
117
+ }),
118
+ };
119
+ }
120
+ /** URL 参数 → 规格 */
121
+ export function blockSpecFromParams(params) {
122
+ const itemRaw = params.getAll('item').filter((v) => v.trim() !== '');
123
+ if (!itemRaw.length) {
124
+ bad(`at least one "item" is required (e.g. item=a|0|A)`);
125
+ }
126
+ const items = itemRaw.map(parseItem);
127
+ const groups = params.getAll('block').filter((v) => v.trim() !== '').map(parseGroup);
128
+ const ids = new Set();
129
+ for (const it of items) {
130
+ if (ids.has(it.id))
131
+ bad(`duplicate item id "${it.id}"`);
132
+ ids.add(it.id);
133
+ }
134
+ const groupIds = new Set(groups.map((g) => g.id));
135
+ for (const it of items) {
136
+ if (it.group && !groupIds.has(it.group)) {
137
+ bad(`item "${it.id}" points at unknown group "${it.group}"`);
138
+ }
139
+ }
140
+ const edges = params.getAll('edge').filter((v) => v.trim() !== '').map((e, i) => {
141
+ const f = e.split('|').map((x) => x.trim());
142
+ if (f.length < 2)
143
+ bad(`"edge" #${i + 1} must be "from|to", got ${JSON.stringify(e)}`);
144
+ if (!ids.has(f[0]))
145
+ bad(`"edge" #${i + 1}: unknown item "${f[0]}"`);
146
+ if (!ids.has(f[1]))
147
+ bad(`"edge" #${i + 1}: unknown item "${f[1]}"`);
148
+ return { from: f[0], to: f[1] };
149
+ });
150
+ const cols = clampInt(params, 'cols', 0, 1, 12);
151
+ const maxCol = Math.max(...items.map((it) => it.col));
152
+ const title = params.get('title')?.trim() || undefined;
153
+ const subtitle = params.get('subtitle')?.trim() || undefined;
154
+ return {
155
+ ...(title ? { title } : {}),
156
+ ...(subtitle ? { subtitle } : {}),
157
+ // cols= 没给就按最右边那列 +1 算(一行放得下)
158
+ cols: cols > 0 ? cols : maxCol + 1,
159
+ items,
160
+ groups,
161
+ edges,
162
+ };
163
+ }
164
+ const DEFS = `<defs>` +
165
+ `<marker id="bl-a" viewBox="0 0 10 10" refX="8.5" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0 0L10 5L0 10z" fill="var(--d-muted)"/></marker>` +
166
+ `</defs>`;
167
+ /**
168
+ * 画一张方块图。
169
+ *
170
+ * 格子按 item= 的列号摆(同一列的方块上下排一行 —— 作者说了算,引擎不挪)。
171
+ * 每列的宽度按那一列最宽的标签算;组的框罩住它那几列。
172
+ */
173
+ export function renderBlock(spec, o) {
174
+ const width = o.width;
175
+ const height = o.height;
176
+ const skin = o.skin;
177
+ const items = spec.items;
178
+ if (!items.length)
179
+ bad('block needs at least one item');
180
+ const titleH = spec.title ? 40 : 30; // 没标题也留一条带:右上角那枚角标在那儿
181
+ const subH = spec.subtitle ? 18 : 0;
182
+ const top = PAD + titleH + subH;
183
+ // 每列的宽度:那一列所有方块里最宽的标签(组标签不算 —— 它挂在框上,不受列宽管)
184
+ const colCount = Math.max(spec.cols, ...items.map((it) => it.col + 1));
185
+ const colW = new Array(colCount).fill(0);
186
+ for (const it of items) {
187
+ const w = Math.max(CELL_W, textW(trunc(it.label, 22), 13) + 40);
188
+ colW[it.col] = Math.max(colW[it.col], w);
189
+ }
190
+ // 空列也有宽度(不然列号与画出来的位置对不上)
191
+ for (let c = 0; c < colCount; c++)
192
+ if (!colW[c])
193
+ colW[c] = CELL_W;
194
+ // 列位置
195
+ const colX = new Array(colCount).fill(0);
196
+ let x = PAD;
197
+ for (let c = 0; c < colCount; c++) {
198
+ colX[c] = x;
199
+ x += colW[c] + GAP_X;
200
+ }
201
+ const gridW = x - GAP_X + PAD;
202
+ // 行:同一列里出现的方块按顺序往下排
203
+ const rowsPerCol = Array.from({ length: colCount }, () => []);
204
+ for (const it of items)
205
+ rowsPerCol[it.col].push(it);
206
+ const rowCount = Math.max(1, ...rowsPerCol.map((r) => r.length));
207
+ // 每行的高度:那一行最高的一格(标签可能两行)
208
+ const rowH = new Array(rowCount).fill(0);
209
+ const rowOf = new Map();
210
+ const cells = new Map();
211
+ const labelLines = new Map();
212
+ rowsPerCol.forEach((list, col) => {
213
+ list.forEach((it, i) => {
214
+ const lines = wrapLabel(it.label, colW[col] - 24);
215
+ labelLines.set(it.id, lines);
216
+ const h = Math.max(CELL_H, lines.length * 16 + 22);
217
+ rowH[i] = Math.max(rowH[i], h);
218
+ rowOf.set(it.id, i);
219
+ });
220
+ });
221
+ const rowY = new Array(rowCount).fill(0);
222
+ let y = top;
223
+ for (let r = 0; r < rowCount; r++) {
224
+ rowY[r] = y;
225
+ y += rowH[r] + GAP_Y;
226
+ }
227
+ const gridH = y - GAP_Y + PAD;
228
+ // 落盒:同一行的方块(不同列)顶部对齐
229
+ rowsPerCol.forEach((list, col) => {
230
+ list.forEach((it, i) => {
231
+ const h = Math.max(CELL_H, (labelLines.get(it.id) ?? []).length * 16 + 22);
232
+ cells.set(it.id, { x: colX[col], y: rowY[i], w: colW[col], h, row: i, col });
233
+ });
234
+ });
235
+ const canvasW = Math.max(width, gridW);
236
+ const canvasH = Math.max(height, gridH);
237
+ const parts = [];
238
+ parts.push(DEFS);
239
+ // 组的标签牌:最后画(它挂在框上沿,可能被上面那一行的方块盖住)
240
+ const groupChips = [];
241
+ // 组的框:罩住它的成员(上下都留 GROUP_PAD),标签挂在上沿
242
+ for (const g of spec.groups) {
243
+ const members = items.filter((it) => it.group === g.id);
244
+ const mboxes = members.map((it) => cells.get(it.id)).filter(Boolean);
245
+ if (!mboxes.length)
246
+ continue;
247
+ // 左右缘:成员盒子的最左/最右(列号只作退路 —— 跨行的组列号会绕回)
248
+ const gx = Math.min(...mboxes.map((b) => b.x)) - GROUP_PAD;
249
+ const gw = Math.max(...mboxes.map((b) => b.x + b.w)) - gx + GROUP_PAD;
250
+ // 上下缘:成员盒子的上下沿
251
+ const gy = Math.min(...mboxes.map((b) => b.y)) - GROUP_PAD;
252
+ const gh = Math.max(...mboxes.map((b) => b.y + b.h)) - Math.min(...mboxes.map((b) => b.y)) + GROUP_PAD * 2;
253
+ const color = sVar((spec.groups.indexOf(g) + 3) % 10);
254
+ // 框:中性虚线(跟 archmap 的分组框一个样)—— 框是「区域」,不是数据
255
+ parts.push(`<rect x="${r2(gx)}" y="${r2(gy)}" width="${r2(gw)}" height="${r2(gh)}" rx="12" fill="none" stroke="var(--d-border)" stroke-width="1.2" stroke-dasharray="6 4"/>`);
256
+ // 组的标签:骑在框的上沿(像图例)—— 牌子一半在框里、一半在框外
257
+ const lw = textW(g.label, 11) + 20;
258
+ const chipY = gy - CHIP_H / 2;
259
+ groupChips.push(`<rect x="${r2(gx + 10)}" y="${r2(chipY)}" width="${r2(lw)}" height="${CHIP_H}" rx="6" fill="var(--d-card)" stroke="${color}" stroke-opacity="0.65" stroke-width="1"/>`, `<text x="${r2(gx + 10 + lw / 2)}" y="${r2(chipY + 14)}" text-anchor="middle" font-size="11" font-weight="700" letter-spacing="0.6" fill="${color}">${esc(g.label)}</text>`);
260
+ }
261
+ // 箭头:从源块的右边出、目标块的左边进(同一列就上下走)
262
+ const byId = new Map(items.map((it) => [it.id, cells.get(it.id)]));
263
+ for (const e of spec.edges) {
264
+ const a = byId.get(e.from);
265
+ const b = byId.get(e.to);
266
+ if (!a || !b)
267
+ continue;
268
+ const ia = o.interactive ? ` data-from="${esc(e.from)}" data-to="${esc(e.to)}"` : '';
269
+ let d;
270
+ if (a.row === b.row && a.col < b.col) {
271
+ // 同行:右边 → 左边,中间那一段走直线
272
+ const x1 = a.x + a.w;
273
+ const x2 = b.x;
274
+ const cy = a.y + a.h / 2;
275
+ d = `M${r2(x1)} ${r2(cy)}L${r2(x2 - 6)} ${r2(cy)}`;
276
+ }
277
+ else if (a.row === b.row && a.col > b.col) {
278
+ // 同行反向:绕到下面走(不穿别的盒子)
279
+ const x1 = a.x;
280
+ const x2 = b.x + b.w;
281
+ const yb = a.y + a.h + 18;
282
+ d = `M${r2(x1)} ${r2(a.y + a.h / 2)}L${r2(x1 - 12)} ${r2(a.y + a.h / 2)}L${r2(x1 - 12)} ${r2(yb)}L${r2(x2 + 12)} ${r2(yb)}L${r2(x2 + 12)} ${r2(b.y + b.h / 2)}L${r2(x2)} ${r2(b.y + b.h / 2)}`;
283
+ }
284
+ else {
285
+ // 跨行:出底/右边 → 进顶/左边,走一段折线
286
+ const fromRight = b.x >= a.x + a.w;
287
+ const x1 = fromRight ? a.x + a.w : a.x + a.w / 2;
288
+ const y1 = fromRight ? a.y + a.h / 2 : a.y + a.h;
289
+ const x2 = fromRight ? b.x : b.x + b.w / 2;
290
+ const y2 = fromRight ? b.y + b.h / 2 : b.y;
291
+ const midX = (x1 + x2) / 2;
292
+ d = `M${r2(x1)} ${r2(y1)}L${r2(midX)} ${r2(y1)}L${r2(midX)} ${r2(y2)}L${r2(x2 - (fromRight ? 6 : 0))} ${r2(y2)}`;
293
+ }
294
+ parts.push(`<path d="${d}"${ia} fill="none" stroke="var(--d-muted)" stroke-width="1.4" marker-end="url(#bl-a)"/>`);
295
+ }
296
+ // 方块:圆角盒子 + 左侧色条 + 名字(archmap 那张脸)
297
+ items.forEach((it, i) => {
298
+ const b = cells.get(it.id);
299
+ const color = sVar(i % 10);
300
+ const lines = labelLines.get(it.id) ?? [it.label];
301
+ const tip = o.interactive
302
+ ? ` data-tip="${esc(`${it.label}${it.group ? ` · ${it.group}` : ''}`)}" tabindex="0"`
303
+ : '';
304
+ const textY = lines.length === 1
305
+ ? b.y + b.h / 2 + 4.5
306
+ : b.y + b.h / 2 - (lines.length - 1) * 8 + 4.5;
307
+ parts.push(`<g${tip}>` +
308
+ `<rect x="${r2(b.x)}" y="${r2(b.y)}" width="${r2(b.w)}" height="${r2(b.h)}" rx="9" fill="var(--d-card)" stroke="var(--d-border)" stroke-width="1"/>` +
309
+ `<rect x="${r2(b.x)}" y="${r2(b.y)}" width="3.5" height="${r2(b.h)}" rx="1.5" fill="${color}"/>` +
310
+ lines.map((l, li) => `<text x="${r2(b.x + b.w / 2 + 2)}" y="${r2(textY + li * 16)}" text-anchor="middle" font-size="13" font-weight="500" fill="var(--d-ink)">${esc(l)}</text>`).join('') +
311
+ `</g>`);
312
+ });
313
+ const iStyle = o.interactive
314
+ ? `<style>#bl g[data-tip]{cursor:pointer;transition:filter .12s ease}#bl g[data-tip]:hover{filter:brightness(1.2)}</style>`
315
+ : '';
316
+ parts.unshift(iStyle);
317
+ // 组的标签牌压在最上(不能被方块盖住)
318
+ parts.push(...groupChips);
319
+ const head = titleBlock(spec.title, PAD) + subtitleBlock(spec.subtitle, PAD, !!spec.title);
320
+ const bg = skin.rules.canvas === 'card' ? card(canvasW, canvasH) : '';
321
+ const meta = o.interactive
322
+ ? `<metadata id="bitems">${esc(JSON.stringify(spec))}</metadata>`
323
+ : '';
324
+ const aria = spec.title ?? `block diagram, ${items.length} blocks`;
325
+ return svgDoc(canvasW, canvasH, 'block', o.version, aria, spec, skin, bg + meta + head + `<g id="bl">${parts.join('')}</g>`);
326
+ }
327
+ /** 标签按格子宽度折行(中文逐字、拉丁按词) */
328
+ function wrapLabel(label, maxW) {
329
+ if (textW(label, 13) <= maxW)
330
+ return [label];
331
+ const atoms = label.match(/[A-Za-z0-9'’\-]+\s*|[^\s]/g) ?? [...label];
332
+ const lines = [];
333
+ let cur = '';
334
+ for (const a of atoms) {
335
+ if (textW(cur + a, 13) <= maxW) {
336
+ cur += a;
337
+ continue;
338
+ }
339
+ if (cur.trim())
340
+ lines.push(cur.trimEnd());
341
+ cur = a.trimStart();
342
+ if (lines.length >= 2)
343
+ break;
344
+ }
345
+ if (cur.trim() && lines.length < 2)
346
+ lines.push(cur.trimEnd());
347
+ return lines.length ? lines : [trunc(label, 22)];
348
+ }
349
+ /**
350
+ * `/draw/block` 入口:GET ?cols=…&item=…&block=…&edge=…
351
+ */
352
+ export function renderBlockFromUrl(url, interactive = false) {
353
+ const params = url.searchParams;
354
+ const spec = blockSpecFromParams(params);
355
+ const v = resolveVersion(params.get('v'));
356
+ const skin = resolveSkin('sankey', params.get('t'), schemeParam(params));
357
+ const width = clampInt(params, 'w', 720, 200, 2400);
358
+ const height = clampInt(params, 'h', 320, 140, 2400);
359
+ const svg = renderBlock(spec, { width, height, version: v.version, skin, interactive });
360
+ return { svg, version: v.version, cacheControl: v.cacheControl };
361
+ }
@@ -48,8 +48,11 @@ export function renderButterfly(spec, o) {
48
48
  if (right.length)
49
49
  legendItems.push({ name: withUnit(right[0].name), color: right[0].color, index: left.length ? 1 : 0 });
50
50
  }
51
- if (line)
51
+ // 折线的名字若与某个条段重名(同一个指标画了条又画了线)⇒ 图例只留一条 ——
52
+ // 同一个名字出现两次,读者会以为是两个指标 ✗
53
+ if (line && !legendItems.some((it) => it.name === withUnit(line.name))) {
52
54
  legendItems.push({ name: withUnit(line.name), color: 'var(--d-s9)', index: legendItems.length });
55
+ }
53
56
  const parts = [card(width, height, true)];
54
57
  // 图例单独一行(标题下面):双翼图的图例项可能很多,和标题并排会撞在一起
55
58
  const contentTop = PAD + titleH + (legendItems.length ? LEGEND_H : 0);
@@ -32,16 +32,46 @@ const colorVar = (ctx, kind) => {
32
32
  function sortItems(items) {
33
33
  return [...items].sort((a, b) => (a.time ?? '99:99').localeCompare(b.time ?? '99:99'));
34
34
  }
35
- /** 按像素宽度截断(挤的格子里文字不能串到隔壁格) */
35
+ /**
36
+ * 按像素宽度截断(挤的格子里文字不能串到隔壁格)。
37
+ *
38
+ * 截掉的那部分**放进 <title>** ⇒ 悬停能看全名 ——
39
+ * 「Natio…」读者只能猜,「National Day」在标题里就够用了 ✓
40
+ */
36
41
  function fitText(s, maxW, fs) {
37
42
  if (maxW <= 8)
38
- return trunc(s, 2);
43
+ return `<title>${esc(s)}</title>${esc(trunc(s, 2))}`;
39
44
  if (textW(s, fs) <= maxW)
40
- return s;
45
+ return esc(s);
41
46
  let t = s;
42
47
  while (t.length > 1 && textW(t + '…', fs) > maxW)
43
48
  t = t.slice(0, -1);
44
- return t + '…';
49
+ return `<title>${esc(s)}</title>${esc(t)}…`;
50
+ }
51
+ /** 按像素宽度折行(最多 maxLines 行)—— 挤的格子里文字不能串到隔壁格,也不能截掉一半 */
52
+ function wrapLines(s, maxW, fs, maxLines = 2) {
53
+ if (!s)
54
+ return [''];
55
+ if (textW(s, fs) <= maxW)
56
+ return [s];
57
+ const words = s.split(/\s+/).filter(Boolean);
58
+ const lines = [];
59
+ let line = '';
60
+ for (const w of words) {
61
+ const cand = line ? line + ' ' + w : w;
62
+ if (line && textW(cand, fs) > maxW) {
63
+ lines.push(line);
64
+ line = w;
65
+ if (lines.length >= maxLines)
66
+ break;
67
+ }
68
+ else
69
+ line = cand;
70
+ }
71
+ if (line && lines.length < maxLines)
72
+ lines.push(line);
73
+ // 还是太长 ⇒ 最后一行再截(但带上 title,悬停能看全)
74
+ return lines.map((l) => (textW(l, fs) > maxW ? fitText(l, maxW, fs) : l));
45
75
  }
46
76
  /** 某一天是休息日吗(默认:周末) */
47
77
  function isRest(ctx, date) {
@@ -129,11 +159,12 @@ function monthGrid(ctx, y, m, x, y0, w, h, dense = false, headY) {
129
159
  const dl = ctx.dayOf(iso)?.label;
130
160
  if (dl) {
131
161
  const dfill = holiday ? 'var(--d-mark)' : 'var(--d-text)';
132
- parts.push(`<text x="${r2(cx + 6)}" y="${r2(cy + 16)}" font-size="${EV_FS}" fill="${dfill}">${esc(fitText(dl, cw - 30, EV_FS))}</text>`);
162
+ parts.push(`<text x="${r2(cx + 6)}" y="${r2(cy + 16)}" font-size="${EV_FS}" fill="${dfill}">${fitText(dl, cw - 30, EV_FS)}</text>`);
133
163
  }
134
164
  // 事件
135
165
  const items = ctx.itemsOn(iso);
136
166
  const room = cw - 26; // 小圆点 + 边距
167
+ let ey = cy + 32; // 事件行的当前 y(折行会把它往下推 ⇒ 「+N」跟着走)
137
168
  if (dense) {
138
169
  // 格子窄:只摆小圆点(哪些天有事),名字留给周历/备注
139
170
  items.slice(0, 8).forEach((it, i) => {
@@ -144,17 +175,21 @@ function monthGrid(ctx, y, m, x, y0, w, h, dense = false, headY) {
144
175
  }
145
176
  else {
146
177
  const maxRows = Math.max(1, Math.floor((ch - 22) / 15));
147
- items.slice(0, maxRows).forEach((it, i) => {
148
- const ey = cy + 32 + i * 15;
178
+ // 名字**折行**而不是截断(截一半等于给错信息):一行放得下就一行,
179
+ // 放不下折成两行,行高按折了几行算 ⇒ 折行的那条把下面几行挤下去
180
+ for (const it of items.slice(0, maxRows)) {
181
+ const lines = wrapLines(it.label, room, EV_FS, 2);
149
182
  parts.push(`<circle cx="${r2(cx + 9)}" cy="${r2(ey - 4)}" r="3" fill="${ctx.colorOf(it.kind)}"/>`);
150
183
  // 月历不写时间(苹果的月视图也不写)—— 格子窄,时间会把名字挤没
151
- const label = it.label;
152
- parts.push(`<text x="${r2(cx + 16)}" y="${r2(ey)}" font-size="${EV_FS}" fill="var(--d-text)">${esc(fitText(label, room, EV_FS))}</text>`);
153
- });
184
+ lines.forEach((ln, li) => {
185
+ parts.push(`<text x="${r2(cx + 16)}" y="${r2(ey + li * 13)}" font-size="${EV_FS}" fill="var(--d-text)">${esc(ln)}</text>`);
186
+ });
187
+ ey += lines.length * 13 + 2;
188
+ }
154
189
  // 下一行:先是「+N」(自己占一行),再排备注 —— 备注跟「+N」挤一行会被盖住
155
190
  let row = maxRows;
156
191
  if (items.length > maxRows) {
157
- parts.push(`<text x="${r2(cx + 6)}" y="${r2(cy + 32 + row * 15)}" font-size="11" fill="var(--d-muted)">+${items.length - maxRows}</text>`);
192
+ parts.push(`<text x="${r2(cx + 6)}" y="${r2(ey + 4)}" font-size="11" fill="var(--d-muted)">+${items.length - maxRows}</text>`);
158
193
  // 没画出来的别丢 —— 提示单元会把它们列出来
159
194
  for (const it of items.slice(maxRows))
160
195
  ctx.overflow.push({ date: iso, label: it.label, time: it.time, kind: it.kind });
@@ -169,7 +204,7 @@ function monthGrid(ctx, y, m, x, y0, w, h, dense = false, headY) {
169
204
  ctx.overflow.push({ date: iso, label: n.text, kind: 'note' });
170
205
  return;
171
206
  }
172
- parts.push(`<text x="${r2(cx + 6)}" y="${r2(ny2)}" font-size="11" fill="var(--d-muted)">${esc(fitText(n.text, cw - 12, 11))}</text>`);
207
+ parts.push(`<text x="${r2(cx + 6)}" y="${r2(ny2)}" font-size="11" fill="var(--d-muted)">${fitText(n.text, cw - 12, 11)}</text>`);
173
208
  });
174
209
  }
175
210
  }
@@ -253,7 +288,7 @@ function planBoard(ctx, start, days, x, y0, w, rowH) {
253
288
  rows.forEach((it, r) => {
254
289
  const ry = y0 + r * rowH;
255
290
  parts.push(`<line x1="${r2(x)}" y1="${r2(ry)}" x2="${r2(x + w)}" y2="${r2(ry)}" stroke="var(--d-grid)" stroke-width="1"/>`);
256
- parts.push(`<text x="${r2(x + 4)}" y="${r2(ry + rowH / 2 + 4)}" font-size="12" fill="var(--d-ink)">${esc(trunc(it.label, 20))}</text>`);
291
+ parts.push(`<text x="${r2(x + 4)}" y="${r2(ry + rowH / 2 + 4)}" font-size="13" fill="var(--d-ink)">${esc(trunc(it.label, 20))}</text>`);
257
292
  const s = isoDay(it.date);
258
293
  const e = isoDay(it.until ?? it.date);
259
294
  const bx = x + labelW + (s - d0) * per;
@@ -359,7 +394,7 @@ export function renderCalendar(spec, o) {
359
394
  const mx = PAD + c * (mw + gap);
360
395
  const my = bodyTop + r * (mh + gap);
361
396
  const mm = { y: p.y, m: i + 1 };
362
- parts.push(`<text x="${r2(mx)}" y="${r2(my + 12)}" font-size="12" font-weight="600" fill="var(--d-ink)">${esc(skin.rules.title === 'editorial' ? MONTH_EN[i] : `${i + 1}月`)}</text>`);
397
+ parts.push(`<text x="${r2(mx)}" y="${r2(my + 12)}" font-size="13" font-weight="600" fill="var(--d-ink)">${esc(skin.rules.title === 'editorial' ? MONTH_EN[i] : `${i + 1}月`)}</text>`);
363
398
  parts.push(yearMini(ctx, mm.y, mm.m, mx, my + 20, mw, mh - 26));
364
399
  }
365
400
  }
@@ -0,0 +1,26 @@
1
+ export interface Center {
2
+ lat: number;
3
+ lon: number;
4
+ /** 数据里的国家名(经纬度的来源) */
5
+ name: string;
6
+ }
7
+ /** 名字 → 经纬度(数据里那份) */
8
+ export declare function centerByName(name: string): Center | undefined;
9
+ /** center= 的值 → 经纬度(国家名 或 lon,lat) */
10
+ export declare function parseCenter(raw: string | null): Center | undefined;
11
+ /**
12
+ * 球面镜头:转到某地正对着看。
13
+ * 实测(拿地球照片试的):alpha = -90 - 经度,beta = 纬度。
14
+ */
15
+ export declare function globeCamera(center: Center): {
16
+ alpha: number;
17
+ beta: number;
18
+ };
19
+ /**
20
+ * 投影后的国家重心 —— 平面地图的 center 要用**投影坐标**(世界地图是
21
+ * Mercator 投影过的,直接给经纬度会偏到地图外面去)。
22
+ *
23
+ * 取**最大那一块**的面积重心(不是所有顶点的平均):美国有阿拉斯加、夏威夷,
24
+ * 顶点平均会把重心拉到阿拉斯加去 ✗ —— 地图就不以美国为中心了。
25
+ */
26
+ export declare function projectedCenter(name: string): Promise<[number, number] | undefined>;