@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.
- package/CHANGELOG.md +17 -0
- package/LICENSE +21 -0
- package/NOTICE.md +11 -0
- package/README.md +68 -2
- package/README.zh-CN.md +69 -0
- package/dist/LICENSE +21 -0
- package/dist/NOTICE.md +11 -0
- package/dist/assets/ICONS-LICENSE.txt +53 -0
- package/dist/assets/maps/LICENSE.md +75 -0
- package/dist/assets/maps/METADATA.md +9 -0
- package/dist/assets/maps/REGIONS.md +28 -0
- package/dist/assets/maps/us-states.geojson +1 -0
- package/dist/assets/maps/world.geojson +1 -0
- package/dist/esm/_virtual/_kchart-families.js +48 -0
- package/dist/esm/_virtual/_rolldown/runtime.js +12 -0
- package/dist/esm/assets/icons.js +11 -0
- package/dist/esm/assets/maps/us-states.js +3 -0
- package/dist/esm/assets/maps/world.js +3 -0
- package/dist/esm/assets/themes/claude.js +69 -0
- package/dist/esm/assets/themes/cloudmusic.js +62 -0
- package/dist/esm/assets/themes/kanagawa.js +67 -0
- package/dist/esm/assets/themes/obsidian.js +67 -0
- package/dist/esm/assets/themes/paper.js +61 -0
- package/dist/esm/assets/themes/terminal.js +60 -0
- package/dist/esm/assets/themes/tokyo.js +62 -0
- package/dist/esm/chart/basic.js +1313 -0
- package/dist/esm/chart/catalog.js +476 -0
- package/dist/esm/chart/composition.js +844 -0
- package/dist/esm/chart/context.js +189 -0
- package/dist/esm/chart/distribution.js +442 -0
- package/dist/esm/chart/fields.js +67 -0
- package/dist/esm/chart/maps.js +563 -0
- package/dist/esm/chart/mindmap.js +629 -0
- package/dist/esm/chart/multivariate.js +1229 -0
- package/dist/esm/chart/registry.js +108 -0
- package/dist/esm/chart/relations.js +949 -0
- package/dist/esm/chart/spec.js +1415 -0
- package/dist/esm/chart/stat-compare.js +302 -0
- package/dist/esm/chart/stat-trend.js +181 -0
- package/dist/esm/chart/statistics.js +1007 -0
- package/dist/esm/chart/unit-variants.js +645 -0
- package/dist/esm/chart/variants.js +552 -0
- package/dist/esm/core/color.js +197 -0
- package/dist/esm/core/context.js +256 -0
- package/dist/esm/core/diagnostics.js +23 -0
- package/dist/esm/core/format.js +167 -0
- package/dist/esm/core/geometry.js +130 -0
- package/dist/esm/core/icon-data.js +5 -0
- package/dist/esm/core/icons.js +173 -0
- package/dist/esm/core/scale.js +112 -0
- package/dist/esm/core/scene.js +234 -0
- package/dist/esm/core/svg.js +89 -0
- package/dist/esm/core/text.js +184 -0
- package/dist/esm/core/theme.js +318 -0
- package/dist/esm/diagram/agentflow.js +596 -0
- package/dist/esm/diagram/architecture.js +729 -0
- package/dist/esm/diagram/block.js +988 -0
- package/dist/esm/diagram/blocks.js +687 -0
- package/dist/esm/diagram/c4.js +1002 -0
- package/dist/esm/diagram/class.js +1158 -0
- package/dist/esm/diagram/cynefin.js +749 -0
- package/dist/esm/diagram/emphasis.js +7 -0
- package/dist/esm/diagram/er.js +657 -0
- package/dist/esm/diagram/eventmodeling.js +948 -0
- package/dist/esm/diagram/gantt-date.js +323 -0
- package/dist/esm/diagram/gantt.js +661 -0
- package/dist/esm/diagram/gitgraph.js +472 -0
- package/dist/esm/diagram/graph-layout.js +4046 -0
- package/dist/esm/diagram/graph-parse.js +1366 -0
- package/dist/esm/diagram/graph-route.js +490 -0
- package/dist/esm/diagram/graph.js +553 -0
- package/dist/esm/diagram/ishikawa.js +496 -0
- package/dist/esm/diagram/journey.js +512 -0
- package/dist/esm/diagram/kanban.js +280 -0
- package/dist/esm/diagram/label.js +56 -0
- package/dist/esm/diagram/layers.js +385 -0
- package/dist/esm/diagram/map-label.js +44 -0
- package/dist/esm/diagram/mindmap.js +277 -0
- package/dist/esm/diagram/numeric-composition.js +78 -0
- package/dist/esm/diagram/numeric-model.js +86 -0
- package/dist/esm/diagram/numeric-parse.js +205 -0
- package/dist/esm/diagram/numeric-radar.js +355 -0
- package/dist/esm/diagram/numeric-sankey.js +201 -0
- package/dist/esm/diagram/numeric-xy.js +422 -0
- package/dist/esm/diagram/packet.js +175 -0
- package/dist/esm/diagram/presentation.js +252 -0
- package/dist/esm/diagram/quadrant.js +297 -0
- package/dist/esm/diagram/railroad-parse.js +465 -0
- package/dist/esm/diagram/railroad.js +294 -0
- package/dist/esm/diagram/registry.js +296 -0
- package/dist/esm/diagram/relations.js +966 -0
- package/dist/esm/diagram/requirement.js +341 -0
- package/dist/esm/diagram/sequence.js +1228 -0
- package/dist/esm/diagram/shapes.js +366 -0
- package/dist/esm/diagram/source.js +538 -0
- package/dist/esm/diagram/support.js +153 -0
- package/dist/esm/diagram/swimlane-mermaid.js +140 -0
- package/dist/esm/diagram/swimlane.js +1186 -0
- package/dist/esm/diagram/time.js +748 -0
- package/dist/esm/diagram/timeline.js +376 -0
- package/dist/esm/diagram/tree-family-icon.js +22 -0
- package/dist/esm/diagram/treeview.js +293 -0
- package/dist/esm/diagram/usecase.js +852 -0
- package/dist/esm/diagram/venn.js +1038 -0
- package/dist/esm/diagram/wardley.js +838 -0
- package/dist/esm/index.d.ts +133 -0
- package/dist/esm/index.js +92 -0
- package/dist/esm/interaction.js +561 -0
- package/dist/esm/mermaid.d.ts +28 -0
- package/dist/esm/mermaid.js +70 -0
- package/dist/esm/node.d.ts +68 -0
- package/dist/esm/node.js +373 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/page-api.js +65 -0
- package/dist/esm/runtime.js +352 -0
- package/dist/esm/src/families.js +209 -0
- package/dist/page-api.js +1 -0
- package/dist/units/chart/basic.js +1 -0
- package/dist/units/chart/catalog.js +1 -0
- package/dist/units/chart/composition.js +1 -0
- package/dist/units/chart/context.js +1 -0
- package/dist/units/chart/distribution.js +1 -0
- package/dist/units/chart/fields.js +1 -0
- package/dist/units/chart/maps.js +1 -0
- package/dist/units/chart/mindmap.js +1 -0
- package/dist/units/chart/multivariate.js +1 -0
- package/dist/units/chart/registry.js +1 -0
- package/dist/units/chart/relations.js +1 -0
- package/dist/units/chart/spec.js +3 -0
- package/dist/units/chart/stat-compare.js +1 -0
- package/dist/units/chart/stat-trend.js +1 -0
- package/dist/units/chart/statistics.js +1 -0
- package/dist/units/chart/unit-variants.js +1 -0
- package/dist/units/chart/variants.js +1 -0
- package/dist/units/core/color.js +1 -0
- package/dist/units/core/context.js +1 -0
- package/dist/units/core/diagnostics.js +1 -0
- package/dist/units/core/format.js +1 -0
- package/dist/units/core/geometry.js +1 -0
- package/dist/units/core/icon-data.js +1 -0
- package/dist/units/core/icons.js +1 -0
- package/dist/units/core/scale.js +1 -0
- package/dist/units/core/scene.js +1 -0
- package/dist/units/core/svg.js +1 -0
- package/dist/units/core/text.js +2 -0
- package/dist/units/core/theme.js +1 -0
- package/dist/units/diagram/agentflow.js +12 -0
- package/dist/units/diagram/architecture.js +4 -0
- package/dist/units/diagram/block.js +2 -0
- package/dist/units/diagram/blocks.js +2 -0
- package/dist/units/diagram/c4.js +6 -0
- package/dist/units/diagram/class.js +5 -0
- package/dist/units/diagram/cynefin.js +4 -0
- package/dist/units/diagram/emphasis.js +1 -0
- package/dist/units/diagram/er.js +9 -0
- package/dist/units/diagram/eventmodeling.js +5 -0
- package/dist/units/diagram/gantt-date.js +1 -0
- package/dist/units/diagram/gantt.js +3 -0
- package/dist/units/diagram/gitgraph.js +2 -0
- package/dist/units/diagram/graph-layout.js +4 -0
- package/dist/units/diagram/graph-parse.js +9 -0
- package/dist/units/diagram/graph-route.js +1 -0
- package/dist/units/diagram/graph.js +1 -0
- package/dist/units/diagram/ishikawa.js +2 -0
- package/dist/units/diagram/journey.js +5 -0
- package/dist/units/diagram/kanban.js +2 -0
- package/dist/units/diagram/label.js +4 -0
- package/dist/units/diagram/layers.js +1 -0
- package/dist/units/diagram/map-label.js +1 -0
- package/dist/units/diagram/mindmap.js +2 -0
- package/dist/units/diagram/numeric-composition.js +1 -0
- package/dist/units/diagram/numeric-model.js +1 -0
- package/dist/units/diagram/numeric-parse.js +2 -0
- package/dist/units/diagram/numeric-radar.js +3 -0
- package/dist/units/diagram/numeric-sankey.js +2 -0
- package/dist/units/diagram/numeric-xy.js +2 -0
- package/dist/units/diagram/packet.js +2 -0
- package/dist/units/diagram/presentation.js +2 -0
- package/dist/units/diagram/quadrant.js +2 -0
- package/dist/units/diagram/railroad-parse.js +4 -0
- package/dist/units/diagram/railroad.js +1 -0
- package/dist/units/diagram/registry.js +2 -0
- package/dist/units/diagram/relations.js +3 -0
- package/dist/units/diagram/requirement.js +3 -0
- package/dist/units/diagram/sequence.js +2 -0
- package/dist/units/diagram/shapes.js +60 -0
- package/dist/units/diagram/source.js +20 -0
- package/dist/units/diagram/support.js +3 -0
- package/dist/units/diagram/swimlane-mermaid.js +3 -0
- package/dist/units/diagram/swimlane.js +2 -0
- package/dist/units/diagram/time.js +3 -0
- package/dist/units/diagram/timeline.js +2 -0
- package/dist/units/diagram/tree-family-icon.js +1 -0
- package/dist/units/diagram/treeview.js +2 -0
- package/dist/units/diagram/usecase.js +3 -0
- package/dist/units/diagram/venn.js +2 -0
- package/dist/units/diagram/wardley.js +4 -0
- package/dist/units/interaction.js +1 -0
- package/dist/units/runtime.js +1 -0
- package/dist/units.json +712 -0
- package/package.json +30 -4
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { resolveIconRef } from "../core/icons.js";
|
|
3
|
+
import { FONT, appearance, error, isEn, warning } from "./support.js";
|
|
4
|
+
import { normalizeLabel } from "./label.js";
|
|
5
|
+
import { presentation } from "./presentation.js";
|
|
6
|
+
// src/diagram/journey.js
|
|
7
|
+
var journey_exports = /* @__PURE__ */ __exportAll({ implementations: () => implementations });
|
|
8
|
+
var TASK_ADVISORY = 60;
|
|
9
|
+
var TASK_CAP = 2e3;
|
|
10
|
+
var honoredConfig = ["journey"];
|
|
11
|
+
var HONORED = /* @__PURE__ */ new Map([
|
|
12
|
+
["taskfontsize", "taskFontSize"],
|
|
13
|
+
["maxlabelwidth", "maxLabelWidth"],
|
|
14
|
+
["titlefontsize", "titleFontSize"],
|
|
15
|
+
["leftmargin", "leftMargin"]
|
|
16
|
+
]);
|
|
17
|
+
var COLOR_KEYS = /* @__PURE__ */ new Set([
|
|
18
|
+
"actorcolours",
|
|
19
|
+
"sectionfills",
|
|
20
|
+
"sectioncolours",
|
|
21
|
+
"titlecolor"
|
|
22
|
+
]);
|
|
23
|
+
var configKey = (value) => String(value).toLowerCase().replace(/[-_]/g, "");
|
|
24
|
+
var FACE_R = 9;
|
|
25
|
+
var ICON_SIZE = 14;
|
|
26
|
+
var MAX_SCORE = 5;
|
|
27
|
+
var LAYOUT = {
|
|
28
|
+
labelX: 12,
|
|
29
|
+
labelPad: 12,
|
|
30
|
+
plotGap: 6,
|
|
31
|
+
right: 16,
|
|
32
|
+
band: 10,
|
|
33
|
+
bottom: 16,
|
|
34
|
+
row: 48,
|
|
35
|
+
chipR: 4,
|
|
36
|
+
chipGap: 6
|
|
37
|
+
};
|
|
38
|
+
LAYOUT.chip = LAYOUT.chipR * 2 + LAYOUT.chipGap;
|
|
39
|
+
var issue = (lang, line, zh, en, fixZh, fixEn) => error(lang, line, zh, en, fixZh, fixEn);
|
|
40
|
+
var pixels = (value, fallback, min, max) => {
|
|
41
|
+
if (value == null || value === "") return fallback;
|
|
42
|
+
if (typeof value === "number") return Number.isFinite(value) ? Math.min(max, Math.max(min, value)) : fallback;
|
|
43
|
+
const match = /^([+-]?\d*\.?\d+)\s*(px|pt|ex|em|rem)?$/i.exec(String(value).trim());
|
|
44
|
+
if (!match) return fallback;
|
|
45
|
+
const factor = {
|
|
46
|
+
px: 1,
|
|
47
|
+
pt: 4 / 3,
|
|
48
|
+
ex: 4,
|
|
49
|
+
em: 12,
|
|
50
|
+
rem: 12
|
|
51
|
+
}[(match[2] || "px").toLowerCase()];
|
|
52
|
+
return Math.min(max, Math.max(min, Number(match[1]) * factor));
|
|
53
|
+
};
|
|
54
|
+
function uncomment(value) {
|
|
55
|
+
let quote = "";
|
|
56
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
57
|
+
const ch = value[i];
|
|
58
|
+
if (quote) {
|
|
59
|
+
if (ch === quote) quote = "";
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (ch === "\"" || ch === "'") {
|
|
63
|
+
quote = ch;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (ch === "%" && value[i + 1] === "%") return value.slice(0, i).trimEnd();
|
|
67
|
+
if (ch === "#" && !/^#[\w]+;/.test(value.slice(i))) return value.slice(0, i).trimEnd();
|
|
68
|
+
}
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
var hasStraySemicolon = (value) => value.replace(/(?:&#?|#)[\w]+;/g, "").includes(";");
|
|
72
|
+
function readConfig(info, lang, line, errors) {
|
|
73
|
+
const source = info?.config?.journey;
|
|
74
|
+
const settings = {};
|
|
75
|
+
if (!source || typeof source !== "object" || Array.isArray(source)) return settings;
|
|
76
|
+
const colors = [], ignored = [];
|
|
77
|
+
for (const [key, value] of Object.entries(source)) {
|
|
78
|
+
const name = configKey(key);
|
|
79
|
+
if (HONORED.has(name)) {
|
|
80
|
+
settings[HONORED.get(name)] = value;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (COLOR_KEYS.has(name)) colors.push(key);
|
|
84
|
+
else ignored.push(key);
|
|
85
|
+
}
|
|
86
|
+
if (colors.length) errors.push(warning("IGNORED_STYLE", lang, line, `旅程图颜色由主题决定,已忽略配置:${colors.join(", ")}`, `Journey colors come from the theme; ignored: ${colors.join(", ")}`, "改用主题调色板", "Use the theme palette"));
|
|
87
|
+
if (ignored.length) errors.push(warning("IGNORED_CONFIG", lang, line, `旅程图不支持这些配置,已忽略:${ignored.join(", ")}`, `Ignored journey config: ${ignored.join(", ")}`, "移除这些配置项", "Remove these config keys"));
|
|
88
|
+
return settings;
|
|
89
|
+
}
|
|
90
|
+
function parse(body, info = {}) {
|
|
91
|
+
const lang = info.lang || "zh";
|
|
92
|
+
const firstLine = Number.isInteger(info.firstLine) ? info.firstLine : 2;
|
|
93
|
+
const errors = [];
|
|
94
|
+
if (body.length > 2e5) return {
|
|
95
|
+
model: null,
|
|
96
|
+
errors: [issue(lang, firstLine, "旅程图源码超过 200000 字符", "Journey source exceeds 200,000 characters", "拆分旅程图", "Split the journey")]
|
|
97
|
+
};
|
|
98
|
+
const raw = readConfig(info, lang, info.headerLine || Math.max(1, firstLine - 1), errors);
|
|
99
|
+
const config = {
|
|
100
|
+
taskFontSize: pixels(raw.taskFontSize, FONT.body.size, 12, 20),
|
|
101
|
+
maxLabelWidth: pixels(raw.maxLabelWidth, 360, 120, 640),
|
|
102
|
+
titleFontSize: pixels(raw.titleFontSize, FONT.title.size, 12, 28),
|
|
103
|
+
leftMargin: pixels(raw.leftMargin, 0, 0, 480)
|
|
104
|
+
};
|
|
105
|
+
const tasks = [], sections = [{
|
|
106
|
+
name: "",
|
|
107
|
+
tasks: []
|
|
108
|
+
}];
|
|
109
|
+
const look = presentation({ lang });
|
|
110
|
+
const assetWarnings = /* @__PURE__ */ new Set();
|
|
111
|
+
const addAssetWarnings = (diagnostics) => diagnostics.forEach((diagnostic) => {
|
|
112
|
+
if (diagnostic.code !== "IGNORED_ASSET" || !assetWarnings.has(diagnostic.message)) {
|
|
113
|
+
errors.push(diagnostic);
|
|
114
|
+
if (diagnostic.code === "IGNORED_ASSET") assetWarnings.add(diagnostic.message);
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
const cleanLabel = (raw, line) => {
|
|
118
|
+
let explicit;
|
|
119
|
+
const consume = (ref) => {
|
|
120
|
+
explicit ??= ref;
|
|
121
|
+
return "";
|
|
122
|
+
};
|
|
123
|
+
const source = raw.replace(/::icon\(([^)]+)\)/gi, (_, ref) => consume(ref.trim())).replace(/(?<![\w:/.-])(?:logos|mdi|tabler|simple-icons):[a-z\d-]+/gi, consume);
|
|
124
|
+
const result = normalizeLabel(source, {
|
|
125
|
+
lang,
|
|
126
|
+
line
|
|
127
|
+
});
|
|
128
|
+
addAssetWarnings(result.diagnostics);
|
|
129
|
+
return {
|
|
130
|
+
text: result.text,
|
|
131
|
+
icon: (explicit ? explicitIcon(explicit, line) : null) || result.icon
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
const explicitIcon = (ref, line) => {
|
|
135
|
+
const icon = resolveIconRef(ref);
|
|
136
|
+
if (!icon) addAssetWarnings([warning("IGNORED_ASSET", lang, line, `未知图标 ${ref}`, `Unknown icon ${ref}`, "使用内置图标", "Use a built-in icon")]);
|
|
137
|
+
return icon;
|
|
138
|
+
};
|
|
139
|
+
let title = info.title || "", titleLine = info.headerLine || Math.max(1, firstLine - 1), decimalWarned = false, overflow = false;
|
|
140
|
+
const ignoredOptions = Object.keys(info.options || {});
|
|
141
|
+
if (ignoredOptions.length) errors.push(warning("IGNORED_CONFIG", lang, info.headerLine || Math.max(1, firstLine - 1), `旅程图标题行不接受选项,已忽略:${ignoredOptions.join(", ")}`, `Journey header options are ignored: ${ignoredOptions.join(", ")}`, "只保留 journey 关键字", "Keep only the journey keyword"));
|
|
142
|
+
const lines = String(body ?? "").replace(/\r\n?/g, "\n").split("\n");
|
|
143
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
144
|
+
const line = firstLine + index;
|
|
145
|
+
const raw = lines[index].trim();
|
|
146
|
+
if (look.accept(raw, line)) continue;
|
|
147
|
+
const text = uncomment(raw).trim();
|
|
148
|
+
if (!text || text.startsWith("%%")) continue;
|
|
149
|
+
if (hasStraySemicolon(text)) {
|
|
150
|
+
errors.push(issue(lang, line, "分号不能用于分隔旅程图语句", "Semicolons cannot separate journey statements", "每行只写一条语句", "Write one statement per line"));
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
let match;
|
|
154
|
+
if (match = /^title(?:\s*:|\s+)(.*)$/i.exec(text)) {
|
|
155
|
+
title = match[1].trim();
|
|
156
|
+
titleLine = line;
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (/^title$/i.test(text)) continue;
|
|
160
|
+
if (/^section\b/i.test(text)) {
|
|
161
|
+
const name = /^section\s+(.+)$/i.exec(text);
|
|
162
|
+
if (!name || !name[1].trim()) {
|
|
163
|
+
errors.push(issue(lang, line, "分组名不能为空", "A section name must be non-empty", "写成「section 名称」", "Write \"section name\""));
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
const section = cleanLabel(name[1].trim(), line);
|
|
167
|
+
sections.push({
|
|
168
|
+
name: section.text,
|
|
169
|
+
icon: section.icon,
|
|
170
|
+
tasks: [],
|
|
171
|
+
line
|
|
172
|
+
});
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const names = [];
|
|
176
|
+
const statement = text.replace(/:::([\w-]+)/g, (_, name) => {
|
|
177
|
+
names.push(name);
|
|
178
|
+
return "";
|
|
179
|
+
});
|
|
180
|
+
const colon = [...statement.matchAll(/::icon\([^)]+\)|(?<![\w:/.-])(?:fa[bsrlk]?|logos|mdi|tabler|simple-icons):[a-z\d-]+|(:)/gi)].find((match) => match[1])?.index;
|
|
181
|
+
const name = colon == null ? "" : statement.slice(0, colon).trim();
|
|
182
|
+
if (!name) {
|
|
183
|
+
errors.push(issue(lang, line, "旅程任务需要写成「任务名: 评分: 参与者」", "A journey task reads \"task name: score: actors\"", "在冒号前写任务名", "Write the task name before the colon"));
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
const [, scoreText, cast = ""] = /^\s*([^:]*?)(?:\s*:\s*(.*))?$/.exec(statement.slice(colon + 1));
|
|
187
|
+
const score = scoreText.trim() ? Number(scoreText) : NaN;
|
|
188
|
+
const actorLabels = cast.split(",").map((actor) => cleanLabel(actor.trim(), line));
|
|
189
|
+
const actors = [...new Set(actorLabels.map((actor) => actor.text).filter(Boolean))];
|
|
190
|
+
if (!Number.isFinite(score)) {
|
|
191
|
+
errors.push(issue(lang, line, `评分「${scoreText}」不是数字`, `Score "${scoreText}" is not a number`, "用 1–5 的整数评分", "Use a whole score from 1 to 5"));
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (score < 1 || score > 5) {
|
|
195
|
+
errors.push(issue(lang, line, `评分 ${score} 超出 1–5 的范围`, `Score ${score} is outside 1–5`, "把评分改为 1 到 5", "Use a score from 1 to 5"));
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (!Number.isInteger(score) && !decimalWarned) {
|
|
199
|
+
decimalWarned = true;
|
|
200
|
+
errors.push(warning("DIAGRAM_HINT", lang, line, `评分 ${score} 不是整数,已按原值绘制`, `Score ${score} is not whole; drawn as written`, "使用 1–5 的整数评分", "Use whole scores from 1 to 5"));
|
|
201
|
+
}
|
|
202
|
+
if (tasks.length >= TASK_CAP) {
|
|
203
|
+
if (!overflow) {
|
|
204
|
+
overflow = true;
|
|
205
|
+
errors.push(issue(lang, line, `旅程图最多 ${TASK_CAP} 个任务`, `A journey can contain at most ${TASK_CAP} tasks`, "把旅程拆成两张图", "Split the journey into two diagrams"));
|
|
206
|
+
}
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
const label = cleanLabel(name, line);
|
|
210
|
+
const id = `task:${tasks.length}`;
|
|
211
|
+
if (names.length) look.addClasses(id, names, line);
|
|
212
|
+
const task = {
|
|
213
|
+
id,
|
|
214
|
+
name: label.text,
|
|
215
|
+
icon: label.icon,
|
|
216
|
+
score,
|
|
217
|
+
actors,
|
|
218
|
+
actorLabels,
|
|
219
|
+
line
|
|
220
|
+
};
|
|
221
|
+
tasks.push(task);
|
|
222
|
+
sections.at(-1).tasks.push(task);
|
|
223
|
+
}
|
|
224
|
+
const normalizedTitle = cleanLabel(title, titleLine);
|
|
225
|
+
title = normalizedTitle.text;
|
|
226
|
+
info.title = title;
|
|
227
|
+
if (!tasks.length && !errors.some((item) => item.severity !== "warning")) errors.push(issue(lang, firstLine, "旅程图中没有任务", "Journey has no tasks", "添加「任务名: 评分: 参与者」", "Add \"task name: score: actors\""));
|
|
228
|
+
const actors = [...new Set(tasks.flatMap((task) => task.actors))];
|
|
229
|
+
const actorIcons = /* @__PURE__ */ new Map(), actorLinks = /* @__PURE__ */ new Map();
|
|
230
|
+
for (const task of tasks) for (const actor of task.actorLabels) if (actor.text) {
|
|
231
|
+
if (actor.icon && !actorIcons.has(actor.text)) actorIcons.set(actor.text, actor.icon);
|
|
232
|
+
if (!actorLinks.has(actor.text)) actorLinks.set(actor.text, look.linkOf(actor.text));
|
|
233
|
+
}
|
|
234
|
+
for (const task of tasks) {
|
|
235
|
+
task.status = look.statusOf(task.id);
|
|
236
|
+
task.link = look.linkOf(task.id);
|
|
237
|
+
}
|
|
238
|
+
for (const section of sections) {
|
|
239
|
+
section.status = look.statusOf(section.name);
|
|
240
|
+
section.link = look.linkOf(section.name);
|
|
241
|
+
}
|
|
242
|
+
errors.push(...look.diagnostics());
|
|
243
|
+
return {
|
|
244
|
+
model: {
|
|
245
|
+
type: "journey",
|
|
246
|
+
title,
|
|
247
|
+
titleIcon: normalizedTitle.icon,
|
|
248
|
+
titleLink: look.linkOf(title),
|
|
249
|
+
tasks,
|
|
250
|
+
sections,
|
|
251
|
+
actors,
|
|
252
|
+
actorIcons: Object.fromEntries(actorIcons),
|
|
253
|
+
actorLinks: Object.fromEntries(actorLinks),
|
|
254
|
+
actorStatuses: Object.fromEntries(actors.map((actor) => [actor, look.statusOf(actor)])),
|
|
255
|
+
config
|
|
256
|
+
},
|
|
257
|
+
errors
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function drawIcon(ctx, icon, x, y, size = ICON_SIZE, color = ctx.color("fg")) {
|
|
261
|
+
if (!icon) return null;
|
|
262
|
+
const [vx, vy, w, h] = icon.viewBox.split(/\s+/).map(Number), scale = size / Math.max(w, h);
|
|
263
|
+
const stroke = icon.set === "tabler";
|
|
264
|
+
return ctx.el("g", {
|
|
265
|
+
transform: `translate(${x + (size - w * scale) / 2} ${y + (size - h * scale) / 2}) scale(${scale}) translate(${-vx} ${-vy})`,
|
|
266
|
+
fill: stroke ? "none" : color,
|
|
267
|
+
stroke: stroke ? color : "none",
|
|
268
|
+
"stroke-width": 1.8,
|
|
269
|
+
"stroke-linecap": "round",
|
|
270
|
+
"stroke-linejoin": "round"
|
|
271
|
+
}, icon.elements.map(({ tag, attrs }) => ctx.shape(tag, attrs)));
|
|
272
|
+
}
|
|
273
|
+
function layout(model, options = {}) {
|
|
274
|
+
const { width = 800, ctx, renderOptions = {} } = options;
|
|
275
|
+
if (!ctx) throw new TypeError("journey layout needs a theme context");
|
|
276
|
+
const look = appearance(ctx);
|
|
277
|
+
const measure = options.measure || ((value, font) => ctx.measure(value, font.size, font.weight));
|
|
278
|
+
const paper = ctx.color("bg"), accent = ctx.color("accent"), grid = ctx.color("grid");
|
|
279
|
+
const ink = ctx.color("fg"), muted = ctx.color("muted");
|
|
280
|
+
const config = model.config || {};
|
|
281
|
+
const bodyFont = {
|
|
282
|
+
size: config.taskFontSize || FONT.body.size,
|
|
283
|
+
weight: FONT.body.weight
|
|
284
|
+
};
|
|
285
|
+
const labelFont = {
|
|
286
|
+
size: FONT.label.size,
|
|
287
|
+
weight: FONT.label.weight
|
|
288
|
+
};
|
|
289
|
+
const scoreCaption = isEn(ctx.lang) ? "Score" : "评分";
|
|
290
|
+
const titleSize = config.titleFontSize || FONT.title.size;
|
|
291
|
+
const maxLabelWidth = config.maxLabelWidth || 360;
|
|
292
|
+
const { tasks, actors } = model, groups = model.sections.filter((g) => g.name || g.icon || g.tasks.length);
|
|
293
|
+
const actorIndex = new Map(actors.map((actor, index) => [actor, index]));
|
|
294
|
+
const linked = (link, children) => link ? [ctx.link(link.href, children, link)] : children;
|
|
295
|
+
const iconSlot = (icon) => icon ? 18 : 0;
|
|
296
|
+
const children = [], errors = [];
|
|
297
|
+
const font = (size, weight) => ({
|
|
298
|
+
size,
|
|
299
|
+
weight
|
|
300
|
+
});
|
|
301
|
+
const widthOf = (value, style) => measure(value, style);
|
|
302
|
+
const toneOf = (name) => {
|
|
303
|
+
const index = actorIndex.get(name);
|
|
304
|
+
const status = model.actorStatuses?.[name];
|
|
305
|
+
return ctx.tint(paper, status ? ctx.design[status] : ctx.color(`tone${index % 6 + 1}`), .8);
|
|
306
|
+
};
|
|
307
|
+
const names = new Map(tasks.map((task) => [task, ctx.wrap(task.name, Math.max(40, maxLabelWidth - iconSlot(task.icon)), bodyFont.size, bodyFont.weight)]));
|
|
308
|
+
const chipsOf = (task) => task.actors.length ? (task.actors.length - 1) * LAYOUT.chip + LAYOUT.chipR * 2 : 0;
|
|
309
|
+
const labelWidth = Math.max(0, ...tasks.map((task) => iconSlot(task.icon) + Math.max(0, ...names.get(task).map((line) => widthOf(line, bodyFont))) + (task.actors.length ? 10 + chipsOf(task) : 0)));
|
|
310
|
+
const sectionFont = font(FONT.body.size, 600);
|
|
311
|
+
const sectionWidth = Math.max(0, ...groups.flatMap((group) => group.name.split("\n").map((line, index) => widthOf(line, sectionFont) + (index === 0 ? iconSlot(group.icon) : 0))));
|
|
312
|
+
const pitch = bodyFont.size + 5;
|
|
313
|
+
const left = Math.max(config.leftMargin || 0, LAYOUT.labelX + Math.max(labelWidth, sectionWidth, widthOf(scoreCaption, labelFont)) + LAYOUT.labelPad + FACE_R + LAYOUT.plotGap);
|
|
314
|
+
const plotW = Math.max(140, width - left - LAYOUT.right);
|
|
315
|
+
const x0 = left, x1 = left + plotW, step = plotW / 4;
|
|
316
|
+
const sceneWidth = Math.ceil(Math.max(width, x1 + LAYOUT.right));
|
|
317
|
+
const inSceneTitle = Boolean(model.title) && !renderOptions?.frame;
|
|
318
|
+
if (inSceneTitle) {
|
|
319
|
+
const titleText = ctx.text(LAYOUT.labelX + iconSlot(model.titleIcon), titleSize + 12, model.title, {
|
|
320
|
+
size: titleSize,
|
|
321
|
+
weight: 600,
|
|
322
|
+
fill: ink
|
|
323
|
+
});
|
|
324
|
+
const titleParts = [...model.titleIcon ? [drawIcon(ctx, model.titleIcon, LAYOUT.labelX, titleSize + 12 - ICON_SIZE / 2)] : [], titleText];
|
|
325
|
+
children.push(...linked(model.titleLink, [ctx.el("g", {}, titleParts)]));
|
|
326
|
+
}
|
|
327
|
+
let cursor = inSceneTitle ? 12 + titleSize + 18 : 16;
|
|
328
|
+
const legendWidth = Math.max(120, x1 - LAYOUT.labelX);
|
|
329
|
+
const legendRows = [];
|
|
330
|
+
let row = [], used = 0, rowHeight = 0;
|
|
331
|
+
for (const name of actors) {
|
|
332
|
+
const lines = ctx.wrap(name, Math.max(40, legendWidth - 13 - iconSlot(model.actorIcons?.[name])), labelFont.size, labelFont.weight);
|
|
333
|
+
const itemWidth = 13 + iconSlot(model.actorIcons?.[name]) + Math.max(0, ...lines.map((line) => widthOf(line, labelFont)));
|
|
334
|
+
if (row.length && used + itemWidth > legendWidth) {
|
|
335
|
+
legendRows.push({
|
|
336
|
+
items: row,
|
|
337
|
+
height: rowHeight
|
|
338
|
+
});
|
|
339
|
+
row = [];
|
|
340
|
+
used = 0;
|
|
341
|
+
rowHeight = 0;
|
|
342
|
+
}
|
|
343
|
+
row.push({
|
|
344
|
+
name,
|
|
345
|
+
lines,
|
|
346
|
+
width: itemWidth
|
|
347
|
+
});
|
|
348
|
+
used += itemWidth + 14;
|
|
349
|
+
rowHeight = Math.max(rowHeight, lines.length * 15);
|
|
350
|
+
}
|
|
351
|
+
if (row.length) legendRows.push({
|
|
352
|
+
items: row,
|
|
353
|
+
height: rowHeight
|
|
354
|
+
});
|
|
355
|
+
for (const legend of legendRows) {
|
|
356
|
+
let x = LAYOUT.labelX;
|
|
357
|
+
for (const item of legend.items) {
|
|
358
|
+
const icon = model.actorIcons?.[item.name], slot = iconSlot(icon);
|
|
359
|
+
const marker = ctx.titled(ctx.circle(x + LAYOUT.chipR, cursor + 8, LAYOUT.chipR, {
|
|
360
|
+
fill: toneOf(item.name),
|
|
361
|
+
stroke: paper,
|
|
362
|
+
"stroke-width": 1
|
|
363
|
+
}), item.name);
|
|
364
|
+
children.push(...linked(model.actorLinks?.[item.name], [marker]));
|
|
365
|
+
if (icon) children.push(drawIcon(ctx, icon, x + 13, cursor + 1));
|
|
366
|
+
item.lines.forEach((text, i) => children.push(...linked(model.actorLinks?.[item.name], [ctx.text(x + 13 + slot, cursor + 8 + i * 15, text, {
|
|
367
|
+
...labelFont,
|
|
368
|
+
fill: muted,
|
|
369
|
+
"dominant-baseline": "middle"
|
|
370
|
+
})])));
|
|
371
|
+
x += item.width + slot + 14;
|
|
372
|
+
}
|
|
373
|
+
cursor += legend.height + (legendRows.length > 1 ? 4 : 0);
|
|
374
|
+
}
|
|
375
|
+
if (legendRows.length) cursor += 10;
|
|
376
|
+
const scaleY = cursor + 8;
|
|
377
|
+
children.push(ctx.text(LAYOUT.labelX, scaleY, scoreCaption, {
|
|
378
|
+
...labelFont,
|
|
379
|
+
fill: muted,
|
|
380
|
+
"dominant-baseline": "middle"
|
|
381
|
+
}));
|
|
382
|
+
for (let score = 1; score <= MAX_SCORE; score += 1) children.push(ctx.text(x0 + (score - 1) * step, scaleY, String(score), {
|
|
383
|
+
...labelFont,
|
|
384
|
+
fill: muted,
|
|
385
|
+
anchor: "middle",
|
|
386
|
+
"dominant-baseline": "middle"
|
|
387
|
+
}));
|
|
388
|
+
cursor = scaleY + 14;
|
|
389
|
+
const bands = [];
|
|
390
|
+
for (const [index, group] of groups.entries()) {
|
|
391
|
+
const sectionLines = group.name || group.icon ? group.name.split("\n") : [];
|
|
392
|
+
const bandY = cursor;
|
|
393
|
+
let y = bandY + (sectionLines.length ? 10 + 18 * sectionLines.length : 0);
|
|
394
|
+
const rows = group.tasks.map((task) => {
|
|
395
|
+
const lines = names.get(task);
|
|
396
|
+
const height = Math.max(LAYOUT.row, lines.length * pitch + 24);
|
|
397
|
+
const entry = {
|
|
398
|
+
task,
|
|
399
|
+
lines,
|
|
400
|
+
y,
|
|
401
|
+
height,
|
|
402
|
+
mid: y + height / 2
|
|
403
|
+
};
|
|
404
|
+
y += height;
|
|
405
|
+
return entry;
|
|
406
|
+
});
|
|
407
|
+
bands.push({
|
|
408
|
+
group,
|
|
409
|
+
index,
|
|
410
|
+
y: bandY,
|
|
411
|
+
height: y - bandY,
|
|
412
|
+
sectionLines,
|
|
413
|
+
rows
|
|
414
|
+
});
|
|
415
|
+
cursor = y + LAYOUT.band;
|
|
416
|
+
}
|
|
417
|
+
const contentBottom = bands.length ? cursor - LAYOUT.band : cursor;
|
|
418
|
+
for (const band of bands) {
|
|
419
|
+
if (!band.group.name) continue;
|
|
420
|
+
const sectionTone = band.group.status ? ctx.design[band.group.status] : ctx.color(`tone${band.index % 6 + 1}`);
|
|
421
|
+
children.push(ctx.rect(8, band.y, x1 + LAYOUT.labelPad - 8, band.height, {
|
|
422
|
+
rx: look.radius,
|
|
423
|
+
fill: ctx.tint(paper, sectionTone, .06),
|
|
424
|
+
meta: {
|
|
425
|
+
kind: "frame",
|
|
426
|
+
id: `section:${band.index}`,
|
|
427
|
+
...band.group.status ? { status: band.group.status } : {}
|
|
428
|
+
}
|
|
429
|
+
}));
|
|
430
|
+
}
|
|
431
|
+
for (const band of bands) {
|
|
432
|
+
band.sectionLines.forEach((line, i) => {
|
|
433
|
+
const iconSlotWidth = i === 0 ? iconSlot(band.group.icon) : 0;
|
|
434
|
+
const text = ctx.text(LAYOUT.labelX + iconSlotWidth, band.y + 15 + i * 18, line, {
|
|
435
|
+
...sectionFont,
|
|
436
|
+
fill: muted,
|
|
437
|
+
"dominant-baseline": "middle"
|
|
438
|
+
});
|
|
439
|
+
const parts = [...i === 0 && band.group.icon ? [drawIcon(ctx, band.group.icon, LAYOUT.labelX, band.y + 8)] : [], text];
|
|
440
|
+
children.push(...linked(band.group.link, parts));
|
|
441
|
+
});
|
|
442
|
+
for (const { task, lines, mid } of band.rows) {
|
|
443
|
+
const taskIconSlot = iconSlot(task.icon);
|
|
444
|
+
if (task.icon) children.push(drawIcon(ctx, task.icon, LAYOUT.labelX, mid - ICON_SIZE / 2));
|
|
445
|
+
lines.forEach((text, i) => children.push(...linked(task.link, [ctx.text(LAYOUT.labelX + taskIconSlot, mid + (i - (lines.length - 1) / 2) * pitch, text, {
|
|
446
|
+
...bodyFont,
|
|
447
|
+
fill: ink,
|
|
448
|
+
"dominant-baseline": "middle"
|
|
449
|
+
})])));
|
|
450
|
+
if (task.actors.length) {
|
|
451
|
+
const start = LAYOUT.labelX + taskIconSlot + Math.max(0, ...lines.map((line) => widthOf(line, bodyFont))) + 10 + LAYOUT.chipR;
|
|
452
|
+
task.actors.forEach((name, i) => {
|
|
453
|
+
const marker = ctx.titled(ctx.circle(start + i * LAYOUT.chip, mid, LAYOUT.chipR, {
|
|
454
|
+
fill: toneOf(name),
|
|
455
|
+
stroke: paper,
|
|
456
|
+
"stroke-width": 1
|
|
457
|
+
}), name);
|
|
458
|
+
children.push(...linked(model.actorLinks?.[name], [marker]));
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
children.push(ctx.line(x0, mid, x1, mid, {
|
|
462
|
+
stroke: grid,
|
|
463
|
+
"stroke-width": 1
|
|
464
|
+
}));
|
|
465
|
+
const faceX = x0 + (task.score - 1) * step;
|
|
466
|
+
const taskTone = task.status ? ctx.design[task.status] : accent;
|
|
467
|
+
const face = ctx.circle(faceX, mid, FACE_R, {
|
|
468
|
+
fill: ctx.tint(paper, taskTone, .06),
|
|
469
|
+
stroke: taskTone,
|
|
470
|
+
"stroke-width": 1.4,
|
|
471
|
+
role: "img",
|
|
472
|
+
"aria-label": `${task.name}: ${scoreCaption} ${task.score}/${MAX_SCORE}`,
|
|
473
|
+
meta: {
|
|
474
|
+
kind: "node",
|
|
475
|
+
id: task.id,
|
|
476
|
+
...task.status ? { status: task.status } : {}
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
children.push(...linked(task.link, [face]));
|
|
480
|
+
for (const eye of [-3, 3]) children.push(ctx.circle(faceX + eye, mid - 2.5, 1.2, { fill: muted }));
|
|
481
|
+
const mouth = task.score > 3 ? `M${faceX - 4} ${mid + 2} Q${faceX} ${mid + 7} ${faceX + 4} ${mid + 2}` : task.score < 3 ? `M${faceX - 4} ${mid + 5.5} Q${faceX} ${mid + .5} ${faceX + 4} ${mid + 5.5}` : `M${faceX - 4} ${mid + 3.5} L${faceX + 4} ${mid + 3.5}`;
|
|
482
|
+
children.push(ctx.path(mouth, {
|
|
483
|
+
fill: "none",
|
|
484
|
+
stroke: accent,
|
|
485
|
+
"stroke-width": 1.4,
|
|
486
|
+
"stroke-linecap": "round"
|
|
487
|
+
}));
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
const height = Math.ceil(Math.max(160, contentBottom + LAYOUT.bottom));
|
|
491
|
+
if (tasks.length > TASK_ADVISORY) errors.push(warning("LARGE_DIAGRAM", options.lang || ctx.lang || "zh", tasks[TASK_ADVISORY].line, `旅程图有 ${tasks.length} 个任务,建议拆分`, `The journey has ${tasks.length} tasks; consider splitting it`, "按阶段拆成两张旅程图", "Split the journey by stage"));
|
|
492
|
+
else if (sceneWidth > width * 2) errors.push(warning("LARGE_DIAGRAM", options.lang || ctx.lang || "zh", 1, "旅程图比给定宽度宽很多", "The journey is much wider than the requested width", "缩小任务名或拆分旅程图", "Shorten task names or split the journey"));
|
|
493
|
+
return {
|
|
494
|
+
width: sceneWidth,
|
|
495
|
+
height,
|
|
496
|
+
scene: {
|
|
497
|
+
width: sceneWidth,
|
|
498
|
+
height,
|
|
499
|
+
children,
|
|
500
|
+
...model.title ? { title: model.title } : {},
|
|
501
|
+
...renderOptions?.frame && model.title ? { heading: model.title } : {}
|
|
502
|
+
},
|
|
503
|
+
errors
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
var implementations = { journey: {
|
|
507
|
+
parse,
|
|
508
|
+
layout,
|
|
509
|
+
honoredConfig,
|
|
510
|
+
acceptsPresentation: true
|
|
511
|
+
} };
|
|
512
|
+
export { implementations, journey_exports };
|