aldehyde 0.2.473 → 0.2.475

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 (203) hide show
  1. package/lib/controls/action/utils.d.ts +1 -1
  2. package/lib/controls/entity-select/entity-select.d.ts +2 -2
  3. package/lib/controls/entity-select/entity-select.d.ts.map +1 -1
  4. package/lib/controls/entity-select/entity-select.js +16 -7
  5. package/lib/controls/entity-select/entity-select.js.map +1 -1
  6. package/lib/controls/entry-control.d.ts.map +1 -1
  7. package/lib/controls/entry-control.js +3 -2
  8. package/lib/controls/entry-control.js.map +1 -1
  9. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.css +47 -3
  10. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.js +12 -12
  11. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.js.map +1 -1
  12. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.json +77 -0
  13. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.ttf +0 -0
  14. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff +0 -0
  15. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff2 +0 -0
  16. package/lib/controls/select/index.d.ts.map +1 -1
  17. package/lib/controls/select/index.js +13 -7
  18. package/lib/controls/select/index.js.map +1 -1
  19. package/lib/controls/text/index.less +1 -0
  20. package/lib/controls/view-control.d.ts.map +1 -1
  21. package/lib/controls/view-control.js +1 -0
  22. package/lib/controls/view-control.js.map +1 -1
  23. package/lib/detail/button/edit-button.d.ts.map +1 -1
  24. package/lib/detail/button/edit-button.js +23 -11
  25. package/lib/detail/button/edit-button.js.map +1 -1
  26. package/lib/detail/button/view-button.d.ts.map +1 -1
  27. package/lib/detail/button/view-button.js +21 -10
  28. package/lib/detail/button/view-button.js.map +1 -1
  29. package/lib/draw-canvas/edit/components/asset-bar/index.d.ts +5 -0
  30. package/lib/draw-canvas/edit/components/asset-bar/index.d.ts.map +1 -0
  31. package/lib/draw-canvas/edit/components/asset-bar/index.js +79 -0
  32. package/lib/draw-canvas/edit/components/asset-bar/index.js.map +1 -0
  33. package/lib/draw-canvas/edit/components/asset-bar/index.less +36 -0
  34. package/lib/draw-canvas/edit/components/main-header/index.d.ts +19 -0
  35. package/lib/draw-canvas/edit/components/main-header/index.d.ts.map +1 -0
  36. package/lib/draw-canvas/edit/components/main-header/index.js +203 -0
  37. package/lib/draw-canvas/edit/components/main-header/index.js.map +1 -0
  38. package/lib/draw-canvas/edit/components/main-header/index.less +21 -0
  39. package/lib/draw-canvas/edit/components/render/index.d.ts +90 -0
  40. package/lib/draw-canvas/edit/components/render/index.d.ts.map +1 -0
  41. package/lib/draw-canvas/edit/components/render/index.js +692 -0
  42. package/lib/draw-canvas/edit/components/render/index.js.map +1 -0
  43. package/lib/draw-canvas/edit/components/render/types.d.ts +247 -0
  44. package/lib/draw-canvas/edit/components/render/types.d.ts.map +1 -0
  45. package/lib/draw-canvas/edit/components/render/types.js +66 -0
  46. package/lib/draw-canvas/edit/components/render/types.js.map +1 -0
  47. package/lib/draw-canvas/edit/components/setting-form/imag-upload.d.ts +26 -0
  48. package/lib/draw-canvas/edit/components/setting-form/imag-upload.d.ts.map +1 -0
  49. package/lib/draw-canvas/edit/components/setting-form/imag-upload.js +83 -0
  50. package/lib/draw-canvas/edit/components/setting-form/imag-upload.js.map +1 -0
  51. package/lib/draw-canvas/edit/components/setting-form/index.d.ts +17 -0
  52. package/lib/draw-canvas/edit/components/setting-form/index.d.ts.map +1 -0
  53. package/lib/draw-canvas/edit/components/setting-form/index.js +243 -0
  54. package/lib/draw-canvas/edit/components/setting-form/index.js.map +1 -0
  55. package/lib/draw-canvas/edit/constant.d.ts +7 -0
  56. package/lib/draw-canvas/edit/constant.d.ts.map +1 -0
  57. package/lib/draw-canvas/edit/constant.js +7 -0
  58. package/lib/draw-canvas/edit/constant.js.map +1 -0
  59. package/lib/draw-canvas/edit/index.d.ts +8 -0
  60. package/lib/draw-canvas/edit/index.d.ts.map +1 -0
  61. package/lib/draw-canvas/edit/index.js +165 -0
  62. package/lib/draw-canvas/edit/index.js.map +1 -0
  63. package/lib/draw-canvas/edit/index.less +49 -0
  64. package/lib/draw-canvas/view/index.d.ts +8 -0
  65. package/lib/draw-canvas/view/index.d.ts.map +1 -0
  66. package/lib/draw-canvas/view/index.js +50 -0
  67. package/lib/draw-canvas/view/index.js.map +1 -0
  68. package/lib/draw-canvas/view/index.less +60 -0
  69. package/lib/draw-canvas/view/view.d.ts +10 -0
  70. package/lib/draw-canvas/view/view.d.ts.map +1 -0
  71. package/lib/draw-canvas/view/view.js +104 -0
  72. package/lib/draw-canvas/view/view.js.map +1 -0
  73. package/lib/form/form-Item-group.d.ts.map +1 -1
  74. package/lib/form/form-Item-group.js +4 -4
  75. package/lib/form/form-Item-group.js.map +1 -1
  76. package/lib/icon/local-aliIcon/iconfont.js +5 -5
  77. package/lib/icon/local-aliIcon/iconfont.js.map +1 -1
  78. package/lib/lowcode-components/index.d.ts +2 -0
  79. package/lib/lowcode-components/index.d.ts.map +1 -1
  80. package/lib/lowcode-components/index.js +2 -1
  81. package/lib/lowcode-components/index.js.map +1 -1
  82. package/lib/lowcode-components/lowcode-view/component/assets.d.ts.map +1 -1
  83. package/lib/lowcode-components/lowcode-view/component/assets.js +8 -0
  84. package/lib/lowcode-components/lowcode-view/component/assets.js.map +1 -1
  85. package/lib/lowcode-components/radar-chart/index.d.ts +51 -0
  86. package/lib/lowcode-components/radar-chart/index.d.ts.map +1 -0
  87. package/lib/lowcode-components/radar-chart/index.js +276 -0
  88. package/lib/lowcode-components/radar-chart/index.js.map +1 -0
  89. package/lib/module/dtmpl-edit-card.d.ts.map +1 -1
  90. package/lib/module/dtmpl-edit-card.js +18 -1
  91. package/lib/module/dtmpl-edit-card.js.map +1 -1
  92. package/lib/module/dtmpl-edit-page.d.ts.map +1 -1
  93. package/lib/module/dtmpl-edit-page.js +19 -2
  94. package/lib/module/dtmpl-edit-page.js.map +1 -1
  95. package/lib/routable/ltmpl-route.d.ts +2 -0
  96. package/lib/routable/ltmpl-route.d.ts.map +1 -1
  97. package/lib/routable/ltmpl-route.js +20 -4
  98. package/lib/routable/ltmpl-route.js.map +1 -1
  99. package/lib/table/act-table.d.ts +2 -0
  100. package/lib/table/act-table.d.ts.map +1 -1
  101. package/lib/table/act-table.js +4 -4
  102. package/lib/table/act-table.js.map +1 -1
  103. package/lib/table/column/column-builder.d.ts.map +1 -1
  104. package/lib/table/column/column-builder.js +23 -8
  105. package/lib/table/column/column-builder.js.map +1 -1
  106. package/lib/table/relation-table.d.ts +7 -0
  107. package/lib/table/relation-table.d.ts.map +1 -1
  108. package/lib/tmpl/control-type-supportor.d.ts.map +1 -1
  109. package/lib/tmpl/control-type-supportor.js +1 -0
  110. package/lib/tmpl/control-type-supportor.js.map +1 -1
  111. package/lib/tmpl/hcservice-v3.d.ts +3 -0
  112. package/lib/tmpl/hcservice-v3.d.ts.map +1 -1
  113. package/lib/tmpl/hcservice-v3.js +61 -0
  114. package/lib/tmpl/hcservice-v3.js.map +1 -1
  115. package/lib/tmpl/interface.d.ts +17 -1
  116. package/lib/tmpl/interface.d.ts.map +1 -1
  117. package/lib/tmpl/interface.js.map +1 -1
  118. package/lib/tmpl/tmpl-config-analysis.js +1 -1
  119. package/lib/tmpl/tmpl-config-analysis.js.map +1 -1
  120. package/lib/units/index.d.ts +3 -1
  121. package/lib/units/index.d.ts.map +1 -1
  122. package/lib/units/index.js +33 -3
  123. package/lib/units/index.js.map +1 -1
  124. package/package.json +4 -1
  125. package/src/aldehyde/controls/entity-select/entity-select.tsx +18 -8
  126. package/src/aldehyde/controls/entry-control.tsx +3 -2
  127. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.css +47 -3
  128. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.js +1 -1
  129. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.json +77 -0
  130. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.ttf +0 -0
  131. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff +0 -0
  132. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff2 +0 -0
  133. package/src/aldehyde/controls/select/index.tsx +7 -6
  134. package/src/aldehyde/controls/text/index.less +1 -0
  135. package/src/aldehyde/controls/view-control.tsx +1 -0
  136. package/src/aldehyde/detail/button/edit-button.tsx +21 -22
  137. package/src/aldehyde/detail/button/view-button.tsx +23 -21
  138. package/src/aldehyde/draw-canvas/edit/components/asset-bar/index.less +36 -0
  139. package/src/aldehyde/draw-canvas/edit/components/asset-bar/index.tsx +95 -0
  140. package/src/aldehyde/draw-canvas/edit/components/main-header/index.less +21 -0
  141. package/src/aldehyde/draw-canvas/edit/components/main-header/index.tsx +233 -0
  142. package/src/aldehyde/draw-canvas/edit/components/render/draws/bg-draw.ts +163 -0
  143. package/src/aldehyde/draw-canvas/edit/components/render/draws/contextmenu-draw.ts +307 -0
  144. package/src/aldehyde/draw-canvas/edit/components/render/draws/graph-draw.ts +251 -0
  145. package/src/aldehyde/draw-canvas/edit/components/render/draws/index.ts +7 -0
  146. package/src/aldehyde/draw-canvas/edit/components/render/draws/link-draw.ts +1416 -0
  147. package/src/aldehyde/draw-canvas/edit/components/render/draws/preview-draw.ts +275 -0
  148. package/src/aldehyde/draw-canvas/edit/components/render/draws/ref-line-draw.ts +72 -0
  149. package/src/aldehyde/draw-canvas/edit/components/render/draws/ruler-draw.ts +167 -0
  150. package/src/aldehyde/draw-canvas/edit/components/render/graphs/base-graph.ts +241 -0
  151. package/src/aldehyde/draw-canvas/edit/components/render/graphs/bezier.ts +542 -0
  152. package/src/aldehyde/draw-canvas/edit/components/render/graphs/circle.ts +700 -0
  153. package/src/aldehyde/draw-canvas/edit/components/render/graphs/curve.ts +501 -0
  154. package/src/aldehyde/draw-canvas/edit/components/render/graphs/index.ts +6 -0
  155. package/src/aldehyde/draw-canvas/edit/components/render/graphs/line.ts +494 -0
  156. package/src/aldehyde/draw-canvas/edit/components/render/graphs/rect.ts +681 -0
  157. package/src/aldehyde/draw-canvas/edit/components/render/handlers/drag-handlers.ts +69 -0
  158. package/src/aldehyde/draw-canvas/edit/components/render/handlers/drag-outside-handlers.ts +159 -0
  159. package/src/aldehyde/draw-canvas/edit/components/render/handlers/graph-handlers.ts +108 -0
  160. package/src/aldehyde/draw-canvas/edit/components/render/handlers/index.ts +9 -0
  161. package/src/aldehyde/draw-canvas/edit/components/render/handlers/key-move-handlers.ts +50 -0
  162. package/src/aldehyde/draw-canvas/edit/components/render/handlers/link-handlers.ts +46 -0
  163. package/src/aldehyde/draw-canvas/edit/components/render/handlers/selection-handlers.ts +393 -0
  164. package/src/aldehyde/draw-canvas/edit/components/render/handlers/shutcut-handlers.ts +46 -0
  165. package/src/aldehyde/draw-canvas/edit/components/render/handlers/text-handlers.ts +82 -0
  166. package/src/aldehyde/draw-canvas/edit/components/render/handlers/zoom-handlers.ts +60 -0
  167. package/src/aldehyde/draw-canvas/edit/components/render/index.ts +776 -0
  168. package/src/aldehyde/draw-canvas/edit/components/render/tools/align-tool.ts +91 -0
  169. package/src/aldehyde/draw-canvas/edit/components/render/tools/asset-tool.ts +142 -0
  170. package/src/aldehyde/draw-canvas/edit/components/render/tools/attract-tool.ts +440 -0
  171. package/src/aldehyde/draw-canvas/edit/components/render/tools/copy-tool.ts +269 -0
  172. package/src/aldehyde/draw-canvas/edit/components/render/tools/import-export-tool.ts +603 -0
  173. package/src/aldehyde/draw-canvas/edit/components/render/tools/index.ts +9 -0
  174. package/src/aldehyde/draw-canvas/edit/components/render/tools/link-tool.ts +225 -0
  175. package/src/aldehyde/draw-canvas/edit/components/render/tools/position-tool.ts +194 -0
  176. package/src/aldehyde/draw-canvas/edit/components/render/tools/selection-tool.ts +132 -0
  177. package/src/aldehyde/draw-canvas/edit/components/render/tools/z-index-tool.ts +227 -0
  178. package/src/aldehyde/draw-canvas/edit/components/render/types.ts +291 -0
  179. package/src/aldehyde/draw-canvas/edit/components/render/utils/a-star.ts +116 -0
  180. package/src/aldehyde/draw-canvas/edit/components/render/utils/bezier-scene-func.ts +73 -0
  181. package/src/aldehyde/draw-canvas/edit/components/setting-form/imag-upload.tsx +118 -0
  182. package/src/aldehyde/draw-canvas/edit/components/setting-form/index.tsx +295 -0
  183. package/src/aldehyde/draw-canvas/edit/constant.ts +6 -0
  184. package/src/aldehyde/draw-canvas/edit/index.less +49 -0
  185. package/src/aldehyde/draw-canvas/edit/index.tsx +197 -0
  186. package/src/aldehyde/draw-canvas/view/index.less +60 -0
  187. package/src/aldehyde/draw-canvas/view/index.tsx +48 -0
  188. package/src/aldehyde/draw-canvas/view/view.tsx +114 -0
  189. package/src/aldehyde/form/form-Item-group.tsx +5 -5
  190. package/src/aldehyde/icon/local-aliIcon/iconfont.js +1 -1
  191. package/src/aldehyde/lowcode-components/index.ts +4 -2
  192. package/src/aldehyde/lowcode-components/lowcode-view/component/assets.ts +8 -0
  193. package/src/aldehyde/lowcode-components/radar-chart/index.tsx +323 -0
  194. package/src/aldehyde/module/dtmpl-edit-card.tsx +18 -1
  195. package/src/aldehyde/module/dtmpl-edit-page.tsx +19 -2
  196. package/src/aldehyde/routable/ltmpl-route.tsx +39 -3
  197. package/src/aldehyde/table/act-table.tsx +7 -4
  198. package/src/aldehyde/table/column/column-builder.tsx +29 -9
  199. package/src/aldehyde/tmpl/control-type-supportor.tsx +1 -0
  200. package/src/aldehyde/tmpl/hcservice-v3.tsx +44 -0
  201. package/src/aldehyde/tmpl/interface.tsx +15 -1
  202. package/src/aldehyde/tmpl/tmpl-config-analysis.tsx +1 -1
  203. package/src/aldehyde/units/index.tsx +31 -3
@@ -0,0 +1,542 @@
1
+ import Konva from 'konva';
2
+ import { GraphAnchor, Render, AssetInfoPoint, LineManualPoint } from '../types';
3
+ import { GraphDraw, LinkDraw, PreviewDraw } from '../draws';
4
+ import { BaseGraph } from './base-graph';
5
+ import { BezierSceneFunc } from '../utils/bezier-scene-func';
6
+
7
+ /**
8
+ * 贝赛尔曲线
9
+ */
10
+
11
+ export class Bezier extends BaseGraph {
12
+ // 实现:更新 图形 的 调整点 的 锚点位置
13
+ static override updateAnchorShadows(graph: Konva.Group, anchorShadows: Konva.Circle[], shape?: Konva.Line): void {
14
+ if (shape) {
15
+ const points = shape.points();
16
+ for (const shadow of anchorShadows) {
17
+ switch (shadow.attrs.adjustType) {
18
+ case 'start':
19
+ shadow.position({ x: points[0], y: points[1] });
20
+ break;
21
+ case 'end':
22
+ shadow.position({ x: points[points.length - 2], y: points[points.length - 1] });
23
+ break;
24
+ }
25
+ }
26
+ }
27
+ }
28
+ // 实现:更新 图形 的 连接点 的 锚点位置
29
+ static override updateLinkAnchorShadows(graph: Konva.Group, linkAnchorShadows: Konva.Circle[], shape?: Konva.Line): void {
30
+ if (shape) {
31
+ const points = shape.points();
32
+ for (const shadow of linkAnchorShadows) {
33
+ switch (shadow.attrs.alias) {
34
+ case 'start':
35
+ shadow.position({ x: points[0], y: points[1] });
36
+ break;
37
+ case 'end':
38
+ shadow.position({ x: points[points.length - 2], y: points[points.length - 1] });
39
+ break;
40
+ }
41
+ }
42
+ }
43
+ }
44
+
45
+ static calculateAngle(sideA: number, sideB: number) {
46
+ if (!isNaN(sideA) && !isNaN(sideB)) {
47
+ const angleInRadians = Math.atan2(sideA, sideB);
48
+ const angleInDegrees = angleInRadians * (180 / Math.PI);
49
+ return angleInDegrees;
50
+ }
51
+ return 0;
52
+ }
53
+
54
+ // 实现:生成 调整点
55
+ static override createAnchorShapes(
56
+ render: Render,
57
+ graph: Konva.Group,
58
+ anchorAndShadows: {
59
+ anchor: GraphAnchor,
60
+ anchorShadow: Konva.Circle,
61
+ shape?: Konva.Shape
62
+ }[],
63
+ adjustAnchor?: GraphAnchor
64
+ ): { anchorAndShadows: { anchor: GraphAnchor, anchorShadow: Konva.Circle, shape?: Konva.Shape | undefined }[] } {
65
+ const stageState = render.getStageState();
66
+ const graphShape = graph.findOne('.graph') as Konva.Line;
67
+ if (graphShape) {
68
+ const points = graphShape.points();
69
+ for (const anchorAndShadow of anchorAndShadows) {
70
+ let rotate = 0;
71
+ const { anchor, anchorShadow } = anchorAndShadow;
72
+ const x = render.toStageValue(anchorShadow.getAbsolutePosition().x - stageState.x);
73
+ const y = render.toStageValue(anchorShadow.getAbsolutePosition().y - stageState.y);
74
+ if (anchor.adjustType === 'manual') {
75
+ const anchorShape = new Konva.Circle({
76
+ name: 'anchor',
77
+ anchor: anchor,
78
+ fill: anchor.adjusted ? `rgba(0,0,0,0.4)` : `rgba(0,0,255,0.4)`,
79
+ radius: render.toStageValue(5),
80
+ strokeWidth: 0,
81
+ x: x,
82
+ y: y,
83
+ rotation: graph.getAbsoluteRotation(),
84
+ // 阻止多余的调整点出现
85
+ visible:
86
+ (graph.attrs.adjusting || graph.attrs.hover === true) &&
87
+ (anchor.adjusted || anchorAndShadows.length <= 6)
88
+ });
89
+ anchorShape.on('mouseenter', () => {
90
+ document.body.style.cursor = 'move';
91
+ graph.setAttr('hover', true);
92
+ graph.setAttr('hoverAnchor', true);
93
+ });
94
+ anchorShape.on('mouseleave', () => {
95
+ document.body.style.cursor = anchorShape.attrs.adjusting ? 'move' : 'default';
96
+ graph.setAttr('hover', false);
97
+ graph.setAttr('hoverAnchor', false);
98
+ // 进入其他元素区域时离开需要靠它 redraw
99
+ render.redraw([GraphDraw.name]);
100
+ });
101
+ anchorAndShadow.shape = anchorShape;
102
+ } else {
103
+ if (anchor.adjustType === 'start') {
104
+ rotate = Bezier.calculateAngle(points[2] - points[0], points[3] - points[1]);
105
+ } else if (anchor.adjustType === 'end') {
106
+ rotate = Bezier.calculateAngle(
107
+ points[points.length - 2] - points[points.length - 4],
108
+ points[points.length - 1] - points[points.length - 3]
109
+ );
110
+ }
111
+ const cos = Math.cos((rotate * Math.PI) / 180);
112
+ const sin = Math.sin((rotate * Math.PI) / 180);
113
+ const offset = render.toStageValue(render.pointSize - 20);
114
+ const offsetX = offset * sin;
115
+ const offsetY = offset * cos;
116
+ const anchorShape = new Konva.Circle({
117
+ name: 'anchor',
118
+ anchor: anchor,
119
+ fill: `rgba(0,0,255,0.4)`,
120
+ radius: render.toStageValue(5),
121
+ strokeWidth: 0,
122
+ // 位置
123
+ x: x,
124
+ y: y,
125
+ offsetX:
126
+ anchor.adjustType === 'start' ? offsetX : anchor.adjustType === 'end' ? -offsetX : 0,
127
+ offsetY:
128
+ anchor.adjustType === 'start' ? offsetY : anchor.adjustType === 'end' ? -offsetY : 0,
129
+ // 旋转角度
130
+ rotation: graph.getAbsoluteRotation(),
131
+ visible: graph.attrs.adjusting || graph.attrs.hover === true
132
+ });
133
+ anchorShape.on('mouseenter', () => {
134
+ document.body.style.cursor = 'move';
135
+ graph.setAttr('hover', true);
136
+ graph.setAttr('hoverAnchor', true);
137
+ });
138
+ anchorShape.on('mouseleave', () => {
139
+ document.body.style.cursor = anchorShape.attrs.adjusting ? 'move' : 'default';
140
+ graph.setAttr('hover', false);
141
+ graph.setAttr('hoverAnchor', false);
142
+ // 进入其他元素区域时离开需要靠它 redraw
143
+ render.redraw([GraphDraw.name]);
144
+ });
145
+ anchorAndShadow.shape = anchorShape;
146
+ }
147
+ }
148
+ }
149
+ return { anchorAndShadows };
150
+ }
151
+
152
+ /**
153
+ * 矩阵变换:坐标系中的一个点,围绕着另外一个点进行旋转
154
+ * - - - - - - - -
155
+ * |x`| |cos -sin| |x-a| |a|
156
+ * | | = | | | | +
157
+ * |y`| |sin cos| |y-b| |b|
158
+ * - - - - - - - -
159
+ * @param x 目标节点坐标 x
160
+ * @param y 目标节点坐标 y
161
+ * @param centerX 围绕的点坐标 x
162
+ * @param centerY 围绕的点坐标 y
163
+ * @param angle 旋转角度
164
+ * @returns
165
+ */
166
+ static rotatePoint(x: number, y: number, centerX: number, centerY: number, angle: number) {
167
+ // 将角度转换为弧度
168
+ const radians = (angle * Math.PI) / 180;
169
+ // 计算旋转后的坐标
170
+ const newX = Math.cos(radians) * (x - centerX) - Math.sin(radians) * (y - centerY) + centerX;
171
+ const newY = Math.sin(radians) * (x - centerX) + Math.cos(radians) * (y - centerY) + centerY;
172
+ return { x: newX, y: newY };
173
+ }
174
+
175
+ // 实现:调整 图形
176
+ static override adjust(
177
+ render: Render,
178
+ graph: Konva.Group,
179
+ graphSnap: Konva.Group,
180
+ adjustShape: Konva.Shape,
181
+ anchorAndShadows: {
182
+ anchor: GraphAnchor,
183
+ anchorShadow: Konva.Circle,
184
+ shape?: Konva.Shape | undefined,
185
+ }[],
186
+ startPoint: Konva.Vector2d,
187
+ endPoint: Konva.Vector2d,
188
+ hoverRect?: Konva.Rect
189
+ ) {
190
+ // 目标 曲线
191
+ const line = graph.findOne('.graph') as Konva.Line;
192
+ // 镜像
193
+ const lineSnap = graphSnap.findOne('.graph') as Konva.Line;
194
+ // 调整点 锚点
195
+ const anchors = (graph.find('.anchor') ?? []) as Konva.Circle[];
196
+ // 镜像
197
+ const anchorsSnap = (graphSnap.find('.anchor') ?? []) as Konva.Circle[];
198
+ // 连接点 锚点
199
+ const linkAnchors = (graph.find('.link-anchor') ?? []) as Konva.Circle[];
200
+ if (line && lineSnap) {
201
+ const stageState = render.getStageState();
202
+ {
203
+ const [graphRotation, adjustType, ex, ey] = [Math.round(graph.rotation()), adjustShape.attrs.anchor?.adjustType, endPoint.x, endPoint.y];
204
+ const { x: cx, y: cy, width: cw, height: ch } = graphSnap.getClientRect();
205
+ const { x, y } = graph.position();
206
+ const [centerX, centerY] = [cx + cw / 2, cy + ch / 2];
207
+ const { x: sx, y: sy } = Bezier.rotatePoint(ex, ey, centerX, centerY, -graphRotation);
208
+ const { x: rx, y: ry } = Bezier.rotatePoint(x, y, centerX, centerY, -graphRotation);
209
+ const points = line.points();
210
+ const manualPoints = (line.attrs.manualPoints ?? []) as LineManualPoint[];
211
+ if (adjustType === 'manual') {
212
+ if (adjustShape.attrs.anchor?.manualIndex !== void 0) {
213
+ const index = adjustShape.attrs.anchor?.adjusted
214
+ ? adjustShape.attrs.anchor?.manualIndex
215
+ : adjustShape.attrs.anchor?.manualIndex + 1;
216
+ const manualPointIndex = manualPoints.findIndex((o) => o.index === index);
217
+ if (manualPointIndex > -1) {
218
+ manualPoints[manualPointIndex].x = (sx - rx) / graph.scaleX();
219
+ manualPoints[manualPointIndex].y = (sy - ry) / graph.scaleY();
220
+ }
221
+ const linkPoints = [
222
+ [points[0], points[1]],
223
+ ...manualPoints.sort((a, b) => a.index - b.index).map((o) => [o.x, o.y]),
224
+ [points[points.length - 2], points[points.length - 1]]
225
+ ].flat();
226
+ line.setAttr('manualPoints', manualPoints);
227
+ line.points(linkPoints);
228
+ const adjustAnchorShadow = anchors.find((o) => o.attrs.adjustType === 'manual' && o.attrs.manualIndex === index);
229
+ if (adjustAnchorShadow) {
230
+ adjustAnchorShadow.position({ x: (sx - rx) / graph.scaleX(), y: (sy - ry) / graph.scaleY() });
231
+ }
232
+ }
233
+ } else {
234
+ const anchor = anchors.find((o) => o.attrs.adjustType === adjustType);
235
+ const anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === adjustType);
236
+ if (anchor && anchorShadow) {
237
+ const linkPoints = [
238
+ [points[0], points[1]],
239
+ ...manualPoints.sort((a, b) => a.index - b.index).map((o) => [o.x, o.y]),
240
+ [points[points.length - 2], points[points.length - 1]]
241
+ ];
242
+ switch (adjustType) {
243
+ case 'start':
244
+ linkPoints[0] = [(sx - rx) / graph.scaleX(), (sy - ry) / graph.scaleY()];
245
+ line.points(linkPoints.flat());
246
+ break;
247
+ case 'end':
248
+ linkPoints[linkPoints.length - 1] = [(sx - rx) / graph.scaleX(), (sy - ry) / graph.scaleY()];
249
+ line.points(linkPoints.flat());
250
+ break;
251
+ }
252
+ }
253
+ }
254
+ }
255
+ // 更新 调整点(拐点)
256
+ Bezier.updateAnchor(render, graph);
257
+ // 更新 调整点 的 锚点 位置
258
+ Bezier.updateAnchorShadows(graph, anchors, line);
259
+ // 更新 图形 的 连接点 的 锚点位置
260
+ Bezier.updateLinkAnchorShadows(graph, linkAnchors, line);
261
+ // 更新 调整点 位置
262
+ for (const anchor of anchors) {
263
+ for (const { shape } of anchorAndShadows) {
264
+ if (shape) {
265
+ if (shape.attrs.anchor?.adjustType === anchor.attrs.adjustType) {
266
+ const anchorShadow = graph
267
+ .find(`.anchor`)
268
+ .find((o) => o.attrs.adjustType === anchor.attrs.adjustType);
269
+ if (anchorShadow) {
270
+ shape.position({
271
+ x: render.toStageValue(anchorShadow.getAbsolutePosition().x - stageState.x),
272
+ y: render.toStageValue(anchorShadow.getAbsolutePosition().y - stageState.y)
273
+ });
274
+ shape.rotation(graph.getAbsoluteRotation());
275
+ }
276
+ }
277
+ }
278
+ }
279
+ }
280
+ // 重绘
281
+ render.redraw([GraphDraw.name, LinkDraw.name, PreviewDraw.name]);
282
+ }
283
+ const allXs = line.points().reduce((arr, item, idx) => {
284
+ if (idx % 2 === 0) {
285
+ arr.push(item);
286
+ }
287
+ return arr;
288
+ }, [] as number[]);
289
+ const allYs = line.points().reduce((arr, item, idx) => {
290
+ if (idx % 2 === 1) {
291
+ arr.push(item);
292
+ }
293
+ return arr;
294
+ }, [] as number[]);
295
+ const minX = Math.min(...allXs);
296
+ const maxX = Math.max(...allXs);
297
+ const minY = Math.min(...allYs);
298
+ const maxY = Math.max(...allYs);
299
+ BaseGraph.adjust(
300
+ render,
301
+ graph,
302
+ graphSnap,
303
+ adjustShape,
304
+ anchorAndShadows,
305
+ startPoint,
306
+ endPoint,
307
+ hoverRect,
308
+ { width: maxX - minX, height: maxY - minY },
309
+ { x: minX, y: minY }
310
+ );
311
+ }
312
+
313
+ /**
314
+ * 提供给 GraphDraw draw 使用
315
+ */
316
+ static override draw(graph: Konva.Group, render: Render, adjustAnchor?: GraphAnchor) {
317
+ // 调整点 信息
318
+ const anchors = (graph.attrs.anchors ?? []) as (GraphAnchor & { manualIndex?: number, adjusted?: boolean })[];
319
+ // 调整点 锚点
320
+ const anchorShapes = graph.find(`.anchor`);
321
+ // 调整点 信息&锚点
322
+ const anchorAndShadows = anchors
323
+ .map((anchor) => ({
324
+ anchor,
325
+ anchorShadow: anchorShapes.find(
326
+ (shape) =>
327
+ shape.attrs.adjustType === anchor.adjustType &&
328
+ shape.attrs.manualIndex === anchor.manualIndex
329
+ ) as Konva.Circle
330
+ }))
331
+ .filter((o) => o.anchorShadow !== void 0);
332
+ return Bezier.createAnchorShapes(render, graph, anchorAndShadows, adjustAnchor);
333
+ }
334
+
335
+ /**
336
+ * 默认图形大小
337
+ */
338
+ static size = 100;
339
+ /**
340
+ * 曲线 对应的 Konva 实例
341
+ */
342
+ private line: Konva.Line;
343
+ constructor(render: Render, dropPoint: Konva.Vector2d) {
344
+ super(render, dropPoint, {
345
+ type: "Bezier",
346
+ // 定义了 2 个 调整点
347
+ anchors: [{ adjustType: 'start' }, { adjustType: 'end' }].map((o) => ({ adjustType: o.adjustType })), // 调整点 类型定义
348
+ linkAnchors: [{ x: 0, y: 0, alias: 'start' }, { x: 0, y: 0, alias: 'end' }] as AssetInfoPoint[]
349
+ })
350
+ // 新建 曲线
351
+ this.line = new Konva.Arrow({
352
+ name: 'graph',
353
+ x: 0,
354
+ y: 0,
355
+ stroke: this.render.getPageSettings().stroke,
356
+ strokeWidth: this.render.getPageSettings().strokeWidth,
357
+ fill: this.render.getPageSettings().stroke,
358
+ points: [],
359
+ pointerAtBeginning: true,
360
+ pointerAtEnding: true,
361
+ lineJoin: 'miter',
362
+ sceneFunc: BezierSceneFunc
363
+ });
364
+ // 给予 1 像素,防止导出图片 toDataURL 失败
365
+ this.group.size({ width: 1, height: 1 });
366
+ // 加入
367
+ this.group.add(this.line);
368
+ // 鼠标按下位置 作为起点
369
+ this.group.position(this.dropPoint);
370
+ }
371
+ // 实现:拖动进行时
372
+ override drawMove(point: Konva.Vector2d): void {
373
+ // 鼠标拖动偏移量
374
+ const offsetX = point.x - this.dropPoint.x;
375
+ const offsetY = point.y - this.dropPoint.y;
376
+ // 起点、终点
377
+ const linkPoints = [[this.line.x(), this.line.y()], [this.line.x() + offsetX, this.line.y() + offsetY]];
378
+ // 曲线 路径
379
+ this.line.points(linkPoints.flat());
380
+ // 更新 图形 的 调整点 的 锚点位置
381
+ Bezier.updateAnchorShadows(this.group, this.anchorShadows, this.line);
382
+ // 更新 图形 的 连接点 的 锚点位置
383
+ Bezier.updateLinkAnchorShadows(this.group, this.linkAnchorShadows, this.line);
384
+ // 重绘
385
+ this.render.redraw([GraphDraw.name, LinkDraw.name, PreviewDraw.name]);
386
+ }
387
+
388
+ // 实现:拖动结束
389
+ override drawEnd(): void {
390
+ if (this.line.width() <= 10 && this.line.height() <= 10) {
391
+ // 加入只点击,无拖动
392
+ // 默认大小
393
+ const width = Bezier.size;
394
+ const height = width;
395
+ // 起点、终点
396
+ const linkPoints = [[this.line.x(), this.line.y()], [this.line.x() + width, this.line.y() + height]].flat();
397
+ // 曲线 位置大小
398
+ this.line.points(linkPoints);
399
+ }
400
+ // 更新 调整点(拐点)
401
+ Bezier.updateAnchor(this.render, this.group);
402
+ // 更新 图形 的 调整点 的 锚点位置
403
+ Bezier.updateAnchorShadows(this.group, this.anchorShadows, this.line);
404
+ // 更新 图形 的 连接点 的 锚点位置
405
+ Bezier.updateLinkAnchorShadows(this.group, this.linkAnchorShadows, this.line);
406
+ // 扣除多余的间隙
407
+ const size = { width: this.line.size().width - 10, height: this.line.size().height - 10 };
408
+ // 更新大小
409
+ this.group.size(size);
410
+ // 对齐线清除
411
+ this.render.attractTool.alignLinesClear();
412
+ // 更新历史
413
+ this.render.updateHistory();
414
+ // 重绘
415
+ this.render.redraw([GraphDraw.name, LinkDraw.name, PreviewDraw.name]);
416
+ super.drawEnd(size, {
417
+ x: Math.min(
418
+ ...this.line.points().reduce((arr, item, idx) => {
419
+ if (idx % 2 === 0) {
420
+ arr.push(item);
421
+ }
422
+ return arr;
423
+ }, [] as number[])
424
+ ),
425
+ y: Math.min(
426
+ ...this.line.points().reduce((arr, item, idx) => {
427
+ if (idx % 2 === 1) {
428
+ arr.push(item);
429
+ }
430
+ return arr;
431
+ }, [] as number[])
432
+ )
433
+ })
434
+ }
435
+
436
+ /**
437
+ * 更新 调整点(拐点)
438
+ * @param render
439
+ * @param graph
440
+ */
441
+ static updateAnchor(render: Render, graph: Konva.Group) {
442
+ const anchors = graph.attrs.anchors ?? [];
443
+ const anchorShadows = graph.find('.anchor') ?? [];
444
+ const shape = graph.findOne('.graph') as Konva.Line;
445
+ if (shape) {
446
+ // 已拐
447
+ let manualPoints = (shape.attrs.manualPoints ?? []) as LineManualPoint[];
448
+ const points = shape.points();
449
+ // 调整点 + 拐点
450
+ const linkPoints = [
451
+ [points[0], points[1]],
452
+ ...manualPoints.sort((a, b) => a.index - b.index).map((o) => [o.x, o.y]),
453
+ [points[points.length - 2], points[points.length - 1]]
454
+ ];
455
+ // 清空 调整点(拐点),保留 start end
456
+ anchors.splice(2);
457
+ const shadows = anchorShadows.splice(2);
458
+ for (const shadow of shadows) {
459
+ shadow.remove();
460
+ shadow.destroy();
461
+ }
462
+ manualPoints = [];
463
+ for (let i = linkPoints.length - 1; i > 0; i--) {
464
+ linkPoints.splice(i, 0, []);
465
+ }
466
+ // 调整点(拐点)
467
+ for (let i = 1; i < linkPoints.length - 1; i++) {
468
+ const anchor = {
469
+ type: graph.attrs.graphType,
470
+ adjustType: 'manual',
471
+ name: 'anchor',
472
+ groupId: graph.id(),
473
+ manualIndex: i,
474
+ adjusted: false
475
+ };
476
+ if (linkPoints[i].length === 0) {
477
+ anchor.adjusted = false;
478
+ // 新增
479
+ const prev = linkPoints[i - 1];
480
+ const next = linkPoints[i + 1];
481
+ const circle = new Konva.Circle({
482
+ adjustType: anchor.adjustType,
483
+ anchorType: anchor.type,
484
+ name: anchor.name,
485
+ manualIndex: anchor.manualIndex,
486
+ radius: 0,
487
+ x: (prev[0] + next[0]) / 2,
488
+ y: (prev[1] + next[1]) / 2,
489
+ anchor
490
+ });
491
+ graph.add(circle);
492
+ } else {
493
+ anchor.adjusted = true;
494
+ // 已拐
495
+ const circle = new Konva.Circle({
496
+ adjustType: anchor.adjustType,
497
+ anchorType: anchor.type,
498
+ name: anchor.name,
499
+ manualIndex: anchor.manualIndex,
500
+ adjusted: true,
501
+ radius: 0,
502
+ x: linkPoints[i][0],
503
+ y: linkPoints[i][1],
504
+ anchor
505
+ });
506
+ graph.add(circle);
507
+ manualPoints.push({ x: linkPoints[i][0], y: linkPoints[i][1], index: anchor.manualIndex });
508
+ }
509
+ anchors.push(anchor);
510
+ }
511
+ shape.setAttr('manualPoints', manualPoints);
512
+ graph.setAttr('anchors', anchors);
513
+ }
514
+ }
515
+
516
+ /**
517
+ * 调整之前
518
+ */
519
+ static adjustStart(
520
+ render: Render,
521
+ graph: Konva.Group,
522
+ adjustAnchor: GraphAnchor & { manualIndex?: number; adjusted?: boolean },
523
+ endPoint: Konva.Vector2d
524
+ ) {
525
+ const { x: gx, y: gy } = graph.position();
526
+ const shape = graph.findOne('.graph') as Konva.Line;
527
+ if (shape && typeof adjustAnchor.manualIndex === 'number') {
528
+ const manualPoints = (shape.attrs.manualPoints ?? []) as LineManualPoint[];
529
+ if (adjustAnchor.adjusted) {
530
+ } else {
531
+ manualPoints.push({
532
+ x: endPoint.x - gx,
533
+ y: endPoint.y - gy,
534
+ index: adjustAnchor.manualIndex
535
+ });
536
+ shape.setAttr('manualPoints', manualPoints);
537
+ }
538
+ // 更新 调整点(拐点)
539
+ Bezier.updateAnchor(render, graph);
540
+ }
541
+ }
542
+ }