@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,376 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { resolveIconRef } from "../core/icons.js";
|
|
3
|
+
import { normalizeLabel } from "./label.js";
|
|
4
|
+
import { presentation } from "./presentation.js";
|
|
5
|
+
import { FONT, error, warning, wrapText } from "./support.js";
|
|
6
|
+
// src/diagram/timeline.js
|
|
7
|
+
var timeline_exports = /* @__PURE__ */ __exportAll({ implementations: () => implementations });
|
|
8
|
+
function parse(body, info) {
|
|
9
|
+
const { lang, firstLine = 2 } = info, errors = [], items = [], sections = [{
|
|
10
|
+
name: "",
|
|
11
|
+
items: []
|
|
12
|
+
}];
|
|
13
|
+
const look = presentation({ lang }), assets = /* @__PURE__ */ new Set();
|
|
14
|
+
const direction = (info.params?.trim() || "LR").toUpperCase();
|
|
15
|
+
const issue = (line, zh, en) => errors.push(error(lang, line, zh, en, "使用 timeline [LR|TD] 和「时段 : 事件」", "Use timeline [LR|TD] and “period : event”"));
|
|
16
|
+
const noteAsset = (diagnostic) => {
|
|
17
|
+
if (assets.has(diagnostic.message)) return;
|
|
18
|
+
assets.add(diagnostic.message);
|
|
19
|
+
errors.push(diagnostic);
|
|
20
|
+
};
|
|
21
|
+
const label = (raw, id, line) => {
|
|
22
|
+
let source = raw.replace(/:::[\w-]+/g, "").trim(), explicit;
|
|
23
|
+
const iconSuffix = /\s*::icon\(([^)]+)\)\s*$/i.exec(source);
|
|
24
|
+
if (iconSuffix) {
|
|
25
|
+
explicit = iconSuffix[1];
|
|
26
|
+
source = source.slice(0, iconSuffix.index).trimEnd();
|
|
27
|
+
}
|
|
28
|
+
source = source.replace(/(?<![\w:/.-])(?:logos|mdi|tabler|simple-icons):[a-z\d-]+/gi, (ref) => {
|
|
29
|
+
explicit ??= ref;
|
|
30
|
+
return "";
|
|
31
|
+
});
|
|
32
|
+
const normalized = normalizeLabel(source, {
|
|
33
|
+
lang,
|
|
34
|
+
line
|
|
35
|
+
});
|
|
36
|
+
normalized.diagnostics.forEach(noteAsset);
|
|
37
|
+
const resolved = explicit ? resolveIconRef(explicit) : null;
|
|
38
|
+
if (explicit && !resolved) noteAsset(warning("IGNORED_ASSET", lang, line, `未知图标 ${explicit}`, `Unknown icon ${explicit}`, "使用内置图标或注册图标集", "Use a built-in icon or register its icon set"));
|
|
39
|
+
return {
|
|
40
|
+
text: normalized.text,
|
|
41
|
+
icon: normalized.icon ?? resolved,
|
|
42
|
+
id,
|
|
43
|
+
line
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
if (!["LR", "TD"].includes(direction)) issue(info.headerLine, "时间线方向必须是 LR 或 TD", "Timeline direction must be LR or TD");
|
|
47
|
+
let title = {
|
|
48
|
+
text: info.title || "",
|
|
49
|
+
line: info.configLines?.title ?? info.headerLine ?? firstLine
|
|
50
|
+
};
|
|
51
|
+
const model = {
|
|
52
|
+
type: "timeline",
|
|
53
|
+
title: "",
|
|
54
|
+
direction,
|
|
55
|
+
items,
|
|
56
|
+
sections,
|
|
57
|
+
firstLine,
|
|
58
|
+
config: info.config?.timeline || {}
|
|
59
|
+
};
|
|
60
|
+
if (body.length > 2e5) {
|
|
61
|
+
issue(firstLine, "时间线源码超过 200000 字符,请拆分", "Timeline exceeds 200,000 characters; split the diagram");
|
|
62
|
+
return {
|
|
63
|
+
model,
|
|
64
|
+
errors
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
for (const [i, raw] of body.split("\n").entries()) {
|
|
68
|
+
const line = i + firstLine;
|
|
69
|
+
const text = raw.trim();
|
|
70
|
+
if (!text || text.startsWith("#") || text.startsWith("%%")) continue;
|
|
71
|
+
if (look.accept(text, line)) continue;
|
|
72
|
+
const heading = /^(title|section)(?:\s*:\s*|\s+)(.+)$/i.exec(text);
|
|
73
|
+
if (heading) {
|
|
74
|
+
if (heading[1].toLowerCase() === "title") title = {
|
|
75
|
+
text: heading[2],
|
|
76
|
+
line
|
|
77
|
+
};
|
|
78
|
+
else {
|
|
79
|
+
const section = label(heading[2], null, line);
|
|
80
|
+
sections.push({
|
|
81
|
+
name: section.text,
|
|
82
|
+
icon: section.icon,
|
|
83
|
+
items: []
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const parts = text.split(/\s*:(?=\s|$)/);
|
|
89
|
+
const periodRaw = parts.shift();
|
|
90
|
+
if (periodRaw.trim()) {
|
|
91
|
+
const id = `period:${items.length}`;
|
|
92
|
+
const period = label(periodRaw, id, line);
|
|
93
|
+
period.events = [];
|
|
94
|
+
period.eventDetails = [];
|
|
95
|
+
itemClasses(periodRaw, id, line);
|
|
96
|
+
period.index = items.length;
|
|
97
|
+
items.push(period);
|
|
98
|
+
sections.at(-1).items.push(period);
|
|
99
|
+
}
|
|
100
|
+
if (!items.length) issue(line, "事件前必须先声明时段", "Declare a period before its events");
|
|
101
|
+
else {
|
|
102
|
+
const item = items.at(-1);
|
|
103
|
+
for (const rawEvent of parts) {
|
|
104
|
+
const eventRaw = rawEvent.trim();
|
|
105
|
+
if (!eventRaw) continue;
|
|
106
|
+
const id = `${item.id}:event:${item.events.length}`;
|
|
107
|
+
const event = label(eventRaw, id, line);
|
|
108
|
+
itemClasses(eventRaw, id, line);
|
|
109
|
+
item.events.push(event.text);
|
|
110
|
+
item.eventDetails.push(event);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function itemClasses(raw, id, line) {
|
|
115
|
+
const classes = [...raw.matchAll(/:::([\w-]+)/g)].map((match) => match[1]);
|
|
116
|
+
if (classes.length) look.addClasses(id, classes, line);
|
|
117
|
+
}
|
|
118
|
+
if (!items.length) issue(firstLine, "缺少时段", "Expected a timeline period");
|
|
119
|
+
const count = items.reduce((n, item) => n + 1 + item.events.length, 0);
|
|
120
|
+
if (count > 2e3) issue(firstLine, `时间线有 ${count} 个条目,超过 2000,请拆分`, `Timeline has ${count} entries (limit 2,000); split the diagram`);
|
|
121
|
+
for (const item of items) {
|
|
122
|
+
item.status = look.statusOf(item.id);
|
|
123
|
+
item.link = look.linkOf(item.id);
|
|
124
|
+
for (const event of item.eventDetails) {
|
|
125
|
+
event.status = look.statusOf(event.id);
|
|
126
|
+
event.link = look.linkOf(event.id);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const heading = label(title.text, null, title.line);
|
|
130
|
+
model.title = info.title = heading.text;
|
|
131
|
+
model.titleIcon = heading.icon;
|
|
132
|
+
errors.push(...look.diagnostics());
|
|
133
|
+
model.count = count;
|
|
134
|
+
return {
|
|
135
|
+
model,
|
|
136
|
+
errors
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function layout(model, { width, ctx, measure, renderOptions }) {
|
|
140
|
+
const { design: d } = ctx, { items, config, sections } = model;
|
|
141
|
+
const vertical = model.direction === "TD";
|
|
142
|
+
const finite = (value, fallback, floor) => Number.isFinite(Number(value)) ? Math.max(floor, Number(value)) : fallback;
|
|
143
|
+
const left = finite(config.leftMargin, 24, 24), pad = finite(config.padding, 12, 12);
|
|
144
|
+
const body = {
|
|
145
|
+
...FONT.body,
|
|
146
|
+
size: finite(config.taskFontSize, 13, 12)
|
|
147
|
+
}, period = {
|
|
148
|
+
...body,
|
|
149
|
+
weight: 600
|
|
150
|
+
};
|
|
151
|
+
const lh = body.size + 5, iconSize = 16, iconGap = 6;
|
|
152
|
+
const occupied = sections.reduce((n, s) => n + (s.name || s.icon || s.items.length ? Math.max(1, s.items.length) : 0), 0);
|
|
153
|
+
const col = vertical ? Math.max(184, pad * 2 + 100) : Math.max(184, pad * 2 + 100, (width - left - 24) / occupied);
|
|
154
|
+
const eventW = vertical ? Math.max(204, width - left - col - 76, pad * 2 + 100) : col - 2 * pad - 14;
|
|
155
|
+
const w = vertical ? left + col + eventW + 76 : left + col * occupied + 24;
|
|
156
|
+
const children = [], scene = {
|
|
157
|
+
width: w,
|
|
158
|
+
height: 0,
|
|
159
|
+
title: model.title,
|
|
160
|
+
children,
|
|
161
|
+
...renderOptions?.frame ? { heading: model.title || void 0 } : {}
|
|
162
|
+
};
|
|
163
|
+
const add = (tag, attrs, meta) => children.push({
|
|
164
|
+
...ctx.el(tag, attrs),
|
|
165
|
+
...meta ? { meta } : {}
|
|
166
|
+
});
|
|
167
|
+
const text = (value, x, y, font, fill, anchor = "start", meta) => children.push(ctx.text(x, y, value, {
|
|
168
|
+
...font,
|
|
169
|
+
fill,
|
|
170
|
+
anchor,
|
|
171
|
+
"dominant-baseline": "central"
|
|
172
|
+
}, meta));
|
|
173
|
+
const wrap = (value, max, font) => wrapText(value, max, font, measure);
|
|
174
|
+
const lines = (values, x, y, font, fill, anchor, pitch = lh) => values.forEach((value, i) => text(value, x, y + i * pitch, font, fill, anchor));
|
|
175
|
+
const line = (x1, y1, x2, y2, stroke, dash) => add("line", {
|
|
176
|
+
x1,
|
|
177
|
+
y1,
|
|
178
|
+
x2,
|
|
179
|
+
y2,
|
|
180
|
+
stroke,
|
|
181
|
+
"stroke-width": 2,
|
|
182
|
+
...dash ? { "stroke-dasharray": "4 4" } : {}
|
|
183
|
+
});
|
|
184
|
+
const card = (x, y, width, height, fill, stroke, meta) => ({
|
|
185
|
+
...ctx.el("rect", {
|
|
186
|
+
x,
|
|
187
|
+
y,
|
|
188
|
+
width,
|
|
189
|
+
height,
|
|
190
|
+
fill,
|
|
191
|
+
stroke,
|
|
192
|
+
rx: 6,
|
|
193
|
+
"stroke-width": 1.5
|
|
194
|
+
}),
|
|
195
|
+
...meta ? { meta } : {}
|
|
196
|
+
});
|
|
197
|
+
const tone = (index) => ctx.color(`tone${config.disableMulticolor ? 1 : 1 + index % 6}`);
|
|
198
|
+
const drawIcon = (icon, x, y, color) => {
|
|
199
|
+
if (!icon) return null;
|
|
200
|
+
const [vx, vy, iw, ih] = icon.viewBox.split(/\s+/).map(Number), scale = iconSize / Math.max(iw, ih), solid = icon.set !== "tabler";
|
|
201
|
+
return ctx.el("g", {
|
|
202
|
+
transform: `translate(${x - (vx + iw / 2) * scale} ${y - (vy + ih / 2) * scale}) scale(${scale})`,
|
|
203
|
+
fill: solid ? color : "none",
|
|
204
|
+
stroke: solid ? "none" : color,
|
|
205
|
+
"stroke-width": 1.6,
|
|
206
|
+
"stroke-linecap": "round",
|
|
207
|
+
"stroke-linejoin": "round"
|
|
208
|
+
}, icon.elements.map(({ tag, attrs }) => ctx.shape(tag, attrs)));
|
|
209
|
+
};
|
|
210
|
+
const boxColor = (status, fallback) => status && d[status] || fallback;
|
|
211
|
+
const titleSlot = model.titleIcon ? 22 : 0;
|
|
212
|
+
const title = !renderOptions?.frame && (model.title || model.titleIcon) ? wrap(model.title, w - 48 - titleSlot, FONT.title) : [];
|
|
213
|
+
if (title.length && model.titleIcon) children.push(drawIcon(model.titleIcon, 32, 24, d.fg1));
|
|
214
|
+
lines(title, 24 + titleSlot, 24, FONT.title, d.fg1, "start", 20);
|
|
215
|
+
const top = title.length ? 24 + title.length * 20 : 24;
|
|
216
|
+
const groups = sections.filter((group) => group.name || group.icon || group.items.length).map((group, index) => ({
|
|
217
|
+
...group,
|
|
218
|
+
index,
|
|
219
|
+
width: vertical ? w - left - 24 : Math.max(col, col * group.items.length)
|
|
220
|
+
}));
|
|
221
|
+
const sectionLines = (group) => wrap(group.name, group.width - 2 * pad - (group.icon ? 22 : 0), FONT.body);
|
|
222
|
+
const draws = items.map((item) => ({
|
|
223
|
+
label: wrap(item.text, col - 2 * pad - 12 - (item.icon ? 22 : 0), period),
|
|
224
|
+
events: item.events.map((event, i) => wrap(event, eventW - (vertical ? 2 * pad : 0) - (item.eventDetails[i].icon ? 22 : 0), body))
|
|
225
|
+
}));
|
|
226
|
+
const prepared = new Map(items.map((item, i) => [item, draws[i]]));
|
|
227
|
+
const emitNodeCard = (item, x, y, width, height, color, font, wrapped, centered = false) => {
|
|
228
|
+
const fill = item.status ? ctx.tint(d.bg, color, .12) : d.bg;
|
|
229
|
+
const outline = card(x, y, width, height, fill, color, {
|
|
230
|
+
kind: "node",
|
|
231
|
+
id: item.id
|
|
232
|
+
});
|
|
233
|
+
const ix = x + pad;
|
|
234
|
+
const iconNode = item.icon ? drawIcon(item.icon, ix + iconSize / 2, y + pad + lh / 2, color) : null;
|
|
235
|
+
const tx = item.icon ? ix + iconSize + iconGap : centered ? x + width / 2 : x + pad;
|
|
236
|
+
const textNodes = wrapped.map((value, i) => ctx.text(tx, y + pad + lh / 2 + i * lh, value, {
|
|
237
|
+
...font,
|
|
238
|
+
fill: d.fg1,
|
|
239
|
+
anchor: centered && !item.icon ? "middle" : "start",
|
|
240
|
+
"dominant-baseline": "central"
|
|
241
|
+
}));
|
|
242
|
+
if (item.link) children.push(ctx.link(item.link.href, [
|
|
243
|
+
outline,
|
|
244
|
+
...iconNode ? [iconNode] : [],
|
|
245
|
+
...textNodes
|
|
246
|
+
], item.link));
|
|
247
|
+
else children.push(outline, ...iconNode ? [iconNode] : [], ...textNodes);
|
|
248
|
+
};
|
|
249
|
+
if (vertical) {
|
|
250
|
+
const axis = left + col + 12, axisEnd = children.length, backgrounds = [];
|
|
251
|
+
let y = top;
|
|
252
|
+
for (const group of groups) {
|
|
253
|
+
const start = y, color = tone(group.index), names = group.name || group.icon ? sectionLines(group) : [];
|
|
254
|
+
if (names.length) {
|
|
255
|
+
if (group.icon) children.push(drawIcon(group.icon, left + pad + iconSize / 2, y + 14, color));
|
|
256
|
+
lines(names, left + pad + (group.icon ? 22 : 0), y + 14, FONT.body, d.fg1);
|
|
257
|
+
y += names.length * lh + 12;
|
|
258
|
+
}
|
|
259
|
+
for (const item of group.items) {
|
|
260
|
+
const { label, events } = prepared.get(item), cardH = label.length * lh + 2 * pad;
|
|
261
|
+
const eventH = events.reduce((n, e) => n + e.length * lh + 2 * pad + 8, 0), center = y + cardH / 2;
|
|
262
|
+
const nodeInk = boxColor(item.status, group.name ? color : tone(item.index));
|
|
263
|
+
line(axis - 22, center, axis, center, nodeInk, true);
|
|
264
|
+
add("circle", {
|
|
265
|
+
cx: axis,
|
|
266
|
+
cy: center,
|
|
267
|
+
r: 5,
|
|
268
|
+
fill: nodeInk
|
|
269
|
+
});
|
|
270
|
+
emitNodeCard(item, left, y, col - 10, cardH, nodeInk, period, label);
|
|
271
|
+
let ey = y;
|
|
272
|
+
for (const [i] of item.events.entries()) {
|
|
273
|
+
const event = item.eventDetails[i], wrapped = events[i], h = wrapped.length * lh + 2 * pad, eventInk = boxColor(event.status, ctx.color("grid"));
|
|
274
|
+
line(axis + 5, ey + h / 2, axis + 24, ey + h / 2, eventInk, true);
|
|
275
|
+
emitNodeCard(event, axis + 24, ey, eventW, h, eventInk, body, wrapped);
|
|
276
|
+
ey += h + 8;
|
|
277
|
+
}
|
|
278
|
+
y += Math.max(cardH, eventH) + 12;
|
|
279
|
+
}
|
|
280
|
+
if (names.length) {
|
|
281
|
+
const frame = card(left - 8, start, group.width + 8, y - start, ctx.tint(d.bg, color, .08), "none", {
|
|
282
|
+
kind: "frame",
|
|
283
|
+
id: `section:${group.index}`
|
|
284
|
+
});
|
|
285
|
+
backgrounds.push(frame);
|
|
286
|
+
}
|
|
287
|
+
y += 12;
|
|
288
|
+
}
|
|
289
|
+
line(axis, top, axis, y - 20, ctx.color("grid"));
|
|
290
|
+
const axisLine = children.pop();
|
|
291
|
+
children.splice(axisEnd, 0, ...backgrounds, axisLine);
|
|
292
|
+
scene.height = y + 8;
|
|
293
|
+
} else {
|
|
294
|
+
const axisY = top + Math.max(0, ...groups.map((group) => group.name || group.icon ? sectionLines(group).length * lh + 14 : 0)) + 8, y = axisY + 18;
|
|
295
|
+
const labelH = Math.max(...draws.map((row) => row.label.length)) * lh + 2 * pad;
|
|
296
|
+
const eventH = Math.max(0, ...draws.map((row) => row.events.reduce((n, event) => n + lh * event.length + 8, 0)));
|
|
297
|
+
scene.height = y + labelH + eventH + 32;
|
|
298
|
+
let x = left;
|
|
299
|
+
for (const group of groups) {
|
|
300
|
+
const color = tone(group.index);
|
|
301
|
+
if (group.name || group.icon) {
|
|
302
|
+
add("rect", {
|
|
303
|
+
x,
|
|
304
|
+
y: top - 8,
|
|
305
|
+
width: group.width - 5,
|
|
306
|
+
height: scene.height - top - 6,
|
|
307
|
+
fill: ctx.tint(d.bg, color, .08),
|
|
308
|
+
stroke: "none"
|
|
309
|
+
}, {
|
|
310
|
+
kind: "frame",
|
|
311
|
+
id: `section:${group.index}`
|
|
312
|
+
});
|
|
313
|
+
if (group.icon) children.push(drawIcon(group.icon, x + pad + iconSize / 2, top + 6, color));
|
|
314
|
+
lines(sectionLines(group), x + pad + (group.icon ? 22 : 0), top + 6, FONT.body, d.fg1);
|
|
315
|
+
}
|
|
316
|
+
x += group.width;
|
|
317
|
+
}
|
|
318
|
+
line(left, axisY, w - 24, axisY, ctx.color("grid"));
|
|
319
|
+
x = left;
|
|
320
|
+
for (const group of groups) {
|
|
321
|
+
if (!group.items.length) {
|
|
322
|
+
x += col;
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
for (const item of group.items) {
|
|
326
|
+
const { label, events } = prepared.get(item), color = boxColor(item.status, tone(group.name ? group.index : item.index));
|
|
327
|
+
add("circle", {
|
|
328
|
+
cx: x + col / 2,
|
|
329
|
+
cy: axisY,
|
|
330
|
+
r: 5,
|
|
331
|
+
fill: color
|
|
332
|
+
});
|
|
333
|
+
emitNodeCard(item, x + 6, y, col - 16, labelH, color, period, label, true);
|
|
334
|
+
let ey = y + labelH + 15;
|
|
335
|
+
for (const [i] of item.events.entries()) {
|
|
336
|
+
const event = item.eventDetails[i], wrapped = events[i], eventColor = boxColor(event.status, color);
|
|
337
|
+
add("circle", {
|
|
338
|
+
cx: x + pad + 2,
|
|
339
|
+
cy: ey,
|
|
340
|
+
r: 2.5,
|
|
341
|
+
fill: eventColor
|
|
342
|
+
});
|
|
343
|
+
const eventLines = wrapped.map((value, j) => ctx.text(x + pad + 14 + (event.icon ? 22 : 0), ey + j * lh, value, {
|
|
344
|
+
...body,
|
|
345
|
+
fill: d.fg2,
|
|
346
|
+
"dominant-baseline": "central"
|
|
347
|
+
}));
|
|
348
|
+
if (event.icon) eventLines.unshift(drawIcon(event.icon, x + pad + 14 + iconSize / 2, ey, eventColor));
|
|
349
|
+
children.push(...event.link ? [ctx.link(event.link.href, eventLines, event.link)] : eventLines);
|
|
350
|
+
ey += wrapped.length * lh + 8;
|
|
351
|
+
}
|
|
352
|
+
x += col;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
const errors = scene.width > 2 * width || model.count > 60 ? [warning("LARGE_DIAGRAM", ctx.lang, model.firstLine, "时间线较大,可滚动查看", "Large timeline; scroll to view", "可拆成多张时间线", "Consider splitting the timeline")] : [];
|
|
357
|
+
return {
|
|
358
|
+
width: scene.width,
|
|
359
|
+
height: scene.height,
|
|
360
|
+
scene,
|
|
361
|
+
errors
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
var implementations = { timeline: {
|
|
365
|
+
optionMode: "raw",
|
|
366
|
+
parse,
|
|
367
|
+
layout,
|
|
368
|
+
acceptsPresentation: true,
|
|
369
|
+
honoredConfig: [
|
|
370
|
+
"timeline.leftMargin",
|
|
371
|
+
"timeline.taskFontSize",
|
|
372
|
+
"timeline.padding",
|
|
373
|
+
"timeline.disableMulticolor"
|
|
374
|
+
]
|
|
375
|
+
} };
|
|
376
|
+
export { implementations, timeline_exports };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
// src/diagram/tree-family-icon.js
|
|
3
|
+
var tree_family_icon_exports = /* @__PURE__ */ __exportAll({ labelIcon: () => labelIcon });
|
|
4
|
+
function labelIcon(ctx, icon, x, y, size, ink) {
|
|
5
|
+
const [l, t, w, h] = icon.viewBox.split(/\s+/).map(Number);
|
|
6
|
+
const scale = size / Math.max(w, h);
|
|
7
|
+
const paint = icon.set === "tabler" ? {
|
|
8
|
+
fill: "none",
|
|
9
|
+
stroke: ink,
|
|
10
|
+
"stroke-width": 1.8,
|
|
11
|
+
"stroke-linecap": "round",
|
|
12
|
+
"stroke-linejoin": "round"
|
|
13
|
+
} : { fill: ink };
|
|
14
|
+
return {
|
|
15
|
+
...ctx.el("g", { transform: `translate(${x - (l + w / 2) * scale} ${y - (t + h / 2) * scale}) scale(${scale})` }, icon.elements.map(({ tag, attrs }) => ctx.shape(tag, {
|
|
16
|
+
...attrs,
|
|
17
|
+
...paint
|
|
18
|
+
}))),
|
|
19
|
+
meta: { kind: "icon" }
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export { labelIcon, tree_family_icon_exports };
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { FONT, appearance, error, maxWidthOf, textBlock, warning, wrapText } from "./support.js";
|
|
3
|
+
import { normalizeLabel } from "./label.js";
|
|
4
|
+
import { presentation } from "./presentation.js";
|
|
5
|
+
import { resolveIconRef } from "../core/icons.js";
|
|
6
|
+
import { labelIcon } from "./tree-family-icon.js";
|
|
7
|
+
// src/diagram/treeview.js
|
|
8
|
+
var treeview_exports = /* @__PURE__ */ __exportAll({ implementations: () => implementations });
|
|
9
|
+
var honoredConfig = [
|
|
10
|
+
"rowIndent",
|
|
11
|
+
"paddingX",
|
|
12
|
+
"paddingY",
|
|
13
|
+
"lineThickness",
|
|
14
|
+
"showIcons",
|
|
15
|
+
"filenameIcons",
|
|
16
|
+
"extensionIcons"
|
|
17
|
+
].map((key) => `treeView.${key}`);
|
|
18
|
+
var clamp = (value, fallback, min, max) => typeof value === "number" && Number.isFinite(value) ? Math.max(min, Math.min(max, value)) : fallback;
|
|
19
|
+
var BRANCH = /^([ \t│┃]*)(?:[├└┣┗])[─━]*[ \t]*/;
|
|
20
|
+
var ANNOTATION = /[ \t]+(?=:::[ \t]*[A-Za-z_]|icon\(|##)/;
|
|
21
|
+
var LEADING_EMOJI = /^(?:\p{Emoji_Presentation}|\p{Extended_Pictographic}\uFE0F|[0-9#*]\uFE0F?\u20E3)/u;
|
|
22
|
+
var MARGIN = 24;
|
|
23
|
+
var STEP = 24;
|
|
24
|
+
var columns = (str) => str.replaceAll(" ", " ").length;
|
|
25
|
+
function parse(body, { firstLine = 2, headerLine = 1, lang, params, config }) {
|
|
26
|
+
const errors = [], rows = [{
|
|
27
|
+
id: "root",
|
|
28
|
+
label: "/",
|
|
29
|
+
directory: true,
|
|
30
|
+
depth: 0,
|
|
31
|
+
description: ""
|
|
32
|
+
}];
|
|
33
|
+
const look = presentation({ lang }), settings = config?.treeView ?? {}, seen = /* @__PURE__ */ new Set();
|
|
34
|
+
const addIssue = (issue) => {
|
|
35
|
+
if (!seen.has(issue.message)) {
|
|
36
|
+
seen.add(issue.message);
|
|
37
|
+
errors.push(issue);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const normalize = (value, line) => {
|
|
41
|
+
const result = normalizeLabel(value, {
|
|
42
|
+
lang,
|
|
43
|
+
line
|
|
44
|
+
});
|
|
45
|
+
result.diagnostics.forEach(addIssue);
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
const lines = String(body).split("\n").map((raw, index) => ({
|
|
49
|
+
raw,
|
|
50
|
+
line: firstLine + index
|
|
51
|
+
})).filter(({ raw, line }) => raw.trim() && !raw.trimStart().startsWith("%%") && !look.accept(raw, line));
|
|
52
|
+
const unit = lines.map(({ raw }) => raw.match(BRANCH)).find((match) => match && columns(match[1]))?.[1];
|
|
53
|
+
const box = lines.some(({ raw }) => BRANCH.test(raw));
|
|
54
|
+
const stack = [];
|
|
55
|
+
let title;
|
|
56
|
+
const fail = (line, zh, en) => errors.push(error(lang, line, zh, en, "检查树节点声明", "Check the tree node declaration"));
|
|
57
|
+
if (params?.trim()) fail(headerLine, "树视图表头不接受参数", "Tree view header takes no parameters");
|
|
58
|
+
for (const { raw, line } of lines) {
|
|
59
|
+
const text = raw.trim();
|
|
60
|
+
const heading = text.match(/^title(?:\s*:\s*|\s+)(.*)/i);
|
|
61
|
+
if (heading) {
|
|
62
|
+
title = normalize(heading[1], line).text;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const prefix = box ? raw.match(BRANCH) : null;
|
|
66
|
+
if (box && /^[\s│┃]+$/.test(raw)) continue;
|
|
67
|
+
if (box && !prefix && /^[ \t│┃]/.test(raw)) {
|
|
68
|
+
fail(line, "缩进缺少树线前缀", "Unexpected indentation without box-drawing characters");
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (prefix && !raw.slice(prefix[0].length).trim()) {
|
|
72
|
+
fail(line, "树线后缺少文件或目录名", "Empty node: expected a filename or directory name after the box-drawing prefix");
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const indent = prefix ? Math.round(columns(prefix[1]) / (unit ? columns(unit) : 4)) + 1 : columns(raw.match(/^[ \t]*/)[0]);
|
|
76
|
+
let value = prefix ? raw.slice(prefix[0].length).trim() : text;
|
|
77
|
+
const quoted = value.match(/^(?:"([^"]*)"|'([^']*)')/);
|
|
78
|
+
const boundary = value.search(ANNOTATION);
|
|
79
|
+
const label = quoted ? quoted[1] ?? quoted[2] : (boundary < 0 ? value : value.slice(0, boundary)).trimEnd();
|
|
80
|
+
value = quoted ? value.slice(quoted[0].length).trimStart() : boundary < 0 ? "" : value.slice(boundary).trimStart();
|
|
81
|
+
let description = "", highlight = false, icon;
|
|
82
|
+
const name = normalize(label, line);
|
|
83
|
+
const directory = name.text.endsWith("/");
|
|
84
|
+
const textLabel = directory && name.text !== "/" ? name.text.slice(0, -1) : name.text;
|
|
85
|
+
while (value) {
|
|
86
|
+
const cls = value.match(/^:::[ \t]*([A-Za-z_][\w-]*)/);
|
|
87
|
+
const ico = value.match(/^icon\(([\w-]*(?::[\w-]+)?)\)/);
|
|
88
|
+
if (value.startsWith("##")) {
|
|
89
|
+
description = normalize(value.slice(2), line).text;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
if (cls) {
|
|
93
|
+
if (cls[1] === "highlight") highlight = true;
|
|
94
|
+
else look.addClasses(textLabel, [cls[1]], line);
|
|
95
|
+
} else if (ico) icon = ico[1] || "none";
|
|
96
|
+
else {
|
|
97
|
+
fail(line, "无法识别树节点注解", "Unrecognized tree node annotation");
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
value = value.slice((cls || ico)[0].length).trimStart();
|
|
101
|
+
}
|
|
102
|
+
while (stack.length && indent <= stack.at(-1).indent) stack.pop();
|
|
103
|
+
const ext = /\.[^.\/]+$/.exec(textLabel)?.[0];
|
|
104
|
+
const mapped = settings.filenameIcons?.[textLabel] ?? (!directory && ext ? settings.extensionIcons?.[ext] : void 0);
|
|
105
|
+
const ref = icon ?? (name.icon ? void 0 : typeof mapped === "string" ? mapped : void 0);
|
|
106
|
+
const defaultGlyph = LEADING_EMOJI.test(textLabel) ? null : resolveIconRef(directory ? "tabler:folder" : "tabler:file");
|
|
107
|
+
let glyph = name.icon ?? defaultGlyph;
|
|
108
|
+
if (ref === "none") glyph = null;
|
|
109
|
+
else if (ref) {
|
|
110
|
+
glyph = resolveIconRef(ref);
|
|
111
|
+
if (!glyph) {
|
|
112
|
+
addIssue(warning("IGNORED_ASSET", lang, line, `未知图标 ${ref}`, `Unknown icon ${ref}`, "使用内置或已注册的图标", "Use a built-in or registered icon"));
|
|
113
|
+
glyph = defaultGlyph;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const row = {
|
|
117
|
+
id: `row-${line}`,
|
|
118
|
+
parent: stack.at(-1)?.id ?? "root",
|
|
119
|
+
depth: stack.length + 1,
|
|
120
|
+
indent,
|
|
121
|
+
line,
|
|
122
|
+
directory,
|
|
123
|
+
label: textLabel,
|
|
124
|
+
description,
|
|
125
|
+
highlight,
|
|
126
|
+
icon,
|
|
127
|
+
glyph: settings.showIcons === false ? null : glyph
|
|
128
|
+
};
|
|
129
|
+
rows.push(row);
|
|
130
|
+
stack.push(row);
|
|
131
|
+
if (rows.length > 2001) {
|
|
132
|
+
fail(line, "树节点最多支持 2000 个", "Tree view supports at most 2,000 entries");
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
rows[0].glyph = settings.showIcons === false ? null : resolveIconRef("tabler:folder");
|
|
137
|
+
rows.forEach((row, index) => {
|
|
138
|
+
row.status = look.statusOf(row.label);
|
|
139
|
+
row.link = look.linkOf(row.label);
|
|
140
|
+
if (index) row.edgeStatus = look.edgeStatusOf(index - 1);
|
|
141
|
+
});
|
|
142
|
+
return {
|
|
143
|
+
model: {
|
|
144
|
+
rows,
|
|
145
|
+
title,
|
|
146
|
+
headerLine,
|
|
147
|
+
settings
|
|
148
|
+
},
|
|
149
|
+
errors: [...errors, ...look.diagnostics()]
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function layout(model, { width, measure, lang }) {
|
|
153
|
+
const available = Math.max(120, width - 48);
|
|
154
|
+
const { settings } = model;
|
|
155
|
+
const step = clamp(clamp(settings.rowIndent, 10, 4, 90) + clamp(settings.paddingX, 14, 4, 24), STEP, 12, 96);
|
|
156
|
+
const inset = clamp(settings.paddingY, 4, 4, 20);
|
|
157
|
+
const lineThickness = clamp(settings.lineThickness, 1, 1, 3);
|
|
158
|
+
let rows, end;
|
|
159
|
+
for (const cap of [
|
|
160
|
+
220,
|
|
161
|
+
190,
|
|
162
|
+
160,
|
|
163
|
+
140,
|
|
164
|
+
120
|
|
165
|
+
]) {
|
|
166
|
+
rows = model.rows.map((row) => {
|
|
167
|
+
const font = {
|
|
168
|
+
...FONT.body,
|
|
169
|
+
weight: row.directory ? 650 : 400
|
|
170
|
+
};
|
|
171
|
+
const lines = wrapText(row.label, cap, font, measure);
|
|
172
|
+
const notes = row.description ? wrapText(row.description, 240, FONT.label, measure) : [];
|
|
173
|
+
const x = MARGIN + step * row.depth;
|
|
174
|
+
const textX = x + (row.glyph ? 20 : 0);
|
|
175
|
+
return {
|
|
176
|
+
...row,
|
|
177
|
+
font,
|
|
178
|
+
lines,
|
|
179
|
+
notes,
|
|
180
|
+
x,
|
|
181
|
+
textX,
|
|
182
|
+
labelEnd: textX + maxWidthOf(lines, font, measure)
|
|
183
|
+
};
|
|
184
|
+
});
|
|
185
|
+
end = Math.max(...rows.map((row) => row.labelEnd));
|
|
186
|
+
if (end + MARGIN <= width) break;
|
|
187
|
+
}
|
|
188
|
+
const noteWidth = Math.max(0, ...rows.map((row) => maxWidthOf(row.notes, FONT.label, measure)));
|
|
189
|
+
const inline = !noteWidth || end + 16 + noteWidth + MARGIN <= width + 240;
|
|
190
|
+
const title = model.title ? wrapText(model.title, available, FONT.title, measure) : [];
|
|
191
|
+
let y = MARGIN + (title.length ? title.length * 19 + 12 : 0);
|
|
192
|
+
let right = Math.max(end, MARGIN + maxWidthOf(title, FONT.title, measure));
|
|
193
|
+
for (const row of rows) {
|
|
194
|
+
const labelH = row.lines.length * 17;
|
|
195
|
+
const noteH = row.notes.length * 16;
|
|
196
|
+
row.top = y;
|
|
197
|
+
row.h = Math.max(24, (inline ? Math.max(labelH, noteH) : labelH + (noteH ? noteH + 4 : 0)) + inset * 2);
|
|
198
|
+
row.labelY = inline ? y + row.h / 2 : y + inset + labelH / 2;
|
|
199
|
+
row.noteY = inline ? row.labelY : y + inset + 4 + labelH + noteH / 2;
|
|
200
|
+
row.noteX = inline ? end + 16 : row.x;
|
|
201
|
+
if (noteH) right = Math.max(right, row.noteX + maxWidthOf(row.notes, FONT.label, measure));
|
|
202
|
+
y += row.h;
|
|
203
|
+
}
|
|
204
|
+
const naturalWidth = Math.ceil(right + MARGIN + 8);
|
|
205
|
+
const errors = rows.length > 61 || naturalWidth > width * 2 ? [warning("LARGE_DIAGRAM", lang, model.headerLine, "树视图较大", "This tree view is large", "考虑拆分为多个树视图", "Consider splitting it into smaller trees")] : [];
|
|
206
|
+
return {
|
|
207
|
+
rows,
|
|
208
|
+
title,
|
|
209
|
+
width: naturalWidth,
|
|
210
|
+
height: y + MARGIN,
|
|
211
|
+
right,
|
|
212
|
+
lineThickness,
|
|
213
|
+
errors
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function scene(plan, ctx) {
|
|
217
|
+
const A = appearance(ctx), { rows, right } = plan;
|
|
218
|
+
const byId = new Map(rows.map((row) => [row.id, row]));
|
|
219
|
+
const trunk = /* @__PURE__ */ new Map(), edges = [], labels = [];
|
|
220
|
+
for (const row of rows) {
|
|
221
|
+
const parent = byId.get(row.parent);
|
|
222
|
+
if (parent) {
|
|
223
|
+
const x = parent.x + 4, y = trunk.get(parent.id) ?? parent.top + parent.h;
|
|
224
|
+
const armY = row.labelY;
|
|
225
|
+
edges.push(ctx.path(`M${x} ${y} V${armY - 2} Q${x} ${armY} ${x + 2} ${armY} H${row.x - 5}`, {
|
|
226
|
+
fill: "none",
|
|
227
|
+
stroke: row.edgeStatus ? ctx.frameTone(A[row.edgeStatus]) : A.fg4,
|
|
228
|
+
"stroke-width": plan.lineThickness,
|
|
229
|
+
meta: {
|
|
230
|
+
kind: "edge",
|
|
231
|
+
from: parent.id,
|
|
232
|
+
to: row.id
|
|
233
|
+
}
|
|
234
|
+
}));
|
|
235
|
+
trunk.set(parent.id, armY);
|
|
236
|
+
}
|
|
237
|
+
const x = row.x - 3, y = row.top + 1, h = row.h - 2;
|
|
238
|
+
const tone = A[row.status] ?? (row.highlight ? A.warn : null);
|
|
239
|
+
const content = [ctx.rect(x, y, (tone ? right + 8 : row.labelEnd + 3) - x, h, {
|
|
240
|
+
fill: tone ? ctx.tint(A.bg, tone, .12) : "none",
|
|
241
|
+
...tone ? {
|
|
242
|
+
stroke: ctx.frameTone(tone),
|
|
243
|
+
rx: 3
|
|
244
|
+
} : {},
|
|
245
|
+
meta: {
|
|
246
|
+
kind: "node",
|
|
247
|
+
id: row.id
|
|
248
|
+
}
|
|
249
|
+
})];
|
|
250
|
+
if (row.glyph) content.push(labelIcon(ctx, row.glyph, row.x + 7, row.labelY, 14, A.fg3));
|
|
251
|
+
content.push(textBlock(ctx, {
|
|
252
|
+
x: row.textX,
|
|
253
|
+
y: row.labelY,
|
|
254
|
+
lines: row.lines,
|
|
255
|
+
font: row.font,
|
|
256
|
+
anchor: "start",
|
|
257
|
+
lineHeight: 17,
|
|
258
|
+
fill: row.parent ? A.fg1 : ctx.color("muted")
|
|
259
|
+
}));
|
|
260
|
+
labels.push(...row.link ? [ctx.link(row.link.href, content, row.link)] : content);
|
|
261
|
+
if (row.notes.length) labels.push(textBlock(ctx, {
|
|
262
|
+
x: row.noteX,
|
|
263
|
+
y: row.noteY,
|
|
264
|
+
lines: row.notes,
|
|
265
|
+
font: FONT.label,
|
|
266
|
+
anchor: "start",
|
|
267
|
+
lineHeight: 16,
|
|
268
|
+
fill: ctx.color("muted")
|
|
269
|
+
}));
|
|
270
|
+
}
|
|
271
|
+
if (plan.title.length) labels.push(textBlock(ctx, {
|
|
272
|
+
x: MARGIN,
|
|
273
|
+
y: MARGIN + plan.title.length * 19 / 2,
|
|
274
|
+
lines: plan.title,
|
|
275
|
+
font: FONT.title,
|
|
276
|
+
anchor: "start",
|
|
277
|
+
lineHeight: 19
|
|
278
|
+
}));
|
|
279
|
+
return {
|
|
280
|
+
width: plan.width,
|
|
281
|
+
height: plan.height,
|
|
282
|
+
children: [...edges, ...labels]
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
var implementations = { "treeView-beta": {
|
|
286
|
+
optionMode: "raw",
|
|
287
|
+
acceptsPresentation: true,
|
|
288
|
+
honoredConfig,
|
|
289
|
+
parse,
|
|
290
|
+
layout,
|
|
291
|
+
scene
|
|
292
|
+
} };
|
|
293
|
+
export { implementations, treeview_exports };
|