@logicflow/extension 2.2.0-alpha.7 → 2.2.1

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 (125) hide show
  1. package/README.md +16 -0
  2. package/package.json +10 -7
  3. package/.turbo/turbo-build.log +0 -38
  4. package/CHANGELOG.md +0 -1829
  5. package/__test__/bpmn-adapter.test.js +0 -227
  6. package/es/materials/curved-edge/__test__/curved-edge.test.d.ts +0 -1
  7. package/es/materials/curved-edge/__test__/curved-edge.test.js +0 -18
  8. package/jest.config.js +0 -198
  9. package/lib/materials/curved-edge/__test__/curved-edge.test.d.ts +0 -1
  10. package/lib/materials/curved-edge/__test__/curved-edge.test.js +0 -20
  11. package/rollup.config.js +0 -52
  12. package/src/NodeResize/BasicShape/Ellipse.tsx +0 -22
  13. package/src/NodeResize/BasicShape/Polygon.tsx +0 -24
  14. package/src/NodeResize/BasicShape/Rect.tsx +0 -44
  15. package/src/NodeResize/control/Control.tsx +0 -537
  16. package/src/NodeResize/control/ControlGroup.tsx +0 -76
  17. package/src/NodeResize/control/Util.ts +0 -206
  18. package/src/NodeResize/index.ts +0 -26
  19. package/src/NodeResize/node/DiamondResize.tsx +0 -149
  20. package/src/NodeResize/node/EllipseResize.tsx +0 -140
  21. package/src/NodeResize/node/HtmlResize.tsx +0 -125
  22. package/src/NodeResize/node/RectResize.tsx +0 -126
  23. package/src/NodeResize/node/index.ts +0 -4
  24. package/src/bpmn/constant.ts +0 -56
  25. package/src/bpmn/events/EndEvent.ts +0 -73
  26. package/src/bpmn/events/StartEvent.ts +0 -52
  27. package/src/bpmn/events/index.ts +0 -2
  28. package/src/bpmn/flow/SequenceFlow.ts +0 -25
  29. package/src/bpmn/flow/index.ts +0 -1
  30. package/src/bpmn/gateways/ExclusiveGateway.ts +0 -71
  31. package/src/bpmn/gateways/index.ts +0 -1
  32. package/src/bpmn/getBpmnId.ts +0 -31
  33. package/src/bpmn/index.ts +0 -60
  34. package/src/bpmn/tasks/ServiceTask.ts +0 -63
  35. package/src/bpmn/tasks/UserTask.ts +0 -64
  36. package/src/bpmn/tasks/index.ts +0 -2
  37. package/src/bpmn-adapter/bpmnIds.ts +0 -31
  38. package/src/bpmn-adapter/index.ts +0 -835
  39. package/src/bpmn-adapter/json2xml.ts +0 -127
  40. package/src/bpmn-adapter/xml2json.ts +0 -544
  41. package/src/bpmn-elements/README.md +0 -223
  42. package/src/bpmn-elements/__tests__/definition.test.js +0 -72
  43. package/src/bpmn-elements/index.d.ts +0 -26
  44. package/src/bpmn-elements/index.ts +0 -107
  45. package/src/bpmn-elements/presets/Event/EndEventFactory.ts +0 -114
  46. package/src/bpmn-elements/presets/Event/IntermediateCatchEvent.ts +0 -108
  47. package/src/bpmn-elements/presets/Event/IntermediateThrowEvent.ts +0 -109
  48. package/src/bpmn-elements/presets/Event/StartEventFactory.ts +0 -114
  49. package/src/bpmn-elements/presets/Event/boundaryEventFactory.ts +0 -117
  50. package/src/bpmn-elements/presets/Event/index.ts +0 -14
  51. package/src/bpmn-elements/presets/Flow/flow.d.ts +0 -6
  52. package/src/bpmn-elements/presets/Flow/index.ts +0 -8
  53. package/src/bpmn-elements/presets/Flow/manhattan.ts +0 -691
  54. package/src/bpmn-elements/presets/Flow/sequenceFlow.ts +0 -65
  55. package/src/bpmn-elements/presets/Gateway/gateway.ts +0 -107
  56. package/src/bpmn-elements/presets/Gateway/index.ts +0 -23
  57. package/src/bpmn-elements/presets/Pool/Lane.ts +0 -211
  58. package/src/bpmn-elements/presets/Pool/Pool.ts +0 -284
  59. package/src/bpmn-elements/presets/Pool/index.ts +0 -89
  60. package/src/bpmn-elements/presets/Task/index.ts +0 -122
  61. package/src/bpmn-elements/presets/Task/subProcess.ts +0 -189
  62. package/src/bpmn-elements/presets/Task/task.ts +0 -193
  63. package/src/bpmn-elements/presets/icons.ts +0 -155
  64. package/src/bpmn-elements/utils.ts +0 -52
  65. package/src/bpmn-elements-adapter/README.md +0 -293
  66. package/src/bpmn-elements-adapter/__tests__/adapter_in.test.js +0 -528
  67. package/src/bpmn-elements-adapter/__tests__/adapter_out.test.js +0 -569
  68. package/src/bpmn-elements-adapter/constant.ts +0 -76
  69. package/src/bpmn-elements-adapter/index.ts +0 -1134
  70. package/src/bpmn-elements-adapter/json2xml.ts +0 -105
  71. package/src/bpmn-elements-adapter/xml2json.ts +0 -542
  72. package/src/components/context-menu/index.ts +0 -253
  73. package/src/components/control/index.ts +0 -155
  74. package/src/components/dnd-panel/index.ts +0 -137
  75. package/src/components/highlight/index.ts +0 -227
  76. package/src/components/menu/index.ts +0 -748
  77. package/src/components/mini-map/index.ts +0 -686
  78. package/src/components/selection-select/index.ts +0 -387
  79. package/src/dynamic-group/index.ts +0 -774
  80. package/src/dynamic-group/model.ts +0 -580
  81. package/src/dynamic-group/node.ts +0 -288
  82. package/src/dynamic-group/utils.ts +0 -46
  83. package/src/index.less +0 -1
  84. package/src/index.ts +0 -47
  85. package/src/insert-node-in-polyline/edge.ts +0 -175
  86. package/src/insert-node-in-polyline/index.ts +0 -193
  87. package/src/materials/curved-edge/__test__/curved-edge.test.ts +0 -46
  88. package/src/materials/curved-edge/index.ts +0 -217
  89. package/src/materials/group/GroupNode.ts +0 -437
  90. package/src/materials/group/index.ts +0 -542
  91. package/src/materials/node-selection/index.ts +0 -380
  92. package/src/mindmap/fakerRoot.ts +0 -19
  93. package/src/mindmap/index.ts +0 -328
  94. package/src/mindmap/markContent.ts +0 -81
  95. package/src/mindmap/markContentOption.ts +0 -81
  96. package/src/mindmap/markEntity.ts +0 -82
  97. package/src/mindmap/markRoot.ts +0 -83
  98. package/src/mindmap/theme.ts +0 -11
  99. package/src/pool/LaneModel.ts +0 -226
  100. package/src/pool/LaneView.ts +0 -220
  101. package/src/pool/PoolModel.ts +0 -631
  102. package/src/pool/PoolView.ts +0 -75
  103. package/src/pool/constant.ts +0 -19
  104. package/src/pool/index.ts +0 -621
  105. package/src/pool/utils.ts +0 -46
  106. package/src/rect-label-node/RectLabelNodeView.ts +0 -33
  107. package/src/rect-label-node/index.ts +0 -15
  108. package/src/style/index.less +0 -381
  109. package/src/style/raw.ts +0 -328
  110. package/src/tools/auto-layout/index.ts +0 -282
  111. package/src/tools/flow-path/index.ts +0 -233
  112. package/src/tools/label/Label.tsx +0 -357
  113. package/src/tools/label/LabelModel.ts +0 -83
  114. package/src/tools/label/LabelOverlay.tsx +0 -162
  115. package/src/tools/label/algorithm.ts +0 -42
  116. package/src/tools/label/index.ts +0 -479
  117. package/src/tools/label/mediumEditor.ts +0 -121
  118. package/src/tools/label/utils.ts +0 -395
  119. package/src/tools/proximity-connect/index.ts +0 -435
  120. package/src/tools/snapshot/README.md +0 -145
  121. package/src/tools/snapshot/index.ts +0 -701
  122. package/src/tools/snapshot/utils.ts +0 -163
  123. package/src/turbo-adapter/index.ts +0 -212
  124. package/stats.html +0 -4842
  125. package/tsconfig.json +0 -18
@@ -1,121 +0,0 @@
1
- import MediumEditor from 'medium-editor'
2
- import Picker from 'vanilla-picker'
3
- import rangy from 'rangy'
4
- import 'rangy/lib/rangy-classapplier'
5
-
6
- export const defaultOptions = {
7
- toolbar: {
8
- allowMultiParagraphSelection: true,
9
- buttons: [
10
- 'bold',
11
- 'colorpicker',
12
- 'italic',
13
- 'underline',
14
- 'strikethrough',
15
- 'quote',
16
- 'justifyLeft',
17
- 'justifyCenter',
18
- 'justifyRight',
19
- 'justifyFull',
20
- 'superscript',
21
- 'subscript',
22
- 'orderedlist',
23
- 'unorderedlist',
24
- 'pre',
25
- 'removeFormat',
26
- 'outdent',
27
- 'indent',
28
- 'h2',
29
- 'h3',
30
- ],
31
- standardizeSelectionStart: false,
32
- updateOnEmptySelection: false,
33
- },
34
-
35
- placeholder: {
36
- text: '请输入内容',
37
- hideOnClick: true,
38
- },
39
- disableEditing: true,
40
- }
41
-
42
- export function createColorPickerButtonClass(MediumEditor?: any) {
43
- const ButtonBase =
44
- MediumEditor?.extensions?.button || MediumEditor?.extensions?.button
45
- const ExtensionBase =
46
- MediumEditor?.Extension || (MediumEditor as any)?.Extension
47
-
48
- // 当 Button 扩展基类不可用时,回退到 Extension 基类,避免在模块加载阶段抛错
49
- const Base = ButtonBase || ExtensionBase
50
- if (!Base) {
51
- console.warn(
52
- 'MediumEditor button/extension base not available; using noop extension',
53
- )
54
- return class {}
55
- }
56
-
57
- return Base.extend({
58
- name: 'colorpicker',
59
- tagNames: ['mark'],
60
- contentDefault: '<b>Color</b>',
61
- aria: 'Color Picker',
62
- action: 'colorPicker',
63
- init: function () {
64
- try {
65
- rangy.init()
66
- } catch {
67
- console.error('rangy.init failed')
68
- }
69
- // 初始化按钮(ButtonBase 才有 prototype.init)
70
- try {
71
- ;(ButtonBase as any)?.prototype?.init?.call(this)
72
- } catch {
73
- console.error('ButtonBase.init failed')
74
- }
75
- this.colorPicker = new Picker({
76
- parent: (this as any).button || undefined,
77
- color: '#000',
78
- onDone: (res) => {
79
- try {
80
- if (this.coloredText && this.coloredText.isAppliedToSelection?.()) {
81
- this.coloredText.undoToSelection()
82
- }
83
- this.coloredText = rangy.createClassApplier('colored', {
84
- elementTagName: 'span',
85
- elementProperties: { style: { color: res.hex } },
86
- normalize: true,
87
- })
88
- this.coloredText.toggleSelection()
89
- this.base?.checkContentChanged?.()
90
- this.setInactive?.()
91
- } catch {
92
- console.error('Picker.onDone failed')
93
- }
94
- },
95
- })
96
- },
97
- getButton: function () {
98
- return (this as any).button
99
- },
100
- handleClick: function () {
101
- this.setActive?.()
102
- this.colorPicker?.show?.()
103
- },
104
- isAlreadyApplied: function (node) {
105
- return node?.nodeName?.toLowerCase?.() === 'mark'
106
- },
107
- isActive: function () {
108
- return (this as any).button?.classList?.contains(
109
- 'medium-editor-button-active',
110
- )
111
- },
112
- setInactive: function () {
113
- ;(this as any).button?.classList?.remove('medium-editor-button-active')
114
- },
115
- setActive: function () {
116
- ;(this as any).button?.classList?.add('medium-editor-button-active')
117
- },
118
- })
119
- }
120
-
121
- export { MediumEditor }
@@ -1,395 +0,0 @@
1
- import LogicFlow, {
2
- BaseEdgeModel,
3
- BaseNodeModel,
4
- getNodeOutline,
5
- getEdgeOutline,
6
- Model,
7
- ModelType,
8
- BezierEdgeModel,
9
- isInSegment,
10
- getBezierPoints,
11
- points2PointsList,
12
- getBBoxOfPoints,
13
- } from '@logicflow/core'
14
- import { head, isEmpty, last, min } from 'lodash-es'
15
- import { calcTwoPointsDistance, getPointOnBezier } from './algorithm'
16
-
17
- import Point = LogicFlow.Point
18
- import LabelConfig = LogicFlow.LabelConfig
19
- import OutlineInfo = Model.OutlineInfo
20
-
21
- export type BBoxInfo = {
22
- x: number
23
- y: number
24
- width: number
25
- height: number
26
- }
27
-
28
- // 工具函数:计算「缩放」后 某坐标点 相对中心位置比例不变的 新坐标点
29
- // 前提条件: 当缩放一个矩形时,如果你希望矩形中的某个点的位置相对于矩形保持不变
30
- //
31
- // 1. 原始矩形的左上角坐标为 (x1, y1),宽度为 w1,高度为 h1。
32
- // 2. 缩放后的矩形的左上角坐标为 (x2, y2),宽度为 w2,高度为 h2。
33
- // 3. 矩形中的某个点在原始矩形中的坐标为 (px1, py1)。
34
- //
35
- // 目标
36
- // 计算该点在缩放后矩形中的新坐标 (px2, py2)。
37
- //
38
- // 步骤
39
- // 1. 计算相对位置:首先计算点 (px1, py1) 在原始矩形中的相对位置。
40
- // relativeX = (px1 - x1) / w1
41
- // relativeY = (py1 - y1) / h1
42
- //
43
- // 2. 计算新坐标:然后,使用相对位置计算该点在缩放后矩形中的新坐标。
44
- // px2 = x2 + relativeX * w2
45
- // py2 = y2 + relativeY * h2
46
- export function calcPointAfterResize(
47
- origin: BBoxInfo,
48
- scaled: BBoxInfo,
49
- point: Point,
50
- ): Point {
51
- const { x: x1, y: y1, width: w1, height: h1 } = origin
52
- const { x: x2, y: y2, width: w2, height: h2 } = scaled
53
- const { x: px1, y: py1 } = point
54
-
55
- // 计算点在原始矩形中的相对位置
56
- const relativeX = (px1 - x1) / w1
57
- const relativeY = (py1 - y1) / h1
58
-
59
- // 计算点在缩放后矩形中的新坐标
60
- const px2 = x2 + relativeX * w2
61
- const py2 = y2 + relativeY * h2
62
-
63
- return { x: px2, y: py2 }
64
- }
65
-
66
- // 工具函数:计算「旋转」后 某坐标点 相对中心位置比例不变的 新坐标点
67
- // 要计算以点 x1 = (x1, y1) 为中心,点 x2 = (x2, y2) 旋转 θ 度后的坐标位置,可以使用旋转矩阵进行计算。
68
- //
69
- // 旋转公式如下:
70
- // 1. 首先将点 x2 平移到以 x1 为原点的坐标系:
71
- // x' = x2 - x1
72
- // y' = y2 - y1
73
- // 2. 然后应用旋转矩阵进行旋转:
74
- // x'' = x' * cos(θ) - y' * sin(θ)
75
- // y'' = x' * sin(θ) + y' * cos(θ)
76
- // 3. 最后将结果平移回原来的坐标系:
77
- // x_new = x'' + x1
78
- // y_new = y'' + y1
79
- //
80
- // 综合起来,旋转后的新坐标 (x_new, y_new) 计算公式如下:
81
- //
82
- // x_new = (x2 - x1) * cos(θ) - (y2 - y1) * sin(θ) + x1
83
- // y_new = (x2 - x1) * sin(θ) + (y2 - y1) * cos(θ) + y1
84
- //
85
- // 其中,θ 需要用弧度表示,如果你有的是角度,可以用以下公式转换为弧度:
86
- //
87
- // rad = deg * π / 180
88
- export function rotatePointAroundCenter(
89
- target: Point,
90
- center: Point,
91
- radian: number,
92
- ): Point {
93
- // Rotate point (x2, y2) around point (x1, y1) by theta degrees.
94
- //
95
- // Parameters:
96
- // x1, y1: Coordinates of the center point.
97
- // x2, y2: Coordinates of the point to rotate.
98
- // theta_degrees: Angle in degrees to rotate the point.
99
- //
100
- // Returns:
101
- // Tuple of new coordinates (x_new, y_new) after rotation.
102
-
103
- const { x: x1, y: y1 } = center
104
- const { x: x2, y: y2 } = target
105
-
106
- // Translate point to origin
107
- const xPrime = x2 - x1
108
- const yPrime = y2 - y1
109
-
110
- // Rotate point
111
- const xDoublePrime = xPrime * Math.cos(radian) - yPrime * Math.sin(radian)
112
- const yDoublePrime = xPrime * Math.sin(radian) + yPrime * Math.cos(radian)
113
-
114
- // Translate point back
115
- const xNew = xDoublePrime + x1
116
- const yNew = yDoublePrime + y1
117
-
118
- return {
119
- x: xNew,
120
- y: yNew,
121
- }
122
- }
123
-
124
- /** Edge 相关工具方法 */
125
-
126
- /**
127
- * 获取某点在一个矩形图形(节点 or 边的 outline)内的偏移量
128
- * @param point 目标点(此处即 Label 的坐标信息)
129
- * @param element 目标元素
130
- */
131
- export const getPointOffsetOfElementOutline = (
132
- point: Point,
133
- element: BaseNodeModel | BaseEdgeModel,
134
- ) => {
135
- const baseType = element.BaseType
136
- const bboxInfo: OutlineInfo | undefined =
137
- baseType === 'node' ? getNodeOutline(element) : getEdgeOutline(element)
138
-
139
- if (bboxInfo) {
140
- const { x, y } = point
141
- const { x: minX, y: minY, x1: maxX, y1: maxY } = bboxInfo
142
- let xDeltaPercent: number = 0.5
143
- let yDeltaPercent: number = 0.5
144
- let xDeltaDistance: number = x - maxX
145
- let yDeltaDistance: number = y - maxY
146
- /**
147
- * 文本在由路径点组成的凸包内,就记录偏移比例
148
- * 文本在凸包外,记录绝对距离
149
- * 用于边路径变化时计算文本新位置
150
- */
151
- if (minX && maxX && minX < x && x < maxX) {
152
- xDeltaPercent = min([(x - minX) / (maxX - minX), 1]) as number
153
- } else if (x <= minX) {
154
- xDeltaDistance = x - minX
155
- } else {
156
- xDeltaDistance = x - maxX
157
- }
158
- if (minY && maxY && minY < y && y < maxY) {
159
- yDeltaPercent = min([(y - minY) / (maxY - minY), 1]) as number
160
- } else if (y <= minY) {
161
- yDeltaDistance = y - minY
162
- } else {
163
- yDeltaDistance = y - maxY
164
- }
165
- return {
166
- xDeltaPercent,
167
- yDeltaPercent,
168
- xDeltaDistance,
169
- yDeltaDistance,
170
- }
171
- }
172
- }
173
-
174
- /**
175
- * 判断节点是否在折线上
176
- * @param point 目标点坐标
177
- * @param points 折线上的点坐标
178
- */
179
- const isPointOnPolyline = (point: Point, points: Point[]): boolean => {
180
- for (let i = 0; i < points.length - 1; i++) {
181
- const start = points[i]
182
- const end = points[i + 1]
183
- if (isInSegment(point, start, end)) {
184
- return true
185
- }
186
- }
187
-
188
- return false
189
- }
190
-
191
- /**
192
- * 给定一个点 P = (x_0, y_0) 和线段的两个端点 A = (x_1, y_1) 和 B = (x_2, y_2) ,可以使用以下步骤计算点到线段的距离:
193
- * 1. 计算向量 AB 和 AP 。
194
- * 2. 计算 AB 的平方长度。
195
- * 3. 计算点 P 在直线 AB 上的投影点 Q 。
196
- * 4. 判断 Q 是否在线段 AB 上。
197
- * 5. 根据 Q 是否在线段上,计算点到线段的距离。
198
- *
199
- * 计算点到线段质检的距离
200
- * @param point
201
- * @param start
202
- * @param end
203
- */
204
- export const pointToSegmentDistance = (
205
- point: Point,
206
- start: Point,
207
- end: Point,
208
- ): number => {
209
- const { x: px, y: py } = point
210
- const { x: sx, y: sy } = start
211
- const { x: ex, y: ey } = end
212
-
213
- const SEx = ex - sx
214
- const SEy = ey - sy
215
- const SPx = px - sx
216
- const SPy = py - sy
217
-
218
- const SE_SE = SEx ** 2 + SEy ** 2
219
- const SP_SE = SPx * SEx + SPy * SEy
220
- let t = SP_SE / SE_SE
221
- if (t < 0) t = 0
222
- if (t > 1) t = 1
223
-
224
- const qx = sx + t * SEx
225
- const qy = sy + t * SEy
226
- return Math.sqrt((px - qx) ** 2 + (py - qy) ** 2)
227
- }
228
-
229
- export const calcPolylineTotalLength = (points: Point[]) => {
230
- let length = 0
231
- for (let i = 0; i < points.length - 1; i++) {
232
- const start = points[i]
233
- const end = points[i + 1]
234
- length += calcTwoPointsDistance(start, end)
235
- }
236
- return length
237
- }
238
-
239
- /**
240
- * TODO: 确认该函数的意义,写完还是没看懂什么意思
241
- * @param point
242
- * @param points
243
- */
244
- export const pointPositionRatio = (point: Point, points: Point[]): number => {
245
- let length = 0
246
- for (let i = 0; i < points.length - 1; i++) {
247
- const start = points[i]
248
- const end = points[i + 1]
249
- const segmentLength = calcTwoPointsDistance(start, end)
250
-
251
- if (pointToSegmentDistance(point, start, end) <= 20) {
252
- const d1 = calcTwoPointsDistance(point, start)
253
- length += d1
254
- const totalLength = calcPolylineTotalLength(points)
255
- // 小数点后保留一位(四舍五入)
256
- return Math.round((length / totalLength) * 10) / 10
257
- } else {
258
- length += segmentLength
259
- }
260
- }
261
- return 0
262
- }
263
-
264
- /**
265
- * 计算一个坐标在贝塞尔曲线上最近的一个点
266
- * @param point
267
- * @param edge
268
- * @param step
269
- */
270
- export const calcClosestPointOnBezierEdge = (
271
- point: Point,
272
- edge: BezierEdgeModel,
273
- step: number = 5,
274
- ): Point => {
275
- let minDistance = Infinity
276
- let closestPoint: Point = point
277
-
278
- const pointsList = getBezierPoints(edge.path)
279
- if (isEmpty(pointsList)) return closestPoint
280
-
281
- const [start, sNext, ePre, end] = pointsList
282
- for (let i = 0; i <= step; i++) {
283
- const t = i / step
284
- const bezierPoint = getPointOnBezier(t, start, sNext, ePre, end)
285
- const distance = calcTwoPointsDistance(point, bezierPoint)
286
- if (distance < minDistance) {
287
- minDistance = distance
288
- closestPoint = bezierPoint
289
- }
290
- }
291
-
292
- return closestPoint
293
- }
294
-
295
- export const getNewPointAtDistance = (
296
- points: Point[],
297
- ratio: number,
298
- ): Point | undefined => {
299
- const totalLength = calcPolylineTotalLength(points)
300
- const targetLength = totalLength * ratio
301
-
302
- let length = 0
303
- for (let i = 0; i < points.length - 1; i++) {
304
- const start = points[i]
305
- const end = points[i + 1]
306
- const segmentLength = calcTwoPointsDistance(start, end)
307
- if (length + segmentLength >= targetLength) {
308
- const ratio = (targetLength - length) / segmentLength
309
- return {
310
- x: start.x + (end.x - start.x) * ratio,
311
- y: start.y + (end.y - start.y) * ratio,
312
- }
313
- } else {
314
- length += segmentLength
315
- }
316
- }
317
- return last(points)
318
- }
319
-
320
- /**
321
- * 计算一个坐标离折线(包括 PolylineEdge 和 LineEdge 直线)最近的一个点
322
- * @param point
323
- * @param edge
324
- */
325
- export const calcLabelPositionOnPolyline = (
326
- point: Point,
327
- edge: BaseEdgeModel,
328
- ): Point => {
329
- let points = points2PointsList(edge.points)
330
- if (points.length === 0) {
331
- points = [edge.startPoint, edge.endPoint]
332
- }
333
-
334
- const { xDeltaPercent, yDeltaPercent, yDeltaDistance, xDeltaDistance } =
335
- getPointOffsetOfElementOutline(point, edge) ?? {}
336
- const isPointOnEdge = isPointOnPolyline(point, points)
337
- const ratio = pointPositionRatio(point, points)
338
-
339
- const start = head(points)
340
- const end = last(points)
341
-
342
- // 分别取路径中,x轴 和 y轴上的最大最小坐标值组合成一个矩形
343
- const { minX, minY, maxX, maxY } = getBBoxOfPoints(points, 10)
344
-
345
- if (!start || !end) return point
346
-
347
- if (xDeltaPercent && yDeltaPercent) {
348
- const positByPercent = {
349
- x: minX + (maxX - minX) * xDeltaPercent,
350
- y: minY + (maxY - minY) * yDeltaPercent,
351
- }
352
- return isPointOnEdge
353
- ? (getNewPointAtDistance(points, ratio) ?? point) // 函数什么意思
354
- : positByPercent
355
- }
356
- // 如果文本在凸包的上方或者下方
357
- if (xDeltaPercent && yDeltaDistance) {
358
- return {
359
- x: minX + (maxX - minX) * xDeltaPercent,
360
- y: yDeltaDistance < 0 ? minY + yDeltaDistance : maxY + yDeltaDistance,
361
- }
362
- }
363
- // 如果文本在凸包的左边或者右边
364
- if (yDeltaPercent && xDeltaDistance) {
365
- return {
366
- x: xDeltaDistance < 0 ? minX + xDeltaDistance : maxX + xDeltaDistance,
367
- y: minY + (maxY - minY) * yDeltaPercent,
368
- }
369
- }
370
- // 如果文本在凸包左上/左下/右上/右下
371
- if (xDeltaDistance && yDeltaDistance) {
372
- return {
373
- x: xDeltaDistance < 0 ? minX + xDeltaDistance : maxX + xDeltaDistance,
374
- y: yDeltaDistance < 0 ? minY + yDeltaDistance : maxY + yDeltaDistance,
375
- }
376
- }
377
- // 兜底
378
- return point
379
- }
380
-
381
- /**
382
- * 计算 Label 离边最近的点的坐标,用于更新为 Label 的坐标
383
- * @param label LabelConfig -> 当前 Label 的配置项
384
- * @param edge
385
- */
386
- export const getLabelPositionOfLine = (
387
- label: LabelConfig,
388
- edge: BaseEdgeModel,
389
- ): Point => {
390
- const { x, y } = label
391
- if (edge.modelType === ModelType.BEZIER_EDGE) {
392
- return calcClosestPointOnBezierEdge({ x, y }, edge as BezierEdgeModel)
393
- }
394
- return calcLabelPositionOnPolyline({ x, y }, edge)
395
- }