@likec4/core 0.33.1 → 0.34.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.
Files changed (120) hide show
  1. package/dist/{colors.mjs → colors.cjs} +15 -3
  2. package/dist/colors.js +3 -15
  3. package/dist/compute-view/EdgeBuilder.cjs +37 -0
  4. package/dist/compute-view/EdgeBuilder.d.ts +1 -2
  5. package/dist/compute-view/EdgeBuilder.js +10 -18
  6. package/dist/compute-view/compute-ctx.cjs +35 -0
  7. package/dist/compute-view/compute-ctx.js +21 -14
  8. package/dist/compute-view/compute-element-view.cjs +135 -0
  9. package/dist/compute-view/compute-element-view.js +70 -62
  10. package/dist/compute-view/compute-predicates.cjs +363 -0
  11. package/dist/compute-view/compute-predicates.d.ts +1 -1
  12. package/dist/compute-view/compute-predicates.js +81 -115
  13. package/dist/compute-view/compute.cjs +60 -0
  14. package/dist/compute-view/compute.d.ts +13 -4
  15. package/dist/compute-view/compute.js +24 -31
  16. package/dist/compute-view/index.cjs +27 -0
  17. package/dist/compute-view/index.d.ts +2 -3
  18. package/dist/compute-view/index.js +2 -24
  19. package/dist/compute-view/utils/anyPossibleRelations.cjs +18 -0
  20. package/dist/compute-view/utils/anyPossibleRelations.js +6 -12
  21. package/dist/compute-view/utils/applyViewRuleStyles.cjs +57 -0
  22. package/dist/compute-view/utils/applyViewRuleStyles.d.ts +1 -2
  23. package/dist/compute-view/utils/applyViewRuleStyles.js +20 -29
  24. package/dist/compute-view/utils/{sortNodes.mjs → sortNodes.cjs} +19 -9
  25. package/dist/compute-view/utils/sortNodes.js +9 -19
  26. package/dist/errors/_base.cjs +62 -0
  27. package/dist/errors/_base.d.ts +20 -3
  28. package/dist/errors/_base.js +41 -14
  29. package/dist/errors/index.cjs +60 -0
  30. package/dist/errors/index.js +5 -60
  31. package/dist/errors/invariant.cjs +23 -0
  32. package/dist/errors/invariant.d.ts +5 -1
  33. package/dist/errors/invariant.js +9 -12
  34. package/dist/errors/model-index.cjs +23 -0
  35. package/dist/errors/model-index.d.ts +5 -1
  36. package/dist/errors/model-index.js +9 -12
  37. package/dist/errors/non-nullable.cjs +23 -0
  38. package/dist/errors/non-nullable.d.ts +5 -1
  39. package/dist/errors/non-nullable.js +11 -14
  40. package/dist/errors/nonexhaustive.cjs +23 -0
  41. package/dist/errors/nonexhaustive.d.ts +6 -2
  42. package/dist/errors/nonexhaustive.js +12 -13
  43. package/dist/index.cjs +71 -0
  44. package/dist/index.d.ts +2 -5
  45. package/dist/index.js +6 -71
  46. package/dist/model-index/{ModelIndex.mjs → ModelIndex.cjs} +35 -23
  47. package/dist/model-index/ModelIndex.js +23 -35
  48. package/dist/model-index/index.cjs +13 -0
  49. package/dist/model-index/index.js +1 -13
  50. package/dist/types/_common.cjs +1 -0
  51. package/dist/types/_common.js +0 -1
  52. package/dist/types/computed-view.cjs +1 -0
  53. package/dist/types/computed-view.js +0 -1
  54. package/dist/types/diagram.cjs +1 -0
  55. package/dist/types/diagram.js +0 -1
  56. package/dist/types/element.cjs +14 -0
  57. package/dist/types/element.js +3 -12
  58. package/dist/types/expression.cjs +45 -0
  59. package/dist/types/expression.js +11 -26
  60. package/dist/types/index.cjs +132 -0
  61. package/dist/types/index.d.ts +10 -12
  62. package/dist/types/index.js +11 -48
  63. package/dist/types/model.cjs +1 -0
  64. package/dist/types/model.d.ts +1 -1
  65. package/dist/types/model.js +0 -1
  66. package/dist/types/opaque.cjs +1 -0
  67. package/dist/types/opaque.d.ts +1 -1
  68. package/dist/types/opaque.js +0 -1
  69. package/dist/types/relation.cjs +1 -0
  70. package/dist/types/relation.js +0 -1
  71. package/dist/types/theme.cjs +1 -0
  72. package/dist/types/theme.js +0 -1
  73. package/dist/types/view.cjs +17 -0
  74. package/dist/types/view.js +4 -12
  75. package/dist/utils/compute-node-levels.cjs +48 -0
  76. package/dist/utils/compute-node-levels.d.ts +2 -2
  77. package/dist/utils/compute-node-levels.js +7 -24
  78. package/dist/utils/fqn.cjs +80 -0
  79. package/dist/utils/fqn.js +19 -33
  80. package/dist/utils/guards.cjs +22 -0
  81. package/dist/utils/guards.js +7 -16
  82. package/dist/utils/index.cjs +49 -0
  83. package/dist/utils/index.d.ts +1 -1
  84. package/dist/utils/index.js +4 -49
  85. package/dist/utils/relations.cjs +59 -0
  86. package/dist/utils/relations.d.ts +14 -12
  87. package/dist/utils/relations.js +28 -33
  88. package/package.json +58 -21
  89. package/dist/compute-view/EdgeBuilder.mjs +0 -31
  90. package/dist/compute-view/compute-ctx.mjs +0 -42
  91. package/dist/compute-view/compute-element-view.mjs +0 -145
  92. package/dist/compute-view/compute-predicates.mjs +0 -324
  93. package/dist/compute-view/compute.mjs +0 -39
  94. package/dist/compute-view/index.mjs +0 -1
  95. package/dist/compute-view/utils/anyPossibleRelations.mjs +0 -12
  96. package/dist/compute-view/utils/applyViewRuleStyles.mjs +0 -50
  97. package/dist/errors/_base.mjs +0 -4
  98. package/dist/errors/index.mjs +0 -5
  99. package/dist/errors/invariant.mjs +0 -8
  100. package/dist/errors/model-index.mjs +0 -8
  101. package/dist/errors/non-nullable.mjs +0 -8
  102. package/dist/errors/nonexhaustive.mjs +0 -5
  103. package/dist/index.mjs +0 -6
  104. package/dist/model-index/index.mjs +0 -1
  105. package/dist/types/_common.mjs +0 -0
  106. package/dist/types/computed-view.mjs +0 -0
  107. package/dist/types/diagram.mjs +0 -0
  108. package/dist/types/element.mjs +0 -5
  109. package/dist/types/expression.mjs +0 -30
  110. package/dist/types/index.mjs +0 -3
  111. package/dist/types/model.mjs +0 -0
  112. package/dist/types/opaque.mjs +0 -0
  113. package/dist/types/relation.mjs +0 -0
  114. package/dist/types/theme.mjs +0 -0
  115. package/dist/types/view.mjs +0 -9
  116. package/dist/utils/compute-node-levels.mjs +0 -31
  117. package/dist/utils/fqn.mjs +0 -66
  118. package/dist/utils/guards.mjs +0 -13
  119. package/dist/utils/index.mjs +0 -4
  120. 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
- export const RelationColors = {
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
- export const Colors = {
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
- export const defaultTheme = {
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
- exports.RelationColors = RelationColors;
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
- exports.Colors = Colors;
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
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
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 (0, _rambdax.keys)(this._relationsObj).flatMap(source => {
14
+ return keys(this._relationsObj).flatMap((source) => {
22
15
  const targets = this._relationsObj[source] ?? {};
23
- return (0, _rambdax.keys)(targets).map(target => {
24
- const relations = (targets[target] ?? []).sort(_relations.compareRelations);
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: (0, _fqn.commonAncestor)(source, target),
21
+ parent: commonAncestor(source, target),
29
22
  source,
30
23
  target,
31
24
  label,
32
- relations: (0, _rambdax.pluck)("id", relations)
25
+ relations: pluck("id", relations)
33
26
  };
34
27
  });
35
- }).sort(_relations.compareRelations).reverse();
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
- "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()) {
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(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);
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((0, _rambdax.difference)([...this.implicits], implicits)) : this.implicits;
28
+ let newImplicits = implicits ? new Set(difference([...this.implicits], implicits)) : this.implicits;
29
29
  if (elements) {
30
- newImplicits = new Set((0, _rambdax.difference)([...newImplicits], elements));
30
+ newImplicits = new Set(
31
+ difference([...newImplicits], elements)
32
+ );
31
33
  }
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);
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
- "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");
9
- var _types = require("../types");
10
- var Expr = _interopRequireWildcard(require("../types/expression"));
11
- var _view = require("../types/view");
12
- var _utils = require("../utils");
13
- var _EdgeBuilder = require("./EdgeBuilder");
14
- var _computeCtx = require("./compute-ctx");
15
- var _computePredicates = require("./compute-predicates");
16
- var _applyViewRuleStyles = require("./utils/applyViewRuleStyles");
17
- var _sortNodes = require("./utils/sortNodes");
18
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
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(_utils.compareByFqnHierarchically).reduce((map, {
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 = (0, _utils.parentFqn)(parent);
39
+ parent = parentFqn(parent);
33
40
  }
34
41
  if (parent) {
35
- const parentNd = (0, _errors.nonNullable)(map.get(parent));
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 ?? _types.DefaultThemeColor,
43
- shape: shape ?? _types.DefaultElementShape,
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 _computeCtx.ComputeCtx(index, rootElement);
55
- const rulesInclude = view.rules.filter(_view.isViewRuleExpression);
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 ? (0, _computePredicates.includeElementKindOrTag)(ctx, expr) : (0, _computePredicates.excludeElementKindOrTag)(ctx, expr);
71
+ ctx = isInclude ? includeElementKindOrTag(ctx, expr) : excludeElementKindOrTag(ctx, expr);
68
72
  continue;
69
73
  }
70
74
  if (Expr.isElementRef(expr)) {
71
- ctx = isInclude ? (0, _computePredicates.includeElementRef)(ctx, expr) : (0, _computePredicates.excludeElementRef)(ctx, expr);
75
+ ctx = isInclude ? includeElementRef(ctx, expr) : excludeElementRef(ctx, expr);
72
76
  continue;
73
77
  }
74
78
  if (Expr.isWildcard(expr)) {
75
- ctx = isInclude ? (0, _computePredicates.includeWildcardRef)(ctx, expr) : (0, _computePredicates.excludeWildcardRef)(ctx, expr);
79
+ ctx = isInclude ? includeWildcardRef(ctx, expr) : excludeWildcardRef(ctx, expr);
76
80
  continue;
77
81
  }
78
82
  if (Expr.isIncoming(expr)) {
79
- ctx = isInclude ? (0, _computePredicates.includeIncomingExpr)(ctx, expr) : (0, _computePredicates.excludeIncomingExpr)(ctx, expr);
83
+ ctx = isInclude ? includeIncomingExpr(ctx, expr) : excludeIncomingExpr(ctx, expr);
80
84
  continue;
81
85
  }
82
86
  if (Expr.isOutgoing(expr)) {
83
- ctx = isInclude ? (0, _computePredicates.includeOutgoingExpr)(ctx, expr) : (0, _computePredicates.excludeOutgoingExpr)(ctx, expr);
87
+ ctx = isInclude ? includeOutgoingExpr(ctx, expr) : excludeOutgoingExpr(ctx, expr);
84
88
  continue;
85
89
  }
86
90
  if (Expr.isInOut(expr)) {
87
- ctx = isInclude ? (0, _computePredicates.includeInOutExpr)(ctx, expr) : (0, _computePredicates.excludeInOutExpr)(ctx, expr);
91
+ ctx = isInclude ? includeInOutExpr(ctx, expr) : excludeInOutExpr(ctx, expr);
88
92
  continue;
89
93
  }
90
94
  if (Expr.isRelation(expr)) {
91
- ctx = isInclude ? (0, _computePredicates.includeRelationExpr)(ctx, expr) : (0, _computePredicates.excludeRelationExpr)(ctx, expr);
95
+ ctx = isInclude ? includeRelationExpr(ctx, expr) : excludeRelationExpr(ctx, expr);
92
96
  continue;
93
97
  }
94
- (0, _errors.nonexhaustive)(expr);
98
+ nonexhaustive(expr);
95
99
  }
96
100
  }
97
- const allElements = [...ctx.elements, ...ctx.implicits].sort(_utils.compareByFqnHierarchically).reverse();
98
- const elementsWithRelations = /* @__PURE__ */new Set();
99
- const edgeBuilder = new _EdgeBuilder.EdgeBuilder();
100
- const anscestorOf = id => e => e.id === id || (0, _utils.isAncestor)(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 = (0, _remeda.find)(allElements, anscestorOf(rel.source));
107
+ const source = find(allElements, anscestorOf(rel.source));
104
108
  if (!source) {
105
109
  continue;
106
110
  }
107
- const target = (0, _remeda.find)(allElements, (0, _remeda.allPass)([anscestorOf(rel.target), e => !(0, _utils.isSameHierarchy)(e, source)]));
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 = (0, _utils.parentFqn)(edge.parent);
129
+ edge.parent = parentFqn(edge.parent);
123
130
  }
124
- (0, _errors.nonNullable)(nodesMap.get(edge.source)).outEdges.push(edge.id);
125
- (0, _errors.nonNullable)(nodesMap.get(edge.target)).inEdges.push(edge.id);
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 = (0, _applyViewRuleStyles.applyViewRuleStyles)(view.rules.filter(_view.isViewRuleStyle), (0, _sortNodes.sortNodes)(nodesMap, edges)
129
- // map(e => nodesMap.get(e.id)!, Array.from(elements))
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
+ }