@likec4/core 0.32.0 → 0.33.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 (106) hide show
  1. package/dist/colors.d.ts +76 -9
  2. package/dist/colors.js +116 -93
  3. package/dist/colors.mjs +112 -0
  4. package/dist/compute-view/EdgeBuilder.d.ts +0 -1
  5. package/dist/compute-view/EdgeBuilder.js +37 -34
  6. package/dist/compute-view/EdgeBuilder.mjs +31 -0
  7. package/dist/compute-view/compute-ctx.d.ts +0 -1
  8. package/dist/compute-view/compute-ctx.js +33 -24
  9. package/dist/compute-view/compute-ctx.mjs +42 -0
  10. package/dist/compute-view/compute-element-view.d.ts +2 -3
  11. package/dist/compute-view/compute-element-view.js +137 -525
  12. package/dist/compute-view/compute-element-view.mjs +145 -0
  13. package/dist/compute-view/compute-predicates.d.ts +16 -0
  14. package/dist/compute-view/compute-predicates.js +358 -0
  15. package/dist/compute-view/compute-predicates.mjs +324 -0
  16. package/dist/compute-view/compute.d.ts +8 -9
  17. package/dist/compute-view/compute.js +49 -39
  18. package/dist/compute-view/compute.mjs +39 -0
  19. package/dist/compute-view/index.d.ts +1 -1
  20. package/dist/compute-view/index.js +24 -2
  21. package/dist/compute-view/index.mjs +1 -0
  22. package/dist/compute-view/utils/anyPossibleRelations.d.ts +0 -1
  23. package/dist/compute-view/utils/anyPossibleRelations.js +17 -12
  24. package/dist/compute-view/utils/anyPossibleRelations.mjs +12 -0
  25. package/dist/compute-view/utils/applyViewRuleStyles.d.ts +3 -0
  26. package/dist/compute-view/utils/applyViewRuleStyles.js +59 -0
  27. package/dist/compute-view/utils/applyViewRuleStyles.mjs +50 -0
  28. package/dist/compute-view/utils/sortNodes.d.ts +0 -1
  29. package/dist/compute-view/utils/sortNodes.js +47 -42
  30. package/dist/compute-view/utils/sortNodes.mjs +40 -0
  31. package/dist/errors/_base.d.ts +0 -1
  32. package/dist/errors/_base.js +14 -11
  33. package/dist/errors/_base.mjs +4 -0
  34. package/dist/errors/index.d.ts +1 -1
  35. package/dist/errors/index.js +60 -5
  36. package/dist/errors/index.mjs +5 -0
  37. package/dist/errors/invariant.d.ts +0 -2
  38. package/dist/errors/invariant.js +16 -21
  39. package/dist/errors/invariant.mjs +8 -0
  40. package/dist/errors/model-index.d.ts +0 -1
  41. package/dist/errors/model-index.js +16 -14
  42. package/dist/errors/model-index.mjs +8 -0
  43. package/dist/errors/non-nullable.d.ts +2 -0
  44. package/dist/errors/non-nullable.js +16 -0
  45. package/dist/errors/non-nullable.mjs +8 -0
  46. package/dist/errors/nonexhaustive.d.ts +0 -1
  47. package/dist/errors/nonexhaustive.js +13 -6
  48. package/dist/errors/nonexhaustive.mjs +5 -0
  49. package/dist/index.d.ts +6 -3
  50. package/dist/index.js +71 -7
  51. package/dist/index.mjs +6 -0
  52. package/dist/model-index/ModelIndex.d.ts +0 -1
  53. package/dist/model-index/ModelIndex.js +125 -122
  54. package/dist/model-index/ModelIndex.mjs +128 -0
  55. package/dist/model-index/index.d.ts +0 -1
  56. package/dist/model-index/index.js +13 -2
  57. package/dist/model-index/index.mjs +1 -0
  58. package/dist/types/_common.d.ts +0 -1
  59. package/dist/types/_common.js +1 -2
  60. package/dist/types/_common.mjs +0 -0
  61. package/dist/types/computed-view.d.ts +7 -6
  62. package/dist/types/computed-view.js +1 -2
  63. package/dist/types/computed-view.mjs +0 -0
  64. package/dist/types/diagram.d.ts +5 -2
  65. package/dist/types/diagram.js +1 -2
  66. package/dist/types/diagram.mjs +0 -0
  67. package/dist/types/element.d.ts +3 -7
  68. package/dist/types/element.js +13 -5
  69. package/dist/types/element.mjs +5 -0
  70. package/dist/types/expression.d.ts +0 -1
  71. package/dist/types/expression.js +45 -31
  72. package/dist/types/expression.mjs +30 -0
  73. package/dist/types/index.d.ts +1 -1
  74. package/dist/types/index.js +48 -4
  75. package/dist/types/index.mjs +3 -0
  76. package/dist/types/model.d.ts +0 -1
  77. package/dist/types/model.js +1 -2
  78. package/dist/types/model.mjs +0 -0
  79. package/dist/types/opaque.d.ts +0 -1
  80. package/dist/types/opaque.js +1 -2
  81. package/dist/types/opaque.mjs +0 -0
  82. package/dist/types/relation.d.ts +0 -1
  83. package/dist/types/relation.js +1 -2
  84. package/dist/types/relation.mjs +0 -0
  85. package/dist/types/theme.d.ts +22 -0
  86. package/dist/types/theme.js +1 -0
  87. package/dist/types/theme.mjs +0 -0
  88. package/dist/types/view.d.ts +2 -2
  89. package/dist/types/view.js +15 -8
  90. package/dist/types/view.mjs +9 -0
  91. package/dist/utils/compute-node-levels.d.ts +0 -1
  92. package/dist/utils/compute-node-levels.js +45 -29
  93. package/dist/utils/compute-node-levels.mjs +31 -0
  94. package/dist/utils/fqn.d.ts +0 -1
  95. package/dist/utils/fqn.js +71 -71
  96. package/dist/utils/fqn.mjs +66 -0
  97. package/dist/utils/guards.d.ts +0 -1
  98. package/dist/utils/guards.js +19 -12
  99. package/dist/utils/guards.mjs +13 -0
  100. package/dist/utils/index.d.ts +0 -1
  101. package/dist/utils/index.js +49 -5
  102. package/dist/utils/index.mjs +4 -0
  103. package/dist/utils/relations.d.ts +0 -1
  104. package/dist/utils/relations.js +56 -49
  105. package/dist/utils/relations.mjs +42 -0
  106. package/package.json +20 -55
package/dist/colors.d.ts CHANGED
@@ -1,10 +1,3 @@
1
- type Color = `#${string}`;
2
- export interface ElementColors {
3
- fill: Color;
4
- stroke: Color;
5
- hiContrast: Color;
6
- loContrast: Color;
7
- }
8
1
  export declare const RelationColors: {
9
2
  readonly lineColor: "#a3a3a3";
10
3
  readonly labelColor: "#d4d4d4";
@@ -77,5 +70,79 @@ export declare const Colors: {
77
70
  readonly loContrast: "#c7d2fe";
78
71
  };
79
72
  };
80
- export {};
81
- //# sourceMappingURL=colors.d.ts.map
73
+ export declare const defaultTheme: {
74
+ readonly font: "Helvetica";
75
+ readonly shadow: "#0a0a0a";
76
+ readonly relation: {
77
+ readonly lineColor: "#a3a3a3";
78
+ readonly labelColor: "#d4d4d4";
79
+ };
80
+ readonly colors: {
81
+ readonly primary: {
82
+ fill: "#3b82f6";
83
+ stroke: "#2563eb";
84
+ hiContrast: "#eff6ff";
85
+ loContrast: "#dbeafe";
86
+ };
87
+ readonly blue: {
88
+ fill: "#3b82f6";
89
+ stroke: "#2563eb";
90
+ hiContrast: "#eff6ff";
91
+ loContrast: "#dbeafe";
92
+ };
93
+ readonly secondary: {
94
+ fill: "#0284c7";
95
+ stroke: "#0369a1";
96
+ hiContrast: "#f0f9ff";
97
+ loContrast: "#e0f2fe";
98
+ };
99
+ readonly sky: {
100
+ fill: "#0284c7";
101
+ stroke: "#0369a1";
102
+ hiContrast: "#f0f9ff";
103
+ loContrast: "#e0f2fe";
104
+ };
105
+ readonly muted: {
106
+ fill: "#64748b";
107
+ stroke: "#475569";
108
+ hiContrast: "#f8fafc";
109
+ loContrast: "#e2e8f0";
110
+ };
111
+ readonly slate: {
112
+ fill: "#64748b";
113
+ stroke: "#475569";
114
+ hiContrast: "#f8fafc";
115
+ loContrast: "#e2e8f0";
116
+ };
117
+ readonly gray: {
118
+ readonly fill: "#737373";
119
+ readonly stroke: "#525252";
120
+ readonly hiContrast: "#fafafa";
121
+ readonly loContrast: "#e5e5e5";
122
+ };
123
+ readonly red: {
124
+ readonly fill: "#ef4444";
125
+ readonly stroke: "#dc2626";
126
+ readonly hiContrast: "#111827";
127
+ readonly loContrast: "#1f2937";
128
+ };
129
+ readonly green: {
130
+ readonly fill: "#16a34a";
131
+ readonly stroke: "#15803d";
132
+ readonly hiContrast: "#111827";
133
+ readonly loContrast: "#1f2937";
134
+ };
135
+ readonly amber: {
136
+ readonly fill: "#d97706";
137
+ readonly stroke: "#b45309";
138
+ readonly hiContrast: "#111827";
139
+ readonly loContrast: "#1f2937";
140
+ };
141
+ readonly indigo: {
142
+ readonly fill: "#6366f1";
143
+ readonly stroke: "#4f46e5";
144
+ readonly hiContrast: "#eef2ff";
145
+ readonly loContrast: "#c7d2fe";
146
+ };
147
+ };
148
+ };
package/dist/colors.js CHANGED
@@ -1,101 +1,124 @@
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
- // fill: colors.blue[500],
3
- // stroke: colors.blue[600],
4
- // hiContrast: colors.blue[50],
5
- // loContrast: colors.blue[100],
6
- fill: '#3b82f6',
7
- stroke: '#2563eb',
8
- hiContrast: '#eff6ff',
9
- loContrast: '#dbeafe'
8
+ // fill: colors.blue[500],
9
+ // stroke: colors.blue[600],
10
+ // hiContrast: colors.blue[50],
11
+ // loContrast: colors.blue[100],
12
+ fill: "#3b82f6",
13
+ stroke: "#2563eb",
14
+ hiContrast: "#eff6ff",
15
+ loContrast: "#dbeafe"
10
16
  };
11
17
  const sky = {
12
- // fill: colors.sky[600],
13
- // stroke: colors.sky[700],
14
- // hiContrast: colors.sky[50],
15
- // loContrast: colors.sky[100],
16
- fill: '#0284c7',
17
- stroke: '#0369a1',
18
- hiContrast: '#f0f9ff',
19
- loContrast: '#e0f2fe'
18
+ // fill: colors.sky[600],
19
+ // stroke: colors.sky[700],
20
+ // hiContrast: colors.sky[50],
21
+ // loContrast: colors.sky[100],
22
+ fill: "#0284c7",
23
+ stroke: "#0369a1",
24
+ hiContrast: "#f0f9ff",
25
+ loContrast: "#e0f2fe"
20
26
  };
21
27
  const slate = {
22
- // fill: colors.slate[500],
23
- // stroke: colors.slate[600],
24
- // hiContrast: colors.slate[50],
25
- // loContrast: colors.slate[200],
26
- fill: '#64748b',
27
- stroke: '#475569',
28
- hiContrast: '#f8fafc',
29
- loContrast: '#e2e8f0'
28
+ // fill: colors.slate[500],
29
+ // stroke: colors.slate[600],
30
+ // hiContrast: colors.slate[50],
31
+ // loContrast: colors.slate[200],
32
+ fill: "#64748b",
33
+ stroke: "#475569",
34
+ hiContrast: "#f8fafc",
35
+ loContrast: "#e2e8f0"
30
36
  };
31
- export const RelationColors = {
32
- // lineColor: colors.neutral[400],
33
- // labelColor: colors.neutral[300],
34
- lineColor: '#a3a3a3',
35
- labelColor: '#d4d4d4'
37
+ const RelationColors = {
38
+ // lineColor: colors.neutral[400],
39
+ // labelColor: colors.neutral[300],
40
+ lineColor: "#a3a3a3",
41
+ labelColor: "#d4d4d4"
36
42
  };
37
- export const Colors = {
38
- primary: blue,
39
- blue,
40
- secondary: sky,
41
- sky,
42
- muted: slate,
43
- slate,
44
- gray: {
45
- // fill: colors.neutral[500],
46
- // stroke: colors.neutral[600],
47
- // hiContrast: colors.neutral[50],
48
- // loContrast: colors.neutral[200],
49
- fill: '#737373',
50
- stroke: '#525252',
51
- hiContrast: '#fafafa',
52
- loContrast: '#e5e5e5'
53
- },
54
- red: {
55
- // fill: colors.red[500],
56
- // stroke: colors.red[600],
57
- // hiContrast: colors.red[50],
58
- // loContrast: colors.red[200],
59
- fill: '#ef4444',
60
- stroke: '#dc2626',
61
- // hiContrast: '#fef2f2',
62
- // loContrast: '#fecaca',
63
- hiContrast: '#111827',
64
- loContrast: '#1f2937' // colors.gray[800],
65
- },
66
- green: {
67
- // fill: colors.green[600],
68
- // stroke: colors.green[700],
69
- // hiContrast: colors.green[50],
70
- // loContrast: colors.green[200],
71
- fill: '#16a34a',
72
- stroke: '#15803d',
73
- hiContrast: '#111827',
74
- // hiContrast: '#f0fdf4',
75
- loContrast: '#1f2937' // colors.gray[800],
76
- // loContrast: '#bbf7d0'
77
- },
78
- amber: {
79
- // fill: colors.amber[600],
80
- // stroke: colors.amber[700],
81
- // hiContrast: colors.amber[50],
82
- // loContrast: colors.amber[200],
83
- fill: '#d97706',
84
- stroke: '#b45309',
85
- // hiContrast: '#fffbeb',
86
- // loContrast: '#fde68a',
87
- hiContrast: '#111827',
88
- loContrast: '#1f2937' // colors.gray[800],
89
- },
90
- indigo: {
91
- // fill: colors.indigo[500],
92
- // stroke: colors.indigo[600],
93
- // hiContrast: colors.indigo[50],
94
- // loContrast: colors.indigo[200],
95
- fill: '#6366f1',
96
- stroke: '#4f46e5',
97
- hiContrast: '#eef2ff',
98
- loContrast: '#c7d2fe'
99
- }
43
+ exports.RelationColors = RelationColors;
44
+ const Colors = {
45
+ primary: blue,
46
+ blue,
47
+ secondary: sky,
48
+ sky,
49
+ muted: slate,
50
+ slate,
51
+ gray: {
52
+ // fill: colors.neutral[500],
53
+ // stroke: colors.neutral[600],
54
+ // hiContrast: colors.neutral[50],
55
+ // loContrast: colors.neutral[200],
56
+ fill: "#737373",
57
+ stroke: "#525252",
58
+ hiContrast: "#fafafa",
59
+ loContrast: "#e5e5e5"
60
+ },
61
+ red: {
62
+ // fill: colors.red[500],
63
+ // stroke: colors.red[600],
64
+ // hiContrast: colors.red[50],
65
+ // loContrast: colors.red[200],
66
+ fill: "#ef4444",
67
+ stroke: "#dc2626",
68
+ // hiContrast: '#fef2f2',
69
+ // loContrast: '#fecaca',
70
+ hiContrast: "#111827",
71
+ // colors.gray[900],
72
+ loContrast: "#1f2937"
73
+ // colors.gray[800],
74
+ },
75
+
76
+ green: {
77
+ // fill: colors.green[600],
78
+ // stroke: colors.green[700],
79
+ // hiContrast: colors.green[50],
80
+ // loContrast: colors.green[200],
81
+ fill: "#16a34a",
82
+ stroke: "#15803d",
83
+ hiContrast: "#111827",
84
+ // colors.gray[900],
85
+ // hiContrast: '#f0fdf4',
86
+ loContrast: "#1f2937"
87
+ // colors.gray[800],
88
+ // loContrast: '#bbf7d0'
89
+ },
90
+
91
+ amber: {
92
+ // fill: colors.amber[600],
93
+ // stroke: colors.amber[700],
94
+ // hiContrast: colors.amber[50],
95
+ // loContrast: colors.amber[200],
96
+ fill: "#d97706",
97
+ stroke: "#b45309",
98
+ // hiContrast: '#fffbeb',
99
+ // loContrast: '#fde68a',
100
+ hiContrast: "#111827",
101
+ // colors.gray[900],
102
+ loContrast: "#1f2937"
103
+ // colors.gray[800],
104
+ },
105
+
106
+ indigo: {
107
+ // fill: colors.indigo[500],
108
+ // stroke: colors.indigo[600],
109
+ // hiContrast: colors.indigo[50],
110
+ // loContrast: colors.indigo[200],
111
+ fill: "#6366f1",
112
+ stroke: "#4f46e5",
113
+ hiContrast: "#eef2ff",
114
+ loContrast: "#c7d2fe"
115
+ }
100
116
  };
101
- //# sourceMappingURL=colors.js.map
117
+ exports.Colors = Colors;
118
+ const defaultTheme = {
119
+ font: "Helvetica",
120
+ shadow: "#0a0a0a",
121
+ relation: RelationColors,
122
+ colors: Colors
123
+ };
124
+ exports.defaultTheme = defaultTheme;
@@ -0,0 +1,112 @@
1
+ const blue = {
2
+ // fill: colors.blue[500],
3
+ // stroke: colors.blue[600],
4
+ // hiContrast: colors.blue[50],
5
+ // loContrast: colors.blue[100],
6
+ fill: "#3b82f6",
7
+ stroke: "#2563eb",
8
+ hiContrast: "#eff6ff",
9
+ loContrast: "#dbeafe"
10
+ };
11
+ const sky = {
12
+ // fill: colors.sky[600],
13
+ // stroke: colors.sky[700],
14
+ // hiContrast: colors.sky[50],
15
+ // loContrast: colors.sky[100],
16
+ fill: "#0284c7",
17
+ stroke: "#0369a1",
18
+ hiContrast: "#f0f9ff",
19
+ loContrast: "#e0f2fe"
20
+ };
21
+ const slate = {
22
+ // fill: colors.slate[500],
23
+ // stroke: colors.slate[600],
24
+ // hiContrast: colors.slate[50],
25
+ // loContrast: colors.slate[200],
26
+ fill: "#64748b",
27
+ stroke: "#475569",
28
+ hiContrast: "#f8fafc",
29
+ loContrast: "#e2e8f0"
30
+ };
31
+ export const RelationColors = {
32
+ // lineColor: colors.neutral[400],
33
+ // labelColor: colors.neutral[300],
34
+ lineColor: "#a3a3a3",
35
+ labelColor: "#d4d4d4"
36
+ };
37
+ export const Colors = {
38
+ primary: blue,
39
+ blue,
40
+ secondary: sky,
41
+ sky,
42
+ muted: slate,
43
+ slate,
44
+ gray: {
45
+ // fill: colors.neutral[500],
46
+ // stroke: colors.neutral[600],
47
+ // hiContrast: colors.neutral[50],
48
+ // loContrast: colors.neutral[200],
49
+ fill: "#737373",
50
+ stroke: "#525252",
51
+ hiContrast: "#fafafa",
52
+ loContrast: "#e5e5e5"
53
+ },
54
+ red: {
55
+ // fill: colors.red[500],
56
+ // stroke: colors.red[600],
57
+ // hiContrast: colors.red[50],
58
+ // loContrast: colors.red[200],
59
+ fill: "#ef4444",
60
+ stroke: "#dc2626",
61
+ // hiContrast: '#fef2f2',
62
+ // loContrast: '#fecaca',
63
+ hiContrast: "#111827",
64
+ // colors.gray[900],
65
+ loContrast: "#1f2937"
66
+ // colors.gray[800],
67
+ },
68
+ green: {
69
+ // fill: colors.green[600],
70
+ // stroke: colors.green[700],
71
+ // hiContrast: colors.green[50],
72
+ // loContrast: colors.green[200],
73
+ fill: "#16a34a",
74
+ stroke: "#15803d",
75
+ hiContrast: "#111827",
76
+ // colors.gray[900],
77
+ // hiContrast: '#f0fdf4',
78
+ loContrast: "#1f2937"
79
+ // colors.gray[800],
80
+ // loContrast: '#bbf7d0'
81
+ },
82
+ amber: {
83
+ // fill: colors.amber[600],
84
+ // stroke: colors.amber[700],
85
+ // hiContrast: colors.amber[50],
86
+ // loContrast: colors.amber[200],
87
+ fill: "#d97706",
88
+ stroke: "#b45309",
89
+ // hiContrast: '#fffbeb',
90
+ // loContrast: '#fde68a',
91
+ hiContrast: "#111827",
92
+ // colors.gray[900],
93
+ loContrast: "#1f2937"
94
+ // colors.gray[800],
95
+ },
96
+ indigo: {
97
+ // fill: colors.indigo[500],
98
+ // stroke: colors.indigo[600],
99
+ // hiContrast: colors.indigo[50],
100
+ // loContrast: colors.indigo[200],
101
+ fill: "#6366f1",
102
+ stroke: "#4f46e5",
103
+ hiContrast: "#eef2ff",
104
+ loContrast: "#c7d2fe"
105
+ }
106
+ };
107
+ export const defaultTheme = {
108
+ font: "Helvetica",
109
+ shadow: "#0a0a0a",
110
+ relation: RelationColors,
111
+ colors: Colors
112
+ };
@@ -5,4 +5,3 @@ export declare class EdgeBuilder {
5
5
  add(source: Fqn, target: Fqn, relation: Relation): this;
6
6
  build(): ComputedEdge[];
7
7
  }
8
- //# sourceMappingURL=EdgeBuilder.d.ts.map
@@ -1,35 +1,38 @@
1
- import { equals, head, keys, pluck, reject } from 'rambdax';
2
- import { commonAncestor } from '../utils/fqn';
3
- import { compareRelations } from '../utils/relations';
4
- export class EdgeBuilder {
5
- _relationsObj = {};
6
- add(source, target, relation) {
7
- const bySource = this._relationsObj[source] ?? {};
8
- const relations = bySource[target] ?? [];
9
- relations.push(relation);
10
- bySource[target] = relations;
11
- this._relationsObj[source] = bySource;
12
- return this;
13
- }
14
- build() {
15
- return keys(this._relationsObj)
16
- .flatMap(source => {
17
- const targets = this._relationsObj[source] ?? {};
18
- return keys(targets).map(target => {
19
- const relations = (targets[target] ?? []).sort(compareRelations);
20
- const label = head(reject(equals(''), pluck('title', relations))) ?? null;
21
- return {
22
- id: `${source}:${target}`,
23
- parent: commonAncestor(source, target),
24
- source,
25
- target,
26
- label,
27
- relations: pluck('id', relations)
28
- };
29
- });
30
- })
31
- .sort(compareRelations)
32
- .reverse();
33
- }
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 {
11
+ _relationsObj = {};
12
+ add(source, target, relation) {
13
+ const bySource = this._relationsObj[source] ?? {};
14
+ const relations = bySource[target] ?? [];
15
+ relations.push(relation);
16
+ bySource[target] = relations;
17
+ this._relationsObj[source] = bySource;
18
+ return this;
19
+ }
20
+ build() {
21
+ return (0, _rambdax.keys)(this._relationsObj).flatMap(source => {
22
+ 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;
26
+ return {
27
+ id: `${source}:${target}`,
28
+ parent: (0, _fqn.commonAncestor)(source, target),
29
+ source,
30
+ target,
31
+ label,
32
+ relations: (0, _rambdax.pluck)("id", relations)
33
+ };
34
+ });
35
+ }).sort(_relations.compareRelations).reverse();
36
+ }
34
37
  }
35
- //# sourceMappingURL=EdgeBuilder.js.map
38
+ exports.EdgeBuilder = EdgeBuilder;
@@ -0,0 +1,31 @@
1
+ import { keys, pluck } from "rambdax";
2
+ import { commonAncestor } from "../utils/fqn.mjs";
3
+ import { compareRelations } from "../utils/relations.mjs";
4
+ export class EdgeBuilder {
5
+ _relationsObj = {};
6
+ add(source, target, relation) {
7
+ const bySource = this._relationsObj[source] ?? {};
8
+ const relations = bySource[target] ?? [];
9
+ relations.push(relation);
10
+ bySource[target] = relations;
11
+ this._relationsObj[source] = bySource;
12
+ return this;
13
+ }
14
+ build() {
15
+ return keys(this._relationsObj).flatMap((source) => {
16
+ const targets = this._relationsObj[source] ?? {};
17
+ return keys(targets).map((target) => {
18
+ const relations = (targets[target] ?? []).sort(compareRelations);
19
+ const label = relations.find((r) => r.title !== "")?.title ?? null;
20
+ return {
21
+ id: `${source}:${target}`,
22
+ parent: commonAncestor(source, target),
23
+ source,
24
+ target,
25
+ label,
26
+ relations: pluck("id", relations)
27
+ };
28
+ });
29
+ }).sort(compareRelations).reverse();
30
+ }
31
+ }
@@ -15,4 +15,3 @@ export declare class ComputeCtx {
15
15
  include({ elements, relations, implicits }: ComputeCtxPatch): ComputeCtx;
16
16
  exclude({ elements, relations, implicits }: ComputeCtxPatch): ComputeCtx;
17
17
  }
18
- //# sourceMappingURL=compute-ctx.d.ts.map
@@ -1,26 +1,35 @@
1
- import { difference } from 'rambdax';
2
- export class ComputeCtx {
3
- index;
4
- root;
5
- elements;
6
- relations;
7
- implicits;
8
- constructor(index, root, elements = new Set(), relations = new Set(), implicits = new Set()) {
9
- this.index = index;
10
- this.root = root;
11
- this.elements = elements;
12
- this.relations = relations;
13
- this.implicits = implicits;
14
- }
15
- include({ elements, relations, implicits }) {
16
- return new ComputeCtx(this.index, this.root, elements ? new Set([...this.elements, ...elements]) : this.elements, relations ? new Set([...this.relations, ...relations]) : this.relations, implicits ? new Set([...this.implicits, ...implicits]) : this.implicits);
17
- }
18
- exclude({ elements, relations, implicits }) {
19
- let newImplicits = implicits ? new Set(difference([...this.implicits], implicits)) : this.implicits;
20
- if (elements) {
21
- newImplicits = new Set(difference([...newImplicits], elements));
22
- }
23
- return new ComputeCtx(this.index, this.root, elements ? new Set(difference([...this.elements], elements)) : this.elements, relations ? new Set(difference([...this.relations], relations)) : this.relations, newImplicits);
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));
24
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
+ }
25
34
  }
26
- //# sourceMappingURL=compute-ctx.js.map
35
+ exports.ComputeCtx = ComputeCtx;
@@ -0,0 +1,42 @@
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()) {
4
+ this.index = index;
5
+ this.root = root;
6
+ this.elements = elements;
7
+ this.relations = relations;
8
+ this.implicits = implicits;
9
+ }
10
+ include({
11
+ elements,
12
+ relations,
13
+ implicits
14
+ }) {
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
+ }
23
+ exclude({
24
+ elements,
25
+ relations,
26
+ implicits
27
+ }) {
28
+ let newImplicits = implicits ? new Set(difference([...this.implicits], implicits)) : this.implicits;
29
+ if (elements) {
30
+ newImplicits = new Set(
31
+ difference([...newImplicits], elements)
32
+ );
33
+ }
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
+ );
41
+ }
42
+ }
@@ -1,4 +1,3 @@
1
1
  import type { ModelIndex } from '../model-index';
2
- import { type ComputeResult, type ElementView } from '../types';
3
- export declare function computeElementView<V extends ElementView>(view: V, index: ModelIndex): ComputeResult<V>;
4
- //# sourceMappingURL=compute-element-view.d.ts.map
2
+ import { type ElementView, type ComputedView } from '../types';
3
+ export declare function computeElementView(view: ElementView, index: ModelIndex): ComputedView;