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