@miragon/context-maps-renderer 0.0.1

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 (95) hide show
  1. package/README.md +148 -0
  2. package/dist/CmBaseViewer.d.ts +49 -0
  3. package/dist/CmBaseViewer.d.ts.map +1 -0
  4. package/dist/Modeler.d.ts +14 -0
  5. package/dist/Modeler.d.ts.map +1 -0
  6. package/dist/NavigatedViewer.d.ts +7 -0
  7. package/dist/NavigatedViewer.d.ts.map +1 -0
  8. package/dist/Viewer.d.ts +7 -0
  9. package/dist/Viewer.d.ts.map +1 -0
  10. package/dist/behaviors/CmClickSelectionBehavior.d.ts +7 -0
  11. package/dist/behaviors/CmClickSelectionBehavior.d.ts.map +1 -0
  12. package/dist/behaviors/CmDragBehavior.d.ts +7 -0
  13. package/dist/behaviors/CmDragBehavior.d.ts.map +1 -0
  14. package/dist/behaviors/CmFlatModelBehavior.d.ts +9 -0
  15. package/dist/behaviors/CmFlatModelBehavior.d.ts.map +1 -0
  16. package/dist/behaviors/index.d.ts +7 -0
  17. package/dist/behaviors/index.d.ts.map +1 -0
  18. package/dist/connect-handles/CmConnectHandles.d.ts +15 -0
  19. package/dist/connect-handles/CmConnectHandles.d.ts.map +1 -0
  20. package/dist/connect-handles/index.d.ts +5 -0
  21. package/dist/connect-handles/index.d.ts.map +1 -0
  22. package/dist/context-maps.css +2 -0
  23. package/dist/draw/ContextMapsRenderer.d.ts +26 -0
  24. package/dist/draw/ContextMapsRenderer.d.ts.map +1 -0
  25. package/dist/draw/endRoleChips.d.ts +17 -0
  26. package/dist/draw/endRoleChips.d.ts.map +1 -0
  27. package/dist/draw/icons.d.ts +10 -0
  28. package/dist/draw/icons.d.ts.map +1 -0
  29. package/dist/draw/index.d.ts +5 -0
  30. package/dist/draw/index.d.ts.map +1 -0
  31. package/dist/draw/palette-icons.d.ts +4 -0
  32. package/dist/draw/palette-icons.d.ts.map +1 -0
  33. package/dist/draw/styles.d.ts +25 -0
  34. package/dist/draw/styles.d.ts.map +1 -0
  35. package/dist/index.d.ts +22 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +1279 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/io/CmExporter.d.ts +11 -0
  40. package/dist/io/CmExporter.d.ts.map +1 -0
  41. package/dist/io/CmImporter.d.ts +20 -0
  42. package/dist/io/CmImporter.d.ts.map +1 -0
  43. package/dist/io/index.d.ts +9 -0
  44. package/dist/io/index.d.ts.map +1 -0
  45. package/dist/io/saveSvg.d.ts +6 -0
  46. package/dist/io/saveSvg.d.ts.map +1 -0
  47. package/dist/io/types.d.ts +11 -0
  48. package/dist/io/types.d.ts.map +1 -0
  49. package/dist/keyboard/CmKeyboard.d.ts +9 -0
  50. package/dist/keyboard/CmKeyboard.d.ts.map +1 -0
  51. package/dist/keyboard/index.d.ts +5 -0
  52. package/dist/keyboard/index.d.ts.map +1 -0
  53. package/dist/label-editing/CmLabelEditing.d.ts +14 -0
  54. package/dist/label-editing/CmLabelEditing.d.ts.map +1 -0
  55. package/dist/label-editing/index.d.ts +5 -0
  56. package/dist/label-editing/index.d.ts.map +1 -0
  57. package/dist/model/CmDiagramElementFactory.d.ts +9 -0
  58. package/dist/model/CmDiagramElementFactory.d.ts.map +1 -0
  59. package/dist/model/CmElementFactory.d.ts +13 -0
  60. package/dist/model/CmElementFactory.d.ts.map +1 -0
  61. package/dist/model/CmLayouter.d.ts +21 -0
  62. package/dist/model/CmLayouter.d.ts.map +1 -0
  63. package/dist/model/di-types.d.ts +27 -0
  64. package/dist/model/di-types.d.ts.map +1 -0
  65. package/dist/model/index.d.ts +15 -0
  66. package/dist/model/index.d.ts.map +1 -0
  67. package/dist/modeling/CmModeling.d.ts +39 -0
  68. package/dist/modeling/CmModeling.d.ts.map +1 -0
  69. package/dist/modeling/cmd/SwapEndsHandler.d.ts +15 -0
  70. package/dist/modeling/cmd/SwapEndsHandler.d.ts.map +1 -0
  71. package/dist/modeling/cmd/UpdatePropertiesHandler.d.ts +13 -0
  72. package/dist/modeling/cmd/UpdatePropertiesHandler.d.ts.map +1 -0
  73. package/dist/modeling/index.d.ts +10 -0
  74. package/dist/modeling/index.d.ts.map +1 -0
  75. package/dist/palette/CmPaletteProvider.d.ts +12 -0
  76. package/dist/palette/CmPaletteProvider.d.ts.map +1 -0
  77. package/dist/palette/index.d.ts +5 -0
  78. package/dist/palette/index.d.ts.map +1 -0
  79. package/dist/rules/CmRules.d.ts +8 -0
  80. package/dist/rules/CmRules.d.ts.map +1 -0
  81. package/dist/rules/index.d.ts +5 -0
  82. package/dist/rules/index.d.ts.map +1 -0
  83. package/dist/theme/index.d.ts +2 -0
  84. package/dist/theme/index.d.ts.map +1 -0
  85. package/dist/theme/palette.d.ts +47 -0
  86. package/dist/theme/palette.d.ts.map +1 -0
  87. package/dist/validation/CmValidationMarkers.d.ts +13 -0
  88. package/dist/validation/CmValidationMarkers.d.ts.map +1 -0
  89. package/dist/validation/index.d.ts +5 -0
  90. package/dist/validation/index.d.ts.map +1 -0
  91. package/dist/zorder/CmZOrder.d.ts +13 -0
  92. package/dist/zorder/CmZOrder.d.ts.map +1 -0
  93. package/dist/zorder/index.d.ts +5 -0
  94. package/dist/zorder/index.d.ts.map +1 -0
  95. package/package.json +48 -0
package/dist/index.js ADDED
@@ -0,0 +1,1279 @@
1
+ import e from "diagram-js/lib/Diagram";
2
+ import t from "diagram-js/lib/layout/CroppingConnectionDocking";
3
+ import { ALL_SUBDOMAIN_SPECS as n, DOCUMENT_VERSION as r, MARK_COLORS as i, MARK_TEXT_COLOR as a, RELATIONSHIP_PATTERN_SPECS as o, SUBDOMAIN_TYPE_SPECS as s, isSymmetricPattern as c, newId as l, validateDocument as u } from "@miragon/context-maps-schema-model";
4
+ import d from "diagram-js/lib/core/ElementFactory";
5
+ import { getMid as f } from "diagram-js/lib/layout/LayoutUtil";
6
+ import p from "diagram-js/lib/draw/BaseRenderer";
7
+ import { append as m, attr as h, clear as g, create as _ } from "tiny-svg";
8
+ import v from "diagram-js/lib/features/selection";
9
+ import y from "diagram-js/lib/navigation/zoomscroll";
10
+ import b from "diagram-js/lib/navigation/movecanvas";
11
+ import x from "diagram-js/lib/features/connection-preview";
12
+ import S from "diagram-js/lib/features/modeling";
13
+ import C from "diagram-js/lib/features/move";
14
+ import w from "diagram-js/lib/features/outline";
15
+ import ee from "diagram-js/lib/features/resize";
16
+ import te from "diagram-js/lib/features/rules";
17
+ import ne from "diagram-js/lib/features/rules/RuleProvider";
18
+ import re from "diagram-js/lib/command/CommandInterceptor";
19
+ import { hasPrimaryModifier as ie } from "diagram-js/lib/util/Mouse";
20
+ import ae from "diagram-js/lib/features/palette";
21
+ import oe from "diagram-js/lib/features/create";
22
+ import se from "diagram-js/lib/features/connect";
23
+ import ce from "diagram-js/lib/features/overlays";
24
+ //#region src/model/di-types.ts
25
+ function T(e) {
26
+ return typeof e == "object" && e ? e.cmKind : void 0;
27
+ }
28
+ function E(e) {
29
+ return typeof T(e) == "string";
30
+ }
31
+ function D(e) {
32
+ return T(e) === "context";
33
+ }
34
+ function O(e) {
35
+ return T(e) === "relationship";
36
+ }
37
+ //#endregion
38
+ //#region src/io/saveSvg.ts
39
+ var k = 40;
40
+ function A(e, t) {
41
+ let n = e.getContainer().querySelector("svg");
42
+ if (!n) throw Error("No SVG found in the canvas container.");
43
+ let r = Infinity, i = Infinity, a = -Infinity, o = -Infinity;
44
+ for (let e of t.getAll()) {
45
+ if (!D(e)) continue;
46
+ let t = e;
47
+ r = Math.min(r, t.x), i = Math.min(i, t.y), a = Math.max(a, t.x + t.width), o = Math.max(o, t.y + t.height);
48
+ }
49
+ Number.isFinite(r) || (r = 0, i = 0, a = 100, o = 100);
50
+ let s = r - k, c = i - k, l = a - r + k * 2, u = o - i + k * 2, d = n.cloneNode(!0);
51
+ d.setAttribute("xmlns", "http://www.w3.org/2000/svg"), d.setAttribute("viewBox", `${s} ${c} ${l} ${u}`), d.setAttribute("width", String(Math.round(l))), d.setAttribute("height", String(Math.round(u)));
52
+ let f = d.querySelector(".viewport");
53
+ return f && f.removeAttribute("transform"), { svg: "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + new XMLSerializer().serializeToString(d) };
54
+ }
55
+ //#endregion
56
+ //#region src/io/types.ts
57
+ var j = "cm-root";
58
+ //#endregion
59
+ //#region src/CmBaseViewer.ts
60
+ function M(e) {
61
+ return typeof e == "number" ? `${e}px` : e;
62
+ }
63
+ var N = class {
64
+ _diagram;
65
+ _container;
66
+ _options;
67
+ constructor(e = {}) {
68
+ this._options = e, this._container = this._createContainer(e);
69
+ }
70
+ _createContainer(e) {
71
+ let t = e.container ?? document.createElement("div");
72
+ return t.classList.add("cm-djs-container"), t.style.width = M(e.width ?? "100%"), t.style.height = M(e.height ?? (e.container ? "100%" : "600px")), t;
73
+ }
74
+ _ensureDiagram() {
75
+ if (!this._diagram) {
76
+ let t = [...this._getModules(), ...this._options.additionalModules ?? []];
77
+ this._diagram = new e({
78
+ canvas: { container: this._container },
79
+ modules: t
80
+ });
81
+ }
82
+ return this._diagram;
83
+ }
84
+ get(e) {
85
+ return this._ensureDiagram().get(e);
86
+ }
87
+ on(e, t, n = 1e3) {
88
+ this.get("eventBus").on(e, n, t);
89
+ }
90
+ off(e, t) {
91
+ this.get("eventBus").off(e, t);
92
+ }
93
+ importDocument(e) {
94
+ let t = this._ensureDiagram(), n = t.get("eventBus"), r = t.get("cmImporter");
95
+ r.clear();
96
+ let i = r.import(e);
97
+ return this._fit(), n.fire("import.done", { warnings: i }), { warnings: i };
98
+ }
99
+ exportDocument() {
100
+ return this.get("cmExporter").export();
101
+ }
102
+ setMeta(e) {
103
+ let t = this.get("canvas"), n;
104
+ try {
105
+ n = t.getRootElement();
106
+ } catch {
107
+ return;
108
+ }
109
+ if (!n || n.id !== "cm-root") return;
110
+ let r = n.businessObject ?? { title: "Untitled context map" };
111
+ n.businessObject = {
112
+ ...r,
113
+ ...e
114
+ };
115
+ }
116
+ getMeta() {
117
+ try {
118
+ return this.get("canvas").getRootElement().businessObject;
119
+ } catch {
120
+ return;
121
+ }
122
+ }
123
+ saveSVG() {
124
+ return A(this.get("canvas"), this.get("elementRegistry"));
125
+ }
126
+ _fit(e = 84, t = 56) {
127
+ let n = this.get("canvas"), r = this.get("elementRegistry"), i = Infinity, a = Infinity, o = -Infinity, s = -Infinity;
128
+ for (let e of r.getAll()) {
129
+ let t = e;
130
+ typeof t.x != "number" || typeof t.y != "number" || typeof t.width != "number" || typeof t.height != "number" || (i = Math.min(i, t.x), a = Math.min(a, t.y), o = Math.max(o, t.x + t.width), s = Math.max(s, t.y + t.height));
131
+ }
132
+ if (!Number.isFinite(i)) return;
133
+ let c = this._container.getBoundingClientRect(), l = c.width, u = c.height, d = Math.max(o - i, 1), f = Math.max(s - a, 1);
134
+ if (!l || !u) {
135
+ n.zoom("fit-viewport");
136
+ return;
137
+ }
138
+ let p = Math.min((l - 2 * t) / d, (u - e - t) / f, 1.25);
139
+ n.viewbox({
140
+ x: i + d / 2 - l / 2 / p,
141
+ y: a - e / p,
142
+ width: l / p,
143
+ height: u / p
144
+ });
145
+ }
146
+ attachTo(e) {
147
+ e.appendChild(this._container), this.get("canvas").resized();
148
+ }
149
+ detach() {
150
+ this._container.remove();
151
+ }
152
+ clear() {
153
+ this._ensureDiagram().clear();
154
+ }
155
+ destroy() {
156
+ this._diagram &&= (this._diagram.destroy(), void 0), this._container.remove();
157
+ }
158
+ get container() {
159
+ return this._container;
160
+ }
161
+ }, P = class {
162
+ elementFactory;
163
+ static $inject = ["elementFactory"];
164
+ constructor(e) {
165
+ this.elementFactory = e;
166
+ }
167
+ createContext(e) {
168
+ return this.elementFactory.createShape({
169
+ id: e.id,
170
+ x: e.position.x,
171
+ y: e.position.y,
172
+ width: e.size.width,
173
+ height: e.size.height,
174
+ cmKind: "context",
175
+ cmLabel: e.label,
176
+ ...e.subdomainType ? { subdomainType: e.subdomainType } : {},
177
+ ...e.team ? { team: e.team } : {},
178
+ ...e.description ? { description: e.description } : {},
179
+ ...e.fill ? { fill: e.fill } : {},
180
+ ...e.stroke ? { stroke: e.stroke } : {}
181
+ });
182
+ }
183
+ createRelationship(e, t, n, r) {
184
+ return this.elementFactory.createConnection({
185
+ id: e.id,
186
+ source: t,
187
+ target: n,
188
+ waypoints: r,
189
+ cmKind: "relationship",
190
+ pattern: e.pattern,
191
+ ...e.upstreamRoles?.length ? { upstreamRoles: [...e.upstreamRoles] } : {},
192
+ ...e.downstreamRoles?.length ? { downstreamRoles: [...e.downstreamRoles] } : {},
193
+ ...e.label ? { cmLabel: e.label } : {},
194
+ ...e.description ? { description: e.description } : {},
195
+ ...e.implementationTechnology ? { implementationTechnology: e.implementationTechnology } : {}
196
+ });
197
+ }
198
+ createNewContext(e, t) {
199
+ let n = s[e];
200
+ return this.elementFactory.createShape({
201
+ width: n.defaultSize.width,
202
+ height: n.defaultSize.height,
203
+ cmKind: "context",
204
+ subdomainType: e,
205
+ cmLabel: t ?? "New Context"
206
+ });
207
+ }
208
+ }, le = class extends d {
209
+ create(e, t) {
210
+ return !t?.id && (e === "shape" || e === "connection") && (t = {
211
+ ...t,
212
+ id: l(e === "shape" ? "ctx" : "rel")
213
+ }), super.create(e, t);
214
+ }
215
+ }, ue = class {
216
+ docking;
217
+ static $inject = ["connectionDocking"];
218
+ constructor(e) {
219
+ this.docking = e;
220
+ }
221
+ layoutConnection(e, t = {}) {
222
+ let n = t.source ?? e.source, r = t.target ?? e.target, i = [n ? f(n) : t.connectionStart || void 0, r ? f(r) : t.connectionEnd || void 0].filter(Boolean);
223
+ return e.waypoints = i, n && r && i.length === 2 ? this.docking.getCroppedWaypoints(e, n, r) : i;
224
+ }
225
+ }, F = {
226
+ elementFactory: ["type", le],
227
+ cmElementFactory: ["type", P],
228
+ connectionDocking: ["type", t]
229
+ }, I = {
230
+ blau: "#335DE5",
231
+ blauLink: "#2B50D4",
232
+ blauHell: "#6B8AFF",
233
+ gruen: "#00E676",
234
+ grau: "#F9F7F7",
235
+ schwarz: "#1D1D1D",
236
+ weiss: "#FFFFFF",
237
+ success: "#0B7A55",
238
+ warning: "#92610A",
239
+ danger: "#C92A2A",
240
+ info: "#2B50D4",
241
+ gradientBrand: "linear-gradient(120deg, #335DE5 30%, #00E676)"
242
+ }, de = {
243
+ "--cd-blau": I.blau,
244
+ "--cd-gruen": I.gruen,
245
+ "--cd-grau": I.grau,
246
+ "--cd-schwarz": I.schwarz,
247
+ "--cd-weiss": I.weiss,
248
+ "--cd-blau-link": I.blauLink,
249
+ "--cd-blau-hell": I.blauHell,
250
+ "--cd-success": I.success,
251
+ "--cd-success-soft": "rgba(11, 122, 85, 0.12)",
252
+ "--cd-warning": I.warning,
253
+ "--cd-warning-soft": "rgba(146, 97, 10, 0.12)",
254
+ "--cd-danger": I.danger,
255
+ "--cd-danger-soft": "rgba(201, 42, 42, 0.12)",
256
+ "--cd-info": I.info,
257
+ "--cd-info-soft": "rgba(43, 80, 212, 0.12)",
258
+ "--cd-gradient-brand": I.gradientBrand
259
+ }, fe = 1500;
260
+ I.blau;
261
+ var L = I.schwarz, R = "#5B5B5B", z = {
262
+ family: "'Geist Variable', 'Geist', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif",
263
+ label: 13.5,
264
+ small: 11
265
+ }, B = I.weiss;
266
+ //#endregion
267
+ //#region src/draw/endRoleChips.ts
268
+ function V(e, t, n, r) {
269
+ if (r.length === 0) return null;
270
+ let i = t.x - e.x, a = t.y - e.y, o = Math.hypot(i, a) || 1, s = i / o, c = a / o, l = z.small * .64, u = z.small + 6, d = r.map((e) => e.length * l + 12), f = d.reduce((e, t) => e + t, 0) + 3 * (r.length - 1), p = f + 8, m = u + 8, h = 11 + n.length * l / 2 + 8 + p / 2, g = {
271
+ x: e.x + s * h,
272
+ y: e.y + c * h
273
+ };
274
+ return {
275
+ box: {
276
+ x: g.x - p / 2,
277
+ y: g.y - m / 2,
278
+ width: p,
279
+ height: m
280
+ },
281
+ center: g,
282
+ chipWidths: d,
283
+ chipHeight: u,
284
+ innerWidth: f,
285
+ gap: 3
286
+ };
287
+ }
288
+ //#endregion
289
+ //#region src/draw/ContextMapsRenderer.ts
290
+ var pe = "#F1F1EE", H = "#8A8577", U = class extends p {
291
+ static $inject = ["eventBus"];
292
+ constructor(e) {
293
+ super(e, fe);
294
+ }
295
+ canRender(e) {
296
+ return E(e);
297
+ }
298
+ drawShape(e, t) {
299
+ if (g(e), D(t)) return this.drawContext(e, t);
300
+ let n = h(_("rect"), {
301
+ width: t.width,
302
+ height: t.height,
303
+ fill: "#eee"
304
+ });
305
+ return m(e, n), n;
306
+ }
307
+ drawConnection(e, t) {
308
+ if (g(e), O(t)) return this.drawRelationship(e, t);
309
+ let n = h(_("polyline"), {
310
+ points: (t.waypoints ?? []).map((e) => `${e.x},${e.y}`).join(" "),
311
+ fill: "none",
312
+ stroke: L
313
+ });
314
+ return m(e, n), n;
315
+ }
316
+ getShapePath(e) {
317
+ let { x: t, y: n, width: r, height: i } = e;
318
+ return `M${t},${n}l${r},0l0,${i}l${-r},0z`;
319
+ }
320
+ getConnectionPath(e) {
321
+ let t = e.waypoints ?? [];
322
+ return t.length === 0 ? "" : t.map((e, t) => `${t === 0 ? "M" : "L"}${e.x},${e.y}`).join("");
323
+ }
324
+ drawContext(e, t) {
325
+ let n = t.subdomainType ? s[t.subdomainType] : void 0, r = Math.max(t.width, 1), i = Math.max(t.height, 1), a = h(_("rect"), {
326
+ x: 1,
327
+ y: 1,
328
+ width: r - 2,
329
+ height: i - 2,
330
+ rx: 8,
331
+ ry: 8,
332
+ fill: t.fill ?? n?.fill ?? pe,
333
+ stroke: t.stroke ?? n?.stroke ?? H,
334
+ "stroke-width": 2,
335
+ "stroke-linejoin": "round"
336
+ });
337
+ m(e, a);
338
+ let o = !!t.team;
339
+ if (this.appendLabel(e, t.cmLabel ?? "", r, o ? i - 18 : i, { "font-weight": "650" }), t.subdomainType && n) {
340
+ m(e, _e(t.subdomainType, 15, 15, 18, n.stroke));
341
+ let r = h(_("text"), {
342
+ x: 28,
343
+ y: 15,
344
+ "font-family": z.family,
345
+ "font-size": z.small,
346
+ "font-weight": "700",
347
+ fill: n.stroke,
348
+ "text-anchor": "start",
349
+ "dominant-baseline": "central",
350
+ "letter-spacing": "0.03em"
351
+ });
352
+ r.textContent = n.label, m(e, r);
353
+ }
354
+ if (t.team) {
355
+ let n = 19 + t.team.length * z.small * .55, a = r / 2 - n / 2, o = i - 12;
356
+ m(e, ye(a + 14 / 2, o, 14, R));
357
+ let s = h(_("text"), {
358
+ x: a + 14 + 5,
359
+ y: o,
360
+ "font-family": z.family,
361
+ "font-size": z.small,
362
+ fill: R,
363
+ "text-anchor": "start",
364
+ "dominant-baseline": "central"
365
+ });
366
+ s.textContent = t.team, m(e, s);
367
+ }
368
+ return a;
369
+ }
370
+ drawRelationship(e, t) {
371
+ let n = o[t.pattern] ?? o["upstream-downstream"], r = t.waypoints ?? [], i = n.dash, a = h(_("polyline"), {
372
+ points: r.map((e) => `${e.x},${e.y}`).join(" "),
373
+ fill: "none",
374
+ stroke: n.stroke,
375
+ "stroke-width": n.strokeWidth,
376
+ "stroke-linejoin": "round",
377
+ "stroke-linecap": "round",
378
+ ...i ? { "stroke-dasharray": i } : {}
379
+ });
380
+ if (m(e, a), r.length >= 2) {
381
+ let i = r[0], a = r[r.length - 1], o = t.upstreamRoles ?? [], s = t.downstreamRoles ?? [];
382
+ if (n.symmetric) {
383
+ let t = (i.x + a.x) / 2, r = (i.y + a.y) / 2;
384
+ this.chip(e, t, r, n.abbreviation, B, n.stroke, n.stroke);
385
+ } else {
386
+ let n = t.pattern === "customer-supplier";
387
+ this.endMarkers(e, i, a, n ? "S" : "U", o), this.endMarkers(e, a, i, n ? "C" : "D", s);
388
+ }
389
+ }
390
+ return a;
391
+ }
392
+ endMarkers(e, t, n, r, a) {
393
+ let o = n.x - t.x, s = n.y - t.y, c = Math.hypot(o, s) || 1, l = o / c, u = s / c, d = i[r] ?? L, f = h(_("text"), {
394
+ x: t.x + l * 11,
395
+ y: t.y + u * 11,
396
+ "font-family": z.family,
397
+ "font-size": z.small + 1,
398
+ "font-weight": "800",
399
+ fill: d,
400
+ stroke: B,
401
+ "stroke-width": 3,
402
+ "paint-order": "stroke",
403
+ "text-anchor": "middle",
404
+ "dominant-baseline": "central"
405
+ });
406
+ f.textContent = r, m(e, f);
407
+ let p = V(t, n, r, a);
408
+ if (!p) return;
409
+ let { box: g, center: v, chipWidths: y, chipHeight: b, innerWidth: x, gap: S } = p, C = v.y;
410
+ m(e, h(_("rect"), {
411
+ x: g.x,
412
+ y: g.y,
413
+ width: g.width,
414
+ height: g.height,
415
+ rx: 6,
416
+ ry: 6,
417
+ fill: B,
418
+ "fill-opacity": .96,
419
+ stroke: "#d9d5cc",
420
+ "stroke-width": 1
421
+ }));
422
+ let w = v.x - x / 2;
423
+ a.forEach((t, n) => {
424
+ let r = y[n], a = i[t] ?? H;
425
+ this.miniChip(e, w + r / 2, C, r, b, t, a), w += r + S;
426
+ });
427
+ }
428
+ miniChip(e, t, n, r, i, o, s) {
429
+ m(e, h(_("rect"), {
430
+ x: t - r / 2,
431
+ y: n - i / 2,
432
+ width: r,
433
+ height: i,
434
+ rx: 3,
435
+ ry: 3,
436
+ fill: s,
437
+ stroke: me(s),
438
+ "stroke-width": 1
439
+ }));
440
+ let c = h(_("text"), {
441
+ x: t,
442
+ y: n,
443
+ "font-family": z.family,
444
+ "font-size": z.small,
445
+ "font-weight": "700",
446
+ fill: a,
447
+ "text-anchor": "middle",
448
+ "dominant-baseline": "central"
449
+ });
450
+ c.textContent = o, m(e, c);
451
+ }
452
+ chip(e, t, n, r, i, a, o) {
453
+ if (!r) return;
454
+ let s = z.small * .64, c = r.length * s + 12, l = z.small + 8;
455
+ m(e, h(_("rect"), {
456
+ x: t - c / 2,
457
+ y: n - l / 2,
458
+ width: c,
459
+ height: l,
460
+ rx: 4,
461
+ ry: 4,
462
+ fill: i,
463
+ stroke: o,
464
+ "stroke-width": 1,
465
+ ...i === B ? { "fill-opacity": .95 } : {}
466
+ }));
467
+ let u = h(_("text"), {
468
+ x: t,
469
+ y: n,
470
+ "font-family": z.family,
471
+ "font-size": z.small,
472
+ "font-weight": "700",
473
+ fill: a,
474
+ "text-anchor": "middle",
475
+ "dominant-baseline": "central"
476
+ });
477
+ u.textContent = r, m(e, u);
478
+ }
479
+ appendLabel(e, t, n, r, i) {
480
+ let a = typeof i["font-size"] == "number" ? i["font-size"] : z.label, o = be(t, n - 20, a), s = a * 1.2, c = r / 2 - (o.length - 1) * s / 2;
481
+ o.forEach((t, r) => {
482
+ let o = h(_("text"), {
483
+ x: n / 2,
484
+ y: c + r * s,
485
+ "font-family": z.family,
486
+ "font-size": a,
487
+ fill: L,
488
+ "text-anchor": "middle",
489
+ "dominant-baseline": "central",
490
+ ...i
491
+ });
492
+ o.textContent = t, m(e, o);
493
+ });
494
+ }
495
+ };
496
+ function me(e, t = .7) {
497
+ let n = /^#([0-9a-f]{6})$/i.exec(e);
498
+ if (!n) return e;
499
+ let r = parseInt(n[1], 16);
500
+ return `rgb(${Math.round((r >> 16 & 255) * t)},${Math.round((r >> 8 & 255) * t)},${Math.round((r & 255) * t)})`;
501
+ }
502
+ var he = "M12 2l2.9 6.26L22 9.27l-5 4.87L18.18 22 12 18.56 5.82 22 7 14.14l-5-4.87 7.1-1.01z", ge = "M23 5.5V20c0 2.2-1.8 4-4 4h-7.3c-1.08 0-2.1-.43-2.85-1.19L1 14.83s1.26-1.23 1.3-1.25c.22-.19.49-.29.79-.29.22 0 .42.06.6.16.04.01 4.31 2.46 4.31 2.46V4c0-.83.67-1.5 1.5-1.5S11 3.17 11 4v7h1V1.5c0-.83.67-1.5 1.5-1.5S15 .67 15 1.5V11h1V2.5c0-.83.67-1.5 1.5-1.5s1.5.67 1.5 1.5V11h1V5.5c0-.83.67-1.5 1.5-1.5s1.5.67 1.5 1.5z";
503
+ function _e(e, t, n, r, i) {
504
+ if (e === "generic") {
505
+ let e = _("g");
506
+ return m(e, h(_("circle"), {
507
+ cx: t,
508
+ cy: n,
509
+ r: r / 2 - 1,
510
+ fill: "none",
511
+ stroke: i,
512
+ "stroke-width": 1.6,
513
+ "stroke-dasharray": "2.2 2.2"
514
+ })), e;
515
+ }
516
+ let a = r / 24, o = e === "supporting" ? " rotate(90 12 12)" : "", s = _("g");
517
+ return h(s, { transform: `translate(${t - 12 * a} ${n - 12 * a}) scale(${a})${o}` }), m(s, h(_("path"), {
518
+ d: e === "core" ? he : ge,
519
+ fill: i
520
+ })), s;
521
+ }
522
+ var ve = "M16 11c1.66 0 2.99-1.34 2.99-3S17.66 5 16 5c-1.66 0-3 1.34-3 3s1.34 3 3 3zm-8 0c1.66 0 2.99-1.34 2.99-3S9.66 5 8 5 5 6.34 5 8s1.34 3 3 3zm0 2c-2.33 0-7 1.17-7 3.5V19h14v-2.5c0-2.33-4.67-3.5-7-3.5zm8 0c-.29 0-.62.02-.97.05 1.16.84 1.97 1.97 1.97 3.45V19h6v-2.5c0-2.33-4.67-3.5-7-3.5z";
523
+ function ye(e, t, n, r) {
524
+ let i = n / 24, a = _("g");
525
+ return h(a, { transform: `translate(${e - 12 * i} ${t - 12 * i}) scale(${i})` }), m(a, h(_("path"), {
526
+ d: ve,
527
+ fill: r
528
+ })), a;
529
+ }
530
+ function be(e, t, n) {
531
+ let r = Math.max(4, Math.floor(t / (n * .58))), i = e.split(/\s+/).filter(Boolean);
532
+ if (i.length === 0) return [];
533
+ let a = [], o = "";
534
+ for (let e of i) {
535
+ let t = o ? `${o} ${e}` : e;
536
+ t.length > r && o ? (a.push(o), o = e) : o = t;
537
+ }
538
+ return o && a.push(o), a;
539
+ }
540
+ //#endregion
541
+ //#region src/draw/index.ts
542
+ var W = {
543
+ __init__: ["cmRenderer"],
544
+ cmRenderer: ["type", U]
545
+ };
546
+ //#endregion
547
+ //#region src/io/CmImporter.ts
548
+ function G(e, t) {
549
+ let n = e.x + e.width / 2, r = e.y + e.height / 2, i = t.x - n, a = t.y - r;
550
+ if (i === 0 && a === 0) return {
551
+ x: n,
552
+ y: r
553
+ };
554
+ let o = i === 0 ? Infinity : e.width / 2 / Math.abs(i), s = a === 0 ? Infinity : e.height / 2 / Math.abs(a), c = Math.min(o, s);
555
+ return {
556
+ x: n + i * c,
557
+ y: r + a * c
558
+ };
559
+ }
560
+ function K(e) {
561
+ return {
562
+ x: e.x + e.width / 2,
563
+ y: e.y + e.height / 2
564
+ };
565
+ }
566
+ var q = class {
567
+ canvas;
568
+ elementFactory;
569
+ factory;
570
+ eventBus;
571
+ elementRegistry;
572
+ static $inject = [
573
+ "canvas",
574
+ "elementFactory",
575
+ "cmElementFactory",
576
+ "eventBus",
577
+ "elementRegistry"
578
+ ];
579
+ constructor(e, t, n, r, i) {
580
+ this.canvas = e, this.elementFactory = t, this.factory = n, this.eventBus = r, this.elementRegistry = i;
581
+ }
582
+ import(e) {
583
+ let t = [];
584
+ this.eventBus.fire("import.render.start", { document: e });
585
+ let n;
586
+ try {
587
+ n = this.canvas.getRootElement();
588
+ } catch {
589
+ n = void 0;
590
+ }
591
+ let r;
592
+ n && n.id === "cm-root" ? r = n : (r = this.elementFactory.createRoot({ id: j }), this.canvas.setRootElement(r)), r.businessObject = { title: e.title };
593
+ let i = /* @__PURE__ */ new Map();
594
+ for (let t of e.contexts) {
595
+ let e = this.factory.createContext(t);
596
+ i.set(t.id, e);
597
+ }
598
+ for (let n of e.relationships) {
599
+ let e = i.get(n.from), a = i.get(n.to);
600
+ if (!e || !a) {
601
+ t.push({
602
+ message: `Relationship "${n.id}" references a missing context; skipped.`,
603
+ elementId: n.id
604
+ });
605
+ continue;
606
+ }
607
+ let o = [G(e, K(a)), G(a, K(e))], s = this.factory.createRelationship(n, e, a, o);
608
+ this.canvas.addConnection(s, r);
609
+ }
610
+ for (let e of i.values()) this.canvas.addShape(e, r);
611
+ return this.eventBus.fire("import.render.done", { warnings: t }), t;
612
+ }
613
+ clear() {
614
+ for (let e of [...this.elementRegistry.getAll()]) if (e.id !== "cm-root") try {
615
+ "waypoints" in e ? this.canvas.removeConnection(e.id) : this.canvas.removeShape(e.id);
616
+ } catch {}
617
+ }
618
+ }, J = class {
619
+ elementRegistry;
620
+ canvas;
621
+ static $inject = ["elementRegistry", "canvas"];
622
+ constructor(e, t) {
623
+ this.elementRegistry = e, this.canvas = t;
624
+ }
625
+ export() {
626
+ let e;
627
+ try {
628
+ e = this.canvas.getRootElement().businessObject;
629
+ } catch {
630
+ e = void 0;
631
+ }
632
+ let t = [], n = [];
633
+ for (let e of this.elementRegistry.getAll()) if (e.id !== "cm-root") {
634
+ if (D(e)) {
635
+ let n = e;
636
+ t.push({
637
+ id: e.id,
638
+ label: e.cmLabel ?? "",
639
+ position: {
640
+ x: n.x,
641
+ y: n.y
642
+ },
643
+ size: {
644
+ width: n.width,
645
+ height: n.height
646
+ },
647
+ ...e.subdomainType ? { subdomainType: e.subdomainType } : {},
648
+ ...e.team ? { team: e.team } : {},
649
+ ...e.description ? { description: e.description } : {},
650
+ ...e.fill ? { fill: e.fill } : {},
651
+ ...e.stroke ? { stroke: e.stroke } : {}
652
+ });
653
+ } else if (O(e)) {
654
+ let t = e.source, r = e.target;
655
+ if (!t?.id || !r?.id) continue;
656
+ n.push({
657
+ id: e.id,
658
+ from: t.id,
659
+ to: r.id,
660
+ pattern: e.pattern,
661
+ ...e.upstreamRoles?.length ? { upstreamRoles: [...e.upstreamRoles] } : {},
662
+ ...e.downstreamRoles?.length ? { downstreamRoles: [...e.downstreamRoles] } : {},
663
+ ...e.cmLabel ? { label: e.cmLabel } : {},
664
+ ...e.description ? { description: e.description } : {},
665
+ ...e.implementationTechnology ? { implementationTechnology: e.implementationTechnology } : {}
666
+ });
667
+ }
668
+ }
669
+ return {
670
+ version: r,
671
+ title: e?.title ?? "Untitled context map",
672
+ contexts: t,
673
+ relationships: n
674
+ };
675
+ }
676
+ }, Y = {
677
+ cmImporter: ["type", q],
678
+ cmExporter: ["type", J]
679
+ }, X = class extends N {
680
+ _getModules() {
681
+ return [
682
+ F,
683
+ W,
684
+ Y
685
+ ];
686
+ }
687
+ }, Z = class extends X {
688
+ _getModules() {
689
+ return [
690
+ ...super._getModules(),
691
+ v,
692
+ y,
693
+ b
694
+ ];
695
+ }
696
+ };
697
+ //#endregion
698
+ //#region src/modeling/cmd/UpdatePropertiesHandler.ts
699
+ function xe(e, t, n) {
700
+ n === void 0 ? delete e[t] : e[t] = n;
701
+ }
702
+ var Se = class {
703
+ execute(e) {
704
+ let { element: t, properties: n } = e, r = t, i = {};
705
+ for (let e of Object.keys(n)) i[e] = r[e], xe(r, e, n[e]);
706
+ return e.oldProperties = i, [t];
707
+ }
708
+ revert(e) {
709
+ let { element: t, oldProperties: n } = e, r = t;
710
+ if (n) for (let e of Object.keys(n)) xe(r, e, n[e]);
711
+ return [t];
712
+ }
713
+ };
714
+ //#endregion
715
+ //#region src/modeling/cmd/SwapEndsHandler.ts
716
+ function Ce(e) {
717
+ let t = e.source;
718
+ return e.source = e.target, e.target = t, Array.isArray(e.waypoints) && (e.waypoints = [...e.waypoints].reverse()), [e];
719
+ }
720
+ var we = class {
721
+ execute(e) {
722
+ return Ce(e.connection);
723
+ }
724
+ revert(e) {
725
+ return Ce(e.connection);
726
+ }
727
+ }, Te = "element.updateProperties", Ee = "relationship.swapEnds", De = class {
728
+ commandStack;
729
+ elementRegistry;
730
+ graphicsFactory;
731
+ static $inject = [
732
+ "commandStack",
733
+ "elementRegistry",
734
+ "graphicsFactory"
735
+ ];
736
+ constructor(e, t, n) {
737
+ this.commandStack = e, this.elementRegistry = t, this.graphicsFactory = n, e.registerHandler(Te, Se), e.registerHandler(Ee, we);
738
+ }
739
+ redraw(e) {
740
+ let t = this.elementRegistry.getGraphics(e);
741
+ t && this.graphicsFactory.update(O(e) ? "connection" : "shape", e, t);
742
+ }
743
+ swapEnds(e) {
744
+ this.commandStack.execute(Ee, { connection: e }), this.redraw(e);
745
+ }
746
+ updateProperties(e, t) {
747
+ this.commandStack.execute(Te, {
748
+ element: e,
749
+ properties: t
750
+ }), this.redraw(e);
751
+ }
752
+ updateLabel(e, t) {
753
+ this.updateProperties(e, { cmLabel: t || void 0 });
754
+ }
755
+ setSubdomainType(e, t) {
756
+ this.updateProperties(e, { subdomainType: t });
757
+ }
758
+ setTeam(e, t) {
759
+ this.updateProperties(e, { team: t || void 0 });
760
+ }
761
+ setDescription(e, t) {
762
+ this.updateProperties(e, { description: t || void 0 });
763
+ }
764
+ setColors(e, t, n) {
765
+ this.updateProperties(e, {
766
+ fill: t,
767
+ stroke: n
768
+ });
769
+ }
770
+ setPattern(e, t) {
771
+ let n = { pattern: t };
772
+ if (c(t)) n.upstreamRoles = void 0, n.downstreamRoles = void 0;
773
+ else if (t === "customer-supplier") {
774
+ let t = (e.upstreamRoles ?? []).filter((e) => e !== "OHS"), r = (e.downstreamRoles ?? []).filter((e) => e !== "CF");
775
+ n.upstreamRoles = t.length ? t : void 0, n.downstreamRoles = r.length ? r : void 0;
776
+ }
777
+ this.updateProperties(e, n);
778
+ }
779
+ setUpstreamRoles(e, t) {
780
+ this.updateProperties(e, { upstreamRoles: t.length ? t : void 0 });
781
+ }
782
+ setDownstreamRoles(e, t) {
783
+ this.updateProperties(e, { downstreamRoles: t.length ? t : void 0 });
784
+ }
785
+ setImplementationTechnology(e, t) {
786
+ this.updateProperties(e, { implementationTechnology: t || void 0 });
787
+ }
788
+ }, Oe = {
789
+ __init__: ["cmModeling"],
790
+ cmModeling: ["type", De],
791
+ layouter: ["type", ue]
792
+ }, ke = class extends ne {
793
+ static $inject = ["eventBus"];
794
+ constructor(e) {
795
+ super(e);
796
+ }
797
+ init() {
798
+ this.addRule(["shape.move", "elements.move"], (e) => e.target && e.target.parent ? null : !0), this.addRule("shape.create", () => !0), this.addRule("shape.resize", () => !0), this.addRule("connection.create", (e) => je(e.source, e.target)), this.addRule("connection.reconnect", (e) => !!je(e.source, e.target, e.connection)), this.addRule("connection.updateWaypoints", () => !0);
799
+ }
800
+ };
801
+ function Ae(e, t, n) {
802
+ let { incoming: r = [], outgoing: i = [] } = e;
803
+ return [...r, ...i].some((r) => r !== n && (r.source === e && r.target === t || r.source === t && r.target === e));
804
+ }
805
+ function je(e, t, n) {
806
+ return !D(e) || !D(t) || e === t || Ae(e, t, n) ? !1 : {
807
+ cmKind: "relationship",
808
+ pattern: "upstream-downstream"
809
+ };
810
+ }
811
+ //#endregion
812
+ //#region src/rules/index.ts
813
+ var Me = {
814
+ __depends__: [te],
815
+ __init__: ["cmRules"],
816
+ cmRules: ["type", ke]
817
+ }, Ne = class extends re {
818
+ static $inject = [
819
+ "eventBus",
820
+ "canvas",
821
+ "modeling"
822
+ ];
823
+ constructor(e, t, n) {
824
+ super(e), this.preExecute(["shape.create", "elements.create"], (e) => {
825
+ e.parent = t.getRootElement();
826
+ }, !0), this.postExecute([
827
+ "shape.move",
828
+ "elements.move",
829
+ "shape.resize"
830
+ ], (e) => {
831
+ let t = e.shapes ?? (e.shape ? [e.shape] : []), r = /* @__PURE__ */ new Set();
832
+ for (let e of t) {
833
+ let t = [...e.incoming ?? [], ...e.outgoing ?? []];
834
+ for (let e of t) r.has(e.id) || (r.add(e.id), n.layoutConnection(e));
835
+ }
836
+ }, !0);
837
+ }
838
+ }, Pe = "cm-dragging", Fe = class {
839
+ static $inject = ["eventBus", "canvas"];
840
+ constructor(e, t) {
841
+ e.on("drag.init", () => {
842
+ t.getContainer().classList.add(Pe);
843
+ }), e.on("drag.cleanup", () => {
844
+ t.getContainer().classList.remove(Pe);
845
+ });
846
+ }
847
+ }, Ie = 2e3, Le = {
848
+ __init__: [
849
+ "cmFlatModelBehavior",
850
+ "cmDragBehavior",
851
+ "cmClickSelectionBehavior"
852
+ ],
853
+ cmFlatModelBehavior: ["type", Ne],
854
+ cmDragBehavior: ["type", Fe],
855
+ cmClickSelectionBehavior: ["type", class {
856
+ static $inject = ["eventBus", "selection"];
857
+ constructor(e, t) {
858
+ e.on("element.click", Ie, (e) => {
859
+ let n = e.element;
860
+ if (E(n) && !ie(e) && t.isSelected(n)) return !1;
861
+ });
862
+ }
863
+ }]
864
+ };
865
+ //#endregion
866
+ //#region src/draw/palette-icons.ts
867
+ function Re(e) {
868
+ return `<svg class="cm-palette-svg" width="24" height="24" viewBox="0 0 26 26" aria-hidden="true">${e}</svg>`;
869
+ }
870
+ var ze = "M12 2l2.9 6.26L22 9.27l-5 4.87L18.18 22 12 18.56 5.82 22 7 14.14l-5-4.87 7.1-1.01z", Be = "M23 5.5V20c0 2.2-1.8 4-4 4h-7.3c-1.08 0-2.1-.43-2.85-1.19L1 14.83s1.26-1.23 1.3-1.25c.22-.19.49-.29.79-.29.22 0 .42.06.6.16.04.01 4.31 2.46 4.31 2.46V4c0-.83.67-1.5 1.5-1.5S11 3.17 11 4v7h1V1.5c0-.83.67-1.5 1.5-1.5S15 .67 15 1.5V11h1V2.5c0-.83.67-1.5 1.5-1.5s1.5.67 1.5 1.5V11h1V5.5c0-.83.67-1.5 1.5-1.5s1.5.67 1.5 1.5z";
871
+ function Ve(e, t, n, r, i) {
872
+ if (e === "generic") return `<circle cx="${t}" cy="${n}" r="${r / 2 - .5}" fill="none" stroke="${i}" stroke-width="1.4" stroke-dasharray="1.8 1.8"/>`;
873
+ let a = r / 24, o = e === "supporting" ? " rotate(90 12 12)" : "", s = `translate(${t - 12 * a} ${n - 12 * a}) scale(${a})${o}`;
874
+ return `<path d="${e === "core" ? ze : Be}" fill="${i}" transform="${s}"/>`;
875
+ }
876
+ function He(e) {
877
+ let t = s[e];
878
+ return Re(`<rect x="2" y="4" width="22" height="18" rx="3.5" fill="${t.fill}" stroke="${t.stroke}" stroke-width="1.5"/>` + Ve(e, 13, 13, 12, t.stroke));
879
+ }
880
+ function Ue(e = "upstream-downstream") {
881
+ let t = o[e], n = t.dash ? ` stroke-dasharray="${t.dash}"` : "", r = Math.min(t.strokeWidth, 2.6);
882
+ return Re(`<g stroke="${t.stroke}" stroke-width="${r}" stroke-linecap="round"><circle cx="5" cy="13" r="2.5" fill="${t.stroke}" stroke="none"/><line x1="7" y1="13" x2="19" y2="13"${n}/><circle cx="21" cy="13" r="2.5" fill="${t.stroke}" stroke="none"/></g>`);
883
+ }
884
+ //#endregion
885
+ //#region src/palette/CmPaletteProvider.ts
886
+ var We = "cm-1-contexts";
887
+ function Ge(e, t) {
888
+ return `<div class="entry cm-palette-entry" draggable="true" title="${t}">${e}</div>`;
889
+ }
890
+ var Ke = class {
891
+ create;
892
+ factory;
893
+ static $inject = [
894
+ "palette",
895
+ "create",
896
+ "cmElementFactory"
897
+ ];
898
+ constructor(e, t, n) {
899
+ this.create = t, this.factory = n, e.registerProvider(this);
900
+ }
901
+ getPaletteEntries() {
902
+ let e = {};
903
+ for (let t of n) {
904
+ let n = (e) => this.create.start(e, this.factory.createNewContext(t.type, t.label));
905
+ e[`context.${t.type}`] = {
906
+ group: We,
907
+ title: `${t.label} — ${t.description}`,
908
+ html: Ge(He(t.type), `${t.label} — ${t.description}`),
909
+ action: {
910
+ dragstart: n,
911
+ click: n
912
+ }
913
+ };
914
+ }
915
+ return e;
916
+ }
917
+ }, qe = {
918
+ __depends__: [
919
+ ae,
920
+ oe,
921
+ se
922
+ ],
923
+ __init__: ["cmPaletteProvider"],
924
+ cmPaletteProvider: ["type", Ke]
925
+ }, Je = "M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z";
926
+ function Ye(e, t = 18) {
927
+ return `<svg width="${t}" height="${t}" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="${e}"/></svg>`;
928
+ }
929
+ //#endregion
930
+ //#region src/connect-handles/CmConnectHandles.ts
931
+ var Xe = "cm-connect-handle", Ze = 28, Qe = 12, $e = [
932
+ {
933
+ side: "top",
934
+ rotationDeg: -90
935
+ },
936
+ {
937
+ side: "right",
938
+ rotationDeg: 0
939
+ },
940
+ {
941
+ side: "bottom",
942
+ rotationDeg: 90
943
+ },
944
+ {
945
+ side: "left",
946
+ rotationDeg: 180
947
+ }
948
+ ];
949
+ function et(e, t) {
950
+ let n = t.width / 2 - Ze / 2, r = t.height / 2 - Ze / 2;
951
+ switch (e) {
952
+ case "top": return {
953
+ top: -40,
954
+ left: n
955
+ };
956
+ case "bottom": return {
957
+ top: t.height + Qe,
958
+ left: n
959
+ };
960
+ case "left": return {
961
+ top: r,
962
+ left: -40
963
+ };
964
+ case "right": return {
965
+ top: r,
966
+ left: t.width + Qe
967
+ };
968
+ }
969
+ }
970
+ var tt = class {
971
+ eventBus;
972
+ selection;
973
+ overlays;
974
+ dragging;
975
+ static $inject = [
976
+ "eventBus",
977
+ "selection",
978
+ "overlays",
979
+ "connect",
980
+ "dragging"
981
+ ];
982
+ constructor(e, t, n, r, i) {
983
+ this.eventBus = e, this.selection = t, this.overlays = n, this.dragging = i;
984
+ let a = () => this.refresh();
985
+ e.on("selection.changed", a), e.on("commandStack.changed", a);
986
+ }
987
+ refresh() {
988
+ this.overlays.remove({ type: Xe });
989
+ let e = this.selection.get();
990
+ if (e.length !== 1) return;
991
+ let t = e[0];
992
+ if (!D(t)) return;
993
+ let n = t;
994
+ for (let { side: e, rotationDeg: r } of $e) {
995
+ let i = document.createElement("div");
996
+ i.className = "cm-connect-handle", i.dataset.side = e, i.title = "Connect to another context", i.innerHTML = `<span style="display:flex;transform:rotate(${r}deg)">${Ye(Je)}</span>`, i.addEventListener("mousedown", (e) => {
997
+ e.button === 0 && (e.preventDefault(), e.stopPropagation(), this.dragging.init(e, "connect", {
998
+ autoActivate: !1,
999
+ trapClick: !1,
1000
+ data: {
1001
+ shape: t,
1002
+ context: {
1003
+ start: t,
1004
+ connectionStart: f(t)
1005
+ }
1006
+ }
1007
+ }), this.eventBus.once("connect.cleanup", 250, () => {
1008
+ this.selection.get().length === 0 && this.selection.select(t);
1009
+ }));
1010
+ }), this.overlays.add(t, Xe, {
1011
+ position: et(e, n),
1012
+ html: i
1013
+ });
1014
+ }
1015
+ }
1016
+ }, nt = {
1017
+ __depends__: [
1018
+ se,
1019
+ ce,
1020
+ v
1021
+ ],
1022
+ __init__: ["cmConnectHandles"],
1023
+ cmConnectHandles: ["type", tt]
1024
+ }, rt = class {
1025
+ canvas;
1026
+ modeling;
1027
+ static $inject = [
1028
+ "eventBus",
1029
+ "canvas",
1030
+ "cmModeling"
1031
+ ];
1032
+ active = null;
1033
+ constructor(e, t, n) {
1034
+ this.canvas = t, this.modeling = n, e.on("element.dblclick", (e) => {
1035
+ E(e.element) && this.activate(e.element);
1036
+ }), e.on([
1037
+ "element.mousedown",
1038
+ "drag.init",
1039
+ "canvas.viewbox.changing"
1040
+ ], () => this.active?.commit());
1041
+ }
1042
+ activate(e) {
1043
+ this.active?.commit();
1044
+ let t = this.canvas.getContainer(), n = this.canvas.zoom(), r = this.canvas.viewbox(), { x: i, y: a } = it(e), o = (i - r.x) * n - 170 / 2, s = (a - r.y) * n - 14, c = document.createElement("input");
1045
+ c.type = "text", c.className = "cm-label-input", c.value = e.cmLabel ?? "", c.style.position = "absolute", c.style.left = `${o}px`, c.style.top = `${s}px`, c.style.width = "170px", t.appendChild(c), c.focus(), c.select();
1046
+ let l = !1, u = () => {
1047
+ l || (l = !0, c.removeEventListener("keydown", f), c.removeEventListener("blur", p), c.remove(), this.active = null);
1048
+ }, d = () => {
1049
+ if (l) return;
1050
+ let t = c.value.trim(), n = t !== (e.cmLabel ?? "");
1051
+ u(), n && this.modeling.updateLabel(e, t);
1052
+ }, f = (e) => {
1053
+ e.key === "Enter" ? (e.preventDefault(), d()) : e.key === "Escape" && (e.preventDefault(), u());
1054
+ }, p = () => d();
1055
+ c.addEventListener("keydown", f), c.addEventListener("blur", p), this.active = {
1056
+ commit: d,
1057
+ cleanup: u
1058
+ };
1059
+ }
1060
+ cancel() {
1061
+ this.active?.cleanup();
1062
+ }
1063
+ };
1064
+ function it(e) {
1065
+ if (O(e)) {
1066
+ let t = e.waypoints ?? [];
1067
+ if (t.length >= 2) {
1068
+ let e = t[0], n = t[t.length - 1];
1069
+ return {
1070
+ x: (e.x + n.x) / 2,
1071
+ y: (e.y + n.y) / 2
1072
+ };
1073
+ }
1074
+ return t.length === 1 ? {
1075
+ x: t[0].x,
1076
+ y: t[0].y
1077
+ } : {
1078
+ x: 0,
1079
+ y: 0
1080
+ };
1081
+ }
1082
+ let t = e;
1083
+ return {
1084
+ x: t.x + t.width / 2,
1085
+ y: t.y + t.height / 2
1086
+ };
1087
+ }
1088
+ //#endregion
1089
+ //#region src/label-editing/index.ts
1090
+ var at = {
1091
+ __init__: ["cmLabelEditing"],
1092
+ cmLabelEditing: ["type", rt]
1093
+ };
1094
+ //#endregion
1095
+ //#region src/keyboard/CmKeyboard.ts
1096
+ function ot(e) {
1097
+ let t = e;
1098
+ return t ? t.tagName === "INPUT" || t.tagName === "TEXTAREA" || t.tagName === "SELECT" || t.isContentEditable : !1;
1099
+ }
1100
+ var st = class {
1101
+ static $inject = [
1102
+ "canvas",
1103
+ "commandStack",
1104
+ "selection",
1105
+ "modeling"
1106
+ ];
1107
+ constructor(e, t, n, r) {
1108
+ (e.getContainer().ownerDocument ?? document).addEventListener("keydown", (e) => {
1109
+ if (ot(e.target)) return;
1110
+ let i = e.ctrlKey || e.metaKey, a = e.key.toLowerCase();
1111
+ if (i && a === "z" && !e.shiftKey) e.preventDefault(), t.canUndo() && t.undo();
1112
+ else if (i && a === "z" && e.shiftKey || i && a === "y") e.preventDefault(), t.canRedo() && t.redo();
1113
+ else if (a === "delete" || a === "backspace") {
1114
+ let t = n.get();
1115
+ t.length && (e.preventDefault(), r.removeElements([...t]));
1116
+ }
1117
+ });
1118
+ }
1119
+ }, ct = {
1120
+ __init__: ["cmKeyboard"],
1121
+ cmKeyboard: ["type", st]
1122
+ }, lt = "cm-validation", Q = 20, $ = 16, ut = 44, dt = "#d97706", ft = "#dc2626";
1123
+ function pt(e) {
1124
+ let t = e.some((e) => e.kind === "error") ? ft : dt, n = document.createElement("div");
1125
+ n.className = "cm-validation-marker", n.innerHTML = `<svg width="${Q}" height="${Q}" viewBox="0 0 24 24"><path d="M12 2.5 23 21.5H1Z" fill="${t}" stroke="#fff" stroke-width="1.6" stroke-linejoin="round"/><text x="12" y="18.5" text-anchor="middle" font-size="12" font-weight="800" fill="#fff" font-family="system-ui, sans-serif">!</text></svg>`;
1126
+ let r = document.createElement("div");
1127
+ r.className = "cm-validation-tooltip";
1128
+ for (let t of e) {
1129
+ let e = document.createElement("div");
1130
+ e.className = "cm-validation-tooltip__message", e.textContent = t.message, r.appendChild(e);
1131
+ }
1132
+ return n.appendChild(r), n;
1133
+ }
1134
+ function mt(e, t, n) {
1135
+ let r = t[0], i = t[t.length - 1], a = i.x - r.x, o = i.y - r.y, s = Math.hypot(a, o) || 1, c = a / s, l = o / s;
1136
+ if (n === "middle") return {
1137
+ x: (r.x + i.x) / 2 + -l * $,
1138
+ y: (r.y + i.y) / 2 + c * $
1139
+ };
1140
+ let u = e.pattern === "customer-supplier", d = n === "upstream" ? V(r, i, u ? "S" : "U", e.upstreamRoles ?? []) : V(i, r, u ? "C" : "D", e.downstreamRoles ?? []);
1141
+ if (d) {
1142
+ let e = {
1143
+ x: d.box.x + d.box.width,
1144
+ y: d.box.y + d.box.height
1145
+ };
1146
+ return {
1147
+ x: e.x + 1,
1148
+ y: e.y + 1
1149
+ };
1150
+ }
1151
+ let f = Math.min(ut, s * .35), p = n === "upstream" ? r.x + c * f : i.x - c * f, m = n === "upstream" ? r.y + l * f : i.y - l * f;
1152
+ return {
1153
+ x: p + -l * $,
1154
+ y: m + c * $
1155
+ };
1156
+ }
1157
+ //#endregion
1158
+ //#region src/validation/index.ts
1159
+ var ht = {
1160
+ __depends__: [ce],
1161
+ __init__: ["cmValidationMarkers"],
1162
+ cmValidationMarkers: ["type", class {
1163
+ elementRegistry;
1164
+ overlays;
1165
+ exporter;
1166
+ static $inject = [
1167
+ "eventBus",
1168
+ "elementRegistry",
1169
+ "overlays",
1170
+ "cmExporter"
1171
+ ];
1172
+ constructor(e, t, n, r) {
1173
+ this.elementRegistry = t, this.overlays = n, this.exporter = r;
1174
+ let i = () => this.refresh();
1175
+ e.on("import.render.done", i), e.on("commandStack.changed", i);
1176
+ }
1177
+ refresh() {
1178
+ this.overlays.remove({ type: lt });
1179
+ let e = u(this.exporter.export()), t = /* @__PURE__ */ new Map(), n = (e, n) => {
1180
+ for (let r of e) {
1181
+ if (!r.relationshipId) continue;
1182
+ let e = `${r.relationshipId} ${r.side ?? "middle"}`, i = t.get(e) ?? {
1183
+ relationshipId: r.relationshipId,
1184
+ findings: []
1185
+ };
1186
+ i.findings.push({
1187
+ ...r,
1188
+ kind: n
1189
+ }), t.set(e, i);
1190
+ }
1191
+ };
1192
+ n(e.errors, "error"), n(e.warnings, "warning");
1193
+ for (let [e, n] of t) {
1194
+ let t = this.elementRegistry.get(n.relationshipId);
1195
+ if (!O(t)) continue;
1196
+ let r = t.waypoints ?? [];
1197
+ if (r.length < 2) continue;
1198
+ let i = e.split(" ")[1], { x: a, y: o } = mt(t, r, i), s = Math.min(...r.map((e) => e.x)), c = Math.min(...r.map((e) => e.y));
1199
+ this.overlays.add(t, lt, {
1200
+ position: {
1201
+ left: a - s - Q / 2,
1202
+ top: o - c - Q / 2
1203
+ },
1204
+ html: pt(n.findings)
1205
+ });
1206
+ }
1207
+ }
1208
+ }]
1209
+ };
1210
+ //#endregion
1211
+ //#region src/zorder/CmZOrder.ts
1212
+ function gt(e) {
1213
+ return +!O(e);
1214
+ }
1215
+ var _t = class {
1216
+ canvas;
1217
+ elementRegistry;
1218
+ static $inject = [
1219
+ "eventBus",
1220
+ "canvas",
1221
+ "elementRegistry"
1222
+ ];
1223
+ importing = !1;
1224
+ constructor(e, t, n) {
1225
+ this.canvas = t, this.elementRegistry = n, e.on("import.render.start", () => {
1226
+ this.importing = !0;
1227
+ }), e.on("import.render.done", () => {
1228
+ this.importing = !1, this.reorder();
1229
+ }), e.on("commandStack.changed", () => {
1230
+ this.importing || this.reorder();
1231
+ });
1232
+ }
1233
+ reorder() {
1234
+ let e = this.elementRegistry.getAll().filter(E).sort((e, t) => gt(e) - gt(t));
1235
+ for (let t of e) {
1236
+ let e = this.canvas.getGraphics(t)?.parentNode, n = e?.parentNode;
1237
+ e && n && n.appendChild(e);
1238
+ }
1239
+ }
1240
+ }, vt = {
1241
+ __init__: ["cmZOrder"],
1242
+ cmZOrder: ["type", _t]
1243
+ }, yt = class extends Z {
1244
+ _getModules() {
1245
+ return [
1246
+ ...super._getModules(),
1247
+ x,
1248
+ S,
1249
+ C,
1250
+ w,
1251
+ ee,
1252
+ Oe,
1253
+ Me,
1254
+ Le,
1255
+ qe,
1256
+ nt,
1257
+ at,
1258
+ ct,
1259
+ ht,
1260
+ vt
1261
+ ];
1262
+ }
1263
+ undo() {
1264
+ this.get("commandStack").undo();
1265
+ }
1266
+ redo() {
1267
+ this.get("commandStack").redo();
1268
+ }
1269
+ canUndo() {
1270
+ return this.get("commandStack").canUndo();
1271
+ }
1272
+ canRedo() {
1273
+ return this.get("commandStack").canRedo();
1274
+ }
1275
+ };
1276
+ //#endregion
1277
+ export { de as CD_TOKENS, N as CmBaseViewer, tt as CmConnectHandles, P as CmElementFactory, J as CmExporter, Ne as CmFlatModelBehavior, q as CmImporter, st as CmKeyboard, rt as CmLabelEditing, De as CmModeling, Ke as CmPaletteProvider, ke as CmRules, _t as CmZOrder, U as ContextMapsRenderer, I as MIRAGON, yt as Modeler, Z as NavigatedViewer, j as ROOT_ID, X as Viewer, Le as cmBehaviorsModule, nt as cmConnectHandlesModule, W as cmDrawModule, ct as cmKeyboardModule, at as cmLabelEditingModule, F as cmModelModule, Oe as cmModelingModule, qe as cmPaletteModule, Me as cmRulesModule, vt as cmZOrderModule, He as contextIconSvg, Y as ioModule, D as isCmContext, E as isCmElement, O as isCmRelationship, Ue as relationshipIconSvg, A as saveSVG };
1278
+
1279
+ //# sourceMappingURL=index.js.map