@likec4/core 1.47.0 → 1.48.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 (181) hide show
  1. package/LICENSE +1 -1
  2. package/dist/_chunks/Builder.view-element.mjs +3284 -0
  3. package/dist/_chunks/LikeC4Model.d.mts +1287 -0
  4. package/dist/_chunks/LikeC4Styles.mjs +691 -0
  5. package/dist/_chunks/RichText.d.mts +84 -0
  6. package/dist/_chunks/RichText.mjs +148 -0
  7. package/dist/_chunks/_aux.d.mts +289 -0
  8. package/dist/_chunks/_aux.mjs +18 -0
  9. package/dist/_chunks/_types.d.mts +781 -0
  10. package/dist/_chunks/_types2.d.mts +38 -0
  11. package/dist/_chunks/assignTagColors.mjs +24 -0
  12. package/dist/_chunks/calcDriftsFromSnapshot.mjs +379 -0
  13. package/dist/_chunks/connection.mjs +0 -0
  14. package/dist/_chunks/const.d.mts +43 -0
  15. package/dist/_chunks/const.mjs +33 -0
  16. package/dist/_chunks/expression-model.d.mts +192 -0
  17. package/dist/_chunks/expression-model.mjs +103 -0
  18. package/dist/_chunks/expression.d.mts +347 -0
  19. package/dist/_chunks/expression.mjs +107 -0
  20. package/dist/_chunks/find.d.mts +82 -0
  21. package/dist/_chunks/find.mjs +646 -0
  22. package/dist/_chunks/find2.d.mts +78 -0
  23. package/dist/_chunks/find2.mjs +287 -0
  24. package/dist/_chunks/fqnRef.d.mts +58 -0
  25. package/dist/_chunks/fqnRef.mjs +41 -0
  26. package/dist/_chunks/geometry.mjs +335 -0
  27. package/dist/_chunks/index.d.mts +169 -0
  28. package/dist/_chunks/index2.d.mts +937 -0
  29. package/dist/_chunks/index3.d.mts +146 -0
  30. package/dist/_chunks/index4.d.mts +62 -0
  31. package/dist/_chunks/index5.d.mts +42 -0
  32. package/dist/_chunks/index6.d.mts +43 -0
  33. package/dist/{shared/core.OtRNdMxy.d.mts → _chunks/index7.d.mts} +113 -197
  34. package/dist/_chunks/index8.d.mts +144 -0
  35. package/dist/_chunks/invariant.mjs +18 -0
  36. package/dist/_chunks/iterable.mjs +146 -0
  37. package/dist/_chunks/libs/@mantine/colors-generator.mjs +3416 -0
  38. package/dist/_chunks/libs/@ungap/structured-clone.mjs +213 -0
  39. package/dist/_chunks/libs/bail.mjs +14 -0
  40. package/dist/_chunks/libs/ccount.mjs +25 -0
  41. package/dist/_chunks/libs/character-entities-html4.mjs +263 -0
  42. package/dist/_chunks/libs/character-entities-legacy.mjs +117 -0
  43. package/dist/_chunks/libs/character-entities.mjs +2136 -0
  44. package/dist/_chunks/libs/comma-separated-tokens.mjs +18 -0
  45. package/dist/_chunks/libs/decode-named-character-reference.mjs +21 -0
  46. package/dist/_chunks/libs/defu.mjs +42 -0
  47. package/dist/_chunks/libs/devlop.mjs +5 -0
  48. package/dist/_chunks/libs/escape-string-regexp.mjs +8 -0
  49. package/dist/_chunks/libs/extend.mjs +77 -0
  50. package/dist/_chunks/libs/graphology-dag.mjs +703 -0
  51. package/dist/_chunks/libs/graphology-types.d.mts +601 -0
  52. package/dist/_chunks/libs/graphology.d.mts +6 -0
  53. package/dist/_chunks/libs/graphology.mjs +4565 -0
  54. package/dist/_chunks/libs/hast-util-sanitize.mjs +863 -0
  55. package/dist/_chunks/libs/hast-util-to-html.mjs +2696 -0
  56. package/dist/_chunks/libs/is-plain-obj.mjs +9 -0
  57. package/dist/_chunks/libs/longest-streak.mjs +30 -0
  58. package/dist/_chunks/libs/markdown-table.mjs +290 -0
  59. package/dist/_chunks/libs/mdast-util-find-and-replace.mjs +653 -0
  60. package/dist/_chunks/libs/mdast-util-from-markdown.mjs +8522 -0
  61. package/dist/_chunks/libs/mdast-util-gfm.mjs +2393 -0
  62. package/dist/_chunks/libs/mdast-util-to-hast.mjs +1803 -0
  63. package/dist/_chunks/libs/micromark-extension-gfm.mjs +2243 -0
  64. package/dist/_chunks/libs/mnemonist.d.mts +254 -0
  65. package/dist/_chunks/libs/mnemonist.mjs +1978 -0
  66. package/dist/_chunks/libs/natural-compare-lite.mjs +42 -0
  67. package/dist/_chunks/libs/rehype-sanitize.mjs +29 -0
  68. package/dist/_chunks/libs/rehype-stringify.mjs +34 -0
  69. package/dist/_chunks/libs/remark-gfm.mjs +36 -0
  70. package/dist/_chunks/libs/remark-github-blockquote-alert.mjs +100 -0
  71. package/dist/_chunks/libs/remark-parse.mjs +39 -0
  72. package/dist/_chunks/libs/remark-rehype.mjs +171 -0
  73. package/dist/_chunks/libs/remeda.mjs +702 -0
  74. package/dist/_chunks/libs/trough.mjs +158 -0
  75. package/dist/_chunks/libs/unified.mjs +2212 -0
  76. package/dist/_chunks/mnemonist.d.mts +1 -0
  77. package/dist/_chunks/mnemonist.mjs +0 -0
  78. package/dist/_chunks/model.mjs +1898 -0
  79. package/dist/_chunks/model2.mjs +0 -0
  80. package/dist/_chunks/relationships-view.mjs +132 -0
  81. package/dist/_chunks/rolldown-runtime.mjs +42 -0
  82. package/dist/{shared/core.C_3y3eqV.d.mts → _chunks/scalar.d.mts} +13 -43
  83. package/dist/_chunks/scalar.mjs +84 -0
  84. package/dist/_chunks/utils.mjs +483 -0
  85. package/dist/builder/index.d.mts +11 -775
  86. package/dist/builder/index.mjs +631 -1022
  87. package/dist/compute-view/index.d.mts +85 -56
  88. package/dist/compute-view/index.mjs +247 -214
  89. package/dist/compute-view/relationships-view/index.d.mts +16 -51
  90. package/dist/compute-view/relationships-view/index.mjs +6 -184
  91. package/dist/geometry/index.d.mts +2 -109
  92. package/dist/geometry/index.mjs +2 -327
  93. package/dist/index.d.mts +18 -20
  94. package/dist/index.mjs +27 -18
  95. package/dist/model/connection/deployment/index.d.mts +12 -15
  96. package/dist/model/connection/deployment/index.mjs +9 -2
  97. package/dist/model/connection/index.d.mts +14 -75
  98. package/dist/model/connection/index.mjs +10 -3
  99. package/dist/model/connection/model/index.d.mts +12 -15
  100. package/dist/model/connection/model/index.mjs +8 -2
  101. package/dist/model/index.d.mts +15 -57
  102. package/dist/model/index.mjs +11 -4
  103. package/dist/styles/index.d.mts +9 -117
  104. package/dist/styles/index.mjs +26 -59
  105. package/dist/types/RichText.d.mts +3 -0
  106. package/dist/types/RichText.mjs +7 -0
  107. package/dist/types/_aux.d.mts +3 -4
  108. package/dist/types/_aux.mjs +2 -7
  109. package/dist/types/expression-model.d.mts +6 -190
  110. package/dist/types/expression-model.mjs +6 -108
  111. package/dist/types/expression.d.mts +5 -6
  112. package/dist/types/expression.mjs +6 -112
  113. package/dist/types/fqnRef.d.mts +4 -60
  114. package/dist/types/fqnRef.mjs +6 -44
  115. package/dist/types/index.d.mts +9 -47
  116. package/dist/types/index.mjs +14 -16
  117. package/dist/types/scalar.d.mts +2 -2
  118. package/dist/types/scalar.mjs +7 -4
  119. package/dist/utils/graphology/index.d.mts +2 -1864
  120. package/dist/utils/graphology/index.mjs +3 -1
  121. package/dist/utils/index.d.mts +11 -124
  122. package/dist/utils/index.mjs +16 -43
  123. package/dist/utils/iterable/index.d.mts +9 -132
  124. package/dist/utils/iterable/index.mjs +2 -61
  125. package/dist/utils/mnemonist.d.mts +2 -0
  126. package/dist/utils/mnemonist.mjs +12 -0
  127. package/package.json +17 -22
  128. package/compute-view/relationships/package.json +0 -4
  129. package/dist/shared/core.3ZhnKAlZ.mjs +0 -106
  130. package/dist/shared/core.78IWAHAE.mjs +0 -332
  131. package/dist/shared/core.B85MJLTf.mjs +0 -5
  132. package/dist/shared/core.BFd1lU9R.mjs +0 -29
  133. package/dist/shared/core.BKlholso.mjs +0 -3
  134. package/dist/shared/core.BNN-3vPH.mjs +0 -1255
  135. package/dist/shared/core.BPGOjone.d.mts +0 -46
  136. package/dist/shared/core.BP_QHEXs.mjs +0 -785
  137. package/dist/shared/core.BbE4y-yl.mjs +0 -177
  138. package/dist/shared/core.Bdy3hhTc.mjs +0 -28382
  139. package/dist/shared/core.BfCKSW-g.d.mts +0 -1266
  140. package/dist/shared/core.BhNcrwzK.mjs +0 -7
  141. package/dist/shared/core.BkVA6gjl.mjs +0 -5
  142. package/dist/shared/core.BoYfZOBm.mjs +0 -3
  143. package/dist/shared/core.BsSXS-_R.mjs +0 -7
  144. package/dist/shared/core.C3JowhaZ.mjs +0 -32
  145. package/dist/shared/core.C4x8aaWa.mjs +0 -27
  146. package/dist/shared/core.CAgYpDtM.d.mts +0 -98
  147. package/dist/shared/core.CHf8VEa3.mjs +0 -1206
  148. package/dist/shared/core.CLSZtnFh.mjs +0 -69
  149. package/dist/shared/core.CbT8JVYL.mjs +0 -5
  150. package/dist/shared/core.CdNCAwq7.mjs +0 -176
  151. package/dist/shared/core.CmGY9blO.mjs +0 -6717
  152. package/dist/shared/core.CmPXpJ8l.mjs +0 -21
  153. package/dist/shared/core.Coi_LOUZ.mjs +0 -7
  154. package/dist/shared/core.CqAJJpK_.mjs +0 -3
  155. package/dist/shared/core.CywrQs86.d.mts +0 -31
  156. package/dist/shared/core.D00YbOhQ.d.mts +0 -300
  157. package/dist/shared/core.D0WZutNd.mjs +0 -94
  158. package/dist/shared/core.D4npX2q8.mjs +0 -18
  159. package/dist/shared/core.DB0Ue5Wx.d.mts +0 -70
  160. package/dist/shared/core.DC5IAaDT.d.mts +0 -334
  161. package/dist/shared/core.DE9qzhn8.d.mts +0 -83
  162. package/dist/shared/core.DGcIbsj4.mjs +0 -3946
  163. package/dist/shared/core.DH7TXqXf.mjs +0 -136
  164. package/dist/shared/core.DKhRkHRN.d.mts +0 -41
  165. package/dist/shared/core.DRJma0Ol.mjs +0 -22
  166. package/dist/shared/core.DU5SRqNF.mjs +0 -2209
  167. package/dist/shared/core.DXhDWKFZ.d.mts +0 -3
  168. package/dist/shared/core.DbfO90vF.mjs +0 -434
  169. package/dist/shared/core.DcS-0zys.mjs +0 -10
  170. package/dist/shared/core.Dh119QSP.mjs +0 -4995
  171. package/dist/shared/core.DjcWextK.mjs +0 -1371
  172. package/dist/shared/core.Dojz4bvg.d.mts +0 -504
  173. package/dist/shared/core.FZ305VYd.mjs +0 -21
  174. package/dist/shared/core.RfnaEmgA.mjs +0 -7
  175. package/dist/shared/core.btEq3i3f.mjs +0 -300
  176. package/dist/shared/core.oSV6SRfk.mjs +0 -13
  177. package/dist/shared/core.om36dXXW.mjs +0 -41
  178. package/dist/shared/core.osFs8tU7.d.mts +0 -466
  179. package/dist/shared/core.q10OP9oJ.mjs +0 -5
  180. package/dist/shared/core.tpvDGvdC.d.mts +0 -87
  181. package/dist/shared/core.uFk_o9X6.mjs +0 -13
@@ -0,0 +1,38 @@
1
+ import { ht as _type, mt as _stage } from "./_aux.mjs";
2
+ import { h as ProjectId } from "./scalar.mjs";
3
+ import { i as BBox } from "./index.mjs";
4
+ import { I as DiagramEdge, J as ComputedEdge, L as DiagramNode, X as ComputedNode, on as ViewAutoLayout, rn as BaseViewProperties } from "./index2.mjs";
5
+
6
+ //#region src/compute-view/projects-view/_types.d.ts
7
+ interface ComputedProjectNode extends ComputedNode {
8
+ readonly projectId: ProjectId;
9
+ }
10
+ interface ComputedProjectEdge extends ComputedEdge {
11
+ readonly projectId: ProjectId;
12
+ }
13
+ interface LayoutedProjectNode extends DiagramNode {
14
+ readonly projectId: ProjectId;
15
+ }
16
+ interface LayoutedProjectEdge extends DiagramEdge {
17
+ readonly projectId: ProjectId;
18
+ }
19
+ /**
20
+ * An overview of projects and their relationships, presented as a graph with nodes and edges.
21
+ * Even though it has same structure as other likec4 views, it is not mixed with them, as it represents a different kind.
22
+ */
23
+ interface ComputedProjectsView extends BaseViewProperties<any> {
24
+ readonly [_type]: 'projects';
25
+ readonly [_stage]: 'computed';
26
+ readonly nodes: ReadonlyArray<ComputedProjectNode>;
27
+ readonly edges: ReadonlyArray<ComputedProjectEdge>;
28
+ readonly autoLayout: ViewAutoLayout;
29
+ }
30
+ interface LayoutedProjectsView extends BaseViewProperties<any> {
31
+ readonly [_type]: 'projects';
32
+ readonly [_stage]: 'layouted';
33
+ readonly nodes: ReadonlyArray<LayoutedProjectNode>;
34
+ readonly edges: ReadonlyArray<LayoutedProjectEdge>;
35
+ readonly bounds: BBox;
36
+ }
37
+ //#endregion
38
+ export { LayoutedProjectNode as a, LayoutedProjectEdge as i, ComputedProjectNode as n, LayoutedProjectsView as o, ComputedProjectsView as r, ComputedProjectEdge as t };
@@ -0,0 +1,24 @@
1
+ import { D as e, Q as t$1, Y as t, et as t$4, l as t$2, m as e$1, p as t$5, w as t$3 } from "./libs/remeda.mjs";
2
+ import { V as DefaultTagColors } from "./LikeC4Styles.mjs";
3
+ import { I as compareNatural } from "./utils.mjs";
4
+ import { n as nonNullable } from "./invariant.mjs";
5
+
6
+ //#region src/styles/assignTagColors.ts
7
+ function assignTagColors(tags) {
8
+ const tagsWithColors = [];
9
+ const tagsWithoutColors = [];
10
+ for (const [tag, spec] of t(tags)) if (e(spec.color)) tagsWithColors.push({
11
+ tag,
12
+ spec: { color: spec.color }
13
+ });
14
+ else tagsWithoutColors.push(tag);
15
+ return t$1(tagsWithoutColors, t$2(compareNatural), t$3((tag, idx) => {
16
+ return {
17
+ tag,
18
+ spec: { color: nonNullable(DefaultTagColors[idx % DefaultTagColors.length]) }
19
+ };
20
+ }), t$4(tagsWithColors), t$2((a, b) => compareNatural(a.tag, b.tag)), t$5(e$1("tag"), e$1("spec")));
21
+ }
22
+
23
+ //#endregion
24
+ export { assignTagColors as t };
@@ -0,0 +1,379 @@
1
+ import { A as e$2, B as t$8, D as e$3, G as t$6, J as n, Q as t, S as t$2, V as t$1, Y as t$5, Z as t$9, _ as t$10, c as t$7, h as t$3, i as n$1, j as e$1, m as e, w as t$4 } from "./libs/remeda.mjs";
2
+ import { M as _layout, g as isElementView, h as isDynamicView } from "./LikeC4Styles.mjs";
3
+ import { l as symmetricDifference } from "./utils.mjs";
4
+ import { t as invariant } from "./invariant.mjs";
5
+ import { f as ifilter, s as ihead } from "./iterable.mjs";
6
+ import { castDraft, produce } from "immer";
7
+
8
+ //#region src/compute-view/utils/buildElementNotations.ts
9
+ /**
10
+ * Build element notations from computed nodes:
11
+ * 1. Group by notation
12
+ * 2. Group by shape
13
+ * 3. Group by color
14
+ * 4. For each group get unique kinds
15
+ * 5. Unwind the groups
16
+ */
17
+ function buildElementNotations(nodes) {
18
+ return t(nodes, n((n) => !!n.notation), t$1(e("notation")), t$2(t$3(t$1(e("shape")), t$2(t$3(t$1(e("color")), t$2(t$3(t$4(e("kind")), n$1())), t$5(), t$4(([color, kinds]) => ({
19
+ kinds,
20
+ color
21
+ })))), t$5(), t$6(([shape, colors]) => colors.map(({ color, kinds }) => ({
22
+ shape,
23
+ color,
24
+ kinds
25
+ }))))), t$5(), t$6(([title, shapes]) => shapes.map(({ shape, color, kinds }) => ({
26
+ title,
27
+ shape,
28
+ color,
29
+ kinds
30
+ }))), t$7(e("shape"), e("title"), [(n) => n.kinds.length, "desc"]));
31
+ }
32
+
33
+ //#endregion
34
+ //#region src/manual-layout/applyManualLayout.ts
35
+ const changed = (a, b) => {
36
+ if (a === b || e$1(a) && e$1(b)) return false;
37
+ return !t$8(a, b);
38
+ };
39
+ /**
40
+ * Maximum allowed drift per coordinate (top, left, bottom, right)
41
+ */
42
+ const MAX_ALLOWED_DRIFT = 5;
43
+ /**
44
+ * 'Safely' applies non-drifting properties from `next` to `draft`.
45
+ * Used to auto-apply certain properties that are not considered drifting.
46
+ */
47
+ function autoApplyMetaAndStyles(draft, next) {
48
+ draft.color = next.color;
49
+ draft.kind = next.kind;
50
+ draft.navigateTo = next.navigateTo ?? null;
51
+ draft.links = next.links ? [...next.links] : null;
52
+ draft.tags = [...next.tags];
53
+ if (e$1(next.style.border)) delete draft.style.border;
54
+ else draft.style.border = next.style.border;
55
+ if (e$2(next.style.opacity)) draft.style.opacity = next.style.opacity;
56
+ else delete draft.style.opacity;
57
+ if (e$1(next.style.multiple)) delete draft.style.multiple;
58
+ else draft.style.multiple = next.style.multiple;
59
+ }
60
+ /**
61
+ * Auto-applies icon changes according to the rules:
62
+ * - If icon was set before and changed, auto-apply
63
+ * - If icon was set before and now removed, auto-apply
64
+ * - If icon was added, only auto-apply if size not changed
65
+ * @returns true if icon was auto-applied, false otherwise
66
+ */
67
+ function autoApplyIcon(draft, next, sizeNotChanged) {
68
+ if (changed(next.icon ?? "none", draft.icon ?? "none")) {
69
+ const iconWasSet = e$3(draft.icon) && draft.icon !== "none";
70
+ switch (true) {
71
+ case iconWasSet && e$3(next.icon) && next.icon !== "none":
72
+ draft.icon = next.icon;
73
+ return true;
74
+ case iconWasSet && (e$1(next.icon) || next.icon === "none"):
75
+ draft.icon = "none";
76
+ return true;
77
+ case !iconWasSet && e$3(next.icon) && next.icon !== "none": if (sizeNotChanged) {
78
+ draft.icon = next.icon;
79
+ return true;
80
+ } else return false;
81
+ }
82
+ }
83
+ return true;
84
+ }
85
+ /**
86
+ * Auto-applies icon style changes according to the rules:
87
+ * - iconColor is always auto-applied
88
+ * - iconSize/iconPosition are auto-applied only if size not changed
89
+ * @returns true if icon style changes were auto-applied, false otherwise
90
+ */
91
+ function autoApplyIconStyles(draft, next, sizeNotChanged) {
92
+ let applied = true;
93
+ if (changed(draft.style.iconColor, next.style.iconColor)) if (e$1(next.style.iconColor)) delete draft.style.iconColor;
94
+ else draft.style.iconColor = next.style.iconColor;
95
+ if (changed(draft.style.iconSize, next.style.iconSize)) if (sizeNotChanged) if (e$1(next.style.iconSize)) delete draft.style.iconSize;
96
+ else draft.style.iconSize = next.style.iconSize;
97
+ else applied = false;
98
+ if (changed(draft.style.iconPosition, next.style.iconPosition)) if (sizeNotChanged) if (e$1(next.style.iconPosition)) delete draft.style.iconPosition;
99
+ else draft.style.iconPosition = next.style.iconPosition;
100
+ else applied = false;
101
+ return applied;
102
+ }
103
+ function patchMarkdownOrString(draft, next) {
104
+ if (!draft) return next;
105
+ if ("md" in next) {
106
+ draft.md = next.md;
107
+ delete draft.txt;
108
+ return draft;
109
+ }
110
+ if ("txt" in next) {
111
+ draft.txt = next.txt;
112
+ delete draft.md;
113
+ }
114
+ return draft;
115
+ }
116
+ /**
117
+ * Auto-applies title, description, technology to leaf node
118
+ * @returns true if all labels were auto-applied, false otherwise
119
+ */
120
+ function autoApplyLabelsToLeaf(draft, next, sizeNotChanged) {
121
+ let applied = true;
122
+ if (changed(draft.title, next.title)) if (sizeNotChanged) draft.title = next.title;
123
+ else applied = false;
124
+ if (changed(draft.description, next.description)) if (e$1(next.description)) delete draft.description;
125
+ else if (sizeNotChanged) draft.description = patchMarkdownOrString(draft.description, next.description);
126
+ else applied = false;
127
+ if (changed(draft.technology, next.technology)) if (e$1(next.technology)) delete draft.technology;
128
+ else if (sizeNotChanged) draft.technology = next.technology;
129
+ else applied = false;
130
+ return applied;
131
+ }
132
+ /**
133
+ * Auto-applies title, description, technology to compound node
134
+ * Currently always updates properties
135
+ */
136
+ function autoApplyLabelsToCompound(draft, next, _sizeNotChanged) {
137
+ draft.title = next.title;
138
+ if (e$1(next.description)) delete draft.description;
139
+ else draft.description = patchMarkdownOrString(draft.description, next.description);
140
+ if (e$1(next.technology)) delete draft.technology;
141
+ else draft.technology = next.technology;
142
+ return true;
143
+ }
144
+ /**
145
+ * Proof-of-concept
146
+ * Use layout from the snapshot, and 'safe'-apply style properties from the `autoLayouted` view
147
+ *
148
+ * @param autoLayouted Auto-layouted view
149
+ * @param snapshot The view snapshot with manual-layout
150
+ * @returns The snapshot with the next view applied
151
+ */
152
+ function applyManualLayout(autoLayouted, snapshot) {
153
+ invariant(autoLayouted.id === snapshot.id, "applyManualLayout: view ids do not match");
154
+ invariant(autoLayouted._stage === "layouted", "applyManualLayout: expected layouted view");
155
+ invariant(snapshot._stage === "layouted", "applyManualLayout: expected layouted snapshot");
156
+ invariant(autoLayouted._layout !== "manual", "applyManualLayout: expected auto-layouted view");
157
+ const viewDrifts = /* @__PURE__ */ new Set();
158
+ if (autoLayouted._type !== snapshot._type) viewDrifts.add("type-changed");
159
+ const nodes = applyNodesManualLayout(snapshot.nodes, autoLayouted.nodes, viewDrifts);
160
+ const edges = applyEdgesManualLayout(snapshot.edges, autoLayouted.edges, viewDrifts);
161
+ const nodeNotations = buildElementNotations(nodes);
162
+ return produce(snapshot, (draft) => {
163
+ draft.title = autoLayouted.title ?? snapshot.title;
164
+ draft.description = autoLayouted.description ?? snapshot.description;
165
+ draft.tags = autoLayouted.tags ? [...autoLayouted.tags] : null;
166
+ draft.links = autoLayouted.links ? [...autoLayouted.links] : null;
167
+ draft.sourcePath = autoLayouted.sourcePath;
168
+ draft[_layout] = "manual";
169
+ if (nodeNotations && nodeNotations.length > 0) draft.notation = { nodes: nodeNotations };
170
+ else delete draft.notation;
171
+ draft.nodes = castDraft(nodes);
172
+ draft.edges = castDraft(edges);
173
+ if (isDynamicView(autoLayouted) && draft._type === "dynamic") draft.variant = autoLayouted.variant;
174
+ if (isElementView(autoLayouted) && draft._type === "element") {
175
+ if (autoLayouted.viewOf) draft.viewOf = autoLayouted.viewOf;
176
+ else delete draft.viewOf;
177
+ if (autoLayouted.extends) draft.extends = autoLayouted.extends;
178
+ else delete draft.extends;
179
+ }
180
+ const drifts = [...viewDrifts];
181
+ if (t$9(drifts, 1)) draft.drifts = drifts;
182
+ else {
183
+ draft.hash = autoLayouted.hash;
184
+ delete draft.drifts;
185
+ }
186
+ });
187
+ }
188
+ function applyNodesManualLayout(snapshotNodes, latestNodes, viewDrifts) {
189
+ const nextNodes = new Map(latestNodes.map((n) => [n.id, n]));
190
+ const nodes = snapshotNodes.map((node) => {
191
+ const next = nextNodes.get(node.id);
192
+ if (!next) {
193
+ viewDrifts.add("nodes-removed");
194
+ return {
195
+ ...node,
196
+ drifts: ["removed"]
197
+ };
198
+ }
199
+ nextNodes.delete(next.id);
200
+ return produce(node, (draft) => {
201
+ autoApplyMetaAndStyles(draft, next);
202
+ const nodeDrifts = /* @__PURE__ */ new Set();
203
+ const wasCompound = node.children.length > 0;
204
+ const willBeCompound = next.children.length > 0;
205
+ if (changed(draft.modelRef, next.modelRef) || changed(draft.deploymentRef, next.deploymentRef)) nodeDrifts.add("modelRef-changed");
206
+ if (willBeCompound && !wasCompound) nodeDrifts.add("became-compound");
207
+ if (!willBeCompound && wasCompound) nodeDrifts.add("became-leaf");
208
+ if (changed(draft.parent, next.parent)) nodeDrifts.add("parent-changed");
209
+ const sizeNotChanged = draft.width + MAX_ALLOWED_DRIFT >= next.width && draft.height + MAX_ALLOWED_DRIFT >= next.height;
210
+ if (changed(draft.shape, next.shape)) if (sizeNotChanged) draft.shape = next.shape;
211
+ else nodeDrifts.add("shape-changed");
212
+ if (!autoApplyIconStyles(draft, next, sizeNotChanged)) nodeDrifts.add("label-changed");
213
+ if (!autoApplyIcon(draft, next, sizeNotChanged && willBeCompound === wasCompound)) nodeDrifts.add("label-changed");
214
+ if (!(wasCompound ? autoApplyLabelsToCompound : autoApplyLabelsToLeaf)(draft, next, sizeNotChanged)) nodeDrifts.add("label-changed");
215
+ if (changed(node.notation, next.notation)) draft.notation = next.notation ?? null;
216
+ if (wasCompound && willBeCompound && symmetricDifference(new Set(node.children), new Set(next.children)).size > 0) nodeDrifts.add("children-changed");
217
+ const _drifts = [...nodeDrifts];
218
+ if (t$9(_drifts, 1)) {
219
+ viewDrifts.add("nodes-drift");
220
+ draft.drifts = _drifts;
221
+ } else delete draft.drifts;
222
+ });
223
+ });
224
+ if (nextNodes.size > 0) viewDrifts.add("nodes-added");
225
+ return nodes;
226
+ }
227
+ function applyEdgesManualLayout(snapshotEdges, latestEdges, viewDrifts) {
228
+ const nextEdges = new Map(latestEdges.map((e) => [e.id, e]));
229
+ const edges = snapshotEdges.map((edge) => {
230
+ let next = nextEdges.get(edge.id) ?? t(nextEdges.values(), ifilter((e) => e.source === edge.source && e.target === edge.target), ihead());
231
+ if (next) nextEdges.delete(next.id);
232
+ return produce(edge, (draft) => {
233
+ if (!next) {
234
+ draft.drifts = ["removed"];
235
+ viewDrifts.add("edges-removed");
236
+ return;
237
+ }
238
+ const edgeDrifts = /* @__PURE__ */ new Set();
239
+ const isSameId = edge.id === next.id;
240
+ switch (true) {
241
+ case isSameId && edge.source == next.source && edge.target == next.target:
242
+ if (changed(draft.dir ?? "forward", next.dir ?? "forward")) edgeDrifts.add("direction-changed");
243
+ break;
244
+ case isSameId && edge.source == next.target && edge.target == next.source:
245
+ if (edge.source !== edge.target) edgeDrifts.add("direction-changed");
246
+ break;
247
+ case isSameId:
248
+ if (edge.source != next.source) edgeDrifts.add("source-changed");
249
+ if (edge.target != next.target) edgeDrifts.add("target-changed");
250
+ break;
251
+ default:
252
+ invariant(edge.id != next.id, "Unexpected case in edge drift detection, ids should not match");
253
+ invariant(edge.source == next.source, "Unexpected case in edge drift detection, sources should match");
254
+ invariant(edge.target == next.target, "Unexpected case in edge drift detection, targets should match");
255
+ if (changed(draft.dir ?? "forward", next.dir ?? "forward")) edgeDrifts.add("direction-changed");
256
+ break;
257
+ }
258
+ draft.color = next.color;
259
+ draft.line = next.line;
260
+ draft.navigateTo = next.navigateTo ?? null;
261
+ draft.tags = next.tags ? [...next.tags] : null;
262
+ if (changed(edge.notes, next.notes)) {
263
+ if (e$1(edge.notes) !== e$1(next.notes)) edgeDrifts.add("notes-changed");
264
+ draft.notes = next.notes ?? edge.notes;
265
+ }
266
+ if (next.astPath) draft.astPath = next.astPath;
267
+ else delete draft.astPath;
268
+ if (changed(t$10(edge, [
269
+ "label",
270
+ "description",
271
+ "technology",
272
+ "labelBBox"
273
+ ]), t$10(next, [
274
+ "label",
275
+ "description",
276
+ "technology",
277
+ "labelBBox"
278
+ ]))) switch (true) {
279
+ case next.labelBBox && !edge.labelBBox:
280
+ edgeDrifts.add("label-added");
281
+ break;
282
+ case edge.labelBBox && !next.labelBBox:
283
+ edgeDrifts.add("label-removed");
284
+ break;
285
+ case !!edge.labelBBox && !!next.labelBBox:
286
+ if (next.labelBBox.width * next.labelBBox.height > (edge.labelBBox.width + MAX_ALLOWED_DRIFT) * (edge.labelBBox.height + MAX_ALLOWED_DRIFT)) {
287
+ draft.labelBBox.width = Math.round(next.labelBBox.width);
288
+ draft.labelBBox.height = Math.round(next.labelBBox.height);
289
+ }
290
+ if (changed(edge.label, next.label)) {
291
+ if (e$1(next.label) !== e$1(edge.label)) edgeDrifts.add("label-changed");
292
+ draft.label = next.label ?? edge.label;
293
+ }
294
+ if (changed(edge.description, next.description)) {
295
+ if (e$1(next.description) !== e$1(edge.description)) edgeDrifts.add("label-changed");
296
+ if (next.description) draft.description = patchMarkdownOrString(edge.description, next.description);
297
+ }
298
+ if (changed(edge.technology, next.technology)) {
299
+ if (e$1(next.technology) !== e$1(edge.technology)) edgeDrifts.add("label-changed");
300
+ draft.technology = next.technology ?? edge.technology ?? null;
301
+ }
302
+ break;
303
+ default:
304
+ invariant(!edge.labelBBox, "Unexpected case in edge labelBBox drift detection");
305
+ invariant(!next.labelBBox, "Unexpected case in next labelBBox drift detection");
306
+ break;
307
+ }
308
+ const _drifts = [...edgeDrifts];
309
+ if (t$9(_drifts, 1)) {
310
+ viewDrifts.add("edges-drift");
311
+ draft.drifts = _drifts;
312
+ } else delete draft.drifts;
313
+ });
314
+ });
315
+ if (nextEdges.size > 0) viewDrifts.add("edges-added");
316
+ return edges;
317
+ }
318
+
319
+ //#endregion
320
+ //#region src/manual-layout/calcDriftsFromSnapshot.ts
321
+ /**
322
+ * Calculates drifts comparing latest autoLayouted with manual snapshot.
323
+ *
324
+ * @returns The autoLayouted view with calculated drifts if any.
325
+ */
326
+ function calcDriftsFromSnapshot(autoLayouted, snapshot) {
327
+ const { drifts, ...manual } = applyManualLayout(autoLayouted, snapshot);
328
+ if (!drifts || drifts.length === 0) return produce(autoLayouted, (draft) => {
329
+ delete draft.drifts;
330
+ draft[_layout] = "auto";
331
+ });
332
+ const viewDrifts = /* @__PURE__ */ new Set();
333
+ if (drifts.includes("type-changed")) viewDrifts.add("type-changed");
334
+ const manualNodes = new Map(manual.nodes.map((n) => [n.id, n]));
335
+ const manualEdges = new Map(manual.edges.map((e) => [e.id, e]));
336
+ const nodes = autoLayouted.nodes.map((node) => {
337
+ const snapshotNode = manualNodes.get(node.id);
338
+ if (snapshotNode) manualNodes.delete(snapshotNode.id);
339
+ return produce(node, (draft) => {
340
+ if (!snapshotNode) {
341
+ viewDrifts.add("nodes-added");
342
+ draft.drifts = ["added"];
343
+ return;
344
+ }
345
+ if (snapshotNode.drifts) {
346
+ viewDrifts.add("nodes-drift");
347
+ draft.drifts = [...snapshotNode.drifts];
348
+ } else delete draft.drifts;
349
+ });
350
+ });
351
+ if (manualNodes.size > 0) viewDrifts.add("nodes-removed");
352
+ const edges = autoLayouted.edges.map((edge) => {
353
+ const snapshotEdge = manualEdges.get(edge.id) ?? t(manualEdges.values(), ifilter((e) => e.source === edge.source && e.target === edge.target), ihead());
354
+ if (snapshotEdge) manualEdges.delete(snapshotEdge.id);
355
+ return produce(edge, (draft) => {
356
+ if (!snapshotEdge) {
357
+ viewDrifts.add("edges-added");
358
+ draft.drifts = ["added"];
359
+ return;
360
+ }
361
+ if (snapshotEdge.drifts) {
362
+ viewDrifts.add("edges-drift");
363
+ draft.drifts = [...snapshotEdge.drifts];
364
+ } else delete draft.drifts;
365
+ });
366
+ });
367
+ if (manualEdges.size > 0) viewDrifts.add("edges-removed");
368
+ const _viewDrifts = [...viewDrifts];
369
+ return produce(autoLayouted, (draft) => {
370
+ if (t$9(_viewDrifts, 1)) draft.drifts = _viewDrifts;
371
+ else delete draft.drifts;
372
+ draft.nodes = castDraft(nodes);
373
+ draft.edges = castDraft(edges);
374
+ draft[_layout] = "auto";
375
+ });
376
+ }
377
+
378
+ //#endregion
379
+ export { applyManualLayout as n, buildElementNotations as r, calcDriftsFromSnapshot as t };
File without changes
@@ -0,0 +1,43 @@
1
+ import { n as Any } from "./_aux.mjs";
2
+ import { s as Fqn } from "./scalar.mjs";
3
+ import { C as ElementModel, i as DeploymentElementModel } from "./LikeC4Model.mjs";
4
+
5
+ //#region src/model/connection/Connection.d.ts
6
+ interface Connection<Elem = ElementModel<Any> | DeploymentElementModel<Any>, Id = string> {
7
+ readonly id: Id;
8
+ readonly source: Elem;
9
+ readonly target: Elem;
10
+ /**
11
+ * Common ancestor of the source and target elements.
12
+ * Represents the boundary of the connection.
13
+ */
14
+ readonly boundary: Elem | null;
15
+ /**
16
+ * Human readable expression of the connection
17
+ * Mostly used for testing and debugging
18
+ */
19
+ readonly expression: string;
20
+ mergeWith(this: Connection<Elem, Id>, other: typeof this): typeof this;
21
+ nonEmpty(): boolean;
22
+ difference(this: Connection<Elem, Id>, other: typeof this): typeof this;
23
+ intersect(this: Connection<Elem, Id>, other: typeof this): typeof this;
24
+ equals(other: Connection): boolean;
25
+ }
26
+ declare namespace Connection {
27
+ type ConnectionPredicate = <C extends Connection<{
28
+ id: string;
29
+ }, any>>(connection: C) => boolean;
30
+ type ElementId = Fqn | string;
31
+ export const isInside: (fqn: ElementId) => ConnectionPredicate;
32
+ export const isDirectedBetween: (source: ElementId, target: ElementId) => ConnectionPredicate;
33
+ export const isAnyBetween: (source: ElementId, target: ElementId) => ConnectionPredicate;
34
+ export const isIncoming: (target: ElementId) => ConnectionPredicate;
35
+ export const isOutgoing: (source: ElementId) => ConnectionPredicate;
36
+ export const isAnyInOut: (source: ElementId) => ConnectionPredicate;
37
+ export {};
38
+ }
39
+ //#endregion
40
+ //#region src/utils/const.d.ts
41
+ declare const customInspectSymbol: unique symbol;
42
+ //#endregion
43
+ export { Connection as n, customInspectSymbol as t };
@@ -0,0 +1,33 @@
1
+ import { C as isAncestor } from "./utils.mjs";
2
+
3
+ //#region src/model/connection/Connection.ts
4
+ let Connection;
5
+ (function(_Connection) {
6
+ _Connection.isInside = (fqn) => {
7
+ return (connection) => isAncestor(fqn, connection.source.id) && isAncestor(fqn, connection.target.id);
8
+ };
9
+ const isDirectedBetween = _Connection.isDirectedBetween = (source, target) => {
10
+ return (connection) => (connection.source.id === source || isAncestor(source, connection.source.id)) && (connection.target.id === target || isAncestor(target, connection.target.id));
11
+ };
12
+ _Connection.isAnyBetween = (source, target) => {
13
+ const forward = isDirectedBetween(source, target), backward = isDirectedBetween(target, source);
14
+ return (connection) => forward(connection) || backward(connection);
15
+ };
16
+ const isIncoming = _Connection.isIncoming = (target) => {
17
+ return (connection) => (connection.target.id === target || isAncestor(target, connection.target.id)) && !isAncestor(target, connection.source.id);
18
+ };
19
+ const isOutgoing = _Connection.isOutgoing = (source) => {
20
+ return (connection) => (connection.source.id === source || isAncestor(source, connection.source.id)) && !isAncestor(source, connection.target.id);
21
+ };
22
+ _Connection.isAnyInOut = (source) => {
23
+ const isIn = isIncoming(source), isOut = isOutgoing(source);
24
+ return (connection) => isIn(connection) || isOut(connection);
25
+ };
26
+ })(Connection || (Connection = {}));
27
+
28
+ //#endregion
29
+ //#region src/utils/const.ts
30
+ const customInspectSymbol = Symbol.for("nodejs.util.inspect.custom");
31
+
32
+ //#endregion
33
+ export { Connection as n, customInspectSymbol as t };