silkio-flowchart 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +38 -3
  3. package/dist/FlowEdge.d.ts +45 -0
  4. package/dist/FlowEdge.js +390 -0
  5. package/dist/Shape.d.ts +48 -0
  6. package/dist/Shape.js +118 -0
  7. package/dist/ai-protocol.d.ts +146 -0
  8. package/dist/ai-protocol.js +578 -0
  9. package/dist/ai-report.d.ts +3 -0
  10. package/dist/ai-report.js +83 -0
  11. package/dist/ai.d.ts +6 -0
  12. package/dist/ai.js +7 -0
  13. package/dist/auto-layout.d.ts +15 -0
  14. package/dist/auto-layout.js +248 -0
  15. package/dist/commands.d.ts +106 -0
  16. package/dist/commands.js +264 -0
  17. package/dist/data.d.ts +24 -0
  18. package/dist/data.js +1 -0
  19. package/dist/edge-router.d.ts +24 -0
  20. package/dist/edge-router.js +22 -0
  21. package/dist/editing.d.ts +32 -0
  22. package/dist/editing.js +148 -0
  23. package/dist/flow-layout-capability.d.ts +7 -0
  24. package/dist/flow-layout-capability.js +2 -0
  25. package/dist/flowchart.d.ts +115 -0
  26. package/dist/flowchart.js +1425 -0
  27. package/dist/geometry.d.ts +98 -0
  28. package/dist/geometry.js +310 -0
  29. package/dist/history-codec.d.ts +47 -0
  30. package/dist/history-codec.js +410 -0
  31. package/dist/hover.d.ts +22 -0
  32. package/dist/hover.js +96 -0
  33. package/dist/index.d.ts +22 -0
  34. package/dist/index.js +18 -0
  35. package/dist/interactions.d.ts +51 -0
  36. package/dist/interactions.js +636 -0
  37. package/dist/model.d.ts +58 -0
  38. package/dist/model.js +233 -0
  39. package/dist/overlay.d.ts +60 -0
  40. package/dist/overlay.js +242 -0
  41. package/dist/quick-create.d.ts +12 -0
  42. package/dist/quick-create.js +29 -0
  43. package/dist/selection.d.ts +8 -0
  44. package/dist/selection.js +31 -0
  45. package/dist/session.d.ts +68 -0
  46. package/dist/session.js +4 -0
  47. package/dist/shape-registry.d.ts +17 -0
  48. package/dist/shape-registry.js +36 -0
  49. package/dist/shapes.d.ts +56 -0
  50. package/dist/shapes.js +291 -0
  51. package/dist/snap-capability.d.ts +23 -0
  52. package/dist/snap-capability.js +32 -0
  53. package/dist/snap.d.ts +34 -0
  54. package/dist/snap.js +370 -0
  55. package/package.json +32 -3
@@ -0,0 +1,410 @@
1
+ // 历史命令编解码器:把 flowchart 各命令的序列化载荷(kind + 纯数据)重建为可执行的
2
+ // HistoryCommand。只依赖 core 契约与自有模型,不依赖 plugin-*(check-deps 分层约束)。
3
+ //
4
+ // 引用解析规则(与各命令的 toJSON 载荷一一对应):
5
+ // - 形状按 id 解析:先查模型形状表(model.shapes),再查会话注册表;查不到且
6
+ // 载荷内嵌了数据快照(delete/replace/add-shape 的 data 字段)时经形状注册表
7
+ // 重建并登记——脱离树/连线表的形状(被删、被顶替的旧形状)由此恢复。
8
+ // - 连线按 id 解析:先查模型连线表,再查会话注册表;查不到时按内嵌的端点 id
9
+ // 与端口方向重建(FlowEdge 构造后回写原 id)。重建发生在 revive 阶段而非
10
+ // redo 执行时,同一连线的 redo/undo 共用同一对象,重放不会重复创建。
11
+ //
12
+ // 复合命令(core 的 composite kind)在此解码为 compose(...),子命令递归走本解码器。
13
+ // 解码失败的命令返回 null:importJSON 收到 null 即整体放弃导入且不改动栈。
14
+ import { compose } from "@silkor/core";
15
+ import { FlowEdge } from "./FlowEdge";
16
+ // 创建编解码器:decode 把 SerializedCommand 重建为 HistoryCommand(失败返回 null)
17
+ export function createFlowchartCodec(deps) {
18
+ const { model, app, router } = deps;
19
+ // 会话注册表:模型形状表/连线表查不到的对象在此登记,跨命令按 id 去重
20
+ const shapes = new Map();
21
+ const edges = new Map();
22
+ // 形状解析:模型形状表 → 注册表;都没有且提供内嵌数据则经形状注册表重建。
23
+ // id 允许缺省(内嵌数据理论可无 id):缺省时只走重建路径,不登记注册表
24
+ function resolveShape(id, data) {
25
+ if (id) {
26
+ const live = model.shapes.get(id);
27
+ if (live)
28
+ return live;
29
+ const cached = shapes.get(id);
30
+ if (cached)
31
+ return cached;
32
+ }
33
+ if (!data)
34
+ return null;
35
+ try {
36
+ const shape = model.createShape(data.shape, {
37
+ id: data.id,
38
+ x: data.x,
39
+ y: data.y,
40
+ width: data.width,
41
+ height: data.height,
42
+ text: data.text,
43
+ });
44
+ if (data.id)
45
+ shapes.set(data.id, shape);
46
+ return shape;
47
+ }
48
+ catch {
49
+ // 未知形状 kind(如导入方缺少对应形状插件):放弃该命令,整体导入失败
50
+ return null;
51
+ }
52
+ }
53
+ // 连线解析:模型连线表 → 注册表;都没有则按端点与端口方向重建并回写原 id
54
+ //(标签文本随载荷内嵌,重建连线恢复原标签)
55
+ function resolveEdge(id, fromId, toId, fromDir, toDir, text) {
56
+ const live = model.edges.find((e) => e.id === id);
57
+ if (live)
58
+ return live;
59
+ const cached = edges.get(id);
60
+ if (cached)
61
+ return cached;
62
+ const from = resolveShape(fromId);
63
+ const to = resolveShape(toId);
64
+ if (!from || !to)
65
+ return null;
66
+ const edge = new FlowEdge(from, to, { from: fromDir, to: toDir });
67
+ edge.id = id;
68
+ edge.router = router;
69
+ if (text)
70
+ edge.label.text = text;
71
+ edges.set(id, edge);
72
+ return edge;
73
+ }
74
+ // decode:按 kind 分发到各重建器,未知 kind 返回 null
75
+ function decode(s) {
76
+ switch (s.kind) {
77
+ case "composite": {
78
+ const p = s.payload;
79
+ const children = p.children.map(decode);
80
+ if (children.some((c) => !c))
81
+ return null;
82
+ return compose(p.type, ...children);
83
+ }
84
+ case "flowchart.move":
85
+ return decodeMove(s.payload);
86
+ case "flowchart.resize":
87
+ return decodeResize(s.payload);
88
+ case "flowchart.reconnect":
89
+ return decodeReconnect(s.payload);
90
+ case "flowchart.text":
91
+ return decodeText(s.payload);
92
+ case "flowchart.edgeText":
93
+ return decodeEdgeText(s.payload);
94
+ case "flowchart.add-shape":
95
+ return decodeAddShape(s.payload);
96
+ case "flowchart.connect":
97
+ return decodeConnect(s.payload);
98
+ case "flowchart.delete":
99
+ return decodeDelete(s.payload);
100
+ case "flowchart.replace":
101
+ return decodeReplace(s.payload);
102
+ case "flowchart.render":
103
+ return decodeRender(s.payload);
104
+ default:
105
+ return null;
106
+ }
107
+ }
108
+ function decodeMove(p) {
109
+ if (p.v === "delta") {
110
+ const targets = [];
111
+ for (const id of p.targets ?? []) {
112
+ const shape = resolveShape(id);
113
+ if (!shape)
114
+ return null;
115
+ targets.push(shape);
116
+ }
117
+ const before = [];
118
+ for (const b of p.before) {
119
+ const shape = resolveShape(b.shapeId);
120
+ if (!shape)
121
+ return null;
122
+ before.push({ shape, x: b.x, y: b.y });
123
+ }
124
+ const dx = p.dx ?? 0;
125
+ const dy = p.dy ?? 0;
126
+ return {
127
+ type: "move",
128
+ redo: () => {
129
+ for (const s of targets) {
130
+ s.x += dx;
131
+ s.y += dy;
132
+ }
133
+ },
134
+ undo: () => {
135
+ for (const m of before) {
136
+ m.shape.x = m.x;
137
+ m.shape.y = m.y;
138
+ }
139
+ },
140
+ toJSON: () => ({ kind: "flowchart.move", payload: p }),
141
+ };
142
+ }
143
+ // abs:拖拽移动,前后绝对位置快照
144
+ const before = [];
145
+ const after = [];
146
+ for (const b of p.before) {
147
+ const shape = resolveShape(b.shapeId);
148
+ if (!shape)
149
+ return null;
150
+ before.push({ shape, x: b.x, y: b.y });
151
+ }
152
+ for (const a of p.after ?? []) {
153
+ const shape = resolveShape(a.shapeId);
154
+ if (!shape)
155
+ return null;
156
+ after.push({ shape, x: a.x, y: a.y });
157
+ }
158
+ return {
159
+ type: "move",
160
+ redo: () => {
161
+ for (const m of after) {
162
+ m.shape.x = m.x;
163
+ m.shape.y = m.y;
164
+ }
165
+ },
166
+ undo: () => {
167
+ for (const m of before) {
168
+ m.shape.x = m.x;
169
+ m.shape.y = m.y;
170
+ }
171
+ },
172
+ toJSON: () => ({ kind: "flowchart.move", payload: p }),
173
+ };
174
+ }
175
+ function decodeResize(p) {
176
+ if (p.v === "single") {
177
+ const shape = resolveShape(p.shapeId);
178
+ if (!shape)
179
+ return null;
180
+ return {
181
+ type: "resize",
182
+ redo: () => {
183
+ Object.assign(shape, p.after);
184
+ shape.layout();
185
+ },
186
+ undo: () => {
187
+ Object.assign(shape, p.before);
188
+ shape.layout();
189
+ },
190
+ toJSON: () => ({ kind: "flowchart.resize", payload: p }),
191
+ };
192
+ }
193
+ // group:逐成员恢复位置与尺寸
194
+ const before = [];
195
+ const after = [];
196
+ for (const b of p.before) {
197
+ const shape = resolveShape(b.shapeId);
198
+ if (!shape)
199
+ return null;
200
+ before.push({ shape, x: b.x, y: b.y, width: b.width, height: b.height });
201
+ }
202
+ for (const a of p.after) {
203
+ const shape = resolveShape(a.shapeId);
204
+ if (!shape)
205
+ return null;
206
+ after.push({ shape, x: a.x, y: a.y, width: a.width, height: a.height });
207
+ }
208
+ return {
209
+ type: "resize",
210
+ redo: () => {
211
+ for (const m of after) {
212
+ Object.assign(m.shape, { x: m.x, y: m.y, width: m.width, height: m.height });
213
+ m.shape.layout();
214
+ }
215
+ },
216
+ undo: () => {
217
+ for (const m of before) {
218
+ Object.assign(m.shape, { x: m.x, y: m.y, width: m.width, height: m.height });
219
+ m.shape.layout();
220
+ }
221
+ },
222
+ toJSON: () => ({ kind: "flowchart.resize", payload: p }),
223
+ };
224
+ }
225
+ function decodeReconnect(p) {
226
+ // 重接不摘除连线,连线必在模型连线表中(或本会话已重建)
227
+ const edge = model.edges.find((e) => e.id === p.edgeId) ?? edges.get(p.edgeId);
228
+ if (!edge)
229
+ return null;
230
+ const oldNode = resolveShape(p.oldNodeId);
231
+ const newNode = resolveShape(p.newNodeId);
232
+ if (!oldNode || !newNode)
233
+ return null;
234
+ return {
235
+ type: "reconnect",
236
+ redo: () => edge.reattachEnd(p.which, newNode, p.newDir),
237
+ undo: () => edge.reattachEnd(p.which, oldNode, p.oldDir),
238
+ toJSON: () => ({ kind: "flowchart.reconnect", payload: p }),
239
+ };
240
+ }
241
+ function decodeText(p) {
242
+ const shape = resolveShape(p.shapeId);
243
+ if (!shape)
244
+ return null;
245
+ return {
246
+ type: "text",
247
+ redo: () => {
248
+ shape.text.text = p.after;
249
+ shape.layout();
250
+ },
251
+ undo: () => {
252
+ shape.text.text = p.before;
253
+ shape.layout();
254
+ },
255
+ toJSON: () => ({ kind: "flowchart.text", payload: p }),
256
+ };
257
+ }
258
+ // 连线标签编辑解码:连线不摘除,必在连线表或本会话已重建(同 reconnect 规则)
259
+ function decodeEdgeText(p) {
260
+ const edge = model.edges.find((e) => e.id === p.edgeId) ?? edges.get(p.edgeId);
261
+ if (!edge)
262
+ return null;
263
+ return {
264
+ type: "text",
265
+ redo: () => {
266
+ edge.label.text = p.after;
267
+ edge.layout();
268
+ },
269
+ undo: () => {
270
+ edge.label.text = p.before;
271
+ edge.layout();
272
+ },
273
+ toJSON: () => ({ kind: "flowchart.edgeText", payload: p }),
274
+ };
275
+ }
276
+ function decodeAddShape(p) {
277
+ const shape = resolveShape(p.data.id, p.data);
278
+ if (!shape)
279
+ return null;
280
+ return {
281
+ type: "add",
282
+ redo: () => model.registerShape(shape),
283
+ undo: () => model.removeShape(shape),
284
+ toJSON: () => ({ kind: "flowchart.add-shape", payload: p }),
285
+ };
286
+ }
287
+ function decodeConnect(p) {
288
+ const edge = resolveEdge(p.edgeId, p.fromId, p.toId, p.fromDir, p.toDir, p.text);
289
+ if (!edge)
290
+ return null;
291
+ return {
292
+ type: "connect",
293
+ redo: () => {
294
+ model.edges.push(edge);
295
+ model.insertEdge(edge);
296
+ },
297
+ undo: () => {
298
+ model.edges = model.edges.filter((e) => e !== edge);
299
+ model.removeTop(edge);
300
+ },
301
+ toJSON: () => ({ kind: "flowchart.connect", payload: p }),
302
+ };
303
+ }
304
+ function decodeDelete(p) {
305
+ if (p.v === "edge") {
306
+ const e = p.edge;
307
+ const edge = resolveEdge(e.edgeId, e.fromId, e.toId, e.fromDir, e.toDir, e.text);
308
+ if (!edge)
309
+ return null;
310
+ return {
311
+ type: "delete",
312
+ redo: () => {
313
+ model.removeTop(edge);
314
+ model.edges = model.edges.filter((x) => x !== edge);
315
+ },
316
+ undo: () => {
317
+ model.edges.splice(Math.min(p.listIdx ?? 0, model.edges.length), 0, edge);
318
+ model.insertAt(edge, p.childIdx ?? 0);
319
+ },
320
+ toJSON: () => ({ kind: "flowchart.delete", payload: p }),
321
+ };
322
+ }
323
+ // shapes:重建删除捕获(被删形状脱离树,一律走内嵌数据重建)。
324
+ // 两段式:先重建全部形状(跨条目的连线端点可能指向后一条目的形状),
325
+ // 再解析各条目的关联连线
326
+ const revives = [];
327
+ for (const item of p.items ?? []) {
328
+ const shape = resolveShape(item.data.id, item.data);
329
+ if (!shape)
330
+ return null;
331
+ revives.push({ data: item.data, childIdx: item.childIdx, edges: item.edges });
332
+ }
333
+ const captures = [];
334
+ for (const r of revives) {
335
+ const shape = resolveShape(r.data.id, r.data);
336
+ if (!shape)
337
+ return null;
338
+ const itemEdges = [];
339
+ for (const e of r.edges) {
340
+ const edge = resolveEdge(e.id, e.fromId, e.toId, e.fromDir, e.toDir, e.text);
341
+ if (!edge)
342
+ return null;
343
+ itemEdges.push({ edge, order: e.order, childIdx: e.childIdx });
344
+ }
345
+ captures.push({ shape, childIdx: r.childIdx, edges: itemEdges });
346
+ }
347
+ return {
348
+ type: "delete",
349
+ redo: () => {
350
+ for (const c of captures)
351
+ model.applyShapeRemoval(c);
352
+ },
353
+ undo: () => {
354
+ for (const c of [...captures].reverse())
355
+ model.restoreShapeRemoval(c);
356
+ },
357
+ toJSON: () => ({ kind: "flowchart.delete", payload: p }),
358
+ };
359
+ }
360
+ function decodeReplace(p) {
361
+ // 旧形状已脱离树且不在形状表,须经内嵌数据重建;新形状在最终态数据里,
362
+ // 优先按 id 命中在位实例(会话注册表兜底)
363
+ const old = resolveShape(p.oldData.id, p.oldData);
364
+ const shape = resolveShape(p.newData.id, p.newData);
365
+ if (!old || !shape)
366
+ return null;
367
+ return {
368
+ type: "replace",
369
+ redo: () => model.swapShape(old, shape),
370
+ undo: () => model.swapShape(shape, old),
371
+ toJSON: () => ({ kind: "flowchart.replace", payload: p }),
372
+ };
373
+ }
374
+ // 整图替换(AI 生成):前后快照各自复活为形状/连线实例集合,redo/undo
375
+ // 整体顶替。形状按 id + 内嵌数据重建(脱离树的旧图靠 data 快照复活),
376
+ // 连线按 edgeIds 复用同一实例;端口方向与标签文本随快照还原
377
+ function decodeRender(p) {
378
+ const revive = (snap) => {
379
+ const shapes = [];
380
+ for (const node of snap.data.nodes) {
381
+ const shape = resolveShape(node.id, node);
382
+ if (!shape)
383
+ return null;
384
+ shapes.push(shape);
385
+ }
386
+ const byId = new Map(shapes.map((s) => [s.id, s]));
387
+ const edges = [];
388
+ snap.data.edges.forEach((e, i) => {
389
+ const id = snap.edgeIds[i];
390
+ if (!id || !byId.has(e.from) || !byId.has(e.to))
391
+ return;
392
+ const edge = resolveEdge(id, e.from, e.to, e.fromDir, e.toDir, e.text);
393
+ if (edge)
394
+ edges.push(edge);
395
+ });
396
+ return { shapes, edges };
397
+ };
398
+ const before = revive(p.before);
399
+ const after = revive(p.after);
400
+ if (!before || !after)
401
+ return null;
402
+ return {
403
+ type: "ai",
404
+ redo: () => model.replaceAll(after.shapes, after.edges),
405
+ undo: () => model.replaceAll(before.shapes, before.edges),
406
+ toJSON: () => ({ kind: "flowchart.render", payload: p }),
407
+ };
408
+ }
409
+ return { decode };
410
+ }
@@ -0,0 +1,22 @@
1
+ import { App } from "@silkor/core";
2
+ import type { SelectionCapability } from "@silkor/core";
3
+ import { FlowEdge } from "./FlowEdge";
4
+ import type { PortDir } from "./FlowEdge";
5
+ import { Shape } from "./Shape";
6
+ export interface HoverFeedbackDeps {
7
+ app: App;
8
+ canvas: HTMLCanvasElement;
9
+ edges: () => FlowEdge[];
10
+ sel: SelectionCapability<Shape | FlowEdge>;
11
+ onRaiseEdgeTop: (edge: FlowEdge) => void;
12
+ }
13
+ export declare class HoverFeedback {
14
+ private deps;
15
+ private hoverPort;
16
+ private hoverEdge;
17
+ constructor(deps: HoverFeedbackDeps);
18
+ get port(): PortDir | null;
19
+ track(e: MouseEvent): void;
20
+ reset(): void;
21
+ clearPort(): void;
22
+ }
package/dist/hover.js ADDED
@@ -0,0 +1,96 @@
1
+ import { App } from "@silkor/core";
2
+ import { FlowEdge } from "./FlowEdge";
3
+ import { Shape } from "./Shape";
4
+ import { cornerHit, edgeHandleHit, edgeHit, hitEdge, hitShape, hoverCursor, portHit, } from "./geometry";
5
+ import { multiBounds, selEdge, selShape } from "./selection";
6
+ // 悬浮反馈(无交互会话时逐帧调用):悬浮端口与悬浮连线状态的唯一属主,
7
+ // 负责光标样式联动与连线高亮/置顶;选中框覆盖层经 port 只读悬浮端口
8
+ export class HoverFeedback {
9
+ deps;
10
+ // 悬浮中的端口方向(单选形状的四向端口):覆盖层放大该圆点并绘制方向箭头
11
+ hoverPort = null;
12
+ // 悬浮中的连线:浅蓝色高亮(类似 hoverPort,状态变化时重绘)
13
+ hoverEdge = null;
14
+ constructor(deps) {
15
+ this.deps = deps;
16
+ }
17
+ // 悬浮中的端口方向(覆盖层状态提供者只读)
18
+ get port() {
19
+ return this.hoverPort;
20
+ }
21
+ // 悬浮反馈跟踪:缩放手柄/边线/端口/形状体/连线分别给对应光标
22
+ track(e) {
23
+ // 右键拖拽视口时跳过:viewport 已设置 grabbing,不要覆盖
24
+ if (e.buttons & 2)
25
+ return;
26
+ const p = this.deps.app.camera.toWorld(e.clientX, e.clientY);
27
+ const scale = this.deps.app.camera.viewport.scale;
28
+ const sel = this.deps.sel;
29
+ // 光标反馈先行:手柄/边线给缩放光标、连线端点手柄给移动光标
30
+ let cursor = null;
31
+ // 多选组合框的手柄/边线优先给缩放光标
32
+ const mb = multiBounds(sel);
33
+ if (mb) {
34
+ const corner = cornerHit(mb, p, scale);
35
+ if (corner)
36
+ cursor =
37
+ corner === "nw" || corner === "se" ? "nwse-resize" : "nesw-resize";
38
+ else {
39
+ const side = edgeHit(mb, p, scale);
40
+ if (side)
41
+ cursor = side === "n" || side === "s" ? "ns-resize" : "ew-resize";
42
+ }
43
+ }
44
+ const hoverSel = selShape(sel);
45
+ if (cursor === null)
46
+ cursor = hoverSel ? hoverCursor(hoverSel, p, scale) : null;
47
+ const selEdgeHover = selEdge(sel);
48
+ if (cursor === null &&
49
+ selEdgeHover &&
50
+ edgeHandleHit(selEdgeHover, p, scale))
51
+ cursor = "move";
52
+ // 悬浮端口跟踪:单选形状的端口上悬浮时覆盖层放大该圆点并绘制方向箭头
53
+ const hp = hoverSel ? portHit(hoverSel, p, scale) : null;
54
+ if (hp !== this.hoverPort) {
55
+ this.hoverPort = hp;
56
+ this.deps.app.requestRender();
57
+ }
58
+ // 悬浮连线跟踪:只有鼠标不压在任何形状或覆盖层手柄/端口上才考虑 edge 悬浮
59
+ //(形状层在上、edge 层在下,被形状遮住的 edge 不该响应;覆盖层手柄不参与
60
+ // 场景命中,但端点手柄压在连线上、端口浮在连线经过处,悬浮时不应穿透
61
+ // 高亮下层连线——光标反馈已表达交互意图)
62
+ const onHandle = cursor !== null || hp !== null;
63
+ const shapeHit = hitShape(this.deps.app.children, p);
64
+ const he = onHandle || shapeHit ? null : hitEdge(this.deps.edges(), p, scale);
65
+ if (he !== this.hoverEdge) {
66
+ const prev = this.hoverEdge;
67
+ if (prev)
68
+ prev.hovered = false;
69
+ this.hoverEdge = he;
70
+ // 悬浮离开(含移向另一条连线)时把激活连线重新置顶,不再被刚才的
71
+ // 悬浮连线遮盖;随后提升新悬浮的连线,保证悬浮中的连线始终在最顶层
72
+ const selEdgeHover2 = selEdge(sel);
73
+ if (prev && selEdgeHover2 && selEdgeHover2 !== he)
74
+ this.deps.onRaiseEdgeTop(selEdgeHover2);
75
+ if (he) {
76
+ he.hovered = true;
77
+ this.deps.onRaiseEdgeTop(he);
78
+ }
79
+ this.deps.app.requestRender();
80
+ }
81
+ // 连线、节点、空白区域统一 default 光标,悬浮反馈由视觉(浅蓝色)而非光标表达
82
+ this.deps.canvas.style.cursor = cursor ?? "";
83
+ }
84
+ // 清空悬浮状态(按下进入交互会话时调用):端口提示消失、连线取消高亮
85
+ reset() {
86
+ this.hoverPort = null;
87
+ if (this.hoverEdge) {
88
+ this.hoverEdge.hovered = false;
89
+ this.hoverEdge = null;
90
+ }
91
+ }
92
+ // 仅清空悬浮端口(选中变化时调用:可能指向新选中形状的错误方向)
93
+ clearPort() {
94
+ this.hoverPort = null;
95
+ }
96
+ }
@@ -0,0 +1,22 @@
1
+ export { FlowChart } from './flowchart';
2
+ export type { FlowChartOptions } from './flowchart';
3
+ export type { Plugin } from '@silkor/core';
4
+ export { Shape } from './Shape';
5
+ export type { ShapeStyle, ShapeOptions } from './Shape';
6
+ export { RectShape, Diamond, EllipseShape, Parallelogram, Hexagon, Database, } from './shapes';
7
+ export { FlowEdge } from './FlowEdge';
8
+ export type { PortDir, FlowEdgeHints } from './FlowEdge';
9
+ export { BuiltinShapes, SHAPE_REGISTRY_CAPABILITY } from './shape-registry';
10
+ export type { ShapeRegistryCapability, ShapeDescriptor } from './shape-registry';
11
+ export { BuiltinSnap, SNAP_CAPABILITY } from './snap-capability';
12
+ export type { SnapCapability, SnapInput } from './snap-capability';
13
+ export type { Bounds, SnapGuides, SpacingGuide, SnapOptions, SnapResult, } from './snap';
14
+ export { BuiltinEdgeRouter, EDGE_ROUTER_CAPABILITY } from './edge-router';
15
+ export type { EdgeRouterCapability, EdgeRouteInput, EdgeRenderStyle, } from './edge-router';
16
+ export type { ShapeKind, BuiltinShapeKind, FlowNodeData, FlowEdgeData, FlowData, FlowChangeType, } from './data';
17
+ export { defaultAIFlowPrompt, normalizeAIFlowGraph, normalizeAIFlowOps, parseAIFlowOps, parseAIFlowResponse, inferFlowShape, toSemanticGraph, } from './ai-protocol';
18
+ export type { AIFlowRole, AIFlowNode, AIFlowEdge, AIFlowGraph, NormalizedFlowNode, NormalizedFlowGraph, AIFlowOp, AIFlowRenderOp, AIFlowCreateNodeOp, AIFlowUpdateEdgeOp, AIFlowUndoOp, AIFlowRedoOp, AIFlowHistoryOp, AIFlowAnswerOp, AIFlowSelection, AIFlowHistoryState, AIFlowStep, AIFlowTurn, AIFlowEditRequest, AIFlowGenerate, AIFlowRunOptions, AIFlowRunResult, } from './ai-protocol';
19
+ export { layoutFlowGraph } from './auto-layout';
20
+ export type { FlowLayoutDirection, FlowLayoutOptions } from './auto-layout';
21
+ export { FLOW_AUTO_LAYOUT_CAPABILITY } from './flow-layout-capability';
22
+ export type { FlowAutoLayoutCapability } from './flow-layout-capability';
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ // 流程图包入口:默认开箱即用——new FlowChart({ canvas, data }) 由场景自建 App
2
+ // 并装配官方插件预设;需要替换官方实现或共用宿主时经 FlowChartOptions.app 显式装配。
3
+ export { FlowChart } from './flowchart';
4
+ export { Shape } from './Shape';
5
+ export { RectShape, Diamond, EllipseShape, Parallelogram, Hexagon, Database, } from './shapes';
6
+ export { FlowEdge } from './FlowEdge';
7
+ // 形状注册表:契约 + 官方形状插件(内置六形状),第三方形状按能力键扩展
8
+ export { BuiltinShapes, SHAPE_REGISTRY_CAPABILITY } from './shape-registry';
9
+ // 吸附能力:契约 + 官方吸附插件(对齐/等间距吸附),第三方吸附策略按能力键同名覆盖
10
+ export { BuiltinSnap, SNAP_CAPABILITY } from './snap-capability';
11
+ // 边路由能力:契约 + 官方路由插件(正交折线 + 圆角 + 箭头),第三方路由策略按能力键同名覆盖
12
+ export { BuiltinEdgeRouter, EDGE_ROUTER_CAPABILITY } from './edge-router';
13
+ // AI 生成:语义图协议(LLM 只输出拓扑语义)/ 操作序列(改图 / 撤销 / 重做 /
14
+ // 查历史 / 回答)/ 选中与历史上下文 / 默认提示词 / 容错解析 /
15
+ // 确定性 DAG 自动布局(把语义图编译成带 x/y 与端口方向的 FlowData)
16
+ export { defaultAIFlowPrompt, normalizeAIFlowGraph, normalizeAIFlowOps, parseAIFlowOps, parseAIFlowResponse, inferFlowShape, toSemanticGraph, } from './ai-protocol';
17
+ export { layoutFlowGraph } from './auto-layout';
18
+ export { FLOW_AUTO_LAYOUT_CAPABILITY } from './flow-layout-capability';
@@ -0,0 +1,51 @@
1
+ import { App } from "@silkor/core";
2
+ import type { HistoryCapability } from "@silkor/core";
3
+ import type { SelectionCapability } from "@silkor/core";
4
+ import type { TextEditorCapability } from "@silkor/core";
5
+ import { FlowEdge } from "./FlowEdge";
6
+ import type { PortDir } from "./FlowEdge";
7
+ import { Shape } from "./Shape";
8
+ import type { Bounds, SnapGuides } from "./snap";
9
+ import type { SnapCapability } from "./snap-capability";
10
+ import type { EdgeRouterCapability } from "./edge-router";
11
+ import type { FlowChangeType } from "./data";
12
+ import type { FlowEditing } from "./editing";
13
+ import type { HoverFeedback } from "./hover";
14
+ import type { FlowModel } from "./model";
15
+ export interface FlowInteractionsDeps {
16
+ app: App;
17
+ canvas: HTMLCanvasElement;
18
+ model: FlowModel;
19
+ sel: SelectionCapability<Shape | FlowEdge>;
20
+ editing: FlowEditing;
21
+ hover: HoverFeedback;
22
+ snapper: SnapCapability;
23
+ router: EdgeRouterCapability;
24
+ editor: TextEditorCapability;
25
+ history: HistoryCapability;
26
+ onChange?: (type: FlowChangeType) => void;
27
+ }
28
+ export declare class FlowInteractions {
29
+ private deps;
30
+ private session;
31
+ linkTarget: Shape | null;
32
+ linkSnap: PortDir | null;
33
+ guides: SnapGuides | null;
34
+ private snapPrev;
35
+ marqueeCombo: Bounds | null;
36
+ private edgePan;
37
+ constructor(deps: FlowInteractionsDeps);
38
+ private onEdgePan;
39
+ private applyMove;
40
+ get busy(): boolean;
41
+ bind(canvas: HTMLCanvasElement): () => void;
42
+ private pendingEdgeEdit;
43
+ private onDown;
44
+ private onMove;
45
+ private updateLinkTarget;
46
+ private applySnap;
47
+ private onUp;
48
+ private createNodeInDirection;
49
+ private onKeyDown;
50
+ select(sel: Shape | FlowEdge | null): void;
51
+ }