@blueking/flow-canvas 0.0.2 → 0.0.4

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