@joplo-app/core 0.2.18 → 0.4.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/dist/actions.d.ts +6 -0
- package/dist/actions.js +34 -0
- package/dist/agent-skill.d.ts +9 -15
- package/dist/agent-skill.js +41 -44
- package/dist/auto-caption.d.ts +3 -0
- package/dist/auto-caption.js +33 -0
- package/dist/catalog.d.ts +39 -47
- package/dist/catalog.js +27 -334
- package/dist/compile.d.ts +2 -8
- package/dist/compile.js +230 -393
- package/dist/content-i18n.js +27 -16
- package/dist/feature-diff.d.ts +9 -9
- package/dist/feature-diff.js +28 -6
- package/dist/focus.d.ts +6 -2
- package/dist/focus.js +28 -36
- package/dist/guide.d.ts +10 -12
- package/dist/guide.js +372 -594
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/media.d.ts +10 -0
- package/dist/media.js +43 -0
- package/dist/node.d.ts +1 -2
- package/dist/node.js +1 -2
- package/dist/outline.js +1 -1
- package/dist/pace.d.ts +4 -1
- package/dist/pace.js +7 -3
- package/dist/player.d.ts +8 -41
- package/dist/player.js +83 -147
- package/dist/playground.d.ts +38 -0
- package/dist/playground.js +111 -0
- package/dist/plugin-data.d.ts +11 -0
- package/dist/plugin-data.js +96 -0
- package/dist/plugins/compiler.d.ts +67 -0
- package/dist/plugins/compiler.js +434 -0
- package/dist/plugins/data.d.ts +12 -0
- package/dist/plugins/data.js +120 -0
- package/dist/result.d.ts +1 -1
- package/dist/result.js +1 -0
- package/dist/runtime.d.ts +22 -0
- package/dist/runtime.js +18 -0
- package/dist/schema.d.ts +593 -112
- package/dist/schema.js +62 -52
- package/dist/scope.js +14 -5
- package/dist/step-identity.d.ts +1 -1
- package/dist/step-identity.js +1 -1
- package/dist/themes.d.ts +7 -0
- package/dist/themes.js +5 -0
- package/dist/traits.d.ts +7 -0
- package/dist/traits.js +26 -0
- package/dist/validate.js +17 -4
- package/package.json +7 -4
- package/dist/diagram/elk.d.ts +0 -6
- package/dist/diagram/elk.js +0 -56
- package/dist/diagram/graph-layout.d.ts +0 -123
- package/dist/diagram/graph-layout.js +0 -620
- package/dist/diagram/index.d.ts +0 -41
- package/dist/diagram/index.js +0 -92
- package/dist/diagram/model.d.ts +0 -217
- package/dist/diagram/model.js +0 -189
- package/dist/diagram/sequence-layout.d.ts +0 -12
- package/dist/diagram/sequence-layout.js +0 -185
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 时序图布局(D69,纯函数、确定):参与者按源码顺序排成列,消息按源码顺序一行一条,片段(alt / opt / loop…)是包住
|
|
3
|
-
* 若干行的框,参与者分组是包住若干列的业务域框。不需要通用图布局算法,编译期直接算好写进 IR。
|
|
4
|
-
*
|
|
5
|
-
* - 列间距:先按相邻头部宽度加最小间隙,再保证每条消息的标签放得下(跨多列的消息把不够的宽度平均分给它跨过的间隙);
|
|
6
|
-
* 自调用(from === to)的回环和标签放在生命线右侧,下一列让出位置。
|
|
7
|
-
* - 行:消息行高固定(标签在线上方),自调用多一点;片段开始处多一行放片段标签,结束处留一点底。
|
|
8
|
-
*/
|
|
9
|
-
import { GROUP_HEAD, GROUP_PAD, EDGE_FONT, groupTitleWidth, textWidth } from "./model.js";
|
|
10
|
-
const M = 12;
|
|
11
|
-
const GAP = 48;
|
|
12
|
-
const ROW = 44;
|
|
13
|
-
const SELF_ROW = 58;
|
|
14
|
-
const SELF_W = 36;
|
|
15
|
-
const BLOCK_HEAD = 30;
|
|
16
|
-
const BLOCK_TAIL = 12;
|
|
17
|
-
const BLOCK_PAD = 18;
|
|
18
|
-
/** 序号徽章占的宽度(numbered 时标签前面画一个圆形序号)。 */
|
|
19
|
-
export const SEQ_BADGE = 20;
|
|
20
|
-
export function layoutSequence(s) {
|
|
21
|
-
const empty = { kind: 'sequence', width: 0, height: 0, actors: {}, lifelines: {}, messages: {}, groups: {}, titles: {}, blocks: {}, blockTitles: {} };
|
|
22
|
-
if (!s.actors.length)
|
|
23
|
-
return empty;
|
|
24
|
-
const idx = new Map(s.actors.map((a, i) => [a.id, i]));
|
|
25
|
-
const n = s.actors.length;
|
|
26
|
-
const labelW = (label) => (label ? textWidth(label, EDGE_FONT) + 12 : 0) + (s.numbered ? SEQ_BADGE : 0);
|
|
27
|
-
// ---------- 列 ----------
|
|
28
|
-
// gap[i] = 第 i 列与第 i+1 列中心的距离
|
|
29
|
-
const gap = [];
|
|
30
|
-
for (let i = 0; i < n - 1; i++)
|
|
31
|
-
gap.push(s.actors[i].w / 2 + s.actors[i + 1].w / 2 + GAP);
|
|
32
|
-
// 同一分组的参与者之间、分组边界也要留出分组的内边距
|
|
33
|
-
for (let i = 0; i < n - 1; i++)
|
|
34
|
-
if (s.actors[i].group !== s.actors[i + 1].group)
|
|
35
|
-
gap[i] = gap[i] + 2 * GROUP_PAD;
|
|
36
|
-
const valid = s.messages.filter((m) => idx.has(m.from) && idx.has(m.to));
|
|
37
|
-
// 自调用:回环 + 标签放在右侧
|
|
38
|
-
for (const m of valid) {
|
|
39
|
-
if (m.from !== m.to)
|
|
40
|
-
continue;
|
|
41
|
-
const i = idx.get(m.from);
|
|
42
|
-
const need = SELF_W + 8 + labelW(m.label) + 16 + (i < n - 1 ? s.actors[i + 1].w / 2 : 0);
|
|
43
|
-
if (i < n - 1)
|
|
44
|
-
gap[i] = Math.max(gap[i], need);
|
|
45
|
-
}
|
|
46
|
-
// 普通消息:标签放得下(按跨度从小到大处理,结果确定)
|
|
47
|
-
const spans = valid.filter((m) => m.from !== m.to).map((m) => ({ a: Math.min(idx.get(m.from), idx.get(m.to)), b: Math.max(idx.get(m.from), idx.get(m.to)), w: labelW(m.label) + 28 }));
|
|
48
|
-
spans.sort((x, y) => x.b - x.a - (y.b - y.a) || x.a - y.a);
|
|
49
|
-
for (const sp of spans) {
|
|
50
|
-
let have = 0;
|
|
51
|
-
for (let i = sp.a; i < sp.b; i++)
|
|
52
|
-
have += gap[i];
|
|
53
|
-
if (have >= sp.w)
|
|
54
|
-
continue;
|
|
55
|
-
const add = (sp.w - have) / (sp.b - sp.a);
|
|
56
|
-
for (let i = sp.a; i < sp.b; i++)
|
|
57
|
-
gap[i] = gap[i] + add;
|
|
58
|
-
}
|
|
59
|
-
const hasGroups = s.actors.some((a) => a.group);
|
|
60
|
-
const left = M + (hasGroups ? GROUP_PAD : 0);
|
|
61
|
-
const cx = [left + s.actors[0].w / 2];
|
|
62
|
-
for (let i = 1; i < n; i++)
|
|
63
|
-
cx.push(cx[i - 1] + gap[i - 1]);
|
|
64
|
-
// ---------- 头部 ----------
|
|
65
|
-
const top = M + (hasGroups ? GROUP_HEAD + 4 : 0);
|
|
66
|
-
const headH = Math.max(...s.actors.map((a) => a.h));
|
|
67
|
-
const actors = {};
|
|
68
|
-
s.actors.forEach((a, i) => {
|
|
69
|
-
actors[a.id] = { x: cx[i] - a.w / 2, y: top + (headH - a.h), w: a.w, h: a.h };
|
|
70
|
-
});
|
|
71
|
-
// ---------- 行 ----------
|
|
72
|
-
const blockOf = new Map(s.blocks.map((b) => [b.id, b]));
|
|
73
|
-
const depthOf = (id) => {
|
|
74
|
-
let d = 0;
|
|
75
|
-
for (let b = blockOf.get(id); b?.parent; b = blockOf.get(b.parent))
|
|
76
|
-
d++;
|
|
77
|
-
return d;
|
|
78
|
-
};
|
|
79
|
-
let y = top + headH + 26;
|
|
80
|
-
const messages = {};
|
|
81
|
-
const blockY = new Map();
|
|
82
|
-
let open = [];
|
|
83
|
-
let k = 0;
|
|
84
|
-
for (const m of s.messages) {
|
|
85
|
-
// 离开的片段:收尾
|
|
86
|
-
const keep = open.filter((b, i) => m.blocks[i] === b);
|
|
87
|
-
for (const b of open.slice(keep.length).reverse()) {
|
|
88
|
-
y += BLOCK_TAIL;
|
|
89
|
-
blockY.get(b).y1 = y;
|
|
90
|
-
}
|
|
91
|
-
// 进入的片段:留出标签行
|
|
92
|
-
for (const b of m.blocks.slice(keep.length)) {
|
|
93
|
-
blockY.set(b, { y0: y, y1: y });
|
|
94
|
-
y += BLOCK_HEAD;
|
|
95
|
-
}
|
|
96
|
-
open = [...m.blocks];
|
|
97
|
-
if (!idx.has(m.from) || !idx.has(m.to))
|
|
98
|
-
continue; // 编译期已报 UNKNOWN_DIAGRAM_NODE
|
|
99
|
-
k++;
|
|
100
|
-
const lw = labelW(m.label);
|
|
101
|
-
if (m.from === m.to) {
|
|
102
|
-
const x = cx[idx.get(m.from)];
|
|
103
|
-
const ly = y + 18;
|
|
104
|
-
const points = [{ x, y: ly }, { x: x + SELF_W, y: ly }, { x: x + SELF_W, y: ly + 20 }, { x, y: ly + 20 }];
|
|
105
|
-
messages[m.id] = { points, label: lw ? { x: x + SELF_W + 8, y: ly + 1, w: lw, h: 18 } : null, n: k, self: true };
|
|
106
|
-
y += SELF_ROW;
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
const x1 = cx[idx.get(m.from)];
|
|
110
|
-
const x2 = cx[idx.get(m.to)];
|
|
111
|
-
const ly = y + 28;
|
|
112
|
-
messages[m.id] = { points: [{ x: x1, y: ly }, { x: x2, y: ly }], label: lw ? { x: (x1 + x2) / 2 - lw / 2, y: ly - 24, w: lw, h: 18 } : null, n: k, self: false };
|
|
113
|
-
y += ROW;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
for (const b of open.reverse()) {
|
|
117
|
-
y += BLOCK_TAIL;
|
|
118
|
-
blockY.get(b).y1 = y;
|
|
119
|
-
}
|
|
120
|
-
// 没有消息的片段(只有标题)
|
|
121
|
-
for (const b of s.blocks)
|
|
122
|
-
if (!blockY.has(b.id))
|
|
123
|
-
blockY.set(b.id, { y0: y, y1: (y += BLOCK_HEAD + BLOCK_TAIL) });
|
|
124
|
-
const bottom = y + 18;
|
|
125
|
-
// ---------- 片段框 ----------
|
|
126
|
-
const blocks = {};
|
|
127
|
-
const blockTitles = {};
|
|
128
|
-
const involved = (bid) => {
|
|
129
|
-
const cols = new Set();
|
|
130
|
-
for (const m of s.messages)
|
|
131
|
-
if (m.blocks.includes(bid) && idx.has(m.from) && idx.has(m.to))
|
|
132
|
-
[idx.get(m.from), idx.get(m.to)].forEach((c) => cols.add(c));
|
|
133
|
-
return [...cols];
|
|
134
|
-
};
|
|
135
|
-
for (const b of s.blocks) {
|
|
136
|
-
const cols = involved(b.id);
|
|
137
|
-
const d = depthOf(b.id);
|
|
138
|
-
const inset = (BLOCK_PAD * 2) / 3;
|
|
139
|
-
const c0 = cols.length ? Math.min(...cols) : 0;
|
|
140
|
-
const c1 = cols.length ? Math.max(...cols) : n - 1;
|
|
141
|
-
// 包含自调用时右侧多留出回环与标签
|
|
142
|
-
const selfExtra = Math.max(0, ...s.messages.filter((m) => m.blocks.includes(b.id) && m.from === m.to && idx.get(m.from) === c1).map((m) => SELF_W + 8 + labelW(m.label)));
|
|
143
|
-
const x0 = cx[c0] - Math.max(BLOCK_PAD + 40, s.actors[c0].w / 2 - 6) + d * inset;
|
|
144
|
-
const x1 = cx[c1] + Math.max(BLOCK_PAD + 40, s.actors[c1].w / 2 - 6, selfExtra + 10) - d * inset;
|
|
145
|
-
const yy = blockY.get(b.id);
|
|
146
|
-
blocks[b.id] = { x: x0, y: yy.y0 + 2, w: x1 - x0, h: yy.y1 - yy.y0 - 2 };
|
|
147
|
-
const title = `${b.kind}${b.label ? ` ${b.label}` : ''}`;
|
|
148
|
-
blockTitles[b.id] = { x: x0, y: yy.y0 + 2, w: Math.min(x1 - x0, textWidth(title, EDGE_FONT) + 18), h: 20 };
|
|
149
|
-
}
|
|
150
|
-
// ---------- 生命线与分组 ----------
|
|
151
|
-
const lifelines = {};
|
|
152
|
-
for (const a of s.actors)
|
|
153
|
-
lifelines[a.id] = { x: cx[idx.get(a.id)], y1: actors[a.id].y + actors[a.id].h, y2: bottom };
|
|
154
|
-
const groups = {};
|
|
155
|
-
const titles = {};
|
|
156
|
-
for (const g of s.groups) {
|
|
157
|
-
const members = s.actors.filter((a) => a.group === g.id);
|
|
158
|
-
if (!members.length)
|
|
159
|
-
continue;
|
|
160
|
-
const x0 = Math.min(...members.map((a) => actors[a.id].x)) - GROUP_PAD;
|
|
161
|
-
const x1 = Math.max(...members.map((a) => actors[a.id].x + actors[a.id].w)) + GROUP_PAD;
|
|
162
|
-
groups[g.id] = { x: x0, y: M, w: x1 - x0, h: bottom + 6 - M };
|
|
163
|
-
titles[g.id] = { x: x0 + 6, y: M + 4, w: Math.min(x1 - x0 - 12, groupTitleWidth(g.label, !!g.icon)), h: GROUP_HEAD - 6 };
|
|
164
|
-
}
|
|
165
|
-
// ---------- 整体尺寸 ----------
|
|
166
|
-
const boxes = [...Object.values(actors), ...Object.values(groups), ...Object.values(blocks), ...Object.values(messages).flatMap((m) => (m.label ? [m.label] : []))];
|
|
167
|
-
const maxX = Math.max(...boxes.map((b) => b.x + b.w), ...Object.values(messages).flatMap((m) => m.points.map((p) => p.x)));
|
|
168
|
-
const minX = Math.min(...boxes.map((b) => b.x));
|
|
169
|
-
const dx = minX < M ? M - minX : 0;
|
|
170
|
-
const r2 = (v) => Math.round(v * 2) / 2;
|
|
171
|
-
const mv = (b) => ({ x: r2(b.x + dx), y: r2(b.y), w: r2(b.w), h: r2(b.h) });
|
|
172
|
-
const mvAll = (o) => Object.fromEntries(Object.entries(o).map(([k2, b]) => [k2, mv(b)]));
|
|
173
|
-
return {
|
|
174
|
-
kind: 'sequence',
|
|
175
|
-
width: Math.ceil(maxX + dx + M),
|
|
176
|
-
height: Math.ceil(bottom + 6 + M),
|
|
177
|
-
actors: mvAll(actors),
|
|
178
|
-
lifelines: Object.fromEntries(Object.entries(lifelines).map(([k2, l]) => [k2, { x: r2(l.x + dx), y1: r2(l.y1), y2: r2(l.y2) }])),
|
|
179
|
-
messages: Object.fromEntries(Object.entries(messages).map(([k2, m]) => [k2, { ...m, points: m.points.map((p) => ({ x: r2(p.x + dx), y: r2(p.y) })), label: m.label ? mv(m.label) : null }])),
|
|
180
|
-
groups: mvAll(groups),
|
|
181
|
-
titles: mvAll(titles),
|
|
182
|
-
blocks: mvAll(blocks),
|
|
183
|
-
blockTitles: mvAll(blockTitles),
|
|
184
|
-
};
|
|
185
|
-
}
|