@likec4/core 1.48.0 → 1.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/THIRD-PARTY-LICENSES.md +1012 -0
- package/dist/_chunks/Builder.view-element.mjs +2 -3284
- package/dist/_chunks/LikeC4Model.d.mts +21 -25
- package/dist/_chunks/RichText.mjs +1 -148
- package/dist/_chunks/_types.d.mts +1 -5
- package/dist/_chunks/_types2.d.mts +2 -4
- package/dist/_chunks/assignTagColors.mjs +1 -24
- package/dist/_chunks/calcDriftsFromSnapshot.mjs +1 -379
- package/dist/_chunks/guards.d.mts +2026 -0
- package/dist/_chunks/guards.mjs +4 -0
- package/dist/_chunks/index.d.mts +255 -136
- package/dist/_chunks/libs/@mantine/colors-generator.mjs +2 -3403
- package/dist/_chunks/libs/@radix-ui/colors.mjs +1 -0
- package/dist/_chunks/libs/@ungap/structured-clone.mjs +1 -213
- package/dist/_chunks/libs/bail.mjs +1 -14
- package/dist/_chunks/libs/ccount.mjs +1 -25
- package/dist/_chunks/libs/character-entities-html4.mjs +1 -263
- package/dist/_chunks/libs/character-entities-legacy.mjs +1 -117
- package/dist/_chunks/libs/character-entities.mjs +2 -2136
- package/dist/_chunks/libs/comma-separated-tokens.mjs +1 -18
- package/dist/_chunks/libs/decode-named-character-reference.mjs +1 -21
- package/dist/_chunks/libs/defu.mjs +1 -42
- package/dist/_chunks/libs/devlop.mjs +1 -5
- package/dist/_chunks/libs/escape-string-regexp.mjs +1 -8
- package/dist/_chunks/libs/extend.mjs +1 -77
- package/dist/_chunks/libs/graphology-dag.mjs +1 -703
- package/dist/_chunks/libs/graphology.mjs +1 -4565
- package/dist/_chunks/libs/hast-util-sanitize.mjs +1 -863
- package/dist/_chunks/libs/hast-util-to-html.mjs +9 -2696
- package/dist/_chunks/libs/is-plain-obj.mjs +1 -9
- package/dist/_chunks/libs/longest-streak.mjs +1 -30
- package/dist/_chunks/libs/markdown-table.mjs +2 -290
- package/dist/_chunks/libs/mdast-util-find-and-replace.mjs +1 -653
- package/dist/_chunks/libs/mdast-util-from-markdown.mjs +3 -8522
- package/dist/_chunks/libs/mdast-util-gfm.mjs +15 -2393
- package/dist/_chunks/libs/mdast-util-to-hast.mjs +11 -1803
- package/dist/_chunks/libs/micromark-extension-gfm.mjs +1 -2243
- package/dist/_chunks/libs/mnemonist.d.mts +1 -91
- package/dist/_chunks/libs/mnemonist.mjs +1 -1978
- package/dist/_chunks/libs/natural-compare-lite.mjs +9 -42
- package/dist/_chunks/libs/ohash.mjs +1 -0
- package/dist/_chunks/libs/rehype-sanitize.mjs +1 -29
- package/dist/_chunks/libs/rehype-stringify.mjs +1 -34
- package/dist/_chunks/libs/remark-gfm.mjs +1 -36
- package/dist/_chunks/libs/remark-github-blockquote-alert.mjs +3 -100
- package/dist/_chunks/libs/remark-parse.mjs +1 -39
- package/dist/_chunks/libs/remark-rehype.mjs +1 -171
- package/dist/_chunks/libs/remeda.mjs +1 -702
- package/dist/_chunks/libs/trough.mjs +1 -158
- package/dist/_chunks/libs/unified.mjs +1 -2212
- package/dist/_chunks/rolldown-runtime.mjs +1 -42
- package/dist/_chunks/{index3.d.mts → theme.d.mts} +15 -13
- package/dist/_chunks/{index7.d.mts → to-text.d.mts} +165 -29
- package/dist/_chunks/to-text.mjs +1 -0
- package/dist/_chunks/vector.d.mts +198 -0
- package/dist/_chunks/vector.mjs +1 -0
- package/dist/builder/index.d.mts +2 -8
- package/dist/builder/index.mjs +1 -662
- package/dist/compute-view/index.d.mts +86 -15
- package/dist/compute-view/index.mjs +2 -262
- package/dist/geometry/index.d.mts +2 -2
- package/dist/geometry/index.mjs +1 -3
- package/dist/index.d.mts +9 -13
- package/dist/index.mjs +1 -27
- package/dist/model/index.d.mts +4 -14
- package/dist/model/index.mjs +1 -11
- package/dist/styles/index.d.mts +2 -8
- package/dist/styles/index.mjs +1 -30
- package/dist/types/index.d.mts +3 -9
- package/dist/types/index.mjs +1 -15
- package/dist/utils/graphology/index.d.mts +1 -1
- package/dist/utils/graphology/index.mjs +1 -3
- package/dist/utils/index.d.mts +4 -11
- package/dist/utils/index.mjs +1 -17
- package/package.json +13 -12
- package/dist/_chunks/LikeC4Styles.mjs +0 -691
- package/dist/_chunks/RichText.d.mts +0 -84
- package/dist/_chunks/_aux.d.mts +0 -289
- package/dist/_chunks/_aux.mjs +0 -18
- package/dist/_chunks/connection.mjs +0 -0
- package/dist/_chunks/const.d.mts +0 -43
- package/dist/_chunks/const.mjs +0 -33
- package/dist/_chunks/expression-model.d.mts +0 -192
- package/dist/_chunks/expression-model.mjs +0 -103
- package/dist/_chunks/expression.d.mts +0 -347
- package/dist/_chunks/expression.mjs +0 -107
- package/dist/_chunks/find.d.mts +0 -82
- package/dist/_chunks/find.mjs +0 -646
- package/dist/_chunks/find2.d.mts +0 -78
- package/dist/_chunks/find2.mjs +0 -287
- package/dist/_chunks/fqnRef.d.mts +0 -58
- package/dist/_chunks/fqnRef.mjs +0 -41
- package/dist/_chunks/geometry.mjs +0 -335
- package/dist/_chunks/index2.d.mts +0 -937
- package/dist/_chunks/index4.d.mts +0 -62
- package/dist/_chunks/index5.d.mts +0 -42
- package/dist/_chunks/index6.d.mts +0 -43
- package/dist/_chunks/index8.d.mts +0 -144
- package/dist/_chunks/invariant.mjs +0 -18
- package/dist/_chunks/iterable.mjs +0 -146
- package/dist/_chunks/libs/graphology-types.d.mts +0 -601
- package/dist/_chunks/libs/graphology.d.mts +0 -6
- package/dist/_chunks/mnemonist.d.mts +0 -1
- package/dist/_chunks/mnemonist.mjs +0 -0
- package/dist/_chunks/model.mjs +0 -1898
- package/dist/_chunks/model2.mjs +0 -0
- package/dist/_chunks/relationships-view.mjs +0 -132
- package/dist/_chunks/scalar.d.mts +0 -109
- package/dist/_chunks/scalar.mjs +0 -84
- package/dist/_chunks/utils.mjs +0 -483
- package/dist/compute-view/relationships-view/index.d.mts +0 -16
- package/dist/compute-view/relationships-view/index.mjs +0 -7
- package/dist/model/connection/deployment/index.d.mts +0 -12
- package/dist/model/connection/deployment/index.mjs +0 -9
- package/dist/model/connection/index.d.mts +0 -14
- package/dist/model/connection/index.mjs +0 -10
- package/dist/model/connection/model/index.d.mts +0 -12
- package/dist/model/connection/model/index.mjs +0 -8
- package/dist/types/RichText.d.mts +0 -3
- package/dist/types/RichText.mjs +0 -7
- package/dist/types/_aux.d.mts +0 -3
- package/dist/types/_aux.mjs +0 -3
- package/dist/types/expression-model.d.mts +0 -6
- package/dist/types/expression-model.mjs +0 -7
- package/dist/types/expression.d.mts +0 -5
- package/dist/types/expression.mjs +0 -7
- package/dist/types/fqnRef.d.mts +0 -4
- package/dist/types/fqnRef.mjs +0 -7
- package/dist/types/scalar.d.mts +0 -2
- package/dist/types/scalar.mjs +0 -7
- package/dist/utils/iterable/index.d.mts +0 -9
- package/dist/utils/iterable/index.mjs +0 -3
- package/dist/utils/mnemonist.d.mts +0 -2
- package/dist/utils/mnemonist.mjs +0 -12
|
@@ -1,379 +1 @@
|
|
|
1
|
-
import
|
|
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 };
|
|
1
|
+
import{C as t$2,H as t$1,K as t$6,M as e$1,O as e$3,Q as t$9,T as t$4,V as t$8,X as t$5,Y as n,_ as t$10,c as t$7,et as t,h as t$3,i as n$1,j as e$2,m as e}from"./libs/remeda.mjs";import{g as isElementView,h as isDynamicView,ht as _layout}from"./RichText.mjs";import{D as ifilter,Q as invariant,S as ihead,l as symmetricDifference}from"./to-text.mjs";import{castDraft,produce}from"immer";function buildElementNotations(o){return t(o,n(r=>!!r.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(([r,i])=>({kinds:i,color:r})))),t$5(),t$6(([r,i])=>i.map(({color:i,kinds:a})=>({shape:r,color:i,kinds:a}))))),t$5(),t$6(([r,i])=>i.map(({shape:i,color:a,kinds:o})=>({title:r,shape:i,color:a,kinds:o}))),t$7(e(`shape`),e(`title`),[r=>r.kinds.length,`desc`]))}const changed=(r,i)=>r===i||e$1(r)&&e$1(i)?!1:!t$8(r,i);function autoApplyMetaAndStyles(r,i){r.color=i.color,r.kind=i.kind,r.navigateTo=i.navigateTo??null,r.links=i.links?[...i.links]:null,r.tags=[...i.tags],e$1(i.style.border)?delete r.style.border:r.style.border=i.style.border,e$2(i.style.opacity)?r.style.opacity=i.style.opacity:delete r.style.opacity,e$1(i.style.multiple)?delete r.style.multiple:r.style.multiple=i.style.multiple}function autoApplyIcon(r,i,a){if(changed(i.icon??`none`,r.icon??`none`)){let c=e$3(r.icon)&&r.icon!==`none`;switch(!0){case c&&e$3(i.icon)&&i.icon!==`none`:return r.icon=i.icon,!0;case c&&(e$1(i.icon)||i.icon===`none`):return r.icon=`none`,!0;case!c&&e$3(i.icon)&&i.icon!==`none`:return a?(r.icon=i.icon,!0):!1}}return!0}function autoApplyIconStyles(r,i,a){let s=!0;return changed(r.style.iconColor,i.style.iconColor)&&(e$1(i.style.iconColor)?delete r.style.iconColor:r.style.iconColor=i.style.iconColor),changed(r.style.iconSize,i.style.iconSize)&&(a?e$1(i.style.iconSize)?delete r.style.iconSize:r.style.iconSize=i.style.iconSize:s=!1),changed(r.style.iconPosition,i.style.iconPosition)&&(a?e$1(i.style.iconPosition)?delete r.style.iconPosition:r.style.iconPosition=i.style.iconPosition:s=!1),s}function patchMarkdownOrString(r,i){return r?`md`in i?(r.md=i.md,delete r.txt,r):(`txt`in i&&(r.txt=i.txt,delete r.md),r):i}function autoApplyLabelsToLeaf(r,i,a){let s=!0;return changed(r.title,i.title)&&(a?r.title=i.title:s=!1),changed(r.description,i.description)&&(e$1(i.description)?delete r.description:a?r.description=patchMarkdownOrString(r.description,i.description):s=!1),changed(r.technology,i.technology)&&(e$1(i.technology)?delete r.technology:a?r.technology=i.technology:s=!1),s}function autoApplyLabelsToCompound(r,i,a){return r.title=i.title,e$1(i.description)?delete r.description:r.description=patchMarkdownOrString(r.description,i.description),e$1(i.technology)?delete r.technology:r.technology=i.technology,!0}function applyManualLayout(r,i){invariant(r.id===i.id,`applyManualLayout: view ids do not match`),invariant(r._stage===`layouted`,`applyManualLayout: expected layouted view`),invariant(i._stage===`layouted`,`applyManualLayout: expected layouted snapshot`),invariant(r._layout!==`manual`,`applyManualLayout: expected auto-layouted view`);let a=new Set;r._type!==i._type&&a.add(`type-changed`);let o=applyNodesManualLayout(i.nodes,r.nodes,a),s=applyEdgesManualLayout(i.edges,r.edges,a),l=buildElementNotations(o);return produce(i,u=>{u.title=r.title??i.title,u.description=r.description??i.description,u.tags=r.tags?[...r.tags]:null,u.links=r.links?[...r.links]:null,u.sourcePath=r.sourcePath,u[_layout]=`manual`,l&&l.length>0?u.notation={nodes:l}:delete u.notation,u.nodes=castDraft(o),u.edges=castDraft(s),isDynamicView(r)&&u._type===`dynamic`&&(u.variant=r.variant),isElementView(r)&&u._type===`element`&&(r.viewOf?u.viewOf=r.viewOf:delete u.viewOf,r.extends?u.extends=r.extends:delete u.extends);let d=[...a];t$9(d,1)?u.drifts=d:(u.hash=r.hash,delete u.drifts)})}function applyNodesManualLayout(r,i,a){let s=new Map(i.map(r=>[r.id,r])),l=r.map(r=>{let i=s.get(r.id);return i?(s.delete(i.id),produce(r,s=>{autoApplyMetaAndStyles(s,i);let l=new Set,u=r.children.length>0,d=i.children.length>0;(changed(s.modelRef,i.modelRef)||changed(s.deploymentRef,i.deploymentRef))&&l.add(`modelRef-changed`),d&&!u&&l.add(`became-compound`),!d&&u&&l.add(`became-leaf`),changed(s.parent,i.parent)&&l.add(`parent-changed`);let f=s.width+5>=i.width&&s.height+5>=i.height;changed(s.shape,i.shape)&&(f?s.shape=i.shape:l.add(`shape-changed`)),autoApplyIconStyles(s,i,f)||l.add(`label-changed`),autoApplyIcon(s,i,f&&d===u)||l.add(`label-changed`),(u?autoApplyLabelsToCompound:autoApplyLabelsToLeaf)(s,i,f)||l.add(`label-changed`),changed(s.notes,i.notes)&&(e$1(i.notes)?delete s.notes:s.notes=patchMarkdownOrString(s.notes,i.notes)),changed(r.notation,i.notation)&&(s.notation=i.notation??null),u&&d&&symmetricDifference(new Set(r.children),new Set(i.children)).size>0&&l.add(`children-changed`);let p=[...l];t$9(p,1)?(a.add(`nodes-drift`),s.drifts=p):delete s.drifts})):(a.add(`nodes-removed`),{...r,drifts:[`removed`]})});return s.size>0&&a.add(`nodes-added`),l}function applyEdgesManualLayout(r,i,a){let s=new Map(i.map(r=>[r.id,r])),l=r.map(r=>{let i=s.get(r.id)??t(s.values(),ifilter(i=>i.source===r.source&&i.target===r.target),ihead());return i&&s.delete(i.id),produce(r,s=>{if(!i){s.drifts=[`removed`],a.add(`edges-removed`);return}let l=new Set,u=r.id===i.id;switch(!0){case u&&r.source==i.source&&r.target==i.target:changed(s.dir??`forward`,i.dir??`forward`)&&l.add(`direction-changed`);break;case u&&r.source==i.target&&r.target==i.source:r.source!==r.target&&l.add(`direction-changed`);break;case u:r.source!=i.source&&l.add(`source-changed`),r.target!=i.target&&l.add(`target-changed`);break;default:invariant(r.id!=i.id,`Unexpected case in edge drift detection, ids should not match`),invariant(r.source==i.source,`Unexpected case in edge drift detection, sources should match`),invariant(r.target==i.target,`Unexpected case in edge drift detection, targets should match`),changed(s.dir??`forward`,i.dir??`forward`)&&l.add(`direction-changed`);break}if(s.color=i.color,s.line=i.line,s.navigateTo=i.navigateTo??null,s.tags=i.tags?[...i.tags]:null,changed(r.notes,i.notes)&&(e$1(r.notes)!==e$1(i.notes)&&l.add(`notes-changed`),s.notes=i.notes??r.notes),i.astPath?s.astPath=i.astPath:delete s.astPath,changed(t$10(r,[`label`,`description`,`technology`,`labelBBox`]),t$10(i,[`label`,`description`,`technology`,`labelBBox`])))switch(!0){case i.labelBBox&&!r.labelBBox:l.add(`label-added`);break;case r.labelBBox&&!i.labelBBox:l.add(`label-removed`);break;case!!r.labelBBox&&!!i.labelBBox:i.labelBBox.width*i.labelBBox.height>(r.labelBBox.width+5)*(r.labelBBox.height+5)&&(s.labelBBox.width=Math.round(i.labelBBox.width),s.labelBBox.height=Math.round(i.labelBBox.height)),changed(r.label,i.label)&&(e$1(i.label)!==e$1(r.label)&&l.add(`label-changed`),s.label=i.label??r.label),changed(r.description,i.description)&&(e$1(i.description)!==e$1(r.description)&&l.add(`label-changed`),i.description&&(s.description=patchMarkdownOrString(r.description,i.description))),changed(r.technology,i.technology)&&(e$1(i.technology)!==e$1(r.technology)&&l.add(`label-changed`),s.technology=i.technology??r.technology??null);break;default:invariant(!r.labelBBox,`Unexpected case in edge labelBBox drift detection`),invariant(!i.labelBBox,`Unexpected case in next labelBBox drift detection`);break}let d=[...l];t$9(d,1)?(a.add(`edges-drift`),s.drifts=d):delete s.drifts})});return s.size>0&&a.add(`edges-added`),l}function calcDriftsFromSnapshot(r,i){let{drifts:a,...o}=applyManualLayout(r,i);if(!a||a.length===0)return produce(r,r=>{delete r.drifts,r[_layout]=`auto`});let s=new Set;a.includes(`type-changed`)&&s.add(`type-changed`);let l=new Map(o.nodes.map(r=>[r.id,r])),u=new Map(o.edges.map(r=>[r.id,r])),d=r.nodes.map(r=>{let i=l.get(r.id);return i&&l.delete(i.id),produce(r,r=>{if(!i){s.add(`nodes-added`),r.drifts=[`added`];return}i.drifts?(s.add(`nodes-drift`),r.drifts=[...i.drifts]):delete r.drifts})});l.size>0&&s.add(`nodes-removed`);let f=r.edges.map(r=>{let i=u.get(r.id)??t(u.values(),ifilter(i=>i.source===r.source&&i.target===r.target),ihead());return i&&u.delete(i.id),produce(r,r=>{if(!i){s.add(`edges-added`),r.drifts=[`added`];return}i.drifts?(s.add(`edges-drift`),r.drifts=[...i.drifts]):delete r.drifts})});u.size>0&&s.add(`edges-removed`);let p=[...s];return produce(r,r=>{t$9(p,1)?r.drifts=p:delete r.drifts,r.nodes=castDraft(d),r.edges=castDraft(f),r[_layout]=`auto`})}export{applyManualLayout as n,buildElementNotations as r,calcDriftsFromSnapshot as t};
|