@mx-sose-front/mx-sose-graph 1.1.7 → 1.1.9

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.
Files changed (52) hide show
  1. package/dist/assets/edgeWorker-b57ca007.js +2 -0
  2. package/dist/assets/edgeWorker-b57ca007.js.map +1 -0
  3. package/dist/index.d.ts +633 -30
  4. package/dist/index.esm.js +8728 -4734
  5. package/dist/index.esm.js.map +1 -1
  6. package/dist/index.umd.js +1 -1
  7. package/dist/index.umd.js.map +1 -1
  8. package/dist/style.css +1 -1
  9. package/package.json +1 -1
  10. package/src/components/Common/Tree.vue +451 -0
  11. package/src/components/Common/index.ts +2 -0
  12. package/src/components/DiagramListTooltip/DiagramListTooltip.vue +1 -2
  13. package/src/components/Edge/Edge.vue +172 -169
  14. package/src/components/Gantt/Gantt.vue +1544 -0
  15. package/src/components/GanttContextMenu/GanttContextMenu.vue +304 -0
  16. package/src/components/InteractionLayer.vue +343 -147
  17. package/src/components/Matrix/Matrix.vue +828 -0
  18. package/src/components/Matrix/index.ts +168 -0
  19. package/src/components/Shape/ConceptualRole.vue +2 -34
  20. package/src/components/Table/Table.vue +970 -0
  21. package/src/constants/edgeShapeKeys.ts +8 -5
  22. package/src/constants/index.ts +259 -45
  23. package/src/hooks/index.ts +2 -0
  24. package/src/hooks/useChartRowSelection.ts +456 -0
  25. package/src/hooks/useResize.ts +2 -2
  26. package/src/hooks/useVirtualScroll.ts +258 -0
  27. package/src/index.ts +1 -1
  28. package/src/render/shape-renderer.ts +62 -2
  29. package/src/statics/icons/childIcons//345/221/275/344/273/244@3x.png +0 -0
  30. package/src/statics/icons/childIcons//346/210/230/347/225/245/346/246/202/345/277/265/350/241/250@3x.png +0 -0
  31. package/src/statics/icons/childIcons//346/216/247/345/210/266@3x.png +0 -0
  32. package/src/statics/icons/createMenu/down.png +0 -0
  33. package/src/statics/icons/createMenu/remove.png +0 -0
  34. package/src/statics/icons/createMenu/up.png +0 -0
  35. package/src/store/graphStore.ts +217 -44
  36. package/src/types/index.ts +86 -4
  37. package/src/utils/batchAutoExpand.ts +9 -10
  38. package/src/utils/containers.ts +72 -17
  39. package/src/utils/contextMenuUtils.ts +7 -7
  40. package/src/utils/dateUtils.ts +160 -0
  41. package/src/utils/diagram.ts +10 -8
  42. package/src/utils/drag.ts +6 -5
  43. package/src/utils/edgeUtils.ts +344 -427
  44. package/src/utils/edgeWorker.ts +471 -0
  45. package/src/utils/hittest.ts +37 -38
  46. package/src/utils/index.ts +3 -0
  47. package/src/utils/keyboardUtils.ts +5 -5
  48. package/src/utils/packageOutline.ts +96 -0
  49. package/src/utils/rafThrottle.ts +162 -0
  50. package/src/utils/workerManager.ts +335 -0
  51. package/src/view/graph.vue +47 -33
  52. /package/src/statics/icons/childIcons//346/210/230/347/225/{245@3x.png" → 245/345/261/202@3x.png"} +0 -0
@@ -0,0 +1,2 @@
1
+ !function(){"use strict";class t{static getShapeCenterPoints(t){const{x:e,y:s,width:n,height:o}=t;return{top:{x:e+n/2,y:s},bottom:{x:e+n/2,y:s+o},left:{x:e,y:s+o/2},right:{x:e+n,y:s+o/2}}}static getDistance(t,e){const s=t.x-e.x,n=t.y-e.y;return Math.sqrt(s*s+n*n)}static buildSelfLoopWaypoints(t,e=0){const{x:s,y:n,width:o,height:i}=t,a=s+o/2,d={x:a,y:n},r={x:a,y:n+i},c=Math.max(.24*o,20)+12*e,u=Math.max(.45*i,26)+10*e;return{sourcePoint:d,targetPoint:r,waypoints:[d,{x:a,y:n-u},{x:s+o+c,y:n-u},{x:s+o+c,y:n+i+u},{x:a,y:n+i+u},r]}}static buildEdgeWaypoints(t,e,s,n){if(n)return this.buildSelfLoopWaypoints(t,s);const{sourcePoint:o,targetPoint:i}=this.calcBestEndpoints(t,e,s);return{sourcePoint:o,targetPoint:i,waypoints:[o,i]}}static calcBestEndpoints(t,e,s){const n=this.getShapeCenterPoints(t),o=this.getShapeCenterPoints(e);let i=1/0,a=n.top,d=o.top;for(const r of Object.values(n))for(const t of Object.values(o)){const e=this.getDistance(r,t);e<i&&(i=e,a=r,d=t)}if(s>0){const n=e.x+e.width/2-(t.x+t.width/2),o=e.y+e.height/2-(t.y+t.height/2),i=5*(s+1);let r=0,c=0;return Math.abs(n)>Math.abs(o)?c=i:r=i,s%2==1&&(r=-r,c=-c),{sourcePoint:{x:a.x+r,y:a.y+c},targetPoint:{x:d.x+r,y:d.y+c}}}return{sourcePoint:a,targetPoint:d}}static updateRelatedEdges(t,e,s,n){let o;if(s){const t=new Set;o=[];for(const n of e){const e=s.get(n);if(e)for(const s of e)t.has(s.id)||(t.add(s.id),o.push(s))}}else o=t.filter(t=>"edge"===t.shapeType);const i=n?t=>n.get(t)??null:e=>t.find(t=>t.id===e)??null,a=new Map;o.forEach(t=>{if(t.sourceId&&t.targetId){const e=t.sourceId.localeCompare(t.targetId)<=0?`${t.sourceId}-${t.targetId}`:`${t.targetId}-${t.sourceId}`;a.has(e)||a.set(e,[]),a.get(e).push(t)}});const d=new Set(e),r=[];return a.forEach(t=>{t.forEach((e,s)=>{const n=e.sourceId&&d.has(e.sourceId),o=e.targetId&&d.has(e.targetId);if(n||o){const n=e.sourceId?i(e.sourceId):null,o=e.targetId?i(e.targetId):null;if(n&&o&&n.bounds&&o.bounds){const i=t.length>1?s:0,{waypoints:a}=this.buildEdgeWaypoints(n.bounds,o.bounds,i,n.id===o.id);r.push({...e,waypointId:JSON.stringify(a)})}}})}),r}static initializeAllEdgeEndpoints(t,e){const s=t.filter(t=>"edge"===t.shapeType),n=e?t=>e.get(t)??null:e=>t.find(t=>t.id===e)??null,o=new Map;s.forEach(t=>{if(t.sourceId&&t.targetId){const e=t.sourceId.localeCompare(t.targetId)<=0?`${t.sourceId}-${t.targetId}`:`${t.targetId}-${t.sourceId}`;o.has(e)||o.set(e,[]),o.get(e).push(t)}});const i=[];return o.forEach(t=>{t.forEach((e,s)=>{const o=e.sourceId?n(e.sourceId):null,a=e.targetId?n(e.targetId):null;if(o&&a&&o.bounds&&a.bounds){const n=t.length>1?s:0,{waypoints:d}=this.buildEdgeWaypoints(o.bounds,a.bounds,n,o.id===a.id);i.push({...e,waypointId:JSON.stringify(d)})}})}),i}static completeConnection(t,e,s,n,o=[]){if(!e.bounds||!t?.bounds)return null;const i=o.filter(s=>"edge"===s.shapeType&&(s.sourceId===t?.id&&s.targetId===e.id||s.sourceId===e.id&&s.targetId===t?.id)).length,{sourcePoint:a,targetPoint:d,waypoints:r}=this.buildEdgeWaypoints(t.bounds,e.bounds,i,t.id===e.id);return{sourceId:t?.id,sourceModelId:t?.modelId,targetId:e.id,targetModelId:e.modelId,sourcePoint:a,targetPoint:d,waypoints:r}}static findNearestConnectPoint(t,e){if(!e?.bounds)return null;const s=t.x,n=t.y,{x:o=0,y:i=0,width:a=0,height:d=0}=e.bounds,r=o,c=o+a,u=i,h=i+d,g=s-o,l=n-i,p=l<0,y=l>d,f=g<0,b=g>a,I=this.getShapeCenterPoints({x:e.bounds.x??0,y:e.bounds.y??0,width:e.bounds.width??0,height:e.bounds.height??0}),x={x:s,y:n};if(p||y||f||b){const t={top:this.getDistance(x,I.top),bottom:this.getDistance(x,I.bottom),left:this.getDistance(x,I.left),right:this.getDistance(x,I.right)};return I[Object.entries(t).reduce((t,[e,s])=>s<t.distance?{key:e,distance:s}:t,{key:"top",distance:1/0}).key]}const w={top:Math.abs(n-u),bottom:Math.abs(n-h),left:Math.abs(s-r),right:Math.abs(s-c)};switch(Object.entries(w).reduce((t,[e,s])=>s<t.distance?{key:e,distance:s}:t,{key:"top",distance:1/0}).key){case"top":return{x:s,y:u};case"bottom":return{x:s,y:h};case"left":return{x:r,y:n};case"right":return{x:c,y:n};default:return I.top}}}self.addEventListener("message",e=>{const{type:s,data:n,id:o}=e.data;try{let e;switch(s){case"updateRelatedEdges":{const{shapes:s,changedIds:o,edgeIndex:i,shapeMapIndex:a}=n,d=i?new Map(Object.entries(i)):void 0,r=a?new Map(Object.entries(a)):void 0;e=t.updateRelatedEdges(s,o,d,r);break}case"initializeAllEdgeEndpoints":{const{shapes:s,shapeMapIndex:o}=n,i=o?new Map(Object.entries(o)):void 0;e=t.initializeAllEdgeEndpoints(s,i);break}case"completeConnection":e=t.completeConnection(n.sourceShape,n.targetShape,n.clickPoint,n.currentConnectPoint,n.shapes);break;case"findNearestConnectPoint":e=t.findNearestConnectPoint(n.mousePos,n.shape);break;default:throw new Error(`Unknown message type: ${s}`)}self.postMessage({id:o,result:e})}catch(i){self.postMessage({id:o,error:i instanceof Error?i.message:String(i)})}})}();
2
+ //# sourceMappingURL=edgeWorker-b57ca007.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edgeWorker-b57ca007.js","sources":["../src/utils/edgeWorker.ts"],"sourcesContent":["// edgeWorker.ts - Web Worker for handling complex edge calculations\r\n\r\ninterface Shape {\r\n id: string;\r\n shapeType: string;\r\n bounds?: {\r\n x: number;\r\n y: number;\r\n width: number;\r\n height: number;\r\n };\r\n sourceId?: string;\r\n targetId?: string;\r\n modelId?: string;\r\n shapeKey?: string;\r\n direction?: string;\r\n parenShapeId?: string;\r\n [key: string]: any;\r\n}\r\n\r\ninterface WorkerMessage {\r\n type: string;\r\n data: any;\r\n id?: number;\r\n}\r\n\r\ninterface WorkerResponse {\r\n id: number;\r\n result: any;\r\n error?: string;\r\n}\r\n\r\nclass EdgeWorkerUtils {\r\n /**\r\n * 获取图形的四个中心点(上下左右)\r\n */\r\n static getShapeCenterPoints(bounds: { x: number; y: number; width: number; height: number }) {\r\n const { x, y, width, height } = bounds;\r\n return {\r\n top: { x: x + width / 2, y: y },\r\n bottom: { x: x + width / 2, y: y + height },\r\n left: { x: x, y: y + height / 2 },\r\n right: { x: x + width, y: y + height / 2 },\r\n };\r\n }\r\n\r\n static getDistance(p1: { x: number; y: number }, p2: { x: number; y: number }) {\r\n const dx = p1.x - p2.x;\r\n const dy = p1.y - p2.y;\r\n return Math.sqrt(dx * dx + dy * dy);\r\n }\r\n\r\n /**\r\n * 生成图元自连接时使用的半环路径。\r\n * Worker 和主线程保持同一套正交折线规则,避免异步回填后形态不一致。\r\n */\r\n static buildSelfLoopWaypoints(\r\n bounds: { x: number; y: number; width: number; height: number },\r\n groupIndex: number = 0\r\n ): {\r\n sourcePoint: { x: number; y: number };\r\n targetPoint: { x: number; y: number };\r\n waypoints: Array<{ x: number; y: number }>;\r\n } {\r\n const { x, y, width, height } = bounds;\r\n const centerX = x + width / 2;\r\n const sourcePoint = { x: centerX, y };\r\n const targetPoint = { x: centerX, y: y + height };\r\n\r\n // 保持上下抬升高度不变,只缩短右侧外扩距离,让右边那段线更贴近图元。\r\n const outwardOffset = Math.max(width * 0.24, 20) + groupIndex * 12;\r\n const verticalPadding = Math.max(height * 0.45, 26) + groupIndex * 10;\r\n const upperPoint = {\r\n x: centerX,\r\n y: y - verticalPadding,\r\n };\r\n const upperRightPoint = {\r\n x: x + width + outwardOffset,\r\n y: y - verticalPadding,\r\n };\r\n const lowerRightPoint = {\r\n x: x + width + outwardOffset,\r\n y: y + height + verticalPadding,\r\n };\r\n const lowerPoint = {\r\n x: centerX,\r\n y: y + height + verticalPadding,\r\n };\r\n\r\n return {\r\n sourcePoint,\r\n targetPoint,\r\n waypoints: [sourcePoint, upperPoint, upperRightPoint, lowerRightPoint, lowerPoint, targetPoint],\r\n };\r\n }\r\n\r\n /**\r\n * 统一生成边的折点数据。\r\n * 普通连线走最近边中点,自连接走专用半环路径。\r\n */\r\n static buildEdgeWaypoints(\r\n sBounds: { x: number; y: number; width: number; height: number },\r\n tBounds: { x: number; y: number; width: number; height: number },\r\n groupIndex: number,\r\n isSelfLoop: boolean\r\n ): {\r\n sourcePoint: { x: number; y: number };\r\n targetPoint: { x: number; y: number };\r\n waypoints: Array<{ x: number; y: number }>;\r\n } {\r\n if (isSelfLoop) {\r\n return this.buildSelfLoopWaypoints(sBounds, groupIndex);\r\n }\r\n\r\n const { sourcePoint, targetPoint } = this.calcBestEndpoints(\r\n sBounds,\r\n tBounds,\r\n groupIndex\r\n );\r\n\r\n return {\r\n sourcePoint,\r\n targetPoint,\r\n waypoints: [sourcePoint, targetPoint],\r\n };\r\n }\r\n\r\n /**\r\n * 计算两个图元之间的最佳连接端点(共用算法,与主线程 EdgeUtils.calcBestEndpoints 一致)\r\n */\r\n static calcBestEndpoints(\r\n sBounds: { x: number; y: number; width: number; height: number },\r\n tBounds: { x: number; y: number; width: number; height: number },\r\n groupIndex: number\r\n ): { sourcePoint: { x: number; y: number }; targetPoint: { x: number; y: number } } {\r\n const sourcePoints = this.getShapeCenterPoints(sBounds);\r\n const targetPoints = this.getShapeCenterPoints(tBounds);\r\n\r\n let minDist = Infinity;\r\n let bestSrc = sourcePoints.top;\r\n let bestTgt = targetPoints.top;\r\n for (const sp of Object.values(sourcePoints)) {\r\n for (const tp of Object.values(targetPoints)) {\r\n const d = this.getDistance(sp, tp);\r\n if (d < minDist) {\r\n minDist = d;\r\n bestSrc = sp;\r\n bestTgt = tp;\r\n }\r\n }\r\n }\r\n\r\n if (groupIndex > 0) {\r\n const dx = (tBounds.x + tBounds.width / 2) - (sBounds.x + sBounds.width / 2);\r\n const dy = (tBounds.y + tBounds.height / 2) - (sBounds.y + sBounds.height / 2);\r\n const offsetDistance = 5 * (groupIndex + 1);\r\n let offsetX = 0, offsetY = 0;\r\n if (Math.abs(dx) > Math.abs(dy)) {\r\n offsetY = offsetDistance;\r\n } else {\r\n offsetX = offsetDistance;\r\n }\r\n if (groupIndex % 2 === 1) {\r\n offsetX = -offsetX;\r\n offsetY = -offsetY;\r\n }\r\n return {\r\n sourcePoint: { x: bestSrc.x + offsetX, y: bestSrc.y + offsetY },\r\n targetPoint: { x: bestTgt.x + offsetX, y: bestTgt.y + offsetY },\r\n };\r\n }\r\n\r\n return { sourcePoint: bestSrc, targetPoint: bestTgt };\r\n }\r\n\r\n /**\r\n * 更新与指定图元相关的连线端点\r\n */\r\n static updateRelatedEdges(\r\n shapes: Shape[],\r\n changedIds: string[],\r\n edgeIndex?: Map<string, Shape[]>,\r\n shapeMapIndex?: Map<string, Shape>\r\n ): Shape[] {\r\n let relatedEdges: Shape[];\r\n if (edgeIndex) {\r\n const seen = new Set<string>();\r\n relatedEdges = [];\r\n for (const id of changedIds) {\r\n const edges = edgeIndex.get(id);\r\n if (edges) {\r\n for (const e of edges) {\r\n if (!seen.has(e.id)) {\r\n seen.add(e.id);\r\n relatedEdges.push(e);\r\n }\r\n }\r\n }\r\n }\r\n } else {\r\n relatedEdges = shapes.filter((shape) => shape.shapeType === \"edge\");\r\n }\r\n\r\n const findShape = shapeMapIndex\r\n ? (id: string) => shapeMapIndex.get(id) ?? null\r\n : (id: string) => shapes.find(s => s.id === id) ?? null;\r\n\r\n const edgeGroups = new Map<string, Shape[]>();\r\n relatedEdges.forEach((edge) => {\r\n if (edge.sourceId && edge.targetId) {\r\n const isForward = edge.sourceId.localeCompare(edge.targetId) <= 0;\r\n const groupKey = isForward\r\n ? `${edge.sourceId}-${edge.targetId}`\r\n : `${edge.targetId}-${edge.sourceId}`;\r\n if (!edgeGroups.has(groupKey)) edgeGroups.set(groupKey, []);\r\n edgeGroups.get(groupKey)!.push(edge);\r\n }\r\n });\r\n\r\n const changedSet = new Set(changedIds);\r\n const updatedEdges: Shape[] = [];\r\n\r\n edgeGroups.forEach((groupEdges) => {\r\n groupEdges.forEach((edge, index) => {\r\n const sourceChanged = edge.sourceId && changedSet.has(edge.sourceId);\r\n const targetChanged = edge.targetId && changedSet.has(edge.targetId);\r\n\r\n if (sourceChanged || targetChanged) {\r\n const sourceShape = edge.sourceId ? findShape(edge.sourceId) : null;\r\n const targetShape = edge.targetId ? findShape(edge.targetId) : null;\r\n\r\n if (sourceShape && targetShape && sourceShape.bounds && targetShape.bounds) {\r\n const groupIndex = groupEdges.length > 1 ? index : 0;\r\n const { waypoints } = this.buildEdgeWaypoints(\r\n sourceShape.bounds,\r\n targetShape.bounds,\r\n groupIndex,\r\n sourceShape.id === targetShape.id\r\n );\r\n updatedEdges.push({\r\n ...edge,\r\n waypointId: JSON.stringify(waypoints),\r\n });\r\n }\r\n }\r\n });\r\n });\r\n\r\n return updatedEdges;\r\n }\r\n\r\n /**\r\n * 初始化所有连线的端点\r\n */\r\n static initializeAllEdgeEndpoints(\r\n shapes: Shape[],\r\n shapeMapIndex?: Map<string, Shape>\r\n ): Shape[] {\r\n const edges = shapes.filter((shape) => shape.shapeType === \"edge\");\r\n\r\n const findShape = shapeMapIndex\r\n ? (id: string) => shapeMapIndex.get(id) ?? null\r\n : (id: string) => shapes.find(s => s.id === id) ?? null;\r\n\r\n const edgeGroups = new Map<string, Shape[]>();\r\n edges.forEach((edge) => {\r\n if (edge.sourceId && edge.targetId) {\r\n const isForward = edge.sourceId.localeCompare(edge.targetId) <= 0;\r\n const groupKey = isForward\r\n ? `${edge.sourceId}-${edge.targetId}`\r\n : `${edge.targetId}-${edge.sourceId}`;\r\n if (!edgeGroups.has(groupKey)) edgeGroups.set(groupKey, []);\r\n edgeGroups.get(groupKey)!.push(edge);\r\n }\r\n });\r\n\r\n const updatedEdges: Shape[] = [];\r\n\r\n edgeGroups.forEach((groupEdges) => {\r\n groupEdges.forEach((edge, index) => {\r\n const sourceShape = edge.sourceId ? findShape(edge.sourceId) : null;\r\n const targetShape = edge.targetId ? findShape(edge.targetId) : null;\r\n\r\n if (sourceShape && targetShape && sourceShape.bounds && targetShape.bounds) {\r\n const groupIndex = groupEdges.length > 1 ? index : 0;\r\n const { waypoints } = this.buildEdgeWaypoints(\r\n sourceShape.bounds,\r\n targetShape.bounds,\r\n groupIndex,\r\n sourceShape.id === targetShape.id\r\n );\r\n updatedEdges.push({\r\n ...edge,\r\n waypointId: JSON.stringify(waypoints),\r\n });\r\n }\r\n });\r\n });\r\n\r\n return updatedEdges;\r\n }\r\n\r\n /**\r\n * 完成连接操作,计算最终连接点\r\n */\r\n static completeConnection(\r\n sourceShape: Shape | undefined,\r\n targetShape: Shape,\r\n clickPoint: { x: number; y: number },\r\n currentConnectPoint: { x: number; y: number },\r\n shapes: Shape[] = []\r\n ) {\r\n if (!targetShape.bounds || !sourceShape?.bounds) return null;\r\n\r\n const existingEdges = shapes.filter(\r\n shape => shape.shapeType === 'edge' &&\r\n ((shape.sourceId === sourceShape?.id && shape.targetId === targetShape.id) ||\r\n (shape.sourceId === targetShape.id && shape.targetId === sourceShape?.id))\r\n );\r\n\r\n const groupIndex = existingEdges.length;\r\n const { sourcePoint, targetPoint, waypoints } = this.buildEdgeWaypoints(\r\n sourceShape.bounds,\r\n targetShape.bounds,\r\n groupIndex,\r\n sourceShape.id === targetShape.id\r\n );\r\n\r\n return {\r\n sourceId: sourceShape?.id,\r\n sourceModelId: sourceShape?.modelId,\r\n targetId: targetShape.id,\r\n targetModelId: targetShape.modelId,\r\n sourcePoint,\r\n targetPoint,\r\n waypoints,\r\n };\r\n }\r\n\r\n /**\r\n * 找到距离鼠标位置最近的连接点\r\n */\r\n static findNearestConnectPoint(\r\n mousePos: { x: number; y: number },\r\n shape: Shape | undefined\r\n ) {\r\n if (!shape?.bounds) return null;\r\n\r\n const mouseX = mousePos.x;\r\n const mouseY = mousePos.y;\r\n const { x = 0, y = 0, width = 0, height = 0 } = shape.bounds;\r\n\r\n const left = x;\r\n const right = x + width;\r\n const top = y;\r\n const bottom = y + height;\r\n\r\n const relativeX = mouseX - x;\r\n const relativeY = mouseY - y;\r\n\r\n const isInTopArea = relativeY < 0;\r\n const isInBottomArea = relativeY > height;\r\n const isInLeftArea = relativeX < 0;\r\n const isInRightArea = relativeX > width;\r\n\r\n const connectPoints = this.getShapeCenterPoints({\r\n x: shape.bounds.x ?? 0,\r\n y: shape.bounds.y ?? 0,\r\n width: shape.bounds.width ?? 0,\r\n height: shape.bounds.height ?? 0,\r\n });\r\n\r\n const mousePoint = { x: mouseX, y: mouseY };\r\n\r\n if (isInTopArea || isInBottomArea || isInLeftArea || isInRightArea) {\r\n const distances = {\r\n top: this.getDistance(mousePoint, connectPoints.top),\r\n bottom: this.getDistance(mousePoint, connectPoints.bottom),\r\n left: this.getDistance(mousePoint, connectPoints.left),\r\n right: this.getDistance(mousePoint, connectPoints.right),\r\n };\r\n\r\n const nearestPoint = Object.entries(distances).reduce(\r\n (min, [key, distance]) =>\r\n distance < min.distance ? { key, distance } : min,\r\n { key: \"top\", distance: Infinity }\r\n );\r\n\r\n return connectPoints[nearestPoint.key as keyof typeof connectPoints];\r\n }\r\n\r\n // 鼠标在图形内部,使用最近的边\r\n const distances = {\r\n top: Math.abs(mouseY - top),\r\n bottom: Math.abs(mouseY - bottom),\r\n left: Math.abs(mouseX - left),\r\n right: Math.abs(mouseX - right),\r\n };\r\n\r\n const nearestEdge = Object.entries(distances).reduce(\r\n (min, [key, distance]) =>\r\n distance < min.distance ? { key, distance } : min,\r\n { key: \"top\", distance: Infinity }\r\n );\r\n\r\n switch (nearestEdge.key) {\r\n case \"top\":\r\n return { x: mouseX, y: top };\r\n case \"bottom\":\r\n return { x: mouseX, y: bottom };\r\n case \"left\":\r\n return { x: left, y: mouseY };\r\n case \"right\":\r\n return { x: right, y: mouseY };\r\n default:\r\n return connectPoints.top;\r\n }\r\n }\r\n}\r\n\r\n// 监听主线程消息\r\nself.addEventListener('message', (event: MessageEvent<WorkerMessage>) => {\r\n const { type, data, id } = event.data;\r\n\r\n try {\r\n let result;\r\n\r\n switch (type) {\r\n case 'updateRelatedEdges': {\r\n const { shapes, changedIds, edgeIndex: edgeIndexData, shapeMapIndex: shapeMapData } = data;\r\n const edgeIndex = edgeIndexData ? new Map(Object.entries(edgeIndexData)) : undefined;\r\n const shapeMapIndex = shapeMapData ? new Map(Object.entries(shapeMapData)) : undefined;\r\n result = EdgeWorkerUtils.updateRelatedEdges(\r\n shapes, changedIds,\r\n edgeIndex as Map<string, Shape[]> | undefined,\r\n shapeMapIndex as Map<string, Shape> | undefined\r\n );\r\n break;\r\n }\r\n case 'initializeAllEdgeEndpoints': {\r\n const { shapes: initShapes, shapeMapIndex: initShapeMapData } = data;\r\n const initShapeMapIndex = initShapeMapData ? new Map(Object.entries(initShapeMapData)) : undefined;\r\n result = EdgeWorkerUtils.initializeAllEdgeEndpoints(\r\n initShapes,\r\n initShapeMapIndex as Map<string, Shape> | undefined\r\n );\r\n break;\r\n }\r\n case 'completeConnection':\r\n result = EdgeWorkerUtils.completeConnection(\r\n data.sourceShape, data.targetShape,\r\n data.clickPoint, data.currentConnectPoint, data.shapes\r\n );\r\n break;\r\n case 'findNearestConnectPoint':\r\n result = EdgeWorkerUtils.findNearestConnectPoint(data.mousePos, data.shape);\r\n break;\r\n default:\r\n throw new Error(`Unknown message type: ${type}`);\r\n }\r\n\r\n self.postMessage({ id, result } as WorkerResponse);\r\n } catch (error) {\r\n self.postMessage({\r\n id,\r\n error: error instanceof Error ? error.message : String(error)\r\n } as WorkerResponse);\r\n }\r\n});\r\n\r\n// Worker 文件不需要 export,由 self.addEventListener 驱动\r\n"],"names":["EdgeWorkerUtils","getShapeCenterPoints","bounds","x","y","width","height","top","bottom","left","right","getDistance","p1","p2","dx","dy","Math","sqrt","buildSelfLoopWaypoints","groupIndex","centerX","sourcePoint","targetPoint","outwardOffset","max","verticalPadding","waypoints","buildEdgeWaypoints","sBounds","tBounds","isSelfLoop","this","calcBestEndpoints","sourcePoints","targetPoints","minDist","Infinity","bestSrc","bestTgt","sp","Object","values","tp","d","offsetDistance","offsetX","offsetY","abs","updateRelatedEdges","shapes","changedIds","edgeIndex","shapeMapIndex","relatedEdges","seen","Set","id","edges","get","e","has","add","push","filter","shape","shapeType","findShape","find","s","edgeGroups","Map","forEach","edge","sourceId","targetId","groupKey","localeCompare","set","changedSet","updatedEdges","groupEdges","index","sourceChanged","targetChanged","sourceShape","targetShape","length","waypointId","JSON","stringify","initializeAllEdgeEndpoints","completeConnection","clickPoint","currentConnectPoint","sourceModelId","modelId","targetModelId","findNearestConnectPoint","mousePos","mouseX","mouseY","relativeX","relativeY","isInTopArea","isInBottomArea","isInLeftArea","isInRightArea","connectPoints","mousePoint","distances","entries","reduce","min","key","distance","self","addEventListener","event","type","data","result","edgeIndexData","shapeMapData","initShap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