@blueking/flow-canvas 0.0.1-beta.3 → 0.0.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/README.md +141 -15
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +819 -33
- package/dist/index.esm.js +1067 -932
- package/dist/style.css +1 -1
- package/package.json +2 -2
- package/dist/core/apply-command.d.ts +0 -11
- package/dist/core/editor.d.ts +0 -50
- package/dist/core/errors.d.ts +0 -6
- package/dist/core/history.d.ts +0 -15
- package/dist/core/plugin-manager.d.ts +0 -58
- package/dist/plugins/clipboard.d.ts +0 -9
- package/dist/plugins/connection-validator.d.ts +0 -3
- package/dist/plugins/minimap.d.ts +0 -7
- package/dist/plugins/selection.d.ts +0 -7
- package/dist/plugins/snapline.d.ts +0 -6
- package/dist/runtime/canvas-api.d.ts +0 -25
- package/dist/runtime/canvas-runtime-core.vue.d.ts +0 -31
- package/dist/runtime/event-bridge.d.ts +0 -28
- package/dist/runtime/graph-bridge.d.ts +0 -127
- package/dist/runtime/overlay-manager.d.ts +0 -3
- package/dist/runtime/shape-registry.d.ts +0 -8
- package/dist/runtime/use-edge-delete-tool.d.ts +0 -11
- package/dist/runtime/use-node-hover.d.ts +0 -10
- package/dist/runtime/use-port-visibility.d.ts +0 -15
- package/dist/shell/canvas-layout.vue.d.ts +0 -35
- package/dist/shell/canvas-node-palette.vue.d.ts +0 -10
- package/dist/shell/canvas-toolbar.vue.d.ts +0 -11
- package/dist/shell/default-node.vue.d.ts +0 -4
- package/dist/shell/default-schema.d.ts +0 -39
- package/dist/shell/node-actions-toolbar.vue.d.ts +0 -22
- package/dist/shell/node-quick-add-popover.vue.d.ts +0 -36
- package/dist/shell/toolbar-items.d.ts +0 -15
- package/dist/types/api.d.ts +0 -104
- package/dist/types/command.d.ts +0 -160
- package/dist/types/flow-model.d.ts +0 -46
- package/dist/types/history.d.ts +0 -18
- package/dist/types/overlay.d.ts +0 -3
- package/dist/types/plugin.d.ts +0 -64
- package/dist/types/schema.d.ts +0 -80
- package/dist/utils/path.d.ts +0 -7
- package/dist/utils/uuid.d.ts +0 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
npm install @blueking/flow-canvas
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
项目中另外还需要安装以下前置依赖
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
npm install @antv/x6 @antv/x6-plugin-minimap @antv/x6-plugin-selection @antv/x6-plugin-snapline @antv/x6-plugin-dnd @antv/x6-vue-shape vue
|
|
@@ -205,7 +205,7 @@ interface FlowNodeModel {
|
|
|
205
205
|
type: string; // 对应 schema.nodeTypes 的 key
|
|
206
206
|
position: { x: number; y: number };
|
|
207
207
|
label?: string;
|
|
208
|
-
ports?: FlowPortModel[];
|
|
208
|
+
ports?: FlowPortModel[]; // 业务自定义端口;未提供 getPorts() 时优先读取,缺省时引擎自动补四向默认端口
|
|
209
209
|
payload?: Record<string, unknown>; // 业务数据
|
|
210
210
|
extensions?: Record<string, unknown>; // 扩展数据
|
|
211
211
|
}
|
|
@@ -239,6 +239,30 @@ interface CanvasNodeDefinition {
|
|
|
239
239
|
|
|
240
240
|
节点 Vue 组件内可通过 `inject('getNode')` 获取 X6 Node 实例,读取 `node.getData()` 访问 `FlowNodeModel`。
|
|
241
241
|
|
|
242
|
+
#### 端口来源与 `getPorts` 选型
|
|
243
|
+
|
|
244
|
+
`getSize` 是必填;`getPorts` 和 `getBehavior` 都是可选。
|
|
245
|
+
|
|
246
|
+
运行时解析节点端口的优先级如下:
|
|
247
|
+
|
|
248
|
+
1. `definition.getPorts(node)`
|
|
249
|
+
2. `node.ports`
|
|
250
|
+
3. 默认四向端口(top/right/bottom/left)
|
|
251
|
+
|
|
252
|
+
这意味着:
|
|
253
|
+
|
|
254
|
+
- 不写 `getPorts` 且 `node.ports` 也未提供时,引擎会自动补一套默认四向端口,位置位于四条边中点
|
|
255
|
+
- 默认 quick-add 会直接绑定到这套默认端口中的 `group: 'right'`,因此普通自定义节点只定义 `component/getSize/getBehavior` 也能保持默认右侧交互
|
|
256
|
+
- 引擎内置的是四个方向端口组的默认位置和样式模板;默认兜底端口也复用这套约定
|
|
257
|
+
- 如果你想显式禁用端口,需要返回空数组,例如 `getPorts: () => []` 或设置 `node.ports = []`
|
|
258
|
+
|
|
259
|
+
推荐使用方式:
|
|
260
|
+
|
|
261
|
+
- 端口结构按节点类型固定时,用 `getPorts`
|
|
262
|
+
- 端口结构需要根据当前节点数据动态计算时,用 `getPorts`
|
|
263
|
+
- 端口本身属于业务数据、需要随 `FlowModel` 持久化或导入导出时,用 `node.ports`
|
|
264
|
+
- 如果同时提供了 `getPorts` 和 `node.ports`,运行时以前者为准
|
|
265
|
+
|
|
242
266
|
### 边类型定义
|
|
243
267
|
|
|
244
268
|
```typescript
|
|
@@ -347,6 +371,27 @@ const { schema, paletteItems } = createDefaultSchema({
|
|
|
347
371
|
});
|
|
348
372
|
```
|
|
349
373
|
|
|
374
|
+
**在自定义 Schema 中复用内置边类型:**
|
|
375
|
+
|
|
376
|
+
当你没有使用 `createDefaultSchema()`,而是像适配层那样手写 `CanvasSchema` 时,可以通过 `createBuiltinEdgeTypes()` 直接复用引擎内置的 `manhattan` / `bezier` 定义,避免在业务包里重复拷贝一份。
|
|
377
|
+
|
|
378
|
+
```typescript
|
|
379
|
+
import { createBuiltinEdgeTypes, type CanvasSchema } from '@blueking/flow-canvas';
|
|
380
|
+
|
|
381
|
+
const builtinEdgeTypes = createBuiltinEdgeTypes();
|
|
382
|
+
|
|
383
|
+
const schema: CanvasSchema = {
|
|
384
|
+
nodeTypes: {
|
|
385
|
+
/* ... */
|
|
386
|
+
},
|
|
387
|
+
edgeTypes: {
|
|
388
|
+
default: { ...builtinEdgeTypes.manhattan, labelDraggable: true },
|
|
389
|
+
...builtinEdgeTypes,
|
|
390
|
+
},
|
|
391
|
+
defaultEdgeType: 'bezier',
|
|
392
|
+
};
|
|
393
|
+
```
|
|
394
|
+
|
|
350
395
|
**手动定义边类型(不使用 `createDefaultSchema`):**
|
|
351
396
|
|
|
352
397
|
在手动编写 `CanvasSchema` 时,同样可以通过 `edgeTypes` 和 `defaultEdgeType` 配置连线样式:
|
|
@@ -611,7 +656,7 @@ if (result.status === 'applied') {
|
|
|
611
656
|
| editor | `CanvasEditorContext` | 编辑器实例(必填) |
|
|
612
657
|
| graphOptions | `Record<string, unknown>` | 额外 X6 Graph 选项 |
|
|
613
658
|
| nodeActions | `NodeActionsConfig` | 节点快捷操作工具栏配置(见下方详细说明) |
|
|
614
|
-
| quickAdd | `QuickAddConfig` |
|
|
659
|
+
| quickAdd | `QuickAddConfig` | 快捷添加按钮配置(默认绑定右侧端口,见下方详细说明) |
|
|
615
660
|
|
|
616
661
|
| Emit | 参数 | 说明 |
|
|
617
662
|
| -------- | --------------- | -------------------- |
|
|
@@ -619,7 +664,7 @@ if (result.status === 'applied') {
|
|
|
619
664
|
|
|
620
665
|
| Slot | Props | 说明 |
|
|
621
666
|
| --------------- | ------------------------------------------------ | ----------------------------------------------------------- |
|
|
622
|
-
| quick-add-panel | `{ node, api, insertNodeToRight, closePopover }` |
|
|
667
|
+
| quick-add-panel | `{ node, api, insertNodeToRight, closePopover }` | 快捷添加弹层内容,点击绑定端口上的"+"按钮时显示(默认显示提示文字) |
|
|
623
668
|
|
|
624
669
|
#### 节点快捷操作工具栏
|
|
625
670
|
|
|
@@ -665,10 +710,10 @@ if (result.status === 'applied') {
|
|
|
665
710
|
|
|
666
711
|
#### 节点快捷添加按钮(Quick Add)
|
|
667
712
|
|
|
668
|
-
hover
|
|
713
|
+
hover 节点时,指定端口会显示为"+"按钮,支持点击弹出面板和拖拽发起连线。默认绑定右侧 `group: 'right'` 端口。通过 `quickAdd` prop 进行全局配置:
|
|
669
714
|
|
|
670
715
|
```html
|
|
671
|
-
<CanvasRuntime :editor="editor" :quick-add="{ enabled: true }">
|
|
716
|
+
<CanvasRuntime :editor="editor" :quick-add="{ enabled: true, portGroup: 'right' }">
|
|
672
717
|
<template #quick-add-panel="{ node, api, insertNodeToRight, closePopover }">
|
|
673
718
|
<!-- 自定义节点选择面板 -->
|
|
674
719
|
</template>
|
|
@@ -677,10 +722,13 @@ hover 节点时,右侧端口显示为"+"按钮,支持点击弹出面板和
|
|
|
677
722
|
|
|
678
723
|
**QuickAddConfig(全局配置)**
|
|
679
724
|
|
|
680
|
-
| 属性 | 类型 | 默认
|
|
681
|
-
| ------------- | --------- |
|
|
682
|
-
| `enabled` | `boolean` | `true`
|
|
683
|
-
| `tooltipText` | `string` | `''`
|
|
725
|
+
| 属性 | 类型 | 默认 | 说明 |
|
|
726
|
+
| ------------- | --------- | --------- | -------------------------------------------------------------- |
|
|
727
|
+
| `enabled` | `boolean` | `true` | 全局开关 |
|
|
728
|
+
| `tooltipText` | `string` | `''` | 自定义 tooltip 文案(空值使用内置提示) |
|
|
729
|
+
| `portGroup` | `string` | `'right'` | quick-add 默认绑定的端口分组;节点不存在该分组端口时不显示 quick-add |
|
|
730
|
+
| `getPort` | `function` | - | 精确指定当前节点使用哪个 port;优先级高于 `portGroup` |
|
|
731
|
+
| `insertDirection` | `string \| function` | - | 点击 quick-add 插入节点时使用的方向;默认跟随当前绑定 port 的标准方向,不可推断时回退为 `'right'` |
|
|
684
732
|
|
|
685
733
|
**NodeBehaviorConfig 中的快捷添加相关字段(逐节点控制)**
|
|
686
734
|
|
|
@@ -690,13 +738,51 @@ hover 节点时,右侧端口显示为"+"按钮,支持点击弹出面板和
|
|
|
690
738
|
|
|
691
739
|
生效规则:显示 = `global.enabled !== false` AND `perNode.quickAddEnabled !== false`。
|
|
692
740
|
|
|
741
|
+
对于未显式提供 `getPorts` / `node.ports` 的自定义节点,quick-add 会落到引擎自动补齐的默认四向端口上,因此默认右侧交互仍然可用。
|
|
742
|
+
|
|
743
|
+
`getPort(node, ports)` 优先级高于 `portGroup`,适合一个节点存在多个同分组 port,或端口选择依赖节点数据的场景。
|
|
744
|
+
|
|
745
|
+
`insertDirection` 用于控制点击 quick-add 后的插入方向:
|
|
746
|
+
|
|
747
|
+
- 不传时:优先跟随当前绑定 port 的标准方向(`top/right/bottom/left`)
|
|
748
|
+
- 如果当前绑定 port 不是标准方向:回退为 `'right'`
|
|
749
|
+
- 传字符串时:固定使用该方向
|
|
750
|
+
- 传函数时:可根据节点和当前绑定 port 动态决定方向
|
|
751
|
+
|
|
752
|
+
`portGroup` / `getPort` 只控制 quick-add 绑定到哪个端口、"+"按钮显示在哪个端口上,以及拖拽从哪个端口发起。
|
|
753
|
+
|
|
754
|
+
slot 中提供的 `insertNodeToRight` helper 出于兼容仍保留这个名字,但它现在会遵循 `insertDirection` 的配置,不再总是向右插入。
|
|
755
|
+
|
|
756
|
+
**自定义 quick-add 端口选择:**
|
|
757
|
+
|
|
758
|
+
```vue
|
|
759
|
+
<CanvasRuntime
|
|
760
|
+
:editor="editor"
|
|
761
|
+
:quick-add="{
|
|
762
|
+
enabled: true,
|
|
763
|
+
portGroup: 'right',
|
|
764
|
+
getPort: (node, ports) => {
|
|
765
|
+
if (node.type === 'gateway') {
|
|
766
|
+
return ports.find((port) => port.id === 'branch_out_main') ?? null;
|
|
767
|
+
}
|
|
768
|
+
return null; // 返回 null 时退回使用 portGroup
|
|
769
|
+
},
|
|
770
|
+
insertDirection: (node, port) => {
|
|
771
|
+
if (node.type === 'gateway' && port?.group === 'bottom') {
|
|
772
|
+
return 'bottom';
|
|
773
|
+
}
|
|
774
|
+
return null; // 返回 null 时按默认推导
|
|
775
|
+
},
|
|
776
|
+
}" />
|
|
777
|
+
```
|
|
778
|
+
|
|
693
779
|
**quick-add-panel Slot Props**
|
|
694
780
|
|
|
695
781
|
| Prop | 类型 | 说明 |
|
|
696
782
|
| ------------------- | ------------------------------------------------- | ------------------------------- |
|
|
697
783
|
| `node` | `FlowNodeModel` | 当前触发的源节点 |
|
|
698
784
|
| `api` | `CanvasApi` | 画布 API |
|
|
699
|
-
| `insertNodeToRight` | `(node: Omit<FlowNodeModel, 'position'>) => void` | 快捷插入方法(自动连线 +
|
|
785
|
+
| `insertNodeToRight` | `(node: Omit<FlowNodeModel, 'position'>) => void` | 快捷插入方法(自动连线 + 事件);方向遵循 `insertDirection` 配置 |
|
|
700
786
|
| `closePopover` | `() => void` | 关闭弹层 |
|
|
701
787
|
|
|
702
788
|
操作触发后通过 `@ui-event` 发出对应事件:`node.quick-add`(弹层打开时)/ `node.action.quick-insert`(插入成功时)。
|
|
@@ -706,7 +792,7 @@ hover 节点时,右侧端口显示为"+"按钮,支持点击弹出面板和
|
|
|
706
792
|
```vue
|
|
707
793
|
<template>
|
|
708
794
|
<CanvasLayout :editor="editor" :palette-items="paletteItems">
|
|
709
|
-
<CanvasRuntime :editor="editor" :quick-add="{ enabled: true }" @ui-event="handleUiEvent">
|
|
795
|
+
<CanvasRuntime :editor="editor" :quick-add="{ enabled: true, portGroup: 'right' }" @ui-event="handleUiEvent">
|
|
710
796
|
<template #quick-add-panel="{ node, insertNodeToRight, closePopover }">
|
|
711
797
|
<div class="quick-add-menu">
|
|
712
798
|
<div class="quick-add-menu__title">选择节点类型</div>
|
|
@@ -963,6 +1049,42 @@ const customItems = [
|
|
|
963
1049
|
| description | `string` | 操作说明,有值时 hover 显示 tooltip 气泡 |
|
|
964
1050
|
| onClick | `(ctx: CanvasCallbackContext) => void` | 点击回调 |
|
|
965
1051
|
|
|
1052
|
+
#### 通过 CSS 变量定制工具栏样式与位置
|
|
1053
|
+
|
|
1054
|
+
`CanvasToolbar` 通过 CSS 自定义属性暴露了位置和外观的定制接口,使用方在父元素上设置对应变量即可覆盖默认值:
|
|
1055
|
+
|
|
1056
|
+
| CSS 变量 | 默认值 | 说明 |
|
|
1057
|
+
| --------------------------------- | --------------------------- | -------------------- |
|
|
1058
|
+
| `--flow-canvas-toolbar-top` | `16px` | 工具栏距画布顶部距离 |
|
|
1059
|
+
| `--flow-canvas-toolbar-left` | `16px` | 工具栏距画布左侧距离 |
|
|
1060
|
+
| `--flow-canvas-toolbar-right` | `auto` | 工具栏距画布右侧距离 |
|
|
1061
|
+
| `--flow-canvas-toolbar-bottom` | `auto` | 工具栏距画布底部距离 |
|
|
1062
|
+
| `--flow-canvas-toolbar-bg` | `#565e7a` | 工具栏背景色 |
|
|
1063
|
+
| `--flow-canvas-toolbar-color` | `#f5f7fa` | 工具栏文字/图标颜色 |
|
|
1064
|
+
| `--flow-canvas-toolbar-hover-bg` | `rgba(255, 255, 255, 0.15)` | 按钮 hover 背景色 |
|
|
1065
|
+
| `--flow-canvas-toolbar-active-bg` | `rgba(255, 255, 255, 0.25)` | 按钮激活态背景色 |
|
|
1066
|
+
|
|
1067
|
+
**示例 — 将工具栏移至画布底部居中,并更换背景色:**
|
|
1068
|
+
|
|
1069
|
+
```vue
|
|
1070
|
+
<template>
|
|
1071
|
+
<CanvasLayout :editor="editor" :palette-items="paletteItems" class="my-canvas-wrapper">
|
|
1072
|
+
<CanvasRuntime :editor="editor" />
|
|
1073
|
+
<CanvasToolbar :editor="editor" />
|
|
1074
|
+
</CanvasLayout>
|
|
1075
|
+
</template>
|
|
1076
|
+
|
|
1077
|
+
<style scoped>
|
|
1078
|
+
.my-canvas-wrapper {
|
|
1079
|
+
--flow-canvas-toolbar-top: auto;
|
|
1080
|
+
--flow-canvas-toolbar-bottom: 16px;
|
|
1081
|
+
--flow-canvas-toolbar-left: 50%;
|
|
1082
|
+
--flow-canvas-toolbar-right: auto;
|
|
1083
|
+
--flow-canvas-toolbar-bg: #1a1a2e;
|
|
1084
|
+
}
|
|
1085
|
+
</style>
|
|
1086
|
+
```
|
|
1087
|
+
|
|
966
1088
|
<br>
|
|
967
1089
|
|
|
968
1090
|
## 自定义节点组件
|
|
@@ -1096,7 +1218,7 @@ const schema: CanvasSchema = {
|
|
|
1096
1218
|
| exportAsImage(options?) | 导出为 PNG Blob |
|
|
1097
1219
|
| exportAsSVG() | 导出为 SVG 字符串 |
|
|
1098
1220
|
| overlay | `OverlayManager` 实例,提供节点屏幕定位 |
|
|
1099
|
-
| insertNodeToRight(sourceNodeId, node, options?) |
|
|
1221
|
+
| insertNodeToRight(sourceNodeId, node, options?) | 默认在指定节点右侧插入新节点;传 `options.direction` 后可改为上/右/下/左方向,并支持自动连线和重叠检测 |
|
|
1100
1222
|
| getContextMenuItems(position) | 收集插件提供的右键菜单项 |
|
|
1101
1223
|
| onGraphEvent(event, handler) | 监听 X6 底层事件,返回取消函数 |
|
|
1102
1224
|
| unsafeGetGraph() | 获取 X6 Graph 实例(谨慎使用) |
|
|
@@ -1226,6 +1348,7 @@ const myPlugin: CanvasPlugin = {
|
|
|
1226
1348
|
| 导出 | 说明 |
|
|
1227
1349
|
| ------------------------------------------------- | --------------------------------------------------------------------------------- |
|
|
1228
1350
|
| `createEmptyFlowModel()` | 创建一个空的 FlowModel(`version: '1.0'`, 空 nodes/edges) |
|
|
1351
|
+
| `createBuiltinEdgeTypes()` | 返回引擎内置的 `manhattan` / `bezier` 边类型定义,适合自定义 Schema 直接复用 |
|
|
1229
1352
|
| `generateId()` | 生成唯一 ID |
|
|
1230
1353
|
| `applyCanvasCommand(model, cmd)` | 纯函数 reducer,将单条命令应用到 FlowModel,返回新 FlowModel |
|
|
1231
1354
|
| `createCanvasHistory(initialFlowModel, options?)` | 创建独立的历史管理器实例(通常由 `useCanvasEditor` 内部调用,高级场景可直接使用) |
|
|
@@ -1337,8 +1460,11 @@ editor.history.clear();
|
|
|
1337
1460
|
| `CanvasToolbarItem` | 工具栏项配置 |
|
|
1338
1461
|
| `BuiltinToolbarType` | 内置工具类型(`'undo'` / `'redo'` / `'select'` / `'auto-layout'` / `'search'` / `'minimap'` / `'export'` / `'zoom-in'` / `'zoom-out'` / `'reset'` 等) |
|
|
1339
1462
|
| `NodeActionsConfig` | 节点快捷操作工具栏全局配置(showDebug / showDelete / showCopy / showCopyInsert / showDisconnect / insertGap) |
|
|
1340
|
-
| `QuickAddConfig` | 快捷添加按钮全局配置(enabled / tooltipText)
|
|
1341
|
-
| `
|
|
1463
|
+
| `QuickAddConfig` | 快捷添加按钮全局配置(enabled / tooltipText / portGroup / getPort) |
|
|
1464
|
+
| `QuickAddPortResolver` | quick-add 端口选择回调类型;返回具体 port 后,优先级高于 `portGroup` |
|
|
1465
|
+
| `QuickAddInsertDirectionResolver` | quick-add 插入方向回调类型;返回具体方向后,优先级高于默认方向推导 |
|
|
1466
|
+
| `InsertDirection` | 节点插入方向类型(`'top' \| 'right' \| 'bottom' \| 'left'`) |
|
|
1467
|
+
| `InsertNodeOptions` | `insertNodeToRight` 选项(autoWireEdges / gap / source / label / direction) |
|
|
1342
1468
|
| `ExportOptions` | 导出选项(backgroundColor / padding / quality) |
|
|
1343
1469
|
| `ConnectionValidator` | 连接校验函数类型 |
|
|
1344
1470
|
| `ConnectionValidateContext` | 连接校验上下文 |
|
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Be=Object.create;var ge=Object.defineProperty;var _e=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var Ae=Object.getPrototypeOf,Te=Object.prototype.hasOwnProperty;var Re=(i,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Pe(e))!Te.call(i,n)&&n!==t&&ge(i,n,{get:()=>e[n],enumerable:!(o=_e(e,n))||o.enumerable});return i};var oe=(i,e,t)=>(t=i!=null?Be(Ae(i)):{},Re(e||!i||!i.__esModule?ge(t,"default",{value:i,enumerable:!0}):t,i));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("vue"),$e=require("@antv/x6"),ze=require("@antv/x6-vue-shape");function Le(){return{version:"1.0",nodes:{},edges:{}}}class H extends Error{constructor(e){super(e),this.name="CanvasConstraintError"}}class ke extends Error{constructor(e){super(e),this.name="CanvasSchemaError"}}function ae(i,e,t){if(e.length===0){if(t===void 0)return;if(typeof t!="object"||t===null||Array.isArray(t))throw new Error("Root value of payload/extensions/meta must be an object or undefined");return t}const o=i?{...i}:{};let n=o;for(let a=0;a<e.length-1;a++){const d=e[a],l=n[d];l&&typeof l=="object"&&!Array.isArray(l)?n[d]={...l}:n[d]={},n=n[d]}const r=e[e.length-1];return t===void 0?delete n[r]:n[r]=t,o}function re(i,e){switch(e.type){case"node.add":return Ve(i,e.node);case"node.move":return Oe(i,e.nodeId,e.position);case"node.remove":return je(i,e.nodeId);case"node.update":return Fe(i,e.nodeId,e.patch);case"node.set-payload":return He(i,e.nodeId,e.path,e.value);case"node.set-extensions":return Ue(i,e.nodeId,e.path,e.value);case"edge.add":return qe(i,e.edge);case"edge.remove":return Ge(i,e.edgeId);case"edge.reconnect":return We(i,e.edgeId,e.source,e.target);case"edge.update":return Qe(i,e.edgeId,e.patch);case"edge.set-payload":return Xe(i,e.edgeId,e.path,e.value);case"edge.label.update":return Ke(i,e.edgeId,e.labelId,e.patch);case"model.set-meta":return Ye(i,e.path,e.value);default:throw new H(`Unknown command type: ${e.type}`)}}function ne(i,e){const t=i.nodes[e];if(!t)throw new H(`Node "${e}" does not exist`);return t}function se(i,e){const t=i.edges[e];if(!t)throw new H(`Edge "${e}" does not exist`);return t}function ee(i,e,t){const o=i.nodes[e.nodeId];if(!o)throw new H(`${t} node "${e.nodeId}" does not exist`);if(e.portId&&o.ports&&!o.ports.some(r=>r.id===e.portId))throw new H(`${t} port "${e.portId}" not found on node "${e.nodeId}"`)}function le(i,e,t){return{...i,nodes:{...i.nodes,[e]:t}}}function de(i,e,t){return{...i,edges:{...i.edges,[e]:t}}}function Ve(i,e){if(i.nodes[e.id])throw new H(`Node id "${e.id}" already exists`);return{...i,nodes:{...i.nodes,[e.id]:e}}}function Oe(i,e,t){const o=ne(i,e);return le(i,e,{...o,position:t})}function je(i,e){ne(i,e);const{[e]:t,...o}=i.nodes,n={};for(const[r,a]of Object.entries(i.edges))a.source.nodeId!==e&&a.target.nodeId!==e&&(n[r]=a);return{...i,nodes:o,edges:n}}function Fe(i,e,t){const o=ne(i,e);return le(i,e,{...o,...t,id:o.id})}function He(i,e,t,o){const n=ne(i,e),r=ae(n.payload,t,o);return le(i,e,{...n,payload:r})}function Ue(i,e,t,o){const n=ne(i,e),r=ae(n.extensions,t,o);return le(i,e,{...n,extensions:r})}function qe(i,e){if(i.edges[e.id])throw new H(`Edge id "${e.id}" already exists`);if(ee(i,e.source,"Source"),ee(i,e.target,"Target"),e.labels){const t=new Set;for(const o of e.labels){if(t.has(o.id))throw new H(`Duplicate label id "${o.id}" in edge "${e.id}"`);t.add(o.id)}}return{...i,edges:{...i.edges,[e.id]:e}}}function Ge(i,e){se(i,e);const{[e]:t,...o}=i.edges;return{...i,edges:o}}function We(i,e,t,o){const n=se(i,e),r=t??n.source,a=o??n.target;return ee(i,r,"Source"),ee(i,a,"Target"),de(i,e,{...n,source:r,target:a})}function Qe(i,e,t){const o=se(i,e),n={...o,...t,id:o.id};return t.source&&ee(i,n.source,"Source"),t.target&&ee(i,n.target,"Target"),de(i,e,n)}function Xe(i,e,t,o){const n=se(i,e),r=ae(n.payload,t,o);return de(i,e,{...n,payload:r})}function Ke(i,e,t,o){const n=se(i,e);if(!n.labels)throw new H(`Edge "${e}" has no labels`);const r=n.labels.findIndex(d=>d.id===t);if(r===-1)throw new H(`Label "${t}" not found in edge "${e}"`);const a=[...n.labels];return a[r]={...a[r],...o,id:t},de(i,e,{...n,labels:a})}function Ye(i,e,t){const o=ae(i.meta,e,t);return{...i,meta:o}}function Ee(i,e){const t=e?.maxHistorySize??100,o=s.ref(i),n=[],r=[],a=s.ref(!1),d=s.ref(!1);function l(){a.value=n.length>0,d.value=r.length>0}function u(w){const y=o.value;let b=y;for(const P of w.commands)b=re(b,P);return n.push({snapshot:y,envelope:w}),n.length>t&&n.shift(),r.length=0,o.value=b,l(),b}function c(){const w=n.pop();return w?(r.push({snapshot:o.value,envelope:w.envelope}),o.value=w.snapshot,l(),w.snapshot):null}function h(){const w=r.pop();if(!w)return null;n.push({snapshot:o.value,envelope:w.envelope});let y=o.value;for(const b of w.envelope.commands)y=re(y,b);return o.value=y,l(),y}function g(){n.length=0,r.length=0,l()}function f(){return o.value}function S(w){o.value=w,g()}return{currentFlowModel:o,execute:u,undo:c,redo:h,canUndo:a,canRedo:d,get undoStack(){return n.map(w=>w.envelope)},get redoStack(){return r.map(w=>w.envelope)},clear:g,createSnapshot:f,replaceFlowModel:S}}function Ze(i){return i!==null&&typeof i=="object"&&i.rejected===!0}class Je{plugins=[];editorContext=null;runtimeCtx=null;runtimeVersion=0;install(e,t){this.plugins=[...e].sort((o,n)=>(o.priority??100)-(n.priority??100)),this.editorContext=t;for(const o of this.plugins)o.install?.(t)}attachRuntime(e){const t=++this.runtimeVersion;this.runtimeCtx=e;const o=this.createSafeRuntimeContext(e,t);for(const n of this.plugins)n.attachRuntime?.(o)}detachRuntime(){for(const e of[...this.plugins].reverse())e.detachRuntime?.();this.runtimeCtx=null}createSafeRuntimeContext(e,t){const o=this,n=new Proxy(e.graph,{get(r,a,d){const l=Reflect.get(r,a,d);return a==="use"&&typeof l=="function"?function(...c){if(o.runtimeVersion===t)return l.apply(r,c)}:l}});return{...e,graph:n}}dispose(){for(const e of[...this.plugins].reverse())e.dispose?.();this.plugins=[],this.editorContext=null,this.runtimeCtx=null}transformCommand(e){if(!this.editorContext)return{envelope:e};let t=e;for(const o of this.plugins){if(!o.transformCommand)continue;const n=this.createPreview(t),r=o.transformCommand(t,n,this.editorContext);if(r===null)return{rejected:!0,error:{code:"plugin_rejected",reason:"",source:o.name}};if(Ze(r))return{rejected:!0,error:{code:r.code??"plugin_rejected",reason:r.reason,source:o.name}};t=r}return{envelope:t}}afterCommand(e,t,o){if(this.editorContext)for(const n of this.plugins)n.afterCommand?.(e,t,o,this.editorContext)}dispatchUiEvent(e){if(this.runtimeCtx)for(const t of this.plugins)t.onUiEvent?.(e,this.runtimeCtx)}dispatchSelectionChange(e){if(this.runtimeCtx)for(const t of this.plugins)t.onSelectionChange?.(e,this.runtimeCtx)}dispatchKeyboardShortcut(e){if(!this.runtimeCtx)return!1;for(const t of this.plugins)if(t.onKeyboardShortcut?.(e,this.runtimeCtx))return!0;return!1}collectContextMenuItems(e){if(!this.runtimeCtx)return[];const t=[];for(const o of this.plugins){const n=o.onBlankContextMenu?.(e,this.runtimeCtx);n&&t.push(...n)}return t}collectToolbarItems(){if(!this.editorContext)return[];const e=new Map;for(const t of this.plugins){const o=t.provideToolbarItems?.(this.editorContext);if(o)for(const n of o)e.set(n.id,n)}return[...e.values()].sort((t,o)=>(t.order??0)-(o.order??0))}collectNodeDecorations(e){if(!this.editorContext)return;let t;for(const o of this.plugins){const n=o.decorateNode?.(e,this.editorContext);n&&(t=t?{...t,...n}:n)}return t}collectEdgeDecorations(e){if(!this.editorContext)return;let t;for(const o of this.plugins){const n=o.decorateEdge?.(e,this.editorContext);n&&(t=t?{...t,...n}:n)}return t}collectExtendedApi(){if(!this.runtimeCtx)return{};const e={};for(const t of this.plugins){const o=t.extendApi?.(this.runtimeCtx.api,this.runtimeCtx);o&&Object.assign(e,o)}return e}createPreview(e){const t=this.editorContext;return{previewFlowModel(o){const n=o??e.commands;let r=t.flowModel.value;for(const a of n)r=re(r,a);return r}}}}function et(i){const{schema:e,plugins:t=[],historyOptions:o}=i,n={version:"1.0",...i.initialFlowModel},r=Ee(n,o),a=s.ref(i.mode??"edit"),d=s.ref(!1),l=s.ref(null),u=s.ref([]),c={},h=new Je;function g(y,b,P,v="user:toolbar"){const m={id:`history-${Date.now()}`,source:v,label:y,timestamp:Date.now(),commands:[]};h.afterCommand(m,b,P),u.value=h.collectToolbarItems(),i.onCommandResult?.({status:"applied",envelope:m,flowModel:P}),i.onFlowModelChange?.({flowModel:P,prevFlowModel:b,envelope:m,source:v})}const f={execute:r.execute,undo(){const y=r.currentFlowModel.value,b=r.undo();return b&&g("撤销",y,b),b},redo(){const y=r.currentFlowModel.value,b=r.redo();return b&&g("重做",y,b),b},get canUndo(){return r.canUndo},get canRedo(){return r.canRedo},get undoStack(){return r.undoStack},get redoStack(){return r.redoStack},clear:r.clear,createSnapshot:r.createSnapshot,replaceFlowModel(y){const b=r.currentFlowModel.value;r.replaceFlowModel(y),g("替换 FlowModel",b,y,"system:replace")}},S={flowModel:s.computed(()=>r.currentFlowModel.value),history:f,schema:e,mode:a,executeCommand:w,replaceFlowModel(y){f.replaceFlowModel(y)},setMode(y){a.value=y},selectionMode:d,setSelectionMode(y){d.value=y},api:l,toolbarItems:u,extendedApi:c,_pluginManager:h};h.install(t,{flowModel:S.flowModel,history:f,schema:e,mode:a,executeCommand:w}),u.value=h.collectToolbarItems(),s.onScopeDispose(()=>{h.dispose()});function w(y){const b=h.transformCommand(y);if("rejected"in b){const m={status:"rejected",envelope:y,error:b.error};return i.onCommandResult?.(m),m}const P=b.envelope,v=r.currentFlowModel.value;try{const m=r.execute(P),N={status:"applied",envelope:P,flowModel:m};return h.afterCommand(P,v,m),u.value=h.collectToolbarItems(),i.onCommandResult?.(N),i.onFlowModelChange?.({flowModel:m,prevFlowModel:v,envelope:P,source:P.source}),N}catch(m){if(m instanceof H){const N={status:"invalid",envelope:P,error:{code:"constraint_violated",reason:m.message,source:"engine"}};return i.onCommandResult?.(N),N}throw m}}return S}class tt{graph;schema;shapeRegistry;resolveNodeDecoration;resolveEdgeDecoration;resolveCanvasContext;knownNodeIds=new Set;knownEdgeIds=new Set;syncing=!1;prevNodeDecorationClasses=new Map;prevNodeDecorationColors=new Set;prevEdgeDecorationClasses=new Map;prevEdgeDecorationColors=new Set;highlightedNodeIds=new Set;highlightedEdgeIds=new Set;hoveredEdgeId=null;defaultHighlightedNodeIds=new Set;defaultHighlightedEdgeIds=new Set;prevEdgeStyleIds=new Set;nodeDefaultAttrs=new Map;edgeDefaultAttrs=new Map;lastModel=null;constructor(e,t,o,n,r,a){this.graph=e,this.schema=t,this.shapeRegistry=o,this.resolveNodeDecoration=n,this.resolveEdgeDecoration=r,this.resolveCanvasContext=a}syncFlowModel(e){if(!this.syncing){this.syncing=!0,this.lastModel=e;try{const t=this.resolveNodes(e),o=this.resolveEdges(e);this.syncNodes(t),this.syncEdges(o,e)}finally{this.syncing=!1}}}get isSyncing(){return this.syncing}saveNodeDefaultAttrs(e,t){const n=t.x6CellConfig?.attrs?.body;if(!n)return;const r={};let a=!1;n.stroke!==void 0&&(r.stroke=n.stroke,a=!0),n.strokeWidth!==void 0&&(r.strokeWidth=n.strokeWidth,a=!0),a&&this.nodeDefaultAttrs.set(e,r)}saveEdgeDefaultAttrs(e,t){const n=t?.x6EdgeConfig?.attrs?.line;if(!n)return;const r={};let a=!1;n.stroke!==void 0&&(r.stroke=n.stroke,a=!0),n.strokeWidth!==void 0&&(r.strokeWidth=n.strokeWidth,a=!0),n.strokeDasharray!==void 0&&(r.strokeDasharray=n.strokeDasharray,a=!0),a&&this.edgeDefaultAttrs.set(e,r)}restoreNodeAttr(e,t,o){const n=this.nodeDefaultAttrs.get(e.id)?.[o];n!==void 0?e.setAttrByPath(t,n):e.removeAttrByPath(t)}restoreEdgeAttr(e,t,o){const n=this.edgeDefaultAttrs.get(e.id)?.[o];n!==void 0?e.setAttrByPath(t,n):e.removeAttrByPath(t)}syncEdgeMarker(e,t,o){const r=t?.x6EdgeConfig?.attrs?.line?.[o],a=`line/${o}`;e.removeAttrByPath(a),r!==void 0&&e.setAttrByPath(a,r)}dispose(){this.knownNodeIds.clear(),this.knownEdgeIds.clear()}resolveNodes(e){const t=new Map;for(const[o,n]of Object.entries(e.nodes)){const r=this.schema.nodeTypes[n.type];if(!r)throw new ke(`Unknown node type "${n.type}" for node "${o}". Registered types: [${Object.keys(this.schema.nodeTypes).join(", ")}]. Register the type in CanvasSchema.nodeTypes before using it in a FlowModel.`);const a=this.shapeRegistry.registerNodeType(n.type,r.component),d=r.getSize(n),l=r.getPorts?.(n)??n.ports??[];t.set(o,{model:n,definition:r,shapeName:a,size:d,ports:l})}return t}resolveEdges(e){const t=new Map;for(const[o,n]of Object.entries(e.edges)){const r=n.type??this.schema.defaultEdgeType??"default",a=this.schema.edgeTypes?.[r];t.set(o,{model:n,definition:a})}return t}syncNodes(e){const t=new Set(e.keys());for(const o of this.knownNodeIds)if(!t.has(o)){const n=this.graph.getCellById(o);n&&this.graph.removeCell(n),this.knownNodeIds.delete(o),this.defaultHighlightedNodeIds.delete(o),this.prevNodeDecorationClasses.delete(o),this.prevNodeDecorationColors.delete(o),this.nodeDefaultAttrs.delete(o)}for(const[o,n]of e){const r=this.graph.getCellById(o);r?this.updateExistingNode(r,n):this.addNewNode(o,n)}}updateExistingNode(e,t){const{model:o,size:n,ports:r,definition:a}=t,d=e.getPosition();(d.x!==o.position.x||d.y!==o.position.y)&&e.setPosition(o.position.x,o.position.y);const l=e.getSize();(l.width!==n.width||l.height!==n.height)&&e.setSize(n.width,n.height,{silent:!0}),this.syncNodePorts(e,r),e.setData({...o}),this.applyNodeBehavior(e,o,a),this.applyNodeHighlightAndDecoration(e,o)}syncNodePorts(e,t){const o=e.getPorts(),n=new Set(t.map(a=>a.id)),r=new Set(o.map(a=>a.id));for(const a of o)a.id&&!n.has(a.id)&&e.removePort(a.id);for(const a of t)r.has(a.id)||e.addPort({id:a.id,group:a.group,...a.x6PortConfig})}addNewNode(e,t){const{model:o,shapeName:n,size:r,ports:a,definition:d}=t,l={id:o.id,shape:n,x:o.position.x,y:o.position.y,width:r.width,height:r.height,data:{...o},ports:{groups:{top:{position:"top",attrs:{circle:{r:6,magnet:!0,fill:"#3a84ff",stroke:"#fff",strokeWidth:1,visibility:"hidden"}}},right:{position:"right",attrs:{circle:{r:6,magnet:!0,fill:"#3a84ff",stroke:"#fff",strokeWidth:1,visibility:"hidden"}}},bottom:{position:"bottom",attrs:{circle:{r:6,magnet:!0,fill:"#3a84ff",stroke:"#fff",strokeWidth:1,visibility:"hidden"}}},left:{position:"left",attrs:{circle:{r:6,magnet:!0,fill:"#3a84ff",stroke:"#fff",strokeWidth:1,visibility:"hidden"}}}},items:a.map(c=>({id:c.id,group:c.group,...c.x6PortConfig}))},...d.x6CellConfig};this.graph.addNode(l),this.knownNodeIds.add(e),this.saveNodeDefaultAttrs(e,d);const u=this.graph.getCellById(e);u&&(this.applyNodeBehavior(u,o,d),this.applyNodeHighlightAndDecoration(u,o))}applyNodeBehavior(e,t,o){if(!o.getBehavior)return;const n=this.resolveCanvasContext?.();if(!n)return;const r=o.getBehavior(t,n);if(r.draggable!==void 0&&e.setProp("draggable",r.draggable,{silent:!0}),r.connectable!==void 0){const d=r.connectable;for(const l of e.getPorts())e.setPortProp(l.id,"attrs/circle/magnet",d,{silent:!0})}if(r.showPorts!==void 0){const d=r.showPorts;for(const l of e.getPorts())e.setPortProp(l.id,"attrs/circle/style/visibility",d?"visible":"hidden",{silent:!0})}const a=e.getData()??{};r.deletable!==void 0&&a._deletable!==r.deletable&&e.setData({...a,_deletable:r.deletable},{silent:!0}),r.selectable!==void 0&&a._selectable!==r.selectable&&e.setData({...e.getData(),_selectable:r.selectable},{silent:!0})}syncEdges(e,t){const o=new Set(e.keys());for(const n of this.knownEdgeIds)if(!o.has(n)){const r=this.graph.getCellById(n);r&&this.graph.removeCell(r),this.knownEdgeIds.delete(n),this.defaultHighlightedEdgeIds.delete(n),this.prevEdgeDecorationClasses.delete(n),this.prevEdgeDecorationColors.delete(n),this.prevEdgeStyleIds.delete(n),this.edgeDefaultAttrs.delete(n)}for(const[n,r]of e){const a=this.graph.getCellById(n),{model:d,definition:l}=r;a?(this.updateExistingEdge(a,d,l,t),this.knownEdgeIds.has(n)||(this.knownEdgeIds.add(n),this.saveEdgeDefaultAttrs(n,l))):this.addNewEdge(n,d,l)}}updateExistingEdge(e,t,o,n){const r=e.getSource(),a=e.getTarget();if((r.cell!==t.source.nodeId||r.port!==t.source.portId)&&e.setSource({cell:t.source.nodeId,port:t.source.portId}),(a.cell!==t.target.nodeId||a.port!==t.target.portId)&&e.setTarget({cell:t.target.nodeId,port:t.target.portId}),o?.router){const d=typeof o.router=="string"?{name:o.router}:o.router;e.setRouter(d)}if(o?.connector){const d=typeof o.connector=="string"?{name:o.connector}:o.connector;e.setConnector(d)}this.syncEdgeMarker(e,o,"sourceMarker"),this.syncEdgeMarker(e,o,"targetMarker"),this.syncEdgeLabels(e,t),e.setData({...t},{silent:!0}),this.applyEdgeStyleAndDecoration(e,t,o)}syncEdgeLabels(e,t){if(!t.labels?.length){e.getLabels().length>0&&e.setLabels([]);return}const o=t.labels.map(n=>({attrs:{label:{text:n.text??""}},position:n.position!=null?{distance:n.position}:void 0}));e.setLabels(o)}addNewEdge(e,t,o){const n={id:t.id,source:{cell:t.source.nodeId,port:t.source.portId},target:{cell:t.target.nodeId,port:t.target.portId},data:{...t},zIndex:-1};o?.router&&(n.router=typeof o.router=="string"?{name:o.router}:o.router),o?.connector&&(n.connector=typeof o.connector=="string"?{name:o.connector}:o.connector),o?.x6EdgeConfig&&Object.assign(n,o.x6EdgeConfig),t.labels?.length&&(n.labels=t.labels.map(a=>({attrs:{label:{text:a.text??""}},position:a.position!=null?{distance:a.position}:void 0}))),this.graph.addEdge(n),this.knownEdgeIds.add(e),this.saveEdgeDefaultAttrs(e,o);const r=this.graph.getCellById(e);r&&this.applyEdgeStyleAndDecoration(r,t,o)}refreshEdgeStyles(){if(this.lastModel)for(const[e,t]of Object.entries(this.lastModel.edges)){const o=this.graph.getCellById(e);if(!o?.isEdge())continue;const n=t.type??this.schema.defaultEdgeType??"default",r=this.schema.edgeTypes?.[n];this.applyEdgeStyleAndDecoration(o,t,r)}}refreshNodeHighlights(){if(this.lastModel)for(const[e,t]of Object.entries(this.lastModel.nodes)){const o=this.graph.getCellById(e);o?.isNode()&&this.applyNodeHighlightAndDecoration(o,t)}}applyNodeHighlightAndDecoration(e,t){const o=this.highlightedNodeIds.has(e.id),n=this.resolveNodeDecoration?.(t),r=this.prevNodeDecorationClasses.get(e.id);r&&(this.graph.findViewByCell(e)?.container?.classList.remove(r),this.prevNodeDecorationClasses.delete(e.id)),n?.className&&(this.graph.findViewByCell(e)?.container?.classList.add(n.className),this.prevNodeDecorationClasses.set(e.id,n.className));const a=n?.borderColor,l=a??(o?"#3a84ff":void 0),u=this.prevNodeDecorationColors.has(e.id)||this.defaultHighlightedNodeIds.has(e.id);l?(e.setAttrByPath("body/stroke",l),e.setAttrByPath("body/strokeWidth",2)):u&&(this.restoreNodeAttr(e,"body/stroke","stroke"),this.restoreNodeAttr(e,"body/strokeWidth","strokeWidth")),a?this.prevNodeDecorationColors.add(e.id):this.prevNodeDecorationColors.delete(e.id),o&&!a?this.defaultHighlightedNodeIds.add(e.id):this.defaultHighlightedNodeIds.delete(e.id)}setHoveredEdge(e){this.hoveredEdgeId=e}setHighlightedNodes(e){this.highlightedNodeIds=new Set(e)}setHighlightedEdges(e){this.highlightedEdgeIds=new Set(e)}applyEdgeStyleAndDecoration(e,t,o){const n=this.highlightedEdgeIds.has(e.id),r=this.resolveEdgeDecoration?.(t),a=this.prevEdgeDecorationClasses.get(e.id);a&&(this.graph.findViewByCell(e)?.container?.classList.remove(a),this.prevEdgeDecorationClasses.delete(e.id)),r?.className&&(this.graph.findViewByCell(e)?.container?.classList.add(r.className),this.prevEdgeDecorationClasses.set(e.id,r.className));let d,l,u;if(o?.style){const S=this.graph.isSelected?.(e)??!1,w=this.hoveredEdgeId===e.id,y=o.style(t,{selected:S,highlighted:n,hovered:w});d=y.stroke,l=y.strokeWidth,u=y.strokeDasharray}const c=!o?.style&&n?"#3a84ff":void 0,h=r?.strokeColor,g=h??d??c,f=!!o?.style||this.prevEdgeDecorationColors.has(e.id)||this.defaultHighlightedEdgeIds.has(e.id)||this.prevEdgeStyleIds.has(e.id);g?e.setAttrByPath("line/stroke",g):f&&this.restoreEdgeAttr(e,"line/stroke","stroke"),o?.style?(this.prevEdgeStyleIds.add(e.id),l?e.setAttrByPath("line/strokeWidth",l):this.restoreEdgeAttr(e,"line/strokeWidth","strokeWidth"),u?e.setAttrByPath("line/strokeDasharray",u):this.restoreEdgeAttr(e,"line/strokeDasharray","strokeDasharray")):this.prevEdgeStyleIds.has(e.id)&&(this.restoreEdgeAttr(e,"line/strokeWidth","strokeWidth"),this.restoreEdgeAttr(e,"line/strokeDasharray","strokeDasharray"),this.prevEdgeStyleIds.delete(e.id)),h?this.prevEdgeDecorationColors.add(e.id):this.prevEdgeDecorationColors.delete(e.id),c?this.defaultHighlightedEdgeIds.add(e.id):this.defaultHighlightedEdgeIds.delete(e.id)}}let ot=0;function _(){const i=Date.now().toString(36),e=Math.random().toString(36).substring(2,8);return`${i}-${e}-${++ot}`}class nt{instanceId=_();registeredShapes=new Map;getShapeName(e){let t=this.registeredShapes.get(e);return t||(t=`flow-node-${this.instanceId}-${e}`,this.registeredShapes.set(e,t)),t}registerNodeType(e,t){const o=this.getShapeName(e);return ze.register({shape:o,component:t,width:100,height:40}),o}dispose(){this.registeredShapes.clear()}}class st{graph;onUiEvent;onCommand;flowModelRef;disposers=[];constructor(e,t,o,n){this.graph=e,this.onUiEvent=t,this.onCommand=o,this.flowModelRef=n,this.bindEvents()}dispose(){for(const e of this.disposers)e();this.disposers=[]}bindEvents(){this.on("node:click",({node:e})=>{this.onUiEvent({type:"node.click",nodeId:e.id})}),this.on("node:dblclick",({node:e})=>{this.onUiEvent({type:"node.dblclick",nodeId:e.id})}),this.on("node:contextmenu",({node:e,e:t})=>{this.onUiEvent({type:"node.contextmenu",nodeId:e.id,position:{x:t.clientX,y:t.clientY}})}),this.on("edge:click",({edge:e,e:t})=>{const n=t.target?.closest?.(".x6-edge-label");if(n){const a=e.getData?.()?.labels??[],d=n.parentElement?.querySelectorAll(".x6-edge-label"),l=d?Array.from(d).indexOf(n):0,u=a[Math.max(0,l)];this.onUiEvent({type:"edge.label.click",edgeId:e.id,labelId:u?.id??`label-${l}`});return}this.onUiEvent({type:"edge.click",edgeId:e.id})}),this.on("blank:click",({e})=>{const t=this.graph.clientToLocal(e.clientX,e.clientY);this.onUiEvent({type:"blank.click",position:{x:t.x,y:t.y}})}),this.on("blank:contextmenu",({e})=>{this.onUiEvent({type:"blank.contextmenu",position:{x:e.clientX,y:e.clientY}})}),this.on("node:moved",({node:e})=>{const t=e.getPosition();this.onCommand({id:_(),source:"user:drag",label:"移动节点",timestamp:Date.now(),commands:[{type:"node.move",nodeId:e.id,position:{x:t.x,y:t.y}}]})}),this.on("edge:connected",({edge:e,isNew:t})=>{const o=e.getSourceCell(),n=e.getTargetCell();if(!o||!n)return;const r=e.getSourcePortId(),a=e.getTargetPortId(),d=e.id in this.flowModelRef.value.edges;t&&!d?this.onCommand({id:_(),source:"user:drag",label:"连线",timestamp:Date.now(),commands:[{type:"edge.add",edge:{id:e.id,source:{nodeId:o.id,portId:r??void 0},target:{nodeId:n.id,portId:a??void 0}}}]}):this.onCommand({id:_(),source:"user:drag",label:"重连",timestamp:Date.now(),commands:[{type:"edge.reconnect",edgeId:e.id,source:{nodeId:o.id,portId:r??void 0},target:{nodeId:n.id,portId:a??void 0}}]})}),this.on("edge:change:labels",({edge:e,current:t})=>{const n=e.getData?.()?.labels??[];if(!n.length||!t?.length)return;const r=[];for(let a=0;a<Math.min(n.length,t.length);a++){const d=t[a],l=n[a];if(!l?.id)continue;const u=typeof d.position=="object"?d.position?.distance:d.position;u!=null&&r.push({type:"edge.label.update",edgeId:e.id,labelId:l.id,patch:{position:u}})}r.length&&this.onCommand({id:_(),source:"user:drag",label:"拖动标签",timestamp:Date.now(),commands:r})})}on(e,t){this.graph.on(e,t),this.disposers.push(()=>this.graph.off(e,t))}}function it(i){function e(t){const o=i.getCellById(t);if(!o||!o.isNode())return null;const n=o,r=n.getPosition(),a=n.getSize(),d={x:r.x,y:r.y,width:a.width,height:a.height},l=i.localToGraph(d);return new DOMRect(l.x,l.y,l.width,l.height)}return{getNodeScreenRect:e}}const rt=100;function at({graph:i,overlayManager:e,executeCommand:t,schema:o,flowModel:n,defaultInsertGap:r,getContextMenuItems:a,onHighlightChange:d,resolveNodeShape:l}){let u=[],c=[],h=null,g=!1,f=null,S=!1;async function w(){if(g)return h;g=!0;try{const v=await import("@antv/x6-plugin-dnd"),m=v.Dnd??v.default;return m?(h=new m({target:i,scaled:!0,animation:!0,getDragNode:N=>N.clone(),getDropNode:N=>N.clone()}),h):null}catch{return console.warn("[flow-canvas] @antv/x6-plugin-dnd not available, add it to your dependencies"),null}}async function y(){if(!S){S=!0;try{const v=await import("@antv/x6-plugin-export"),m=v.Export??v.default;m&&i.use(new m)}catch{console.warn("[flow-canvas] @antv/x6-plugin-export not available, add it to your dependencies")}}}const b=({node:v})=>{const m=v.getData?.();if(!m?._dndSessionId||m._dndSessionId!==f)return;f=null;const N=v.getPosition();i.removeNode(v.id);const{_dndSessionId:T,...M}=m,C=M.id||_();t({id:_(),source:"user:drag",label:"拖入节点",timestamp:Date.now(),commands:[{type:"node.add",node:{...M,id:C,position:{x:N.x,y:N.y}}}]})};return i.on("node:added",b),{zoomIn(){i.zoom(.1)},zoomOut(){i.zoom(-.1)},zoomTo(v){i.zoomTo(v)},zoomToFit(){i.zoomToFit({padding:40,maxScale:1.5})},getZoom(){return i.zoom()},centerContent(){i.centerContent()},scrollToOrigin(){i.translate(0,0)},scrollToNode(v){const m=i.getCellById(v);m&&i.centerCell(m)},getSelection(){const v=i.getSelectedCells?.()??[];return{nodeIds:v.filter(m=>m.isNode()).map(m=>m.id),edgeIds:v.filter(m=>m.isEdge()).map(m=>m.id)}},selectNodes(v){const m=v.map(N=>i.getCellById(N)).filter(Boolean);i.select?.(m)},selectEdges(v){const m=v.map(N=>i.getCellById(N)).filter(Boolean);i.select?.(m)},clearSelection(){const v=i.getSelectedCells?.();v?.length&&i.unselect?.(v)},registerDndSource(v,m){const N=async T=>{const M=await w();if(!M)return;const C=_();f=C;const z=m(),q=l?.(z.type),V=i.createNode({width:q?.width??154,height:q?.height??54,shape:q?.shapeName??"rect",data:{...z,_dndSessionId:C}});M.start(V,T)};return v.addEventListener("mousedown",N),()=>{v.removeEventListener("mousedown",N)}},startConnection(v,m){const N=i.getCellById(v);if(!N?.isNode())return;const T=N,M=i.findViewByCell(T);if(!M)return;const C=M.findPortElem(m,"circle")??M.findPortElem(m);if(!C)return;const q=(C.matches?.("[magnet]")?C:C.querySelector?.("[magnet]"))??C,V=q.getBoundingClientRect(),F=V.left+V.width/2,U=V.top+V.height/2,O=new MouseEvent("mousedown",{clientX:F,clientY:U,button:0,buttons:1,bubbles:!0,cancelable:!0});q.dispatchEvent(O)},async exportAsImage(v){await y();const m=i;return typeof m.toPNG!="function"?(console.warn("[flow-canvas] exportAsImage requires @antv/x6-plugin-export, add it to your dependencies"),new Blob):new Promise(N=>{m.toPNG(T=>{fetch(T).then(M=>M.blob()).then(N).catch(()=>N(new Blob))},{backgroundColor:v?.backgroundColor??"#ffffff",padding:v?.padding??20,quality:v?.quality,copyStyles:!0})})},async exportAsSVG(){await y();const v=i;return typeof v.toSVG!="function"?(console.warn("[flow-canvas] exportAsSVG requires @antv/x6-plugin-export, add it to your dependencies"),""):new Promise(m=>{v.toSVG(N=>m(N))})},highlightNodes(v){u=v,d?.(u,c)},highlightEdges(v){c=v,d?.(u,c)},clearHighlight(){u=[],c=[],d?.([],[])},overlay:e,getContextMenuItems(v){return a?.(v)??[]},insertNodeToRight(v,m,N){const T=n.value,M=T.nodes[v];if(!M)return{status:"invalid",envelope:{id:"",source:"user:toolbar",timestamp:Date.now(),commands:[]},error:{code:"constraint_violated",reason:`Source node "${v}" not found`,source:"api"}};const C=N?.gap??r??rt,z=o.nodeTypes[M.type],q=o.nodeTypes[m.type],V=z?.getSize(M)??{width:154,height:54},F=q?.getSize({...m,position:{x:0,y:0}})??{width:154,height:54},U={x:M.position.x+V.width+C,y:M.position.y+(V.height-F.height)/2},O=m.id||_(),Z={...m,id:O,position:U},Q=[{type:"node.add",node:Z}],ce=F.width+C,X={x:U.x,y:U.y,width:F.width,height:F.height};for(const[G,j]of Object.entries(T.nodes)){if(G===v||G===O)continue;const K=o.nodeTypes[j.type]?.getSize(j)??{width:154,height:54},L=X.x<j.position.x+K.width&&X.x+X.width>j.position.x,E=X.y<j.position.y+K.height&&X.y+X.height>j.position.y;L&&E&&Q.push({type:"node.move",nodeId:G,position:{x:j.position.x+ce,y:j.position.y}})}if(N?.autoWireEdges){const G=M.ports?.find(L=>L.group==="right"),j=Z.ports?.find(L=>L.group==="left"),te=Z.ports?.find(L=>L.group==="right"),K=G?Object.values(T.edges).find(L=>L.source.nodeId===v&&L.source.portId===G.id):Object.values(T.edges).find(L=>L.source.nodeId===v);if(K){const L=K.target;Q.push({type:"edge.remove",edgeId:K.id}),Q.push({type:"edge.add",edge:{id:_(),source:{nodeId:v,portId:G?.id},target:{nodeId:O,portId:j?.id}}}),Q.push({type:"edge.add",edge:{id:_(),source:{nodeId:O,portId:te?.id},target:L}})}else Q.push({type:"edge.add",edge:{id:_(),source:{nodeId:v,portId:G?.id},target:{nodeId:O,portId:j?.id}}})}const ie={id:_(),source:N?.source??"user:toolbar",label:N?.label??"插入节点",timestamp:Date.now(),commands:Q};return t(ie)},onGraphEvent(v,m){return i.on(v,m),()=>i.off(v,m)},unsafeGetGraph(){return i}}}function lt(){const i=s.ref(null),e=s.ref(!1);let t=null,o=!1;function n(c){t&&(clearTimeout(t),t=null),i.value=c}function r(c=100){o||(t&&clearTimeout(t),t=setTimeout(()=>{i.value=null,t=null},c))}function a(){o=!0,t&&(clearTimeout(t),t=null)}function d(c=100){o=!1,r(c)}function l(){t&&(clearTimeout(t),t=null)}function u(){t&&clearTimeout(t)}return{hoveredNodeId:i,isDraggingNode:e,enter:n,leave:r,enterOverlay:a,leaveOverlay:d,cancelLeave:l,cleanup:u}}const he=10;function ve(i,e){const t=i.getTotalLength();if(t===0)return{...e,length:0,totalLength:0};let o=i.getPointAtLength(0),n=1/0;const r=50,a=t/r;let d=0;for(let h=0;h<=r;h++){const g=h*a,f=i.getPointAtLength(g),S=(f.x-e.x)**2+(f.y-e.y)**2;S<n&&(n=S,o=f,d=g)}const l=Math.max(0,d-a),u=Math.min(t,d+a),c=(u-l)/20;for(let h=l;h<=u;h+=c){const g=i.getPointAtLength(h),f=(g.x-e.x)**2+(g.y-e.y)**2;f<n&&(n=f,o=g,d=h)}return{x:o.x,y:o.y,length:d,totalLength:t}}function me(i,e){return i<he||i>e-he}function ye(){const i="http://www.w3.org/2000/svg",e=document.createElementNS(i,"g");e.setAttribute("class","flow-canvas-edge-delete-tool"),e.style.cursor="pointer";const t=document.createElementNS(i,"rect");t.setAttribute("width","20"),t.setAttribute("height","20"),t.setAttribute("x","-10"),t.setAttribute("y","-10"),t.setAttribute("rx","4"),t.setAttribute("ry","4"),t.setAttribute("fill","#3a84ff"),e.appendChild(t);const o=document.createElementNS(i,"text");return o.setAttribute("font-family","flow-canvas"),o.setAttribute("font-size","16"),o.setAttribute("fill","#ffffff"),o.setAttribute("text-anchor","middle"),o.setAttribute("dominant-baseline","central"),o.textContent="",e.appendChild(o),e}function dt(i){let e=null,t=null;function o(d,l){r(),t=d;const u=i.getCellById(d);if(!u?.isEdge())return;const c=i.findViewByCell(u);if(!c)return;const h=c.container.querySelector("path");if(!h)return;const g=i.clientToLocal(l.clientX,l.clientY),f=ve(h,g);if(me(f.length,f.totalLength))return;const S=ye();S.setAttribute("transform",`translate(${f.x}, ${f.y})`),c.container.appendChild(S),e=S}function n(d){if(!t)return;const l=i.getCellById(t);if(!l?.isEdge())return;const u=i.findViewByCell(l);if(!u)return;const c=u.container.querySelector("path");if(!c)return;const h=i.clientToLocal(d.clientX,d.clientY),g=ve(c,h);if(me(g.length,g.totalLength))e&&e.setAttribute("display","none");else if(e)e.removeAttribute("display"),e.setAttribute("transform",`translate(${g.x}, ${g.y})`);else{const f=ye();f.setAttribute("transform",`translate(${g.x}, ${g.y})`),u.container.appendChild(f),e=f}}function r(){e&&(e.remove(),e=null),t=null}function a(d){d===t&&(e=null,t=null)}return{show:o,move:n,remove:r,handleEdgeRemoved:a}}function ct(i){let e=null,t=0;function o(c){const h=c?"visible":"hidden";for(const g of i.getNodes())for(const f of g.getPorts())g.setPortProp(f.id,"attrs/circle/visibility",h)}function n(c){if(!e)for(const h of c.getPorts())c.setPortProp(h.id,"attrs/circle/visibility","visible")}function r(c){if(!e)for(const h of c.getPorts())c.setPortProp(h.id,"attrs/circle/visibility","hidden")}function a(c){c.getTargetCell()||(e=c.id,o(!0))}function d(){e=null,o(!1),t=Date.now()+300}function l(c){c===e&&(e=null,o(!1))}function u(){return!e&&Date.now()>=t}return{showNodePorts:n,hideNodePorts:r,handleEdgeAdded:a,handleEdgeConnected:d,handleEdgeRemoved:l,canShowEdgeTool:u}}const ut={class:"flow-canvas-node-actions__bar"},ft=s.defineComponent({__name:"node-actions-toolbar",props:{node:{},position:{},config:{},behavior:{},actionsOffset:{}},emits:["action"],setup(i,{emit:e}){const t=i,o=s.computed(()=>{const h=t.actionsOffset?.x??0,g=t.actionsOffset?.y??0,f=h!==0||g!==0;return{left:`${t.position.x}px`,top:`${t.position.y}px`,transform:f?`translate(${h}px, ${g}px)`:"translateX(-100%)"}}),n=e,r=s.computed(()=>({debug:{visible:t.config.showDebug&&t.behavior.debuggable!==!1,disabled:t.behavior.debugDisabled===!0},delete:{visible:t.config.showDelete&&t.behavior.deletable!==!1,disabled:t.behavior.deleteDisabled===!0},copy:{visible:t.config.showCopy&&t.behavior.copyable!==!1,disabled:t.behavior.copyDisabled===!0},copyInsert:{visible:t.config.showCopyInsert&&t.behavior.copyable!==!1,disabled:t.behavior.copyInsertDisabled===!0},disconnect:{visible:t.config.showDisconnect&&t.behavior.disconnectable!==!1,disabled:t.behavior.disconnectDisabled===!0}})),a=s.computed(()=>r.value.copy.visible||r.value.copyInsert.visible||r.value.disconnect.visible),d=s.ref(!1);let l=null;function u(){l&&(clearTimeout(l),l=null),d.value=!0}function c(){l=setTimeout(()=>{d.value=!1,l=null},100)}return s.onBeforeUnmount(()=>{l&&clearTimeout(l)}),(h,g)=>(s.openBlock(),s.createElementBlock("div",{class:"flow-canvas-node-actions",style:s.normalizeStyle(o.value)},[s.createElementVNode("div",ut,[r.value.debug.visible?(s.openBlock(),s.createElementBlock("i",{key:0,class:s.normalizeClass(["flow-canvas-icon canvas-debug flow-canvas-node-actions__icon",{"is-disabled":r.value.debug.disabled}]),onClick:g[0]||(g[0]=f=>!r.value.debug.disabled&&n("action","debug",i.node.id))},null,2)):s.createCommentVNode("",!0),r.value.delete.visible?(s.openBlock(),s.createElementBlock("i",{key:1,class:s.normalizeClass(["flow-canvas-icon canvas-shanchu flow-canvas-node-actions__icon",{"is-disabled":r.value.delete.disabled}]),onClick:g[1]||(g[1]=f=>!r.value.delete.disabled&&n("action","delete",i.node.id))},null,2)):s.createCommentVNode("",!0),a.value?(s.openBlock(),s.createElementBlock("div",{key:2,class:"flow-canvas-node-actions__more-wrapper",onMouseenter:u,onMouseleave:c},[...g[5]||(g[5]=[s.createElementVNode("i",{class:"flow-canvas-icon canvas-gengduo flow-canvas-node-actions__icon"},null,-1)])],32)):s.createCommentVNode("",!0)]),s.createVNode(s.Transition,{name:"flow-canvas-fade"},{default:s.withCtx(()=>[d.value&&a.value?(s.openBlock(),s.createElementBlock("div",{key:0,class:"flow-canvas-node-actions__dropdown",onMouseenter:u,onMouseleave:c},[r.value.copy.visible?(s.openBlock(),s.createElementBlock("div",{key:0,class:s.normalizeClass(["flow-canvas-node-actions__dropdown-item",{"is-disabled":r.value.copy.disabled}]),onClick:g[2]||(g[2]=f=>!r.value.copy.disabled&&n("action","copy",i.node.id))},[...g[6]||(g[6]=[s.createElementVNode("i",{class:"flow-canvas-icon canvas-copy-fuzhi-2"},null,-1),s.createElementVNode("span",null,"复制",-1)])],2)):s.createCommentVNode("",!0),r.value.copyInsert.visible?(s.openBlock(),s.createElementBlock("div",{key:1,class:s.normalizeClass(["flow-canvas-node-actions__dropdown-item",{"is-disabled":r.value.copyInsert.disabled}]),onClick:g[3]||(g[3]=f=>!r.value.copyInsert.disabled&&n("action","copy-insert",i.node.id))},[...g[7]||(g[7]=[s.createElementVNode("i",{class:"flow-canvas-icon canvas-fuzhibingcharu"},null,-1),s.createElementVNode("span",null,"复制并插入",-1)])],2)):s.createCommentVNode("",!0),r.value.disconnect.visible?(s.openBlock(),s.createElementBlock("div",{key:2,class:s.normalizeClass(["flow-canvas-node-actions__dropdown-item",{"is-disabled":r.value.disconnect.disabled}]),onClick:g[4]||(g[4]=f=>!r.value.disconnect.disabled&&n("action","disconnect",i.node.id))},[...g[8]||(g[8]=[s.createElementVNode("i",{class:"flow-canvas-icon canvas-unlock-jiebang"},null,-1),s.createElementVNode("span",null,"断开连线",-1)])],2)):s.createCommentVNode("",!0)],32)):s.createCommentVNode("",!0)]),_:1})],4))}}),J=(i,e)=>{const t=i.__vccOpts||i;for(const[o,n]of e)t[o]=n;return t},Ce=J(ft,[["__scopeId","data-v-3b39dab5"]]),pt={key:0,class:"flow-canvas-quick-add__tooltip"},gt=5,ht=s.defineComponent({__name:"node-quick-add-popover",props:{node:{},portPosition:{},tooltipText:{}},emits:["open","close","start-drag","mouseenter","mouseleave"],setup(i,{expose:e,emit:t}){const o=i,n=t,r=s.ref(),a=s.ref(),d=s.ref(!1),l=s.ref(!1);let u=null,c=!1,h=null;function g(M){M.preventDefault(),M.stopPropagation(),u={x:M.clientX,y:M.clientY},c=!1,document.addEventListener("mousemove",f),document.addEventListener("mouseup",S)}function f(M){if(!u)return;const C=M.clientX-u.x,z=M.clientY-u.y;Math.sqrt(C*C+z*z)>=gt&&(c=!0,w(),n("start-drag",o.node.id))}function S(){w(),c||y(),u=null,c=!1}function w(){document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",S)}function y(){l.value?P():b()}function b(){l.value=!0,n("open",o.node.id),requestAnimationFrame(()=>{document.addEventListener("mousedown",v)})}function P(){l.value=!1,n("close"),document.removeEventListener("mousedown",v)}function v(M){const C=M.target;r.value?.contains(C)||a.value?.contains(C)||P()}function m(){l.value||n("mouseleave")}function N(){h&&(clearTimeout(h),h=null),n("mouseenter")}function T(){h=setTimeout(()=>{P(),n("mouseleave"),h=null},150)}return s.onBeforeUnmount(()=>{w(),h&&clearTimeout(h),document.removeEventListener("mousedown",v)}),e({closePopover:P}),(M,C)=>(s.openBlock(),s.createElementBlock("div",{class:"flow-canvas-quick-add",style:s.normalizeStyle({left:`${i.portPosition.x}px`,top:`${i.portPosition.y}px`}),onMouseenter:C[2]||(C[2]=z=>n("mouseenter")),onMouseleave:m,onClick:C[3]||(C[3]=s.withModifiers(()=>{},["stop"]))},[s.createElementVNode("div",{ref_key:"btnRef",ref:r,class:s.normalizeClass(["flow-canvas-quick-add__btn",{"is-hovered":d.value,"is-active":l.value}]),onMouseenter:C[0]||(C[0]=z=>d.value=!0),onMouseleave:C[1]||(C[1]=z=>d.value=!1),onMousedown:g},[...C[4]||(C[4]=[s.createElementVNode("i",{class:"flow-canvas-icon canvas-zoom-add"},null,-1)])],34),d.value&&!l.value?(s.openBlock(),s.createElementBlock("div",pt,[...C[5]||(C[5]=[s.createElementVNode("div",null,[s.createElementVNode("b",null,"点击"),s.createTextVNode(" 添加节点")],-1),s.createElementVNode("div",null,[s.createElementVNode("b",null,"拖拽"),s.createTextVNode(" 连接节点")],-1)])])):s.createCommentVNode("",!0),s.createVNode(s.Transition,{name:"flow-canvas-fade"},{default:s.withCtx(()=>[l.value?(s.openBlock(),s.createElementBlock("div",{key:0,ref_key:"popoverRef",ref:a,class:"flow-canvas-quick-add__popover",onMouseenter:N,onMouseleave:T},[s.renderSlot(M.$slots,"default",{},()=>[C[6]||(C[6]=s.createElementVNode("div",{class:"flow-canvas-quick-add__default-content"},"节点快捷操作面板",-1))],!0)],544)):s.createCommentVNode("",!0)]),_:3})],36))}}),xe=J(ht,[["__scopeId","data-v-deb5af25"]]),vt={class:"flow-canvas-runtime-core__overlay"},mt=s.defineComponent({__name:"canvas-runtime-core",props:{editor:{},graphOptions:{},nodeActions:{},quickAdd:{}},emits:["ui-event"],setup(i,{emit:e}){const t=i,o=e,n=s.ref(),r=s.ref();let a,d,l,u;const c=lt(),{hoveredNodeId:h,isDraggingNode:g}=c,f=c.enterOverlay,S=()=>c.leaveOverlay(),w=s.ref(null);let y=null;function b(E){return v(),j(E)?(w.value=E,!0):(w.value=null,!1)}function P(){y&&clearTimeout(y),y=setTimeout(()=>{w.value=null,y=null},150)}function v(){y&&(clearTimeout(y),y=null)}function m(){v(),c.enterOverlay()}function N(){P(),c.leaveOverlay()}let T=null,M=null,C=null;const z=s.ref(0),q=s.computed(()=>{if(z.value,!t.editor.api.value)return[];const E=t.editor.flowModel.value,x=t.editor.api.value.overlay,k=[];for(const[D,R]of Object.entries(E.nodes)){const B=t.editor._pluginManager.collectNodeDecorations(R);if(!B?.badge)continue;const $=x.getNodeScreenRect(D);$&&k.push({nodeId:D,x:$.x+$.width-4,y:$.y-8,badge:B.badge})}return k}),V=s.computed(()=>({showDebug:!1,showDelete:!0,showCopy:!0,showCopyInsert:!0,showDisconnect:!0,insertGap:100,...t.nodeActions})),F=s.computed(()=>{z.value;const E=h.value;if(!E||g.value||!t.editor.api.value||t.editor.mode.value!=="edit")return null;const x=t.editor.flowModel.value,k=x.nodes[E];if(!k)return null;const D=t.editor.api.value.overlay.getNodeScreenRect(E);if(!D)return null;const B=t.editor.schema.nodeTypes[k.type]?.getBehavior?.(k,{api:t.editor.api.value,flowModel:x,history:t.editor.history,mode:t.editor.mode.value})??{};return B.showActions===!1?null:{node:k,position:{x:D.x+D.width,y:D.y+D.height+4},behavior:B}}),U=s.computed(()=>({enabled:!0,tooltipText:"",...t.quickAdd})),O=s.computed(()=>{if(z.value,!U.value.enabled)return null;const E=w.value;if(!E||g.value||!t.editor.api.value||t.editor.mode.value!=="edit")return null;const x=t.editor.flowModel.value,k=x.nodes[E];if(!k)return null;const R=t.editor.schema.nodeTypes[k.type]?.getBehavior?.(k,{api:t.editor.api.value,flowModel:x,history:t.editor.history,mode:t.editor.mode.value})??{};if(R.quickAddEnabled===!1)return null;const B=t.editor.api.value.overlay.getNodeScreenRect(E);return B?{node:k,portPosition:{x:B.x+B.width,y:B.y+B.height/2},behavior:R}:null}),Z=s.ref();function Q(E){const x=O.value;x&&o("ui-event",{type:"node.quick-add",nodeId:E,position:x.portPosition})}function ce(E){const x=t.editor.api.value;x&&x.startConnection(E,"right")}function X(E,x){const k=t.editor.api.value;if(!k)return;const D=x.id||_(),R={...x,id:D};k.insertNodeToRight(E,R,{autoWireEdges:!0,gap:V.value.insertGap,source:"user:quick-add",label:"快捷插入节点"}).status==="applied"&&o("ui-event",{type:"node.action.quick-insert",sourceNodeId:E,newNodeId:D}),Z.value?.closePopover()}function ie(E){return{id:_(),type:E.type,label:E.label,ports:E.ports?JSON.parse(JSON.stringify(E.ports)):void 0,payload:E.payload?JSON.parse(JSON.stringify(E.payload)):void 0,extensions:E.extensions?JSON.parse(JSON.stringify(E.extensions)):void 0}}function G(E,x){const k=t.editor,D=k.api.value;switch(E){case"delete":{k.executeCommand({id:_(),source:"user:toolbar",label:"删除节点",timestamp:Date.now(),commands:[{type:"node.remove",nodeId:x}]}),o("ui-event",{type:"node.action.delete",nodeId:x}),h.value=null;break}case"copy":{if(!D)break;const R=k.flowModel.value.nodes[x];if(!R)break;const B=ie(R);D.insertNodeToRight(x,B,{autoWireEdges:!1,gap:V.value.insertGap,label:"复制节点"}),o("ui-event",{type:"node.action.copy",sourceNodeId:x,newNodeId:B.id});break}case"copy-insert":{if(!D)break;const R=k.flowModel.value.nodes[x];if(!R)break;const B=ie(R);D.insertNodeToRight(x,B,{autoWireEdges:!0,gap:V.value.insertGap,label:"复制并插入节点"}),o("ui-event",{type:"node.action.copy-insert",sourceNodeId:x,newNodeId:B.id});break}case"disconnect":{const R=k.flowModel.value,B=Object.entries(R.edges).filter(([,$])=>{const W=$;return W.source.nodeId===x||W.target.nodeId===x}).map(([$])=>$);if(B.length===0)break;k.executeCommand({id:_(),source:"user:toolbar",label:"断开连线",timestamp:Date.now(),commands:B.map($=>({type:"edge.remove",edgeId:$}))}),o("ui-event",{type:"node.action.disconnect",nodeId:x,edgeIds:B});break}case"debug":{o("ui-event",{type:"node.action.debug",nodeId:x});break}}}function j(E){if(!U.value.enabled||t.editor.mode.value!=="edit")return!1;const x=t.editor.flowModel.value,k=x.nodes[E];return k?(t.editor.schema.nodeTypes[k.type]?.getBehavior?.(k,{api:t.editor.api.value,flowModel:x,history:t.editor.history,mode:t.editor.mode.value})??{}).quickAddEnabled!==!1:!1}function te(E){if(t.editor.mode.value!=="edit")return;t.editor._pluginManager.dispatchKeyboardShortcut(E)&&(E.preventDefault(),E.stopPropagation())}function K(){return{refX:0,children:[{tagName:"path",d:"M -16 -5 L -8 0 L -16 5 Z",transform:"rotate(0)"},{tagName:"circle",cx:0,cy:0,r:8,fill:"#3a84ff",stroke:"#3a84ff",transform:"rotate(0)"}]}}function L(E){const x=t.editor.schema.defaultEdgeType??"default",k=t.editor.schema.edgeTypes?.[x],D={zIndex:-1,attrs:{line:{stroke:"#abb5cc",strokeWidth:2,targetMarker:{name:"block",width:8,height:8}}}};k?.router&&(D.router=typeof k.router=="string"?{name:k.router}:k.router),k?.connector&&(D.connector=typeof k.connector=="string"?{name:k.connector}:k.connector),k?.x6EdgeConfig&&Object.assign(D,k.x6EdgeConfig);const R=D.attrs??{},B=R.line??{};return D.attrs={...R,line:{...B,targetMarker:K()}},E.createEdge(D)}return s.onMounted(()=>{if(!r.value)return;const E=new Set(["model","container"]),x={};if(t.graphOptions)for(const[p,I]of Object.entries(t.graphOptions)){if(E.has(p)){console.warn(`[flow-canvas] graphOptions.${p} is managed by the engine and will be ignored`);continue}x[p]=I}a=new $e.Graph({container:r.value,autoResize:!0,background:{color:"#edf2fc"},grid:{visible:!0,size:20,type:"dot"},panning:{enabled:!0},mousewheel:{enabled:!0,modifiers:["ctrl","meta"]},interacting:{nodeMovable(p){return p.cell.getProp("draggable")!==!1}},connecting:{allowBlank:!1,allowMulti:!0,allowLoop:!1,allowNode:!1,allowEdge:!1,highlight:!0,anchor:"center",connectionPoint:"anchor",snap:{radius:30},createEdge(){return L(this)}},...x}),l=new nt,d=new tt(a,t.editor.schema,l,p=>t.editor._pluginManager.collectNodeDecorations(p),p=>t.editor._pluginManager.collectEdgeDecorations(p),()=>t.editor.api.value?{api:t.editor.api.value,flowModel:t.editor.flowModel.value,history:t.editor.history,mode:t.editor.mode.value}:null);const k=it(a),D=at({graph:a,overlayManager:k,executeCommand:p=>t.editor.executeCommand(p),schema:t.editor.schema,flowModel:t.editor.flowModel,defaultInsertGap:t.nodeActions?.insertGap,getContextMenuItems:p=>t.editor._pluginManager.collectContextMenuItems(p),onHighlightChange:(p,I)=>{d.setHighlightedNodes(p),d.setHighlightedEdges(I),d.refreshNodeHighlights(),d.refreshEdgeStyles()},resolveNodeShape:p=>{const I=t.editor.schema.nodeTypes[p];if(!I)return null;const A=l.registerNodeType(p,I.component),Y=I.getSize({id:"",type:p,position:{x:0,y:0}});return{shapeName:A,width:Y.width,height:Y.height}}});t.editor.api.value=D;const R={flowModel:t.editor.flowModel,history:t.editor.history,schema:t.editor.schema,mode:t.editor.mode,executeCommand:t.editor.executeCommand,api:D,overlay:k,graph:a};t.editor._pluginManager.attachRuntime(R);const B=t.editor._pluginManager.collectExtendedApi();Object.assign(t.editor.extendedApi,B),u=new st(a,p=>{(p.type==="node.click"||p.type==="node.dblclick"||p.type==="node.contextmenu")&&c.enter(p.nodeId),t.editor._pluginManager.dispatchUiEvent(p),o("ui-event",p)},p=>{if(d.isSyncing)return;if(t.editor.executeCommand(p).status!=="applied"){for(const A of p.commands)if(A.type==="edge.add"){const Y=a.getCellById(A.edge.id);Y&&a.removeCell(Y)}}},t.editor.flowModel),T=dt(a);const $=ct(a),W=a,ue=p=>{const I=W.isRubberbandEnabled?.()??!1;I&&W.disableRubberband?.(),p?a.enablePanning():a.disablePanning(),I&&W.enableRubberband?.()},fe=()=>{z.value++};a.on("translate",fe),a.on("scale",fe),a.on("resize",fe),a.on("node:move",()=>{g.value=!0}),a.on("node:moved",()=>{g.value=!1}),a.on("node:mouseenter",({node:p})=>{c.enter(p.id),U.value.enabled&&b(p.id)||$.showNodePorts(p)}),a.on("node:mouseleave",({node:p})=>{const I=t.editor.flowModel.value.nodes[p.id];let A=100;I&&t.editor.api.value&&t.editor.schema.nodeTypes[I.type]?.getBehavior?.(I,{api:t.editor.api.value,flowModel:t.editor.flowModel.value,history:t.editor.history,mode:t.editor.mode.value})?.actionsOffset&&(A=300),c.leave(A),U.value.enabled&&w.value===p.id?P():$.hideNodePorts(p)});function Me(p){const I=a.getCellById(p);if(!I?.isNode())return;const A=I,Y=!g.value&&j(p);for(const pe of A.getPorts()){const De=Y&&pe.group==="right"?"hidden":"visible";A.setPortProp(pe.id,"attrs/circle/visibility",De)}}s.watch([w,g],([p],[I])=>{if(I&&I!==p){const A=a.getCellById(I);A?.isNode()&&$.hideNodePorts(A)}p&&Me(p)},{flush:"sync"}),a.on("edge:added",({edge:p})=>{$.handleEdgeAdded(p)}),a.on("edge:connected",()=>{$.handleEdgeConnected()}),a.on("edge:removed",({edge:p})=>{$.handleEdgeRemoved(p.id),T.handleEdgeRemoved(p.id)}),a.on("selection:changed",()=>{const p=a.getSelectedCells?.()??[],I={nodeIds:p.filter(A=>A.isNode()).map(A=>A.id),edgeIds:p.filter(A=>A.isEdge()).map(A=>A.id)};t.editor._pluginManager.dispatchSelectionChange(I),o("ui-event",{type:"selection.change",nodeIds:I.nodeIds,edgeIds:I.edgeIds}),d.refreshEdgeStyles()}),a.on("edge:mouseenter",({edge:p,e:I})=>{d.setHoveredEdge(p.id),d.refreshEdgeStyles(),t.editor.mode.value==="edit"&&$.canShowEdgeTool()&&T.show(p.id,I)}),M=p=>T.move(p),a.container.addEventListener("mousemove",M),a.on("edge:mouseleave",()=>{d.setHoveredEdge(null),d.refreshEdgeStyles(),T.remove()}),a.on("edge:click",({edge:p,e:I})=>{I.target?.closest?.(".flow-canvas-edge-delete-tool")&&t.editor.mode.value==="edit"&&(T.remove(),t.editor.executeCommand({id:_(),source:"user:toolbar",label:"删除连线",timestamp:Date.now(),commands:[{type:"edge.remove",edgeId:p.id}]}))}),n.value?.addEventListener("keydown",te),d.syncFlowModel(t.editor.flowModel.value),s.watch(()=>t.editor.flowModel.value,p=>d.syncFlowModel(p)),s.watch(()=>t.editor.selectionMode.value,p=>{if(C?.(),C=null,p){ue(!1),W.enableRubberband?.();const I=()=>{a.container.removeEventListener("mouseup",I),C=null,setTimeout(()=>{t.editor.selectionMode.value&&t.editor.setSelectionMode(!1)},50)};a.container.addEventListener("mouseup",I),C=()=>a.container.removeEventListener("mouseup",I)}else W.disableRubberband?.(),ue(!0)}),s.watch(()=>t.editor.mode.value,p=>{const I=p==="edit";ue(!0),I?W.enableSelection?.():W.disableSelection?.()})}),s.onBeforeUnmount(()=>{c.cleanup(),y&&clearTimeout(y),T?.remove(),C?.(),M&&a?.container?.removeEventListener("mousemove",M),n.value?.removeEventListener("keydown",te),t.editor._pluginManager.detachRuntime(),t.editor.api.value=null;for(const E of Object.keys(t.editor.extendedApi))delete t.editor.extendedApi[E];u?.dispose(),d?.dispose(),l?.dispose(),a?.dispose()}),(E,x)=>(s.openBlock(),s.createElementBlock("div",{ref_key:"rootRef",ref:n,class:"flow-canvas-runtime-core",tabindex:"0"},[s.createElementVNode("div",{ref_key:"containerRef",ref:r,class:"flow-canvas-runtime-core__graph"},null,512),s.createElementVNode("div",vt,[(s.openBlock(!0),s.createElementBlock(s.Fragment,null,s.renderList(q.value,k=>(s.openBlock(),s.createElementBlock("div",{key:`badge-${k.nodeId}`,class:"flow-canvas-runtime-core__badge",style:s.normalizeStyle({left:`${k.x}px`,top:`${k.y}px`,backgroundColor:k.badge.color})},s.toDisplayString(k.badge.text),5))),128)),O.value?(s.openBlock(),s.createBlock(xe,{key:0,ref_key:"quickAddPopoverRef",ref:Z,node:O.value.node,"port-position":O.value.portPosition,"tooltip-text":U.value.tooltipText,onOpen:Q,onStartDrag:ce,onMouseenter:m,onMouseleave:N},{default:s.withCtx(()=>[s.renderSlot(E.$slots,"quick-add-panel",{node:O.value.node,api:i.editor.api.value,insertNodeToRight:k=>X(O.value.node.id,k),closePopover:()=>Z.value?.closePopover()},void 0,!0)]),_:3},8,["node","port-position","tooltip-text"])):s.createCommentVNode("",!0),F.value?(s.openBlock(),s.createBlock(Ce,{key:1,node:F.value.node,position:F.value.position,config:V.value,behavior:F.value.behavior,"actions-offset":F.value.behavior.actionsOffset,onAction:G,onMouseenter:s.unref(f),onMouseleave:S},null,8,["node","position","config","behavior","actions-offset","onMouseenter"])):s.createCommentVNode("",!0)])],512))}}),yt=J(mt,[["__scopeId","data-v-96013976"]]),bt={class:"flow-canvas-node-palette"},wt=["data-node-type"],kt={class:"flow-canvas-node-palette__item-label"},Et=s.defineComponent({__name:"canvas-node-palette",props:{editor:{},items:{}},setup(i){const e=i,t=s.ref(),o=s.computed(()=>e.items?e.items:Object.keys(e.editor.schema.nodeTypes).map(n=>({type:n,label:n.charAt(0).toUpperCase()+n.slice(1)})));return s.watch([()=>e.editor.api.value,o,t],([n,r,a],d,l)=>{if(!n||!a)return;const u=[];for(const c of r){const h=a.querySelector(`[data-node-type="${c.type}"]`);if(!h)continue;const g=n.registerDndSource(h,()=>({id:_(),type:c.type,label:c.label,position:{x:0,y:0}}));u.push(g)}l(()=>{for(const c of u)c()})},{flush:"post"}),(n,r)=>(s.openBlock(),s.createElementBlock("div",bt,[s.createElementVNode("div",{ref_key:"listRef",ref:t,class:"flow-canvas-node-palette__list"},[(s.openBlock(!0),s.createElementBlock(s.Fragment,null,s.renderList(o.value,a=>(s.openBlock(),s.createElementBlock("div",{key:a.type,class:"flow-canvas-node-palette__item","data-node-type":a.type},[a.icon?(s.openBlock(),s.createElementBlock("i",{key:0,class:s.normalizeClass([a.icon,"flow-canvas-node-palette__item-icon"])},null,2)):s.createCommentVNode("",!0),s.createElementVNode("span",kt,s.toDisplayString(a.label),1)],8,wt))),128))],512)]))}}),Ne=J(Et,[["__scopeId","data-v-300314b7"]]),Ct={class:"flow-canvas-layout"},xt={class:"flow-canvas-layout__main"},Nt={class:"flow-canvas-layout__content"},It={key:0,class:"flow-canvas-layout__footer"},St=s.defineComponent({__name:"canvas-layout",props:{sidebarCollapsed:{type:Boolean,default:!1},sidebarWidth:{default:260},hideSidebar:{type:Boolean,default:!1},hideFooter:{type:Boolean,default:!1},editor:{default:void 0},paletteItems:{default:void 0}},emits:["update:sidebarCollapsed"],setup(i){return(e,t)=>(s.openBlock(),s.createElementBlock("div",Ct,[!i.hideSidebar&&(e.$slots.sidebar||i.editor)?(s.openBlock(),s.createElementBlock("aside",{key:0,class:s.normalizeClass(["flow-canvas-layout__sidebar",{"is-collapsed":i.sidebarCollapsed}]),style:s.normalizeStyle({width:i.sidebarCollapsed?"0px":`${i.sidebarWidth}px`})},[s.renderSlot(e.$slots,"sidebar",{},()=>[i.editor?(s.openBlock(),s.createBlock(Ne,{key:0,editor:i.editor,items:i.paletteItems},null,8,["editor","items"])):s.createCommentVNode("",!0)],!0)],6)):s.createCommentVNode("",!0),s.createElementVNode("div",xt,[s.createElementVNode("div",Nt,[s.renderSlot(e.$slots,"default",{},void 0,!0)]),!i.hideFooter&&e.$slots.footer?(s.openBlock(),s.createElementBlock("div",It,[s.renderSlot(e.$slots,"footer",{},void 0,!0)])):s.createCommentVNode("",!0)])]))}}),Mt=J(St,[["__scopeId","data-v-26f35b6b"]]),Dt=["undo","redo"];function Ie(i){const e=new Set(i?.include),t=new Set([...Dt.filter(l=>!e.has(l)),...i?.exclude??[]]),o=[{id:"undo",type:"undo",group:"history",icon:"flow-canvas-icon canvas-undo",description:"撤销",order:10},{id:"redo",type:"redo",group:"history",icon:"flow-canvas-icon canvas-redo",description:"重做",order:11}],n=[{id:"select",type:"select",group:"tools",icon:"flow-canvas-icon canvas-kuangxuan",description:"框选",order:20},{id:"auto-layout",type:"auto-layout",group:"tools",icon:"flow-canvas-icon canvas-beautify",description:"自动排版",order:21},{id:"search",type:"search",group:"tools",icon:"flow-canvas-icon canvas-search",description:"搜索节点",order:22},{id:"minimap",type:"minimap",group:"tools",icon:"flow-canvas-icon canvas-map",description:"缩略图",order:23},{id:"export",type:"export",group:"tools",icon:"flow-canvas-icon canvas-xiazai",description:"导出为图片",order:24}],r=[{id:"zoom-out",type:"zoom-out",group:"zoom",icon:"flow-canvas-icon canvas-zoom-minus",description:"缩小画布",order:30},{id:"zoom-display",type:"zoom-display",group:"zoom",order:31},{id:"zoom-in",type:"zoom-in",group:"zoom",icon:"flow-canvas-icon canvas-zoom-add",description:"放大画布",order:32}],a=[{id:"reset",type:"reset",group:"reset",icon:"flow-canvas-icon canvas-reset-1_1",description:"重置视图",order:40}];return[...[...o,...n].filter(l=>!t.has(l.type)),...r,...a]}const Bt={class:"flow-canvas-toolbar"},_t={key:0,class:"flow-canvas-toolbar__separator"},Pt={class:"flow-canvas-toolbar__group"},At={key:0,class:"flow-canvas-toolbar__zoom-display"},Tt=["data-description","disabled","onClick"],Rt=["textContent"],$t=s.defineComponent({__name:"canvas-toolbar",props:{items:{},exclude:{},editor:{}},setup(i){const e=i,t=s.computed(()=>e.items?e.items:Ie({exclude:e.exclude})),o=s.ref(1);let n=null;s.watch(()=>e.editor.api.value,f=>{n?.(),n=null,f&&(o.value=f.getZoom(),n=f.onGraphEvent("scale",()=>{o.value=f.getZoom()}))},{immediate:!0}),s.onScopeDispose(()=>{n?.()});const r=s.computed(()=>`${Math.round(o.value*100)}%`),a=s.computed(()=>e.editor.api.value?{api:e.editor.api.value,flowModel:e.editor.flowModel.value,history:e.editor.history,mode:e.editor.mode.value}:null);function d(f){return f.visible===!1?!1:typeof f.visible=="function"?a.value?f.visible(a.value):!1:!0}function l(f){return f.type==="select"?e.editor.selectionMode.value:!1}function u(f){return!a.value||f.disabled===!0?!0:typeof f.disabled=="function"?f.disabled(a.value):f.type==="undo"?!e.editor.history.canUndo.value:f.type==="redo"?!e.editor.history.canRedo.value:!1}function c(f){if(!a.value||u(f))return;if(f.onClick){f.onClick(a.value);return}const{api:S}=a.value;switch(f.type){case"undo":e.editor.history.undo();break;case"redo":e.editor.history.redo();break;case"zoom-in":S.zoomIn(),o.value=S.getZoom();break;case"zoom-out":S.zoomOut(),o.value=S.getZoom();break;case"fit":S.zoomToFit();break;case"reset":S.zoomTo(1),S.scrollToOrigin(),o.value=1;break;case"export":S.exportAsImage().then(w=>{const y=URL.createObjectURL(w),b=document.createElement("a");b.href=y,b.download="canvas-export.png",b.click(),URL.revokeObjectURL(y)}).catch(w=>{console.warn("[flow-canvas] Export failed:",w)});break;case"select":e.editor.setSelectionMode(!e.editor.selectionMode.value);break;case"search":case"auto-layout":case"minimap":console.warn(`[flow-canvas] "${f.type}" toolbar item has no built-in handler. Provide an onClick callback.`);break;default:f.type!=="custom"&&console.warn(`[flow-canvas] No default handler for toolbar type "${f.type}". Provide an onClick handler.`);break}}const h=s.computed(()=>t.value.filter(d)),g=s.computed(()=>{const f=new Map,S=[];for(const w of h.value){const y=w.group??"default";f.has(y)||(f.set(y,[]),S.push(y)),f.get(y).push(w)}return S.map(w=>({name:w,items:f.get(w)})).filter(w=>w.items.length>0)});return(f,S)=>(s.openBlock(),s.createElementBlock("div",Bt,[(s.openBlock(!0),s.createElementBlock(s.Fragment,null,s.renderList(g.value,(w,y)=>(s.openBlock(),s.createElementBlock(s.Fragment,{key:w.name},[y>0?(s.openBlock(),s.createElementBlock("div",_t)):s.createCommentVNode("",!0),s.createElementVNode("div",Pt,[(s.openBlock(!0),s.createElementBlock(s.Fragment,null,s.renderList(w.items,b=>(s.openBlock(),s.createElementBlock(s.Fragment,{key:b.id},[b.type==="zoom-display"?(s.openBlock(),s.createElementBlock("span",At,s.toDisplayString(r.value),1)):(s.openBlock(),s.createElementBlock("button",{key:1,class:s.normalizeClass(["flow-canvas-toolbar__btn",{"is-disabled":u(b),"is-active":l(b)}]),"data-description":b.description,disabled:u(b),onClick:P=>c(b)},[b.component?(s.openBlock(),s.createBlock(s.resolveDynamicComponent(b.component),{key:0})):b.icon?(s.openBlock(),s.createElementBlock("i",{key:1,class:s.normalizeClass(b.icon)},null,2)):(s.openBlock(),s.createElementBlock("span",{key:2,class:"flow-canvas-toolbar__text",textContent:s.toDisplayString(b.text??b.description??b.id)},null,8,Rt))],10,Tt))],64))),128))])],64))),128))]))}}),zt=J($t,[["__scopeId","data-v-ca50cd45"]]),Lt={class:"flow-canvas-default-node__ep-label"},Vt={key:1,class:"flow-canvas-default-node__diamond"},Ot={key:2,class:"flow-canvas-default-node__task-label"},jt=s.defineComponent({__name:"default-node",setup(i){const t=s.inject("getNode")?.(),o=s.computed(()=>t?.getData?.()??null),n=s.computed(()=>o.value?.label||o.value?.type||""),r={start:"canvas-kaishi",end:"canvas-stop","parallel-gateway":"canvas-bingxingwangguan","branch-gateway":"canvas-fenzhiwangguan","converge-gateway":"canvas-huijuwangguan","conditional-parallel-gateway":"canvas-tiaojianbingxingwangguan"},a=new Set(["start","end"]),d=new Set(["parallel-gateway","branch-gateway","converge-gateway","conditional-parallel-gateway"]),l=s.computed(()=>{const c=o.value?.type??"";return a.has(c)?"endpoint":d.has(c)?"gateway":"task"}),u=s.computed(()=>r[o.value?.type??""]??"");return(c,h)=>(s.openBlock(),s.createElementBlock("div",{class:s.normalizeClass(["flow-canvas-default-node",`is-${l.value}`])},[l.value==="endpoint"?(s.openBlock(),s.createElementBlock(s.Fragment,{key:0},[u.value?(s.openBlock(),s.createElementBlock("i",{key:0,class:s.normalizeClass([["flow-canvas-icon",u.value],"flow-canvas-default-node__ep-icon"])},null,2)):s.createCommentVNode("",!0),s.createElementVNode("span",Lt,s.toDisplayString(n.value),1)],64)):l.value==="gateway"?(s.openBlock(),s.createElementBlock("div",Vt,[u.value?(s.openBlock(),s.createElementBlock("i",{key:0,class:s.normalizeClass([["flow-canvas-icon",u.value],"flow-canvas-default-node__gw-icon"])},null,2)):s.createCommentVNode("",!0)])):(s.openBlock(),s.createElementBlock("span",Ot,s.toDisplayString(n.value),1))],2))}}),Se=J(jt,[["__scopeId","data-v-c88cdae7"]]),Ft={start:{label:"开始",icon:"flow-canvas-icon canvas-kaishi",width:88,height:40},end:{label:"结束",icon:"flow-canvas-icon canvas-stop",width:88,height:40},empty:{label:"空节点",icon:"flow-canvas-icon canvas-jiedi",width:240,height:48},"parallel-gateway":{label:"并行网关",icon:"flow-canvas-icon canvas-bingxingwangguan",width:64,height:64},"branch-gateway":{label:"分支网关",icon:"flow-canvas-icon canvas-fenzhiwangguan",width:64,height:64},"converge-gateway":{label:"汇聚网关",icon:"flow-canvas-icon canvas-huijuwangguan",width:64,height:64},"conditional-parallel-gateway":{label:"条件并行网关",icon:"flow-canvas-icon canvas-tiaojianbingxingwangguan",width:64,height:64}},be=(i,e)=>({stroke:e.hovered?"#3a84ff":"#abb5cc",strokeWidth:2}),we={attrs:{line:{stroke:"#abb5cc",strokeWidth:2,targetMarker:{name:"block",width:8,height:8}}}},Ht={manhattan:{router:{name:"manhattan",args:{padding:10,maxDirectionChange:90}},connector:{name:"rounded",args:{radius:8}},style:be,x6EdgeConfig:we},bezier:{connector:{name:"smooth"},style:be,x6EdgeConfig:we}};function Ut(i){const e=i?.nodeTypes??Ft,t={},o=[];for(const[a,d]of Object.entries(e)){const l=d.width??150,u=d.height??50;t[a]={component:Se,getSize:()=>({width:l,height:u}),getPorts:()=>[{id:"top",group:"top"},{id:"right",group:"right"},{id:"bottom",group:"bottom"},{id:"left",group:"left"}]},o.push({type:a,label:d.label??a,icon:d.icon})}const n={...Ht,...i?.edgeTypes},r=i?.defaultEdgeType??"manhattan";return{schema:{nodeTypes:t,defaultEdgeType:r,edgeTypes:n},paletteItems:o}}function qt(i){return{name:"connection-validator",priority:10,transformCommand(e,t,o){for(const n of e.commands){if(n.type!=="edge.add"&&n.type!=="edge.reconnect")continue;const r=o.flowModel.value,a=n.type==="edge.add"?n.edge.source.nodeId:n.source?.nodeId,d=n.type==="edge.add"?n.edge.target.nodeId:n.target?.nodeId;if(!a||!d)continue;const l=r.nodes[a],u=r.nodes[d];if(!l||!u)continue;const c=n.type==="edge.add"?n.edge.source.portId:n.source?.portId,h=n.type==="edge.add"?n.edge.target.portId:n.target?.portId,g=c?l.ports?.find(b=>b.id===c):void 0,f=h?u.ports?.find(b=>b.id===h):void 0,S=n.type==="edge.reconnect"?n.edgeId:void 0,w=Object.values(r.edges).filter(b=>b.id!==S),y=i({flowModel:r,sourceNode:l,targetNode:u,sourcePort:g,targetPort:f,existingEdges:w});if(!y.valid)return{rejected:!0,reason:y.reason??"Connection validation failed",code:"validation_failed"}}return e}}}function Gt(i){const{rubberband:e=!0,multiple:t=!0,movable:o=!0}=i??{};return{name:"selection",priority:90,async attachRuntime(n){const{Selection:r}=await import("@antv/x6-plugin-selection");n.graph.use(new r({enabled:!0,rubberband:e,multiple:t,movable:o,showNodeSelectionBox:!0,filter:a=>!(a.isNode()&&(!n.graph.isRubberbandEnabled?.()||(a.getData?.()??{})._selectable===!1))}))}}}function Wt(i){const{tolerance:e=10,color:t="#3a84ff"}=i??{};let o=null;return{name:"snapline",priority:90,async attachRuntime(n){const{Snapline:r}=await import("@antv/x6-plugin-snapline");n.graph.use(new r({enabled:!0,tolerance:e,className:"flow-canvas-snapline"})),o=document.createElement("style"),o.textContent=`.flow-canvas-snapline line { stroke: ${t} !important; }`,document.head.appendChild(o)},detachRuntime(){o?.remove(),o=null}}}function Qt(i){let e=null;return{name:"minimap",priority:90,async attachRuntime(t){if(!i?.container)return;e=i.container;const{MiniMap:o}=await import("@antv/x6-plugin-minimap");t.graph.use(new o({container:i.container,width:i.width??200,height:i.height??160}))},detachRuntime(){e=null},provideToolbarItems(){return[{id:"minimap",type:"minimap",tooltip:"小地图",order:100,visible:!!i?.container,onClick(){if(!e)return;const t=e.style.display==="none";e.style.display=t?"":"none"}}]}}}function Xt(){let i=null,e=0;return{name:"clipboard",priority:90,onKeyboardShortcut(t,o){const n=t.metaKey||t.ctrlKey;if(n&&t.key==="c"){const r=o.graph.getSelectedCells?.()??[];if(!r.length)return!1;const a=o.flowModel.value,d=new Set(r.filter(c=>c.isNode()).map(c=>c.id)),l=[...d].map(c=>a.nodes[c]).filter(Boolean);if(!l.length)return!1;const u=Object.values(a.edges).filter(c=>d.has(c.source.nodeId)&&d.has(c.target.nodeId));return i={nodes:l,edges:u},e=0,!0}if(n&&t.key==="v"){if(!i?.nodes.length)return!1;e++;const r=e*30,a=new Map,d=[];for(const l of i.nodes){const u=`${l.id}_cp${_().slice(0,6)}`;a.set(l.id,u),d.push({type:"node.add",node:{...l,id:u,position:{x:l.position.x+r,y:l.position.y+r},payload:l.payload?{...l.payload}:{},extensions:l.extensions?{...l.extensions}:void 0}})}for(const l of i.edges){const u=a.get(l.source.nodeId),c=a.get(l.target.nodeId);!u||!c||d.push({type:"edge.add",edge:{...l,id:`${l.id}_cp${_().slice(0,6)}`,source:{...l.source,nodeId:u},target:{...l.target,nodeId:c},labels:l.labels?.map(h=>({...h,id:`${h.id}_cp${_().slice(0,6)}`})),payload:l.payload?{...l.payload}:{}}})}return d.length&&o.executeCommand({id:_(),source:"user:keyboard",label:"粘贴",timestamp:Date.now(),commands:d}),!0}return!1}}}exports.CanvasConstraintError=H;exports.CanvasLayout=Mt;exports.CanvasNodePalette=Ne;exports.CanvasRuntime=yt;exports.CanvasSchemaError=ke;exports.CanvasToolbar=zt;exports.DefaultNode=Se;exports.NodeActionsToolbar=Ce;exports.NodeQuickAddPopover=xe;exports.applyCanvasCommand=re;exports.clipboardPlugin=Xt;exports.connectionValidatorPlugin=qt;exports.createCanvasHistory=Ee;exports.createDefaultSchema=Ut;exports.createDefaultToolbarItems=Ie;exports.createEmptyFlowModel=Le;exports.generateId=_;exports.minimapPlugin=Qt;exports.selectionPlugin=Gt;exports.snaplinePlugin=Wt;exports.useCanvasEditor=et;
|
|
1
|
+
"use strict";var Fe=Object.create;var Ce=Object.defineProperty;var Ge=Object.getOwnPropertyDescriptor;var He=Object.getOwnPropertyNames;var qe=Object.getPrototypeOf,Ue=Object.prototype.hasOwnProperty;var We=(s,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of He(e))!Ue.call(s,n)&&n!==t&&Ce(s,n,{get:()=>e[n],enumerable:!(o=Ge(e,n))||o.enumerable});return s};var le=(s,e,t)=>(t=s!=null?Fe(qe(s)):{},We(e||!s||!s.__esModule?Ce(t,"default",{value:s,enumerable:!0}):t,s));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("vue"),Qe=require("@antv/x6"),Xe=require("@antv/x6-vue-shape");function Ke(){return{version:"1.0",nodes:{},edges:{}}}class H extends Error{constructor(e){super(e),this.name="CanvasConstraintError"}}class Pe extends Error{constructor(e){super(e),this.name="CanvasSchemaError"}}function ge(s,e,t){if(e.length===0){if(t===void 0)return;if(typeof t!="object"||t===null||Array.isArray(t))throw new Error("Root value of payload/extensions/meta must be an object or undefined");return t}const o=s?{...s}:{};let n=o;for(let a=0;a<e.length-1;a++){const d=e[a],l=n[d];l&&typeof l=="object"&&!Array.isArray(l)?n[d]={...l}:n[d]={},n=n[d]}const r=e[e.length-1];return t===void 0?delete n[r]:n[r]=t,o}function pe(s,e){switch(e.type){case"node.add":return Ye(s,e.node);case"node.move":return Ze(s,e.nodeId,e.position);case"node.remove":return Je(s,e.nodeId);case"node.update":return et(s,e.nodeId,e.patch);case"node.set-payload":return tt(s,e.nodeId,e.path,e.value);case"node.set-extensions":return ot(s,e.nodeId,e.path,e.value);case"edge.add":return nt(s,e.edge);case"edge.remove":return st(s,e.edgeId);case"edge.reconnect":return it(s,e.edgeId,e.source,e.target);case"edge.update":return rt(s,e.edgeId,e.patch);case"edge.set-payload":return at(s,e.edgeId,e.path,e.value);case"edge.label.update":return lt(s,e.edgeId,e.labelId,e.patch);case"model.set-meta":return dt(s,e.path,e.value);default:throw new H(`Unknown command type: ${e.type}`)}}function de(s,e){const t=s.nodes[e];if(!t)throw new H(`Node "${e}" does not exist`);return t}function ce(s,e){const t=s.edges[e];if(!t)throw new H(`Edge "${e}" does not exist`);return t}function re(s,e,t){const o=s.nodes[e.nodeId];if(!o)throw new H(`${t} node "${e.nodeId}" does not exist`);if(e.portId&&o.ports&&!o.ports.some(r=>r.id===e.portId))throw new H(`${t} port "${e.portId}" not found on node "${e.nodeId}"`)}function he(s,e,t){return{...s,nodes:{...s.nodes,[e]:t}}}function ve(s,e,t){return{...s,edges:{...s.edges,[e]:t}}}function Ye(s,e){if(s.nodes[e.id])throw new H(`Node id "${e.id}" already exists`);return{...s,nodes:{...s.nodes,[e.id]:e}}}function Ze(s,e,t){const o=de(s,e);return he(s,e,{...o,position:t})}function Je(s,e){de(s,e);const{[e]:t,...o}=s.nodes,n={};for(const[r,a]of Object.entries(s.edges))a.source.nodeId!==e&&a.target.nodeId!==e&&(n[r]=a);return{...s,nodes:o,edges:n}}function et(s,e,t){const o=de(s,e);return he(s,e,{...o,...t,id:o.id})}function tt(s,e,t,o){const n=de(s,e),r=ge(n.payload,t,o);return he(s,e,{...n,payload:r})}function ot(s,e,t,o){const n=de(s,e),r=ge(n.extensions,t,o);return he(s,e,{...n,extensions:r})}function nt(s,e){if(s.edges[e.id])throw new H(`Edge id "${e.id}" already exists`);if(re(s,e.source,"Source"),re(s,e.target,"Target"),e.labels){const t=new Set;for(const o of e.labels){if(t.has(o.id))throw new H(`Duplicate label id "${o.id}" in edge "${e.id}"`);t.add(o.id)}}return{...s,edges:{...s.edges,[e.id]:e}}}function st(s,e){ce(s,e);const{[e]:t,...o}=s.edges;return{...s,edges:o}}function it(s,e,t,o){const n=ce(s,e),r=t??n.source,a=o??n.target;return re(s,r,"Source"),re(s,a,"Target"),ve(s,e,{...n,source:r,target:a})}function rt(s,e,t){const o=ce(s,e),n={...o,...t,id:o.id};return t.source&&re(s,n.source,"Source"),t.target&&re(s,n.target,"Target"),ve(s,e,n)}function at(s,e,t,o){const n=ce(s,e),r=ge(n.payload,t,o);return ve(s,e,{...n,payload:r})}function lt(s,e,t,o){const n=ce(s,e);if(!n.labels)throw new H(`Edge "${e}" has no labels`);const r=n.labels.findIndex(d=>d.id===t);if(r===-1)throw new H(`Label "${t}" not found in edge "${e}"`);const a=[...n.labels];return a[r]={...a[r],...o,id:t},ve(s,e,{...n,labels:a})}function dt(s,e,t){const o=ge(s.meta,e,t);return{...s,meta:o}}function Be(s,e){const t=e?.maxHistorySize??100,o=i.ref(s),n=[],r=[],a=i.ref(!1),d=i.ref(!1);function l(){a.value=n.length>0,d.value=r.length>0}function p(C){const k=o.value;let E=k;for(const B of C.commands)E=pe(E,B);return n.push({snapshot:k,envelope:C}),n.length>t&&n.shift(),r.length=0,o.value=E,l(),E}function c(){const C=n.pop();return C?(r.push({snapshot:o.value,envelope:C.envelope}),o.value=C.snapshot,l(),C.snapshot):null}function w(){const C=r.pop();if(!C)return null;n.push({snapshot:o.value,envelope:C.envelope});let k=o.value;for(const E of C.envelope.commands)k=pe(k,E);return o.value=k,l(),k}function b(){n.length=0,r.length=0,l()}function h(){return o.value}function M(C){o.value=C,b()}return{currentFlowModel:o,execute:p,undo:c,redo:w,canUndo:a,canRedo:d,get undoStack(){return n.map(C=>C.envelope)},get redoStack(){return r.map(C=>C.envelope)},clear:b,createSnapshot:h,replaceFlowModel:M}}function ct(s){return s!==null&&typeof s=="object"&&s.rejected===!0}class ut{plugins=[];editorContext=null;runtimeCtx=null;runtimeVersion=0;install(e,t){this.plugins=[...e].sort((o,n)=>(o.priority??100)-(n.priority??100)),this.editorContext=t;for(const o of this.plugins)o.install?.(t)}attachRuntime(e){const t=++this.runtimeVersion;this.runtimeCtx=e;const o=this.createSafeRuntimeContext(e,t);for(const n of this.plugins)n.attachRuntime?.(o)}detachRuntime(){for(const e of[...this.plugins].reverse())e.detachRuntime?.();this.runtimeCtx=null}createSafeRuntimeContext(e,t){const o=this,n=new Proxy(e.graph,{get(r,a,d){const l=Reflect.get(r,a,d);return a==="use"&&typeof l=="function"?function(...c){if(o.runtimeVersion===t)return l.apply(r,c)}:l}});return{...e,graph:n}}dispose(){for(const e of[...this.plugins].reverse())e.dispose?.();this.plugins=[],this.editorContext=null,this.runtimeCtx=null}transformCommand(e){if(!this.editorContext)return{envelope:e};let t=e;for(const o of this.plugins){if(!o.transformCommand)continue;const n=this.createPreview(t),r=o.transformCommand(t,n,this.editorContext);if(r===null)return{rejected:!0,error:{code:"plugin_rejected",reason:"",source:o.name}};if(ct(r))return{rejected:!0,error:{code:r.code??"plugin_rejected",reason:r.reason,source:o.name}};t=r}return{envelope:t}}afterCommand(e,t,o){if(this.editorContext)for(const n of this.plugins)n.afterCommand?.(e,t,o,this.editorContext)}dispatchUiEvent(e){if(this.runtimeCtx)for(const t of this.plugins)t.onUiEvent?.(e,this.runtimeCtx)}dispatchSelectionChange(e){if(this.runtimeCtx)for(const t of this.plugins)t.onSelectionChange?.(e,this.runtimeCtx)}dispatchKeyboardShortcut(e){if(!this.runtimeCtx)return!1;for(const t of this.plugins)if(t.onKeyboardShortcut?.(e,this.runtimeCtx))return!0;return!1}collectContextMenuItems(e){if(!this.runtimeCtx)return[];const t=[];for(const o of this.plugins){const n=o.onBlankContextMenu?.(e,this.runtimeCtx);n&&t.push(...n)}return t}collectToolbarItems(){if(!this.editorContext)return[];const e=new Map;for(const t of this.plugins){const o=t.provideToolbarItems?.(this.editorContext);if(o)for(const n of o)e.set(n.id,n)}return[...e.values()].sort((t,o)=>(t.order??0)-(o.order??0))}collectNodeDecorations(e){if(!this.editorContext)return;let t;for(const o of this.plugins){const n=o.decorateNode?.(e,this.editorContext);n&&(t=t?{...t,...n}:n)}return t}collectEdgeDecorations(e){if(!this.editorContext)return;let t;for(const o of this.plugins){const n=o.decorateEdge?.(e,this.editorContext);n&&(t=t?{...t,...n}:n)}return t}collectExtendedApi(){if(!this.runtimeCtx)return{};const e={};for(const t of this.plugins){const o=t.extendApi?.(this.runtimeCtx.api,this.runtimeCtx);o&&Object.assign(e,o)}return e}createPreview(e){const t=this.editorContext;return{previewFlowModel(o){const n=o??e.commands;let r=t.flowModel.value;for(const a of n)r=pe(r,a);return r}}}}function ft(s){const{schema:e,plugins:t=[],historyOptions:o}=s,n={version:"1.0",...s.initialFlowModel},r=Be(n,o),a=i.ref(s.mode??"edit"),d=i.ref(!1),l=i.ref(null),p=i.ref([]),c={},w=new ut;function b(k,E,B,z="user:toolbar"){const R={id:`history-${Date.now()}`,source:z,label:k,timestamp:Date.now(),commands:[]};w.afterCommand(R,E,B),p.value=w.collectToolbarItems(),s.onCommandResult?.({status:"applied",envelope:R,flowModel:B}),s.onFlowModelChange?.({flowModel:B,prevFlowModel:E,envelope:R,source:z})}const h={execute:r.execute,undo(){const k=r.currentFlowModel.value,E=r.undo();return E&&b("撤销",k,E),E},redo(){const k=r.currentFlowModel.value,E=r.redo();return E&&b("重做",k,E),E},get canUndo(){return r.canUndo},get canRedo(){return r.canRedo},get undoStack(){return r.undoStack},get redoStack(){return r.redoStack},clear:r.clear,createSnapshot:r.createSnapshot,replaceFlowModel(k){const E=r.currentFlowModel.value;r.replaceFlowModel(k),b("替换 FlowModel",E,k,"system:replace")}},M={flowModel:i.computed(()=>r.currentFlowModel.value),history:h,schema:e,mode:a,executeCommand:C,replaceFlowModel(k){h.replaceFlowModel(k)},setMode(k){a.value=k},selectionMode:d,setSelectionMode(k){d.value=k},api:l,toolbarItems:p,extendedApi:c,_pluginManager:w};w.install(t,{flowModel:M.flowModel,history:h,schema:e,mode:a,executeCommand:C}),p.value=w.collectToolbarItems(),i.onScopeDispose(()=>{w.dispose()});function C(k){const E=w.transformCommand(k);if("rejected"in E){const R={status:"rejected",envelope:k,error:E.error};return s.onCommandResult?.(R),R}const B=E.envelope,z=r.currentFlowModel.value;try{const R=r.execute(B),q={status:"applied",envelope:B,flowModel:R};return w.afterCommand(B,z,R),p.value=w.collectToolbarItems(),s.onCommandResult?.(q),s.onFlowModelChange?.({flowModel:R,prevFlowModel:z,envelope:B,source:B.source}),q}catch(R){if(R instanceof H){const q={status:"invalid",envelope:B,error:{code:"constraint_violated",reason:R.message,source:"engine"}};return s.onCommandResult?.(q),q}throw R}}return M}const pt=["top","right","bottom","left"];function _e(){return pt.map(s=>({id:s,group:s}))}function ke(s,e){return e?.(s)??s.ports??_e()}class gt{graph;schema;shapeRegistry;resolveNodeDecoration;resolveEdgeDecoration;resolveCanvasContext;knownNodeIds=new Set;knownEdgeIds=new Set;syncing=!1;prevNodeDecorationClasses=new Map;prevNodeDecorationColors=new Set;prevEdgeDecorationClasses=new Map;prevEdgeDecorationColors=new Set;highlightedNodeIds=new Set;highlightedEdgeIds=new Set;hoveredEdgeId=null;defaultHighlightedNodeIds=new Set;defaultHighlightedEdgeIds=new Set;prevEdgeStyleIds=new Set;nodeDefaultAttrs=new Map;edgeDefaultAttrs=new Map;lastModel=null;constructor(e,t,o,n,r,a){this.graph=e,this.schema=t,this.shapeRegistry=o,this.resolveNodeDecoration=n,this.resolveEdgeDecoration=r,this.resolveCanvasContext=a}syncFlowModel(e){if(!this.syncing){this.syncing=!0,this.lastModel=e;try{const t=this.resolveNodes(e),o=this.resolveEdges(e);this.syncNodes(t),this.syncEdges(o,e)}finally{this.syncing=!1}}}get isSyncing(){return this.syncing}saveNodeDefaultAttrs(e,t){const n=t.x6CellConfig?.attrs?.body;if(!n)return;const r={};let a=!1;n.stroke!==void 0&&(r.stroke=n.stroke,a=!0),n.strokeWidth!==void 0&&(r.strokeWidth=n.strokeWidth,a=!0),a&&this.nodeDefaultAttrs.set(e,r)}saveEdgeDefaultAttrs(e,t){const n=t?.x6EdgeConfig?.attrs?.line;if(!n)return;const r={};let a=!1;n.stroke!==void 0&&(r.stroke=n.stroke,a=!0),n.strokeWidth!==void 0&&(r.strokeWidth=n.strokeWidth,a=!0),n.strokeDasharray!==void 0&&(r.strokeDasharray=n.strokeDasharray,a=!0),a&&this.edgeDefaultAttrs.set(e,r)}restoreNodeAttr(e,t,o){const n=this.nodeDefaultAttrs.get(e.id)?.[o];n!==void 0?e.setAttrByPath(t,n):e.removeAttrByPath(t)}restoreEdgeAttr(e,t,o){const n=this.edgeDefaultAttrs.get(e.id)?.[o];n!==void 0?e.setAttrByPath(t,n):e.removeAttrByPath(t)}syncEdgeMarker(e,t,o){const r=t?.x6EdgeConfig?.attrs?.line?.[o],a=`line/${o}`;e.removeAttrByPath(a),r!==void 0&&e.setAttrByPath(a,r)}dispose(){this.knownNodeIds.clear(),this.knownEdgeIds.clear()}resolveNodes(e){const t=new Map;for(const[o,n]of Object.entries(e.nodes)){const r=this.schema.nodeTypes[n.type];if(!r)throw new Pe(`Unknown node type "${n.type}" for node "${o}". Registered types: [${Object.keys(this.schema.nodeTypes).join(", ")}]. Register the type in CanvasSchema.nodeTypes before using it in a FlowModel.`);const a=this.shapeRegistry.registerNodeType(n.type,r.component),d=r.getSize(n),l=ke(n,r.getPorts);t.set(o,{model:n,definition:r,shapeName:a,size:d,ports:l})}return t}resolveEdges(e){const t=new Map;for(const[o,n]of Object.entries(e.edges)){const r=n.type??this.schema.defaultEdgeType??"default",a=this.schema.edgeTypes?.[r];t.set(o,{model:n,definition:a})}return t}syncNodes(e){const t=new Set(e.keys());for(const o of this.knownNodeIds)if(!t.has(o)){const n=this.graph.getCellById(o);n&&this.graph.removeCell(n),this.knownNodeIds.delete(o),this.defaultHighlightedNodeIds.delete(o),this.prevNodeDecorationClasses.delete(o),this.prevNodeDecorationColors.delete(o),this.nodeDefaultAttrs.delete(o)}for(const[o,n]of e){const r=this.graph.getCellById(o);r?this.updateExistingNode(r,n):this.addNewNode(o,n)}}updateExistingNode(e,t){const{model:o,size:n,ports:r,definition:a}=t,d=e.getPosition();(d.x!==o.position.x||d.y!==o.position.y)&&e.setPosition(o.position.x,o.position.y);const l=e.getSize();(l.width!==n.width||l.height!==n.height)&&e.setSize(n.width,n.height,{silent:!0}),this.syncNodePorts(e,r),e.setData({...o}),this.applyNodeBehavior(e,o,a),this.applyNodeHighlightAndDecoration(e,o)}syncNodePorts(e,t){const o=e.getPorts(),n=new Set(t.map(a=>a.id)),r=new Set(o.map(a=>a.id));for(const a of o)a.id&&!n.has(a.id)&&e.removePort(a.id);for(const a of t)r.has(a.id)||e.addPort({id:a.id,group:a.group,...a.x6PortConfig})}addNewNode(e,t){const{model:o,shapeName:n,size:r,ports:a,definition:d}=t,l={id:o.id,shape:n,x:o.position.x,y:o.position.y,width:r.width,height:r.height,data:{...o},ports:{groups:{top:{position:"top",attrs:{circle:{r:6,magnet:!0,fill:"#3a84ff",stroke:"#fff",strokeWidth:1,visibility:"hidden"}}},right:{position:"right",attrs:{circle:{r:6,magnet:!0,fill:"#3a84ff",stroke:"#fff",strokeWidth:1,visibility:"hidden"}}},bottom:{position:"bottom",attrs:{circle:{r:6,magnet:!0,fill:"#3a84ff",stroke:"#fff",strokeWidth:1,visibility:"hidden"}}},left:{position:"left",attrs:{circle:{r:6,magnet:!0,fill:"#3a84ff",stroke:"#fff",strokeWidth:1,visibility:"hidden"}}}},items:a.map(c=>({id:c.id,group:c.group,...c.x6PortConfig}))},...d.x6CellConfig};this.graph.addNode(l),this.knownNodeIds.add(e),this.saveNodeDefaultAttrs(e,d);const p=this.graph.getCellById(e);p&&(this.applyNodeBehavior(p,o,d),this.applyNodeHighlightAndDecoration(p,o))}applyNodeBehavior(e,t,o){if(!o.getBehavior)return;const n=this.resolveCanvasContext?.();if(!n)return;const r=o.getBehavior(t,n);if(r.draggable!==void 0&&e.setProp("draggable",r.draggable,{silent:!0}),r.connectable!==void 0){const d=r.connectable;for(const l of e.getPorts())e.setPortProp(l.id,"attrs/circle/magnet",d,{silent:!0})}if(r.showPorts!==void 0){const d=r.showPorts;for(const l of e.getPorts())e.setPortProp(l.id,"attrs/circle/style/visibility",d?"visible":"hidden",{silent:!0})}const a=e.getData()??{};r.deletable!==void 0&&a._deletable!==r.deletable&&e.setData({...a,_deletable:r.deletable},{silent:!0}),r.selectable!==void 0&&a._selectable!==r.selectable&&e.setData({...e.getData(),_selectable:r.selectable},{silent:!0})}syncEdges(e,t){const o=new Set(e.keys());for(const n of this.knownEdgeIds)if(!o.has(n)){const r=this.graph.getCellById(n);r&&this.graph.removeCell(r),this.knownEdgeIds.delete(n),this.defaultHighlightedEdgeIds.delete(n),this.prevEdgeDecorationClasses.delete(n),this.prevEdgeDecorationColors.delete(n),this.prevEdgeStyleIds.delete(n),this.edgeDefaultAttrs.delete(n)}for(const[n,r]of e){const a=this.graph.getCellById(n),{model:d,definition:l}=r;a?(this.updateExistingEdge(a,d,l,t),this.knownEdgeIds.has(n)||(this.knownEdgeIds.add(n),this.saveEdgeDefaultAttrs(n,l))):this.addNewEdge(n,d,l)}}updateExistingEdge(e,t,o,n){const r=e.getSource(),a=e.getTarget();if((r.cell!==t.source.nodeId||r.port!==t.source.portId)&&e.setSource({cell:t.source.nodeId,port:t.source.portId}),(a.cell!==t.target.nodeId||a.port!==t.target.portId)&&e.setTarget({cell:t.target.nodeId,port:t.target.portId}),o?.router){const d=typeof o.router=="string"?{name:o.router}:o.router;e.setRouter(d)}if(o?.connector){const d=typeof o.connector=="string"?{name:o.connector}:o.connector;e.setConnector(d)}this.syncEdgeMarker(e,o,"sourceMarker"),this.syncEdgeMarker(e,o,"targetMarker"),this.syncEdgeLabels(e,t),e.setData({...t},{silent:!0}),this.applyEdgeStyleAndDecoration(e,t,o)}syncEdgeLabels(e,t){if(!t.labels?.length){e.getLabels().length>0&&e.setLabels([]);return}const o=t.labels.map(n=>({attrs:{label:{text:n.text??""}},position:n.position!=null?{distance:n.position}:void 0}));e.setLabels(o)}addNewEdge(e,t,o){const n={id:t.id,source:{cell:t.source.nodeId,port:t.source.portId},target:{cell:t.target.nodeId,port:t.target.portId},data:{...t},zIndex:-1};o?.router&&(n.router=typeof o.router=="string"?{name:o.router}:o.router),o?.connector&&(n.connector=typeof o.connector=="string"?{name:o.connector}:o.connector),o?.x6EdgeConfig&&Object.assign(n,o.x6EdgeConfig),t.labels?.length&&(n.labels=t.labels.map(a=>({attrs:{label:{text:a.text??""}},position:a.position!=null?{distance:a.position}:void 0}))),this.graph.addEdge(n),this.knownEdgeIds.add(e),this.saveEdgeDefaultAttrs(e,o);const r=this.graph.getCellById(e);r&&this.applyEdgeStyleAndDecoration(r,t,o)}refreshEdgeStyles(){if(this.lastModel)for(const[e,t]of Object.entries(this.lastModel.edges)){const o=this.graph.getCellById(e);if(!o?.isEdge())continue;const n=t.type??this.schema.defaultEdgeType??"default",r=this.schema.edgeTypes?.[n];this.applyEdgeStyleAndDecoration(o,t,r)}}refreshNodeHighlights(){if(this.lastModel)for(const[e,t]of Object.entries(this.lastModel.nodes)){const o=this.graph.getCellById(e);o?.isNode()&&this.applyNodeHighlightAndDecoration(o,t)}}applyNodeHighlightAndDecoration(e,t){const o=this.highlightedNodeIds.has(e.id),n=this.resolveNodeDecoration?.(t),r=this.prevNodeDecorationClasses.get(e.id);r&&(this.graph.findViewByCell(e)?.container?.classList.remove(r),this.prevNodeDecorationClasses.delete(e.id)),n?.className&&(this.graph.findViewByCell(e)?.container?.classList.add(n.className),this.prevNodeDecorationClasses.set(e.id,n.className));const a=n?.borderColor,l=a??(o?"#3a84ff":void 0),p=this.prevNodeDecorationColors.has(e.id)||this.defaultHighlightedNodeIds.has(e.id);l?(e.setAttrByPath("body/stroke",l),e.setAttrByPath("body/strokeWidth",2)):p&&(this.restoreNodeAttr(e,"body/stroke","stroke"),this.restoreNodeAttr(e,"body/strokeWidth","strokeWidth")),a?this.prevNodeDecorationColors.add(e.id):this.prevNodeDecorationColors.delete(e.id),o&&!a?this.defaultHighlightedNodeIds.add(e.id):this.defaultHighlightedNodeIds.delete(e.id)}setHoveredEdge(e){this.hoveredEdgeId=e}setHighlightedNodes(e){this.highlightedNodeIds=new Set(e)}setHighlightedEdges(e){this.highlightedEdgeIds=new Set(e)}applyEdgeStyleAndDecoration(e,t,o){const n=this.highlightedEdgeIds.has(e.id),r=this.resolveEdgeDecoration?.(t),a=this.prevEdgeDecorationClasses.get(e.id);a&&(this.graph.findViewByCell(e)?.container?.classList.remove(a),this.prevEdgeDecorationClasses.delete(e.id)),r?.className&&(this.graph.findViewByCell(e)?.container?.classList.add(r.className),this.prevEdgeDecorationClasses.set(e.id,r.className));let d,l,p;if(o?.style){const M=this.graph.isSelected?.(e)??!1,C=this.hoveredEdgeId===e.id,k=o.style(t,{selected:M,highlighted:n,hovered:C});d=k.stroke,l=k.strokeWidth,p=k.strokeDasharray}const c=!o?.style&&n?"#3a84ff":void 0,w=r?.strokeColor,b=w??d??c,h=!!o?.style||this.prevEdgeDecorationColors.has(e.id)||this.defaultHighlightedEdgeIds.has(e.id)||this.prevEdgeStyleIds.has(e.id);b?e.setAttrByPath("line/stroke",b):h&&this.restoreEdgeAttr(e,"line/stroke","stroke"),o?.style?(this.prevEdgeStyleIds.add(e.id),l?e.setAttrByPath("line/strokeWidth",l):this.restoreEdgeAttr(e,"line/strokeWidth","strokeWidth"),p?e.setAttrByPath("line/strokeDasharray",p):this.restoreEdgeAttr(e,"line/strokeDasharray","strokeDasharray")):this.prevEdgeStyleIds.has(e.id)&&(this.restoreEdgeAttr(e,"line/strokeWidth","strokeWidth"),this.restoreEdgeAttr(e,"line/strokeDasharray","strokeDasharray"),this.prevEdgeStyleIds.delete(e.id)),w?this.prevEdgeDecorationColors.add(e.id):this.prevEdgeDecorationColors.delete(e.id),c?this.defaultHighlightedEdgeIds.add(e.id):this.defaultHighlightedEdgeIds.delete(e.id)}}let ht=0;function A(){const s=Date.now().toString(36),e=Math.random().toString(36).substring(2,8);return`${s}-${e}-${++ht}`}class vt{instanceId=A();registeredShapes=new Map;getShapeName(e){let t=this.registeredShapes.get(e);return t||(t=`flow-node-${this.instanceId}-${e}`,this.registeredShapes.set(e,t)),t}registerNodeType(e,t){const o=this.getShapeName(e);return Xe.register({shape:o,component:t,width:100,height:40}),o}dispose(){this.registeredShapes.clear()}}class mt{graph;onUiEvent;onCommand;flowModelRef;disposers=[];constructor(e,t,o,n){this.graph=e,this.onUiEvent=t,this.onCommand=o,this.flowModelRef=n,this.bindEvents()}dispose(){for(const e of this.disposers)e();this.disposers=[]}bindEvents(){this.on("node:click",({node:e})=>{this.onUiEvent({type:"node.click",nodeId:e.id})}),this.on("node:dblclick",({node:e})=>{this.onUiEvent({type:"node.dblclick",nodeId:e.id})}),this.on("node:contextmenu",({node:e,e:t})=>{this.onUiEvent({type:"node.contextmenu",nodeId:e.id,position:{x:t.clientX,y:t.clientY}})}),this.on("edge:click",({edge:e,e:t})=>{const n=t.target?.closest?.(".x6-edge-label");if(n){const a=e.getData?.()?.labels??[],d=n.parentElement?.querySelectorAll(".x6-edge-label"),l=d?Array.from(d).indexOf(n):0,p=a[Math.max(0,l)];this.onUiEvent({type:"edge.label.click",edgeId:e.id,labelId:p?.id??`label-${l}`});return}this.onUiEvent({type:"edge.click",edgeId:e.id})}),this.on("blank:click",({e})=>{const t=this.graph.clientToLocal(e.clientX,e.clientY);this.onUiEvent({type:"blank.click",position:{x:t.x,y:t.y}})}),this.on("blank:contextmenu",({e})=>{this.onUiEvent({type:"blank.contextmenu",position:{x:e.clientX,y:e.clientY}})}),this.on("node:moved",({node:e})=>{const t=e.getPosition();this.onCommand({id:A(),source:"user:drag",label:"移动节点",timestamp:Date.now(),commands:[{type:"node.move",nodeId:e.id,position:{x:t.x,y:t.y}}]})}),this.on("edge:connected",({edge:e,isNew:t})=>{const o=e.getSourceCell(),n=e.getTargetCell();if(!o||!n)return;const r=e.getSourcePortId(),a=e.getTargetPortId(),d=e.id in this.flowModelRef.value.edges;t&&!d?this.onCommand({id:A(),source:"user:drag",label:"连线",timestamp:Date.now(),commands:[{type:"edge.add",edge:{id:e.id,source:{nodeId:o.id,portId:r??void 0},target:{nodeId:n.id,portId:a??void 0}}}]}):this.onCommand({id:A(),source:"user:drag",label:"重连",timestamp:Date.now(),commands:[{type:"edge.reconnect",edgeId:e.id,source:{nodeId:o.id,portId:r??void 0},target:{nodeId:n.id,portId:a??void 0}}]})}),this.on("edge:change:labels",({edge:e,current:t})=>{const n=e.getData?.()?.labels??[];if(!n.length||!t?.length)return;const r=[];for(let a=0;a<Math.min(n.length,t.length);a++){const d=t[a],l=n[a];if(!l?.id)continue;const p=typeof d.position=="object"?d.position?.distance:d.position;p!=null&&r.push({type:"edge.label.update",edgeId:e.id,labelId:l.id,patch:{position:p}})}r.length&&this.onCommand({id:A(),source:"user:drag",label:"拖动标签",timestamp:Date.now(),commands:r})})}on(e,t){this.graph.on(e,t),this.disposers.push(()=>this.graph.off(e,t))}}function yt(s){function e(t){const o=s.getCellById(t);if(!o||!o.isNode())return null;const n=o,r=n.getPosition(),a=n.getSize(),d={x:r.x,y:r.y,width:a.width,height:a.height},l=s.localToGraph(d);return new DOMRect(l.x,l.y,l.width,l.height)}return{getNodeScreenRect:e}}const bt=100;function wt({graph:s,overlayManager:e,executeCommand:t,schema:o,flowModel:n,defaultInsertGap:r,getContextMenuItems:a,onHighlightChange:d,resolveNodeShape:l}){let p=[],c=[],w=null,b=!1,h=null,M=!1;async function C(){if(b)return w;b=!0;try{const g=await import("@antv/x6-plugin-dnd"),u=g.Dnd??g.default;return u?(w=new u({target:s,scaled:!0,animation:!0,getDragNode:x=>x.clone(),getDropNode:x=>x.clone()}),w):null}catch{return console.warn("[flow-canvas] @antv/x6-plugin-dnd not available, add it to your dependencies"),null}}async function k(){if(!M){M=!0;try{const g=await import("@antv/x6-plugin-export"),u=g.Export??g.default;u&&s.use(new u)}catch{console.warn("[flow-canvas] @antv/x6-plugin-export not available, add it to your dependencies")}}}const E=({node:g})=>{const u=g.getData?.();if(!u?._dndSessionId||u._dndSessionId!==h)return;h=null;const x=g.getPosition();s.removeNode(g.id);const{_dndSessionId:$,...P}=u,L=P.id||A();t({id:A(),source:"user:drag",label:"拖入节点",timestamp:Date.now(),commands:[{type:"node.add",node:{...P,id:L,position:{x:x.x,y:x.y}}}]})};s.on("node:added",E);function B(g){const u=o.nodeTypes[g.type];return ke(g,u?.getPorts)}function z(g,u,x,$,P){switch(g){case"left":return{x:u.position.x-P-$.width,y:u.position.y+(x.height-$.height)/2};case"top":return{x:u.position.x+(x.width-$.width)/2,y:u.position.y-P-$.height};case"bottom":return{x:u.position.x+(x.width-$.width)/2,y:u.position.y+x.height+P};default:return{x:u.position.x+x.width+P,y:u.position.y+(x.height-$.height)/2}}}function R(g,u,x){switch(g){case"left":return{x:-(u.width+x),y:0};case"top":return{x:0,y:-(u.height+x)};case"bottom":return{x:0,y:u.height+x};default:return{x:u.width+x,y:0}}}function q(g){switch(g){case"left":return"right";case"top":return"bottom";case"bottom":return"top";default:return"left"}}return{zoomIn(){s.zoom(.1)},zoomOut(){s.zoom(-.1)},zoomTo(g){s.zoomTo(g)},zoomToFit(){s.zoomToFit({padding:40,maxScale:1.5})},getZoom(){return s.zoom()},centerContent(){s.centerContent()},scrollToOrigin(){s.translate(0,0)},scrollToNode(g){const u=s.getCellById(g);u&&s.centerCell(u)},getSelection(){const g=s.getSelectedCells?.()??[];return{nodeIds:g.filter(u=>u.isNode()).map(u=>u.id),edgeIds:g.filter(u=>u.isEdge()).map(u=>u.id)}},selectNodes(g){const u=g.map(x=>s.getCellById(x)).filter(Boolean);s.select?.(u)},selectEdges(g){const u=g.map(x=>s.getCellById(x)).filter(Boolean);s.select?.(u)},clearSelection(){const g=s.getSelectedCells?.();g?.length&&s.unselect?.(g)},registerDndSource(g,u){const x=async $=>{const P=await C();if(!P)return;const L=A();h=L;const V=u(),O=l?.(V.type),G=s.createNode({width:O?.width??154,height:O?.height??54,shape:O?.shapeName??"rect",data:{...V,_dndSessionId:L}});P.start(G,$)};return g.addEventListener("mousedown",x),()=>{g.removeEventListener("mousedown",x)}},startConnection(g,u){const x=s.getCellById(g);if(!x?.isNode())return;const $=x,P=s.findViewByCell($);if(!P)return;const L=P.findPortElem(u,"circle")??P.findPortElem(u);if(!L)return;const O=(L.matches?.("[magnet]")?L:L.querySelector?.("[magnet]"))??L,G=O.getBoundingClientRect(),ae=G.left+G.width/2,Z=G.top+G.height/2,te=new MouseEvent("mousedown",{clientX:ae,clientY:Z,button:0,buttons:1,bubbles:!0,cancelable:!0});O.dispatchEvent(te)},async exportAsImage(g){await k();const u=s;return typeof u.toPNG!="function"?(console.warn("[flow-canvas] exportAsImage requires @antv/x6-plugin-export, add it to your dependencies"),new Blob):new Promise(x=>{u.toPNG($=>{fetch($).then(P=>P.blob()).then(x).catch(()=>x(new Blob))},{backgroundColor:g?.backgroundColor??"#ffffff",padding:g?.padding??20,quality:g?.quality,copyStyles:!0})})},async exportAsSVG(){await k();const g=s;return typeof g.toSVG!="function"?(console.warn("[flow-canvas] exportAsSVG requires @antv/x6-plugin-export, add it to your dependencies"),""):new Promise(u=>{g.toSVG(x=>u(x))})},highlightNodes(g){p=g,d?.(p,c)},highlightEdges(g){c=g,d?.(p,c)},clearHighlight(){p=[],c=[],d?.([],[])},overlay:e,getContextMenuItems(g){return a?.(g)??[]},insertNodeToRight(g,u,x){const $=n.value,P=$.nodes[g];if(!P)return{status:"invalid",envelope:{id:"",source:"user:toolbar",timestamp:Date.now(),commands:[]},error:{code:"constraint_violated",reason:`Source node "${g}" not found`,source:"api"}};const L=x?.gap??r??bt,V=x?.direction??"right",O=o.nodeTypes[P.type],G=o.nodeTypes[u.type],ae=O?.getSize(P)??{width:154,height:54},Z=G?.getSize({...u,position:{x:0,y:0}})??{width:154,height:54},te=z(V,P,ae,Z,L),J=u.id||A(),ue={...u,id:J,position:te},W=[{type:"node.add",node:ue}],fe=R(V,Z,L),Q={x:te.x,y:te.y,width:Z.width,height:Z.height};for(const[oe,j]of Object.entries($.nodes)){if(oe===g||oe===J)continue;const se=o.nodeTypes[j.type]?.getSize(j)??{width:154,height:54},K=Q.x<j.position.x+se.width&&Q.x+Q.width>j.position.x,ie=Q.y<j.position.y+se.height&&Q.y+Q.height>j.position.y;K&&ie&&W.push({type:"node.move",nodeId:oe,position:{x:j.position.x+fe.x,y:j.position.y+fe.y}})}if(x?.autoWireEdges){const oe=B(P),j=B(ue),X=V,se=q(V),K=oe.find(v=>v.group===X),ie=j.find(v=>v.group===se),ye=j.find(v=>v.group===X),m=K?Object.values($.edges).find(v=>v.source.nodeId===g&&v.source.portId===K.id):Object.values($.edges).find(v=>v.source.nodeId===g);if(m){const v=m.target;W.push({type:"edge.remove",edgeId:m.id}),W.push({type:"edge.add",edge:{id:A(),source:{nodeId:g,portId:K?.id},target:{nodeId:J,portId:ie?.id}}}),W.push({type:"edge.add",edge:{id:A(),source:{nodeId:J,portId:ye?.id},target:v}})}else W.push({type:"edge.add",edge:{id:A(),source:{nodeId:g,portId:K?.id},target:{nodeId:J,portId:ie?.id}}})}const me={id:A(),source:x?.source??"user:toolbar",label:x?.label??"插入节点",timestamp:Date.now(),commands:W};return t(me)},onGraphEvent(g,u){return s.on(g,u),()=>s.off(g,u)},unsafeGetGraph(){return s}}}function kt(){const s=i.ref(null),e=i.ref(!1);let t=null,o=!1;function n(c){t&&(clearTimeout(t),t=null),s.value=c}function r(c=100){o||(t&&clearTimeout(t),t=setTimeout(()=>{s.value=null,t=null},c))}function a(){o=!0,t&&(clearTimeout(t),t=null)}function d(c=100){o=!1,r(c)}function l(){t&&(clearTimeout(t),t=null)}function p(){t&&clearTimeout(t)}return{hoveredNodeId:s,isDraggingNode:e,enter:n,leave:r,enterOverlay:a,leaveOverlay:d,cancelLeave:l,cleanup:p}}const xe=10;function Ne(s,e){const t=s.getTotalLength();if(t===0)return{...e,length:0,totalLength:0};let o=s.getPointAtLength(0),n=1/0;const r=50,a=t/r;let d=0;for(let w=0;w<=r;w++){const b=w*a,h=s.getPointAtLength(b),M=(h.x-e.x)**2+(h.y-e.y)**2;M<n&&(n=M,o=h,d=b)}const l=Math.max(0,d-a),p=Math.min(t,d+a),c=(p-l)/20;for(let w=l;w<=p;w+=c){const b=s.getPointAtLength(w),h=(b.x-e.x)**2+(b.y-e.y)**2;h<n&&(n=h,o=b,d=w)}return{x:o.x,y:o.y,length:d,totalLength:t}}function Ie(s,e){return s<xe||s>e-xe}function Me(){const s="http://www.w3.org/2000/svg",e=document.createElementNS(s,"g");e.setAttribute("class","flow-canvas-edge-delete-tool"),e.style.cursor="pointer";const t=document.createElementNS(s,"rect");t.setAttribute("width","20"),t.setAttribute("height","20"),t.setAttribute("x","-10"),t.setAttribute("y","-10"),t.setAttribute("rx","4"),t.setAttribute("ry","4"),t.setAttribute("fill","#3a84ff"),e.appendChild(t);const o=document.createElementNS(s,"text");return o.setAttribute("font-family","flow-canvas"),o.setAttribute("font-size","16"),o.setAttribute("fill","#ffffff"),o.setAttribute("text-anchor","middle"),o.setAttribute("dominant-baseline","central"),o.textContent="",e.appendChild(o),e}function Et(s){let e=null,t=null;function o(d,l){r(),t=d;const p=s.getCellById(d);if(!p?.isEdge())return;const c=s.findViewByCell(p);if(!c)return;const w=c.container.querySelector("path");if(!w)return;const b=s.clientToLocal(l.clientX,l.clientY),h=Ne(w,b);if(Ie(h.length,h.totalLength))return;const M=Me();M.setAttribute("transform",`translate(${h.x}, ${h.y})`),c.container.appendChild(M),e=M}function n(d){if(!t)return;const l=s.getCellById(t);if(!l?.isEdge())return;const p=s.findViewByCell(l);if(!p)return;const c=p.container.querySelector("path");if(!c)return;const w=s.clientToLocal(d.clientX,d.clientY),b=Ne(c,w);if(Ie(b.length,b.totalLength))e&&e.setAttribute("display","none");else if(e)e.removeAttribute("display"),e.setAttribute("transform",`translate(${b.x}, ${b.y})`);else{const h=Me();h.setAttribute("transform",`translate(${b.x}, ${b.y})`),p.container.appendChild(h),e=h}}function r(){e&&(e.remove(),e=null),t=null}function a(d){d===t&&(e=null,t=null)}return{show:o,move:n,remove:r,handleEdgeRemoved:a}}function Ct(s){let e=null,t=0;function o(c){const w=c?"visible":"hidden";for(const b of s.getNodes())for(const h of b.getPorts())b.setPortProp(h.id,"attrs/circle/visibility",w)}function n(c){if(!e)for(const w of c.getPorts())c.setPortProp(w.id,"attrs/circle/visibility","visible")}function r(c){if(!e)for(const w of c.getPorts())c.setPortProp(w.id,"attrs/circle/visibility","hidden")}function a(c){c.getTargetCell()||(e=c.id,o(!0))}function d(){e=null,o(!1),t=Date.now()+300}function l(c){c===e&&(e=null,o(!1))}function p(){return!e&&Date.now()>=t}return{showNodePorts:n,hideNodePorts:r,handleEdgeAdded:a,handleEdgeConnected:d,handleEdgeRemoved:l,canShowEdgeTool:p}}const xt={class:"flow-canvas-node-actions__bar"},Nt=i.defineComponent({__name:"node-actions-toolbar",props:{node:{},position:{},config:{},behavior:{},actionsOffset:{}},emits:["action"],setup(s,{emit:e}){const t=s,o=i.computed(()=>{const w=t.actionsOffset?.x??0,b=t.actionsOffset?.y??0,h=w!==0||b!==0;return{left:`${t.position.x}px`,top:`${t.position.y}px`,transform:h?`translate(${w}px, ${b}px)`:"translateX(-100%)"}}),n=e,r=i.computed(()=>({debug:{visible:t.config.showDebug&&t.behavior.debuggable!==!1,disabled:t.behavior.debugDisabled===!0},delete:{visible:t.config.showDelete&&t.behavior.deletable!==!1,disabled:t.behavior.deleteDisabled===!0},copy:{visible:t.config.showCopy&&t.behavior.copyable!==!1,disabled:t.behavior.copyDisabled===!0},copyInsert:{visible:t.config.showCopyInsert&&t.behavior.copyable!==!1,disabled:t.behavior.copyInsertDisabled===!0},disconnect:{visible:t.config.showDisconnect&&t.behavior.disconnectable!==!1,disabled:t.behavior.disconnectDisabled===!0}})),a=i.computed(()=>r.value.copy.visible||r.value.copyInsert.visible||r.value.disconnect.visible),d=i.ref(!1);let l=null;function p(){l&&(clearTimeout(l),l=null),d.value=!0}function c(){l=setTimeout(()=>{d.value=!1,l=null},100)}return i.onBeforeUnmount(()=>{l&&clearTimeout(l)}),(w,b)=>(i.openBlock(),i.createElementBlock("div",{class:"flow-canvas-node-actions",style:i.normalizeStyle(o.value)},[i.createElementVNode("div",xt,[r.value.debug.visible?(i.openBlock(),i.createElementBlock("i",{key:0,class:i.normalizeClass(["flow-canvas-icon canvas-debug flow-canvas-node-actions__icon",{"is-disabled":r.value.debug.disabled}]),onClick:b[0]||(b[0]=h=>!r.value.debug.disabled&&n("action","debug",s.node.id))},null,2)):i.createCommentVNode("",!0),r.value.delete.visible?(i.openBlock(),i.createElementBlock("i",{key:1,class:i.normalizeClass(["flow-canvas-icon canvas-shanchu flow-canvas-node-actions__icon",{"is-disabled":r.value.delete.disabled}]),onClick:b[1]||(b[1]=h=>!r.value.delete.disabled&&n("action","delete",s.node.id))},null,2)):i.createCommentVNode("",!0),a.value?(i.openBlock(),i.createElementBlock("div",{key:2,class:"flow-canvas-node-actions__more-wrapper",onMouseenter:p,onMouseleave:c},[...b[5]||(b[5]=[i.createElementVNode("i",{class:"flow-canvas-icon canvas-gengduo flow-canvas-node-actions__icon"},null,-1)])],32)):i.createCommentVNode("",!0)]),i.createVNode(i.Transition,{name:"flow-canvas-fade"},{default:i.withCtx(()=>[d.value&&a.value?(i.openBlock(),i.createElementBlock("div",{key:0,class:"flow-canvas-node-actions__dropdown",onMouseenter:p,onMouseleave:c},[r.value.copy.visible?(i.openBlock(),i.createElementBlock("div",{key:0,class:i.normalizeClass(["flow-canvas-node-actions__dropdown-item",{"is-disabled":r.value.copy.disabled}]),onClick:b[2]||(b[2]=h=>!r.value.copy.disabled&&n("action","copy",s.node.id))},[...b[6]||(b[6]=[i.createElementVNode("i",{class:"flow-canvas-icon canvas-copy-fuzhi-2"},null,-1),i.createElementVNode("span",null,"复制",-1)])],2)):i.createCommentVNode("",!0),r.value.copyInsert.visible?(i.openBlock(),i.createElementBlock("div",{key:1,class:i.normalizeClass(["flow-canvas-node-actions__dropdown-item",{"is-disabled":r.value.copyInsert.disabled}]),onClick:b[3]||(b[3]=h=>!r.value.copyInsert.disabled&&n("action","copy-insert",s.node.id))},[...b[7]||(b[7]=[i.createElementVNode("i",{class:"flow-canvas-icon canvas-fuzhibingcharu"},null,-1),i.createElementVNode("span",null,"复制并插入",-1)])],2)):i.createCommentVNode("",!0),r.value.disconnect.visible?(i.openBlock(),i.createElementBlock("div",{key:2,class:i.normalizeClass(["flow-canvas-node-actions__dropdown-item",{"is-disabled":r.value.disconnect.disabled}]),onClick:b[4]||(b[4]=h=>!r.value.disconnect.disabled&&n("action","disconnect",s.node.id))},[...b[8]||(b[8]=[i.createElementVNode("i",{class:"flow-canvas-icon canvas-unlock-jiebang"},null,-1),i.createElementVNode("span",null,"断开连线",-1)])],2)):i.createCommentVNode("",!0)],32)):i.createCommentVNode("",!0)]),_:1})],4))}}),ne=(s,e)=>{const t=s.__vccOpts||s;for(const[o,n]of e)t[o]=n;return t},Ae=ne(Nt,[["__scopeId","data-v-3b39dab5"]]),It={key:0,class:"flow-canvas-quick-add__tooltip"},Mt=5,St=i.defineComponent({__name:"node-quick-add-popover",props:{node:{},portPosition:{},tooltipText:{}},emits:["open","close","start-drag","mouseenter","mouseleave"],setup(s,{expose:e,emit:t}){const o=s,n=t,r=i.ref(),a=i.ref(),d=i.ref(!1),l=i.ref(!1);let p=null,c=!1,w=null;function b(g){g.preventDefault(),g.stopPropagation(),p={x:g.clientX,y:g.clientY},c=!1,document.addEventListener("mousemove",h),document.addEventListener("mouseup",M)}function h(g){if(!p)return;const u=g.clientX-p.x,x=g.clientY-p.y;Math.sqrt(u*u+x*x)>=Mt&&(c=!0,C(),n("start-drag",o.node.id))}function M(){C(),c||k(),p=null,c=!1}function C(){document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",M)}function k(){l.value?B():E()}function E(){l.value=!0,n("open",o.node.id),requestAnimationFrame(()=>{document.addEventListener("mousedown",z)})}function B(){l.value=!1,n("close"),document.removeEventListener("mousedown",z)}function z(g){const u=g.target;r.value?.contains(u)||a.value?.contains(u)||B()}function R(){l.value||n("mouseleave")}function q(){w&&(clearTimeout(w),w=null),n("mouseenter")}function U(){w=setTimeout(()=>{B(),n("mouseleave"),w=null},150)}return i.onBeforeUnmount(()=>{C(),w&&clearTimeout(w),document.removeEventListener("mousedown",z)}),e({closePopover:B}),(g,u)=>(i.openBlock(),i.createElementBlock("div",{class:"flow-canvas-quick-add",style:i.normalizeStyle({left:`${s.portPosition.x}px`,top:`${s.portPosition.y}px`}),onMouseenter:u[2]||(u[2]=x=>n("mouseenter")),onMouseleave:R,onClick:u[3]||(u[3]=i.withModifiers(()=>{},["stop"]))},[i.createElementVNode("div",{ref_key:"btnRef",ref:r,class:i.normalizeClass(["flow-canvas-quick-add__btn",{"is-hovered":d.value,"is-active":l.value}]),onMouseenter:u[0]||(u[0]=x=>d.value=!0),onMouseleave:u[1]||(u[1]=x=>d.value=!1),onMousedown:b},[...u[4]||(u[4]=[i.createElementVNode("i",{class:"flow-canvas-icon canvas-zoom-add"},null,-1)])],34),d.value&&!l.value?(i.openBlock(),i.createElementBlock("div",It,[...u[5]||(u[5]=[i.createElementVNode("div",null,[i.createElementVNode("b",null,"点击"),i.createTextVNode(" 添加节点")],-1),i.createElementVNode("div",null,[i.createElementVNode("b",null,"拖拽"),i.createTextVNode(" 连接节点")],-1)])])):i.createCommentVNode("",!0),i.createVNode(i.Transition,{name:"flow-canvas-fade"},{default:i.withCtx(()=>[l.value?(i.openBlock(),i.createElementBlock("div",{key:0,ref_key:"popoverRef",ref:a,class:"flow-canvas-quick-add__popover",onMouseenter:q,onMouseleave:U},[i.renderSlot(g.$slots,"default",{},()=>[u[6]||(u[6]=i.createElementVNode("div",{class:"flow-canvas-quick-add__default-content"},"节点快捷操作面板",-1))],!0)],544)):i.createCommentVNode("",!0)]),_:3})],36))}}),Te=ne(St,[["__scopeId","data-v-deb5af25"]]),Dt={class:"flow-canvas-runtime-core__overlay"},Pt=i.defineComponent({__name:"canvas-runtime-core",props:{editor:{},graphOptions:{},nodeActions:{},quickAdd:{}},emits:["ui-event"],setup(s,{emit:e}){const t=s,o=e,n=i.ref(),r=i.ref();let a,d,l,p;const c=kt(),{hoveredNodeId:w,isDraggingNode:b}=c,h=c.enterOverlay,M=()=>c.leaveOverlay(),C=i.ref(null);let k=null;function E(m){return z(),W(m)?(C.value=m,!0):(C.value=null,!1)}function B(){k&&clearTimeout(k),k=setTimeout(()=>{C.value=null,k=null},150)}function z(){k&&(clearTimeout(k),k=null)}function R(){z(),c.enterOverlay()}function q(){B(),c.leaveOverlay()}let U=null,g=null,u=null;const x=i.ref(0),$=i.computed(()=>{if(x.value,!t.editor.api.value)return[];const m=t.editor.flowModel.value,v=t.editor.api.value.overlay,f=[];for(const[N,S]of Object.entries(m.nodes)){const D=t.editor._pluginManager.collectNodeDecorations(S);if(!D?.badge)continue;const _=v.getNodeScreenRect(N);_&&f.push({nodeId:N,x:_.x+_.width-4,y:_.y-8,badge:D.badge})}return f}),P=i.computed(()=>({showDebug:!1,showDelete:!0,showCopy:!0,showCopyInsert:!0,showDisconnect:!0,insertGap:100,...t.nodeActions})),L=i.computed(()=>{x.value;const m=w.value;if(!m||b.value||!t.editor.api.value||t.editor.mode.value!=="edit")return null;const v=t.editor.flowModel.value,f=v.nodes[m];if(!f)return null;const N=t.editor.api.value.overlay.getNodeScreenRect(m);if(!N)return null;const D=t.editor.schema.nodeTypes[f.type]?.getBehavior?.(f,{api:t.editor.api.value,flowModel:v,history:t.editor.history,mode:t.editor.mode.value})??{};return D.showActions===!1?null:{node:f,position:{x:N.x+N.width,y:N.y+N.height+4},behavior:D}}),V=i.computed(()=>({enabled:!0,tooltipText:"",portGroup:"right",...t.quickAdd})),O=i.computed(()=>{if(x.value,!V.value.enabled)return null;const m=C.value;if(!m||b.value||!t.editor.api.value||t.editor.mode.value!=="edit")return null;const v=t.editor.flowModel.value,f=v.nodes[m];if(!f)return null;const S=t.editor.schema.nodeTypes[f.type]?.getBehavior?.(f,{api:t.editor.api.value,flowModel:v,history:t.editor.history,mode:t.editor.mode.value})??{};if(S.quickAddEnabled===!1)return null;const D=X(f);return D?{node:f,portId:D.portId,portGroup:D.portGroup,portPosition:D.portPosition,behavior:S}:null}),G=i.ref();function ae(m){const v=O.value;v&&o("ui-event",{type:"node.quick-add",nodeId:m,position:v.portPosition})}function Z(m){const v=t.editor.api.value;if(!v)return;const N=t.editor.flowModel.value.nodes[m];if(!N)return;const S=X(N);S&&v.startConnection(m,S.portId)}function te(m,v){const f=t.editor.api.value;if(!f)return;const N=v.id||A(),S={...v,id:N},D=t.editor.flowModel.value.nodes[m];if(!D)return;f.insertNodeToRight(m,S,{autoWireEdges:!0,direction:se(D),gap:P.value.insertGap,source:"user:quick-add",label:"快捷插入节点"}).status==="applied"&&o("ui-event",{type:"node.action.quick-insert",sourceNodeId:m,newNodeId:N}),G.value?.closePopover()}function J(m){return{id:A(),type:m.type,label:m.label,ports:m.ports?JSON.parse(JSON.stringify(m.ports)):void 0,payload:m.payload?JSON.parse(JSON.stringify(m.payload)):void 0,extensions:m.extensions?JSON.parse(JSON.stringify(m.extensions)):void 0}}function ue(m,v){const f=t.editor,N=f.api.value;switch(m){case"delete":{f.executeCommand({id:A(),source:"user:toolbar",label:"删除节点",timestamp:Date.now(),commands:[{type:"node.remove",nodeId:v}]}),o("ui-event",{type:"node.action.delete",nodeId:v}),w.value=null;break}case"copy":{if(!N)break;const S=f.flowModel.value.nodes[v];if(!S)break;const D=J(S);N.insertNodeToRight(v,D,{autoWireEdges:!1,gap:P.value.insertGap,label:"复制节点"}),o("ui-event",{type:"node.action.copy",sourceNodeId:v,newNodeId:D.id});break}case"copy-insert":{if(!N)break;const S=f.flowModel.value.nodes[v];if(!S)break;const D=J(S);N.insertNodeToRight(v,D,{autoWireEdges:!0,gap:P.value.insertGap,label:"复制并插入节点"}),o("ui-event",{type:"node.action.copy-insert",sourceNodeId:v,newNodeId:D.id});break}case"disconnect":{const S=f.flowModel.value,D=Object.entries(S.edges).filter(([,_])=>{const F=_;return F.source.nodeId===v||F.target.nodeId===v}).map(([_])=>_);if(D.length===0)break;f.executeCommand({id:A(),source:"user:toolbar",label:"断开连线",timestamp:Date.now(),commands:D.map(_=>({type:"edge.remove",edgeId:_}))}),o("ui-event",{type:"node.action.disconnect",nodeId:v,edgeIds:D});break}case"debug":{o("ui-event",{type:"node.action.debug",nodeId:v});break}}}function W(m){if(!V.value.enabled||t.editor.mode.value!=="edit")return!1;const v=t.editor.flowModel.value,f=v.nodes[m];return!f||(t.editor.schema.nodeTypes[f.type]?.getBehavior?.(f,{api:t.editor.api.value,flowModel:v,history:t.editor.history,mode:t.editor.mode.value})??{}).quickAddEnabled===!1?!1:!!X(f)}function fe(m){const v=t.editor.schema.nodeTypes[m.type];return ke(m,v?.getPorts)}function Q(m){return m==="top"||m==="right"||m==="bottom"||m==="left"}function me(m,v){const f=V.value.getPort?.(m,v);if(!f)return null;const N=typeof f=="string"?f:f.id;return v.find(S=>S.id===N)??null}function oe(m,v){const f=t.editor.api.value?.overlay.getNodeScreenRect(m);if(!f)return null;switch(v){case"top":return{x:f.x+f.width/2,y:f.y};case"bottom":return{x:f.x+f.width/2,y:f.y+f.height};case"left":return{x:f.x,y:f.y+f.height/2};case"right":return{x:f.x+f.width,y:f.y+f.height/2};default:return null}}function j(m,v,f){const N=a.getCellById(m);if(N?.isNode()){const S=N,D=a.findViewByCell(S),_=D?.findPortElem(v,"circle")??D?.findPortElem(v);if(_){const F=a.container.getBoundingClientRect(),ee=_.getBoundingClientRect();return{x:ee.left-F.left+ee.width/2,y:ee.top-F.top+ee.height/2}}}return oe(m,f)}function X(m){const v=fe(m),f=me(m,v)??v.find(S=>S.group===V.value.portGroup)??null;if(!f)return null;const N=j(m.id,f.id,f.group);return N?{portId:f.id,portGroup:f.group,portPosition:N}:null}function se(m){const v=X(m),f=V.value.insertDirection;if(typeof f=="function"){const N=f(m,v?{id:v.portId,group:v.portGroup}:null);if(N)return N}else if(f)return f;return v&&Q(v.portGroup)?v.portGroup:Q(V.value.portGroup)?V.value.portGroup:"right"}function K(m){if(t.editor.mode.value!=="edit")return;t.editor._pluginManager.dispatchKeyboardShortcut(m)&&(m.preventDefault(),m.stopPropagation())}function ie(){return{refX:0,children:[{tagName:"path",d:"M -16 -5 L -8 0 L -16 5 Z",transform:"rotate(0)"},{tagName:"circle",cx:0,cy:0,r:8,fill:"#3a84ff",stroke:"#3a84ff",transform:"rotate(0)"}]}}function ye(m){const v=t.editor.schema.defaultEdgeType??"default",f=t.editor.schema.edgeTypes?.[v],N={zIndex:-1,attrs:{line:{stroke:"#abb5cc",strokeWidth:2,targetMarker:{name:"block",width:8,height:8}}}};f?.router&&(N.router=typeof f.router=="string"?{name:f.router}:f.router),f?.connector&&(N.connector=typeof f.connector=="string"?{name:f.connector}:f.connector),f?.x6EdgeConfig&&Object.assign(N,f.x6EdgeConfig);const S=N.attrs??{},D=S.line??{};return N.attrs={...S,line:{...D,targetMarker:ie()}},m.createEdge(N)}return i.onMounted(()=>{if(!r.value)return;const m=new Set(["model","container"]),v={};if(t.graphOptions)for(const[y,I]of Object.entries(t.graphOptions)){if(m.has(y)){console.warn(`[flow-canvas] graphOptions.${y} is managed by the engine and will be ignored`);continue}v[y]=I}a=new Qe.Graph({container:r.value,autoResize:!0,background:{color:"#edf2fc"},grid:{visible:!0,size:20,type:"dot"},panning:{enabled:!0},mousewheel:{enabled:!0,modifiers:["ctrl","meta"]},interacting:{nodeMovable(y){return y.cell.getProp("draggable")!==!1}},connecting:{allowBlank:!1,allowMulti:!0,allowLoop:!1,allowNode:!1,allowEdge:!1,highlight:!0,anchor:"center",connectionPoint:"anchor",snap:{radius:30},createEdge(){return ye(this)}},...v}),l=new vt,d=new gt(a,t.editor.schema,l,y=>t.editor._pluginManager.collectNodeDecorations(y),y=>t.editor._pluginManager.collectEdgeDecorations(y),()=>t.editor.api.value?{api:t.editor.api.value,flowModel:t.editor.flowModel.value,history:t.editor.history,mode:t.editor.mode.value}:null);const f=yt(a),N=wt({graph:a,overlayManager:f,executeCommand:y=>t.editor.executeCommand(y),schema:t.editor.schema,flowModel:t.editor.flowModel,defaultInsertGap:t.nodeActions?.insertGap,getContextMenuItems:y=>t.editor._pluginManager.collectContextMenuItems(y),onHighlightChange:(y,I)=>{d.setHighlightedNodes(y),d.setHighlightedEdges(I),d.refreshNodeHighlights(),d.refreshEdgeStyles()},resolveNodeShape:y=>{const I=t.editor.schema.nodeTypes[y];if(!I)return null;const T=l.registerNodeType(y,I.component),Y=I.getSize({id:"",type:y,position:{x:0,y:0}});return{shapeName:T,width:Y.width,height:Y.height}}});t.editor.api.value=N;const S={flowModel:t.editor.flowModel,history:t.editor.history,schema:t.editor.schema,mode:t.editor.mode,executeCommand:t.editor.executeCommand,api:N,overlay:f,graph:a};t.editor._pluginManager.attachRuntime(S);const D=t.editor._pluginManager.collectExtendedApi();Object.assign(t.editor.extendedApi,D),p=new mt(a,y=>{(y.type==="node.click"||y.type==="node.dblclick"||y.type==="node.contextmenu")&&c.enter(y.nodeId),t.editor._pluginManager.dispatchUiEvent(y),o("ui-event",y)},y=>{if(d.isSyncing)return;if(t.editor.executeCommand(y).status!=="applied"){for(const T of y.commands)if(T.type==="edge.add"){const Y=a.getCellById(T.edge.id);Y&&a.removeCell(Y)}}},t.editor.flowModel),U=Et(a);const _=Ct(a),F=a,ee=y=>{const I=F.isRubberbandEnabled?.()??!1;I&&F.disableRubberband?.(),y?a.enablePanning():a.disablePanning(),I&&F.enableRubberband?.()},be=()=>{x.value++};a.on("translate",be),a.on("scale",be),a.on("resize",be),a.on("node:move",()=>{b.value=!0}),a.on("node:moved",()=>{b.value=!1}),a.on("node:mouseenter",({node:y})=>{c.enter(y.id),V.value.enabled&&E(y.id)||_.showNodePorts(y)}),a.on("node:mouseleave",({node:y})=>{const I=t.editor.flowModel.value.nodes[y.id];let T=100;I&&t.editor.api.value&&t.editor.schema.nodeTypes[I.type]?.getBehavior?.(I,{api:t.editor.api.value,flowModel:t.editor.flowModel.value,history:t.editor.history,mode:t.editor.mode.value})?.actionsOffset&&(T=300),c.leave(T),V.value.enabled&&C.value===y.id?B():_.hideNodePorts(y)});function Oe(y){const I=a.getCellById(y);if(!I?.isNode())return;const T=I,Y=t.editor.flowModel.value.nodes[y];if(!Y)return;const we=X(Y),ze=!b.value&&!!we&&W(y);for(const Ee of T.getPorts()){const je=ze&&Ee.id===we?.portId?"hidden":"visible";T.setPortProp(Ee.id,"attrs/circle/visibility",je)}}i.watch([C,b],([y],[I])=>{if(I&&I!==y){const T=a.getCellById(I);T?.isNode()&&_.hideNodePorts(T)}y&&Oe(y)},{flush:"sync"}),a.on("edge:added",({edge:y})=>{_.handleEdgeAdded(y)}),a.on("edge:connected",()=>{_.handleEdgeConnected()}),a.on("edge:removed",({edge:y})=>{_.handleEdgeRemoved(y.id),U.handleEdgeRemoved(y.id)}),a.on("selection:changed",()=>{const y=a.getSelectedCells?.()??[],I={nodeIds:y.filter(T=>T.isNode()).map(T=>T.id),edgeIds:y.filter(T=>T.isEdge()).map(T=>T.id)};t.editor._pluginManager.dispatchSelectionChange(I),o("ui-event",{type:"selection.change",nodeIds:I.nodeIds,edgeIds:I.edgeIds}),d.refreshEdgeStyles()}),a.on("edge:mouseenter",({edge:y,e:I})=>{d.setHoveredEdge(y.id),d.refreshEdgeStyles(),t.editor.mode.value==="edit"&&_.canShowEdgeTool()&&U.show(y.id,I)}),g=y=>U.move(y),a.container.addEventListener("mousemove",g),a.on("edge:mouseleave",()=>{d.setHoveredEdge(null),d.refreshEdgeStyles(),U.remove()}),a.on("edge:click",({edge:y,e:I})=>{I.target?.closest?.(".flow-canvas-edge-delete-tool")&&t.editor.mode.value==="edit"&&(U.remove(),t.editor.executeCommand({id:A(),source:"user:toolbar",label:"删除连线",timestamp:Date.now(),commands:[{type:"edge.remove",edgeId:y.id}]}))}),n.value?.addEventListener("keydown",K),d.syncFlowModel(t.editor.flowModel.value),i.watch(()=>t.editor.flowModel.value,y=>d.syncFlowModel(y)),i.watch(()=>t.editor.selectionMode.value,y=>{if(u?.(),u=null,y){ee(!1),F.enableRubberband?.();const I=()=>{a.container.removeEventListener("mouseup",I),u=null,setTimeout(()=>{t.editor.selectionMode.value&&t.editor.setSelectionMode(!1)},50)};a.container.addEventListener("mouseup",I),u=()=>a.container.removeEventListener("mouseup",I)}else F.disableRubberband?.(),ee(!0)}),i.watch(()=>t.editor.mode.value,y=>{const I=y==="edit";ee(!0),I?F.enableSelection?.():F.disableSelection?.()})}),i.onBeforeUnmount(()=>{c.cleanup(),k&&clearTimeout(k),U?.remove(),u?.(),g&&a?.container?.removeEventListener("mousemove",g),n.value?.removeEventListener("keydown",K),t.editor._pluginManager.detachRuntime(),t.editor.api.value=null;for(const m of Object.keys(t.editor.extendedApi))delete t.editor.extendedApi[m];p?.dispose(),d?.dispose(),l?.dispose(),a?.dispose()}),(m,v)=>(i.openBlock(),i.createElementBlock("div",{ref_key:"rootRef",ref:n,class:"flow-canvas-runtime-core",tabindex:"0"},[i.createElementVNode("div",{ref_key:"containerRef",ref:r,class:"flow-canvas-runtime-core__graph"},null,512),i.createElementVNode("div",Dt,[(i.openBlock(!0),i.createElementBlock(i.Fragment,null,i.renderList($.value,f=>(i.openBlock(),i.createElementBlock("div",{key:`badge-${f.nodeId}`,class:"flow-canvas-runtime-core__badge",style:i.normalizeStyle({left:`${f.x}px`,top:`${f.y}px`,backgroundColor:f.badge.color})},i.toDisplayString(f.badge.text),5))),128)),O.value?(i.openBlock(),i.createBlock(Te,{key:0,ref_key:"quickAddPopoverRef",ref:G,node:O.value.node,"port-position":O.value.portPosition,"tooltip-text":V.value.tooltipText,onOpen:ae,onStartDrag:Z,onMouseenter:R,onMouseleave:q},{default:i.withCtx(()=>[i.renderSlot(m.$slots,"quick-add-panel",{node:O.value.node,api:s.editor.api.value,insertNodeToRight:f=>te(O.value.node.id,f),closePopover:()=>G.value?.closePopover()},void 0,!0)]),_:3},8,["node","port-position","tooltip-text"])):i.createCommentVNode("",!0),L.value?(i.openBlock(),i.createBlock(Ae,{key:1,node:L.value.node,position:L.value.position,config:P.value,behavior:L.value.behavior,"actions-offset":L.value.behavior.actionsOffset,onAction:ue,onMouseenter:i.unref(h),onMouseleave:M},null,8,["node","position","config","behavior","actions-offset","onMouseenter"])):i.createCommentVNode("",!0)])],512))}}),Bt=ne(Pt,[["__scopeId","data-v-7e8e2569"]]),_t={class:"flow-canvas-node-palette"},At=["data-node-type"],Tt={class:"flow-canvas-node-palette__item-label"},Rt=i.defineComponent({__name:"canvas-node-palette",props:{editor:{},items:{}},setup(s){const e=s,t=i.ref(),o=i.computed(()=>e.items?e.items:Object.keys(e.editor.schema.nodeTypes).map(n=>({type:n,label:n.charAt(0).toUpperCase()+n.slice(1)})));return i.watch([()=>e.editor.api.value,o,t],([n,r,a],d,l)=>{if(!n||!a)return;const p=[];for(const c of r){const w=a.querySelector(`[data-node-type="${c.type}"]`);if(!w)continue;const b=n.registerDndSource(w,()=>({id:A(),type:c.type,label:c.label,position:{x:0,y:0}}));p.push(b)}l(()=>{for(const c of p)c()})},{flush:"post"}),(n,r)=>(i.openBlock(),i.createElementBlock("div",_t,[i.createElementVNode("div",{ref_key:"listRef",ref:t,class:"flow-canvas-node-palette__list"},[(i.openBlock(!0),i.createElementBlock(i.Fragment,null,i.renderList(o.value,a=>(i.openBlock(),i.createElementBlock("div",{key:a.type,class:"flow-canvas-node-palette__item","data-node-type":a.type},[a.icon?(i.openBlock(),i.createElementBlock("i",{key:0,class:i.normalizeClass([a.icon,"flow-canvas-node-palette__item-icon"])},null,2)):i.createCommentVNode("",!0),i.createElementVNode("span",Tt,i.toDisplayString(a.label),1)],8,At))),128))],512)]))}}),Re=ne(Rt,[["__scopeId","data-v-300314b7"]]),$t={class:"flow-canvas-layout"},Lt={class:"flow-canvas-layout__main"},Vt={class:"flow-canvas-layout__content"},Ot={key:0,class:"flow-canvas-layout__footer"},zt=i.defineComponent({__name:"canvas-layout",props:{sidebarCollapsed:{type:Boolean,default:!1},sidebarWidth:{default:260},hideSidebar:{type:Boolean,default:!1},hideFooter:{type:Boolean,default:!1},editor:{default:void 0},paletteItems:{default:void 0}},emits:["update:sidebarCollapsed"],setup(s){return(e,t)=>(i.openBlock(),i.createElementBlock("div",$t,[!s.hideSidebar&&(e.$slots.sidebar||s.editor)?(i.openBlock(),i.createElementBlock("aside",{key:0,class:i.normalizeClass(["flow-canvas-layout__sidebar",{"is-collapsed":s.sidebarCollapsed}]),style:i.normalizeStyle({width:s.sidebarCollapsed?"0px":`${s.sidebarWidth}px`})},[i.renderSlot(e.$slots,"sidebar",{},()=>[s.editor?(i.openBlock(),i.createBlock(Re,{key:0,editor:s.editor,items:s.paletteItems},null,8,["editor","items"])):i.createCommentVNode("",!0)],!0)],6)):i.createCommentVNode("",!0),i.createElementVNode("div",Lt,[i.createElementVNode("div",Vt,[i.renderSlot(e.$slots,"default",{},void 0,!0)]),!s.hideFooter&&e.$slots.footer?(i.openBlock(),i.createElementBlock("div",Ot,[i.renderSlot(e.$slots,"footer",{},void 0,!0)])):i.createCommentVNode("",!0)])]))}}),jt=ne(zt,[["__scopeId","data-v-26f35b6b"]]),Ft=["undo","redo"];function $e(s){const e=new Set(s?.include),t=new Set([...Ft.filter(l=>!e.has(l)),...s?.exclude??[]]),o=[{id:"undo",type:"undo",group:"history",icon:"flow-canvas-icon canvas-undo",description:"撤销",order:10},{id:"redo",type:"redo",group:"history",icon:"flow-canvas-icon canvas-redo",description:"重做",order:11}],n=[{id:"select",type:"select",group:"tools",icon:"flow-canvas-icon canvas-kuangxuan",description:"框选",order:20},{id:"auto-layout",type:"auto-layout",group:"tools",icon:"flow-canvas-icon canvas-beautify",description:"自动排版",order:21},{id:"search",type:"search",group:"tools",icon:"flow-canvas-icon canvas-search",description:"搜索节点",order:22},{id:"minimap",type:"minimap",group:"tools",icon:"flow-canvas-icon canvas-map",description:"缩略图",order:23},{id:"export",type:"export",group:"tools",icon:"flow-canvas-icon canvas-xiazai",description:"导出为图片",order:24}],r=[{id:"zoom-out",type:"zoom-out",group:"zoom",icon:"flow-canvas-icon canvas-zoom-minus",description:"缩小画布",order:30},{id:"zoom-display",type:"zoom-display",group:"zoom",order:31},{id:"zoom-in",type:"zoom-in",group:"zoom",icon:"flow-canvas-icon canvas-zoom-add",description:"放大画布",order:32}],a=[{id:"reset",type:"reset",group:"reset",icon:"flow-canvas-icon canvas-reset-1_1",description:"重置视图",order:40}];return[...[...o,...n].filter(l=>!t.has(l.type)),...r,...a]}const Gt={class:"flow-canvas-toolbar"},Ht={key:0,class:"flow-canvas-toolbar__separator"},qt={class:"flow-canvas-toolbar__group"},Ut={key:0,class:"flow-canvas-toolbar__zoom-display"},Wt=["data-description","disabled","onClick"],Qt=["textContent"],Xt=i.defineComponent({__name:"canvas-toolbar",props:{items:{},exclude:{},editor:{}},setup(s){const e=s,t=i.computed(()=>e.items?e.items:$e({exclude:e.exclude})),o=i.ref(1);let n=null;i.watch(()=>e.editor.api.value,h=>{n?.(),n=null,h&&(o.value=h.getZoom(),n=h.onGraphEvent("scale",()=>{o.value=h.getZoom()}))},{immediate:!0}),i.onScopeDispose(()=>{n?.()});const r=i.computed(()=>`${Math.round(o.value*100)}%`),a=i.computed(()=>e.editor.api.value?{api:e.editor.api.value,flowModel:e.editor.flowModel.value,history:e.editor.history,mode:e.editor.mode.value}:null);function d(h){return h.visible===!1?!1:typeof h.visible=="function"?a.value?h.visible(a.value):!1:!0}function l(h){return h.type==="select"?e.editor.selectionMode.value:!1}function p(h){return!a.value||h.disabled===!0?!0:typeof h.disabled=="function"?h.disabled(a.value):h.type==="undo"?!e.editor.history.canUndo.value:h.type==="redo"?!e.editor.history.canRedo.value:!1}function c(h){if(!a.value||p(h))return;if(h.onClick){h.onClick(a.value);return}const{api:M}=a.value;switch(h.type){case"undo":e.editor.history.undo();break;case"redo":e.editor.history.redo();break;case"zoom-in":M.zoomIn(),o.value=M.getZoom();break;case"zoom-out":M.zoomOut(),o.value=M.getZoom();break;case"fit":M.zoomToFit();break;case"reset":M.zoomTo(1),M.scrollToOrigin(),o.value=1;break;case"export":M.exportAsImage().then(C=>{const k=URL.createObjectURL(C),E=document.createElement("a");E.href=k,E.download="canvas-export.png",E.click(),URL.revokeObjectURL(k)}).catch(C=>{console.warn("[flow-canvas] Export failed:",C)});break;case"select":e.editor.setSelectionMode(!e.editor.selectionMode.value);break;case"search":case"auto-layout":case"minimap":console.warn(`[flow-canvas] "${h.type}" toolbar item has no built-in handler. Provide an onClick callback.`);break;default:h.type!=="custom"&&console.warn(`[flow-canvas] No default handler for toolbar type "${h.type}". Provide an onClick handler.`);break}}const w=i.computed(()=>t.value.filter(d)),b=i.computed(()=>{const h=new Map,M=[];for(const C of w.value){const k=C.group??"default";h.has(k)||(h.set(k,[]),M.push(k)),h.get(k).push(C)}return M.map(C=>({name:C,items:h.get(C)})).filter(C=>C.items.length>0)});return(h,M)=>(i.openBlock(),i.createElementBlock("div",Gt,[(i.openBlock(!0),i.createElementBlock(i.Fragment,null,i.renderList(b.value,(C,k)=>(i.openBlock(),i.createElementBlock(i.Fragment,{key:C.name},[k>0?(i.openBlock(),i.createElementBlock("div",Ht)):i.createCommentVNode("",!0),i.createElementVNode("div",qt,[(i.openBlock(!0),i.createElementBlock(i.Fragment,null,i.renderList(C.items,E=>(i.openBlock(),i.createElementBlock(i.Fragment,{key:E.id},[E.type==="zoom-display"?(i.openBlock(),i.createElementBlock("span",Ut,i.toDisplayString(r.value),1)):(i.openBlock(),i.createElementBlock("button",{key:1,class:i.normalizeClass(["flow-canvas-toolbar__btn",{"is-disabled":p(E),"is-active":l(E)}]),"data-description":E.description,disabled:p(E),onClick:B=>c(E)},[E.component?(i.openBlock(),i.createBlock(i.resolveDynamicComponent(E.component),{key:0})):E.icon?(i.openBlock(),i.createElementBlock("i",{key:1,class:i.normalizeClass(E.icon)},null,2)):(i.openBlock(),i.createElementBlock("span",{key:2,class:"flow-canvas-toolbar__text",textContent:i.toDisplayString(E.text??E.description??E.id)},null,8,Qt))],10,Wt))],64))),128))])],64))),128))]))}}),Kt=ne(Xt,[["__scopeId","data-v-51b5c98a"]]),Yt={class:"flow-canvas-default-node__ep-label"},Zt={key:1,class:"flow-canvas-default-node__diamond"},Jt={key:2,class:"flow-canvas-default-node__task-label"},eo=i.defineComponent({__name:"default-node",setup(s){const t=i.inject("getNode")?.(),o=i.computed(()=>t?.getData?.()??null),n=i.computed(()=>o.value?.label||o.value?.type||""),r={start:"canvas-kaishi",end:"canvas-stop","parallel-gateway":"canvas-bingxingwangguan","branch-gateway":"canvas-fenzhiwangguan","converge-gateway":"canvas-huijuwangguan","conditional-parallel-gateway":"canvas-tiaojianbingxingwangguan"},a=new Set(["start","end"]),d=new Set(["parallel-gateway","branch-gateway","converge-gateway","conditional-parallel-gateway"]),l=i.computed(()=>{const c=o.value?.type??"";return a.has(c)?"endpoint":d.has(c)?"gateway":"task"}),p=i.computed(()=>r[o.value?.type??""]??"");return(c,w)=>(i.openBlock(),i.createElementBlock("div",{class:i.normalizeClass(["flow-canvas-default-node",`is-${l.value}`])},[l.value==="endpoint"?(i.openBlock(),i.createElementBlock(i.Fragment,{key:0},[p.value?(i.openBlock(),i.createElementBlock("i",{key:0,class:i.normalizeClass([["flow-canvas-icon",p.value],"flow-canvas-default-node__ep-icon"])},null,2)):i.createCommentVNode("",!0),i.createElementVNode("span",Yt,i.toDisplayString(n.value),1)],64)):l.value==="gateway"?(i.openBlock(),i.createElementBlock("div",Zt,[p.value?(i.openBlock(),i.createElementBlock("i",{key:0,class:i.normalizeClass([["flow-canvas-icon",p.value],"flow-canvas-default-node__gw-icon"])},null,2)):i.createCommentVNode("",!0)])):(i.openBlock(),i.createElementBlock("span",Jt,i.toDisplayString(n.value),1))],2))}}),Le=ne(eo,[["__scopeId","data-v-c88cdae7"]]),to={start:{label:"开始",icon:"flow-canvas-icon canvas-kaishi",width:88,height:40},end:{label:"结束",icon:"flow-canvas-icon canvas-stop",width:88,height:40},empty:{label:"空节点",icon:"flow-canvas-icon canvas-jiedi",width:240,height:48},"parallel-gateway":{label:"并行网关",icon:"flow-canvas-icon canvas-bingxingwangguan",width:64,height:64},"branch-gateway":{label:"分支网关",icon:"flow-canvas-icon canvas-fenzhiwangguan",width:64,height:64},"converge-gateway":{label:"汇聚网关",icon:"flow-canvas-icon canvas-huijuwangguan",width:64,height:64},"conditional-parallel-gateway":{label:"条件并行网关",icon:"flow-canvas-icon canvas-tiaojianbingxingwangguan",width:64,height:64}},Se=(s,e)=>({stroke:e.hovered?"#3a84ff":"#abb5cc",strokeWidth:2});function De(){return{attrs:{line:{stroke:"#abb5cc",strokeWidth:2,targetMarker:{name:"block",width:8,height:8}}}}}function Ve(){return{manhattan:{router:{name:"manhattan",args:{padding:10,maxDirectionChange:90}},connector:{name:"rounded",args:{radius:8}},style:Se,x6EdgeConfig:De()},bezier:{connector:{name:"smooth"},style:Se,x6EdgeConfig:De()}}}function oo(s){const e=s?.nodeTypes??to,t={},o=[];for(const[a,d]of Object.entries(e)){const l=d.width??150,p=d.height??50;t[a]={component:Le,getSize:()=>({width:l,height:p}),getPorts:()=>_e()},o.push({type:a,label:d.label??a,icon:d.icon})}const n={...Ve(),...s?.edgeTypes},r=s?.defaultEdgeType??"manhattan";return{schema:{nodeTypes:t,defaultEdgeType:r,edgeTypes:n},paletteItems:o}}function no(s){return{name:"connection-validator",priority:10,transformCommand(e,t,o){for(const n of e.commands){if(n.type!=="edge.add"&&n.type!=="edge.reconnect")continue;const r=o.flowModel.value,a=n.type==="edge.add"?n.edge.source.nodeId:n.source?.nodeId,d=n.type==="edge.add"?n.edge.target.nodeId:n.target?.nodeId;if(!a||!d)continue;const l=r.nodes[a],p=r.nodes[d];if(!l||!p)continue;const c=n.type==="edge.add"?n.edge.source.portId:n.source?.portId,w=n.type==="edge.add"?n.edge.target.portId:n.target?.portId,b=c?l.ports?.find(E=>E.id===c):void 0,h=w?p.ports?.find(E=>E.id===w):void 0,M=n.type==="edge.reconnect"?n.edgeId:void 0,C=Object.values(r.edges).filter(E=>E.id!==M),k=s({flowModel:r,sourceNode:l,targetNode:p,sourcePort:b,targetPort:h,existingEdges:C});if(!k.valid)return{rejected:!0,reason:k.reason??"Connection validation failed",code:"validation_failed"}}return e}}}function so(s){const{rubberband:e=!0,multiple:t=!0,movable:o=!0}=s??{};return{name:"selection",priority:90,async attachRuntime(n){const{Selection:r}=await import("@antv/x6-plugin-selection");n.graph.use(new r({enabled:!0,rubberband:e,multiple:t,movable:o,showNodeSelectionBox:!0,filter:a=>!(a.isNode()&&(!n.graph.isRubberbandEnabled?.()||(a.getData?.()??{})._selectable===!1))}))}}}function io(s){const{tolerance:e=10,color:t="#3a84ff"}=s??{};let o=null;return{name:"snapline",priority:90,async attachRuntime(n){const{Snapline:r}=await import("@antv/x6-plugin-snapline");n.graph.use(new r({enabled:!0,tolerance:e,className:"flow-canvas-snapline"})),o=document.createElement("style"),o.textContent=`.flow-canvas-snapline line { stroke: ${t} !important; }`,document.head.appendChild(o)},detachRuntime(){o?.remove(),o=null}}}function ro(s){let e=null;return{name:"minimap",priority:90,async attachRuntime(t){if(!s?.container)return;e=s.container;const{MiniMap:o}=await import("@antv/x6-plugin-minimap");t.graph.use(new o({container:s.container,width:s.width??200,height:s.height??160}))},detachRuntime(){e=null},provideToolbarItems(){return[{id:"minimap",type:"minimap",tooltip:"小地图",order:100,visible:!!s?.container,onClick(){if(!e)return;const t=e.style.display==="none";e.style.display=t?"":"none"}}]}}}function ao(){let s=null,e=0;return{name:"clipboard",priority:90,onKeyboardShortcut(t,o){const n=t.metaKey||t.ctrlKey;if(n&&t.key==="c"){const r=o.graph.getSelectedCells?.()??[];if(!r.length)return!1;const a=o.flowModel.value,d=new Set(r.filter(c=>c.isNode()).map(c=>c.id)),l=[...d].map(c=>a.nodes[c]).filter(Boolean);if(!l.length)return!1;const p=Object.values(a.edges).filter(c=>d.has(c.source.nodeId)&&d.has(c.target.nodeId));return s={nodes:l,edges:p},e=0,!0}if(n&&t.key==="v"){if(!s?.nodes.length)return!1;e++;const r=e*30,a=new Map,d=[];for(const l of s.nodes){const p=`${l.id}_cp${A().slice(0,6)}`;a.set(l.id,p),d.push({type:"node.add",node:{...l,id:p,position:{x:l.position.x+r,y:l.position.y+r},payload:l.payload?{...l.payload}:{},extensions:l.extensions?{...l.extensions}:void 0}})}for(const l of s.edges){const p=a.get(l.source.nodeId),c=a.get(l.target.nodeId);!p||!c||d.push({type:"edge.add",edge:{...l,id:`${l.id}_cp${A().slice(0,6)}`,source:{...l.source,nodeId:p},target:{...l.target,nodeId:c},labels:l.labels?.map(w=>({...w,id:`${w.id}_cp${A().slice(0,6)}`})),payload:l.payload?{...l.payload}:{}}})}return d.length&&o.executeCommand({id:A(),source:"user:keyboard",label:"粘贴",timestamp:Date.now(),commands:d}),!0}return!1}}}exports.CanvasConstraintError=H;exports.CanvasLayout=jt;exports.CanvasNodePalette=Re;exports.CanvasRuntime=Bt;exports.CanvasSchemaError=Pe;exports.CanvasToolbar=Kt;exports.DefaultNode=Le;exports.NodeActionsToolbar=Ae;exports.NodeQuickAddPopover=Te;exports.applyCanvasCommand=pe;exports.clipboardPlugin=ao;exports.connectionValidatorPlugin=no;exports.createBuiltinEdgeTypes=Ve;exports.createCanvasHistory=Be;exports.createDefaultSchema=oo;exports.createDefaultToolbarItems=$e;exports.createEmptyFlowModel=Ke;exports.generateId=A;exports.minimapPlugin=ro;exports.selectionPlugin=so;exports.snaplinePlugin=io;exports.useCanvasEditor=ft;
|