tavi-interaction-chain 0.0.0-stage → 0.2.2
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/chain.d.ts +42 -0
- package/dist/chain.js +163 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/topology.d.ts +28 -0
- package/dist/topology.js +392 -0
- package/dist/workflow-canvas.d.ts +20 -0
- package/dist/workflow-canvas.js +111 -0
- package/package.json +35 -4
- package/schema.json +101 -0
- package/skill/tavi-interaction-chain/SKILL.md +18 -0
- package/style.css +161 -0
- package/theme.css +86 -0
- package/topology.schema.json +88 -0
- package/README.md +0 -3
package/dist/chain.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export declare const MAX_CHAIN_STEPS = 40;
|
|
2
|
+
declare const kinds: readonly ["input", "plan", "tool", "question", "approval", "output", "notice"];
|
|
3
|
+
declare const states: readonly ["queued", "running", "waiting", "completed", "failed", "cancelled", "unknown"];
|
|
4
|
+
export type StepKind = typeof kinds[number];
|
|
5
|
+
export type StepStatus = typeof states[number];
|
|
6
|
+
export interface Choice {
|
|
7
|
+
id: string;
|
|
8
|
+
label: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ChainStep {
|
|
11
|
+
id: string;
|
|
12
|
+
kind: StepKind;
|
|
13
|
+
status: StepStatus;
|
|
14
|
+
label: string;
|
|
15
|
+
timestamp?: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
choices?: readonly Choice[];
|
|
18
|
+
}
|
|
19
|
+
export interface ChainSnapshot {
|
|
20
|
+
version: 1;
|
|
21
|
+
steps: readonly ChainStep[];
|
|
22
|
+
}
|
|
23
|
+
export interface ActionIntent {
|
|
24
|
+
stepId: string;
|
|
25
|
+
choiceId: string;
|
|
26
|
+
}
|
|
27
|
+
export interface ChainRenderOptions {
|
|
28
|
+
selectedId?: string;
|
|
29
|
+
onSelect: (step: ChainStep) => void;
|
|
30
|
+
}
|
|
31
|
+
export interface ChainActionOptions {
|
|
32
|
+
onAction?: (intent: ActionIntent) => Promise<void>;
|
|
33
|
+
readOnly?: boolean;
|
|
34
|
+
}
|
|
35
|
+
export declare const statusLabel: Record<StepStatus, string>;
|
|
36
|
+
export declare const kindLabel: Record<StepKind, string>;
|
|
37
|
+
/** Allowlist the display projection before it reaches the DOM. */
|
|
38
|
+
export declare function parseChain(input: unknown): ChainSnapshot;
|
|
39
|
+
/** Mount or update an ordered SVG chain with native controls and stable focus. */
|
|
40
|
+
export declare function renderChain(host: HTMLElement, snapshot: ChainSnapshot, options: ChainRenderOptions): void;
|
|
41
|
+
export declare function renderChainActions(host: HTMLElement, step: ChainStep, options: ChainActionOptions): void;
|
|
42
|
+
export {};
|
package/dist/chain.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
export const MAX_CHAIN_STEPS = 40;
|
|
2
|
+
const kinds = ['input', 'plan', 'tool', 'question', 'approval', 'output', 'notice'];
|
|
3
|
+
const states = ['queued', 'running', 'waiting', 'completed', 'failed', 'cancelled', 'unknown'];
|
|
4
|
+
export const statusLabel = {
|
|
5
|
+
queued: '待执行', running: '进行中', waiting: '等待处理', completed: '已完成',
|
|
6
|
+
failed: '失败', cancelled: '已取消', unknown: '状态未知',
|
|
7
|
+
};
|
|
8
|
+
export const kindLabel = {
|
|
9
|
+
input: '用户输入', plan: '计划', tool: '工具', question: '用户选择',
|
|
10
|
+
approval: '权限请求', output: '输出', notice: '提示',
|
|
11
|
+
};
|
|
12
|
+
function record(value) {
|
|
13
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
14
|
+
throw new TypeError('Expected an object');
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
function boundedString(value, min, max) {
|
|
18
|
+
if (typeof value !== 'string' || value.length < min || value.length > max * 2 || Array.from(value).length > max)
|
|
19
|
+
throw new TypeError('Invalid chain string');
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
function uniqueIds(items) {
|
|
23
|
+
if (new Set(items.map(item => item.id)).size !== items.length)
|
|
24
|
+
throw new TypeError('Duplicate chain ID');
|
|
25
|
+
}
|
|
26
|
+
/** Allowlist the display projection before it reaches the DOM. */
|
|
27
|
+
export function parseChain(input) {
|
|
28
|
+
const data = record(input);
|
|
29
|
+
if (data.version !== 1 || !Array.isArray(data.steps) || data.steps.length > MAX_CHAIN_STEPS)
|
|
30
|
+
throw new TypeError('Invalid chain snapshot');
|
|
31
|
+
const steps = data.steps.map((item) => {
|
|
32
|
+
const step = record(item);
|
|
33
|
+
const kind = kinds.find(kind => kind === step.kind);
|
|
34
|
+
const status = states.find(state => state === step.status);
|
|
35
|
+
if (!kind || !status)
|
|
36
|
+
throw new TypeError('Invalid chain kind or status');
|
|
37
|
+
const id = boundedString(step.id, 1, 256);
|
|
38
|
+
const label = boundedString(step.label, 1, 120);
|
|
39
|
+
const description = step.description === undefined ? undefined : boundedString(step.description, 0, 400);
|
|
40
|
+
let choices;
|
|
41
|
+
if (step.choices !== undefined) {
|
|
42
|
+
if (kind !== 'question' || !Array.isArray(step.choices) || step.choices.length > 6)
|
|
43
|
+
throw new TypeError('Invalid chain choices');
|
|
44
|
+
choices = step.choices.map((item) => {
|
|
45
|
+
const choice = record(item);
|
|
46
|
+
return { id: boundedString(choice.id, 1, 80), label: boundedString(choice.label, 1, 80) };
|
|
47
|
+
});
|
|
48
|
+
uniqueIds(choices);
|
|
49
|
+
}
|
|
50
|
+
const timestamp = step.timestamp;
|
|
51
|
+
if (timestamp !== undefined && (typeof timestamp !== 'string' || !/^\d{4}-\d\d-\d\dT.*(?:Z|[+-]\d\d:\d\d)$/.test(timestamp) || !Number.isFinite(Date.parse(timestamp))))
|
|
52
|
+
throw new TypeError('Invalid step timestamp');
|
|
53
|
+
return { id, kind, status, label, description, choices, timestamp };
|
|
54
|
+
});
|
|
55
|
+
uniqueIds(steps);
|
|
56
|
+
return { version: 1, steps };
|
|
57
|
+
}
|
|
58
|
+
const svgNS = 'http://www.w3.org/2000/svg';
|
|
59
|
+
const glyphs = {
|
|
60
|
+
input: 'M8 12h8m-8 4h5M6 6h12v14H6Z',
|
|
61
|
+
plan: 'm7 8 1 1 2-2m2 1h5m-10 5 1 1 2-2m2 1h5m-10 5 1 1 2-2m2 1h5',
|
|
62
|
+
tool: 'm9 8-4 4 4 4m6-8 4 4-4 4m-2-10-2 12',
|
|
63
|
+
question: 'M9 9a3 3 0 1 1 4 3c-1 .5-1 1-1 2m0 3v.1',
|
|
64
|
+
approval: 'M12 4 6 7v5c0 4 4 7 6 8 2-1 6-4 6-8V7Zm-3 8 2 2 4-4',
|
|
65
|
+
output: 'M6 6h12v12H6Zm3 6 2 2 4-4',
|
|
66
|
+
notice: 'M12 7v6m0 4v.1M12 3l9 17H3Z',
|
|
67
|
+
};
|
|
68
|
+
function element(doc, tag, css, text) {
|
|
69
|
+
const node = doc.createElement(tag);
|
|
70
|
+
node.className = css;
|
|
71
|
+
if (text !== undefined)
|
|
72
|
+
node.textContent = text;
|
|
73
|
+
return node;
|
|
74
|
+
}
|
|
75
|
+
function svg(doc, viewBox, css) {
|
|
76
|
+
const root = doc.createElementNS(svgNS, 'svg');
|
|
77
|
+
root.setAttribute('viewBox', viewBox);
|
|
78
|
+
root.setAttribute('class', css);
|
|
79
|
+
root.setAttribute('aria-hidden', 'true');
|
|
80
|
+
root.setAttribute('focusable', 'false');
|
|
81
|
+
return root;
|
|
82
|
+
}
|
|
83
|
+
function path(doc, parent, d) {
|
|
84
|
+
const child = doc.createElementNS(svgNS, 'path');
|
|
85
|
+
child.setAttribute('d', d);
|
|
86
|
+
parent.append(child);
|
|
87
|
+
}
|
|
88
|
+
function makeStep(doc, step, index, count, options) {
|
|
89
|
+
const row = element(doc, 'li', 'tavi-chain__step');
|
|
90
|
+
const rail = svg(doc, '0 0 32 100', 'tavi-chain__rail');
|
|
91
|
+
rail.setAttribute('preserveAspectRatio', 'none');
|
|
92
|
+
if (index > 0)
|
|
93
|
+
path(doc, rail, 'M16 0v50');
|
|
94
|
+
if (index < count - 1)
|
|
95
|
+
path(doc, rail, 'M16 50v50M12 92l4 8 4-8');
|
|
96
|
+
row.append(rail);
|
|
97
|
+
const button = element(doc, 'button', 'tavi-chain__node');
|
|
98
|
+
button.type = 'button';
|
|
99
|
+
button.dataset.chainId = step.id;
|
|
100
|
+
button.dataset.state = step.status;
|
|
101
|
+
button.setAttribute('aria-pressed', String(step.id === options.selectedId));
|
|
102
|
+
button.addEventListener('click', () => options.onSelect(step));
|
|
103
|
+
const icon = svg(doc, '0 0 24 24', 'tavi-chain__glyph');
|
|
104
|
+
path(doc, icon, glyphs[step.kind]);
|
|
105
|
+
const label = element(doc, 'span', 'tavi-chain__label');
|
|
106
|
+
label.append(element(doc, 'span', 'tavi-chain__kind', kindLabel[step.kind]), element(doc, 'strong', '', step.label));
|
|
107
|
+
button.append(icon, label, element(doc, 'span', 'tavi-chain__state', statusLabel[step.status]));
|
|
108
|
+
row.append(button);
|
|
109
|
+
return row;
|
|
110
|
+
}
|
|
111
|
+
/** Mount or update an ordered SVG chain with native controls and stable focus. */
|
|
112
|
+
export function renderChain(host, snapshot, options) {
|
|
113
|
+
const data = parseChain(snapshot);
|
|
114
|
+
const doc = host.ownerDocument;
|
|
115
|
+
const activeId = host.contains(doc.activeElement) ? doc.activeElement.dataset.chainId : undefined;
|
|
116
|
+
const list = element(doc, 'ol', 'tavi-chain');
|
|
117
|
+
list.setAttribute('role', 'list');
|
|
118
|
+
list.setAttribute('aria-label', '交互步骤');
|
|
119
|
+
const buttons = new Map();
|
|
120
|
+
for (const [index, step] of data.steps.entries()) {
|
|
121
|
+
const row = makeStep(doc, step, index, data.steps.length, options);
|
|
122
|
+
buttons.set(step.id, row.querySelector('button'));
|
|
123
|
+
list.append(row);
|
|
124
|
+
}
|
|
125
|
+
host.replaceChildren(data.steps.length ? list : element(doc, 'p', 'tavi-chain__empty', '当前没有可显示的步骤。'));
|
|
126
|
+
if (activeId)
|
|
127
|
+
(buttons.get(activeId) ?? buttons.values().next().value)?.focus({ preventScroll: true });
|
|
128
|
+
}
|
|
129
|
+
export function renderChainActions(host, step, options) {
|
|
130
|
+
const doc = host.ownerDocument;
|
|
131
|
+
host.replaceChildren();
|
|
132
|
+
const action = options.onAction;
|
|
133
|
+
if (!action || options.readOnly || step.kind !== 'question' || step.status !== 'waiting' || !step.choices?.length)
|
|
134
|
+
return;
|
|
135
|
+
const feedback = element(doc, 'p', 'tavi-chain__feedback');
|
|
136
|
+
feedback.setAttribute('role', 'status');
|
|
137
|
+
const group = element(doc, 'div', 'tavi-chain__actions');
|
|
138
|
+
const buttons = [];
|
|
139
|
+
let pending = false;
|
|
140
|
+
for (const choice of step.choices) {
|
|
141
|
+
const button = element(doc, 'button', 'tavi-chain__action', choice.label);
|
|
142
|
+
button.type = 'button';
|
|
143
|
+
button.addEventListener('click', async () => {
|
|
144
|
+
if (pending || !group.isConnected)
|
|
145
|
+
return;
|
|
146
|
+
pending = true;
|
|
147
|
+
for (const item of buttons)
|
|
148
|
+
item.setAttribute('aria-disabled', 'true');
|
|
149
|
+
feedback.textContent = '正在提交…';
|
|
150
|
+
try {
|
|
151
|
+
await action({ stepId: step.id, choiceId: choice.id });
|
|
152
|
+
feedback.textContent = '已提交,等待更新。';
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
feedback.textContent = '未收到成功确认,请刷新状态后再操作。';
|
|
156
|
+
// An ambiguous result must be reconciled by the host before a retry.
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
group.append(button);
|
|
160
|
+
buttons.push(button);
|
|
161
|
+
}
|
|
162
|
+
host.append(group, feedback);
|
|
163
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ChainSnapshot, type ChainStep } from './chain.js';
|
|
2
|
+
export type LinkKind = 'forward' | 'feedback' | 'control';
|
|
3
|
+
export interface TopologyNode extends ChainStep {
|
|
4
|
+
column: number;
|
|
5
|
+
lane?: 'main' | 'input';
|
|
6
|
+
slot?: 0 | 1 | 2;
|
|
7
|
+
channel?: string;
|
|
8
|
+
rateHz?: number;
|
|
9
|
+
}
|
|
10
|
+
export interface TopologyLink {
|
|
11
|
+
from: string;
|
|
12
|
+
to: string;
|
|
13
|
+
kind: LinkKind;
|
|
14
|
+
}
|
|
15
|
+
export interface TopologySnapshot {
|
|
16
|
+
version: 1;
|
|
17
|
+
nodes: readonly TopologyNode[];
|
|
18
|
+
links: readonly TopologyLink[];
|
|
19
|
+
}
|
|
20
|
+
export interface TopologyOptions {
|
|
21
|
+
selectedId?: string;
|
|
22
|
+
onSelect?: (node: TopologyNode) => void;
|
|
23
|
+
onPreview?: (node: TopologyNode | null) => void;
|
|
24
|
+
onClear?: () => void;
|
|
25
|
+
}
|
|
26
|
+
export declare function parseTopology(input: unknown): TopologySnapshot;
|
|
27
|
+
export declare function toTopology(snapshot: ChainSnapshot): TopologySnapshot;
|
|
28
|
+
export declare function renderTopology(host: HTMLElement, input: TopologySnapshot, options: TopologyOptions): void;
|
package/dist/topology.js
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { kindLabel, parseChain, statusLabel } from './chain.js';
|
|
2
|
+
const linkKinds = ['forward', 'feedback', 'control'];
|
|
3
|
+
export function parseTopology(input) {
|
|
4
|
+
if (!input || typeof input !== 'object')
|
|
5
|
+
throw new TypeError('Invalid topology');
|
|
6
|
+
const data = input;
|
|
7
|
+
if (data.version !== 1 || !Array.isArray(data.nodes) || !Array.isArray(data.links) || data.links.length > 80) {
|
|
8
|
+
throw new TypeError('Invalid topology snapshot');
|
|
9
|
+
}
|
|
10
|
+
const chain = parseChain({ version: data.version, steps: data.nodes });
|
|
11
|
+
const positions = new Set();
|
|
12
|
+
const nodes = chain.steps.map((step, index) => {
|
|
13
|
+
const { column, lane = 'main', slot = 0, channel, rateHz } = data.nodes[index];
|
|
14
|
+
if (!Number.isInteger(column) || column < 0 || column >= 40 || !['main', 'input'].includes(lane) ||
|
|
15
|
+
![0, 1, 2].includes(slot) || (lane === 'main' && slot !== 0) ||
|
|
16
|
+
(channel !== undefined && (typeof channel !== 'string' || channel.length > 160)) ||
|
|
17
|
+
(rateHz !== undefined && (typeof rateHz !== 'number' || !Number.isFinite(rateHz) || rateHz < 0))) {
|
|
18
|
+
throw new TypeError('Invalid topology node position or metadata');
|
|
19
|
+
}
|
|
20
|
+
const position = [column, lane, slot].join(':');
|
|
21
|
+
if (positions.has(position))
|
|
22
|
+
throw new TypeError('Overlapping topology nodes');
|
|
23
|
+
positions.add(position);
|
|
24
|
+
return { ...step, column, lane, slot, channel, rateHz };
|
|
25
|
+
});
|
|
26
|
+
const ids = new Set(nodes.map(node => node.id));
|
|
27
|
+
const edges = new Set();
|
|
28
|
+
const links = data.links.map((link) => {
|
|
29
|
+
if (!link || !ids.has(link.from) || !ids.has(link.to) || link.from === link.to || !linkKinds.includes(link.kind)) {
|
|
30
|
+
throw new TypeError('Invalid topology link');
|
|
31
|
+
}
|
|
32
|
+
const key = JSON.stringify([link.from, link.to, link.kind]);
|
|
33
|
+
if (edges.has(key))
|
|
34
|
+
throw new TypeError('Duplicate topology link');
|
|
35
|
+
edges.add(key);
|
|
36
|
+
return { from: link.from, to: link.to, kind: link.kind };
|
|
37
|
+
});
|
|
38
|
+
return { version: 1, nodes, links };
|
|
39
|
+
}
|
|
40
|
+
export function toTopology(snapshot) {
|
|
41
|
+
const { steps } = parseChain(snapshot);
|
|
42
|
+
return {
|
|
43
|
+
version: 1,
|
|
44
|
+
nodes: steps.map((step, column) => ({ ...step, column })),
|
|
45
|
+
links: steps.slice(1).map((step, index) => ({ from: steps[index].id, to: step.id, kind: 'forward' })),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const svgNS = 'http://www.w3.org/2000/svg';
|
|
49
|
+
const columnWidth = 224;
|
|
50
|
+
const nodeWidth = 192;
|
|
51
|
+
const inset = 18;
|
|
52
|
+
const inputWidth = 88;
|
|
53
|
+
const inputHeight = 39;
|
|
54
|
+
const mainHeight = 66;
|
|
55
|
+
let chartId = 0;
|
|
56
|
+
const centerX = (box) => box.x + box.w / 2;
|
|
57
|
+
const centerY = (box) => box.y + box.h / 2;
|
|
58
|
+
function nodeBox(node, mainY) {
|
|
59
|
+
const x = inset + node.column * columnWidth;
|
|
60
|
+
return node.lane === 'input'
|
|
61
|
+
? { x: x + (node.slot ?? 0) * (inputWidth + 11), y: 13, w: inputWidth, h: inputHeight }
|
|
62
|
+
: { x, y: mainY, w: nodeWidth, h: mainHeight };
|
|
63
|
+
}
|
|
64
|
+
function directLink(from, to, kind) {
|
|
65
|
+
return kind === 'forward' && from.lane !== 'input' && to.lane !== 'input' && from.column + 1 === to.column;
|
|
66
|
+
}
|
|
67
|
+
function edgePath(from, to, a, b, routeY, kind) {
|
|
68
|
+
if (from.lane === 'input' && to.lane !== 'input') {
|
|
69
|
+
const targetX = Math.max(b.x + 19, Math.min(b.x + b.w - 19, centerX(a)));
|
|
70
|
+
const y = (a.y + a.h + b.y) / 2;
|
|
71
|
+
return `M ${centerX(a)} ${a.y + a.h} V ${y} H ${targetX} V ${b.y}`;
|
|
72
|
+
}
|
|
73
|
+
if (from.lane !== 'input' && to.lane === 'input') {
|
|
74
|
+
const y = (b.y + b.h + a.y) / 2;
|
|
75
|
+
return `M ${centerX(a)} ${a.y} V ${y} H ${centerX(b)} V ${b.y + b.h}`;
|
|
76
|
+
}
|
|
77
|
+
if (from.lane === 'input' && to.lane === 'input') {
|
|
78
|
+
const y = a.y + a.h + 12;
|
|
79
|
+
return `M ${centerX(a)} ${a.y + a.h} V ${y} H ${centerX(b)} V ${b.y + b.h}`;
|
|
80
|
+
}
|
|
81
|
+
if (directLink(from, to, kind)) {
|
|
82
|
+
return `M ${a.x + a.w} ${centerY(a)} H ${b.x}`;
|
|
83
|
+
}
|
|
84
|
+
return `M ${centerX(a)} ${a.y + a.h} V ${routeY} H ${centerX(b)} V ${b.y + b.h}`;
|
|
85
|
+
}
|
|
86
|
+
function makeElement(doc, tag, css, text) {
|
|
87
|
+
const result = doc.createElement(tag);
|
|
88
|
+
result.className = css;
|
|
89
|
+
result.textContent = text ?? '';
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
function makeSvg(doc, tag, attributes) {
|
|
93
|
+
const result = doc.createElementNS(svgNS, tag);
|
|
94
|
+
for (const [name, value] of Object.entries(attributes))
|
|
95
|
+
result.setAttribute(name, value);
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
function addMousePan(view) {
|
|
99
|
+
let drag;
|
|
100
|
+
view.addEventListener('pointerdown', event => {
|
|
101
|
+
if (event.pointerType !== 'mouse' || event.button !== 0 || view.scrollWidth <= view.clientWidth ||
|
|
102
|
+
!(event.target instanceof Element) || !event.target.closest('.tavi-topology__canvas') || event.target.closest('button'))
|
|
103
|
+
return;
|
|
104
|
+
view.setPointerCapture(event.pointerId);
|
|
105
|
+
drag = { id: event.pointerId, x: event.clientX, offset: view.scrollLeft };
|
|
106
|
+
view.dataset.panning = 'true';
|
|
107
|
+
event.preventDefault();
|
|
108
|
+
});
|
|
109
|
+
view.addEventListener('pointermove', event => {
|
|
110
|
+
if (drag?.id === event.pointerId)
|
|
111
|
+
view.scrollLeft = drag.offset + drag.x - event.clientX;
|
|
112
|
+
});
|
|
113
|
+
const stop = (event) => {
|
|
114
|
+
if (drag?.id !== event.pointerId)
|
|
115
|
+
return;
|
|
116
|
+
drag = undefined;
|
|
117
|
+
delete view.dataset.panning;
|
|
118
|
+
};
|
|
119
|
+
view.addEventListener('pointerup', stop);
|
|
120
|
+
view.addEventListener('pointercancel', stop);
|
|
121
|
+
view.addEventListener('lostpointercapture', stop);
|
|
122
|
+
}
|
|
123
|
+
/** Draw typed SVG edges with native HTML nodes positioned on the same canvas. */
|
|
124
|
+
const observers = new WeakMap();
|
|
125
|
+
export function renderTopology(host, input, options) {
|
|
126
|
+
observers.get(host)?.disconnect();
|
|
127
|
+
const { nodes, links } = parseTopology(input);
|
|
128
|
+
const doc = host.ownerDocument;
|
|
129
|
+
if (!nodes.length) {
|
|
130
|
+
host.replaceChildren(makeElement(doc, 'p', 'tavi-chain__empty', '当前没有可显示的步骤。'));
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const previousScroll = host.querySelector('.tavi-topology')?.scrollLeft ?? 0;
|
|
134
|
+
const activeId = host.contains(doc.activeElement) ? doc.activeElement.dataset.chainId : undefined;
|
|
135
|
+
const view = makeElement(doc, 'div', 'tavi-topology');
|
|
136
|
+
view.setAttribute('role', 'group');
|
|
137
|
+
view.setAttribute('aria-label', '交互链路图');
|
|
138
|
+
addMousePan(view);
|
|
139
|
+
const canvas = makeElement(doc, 'div', 'tavi-topology__canvas');
|
|
140
|
+
const width = (Math.max(...nodes.map(node => node.column)) + 1) * columnWidth + inset * 2 - (columnWidth - nodeWidth);
|
|
141
|
+
const mainY = nodes.some(node => node.lane === 'input') ? 82 : 13;
|
|
142
|
+
const bottom = mainY + mainHeight;
|
|
143
|
+
const loops = links.filter(link => {
|
|
144
|
+
const from = nodes.find(node => node.id === link.from);
|
|
145
|
+
const to = nodes.find(node => node.id === link.to);
|
|
146
|
+
return from.lane !== 'input' && to.lane !== 'input' && !directLink(from, to, link.kind);
|
|
147
|
+
}).length;
|
|
148
|
+
const height = bottom + (loops ? 28 + Math.min(loops - 1, 3) * 10 : 13);
|
|
149
|
+
canvas.style.width = width + 'px';
|
|
150
|
+
canvas.style.height = height + 'px';
|
|
151
|
+
const svg = makeSvg(doc, 'svg', {
|
|
152
|
+
class: 'tavi-topology__edges', viewBox: `0 0 ${width} ${height}`, 'aria-hidden': 'true', focusable: 'false',
|
|
153
|
+
});
|
|
154
|
+
const defs = makeSvg(doc, 'defs', {});
|
|
155
|
+
const id = 'tavi-topology-arrow-' + (++chartId);
|
|
156
|
+
for (const kind of linkKinds) {
|
|
157
|
+
const marker = makeSvg(doc, 'marker', { id: id + '-' + kind, viewBox: '0 0 10 10', refX: '9.5', refY: '5', markerUnits: 'userSpaceOnUse', markerWidth: '10', markerHeight: '10', orient: 'auto-start-reverse' });
|
|
158
|
+
marker.append(makeSvg(doc, 'path', { d: 'M 0 0 L 10 5 L 0 10 z', class: `tavi-topology__arrow tavi-topology__arrow--${kind}` }));
|
|
159
|
+
defs.append(marker);
|
|
160
|
+
}
|
|
161
|
+
svg.append(defs);
|
|
162
|
+
let loop = 0;
|
|
163
|
+
const byId = new Map(nodes.map(node => [node.id, node]));
|
|
164
|
+
const boxes = new Map(nodes.map(node => [node.id, nodeBox(node, mainY)]));
|
|
165
|
+
const paths = links.map(link => {
|
|
166
|
+
const from = byId.get(link.from);
|
|
167
|
+
const to = byId.get(link.to);
|
|
168
|
+
const isLoop = from.lane !== 'input' && to.lane !== 'input' && !directLink(from, to, link.kind);
|
|
169
|
+
const path = makeSvg(doc, 'path', {
|
|
170
|
+
class: `tavi-topology__edge tavi-topology__edge--${link.kind}`,
|
|
171
|
+
d: edgePath(from, to, boxes.get(link.from), boxes.get(link.to), bottom + 13 + (isLoop ? (loop++ % 4) * 10 : 0), link.kind),
|
|
172
|
+
'marker-end': `url(#${id}-${link.kind})`,
|
|
173
|
+
});
|
|
174
|
+
svg.append(path);
|
|
175
|
+
return { link, path };
|
|
176
|
+
});
|
|
177
|
+
canvas.append(svg);
|
|
178
|
+
const buttons = new Map();
|
|
179
|
+
let selected = options.selectedId;
|
|
180
|
+
let hovered;
|
|
181
|
+
let focused;
|
|
182
|
+
const paint = () => {
|
|
183
|
+
const inspection = hovered ?? focused;
|
|
184
|
+
const highlight = inspection ?? selected;
|
|
185
|
+
for (const { link, path } of paths) {
|
|
186
|
+
const related = link.from === highlight || link.to === highlight;
|
|
187
|
+
path.classList.toggle('is-related', !!highlight && related);
|
|
188
|
+
path.classList.toggle('is-dimmed', !!highlight && !related);
|
|
189
|
+
}
|
|
190
|
+
if (options.onSelect)
|
|
191
|
+
for (const [id, button] of buttons)
|
|
192
|
+
button.setAttribute('aria-pressed', String(selected === id));
|
|
193
|
+
options.onPreview?.(inspection ? byId.get(inspection) ?? null : null);
|
|
194
|
+
};
|
|
195
|
+
for (const node of nodes) {
|
|
196
|
+
const box = boxes.get(node.id);
|
|
197
|
+
const button = makeElement(doc, 'button', 'tavi-chain__node tavi-topology__node');
|
|
198
|
+
button.type = 'button';
|
|
199
|
+
button.dataset.chainId = node.id;
|
|
200
|
+
button.dataset.state = node.status;
|
|
201
|
+
button.dataset.lane = node.lane ?? 'main';
|
|
202
|
+
button.dataset.kind = node.kind;
|
|
203
|
+
button.style.left = box.x + 'px';
|
|
204
|
+
button.style.top = box.y + 'px';
|
|
205
|
+
button.style.width = box.w + 'px';
|
|
206
|
+
button.style.height = box.h + 'px';
|
|
207
|
+
const label = makeElement(doc, 'strong', 'tavi-topology__name', node.label);
|
|
208
|
+
const info = makeElement(doc, 'span', 'tavi-topology__meta', statusLabel[node.status]);
|
|
209
|
+
button.append(label, info);
|
|
210
|
+
if (node.timestamp) {
|
|
211
|
+
const date = new Date(node.timestamp);
|
|
212
|
+
const role = node.kind === 'output' ? '助手' : kindLabel[node.kind];
|
|
213
|
+
const time = makeElement(doc, 'time', 'tavi-topology__channel', [String(node.column + 1).padStart(2, '0'), role, date.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit', hour12: false })].join(' · '));
|
|
214
|
+
time.dateTime = node.timestamp;
|
|
215
|
+
time.title = date.toLocaleString('zh-CN');
|
|
216
|
+
button.append(time);
|
|
217
|
+
}
|
|
218
|
+
if (node.rateHz !== undefined)
|
|
219
|
+
info.title = node.rateHz + ' Hz';
|
|
220
|
+
if (node.channel)
|
|
221
|
+
button.append(makeElement(doc, 'span', 'tavi-topology__channel', node.channel));
|
|
222
|
+
button.addEventListener('pointerenter', event => {
|
|
223
|
+
if (event.pointerType === 'touch')
|
|
224
|
+
return;
|
|
225
|
+
hovered = node.id;
|
|
226
|
+
paint();
|
|
227
|
+
});
|
|
228
|
+
button.addEventListener('pointerleave', () => {
|
|
229
|
+
if (hovered === node.id)
|
|
230
|
+
hovered = undefined;
|
|
231
|
+
paint();
|
|
232
|
+
});
|
|
233
|
+
button.addEventListener('focus', () => {
|
|
234
|
+
if (button.matches(':focus-visible'))
|
|
235
|
+
focused = node.id;
|
|
236
|
+
paint();
|
|
237
|
+
});
|
|
238
|
+
button.addEventListener('blur', () => {
|
|
239
|
+
if (focused === node.id)
|
|
240
|
+
focused = undefined;
|
|
241
|
+
paint();
|
|
242
|
+
});
|
|
243
|
+
if (options.onSelect)
|
|
244
|
+
button.addEventListener('click', () => {
|
|
245
|
+
selected = node.id;
|
|
246
|
+
paint();
|
|
247
|
+
options.onSelect?.(node);
|
|
248
|
+
});
|
|
249
|
+
buttons.set(node.id, button);
|
|
250
|
+
canvas.append(button);
|
|
251
|
+
}
|
|
252
|
+
view.addEventListener('keydown', event => {
|
|
253
|
+
if (event.key !== 'Escape' || !options.onClear || !(selected || hovered || focused))
|
|
254
|
+
return;
|
|
255
|
+
event.preventDefault();
|
|
256
|
+
event.stopPropagation();
|
|
257
|
+
selected = hovered = focused = undefined;
|
|
258
|
+
paint();
|
|
259
|
+
options.onClear();
|
|
260
|
+
});
|
|
261
|
+
view.append(canvas);
|
|
262
|
+
host.replaceChildren(view);
|
|
263
|
+
// Only ordered session chains can reflow. Explicit topology owns its lane coordinates.
|
|
264
|
+
const main = nodes.filter(n => n.lane !== 'input');
|
|
265
|
+
const branches = nodes.filter(n => n.lane === 'input');
|
|
266
|
+
const primaryLinks = links.filter(link => byId.get(link.from)?.lane !== 'input');
|
|
267
|
+
const ordered = main.every((n, i) => n.column === i)
|
|
268
|
+
&& primaryLinks.length === main.length - 1
|
|
269
|
+
&& primaryLinks.every((link, i) => link.kind === 'forward' && link.from === main[i].id && link.to === main[i + 1].id)
|
|
270
|
+
&& branches.every(n => links.some(l => l.from === n.id && l.to === main[n.column]?.id))
|
|
271
|
+
&& links.every(l => byId.get(l.from)?.lane !== 'input' || main[byId.get(l.from).column]?.id === l.to);
|
|
272
|
+
if (ordered) {
|
|
273
|
+
const offsets = new Map();
|
|
274
|
+
const draggable = host.dataset.draggable === 'true';
|
|
275
|
+
const layout = () => {
|
|
276
|
+
const available = view.offsetWidth - 2 * view.clientLeft;
|
|
277
|
+
if (!available)
|
|
278
|
+
return;
|
|
279
|
+
const gap = 22, margin = 12;
|
|
280
|
+
const minWidth = branches.length ? 214 : 148;
|
|
281
|
+
const inner = Math.max(1, available - 2 * margin);
|
|
282
|
+
const columns = Math.min(main.length, Math.max(1, Math.floor((available - 2 * margin + gap) / (minWidth + gap))));
|
|
283
|
+
const w = (inner - (columns - 1) * gap) / columns;
|
|
284
|
+
const headroom = branches.length ? 51 : 0;
|
|
285
|
+
const rowHeight = mainHeight + headroom + 32;
|
|
286
|
+
const h = Math.ceil(main.length / columns) * rowHeight + (draggable ? 160 : 0);
|
|
287
|
+
const topInset = (h - ((Math.ceil(main.length / columns) - 1) * rowHeight + headroom + mainHeight)) / 2;
|
|
288
|
+
canvas.style.width = available + 'px';
|
|
289
|
+
view.dataset.responsive = 'true';
|
|
290
|
+
view.style.boxSizing = 'content-box';
|
|
291
|
+
view.style.height = h + 'px';
|
|
292
|
+
canvas.style.height = h + 'px';
|
|
293
|
+
svg.setAttribute('viewBox', '0 0 ' + available + ' ' + h);
|
|
294
|
+
for (const n of nodes) {
|
|
295
|
+
const row = Math.floor(n.column / columns);
|
|
296
|
+
const col = row % 2 ? columns - 1 - n.column % columns : n.column % columns;
|
|
297
|
+
const x = margin + col * (w + gap), y = topInset + row * rowHeight;
|
|
298
|
+
const siblings = branches.filter(b => b.column === n.column).sort((a, b) => a.slot - b.slot);
|
|
299
|
+
const small = (w - 4 * (siblings.length - 1)) / Math.max(1, siblings.length);
|
|
300
|
+
const stageWidth = draggable ? Math.min(w, (w - 20) * 2 / 3 + 24) : w - 20;
|
|
301
|
+
const box = n.lane === 'input'
|
|
302
|
+
? { x: x + siblings.indexOf(n) * (small + 4), y, w: small, h: 27 }
|
|
303
|
+
: { x: x + (w - stageWidth) / 2, y: y + headroom, w: stageWidth, h: mainHeight };
|
|
304
|
+
const offset = offsets.get(n.id);
|
|
305
|
+
if (offset) {
|
|
306
|
+
offset.x = Math.max(-box.x, Math.min(available - box.x - box.w, offset.x));
|
|
307
|
+
box.x += offset.x;
|
|
308
|
+
offset.y = Math.max(-box.y, Math.min(h - box.y - box.h, offset.y));
|
|
309
|
+
box.y += offset.y;
|
|
310
|
+
}
|
|
311
|
+
buttons.get(n.id).style.minHeight = box.h + 'px';
|
|
312
|
+
boxes.set(n.id, box);
|
|
313
|
+
Object.assign(buttons.get(n.id).style, { left: box.x + 'px', top: box.y + 'px', width: box.w + 'px', height: box.h + 'px' });
|
|
314
|
+
}
|
|
315
|
+
for (const { path, link } of paths) {
|
|
316
|
+
const a = boxes.get(link.from), b = boxes.get(link.to);
|
|
317
|
+
let d;
|
|
318
|
+
if (byId.get(link.from).lane === 'input') {
|
|
319
|
+
const end = Math.max(b.x + 5, Math.min(b.x + b.w - 5, centerX(a) + (centerX(b) - centerX(a)) * 0.3));
|
|
320
|
+
d = 'M ' + centerX(a) + ' ' + (a.y + a.h) + ' Q ' + centerX(a) + ' ' + (b.y - 8) + ' ' + end + ' ' + b.y;
|
|
321
|
+
}
|
|
322
|
+
else if (a.y !== b.y && (offsets.has(link.from) || offsets.has(link.to))) {
|
|
323
|
+
const right = centerX(b) >= centerX(a);
|
|
324
|
+
const start = a.x + (right ? a.w : 0), end = b.x + (right ? 0 : b.w);
|
|
325
|
+
const mid = (start + end) / 2;
|
|
326
|
+
d = 'M ' + start + ' ' + centerY(a) + ' C ' + mid + ' ' + centerY(a) + ' ' + mid + ' ' + centerY(b) + ' ' + end + ' ' + centerY(b);
|
|
327
|
+
}
|
|
328
|
+
else if (a.y !== b.y) {
|
|
329
|
+
const right = Math.floor(byId.get(link.from).column / columns) % 2 === 0;
|
|
330
|
+
const side = a.x + (right ? a.w : 0);
|
|
331
|
+
d = 'M ' + side + ' ' + centerY(a) + ' h ' + (right ? 8 : -8) + ' V ' + centerY(b) + ' H ' + side;
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
d = 'M ' + (a.x + (b.x > a.x ? a.w : 0)) + ' ' + centerY(a) + ' H ' + (b.x + (b.x > a.x ? 0 : b.w));
|
|
335
|
+
}
|
|
336
|
+
path.setAttribute('d', d);
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
if (draggable)
|
|
340
|
+
for (const stage of nodes) {
|
|
341
|
+
const id = stage.id;
|
|
342
|
+
const button = buttons.get(id);
|
|
343
|
+
let drag;
|
|
344
|
+
let moved = false;
|
|
345
|
+
button.addEventListener('pointerdown', e => {
|
|
346
|
+
if (!e.isPrimary || e.button !== 0)
|
|
347
|
+
return;
|
|
348
|
+
moved = false;
|
|
349
|
+
drag = { pointer: e.pointerId, x: e.clientX, y: e.clientY };
|
|
350
|
+
button.setPointerCapture(e.pointerId);
|
|
351
|
+
});
|
|
352
|
+
button.addEventListener('pointermove', e => {
|
|
353
|
+
if (!drag || drag.pointer !== e.pointerId)
|
|
354
|
+
return;
|
|
355
|
+
const scale = canvas.getBoundingClientRect().width / canvas.offsetWidth || 1;
|
|
356
|
+
const dx = (e.clientX - drag.x) / scale, dy = (e.clientY - drag.y) / scale;
|
|
357
|
+
if (!moved && Math.hypot(dx, dy) < 3)
|
|
358
|
+
return;
|
|
359
|
+
moved = true;
|
|
360
|
+
const members = stage.lane === 'input' ? [stage] : nodes.filter(n => n.column === stage.column);
|
|
361
|
+
const group = members.map(n => boxes.get(n.id));
|
|
362
|
+
const shiftX = Math.max(-Math.min(...group.map(b => b.x)), Math.min(canvas.clientWidth - Math.max(...group.map(b => b.x + b.w)), dx));
|
|
363
|
+
const shiftY = Math.max(-Math.min(...group.map(b => b.y)), Math.min(canvas.clientHeight - Math.max(...group.map(b => b.y + b.h)), dy));
|
|
364
|
+
for (const member of members) {
|
|
365
|
+
const prior = offsets.get(member.id) ?? { x: 0, y: 0 };
|
|
366
|
+
offsets.set(member.id, { x: prior.x + shiftX, y: prior.y + shiftY });
|
|
367
|
+
}
|
|
368
|
+
drag.x = e.clientX;
|
|
369
|
+
drag.y = e.clientY;
|
|
370
|
+
layout();
|
|
371
|
+
});
|
|
372
|
+
button.addEventListener('lostpointercapture', () => { drag = undefined; });
|
|
373
|
+
button.addEventListener('click', e => {
|
|
374
|
+
if (moved && e.detail) {
|
|
375
|
+
e.stopImmediatePropagation();
|
|
376
|
+
moved = false;
|
|
377
|
+
}
|
|
378
|
+
}, true);
|
|
379
|
+
}
|
|
380
|
+
layout();
|
|
381
|
+
view.addEventListener('tavi-scale-change', layout);
|
|
382
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
383
|
+
const observer = new ResizeObserver(layout);
|
|
384
|
+
observer.observe(view);
|
|
385
|
+
observers.set(host, observer);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
view.scrollLeft = previousScroll;
|
|
389
|
+
paint();
|
|
390
|
+
if (activeId)
|
|
391
|
+
(buttons.get(activeId) ?? buttons.values().next().value)?.focus({ preventScroll: true });
|
|
392
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type TopologyNode, type TopologySnapshot } from './topology.js';
|
|
2
|
+
export interface WorkflowCanvasConfig {
|
|
3
|
+
/** Omit to inherit the host palette. Requires theme.css for explicit modes. */
|
|
4
|
+
theme?: 'light' | 'dark';
|
|
5
|
+
graph: TopologySnapshot;
|
|
6
|
+
/** Per-node overrides keyed by stable node ID. */
|
|
7
|
+
copy?: Record<string, {
|
|
8
|
+
label?: string;
|
|
9
|
+
channel?: string;
|
|
10
|
+
tooltip?: string;
|
|
11
|
+
}>;
|
|
12
|
+
draggable?: boolean;
|
|
13
|
+
/** Show input-lane cards and their connections. Defaults to true. */
|
|
14
|
+
showChildCards?: boolean;
|
|
15
|
+
zoom?: boolean;
|
|
16
|
+
/** Omit to render only the canvas. The host owns the detail view. */
|
|
17
|
+
onDetail?: (node: TopologyNode) => void;
|
|
18
|
+
}
|
|
19
|
+
/** Mount or update a canvas. Dispose before unmounting the host. */
|
|
20
|
+
export declare function renderWorkflowCanvas(host: HTMLElement, config: WorkflowCanvasConfig): () => void;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { renderTopology } from './topology.js';
|
|
2
|
+
/** Mount or update a canvas. Dispose before unmounting the host. */
|
|
3
|
+
export function renderWorkflowCanvas(host, config) {
|
|
4
|
+
mounts.get(host)?.();
|
|
5
|
+
if (config.theme)
|
|
6
|
+
host.dataset.workflowTheme = config.theme;
|
|
7
|
+
const controller = new AbortController();
|
|
8
|
+
const options = { signal: controller.signal };
|
|
9
|
+
const hidden = new Set(config.showChildCards === false
|
|
10
|
+
? config.graph.nodes.filter(node => node.lane === 'input').map(node => node.id)
|
|
11
|
+
: []);
|
|
12
|
+
const graph = { ...config.graph,
|
|
13
|
+
links: config.graph.links.filter(link => !hidden.has(link.from) && !hidden.has(link.to)),
|
|
14
|
+
nodes: config.graph.nodes.filter(node => !hidden.has(node.id)).map(node => {
|
|
15
|
+
const copy = config.copy?.[node.id];
|
|
16
|
+
return { ...node, label: copy?.label ?? node.label, channel: copy?.channel ?? node.channel };
|
|
17
|
+
}) };
|
|
18
|
+
host.dataset.draggable = String(config.draggable ?? true);
|
|
19
|
+
renderTopology(host, graph, { onPreview: node => { if (node)
|
|
20
|
+
config.onDetail?.(node); } });
|
|
21
|
+
const tip = document.createElement('span');
|
|
22
|
+
tip.className = 'tavi-workflow-tip';
|
|
23
|
+
tip.setAttribute('role', 'tooltip');
|
|
24
|
+
tip.hidden = true;
|
|
25
|
+
host.append(tip);
|
|
26
|
+
const buttons = host.querySelectorAll('[data-chain-id]');
|
|
27
|
+
const hide = () => { tip.hidden = true; };
|
|
28
|
+
for (const button of buttons) {
|
|
29
|
+
const message = config.copy?.[button.dataset.chainId]?.tooltip;
|
|
30
|
+
if (!message)
|
|
31
|
+
continue;
|
|
32
|
+
const show = (x, y) => {
|
|
33
|
+
tip.textContent = message;
|
|
34
|
+
tip.hidden = false;
|
|
35
|
+
tip.style.left = Math.max(8, x + 14 + tip.offsetWidth <= innerWidth - 8 ? x + 14 : x - tip.offsetWidth - 14) + 'px';
|
|
36
|
+
tip.style.top = Math.max(8, y + 18 + tip.offsetHeight <= innerHeight - 8 ? y + 18 : y - tip.offsetHeight - 12) + 'px';
|
|
37
|
+
};
|
|
38
|
+
button.addEventListener('pointermove', e => {
|
|
39
|
+
if (e.buttons || e.pointerType === 'touch')
|
|
40
|
+
return hide();
|
|
41
|
+
show(e.clientX, e.clientY);
|
|
42
|
+
}, options);
|
|
43
|
+
button.addEventListener('focus', () => {
|
|
44
|
+
if (button.matches(':focus-visible')) {
|
|
45
|
+
const rect = button.getBoundingClientRect();
|
|
46
|
+
show(rect.left + rect.width / 2, rect.bottom);
|
|
47
|
+
}
|
|
48
|
+
}, options);
|
|
49
|
+
button.addEventListener('blur', hide, options);
|
|
50
|
+
button.addEventListener('pointerleave', hide, options);
|
|
51
|
+
}
|
|
52
|
+
host.addEventListener('pointerdown', hide, options);
|
|
53
|
+
host.addEventListener('keydown', e => { if (e.key === 'Escape')
|
|
54
|
+
hide(); }, options);
|
|
55
|
+
if (config.zoom !== false) {
|
|
56
|
+
let scale = 1;
|
|
57
|
+
const tools = document.createElement('div');
|
|
58
|
+
tools.className = 'tavi-zoom-tools';
|
|
59
|
+
tools.setAttribute('role', 'group');
|
|
60
|
+
tools.setAttribute('aria-label', '画布缩放');
|
|
61
|
+
const percent = document.createElement('span');
|
|
62
|
+
function button(icon, label, action) {
|
|
63
|
+
const item = document.createElement('button');
|
|
64
|
+
item.type = 'button';
|
|
65
|
+
item.textContent = icon;
|
|
66
|
+
item.title = label;
|
|
67
|
+
item.setAttribute('aria-label', label);
|
|
68
|
+
item.addEventListener('click', action, options);
|
|
69
|
+
return item;
|
|
70
|
+
}
|
|
71
|
+
const minus = button('−', '缩小画布', () => apply(scale - .25));
|
|
72
|
+
const plus = button('+', '放大画布', () => apply(scale + .25));
|
|
73
|
+
const reset = button('↺', '恢复原始尺寸', () => apply(1));
|
|
74
|
+
tools.append(minus, percent, plus, reset);
|
|
75
|
+
host.append(tools);
|
|
76
|
+
function apply(value) {
|
|
77
|
+
scale = Math.max(.5, Math.min(2, value));
|
|
78
|
+
if (Math.round(scale * 100) === 100)
|
|
79
|
+
scale = 1;
|
|
80
|
+
host.dataset.canvasFits = String(scale <= 1);
|
|
81
|
+
host.style.setProperty('--canvas-scale', String(scale));
|
|
82
|
+
host.querySelector('.tavi-topology')?.dispatchEvent(new Event('tavi-scale-change'));
|
|
83
|
+
percent.textContent = Math.round(scale * 100) + '%';
|
|
84
|
+
minus.disabled = scale <= .5;
|
|
85
|
+
plus.disabled = scale >= 2;
|
|
86
|
+
hide();
|
|
87
|
+
}
|
|
88
|
+
apply(1);
|
|
89
|
+
host.addEventListener('wheel', e => {
|
|
90
|
+
if (!e.deltaY)
|
|
91
|
+
return;
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
const unit = e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? innerHeight : 1;
|
|
94
|
+
apply(scale * Math.exp(-e.deltaY * unit * .002));
|
|
95
|
+
}, { ...options, passive: false });
|
|
96
|
+
}
|
|
97
|
+
const dispose = () => {
|
|
98
|
+
if (mounts.get(host) !== dispose)
|
|
99
|
+
return;
|
|
100
|
+
controller.abort();
|
|
101
|
+
renderTopology(host, { version: 1, nodes: [], links: [] }, {});
|
|
102
|
+
host.replaceChildren();
|
|
103
|
+
host.style.removeProperty('--canvas-scale');
|
|
104
|
+
delete host.dataset.canvasFits;
|
|
105
|
+
delete host.dataset.workflowTheme;
|
|
106
|
+
mounts.delete(host);
|
|
107
|
+
};
|
|
108
|
+
mounts.set(host, dispose);
|
|
109
|
+
return dispose;
|
|
110
|
+
}
|
|
111
|
+
const mounts = new WeakMap();
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tavi-interaction-chain",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Framework-independent SVG interaction chains for Tavi",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./style.css": "./style.css",
|
|
12
|
+
"./theme.css": "./theme.css",
|
|
13
|
+
"./schema.json": "./schema.json",
|
|
14
|
+
"./topology.schema.json": "./topology.schema.json"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"style.css",
|
|
19
|
+
"theme.css",
|
|
20
|
+
"schema.json",
|
|
21
|
+
"topology.schema.json",
|
|
22
|
+
"skill"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc -p tsconfig.json",
|
|
26
|
+
"test": "npm run build && tsc -p demo/tsconfig.json && node --test test/*.test.mjs",
|
|
27
|
+
"prepack": "npm run build",
|
|
28
|
+
"dev": "vite --open /demo/",
|
|
29
|
+
"prepublishOnly": "npm test"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"dompurify": "^3.5.0",
|
|
33
|
+
"marked": "^18.3.0",
|
|
34
|
+
"typescript": "^5.9.3",
|
|
35
|
+
"vite": "^6.4.6"
|
|
36
|
+
}
|
|
37
|
+
}
|
package/schema.json
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"title": "Tavi interaction chain v1",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"required": [
|
|
6
|
+
"version",
|
|
7
|
+
"steps"
|
|
8
|
+
],
|
|
9
|
+
"properties": {
|
|
10
|
+
"version": {
|
|
11
|
+
"const": 1
|
|
12
|
+
},
|
|
13
|
+
"steps": {
|
|
14
|
+
"type": "array",
|
|
15
|
+
"maxItems": 40,
|
|
16
|
+
"items": {
|
|
17
|
+
"type": "object",
|
|
18
|
+
"required": [
|
|
19
|
+
"id",
|
|
20
|
+
"kind",
|
|
21
|
+
"status",
|
|
22
|
+
"label"
|
|
23
|
+
],
|
|
24
|
+
"properties": {
|
|
25
|
+
"id": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"minLength": 1,
|
|
28
|
+
"maxLength": 256
|
|
29
|
+
},
|
|
30
|
+
"kind": {
|
|
31
|
+
"enum": [
|
|
32
|
+
"input",
|
|
33
|
+
"plan",
|
|
34
|
+
"tool",
|
|
35
|
+
"question",
|
|
36
|
+
"approval",
|
|
37
|
+
"output",
|
|
38
|
+
"notice"
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
"status": {
|
|
42
|
+
"enum": [
|
|
43
|
+
"queued",
|
|
44
|
+
"running",
|
|
45
|
+
"waiting",
|
|
46
|
+
"completed",
|
|
47
|
+
"failed",
|
|
48
|
+
"cancelled",
|
|
49
|
+
"unknown"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
"label": {
|
|
53
|
+
"type": "string",
|
|
54
|
+
"minLength": 1,
|
|
55
|
+
"maxLength": 120
|
|
56
|
+
},
|
|
57
|
+
"timestamp": {"type":"string","format":"date-time"},
|
|
58
|
+
"description": {
|
|
59
|
+
"type": "string",
|
|
60
|
+
"maxLength": 400
|
|
61
|
+
},
|
|
62
|
+
"choices": {
|
|
63
|
+
"type": "array",
|
|
64
|
+
"maxItems": 6,
|
|
65
|
+
"items": {
|
|
66
|
+
"type": "object",
|
|
67
|
+
"required": [
|
|
68
|
+
"id",
|
|
69
|
+
"label"
|
|
70
|
+
],
|
|
71
|
+
"properties": {
|
|
72
|
+
"id": {
|
|
73
|
+
"type": "string",
|
|
74
|
+
"minLength": 1,
|
|
75
|
+
"maxLength": 80
|
|
76
|
+
},
|
|
77
|
+
"label": {
|
|
78
|
+
"type": "string",
|
|
79
|
+
"minLength": 1,
|
|
80
|
+
"maxLength": 80
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"if": {
|
|
87
|
+
"required": [
|
|
88
|
+
"choices"
|
|
89
|
+
]
|
|
90
|
+
},
|
|
91
|
+
"then": {
|
|
92
|
+
"properties": {
|
|
93
|
+
"kind": {
|
|
94
|
+
"const": "question"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: tavi-interaction-chain
|
|
3
|
+
description: 生成或接入 Tavi 的链式可交互 SVG,用于把会话、工具、等待选择和结果投影为可点选的步骤。适用于扩展桌面执行轨迹、Playground 和自有 Tavi 生态视图。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Tavi 交互链
|
|
7
|
+
|
|
8
|
+
已有 Tavi 桌面源码时,先参考 `docs/interaction-chain.md` 与 `app/renderer/interaction-chain.ts`。生态或 Web 宿主使用 `tavi-interaction-chain`,导入 `tavi-interaction-chain/style.css`。包同时提供 `tavi-interaction-chain/schema.json` 和运行时解析函数 `parseChain`。
|
|
9
|
+
|
|
10
|
+
1. 使用宿主已授权的事件投影生成 `{version: 1, steps}`。每一步包含稳定的 `id`、`kind`、`status`、简短的 `label` 和可选 `description`。使用真实事件顺序,正在执行、完成、失败、取消与未知分别映射。单次最多展示 40 步。
|
|
11
|
+
2. 横向图调用 `renderTopology(host, toTopology(snapshot), {selectedId, onSelect, onPreview})`。生态拓扑用 `tavi-interaction-chain/topology.schema.json` 显式声明列、主链/输入位置和 `forward`、`feedback`、`control` 连线。悬停预览详情,点击固定详情或打开宿主已有记录。保留原有工具详情、提问和审批入口。
|
|
12
|
+
3. 只有宿主提供有效待处理问题时,向对应 question 步骤传入 `choices: [{id, label}]` 并调用 `renderChainActions`。提交回调获得 `{stepId, choiceId}`,由宿主复核会话归属、请求 ID、授权和时效,并交给现有问答入口。历史、只读与审批节点保持查看模式。成功或失败由权威快照更新,含糊回执先对账。
|
|
13
|
+
4. 使用本地夹具验证键盘选中、点击查看、两种选择得到不同结果、重复提交保护,以及历史或只读场景缺少执行入口。多次工具更新应归并到同一节点。
|
|
14
|
+
|
|
15
|
+
数据值使用纯文本。快照中的字段不能携带任意 HTML、SVG、脚本、URL、命令或凭据。需要图内审批时先厘清宿主已有授权和交互契约。
|
|
16
|
+
|
|
17
|
+
### 通用画布(0.2.1)
|
|
18
|
+
宿主先加载 tavi-interaction-chain/style.css,再通过包主入口调用 renderWorkflowCanvas(host, config)。config.graph 提供节点与边;config.copy 以节点 ID 为键,可覆盖 label、channel 和 tooltip。只需画布时省略 onDetail;需要自定义详情时传入 onDetail(node),在宿主自己的区域展示业务字段。zoom 默认为 true,滚轮缩放范围 50%–200%;draggable 控制主卡整组拖动。卸载宿主前调用返回的清理函数。
|
package/style.css
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
.tavi-chain {
|
|
2
|
+
--tc-line: var(--tavi-chain-line, #c9d4e2);
|
|
3
|
+
--tc-surface: var(--tavi-chain-surface, #f7faff);
|
|
4
|
+
--tc-text: var(--tavi-chain-text, #172b43);
|
|
5
|
+
--tc-muted: var(--tavi-chain-muted, #49647f);
|
|
6
|
+
--tc-accent: var(--tavi-chain-accent, #205ec7);
|
|
7
|
+
display: grid;
|
|
8
|
+
padding: 0;
|
|
9
|
+
margin: 0;
|
|
10
|
+
min-width: 0;
|
|
11
|
+
list-style: none;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.tavi-chain__step {
|
|
15
|
+
position: relative;
|
|
16
|
+
min-width: 0;
|
|
17
|
+
padding: 5px 3px 5px 19px;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.tavi-chain__rail {
|
|
21
|
+
position: absolute;
|
|
22
|
+
inset: 0 auto 0 0;
|
|
23
|
+
width: 32px;
|
|
24
|
+
height: 100%;
|
|
25
|
+
fill: none;
|
|
26
|
+
stroke: var(--tc-line);
|
|
27
|
+
pointer-events: none;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.tavi-chain__rail path { vector-effect: non-scaling-stroke; }
|
|
31
|
+
|
|
32
|
+
.tavi-chain__node {
|
|
33
|
+
position: relative;
|
|
34
|
+
width: 100%;
|
|
35
|
+
min-height: 53px;
|
|
36
|
+
display: grid;
|
|
37
|
+
grid-template-columns: 27px minmax(0, 1fr) auto;
|
|
38
|
+
gap: 9px;
|
|
39
|
+
align-items: center;
|
|
40
|
+
padding: 7px 9px;
|
|
41
|
+
border: 1px solid var(--tc-line);
|
|
42
|
+
border-radius: var(--tavi-chain-radius, 8px);
|
|
43
|
+
color: var(--tc-text);
|
|
44
|
+
background: var(--tc-surface);
|
|
45
|
+
text-align: left;
|
|
46
|
+
font: inherit;
|
|
47
|
+
cursor: pointer;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.tavi-chain__node:hover, .tavi-chain__node[aria-pressed="true"] { border-color: var(--tc-accent); }
|
|
51
|
+
.tavi-chain > .tavi-chain__step > .tavi-chain__node:hover { background: var(--tavi-chain-hover, var(--tc-surface)); }
|
|
52
|
+
.tavi-chain > .tavi-chain__step > .tavi-chain__node[aria-pressed="true"] { background: var(--tavi-chain-selected, var(--tc-surface)); box-shadow: inset 3px 0 var(--tc-accent); }
|
|
53
|
+
.tavi-chain__node:focus-visible, .tavi-chain__action:focus-visible { outline: 2px solid var(--tavi-chain-focus, var(--tavi-chain-accent, #205ec7)); outline-offset: 2px; }
|
|
54
|
+
.tavi-chain__glyph { width: 25px; height: 25px; fill: none; stroke: var(--tc-accent); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
|
|
55
|
+
.tavi-chain__label, .tavi-chain__label strong { min-width: 0; overflow-wrap: anywhere; }
|
|
56
|
+
.tavi-chain__label strong { display: block; font-size: .875rem; line-height: 1.25; }
|
|
57
|
+
.tavi-chain__kind, .tavi-chain__state { display: block; color: var(--tc-muted); font-size: .75rem; line-height: 1.2; }
|
|
58
|
+
.tavi-chain__state { border: 1px solid currentColor; border-radius: 4px; padding: 3px 5px; }
|
|
59
|
+
.tavi-chain__node[data-state="waiting"] .tavi-chain__state { color: var(--tavi-chain-waiting, #8a5306); }
|
|
60
|
+
.tavi-chain__node[data-state="failed"] .tavi-chain__state { color: var(--tavi-chain-failed, #a83438); }
|
|
61
|
+
.tavi-chain__node[data-state="completed"] .tavi-chain__state { color: var(--tavi-chain-completed, #186650); }
|
|
62
|
+
.tavi-chain__actions { display: flex; flex-wrap: wrap; gap: 8px; }
|
|
63
|
+
.tavi-chain__action { min-height: 40px; border: 1px solid var(--tavi-chain-line, currentColor); border-radius: var(--tavi-chain-radius, 6px); background: var(--tavi-chain-action-bg, transparent); color: inherit; padding: 6px 12px; font: inherit; cursor: pointer; }
|
|
64
|
+
.tavi-chain__action:hover:not([aria-disabled="true"]) { background: var(--tavi-chain-hover, transparent); border-color: var(--tavi-chain-accent, currentColor); }
|
|
65
|
+
.tavi-chain__action[aria-disabled="true"] { opacity: .7; cursor: wait; }
|
|
66
|
+
.tavi-chain__feedback:empty { display: none; }
|
|
67
|
+
@media (forced-colors: active) {
|
|
68
|
+
.tavi-chain__node[aria-pressed="true"] { border: 2px solid Highlight; }
|
|
69
|
+
.tavi-chain__rail, .tavi-chain__glyph { stroke: CanvasText; }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.tavi-topology {
|
|
73
|
+
background-image: radial-gradient(var(--tavi-topology-grid, #cdddeb) .7px, transparent .7px);
|
|
74
|
+
background-size: 13px 13px;
|
|
75
|
+
align-content: safe center;
|
|
76
|
+
max-width: 100%;
|
|
77
|
+
overflow-x: auto;
|
|
78
|
+
overscroll-behavior-inline: contain;
|
|
79
|
+
scrollbar-color: var(--tavi-topology-scroll, #8ba6bf) transparent;
|
|
80
|
+
background-color: var(--tavi-topology-bg, #f6faff);
|
|
81
|
+
}
|
|
82
|
+
.tavi-topology__canvas {
|
|
83
|
+
position: relative;
|
|
84
|
+
isolation: isolate;
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
.tavi-topology__edges {
|
|
88
|
+
position: absolute;
|
|
89
|
+
inset: 0;
|
|
90
|
+
width: 100%;
|
|
91
|
+
height: 100%;
|
|
92
|
+
pointer-events: none;
|
|
93
|
+
}
|
|
94
|
+
.tavi-topology__edge { stroke-width: 2; fill: none; vector-effect: non-scaling-stroke; }
|
|
95
|
+
.tavi-topology__edge--forward { stroke: var(--tavi-topology-forward, #2967c4); }
|
|
96
|
+
.tavi-topology__edge--feedback { stroke: var(--tavi-topology-feedback, #137f62); stroke-dasharray: 6 4; }
|
|
97
|
+
.tavi-topology__edge--control { stroke: var(--tavi-topology-control, #7045a4); stroke-dasharray: 2 4; stroke-linecap: round; }
|
|
98
|
+
.tavi-topology__arrow--forward { fill: var(--tavi-topology-forward, #2967c4); }
|
|
99
|
+
.tavi-topology__arrow--feedback { fill: var(--tavi-topology-feedback, #137f62); }
|
|
100
|
+
.tavi-topology__arrow--control { fill: var(--tavi-topology-control, #7045a4); }
|
|
101
|
+
.tavi-topology__edge.is-related { stroke-width: 3; }
|
|
102
|
+
.tavi-topology__edge.is-dimmed { opacity: .23; }
|
|
103
|
+
.tavi-topology .tavi-topology__node {
|
|
104
|
+
--tone: var(--tavi-topology-forward, #2967c4);
|
|
105
|
+
position: absolute;
|
|
106
|
+
box-sizing: border-box;
|
|
107
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
108
|
+
grid-template-rows: auto auto;
|
|
109
|
+
gap: 4px 5px;
|
|
110
|
+
min-height: 0;
|
|
111
|
+
width: auto;
|
|
112
|
+
align-content: center;
|
|
113
|
+
padding: 6px 9px 6px 10px;
|
|
114
|
+
border: 1px solid var(--tavi-topology-border, #baccdf);
|
|
115
|
+
border-left: 3px solid var(--tone);
|
|
116
|
+
border-radius: var(--tavi-topology-radius, 9px);
|
|
117
|
+
background: var(--tavi-topology-surface, #fff);
|
|
118
|
+
color: var(--tavi-topology-text, #18263b);
|
|
119
|
+
}
|
|
120
|
+
.tavi-topology .tavi-topology__node[data-lane="input"] { grid-template-rows: auto; padding: 4px 5px; gap: 3px; }
|
|
121
|
+
.tavi-topology .tavi-topology__node:hover { border-color: var(--tone); background: var(--tavi-topology-hover, var(--tavi-topology-surface, #fff)); }
|
|
122
|
+
.tavi-topology .tavi-topology__node[aria-pressed]:active { background: var(--tavi-topology-pressed, #e9f2fd); }
|
|
123
|
+
.tavi-topology .tavi-topology__node[aria-pressed="true"] { border-color: var(--tone); box-shadow: 0 0 0 1px var(--tone); background: var(--tavi-topology-selected, var(--tavi-topology-surface, #fff)); }
|
|
124
|
+
.tavi-topology .tavi-topology__node:focus-visible { outline: 2px solid var(--tavi-topology-focus, #225cad); outline-offset: 3px; }
|
|
125
|
+
.tavi-topology__name, .tavi-topology__meta, .tavi-topology__channel { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
126
|
+
.tavi-topology__name { font-size: .85rem; }
|
|
127
|
+
.tavi-topology__node[data-lane="input"] .tavi-topology__name { font-size: .73rem; }
|
|
128
|
+
.tavi-topology__meta { font-size: .68rem; font-weight: 600; color: var(--tone); background: var(--tavi-topology-meta-bg, transparent); border-radius: 999px; padding: 1px 5px; }
|
|
129
|
+
.tavi-topology__node[data-lane="input"] .tavi-topology__meta { font-size: .6rem; padding-inline: 2px; }
|
|
130
|
+
.tavi-topology__channel { grid-column: 1 / -1; font: .68rem var(--tavi-topology-mono, ui-monospace, monospace); color: var(--tavi-topology-muted, #46637c); }
|
|
131
|
+
@media (pointer: fine) {
|
|
132
|
+
.tavi-topology__canvas { cursor: grab; }
|
|
133
|
+
.tavi-topology[data-panning="true"] .tavi-topology__canvas { cursor: grabbing; user-select: none; }
|
|
134
|
+
}
|
|
135
|
+
@media (forced-colors: active) {
|
|
136
|
+
.tavi-topology__edge { stroke: CanvasText; }
|
|
137
|
+
.tavi-topology__arrow { fill: CanvasText; }
|
|
138
|
+
.tavi-topology .tavi-topology__node[aria-pressed="true"] { border: 2px solid Highlight; }
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.tavi-chain__node { --state-color: var(--tavi-chain-muted, #64748b); }
|
|
142
|
+
.tavi-chain__node[data-state="running"] { --state-color: var(--tavi-chain-accent, #6754c6); }
|
|
143
|
+
.tavi-chain__node[data-state="completed"] { --state-color: var(--tavi-chain-completed, #18744c); }
|
|
144
|
+
.tavi-chain__node[data-state="waiting"] { --state-color: var(--tavi-chain-waiting, #895800); }
|
|
145
|
+
.tavi-chain__node[data-state="failed"] { --state-color: var(--tavi-chain-failed, #a83438); }
|
|
146
|
+
.tavi-topology .tavi-topology__node { --tone: var(--state-color); }
|
|
147
|
+
.tavi-chain__node :is(.tavi-chain__state,.tavi-topology__meta) {
|
|
148
|
+
color: var(--state-color); background: color-mix(in srgb, var(--state-color) 13%, transparent);
|
|
149
|
+
padding: 2px 6px; border-radius: 999px; font-weight: 600;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.tavi-topology__canvas { zoom:var(--canvas-scale,1); margin-inline:auto; }
|
|
153
|
+
.tavi-workflow-tip { position:fixed; z-index:100; pointer-events:none; max-width:min(350px,calc(100vw - 16px)); box-sizing:border-box; padding:7px 12px; border:1px solid var(--tavi-chain-line,#bbb); border-radius:6px; background:var(--tavi-chain-surface,#fff); color:var(--tavi-chain-text,#202638); font-size:13px; overflow-wrap:anywhere; }
|
|
154
|
+
|
|
155
|
+
:where(:has(> .tavi-zoom-tools)) { position:relative; }
|
|
156
|
+
.tavi-zoom-tools { position:absolute; z-index:4; top:16px; right:16px; display:flex; align-items:center; padding:2px; gap:2px; border:1px solid var(--tavi-chain-line,#ddd); border-radius:7px; background:var(--tavi-chain-surface,#fff); color:var(--tavi-chain-text,#202638); box-shadow:0 2px 6px #0001; }
|
|
157
|
+
.tavi-zoom-tools button { border:0; border-radius:4px; width:26px; height:26px; background:transparent; color:inherit; font:18px/1 sans-serif; cursor:pointer; }
|
|
158
|
+
.tavi-zoom-tools button:hover { background:var(--tavi-chain-hover,#eee); }
|
|
159
|
+
.tavi-zoom-tools button:disabled { opacity:.35; cursor:default; }
|
|
160
|
+
.tavi-zoom-tools span { font:12px/1 sans-serif; min-width:35px; text-align:center; font-variant-numeric:tabular-nums; }
|
|
161
|
+
[data-canvas-fits="true"] > .tavi-topology[data-responsive="true"] { overflow:clip; }
|
package/theme.css
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
.tavi-chain-theme-web, [data-workflow-theme] {
|
|
2
|
+
color-scheme: dark;
|
|
3
|
+
--tavi-chain-line: var(--line);
|
|
4
|
+
--tavi-chain-surface: var(--bg-card);
|
|
5
|
+
--tavi-chain-text: var(--text-primary);
|
|
6
|
+
--tavi-chain-muted: var(--text-secondary);
|
|
7
|
+
--tavi-chain-accent: var(--accent);
|
|
8
|
+
--tavi-chain-focus: var(--accent);
|
|
9
|
+
--tavi-chain-hover: var(--bg-hover);
|
|
10
|
+
--tavi-chain-selected: var(--accent-soft);
|
|
11
|
+
--tavi-chain-waiting: var(--warn);
|
|
12
|
+
--tavi-chain-failed: var(--danger);
|
|
13
|
+
--tavi-chain-completed: var(--ok);
|
|
14
|
+
--tavi-chain-radius: var(--radius-sm);
|
|
15
|
+
--tavi-chain-action-bg: var(--bg-raised);
|
|
16
|
+
--tavi-topology-bg: var(--bg-base);
|
|
17
|
+
--tavi-topology-grid: var(--line);
|
|
18
|
+
--tavi-topology-border: var(--line-strong);
|
|
19
|
+
--tavi-topology-surface: var(--bg-card);
|
|
20
|
+
--tavi-topology-text: var(--text-primary);
|
|
21
|
+
--tavi-topology-muted: var(--text-secondary);
|
|
22
|
+
--tavi-topology-forward: var(--accent);
|
|
23
|
+
--tavi-topology-feedback: var(--ok);
|
|
24
|
+
--tavi-topology-control: var(--cyan);
|
|
25
|
+
--tavi-topology-output: var(--warn);
|
|
26
|
+
--tavi-topology-failed: var(--danger);
|
|
27
|
+
--tavi-topology-waiting: var(--warn);
|
|
28
|
+
--tavi-topology-focus: var(--accent);
|
|
29
|
+
--tavi-topology-hover: var(--bg-hover);
|
|
30
|
+
--tavi-topology-selected: var(--accent-soft);
|
|
31
|
+
--tavi-topology-pressed: var(--bg-raised);
|
|
32
|
+
--tavi-topology-meta-bg: var(--bg-raised);
|
|
33
|
+
--tavi-topology-scroll: var(--text-muted);
|
|
34
|
+
--tavi-topology-radius: var(--radius);
|
|
35
|
+
--tavi-topology-mono: var(--font-mono);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.tavi-chain-theme-desktop {
|
|
39
|
+
--tavi-chain-line: var(--border);
|
|
40
|
+
--tavi-chain-surface: var(--panel);
|
|
41
|
+
--tavi-chain-text: var(--fg-0);
|
|
42
|
+
--tavi-chain-muted: var(--fg-1);
|
|
43
|
+
--tavi-chain-accent: var(--accent);
|
|
44
|
+
--tavi-chain-focus: var(--focus-ring);
|
|
45
|
+
--tavi-chain-hover: var(--hover);
|
|
46
|
+
--tavi-chain-selected: var(--soft);
|
|
47
|
+
--tavi-chain-waiting: var(--warn);
|
|
48
|
+
--tavi-chain-failed: var(--err);
|
|
49
|
+
--tavi-chain-completed: var(--ok);
|
|
50
|
+
--tavi-chain-action-bg: var(--bg-1);
|
|
51
|
+
--tavi-topology-bg: var(--bg-1);
|
|
52
|
+
--tavi-topology-grid: var(--border-strong);
|
|
53
|
+
--tavi-topology-border: var(--border-strong);
|
|
54
|
+
--tavi-topology-surface: var(--panel);
|
|
55
|
+
--tavi-topology-text: var(--fg-0);
|
|
56
|
+
--tavi-topology-muted: var(--fg-2);
|
|
57
|
+
--tavi-topology-forward: var(--accent);
|
|
58
|
+
--tavi-topology-feedback: var(--ok);
|
|
59
|
+
--tavi-topology-control: var(--rb-accent);
|
|
60
|
+
--tavi-topology-output: var(--fg-1);
|
|
61
|
+
--tavi-topology-failed: var(--err);
|
|
62
|
+
--tavi-topology-waiting: var(--warn);
|
|
63
|
+
--tavi-topology-focus: var(--focus-ring);
|
|
64
|
+
--tavi-topology-hover: var(--hover);
|
|
65
|
+
--tavi-topology-selected: var(--soft);
|
|
66
|
+
--tavi-topology-pressed: var(--active);
|
|
67
|
+
--tavi-topology-meta-bg: var(--bg-2);
|
|
68
|
+
--tavi-topology-scroll: var(--border-strong);
|
|
69
|
+
--tavi-topology-mono: var(--mono);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
[data-theme="light"], [data-workflow-theme="light"] {
|
|
73
|
+
color-scheme: light;
|
|
74
|
+
--bg-base:#f4f6fa; --bg-panel:#fff; --bg-card:#fff; --bg-raised:#edf0f6; --bg-hover:#e9ecf6;
|
|
75
|
+
--line:#d5dae4; --line-strong:#aeb7c8; --text-primary:#202638; --text-secondary:#47536a;
|
|
76
|
+
--text-muted:#58657c; --accent:#6049bd; --accent-soft:#ede9ff; --ok:#176c48;
|
|
77
|
+
--warn:#875200; --danger:#ad343b; --cyan:#0b7274;
|
|
78
|
+
}
|
|
79
|
+
[data-theme="light"] .tavi-chain-theme-web { color-scheme:light; }
|
|
80
|
+
|
|
81
|
+
[data-workflow-theme="dark"] {
|
|
82
|
+
color-scheme:dark;
|
|
83
|
+
--bg-base:#080a0f; --bg-panel:#0d1017; --bg-card:#12161f; --bg-raised:#171c27; --bg-hover:#1c2230;
|
|
84
|
+
--line:#303541; --line-strong:#444958; --text-primary:#e8ecf4; --text-secondary:#a3adc2; --text-muted:#6b7688;
|
|
85
|
+
--accent:#8b7dff; --accent-soft:#29243f; --ok:#4ade80; --warn:#fbbf24; --danger:#f87171; --cyan:#3ddbd9;
|
|
86
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"title": "Tavi interaction topology v1",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"required": [
|
|
6
|
+
"version",
|
|
7
|
+
"nodes",
|
|
8
|
+
"links"
|
|
9
|
+
],
|
|
10
|
+
"properties": {
|
|
11
|
+
"version": {
|
|
12
|
+
"const": 1
|
|
13
|
+
},
|
|
14
|
+
"nodes": {
|
|
15
|
+
"type": "array",
|
|
16
|
+
"maxItems": 40,
|
|
17
|
+
"items": {
|
|
18
|
+
"allOf": [
|
|
19
|
+
{
|
|
20
|
+
"$ref": "./schema.json#/properties/steps/items"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"type": "object",
|
|
24
|
+
"required": [
|
|
25
|
+
"column"
|
|
26
|
+
],
|
|
27
|
+
"properties": {
|
|
28
|
+
"column": {
|
|
29
|
+
"type": "integer",
|
|
30
|
+
"minimum": 0,
|
|
31
|
+
"maximum": 39
|
|
32
|
+
},
|
|
33
|
+
"lane": {
|
|
34
|
+
"enum": [
|
|
35
|
+
"main",
|
|
36
|
+
"input"
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
"slot": {
|
|
40
|
+
"enum": [
|
|
41
|
+
0,
|
|
42
|
+
1, 2
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
"channel": {
|
|
46
|
+
"type": "string",
|
|
47
|
+
"maxLength": 160
|
|
48
|
+
},
|
|
49
|
+
"rateHz": {
|
|
50
|
+
"type": "number",
|
|
51
|
+
"minimum": 0
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"links": {
|
|
59
|
+
"type": "array",
|
|
60
|
+
"maxItems": 80,
|
|
61
|
+
"items": {
|
|
62
|
+
"type": "object",
|
|
63
|
+
"required": [
|
|
64
|
+
"from",
|
|
65
|
+
"to",
|
|
66
|
+
"kind"
|
|
67
|
+
],
|
|
68
|
+
"properties": {
|
|
69
|
+
"from": {
|
|
70
|
+
"type": "string"
|
|
71
|
+
},
|
|
72
|
+
"to": {
|
|
73
|
+
"type": "string"
|
|
74
|
+
},
|
|
75
|
+
"kind": {
|
|
76
|
+
"enum": [
|
|
77
|
+
"forward",
|
|
78
|
+
"feedback",
|
|
79
|
+
"control"
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
package/README.md
DELETED