aldehyde 0.2.473 → 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.
- package/lib/controls/entry-control.js +2 -2
- package/lib/controls/entry-control.js.map +1 -1
- package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.css +47 -3
- package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.js +12 -12
- package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.js.map +1 -1
- package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.json +77 -0
- package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.ttf +0 -0
- package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff +0 -0
- package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff2 +0 -0
- package/lib/draw-canvas/edit/components/asset-bar/index.d.ts +5 -0
- package/lib/draw-canvas/edit/components/asset-bar/index.d.ts.map +1 -0
- package/lib/draw-canvas/edit/components/asset-bar/index.js +78 -0
- package/lib/draw-canvas/edit/components/asset-bar/index.js.map +1 -0
- package/lib/draw-canvas/edit/components/asset-bar/index.less +36 -0
- package/lib/draw-canvas/edit/components/main-header/index.d.ts +14 -0
- package/lib/draw-canvas/edit/components/main-header/index.d.ts.map +1 -0
- package/lib/draw-canvas/edit/components/main-header/index.js +163 -0
- package/lib/draw-canvas/edit/components/main-header/index.js.map +1 -0
- package/lib/draw-canvas/edit/components/main-header/index.less +21 -0
- package/lib/draw-canvas/edit/components/render/index.d.ts +86 -0
- package/lib/draw-canvas/edit/components/render/index.d.ts.map +1 -0
- package/lib/draw-canvas/edit/components/render/index.js +686 -0
- package/lib/draw-canvas/edit/components/render/index.js.map +1 -0
- package/lib/draw-canvas/edit/components/render/types.d.ts +243 -0
- package/lib/draw-canvas/edit/components/render/types.d.ts.map +1 -0
- package/lib/draw-canvas/edit/components/render/types.js +66 -0
- package/lib/draw-canvas/edit/components/render/types.js.map +1 -0
- package/lib/draw-canvas/edit/components/setting-form/index.d.ts +19 -0
- package/lib/draw-canvas/edit/components/setting-form/index.d.ts.map +1 -0
- package/lib/draw-canvas/edit/components/setting-form/index.js +164 -0
- package/lib/draw-canvas/edit/components/setting-form/index.js.map +1 -0
- package/lib/draw-canvas/edit/index.d.ts +5 -0
- package/lib/draw-canvas/edit/index.d.ts.map +1 -0
- package/lib/draw-canvas/edit/index.js +112 -0
- package/lib/draw-canvas/edit/index.js.map +1 -0
- package/lib/draw-canvas/edit/index.less +34 -0
- package/lib/form/form-Item-group.d.ts.map +1 -1
- package/lib/form/form-Item-group.js +1 -1
- package/lib/form/form-Item-group.js.map +1 -1
- package/lib/icon/local-aliIcon/iconfont.js +5 -5
- package/lib/icon/local-aliIcon/iconfont.js.map +1 -1
- package/lib/table/relation-table.d.ts +4 -0
- package/lib/table/relation-table.d.ts.map +1 -1
- package/lib/tmpl/hcservice-v3.d.ts +1 -0
- package/lib/tmpl/hcservice-v3.d.ts.map +1 -1
- package/lib/tmpl/hcservice-v3.js +27 -0
- package/lib/tmpl/hcservice-v3.js.map +1 -1
- package/lib/tmpl/interface.d.ts +4 -0
- package/lib/tmpl/interface.d.ts.map +1 -1
- package/lib/tmpl/interface.js.map +1 -1
- package/lib/units/index.d.ts +1 -0
- package/lib/units/index.d.ts.map +1 -1
- package/lib/units/index.js +16 -0
- package/lib/units/index.js.map +1 -1
- package/package.json +1 -1
- package/src/aldehyde/controls/entry-control.tsx +2 -2
- package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.css +47 -3
- package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.js +1 -1
- package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.json +77 -0
- package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.ttf +0 -0
- package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff +0 -0
- package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.woff2 +0 -0
- package/src/aldehyde/draw-canvas/edit/components/asset-bar/index.less +36 -0
- package/src/aldehyde/draw-canvas/edit/components/asset-bar/index.tsx +93 -0
- package/src/aldehyde/draw-canvas/edit/components/main-header/index.less +21 -0
- package/src/aldehyde/draw-canvas/edit/components/main-header/index.tsx +187 -0
- package/src/aldehyde/draw-canvas/edit/components/render/draws/bg-draw.ts +98 -0
- package/src/aldehyde/draw-canvas/edit/components/render/draws/contextmenu-draw.ts +307 -0
- package/src/aldehyde/draw-canvas/edit/components/render/draws/graph-draw.ts +251 -0
- package/src/aldehyde/draw-canvas/edit/components/render/draws/index.ts +7 -0
- package/src/aldehyde/draw-canvas/edit/components/render/draws/link-draw.ts +1416 -0
- package/src/aldehyde/draw-canvas/edit/components/render/draws/preview-draw.ts +257 -0
- package/src/aldehyde/draw-canvas/edit/components/render/draws/ref-line-draw.ts +72 -0
- package/src/aldehyde/draw-canvas/edit/components/render/draws/ruler-draw.ts +167 -0
- package/src/aldehyde/draw-canvas/edit/components/render/graphs/base-graph.ts +241 -0
- package/src/aldehyde/draw-canvas/edit/components/render/graphs/bezier.ts +542 -0
- package/src/aldehyde/draw-canvas/edit/components/render/graphs/circle.ts +700 -0
- package/src/aldehyde/draw-canvas/edit/components/render/graphs/curve.ts +501 -0
- package/src/aldehyde/draw-canvas/edit/components/render/graphs/index.ts +6 -0
- package/src/aldehyde/draw-canvas/edit/components/render/graphs/line.ts +494 -0
- package/src/aldehyde/draw-canvas/edit/components/render/graphs/rect.ts +681 -0
- package/src/aldehyde/draw-canvas/edit/components/render/handlers/drag-handlers.ts +69 -0
- package/src/aldehyde/draw-canvas/edit/components/render/handlers/drag-outside-handlers.ts +162 -0
- package/src/aldehyde/draw-canvas/edit/components/render/handlers/graph-handlers.ts +108 -0
- package/src/aldehyde/draw-canvas/edit/components/render/handlers/index.ts +9 -0
- package/src/aldehyde/draw-canvas/edit/components/render/handlers/key-move-handlers.ts +50 -0
- package/src/aldehyde/draw-canvas/edit/components/render/handlers/link-handlers.ts +46 -0
- package/src/aldehyde/draw-canvas/edit/components/render/handlers/selection-handlers.ts +385 -0
- package/src/aldehyde/draw-canvas/edit/components/render/handlers/shutcut-handlers.ts +46 -0
- package/src/aldehyde/draw-canvas/edit/components/render/handlers/text-handlers.ts +82 -0
- package/src/aldehyde/draw-canvas/edit/components/render/handlers/zoom-handlers.ts +60 -0
- package/src/aldehyde/draw-canvas/edit/components/render/index.ts +768 -0
- package/src/aldehyde/draw-canvas/edit/components/render/tools/align-tool.ts +91 -0
- package/src/aldehyde/draw-canvas/edit/components/render/tools/asset-tool.ts +142 -0
- package/src/aldehyde/draw-canvas/edit/components/render/tools/attract-tool.ts +440 -0
- package/src/aldehyde/draw-canvas/edit/components/render/tools/copy-tool.ts +269 -0
- package/src/aldehyde/draw-canvas/edit/components/render/tools/import-export-tool.ts +603 -0
- package/src/aldehyde/draw-canvas/edit/components/render/tools/index.ts +9 -0
- package/src/aldehyde/draw-canvas/edit/components/render/tools/link-tool.ts +225 -0
- package/src/aldehyde/draw-canvas/edit/components/render/tools/position-tool.ts +212 -0
- package/src/aldehyde/draw-canvas/edit/components/render/tools/selection-tool.ts +132 -0
- package/src/aldehyde/draw-canvas/edit/components/render/tools/z-index-tool.ts +227 -0
- package/src/aldehyde/draw-canvas/edit/components/render/types.ts +287 -0
- package/src/aldehyde/draw-canvas/edit/components/render/utils/a-star.ts +116 -0
- package/src/aldehyde/draw-canvas/edit/components/render/utils/bezier-scene-func.ts +73 -0
- package/src/aldehyde/draw-canvas/edit/components/setting-form/index.tsx +200 -0
- package/src/aldehyde/draw-canvas/edit/index.less +34 -0
- package/src/aldehyde/draw-canvas/edit/index.tsx +138 -0
- package/src/aldehyde/form/form-Item-group.tsx +1 -0
- package/src/aldehyde/icon/local-aliIcon/iconfont.js +1 -1
- package/src/aldehyde/tmpl/hcservice-v3.tsx +14 -0
- package/src/aldehyde/tmpl/interface.tsx +2 -0
- package/src/aldehyde/units/index.tsx +15 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import Konva from 'konva';
|
|
2
|
+
import { Render } from '../index';
|
|
3
|
+
import { GraphDraw, LinkDraw, RulerDraw, PreviewDraw } from '../draws';
|
|
4
|
+
|
|
5
|
+
// 层接工具
|
|
6
|
+
|
|
7
|
+
export class ZIndexTool {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
static readonly name = 'ZIndexTool';
|
|
10
|
+
|
|
11
|
+
private render: Render;
|
|
12
|
+
constructor(render: Render) {
|
|
13
|
+
this.render = render;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// 获取移动节点
|
|
17
|
+
getNodes(nodes: Konva.Node[]) {
|
|
18
|
+
const targets: Konva.Node[] = [];
|
|
19
|
+
for (const node of nodes) {
|
|
20
|
+
if (node instanceof Konva.Transformer) {
|
|
21
|
+
// 已选择的节点
|
|
22
|
+
targets.push(...this.render.selectionTool.selectingNodes);
|
|
23
|
+
} else {
|
|
24
|
+
// 未选择的节点
|
|
25
|
+
targets.push(node);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return targets;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 最大 zIndex
|
|
32
|
+
getMaxZIndex() {
|
|
33
|
+
return Math.max(
|
|
34
|
+
...this.render.layer
|
|
35
|
+
.getChildren((node) => !this.render.ignore(node))
|
|
36
|
+
.map((o) => o.zIndex())
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 最小 zIndex
|
|
41
|
+
getMinZIndex() {
|
|
42
|
+
return Math.min(
|
|
43
|
+
...this.render.layer
|
|
44
|
+
.getChildren((node) => !this.render.ignore(node))
|
|
45
|
+
.map((o) => o.zIndex())
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 记录选择期间的 zIndex
|
|
50
|
+
updateSelectingZIndex(nodes: Konva.Node[]) {
|
|
51
|
+
for (const node of nodes) {
|
|
52
|
+
node.setAttrs({
|
|
53
|
+
selectingZIndex: node.zIndex()
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 恢复选择期间的 zIndex
|
|
59
|
+
resetSelectingZIndex(nodes: Konva.Node[]) {
|
|
60
|
+
nodes.sort((a, b) => a.zIndex() - b.zIndex());
|
|
61
|
+
for (const node of nodes) {
|
|
62
|
+
node.zIndex(node.attrs.selectingZIndex);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 更新 zIndex 缓存
|
|
67
|
+
updateLastZindex(nodes: Konva.Node[]) {
|
|
68
|
+
for (const node of nodes) {
|
|
69
|
+
node.setAttrs({ lastZIndex: node.zIndex() });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 上移
|
|
74
|
+
up(nodes: Konva.Node[]) {
|
|
75
|
+
// 最大zIndex
|
|
76
|
+
const maxZIndex = this.getMaxZIndex();
|
|
77
|
+
const sorted = this.getNodes(nodes).sort((a, b) => b.zIndex() - a.zIndex());
|
|
78
|
+
// 上移
|
|
79
|
+
let lastNode: Konva.Node | null = null;
|
|
80
|
+
if (this.render.selectionTool.selectingNodes.length > 0) {
|
|
81
|
+
this.updateSelectingZIndex(sorted);
|
|
82
|
+
for (const node of sorted) {
|
|
83
|
+
if (
|
|
84
|
+
node.attrs.lastZIndex < maxZIndex &&
|
|
85
|
+
(lastNode === null || node.attrs.lastZIndex < lastNode.attrs.lastZIndex - 1)
|
|
86
|
+
) {
|
|
87
|
+
node.setAttrs({
|
|
88
|
+
lastZIndex: node.attrs.lastZIndex + 1
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
lastNode = node;
|
|
92
|
+
}
|
|
93
|
+
this.resetSelectingZIndex(sorted);
|
|
94
|
+
} else {
|
|
95
|
+
// 直接调整
|
|
96
|
+
for (const node of sorted) {
|
|
97
|
+
if (
|
|
98
|
+
node.zIndex() < maxZIndex &&
|
|
99
|
+
(lastNode === null || node.zIndex() < lastNode.zIndex() - 1)
|
|
100
|
+
) {
|
|
101
|
+
node.zIndex(node.zIndex() + 1);
|
|
102
|
+
}
|
|
103
|
+
lastNode = node;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this.updateLastZindex(sorted);
|
|
107
|
+
// 更新历史
|
|
108
|
+
this.render.updateHistory();
|
|
109
|
+
// 重绘
|
|
110
|
+
this.render.redraw([
|
|
111
|
+
GraphDraw.name,
|
|
112
|
+
LinkDraw.name,
|
|
113
|
+
RulerDraw.name,
|
|
114
|
+
PreviewDraw.name
|
|
115
|
+
]);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// 下移
|
|
120
|
+
down(nodes: Konva.Node[]) {
|
|
121
|
+
// 最小 zIndex
|
|
122
|
+
const minZIndex = this.getMinZIndex();
|
|
123
|
+
const sorted = this.getNodes(nodes).sort((a, b) => a.zIndex() - b.zIndex());
|
|
124
|
+
// 下移
|
|
125
|
+
let lastNode: Konva.Node | null = null;
|
|
126
|
+
|
|
127
|
+
if (this.render.selectionTool.selectingNodes.length > 0) {
|
|
128
|
+
this.updateSelectingZIndex(sorted);
|
|
129
|
+
|
|
130
|
+
for (const node of sorted) {
|
|
131
|
+
if (
|
|
132
|
+
node.attrs.lastZIndex > minZIndex &&
|
|
133
|
+
(lastNode === null || node.attrs.lastZIndex > lastNode.attrs.lastZIndex + 1)
|
|
134
|
+
) {
|
|
135
|
+
node.setAttrs({ lastZIndex: node.attrs.lastZIndex - 1 });
|
|
136
|
+
}
|
|
137
|
+
lastNode = node;
|
|
138
|
+
}
|
|
139
|
+
this.resetSelectingZIndex(sorted);
|
|
140
|
+
} else {
|
|
141
|
+
// 直接调整
|
|
142
|
+
for (const node of sorted) {
|
|
143
|
+
if (
|
|
144
|
+
node.zIndex() > minZIndex &&
|
|
145
|
+
(lastNode === null || node.zIndex() > lastNode.zIndex() + 1)
|
|
146
|
+
) {
|
|
147
|
+
node.zIndex(node.zIndex() - 1);
|
|
148
|
+
}
|
|
149
|
+
lastNode = node;
|
|
150
|
+
}
|
|
151
|
+
this.updateLastZindex(sorted);
|
|
152
|
+
// 更新历史
|
|
153
|
+
this.render.updateHistory();
|
|
154
|
+
// 重绘
|
|
155
|
+
this.render.redraw([
|
|
156
|
+
GraphDraw.name,
|
|
157
|
+
LinkDraw.name,
|
|
158
|
+
RulerDraw.name,
|
|
159
|
+
PreviewDraw.name
|
|
160
|
+
]);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// 置顶
|
|
165
|
+
top(nodes: Konva.Node[]) {
|
|
166
|
+
// 最大 zIndex
|
|
167
|
+
let maxZIndex = this.getMaxZIndex();
|
|
168
|
+
const sorted = this.getNodes(nodes).sort((a, b) => b.zIndex() - a.zIndex());
|
|
169
|
+
if (this.render.selectionTool.selectingNodes.length > 0) {
|
|
170
|
+
// 先选中再调整
|
|
171
|
+
this.updateSelectingZIndex(sorted);
|
|
172
|
+
// 置顶
|
|
173
|
+
for (const node of sorted) {
|
|
174
|
+
node.setAttrs({ lastZIndex: maxZIndex-- });
|
|
175
|
+
}
|
|
176
|
+
this.resetSelectingZIndex(sorted);
|
|
177
|
+
} else {
|
|
178
|
+
// 直接调整
|
|
179
|
+
for (const node of sorted) {
|
|
180
|
+
node.zIndex(maxZIndex);
|
|
181
|
+
}
|
|
182
|
+
this.updateLastZindex(sorted);
|
|
183
|
+
// 更新历史
|
|
184
|
+
this.render.updateHistory();
|
|
185
|
+
// 重绘
|
|
186
|
+
this.render.redraw([
|
|
187
|
+
GraphDraw.name,
|
|
188
|
+
LinkDraw.name,
|
|
189
|
+
RulerDraw.name,
|
|
190
|
+
PreviewDraw.name
|
|
191
|
+
]);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// 置底
|
|
196
|
+
bottom(nodes: Konva.Node[]) {
|
|
197
|
+
// 最小 zIndex
|
|
198
|
+
let minZIndex = this.getMinZIndex();
|
|
199
|
+
const sorted = this.getNodes(nodes).sort((a, b) => a.zIndex() - b.zIndex());
|
|
200
|
+
if (this.render.selectionTool.selectingNodes.length > 0) {
|
|
201
|
+
// 先选中再调整
|
|
202
|
+
this.updateSelectingZIndex(sorted);
|
|
203
|
+
// 置底
|
|
204
|
+
for (const node of sorted) {
|
|
205
|
+
node.setAttrs({
|
|
206
|
+
lastZIndex: minZIndex++
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
this.resetSelectingZIndex(sorted);
|
|
210
|
+
} else {
|
|
211
|
+
// 直接调整
|
|
212
|
+
for (const node of sorted) {
|
|
213
|
+
node.zIndex(minZIndex);
|
|
214
|
+
}
|
|
215
|
+
this.updateLastZindex(sorted);
|
|
216
|
+
// 更新历史
|
|
217
|
+
this.render.updateHistory();
|
|
218
|
+
// 重绘
|
|
219
|
+
this.render.redraw([
|
|
220
|
+
GraphDraw.name,
|
|
221
|
+
LinkDraw.name,
|
|
222
|
+
RulerDraw.name,
|
|
223
|
+
PreviewDraw.name
|
|
224
|
+
]);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import Konva from 'konva';
|
|
2
|
+
import { Render } from './index';
|
|
3
|
+
|
|
4
|
+
export interface RenderConfig {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
showBg?: boolean;
|
|
8
|
+
showRuler?: boolean;
|
|
9
|
+
showRefLine?: boolean;
|
|
10
|
+
showPreview?: boolean;
|
|
11
|
+
showContextmenu?: boolean;
|
|
12
|
+
attractResize?: boolean;
|
|
13
|
+
attractBg?: boolean;
|
|
14
|
+
attractNode?: boolean;
|
|
15
|
+
readonly?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type RenderEvents = {
|
|
19
|
+
['history-change']: { records: string[]; index: number };
|
|
20
|
+
['selection-change']: Konva.Node[];
|
|
21
|
+
['link-type-change']: LinkType;
|
|
22
|
+
['scale-change']: number;
|
|
23
|
+
['loading']: boolean;
|
|
24
|
+
['graph-type-change']: GraphType | undefined;
|
|
25
|
+
['texting-change']: boolean;
|
|
26
|
+
['page-settings-change']: PageSettings;
|
|
27
|
+
['link-selection-change']: Konva.Line | undefined;
|
|
28
|
+
['asset-position-change']: Konva.Node[];
|
|
29
|
+
['asset-rotation-change']: Konva.Node[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface Handler {
|
|
33
|
+
handlers?: {
|
|
34
|
+
stage?: {
|
|
35
|
+
[index: string]: (e?: any) => void | boolean
|
|
36
|
+
};
|
|
37
|
+
dom?: {
|
|
38
|
+
[index: string]: (e?: any) => void
|
|
39
|
+
};
|
|
40
|
+
transformer?: {
|
|
41
|
+
[index: string]: (e?: any) => void
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
transformerConfig?: {
|
|
45
|
+
anchorDragBoundFunc?: (
|
|
46
|
+
oldPos: Konva.Vector2d,
|
|
47
|
+
newPos: Konva.Vector2d,
|
|
48
|
+
e: MouseEvent
|
|
49
|
+
) => Konva.Vector2d;
|
|
50
|
+
dragBoundFunc?: (newPos: Konva.Vector2d, e: MouseEvent) => Konva.Vector2d
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export enum MouseButton {
|
|
55
|
+
左键 = 0,
|
|
56
|
+
右键 = 2
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface Draw {
|
|
60
|
+
readonly layer: Konva.Layer;
|
|
61
|
+
option: {
|
|
62
|
+
[index: string]: any
|
|
63
|
+
};
|
|
64
|
+
init: () => void;
|
|
65
|
+
draw: () => void;
|
|
66
|
+
clear: () => void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export class BaseDraw {
|
|
70
|
+
protected render: Render;
|
|
71
|
+
readonly layer: Konva.Layer;
|
|
72
|
+
protected group: Konva.Group;
|
|
73
|
+
constructor(render: Render, layer: Konva.Layer) {
|
|
74
|
+
this.render = render;
|
|
75
|
+
this.layer = layer;
|
|
76
|
+
this.group = new Konva.Group();
|
|
77
|
+
}
|
|
78
|
+
init() {
|
|
79
|
+
this.layer.add(this.group);
|
|
80
|
+
this.draw();
|
|
81
|
+
}
|
|
82
|
+
draw() { }
|
|
83
|
+
clear() {
|
|
84
|
+
// 重置
|
|
85
|
+
this.group.destroy();
|
|
86
|
+
const name = this.group.name();
|
|
87
|
+
this.group = new Konva.Group({ name });
|
|
88
|
+
this.layer.add(this.group);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { Render }
|
|
93
|
+
|
|
94
|
+
export interface AssetInfoPoint {
|
|
95
|
+
x: number;
|
|
96
|
+
y: number;
|
|
97
|
+
direction?: 'top' | 'bottom' | 'left' | 'right'; // 人为定义连接点属于元素的什么方向
|
|
98
|
+
alias?: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface AssetInfo {
|
|
102
|
+
url: string;
|
|
103
|
+
avatar?: string; // 子素材需要额外的封面
|
|
104
|
+
points?: Array<AssetInfoPoint>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export enum MoveKey {
|
|
108
|
+
上 = 'ArrowUp',
|
|
109
|
+
左 = 'ArrowLeft',
|
|
110
|
+
右 = 'ArrowRight',
|
|
111
|
+
下 = 'ArrowDown'
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export enum ShutcutKey {
|
|
115
|
+
删除 = 'Delete',
|
|
116
|
+
C = 'KeyC',
|
|
117
|
+
V = 'KeyV',
|
|
118
|
+
Z = 'KeyZ',
|
|
119
|
+
A = 'KeyA',
|
|
120
|
+
R = 'KeyR',
|
|
121
|
+
Esc = 'Escape',
|
|
122
|
+
Backspace = 'Backspace',
|
|
123
|
+
Enter = 'Enter'
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 布局类型
|
|
127
|
+
export type AlignType = "Middle" | "Left" | "Right" | "Center" | "Top" | "Bottom";
|
|
128
|
+
|
|
129
|
+
// 连接线 类型
|
|
130
|
+
export type LinkType = "auto" | "curve" | "bezier" | "manual" | "straight";
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 连接对
|
|
134
|
+
*/
|
|
135
|
+
export interface LinkDrawPair {
|
|
136
|
+
id: string;
|
|
137
|
+
from: {
|
|
138
|
+
groupId: string;
|
|
139
|
+
pointId: string;
|
|
140
|
+
rawGroupId?: string; // 预留
|
|
141
|
+
};
|
|
142
|
+
to: {
|
|
143
|
+
groupId: string;
|
|
144
|
+
pointId: string;
|
|
145
|
+
rawGroupId?: string; // 预留
|
|
146
|
+
};
|
|
147
|
+
disabled?: boolean; // 标记为 true,算法会忽略该 pair 的画线逻辑
|
|
148
|
+
linkType?: LinkType; // 连接线类型
|
|
149
|
+
style?: Konva.LineConfig & LinkSettings
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 连接点
|
|
154
|
+
*/
|
|
155
|
+
export interface LinkDrawPoint {
|
|
156
|
+
id: string;
|
|
157
|
+
groupId: string;
|
|
158
|
+
rawGroupId?: string; // 预留
|
|
159
|
+
visible: boolean;
|
|
160
|
+
pairs: LinkDrawPair[];
|
|
161
|
+
x: number;
|
|
162
|
+
y: number;
|
|
163
|
+
direction?: 'top' | 'bottom' | 'left' | 'right'; // 人为定义连接点属于元素的什么方向
|
|
164
|
+
alias?: string
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* 连接线 拐点
|
|
169
|
+
*/
|
|
170
|
+
export interface ManualPoint {
|
|
171
|
+
x: number;
|
|
172
|
+
y: number;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* 连接线 拐点 表
|
|
177
|
+
*/
|
|
178
|
+
export interface ManualPointsMap {
|
|
179
|
+
[index: string]: ManualPoint[]
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* 直线、折线 拐点
|
|
184
|
+
*/
|
|
185
|
+
export interface LineManualPoint {
|
|
186
|
+
x: number;
|
|
187
|
+
y: number;
|
|
188
|
+
index: number;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* 图形类型
|
|
193
|
+
*/
|
|
194
|
+
export type GraphType = 'Line' | 'Curve' | 'Rect' | 'Circle' | 'Bezier';
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* 图形 的 调整点 信息
|
|
198
|
+
*/
|
|
199
|
+
export interface GraphAnchor {
|
|
200
|
+
type?: GraphType;
|
|
201
|
+
adjustType: string;
|
|
202
|
+
name?: string;
|
|
203
|
+
groupId?: string;
|
|
204
|
+
adjusted?: boolean;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* 图形 的 调整点 图形、锚点关系
|
|
209
|
+
*/
|
|
210
|
+
export interface GraphAnchorShape {
|
|
211
|
+
shape: Konva.Shape;
|
|
212
|
+
anchorShadow: Konva.Circle
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* 素材类型
|
|
217
|
+
*/
|
|
218
|
+
export enum AssetType {
|
|
219
|
+
'Image' = 'Image',
|
|
220
|
+
'Json' = 'Json',
|
|
221
|
+
'Graph' = 'Graph',
|
|
222
|
+
'Text' = 'Text'
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* 图片类型
|
|
227
|
+
*/
|
|
228
|
+
export enum ImageType {
|
|
229
|
+
'svg' = 'svg',
|
|
230
|
+
'gif' = 'gif',
|
|
231
|
+
'other' = 'other'
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* 对齐信息
|
|
236
|
+
*/
|
|
237
|
+
export interface SortItem {
|
|
238
|
+
id?: number; // 有 id 就是其他节点,否则就是 选择目标
|
|
239
|
+
value: number // 左、垂直中、右的 x 坐标值; 上、水平中、下的 y 坐标值;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* 页面设置
|
|
244
|
+
*/
|
|
245
|
+
export interface PageSettings {
|
|
246
|
+
// 画布尺寸
|
|
247
|
+
pageWidth: number;
|
|
248
|
+
pageHeight: number;
|
|
249
|
+
// 样式设置
|
|
250
|
+
background: string;
|
|
251
|
+
stroke: string;
|
|
252
|
+
strokeWidth: number;
|
|
253
|
+
fill: string;
|
|
254
|
+
linkStroke: string;
|
|
255
|
+
linkStrokeWidth: number;
|
|
256
|
+
fontSize: number;
|
|
257
|
+
textFill: string
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* 素材设置
|
|
262
|
+
*/
|
|
263
|
+
export interface AssetSettings {
|
|
264
|
+
stroke: string;
|
|
265
|
+
strokeWidth: number;
|
|
266
|
+
fill: string;
|
|
267
|
+
arrowStart: boolean;
|
|
268
|
+
arrowEnd: boolean;
|
|
269
|
+
fontSize: number;
|
|
270
|
+
textFill: string;
|
|
271
|
+
text: string;
|
|
272
|
+
x: number;
|
|
273
|
+
y: number;
|
|
274
|
+
rotation: number;
|
|
275
|
+
tension: number;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* 连接线设置
|
|
280
|
+
*/
|
|
281
|
+
export interface LinkSettings {
|
|
282
|
+
stroke: string;
|
|
283
|
+
strokeWidth: number;
|
|
284
|
+
arrowStart: boolean;
|
|
285
|
+
arrowEnd: boolean;
|
|
286
|
+
tension: number;
|
|
287
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
export interface Node {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
cost?: number; // 代价
|
|
5
|
+
parent?: Node; // 上一步
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default function aStar(config: {
|
|
9
|
+
from: Node; // 起点
|
|
10
|
+
to: Node; // 终点
|
|
11
|
+
matrix: number[][]; // 矩阵
|
|
12
|
+
maxCost: number // 作为墙的值
|
|
13
|
+
}): Node[] {
|
|
14
|
+
const { from, to, matrix, maxCost = 1 } = config;
|
|
15
|
+
const grid: Node[][] = matrixToGrid(matrix);
|
|
16
|
+
const start = grid[from.y][from.x];
|
|
17
|
+
const goal = grid[to.y][to.x];
|
|
18
|
+
// 初始化 open 和 closed 列表
|
|
19
|
+
const open: Node[] = [start];
|
|
20
|
+
const closed = new Set<Node>();
|
|
21
|
+
// 初始化每个节点的 f, g, h 值
|
|
22
|
+
const f = new Map<Node, number>();
|
|
23
|
+
const g = new Map<Node, number>();
|
|
24
|
+
const h = new Map<Node, number>();
|
|
25
|
+
g.set(start, 0);
|
|
26
|
+
h.set(start, manhattanDistance(start, goal));
|
|
27
|
+
f.set(start, g.get(start)! + h.get(start)!);
|
|
28
|
+
// A* 算法主循环
|
|
29
|
+
while (open.length > 0) {
|
|
30
|
+
// 从 open 列表中找到 f 值最小的节点
|
|
31
|
+
const current = open.reduce((a, b) => (f.get(a)! < f.get(b)! ? a : b));
|
|
32
|
+
// 如果当前节点是目标节点,返回路径
|
|
33
|
+
if (current === goal) {
|
|
34
|
+
return reconstructPath(goal);
|
|
35
|
+
}
|
|
36
|
+
// 将当前节点从 open 列表中移除,并加入 closed 列表
|
|
37
|
+
open.splice(open.indexOf(current), 1);
|
|
38
|
+
closed.add(current);
|
|
39
|
+
// 遍历当前节点的邻居
|
|
40
|
+
for (const neighbor of getNeighbors(current, grid)) {
|
|
41
|
+
// 如果邻居节点已经在 closed 列表中,跳过
|
|
42
|
+
if (closed.has(neighbor)) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
// 计算从起点到邻居节点的距离(转弯距离增加)
|
|
46
|
+
const tentativeG =
|
|
47
|
+
g.get(current)! + // 累计距离
|
|
48
|
+
(neighbor.cost ?? 1) + // 下一步距离
|
|
49
|
+
((current.x === current.parent?.x && current.x !== neighbor.x) ||
|
|
50
|
+
(current.y === current.parent?.y && current.y !== neighbor.y)
|
|
51
|
+
? grid.length + grid[0].length
|
|
52
|
+
: 0);
|
|
53
|
+
// 如果邻居节点不在 open 列表中,或者新的 g 值更小,更新邻居节点的 g, h, f 值,并将其加入 open 列表
|
|
54
|
+
if (!open.includes(neighbor) || tentativeG < g.get(neighbor)!) {
|
|
55
|
+
g.set(neighbor, tentativeG);
|
|
56
|
+
h.set(neighbor, manhattanDistance(neighbor, goal));
|
|
57
|
+
f.set(neighbor, g.get(neighbor)! + h.get(neighbor)!);
|
|
58
|
+
neighbor.parent = current;
|
|
59
|
+
if (!open.includes(neighbor)) {
|
|
60
|
+
open.push(neighbor);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 如果 open 列表为空,表示无法到达目标节点,返回 null
|
|
67
|
+
return [];
|
|
68
|
+
|
|
69
|
+
// 数据转换
|
|
70
|
+
function matrixToGrid(matrix: number[][]) {
|
|
71
|
+
const mt: Node[][] = [];
|
|
72
|
+
for (let y = 0; y < matrix.length; y++) {
|
|
73
|
+
if (mt[y] === void 0) {
|
|
74
|
+
mt[y] = [];
|
|
75
|
+
}
|
|
76
|
+
for (let x = 0; x < matrix[y].length; x++) {
|
|
77
|
+
mt[y].push({ x, y, cost: matrix[y][x] });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return mt;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 从目标节点开始,沿着 parent 指针重构路径
|
|
84
|
+
function reconstructPath(node: Node): Node[] {
|
|
85
|
+
const path = [node];
|
|
86
|
+
while (node.parent) {
|
|
87
|
+
path.push(node.parent);
|
|
88
|
+
node = node.parent;
|
|
89
|
+
}
|
|
90
|
+
return path.reverse();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 计算曼哈顿距离
|
|
94
|
+
function manhattanDistance(a: Node, b: Node): number {
|
|
95
|
+
return Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 获取当前节点的邻居
|
|
99
|
+
function getNeighbors(node: Node, grid: Node[][]): Node[] {
|
|
100
|
+
const neighbors = [];
|
|
101
|
+
const { x, y } = node;
|
|
102
|
+
if (x > 0 && (grid[y][x - 1].cost ?? 0) < maxCost) {
|
|
103
|
+
neighbors.push(grid[y][x - 1]);
|
|
104
|
+
}
|
|
105
|
+
if (x < grid[0].length - 1 && (grid[y][x + 1].cost ?? 0) < maxCost) {
|
|
106
|
+
neighbors.push(grid[y][x + 1]);
|
|
107
|
+
}
|
|
108
|
+
if (y > 0 && (grid[y - 1][x].cost ?? 0) < maxCost) {
|
|
109
|
+
neighbors.push(grid[y - 1][x]);
|
|
110
|
+
}
|
|
111
|
+
if (y < grid.length - 1 && (grid[y + 1][x].cost ?? 0) < maxCost) {
|
|
112
|
+
neighbors.push(grid[y + 1][x]);
|
|
113
|
+
}
|
|
114
|
+
return neighbors;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import Konva from 'konva';
|
|
2
|
+
|
|
3
|
+
function rotatePoint(x1: number, y1: number, x2: number, y2: number, angleInDegrees: number) {
|
|
4
|
+
const radians = angleInDegrees * (Math.PI / 180);
|
|
5
|
+
const cosTheta = Math.cos(radians);
|
|
6
|
+
const sinTheta = Math.sin(radians);
|
|
7
|
+
|
|
8
|
+
// Translate point (x2, y2) to be relative to (x1, y1)
|
|
9
|
+
const x = x2 - x1;
|
|
10
|
+
const y = y2 - y1;
|
|
11
|
+
|
|
12
|
+
// Rotate point
|
|
13
|
+
const xPrime = cosTheta * x - sinTheta * y;
|
|
14
|
+
const yPrime = sinTheta * x + cosTheta * y;
|
|
15
|
+
|
|
16
|
+
// Translate back
|
|
17
|
+
const xNew = xPrime + x1;
|
|
18
|
+
const yNew = yPrime + y1;
|
|
19
|
+
|
|
20
|
+
return { x: xNew, y: yNew };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function drawPointer(ctx: Konva.Context, shape: Konva.Shape, startX: number, startY: number, ctrlX: number, ctrlY: number) {
|
|
24
|
+
const x2 = startX + 12;
|
|
25
|
+
const y2 = startY - 6;
|
|
26
|
+
const x3 = startX + 12;
|
|
27
|
+
const y3 = startY + 6;
|
|
28
|
+
const angle = (Math.atan2(ctrlY - startY, ctrlX - startX) * 180) / Math.PI;
|
|
29
|
+
const p2 = rotatePoint(startX, startY, x2, y2, angle);
|
|
30
|
+
const p3 = rotatePoint(startX, startY, x3, y3, angle);
|
|
31
|
+
ctx.beginPath();
|
|
32
|
+
ctx.moveTo(startX, startY);
|
|
33
|
+
ctx.lineTo(p2.x, p2.y);
|
|
34
|
+
ctx.lineTo(p3.x, p3.y);
|
|
35
|
+
ctx.lineTo(startX, startY);
|
|
36
|
+
ctx.lineTo(p2.x, p2.y);
|
|
37
|
+
ctx.strokeShape(shape);
|
|
38
|
+
ctx.fillShape(shape);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function BezierSceneFunc(ctx: Konva.Context, shape: Konva.Shape) {
|
|
42
|
+
if (shape instanceof Konva.Arrow) {
|
|
43
|
+
const ps = shape.points();
|
|
44
|
+
if (ps.length / 2 === 4) {
|
|
45
|
+
// 三次
|
|
46
|
+
ctx.beginPath();
|
|
47
|
+
ctx.moveTo(ps[0], ps[1]);
|
|
48
|
+
ctx.bezierCurveTo(ps[2], ps[3], ps[4], ps[5], ps[6], ps[7]);
|
|
49
|
+
ctx.strokeShape(shape);
|
|
50
|
+
ctx.closePath();
|
|
51
|
+
shape.pointerAtBeginning() && drawPointer(ctx, shape, ps[0], ps[1], ps[2], ps[3]);
|
|
52
|
+
shape.pointerAtEnding() && drawPointer(ctx, shape, ps[6], ps[7], ps[4], ps[5]);
|
|
53
|
+
} else if (ps.length / 2 === 3) {
|
|
54
|
+
// 二次
|
|
55
|
+
ctx.beginPath();
|
|
56
|
+
ctx.moveTo(ps[0], ps[1]);
|
|
57
|
+
ctx.quadraticCurveTo(ps[2], ps[3], ps[4], ps[5]);
|
|
58
|
+
ctx.strokeShape(shape);
|
|
59
|
+
ctx.closePath();
|
|
60
|
+
shape.pointerAtBeginning() && drawPointer(ctx, shape, ps[0], ps[1], ps[2], ps[3]);
|
|
61
|
+
shape.pointerAtEnding() && drawPointer(ctx, shape, ps[4], ps[5], ps[2], ps[3]);
|
|
62
|
+
} else {
|
|
63
|
+
// 直线
|
|
64
|
+
ctx.beginPath();
|
|
65
|
+
ctx.moveTo(ps[0], ps[1]);
|
|
66
|
+
ctx.lineTo(ps[2], ps[3]);
|
|
67
|
+
ctx.strokeShape(shape);
|
|
68
|
+
ctx.closePath();
|
|
69
|
+
shape.pointerAtBeginning() && drawPointer(ctx, shape, ps[0], ps[1], ps[2], ps[3]);
|
|
70
|
+
shape.pointerAtEnding() && drawPointer(ctx, shape, ps[2], ps[3], ps[0], ps[1]);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|