@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
@@ -0,0 +1,324 @@
1
+ import { anyPass, both, either, isNil, uniq } from "rambdax";
2
+ import * as Expr from "../types/expression.mjs";
3
+ import { Relations, commonAncestor, isAncestor, isSameHierarchy } from "../utils/index.mjs";
4
+ import { isAnyInOut, isBetween, isIncoming, isInside, isOutgoing } from "../utils/relations.mjs";
5
+ import { ComputeCtx } from "./compute-ctx.mjs";
6
+ export const includeElementRef = (ctx, expr) => {
7
+ const elements = expr.isDescedants ? ctx.index.children(expr.element) : [ctx.index.find(expr.element)];
8
+ const filters = [];
9
+ if (expr.isDescedants) {
10
+ elements.forEach((child) => {
11
+ filters.push(both(Relations.isInside(expr.element), Relations.isAnyInOut(child.id)));
12
+ });
13
+ }
14
+ const ctxElements = uniq([...ctx.elements, ...ctx.implicits]);
15
+ const excludeImplicits = [];
16
+ for (const el of elements) {
17
+ if (ctx.root && ctx.root !== el.id && !isAncestor(el.id, ctx.root)) {
18
+ excludeImplicits.push(...[...ctx.implicits].filter((impl) => isAncestor(el.id, impl.id)));
19
+ }
20
+ for (const ctxEl of ctxElements) {
21
+ if (!isSameHierarchy(el, ctxEl)) {
22
+ filters.push(Relations.isAnyBetween(el.id, ctxEl.id));
23
+ }
24
+ }
25
+ }
26
+ const relations = filters.length ? ctx.index.filterRelations(anyPass(filters)) : [];
27
+ if (excludeImplicits.length == 0) {
28
+ return ctx.include({ elements, relations });
29
+ }
30
+ return ctx.include({ elements, relations }).exclude({ implicits: excludeImplicits });
31
+ };
32
+ export const excludeElementRef = (ctx, expr) => {
33
+ const elements = expr.isDescedants ? ctx.index.children(expr.element) : [ctx.index.find(expr.element)];
34
+ const elementsIds = elements.map((e) => e.id);
35
+ const relations = [...ctx.relations].filter(
36
+ (r) => elementsIds.includes(r.source) || elementsIds.includes(r.target)
37
+ );
38
+ return ctx.exclude({ elements, relations });
39
+ };
40
+ const asElementPredicate = (expr) => {
41
+ if (expr.isEqual) {
42
+ if (Expr.isElementKindExpr(expr)) {
43
+ return (e) => e.kind === expr.elementKind;
44
+ } else {
45
+ return ({ tags }) => !!tags && tags.includes(expr.elementTag);
46
+ }
47
+ } else {
48
+ if (Expr.isElementKindExpr(expr)) {
49
+ return (e) => e.kind !== expr.elementKind;
50
+ } else {
51
+ return ({ tags }) => isNil(tags) || tags.length === 0 || !tags.includes(expr.elementTag);
52
+ }
53
+ }
54
+ };
55
+ export const includeElementKindOrTag = (ctx, expr) => {
56
+ const elements = ctx.index.elements.filter(asElementPredicate(expr));
57
+ return elements.reduce(
58
+ (accCtx, el) => includeElementRef(accCtx, {
59
+ element: el.id,
60
+ isDescedants: false
61
+ }),
62
+ ctx
63
+ );
64
+ };
65
+ export const excludeElementKindOrTag = (ctx, expr) => {
66
+ const predicate = asElementPredicate(expr);
67
+ const elements = [...ctx.elements].filter(predicate);
68
+ const implicits = [...ctx.implicits].filter(predicate);
69
+ return ctx.exclude({ elements, implicits });
70
+ };
71
+ export const includeWildcardRef = (ctx, _expr) => {
72
+ const { root } = ctx;
73
+ if (root) {
74
+ const elements = [ctx.index.find(root), ...ctx.index.children(root)];
75
+ const allImplicits = [
76
+ ...ctx.index.siblings(root),
77
+ ...ctx.index.ancestors(root).flatMap((a) => [...ctx.index.siblings(a.id)])
78
+ ];
79
+ const inOut = ctx.index.filterRelations(isAnyInOut(root));
80
+ const implicits = [];
81
+ for (const implicit of allImplicits) {
82
+ if (inOut.some(isAnyInOut(implicit.id))) {
83
+ implicits.push(implicit);
84
+ }
85
+ }
86
+ return ctx.include({
87
+ elements,
88
+ relations: [...ctx.index.filterRelations(isInside(root)), ...inOut],
89
+ implicits
90
+ });
91
+ } else {
92
+ const elements = ctx.index.rootElements();
93
+ if (elements.length <= 1) {
94
+ return new ComputeCtx(ctx.index, ctx.root, new Set(elements));
95
+ }
96
+ const relations = ctx.index.filterRelations(
97
+ (rel) => isNil(commonAncestor(rel.source, rel.target))
98
+ );
99
+ return ctx.include({
100
+ elements,
101
+ relations
102
+ });
103
+ }
104
+ };
105
+ export const excludeWildcardRef = (ctx, _expr) => {
106
+ const { root } = ctx;
107
+ if (root) {
108
+ const relations = [...ctx.relations].filter(either(isInside(root), isAnyInOut(root)));
109
+ return ctx.exclude({
110
+ elements: [...ctx.elements].filter((e) => e.id === root || isAncestor(root, e.id)),
111
+ relations,
112
+ implicits: [...ctx.implicits].filter((e) => relations.some(isAnyInOut(e.id)))
113
+ });
114
+ } else {
115
+ return new ComputeCtx(ctx.index, ctx.root);
116
+ }
117
+ };
118
+ const resolveElements = (ctx, expr) => {
119
+ if (Expr.isWildcard(expr)) {
120
+ if (ctx.root) {
121
+ return [ctx.index.find(ctx.root)];
122
+ } else {
123
+ return ctx.index.rootElements();
124
+ }
125
+ }
126
+ if (Expr.isElementKindExpr(expr)) {
127
+ return ctx.index.elements.filter((el) => {
128
+ if (expr.isEqual) {
129
+ return el.kind === expr.elementKind;
130
+ }
131
+ return el.kind !== expr.elementKind;
132
+ });
133
+ }
134
+ if (Expr.isElementTagExpr(expr)) {
135
+ return ctx.index.elements.filter((el) => {
136
+ const tags = el.tags;
137
+ if (expr.isEqual) {
138
+ return !!tags && tags.includes(expr.elementTag);
139
+ }
140
+ return isNil(tags) || tags.length === 0 || !tags.includes(expr.elementTag);
141
+ });
142
+ }
143
+ if (expr.isDescedants) {
144
+ return ctx.index.children(expr.element);
145
+ } else {
146
+ return [ctx.index.find(expr.element)];
147
+ }
148
+ };
149
+ export const includeIncomingExpr = (ctx, expr) => {
150
+ if (Expr.isWildcard(expr.incoming) && !ctx.root) {
151
+ return ctx;
152
+ }
153
+ const elements = resolveElements(ctx, expr.incoming);
154
+ if (elements.length === 0) {
155
+ return ctx;
156
+ }
157
+ let allrelations = ctx.index.relations;
158
+ if (Expr.isElementRef(expr.incoming)) {
159
+ allrelations = allrelations.filter(isIncoming(expr.incoming.element));
160
+ }
161
+ const implicits = [];
162
+ const relations = [];
163
+ for (const el of elements) {
164
+ const elRelations = allrelations.filter(isIncoming(el.id));
165
+ if (elRelations.length > 0) {
166
+ relations.push(...elRelations);
167
+ implicits.push(el);
168
+ }
169
+ }
170
+ return ctx.include({
171
+ relations,
172
+ implicits
173
+ });
174
+ };
175
+ export const excludeIncomingExpr = (ctx, expr) => {
176
+ if (Expr.isWildcard(expr.incoming) && !ctx.root) {
177
+ return ctx;
178
+ }
179
+ const elements = resolveElements(ctx, expr.incoming);
180
+ if (elements.length === 0) {
181
+ return ctx;
182
+ }
183
+ const isIncomings = anyPass(elements.map((el) => isIncoming(el.id)));
184
+ const excluded = [...ctx.relations].filter(isIncomings);
185
+ if (excluded.length > 0) {
186
+ return ctx.exclude({
187
+ relations: excluded
188
+ });
189
+ }
190
+ return ctx;
191
+ };
192
+ export const includeOutgoingExpr = (ctx, expr) => {
193
+ if (Expr.isWildcard(expr.outgoing) && !ctx.root) {
194
+ return ctx;
195
+ }
196
+ const elements = resolveElements(ctx, expr.outgoing);
197
+ if (elements.length === 0) {
198
+ return ctx;
199
+ }
200
+ let allrelations = ctx.index.relations;
201
+ if (Expr.isElementRef(expr.outgoing)) {
202
+ allrelations = allrelations.filter(isOutgoing(expr.outgoing.element));
203
+ }
204
+ const implicits = [];
205
+ const relations = [];
206
+ for (const el of elements) {
207
+ const elRelations = allrelations.filter(isOutgoing(el.id));
208
+ if (elRelations.length > 0) {
209
+ relations.push(...elRelations);
210
+ implicits.push(el);
211
+ }
212
+ }
213
+ return ctx.include({
214
+ relations,
215
+ implicits
216
+ });
217
+ };
218
+ export const excludeOutgoingExpr = (ctx, expr) => {
219
+ if (Expr.isWildcard(expr.outgoing) && !ctx.root) {
220
+ return ctx;
221
+ }
222
+ const elements = resolveElements(ctx, expr.outgoing);
223
+ if (elements.length === 0) {
224
+ return ctx;
225
+ }
226
+ const isOutgoings = anyPass(elements.map((el) => isOutgoing(el.id)));
227
+ const excluded = [...ctx.relations].filter(isOutgoings);
228
+ if (excluded.length > 0) {
229
+ return ctx.exclude({
230
+ relations: excluded
231
+ });
232
+ }
233
+ return ctx;
234
+ };
235
+ export const includeInOutExpr = (ctx, expr) => {
236
+ if (Expr.isWildcard(expr.inout) && !ctx.root) {
237
+ return ctx;
238
+ }
239
+ const targets = resolveElements(ctx, expr.inout);
240
+ if (targets.length === 0) {
241
+ return ctx;
242
+ }
243
+ let allrelations = ctx.index.relations;
244
+ if (Expr.isElementRef(expr.inout)) {
245
+ allrelations = allrelations.filter(isAnyInOut(expr.inout.element));
246
+ }
247
+ const implicits = [];
248
+ const relations = [];
249
+ for (const target of targets) {
250
+ const foundRelations = allrelations.filter(isAnyInOut(target.id));
251
+ if (foundRelations.length > 0) {
252
+ relations.push(...foundRelations);
253
+ implicits.push(target);
254
+ }
255
+ }
256
+ return ctx.include({
257
+ relations,
258
+ implicits
259
+ });
260
+ };
261
+ export const excludeInOutExpr = (ctx, expr) => {
262
+ if (Expr.isWildcard(expr.inout) && !ctx.root) {
263
+ return ctx;
264
+ }
265
+ const targets = resolveElements(ctx, expr.inout);
266
+ if (targets.length === 0) {
267
+ return ctx;
268
+ }
269
+ const excluded = [...ctx.relations].filter(anyPass(targets.map((t) => isAnyInOut(t.id))));
270
+ if (excluded.length > 0) {
271
+ return ctx.exclude({
272
+ relations: excluded
273
+ });
274
+ }
275
+ return ctx;
276
+ };
277
+ export const includeRelationExpr = (ctx, expr) => {
278
+ const sources = resolveElements(ctx, expr.source);
279
+ const targets = resolveElements(ctx, expr.target);
280
+ if (sources.length === 0 || targets.length === 0) {
281
+ return ctx;
282
+ }
283
+ const implicits = [];
284
+ const relations = [];
285
+ for (const source of sources) {
286
+ for (const target of targets) {
287
+ if (isSameHierarchy(source, target)) {
288
+ continue;
289
+ }
290
+ const foundRelations = ctx.index.filterRelations(isBetween(source.id, target.id));
291
+ if (foundRelations.length > 0) {
292
+ relations.push(...foundRelations);
293
+ implicits.push(source, target);
294
+ }
295
+ }
296
+ }
297
+ return ctx.include({
298
+ relations,
299
+ implicits
300
+ });
301
+ };
302
+ export const excludeRelationExpr = (ctx, expr) => {
303
+ const sources = resolveElements(ctx, expr.source);
304
+ const targets = resolveElements(ctx, expr.target);
305
+ const filters = [];
306
+ for (const source of sources) {
307
+ for (const target of targets) {
308
+ if (isSameHierarchy(source, target)) {
309
+ continue;
310
+ }
311
+ filters.push(isBetween(source.id, target.id));
312
+ }
313
+ }
314
+ if (filters.length == 0) {
315
+ return ctx;
316
+ }
317
+ const excluded = [...ctx.relations].filter(anyPass(filters));
318
+ if (excluded.length == 0) {
319
+ return ctx;
320
+ }
321
+ return ctx.exclude({
322
+ relations: excluded
323
+ });
324
+ };
@@ -1,17 +1,16 @@
1
1
  import { ModelIndex } from '../model-index';
2
- import type { ComputeResult, Element, ElementView, Fqn, Relation, RelationID, ViewID } from '../types';
3
- export declare function computeView<V extends ElementView>(view: V, index: ModelIndex): ComputeResult<V> | null;
4
- type InputModel<V extends ElementView> = {
2
+ import type { ComputedView, Element, ElementView, Fqn, Relation, RelationID, ViewID } from '../types';
3
+ export declare function computeView<V extends ElementView>(view: V, index: ModelIndex): ComputedView | null;
4
+ type InputModel = {
5
5
  elements: Record<Fqn, Element>;
6
6
  relations: Record<RelationID, Relation>;
7
- views: V[];
7
+ views: ElementView[];
8
8
  };
9
- type OutputModel<V extends ElementView> = {
9
+ type OutputModel = {
10
10
  elements: Record<Fqn, Element>;
11
11
  relations: Record<RelationID, Relation>;
12
- views: Record<ViewID, ComputeResult<V>>;
12
+ views: Record<ViewID, ComputedView>;
13
13
  };
14
- export declare function computeViews<V extends ElementView>(model: InputModel<V>): OutputModel<V>;
15
- export declare function assignNavigateTo<V extends ElementView, R extends ComputeResult<V>[]>(views: R): R;
14
+ export declare function computeViews(model: InputModel): OutputModel;
15
+ export declare function assignNavigateTo<R extends Iterable<ComputedView>>(views: R): R;
16
16
  export {};
17
- //# sourceMappingURL=compute.d.ts.map
@@ -1,43 +1,53 @@
1
- import { compact, find, map, mapToObj } from 'remeda';
2
- import { ModelIndex } from '../model-index';
3
- import { computeElementView } from './compute-element-view';
4
- export function computeView(view, index) {
5
- try {
6
- return computeElementView(view, index);
7
- }
8
- catch (e) {
9
- console.error(e);
10
- return null;
11
- }
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.assignNavigateTo = assignNavigateTo;
7
+ exports.computeView = computeView;
8
+ exports.computeViews = computeViews;
9
+ var _remeda = require("remeda");
10
+ var _modelIndex = require("../model-index");
11
+ var _computeElementView = require("./compute-element-view");
12
+ function computeView(view, index) {
13
+ try {
14
+ return (0, _computeElementView.computeElementView)(view, index);
15
+ } catch (e) {
16
+ console.error(e);
17
+ return null;
18
+ }
12
19
  }
13
- export function computeViews(model) {
14
- const index = ModelIndex.from(model);
15
- const computedViews = compact(map(model.views, view => computeView(view, index)));
16
- return {
17
- elements: model.elements,
18
- relations: model.relations,
19
- views: mapToObj(computedViews, view => [view.id, view])
20
- };
20
+ function computeViews(model) {
21
+ const index = _modelIndex.ModelIndex.from(model);
22
+ const computedViews = (0, _remeda.compact)((0, _remeda.map)(model.views, view => computeView(view, index)));
23
+ return {
24
+ elements: model.elements,
25
+ relations: model.relations,
26
+ views: (0, _remeda.mapToObj)(computedViews, view => [view.id, view])
27
+ };
21
28
  }
22
- export function assignNavigateTo(views) {
23
- const allElementViews = new Map();
24
- for (const { id, viewOf } of views) {
25
- if (viewOf) {
26
- const viewsOf = allElementViews.get(viewOf) ?? [];
27
- viewsOf.push(id);
28
- allElementViews.set(viewOf, viewsOf);
29
- }
29
+ function assignNavigateTo(views) {
30
+ const allElementViews = /* @__PURE__ */new Map();
31
+ for (const {
32
+ id,
33
+ viewOf
34
+ } of views) {
35
+ if (viewOf) {
36
+ const viewsOf = allElementViews.get(viewOf) ?? [];
37
+ viewsOf.push(id);
38
+ allElementViews.set(viewOf, viewsOf);
30
39
  }
31
- // set default navigateTo
32
- for (const { id, nodes } of views) {
33
- for (const node of nodes) {
34
- // find first element view that is not the current one
35
- const navigateTo = find(allElementViews.get(node.id) ?? [], v => v !== id);
36
- if (navigateTo) {
37
- node.navigateTo = navigateTo;
38
- }
39
- }
40
+ }
41
+ for (const {
42
+ id,
43
+ nodes
44
+ } of views) {
45
+ for (const node of nodes) {
46
+ const navigateTo = (0, _remeda.find)(allElementViews.get(node.id) ?? [], v => v !== id);
47
+ if (navigateTo) {
48
+ node.navigateTo = navigateTo;
49
+ }
40
50
  }
41
- return views;
42
- }
43
- //# sourceMappingURL=compute.js.map
51
+ }
52
+ return views;
53
+ }
@@ -0,0 +1,39 @@
1
+ import { compact, find, map, mapToObj } from "remeda";
2
+ import { ModelIndex } from "../model-index/index.mjs";
3
+ import { computeElementView } from "./compute-element-view.mjs";
4
+ export function computeView(view, index) {
5
+ try {
6
+ return computeElementView(view, index);
7
+ } catch (e) {
8
+ console.error(e);
9
+ return null;
10
+ }
11
+ }
12
+ export function computeViews(model) {
13
+ const index = ModelIndex.from(model);
14
+ const computedViews = compact(map(model.views, (view) => computeView(view, index)));
15
+ return {
16
+ elements: model.elements,
17
+ relations: model.relations,
18
+ views: mapToObj(computedViews, (view) => [view.id, view])
19
+ };
20
+ }
21
+ export function assignNavigateTo(views) {
22
+ const allElementViews = /* @__PURE__ */ new Map();
23
+ for (const { id, viewOf } of views) {
24
+ if (viewOf) {
25
+ const viewsOf = allElementViews.get(viewOf) ?? [];
26
+ viewsOf.push(id);
27
+ allElementViews.set(viewOf, viewsOf);
28
+ }
29
+ }
30
+ for (const { id, nodes } of views) {
31
+ for (const node of nodes) {
32
+ const navigateTo = find(allElementViews.get(node.id) ?? [], (v) => v !== id);
33
+ if (navigateTo) {
34
+ node.navigateTo = navigateTo;
35
+ }
36
+ }
37
+ }
38
+ return views;
39
+ }
@@ -1,3 +1,3 @@
1
1
  export { computeView, computeViews, assignNavigateTo } from './compute';
2
+ export type * from '../types/view';
2
3
  export type * from '../types/computed-view';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1,2 +1,24 @@
1
- export { computeView, computeViews, assignNavigateTo } from './compute';
2
- //# sourceMappingURL=index.js.map
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "assignNavigateTo", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _compute.assignNavigateTo;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "computeView", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _compute.computeView;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "computeViews", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _compute.computeViews;
22
+ }
23
+ });
24
+ var _compute = require("./compute");
@@ -0,0 +1 @@
1
+ export { computeView, computeViews, assignNavigateTo } from "./compute.mjs";
@@ -1,3 +1,2 @@
1
1
  import type { Element } from '../../types';
2
2
  export declare function anyPossibleRelations(elements: Element[]): Generator<[source: Element, target: Element]>;
3
- //# sourceMappingURL=anyPossibleRelations.d.ts.map
@@ -1,13 +1,18 @@
1
- import { prop, uniqBy } from 'rambdax';
2
- import { compareByFqnHierarchically, isAncestor } from '../../utils/fqn';
3
- export function* anyPossibleRelations(elements) {
4
- const uniqElements = uniqBy(prop('id'), elements).sort(compareByFqnHierarchically).reverse();
5
- for (const source of uniqElements) {
6
- for (const target of uniqElements) {
7
- if (source !== target && !isAncestor(source, target) && !isAncestor(target, source)) {
8
- yield [source, target];
9
- }
10
- }
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.anyPossibleRelations = anyPossibleRelations;
7
+ var _rambdax = require("rambdax");
8
+ var _fqn = require("../../utils/fqn");
9
+ function* anyPossibleRelations(elements) {
10
+ const uniqElements = (0, _rambdax.uniqBy)((0, _rambdax.prop)("id"), elements).sort(_fqn.compareByFqnHierarchically).reverse();
11
+ for (const source of uniqElements) {
12
+ for (const target of uniqElements) {
13
+ if (source !== target && !(0, _fqn.isAncestor)(source, target) && !(0, _fqn.isAncestor)(target, source)) {
14
+ yield [source, target];
15
+ }
11
16
  }
12
- }
13
- //# sourceMappingURL=anyPossibleRelations.js.map
17
+ }
18
+ }
@@ -0,0 +1,12 @@
1
+ import { prop, uniqBy } from "rambdax";
2
+ import { compareByFqnHierarchically, isAncestor } from "../../utils/fqn.mjs";
3
+ export function* anyPossibleRelations(elements) {
4
+ const uniqElements = uniqBy(prop("id"), elements).sort(compareByFqnHierarchically).reverse();
5
+ for (const source of uniqElements) {
6
+ for (const target of uniqElements) {
7
+ if (source !== target && !isAncestor(source, target) && !isAncestor(target, source)) {
8
+ yield [source, target];
9
+ }
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,3 @@
1
+ import { type ComputedNode } from '../../types';
2
+ import { type ViewRuleStyle } from '../../types/view';
3
+ export declare function applyViewRuleStyles(rules: ViewRuleStyle[], _nodes: ComputedNode[]): ComputedNode[];
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.applyViewRuleStyles = applyViewRuleStyles;
7
+ var _rambdax = require("rambdax");
8
+ var _remeda = require("remeda");
9
+ var Expr = _interopRequireWildcard(require("../../types/expression"));
10
+ var _errors = require("../../errors");
11
+ 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); }
12
+ 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; }
13
+ function applyViewRuleStyles(rules, _nodes) {
14
+ if (rules.length === 0) {
15
+ return _nodes;
16
+ }
17
+ const nodes = (0, _rambdax.clone)(_nodes);
18
+ for (const rule of rules) {
19
+ const predicates = [];
20
+ if (!rule.style.color && !rule.style.shape) {
21
+ continue;
22
+ }
23
+ for (const target of rule.targets) {
24
+ if (Expr.isWildcard(target)) {
25
+ predicates.push(() => true);
26
+ break;
27
+ }
28
+ if (Expr.isElementKindExpr(target)) {
29
+ predicates.push(target.isEqual ? n => n.kind === target.elementKind : n => n.kind !== target.elementKind);
30
+ continue;
31
+ }
32
+ if (Expr.isElementTagExpr(target)) {
33
+ predicates.push(target.isEqual ? ({
34
+ tags
35
+ }) => !!tags && tags.includes(target.elementTag) : ({
36
+ tags
37
+ }) => (0, _rambdax.isNil)(tags) || !tags.includes(target.elementTag));
38
+ continue;
39
+ }
40
+ if (Expr.isElementRef(target)) {
41
+ const {
42
+ element,
43
+ isDescedants
44
+ } = target;
45
+ predicates.push(isDescedants ? n => n.id.startsWith(element + ".") : n => n.id === element);
46
+ continue;
47
+ }
48
+ (0, _errors.nonexhaustive)(target);
49
+ }
50
+ (0, _rambdax.filter)((0, _rambdax.anyPass)(predicates), nodes).forEach(n => {
51
+ n.shape = rule.style.shape ?? n.shape;
52
+ n.color = rule.style.color ?? n.color;
53
+ if (_remeda.isDefined.strict(rule.style.icon)) {
54
+ n.icon = rule.style.icon;
55
+ }
56
+ });
57
+ }
58
+ return nodes;
59
+ }