@fengwk/kchart 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +21 -0
  3. package/NOTICE.md +11 -0
  4. package/README.md +68 -2
  5. package/README.zh-CN.md +69 -0
  6. package/dist/LICENSE +21 -0
  7. package/dist/NOTICE.md +11 -0
  8. package/dist/assets/ICONS-LICENSE.txt +53 -0
  9. package/dist/assets/maps/LICENSE.md +75 -0
  10. package/dist/assets/maps/METADATA.md +9 -0
  11. package/dist/assets/maps/REGIONS.md +28 -0
  12. package/dist/assets/maps/us-states.geojson +1 -0
  13. package/dist/assets/maps/world.geojson +1 -0
  14. package/dist/esm/_virtual/_kchart-families.js +48 -0
  15. package/dist/esm/_virtual/_rolldown/runtime.js +12 -0
  16. package/dist/esm/assets/icons.js +11 -0
  17. package/dist/esm/assets/maps/us-states.js +3 -0
  18. package/dist/esm/assets/maps/world.js +3 -0
  19. package/dist/esm/assets/themes/claude.js +69 -0
  20. package/dist/esm/assets/themes/cloudmusic.js +62 -0
  21. package/dist/esm/assets/themes/kanagawa.js +67 -0
  22. package/dist/esm/assets/themes/obsidian.js +67 -0
  23. package/dist/esm/assets/themes/paper.js +61 -0
  24. package/dist/esm/assets/themes/terminal.js +60 -0
  25. package/dist/esm/assets/themes/tokyo.js +62 -0
  26. package/dist/esm/chart/basic.js +1313 -0
  27. package/dist/esm/chart/catalog.js +476 -0
  28. package/dist/esm/chart/composition.js +844 -0
  29. package/dist/esm/chart/context.js +189 -0
  30. package/dist/esm/chart/distribution.js +442 -0
  31. package/dist/esm/chart/fields.js +67 -0
  32. package/dist/esm/chart/maps.js +563 -0
  33. package/dist/esm/chart/mindmap.js +629 -0
  34. package/dist/esm/chart/multivariate.js +1229 -0
  35. package/dist/esm/chart/registry.js +108 -0
  36. package/dist/esm/chart/relations.js +949 -0
  37. package/dist/esm/chart/spec.js +1415 -0
  38. package/dist/esm/chart/stat-compare.js +302 -0
  39. package/dist/esm/chart/stat-trend.js +181 -0
  40. package/dist/esm/chart/statistics.js +1007 -0
  41. package/dist/esm/chart/unit-variants.js +645 -0
  42. package/dist/esm/chart/variants.js +552 -0
  43. package/dist/esm/core/color.js +197 -0
  44. package/dist/esm/core/context.js +256 -0
  45. package/dist/esm/core/diagnostics.js +23 -0
  46. package/dist/esm/core/format.js +167 -0
  47. package/dist/esm/core/geometry.js +130 -0
  48. package/dist/esm/core/icon-data.js +5 -0
  49. package/dist/esm/core/icons.js +173 -0
  50. package/dist/esm/core/scale.js +112 -0
  51. package/dist/esm/core/scene.js +234 -0
  52. package/dist/esm/core/svg.js +89 -0
  53. package/dist/esm/core/text.js +184 -0
  54. package/dist/esm/core/theme.js +318 -0
  55. package/dist/esm/diagram/agentflow.js +596 -0
  56. package/dist/esm/diagram/architecture.js +729 -0
  57. package/dist/esm/diagram/block.js +988 -0
  58. package/dist/esm/diagram/blocks.js +687 -0
  59. package/dist/esm/diagram/c4.js +1002 -0
  60. package/dist/esm/diagram/class.js +1158 -0
  61. package/dist/esm/diagram/cynefin.js +749 -0
  62. package/dist/esm/diagram/emphasis.js +7 -0
  63. package/dist/esm/diagram/er.js +657 -0
  64. package/dist/esm/diagram/eventmodeling.js +948 -0
  65. package/dist/esm/diagram/gantt-date.js +323 -0
  66. package/dist/esm/diagram/gantt.js +661 -0
  67. package/dist/esm/diagram/gitgraph.js +472 -0
  68. package/dist/esm/diagram/graph-layout.js +4046 -0
  69. package/dist/esm/diagram/graph-parse.js +1366 -0
  70. package/dist/esm/diagram/graph-route.js +490 -0
  71. package/dist/esm/diagram/graph.js +553 -0
  72. package/dist/esm/diagram/ishikawa.js +496 -0
  73. package/dist/esm/diagram/journey.js +512 -0
  74. package/dist/esm/diagram/kanban.js +280 -0
  75. package/dist/esm/diagram/label.js +56 -0
  76. package/dist/esm/diagram/layers.js +385 -0
  77. package/dist/esm/diagram/map-label.js +44 -0
  78. package/dist/esm/diagram/mindmap.js +277 -0
  79. package/dist/esm/diagram/numeric-composition.js +78 -0
  80. package/dist/esm/diagram/numeric-model.js +86 -0
  81. package/dist/esm/diagram/numeric-parse.js +205 -0
  82. package/dist/esm/diagram/numeric-radar.js +355 -0
  83. package/dist/esm/diagram/numeric-sankey.js +201 -0
  84. package/dist/esm/diagram/numeric-xy.js +422 -0
  85. package/dist/esm/diagram/packet.js +175 -0
  86. package/dist/esm/diagram/presentation.js +252 -0
  87. package/dist/esm/diagram/quadrant.js +297 -0
  88. package/dist/esm/diagram/railroad-parse.js +465 -0
  89. package/dist/esm/diagram/railroad.js +294 -0
  90. package/dist/esm/diagram/registry.js +296 -0
  91. package/dist/esm/diagram/relations.js +966 -0
  92. package/dist/esm/diagram/requirement.js +341 -0
  93. package/dist/esm/diagram/sequence.js +1228 -0
  94. package/dist/esm/diagram/shapes.js +366 -0
  95. package/dist/esm/diagram/source.js +538 -0
  96. package/dist/esm/diagram/support.js +153 -0
  97. package/dist/esm/diagram/swimlane-mermaid.js +140 -0
  98. package/dist/esm/diagram/swimlane.js +1186 -0
  99. package/dist/esm/diagram/time.js +748 -0
  100. package/dist/esm/diagram/timeline.js +376 -0
  101. package/dist/esm/diagram/tree-family-icon.js +22 -0
  102. package/dist/esm/diagram/treeview.js +293 -0
  103. package/dist/esm/diagram/usecase.js +852 -0
  104. package/dist/esm/diagram/venn.js +1038 -0
  105. package/dist/esm/diagram/wardley.js +838 -0
  106. package/dist/esm/index.d.ts +133 -0
  107. package/dist/esm/index.js +92 -0
  108. package/dist/esm/interaction.js +561 -0
  109. package/dist/esm/mermaid.d.ts +28 -0
  110. package/dist/esm/mermaid.js +70 -0
  111. package/dist/esm/node.d.ts +68 -0
  112. package/dist/esm/node.js +373 -0
  113. package/dist/esm/package.json +1 -0
  114. package/dist/esm/page-api.js +65 -0
  115. package/dist/esm/runtime.js +352 -0
  116. package/dist/esm/src/families.js +209 -0
  117. package/dist/page-api.js +1 -0
  118. package/dist/units/chart/basic.js +1 -0
  119. package/dist/units/chart/catalog.js +1 -0
  120. package/dist/units/chart/composition.js +1 -0
  121. package/dist/units/chart/context.js +1 -0
  122. package/dist/units/chart/distribution.js +1 -0
  123. package/dist/units/chart/fields.js +1 -0
  124. package/dist/units/chart/maps.js +1 -0
  125. package/dist/units/chart/mindmap.js +1 -0
  126. package/dist/units/chart/multivariate.js +1 -0
  127. package/dist/units/chart/registry.js +1 -0
  128. package/dist/units/chart/relations.js +1 -0
  129. package/dist/units/chart/spec.js +3 -0
  130. package/dist/units/chart/stat-compare.js +1 -0
  131. package/dist/units/chart/stat-trend.js +1 -0
  132. package/dist/units/chart/statistics.js +1 -0
  133. package/dist/units/chart/unit-variants.js +1 -0
  134. package/dist/units/chart/variants.js +1 -0
  135. package/dist/units/core/color.js +1 -0
  136. package/dist/units/core/context.js +1 -0
  137. package/dist/units/core/diagnostics.js +1 -0
  138. package/dist/units/core/format.js +1 -0
  139. package/dist/units/core/geometry.js +1 -0
  140. package/dist/units/core/icon-data.js +1 -0
  141. package/dist/units/core/icons.js +1 -0
  142. package/dist/units/core/scale.js +1 -0
  143. package/dist/units/core/scene.js +1 -0
  144. package/dist/units/core/svg.js +1 -0
  145. package/dist/units/core/text.js +2 -0
  146. package/dist/units/core/theme.js +1 -0
  147. package/dist/units/diagram/agentflow.js +12 -0
  148. package/dist/units/diagram/architecture.js +4 -0
  149. package/dist/units/diagram/block.js +2 -0
  150. package/dist/units/diagram/blocks.js +2 -0
  151. package/dist/units/diagram/c4.js +6 -0
  152. package/dist/units/diagram/class.js +5 -0
  153. package/dist/units/diagram/cynefin.js +4 -0
  154. package/dist/units/diagram/emphasis.js +1 -0
  155. package/dist/units/diagram/er.js +9 -0
  156. package/dist/units/diagram/eventmodeling.js +5 -0
  157. package/dist/units/diagram/gantt-date.js +1 -0
  158. package/dist/units/diagram/gantt.js +3 -0
  159. package/dist/units/diagram/gitgraph.js +2 -0
  160. package/dist/units/diagram/graph-layout.js +4 -0
  161. package/dist/units/diagram/graph-parse.js +9 -0
  162. package/dist/units/diagram/graph-route.js +1 -0
  163. package/dist/units/diagram/graph.js +1 -0
  164. package/dist/units/diagram/ishikawa.js +2 -0
  165. package/dist/units/diagram/journey.js +5 -0
  166. package/dist/units/diagram/kanban.js +2 -0
  167. package/dist/units/diagram/label.js +4 -0
  168. package/dist/units/diagram/layers.js +1 -0
  169. package/dist/units/diagram/map-label.js +1 -0
  170. package/dist/units/diagram/mindmap.js +2 -0
  171. package/dist/units/diagram/numeric-composition.js +1 -0
  172. package/dist/units/diagram/numeric-model.js +1 -0
  173. package/dist/units/diagram/numeric-parse.js +2 -0
  174. package/dist/units/diagram/numeric-radar.js +3 -0
  175. package/dist/units/diagram/numeric-sankey.js +2 -0
  176. package/dist/units/diagram/numeric-xy.js +2 -0
  177. package/dist/units/diagram/packet.js +2 -0
  178. package/dist/units/diagram/presentation.js +2 -0
  179. package/dist/units/diagram/quadrant.js +2 -0
  180. package/dist/units/diagram/railroad-parse.js +4 -0
  181. package/dist/units/diagram/railroad.js +1 -0
  182. package/dist/units/diagram/registry.js +2 -0
  183. package/dist/units/diagram/relations.js +3 -0
  184. package/dist/units/diagram/requirement.js +3 -0
  185. package/dist/units/diagram/sequence.js +2 -0
  186. package/dist/units/diagram/shapes.js +60 -0
  187. package/dist/units/diagram/source.js +20 -0
  188. package/dist/units/diagram/support.js +3 -0
  189. package/dist/units/diagram/swimlane-mermaid.js +3 -0
  190. package/dist/units/diagram/swimlane.js +2 -0
  191. package/dist/units/diagram/time.js +3 -0
  192. package/dist/units/diagram/timeline.js +2 -0
  193. package/dist/units/diagram/tree-family-icon.js +1 -0
  194. package/dist/units/diagram/treeview.js +2 -0
  195. package/dist/units/diagram/usecase.js +3 -0
  196. package/dist/units/diagram/venn.js +2 -0
  197. package/dist/units/diagram/wardley.js +4 -0
  198. package/dist/units/interaction.js +1 -0
  199. package/dist/units/runtime.js +1 -0
  200. package/dist/units.json +712 -0
  201. package/package.json +30 -4
@@ -0,0 +1,749 @@
1
+ import { __exportAll } from "../_virtual/_rolldown/runtime.js";
2
+ import { labelIcon } from "./tree-family-icon.js";
3
+ import { normalizeLabel } from "./label.js";
4
+ import { presentation } from "./presentation.js";
5
+ import { FONT, appearance, error, fallbackMeasure, isEn, labelText, warning, wrapText } from "./support.js";
6
+ // src/diagram/cynefin.js
7
+ var cynefin_exports = /* @__PURE__ */ __exportAll({
8
+ DOMAINS: () => DOMAINS,
9
+ NOTES: () => NOTES,
10
+ implementations: () => implementations
11
+ });
12
+ var DOMAINS = [
13
+ "complex",
14
+ "complicated",
15
+ "clear",
16
+ "chaotic",
17
+ "confusion"
18
+ ];
19
+ var QUADRANTS = [
20
+ "complex",
21
+ "complicated",
22
+ "chaotic",
23
+ "clear"
24
+ ];
25
+ var CELLS = {
26
+ complex: [0, 0],
27
+ complicated: [1, 0],
28
+ chaotic: [0, 1],
29
+ clear: [1, 1]
30
+ };
31
+ var TITLES = {
32
+ complex: "Complex",
33
+ complicated: "Complicated",
34
+ chaotic: "Chaotic",
35
+ clear: "Clear",
36
+ confusion: "Confusion"
37
+ };
38
+ var NOTES = {
39
+ complex: ["Probe → Sense → Respond", "Emergent Practices"],
40
+ complicated: ["Sense → Analyse → Respond", "Good Practices"],
41
+ clear: ["Sense → Categorise → Respond", "Best Practices"],
42
+ chaotic: ["Act → Sense → Respond", "Novel Practices"],
43
+ confusion: ["", "Disorder"]
44
+ };
45
+ var TITLES_ZH = {
46
+ complex: "复杂",
47
+ complicated: "繁杂",
48
+ chaotic: "混乱",
49
+ clear: "清晰",
50
+ confusion: "困惑"
51
+ };
52
+ var NOTES_ZH = {
53
+ complex: ["探测 → 感知 → 响应", "涌现实践"],
54
+ complicated: ["感知 → 分析 → 响应", "良好实践"],
55
+ clear: ["感知 → 分类 → 响应", "最佳实践"],
56
+ chaotic: ["行动 → 感知 → 响应", "新颖实践"],
57
+ confusion: ["", "失序"]
58
+ };
59
+ var TONES = {
60
+ complex: "tone1",
61
+ complicated: "tone2",
62
+ chaotic: "tone3",
63
+ clear: "tone4",
64
+ confusion: "tone5"
65
+ };
66
+ var MARGIN = 24;
67
+ var TITLE_LINE = 20;
68
+ var TITLE_GAP = 14;
69
+ var MIN_PLOT = 640;
70
+ var MAX_PLOT = 960;
71
+ var PANEL_PAD = 22;
72
+ var CORRIDOR = 46;
73
+ var NAME_LINE = 18;
74
+ var SUB_PITCH = 18;
75
+ var ITEM_GAP = 10;
76
+ var CHIP_PAD_X = 10;
77
+ var CHIP_MIN_H = 24;
78
+ var CHIP_LINE = 15;
79
+ var CHIP_GAP = 4;
80
+ var CHIP_CAP = 190;
81
+ var QUADRANT_HINT = 4;
82
+ var PORT_CLEAR = 16;
83
+ var BOW_RATIO = .12;
84
+ var BOW_MIN = 12;
85
+ var LABEL_LINE = 16;
86
+ var LABEL_CAP = 200;
87
+ var NODE_HINT = 60;
88
+ new Set(DOMAINS);
89
+ var STRING = /^(?:"((?:\\.|[^"\\])*)"|'((?:\\.|[^'\\])*)')/;
90
+ var DECODE = /\\(["'\\])/g;
91
+ function stripComment(line) {
92
+ let quote = "";
93
+ for (let i = 0; i < line.length; i += 1) {
94
+ const char = line[i];
95
+ if (quote) {
96
+ if (char === quote) quote = "";
97
+ continue;
98
+ }
99
+ if (char === "\"" || char === "'") {
100
+ quote = char;
101
+ continue;
102
+ }
103
+ if (char === "%" && line[i + 1] === "%") return line.slice(0, i);
104
+ }
105
+ return line;
106
+ }
107
+ function readStrings(text) {
108
+ const items = [];
109
+ let rest = String(text ?? "");
110
+ for (;;) {
111
+ const match = STRING.exec(rest);
112
+ if (!match) break;
113
+ items.push((match[1] ?? match[2] ?? "").replace(DECODE, "$1"));
114
+ rest = rest.slice(match[0].length);
115
+ }
116
+ return {
117
+ items,
118
+ rest: rest.trim()
119
+ };
120
+ }
121
+ function parse(source, info = {}) {
122
+ const lang = info.lang || "zh";
123
+ const firstLine = Number.isInteger(info.firstLine) ? info.firstLine : 2;
124
+ const headerLine = Number.isInteger(info.headerLine) ? info.headerLine : Math.max(1, firstLine - 1);
125
+ const errors = [];
126
+ const domains = Object.fromEntries(DOMAINS.map((name) => [name, []]));
127
+ const transitions = [];
128
+ const look = presentation({ lang });
129
+ const model = {
130
+ kind: "cynefin-beta",
131
+ title: "",
132
+ accTitle: "",
133
+ accDescr: "",
134
+ domains,
135
+ transitions,
136
+ showDomainDescriptions: info.config?.cynefin?.showDomainDescriptions !== false
137
+ };
138
+ const assets = /* @__PURE__ */ new Set();
139
+ const normalize = (raw, line) => {
140
+ const value = normalizeLabel(raw, {
141
+ lang,
142
+ line
143
+ });
144
+ for (const issue of value.diagnostics) if (!assets.has(issue.message)) {
145
+ assets.add(issue.message);
146
+ errors.push(issue);
147
+ }
148
+ return {
149
+ label: value.text,
150
+ icon: value.icon
151
+ };
152
+ };
153
+ const unknownDomain = (value, line) => error(lang, line, `未知的 Cynefin 域「${value}」`, `Unknown Cynefin domain "${value}"`, `使用 ${DOMAINS.join(" / ")}`, `Use one of ${DOMAINS.join(" / ")}`);
154
+ const readTitle = (value, line) => {
155
+ if (model.title) {
156
+ errors.push(error(lang, line, "标题重复", "Duplicate title", "只保留一个 title", "Keep only one title"));
157
+ return;
158
+ }
159
+ model.title = normalize(value.trim(), line).label;
160
+ };
161
+ const header = String(info.params ?? "").replace(/^:/, "").trim();
162
+ if (header) {
163
+ const inline = /^title\b\s*([\s\S]*)$/i.exec(header);
164
+ if (inline) readTitle(inline[1], headerLine);
165
+ else errors.push(error(lang, headerLine, `标题行之后多出「${header}」`, `Unexpected text after the header: "${header}"`, "把标题写成单独一行 title …", "Put the title on its own line"));
166
+ }
167
+ let current = null, block = null;
168
+ for (const [index, raw] of String(source ?? "").split("\n").entries()) {
169
+ const line = firstLine + index;
170
+ const text = stripComment(raw).trim();
171
+ if (block) {
172
+ block.lines.push(text);
173
+ if (/}/.test(text)) {
174
+ model.accDescr = labelText(block.lines.join("\n").replace(/}\s*$/, "").trim());
175
+ block = null;
176
+ }
177
+ continue;
178
+ }
179
+ if (!text) continue;
180
+ if (look.accept(text, line)) continue;
181
+ const accTitle = /^accTitle\s*:\s*([\s\S]*)$/i.exec(text);
182
+ if (accTitle) {
183
+ model.accTitle = labelText(accTitle[1].trim());
184
+ continue;
185
+ }
186
+ const accDescr = /^accDescr\s*:\s*([\s\S]*)$/i.exec(text);
187
+ if (accDescr) {
188
+ model.accDescr = labelText(accDescr[1].trim());
189
+ continue;
190
+ }
191
+ const accOpen = /^accDescr\s*\{([\s\S]*)$/i.exec(text);
192
+ if (accOpen) {
193
+ if (/}/.test(accOpen[1])) model.accDescr = labelText(accOpen[1].replace(/}[\s\S]*$/, "").trim());
194
+ else block = { lines: [accOpen[1]] };
195
+ continue;
196
+ }
197
+ const title = /^title\b\s*([\s\S]*)$/i.exec(text);
198
+ if (title) {
199
+ readTitle(title[1], line);
200
+ continue;
201
+ }
202
+ if (/^[A-Za-z]+\s*[-=.][-=>=.]*\s*>/.test(text)) {
203
+ const hop = /^([A-Za-z]+)\s*-->\s*([A-Za-z]+)\s*(?::\s*([\s\S]*))?$/.exec(text);
204
+ if (!hop) {
205
+ errors.push(error(lang, line, "只支持 --> 转移箭头", "Only --> transitions are supported", "把转移写成 complex --> clear", "Write the transition as complex --> clear"));
206
+ continue;
207
+ }
208
+ const from = DOMAINS.find((name) => name === hop[1].toLowerCase());
209
+ const to = DOMAINS.find((name) => name === hop[2].toLowerCase());
210
+ if (!from) {
211
+ errors.push(unknownDomain(hop[1], line));
212
+ continue;
213
+ }
214
+ if (!to) {
215
+ errors.push(unknownDomain(hop[2], line));
216
+ continue;
217
+ }
218
+ let label = "";
219
+ if (hop[3] !== void 0) {
220
+ const read = readStrings(hop[3]);
221
+ if (!read.items.length) {
222
+ errors.push(error(lang, line, "转移标签必须使用引号", "Expected a quoted transition label", "把标签写成 : \"文本\"", "Write the label as : \"text\""));
223
+ continue;
224
+ }
225
+ if (read.rest) {
226
+ errors.push(error(lang, line, `转移标签后多出「${read.rest}」`, `Unexpected text after the transition label: "${read.rest}"`, "一个转移只写一个引号标签", "Use one quoted label per transition"));
227
+ continue;
228
+ }
229
+ label = normalize(read.items[0], line).label;
230
+ }
231
+ if (from === to) {
232
+ errors.push(warning("DIAGRAM_HINT", lang, line, `自环转移「${from}」已省略`, `The self-loop on "${from}" was dropped`, "删除自环;域不能转移到自身", "Remove the self-loop; a domain cannot transition to itself"));
233
+ continue;
234
+ }
235
+ transitions.push({
236
+ from,
237
+ to,
238
+ label,
239
+ line
240
+ });
241
+ continue;
242
+ }
243
+ const word = /^([A-Za-z]+)([\s\S]*)$/.exec(text);
244
+ const domain = word && DOMAINS.find((name) => name === word[1].toLowerCase());
245
+ if (domain) {
246
+ current = domain;
247
+ const read = readStrings(word[2]);
248
+ if (read.rest) errors.push(error(lang, line, `域「${domain}」之后多出「${read.rest}」`, `Unexpected text after domain "${domain}": "${read.rest}"`, "每个条目写成一行引号字符串", "Put each item on its own line as a quoted string"));
249
+ for (const item of read.items) domains[domain].push({
250
+ ...normalize(item, line),
251
+ line
252
+ });
253
+ continue;
254
+ }
255
+ if (!current) {
256
+ errors.push(unknownDomain(word ? word[1] : text, line));
257
+ continue;
258
+ }
259
+ const read = readStrings(text);
260
+ if (!read.items.length) {
261
+ errors.push(error(lang, line, "域条目必须是引号字符串", "Expected a quoted string for a domain item", "把条目写成 \"文本\"", "Wrap the item in quotes"));
262
+ continue;
263
+ }
264
+ if (read.rest) {
265
+ errors.push(error(lang, line, `条目之后多出「${read.rest}」`, `Unexpected text after the item: "${read.rest}"`, "每个条目只写一个引号字符串", "Use one quoted string per item"));
266
+ continue;
267
+ }
268
+ for (const item of read.items) domains[current].push({
269
+ ...normalize(item, line),
270
+ line
271
+ });
272
+ }
273
+ if (block) {
274
+ errors.push(error(lang, firstLine, "accDescr 缺少结束的 }", "accDescr is missing its closing }", "补齐 accDescr 的右花括号", "Close the accDescr block"));
275
+ model.accDescr = labelText(block.lines.join("\n").trim());
276
+ }
277
+ errors.push(...look.diagnostics());
278
+ transitions.forEach((transition, index) => {
279
+ transition.status = look.edgeStatusOf(index);
280
+ });
281
+ for (const name of DOMAINS) domains[name].forEach((item, index) => {
282
+ item.id = `${name}-${index}`;
283
+ item.status = look.statusOf(item.id) ?? look.statusOf(name);
284
+ item.link = look.linkOf(item.id) ?? look.linkOf(name);
285
+ });
286
+ return {
287
+ model,
288
+ errors
289
+ };
290
+ }
291
+ var clamp = (value, low, high) => Math.min(high, Math.max(low, value));
292
+ var centreOf = (rect) => rect.ellipse ? {
293
+ x: rect.cx,
294
+ y: rect.cy
295
+ } : {
296
+ x: rect.x + rect.w / 2,
297
+ y: rect.y + rect.h / 2
298
+ };
299
+ function portOf(from, to) {
300
+ const a = centreOf(from), b = centreOf(to);
301
+ if (from.ellipse) {
302
+ const angle = Math.atan2((b.y - from.cy) / from.ry, (b.x - from.cx) / from.rx);
303
+ const cos = Math.cos(angle), sin = Math.sin(angle);
304
+ return {
305
+ x: from.cx + (from.rx + 8) * cos,
306
+ y: from.cy + (from.ry + 8) * sin
307
+ };
308
+ }
309
+ const dx = b.x - a.x, dy = b.y - a.y;
310
+ return Math.abs(dx) >= Math.abs(dy) ? {
311
+ x: dx >= 0 ? from.x + from.w + PORT_CLEAR : from.x - PORT_CLEAR,
312
+ y: a.y
313
+ } : {
314
+ x: a.x,
315
+ y: dy >= 0 ? from.y + from.h + PORT_CLEAR : from.y - PORT_CLEAR
316
+ };
317
+ }
318
+ function arcOf(a, b, centre, rx, ry) {
319
+ const dx = b.x - a.x, dy = b.y - a.y, len = Math.hypot(dx, dy) || 1;
320
+ const nx = -dy / len, ny = dx / len;
321
+ const mid = {
322
+ x: (a.x + b.x) / 2,
323
+ y: (a.y + b.y) / 2
324
+ };
325
+ const away = (mid.x - centre.x) * nx + (mid.y - centre.y) * ny >= 0 ? 1 : -1;
326
+ const clear = (ctrl) => {
327
+ for (let i = 0; i <= 20; i += 1) {
328
+ const t = i / 20, u = 1 - t;
329
+ const x = u * u * a.x + 2 * u * t * ctrl.x + t * t * b.x;
330
+ const y = u * u * a.y + 2 * u * t * ctrl.y + t * t * b.y;
331
+ if (Math.hypot((x - centre.x) / rx, (y - centre.y) / ry) < 1.12) return false;
332
+ }
333
+ return true;
334
+ };
335
+ let offset = Math.max(BOW_MIN, len * BOW_RATIO);
336
+ let ctrl = {
337
+ x: mid.x + nx * offset * away,
338
+ y: mid.y + ny * offset * away
339
+ };
340
+ const limit = len * 1.4 + 240;
341
+ while (!clear(ctrl) && offset < limit) {
342
+ offset += 8;
343
+ ctrl = {
344
+ x: mid.x + nx * offset * away,
345
+ y: mid.y + ny * offset * away
346
+ };
347
+ }
348
+ const apex = {
349
+ x: (a.x + 2 * ctrl.x + b.x) / 4,
350
+ y: (a.y + 2 * ctrl.y + b.y) / 4
351
+ };
352
+ return {
353
+ a,
354
+ b,
355
+ ctrl,
356
+ away,
357
+ nx,
358
+ ny,
359
+ apex,
360
+ offset
361
+ };
362
+ }
363
+ function layout(model, options = {}) {
364
+ const measure = options.measure || fallbackMeasure;
365
+ const width = Math.max(1, Number(options.width) || 800);
366
+ const lang = options.lang || "zh";
367
+ const titles = isEn(lang) ? TITLES : TITLES_ZH, notes = isEn(lang) ? NOTES : NOTES_ZH;
368
+ const errors = [];
369
+ const ink = (value, font) => Math.max(0, measure(value, font.size, font.weight));
370
+ const wrap = (value, maxWidth, font) => wrapText(value, maxWidth, font, (piece, spec) => measure(piece, spec));
371
+ const nameFont = {
372
+ size: FONT.title.size,
373
+ weight: FONT.title.weight
374
+ };
375
+ const bodyFont = {
376
+ size: FONT.label.size,
377
+ weight: FONT.label.weight
378
+ };
379
+ const widest = (lines, font) => Math.ceil(Math.max(0, ...lines.map((line) => ink(line, font))));
380
+ const titleLines = model.title ? wrap(model.title, Math.max(160, Math.min(640, width - 48)), nameFont) : [];
381
+ const titleHeight = titleLines.length ? titleLines.length * TITLE_LINE + TITLE_GAP : 0;
382
+ const plotW = clamp(width - 48, MIN_PLOT, MAX_PLOT);
383
+ const chipCap = Math.max(96, Math.min(CHIP_CAP, plotW / 2 - 44 - 8));
384
+ const chipOf = (label, cap, icon) => {
385
+ const lines = wrap(label, cap, bodyFont);
386
+ return {
387
+ lines,
388
+ w: widest(lines, bodyFont) + 20 + (icon ? 18 : 0),
389
+ h: Math.max(CHIP_MIN_H, lines.length * CHIP_LINE + 12)
390
+ };
391
+ };
392
+ const blocks = {};
393
+ let count = 0;
394
+ for (const name of QUADRANTS) {
395
+ const rows = model.domains[name];
396
+ count += rows.length;
397
+ const chips = rows.map((item, index) => ({
398
+ ...item,
399
+ id: `${name}-${index}`,
400
+ line: item.line,
401
+ ...chipOf(item.label, chipCap, item.icon)
402
+ }));
403
+ if (rows.length > QUADRANT_HINT) errors.push(warning("DIAGRAM_HINT", lang, rows[QUADRANT_HINT].line, `「${titles[name]}」有 ${rows.length} 个条目,面板会变高`, `"${titles[name]}" holds ${rows.length} items and makes a tall panel`, `每个域保留 ${QUADRANT_HINT} 个条目以内`, `Keep at most ${QUADRANT_HINT} items per domain`));
404
+ const subs = model.showDomainDescriptions ? notes[name] : [notes[name][1]];
405
+ const blockW = Math.ceil(Math.max(widest([titles[name]], nameFont), widest(subs, bodyFont), ...chips.map((chip) => chip.w), 0));
406
+ const chipsH = chips.reduce((sum, chip) => sum + chip.h + CHIP_GAP, -4);
407
+ blocks[name] = {
408
+ id: name,
409
+ subs,
410
+ chips,
411
+ w: blockW,
412
+ h: 24 + subs.length * SUB_PITCH + (chips.length ? ITEM_GAP + chipsH : 0),
413
+ tone: TONES[name],
414
+ count: rows.length
415
+ };
416
+ }
417
+ const maxBlockH = Math.max(...QUADRANTS.map((name) => blocks[name].h));
418
+ const confusionRows = model.domains.confusion;
419
+ count += confusionRows.length;
420
+ const confCap = Math.max(80, plotW * .15 * 2 - 56);
421
+ const confusionChips = confusionRows.map((item, index) => ({
422
+ ...item,
423
+ id: `confusion-${index}`,
424
+ line: item.line,
425
+ ...chipOf(item.label, confCap, item.icon)
426
+ }));
427
+ const confusionChipsH = confusionChips.reduce((sum, chip) => sum + chip.h + CHIP_GAP, -4);
428
+ const confusionBlockH = 24 + (model.showDomainDescriptions ? SUB_PITCH : 0) + (confusionChips.length ? ITEM_GAP + confusionChipsH : 0);
429
+ const rx = Math.max(plotW * .15, Math.ceil(Math.max(0, ...confusionChips.map((chip) => chip.w)) / 2) + 18);
430
+ const requiredRy = confusionBlockH * .68 + 12;
431
+ const plotH = Math.ceil(Math.max(clamp(plotW * .72, 380, 620), 2 * (PANEL_PAD + maxBlockH + CORRIDOR), 2 * (requiredRy + CORRIDOR)));
432
+ const ry = Math.max(plotH * .15, requiredRy);
433
+ const panelW = plotW / 2, panelH = plotH / 2;
434
+ const plotX = MARGIN, plotY = MARGIN + titleHeight;
435
+ const centre = {
436
+ x: plotX + plotW / 2,
437
+ y: plotY + plotH / 2
438
+ };
439
+ const bottomBlockH = Math.max(blocks.chaotic.h, blocks.clear.h);
440
+ const quadrants = {};
441
+ for (const name of QUADRANTS) {
442
+ const [col, row] = CELLS[name];
443
+ const panel = {
444
+ x: plotX + col * panelW,
445
+ y: plotY + row * panelH,
446
+ w: panelW,
447
+ h: panelH
448
+ };
449
+ const block = blocks[name];
450
+ const blockX = panel.x + (panel.w - block.w) / 2;
451
+ const blockY = row === 0 ? panel.y + PANEL_PAD : panel.y + panel.h - PANEL_PAD - bottomBlockH;
452
+ const texts = [];
453
+ let cursor = blockY;
454
+ texts.push({
455
+ kind: "name",
456
+ text: titles[name],
457
+ x: blockX + block.w / 2,
458
+ y: cursor + NAME_LINE / 2,
459
+ font: nameFont
460
+ });
461
+ cursor += 24;
462
+ for (const line of block.subs) {
463
+ texts.push({
464
+ kind: "sub",
465
+ text: line,
466
+ x: blockX + block.w / 2,
467
+ y: cursor + SUB_PITCH / 2,
468
+ font: bodyFont
469
+ });
470
+ cursor += SUB_PITCH;
471
+ }
472
+ if (block.chips.length) cursor += ITEM_GAP;
473
+ for (const chip of block.chips) {
474
+ chip.x = blockX + (block.w - chip.w) / 2;
475
+ chip.y = cursor;
476
+ cursor += chip.h + CHIP_GAP;
477
+ }
478
+ quadrants[name] = {
479
+ ...block,
480
+ ...panel,
481
+ row,
482
+ blockX,
483
+ blockY,
484
+ content: {
485
+ x: blockX,
486
+ y: blockY,
487
+ w: block.w,
488
+ h: block.h
489
+ },
490
+ texts
491
+ };
492
+ }
493
+ const confusionTexts = [];
494
+ {
495
+ let cursor = centre.y - confusionBlockH / 2;
496
+ confusionTexts.push({
497
+ kind: "name",
498
+ text: titles.confusion,
499
+ x: centre.x,
500
+ y: cursor + NAME_LINE / 2,
501
+ font: nameFont
502
+ });
503
+ cursor += 24;
504
+ if (model.showDomainDescriptions) {
505
+ confusionTexts.push({
506
+ kind: "sub",
507
+ text: notes.confusion[1],
508
+ x: centre.x,
509
+ y: cursor + SUB_PITCH / 2,
510
+ font: bodyFont
511
+ });
512
+ cursor += SUB_PITCH;
513
+ }
514
+ cursor += ITEM_GAP;
515
+ for (const chip of confusionChips) {
516
+ chip.x = centre.x - chip.w / 2;
517
+ chip.y = cursor;
518
+ cursor += chip.h + CHIP_GAP;
519
+ }
520
+ }
521
+ const shapes = {
522
+ ...Object.fromEntries(QUADRANTS.map((name) => [name, quadrants[name].content])),
523
+ confusion: {
524
+ ellipse: true,
525
+ cx: centre.x,
526
+ cy: centre.y,
527
+ rx,
528
+ ry
529
+ }
530
+ };
531
+ const arcs = [];
532
+ for (const transition of model.transitions) {
533
+ const arc = arcOf(portOf(shapes[transition.from], shapes[transition.to]), portOf(shapes[transition.to], shapes[transition.from]), centre, rx, ry);
534
+ let label = null;
535
+ if (transition.label) {
536
+ const lines = wrap(transition.label, Math.max(96, Math.min(LABEL_CAP, plotW - 80)), bodyFont);
537
+ const w = widest(lines, bodyFont) + 16;
538
+ const h = lines.length * LABEL_LINE + 6;
539
+ label = {
540
+ lines,
541
+ x: clamp(arc.apex.x + arc.nx * arc.away * 16 - w / 2, 30, plotX + plotW - 6 - w),
542
+ y: clamp(arc.apex.y + arc.ny * arc.away * 16 - h / 2, plotY + 6, plotY + plotH - 6 - h),
543
+ w,
544
+ h
545
+ };
546
+ }
547
+ arcs.push({
548
+ ...transition,
549
+ ...arc,
550
+ label
551
+ });
552
+ }
553
+ if (count > NODE_HINT) {
554
+ const line = model.transitions[0]?.line || confusionRows[0]?.line || 1;
555
+ errors.push(warning("LARGE_DIAGRAM", lang, line, `Cynefin 图有 ${count} 个条目,建议拆分`, `The Cynefin map holds ${count} items; consider splitting it`, "按域拆成多张图", "Split the map by domain"));
556
+ }
557
+ const planWidth = Math.ceil(plotW + 48);
558
+ const planHeight = Math.ceil(plotY + plotH + MARGIN);
559
+ if (count <= NODE_HINT && (planWidth > width * 2 || planHeight > width * 2)) {
560
+ const line = confusionRows[0]?.line || 1;
561
+ errors.push(warning("LARGE_DIAGRAM", lang, line, `Cynefin 图需要 ${planWidth}×${planHeight}px,超过图框两倍`, `The Cynefin map needs ${planWidth}×${planHeight}px, more than twice the frame`, "加宽图框,或减少域条目", "Widen the frame, or trim the domain items"));
562
+ }
563
+ return {
564
+ width: planWidth,
565
+ height: planHeight,
566
+ title: titleLines.length ? {
567
+ lines: titleLines,
568
+ x: plotX + plotW / 2,
569
+ top: 34
570
+ } : null,
571
+ plot: {
572
+ x: plotX,
573
+ y: plotY,
574
+ w: plotW,
575
+ h: plotH
576
+ },
577
+ centre,
578
+ rx,
579
+ ry,
580
+ quadrants: QUADRANTS.map((name) => quadrants[name]),
581
+ confusion: {
582
+ texts: confusionTexts,
583
+ chips: confusionChips
584
+ },
585
+ arcs,
586
+ errors,
587
+ anchor: {
588
+ x: centre.x,
589
+ y: centre.y
590
+ }
591
+ };
592
+ }
593
+ var path = (ctx, d, attrs, meta) => ctx.path(d, {
594
+ ...attrs,
595
+ ...meta ? { meta } : {}
596
+ });
597
+ function scene(plan, ctx) {
598
+ const look = appearance(ctx);
599
+ const paper = ctx.color("bg");
600
+ const ink = ctx.design;
601
+ const tone = (name) => ctx.frameTone(ctx.color(TONES[name]));
602
+ const children = [];
603
+ const label = (text, font, fill, x, y, anchor = "middle") => ctx.text(x, y, text, {
604
+ anchor,
605
+ size: font.size,
606
+ weight: font.weight,
607
+ fill,
608
+ "dominant-baseline": "central"
609
+ });
610
+ const arrow = {
611
+ tag: "marker",
612
+ attrs: {
613
+ id: "cynefin-arrow",
614
+ viewBox: "0 0 8 8",
615
+ refX: 7,
616
+ refY: 4,
617
+ markerWidth: 8,
618
+ markerHeight: 8,
619
+ markerUnits: "userSpaceOnUse",
620
+ orient: "auto"
621
+ },
622
+ children: [ctx.path("M0 0 L8 4 L0 8 Z", { fill: ink.fg4 })]
623
+ };
624
+ children.push(ctx.el("defs", {}, [arrow]));
625
+ for (const panel of plan.quadrants) {
626
+ const color = tone(panel.id);
627
+ children.push(ctx.rect(panel.x, panel.y, panel.w, panel.h, {
628
+ rx: 8,
629
+ fill: ctx.tint(paper, color, .07),
630
+ stroke: ctx.tint(paper, color, .35),
631
+ "stroke-width": 1,
632
+ meta: {
633
+ kind: "frame",
634
+ id: panel.id
635
+ }
636
+ }));
637
+ }
638
+ const { x: px, y: py, w: pw, h: ph } = plan.plot;
639
+ const seamY = plan.centre.y, seamX = plan.centre.x;
640
+ const gapX = plan.rx + 12, gapY = plan.ry + 12;
641
+ children.push(ctx.line(px, seamY, seamX - gapX, seamY, {
642
+ stroke: ctx.color("axis"),
643
+ "stroke-width": 2,
644
+ "stroke-linecap": "round"
645
+ }));
646
+ children.push(ctx.line(seamX + gapX, seamY, px + pw, seamY, {
647
+ stroke: ctx.color("axis"),
648
+ "stroke-width": 2,
649
+ "stroke-linecap": "round"
650
+ }));
651
+ children.push(ctx.line(seamX, py, seamX, seamY - gapY, {
652
+ stroke: ctx.color("axis"),
653
+ "stroke-width": 2,
654
+ "stroke-linecap": "round"
655
+ }));
656
+ children.push(ctx.line(seamX, seamY + gapY, seamX, py + ph, {
657
+ stroke: ink.danger,
658
+ "stroke-width": 3,
659
+ "stroke-linecap": "round"
660
+ }));
661
+ children.push({
662
+ ...ctx.el("ellipse", {
663
+ cx: plan.centre.x,
664
+ cy: plan.centre.y,
665
+ rx: plan.rx,
666
+ ry: plan.ry,
667
+ fill: ctx.tint(paper, tone("confusion"), .08),
668
+ stroke: ink.fg4,
669
+ "stroke-width": 1.5,
670
+ "stroke-dasharray": "4 3"
671
+ }),
672
+ meta: {
673
+ kind: "frame",
674
+ id: "confusion"
675
+ }
676
+ });
677
+ for (const panel of plan.quadrants) for (const item of panel.texts) children.push(label(item.text, item.font, item.kind === "name" ? ink.fg1 : ctx.color("muted"), item.x, item.y));
678
+ for (const item of plan.confusion.texts) children.push(label(item.text, item.font, item.kind === "name" ? ink.fg1 : ctx.color("muted"), item.x, item.y));
679
+ const chip = (item, extra = {}) => ctx.el("g", {}, [
680
+ ctx.rect(item.x, item.y, item.w, item.h, {
681
+ rx: look.smallRadius,
682
+ fill: extra.fill || (item.status ? ctx.tint(ctx.design.surface, ink[item.status], .1) : ctx.design.surface),
683
+ stroke: extra.dashed ? ink.line2 : item.status ? ink[item.status] : ctx.design.line2,
684
+ "stroke-width": 1,
685
+ ...extra.dashed ? { "stroke-dasharray": "4 3" } : {},
686
+ ...extra.meta ? { meta: extra.meta } : {}
687
+ }),
688
+ ...item.icon ? [labelIcon(ctx, item.icon, item.x + CHIP_PAD_X + 6, item.y + item.h / 2, 12, ink.fg3)] : [],
689
+ ...item.lines.map((line, index) => label(line, FONT.label, ink.fg2, item.x + item.w / 2 + (item.icon ? 9 : 0), item.y + item.h / 2 + (index - (item.lines.length - 1) / 2) * LABEL_LINE))
690
+ ]);
691
+ const addChip = (item) => {
692
+ const drawing = chip(item, { meta: {
693
+ kind: "node",
694
+ id: item.id
695
+ } });
696
+ children.push(item.link ? ctx.link(item.link.href, [drawing], item.link) : drawing);
697
+ };
698
+ for (const panel of plan.quadrants) for (const item of panel.chips) addChip(item);
699
+ for (const item of plan.confusion.chips) addChip(item);
700
+ for (const arc of plan.arcs) children.push(path(ctx, `M${arc.a.x} ${arc.a.y} Q${arc.ctrl.x} ${arc.ctrl.y} ${arc.b.x} ${arc.b.y}`, {
701
+ fill: "none",
702
+ stroke: arc.status ? ctx.frameTone(ink[arc.status]) : ink.fg4,
703
+ "stroke-width": 1.5,
704
+ "marker-end": "url(#cynefin-arrow)"
705
+ }, {
706
+ kind: "edge",
707
+ from: arc.from,
708
+ to: arc.to
709
+ }));
710
+ for (const arc of plan.arcs) {
711
+ if (!arc.label) continue;
712
+ children.push({
713
+ ...ctx.el("g", {}, [ctx.rect(arc.label.x, arc.label.y, arc.label.w, arc.label.h, {
714
+ rx: look.smallRadius,
715
+ fill: paper,
716
+ stroke: ctx.tint(paper, ink.fg4, .35),
717
+ "stroke-width": 1
718
+ }), ...arc.label.lines.map((line, index) => label(line, {
719
+ size: FONT.label.size,
720
+ weight: 400
721
+ }, ctx.color("muted"), arc.label.x + arc.label.w / 2, arc.label.y + arc.label.h / 2 + (index - (arc.label.lines.length - 1) / 2) * LABEL_LINE))]),
722
+ meta: {
723
+ kind: "edge-label-group",
724
+ from: arc.from,
725
+ to: arc.to
726
+ }
727
+ });
728
+ }
729
+ if (plan.title) plan.title.lines.forEach((line, index) => children.push(label(line, {
730
+ size: FONT.title.size,
731
+ weight: FONT.title.weight
732
+ }, ink.fg1, plan.title.x, plan.title.top + index * TITLE_LINE)));
733
+ return {
734
+ width: plan.width,
735
+ height: plan.height,
736
+ title: plan.title ? plan.title.lines.join(" ") : void 0,
737
+ children,
738
+ anchor: plan.anchor
739
+ };
740
+ }
741
+ var implementations = { "cynefin-beta": {
742
+ optionMode: "raw",
743
+ parse,
744
+ layout,
745
+ scene,
746
+ acceptsPresentation: true,
747
+ honoredConfig: ["cynefin.showDomainDescriptions"]
748
+ } };
749
+ export { DOMAINS, NOTES, cynefin_exports, implementations };