@fengwk/kchart 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +31 -2
  3. package/README.zh-CN.md +31 -2
  4. package/dist/esm/_virtual/_kchart-families.js +2 -1
  5. package/dist/esm/chart/composition.js +7 -5
  6. package/dist/esm/chart/maps.js +9 -7
  7. package/dist/esm/chart/mindmap.js +19 -5
  8. package/dist/esm/chart/multivariate.js +49 -14
  9. package/dist/esm/chart/relations.js +15 -7
  10. package/dist/esm/chart/spec.js +5 -2
  11. package/dist/esm/core/context.js +29 -10
  12. package/dist/esm/core/scene.js +238 -21
  13. package/dist/esm/core/text.js +1 -1
  14. package/dist/esm/diagram/block.js +287 -295
  15. package/dist/esm/diagram/blocks.js +541 -605
  16. package/dist/esm/diagram/board-paint.js +594 -0
  17. package/dist/esm/diagram/board-route.js +60 -0
  18. package/dist/esm/diagram/c4.js +75 -35
  19. package/dist/esm/diagram/class.js +3 -2
  20. package/dist/esm/diagram/cynefin.js +55 -9
  21. package/dist/esm/diagram/eventmodeling.js +4 -2
  22. package/dist/esm/diagram/gantt.js +37 -15
  23. package/dist/esm/diagram/gitgraph.js +26 -5
  24. package/dist/esm/diagram/graph-layout.js +39 -2
  25. package/dist/esm/diagram/graph-route.js +296 -38
  26. package/dist/esm/diagram/info.js +32 -0
  27. package/dist/esm/diagram/journey.js +5 -5
  28. package/dist/esm/diagram/kanban.js +3 -3
  29. package/dist/esm/diagram/layers.js +9 -7
  30. package/dist/esm/diagram/mindmap.js +5 -1
  31. package/dist/esm/diagram/numeric-composition.js +24 -4
  32. package/dist/esm/diagram/numeric-model.js +1 -1
  33. package/dist/esm/diagram/numeric-radar.js +25 -7
  34. package/dist/esm/diagram/numeric-sankey.js +4 -3
  35. package/dist/esm/diagram/numeric-xy.js +12 -2
  36. package/dist/esm/diagram/packet.js +4 -4
  37. package/dist/esm/diagram/quadrant.js +12 -5
  38. package/dist/esm/diagram/railroad-parse.js +20 -10
  39. package/dist/esm/diagram/railroad.js +1 -1
  40. package/dist/esm/diagram/registry.js +46 -8
  41. package/dist/esm/diagram/sequence.js +43 -6
  42. package/dist/esm/diagram/swimlane.js +2 -2
  43. package/dist/esm/diagram/time.js +3 -3
  44. package/dist/esm/diagram/timeline.js +5 -5
  45. package/dist/esm/diagram/treeview.js +5 -3
  46. package/dist/esm/diagram/venn.js +35 -15
  47. package/dist/esm/diagram/wardley.js +61 -26
  48. package/dist/esm/diagram/zenuml.js +338 -0
  49. package/dist/esm/index.d.ts +3 -1
  50. package/dist/esm/mermaid.d.ts +1 -1
  51. package/dist/esm/mermaid.js +2 -1
  52. package/dist/esm/node.js +8 -2
  53. package/dist/esm/src/families.js +6 -1
  54. package/dist/units/chart/composition.js +1 -1
  55. package/dist/units/chart/maps.js +1 -1
  56. package/dist/units/chart/mindmap.js +1 -1
  57. package/dist/units/chart/multivariate.js +1 -1
  58. package/dist/units/chart/relations.js +1 -1
  59. package/dist/units/chart/spec.js +1 -1
  60. package/dist/units/core/context.js +1 -1
  61. package/dist/units/core/scene.js +1 -1
  62. package/dist/units/core/text.js +1 -1
  63. package/dist/units/diagram/block.js +2 -2
  64. package/dist/units/diagram/blocks.js +2 -2
  65. package/dist/units/diagram/board-paint.js +1 -0
  66. package/dist/units/diagram/board-route.js +1 -0
  67. package/dist/units/diagram/c4.js +1 -1
  68. package/dist/units/diagram/class.js +2 -2
  69. package/dist/units/diagram/cynefin.js +2 -2
  70. package/dist/units/diagram/eventmodeling.js +1 -1
  71. package/dist/units/diagram/gantt.js +3 -3
  72. package/dist/units/diagram/gitgraph.js +2 -1
  73. package/dist/units/diagram/graph-layout.js +1 -1
  74. package/dist/units/diagram/graph-route.js +1 -1
  75. package/dist/units/diagram/info.js +2 -0
  76. package/dist/units/diagram/journey.js +3 -3
  77. package/dist/units/diagram/kanban.js +1 -1
  78. package/dist/units/diagram/layers.js +1 -1
  79. package/dist/units/diagram/mindmap.js +1 -1
  80. package/dist/units/diagram/numeric-composition.js +1 -1
  81. package/dist/units/diagram/numeric-model.js +1 -1
  82. package/dist/units/diagram/numeric-radar.js +2 -2
  83. package/dist/units/diagram/numeric-sankey.js +1 -1
  84. package/dist/units/diagram/numeric-xy.js +1 -1
  85. package/dist/units/diagram/packet.js +1 -1
  86. package/dist/units/diagram/quadrant.js +1 -1
  87. package/dist/units/diagram/railroad-parse.js +2 -2
  88. package/dist/units/diagram/railroad.js +1 -1
  89. package/dist/units/diagram/registry.js +2 -2
  90. package/dist/units/diagram/sequence.js +1 -1
  91. package/dist/units/diagram/swimlane.js +2 -2
  92. package/dist/units/diagram/time.js +1 -1
  93. package/dist/units/diagram/timeline.js +1 -1
  94. package/dist/units/diagram/treeview.js +1 -1
  95. package/dist/units/diagram/venn.js +1 -1
  96. package/dist/units/diagram/wardley.js +4 -4
  97. package/dist/units/diagram/zenuml.js +2 -0
  98. package/dist/units.json +79 -51
  99. package/package.json +1 -1
  100. package/dist/esm/diagram/relations.js +0 -966
  101. package/dist/units/diagram/relations.js +0 -3
@@ -1,684 +1,620 @@
1
1
  import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
- import { FONT, appearance, error, fallbackMeasure, maxWidthOf, snap, wrapText } from "./support.js";
2
+ import { FONT, error, warning } from "./support.js";
3
3
  import { geometry, has } from "../core/icons.js";
4
+ import { EDGE_KINDS, ITEM, STYLES, boardLook, drawCard, drawEdge, drawFrame, drawItem, drawLabel, drawLegend, drawNote, frameTitle, markers, measureCard, measureItem, measureLabel, measureLegend, measureNote, surfaceAt, titleRect } from "./board-paint.js";
5
+ import { routeBoard } from "./board-route.js";
4
6
  // src/diagram/blocks.js
5
7
  var blocks_exports = /* @__PURE__ */ __exportAll({ implementations: () => implementations });
6
- var LIMITS = Object.freeze({
7
- depth: 4,
8
- edges: 8,
9
- boxes: 80,
10
- items: 160,
8
+ var LIMITS = {
9
+ depth: 8,
10
+ endpoints: 400,
11
+ items: 1e3,
12
+ edges: 200,
11
13
  labelChars: 24,
12
- labelLines: 2,
13
- labelWidth: 312,
14
- titleLines: 3
15
- });
14
+ desc: 8
15
+ };
16
16
  var GAP = 16;
17
- var ARROW = 56;
18
17
  var PAD = 12;
19
- var ITEM_GAP = 8;
20
- var ITEM_H = 36;
21
- var HEADER = 36;
22
- var MARGIN = 4;
23
- var SPARSE_CELL = 260;
24
- var issue = (lang, line, zh, en, fixZh, fixEn) => error(lang, line, zh, en, fixZh, fixEn);
25
- function parse(source, info) {
26
- const { lang, options = {}, firstLine = 2 } = info;
27
- const errors = Object.keys(options).map((key) => issue(lang, firstLine - 1, `blocks 不支持选项「${key}」`, `Unsupported blocks option: ${key}`, "删除这个选项", "Remove this option"));
28
- const nodes = [], edges = [], stack = [], indents = [];
18
+ var ITEM_GAP = ITEM.gap;
19
+ var MARGIN = 16;
20
+ var HEAD = /^(row|col|grid|box|card|note|legend)(?:\s+(.*))?$/;
21
+ var LEGEND_KEYS = [
22
+ ...STYLES,
23
+ "default",
24
+ "db",
25
+ ...Object.keys(EDGE_KINDS)
26
+ ];
27
+ var ATTR = /\{((?:"[^"\n]*"|[^{}"]|"(?=[^"\n]*\}$))*)\}$/;
28
+ var ID = /^[A-Za-z_][A-Za-z0-9_-]*$/;
29
+ var RESERVED = /[::]|->|=>|~>/;
30
+ var count = (text) => [...text].length;
31
+ function attributes(header, kind, fail) {
32
+ const match = header.match(ATTR), title = (match ? header.slice(0, match.index) : header).trim();
33
+ const attrs = {};
34
+ const allowed = `${STYLES.join(", ")}, ${kind === "box" ? "db, " : "\"tag\", "}#XX, @id`;
35
+ const invalid = (token) => fail(`未知属性或属性位置无效:${token}`, `Unknown or misplaced attribute: ${token}`, `在标题末尾用 {...},仅使用:${allowed}`, `Use {...} after the title with only: ${allowed}`);
36
+ if (/[{}]/.test(title)) invalid(title);
37
+ for (const token of match?.[1].match(/(?:"[^"]*"|[^,\s"]+)+|"/g) || []) if (STYLES.includes(token)) {
38
+ if (attrs.style) fail("只能使用一种样式", "Only one style is allowed", "保留一个样式词", "Keep one style word");
39
+ else attrs.style = token;
40
+ } else if (token === "db" && kind === "box" && !attrs.db) attrs.db = true;
41
+ else if (token.startsWith("#")) {
42
+ if (attrs.badge || !/^#[0-9A-Za-z.-]{1,4}$/.test(token)) fail("徽章无效或重复", "Invalid or repeated badge", "只写一个 # 加 1–4 个字母、数字、点或连字符", "Use one # followed by 1–4 letters, digits, dots or hyphens");
43
+ else attrs.badge = token.slice(1);
44
+ } else if (token.startsWith("@")) {
45
+ if (attrs.ref || !ID.test(token.slice(1))) fail("引用 ID 无效或重复", "Invalid or repeated reference ID", "只写一个 @id,以字母或下划线开头,后接字母、数字、下划线或连字符", "Use one @id starting with a letter or underscore, followed by letters, digits, underscores or hyphens");
46
+ else attrs.ref = token.slice(1);
47
+ } else if (token.startsWith("\"") && kind === "card") {
48
+ const tag = token.slice(1, -1);
49
+ if (attrs.tag || !/^"[^"\n]+"$/.test(token) || !tag.trim() || count(tag) > 12) fail("标签无效、重复或过长", "Invalid, repeated or overlong tag", "只写一个双引号标签,最多 12 个字符", "Use one double-quoted tag of at most 12 characters");
50
+ else attrs.tag = tag;
51
+ } else invalid(token);
52
+ return {
53
+ title,
54
+ ...attrs
55
+ };
56
+ }
57
+ function parse(source, { lang, options = {}, firstLine = 2 }) {
58
+ const errors = [], nodes = [], edges = [], stack = [], indents = [], endpoints = [], items = [];
59
+ const refs = /* @__PURE__ */ new Map(), titles = /* @__PURE__ */ new Map(), nonEndpoints = /* @__PURE__ */ new Set();
60
+ const at = (line) => (zh, en, fixZh, fixEn) => errors.push(error(lang, line, zh, en, fixZh, fixEn));
61
+ const split = (fail, zh, en) => fail(zh, en, "拆成两张图", "Split into two diagrams");
62
+ for (const key of Object.keys(options)) at(firstLine - 1)(`blocks 不支持选项「${key}」`, `Unsupported blocks option: ${key}`, "删除这个选项", "Remove this option");
29
63
  for (const [i, raw] of String(source).split("\n").entries()) {
30
64
  if (!raw.trim() || raw.trimStart().startsWith("%%")) continue;
31
- const line = firstLine + i;
32
- if (/^\s*\t/.test(raw)) {
33
- errors.push(issue(lang, line, "缩进不能使用 Tab", "Tabs are not allowed in indentation", "把 Tab 换成空格", "Replace tabs with spaces"));
65
+ const line = firstLine + i, fail = at(line);
66
+ if (/^ *\t/.test(raw)) {
67
+ fail("缩进不能使用 Tab", "Tabs are not allowed in indentation", "把 Tab 换成空格", "Replace tabs with spaces");
34
68
  continue;
35
69
  }
36
- const indent = raw.match(/^ */)[0].length, text = raw.slice(indent).trim();
37
- const edge = text.match(/^(.+?)\s*(->|~>)\s*(.+?)(?:\s*[::]\s*(.*))?$/), head = /^(row|col|box)(?:\s|$)/.test(text);
70
+ const indent = raw.match(/^ */)[0].length, text = raw.trim();
38
71
  while (stack.length && indent <= stack.at(-1).indent) stack.pop();
39
72
  const parent = stack.at(-1);
73
+ if (parent?.kind === "card") {
74
+ parent.desc.push(text);
75
+ if (parent.desc.length === LIMITS.desc + 1) fail("卡片描述最多 8 行", "At most 8 card description lines", "合并描述行或拆成两张卡片", "Combine description lines or split into two cards");
76
+ continue;
77
+ }
78
+ if (parent?.kind === "legend") {
79
+ const entry = text.match(/^([^::]+)[::]\s*(.+)$/), key = entry?.[1].trim();
80
+ if (!entry || !LEGEND_KEYS.includes(key)) fail("图例键无效或缺少说明", "Unknown legend key or missing meaning", `使用「键: 说明」;键为 ${LEGEND_KEYS.join(", ")}`, `Use "key: meaning" with one of ${LEGEND_KEYS.join(", ")}`);
81
+ else if (parent.entries.some((item) => item.key === key)) fail(`图例键「${key}」重复`, `Repeated legend key: ${key}`, "合并同一个键的说明", "Combine the meanings for this key");
82
+ else parent.entries.push({
83
+ key,
84
+ label: entry[2]
85
+ });
86
+ continue;
87
+ }
88
+ let head = text.match(HEAD);
89
+ if (parent?.kind === "box" && head && (/^(card|note)$/.test(text) || head[1] === "legend" && head[2])) head = null;
90
+ const edge = text.match(/^(.+?)\s*(->|=>|~>)\s*(.+?)(?:\s*[::]\s*(.*))?$/);
40
91
  if (edge && !head && (!parent || parent.kind !== "box" || parent.inline)) {
41
- if (indent) errors.push(issue(lang, line, "关系必须写在顶格", "Relations must start at column 0", "去掉这一行的缩进", "Remove the indentation from this relation"));
92
+ if (indent) fail("关系必须写在顶格", "Relations must start at column 0", "去掉这一行的缩进", "Remove the indentation from this relation");
93
+ const label = (edge[4] || "").trim();
94
+ if (count(label) > LIMITS.labelChars) fail("关系标签过长", "Relation label is too long", "把标签缩到 24 个字符以内", "Keep the label within 24 characters");
42
95
  edges.push({
43
- from: edge[1].trim(),
44
- to: edge[3].trim(),
45
- async: edge[2] === "~>",
46
- label: (edge[4] || "").trim(),
96
+ id: `edge-${edges.length}`,
97
+ ends: [edge[1].trim(), edge[3].trim()],
98
+ kind: EDGE_KINDS[edge[2]],
99
+ label,
47
100
  line
48
101
  });
102
+ if (edges.length === LIMITS.edges + 1) split(fail, "关系最多 200 条", "At most 200 relations");
49
103
  continue;
50
104
  }
105
+ if (parent?.kind === "note") {
106
+ fail("note 不能有子条目", "Notes cannot have children", "将这一行退回到与 note 同级", "Move this line to the same indentation as the note");
107
+ continue;
108
+ }
109
+ const addItems = (box, value) => {
110
+ if (box.children.length) fail("box 不能混用能力项和结构行", "A box cannot mix capabilities and structure lines", "将能力项移到单独的 box", "Move capabilities to their own box");
111
+ for (const part of value.split(/[,,]/)) {
112
+ const raw = part.trim(), icon = raw.match(/^\[icon:([a-z0-9][\w.-]*)\]\s*/i), value = icon ? raw.slice(icon[0].length) : raw;
113
+ const mark = value.match(/^([+~=])\s*/)?.[1] || "", name = value.replace(/^[+~=]\s*/, "").trim();
114
+ if (!name) {
115
+ fail("能力项名称不能为空", "Capability labels cannot be empty", "删除空项或补上名称", "Remove the empty item or add a label");
116
+ continue;
117
+ }
118
+ if (icon ? !has(icon[1]) : /\[icon:/.test(raw)) fail("未知图标或图标写法无效", "Unknown icon or invalid icon syntax", "写成 [icon:database] 名称", "Use a valid icon, e.g. [icon:database] name");
119
+ const item = {
120
+ name,
121
+ label: mark ? `${mark} ${name}` : name,
122
+ mark,
123
+ tone: {
124
+ "+": "new",
125
+ "~": "info",
126
+ "=": "ok"
127
+ }[mark],
128
+ icon: icon?.[1],
129
+ line
130
+ };
131
+ box.items.push(item);
132
+ items.push(item);
133
+ nonEndpoints.add(name);
134
+ nonEndpoints.add(item.label);
135
+ if (items.length === LIMITS.items + 1) split(fail, "能力项最多 1000 个", "At most 1000 capabilities");
136
+ }
137
+ };
51
138
  if (!head && parent?.kind === "box" && !parent.inline) {
52
- parent.items.push(...parseItems(text, line, lang, errors));
139
+ addItems(parent, text);
140
+ continue;
141
+ }
142
+ if (!head) {
143
+ if (parent) fail("能力项只能写在 box 内", "Capabilities belong inside a box", "把这一行改成 box,或移入 box", "Change this line into a box or move it inside a box");
144
+ else fail("无法识别这一行", "Unrecognized line", "使用结构关键字,或写成「A -> B」", "Use a structure keyword or write a relation as \"A -> B\"");
53
145
  continue;
54
146
  }
55
147
  const depth = stack.length;
148
+ if (depth >= LIMITS.depth) {
149
+ split(fail, "嵌套超过 8 层", "Nesting exceeds 8 levels");
150
+ continue;
151
+ }
56
152
  indents[depth] ??= indent;
57
153
  if (indents[depth] !== indent) {
58
- errors.push(issue(lang, line, "同级条目的缩进不一致", "Inconsistent indentation at the same level", `把这一行缩进改为 ${indents[depth]} 个空格`, `Indent this line with ${indents[depth]} spaces`));
154
+ fail("同级条目的缩进不一致", "Inconsistent indentation at the same level", `把这一行缩进改为 ${indents[depth]} 个空格`, `Indent this line with ${indents[depth]} spaces`);
59
155
  continue;
60
156
  }
61
- if (stack.filter((entry) => entry.kind === "box").length + (text.startsWith("box") ? 1 : 0) > LIMITS.depth) {
62
- errors.push(issue(lang, line, `嵌套超过 ${LIMITS.depth} 层`, `Nesting exceeds ${LIMITS.depth} levels`, "把内层拆成另一张图", "Split the inner level into another diagram"));
63
- continue;
157
+ const kind = head[1];
158
+ let body = head[2] || "";
159
+ const node = {
160
+ kind,
161
+ line,
162
+ indent,
163
+ parent,
164
+ weight: 1,
165
+ children: [],
166
+ items: []
167
+ };
168
+ if (parent?.items.length) fail("box 不能混用能力项和结构行", "A box cannot mix capabilities and structure lines", "将子结构移到单独的 box", "Move the child structures to a separate box");
169
+ if (kind === "row" || kind === "col" || kind === "box") {
170
+ const weight = body.match(kind === "box" ? /^(\d+(?:\.\d+)?)\s+(?![::\s])/ : /^\d+(?:\.\d+)?$/);
171
+ if (weight) {
172
+ const number = Number(weight[0]);
173
+ if (number > 0 && Number.isFinite(number)) {
174
+ node.weight = number;
175
+ node.explicit = true;
176
+ } else if (kind !== "box" || !Number.isFinite(number)) fail("权重必须是有限正数", "Weight must be finite and positive", "使用较小的正数,例如 3", "Use a small positive number such as 3");
177
+ body = body.slice(weight[0].length);
178
+ } else if (kind !== "box" && body) fail(`${kind} 后面只能写权重`, `Only a weight may follow ${kind}`, "删除多余文字,或写成正数", "Remove the extra text or use a positive number");
179
+ }
180
+ if (kind === "box" || kind === "card") {
181
+ const colon = kind === "box" ? body.match(/^(?:\{[^}]*\}|[^::\{])*([::])/)?.[0].length : null;
182
+ Object.assign(node, attributes(colon ? body.slice(0, colon - 1).trim() : body, kind, fail));
183
+ if (!node.title) fail("标题不能为空", "Title cannot be empty", "在关键字后补上标题", "Add a title after the keyword");
184
+ node.id = node.ref || `#${endpoints.length + 1}`;
185
+ endpoints.push(node);
186
+ if (endpoints.length === LIMITS.endpoints + 1) split(fail, "容器和卡片合计最多 400 个", "At most 400 boxes and cards combined");
187
+ if (node.ref) {
188
+ if (refs.has(node.ref)) fail(`引用 ID @${node.ref} 重复`, `Duplicate reference ID @${node.ref}`, "换一个未使用的 @id", "Use a different, unused @id");
189
+ else refs.set(node.ref, node);
190
+ }
191
+ if (!titles.has(node.title)) titles.set(node.title, []);
192
+ titles.get(node.title).push(node);
193
+ if (kind === "card") node.desc = [];
194
+ else if (colon && body.slice(colon).trim()) {
195
+ node.inline = true;
196
+ addItems(node, body.slice(colon));
197
+ }
198
+ } else if (kind === "grid") {
199
+ node.cols = Number(body);
200
+ if (!/^\d+$/.test(body) || node.cols < 1 || node.cols > 12) fail("grid 列数必须在 1–12 之间", "Grid column count must be between 1 and 12", "写成 grid 1 到 grid 12", "Use grid 1 through grid 12");
201
+ } else if (kind === "note") {
202
+ node.text = body;
203
+ nonEndpoints.add(body);
204
+ if (!body) fail("note 缺少正文", "Note text is missing", "在 note 后写上正文", "Add text after note");
205
+ } else if (kind === "legend") {
206
+ node.entries = [];
207
+ if (body) fail("legend 说明必须缩进另写", "Legend entries must be on indented lines", "将说明移到下一行并缩进", "Move the entry to its own indented line");
64
208
  }
65
- const node = readNode(text, line, indent, lang, errors);
66
- if (!node) continue;
67
209
  (parent ? parent.children : nodes).push(node);
68
210
  stack.push(node);
69
211
  }
70
- const boxes = [], items = [];
71
- walk(nodes, null, (node, parent) => {
72
- node.parent = parent;
73
- if (node.kind === "box") boxes.push(node);
74
- items.push(...node.items);
75
- if (node.kind !== "box" && node.items.length) errors.push(issue(lang, node.line, "能力项只能写在 box 内", "Capabilities belong inside a box", "把这一行改成 box,或移入上一个 box", "Change this line into a box, or move it into the previous box"));
76
- if (node.children.length && node.items.length) errors.push(issue(lang, node.line, "box 不能同时写行内能力项和子容器", "A box cannot mix inline capabilities and child containers", "改成缩进的能力项,或去掉子容器", "Use indented capabilities, or remove the child containers"));
77
- });
78
- const names = /* @__PURE__ */ new Map();
79
- for (const box of boxes) {
80
- if (!box.title) errors.push(issue(lang, box.line, "box 名称不能为空", "Box name cannot be empty", "写上唯一名称", "Add a unique name"));
81
- const list = names.get(box.title) || [];
82
- list.push(box);
83
- names.set(box.title, list);
212
+ for (const edge of edges) {
213
+ const fail = at(edge.line);
214
+ [edge.from, edge.to] = edge.ends.map((end) => {
215
+ const named = refs.get(end.replace(/^@/, ""));
216
+ if (named) return named;
217
+ const matches = !RESERVED.test(end) ? titles.get(end) : null;
218
+ if (matches?.length === 1) return matches[0];
219
+ if (nonEndpoints.has(end) && !matches?.length) fail(`关系不能指向注释或能力项「${end}」`, `Relations cannot target a note or capability: ${end}`, "改为所属 box 或 card 的名称", "Use the containing box or a card as the endpoint");
220
+ else fail(matches?.length ? `关系端点「${end}」不唯一` : `关系端点「${end}」不存在`, matches?.length ? `Ambiguous relation endpoint: ${end}` : `Unknown relation endpoint: ${end}`, "给目标加 {@id},并在关系中使用该 id", "Add {@id} to the one you mean and use that id in the relation");
221
+ return null;
222
+ });
223
+ if (edge.from && edge.from === edge.to) fail("关系不能指向自身", "A relation cannot target itself", "选择不同的端点或删除该关系", "Choose a different endpoint or remove the relation");
84
224
  }
85
- for (const [title, list] of names) if (list.length > 1) errors.push(issue(lang, list[1].line, `容器名称「${title}」重复`, `Duplicate container name: ${title}`, "改成唯一名称;关系只能指向唯一容器", "Use a unique name; relations can only target one container"));
86
- for (const edge of edges) for (const end of ["from", "to"]) if ((names.get(edge[end]) || []).length !== 1) errors.push(issue(lang, edge.line, `关系指向的容器「${edge[end]}」不存在或不唯一`, `Relation target "${edge[end]}" is missing or not unique`, "改成图中唯一的容器名称", "Use the unique name of a container in this diagram"));
87
- if (edges.length > LIMITS.edges) errors.push(issue(lang, edges[LIMITS.edges].line, `关系最多 ${LIMITS.edges} 条`, `At most ${LIMITS.edges} relations`, "删掉次要关系,或改用泳道图、流程图", "Remove secondary relations, or use a swimlane or flowchart"));
88
- for (const edge of edges) if ([...edge.label].length > LIMITS.labelChars) errors.push(issue(lang, edge.line, `关系标签「${edge.label}」过长`, `Relation label is too long: ${edge.label}`, `把标签缩到 ${LIMITS.labelChars} 个字符以内,或把说明移到图外`, `Keep the label within ${LIMITS.labelChars} characters, or move the description outside`));
89
- if (boxes.length > LIMITS.boxes) errors.push(issue(lang, boxes[LIMITS.boxes].line, `容器最多 ${LIMITS.boxes} 个`, `At most ${LIMITS.boxes} containers`, "拆成总图和分图", "Split into an overview and detail diagrams"));
90
- if (items.length > LIMITS.items) errors.push(issue(lang, items[LIMITS.items].line, `能力项最多 ${LIMITS.items} 个`, `At most ${LIMITS.items} capabilities`, "把说明移到图外,或拆成两张图", "Move descriptions outside, or split into two diagrams"));
91
- for (const item of items) if (item.icon && !has(item.icon)) errors.push(issue(lang, item.line, `未知图标「${item.icon}」`, `Unknown icon: ${item.icon}`, "换成图标库中的名称,例如 database", "Use a name from the icon library"));
92
- if (!nodes.length) errors.push(issue(lang, firstLine, "图中没有容器", "Diagram has no containers", "添加 row、col 或 box", "Add a row, col, or box"));
225
+ if (!nodes.length) at(firstLine)("图中没有结构", "Diagram has no structure", "添加 box 或 card", "Add a box or card");
93
226
  return {
94
227
  model: {
95
- type: "blocks",
96
228
  nodes,
229
+ endpoints,
97
230
  edges,
98
- boxes,
99
231
  items
100
232
  },
101
233
  errors
102
234
  };
103
235
  }
104
- function readNode(text, line, indent, lang, errors) {
105
- const head = text.match(/^(row|col|box)(?:\s+(.*))?$/);
106
- if (!head) {
107
- errors.push(issue(lang, line, "无法识别这一行", "Unrecognized line", "使用 row、col、box,或「容器 -> 容器: 标签」", "Use row, col, box, or \"container -> container: label\""));
108
- return null;
109
- }
110
- const kind = head[1], rest = (head[2] || "").trim();
111
- if (kind !== "box") {
112
- const weighted = rest.match(/^(\d+(?:\.\d+)?)(?:\s+(.*))?$/), weight = weighted ? Number(weighted[1]) : 1;
113
- if (weighted && !(weight > 0)) errors.push(issue(lang, line, "宽度权重必须是正数", "Width weight must be a positive number", "写成正数,例如 col 3", "Use a positive number, for example col 3"));
114
- else if (rest && !weighted) errors.push(issue(lang, line, `${kind} 后面只能写宽度权重`, `Only a width weight may follow ${kind}`, "删掉多余文字,或改成 box", "Remove the extra text, or change this into a box"));
115
- return {
116
- kind,
117
- weight,
118
- explicit: Boolean(weighted),
119
- indent,
120
- line,
121
- title: "",
122
- flag: "",
123
- items: [],
124
- children: []
125
- };
126
- }
127
- let body = rest, weight = 1, explicit = false;
128
- const declared = rest.match(/^(\d+(?:\.\d+)?)\s+(?![::\s])([\s\S]*)$/);
129
- if (declared) {
130
- weight = Number(declared[1]);
131
- explicit = weight > 0;
132
- body = declared[2];
133
- if (!explicit) weight = 1;
134
- }
135
- const colon = body.search(/[::]/), header = (colon < 0 ? body : body.slice(0, colon)).trim(), inline = colon < 0 ? "" : body.slice(colon + 1);
136
- const flag = header.match(/\s*\{(db|ext)\}\s*$/)?.[1] || "", title = header.replace(/\s*\{(db|ext)\}\s*$/, "").trim();
137
- const badFlag = /\{(?!db\}|ext\})/.test(header) || /\}\s*\S/.test(header);
138
- if (badFlag || !title && body) errors.push(issue(lang, line, "box 写法无效", "Invalid box syntax", "使用「box 名称 [{db}|{ext}] [: 能力项, 能力项]」", "Use \"box Name [{db}|{ext}] [: item, item]\""));
139
- const items = inline ? parseItems(inline, line, lang, errors) : [];
140
- return {
141
- kind,
142
- weight,
143
- explicit,
144
- indent,
145
- line,
146
- title,
147
- flag: badFlag ? "" : flag,
148
- inline: items.length > 0,
149
- items,
150
- children: []
151
- };
152
- }
153
- function parseItems(text, line, lang, errors) {
154
- return text.split(/[,,]/).map((part) => {
155
- const raw = part.trim(), icon = raw.match(/^\[icon:([a-z0-9][\w.-]*)\]\s*/i), value = icon ? raw.slice(icon[0].length) : raw;
156
- const mark = value.match(/^([+~=])\s*/)?.[1] || "", name = value.replace(/^[+~=]\s*/, "").trim();
157
- if (!name) errors.push(issue(lang, line, "能力项名称不能为空", "Capability labels cannot be empty", "删除空项或补上名称", "Remove the empty item or add a label"));
158
- if (/\[icon:/.test(raw) && !icon) errors.push(issue(lang, line, "图标写法无效", "Invalid icon syntax", "写成 [icon:database] 名称", "Write [icon:database] name"));
159
- return {
160
- label: mark ? `${mark} ${name}` : name,
161
- name,
162
- mark,
163
- tone: {
164
- "+": "new",
165
- "~": "info",
166
- "=": "ok"
167
- }[mark] || "",
168
- icon: icon?.[1] || "",
169
- line
170
- };
171
- }).filter((item) => item.name);
172
- }
173
- function walk(nodes, parent, visit) {
174
- for (const node of nodes) {
175
- visit(node, parent);
176
- walk(node.children, node, visit);
177
- }
178
- }
179
- function layout(model, { width, lang, measure }) {
180
- const errors = [], root = model.nodes.length === 1 ? model.nodes[0] : {
181
- kind: "col",
182
- weight: 1,
183
- children: model.nodes,
184
- items: [],
185
- title: "",
186
- line: model.nodes[0]?.line || 1
187
- };
188
- const boxes = [], items = [];
189
- const collect = (node) => {
190
- if (node.kind === "box") boxes.push(node);
191
- items.push(...node.items || []);
192
- node.children.forEach(collect);
193
- };
194
- collect(root);
195
- for (const item of items) if ([...item.name].length > LIMITS.labelChars || measure(item.name, FONT.body) > LIMITS.labelWidth) errors.push(issue(lang, item.line, `能力项「${item.label}」过长`, `Capability label is too long: ${item.label}`, "把说明移到图外,名称缩短至约 16 个汉字", "Move descriptions outside; shorten the label to about 16 CJK characters"));
196
- for (const box of boxes) if (measure(box.title, FONT.title) > LIMITS.labelWidth * 2) errors.push(issue(lang, box.line, `容器标题「${box.title}」过长`, `Container title is too long: ${box.title}`, "缩短标题,把说明放到图注", "Shorten the title and move the description to the caption"));
197
- if (errors.length) return {
198
- width,
199
- height: 0,
200
- errors
201
- };
202
- const byTitle = new Map(boxes.map((box) => [box.title, box])), resolved = model.edges.map((edge) => ({
203
- ...edge,
204
- fromBox: byTitle.get(edge.from),
205
- toBox: byTitle.get(edge.to)
206
- })), pairs = /* @__PURE__ */ new Map();
207
- for (const edge of resolved) {
208
- const key = pairOf(edge.fromBox, edge.toBox);
209
- if (!pairs.has(key)) pairs.set(key, []);
210
- pairs.get(key).push(edge);
211
- }
212
- const natural = sizeOf(root, measure, pairs), canvas = Math.max(Math.floor(width), natural.w + 8);
213
- const placed = place(root, MARGIN, MARGIN, canvas - 8, measure, pairs), frames = [], nodes = [];
214
- flatten(placed, frames, nodes);
215
- const edges = [];
216
- for (const edge of resolved) {
217
- const route = routeEdge(edge, frames, nodes, measure);
218
- if (!route) errors.push(issue(lang, edge.line, `容器「${edge.from}」与「${edge.to}」之间没有可用箭头通道`, `No clear arrow lane between "${edge.from}" and "${edge.to}"`, "让两个容器只隔一条空间隙,并避开能力项;或改用泳道图、流程图", "Leave one empty gap between the containers and clear of capability items, or use a swimlane or flowchart"));
219
- else edges.push(route);
236
+ var sum = (values) => values.reduce((a, b) => a + b, 0);
237
+ var lexLess = (a, b) => {
238
+ const i = a.findIndex((v, i) => v !== b[i]);
239
+ return i >= 0 && a[i] < b[i];
240
+ };
241
+ var offsets = (sizes, gaps) => {
242
+ let next = 0;
243
+ return sizes.map((size, i) => {
244
+ const at = next;
245
+ next += size + (gaps[i] || 0);
246
+ return at;
247
+ });
248
+ };
249
+ function distribute(mins, weights, space) {
250
+ const extra = Math.max(0, space - sum(mins)), scale = Math.max(...weights) || 1;
251
+ const scaled = weights.map((w) => w / scale), total = sum(scaled);
252
+ const out = mins.map((min, i) => min + Math.floor(extra * scaled[i] / total));
253
+ let rest = space - sum(out);
254
+ for (let i = 0; rest >= 1; i = (i + 1) % out.length) if (weights[i]) {
255
+ out[i]++;
256
+ rest--;
220
257
  }
221
- if (errors.length) return {
222
- width: canvas,
223
- height: placed.h + 8,
224
- frames,
225
- nodes,
226
- edges,
227
- errors
228
- };
229
- return {
230
- type: "blocks",
231
- width: canvas,
232
- height: snap(placed.h + 8),
233
- frames,
234
- nodes,
235
- edges,
236
- errors: []
237
- };
238
- }
239
- var textWidth = (text, font, measure) => measure(String(text || ""), font);
240
- function itemMin(item, measure) {
241
- return snap(Math.max(48, textWidth(item.label, FONT.body, measure) + 16 + (item.icon ? 28 : 0)));
242
- }
243
- function cellOf(items, measure) {
244
- return items.length ? snap(Math.max(72, ...items.map((item) => itemMin(item, measure)))) : 72;
245
- }
246
- function gridOf(items, cols, cell) {
247
- const used = Math.max(1, cols), rows = Math.max(1, Math.ceil(items.length / used));
248
- return {
249
- cols: used,
250
- rows,
251
- cell,
252
- width: used * cell + ITEM_GAP * (used - 1),
253
- height: rows * ITEM_H + ITEM_GAP * (rows - 1)
254
- };
258
+ return out;
255
259
  }
256
- function chooseGrid(items, measure, limit) {
257
- const cell = cellOf(items, measure), total = Math.max(1, items.length), ceiling = Math.min(total, Math.ceil(Math.sqrt(total)));
258
- let best = null;
259
- for (let cols = 1; cols <= total; cols += 1) {
260
- const grid = gridOf(items, cols, cell);
261
- if (grid.width > limit && cols !== 1) break;
260
+ function itemGrid(items, cell, width) {
261
+ let best;
262
+ for (let cols = 1; cols <= items.length; cols++) {
263
+ const cw = Math.floor((width - ITEM_GAP * (cols - 1)) / cols);
264
+ if (cw < cell && cols > 1) break;
265
+ const rows = Math.ceil(items.length / cols);
262
266
  const score = [
263
- Math.floor((limit - ITEM_GAP * (cols - 1)) / cols) > SPARSE_CELL ? 1 : 0,
264
- grid.rows * grid.cols - total,
265
- Math.abs(grid.cols - grid.rows),
266
- grid.rows,
267
- Math.abs(grid.cols - ceiling)
267
+ +(cw > 260),
268
+ rows * cols - items.length,
269
+ Math.abs(cols - rows),
270
+ rows
268
271
  ];
269
272
  if (!best || lexLess(score, best.score)) best = {
270
- grid,
273
+ cols,
274
+ rows,
275
+ cw: Math.max(cw, cell),
271
276
  score
272
277
  };
273
278
  }
274
- return best ? best.grid : gridOf(items, 1, cell);
275
- }
276
- function lexLess(a, b) {
277
- for (let i = 0; i < a.length; i += 1) if (a[i] !== b[i]) return a[i] < b[i];
278
- return false;
279
+ return best;
279
280
  }
280
- var LABEL_WRAP = 160;
281
- function labelPlan(text, measure) {
282
- if (!text) return {
283
- lines: [],
284
- w: 0,
285
- h: 0
286
- };
287
- const lines = wrapText(text, LABEL_WRAP, FONT.label, measure).slice(0, LIMITS.labelLines);
288
- return {
289
- lines,
290
- w: snap(maxWidthOf(lines, FONT.label, measure) + 12),
291
- h: lines.length * 16 + 2
281
+ var pathTo = (node) => node ? [...pathTo(node.parent), node] : [];
282
+ var slot = (node, child, axis) => {
283
+ const i = node.children.indexOf(child);
284
+ return node.kind === "grid" ? axis === "x" ? i % node.cols : Math.floor(i / node.cols) : node.kind === "col" === (axis === "y") ? i : 0;
285
+ };
286
+ function corridors(root, edges) {
287
+ const plans = /* @__PURE__ */ new Map();
288
+ const plan = (node) => {
289
+ if (!plans.has(node)) plans.set(node, {
290
+ x: /* @__PURE__ */ new Map(),
291
+ y: /* @__PURE__ */ new Map(),
292
+ inner: []
293
+ });
294
+ return plans.get(node);
292
295
  };
296
+ for (const edge of edges) {
297
+ const a = pathTo(edge.from), b = pathTo(edge.to);
298
+ if (root !== a[0]) {
299
+ a.unshift(root);
300
+ b.unshift(root);
301
+ }
302
+ let i = 0;
303
+ while (a[i] && a[i] === b[i]) i++;
304
+ const split = a[i - 1];
305
+ if (a[i] && b[i]) for (const axis of ["x", "y"]) {
306
+ const start = slot(split, a[i], axis), end = slot(split, b[i], axis);
307
+ const lanes = plan(split)[axis];
308
+ for (let j = Math.min(start, end); j < Math.max(start, end); j++) {
309
+ if (!lanes.has(j)) lanes.set(j, []);
310
+ lanes.get(j).push(edge);
311
+ }
312
+ }
313
+ else if (split.kind === "box") plan(split).inner.push(edge);
314
+ for (const node of [...a.slice(i, -1), ...b.slice(i, -1)]) if (node.kind === "box") plan(node).inner.push(edge);
315
+ }
316
+ return plans;
293
317
  }
294
- function sizeOf(node, measure, pairs) {
295
- if (node.kind !== "box" && !node.children.length && !node.items?.length) return {
296
- w: 72,
297
- h: 36
318
+ function layout(model, { width, lang, measure, compact }) {
319
+ const errors = [], root = model.nodes.length === 1 ? model.nodes[0] : {
320
+ kind: "col",
321
+ children: model.nodes,
322
+ items: []
298
323
  };
299
- if (node.kind === "box" && node.items?.length && !node.children.length) {
300
- const grid = gridOf(node.items, 1, cellOf(node.items, measure)), title = snap(textWidth(node.title, FONT.title, measure) + 24);
301
- return {
302
- w: Math.max(grid.width, title) + 24,
303
- h: HEADER + grid.height + PAD,
304
- grid
305
- };
324
+ const metrics = /* @__PURE__ */ new Map();
325
+ const short = (node, zh, en) => errors.push(error(lang, node.line, zh, en, "缩短文字,把说明移到图注", "Shorten the text and move details to the caption"));
326
+ for (const node of model.endpoints) {
327
+ const data = node.kind === "card" ? measureCard(node, measure) : frameTitle(node, measure);
328
+ if (node.kind === "card" ? data.titleLines.length > 2 : data.lines.length > 3) short(node, node.kind === "card" ? "卡片标题最多换行成 2 行" : "容器标题最多换行成 3 行", node.kind === "card" ? "Card titles may wrap to at most 2 lines" : "Box titles may wrap to at most 3 lines");
329
+ metrics.set(node, data);
306
330
  }
307
- if (node.kind === "box" && !node.children.length) {
308
- const w = Math.max(48, snap(textWidth(node.title, FONT.title, measure)) + 24);
331
+ for (const item of model.items) if (count(item.name) > 24 || measure(item.name, FONT.body) > 312) short(item, `能力项「${item.label}」过长`, `Capability label is too long: ${item.label}`);
332
+ const edges = model.edges.map((edge) => {
333
+ const label = measureLabel(edge.label, measure);
334
+ if (label?.lines.length > 2) short(edge, "关系标签最多换行成 2 行", "Relation labels may wrap to at most 2 lines");
309
335
  return {
310
- w: snap(w),
311
- h: 48
336
+ ...edge,
337
+ label
312
338
  };
313
- }
314
- const kids = node.children.map((child) => ({
315
- child,
316
- size: sizeOf(child, measure, pairs)
317
- })), vertical = node.kind === "col", gaps = gapPlan(node, kids.map((item) => item.child), pairs, measure);
318
- const cross = Math.max(72, ...kids.map((item) => vertical ? item.size.w : item.size.h)), main = kids.reduce((sum, item) => sum + (vertical ? item.size.h : item.size.w), 0) + gaps.reduce((a, b) => a + b, 0);
319
- let w = vertical ? cross : main, h = vertical ? main : cross;
320
- if (node.kind === "box") {
321
- const title = snap(textWidth(node.title, FONT.title, measure) + 24);
322
- w = Math.max(w, title) + 24;
323
- h += 48;
324
- }
325
- return {
326
- w: snap(w),
327
- h: snap(h),
328
- kids
339
+ });
340
+ if (errors.length) return {
341
+ width,
342
+ height: 0,
343
+ errors
329
344
  };
330
- }
331
- function gapPlan(node, children, pairs, measure) {
332
- const vertical = node.kind === "col", gaps = [];
333
- for (let i = 0; i < children.length - 1; i += 1) {
334
- const edges = [];
335
- for (const a of boxesIn(children[i])) for (const b of boxesIn(children[i + 1])) edges.push(...pairs.get(pairOf(a, b)) || []);
336
- const need = (edge) => {
337
- const plan = labelPlan(edge.label, measure);
338
- return vertical ? plan.h ? plan.h + 48 : 0 : plan.w + 24;
339
- };
340
- gaps.push(edges.length ? Math.max(ARROW, ...edges.map(need)) : GAP);
341
- }
342
- return gaps;
343
- }
344
- function pairOf(a, b) {
345
- return [a.title, b.title].sort().join("\0");
346
- }
347
- function boxesIn(node, out = []) {
348
- if (node.kind === "box") out.push(node);
349
- for (const child of node.children || []) boxesIn(child, out);
350
- return out;
351
- }
352
- function place(node, x, y, w, measure, pairs, minH = 0) {
353
- const box = {
354
- ...node,
355
- x,
356
- y,
357
- w,
358
- h: 0,
359
- children: [],
360
- itemNodes: []
361
- }, framed = node.kind === "box";
362
- const innerX = framed ? x + PAD : x, innerY = framed ? y + HEADER : y, innerW = framed ? w - 24 : w, padding = framed ? 48 : 0;
363
- if (framed && node.items?.length && !node.children.length) {
364
- const grid = chooseGrid(node.items, measure, innerW), cols = grid.cols;
365
- const cw = Math.max(grid.cell, Math.floor((innerW - ITEM_GAP * (cols - 1)) / cols));
366
- const left = innerX + Math.max(0, Math.floor((innerW - cw * cols - ITEM_GAP * (cols - 1)) / 2));
367
- node.items.forEach((item, index) => box.itemNodes.push({
368
- ...item,
369
- x: left + index % cols * (cw + ITEM_GAP),
370
- y: innerY + Math.floor(index / cols) * 44,
371
- w: cw,
372
- h: ITEM_H
373
- }));
374
- box.h = Math.max(minH, padding + grid.height);
375
- return box;
376
- }
377
- const kids = node.children || [];
378
- if (!kids.length) {
379
- box.h = Math.max(minH, padding);
380
- return box;
381
- }
382
- const horizontal = node.kind !== "col", sizes = kids.map((child) => sizeOf(child, measure, pairs)), gaps = gapPlan(node, kids, pairs, measure), mins = sizes.map((size) => horizontal ? size.w : size.h);
383
- const anyExplicit = kids.some((child) => child.explicit);
384
- if (horizontal && !anyExplicit) {
385
- const groups = /* @__PURE__ */ new Map();
386
- kids.forEach((child, index) => {
387
- if (child.kind !== "box" || child.children.length || !child.items?.length) return;
388
- if (!groups.has(child.items.length)) groups.set(child.items.length, []);
389
- groups.get(child.items.length).push(index);
345
+ const plans = corridors(root, edges);
346
+ let result, routed, naturalWidth;
347
+ for (let pass = 0; pass < (edges.length ? 3 : 1); pass++) {
348
+ const sizes = /* @__PURE__ */ new Map();
349
+ const gaps = (node, axis, n) => Array.from({ length: n - 1 }, (_, i) => {
350
+ const lanes = plans.get(node)?.[axis].get(i) || [];
351
+ return lanes.length ? Math.max(28, 16 + 12 * lanes.length, ...lanes.map((e) => e.label ? 24 + (axis === "x" ? e.label.w : e.label.h) : 0)) + pass * 16 : GAP;
390
352
  });
391
- for (const indexes of groups.values()) {
392
- if (indexes.length < 2) continue;
393
- const widest = Math.max(...indexes.map((index) => mins[index]));
394
- for (const index of indexes) mins[index] = widest;
395
- }
396
- }
397
- const bare = (child) => child.kind === "box" && !child.children.length && !child.items?.length;
398
- const weights = kids.map((child, i) => anyExplicit ? child.explicit ? child.weight : 1 : bare(child) ? 0 : Math.max(72, mins[i]));
399
- if (weights.every((weight) => weight === 0)) weights.fill(1);
400
- const gapSum = gaps.reduce((a, b) => a + b, 0), share = horizontal ? distribute(mins, weights, Math.max(innerW - gapSum, mins.reduce((a, b) => a + b, 0))) : mins;
401
- const placed = kids.map((child, index) => ({
402
- child,
403
- w: horizontal ? share[index] : innerW,
404
- x: horizontal ? innerX + share.slice(0, index).reduce((a, b) => a + b, 0) + gaps.slice(0, index).reduce((a, b) => a + b, 0) : innerX
405
- }));
406
- if (horizontal) {
407
- const first = placed.map((item) => place(item.child, item.x, innerY, item.w, measure, pairs));
408
- const rowH = Math.max(minH - padding, ...first.map((child) => child.h));
409
- box.children = first.map((child, index) => child.h === rowH ? child : place(kids[index], placed[index].x, innerY, placed[index].w, measure, pairs, rowH));
410
- box.h = padding + rowH;
411
- return box;
412
- }
413
- const natural = kids.map((child) => place(child, innerX, innerY, innerW, measure, pairs).h);
414
- const extra = Math.max(0, minH - padding - natural.reduce((a, b) => a + b, 0) - gaps.reduce((a, b) => a + b, 0));
415
- const each = Math.floor(extra / kids.length);
416
- let cursor = innerY;
417
- kids.forEach((child, index) => {
418
- const grow = each + (index === kids.length - 1 ? extra - each * kids.length : 0);
419
- const item = place(child, innerX, cursor, innerW, measure, pairs, natural[index] + grow);
420
- box.children.push(item);
421
- cursor += item.h + (gaps[index] || 0);
422
- });
423
- box.h = Math.max(minH, padding + cursor - innerY);
424
- return box;
425
- }
426
- function distribute(mins, weights, space) {
427
- const minSum = mins.reduce((a, b) => a + b, 0), extra = Math.max(0, space - minSum), weightSum = weights.reduce((a, b) => a + b, 0);
428
- const out = mins.map((min, i) => min + Math.floor(extra * weights[i] / weightSum)), takers = weights.map((weight, i) => weight > 0 ? i : -1).filter((i) => i >= 0);
429
- let rest = space - out.reduce((a, b) => a + b, 0);
430
- for (let k = 0; rest > 0; k += 1, rest -= 1) out[takers[k % takers.length]] += 1;
431
- return out;
432
- }
433
- function flatten(n, frames, nodes) {
434
- if (n.kind === "box") frames.push(n);
435
- for (const item of n.itemNodes || []) nodes.push({
436
- ...item,
437
- parent: n
438
- });
439
- for (const c of n.children || []) flatten(c, frames, nodes);
440
- }
441
- function contains(outer, inner) {
442
- return outer.x <= inner.x + .5 && outer.y <= inner.y + .5 && outer.x + outer.w + .5 >= inner.x + inner.w && outer.y + outer.h + .5 >= inner.y + inner.h;
443
- }
444
- function overlap(a, b) {
445
- return a.w > 0 && a.h > 0 && b.w > 0 && b.h > 0 && a.x < b.x + b.w - .5 && b.x < a.x + a.w - .5 && a.y < b.y + b.h - .5 && b.y < a.y + a.h - .5;
446
- }
447
- function routeEdge(edge, frames, nodes = [], measure = fallbackMeasure) {
448
- const a = frames.find((frame) => frame.title === edge.from), b = frames.find((frame) => frame.title === edge.to);
449
- if (!a || !b || a === b) return null;
450
- const candidates = [];
451
- if (a.x + a.w <= b.x + .5) candidates.push({
452
- dir: "right",
453
- gap: {
454
- x: a.x + a.w,
455
- y: Math.max(a.y, b.y),
456
- w: b.x - (a.x + a.w),
457
- h: Math.min(a.y + a.h, b.y + b.h) - Math.max(a.y, b.y)
458
- }
459
- });
460
- if (b.x + b.w <= a.x + .5) candidates.push({
461
- dir: "left",
462
- gap: {
463
- x: b.x + b.w,
464
- y: Math.max(a.y, b.y),
465
- w: a.x - (b.x + b.w),
466
- h: Math.min(a.y + a.h, b.y + b.h) - Math.max(a.y, b.y)
353
+ function size(node) {
354
+ const { kind, children, items } = node, data = metrics.get(node);
355
+ let plan;
356
+ if (kind === "card") plan = { w: data.w };
357
+ else if (kind === "note") plan = { w: Math.max(24, measureNote(node.text, measure).w) };
358
+ else if (kind === "legend") plan = { w: Math.max(52, measureLegend(node.entries, measure, 240).w) };
359
+ else {
360
+ const grid = kind === "grid", vertical = kind === "col", columns = grid ? node.cols : vertical ? 1 : Math.max(1, children.length);
361
+ const rows = vertical ? Math.max(1, children.length) : Math.max(1, Math.ceil(children.length / columns));
362
+ const gx = gaps(node, "x", columns), gy = gaps(node, "y", rows);
363
+ const mins = Array(columns).fill(0);
364
+ children.forEach((child, i) => {
365
+ const col = i % columns;
366
+ mins[col] = Math.max(mins[col], size(child).w);
367
+ });
368
+ const bare = (child) => child.kind === "box" && !child.children.length && !child.items.length;
369
+ const explicit = children.some((child) => child.explicit);
370
+ if (grid) mins.fill(Math.max(24, ...mins));
371
+ else if (!vertical && !explicit) {
372
+ const groups = /* @__PURE__ */ new Map();
373
+ children.forEach((child, i) => {
374
+ if (child.items.length) groups.set(child.items.length, Math.max(groups.get(child.items.length) || 0, mins[i]));
375
+ });
376
+ children.forEach((child, i) => {
377
+ if (child.items.length) mins[i] = groups.get(child.items.length);
378
+ });
379
+ }
380
+ const weights = grid || vertical ? mins.map(() => 1) : children.map((child, i) => explicit ? child.weight : bare(child) ? 0 : Math.max(72, mins[i]));
381
+ if (weights.every((w) => !w)) weights.fill(1);
382
+ const inner = plans.get(node)?.inner.length || 0;
383
+ const pad = kind === "box" ? Math.max(PAD, inner ? 16 + Math.min(inner, 4) * 6 + pass * 12 : 0) : 0;
384
+ const top = kind === "box" ? Math.max(36, data.band) + pad - PAD : 0;
385
+ const cell = items.length ? Math.max(...items.map((item) => measureItem(item, measure))) : 0;
386
+ plan = {
387
+ w: Math.max(kind === "box" ? 48 : 72, data?.minW || 0, 2 * pad + Math.max(cell, sum(mins) + sum(gx))),
388
+ pad,
389
+ top,
390
+ cell,
391
+ columns,
392
+ gx,
393
+ gy,
394
+ mins,
395
+ weights
396
+ };
397
+ }
398
+ sizes.set(node, plan);
399
+ return plan;
467
400
  }
468
- });
469
- if (a.y + a.h <= b.y + .5) candidates.push({
470
- dir: "down",
471
- gap: {
472
- x: Math.max(a.x, b.x),
473
- y: a.y + a.h,
474
- w: Math.min(a.x + a.w, b.x + b.w) - Math.max(a.x, b.x),
475
- h: b.y - (a.y + a.h)
401
+ const rim = MARGIN + pass * 16;
402
+ const minimum = size(root).w + rim * 2;
403
+ naturalWidth ??= minimum;
404
+ const canvas = compact ? minimum : Math.max(Math.floor(width), minimum);
405
+ function compose(node, w) {
406
+ const plan = sizes.get(node), { kind } = node;
407
+ if (kind === "card" || kind === "note" || kind === "legend") {
408
+ const paint = kind === "card" ? metrics.get(node) : kind === "note" ? measureNote(node.text, measure, w) : measureLegend(node.entries, measure, w);
409
+ return {
410
+ node,
411
+ w,
412
+ h: paint.h,
413
+ paint,
414
+ plan
415
+ };
416
+ }
417
+ const { pad, top, columns, mins, weights, gx, gy, cell } = plan;
418
+ const inner = w - 2 * pad;
419
+ if (node.items.length) {
420
+ const grid = itemGrid(node.items, cell, inner);
421
+ return {
422
+ node,
423
+ w,
424
+ h: top + grid.rows * ITEM.h + (grid.rows - 1) * ITEM_GAP + pad,
425
+ grid,
426
+ plan
427
+ };
428
+ }
429
+ const cols = !node.children.length ? [] : kind === "grid" ? mins.map(() => Math.floor((inner - sum(gx)) / columns)) : distribute(mins, weights, inner - sum(gx));
430
+ const children = node.children.map((child, i) => compose(child, cols[i % columns]));
431
+ const rows = Array(gy.length + 1).fill(0);
432
+ children.forEach((child, i) => {
433
+ const row = Math.floor(i / columns);
434
+ rows[row] = Math.max(rows[row], child.h);
435
+ });
436
+ return {
437
+ node,
438
+ w,
439
+ h: Math.max(kind === "box" ? 48 : 0, top + sum(rows) + sum(gy) + pad),
440
+ cols,
441
+ rows,
442
+ children,
443
+ plan
444
+ };
476
445
  }
477
- });
478
- if (b.y + b.h <= a.y + .5) candidates.push({
479
- dir: "up",
480
- gap: {
481
- x: Math.max(a.x, b.x),
482
- y: b.y + b.h,
483
- w: Math.min(a.x + a.w, b.x + b.w) - Math.max(a.x, b.x),
484
- h: a.y - (b.y + b.h)
446
+ const frames = [], cards = [], notes = [], legends = [], nodes = [];
447
+ function place(tree, x, y, h, parent) {
448
+ const { node, w, plan, paint, grid, children, cols, rows } = tree;
449
+ const { kind, id, style, db, badge, tag } = node;
450
+ const rect = {
451
+ x,
452
+ y,
453
+ w,
454
+ h
455
+ };
456
+ if (kind === "card") {
457
+ cards.push({
458
+ ...paint,
459
+ ...rect,
460
+ id,
461
+ style,
462
+ badge,
463
+ tag,
464
+ parent: parent?.id
465
+ });
466
+ return;
467
+ }
468
+ if (kind === "note" || kind === "legend") {
469
+ (kind === "note" ? notes : legends).push({
470
+ ...rect,
471
+ ...paint
472
+ });
473
+ return;
474
+ }
475
+ if (kind === "box") {
476
+ const title = metrics.get(node);
477
+ const frame = {
478
+ ...rect,
479
+ id,
480
+ name: node.title,
481
+ style,
482
+ db,
483
+ badge,
484
+ title,
485
+ parent: parent?.id
486
+ };
487
+ frame.titleRect = titleRect(frame, title);
488
+ frames.push(frame);
489
+ parent = frame;
490
+ }
491
+ const { pad, top, gx, gy, columns } = plan;
492
+ if (grid) {
493
+ const left = x + Math.floor((w - grid.cw * grid.cols - ITEM_GAP * (grid.cols - 1)) / 2);
494
+ node.items.forEach((item, i) => nodes.push({
495
+ ...item,
496
+ parent,
497
+ id: `${id}/item-${i}`,
498
+ x: left + i % grid.cols * (grid.cw + ITEM_GAP),
499
+ y: y + top + Math.floor(i / grid.cols) * (ITEM.h + ITEM_GAP),
500
+ w: grid.cw,
501
+ h: ITEM.h
502
+ }));
503
+ } else if (children.length) {
504
+ const heights = distribute(rows, rows.map(() => 1), h - top - pad - sum(gy));
505
+ const xs = offsets(cols, gx), ys = offsets(heights, gy);
506
+ const mixed = new Set(children.filter((child) => child.node.kind !== "card").map((child) => Math.floor(children.indexOf(child) / columns)));
507
+ children.forEach((child, i) => {
508
+ const c = i % columns, r = Math.floor(i / columns);
509
+ const own = kind !== "col" && child.node.kind === "card" && mixed.has(r);
510
+ place(child, x + pad + xs[c], y + top + ys[r] + (own ? (heights[r] - child.h) / 2 : 0), own ? child.h : heights[r], parent);
511
+ });
512
+ }
485
513
  }
486
- });
487
- const ranked = candidates.filter((item) => item.gap.w >= 24 && item.gap.h >= 24).map((item) => ({
488
- ...item,
489
- lane: arrowLane(item, frames, nodes, a, b, edge.label, measure)
490
- })).filter((item) => item.lane);
491
- if (!ranked.length) return null;
492
- ranked.sort((p, q) => laneArea(q.lane) - laneArea(p.lane));
493
- const { dir, lane } = ranked[0], midX = lane.x + lane.w / 2, midY = lane.y + lane.h / 2, horizontal = dir === "right" || dir === "left";
494
- const path = horizontal ? dir === "right" ? `M${lane.x + 4} ${midY} H${lane.x + lane.w - 4}` : `M${lane.x + lane.w - 4} ${midY} H${lane.x + 4}` : dir === "down" ? `M${midX} ${lane.y + 4} V${lane.y + lane.h - 4}` : `M${midX} ${lane.y + lane.h - 4} V${lane.y + 4}`;
495
- const plan = labelPlan(edge.label || "", measure), room = Math.max(24, (horizontal ? ranked[0].gap.w : lane.w) - 8);
496
- const lines = edge.label && plan.w > room ? wrapText(edge.label, Math.max(24, room - 12), FONT.label, measure).slice(0, LIMITS.labelLines) : plan.lines;
497
- const labelW = lines.length ? snap(maxWidthOf(lines, FONT.label, measure) + 12) : 0, labelH = lines.length ? Math.max(18, lines.length * 16 + 2) : 0;
514
+ const tree = compose(root, canvas - 2 * rim);
515
+ place(tree, rim, rim, tree.h, void 0);
516
+ result = {
517
+ width: canvas,
518
+ height: tree.h + 2 * rim,
519
+ frames,
520
+ cards,
521
+ notes,
522
+ legends,
523
+ nodes
524
+ };
525
+ routed = routeBoard({
526
+ ...result,
527
+ nodes: [...cards, ...nodes.map((n) => ({
528
+ ...n,
529
+ parent: n.parent.id
530
+ }))],
531
+ blockers: [...notes, ...legends],
532
+ edges: edges.map((edge) => ({
533
+ id: edge.id,
534
+ from: edge.from.id,
535
+ to: edge.to.id,
536
+ label: edge.label
537
+ }))
538
+ });
539
+ if (!routed.failed.length && routed.edges.every((route) => !route.labelRect || labelFits(route.labelRect, result))) break;
540
+ }
541
+ const byId = new Map(routed.edges.map((edge) => [edge.id, edge]));
542
+ const placed = [];
543
+ for (const edge of edges) {
544
+ const route = byId.get(edge.id);
545
+ if (!route || edge.label && !labelFits(route.labelRect, result)) errors.push(error(lang, edge.line, `关系「${edge.ends.join(" → ")}」没有可用通道`, `No clear route for "${edge.ends.join(" → ")}"`, "减少共享同一通道的关系,或调整 row、col、grid 的组合", "Reduce relations sharing the corridor or adjust the row, col or grid composition"));
546
+ else placed.push({
547
+ ...route,
548
+ from: edge.from.id,
549
+ to: edge.to.id,
550
+ kind: edge.kind,
551
+ labelLines: edge.label?.lines
552
+ });
553
+ }
554
+ if (model.endpoints.length > 60 || naturalWidth > width * 2) errors.push(warning("LARGE_DIAGRAM", lang, model.nodes[0].line, "图较大,可滚动查看", "Large board; scroll to view it", "可拆成总图和分图", "Consider splitting into an overview and detail boards"));
498
555
  return {
499
- ...edge,
500
- dir,
501
- gap: lane,
502
- path,
503
- labelLines: lines,
504
- labelX: midX,
505
- labelY: midY,
506
- labelBox: {
507
- x: midX - labelW / 2,
508
- y: midY - labelH / 2,
509
- w: labelW,
510
- h: labelH
511
- }
556
+ ...result,
557
+ edges: placed,
558
+ errors
512
559
  };
513
560
  }
514
- function laneArea(box) {
515
- return box.w * box.h;
516
- }
517
- function arrowLane(item, frames, nodes, a, b, label, measure) {
518
- const { dir, gap } = item, horizontal = dir === "right" || dir === "left", span = horizontal ? gap.h : gap.w, cross = horizontal ? gap.w : gap.h;
519
- if (cross < 24 || span < 24) return null;
520
- const thickness = cross - 8, along = Math.min(Math.max(64, measure(label, FONT.label) + 20), Math.max(24, span - 12));
521
- if (thickness < 20 || along < 20) return null;
522
- const lane = horizontal ? {
523
- x: gap.x + (gap.w - thickness) / 2,
524
- y: gap.y + (gap.h - along) / 2,
525
- w: thickness,
526
- h: along
527
- } : {
528
- x: gap.x + (gap.w - along) / 2,
529
- y: gap.y + (gap.h - thickness) / 2,
530
- w: along,
531
- h: thickness
532
- };
533
- const blockedByFrame = frames.some((frame) => frame !== a && frame !== b && overlap(frame, lane) && !(contains(frame, a) && contains(frame, b)));
534
- const blockedByItem = nodes.some((node) => overlap(node, lane));
535
- return blockedByFrame || blockedByItem ? null : lane;
561
+ function labelFits(rect, { width, height }) {
562
+ return rect && rect.x >= 0 && rect.y >= 0 && rect.x + rect.w <= width && rect.y + rect.h <= height;
536
563
  }
537
564
  function scene(g, ctx) {
538
- const d = ctx.design, appearance$1 = appearance(ctx), frameColor = (line) => ctx.frameTone(ctx.color(`tone${line % 6 + 1}`));
539
- const children = [ctx.el("defs", {}, [marker("blocks-arrow", ctx, false), marker("blocks-arrow-async", ctx, true)])];
540
- for (const frame of g.frames) {
541
- const tone = frameColor(frame.line), fill = ctx.tint(d.bg, tone, .07), stroke = ctx.tint(d.bg, tone, .45);
542
- const shape = frame.flag === "db" ? cylinder(frame, ctx, fill, stroke) : ctx.rect(frame.x, frame.y, frame.w, frame.h, {
543
- rx: appearance$1.radius,
544
- fill,
545
- stroke,
546
- "stroke-width": 1,
547
- ...frame.flag === "ext" ? { "stroke-dasharray": "5 4" } : {}
548
- });
549
- const titleLines = wrapText(frame.title, Math.max(48, frame.w - 24), FONT.title, (v, f) => ctx.measure(v, f.size, f.weight)).slice(0, LIMITS.titleLines);
550
- const titleY = frame.itemNodes?.length || frame.children?.length ? frame.y + 20 : frame.y + frame.h / 2;
551
- const frameChildren = [shape, ...titleLines.map((line, i) => ctx.text(frame.x + frame.w / 2, titleY + (i - (titleLines.length - 1) / 2) * 18, line, {
552
- anchor: "middle",
553
- size: FONT.title.size,
554
- weight: FONT.title.weight,
555
- fill: ctx.color("fg"),
556
- "dominant-baseline": "central"
557
- }))];
558
- children.push({
559
- ...ctx.el("g", {}, frameChildren),
560
- meta: {
561
- kind: "container",
562
- name: frame.title,
563
- ...frame.flag ? { flag: frame.flag } : {}
564
- }
565
- });
566
- }
567
- for (const node of g.nodes) {
568
- const tone = node.tone ? d[node.tone] : frameColor(node.parent?.line || 1);
569
- const parts = [ctx.rect(node.x, node.y, node.w, node.h, {
570
- rx: appearance$1.smallRadius,
571
- fill: appearance$1.node,
572
- stroke: (node.tone ? ctx.mix : ctx.tint)(d.bg, tone, .4),
573
- "stroke-width": 1
574
- })];
575
- if (node.icon) {
576
- const geo = geometry(node.icon);
577
- for (const item of geo?.elements || []) parts.push(ctx.shape(item.tag, {
578
- ...item.attrs,
579
- transform: `translate(${node.x + 8} ${node.y + 8}) scale(.8)`,
580
- fill: "none",
581
- stroke: ctx.color("muted"),
582
- "stroke-width": 1.5
583
- }));
565
+ const styles = [...g.cards, ...g.frames].map((box) => box.style).concat(g.nodes.map((node) => node.tone), g.legends.flatMap((legend) => legend.rows.flat().map((item) => item.key)));
566
+ const look = boardLook(ctx, styles), marks = markers(ctx);
567
+ const under = ({ x, y, w = 2, h = 2 }) => surfaceAt(g.frames, look, x + w / 2, y + h / 2);
568
+ const capabilities = g.nodes.map((node) => ({
569
+ ...drawItem(ctx, {
570
+ ...node,
571
+ icon: node.icon ? geometry(node.icon) : null,
572
+ under: under(node)
573
+ }, look),
574
+ meta: {
575
+ kind: "capability",
576
+ label: node.name,
577
+ container: node.parent.name,
578
+ ...node.mark ? { mark: node.mark } : {}
584
579
  }
585
- const textX = node.x + node.w / 2 + (node.icon ? 12 : 0), textY = node.y + node.h / 2;
586
- if (node.mark && node.tone) {
587
- const attrs = {
588
- x: textX - ctx.measure(node.label, FONT.body.size, FONT.body.weight) / 2,
589
- y: textY,
590
- "text-anchor": "start",
591
- "dominant-baseline": "central",
592
- "font-size": FONT.body.size,
593
- "font-weight": FONT.body.weight,
594
- fill: ctx.color("fg")
595
- };
596
- parts.push(ctx.el("text", attrs, [{
597
- ...ctx.el("tspan", { fill: tone }),
598
- text: node.mark
599
- }, {
600
- ...ctx.el("tspan"),
601
- text: ` ${node.name}`
602
- }]));
603
- } else parts.push(ctx.text(textX, textY, node.label, {
604
- anchor: "middle",
605
- size: FONT.body.size,
606
- fill: ctx.color("fg"),
607
- "dominant-baseline": "central"
608
- }));
609
- children.push({
610
- ...ctx.el("g", {}, parts),
611
- meta: {
612
- kind: "capability",
613
- label: node.name,
614
- container: node.parent?.title,
615
- ...node.mark ? { mark: node.mark } : {}
616
- }
617
- });
618
- }
580
+ }));
581
+ const paths = [], labels = [];
619
582
  for (const edge of g.edges) {
620
- const lineAttrs = {
621
- d: edge.path,
622
- fill: "none",
623
- stroke: ctx.color("muted"),
624
- "stroke-width": 2,
625
- "stroke-linecap": "round",
626
- ...edge.async ? { "stroke-dasharray": "5 4" } : {},
627
- "marker-end": `url(#${edge.async ? "blocks-arrow-async" : "blocks-arrow"})`
628
- };
629
- const parts = [ctx.path(edge.path, lineAttrs)];
630
- if (edge.label) {
631
- const lines = edge.labelLines || wrapText(edge.label, 160, FONT.label, (v, f) => ctx.measure(v, f.size, f.weight)).slice(0, LIMITS.labelLines);
632
- const { x, y, w, h } = edge.labelBox;
633
- parts.push(ctx.rect(x, y, w, h, {
634
- rx: 4,
635
- fill: d.bg
636
- }));
637
- lines.forEach((line, i) => parts.push(ctx.text(edge.labelX, edge.labelY + (i - (lines.length - 1) / 2) * 16, line, {
638
- anchor: "middle",
639
- size: FONT.label.size,
640
- fill: ctx.color("fg"),
641
- "dominant-baseline": "central"
642
- })));
643
- }
644
- children.push({
645
- ...ctx.el("g", {}, parts),
646
- meta: {
647
- kind: "relation",
583
+ const stroke = look.edge(edge.kind);
584
+ paths.push(drawEdge(ctx, edge, stroke, { end: marks.url("arrow", stroke.stroke) }));
585
+ if (edge.labelLines) {
586
+ const rect = edge.labelRect;
587
+ labels.push(drawLabel(ctx, {
648
588
  from: edge.from,
649
589
  to: edge.to,
650
- async: edge.async
651
- }
652
- });
590
+ rect,
591
+ lines: edge.labelLines,
592
+ plate: surfaceAt(g.frames, look, rect.x + rect.w / 2, rect.y + rect.h / 2)
593
+ }, look));
594
+ }
653
595
  }
596
+ const legends = g.legends.map((legend) => drawLegend(ctx, legend, look, marks, under({
597
+ x: legend.x,
598
+ y: legend.y
599
+ })));
654
600
  return {
655
601
  width: g.width,
656
602
  height: g.height,
657
- children
603
+ children: [
604
+ ...marks.defs(),
605
+ ...g.frames.map((frame) => drawFrame(ctx, frame, look)),
606
+ ...capabilities,
607
+ ...g.cards.map((card) => drawCard(ctx, {
608
+ ...card,
609
+ under: under(card)
610
+ }, look)),
611
+ ...g.notes.map((note) => drawNote(ctx, note, look)),
612
+ ...legends,
613
+ ...paths,
614
+ ...labels
615
+ ]
658
616
  };
659
617
  }
660
- function marker(id, ctx, dashed) {
661
- return ctx.el("marker", {
662
- id,
663
- viewBox: "0 0 10 10",
664
- refX: 8,
665
- refY: 5,
666
- markerWidth: 8,
667
- markerHeight: 8,
668
- orient: "auto-start-reverse"
669
- }, [ctx.path("M1 1 L9 5 L1 9 Z", {
670
- fill: ctx.color("muted"),
671
- ...dashed ? { "stroke-dasharray": "5 4" } : {}
672
- })]);
673
- }
674
- function cylinder(f, ctx, fill, stroke) {
675
- const ry = Math.min(7, Math.max(4, f.h / 8)), x = f.x, y = f.y, w = f.w, h = f.h;
676
- return ctx.path(`M${x} ${y + ry} A${w / 2} ${ry} 0 0 1 ${x + w} ${y + ry} V${y + h - ry} A${w / 2} ${ry} 0 0 1 ${x} ${y + h - ry} Z M${x} ${y + ry} A${w / 2} ${ry} 0 0 0 ${x + w} ${y + ry}`, {
677
- fill,
678
- stroke,
679
- "stroke-width": 1.5
680
- });
681
- }
682
618
  var implementations = { blocks: {
683
619
  parse,
684
620
  layout,