@rsconcept/domain 1.0.0 → 1.1.0
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/README.md +3 -3
- package/dist/analyzer-DlSq3Y3r.d.ts +39 -0
- package/dist/arguments-extractor-1acwjQNc.d.ts +38 -0
- package/dist/ast-C8sIpKdL.d.ts +51 -0
- package/dist/ast-annotations-BiMjkKvz.d.ts +16 -0
- package/dist/branded-ZlzIcxzu.d.ts +9 -0
- package/dist/calculator-C9W2jkSx.d.ts +39 -0
- package/dist/cctext/index.d.ts +2 -1
- package/dist/cctext/index.js +2 -42
- package/dist/cctext/language-api.d.ts +10 -12
- package/dist/cctext/language-api.js +157 -227
- package/dist/cctext/language-api.js.map +1 -1
- package/dist/cctext/language.d.ts +24 -22
- package/dist/cctext/language.js +43 -39
- package/dist/cctext/language.js.map +1 -1
- package/dist/error-E1LVq_3w.d.ts +87 -0
- package/dist/graph/graph.d.ts +2 -62
- package/dist/graph/graph.js +339 -382
- package/dist/graph/graph.js.map +1 -1
- package/dist/graph/index.d.ts +2 -1
- package/dist/graph/index.js +2 -384
- package/dist/graph-DR8rL2o3.d.ts +64 -0
- package/dist/hash-Y8I4c6Al.d.ts +8 -0
- package/dist/index-BKZ67WMa.d.ts +1 -0
- package/dist/index-BVVgDSdq.d.ts +1 -0
- package/dist/index-DmtQKWjk.d.ts +1 -0
- package/dist/index-_6s0AX1B.d.ts +1 -0
- package/dist/index.d.ts +27 -28
- package/dist/index.js +23 -5851
- package/dist/lezer-tree-iS7LpLBJ.d.ts +14 -0
- package/dist/library/folder-tree.d.ts +22 -20
- package/dist/library/folder-tree.js +108 -130
- package/dist/library/folder-tree.js.map +1 -1
- package/dist/library/index.d.ts +8 -17
- package/dist/library/index.js +7 -2800
- package/dist/library/library-api.d.ts +3 -1
- package/dist/library/library-api.js +9 -8
- package/dist/library/library-api.js.map +1 -1
- package/dist/library/library.d.ts +2 -56
- package/dist/library/library.js +23 -19
- package/dist/library/library.js.map +1 -1
- package/dist/library/oss-api.d.ts +26 -37
- package/dist/library/oss-api.js +257 -1096
- package/dist/library/oss-api.js.map +1 -1
- package/dist/library/oss-layout-api.d.ts +28 -28
- package/dist/library/oss-layout-api.js +239 -316
- package/dist/library/oss-layout-api.js.map +1 -1
- package/dist/library/oss-layout.d.ts +2 -25
- package/dist/library/oss-layout.js +1 -1
- package/dist/library/oss.d.ts +87 -89
- package/dist/library/oss.js +27 -26
- package/dist/library/oss.js.map +1 -1
- package/dist/library/rsengine.d.ts +100 -106
- package/dist/library/rsengine.js +439 -2599
- package/dist/library/rsengine.js.map +1 -1
- package/dist/library/rsform-api.d.ts +11 -16
- package/dist/library/rsform-api.js +313 -825
- package/dist/library/rsform-api.js.map +1 -1
- package/dist/library/rsform.d.ts +159 -167
- package/dist/library/rsform.js +29 -28
- package/dist/library/rsform.js.map +1 -1
- package/dist/library/rsmodel-api.d.ts +8 -15
- package/dist/library/rsmodel-api.js +172 -813
- package/dist/library/rsmodel-api.js.map +1 -1
- package/dist/library/rsmodel.d.ts +27 -33
- package/dist/library/rsmodel.js +16 -23
- package/dist/library/rsmodel.js.map +1 -1
- package/dist/library/structure-planner.d.ts +20 -26
- package/dist/library/structure-planner.js +106 -474
- package/dist/library/structure-planner.js.map +1 -1
- package/dist/library-CYun28Xz.d.ts +58 -0
- package/dist/oss-layout-3glgAqfn.d.ts +27 -0
- package/dist/parser-Bwd8LxJ1.d.ts +7 -0
- package/dist/parsing/ast.d.ts +2 -49
- package/dist/parsing/ast.js +68 -76
- package/dist/parsing/ast.js.map +1 -1
- package/dist/parsing/index.d.ts +3 -3
- package/dist/parsing/index.js +3 -141
- package/dist/parsing/lezer-tree.d.ts +2 -13
- package/dist/parsing/lezer-tree.js +50 -43
- package/dist/parsing/lezer-tree.js.map +1 -1
- package/dist/rslang/api.d.ts +9 -14
- package/dist/rslang/api.js +114 -827
- package/dist/rslang/api.js.map +1 -1
- package/dist/rslang/ast-annotations.d.ts +2 -18
- package/dist/rslang/ast-annotations.js +34 -45
- package/dist/rslang/ast-annotations.js.map +1 -1
- package/dist/rslang/error.d.ts +2 -85
- package/dist/rslang/error.js +88 -150
- package/dist/rslang/error.js.map +1 -1
- package/dist/rslang/eval/calculator.d.ts +2 -43
- package/dist/rslang/eval/calculator.js +81 -1636
- package/dist/rslang/eval/calculator.js.map +1 -1
- package/dist/rslang/eval/evaluation-cache.d.ts +22 -26
- package/dist/rslang/eval/evaluation-cache.js +168 -287
- package/dist/rslang/eval/evaluation-cache.js.map +1 -1
- package/dist/rslang/eval/evaluator.d.ts +59 -63
- package/dist/rslang/eval/evaluator.js +602 -1509
- package/dist/rslang/eval/evaluator.js.map +1 -1
- package/dist/rslang/eval/value-api.d.ts +2 -48
- package/dist/rslang/eval/value-api.js +2 -490
- package/dist/rslang/eval/value.d.ts +2 -36
- package/dist/rslang/eval/value.js +2 -118
- package/dist/rslang/index.d.ts +14 -17
- package/dist/rslang/index.js +12 -4314
- package/dist/rslang/labels.d.ts +6 -6
- package/dist/rslang/labels.js +139 -305
- package/dist/rslang/labels.js.map +1 -1
- package/dist/rslang/parser/expression-generator.d.ts +5 -5
- package/dist/rslang/parser/expression-generator.js +248 -446
- package/dist/rslang/parser/expression-generator.js.map +1 -1
- package/dist/rslang/parser/normalize.d.ts +4 -8
- package/dist/rslang/parser/normalize.js +286 -481
- package/dist/rslang/parser/normalize.js.map +1 -1
- package/dist/rslang/parser/parser.d.ts +2 -5
- package/dist/rslang/parser/parser.js +30 -21
- package/dist/rslang/parser/parser.js.map +1 -1
- package/dist/rslang/parser/parser.terms.d.ts +43 -41
- package/dist/rslang/parser/parser.terms.js +44 -83
- package/dist/rslang/parser/parser.terms.js.map +1 -1
- package/dist/rslang/parser/syntax-errors.d.ts +5 -8
- package/dist/rslang/parser/syntax-errors.js +113 -382
- package/dist/rslang/parser/syntax-errors.js.map +1 -1
- package/dist/rslang/parser/token.d.ts +2 -79
- package/dist/rslang/parser/token.js +81 -93
- package/dist/rslang/parser/token.js.map +1 -1
- package/dist/rslang/semantic/analyzer.d.ts +2 -39
- package/dist/rslang/semantic/analyzer.js +186 -2600
- package/dist/rslang/semantic/analyzer.js.map +1 -1
- package/dist/rslang/semantic/arguments-extractor.d.ts +2 -42
- package/dist/rslang/semantic/arguments-extractor.js +202 -361
- package/dist/rslang/semantic/arguments-extractor.js.map +1 -1
- package/dist/rslang/semantic/type-auditor.d.ts +64 -68
- package/dist/rslang/semantic/type-auditor.js +594 -1564
- package/dist/rslang/semantic/type-auditor.js.map +1 -1
- package/dist/rslang/semantic/typification-api.d.ts +4 -7
- package/dist/rslang/semantic/typification-api.js +162 -303
- package/dist/rslang/semantic/typification-api.js.map +1 -1
- package/dist/rslang/semantic/typification-parser.d.ts +2 -12
- package/dist/rslang/semantic/typification-parser.js +165 -219
- package/dist/rslang/semantic/typification-parser.js.map +1 -1
- package/dist/rslang/semantic/typification.d.ts +2 -119
- package/dist/rslang/semantic/typification.js +66 -52
- package/dist/rslang/semantic/typification.js.map +1 -1
- package/dist/rslang/semantic/value-auditor.d.ts +32 -38
- package/dist/rslang/semantic/value-auditor.js +206 -518
- package/dist/rslang/semantic/value-auditor.js.map +1 -1
- package/dist/rslang/semantic/value-class.d.ts +2 -10
- package/dist/rslang/semantic/value-class.js +8 -7
- package/dist/rslang/semantic/value-class.js.map +1 -1
- package/dist/rslang/typification-graph.d.ts +2 -33
- package/dist/rslang/typification-graph.js +94 -306
- package/dist/rslang/typification-graph.js.map +1 -1
- package/dist/shared/branded.d.ts +2 -7
- package/dist/shared/branded.js +1 -1
- package/dist/shared/hash.d.ts +2 -6
- package/dist/shared/hash.js +13 -13
- package/dist/shared/hash.js.map +1 -1
- package/dist/shared/index.d.ts +3 -2
- package/dist/shared/index.js +2 -18
- package/dist/token-DeXAmzwr.d.ts +81 -0
- package/dist/typification-Dk-fisgO.d.ts +120 -0
- package/dist/typification-graph-6HcZ-rKH.d.ts +30 -0
- package/dist/typification-parser-BBVx1RxP.d.ts +13 -0
- package/dist/value-B8UtCqaK.js +366 -0
- package/dist/value-B8UtCqaK.js.map +1 -0
- package/dist/value-CTjX6825.d.ts +33 -0
- package/dist/value-api-Bw-SgaYY.d.ts +49 -0
- package/dist/value-class-CNI-lqXJ.d.ts +12 -0
- package/package.json +8 -8
- package/src/library/rsform-api.test.ts +24 -0
- package/src/library/rsform-api.ts +12 -4
- package/dist/cctext/index.js.map +0 -1
- package/dist/graph/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/library/index.js.map +0 -1
- package/dist/library/oss-layout.js.map +0 -1
- package/dist/parsing/index.js.map +0 -1
- package/dist/rslang/eval/value-api.js.map +0 -1
- package/dist/rslang/eval/value.js.map +0 -1
- package/dist/rslang/index.js.map +0 -1
- package/dist/shared/branded.js.map +0 -1
- package/dist/shared/index.js.map +0 -1
|
@@ -1,330 +1,253 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
SYNTHESIS: "synthesis",
|
|
9
|
-
REPLICA: "replica"
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
// src/library/oss-layout-api.ts
|
|
13
|
-
var GRID_SIZE = 10;
|
|
14
|
-
var MIN_DISTANCE = 2 * GRID_SIZE;
|
|
15
|
-
var OPERATION_NODE_WIDTH = 150;
|
|
16
|
-
var OPERATION_NODE_HEIGHT = 40;
|
|
1
|
+
import { NodeType, OperationType } from "./oss.js";
|
|
2
|
+
//#region src/library/oss-layout-api.ts
|
|
3
|
+
const GRID_SIZE = 10;
|
|
4
|
+
const MIN_DISTANCE = 20;
|
|
5
|
+
const OPERATION_NODE_WIDTH = 150;
|
|
6
|
+
const OPERATION_NODE_HEIGHT = 40;
|
|
7
|
+
/** Layout manipulations for {@link OperationSchema}. */
|
|
17
8
|
var LayoutManager = class {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
closestNode = findClosestNodeByDistance(descendantsNodes, targetNode);
|
|
202
|
-
} else {
|
|
203
|
-
closestNode = findClosestNodeByDistance(lowerNodes, targetNode);
|
|
204
|
-
}
|
|
205
|
-
return closestNode?.nodeID ?? null;
|
|
206
|
-
}
|
|
207
|
-
extendParentBounds(parent, child) {
|
|
208
|
-
if (!parent) {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
const borderX = child.x + child.width + MIN_DISTANCE;
|
|
212
|
-
const borderY = child.y + child.height + MIN_DISTANCE;
|
|
213
|
-
parent.width = Math.max(parent.width, borderX - parent.x);
|
|
214
|
-
parent.height = Math.max(parent.height, borderY - parent.y);
|
|
215
|
-
}
|
|
216
|
-
calculatePositionForFreeOperation(initial) {
|
|
217
|
-
if (this.oss.operations.length === 0) {
|
|
218
|
-
return initial;
|
|
219
|
-
}
|
|
220
|
-
const freeInputs = this.oss.operations.filter(
|
|
221
|
-
(operation) => operation.parent === null && (operation.operation_type !== OperationType.SYNTHESIS || operation.arguments.length === 0)
|
|
222
|
-
).map((operation) => operation.nodeID);
|
|
223
|
-
let inputsPositions = this.layout.filter((pos) => freeInputs.includes(pos.nodeID));
|
|
224
|
-
if (inputsPositions.length === 0) {
|
|
225
|
-
inputsPositions = this.layout.filter((pos) => pos.nodeID.startsWith("o"));
|
|
226
|
-
}
|
|
227
|
-
const maxX = Math.max(...inputsPositions.map((node) => node.x));
|
|
228
|
-
const minY = Math.min(...inputsPositions.map((node) => node.y));
|
|
229
|
-
return {
|
|
230
|
-
x: maxX + OPERATION_NODE_WIDTH + MIN_DISTANCE + GRID_SIZE,
|
|
231
|
-
y: minY
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
calculatePositionForFreeBlock(initial) {
|
|
235
|
-
const rootBlocks = this.oss.blocks.filter((block) => block.parent === null).map((block) => block.nodeID);
|
|
236
|
-
const blocksPositions = this.layout.filter((pos) => rootBlocks.includes(pos.nodeID));
|
|
237
|
-
if (blocksPositions.length === 0) {
|
|
238
|
-
return initial;
|
|
239
|
-
}
|
|
240
|
-
const maxX = Math.max(...blocksPositions.map((node) => node.x + node.width));
|
|
241
|
-
const minY = Math.min(...blocksPositions.map((node) => node.y));
|
|
242
|
-
return { ...initial, x: maxX + MIN_DISTANCE, y: minY };
|
|
243
|
-
}
|
|
244
|
-
calculateOffsetForParentChange(target, parent) {
|
|
245
|
-
const newPosition = { ...target };
|
|
246
|
-
if (parent === null) {
|
|
247
|
-
const rootElements = this.oss.hierarchy.rootNodes();
|
|
248
|
-
const positions = this.layout.filter((pos) => rootElements.includes(pos.nodeID));
|
|
249
|
-
preventOverlap(newPosition, positions);
|
|
250
|
-
} else if (!rectanglesStrictOverlap(target, parent)) {
|
|
251
|
-
newPosition.x = parent.x + MIN_DISTANCE;
|
|
252
|
-
newPosition.y = parent.y + MIN_DISTANCE;
|
|
253
|
-
const siblings = this.oss.hierarchy.at(parent.nodeID)?.outputs ?? [];
|
|
254
|
-
const siblingsPositions = this.layout.filter((pos) => siblings.includes(pos.nodeID));
|
|
255
|
-
preventOverlap(newPosition, siblingsPositions);
|
|
256
|
-
}
|
|
257
|
-
return { x: newPosition.x - target.x, y: newPosition.y - target.y };
|
|
258
|
-
}
|
|
9
|
+
oss;
|
|
10
|
+
layout;
|
|
11
|
+
constructor(oss, layout) {
|
|
12
|
+
this.oss = oss;
|
|
13
|
+
if (layout) this.layout = layout;
|
|
14
|
+
else this.layout = this.oss.layout;
|
|
15
|
+
}
|
|
16
|
+
/** Calculate insert position for a new {@link Operation} */
|
|
17
|
+
newOperationPosition(position, parent, args = []) {
|
|
18
|
+
const result = { ...position };
|
|
19
|
+
const parentNode = this.layout.find((pos) => pos.nodeID === `b${parent}`) ?? null;
|
|
20
|
+
const operations = this.layout.filter((pos) => pos.nodeID.startsWith("o"));
|
|
21
|
+
const hasArguments = args.length !== 0;
|
|
22
|
+
if (hasArguments) {
|
|
23
|
+
const pos = calculatePositionFromArgs(operations.filter((node) => args.includes(Number(node.nodeID.slice(1)))));
|
|
24
|
+
result.x = pos.x;
|
|
25
|
+
result.y = pos.y;
|
|
26
|
+
} else if (parentNode) {
|
|
27
|
+
result.x = parentNode.x + MIN_DISTANCE;
|
|
28
|
+
result.y = parentNode.y + MIN_DISTANCE;
|
|
29
|
+
} else {
|
|
30
|
+
const pos = this.calculatePositionForFreeOperation(result);
|
|
31
|
+
result.x = pos.x;
|
|
32
|
+
result.y = pos.y;
|
|
33
|
+
}
|
|
34
|
+
const siblingBlocks = this.oss.blocks.filter((block) => block.parent === parent).map((block) => block.nodeID);
|
|
35
|
+
preventOverlap(result, this.layout.filter((node) => siblingBlocks.includes(node.nodeID)), {
|
|
36
|
+
moveX: !hasArguments,
|
|
37
|
+
moveY: hasArguments
|
|
38
|
+
});
|
|
39
|
+
preventOverlap(result, operations);
|
|
40
|
+
this.extendParentBounds(parentNode, result);
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
/** Calculate insert position for a new {@link Block} */
|
|
44
|
+
newBlockPosition(position, parent, blocks, operations) {
|
|
45
|
+
const blockNodes = blocks.map((id) => this.layout.find((block) => block.nodeID === `b${id}`)).filter((node) => !!node);
|
|
46
|
+
const operationNodes = operations.map((id) => this.layout.find((operation) => operation.nodeID === `o${id}`)).filter((node) => !!node);
|
|
47
|
+
const parentNode = this.layout.find((pos) => pos.nodeID === `b${parent}`) ?? null;
|
|
48
|
+
const parentID = parentNode ? parent : null;
|
|
49
|
+
let result = { ...position };
|
|
50
|
+
if (blockNodes.length !== 0 || operationNodes.length !== 0) result = calculatePositionFromChildren(position, operationNodes, blockNodes);
|
|
51
|
+
else if (parentNode) result = {
|
|
52
|
+
x: parentNode.x + MIN_DISTANCE,
|
|
53
|
+
y: parentNode.y + MIN_DISTANCE,
|
|
54
|
+
width: position.width,
|
|
55
|
+
height: position.height
|
|
56
|
+
};
|
|
57
|
+
else result = this.calculatePositionForFreeBlock(result);
|
|
58
|
+
if (blockNodes.length === 0 && operationNodes.length === 0) {
|
|
59
|
+
const siblings = this.oss.blocks.filter((block) => block.parent === parentID).map((block) => block.nodeID);
|
|
60
|
+
preventOverlap(result, this.layout.filter((node) => siblings.includes(node.nodeID)));
|
|
61
|
+
}
|
|
62
|
+
this.extendParentBounds(parentNode, result);
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
/** Calculate insert position for a new clone of {@link Operation} */
|
|
66
|
+
newClonePosition(targetID) {
|
|
67
|
+
const targetNode = this.layout.find((pos) => pos.nodeID === targetID);
|
|
68
|
+
if (!targetNode) return null;
|
|
69
|
+
else return {
|
|
70
|
+
x: targetNode.x + targetNode.width / 2 + 10,
|
|
71
|
+
y: targetNode.y + targetNode.height / 2 + 10,
|
|
72
|
+
width: 150,
|
|
73
|
+
height: 40
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** Update layout when parent changes */
|
|
77
|
+
onChangeParent(targetID, newParent) {
|
|
78
|
+
const targetNode = this.layout.find((pos) => pos.nodeID === targetID);
|
|
79
|
+
if (!targetNode) return;
|
|
80
|
+
const parentNode = this.layout.find((pos) => pos.nodeID === newParent) ?? null;
|
|
81
|
+
const offset = this.calculateOffsetForParentChange(targetNode, parentNode);
|
|
82
|
+
if (offset.x === 0 && offset.y === 0) return;
|
|
83
|
+
targetNode.x += offset.x;
|
|
84
|
+
targetNode.y += offset.y;
|
|
85
|
+
const children = this.oss.hierarchy.expandAllOutputs([targetID]);
|
|
86
|
+
const childrenPositions = this.layout.filter((pos) => children.includes(pos.nodeID));
|
|
87
|
+
for (const child of childrenPositions) {
|
|
88
|
+
child.x += offset.x;
|
|
89
|
+
child.y += offset.y;
|
|
90
|
+
}
|
|
91
|
+
this.extendParentBounds(parentNode, targetNode);
|
|
92
|
+
}
|
|
93
|
+
/** Calculate closest node to the left */
|
|
94
|
+
selectLeft(targetID) {
|
|
95
|
+
const targetNode = this.layout.find((pos) => pos.nodeID === targetID);
|
|
96
|
+
if (!targetNode) return null;
|
|
97
|
+
const leftNodes = this.layout.filter((pos) => pos.nodeID !== targetID && pos.nodeID.startsWith("o")).filter((pos) => pos.x <= targetNode.x);
|
|
98
|
+
if (leftNodes.length === 0) return null;
|
|
99
|
+
const similarYNodes = leftNodes.filter((pos) => Math.abs(pos.y - targetNode.y) <= MIN_DISTANCE);
|
|
100
|
+
let closestNode = null;
|
|
101
|
+
if (similarYNodes.length > 0) closestNode = similarYNodes.reduce((prev, curr) => curr.x > prev.x ? curr : prev);
|
|
102
|
+
else closestNode = findClosestNodeByDistance(leftNodes, targetNode);
|
|
103
|
+
return closestNode?.nodeID ?? null;
|
|
104
|
+
}
|
|
105
|
+
/** Calculate closest node to the right */
|
|
106
|
+
selectRight(targetID) {
|
|
107
|
+
const targetNode = this.layout.find((pos) => pos.nodeID === targetID);
|
|
108
|
+
if (!targetNode) return null;
|
|
109
|
+
const rightNodes = this.layout.filter((pos) => pos.nodeID !== targetID && pos.nodeID.startsWith("o")).filter((pos) => pos.x >= targetNode.x);
|
|
110
|
+
if (rightNodes.length === 0) return null;
|
|
111
|
+
const similarYNodes = rightNodes.filter((pos) => Math.abs(pos.y - targetNode.y) <= MIN_DISTANCE);
|
|
112
|
+
let closestNode = null;
|
|
113
|
+
if (similarYNodes.length > 0) closestNode = similarYNodes.reduce((prev, curr) => curr.x < prev.x ? curr : prev);
|
|
114
|
+
else closestNode = findClosestNodeByDistance(rightNodes, targetNode);
|
|
115
|
+
return closestNode?.nodeID ?? null;
|
|
116
|
+
}
|
|
117
|
+
/** Calculate closest node upwards */
|
|
118
|
+
selectUp(targetID) {
|
|
119
|
+
const targetNode = this.layout.find((pos) => pos.nodeID === targetID);
|
|
120
|
+
if (!targetNode) return null;
|
|
121
|
+
const upperNodes = this.layout.filter((pos) => pos.nodeID !== targetID && pos.nodeID.startsWith("o")).filter((pos) => pos.y <= targetNode.y - MIN_DISTANCE);
|
|
122
|
+
const targetOperation = this.oss.itemByNodeID.get(targetID);
|
|
123
|
+
if (upperNodes.length === 0 || !targetOperation || targetOperation.nodeType === NodeType.BLOCK) return null;
|
|
124
|
+
const predecessors = this.oss.graph.expandAllInputs([targetOperation.id]);
|
|
125
|
+
const predecessorNodes = upperNodes.filter((pos) => predecessors.includes(Number(pos.nodeID.slice(1))));
|
|
126
|
+
let closestNode = null;
|
|
127
|
+
if (predecessorNodes.length > 0) closestNode = findClosestNodeByDistance(predecessorNodes, targetNode);
|
|
128
|
+
else closestNode = findClosestNodeByDistance(upperNodes, targetNode);
|
|
129
|
+
return closestNode?.nodeID ?? null;
|
|
130
|
+
}
|
|
131
|
+
/** Calculate closest node downwards */
|
|
132
|
+
selectDown(targetID) {
|
|
133
|
+
const targetNode = this.layout.find((pos) => pos.nodeID === targetID);
|
|
134
|
+
if (!targetNode) return null;
|
|
135
|
+
const lowerNodes = this.layout.filter((pos) => pos.nodeID !== targetID && pos.nodeID.startsWith("o")).filter((pos) => pos.y >= targetNode.y - MIN_DISTANCE);
|
|
136
|
+
const targetOperation = this.oss.itemByNodeID.get(targetID);
|
|
137
|
+
if (lowerNodes.length === 0 || !targetOperation || targetOperation.nodeType === NodeType.BLOCK) return null;
|
|
138
|
+
const descendants = this.oss.graph.expandAllOutputs([targetOperation.id]);
|
|
139
|
+
const descendantsNodes = lowerNodes.filter((pos) => descendants.includes(Number(pos.nodeID.slice(1))));
|
|
140
|
+
let closestNode = null;
|
|
141
|
+
if (descendantsNodes.length > 0) closestNode = findClosestNodeByDistance(descendantsNodes, targetNode);
|
|
142
|
+
else closestNode = findClosestNodeByDistance(lowerNodes, targetNode);
|
|
143
|
+
return closestNode?.nodeID ?? null;
|
|
144
|
+
}
|
|
145
|
+
extendParentBounds(parent, child) {
|
|
146
|
+
if (!parent) return;
|
|
147
|
+
const borderX = child.x + child.width + MIN_DISTANCE;
|
|
148
|
+
const borderY = child.y + child.height + MIN_DISTANCE;
|
|
149
|
+
parent.width = Math.max(parent.width, borderX - parent.x);
|
|
150
|
+
parent.height = Math.max(parent.height, borderY - parent.y);
|
|
151
|
+
}
|
|
152
|
+
calculatePositionForFreeOperation(initial) {
|
|
153
|
+
if (this.oss.operations.length === 0) return initial;
|
|
154
|
+
const freeInputs = this.oss.operations.filter((operation) => operation.parent === null && (operation.operation_type !== OperationType.SYNTHESIS || operation.arguments.length === 0)).map((operation) => operation.nodeID);
|
|
155
|
+
let inputsPositions = this.layout.filter((pos) => freeInputs.includes(pos.nodeID));
|
|
156
|
+
if (inputsPositions.length === 0) inputsPositions = this.layout.filter((pos) => pos.nodeID.startsWith("o"));
|
|
157
|
+
const maxX = Math.max(...inputsPositions.map((node) => node.x));
|
|
158
|
+
const minY = Math.min(...inputsPositions.map((node) => node.y));
|
|
159
|
+
return {
|
|
160
|
+
x: maxX + 150 + MIN_DISTANCE + 10,
|
|
161
|
+
y: minY
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
calculatePositionForFreeBlock(initial) {
|
|
165
|
+
const rootBlocks = this.oss.blocks.filter((block) => block.parent === null).map((block) => block.nodeID);
|
|
166
|
+
const blocksPositions = this.layout.filter((pos) => rootBlocks.includes(pos.nodeID));
|
|
167
|
+
if (blocksPositions.length === 0) return initial;
|
|
168
|
+
const maxX = Math.max(...blocksPositions.map((node) => node.x + node.width));
|
|
169
|
+
const minY = Math.min(...blocksPositions.map((node) => node.y));
|
|
170
|
+
return {
|
|
171
|
+
...initial,
|
|
172
|
+
x: maxX + MIN_DISTANCE,
|
|
173
|
+
y: minY
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
calculateOffsetForParentChange(target, parent) {
|
|
177
|
+
const newPosition = { ...target };
|
|
178
|
+
if (parent === null) {
|
|
179
|
+
const rootElements = this.oss.hierarchy.rootNodes();
|
|
180
|
+
preventOverlap(newPosition, this.layout.filter((pos) => rootElements.includes(pos.nodeID)));
|
|
181
|
+
} else if (!rectanglesStrictOverlap(target, parent)) {
|
|
182
|
+
newPosition.x = parent.x + MIN_DISTANCE;
|
|
183
|
+
newPosition.y = parent.y + MIN_DISTANCE;
|
|
184
|
+
const siblings = this.oss.hierarchy.at(parent.nodeID)?.outputs ?? [];
|
|
185
|
+
preventOverlap(newPosition, this.layout.filter((pos) => siblings.includes(pos.nodeID)));
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
x: newPosition.x - target.x,
|
|
189
|
+
y: newPosition.y - target.y
|
|
190
|
+
};
|
|
191
|
+
}
|
|
259
192
|
};
|
|
260
193
|
function rectanglesOverlap(a, b) {
|
|
261
|
-
|
|
194
|
+
return !(a.x + a.width + MIN_DISTANCE <= b.x || b.x + b.width + MIN_DISTANCE <= a.x || a.y + a.height + MIN_DISTANCE <= b.y || b.y + b.height + MIN_DISTANCE <= a.y);
|
|
262
195
|
}
|
|
263
196
|
function rectanglesStrictOverlap(a, b) {
|
|
264
|
-
|
|
197
|
+
return !(a.x + a.width <= b.x || b.x + b.width <= a.x || a.y + a.height <= b.y || b.y + b.height <= a.y);
|
|
265
198
|
}
|
|
266
|
-
function preventOverlap(target, fixedRectangles, options = {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
break;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
} while (hasOverlap);
|
|
199
|
+
function preventOverlap(target, fixedRectangles, options = {
|
|
200
|
+
moveX: true,
|
|
201
|
+
moveY: true
|
|
202
|
+
}) {
|
|
203
|
+
if (!options.moveX && !options.moveY || fixedRectangles.length === 0) return;
|
|
204
|
+
let hasOverlap;
|
|
205
|
+
do {
|
|
206
|
+
hasOverlap = false;
|
|
207
|
+
for (const fixed of fixedRectangles) if (rectanglesOverlap(target, fixed)) {
|
|
208
|
+
hasOverlap = true;
|
|
209
|
+
if (options.moveX) target.x += MIN_DISTANCE;
|
|
210
|
+
if (options.moveY) target.y += MIN_DISTANCE;
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
} while (hasOverlap);
|
|
286
214
|
}
|
|
287
215
|
function calculatePositionFromArgs(args) {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
216
|
+
const maxY = Math.max(...args.map((node) => node.y));
|
|
217
|
+
const minX = Math.min(...args.map((node) => node.x));
|
|
218
|
+
const maxX = Math.max(...args.map((node) => node.x));
|
|
219
|
+
return {
|
|
220
|
+
x: Math.ceil((maxX + minX) / 2 / 10) * 10,
|
|
221
|
+
y: maxY + 80 + MIN_DISTANCE
|
|
222
|
+
};
|
|
295
223
|
}
|
|
296
224
|
function calculatePositionFromChildren(initial, operations, blocks) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
height: bottom - top
|
|
310
|
-
};
|
|
225
|
+
const allNodes = [...blocks, ...operations];
|
|
226
|
+
if (allNodes.length === 0) return initial;
|
|
227
|
+
const left = Math.min(...allNodes.map((n) => n.x)) - MIN_DISTANCE;
|
|
228
|
+
const top = Math.min(...allNodes.map((n) => n.y)) - MIN_DISTANCE;
|
|
229
|
+
const right = Math.max(...allNodes.map((n) => n.x + n.width)) + MIN_DISTANCE;
|
|
230
|
+
const bottom = Math.max(...allNodes.map((n) => n.y + n.height)) + MIN_DISTANCE;
|
|
231
|
+
return {
|
|
232
|
+
x: left,
|
|
233
|
+
y: top,
|
|
234
|
+
width: right - left,
|
|
235
|
+
height: bottom - top
|
|
236
|
+
};
|
|
311
237
|
}
|
|
312
238
|
function findClosestNodeByDistance(nodes, target) {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
239
|
+
let minDist = Infinity;
|
|
240
|
+
let minNode = null;
|
|
241
|
+
for (const curr of nodes) {
|
|
242
|
+
const currDist = Math.hypot(curr.x - target.x, curr.y - target.y);
|
|
243
|
+
if (currDist < minDist) {
|
|
244
|
+
minDist = currDist;
|
|
245
|
+
minNode = curr;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return minNode;
|
|
323
249
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
OPERATION_NODE_HEIGHT,
|
|
328
|
-
OPERATION_NODE_WIDTH
|
|
329
|
-
};
|
|
250
|
+
//#endregion
|
|
251
|
+
export { GRID_SIZE, LayoutManager, OPERATION_NODE_HEIGHT, OPERATION_NODE_WIDTH };
|
|
252
|
+
|
|
330
253
|
//# sourceMappingURL=oss-layout-api.js.map
|