@zenwave360/vistas-eventflow 0.1.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 (42) hide show
  1. package/FLOWVIEWMODEL_EXAMPLES.md +896 -0
  2. package/LICENSE +21 -0
  3. package/README.md +151 -0
  4. package/dist/EventFlowVisualizer.d.ts +25 -0
  5. package/dist/EventFlowVisualizer.d.ts.map +1 -0
  6. package/dist/ServiceMapVisualizer.d.ts +14 -0
  7. package/dist/ServiceMapVisualizer.d.ts.map +1 -0
  8. package/dist/components/CausationEdge.d.ts +8 -0
  9. package/dist/components/CausationEdge.d.ts.map +1 -0
  10. package/dist/components/CommandNode.d.ts +10 -0
  11. package/dist/components/CommandNode.d.ts.map +1 -0
  12. package/dist/components/EndNode.d.ts +10 -0
  13. package/dist/components/EndNode.d.ts.map +1 -0
  14. package/dist/components/EventNode.d.ts +10 -0
  15. package/dist/components/EventNode.d.ts.map +1 -0
  16. package/dist/components/OutcomeNode.d.ts +7 -0
  17. package/dist/components/OutcomeNode.d.ts.map +1 -0
  18. package/dist/components/PolicyNode.d.ts +16 -0
  19. package/dist/components/PolicyNode.d.ts.map +1 -0
  20. package/dist/components/ServiceGroupNode.d.ts +10 -0
  21. package/dist/components/ServiceGroupNode.d.ts.map +1 -0
  22. package/dist/components/ServiceMapNode.d.ts +8 -0
  23. package/dist/components/ServiceMapNode.d.ts.map +1 -0
  24. package/dist/components/StartNode.d.ts +10 -0
  25. package/dist/components/StartNode.d.ts.map +1 -0
  26. package/dist/components/SystemGroupNode.d.ts +7 -0
  27. package/dist/components/SystemGroupNode.d.ts.map +1 -0
  28. package/dist/index.d.ts +29 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +645 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/labelFormatting.d.ts +6 -0
  33. package/dist/labelFormatting.d.ts.map +1 -0
  34. package/dist/styles.css +1 -0
  35. package/dist/types/FlowViewModel-updated.d.ts +114 -0
  36. package/dist/types/FlowViewModel-updated.d.ts.map +1 -0
  37. package/dist/types/FlowViewModel.d.ts +124 -0
  38. package/dist/types/FlowViewModel.d.ts.map +1 -0
  39. package/dist/types/ServiceViewModel.d.ts +64 -0
  40. package/dist/types/ServiceViewModel.d.ts.map +1 -0
  41. package/event-flow-architecture-and-contracts.md +1067 -0
  42. package/package.json +54 -0
package/dist/index.js ADDED
@@ -0,0 +1,645 @@
1
+ import { jsxs as y, jsx as s, Fragment as te } from "react/jsx-runtime";
2
+ import { useMemo as x, useState as K, useRef as q, useEffect as F, useCallback as M } from "react";
3
+ import J, { Handle as O, Position as R, getBezierPath as ne, BaseEdge as ie, EdgeLabelRenderer as oe, applyNodeChanges as Q, Background as V, Controls as ee, MiniMap as se, MarkerType as re } from "reactflow";
4
+ function ce({ data: e }) {
5
+ return /* @__PURE__ */ y("div", { className: "eventflow-command-node", title: e.title, children: [
6
+ e.endOutcomeLabels && e.endOutcomeLabels.length > 0 ? /* @__PURE__ */ s("div", { className: "node-role-badge node-role-badge-end-outcome", children: e.endOutcomeLabels.join(", ") }) : null,
7
+ /* @__PURE__ */ s(O, { type: "target", position: R.Left }),
8
+ /* @__PURE__ */ s("div", { className: "node-header", children: /* @__PURE__ */ s("strong", { children: e.label }) }),
9
+ /* @__PURE__ */ s(O, { type: "source", position: R.Right })
10
+ ] });
11
+ }
12
+ function ae({ data: e }) {
13
+ return /* @__PURE__ */ y("div", { className: "eventflow-event-node", title: e.title, children: [
14
+ e.endOutcomeLabels && e.endOutcomeLabels.length > 0 ? /* @__PURE__ */ s("div", { className: "node-role-badge node-role-badge-end-outcome", children: e.endOutcomeLabels.join(", ") }) : null,
15
+ /* @__PURE__ */ s(O, { type: "target", position: R.Left }),
16
+ /* @__PURE__ */ s("div", { className: "node-header", children: /* @__PURE__ */ s("strong", { children: e.label }) }),
17
+ /* @__PURE__ */ s(O, { type: "source", position: R.Right })
18
+ ] });
19
+ }
20
+ function le({ data: e }) {
21
+ return /* @__PURE__ */ y("div", { className: "eventflow-policy-node", title: e.title, children: [
22
+ e.endOutcomeLabels && e.endOutcomeLabels.length > 0 ? /* @__PURE__ */ s("div", { className: "node-role-badge node-role-badge-end-outcome", children: e.endOutcomeLabels.join(", ") }) : null,
23
+ /* @__PURE__ */ s(O, { type: "target", position: R.Left }),
24
+ e.policyLabelParts ? /* @__PURE__ */ y("div", { className: "node-header eventflow-policy-label", children: [
25
+ /* @__PURE__ */ s("span", { className: "eventflow-policy-keyword", children: e.policyLabelParts.when }),
26
+ /* @__PURE__ */ s("strong", { className: "eventflow-policy-condition", children: e.policyLabelParts.condition }),
27
+ /* @__PURE__ */ s("span", { className: "eventflow-policy-keyword", children: e.policyLabelParts.do }),
28
+ /* @__PURE__ */ s("strong", { className: "eventflow-policy-action", children: e.policyLabelParts.action })
29
+ ] }) : /* @__PURE__ */ s("div", { className: "node-header", children: /* @__PURE__ */ s("strong", { children: e.label }) }),
30
+ /* @__PURE__ */ s(O, { type: "source", position: R.Right })
31
+ ] });
32
+ }
33
+ function de({ data: e }) {
34
+ return /* @__PURE__ */ y("div", { className: "eventflow-start-node-shell", title: e.title, children: [
35
+ /* @__PURE__ */ s("div", { className: "node-role-badge node-role-badge-start", children: "START" }),
36
+ e.endOutcomeLabels && e.endOutcomeLabels.length > 0 ? /* @__PURE__ */ s("div", { className: "node-role-badge node-role-badge-end-outcome", children: e.endOutcomeLabels.join(", ") }) : null,
37
+ /* @__PURE__ */ y("div", { className: "eventflow-start-node", children: [
38
+ /* @__PURE__ */ s("div", { className: "node-header", children: /* @__PURE__ */ s("strong", { children: e.label }) }),
39
+ /* @__PURE__ */ s(O, { type: "source", position: R.Right })
40
+ ] })
41
+ ] });
42
+ }
43
+ function ue({ data: e }) {
44
+ return /* @__PURE__ */ y("div", { className: "eventflow-end-node", title: e.title, children: [
45
+ e.endOutcomeLabels && e.endOutcomeLabels.length > 0 ? /* @__PURE__ */ s("div", { className: "node-role-badge node-role-badge-end-outcome", children: e.endOutcomeLabels.join(", ") }) : null,
46
+ /* @__PURE__ */ s(O, { type: "target", position: R.Left }),
47
+ /* @__PURE__ */ s("div", { className: "node-header", children: /* @__PURE__ */ s("strong", { children: e.label }) })
48
+ ] });
49
+ }
50
+ function he({ data: e }) {
51
+ return /* @__PURE__ */ y("div", { className: "eventflow-outcome-node", children: [
52
+ /* @__PURE__ */ s(O, { type: "target", position: R.Left }),
53
+ /* @__PURE__ */ s("div", { className: "node-header", children: e.label }),
54
+ /* @__PURE__ */ s(O, { type: "source", position: R.Right })
55
+ ] });
56
+ }
57
+ var C = /* @__PURE__ */ ((e) => (e.START = "START", e.COMMAND = "COMMAND", e.EVENT = "EVENT", e.POLICY = "POLICY", e.END = "END", e))(C || {}), b = /* @__PURE__ */ ((e) => (e.CAUSATION = "CAUSATION", e.CALL = "CALL", e.OUTCOME_HANDLER = "OUTCOME_HANDLER", e.TRIGGER = "TRIGGER", e.CONDITIONAL = "CONDITIONAL", e.ERROR = "ERROR", e))(b || {}), me = /* @__PURE__ */ ((e) => (e.LR = "LR", e.TB = "TB", e))(me || {});
58
+ function je(e) {
59
+ return {
60
+ schema: "zfl.eventflow.view@1",
61
+ layout: null,
62
+ bounds: null,
63
+ systemGroups: null,
64
+ ...e
65
+ };
66
+ }
67
+ function pe(e) {
68
+ return e === b.ERROR ? "#dc2626" : e === b.CALL ? "#2563eb" : e === b.OUTCOME_HANDLER ? "#ea580c" : e === b.TRIGGER ? "#7c3aed" : e === b.CONDITIONAL ? "#0f766e" : "#64748b";
69
+ }
70
+ function fe(e) {
71
+ if (e === b.CALL) return "14 8";
72
+ if (e === b.OUTCOME_HANDLER) return "3 6";
73
+ if (e === b.TRIGGER) return "6 4";
74
+ if (e === b.CONDITIONAL) return "10 6";
75
+ if (e === b.ERROR) return "3 3";
76
+ }
77
+ function ge(e) {
78
+ const [i, n, o] = ne(e), r = e.data?.edgeType, u = pe(r), l = fe(r);
79
+ return /* @__PURE__ */ y(te, { children: [
80
+ /* @__PURE__ */ s(
81
+ ie,
82
+ {
83
+ id: e.id,
84
+ path: i,
85
+ markerEnd: e.markerEnd,
86
+ style: {
87
+ stroke: u,
88
+ strokeWidth: 2.5,
89
+ strokeDasharray: l
90
+ }
91
+ }
92
+ ),
93
+ e.label && /* @__PURE__ */ s(oe, { children: /* @__PURE__ */ s(
94
+ "div",
95
+ {
96
+ className: "eventflow-edge-label",
97
+ style: {
98
+ transform: `translate(-50%, -50%) translate(${n}px,${o}px)`
99
+ },
100
+ children: e.label
101
+ }
102
+ ) })
103
+ ] });
104
+ }
105
+ function Ne(e) {
106
+ return e.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/[_-]+/g, " ").replace(/\s+/g, " ").trim();
107
+ }
108
+ function I(e) {
109
+ return e.split(":").map((i) => Ne(i)).join(": ");
110
+ }
111
+ function Ye(e) {
112
+ return e.split(`
113
+ `).map((i) => I(i)).join(`
114
+ `);
115
+ }
116
+ const U = 180, X = 112, j = 32, be = 72, ve = 180, $ = 24;
117
+ function ye(e) {
118
+ const i = e.dimensions?.width ?? U, n = e.dimensions?.height ?? X;
119
+ return {
120
+ width: Math.max(i, U),
121
+ height: Math.max(n, X)
122
+ };
123
+ }
124
+ function Ee(e, i) {
125
+ const n = e.position ?? { x: 0, y: 0 }, o = e.dimensions;
126
+ return o ? {
127
+ x: n.x - (i.width - o.width) / 2,
128
+ y: n.y - (i.height - o.height) / 2
129
+ } : n;
130
+ }
131
+ function Le(e) {
132
+ switch (e) {
133
+ case C.START:
134
+ return "startNode";
135
+ case C.COMMAND:
136
+ return "commandNode";
137
+ case C.EVENT:
138
+ return "eventNode";
139
+ case C.POLICY:
140
+ return "policyNode";
141
+ case C.END:
142
+ return "endNode";
143
+ default:
144
+ return "eventNode";
145
+ }
146
+ }
147
+ function Oe(e) {
148
+ return e === "startNode" ? "#22c55e" : e === "commandNode" ? "#3b82f6" : e === "eventNode" ? "#f97316" : e === "policyNode" ? "#a855f7" : e === "endNode" ? "#ef4444" : e === "outcomeNode" ? "#e2e8f0" : "#cbd5e1";
149
+ }
150
+ function Re(e) {
151
+ return e === b.CALL ? "#2563eb" : e === b.OUTCOME_HANDLER ? "#ea580c" : e === b.ERROR ? "#dc2626" : "#64748b";
152
+ }
153
+ function xe(e, i) {
154
+ return [e, i].filter(Boolean).join(" / ") || void 0;
155
+ }
156
+ function Ce(e) {
157
+ const i = e.match(/^\s*(when)\s+(.+?)\s+(do)\s+(.+)\s*$/i);
158
+ if (i)
159
+ return {
160
+ when: i[1].toLowerCase(),
161
+ condition: i[2],
162
+ do: i[3].toLowerCase(),
163
+ action: i[4]
164
+ };
165
+ }
166
+ function Ie(e) {
167
+ return e.endOutcome ?? e.endOutcomeLabels;
168
+ }
169
+ function Me(e, i, n) {
170
+ const o = [], r = i?.humanizeLabels ?? !0;
171
+ return { nodes: e.nodes.flatMap((l) => {
172
+ if (!l.position || !l.dimensions)
173
+ return o.push(l.id), [];
174
+ const t = ye(l), h = r ? I(l.label) : l.label, c = Ie(l)?.filter((a) => a != null && a.trim().length > 0).map((a) => r ? I(a) : a);
175
+ return [{
176
+ id: l.id,
177
+ type: Le(l.type),
178
+ position: Ee(l, t),
179
+ className: n?.has(l.id) ? "eventflow-node-highlighted" : void 0,
180
+ data: {
181
+ label: h,
182
+ endOutcomeLabels: c,
183
+ sourceRef: l.sourceRef,
184
+ title: xe(l.system, l.service),
185
+ policyLabelParts: l.type === C.POLICY ? Ce(h) : void 0
186
+ },
187
+ style: {
188
+ width: t.width,
189
+ height: t.height
190
+ }
191
+ }];
192
+ }), missingLayoutNodeIds: o };
193
+ }
194
+ function k(e, i) {
195
+ const n = e.style, o = typeof n?.width == "number" ? n.width : i?.width ?? null, r = typeof n?.height == "number" ? n.height : i?.height ?? null;
196
+ return o === null || r === null ? null : { width: o, height: r };
197
+ }
198
+ function Y(e, i) {
199
+ const n = k(e, i);
200
+ return n ? {
201
+ x: e.position.x + n.width / 2,
202
+ y: e.position.y + n.height / 2
203
+ } : null;
204
+ }
205
+ function we(e) {
206
+ return Math.min(Math.max(e.length * 7 + 24, be), ve);
207
+ }
208
+ function H(e, i, n, o, r, u) {
209
+ return {
210
+ id: e,
211
+ source: i,
212
+ target: n,
213
+ type: "causationEdge",
214
+ label: r || void 0,
215
+ data: {
216
+ edgeType: o,
217
+ sourceRef: u ?? void 0
218
+ },
219
+ markerEnd: {
220
+ type: re.ArrowClosed,
221
+ width: 18,
222
+ height: 18,
223
+ color: Re(o)
224
+ }
225
+ };
226
+ }
227
+ function De(e, i, n) {
228
+ const o = new Map(i.map((a) => [a.id, a])), r = new Map(e.nodes.map((a) => [a.id, a])), u = n?.humanizeLabels ?? !0, l = /* @__PURE__ */ new Map();
229
+ e.edges.forEach((a) => {
230
+ const d = a.outcome?.trim();
231
+ if (!d || !o.has(a.source) || !o.has(a.target) || r.get(a.source)?.type !== C.COMMAND)
232
+ return;
233
+ const f = `${a.source}::${d}`, E = l.get(f);
234
+ if (E) {
235
+ E.push(a);
236
+ return;
237
+ }
238
+ l.set(f, [a]);
239
+ });
240
+ const t = [], h = [], c = /* @__PURE__ */ new Set();
241
+ return l.forEach((a, d) => {
242
+ if (a.length < 2)
243
+ return;
244
+ const f = o.get(a[0].source);
245
+ if (!f)
246
+ return;
247
+ const E = Y(f, null);
248
+ if (!E)
249
+ return;
250
+ const w = a.map((p) => o.get(p.target)).filter((p) => !!p);
251
+ if (w.length < 2)
252
+ return;
253
+ const v = w.map((p) => Y(p, null)).filter((p) => !!p);
254
+ if (v.length < 2)
255
+ return;
256
+ const D = a[0].outcome.trim(), T = u ? I(D) : D, A = we(T), S = v.reduce((p, W) => p + W.x, 0) / v.length, B = v.reduce((p, W) => p + W.y, 0) / v.length, _ = k(f, null), G = Math.min(...w.map((p) => p.position.x)), g = _ ? f.position.x + _.width + $ : f.position.x + $, N = G - A - $;
257
+ let L = (E.x + S) / 2 - A / 2;
258
+ N >= g && (L = Math.min(Math.max(L, g), N));
259
+ const m = `synthetic:outcome:${d}`, z = {
260
+ id: m,
261
+ type: "outcomeNode",
262
+ position: {
263
+ x: L,
264
+ y: B - j / 2
265
+ },
266
+ draggable: !1,
267
+ selectable: !1,
268
+ connectable: !1,
269
+ data: {
270
+ label: T,
271
+ synthetic: !0
272
+ },
273
+ style: {
274
+ width: A,
275
+ height: j
276
+ }
277
+ };
278
+ t.push(z), h.push(
279
+ H(
280
+ `${m}:in`,
281
+ a[0].source,
282
+ m,
283
+ a[0].type,
284
+ void 0,
285
+ a[0].sourceRef
286
+ )
287
+ ), a.forEach((p) => {
288
+ c.add(p.id), h.push(
289
+ H(
290
+ `${m}:${p.id}`,
291
+ m,
292
+ p.target,
293
+ p.type,
294
+ void 0,
295
+ p.sourceRef
296
+ )
297
+ );
298
+ });
299
+ }), {
300
+ nodes: t,
301
+ edges: h,
302
+ groupedEdgeIds: c
303
+ };
304
+ }
305
+ function Ae(e, i) {
306
+ const n = e.filter((t) => t.position && t.dimensions);
307
+ if (n.length === 0)
308
+ return i;
309
+ const o = Math.min(...n.map((t) => t.position.x)), r = Math.min(...n.map((t) => t.position.y)), u = Math.max(...n.map((t) => t.position.x + t.dimensions.width)), l = Math.max(...n.map((t) => t.position.y + t.dimensions.height));
310
+ return {
311
+ x: o,
312
+ y: r,
313
+ width: u - o,
314
+ height: l - r
315
+ };
316
+ }
317
+ function Te(e, i) {
318
+ const n = new Map(i.map((r) => [r.id, r])), o = e.nodes.map((r) => {
319
+ const u = n.get(r.id);
320
+ return u ? {
321
+ ...r,
322
+ position: {
323
+ x: u.position.x,
324
+ y: u.position.y
325
+ },
326
+ dimensions: k(u, r.dimensions)
327
+ } : r;
328
+ });
329
+ return {
330
+ ...e,
331
+ nodes: o,
332
+ bounds: Ae(o, e.bounds)
333
+ };
334
+ }
335
+ function Ze({
336
+ flowViewModel: e,
337
+ theme: i = "light",
338
+ editable: n = !0,
339
+ displaySettings: o,
340
+ highlightedNodeIds: r,
341
+ onNodeClick: u,
342
+ onSelectionChange: l,
343
+ onFlowViewModelChange: t
344
+ }) {
345
+ const h = x(() => ({
346
+ startNode: de,
347
+ commandNode: ce,
348
+ eventNode: ae,
349
+ policyNode: le,
350
+ endNode: ue,
351
+ outcomeNode: he
352
+ }), []), c = x(() => ({
353
+ causationEdge: ge
354
+ }), []), a = x(
355
+ () => new Set(r ?? []),
356
+ [r]
357
+ ), d = x(
358
+ () => Me(e, o, a),
359
+ [o, e, a]
360
+ ), [f, E] = K(d.nodes), w = q(e);
361
+ F(() => {
362
+ w.current = e, E(d.nodes), d.missingLayoutNodeIds.length > 0;
363
+ }, [e, d]);
364
+ const v = x(
365
+ () => De(e, f, o),
366
+ [o, e, f]
367
+ ), D = x(
368
+ () => [...f, ...v.nodes],
369
+ [f, v.nodes]
370
+ ), T = x(() => {
371
+ const g = new Set(D.map((m) => m.id)), N = [];
372
+ return [...e.edges.flatMap((m) => {
373
+ if (v.groupedEdgeIds.has(m.id))
374
+ return [];
375
+ if (!g.has(m.source) || !g.has(m.target))
376
+ return N.push(m.id), [];
377
+ const z = m.outcome?.trim();
378
+ return [H(
379
+ m.id,
380
+ m.source,
381
+ m.target,
382
+ m.type,
383
+ z || m.label || void 0,
384
+ m.sourceRef
385
+ )];
386
+ }), ...v.edges];
387
+ }, [e.edges, D, v.edges, v.groupedEdgeIds]), A = M((g) => {
388
+ t && t(
389
+ Te(w.current, g)
390
+ );
391
+ }, [t]), S = M((g) => {
392
+ E((N) => Q(g, N));
393
+ }, []), B = M((g, N, L) => {
394
+ A(L);
395
+ }, [A]), _ = M((g, N) => {
396
+ u && !N.data.synthetic && N.data.sourceRef && u(N.id, N.data.sourceRef);
397
+ }, [u]), G = M(({ nodes: g, edges: N }) => {
398
+ l && l(
399
+ g.map((L) => L.id),
400
+ N.map((L) => L.id)
401
+ );
402
+ }, [l]);
403
+ return /* @__PURE__ */ s("div", { className: `eventflow-visualizer theme-${i}`, style: { width: "100%", height: "100%" }, children: /* @__PURE__ */ y(
404
+ J,
405
+ {
406
+ nodes: D,
407
+ edges: T,
408
+ nodeTypes: h,
409
+ edgeTypes: c,
410
+ proOptions: { hideAttribution: !0 },
411
+ onNodesChange: S,
412
+ onNodeDragStop: B,
413
+ onNodeClick: _,
414
+ onSelectionChange: G,
415
+ fitView: !0,
416
+ nodesDraggable: n,
417
+ nodesConnectable: !1,
418
+ elementsSelectable: !0,
419
+ children: [
420
+ /* @__PURE__ */ s(V, { gap: 24, color: i === "dark" ? "#334155" : "#e2e8f0" }),
421
+ /* @__PURE__ */ s(ee, {}),
422
+ /* @__PURE__ */ s(se, { nodeColor: (g) => Oe(g.type) })
423
+ ]
424
+ }
425
+ ) });
426
+ }
427
+ function _e({ data: e }) {
428
+ return /* @__PURE__ */ s("div", { className: "service-map-group-node", children: /* @__PURE__ */ y("div", { className: "service-map-group-shell", children: [
429
+ /* @__PURE__ */ s("div", { className: "service-map-group-legend", title: e.title, children: e.legendLabel }),
430
+ /* @__PURE__ */ s(
431
+ "div",
432
+ {
433
+ className: "service-map-group-label",
434
+ title: e.title,
435
+ style: {
436
+ left: e.centerX,
437
+ width: e.centerWidth
438
+ },
439
+ children: e.centerLabel
440
+ }
441
+ )
442
+ ] }) });
443
+ }
444
+ function Pe({ data: e }) {
445
+ return /* @__PURE__ */ s("div", { className: "service-map-note service-map-note-command", title: e.title, children: /* @__PURE__ */ s("strong", { children: e.label }) });
446
+ }
447
+ function Se({ data: e }) {
448
+ return /* @__PURE__ */ s("div", { className: "service-map-note service-map-note-event", title: e.title, children: /* @__PURE__ */ s("strong", { children: e.label }) });
449
+ }
450
+ var P = /* @__PURE__ */ ((e) => (e.COMMAND = "COMMAND", e.EVENT = "EVENT", e))(P || {});
451
+ function Ke(e) {
452
+ return {
453
+ schema: "zfl.services.view@1",
454
+ layout: null,
455
+ bounds: null,
456
+ ...e
457
+ };
458
+ }
459
+ function Be(e, i) {
460
+ return [e, i].filter(Boolean).join(" / ") || void 0;
461
+ }
462
+ function Ge(e) {
463
+ return I(e.replace(/\//g, " / "));
464
+ }
465
+ function ze(e, i) {
466
+ const n = e.split("/").filter(Boolean), o = n[0] ?? "Unbounded", r = n[1] ?? o;
467
+ return {
468
+ legendLabel: i ? I(o) : o,
469
+ centerLabel: i ? I(r) : r
470
+ };
471
+ }
472
+ function We(e, i) {
473
+ const n = e.dimensions?.width ?? 0, o = i.filter((d) => d.position && d.dimensions);
474
+ if (n <= 0 || o.length === 0)
475
+ return { centerX: n / 2, centerWidth: void 0 };
476
+ const r = o.filter((d) => d.type === P.COMMAND), u = o.filter((d) => d.type === P.EVENT), l = r.length > 0 ? Math.max(...r.map((d) => d.position.x - (e.position?.x ?? 0) + d.dimensions.width)) : 24, t = u.length > 0 ? Math.min(...u.map((d) => d.position.x - (e.position?.x ?? 0))) : n - 24, h = Math.max(t - l, 0), c = h > 0 ? Math.max(h - 20, 120) : Math.min(n - 48, 196);
477
+ return {
478
+ centerX: h > 0 ? l + h / 2 : n / 2,
479
+ centerWidth: Math.min(c, 220)
480
+ };
481
+ }
482
+ function Z(e, i) {
483
+ const n = e.style, o = typeof n?.width == "number" ? n.width : i?.width ?? null, r = typeof n?.height == "number" ? n.height : i?.height ?? null;
484
+ return o === null || r === null ? null : { width: o, height: r };
485
+ }
486
+ function $e(e, i) {
487
+ const n = i?.humanizeLabels ?? !0, o = new Map(e.groups.map((t) => [t.id, t])), r = new Map(e.groups.map((t) => [
488
+ t.id,
489
+ e.nodes.filter((h) => h.groupId === t.id)
490
+ ])), u = e.groups.flatMap((t) => {
491
+ if (!t.position || !t.dimensions)
492
+ return [];
493
+ const h = ze(t.path, n), c = We(t, r.get(t.id) ?? []);
494
+ return [{
495
+ id: t.id,
496
+ type: "serviceGroupNode",
497
+ position: t.position,
498
+ data: {
499
+ legendLabel: h.legendLabel,
500
+ centerLabel: h.centerLabel,
501
+ centerX: c.centerX,
502
+ centerWidth: c.centerWidth,
503
+ title: n ? Ge(t.path) : t.path
504
+ },
505
+ style: {
506
+ width: t.dimensions.width,
507
+ height: t.dimensions.height
508
+ }
509
+ }];
510
+ }), l = e.nodes.flatMap((t) => {
511
+ if (!t.position || !t.dimensions)
512
+ return [];
513
+ const h = o.get(t.groupId);
514
+ return h?.position ? [{
515
+ id: t.id,
516
+ type: t.type === P.COMMAND ? "serviceCommandNode" : "serviceEventNode",
517
+ parentNode: t.groupId,
518
+ extent: "parent",
519
+ position: {
520
+ x: t.position.x - h.position.x,
521
+ y: t.position.y - h.position.y
522
+ },
523
+ data: {
524
+ label: n ? I(t.label) : t.label,
525
+ title: Be(t.system, t.servicePath)
526
+ },
527
+ style: {
528
+ width: t.dimensions.width,
529
+ height: t.dimensions.height
530
+ }
531
+ }] : [];
532
+ });
533
+ return [...u, ...l];
534
+ }
535
+ function He(e, i) {
536
+ const n = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map();
537
+ i.forEach((c) => {
538
+ if (c.id.startsWith("group:")) {
539
+ const a = e.groups.find((d) => d.id === c.id);
540
+ if (!a)
541
+ return;
542
+ n.set(c.id, {
543
+ ...a,
544
+ position: { x: c.position.x, y: c.position.y },
545
+ dimensions: Z(c, a.dimensions)
546
+ });
547
+ return;
548
+ }
549
+ o.set(c.id, c);
550
+ });
551
+ const r = e.groups.map((c) => n.get(c.id) ?? c), u = new Map(r.map((c) => [c.id, c.position])), l = e.nodes.map((c) => {
552
+ const a = o.get(c.id);
553
+ if (!a)
554
+ return c;
555
+ const d = u.get(c.groupId), f = {
556
+ x: (d?.x ?? 0) + a.position.x,
557
+ y: (d?.y ?? 0) + a.position.y
558
+ };
559
+ return {
560
+ ...c,
561
+ position: f,
562
+ dimensions: Z(a, c.dimensions)
563
+ };
564
+ }), t = r.filter((c) => c.position && c.dimensions), h = t.length === 0 ? e.bounds : {
565
+ x: 0,
566
+ y: 0,
567
+ width: Math.max(...t.map((c) => c.position.x + c.dimensions.width)),
568
+ height: Math.max(...t.map((c) => c.position.y + c.dimensions.height))
569
+ };
570
+ return {
571
+ ...e,
572
+ groups: r,
573
+ nodes: l,
574
+ bounds: h
575
+ };
576
+ }
577
+ function qe({
578
+ serviceViewModel: e,
579
+ theme: i = "light",
580
+ editable: n = !1,
581
+ displaySettings: o,
582
+ onServiceViewModelChange: r
583
+ }) {
584
+ const u = x(
585
+ () => $e(e, o),
586
+ [o, e]
587
+ ), [l, t] = K(u), h = q(e);
588
+ F(() => {
589
+ h.current = e, t(u);
590
+ }, [u, e]);
591
+ const c = M((d) => {
592
+ r && r(
593
+ He(h.current, d)
594
+ );
595
+ }, [r]), a = M((d) => {
596
+ t((f) => {
597
+ const E = Q(d, f);
598
+ return c(E), E;
599
+ });
600
+ }, [c]);
601
+ return /* @__PURE__ */ s("div", { className: `eventflow-visualizer service-map-visualizer ${i === "dark" ? "theme-dark" : ""}`, children: /* @__PURE__ */ y(
602
+ J,
603
+ {
604
+ fitView: !0,
605
+ nodes: l,
606
+ edges: [],
607
+ onNodesChange: n ? a : void 0,
608
+ nodeTypes: {
609
+ serviceGroupNode: _e,
610
+ serviceCommandNode: Pe,
611
+ serviceEventNode: Se
612
+ },
613
+ nodesDraggable: n,
614
+ nodesConnectable: !1,
615
+ elementsSelectable: !0,
616
+ minZoom: 0.15,
617
+ maxZoom: 1.5,
618
+ children: [
619
+ /* @__PURE__ */ s(V, { gap: 24, size: 1, color: i === "dark" ? "#334155" : "#d6d3d1" }),
620
+ /* @__PURE__ */ s(ee, { showInteractive: !1 })
621
+ ]
622
+ }
623
+ ) });
624
+ }
625
+ export {
626
+ ge as CausationEdge,
627
+ ce as CommandNode,
628
+ me as Direction,
629
+ ue as EndNode,
630
+ Ze as EventFlowVisualizer,
631
+ ae as EventNode,
632
+ b as FlowEdgeType,
633
+ C as FlowNodeType,
634
+ he as OutcomeNode,
635
+ le as PolicyNode,
636
+ qe as ServiceMapVisualizer,
637
+ P as ServiceNodeType,
638
+ de as StartNode,
639
+ je as createFlowViewModel,
640
+ Ke as createServiceViewModel,
641
+ Ze as default,
642
+ I as humanizeLabel,
643
+ Ye as humanizeMultilineLabel
644
+ };
645
+ //# sourceMappingURL=index.js.map