@blueking/flow-canvas 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1060 -1055
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var tt=Object.create;var Me=Object.defineProperty;var ot=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var rt=Object.getPrototypeOf,st=Object.prototype.hasOwnProperty;var it=(n,e,o,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of nt(e))!st.call(n,r)&&r!==o&&Me(n,r,{get:()=>e[r],enumerable:!(t=ot(e,r))||t.enumerable});return n};var Ce=(n,e,o)=>(o=n!=null?tt(rt(n)):{},it(e||!n||!n.__esModule?Me(o,"default",{value:n,enumerable:!0}):o,n));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("vue"),at=require("@antv/x6"),lt=require("@antv/x6-vue-shape"),ct=require("@antv/x6-plugin-selection"),dt=require("@antv/x6-plugin-minimap");function ut(){return{version:"1.0",nodes:{},edges:{}}}class te extends Error{constructor(e){super(e),this.name="CanvasConstraintError"}}class He extends Error{constructor(e){super(e),this.name="CanvasSchemaError"}}function ye(n,e,o){if(e.length===0){if(o===void 0)return;if(typeof o!="object"||o===null||Array.isArray(o))throw new Error("Root value of payload/extensions/meta must be an object or undefined");return o}const t=n?{...n}:{};let r=t;for(let a=0;a<e.length-1;a++){const c=e[a],l=r[c];l&&typeof l=="object"&&!Array.isArray(l)?r[c]={...l}:r[c]={},r=r[c]}const i=e[e.length-1];return o===void 0?delete r[i]:r[i]=o,t}function Ie(n,e){switch(e.type){case"node.add":return ft(n,e.node);case"node.move":return gt(n,e.nodeId,e.position);case"node.remove":return pt(n,e.nodeId);case"node.update":return ht(n,e.nodeId,e.patch);case"node.set-payload":return vt(n,e.nodeId,e.path,e.value);case"node.set-extensions":return mt(n,e.nodeId,e.path,e.value);case"edge.add":return yt(n,e.edge);case"edge.remove":return wt(n,e.edgeId);case"edge.reconnect":return bt(n,e.edgeId,e.source,e.target);case"edge.update":return Et(n,e.edgeId,e.patch);case"edge.set-payload":return kt(n,e.edgeId,e.path,e.value);case"edge.label.update":return Ct(n,e.edgeId,e.labelId,e.patch);case"model.set-meta":return xt(n,e.path,e.value);default:throw new te(`Unknown command type: ${e.type}`)}}function ge(n,e){const o=n.nodes[e];if(!o)throw new te(`Node "${e}" does not exist`);return o}function pe(n,e){const o=n.edges[e];if(!o)throw new te(`Edge "${e}" does not exist`);return o}function ue(n,e,o){const t=n.nodes[e.nodeId];if(!t)throw new te(`${o} node "${e.nodeId}" does not exist`);if(e.portId&&t.ports&&!t.ports.some(i=>i.id===e.portId))throw new te(`${o} port "${e.portId}" not found on node "${e.nodeId}"`)}function we(n,e,o){return{...n,nodes:{...n.nodes,[e]:o}}}function be(n,e,o){return{...n,edges:{...n.edges,[e]:o}}}function ft(n,e){if(n.nodes[e.id])throw new te(`Node id "${e.id}" already exists`);return{...n,nodes:{...n.nodes,[e.id]:e}}}function gt(n,e,o){const t=ge(n,e);return we(n,e,{...t,position:o})}function pt(n,e){ge(n,e);const{[e]:o,...t}=n.nodes,r={};for(const[i,a]of Object.entries(n.edges))a.source.nodeId!==e&&a.target.nodeId!==e&&(r[i]=a);return{...n,nodes:t,edges:r}}function ht(n,e,o){const t=ge(n,e);return we(n,e,{...t,...o,id:t.id})}function vt(n,e,o,t){const r=ge(n,e),i=ye(r.payload,o,t);return we(n,e,{...r,payload:i})}function mt(n,e,o,t){const r=ge(n,e),i=ye(r.extensions,o,t);return we(n,e,{...r,extensions:i})}function yt(n,e){if(n.edges[e.id])throw new te(`Edge id "${e.id}" already exists`);if(ue(n,e.source,"Source"),ue(n,e.target,"Target"),e.labels){const o=new Set;for(const t of e.labels){if(o.has(t.id))throw new te(`Duplicate label id "${t.id}" in edge "${e.id}"`);o.add(t.id)}}return{...n,edges:{...n.edges,[e.id]:e}}}function wt(n,e){pe(n,e);const{[e]:o,...t}=n.edges;return{...n,edges:t}}function bt(n,e,o,t){const r=pe(n,e),i=o??r.source,a=t??r.target;return ue(n,i,"Source"),ue(n,a,"Target"),be(n,e,{...r,source:i,target:a})}function Et(n,e,o){const t=pe(n,e),r={...t,...o,id:t.id};return o.source&&ue(n,r.source,"Source"),o.target&&ue(n,r.target,"Target"),be(n,e,r)}function kt(n,e,o,t){const r=pe(n,e),i=ye(r.payload,o,t);return be(n,e,{...r,payload:i})}function Ct(n,e,o,t){const r=pe(n,e);if(!r.labels)throw new te(`Edge "${e}" has no labels`);const i=r.labels.findIndex(c=>c.id===o);if(i===-1)throw new te(`Label "${o}" not found in edge "${e}"`);const a=[...r.labels];return a[i]={...a[i],...t,id:o},be(n,e,{...r,labels:a})}function xt(n,e,o){const t=ye(n.meta,e,o);return{...n,meta:t}}function Ge(n,e){const o=e?.maxHistorySize??100,t=s.ref(n),r=[],i=[],a=s.ref(!1),c=s.ref(!1);function l(){a.value=r.length>0,c.value=i.length>0}function v(E){const N=t.value;let M=N;for(const O of E.commands)M=Ie(M,O);if(!E.skipHistory){const O=e?.excludeCommandFromHistory,q=O?E.commands.filter(S=>!O(S)):E.commands;if(q.length>0){const S=q.length<E.commands.length?{...E,commands:q}:E;r.push({snapshot:N,envelope:S}),r.length>o&&r.shift(),i.length=0}}return t.value=M,l(),M}function g(){const E=r.pop();if(!E)return null;i.push({snapshot:t.value,envelope:E.envelope});const N=e?.preserveMetaOnUndoRedo?{...E.snapshot,meta:t.value.meta}:E.snapshot;return t.value=N,l(),N}function h(){const E=i.pop();if(!E)return null;r.push({snapshot:t.value,envelope:E.envelope});const N=e?.preserveMetaOnUndoRedo?{...E.snapshot,meta:t.value.meta}:E.snapshot;return t.value=N,l(),N}function f(){r.length=0,i.length=0,l()}function b(){return t.value}function A(E){t.value=E,f()}function R(E,N){const M={id:`update-${Date.now()}`,source:"system:update",label:N??"更新模型",timestamp:Date.now(),commands:[]};r.push({snapshot:t.value,envelope:M}),r.length>o&&r.shift(),i.length=0,t.value=E,l()}return{currentFlowModel:t,execute:v,undo:g,redo:h,canUndo:a,canRedo:c,get undoStack(){return r.map(E=>E.envelope)},get redoStack(){return i.map(E=>E.envelope)},clear:f,createSnapshot:b,replaceFlowModel:A,updateFlowModel:R}}function It(n){return n!==null&&typeof n=="object"&&n.rejected===!0}class St{plugins=[];editorContext=null;runtimeCtx=null;runtimeVersion=0;install(e,o){this.plugins=[...e].sort((t,r)=>(t.priority??100)-(r.priority??100)),this.editorContext=o;for(const t of this.plugins)t.install?.(o)}attachRuntime(e){const o=++this.runtimeVersion;this.runtimeCtx=e;const t=this.createSafeRuntimeContext(e,o);for(const r of this.plugins)r.attachRuntime?.(t)}detachRuntime(){for(const e of[...this.plugins].reverse())e.detachRuntime?.();this.runtimeCtx=null}createSafeRuntimeContext(e,o){const t=this,r=new Proxy(e.graph,{get(i,a,c){const l=Reflect.get(i,a,c);return a==="use"&&typeof l=="function"?function(...g){if(t.runtimeVersion===o)return l.apply(i,g)}:l}});return{...e,graph:r}}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 o=e;for(const t of this.plugins){if(!t.transformCommand)continue;const r=this.createPreview(o),i=t.transformCommand(o,r,this.editorContext);if(i===null)return{rejected:!0,error:{code:"plugin_rejected",reason:"",source:t.name}};if(It(i))return{rejected:!0,error:{code:i.code??"plugin_rejected",reason:i.reason,source:t.name}};o=i}return{envelope:o}}afterCommand(e,o,t){if(this.editorContext)for(const r of this.plugins)r.afterCommand?.(e,o,t,this.editorContext)}dispatchUiEvent(e){if(this.runtimeCtx)for(const o of this.plugins)o.onUiEvent?.(e,this.runtimeCtx)}dispatchSelectionChange(e){if(this.runtimeCtx)for(const o of this.plugins)o.onSelectionChange?.(e,this.runtimeCtx)}dispatchKeyboardShortcut(e){if(!this.runtimeCtx)return!1;for(const o of this.plugins)if(o.onKeyboardShortcut?.(e,this.runtimeCtx))return!0;return!1}collectContextMenuItems(e){if(!this.runtimeCtx)return[];const o=[];for(const t of this.plugins){const r=t.onBlankContextMenu?.(e,this.runtimeCtx);r&&o.push(...r)}return o}collectToolbarItems(){if(!this.editorContext)return[];const e=new Map;for(const o of this.plugins){const t=o.provideToolbarItems?.(this.editorContext);if(t)for(const r of t)e.set(r.id,r)}return[...e.values()].sort((o,t)=>(o.order??0)-(t.order??0))}collectNodeDecorations(e){if(!this.editorContext)return;let o;for(const t of this.plugins){const r=t.decorateNode?.(e,this.editorContext);r&&(o=o?{...o,...r}:r)}return o}collectEdgeDecorations(e){if(!this.editorContext)return;let o;for(const t of this.plugins){const r=t.decorateEdge?.(e,this.editorContext);r&&(o=o?{...o,...r}:r)}return o}collectExtendedApi(){if(!this.runtimeCtx)return{};const e={};for(const o of this.plugins){const t=o.extendApi?.(this.runtimeCtx.api,this.runtimeCtx);t&&Object.assign(e,t)}return e}createPreview(e){const o=this.editorContext;return{previewFlowModel(t){const r=t??e.commands;let i=o.flowModel.value;for(const a of r)i=Ie(i,a);return i}}}}let Nt=0;function X(){const n=Date.now().toString(36),e=Math.random().toString(36).substring(2,8);return`${n}-${e}-${++Nt}`}const Se=()=>X();function Mt(n){const{schema:e,plugins:o=[],historyOptions:t}=n,r=n.idGenerator??Se,i={version:"1.0",...n.initialFlowModel},a=Ge(i,t),c=s.ref(n.mode??"edit"),l=s.ref(!1),v=s.ref(null),g=s.ref([]),h={},f=new St;function b(N,M,O,q="user:toolbar"){const S={id:`history-${Date.now()}`,source:q,label:N,timestamp:Date.now(),commands:[]};f.afterCommand(S,M,O),g.value=f.collectToolbarItems(),n.onCommandResult?.({status:"applied",envelope:S,flowModel:O}),n.onFlowModelChange?.({flowModel:O,prevFlowModel:M,envelope:S,source:q})}const A={execute:a.execute,undo(){const N=a.currentFlowModel.value,M=a.undo();return M&&b("撤销",N,M),M},redo(){const N=a.currentFlowModel.value,M=a.redo();return M&&b("重做",N,M),M},get canUndo(){return a.canUndo},get canRedo(){return a.canRedo},get undoStack(){return a.undoStack},get redoStack(){return a.redoStack},clear:a.clear,createSnapshot:a.createSnapshot,replaceFlowModel(N){const M=a.currentFlowModel.value;a.replaceFlowModel(N),b("替换 FlowModel",M,N,"system:replace")},updateFlowModel(N,M){const O=a.currentFlowModel.value;a.updateFlowModel(N,M),b(M??"更新 FlowModel",O,N,"system:update")}},R={flowModel:s.computed(()=>a.currentFlowModel.value),history:A,schema:e,mode:c,idGenerator:r,executeCommand:E,replaceFlowModel(N){A.replaceFlowModel(N)},updateFlowModel(N,M){A.updateFlowModel(N,M)},setMode(N){c.value=N},selectionMode:l,setSelectionMode(N){l.value=N},api:v,toolbarItems:g,extendedApi:h,_pluginManager:f,_emitUiEvent:N=>{f.dispatchUiEvent(N)}};f.install(o,{flowModel:R.flowModel,history:A,schema:e,mode:c,idGenerator:r,executeCommand:E}),g.value=f.collectToolbarItems(),s.onScopeDispose(()=>{f.dispose()});function E(N){const M=f.transformCommand(N);if("rejected"in M){const S={status:"rejected",envelope:N,error:M.error};return n.onCommandResult?.(S),S}const O=M.envelope,q=a.currentFlowModel.value;try{const S=a.execute(O),G={status:"applied",envelope:O,flowModel:S};return f.afterCommand(O,q,S),g.value=f.collectToolbarItems(),n.onCommandResult?.(G),n.onFlowModelChange?.({flowModel:S,prevFlowModel:q,envelope:O,source:O.source}),G}catch(S){if(S instanceof te){const G={status:"invalid",envelope:O,error:{code:"constraint_violated",reason:S.message,source:"engine"}};return n.onCommandResult?.(G),G}throw S}}return R}const Dt=["top","right","bottom","left"];function Ue(){return Dt.map(n=>({id:n,group:n}))}function Ne(n,e){return e?.(n)??n.ports??Ue()}const xe=-1,At="flow-canvas-node-ring-target",De="flow-canvas-node-ring-target--decorated",Ae="flow-canvas-node-ring-target--pulse",_t="linear-gradient(135deg, #cadcfa 0%, #cee0ff 100%)";class Pt{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;prevEdgeDecorationMarkerIds=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;pendingDecorationRAFs=new Map;constructor(e,o,t,r,i,a){this.graph=e,this.schema=o,this.shapeRegistry=t,this.resolveNodeDecoration=r,this.resolveEdgeDecoration=i,this.resolveCanvasContext=a}syncFlowModel(e){if(!this.syncing){this.syncing=!0,this.lastModel=e;try{const o=this.resolveNodes(e),t=this.resolveEdges(e);this.syncNodes(o),this.syncEdges(t,e)}finally{this.syncing=!1}}}get isSyncing(){return this.syncing}saveNodeDefaultAttrs(e,o){const r=o.x6CellConfig?.attrs?.body;if(!r)return;const i={};let a=!1;r.stroke!==void 0&&(i.stroke=r.stroke,a=!0),r.strokeWidth!==void 0&&(i.strokeWidth=r.strokeWidth,a=!0),a&&this.nodeDefaultAttrs.set(e,i)}saveEdgeDefaultAttrs(e,o){const r=o?.x6EdgeConfig?.attrs?.line;if(!r)return;const i={};let a=!1;r.stroke!==void 0&&(i.stroke=r.stroke,a=!0),r.strokeWidth!==void 0&&(i.strokeWidth=r.strokeWidth,a=!0),r.strokeDasharray!==void 0&&(i.strokeDasharray=r.strokeDasharray,a=!0),a&&this.edgeDefaultAttrs.set(e,i)}restoreNodeAttr(e,o,t){const r=this.nodeDefaultAttrs.get(e.id)?.[t];if(r!==void 0)e.setAttrByPath(o,r);else{const i=t==="stroke"?"none":0;e.setAttrByPath(o,i)}}restoreEdgeAttr(e,o,t){const r=this.edgeDefaultAttrs.get(e.id)?.[t];r!==void 0?this.setEdgeAttrIfChanged(e,o,r):e.attr(o)!==void 0&&e.removeAttrByPath(o)}setEdgeAttrIfChanged(e,o,t){const r=e.attr(o),i=typeof r=="object"&&r!==null,a=typeof t=="object"&&t!==null;r!==t&&(i&&a&&JSON.stringify(r)===JSON.stringify(t)||e.setAttrByPath(o,t))}getNodeRingTarget(e){return e?e.querySelector(".flow-canvas-highlight-target")??e.querySelector(".flow-canvas-node-surface > :first-child"):null}syncEdgeMarker(e,o,t){const i=o?.x6EdgeConfig?.attrs?.line?.[t],a=`line/${t}`;e.removeAttrByPath(a),i!==void 0&&e.setAttrByPath(a,i)}getEdgeMarkerConfig(e,o){const r=e?.x6EdgeConfig?.attrs?.line?.[o];if(r)return typeof r=="string"?{name:r}:{...r}}applyEdgeMarkerDecoration(e,o,t,r){if(!r){this.prevEdgeDecorationMarkerIds.has(e.id)&&(this.syncEdgeMarker(e,o,t),this.prevEdgeDecorationMarkerIds.delete(e.id));return}const i=this.getEdgeMarkerConfig(o,t)??{name:"block",width:8,height:8};this.setEdgeAttrIfChanged(e,`line/${t}`,{...i,stroke:r,fill:r}),this.prevEdgeDecorationMarkerIds.add(e.id)}dispose(){for(const e of this.pendingDecorationRAFs.values())cancelAnimationFrame(e);this.pendingDecorationRAFs.clear(),this.knownNodeIds.clear(),this.knownEdgeIds.clear()}resolveNodes(e){const o=new Map;for(const[t,r]of Object.entries(e.nodes)){const i=this.schema.nodeTypes[r.type];if(!i)throw new He(`Unknown node type "${r.type}" for node "${t}". 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(r.type,i.component),c=i.getSize(r),l=Ne(r,i.getPorts);o.set(t,{model:r,definition:i,shapeName:a,size:c,ports:l})}return o}resolveEdges(e){const o=new Map;for(const[t,r]of Object.entries(e.edges)){const i=r.type??this.schema.defaultEdgeType??"default",a=this.schema.edgeTypes?.[i];o.set(t,{model:r,definition:a})}return o}syncNodes(e){const o=new Set(e.keys());for(const t of this.knownNodeIds)if(!o.has(t)){const r=this.graph.getCellById(t);r&&this.graph.removeCell(r),this.knownNodeIds.delete(t),this.defaultHighlightedNodeIds.delete(t),this.prevNodeDecorationClasses.delete(t),this.prevNodeDecorationColors.delete(t),this.nodeDefaultAttrs.delete(t);const i=this.pendingDecorationRAFs.get(t);i&&(cancelAnimationFrame(i),this.pendingDecorationRAFs.delete(t))}for(const[t,r]of e){const i=this.graph.getCellById(t);i?this.updateExistingNode(i,r):this.addNewNode(t,r)}}updateExistingNode(e,o){const{model:t,size:r,ports:i,definition:a}=o;if(e.getData()?.type!==t.type){this.graph.removeCell(e),this.addNewNode(e.id,o);return}const l=e.getPosition();(l.x!==t.position.x||l.y!==t.position.y)&&e.setPosition(t.position.x,t.position.y);const v=e.getSize();(v.width!==r.width||v.height!==r.height)&&e.setSize(r.width,r.height,{silent:!0}),this.syncNodePorts(e,i),e.setData({...t}),this.applyNodeBehavior(e,t,a),this.applyNodeHighlightAndDecoration(e,t)}syncNodePorts(e,o){const t=e.getPorts(),r=new Set(o.map(a=>a.id)),i=new Set(t.map(a=>a.id));for(const a of t)a.id&&!r.has(a.id)&&e.removePort(a.id);for(const a of o)i.has(a.id)||e.addPort({id:a.id,group:a.group,...a.x6PortConfig})}addNewNode(e,o){const{model:t,shapeName:r,size:i,ports:a,definition:c}=o,l={id:t.id,shape:r,x:t.position.x,y:t.position.y,width:i.width,height:i.height,data:{...t},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(g=>({id:g.id,group:g.group,...g.x6PortConfig}))},...c.x6CellConfig};this.graph.addNode(l),this.knownNodeIds.add(e),this.saveNodeDefaultAttrs(e,c);const v=this.graph.getCellById(e);v&&(this.applyNodeBehavior(v,t,c),this.applyNodeHighlightAndDecoration(v,t),this.scheduleDecorationRetryIfNeeded(v))}scheduleDecorationRetryIfNeeded(e){const o=this.graph.findViewByCell(e)?.container;if(this.getNodeRingTarget(o))return;const t=e.id,r=this.pendingDecorationRAFs.get(t);r&&cancelAnimationFrame(r);const i=requestAnimationFrame(()=>{if(this.pendingDecorationRAFs.delete(t),!this.knownNodeIds.has(t))return;const a=this.lastModel?.nodes[t];if(!a)return;const c=this.graph.getCellById(t);c?.isNode()&&this.applyNodeHighlightAndDecoration(c,a)});this.pendingDecorationRAFs.set(t,i)}applyNodeBehavior(e,o,t){if(!t.getBehavior)return;const r=this.resolveCanvasContext?.();if(!r)return;const i=t.getBehavior(o,r);if(i.draggable!==void 0&&e.setProp("draggable",i.draggable,{silent:!0}),i.connectable!==void 0){const c=i.connectable?!0:i.targetable===!1?!1:"passive";for(const l of e.getPorts())e.setPortProp(l.id,"attrs/circle/magnet",c,{silent:!0})}if(i.showPorts!==void 0){const c=i.showPorts;for(const l of e.getPorts())e.setPortProp(l.id,"attrs/circle/visibility",c?"visible":"hidden",{silent:!0})}const a=e.getData()??{};i.deletable!==void 0&&a._deletable!==i.deletable&&e.setData({...a,_deletable:i.deletable},{silent:!0}),i.selectable!==void 0&&a._selectable!==i.selectable&&e.setData({...e.getData(),_selectable:i.selectable},{silent:!0})}syncEdges(e,o){const t=new Set(e.keys());for(const r of this.knownEdgeIds)if(!t.has(r)){const i=this.graph.getCellById(r);i&&this.graph.removeCell(i),this.knownEdgeIds.delete(r),this.defaultHighlightedEdgeIds.delete(r),this.prevEdgeDecorationClasses.delete(r),this.prevEdgeDecorationColors.delete(r),this.prevEdgeDecorationMarkerIds.delete(r),this.prevEdgeStyleIds.delete(r),this.edgeDefaultAttrs.delete(r)}for(const[r,i]of e){const a=this.graph.getCellById(r),{model:c,definition:l}=i;a?(this.updateExistingEdge(a,c,l,o),this.knownEdgeIds.has(r)||(this.knownEdgeIds.add(r),this.saveEdgeDefaultAttrs(r,l))):this.addNewEdge(r,c,l)}}updateExistingEdge(e,o,t,r){const i=e.getSource(),a=e.getTarget(),c=i.cell!==o.source.nodeId||i.port!==o.source.portId,l=a.cell!==o.target.nodeId||a.port!==o.target.portId;c&&e.setSource({cell:o.source.nodeId,port:o.source.portId}),l&&e.setTarget({cell:o.target.nodeId,port:o.target.portId});const g=(e.getData()?.type??void 0)!==(o.type??void 0);if(g){if(t?.router){const h=typeof t.router=="string"?{name:t.router}:t.router;e.setRouter(h)}if(t?.connector){const h=typeof t.connector=="string"?{name:t.connector}:t.connector;e.setConnector(h)}}(g||c||l)&&(this.syncEdgeMarker(e,t,"sourceMarker"),this.syncEdgeMarker(e,t,"targetMarker")),this.syncEdgeLabels(e,o),e.getZIndex()!==xe&&e.setZIndex(xe),e.setData({...o},{silent:!0}),this.applyEdgeStyleAndDecoration(e,o,t)}syncEdgeLabels(e,o){if(!o.labels?.length){e.getLabels().length>0&&e.setLabels([]);return}const t=o.labels.map(r=>({attrs:{label:{text:r.text??""}},position:r.position!=null?{distance:r.position}:void 0}));e.setLabels(t)}addNewEdge(e,o,t){const r={id:o.id,source:{cell:o.source.nodeId,port:o.source.portId},target:{cell:o.target.nodeId,port:o.target.portId},data:{...o},zIndex:xe};t?.router&&(r.router=typeof t.router=="string"?{name:t.router}:t.router),t?.connector&&(r.connector=typeof t.connector=="string"?{name:t.connector}:t.connector),t?.x6EdgeConfig&&Object.assign(r,t.x6EdgeConfig),o.labels?.length&&(r.labels=o.labels.map(a=>({attrs:{label:{text:a.text??""}},position:a.position!=null?{distance:a.position}:void 0}))),this.graph.addEdge(r),this.knownEdgeIds.add(e),this.saveEdgeDefaultAttrs(e,t);const i=this.graph.getCellById(e);i&&this.applyEdgeStyleAndDecoration(i,o,t)}refreshEdgeStyles(){if(this.lastModel)for(const[e,o]of Object.entries(this.lastModel.edges)){const t=this.graph.getCellById(e);if(!t?.isEdge())continue;const r=o.type??this.schema.defaultEdgeType??"default",i=this.schema.edgeTypes?.[r];this.applyEdgeStyleAndDecoration(t,o,i)}}refreshSingleEdgeStyle(e){if(!this.lastModel)return;const o=this.lastModel.edges[e];if(!o)return;const t=this.graph.getCellById(e);if(!t?.isEdge())return;const r=o.type??this.schema.defaultEdgeType??"default",i=this.schema.edgeTypes?.[r];this.applyEdgeStyleAndDecoration(t,o,i)}refreshNodeHighlights(){if(this.lastModel)for(const[e,o]of Object.entries(this.lastModel.nodes)){const t=this.graph.getCellById(e);t?.isNode()&&this.applyNodeHighlightAndDecoration(t,o)}}applyNodeHighlightAndDecoration(e,o){const t=this.highlightedNodeIds.has(e.id),r=this.resolveNodeDecoration?.(o),i=this.graph.findViewByCell(e)?.container,a=this.getNodeRingTarget(i),c=this.prevNodeDecorationClasses.get(e.id);c&&(i?.classList.remove(c),this.prevNodeDecorationClasses.delete(e.id)),r?.className&&(i?.classList.add(r.className),this.prevNodeDecorationClasses.set(e.id,r.className));const l=r?.borderColor,g=l??(t?"#3a84ff":void 0),h=this.prevNodeDecorationColors.has(e.id)||this.defaultHighlightedNodeIds.has(e.id);g?(e.setAttrByPath("body/stroke",g),e.setAttrByPath("body/strokeWidth",2)):h&&(this.restoreNodeAttr(e,"body/stroke","stroke"),this.restoreNodeAttr(e,"body/strokeWidth","strokeWidth")),a&&(a.classList.add(At),l?(a.classList.add(De),a.style.setProperty("--flow-canvas-node-decoration-ring-background",l),a.style.setProperty("--flow-canvas-node-decoration-ring-opacity","0.95")):(a.classList.remove(De),a.style.removeProperty("--flow-canvas-node-decoration-ring-background"),a.style.removeProperty("--flow-canvas-node-decoration-ring-opacity")),t?(a.classList.add(Ae),a.style.setProperty("--flow-canvas-node-pulse-ring-background",l??_t),a.style.setProperty("--flow-canvas-node-pulse-ring-opacity","0.95")):(a.classList.remove(Ae),a.style.removeProperty("--flow-canvas-node-pulse-ring-background"),a.style.removeProperty("--flow-canvas-node-pulse-ring-opacity"))),l?this.prevNodeDecorationColors.add(e.id):this.prevNodeDecorationColors.delete(e.id),t&&!l?this.defaultHighlightedNodeIds.add(e.id):this.defaultHighlightedNodeIds.delete(e.id)}getHoveredEdgeId(){return this.hoveredEdgeId}setHoveredEdge(e){this.hoveredEdgeId=e}setHighlightedNodes(e){this.highlightedNodeIds=new Set(e)}setHighlightedEdges(e){const o=this.highlightedEdgeIds;return this.highlightedEdgeIds=new Set(e),o}applyEdgeStyleAndDecoration(e,o,t){const r=this.highlightedEdgeIds.has(e.id),i=this.resolveEdgeDecoration?.(o),a=this.prevEdgeDecorationClasses.get(e.id);a&&(this.graph.findViewByCell(e)?.container?.classList.remove(a),this.prevEdgeDecorationClasses.delete(e.id)),i?.className&&(this.graph.findViewByCell(e)?.container?.classList.add(i.className),this.prevEdgeDecorationClasses.set(e.id,i.className));let c,l,v;if(t?.style){const R=this.graph.isSelected?.(e)??!1,E=this.hoveredEdgeId===e.id,N=t.style(o,{selected:R,highlighted:r,hovered:E});c=N.stroke,l=N.strokeWidth,v=N.strokeDasharray}const g=!t?.style&&r?"#3a84ff":void 0,h=i?.strokeColor,f=i?.targetMarkerColor,b=h??c??g,A=!!t?.style||this.prevEdgeDecorationColors.has(e.id)||this.defaultHighlightedEdgeIds.has(e.id)||this.prevEdgeStyleIds.has(e.id);b?this.setEdgeAttrIfChanged(e,"line/stroke",b):A&&this.restoreEdgeAttr(e,"line/stroke","stroke"),this.applyEdgeMarkerDecoration(e,t,"targetMarker",f),t?.style?(this.prevEdgeStyleIds.add(e.id),l?this.setEdgeAttrIfChanged(e,"line/strokeWidth",l):this.restoreEdgeAttr(e,"line/strokeWidth","strokeWidth"),v?this.setEdgeAttrIfChanged(e,"line/strokeDasharray",v):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),g?this.defaultHighlightedEdgeIds.add(e.id):this.defaultHighlightedEdgeIds.delete(e.id)}}class Bt{instanceId=X();registeredShapes=new Map;wrappedComponents=new Map;getShapeName(e){let o=this.registeredShapes.get(e);return o||(o=`flow-node-${this.instanceId}-${e}`,this.registeredShapes.set(e,o)),o}registerNodeType(e,o){const t=this.getShapeName(e);let r=this.wrappedComponents.get(e);return r||(r=s.defineComponent({name:`FlowCanvasNodeShape${e.replace(/(^|[-_])(\w)/g,(i,a,c)=>c.toUpperCase())}`,setup(){return()=>s.h("div",{class:"flow-canvas-node-surface"},[s.h(o)])}}),this.wrappedComponents.set(e,r)),lt.register({shape:t,component:r,width:100,height:40}),t}dispose(){this.registeredShapes.clear(),this.wrappedComponents.clear()}}class Tt{graph;onUiEvent;onCommand;flowModelRef;idGenerator;disposers=[];constructor(e,o,t,r,i){this.graph=e,this.onUiEvent=o,this.onCommand=t,this.flowModelRef=r,this.idGenerator=i??Se,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:mouseenter",({node:e})=>{this.onUiEvent({type:"node.mouseenter",nodeId:e.id})}),this.on("node:mouseleave",({node:e})=>{this.onUiEvent({type:"node.mouseleave",nodeId:e.id})}),this.on("node:contextmenu",({node:e,e:o})=>{this.onUiEvent({type:"node.contextmenu",nodeId:e.id,position:{x:o.clientX,y:o.clientY}})}),this.on("edge:click",({edge:e,e:o})=>{const r=o.target?.closest?.(".x6-edge-label");if(r){const a=e.getData?.()?.labels??[],c=r.parentElement?.querySelectorAll(".x6-edge-label"),l=c?Array.from(c).indexOf(r):0,v=a[Math.max(0,l)];this.onUiEvent({type:"edge.label.click",edgeId:e.id,labelId:v?.id??`label-${l}`});return}this.onUiEvent({type:"edge.click",edgeId:e.id})}),this.on("blank:click",({e})=>{const o=this.graph.clientToLocal(e.clientX,e.clientY);this.onUiEvent({type:"blank.click",position:{x:o.x,y:o.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 o=e.getPosition();this.onCommand({id:X(),source:"user:drag",label:"移动节点",timestamp:Date.now(),commands:[{type:"node.move",nodeId:e.id,position:{x:o.x,y:o.y}}]})}),this.on("edge:connected",({edge:e,isNew:o})=>{const t=e.getSourceCell(),r=e.getTargetCell();if(!t||!r)return;const i=e.getSourcePortId(),a=e.getTargetPortId(),c=e.id in this.flowModelRef.value.edges;o&&!c?(this.graph.removeCell(e),this.onCommand({id:X(),source:"user:drag",label:"连线",timestamp:Date.now(),commands:[{type:"edge.add",edge:{id:this.idGenerator("edge"),source:{nodeId:t.id,portId:i??void 0},target:{nodeId:r.id,portId:a??void 0}}}]})):this.onCommand({id:X(),source:"user:drag",label:"重连",timestamp:Date.now(),commands:[{type:"edge.reconnect",edgeId:e.id,source:{nodeId:t.id,portId:i??void 0},target:{nodeId:r.id,portId:a??void 0}}]})}),this.on("edge:change:labels",({edge:e,current:o})=>{const r=e.getData?.()?.labels??[];if(!r.length||!o?.length)return;const i=[];for(let a=0;a<Math.min(r.length,o.length);a++){const c=o[a],l=r[a];if(!l?.id)continue;const v=typeof c.position=="object"?c.position?.distance:c.position;v!=null&&i.push({type:"edge.label.update",edgeId:e.id,labelId:l.id,patch:{position:v}})}i.length&&this.onCommand({id:X(),source:"user:drag",label:"拖动标签",timestamp:Date.now(),commands:i})})}on(e,o){this.graph.on(e,o),this.disposers.push(()=>this.graph.off(e,o))}}function Rt(n){function e(t){const r=n.getCellById(t);if(!r||!r.isNode())return null;const i=r,a=i.getPosition(),c=i.getSize(),l={x:a.x,y:a.y,width:c.width,height:c.height},v=n.localToGraph(l);return new DOMRect(v.x,v.y,v.width,v.height)}function o(t){const r=e(t);if(!r)return null;const i=n.container;if(!i||typeof i.getBoundingClientRect!="function")return r;const a=i.getBoundingClientRect();return new DOMRect(r.x+a.left,r.y+a.top,r.width,r.height)}return{getNodeScreenRect:e,getNodeViewportRect:o}}const Lt=Object.freeze({top:24,right:8,bottom:8,left:8});function je(n){return{nodeIds:n.filter(e=>e.isNode()).map(e=>e.id),edgeIds:n.filter(e=>e.isEdge()).map(e=>e.id)}}function Ot(n,e=Lt){return new DOMRect(n.x-e.left,n.y-e.top,n.width+e.left+e.right,n.height+e.top+e.bottom)}function $t(n,e){const o=[...e.nodeIds.map(i=>n.getCellById(i)),...e.edgeIds.map(i=>n.getCellById(i))].filter(i=>!!i);if(o.length===0)return null;const t=n.getCellsBBox(o);if(!t)return null;const r=n.localToGraph(t);return Ot(r)}function We(n,e,o){const t=n.nodeIds.filter(a=>{const c=e.nodes[a];if(!c)return!1;const l=o(c);return l.deletable!==!1&&l.deleteDisabled!==!0}),r=new Set(t),i=n.edgeIds.filter(a=>{const c=e.edges[a];return c?!r.has(c.source.nodeId)&&!r.has(c.target.nodeId):!1});return{nodeIds:t,edgeIds:i}}function Ft(n){return[...n.edgeIds.map(e=>({type:"edge.remove",edgeId:e})),...n.nodeIds.map(e=>({type:"node.remove",nodeId:e}))]}const Vt=100;function zt({graph:n,overlayManager:e,executeCommand:o,schema:t,flowModel:r,getNodeBehavior:i,idGenerator:a,defaultInsertGap:c,getContextMenuItems:l,onHighlightChange:v,resolveNodeShape:g}){const h=a??Se;let f=[],b=[],A=null,R=!1,E=null;async function N(){if(R)return A;R=!0;try{const d=await import("@antv/x6-plugin-dnd"),w=d.Dnd??d.default;return w?(A=new w({target:n,scaled:!0,animation:!0,getDragNode:u=>u.clone(),getDropNode:u=>u.clone()}),A):null}catch{return console.warn("[flow-canvas] @antv/x6-plugin-dnd not available, add it to your dependencies"),null}}function M(){return new Promise(d=>{requestAnimationFrame(()=>requestAnimationFrame(()=>d()))})}const O=({node:d})=>{const w=d.getData?.();if(!w?._dndSessionId||w._dndSessionId!==E)return;E=null;const u=d.getPosition();n.removeNode(d.id);const{_dndSessionId:p,...m}=w,y=m.id||h("node");o({id:X(),source:"user:drag",label:"拖入节点",timestamp:Date.now(),commands:[{type:"node.add",node:{...m,id:y,position:{x:u.x,y:u.y}}}]})};n.on("node:added",O);function q(d){const w=t.nodeTypes[d.type];return Ne(d,w?.getPorts)}function S(d){return d??je(n.getSelectedCells?.()??[])}function G(d,w,u,p,m){switch(d){case"left":return{x:w.position.x-m-p.width,y:w.position.y+(u.height-p.height)/2};case"top":return{x:w.position.x+(u.width-p.width)/2,y:w.position.y-m-p.height};case"bottom":return{x:w.position.x+(u.width-p.width)/2,y:w.position.y+u.height+m};default:return{x:w.position.x+u.width+m,y:w.position.y+(u.height-p.height)/2}}}function z(d){switch(d){case"left":return"right";case"top":return"bottom";case"bottom":return"top";default:return"left"}}const F={zoomIn(){n.zoom(.1)},zoomOut(){n.zoom(-.1)},zoomTo(d){n.zoomTo(d)},zoomToFit(d){n.zoomToFit({padding:40,maxScale:1,...d})},getZoom(){return n.zoom()},centerContent(){n.centerContent()},scrollToOrigin(){n.translate(0,0)},scrollToNode(d){const w=n.getCellById(d);w&&n.centerCell(w)},getSelection(){return S()},getSelectionBounds(d){return $t(n,S(d))},selectNodes(d){const w=d.map(u=>n.getCellById(u)).filter(Boolean);n.select?.(w)},selectEdges(d){const w=d.map(u=>n.getCellById(u)).filter(Boolean);n.select?.(w)},clearSelection(){const d=n.getSelectedCells?.();d?.length&&n.unselect?.(d)},deleteSelection(d){const w=S(d?.selection),u=We(w,r.value,i??(()=>({}))),p=Ft(u);if(p.length===0)return null;const m=o({id:X(),source:d?.source??"user:toolbar",label:d?.label??"删除选中",timestamp:Date.now(),commands:p});return m.status==="applied"&&d?.clearSelectionAfterApply!==!1&&F.clearSelection(),m},registerDndSource(d,w){const u=async p=>{const m=await N();if(!m)return;const y=X();E=y;const k=w(),T=g?.(k.type),V=n.createNode({width:T?.width??154,height:T?.height??54,shape:T?.shapeName??"rect",data:{...k,_dndSessionId:y}});m.start(V,p)};return d.addEventListener("mousedown",u),()=>{d.removeEventListener("mousedown",u)}},startConnection(d,w){const u=n.getCellById(d);if(!u?.isNode())return;const p=u,m=n.findViewByCell(p);if(!m)return;const y=m.findPortElem(w,"circle")??m.findPortElem(w);if(!y)return;const T=(y.matches?.("[magnet]")?y:y.querySelector?.("[magnet]"))??y,V=T.getBoundingClientRect(),J=V.left+V.width/2,D=V.top+V.height/2,_=new MouseEvent("mousedown",{clientX:J,clientY:D,button:0,buttons:1,bubbles:!0,cancelable:!0});T.dispatchEvent(_)},async exportAsImage(d){const{domToBlob:w}=await import("modern-screenshot"),u=d?.padding??20,p=d?.backgroundColor??n.options.background?.color??"#ffffff",m=n.zoom(),y=n.translate(),k=n.getContentBBox(),T=k.width/m,V=k.height/m;if(T===0||V===0)return new Blob;const J=(k.x-y.tx)/m,D=(k.y-y.ty)/m,_=Math.ceil(T+u*2),C=Math.ceil(V+u*2),B=document.createElement("div");B.style.cssText="position:fixed;left:-99999px;top:0;pointer-events:none;";const $=n.container.cloneNode(!0);$.style.width=`${_}px`,$.style.height=`${C}px`,$.style.overflow="visible";const j=$.querySelector("svg");j&&(j.setAttribute("width",String(_)),j.setAttribute("height",String(C)),j.style.width=`${_}px`,j.style.height=`${C}px`),$.querySelector(".x6-graph-svg-viewport")?.setAttribute("transform",`matrix(1,0,0,1,${-J+u},${-D+u})`),B.appendChild($),document.body.appendChild(B);try{return await M(),await w($,{width:_,height:C,backgroundColor:p,scale:d?.scale??window.devicePixelRatio,filter:W=>{if(W instanceof Element){const U=W.getAttribute("class")??"";if(U.includes("x6-widget-selection")||U.includes("x6-widget-transform")||U.includes("x6-graph-grid")||U.includes("x6-graph-background"))return!1}return!0}})}catch(W){return console.warn("[flow-canvas] Export failed:",W),new Blob}finally{B.remove()}},highlightNodes(d){f=d,v?.(f,b)},highlightEdges(d){b=d,v?.(f,b)},clearHighlight(){f=[],b=[],v?.([],[])},overlay:e,getContextMenuItems(d){return l?.(d)??[]},insertNodeToRight(d,w,u){const p=r.value,m=p.nodes[d];if(!m)return{status:"invalid",envelope:{id:"",source:"user:toolbar",timestamp:Date.now(),commands:[]},error:{code:"constraint_violated",reason:`Source node "${d}" not found`,source:"api"}};const y=u?.gap??c??Vt,k=u?.direction??"right",T=t.nodeTypes[m.type],V=t.nodeTypes[w.type],J=T?.getSize(m)??{width:154,height:54},D=V?.getSize({...w,position:{x:0,y:0}})??{width:154,height:54},_=G(k,m,J,D,y),C=w.id||h("node"),B={...w,id:C,position:_},$=[{type:"node.add",node:B}];if(u?.autoWireEdges){const ee=q(m),W=q(B),U=k,ie=z(k),ne=ee.find(x=>x.group===U),le=W.find(x=>x.group===ie),Ee=W.find(x=>x.group===U),fe=ne?Object.values(p.edges).find(x=>x.source.nodeId===d&&x.source.portId===ne.id):Object.values(p.edges).find(x=>x.source.nodeId===d);if(fe){const x=fe.target,I=D.width+y,P=k==="right"?I:k==="left"?-I:0,H=k==="bottom"?I:k==="top"?-I:0,K=new Set,oe=[x.nodeId];for(;oe.length>0;){const Y=oe.shift();if(K.has(Y)||Y===d)continue;K.add(Y);const de=p.nodes[Y];if(de){$.push({type:"node.move",nodeId:Y,position:{x:de.position.x+P,y:de.position.y+H}});for(const ce of Object.values(p.edges))ce.source.nodeId===Y&&!K.has(ce.target.nodeId)&&oe.push(ce.target.nodeId)}}$.push({type:"edge.remove",edgeId:fe.id}),$.push({type:"edge.add",edge:{id:h("edge"),source:{nodeId:d,portId:ne?.id},target:{nodeId:C,portId:le?.id}}}),$.push({type:"edge.add",edge:{id:h("edge"),source:{nodeId:C,portId:Ee?.id},target:x}})}else $.push({type:"edge.add",edge:{id:h("edge"),source:{nodeId:d,portId:ne?.id},target:{nodeId:C,portId:le?.id}}})}const j={id:X(),source:u?.source??"user:toolbar",label:u?.label??"插入节点",timestamp:Date.now(),commands:$};return o(j)},onGraphEvent(d,w){return n.on(d,w),()=>n.off(d,w)},unsafeGetGraph(){return n}};return F}function qt(){const n=s.ref(null),e=s.ref(!1);let o=null,t=!1;function r(h){o&&(clearTimeout(o),o=null),n.value=h}function i(h=100){t||(o&&clearTimeout(o),o=setTimeout(()=>{n.value=null,o=null},h))}function a(){t=!0,o&&(clearTimeout(o),o=null)}function c(h=100){t=!1,i(h)}function l(){o&&(clearTimeout(o),o=null)}function v(){l(),t=!1,n.value=null}function g(){o&&clearTimeout(o)}return{hoveredNodeId:n,isDraggingNode:e,enter:r,leave:i,enterOverlay:a,leaveOverlay:c,cancelLeave:l,reset:v,cleanup:g}}const _e=10,he=12;function Pe(n,e){const o=n.getTotalLength();if(o===0)return{...e,length:0,totalLength:0};let t=n.getPointAtLength(0),r=1/0;const i=50,a=o/i;let c=0;for(let h=0;h<=i;h++){const f=h*a,b=n.getPointAtLength(f),A=(b.x-e.x)**2+(b.y-e.y)**2;A<r&&(r=A,t=b,c=f)}const l=Math.max(0,c-a),v=Math.min(o,c+a),g=(v-l)/20;for(let h=l;h<=v;h+=g){const f=n.getPointAtLength(h),b=(f.x-e.x)**2+(f.y-e.y)**2;b<r&&(r=b,t=f,c=h)}return{x:t.x,y:t.y,length:c,totalLength:o}}function Be(n,e){return n<_e||n>e-_e}function Te(n,e,o){const t=n.querySelectorAll(".x6-edge-label");for(const r of t){const i=r.getBoundingClientRect();if(e>=i.left-he&&e<=i.right+he&&o>=i.top-he&&o<=i.bottom+he)return!0}return!1}function Re(){const n="http://www.w3.org/2000/svg",e=document.createElementNS(n,"g");e.setAttribute("class","flow-canvas-edge-delete-tool"),e.style.cursor="pointer";const o=document.createElementNS(n,"rect");o.setAttribute("width","20"),o.setAttribute("height","20"),o.setAttribute("x","-10"),o.setAttribute("y","-10"),o.setAttribute("rx","4"),o.setAttribute("ry","4"),o.setAttribute("fill","#3a84ff"),e.appendChild(o);const t=document.createElementNS(n,"text");return t.setAttribute("font-family","flow-canvas"),t.setAttribute("font-size","16"),t.setAttribute("fill","#ffffff"),t.setAttribute("text-anchor","middle"),t.setAttribute("dominant-baseline","central"),t.textContent="",e.appendChild(t),e}function Ht(n){let e=null,o=null;function t(c,l){if(i(),o=c,l.target?.closest?.(".x6-edge-label"))return;const g=n.getCellById(c);if(!g?.isEdge())return;const h=n.findViewByCell(g);if(!h)return;const f=h.container.querySelector("path");if(!f)return;const b=n.clientToLocal(l.clientX,l.clientY),A=Pe(f,b);if(Be(A.length,A.totalLength)||Te(h.container,l.clientX,l.clientY))return;const R=Re();R.setAttribute("transform",`translate(${A.x}, ${A.y})`),h.container.appendChild(R),e=R}function r(c){if(!o)return;if(c.target?.closest?.(".x6-edge-label")){e&&e.setAttribute("display","none");return}const v=n.getCellById(o);if(!v?.isEdge())return;const g=n.findViewByCell(v);if(!g)return;const h=g.container.querySelector("path");if(!h)return;const f=n.clientToLocal(c.clientX,c.clientY),b=Pe(h,f);if(Be(b.length,b.totalLength)||Te(g.container,c.clientX,c.clientY))e&&e.setAttribute("display","none");else if(e)e.removeAttribute("display"),e.setAttribute("transform",`translate(${b.x}, ${b.y})`);else{const A=Re();A.setAttribute("transform",`translate(${b.x}, ${b.y})`),g.container.appendChild(A),e=A}}function i(){e&&(e.remove(),e=null),o=null}function a(c){c===o&&(e=null,o=null)}return{show:t,move:r,remove:i,handleEdgeRemoved:a}}function Gt(n){let e=null,o=0;function t(g){const h=g?"visible":"hidden";for(const f of n.getNodes())for(const b of f.getPorts())f.setPortProp(b.id,"attrs/circle/visibility",h)}function r(g){if(!e)for(const h of g.getPorts())g.setPortProp(h.id,"attrs/circle/visibility","visible")}function i(g){if(!e)for(const h of g.getPorts())g.setPortProp(h.id,"attrs/circle/visibility","hidden")}function a(g,h){if(!g.getTargetCell())if(e=g.id,h?.size)for(const f of n.getNodes()){const b=h.has(f.id)?"hidden":"visible";for(const A of f.getPorts())f.setPortProp(A.id,"attrs/circle/visibility",b)}else t(!0)}function c(){e=null,t(!1),o=Date.now()+300}function l(g){g===e&&(e=null,t(!1))}function v(){return!e&&Date.now()>=o}return{showNodePorts:r,hideNodePorts:i,handleEdgeAdded:a,handleEdgeConnected:c,handleEdgeRemoved:l,canShowEdgeTool:v}}function Le(n){return n==="top"||n==="right"||n==="bottom"||n==="left"}function Ut(n){const{editor:e,nodeHover:o,isSelectionModeActive:t,viewportVersion:r,getNodeBehavior:i,getInsertGap:a}=n,{isDraggingNode:c}=n,l=s.ref(null),v=s.ref(!1);let g=null,h=null,f=null;const b=s.computed(()=>({enabled:!0,portGroup:"right",autoPanOnOpen:!0,autoPanPadding:16,...n.quickAddProp.value}));function A(){g&&(clearTimeout(g),g=null)}function R(){g&&clearTimeout(g),g=setTimeout(()=>{l.value=null,g=null},150)}function E(D){return v.value?!0:(A(),d(D)?(l.value=D,!0):(l.value=null,!1))}function N(){A(),o.enterOverlay()}function M(){R(),o.leaveOverlay()}function O(D){const _=e.schema.nodeTypes[D.type];return Ne(D,_?.getPorts)}function q(D,_){const C=b.value.getPort?.(D,_);if(!C)return null;const B=typeof C=="string"?C:C.id;return _.find($=>$.id===B)??null}function S(D,_){const C=e.api.value?.overlay.getNodeScreenRect(D);if(!C)return null;switch(_){case"top":return{x:C.x+C.width/2,y:C.y};case"bottom":return{x:C.x+C.width/2,y:C.y+C.height};case"left":return{x:C.x,y:C.y+C.height/2};case"right":return{x:C.x+C.width,y:C.y+C.height/2};default:return null}}function G(D,_,C){if(!h)return S(D,C);const B=h.getCellById(D);if(B?.isNode()){const $=B,j=h.findViewByCell($),ee=j?.findPortElem(_,"circle")??j?.findPortElem(_);if(ee){const W=h.container.getBoundingClientRect(),U=ee.getBoundingClientRect();return{x:U.left-W.left+U.width/2,y:U.top-W.top+U.height/2}}}return S(D,C)}function z(D){const _=O(D),C=q(D,_)??_.find($=>$.group===b.value.portGroup)??null;if(!C)return null;const B=G(D.id,C.id,C.group);return B?{portId:C.id,portGroup:C.group,portPosition:B}:null}function F(D){const _=z(D),C=b.value.insertDirection;if(typeof C=="function"){const B=C(D,_?{id:_.portId,group:_.portGroup}:null);if(B)return B}else if(C)return C;return _&&Le(_.portGroup)?_.portGroup:Le(b.value.portGroup)?b.value.portGroup:"right"}function d(D){if(!b.value.enabled||e.mode.value!=="edit")return!1;const C=e.flowModel.value.nodes[D];return!C||i(C).quickAddEnabled===!1?!1:!!z(C)}const w=s.computed(()=>{if(r.value,!b.value.enabled)return null;const D=l.value;if(!D||c.value||!e.api.value||e.mode.value!=="edit"||t.value)return null;const C=e.flowModel.value.nodes[D];if(!C)return null;const B=i(C);if(B.quickAddEnabled===!1)return null;const $=z(C);return $?{node:C,...$,behavior:B}:null});function u(D){v.value=!0,w.value&&e._emitUiEvent({type:"node.quick-add",nodeId:D,position:w.value.portPosition})}function p(){v.value=!1}function m(D){const _=e.api.value;if(!_)return;const C=e.flowModel.value.nodes[D];if(!C)return;const B=z(C);B&&_.startConnection(D,B.portId)}function y(D){if(!h||!b.value.autoPanOnOpen||D<=0)return;const _=h.translate();h.translate(_.tx-D,_.ty)}function k(D,_){const C=e.api.value;if(!C)return;const B=_.id||e.idGenerator("node"),$={..._,id:B},j=e.flowModel.value.nodes[D];if(!j)return;C.insertNodeToRight(D,$,{autoWireEdges:!0,direction:F(j),gap:a(),source:"user:quick-add",label:"快捷插入节点"}).status==="applied"&&e._emitUiEvent({type:"node.action.quick-insert",sourceNodeId:D,newNodeId:B}),n.closePopover()}function T(D){if(!h)return;const _=h.getCellById(D);if(!_?.isNode())return;const C=_,B=e.flowModel.value.nodes[D];if(!B)return;const $=z(B);let j=!0;i(B).hidePortForQuickAdd===!1&&(j=!1);const W=j&&!c.value&&!!$&&d(D);for(const U of C.getPorts()){const ie=W&&U.id===$?.portId?"hidden":"visible";C.setPortProp(U.id,"attrs/circle/visibility",ie)}}function V(D,_){f?.(),h=D,f=s.watch([l,c],([C],[B])=>{if(B&&B!==C){const $=D.getCellById(B);$?.isNode()&&_($)}C&&T(C)},{flush:"sync"})}s.watch(w,D=>{D||(v.value=!1)});function J(){g&&clearTimeout(g),f?.(),f=null,h=null}return{quickAddNodeId:l,quickAddPopoverOpen:v,mergedConfig:b,data:w,enter:E,leave:R,cancelLeave:A,handleOverlayEnter:N,handleOverlayLeave:M,handleOpen:u,handleClose:p,handleStartDrag:m,handlePopoverViewportOverflow:y,handleInsert:k,isActiveForNode:d,syncNodePorts:T,attachRuntime:V,cleanup:J}}const jt=15,Wt=10;function Xt(n){const{editor:e}=n;let o=null,t=null,r=null,i=null;const a=[];let c=null;const l=s.computed(()=>({enabled:!1,bufferMargin:jt,incomingPortGroup:"left",outgoingPortGroup:"right",...n.edgeDropProp.value}));function v(d){if(!o)return null;const w=o.getCellById(d);if(!w?.isEdge())return null;const u=o.findViewByCell(w)?.container;if(!u)return null;const p=u.querySelectorAll("path");for(const m of p)if(m.getAttribute("stroke")!=="transparent")return m;return null}function g(d){const w=v(d);w&&(w.style.stroke="#3a84ff",i=d)}function h(){if(!i)return;const d=v(i);d&&(d.style.stroke=""),i=null}function f(d,w,u){if(o){const p=o.getCellById(d);if(p?.isNode()){const m=p.getPorts().find(y=>y.group===u);if(m?.id)return m.id}}if(w.ports?.length){const p=w.ports.find(m=>m.group===u);if(p)return p.id}return u}function b(d){const w=d.getTotalLength();if(w===0)return[];const u=[];for(let m=0;m<=w;m+=Wt){const y=d.getPointAtLength(m);u.push({x:y.x,y:y.y})}const p=d.getPointAtLength(w);return u.push({x:p.x,y:p.y}),u}function A(d,w,u){if(!o)return null;const p=l.value,m=p.bufferMargin,y={x:d.x+m,y:d.y+m,width:Math.max(0,d.width-m*2),height:Math.max(0,d.height-m*2)};if(y.width<=0||y.height<=0)return null;const k=y.x+y.width,T=y.y+y.height;let V=null;const J=d.x+d.width/2,D=d.y+d.height/2;for(const _ of o.getEdges()){const C=w.edges[_.id];if(!C||u&&(C.source.nodeId===u||C.target.nodeId===u)||p.isEdgeDropTarget&&!p.isEdgeDropTarget(C,w))continue;const B=o.findViewByCell(_);if(!B)continue;const $=B.findOne?.("path");if(!$||typeof $.getTotalLength!="function")continue;const j=b($);if(!j.length)continue;let ee=!1,W=1/0;for(const U of j)if(U.x>=y.x&&U.x<=k&&U.y>=y.y&&U.y<=T){const ie=U.x-J,ne=U.y-D,le=ie*ie+ne*ne;le<W&&(W=le),ee=!0}ee&&(!V||W<V.distSq)&&(V={edgeId:_.id,edge:C,distSq:W})}return V?{edgeId:V.edgeId,edge:V.edge}:null}function R(d,w){if(!l.value.enabled)return;const p=e.flowModel.value,m=A(d,p,w);m?t!==m.edgeId&&(h(),t=m.edgeId,g(m.edgeId)):t&&(h(),t=null)}let E=!0;function N({node:d}){if(t=null,!l.value.enabled)return;const w=e.flowModel.value,u=w.nodes[d.id];if(!u){E=!1;return}const p=l.value;E=!p.isNodeInsertable||p.isNodeInsertable(u,w)}function M({node:d}){!l.value.enabled||!E||r===null&&(r=requestAnimationFrame(()=>{if(r=null,!o)return;const w=d.getPosition(),u=d.getSize();R({x:w.x,y:w.y,width:u.width,height:u.height},d.id)}))}function O(){r!==null&&(cancelAnimationFrame(r),r=null),h(),E=!0}function q(){if(!o)return;let d=!1;c=()=>{if(!l.value.enabled)return;const w=document.querySelector(".x6-widget-dnd");if(!w){d&&(d=!1,h(),t=null);return}d=!0,r===null&&(r=requestAnimationFrame(()=>{if(r=null,!o)return;const u=w.getBoundingClientRect(),p=o.clientToLocal(u.left,u.top),m=o.clientToLocal(u.right,u.bottom),y={x:p.x,y:p.y,width:m.x-p.x,height:m.y-p.y};R(y)}))},document.addEventListener("mousemove",c),a.push(()=>{c&&(document.removeEventListener("mousemove",c),c=null)})}function S(){h(),t=null,r!==null&&(cancelAnimationFrame(r),r=null)}function G(d){if(!t||d.source!=="user:drag")return d;const w=t;t=null,h();const u=e.flowModel.value,p=u.edges[w];if(!p)return d;const m=d.commands.find(B=>B.type==="node.add"||B.type==="node.move");if(!m)return d;const y=m.type==="node.add"?m.node.id:m.nodeId,k=m.type==="node.add"?m.node:u.nodes[m.nodeId];if(!k)return d;const T=l.value;if(T.isNodeInsertable&&!T.isNodeInsertable(k,u))return d;const V=f(y,k,T.incomingPortGroup),J=f(y,k,T.outgoingPortGroup),D=e.idGenerator("edge"),_=e.idGenerator("edge"),C=[{type:"edge.remove",edgeId:w},{type:"edge.add",edge:{id:D,type:p.type,source:{nodeId:p.source.nodeId,portId:p.source.portId},target:{nodeId:y,portId:V}}},{type:"edge.add",edge:{id:_,type:p.type,source:{nodeId:y,portId:J},target:{nodeId:p.target.nodeId,portId:p.target.portId}}}];return{...d,source:"user:edge-drop",commands:[...d.commands,...C]}}function z(d){o=d;const w=(u,p)=>{d.on(u,p),a.push(()=>d.off(u,p))};w("node:move",N),w("node:change:position",M),w("node:moved",O),q()}function F(){S();for(const d of a)d();a.length=0,o=null,E=!0}return{attachRuntime:z,tryExpandForEdgeDrop:G,cleanup:F}}function Kt(n){function e(r){return{id:n.idGenerator("node"),type:r.type,label:r.label,ports:r.ports?JSON.parse(JSON.stringify(r.ports)):void 0,payload:r.payload?JSON.parse(JSON.stringify(r.payload)):void 0,extensions:r.extensions?JSON.parse(JSON.stringify(r.extensions)):void 0}}function o(r,i,a){const c=n.api.value;switch(r){case"delete":return n.executeCommand({id:X(),source:"user:toolbar",label:"删除节点",timestamp:Date.now(),commands:[{type:"node.remove",nodeId:i}]}),n._emitUiEvent({type:"node.action.delete",nodeId:i}),!0;case"copy":{if(!c)break;const l=n.flowModel.value.nodes[i];if(!l)break;const v=e(l),g=50;n.executeCommand({id:X(),source:"user:toolbar",label:"复制节点",timestamp:Date.now(),commands:[{type:"node.add",node:{...v,position:{x:l.position.x+g,y:l.position.y+g}}}]}),c.selectNodes([v.id]),n._emitUiEvent({type:"node.action.copy",sourceNodeId:i,newNodeId:v.id});break}case"copy-insert":{if(!c)break;const l=n.flowModel.value.nodes[i];if(!l)break;const v=e(l);c.insertNodeToRight(i,v,{autoWireEdges:!0,gap:a,label:"复制并插入节点"}),c.selectNodes([v.id]),n._emitUiEvent({type:"node.action.copy-insert",sourceNodeId:i,newNodeId:v.id});break}case"disconnect":{const l=n.flowModel.value,v=Object.entries(l.edges).filter(([,g])=>{const h=g;return h.source.nodeId===i||h.target.nodeId===i}).map(([g])=>g);if(v.length===0)break;n.executeCommand({id:X(),source:"user:toolbar",label:"断开连线",timestamp:Date.now(),commands:v.map(g=>({type:"edge.remove",edgeId:g}))}),n._emitUiEvent({type:"node.action.disconnect",nodeId:i,edgeIds:v});break}case"debug":{n._emitUiEvent({type:"node.action.debug",nodeId:i});break}}return!1}function t(r){n.api.value?.deleteSelection({selection:r,source:"user:toolbar",label:"批量删除选中"})}return{handleNodeAction:o,deleteSelection:t}}function Yt(){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 Zt(n,e){const o=e.defaultEdgeType??"default",t=e.edgeTypes?.[o],r={zIndex:-1,attrs:{line:{stroke:"#abb5cc",strokeWidth:2,targetMarker:{name:"block",width:8,height:8}}}};t?.router&&(r.router=typeof t.router=="string"?{name:t.router}:t.router),t?.connector&&(r.connector=typeof t.connector=="string"?{name:t.connector}:t.connector),t?.x6EdgeConfig&&Object.assign(r,t.x6EdgeConfig);const i=r.attrs??{},a=i.line??{};return r.attrs={...i,line:{...a,targetMarker:Yt()}},n.createEdge(r)}const Qt=".x6-widget-selection",Jt=".x6-graph-svg";function eo(n){const e=n.querySelector(Qt),o=n.querySelector(Jt);return!e||!o||e.parentNode!==o.parentNode||!o.parentNode||o.previousSibling===e?!1:(o.parentNode.insertBefore(e,o),!0)}function to(n){const e=()=>eo(n);e();const o=new MutationObserver(()=>{e()});return o.observe(n,{childList:!0}),()=>o.disconnect()}function oo(n,e,o){const t=new Set(e),r=new Set(o),i=new Set([...t,...r]);for(const a of i){const c=n.getCellById(a);if(!c?.isNode())continue;const l=r.has(a),v=c.getData()??{};v._selected!==l&&c.setData({...v,_selected:l})}}const no={class:"flow-canvas-node-actions__bar"},ro=s.defineComponent({__name:"node-actions-toolbar",props:{node:{},position:{},config:{},behavior:{},actionsOffset:{}},emits:["action"],setup(n,{emit:e}){const o=n,t=s.computed(()=>{const h=o.actionsOffset?.x??0,f=o.actionsOffset?.y??0,b=h!==0||f!==0;return{left:`${o.position.x}px`,top:`${o.position.y}px`,transform:b?`translate(${h}px, ${f}px)`:"translateX(-100%)"}}),r=e,i=s.computed(()=>({debug:{visible:o.config.showDebug&&o.behavior.debuggable!==!1,disabled:o.behavior.debugDisabled===!0},delete:{visible:o.config.showDelete&&o.behavior.deletable!==!1,disabled:o.behavior.deleteDisabled===!0},copy:{visible:o.config.showCopy&&o.behavior.copyable!==!1,disabled:o.behavior.copyDisabled===!0},copyInsert:{visible:o.config.showCopyInsert&&o.behavior.copyable!==!1,disabled:o.behavior.copyInsertDisabled===!0},disconnect:{visible:o.config.showDisconnect&&o.behavior.disconnectable!==!1,disabled:o.behavior.disconnectDisabled===!0}})),a=s.computed(()=>i.value.copy.visible||i.value.copyInsert.visible||i.value.disconnect.visible),c=s.ref(!1);let l=null;function v(){l&&(clearTimeout(l),l=null),c.value=!0}function g(){l=setTimeout(()=>{c.value=!1,l=null},100)}return s.onBeforeUnmount(()=>{l&&clearTimeout(l)}),(h,f)=>(s.openBlock(),s.createElementBlock("div",{class:"flow-canvas-node-actions",style:s.normalizeStyle(t.value)},[s.createElementVNode("div",no,[i.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":i.value.debug.disabled}]),onClick:f[0]||(f[0]=b=>!i.value.debug.disabled&&r("action","debug",n.node.id))},null,2)):s.createCommentVNode("",!0),i.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":i.value.delete.disabled}]),onClick:f[1]||(f[1]=b=>!i.value.delete.disabled&&r("action","delete",n.node.id))},null,2)):s.createCommentVNode("",!0),a.value?(s.openBlock(),s.createElementBlock("div",{key:2,class:"flow-canvas-node-actions__more-wrapper",onMouseenter:v,onMouseleave:g},[...f[5]||(f[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(()=>[c.value&&a.value?(s.openBlock(),s.createElementBlock("div",{key:0,class:"flow-canvas-node-actions__dropdown",onMouseenter:v,onMouseleave:g},[i.value.copy.visible?(s.openBlock(),s.createElementBlock("div",{key:0,class:s.normalizeClass(["flow-canvas-node-actions__dropdown-item",{"is-disabled":i.value.copy.disabled}]),onClick:f[2]||(f[2]=b=>!i.value.copy.disabled&&r("action","copy",n.node.id))},[...f[6]||(f[6]=[s.createElementVNode("i",{class:"flow-canvas-icon canvas-copy-fuzhi-2"},null,-1),s.createElementVNode("span",null,"复制",-1)])],2)):s.createCommentVNode("",!0),i.value.copyInsert.visible?(s.openBlock(),s.createElementBlock("div",{key:1,class:s.normalizeClass(["flow-canvas-node-actions__dropdown-item",{"is-disabled":i.value.copyInsert.disabled}]),onClick:f[3]||(f[3]=b=>!i.value.copyInsert.disabled&&r("action","copy-insert",n.node.id))},[...f[7]||(f[7]=[s.createElementVNode("i",{class:"flow-canvas-icon canvas-fuzhibingcharu"},null,-1),s.createElementVNode("span",null,"复制并插入",-1)])],2)):s.createCommentVNode("",!0),i.value.disconnect.visible?(s.openBlock(),s.createElementBlock("div",{key:2,class:s.normalizeClass(["flow-canvas-node-actions__dropdown-item",{"is-disabled":i.value.disconnect.disabled}]),onClick:f[4]||(f[4]=b=>!i.value.disconnect.disabled&&r("action","disconnect",n.node.id))},[...f[8]||(f[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))}}),se=(n,e)=>{const o=n.__vccOpts||n;for(const[t,r]of e)o[t]=r;return o},Xe=se(ro,[["__scopeId","data-v-3b39dab5"]]),so={key:0,class:"flow-canvas-quick-add__tooltip"},io=5,ao=s.defineComponent({__name:"node-quick-add-popover",props:{node:{},portPosition:{},autoPanOnOpen:{type:Boolean},autoPanPadding:{}},emits:["open","close","start-drag","viewport-overflow-right","mouseenter","mouseleave"],setup(n,{expose:e,emit:o}){const t=n,r=o,i=s.ref(),a=s.ref(),c=s.ref(!1),l=s.ref(!1);let v=null,g=!1,h=null;function f(F){F.preventDefault(),F.stopPropagation(),v={x:F.clientX,y:F.clientY},g=!1,document.addEventListener("mousemove",b),document.addEventListener("mouseup",A)}function b(F){if(!v)return;const d=F.clientX-v.x,w=F.clientY-v.y;Math.sqrt(d*d+w*w)>=io&&(g=!0,R(),r("start-drag",t.node.id))}function A(){R(),g||E(),v=null,g=!1}function R(){document.removeEventListener("mousemove",b),document.removeEventListener("mouseup",A)}function E(){l.value?O():N()}function N(){l.value=!0,r("open",t.node.id),s.nextTick(()=>{requestAnimationFrame(()=>{M()})}),requestAnimationFrame(()=>{document.addEventListener("mousedown",q)})}function M(){if(!l.value||!t.autoPanOnOpen||!a.value)return;const F=window.innerWidth||document.documentElement.clientWidth||0;if(F<=0)return;const d=t.autoPanPadding??16,u=a.value.getBoundingClientRect().right+d-F;u>0&&r("viewport-overflow-right",u)}function O(){l.value=!1,r("close"),document.removeEventListener("mousedown",q)}function q(F){const d=F.target;i.value?.contains(d)||a.value?.contains(d)||O()}function S(){l.value||r("mouseleave")}function G(){h&&(clearTimeout(h),h=null),r("mouseenter")}function z(){h=setTimeout(()=>{O(),r("mouseleave"),h=null},150)}return s.onBeforeUnmount(()=>{R(),h&&clearTimeout(h),document.removeEventListener("mousedown",q)}),e({closePopover:O}),(F,d)=>(s.openBlock(),s.createElementBlock("div",{class:"flow-canvas-quick-add",style:s.normalizeStyle({left:`${n.portPosition.x}px`,top:`${n.portPosition.y}px`}),onMouseenter:d[2]||(d[2]=w=>r("mouseenter")),onMouseleave:S,onClick:d[3]||(d[3]=s.withModifiers(()=>{},["stop"]))},[s.createElementVNode("div",{ref_key:"btnRef",ref:i,class:s.normalizeClass(["flow-canvas-quick-add__btn",{"is-hovered":c.value,"is-active":l.value}]),onMouseenter:d[0]||(d[0]=w=>c.value=!0),onMouseleave:d[1]||(d[1]=w=>c.value=!1),onMousedown:f},[...d[4]||(d[4]=[s.createElementVNode("i",{class:"flow-canvas-icon canvas-zoom-add"},null,-1)])],34),c.value&&!l.value?(s.openBlock(),s.createElementBlock("div",so,[...d[5]||(d[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:G,onMouseleave:z},[s.renderSlot(F.$slots,"default",{},()=>[d[6]||(d[6]=s.createElementVNode("div",{class:"flow-canvas-quick-add__default-content"},"节点快捷操作面板",-1))],!0)],544)):s.createCommentVNode("",!0)]),_:3})],36))}}),Ke=se(ao,[["__scopeId","data-v-255b3d8c"]]),lo={class:"flow-canvas-selection-actions__bar"},co=s.defineComponent({__name:"selection-actions-toolbar",props:{position:{},canDelete:{type:Boolean}},emits:["action"],setup(n,{emit:e}){const o=n,t=e,r=s.computed(()=>({left:`${o.position.x}px`,top:`${o.position.y}px`,transform:"translateX(-100%)"}));return(i,a)=>(s.openBlock(),s.createElementBlock("div",{class:"flow-canvas-selection-actions",style:s.normalizeStyle(r.value)},[s.createElementVNode("div",lo,[s.createElementVNode("i",{class:s.normalizeClass(["flow-canvas-icon canvas-shanchu flow-canvas-selection-actions__icon",{"is-disabled":!n.canDelete}]),onClick:a[0]||(a[0]=c=>n.canDelete&&t("action","delete"))},null,2)])],4))}}),uo=se(co,[["__scopeId","data-v-25eb8b79"]]),fo={class:"flow-canvas-runtime-core__overlay"},go=s.defineComponent({__name:"canvas-runtime-core",props:{editor:{},graphOptions:{},nodeActions:{},quickAdd:{},edgeDrop:{},getConnectionExcludedNodeIds:{type:Function},toolbarInclude:{}},emits:["ui-event"],setup(n,{expose:e,emit:o}){const t=n,r=o,i=s.ref(),a=s.ref();let c,l,v,g,h=null,f=null,b=null,A=null,R=null;const E=qt(),{hoveredNodeId:N,isDraggingNode:M}=E,O=E.enterOverlay,q=()=>E.leaveOverlay(),S=s.ref(0),G=s.ref({nodeIds:[],edgeIds:[]});function z(x){const I=t.editor.api.value;return I?t.editor.schema.nodeTypes[x.type]?.getBehavior?.(x,{api:I,flowModel:t.editor.flowModel.value,history:t.editor.history,mode:t.editor.mode.value})??{}:{}}const F=s.computed(()=>t.editor.mode.value==="edit"&&t.editor.selectionMode.value),d=s.computed(()=>({showDebug:!1,showDelete:!0,showCopy:!0,showCopyInsert:!0,showDisconnect:!0,insertGap:100,...t.nodeActions})),w=s.computed(()=>{if(S.value,!t.editor.api.value)return[];const x=t.editor.flowModel.value,I=t.editor.api.value.overlay,P=[];for(const[H,K]of Object.entries(x.nodes)){const oe=t.editor._pluginManager.collectNodeDecorations(K);if(!oe?.badge)continue;const Y=I.getNodeScreenRect(H);Y&&P.push({nodeId:H,x:Y.x+Y.width-4,y:Y.y-8,badge:oe.badge})}return P}),u=s.computed(()=>{S.value;const x=N.value;if(!x||M.value||!t.editor.api.value||t.editor.mode.value!=="edit"||F.value)return null;const P=t.editor.flowModel.value.nodes[x];if(!P)return null;const H=t.editor.api.value.overlay.getNodeScreenRect(x);if(!H)return null;const K=z(P);return K.showActions===!1?null:{node:P,position:{x:H.x+H.width,y:H.y+H.height+4},behavior:K}}),p=s.computed(()=>{if(S.value,!t.editor.api.value||t.editor.mode.value!=="edit")return null;const x=G.value;if(x.nodeIds.length+x.edgeIds.length===0)return null;const I=t.editor.api.value.getSelectionBounds(x);if(!I)return null;const P=We(x,t.editor.flowModel.value,z);return{position:{x:I.x+I.width,y:I.y+I.height+4},canDelete:P.nodeIds.length>0||P.edgeIds.length>0}}),m=s.ref(),y=Ut({editor:t.editor,quickAddProp:s.computed(()=>t.quickAdd),isDraggingNode:M,nodeHover:E,isSelectionModeActive:F,viewportVersion:S,getNodeBehavior:z,getInsertGap:()=>d.value.insertGap,closePopover:()=>m.value?.closePopover()}),k=y.data,T=y.handleOpen,V=y.handleStartDrag;function J(){y.handleClose(),E.leaveOverlay(200),y.leave()}const D=y.handleOverlayEnter,_=y.handleOverlayLeave,C=y.handleInsert,B=Xt({editor:t.editor,edgeDropProp:s.computed(()=>t.edgeDrop)}),$=Kt(t.editor);function j(x,I){$.handleNodeAction(x,I,d.value.insertGap)&&(N.value=null)}function ee(x){x==="delete"&&$.deleteSelection(G.value)}function W(x){if(t.editor.mode.value!=="edit")return;if((x.metaKey||x.ctrlKey)&&(x.key==="z"||x.key==="Z")){if(x.shiftKey){if(!t.toolbarInclude?.includes("redo"))return;t.editor.history.redo()}else{if(!t.toolbarInclude?.includes("undo"))return;t.editor.history.undo()}x.preventDefault();return}t.editor._pluginManager.dispatchKeyboardShortcut(x)&&(x.preventDefault(),x.stopPropagation())}function U(x,I){const P=c,H=K=>{const oe=P.isRubberbandEnabled?.()??!1;oe&&P.disableRubberband?.(),K?c.enablePanning():c.disablePanning(),oe&&P.enableRubberband?.()};x&&I?(P.enableSelection?.(),E.reset(),y.quickAddNodeId.value=null,y.quickAddPopoverOpen.value=!1,h?.remove(),H(!1),P.enableRubberband?.()):(P.disableRubberband?.(),H(!0),P.disableSelection?.(),P.cleanSelection?.())}function ie(x){c.on("node:move",({node:I})=>{M.value=!0;const P=t.editor.flowModel.value.nodes[I.id];P&&z(P).bringToFrontOnDrag===!1||I.toFront?.()}),c.on("node:moved",()=>{M.value=!1}),c.on("node:mouseenter",({node:I})=>{if(F.value){N.value=null,y.quickAddNodeId.value=null,x.hideNodePorts(I);return}E.enter(I.id);const P=t.editor.flowModel.value.nodes[I.id];if(P&&z(P).showPorts===!1){y.mergedConfig.value.enabled&&y.enter(I.id);return}y.mergedConfig.value.enabled&&y.enter(I.id)||x.showNodePorts(I)}),c.on("node:mouseleave",({node:I})=>{if(F.value){x.hideNodePorts(I);return}const P=t.editor.flowModel.value.nodes[I.id];let H=100;P&&z(P).actionsOffset&&(H=300),E.leave(H),y.mergedConfig.value.enabled?y.quickAddNodeId.value===I.id&&!y.quickAddPopoverOpen.value?y.leave():y.quickAddNodeId.value!==I.id&&x.hideNodePorts(I):x.hideNodePorts(I)})}function ne(x){c.on("edge:added",({edge:I})=>{let P;if(t.getConnectionExcludedNodeIds&&!I.getTargetCell()){const H=I.getSourceCell();if(H){const K=t.getConnectionExcludedNodeIds(H.id);P=K instanceof Set?K:new Set(K)}}x.handleEdgeAdded(I,P)}),c.on("edge:connected",()=>{x.handleEdgeConnected()}),c.on("edge:removed",({edge:I})=>{x.handleEdgeRemoved(I.id),h.handleEdgeRemoved(I.id)}),c.on("edge:mouseenter",({edge:I,e:P})=>{const H=l.getHoveredEdgeId();l.setHoveredEdge(I.id),H&&H!==I.id&&l.refreshSingleEdgeStyle(H),l.refreshSingleEdgeStyle(I.id),t.editor.mode.value==="edit"&&!F.value&&x.canShowEdgeTool()&&h.show(I.id,P)}),c.on("edge:mouseleave",({edge:I})=>{l.setHoveredEdge(null),l.refreshSingleEdgeStyle(I.id),h.remove()}),c.on("edge:click",({edge:I,e:P})=>{P.target?.closest?.(".flow-canvas-edge-delete-tool")&&t.editor.mode.value==="edit"&&(h.remove(),t.editor.executeCommand({id:X(),source:"user:toolbar",label:"删除连线",timestamp:Date.now(),commands:[{type:"edge.remove",edgeId:I.id}]}))}),f=I=>h.move(I),c.container.addEventListener("mousemove",f)}function le(){b=x=>{if(!N.value&&!y.quickAddNodeId.value)return;const I=x.target;if(I?.closest?.(".x6-node")||I?.closest?.(".flow-canvas-node-actions")||I?.closest?.(".flow-canvas-quick-add")){E.cancelLeave(),y.cancelLeave();return}E.leave(180),y.quickAddPopoverOpen.value||y.leave()},i.value?.addEventListener("mousemove",b),A=()=>{E.reset(),y.quickAddPopoverOpen.value||(y.quickAddNodeId.value=null)},i.value?.addEventListener("mouseleave",A),i.value?.addEventListener("keydown",W)}function Ee(){s.watch(()=>t.editor.flowModel.value,x=>l.syncFlowModel(x)),s.watch([()=>t.editor.mode.value,()=>t.editor.selectionMode.value],([x,I])=>{U(x==="edit",I)},{immediate:!0})}s.onMounted(()=>{if(!a.value)return;const x=new Set(["model","container"]),I={};if(t.graphOptions)for(const[L,Z]of Object.entries(t.graphOptions)){if(x.has(L)){console.warn(`[flow-canvas] graphOptions.${L} is managed by the engine and will be ignored`);continue}I[L]=Z}c=new at.Graph({container:a.value,autoResize:!0,background:{color:"#edf2fc"},grid:{visible:!0,size:20,type:"dot",args:{color:"#C1CADB",thickness:2}},highlighting:{magnetAdsorbed:{name:"className",args:{className:"flow-canvas-magnet-adsorbed"}}},panning:{enabled:!0},mousewheel:{enabled:!0,modifiers:["ctrl","meta"]},interacting:{nodeMovable(L){return L.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 Zt(this,t.editor.schema)}},...I}),v=new Bt,l=new Pt(c,t.editor.schema,v,L=>t.editor._pluginManager.collectNodeDecorations(L),L=>t.editor._pluginManager.collectEdgeDecorations(L),()=>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 P=Rt(c),H=zt({graph:c,overlayManager:P,executeCommand:L=>t.editor.executeCommand(B.tryExpandForEdgeDrop(L)),schema:t.editor.schema,flowModel:t.editor.flowModel,getNodeBehavior:z,idGenerator:t.editor.idGenerator,defaultInsertGap:t.nodeActions?.insertGap,getContextMenuItems:L=>t.editor._pluginManager.collectContextMenuItems(L),onHighlightChange:(L,Z)=>{l.setHighlightedNodes(L);const re=l.setHighlightedEdges(Z);l.refreshNodeHighlights();const Q=new Set(Z);for(const ae of re)Q.has(ae)||l.refreshSingleEdgeStyle(ae);for(const ae of Q)re.has(ae)||l.refreshSingleEdgeStyle(ae)},resolveNodeShape:L=>{const Z=t.editor.schema.nodeTypes[L];if(!Z)return null;const re=v.registerNodeType(L,Z.component),Q=Z.getSize({id:"",type:L,position:{x:0,y:0}});return{shapeName:re,width:Q.width,height:Q.height}}});t.editor.api.value=H;const K={flowModel:t.editor.flowModel,history:t.editor.history,schema:t.editor.schema,mode:t.editor.mode,idGenerator:t.editor.idGenerator,executeCommand:t.editor.executeCommand,selectionMode:t.editor.selectionMode,api:H,overlay:P,graph:c};t.editor._pluginManager.attachRuntime(K);const oe=t.editor._pluginManager.collectExtendedApi();Object.assign(t.editor.extendedApi,oe),t.editor._emitUiEvent=L=>{t.editor._pluginManager.dispatchUiEvent(L),r("ui-event",L)},g=new Tt(c,L=>{(L.type==="node.click"||L.type==="node.dblclick"||L.type==="node.contextmenu")&&E.enter(L.nodeId),t.editor._emitUiEvent(L)},L=>{if(l.isSyncing)return;const Z=B.tryExpandForEdgeDrop(L);if(t.editor.executeCommand(Z).status!=="applied"){for(const Q of Z.commands)if(Q.type==="edge.add"){const ae=c.getCellById(Q.edge.id);ae&&c.removeCell(ae)}}},t.editor.flowModel,t.editor.idGenerator),h=Ht(c);const Y=Gt(c);y.attachRuntime(c,L=>Y.hideNodePorts(L)),B.attachRuntime(c),ie(Y),ne(Y),R=to(c.container);let de=new Set,ce=new Set;c.on("selection:changed",()=>{const L=je(c.getSelectedCells?.()??[]),Z=new Set(L.nodeIds);oo(c,de,Z),de=Z,G.value=L,t.editor._pluginManager.dispatchSelectionChange(L),r("ui-event",{type:"selection.change",nodeIds:L.nodeIds,edgeIds:L.edgeIds}),l.refreshNodeHighlights();const re=new Set(L.edgeIds);for(const Q of ce)re.has(Q)||l.refreshSingleEdgeStyle(Q);for(const Q of re)ce.has(Q)||l.refreshSingleEdgeStyle(Q);ce=re});const ke=()=>{S.value++};c.on("translate",ke),c.on("scale",ke),c.on("resize",ke),le(),l.syncFlowModel(t.editor.flowModel.value),Ee()});function fe(){E.reset(),y.quickAddNodeId.value=null,y.quickAddPopoverOpen.value=!1}return e({resetHoverState:fe}),s.onBeforeUnmount(()=>{E.cleanup(),y.cleanup(),B.cleanup(),h?.remove(),f&&c?.container?.removeEventListener("mousemove",f),b&&i.value?.removeEventListener("mousemove",b),A&&i.value?.removeEventListener("mouseleave",A),R?.(),i.value?.removeEventListener("keydown",W),t.editor._pluginManager.detachRuntime(),t.editor.api.value=null;for(const x of Object.keys(t.editor.extendedApi))delete t.editor.extendedApi[x];g?.dispose(),l?.dispose(),v?.dispose(),c?.dispose()}),(x,I)=>(s.openBlock(),s.createElementBlock("div",{ref_key:"rootRef",ref:i,class:s.normalizeClass(["flow-canvas-runtime-core",{"flow-canvas-runtime-core--selection-mode":F.value}]),tabindex:"0"},[s.createElementVNode("div",{ref_key:"containerRef",ref:a,class:"flow-canvas-runtime-core__graph"},null,512),s.createElementVNode("div",fo,[(s.openBlock(!0),s.createElementBlock(s.Fragment,null,s.renderList(w.value,P=>(s.openBlock(),s.createElementBlock("div",{key:`badge-${P.nodeId}`,class:"flow-canvas-runtime-core__badge",style:s.normalizeStyle({left:`${P.x}px`,top:`${P.y}px`,backgroundColor:P.badge.color})},s.toDisplayString(P.badge.text),5))),128)),s.unref(k)?(s.openBlock(),s.createBlock(Ke,{key:0,ref_key:"quickAddPopoverRef",ref:m,node:s.unref(k).node,"port-position":s.unref(k).portPosition,"auto-pan-on-open":s.unref(y).mergedConfig.value.autoPanOnOpen,"auto-pan-padding":s.unref(y).mergedConfig.value.autoPanPadding,onOpen:s.unref(T),onClose:J,onStartDrag:s.unref(V),onViewportOverflowRight:s.unref(y).handlePopoverViewportOverflow,onMouseenter:s.unref(D),onMouseleave:s.unref(_)},{default:s.withCtx(()=>[s.renderSlot(x.$slots,"quick-add-panel",{node:s.unref(k).node,api:n.editor.api.value,insertNodeToRight:P=>s.unref(C)(s.unref(k).node.id,P),closePopover:()=>m.value?.closePopover()},void 0,!0)]),_:3},8,["node","port-position","auto-pan-on-open","auto-pan-padding","onOpen","onStartDrag","onViewportOverflowRight","onMouseenter","onMouseleave"])):s.createCommentVNode("",!0),u.value?(s.openBlock(),s.createBlock(Xe,{key:1,node:u.value.node,position:u.value.position,config:d.value,behavior:u.value.behavior,"actions-offset":u.value.behavior.actionsOffset,onAction:j,onMouseenter:s.unref(O),onMouseleave:q},null,8,["node","position","config","behavior","actions-offset","onMouseenter"])):s.createCommentVNode("",!0),p.value?(s.openBlock(),s.createBlock(uo,{key:2,position:p.value.position,"can-delete":p.value.canDelete,onAction:ee},null,8,["position","can-delete"])):s.createCommentVNode("",!0)])],2))}}),po=se(go,[["__scopeId","data-v-84584822"]]),ho={class:"flow-canvas-node-palette"},vo=["data-node-type"],mo={class:"flow-canvas-node-palette__item-label"},yo=s.defineComponent({__name:"canvas-node-palette",props:{editor:{},items:{}},setup(n){const e=n,o=s.ref(),t=s.computed(()=>e.items?e.items:Object.keys(e.editor.schema.nodeTypes).map(r=>({type:r,label:r.charAt(0).toUpperCase()+r.slice(1)})));return s.watch([()=>e.editor.api.value,t,o],([r,i,a],c,l)=>{if(!r||!a)return;const v=[];for(const g of i){const h=a.querySelector(`[data-node-type="${g.type}"]`);if(!h)continue;const f=r.registerDndSource(h,()=>({id:X(),type:g.type,label:g.label,position:{x:0,y:0}}));v.push(f)}l(()=>{for(const g of v)g()})},{flush:"post"}),(r,i)=>(s.openBlock(),s.createElementBlock("div",ho,[s.createElementVNode("div",{ref_key:"listRef",ref:o,class:"flow-canvas-node-palette__list"},[(s.openBlock(!0),s.createElementBlock(s.Fragment,null,s.renderList(t.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",mo,s.toDisplayString(a.label),1)],8,vo))),128))],512)]))}}),Ye=se(yo,[["__scopeId","data-v-300314b7"]]),wo={class:"flow-canvas-layout"},bo={class:"flow-canvas-layout__main"},Eo={class:"flow-canvas-layout__content"},ko={key:0,class:"flow-canvas-layout__footer"},Co=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(n){return(e,o)=>(s.openBlock(),s.createElementBlock("div",wo,[!n.hideSidebar&&(e.$slots.sidebar||n.editor)?(s.openBlock(),s.createElementBlock("aside",{key:0,class:s.normalizeClass(["flow-canvas-layout__sidebar",{"is-collapsed":n.sidebarCollapsed}]),style:s.normalizeStyle({width:n.sidebarCollapsed?"0px":`${n.sidebarWidth}px`})},[s.renderSlot(e.$slots,"sidebar",{},()=>[n.editor?(s.openBlock(),s.createBlock(Ye,{key:0,editor:n.editor,items:n.paletteItems},null,8,["editor","items"])):s.createCommentVNode("",!0)],!0)],6)):s.createCommentVNode("",!0),s.createElementVNode("div",bo,[s.createElementVNode("div",Eo,[s.renderSlot(e.$slots,"default",{},void 0,!0)]),!n.hideFooter&&e.$slots.footer?(s.openBlock(),s.createElementBlock("div",ko,[s.renderSlot(e.$slots,"footer",{},void 0,!0)])):s.createCommentVNode("",!0)])]))}}),xo=se(Co,[["__scopeId","data-v-26f35b6b"]]),Oe=typeof navigator<"u"&&/Mac|iPod|iPhone|iPad/.test(navigator.platform??navigator.userAgent),Io=["undo","redo"];function Ze(n){const e=new Set(n?.include),o=new Set(Io.filter(l=>!e.has(l))),t=[{id:"undo",type:"undo",group:"history",icon:"flow-canvas-icon canvas-undo",description:"撤销",shortcut:Oe?["⌘","Z"]:["Ctrl","Z"],order:10},{id:"redo",type:"redo",group:"history",icon:"flow-canvas-icon canvas-redo",description:"重做",shortcut:Oe?["⇧","⌘","Z"]:["Ctrl","Shift","Z"],order:11}],r=[{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:"export",type:"export",group:"tools",icon:"flow-canvas-icon canvas-xiazai",description:"下载",order:24}],i=[{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[...[...t,...r].filter(l=>!o.has(l.type)),...i,...a]}const So={class:"flow-canvas-toolbar"},No={key:0,class:"flow-canvas-toolbar__separator"},Mo={class:"flow-canvas-toolbar__group"},Do={key:0,class:"flow-canvas-toolbar__zoom-display"},Ao=["data-toolbar-id","data-toolbar-type","disabled","onClick","onMouseenter"],_o=["textContent"],Po={key:0,class:"flow-canvas-toolbar-tooltip__kbd"},Bo=s.defineComponent({__name:"canvas-toolbar",props:{items:{},exclude:{},include:{},editor:{}},setup(n){const e=new Set(["undo","redo","select","auto-layout","search","minimap","export"]),o=new Set(["select","search","minimap"]);function t(u){return u.id.startsWith("plugin:")||u.type==="custom"}function r(u){return u!=="custom"&&o.has(u)}const i=n,a=s.computed(()=>{if(i.items)return i.items;const u=Ze({include:i.include}),p=i.editor.toolbarItems.value,m=new Set(i.exclude??[]),y=new Map;for(const k of u)y.set(k.id,k);for(const k of p){const T=y.get(k.id);T?y.set(k.id,{...T,...k,order:T.order,group:T.group}):t(k)&&y.set(k.id,k)}return[...y.values()].filter(k=>k.type==="custom"||!e.has(k.type)?!0:!m.has(k.type)).sort((k,T)=>(k.order??0)-(T.order??0))}),c=s.ref(1),l=s.ref(null),v=s.ref(null),g=s.ref(!1);let h=null;s.watch(()=>i.editor.api.value,u=>{h?.(),h=null,u&&(c.value=u.getZoom(),h=u.onGraphEvent("scale",()=>{c.value=u.getZoom()}))},{immediate:!0});const f=s.reactive({visible:!1,text:"",shortcut:[],x:0,y:0});function b(u,p){if(!p.description)return;const y=u.currentTarget.getBoundingClientRect();f.text=p.description,f.shortcut=p.shortcut??[],f.visible=!0,s.nextTick(()=>{const k=l.value?.offsetWidth??0,T=l.value?.offsetHeight??0;f.x=y.left+y.width/2-k/2,f.y=y.top-T-6})}function A(){f.visible=!1,l.value=null}s.onScopeDispose(()=>{h?.()});const R=s.computed(()=>`${Math.round(c.value*100)}%`),E=s.computed(()=>i.editor.api.value?{api:i.editor.api.value,flowModel:i.editor.flowModel.value,history:i.editor.history,mode:i.editor.mode.value}:null);function N(u){return u.visible===!1?!1:typeof u.visible=="function"?E.value?u.visible(E.value):!1:!0}function M(u){return typeof u.active=="function"?E.value?u.active(E.value):!1:u.active!==void 0?u.active:u.type==="select"?i.editor.selectionMode.value:!1}const O=s.computed(()=>{const u=d.value.filter(m=>r(m.type)&&M(m));if(u.length===0)return null;const p=v.value;return p&&u.some(m=>m.type===p)?p:u[0]?.type??null});function q(u){return r(u.type)?O.value===u.type:M(u)}function S(u){return!E.value||u.disabled===!0?!0:typeof u.disabled=="function"?u.disabled(E.value):u.type==="undo"?!i.editor.history.canUndo.value:u.type==="redo"?!i.editor.history.canRedo.value:u.type==="export"?g.value:!1}function G(u){if(!(!E.value||!r(u.type)||!M(u))){if(u.type==="select"){i.editor.setSelectionMode(!1);return}u.onClick?.(E.value)}}function z(u){if(r(u.type))for(const p of d.value)!r(p.type)||p.id===u.id||G(p)}function F(u){if(!E.value||S(u))return;if(r(u.type)&&(v.value=u.type,z(u)),u.onClick){u.onClick(E.value);return}const{api:p}=E.value;switch(u.type){case"undo":i.editor.history.undo();break;case"redo":i.editor.history.redo();break;case"zoom-in":p.zoomIn(),c.value=p.getZoom();break;case"zoom-out":p.zoomOut(),c.value=p.getZoom();break;case"fit":p.zoomToFit();break;case"reset":p.zoomTo(1),p.scrollToOrigin(),c.value=1;break;case"export":if(g.value)break;g.value=!0,p.exportAsImage().then(m=>{const y=URL.createObjectURL(m),k=document.createElement("a");k.href=y,k.download="canvas-export.png",k.click(),URL.revokeObjectURL(y)}).catch(m=>{console.warn("[flow-canvas] Export failed:",m)}).finally(()=>{g.value=!1});break;case"select":i.editor.setSelectionMode(!i.editor.selectionMode.value);break;case"auto-layout":i.editor._emitUiEvent({type:"toolbar.auto-layout"});break;case"search":case"minimap":console.warn(`[flow-canvas] "${u.type}" toolbar item has no built-in handler. Provide an onClick callback.`);break;default:u.type!=="custom"&&console.warn(`[flow-canvas] No default handler for toolbar type "${u.type}". Provide an onClick handler.`);break}}const d=s.computed(()=>a.value.filter(N)),w=s.computed(()=>{const u=new Map,p=[];for(const m of d.value){const y=m.group??"default";u.has(y)||(u.set(y,[]),p.push(y)),u.get(y).push(m)}return p.map(m=>({name:m,items:u.get(m)})).filter(m=>m.items.length>0)});return(u,p)=>(s.openBlock(),s.createElementBlock("div",So,[(s.openBlock(!0),s.createElementBlock(s.Fragment,null,s.renderList(w.value,(m,y)=>(s.openBlock(),s.createElementBlock(s.Fragment,{key:m.name},[y>0?(s.openBlock(),s.createElementBlock("div",No)):s.createCommentVNode("",!0),s.createElementVNode("div",Mo,[(s.openBlock(!0),s.createElementBlock(s.Fragment,null,s.renderList(m.items,k=>(s.openBlock(),s.createElementBlock(s.Fragment,{key:k.id},[k.type==="zoom-display"?(s.openBlock(),s.createElementBlock("span",Do,s.toDisplayString(R.value),1)):(s.openBlock(),s.createElementBlock("button",{key:1,type:"button",class:s.normalizeClass(["flow-canvas-toolbar__btn",{"is-disabled":S(k),"is-active":q(k),"is-exporting":k.type==="export"&&g.value}]),"data-toolbar-id":k.id,"data-toolbar-type":k.type,disabled:S(k),onClick:T=>F(k),onMouseenter:T=>b(T,k),onMouseleave:A},[k.component?(s.openBlock(),s.createBlock(s.resolveDynamicComponent(k.component),{key:0})):k.icon?(s.openBlock(),s.createElementBlock("i",{key:1,class:s.normalizeClass(k.icon)},null,2)):(s.openBlock(),s.createElementBlock("span",{key:2,class:"flow-canvas-toolbar__text",textContent:s.toDisplayString(k.text??k.description??k.id)},null,8,_o))],42,Ao))],64))),128))])],64))),128)),(s.openBlock(),s.createBlock(s.Teleport,{to:"body"},[f.visible?(s.openBlock(),s.createElementBlock("div",{key:0,ref_key:"tooltipRef",ref:l,class:"flow-canvas-toolbar-tooltip",style:s.normalizeStyle({left:`${f.x}px`,top:`${f.y}px`})},[s.createElementVNode("span",null,s.toDisplayString(f.text),1),f.shortcut.length?(s.openBlock(),s.createElementBlock("kbd",Po,[(s.openBlock(!0),s.createElementBlock(s.Fragment,null,s.renderList(f.shortcut,(m,y)=>(s.openBlock(),s.createElementBlock("span",{key:y},s.toDisplayString(m),1))),128))])):s.createCommentVNode("",!0),p[0]||(p[0]=s.createElementVNode("div",{class:"flow-canvas-toolbar-tooltip__arrow"},null,-1))],4)):s.createCommentVNode("",!0)]))]))}}),To=se(Bo,[["__scopeId","data-v-904248f4"]]),Ro={class:"flow-canvas-default-node__ep-label"},Lo={key:1,class:"flow-canvas-default-node__diamond flow-canvas-highlight-target"},Oo={key:2,class:"flow-canvas-default-node__task-label"},$o=s.defineComponent({__name:"default-node",setup(n){const o=s.inject("getNode")?.(),t=s.computed(()=>o?.getData?.()??null),r=s.computed(()=>t.value?.label||t.value?.type||""),i={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"]),c=new Set(["parallel-gateway","branch-gateway","converge-gateway","conditional-parallel-gateway"]),l=s.computed(()=>{const g=t.value?.type??"";return a.has(g)?"endpoint":c.has(g)?"gateway":"task"}),v=s.computed(()=>i[t.value?.type??""]??"");return(g,h)=>(s.openBlock(),s.createElementBlock("div",{class:s.normalizeClass(["flow-canvas-default-node",[`is-${l.value}`,{"flow-canvas-highlight-target":l.value!=="gateway"}]])},[l.value==="endpoint"?(s.openBlock(),s.createElementBlock(s.Fragment,{key:0},[v.value?(s.openBlock(),s.createElementBlock("i",{key:0,class:s.normalizeClass([["flow-canvas-icon",v.value],"flow-canvas-default-node__ep-icon"])},null,2)):s.createCommentVNode("",!0),s.createElementVNode("span",Ro,s.toDisplayString(r.value),1)],64)):l.value==="gateway"?(s.openBlock(),s.createElementBlock("div",Lo,[v.value?(s.openBlock(),s.createElementBlock("i",{key:0,class:s.normalizeClass([["flow-canvas-icon",v.value],"flow-canvas-default-node__gw-icon"])},null,2)):s.createCommentVNode("",!0)])):(s.openBlock(),s.createElementBlock("span",Oo,s.toDisplayString(r.value),1))],2))}}),Qe=se($o,[["__scopeId","data-v-f0e24a9f"]]),Fo={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}},$e=(n,e)=>({stroke:e.hovered?"#3a84ff":"#abb5cc",strokeWidth:2});function Fe(){return{attrs:{line:{stroke:"#abb5cc",strokeWidth:2,targetMarker:{name:"block",width:8,height:8}}}}}function Je(){return{manhattan:{router:{name:"manhattan",args:{padding:10,maxDirectionChange:90}},connector:{name:"rounded",args:{radius:8}},style:$e,x6EdgeConfig:Fe()},bezier:{connector:{name:"smooth"},style:$e,x6EdgeConfig:Fe()}}}function Vo(n){const e=n?.nodeTypes??Fo,o={},t=[];for(const[a,c]of Object.entries(e)){const l=c.width??150,v=c.height??50;o[a]={component:Qe,getSize:()=>({width:l,height:v}),getPorts:()=>Ue()},t.push({type:a,label:c.label??a,icon:c.icon})}const r={...Je(),...n?.edgeTypes},i=n?.defaultEdgeType??"manhattan";return{schema:{nodeTypes:o,defaultEdgeType:i,edgeTypes:r},paletteItems:t}}function zo(n){return{name:"connection-validator",priority:10,transformCommand(e,o,t){const r=new Set;for(const i of e.commands)i.type==="edge.remove"&&r.add(i.edgeId);for(const i of e.commands){if(i.type!=="edge.add"&&i.type!=="edge.reconnect")continue;const a=t.flowModel.value,c=i.type==="edge.add"?i.edge.source.nodeId:i.source?.nodeId,l=i.type==="edge.add"?i.edge.target.nodeId:i.target?.nodeId;if(!c||!l)continue;const v=a.nodes[c],g=a.nodes[l];if(!v||!g)continue;const h=i.type==="edge.add"?i.edge.source.portId:i.source?.portId,f=i.type==="edge.add"?i.edge.target.portId:i.target?.portId,b=h?v.ports?.find(M=>M.id===h):void 0,A=f?g.ports?.find(M=>M.id===f):void 0,R=i.type==="edge.reconnect"?i.edgeId:void 0,E=Object.values(a.edges).filter(M=>M.id!==R&&!r.has(M.id)),N=n({flowModel:a,sourceNode:v,targetNode:g,sourcePort:b,targetPort:A,existingEdges:E});if(!N.valid)return{rejected:!0,reason:N.reason??"Connection validation failed",code:"validation_failed"}}return e}}}function qo(n){const{rubberband:e=!0,multiple:o=!0,movable:t=!0}=n??{};return{name:"selection",priority:90,attachRuntime(r){r.graph.use(new ct.Selection({enabled:!0,rubberband:e,multiple:o,movable:t,pointerEvents:"none",showNodeSelectionBox:!0,filter:i=>!(i.isNode()&&(i.getData?.()??{})._selectable===!1)}))}}}function Ho(n){const{tolerance:e=10,color:o="#3a84ff"}=n??{};let t=null;return{name:"snapline",priority:90,async attachRuntime(r){const{Snapline:i}=await import("@antv/x6-plugin-snapline");r.graph.use(new i({enabled:!0,tolerance:e,className:"flow-canvas-snapline"})),t=document.createElement("style"),t.textContent=`.flow-canvas-snapline line { stroke: ${o} !important; }`,document.head.appendChild(t)},detachRuntime(){t?.remove(),t=null}}}const Go={class:"flow-canvas-search-popover__input-box"},Uo=["value","placeholder"],jo={key:0,class:"flow-canvas-search-popover__no-result"},Wo={class:"flow-canvas-search-popover__counter"},Xo=["onMouseenter","onClick"],Ko={class:"flow-canvas-search-popover__item-label"},Yo=s.defineComponent({__name:"search-popover",props:{open:{type:Boolean},position:{},query:{},results:{},matchIndex:{default:-1},placeholder:{default:"搜索节点名称"},isAnchorTarget:{type:Function,default:void 0}},emits:["update:query","select","nextMatch","prevMatch","close"],setup(n,{emit:e}){const o=n,t=e,r=s.ref(null),i=s.ref(null),a=s.ref(-1);s.watch(()=>o.open,f=>{f&&(a.value=-1,s.nextTick(()=>{r.value?.focus(),r.value?.select()}))}),s.watch(()=>o.query,()=>{a.value=-1}),s.watch(()=>o.results.length,f=>{if(!f){a.value=-1;return}a.value>=f&&(a.value=-1)});function c(f){t("update:query",f.target.value)}function l(f){a.value=f}function v(){a.value=-1}function g(f){if(f.key==="Escape"){f.preventDefault(),t("close");return}if(f.key==="ArrowDown"){if(f.preventDefault(),!o.results.length)return;a.value=a.value<o.results.length-1?a.value+1:0;return}if(f.key==="ArrowUp"){if(f.preventDefault(),!o.results.length)return;a.value=a.value>0?a.value-1:o.results.length-1;return}if(f.key==="Enter"){if(f.preventDefault(),a.value>=0){const b=o.results[a.value];b&&t("select",b.id);return}f.shiftKey?t("prevMatch"):t("nextMatch")}}function h(f){if(!o.open)return;const b=f.target;b&&i.value?.contains(b)||o.isAnchorTarget?.(f.target)||t("close")}return s.onMounted(()=>{document.addEventListener("mousedown",h)}),s.onBeforeUnmount(()=>{document.removeEventListener("mousedown",h)}),(f,b)=>n.open?(s.openBlock(),s.createElementBlock("div",{key:0,ref_key:"panelRef",ref:i,class:"flow-canvas-search-popover",style:s.normalizeStyle({left:`${n.position.x}px`,top:`${n.position.y}px`,width:`${n.position.width}px`})},[s.createElementVNode("div",Go,[s.createElementVNode("input",{ref_key:"inputRef",ref:r,value:n.query,placeholder:n.placeholder,onInput:c,onKeydown:g},null,40,Uo),n.query?(s.openBlock(),s.createElementBlock(s.Fragment,{key:0},[n.results.length?(s.openBlock(),s.createElementBlock(s.Fragment,{key:1},[s.createElementVNode("button",{type:"button",class:"flow-canvas-search-popover__nav-btn","aria-label":"上一个",onClick:b[0]||(b[0]=A=>t("prevMatch"))},[...b[2]||(b[2]=[s.createElementVNode("svg",{viewBox:"0 0 16 16",width:"12",height:"12"},[s.createElementVNode("path",{d:"M10.3 12.3 6 8l4.3-4.3",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),s.createElementVNode("span",Wo,s.toDisplayString(n.matchIndex>=0?n.matchIndex+1:0)+" / "+s.toDisplayString(n.results.length),1),s.createElementVNode("button",{type:"button",class:"flow-canvas-search-popover__nav-btn","aria-label":"下一个",onClick:b[1]||(b[1]=A=>t("nextMatch"))},[...b[3]||(b[3]=[s.createElementVNode("svg",{viewBox:"0 0 16 16",width:"12",height:"12"},[s.createElementVNode("path",{d:"M5.7 3.7 10 8l-4.3 4.3",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])])],64)):(s.openBlock(),s.createElementBlock("span",jo,"无结果"))],64)):s.createCommentVNode("",!0),b[4]||(b[4]=s.createElementVNode("i",{class:"flow-canvas-icon canvas-search flow-canvas-search-popover__search-icon"},null,-1))]),n.query&&n.results.length?(s.openBlock(),s.createElementBlock("div",{key:0,class:"flow-canvas-search-popover__list-box",onMouseleave:v},[(s.openBlock(!0),s.createElementBlock(s.Fragment,null,s.renderList(n.results,(A,R)=>(s.openBlock(),s.createElementBlock("button",{key:A.id,type:"button",class:s.normalizeClass(["flow-canvas-search-popover__item",{"is-active":R===a.value,"is-matched":R===n.matchIndex}]),onMouseenter:E=>l(R),onClick:E=>t("select",A.id)},[s.createElementVNode("span",Ko,s.toDisplayString(A.label),1)],42,Xo))),128))],32)):s.createCommentVNode("",!0)],4)):s.createCommentVNode("",!0)}}),Zo=se(Yo,[["__scopeId","data-v-aca2b1c1"]]),Ve=282,Qo=4,Jo=300,ve="flow-canvas-node-ring-target--search-match",me="flow-canvas-node-ring-target--search-current",en="flow-canvas-node-ring-target";function tn(n){return n!==null}function on(n){const e=new Set;return n.map(o=>o?.trim()).filter(o=>!!o).filter(o=>{const t=o.toLowerCase();return e.has(t)?!1:(e.add(t),!0)})}function nn(n,e){const o=Math.max(8,window.innerWidth-e-8);return Math.min(Math.max(8,n),o)}function rn(n,e){const o=e?.getNodeMeta?.(n);if(o===null)return null;const t=o?.label?.trim()||n.label?.trim()||n.id,r=o?.subtitle?.trim()||void 0,i=on(o?.keywords??[n.label,r]);return i.length?{id:n.id,label:t,subtitle:r,keywords:i}:null}function sn(n){let e=null,o=null,t=null,r=null,i=null,a=null;const c=s.ref(!1),l=s.ref(""),v=s.ref({x:0,y:0,width:Ve}),g=s.ref(-1),h=s.computed(()=>e?Object.values(e.flowModel.value.nodes).map(p=>rn(p,n)).filter(tn):[]),f=s.computed(()=>{const p=l.value.trim().toLowerCase(),m=Math.max(1,n?.maxResults??Jo);return p?h.value.filter(y=>y.keywords.some(k=>k.toLowerCase().includes(p))).slice(0,m):h.value.slice(0,m)});function b(){return t?.querySelector('.flow-canvas-toolbar__btn[data-toolbar-type="search"]')}function A(){return b()?.closest(".flow-canvas-toolbar")}function R(){const p=A(),m=t?.getBoundingClientRect(),y=p?.getBoundingClientRect()??m;if(!y)return;const k=Math.max(Ve,Math.round(y.width));v.value={x:nn(y.left,k),y:y.bottom+Qo,width:k}}function E(p){if(!o)return null;const m=o.graph.getCellById(p);if(!m?.isNode())return null;const y=o.graph.findViewByCell(m)?.container;return y?y.querySelector(".flow-canvas-highlight-target")??y.querySelector(".flow-canvas-node-surface > :first-child"):null}function N(){if(!o)return;const p=o.graph.getNodes();for(const m of p){const y=E(m.id);y&&y.classList.remove(ve,me)}}function M(){if(!o)return;const p=l.value.trim().toLowerCase();if(!c.value||!p){N();return}const m=new Set(f.value.map(T=>T.id)),y=g.value>=0?f.value[g.value]?.id:null,k=o.graph.getNodes();for(const T of k){const V=E(T.id);V&&(V.classList.add(en),T.id===y?(V.classList.remove(ve),V.classList.add(me)):m.has(T.id)?(V.classList.remove(me),V.classList.add(ve)):V.classList.remove(ve,me))}}function O(p){if(!o)return;const m=f.value.findIndex(y=>y.id===p);m>=0&&(g.value=m),o.api.scrollToNode(p),M()}function q(){const p=f.value;if(p.length===0)return;const m=g.value<p.length-1?g.value+1:0;g.value=m,O(p[m].id)}function S(){const p=f.value;if(p.length===0)return;const m=g.value>0?g.value-1:p.length-1;g.value=m,O(p[m].id)}function G(){o&&(c.value=!0,R(),requestAnimationFrame(()=>R()))}function z(){c.value=!1,l.value="",g.value=-1,N()}function F(){if(c.value){z();return}G()}function d(p){const m=b();return!!(m&&p instanceof Node&&m.contains(p))}function w(){c.value&&R()}const u=s.defineComponent({name:"FlowCanvasSearchHost",setup(){return()=>s.h(Zo,{open:c.value,position:v.value,query:l.value,results:f.value,matchIndex:g.value,placeholder:n?.placeholder??"搜索节点名称",isAnchorTarget:d,"onUpdate:query":p=>{l.value=p,g.value=-1},onSelect:O,onNextMatch:q,onPrevMatch:S,onClose:z})}});return{name:"search",priority:90,install(p){e=p},attachRuntime(p){o=p,t=p.graph.container.closest(".flow-canvas-layout__content")??p.graph.container.parentElement,r=document.createElement("div"),r.className="flow-canvas-search-host",document.body.append(r),i=s.createApp(u),i.mount(r),a=s.watch(()=>[l.value,f.value.length],()=>{g.value=-1,M()}),window.addEventListener("resize",w),window.addEventListener("scroll",w,!0)},detachRuntime(){z(),a?.(),a=null,window.removeEventListener("resize",w),window.removeEventListener("scroll",w,!0),i?.unmount(),i=null,r?.remove(),r=null,t=null,o=null},dispose(){z(),a?.(),a=null,e=null},provideToolbarItems(){return[{id:"plugin:search",type:"search",icon:"flow-canvas-icon canvas-search",description:"搜索",group:"tools",order:22,active:()=>c.value,onClick:F}]}}}const ze=52,qe=16,et=4,an=40;function ln(n){const{mountRect:e,toolbarRect:o,fallbackLeft:t,fallbackTop:r,fallbackWidth:i,height:a}=n,c=n.offset??et;return!o||o.width<=0?{left:t,top:r,width:i,height:a}:{left:Math.round(o.left-e.left),top:Math.round(o.bottom-e.top+c),width:Math.round(o.width),height:a}}function cn(n){const e=document.createElement("div");e.className="flow-canvas-minimap",n.floating!==!1&&e.classList.add("flow-canvas-minimap--floating");const o=document.createElement("div");o.className="flow-canvas-minimap__host",e.append(o),Object.assign(e.style,{width:`${n.width}px`,height:`${n.height}px`}),n.floating!==!1&&Object.assign(e.style,{top:`${ze}px`,left:`${qe}px`});let t=null,r=n.defaultOpen??!1,i=null,a=null,c=null,l=null,v={width:n.width,height:n.height};function g(S,G){if(!t)return;const z=t;z.options.width=S,z.options.height=G,z.updatePaper(n.sourceGraph.container.clientWidth,n.sourceGraph.container.clientHeight)}function h(){if(n.floating===!1)return;const S=ln({mountRect:n.mountTarget.getBoundingClientRect(),toolbarRect:n.getToolbarElement?.()?.getBoundingClientRect()??null,fallbackLeft:qe,fallbackTop:ze,fallbackWidth:n.width,height:n.height,offset:n.panelOffset??et});v={width:S.width,height:S.height},Object.assign(e.style,{left:`${S.left}px`,top:`${S.top}px`,width:`${S.width}px`,height:`${S.height}px`}),g(S.width,S.height)}function f(){if(n.floating===!1||typeof ResizeObserver>"u")return;const S=n.getToolbarElement?.()??null;a||(a=new ResizeObserver(()=>{r&&(f(),h())})),l!==S&&(a.disconnect(),a.observe(n.mountTarget),S&&a.observe(S),l=S)}function b(){n.floating!==!1&&(h(),f(),c||(c=()=>{r&&(f(),h())},window.addEventListener("resize",c)))}function A(){c&&(window.removeEventListener("resize",c),c=null),a?.disconnect(),a=null,l=null}function R(){!n.onClickOutside||i||(i=S=>{const G=S.target;G&&e.contains(G)||S.target?.closest('[data-toolbar-type="minimap"]')||S.target?.closest(".flow-canvas-layout__content")||n.onClickOutside()},document.addEventListener("mousedown",i))}function E(){i&&(document.removeEventListener("mousedown",i),i=null)}function N(){t||(t=new dt.MiniMap({container:o,width:v.width,height:v.height,padding:n.contentPadding??an,scalable:!1}),n.sourceGraph.use(t))}function M(S){r=S,e.style.display=r?"":"none",r?(b(),N(),R(),requestAnimationFrame(()=>{r&&(f(),h())})):(E(),A())}function O(){M(r),n.mountTarget.appendChild(e)}function q(){E(),A(),t?.dispose(),t=null,e.remove()}return O(),{element:e,isOpen:()=>r,setOpen:M,toggle(){const S=!r;return M(S),S},destroy:q}}function dn(n){let e=null,o=null;const t=s.ref(!1);function r(){return o?.querySelector('.flow-canvas-toolbar__btn[data-toolbar-type="minimap"]')}function i(){return r()?.closest(".flow-canvas-toolbar")}function a(l){e?.setOpen(l),t.value=l}function c(){e&&(t.value=e.toggle())}return{name:"minimap",priority:90,attachRuntime(l){const v=l,g=n?.width??334,h=n?.height??180;o=v.graph.container.closest(".flow-canvas-layout__content")??v.graph.container.parentElement;const f=n?.container??o;f&&(e=cn({sourceGraph:l.graph,mountTarget:f,width:g,height:h,floating:!n?.container,defaultOpen:!1,getToolbarElement:n?.container?void 0:i,onClickOutside:()=>a(!1)}),a(!1))},detachRuntime(){e?.destroy(),e=null,o=null,t.value=!1},provideToolbarItems(){return[{id:"plugin:minimap",type:"minimap",icon:"flow-canvas-icon canvas-map",description:"小地图",group:"tools",order:23,active:()=>t.value,onClick:c}]}}}function un(){let n=null,e=0;return{name:"clipboard",priority:90,onKeyboardShortcut(o,t){const r=o.metaKey||o.ctrlKey;if(r&&o.key==="c"){const i=t.graph.getSelectedCells?.()??[];if(!i.length)return!1;const a=t.flowModel.value,c=new Set(i.filter(g=>g.isNode()).map(g=>g.id)),l=[...c].map(g=>a.nodes[g]).filter(Boolean);if(!l.length)return!1;const v=Object.values(a.edges).filter(g=>c.has(g.source.nodeId)&&c.has(g.target.nodeId));return n={nodes:l,edges:v},e=0,!0}if(r&&o.key==="v"){if(!n?.nodes.length)return!1;e++;const i=e*30,a=new Map,c=[];for(const l of n.nodes){const v=`${l.id}_cp${X().slice(0,6)}`;a.set(l.id,v),c.push({type:"node.add",node:{...l,id:v,position:{x:l.position.x+i,y:l.position.y+i},payload:l.payload?{...l.payload}:{},extensions:l.extensions?{...l.extensions}:void 0}})}for(const l of n.edges){const v=a.get(l.source.nodeId),g=a.get(l.target.nodeId);!v||!g||c.push({type:"edge.add",edge:{...l,id:`${l.id}_cp${X().slice(0,6)}`,source:{...l.source,nodeId:v},target:{...l.target,nodeId:g},labels:l.labels?.map(h=>({...h,id:`${h.id}_cp${X().slice(0,6)}`})),payload:l.payload?{...l.payload}:{}}})}return c.length&&t.executeCommand({id:X(),source:"user:keyboard",label:"粘贴",timestamp:Date.now(),commands:c}),!0}return!1}}}exports.CanvasConstraintError=te;exports.CanvasLayout=xo;exports.CanvasNodePalette=Ye;exports.CanvasRuntime=po;exports.CanvasSchemaError=He;exports.CanvasToolbar=To;exports.DefaultNode=Qe;exports.NodeActionsToolbar=Xe;exports.NodeQuickAddPopover=Ke;exports.applyCanvasCommand=Ie;exports.clipboardPlugin=un;exports.connectionValidatorPlugin=zo;exports.createBuiltinEdgeTypes=Je;exports.createCanvasHistory=Ge;exports.createDefaultSchema=Vo;exports.createDefaultToolbarItems=Ze;exports.createEmptyFlowModel=ut;exports.generateId=X;exports.minimapPlugin=dn;exports.searchPlugin=sn;exports.selectionPlugin=qo;exports.snaplinePlugin=Ho;exports.useCanvasEditor=Mt;
|
|
1
|
+
"use strict";var tt=Object.create;var Me=Object.defineProperty;var ot=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var rt=Object.getPrototypeOf,st=Object.prototype.hasOwnProperty;var it=(n,e,o,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of nt(e))!st.call(n,r)&&r!==o&&Me(n,r,{get:()=>e[r],enumerable:!(t=ot(e,r))||t.enumerable});return n};var Ce=(n,e,o)=>(o=n!=null?tt(rt(n)):{},it(e||!n||!n.__esModule?Me(o,"default",{value:n,enumerable:!0}):o,n));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("vue"),at=require("@antv/x6"),lt=require("@antv/x6-vue-shape"),ct=require("@antv/x6-plugin-selection"),dt=require("@antv/x6-plugin-minimap");function ut(){return{version:"1.0",nodes:{},edges:{}}}class ne extends Error{constructor(e){super(e),this.name="CanvasConstraintError"}}class He extends Error{constructor(e){super(e),this.name="CanvasSchemaError"}}function ye(n,e,o){if(e.length===0){if(o===void 0)return;if(typeof o!="object"||o===null||Array.isArray(o))throw new Error("Root value of payload/extensions/meta must be an object or undefined");return o}const t=n?{...n}:{};let r=t;for(let a=0;a<e.length-1;a++){const c=e[a],l=r[c];l&&typeof l=="object"&&!Array.isArray(l)?r[c]={...l}:r[c]={},r=r[c]}const i=e[e.length-1];return o===void 0?delete r[i]:r[i]=o,t}function Ie(n,e){switch(e.type){case"node.add":return ft(n,e.node);case"node.move":return pt(n,e.nodeId,e.position);case"node.remove":return gt(n,e.nodeId);case"node.update":return ht(n,e.nodeId,e.patch);case"node.set-payload":return vt(n,e.nodeId,e.path,e.value);case"node.set-extensions":return mt(n,e.nodeId,e.path,e.value);case"edge.add":return yt(n,e.edge);case"edge.remove":return wt(n,e.edgeId);case"edge.reconnect":return bt(n,e.edgeId,e.source,e.target);case"edge.update":return Et(n,e.edgeId,e.patch);case"edge.set-payload":return kt(n,e.edgeId,e.path,e.value);case"edge.label.update":return Ct(n,e.edgeId,e.labelId,e.patch);case"model.set-meta":return xt(n,e.path,e.value);default:throw new ne(`Unknown command type: ${e.type}`)}}function pe(n,e){const o=n.nodes[e];if(!o)throw new ne(`Node "${e}" does not exist`);return o}function ge(n,e){const o=n.edges[e];if(!o)throw new ne(`Edge "${e}" does not exist`);return o}function ue(n,e,o){const t=n.nodes[e.nodeId];if(!t)throw new ne(`${o} node "${e.nodeId}" does not exist`);if(e.portId&&t.ports&&!t.ports.some(i=>i.id===e.portId))throw new ne(`${o} port "${e.portId}" not found on node "${e.nodeId}"`)}function we(n,e,o){return{...n,nodes:{...n.nodes,[e]:o}}}function be(n,e,o){return{...n,edges:{...n.edges,[e]:o}}}function ft(n,e){if(n.nodes[e.id])throw new ne(`Node id "${e.id}" already exists`);return{...n,nodes:{...n.nodes,[e.id]:e}}}function pt(n,e,o){const t=pe(n,e);return we(n,e,{...t,position:o})}function gt(n,e){pe(n,e);const{[e]:o,...t}=n.nodes,r={};for(const[i,a]of Object.entries(n.edges))a.source.nodeId!==e&&a.target.nodeId!==e&&(r[i]=a);return{...n,nodes:t,edges:r}}function ht(n,e,o){const t=pe(n,e);return we(n,e,{...t,...o,id:t.id})}function vt(n,e,o,t){const r=pe(n,e),i=ye(r.payload,o,t);return we(n,e,{...r,payload:i})}function mt(n,e,o,t){const r=pe(n,e),i=ye(r.extensions,o,t);return we(n,e,{...r,extensions:i})}function yt(n,e){if(n.edges[e.id])throw new ne(`Edge id "${e.id}" already exists`);if(ue(n,e.source,"Source"),ue(n,e.target,"Target"),e.labels){const o=new Set;for(const t of e.labels){if(o.has(t.id))throw new ne(`Duplicate label id "${t.id}" in edge "${e.id}"`);o.add(t.id)}}return{...n,edges:{...n.edges,[e.id]:e}}}function wt(n,e){ge(n,e);const{[e]:o,...t}=n.edges;return{...n,edges:t}}function bt(n,e,o,t){const r=ge(n,e),i=o??r.source,a=t??r.target;return ue(n,i,"Source"),ue(n,a,"Target"),be(n,e,{...r,source:i,target:a})}function Et(n,e,o){const t=ge(n,e),r={...t,...o,id:t.id};return o.source&&ue(n,r.source,"Source"),o.target&&ue(n,r.target,"Target"),be(n,e,r)}function kt(n,e,o,t){const r=ge(n,e),i=ye(r.payload,o,t);return be(n,e,{...r,payload:i})}function Ct(n,e,o,t){const r=ge(n,e);if(!r.labels)throw new ne(`Edge "${e}" has no labels`);const i=r.labels.findIndex(c=>c.id===o);if(i===-1)throw new ne(`Label "${o}" not found in edge "${e}"`);const a=[...r.labels];return a[i]={...a[i],...t,id:o},be(n,e,{...r,labels:a})}function xt(n,e,o){const t=ye(n.meta,e,o);return{...n,meta:t}}function Ge(n,e){const o=e?.maxHistorySize??100,t=s.ref(n),r=[],i=[],a=s.ref(!1),c=s.ref(!1);function l(){a.value=r.length>0,c.value=i.length>0}function v(E){const N=t.value;let M=N;for(const O of E.commands)M=Ie(M,O);if(!E.skipHistory){const O=e?.excludeCommandFromHistory,q=O?E.commands.filter(S=>!O(S)):E.commands;if(q.length>0){const S=q.length<E.commands.length?{...E,commands:q}:E;r.push({snapshot:N,envelope:S}),r.length>o&&r.shift(),i.length=0}}return t.value=M,l(),M}function p(){const E=r.pop();if(!E)return null;i.push({snapshot:t.value,envelope:E.envelope});const N=e?.preserveMetaOnUndoRedo?{...E.snapshot,meta:t.value.meta}:E.snapshot;return t.value=N,l(),N}function h(){const E=i.pop();if(!E)return null;r.push({snapshot:t.value,envelope:E.envelope});const N=e?.preserveMetaOnUndoRedo?{...E.snapshot,meta:t.value.meta}:E.snapshot;return t.value=N,l(),N}function f(){r.length=0,i.length=0,l()}function b(){return t.value}function A(E){t.value=E,f()}function R(E,N){const M={id:`update-${Date.now()}`,source:"system:update",label:N??"更新模型",timestamp:Date.now(),commands:[]};r.push({snapshot:t.value,envelope:M}),r.length>o&&r.shift(),i.length=0,t.value=E,l()}return{currentFlowModel:t,execute:v,undo:p,redo:h,canUndo:a,canRedo:c,get undoStack(){return r.map(E=>E.envelope)},get redoStack(){return i.map(E=>E.envelope)},clear:f,createSnapshot:b,replaceFlowModel:A,updateFlowModel:R}}function It(n){return n!==null&&typeof n=="object"&&n.rejected===!0}class St{plugins=[];editorContext=null;runtimeCtx=null;runtimeVersion=0;install(e,o){this.plugins=[...e].sort((t,r)=>(t.priority??100)-(r.priority??100)),this.editorContext=o;for(const t of this.plugins)t.install?.(o)}attachRuntime(e){const o=++this.runtimeVersion;this.runtimeCtx=e;const t=this.createSafeRuntimeContext(e,o);for(const r of this.plugins)r.attachRuntime?.(t)}detachRuntime(){for(const e of[...this.plugins].reverse())e.detachRuntime?.();this.runtimeCtx=null}createSafeRuntimeContext(e,o){const t=this,r=new Proxy(e.graph,{get(i,a,c){const l=Reflect.get(i,a,c);return a==="use"&&typeof l=="function"?function(...p){if(t.runtimeVersion===o)return l.apply(i,p)}:l}});return{...e,graph:r}}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 o=e;for(const t of this.plugins){if(!t.transformCommand)continue;const r=this.createPreview(o),i=t.transformCommand(o,r,this.editorContext);if(i===null)return{rejected:!0,error:{code:"plugin_rejected",reason:"",source:t.name}};if(It(i))return{rejected:!0,error:{code:i.code??"plugin_rejected",reason:i.reason,source:t.name}};o=i}return{envelope:o}}afterCommand(e,o,t){if(this.editorContext)for(const r of this.plugins)r.afterCommand?.(e,o,t,this.editorContext)}dispatchUiEvent(e){if(this.runtimeCtx)for(const o of this.plugins)o.onUiEvent?.(e,this.runtimeCtx)}dispatchSelectionChange(e){if(this.runtimeCtx)for(const o of this.plugins)o.onSelectionChange?.(e,this.runtimeCtx)}dispatchKeyboardShortcut(e){if(!this.runtimeCtx)return!1;for(const o of this.plugins)if(o.onKeyboardShortcut?.(e,this.runtimeCtx))return!0;return!1}collectContextMenuItems(e){if(!this.runtimeCtx)return[];const o=[];for(const t of this.plugins){const r=t.onBlankContextMenu?.(e,this.runtimeCtx);r&&o.push(...r)}return o}collectToolbarItems(){if(!this.editorContext)return[];const e=new Map;for(const o of this.plugins){const t=o.provideToolbarItems?.(this.editorContext);if(t)for(const r of t)e.set(r.id,r)}return[...e.values()].sort((o,t)=>(o.order??0)-(t.order??0))}collectNodeDecorations(e){if(!this.editorContext)return;let o;for(const t of this.plugins){const r=t.decorateNode?.(e,this.editorContext);r&&(o=o?{...o,...r}:r)}return o}collectEdgeDecorations(e){if(!this.editorContext)return;let o;for(const t of this.plugins){const r=t.decorateEdge?.(e,this.editorContext);r&&(o=o?{...o,...r}:r)}return o}collectExtendedApi(){if(!this.runtimeCtx)return{};const e={};for(const o of this.plugins){const t=o.extendApi?.(this.runtimeCtx.api,this.runtimeCtx);t&&Object.assign(e,t)}return e}createPreview(e){const o=this.editorContext;return{previewFlowModel(t){const r=t??e.commands;let i=o.flowModel.value;for(const a of r)i=Ie(i,a);return i}}}}let Nt=0;function X(){const n=Date.now().toString(36),e=Math.random().toString(36).substring(2,8);return`${n}-${e}-${++Nt}`}const Se=()=>X();function Mt(n){const{schema:e,plugins:o=[],historyOptions:t}=n,r=n.idGenerator??Se,i={version:"1.0",...n.initialFlowModel},a=Ge(i,t),c=s.ref(n.mode??"edit"),l=s.ref(!1),v=s.ref(null),p=s.ref([]),h={},f=new St;function b(N,M,O,q="user:toolbar"){const S={id:`history-${Date.now()}`,source:q,label:N,timestamp:Date.now(),commands:[]};f.afterCommand(S,M,O),p.value=f.collectToolbarItems(),n.onCommandResult?.({status:"applied",envelope:S,flowModel:O}),n.onFlowModelChange?.({flowModel:O,prevFlowModel:M,envelope:S,source:q})}const A={execute:a.execute,undo(){const N=a.currentFlowModel.value,M=a.undo();return M&&b("撤销",N,M),M},redo(){const N=a.currentFlowModel.value,M=a.redo();return M&&b("重做",N,M),M},get canUndo(){return a.canUndo},get canRedo(){return a.canRedo},get undoStack(){return a.undoStack},get redoStack(){return a.redoStack},clear:a.clear,createSnapshot:a.createSnapshot,replaceFlowModel(N){const M=a.currentFlowModel.value;a.replaceFlowModel(N),b("替换 FlowModel",M,N,"system:replace")},updateFlowModel(N,M){const O=a.currentFlowModel.value;a.updateFlowModel(N,M),b(M??"更新 FlowModel",O,N,"system:update")}},R={flowModel:s.computed(()=>a.currentFlowModel.value),history:A,schema:e,mode:c,idGenerator:r,executeCommand:E,replaceFlowModel(N){A.replaceFlowModel(N)},updateFlowModel(N,M){A.updateFlowModel(N,M)},setMode(N){c.value=N},selectionMode:l,setSelectionMode(N){l.value=N},api:v,toolbarItems:p,extendedApi:h,_pluginManager:f,_emitUiEvent:N=>{f.dispatchUiEvent(N)}};f.install(o,{flowModel:R.flowModel,history:A,schema:e,mode:c,idGenerator:r,executeCommand:E}),p.value=f.collectToolbarItems(),s.onScopeDispose(()=>{f.dispose()});function E(N){const M=f.transformCommand(N);if("rejected"in M){const S={status:"rejected",envelope:N,error:M.error};return n.onCommandResult?.(S),S}const O=M.envelope,q=a.currentFlowModel.value;try{const S=a.execute(O),G={status:"applied",envelope:O,flowModel:S};return f.afterCommand(O,q,S),p.value=f.collectToolbarItems(),n.onCommandResult?.(G),n.onFlowModelChange?.({flowModel:S,prevFlowModel:q,envelope:O,source:O.source}),G}catch(S){if(S instanceof ne){const G={status:"invalid",envelope:O,error:{code:"constraint_violated",reason:S.message,source:"engine"}};return n.onCommandResult?.(G),G}throw S}}return R}const Dt=["top","right","bottom","left"];function Ue(){return Dt.map(n=>({id:n,group:n}))}function Ne(n,e){return e?.(n)??n.ports??Ue()}const xe=-1,At="flow-canvas-node-ring-target",De="flow-canvas-node-ring-target--decorated",Ae="flow-canvas-node-ring-target--pulse",_t="linear-gradient(135deg, #cadcfa 0%, #cee0ff 100%)";class Pt{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;prevEdgeDecorationMarkerIds=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;pendingDecorationRAFs=new Map;constructor(e,o,t,r,i,a){this.graph=e,this.schema=o,this.shapeRegistry=t,this.resolveNodeDecoration=r,this.resolveEdgeDecoration=i,this.resolveCanvasContext=a}syncFlowModel(e){if(!this.syncing){this.syncing=!0,this.lastModel=e;try{const o=this.resolveNodes(e),t=this.resolveEdges(e);this.syncNodes(o),this.syncEdges(t,e)}finally{this.syncing=!1}}}get isSyncing(){return this.syncing}saveNodeDefaultAttrs(e,o){const r=o.x6CellConfig?.attrs?.body;if(!r)return;const i={};let a=!1;r.stroke!==void 0&&(i.stroke=r.stroke,a=!0),r.strokeWidth!==void 0&&(i.strokeWidth=r.strokeWidth,a=!0),a&&this.nodeDefaultAttrs.set(e,i)}saveEdgeDefaultAttrs(e,o){const r=o?.x6EdgeConfig?.attrs?.line;if(!r)return;const i={};let a=!1;r.stroke!==void 0&&(i.stroke=r.stroke,a=!0),r.strokeWidth!==void 0&&(i.strokeWidth=r.strokeWidth,a=!0),r.strokeDasharray!==void 0&&(i.strokeDasharray=r.strokeDasharray,a=!0),a&&this.edgeDefaultAttrs.set(e,i)}restoreNodeAttr(e,o,t){const r=this.nodeDefaultAttrs.get(e.id)?.[t];if(r!==void 0)e.setAttrByPath(o,r);else{const i=t==="stroke"?"none":0;e.setAttrByPath(o,i)}}restoreEdgeAttr(e,o,t){const r=this.edgeDefaultAttrs.get(e.id)?.[t];r!==void 0?this.setEdgeAttrIfChanged(e,o,r):e.attr(o)!==void 0&&e.removeAttrByPath(o)}setEdgeAttrIfChanged(e,o,t){const r=e.attr(o),i=typeof r=="object"&&r!==null,a=typeof t=="object"&&t!==null;r!==t&&(i&&a&&JSON.stringify(r)===JSON.stringify(t)||e.setAttrByPath(o,t))}getNodeRingTarget(e){return e?e.querySelector(".flow-canvas-highlight-target")??e.querySelector(".flow-canvas-node-surface > :first-child"):null}syncEdgeMarker(e,o,t){const i=o?.x6EdgeConfig?.attrs?.line?.[t],a=`line/${t}`;e.removeAttrByPath(a),i!==void 0&&e.setAttrByPath(a,i)}getEdgeMarkerConfig(e,o){const r=e?.x6EdgeConfig?.attrs?.line?.[o];if(r)return typeof r=="string"?{name:r}:{...r}}applyEdgeMarkerDecoration(e,o,t,r){if(!r){this.prevEdgeDecorationMarkerIds.has(e.id)&&(this.syncEdgeMarker(e,o,t),this.prevEdgeDecorationMarkerIds.delete(e.id));return}const i=this.getEdgeMarkerConfig(o,t)??{name:"block",width:8,height:8};this.setEdgeAttrIfChanged(e,`line/${t}`,{...i,stroke:r,fill:r}),this.prevEdgeDecorationMarkerIds.add(e.id)}dispose(){for(const e of this.pendingDecorationRAFs.values())cancelAnimationFrame(e);this.pendingDecorationRAFs.clear(),this.knownNodeIds.clear(),this.knownEdgeIds.clear()}resolveNodes(e){const o=new Map;for(const[t,r]of Object.entries(e.nodes)){const i=this.schema.nodeTypes[r.type];if(!i)throw new He(`Unknown node type "${r.type}" for node "${t}". 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(r.type,i.component),c=i.getSize(r),l=Ne(r,i.getPorts);o.set(t,{model:r,definition:i,shapeName:a,size:c,ports:l})}return o}resolveEdges(e){const o=new Map;for(const[t,r]of Object.entries(e.edges)){const i=r.type??this.schema.defaultEdgeType??"default",a=this.schema.edgeTypes?.[i];o.set(t,{model:r,definition:a})}return o}syncNodes(e){const o=new Set(e.keys());for(const t of this.knownNodeIds)if(!o.has(t)){const r=this.graph.getCellById(t);r&&this.graph.removeCell(r),this.knownNodeIds.delete(t),this.defaultHighlightedNodeIds.delete(t),this.prevNodeDecorationClasses.delete(t),this.prevNodeDecorationColors.delete(t),this.nodeDefaultAttrs.delete(t);const i=this.pendingDecorationRAFs.get(t);i&&(cancelAnimationFrame(i),this.pendingDecorationRAFs.delete(t))}for(const[t,r]of e){const i=this.graph.getCellById(t);i?this.updateExistingNode(i,r):this.addNewNode(t,r)}}updateExistingNode(e,o){const{model:t,size:r,ports:i,definition:a}=o;if(e.getData()?.type!==t.type){this.graph.removeCell(e),this.addNewNode(e.id,o);return}const l=e.getPosition();(l.x!==t.position.x||l.y!==t.position.y)&&e.setPosition(t.position.x,t.position.y);const v=e.getSize();(v.width!==r.width||v.height!==r.height)&&e.setSize(r.width,r.height,{silent:!0}),this.syncNodePorts(e,i),e.setData({...t}),this.applyNodeBehavior(e,t,a),this.applyNodeHighlightAndDecoration(e,t)}syncNodePorts(e,o){const t=e.getPorts(),r=new Set(o.map(a=>a.id)),i=new Set(t.map(a=>a.id));for(const a of t)a.id&&!r.has(a.id)&&e.removePort(a.id);for(const a of o)i.has(a.id)||e.addPort({id:a.id,group:a.group,...a.x6PortConfig})}addNewNode(e,o){const{model:t,shapeName:r,size:i,ports:a,definition:c}=o,l={id:t.id,shape:r,x:t.position.x,y:t.position.y,width:i.width,height:i.height,data:{...t},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(p=>({id:p.id,group:p.group,...p.x6PortConfig}))},...c.x6CellConfig};this.graph.addNode(l),this.knownNodeIds.add(e),this.saveNodeDefaultAttrs(e,c);const v=this.graph.getCellById(e);v&&(this.applyNodeBehavior(v,t,c),this.applyNodeHighlightAndDecoration(v,t),this.scheduleDecorationRetryIfNeeded(v))}scheduleDecorationRetryIfNeeded(e){const o=this.graph.findViewByCell(e)?.container;if(this.getNodeRingTarget(o))return;const t=e.id,r=this.pendingDecorationRAFs.get(t);r&&cancelAnimationFrame(r);const i=requestAnimationFrame(()=>{if(this.pendingDecorationRAFs.delete(t),!this.knownNodeIds.has(t))return;const a=this.lastModel?.nodes[t];if(!a)return;const c=this.graph.getCellById(t);c?.isNode()&&this.applyNodeHighlightAndDecoration(c,a)});this.pendingDecorationRAFs.set(t,i)}applyNodeBehavior(e,o,t){if(!t.getBehavior)return;const r=this.resolveCanvasContext?.();if(!r)return;const i=t.getBehavior(o,r);if(i.draggable!==void 0&&e.setProp("draggable",i.draggable,{silent:!0}),i.connectable!==void 0){const c=i.connectable?!0:i.targetable===!1?!1:"passive";for(const l of e.getPorts())e.setPortProp(l.id,"attrs/circle/magnet",c,{silent:!0})}if(i.showPorts!==void 0){const c=i.showPorts;for(const l of e.getPorts())e.setPortProp(l.id,"attrs/circle/visibility",c?"visible":"hidden",{silent:!0})}const a=e.getData()??{};i.deletable!==void 0&&a._deletable!==i.deletable&&e.setData({...a,_deletable:i.deletable},{silent:!0}),i.selectable!==void 0&&a._selectable!==i.selectable&&e.setData({...e.getData(),_selectable:i.selectable},{silent:!0})}syncEdges(e,o){const t=new Set(e.keys());for(const r of this.knownEdgeIds)if(!t.has(r)){const i=this.graph.getCellById(r);i&&this.graph.removeCell(i),this.knownEdgeIds.delete(r),this.defaultHighlightedEdgeIds.delete(r),this.prevEdgeDecorationClasses.delete(r),this.prevEdgeDecorationColors.delete(r),this.prevEdgeDecorationMarkerIds.delete(r),this.prevEdgeStyleIds.delete(r),this.edgeDefaultAttrs.delete(r)}for(const[r,i]of e){const a=this.graph.getCellById(r),{model:c,definition:l}=i;a?(this.updateExistingEdge(a,c,l,o),this.knownEdgeIds.has(r)||(this.knownEdgeIds.add(r),this.saveEdgeDefaultAttrs(r,l))):this.addNewEdge(r,c,l)}}updateExistingEdge(e,o,t,r){const i=e.getSource(),a=e.getTarget(),c=i.cell!==o.source.nodeId||i.port!==o.source.portId,l=a.cell!==o.target.nodeId||a.port!==o.target.portId;c&&e.setSource({cell:o.source.nodeId,port:o.source.portId}),l&&e.setTarget({cell:o.target.nodeId,port:o.target.portId});const p=(e.getData()?.type??void 0)!==(o.type??void 0);if(p){if(t?.router){const h=typeof t.router=="string"?{name:t.router}:t.router;e.setRouter(h)}if(t?.connector){const h=typeof t.connector=="string"?{name:t.connector}:t.connector;e.setConnector(h)}}(p||c||l)&&(this.syncEdgeMarker(e,t,"sourceMarker"),this.syncEdgeMarker(e,t,"targetMarker")),this.syncEdgeLabels(e,o),e.getZIndex()!==xe&&e.setZIndex(xe),e.setData({...o},{silent:!0}),this.applyEdgeStyleAndDecoration(e,o,t)}syncEdgeLabels(e,o){if(!o.labels?.length){e.getLabels().length>0&&e.setLabels([]);return}const t=o.labels.map(r=>({attrs:{label:{text:r.text??""}},position:r.position!=null?{distance:r.position}:void 0}));e.setLabels(t)}addNewEdge(e,o,t){const r={id:o.id,source:{cell:o.source.nodeId,port:o.source.portId},target:{cell:o.target.nodeId,port:o.target.portId},data:{...o},zIndex:xe};t?.router&&(r.router=typeof t.router=="string"?{name:t.router}:t.router),t?.connector&&(r.connector=typeof t.connector=="string"?{name:t.connector}:t.connector),t?.x6EdgeConfig&&Object.assign(r,t.x6EdgeConfig),o.labels?.length&&(r.labels=o.labels.map(a=>({attrs:{label:{text:a.text??""}},position:a.position!=null?{distance:a.position}:void 0}))),this.graph.addEdge(r),this.knownEdgeIds.add(e),this.saveEdgeDefaultAttrs(e,t);const i=this.graph.getCellById(e);i&&this.applyEdgeStyleAndDecoration(i,o,t)}refreshEdgeStyles(){if(this.lastModel)for(const[e,o]of Object.entries(this.lastModel.edges)){const t=this.graph.getCellById(e);if(!t?.isEdge())continue;const r=o.type??this.schema.defaultEdgeType??"default",i=this.schema.edgeTypes?.[r];this.applyEdgeStyleAndDecoration(t,o,i)}}refreshSingleEdgeStyle(e){if(!this.lastModel)return;const o=this.lastModel.edges[e];if(!o)return;const t=this.graph.getCellById(e);if(!t?.isEdge())return;const r=o.type??this.schema.defaultEdgeType??"default",i=this.schema.edgeTypes?.[r];this.applyEdgeStyleAndDecoration(t,o,i)}refreshNodeHighlights(){if(this.lastModel)for(const[e,o]of Object.entries(this.lastModel.nodes)){const t=this.graph.getCellById(e);t?.isNode()&&this.applyNodeHighlightAndDecoration(t,o)}}applyNodeHighlightAndDecoration(e,o){const t=this.highlightedNodeIds.has(e.id),r=this.resolveNodeDecoration?.(o),i=this.graph.findViewByCell(e)?.container,a=this.getNodeRingTarget(i),c=this.prevNodeDecorationClasses.get(e.id);c&&(i?.classList.remove(c),this.prevNodeDecorationClasses.delete(e.id)),r?.className&&(i?.classList.add(r.className),this.prevNodeDecorationClasses.set(e.id,r.className));const l=r?.borderColor,p=l??(t?"#3a84ff":void 0),h=this.prevNodeDecorationColors.has(e.id)||this.defaultHighlightedNodeIds.has(e.id);p?(e.setAttrByPath("body/stroke",p),e.setAttrByPath("body/strokeWidth",2)):h&&(this.restoreNodeAttr(e,"body/stroke","stroke"),this.restoreNodeAttr(e,"body/strokeWidth","strokeWidth")),a&&(a.classList.add(At),l?(a.classList.add(De),a.style.setProperty("--flow-canvas-node-decoration-ring-background",l),a.style.setProperty("--flow-canvas-node-decoration-ring-opacity","0.95")):(a.classList.remove(De),a.style.removeProperty("--flow-canvas-node-decoration-ring-background"),a.style.removeProperty("--flow-canvas-node-decoration-ring-opacity")),t?(a.classList.add(Ae),a.style.setProperty("--flow-canvas-node-pulse-ring-background",l??_t),a.style.setProperty("--flow-canvas-node-pulse-ring-opacity","0.95")):(a.classList.remove(Ae),a.style.removeProperty("--flow-canvas-node-pulse-ring-background"),a.style.removeProperty("--flow-canvas-node-pulse-ring-opacity"))),l?this.prevNodeDecorationColors.add(e.id):this.prevNodeDecorationColors.delete(e.id),t&&!l?this.defaultHighlightedNodeIds.add(e.id):this.defaultHighlightedNodeIds.delete(e.id)}getHoveredEdgeId(){return this.hoveredEdgeId}setHoveredEdge(e){this.hoveredEdgeId=e}setHighlightedNodes(e){this.highlightedNodeIds=new Set(e)}setHighlightedEdges(e){const o=this.highlightedEdgeIds;return this.highlightedEdgeIds=new Set(e),o}applyEdgeStyleAndDecoration(e,o,t){const r=this.highlightedEdgeIds.has(e.id),i=this.resolveEdgeDecoration?.(o),a=this.prevEdgeDecorationClasses.get(e.id);a&&(this.graph.findViewByCell(e)?.container?.classList.remove(a),this.prevEdgeDecorationClasses.delete(e.id)),i?.className&&(this.graph.findViewByCell(e)?.container?.classList.add(i.className),this.prevEdgeDecorationClasses.set(e.id,i.className));let c,l,v;if(t?.style){const R=this.graph.isSelected?.(e)??!1,E=this.hoveredEdgeId===e.id,N=t.style(o,{selected:R,highlighted:r,hovered:E});c=N.stroke,l=N.strokeWidth,v=N.strokeDasharray}const p=!t?.style&&r?"#3a84ff":void 0,h=i?.strokeColor,f=i?.targetMarkerColor,b=h??c??p,A=!!t?.style||this.prevEdgeDecorationColors.has(e.id)||this.defaultHighlightedEdgeIds.has(e.id)||this.prevEdgeStyleIds.has(e.id);b?this.setEdgeAttrIfChanged(e,"line/stroke",b):A&&this.restoreEdgeAttr(e,"line/stroke","stroke"),this.applyEdgeMarkerDecoration(e,t,"targetMarker",f),t?.style?(this.prevEdgeStyleIds.add(e.id),l?this.setEdgeAttrIfChanged(e,"line/strokeWidth",l):this.restoreEdgeAttr(e,"line/strokeWidth","strokeWidth"),v?this.setEdgeAttrIfChanged(e,"line/strokeDasharray",v):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),p?this.defaultHighlightedEdgeIds.add(e.id):this.defaultHighlightedEdgeIds.delete(e.id)}}class Bt{instanceId=X();registeredShapes=new Map;wrappedComponents=new Map;getShapeName(e){let o=this.registeredShapes.get(e);return o||(o=`flow-node-${this.instanceId}-${e}`,this.registeredShapes.set(e,o)),o}registerNodeType(e,o){const t=this.getShapeName(e);let r=this.wrappedComponents.get(e);return r||(r=s.defineComponent({name:`FlowCanvasNodeShape${e.replace(/(^|[-_])(\w)/g,(i,a,c)=>c.toUpperCase())}`,setup(){return()=>s.h("div",{class:"flow-canvas-node-surface"},[s.h(o)])}}),this.wrappedComponents.set(e,r)),lt.register({shape:t,component:r,width:100,height:40}),t}dispose(){this.registeredShapes.clear(),this.wrappedComponents.clear()}}class Tt{graph;onUiEvent;onCommand;flowModelRef;idGenerator;disposers=[];constructor(e,o,t,r,i){this.graph=e,this.onUiEvent=o,this.onCommand=t,this.flowModelRef=r,this.idGenerator=i??Se,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:mouseenter",({node:e})=>{this.onUiEvent({type:"node.mouseenter",nodeId:e.id})}),this.on("node:mouseleave",({node:e})=>{this.onUiEvent({type:"node.mouseleave",nodeId:e.id})}),this.on("node:contextmenu",({node:e,e:o})=>{this.onUiEvent({type:"node.contextmenu",nodeId:e.id,position:{x:o.clientX,y:o.clientY}})}),this.on("edge:click",({edge:e,e:o})=>{const r=o.target?.closest?.(".x6-edge-label");if(r){const a=e.getData?.()?.labels??[],c=r.parentElement?.querySelectorAll(".x6-edge-label"),l=c?Array.from(c).indexOf(r):0,v=a[Math.max(0,l)];this.onUiEvent({type:"edge.label.click",edgeId:e.id,labelId:v?.id??`label-${l}`});return}this.onUiEvent({type:"edge.click",edgeId:e.id})}),this.on("blank:click",({e})=>{const o=this.graph.clientToLocal(e.clientX,e.clientY);this.onUiEvent({type:"blank.click",position:{x:o.x,y:o.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 o=e.getPosition();this.onCommand({id:X(),source:"user:drag",label:"移动节点",timestamp:Date.now(),commands:[{type:"node.move",nodeId:e.id,position:{x:o.x,y:o.y}}]})}),this.on("edge:connected",({edge:e,isNew:o})=>{const t=e.getSourceCell(),r=e.getTargetCell();if(!t||!r)return;const i=e.getSourcePortId(),a=e.getTargetPortId(),c=e.id in this.flowModelRef.value.edges;o&&!c?(this.graph.removeCell(e),this.onCommand({id:X(),source:"user:drag",label:"连线",timestamp:Date.now(),commands:[{type:"edge.add",edge:{id:this.idGenerator("edge"),source:{nodeId:t.id,portId:i??void 0},target:{nodeId:r.id,portId:a??void 0}}}]})):this.onCommand({id:X(),source:"user:drag",label:"重连",timestamp:Date.now(),commands:[{type:"edge.reconnect",edgeId:e.id,source:{nodeId:t.id,portId:i??void 0},target:{nodeId:r.id,portId:a??void 0}}]})}),this.on("edge:change:labels",({edge:e,current:o})=>{const r=e.getData?.()?.labels??[];if(!r.length||!o?.length)return;const i=[];for(let a=0;a<Math.min(r.length,o.length);a++){const c=o[a],l=r[a];if(!l?.id)continue;const v=typeof c.position=="object"?c.position?.distance:c.position;v!=null&&i.push({type:"edge.label.update",edgeId:e.id,labelId:l.id,patch:{position:v}})}i.length&&this.onCommand({id:X(),source:"user:drag",label:"拖动标签",timestamp:Date.now(),commands:i})})}on(e,o){this.graph.on(e,o),this.disposers.push(()=>this.graph.off(e,o))}}function Rt(n){function e(t){const r=n.getCellById(t);if(!r||!r.isNode())return null;const i=r,a=i.getPosition(),c=i.getSize(),l={x:a.x,y:a.y,width:c.width,height:c.height},v=n.localToGraph(l);return new DOMRect(v.x,v.y,v.width,v.height)}function o(t){const r=e(t);if(!r)return null;const i=n.container;if(!i||typeof i.getBoundingClientRect!="function")return r;const a=i.getBoundingClientRect();return new DOMRect(r.x+a.left,r.y+a.top,r.width,r.height)}return{getNodeScreenRect:e,getNodeViewportRect:o}}const Lt=Object.freeze({top:24,right:8,bottom:8,left:8});function je(n){return{nodeIds:n.filter(e=>e.isNode()).map(e=>e.id),edgeIds:n.filter(e=>e.isEdge()).map(e=>e.id)}}function Ot(n,e=Lt){return new DOMRect(n.x-e.left,n.y-e.top,n.width+e.left+e.right,n.height+e.top+e.bottom)}function $t(n,e){const o=[...e.nodeIds.map(i=>n.getCellById(i)),...e.edgeIds.map(i=>n.getCellById(i))].filter(i=>!!i);if(o.length===0)return null;const t=n.getCellsBBox(o);if(!t)return null;const r=n.localToGraph(t);return Ot(r)}function We(n,e,o){const t=n.nodeIds.filter(a=>{const c=e.nodes[a];if(!c)return!1;const l=o(c);return l.deletable!==!1&&l.deleteDisabled!==!0}),r=new Set(t),i=n.edgeIds.filter(a=>{const c=e.edges[a];return c?!r.has(c.source.nodeId)&&!r.has(c.target.nodeId):!1});return{nodeIds:t,edgeIds:i}}function Ft(n){return[...n.edgeIds.map(e=>({type:"edge.remove",edgeId:e})),...n.nodeIds.map(e=>({type:"node.remove",nodeId:e}))]}const Vt=100;function zt({graph:n,overlayManager:e,executeCommand:o,schema:t,flowModel:r,getNodeBehavior:i,idGenerator:a,defaultInsertGap:c,getContextMenuItems:l,onHighlightChange:v,resolveNodeShape:p}){const h=a??Se;let f=[],b=[],A=null,R=!1,E=null;async function N(){if(R)return A;R=!0;try{const d=await import("@antv/x6-plugin-dnd"),w=d.Dnd??d.default;return w?(A=new w({target:n,scaled:!0,animation:!0,getDragNode:u=>u.clone(),getDropNode:u=>u.clone()}),A):null}catch{return console.warn("[flow-canvas] @antv/x6-plugin-dnd not available, add it to your dependencies"),null}}function M(){return new Promise(d=>{requestAnimationFrame(()=>requestAnimationFrame(()=>d()))})}const O=({node:d})=>{const w=d.getData?.();if(!w?._dndSessionId||w._dndSessionId!==E)return;E=null;const u=d.getPosition();n.removeNode(d.id);const{_dndSessionId:g,...m}=w,y=m.id||h("node");o({id:X(),source:"user:drag",label:"拖入节点",timestamp:Date.now(),commands:[{type:"node.add",node:{...m,id:y,position:{x:u.x,y:u.y}}}]})};n.on("node:added",O);function q(d){const w=t.nodeTypes[d.type];return Ne(d,w?.getPorts)}function S(d){return d??je(n.getSelectedCells?.()??[])}function G(d,w,u,g,m){switch(d){case"left":return{x:w.position.x-m-g.width,y:w.position.y+(u.height-g.height)/2};case"top":return{x:w.position.x+(u.width-g.width)/2,y:w.position.y-m-g.height};case"bottom":return{x:w.position.x+(u.width-g.width)/2,y:w.position.y+u.height+m};default:return{x:w.position.x+u.width+m,y:w.position.y+(u.height-g.height)/2}}}function z(d){switch(d){case"left":return"right";case"top":return"bottom";case"bottom":return"top";default:return"left"}}const F={zoomIn(){n.zoom(.1)},zoomOut(){n.zoom(-.1)},zoomTo(d){n.zoomTo(d)},zoomToFit(d){n.zoomToFit({padding:40,maxScale:1,...d})},getZoom(){return n.zoom()},centerContent(){n.centerContent()},scrollToOrigin(){n.translate(0,0)},scrollToNode(d){const w=n.getCellById(d);w&&n.centerCell(w)},getSelection(){return S()},getSelectionBounds(d){return $t(n,S(d))},selectNodes(d){const w=d.map(u=>n.getCellById(u)).filter(Boolean);n.select?.(w)},selectEdges(d){const w=d.map(u=>n.getCellById(u)).filter(Boolean);n.select?.(w)},clearSelection(){const d=n.getSelectedCells?.();d?.length&&n.unselect?.(d)},deleteSelection(d){const w=S(d?.selection),u=We(w,r.value,i??(()=>({}))),g=Ft(u);if(g.length===0)return null;const m=o({id:X(),source:d?.source??"user:toolbar",label:d?.label??"删除选中",timestamp:Date.now(),commands:g});return m.status==="applied"&&d?.clearSelectionAfterApply!==!1&&F.clearSelection(),m},registerDndSource(d,w){const u=async g=>{const m=await N();if(!m)return;const y=X();E=y;const k=w(),T=p?.(k.type),V=n.createNode({width:T?.width??154,height:T?.height??54,shape:T?.shapeName??"rect",data:{...k,_dndSessionId:y}});m.start(V,g)};return d.addEventListener("mousedown",u),()=>{d.removeEventListener("mousedown",u)}},startConnection(d,w){const u=n.getCellById(d);if(!u?.isNode())return;const g=u,m=n.findViewByCell(g);if(!m)return;const y=m.findPortElem(w,"circle")??m.findPortElem(w);if(!y)return;const T=(y.matches?.("[magnet]")?y:y.querySelector?.("[magnet]"))??y,V=T.getBoundingClientRect(),oe=V.left+V.width/2,D=V.top+V.height/2,_=new MouseEvent("mousedown",{clientX:oe,clientY:D,button:0,buttons:1,bubbles:!0,cancelable:!0});T.dispatchEvent(_)},async exportAsImage(d){const{domToBlob:w}=await import("modern-screenshot"),u=d?.padding??20,g=d?.backgroundColor??n.options.background?.color??"#ffffff",m=n.zoom(),y=n.translate(),k=n.getContentBBox(),T=k.width/m,V=k.height/m;if(T===0||V===0)return new Blob;const oe=(k.x-y.tx)/m,D=(k.y-y.ty)/m,_=Math.ceil(T+u*2),C=Math.ceil(V+u*2),B=document.createElement("div");B.style.cssText="position:fixed;left:-99999px;top:0;pointer-events:none;";const $=new Set;let U=n.container.parentElement;for(;U&&U!==document.body&&U!==document.documentElement;)U.classList.forEach(Z=>$.add(Z)),U=U.parentElement;$.size>0&&(B.className=Array.from($).join(" "));const K=n.container.cloneNode(!0);K.style.width=`${_}px`,K.style.height=`${C}px`,K.style.overflow="visible";const j=K.querySelector("svg");j&&(j.setAttribute("width",String(_)),j.setAttribute("height",String(C)),j.style.width=`${_}px`,j.style.height=`${C}px`),K.querySelector(".x6-graph-svg-viewport")?.setAttribute("transform",`matrix(1,0,0,1,${-oe+u},${-D+u})`),B.appendChild(K),document.body.appendChild(B);try{return await M(),await w(K,{width:_,height:C,backgroundColor:g,scale:d?.scale??window.devicePixelRatio,filter:Z=>{if(Z instanceof Element){const J=Z.getAttribute("class")??"";if(J.includes("x6-widget-selection")||J.includes("x6-widget-transform")||J.includes("x6-graph-grid")||J.includes("x6-graph-background"))return!1}return!0}})}catch(Z){return console.warn("[flow-canvas] Export failed:",Z),new Blob}finally{B.remove()}},highlightNodes(d){f=d,v?.(f,b)},highlightEdges(d){b=d,v?.(f,b)},clearHighlight(){f=[],b=[],v?.([],[])},overlay:e,getContextMenuItems(d){return l?.(d)??[]},insertNodeToRight(d,w,u){const g=r.value,m=g.nodes[d];if(!m)return{status:"invalid",envelope:{id:"",source:"user:toolbar",timestamp:Date.now(),commands:[]},error:{code:"constraint_violated",reason:`Source node "${d}" not found`,source:"api"}};const y=u?.gap??c??Vt,k=u?.direction??"right",T=t.nodeTypes[m.type],V=t.nodeTypes[w.type],oe=T?.getSize(m)??{width:154,height:54},D=V?.getSize({...w,position:{x:0,y:0}})??{width:154,height:54},_=G(k,m,oe,D,y),C=w.id||h("node"),B={...w,id:C,position:_},$=[{type:"node.add",node:B}];if(u?.autoWireEdges){const K=q(m),j=q(B),W=k,Z=z(k),J=K.find(x=>x.group===W),le=j.find(x=>x.group===Z),Ee=j.find(x=>x.group===W),fe=J?Object.values(g.edges).find(x=>x.source.nodeId===d&&x.source.portId===J.id):Object.values(g.edges).find(x=>x.source.nodeId===d);if(fe){const x=fe.target,I=D.width+y,P=k==="right"?I:k==="left"?-I:0,H=k==="bottom"?I:k==="top"?-I:0,Y=new Set,re=[x.nodeId];for(;re.length>0;){const Q=re.shift();if(Y.has(Q)||Q===d)continue;Y.add(Q);const de=g.nodes[Q];if(de){$.push({type:"node.move",nodeId:Q,position:{x:de.position.x+P,y:de.position.y+H}});for(const ce of Object.values(g.edges))ce.source.nodeId===Q&&!Y.has(ce.target.nodeId)&&re.push(ce.target.nodeId)}}$.push({type:"edge.remove",edgeId:fe.id}),$.push({type:"edge.add",edge:{id:h("edge"),source:{nodeId:d,portId:J?.id},target:{nodeId:C,portId:le?.id}}}),$.push({type:"edge.add",edge:{id:h("edge"),source:{nodeId:C,portId:Ee?.id},target:x}})}else $.push({type:"edge.add",edge:{id:h("edge"),source:{nodeId:d,portId:J?.id},target:{nodeId:C,portId:le?.id}}})}const U={id:X(),source:u?.source??"user:toolbar",label:u?.label??"插入节点",timestamp:Date.now(),commands:$};return o(U)},onGraphEvent(d,w){return n.on(d,w),()=>n.off(d,w)},unsafeGetGraph(){return n}};return F}function qt(){const n=s.ref(null),e=s.ref(!1);let o=null,t=!1;function r(h){o&&(clearTimeout(o),o=null),n.value=h}function i(h=100){t||(o&&clearTimeout(o),o=setTimeout(()=>{n.value=null,o=null},h))}function a(){t=!0,o&&(clearTimeout(o),o=null)}function c(h=100){t=!1,i(h)}function l(){o&&(clearTimeout(o),o=null)}function v(){l(),t=!1,n.value=null}function p(){o&&clearTimeout(o)}return{hoveredNodeId:n,isDraggingNode:e,enter:r,leave:i,enterOverlay:a,leaveOverlay:c,cancelLeave:l,reset:v,cleanup:p}}const _e=10,he=12;function Pe(n,e){const o=n.getTotalLength();if(o===0)return{...e,length:0,totalLength:0};let t=n.getPointAtLength(0),r=1/0;const i=50,a=o/i;let c=0;for(let h=0;h<=i;h++){const f=h*a,b=n.getPointAtLength(f),A=(b.x-e.x)**2+(b.y-e.y)**2;A<r&&(r=A,t=b,c=f)}const l=Math.max(0,c-a),v=Math.min(o,c+a),p=(v-l)/20;for(let h=l;h<=v;h+=p){const f=n.getPointAtLength(h),b=(f.x-e.x)**2+(f.y-e.y)**2;b<r&&(r=b,t=f,c=h)}return{x:t.x,y:t.y,length:c,totalLength:o}}function Be(n,e){return n<_e||n>e-_e}function Te(n,e,o){const t=n.querySelectorAll(".x6-edge-label");for(const r of t){const i=r.getBoundingClientRect();if(e>=i.left-he&&e<=i.right+he&&o>=i.top-he&&o<=i.bottom+he)return!0}return!1}function Re(){const n="http://www.w3.org/2000/svg",e=document.createElementNS(n,"g");e.setAttribute("class","flow-canvas-edge-delete-tool"),e.style.cursor="pointer";const o=document.createElementNS(n,"rect");o.setAttribute("width","20"),o.setAttribute("height","20"),o.setAttribute("x","-10"),o.setAttribute("y","-10"),o.setAttribute("rx","4"),o.setAttribute("ry","4"),o.setAttribute("fill","#3a84ff"),e.appendChild(o);const t=document.createElementNS(n,"text");return t.setAttribute("font-family","flow-canvas"),t.setAttribute("font-size","16"),t.setAttribute("fill","#ffffff"),t.setAttribute("text-anchor","middle"),t.setAttribute("dominant-baseline","central"),t.textContent="",e.appendChild(t),e}function Ht(n){let e=null,o=null;function t(c,l){if(i(),o=c,l.target?.closest?.(".x6-edge-label"))return;const p=n.getCellById(c);if(!p?.isEdge())return;const h=n.findViewByCell(p);if(!h)return;const f=h.container.querySelector("path");if(!f)return;const b=n.clientToLocal(l.clientX,l.clientY),A=Pe(f,b);if(Be(A.length,A.totalLength)||Te(h.container,l.clientX,l.clientY))return;const R=Re();R.setAttribute("transform",`translate(${A.x}, ${A.y})`),h.container.appendChild(R),e=R}function r(c){if(!o)return;if(c.target?.closest?.(".x6-edge-label")){e&&e.setAttribute("display","none");return}const v=n.getCellById(o);if(!v?.isEdge())return;const p=n.findViewByCell(v);if(!p)return;const h=p.container.querySelector("path");if(!h)return;const f=n.clientToLocal(c.clientX,c.clientY),b=Pe(h,f);if(Be(b.length,b.totalLength)||Te(p.container,c.clientX,c.clientY))e&&e.setAttribute("display","none");else if(e)e.removeAttribute("display"),e.setAttribute("transform",`translate(${b.x}, ${b.y})`);else{const A=Re();A.setAttribute("transform",`translate(${b.x}, ${b.y})`),p.container.appendChild(A),e=A}}function i(){e&&(e.remove(),e=null),o=null}function a(c){c===o&&(e=null,o=null)}return{show:t,move:r,remove:i,handleEdgeRemoved:a}}function Gt(n){let e=null,o=0;function t(p){const h=p?"visible":"hidden";for(const f of n.getNodes())for(const b of f.getPorts())f.setPortProp(b.id,"attrs/circle/visibility",h)}function r(p){if(!e)for(const h of p.getPorts())p.setPortProp(h.id,"attrs/circle/visibility","visible")}function i(p){if(!e)for(const h of p.getPorts())p.setPortProp(h.id,"attrs/circle/visibility","hidden")}function a(p,h){if(!p.getTargetCell())if(e=p.id,h?.size)for(const f of n.getNodes()){const b=h.has(f.id)?"hidden":"visible";for(const A of f.getPorts())f.setPortProp(A.id,"attrs/circle/visibility",b)}else t(!0)}function c(){e=null,t(!1),o=Date.now()+300}function l(p){p===e&&(e=null,t(!1))}function v(){return!e&&Date.now()>=o}return{showNodePorts:r,hideNodePorts:i,handleEdgeAdded:a,handleEdgeConnected:c,handleEdgeRemoved:l,canShowEdgeTool:v}}function Le(n){return n==="top"||n==="right"||n==="bottom"||n==="left"}function Ut(n){const{editor:e,nodeHover:o,isSelectionModeActive:t,viewportVersion:r,getNodeBehavior:i,getInsertGap:a}=n,{isDraggingNode:c}=n,l=s.ref(null),v=s.ref(!1);let p=null,h=null,f=null;const b=s.computed(()=>({enabled:!0,portGroup:"right",autoPanOnOpen:!0,autoPanPadding:16,...n.quickAddProp.value}));function A(){p&&(clearTimeout(p),p=null)}function R(){p&&clearTimeout(p),p=setTimeout(()=>{l.value=null,p=null},150)}function E(D){return v.value?!0:(A(),d(D)?(l.value=D,!0):(l.value=null,!1))}function N(){A(),o.enterOverlay()}function M(){R(),o.leaveOverlay()}function O(D){const _=e.schema.nodeTypes[D.type];return Ne(D,_?.getPorts)}function q(D,_){const C=b.value.getPort?.(D,_);if(!C)return null;const B=typeof C=="string"?C:C.id;return _.find($=>$.id===B)??null}function S(D,_){const C=e.api.value?.overlay.getNodeScreenRect(D);if(!C)return null;switch(_){case"top":return{x:C.x+C.width/2,y:C.y};case"bottom":return{x:C.x+C.width/2,y:C.y+C.height};case"left":return{x:C.x,y:C.y+C.height/2};case"right":return{x:C.x+C.width,y:C.y+C.height/2};default:return null}}function G(D,_,C){if(!h)return S(D,C);const B=h.getCellById(D);if(B?.isNode()){const $=B,U=h.findViewByCell($),K=U?.findPortElem(_,"circle")??U?.findPortElem(_);if(K){const j=h.container.getBoundingClientRect(),W=K.getBoundingClientRect();return{x:W.left-j.left+W.width/2,y:W.top-j.top+W.height/2}}}return S(D,C)}function z(D){const _=O(D),C=q(D,_)??_.find($=>$.group===b.value.portGroup)??null;if(!C)return null;const B=G(D.id,C.id,C.group);return B?{portId:C.id,portGroup:C.group,portPosition:B}:null}function F(D){const _=z(D),C=b.value.insertDirection;if(typeof C=="function"){const B=C(D,_?{id:_.portId,group:_.portGroup}:null);if(B)return B}else if(C)return C;return _&&Le(_.portGroup)?_.portGroup:Le(b.value.portGroup)?b.value.portGroup:"right"}function d(D){if(!b.value.enabled||e.mode.value!=="edit")return!1;const C=e.flowModel.value.nodes[D];return!C||i(C).quickAddEnabled===!1?!1:!!z(C)}const w=s.computed(()=>{if(r.value,!b.value.enabled)return null;const D=l.value;if(!D||c.value||!e.api.value||e.mode.value!=="edit"||t.value)return null;const C=e.flowModel.value.nodes[D];if(!C)return null;const B=i(C);if(B.quickAddEnabled===!1)return null;const $=z(C);return $?{node:C,...$,behavior:B}:null});function u(D){v.value=!0,w.value&&e._emitUiEvent({type:"node.quick-add",nodeId:D,position:w.value.portPosition})}function g(){v.value=!1}function m(D){const _=e.api.value;if(!_)return;const C=e.flowModel.value.nodes[D];if(!C)return;const B=z(C);B&&_.startConnection(D,B.portId)}function y(D){if(!h||!b.value.autoPanOnOpen||D<=0)return;const _=h.translate();h.translate(_.tx-D,_.ty)}function k(D,_){const C=e.api.value;if(!C)return;const B=_.id||e.idGenerator("node"),$={..._,id:B},U=e.flowModel.value.nodes[D];if(!U)return;C.insertNodeToRight(D,$,{autoWireEdges:!0,direction:F(U),gap:a(),source:"user:quick-add",label:"快捷插入节点"}).status==="applied"&&e._emitUiEvent({type:"node.action.quick-insert",sourceNodeId:D,newNodeId:B}),n.closePopover()}function T(D){if(!h)return;const _=h.getCellById(D);if(!_?.isNode())return;const C=_,B=e.flowModel.value.nodes[D];if(!B)return;const $=z(B);let U=!0;i(B).hidePortForQuickAdd===!1&&(U=!1);const j=U&&!c.value&&!!$&&d(D);for(const W of C.getPorts()){const Z=j&&W.id===$?.portId?"hidden":"visible";C.setPortProp(W.id,"attrs/circle/visibility",Z)}}function V(D,_){f?.(),h=D,f=s.watch([l,c],([C],[B])=>{if(B&&B!==C){const $=D.getCellById(B);$?.isNode()&&_($)}C&&T(C)},{flush:"sync"})}s.watch(w,D=>{D||(v.value=!1)});function oe(){p&&clearTimeout(p),f?.(),f=null,h=null}return{quickAddNodeId:l,quickAddPopoverOpen:v,mergedConfig:b,data:w,enter:E,leave:R,cancelLeave:A,handleOverlayEnter:N,handleOverlayLeave:M,handleOpen:u,handleClose:g,handleStartDrag:m,handlePopoverViewportOverflow:y,handleInsert:k,isActiveForNode:d,syncNodePorts:T,attachRuntime:V,cleanup:oe}}const jt=15,Wt=10;function Xt(n){const{editor:e}=n;let o=null,t=null,r=null,i=null;const a=[];let c=null;const l=s.computed(()=>({enabled:!1,bufferMargin:jt,incomingPortGroup:"left",outgoingPortGroup:"right",...n.edgeDropProp.value}));function v(d){if(!o)return null;const w=o.getCellById(d);if(!w?.isEdge())return null;const u=o.findViewByCell(w)?.container;if(!u)return null;const g=u.querySelectorAll("path");for(const m of g)if(m.getAttribute("stroke")!=="transparent")return m;return null}function p(d){const w=v(d);w&&(w.style.stroke="#3a84ff",i=d)}function h(){if(!i)return;const d=v(i);d&&(d.style.stroke=""),i=null}function f(d,w,u){if(o){const g=o.getCellById(d);if(g?.isNode()){const m=g.getPorts().find(y=>y.group===u);if(m?.id)return m.id}}if(w.ports?.length){const g=w.ports.find(m=>m.group===u);if(g)return g.id}return u}function b(d){const w=d.getTotalLength();if(w===0)return[];const u=[];for(let m=0;m<=w;m+=Wt){const y=d.getPointAtLength(m);u.push({x:y.x,y:y.y})}const g=d.getPointAtLength(w);return u.push({x:g.x,y:g.y}),u}function A(d,w,u){if(!o)return null;const g=l.value,m=g.bufferMargin,y={x:d.x+m,y:d.y+m,width:Math.max(0,d.width-m*2),height:Math.max(0,d.height-m*2)};if(y.width<=0||y.height<=0)return null;const k=y.x+y.width,T=y.y+y.height;let V=null;const oe=d.x+d.width/2,D=d.y+d.height/2;for(const _ of o.getEdges()){const C=w.edges[_.id];if(!C||u&&(C.source.nodeId===u||C.target.nodeId===u)||g.isEdgeDropTarget&&!g.isEdgeDropTarget(C,w))continue;const B=o.findViewByCell(_);if(!B)continue;const $=B.findOne?.("path");if(!$||typeof $.getTotalLength!="function")continue;const U=b($);if(!U.length)continue;let K=!1,j=1/0;for(const W of U)if(W.x>=y.x&&W.x<=k&&W.y>=y.y&&W.y<=T){const Z=W.x-oe,J=W.y-D,le=Z*Z+J*J;le<j&&(j=le),K=!0}K&&(!V||j<V.distSq)&&(V={edgeId:_.id,edge:C,distSq:j})}return V?{edgeId:V.edgeId,edge:V.edge}:null}function R(d,w){if(!l.value.enabled)return;const g=e.flowModel.value,m=A(d,g,w);m?t!==m.edgeId&&(h(),t=m.edgeId,p(m.edgeId)):t&&(h(),t=null)}let E=!0;function N({node:d}){if(t=null,!l.value.enabled)return;const w=e.flowModel.value,u=w.nodes[d.id];if(!u){E=!1;return}const g=l.value;E=!g.isNodeInsertable||g.isNodeInsertable(u,w)}function M({node:d}){!l.value.enabled||!E||r===null&&(r=requestAnimationFrame(()=>{if(r=null,!o)return;const w=d.getPosition(),u=d.getSize();R({x:w.x,y:w.y,width:u.width,height:u.height},d.id)}))}function O(){r!==null&&(cancelAnimationFrame(r),r=null),h(),E=!0}function q(){if(!o)return;let d=!1;c=()=>{if(!l.value.enabled)return;const w=document.querySelector(".x6-widget-dnd");if(!w){d&&(d=!1,h(),t=null);return}d=!0,r===null&&(r=requestAnimationFrame(()=>{if(r=null,!o)return;const u=w.getBoundingClientRect(),g=o.clientToLocal(u.left,u.top),m=o.clientToLocal(u.right,u.bottom),y={x:g.x,y:g.y,width:m.x-g.x,height:m.y-g.y};R(y)}))},document.addEventListener("mousemove",c),a.push(()=>{c&&(document.removeEventListener("mousemove",c),c=null)})}function S(){h(),t=null,r!==null&&(cancelAnimationFrame(r),r=null)}function G(d){if(!t||d.source!=="user:drag")return d;const w=t;t=null,h();const u=e.flowModel.value,g=u.edges[w];if(!g)return d;const m=d.commands.find(B=>B.type==="node.add"||B.type==="node.move");if(!m)return d;const y=m.type==="node.add"?m.node.id:m.nodeId,k=m.type==="node.add"?m.node:u.nodes[m.nodeId];if(!k)return d;const T=l.value;if(T.isNodeInsertable&&!T.isNodeInsertable(k,u))return d;const V=f(y,k,T.incomingPortGroup),oe=f(y,k,T.outgoingPortGroup),D=e.idGenerator("edge"),_=e.idGenerator("edge"),C=[{type:"edge.remove",edgeId:w},{type:"edge.add",edge:{id:D,type:g.type,source:{nodeId:g.source.nodeId,portId:g.source.portId},target:{nodeId:y,portId:V}}},{type:"edge.add",edge:{id:_,type:g.type,source:{nodeId:y,portId:oe},target:{nodeId:g.target.nodeId,portId:g.target.portId}}}];return{...d,source:"user:edge-drop",commands:[...d.commands,...C]}}function z(d){o=d;const w=(u,g)=>{d.on(u,g),a.push(()=>d.off(u,g))};w("node:move",N),w("node:change:position",M),w("node:moved",O),q()}function F(){S();for(const d of a)d();a.length=0,o=null,E=!0}return{attachRuntime:z,tryExpandForEdgeDrop:G,cleanup:F}}function Kt(n){function e(r){return{id:n.idGenerator("node"),type:r.type,label:r.label,ports:r.ports?JSON.parse(JSON.stringify(r.ports)):void 0,payload:r.payload?JSON.parse(JSON.stringify(r.payload)):void 0,extensions:r.extensions?JSON.parse(JSON.stringify(r.extensions)):void 0}}function o(r,i,a){const c=n.api.value;switch(r){case"delete":return n.executeCommand({id:X(),source:"user:toolbar",label:"删除节点",timestamp:Date.now(),commands:[{type:"node.remove",nodeId:i}]}),n._emitUiEvent({type:"node.action.delete",nodeId:i}),!0;case"copy":{if(!c)break;const l=n.flowModel.value.nodes[i];if(!l)break;const v=e(l),p=50;n.executeCommand({id:X(),source:"user:toolbar",label:"复制节点",timestamp:Date.now(),commands:[{type:"node.add",node:{...v,position:{x:l.position.x+p,y:l.position.y+p}}}]}),c.selectNodes([v.id]),n._emitUiEvent({type:"node.action.copy",sourceNodeId:i,newNodeId:v.id});break}case"copy-insert":{if(!c)break;const l=n.flowModel.value.nodes[i];if(!l)break;const v=e(l);c.insertNodeToRight(i,v,{autoWireEdges:!0,gap:a,label:"复制并插入节点"}),c.selectNodes([v.id]),n._emitUiEvent({type:"node.action.copy-insert",sourceNodeId:i,newNodeId:v.id});break}case"disconnect":{const l=n.flowModel.value,v=Object.entries(l.edges).filter(([,p])=>{const h=p;return h.source.nodeId===i||h.target.nodeId===i}).map(([p])=>p);if(v.length===0)break;n.executeCommand({id:X(),source:"user:toolbar",label:"断开连线",timestamp:Date.now(),commands:v.map(p=>({type:"edge.remove",edgeId:p}))}),n._emitUiEvent({type:"node.action.disconnect",nodeId:i,edgeIds:v});break}case"debug":{n._emitUiEvent({type:"node.action.debug",nodeId:i});break}}return!1}function t(r){n.api.value?.deleteSelection({selection:r,source:"user:toolbar",label:"批量删除选中"})}return{handleNodeAction:o,deleteSelection:t}}function Yt(){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 Zt(n,e){const o=e.defaultEdgeType??"default",t=e.edgeTypes?.[o],r={zIndex:-1,attrs:{line:{stroke:"#abb5cc",strokeWidth:2,targetMarker:{name:"block",width:8,height:8}}}};t?.router&&(r.router=typeof t.router=="string"?{name:t.router}:t.router),t?.connector&&(r.connector=typeof t.connector=="string"?{name:t.connector}:t.connector),t?.x6EdgeConfig&&Object.assign(r,t.x6EdgeConfig);const i=r.attrs??{},a=i.line??{};return r.attrs={...i,line:{...a,targetMarker:Yt()}},n.createEdge(r)}const Qt=".x6-widget-selection",Jt=".x6-graph-svg";function eo(n){const e=n.querySelector(Qt),o=n.querySelector(Jt);return!e||!o||e.parentNode!==o.parentNode||!o.parentNode||o.previousSibling===e?!1:(o.parentNode.insertBefore(e,o),!0)}function to(n){const e=()=>eo(n);e();const o=new MutationObserver(()=>{e()});return o.observe(n,{childList:!0}),()=>o.disconnect()}function oo(n,e,o){const t=new Set(e),r=new Set(o),i=new Set([...t,...r]);for(const a of i){const c=n.getCellById(a);if(!c?.isNode())continue;const l=r.has(a),v=c.getData()??{};v._selected!==l&&c.setData({...v,_selected:l})}}const no={class:"flow-canvas-node-actions__bar"},ro=s.defineComponent({__name:"node-actions-toolbar",props:{node:{},position:{},config:{},behavior:{},actionsOffset:{}},emits:["action"],setup(n,{emit:e}){const o=n,t=s.computed(()=>{const h=o.actionsOffset?.x??0,f=o.actionsOffset?.y??0,b=h!==0||f!==0;return{left:`${o.position.x}px`,top:`${o.position.y}px`,transform:b?`translate(${h}px, ${f}px)`:"translateX(-100%)"}}),r=e,i=s.computed(()=>({debug:{visible:o.config.showDebug&&o.behavior.debuggable!==!1,disabled:o.behavior.debugDisabled===!0},delete:{visible:o.config.showDelete&&o.behavior.deletable!==!1,disabled:o.behavior.deleteDisabled===!0},copy:{visible:o.config.showCopy&&o.behavior.copyable!==!1,disabled:o.behavior.copyDisabled===!0},copyInsert:{visible:o.config.showCopyInsert&&o.behavior.copyable!==!1,disabled:o.behavior.copyInsertDisabled===!0},disconnect:{visible:o.config.showDisconnect&&o.behavior.disconnectable!==!1,disabled:o.behavior.disconnectDisabled===!0}})),a=s.computed(()=>i.value.copy.visible||i.value.copyInsert.visible||i.value.disconnect.visible),c=s.ref(!1);let l=null;function v(){l&&(clearTimeout(l),l=null),c.value=!0}function p(){l=setTimeout(()=>{c.value=!1,l=null},100)}return s.onBeforeUnmount(()=>{l&&clearTimeout(l)}),(h,f)=>(s.openBlock(),s.createElementBlock("div",{class:"flow-canvas-node-actions",style:s.normalizeStyle(t.value)},[s.createElementVNode("div",no,[i.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":i.value.debug.disabled}]),onClick:f[0]||(f[0]=b=>!i.value.debug.disabled&&r("action","debug",n.node.id))},null,2)):s.createCommentVNode("",!0),i.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":i.value.delete.disabled}]),onClick:f[1]||(f[1]=b=>!i.value.delete.disabled&&r("action","delete",n.node.id))},null,2)):s.createCommentVNode("",!0),a.value?(s.openBlock(),s.createElementBlock("div",{key:2,class:"flow-canvas-node-actions__more-wrapper",onMouseenter:v,onMouseleave:p},[...f[5]||(f[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(()=>[c.value&&a.value?(s.openBlock(),s.createElementBlock("div",{key:0,class:"flow-canvas-node-actions__dropdown",onMouseenter:v,onMouseleave:p},[i.value.copy.visible?(s.openBlock(),s.createElementBlock("div",{key:0,class:s.normalizeClass(["flow-canvas-node-actions__dropdown-item",{"is-disabled":i.value.copy.disabled}]),onClick:f[2]||(f[2]=b=>!i.value.copy.disabled&&r("action","copy",n.node.id))},[...f[6]||(f[6]=[s.createElementVNode("i",{class:"flow-canvas-icon canvas-copy-fuzhi-2"},null,-1),s.createElementVNode("span",null,"复制",-1)])],2)):s.createCommentVNode("",!0),i.value.copyInsert.visible?(s.openBlock(),s.createElementBlock("div",{key:1,class:s.normalizeClass(["flow-canvas-node-actions__dropdown-item",{"is-disabled":i.value.copyInsert.disabled}]),onClick:f[3]||(f[3]=b=>!i.value.copyInsert.disabled&&r("action","copy-insert",n.node.id))},[...f[7]||(f[7]=[s.createElementVNode("i",{class:"flow-canvas-icon canvas-fuzhibingcharu"},null,-1),s.createElementVNode("span",null,"复制并插入",-1)])],2)):s.createCommentVNode("",!0),i.value.disconnect.visible?(s.openBlock(),s.createElementBlock("div",{key:2,class:s.normalizeClass(["flow-canvas-node-actions__dropdown-item",{"is-disabled":i.value.disconnect.disabled}]),onClick:f[4]||(f[4]=b=>!i.value.disconnect.disabled&&r("action","disconnect",n.node.id))},[...f[8]||(f[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))}}),ie=(n,e)=>{const o=n.__vccOpts||n;for(const[t,r]of e)o[t]=r;return o},Xe=ie(ro,[["__scopeId","data-v-3b39dab5"]]),so={key:0,class:"flow-canvas-quick-add__tooltip"},io=5,ao=s.defineComponent({__name:"node-quick-add-popover",props:{node:{},portPosition:{},autoPanOnOpen:{type:Boolean},autoPanPadding:{}},emits:["open","close","start-drag","viewport-overflow-right","mouseenter","mouseleave"],setup(n,{expose:e,emit:o}){const t=n,r=o,i=s.ref(),a=s.ref(),c=s.ref(!1),l=s.ref(!1);let v=null,p=!1,h=null;function f(F){F.preventDefault(),F.stopPropagation(),v={x:F.clientX,y:F.clientY},p=!1,document.addEventListener("mousemove",b),document.addEventListener("mouseup",A)}function b(F){if(!v)return;const d=F.clientX-v.x,w=F.clientY-v.y;Math.sqrt(d*d+w*w)>=io&&(p=!0,R(),r("start-drag",t.node.id))}function A(){R(),p||E(),v=null,p=!1}function R(){document.removeEventListener("mousemove",b),document.removeEventListener("mouseup",A)}function E(){l.value?O():N()}function N(){l.value=!0,r("open",t.node.id),s.nextTick(()=>{requestAnimationFrame(()=>{M()})}),requestAnimationFrame(()=>{document.addEventListener("mousedown",q)})}function M(){if(!l.value||!t.autoPanOnOpen||!a.value)return;const F=window.innerWidth||document.documentElement.clientWidth||0;if(F<=0)return;const d=t.autoPanPadding??16,u=a.value.getBoundingClientRect().right+d-F;u>0&&r("viewport-overflow-right",u)}function O(){l.value=!1,r("close"),document.removeEventListener("mousedown",q)}function q(F){const d=F.target;i.value?.contains(d)||a.value?.contains(d)||O()}function S(){l.value||r("mouseleave")}function G(){h&&(clearTimeout(h),h=null),r("mouseenter")}function z(){h=setTimeout(()=>{O(),r("mouseleave"),h=null},150)}return s.onBeforeUnmount(()=>{R(),h&&clearTimeout(h),document.removeEventListener("mousedown",q)}),e({closePopover:O}),(F,d)=>(s.openBlock(),s.createElementBlock("div",{class:"flow-canvas-quick-add",style:s.normalizeStyle({left:`${n.portPosition.x}px`,top:`${n.portPosition.y}px`}),onMouseenter:d[2]||(d[2]=w=>r("mouseenter")),onMouseleave:S,onClick:d[3]||(d[3]=s.withModifiers(()=>{},["stop"]))},[s.createElementVNode("div",{ref_key:"btnRef",ref:i,class:s.normalizeClass(["flow-canvas-quick-add__btn",{"is-hovered":c.value,"is-active":l.value}]),onMouseenter:d[0]||(d[0]=w=>c.value=!0),onMouseleave:d[1]||(d[1]=w=>c.value=!1),onMousedown:f},[...d[4]||(d[4]=[s.createElementVNode("i",{class:"flow-canvas-icon canvas-zoom-add"},null,-1)])],34),c.value&&!l.value?(s.openBlock(),s.createElementBlock("div",so,[...d[5]||(d[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:G,onMouseleave:z},[s.renderSlot(F.$slots,"default",{},()=>[d[6]||(d[6]=s.createElementVNode("div",{class:"flow-canvas-quick-add__default-content"},"节点快捷操作面板",-1))],!0)],544)):s.createCommentVNode("",!0)]),_:3})],36))}}),Ke=ie(ao,[["__scopeId","data-v-255b3d8c"]]),lo={class:"flow-canvas-selection-actions__bar"},co=s.defineComponent({__name:"selection-actions-toolbar",props:{position:{},canDelete:{type:Boolean}},emits:["action"],setup(n,{emit:e}){const o=n,t=e,r=s.computed(()=>({left:`${o.position.x}px`,top:`${o.position.y}px`,transform:"translateX(-100%)"}));return(i,a)=>(s.openBlock(),s.createElementBlock("div",{class:"flow-canvas-selection-actions",style:s.normalizeStyle(r.value)},[s.createElementVNode("div",lo,[s.createElementVNode("i",{class:s.normalizeClass(["flow-canvas-icon canvas-shanchu flow-canvas-selection-actions__icon",{"is-disabled":!n.canDelete}]),onClick:a[0]||(a[0]=c=>n.canDelete&&t("action","delete"))},null,2)])],4))}}),uo=ie(co,[["__scopeId","data-v-25eb8b79"]]),fo={class:"flow-canvas-runtime-core__overlay"},po=s.defineComponent({__name:"canvas-runtime-core",props:{editor:{},graphOptions:{},nodeActions:{},quickAdd:{},edgeDrop:{},getConnectionExcludedNodeIds:{type:Function},toolbarInclude:{}},emits:["ui-event"],setup(n,{expose:e,emit:o}){const t=n,r=o,i=s.ref(),a=s.ref();let c,l,v,p,h=null,f=null,b=null,A=null,R=null;const E=qt(),{hoveredNodeId:N,isDraggingNode:M}=E,O=E.enterOverlay,q=()=>E.leaveOverlay(),S=s.ref(0),G=s.ref({nodeIds:[],edgeIds:[]});function z(x){const I=t.editor.api.value;return I?t.editor.schema.nodeTypes[x.type]?.getBehavior?.(x,{api:I,flowModel:t.editor.flowModel.value,history:t.editor.history,mode:t.editor.mode.value})??{}:{}}const F=s.computed(()=>t.editor.mode.value==="edit"&&t.editor.selectionMode.value),d=s.computed(()=>({showDebug:!1,showDelete:!0,showCopy:!0,showCopyInsert:!0,showDisconnect:!0,insertGap:100,...t.nodeActions})),w=s.computed(()=>{if(S.value,!t.editor.api.value)return[];const x=t.editor.flowModel.value,I=t.editor.api.value.overlay,P=[];for(const[H,Y]of Object.entries(x.nodes)){const re=t.editor._pluginManager.collectNodeDecorations(Y);if(!re?.badge)continue;const Q=I.getNodeScreenRect(H);Q&&P.push({nodeId:H,x:Q.x+Q.width-4,y:Q.y-8,badge:re.badge})}return P}),u=s.computed(()=>{S.value;const x=N.value;if(!x||M.value||!t.editor.api.value||t.editor.mode.value!=="edit"||F.value)return null;const P=t.editor.flowModel.value.nodes[x];if(!P)return null;const H=t.editor.api.value.overlay.getNodeScreenRect(x);if(!H)return null;const Y=z(P);return Y.showActions===!1?null:{node:P,position:{x:H.x+H.width,y:H.y+H.height+4},behavior:Y}}),g=s.computed(()=>{if(S.value,!t.editor.api.value||t.editor.mode.value!=="edit")return null;const x=G.value;if(x.nodeIds.length+x.edgeIds.length===0)return null;const I=t.editor.api.value.getSelectionBounds(x);if(!I)return null;const P=We(x,t.editor.flowModel.value,z);return{position:{x:I.x+I.width,y:I.y+I.height+4},canDelete:P.nodeIds.length>0||P.edgeIds.length>0}}),m=s.ref(),y=Ut({editor:t.editor,quickAddProp:s.computed(()=>t.quickAdd),isDraggingNode:M,nodeHover:E,isSelectionModeActive:F,viewportVersion:S,getNodeBehavior:z,getInsertGap:()=>d.value.insertGap,closePopover:()=>m.value?.closePopover()}),k=y.data,T=y.handleOpen,V=y.handleStartDrag;function oe(){y.handleClose(),E.leaveOverlay(200),y.leave()}const D=y.handleOverlayEnter,_=y.handleOverlayLeave,C=y.handleInsert,B=Xt({editor:t.editor,edgeDropProp:s.computed(()=>t.edgeDrop)}),$=Kt(t.editor);function U(x,I){$.handleNodeAction(x,I,d.value.insertGap)&&(N.value=null)}function K(x){x==="delete"&&$.deleteSelection(G.value)}function j(x){if(t.editor.mode.value!=="edit")return;if((x.metaKey||x.ctrlKey)&&(x.key==="z"||x.key==="Z")){if(x.shiftKey){if(!t.toolbarInclude?.includes("redo"))return;t.editor.history.redo()}else{if(!t.toolbarInclude?.includes("undo"))return;t.editor.history.undo()}x.preventDefault();return}t.editor._pluginManager.dispatchKeyboardShortcut(x)&&(x.preventDefault(),x.stopPropagation())}function W(x,I){const P=c,H=Y=>{const re=P.isRubberbandEnabled?.()??!1;re&&P.disableRubberband?.(),Y?c.enablePanning():c.disablePanning(),re&&P.enableRubberband?.()};x&&I?(P.enableSelection?.(),E.reset(),y.quickAddNodeId.value=null,y.quickAddPopoverOpen.value=!1,h?.remove(),H(!1),P.enableRubberband?.()):(P.disableRubberband?.(),H(!0),P.disableSelection?.(),P.cleanSelection?.())}function Z(x){c.on("node:move",({node:I})=>{M.value=!0;const P=t.editor.flowModel.value.nodes[I.id];P&&z(P).bringToFrontOnDrag===!1||I.toFront?.()}),c.on("node:moved",()=>{M.value=!1}),c.on("node:mouseenter",({node:I})=>{if(F.value){N.value=null,y.quickAddNodeId.value=null,x.hideNodePorts(I);return}E.enter(I.id);const P=t.editor.flowModel.value.nodes[I.id];if(P&&z(P).showPorts===!1){y.mergedConfig.value.enabled&&y.enter(I.id);return}y.mergedConfig.value.enabled&&y.enter(I.id)||x.showNodePorts(I)}),c.on("node:mouseleave",({node:I})=>{if(F.value){x.hideNodePorts(I);return}const P=t.editor.flowModel.value.nodes[I.id];let H=100;P&&z(P).actionsOffset&&(H=300),E.leave(H),y.mergedConfig.value.enabled?y.quickAddNodeId.value===I.id&&!y.quickAddPopoverOpen.value?y.leave():y.quickAddNodeId.value!==I.id&&x.hideNodePorts(I):x.hideNodePorts(I)})}function J(x){c.on("edge:added",({edge:I})=>{let P;if(t.getConnectionExcludedNodeIds&&!I.getTargetCell()){const H=I.getSourceCell();if(H){const Y=t.getConnectionExcludedNodeIds(H.id);P=Y instanceof Set?Y:new Set(Y)}}x.handleEdgeAdded(I,P)}),c.on("edge:connected",()=>{x.handleEdgeConnected()}),c.on("edge:removed",({edge:I})=>{x.handleEdgeRemoved(I.id),h.handleEdgeRemoved(I.id)}),c.on("edge:mouseenter",({edge:I,e:P})=>{const H=l.getHoveredEdgeId();l.setHoveredEdge(I.id),H&&H!==I.id&&l.refreshSingleEdgeStyle(H),l.refreshSingleEdgeStyle(I.id),t.editor.mode.value==="edit"&&!F.value&&x.canShowEdgeTool()&&h.show(I.id,P)}),c.on("edge:mouseleave",({edge:I})=>{l.setHoveredEdge(null),l.refreshSingleEdgeStyle(I.id),h.remove()}),c.on("edge:click",({edge:I,e:P})=>{P.target?.closest?.(".flow-canvas-edge-delete-tool")&&t.editor.mode.value==="edit"&&(h.remove(),t.editor.executeCommand({id:X(),source:"user:toolbar",label:"删除连线",timestamp:Date.now(),commands:[{type:"edge.remove",edgeId:I.id}]}))}),f=I=>h.move(I),c.container.addEventListener("mousemove",f)}function le(){b=x=>{if(!N.value&&!y.quickAddNodeId.value)return;const I=x.target;if(I?.closest?.(".x6-node")||I?.closest?.(".flow-canvas-node-actions")||I?.closest?.(".flow-canvas-quick-add")){E.cancelLeave(),y.cancelLeave();return}E.leave(180),y.quickAddPopoverOpen.value||y.leave()},i.value?.addEventListener("mousemove",b),A=()=>{E.reset(),y.quickAddPopoverOpen.value||(y.quickAddNodeId.value=null)},i.value?.addEventListener("mouseleave",A),i.value?.addEventListener("keydown",j)}function Ee(){s.watch(()=>t.editor.flowModel.value,x=>l.syncFlowModel(x)),s.watch([()=>t.editor.mode.value,()=>t.editor.selectionMode.value],([x,I])=>{W(x==="edit",I)},{immediate:!0})}s.onMounted(()=>{if(!a.value)return;const x=new Set(["model","container"]),I={};if(t.graphOptions)for(const[L,ee]of Object.entries(t.graphOptions)){if(x.has(L)){console.warn(`[flow-canvas] graphOptions.${L} is managed by the engine and will be ignored`);continue}I[L]=ee}c=new at.Graph({container:a.value,autoResize:!0,background:{color:"#edf2fc"},grid:{visible:!0,size:20,type:"dot",args:{color:"#C1CADB",thickness:2}},highlighting:{magnetAdsorbed:{name:"className",args:{className:"flow-canvas-magnet-adsorbed"}}},panning:{enabled:!0},mousewheel:{enabled:!0,modifiers:["ctrl","meta"]},interacting:{nodeMovable(L){return L.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 Zt(this,t.editor.schema)}},...I}),v=new Bt,l=new Pt(c,t.editor.schema,v,L=>t.editor._pluginManager.collectNodeDecorations(L),L=>t.editor._pluginManager.collectEdgeDecorations(L),()=>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 P=Rt(c),H=zt({graph:c,overlayManager:P,executeCommand:L=>t.editor.executeCommand(B.tryExpandForEdgeDrop(L)),schema:t.editor.schema,flowModel:t.editor.flowModel,getNodeBehavior:z,idGenerator:t.editor.idGenerator,defaultInsertGap:t.nodeActions?.insertGap,getContextMenuItems:L=>t.editor._pluginManager.collectContextMenuItems(L),onHighlightChange:(L,ee)=>{l.setHighlightedNodes(L);const se=l.setHighlightedEdges(ee);l.refreshNodeHighlights();const te=new Set(ee);for(const ae of se)te.has(ae)||l.refreshSingleEdgeStyle(ae);for(const ae of te)se.has(ae)||l.refreshSingleEdgeStyle(ae)},resolveNodeShape:L=>{const ee=t.editor.schema.nodeTypes[L];if(!ee)return null;const se=v.registerNodeType(L,ee.component),te=ee.getSize({id:"",type:L,position:{x:0,y:0}});return{shapeName:se,width:te.width,height:te.height}}});t.editor.api.value=H;const Y={flowModel:t.editor.flowModel,history:t.editor.history,schema:t.editor.schema,mode:t.editor.mode,idGenerator:t.editor.idGenerator,executeCommand:t.editor.executeCommand,selectionMode:t.editor.selectionMode,api:H,overlay:P,graph:c};t.editor._pluginManager.attachRuntime(Y);const re=t.editor._pluginManager.collectExtendedApi();Object.assign(t.editor.extendedApi,re),t.editor._emitUiEvent=L=>{t.editor._pluginManager.dispatchUiEvent(L),r("ui-event",L)},p=new Tt(c,L=>{(L.type==="node.click"||L.type==="node.dblclick"||L.type==="node.contextmenu")&&E.enter(L.nodeId),t.editor._emitUiEvent(L)},L=>{if(l.isSyncing)return;const ee=B.tryExpandForEdgeDrop(L);if(t.editor.executeCommand(ee).status!=="applied"){for(const te of ee.commands)if(te.type==="edge.add"){const ae=c.getCellById(te.edge.id);ae&&c.removeCell(ae)}}},t.editor.flowModel,t.editor.idGenerator),h=Ht(c);const Q=Gt(c);y.attachRuntime(c,L=>Q.hideNodePorts(L)),B.attachRuntime(c),Z(Q),J(Q),R=to(c.container);let de=new Set,ce=new Set;c.on("selection:changed",()=>{const L=je(c.getSelectedCells?.()??[]),ee=new Set(L.nodeIds);oo(c,de,ee),de=ee,G.value=L,t.editor._pluginManager.dispatchSelectionChange(L),r("ui-event",{type:"selection.change",nodeIds:L.nodeIds,edgeIds:L.edgeIds}),l.refreshNodeHighlights();const se=new Set(L.edgeIds);for(const te of ce)se.has(te)||l.refreshSingleEdgeStyle(te);for(const te of se)ce.has(te)||l.refreshSingleEdgeStyle(te);ce=se});const ke=()=>{S.value++};c.on("translate",ke),c.on("scale",ke),c.on("resize",ke),le(),l.syncFlowModel(t.editor.flowModel.value),Ee()});function fe(){E.reset(),y.quickAddNodeId.value=null,y.quickAddPopoverOpen.value=!1}return e({resetHoverState:fe}),s.onBeforeUnmount(()=>{E.cleanup(),y.cleanup(),B.cleanup(),h?.remove(),f&&c?.container?.removeEventListener("mousemove",f),b&&i.value?.removeEventListener("mousemove",b),A&&i.value?.removeEventListener("mouseleave",A),R?.(),i.value?.removeEventListener("keydown",j),t.editor._pluginManager.detachRuntime(),t.editor.api.value=null;for(const x of Object.keys(t.editor.extendedApi))delete t.editor.extendedApi[x];p?.dispose(),l?.dispose(),v?.dispose(),c?.dispose()}),(x,I)=>(s.openBlock(),s.createElementBlock("div",{ref_key:"rootRef",ref:i,class:s.normalizeClass(["flow-canvas-runtime-core",{"flow-canvas-runtime-core--selection-mode":F.value}]),tabindex:"0"},[s.createElementVNode("div",{ref_key:"containerRef",ref:a,class:"flow-canvas-runtime-core__graph"},null,512),s.createElementVNode("div",fo,[(s.openBlock(!0),s.createElementBlock(s.Fragment,null,s.renderList(w.value,P=>(s.openBlock(),s.createElementBlock("div",{key:`badge-${P.nodeId}`,class:"flow-canvas-runtime-core__badge",style:s.normalizeStyle({left:`${P.x}px`,top:`${P.y}px`,backgroundColor:P.badge.color})},s.toDisplayString(P.badge.text),5))),128)),s.unref(k)?(s.openBlock(),s.createBlock(Ke,{key:0,ref_key:"quickAddPopoverRef",ref:m,node:s.unref(k).node,"port-position":s.unref(k).portPosition,"auto-pan-on-open":s.unref(y).mergedConfig.value.autoPanOnOpen,"auto-pan-padding":s.unref(y).mergedConfig.value.autoPanPadding,onOpen:s.unref(T),onClose:oe,onStartDrag:s.unref(V),onViewportOverflowRight:s.unref(y).handlePopoverViewportOverflow,onMouseenter:s.unref(D),onMouseleave:s.unref(_)},{default:s.withCtx(()=>[s.renderSlot(x.$slots,"quick-add-panel",{node:s.unref(k).node,api:n.editor.api.value,insertNodeToRight:P=>s.unref(C)(s.unref(k).node.id,P),closePopover:()=>m.value?.closePopover()},void 0,!0)]),_:3},8,["node","port-position","auto-pan-on-open","auto-pan-padding","onOpen","onStartDrag","onViewportOverflowRight","onMouseenter","onMouseleave"])):s.createCommentVNode("",!0),u.value?(s.openBlock(),s.createBlock(Xe,{key:1,node:u.value.node,position:u.value.position,config:d.value,behavior:u.value.behavior,"actions-offset":u.value.behavior.actionsOffset,onAction:U,onMouseenter:s.unref(O),onMouseleave:q},null,8,["node","position","config","behavior","actions-offset","onMouseenter"])):s.createCommentVNode("",!0),g.value?(s.openBlock(),s.createBlock(uo,{key:2,position:g.value.position,"can-delete":g.value.canDelete,onAction:K},null,8,["position","can-delete"])):s.createCommentVNode("",!0)])],2))}}),go=ie(po,[["__scopeId","data-v-84584822"]]),ho={class:"flow-canvas-node-palette"},vo=["data-node-type"],mo={class:"flow-canvas-node-palette__item-label"},yo=s.defineComponent({__name:"canvas-node-palette",props:{editor:{},items:{}},setup(n){const e=n,o=s.ref(),t=s.computed(()=>e.items?e.items:Object.keys(e.editor.schema.nodeTypes).map(r=>({type:r,label:r.charAt(0).toUpperCase()+r.slice(1)})));return s.watch([()=>e.editor.api.value,t,o],([r,i,a],c,l)=>{if(!r||!a)return;const v=[];for(const p of i){const h=a.querySelector(`[data-node-type="${p.type}"]`);if(!h)continue;const f=r.registerDndSource(h,()=>({id:X(),type:p.type,label:p.label,position:{x:0,y:0}}));v.push(f)}l(()=>{for(const p of v)p()})},{flush:"post"}),(r,i)=>(s.openBlock(),s.createElementBlock("div",ho,[s.createElementVNode("div",{ref_key:"listRef",ref:o,class:"flow-canvas-node-palette__list"},[(s.openBlock(!0),s.createElementBlock(s.Fragment,null,s.renderList(t.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",mo,s.toDisplayString(a.label),1)],8,vo))),128))],512)]))}}),Ye=ie(yo,[["__scopeId","data-v-300314b7"]]),wo={class:"flow-canvas-layout"},bo={class:"flow-canvas-layout__main"},Eo={class:"flow-canvas-layout__content"},ko={key:0,class:"flow-canvas-layout__footer"},Co=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(n){return(e,o)=>(s.openBlock(),s.createElementBlock("div",wo,[!n.hideSidebar&&(e.$slots.sidebar||n.editor)?(s.openBlock(),s.createElementBlock("aside",{key:0,class:s.normalizeClass(["flow-canvas-layout__sidebar",{"is-collapsed":n.sidebarCollapsed}]),style:s.normalizeStyle({width:n.sidebarCollapsed?"0px":`${n.sidebarWidth}px`})},[s.renderSlot(e.$slots,"sidebar",{},()=>[n.editor?(s.openBlock(),s.createBlock(Ye,{key:0,editor:n.editor,items:n.paletteItems},null,8,["editor","items"])):s.createCommentVNode("",!0)],!0)],6)):s.createCommentVNode("",!0),s.createElementVNode("div",bo,[s.createElementVNode("div",Eo,[s.renderSlot(e.$slots,"default",{},void 0,!0)]),!n.hideFooter&&e.$slots.footer?(s.openBlock(),s.createElementBlock("div",ko,[s.renderSlot(e.$slots,"footer",{},void 0,!0)])):s.createCommentVNode("",!0)])]))}}),xo=ie(Co,[["__scopeId","data-v-26f35b6b"]]),Oe=typeof navigator<"u"&&/Mac|iPod|iPhone|iPad/.test(navigator.platform??navigator.userAgent),Io=["undo","redo"];function Ze(n){const e=new Set(n?.include),o=new Set(Io.filter(l=>!e.has(l))),t=[{id:"undo",type:"undo",group:"history",icon:"flow-canvas-icon canvas-undo",description:"撤销",shortcut:Oe?["⌘","Z"]:["Ctrl","Z"],order:10},{id:"redo",type:"redo",group:"history",icon:"flow-canvas-icon canvas-redo",description:"重做",shortcut:Oe?["⇧","⌘","Z"]:["Ctrl","Shift","Z"],order:11}],r=[{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:"export",type:"export",group:"tools",icon:"flow-canvas-icon canvas-xiazai",description:"下载",order:24}],i=[{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[...[...t,...r].filter(l=>!o.has(l.type)),...i,...a]}const So={class:"flow-canvas-toolbar"},No={key:0,class:"flow-canvas-toolbar__separator"},Mo={class:"flow-canvas-toolbar__group"},Do={key:0,class:"flow-canvas-toolbar__zoom-display"},Ao=["data-toolbar-id","data-toolbar-type","disabled","onClick","onMouseenter"],_o=["textContent"],Po={key:0,class:"flow-canvas-toolbar-tooltip__kbd"},Bo=s.defineComponent({__name:"canvas-toolbar",props:{items:{},exclude:{},include:{},editor:{}},setup(n){const e=new Set(["undo","redo","select","auto-layout","search","minimap","export"]),o=new Set(["select","search","minimap"]);function t(u){return u.id.startsWith("plugin:")||u.type==="custom"}function r(u){return u!=="custom"&&o.has(u)}const i=n,a=s.computed(()=>{if(i.items)return i.items;const u=Ze({include:i.include}),g=i.editor.toolbarItems.value,m=new Set(i.exclude??[]),y=new Map;for(const k of u)y.set(k.id,k);for(const k of g){const T=y.get(k.id);T?y.set(k.id,{...T,...k,order:T.order,group:T.group}):t(k)&&y.set(k.id,k)}return[...y.values()].filter(k=>k.type==="custom"||!e.has(k.type)?!0:!m.has(k.type)).sort((k,T)=>(k.order??0)-(T.order??0))}),c=s.ref(1),l=s.ref(null),v=s.ref(null),p=s.ref(!1);let h=null;s.watch(()=>i.editor.api.value,u=>{h?.(),h=null,u&&(c.value=u.getZoom(),h=u.onGraphEvent("scale",()=>{c.value=u.getZoom()}))},{immediate:!0});const f=s.reactive({visible:!1,text:"",shortcut:[],x:0,y:0});function b(u,g){if(!g.description)return;const y=u.currentTarget.getBoundingClientRect();f.text=g.description,f.shortcut=g.shortcut??[],f.visible=!0,s.nextTick(()=>{const k=l.value?.offsetWidth??0,T=l.value?.offsetHeight??0;f.x=y.left+y.width/2-k/2,f.y=y.top-T-6})}function A(){f.visible=!1,l.value=null}s.onScopeDispose(()=>{h?.()});const R=s.computed(()=>`${Math.round(c.value*100)}%`),E=s.computed(()=>i.editor.api.value?{api:i.editor.api.value,flowModel:i.editor.flowModel.value,history:i.editor.history,mode:i.editor.mode.value}:null);function N(u){return u.visible===!1?!1:typeof u.visible=="function"?E.value?u.visible(E.value):!1:!0}function M(u){return typeof u.active=="function"?E.value?u.active(E.value):!1:u.active!==void 0?u.active:u.type==="select"?i.editor.selectionMode.value:!1}const O=s.computed(()=>{const u=d.value.filter(m=>r(m.type)&&M(m));if(u.length===0)return null;const g=v.value;return g&&u.some(m=>m.type===g)?g:u[0]?.type??null});function q(u){return r(u.type)?O.value===u.type:M(u)}function S(u){return!E.value||u.disabled===!0?!0:typeof u.disabled=="function"?u.disabled(E.value):u.type==="undo"?!i.editor.history.canUndo.value:u.type==="redo"?!i.editor.history.canRedo.value:u.type==="export"?p.value:!1}function G(u){if(!(!E.value||!r(u.type)||!M(u))){if(u.type==="select"){i.editor.setSelectionMode(!1);return}u.onClick?.(E.value)}}function z(u){if(r(u.type))for(const g of d.value)!r(g.type)||g.id===u.id||G(g)}function F(u){if(!E.value||S(u))return;if(r(u.type)&&(v.value=u.type,z(u)),u.onClick){u.onClick(E.value);return}const{api:g}=E.value;switch(u.type){case"undo":i.editor.history.undo();break;case"redo":i.editor.history.redo();break;case"zoom-in":g.zoomIn(),c.value=g.getZoom();break;case"zoom-out":g.zoomOut(),c.value=g.getZoom();break;case"fit":g.zoomToFit();break;case"reset":g.zoomTo(1),g.scrollToOrigin(),c.value=1;break;case"export":if(p.value)break;p.value=!0,g.exportAsImage().then(m=>{const y=URL.createObjectURL(m),k=document.createElement("a");k.href=y,k.download="canvas-export.png",k.click(),URL.revokeObjectURL(y)}).catch(m=>{console.warn("[flow-canvas] Export failed:",m)}).finally(()=>{p.value=!1});break;case"select":i.editor.setSelectionMode(!i.editor.selectionMode.value);break;case"auto-layout":i.editor._emitUiEvent({type:"toolbar.auto-layout"});break;case"search":case"minimap":console.warn(`[flow-canvas] "${u.type}" toolbar item has no built-in handler. Provide an onClick callback.`);break;default:u.type!=="custom"&&console.warn(`[flow-canvas] No default handler for toolbar type "${u.type}". Provide an onClick handler.`);break}}const d=s.computed(()=>a.value.filter(N)),w=s.computed(()=>{const u=new Map,g=[];for(const m of d.value){const y=m.group??"default";u.has(y)||(u.set(y,[]),g.push(y)),u.get(y).push(m)}return g.map(m=>({name:m,items:u.get(m)})).filter(m=>m.items.length>0)});return(u,g)=>(s.openBlock(),s.createElementBlock("div",So,[(s.openBlock(!0),s.createElementBlock(s.Fragment,null,s.renderList(w.value,(m,y)=>(s.openBlock(),s.createElementBlock(s.Fragment,{key:m.name},[y>0?(s.openBlock(),s.createElementBlock("div",No)):s.createCommentVNode("",!0),s.createElementVNode("div",Mo,[(s.openBlock(!0),s.createElementBlock(s.Fragment,null,s.renderList(m.items,k=>(s.openBlock(),s.createElementBlock(s.Fragment,{key:k.id},[k.type==="zoom-display"?(s.openBlock(),s.createElementBlock("span",Do,s.toDisplayString(R.value),1)):(s.openBlock(),s.createElementBlock("button",{key:1,type:"button",class:s.normalizeClass(["flow-canvas-toolbar__btn",{"is-disabled":S(k),"is-active":q(k),"is-exporting":k.type==="export"&&p.value}]),"data-toolbar-id":k.id,"data-toolbar-type":k.type,disabled:S(k),onClick:T=>F(k),onMouseenter:T=>b(T,k),onMouseleave:A},[k.component?(s.openBlock(),s.createBlock(s.resolveDynamicComponent(k.component),{key:0})):k.icon?(s.openBlock(),s.createElementBlock("i",{key:1,class:s.normalizeClass(k.icon)},null,2)):(s.openBlock(),s.createElementBlock("span",{key:2,class:"flow-canvas-toolbar__text",textContent:s.toDisplayString(k.text??k.description??k.id)},null,8,_o))],42,Ao))],64))),128))])],64))),128)),(s.openBlock(),s.createBlock(s.Teleport,{to:"body"},[f.visible?(s.openBlock(),s.createElementBlock("div",{key:0,ref_key:"tooltipRef",ref:l,class:"flow-canvas-toolbar-tooltip",style:s.normalizeStyle({left:`${f.x}px`,top:`${f.y}px`})},[s.createElementVNode("span",null,s.toDisplayString(f.text),1),f.shortcut.length?(s.openBlock(),s.createElementBlock("kbd",Po,[(s.openBlock(!0),s.createElementBlock(s.Fragment,null,s.renderList(f.shortcut,(m,y)=>(s.openBlock(),s.createElementBlock("span",{key:y},s.toDisplayString(m),1))),128))])):s.createCommentVNode("",!0),g[0]||(g[0]=s.createElementVNode("div",{class:"flow-canvas-toolbar-tooltip__arrow"},null,-1))],4)):s.createCommentVNode("",!0)]))]))}}),To=ie(Bo,[["__scopeId","data-v-904248f4"]]),Ro={class:"flow-canvas-default-node__ep-label"},Lo={key:1,class:"flow-canvas-default-node__diamond flow-canvas-highlight-target"},Oo={key:2,class:"flow-canvas-default-node__task-label"},$o=s.defineComponent({__name:"default-node",setup(n){const o=s.inject("getNode")?.(),t=s.computed(()=>o?.getData?.()??null),r=s.computed(()=>t.value?.label||t.value?.type||""),i={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"]),c=new Set(["parallel-gateway","branch-gateway","converge-gateway","conditional-parallel-gateway"]),l=s.computed(()=>{const p=t.value?.type??"";return a.has(p)?"endpoint":c.has(p)?"gateway":"task"}),v=s.computed(()=>i[t.value?.type??""]??"");return(p,h)=>(s.openBlock(),s.createElementBlock("div",{class:s.normalizeClass(["flow-canvas-default-node",[`is-${l.value}`,{"flow-canvas-highlight-target":l.value!=="gateway"}]])},[l.value==="endpoint"?(s.openBlock(),s.createElementBlock(s.Fragment,{key:0},[v.value?(s.openBlock(),s.createElementBlock("i",{key:0,class:s.normalizeClass([["flow-canvas-icon",v.value],"flow-canvas-default-node__ep-icon"])},null,2)):s.createCommentVNode("",!0),s.createElementVNode("span",Ro,s.toDisplayString(r.value),1)],64)):l.value==="gateway"?(s.openBlock(),s.createElementBlock("div",Lo,[v.value?(s.openBlock(),s.createElementBlock("i",{key:0,class:s.normalizeClass([["flow-canvas-icon",v.value],"flow-canvas-default-node__gw-icon"])},null,2)):s.createCommentVNode("",!0)])):(s.openBlock(),s.createElementBlock("span",Oo,s.toDisplayString(r.value),1))],2))}}),Qe=ie($o,[["__scopeId","data-v-f0e24a9f"]]),Fo={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}},$e=(n,e)=>({stroke:e.hovered?"#3a84ff":"#abb5cc",strokeWidth:2});function Fe(){return{attrs:{line:{stroke:"#abb5cc",strokeWidth:2,targetMarker:{name:"block",width:8,height:8}}}}}function Je(){return{manhattan:{router:{name:"manhattan",args:{padding:10,maxDirectionChange:90}},connector:{name:"rounded",args:{radius:8}},style:$e,x6EdgeConfig:Fe()},bezier:{connector:{name:"smooth"},style:$e,x6EdgeConfig:Fe()}}}function Vo(n){const e=n?.nodeTypes??Fo,o={},t=[];for(const[a,c]of Object.entries(e)){const l=c.width??150,v=c.height??50;o[a]={component:Qe,getSize:()=>({width:l,height:v}),getPorts:()=>Ue()},t.push({type:a,label:c.label??a,icon:c.icon})}const r={...Je(),...n?.edgeTypes},i=n?.defaultEdgeType??"manhattan";return{schema:{nodeTypes:o,defaultEdgeType:i,edgeTypes:r},paletteItems:t}}function zo(n){return{name:"connection-validator",priority:10,transformCommand(e,o,t){const r=new Set;for(const i of e.commands)i.type==="edge.remove"&&r.add(i.edgeId);for(const i of e.commands){if(i.type!=="edge.add"&&i.type!=="edge.reconnect")continue;const a=t.flowModel.value,c=i.type==="edge.add"?i.edge.source.nodeId:i.source?.nodeId,l=i.type==="edge.add"?i.edge.target.nodeId:i.target?.nodeId;if(!c||!l)continue;const v=a.nodes[c],p=a.nodes[l];if(!v||!p)continue;const h=i.type==="edge.add"?i.edge.source.portId:i.source?.portId,f=i.type==="edge.add"?i.edge.target.portId:i.target?.portId,b=h?v.ports?.find(M=>M.id===h):void 0,A=f?p.ports?.find(M=>M.id===f):void 0,R=i.type==="edge.reconnect"?i.edgeId:void 0,E=Object.values(a.edges).filter(M=>M.id!==R&&!r.has(M.id)),N=n({flowModel:a,sourceNode:v,targetNode:p,sourcePort:b,targetPort:A,existingEdges:E});if(!N.valid)return{rejected:!0,reason:N.reason??"Connection validation failed",code:"validation_failed"}}return e}}}function qo(n){const{rubberband:e=!0,multiple:o=!0,movable:t=!0}=n??{};return{name:"selection",priority:90,attachRuntime(r){r.graph.use(new ct.Selection({enabled:!0,rubberband:e,multiple:o,movable:t,pointerEvents:"none",showNodeSelectionBox:!0,filter:i=>!(i.isNode()&&(i.getData?.()??{})._selectable===!1)}))}}}function Ho(n){const{tolerance:e=10,color:o="#3a84ff"}=n??{};let t=null;return{name:"snapline",priority:90,async attachRuntime(r){const{Snapline:i}=await import("@antv/x6-plugin-snapline");r.graph.use(new i({enabled:!0,tolerance:e,className:"flow-canvas-snapline"})),t=document.createElement("style"),t.textContent=`.flow-canvas-snapline line { stroke: ${o} !important; }`,document.head.appendChild(t)},detachRuntime(){t?.remove(),t=null}}}const Go={class:"flow-canvas-search-popover__input-box"},Uo=["value","placeholder"],jo={key:0,class:"flow-canvas-search-popover__no-result"},Wo={class:"flow-canvas-search-popover__counter"},Xo=["onMouseenter","onClick"],Ko={class:"flow-canvas-search-popover__item-label"},Yo=s.defineComponent({__name:"search-popover",props:{open:{type:Boolean},position:{},query:{},results:{},matchIndex:{default:-1},placeholder:{default:"搜索节点名称"},isAnchorTarget:{type:Function,default:void 0}},emits:["update:query","select","nextMatch","prevMatch","close"],setup(n,{emit:e}){const o=n,t=e,r=s.ref(null),i=s.ref(null),a=s.ref(-1);s.watch(()=>o.open,f=>{f&&(a.value=-1,s.nextTick(()=>{r.value?.focus(),r.value?.select()}))}),s.watch(()=>o.query,()=>{a.value=-1}),s.watch(()=>o.results.length,f=>{if(!f){a.value=-1;return}a.value>=f&&(a.value=-1)});function c(f){t("update:query",f.target.value)}function l(f){a.value=f}function v(){a.value=-1}function p(f){if(f.key==="Escape"){f.preventDefault(),t("close");return}if(f.key==="ArrowDown"){if(f.preventDefault(),!o.results.length)return;a.value=a.value<o.results.length-1?a.value+1:0;return}if(f.key==="ArrowUp"){if(f.preventDefault(),!o.results.length)return;a.value=a.value>0?a.value-1:o.results.length-1;return}if(f.key==="Enter"){if(f.preventDefault(),a.value>=0){const b=o.results[a.value];b&&t("select",b.id);return}f.shiftKey?t("prevMatch"):t("nextMatch")}}function h(f){if(!o.open)return;const b=f.target;b&&i.value?.contains(b)||o.isAnchorTarget?.(f.target)||t("close")}return s.onMounted(()=>{document.addEventListener("mousedown",h)}),s.onBeforeUnmount(()=>{document.removeEventListener("mousedown",h)}),(f,b)=>n.open?(s.openBlock(),s.createElementBlock("div",{key:0,ref_key:"panelRef",ref:i,class:"flow-canvas-search-popover",style:s.normalizeStyle({left:`${n.position.x}px`,top:`${n.position.y}px`,width:`${n.position.width}px`})},[s.createElementVNode("div",Go,[s.createElementVNode("input",{ref_key:"inputRef",ref:r,value:n.query,placeholder:n.placeholder,onInput:c,onKeydown:p},null,40,Uo),n.query?(s.openBlock(),s.createElementBlock(s.Fragment,{key:0},[n.results.length?(s.openBlock(),s.createElementBlock(s.Fragment,{key:1},[s.createElementVNode("button",{type:"button",class:"flow-canvas-search-popover__nav-btn","aria-label":"上一个",onClick:b[0]||(b[0]=A=>t("prevMatch"))},[...b[2]||(b[2]=[s.createElementVNode("svg",{viewBox:"0 0 16 16",width:"12",height:"12"},[s.createElementVNode("path",{d:"M10.3 12.3 6 8l4.3-4.3",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])]),s.createElementVNode("span",Wo,s.toDisplayString(n.matchIndex>=0?n.matchIndex+1:0)+" / "+s.toDisplayString(n.results.length),1),s.createElementVNode("button",{type:"button",class:"flow-canvas-search-popover__nav-btn","aria-label":"下一个",onClick:b[1]||(b[1]=A=>t("nextMatch"))},[...b[3]||(b[3]=[s.createElementVNode("svg",{viewBox:"0 0 16 16",width:"12",height:"12"},[s.createElementVNode("path",{d:"M5.7 3.7 10 8l-4.3 4.3",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"})],-1)])])],64)):(s.openBlock(),s.createElementBlock("span",jo,"无结果"))],64)):s.createCommentVNode("",!0),b[4]||(b[4]=s.createElementVNode("i",{class:"flow-canvas-icon canvas-search flow-canvas-search-popover__search-icon"},null,-1))]),n.query&&n.results.length?(s.openBlock(),s.createElementBlock("div",{key:0,class:"flow-canvas-search-popover__list-box",onMouseleave:v},[(s.openBlock(!0),s.createElementBlock(s.Fragment,null,s.renderList(n.results,(A,R)=>(s.openBlock(),s.createElementBlock("button",{key:A.id,type:"button",class:s.normalizeClass(["flow-canvas-search-popover__item",{"is-active":R===a.value,"is-matched":R===n.matchIndex}]),onMouseenter:E=>l(R),onClick:E=>t("select",A.id)},[s.createElementVNode("span",Ko,s.toDisplayString(A.label),1)],42,Xo))),128))],32)):s.createCommentVNode("",!0)],4)):s.createCommentVNode("",!0)}}),Zo=ie(Yo,[["__scopeId","data-v-aca2b1c1"]]),Ve=282,Qo=4,Jo=300,ve="flow-canvas-node-ring-target--search-match",me="flow-canvas-node-ring-target--search-current",en="flow-canvas-node-ring-target";function tn(n){return n!==null}function on(n){const e=new Set;return n.map(o=>o?.trim()).filter(o=>!!o).filter(o=>{const t=o.toLowerCase();return e.has(t)?!1:(e.add(t),!0)})}function nn(n,e){const o=Math.max(8,window.innerWidth-e-8);return Math.min(Math.max(8,n),o)}function rn(n,e){const o=e?.getNodeMeta?.(n);if(o===null)return null;const t=o?.label?.trim()||n.label?.trim()||n.id,r=o?.subtitle?.trim()||void 0,i=on(o?.keywords??[n.label,r]);return i.length?{id:n.id,label:t,subtitle:r,keywords:i}:null}function sn(n){let e=null,o=null,t=null,r=null,i=null,a=null;const c=s.ref(!1),l=s.ref(""),v=s.ref({x:0,y:0,width:Ve}),p=s.ref(-1),h=s.computed(()=>e?Object.values(e.flowModel.value.nodes).map(g=>rn(g,n)).filter(tn):[]),f=s.computed(()=>{const g=l.value.trim().toLowerCase(),m=Math.max(1,n?.maxResults??Jo);return g?h.value.filter(y=>y.keywords.some(k=>k.toLowerCase().includes(g))).slice(0,m):h.value.slice(0,m)});function b(){return t?.querySelector('.flow-canvas-toolbar__btn[data-toolbar-type="search"]')}function A(){return b()?.closest(".flow-canvas-toolbar")}function R(){const g=A(),m=t?.getBoundingClientRect(),y=g?.getBoundingClientRect()??m;if(!y)return;const k=Math.max(Ve,Math.round(y.width));v.value={x:nn(y.left,k),y:y.bottom+Qo,width:k}}function E(g){if(!o)return null;const m=o.graph.getCellById(g);if(!m?.isNode())return null;const y=o.graph.findViewByCell(m)?.container;return y?y.querySelector(".flow-canvas-highlight-target")??y.querySelector(".flow-canvas-node-surface > :first-child"):null}function N(){if(!o)return;const g=o.graph.getNodes();for(const m of g){const y=E(m.id);y&&y.classList.remove(ve,me)}}function M(){if(!o)return;const g=l.value.trim().toLowerCase();if(!c.value||!g){N();return}const m=new Set(f.value.map(T=>T.id)),y=p.value>=0?f.value[p.value]?.id:null,k=o.graph.getNodes();for(const T of k){const V=E(T.id);V&&(V.classList.add(en),T.id===y?(V.classList.remove(ve),V.classList.add(me)):m.has(T.id)?(V.classList.remove(me),V.classList.add(ve)):V.classList.remove(ve,me))}}function O(g){if(!o)return;const m=f.value.findIndex(y=>y.id===g);m>=0&&(p.value=m),o.api.scrollToNode(g),M()}function q(){const g=f.value;if(g.length===0)return;const m=p.value<g.length-1?p.value+1:0;p.value=m,O(g[m].id)}function S(){const g=f.value;if(g.length===0)return;const m=p.value>0?p.value-1:g.length-1;p.value=m,O(g[m].id)}function G(){o&&(c.value=!0,R(),requestAnimationFrame(()=>R()))}function z(){c.value=!1,l.value="",p.value=-1,N()}function F(){if(c.value){z();return}G()}function d(g){const m=b();return!!(m&&g instanceof Node&&m.contains(g))}function w(){c.value&&R()}const u=s.defineComponent({name:"FlowCanvasSearchHost",setup(){return()=>s.h(Zo,{open:c.value,position:v.value,query:l.value,results:f.value,matchIndex:p.value,placeholder:n?.placeholder??"搜索节点名称",isAnchorTarget:d,"onUpdate:query":g=>{l.value=g,p.value=-1},onSelect:O,onNextMatch:q,onPrevMatch:S,onClose:z})}});return{name:"search",priority:90,install(g){e=g},attachRuntime(g){o=g,t=g.graph.container.closest(".flow-canvas-layout__content")??g.graph.container.parentElement,r=document.createElement("div"),r.className="flow-canvas-search-host",document.body.append(r),i=s.createApp(u),i.mount(r),a=s.watch(()=>[l.value,f.value.length],()=>{p.value=-1,M()}),window.addEventListener("resize",w),window.addEventListener("scroll",w,!0)},detachRuntime(){z(),a?.(),a=null,window.removeEventListener("resize",w),window.removeEventListener("scroll",w,!0),i?.unmount(),i=null,r?.remove(),r=null,t=null,o=null},dispose(){z(),a?.(),a=null,e=null},provideToolbarItems(){return[{id:"plugin:search",type:"search",icon:"flow-canvas-icon canvas-search",description:"搜索",group:"tools",order:22,active:()=>c.value,onClick:F}]}}}const ze=52,qe=16,et=4,an=40;function ln(n){const{mountRect:e,toolbarRect:o,fallbackLeft:t,fallbackTop:r,fallbackWidth:i,height:a}=n,c=n.offset??et;return!o||o.width<=0?{left:t,top:r,width:i,height:a}:{left:Math.round(o.left-e.left),top:Math.round(o.bottom-e.top+c),width:Math.round(o.width),height:a}}function cn(n){const e=document.createElement("div");e.className="flow-canvas-minimap",n.floating!==!1&&e.classList.add("flow-canvas-minimap--floating");const o=document.createElement("div");o.className="flow-canvas-minimap__host",e.append(o),Object.assign(e.style,{width:`${n.width}px`,height:`${n.height}px`}),n.floating!==!1&&Object.assign(e.style,{top:`${ze}px`,left:`${qe}px`});let t=null,r=n.defaultOpen??!1,i=null,a=null,c=null,l=null,v={width:n.width,height:n.height};function p(S,G){if(!t)return;const z=t;z.options.width=S,z.options.height=G,z.updatePaper(n.sourceGraph.container.clientWidth,n.sourceGraph.container.clientHeight)}function h(){if(n.floating===!1)return;const S=ln({mountRect:n.mountTarget.getBoundingClientRect(),toolbarRect:n.getToolbarElement?.()?.getBoundingClientRect()??null,fallbackLeft:qe,fallbackTop:ze,fallbackWidth:n.width,height:n.height,offset:n.panelOffset??et});v={width:S.width,height:S.height},Object.assign(e.style,{left:`${S.left}px`,top:`${S.top}px`,width:`${S.width}px`,height:`${S.height}px`}),p(S.width,S.height)}function f(){if(n.floating===!1||typeof ResizeObserver>"u")return;const S=n.getToolbarElement?.()??null;a||(a=new ResizeObserver(()=>{r&&(f(),h())})),l!==S&&(a.disconnect(),a.observe(n.mountTarget),S&&a.observe(S),l=S)}function b(){n.floating!==!1&&(h(),f(),c||(c=()=>{r&&(f(),h())},window.addEventListener("resize",c)))}function A(){c&&(window.removeEventListener("resize",c),c=null),a?.disconnect(),a=null,l=null}function R(){!n.onClickOutside||i||(i=S=>{const G=S.target;G&&e.contains(G)||S.target?.closest('[data-toolbar-type="minimap"]')||S.target?.closest(".flow-canvas-layout__content")||n.onClickOutside()},document.addEventListener("mousedown",i))}function E(){i&&(document.removeEventListener("mousedown",i),i=null)}function N(){t||(t=new dt.MiniMap({container:o,width:v.width,height:v.height,padding:n.contentPadding??an,scalable:!1}),n.sourceGraph.use(t))}function M(S){r=S,e.style.display=r?"":"none",r?(b(),N(),R(),requestAnimationFrame(()=>{r&&(f(),h())})):(E(),A())}function O(){M(r),n.mountTarget.appendChild(e)}function q(){E(),A(),t?.dispose(),t=null,e.remove()}return O(),{element:e,isOpen:()=>r,setOpen:M,toggle(){const S=!r;return M(S),S},destroy:q}}function dn(n){let e=null,o=null;const t=s.ref(!1);function r(){return o?.querySelector('.flow-canvas-toolbar__btn[data-toolbar-type="minimap"]')}function i(){return r()?.closest(".flow-canvas-toolbar")}function a(l){e?.setOpen(l),t.value=l}function c(){e&&(t.value=e.toggle())}return{name:"minimap",priority:90,attachRuntime(l){const v=l,p=n?.width??334,h=n?.height??180;o=v.graph.container.closest(".flow-canvas-layout__content")??v.graph.container.parentElement;const f=n?.container??o;f&&(e=cn({sourceGraph:l.graph,mountTarget:f,width:p,height:h,floating:!n?.container,defaultOpen:!1,getToolbarElement:n?.container?void 0:i,onClickOutside:()=>a(!1)}),a(!1))},detachRuntime(){e?.destroy(),e=null,o=null,t.value=!1},provideToolbarItems(){return[{id:"plugin:minimap",type:"minimap",icon:"flow-canvas-icon canvas-map",description:"小地图",group:"tools",order:23,active:()=>t.value,onClick:c}]}}}function un(){let n=null,e=0;return{name:"clipboard",priority:90,onKeyboardShortcut(o,t){const r=o.metaKey||o.ctrlKey;if(r&&o.key==="c"){const i=t.graph.getSelectedCells?.()??[];if(!i.length)return!1;const a=t.flowModel.value,c=new Set(i.filter(p=>p.isNode()).map(p=>p.id)),l=[...c].map(p=>a.nodes[p]).filter(Boolean);if(!l.length)return!1;const v=Object.values(a.edges).filter(p=>c.has(p.source.nodeId)&&c.has(p.target.nodeId));return n={nodes:l,edges:v},e=0,!0}if(r&&o.key==="v"){if(!n?.nodes.length)return!1;e++;const i=e*30,a=new Map,c=[];for(const l of n.nodes){const v=`${l.id}_cp${X().slice(0,6)}`;a.set(l.id,v),c.push({type:"node.add",node:{...l,id:v,position:{x:l.position.x+i,y:l.position.y+i},payload:l.payload?{...l.payload}:{},extensions:l.extensions?{...l.extensions}:void 0}})}for(const l of n.edges){const v=a.get(l.source.nodeId),p=a.get(l.target.nodeId);!v||!p||c.push({type:"edge.add",edge:{...l,id:`${l.id}_cp${X().slice(0,6)}`,source:{...l.source,nodeId:v},target:{...l.target,nodeId:p},labels:l.labels?.map(h=>({...h,id:`${h.id}_cp${X().slice(0,6)}`})),payload:l.payload?{...l.payload}:{}}})}return c.length&&t.executeCommand({id:X(),source:"user:keyboard",label:"粘贴",timestamp:Date.now(),commands:c}),!0}return!1}}}exports.CanvasConstraintError=ne;exports.CanvasLayout=xo;exports.CanvasNodePalette=Ye;exports.CanvasRuntime=go;exports.CanvasSchemaError=He;exports.CanvasToolbar=To;exports.DefaultNode=Qe;exports.NodeActionsToolbar=Xe;exports.NodeQuickAddPopover=Ke;exports.applyCanvasCommand=Ie;exports.clipboardPlugin=un;exports.connectionValidatorPlugin=zo;exports.createBuiltinEdgeTypes=Je;exports.createCanvasHistory=Ge;exports.createDefaultSchema=Vo;exports.createDefaultToolbarItems=Ze;exports.createEmptyFlowModel=ut;exports.generateId=X;exports.minimapPlugin=dn;exports.searchPlugin=sn;exports.selectionPlugin=qo;exports.snaplinePlugin=Ho;exports.useCanvasEditor=Mt;
|