@likec4/core 1.17.1 → 1.19.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 (184) hide show
  1. package/LICENSE +1 -1
  2. package/dist/builder/index.d.mts +502 -0
  3. package/dist/builder/index.d.ts +502 -0
  4. package/dist/builder/index.js +871 -0
  5. package/dist/compute-view/index.d.mts +22 -0
  6. package/dist/compute-view/index.d.ts +22 -0
  7. package/dist/compute-view/index.js +78 -0
  8. package/dist/index.d.mts +10 -919
  9. package/dist/index.d.ts +10 -919
  10. package/dist/{index.mjs → index.js} +7 -1688
  11. package/dist/model/index.d.mts +254 -0
  12. package/dist/model/index.d.ts +254 -0
  13. package/dist/model/index.js +1 -0
  14. package/dist/shared/chunk-RAAYCPUM.M-JWF7SS.js +21 -0
  15. package/dist/shared/core.BIfgabEw.d.ts +719 -0
  16. package/dist/shared/core.BZ9Msq7w.d.mts +719 -0
  17. package/dist/shared/{core.CoLQkcYL.d.cts → core.C05RDLhi.d.ts} +460 -362
  18. package/dist/shared/{core.CoLQkcYL.d.mts → core.CmYMqgha.d.mts} +460 -362
  19. package/dist/shared/core.D6-fWbM3.d.ts +127 -0
  20. package/dist/shared/core.D74xkKkG.d.mts +148 -0
  21. package/dist/shared/core.D74xkKkG.d.ts +148 -0
  22. package/dist/shared/core.sLaWHBjR.d.mts +127 -0
  23. package/dist/shared/index.-BdzdI2C.js +7443 -0
  24. package/dist/shared/object_hash.CE_oF3I3.js +1222 -0
  25. package/dist/shared/{core.BXTs-8n7.mjs → view.CyZrG8BJ.js} +108 -47
  26. package/dist/types/index.d.mts +71 -1
  27. package/dist/types/index.d.ts +71 -1
  28. package/dist/types/index.js +20 -0
  29. package/dist/utils/index.d.mts +404 -0
  30. package/dist/utils/index.d.ts +404 -0
  31. package/dist/utils/index.js +330 -0
  32. package/package.json +59 -47
  33. package/src/builder/Builder-style1.test-d.ts +190 -0
  34. package/src/builder/Builder-style2.test-d.ts +175 -0
  35. package/src/builder/Builder.deployment.ts +224 -0
  36. package/src/builder/Builder.deploymentModel.ts +385 -0
  37. package/src/builder/Builder.element.ts +19 -19
  38. package/src/builder/Builder.model.ts +67 -42
  39. package/src/builder/Builder.ts +533 -367
  40. package/src/builder/Builder.view-common.ts +234 -0
  41. package/src/builder/Builder.view-deployment.ts +135 -0
  42. package/src/builder/Builder.view-element.ts +189 -0
  43. package/src/builder/Builder.views.ts +109 -33
  44. package/src/builder/Builder.with.ts +475 -0
  45. package/src/builder/__snapshots__/Builder-style1.spec.ts.snap +374 -0
  46. package/src/builder/__snapshots__/Builder-style2.spec.ts.snap +183 -0
  47. package/src/builder/__snapshots__/Builder.spec.ts.snap +374 -0
  48. package/src/builder/_types.ts +113 -18
  49. package/src/builder/index.ts +10 -4
  50. package/src/colors/index.ts +2 -2
  51. package/src/compute-view/compute-view.ts +83 -0
  52. package/src/compute-view/deployment-view/__test__/TestHelper.ts +236 -0
  53. package/src/compute-view/deployment-view/__test__/fixture.ts +198 -0
  54. package/src/compute-view/deployment-view/_types.ts +37 -0
  55. package/src/compute-view/deployment-view/clean-connections.ts +238 -0
  56. package/src/compute-view/deployment-view/compute.ts +125 -0
  57. package/src/compute-view/deployment-view/memory/index.ts +9 -0
  58. package/src/compute-view/deployment-view/memory/memory.ts +97 -0
  59. package/src/compute-view/deployment-view/predicates/elements.ts +144 -0
  60. package/src/compute-view/deployment-view/predicates/relation-direct.ts +237 -0
  61. package/src/compute-view/deployment-view/predicates/relation-in-out.ts +61 -0
  62. package/src/compute-view/deployment-view/predicates/relation-incoming.ts +95 -0
  63. package/src/compute-view/deployment-view/predicates/relation-outgoing.ts +88 -0
  64. package/src/compute-view/deployment-view/predicates/wildcard.ts +29 -0
  65. package/src/compute-view/deployment-view/stages/stage-exclude.ts +5 -0
  66. package/src/compute-view/deployment-view/stages/stage-final.ts +245 -0
  67. package/src/compute-view/deployment-view/stages/stage-include.ts +95 -0
  68. package/src/compute-view/deployment-view/utils.ts +276 -0
  69. package/src/compute-view/dynamic-view/__test__/fixture.ts +58 -0
  70. package/src/compute-view/dynamic-view/compute.ts +324 -0
  71. package/src/compute-view/element-view/__test__/TestHelper.ts +258 -0
  72. package/src/compute-view/element-view/__test__/__snapshots__/legacy.spec.ts.snap +458 -0
  73. package/src/compute-view/element-view/__test__/fixture.ts +675 -0
  74. package/src/compute-view/element-view/_types.ts +48 -0
  75. package/src/compute-view/element-view/clean-connections.ts +113 -0
  76. package/src/compute-view/element-view/compute.ts +315 -0
  77. package/src/compute-view/element-view/memory/NodeGroup.ts +31 -0
  78. package/src/compute-view/element-view/memory/index.ts +10 -0
  79. package/src/compute-view/element-view/memory/memory.ts +177 -0
  80. package/src/compute-view/element-view/memory/stage-exclude.ts +59 -0
  81. package/src/compute-view/element-view/memory/stage-final.ts +129 -0
  82. package/src/compute-view/element-view/memory/stage-include.ts +128 -0
  83. package/src/compute-view/element-view/predicates/_utils.ts +86 -0
  84. package/src/compute-view/element-view/predicates/element-expand.ts +33 -0
  85. package/src/compute-view/element-view/predicates/element-kind-tag.ts +26 -0
  86. package/src/compute-view/element-view/predicates/element-ref.ts +37 -0
  87. package/src/compute-view/element-view/predicates/relation-direct.ts +309 -0
  88. package/src/compute-view/element-view/predicates/relation-in-out.ts +66 -0
  89. package/src/compute-view/element-view/predicates/relation-in.ts +118 -0
  90. package/src/compute-view/element-view/predicates/relation-out.ts +116 -0
  91. package/src/compute-view/element-view/predicates/wildcard.ts +88 -0
  92. package/src/compute-view/element-view/utils.ts +59 -0
  93. package/src/compute-view/index.ts +4 -0
  94. package/src/compute-view/memory/AbstractMemory.ts +45 -0
  95. package/src/compute-view/memory/AbstractStageExclude.ts +216 -0
  96. package/src/compute-view/memory/AbstractStageInclude.ts +200 -0
  97. package/src/compute-view/memory/_types.ts +147 -0
  98. package/src/compute-view/memory/index.ts +5 -0
  99. package/src/compute-view/memory/ops.ts +43 -0
  100. package/src/compute-view/utils/__snapshots__/sortNodes.spec.ts.snap +113 -0
  101. package/src/compute-view/utils/ancestorsOfNode.ts +19 -0
  102. package/src/compute-view/utils/applyCustomElementProperties.ts +66 -0
  103. package/src/compute-view/utils/applyCustomRelationProperties.ts +41 -0
  104. package/src/compute-view/utils/applyViewRuleStyles.ts +53 -0
  105. package/src/compute-view/utils/buildComputedNodes.ts +148 -0
  106. package/src/compute-view/utils/buildElementNotations.ts +63 -0
  107. package/src/compute-view/utils/elementExpressionToPredicate.ts +50 -0
  108. package/src/compute-view/utils/link-nodes-with-edges.ts +54 -0
  109. package/src/compute-view/utils/merge-props-from-relationships.ts +128 -0
  110. package/src/compute-view/utils/relationExpressionToPredicates.ts +55 -0
  111. package/src/compute-view/utils/resolve-extended-views.ts +69 -0
  112. package/src/compute-view/utils/resolve-global-rules.ts +83 -0
  113. package/src/compute-view/utils/topological-sort.ts +256 -0
  114. package/src/compute-view/utils/uniqueTags.test.ts +42 -0
  115. package/src/compute-view/utils/uniqueTags.ts +21 -0
  116. package/src/compute-view/utils/view-hash.ts +27 -0
  117. package/src/compute-view/utils/with-readable-edges.ts +36 -0
  118. package/src/index.ts +22 -12
  119. package/src/model/DeploymentElementModel.ts +599 -0
  120. package/src/model/DeploymentModel.ts +370 -0
  121. package/src/model/ElementModel.ts +221 -0
  122. package/src/model/LikeC4Model.test-d.ts +152 -0
  123. package/src/model/LikeC4Model.ts +336 -457
  124. package/src/model/RelationModel.ts +85 -0
  125. package/src/model/__test__/fixture.ts +149 -338
  126. package/src/model/connection/Connection.ts +72 -0
  127. package/src/model/connection/deployment/DeploymentConnectionModel.ts +178 -0
  128. package/src/model/connection/deployment/find.ts +120 -0
  129. package/src/model/connection/deployment/index.ts +8 -0
  130. package/src/model/connection/index.ts +22 -0
  131. package/src/model/connection/model/ConnectionModel.ts +157 -0
  132. package/src/model/connection/model/find.ts +117 -0
  133. package/src/model/connection/model/index.ts +8 -0
  134. package/src/model/connection/ops.ts +274 -0
  135. package/src/model/guards.ts +9 -0
  136. package/src/model/index.ts +46 -2
  137. package/src/model/types.ts +112 -15
  138. package/src/model/view/EdgeModel.ts +103 -0
  139. package/src/model/view/LikeC4ViewModel.ts +226 -0
  140. package/src/model/view/NodeModel.ts +229 -0
  141. package/src/types/_common.ts +55 -1
  142. package/src/types/deployments.ts +169 -0
  143. package/src/types/element.ts +9 -5
  144. package/src/types/expression-v2.ts +172 -0
  145. package/src/types/expression.ts +17 -11
  146. package/src/types/global.ts +3 -3
  147. package/src/types/index.ts +220 -12
  148. package/src/types/model.ts +75 -12
  149. package/src/types/operators.ts +1 -1
  150. package/src/types/overview-graph.ts +2 -2
  151. package/src/types/relation.ts +18 -14
  152. package/src/types/theme.ts +0 -1
  153. package/src/types/view-notation.ts +2 -2
  154. package/src/types/view.ts +117 -41
  155. package/src/utils/{commonHead.ts → common-head.ts} +2 -0
  156. package/src/utils/const.ts +1 -0
  157. package/src/utils/fqn.ts +203 -56
  158. package/src/utils/getOrCreate.ts +42 -0
  159. package/src/utils/graphlib.ts +10 -0
  160. package/src/utils/index.ts +74 -6
  161. package/src/utils/iterable/_types.ts +5 -0
  162. package/src/utils/iterable/filter.ts +55 -0
  163. package/src/utils/iterable/flat.ts +17 -0
  164. package/src/utils/iterable/index.ts +12 -0
  165. package/src/utils/iterable/map.ts +40 -0
  166. package/src/utils/iterable/reduce.ts +24 -0
  167. package/src/utils/iterable/some.ts +36 -0
  168. package/src/utils/iterable/to.ts +19 -0
  169. package/src/utils/iterable/unique.ts +29 -0
  170. package/src/utils/object-hash.ts +3 -0
  171. package/src/utils/relations.ts +3 -64
  172. package/src/utils/set.ts +78 -0
  173. package/src/utils/string-hash.ts +16 -0
  174. package/dist/index.cjs +0 -5452
  175. package/dist/index.d.cts +0 -1053
  176. package/dist/shared/core.CoLQkcYL.d.ts +0 -734
  177. package/dist/shared/core.DIYZvpVg.cjs +0 -353
  178. package/dist/types/index.cjs +0 -70
  179. package/dist/types/index.d.cts +0 -2
  180. package/dist/types/index.mjs +0 -1
  181. package/src/builder/Builder.test-d.ts +0 -69
  182. package/src/builder/Builder.view.ts +0 -358
  183. package/src/model/LikeC4DiagramModel.ts +0 -338
  184. package/src/model/LikeC4ViewModel.ts +0 -320
@@ -1,736 +1,9 @@
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';
3
- import defu from 'defu';
4
-
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}
32
-
33
- function t(n){return typeof n=="function"}
34
-
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
- }
127
-
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
- }
212
- }
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);
235
- }
236
-
237
- function parseWhere(where) {
238
- if (t$1(where)) {
239
- const op = where;
240
- switch (true) {
241
- case op.startsWith("tag is not #"):
242
- return {
243
- tag: {
244
- neq: op.replace("tag is not #", "")
245
- }
246
- };
247
- case op.startsWith("tag is #"):
248
- return {
249
- tag: {
250
- eq: op.replace("tag is #", "")
251
- }
252
- };
253
- case op.startsWith("kind is not "):
254
- return {
255
- kind: {
256
- neq: op.replace("kind is not ", "")
257
- }
258
- };
259
- case op.startsWith("kind is "):
260
- return {
261
- kind: {
262
- eq: op.replace("kind is ", "")
263
- }
264
- };
265
- default:
266
- throw new Error(`Unknown where operator: ${where}`);
267
- }
268
- }
269
- if (where.and) {
270
- return {
271
- and: m(where.and, parseWhere)
272
- };
273
- }
274
- if (where.or) {
275
- return {
276
- or: m(where.or, parseWhere)
277
- };
278
- }
279
- if (where.not) {
280
- return {
281
- not: parseWhere(where.not)
282
- };
283
- }
284
- throw new Error(`Unknown where operator: ${where}`);
285
- }
286
- function $include(...args) {
287
- return (b) => {
288
- let expr = $expr(args[0]);
289
- const isElement = isElementPredicateExpr(expr);
290
- if (args.length === 2) {
291
- const condition = args[1].where ? parseWhere(args[1].where) : void 0;
292
- if (condition) {
293
- expr = {
294
- where: {
295
- expr,
296
- condition
297
- }
298
- };
299
- }
300
- const custom = args[1].with;
301
- if (custom) {
302
- if (isElement) {
303
- expr = {
304
- custom: {
305
- ...custom,
306
- expr
307
- }
308
- };
309
- } else {
310
- expr = {
311
- customRelation: {
312
- ...custom,
313
- relation: expr
314
- }
315
- };
316
- }
317
- }
318
- }
319
- b.include(expr);
320
- return b;
321
- };
322
- }
323
- function $exclude(...args) {
324
- return (b) => {
325
- let expr = $expr(args[0]);
326
- if (args.length === 2 && args[1].where) {
327
- const condition = parseWhere(args[1].where);
328
- expr = {
329
- where: {
330
- expr,
331
- condition
332
- }
333
- };
334
- }
335
- b.exclude(expr);
336
- return b;
337
- };
338
- }
339
- function $expr(expr) {
340
- if (!t$1(expr)) {
341
- return expr;
342
- }
343
- if (expr === "*") {
344
- return { wildcard: true };
345
- }
346
- if (expr.startsWith("->")) {
347
- if (expr.endsWith("->")) {
348
- return {
349
- inout: $expr(expr.replace(/->/g, "").trim())
350
- };
351
- }
352
- return {
353
- incoming: $expr(expr.replace("-> ", ""))
354
- };
355
- }
356
- if (expr.endsWith(" ->")) {
357
- return {
358
- outgoing: $expr(expr.replace(" ->", ""))
359
- };
360
- }
361
- if (expr.includes(" <-> ")) {
362
- const [source, target] = expr.split(" <-> ");
363
- return {
364
- source: $expr(source),
365
- target: $expr(target),
366
- isBidirectional: true
367
- };
368
- }
369
- if (expr.includes(" -> ")) {
370
- const [source, target] = expr.split(" -> ");
371
- return {
372
- source: $expr(source),
373
- target: $expr(target)
374
- };
375
- }
376
- if (expr.endsWith("._")) {
377
- return {
378
- expanded: expr.replace("._", "")
379
- };
380
- }
381
- if (expr.endsWith(".*")) {
382
- return {
383
- element: expr.replace(".*", ""),
384
- isDescedants: true
385
- };
386
- }
387
- return {
388
- element: expr,
389
- isDescedants: false
390
- };
391
- }
392
- function $style(element, { notation, ...style }) {
393
- return (b) => b.style({
394
- targets: (o$5(element) ? element : [element]).map((e) => $expr(e)),
395
- ...notation ? { notation } : {},
396
- style: {
397
- ...style
398
- }
399
- });
400
- }
401
- function $autoLayout(layout) {
402
- return (b) => b.autoLayout(layout);
403
- }
404
- function $rules(...rules) {
405
- return (b) => rules.reduce((b2, rule) => rule(b2), b);
406
- }
407
-
408
- function builder(spec, _elements = /* @__PURE__ */ new Map(), _relations = [], _views = /* @__PURE__ */ new Map(), _globals = {
409
- predicates: {},
410
- dynamicPredicates: {},
411
- styles: {}
412
- }) {
413
- const toLikeC4Specification = () => ({
414
- tags: spec.tags ?? [],
415
- elements: {
416
- ...spec.elements
417
- },
418
- relationships: {
419
- ...spec.relationships
420
- }
421
- });
422
- const mapLinks = (links) => {
423
- if (!links || !i$3(links, 1)) {
424
- return null;
425
- }
426
- return m(links, (l) => typeof l === "string" ? { url: l } : l);
427
- };
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
- const self = {
464
- get Types() {
465
- throw new Error("Types are not available in runtime");
466
- },
467
- clone: () => builder(
468
- structuredClone(spec),
469
- structuredClone(_elements),
470
- structuredClone(_relations),
471
- structuredClone(_views),
472
- structuredClone(_globals)
473
- ),
474
- __model: () => ({
475
- addElement: (element) => {
476
- const parent = parentFqn(element.id);
477
- if (parent) {
478
- invariant(
479
- _elements.get(parent),
480
- `Parent element with id "${parent}" not found for element with id "${element.id}"`
481
- );
482
- }
483
- if (_elements.has(element.id)) {
484
- throw new Error(`Element with id "${element.id}" already exists`);
485
- }
486
- _elements.set(element.id, element);
487
- return self;
488
- },
489
- addRelation(relation) {
490
- const sourceEl = _elements.get(relation.source);
491
- invariant(sourceEl, `Element with id "${relation.source}" not found`);
492
- const targetEl = _elements.get(relation.target);
493
- invariant(targetEl, `Element with id "${relation.target}" not found`);
494
- invariant(
495
- !isSameHierarchy(sourceEl, targetEl),
496
- "Cannot create relationship between elements in the same hierarchy"
497
- );
498
- _relations.push({
499
- id: `rel${_relations.length + 1}`,
500
- ...relation
501
- });
502
- return self;
503
- },
504
- /**
505
- * Fully qualified name for nested elements
506
- */
507
- fqn(id) {
508
- return id;
509
- },
510
- addSourcelessRelation() {
511
- throw new Error("Can be called only in nested model");
512
- }
513
- }),
514
- __views: () => ({
515
- addView: (view) => {
516
- if (isScopedElementView(view)) {
517
- invariant(_elements.get(view.viewOf), `Invalid view ${view.id}, wlement with id "${view.viewOf}" not found`);
518
- }
519
- _views.set(view.id, view);
520
- return self;
521
- }
522
- }),
523
- build: () => ({
524
- specification: toLikeC4Specification(),
525
- elements: n(Array.from(_elements.entries())),
526
- relations: l$1(_relations, (r) => [r.id, r]),
527
- globals: structuredClone(_globals),
528
- views: n(Array.from(_views.entries()))
529
- }),
530
- helpers: () => ({
531
- model: {
532
- model: (...ops) => {
533
- return (b) => {
534
- const v = b.__model();
535
- for (const op of ops) {
536
- op(v);
537
- }
538
- return b;
539
- };
540
- },
541
- rel: (source, target, _props) => {
542
- return (b) => {
543
- const {
544
- title = "",
545
- links: _links = [],
546
- ...props
547
- } = defu(
548
- typeof _props === "string" ? { title: _props } : { ..._props },
549
- { title: null, links: null }
550
- );
551
- const links = mapLinks(_links);
552
- b.addRelation({
553
- source,
554
- target,
555
- title,
556
- ...links && { links },
557
- ...props
558
- });
559
- return b;
560
- };
561
- },
562
- relTo: (target, _props) => {
563
- return (b) => {
564
- const {
565
- title = "",
566
- links: _links = [],
567
- ...props
568
- } = defu(
569
- typeof _props === "string" ? { title: _props } : { ..._props },
570
- { title: null, links: null }
571
- );
572
- const links = mapLinks(_links);
573
- b.addSourcelessRelation({
574
- target,
575
- title,
576
- ...links && { links },
577
- ...props
578
- });
579
- return b;
580
- };
581
- },
582
- ...i(
583
- spec.elements,
584
- ({ style: specStyle, ...spec2 }, kind) => (id, _props) => {
585
- const add = (b) => {
586
- const {
587
- links: _links,
588
- icon: _icon,
589
- style,
590
- title,
591
- ...props
592
- } = typeof _props === "string" ? { title: _props } : { ..._props };
593
- const links = mapLinks(_links);
594
- const icon = _icon ?? specStyle?.icon;
595
- const _id = b.fqn(id);
596
- b.addElement({
597
- id: _id,
598
- kind,
599
- title: title ?? nameFromFqn(_id),
600
- description: null,
601
- technology: null,
602
- tags: null,
603
- color: specStyle?.color ?? DefaultThemeColor,
604
- shape: specStyle?.shape ?? DefaultElementShape,
605
- style: d$1({
606
- border: specStyle?.border,
607
- opacity: specStyle?.opacity,
608
- ...style
609
- }, l),
610
- links,
611
- ...icon && { icon },
612
- ...spec2,
613
- ...props
614
- });
615
- return b;
616
- };
617
- add.with = (...ops) => (b) => {
618
- add(b);
619
- const nestedBuilder = {
620
- ...b,
621
- fqn: (child) => `${b.fqn(id)}.${child}`,
622
- addSourcelessRelation: (relation) => {
623
- return b.addRelation({
624
- ...relation,
625
- source: b.fqn(id)
626
- });
627
- }
628
- };
629
- for (const op of ops) {
630
- op(nestedBuilder);
631
- }
632
- return b;
633
- };
634
- return add;
635
- }
636
- )
637
- },
638
- views: {
639
- views: (...ops) => {
640
- return (b) => {
641
- const v = b.__views();
642
- for (const op of ops) {
643
- op(v);
644
- }
645
- return b;
646
- };
647
- },
648
- view: (id, _props, builder2) => {
649
- if (t(_props)) {
650
- builder2 = _props;
651
- _props = {};
652
- }
653
- return (b) => {
654
- const {
655
- links: _links = [],
656
- title = null,
657
- ...props
658
- } = typeof _props === "string" ? { title: _props } : { ..._props };
659
- const links = mapLinks(_links);
660
- const view = {
661
- id,
662
- __: "element",
663
- title,
664
- description: null,
665
- tags: null,
666
- rules: [],
667
- links,
668
- customColorDefinitions: {},
669
- ...props
670
- };
671
- b.addView(view);
672
- if (builder2) {
673
- builder2(mkViewBuilder(view));
674
- }
675
- return b;
676
- };
677
- },
678
- viewOf: (id, viewOf, _props, builder2) => {
679
- if (t(_props)) {
680
- builder2 = _props;
681
- _props = {};
682
- }
683
- return (b) => {
684
- const {
685
- links: _links = [],
686
- title = null,
687
- ...props
688
- } = typeof _props === "string" ? { title: _props } : { ..._props };
689
- const links = mapLinks(_links);
690
- const view = {
691
- id,
692
- __: "element",
693
- viewOf,
694
- title,
695
- description: null,
696
- tags: null,
697
- rules: [],
698
- links,
699
- customColorDefinitions: {},
700
- ...props
701
- };
702
- b.addView(view);
703
- if (builder2) {
704
- builder2(mkViewBuilder(view));
705
- }
706
- return b;
707
- };
708
- },
709
- $autoLayout,
710
- $exclude,
711
- $expr,
712
- $include,
713
- $rules,
714
- $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 = {}));
1
+ export { i as invariant, a as nonNullable, n as nonexhaustive } from './shared/chunk-RAAYCPUM.M-JWF7SS.js';
2
+ export { A as AsFqn, B as BorderStyles, Q as ComputedNode, S as ComputedView, N as DefaultArrowType, e as DefaultElementShape, O as DefaultLineStyle, P as DefaultRelationshipColor, d as DefaultThemeColor, D as DeploymentElement, T as DiagramNode, E as ElementKind, g as ElementShapes, f as Expr, C as ExpressionV2, F as FqnExpr, G as FqnRef, R as RelationExpr, U as extractStep, V as getBBoxCenter, W as getParallelStepsPrefix, H as isAndOperator, X as isAutoLayoutDirection, h as isCustomElement, j as isCustomRelationExpr, Y as isDeploymentView, Z as isDynamicView, _ as isDynamicViewParallelSteps, k as isElement, l as isElementKindExpr, b as isElementPredicateExpr, m as isElementRef, p as isElementTagExpr, a as isElementView, q as isElementWhere, r as isExpandedElementExpr, i as isExtendsElementView, t as isInOut, s as isIncoming, I as isKindEqual, J as isNotOperator, K as isOrOperator, u as isOutgoing, v as isRelation, w as isRelationExpression, x as isRelationPredicateExpr, y as isRelationWhere, c as isScopedElementView, $ as isStepEdgeId, L as isTagEqual, a0 as isViewRuleAutoLayout, a1 as isViewRuleGlobalPredicateRef, a2 as isViewRuleGlobalStyle, a3 as isViewRuleGroup, a4 as isViewRulePredicate, a5 as isViewRuleStyle, z as isWildcard, a6 as stepEdgeId, M as whereOperatorAsPredicate } from './shared/view.CyZrG8BJ.js';
3
+ export { b as LikeC4DeploymentModel, L as LikeC4Model, e as LikeC4ViewModel } from './shared/index.-BdzdI2C.js';
4
+ export { isThemeColor } from './types/index.js';
5
+ export { D as DefaultMap, e as ancestorsFqn, f as commonAncestor, c as commonHead, g as compareByFqnHierarchically, h as compareFqnHierarchically, d as compareNatural, H as difference, I as equalsSet, v as getOrCreate, i as hasAtLeast, j as hierarchyDistance, k as hierarchyLevel, y as ifilter, z as iflat, A as imap, J as intersection, o as isAncestor, q as isDescendantOf, B as isIterable, w as isNonEmptyArray, a as isSameHierarchy, x as isString, C as isome, E as iunique, n as nameFromFqn, N as objectHash, p as parentFqn, s as sortByFqnHierarchically, r as sortNaturalByFqn, u as sortParentsFirst, M as stringHash, K as symmetricDifference, F as toArray, G as toSet, L as union } from './shared/object_hash.CE_oF3I3.js';
6
+ export { LinkedList, compareRelations, delay, ireduce } from './utils/index.js';
734
7
 
735
8
  const { min: min$4, max: max$4 } = Math;
736
9
 
@@ -4396,958 +3669,4 @@ function computeColorValues(color) {
4396
3669
  }
4397
3670
  }
4398
3671
 
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 };
3672
+ export { ElementColors, RelationshipColors, computeColorValues, defaultTheme };