@likec4/core 0.33.1 → 0.35.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/dist/{colors.mjs → colors.cjs} +15 -3
- package/dist/colors.js +3 -15
- package/dist/compute-view/EdgeBuilder.cjs +37 -0
- package/dist/compute-view/EdgeBuilder.d.ts +1 -2
- package/dist/compute-view/EdgeBuilder.js +10 -18
- package/dist/compute-view/compute-ctx.cjs +35 -0
- package/dist/compute-view/compute-ctx.js +21 -14
- package/dist/compute-view/compute-element-view.cjs +135 -0
- package/dist/compute-view/compute-element-view.js +70 -62
- package/dist/compute-view/compute-predicates.cjs +363 -0
- package/dist/compute-view/compute-predicates.d.ts +1 -1
- package/dist/compute-view/compute-predicates.js +81 -115
- package/dist/compute-view/compute.cjs +60 -0
- package/dist/compute-view/compute.d.ts +13 -4
- package/dist/compute-view/compute.js +24 -31
- package/dist/compute-view/index.cjs +27 -0
- package/dist/compute-view/index.d.ts +2 -3
- package/dist/compute-view/index.js +2 -24
- package/dist/compute-view/utils/anyPossibleRelations.cjs +18 -0
- package/dist/compute-view/utils/anyPossibleRelations.js +6 -12
- package/dist/compute-view/utils/applyViewRuleStyles.cjs +57 -0
- package/dist/compute-view/utils/applyViewRuleStyles.d.ts +1 -2
- package/dist/compute-view/utils/applyViewRuleStyles.js +20 -29
- package/dist/compute-view/utils/{sortNodes.mjs → sortNodes.cjs} +19 -9
- package/dist/compute-view/utils/sortNodes.js +9 -19
- package/dist/errors/_base.cjs +62 -0
- package/dist/errors/_base.d.ts +20 -3
- package/dist/errors/_base.js +41 -14
- package/dist/errors/index.cjs +60 -0
- package/dist/errors/index.js +5 -60
- package/dist/errors/invariant.cjs +23 -0
- package/dist/errors/invariant.d.ts +5 -1
- package/dist/errors/invariant.js +9 -12
- package/dist/errors/model-index.cjs +23 -0
- package/dist/errors/model-index.d.ts +5 -1
- package/dist/errors/model-index.js +9 -12
- package/dist/errors/non-nullable.cjs +23 -0
- package/dist/errors/non-nullable.d.ts +5 -1
- package/dist/errors/non-nullable.js +11 -14
- package/dist/errors/nonexhaustive.cjs +23 -0
- package/dist/errors/nonexhaustive.d.ts +6 -2
- package/dist/errors/nonexhaustive.js +12 -13
- package/dist/index.cjs +71 -0
- package/dist/index.d.ts +2 -5
- package/dist/index.js +6 -71
- package/dist/model-index/{ModelIndex.mjs → ModelIndex.cjs} +35 -23
- package/dist/model-index/ModelIndex.js +23 -35
- package/dist/model-index/index.cjs +13 -0
- package/dist/model-index/index.js +1 -13
- package/dist/types/_common.cjs +1 -0
- package/dist/types/_common.js +0 -1
- package/dist/types/computed-view.cjs +1 -0
- package/dist/types/computed-view.js +0 -1
- package/dist/types/diagram.cjs +1 -0
- package/dist/types/diagram.js +0 -1
- package/dist/types/element.cjs +14 -0
- package/dist/types/element.js +3 -12
- package/dist/types/expression.cjs +45 -0
- package/dist/types/expression.js +11 -26
- package/dist/types/index.cjs +132 -0
- package/dist/types/index.d.ts +10 -12
- package/dist/types/index.js +11 -48
- package/dist/types/model.cjs +1 -0
- package/dist/types/model.d.ts +1 -1
- package/dist/types/model.js +0 -1
- package/dist/types/opaque.cjs +1 -0
- package/dist/types/opaque.d.ts +1 -1
- package/dist/types/opaque.js +0 -1
- package/dist/types/relation.cjs +1 -0
- package/dist/types/relation.js +0 -1
- package/dist/types/theme.cjs +1 -0
- package/dist/types/theme.js +0 -1
- package/dist/types/view.cjs +17 -0
- package/dist/types/view.js +4 -12
- package/dist/utils/compute-node-levels.cjs +48 -0
- package/dist/utils/compute-node-levels.d.ts +2 -2
- package/dist/utils/compute-node-levels.js +7 -24
- package/dist/utils/fqn.cjs +80 -0
- package/dist/utils/fqn.js +19 -33
- package/dist/utils/guards.cjs +22 -0
- package/dist/utils/guards.js +7 -16
- package/dist/utils/index.cjs +49 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +4 -49
- package/dist/utils/relations.cjs +59 -0
- package/dist/utils/relations.d.ts +14 -12
- package/dist/utils/relations.js +28 -33
- package/package.json +63 -25
- package/dist/compute-view/EdgeBuilder.mjs +0 -31
- package/dist/compute-view/compute-ctx.mjs +0 -42
- package/dist/compute-view/compute-element-view.mjs +0 -145
- package/dist/compute-view/compute-predicates.mjs +0 -324
- package/dist/compute-view/compute.mjs +0 -39
- package/dist/compute-view/index.mjs +0 -1
- package/dist/compute-view/utils/anyPossibleRelations.mjs +0 -12
- package/dist/compute-view/utils/applyViewRuleStyles.mjs +0 -50
- package/dist/errors/_base.mjs +0 -4
- package/dist/errors/index.mjs +0 -5
- package/dist/errors/invariant.mjs +0 -8
- package/dist/errors/model-index.mjs +0 -8
- package/dist/errors/non-nullable.mjs +0 -8
- package/dist/errors/nonexhaustive.mjs +0 -5
- package/dist/index.mjs +0 -6
- package/dist/model-index/index.mjs +0 -1
- package/dist/types/_common.mjs +0 -0
- package/dist/types/computed-view.mjs +0 -0
- package/dist/types/diagram.mjs +0 -0
- package/dist/types/element.mjs +0 -5
- package/dist/types/expression.mjs +0 -30
- package/dist/types/index.mjs +0 -3
- package/dist/types/model.mjs +0 -0
- package/dist/types/opaque.mjs +0 -0
- package/dist/types/relation.mjs +0 -0
- package/dist/types/theme.mjs +0 -0
- package/dist/types/view.mjs +0 -9
- package/dist/utils/compute-node-levels.mjs +0 -31
- package/dist/utils/fqn.mjs +0 -66
- package/dist/utils/guards.mjs +0 -13
- package/dist/utils/index.mjs +0 -4
- package/dist/utils/relations.mjs +0 -42
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.defaultTheme = exports.RelationColors = exports.Colors = void 0;
|
|
1
7
|
const blue = {
|
|
2
8
|
// fill: colors.blue[500],
|
|
3
9
|
// stroke: colors.blue[600],
|
|
@@ -28,13 +34,14 @@ const slate = {
|
|
|
28
34
|
hiContrast: "#f8fafc",
|
|
29
35
|
loContrast: "#e2e8f0"
|
|
30
36
|
};
|
|
31
|
-
|
|
37
|
+
const RelationColors = {
|
|
32
38
|
// lineColor: colors.neutral[400],
|
|
33
39
|
// labelColor: colors.neutral[300],
|
|
34
40
|
lineColor: "#a3a3a3",
|
|
35
41
|
labelColor: "#d4d4d4"
|
|
36
42
|
};
|
|
37
|
-
|
|
43
|
+
exports.RelationColors = RelationColors;
|
|
44
|
+
const Colors = {
|
|
38
45
|
primary: blue,
|
|
39
46
|
blue,
|
|
40
47
|
secondary: sky,
|
|
@@ -65,6 +72,7 @@ export const Colors = {
|
|
|
65
72
|
loContrast: "#1f2937"
|
|
66
73
|
// colors.gray[800],
|
|
67
74
|
},
|
|
75
|
+
|
|
68
76
|
green: {
|
|
69
77
|
// fill: colors.green[600],
|
|
70
78
|
// stroke: colors.green[700],
|
|
@@ -79,6 +87,7 @@ export const Colors = {
|
|
|
79
87
|
// colors.gray[800],
|
|
80
88
|
// loContrast: '#bbf7d0'
|
|
81
89
|
},
|
|
90
|
+
|
|
82
91
|
amber: {
|
|
83
92
|
// fill: colors.amber[600],
|
|
84
93
|
// stroke: colors.amber[700],
|
|
@@ -93,6 +102,7 @@ export const Colors = {
|
|
|
93
102
|
loContrast: "#1f2937"
|
|
94
103
|
// colors.gray[800],
|
|
95
104
|
},
|
|
105
|
+
|
|
96
106
|
indigo: {
|
|
97
107
|
// fill: colors.indigo[500],
|
|
98
108
|
// stroke: colors.indigo[600],
|
|
@@ -104,9 +114,11 @@ export const Colors = {
|
|
|
104
114
|
loContrast: "#c7d2fe"
|
|
105
115
|
}
|
|
106
116
|
};
|
|
107
|
-
|
|
117
|
+
exports.Colors = Colors;
|
|
118
|
+
const defaultTheme = {
|
|
108
119
|
font: "Helvetica",
|
|
109
120
|
shadow: "#0a0a0a",
|
|
110
121
|
relation: RelationColors,
|
|
111
122
|
colors: Colors
|
|
112
123
|
};
|
|
124
|
+
exports.defaultTheme = defaultTheme;
|
package/dist/colors.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.defaultTheme = exports.RelationColors = exports.Colors = void 0;
|
|
7
1
|
const blue = {
|
|
8
2
|
// fill: colors.blue[500],
|
|
9
3
|
// stroke: colors.blue[600],
|
|
@@ -34,14 +28,13 @@ const slate = {
|
|
|
34
28
|
hiContrast: "#f8fafc",
|
|
35
29
|
loContrast: "#e2e8f0"
|
|
36
30
|
};
|
|
37
|
-
const RelationColors = {
|
|
31
|
+
export const RelationColors = {
|
|
38
32
|
// lineColor: colors.neutral[400],
|
|
39
33
|
// labelColor: colors.neutral[300],
|
|
40
34
|
lineColor: "#a3a3a3",
|
|
41
35
|
labelColor: "#d4d4d4"
|
|
42
36
|
};
|
|
43
|
-
|
|
44
|
-
const Colors = {
|
|
37
|
+
export const Colors = {
|
|
45
38
|
primary: blue,
|
|
46
39
|
blue,
|
|
47
40
|
secondary: sky,
|
|
@@ -72,7 +65,6 @@ const Colors = {
|
|
|
72
65
|
loContrast: "#1f2937"
|
|
73
66
|
// colors.gray[800],
|
|
74
67
|
},
|
|
75
|
-
|
|
76
68
|
green: {
|
|
77
69
|
// fill: colors.green[600],
|
|
78
70
|
// stroke: colors.green[700],
|
|
@@ -87,7 +79,6 @@ const Colors = {
|
|
|
87
79
|
// colors.gray[800],
|
|
88
80
|
// loContrast: '#bbf7d0'
|
|
89
81
|
},
|
|
90
|
-
|
|
91
82
|
amber: {
|
|
92
83
|
// fill: colors.amber[600],
|
|
93
84
|
// stroke: colors.amber[700],
|
|
@@ -102,7 +93,6 @@ const Colors = {
|
|
|
102
93
|
loContrast: "#1f2937"
|
|
103
94
|
// colors.gray[800],
|
|
104
95
|
},
|
|
105
|
-
|
|
106
96
|
indigo: {
|
|
107
97
|
// fill: colors.indigo[500],
|
|
108
98
|
// stroke: colors.indigo[600],
|
|
@@ -114,11 +104,9 @@ const Colors = {
|
|
|
114
104
|
loContrast: "#c7d2fe"
|
|
115
105
|
}
|
|
116
106
|
};
|
|
117
|
-
|
|
118
|
-
const defaultTheme = {
|
|
107
|
+
export const defaultTheme = {
|
|
119
108
|
font: "Helvetica",
|
|
120
109
|
shadow: "#0a0a0a",
|
|
121
110
|
relation: RelationColors,
|
|
122
111
|
colors: Colors
|
|
123
112
|
};
|
|
124
|
-
exports.defaultTheme = defaultTheme;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.EdgeBuilder = void 0;
|
|
7
|
+
var _rambdax = require("rambdax");
|
|
8
|
+
var _utils = require("../utils/index.cjs");
|
|
9
|
+
class EdgeBuilder {
|
|
10
|
+
_relationsObj = {};
|
|
11
|
+
add(source, target, relation) {
|
|
12
|
+
const bySource = this._relationsObj[source] ?? {};
|
|
13
|
+
const relations = bySource[target] ?? [];
|
|
14
|
+
relations.push(relation);
|
|
15
|
+
bySource[target] = relations;
|
|
16
|
+
this._relationsObj[source] = bySource;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
build() {
|
|
20
|
+
return (0, _rambdax.keys)(this._relationsObj).flatMap(source => {
|
|
21
|
+
const targets = this._relationsObj[source] ?? {};
|
|
22
|
+
return (0, _rambdax.keys)(targets).map(target => {
|
|
23
|
+
const relations = (targets[target] ?? []).sort(_utils.compareRelations);
|
|
24
|
+
const label = relations.find(r => r.title !== "")?.title ?? null;
|
|
25
|
+
return {
|
|
26
|
+
id: `${source}:${target}`,
|
|
27
|
+
parent: (0, _utils.commonAncestor)(source, target),
|
|
28
|
+
source,
|
|
29
|
+
target,
|
|
30
|
+
label,
|
|
31
|
+
relations: (0, _rambdax.pluck)("id", relations)
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}).sort(_utils.compareRelations).reverse();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.EdgeBuilder = EdgeBuilder;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { Fqn, Relation } from '../types';
|
|
2
|
-
import type { ComputedEdge } from '../types/computed-view';
|
|
1
|
+
import type { ComputedEdge, Fqn, Relation } from '../types';
|
|
3
2
|
export declare class EdgeBuilder {
|
|
4
3
|
private _relationsObj;
|
|
5
4
|
add(source: Fqn, target: Fqn, relation: Relation): this;
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.EdgeBuilder = void 0;
|
|
7
|
-
var _rambdax = require("rambdax");
|
|
8
|
-
var _fqn = require("../utils/fqn");
|
|
9
|
-
var _relations = require("../utils/relations");
|
|
10
|
-
class EdgeBuilder {
|
|
1
|
+
import { keys, pluck } from "rambdax";
|
|
2
|
+
import { commonAncestor, compareRelations } from "../utils/index.js";
|
|
3
|
+
export class EdgeBuilder {
|
|
11
4
|
_relationsObj = {};
|
|
12
5
|
add(source, target, relation) {
|
|
13
6
|
const bySource = this._relationsObj[source] ?? {};
|
|
@@ -18,21 +11,20 @@ class EdgeBuilder {
|
|
|
18
11
|
return this;
|
|
19
12
|
}
|
|
20
13
|
build() {
|
|
21
|
-
return
|
|
14
|
+
return keys(this._relationsObj).flatMap((source) => {
|
|
22
15
|
const targets = this._relationsObj[source] ?? {};
|
|
23
|
-
return
|
|
24
|
-
const relations = (targets[target] ?? []).sort(
|
|
25
|
-
const label = relations.find(r => r.title !== "")?.title ?? null;
|
|
16
|
+
return keys(targets).map((target) => {
|
|
17
|
+
const relations = (targets[target] ?? []).sort(compareRelations);
|
|
18
|
+
const label = relations.find((r) => r.title !== "")?.title ?? null;
|
|
26
19
|
return {
|
|
27
20
|
id: `${source}:${target}`,
|
|
28
|
-
parent:
|
|
21
|
+
parent: commonAncestor(source, target),
|
|
29
22
|
source,
|
|
30
23
|
target,
|
|
31
24
|
label,
|
|
32
|
-
relations:
|
|
25
|
+
relations: pluck("id", relations)
|
|
33
26
|
};
|
|
34
27
|
});
|
|
35
|
-
}).sort(
|
|
28
|
+
}).sort(compareRelations).reverse();
|
|
36
29
|
}
|
|
37
30
|
}
|
|
38
|
-
exports.EdgeBuilder = EdgeBuilder;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ComputeCtx = void 0;
|
|
7
|
+
var _rambdax = require("rambdax");
|
|
8
|
+
class ComputeCtx {
|
|
9
|
+
constructor(index, root, elements = /* @__PURE__ */new Set(), relations = /* @__PURE__ */new Set(), implicits = /* @__PURE__ */new Set()) {
|
|
10
|
+
this.index = index;
|
|
11
|
+
this.root = root;
|
|
12
|
+
this.elements = elements;
|
|
13
|
+
this.relations = relations;
|
|
14
|
+
this.implicits = implicits;
|
|
15
|
+
}
|
|
16
|
+
include({
|
|
17
|
+
elements,
|
|
18
|
+
relations,
|
|
19
|
+
implicits
|
|
20
|
+
}) {
|
|
21
|
+
return new ComputeCtx(this.index, this.root, elements ? /* @__PURE__ */new Set([...this.elements, ...elements]) : this.elements, relations ? /* @__PURE__ */new Set([...this.relations, ...relations]) : this.relations, implicits ? /* @__PURE__ */new Set([...this.implicits, ...implicits]) : this.implicits);
|
|
22
|
+
}
|
|
23
|
+
exclude({
|
|
24
|
+
elements,
|
|
25
|
+
relations,
|
|
26
|
+
implicits
|
|
27
|
+
}) {
|
|
28
|
+
let newImplicits = implicits ? new Set((0, _rambdax.difference)([...this.implicits], implicits)) : this.implicits;
|
|
29
|
+
if (elements) {
|
|
30
|
+
newImplicits = new Set((0, _rambdax.difference)([...newImplicits], elements));
|
|
31
|
+
}
|
|
32
|
+
return new ComputeCtx(this.index, this.root, elements ? new Set((0, _rambdax.difference)([...this.elements], elements)) : this.elements, relations ? new Set((0, _rambdax.difference)([...this.relations], relations)) : this.relations, newImplicits);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.ComputeCtx = ComputeCtx;
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ComputeCtx = void 0;
|
|
7
|
-
var _rambdax = require("rambdax");
|
|
8
|
-
class ComputeCtx {
|
|
9
|
-
constructor(index, root, elements = /* @__PURE__ */new Set(), relations = /* @__PURE__ */new Set(), implicits = /* @__PURE__ */new Set()) {
|
|
1
|
+
import { difference } from "rambdax";
|
|
2
|
+
export class ComputeCtx {
|
|
3
|
+
constructor(index, root, elements = /* @__PURE__ */ new Set(), relations = /* @__PURE__ */ new Set(), implicits = /* @__PURE__ */ new Set()) {
|
|
10
4
|
this.index = index;
|
|
11
5
|
this.root = root;
|
|
12
6
|
this.elements = elements;
|
|
@@ -18,18 +12,31 @@ class ComputeCtx {
|
|
|
18
12
|
relations,
|
|
19
13
|
implicits
|
|
20
14
|
}) {
|
|
21
|
-
return new ComputeCtx(
|
|
15
|
+
return new ComputeCtx(
|
|
16
|
+
this.index,
|
|
17
|
+
this.root,
|
|
18
|
+
elements ? /* @__PURE__ */ new Set([...this.elements, ...elements]) : this.elements,
|
|
19
|
+
relations ? /* @__PURE__ */ new Set([...this.relations, ...relations]) : this.relations,
|
|
20
|
+
implicits ? /* @__PURE__ */ new Set([...this.implicits, ...implicits]) : this.implicits
|
|
21
|
+
);
|
|
22
22
|
}
|
|
23
23
|
exclude({
|
|
24
24
|
elements,
|
|
25
25
|
relations,
|
|
26
26
|
implicits
|
|
27
27
|
}) {
|
|
28
|
-
let newImplicits = implicits ? new Set(
|
|
28
|
+
let newImplicits = implicits ? new Set(difference([...this.implicits], implicits)) : this.implicits;
|
|
29
29
|
if (elements) {
|
|
30
|
-
newImplicits = new Set(
|
|
30
|
+
newImplicits = new Set(
|
|
31
|
+
difference([...newImplicits], elements)
|
|
32
|
+
);
|
|
31
33
|
}
|
|
32
|
-
return new ComputeCtx(
|
|
34
|
+
return new ComputeCtx(
|
|
35
|
+
this.index,
|
|
36
|
+
this.root,
|
|
37
|
+
elements ? new Set(difference([...this.elements], elements)) : this.elements,
|
|
38
|
+
relations ? new Set(difference([...this.relations], relations)) : this.relations,
|
|
39
|
+
newImplicits
|
|
40
|
+
);
|
|
33
41
|
}
|
|
34
42
|
}
|
|
35
|
-
exports.ComputeCtx = ComputeCtx;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.computeElementView = computeElementView;
|
|
7
|
+
var _remeda = require("remeda");
|
|
8
|
+
var _errors = require("../errors/index.cjs");
|
|
9
|
+
var _types = require("../types/index.cjs");
|
|
10
|
+
var _utils = require("../utils/index.cjs");
|
|
11
|
+
var _EdgeBuilder = require("./EdgeBuilder.cjs");
|
|
12
|
+
var _computeCtx = require("./compute-ctx.cjs");
|
|
13
|
+
var _computePredicates = require("./compute-predicates.cjs");
|
|
14
|
+
var _applyViewRuleStyles = require("./utils/applyViewRuleStyles.cjs");
|
|
15
|
+
var _sortNodes = require("./utils/sortNodes.cjs");
|
|
16
|
+
function reduceToMap(elementsIterator) {
|
|
17
|
+
return Array.from(elementsIterator).sort(_utils.compareByFqnHierarchically).reduce((map, {
|
|
18
|
+
id,
|
|
19
|
+
color,
|
|
20
|
+
shape,
|
|
21
|
+
...el
|
|
22
|
+
}) => {
|
|
23
|
+
let parent = (0, _utils.parentFqn)(id);
|
|
24
|
+
while (parent) {
|
|
25
|
+
if (map.has(parent)) {
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
parent = (0, _utils.parentFqn)(parent);
|
|
29
|
+
}
|
|
30
|
+
if (parent) {
|
|
31
|
+
const parentNd = (0, _errors.nonNullable)(map.get(parent));
|
|
32
|
+
parentNd.children.push(id);
|
|
33
|
+
}
|
|
34
|
+
const node = {
|
|
35
|
+
...el,
|
|
36
|
+
id,
|
|
37
|
+
parent,
|
|
38
|
+
color: color ?? _types.DefaultThemeColor,
|
|
39
|
+
shape: shape ?? _types.DefaultElementShape,
|
|
40
|
+
children: [],
|
|
41
|
+
inEdges: [],
|
|
42
|
+
outEdges: []
|
|
43
|
+
};
|
|
44
|
+
map.set(id, node);
|
|
45
|
+
return map;
|
|
46
|
+
}, /* @__PURE__ */new Map());
|
|
47
|
+
}
|
|
48
|
+
function computeElementView(view, index) {
|
|
49
|
+
const rootElement = view.viewOf ?? null;
|
|
50
|
+
let ctx = new _computeCtx.ComputeCtx(index, rootElement);
|
|
51
|
+
const rulesInclude = view.rules.filter(_types.isViewRuleExpression);
|
|
52
|
+
if (rootElement && rulesInclude.length == 0) {
|
|
53
|
+
ctx = ctx.include({
|
|
54
|
+
elements: [index.find(rootElement)]
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
for (const {
|
|
58
|
+
isInclude,
|
|
59
|
+
exprs
|
|
60
|
+
} of rulesInclude) {
|
|
61
|
+
for (const expr of exprs) {
|
|
62
|
+
if (_types.Expr.isElementKindExpr(expr) || _types.Expr.isElementTagExpr(expr)) {
|
|
63
|
+
ctx = isInclude ? (0, _computePredicates.includeElementKindOrTag)(ctx, expr) : (0, _computePredicates.excludeElementKindOrTag)(ctx, expr);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (_types.Expr.isElementRef(expr)) {
|
|
67
|
+
ctx = isInclude ? (0, _computePredicates.includeElementRef)(ctx, expr) : (0, _computePredicates.excludeElementRef)(ctx, expr);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (_types.Expr.isWildcard(expr)) {
|
|
71
|
+
ctx = isInclude ? (0, _computePredicates.includeWildcardRef)(ctx, expr) : (0, _computePredicates.excludeWildcardRef)(ctx, expr);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (_types.Expr.isIncoming(expr)) {
|
|
75
|
+
ctx = isInclude ? (0, _computePredicates.includeIncomingExpr)(ctx, expr) : (0, _computePredicates.excludeIncomingExpr)(ctx, expr);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (_types.Expr.isOutgoing(expr)) {
|
|
79
|
+
ctx = isInclude ? (0, _computePredicates.includeOutgoingExpr)(ctx, expr) : (0, _computePredicates.excludeOutgoingExpr)(ctx, expr);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (_types.Expr.isInOut(expr)) {
|
|
83
|
+
ctx = isInclude ? (0, _computePredicates.includeInOutExpr)(ctx, expr) : (0, _computePredicates.excludeInOutExpr)(ctx, expr);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (_types.Expr.isRelation(expr)) {
|
|
87
|
+
ctx = isInclude ? (0, _computePredicates.includeRelationExpr)(ctx, expr) : (0, _computePredicates.excludeRelationExpr)(ctx, expr);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
(0, _errors.nonexhaustive)(expr);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const allElements = [...ctx.elements, ...ctx.implicits].sort(_utils.compareByFqnHierarchically).reverse();
|
|
94
|
+
const elementsWithRelations = /* @__PURE__ */new Set();
|
|
95
|
+
const edgeBuilder = new _EdgeBuilder.EdgeBuilder();
|
|
96
|
+
const anscestorOf = id => e => e.id === id || (0, _utils.isAncestor)(e.id, id);
|
|
97
|
+
const sortedRelations = [...ctx.relations];
|
|
98
|
+
for (const rel of sortedRelations) {
|
|
99
|
+
const source = (0, _remeda.find)(allElements, anscestorOf(rel.source));
|
|
100
|
+
if (!source) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const target = (0, _remeda.find)(allElements, (0, _remeda.allPass)([anscestorOf(rel.target), e => !(0, _utils.isSameHierarchy)(e, source)]));
|
|
104
|
+
if (!target) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
elementsWithRelations.add(source);
|
|
108
|
+
elementsWithRelations.add(target);
|
|
109
|
+
edgeBuilder.add(source.id, target.id, rel);
|
|
110
|
+
}
|
|
111
|
+
const elements = /* @__PURE__ */new Set([...ctx.elements, ...elementsWithRelations]);
|
|
112
|
+
const nodesMap = reduceToMap(elements);
|
|
113
|
+
const edges = edgeBuilder.build().map(edge => {
|
|
114
|
+
while (edge.parent) {
|
|
115
|
+
if (nodesMap.has(edge.parent)) {
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
edge.parent = (0, _utils.parentFqn)(edge.parent);
|
|
119
|
+
}
|
|
120
|
+
(0, _errors.nonNullable)(nodesMap.get(edge.source)).outEdges.push(edge.id);
|
|
121
|
+
(0, _errors.nonNullable)(nodesMap.get(edge.target)).inEdges.push(edge.id);
|
|
122
|
+
return edge;
|
|
123
|
+
});
|
|
124
|
+
const nodes = (0, _applyViewRuleStyles.applyViewRuleStyles)(view.rules.filter(_types.isViewRuleStyle), (0, _sortNodes.sortNodes)(nodesMap, edges)
|
|
125
|
+
// map(e => nodesMap.get(e.id)!, Array.from(elements))
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const autoLayoutRule = view.rules.find(_types.isViewRuleAutoLayout);
|
|
129
|
+
return {
|
|
130
|
+
...view,
|
|
131
|
+
autoLayout: autoLayoutRule?.autoLayout ?? "TB",
|
|
132
|
+
nodes,
|
|
133
|
+
edges
|
|
134
|
+
};
|
|
135
|
+
}
|
|
@@ -1,110 +1,117 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import { allPass, find } from "remeda";
|
|
2
|
+
import { nonNullable, nonexhaustive } from "../errors/index.js";
|
|
3
|
+
import {
|
|
4
|
+
DefaultElementShape,
|
|
5
|
+
DefaultThemeColor,
|
|
6
|
+
Expr,
|
|
7
|
+
isViewRuleAutoLayout,
|
|
8
|
+
isViewRuleExpression,
|
|
9
|
+
isViewRuleStyle
|
|
10
|
+
} from "../types/index.js";
|
|
11
|
+
import { compareByFqnHierarchically, isAncestor, isSameHierarchy, parentFqn } from "../utils/index.js";
|
|
12
|
+
import { EdgeBuilder } from "./EdgeBuilder.js";
|
|
13
|
+
import { ComputeCtx } from "./compute-ctx.js";
|
|
14
|
+
import {
|
|
15
|
+
excludeElementKindOrTag,
|
|
16
|
+
excludeElementRef,
|
|
17
|
+
excludeInOutExpr,
|
|
18
|
+
excludeIncomingExpr,
|
|
19
|
+
excludeOutgoingExpr,
|
|
20
|
+
excludeRelationExpr,
|
|
21
|
+
excludeWildcardRef,
|
|
22
|
+
includeElementKindOrTag,
|
|
23
|
+
includeElementRef,
|
|
24
|
+
includeInOutExpr,
|
|
25
|
+
includeIncomingExpr,
|
|
26
|
+
includeOutgoingExpr,
|
|
27
|
+
includeRelationExpr,
|
|
28
|
+
includeWildcardRef
|
|
29
|
+
} from "./compute-predicates.js";
|
|
30
|
+
import { applyViewRuleStyles } from "./utils/applyViewRuleStyles.js";
|
|
31
|
+
import { sortNodes } from "./utils/sortNodes.js";
|
|
20
32
|
function reduceToMap(elementsIterator) {
|
|
21
|
-
return Array.from(elementsIterator).sort(
|
|
22
|
-
id
|
|
23
|
-
color,
|
|
24
|
-
shape,
|
|
25
|
-
...el
|
|
26
|
-
}) => {
|
|
27
|
-
let parent = (0, _utils.parentFqn)(id);
|
|
33
|
+
return Array.from(elementsIterator).sort(compareByFqnHierarchically).reduce((map, { id, color, shape, ...el }) => {
|
|
34
|
+
let parent = parentFqn(id);
|
|
28
35
|
while (parent) {
|
|
29
36
|
if (map.has(parent)) {
|
|
30
37
|
break;
|
|
31
38
|
}
|
|
32
|
-
parent =
|
|
39
|
+
parent = parentFqn(parent);
|
|
33
40
|
}
|
|
34
41
|
if (parent) {
|
|
35
|
-
const parentNd =
|
|
42
|
+
const parentNd = nonNullable(map.get(parent));
|
|
36
43
|
parentNd.children.push(id);
|
|
37
44
|
}
|
|
38
45
|
const node = {
|
|
39
46
|
...el,
|
|
40
47
|
id,
|
|
41
48
|
parent,
|
|
42
|
-
color: color ??
|
|
43
|
-
shape: shape ??
|
|
49
|
+
color: color ?? DefaultThemeColor,
|
|
50
|
+
shape: shape ?? DefaultElementShape,
|
|
44
51
|
children: [],
|
|
45
52
|
inEdges: [],
|
|
46
53
|
outEdges: []
|
|
47
54
|
};
|
|
48
55
|
map.set(id, node);
|
|
49
56
|
return map;
|
|
50
|
-
}, /* @__PURE__ */new Map());
|
|
57
|
+
}, /* @__PURE__ */ new Map());
|
|
51
58
|
}
|
|
52
|
-
function computeElementView(view, index) {
|
|
59
|
+
export function computeElementView(view, index) {
|
|
53
60
|
const rootElement = view.viewOf ?? null;
|
|
54
|
-
let ctx = new
|
|
55
|
-
const rulesInclude = view.rules.filter(
|
|
61
|
+
let ctx = new ComputeCtx(index, rootElement);
|
|
62
|
+
const rulesInclude = view.rules.filter(isViewRuleExpression);
|
|
56
63
|
if (rootElement && rulesInclude.length == 0) {
|
|
57
64
|
ctx = ctx.include({
|
|
58
65
|
elements: [index.find(rootElement)]
|
|
59
66
|
});
|
|
60
67
|
}
|
|
61
|
-
for (const {
|
|
62
|
-
isInclude,
|
|
63
|
-
exprs
|
|
64
|
-
} of rulesInclude) {
|
|
68
|
+
for (const { isInclude, exprs } of rulesInclude) {
|
|
65
69
|
for (const expr of exprs) {
|
|
66
70
|
if (Expr.isElementKindExpr(expr) || Expr.isElementTagExpr(expr)) {
|
|
67
|
-
ctx = isInclude ?
|
|
71
|
+
ctx = isInclude ? includeElementKindOrTag(ctx, expr) : excludeElementKindOrTag(ctx, expr);
|
|
68
72
|
continue;
|
|
69
73
|
}
|
|
70
74
|
if (Expr.isElementRef(expr)) {
|
|
71
|
-
ctx = isInclude ?
|
|
75
|
+
ctx = isInclude ? includeElementRef(ctx, expr) : excludeElementRef(ctx, expr);
|
|
72
76
|
continue;
|
|
73
77
|
}
|
|
74
78
|
if (Expr.isWildcard(expr)) {
|
|
75
|
-
ctx = isInclude ?
|
|
79
|
+
ctx = isInclude ? includeWildcardRef(ctx, expr) : excludeWildcardRef(ctx, expr);
|
|
76
80
|
continue;
|
|
77
81
|
}
|
|
78
82
|
if (Expr.isIncoming(expr)) {
|
|
79
|
-
ctx = isInclude ?
|
|
83
|
+
ctx = isInclude ? includeIncomingExpr(ctx, expr) : excludeIncomingExpr(ctx, expr);
|
|
80
84
|
continue;
|
|
81
85
|
}
|
|
82
86
|
if (Expr.isOutgoing(expr)) {
|
|
83
|
-
ctx = isInclude ?
|
|
87
|
+
ctx = isInclude ? includeOutgoingExpr(ctx, expr) : excludeOutgoingExpr(ctx, expr);
|
|
84
88
|
continue;
|
|
85
89
|
}
|
|
86
90
|
if (Expr.isInOut(expr)) {
|
|
87
|
-
ctx = isInclude ?
|
|
91
|
+
ctx = isInclude ? includeInOutExpr(ctx, expr) : excludeInOutExpr(ctx, expr);
|
|
88
92
|
continue;
|
|
89
93
|
}
|
|
90
94
|
if (Expr.isRelation(expr)) {
|
|
91
|
-
ctx = isInclude ?
|
|
95
|
+
ctx = isInclude ? includeRelationExpr(ctx, expr) : excludeRelationExpr(ctx, expr);
|
|
92
96
|
continue;
|
|
93
97
|
}
|
|
94
|
-
|
|
98
|
+
nonexhaustive(expr);
|
|
95
99
|
}
|
|
96
100
|
}
|
|
97
|
-
const allElements = [...ctx.elements, ...ctx.implicits].sort(
|
|
98
|
-
const elementsWithRelations = /* @__PURE__ */new Set();
|
|
99
|
-
const edgeBuilder = new
|
|
100
|
-
const anscestorOf = id => e => e.id === id ||
|
|
101
|
+
const allElements = [...ctx.elements, ...ctx.implicits].sort(compareByFqnHierarchically).reverse();
|
|
102
|
+
const elementsWithRelations = /* @__PURE__ */ new Set();
|
|
103
|
+
const edgeBuilder = new EdgeBuilder();
|
|
104
|
+
const anscestorOf = (id) => (e) => e.id === id || isAncestor(e.id, id);
|
|
101
105
|
const sortedRelations = [...ctx.relations];
|
|
102
106
|
for (const rel of sortedRelations) {
|
|
103
|
-
const source =
|
|
107
|
+
const source = find(allElements, anscestorOf(rel.source));
|
|
104
108
|
if (!source) {
|
|
105
109
|
continue;
|
|
106
110
|
}
|
|
107
|
-
const target =
|
|
111
|
+
const target = find(
|
|
112
|
+
allElements,
|
|
113
|
+
allPass([anscestorOf(rel.target), (e) => !isSameHierarchy(e, source)])
|
|
114
|
+
);
|
|
108
115
|
if (!target) {
|
|
109
116
|
continue;
|
|
110
117
|
}
|
|
@@ -112,28 +119,29 @@ function computeElementView(view, index) {
|
|
|
112
119
|
elementsWithRelations.add(target);
|
|
113
120
|
edgeBuilder.add(source.id, target.id, rel);
|
|
114
121
|
}
|
|
115
|
-
const elements = /* @__PURE__ */new Set([...ctx.elements, ...elementsWithRelations]);
|
|
122
|
+
const elements = /* @__PURE__ */ new Set([...ctx.elements, ...elementsWithRelations]);
|
|
116
123
|
const nodesMap = reduceToMap(elements);
|
|
117
|
-
const edges = edgeBuilder.build().map(edge => {
|
|
124
|
+
const edges = edgeBuilder.build().map((edge) => {
|
|
118
125
|
while (edge.parent) {
|
|
119
126
|
if (nodesMap.has(edge.parent)) {
|
|
120
127
|
break;
|
|
121
128
|
}
|
|
122
|
-
edge.parent =
|
|
129
|
+
edge.parent = parentFqn(edge.parent);
|
|
123
130
|
}
|
|
124
|
-
|
|
125
|
-
|
|
131
|
+
nonNullable(nodesMap.get(edge.source)).outEdges.push(edge.id);
|
|
132
|
+
nonNullable(nodesMap.get(edge.target)).inEdges.push(edge.id);
|
|
126
133
|
return edge;
|
|
127
134
|
});
|
|
128
|
-
const nodes =
|
|
129
|
-
|
|
135
|
+
const nodes = applyViewRuleStyles(
|
|
136
|
+
view.rules.filter(isViewRuleStyle),
|
|
137
|
+
sortNodes(nodesMap, edges)
|
|
138
|
+
// map(e => nodesMap.get(e.id)!, Array.from(elements))
|
|
130
139
|
);
|
|
131
|
-
|
|
132
|
-
const autoLayoutRule = view.rules.find(_view.isViewRuleAutoLayout);
|
|
140
|
+
const autoLayoutRule = view.rules.find(isViewRuleAutoLayout);
|
|
133
141
|
return {
|
|
134
142
|
...view,
|
|
135
143
|
autoLayout: autoLayoutRule?.autoLayout ?? "TB",
|
|
136
144
|
nodes,
|
|
137
145
|
edges
|
|
138
146
|
};
|
|
139
|
-
}
|
|
147
|
+
}
|