@likec4/core 0.40.0 → 0.42.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 (124) hide show
  1. package/README.md +2 -6
  2. package/dist/cjs/colors/element.d.ts +68 -0
  3. package/dist/{esm/colors.js → cjs/colors/element.js} +9 -23
  4. package/dist/cjs/colors/index.d.ts +132 -0
  5. package/dist/cjs/colors/index.js +27 -0
  6. package/dist/cjs/colors/relationships.d.ts +57 -0
  7. package/dist/cjs/colors/relationships.js +76 -0
  8. package/dist/cjs/index.d.ts +0 -2
  9. package/dist/cjs/index.js +0 -22
  10. package/dist/cjs/types/computed-view.d.ts +10 -7
  11. package/dist/cjs/types/diagram.d.ts +14 -5
  12. package/dist/cjs/types/expression.d.ts +1 -1
  13. package/dist/cjs/types/relation.d.ts +12 -0
  14. package/dist/cjs/types/relation.js +12 -1
  15. package/dist/cjs/types/theme.d.ts +12 -14
  16. package/dist/cjs/types/view.d.ts +7 -4
  17. package/dist/cjs/types/view.js +1 -1
  18. package/dist/cjs/utils/fqn.d.ts +6 -1
  19. package/dist/cjs/utils/fqn.js +17 -4
  20. package/dist/cjs/utils/guards.d.ts +1 -0
  21. package/dist/cjs/utils/guards.js +7 -0
  22. package/dist/cjs/utils/index.d.ts +0 -1
  23. package/dist/cjs/utils/index.js +0 -11
  24. package/dist/esm/colors/element.d.ts +68 -0
  25. package/dist/{cjs/colors.js → esm/colors/element.js} +1 -33
  26. package/dist/esm/colors/index.d.ts +132 -0
  27. package/dist/esm/colors/index.js +9 -0
  28. package/dist/esm/colors/relationships.d.ts +57 -0
  29. package/dist/esm/colors/relationships.js +64 -0
  30. package/dist/esm/index.d.ts +0 -2
  31. package/dist/esm/index.js +1 -3
  32. package/dist/esm/types/computed-view.d.ts +10 -7
  33. package/dist/esm/types/diagram.d.ts +14 -5
  34. package/dist/esm/types/expression.d.ts +1 -1
  35. package/dist/esm/types/relation.d.ts +12 -0
  36. package/dist/esm/types/relation.js +3 -0
  37. package/dist/esm/types/theme.d.ts +12 -14
  38. package/dist/esm/types/view.d.ts +7 -4
  39. package/dist/esm/types/view.js +1 -1
  40. package/dist/esm/utils/fqn.d.ts +6 -1
  41. package/dist/esm/utils/fqn.js +16 -4
  42. package/dist/esm/utils/guards.d.ts +1 -0
  43. package/dist/esm/utils/guards.js +1 -0
  44. package/dist/esm/utils/index.d.ts +0 -1
  45. package/dist/esm/utils/index.js +0 -1
  46. package/dist/types/colors/element.d.ts +69 -0
  47. package/dist/types/colors/index.d.ts +133 -0
  48. package/dist/types/colors/relationships.d.ts +58 -0
  49. package/dist/types/errors/index.d.ts +46 -0
  50. package/dist/types/index.d.ts +7 -0
  51. package/dist/types/types/_common.d.ts +4 -0
  52. package/dist/types/types/computed-view.d.ts +45 -0
  53. package/dist/types/types/diagram.d.ts +42 -0
  54. package/dist/types/types/element.d.ts +30 -0
  55. package/dist/types/types/expression.d.ts +57 -0
  56. package/dist/types/types/index.d.ts +12 -0
  57. package/dist/types/types/model.d.ts +15 -0
  58. package/dist/types/types/opaque.d.ts +103 -0
  59. package/dist/types/types/relation.d.ts +23 -0
  60. package/dist/types/types/theme.d.ts +27 -0
  61. package/dist/types/types/view.d.ts +62 -0
  62. package/dist/types/utils/fqn.d.ts +34 -0
  63. package/dist/types/utils/guards.d.ts +5 -0
  64. package/dist/types/utils/index.d.ts +4 -0
  65. package/dist/types/utils/relations.d.ts +26 -0
  66. package/package.json +51 -54
  67. package/dist/cjs/colors.d.ts +0 -148
  68. package/dist/cjs/compute-view/EdgeBuilder.d.ts +0 -6
  69. package/dist/cjs/compute-view/EdgeBuilder.js +0 -37
  70. package/dist/cjs/compute-view/compute-ctx.d.ts +0 -20
  71. package/dist/cjs/compute-view/compute-ctx.js +0 -91
  72. package/dist/cjs/compute-view/compute-element-view.d.ts +0 -3
  73. package/dist/cjs/compute-view/compute-element-view.js +0 -100
  74. package/dist/cjs/compute-view/compute-predicates.d.ts +0 -16
  75. package/dist/cjs/compute-view/compute-predicates.js +0 -363
  76. package/dist/cjs/compute-view/compute.d.ts +0 -14
  77. package/dist/cjs/compute-view/compute.js +0 -46
  78. package/dist/cjs/compute-view/index.d.ts +0 -4
  79. package/dist/cjs/compute-view/index.js +0 -49
  80. package/dist/cjs/compute-view/resolve-extended-views.d.ts +0 -6
  81. package/dist/cjs/compute-view/resolve-extended-views.js +0 -53
  82. package/dist/cjs/compute-view/resolve-relative-paths.d.ts +0 -2
  83. package/dist/cjs/compute-view/resolve-relative-paths.js +0 -84
  84. package/dist/cjs/compute-view/utils/anyPossibleRelations.d.ts +0 -2
  85. package/dist/cjs/compute-view/utils/anyPossibleRelations.js +0 -18
  86. package/dist/cjs/compute-view/utils/applyViewRuleStyles.d.ts +0 -2
  87. package/dist/cjs/compute-view/utils/applyViewRuleStyles.js +0 -57
  88. package/dist/cjs/compute-view/utils/sortNodes.d.ts +0 -19
  89. package/dist/cjs/compute-view/utils/sortNodes.js +0 -47
  90. package/dist/cjs/model-index/ModelIndex.d.ts +0 -27
  91. package/dist/cjs/model-index/ModelIndex.js +0 -139
  92. package/dist/cjs/model-index/index.d.ts +0 -1
  93. package/dist/cjs/model-index/index.js +0 -13
  94. package/dist/cjs/utils/compute-node-levels.d.ts +0 -7
  95. package/dist/cjs/utils/compute-node-levels.js +0 -48
  96. package/dist/esm/colors.d.ts +0 -148
  97. package/dist/esm/compute-view/EdgeBuilder.d.ts +0 -6
  98. package/dist/esm/compute-view/EdgeBuilder.js +0 -30
  99. package/dist/esm/compute-view/compute-ctx.d.ts +0 -20
  100. package/dist/esm/compute-view/compute-ctx.js +0 -100
  101. package/dist/esm/compute-view/compute-element-view.d.ts +0 -3
  102. package/dist/esm/compute-view/compute-element-view.js +0 -98
  103. package/dist/esm/compute-view/compute-predicates.d.ts +0 -16
  104. package/dist/esm/compute-view/compute-predicates.js +0 -324
  105. package/dist/esm/compute-view/compute.d.ts +0 -14
  106. package/dist/esm/compute-view/compute.js +0 -36
  107. package/dist/esm/compute-view/index.d.ts +0 -4
  108. package/dist/esm/compute-view/index.js +0 -4
  109. package/dist/esm/compute-view/resolve-extended-views.d.ts +0 -6
  110. package/dist/esm/compute-view/resolve-extended-views.js +0 -41
  111. package/dist/esm/compute-view/resolve-relative-paths.d.ts +0 -2
  112. package/dist/esm/compute-view/resolve-relative-paths.js +0 -76
  113. package/dist/esm/compute-view/utils/anyPossibleRelations.d.ts +0 -2
  114. package/dist/esm/compute-view/utils/anyPossibleRelations.js +0 -12
  115. package/dist/esm/compute-view/utils/applyViewRuleStyles.d.ts +0 -2
  116. package/dist/esm/compute-view/utils/applyViewRuleStyles.js +0 -50
  117. package/dist/esm/compute-view/utils/sortNodes.d.ts +0 -19
  118. package/dist/esm/compute-view/utils/sortNodes.js +0 -37
  119. package/dist/esm/model-index/ModelIndex.d.ts +0 -27
  120. package/dist/esm/model-index/ModelIndex.js +0 -127
  121. package/dist/esm/model-index/index.d.ts +0 -1
  122. package/dist/esm/model-index/index.js +0 -1
  123. package/dist/esm/utils/compute-node-levels.d.ts +0 -7
  124. package/dist/esm/utils/compute-node-levels.js +0 -31
@@ -1,6 +0,0 @@
1
- import type { ComputedEdge, Fqn, Relation } from '../types';
2
- export declare class EdgeBuilder {
3
- private _relationsObj;
4
- add(source: Fqn, target: Fqn, relation: Relation): this;
5
- build(): ComputedEdge[];
6
- }
@@ -1,30 +0,0 @@
1
- import { keys, pluck } from "rambdax";
2
- import { commonAncestor, compareRelations } from "../utils/index.js";
3
- export class EdgeBuilder {
4
- _relationsObj = {};
5
- add(source, target, relation) {
6
- const bySource = this._relationsObj[source] ?? {};
7
- const relations = bySource[target] ?? [];
8
- relations.push(relation);
9
- bySource[target] = relations;
10
- this._relationsObj[source] = bySource;
11
- return this;
12
- }
13
- build() {
14
- return keys(this._relationsObj).flatMap((source) => {
15
- const targets = this._relationsObj[source] ?? {};
16
- return keys(targets).map((target) => {
17
- const relations = (targets[target] ?? []).sort(compareRelations);
18
- const label = relations.find((r) => r.title !== "")?.title ?? null;
19
- return {
20
- id: `${source}:${target}`,
21
- parent: commonAncestor(source, target),
22
- source,
23
- target,
24
- label,
25
- relations: pluck("id", relations)
26
- };
27
- });
28
- }).sort(compareRelations).reverse();
29
- }
30
- }
@@ -1,20 +0,0 @@
1
- import type { ModelIndex } from '../model-index';
2
- import type { Fqn, Element, Relation, ViewRuleExpression, ElementView } from '../types';
3
- export type ComputeCtxPatch = {
4
- elements?: Element[];
5
- relations?: Relation[];
6
- implicits?: Element[];
7
- };
8
- export declare class ComputeCtx {
9
- index: ModelIndex;
10
- root: Fqn | null;
11
- elements: ReadonlySet<Element>;
12
- relations: ReadonlySet<Relation>;
13
- implicits: ReadonlySet<Element>;
14
- readonly allElements: ReadonlySet<Element>;
15
- constructor(index: ModelIndex, root: Fqn | null, elements?: ReadonlySet<Element>, relations?: ReadonlySet<Relation>, implicits?: ReadonlySet<Element>);
16
- include({ elements, relations, implicits }: ComputeCtxPatch): ComputeCtx;
17
- exclude({ elements, relations, implicits }: ComputeCtxPatch): ComputeCtx;
18
- processViewRules(viewRules: ViewRuleExpression[]): ComputeCtx;
19
- static create(view: ElementView, index: ModelIndex): ComputeCtx;
20
- }
@@ -1,100 +0,0 @@
1
- import { difference } from "rambdax";
2
- import { Expr, isStrictElementView, isViewRuleExpression } from "../types/index.js";
3
- import {
4
- excludeElementKindOrTag,
5
- excludeElementRef,
6
- excludeInOutExpr,
7
- excludeIncomingExpr,
8
- excludeOutgoingExpr,
9
- excludeRelationExpr,
10
- excludeWildcardRef,
11
- includeElementKindOrTag,
12
- includeElementRef,
13
- includeInOutExpr,
14
- includeIncomingExpr,
15
- includeOutgoingExpr,
16
- includeRelationExpr,
17
- includeWildcardRef
18
- } from "./compute-predicates.js";
19
- import { nonexhaustive } from "../errors/index.js";
20
- export class ComputeCtx {
21
- constructor(index, root, elements = /* @__PURE__ */ new Set(), relations = /* @__PURE__ */ new Set(), implicits = /* @__PURE__ */ new Set()) {
22
- this.index = index;
23
- this.root = root;
24
- this.elements = elements;
25
- this.relations = relations;
26
- this.implicits = implicits;
27
- this.allElements = /* @__PURE__ */ new Set([...this.elements, ...this.implicits]);
28
- }
29
- allElements;
30
- include({ elements, relations, implicits }) {
31
- return new ComputeCtx(
32
- this.index,
33
- this.root,
34
- elements ? /* @__PURE__ */ new Set([...this.elements, ...elements]) : this.elements,
35
- relations ? /* @__PURE__ */ new Set([...this.relations, ...relations]) : this.relations,
36
- implicits ? /* @__PURE__ */ new Set([...this.implicits, ...implicits]) : this.implicits
37
- );
38
- }
39
- exclude({ elements, relations, implicits }) {
40
- let newImplicits = implicits ? new Set(difference([...this.implicits], implicits)) : this.implicits;
41
- if (elements) {
42
- newImplicits = new Set(difference([...newImplicits], elements));
43
- }
44
- return new ComputeCtx(
45
- this.index,
46
- this.root,
47
- elements ? new Set(difference([...this.elements], elements)) : this.elements,
48
- relations ? new Set(difference([...this.relations], relations)) : this.relations,
49
- newImplicits
50
- );
51
- }
52
- processViewRules(viewRules) {
53
- let ctx = this;
54
- for (const { isInclude, exprs } of viewRules) {
55
- for (const expr of exprs) {
56
- if (Expr.isElementKindExpr(expr) || Expr.isElementTagExpr(expr)) {
57
- ctx = isInclude ? includeElementKindOrTag(ctx, expr) : excludeElementKindOrTag(ctx, expr);
58
- continue;
59
- }
60
- if (Expr.isElementRef(expr)) {
61
- ctx = isInclude ? includeElementRef(ctx, expr) : excludeElementRef(ctx, expr);
62
- continue;
63
- }
64
- if (Expr.isWildcard(expr)) {
65
- ctx = isInclude ? includeWildcardRef(ctx, expr) : excludeWildcardRef(ctx, expr);
66
- continue;
67
- }
68
- if (Expr.isIncoming(expr)) {
69
- ctx = isInclude ? includeIncomingExpr(ctx, expr) : excludeIncomingExpr(ctx, expr);
70
- continue;
71
- }
72
- if (Expr.isOutgoing(expr)) {
73
- ctx = isInclude ? includeOutgoingExpr(ctx, expr) : excludeOutgoingExpr(ctx, expr);
74
- continue;
75
- }
76
- if (Expr.isInOut(expr)) {
77
- ctx = isInclude ? includeInOutExpr(ctx, expr) : excludeInOutExpr(ctx, expr);
78
- continue;
79
- }
80
- if (Expr.isRelation(expr)) {
81
- ctx = isInclude ? includeRelationExpr(ctx, expr) : excludeRelationExpr(ctx, expr);
82
- continue;
83
- }
84
- nonexhaustive(expr);
85
- }
86
- }
87
- return ctx;
88
- }
89
- static create(view, index) {
90
- const rootElement = isStrictElementView(view) ? view.viewOf : null;
91
- let ctx = new ComputeCtx(index, rootElement);
92
- const rulesInclude = view.rules.filter(isViewRuleExpression);
93
- if (rootElement && rulesInclude.length == 0) {
94
- ctx = ctx.include({
95
- elements: [index.find(rootElement)]
96
- });
97
- }
98
- return ctx.processViewRules(rulesInclude);
99
- }
100
- }
@@ -1,3 +0,0 @@
1
- import type { ModelIndex } from '../model-index';
2
- import { type ComputedView, type ElementView } from '../types';
3
- export declare function computeElementView(view: ElementView, index: ModelIndex): ComputedView;
@@ -1,98 +0,0 @@
1
- import { allPass, find } from "remeda";
2
- import { nonNullable } from "../errors/index.js";
3
- import {
4
- DefaultElementShape,
5
- DefaultThemeColor,
6
- isViewRuleAutoLayout,
7
- isViewRuleStyle
8
- } from "../types/index.js";
9
- import { compareByFqnHierarchically, isAncestor, isSameHierarchy, parentFqn } from "../utils/index.js";
10
- import { EdgeBuilder } from "./EdgeBuilder.js";
11
- import { ComputeCtx } from "./compute-ctx.js";
12
- import { applyViewRuleStyles } from "./utils/applyViewRuleStyles.js";
13
- import { sortNodes } from "./utils/sortNodes.js";
14
- function reduceToMap(elementsIterator) {
15
- return Array.from(elementsIterator).sort(compareByFqnHierarchically).reduce((map, { id, color, shape, ...el }) => {
16
- let parent = parentFqn(id);
17
- let level = 0;
18
- while (parent) {
19
- if (map.has(parent)) {
20
- break;
21
- }
22
- parent = parentFqn(parent);
23
- }
24
- if (parent) {
25
- const parentNd = nonNullable(map.get(parent));
26
- parentNd.children.push(id);
27
- level = parentNd.level + 1;
28
- }
29
- const node = {
30
- ...el,
31
- id,
32
- parent,
33
- level,
34
- color: color ?? DefaultThemeColor,
35
- shape: shape ?? DefaultElementShape,
36
- children: [],
37
- inEdges: [],
38
- outEdges: []
39
- };
40
- map.set(id, node);
41
- return map;
42
- }, /* @__PURE__ */ new Map());
43
- }
44
- const keepOriginalSortFromView = (_nodes, ctx) => {
45
- const nodes = [...ctx.allElements].flatMap((e) => _nodes.get(e.id) || []);
46
- for (const node of nodes) {
47
- node.children = nodes.flatMap((n) => n.parent === node.id ? n.id : []);
48
- }
49
- return nodes;
50
- };
51
- export function computeElementView(view, index) {
52
- const ctx = ComputeCtx.create(view, index);
53
- const leafsFirst = [...ctx.allElements].sort((a, b) => -1 * compareByFqnHierarchically(a, b));
54
- const elementsWithRelations = /* @__PURE__ */ new Set();
55
- const edgeBuilder = new EdgeBuilder();
56
- const anscestorOf = (id) => (e) => e.id === id || isAncestor(e.id, id);
57
- const sortedRelations = [...ctx.relations];
58
- for (const rel of sortedRelations) {
59
- const source = find(leafsFirst, anscestorOf(rel.source));
60
- if (!source) {
61
- continue;
62
- }
63
- const target = find(
64
- leafsFirst,
65
- allPass([anscestorOf(rel.target), (e) => !isSameHierarchy(e, source)])
66
- );
67
- if (!target) {
68
- continue;
69
- }
70
- elementsWithRelations.add(source);
71
- elementsWithRelations.add(target);
72
- edgeBuilder.add(source.id, target.id, rel);
73
- }
74
- const nodesMap = reduceToMap(/* @__PURE__ */ new Set([...ctx.elements, ...elementsWithRelations]));
75
- const edges = edgeBuilder.build().map((edge) => {
76
- while (edge.parent) {
77
- if (nodesMap.has(edge.parent)) {
78
- break;
79
- }
80
- edge.parent = parentFqn(edge.parent);
81
- }
82
- nonNullable(nodesMap.get(edge.source)).outEdges.push(edge.id);
83
- nonNullable(nodesMap.get(edge.target)).inEdges.push(edge.id);
84
- return edge;
85
- });
86
- const nodes = applyViewRuleStyles(
87
- view.rules.filter(isViewRuleStyle),
88
- sortNodes(keepOriginalSortFromView(nodesMap, ctx), edges)
89
- // map(e => nodesMap.get(e.id)!, Array.from(elements))
90
- );
91
- const autoLayoutRule = view.rules.find(isViewRuleAutoLayout);
92
- return {
93
- ...view,
94
- autoLayout: autoLayoutRule?.autoLayout ?? "TB",
95
- nodes,
96
- edges
97
- };
98
- }
@@ -1,16 +0,0 @@
1
- import { Expr } from '../types';
2
- import { ComputeCtx } from './compute-ctx';
3
- export declare const includeElementRef: (ctx: ComputeCtx, expr: Expr.ElementRefExpr) => ComputeCtx;
4
- export declare const excludeElementRef: (ctx: ComputeCtx, expr: Expr.ElementRefExpr) => ComputeCtx;
5
- export declare const includeElementKindOrTag: (ctx: ComputeCtx, expr: Expr.ElementKindExpr | Expr.ElementTagExpr) => ComputeCtx;
6
- export declare const excludeElementKindOrTag: (ctx: ComputeCtx, expr: Expr.ElementKindExpr | Expr.ElementTagExpr) => ComputeCtx;
7
- export declare const includeWildcardRef: (ctx: ComputeCtx, _expr: Expr.WildcardExpr) => ComputeCtx;
8
- export declare const excludeWildcardRef: (ctx: ComputeCtx, _expr: Expr.WildcardExpr) => ComputeCtx;
9
- export declare const includeIncomingExpr: (ctx: ComputeCtx, expr: Expr.IncomingExpr) => ComputeCtx;
10
- export declare const excludeIncomingExpr: (ctx: ComputeCtx, expr: Expr.IncomingExpr) => ComputeCtx;
11
- export declare const includeOutgoingExpr: (ctx: ComputeCtx, expr: Expr.OutgoingExpr) => ComputeCtx;
12
- export declare const excludeOutgoingExpr: (ctx: ComputeCtx, expr: Expr.OutgoingExpr) => ComputeCtx;
13
- export declare const includeInOutExpr: (ctx: ComputeCtx, expr: Expr.InOutExpr) => ComputeCtx;
14
- export declare const excludeInOutExpr: (ctx: ComputeCtx, expr: Expr.InOutExpr) => ComputeCtx;
15
- export declare const includeRelationExpr: (ctx: ComputeCtx, expr: Expr.RelationExpr) => ComputeCtx;
16
- export declare const excludeRelationExpr: (ctx: ComputeCtx, expr: Expr.RelationExpr) => ComputeCtx;
@@ -1,324 +0,0 @@
1
- import { anyPass, both, either, isNil, uniq } from "rambdax";
2
- import { Expr } from "../types/index.js";
3
- import { Relations, commonAncestor, isAncestor, isSameHierarchy } from "../utils/index.js";
4
- import { ComputeCtx } from "./compute-ctx.js";
5
- const { isAnyInOut, isBetween, isIncoming, isInside, isOutgoing, isAnyBetween } = Relations;
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(isInside(expr.element), 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(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,14 +0,0 @@
1
- import type { BaseError } from '../errors';
2
- import type { ModelIndex } from '../model-index';
3
- import { type ComputedView, type ElementView } from '../types';
4
- type ComputeViewResult = {
5
- isSuccess: true;
6
- view: ComputedView;
7
- } | {
8
- isSuccess: false;
9
- error: BaseError;
10
- view: undefined;
11
- };
12
- export declare function computeView(view: ElementView, index: ModelIndex): ComputeViewResult;
13
- export declare function assignNavigateTo<R extends Iterable<ComputedView>>(views: R): R;
14
- export {};
@@ -1,36 +0,0 @@
1
- import { find } from "rambdax";
2
- import { normalizeError } from "../errors/index.js";
3
- import { computeElementView } from "./compute-element-view.js";
4
- export function computeView(view, index) {
5
- try {
6
- return {
7
- isSuccess: true,
8
- view: computeElementView(view, index)
9
- };
10
- } catch (e) {
11
- return {
12
- isSuccess: false,
13
- error: normalizeError(e),
14
- view: void 0
15
- };
16
- }
17
- }
18
- export function assignNavigateTo(views) {
19
- const allElementViews = /* @__PURE__ */ new Map();
20
- for (const v of views) {
21
- if (v.viewOf && !v.extends) {
22
- const viewsOf = allElementViews.get(v.viewOf) ?? [];
23
- viewsOf.push(v.id);
24
- allElementViews.set(v.viewOf, viewsOf);
25
- }
26
- }
27
- for (const { id, nodes } of views) {
28
- for (const node of nodes) {
29
- const navigateTo = find((v) => v !== id, allElementViews.get(node.id) ?? []);
30
- if (navigateTo) {
31
- node.navigateTo = navigateTo;
32
- }
33
- }
34
- }
35
- return views;
36
- }
@@ -1,4 +0,0 @@
1
- export * from './compute';
2
- export * from './resolve-extended-views';
3
- export * from './resolve-relative-paths';
4
- export * from './EdgeBuilder';
@@ -1,4 +0,0 @@
1
- export * from "./compute.js";
2
- export * from "./resolve-extended-views.js";
3
- export * from "./resolve-relative-paths.js";
4
- export * from "./EdgeBuilder.js";
@@ -1,6 +0,0 @@
1
- import { type ElementView } from '../types';
2
- /**
3
- * Resolve rules of extended views
4
- * (Removes invalid views)
5
- */
6
- export declare function resolveRulesExtendedViews<V extends Record<any, ElementView>>(unresolvedViews: V): V;