@likec4/core 1.17.1 → 1.18.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 (112) hide show
  1. package/dist/compute-view/index.d.mts +91 -0
  2. package/dist/compute-view/index.d.ts +91 -0
  3. package/dist/compute-view/index.mjs +79 -0
  4. package/dist/index.d.mts +246 -434
  5. package/dist/index.d.ts +246 -434
  6. package/dist/index.mjs +418 -1322
  7. package/dist/model/index.d.mts +642 -0
  8. package/dist/model/index.d.ts +642 -0
  9. package/dist/model/index.mjs +2 -0
  10. package/dist/shared/core.BBgiAAv1.mjs +144 -0
  11. package/dist/shared/core.BPyJvuMU.mjs +2420 -0
  12. package/dist/shared/core.BQ4AbfvB.mjs +9228 -0
  13. package/dist/shared/{core.CoLQkcYL.d.mts → core.DMYY7C8s.d.mts} +398 -249
  14. package/dist/shared/{core.CoLQkcYL.d.ts → core.DMYY7C8s.d.ts} +398 -249
  15. package/dist/shared/core.k12s_keD.mjs +203 -0
  16. package/dist/types/index.d.mts +69 -1
  17. package/dist/types/index.d.ts +69 -1
  18. package/dist/types/index.mjs +21 -1
  19. package/package.json +38 -40
  20. package/src/builder/Builder.deployment.ts +219 -0
  21. package/src/builder/Builder.deploymentModel.ts +360 -0
  22. package/src/builder/Builder.element.ts +17 -19
  23. package/src/builder/Builder.model.ts +13 -2
  24. package/src/builder/Builder.test-d.ts +59 -4
  25. package/src/builder/Builder.ts +238 -53
  26. package/src/builder/Builder.view.ts +238 -53
  27. package/src/builder/_types.ts +87 -15
  28. package/src/compute-view/LikeC4ModelGraph.ts +330 -0
  29. package/src/compute-view/compute-view.ts +92 -0
  30. package/src/compute-view/deployment-view/Memory.ts +108 -0
  31. package/src/compute-view/deployment-view/Stage.ts +145 -0
  32. package/src/compute-view/deployment-view/__test__/fixture.ts +210 -0
  33. package/src/compute-view/deployment-view/_types.ts +29 -0
  34. package/src/compute-view/deployment-view/clean-connections.ts +229 -0
  35. package/src/compute-view/deployment-view/compute.ts +111 -0
  36. package/src/compute-view/deployment-view/predicates/deployment-ref.ts +146 -0
  37. package/src/compute-view/deployment-view/predicates/relation-direct.ts +130 -0
  38. package/src/compute-view/deployment-view/predicates/relation-in-out.ts +43 -0
  39. package/src/compute-view/deployment-view/predicates/relation-incoming.ts +46 -0
  40. package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +49 -0
  41. package/src/compute-view/deployment-view/predicates/wildcard.ts +29 -0
  42. package/src/compute-view/deployment-view/utils.ts +212 -0
  43. package/src/compute-view/dynamic-view/__test__/fixture.ts +58 -0
  44. package/src/compute-view/dynamic-view/compute.ts +310 -0
  45. package/src/compute-view/element-view/__test__/__snapshots__/legacy.spec.ts.snap +456 -0
  46. package/src/compute-view/element-view/__test__/fixture.ts +645 -0
  47. package/src/compute-view/element-view/compute.ts +734 -0
  48. package/src/compute-view/element-view/predicates.ts +517 -0
  49. package/src/compute-view/index.ts +5 -0
  50. package/src/compute-view/utils/__snapshots__/sortNodes.spec.ts.snap +113 -0
  51. package/src/compute-view/utils/ancestorsOfNode.ts +19 -0
  52. package/src/compute-view/utils/applyCustomElementProperties.ts +66 -0
  53. package/src/compute-view/utils/applyCustomRelationProperties.ts +41 -0
  54. package/src/compute-view/utils/applyViewRuleStyles.ts +53 -0
  55. package/src/compute-view/utils/buildComputedNodes.ts +148 -0
  56. package/src/compute-view/utils/buildElementNotations.ts +63 -0
  57. package/src/compute-view/utils/derive-edge-props-from-relationships.ts +97 -0
  58. package/src/compute-view/utils/elementExpressionToPredicate.ts +52 -0
  59. package/src/compute-view/utils/link-nodes-with-edges.ts +58 -0
  60. package/src/compute-view/utils/relationExpressionToPredicates.ts +55 -0
  61. package/src/compute-view/utils/resolve-extended-views.ts +65 -0
  62. package/src/compute-view/utils/resolve-global-rules.ts +83 -0
  63. package/src/compute-view/utils/sortNodes.ts +101 -0
  64. package/src/compute-view/utils/topological-sort.ts +160 -0
  65. package/src/compute-view/utils/uniqueTags.test.ts +42 -0
  66. package/src/compute-view/utils/uniqueTags.ts +21 -0
  67. package/src/compute-view/utils/view-hash.ts +27 -0
  68. package/src/compute-view/utils/with-readable-edges.ts +31 -0
  69. package/src/index.ts +5 -1
  70. package/src/model/DeploymentElementModel.ts +534 -0
  71. package/src/model/DeploymentModel.ts +364 -0
  72. package/src/model/ElementModel.ts +195 -0
  73. package/src/model/LikeC4Model.test-d.ts +151 -0
  74. package/src/model/LikeC4Model.ts +280 -457
  75. package/src/model/RelationModel.ts +84 -0
  76. package/src/model/__test__/fixture.ts +153 -338
  77. package/src/model/connection/ConnectionModel.ts +94 -0
  78. package/src/model/connection/DeploymentConnectionModel.ts +99 -0
  79. package/src/model/connection/deployment.ts +124 -0
  80. package/src/model/connection/model.ts +123 -0
  81. package/src/model/index.ts +4 -2
  82. package/src/model/types.ts +95 -15
  83. package/src/model/view/EdgeModel.ts +103 -0
  84. package/src/model/view/LikeC4ViewModel.ts +220 -0
  85. package/src/model/view/NodeModel.ts +228 -0
  86. package/src/types/_common.ts +2 -0
  87. package/src/types/deployments.ts +237 -0
  88. package/src/types/element.ts +7 -3
  89. package/src/types/expression.ts +8 -6
  90. package/src/types/index.ts +1 -0
  91. package/src/types/model.ts +68 -9
  92. package/src/types/overview-graph.ts +2 -2
  93. package/src/types/relation.ts +4 -4
  94. package/src/types/view-notation.ts +2 -2
  95. package/src/types/view.ts +104 -30
  96. package/src/utils/{commonHead.ts → common-head.ts} +2 -0
  97. package/src/utils/fqn.ts +83 -27
  98. package/src/utils/getOrCreate.ts +42 -0
  99. package/src/utils/graphlib.ts +10 -0
  100. package/src/utils/index.ts +4 -1
  101. package/src/utils/object-hash.ts +3 -0
  102. package/src/utils/set.ts +76 -0
  103. package/src/utils/string-hash.ts +16 -0
  104. package/dist/index.cjs +0 -5452
  105. package/dist/index.d.cts +0 -1053
  106. package/dist/shared/core.BXTs-8n7.mjs +0 -293
  107. package/dist/shared/core.CoLQkcYL.d.cts +0 -734
  108. package/dist/shared/core.DIYZvpVg.cjs +0 -353
  109. package/dist/types/index.cjs +0 -70
  110. package/dist/types/index.d.cts +0 -2
  111. package/src/model/LikeC4DiagramModel.ts +0 -338
  112. package/src/model/LikeC4ViewModel.ts +0 -320
package/dist/index.mjs CHANGED
@@ -1,237 +1,33 @@
1
- import { u as u$1, i as isElementPredicateExpr, o as o$5, a as invariant, b as isScopedElementView, D as DefaultThemeColor, c as DefaultElementShape, n as n$2, d as nonNullable, e as DefaultRelationshipColor } from './shared/core.BXTs-8n7.mjs';
2
- export { A as AsFqn, B as BorderStyles, a3 as ComputedNode, N as DefaultArrowType, M as DefaultLineStyle, a7 as DiagramNode, E as ElementKind, h as ElementShapes, f as Expr, $ as StepEdgeId, a1 as extractStep, a6 as getBBoxCenter, a2 as getParallelStepsPrefix, J as isAndOperator, T as isAutoLayoutDirection, a4 as isComputedDynamicView, a5 as isComputedElementView, l as isCustomElement, C as isCustomRelationExpr, Y as isDynamicView, W as isDynamicViewIncludeRule, X as isDynamicViewParallelSteps, r as isElement, p as isElementKindExpr, j as isElementRef, q as isElementTagExpr, Z as isElementView, s as isElementWhere, k as isExpandedElementExpr, _ as isExtendsElementView, v as isInOut, w as isIncoming, H as isKindEqual, I as isNotOperator, K as isOrOperator, x as isOutgoing, t as isRelation, y as isRelationExpression, F as isRelationPredicateExpr, z as isRelationWhere, a0 as isStepEdgeId, G as isTagEqual, O as isThemeColor, U as isViewRuleAutoLayout, Q as isViewRuleGlobalPredicateRef, S as isViewRuleGlobalStyle, V as isViewRuleGroup, P as isViewRulePredicate, R as isViewRuleStyle, m as isWildcard, g as nonexhaustive, L as whereOperatorAsPredicate } from './shared/core.BXTs-8n7.mjs';
1
+ import { u, o as o$1, b as invariant, c as isScopedElementView, D as DeploymentElement, d as DefaultThemeColor, e as DefaultElementShape } from './shared/core.k12s_keD.mjs';
2
+ export { A as AsFqn, B as BorderStyles, H as ComputedNode, I as ComputedView, h as DeploymentElementExpression, j as DeploymentExpression, g as DeploymentRelationExpression, K as DiagramNode, E as ElementKind, k as ElementShapes, F as extractStep, J as getBBoxCenter, G as getParallelStepsPrefix, r as isAutoLayoutDirection, w as isDeploymentView, x as isDynamicView, v as isDynamicViewParallelSteps, y as isElementView, i as isExtendsElementView, C as isStepEdgeId, s as isViewRuleAutoLayout, m as isViewRuleGlobalPredicateRef, q as isViewRuleGlobalStyle, t as isViewRuleGroup, l as isViewRulePredicate, p as isViewRuleStyle, f as nonNullable, n as nonexhaustive, z as stepEdgeId } from './shared/core.k12s_keD.mjs';
3
+ import { m, l, c as computeViews, b as i, g as i$1, h as d, j as l$1 } from './shared/core.BQ4AbfvB.mjs';
4
+ export { n as commonHead, k as compareRelations, o as objectHash, s as stringHash } from './shared/core.BQ4AbfvB.mjs';
5
+ import { t as t$1, p as parentFqn, i as isSameHierarchy, L as LikeC4Model, n as nameFromFqn } from './shared/core.BPyJvuMU.mjs';
6
+ export { a as LikeC4DeploymentModel, b as LikeC4ViewModel, l as ancestorsFqn, k as commonAncestor, o as compareByFqnHierarchically, m as compareFqnHierarchically, c as compareNatural, A as difference, B as equals, v as getOrCreate, D as hasIntersection, h as hierarchyDepth, j as hierarchyDistance, z as intersection, e as isAncestor, f as isDescendantOf, x as isNonEmptyArray, w as isString, g as notDescendantOf, d as parentFqnPredicate, s as sortByFqnHierarchically, u as sortNaturalByFqn, q as sortParentsFirst, C as symmetricDifference, y as union } from './shared/core.BPyJvuMU.mjs';
7
+ import { i as isElementPredicateExpr } from './shared/core.BBgiAAv1.mjs';
8
+ export { y as DefaultArrowType, D as DefaultLineStyle, z as DefaultRelationshipColor, e as Expr, v as isAndOperator, c as isCustomElement, q as isCustomRelationExpr, h as isElement, f as isElementKindExpr, a as isElementRef, g as isElementTagExpr, j as isElementWhere, b as isExpandedElementExpr, l as isInOut, m as isIncoming, t as isKindEqual, u as isNotOperator, w as isOrOperator, n as isOutgoing, k as isRelation, o as isRelationExpression, r as isRelationPredicateExpr, p as isRelationWhere, s as isTagEqual, d as isWildcard, x as whereOperatorAsPredicate } from './shared/core.BBgiAAv1.mjs';
3
9
  import defu from 'defu';
10
+ export { isThemeColor } from './types/index.mjs';
4
11
 
5
- function r$1(...t){return u$1(Object.values,t)}
6
-
7
- function d$2(...e){return u$1(a,e,o$4)}var a=(e,n)=>e.length<n.length?e.map((t,r)=>[t,n[r]]):n.map((t,r)=>[e[r],t]),o$4=e=>(n,t)=>({hasNext:!0,next:[n,e[t]],done:t>=e.length-1});
8
-
9
- var s={done:!1,hasNext:!1};
10
-
11
- function x(t,...o){let n=t,u=o.map(e=>"lazy"in e?f(e):void 0),p=0;for(;p<o.length;){if(u[p]===void 0||!B(n)){let i=o[p];n=i(n),p+=1;continue}let r=[];for(let i=p;i<o.length;i++){let l=u[i];if(l===void 0||(r.push(l),l.isSingle))break}let a=[];for(let i of n)if(A(i,a,r))break;let{isSingle:y}=r.at(-1);n=y?a[0]:a,p+=r.length;}return n}function A(t,o,n){if(n.length===0)return o.push(t),!1;let u=t,p=s,e=!1;for(let[r,a]of n.entries()){let{index:y,items:i}=a;if(i.push(u),p=a(u,y,i),a.index+=1,p.hasNext){if(p.hasMany??!1){for(let l of p.next)if(A(l,o,n.slice(r+1)))return !0;return e}u=p.next;}if(!p.hasNext)break;p.done&&(e=!0);}return p.hasNext&&o.push(u),e}function f(t){let{lazy:o,lazyArgs:n}=t,u=o(...n);return Object.assign(u,{isSingle:o.single??!1,index:0,items:[]})}function B(t){return typeof t=="string"||typeof t=="object"&&t!==null&&Symbol.iterator in t}
12
-
13
- function i$3(...e){return u$1(r,e)}var r=(e,t)=>e.length>=t;
14
-
15
- function u(...e){return u$1(i$2,e)}function i$2(e,a){let n=[];for(let[o,r]of e.entries()){if(!a(r,o,e))break;n.push(r);}return n}
16
-
17
- function m$1(...r){return u$1(o$3,r)}function o$3(r,t){let e=[...r];return e.sort(t),e}
18
-
19
- function o$2(r,n){let e=Math.ceil(r),t=Math.floor(n);if(t<e)throw new RangeError(`randomInteger: The range [${r.toString()},${n.toString()}] contains no integer`);return Math.floor(Math.random()*(t-e+1)+e)}
20
-
21
- function d$1(...e){return u$1(i$1,e)}function i$1(e,o){let t={};for(let[r,n]of Object.entries(e))o(n,r,e)&&(t[r]=n);return t}
22
-
23
- function m(...a){return u$1(o$1,a,p)}var o$1=(a,e)=>a.map(e),p=a=>(e,t,r)=>({done:!1,hasNext:!0,next:a(e,t,r)});
24
-
25
- function l$1(...n){return u$1(d,n)}function d(n,o){let e={};for(let[a,t]of n.entries()){let[y,u]=o(t,a,n);e[y]=u;}return e}
26
-
27
- function i(...e){return u$1(o,e)}function o(e,r){let a={};for(let[n,u]of Object.entries(e)){let l=r(u,n,e);a[n]=l;}return a}
28
-
29
- function t$1(r){return typeof r=="string"}
30
-
31
- function n$1(e){return !!e}
12
+ function o(r,n){let e=Math.ceil(r),t=Math.floor(n);if(t<e)throw new RangeError(`randomInteger: The range [${r.toString()},${n.toString()}] contains no integer`);return Math.floor(Math.random()*(t-e+1)+e)}
32
13
 
33
14
  function t(n){return typeof n=="function"}
34
15
 
35
- function l(n){return n!=null}
36
-
37
- function n(...r){return u$1(Object.fromEntries,r)}
38
-
39
- function getDefaultExportFromCjs (x) {
40
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
41
- }
42
-
43
- var naturalCompareLite = {exports: {}};
44
-
45
- var hasRequiredNaturalCompareLite;
46
-
47
- function requireNaturalCompareLite () {
48
- if (hasRequiredNaturalCompareLite) return naturalCompareLite.exports;
49
- hasRequiredNaturalCompareLite = 1;
50
- /*
51
- * @version 1.4.0
52
- * @date 2015-10-26
53
- * @stability 3 - Stable
54
- * @author Lauri Rooden (https://github.com/litejs/natural-compare-lite)
55
- * @license MIT License
56
- */
57
-
58
-
59
- var naturalCompare = function(a, b) {
60
- var i, codeA
61
- , codeB = 1
62
- , posA = 0
63
- , posB = 0
64
- , alphabet = String.alphabet;
65
-
66
- function getCode(str, pos, code) {
67
- if (code) {
68
- for (i = pos; code = getCode(str, i), code < 76 && code > 65;) ++i;
69
- return +str.slice(pos - 1, i)
70
- }
71
- code = alphabet && alphabet.indexOf(str.charAt(pos));
72
- return code > -1 ? code + 76 : ((code = str.charCodeAt(pos) || 0), code < 45 || code > 127) ? code
73
- : code < 46 ? 65 // -
74
- : code < 48 ? code - 1
75
- : code < 58 ? code + 18 // 0-9
76
- : code < 65 ? code - 11
77
- : code < 91 ? code + 11 // A-Z
78
- : code < 97 ? code - 37
79
- : code < 123 ? code + 5 // a-z
80
- : code - 63
81
- }
82
-
83
-
84
- if ((a+="") != (b+="")) for (;codeB;) {
85
- codeA = getCode(a, posA++);
86
- codeB = getCode(b, posB++);
87
-
88
- if (codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
89
- codeA = getCode(a, posA, posA);
90
- codeB = getCode(b, posB, posA = i);
91
- posB = i;
92
- }
93
-
94
- if (codeA != codeB) return (codeA < codeB) ? -1 : 1
95
- }
96
- return 0
97
- };
98
-
99
- try {
100
- naturalCompareLite.exports = naturalCompare;
101
- } catch (e) {
102
- String.naturalCompare = naturalCompare;
103
- }
104
- return naturalCompareLite.exports;
105
- }
106
-
107
- var naturalCompareLiteExports = requireNaturalCompareLite();
108
- const compare = /*@__PURE__*/getDefaultExportFromCjs(naturalCompareLiteExports);
109
-
110
- function compareNatural(a, b) {
111
- if (a === b) return 0;
112
- if (t$1(a)) {
113
- if (t$1(b)) {
114
- return compare(a, b);
115
- }
116
- return 1;
117
- }
118
- return t$1(b) ? -1 : 0;
119
- }
120
-
121
- function isString(value) {
122
- return value != null && typeof value === "string";
123
- }
124
- function isNonEmptyArray(arr) {
125
- return !!arr && Array.isArray(arr) && arr.length > 0;
126
- }
16
+ function n(...r){return u(Object.fromEntries,r)}
127
17
 
128
- function nameFromFqn(fqn) {
129
- const lastDot = fqn.lastIndexOf(".");
130
- if (lastDot > 0) {
131
- return fqn.slice(lastDot + 1);
132
- } else {
133
- return fqn;
134
- }
135
- }
136
- function isAncestor(...args) {
137
- const ancestor = isString(args[0]) ? args[0] : args[0].id;
138
- const another = isString(args[1]) ? args[1] : args[1].id;
139
- return another.startsWith(ancestor + ".");
140
- }
141
- function isSameHierarchy(one, another) {
142
- const first = isString(one) ? one : one.id;
143
- const second = isString(another) ? another : another.id;
144
- return first === second || second.startsWith(first + ".") || first.startsWith(second + ".");
145
- }
146
- function isDescendantOf(ancestors) {
147
- const predicates = ancestors.flatMap((a) => [(e) => e.id === a.id, (e) => isAncestor(a, e)]);
148
- return (e) => predicates.some((p) => p(e));
149
- }
150
- function notDescendantOf(ancestors) {
151
- const isDescendant = isDescendantOf(ancestors);
152
- return (e) => !isDescendant(e);
153
- }
154
- function commonAncestor(first, second) {
155
- const parentA = parentFqn(first);
156
- const parentB = parentFqn(second);
157
- if (parentA === parentB) {
158
- return parentA;
159
- }
160
- if (!parentA || !parentB) {
161
- return null;
162
- }
163
- const a = first.split(".");
164
- const b = second.split(".");
165
- let ancestor = null;
166
- while (a.length > 1 && b.length > 1 && !!a[0] && a[0] === b[0]) {
167
- ancestor = ancestor ? `${ancestor}.${a[0]}` : a[0];
168
- a.shift();
169
- b.shift();
170
- }
171
- return ancestor;
172
- }
173
- function parentFqn(fqn) {
174
- const lastDot = fqn.lastIndexOf(".");
175
- if (lastDot > 0) {
176
- return fqn.slice(0, lastDot);
177
- }
178
- return null;
179
- }
180
- function parentFqnPredicate(parent) {
181
- const prefix = parent + ".";
182
- return (e) => !!e.parent && (e.parent === parent || e.parent.startsWith(prefix));
183
- }
184
- function ancestorsFqn(fqn) {
185
- const path = fqn.split(".");
186
- path.pop();
187
- if (path.length === 0) {
188
- return [];
189
- }
190
- return path.reduce((acc, part, idx) => {
191
- if (idx === 0) {
192
- acc.push(part);
193
- return acc;
194
- }
195
- acc.unshift(`${acc[0]}.${part}`);
196
- return acc;
197
- }, []);
198
- }
199
- function compareFqnHierarchically(a, b) {
200
- const depthA = a.split(".").length;
201
- const depthB = b.split(".").length;
202
- switch (true) {
203
- case depthA > depthB: {
204
- return 1;
205
- }
206
- case depthA < depthB: {
207
- return -1;
208
- }
209
- default: {
210
- return 0;
211
- }
18
+ const DELAY = "LIKEC4_DELAY";
19
+ function delay(...args) {
20
+ let ms = 100;
21
+ if (args.length === 2) {
22
+ ms = o(args[0], args[1]);
23
+ } else if (args.length === 1) {
24
+ ms = args[0];
212
25
  }
213
- }
214
- function compareByFqnHierarchically(a, b) {
215
- return compareFqnHierarchically(a.id, b.id);
216
- }
217
- function sortByFqnHierarchically(array) {
218
- return array.map((item) => ({ item, fqn: item.id.split(".") })).sort((a, b) => {
219
- return a.fqn.length - b.fqn.length;
220
- }).map(({ item }) => item);
221
- }
222
- function sortNaturalByFqn(array) {
223
- return array.map((item) => ({ item, fqn: item.id.split(".") })).sort((a, b) => {
224
- if (a.fqn.length !== b.fqn.length) {
225
- return a.fqn.length - b.fqn.length;
226
- }
227
- for (let i = 0; i < a.fqn.length; i++) {
228
- const compare = compareNatural(a.fqn[i], b.fqn[i]);
229
- if (compare !== 0) {
230
- return compare;
231
- }
232
- }
233
- return 0;
234
- }).map(({ item }) => item);
26
+ return new Promise((resolve) => {
27
+ setTimeout(() => {
28
+ resolve(DELAY);
29
+ }, ms ?? 100);
30
+ });
235
31
  }
236
32
 
237
33
  function parseWhere(where) {
@@ -285,8 +81,7 @@ function parseWhere(where) {
285
81
  }
286
82
  function $include(...args) {
287
83
  return (b) => {
288
- let expr = $expr(args[0]);
289
- const isElement = isElementPredicateExpr(expr);
84
+ let expr = b.$expr(args[0]);
290
85
  if (args.length === 2) {
291
86
  const condition = args[1].where ? parseWhere(args[1].where) : void 0;
292
87
  if (condition) {
@@ -299,6 +94,7 @@ function $include(...args) {
299
94
  }
300
95
  const custom = args[1].with;
301
96
  if (custom) {
97
+ const isElement = isElementPredicateExpr(expr);
302
98
  if (isElement) {
303
99
  expr = {
304
100
  custom: {
@@ -322,7 +118,7 @@ function $include(...args) {
322
118
  }
323
119
  function $exclude(...args) {
324
120
  return (b) => {
325
- let expr = $expr(args[0]);
121
+ let expr = b.$expr(args[0]);
326
122
  if (args.length === 2 && args[1].where) {
327
123
  const condition = parseWhere(args[1].where);
328
124
  expr = {
@@ -336,62 +132,140 @@ function $exclude(...args) {
336
132
  return b;
337
133
  };
338
134
  }
135
+ const asTypedExpr = (expr) => {
136
+ return expr;
137
+ };
339
138
  function $expr(expr) {
340
139
  if (!t$1(expr)) {
341
140
  return expr;
342
141
  }
343
142
  if (expr === "*") {
344
- return { wildcard: true };
143
+ return asTypedExpr({ wildcard: true });
345
144
  }
346
145
  if (expr.startsWith("->")) {
347
146
  if (expr.endsWith("->")) {
348
- return {
147
+ return asTypedExpr({
349
148
  inout: $expr(expr.replace(/->/g, "").trim())
350
- };
149
+ });
351
150
  }
352
- return {
151
+ return asTypedExpr({
353
152
  incoming: $expr(expr.replace("-> ", ""))
354
- };
153
+ });
355
154
  }
356
155
  if (expr.endsWith(" ->")) {
357
- return {
156
+ return asTypedExpr({
358
157
  outgoing: $expr(expr.replace(" ->", ""))
359
- };
158
+ });
360
159
  }
361
160
  if (expr.includes(" <-> ")) {
362
161
  const [source, target] = expr.split(" <-> ");
363
- return {
162
+ return asTypedExpr({
364
163
  source: $expr(source),
365
164
  target: $expr(target),
366
165
  isBidirectional: true
367
- };
166
+ });
368
167
  }
369
168
  if (expr.includes(" -> ")) {
370
169
  const [source, target] = expr.split(" -> ");
371
- return {
170
+ return asTypedExpr({
372
171
  source: $expr(source),
373
172
  target: $expr(target)
374
- };
173
+ });
375
174
  }
376
175
  if (expr.endsWith("._")) {
377
- return {
176
+ return asTypedExpr({
378
177
  expanded: expr.replace("._", "")
379
- };
178
+ });
380
179
  }
381
180
  if (expr.endsWith(".*")) {
382
- return {
181
+ return asTypedExpr({
383
182
  element: expr.replace(".*", ""),
384
- isDescedants: true
385
- };
183
+ isChildren: true
184
+ });
386
185
  }
387
- return {
388
- element: expr,
389
- isDescedants: false
390
- };
186
+ if (expr.endsWith(".**")) {
187
+ return asTypedExpr({
188
+ element: expr.replace(".**", ""),
189
+ isDescendants: true
190
+ });
191
+ }
192
+ return asTypedExpr({
193
+ element: expr
194
+ });
195
+ }
196
+ const asTypedDeploymentExpression = (expr) => {
197
+ return expr;
198
+ };
199
+ function $deploymentExpr(expr) {
200
+ if (!t$1(expr)) {
201
+ return expr;
202
+ }
203
+ if (expr === "*") {
204
+ return asTypedDeploymentExpression({ wildcard: true });
205
+ }
206
+ if (expr.startsWith("->")) {
207
+ if (expr.endsWith("->")) {
208
+ return asTypedDeploymentExpression({
209
+ inout: $deploymentExpr(expr.replace(/->/g, "").trim())
210
+ });
211
+ }
212
+ return asTypedDeploymentExpression({
213
+ incoming: $deploymentExpr(expr.replace("-> ", ""))
214
+ });
215
+ }
216
+ if (expr.endsWith(" ->")) {
217
+ return asTypedDeploymentExpression({
218
+ outgoing: $deploymentExpr(expr.replace(" ->", ""))
219
+ });
220
+ }
221
+ if (expr.includes(" <-> ")) {
222
+ const [source, target] = expr.split(" <-> ");
223
+ return asTypedDeploymentExpression({
224
+ source: $deploymentExpr(source),
225
+ target: $deploymentExpr(target),
226
+ isBidirectional: true
227
+ });
228
+ }
229
+ if (expr.includes(" -> ")) {
230
+ const [source, target] = expr.split(" -> ");
231
+ return asTypedDeploymentExpression({
232
+ source: $deploymentExpr(source),
233
+ target: $deploymentExpr(target)
234
+ });
235
+ }
236
+ if (expr.endsWith("._")) {
237
+ return asTypedDeploymentExpression({
238
+ ref: {
239
+ id: expr.replace("._", "")
240
+ },
241
+ selector: "expanded"
242
+ });
243
+ }
244
+ if (expr.endsWith(".**")) {
245
+ return asTypedDeploymentExpression({
246
+ ref: {
247
+ id: expr.replace(".**", "")
248
+ },
249
+ selector: "descendants"
250
+ });
251
+ }
252
+ if (expr.endsWith(".*")) {
253
+ return asTypedDeploymentExpression({
254
+ ref: {
255
+ id: expr.replace(".*", "")
256
+ },
257
+ selector: "children"
258
+ });
259
+ }
260
+ return asTypedDeploymentExpression({
261
+ ref: {
262
+ id: expr
263
+ }
264
+ });
391
265
  }
392
266
  function $style(element, { notation, ...style }) {
393
267
  return (b) => b.style({
394
- targets: (o$5(element) ? element : [element]).map((e) => $expr(e)),
268
+ targets: (o$1(element) ? element : [element]).map((e) => b.$expr(e)),
395
269
  ...notation ? { notation } : {},
396
270
  style: {
397
271
  ...style
@@ -404,73 +278,81 @@ function $autoLayout(layout) {
404
278
  function $rules(...rules) {
405
279
  return (b) => rules.reduce((b2, rule) => rule(b2), b);
406
280
  }
281
+ function mkViewBuilder(view) {
282
+ const viewBuilder = {
283
+ $expr: view.__ === "deployment" ? $deploymentExpr : $expr,
284
+ autoLayout(autoLayout) {
285
+ view.rules.push({
286
+ direction: autoLayout
287
+ });
288
+ return viewBuilder;
289
+ },
290
+ exclude(expr) {
291
+ view.rules.push({
292
+ exclude: [expr]
293
+ });
294
+ return viewBuilder;
295
+ },
296
+ include(expr) {
297
+ view.rules.push({
298
+ include: [expr]
299
+ });
300
+ return viewBuilder;
301
+ },
302
+ style(rule) {
303
+ view.rules.push(rule);
304
+ return viewBuilder;
305
+ }
306
+ // title(title: string) {
307
+ // view.title = title
308
+ // return viewBuilder
309
+ // },
310
+ // description(description: string) {
311
+ // view.description = description
312
+ // return viewBuilder
313
+ // }
314
+ };
315
+ return viewBuilder;
316
+ }
407
317
 
408
318
  function builder(spec, _elements = /* @__PURE__ */ new Map(), _relations = [], _views = /* @__PURE__ */ new Map(), _globals = {
409
319
  predicates: {},
410
320
  dynamicPredicates: {},
411
321
  styles: {}
412
- }) {
322
+ }, _deployments = /* @__PURE__ */ new Map(), _deploymentRelations = []) {
413
323
  const toLikeC4Specification = () => ({
414
- tags: spec.tags ?? [],
415
324
  elements: {
416
325
  ...spec.elements
417
326
  },
327
+ deployments: {
328
+ ...spec.deployments
329
+ },
418
330
  relationships: {
419
331
  ...spec.relationships
420
- }
332
+ },
333
+ tags: spec.tags ?? []
421
334
  });
422
335
  const mapLinks = (links) => {
423
- if (!links || !i$3(links, 1)) {
336
+ if (!links || !i$1(links, 1)) {
424
337
  return null;
425
338
  }
426
339
  return m(links, (l) => typeof l === "string" ? { url: l } : l);
427
340
  };
428
- const mkViewBuilder = (view) => {
429
- const viewBuilder = {
430
- autoLayout(autoLayout) {
431
- view.rules.push({
432
- direction: autoLayout
433
- });
434
- return viewBuilder;
435
- },
436
- exclude(expr) {
437
- view.rules.push({
438
- exclude: [expr]
439
- });
440
- return viewBuilder;
441
- },
442
- include(expr) {
443
- view.rules.push({
444
- include: [expr]
445
- });
446
- return viewBuilder;
447
- },
448
- style(rule) {
449
- view.rules.push(rule);
450
- return viewBuilder;
451
- }
452
- // title(title: string) {
453
- // view.title = title
454
- // return viewBuilder
455
- // },
456
- // description(description: string) {
457
- // view.description = description
458
- // return viewBuilder
459
- // }
460
- };
461
- return viewBuilder;
462
- };
463
341
  const self = {
464
342
  get Types() {
465
343
  throw new Error("Types are not available in runtime");
466
344
  },
467
- clone: () => builder(
468
- structuredClone(spec),
469
- structuredClone(_elements),
470
- structuredClone(_relations),
471
- structuredClone(_views),
472
- structuredClone(_globals)
473
- ),
345
+ clone: () => {
346
+ return builder(
347
+ structuredClone(spec),
348
+ structuredClone(_elements),
349
+ structuredClone(_relations),
350
+ structuredClone(_views),
351
+ structuredClone(_globals),
352
+ structuredClone(_deployments),
353
+ structuredClone(_deploymentRelations)
354
+ );
355
+ },
474
356
  __model: () => ({
475
357
  addElement: (element) => {
476
358
  const parent = parentFqn(element.id);
@@ -520,13 +402,53 @@ function builder(spec, _elements = /* @__PURE__ */ new Map(), _relations = [], _
520
402
  return self;
521
403
  }
522
404
  }),
405
+ __deployment: () => ({
406
+ addDeployment: (node) => {
407
+ if (_deployments.has(node.id)) {
408
+ throw new Error(`Deployment with id "${node.id}" already exists`);
409
+ }
410
+ const parent = parentFqn(node.id);
411
+ if (parent) {
412
+ invariant(
413
+ _deployments.get(parent),
414
+ `Parent element with id "${parent}" not found for node with id "${node.id}"`
415
+ );
416
+ }
417
+ if (DeploymentElement.isInstance(node)) {
418
+ invariant(parent, "Instance must have parent");
419
+ }
420
+ _deployments.set(node.id, node);
421
+ return self;
422
+ },
423
+ addDeploymentRelation: (relation) => {
424
+ invariant(
425
+ !isSameHierarchy(relation.source.id, relation.target.id),
426
+ "Cannot create relationship between elements in the same hierarchy"
427
+ );
428
+ _deploymentRelations.push({
429
+ id: `deploy_rel${_deploymentRelations.length + 1}`,
430
+ ...relation
431
+ });
432
+ return self;
433
+ },
434
+ fqn: (id) => id
435
+ }),
523
436
  build: () => ({
524
437
  specification: toLikeC4Specification(),
525
438
  elements: n(Array.from(_elements.entries())),
526
- relations: l$1(_relations, (r) => [r.id, r]),
439
+ relations: l(_relations, (r) => [r.id, r]),
527
440
  globals: structuredClone(_globals),
441
+ deployments: {
442
+ elements: n(Array.from(_deployments.entries())),
443
+ relations: l(_deploymentRelations, (r) => [r.id, r])
444
+ },
528
445
  views: n(Array.from(_views.entries()))
529
446
  }),
447
+ buildComputedModel: () => {
448
+ const parsed = self.build();
449
+ const computed = computeViews(parsed);
450
+ return LikeC4Model.create(computed);
451
+ },
530
452
  helpers: () => ({
531
453
  model: {
532
454
  model: (...ops) => {
@@ -602,11 +524,11 @@ function builder(spec, _elements = /* @__PURE__ */ new Map(), _relations = [], _
602
524
  tags: null,
603
525
  color: specStyle?.color ?? DefaultThemeColor,
604
526
  shape: specStyle?.shape ?? DefaultElementShape,
605
- style: d$1({
527
+ style: d({
606
528
  border: specStyle?.border,
607
529
  opacity: specStyle?.opacity,
608
530
  ...style
609
- }, l),
531
+ }, l$1),
610
532
  links,
611
533
  ...icon && { icon },
612
534
  ...spec2,
@@ -706,78 +628,206 @@ function builder(spec, _elements = /* @__PURE__ */ new Map(), _relations = [], _
706
628
  return b;
707
629
  };
708
630
  },
631
+ deploymentView: (id, _props, builder2) => {
632
+ if (t(_props)) {
633
+ builder2 = _props;
634
+ _props = {};
635
+ }
636
+ return (b) => {
637
+ const {
638
+ links: _links = [],
639
+ title = null,
640
+ ...props
641
+ } = typeof _props === "string" ? { title: _props } : { ..._props };
642
+ const links = mapLinks(_links);
643
+ const view = {
644
+ id,
645
+ __: "deployment",
646
+ title,
647
+ description: null,
648
+ tags: null,
649
+ rules: [],
650
+ links,
651
+ customColorDefinitions: {},
652
+ ...props
653
+ };
654
+ b.addView(view);
655
+ if (builder2) {
656
+ builder2(mkViewBuilder(view));
657
+ }
658
+ return b;
659
+ };
660
+ },
709
661
  $autoLayout,
710
662
  $exclude,
711
- $expr,
712
663
  $include,
713
664
  $rules,
714
665
  $style
715
- }
716
- }),
717
- with: (...ops) => {
718
- return ops.reduce((b, op) => op(b), self).clone();
719
- }
720
- };
721
- return self;
722
- }
723
- var Builder;
724
- ((Builder2) => {
725
- function forSpecification(spec) {
726
- const b = builder(spec);
727
- return {
728
- ...b.helpers(),
729
- builder: b
730
- };
731
- }
732
- Builder2.forSpecification = forSpecification;
733
- })(Builder || (Builder = {}));
734
-
735
- const { min: min$4, max: max$4 } = Math;
736
-
737
- const limit = (x, low = 0, high = 1) => {
738
- return min$4(max$4(low, x), high);
739
- };
740
-
741
- const clip_rgb = (rgb) => {
742
- rgb._clipped = false;
743
- rgb._unclipped = rgb.slice(0);
744
- for (let i = 0; i <= 3; i++) {
745
- if (i < 3) {
746
- if (rgb[i] < 0 || rgb[i] > 255) rgb._clipped = true;
747
- rgb[i] = limit(rgb[i], 0, 255);
748
- } else if (i === 3) {
749
- rgb[i] = limit(rgb[i], 0, 1);
750
- }
751
- }
752
- return rgb;
753
- };
754
-
755
- // ported from jQuery's $.type
756
- const classToType = {};
757
- for (let name of [
758
- 'Boolean',
759
- 'Number',
760
- 'String',
761
- 'Function',
762
- 'Array',
763
- 'Date',
764
- 'RegExp',
765
- 'Undefined',
766
- 'Null'
767
- ]) {
768
- classToType[`[object ${name}]`] = name.toLowerCase();
769
- }
770
- function type (obj) {
771
- return classToType[Object.prototype.toString.call(obj)] || 'object';
772
- }
773
-
774
- const unpack = (args, keyOrder = null) => {
775
- // if called with more than 3 arguments, we return the arguments
776
- if (args.length >= 3) return Array.prototype.slice.call(args);
777
- // with less than 3 args we check if first arg is object
778
- // and use the keyOrder string to extract and sort properties
779
- if (type(args[0]) == 'object' && keyOrder) {
780
- return keyOrder
666
+ },
667
+ deployment: {
668
+ deployment: (...ops) => {
669
+ return (b) => {
670
+ const v = b.__deployment();
671
+ for (const op of ops) {
672
+ op(v);
673
+ }
674
+ return b;
675
+ };
676
+ },
677
+ instanceOf: (id, to, _props) => {
678
+ return (b) => {
679
+ const {
680
+ links,
681
+ title,
682
+ ...props
683
+ } = typeof _props === "string" ? { title: _props } : { ..._props };
684
+ const _id = b.fqn(id);
685
+ invariant(_elements.has(to), `Target element with id "${to}" not found`);
686
+ b.addDeployment({
687
+ id: _id,
688
+ element: to,
689
+ ...title && { title },
690
+ ...links && { links: mapLinks(links) },
691
+ ...props
692
+ });
693
+ return b;
694
+ };
695
+ },
696
+ rel: (source, target, _props) => {
697
+ return (b) => {
698
+ const {
699
+ title,
700
+ links,
701
+ ...props
702
+ } = typeof _props === "string" ? { title: _props } : { ..._props };
703
+ b.addDeploymentRelation({
704
+ source: {
705
+ id: source
706
+ },
707
+ target: {
708
+ id: target
709
+ },
710
+ ...title && { title },
711
+ ...links && { links: mapLinks(links) },
712
+ ...props
713
+ });
714
+ return b;
715
+ };
716
+ },
717
+ ...i(
718
+ spec.deployments ?? {},
719
+ ({ style: specStyle, ...spec2 }, kind) => (id, _props) => {
720
+ const add = (b) => {
721
+ const {
722
+ links,
723
+ icon: _icon,
724
+ style,
725
+ title,
726
+ ...props
727
+ } = typeof _props === "string" ? { title: _props } : { ..._props };
728
+ const icon = _icon ?? specStyle?.icon;
729
+ const _id = b.fqn(id);
730
+ b.addDeployment({
731
+ id: _id,
732
+ kind,
733
+ title: title ?? nameFromFqn(_id),
734
+ description: null,
735
+ technology: null,
736
+ tags: null,
737
+ color: specStyle?.color ?? DefaultThemeColor,
738
+ shape: specStyle?.shape ?? DefaultElementShape,
739
+ style: d({
740
+ border: specStyle?.border,
741
+ opacity: specStyle?.opacity,
742
+ ...style
743
+ }, l$1),
744
+ ...links && { links: mapLinks(links) },
745
+ ...icon && { icon },
746
+ ...spec2,
747
+ ...props
748
+ });
749
+ return b;
750
+ };
751
+ add.with = (...ops) => (b) => {
752
+ add(b);
753
+ const nestedBuilder = {
754
+ ...b,
755
+ fqn: (child) => `${b.fqn(id)}.${child}`
756
+ };
757
+ for (const op of ops) {
758
+ op(nestedBuilder);
759
+ }
760
+ return b;
761
+ };
762
+ return add;
763
+ }
764
+ )
765
+ }
766
+ }),
767
+ with: (...ops) => {
768
+ return ops.reduce((b, op) => op(b), self).clone();
769
+ }
770
+ };
771
+ return self;
772
+ }
773
+ var Builder;
774
+ ((Builder2) => {
775
+ function forSpecification(spec) {
776
+ const b = builder(spec);
777
+ return {
778
+ ...b.helpers(),
779
+ builder: b
780
+ };
781
+ }
782
+ Builder2.forSpecification = forSpecification;
783
+ })(Builder || (Builder = {}));
784
+
785
+ const { min: min$4, max: max$4 } = Math;
786
+
787
+ const limit = (x, low = 0, high = 1) => {
788
+ return min$4(max$4(low, x), high);
789
+ };
790
+
791
+ const clip_rgb = (rgb) => {
792
+ rgb._clipped = false;
793
+ rgb._unclipped = rgb.slice(0);
794
+ for (let i = 0; i <= 3; i++) {
795
+ if (i < 3) {
796
+ if (rgb[i] < 0 || rgb[i] > 255) rgb._clipped = true;
797
+ rgb[i] = limit(rgb[i], 0, 255);
798
+ } else if (i === 3) {
799
+ rgb[i] = limit(rgb[i], 0, 1);
800
+ }
801
+ }
802
+ return rgb;
803
+ };
804
+
805
+ // ported from jQuery's $.type
806
+ const classToType = {};
807
+ for (let name of [
808
+ 'Boolean',
809
+ 'Number',
810
+ 'String',
811
+ 'Function',
812
+ 'Array',
813
+ 'Date',
814
+ 'RegExp',
815
+ 'Undefined',
816
+ 'Null'
817
+ ]) {
818
+ classToType[`[object ${name}]`] = name.toLowerCase();
819
+ }
820
+ function type (obj) {
821
+ return classToType[Object.prototype.toString.call(obj)] || 'object';
822
+ }
823
+
824
+ const unpack = (args, keyOrder = null) => {
825
+ // if called with more than 3 arguments, we return the arguments
826
+ if (args.length >= 3) return Array.prototype.slice.call(args);
827
+ // with less than 3 args we check if first arg is object
828
+ // and use the keyOrder string to extract and sort properties
829
+ if (type(args[0]) == 'object' && keyOrder) {
830
+ return keyOrder
781
831
  .split('')
782
832
  .filter((k) => args[0][k] !== undefined)
783
833
  .map((k) => args[0][k]);
@@ -4396,958 +4446,4 @@ function computeColorValues(color) {
4396
4446
  }
4397
4447
  }
4398
4448
 
4399
- function getId(element) {
4400
- return t$1(element) ? element : element.id;
4401
- }
4402
-
4403
- class LikeC4DiagramModel {
4404
- constructor(view, model) {
4405
- this.view = view;
4406
- this.model = model;
4407
- for (const node of view.nodes) {
4408
- const el = new LikeC4DiagramModel.Element(node, this);
4409
- this._elements.set(node.id, el);
4410
- if (n$2(node.parent)) {
4411
- this._rootElements.add(el);
4412
- }
4413
- }
4414
- this._connections = new Map(view.edges.map((e) => [e.id, new LikeC4DiagramModel.Connection(e, this)]));
4415
- }
4416
- _rootElements = /* @__PURE__ */ new Set();
4417
- _elements = /* @__PURE__ */ new Map();
4418
- _connections;
4419
- get isDynamic() {
4420
- return this.view.__ === "dynamic";
4421
- }
4422
- get id() {
4423
- return this.view.id;
4424
- }
4425
- get title() {
4426
- return this.view.title;
4427
- }
4428
- get viewOf() {
4429
- if (n$2(this.view.__) || this.view.__ === "element") {
4430
- const computedView = this.view;
4431
- return computedView.viewOf ? this.model.element(computedView.viewOf) : null;
4432
- }
4433
- return null;
4434
- }
4435
- get tags() {
4436
- return this.view.tags ?? [];
4437
- }
4438
- roots() {
4439
- return [...this._rootElements];
4440
- }
4441
- elements() {
4442
- return [...this._elements.values()];
4443
- }
4444
- element(id) {
4445
- return nonNullable(this._elements.get(id), `LikeC4DiagramModel.Element ${id} in view ${this.view.id} not found`);
4446
- }
4447
- hasElement(id) {
4448
- return this._elements.has(id);
4449
- }
4450
- connections() {
4451
- return [...this._connections.values()];
4452
- }
4453
- connection(id) {
4454
- return nonNullable(this._connections.get(id), `Connection ${id} in view ${this.view.id} not found`);
4455
- }
4456
- findConnections(source, target, direction = "direct") {
4457
- const sourceId = getId(source);
4458
- const targetId = getId(target);
4459
- return this.connections().filter(
4460
- (c) => c.source.id === sourceId && c.target.id === targetId || direction === "both" && c.source.id === targetId && c.target.id === sourceId
4461
- );
4462
- }
4463
- parent(element) {
4464
- const el = this.element(getId(element));
4465
- return el.node.parent ? this.element(el.node.parent) : null;
4466
- }
4467
- children(element) {
4468
- const el = this.element(getId(element));
4469
- return el.node.children.map((c) => this.element(c));
4470
- }
4471
- // Get all sibling (i.e. same parent)
4472
- siblings(element) {
4473
- const id = getId(element);
4474
- const parent = this.parent(id);
4475
- const siblings = parent ? this.children(parent) : this.roots();
4476
- return siblings.filter((e) => e.id !== id);
4477
- }
4478
- /**
4479
- * Get all ancestor elements (i.e. parent, parent’s parent, etc.)
4480
- * (from closest to root)
4481
- */
4482
- ancestors(element) {
4483
- let id = getId(element);
4484
- const result = [];
4485
- let parent;
4486
- while (parent = this.parent(id)) {
4487
- result.push(parent);
4488
- id = parent.id;
4489
- }
4490
- return result;
4491
- }
4492
- descendants(element) {
4493
- const children = this.children(element);
4494
- return children.flatMap((c) => [c, ...this.descendants(c.id)]);
4495
- }
4496
- incoming(element, filter = "all") {
4497
- const el = this.element(getId(element));
4498
- const edges = el.node.inEdges.map((e) => this.connection(e));
4499
- if (filter === "all" || edges.length === 0) {
4500
- return edges;
4501
- }
4502
- return edges.filter((rel) => {
4503
- if (filter === "direct") {
4504
- return rel.target.id === el.id;
4505
- }
4506
- return rel.target.id !== el.id;
4507
- });
4508
- }
4509
- incomers(element, filter = "all") {
4510
- return this.incoming(element, filter).map((r) => r.source);
4511
- }
4512
- /**
4513
- * Outgoing relationships from the element and its descendants
4514
- */
4515
- outgoing(element, filter = "all") {
4516
- const el = this.element(getId(element));
4517
- const edges = el.node.outEdges.map((e) => this.connection(e));
4518
- if (filter === "all" || edges.length === 0) {
4519
- return edges;
4520
- }
4521
- return edges.filter((rel) => {
4522
- if (filter === "direct") {
4523
- return rel.source.id === el.id;
4524
- }
4525
- return rel.source.id !== el.id;
4526
- });
4527
- }
4528
- outgoers(element, filter = "all") {
4529
- return this.outgoing(element, filter).map((r) => r.target);
4530
- }
4531
- }
4532
- ((LikeC4DiagramModel2) => {
4533
- class Element {
4534
- constructor(node, view) {
4535
- this.node = node;
4536
- this.view = view;
4537
- }
4538
- get id() {
4539
- return this.node.id;
4540
- }
4541
- get title() {
4542
- return this.node.title;
4543
- }
4544
- get kind() {
4545
- return this.node.kind;
4546
- }
4547
- get isRoot() {
4548
- return n$2(this.node.parent);
4549
- }
4550
- get hasNested() {
4551
- return this.node.children.length > 0;
4552
- }
4553
- get shape() {
4554
- return this.node.shape;
4555
- }
4556
- get color() {
4557
- return this.node.color;
4558
- }
4559
- get tags() {
4560
- return this.node.tags ?? [];
4561
- }
4562
- get level() {
4563
- return this.node.level;
4564
- }
4565
- get depth() {
4566
- return this.node.depth ?? 0;
4567
- }
4568
- model() {
4569
- return this.view.model.element(this.id);
4570
- }
4571
- parent() {
4572
- return this.node.parent ? this.view.element(this.node.parent) : null;
4573
- }
4574
- metadata(key, defaultValue) {
4575
- return this.model().metadata(key) ?? defaultValue;
4576
- }
4577
- hasMetadata(key) {
4578
- return this.model().hasMetadata(key);
4579
- }
4580
- ancestors() {
4581
- return this.view.ancestors(this);
4582
- }
4583
- siblings() {
4584
- return this.view.siblings(this);
4585
- }
4586
- descendants() {
4587
- return this.view.descendants(this);
4588
- }
4589
- children() {
4590
- return this.view.children(this);
4591
- }
4592
- incoming(filter = "all") {
4593
- return this.view.incoming(this, filter);
4594
- }
4595
- incomers(filter = "all") {
4596
- return this.view.incomers(this, filter);
4597
- }
4598
- outgoing(filter = "all") {
4599
- return this.view.outgoing(this, filter);
4600
- }
4601
- outgoers(filter = "all") {
4602
- return this.view.outgoers(this, filter);
4603
- }
4604
- connectionsTo(target) {
4605
- return this.view.findConnections(this, target);
4606
- }
4607
- }
4608
- LikeC4DiagramModel2.Element = Element;
4609
- class Connection {
4610
- constructor(edge, view) {
4611
- this.edge = edge;
4612
- this.view = view;
4613
- }
4614
- get id() {
4615
- return this.edge.id;
4616
- }
4617
- get source() {
4618
- return this.view.element(this.edge.source);
4619
- }
4620
- get target() {
4621
- return this.view.element(this.edge.target);
4622
- }
4623
- get tags() {
4624
- return this.edge.tags ?? [];
4625
- }
4626
- get color() {
4627
- return this.edge.color ?? DefaultRelationshipColor;
4628
- }
4629
- /**
4630
- * Model relationships
4631
- */
4632
- relationships() {
4633
- return this.edge.relations.map((r) => nonNullable(this.view.model.relationship(r)));
4634
- }
4635
- }
4636
- LikeC4DiagramModel2.Connection = Connection;
4637
- })(LikeC4DiagramModel || (LikeC4DiagramModel = {}));
4638
-
4639
- class LikeC4ViewModel {
4640
- constructor(view, model) {
4641
- this.view = view;
4642
- this.model = model;
4643
- for (const node of view.nodes) {
4644
- const el = new LikeC4ViewModel.Element(node, this);
4645
- this._elements.set(node.id, el);
4646
- if (n$2(node.parent)) {
4647
- this._rootElements.add(el);
4648
- }
4649
- }
4650
- this._connections = new Map(view.edges.map((e) => [e.id, new LikeC4ViewModel.Connection(e, this)]));
4651
- }
4652
- _rootElements = /* @__PURE__ */ new Set();
4653
- _elements = /* @__PURE__ */ new Map();
4654
- _connections;
4655
- get id() {
4656
- return this.view.id;
4657
- }
4658
- get title() {
4659
- return this.view.title;
4660
- }
4661
- get viewOf() {
4662
- if (this.view.__ !== "dynamic") {
4663
- return this.view.viewOf ? this.model.element(this.view.viewOf) : null;
4664
- }
4665
- return null;
4666
- }
4667
- get tags() {
4668
- return this.view.tags ?? [];
4669
- }
4670
- roots() {
4671
- return [...this._rootElements];
4672
- }
4673
- elements() {
4674
- return [...this._elements.values()];
4675
- }
4676
- element(id) {
4677
- return nonNullable(this._elements.get(id), `LikeC4ViewModel.Element ${id} in view ${this.id} not found`);
4678
- }
4679
- hasElement(id) {
4680
- return this._elements.has(id);
4681
- }
4682
- connections() {
4683
- return [...this._connections.values()];
4684
- }
4685
- connection(id) {
4686
- return nonNullable(this._connections.get(id), `Connection ${id} in view ${this.id} not found`);
4687
- }
4688
- findConnections(source, target, direction = "direct") {
4689
- const sourceId = getId(source);
4690
- const targetId = getId(target);
4691
- return this.connections().filter(
4692
- (c) => c.source.id === sourceId && c.target.id === targetId || direction === "both" && c.source.id === targetId && c.target.id === sourceId
4693
- );
4694
- }
4695
- parent(element) {
4696
- const el = this.element(getId(element));
4697
- return el.node.parent ? this.element(el.node.parent) : null;
4698
- }
4699
- children(element) {
4700
- const el = this.element(getId(element));
4701
- return el.node.children.map((c) => this.element(c));
4702
- }
4703
- // Get all sibling (i.e. same parent)
4704
- siblings(element) {
4705
- const id = getId(element);
4706
- const parent = this.parent(id);
4707
- const siblings = parent ? this.children(parent) : this.roots();
4708
- return siblings.filter((e) => e.id !== id);
4709
- }
4710
- /**
4711
- * Get all ancestor elements (i.e. parent, parent’s parent, etc.)
4712
- * (from closest to root)
4713
- */
4714
- ancestors(element) {
4715
- let id = getId(element);
4716
- const result = [];
4717
- let parent;
4718
- while (parent = this.parent(id)) {
4719
- result.push(parent);
4720
- id = parent.id;
4721
- }
4722
- return result;
4723
- }
4724
- descendants(element) {
4725
- const children = this.children(element);
4726
- return children.flatMap((c) => [c, ...this.descendants(c.id)]);
4727
- }
4728
- incoming(element, filter = "all") {
4729
- const el = this.element(getId(element));
4730
- const edges = el.node.inEdges.map((e) => nonNullable(this._connections.get(e), `Edge ${e} not found`));
4731
- if (filter === "all" || edges.length === 0) {
4732
- return edges;
4733
- }
4734
- return edges.filter((rel) => {
4735
- if (filter === "direct") {
4736
- return rel.target.id === el.id;
4737
- }
4738
- return rel.target.id !== el.id;
4739
- });
4740
- }
4741
- incomers(element, filter = "all") {
4742
- return [...new Set(this.incoming(element, filter).map((r) => r.source))];
4743
- }
4744
- /**
4745
- * Outgoing relationships from the element and its descendants
4746
- */
4747
- outgoing(element, filter = "all") {
4748
- const el = this.element(getId(element));
4749
- const edges = el.node.outEdges.map((e) => nonNullable(this._connections.get(e), `Edge ${e} not found`));
4750
- if (filter === "all" || edges.length === 0) {
4751
- return edges;
4752
- }
4753
- return edges.filter((rel) => {
4754
- if (filter === "direct") {
4755
- return rel.source.id === el.id;
4756
- }
4757
- return rel.source.id !== el.id;
4758
- });
4759
- }
4760
- outgoers(element, filter = "all") {
4761
- return [...new Set(this.outgoing(element, filter).map((r) => r.target))];
4762
- }
4763
- }
4764
- ((LikeC4ViewModel2) => {
4765
- class Element {
4766
- constructor(node, viewmodel) {
4767
- this.node = node;
4768
- this.viewmodel = viewmodel;
4769
- }
4770
- get id() {
4771
- return this.node.id;
4772
- }
4773
- get title() {
4774
- return this.node.title;
4775
- }
4776
- get kind() {
4777
- return this.node.kind;
4778
- }
4779
- get isRoot() {
4780
- return n$2(this.node.parent);
4781
- }
4782
- get hasNested() {
4783
- return this.node.children.length > 0;
4784
- }
4785
- get shape() {
4786
- return this.node.shape;
4787
- }
4788
- get color() {
4789
- return this.node.color;
4790
- }
4791
- get tags() {
4792
- return this.node.tags ?? [];
4793
- }
4794
- model() {
4795
- return this.viewmodel.model.element(this.id);
4796
- }
4797
- parent() {
4798
- return this.node.parent ? this.viewmodel.element(this.node.parent) : null;
4799
- }
4800
- metadata(key, defaultValue) {
4801
- return this.model().metadata(key) ?? defaultValue;
4802
- }
4803
- hasMetadata(key) {
4804
- return this.model().hasMetadata(key);
4805
- }
4806
- ancestors() {
4807
- return this.viewmodel.ancestors(this);
4808
- }
4809
- siblings() {
4810
- return this.viewmodel.siblings(this);
4811
- }
4812
- descendants() {
4813
- return this.viewmodel.descendants(this);
4814
- }
4815
- children() {
4816
- return this.viewmodel.children(this);
4817
- }
4818
- incoming(filter = "all") {
4819
- return this.viewmodel.incoming(this, filter);
4820
- }
4821
- incomers(filter = "all") {
4822
- return this.viewmodel.incomers(this, filter);
4823
- }
4824
- outgoing(filter = "all") {
4825
- return this.viewmodel.outgoing(this, filter);
4826
- }
4827
- outgoers(filter = "all") {
4828
- return this.viewmodel.outgoers(this, filter);
4829
- }
4830
- connectionsTo(target) {
4831
- return this.viewmodel.findConnections(this, target);
4832
- }
4833
- }
4834
- LikeC4ViewModel2.Element = Element;
4835
- class Connection {
4836
- constructor(edge, viewmodel) {
4837
- this.edge = edge;
4838
- this.viewmodel = viewmodel;
4839
- }
4840
- get id() {
4841
- return this.edge.id;
4842
- }
4843
- get source() {
4844
- return this.viewmodel.element(this.edge.source);
4845
- }
4846
- get target() {
4847
- return this.viewmodel.element(this.edge.target);
4848
- }
4849
- get tags() {
4850
- return this.edge.tags ?? [];
4851
- }
4852
- /**
4853
- * Model relationships
4854
- */
4855
- relationships() {
4856
- return this.edge.relations.map((r) => nonNullable(this.viewmodel.model.relationship(r)));
4857
- }
4858
- }
4859
- LikeC4ViewModel2.Connection = Connection;
4860
- })(LikeC4ViewModel || (LikeC4ViewModel = {}));
4861
-
4862
- class LikeC4Model {
4863
- constructor(type, sourcemodel, elements, relations, views, ViewModelClass) {
4864
- this.type = type;
4865
- this.sourcemodel = sourcemodel;
4866
- for (const el of elements) {
4867
- this.addElement(el);
4868
- }
4869
- for (const rel of relations) {
4870
- this.addRelation(rel);
4871
- }
4872
- this._views = new Map(
4873
- x(
4874
- r$1(views),
4875
- m$1((a, b) => compareNatural(a.title ?? "untitled", b.title ?? "untitled")),
4876
- m((view) => [view.id, new ViewModelClass(view, this)])
4877
- )
4878
- );
4879
- }
4880
- _elements = /* @__PURE__ */ new Map();
4881
- // Parent element for given FQN
4882
- _parents = /* @__PURE__ */ new Map();
4883
- // Children elements for given FQN
4884
- _children = /* @__PURE__ */ new Map();
4885
- _rootElements = /* @__PURE__ */ new Set();
4886
- _relations = /* @__PURE__ */ new Map();
4887
- // Incoming to an element or its descendants
4888
- _incoming = /* @__PURE__ */ new Map();
4889
- // Outgoing from an element or its descendants
4890
- _outgoing = /* @__PURE__ */ new Map();
4891
- // Relationships inside the element, among descendants
4892
- _internal = /* @__PURE__ */ new Map();
4893
- _cacheAscendingSiblings = /* @__PURE__ */ new Map();
4894
- _views;
4895
- /**
4896
- * Returns the root elements of the model.
4897
- */
4898
- roots() {
4899
- return [...this._rootElements];
4900
- }
4901
- /**
4902
- * Returns all elements in the model.
4903
- */
4904
- elements() {
4905
- return [...this._elements.values()];
4906
- }
4907
- /**
4908
- * Returns a specific element by its FQN.
4909
- */
4910
- element(id) {
4911
- return nonNullable(this._elements.get(id), `Element ${id} not found`);
4912
- }
4913
- /**
4914
- * Returns all relationships in the model.
4915
- */
4916
- relationships() {
4917
- return [...this._relations.values()];
4918
- }
4919
- /**
4920
- * Returns a specific relationship by its ID.
4921
- */
4922
- relationship(id) {
4923
- return nonNullable(this._relations.get(id), `Relation ${id} not found`);
4924
- }
4925
- /**
4926
- * Returns all views in the model.
4927
- */
4928
- views() {
4929
- return [...this._views.values()];
4930
- }
4931
- /**
4932
- * Returns a specific view by its ID.
4933
- */
4934
- view(viewId) {
4935
- return nonNullable(this._views.get(viewId), `View ${viewId} not found`);
4936
- }
4937
- /**
4938
- * Returns the parent element of given element.
4939
- * @see ancestors
4940
- */
4941
- parent(element) {
4942
- const id = getId(element);
4943
- return this._parents.get(id) || null;
4944
- }
4945
- /**
4946
- * Get all children of the element (only direct children),
4947
- * @see descendants
4948
- */
4949
- children(element) {
4950
- const id = getId(element);
4951
- return this._childrenOf(id);
4952
- }
4953
- /**
4954
- * Get all sibling (i.e. same parent)
4955
- */
4956
- siblings(element) {
4957
- const id = getId(element);
4958
- const parent = this._parents.get(id);
4959
- const siblings = parent ? this._childrenOf(parent.id) : this.roots();
4960
- return siblings.filter((e) => e.id !== id);
4961
- }
4962
- /**
4963
- * Get all ancestor elements (i.e. parent, parent’s parent, etc.)
4964
- * (from closest to root)
4965
- */
4966
- ancestors(element) {
4967
- let id = t$1(element) ? element : element.id;
4968
- const result = [];
4969
- let parent;
4970
- while (parent = this._parents.get(id)) {
4971
- result.push(parent);
4972
- id = parent.id;
4973
- }
4974
- return result;
4975
- }
4976
- /**
4977
- * Get all descendant elements (i.e. children, children’s children, etc.)
4978
- */
4979
- descendants(element) {
4980
- const id = getId(element);
4981
- const children = this._childrenOf(id);
4982
- return children.flatMap((c) => [c, ...this.descendants(c.id)]);
4983
- }
4984
- /**
4985
- * Incoming relationships to the element and its descendants
4986
- * @see incomers
4987
- */
4988
- incoming(element, filter = "all") {
4989
- const id = getId(element);
4990
- const incoming = Array.from(this._incomingTo(id));
4991
- if (filter === "all" || incoming.length === 0) {
4992
- return incoming;
4993
- }
4994
- return incoming.filter((rel) => {
4995
- if (filter === "direct") {
4996
- return rel.target.id === id;
4997
- }
4998
- return rel.target.id !== id;
4999
- });
5000
- }
5001
- /**
5002
- * Source elements of incoming relationships
5003
- */
5004
- incomers(element, filter = "all") {
5005
- return [...new Set(this.incoming(element, filter).map((r) => r.source))];
5006
- }
5007
- /**
5008
- * Outgoing relationships from the element and its descendants
5009
- * @see outgoers
5010
- */
5011
- outgoing(element, filter = "all") {
5012
- const id = getId(element);
5013
- const outgoing = Array.from(this._outgoingFrom(id));
5014
- if (filter === "all" || outgoing.length === 0) {
5015
- return outgoing;
5016
- }
5017
- return outgoing.filter((rel) => {
5018
- if (filter === "direct") {
5019
- return rel.source.id === id;
5020
- }
5021
- return rel.source.id !== id;
5022
- });
5023
- }
5024
- /**
5025
- * Target elements of outgoing relationships
5026
- */
5027
- outgoers(element, filter = "all") {
5028
- return [...new Set(this.outgoing(element, filter).map((r) => r.target))];
5029
- }
5030
- /**
5031
- * Relationships inside the element, among descendants
5032
- */
5033
- internal(element) {
5034
- const id = getId(element);
5035
- return Array.from(this._internalOf(id));
5036
- }
5037
- /**
5038
- * Resolve siblings of the element and siblings of ancestors
5039
- * (from closest to root)
5040
- */
5041
- ascendingSiblings(element) {
5042
- const id = getId(element);
5043
- let siblings = this._cacheAscendingSiblings.get(id);
5044
- if (!siblings) {
5045
- siblings = [
5046
- ...this.siblings(id),
5047
- ...this.ancestors(id).flatMap((a) => this.siblings(a.id))
5048
- ];
5049
- this._cacheAscendingSiblings.set(id, siblings);
5050
- }
5051
- return siblings.slice();
5052
- }
5053
- /**
5054
- * Resolve all views that contain the element
5055
- */
5056
- viewsWithElement(element) {
5057
- const id = getId(element);
5058
- return [...this._views.values()].filter((v) => v.hasElement(id));
5059
- }
5060
- addElement(parsed) {
5061
- if (this._elements.has(parsed.id)) {
5062
- throw new Error(`Element ${parsed.id} already exists`);
5063
- }
5064
- const el = new LikeC4Model.ElementModel(parsed, this);
5065
- this._elements.set(el.id, el);
5066
- const parentId = parentFqn(el.id);
5067
- if (parentId) {
5068
- this._parents.set(el.id, this.element(parentId));
5069
- this._childrenOf(parentId).push(el);
5070
- } else {
5071
- this._rootElements.add(el);
5072
- }
5073
- }
5074
- addRelation(relation) {
5075
- if (this._relations.has(relation.id)) {
5076
- throw new Error(`Relation ${relation.id} already exists`);
5077
- }
5078
- const rel = new LikeC4Model.Relationship(relation, this);
5079
- this._relations.set(rel.id, rel);
5080
- this._incomingTo(relation.target).add(rel);
5081
- this._outgoingFrom(relation.source).add(rel);
5082
- const relParent = commonAncestor(relation.source, relation.target);
5083
- if (relParent) {
5084
- for (const ancestor of [relParent, ...ancestorsFqn(relParent)]) {
5085
- this._internalOf(ancestor).add(rel);
5086
- }
5087
- }
5088
- for (const sourceAncestor of ancestorsFqn(relation.source)) {
5089
- if (sourceAncestor === relParent) {
5090
- break;
5091
- }
5092
- this._outgoingFrom(sourceAncestor).add(rel);
5093
- }
5094
- for (const targetAncestor of ancestorsFqn(relation.target)) {
5095
- if (targetAncestor === relParent) {
5096
- break;
5097
- }
5098
- this._incomingTo(targetAncestor).add(rel);
5099
- }
5100
- }
5101
- _childrenOf(id) {
5102
- let children = this._children.get(id);
5103
- if (!children) {
5104
- children = [];
5105
- this._children.set(id, children);
5106
- }
5107
- return children;
5108
- }
5109
- _incomingTo(id) {
5110
- let incoming = this._incoming.get(id);
5111
- if (!incoming) {
5112
- incoming = /* @__PURE__ */ new Set();
5113
- this._incoming.set(id, incoming);
5114
- }
5115
- return incoming;
5116
- }
5117
- _outgoingFrom(id) {
5118
- let outgoing = this._outgoing.get(id);
5119
- if (!outgoing) {
5120
- outgoing = /* @__PURE__ */ new Set();
5121
- this._outgoing.set(id, outgoing);
5122
- }
5123
- return outgoing;
5124
- }
5125
- _internalOf(id) {
5126
- let internal = this._internal.get(id);
5127
- if (!internal) {
5128
- internal = /* @__PURE__ */ new Set();
5129
- this._internal.set(id, internal);
5130
- }
5131
- return internal;
5132
- }
5133
- }
5134
- ((LikeC4Model2) => {
5135
- function create(source) {
5136
- if (source.__ === "layouted") {
5137
- return LikeC4Model2.layouted(source);
5138
- }
5139
- return LikeC4Model2.computed(source);
5140
- }
5141
- LikeC4Model2.create = create;
5142
- function computed(source) {
5143
- return new LikeC4Model2(
5144
- "computed",
5145
- source,
5146
- r$1(source.elements),
5147
- r$1(source.relations),
5148
- source.views,
5149
- LikeC4ViewModel
5150
- );
5151
- }
5152
- LikeC4Model2.computed = computed;
5153
- function layouted(source) {
5154
- return new LikeC4Model2(
5155
- "layouted",
5156
- source,
5157
- r$1(source.elements),
5158
- r$1(source.relations),
5159
- source.views,
5160
- LikeC4DiagramModel
5161
- );
5162
- }
5163
- LikeC4Model2.layouted = layouted;
5164
- function isModel(model) {
5165
- return model instanceof LikeC4Model2;
5166
- }
5167
- LikeC4Model2.isModel = isModel;
5168
- ((ViewModel2) => {
5169
- function isLayouted2(model) {
5170
- return model instanceof LikeC4DiagramModel;
5171
- }
5172
- ViewModel2.isLayouted = isLayouted2;
5173
- })(LikeC4Model2.ViewModel || (LikeC4Model2.ViewModel = {}));
5174
- function isLayouted(model) {
5175
- return model.type === "layouted";
5176
- }
5177
- LikeC4Model2.isLayouted = isLayouted;
5178
- class Relationship {
5179
- constructor(relationship, model) {
5180
- this.relationship = relationship;
5181
- this.model = model;
5182
- }
5183
- get id() {
5184
- return this.relationship.id;
5185
- }
5186
- get title() {
5187
- return this.relationship.title;
5188
- }
5189
- get kind() {
5190
- return this.relationship.kind ?? null;
5191
- }
5192
- get tags() {
5193
- return this.relationship.tags ?? [];
5194
- }
5195
- get source() {
5196
- return this.model.element(this.relationship.source);
5197
- }
5198
- get target() {
5199
- return this.model.element(this.relationship.target);
5200
- }
5201
- metadata(key, defaultValue) {
5202
- return this.relationship.metadata?.[key] ?? defaultValue;
5203
- }
5204
- hasMetadata(key) {
5205
- return n$1(this.relationship.metadata?.[key]);
5206
- }
5207
- }
5208
- LikeC4Model2.Relationship = Relationship;
5209
- class ElementModel {
5210
- constructor(element, model) {
5211
- this.element = element;
5212
- this.model = model;
5213
- }
5214
- get id() {
5215
- return this.element.id;
5216
- }
5217
- get title() {
5218
- return this.element.title;
5219
- }
5220
- get kind() {
5221
- return this.element.kind;
5222
- }
5223
- get isRoot() {
5224
- return parentFqn(this.element.id) === null;
5225
- }
5226
- get hasNested() {
5227
- return this.model.children(this).length > 0;
5228
- }
5229
- get shape() {
5230
- return this.element.shape ?? DefaultElementShape;
5231
- }
5232
- get color() {
5233
- return this.element.color ?? DefaultThemeColor;
5234
- }
5235
- get tags() {
5236
- return this.element.tags ?? [];
5237
- }
5238
- parent() {
5239
- return this.model.parent(this);
5240
- }
5241
- metadata(key, defaultValue) {
5242
- return this.element.metadata?.[key] ?? defaultValue;
5243
- }
5244
- hasMetadata(key) {
5245
- return n$1(this.element.metadata?.[key]);
5246
- }
5247
- ancestors() {
5248
- return this.model.ancestors(this);
5249
- }
5250
- siblings() {
5251
- return this.model.siblings(this);
5252
- }
5253
- descendants() {
5254
- return this.model.descendants(this);
5255
- }
5256
- children() {
5257
- return this.model.children(this);
5258
- }
5259
- /**
5260
- * First 'view of' current element
5261
- */
5262
- viewOf() {
5263
- return this.model.views().find((v) => v.viewOf?.id === this.id) ?? null;
5264
- }
5265
- /**
5266
- * All views 'view of' current element
5267
- */
5268
- viewsOf() {
5269
- return this.model.views().filter((v) => v.viewOf?.id === this.id);
5270
- }
5271
- /**
5272
- * Views that contain this element
5273
- */
5274
- views() {
5275
- return this.model.viewsWithElement(this);
5276
- }
5277
- incoming(filter) {
5278
- return this.model.incoming(this, filter);
5279
- }
5280
- incomers(filter) {
5281
- return this.model.incomers(this, filter);
5282
- }
5283
- outgoing(filter) {
5284
- return this.model.outgoing(this, filter);
5285
- }
5286
- outgoers(filter) {
5287
- return this.model.outgoers(this, filter);
5288
- }
5289
- internal() {
5290
- return this.model.internal(this);
5291
- }
5292
- /**
5293
- * Resolve siblings of the element and siblings of ancestors
5294
- * (from closest to root)
5295
- */
5296
- ascendingSiblings() {
5297
- return this.model.ascendingSiblings(this);
5298
- }
5299
- // public *descendants(): IterableIterator<LikeC4Element> {
5300
- // return
5301
- // }
5302
- }
5303
- LikeC4Model2.ElementModel = ElementModel;
5304
- })(LikeC4Model || (LikeC4Model = {}));
5305
-
5306
- function commonHead(sources, targets, equals) {
5307
- if (sources.length === 0 || targets.length === 0) {
5308
- return [];
5309
- }
5310
- equals ??= Object.is;
5311
- return x(
5312
- d$2(sources, targets),
5313
- u(([source, target]) => equals(source, target)),
5314
- m(([source, _]) => source)
5315
- );
5316
- }
5317
-
5318
- const DELAY = "LIKEC4_DELAY";
5319
- function delay(...args) {
5320
- let ms = 100;
5321
- if (args.length === 2) {
5322
- ms = o$2(args[0], args[1]);
5323
- } else if (args.length === 1) {
5324
- ms = args[0];
5325
- }
5326
- return new Promise((resolve) => {
5327
- setTimeout(() => {
5328
- resolve(DELAY);
5329
- }, ms ?? 100);
5330
- });
5331
- }
5332
-
5333
- const compareRelations = (a, b) => {
5334
- const parentA = commonAncestor(a.source, a.target);
5335
- const parentB = commonAncestor(b.source, b.target);
5336
- if (parentA && !parentB) {
5337
- return 1;
5338
- }
5339
- if (!parentA && parentB) {
5340
- return -1;
5341
- }
5342
- const compareParents = parentA && parentB ? compareFqnHierarchically(parentA, parentB) : 0;
5343
- if (compareParents !== 0) {
5344
- return compareParents;
5345
- }
5346
- const compareSource = compareFqnHierarchically(a.source, b.source);
5347
- if (compareSource !== 0) {
5348
- return compareSource;
5349
- }
5350
- return compareFqnHierarchically(a.target, b.target);
5351
- };
5352
-
5353
- export { Builder, DefaultElementShape, DefaultRelationshipColor, DefaultThemeColor, ElementColors, LikeC4DiagramModel, LikeC4Model, LikeC4ViewModel, RelationshipColors, ancestorsFqn, commonAncestor, commonHead, compareByFqnHierarchically, compareFqnHierarchically, compareNatural, compareRelations, computeColorValues, defaultTheme, delay, i$3 as hasAtLeast, invariant, isAncestor, isDescendantOf, isElementPredicateExpr, isNonEmptyArray, isSameHierarchy, isScopedElementView, isString, nameFromFqn, nonNullable, notDescendantOf, parentFqn, parentFqnPredicate, sortByFqnHierarchically, sortNaturalByFqn };
4449
+ export { Builder, DefaultElementShape, DefaultThemeColor, DeploymentElement, ElementColors, LikeC4Model, RelationshipColors, computeColorValues, defaultTheme, delay, i$1 as hasAtLeast, invariant, isElementPredicateExpr, isSameHierarchy, isScopedElementView, nameFromFqn, parentFqn };