@likec4/core 1.47.0 → 1.49.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 (152) hide show
  1. package/LICENSE +1 -1
  2. package/dist/THIRD-PARTY-LICENSES.md +1012 -0
  3. package/dist/_chunks/Builder.view-element.mjs +2 -0
  4. package/dist/_chunks/LikeC4Model.d.mts +1283 -0
  5. package/dist/_chunks/RichText.mjs +1 -0
  6. package/dist/_chunks/_types.d.mts +777 -0
  7. package/dist/_chunks/_types2.d.mts +36 -0
  8. package/dist/_chunks/assignTagColors.mjs +1 -0
  9. package/dist/_chunks/calcDriftsFromSnapshot.mjs +1 -0
  10. package/dist/_chunks/guards.d.mts +2026 -0
  11. package/dist/_chunks/guards.mjs +4 -0
  12. package/dist/_chunks/index.d.mts +288 -0
  13. package/dist/_chunks/libs/@mantine/colors-generator.mjs +15 -0
  14. package/dist/_chunks/libs/@radix-ui/colors.mjs +1 -0
  15. package/dist/_chunks/libs/@ungap/structured-clone.mjs +1 -0
  16. package/dist/_chunks/libs/bail.mjs +1 -0
  17. package/dist/_chunks/libs/ccount.mjs +1 -0
  18. package/dist/_chunks/libs/character-entities-html4.mjs +1 -0
  19. package/dist/_chunks/libs/character-entities-legacy.mjs +1 -0
  20. package/dist/_chunks/libs/character-entities.mjs +2 -0
  21. package/dist/_chunks/libs/comma-separated-tokens.mjs +1 -0
  22. package/dist/_chunks/libs/decode-named-character-reference.mjs +1 -0
  23. package/dist/_chunks/libs/defu.mjs +1 -0
  24. package/dist/_chunks/libs/devlop.mjs +1 -0
  25. package/dist/_chunks/libs/escape-string-regexp.mjs +1 -0
  26. package/dist/_chunks/libs/extend.mjs +1 -0
  27. package/dist/_chunks/libs/graphology-dag.mjs +1 -0
  28. package/dist/_chunks/libs/graphology.mjs +1 -0
  29. package/dist/_chunks/libs/hast-util-sanitize.mjs +1 -0
  30. package/dist/_chunks/libs/hast-util-to-html.mjs +9 -0
  31. package/dist/_chunks/libs/is-plain-obj.mjs +1 -0
  32. package/dist/_chunks/libs/longest-streak.mjs +1 -0
  33. package/dist/_chunks/libs/markdown-table.mjs +2 -0
  34. package/dist/_chunks/libs/mdast-util-find-and-replace.mjs +1 -0
  35. package/dist/_chunks/libs/mdast-util-from-markdown.mjs +3 -0
  36. package/dist/_chunks/libs/mdast-util-gfm.mjs +15 -0
  37. package/dist/_chunks/libs/mdast-util-to-hast.mjs +11 -0
  38. package/dist/_chunks/libs/micromark-extension-gfm.mjs +1 -0
  39. package/dist/_chunks/libs/mnemonist.d.mts +164 -0
  40. package/dist/_chunks/libs/mnemonist.mjs +1 -0
  41. package/dist/_chunks/libs/natural-compare-lite.mjs +9 -0
  42. package/dist/_chunks/libs/ohash.mjs +1 -0
  43. package/dist/_chunks/libs/rehype-sanitize.mjs +1 -0
  44. package/dist/_chunks/libs/rehype-stringify.mjs +1 -0
  45. package/dist/_chunks/libs/remark-gfm.mjs +1 -0
  46. package/dist/_chunks/libs/remark-github-blockquote-alert.mjs +3 -0
  47. package/dist/_chunks/libs/remark-parse.mjs +1 -0
  48. package/dist/_chunks/libs/remark-rehype.mjs +1 -0
  49. package/dist/_chunks/libs/remeda.mjs +1 -0
  50. package/dist/_chunks/libs/trough.mjs +1 -0
  51. package/dist/_chunks/libs/unified.mjs +1 -0
  52. package/dist/_chunks/rolldown-runtime.mjs +1 -0
  53. package/dist/_chunks/theme.d.mts +148 -0
  54. package/dist/_chunks/to-text.d.mts +404 -0
  55. package/dist/_chunks/to-text.mjs +1 -0
  56. package/dist/_chunks/vector.d.mts +198 -0
  57. package/dist/_chunks/vector.mjs +1 -0
  58. package/dist/builder/index.d.mts +5 -775
  59. package/dist/builder/index.mjs +1 -1053
  60. package/dist/compute-view/index.d.mts +156 -56
  61. package/dist/compute-view/index.mjs +2 -229
  62. package/dist/geometry/index.d.mts +2 -109
  63. package/dist/geometry/index.mjs +1 -328
  64. package/dist/index.d.mts +14 -20
  65. package/dist/index.mjs +1 -18
  66. package/dist/model/index.d.mts +5 -57
  67. package/dist/model/index.mjs +1 -4
  68. package/dist/styles/index.d.mts +3 -117
  69. package/dist/styles/index.mjs +1 -63
  70. package/dist/types/index.d.mts +3 -47
  71. package/dist/types/index.mjs +1 -17
  72. package/dist/utils/graphology/index.d.mts +2 -1864
  73. package/dist/utils/graphology/index.mjs +1 -1
  74. package/dist/utils/index.d.mts +4 -124
  75. package/dist/utils/index.mjs +1 -44
  76. package/package.json +20 -24
  77. package/compute-view/relationships/package.json +0 -4
  78. package/dist/compute-view/relationships-view/index.d.mts +0 -51
  79. package/dist/compute-view/relationships-view/index.mjs +0 -185
  80. package/dist/model/connection/deployment/index.d.mts +0 -15
  81. package/dist/model/connection/deployment/index.mjs +0 -2
  82. package/dist/model/connection/index.d.mts +0 -75
  83. package/dist/model/connection/index.mjs +0 -3
  84. package/dist/model/connection/model/index.d.mts +0 -15
  85. package/dist/model/connection/model/index.mjs +0 -2
  86. package/dist/shared/core.3ZhnKAlZ.mjs +0 -106
  87. package/dist/shared/core.78IWAHAE.mjs +0 -332
  88. package/dist/shared/core.B85MJLTf.mjs +0 -5
  89. package/dist/shared/core.BFd1lU9R.mjs +0 -29
  90. package/dist/shared/core.BKlholso.mjs +0 -3
  91. package/dist/shared/core.BNN-3vPH.mjs +0 -1255
  92. package/dist/shared/core.BPGOjone.d.mts +0 -46
  93. package/dist/shared/core.BP_QHEXs.mjs +0 -785
  94. package/dist/shared/core.BbE4y-yl.mjs +0 -177
  95. package/dist/shared/core.Bdy3hhTc.mjs +0 -28382
  96. package/dist/shared/core.BfCKSW-g.d.mts +0 -1266
  97. package/dist/shared/core.BhNcrwzK.mjs +0 -7
  98. package/dist/shared/core.BkVA6gjl.mjs +0 -5
  99. package/dist/shared/core.BoYfZOBm.mjs +0 -3
  100. package/dist/shared/core.BsSXS-_R.mjs +0 -7
  101. package/dist/shared/core.C3JowhaZ.mjs +0 -32
  102. package/dist/shared/core.C4x8aaWa.mjs +0 -27
  103. package/dist/shared/core.CAgYpDtM.d.mts +0 -98
  104. package/dist/shared/core.CHf8VEa3.mjs +0 -1206
  105. package/dist/shared/core.CLSZtnFh.mjs +0 -69
  106. package/dist/shared/core.C_3y3eqV.d.mts +0 -139
  107. package/dist/shared/core.CbT8JVYL.mjs +0 -5
  108. package/dist/shared/core.CdNCAwq7.mjs +0 -176
  109. package/dist/shared/core.CmGY9blO.mjs +0 -6717
  110. package/dist/shared/core.CmPXpJ8l.mjs +0 -21
  111. package/dist/shared/core.Coi_LOUZ.mjs +0 -7
  112. package/dist/shared/core.CqAJJpK_.mjs +0 -3
  113. package/dist/shared/core.CywrQs86.d.mts +0 -31
  114. package/dist/shared/core.D00YbOhQ.d.mts +0 -300
  115. package/dist/shared/core.D0WZutNd.mjs +0 -94
  116. package/dist/shared/core.D4npX2q8.mjs +0 -18
  117. package/dist/shared/core.DB0Ue5Wx.d.mts +0 -70
  118. package/dist/shared/core.DC5IAaDT.d.mts +0 -334
  119. package/dist/shared/core.DE9qzhn8.d.mts +0 -83
  120. package/dist/shared/core.DGcIbsj4.mjs +0 -3946
  121. package/dist/shared/core.DH7TXqXf.mjs +0 -136
  122. package/dist/shared/core.DKhRkHRN.d.mts +0 -41
  123. package/dist/shared/core.DRJma0Ol.mjs +0 -22
  124. package/dist/shared/core.DU5SRqNF.mjs +0 -2209
  125. package/dist/shared/core.DXhDWKFZ.d.mts +0 -3
  126. package/dist/shared/core.DbfO90vF.mjs +0 -434
  127. package/dist/shared/core.DcS-0zys.mjs +0 -10
  128. package/dist/shared/core.Dh119QSP.mjs +0 -4995
  129. package/dist/shared/core.DjcWextK.mjs +0 -1371
  130. package/dist/shared/core.Dojz4bvg.d.mts +0 -504
  131. package/dist/shared/core.FZ305VYd.mjs +0 -21
  132. package/dist/shared/core.OtRNdMxy.d.mts +0 -352
  133. package/dist/shared/core.RfnaEmgA.mjs +0 -7
  134. package/dist/shared/core.btEq3i3f.mjs +0 -300
  135. package/dist/shared/core.oSV6SRfk.mjs +0 -13
  136. package/dist/shared/core.om36dXXW.mjs +0 -41
  137. package/dist/shared/core.osFs8tU7.d.mts +0 -466
  138. package/dist/shared/core.q10OP9oJ.mjs +0 -5
  139. package/dist/shared/core.tpvDGvdC.d.mts +0 -87
  140. package/dist/shared/core.uFk_o9X6.mjs +0 -13
  141. package/dist/types/_aux.d.mts +0 -4
  142. package/dist/types/_aux.mjs +0 -8
  143. package/dist/types/expression-model.d.mts +0 -190
  144. package/dist/types/expression-model.mjs +0 -109
  145. package/dist/types/expression.d.mts +0 -6
  146. package/dist/types/expression.mjs +0 -113
  147. package/dist/types/fqnRef.d.mts +0 -60
  148. package/dist/types/fqnRef.mjs +0 -45
  149. package/dist/types/scalar.d.mts +0 -2
  150. package/dist/types/scalar.mjs +0 -4
  151. package/dist/utils/iterable/index.d.mts +0 -132
  152. package/dist/utils/iterable/index.mjs +0 -62
@@ -1,79 +1,179 @@
1
- import { A as Any, t as toComputed, d as AnyParsed, m as _stage } from '../shared/core.D00YbOhQ.mjs';
2
- import { f as LikeC4Model } from '../shared/core.BfCKSW-g.mjs';
3
- import { P as ParsedLikeC4ModelData, C as ComputedLikeC4ModelData, p as ParsedView, r as ComputedView, J as DiagramNode, K as DiagramEdge } from '../shared/core.osFs8tU7.mjs';
4
- import { H as BaseViewProperties, O as ComputedNode, P as ComputedEdge, B as ViewAutoLayout } from '../shared/core.Dojz4bvg.mjs';
5
- import { P as ProjectId } from '../shared/core.C_3y3eqV.mjs';
6
- import { B as BBox } from '../shared/core.BPGOjone.mjs';
7
- import { N as NonEmptyArray } from '../shared/core.DB0Ue5Wx.mjs';
8
- import 'type-fest';
9
- import '../shared/core.CAgYpDtM.mjs';
10
- import '../shared/core.DC5IAaDT.mjs';
11
- import '../types/fqnRef.mjs';
12
- import '../shared/core.CywrQs86.mjs';
13
- import '../types/expression-model.mjs';
1
+ import { Br as ElementId, Ji as _stage, On as ModelExpression, Pr as AnyParsed, S as ComputedView, Yi as _type, _ as ComputedLikeC4ModelData, at as ComputedNode, b as ParsedLikeC4ModelData, ci as ViewId, cn as AnyIncludePredicate, fn as BaseViewProperties, hn as ViewAutoLayout, ia as NonEmptyArray, ii as Unknown, jr as Any, pi as toComputed, rt as ComputedEdge, sn as AnyExcludePredicate, w as ParsedView } from "../_chunks/guards.mjs";
2
+ import "../types/index.mjs";
3
+ import "../_chunks/theme.mjs";
4
+ import { C as ElementModel, T as RelationshipModel, n as LikeC4Model } from "../_chunks/LikeC4Model.mjs";
5
+ import { B as ViewPredicate } from "../_chunks/_types.mjs";
6
+ import "../_chunks/index.mjs";
7
+ import "../model/index.mjs";
8
+ import { a as LayoutedProjectNode, i as LayoutedProjectEdge, n as ComputedProjectNode, o as LayoutedProjectsView, r as ComputedProjectsView, t as ComputedProjectEdge } from "../_chunks/_types2.mjs";
14
9
 
10
+ //#region src/compute-view/compute-view.d.ts
15
11
  type ComputeViewResult<V> = {
16
- isSuccess: true;
17
- error?: undefined;
18
- view: V;
12
+ isSuccess: true;
13
+ error?: undefined;
14
+ view: V;
19
15
  } | {
20
- isSuccess: false;
21
- error: Error;
22
- view: undefined;
16
+ isSuccess: false;
17
+ error: Error;
18
+ view: undefined;
23
19
  };
24
20
  declare function unsafeComputeView<A extends Any>(viewsource: ParsedView<A>, likec4model: LikeC4Model<any>): ComputedView<A>;
25
21
  declare function computeView<A extends Any>(viewsource: ParsedView<A>, likec4model: LikeC4Model<A>): ComputeViewResult<ComputedView<A>>;
26
22
  declare function computeParsedModelData<A extends AnyParsed, B extends toComputed<A> = toComputed<A>>(parsed: ParsedLikeC4ModelData<A>): ComputedLikeC4ModelData<B>;
27
23
  declare function computeLikeC4Model<A extends Any, B extends toComputed<A> = toComputed<A>>(parsed: ParsedLikeC4ModelData<A>): LikeC4Model<B>;
28
-
24
+ //#endregion
25
+ //#region src/compute-view/utils/resolve-extended-views.d.ts
29
26
  /**
30
27
  * Resolve rules of extended views
31
28
  * (Removes invalid views)
32
29
  */
33
30
  declare function resolveRulesExtendedViews<A extends Any, V extends Record<any, ParsedView<A>>>(unresolvedViews: V): V;
34
-
31
+ //#endregion
32
+ //#region src/compute-view/utils/with-readable-edges.d.ts
35
33
  /**
36
34
  * Convert hashed edge ids to human-readable
37
35
  * Mostly for testing purposes
38
36
  */
39
- declare function withReadableEdges<V extends ComputedView<any>>({ edges, nodes, ...view }: V, separator?: string): V & {
40
- nodeIds: string[];
41
- edgeIds: string[];
37
+ declare function withReadableEdges<V extends ComputedView<any>>({
38
+ edges,
39
+ nodes,
40
+ ...view
41
+ }: V, separator?: string): V & {
42
+ nodeIds: string[];
43
+ edgeIds: string[];
42
44
  };
43
- declare function viewsWithReadableEdges<A extends Any>({ views, ...model }: ComputedLikeC4ModelData<A>): ComputedLikeC4ModelData<A>;
44
-
45
- interface ComputedProjectNode extends ComputedNode {
46
- readonly projectId: ProjectId;
47
- }
48
- interface ComputedProjectEdge extends ComputedEdge {
49
- readonly projectId: ProjectId;
50
- }
51
- interface LayoutedProjectNode extends DiagramNode {
52
- readonly projectId: ProjectId;
53
- }
54
- interface LayoutedProjectEdge extends DiagramEdge {
55
- readonly projectId: ProjectId;
56
- }
45
+ declare function viewsWithReadableEdges<A extends Any>({
46
+ views,
47
+ ...model
48
+ }: ComputedLikeC4ModelData<A>): ComputedLikeC4ModelData<A>;
49
+ //#endregion
50
+ //#region src/compute-view/projects-view/compute.d.ts
57
51
  /**
58
- * An overview of projects and their relationships, presented as a graph with nodes and edges.
59
- * Even though it has same structure as other likec4 views, it is not mixed with them, as it represents a different kind.
52
+ * Computes an overview of projects and their relationships
60
53
  */
61
- interface ComputedProjectsView extends BaseViewProperties<any> {
62
- readonly [_stage]: 'computed';
63
- readonly nodes: ReadonlyArray<ComputedProjectNode>;
64
- readonly edges: ReadonlyArray<ComputedProjectEdge>;
65
- readonly autoLayout: ViewAutoLayout;
66
- }
67
- interface LayoutedProjectsView extends BaseViewProperties<any> {
68
- readonly [_stage]: 'layouted';
69
- readonly nodes: ReadonlyArray<LayoutedProjectNode>;
70
- readonly edges: ReadonlyArray<LayoutedProjectEdge>;
71
- readonly bounds: BBox;
54
+ declare function computeProjectsView(likec4models: NonEmptyArray<LikeC4Model>): ComputedProjectsView;
55
+ //#endregion
56
+ //#region src/compute-view/relationships-view/_types.d.ts
57
+ type RelationshipsViewData<M extends Any = Unknown> = {
58
+ incomers: ReadonlySet<ElementModel<M>>;
59
+ incoming: ReadonlySet<RelationshipModel<M>>;
60
+ subjects: ReadonlySet<ElementModel<M>>;
61
+ outgoing: ReadonlySet<RelationshipModel<M>>;
62
+ outgoers: ReadonlySet<ElementModel<M>>;
63
+ };
64
+ //#endregion
65
+ //#region src/compute-view/relationships-view/compute.d.ts
66
+ declare function computeRelationshipsView<M extends Any>(subjectId: ElementId<M>, likec4model: LikeC4Model<M>, scopeViewId: ViewId<M> | null, scope?: 'global' | 'view'): RelationshipsViewData<M>;
67
+ //#endregion
68
+ //#region src/compute-view/relationships-view/utils.d.ts
69
+ /**
70
+ * Builds a tree structure from a flat list of elements.
71
+ * @param elements - An iterable of ElementModel instances.
72
+ * @returns An object containing the sorted elements, a lookup by ID, root elements, parent and children accessors, and a flatten method.
73
+ * @example
74
+ * ```ts
75
+ * const elements = [
76
+ * { id: 'A' },
77
+ * { id: 'A.B' },
78
+ * { id: 'A.B.C' },
79
+ * { id: 'A.B.D' },
80
+ * { id: 'E' },
81
+ * ]
82
+ *
83
+ * const tree = treeFromElements(elements)
84
+ *
85
+ * tree.sorted.map(e => e.id) // ['A', 'A.B', 'A.B.C', 'A.B.D', 'E']
86
+ *
87
+ * tree.byId('A.B').id // 'A.B'
88
+ *
89
+ * [...tree.root].map(e => e.id) // ['A', 'E']
90
+ *
91
+ * tree.parent(tree.byId('A.B.C'))?.id // 'A.B'
92
+ *
93
+ * tree.children(tree.byId('A')).map(e => e.id) // ['A.B']
94
+ */
95
+ declare function treeFromElements<M extends Any>(elements: Iterable<ElementModel<M>>): Readonly<{
96
+ /**
97
+ * Elements sorted in a way that parents go before their descendants.
98
+ */
99
+ sorted: ReadonlyArray<ElementModel<M>>;
100
+ /**
101
+ * Get element by its id (FQN)
102
+ */
103
+ byId(id: ElementId<M>): ElementModel<M>;
104
+ /**
105
+ * Root elements (i.e. those without parents)
106
+ */
107
+ root: ReadonlySet<ElementModel<M>>;
108
+ /**
109
+ * Get parent element or null if it's a root
110
+ */
111
+ parent(el: ElementId<M> | ElementModel<M>): ElementModel<M> | null;
112
+ /**
113
+ * Get child elements (i.e. direct descendants)
114
+ */
115
+ children(el: ElementId<M> | ElementModel<M>): ReadonlyArray<ElementModel<M>>;
116
+ /**
117
+ * Flattens the tree structure by removing redundant hierarchy levels.
118
+ * @example
119
+ * A
120
+ * └── B
121
+ * ├── C
122
+ * │ └── D
123
+ * │ └── E
124
+ * └── F
125
+ * └── G
126
+ * becomes
127
+ * A
128
+ * ├── C
129
+ * │ └── E
130
+ * └── F
131
+ * └── G
132
+ */
133
+ flatten(): ReadonlySet<ElementModel<M>>;
134
+ }>;
135
+ //#endregion
136
+ //#region src/compute-view/adhoc-view/compute.d.ts
137
+ interface AdhocViewIncludePredicate<A extends Any> extends AnyIncludePredicate<ModelExpression<A>> {}
138
+ interface AdhocViewExcludePredicate<A extends Any> extends AnyExcludePredicate<ModelExpression<A>> {}
139
+ type AdhocViewPredicate<A extends Any = Any> = AdhocViewIncludePredicate<A> | AdhocViewExcludePredicate<A>;
140
+ interface ComputedAdhocView extends BaseViewProperties<Any> {
141
+ readonly [_type]: 'adhoc';
142
+ readonly [_stage]: 'computed';
143
+ readonly nodes: ReadonlyArray<ComputedNode>;
144
+ readonly edges: ReadonlyArray<ComputedEdge>;
145
+ readonly autoLayout: ViewAutoLayout;
72
146
  }
73
-
74
147
  /**
75
- * Computes an overview of projects and their relationships
148
+ * Computes an adhoc view based on the given predicates.
149
+ * Adhoc views are not defined in the model, but computed on demand.
150
+ * Available for logical model only.
151
+ *
152
+ * @param predicates accepts the same predicates as element view.
153
+ * @param likec4model The LikeC4 model to compute view.
154
+ * @returns The computed adhoc view.
76
155
  */
77
- declare function computeProjectsView(likec4models: NonEmptyArray<LikeC4Model>): ComputedProjectsView;
78
-
79
- export { type ComputeViewResult, type ComputedProjectEdge, type ComputedProjectNode, type ComputedProjectsView, type LayoutedProjectEdge, type LayoutedProjectNode, type LayoutedProjectsView, computeLikeC4Model, computeParsedModelData, computeProjectsView, computeView, resolveRulesExtendedViews, unsafeComputeView, viewsWithReadableEdges, withReadableEdges };
156
+ declare function computeAdhocView<A extends Any>(likec4model: LikeC4Model<A>, predicates: AdhocViewPredicate<NoInfer<A>>[]): ComputedAdhocView;
157
+ //#endregion
158
+ //#region src/compute-view/adhoc-view/builder.d.ts
159
+ /**
160
+ * Allows you to define type-safe adhoc views using types from the model.
161
+ */
162
+ declare class AdhocView<A extends Any> {
163
+ #private;
164
+ private readonly model;
165
+ /**
166
+ * Creates a new adhoc view builder.
167
+ */
168
+ static use<A extends Any>(model: LikeC4Model<A>): AdhocView<A>;
169
+ private constructor();
170
+ /**
171
+ * Used to cache the type of the predicates.
172
+ */
173
+ readonly Expr: ViewPredicate.AllExpression<ViewPredicate.ElementExpr<A['ElementId']>>;
174
+ include(...predicates: this['Expr'][]): this;
175
+ exclude(...predicates: this['Expr'][]): this;
176
+ compute(): ComputedAdhocView;
177
+ }
178
+ //#endregion
179
+ export { AdhocView, type AdhocViewExcludePredicate, type AdhocViewIncludePredicate, type AdhocViewPredicate, type ComputeViewResult, type ComputedAdhocView, ComputedProjectEdge, ComputedProjectNode, ComputedProjectsView, LayoutedProjectEdge, LayoutedProjectNode, LayoutedProjectsView, type RelationshipsViewData, computeAdhocView, computeLikeC4Model, computeParsedModelData, computeProjectsView, computeRelationshipsView, computeView, resolveRulesExtendedViews, treeFromElements, unsafeComputeView, viewsWithReadableEdges, withReadableEdges };
@@ -1,229 +1,2 @@
1
- import { w as willCreateCycle, t as topologicalSortExports, a as t$4, n as n$1, b as t$9, l as linkNodesWithEdges, c as topologicalSort } from '../shared/core.Dh119QSP.mjs';
2
- export { d as computeLikeC4Model, e as computeParsedModelData, f as computeView, u as unsafeComputeView } from '../shared/core.Dh119QSP.mjs';
3
- import { n } from '../shared/core.BhNcrwzK.mjs';
4
- import { t as t$2 } from '../shared/core.DU5SRqNF.mjs';
5
- import { r as isExtendsElementView, p as isElementView, _ as _stage } from '../shared/core.DH7TXqXf.mjs';
6
- import { G as Graph } from '../shared/core.CmGY9blO.mjs';
7
- import { c as isNonEmptyArray } from '../shared/core.CdNCAwq7.mjs';
8
- import { t as t$5 } from '../shared/core.CbT8JVYL.mjs';
9
- import { t as t$3, b as t$8 } from '../shared/core.DjcWextK.mjs';
10
- import { t as t$1, a as t$7 } from '../shared/core.BsSXS-_R.mjs';
11
- import { t as t$6, e as e$1 } from '../shared/core.Coi_LOUZ.mjs';
12
- import { e } from '../shared/core.BP_QHEXs.mjs';
13
- import { D as DefaultMap } from '../shared/core.BbE4y-yl.mjs';
14
- import { a as nonNullable, i as invariant } from '../shared/core.D4npX2q8.mjs';
15
- import { s as stringHash } from '../shared/core.oSV6SRfk.mjs';
16
- import { preferSummary } from '../types/_aux.mjs';
17
- import { a as GlobalFqn, P as ProjectId } from '../shared/core.D0WZutNd.mjs';
18
-
19
- function t(...t){return t$1(Object.keys,t)}
20
-
21
- function resolveRulesExtendedViews(unresolvedViews) {
22
- const g = new Graph({
23
- type: "directed"
24
- });
25
- const extendedViews = [];
26
- for (const view of t$2(unresolvedViews)) {
27
- g.addNode(view.id, { view });
28
- if (isExtendsElementView(view)) {
29
- extendedViews.push(view);
30
- }
31
- }
32
- if (extendedViews.length === 0) {
33
- return unresolvedViews;
34
- }
35
- for (const view of extendedViews) {
36
- if (!g.hasNode(view.extends)) {
37
- console.warn(`View "${view.id}" extends from "${view.extends}" which does not exist`);
38
- continue;
39
- }
40
- if (willCreateCycle(g, view.id, view.extends)) {
41
- console.warn(`View "${view.id}" extends from "${view.extends}" which creates a cycle`);
42
- continue;
43
- }
44
- g.addDirectedEdge(view.id, view.extends);
45
- }
46
- const sorted = topologicalSortExports.topologicalSort(g).reverse();
47
- return sorted.reduce((acc, id) => {
48
- const view = g.getNodeAttribute(id, "view");
49
- if (!isExtendsElementView(view)) {
50
- acc[view.id] = view;
51
- return acc;
52
- }
53
- const extendsFrom = acc[view.extends];
54
- if (!extendsFrom || !isElementView(extendsFrom)) {
55
- return acc;
56
- }
57
- const tags = n([
58
- ...extendsFrom.tags ?? [],
59
- ...view.tags ?? []
60
- ]);
61
- const links = [
62
- ...extendsFrom.links ?? [],
63
- ...view.links ?? []
64
- ];
65
- acc[view.id] = {
66
- ...extendsFrom,
67
- ...view,
68
- title: view.title ?? extendsFrom.title ?? null,
69
- description: view.description ?? extendsFrom.description ?? null,
70
- tags,
71
- links: isNonEmptyArray(links) ? links : null,
72
- rules: [...extendsFrom.rules, ...view.rules]
73
- };
74
- return acc;
75
- }, {});
76
- }
77
-
78
- function withReadableEdges({ edges, nodes, ...view }, separator = ":") {
79
- const edgeids = t$4(edges, (e) => [e.id, `${e.source}${separator}${e.target}`]);
80
- return {
81
- ...view,
82
- edges: edges.map((e) => ({
83
- ...e,
84
- id: edgeids[e.id]
85
- })),
86
- nodes: nodes.map((n) => ({
87
- ...n,
88
- inEdges: t$5(n.inEdges, (e) => edgeids[e]),
89
- outEdges: t$5(n.outEdges, (e) => edgeids[e])
90
- })),
91
- nodeIds: nodes.map((n) => n.id),
92
- edgeIds: edges.map((e) => edgeids[e.id])
93
- };
94
- }
95
- function viewsWithReadableEdges({ views, ...model }) {
96
- return {
97
- ...model,
98
- views: t$3(views, (v) => n$1(withReadableEdges(v), ["nodeIds", "edgeIds"]))
99
- };
100
- }
101
-
102
- const keysCount = (object) => t(object).length;
103
- const nodeId = (projectId) => stringHash(projectId);
104
- function computeProjectsView(likec4models) {
105
- const nodesMap = buildNodesForEachModel(likec4models);
106
- const key = (from, to) => `${from}->${to}`;
107
- const relationships = new DefaultMap((key2) => {
108
- const [from, to] = key2.split("->");
109
- return {
110
- from,
111
- to,
112
- relationships: /* @__PURE__ */ new Set()
113
- };
114
- });
115
- const relationshipsFromTo = (from, to) => relationships.get(key(from, to)).relationships;
116
- const processImportedElement = (model, importedElement) => {
117
- const projectId = importedElement.projectId;
118
- invariant(projectId !== model.projectId, "Imported element must have a different project id");
119
- const incoming = relationshipsFromTo(model.projectId, projectId);
120
- for (const rel of importedElement.incoming("direct")) {
121
- if (rel.source.projectId === model.projectId) {
122
- incoming.add(rel);
123
- }
124
- }
125
- const outgoing = relationshipsFromTo(projectId, model.projectId);
126
- for (const rel of importedElement.outgoing("direct")) {
127
- if (rel.target.projectId === model.projectId) {
128
- outgoing.add(rel);
129
- }
130
- }
131
- };
132
- for (const model of likec4models) {
133
- if (e(model.$data.imports)) {
134
- continue;
135
- }
136
- for (const [projectId, imported] of t$6(model.$data.imports)) {
137
- for (const importedElement of imported) {
138
- const fqn = GlobalFqn(projectId, importedElement.id);
139
- processImportedElement(
140
- model,
141
- nonNullable(
142
- model.findElement(fqn),
143
- `Element ${importedElement.id} from project ${projectId} not found in model ${model.projectId}`
144
- )
145
- );
146
- }
147
- }
148
- }
149
- const edges = Array.from(relationships.entries()).filter(([_, { relationships: relationships2 }]) => relationships2.size > 0).map(([key2, { from, to, relationships: relationshipsSet }]) => {
150
- const relationships2 = [...relationshipsSet];
151
- invariant(t$7(relationships2, 1), "Relationships set must have at least one relationship");
152
- const edge = {
153
- id: stringHash(key2),
154
- source: nodeId(from),
155
- target: nodeId(to),
156
- projectId: from,
157
- relations: t$5(relationships2, e$1("id")),
158
- label: null,
159
- color: "gray",
160
- parent: null,
161
- line: "solid",
162
- tags: n(t$8(relationships2, e$1("tags")))
163
- };
164
- const onlyOne = t$9(relationships2);
165
- if (onlyOne) {
166
- edge.label = onlyOne.title;
167
- edge.description = preferSummary(onlyOne.$relationship) ?? null;
168
- edge.technology = onlyOne.technology;
169
- edge.color = onlyOne.color;
170
- edge.line = onlyOne.line;
171
- if (onlyOne.kind) {
172
- edge.kind = onlyOne.kind;
173
- }
174
- if (onlyOne.$relationship.navigateTo) {
175
- edge.navigateTo = onlyOne.$relationship.navigateTo;
176
- }
177
- }
178
- return edge;
179
- });
180
- linkNodesWithEdges(nodesMap, edges);
181
- const sorted = topologicalSort({
182
- nodes: nodesMap,
183
- edges
184
- });
185
- return {
186
- id: "projects-view",
187
- [_stage]: "computed",
188
- title: "Projects",
189
- description: {
190
- txt: "Overview of all projects and their relationships"
191
- },
192
- autoLayout: {
193
- direction: "TB"
194
- },
195
- ...sorted
196
- };
197
- }
198
- function buildNodesForEachModel(likec4models) {
199
- const nodesMap = /* @__PURE__ */ new Map();
200
- for (const model of likec4models) {
201
- const projectId = ProjectId(model.projectId);
202
- const node = {
203
- id: nodeId(projectId),
204
- kind: "@project",
205
- parent: null,
206
- projectId,
207
- title: model.project.title ?? model.project.id,
208
- description: {
209
- txt: [
210
- `Elements: ${keysCount(model.$data.elements)}`,
211
- `Relationships: ${keysCount(model.$data.relations)}`,
212
- `Views: ${keysCount(model.$data.views)}`
213
- ].join("\n")
214
- },
215
- shape: "rectangle",
216
- children: [],
217
- inEdges: [],
218
- outEdges: [],
219
- color: "primary",
220
- level: 0,
221
- style: {},
222
- tags: []
223
- };
224
- nodesMap.set(node.id, node);
225
- }
226
- return nodesMap;
227
- }
228
-
229
- export { computeProjectsView, resolveRulesExtendedViews, viewsWithReadableEdges, withReadableEdges };
1
+ import{r as __toESM}from"../_chunks/rolldown-runtime.mjs";import"../_chunks/libs/defu.mjs";import{$ as r,C as t$3,D as t$4,K as t$7,L as e,Q as t$6,S as n$1,T as t$2,X as t$5,Y as n$2,b as e$2,d as t$10,et as t$9,i as n,m as e$1,r as t,w as t$1,y as t$8}from"../_chunks/libs/remeda.mjs";import{Q as GlobalFqn,_ as isExtendsElementView,_t as _type,bt as preferSummary,g as isElementView,gt as _stage,ot as ViewId,rt as ProjectId}from"../_chunks/RichText.mjs";import{$ as nonNullable,D as ifilter,I as isAncestor,K as isNonEmptyArray,L as isDescendantOf,Q as invariant,U as sortParentsFirst,_ as toArray,r as stringHash,v as toSet,x as imap}from"../_chunks/to-text.mjs";import{n as require_topological_sort,t as require_will_create_cycle}from"../_chunks/libs/graphology-dag.mjs";import{t as import_default_map}from"../_chunks/libs/mnemonist.mjs";import"../_chunks/libs/natural-compare-lite.mjs";import"../_chunks/libs/extend.mjs";import"../_chunks/libs/@mantine/colors-generator.mjs";import{a as unsafeComputeView,c as linkNodesWithEdges,i as computeView,n as computeLikeC4Model,o as computeElementView,r as computeParsedModelData,s as topologicalSort$1,t as $expr}from"../_chunks/Builder.view-element.mjs";import{t as Graph}from"../_chunks/libs/graphology.mjs";var import_topological_sort=require_topological_sort(),import_will_create_cycle=__toESM(require_will_create_cycle(),1);function resolveRulesExtendedViews(i){let a=new Graph({type:`directed`}),o=[];for(let s of t(i))a.addNode(s.id,{view:s}),isExtendsElementView(s)&&o.push(s);if(o.length===0)return i;for(let i of o){if(!a.hasNode(i.extends)){console.warn(`View "${i.id}" extends from "${i.extends}" which does not exist`);continue}if((0,import_will_create_cycle.default)(a,i.id,i.extends)){console.warn(`View "${i.id}" extends from "${i.extends}" which creates a cycle`);continue}a.addDirectedEdge(i.id,i.extends)}return(0,import_topological_sort.topologicalSort)(a).reverse().reduce((i,o)=>{let s=a.getNodeAttribute(o,`view`);if(!isExtendsElementView(s))return i[s.id]=s,i;let c=i[s.extends];if(!c||!isElementView(c))return i;let l=n([...c.tags??[],...s.tags??[]]),u=[...c.links??[],...s.links??[]];return i[s.id]={...c,...s,title:s.title??c.title??null,description:s.description??c.description??null,tags:l,links:isNonEmptyArray(u)?u:null,rules:[...c.rules,...s.rules]},i},{})}function withReadableEdges({edges:i,nodes:a,...o},s=`:`){let c=t$1(i,i=>[i.id,`${i.source}${s}${i.target}`]);return{...o,edges:i.map(i=>({...i,id:c[i.id]})),nodes:a.map(i=>({...i,inEdges:t$2(i.inEdges,i=>c[i]),outEdges:t$2(i.outEdges,i=>c[i])})),nodeIds:a.map(i=>i.id),edgeIds:i.map(i=>c[i.id])}}function viewsWithReadableEdges({views:i,...a}){return{...a,views:t$3(i,i=>n$1(withReadableEdges(i),[`nodeIds`,`edgeIds`]))}}const keysCount=i=>t$4(i).length,nodeId=i=>stringHash(i);function computeProjectsView(i){let a=buildNodesForEachModel(i),o=(i,a)=>`${i}->${a}`,s=new import_default_map.default(i=>{let[a,o]=i.split(`->`);return{from:a,to:o,relationships:new Set}}),d=(i,a)=>s.get(o(i,a)).relationships,p=(i,a)=>{let o=a.projectId;invariant(o!==i.projectId,`Imported element must have a different project id`);let s=d(i.projectId,o);for(let o of a.incoming(`direct`))o.source.projectId===i.projectId&&s.add(o);let c=d(o,i.projectId);for(let o of a.outgoing(`direct`))o.target.projectId===i.projectId&&c.add(o)};for(let a of i)if(!e(a.$data.imports))for(let[i,o]of t$5(a.$data.imports))for(let s of o){let o=GlobalFqn(i,s.id);p(a,nonNullable(a.findElement(o),`Element ${s.id} from project ${i} not found in model ${a.projectId}`))}let m=Array.from(s.entries()).filter(([i,{relationships:a}])=>a.size>0).map(([i,{from:a,to:o,relationships:s}])=>{let l=[...s];invariant(t$6(l,1),`Relationships set must have at least one relationship`);let d={id:stringHash(i),source:nodeId(a),target:nodeId(o),projectId:a,relations:t$2(l,e$1(`id`)),label:null,color:`gray`,parent:null,line:`solid`,tags:n(t$7(l,e$1(`tags`)))},f=t$8(l);return f&&(d.label=f.title,d.description=preferSummary(f.$relationship)??null,d.technology=f.technology,d.color=f.color,d.line=f.line,f.kind&&(d.kind=f.kind),f.$relationship.navigateTo&&(d.navigateTo=f.$relationship.navigateTo)),d});linkNodesWithEdges(a,m);let h=topologicalSort$1({nodes:a,edges:m});return{id:`projects-view`,[_type]:`projects`,[_stage]:`computed`,title:`Projects`,description:{txt:`Overview of all projects and their relationships`},autoLayout:{direction:`TB`},...h}}function buildNodesForEachModel(i){let a=new Map;for(let o of i){let i=ProjectId(o.projectId),s={id:nodeId(i),kind:`@project`,parent:null,projectId:i,title:o.project.title??o.project.id,description:{txt:[`Elements: ${keysCount(o.$data.elements)}`,`Relationships: ${keysCount(o.$data.relations)}`,`Views: ${keysCount(o.$data.views)}`].join(`
2
+ `)},shape:`rectangle`,children:[],inEdges:[],outEdges:[],color:`primary`,level:0,style:{},tags:[]};a.set(s.id,s)}return a}function treeFromElements(i){let o=sortParentsFirst([...i]),s=new Set(o),c=new Map,l=new import_default_map.default(()=>null),u=o.reduce((i,o,u,d)=>(c.set(o.id,o),i.set(o.id,t$9(d,r(u+1),n$2(isDescendantOf(o)),t$10((i,a)=>(s.delete(a),i.some(isAncestor(a))||(i.push(a),l.set(a.id,o)),i),[]))),i),new import_default_map.default(()=>[]));return{sorted:o,byId:i=>nonNullable(c.get(i),`Element not found by id: ${i}`),root:s,parent:i=>l.get(typeof i==`string`?i:i.id),children:i=>u.get(typeof i==`string`?i:i.id),flatten:e$2(()=>new Set([...s,...o.reduce((i,a)=>{let o=u.get(a.id);return o.length===0?(i.push(a),i):(o.length>1&&i.push(...o),i)},[])]))}}const finalize=(i,a)=>i.size>2&&a.size!==i.size?new Set(sortParentsFirst([...treeFromElements(i).flatten(),...a])):i.size>1?new Set(sortParentsFirst([...i])):i;function computeRelationships(i,a,o){let s=i=>a.has(i),c=new Set([i]),l={incomers:new Set,subjects:new Set([i]),outgoers:new Set},u=new Set(o.incoming.flatMap(a=>{if(l.subjects.add(a.target),l.incomers.add(a.source),c.add(a.target),a.target!==i){let o=a.target.parent;for(;o&&o!==i;)c.add(o),o=o.parent}let o=a.source,u=[];for(;u.push(o),!(s(o)||!o.parent);)o=o.parent;return u})),d=new Set(o.outgoing.flatMap(a=>{if(l.subjects.add(a.source),l.outgoers.add(a.target),c.add(a.source),a.source!==i){let o=a.source.parent;for(;o&&o!==i;)c.add(o),o=o.parent}let o=a.target,u=[];for(;u.push(o),!(s(o)||!o.parent);)o=o.parent;return u}));return{incomers:finalize(u,l.incomers),incoming:new Set(o.incoming),subjects:finalize(c,l.subjects),outgoing:new Set(o.outgoing),outgoers:finalize(d,l.outgoers)}}function computeRelationshipsView(i,a,o,s=`global`){let c=o?a.findView(o):null;if(s===`view`)return invariant(c,`Scope view id is required when scope is "view"`),computeScopedRelationshipsView(i,c,a);let l=a.element(i);return computeRelationships(l,toSet(l.ascendingSiblings()),{incoming:[...l.incoming()],outgoing:[...l.outgoing()]})}function computeScopedRelationshipsView(i,a,o){let s=o.element(i),c={incoming:toArray(ifilter(s.incoming(),i=>a.includesRelation(i.id))),outgoing:toArray(ifilter(s.outgoing(),i=>a.includesRelation(i.id)))},l=isDescendantOf(s);return computeRelationships(s,new Set([...s.ascendingSiblings(),...t$9(a.elements(),imap(i=>i.element),ifilter(i=>i!==s&&l(i)))]),c)}function computeAdhocView(i,a){return{...computeElementView(i,{id:ViewId(`adhoc`),_stage:`parsed`,_type:`element`,rules:a,title:null,description:null}),_type:`adhoc`,_stage:`computed`}}var AdhocView=class i{static use(a){return new i(a)}#e=[];constructor(i){this.model=i}Expr;include(...i){return this.#e.push({include:i.map(i=>$expr(i))}),this}exclude(...i){return this.#e.push({exclude:i.map(i=>$expr(i))}),this}compute(){return computeAdhocView(this.model,this.#e)}};export{AdhocView,computeAdhocView,computeLikeC4Model,computeParsedModelData,computeProjectsView,computeRelationshipsView,computeView,resolveRulesExtendedViews,treeFromElements,unsafeComputeView,viewsWithReadableEdges,withReadableEdges};
@@ -1,109 +1,2 @@
1
- export { B as BBox, P as Point, R as RectBox, X as XYPoint } from '../shared/core.BPGOjone.mjs';
2
-
3
- interface VectorValue {
4
- readonly x: number;
5
- readonly y: number;
6
- }
7
- declare class Vector implements VectorValue {
8
- readonly x: number;
9
- readonly y: number;
10
- constructor(x: number, y: number);
11
- static create(position: VectorValue): Vector;
12
- static create(x: number, y: number): Vector;
13
- /**
14
- * Adds two vectors.
15
- * @param a The first vector.
16
- * @param b The second vector.
17
- * @returns The sum of the two vectors.
18
- */
19
- static add(a: VectorValue, b: VectorValue): VectorValue;
20
- /**
21
- * Subtracts two vectors.
22
- * @param a The first vector.
23
- * @param b The second vector.
24
- * @returns The difference of the two vectors.
25
- */
26
- static subtract(a: VectorValue, b: VectorValue): VectorValue;
27
- /**
28
- * Multiplies a vector by a scalar.
29
- * @param a The vector.
30
- * @param b The scalar.
31
- * @returns The scaled vector.
32
- */
33
- static multiply(a: VectorValue, b: number): VectorValue;
34
- /**
35
- * Divides a vector by a scalar.
36
- * @param a The vector.
37
- * @param b The scalar.
38
- * @returns The scaled vector.
39
- */
40
- static divide(a: VectorValue, b: number): VectorValue;
41
- /**
42
- * Calculates the dot product of the vectors.
43
- * @param a The first vector.
44
- * @param b The second vector.
45
- * @returns The dot product.
46
- */
47
- static dot(a: VectorValue, b: VectorValue): number;
48
- /**
49
- * Adds the given vector to this vector.
50
- * @param b The vector to add.
51
- * @returns A new vector that is the sum of this vector and the given vector.
52
- */
53
- add(b: VectorValue): Vector;
54
- /**
55
- * Subtracts the given vector from this vector.
56
- * @param b The vector to subtract.
57
- * @returns A new vector that is the difference of this vector and the given vector.
58
- */
59
- subtract(b: VectorValue): Vector;
60
- /**
61
- * Multiplies this vector by a scalar.
62
- * @param b The scalar to multiply by.
63
- * @returns A new vector that is the product of this vector and the given scalar.
64
- */
65
- multiply(b: number): Vector;
66
- /**
67
- * Divides this vector by a scalar.
68
- * @param b The scalar to divide by.
69
- * @returns A new vector that is the quotient of this vector and the given scalar.
70
- */
71
- divide(b: number): Vector;
72
- /**
73
- * Calculates the dot product of this vector and another vector.
74
- * @param b The other vector.
75
- * @returns The dot product.
76
- */
77
- dot(b: VectorValue): number;
78
- /**
79
- * Calculates the cross product of this vector and another vector.
80
- * The cross product of two 2D vectors is a scalar value: a.x * b.y - a.y * b.x
81
- * @param b The other vector.
82
- * @returns The cross product as a scalar.
83
- */
84
- cross(b: VectorValue): number;
85
- /**
86
- * Calculates the length (magnitude) of this vector.
87
- * @returns The length of the vector.
88
- */
89
- length(): number;
90
- /**
91
- * Normalizes the vector (makes it unit length, i.e., has a length of 1).
92
- * @returns A new vector that is the normalized version of this vector.
93
- */
94
- normalize(): Vector;
95
- /**
96
- * Rounds the components of the vector to the nearest integers.
97
- * @returns A new vector with rounded components.
98
- */
99
- round(): Vector;
100
- /**
101
- * Converts the vector to a plain object.
102
- * @returns An object with x and y properties.
103
- */
104
- toObject(): VectorValue;
105
- }
106
- declare function vector(source: VectorValue | Vector): Vector;
107
- declare function vector(x: number, y: number): Vector;
108
-
109
- export { Vector, type VectorValue, vector };
1
+ import { a as RectBox, c as XYPoint, i as BBox, l as convertPoint, n as VectorValue, o as Dimensions, r as vector, s as Point, t as Vector, u as isPoint } from "../_chunks/vector.mjs";
2
+ export { BBox, Dimensions, Point, RectBox, Vector, VectorValue, XYPoint, convertPoint, isPoint, vector };