aldehyde 0.2.472 → 0.2.474

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 (116) hide show
  1. package/lib/controls/entity-select/entity-select.js +1 -1
  2. package/lib/controls/entity-select/entity-select.js.map +1 -1
  3. package/lib/controls/entry-control.js +2 -2
  4. package/lib/controls/entry-control.js.map +1 -1
  5. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.css +47 -3
  6. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.js +12 -12
  7. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.js.map +1 -1
  8. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.json +77 -0
  9. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.ttf +0 -0
  10. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff +0 -0
  11. package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff2 +0 -0
  12. package/lib/draw-canvas/edit/components/asset-bar/index.d.ts +5 -0
  13. package/lib/draw-canvas/edit/components/asset-bar/index.d.ts.map +1 -0
  14. package/lib/draw-canvas/edit/components/asset-bar/index.js +78 -0
  15. package/lib/draw-canvas/edit/components/asset-bar/index.js.map +1 -0
  16. package/lib/draw-canvas/edit/components/asset-bar/index.less +36 -0
  17. package/lib/draw-canvas/edit/components/main-header/index.d.ts +14 -0
  18. package/lib/draw-canvas/edit/components/main-header/index.d.ts.map +1 -0
  19. package/lib/draw-canvas/edit/components/main-header/index.js +163 -0
  20. package/lib/draw-canvas/edit/components/main-header/index.js.map +1 -0
  21. package/lib/draw-canvas/edit/components/main-header/index.less +21 -0
  22. package/lib/draw-canvas/edit/components/render/index.d.ts +86 -0
  23. package/lib/draw-canvas/edit/components/render/index.d.ts.map +1 -0
  24. package/lib/draw-canvas/edit/components/render/index.js +686 -0
  25. package/lib/draw-canvas/edit/components/render/index.js.map +1 -0
  26. package/lib/draw-canvas/edit/components/render/types.d.ts +243 -0
  27. package/lib/draw-canvas/edit/components/render/types.d.ts.map +1 -0
  28. package/lib/draw-canvas/edit/components/render/types.js +66 -0
  29. package/lib/draw-canvas/edit/components/render/types.js.map +1 -0
  30. package/lib/draw-canvas/edit/components/setting-form/index.d.ts +19 -0
  31. package/lib/draw-canvas/edit/components/setting-form/index.d.ts.map +1 -0
  32. package/lib/draw-canvas/edit/components/setting-form/index.js +164 -0
  33. package/lib/draw-canvas/edit/components/setting-form/index.js.map +1 -0
  34. package/lib/draw-canvas/edit/index.d.ts +5 -0
  35. package/lib/draw-canvas/edit/index.d.ts.map +1 -0
  36. package/lib/draw-canvas/edit/index.js +112 -0
  37. package/lib/draw-canvas/edit/index.js.map +1 -0
  38. package/lib/draw-canvas/edit/index.less +34 -0
  39. package/lib/form/form-Item-group.d.ts.map +1 -1
  40. package/lib/form/form-Item-group.js +1 -1
  41. package/lib/form/form-Item-group.js.map +1 -1
  42. package/lib/icon/local-aliIcon/iconfont.js +5 -5
  43. package/lib/icon/local-aliIcon/iconfont.js.map +1 -1
  44. package/lib/table/relation-table.d.ts +4 -0
  45. package/lib/table/relation-table.d.ts.map +1 -1
  46. package/lib/tmpl/hcservice-v3.d.ts +1 -0
  47. package/lib/tmpl/hcservice-v3.d.ts.map +1 -1
  48. package/lib/tmpl/hcservice-v3.js +27 -0
  49. package/lib/tmpl/hcservice-v3.js.map +1 -1
  50. package/lib/tmpl/interface.d.ts +4 -0
  51. package/lib/tmpl/interface.d.ts.map +1 -1
  52. package/lib/tmpl/interface.js.map +1 -1
  53. package/lib/units/index.d.ts +1 -0
  54. package/lib/units/index.d.ts.map +1 -1
  55. package/lib/units/index.js +16 -0
  56. package/lib/units/index.js.map +1 -1
  57. package/package.json +1 -1
  58. package/src/aldehyde/controls/entity-select/entity-select.tsx +1 -1
  59. package/src/aldehyde/controls/entry-control.tsx +2 -2
  60. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.css +47 -3
  61. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.js +1 -1
  62. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.json +77 -0
  63. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.ttf +0 -0
  64. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff +0 -0
  65. package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff2 +0 -0
  66. package/src/aldehyde/draw-canvas/edit/components/asset-bar/index.less +36 -0
  67. package/src/aldehyde/draw-canvas/edit/components/asset-bar/index.tsx +93 -0
  68. package/src/aldehyde/draw-canvas/edit/components/main-header/index.less +21 -0
  69. package/src/aldehyde/draw-canvas/edit/components/main-header/index.tsx +187 -0
  70. package/src/aldehyde/draw-canvas/edit/components/render/draws/bg-draw.ts +98 -0
  71. package/src/aldehyde/draw-canvas/edit/components/render/draws/contextmenu-draw.ts +307 -0
  72. package/src/aldehyde/draw-canvas/edit/components/render/draws/graph-draw.ts +251 -0
  73. package/src/aldehyde/draw-canvas/edit/components/render/draws/index.ts +7 -0
  74. package/src/aldehyde/draw-canvas/edit/components/render/draws/link-draw.ts +1416 -0
  75. package/src/aldehyde/draw-canvas/edit/components/render/draws/preview-draw.ts +257 -0
  76. package/src/aldehyde/draw-canvas/edit/components/render/draws/ref-line-draw.ts +72 -0
  77. package/src/aldehyde/draw-canvas/edit/components/render/draws/ruler-draw.ts +167 -0
  78. package/src/aldehyde/draw-canvas/edit/components/render/graphs/base-graph.ts +241 -0
  79. package/src/aldehyde/draw-canvas/edit/components/render/graphs/bezier.ts +542 -0
  80. package/src/aldehyde/draw-canvas/edit/components/render/graphs/circle.ts +700 -0
  81. package/src/aldehyde/draw-canvas/edit/components/render/graphs/curve.ts +501 -0
  82. package/src/aldehyde/draw-canvas/edit/components/render/graphs/index.ts +6 -0
  83. package/src/aldehyde/draw-canvas/edit/components/render/graphs/line.ts +494 -0
  84. package/src/aldehyde/draw-canvas/edit/components/render/graphs/rect.ts +681 -0
  85. package/src/aldehyde/draw-canvas/edit/components/render/handlers/drag-handlers.ts +69 -0
  86. package/src/aldehyde/draw-canvas/edit/components/render/handlers/drag-outside-handlers.ts +162 -0
  87. package/src/aldehyde/draw-canvas/edit/components/render/handlers/graph-handlers.ts +108 -0
  88. package/src/aldehyde/draw-canvas/edit/components/render/handlers/index.ts +9 -0
  89. package/src/aldehyde/draw-canvas/edit/components/render/handlers/key-move-handlers.ts +50 -0
  90. package/src/aldehyde/draw-canvas/edit/components/render/handlers/link-handlers.ts +46 -0
  91. package/src/aldehyde/draw-canvas/edit/components/render/handlers/selection-handlers.ts +385 -0
  92. package/src/aldehyde/draw-canvas/edit/components/render/handlers/shutcut-handlers.ts +46 -0
  93. package/src/aldehyde/draw-canvas/edit/components/render/handlers/text-handlers.ts +82 -0
  94. package/src/aldehyde/draw-canvas/edit/components/render/handlers/zoom-handlers.ts +60 -0
  95. package/src/aldehyde/draw-canvas/edit/components/render/index.ts +768 -0
  96. package/src/aldehyde/draw-canvas/edit/components/render/tools/align-tool.ts +91 -0
  97. package/src/aldehyde/draw-canvas/edit/components/render/tools/asset-tool.ts +142 -0
  98. package/src/aldehyde/draw-canvas/edit/components/render/tools/attract-tool.ts +440 -0
  99. package/src/aldehyde/draw-canvas/edit/components/render/tools/copy-tool.ts +269 -0
  100. package/src/aldehyde/draw-canvas/edit/components/render/tools/import-export-tool.ts +603 -0
  101. package/src/aldehyde/draw-canvas/edit/components/render/tools/index.ts +9 -0
  102. package/src/aldehyde/draw-canvas/edit/components/render/tools/link-tool.ts +225 -0
  103. package/src/aldehyde/draw-canvas/edit/components/render/tools/position-tool.ts +212 -0
  104. package/src/aldehyde/draw-canvas/edit/components/render/tools/selection-tool.ts +132 -0
  105. package/src/aldehyde/draw-canvas/edit/components/render/tools/z-index-tool.ts +227 -0
  106. package/src/aldehyde/draw-canvas/edit/components/render/types.ts +287 -0
  107. package/src/aldehyde/draw-canvas/edit/components/render/utils/a-star.ts +116 -0
  108. package/src/aldehyde/draw-canvas/edit/components/render/utils/bezier-scene-func.ts +73 -0
  109. package/src/aldehyde/draw-canvas/edit/components/setting-form/index.tsx +200 -0
  110. package/src/aldehyde/draw-canvas/edit/index.less +34 -0
  111. package/src/aldehyde/draw-canvas/edit/index.tsx +138 -0
  112. package/src/aldehyde/form/form-Item-group.tsx +1 -0
  113. package/src/aldehyde/icon/local-aliIcon/iconfont.js +1 -1
  114. package/src/aldehyde/tmpl/hcservice-v3.tsx +14 -0
  115. package/src/aldehyde/tmpl/interface.tsx +2 -0
  116. package/src/aldehyde/units/index.tsx +15 -0
@@ -0,0 +1,681 @@
1
+ import Konva from 'konva';
2
+ import { GraphAnchor, Render, AssetInfoPoint } from '../types';
3
+ import { GraphDraw, LinkDraw, PreviewDraw } from '../draws';
4
+ import { BaseGraph } from './base-graph';
5
+
6
+ /**
7
+ * 图形 矩形
8
+ */
9
+ export class Rect extends BaseGraph {
10
+ // 实现:更新 图形 的 调整点 的 锚点位置
11
+ static override updateAnchorShadows(graph: Konva.Group, anchorShadows: Konva.Circle[]): void {
12
+ const { width, height } = graph.size();
13
+ for (const shadow of anchorShadows) {
14
+ switch (shadow.attrs.adjustType) {
15
+ case 'top':
16
+ shadow.position({ x: width / 2, y: 0 });
17
+ break;
18
+ case 'bottom':
19
+ shadow.position({ x: width / 2, y: height });
20
+ break;
21
+ case 'left':
22
+ shadow.position({ x: 0, y: height / 2 });
23
+ break;
24
+ case 'right':
25
+ shadow.position({ x: width, y: height / 2 });
26
+ break;
27
+ case 'top-left':
28
+ shadow.position({ x: 0, y: 0 });
29
+ break;
30
+ case 'top-right':
31
+ shadow.position({ x: width, y: 0 });
32
+ break;
33
+ case 'bottom-left':
34
+ shadow.position({ x: 0, y: height });
35
+ break;
36
+ case 'bottom-right':
37
+ shadow.position({ x: width, y: height });
38
+ break;
39
+ }
40
+ }
41
+ }
42
+
43
+ // 实现:更新 图形 的 连接点 的 锚点位置
44
+ static override updateLinkAnchorShadows(graph: Konva.Group, linkAnchorShadows: Konva.Circle[]): void {
45
+ const { width, height } = graph.size();
46
+ for (const shadow of linkAnchorShadows) {
47
+ switch (shadow.attrs.alias) {
48
+ case 'top':
49
+ shadow.position({ x: width / 2, y: 0 });
50
+ break;
51
+ case 'bottom':
52
+ shadow.position({ x: width / 2, y: height });
53
+ break;
54
+ case 'left':
55
+ shadow.position({ x: 0, y: height / 2 });
56
+ break;
57
+ case 'right':
58
+ shadow.position({ x: width, y: height / 2 });
59
+ break;
60
+ case 'center':
61
+ shadow.position({ x: width / 2, y: height / 2 });
62
+ break;
63
+ }
64
+ }
65
+ }
66
+
67
+ // 实现:生成 调整点
68
+ static override createAnchorShapes(
69
+ render: Render,
70
+ graph: Konva.Group,
71
+ anchorAndShadows: {
72
+ anchor: GraphAnchor;
73
+ anchorShadow: Konva.Circle;
74
+ shape?: Konva.Shape;
75
+ }[],
76
+ // eslint-disable-next-line
77
+ adjustAnchor?: GraphAnchor
78
+ ): {
79
+ anchorAndShadows: {
80
+ anchor: GraphAnchor;
81
+ anchorShadow: Konva.Circle;
82
+ shape?: Konva.Shape | undefined;
83
+ }[];
84
+ } {
85
+ const stageState = render.getStageState();
86
+ for (const anchorAndShadow of anchorAndShadows) {
87
+ const { anchor, anchorShadow } = anchorAndShadow;
88
+ const x = render.toStageValue(anchorShadow.getAbsolutePosition().x - stageState.x),
89
+ y = render.toStageValue(anchorShadow.getAbsolutePosition().y - stageState.y);
90
+ const offset = render.toStageValue(render.pointSize + 5);
91
+ const anchorShape = new Konva.Line({
92
+ name: 'anchor',
93
+ anchor: anchor,
94
+ stroke: `rgba(0,0,255,0.4)`,
95
+ strokeWidth: render.toStageValue(2),
96
+ hitStrokeWidth: render.toStageValue(3),
97
+ x,
98
+ y,
99
+ points: {
100
+ 'top-left': [[-offset, offset / 2], [-offset, -offset], [offset / 2, -offset]].flat(),
101
+ top: [[-offset, -offset], [offset, -offset]].flat(),
102
+ 'top-right': [[-offset / 2, -offset], [offset, -offset], [offset, offset / 2]].flat(),
103
+ right: [[offset, -offset], [offset, offset]].flat(),
104
+ 'bottom-right': [[-offset / 2, offset], [offset, offset], [offset, -offset / 2]].flat(),
105
+ bottom: [[-offset, offset], [offset, offset]].flat(),
106
+ 'bottom-left': [[-offset, -offset / 2], [-offset, offset], [offset / 2, offset]].flat(),
107
+ left: [[-offset, -offset], [-offset, offset]].flat()
108
+ }[anchor.adjustType] ?? [],
109
+ rotation: graph.getAbsoluteRotation(), // 旋转角度
110
+ visible: graph.attrs.adjusting || graph.attrs.hover === true
111
+ });
112
+ anchorShape.on('mouseenter', () => {
113
+ document.body.style.cursor = 'move';
114
+ graph.setAttr('hover', true);
115
+ graph.setAttr('hoverAnchor', true);
116
+ });
117
+ anchorShape.on('mouseleave', () => {
118
+ document.body.style.cursor = anchorShape.attrs.adjusting ? 'move' : 'default';
119
+ graph.setAttr('hover', false);
120
+ graph.setAttr('hoverAnchor', false);
121
+ render.redraw([GraphDraw.name]);
122
+ });
123
+ anchorAndShadow.shape = anchorShape;
124
+ }
125
+ return { anchorAndShadows };
126
+ }
127
+
128
+ // 实现:调整 图形
129
+ static override adjust(
130
+ render: Render,
131
+ graph: Konva.Group,
132
+ graphSnap: Konva.Group,
133
+ adjustShape: Konva.Shape,
134
+ anchorAndShadows: {
135
+ anchor: GraphAnchor;
136
+ anchorShadow: Konva.Circle;
137
+ shape?: Konva.Shape | undefined;
138
+ }[],
139
+ startPoint: Konva.Vector2d,
140
+ endPoint: Konva.Vector2d,
141
+ hoverRect?: Konva.Rect
142
+ ) {
143
+ // 目标 矩形
144
+ const rect = graph.findOne('.graph') as Konva.Rect;
145
+ const rectSnap = graphSnap.findOne('.graph') as Konva.Rect;
146
+ const anchors = (graph.find('.anchor') ?? []) as Konva.Circle[];
147
+ const anchorsSnap = (graphSnap.find('.anchor') ?? []) as Konva.Circle[];
148
+ const linkAnchors = (graph.find('.link-anchor') ?? []) as Konva.Circle[];
149
+ if (rect && rectSnap) {
150
+ const [graphRotation, adjustType, ex, ey] = [
151
+ Math.round(graph.rotation()),
152
+ adjustShape.attrs.anchor?.adjustType,
153
+ endPoint.x,
154
+ endPoint.y
155
+ ];
156
+ let anchorShadow: Konva.Circle | undefined, anchorShadowAcross: Konva.Circle | undefined;
157
+ switch (adjustType) {
158
+ case 'top':
159
+ anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'top');
160
+ anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'bottom');
161
+ break;
162
+ case 'bottom':
163
+ anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'bottom');
164
+ anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'top');
165
+ break;
166
+ case 'left':
167
+ anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'left');
168
+ anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'right');
169
+ break;
170
+ case 'right':
171
+ anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'right');
172
+ anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'left');
173
+ break;
174
+ case 'top-left':
175
+ anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'top-left');
176
+ anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'bottom-right');
177
+ break;
178
+ case 'top-right':
179
+ anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'top-right');
180
+ anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'bottom-left');
181
+ break;
182
+ case 'bottom-left':
183
+ anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'bottom-left');
184
+ anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'top-right');
185
+ break;
186
+ case 'bottom-right':
187
+ anchorShadow = anchorsSnap.find((o) => o.attrs.adjustType === 'bottom-right');
188
+ anchorShadowAcross = anchorsSnap.find((o) => o.attrs.adjustType === 'top-left');
189
+ break;
190
+ }
191
+ if (anchorShadow && anchorShadowAcross) {
192
+ const { x: sx, y: sy } = anchorShadow.getAbsolutePosition();
193
+ const { x: ax, y: ay } = anchorShadowAcross.getAbsolutePosition();
194
+ {
195
+ const d1 = Math.sqrt(Math.pow(sx - ax, 2) + Math.pow(sy - ay, 2));
196
+ const d2 = Math.sqrt(Math.pow(ex - ax, 2) + Math.pow(ey - ay, 2));
197
+ const r1 = d2 / d1;
198
+ let zeroWidth = 1, zeroHeight = 1;
199
+ switch (adjustType) {
200
+ case 'top':
201
+ if (graphRotation >= 45 && graphRotation < 135) {
202
+ zeroHeight = ex <= ax ? 0 : 1;
203
+ } else if (graphRotation >= -135 && graphRotation < -45) {
204
+ zeroHeight = ex >= ax ? 0 : 1;
205
+ } else if (graphRotation >= -45 && graphRotation < 45) {
206
+ zeroHeight = ey >= ay ? 0 : 1;
207
+ } else {
208
+ zeroHeight = ey <= ay ? 0 : 1;
209
+ }
210
+ break;
211
+ case 'bottom':
212
+ if (graphRotation >= 45 && graphRotation < 135) {
213
+ zeroHeight = ex <= ax ? 1 : 0;
214
+ } else if (graphRotation >= -135 && graphRotation < -45) {
215
+ zeroHeight = ex >= ax ? 1 : 0;
216
+ } else if (graphRotation >= -45 && graphRotation < 45) {
217
+ zeroHeight = ey >= ay ? 1 : 0;
218
+ } else {
219
+ zeroHeight = ey <= ay ? 1 : 0;
220
+ }
221
+ break;
222
+ case 'left':
223
+ if (graphRotation >= 45 && graphRotation < 135) {
224
+ zeroWidth = ey >= ay ? 0 : 1;
225
+ } else if (graphRotation >= -135 && graphRotation < -45) {
226
+ zeroWidth = ex <= ax ? 0 : 1;
227
+ } else if (graphRotation >= -45 && graphRotation < 45) {
228
+ zeroWidth = ex >= ax ? 0 : 1;
229
+ } else {
230
+ zeroWidth = ey <= ay ? 0 : 1;
231
+ }
232
+ break;
233
+ case 'right':
234
+ if (graphRotation >= 45 && graphRotation < 135) {
235
+ zeroWidth = ey >= ay ? 1 : 0;
236
+ } else if (graphRotation >= -135 && graphRotation < -45) {
237
+ zeroWidth = ex <= ax ? 1 : 0;
238
+ } else if (graphRotation >= -45 && graphRotation < 45) {
239
+ zeroWidth = ex >= ax ? 1 : 0;
240
+ } else {
241
+ zeroWidth = ey <= ay ? 1 : 0;
242
+ }
243
+ break;
244
+ case 'top-left':
245
+ if (graphRotation > -45 && graphRotation < 45) {
246
+ if (ex >= ax && ey >= ay) {
247
+ zeroWidth = 0;
248
+ zeroHeight = 0;
249
+ } else {
250
+ zeroWidth = 1;
251
+ zeroHeight = 1;
252
+ }
253
+ } else if (graphRotation === 45) {
254
+ if (ey >= ay) {
255
+ zeroWidth = 0;
256
+ zeroHeight = 0;
257
+ } else {
258
+ zeroWidth = 1;
259
+ zeroHeight = 1;
260
+ }
261
+ } else if (graphRotation > 45 && graphRotation < 135) {
262
+ if (ex <= ax && ey >= ay) {
263
+ zeroWidth = 0;
264
+ zeroHeight = 0;
265
+ } else {
266
+ zeroWidth = 1;
267
+ zeroHeight = 1;
268
+ }
269
+ } else if (graphRotation === 135) {
270
+ if (ex <= ax) {
271
+ zeroWidth = 0;
272
+ zeroHeight = 0;
273
+ } else {
274
+ zeroWidth = 1;
275
+ zeroHeight = 1;
276
+ }
277
+ } else if ((graphRotation > 135 && graphRotation <= 180) || (graphRotation >= -180 && graphRotation < -135)) {
278
+ if (ex <= ax && ey <= ay) {
279
+ zeroWidth = 0;
280
+ zeroHeight = 0;
281
+ } else {
282
+ zeroWidth = 1;
283
+ zeroHeight = 1;
284
+ }
285
+ } else if (graphRotation === -135) {
286
+ if (ey <= ay) {
287
+ zeroWidth = 0;
288
+ zeroHeight = 0;
289
+ } else {
290
+ zeroWidth = 1;
291
+ zeroHeight = 1;
292
+ }
293
+ } else if (graphRotation > -135 && graphRotation < -45) {
294
+ if (ex >= ax && ey <= ay) {
295
+ zeroWidth = 0;
296
+ zeroHeight = 0;
297
+ } else {
298
+ zeroWidth = 1;
299
+ zeroHeight = 1;
300
+ }
301
+ } else if (graphRotation === -45) {
302
+ if (ex >= ax) {
303
+ zeroWidth = 0;
304
+ zeroHeight = 0;
305
+ } else {
306
+ zeroWidth = 1;
307
+ zeroHeight = 1;
308
+ }
309
+ }
310
+ break;
311
+ case 'top-right':
312
+ if (graphRotation > -45 && graphRotation < 45) {
313
+ if (ex <= ax && ey >= ay) {
314
+ zeroWidth = 0;
315
+ zeroHeight = 0;
316
+ } else {
317
+ zeroWidth = 1;
318
+ zeroHeight = 1;
319
+ }
320
+ } else if (graphRotation === 45) {
321
+ if (ex <= ax) {
322
+ zeroWidth = 0;
323
+ zeroHeight = 0;
324
+ } else {
325
+ zeroWidth = 1;
326
+ zeroHeight = 1;
327
+ }
328
+ } else if (graphRotation > 45 && graphRotation < 135) {
329
+ if (ex <= ax && ey <= ay) {
330
+ zeroWidth = 0;
331
+ zeroHeight = 0;
332
+ } else {
333
+ zeroWidth = 1;
334
+ zeroHeight = 1;
335
+ }
336
+ } else if (graphRotation === 135) {
337
+ if (ey <= ay) {
338
+ zeroWidth = 0;
339
+ zeroHeight = 0;
340
+ } else {
341
+ zeroWidth = 1;
342
+ zeroHeight = 1;
343
+ }
344
+ } else if ((graphRotation > 135 && graphRotation <= 180) || (graphRotation >= -180 && graphRotation < -135)) {
345
+ if (ex >= ax && ey <= ay) {
346
+ zeroWidth = 0;
347
+ zeroHeight = 0;
348
+ } else {
349
+ zeroWidth = 1;
350
+ zeroHeight = 1;
351
+ }
352
+ } else if (graphRotation === -135) {
353
+ if (ex >= ax) {
354
+ zeroWidth = 0;
355
+ zeroHeight = 0;
356
+ } else {
357
+ zeroWidth = 1;
358
+ zeroHeight = 1;
359
+ }
360
+ } else if (graphRotation > -135 && graphRotation < -45) {
361
+ if (ex >= ax && ey >= ay) {
362
+ zeroWidth = 0;
363
+ zeroHeight = 0;
364
+ } else {
365
+ zeroWidth = 1;
366
+ zeroHeight = 1;
367
+ }
368
+ } else if (graphRotation === -45) {
369
+ if (ey >= ay) {
370
+ zeroWidth = 0;
371
+ zeroHeight = 0;
372
+ } else {
373
+ zeroWidth = 1;
374
+ zeroHeight = 1;
375
+ }
376
+ }
377
+ break;
378
+ case 'bottom-left':
379
+ if (graphRotation > -45 && graphRotation < 45) {
380
+ if (ex >= ax && ey <= ay) {
381
+ zeroWidth = 0;
382
+ zeroHeight = 0;
383
+ } else {
384
+ zeroWidth = 1;
385
+ zeroHeight = 1;
386
+ }
387
+ } else if (graphRotation === 45) {
388
+ if (ex >= ax) {
389
+ zeroWidth = 0;
390
+ zeroHeight = 0;
391
+ } else {
392
+ zeroWidth = 1;
393
+ zeroHeight = 1;
394
+ }
395
+ } else if (graphRotation > 45 && graphRotation < 135) {
396
+ if (ex >= ax && ey >= ay) {
397
+ zeroWidth = 0;
398
+ zeroHeight = 0;
399
+ } else {
400
+ zeroWidth = 1;
401
+ zeroHeight = 1;
402
+ }
403
+ } else if (graphRotation === 135) {
404
+ if (ey >= ay) {
405
+ zeroWidth = 0;
406
+ zeroHeight = 0;
407
+ } else {
408
+ zeroWidth = 1;
409
+ zeroHeight = 1;
410
+ }
411
+ } else if ((graphRotation > 135 && graphRotation <= 180) || (graphRotation >= -180 && graphRotation < -135)) {
412
+ if (ex <= ax && ey >= ay) {
413
+ zeroWidth = 0;
414
+ zeroHeight = 0;
415
+ } else {
416
+ zeroWidth = 1;
417
+ zeroHeight = 1;
418
+ }
419
+ } else if (graphRotation === -135) {
420
+ if (ex <= ax) {
421
+ zeroWidth = 0;
422
+ zeroHeight = 0;
423
+ } else {
424
+ zeroWidth = 1;
425
+ zeroHeight = 1;
426
+ }
427
+ } else if (graphRotation > -135 && graphRotation < -45) {
428
+ if (ex <= ax && ey <= ay) {
429
+ zeroWidth = 0;
430
+ zeroHeight = 0;
431
+ } else {
432
+ zeroWidth = 1;
433
+ zeroHeight = 1;
434
+ }
435
+ } else if (graphRotation === -45) {
436
+ if (ey <= ay) {
437
+ zeroWidth = 0;
438
+ zeroHeight = 0;
439
+ } else {
440
+ zeroWidth = 1;
441
+ zeroHeight = 1;
442
+ }
443
+ }
444
+ break;
445
+ case 'bottom-right':
446
+ if (graphRotation > -45 && graphRotation < 45) {
447
+ if (ex <= ax && ey <= ay) {
448
+ zeroWidth = 0;
449
+ zeroHeight = 0;
450
+ } else {
451
+ zeroWidth = 1;
452
+ zeroHeight = 1;
453
+ }
454
+ } else if (graphRotation === 45) {
455
+ if (ey <= ay) {
456
+ zeroWidth = 0;
457
+ zeroHeight = 0;
458
+ } else {
459
+ zeroWidth = 1;
460
+ zeroHeight = 1;
461
+ }
462
+ } else if (graphRotation > 45 && graphRotation < 135) {
463
+ if (ex >= ax && ey <= ay) {
464
+ zeroWidth = 0;
465
+ zeroHeight = 0;
466
+ } else {
467
+ zeroWidth = 1;
468
+ zeroHeight = 1;
469
+ }
470
+ } else if (graphRotation === 135) {
471
+ if (ex >= ax) {
472
+ zeroWidth = 0;
473
+ zeroHeight = 0;
474
+ } else {
475
+ zeroWidth = 1;
476
+ zeroHeight = 1;
477
+ }
478
+ } else if ((graphRotation > 135 && graphRotation <= 180) || (graphRotation >= -180 && graphRotation < -135)) {
479
+ if (ex >= ax && ey >= ay) {
480
+ zeroWidth = 0;
481
+ zeroHeight = 0;
482
+ } else {
483
+ zeroWidth = 1;
484
+ zeroHeight = 1;
485
+ }
486
+ } else if (graphRotation === -135) {
487
+ if (ey >= ay) {
488
+ zeroWidth = 0;
489
+ zeroHeight = 0;
490
+ } else {
491
+ zeroWidth = 1;
492
+ zeroHeight = 1;
493
+ }
494
+ } else if (graphRotation > -135 && graphRotation < -45) {
495
+ if (ex <= ax && ey >= ay) {
496
+ zeroWidth = 0;
497
+ zeroHeight = 0;
498
+ } else {
499
+ zeroWidth = 1;
500
+ zeroHeight = 1;
501
+ }
502
+ } else if (graphRotation === -45) {
503
+ if (ex <= ax) {
504
+ zeroWidth = 0;
505
+ zeroHeight = 0;
506
+ } else {
507
+ zeroWidth = 1;
508
+ zeroHeight = 1;
509
+ }
510
+ }
511
+ break;
512
+ }
513
+ if (/-?(left|right)$/.test(adjustType)) {
514
+ graph.width(Math.max(2, graphSnap.width() * r1 * zeroWidth));
515
+ }
516
+ if (/^(top|bottom)-?/.test(adjustType)) {
517
+ graph.height(Math.max(2, graphSnap.height() * r1 * zeroHeight));
518
+ }
519
+ }
520
+ {
521
+ const [graphWidth, graphHeight] = [graph.width() * graph.scaleX(), graph.height() * graph.scaleY()];
522
+ const cos = Math.cos((graphRotation * Math.PI) / 180);
523
+ const sin = Math.sin((graphRotation * Math.PI) / 180);
524
+ const tan = Math.tan((graphRotation * Math.PI) / 180);
525
+ switch (adjustType) {
526
+ case 'top':
527
+ graph.x(ax - (graphWidth / 2 - graphHeight * tan) * cos);
528
+ if (graphRotation !== 90 && graphRotation !== -90) {
529
+ graph.y(ay - (graphHeight / cos + (graphWidth / 2 - graphHeight * tan) * sin));
530
+ }
531
+ break;
532
+ case 'bottom': // 无需处理
533
+ break;
534
+ case 'left':
535
+ if ([90, -90].includes(graphRotation)) {
536
+ graph.y(ay - graphWidth);
537
+ } else if (Math.abs(graphRotation) === 180) {
538
+ graph.x(ax + graphWidth);
539
+ } else {
540
+ const v1 = graphHeight / 2 / cos;
541
+ const v2 = v1 * sin;
542
+ const v3 = graphWidth - v2;
543
+ const v4 = v3 * sin;
544
+ graph.x(ax - v3 * cos);
545
+ graph.y(ay - (v1 + v4));
546
+ }
547
+ break;
548
+ case 'right': // 无需处理
549
+ break;
550
+ case 'top-left':
551
+ graph.x(ax - (graphWidth - graphHeight * tan) * cos);
552
+ graph.y(ay - (graphWidth * sin + graphHeight * cos));
553
+ break;
554
+ case 'top-right':
555
+ graph.x(ax + graphHeight * sin);
556
+ graph.y(ay - graphHeight * cos);
557
+ break;
558
+ case 'bottom-left':
559
+ graph.x(ax - graphWidth * cos);
560
+ graph.y(ay - graphWidth * sin);
561
+ break;
562
+ case 'bottom-right': // 无需处理
563
+ break;
564
+ }
565
+ }
566
+ }
567
+ const [graphWidth, graphHeight] = [graph.width(), graph.height()];
568
+ // 更新 矩形 大小
569
+ rect.width(graphWidth);
570
+ rect.height(graphHeight);
571
+ // 更新 调整点 的 锚点 位置
572
+ Rect.updateAnchorShadows(graph, anchors);
573
+ // 更新 图形 的 连接点 的 锚点位置
574
+ Rect.updateLinkAnchorShadows(graph, linkAnchors);
575
+ const stageState = render.getStageState();
576
+ // 更新 调整点 位置
577
+ for (const anchor of anchors) {
578
+ for (const { shape } of anchorAndShadows) {
579
+ if (shape) {
580
+ if (shape.attrs.anchor?.adjustType === anchor.attrs.adjustType) {
581
+ const anchorShadow = graph.find(`.anchor`).find((o) => o.attrs.adjustType === anchor.attrs.adjustType);
582
+ if (anchorShadow) {
583
+ shape.position({
584
+ x: render.toStageValue(anchorShadow.getAbsolutePosition().x - stageState.x),
585
+ y: render.toStageValue(anchorShadow.getAbsolutePosition().y - stageState.y)
586
+ });
587
+ shape.rotation(graph.getAbsoluteRotation());
588
+ }
589
+ }
590
+ }
591
+ }
592
+ }
593
+ render.redraw([GraphDraw.name, LinkDraw.name, PreviewDraw.name]);
594
+ }
595
+ BaseGraph.adjust(render, graph, graphSnap, adjustShape, anchorAndShadows, startPoint, endPoint, hoverRect);
596
+ }
597
+
598
+ /**
599
+ * 提供给 GraphDraw draw 使用
600
+ */
601
+ static override draw(graph: Konva.Group, render: Render, adjustAnchor?: GraphAnchor) {
602
+ // 调整点 及其 锚点
603
+ const { anchorAndShadows } = super.draw(graph, render, adjustAnchor);
604
+ return Rect.createAnchorShapes(render, graph, anchorAndShadows, adjustAnchor);
605
+ }
606
+
607
+ /**
608
+ * 默认图形大小
609
+ */
610
+ static size = 100;
611
+
612
+ /**
613
+ * 矩形 对应的 Konva 实例
614
+ */
615
+ private rect: Konva.Rect;
616
+
617
+ constructor(render: Render, dropPoint: Konva.Vector2d) {
618
+ super(render, dropPoint, {
619
+ type: "Rect",
620
+ anchors: [
621
+ { adjustType: 'top' },
622
+ { adjustType: 'bottom' },
623
+ { adjustType: 'left' },
624
+ { adjustType: 'right' },
625
+ { adjustType: 'top-left' },
626
+ { adjustType: 'top-right' },
627
+ { adjustType: 'bottom-left' },
628
+ { adjustType: 'bottom-right' }
629
+ ].map((o) => ({ adjustType: o.adjustType })),
630
+ linkAnchors: [
631
+ { x: 0, y: 0, alias: 'top', direction: 'top' },
632
+ { x: 0, y: 0, alias: 'bottom', direction: 'bottom' },
633
+ { x: 0, y: 0, alias: 'left', direction: 'left' },
634
+ { x: 0, y: 0, alias: 'right', direction: 'right' },
635
+ { x: 0, y: 0, alias: 'center' }
636
+ ] as AssetInfoPoint[]
637
+ });
638
+ this.rect = new Konva.Rect({
639
+ name: 'graph',
640
+ x: 0,
641
+ y: 0,
642
+ width: 0,
643
+ height: 0,
644
+ stroke: this.render.getPageSettings().stroke,
645
+ strokeWidth: this.render.getPageSettings().strokeWidth
646
+ });
647
+ this.group.add(this.rect);
648
+ this.group.position(this.dropPoint);
649
+ }
650
+
651
+ // 实现:拖动进行时
652
+ override drawMove(point: Konva.Vector2d): void {
653
+ let offsetX = point.x - this.dropPoint.x,
654
+ offsetY = point.y - this.dropPoint.y;
655
+ if (offsetX < 1) offsetX = 1;
656
+ if (offsetY < 1) offsetY = 1;
657
+ // 矩形 位置大小
658
+ this.rect.width(offsetX);
659
+ this.rect.height(offsetY);
660
+ this.group.size({ width: offsetX, height: offsetY });
661
+ Rect.updateAnchorShadows(this.group, this.anchorShadows);
662
+ Rect.updateLinkAnchorShadows(this.group, this.linkAnchorShadows);
663
+ this.render.redraw([GraphDraw.name, LinkDraw.name, PreviewDraw.name]);
664
+ }
665
+
666
+ // 实现:拖动结束
667
+ override drawEnd(): void {
668
+ if (this.rect.width() <= 1 && this.rect.height() <= 1) {
669
+ const width = Rect.size, height = width;
670
+ this.rect.width(width - this.rect.strokeWidth());
671
+ this.rect.height(height - this.rect.strokeWidth());
672
+ this.group.size({ width, height });
673
+ Rect.updateAnchorShadows(this.group, this.anchorShadows);
674
+ Rect.updateLinkAnchorShadows(this.group, this.linkAnchorShadows);
675
+ this.render.attractTool.alignLinesClear();
676
+ this.render.updateHistory();
677
+ this.render.redraw([GraphDraw.name, LinkDraw.name, PreviewDraw.name]);
678
+ }
679
+ super.drawEnd();
680
+ }
681
+ }