@blueking/flow-canvas 0.0.4 → 0.0.6

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 CHANGED
@@ -1 +1 @@
1
- "use strict";var Fe=Object.create;var we=Object.defineProperty;var Ge=Object.getOwnPropertyDescriptor;var Ue=Object.getOwnPropertyNames;var je=Object.getPrototypeOf,We=Object.prototype.hasOwnProperty;var Xe=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ue(e))!We.call(s,n)&&n!==t&&we(s,n,{get:()=>e[n],enumerable:!(r=Ge(e,n))||r.enumerable});return s};var he=(s,e,t)=>(t=s!=null?Fe(je(s)):{},Xe(e||!s||!s.__esModule?we(t,"default",{value:s,enumerable:!0}):t,s));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("vue"),Ke=require("@antv/x6"),Ye=require("@antv/x6-vue-shape"),Qe=require("@antv/x6-plugin-selection"),Ze=require("@antv/x6-plugin-minimap");function Je(){return{version:"1.0",nodes:{},edges:{}}}class ee extends Error{constructor(e){super(e),this.name="CanvasConstraintError"}}class Ae extends Error{constructor(e){super(e),this.name="CanvasSchemaError"}}function fe(s,e,t){if(e.length===0){if(t===void 0)return;if(typeof t!="object"||t===null||Array.isArray(t))throw new Error("Root value of payload/extensions/meta must be an object or undefined");return t}const r=s?{...s}:{};let n=r;for(let a=0;a<e.length-1;a++){const c=e[a],l=n[c];l&&typeof l=="object"&&!Array.isArray(l)?n[c]={...l}:n[c]={},n=n[c]}const i=e[e.length-1];return t===void 0?delete n[i]:n[i]=t,r}function ue(s,e){switch(e.type){case"node.add":return et(s,e.node);case"node.move":return tt(s,e.nodeId,e.position);case"node.remove":return ot(s,e.nodeId);case"node.update":return nt(s,e.nodeId,e.patch);case"node.set-payload":return st(s,e.nodeId,e.path,e.value);case"node.set-extensions":return rt(s,e.nodeId,e.path,e.value);case"edge.add":return it(s,e.edge);case"edge.remove":return at(s,e.edgeId);case"edge.reconnect":return lt(s,e.edgeId,e.source,e.target);case"edge.update":return ct(s,e.edgeId,e.patch);case"edge.set-payload":return dt(s,e.edgeId,e.path,e.value);case"edge.label.update":return ut(s,e.edgeId,e.labelId,e.patch);case"model.set-meta":return ft(s,e.path,e.value);default:throw new ee(`Unknown command type: ${e.type}`)}}function ae(s,e){const t=s.nodes[e];if(!t)throw new ee(`Node "${e}" does not exist`);return t}function le(s,e){const t=s.edges[e];if(!t)throw new ee(`Edge "${e}" does not exist`);return t}function re(s,e,t){const r=s.nodes[e.nodeId];if(!r)throw new ee(`${t} node "${e.nodeId}" does not exist`);if(e.portId&&r.ports&&!r.ports.some(i=>i.id===e.portId))throw new ee(`${t} port "${e.portId}" not found on node "${e.nodeId}"`)}function pe(s,e,t){return{...s,nodes:{...s.nodes,[e]:t}}}function ge(s,e,t){return{...s,edges:{...s.edges,[e]:t}}}function et(s,e){if(s.nodes[e.id])throw new ee(`Node id "${e.id}" already exists`);return{...s,nodes:{...s.nodes,[e.id]:e}}}function tt(s,e,t){const r=ae(s,e);return pe(s,e,{...r,position:t})}function ot(s,e){ae(s,e);const{[e]:t,...r}=s.nodes,n={};for(const[i,a]of Object.entries(s.edges))a.source.nodeId!==e&&a.target.nodeId!==e&&(n[i]=a);return{...s,nodes:r,edges:n}}function nt(s,e,t){const r=ae(s,e);return pe(s,e,{...r,...t,id:r.id})}function st(s,e,t,r){const n=ae(s,e),i=fe(n.payload,t,r);return pe(s,e,{...n,payload:i})}function rt(s,e,t,r){const n=ae(s,e),i=fe(n.extensions,t,r);return pe(s,e,{...n,extensions:i})}function it(s,e){if(s.edges[e.id])throw new ee(`Edge id "${e.id}" already exists`);if(re(s,e.source,"Source"),re(s,e.target,"Target"),e.labels){const t=new Set;for(const r of e.labels){if(t.has(r.id))throw new ee(`Duplicate label id "${r.id}" in edge "${e.id}"`);t.add(r.id)}}return{...s,edges:{...s.edges,[e.id]:e}}}function at(s,e){le(s,e);const{[e]:t,...r}=s.edges;return{...s,edges:r}}function lt(s,e,t,r){const n=le(s,e),i=t??n.source,a=r??n.target;return re(s,i,"Source"),re(s,a,"Target"),ge(s,e,{...n,source:i,target:a})}function ct(s,e,t){const r=le(s,e),n={...r,...t,id:r.id};return t.source&&re(s,n.source,"Source"),t.target&&re(s,n.target,"Target"),ge(s,e,n)}function dt(s,e,t,r){const n=le(s,e),i=fe(n.payload,t,r);return ge(s,e,{...n,payload:i})}function ut(s,e,t,r){const n=le(s,e);if(!n.labels)throw new ee(`Edge "${e}" has no labels`);const i=n.labels.findIndex(c=>c.id===t);if(i===-1)throw new ee(`Label "${t}" not found in edge "${e}"`);const a=[...n.labels];return a[i]={...a[i],...r,id:t},ge(s,e,{...n,labels:a})}function ft(s,e,t){const r=fe(s.meta,e,t);return{...s,meta:r}}function Pe(s,e){const t=e?.maxHistorySize??100,r=o.ref(s),n=[],i=[],a=o.ref(!1),c=o.ref(!1);function l(){a.value=n.length>0,c.value=i.length>0}function g(C){const M=r.value;let D=M;for(const T of C.commands)D=ue(D,T);return n.push({snapshot:M,envelope:C}),n.length>t&&n.shift(),i.length=0,r.value=D,l(),D}function u(){const C=n.pop();return C?(i.push({snapshot:r.value,envelope:C.envelope}),r.value=C.snapshot,l(),C.snapshot):null}function h(){const C=i.pop();if(!C)return null;n.push({snapshot:r.value,envelope:C.envelope});let M=r.value;for(const D of C.envelope.commands)M=ue(M,D);return r.value=M,l(),M}function f(){n.length=0,i.length=0,l()}function y(){return r.value}function m(C){r.value=C,f()}return{currentFlowModel:r,execute:g,undo:u,redo:h,canUndo:a,canRedo:c,get undoStack(){return n.map(C=>C.envelope)},get redoStack(){return i.map(C=>C.envelope)},clear:f,createSnapshot:y,replaceFlowModel:m}}function pt(s){return s!==null&&typeof s=="object"&&s.rejected===!0}class gt{plugins=[];editorContext=null;runtimeCtx=null;runtimeVersion=0;install(e,t){this.plugins=[...e].sort((r,n)=>(r.priority??100)-(n.priority??100)),this.editorContext=t;for(const r of this.plugins)r.install?.(t)}attachRuntime(e){const t=++this.runtimeVersion;this.runtimeCtx=e;const r=this.createSafeRuntimeContext(e,t);for(const n of this.plugins)n.attachRuntime?.(r)}detachRuntime(){for(const e of[...this.plugins].reverse())e.detachRuntime?.();this.runtimeCtx=null}createSafeRuntimeContext(e,t){const r=this,n=new Proxy(e.graph,{get(i,a,c){const l=Reflect.get(i,a,c);return a==="use"&&typeof l=="function"?function(...u){if(r.runtimeVersion===t)return l.apply(i,u)}:l}});return{...e,graph:n}}dispose(){for(const e of[...this.plugins].reverse())e.dispose?.();this.plugins=[],this.editorContext=null,this.runtimeCtx=null}transformCommand(e){if(!this.editorContext)return{envelope:e};let t=e;for(const r of this.plugins){if(!r.transformCommand)continue;const n=this.createPreview(t),i=r.transformCommand(t,n,this.editorContext);if(i===null)return{rejected:!0,error:{code:"plugin_rejected",reason:"",source:r.name}};if(pt(i))return{rejected:!0,error:{code:i.code??"plugin_rejected",reason:i.reason,source:r.name}};t=i}return{envelope:t}}afterCommand(e,t,r){if(this.editorContext)for(const n of this.plugins)n.afterCommand?.(e,t,r,this.editorContext)}dispatchUiEvent(e){if(this.runtimeCtx)for(const t of this.plugins)t.onUiEvent?.(e,this.runtimeCtx)}dispatchSelectionChange(e){if(this.runtimeCtx)for(const t of this.plugins)t.onSelectionChange?.(e,this.runtimeCtx)}dispatchKeyboardShortcut(e){if(!this.runtimeCtx)return!1;for(const t of this.plugins)if(t.onKeyboardShortcut?.(e,this.runtimeCtx))return!0;return!1}collectContextMenuItems(e){if(!this.runtimeCtx)return[];const t=[];for(const r of this.plugins){const n=r.onBlankContextMenu?.(e,this.runtimeCtx);n&&t.push(...n)}return t}collectToolbarItems(){if(!this.editorContext)return[];const e=new Map;for(const t of this.plugins){const r=t.provideToolbarItems?.(this.editorContext);if(r)for(const n of r)e.set(n.id,n)}return[...e.values()].sort((t,r)=>(t.order??0)-(r.order??0))}collectNodeDecorations(e){if(!this.editorContext)return;let t;for(const r of this.plugins){const n=r.decorateNode?.(e,this.editorContext);n&&(t=t?{...t,...n}:n)}return t}collectEdgeDecorations(e){if(!this.editorContext)return;let t;for(const r of this.plugins){const n=r.decorateEdge?.(e,this.editorContext);n&&(t=t?{...t,...n}:n)}return t}collectExtendedApi(){if(!this.runtimeCtx)return{};const e={};for(const t of this.plugins){const r=t.extendApi?.(this.runtimeCtx.api,this.runtimeCtx);r&&Object.assign(e,r)}return e}createPreview(e){const t=this.editorContext;return{previewFlowModel(r){const n=r??e.commands;let i=t.flowModel.value;for(const a of n)i=ue(i,a);return i}}}}let ht=0;function j(){const s=Date.now().toString(36),e=Math.random().toString(36).substring(2,8);return`${s}-${e}-${++ht}`}const ye=()=>j();function vt(s){const{schema:e,plugins:t=[],historyOptions:r}=s,n=s.idGenerator??ye,i={version:"1.0",...s.initialFlowModel},a=Pe(i,r),c=o.ref(s.mode??"edit"),l=o.ref(!1),g=o.ref(null),u=o.ref([]),h={},f=new gt;function y(D,T,O,G="user:toolbar"){const R={id:`history-${Date.now()}`,source:G,label:D,timestamp:Date.now(),commands:[]};f.afterCommand(R,T,O),u.value=f.collectToolbarItems(),s.onCommandResult?.({status:"applied",envelope:R,flowModel:O}),s.onFlowModelChange?.({flowModel:O,prevFlowModel:T,envelope:R,source:G})}const m={execute:a.execute,undo(){const D=a.currentFlowModel.value,T=a.undo();return T&&y("撤销",D,T),T},redo(){const D=a.currentFlowModel.value,T=a.redo();return T&&y("重做",D,T),T},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(D){const T=a.currentFlowModel.value;a.replaceFlowModel(D),y("替换 FlowModel",T,D,"system:replace")}},C={flowModel:o.computed(()=>a.currentFlowModel.value),history:m,schema:e,mode:c,idGenerator:n,executeCommand:M,replaceFlowModel(D){m.replaceFlowModel(D)},setMode(D){c.value=D},selectionMode:l,setSelectionMode(D){l.value=D},api:g,toolbarItems:u,extendedApi:h,_pluginManager:f,_emitUiEvent:D=>{f.dispatchUiEvent(D)}};f.install(t,{flowModel:C.flowModel,history:m,schema:e,mode:c,idGenerator:n,executeCommand:M}),u.value=f.collectToolbarItems(),o.onScopeDispose(()=>{f.dispose()});function M(D){const T=f.transformCommand(D);if("rejected"in T){const R={status:"rejected",envelope:D,error:T.error};return s.onCommandResult?.(R),R}const O=T.envelope,G=a.currentFlowModel.value;try{const R=a.execute(O),q={status:"applied",envelope:O,flowModel:R};return f.afterCommand(O,G,R),u.value=f.collectToolbarItems(),s.onCommandResult?.(q),s.onFlowModelChange?.({flowModel:R,prevFlowModel:G,envelope:O,source:O.source}),q}catch(R){if(R instanceof ee){const q={status:"invalid",envelope:O,error:{code:"constraint_violated",reason:R.message,source:"engine"}};return s.onCommandResult?.(q),q}throw R}}return C}const mt=["top","right","bottom","left"];function Te(){return mt.map(s=>({id:s,group:s}))}function be(s,e){return e?.(s)??s.ports??Te()}const ve=-1,yt="flow-canvas-node-ring-target",ke="flow-canvas-node-ring-target--decorated",Ee="flow-canvas-node-ring-target--pulse",bt="linear-gradient(135deg, #cadcfa 0%, #cee0ff 100%)";class wt{graph;schema;shapeRegistry;resolveNodeDecoration;resolveEdgeDecoration;resolveCanvasContext;knownNodeIds=new Set;knownEdgeIds=new Set;syncing=!1;prevNodeDecorationClasses=new Map;prevNodeDecorationColors=new Set;prevEdgeDecorationClasses=new Map;prevEdgeDecorationColors=new Set;highlightedNodeIds=new Set;highlightedEdgeIds=new Set;hoveredEdgeId=null;defaultHighlightedNodeIds=new Set;defaultHighlightedEdgeIds=new Set;prevEdgeStyleIds=new Set;nodeDefaultAttrs=new Map;edgeDefaultAttrs=new Map;lastModel=null;constructor(e,t,r,n,i,a){this.graph=e,this.schema=t,this.shapeRegistry=r,this.resolveNodeDecoration=n,this.resolveEdgeDecoration=i,this.resolveCanvasContext=a}syncFlowModel(e){if(!this.syncing){this.syncing=!0,this.lastModel=e;try{const t=this.resolveNodes(e),r=this.resolveEdges(e);this.syncNodes(t),this.syncEdges(r,e)}finally{this.syncing=!1}}}get isSyncing(){return this.syncing}saveNodeDefaultAttrs(e,t){const n=t.x6CellConfig?.attrs?.body;if(!n)return;const i={};let a=!1;n.stroke!==void 0&&(i.stroke=n.stroke,a=!0),n.strokeWidth!==void 0&&(i.strokeWidth=n.strokeWidth,a=!0),a&&this.nodeDefaultAttrs.set(e,i)}saveEdgeDefaultAttrs(e,t){const n=t?.x6EdgeConfig?.attrs?.line;if(!n)return;const i={};let a=!1;n.stroke!==void 0&&(i.stroke=n.stroke,a=!0),n.strokeWidth!==void 0&&(i.strokeWidth=n.strokeWidth,a=!0),n.strokeDasharray!==void 0&&(i.strokeDasharray=n.strokeDasharray,a=!0),a&&this.edgeDefaultAttrs.set(e,i)}restoreNodeAttr(e,t,r){const n=this.nodeDefaultAttrs.get(e.id)?.[r];if(n!==void 0)e.setAttrByPath(t,n);else{const i=r==="stroke"?"none":0;e.setAttrByPath(t,i)}}restoreEdgeAttr(e,t,r){const n=this.edgeDefaultAttrs.get(e.id)?.[r];n!==void 0?e.setAttrByPath(t,n):e.removeAttrByPath(t)}getNodeRingTarget(e){return e?e.querySelector(".flow-canvas-highlight-target")??e.querySelector(".flow-canvas-node-surface > :first-child"):null}syncEdgeMarker(e,t,r){const i=t?.x6EdgeConfig?.attrs?.line?.[r],a=`line/${r}`;e.removeAttrByPath(a),i!==void 0&&e.setAttrByPath(a,i)}dispose(){this.knownNodeIds.clear(),this.knownEdgeIds.clear()}resolveNodes(e){const t=new Map;for(const[r,n]of Object.entries(e.nodes)){const i=this.schema.nodeTypes[n.type];if(!i)throw new Ae(`Unknown node type "${n.type}" for node "${r}". Registered types: [${Object.keys(this.schema.nodeTypes).join(", ")}]. Register the type in CanvasSchema.nodeTypes before using it in a FlowModel.`);const a=this.shapeRegistry.registerNodeType(n.type,i.component),c=i.getSize(n),l=be(n,i.getPorts);t.set(r,{model:n,definition:i,shapeName:a,size:c,ports:l})}return t}resolveEdges(e){const t=new Map;for(const[r,n]of Object.entries(e.edges)){const i=n.type??this.schema.defaultEdgeType??"default",a=this.schema.edgeTypes?.[i];t.set(r,{model:n,definition:a})}return t}syncNodes(e){const t=new Set(e.keys());for(const r of this.knownNodeIds)if(!t.has(r)){const n=this.graph.getCellById(r);n&&this.graph.removeCell(n),this.knownNodeIds.delete(r),this.defaultHighlightedNodeIds.delete(r),this.prevNodeDecorationClasses.delete(r),this.prevNodeDecorationColors.delete(r),this.nodeDefaultAttrs.delete(r)}for(const[r,n]of e){const i=this.graph.getCellById(r);i?this.updateExistingNode(i,n):this.addNewNode(r,n)}}updateExistingNode(e,t){const{model:r,size:n,ports:i,definition:a}=t;if(e.getData()?.type!==r.type){this.graph.removeCell(e),this.addNewNode(e.id,t);return}const l=e.getPosition();(l.x!==r.position.x||l.y!==r.position.y)&&e.setPosition(r.position.x,r.position.y);const g=e.getSize();(g.width!==n.width||g.height!==n.height)&&e.setSize(n.width,n.height,{silent:!0}),this.syncNodePorts(e,i),e.setData({...r}),this.applyNodeBehavior(e,r,a),this.applyNodeHighlightAndDecoration(e,r)}syncNodePorts(e,t){const r=e.getPorts(),n=new Set(t.map(a=>a.id)),i=new Set(r.map(a=>a.id));for(const a of r)a.id&&!n.has(a.id)&&e.removePort(a.id);for(const a of t)i.has(a.id)||e.addPort({id:a.id,group:a.group,...a.x6PortConfig})}addNewNode(e,t){const{model:r,shapeName:n,size:i,ports:a,definition:c}=t,l={id:r.id,shape:n,x:r.position.x,y:r.position.y,width:i.width,height:i.height,data:{...r},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(u=>({id:u.id,group:u.group,...u.x6PortConfig}))},...c.x6CellConfig};this.graph.addNode(l),this.knownNodeIds.add(e),this.saveNodeDefaultAttrs(e,c);const g=this.graph.getCellById(e);g&&(this.applyNodeBehavior(g,r,c),this.applyNodeHighlightAndDecoration(g,r))}applyNodeBehavior(e,t,r){if(!r.getBehavior)return;const n=this.resolveCanvasContext?.();if(!n)return;const i=r.getBehavior(t,n);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,t){const r=new Set(e.keys());for(const n of this.knownEdgeIds)if(!r.has(n)){const i=this.graph.getCellById(n);i&&this.graph.removeCell(i),this.knownEdgeIds.delete(n),this.defaultHighlightedEdgeIds.delete(n),this.prevEdgeDecorationClasses.delete(n),this.prevEdgeDecorationColors.delete(n),this.prevEdgeStyleIds.delete(n),this.edgeDefaultAttrs.delete(n)}for(const[n,i]of e){const a=this.graph.getCellById(n),{model:c,definition:l}=i;a?(this.updateExistingEdge(a,c,l,t),this.knownEdgeIds.has(n)||(this.knownEdgeIds.add(n),this.saveEdgeDefaultAttrs(n,l))):this.addNewEdge(n,c,l)}}updateExistingEdge(e,t,r,n){const i=e.getSource(),a=e.getTarget();if((i.cell!==t.source.nodeId||i.port!==t.source.portId)&&e.setSource({cell:t.source.nodeId,port:t.source.portId}),(a.cell!==t.target.nodeId||a.port!==t.target.portId)&&e.setTarget({cell:t.target.nodeId,port:t.target.portId}),r?.router){const c=typeof r.router=="string"?{name:r.router}:r.router;e.setRouter(c)}if(r?.connector){const c=typeof r.connector=="string"?{name:r.connector}:r.connector;e.setConnector(c)}this.syncEdgeMarker(e,r,"sourceMarker"),this.syncEdgeMarker(e,r,"targetMarker"),this.syncEdgeLabels(e,t),e.getZIndex()!==ve&&e.setZIndex(ve),e.setData({...t},{silent:!0}),this.applyEdgeStyleAndDecoration(e,t,r)}syncEdgeLabels(e,t){if(!t.labels?.length){e.getLabels().length>0&&e.setLabels([]);return}const r=t.labels.map(n=>({attrs:{label:{text:n.text??""}},position:n.position!=null?{distance:n.position}:void 0}));e.setLabels(r)}addNewEdge(e,t,r){const n={id:t.id,source:{cell:t.source.nodeId,port:t.source.portId},target:{cell:t.target.nodeId,port:t.target.portId},data:{...t},zIndex:ve};r?.router&&(n.router=typeof r.router=="string"?{name:r.router}:r.router),r?.connector&&(n.connector=typeof r.connector=="string"?{name:r.connector}:r.connector),r?.x6EdgeConfig&&Object.assign(n,r.x6EdgeConfig),t.labels?.length&&(n.labels=t.labels.map(a=>({attrs:{label:{text:a.text??""}},position:a.position!=null?{distance:a.position}:void 0}))),this.graph.addEdge(n),this.knownEdgeIds.add(e),this.saveEdgeDefaultAttrs(e,r);const i=this.graph.getCellById(e);i&&this.applyEdgeStyleAndDecoration(i,t,r)}refreshEdgeStyles(){if(this.lastModel)for(const[e,t]of Object.entries(this.lastModel.edges)){const r=this.graph.getCellById(e);if(!r?.isEdge())continue;const n=t.type??this.schema.defaultEdgeType??"default",i=this.schema.edgeTypes?.[n];this.applyEdgeStyleAndDecoration(r,t,i)}}refreshNodeHighlights(){if(this.lastModel)for(const[e,t]of Object.entries(this.lastModel.nodes)){const r=this.graph.getCellById(e);r?.isNode()&&this.applyNodeHighlightAndDecoration(r,t)}}applyNodeHighlightAndDecoration(e,t){const r=this.highlightedNodeIds.has(e.id),n=this.resolveNodeDecoration?.(t),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)),n?.className&&(i?.classList.add(n.className),this.prevNodeDecorationClasses.set(e.id,n.className));const l=n?.borderColor,u=l??(r?"#3a84ff":void 0),h=this.prevNodeDecorationColors.has(e.id)||this.defaultHighlightedNodeIds.has(e.id);u?(e.setAttrByPath("body/stroke",u),e.setAttrByPath("body/strokeWidth",2)):h&&(this.restoreNodeAttr(e,"body/stroke","stroke"),this.restoreNodeAttr(e,"body/strokeWidth","strokeWidth")),a&&(a.classList.add(yt),l?(a.classList.add(ke),a.style.setProperty("--flow-canvas-node-decoration-ring-background",l),a.style.setProperty("--flow-canvas-node-decoration-ring-opacity","0.95")):(a.classList.remove(ke),a.style.removeProperty("--flow-canvas-node-decoration-ring-background"),a.style.removeProperty("--flow-canvas-node-decoration-ring-opacity")),r?(a.classList.add(Ee),a.style.setProperty("--flow-canvas-node-pulse-ring-background",l??bt),a.style.setProperty("--flow-canvas-node-pulse-ring-opacity","0.95")):(a.classList.remove(Ee),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),r&&!l?this.defaultHighlightedNodeIds.add(e.id):this.defaultHighlightedNodeIds.delete(e.id)}setHoveredEdge(e){this.hoveredEdgeId=e}setHighlightedNodes(e){this.highlightedNodeIds=new Set(e)}setHighlightedEdges(e){this.highlightedEdgeIds=new Set(e)}applyEdgeStyleAndDecoration(e,t,r){const n=this.highlightedEdgeIds.has(e.id),i=this.resolveEdgeDecoration?.(t),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,g;if(r?.style){const m=this.graph.isSelected?.(e)??!1,C=this.hoveredEdgeId===e.id,M=r.style(t,{selected:m,highlighted:n,hovered:C});c=M.stroke,l=M.strokeWidth,g=M.strokeDasharray}const u=!r?.style&&n?"#3a84ff":void 0,h=i?.strokeColor,f=h??c??u,y=!!r?.style||this.prevEdgeDecorationColors.has(e.id)||this.defaultHighlightedEdgeIds.has(e.id)||this.prevEdgeStyleIds.has(e.id);f?e.setAttrByPath("line/stroke",f):y&&this.restoreEdgeAttr(e,"line/stroke","stroke"),r?.style?(this.prevEdgeStyleIds.add(e.id),l?e.setAttrByPath("line/strokeWidth",l):this.restoreEdgeAttr(e,"line/strokeWidth","strokeWidth"),g?e.setAttrByPath("line/strokeDasharray",g):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),u?this.defaultHighlightedEdgeIds.add(e.id):this.defaultHighlightedEdgeIds.delete(e.id)}}class kt{instanceId=j();registeredShapes=new Map;wrappedComponents=new Map;getShapeName(e){let t=this.registeredShapes.get(e);return t||(t=`flow-node-${this.instanceId}-${e}`,this.registeredShapes.set(e,t)),t}registerNodeType(e,t){const r=this.getShapeName(e);let n=this.wrappedComponents.get(e);return n||(n=o.defineComponent({name:`FlowCanvasNodeShape${e.replace(/(^|[-_])(\w)/g,(i,a,c)=>c.toUpperCase())}`,setup(){return()=>o.h("div",{class:"flow-canvas-node-surface"},[o.h(t)])}}),this.wrappedComponents.set(e,n)),Ye.register({shape:r,component:n,width:100,height:40}),r}dispose(){this.registeredShapes.clear(),this.wrappedComponents.clear()}}class Et{graph;onUiEvent;onCommand;flowModelRef;idGenerator;disposers=[];constructor(e,t,r,n,i){this.graph=e,this.onUiEvent=t,this.onCommand=r,this.flowModelRef=n,this.idGenerator=i??ye,this.bindEvents()}dispose(){for(const e of this.disposers)e();this.disposers=[]}bindEvents(){this.on("node:click",({node:e})=>{this.onUiEvent({type:"node.click",nodeId:e.id})}),this.on("node:dblclick",({node:e})=>{this.onUiEvent({type:"node.dblclick",nodeId:e.id})}),this.on("node:contextmenu",({node:e,e:t})=>{this.onUiEvent({type:"node.contextmenu",nodeId:e.id,position:{x:t.clientX,y:t.clientY}})}),this.on("edge:click",({edge:e,e:t})=>{const n=t.target?.closest?.(".x6-edge-label");if(n){const a=e.getData?.()?.labels??[],c=n.parentElement?.querySelectorAll(".x6-edge-label"),l=c?Array.from(c).indexOf(n):0,g=a[Math.max(0,l)];this.onUiEvent({type:"edge.label.click",edgeId:e.id,labelId:g?.id??`label-${l}`});return}this.onUiEvent({type:"edge.click",edgeId:e.id})}),this.on("blank:click",({e})=>{const t=this.graph.clientToLocal(e.clientX,e.clientY);this.onUiEvent({type:"blank.click",position:{x:t.x,y:t.y}})}),this.on("blank:contextmenu",({e})=>{this.onUiEvent({type:"blank.contextmenu",position:{x:e.clientX,y:e.clientY}})}),this.on("node:moved",({node:e})=>{const t=e.getPosition();this.onCommand({id:j(),source:"user:drag",label:"移动节点",timestamp:Date.now(),commands:[{type:"node.move",nodeId:e.id,position:{x:t.x,y:t.y}}]})}),this.on("edge:connected",({edge:e,isNew:t})=>{const r=e.getSourceCell(),n=e.getTargetCell();if(!r||!n)return;const i=e.getSourcePortId(),a=e.getTargetPortId(),c=e.id in this.flowModelRef.value.edges;t&&!c?(this.graph.removeCell(e),this.onCommand({id:j(),source:"user:drag",label:"连线",timestamp:Date.now(),commands:[{type:"edge.add",edge:{id:this.idGenerator("edge"),source:{nodeId:r.id,portId:i??void 0},target:{nodeId:n.id,portId:a??void 0}}}]})):this.onCommand({id:j(),source:"user:drag",label:"重连",timestamp:Date.now(),commands:[{type:"edge.reconnect",edgeId:e.id,source:{nodeId:r.id,portId:i??void 0},target:{nodeId:n.id,portId:a??void 0}}]})}),this.on("edge:change:labels",({edge:e,current:t})=>{const n=e.getData?.()?.labels??[];if(!n.length||!t?.length)return;const i=[];for(let a=0;a<Math.min(n.length,t.length);a++){const c=t[a],l=n[a];if(!l?.id)continue;const g=typeof c.position=="object"?c.position?.distance:c.position;g!=null&&i.push({type:"edge.label.update",edgeId:e.id,labelId:l.id,patch:{position:g}})}i.length&&this.onCommand({id:j(),source:"user:drag",label:"拖动标签",timestamp:Date.now(),commands:i})})}on(e,t){this.graph.on(e,t),this.disposers.push(()=>this.graph.off(e,t))}}function Ct(s){function e(t){const r=s.getCellById(t);if(!r||!r.isNode())return null;const n=r,i=n.getPosition(),a=n.getSize(),c={x:i.x,y:i.y,width:a.width,height:a.height},l=s.localToGraph(c);return new DOMRect(l.x,l.y,l.width,l.height)}return{getNodeScreenRect:e}}function Re(s){return{nodeIds:s.filter(e=>e.isNode()).map(e=>e.id),edgeIds:s.filter(e=>e.isEdge()).map(e=>e.id)}}function xt(s,e){const t=[...e.nodeIds.map(i=>s.getCellById(i)),...e.edgeIds.map(i=>s.getCellById(i))].filter(i=>!!i);if(t.length===0)return null;const r=s.getCellsBBox(t);if(!r)return null;const n=s.localToGraph(r);return new DOMRect(n.x,n.y,n.width,n.height)}function Le(s,e,t){const r=s.nodeIds.filter(a=>{const c=e.nodes[a];if(!c)return!1;const l=t(c);return l.deletable!==!1&&l.deleteDisabled!==!0}),n=new Set(r),i=s.edgeIds.filter(a=>{const c=e.edges[a];return c?!n.has(c.source.nodeId)&&!n.has(c.target.nodeId):!1});return{nodeIds:r,edgeIds:i}}function Nt(s){return[...s.edgeIds.map(e=>({type:"edge.remove",edgeId:e})),...s.nodeIds.map(e=>({type:"node.remove",nodeId:e}))]}const It=100;function St({graph:s,overlayManager:e,executeCommand:t,schema:r,flowModel:n,getNodeBehavior:i,idGenerator:a,defaultInsertGap:c,getContextMenuItems:l,onHighlightChange:g,resolveNodeShape:u}){const h=a??ye;let f=[],y=[],m=null,C=!1,M=null;async function D(){if(C)return m;C=!0;try{const v=await import("@antv/x6-plugin-dnd"),d=v.Dnd??v.default;return d?(m=new d({target:s,scaled:!0,animation:!0,getDragNode:p=>p.clone(),getDropNode:p=>p.clone()}),m):null}catch{return console.warn("[flow-canvas] @antv/x6-plugin-dnd not available, add it to your dependencies"),null}}function T(){return new Promise(v=>{requestAnimationFrame(()=>requestAnimationFrame(()=>v()))})}const O=({node:v})=>{const d=v.getData?.();if(!d?._dndSessionId||d._dndSessionId!==M)return;M=null;const p=v.getPosition();s.removeNode(v.id);const{_dndSessionId:I,...S}=d,k=S.id||h("node");t({id:j(),source:"user:drag",label:"拖入节点",timestamp:Date.now(),commands:[{type:"node.add",node:{...S,id:k,position:{x:p.x,y:p.y}}}]})};s.on("node:added",O);function G(v){const d=r.nodeTypes[v.type];return be(v,d?.getPorts)}function R(v){return v??Re(s.getSelectedCells?.()??[])}function q(v,d,p,I,S){switch(v){case"left":return{x:d.position.x-S-I.width,y:d.position.y+(p.height-I.height)/2};case"top":return{x:d.position.x+(p.width-I.width)/2,y:d.position.y-S-I.height};case"bottom":return{x:d.position.x+(p.width-I.width)/2,y:d.position.y+p.height+S};default:return{x:d.position.x+p.width+S,y:d.position.y+(p.height-I.height)/2}}}function H(v,d,p){switch(v){case"left":return{x:-(d.width+p),y:0};case"top":return{x:0,y:-(d.height+p)};case"bottom":return{x:0,y:d.height+p};default:return{x:d.width+p,y:0}}}function N(v){switch(v){case"left":return"right";case"top":return"bottom";case"bottom":return"top";default:return"left"}}const L={zoomIn(){s.zoom(.1)},zoomOut(){s.zoom(-.1)},zoomTo(v){s.zoomTo(v)},zoomToFit(){s.zoomToFit({padding:40,maxScale:1.5})},getZoom(){return s.zoom()},centerContent(){s.centerContent()},scrollToOrigin(){s.translate(0,0)},scrollToNode(v){const d=s.getCellById(v);d&&s.centerCell(d)},getSelection(){return R()},getSelectionBounds(v){return xt(s,R(v))},selectNodes(v){const d=v.map(p=>s.getCellById(p)).filter(Boolean);s.select?.(d)},selectEdges(v){const d=v.map(p=>s.getCellById(p)).filter(Boolean);s.select?.(d)},clearSelection(){const v=s.getSelectedCells?.();v?.length&&s.unselect?.(v)},deleteSelection(v){const d=R(v?.selection),p=Le(d,n.value,i??(()=>({}))),I=Nt(p);if(I.length===0)return null;const S=t({id:j(),source:v?.source??"user:toolbar",label:v?.label??"删除选中",timestamp:Date.now(),commands:I});return S.status==="applied"&&v?.clearSelectionAfterApply!==!1&&L.clearSelection(),S},registerDndSource(v,d){const p=async I=>{const S=await D();if(!S)return;const k=j();M=k;const V=d(),Y=u?.(V.type),x=s.createNode({width:Y?.width??154,height:Y?.height??54,shape:Y?.shapeName??"rect",data:{...V,_dndSessionId:k}});S.start(x,I)};return v.addEventListener("mousedown",p),()=>{v.removeEventListener("mousedown",p)}},startConnection(v,d){const p=s.getCellById(v);if(!p?.isNode())return;const I=p,S=s.findViewByCell(I);if(!S)return;const k=S.findPortElem(d,"circle")??S.findPortElem(d);if(!k)return;const Y=(k.matches?.("[magnet]")?k:k.querySelector?.("[magnet]"))??k,x=Y.getBoundingClientRect(),A=x.left+x.width/2,b=x.top+x.height/2,B=new MouseEvent("mousedown",{clientX:A,clientY:b,button:0,buttons:1,bubbles:!0,cancelable:!0});Y.dispatchEvent(B)},async exportAsImage(v){const{domToBlob:d}=await import("modern-screenshot"),p=v?.padding??20,I=v?.backgroundColor??s.options.background?.color??"#ffffff",S=s.zoom(),k=s.translate(),V=s.getContentBBox(),Y=V.width/S,x=V.height/S;if(Y===0||x===0)return new Blob;const A=(V.x-k.tx)/S,b=(V.y-k.ty)/S,B=Math.ceil(Y+p*2),z=Math.ceil(x+p*2),U=document.createElement("div");U.style.cssText="position:fixed;left:-99999px;top:0;pointer-events:none;";const F=s.container.cloneNode(!0);F.style.width=`${B}px`,F.style.height=`${z}px`,F.style.overflow="visible";const Q=F.querySelector("svg");Q&&(Q.setAttribute("width",String(B)),Q.setAttribute("height",String(z)),Q.style.width=`${B}px`,Q.style.height=`${z}px`),F.querySelector(".x6-graph-svg-viewport")?.setAttribute("transform",`matrix(1,0,0,1,${-A+p},${-b+p})`),U.appendChild(F),document.body.appendChild(U);try{return await T(),await d(F,{width:B,height:z,backgroundColor:I,scale:v?.scale??window.devicePixelRatio,filter:te=>{if(te instanceof Element){const Z=te.getAttribute("class")??"";if(Z.includes("x6-widget-selection")||Z.includes("x6-widget-transform")||Z.includes("x6-graph-grid")||Z.includes("x6-graph-background"))return!1}return!0}})}catch(te){return console.warn("[flow-canvas] Export failed:",te),new Blob}finally{U.remove()}},highlightNodes(v){f=v,g?.(f,y)},highlightEdges(v){y=v,g?.(f,y)},clearHighlight(){f=[],y=[],g?.([],[])},overlay:e,getContextMenuItems(v){return l?.(v)??[]},insertNodeToRight(v,d,p){const I=n.value,S=I.nodes[v];if(!S)return{status:"invalid",envelope:{id:"",source:"user:toolbar",timestamp:Date.now(),commands:[]},error:{code:"constraint_violated",reason:`Source node "${v}" not found`,source:"api"}};const k=p?.gap??c??It,V=p?.direction??"right",Y=r.nodeTypes[S.type],x=r.nodeTypes[d.type],A=Y?.getSize(S)??{width:154,height:54},b=x?.getSize({...d,position:{x:0,y:0}})??{width:154,height:54},B=q(V,S,A,b,k),z=d.id||h("node"),U={...d,id:z,position:B},F=[{type:"node.add",node:U}],Q=H(V,b,k),W={x:B.x,y:B.y,width:b.width,height:b.height};for(const[Z,E]of Object.entries(I.nodes)){if(Z===v||Z===z)continue;const _=r.nodeTypes[E.type]?.getSize(E)??{width:154,height:54},$=W.x<E.position.x+_.width&&W.x+W.width>E.position.x,X=W.y<E.position.y+_.height&&W.y+W.height>E.position.y;$&&X&&F.push({type:"node.move",nodeId:Z,position:{x:E.position.x+Q.x,y:E.position.y+Q.y}})}if(p?.autoWireEdges){const Z=G(S),E=G(U),w=V,_=N(V),$=Z.find(K=>K.group===w),X=E.find(K=>K.group===_),oe=E.find(K=>K.group===w),J=$?Object.values(I.edges).find(K=>K.source.nodeId===v&&K.source.portId===$.id):Object.values(I.edges).find(K=>K.source.nodeId===v);if(J){const K=J.target;F.push({type:"edge.remove",edgeId:J.id}),F.push({type:"edge.add",edge:{id:h("edge"),source:{nodeId:v,portId:$?.id},target:{nodeId:z,portId:X?.id}}}),F.push({type:"edge.add",edge:{id:h("edge"),source:{nodeId:z,portId:oe?.id},target:K}})}else F.push({type:"edge.add",edge:{id:h("edge"),source:{nodeId:v,portId:$?.id},target:{nodeId:z,portId:X?.id}}})}const te={id:j(),source:p?.source??"user:toolbar",label:p?.label??"插入节点",timestamp:Date.now(),commands:F};return t(te)},onGraphEvent(v,d){return s.on(v,d),()=>s.off(v,d)},unsafeGetGraph(){return s}};return L}function _t(){const s=o.ref(null),e=o.ref(!1);let t=null,r=!1;function n(h){t&&(clearTimeout(t),t=null),s.value=h}function i(h=100){r||(t&&clearTimeout(t),t=setTimeout(()=>{s.value=null,t=null},h))}function a(){r=!0,t&&(clearTimeout(t),t=null)}function c(h=100){r=!1,i(h)}function l(){t&&(clearTimeout(t),t=null)}function g(){l(),r=!1,s.value=null}function u(){t&&clearTimeout(t)}return{hoveredNodeId:s,isDraggingNode:e,enter:n,leave:i,enterOverlay:a,leaveOverlay:c,cancelLeave:l,reset:g,cleanup:u}}const Ce=10,de=12;function xe(s,e){const t=s.getTotalLength();if(t===0)return{...e,length:0,totalLength:0};let r=s.getPointAtLength(0),n=1/0;const i=50,a=t/i;let c=0;for(let h=0;h<=i;h++){const f=h*a,y=s.getPointAtLength(f),m=(y.x-e.x)**2+(y.y-e.y)**2;m<n&&(n=m,r=y,c=f)}const l=Math.max(0,c-a),g=Math.min(t,c+a),u=(g-l)/20;for(let h=l;h<=g;h+=u){const f=s.getPointAtLength(h),y=(f.x-e.x)**2+(f.y-e.y)**2;y<n&&(n=y,r=f,c=h)}return{x:r.x,y:r.y,length:c,totalLength:t}}function Ne(s,e){return s<Ce||s>e-Ce}function Ie(s,e,t){const r=s.querySelectorAll(".x6-edge-label");for(const n of r){const i=n.getBoundingClientRect();if(e>=i.left-de&&e<=i.right+de&&t>=i.top-de&&t<=i.bottom+de)return!0}return!1}function Se(){const s="http://www.w3.org/2000/svg",e=document.createElementNS(s,"g");e.setAttribute("class","flow-canvas-edge-delete-tool"),e.style.cursor="pointer";const t=document.createElementNS(s,"rect");t.setAttribute("width","20"),t.setAttribute("height","20"),t.setAttribute("x","-10"),t.setAttribute("y","-10"),t.setAttribute("rx","4"),t.setAttribute("ry","4"),t.setAttribute("fill","#3a84ff"),e.appendChild(t);const r=document.createElementNS(s,"text");return r.setAttribute("font-family","flow-canvas"),r.setAttribute("font-size","16"),r.setAttribute("fill","#ffffff"),r.setAttribute("text-anchor","middle"),r.setAttribute("dominant-baseline","central"),r.textContent="",e.appendChild(r),e}function Mt(s){let e=null,t=null;function r(c,l){if(i(),t=c,l.target?.closest?.(".x6-edge-label"))return;const u=s.getCellById(c);if(!u?.isEdge())return;const h=s.findViewByCell(u);if(!h)return;const f=h.container.querySelector("path");if(!f)return;const y=s.clientToLocal(l.clientX,l.clientY),m=xe(f,y);if(Ne(m.length,m.totalLength)||Ie(h.container,l.clientX,l.clientY))return;const C=Se();C.setAttribute("transform",`translate(${m.x}, ${m.y})`),h.container.appendChild(C),e=C}function n(c){if(!t)return;if(c.target?.closest?.(".x6-edge-label")){e&&e.setAttribute("display","none");return}const g=s.getCellById(t);if(!g?.isEdge())return;const u=s.findViewByCell(g);if(!u)return;const h=u.container.querySelector("path");if(!h)return;const f=s.clientToLocal(c.clientX,c.clientY),y=xe(h,f);if(Ne(y.length,y.totalLength)||Ie(u.container,c.clientX,c.clientY))e&&e.setAttribute("display","none");else if(e)e.removeAttribute("display"),e.setAttribute("transform",`translate(${y.x}, ${y.y})`);else{const m=Se();m.setAttribute("transform",`translate(${y.x}, ${y.y})`),u.container.appendChild(m),e=m}}function i(){e&&(e.remove(),e=null),t=null}function a(c){c===t&&(e=null,t=null)}return{show:r,move:n,remove:i,handleEdgeRemoved:a}}function Dt(s){let e=null,t=0;function r(u){const h=u?"visible":"hidden";for(const f of s.getNodes())for(const y of f.getPorts())f.setPortProp(y.id,"attrs/circle/visibility",h)}function n(u){if(!e)for(const h of u.getPorts())u.setPortProp(h.id,"attrs/circle/visibility","visible")}function i(u){if(!e)for(const h of u.getPorts())u.setPortProp(h.id,"attrs/circle/visibility","hidden")}function a(u,h){if(!u.getTargetCell())if(e=u.id,h?.size)for(const f of s.getNodes()){const y=h.has(f.id)?"hidden":"visible";for(const m of f.getPorts())f.setPortProp(m.id,"attrs/circle/visibility",y)}else r(!0)}function c(){e=null,r(!1),t=Date.now()+300}function l(u){u===e&&(e=null,r(!1))}function g(){return!e&&Date.now()>=t}return{showNodePorts:n,hideNodePorts:i,handleEdgeAdded:a,handleEdgeConnected:c,handleEdgeRemoved:l,canShowEdgeTool:g}}function _e(s){return s==="top"||s==="right"||s==="bottom"||s==="left"}function Bt(s){const{editor:e,nodeHover:t,isSelectionModeActive:r,viewportVersion:n,getNodeBehavior:i,getInsertGap:a}=s,{isDraggingNode:c}=s,l=o.ref(null),g=o.ref(!1);let u=null,h=null,f=null;const y=o.computed(()=>({enabled:!0,portGroup:"right",...s.quickAddProp.value}));function m(){u&&(clearTimeout(u),u=null)}function C(){u&&clearTimeout(u),u=setTimeout(()=>{l.value=null,u=null},150)}function M(x){return g.value?!0:(m(),L(x)?(l.value=x,!0):(l.value=null,!1))}function D(){m(),t.enterOverlay()}function T(){C(),t.leaveOverlay()}function O(x){const A=e.schema.nodeTypes[x.type];return be(x,A?.getPorts)}function G(x,A){const b=y.value.getPort?.(x,A);if(!b)return null;const B=typeof b=="string"?b:b.id;return A.find(z=>z.id===B)??null}function R(x,A){const b=e.api.value?.overlay.getNodeScreenRect(x);if(!b)return null;switch(A){case"top":return{x:b.x+b.width/2,y:b.y};case"bottom":return{x:b.x+b.width/2,y:b.y+b.height};case"left":return{x:b.x,y:b.y+b.height/2};case"right":return{x:b.x+b.width,y:b.y+b.height/2};default:return null}}function q(x,A,b){if(!h)return R(x,b);const B=h.getCellById(x);if(B?.isNode()){const z=B,U=h.findViewByCell(z),F=U?.findPortElem(A,"circle")??U?.findPortElem(A);if(F){const Q=h.container.getBoundingClientRect(),W=F.getBoundingClientRect();return{x:W.left-Q.left+W.width/2,y:W.top-Q.top+W.height/2}}}return R(x,b)}function H(x){const A=O(x),b=G(x,A)??A.find(z=>z.group===y.value.portGroup)??null;if(!b)return null;const B=q(x.id,b.id,b.group);return B?{portId:b.id,portGroup:b.group,portPosition:B}:null}function N(x){const A=H(x),b=y.value.insertDirection;if(typeof b=="function"){const B=b(x,A?{id:A.portId,group:A.portGroup}:null);if(B)return B}else if(b)return b;return A&&_e(A.portGroup)?A.portGroup:_e(y.value.portGroup)?y.value.portGroup:"right"}function L(x){if(!y.value.enabled||e.mode.value!=="edit")return!1;const b=e.flowModel.value.nodes[x];return!b||i(b).quickAddEnabled===!1?!1:!!H(b)}const v=o.computed(()=>{if(n.value,!y.value.enabled)return null;const x=l.value;if(!x||c.value||!e.api.value||e.mode.value!=="edit"||r.value)return null;const b=e.flowModel.value.nodes[x];if(!b)return null;const B=i(b);if(B.quickAddEnabled===!1)return null;const z=H(b);return z?{node:b,...z,behavior:B}:null});function d(x){g.value=!0,v.value&&e._emitUiEvent({type:"node.quick-add",nodeId:x,position:v.value.portPosition})}function p(){g.value=!1}function I(x){const A=e.api.value;if(!A)return;const b=e.flowModel.value.nodes[x];if(!b)return;const B=H(b);B&&A.startConnection(x,B.portId)}function S(x,A){const b=e.api.value;if(!b)return;const B=A.id||e.idGenerator("node"),z={...A,id:B},U=e.flowModel.value.nodes[x];if(!U)return;b.insertNodeToRight(x,z,{autoWireEdges:!0,direction:N(U),gap:a(),source:"user:quick-add",label:"快捷插入节点"}).status==="applied"&&e._emitUiEvent({type:"node.action.quick-insert",sourceNodeId:x,newNodeId:B}),s.closePopover()}function k(x){if(!h)return;const A=h.getCellById(x);if(!A?.isNode())return;const b=A,B=e.flowModel.value.nodes[x];if(!B)return;const z=H(B);let U=!0;i(B).hidePortForQuickAdd===!1&&(U=!1);const Q=U&&!c.value&&!!z&&L(x);for(const W of b.getPorts()){const te=Q&&W.id===z?.portId?"hidden":"visible";b.setPortProp(W.id,"attrs/circle/visibility",te)}}function V(x,A){f?.(),h=x,f=o.watch([l,c],([b],[B])=>{if(B&&B!==b){const z=x.getCellById(B);z?.isNode()&&A(z)}b&&k(b)},{flush:"sync"})}o.watch(v,x=>{x||(g.value=!1)});function Y(){u&&clearTimeout(u),f?.(),f=null,h=null}return{quickAddNodeId:l,quickAddPopoverOpen:g,mergedConfig:y,data:v,enter:M,leave:C,cancelLeave:m,handleOverlayEnter:D,handleOverlayLeave:T,handleOpen:d,handleClose:p,handleStartDrag:I,handleInsert:S,isActiveForNode:L,syncNodePorts:k,attachRuntime:V,cleanup:Y}}function At(s){function e(n){return{id:s.idGenerator("node"),type:n.type,label:n.label,ports:n.ports?JSON.parse(JSON.stringify(n.ports)):void 0,payload:n.payload?JSON.parse(JSON.stringify(n.payload)):void 0,extensions:n.extensions?JSON.parse(JSON.stringify(n.extensions)):void 0}}function t(n,i,a){const c=s.api.value;switch(n){case"delete":return s.executeCommand({id:j(),source:"user:toolbar",label:"删除节点",timestamp:Date.now(),commands:[{type:"node.remove",nodeId:i}]}),s._emitUiEvent({type:"node.action.delete",nodeId:i}),!0;case"copy":{if(!c)break;const l=s.flowModel.value.nodes[i];if(!l)break;const g=e(l);c.insertNodeToRight(i,g,{autoWireEdges:!1,gap:a,label:"复制节点"}),s._emitUiEvent({type:"node.action.copy",sourceNodeId:i,newNodeId:g.id});break}case"copy-insert":{if(!c)break;const l=s.flowModel.value.nodes[i];if(!l)break;const g=e(l);c.insertNodeToRight(i,g,{autoWireEdges:!0,gap:a,label:"复制并插入节点"}),s._emitUiEvent({type:"node.action.copy-insert",sourceNodeId:i,newNodeId:g.id});break}case"disconnect":{const l=s.flowModel.value,g=Object.entries(l.edges).filter(([,u])=>{const h=u;return h.source.nodeId===i||h.target.nodeId===i}).map(([u])=>u);if(g.length===0)break;s.executeCommand({id:j(),source:"user:toolbar",label:"断开连线",timestamp:Date.now(),commands:g.map(u=>({type:"edge.remove",edgeId:u}))}),s._emitUiEvent({type:"node.action.disconnect",nodeId:i,edgeIds:g});break}case"debug":{s._emitUiEvent({type:"node.action.debug",nodeId:i});break}}return!1}function r(n){s.api.value?.deleteSelection({selection:n,source:"user:toolbar",label:"批量删除选中"})}return{handleNodeAction:t,deleteSelection:r}}function Pt(){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 Tt(s,e){const t=e.defaultEdgeType??"default",r=e.edgeTypes?.[t],n={zIndex:-1,attrs:{line:{stroke:"#abb5cc",strokeWidth:2,targetMarker:{name:"block",width:8,height:8}}}};r?.router&&(n.router=typeof r.router=="string"?{name:r.router}:r.router),r?.connector&&(n.connector=typeof r.connector=="string"?{name:r.connector}:r.connector),r?.x6EdgeConfig&&Object.assign(n,r.x6EdgeConfig);const i=n.attrs??{},a=i.line??{};return n.attrs={...i,line:{...a,targetMarker:Pt()}},s.createEdge(n)}const Rt={class:"flow-canvas-node-actions__bar"},Lt=o.defineComponent({__name:"node-actions-toolbar",props:{node:{},position:{},config:{},behavior:{},actionsOffset:{}},emits:["action"],setup(s,{emit:e}){const t=s,r=o.computed(()=>{const h=t.actionsOffset?.x??0,f=t.actionsOffset?.y??0,y=h!==0||f!==0;return{left:`${t.position.x}px`,top:`${t.position.y}px`,transform:y?`translate(${h}px, ${f}px)`:"translateX(-100%)"}}),n=e,i=o.computed(()=>({debug:{visible:t.config.showDebug&&t.behavior.debuggable!==!1,disabled:t.behavior.debugDisabled===!0},delete:{visible:t.config.showDelete&&t.behavior.deletable!==!1,disabled:t.behavior.deleteDisabled===!0},copy:{visible:t.config.showCopy&&t.behavior.copyable!==!1,disabled:t.behavior.copyDisabled===!0},copyInsert:{visible:t.config.showCopyInsert&&t.behavior.copyable!==!1,disabled:t.behavior.copyInsertDisabled===!0},disconnect:{visible:t.config.showDisconnect&&t.behavior.disconnectable!==!1,disabled:t.behavior.disconnectDisabled===!0}})),a=o.computed(()=>i.value.copy.visible||i.value.copyInsert.visible||i.value.disconnect.visible),c=o.ref(!1);let l=null;function g(){l&&(clearTimeout(l),l=null),c.value=!0}function u(){l=setTimeout(()=>{c.value=!1,l=null},100)}return o.onBeforeUnmount(()=>{l&&clearTimeout(l)}),(h,f)=>(o.openBlock(),o.createElementBlock("div",{class:"flow-canvas-node-actions",style:o.normalizeStyle(r.value)},[o.createElementVNode("div",Rt,[i.value.debug.visible?(o.openBlock(),o.createElementBlock("i",{key:0,class:o.normalizeClass(["flow-canvas-icon canvas-debug flow-canvas-node-actions__icon",{"is-disabled":i.value.debug.disabled}]),onClick:f[0]||(f[0]=y=>!i.value.debug.disabled&&n("action","debug",s.node.id))},null,2)):o.createCommentVNode("",!0),i.value.delete.visible?(o.openBlock(),o.createElementBlock("i",{key:1,class:o.normalizeClass(["flow-canvas-icon canvas-shanchu flow-canvas-node-actions__icon",{"is-disabled":i.value.delete.disabled}]),onClick:f[1]||(f[1]=y=>!i.value.delete.disabled&&n("action","delete",s.node.id))},null,2)):o.createCommentVNode("",!0),a.value?(o.openBlock(),o.createElementBlock("div",{key:2,class:"flow-canvas-node-actions__more-wrapper",onMouseenter:g,onMouseleave:u},[...f[5]||(f[5]=[o.createElementVNode("i",{class:"flow-canvas-icon canvas-gengduo flow-canvas-node-actions__icon"},null,-1)])],32)):o.createCommentVNode("",!0)]),o.createVNode(o.Transition,{name:"flow-canvas-fade"},{default:o.withCtx(()=>[c.value&&a.value?(o.openBlock(),o.createElementBlock("div",{key:0,class:"flow-canvas-node-actions__dropdown",onMouseenter:g,onMouseleave:u},[i.value.copy.visible?(o.openBlock(),o.createElementBlock("div",{key:0,class:o.normalizeClass(["flow-canvas-node-actions__dropdown-item",{"is-disabled":i.value.copy.disabled}]),onClick:f[2]||(f[2]=y=>!i.value.copy.disabled&&n("action","copy",s.node.id))},[...f[6]||(f[6]=[o.createElementVNode("i",{class:"flow-canvas-icon canvas-copy-fuzhi-2"},null,-1),o.createElementVNode("span",null,"复制",-1)])],2)):o.createCommentVNode("",!0),i.value.copyInsert.visible?(o.openBlock(),o.createElementBlock("div",{key:1,class:o.normalizeClass(["flow-canvas-node-actions__dropdown-item",{"is-disabled":i.value.copyInsert.disabled}]),onClick:f[3]||(f[3]=y=>!i.value.copyInsert.disabled&&n("action","copy-insert",s.node.id))},[...f[7]||(f[7]=[o.createElementVNode("i",{class:"flow-canvas-icon canvas-fuzhibingcharu"},null,-1),o.createElementVNode("span",null,"复制并插入",-1)])],2)):o.createCommentVNode("",!0),i.value.disconnect.visible?(o.openBlock(),o.createElementBlock("div",{key:2,class:o.normalizeClass(["flow-canvas-node-actions__dropdown-item",{"is-disabled":i.value.disconnect.disabled}]),onClick:f[4]||(f[4]=y=>!i.value.disconnect.disabled&&n("action","disconnect",s.node.id))},[...f[8]||(f[8]=[o.createElementVNode("i",{class:"flow-canvas-icon canvas-unlock-jiebang"},null,-1),o.createElementVNode("span",null,"断开连线",-1)])],2)):o.createCommentVNode("",!0)],32)):o.createCommentVNode("",!0)]),_:1})],4))}}),ne=(s,e)=>{const t=s.__vccOpts||s;for(const[r,n]of e)t[r]=n;return t},Oe=ne(Lt,[["__scopeId","data-v-3b39dab5"]]),Ot={key:0,class:"flow-canvas-quick-add__tooltip"},$t=5,Vt=o.defineComponent({__name:"node-quick-add-popover",props:{node:{},portPosition:{}},emits:["open","close","start-drag","mouseenter","mouseleave"],setup(s,{expose:e,emit:t}){const r=s,n=t,i=o.ref(),a=o.ref(),c=o.ref(!1),l=o.ref(!1);let g=null,u=!1,h=null;function f(H){H.preventDefault(),H.stopPropagation(),g={x:H.clientX,y:H.clientY},u=!1,document.addEventListener("mousemove",y),document.addEventListener("mouseup",m)}function y(H){if(!g)return;const N=H.clientX-g.x,L=H.clientY-g.y;Math.sqrt(N*N+L*L)>=$t&&(u=!0,C(),n("start-drag",r.node.id))}function m(){C(),u||M(),g=null,u=!1}function C(){document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",m)}function M(){l.value?T():D()}function D(){l.value=!0,n("open",r.node.id),requestAnimationFrame(()=>{document.addEventListener("mousedown",O)})}function T(){l.value=!1,n("close"),document.removeEventListener("mousedown",O)}function O(H){const N=H.target;i.value?.contains(N)||a.value?.contains(N)||T()}function G(){l.value||n("mouseleave")}function R(){h&&(clearTimeout(h),h=null),n("mouseenter")}function q(){h=setTimeout(()=>{T(),n("mouseleave"),h=null},150)}return o.onBeforeUnmount(()=>{C(),h&&clearTimeout(h),document.removeEventListener("mousedown",O)}),e({closePopover:T}),(H,N)=>(o.openBlock(),o.createElementBlock("div",{class:"flow-canvas-quick-add",style:o.normalizeStyle({left:`${s.portPosition.x}px`,top:`${s.portPosition.y}px`}),onMouseenter:N[2]||(N[2]=L=>n("mouseenter")),onMouseleave:G,onClick:N[3]||(N[3]=o.withModifiers(()=>{},["stop"]))},[o.createElementVNode("div",{ref_key:"btnRef",ref:i,class:o.normalizeClass(["flow-canvas-quick-add__btn",{"is-hovered":c.value,"is-active":l.value}]),onMouseenter:N[0]||(N[0]=L=>c.value=!0),onMouseleave:N[1]||(N[1]=L=>c.value=!1),onMousedown:f},[...N[4]||(N[4]=[o.createElementVNode("i",{class:"flow-canvas-icon canvas-zoom-add"},null,-1)])],34),c.value&&!l.value?(o.openBlock(),o.createElementBlock("div",Ot,[...N[5]||(N[5]=[o.createElementVNode("div",null,[o.createElementVNode("b",null,"点击"),o.createTextVNode(" 添加节点")],-1),o.createElementVNode("div",null,[o.createElementVNode("b",null,"拖拽"),o.createTextVNode(" 连接节点")],-1)])])):o.createCommentVNode("",!0),o.createVNode(o.Transition,{name:"flow-canvas-fade"},{default:o.withCtx(()=>[l.value?(o.openBlock(),o.createElementBlock("div",{key:0,ref_key:"popoverRef",ref:a,class:"flow-canvas-quick-add__popover",onMouseenter:R,onMouseleave:q},[o.renderSlot(H.$slots,"default",{},()=>[N[6]||(N[6]=o.createElementVNode("div",{class:"flow-canvas-quick-add__default-content"},"节点快捷操作面板",-1))],!0)],544)):o.createCommentVNode("",!0)]),_:3})],36))}}),$e=ne(Vt,[["__scopeId","data-v-336cc3b4"]]),zt={class:"flow-canvas-selection-actions__bar"},Ht=o.defineComponent({__name:"selection-actions-toolbar",props:{position:{},canDelete:{type:Boolean}},emits:["action"],setup(s,{emit:e}){const t=s,r=e,n=o.computed(()=>({left:`${t.position.x}px`,top:`${t.position.y}px`,transform:"translateX(-100%)"}));return(i,a)=>(o.openBlock(),o.createElementBlock("div",{class:"flow-canvas-selection-actions",style:o.normalizeStyle(n.value)},[o.createElementVNode("div",zt,[o.createElementVNode("i",{class:o.normalizeClass(["flow-canvas-icon canvas-shanchu flow-canvas-selection-actions__icon",{"is-disabled":!s.canDelete}]),onClick:a[0]||(a[0]=c=>s.canDelete&&r("action","delete"))},null,2)])],4))}}),qt=ne(Ht,[["__scopeId","data-v-25eb8b79"]]),Ft={class:"flow-canvas-runtime-core__overlay"},Gt=o.defineComponent({__name:"canvas-runtime-core",props:{editor:{},graphOptions:{},nodeActions:{},quickAdd:{},getConnectionExcludedNodeIds:{type:Function}},emits:["ui-event"],setup(s,{emit:e}){const t=s,r=e,n=o.ref(),i=o.ref();let a,c,l,g,u=null,h=null,f=null,y=null;const m=_t(),{hoveredNodeId:C,isDraggingNode:M}=m,D=m.enterOverlay,T=()=>m.leaveOverlay(),O=o.ref(0),G=o.ref({nodeIds:[],edgeIds:[]});function R(E){const w=t.editor.api.value;return w?t.editor.schema.nodeTypes[E.type]?.getBehavior?.(E,{api:w,flowModel:t.editor.flowModel.value,history:t.editor.history,mode:t.editor.mode.value})??{}:{}}const q=o.computed(()=>t.editor.mode.value==="edit"&&t.editor.selectionMode.value),H=o.computed(()=>({showDebug:!1,showDelete:!0,showCopy:!0,showCopyInsert:!0,showDisconnect:!0,insertGap:100,...t.nodeActions})),N=o.computed(()=>{if(O.value,!t.editor.api.value)return[];const E=t.editor.flowModel.value,w=t.editor.api.value.overlay,_=[];for(const[$,X]of Object.entries(E.nodes)){const oe=t.editor._pluginManager.collectNodeDecorations(X);if(!oe?.badge)continue;const J=w.getNodeScreenRect($);J&&_.push({nodeId:$,x:J.x+J.width-4,y:J.y-8,badge:oe.badge})}return _}),L=o.computed(()=>{O.value;const E=C.value;if(!E||M.value||!t.editor.api.value||t.editor.mode.value!=="edit"||q.value)return null;const _=t.editor.flowModel.value.nodes[E];if(!_)return null;const $=t.editor.api.value.overlay.getNodeScreenRect(E);if(!$)return null;const X=R(_);return X.showActions===!1?null:{node:_,position:{x:$.x+$.width,y:$.y+$.height+4},behavior:X}}),v=o.computed(()=>{if(O.value,!t.editor.api.value||t.editor.mode.value!=="edit")return null;const E=G.value;if(E.nodeIds.length+E.edgeIds.length<=1)return null;const w=t.editor.api.value.getSelectionBounds(E);if(!w)return null;const _=Le(E,t.editor.flowModel.value,R);return{position:{x:w.x+w.width,y:w.y+w.height+4},canDelete:_.nodeIds.length>0||_.edgeIds.length>0}}),d=o.ref(),p=Bt({editor:t.editor,quickAddProp:o.computed(()=>t.quickAdd),isDraggingNode:M,nodeHover:m,isSelectionModeActive:q,viewportVersion:O,getNodeBehavior:R,getInsertGap:()=>H.value.insertGap,closePopover:()=>d.value?.closePopover()}),I=p.data,S=p.handleOpen,k=p.handleClose,V=p.handleStartDrag,Y=p.handleOverlayEnter,x=p.handleOverlayLeave,A=p.handleInsert,b=At(t.editor);function B(E,w){b.handleNodeAction(E,w,H.value.insertGap)&&(C.value=null)}function z(E){E==="delete"&&b.deleteSelection(G.value)}function U(E){if(t.editor.mode.value!=="edit")return;t.editor._pluginManager.dispatchKeyboardShortcut(E)&&(E.preventDefault(),E.stopPropagation())}function F(E,w){const _=a,$=X=>{const oe=_.isRubberbandEnabled?.()??!1;oe&&_.disableRubberband?.(),X?a.enablePanning():a.disablePanning(),oe&&_.enableRubberband?.()};E?(_.enableSelection?.(),w?(m.reset(),p.quickAddNodeId.value=null,p.quickAddPopoverOpen.value=!1,u?.remove(),$(!1),_.enableRubberband?.()):(_.disableRubberband?.(),$(!0))):(_.disableRubberband?.(),$(!0),_.disableSelection?.())}function Q(E){a.on("node:move",({node:w})=>{M.value=!0;const _=t.editor.flowModel.value.nodes[w.id];_&&R(_).bringToFrontOnDrag===!1||w.toFront?.()}),a.on("node:moved",()=>{M.value=!1}),a.on("node:mouseenter",({node:w})=>{if(q.value){C.value=null,p.quickAddNodeId.value=null,E.hideNodePorts(w);return}m.enter(w.id);const _=t.editor.flowModel.value.nodes[w.id];if(_&&R(_).showPorts===!1){p.mergedConfig.value.enabled&&p.enter(w.id);return}p.mergedConfig.value.enabled&&p.enter(w.id)||E.showNodePorts(w)}),a.on("node:mouseleave",({node:w})=>{if(q.value){E.hideNodePorts(w);return}const _=t.editor.flowModel.value.nodes[w.id];let $=100;_&&R(_).actionsOffset&&($=300),m.leave($),p.mergedConfig.value.enabled?p.quickAddNodeId.value===w.id&&!p.quickAddPopoverOpen.value?p.leave():p.quickAddNodeId.value!==w.id&&E.hideNodePorts(w):E.hideNodePorts(w)})}function W(E){a.on("edge:added",({edge:w})=>{let _;if(t.getConnectionExcludedNodeIds&&!w.getTargetCell()){const $=w.getSourceCell();if($){const X=t.getConnectionExcludedNodeIds($.id);_=X instanceof Set?X:new Set(X)}}E.handleEdgeAdded(w,_)}),a.on("edge:connected",()=>{E.handleEdgeConnected()}),a.on("edge:removed",({edge:w})=>{E.handleEdgeRemoved(w.id),u.handleEdgeRemoved(w.id)}),a.on("edge:mouseenter",({edge:w,e:_})=>{c.setHoveredEdge(w.id),c.refreshEdgeStyles(),t.editor.mode.value==="edit"&&!q.value&&E.canShowEdgeTool()&&u.show(w.id,_)}),a.on("edge:mouseleave",()=>{c.setHoveredEdge(null),c.refreshEdgeStyles(),u.remove()}),a.on("edge:click",({edge:w,e:_})=>{_.target?.closest?.(".flow-canvas-edge-delete-tool")&&t.editor.mode.value==="edit"&&(u.remove(),t.editor.executeCommand({id:j(),source:"user:toolbar",label:"删除连线",timestamp:Date.now(),commands:[{type:"edge.remove",edgeId:w.id}]}))}),h=w=>u.move(w),a.container.addEventListener("mousemove",h)}function te(){f=E=>{if(!C.value&&!p.quickAddNodeId.value)return;const w=E.target;if(w?.closest?.(".x6-node")||w?.closest?.(".flow-canvas-node-actions")||w?.closest?.(".flow-canvas-quick-add")){m.cancelLeave(),p.cancelLeave();return}m.leave(180),p.quickAddPopoverOpen.value||p.leave()},n.value?.addEventListener("mousemove",f),y=()=>{m.reset(),p.quickAddPopoverOpen.value||(p.quickAddNodeId.value=null)},n.value?.addEventListener("mouseleave",y),n.value?.addEventListener("keydown",U)}function Z(){o.watch(()=>t.editor.flowModel.value,E=>c.syncFlowModel(E)),o.watch([()=>t.editor.mode.value,()=>t.editor.selectionMode.value],([E,w])=>{F(E==="edit",w)},{immediate:!0})}return o.onMounted(()=>{if(!i.value)return;const E=new Set(["model","container"]),w={};if(t.graphOptions)for(const[P,se]of Object.entries(t.graphOptions)){if(E.has(P)){console.warn(`[flow-canvas] graphOptions.${P} is managed by the engine and will be ignored`);continue}w[P]=se}a=new Ke.Graph({container:i.value,autoResize:!0,background:{color:"#edf2fc"},grid:{visible:!0,size:20,type:"dot"},highlighting:{magnetAdsorbed:{name:"className",args:{className:"flow-canvas-magnet-adsorbed"}}},panning:{enabled:!0},mousewheel:{enabled:!0,modifiers:["ctrl","meta"]},interacting:{nodeMovable(P){return P.cell.getProp("draggable")!==!1}},connecting:{allowBlank:!1,allowMulti:!0,allowLoop:!1,allowNode:!1,allowEdge:!1,highlight:!0,anchor:"center",connectionPoint:"anchor",snap:{radius:30},createEdge(){return Tt(this,t.editor.schema)}},...w}),l=new kt,c=new wt(a,t.editor.schema,l,P=>t.editor._pluginManager.collectNodeDecorations(P),P=>t.editor._pluginManager.collectEdgeDecorations(P),()=>t.editor.api.value?{api:t.editor.api.value,flowModel:t.editor.flowModel.value,history:t.editor.history,mode:t.editor.mode.value}:null);const _=Ct(a),$=St({graph:a,overlayManager:_,executeCommand:P=>t.editor.executeCommand(P),schema:t.editor.schema,flowModel:t.editor.flowModel,getNodeBehavior:R,idGenerator:t.editor.idGenerator,defaultInsertGap:t.nodeActions?.insertGap,getContextMenuItems:P=>t.editor._pluginManager.collectContextMenuItems(P),onHighlightChange:(P,se)=>{c.setHighlightedNodes(P),c.setHighlightedEdges(se),c.refreshNodeHighlights(),c.refreshEdgeStyles()},resolveNodeShape:P=>{const se=t.editor.schema.nodeTypes[P];if(!se)return null;const ce=l.registerNodeType(P,se.component),ie=se.getSize({id:"",type:P,position:{x:0,y:0}});return{shapeName:ce,width:ie.width,height:ie.height}}});t.editor.api.value=$;const X={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:$,overlay:_,graph:a};t.editor._pluginManager.attachRuntime(X);const oe=t.editor._pluginManager.collectExtendedApi();Object.assign(t.editor.extendedApi,oe),t.editor._emitUiEvent=P=>{t.editor._pluginManager.dispatchUiEvent(P),r("ui-event",P)},g=new Et(a,P=>{(P.type==="node.click"||P.type==="node.dblclick"||P.type==="node.contextmenu")&&m.enter(P.nodeId),t.editor._emitUiEvent(P)},P=>{if(c.isSyncing)return;if(t.editor.executeCommand(P).status!=="applied"){for(const ce of P.commands)if(ce.type==="edge.add"){const ie=a.getCellById(ce.edge.id);ie&&a.removeCell(ie)}}},t.editor.flowModel,t.editor.idGenerator),u=Mt(a);const J=Dt(a);p.attachRuntime(a,P=>J.hideNodePorts(P)),Q(J),W(J),a.on("selection:changed",()=>{const P=Re(a.getSelectedCells?.()??[]);G.value=P,t.editor._pluginManager.dispatchSelectionChange(P),r("ui-event",{type:"selection.change",nodeIds:P.nodeIds,edgeIds:P.edgeIds}),c.refreshNodeHighlights(),c.refreshEdgeStyles()});const K=()=>{O.value++};a.on("translate",K),a.on("scale",K),a.on("resize",K),te(),c.syncFlowModel(t.editor.flowModel.value),Z()}),o.onBeforeUnmount(()=>{m.cleanup(),p.cleanup(),u?.remove(),h&&a?.container?.removeEventListener("mousemove",h),f&&n.value?.removeEventListener("mousemove",f),y&&n.value?.removeEventListener("mouseleave",y),n.value?.removeEventListener("keydown",U),t.editor._pluginManager.detachRuntime(),t.editor.api.value=null;for(const E of Object.keys(t.editor.extendedApi))delete t.editor.extendedApi[E];g?.dispose(),c?.dispose(),l?.dispose(),a?.dispose()}),(E,w)=>(o.openBlock(),o.createElementBlock("div",{ref_key:"rootRef",ref:n,class:o.normalizeClass(["flow-canvas-runtime-core",{"flow-canvas-runtime-core--selection-mode":q.value}]),tabindex:"0"},[o.createElementVNode("div",{ref_key:"containerRef",ref:i,class:"flow-canvas-runtime-core__graph"},null,512),o.createElementVNode("div",Ft,[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(N.value,_=>(o.openBlock(),o.createElementBlock("div",{key:`badge-${_.nodeId}`,class:"flow-canvas-runtime-core__badge",style:o.normalizeStyle({left:`${_.x}px`,top:`${_.y}px`,backgroundColor:_.badge.color})},o.toDisplayString(_.badge.text),5))),128)),o.unref(I)?(o.openBlock(),o.createBlock($e,{key:0,ref_key:"quickAddPopoverRef",ref:d,node:o.unref(I).node,"port-position":o.unref(I).portPosition,onOpen:o.unref(S),onClose:o.unref(k),onStartDrag:o.unref(V),onMouseenter:o.unref(Y),onMouseleave:o.unref(x)},{default:o.withCtx(()=>[o.renderSlot(E.$slots,"quick-add-panel",{node:o.unref(I).node,api:s.editor.api.value,insertNodeToRight:_=>o.unref(A)(o.unref(I).node.id,_),closePopover:()=>d.value?.closePopover()},void 0,!0)]),_:3},8,["node","port-position","onOpen","onClose","onStartDrag","onMouseenter","onMouseleave"])):o.createCommentVNode("",!0),L.value?(o.openBlock(),o.createBlock(Oe,{key:1,node:L.value.node,position:L.value.position,config:H.value,behavior:L.value.behavior,"actions-offset":L.value.behavior.actionsOffset,onAction:B,onMouseenter:o.unref(D),onMouseleave:T},null,8,["node","position","config","behavior","actions-offset","onMouseenter"])):o.createCommentVNode("",!0),v.value?(o.openBlock(),o.createBlock(qt,{key:2,position:v.value.position,"can-delete":v.value.canDelete,onAction:z},null,8,["position","can-delete"])):o.createCommentVNode("",!0)])],2))}}),Ut=ne(Gt,[["__scopeId","data-v-84f96992"]]),jt={class:"flow-canvas-node-palette"},Wt=["data-node-type"],Xt={class:"flow-canvas-node-palette__item-label"},Kt=o.defineComponent({__name:"canvas-node-palette",props:{editor:{},items:{}},setup(s){const e=s,t=o.ref(),r=o.computed(()=>e.items?e.items:Object.keys(e.editor.schema.nodeTypes).map(n=>({type:n,label:n.charAt(0).toUpperCase()+n.slice(1)})));return o.watch([()=>e.editor.api.value,r,t],([n,i,a],c,l)=>{if(!n||!a)return;const g=[];for(const u of i){const h=a.querySelector(`[data-node-type="${u.type}"]`);if(!h)continue;const f=n.registerDndSource(h,()=>({id:j(),type:u.type,label:u.label,position:{x:0,y:0}}));g.push(f)}l(()=>{for(const u of g)u()})},{flush:"post"}),(n,i)=>(o.openBlock(),o.createElementBlock("div",jt,[o.createElementVNode("div",{ref_key:"listRef",ref:t,class:"flow-canvas-node-palette__list"},[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(r.value,a=>(o.openBlock(),o.createElementBlock("div",{key:a.type,class:"flow-canvas-node-palette__item","data-node-type":a.type},[a.icon?(o.openBlock(),o.createElementBlock("i",{key:0,class:o.normalizeClass([a.icon,"flow-canvas-node-palette__item-icon"])},null,2)):o.createCommentVNode("",!0),o.createElementVNode("span",Xt,o.toDisplayString(a.label),1)],8,Wt))),128))],512)]))}}),Ve=ne(Kt,[["__scopeId","data-v-300314b7"]]),Yt={class:"flow-canvas-layout"},Qt={class:"flow-canvas-layout__main"},Zt={class:"flow-canvas-layout__content"},Jt={key:0,class:"flow-canvas-layout__footer"},eo=o.defineComponent({__name:"canvas-layout",props:{sidebarCollapsed:{type:Boolean,default:!1},sidebarWidth:{default:260},hideSidebar:{type:Boolean,default:!1},hideFooter:{type:Boolean,default:!1},editor:{default:void 0},paletteItems:{default:void 0}},emits:["update:sidebarCollapsed"],setup(s){return(e,t)=>(o.openBlock(),o.createElementBlock("div",Yt,[!s.hideSidebar&&(e.$slots.sidebar||s.editor)?(o.openBlock(),o.createElementBlock("aside",{key:0,class:o.normalizeClass(["flow-canvas-layout__sidebar",{"is-collapsed":s.sidebarCollapsed}]),style:o.normalizeStyle({width:s.sidebarCollapsed?"0px":`${s.sidebarWidth}px`})},[o.renderSlot(e.$slots,"sidebar",{},()=>[s.editor?(o.openBlock(),o.createBlock(Ve,{key:0,editor:s.editor,items:s.paletteItems},null,8,["editor","items"])):o.createCommentVNode("",!0)],!0)],6)):o.createCommentVNode("",!0),o.createElementVNode("div",Qt,[o.createElementVNode("div",Zt,[o.renderSlot(e.$slots,"default",{},void 0,!0)]),!s.hideFooter&&e.$slots.footer?(o.openBlock(),o.createElementBlock("div",Jt,[o.renderSlot(e.$slots,"footer",{},void 0,!0)])):o.createCommentVNode("",!0)])]))}}),to=ne(eo,[["__scopeId","data-v-26f35b6b"]]),oo=["undo","redo"];function ze(s){const e=new Set(s?.include),t=new Set(oo.filter(l=>!e.has(l))),r=[{id:"undo",type:"undo",group:"history",icon:"flow-canvas-icon canvas-undo",description:"撤销",order:10},{id:"redo",type:"redo",group:"history",icon:"flow-canvas-icon canvas-redo",description:"重做",order:11}],n=[{id:"select",type:"select",group:"tools",icon:"flow-canvas-icon canvas-kuangxuan",description:"框选",order:20},{id:"auto-layout",type:"auto-layout",group:"tools",icon:"flow-canvas-icon canvas-beautify",description:"自动排版",order:21},{id:"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[...[...r,...n].filter(l=>!t.has(l.type)),...i,...a]}const no={class:"flow-canvas-toolbar"},so={key:0,class:"flow-canvas-toolbar__separator"},ro={class:"flow-canvas-toolbar__group"},io={key:0,class:"flow-canvas-toolbar__zoom-display"},ao=["data-toolbar-id","data-toolbar-type","disabled","onClick","onMouseenter"],lo=["textContent"],co=o.defineComponent({__name:"canvas-toolbar",props:{items:{},exclude:{},editor:{}},setup(s){const e=new Set(["undo","redo","select","auto-layout","search","minimap","export"]),t=new Set(["select","search","minimap"]);function r(d){return d.id.startsWith("plugin:")||d.type==="custom"}function n(d){return d!=="custom"&&t.has(d)}const i=s,a=o.computed(()=>{if(i.items)return i.items;const d=ze(),p=i.editor.toolbarItems.value,I=new Set(i.exclude??[]),S=new Map;for(const k of d)S.set(k.id,k);for(const k of p){const V=S.get(k.id);V?S.set(k.id,{...V,...k,order:V.order,group:V.group}):r(k)&&S.set(k.id,k)}return[...S.values()].filter(k=>k.type==="custom"||!e.has(k.type)?!0:!I.has(k.type)).sort((k,V)=>(k.order??0)-(V.order??0))}),c=o.ref(1),l=o.ref(null),g=o.ref(null),u=o.ref(!1);let h=null;o.watch(()=>i.editor.api.value,d=>{h?.(),h=null,d&&(c.value=d.getZoom(),h=d.onGraphEvent("scale",()=>{c.value=d.getZoom()}))},{immediate:!0});const f=o.reactive({visible:!1,text:"",x:0,y:0});function y(d,p){if(!p.description)return;const S=d.currentTarget.getBoundingClientRect();f.text=p.description,f.visible=!0,o.nextTick(()=>{const k=l.value?.offsetWidth??0,V=l.value?.offsetHeight??0;f.x=S.left+S.width/2-k/2,f.y=S.top-V-6})}function m(){f.visible=!1,l.value=null}o.onScopeDispose(()=>{h?.()});const C=o.computed(()=>`${Math.round(c.value*100)}%`),M=o.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 D(d){return d.visible===!1?!1:typeof d.visible=="function"?M.value?d.visible(M.value):!1:!0}function T(d){return typeof d.active=="function"?M.value?d.active(M.value):!1:d.active!==void 0?d.active:d.type==="select"?i.editor.selectionMode.value:!1}const O=o.computed(()=>{const d=L.value.filter(I=>n(I.type)&&T(I));if(d.length===0)return null;const p=g.value;return p&&d.some(I=>I.type===p)?p:d[0]?.type??null});function G(d){return n(d.type)?O.value===d.type:T(d)}function R(d){return!M.value||d.disabled===!0?!0:typeof d.disabled=="function"?d.disabled(M.value):d.type==="undo"?!i.editor.history.canUndo.value:d.type==="redo"?!i.editor.history.canRedo.value:d.type==="export"?u.value:!1}function q(d){if(!(!M.value||!n(d.type)||!T(d))){if(d.type==="select"){i.editor.setSelectionMode(!1);return}d.onClick?.(M.value)}}function H(d){if(n(d.type))for(const p of L.value)!n(p.type)||p.id===d.id||q(p)}function N(d){if(!M.value||R(d))return;if(n(d.type)&&(g.value=d.type,H(d)),d.onClick){d.onClick(M.value);return}const{api:p}=M.value;switch(d.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(u.value)break;u.value=!0,p.exportAsImage().then(I=>{const S=URL.createObjectURL(I),k=document.createElement("a");k.href=S,k.download="canvas-export.png",k.click(),URL.revokeObjectURL(S)}).catch(I=>{console.warn("[flow-canvas] Export failed:",I)}).finally(()=>{u.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] "${d.type}" toolbar item has no built-in handler. Provide an onClick callback.`);break;default:d.type!=="custom"&&console.warn(`[flow-canvas] No default handler for toolbar type "${d.type}". Provide an onClick handler.`);break}}const L=o.computed(()=>a.value.filter(D)),v=o.computed(()=>{const d=new Map,p=[];for(const I of L.value){const S=I.group??"default";d.has(S)||(d.set(S,[]),p.push(S)),d.get(S).push(I)}return p.map(I=>({name:I,items:d.get(I)})).filter(I=>I.items.length>0)});return(d,p)=>(o.openBlock(),o.createElementBlock("div",no,[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(v.value,(I,S)=>(o.openBlock(),o.createElementBlock(o.Fragment,{key:I.name},[S>0?(o.openBlock(),o.createElementBlock("div",so)):o.createCommentVNode("",!0),o.createElementVNode("div",ro,[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(I.items,k=>(o.openBlock(),o.createElementBlock(o.Fragment,{key:k.id},[k.type==="zoom-display"?(o.openBlock(),o.createElementBlock("span",io,o.toDisplayString(C.value),1)):(o.openBlock(),o.createElementBlock("button",{key:1,type:"button",class:o.normalizeClass(["flow-canvas-toolbar__btn",{"is-disabled":R(k),"is-active":G(k),"is-exporting":k.type==="export"&&u.value}]),"data-toolbar-id":k.id,"data-toolbar-type":k.type,disabled:R(k),onClick:V=>N(k),onMouseenter:V=>y(V,k),onMouseleave:m},[k.component?(o.openBlock(),o.createBlock(o.resolveDynamicComponent(k.component),{key:0})):k.icon?(o.openBlock(),o.createElementBlock("i",{key:1,class:o.normalizeClass(k.icon)},null,2)):(o.openBlock(),o.createElementBlock("span",{key:2,class:"flow-canvas-toolbar__text",textContent:o.toDisplayString(k.text??k.description??k.id)},null,8,lo))],42,ao))],64))),128))])],64))),128)),(o.openBlock(),o.createBlock(o.Teleport,{to:"body"},[f.visible?(o.openBlock(),o.createElementBlock("div",{key:0,ref_key:"tooltipRef",ref:l,class:"flow-canvas-toolbar-tooltip",style:o.normalizeStyle({left:`${f.x}px`,top:`${f.y}px`})},[o.createTextVNode(o.toDisplayString(f.text)+" ",1),p[0]||(p[0]=o.createElementVNode("div",{class:"flow-canvas-toolbar-tooltip__arrow"},null,-1))],4)):o.createCommentVNode("",!0)]))]))}}),uo=ne(co,[["__scopeId","data-v-77d4afbb"]]),fo={class:"flow-canvas-default-node__ep-label"},po={key:1,class:"flow-canvas-default-node__diamond flow-canvas-highlight-target"},go={key:2,class:"flow-canvas-default-node__task-label"},ho=o.defineComponent({__name:"default-node",setup(s){const t=o.inject("getNode")?.(),r=o.computed(()=>t?.getData?.()??null),n=o.computed(()=>r.value?.label||r.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=o.computed(()=>{const u=r.value?.type??"";return a.has(u)?"endpoint":c.has(u)?"gateway":"task"}),g=o.computed(()=>i[r.value?.type??""]??"");return(u,h)=>(o.openBlock(),o.createElementBlock("div",{class:o.normalizeClass(["flow-canvas-default-node",[`is-${l.value}`,{"flow-canvas-highlight-target":l.value!=="gateway"}]])},[l.value==="endpoint"?(o.openBlock(),o.createElementBlock(o.Fragment,{key:0},[g.value?(o.openBlock(),o.createElementBlock("i",{key:0,class:o.normalizeClass([["flow-canvas-icon",g.value],"flow-canvas-default-node__ep-icon"])},null,2)):o.createCommentVNode("",!0),o.createElementVNode("span",fo,o.toDisplayString(n.value),1)],64)):l.value==="gateway"?(o.openBlock(),o.createElementBlock("div",po,[g.value?(o.openBlock(),o.createElementBlock("i",{key:0,class:o.normalizeClass([["flow-canvas-icon",g.value],"flow-canvas-default-node__gw-icon"])},null,2)):o.createCommentVNode("",!0)])):(o.openBlock(),o.createElementBlock("span",go,o.toDisplayString(n.value),1))],2))}}),He=ne(ho,[["__scopeId","data-v-f0e24a9f"]]),vo={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}},Me=(s,e)=>({stroke:e.hovered?"#3a84ff":"#abb5cc",strokeWidth:2});function De(){return{attrs:{line:{stroke:"#abb5cc",strokeWidth:2,targetMarker:{name:"block",width:8,height:8}}}}}function qe(){return{manhattan:{router:{name:"manhattan",args:{padding:10,maxDirectionChange:90}},connector:{name:"rounded",args:{radius:8}},style:Me,x6EdgeConfig:De()},bezier:{connector:{name:"smooth"},style:Me,x6EdgeConfig:De()}}}function mo(s){const e=s?.nodeTypes??vo,t={},r=[];for(const[a,c]of Object.entries(e)){const l=c.width??150,g=c.height??50;t[a]={component:He,getSize:()=>({width:l,height:g}),getPorts:()=>Te()},r.push({type:a,label:c.label??a,icon:c.icon})}const n={...qe(),...s?.edgeTypes},i=s?.defaultEdgeType??"manhattan";return{schema:{nodeTypes:t,defaultEdgeType:i,edgeTypes:n},paletteItems:r}}function yo(s){return{name:"connection-validator",priority:10,transformCommand(e,t,r){for(const n of e.commands){if(n.type!=="edge.add"&&n.type!=="edge.reconnect")continue;const i=r.flowModel.value,a=n.type==="edge.add"?n.edge.source.nodeId:n.source?.nodeId,c=n.type==="edge.add"?n.edge.target.nodeId:n.target?.nodeId;if(!a||!c)continue;const l=i.nodes[a],g=i.nodes[c];if(!l||!g)continue;const u=n.type==="edge.add"?n.edge.source.portId:n.source?.portId,h=n.type==="edge.add"?n.edge.target.portId:n.target?.portId,f=u?l.ports?.find(D=>D.id===u):void 0,y=h?g.ports?.find(D=>D.id===h):void 0,m=n.type==="edge.reconnect"?n.edgeId:void 0,C=Object.values(i.edges).filter(D=>D.id!==m),M=s({flowModel:i,sourceNode:l,targetNode:g,sourcePort:f,targetPort:y,existingEdges:C});if(!M.valid)return{rejected:!0,reason:M.reason??"Connection validation failed",code:"validation_failed"}}return e}}}function bo(s){const{rubberband:e=!0,multiple:t=!0,movable:r=!0}=s??{};return{name:"selection",priority:90,attachRuntime(n){n.graph.use(new Qe.Selection({enabled:!0,rubberband:e,multiple:t,movable:r,pointerEvents:"none",showNodeSelectionBox:!0,filter:i=>!(i.isNode()&&(i.getData?.()??{})._selectable===!1)}))}}}function wo(s){const{tolerance:e=10,color:t="#3a84ff"}=s??{};let r=null;return{name:"snapline",priority:90,async attachRuntime(n){const{Snapline:i}=await import("@antv/x6-plugin-snapline");n.graph.use(new i({enabled:!0,tolerance:e,className:"flow-canvas-snapline"})),r=document.createElement("style"),r.textContent=`.flow-canvas-snapline line { stroke: ${t} !important; }`,document.head.appendChild(r)},detachRuntime(){r?.remove(),r=null}}}const ko={class:"flow-canvas-search-popover__input"},Eo=["value","placeholder"],Co=["onMouseenter","onClick"],xo={class:"flow-canvas-search-popover__item-label"},No={key:0,class:"flow-canvas-search-popover__item-subtitle"},Io={key:1,class:"flow-canvas-search-popover__empty"},So=o.defineComponent({__name:"search-popover",props:{open:{type:Boolean},position:{},query:{},results:{},placeholder:{default:"搜索节点名称"},emptyText:{default:"暂无匹配节点"},isAnchorTarget:{type:Function,default:void 0}},emits:["update:query","select","close"],setup(s,{emit:e}){const t=s,r=e,n=o.ref(null),i=o.ref(null),a=o.ref(-1);o.watch(()=>t.open,m=>{m&&(a.value=-1,o.nextTick(()=>{n.value?.focus(),n.value?.select()}))}),o.watch(()=>t.query,()=>{a.value=-1}),o.watch(()=>t.results.length,m=>{if(!m){a.value=-1;return}a.value>=m&&(a.value=-1)});function c(m){r("update:query",m.target.value)}function l(m){a.value=m}function g(){a.value=-1}function u(){r("update:query",""),o.nextTick(()=>{n.value?.focus()})}function h(){const m=t.results[a.value]??t.results[0];m&&r("select",m.id)}function f(m){if(m.key==="Escape"){m.preventDefault(),r("close");return}if(m.key==="ArrowDown"){if(m.preventDefault(),!t.results.length)return;a.value=a.value<t.results.length-1?a.value+1:0;return}if(m.key==="ArrowUp"){if(m.preventDefault(),!t.results.length)return;a.value=a.value>0?a.value-1:t.results.length-1;return}m.key==="Enter"&&(m.preventDefault(),h())}function y(m){if(!t.open)return;const C=m.target;C&&i.value?.contains(C)||t.isAnchorTarget?.(m.target)||r("close")}return o.onMounted(()=>{document.addEventListener("mousedown",y)}),o.onBeforeUnmount(()=>{document.removeEventListener("mousedown",y)}),(m,C)=>s.open?(o.openBlock(),o.createElementBlock("div",{key:0,ref_key:"panelRef",ref:i,class:"flow-canvas-search-popover",style:o.normalizeStyle({left:`${s.position.x}px`,top:`${s.position.y}px`,width:`${s.position.width}px`})},[o.createElementVNode("div",ko,[C[1]||(C[1]=o.createElementVNode("i",{class:"flow-canvas-icon canvas-search"},null,-1)),o.createElementVNode("input",{ref_key:"inputRef",ref:n,value:s.query,placeholder:s.placeholder,onInput:c,onKeydown:f},null,40,Eo),s.query?(o.openBlock(),o.createElementBlock("button",{key:0,type:"button",class:"flow-canvas-search-popover__clear","aria-label":"清空搜索",onClick:u},[...C[0]||(C[0]=[o.createElementVNode("i",{class:"flow-canvas-icon canvas-close-circle-shape"},null,-1)])])):o.createCommentVNode("",!0)]),s.results.length?(o.openBlock(),o.createElementBlock("div",{key:0,class:"flow-canvas-search-popover__list",onMouseleave:g},[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(s.results,(M,D)=>(o.openBlock(),o.createElementBlock("button",{key:M.id,type:"button",class:o.normalizeClass(["flow-canvas-search-popover__item",{"is-active":D===a.value}]),onMouseenter:T=>l(D),onClick:T=>r("select",M.id)},[o.createElementVNode("span",xo,o.toDisplayString(M.label),1),M.subtitle?(o.openBlock(),o.createElementBlock("span",No,o.toDisplayString(M.subtitle),1)):o.createCommentVNode("",!0)],42,Co))),128))],32)):(o.openBlock(),o.createElementBlock("div",Io,o.toDisplayString(s.emptyText),1))],4)):o.createCommentVNode("",!0)}}),_o=ne(So,[["__scopeId","data-v-c80f6b26"]]),Be=282,Mo=4,Do=300,Bo=360,me=100,Ao=Bo*4-me;function Po(s){return s!==null}function To(s){const e=new Set;return s.map(t=>t?.trim()).filter(t=>!!t).filter(t=>{const r=t.toLowerCase();return e.has(r)?!1:(e.add(r),!0)})}function Ro(s,e){const t=Math.max(8,window.innerWidth-e-8);return Math.min(Math.max(8,s),t)}function Lo(s,e){const t=e?.getNodeMeta?.(s);if(t===null)return null;const r=t?.label?.trim()||s.label?.trim()||s.id,n=t?.subtitle?.trim()||void 0,i=To(t?.keywords??[s.label,n]);return i.length?{id:s.id,label:r,subtitle:n,keywords:i}:null}function Oo(s){let e=null,t=null,r=null,n=null,i=null,a=[];const c=o.ref(!1),l=o.ref(""),g=o.ref({x:0,y:0,width:Be}),u=o.computed(()=>e?Object.values(e.flowModel.value.nodes).map(N=>Lo(N,s)).filter(Po):[]),h=o.computed(()=>{const N=l.value.trim().toLowerCase(),L=Math.max(1,s?.maxResults??Do);return N?u.value.filter(v=>v.keywords.some(d=>d.toLowerCase().includes(N))).slice(0,L):u.value.slice(0,L)});function f(){return r?.querySelector('.flow-canvas-toolbar__btn[data-toolbar-type="search"]')}function y(){return f()?.closest(".flow-canvas-toolbar")}function m(){const N=y(),L=r?.getBoundingClientRect(),v=N?.getBoundingClientRect()??L;if(!v)return;const d=Math.max(Be,Math.round(v.width));g.value={x:Ro(v.left,d),y:v.bottom+Mo,width:d}}function C(){a.forEach(N=>clearTimeout(N)),a=[],t?.api.clearHighlight()}function M(N){C();const L=setTimeout(()=>{t?.api.highlightNodes([N])},me),v=setTimeout(()=>{t?.api.clearHighlight(),a=[]},me+Ao);a.push(L,v)}function D(N){t&&(t.api.scrollToNode(N),M(N))}function T(){t&&(c.value=!0,m(),requestAnimationFrame(()=>m()))}function O(){c.value=!1,l.value=""}function G(){if(c.value){O();return}T()}function R(N){const L=f();return!!(L&&N instanceof Node&&L.contains(N))}function q(){c.value&&m()}const H=o.defineComponent({name:"FlowCanvasSearchHost",setup(){return()=>o.h(_o,{open:c.value,position:g.value,query:l.value,results:h.value,placeholder:s?.placeholder??"搜索节点名称",emptyText:s?.emptyText??"暂无匹配节点",isAnchorTarget:R,"onUpdate:query":N=>{l.value=N},onSelect:D,onClose:O})}});return{name:"search",priority:90,install(N){e=N},attachRuntime(N){t=N,r=N.graph.container.closest(".flow-canvas-layout__content")??N.graph.container.parentElement,n=document.createElement("div"),n.className="flow-canvas-search-host",document.body.append(n),i=o.createApp(H),i.mount(n),window.addEventListener("resize",q),window.addEventListener("scroll",q,!0)},detachRuntime(){O(),C(),window.removeEventListener("resize",q),window.removeEventListener("scroll",q,!0),i?.unmount(),i=null,n?.remove(),n=null,r=null,t=null},dispose(){O(),C(),e=null},provideToolbarItems(){return[{id:"plugin:search",type:"search",icon:"flow-canvas-icon canvas-search",description:"搜索节点",group:"tools",order:22,active:()=>c.value,onClick:G}]}}}const $o=52,Vo=16,zo=40;function Ho(s){const e=document.createElement("div");e.className="flow-canvas-minimap",s.floating!==!1&&e.classList.add("flow-canvas-minimap--floating");const t=document.createElement("div");t.className="flow-canvas-minimap__host",e.append(t),Object.assign(e.style,{width:`${s.width}px`,height:`${s.height}px`}),s.floating!==!1&&Object.assign(e.style,{top:`${$o}px`,left:`${Vo}px`});let r=null,n=s.defaultOpen??!1,i=null;function a(){!s.onClickOutside||i||(i=f=>{const y=f.target;y&&e.contains(y)||f.target?.closest('[data-toolbar-type="minimap"]')||s.onClickOutside()},document.addEventListener("mousedown",i))}function c(){i&&(document.removeEventListener("mousedown",i),i=null)}function l(){r||(r=new Ze.MiniMap({container:t,width:s.width,height:s.height,padding:s.contentPadding??zo,scalable:!1}),s.sourceGraph.use(r))}function g(f){n=f,e.style.display=n?"":"none",n?(l(),a()):c()}function u(){g(n),s.mountTarget.appendChild(e)}function h(){c(),r?.dispose(),r=null,e.remove()}return u(),{element:e,isOpen:()=>n,setOpen:g,toggle(){const f=!n;return g(f),f},destroy:h}}function qo(s){let e=null;const t=o.ref(!1);function r(i){e?.setOpen(i),t.value=i}function n(){e&&(t.value=e.toggle())}return{name:"minimap",priority:90,attachRuntime(i){const a=s?.width??334,c=s?.height??180,l=s?.container??i.graph.container.closest(".flow-canvas-layout__content")??i.graph.container.parentElement;l&&(e=Ho({sourceGraph:i.graph,mountTarget:l,width:a,height:c,floating:!s?.container,defaultOpen:!1,onClickOutside:()=>r(!1)}),r(!1))},detachRuntime(){e?.destroy(),e=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:n}]}}}function Fo(){let s=null,e=0;return{name:"clipboard",priority:90,onKeyboardShortcut(t,r){const n=t.metaKey||t.ctrlKey;if(n&&t.key==="c"){const i=r.graph.getSelectedCells?.()??[];if(!i.length)return!1;const a=r.flowModel.value,c=new Set(i.filter(u=>u.isNode()).map(u=>u.id)),l=[...c].map(u=>a.nodes[u]).filter(Boolean);if(!l.length)return!1;const g=Object.values(a.edges).filter(u=>c.has(u.source.nodeId)&&c.has(u.target.nodeId));return s={nodes:l,edges:g},e=0,!0}if(n&&t.key==="v"){if(!s?.nodes.length)return!1;e++;const i=e*30,a=new Map,c=[];for(const l of s.nodes){const g=`${l.id}_cp${j().slice(0,6)}`;a.set(l.id,g),c.push({type:"node.add",node:{...l,id:g,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 s.edges){const g=a.get(l.source.nodeId),u=a.get(l.target.nodeId);!g||!u||c.push({type:"edge.add",edge:{...l,id:`${l.id}_cp${j().slice(0,6)}`,source:{...l.source,nodeId:g},target:{...l.target,nodeId:u},labels:l.labels?.map(h=>({...h,id:`${h.id}_cp${j().slice(0,6)}`})),payload:l.payload?{...l.payload}:{}}})}return c.length&&r.executeCommand({id:j(),source:"user:keyboard",label:"粘贴",timestamp:Date.now(),commands:c}),!0}return!1}}}exports.CanvasConstraintError=ee;exports.CanvasLayout=to;exports.CanvasNodePalette=Ve;exports.CanvasRuntime=Ut;exports.CanvasSchemaError=Ae;exports.CanvasToolbar=uo;exports.DefaultNode=He;exports.NodeActionsToolbar=Oe;exports.NodeQuickAddPopover=$e;exports.applyCanvasCommand=ue;exports.clipboardPlugin=Fo;exports.connectionValidatorPlugin=yo;exports.createBuiltinEdgeTypes=qe;exports.createCanvasHistory=Pe;exports.createDefaultSchema=mo;exports.createDefaultToolbarItems=ze;exports.createEmptyFlowModel=Je;exports.generateId=j;exports.minimapPlugin=qo;exports.searchPlugin=Oo;exports.selectionPlugin=bo;exports.snaplinePlugin=wo;exports.useCanvasEditor=vt;
1
+ "use strict";var je=Object.create;var Ce=Object.defineProperty;var We=Object.getOwnPropertyDescriptor;var Xe=Object.getOwnPropertyNames;var Ye=Object.getPrototypeOf,Ke=Object.prototype.hasOwnProperty;var Qe=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Xe(e))!Ke.call(r,n)&&n!==t&&Ce(r,n,{get:()=>e[n],enumerable:!(s=We(e,n))||s.enumerable});return r};var ye=(r,e,t)=>(t=r!=null?je(Ye(r)):{},Qe(e||!r||!r.__esModule?Ce(t,"default",{value:r,enumerable:!0}):t,r));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("vue"),Ze=require("@antv/x6"),Je=require("@antv/x6-vue-shape"),et=require("@antv/x6-plugin-selection"),tt=require("@antv/x6-plugin-minimap");function ot(){return{version:"1.0",nodes:{},edges:{}}}class oe extends Error{constructor(e){super(e),this.name="CanvasConstraintError"}}class Le extends Error{constructor(e){super(e),this.name="CanvasSchemaError"}}function pe(r,e,t){if(e.length===0){if(t===void 0)return;if(typeof t!="object"||t===null||Array.isArray(t))throw new Error("Root value of payload/extensions/meta must be an object or undefined");return t}const s=r?{...r}:{};let n=s;for(let a=0;a<e.length-1;a++){const c=e[a],l=n[c];l&&typeof l=="object"&&!Array.isArray(l)?n[c]={...l}:n[c]={},n=n[c]}const i=e[e.length-1];return t===void 0?delete n[i]:n[i]=t,s}function fe(r,e){switch(e.type){case"node.add":return nt(r,e.node);case"node.move":return st(r,e.nodeId,e.position);case"node.remove":return rt(r,e.nodeId);case"node.update":return it(r,e.nodeId,e.patch);case"node.set-payload":return at(r,e.nodeId,e.path,e.value);case"node.set-extensions":return lt(r,e.nodeId,e.path,e.value);case"edge.add":return ct(r,e.edge);case"edge.remove":return dt(r,e.edgeId);case"edge.reconnect":return ut(r,e.edgeId,e.source,e.target);case"edge.update":return ft(r,e.edgeId,e.patch);case"edge.set-payload":return pt(r,e.edgeId,e.path,e.value);case"edge.label.update":return gt(r,e.edgeId,e.labelId,e.patch);case"model.set-meta":return ht(r,e.path,e.value);default:throw new oe(`Unknown command type: ${e.type}`)}}function ce(r,e){const t=r.nodes[e];if(!t)throw new oe(`Node "${e}" does not exist`);return t}function de(r,e){const t=r.edges[e];if(!t)throw new oe(`Edge "${e}" does not exist`);return t}function le(r,e,t){const s=r.nodes[e.nodeId];if(!s)throw new oe(`${t} node "${e.nodeId}" does not exist`);if(e.portId&&s.ports&&!s.ports.some(i=>i.id===e.portId))throw new oe(`${t} port "${e.portId}" not found on node "${e.nodeId}"`)}function ge(r,e,t){return{...r,nodes:{...r.nodes,[e]:t}}}function he(r,e,t){return{...r,edges:{...r.edges,[e]:t}}}function nt(r,e){if(r.nodes[e.id])throw new oe(`Node id "${e.id}" already exists`);return{...r,nodes:{...r.nodes,[e.id]:e}}}function st(r,e,t){const s=ce(r,e);return ge(r,e,{...s,position:t})}function rt(r,e){ce(r,e);const{[e]:t,...s}=r.nodes,n={};for(const[i,a]of Object.entries(r.edges))a.source.nodeId!==e&&a.target.nodeId!==e&&(n[i]=a);return{...r,nodes:s,edges:n}}function it(r,e,t){const s=ce(r,e);return ge(r,e,{...s,...t,id:s.id})}function at(r,e,t,s){const n=ce(r,e),i=pe(n.payload,t,s);return ge(r,e,{...n,payload:i})}function lt(r,e,t,s){const n=ce(r,e),i=pe(n.extensions,t,s);return ge(r,e,{...n,extensions:i})}function ct(r,e){if(r.edges[e.id])throw new oe(`Edge id "${e.id}" already exists`);if(le(r,e.source,"Source"),le(r,e.target,"Target"),e.labels){const t=new Set;for(const s of e.labels){if(t.has(s.id))throw new oe(`Duplicate label id "${s.id}" in edge "${e.id}"`);t.add(s.id)}}return{...r,edges:{...r.edges,[e.id]:e}}}function dt(r,e){de(r,e);const{[e]:t,...s}=r.edges;return{...r,edges:s}}function ut(r,e,t,s){const n=de(r,e),i=t??n.source,a=s??n.target;return le(r,i,"Source"),le(r,a,"Target"),he(r,e,{...n,source:i,target:a})}function ft(r,e,t){const s=de(r,e),n={...s,...t,id:s.id};return t.source&&le(r,n.source,"Source"),t.target&&le(r,n.target,"Target"),he(r,e,n)}function pt(r,e,t,s){const n=de(r,e),i=pe(n.payload,t,s);return he(r,e,{...n,payload:i})}function gt(r,e,t,s){const n=de(r,e);if(!n.labels)throw new oe(`Edge "${e}" has no labels`);const i=n.labels.findIndex(c=>c.id===t);if(i===-1)throw new oe(`Label "${t}" not found in edge "${e}"`);const a=[...n.labels];return a[i]={...a[i],...s,id:t},he(r,e,{...n,labels:a})}function ht(r,e,t){const s=pe(r.meta,e,t);return{...r,meta:s}}function Re(r,e){const t=e?.maxHistorySize??100,s=o.ref(r),n=[],i=[],a=o.ref(!1),c=o.ref(!1);function l(){a.value=n.length>0,c.value=i.length>0}function v(N){const S=s.value;let B=S;for(const P of N.commands)B=fe(B,P);return n.push({snapshot:S,envelope:N}),n.length>t&&n.shift(),i.length=0,s.value=B,l(),B}function f(){const N=n.pop();return N?(i.push({snapshot:s.value,envelope:N.envelope}),s.value=N.snapshot,l(),N.snapshot):null}function g(){const N=i.pop();if(!N)return null;n.push({snapshot:s.value,envelope:N.envelope});let S=s.value;for(const B of N.envelope.commands)S=fe(S,B);return s.value=S,l(),S}function h(){n.length=0,i.length=0,l()}function k(){return s.value}function w(N){s.value=N,h()}return{currentFlowModel:s,execute:v,undo:f,redo:g,canUndo:a,canRedo:c,get undoStack(){return n.map(N=>N.envelope)},get redoStack(){return i.map(N=>N.envelope)},clear:h,createSnapshot:k,replaceFlowModel:w}}function vt(r){return r!==null&&typeof r=="object"&&r.rejected===!0}class mt{plugins=[];editorContext=null;runtimeCtx=null;runtimeVersion=0;install(e,t){this.plugins=[...e].sort((s,n)=>(s.priority??100)-(n.priority??100)),this.editorContext=t;for(const s of this.plugins)s.install?.(t)}attachRuntime(e){const t=++this.runtimeVersion;this.runtimeCtx=e;const s=this.createSafeRuntimeContext(e,t);for(const n of this.plugins)n.attachRuntime?.(s)}detachRuntime(){for(const e of[...this.plugins].reverse())e.detachRuntime?.();this.runtimeCtx=null}createSafeRuntimeContext(e,t){const s=this,n=new Proxy(e.graph,{get(i,a,c){const l=Reflect.get(i,a,c);return a==="use"&&typeof l=="function"?function(...f){if(s.runtimeVersion===t)return l.apply(i,f)}:l}});return{...e,graph:n}}dispose(){for(const e of[...this.plugins].reverse())e.dispose?.();this.plugins=[],this.editorContext=null,this.runtimeCtx=null}transformCommand(e){if(!this.editorContext)return{envelope:e};let t=e;for(const s of this.plugins){if(!s.transformCommand)continue;const n=this.createPreview(t),i=s.transformCommand(t,n,this.editorContext);if(i===null)return{rejected:!0,error:{code:"plugin_rejected",reason:"",source:s.name}};if(vt(i))return{rejected:!0,error:{code:i.code??"plugin_rejected",reason:i.reason,source:s.name}};t=i}return{envelope:t}}afterCommand(e,t,s){if(this.editorContext)for(const n of this.plugins)n.afterCommand?.(e,t,s,this.editorContext)}dispatchUiEvent(e){if(this.runtimeCtx)for(const t of this.plugins)t.onUiEvent?.(e,this.runtimeCtx)}dispatchSelectionChange(e){if(this.runtimeCtx)for(const t of this.plugins)t.onSelectionChange?.(e,this.runtimeCtx)}dispatchKeyboardShortcut(e){if(!this.runtimeCtx)return!1;for(const t of this.plugins)if(t.onKeyboardShortcut?.(e,this.runtimeCtx))return!0;return!1}collectContextMenuItems(e){if(!this.runtimeCtx)return[];const t=[];for(const s of this.plugins){const n=s.onBlankContextMenu?.(e,this.runtimeCtx);n&&t.push(...n)}return t}collectToolbarItems(){if(!this.editorContext)return[];const e=new Map;for(const t of this.plugins){const s=t.provideToolbarItems?.(this.editorContext);if(s)for(const n of s)e.set(n.id,n)}return[...e.values()].sort((t,s)=>(t.order??0)-(s.order??0))}collectNodeDecorations(e){if(!this.editorContext)return;let t;for(const s of this.plugins){const n=s.decorateNode?.(e,this.editorContext);n&&(t=t?{...t,...n}:n)}return t}collectEdgeDecorations(e){if(!this.editorContext)return;let t;for(const s of this.plugins){const n=s.decorateEdge?.(e,this.editorContext);n&&(t=t?{...t,...n}:n)}return t}collectExtendedApi(){if(!this.runtimeCtx)return{};const e={};for(const t of this.plugins){const s=t.extendApi?.(this.runtimeCtx.api,this.runtimeCtx);s&&Object.assign(e,s)}return e}createPreview(e){const t=this.editorContext;return{previewFlowModel(s){const n=s??e.commands;let i=t.flowModel.value;for(const a of n)i=fe(i,a);return i}}}}let yt=0;function Y(){const r=Date.now().toString(36),e=Math.random().toString(36).substring(2,8);return`${r}-${e}-${++yt}`}const Ee=()=>Y();function wt(r){const{schema:e,plugins:t=[],historyOptions:s}=r,n=r.idGenerator??Ee,i={version:"1.0",...r.initialFlowModel},a=Re(i,s),c=o.ref(r.mode??"edit"),l=o.ref(!1),v=o.ref(null),f=o.ref([]),g={},h=new mt;function k(B,P,V,U="user:toolbar"){const L={id:`history-${Date.now()}`,source:U,label:B,timestamp:Date.now(),commands:[]};h.afterCommand(L,P,V),f.value=h.collectToolbarItems(),r.onCommandResult?.({status:"applied",envelope:L,flowModel:V}),r.onFlowModelChange?.({flowModel:V,prevFlowModel:P,envelope:L,source:U})}const w={execute:a.execute,undo(){const B=a.currentFlowModel.value,P=a.undo();return P&&k("撤销",B,P),P},redo(){const B=a.currentFlowModel.value,P=a.redo();return P&&k("重做",B,P),P},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(B){const P=a.currentFlowModel.value;a.replaceFlowModel(B),k("替换 FlowModel",P,B,"system:replace")}},N={flowModel:o.computed(()=>a.currentFlowModel.value),history:w,schema:e,mode:c,idGenerator:n,executeCommand:S,replaceFlowModel(B){w.replaceFlowModel(B)},setMode(B){c.value=B},selectionMode:l,setSelectionMode(B){l.value=B},api:v,toolbarItems:f,extendedApi:g,_pluginManager:h,_emitUiEvent:B=>{h.dispatchUiEvent(B)}};h.install(t,{flowModel:N.flowModel,history:w,schema:e,mode:c,idGenerator:n,executeCommand:S}),f.value=h.collectToolbarItems(),o.onScopeDispose(()=>{h.dispose()});function S(B){const P=h.transformCommand(B);if("rejected"in P){const L={status:"rejected",envelope:B,error:P.error};return r.onCommandResult?.(L),L}const V=P.envelope,U=a.currentFlowModel.value;try{const L=a.execute(V),F={status:"applied",envelope:V,flowModel:L};return h.afterCommand(V,U,L),f.value=h.collectToolbarItems(),r.onCommandResult?.(F),r.onFlowModelChange?.({flowModel:L,prevFlowModel:U,envelope:V,source:V.source}),F}catch(L){if(L instanceof oe){const F={status:"invalid",envelope:V,error:{code:"constraint_violated",reason:L.message,source:"engine"}};return r.onCommandResult?.(F),F}throw L}}return N}const bt=["top","right","bottom","left"];function Oe(){return bt.map(r=>({id:r,group:r}))}function ke(r,e){return e?.(r)??r.ports??Oe()}const we=-1,Et="flow-canvas-node-ring-target",xe="flow-canvas-node-ring-target--decorated",Ie="flow-canvas-node-ring-target--pulse",kt="linear-gradient(135deg, #cadcfa 0%, #cee0ff 100%)";class Ct{graph;schema;shapeRegistry;resolveNodeDecoration;resolveEdgeDecoration;resolveCanvasContext;knownNodeIds=new Set;knownEdgeIds=new Set;syncing=!1;prevNodeDecorationClasses=new Map;prevNodeDecorationColors=new Set;prevEdgeDecorationClasses=new Map;prevEdgeDecorationColors=new Set;highlightedNodeIds=new Set;highlightedEdgeIds=new Set;hoveredEdgeId=null;defaultHighlightedNodeIds=new Set;defaultHighlightedEdgeIds=new Set;prevEdgeStyleIds=new Set;nodeDefaultAttrs=new Map;edgeDefaultAttrs=new Map;lastModel=null;constructor(e,t,s,n,i,a){this.graph=e,this.schema=t,this.shapeRegistry=s,this.resolveNodeDecoration=n,this.resolveEdgeDecoration=i,this.resolveCanvasContext=a}syncFlowModel(e){if(!this.syncing){this.syncing=!0,this.lastModel=e;try{const t=this.resolveNodes(e),s=this.resolveEdges(e);this.syncNodes(t),this.syncEdges(s,e)}finally{this.syncing=!1}}}get isSyncing(){return this.syncing}saveNodeDefaultAttrs(e,t){const n=t.x6CellConfig?.attrs?.body;if(!n)return;const i={};let a=!1;n.stroke!==void 0&&(i.stroke=n.stroke,a=!0),n.strokeWidth!==void 0&&(i.strokeWidth=n.strokeWidth,a=!0),a&&this.nodeDefaultAttrs.set(e,i)}saveEdgeDefaultAttrs(e,t){const n=t?.x6EdgeConfig?.attrs?.line;if(!n)return;const i={};let a=!1;n.stroke!==void 0&&(i.stroke=n.stroke,a=!0),n.strokeWidth!==void 0&&(i.strokeWidth=n.strokeWidth,a=!0),n.strokeDasharray!==void 0&&(i.strokeDasharray=n.strokeDasharray,a=!0),a&&this.edgeDefaultAttrs.set(e,i)}restoreNodeAttr(e,t,s){const n=this.nodeDefaultAttrs.get(e.id)?.[s];if(n!==void 0)e.setAttrByPath(t,n);else{const i=s==="stroke"?"none":0;e.setAttrByPath(t,i)}}restoreEdgeAttr(e,t,s){const n=this.edgeDefaultAttrs.get(e.id)?.[s];n!==void 0?this.setEdgeAttrIfChanged(e,t,n):e.attr(t)!==void 0&&e.removeAttrByPath(t)}setEdgeAttrIfChanged(e,t,s){e.attr(t)!==s&&e.setAttrByPath(t,s)}getNodeRingTarget(e){return e?e.querySelector(".flow-canvas-highlight-target")??e.querySelector(".flow-canvas-node-surface > :first-child"):null}syncEdgeMarker(e,t,s){const i=t?.x6EdgeConfig?.attrs?.line?.[s],a=`line/${s}`;e.removeAttrByPath(a),i!==void 0&&e.setAttrByPath(a,i)}dispose(){this.knownNodeIds.clear(),this.knownEdgeIds.clear()}resolveNodes(e){const t=new Map;for(const[s,n]of Object.entries(e.nodes)){const i=this.schema.nodeTypes[n.type];if(!i)throw new Le(`Unknown node type "${n.type}" for node "${s}". Registered types: [${Object.keys(this.schema.nodeTypes).join(", ")}]. Register the type in CanvasSchema.nodeTypes before using it in a FlowModel.`);const a=this.shapeRegistry.registerNodeType(n.type,i.component),c=i.getSize(n),l=ke(n,i.getPorts);t.set(s,{model:n,definition:i,shapeName:a,size:c,ports:l})}return t}resolveEdges(e){const t=new Map;for(const[s,n]of Object.entries(e.edges)){const i=n.type??this.schema.defaultEdgeType??"default",a=this.schema.edgeTypes?.[i];t.set(s,{model:n,definition:a})}return t}syncNodes(e){const t=new Set(e.keys());for(const s of this.knownNodeIds)if(!t.has(s)){const n=this.graph.getCellById(s);n&&this.graph.removeCell(n),this.knownNodeIds.delete(s),this.defaultHighlightedNodeIds.delete(s),this.prevNodeDecorationClasses.delete(s),this.prevNodeDecorationColors.delete(s),this.nodeDefaultAttrs.delete(s)}for(const[s,n]of e){const i=this.graph.getCellById(s);i?this.updateExistingNode(i,n):this.addNewNode(s,n)}}updateExistingNode(e,t){const{model:s,size:n,ports:i,definition:a}=t;if(e.getData()?.type!==s.type){this.graph.removeCell(e),this.addNewNode(e.id,t);return}const l=e.getPosition();(l.x!==s.position.x||l.y!==s.position.y)&&e.setPosition(s.position.x,s.position.y);const v=e.getSize();(v.width!==n.width||v.height!==n.height)&&e.setSize(n.width,n.height,{silent:!0}),this.syncNodePorts(e,i),e.setData({...s}),this.applyNodeBehavior(e,s,a),this.applyNodeHighlightAndDecoration(e,s)}syncNodePorts(e,t){const s=e.getPorts(),n=new Set(t.map(a=>a.id)),i=new Set(s.map(a=>a.id));for(const a of s)a.id&&!n.has(a.id)&&e.removePort(a.id);for(const a of t)i.has(a.id)||e.addPort({id:a.id,group:a.group,...a.x6PortConfig})}addNewNode(e,t){const{model:s,shapeName:n,size:i,ports:a,definition:c}=t,l={id:s.id,shape:n,x:s.position.x,y:s.position.y,width:i.width,height:i.height,data:{...s},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(f=>({id:f.id,group:f.group,...f.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,s,c),this.applyNodeHighlightAndDecoration(v,s))}applyNodeBehavior(e,t,s){if(!s.getBehavior)return;const n=this.resolveCanvasContext?.();if(!n)return;const i=s.getBehavior(t,n);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,t){const s=new Set(e.keys());for(const n of this.knownEdgeIds)if(!s.has(n)){const i=this.graph.getCellById(n);i&&this.graph.removeCell(i),this.knownEdgeIds.delete(n),this.defaultHighlightedEdgeIds.delete(n),this.prevEdgeDecorationClasses.delete(n),this.prevEdgeDecorationColors.delete(n),this.prevEdgeStyleIds.delete(n),this.edgeDefaultAttrs.delete(n)}for(const[n,i]of e){const a=this.graph.getCellById(n),{model:c,definition:l}=i;a?(this.updateExistingEdge(a,c,l,t),this.knownEdgeIds.has(n)||(this.knownEdgeIds.add(n),this.saveEdgeDefaultAttrs(n,l))):this.addNewEdge(n,c,l)}}updateExistingEdge(e,t,s,n){const i=e.getSource(),a=e.getTarget(),c=i.cell!==t.source.nodeId||i.port!==t.source.portId,l=a.cell!==t.target.nodeId||a.port!==t.target.portId;c&&e.setSource({cell:t.source.nodeId,port:t.source.portId}),l&&e.setTarget({cell:t.target.nodeId,port:t.target.portId});const f=(e.getData()?.type??void 0)!==(t.type??void 0);if(f){if(s?.router){const g=typeof s.router=="string"?{name:s.router}:s.router;e.setRouter(g)}if(s?.connector){const g=typeof s.connector=="string"?{name:s.connector}:s.connector;e.setConnector(g)}}(f||c||l)&&(this.syncEdgeMarker(e,s,"sourceMarker"),this.syncEdgeMarker(e,s,"targetMarker")),this.syncEdgeLabels(e,t),e.getZIndex()!==we&&e.setZIndex(we),e.setData({...t},{silent:!0}),this.applyEdgeStyleAndDecoration(e,t,s)}syncEdgeLabels(e,t){if(!t.labels?.length){e.getLabels().length>0&&e.setLabels([]);return}const s=t.labels.map(n=>({attrs:{label:{text:n.text??""}},position:n.position!=null?{distance:n.position}:void 0}));e.setLabels(s)}addNewEdge(e,t,s){const n={id:t.id,source:{cell:t.source.nodeId,port:t.source.portId},target:{cell:t.target.nodeId,port:t.target.portId},data:{...t},zIndex:we};s?.router&&(n.router=typeof s.router=="string"?{name:s.router}:s.router),s?.connector&&(n.connector=typeof s.connector=="string"?{name:s.connector}:s.connector),s?.x6EdgeConfig&&Object.assign(n,s.x6EdgeConfig),t.labels?.length&&(n.labels=t.labels.map(a=>({attrs:{label:{text:a.text??""}},position:a.position!=null?{distance:a.position}:void 0}))),this.graph.addEdge(n),this.knownEdgeIds.add(e),this.saveEdgeDefaultAttrs(e,s);const i=this.graph.getCellById(e);i&&this.applyEdgeStyleAndDecoration(i,t,s)}refreshEdgeStyles(){if(this.lastModel)for(const[e,t]of Object.entries(this.lastModel.edges)){const s=this.graph.getCellById(e);if(!s?.isEdge())continue;const n=t.type??this.schema.defaultEdgeType??"default",i=this.schema.edgeTypes?.[n];this.applyEdgeStyleAndDecoration(s,t,i)}}refreshSingleEdgeStyle(e){if(!this.lastModel)return;const t=this.lastModel.edges[e];if(!t)return;const s=this.graph.getCellById(e);if(!s?.isEdge())return;const n=t.type??this.schema.defaultEdgeType??"default",i=this.schema.edgeTypes?.[n];this.applyEdgeStyleAndDecoration(s,t,i)}refreshNodeHighlights(){if(this.lastModel)for(const[e,t]of Object.entries(this.lastModel.nodes)){const s=this.graph.getCellById(e);s?.isNode()&&this.applyNodeHighlightAndDecoration(s,t)}}applyNodeHighlightAndDecoration(e,t){const s=this.highlightedNodeIds.has(e.id),n=this.resolveNodeDecoration?.(t),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)),n?.className&&(i?.classList.add(n.className),this.prevNodeDecorationClasses.set(e.id,n.className));const l=n?.borderColor,f=l??(s?"#3a84ff":void 0),g=this.prevNodeDecorationColors.has(e.id)||this.defaultHighlightedNodeIds.has(e.id);f?(e.setAttrByPath("body/stroke",f),e.setAttrByPath("body/strokeWidth",2)):g&&(this.restoreNodeAttr(e,"body/stroke","stroke"),this.restoreNodeAttr(e,"body/strokeWidth","strokeWidth")),a&&(a.classList.add(Et),l?(a.classList.add(xe),a.style.setProperty("--flow-canvas-node-decoration-ring-background",l),a.style.setProperty("--flow-canvas-node-decoration-ring-opacity","0.95")):(a.classList.remove(xe),a.style.removeProperty("--flow-canvas-node-decoration-ring-background"),a.style.removeProperty("--flow-canvas-node-decoration-ring-opacity")),s?(a.classList.add(Ie),a.style.setProperty("--flow-canvas-node-pulse-ring-background",l??kt),a.style.setProperty("--flow-canvas-node-pulse-ring-opacity","0.95")):(a.classList.remove(Ie),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),s&&!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 t=this.highlightedEdgeIds;return this.highlightedEdgeIds=new Set(e),t}applyEdgeStyleAndDecoration(e,t,s){const n=this.highlightedEdgeIds.has(e.id),i=this.resolveEdgeDecoration?.(t),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(s?.style){const w=this.graph.isSelected?.(e)??!1,N=this.hoveredEdgeId===e.id,S=s.style(t,{selected:w,highlighted:n,hovered:N});c=S.stroke,l=S.strokeWidth,v=S.strokeDasharray}const f=!s?.style&&n?"#3a84ff":void 0,g=i?.strokeColor,h=g??c??f,k=!!s?.style||this.prevEdgeDecorationColors.has(e.id)||this.defaultHighlightedEdgeIds.has(e.id)||this.prevEdgeStyleIds.has(e.id);h?this.setEdgeAttrIfChanged(e,"line/stroke",h):k&&this.restoreEdgeAttr(e,"line/stroke","stroke"),s?.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)),g?this.prevEdgeDecorationColors.add(e.id):this.prevEdgeDecorationColors.delete(e.id),f?this.defaultHighlightedEdgeIds.add(e.id):this.defaultHighlightedEdgeIds.delete(e.id)}}class xt{instanceId=Y();registeredShapes=new Map;wrappedComponents=new Map;getShapeName(e){let t=this.registeredShapes.get(e);return t||(t=`flow-node-${this.instanceId}-${e}`,this.registeredShapes.set(e,t)),t}registerNodeType(e,t){const s=this.getShapeName(e);let n=this.wrappedComponents.get(e);return n||(n=o.defineComponent({name:`FlowCanvasNodeShape${e.replace(/(^|[-_])(\w)/g,(i,a,c)=>c.toUpperCase())}`,setup(){return()=>o.h("div",{class:"flow-canvas-node-surface"},[o.h(t)])}}),this.wrappedComponents.set(e,n)),Je.register({shape:s,component:n,width:100,height:40}),s}dispose(){this.registeredShapes.clear(),this.wrappedComponents.clear()}}class It{graph;onUiEvent;onCommand;flowModelRef;idGenerator;disposers=[];constructor(e,t,s,n,i){this.graph=e,this.onUiEvent=t,this.onCommand=s,this.flowModelRef=n,this.idGenerator=i??Ee,this.bindEvents()}dispose(){for(const e of this.disposers)e();this.disposers=[]}bindEvents(){this.on("node:click",({node:e})=>{this.onUiEvent({type:"node.click",nodeId:e.id})}),this.on("node:dblclick",({node:e})=>{this.onUiEvent({type:"node.dblclick",nodeId:e.id})}),this.on("node:contextmenu",({node:e,e:t})=>{this.onUiEvent({type:"node.contextmenu",nodeId:e.id,position:{x:t.clientX,y:t.clientY}})}),this.on("edge:click",({edge:e,e:t})=>{const n=t.target?.closest?.(".x6-edge-label");if(n){const a=e.getData?.()?.labels??[],c=n.parentElement?.querySelectorAll(".x6-edge-label"),l=c?Array.from(c).indexOf(n):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 t=this.graph.clientToLocal(e.clientX,e.clientY);this.onUiEvent({type:"blank.click",position:{x:t.x,y:t.y}})}),this.on("blank:contextmenu",({e})=>{this.onUiEvent({type:"blank.contextmenu",position:{x:e.clientX,y:e.clientY}})}),this.on("node:moved",({node:e})=>{const t=e.getPosition();this.onCommand({id:Y(),source:"user:drag",label:"移动节点",timestamp:Date.now(),commands:[{type:"node.move",nodeId:e.id,position:{x:t.x,y:t.y}}]})}),this.on("edge:connected",({edge:e,isNew:t})=>{const s=e.getSourceCell(),n=e.getTargetCell();if(!s||!n)return;const i=e.getSourcePortId(),a=e.getTargetPortId(),c=e.id in this.flowModelRef.value.edges;t&&!c?(this.graph.removeCell(e),this.onCommand({id:Y(),source:"user:drag",label:"连线",timestamp:Date.now(),commands:[{type:"edge.add",edge:{id:this.idGenerator("edge"),source:{nodeId:s.id,portId:i??void 0},target:{nodeId:n.id,portId:a??void 0}}}]})):this.onCommand({id:Y(),source:"user:drag",label:"重连",timestamp:Date.now(),commands:[{type:"edge.reconnect",edgeId:e.id,source:{nodeId:s.id,portId:i??void 0},target:{nodeId:n.id,portId:a??void 0}}]})}),this.on("edge:change:labels",({edge:e,current:t})=>{const n=e.getData?.()?.labels??[];if(!n.length||!t?.length)return;const i=[];for(let a=0;a<Math.min(n.length,t.length);a++){const c=t[a],l=n[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:Y(),source:"user:drag",label:"拖动标签",timestamp:Date.now(),commands:i})})}on(e,t){this.graph.on(e,t),this.disposers.push(()=>this.graph.off(e,t))}}function Nt(r){function e(t){const s=r.getCellById(t);if(!s||!s.isNode())return null;const n=s,i=n.getPosition(),a=n.getSize(),c={x:i.x,y:i.y,width:a.width,height:a.height},l=r.localToGraph(c);return new DOMRect(l.x,l.y,l.width,l.height)}return{getNodeScreenRect:e}}function $e(r){return{nodeIds:r.filter(e=>e.isNode()).map(e=>e.id),edgeIds:r.filter(e=>e.isEdge()).map(e=>e.id)}}function St(r,e){const t=[...e.nodeIds.map(i=>r.getCellById(i)),...e.edgeIds.map(i=>r.getCellById(i))].filter(i=>!!i);if(t.length===0)return null;const s=r.getCellsBBox(t);if(!s)return null;const n=r.localToGraph(s);return new DOMRect(n.x,n.y,n.width,n.height)}function Ve(r,e,t){const s=r.nodeIds.filter(a=>{const c=e.nodes[a];if(!c)return!1;const l=t(c);return l.deletable!==!1&&l.deleteDisabled!==!0}),n=new Set(s),i=r.edgeIds.filter(a=>{const c=e.edges[a];return c?!n.has(c.source.nodeId)&&!n.has(c.target.nodeId):!1});return{nodeIds:s,edgeIds:i}}function Mt(r){return[...r.edgeIds.map(e=>({type:"edge.remove",edgeId:e})),...r.nodeIds.map(e=>({type:"node.remove",nodeId:e}))]}const Dt=100;function _t({graph:r,overlayManager:e,executeCommand:t,schema:s,flowModel:n,getNodeBehavior:i,idGenerator:a,defaultInsertGap:c,getContextMenuItems:l,onHighlightChange:v,resolveNodeShape:f}){const g=a??Ee;let h=[],k=[],w=null,N=!1,S=null;async function B(){if(N)return w;N=!0;try{const p=await import("@antv/x6-plugin-dnd"),d=p.Dnd??p.default;return d?(w=new d({target:r,scaled:!0,animation:!0,getDragNode:u=>u.clone(),getDropNode:u=>u.clone()}),w):null}catch{return console.warn("[flow-canvas] @antv/x6-plugin-dnd not available, add it to your dependencies"),null}}function P(){return new Promise(p=>{requestAnimationFrame(()=>requestAnimationFrame(()=>p()))})}const V=({node:p})=>{const d=p.getData?.();if(!d?._dndSessionId||d._dndSessionId!==S)return;S=null;const u=p.getPosition();r.removeNode(p.id);const{_dndSessionId:m,...E}=d,C=E.id||g("node");t({id:Y(),source:"user:drag",label:"拖入节点",timestamp:Date.now(),commands:[{type:"node.add",node:{...E,id:C,position:{x:u.x,y:u.y}}}]})};r.on("node:added",V);function U(p){const d=s.nodeTypes[p.type];return ke(p,d?.getPorts)}function L(p){return p??$e(r.getSelectedCells?.()??[])}function F(p,d,u,m,E){switch(p){case"left":return{x:d.position.x-E-m.width,y:d.position.y+(u.height-m.height)/2};case"top":return{x:d.position.x+(u.width-m.width)/2,y:d.position.y-E-m.height};case"bottom":return{x:d.position.x+(u.width-m.width)/2,y:d.position.y+u.height+E};default:return{x:d.position.x+u.width+E,y:d.position.y+(u.height-m.height)/2}}}function H(p,d,u){switch(p){case"left":return{x:-(d.width+u),y:0};case"top":return{x:0,y:-(d.height+u)};case"bottom":return{x:0,y:d.height+u};default:return{x:d.width+u,y:0}}}function M(p){switch(p){case"left":return"right";case"top":return"bottom";case"bottom":return"top";default:return"left"}}const y={zoomIn(){r.zoom(.1)},zoomOut(){r.zoom(-.1)},zoomTo(p){r.zoomTo(p)},zoomToFit(){r.zoomToFit({padding:40,maxScale:1.5})},getZoom(){return r.zoom()},centerContent(){r.centerContent()},scrollToOrigin(){r.translate(0,0)},scrollToNode(p){const d=r.getCellById(p);d&&r.centerCell(d)},getSelection(){return L()},getSelectionBounds(p){return St(r,L(p))},selectNodes(p){const d=p.map(u=>r.getCellById(u)).filter(Boolean);r.select?.(d)},selectEdges(p){const d=p.map(u=>r.getCellById(u)).filter(Boolean);r.select?.(d)},clearSelection(){const p=r.getSelectedCells?.();p?.length&&r.unselect?.(p)},deleteSelection(p){const d=L(p?.selection),u=Ve(d,n.value,i??(()=>({}))),m=Mt(u);if(m.length===0)return null;const E=t({id:Y(),source:p?.source??"user:toolbar",label:p?.label??"删除选中",timestamp:Date.now(),commands:m});return E.status==="applied"&&p?.clearSelectionAfterApply!==!1&&y.clearSelection(),E},registerDndSource(p,d){const u=async m=>{const E=await B();if(!E)return;const C=Y();S=C;const O=d(),G=f?.(O.type),I=r.createNode({width:G?.width??154,height:G?.height??54,shape:G?.shapeName??"rect",data:{...O,_dndSessionId:C}});E.start(I,m)};return p.addEventListener("mousedown",u),()=>{p.removeEventListener("mousedown",u)}},startConnection(p,d){const u=r.getCellById(p);if(!u?.isNode())return;const m=u,E=r.findViewByCell(m);if(!E)return;const C=E.findPortElem(d,"circle")??E.findPortElem(d);if(!C)return;const G=(C.matches?.("[magnet]")?C:C.querySelector?.("[magnet]"))??C,I=G.getBoundingClientRect(),T=I.left+I.width/2,b=I.top+I.height/2,A=new MouseEvent("mousedown",{clientX:T,clientY:b,button:0,buttons:1,bubbles:!0,cancelable:!0});G.dispatchEvent(A)},async exportAsImage(p){const{domToBlob:d}=await import("modern-screenshot"),u=p?.padding??20,m=p?.backgroundColor??r.options.background?.color??"#ffffff",E=r.zoom(),C=r.translate(),O=r.getContentBBox(),G=O.width/E,I=O.height/E;if(G===0||I===0)return new Blob;const T=(O.x-C.tx)/E,b=(O.y-C.ty)/E,A=Math.ceil(G+u*2),$=Math.ceil(I+u*2),j=document.createElement("div");j.style.cssText="position:fixed;left:-99999px;top:0;pointer-events:none;";const q=r.container.cloneNode(!0);q.style.width=`${A}px`,q.style.height=`${$}px`,q.style.overflow="visible";const K=q.querySelector("svg");K&&(K.setAttribute("width",String(A)),K.setAttribute("height",String($)),K.style.width=`${A}px`,K.style.height=`${$}px`),q.querySelector(".x6-graph-svg-viewport")?.setAttribute("transform",`matrix(1,0,0,1,${-T+u},${-b+u})`),j.appendChild(q),document.body.appendChild(j);try{return await P(),await d(q,{width:A,height:$,backgroundColor:m,scale:p?.scale??window.devicePixelRatio,filter:Q=>{if(Q instanceof Element){const J=Q.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(Q){return console.warn("[flow-canvas] Export failed:",Q),new Blob}finally{j.remove()}},highlightNodes(p){h=p,v?.(h,k)},highlightEdges(p){k=p,v?.(h,k)},clearHighlight(){h=[],k=[],v?.([],[])},overlay:e,getContextMenuItems(p){return l?.(p)??[]},insertNodeToRight(p,d,u){const m=n.value,E=m.nodes[p];if(!E)return{status:"invalid",envelope:{id:"",source:"user:toolbar",timestamp:Date.now(),commands:[]},error:{code:"constraint_violated",reason:`Source node "${p}" not found`,source:"api"}};const C=u?.gap??c??Dt,O=u?.direction??"right",G=s.nodeTypes[E.type],I=s.nodeTypes[d.type],T=G?.getSize(E)??{width:154,height:54},b=I?.getSize({...d,position:{x:0,y:0}})??{width:154,height:54},A=F(O,E,T,b,C),$=d.id||g("node"),j={...d,id:$,position:A},q=[{type:"node.add",node:j}],K=H(O,b,C),W={x:A.x,y:A.y,width:b.width,height:b.height};for(const[J,Z]of Object.entries(m.nodes)){if(J===p||J===$)continue;const x=s.nodeTypes[Z.type]?.getSize(Z)??{width:154,height:54},_=W.x<Z.position.x+x.width&&W.x+W.width>Z.position.x,z=W.y<Z.position.y+x.height&&W.y+W.height>Z.position.y;_&&z&&q.push({type:"node.move",nodeId:J,position:{x:Z.position.x+K.x,y:Z.position.y+K.y}})}if(u?.autoWireEdges){const J=U(E),Z=U(j),D=O,x=M(O),_=J.find(X=>X.group===D),z=Z.find(X=>X.group===x),te=Z.find(X=>X.group===D),ne=_?Object.values(m.edges).find(X=>X.source.nodeId===p&&X.source.portId===_.id):Object.values(m.edges).find(X=>X.source.nodeId===p);if(ne){const X=ne.target;q.push({type:"edge.remove",edgeId:ne.id}),q.push({type:"edge.add",edge:{id:g("edge"),source:{nodeId:p,portId:_?.id},target:{nodeId:$,portId:z?.id}}}),q.push({type:"edge.add",edge:{id:g("edge"),source:{nodeId:$,portId:te?.id},target:X}})}else q.push({type:"edge.add",edge:{id:g("edge"),source:{nodeId:p,portId:_?.id},target:{nodeId:$,portId:z?.id}}})}const Q={id:Y(),source:u?.source??"user:toolbar",label:u?.label??"插入节点",timestamp:Date.now(),commands:q};return t(Q)},onGraphEvent(p,d){return r.on(p,d),()=>r.off(p,d)},unsafeGetGraph(){return r}};return y}function At(){const r=o.ref(null),e=o.ref(!1);let t=null,s=!1;function n(g){t&&(clearTimeout(t),t=null),r.value=g}function i(g=100){s||(t&&clearTimeout(t),t=setTimeout(()=>{r.value=null,t=null},g))}function a(){s=!0,t&&(clearTimeout(t),t=null)}function c(g=100){s=!1,i(g)}function l(){t&&(clearTimeout(t),t=null)}function v(){l(),s=!1,r.value=null}function f(){t&&clearTimeout(t)}return{hoveredNodeId:r,isDraggingNode:e,enter:n,leave:i,enterOverlay:a,leaveOverlay:c,cancelLeave:l,reset:v,cleanup:f}}const Ne=10,ue=12;function Se(r,e){const t=r.getTotalLength();if(t===0)return{...e,length:0,totalLength:0};let s=r.getPointAtLength(0),n=1/0;const i=50,a=t/i;let c=0;for(let g=0;g<=i;g++){const h=g*a,k=r.getPointAtLength(h),w=(k.x-e.x)**2+(k.y-e.y)**2;w<n&&(n=w,s=k,c=h)}const l=Math.max(0,c-a),v=Math.min(t,c+a),f=(v-l)/20;for(let g=l;g<=v;g+=f){const h=r.getPointAtLength(g),k=(h.x-e.x)**2+(h.y-e.y)**2;k<n&&(n=k,s=h,c=g)}return{x:s.x,y:s.y,length:c,totalLength:t}}function Me(r,e){return r<Ne||r>e-Ne}function De(r,e,t){const s=r.querySelectorAll(".x6-edge-label");for(const n of s){const i=n.getBoundingClientRect();if(e>=i.left-ue&&e<=i.right+ue&&t>=i.top-ue&&t<=i.bottom+ue)return!0}return!1}function _e(){const r="http://www.w3.org/2000/svg",e=document.createElementNS(r,"g");e.setAttribute("class","flow-canvas-edge-delete-tool"),e.style.cursor="pointer";const t=document.createElementNS(r,"rect");t.setAttribute("width","20"),t.setAttribute("height","20"),t.setAttribute("x","-10"),t.setAttribute("y","-10"),t.setAttribute("rx","4"),t.setAttribute("ry","4"),t.setAttribute("fill","#3a84ff"),e.appendChild(t);const s=document.createElementNS(r,"text");return s.setAttribute("font-family","flow-canvas"),s.setAttribute("font-size","16"),s.setAttribute("fill","#ffffff"),s.setAttribute("text-anchor","middle"),s.setAttribute("dominant-baseline","central"),s.textContent="",e.appendChild(s),e}function Pt(r){let e=null,t=null;function s(c,l){if(i(),t=c,l.target?.closest?.(".x6-edge-label"))return;const f=r.getCellById(c);if(!f?.isEdge())return;const g=r.findViewByCell(f);if(!g)return;const h=g.container.querySelector("path");if(!h)return;const k=r.clientToLocal(l.clientX,l.clientY),w=Se(h,k);if(Me(w.length,w.totalLength)||De(g.container,l.clientX,l.clientY))return;const N=_e();N.setAttribute("transform",`translate(${w.x}, ${w.y})`),g.container.appendChild(N),e=N}function n(c){if(!t)return;if(c.target?.closest?.(".x6-edge-label")){e&&e.setAttribute("display","none");return}const v=r.getCellById(t);if(!v?.isEdge())return;const f=r.findViewByCell(v);if(!f)return;const g=f.container.querySelector("path");if(!g)return;const h=r.clientToLocal(c.clientX,c.clientY),k=Se(g,h);if(Me(k.length,k.totalLength)||De(f.container,c.clientX,c.clientY))e&&e.setAttribute("display","none");else if(e)e.removeAttribute("display"),e.setAttribute("transform",`translate(${k.x}, ${k.y})`);else{const w=_e();w.setAttribute("transform",`translate(${k.x}, ${k.y})`),f.container.appendChild(w),e=w}}function i(){e&&(e.remove(),e=null),t=null}function a(c){c===t&&(e=null,t=null)}return{show:s,move:n,remove:i,handleEdgeRemoved:a}}function Bt(r){let e=null,t=0;function s(f){const g=f?"visible":"hidden";for(const h of r.getNodes())for(const k of h.getPorts())h.setPortProp(k.id,"attrs/circle/visibility",g)}function n(f){if(!e)for(const g of f.getPorts())f.setPortProp(g.id,"attrs/circle/visibility","visible")}function i(f){if(!e)for(const g of f.getPorts())f.setPortProp(g.id,"attrs/circle/visibility","hidden")}function a(f,g){if(!f.getTargetCell())if(e=f.id,g?.size)for(const h of r.getNodes()){const k=g.has(h.id)?"hidden":"visible";for(const w of h.getPorts())h.setPortProp(w.id,"attrs/circle/visibility",k)}else s(!0)}function c(){e=null,s(!1),t=Date.now()+300}function l(f){f===e&&(e=null,s(!1))}function v(){return!e&&Date.now()>=t}return{showNodePorts:n,hideNodePorts:i,handleEdgeAdded:a,handleEdgeConnected:c,handleEdgeRemoved:l,canShowEdgeTool:v}}function Ae(r){return r==="top"||r==="right"||r==="bottom"||r==="left"}function Tt(r){const{editor:e,nodeHover:t,isSelectionModeActive:s,viewportVersion:n,getNodeBehavior:i,getInsertGap:a}=r,{isDraggingNode:c}=r,l=o.ref(null),v=o.ref(!1);let f=null,g=null,h=null;const k=o.computed(()=>({enabled:!0,portGroup:"right",...r.quickAddProp.value}));function w(){f&&(clearTimeout(f),f=null)}function N(){f&&clearTimeout(f),f=setTimeout(()=>{l.value=null,f=null},150)}function S(I){return v.value?!0:(w(),y(I)?(l.value=I,!0):(l.value=null,!1))}function B(){w(),t.enterOverlay()}function P(){N(),t.leaveOverlay()}function V(I){const T=e.schema.nodeTypes[I.type];return ke(I,T?.getPorts)}function U(I,T){const b=k.value.getPort?.(I,T);if(!b)return null;const A=typeof b=="string"?b:b.id;return T.find($=>$.id===A)??null}function L(I,T){const b=e.api.value?.overlay.getNodeScreenRect(I);if(!b)return null;switch(T){case"top":return{x:b.x+b.width/2,y:b.y};case"bottom":return{x:b.x+b.width/2,y:b.y+b.height};case"left":return{x:b.x,y:b.y+b.height/2};case"right":return{x:b.x+b.width,y:b.y+b.height/2};default:return null}}function F(I,T,b){if(!g)return L(I,b);const A=g.getCellById(I);if(A?.isNode()){const $=A,j=g.findViewByCell($),q=j?.findPortElem(T,"circle")??j?.findPortElem(T);if(q){const K=g.container.getBoundingClientRect(),W=q.getBoundingClientRect();return{x:W.left-K.left+W.width/2,y:W.top-K.top+W.height/2}}}return L(I,b)}function H(I){const T=V(I),b=U(I,T)??T.find($=>$.group===k.value.portGroup)??null;if(!b)return null;const A=F(I.id,b.id,b.group);return A?{portId:b.id,portGroup:b.group,portPosition:A}:null}function M(I){const T=H(I),b=k.value.insertDirection;if(typeof b=="function"){const A=b(I,T?{id:T.portId,group:T.portGroup}:null);if(A)return A}else if(b)return b;return T&&Ae(T.portGroup)?T.portGroup:Ae(k.value.portGroup)?k.value.portGroup:"right"}function y(I){if(!k.value.enabled||e.mode.value!=="edit")return!1;const b=e.flowModel.value.nodes[I];return!b||i(b).quickAddEnabled===!1?!1:!!H(b)}const p=o.computed(()=>{if(n.value,!k.value.enabled)return null;const I=l.value;if(!I||c.value||!e.api.value||e.mode.value!=="edit"||s.value)return null;const b=e.flowModel.value.nodes[I];if(!b)return null;const A=i(b);if(A.quickAddEnabled===!1)return null;const $=H(b);return $?{node:b,...$,behavior:A}:null});function d(I){v.value=!0,p.value&&e._emitUiEvent({type:"node.quick-add",nodeId:I,position:p.value.portPosition})}function u(){v.value=!1}function m(I){const T=e.api.value;if(!T)return;const b=e.flowModel.value.nodes[I];if(!b)return;const A=H(b);A&&T.startConnection(I,A.portId)}function E(I,T){const b=e.api.value;if(!b)return;const A=T.id||e.idGenerator("node"),$={...T,id:A},j=e.flowModel.value.nodes[I];if(!j)return;b.insertNodeToRight(I,$,{autoWireEdges:!0,direction:M(j),gap:a(),source:"user:quick-add",label:"快捷插入节点"}).status==="applied"&&e._emitUiEvent({type:"node.action.quick-insert",sourceNodeId:I,newNodeId:A}),r.closePopover()}function C(I){if(!g)return;const T=g.getCellById(I);if(!T?.isNode())return;const b=T,A=e.flowModel.value.nodes[I];if(!A)return;const $=H(A);let j=!0;i(A).hidePortForQuickAdd===!1&&(j=!1);const K=j&&!c.value&&!!$&&y(I);for(const W of b.getPorts()){const Q=K&&W.id===$?.portId?"hidden":"visible";b.setPortProp(W.id,"attrs/circle/visibility",Q)}}function O(I,T){h?.(),g=I,h=o.watch([l,c],([b],[A])=>{if(A&&A!==b){const $=I.getCellById(A);$?.isNode()&&T($)}b&&C(b)},{flush:"sync"})}o.watch(p,I=>{I||(v.value=!1)});function G(){f&&clearTimeout(f),h?.(),h=null,g=null}return{quickAddNodeId:l,quickAddPopoverOpen:v,mergedConfig:k,data:p,enter:S,leave:N,cancelLeave:w,handleOverlayEnter:B,handleOverlayLeave:P,handleOpen:d,handleClose:u,handleStartDrag:m,handleInsert:E,isActiveForNode:y,syncNodePorts:C,attachRuntime:O,cleanup:G}}const Lt=15,Rt=10;function Ot(r){const{editor:e}=r;let t=null,s=null,n=null,i=null;const a=[];let c=null;const l=o.computed(()=>({enabled:!1,bufferMargin:Lt,incomingPortGroup:"left",outgoingPortGroup:"right",...r.edgeDropProp.value}));function v(y){if(!t)return null;const p=t.getCellById(y);if(!p?.isEdge())return null;const d=t.findViewByCell(p)?.container;if(!d)return null;const u=d.querySelectorAll("path");for(const m of u)if(m.getAttribute("stroke")!=="transparent")return m;return null}function f(y){const p=v(y);p&&(p.style.stroke="#3a84ff",i=y)}function g(){if(!i)return;const y=v(i);y&&(y.style.stroke=""),i=null}function h(y,p,d){if(t){const u=t.getCellById(y);if(u?.isNode()){const m=u.getPorts().find(E=>E.group===d);if(m?.id)return m.id}}if(p.ports?.length){const u=p.ports.find(m=>m.group===d);if(u)return u.id}return d}function k(y){const p=y.getTotalLength();if(p===0)return[];const d=[];for(let m=0;m<=p;m+=Rt){const E=y.getPointAtLength(m);d.push({x:E.x,y:E.y})}const u=y.getPointAtLength(p);return d.push({x:u.x,y:u.y}),d}function w(y,p,d){if(!t)return null;const u=l.value,m=u.bufferMargin,E={x:y.x+m,y:y.y+m,width:Math.max(0,y.width-m*2),height:Math.max(0,y.height-m*2)};if(E.width<=0||E.height<=0)return null;const C=E.x+E.width,O=E.y+E.height;let G=null;const I=y.x+y.width/2,T=y.y+y.height/2;for(const b of t.getEdges()){const A=p.edges[b.id];if(!A||d&&(A.source.nodeId===d||A.target.nodeId===d)||u.isEdgeDropTarget&&!u.isEdgeDropTarget(A,p))continue;const $=t.findViewByCell(b);if(!$)continue;const j=$.findOne?.("path");if(!j||typeof j.getTotalLength!="function")continue;const q=k(j);if(!q.length)continue;let K=!1,W=1/0;for(const Q of q)if(Q.x>=E.x&&Q.x<=C&&Q.y>=E.y&&Q.y<=O){const J=Q.x-I,Z=Q.y-T,D=J*J+Z*Z;D<W&&(W=D),K=!0}K&&(!G||W<G.distSq)&&(G={edgeId:b.id,edge:A,distSq:W})}return G?{edgeId:G.edgeId,edge:G.edge}:null}function N(y,p){if(!l.value.enabled)return;const u=e.flowModel.value,m=w(y,u,p);m?s!==m.edgeId&&(g(),s=m.edgeId,f(m.edgeId)):s&&(g(),s=null)}let S=!0;function B({node:y}){if(s=null,!l.value.enabled)return;const p=e.flowModel.value,d=p.nodes[y.id];if(!d){S=!1;return}const u=l.value;S=!u.isNodeInsertable||u.isNodeInsertable(d,p)}function P({node:y}){!l.value.enabled||!S||n===null&&(n=requestAnimationFrame(()=>{if(n=null,!t)return;const p=y.getPosition(),d=y.getSize();N({x:p.x,y:p.y,width:d.width,height:d.height},y.id)}))}function V(){n!==null&&(cancelAnimationFrame(n),n=null),g(),S=!0}function U(){if(!t)return;let y=!1;c=()=>{if(!l.value.enabled)return;const p=document.querySelector(".x6-widget-dnd");if(!p){y&&(y=!1,g(),s=null);return}y=!0,n===null&&(n=requestAnimationFrame(()=>{if(n=null,!t)return;const d=p.getBoundingClientRect(),u=t.clientToLocal(d.left,d.top),m=t.clientToLocal(d.right,d.bottom),E={x:u.x,y:u.y,width:m.x-u.x,height:m.y-u.y};N(E)}))},document.addEventListener("mousemove",c),a.push(()=>{c&&(document.removeEventListener("mousemove",c),c=null)})}function L(){g(),s=null,n!==null&&(cancelAnimationFrame(n),n=null)}function F(y){if(!s||y.source!=="user:drag")return y;const p=s;s=null,g();const d=e.flowModel.value,u=d.edges[p];if(!u)return y;const m=y.commands.find($=>$.type==="node.add"||$.type==="node.move");if(!m)return y;const E=m.type==="node.add"?m.node.id:m.nodeId,C=m.type==="node.add"?m.node:d.nodes[m.nodeId];if(!C)return y;const O=l.value;if(O.isNodeInsertable&&!O.isNodeInsertable(C,d))return y;const G=h(E,C,O.incomingPortGroup),I=h(E,C,O.outgoingPortGroup),T=e.idGenerator("edge"),b=e.idGenerator("edge"),A=[{type:"edge.remove",edgeId:p},{type:"edge.add",edge:{id:T,type:u.type,source:{nodeId:u.source.nodeId,portId:u.source.portId},target:{nodeId:E,portId:G}}},{type:"edge.add",edge:{id:b,type:u.type,source:{nodeId:E,portId:I},target:{nodeId:u.target.nodeId,portId:u.target.portId}}}];return{...y,source:"user:edge-drop",commands:[...y.commands,...A]}}function H(y){t=y;const p=(d,u)=>{y.on(d,u),a.push(()=>y.off(d,u))};p("node:move",B),p("node:change:position",P),p("node:moved",V),U()}function M(){L();for(const y of a)y();a.length=0,t=null,S=!0}return{attachRuntime:H,tryExpandForEdgeDrop:F,cleanup:M}}function $t(r){function e(n){return{id:r.idGenerator("node"),type:n.type,label:n.label,ports:n.ports?JSON.parse(JSON.stringify(n.ports)):void 0,payload:n.payload?JSON.parse(JSON.stringify(n.payload)):void 0,extensions:n.extensions?JSON.parse(JSON.stringify(n.extensions)):void 0}}function t(n,i,a){const c=r.api.value;switch(n){case"delete":return r.executeCommand({id:Y(),source:"user:toolbar",label:"删除节点",timestamp:Date.now(),commands:[{type:"node.remove",nodeId:i}]}),r._emitUiEvent({type:"node.action.delete",nodeId:i}),!0;case"copy":{if(!c)break;const l=r.flowModel.value.nodes[i];if(!l)break;const v=e(l);c.insertNodeToRight(i,v,{autoWireEdges:!1,gap:a,label:"复制节点"}),r._emitUiEvent({type:"node.action.copy",sourceNodeId:i,newNodeId:v.id});break}case"copy-insert":{if(!c)break;const l=r.flowModel.value.nodes[i];if(!l)break;const v=e(l);c.insertNodeToRight(i,v,{autoWireEdges:!0,gap:a,label:"复制并插入节点"}),r._emitUiEvent({type:"node.action.copy-insert",sourceNodeId:i,newNodeId:v.id});break}case"disconnect":{const l=r.flowModel.value,v=Object.entries(l.edges).filter(([,f])=>{const g=f;return g.source.nodeId===i||g.target.nodeId===i}).map(([f])=>f);if(v.length===0)break;r.executeCommand({id:Y(),source:"user:toolbar",label:"断开连线",timestamp:Date.now(),commands:v.map(f=>({type:"edge.remove",edgeId:f}))}),r._emitUiEvent({type:"node.action.disconnect",nodeId:i,edgeIds:v});break}case"debug":{r._emitUiEvent({type:"node.action.debug",nodeId:i});break}}return!1}function s(n){r.api.value?.deleteSelection({selection:n,source:"user:toolbar",label:"批量删除选中"})}return{handleNodeAction:t,deleteSelection:s}}function Vt(){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(r,e){const t=e.defaultEdgeType??"default",s=e.edgeTypes?.[t],n={zIndex:-1,attrs:{line:{stroke:"#abb5cc",strokeWidth:2,targetMarker:{name:"block",width:8,height:8}}}};s?.router&&(n.router=typeof s.router=="string"?{name:s.router}:s.router),s?.connector&&(n.connector=typeof s.connector=="string"?{name:s.connector}:s.connector),s?.x6EdgeConfig&&Object.assign(n,s.x6EdgeConfig);const i=n.attrs??{},a=i.line??{};return n.attrs={...i,line:{...a,targetMarker:Vt()}},r.createEdge(n)}const Ht={class:"flow-canvas-node-actions__bar"},Ft=o.defineComponent({__name:"node-actions-toolbar",props:{node:{},position:{},config:{},behavior:{},actionsOffset:{}},emits:["action"],setup(r,{emit:e}){const t=r,s=o.computed(()=>{const g=t.actionsOffset?.x??0,h=t.actionsOffset?.y??0,k=g!==0||h!==0;return{left:`${t.position.x}px`,top:`${t.position.y}px`,transform:k?`translate(${g}px, ${h}px)`:"translateX(-100%)"}}),n=e,i=o.computed(()=>({debug:{visible:t.config.showDebug&&t.behavior.debuggable!==!1,disabled:t.behavior.debugDisabled===!0},delete:{visible:t.config.showDelete&&t.behavior.deletable!==!1,disabled:t.behavior.deleteDisabled===!0},copy:{visible:t.config.showCopy&&t.behavior.copyable!==!1,disabled:t.behavior.copyDisabled===!0},copyInsert:{visible:t.config.showCopyInsert&&t.behavior.copyable!==!1,disabled:t.behavior.copyInsertDisabled===!0},disconnect:{visible:t.config.showDisconnect&&t.behavior.disconnectable!==!1,disabled:t.behavior.disconnectDisabled===!0}})),a=o.computed(()=>i.value.copy.visible||i.value.copyInsert.visible||i.value.disconnect.visible),c=o.ref(!1);let l=null;function v(){l&&(clearTimeout(l),l=null),c.value=!0}function f(){l=setTimeout(()=>{c.value=!1,l=null},100)}return o.onBeforeUnmount(()=>{l&&clearTimeout(l)}),(g,h)=>(o.openBlock(),o.createElementBlock("div",{class:"flow-canvas-node-actions",style:o.normalizeStyle(s.value)},[o.createElementVNode("div",Ht,[i.value.debug.visible?(o.openBlock(),o.createElementBlock("i",{key:0,class:o.normalizeClass(["flow-canvas-icon canvas-debug flow-canvas-node-actions__icon",{"is-disabled":i.value.debug.disabled}]),onClick:h[0]||(h[0]=k=>!i.value.debug.disabled&&n("action","debug",r.node.id))},null,2)):o.createCommentVNode("",!0),i.value.delete.visible?(o.openBlock(),o.createElementBlock("i",{key:1,class:o.normalizeClass(["flow-canvas-icon canvas-shanchu flow-canvas-node-actions__icon",{"is-disabled":i.value.delete.disabled}]),onClick:h[1]||(h[1]=k=>!i.value.delete.disabled&&n("action","delete",r.node.id))},null,2)):o.createCommentVNode("",!0),a.value?(o.openBlock(),o.createElementBlock("div",{key:2,class:"flow-canvas-node-actions__more-wrapper",onMouseenter:v,onMouseleave:f},[...h[5]||(h[5]=[o.createElementVNode("i",{class:"flow-canvas-icon canvas-gengduo flow-canvas-node-actions__icon"},null,-1)])],32)):o.createCommentVNode("",!0)]),o.createVNode(o.Transition,{name:"flow-canvas-fade"},{default:o.withCtx(()=>[c.value&&a.value?(o.openBlock(),o.createElementBlock("div",{key:0,class:"flow-canvas-node-actions__dropdown",onMouseenter:v,onMouseleave:f},[i.value.copy.visible?(o.openBlock(),o.createElementBlock("div",{key:0,class:o.normalizeClass(["flow-canvas-node-actions__dropdown-item",{"is-disabled":i.value.copy.disabled}]),onClick:h[2]||(h[2]=k=>!i.value.copy.disabled&&n("action","copy",r.node.id))},[...h[6]||(h[6]=[o.createElementVNode("i",{class:"flow-canvas-icon canvas-copy-fuzhi-2"},null,-1),o.createElementVNode("span",null,"复制",-1)])],2)):o.createCommentVNode("",!0),i.value.copyInsert.visible?(o.openBlock(),o.createElementBlock("div",{key:1,class:o.normalizeClass(["flow-canvas-node-actions__dropdown-item",{"is-disabled":i.value.copyInsert.disabled}]),onClick:h[3]||(h[3]=k=>!i.value.copyInsert.disabled&&n("action","copy-insert",r.node.id))},[...h[7]||(h[7]=[o.createElementVNode("i",{class:"flow-canvas-icon canvas-fuzhibingcharu"},null,-1),o.createElementVNode("span",null,"复制并插入",-1)])],2)):o.createCommentVNode("",!0),i.value.disconnect.visible?(o.openBlock(),o.createElementBlock("div",{key:2,class:o.normalizeClass(["flow-canvas-node-actions__dropdown-item",{"is-disabled":i.value.disconnect.disabled}]),onClick:h[4]||(h[4]=k=>!i.value.disconnect.disabled&&n("action","disconnect",r.node.id))},[...h[8]||(h[8]=[o.createElementVNode("i",{class:"flow-canvas-icon canvas-unlock-jiebang"},null,-1),o.createElementVNode("span",null,"断开连线",-1)])],2)):o.createCommentVNode("",!0)],32)):o.createCommentVNode("",!0)]),_:1})],4))}}),re=(r,e)=>{const t=r.__vccOpts||r;for(const[s,n]of e)t[s]=n;return t},ze=re(Ft,[["__scopeId","data-v-3b39dab5"]]),qt={key:0,class:"flow-canvas-quick-add__tooltip"},Gt=5,Ut=o.defineComponent({__name:"node-quick-add-popover",props:{node:{},portPosition:{}},emits:["open","close","start-drag","mouseenter","mouseleave"],setup(r,{expose:e,emit:t}){const s=r,n=t,i=o.ref(),a=o.ref(),c=o.ref(!1),l=o.ref(!1);let v=null,f=!1,g=null;function h(H){H.preventDefault(),H.stopPropagation(),v={x:H.clientX,y:H.clientY},f=!1,document.addEventListener("mousemove",k),document.addEventListener("mouseup",w)}function k(H){if(!v)return;const M=H.clientX-v.x,y=H.clientY-v.y;Math.sqrt(M*M+y*y)>=Gt&&(f=!0,N(),n("start-drag",s.node.id))}function w(){N(),f||S(),v=null,f=!1}function N(){document.removeEventListener("mousemove",k),document.removeEventListener("mouseup",w)}function S(){l.value?P():B()}function B(){l.value=!0,n("open",s.node.id),requestAnimationFrame(()=>{document.addEventListener("mousedown",V)})}function P(){l.value=!1,n("close"),document.removeEventListener("mousedown",V)}function V(H){const M=H.target;i.value?.contains(M)||a.value?.contains(M)||P()}function U(){l.value||n("mouseleave")}function L(){g&&(clearTimeout(g),g=null),n("mouseenter")}function F(){g=setTimeout(()=>{P(),n("mouseleave"),g=null},150)}return o.onBeforeUnmount(()=>{N(),g&&clearTimeout(g),document.removeEventListener("mousedown",V)}),e({closePopover:P}),(H,M)=>(o.openBlock(),o.createElementBlock("div",{class:"flow-canvas-quick-add",style:o.normalizeStyle({left:`${r.portPosition.x}px`,top:`${r.portPosition.y}px`}),onMouseenter:M[2]||(M[2]=y=>n("mouseenter")),onMouseleave:U,onClick:M[3]||(M[3]=o.withModifiers(()=>{},["stop"]))},[o.createElementVNode("div",{ref_key:"btnRef",ref:i,class:o.normalizeClass(["flow-canvas-quick-add__btn",{"is-hovered":c.value,"is-active":l.value}]),onMouseenter:M[0]||(M[0]=y=>c.value=!0),onMouseleave:M[1]||(M[1]=y=>c.value=!1),onMousedown:h},[...M[4]||(M[4]=[o.createElementVNode("i",{class:"flow-canvas-icon canvas-zoom-add"},null,-1)])],34),c.value&&!l.value?(o.openBlock(),o.createElementBlock("div",qt,[...M[5]||(M[5]=[o.createElementVNode("div",null,[o.createElementVNode("b",null,"点击"),o.createTextVNode(" 添加节点")],-1),o.createElementVNode("div",null,[o.createElementVNode("b",null,"拖拽"),o.createTextVNode(" 连接节点")],-1)])])):o.createCommentVNode("",!0),o.createVNode(o.Transition,{name:"flow-canvas-fade"},{default:o.withCtx(()=>[l.value?(o.openBlock(),o.createElementBlock("div",{key:0,ref_key:"popoverRef",ref:a,class:"flow-canvas-quick-add__popover",onMouseenter:L,onMouseleave:F},[o.renderSlot(H.$slots,"default",{},()=>[M[6]||(M[6]=o.createElementVNode("div",{class:"flow-canvas-quick-add__default-content"},"节点快捷操作面板",-1))],!0)],544)):o.createCommentVNode("",!0)]),_:3})],36))}}),He=re(Ut,[["__scopeId","data-v-336cc3b4"]]),jt={class:"flow-canvas-selection-actions__bar"},Wt=o.defineComponent({__name:"selection-actions-toolbar",props:{position:{},canDelete:{type:Boolean}},emits:["action"],setup(r,{emit:e}){const t=r,s=e,n=o.computed(()=>({left:`${t.position.x}px`,top:`${t.position.y}px`,transform:"translateX(-100%)"}));return(i,a)=>(o.openBlock(),o.createElementBlock("div",{class:"flow-canvas-selection-actions",style:o.normalizeStyle(n.value)},[o.createElementVNode("div",jt,[o.createElementVNode("i",{class:o.normalizeClass(["flow-canvas-icon canvas-shanchu flow-canvas-selection-actions__icon",{"is-disabled":!r.canDelete}]),onClick:a[0]||(a[0]=c=>r.canDelete&&s("action","delete"))},null,2)])],4))}}),Xt=re(Wt,[["__scopeId","data-v-25eb8b79"]]),Yt={class:"flow-canvas-runtime-core__overlay"},Kt=o.defineComponent({__name:"canvas-runtime-core",props:{editor:{},graphOptions:{},nodeActions:{},quickAdd:{},edgeDrop:{},getConnectionExcludedNodeIds:{type:Function}},emits:["ui-event"],setup(r,{emit:e}){const t=r,s=e,n=o.ref(),i=o.ref();let a,c,l,v,f=null,g=null,h=null,k=null;const w=At(),{hoveredNodeId:N,isDraggingNode:S}=w,B=w.enterOverlay,P=()=>w.leaveOverlay(),V=o.ref(0),U=o.ref({nodeIds:[],edgeIds:[]});function L(D){const x=t.editor.api.value;return x?t.editor.schema.nodeTypes[D.type]?.getBehavior?.(D,{api:x,flowModel:t.editor.flowModel.value,history:t.editor.history,mode:t.editor.mode.value})??{}:{}}const F=o.computed(()=>t.editor.mode.value==="edit"&&t.editor.selectionMode.value),H=o.computed(()=>({showDebug:!1,showDelete:!0,showCopy:!0,showCopyInsert:!0,showDisconnect:!0,insertGap:100,...t.nodeActions})),M=o.computed(()=>{if(V.value,!t.editor.api.value)return[];const D=t.editor.flowModel.value,x=t.editor.api.value.overlay,_=[];for(const[z,te]of Object.entries(D.nodes)){const ne=t.editor._pluginManager.collectNodeDecorations(te);if(!ne?.badge)continue;const X=x.getNodeScreenRect(z);X&&_.push({nodeId:z,x:X.x+X.width-4,y:X.y-8,badge:ne.badge})}return _}),y=o.computed(()=>{V.value;const D=N.value;if(!D||S.value||!t.editor.api.value||t.editor.mode.value!=="edit"||F.value)return null;const _=t.editor.flowModel.value.nodes[D];if(!_)return null;const z=t.editor.api.value.overlay.getNodeScreenRect(D);if(!z)return null;const te=L(_);return te.showActions===!1?null:{node:_,position:{x:z.x+z.width,y:z.y+z.height+4},behavior:te}}),p=o.computed(()=>{if(V.value,!t.editor.api.value||t.editor.mode.value!=="edit")return null;const D=U.value;if(D.nodeIds.length+D.edgeIds.length<=1)return null;const x=t.editor.api.value.getSelectionBounds(D);if(!x)return null;const _=Ve(D,t.editor.flowModel.value,L);return{position:{x:x.x+x.width,y:x.y+x.height+4},canDelete:_.nodeIds.length>0||_.edgeIds.length>0}}),d=o.ref(),u=Tt({editor:t.editor,quickAddProp:o.computed(()=>t.quickAdd),isDraggingNode:S,nodeHover:w,isSelectionModeActive:F,viewportVersion:V,getNodeBehavior:L,getInsertGap:()=>H.value.insertGap,closePopover:()=>d.value?.closePopover()}),m=u.data,E=u.handleOpen,C=u.handleClose,O=u.handleStartDrag,G=u.handleOverlayEnter,I=u.handleOverlayLeave,T=u.handleInsert,b=Ot({editor:t.editor,edgeDropProp:o.computed(()=>t.edgeDrop)}),A=$t(t.editor);function $(D,x){A.handleNodeAction(D,x,H.value.insertGap)&&(N.value=null)}function j(D){D==="delete"&&A.deleteSelection(U.value)}function q(D){if(t.editor.mode.value!=="edit")return;t.editor._pluginManager.dispatchKeyboardShortcut(D)&&(D.preventDefault(),D.stopPropagation())}function K(D,x){const _=a,z=te=>{const ne=_.isRubberbandEnabled?.()??!1;ne&&_.disableRubberband?.(),te?a.enablePanning():a.disablePanning(),ne&&_.enableRubberband?.()};D&&x?(_.enableSelection?.(),w.reset(),u.quickAddNodeId.value=null,u.quickAddPopoverOpen.value=!1,f?.remove(),z(!1),_.enableRubberband?.()):(_.disableRubberband?.(),z(!0),_.disableSelection?.(),_.cleanSelection?.())}function W(D){a.on("node:move",({node:x})=>{S.value=!0;const _=t.editor.flowModel.value.nodes[x.id];_&&L(_).bringToFrontOnDrag===!1||x.toFront?.()}),a.on("node:moved",()=>{S.value=!1}),a.on("node:mouseenter",({node:x})=>{if(F.value){N.value=null,u.quickAddNodeId.value=null,D.hideNodePorts(x);return}w.enter(x.id);const _=t.editor.flowModel.value.nodes[x.id];if(_&&L(_).showPorts===!1){u.mergedConfig.value.enabled&&u.enter(x.id);return}u.mergedConfig.value.enabled&&u.enter(x.id)||D.showNodePorts(x)}),a.on("node:mouseleave",({node:x})=>{if(F.value){D.hideNodePorts(x);return}const _=t.editor.flowModel.value.nodes[x.id];let z=100;_&&L(_).actionsOffset&&(z=300),w.leave(z),u.mergedConfig.value.enabled?u.quickAddNodeId.value===x.id&&!u.quickAddPopoverOpen.value?u.leave():u.quickAddNodeId.value!==x.id&&D.hideNodePorts(x):D.hideNodePorts(x)})}function Q(D){a.on("edge:added",({edge:x})=>{let _;if(t.getConnectionExcludedNodeIds&&!x.getTargetCell()){const z=x.getSourceCell();if(z){const te=t.getConnectionExcludedNodeIds(z.id);_=te instanceof Set?te:new Set(te)}}D.handleEdgeAdded(x,_)}),a.on("edge:connected",()=>{D.handleEdgeConnected()}),a.on("edge:removed",({edge:x})=>{D.handleEdgeRemoved(x.id),f.handleEdgeRemoved(x.id)}),a.on("edge:mouseenter",({edge:x,e:_})=>{const z=c.getHoveredEdgeId();c.setHoveredEdge(x.id),z&&z!==x.id&&c.refreshSingleEdgeStyle(z),c.refreshSingleEdgeStyle(x.id),t.editor.mode.value==="edit"&&!F.value&&D.canShowEdgeTool()&&f.show(x.id,_)}),a.on("edge:mouseleave",({edge:x})=>{c.setHoveredEdge(null),c.refreshSingleEdgeStyle(x.id),f.remove()}),a.on("edge:click",({edge:x,e:_})=>{_.target?.closest?.(".flow-canvas-edge-delete-tool")&&t.editor.mode.value==="edit"&&(f.remove(),t.editor.executeCommand({id:Y(),source:"user:toolbar",label:"删除连线",timestamp:Date.now(),commands:[{type:"edge.remove",edgeId:x.id}]}))}),g=x=>f.move(x),a.container.addEventListener("mousemove",g)}function J(){h=D=>{if(!N.value&&!u.quickAddNodeId.value)return;const x=D.target;if(x?.closest?.(".x6-node")||x?.closest?.(".flow-canvas-node-actions")||x?.closest?.(".flow-canvas-quick-add")){w.cancelLeave(),u.cancelLeave();return}w.leave(180),u.quickAddPopoverOpen.value||u.leave()},n.value?.addEventListener("mousemove",h),k=()=>{w.reset(),u.quickAddPopoverOpen.value||(u.quickAddNodeId.value=null)},n.value?.addEventListener("mouseleave",k),n.value?.addEventListener("keydown",q)}function Z(){o.watch(()=>t.editor.flowModel.value,D=>c.syncFlowModel(D)),o.watch([()=>t.editor.mode.value,()=>t.editor.selectionMode.value],([D,x])=>{K(D==="edit",x)},{immediate:!0})}return o.onMounted(()=>{if(!i.value)return;const D=new Set(["model","container"]),x={};if(t.graphOptions)for(const[R,ee]of Object.entries(t.graphOptions)){if(D.has(R)){console.warn(`[flow-canvas] graphOptions.${R} is managed by the engine and will be ignored`);continue}x[R]=ee}a=new Ze.Graph({container:i.value,autoResize:!0,background:{color:"#edf2fc"},grid:{visible:!0,size:20,type:"dot"},highlighting:{magnetAdsorbed:{name:"className",args:{className:"flow-canvas-magnet-adsorbed"}}},panning:{enabled:!0},mousewheel:{enabled:!0,modifiers:["ctrl","meta"]},interacting:{nodeMovable(R){return R.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)}},...x}),l=new xt,c=new Ct(a,t.editor.schema,l,R=>t.editor._pluginManager.collectNodeDecorations(R),R=>t.editor._pluginManager.collectEdgeDecorations(R),()=>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 _=Nt(a),z=_t({graph:a,overlayManager:_,executeCommand:R=>t.editor.executeCommand(b.tryExpandForEdgeDrop(R)),schema:t.editor.schema,flowModel:t.editor.flowModel,getNodeBehavior:L,idGenerator:t.editor.idGenerator,defaultInsertGap:t.nodeActions?.insertGap,getContextMenuItems:R=>t.editor._pluginManager.collectContextMenuItems(R),onHighlightChange:(R,ee)=>{c.setHighlightedNodes(R);const se=c.setHighlightedEdges(ee);c.refreshNodeHighlights();const ie=new Set(ee);for(const ae of se)ie.has(ae)||c.refreshSingleEdgeStyle(ae);for(const ae of ie)se.has(ae)||c.refreshSingleEdgeStyle(ae)},resolveNodeShape:R=>{const ee=t.editor.schema.nodeTypes[R];if(!ee)return null;const se=l.registerNodeType(R,ee.component),ie=ee.getSize({id:"",type:R,position:{x:0,y:0}});return{shapeName:se,width:ie.width,height:ie.height}}});t.editor.api.value=z;const te={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:z,overlay:_,graph:a};t.editor._pluginManager.attachRuntime(te);const ne=t.editor._pluginManager.collectExtendedApi();Object.assign(t.editor.extendedApi,ne),t.editor._emitUiEvent=R=>{t.editor._pluginManager.dispatchUiEvent(R),s("ui-event",R)},v=new It(a,R=>{(R.type==="node.click"||R.type==="node.dblclick"||R.type==="node.contextmenu")&&w.enter(R.nodeId),t.editor._emitUiEvent(R)},R=>{if(c.isSyncing)return;const ee=b.tryExpandForEdgeDrop(R);if(t.editor.executeCommand(ee).status!=="applied"){for(const ie of ee.commands)if(ie.type==="edge.add"){const ae=a.getCellById(ie.edge.id);ae&&a.removeCell(ae)}}},t.editor.flowModel,t.editor.idGenerator),f=Pt(a);const X=Bt(a);u.attachRuntime(a,R=>X.hideNodePorts(R)),b.attachRuntime(a),W(X),Q(X);let ve=new Set;a.on("selection:changed",()=>{const R=$e(a.getSelectedCells?.()??[]);U.value=R,t.editor._pluginManager.dispatchSelectionChange(R),s("ui-event",{type:"selection.change",nodeIds:R.nodeIds,edgeIds:R.edgeIds}),c.refreshNodeHighlights();const ee=new Set(R.edgeIds);for(const se of ve)ee.has(se)||c.refreshSingleEdgeStyle(se);for(const se of ee)ve.has(se)||c.refreshSingleEdgeStyle(se);ve=ee});const me=()=>{V.value++};a.on("translate",me),a.on("scale",me),a.on("resize",me),J(),c.syncFlowModel(t.editor.flowModel.value),Z()}),o.onBeforeUnmount(()=>{w.cleanup(),u.cleanup(),b.cleanup(),f?.remove(),g&&a?.container?.removeEventListener("mousemove",g),h&&n.value?.removeEventListener("mousemove",h),k&&n.value?.removeEventListener("mouseleave",k),n.value?.removeEventListener("keydown",q),t.editor._pluginManager.detachRuntime(),t.editor.api.value=null;for(const D of Object.keys(t.editor.extendedApi))delete t.editor.extendedApi[D];v?.dispose(),c?.dispose(),l?.dispose(),a?.dispose()}),(D,x)=>(o.openBlock(),o.createElementBlock("div",{ref_key:"rootRef",ref:n,class:o.normalizeClass(["flow-canvas-runtime-core",{"flow-canvas-runtime-core--selection-mode":F.value}]),tabindex:"0"},[o.createElementVNode("div",{ref_key:"containerRef",ref:i,class:"flow-canvas-runtime-core__graph"},null,512),o.createElementVNode("div",Yt,[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(M.value,_=>(o.openBlock(),o.createElementBlock("div",{key:`badge-${_.nodeId}`,class:"flow-canvas-runtime-core__badge",style:o.normalizeStyle({left:`${_.x}px`,top:`${_.y}px`,backgroundColor:_.badge.color})},o.toDisplayString(_.badge.text),5))),128)),o.unref(m)?(o.openBlock(),o.createBlock(He,{key:0,ref_key:"quickAddPopoverRef",ref:d,node:o.unref(m).node,"port-position":o.unref(m).portPosition,onOpen:o.unref(E),onClose:o.unref(C),onStartDrag:o.unref(O),onMouseenter:o.unref(G),onMouseleave:o.unref(I)},{default:o.withCtx(()=>[o.renderSlot(D.$slots,"quick-add-panel",{node:o.unref(m).node,api:r.editor.api.value,insertNodeToRight:_=>o.unref(T)(o.unref(m).node.id,_),closePopover:()=>d.value?.closePopover()},void 0,!0)]),_:3},8,["node","port-position","onOpen","onClose","onStartDrag","onMouseenter","onMouseleave"])):o.createCommentVNode("",!0),y.value?(o.openBlock(),o.createBlock(ze,{key:1,node:y.value.node,position:y.value.position,config:H.value,behavior:y.value.behavior,"actions-offset":y.value.behavior.actionsOffset,onAction:$,onMouseenter:o.unref(B),onMouseleave:P},null,8,["node","position","config","behavior","actions-offset","onMouseenter"])):o.createCommentVNode("",!0),p.value?(o.openBlock(),o.createBlock(Xt,{key:2,position:p.value.position,"can-delete":p.value.canDelete,onAction:j},null,8,["position","can-delete"])):o.createCommentVNode("",!0)])],2))}}),Qt=re(Kt,[["__scopeId","data-v-5a3959fd"]]),Zt={class:"flow-canvas-node-palette"},Jt=["data-node-type"],eo={class:"flow-canvas-node-palette__item-label"},to=o.defineComponent({__name:"canvas-node-palette",props:{editor:{},items:{}},setup(r){const e=r,t=o.ref(),s=o.computed(()=>e.items?e.items:Object.keys(e.editor.schema.nodeTypes).map(n=>({type:n,label:n.charAt(0).toUpperCase()+n.slice(1)})));return o.watch([()=>e.editor.api.value,s,t],([n,i,a],c,l)=>{if(!n||!a)return;const v=[];for(const f of i){const g=a.querySelector(`[data-node-type="${f.type}"]`);if(!g)continue;const h=n.registerDndSource(g,()=>({id:Y(),type:f.type,label:f.label,position:{x:0,y:0}}));v.push(h)}l(()=>{for(const f of v)f()})},{flush:"post"}),(n,i)=>(o.openBlock(),o.createElementBlock("div",Zt,[o.createElementVNode("div",{ref_key:"listRef",ref:t,class:"flow-canvas-node-palette__list"},[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(s.value,a=>(o.openBlock(),o.createElementBlock("div",{key:a.type,class:"flow-canvas-node-palette__item","data-node-type":a.type},[a.icon?(o.openBlock(),o.createElementBlock("i",{key:0,class:o.normalizeClass([a.icon,"flow-canvas-node-palette__item-icon"])},null,2)):o.createCommentVNode("",!0),o.createElementVNode("span",eo,o.toDisplayString(a.label),1)],8,Jt))),128))],512)]))}}),Fe=re(to,[["__scopeId","data-v-300314b7"]]),oo={class:"flow-canvas-layout"},no={class:"flow-canvas-layout__main"},so={class:"flow-canvas-layout__content"},ro={key:0,class:"flow-canvas-layout__footer"},io=o.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(r){return(e,t)=>(o.openBlock(),o.createElementBlock("div",oo,[!r.hideSidebar&&(e.$slots.sidebar||r.editor)?(o.openBlock(),o.createElementBlock("aside",{key:0,class:o.normalizeClass(["flow-canvas-layout__sidebar",{"is-collapsed":r.sidebarCollapsed}]),style:o.normalizeStyle({width:r.sidebarCollapsed?"0px":`${r.sidebarWidth}px`})},[o.renderSlot(e.$slots,"sidebar",{},()=>[r.editor?(o.openBlock(),o.createBlock(Fe,{key:0,editor:r.editor,items:r.paletteItems},null,8,["editor","items"])):o.createCommentVNode("",!0)],!0)],6)):o.createCommentVNode("",!0),o.createElementVNode("div",no,[o.createElementVNode("div",so,[o.renderSlot(e.$slots,"default",{},void 0,!0)]),!r.hideFooter&&e.$slots.footer?(o.openBlock(),o.createElementBlock("div",ro,[o.renderSlot(e.$slots,"footer",{},void 0,!0)])):o.createCommentVNode("",!0)])]))}}),ao=re(io,[["__scopeId","data-v-26f35b6b"]]),lo=["undo","redo"];function qe(r){const e=new Set(r?.include),t=new Set(lo.filter(l=>!e.has(l))),s=[{id:"undo",type:"undo",group:"history",icon:"flow-canvas-icon canvas-undo",description:"撤销",order:10},{id:"redo",type:"redo",group:"history",icon:"flow-canvas-icon canvas-redo",description:"重做",order:11}],n=[{id:"select",type:"select",group:"tools",icon:"flow-canvas-icon canvas-kuangxuan",description:"框选",order:20},{id:"auto-layout",type:"auto-layout",group:"tools",icon:"flow-canvas-icon canvas-beautify",description:"自动排版",order:21},{id:"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[...[...s,...n].filter(l=>!t.has(l.type)),...i,...a]}const co={class:"flow-canvas-toolbar"},uo={key:0,class:"flow-canvas-toolbar__separator"},fo={class:"flow-canvas-toolbar__group"},po={key:0,class:"flow-canvas-toolbar__zoom-display"},go=["data-toolbar-id","data-toolbar-type","disabled","onClick","onMouseenter"],ho=["textContent"],vo=o.defineComponent({__name:"canvas-toolbar",props:{items:{},exclude:{},editor:{}},setup(r){const e=new Set(["undo","redo","select","auto-layout","search","minimap","export"]),t=new Set(["select","search","minimap"]);function s(d){return d.id.startsWith("plugin:")||d.type==="custom"}function n(d){return d!=="custom"&&t.has(d)}const i=r,a=o.computed(()=>{if(i.items)return i.items;const d=qe(),u=i.editor.toolbarItems.value,m=new Set(i.exclude??[]),E=new Map;for(const C of d)E.set(C.id,C);for(const C of u){const O=E.get(C.id);O?E.set(C.id,{...O,...C,order:O.order,group:O.group}):s(C)&&E.set(C.id,C)}return[...E.values()].filter(C=>C.type==="custom"||!e.has(C.type)?!0:!m.has(C.type)).sort((C,O)=>(C.order??0)-(O.order??0))}),c=o.ref(1),l=o.ref(null),v=o.ref(null),f=o.ref(!1);let g=null;o.watch(()=>i.editor.api.value,d=>{g?.(),g=null,d&&(c.value=d.getZoom(),g=d.onGraphEvent("scale",()=>{c.value=d.getZoom()}))},{immediate:!0});const h=o.reactive({visible:!1,text:"",x:0,y:0});function k(d,u){if(!u.description)return;const E=d.currentTarget.getBoundingClientRect();h.text=u.description,h.visible=!0,o.nextTick(()=>{const C=l.value?.offsetWidth??0,O=l.value?.offsetHeight??0;h.x=E.left+E.width/2-C/2,h.y=E.top-O-6})}function w(){h.visible=!1,l.value=null}o.onScopeDispose(()=>{g?.()});const N=o.computed(()=>`${Math.round(c.value*100)}%`),S=o.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 B(d){return d.visible===!1?!1:typeof d.visible=="function"?S.value?d.visible(S.value):!1:!0}function P(d){return typeof d.active=="function"?S.value?d.active(S.value):!1:d.active!==void 0?d.active:d.type==="select"?i.editor.selectionMode.value:!1}const V=o.computed(()=>{const d=y.value.filter(m=>n(m.type)&&P(m));if(d.length===0)return null;const u=v.value;return u&&d.some(m=>m.type===u)?u:d[0]?.type??null});function U(d){return n(d.type)?V.value===d.type:P(d)}function L(d){return!S.value||d.disabled===!0?!0:typeof d.disabled=="function"?d.disabled(S.value):d.type==="undo"?!i.editor.history.canUndo.value:d.type==="redo"?!i.editor.history.canRedo.value:d.type==="export"?f.value:!1}function F(d){if(!(!S.value||!n(d.type)||!P(d))){if(d.type==="select"){i.editor.setSelectionMode(!1);return}d.onClick?.(S.value)}}function H(d){if(n(d.type))for(const u of y.value)!n(u.type)||u.id===d.id||F(u)}function M(d){if(!S.value||L(d))return;if(n(d.type)&&(v.value=d.type,H(d)),d.onClick){d.onClick(S.value);return}const{api:u}=S.value;switch(d.type){case"undo":i.editor.history.undo();break;case"redo":i.editor.history.redo();break;case"zoom-in":u.zoomIn(),c.value=u.getZoom();break;case"zoom-out":u.zoomOut(),c.value=u.getZoom();break;case"fit":u.zoomToFit();break;case"reset":u.zoomTo(1),u.scrollToOrigin(),c.value=1;break;case"export":if(f.value)break;f.value=!0,u.exportAsImage().then(m=>{const E=URL.createObjectURL(m),C=document.createElement("a");C.href=E,C.download="canvas-export.png",C.click(),URL.revokeObjectURL(E)}).catch(m=>{console.warn("[flow-canvas] Export failed:",m)}).finally(()=>{f.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] "${d.type}" toolbar item has no built-in handler. Provide an onClick callback.`);break;default:d.type!=="custom"&&console.warn(`[flow-canvas] No default handler for toolbar type "${d.type}". Provide an onClick handler.`);break}}const y=o.computed(()=>a.value.filter(B)),p=o.computed(()=>{const d=new Map,u=[];for(const m of y.value){const E=m.group??"default";d.has(E)||(d.set(E,[]),u.push(E)),d.get(E).push(m)}return u.map(m=>({name:m,items:d.get(m)})).filter(m=>m.items.length>0)});return(d,u)=>(o.openBlock(),o.createElementBlock("div",co,[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(p.value,(m,E)=>(o.openBlock(),o.createElementBlock(o.Fragment,{key:m.name},[E>0?(o.openBlock(),o.createElementBlock("div",uo)):o.createCommentVNode("",!0),o.createElementVNode("div",fo,[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(m.items,C=>(o.openBlock(),o.createElementBlock(o.Fragment,{key:C.id},[C.type==="zoom-display"?(o.openBlock(),o.createElementBlock("span",po,o.toDisplayString(N.value),1)):(o.openBlock(),o.createElementBlock("button",{key:1,type:"button",class:o.normalizeClass(["flow-canvas-toolbar__btn",{"is-disabled":L(C),"is-active":U(C),"is-exporting":C.type==="export"&&f.value}]),"data-toolbar-id":C.id,"data-toolbar-type":C.type,disabled:L(C),onClick:O=>M(C),onMouseenter:O=>k(O,C),onMouseleave:w},[C.component?(o.openBlock(),o.createBlock(o.resolveDynamicComponent(C.component),{key:0})):C.icon?(o.openBlock(),o.createElementBlock("i",{key:1,class:o.normalizeClass(C.icon)},null,2)):(o.openBlock(),o.createElementBlock("span",{key:2,class:"flow-canvas-toolbar__text",textContent:o.toDisplayString(C.text??C.description??C.id)},null,8,ho))],42,go))],64))),128))])],64))),128)),(o.openBlock(),o.createBlock(o.Teleport,{to:"body"},[h.visible?(o.openBlock(),o.createElementBlock("div",{key:0,ref_key:"tooltipRef",ref:l,class:"flow-canvas-toolbar-tooltip",style:o.normalizeStyle({left:`${h.x}px`,top:`${h.y}px`})},[o.createTextVNode(o.toDisplayString(h.text)+" ",1),u[0]||(u[0]=o.createElementVNode("div",{class:"flow-canvas-toolbar-tooltip__arrow"},null,-1))],4)):o.createCommentVNode("",!0)]))]))}}),mo=re(vo,[["__scopeId","data-v-77d4afbb"]]),yo={class:"flow-canvas-default-node__ep-label"},wo={key:1,class:"flow-canvas-default-node__diamond flow-canvas-highlight-target"},bo={key:2,class:"flow-canvas-default-node__task-label"},Eo=o.defineComponent({__name:"default-node",setup(r){const t=o.inject("getNode")?.(),s=o.computed(()=>t?.getData?.()??null),n=o.computed(()=>s.value?.label||s.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=o.computed(()=>{const f=s.value?.type??"";return a.has(f)?"endpoint":c.has(f)?"gateway":"task"}),v=o.computed(()=>i[s.value?.type??""]??"");return(f,g)=>(o.openBlock(),o.createElementBlock("div",{class:o.normalizeClass(["flow-canvas-default-node",[`is-${l.value}`,{"flow-canvas-highlight-target":l.value!=="gateway"}]])},[l.value==="endpoint"?(o.openBlock(),o.createElementBlock(o.Fragment,{key:0},[v.value?(o.openBlock(),o.createElementBlock("i",{key:0,class:o.normalizeClass([["flow-canvas-icon",v.value],"flow-canvas-default-node__ep-icon"])},null,2)):o.createCommentVNode("",!0),o.createElementVNode("span",yo,o.toDisplayString(n.value),1)],64)):l.value==="gateway"?(o.openBlock(),o.createElementBlock("div",wo,[v.value?(o.openBlock(),o.createElementBlock("i",{key:0,class:o.normalizeClass([["flow-canvas-icon",v.value],"flow-canvas-default-node__gw-icon"])},null,2)):o.createCommentVNode("",!0)])):(o.openBlock(),o.createElementBlock("span",bo,o.toDisplayString(n.value),1))],2))}}),Ge=re(Eo,[["__scopeId","data-v-f0e24a9f"]]),ko={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}},Pe=(r,e)=>({stroke:e.hovered?"#3a84ff":"#abb5cc",strokeWidth:2});function Be(){return{attrs:{line:{stroke:"#abb5cc",strokeWidth:2,targetMarker:{name:"block",width:8,height:8}}}}}function Ue(){return{manhattan:{router:{name:"manhattan",args:{padding:10,maxDirectionChange:90}},connector:{name:"rounded",args:{radius:8}},style:Pe,x6EdgeConfig:Be()},bezier:{connector:{name:"smooth"},style:Pe,x6EdgeConfig:Be()}}}function Co(r){const e=r?.nodeTypes??ko,t={},s=[];for(const[a,c]of Object.entries(e)){const l=c.width??150,v=c.height??50;t[a]={component:Ge,getSize:()=>({width:l,height:v}),getPorts:()=>Oe()},s.push({type:a,label:c.label??a,icon:c.icon})}const n={...Ue(),...r?.edgeTypes},i=r?.defaultEdgeType??"manhattan";return{schema:{nodeTypes:t,defaultEdgeType:i,edgeTypes:n},paletteItems:s}}function xo(r){return{name:"connection-validator",priority:10,transformCommand(e,t,s){const n=new Set;for(const i of e.commands)i.type==="edge.remove"&&n.add(i.edgeId);for(const i of e.commands){if(i.type!=="edge.add"&&i.type!=="edge.reconnect")continue;const a=s.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],f=a.nodes[l];if(!v||!f)continue;const g=i.type==="edge.add"?i.edge.source.portId:i.source?.portId,h=i.type==="edge.add"?i.edge.target.portId:i.target?.portId,k=g?v.ports?.find(P=>P.id===g):void 0,w=h?f.ports?.find(P=>P.id===h):void 0,N=i.type==="edge.reconnect"?i.edgeId:void 0,S=Object.values(a.edges).filter(P=>P.id!==N&&!n.has(P.id)),B=r({flowModel:a,sourceNode:v,targetNode:f,sourcePort:k,targetPort:w,existingEdges:S});if(!B.valid)return{rejected:!0,reason:B.reason??"Connection validation failed",code:"validation_failed"}}return e}}}function Io(r){const{rubberband:e=!0,multiple:t=!0,movable:s=!0}=r??{};return{name:"selection",priority:90,attachRuntime(n){n.graph.use(new et.Selection({enabled:!0,rubberband:e,multiple:t,movable:s,pointerEvents:"none",showNodeSelectionBox:!0,filter:i=>!(i.isNode()&&(i.getData?.()??{})._selectable===!1)}))}}}function No(r){const{tolerance:e=10,color:t="#3a84ff"}=r??{};let s=null;return{name:"snapline",priority:90,async attachRuntime(n){const{Snapline:i}=await import("@antv/x6-plugin-snapline");n.graph.use(new i({enabled:!0,tolerance:e,className:"flow-canvas-snapline"})),s=document.createElement("style"),s.textContent=`.flow-canvas-snapline line { stroke: ${t} !important; }`,document.head.appendChild(s)},detachRuntime(){s?.remove(),s=null}}}const So={class:"flow-canvas-search-popover__input"},Mo=["value","placeholder"],Do=["onMouseenter","onClick"],_o={class:"flow-canvas-search-popover__item-label"},Ao={key:0,class:"flow-canvas-search-popover__item-subtitle"},Po={key:1,class:"flow-canvas-search-popover__empty"},Bo=o.defineComponent({__name:"search-popover",props:{open:{type:Boolean},position:{},query:{},results:{},placeholder:{default:"搜索节点名称"},emptyText:{default:"暂无匹配节点"},isAnchorTarget:{type:Function,default:void 0}},emits:["update:query","select","close"],setup(r,{emit:e}){const t=r,s=e,n=o.ref(null),i=o.ref(null),a=o.ref(-1);o.watch(()=>t.open,w=>{w&&(a.value=-1,o.nextTick(()=>{n.value?.focus(),n.value?.select()}))}),o.watch(()=>t.query,()=>{a.value=-1}),o.watch(()=>t.results.length,w=>{if(!w){a.value=-1;return}a.value>=w&&(a.value=-1)});function c(w){s("update:query",w.target.value)}function l(w){a.value=w}function v(){a.value=-1}function f(){s("update:query",""),o.nextTick(()=>{n.value?.focus()})}function g(){const w=t.results[a.value]??t.results[0];w&&s("select",w.id)}function h(w){if(w.key==="Escape"){w.preventDefault(),s("close");return}if(w.key==="ArrowDown"){if(w.preventDefault(),!t.results.length)return;a.value=a.value<t.results.length-1?a.value+1:0;return}if(w.key==="ArrowUp"){if(w.preventDefault(),!t.results.length)return;a.value=a.value>0?a.value-1:t.results.length-1;return}w.key==="Enter"&&(w.preventDefault(),g())}function k(w){if(!t.open)return;const N=w.target;N&&i.value?.contains(N)||t.isAnchorTarget?.(w.target)||s("close")}return o.onMounted(()=>{document.addEventListener("mousedown",k)}),o.onBeforeUnmount(()=>{document.removeEventListener("mousedown",k)}),(w,N)=>r.open?(o.openBlock(),o.createElementBlock("div",{key:0,ref_key:"panelRef",ref:i,class:"flow-canvas-search-popover",style:o.normalizeStyle({left:`${r.position.x}px`,top:`${r.position.y}px`,width:`${r.position.width}px`})},[o.createElementVNode("div",So,[N[1]||(N[1]=o.createElementVNode("i",{class:"flow-canvas-icon canvas-search"},null,-1)),o.createElementVNode("input",{ref_key:"inputRef",ref:n,value:r.query,placeholder:r.placeholder,onInput:c,onKeydown:h},null,40,Mo),r.query?(o.openBlock(),o.createElementBlock("button",{key:0,type:"button",class:"flow-canvas-search-popover__clear","aria-label":"清空搜索",onClick:f},[...N[0]||(N[0]=[o.createElementVNode("i",{class:"flow-canvas-icon canvas-close-circle-shape"},null,-1)])])):o.createCommentVNode("",!0)]),r.results.length?(o.openBlock(),o.createElementBlock("div",{key:0,class:"flow-canvas-search-popover__list",onMouseleave:v},[(o.openBlock(!0),o.createElementBlock(o.Fragment,null,o.renderList(r.results,(S,B)=>(o.openBlock(),o.createElementBlock("button",{key:S.id,type:"button",class:o.normalizeClass(["flow-canvas-search-popover__item",{"is-active":B===a.value}]),onMouseenter:P=>l(B),onClick:P=>s("select",S.id)},[o.createElementVNode("span",_o,o.toDisplayString(S.label),1),S.subtitle?(o.openBlock(),o.createElementBlock("span",Ao,o.toDisplayString(S.subtitle),1)):o.createCommentVNode("",!0)],42,Do))),128))],32)):(o.openBlock(),o.createElementBlock("div",Po,o.toDisplayString(r.emptyText),1))],4)):o.createCommentVNode("",!0)}}),To=re(Bo,[["__scopeId","data-v-c80f6b26"]]),Te=282,Lo=4,Ro=300,Oo=360,be=100,$o=Oo*4-be;function Vo(r){return r!==null}function zo(r){const e=new Set;return r.map(t=>t?.trim()).filter(t=>!!t).filter(t=>{const s=t.toLowerCase();return e.has(s)?!1:(e.add(s),!0)})}function Ho(r,e){const t=Math.max(8,window.innerWidth-e-8);return Math.min(Math.max(8,r),t)}function Fo(r,e){const t=e?.getNodeMeta?.(r);if(t===null)return null;const s=t?.label?.trim()||r.label?.trim()||r.id,n=t?.subtitle?.trim()||void 0,i=zo(t?.keywords??[r.label,n]);return i.length?{id:r.id,label:s,subtitle:n,keywords:i}:null}function qo(r){let e=null,t=null,s=null,n=null,i=null,a=[];const c=o.ref(!1),l=o.ref(""),v=o.ref({x:0,y:0,width:Te}),f=o.computed(()=>e?Object.values(e.flowModel.value.nodes).map(M=>Fo(M,r)).filter(Vo):[]),g=o.computed(()=>{const M=l.value.trim().toLowerCase(),y=Math.max(1,r?.maxResults??Ro);return M?f.value.filter(p=>p.keywords.some(d=>d.toLowerCase().includes(M))).slice(0,y):f.value.slice(0,y)});function h(){return s?.querySelector('.flow-canvas-toolbar__btn[data-toolbar-type="search"]')}function k(){return h()?.closest(".flow-canvas-toolbar")}function w(){const M=k(),y=s?.getBoundingClientRect(),p=M?.getBoundingClientRect()??y;if(!p)return;const d=Math.max(Te,Math.round(p.width));v.value={x:Ho(p.left,d),y:p.bottom+Lo,width:d}}function N(){a.forEach(M=>clearTimeout(M)),a=[],t?.api.clearHighlight()}function S(M){N();const y=setTimeout(()=>{t?.api.highlightNodes([M])},be),p=setTimeout(()=>{t?.api.clearHighlight(),a=[]},be+$o);a.push(y,p)}function B(M){t&&(t.api.scrollToNode(M),S(M))}function P(){t&&(c.value=!0,w(),requestAnimationFrame(()=>w()))}function V(){c.value=!1,l.value=""}function U(){if(c.value){V();return}P()}function L(M){const y=h();return!!(y&&M instanceof Node&&y.contains(M))}function F(){c.value&&w()}const H=o.defineComponent({name:"FlowCanvasSearchHost",setup(){return()=>o.h(To,{open:c.value,position:v.value,query:l.value,results:g.value,placeholder:r?.placeholder??"搜索节点名称",emptyText:r?.emptyText??"暂无匹配节点",isAnchorTarget:L,"onUpdate:query":M=>{l.value=M},onSelect:B,onClose:V})}});return{name:"search",priority:90,install(M){e=M},attachRuntime(M){t=M,s=M.graph.container.closest(".flow-canvas-layout__content")??M.graph.container.parentElement,n=document.createElement("div"),n.className="flow-canvas-search-host",document.body.append(n),i=o.createApp(H),i.mount(n),window.addEventListener("resize",F),window.addEventListener("scroll",F,!0)},detachRuntime(){V(),N(),window.removeEventListener("resize",F),window.removeEventListener("scroll",F,!0),i?.unmount(),i=null,n?.remove(),n=null,s=null,t=null},dispose(){V(),N(),e=null},provideToolbarItems(){return[{id:"plugin:search",type:"search",icon:"flow-canvas-icon canvas-search",description:"搜索节点",group:"tools",order:22,active:()=>c.value,onClick:U}]}}}const Go=52,Uo=16,jo=40;function Wo(r){const e=document.createElement("div");e.className="flow-canvas-minimap",r.floating!==!1&&e.classList.add("flow-canvas-minimap--floating");const t=document.createElement("div");t.className="flow-canvas-minimap__host",e.append(t),Object.assign(e.style,{width:`${r.width}px`,height:`${r.height}px`}),r.floating!==!1&&Object.assign(e.style,{top:`${Go}px`,left:`${Uo}px`});let s=null,n=r.defaultOpen??!1,i=null;function a(){!r.onClickOutside||i||(i=h=>{const k=h.target;k&&e.contains(k)||h.target?.closest('[data-toolbar-type="minimap"]')||r.onClickOutside()},document.addEventListener("mousedown",i))}function c(){i&&(document.removeEventListener("mousedown",i),i=null)}function l(){s||(s=new tt.MiniMap({container:t,width:r.width,height:r.height,padding:r.contentPadding??jo,scalable:!1}),r.sourceGraph.use(s))}function v(h){n=h,e.style.display=n?"":"none",n?(l(),a()):c()}function f(){v(n),r.mountTarget.appendChild(e)}function g(){c(),s?.dispose(),s=null,e.remove()}return f(),{element:e,isOpen:()=>n,setOpen:v,toggle(){const h=!n;return v(h),h},destroy:g}}function Xo(r){let e=null;const t=o.ref(!1);function s(i){e?.setOpen(i),t.value=i}function n(){e&&(t.value=e.toggle())}return{name:"minimap",priority:90,attachRuntime(i){const a=r?.width??334,c=r?.height??180,l=r?.container??i.graph.container.closest(".flow-canvas-layout__content")??i.graph.container.parentElement;l&&(e=Wo({sourceGraph:i.graph,mountTarget:l,width:a,height:c,floating:!r?.container,defaultOpen:!1,onClickOutside:()=>s(!1)}),s(!1))},detachRuntime(){e?.destroy(),e=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:n}]}}}function Yo(){let r=null,e=0;return{name:"clipboard",priority:90,onKeyboardShortcut(t,s){const n=t.metaKey||t.ctrlKey;if(n&&t.key==="c"){const i=s.graph.getSelectedCells?.()??[];if(!i.length)return!1;const a=s.flowModel.value,c=new Set(i.filter(f=>f.isNode()).map(f=>f.id)),l=[...c].map(f=>a.nodes[f]).filter(Boolean);if(!l.length)return!1;const v=Object.values(a.edges).filter(f=>c.has(f.source.nodeId)&&c.has(f.target.nodeId));return r={nodes:l,edges:v},e=0,!0}if(n&&t.key==="v"){if(!r?.nodes.length)return!1;e++;const i=e*30,a=new Map,c=[];for(const l of r.nodes){const v=`${l.id}_cp${Y().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 r.edges){const v=a.get(l.source.nodeId),f=a.get(l.target.nodeId);!v||!f||c.push({type:"edge.add",edge:{...l,id:`${l.id}_cp${Y().slice(0,6)}`,source:{...l.source,nodeId:v},target:{...l.target,nodeId:f},labels:l.labels?.map(g=>({...g,id:`${g.id}_cp${Y().slice(0,6)}`})),payload:l.payload?{...l.payload}:{}}})}return c.length&&s.executeCommand({id:Y(),source:"user:keyboard",label:"粘贴",timestamp:Date.now(),commands:c}),!0}return!1}}}exports.CanvasConstraintError=oe;exports.CanvasLayout=ao;exports.CanvasNodePalette=Fe;exports.CanvasRuntime=Qt;exports.CanvasSchemaError=Le;exports.CanvasToolbar=mo;exports.DefaultNode=Ge;exports.NodeActionsToolbar=ze;exports.NodeQuickAddPopover=He;exports.applyCanvasCommand=fe;exports.clipboardPlugin=Yo;exports.connectionValidatorPlugin=xo;exports.createBuiltinEdgeTypes=Ue;exports.createCanvasHistory=Re;exports.createDefaultSchema=Co;exports.createDefaultToolbarItems=qe;exports.createEmptyFlowModel=ot;exports.generateId=Y;exports.minimapPlugin=Xo;exports.searchPlugin=qo;exports.selectionPlugin=Io;exports.snaplinePlugin=No;exports.useCanvasEditor=wt;
package/dist/index.d.ts CHANGED
@@ -112,7 +112,7 @@ type CanvasCommand = {
112
112
  path: string[];
113
113
  value: unknown;
114
114
  };
115
- type CommandSource = 'user:drag' | 'user:keyboard' | 'user:toolbar' | 'user:quick-add' | 'user:panel' | 'plugin' | 'system' | 'system:replace';
115
+ type CommandSource = 'user:drag' | 'user:edge-drop' | 'user:keyboard' | 'user:toolbar' | 'user:quick-add' | 'user:panel' | 'plugin' | 'system' | 'system:replace';
116
116
  interface CommandEnvelope {
117
117
  id: string;
118
118
  label?: string;
@@ -407,6 +407,20 @@ interface QuickAddConfig {
407
407
  /** 点击 quick-add 插入节点时使用的方向;默认跟随绑定 port 的标准方向,不可推断时回退为 'right' */
408
408
  insertDirection?: InsertDirection | QuickAddInsertDirectionResolver;
409
409
  }
410
+ interface EdgeDropConfig {
411
+ /** 全局开关,默认 false */
412
+ enabled?: boolean;
413
+ /** 节点矩形向内收缩的边距(px),越大越不容易触发,默认 15 */
414
+ bufferMargin?: number;
415
+ /** 判断拖拽中的节点是否可以插入到边上,默认全部允许 */
416
+ isNodeInsertable?: (node: FlowNodeModel, flowModel: FlowModel) => boolean;
417
+ /** 判断边是否可作为插入目标,默认全部允许 */
418
+ isEdgeDropTarget?: (edge: FlowEdgeModel, flowModel: FlowModel) => boolean;
419
+ /** 插入节点的入口端口分组,默认 'left' */
420
+ incomingPortGroup?: string;
421
+ /** 插入节点的出口端口分组,默认 'right' */
422
+ outgoingPortGroup?: string;
423
+ }
410
424
  interface NodePaletteItem {
411
425
  type: string;
412
426
  label: string;
@@ -643,6 +657,7 @@ type __VLS_Props$5 = {
643
657
  graphOptions?: Record<string, unknown>;
644
658
  nodeActions?: NodeActionsConfig;
645
659
  quickAdd?: QuickAddConfig;
660
+ edgeDrop?: EdgeDropConfig;
646
661
  /** 拖拽连线时,根据源节点 ID 返回不应显示端口的节点 ID 集合(如自身、上游、不可作为目标的节点) */
647
662
  getConnectionExcludedNodeIds?: (sourceNodeId: string) => Iterable<string>;
648
663
  };
@@ -872,4 +887,4 @@ declare function minimapPlugin(options?: MinimapPluginOptions): CanvasPlugin;
872
887
  declare function clipboardPlugin(): CanvasPlugin;
873
888
 
874
889
  export { CanvasConstraintError, _default$5 as CanvasLayout, _default$3 as CanvasNodePalette, _default$6 as CanvasRuntime, CanvasSchemaError, _default$4 as CanvasToolbar, _default$2 as DefaultNode, _default$1 as NodeActionsToolbar, _default as NodeQuickAddPopover, applyCanvasCommand, clipboardPlugin, connectionValidatorPlugin, createBuiltinEdgeTypes, createCanvasHistory, createDefaultSchema, createDefaultToolbarItems, createEmptyFlowModel, generateId, minimapPlugin, searchPlugin, selectionPlugin, snaplinePlugin, useCanvasEditor };
875
- export type { BuiltinEdgeType, BuiltinToolbarType, CanvasApi, CanvasCallbackContext, CanvasCommand, CanvasEdgeDefinition, CanvasEditorContext, CanvasEditorOptions, CanvasHistory, CanvasHistoryOptions, CanvasMode, CanvasNodeDefinition, CanvasPlugin, CanvasPosition, CanvasSchema, CanvasSelection, CanvasToolbarItem, CanvasUiEvent, CommandEnvelope, CommandExecutionError, CommandExecutionResult, CommandPreview, CommandRejection, CommandSource, ConnectionValidateContext, ConnectionValidateResult, ConnectionValidator, ContextMenuItem, CoreToolbarType, DefaultNodeTypeConfig, DefaultSchemaOptions, DefaultSchemaResult, DefaultToolbarItemsOptions, DeleteSelectionOptions, EdgeDecoration, EdgeRenderState, EdgeStyle, EditorPluginContext, ExportOptions, FlowEdgeLabelModel, FlowEdgeModel, FlowModel, FlowModelChangeEvent, FlowNodeModel, FlowPortModel, GraphWithSelection, IdGenerator, InsertDirection, InsertNodeOptions, MinimapPluginOptions, NodeActionsConfig, NodeBehaviorConfig, NodeDecoration, NodePaletteItem, OverlayManager, PluginManagedToolbarType, QuickAddConfig, QuickAddInsertDirectionResolver, QuickAddPortResolver, RuntimePluginContext, ScreenPosition, SearchNodeMeta, SearchPluginOptions, SelectionPluginOptions, SnaplinePluginOptions };
890
+ export type { BuiltinEdgeType, BuiltinToolbarType, CanvasApi, CanvasCallbackContext, CanvasCommand, CanvasEdgeDefinition, CanvasEditorContext, CanvasEditorOptions, CanvasHistory, CanvasHistoryOptions, CanvasMode, CanvasNodeDefinition, CanvasPlugin, CanvasPosition, CanvasSchema, CanvasSelection, CanvasToolbarItem, CanvasUiEvent, CommandEnvelope, CommandExecutionError, CommandExecutionResult, CommandPreview, CommandRejection, CommandSource, ConnectionValidateContext, ConnectionValidateResult, ConnectionValidator, ContextMenuItem, CoreToolbarType, DefaultNodeTypeConfig, DefaultSchemaOptions, DefaultSchemaResult, DefaultToolbarItemsOptions, DeleteSelectionOptions, EdgeDecoration, EdgeDropConfig, EdgeRenderState, EdgeStyle, EditorPluginContext, ExportOptions, FlowEdgeLabelModel, FlowEdgeModel, FlowModel, FlowModelChangeEvent, FlowNodeModel, FlowPortModel, GraphWithSelection, IdGenerator, InsertDirection, InsertNodeOptions, MinimapPluginOptions, NodeActionsConfig, NodeBehaviorConfig, NodeDecoration, NodePaletteItem, OverlayManager, PluginManagedToolbarType, QuickAddConfig, QuickAddInsertDirectionResolver, QuickAddPortResolver, RuntimePluginContext, ScreenPosition, SearchNodeMeta, SearchPluginOptions, SelectionPluginOptions, SnaplinePluginOptions };