whipped 0.8.0 → 0.9.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 (86) hide show
  1. package/dist/cli.js +1294 -259
  2. package/dist/mcp-server.js +150 -2
  3. package/dist/migrations/014_companion_sessions.sql +34 -0
  4. package/dist/migrations/015_companion_worktree_mode.sql +45 -0
  5. package/dist/migrations/016_companion_plans.sql +22 -0
  6. package/dist/migrations/017_companion_saved_plans.sql +23 -0
  7. package/dist/migrations/018_generalize_plan_session_ref.sql +29 -0
  8. package/dist/migrations/019_rename_plan_to_canvas.sql +20 -0
  9. package/dist/web-ui/assets/abnfDiagram-VRR7QNED-RwOyl_Kz.js +119 -0
  10. package/dist/web-ui/assets/arc-DmDBHE0H.js +131 -0
  11. package/dist/web-ui/assets/architectureDiagram-ZJ3FMSHR-RTwadm6J.js +8821 -0
  12. package/dist/web-ui/assets/blockDiagram-677ZJIJ3-Dvv5uMUE.js +3801 -0
  13. package/dist/web-ui/assets/c4Diagram-LMCZKHZV-bvr9R9cD.js +2479 -0
  14. package/dist/web-ui/assets/channel-BGhlETgZ.js +7 -0
  15. package/dist/web-ui/assets/chunk-2Q5K7J3B-BRq-Qbau.js +17 -0
  16. package/dist/web-ui/assets/chunk-32BRIVSS-Dy1BUZGx.js +116 -0
  17. package/dist/web-ui/assets/chunk-5VM5RSS4-DCUiIwIc.js +19 -0
  18. package/dist/web-ui/assets/chunk-EX3LRPZG-Cg_Vtzwz.js +1996 -0
  19. package/dist/web-ui/assets/chunk-JWPE2WC7-BW4n_ZhH.js +17 -0
  20. package/dist/web-ui/assets/chunk-MOJQB5TN-BykRa615.js +855 -0
  21. package/dist/web-ui/assets/chunk-RYQCIY6F-D4F7oV1d.js +476 -0
  22. package/dist/web-ui/assets/chunk-V7JOEXUC-DD4mm30h.js +2022 -0
  23. package/dist/web-ui/assets/chunk-VR4S4FIN-Fgvcluvk.js +25 -0
  24. package/dist/web-ui/assets/chunk-XXDRQBXY-C4FVmO5r.js +13 -0
  25. package/dist/web-ui/assets/classDiagram-OUVF2IWQ-DD4KIYF1.js +24 -0
  26. package/dist/web-ui/assets/classDiagram-v2-EOCWNBFH-DD4KIYF1.js +24 -0
  27. package/dist/web-ui/assets/cose-bilkent-JH36ORCC-ekFwvYt9.js +4943 -0
  28. package/dist/web-ui/assets/cynefin-VYW2F7L2-DTNV7gvQ.js +31527 -0
  29. package/dist/web-ui/assets/cynefinDiagram-TSTJHNR4-koYialeC.js +454 -0
  30. package/dist/web-ui/assets/cytoscape.esm-CaQ7Fomf.js +30346 -0
  31. package/dist/web-ui/assets/dagre-VKFMJZFB-Do43FV3o.js +526 -0
  32. package/dist/web-ui/assets/defaultLocale-B2RvLBDe.js +206 -0
  33. package/dist/web-ui/assets/diagram-FQU43EPY-D0STdny6.js +636 -0
  34. package/dist/web-ui/assets/diagram-G47NLZAW-D9g6BdZT.js +858 -0
  35. package/dist/web-ui/assets/diagram-NH7WQ7WH-zLW6CAmi.js +212 -0
  36. package/dist/web-ui/assets/diagram-OA4YK3LP-CA5tvsYw.js +492 -0
  37. package/dist/web-ui/assets/diagram-WEI45ONY-CLmYUHR0.js +309 -0
  38. package/dist/web-ui/assets/ebnfDiagram-CCIWWBDH-KkHubBI6.js +139 -0
  39. package/dist/web-ui/assets/erDiagram-Q63AITRT-BJna2u1n.js +1238 -0
  40. package/dist/web-ui/assets/flowDiagram-23GEKE2U-DVJKalah.js +2353 -0
  41. package/dist/web-ui/assets/ganttDiagram-NO4QXBWP-D9HwNV4u.js +3733 -0
  42. package/dist/web-ui/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  43. package/dist/web-ui/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  44. package/dist/web-ui/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  45. package/dist/web-ui/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  46. package/dist/web-ui/assets/geist-mono-cyrillic-ext-wght-normal-I4S5GZfc.woff2 +0 -0
  47. package/dist/web-ui/assets/geist-mono-cyrillic-wght-normal-BmXc_FBt.woff2 +0 -0
  48. package/dist/web-ui/assets/geist-mono-latin-ext-wght-normal-DrnZ1wKl.woff2 +0 -0
  49. package/dist/web-ui/assets/geist-mono-latin-wght-normal-B_7UjwxQ.woff2 +0 -0
  50. package/dist/web-ui/assets/geist-mono-symbols2-wght-normal-GZpp1pK2.woff2 +0 -0
  51. package/dist/web-ui/assets/geist-mono-vietnamese-wght-normal-D8KDMBhC.woff2 +0 -0
  52. package/dist/web-ui/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  53. package/dist/web-ui/assets/gitGraphDiagram-IHSO6WYX-B7wnoO0J.js +1385 -0
  54. package/dist/web-ui/assets/graph-BMLV0goG.js +2042 -0
  55. package/dist/web-ui/assets/{index-CRXPsGTP.css → index-DPjATOCj.css} +800 -1207
  56. package/dist/web-ui/assets/{index-CuGz83Sg.js → index-DZ7I8r_C.js} +41629 -39831
  57. package/dist/web-ui/assets/infoDiagram-FWYZ7A6U-BY6XoiF8.js +32 -0
  58. package/dist/web-ui/assets/init-ZxktEp_H.js +16 -0
  59. package/dist/web-ui/assets/ishikawaDiagram-FXEZZL3T-BaZVnO8j.js +967 -0
  60. package/dist/web-ui/assets/journeyDiagram-5HDEW3XC-CUA6DUAQ.js +1256 -0
  61. package/dist/web-ui/assets/kanban-definition-HUTT4EX6-5W5tiWrd.js +1055 -0
  62. package/dist/web-ui/assets/katex-CqNtglxf.js +14499 -0
  63. package/dist/web-ui/assets/layout-BNmRhaUB.js +2359 -0
  64. package/dist/web-ui/assets/linear-CfvGIyDE.js +340 -0
  65. package/dist/web-ui/assets/map-BEO0Bu8q.js +298 -0
  66. package/dist/web-ui/assets/mermaid.core-BRk3IzY2.js +26639 -0
  67. package/dist/web-ui/assets/mindmap-definition-LN4V7U3C-2GmLg6ou.js +1183 -0
  68. package/dist/web-ui/assets/ordinal-DSZU4PqD.js +76 -0
  69. package/dist/web-ui/assets/pegDiagram-2B236MQR-gTEdrkJg.js +127 -0
  70. package/dist/web-ui/assets/pieDiagram-ENE6RG2P-CYXjIhqC.js +318 -0
  71. package/dist/web-ui/assets/quadrantDiagram-ABIIQ3AL-BStRZxwf.js +1341 -0
  72. package/dist/web-ui/assets/railroadDiagram-RFXS5EU6-btveDRG2.js +93 -0
  73. package/dist/web-ui/assets/requirementDiagram-TGXJPOKE-Cy_155rE.js +1205 -0
  74. package/dist/web-ui/assets/sankeyDiagram-HTMAVEWB-Chtvw3_G.js +1264 -0
  75. package/dist/web-ui/assets/sequenceDiagram-DBY2YBRQ-DDuMVEX1.js +4523 -0
  76. package/dist/web-ui/assets/sizeCapture-X5ZJPWSS-Bylf0o6J.js +64 -0
  77. package/dist/web-ui/assets/stateDiagram-2N3HPSRC-DIzLeR5G.js +453 -0
  78. package/dist/web-ui/assets/stateDiagram-v2-6OUMAXLB-zG_WjT1-.js +23 -0
  79. package/dist/web-ui/assets/swimlanes-5IMT3BWC-TKaCmVta.js +8575 -0
  80. package/dist/web-ui/assets/swimlanesDiagram-G3AALYLV-C5eB3qqS.js +21 -0
  81. package/dist/web-ui/assets/timeline-definition-FHXFAJF6-CC5Ujpcu.js +1606 -0
  82. package/dist/web-ui/assets/vennDiagram-L72KCM5P-DUSVXSYT.js +2523 -0
  83. package/dist/web-ui/assets/wardleyDiagram-EHGQE667-CoP9xn89.js +978 -0
  84. package/dist/web-ui/assets/xychartDiagram-FW5EYKEG-B9FqP_kk.js +1972 -0
  85. package/dist/web-ui/index.html +2 -2
  86. package/package.json +14 -16
@@ -0,0 +1,636 @@
1
+ import { p as populateCommonDb } from "./chunk-JWPE2WC7-BW4n_ZhH.js";
2
+ import { o as getDiagramTitle, n as setDiagramTitle, s as setAccDescription, g as getAccDescription, a as getAccTitle, b as setAccTitle, _ as __name, l as log, c as getConfig2, d as select, z as setupGraphViewbox2, p as clear, A as cleanAndMerge, y as getConfig, B as defaultConfig_default, i as sanitizeText, w as wrapLabel, ak as calculateTextDimensions } from "./mermaid.core-BRk3IzY2.js";
3
+ import { p as parse, i as isEmResetFrame } from "./cynefin-VYW2F7L2-DTNV7gvQ.js";
4
+ import "./index-DZ7I8r_C.js";
5
+ var PositionFrameKind = "position frame";
6
+ var FramePositionedKind = "frame positioned";
7
+ var PositionRelationKind = "position relation";
8
+ var RelationPositionedKind = "relation positioned";
9
+ var setOptions = /* @__PURE__ */ __name(function(_rawOptString) {
10
+ log.debug("options str", _rawOptString);
11
+ }, "setOptions");
12
+ var getOptions = /* @__PURE__ */ __name(function() {
13
+ return {};
14
+ }, "getOptions");
15
+ var clear2 = /* @__PURE__ */ __name(function() {
16
+ reset();
17
+ clear();
18
+ }, "clear");
19
+ function reset() {
20
+ store = {};
21
+ }
22
+ __name(reset, "reset");
23
+ var DEFAULT_EVENTMODELING_CONFIG = defaultConfig_default.eventmodeling;
24
+ var getConfig3 = /* @__PURE__ */ __name(() => {
25
+ const config = cleanAndMerge({
26
+ ...DEFAULT_EVENTMODELING_CONFIG,
27
+ ...getConfig().eventmodeling
28
+ });
29
+ return config;
30
+ }, "getConfig");
31
+ var store = {};
32
+ function getState() {
33
+ let state = initial;
34
+ const { ast } = store;
35
+ const diagramProps2 = getDiagramProps();
36
+ if (!ast) {
37
+ throw new Error("No data for EventModel");
38
+ }
39
+ ast.frames.forEach((frame, index) => {
40
+ const textProps = calculateTextProps(frame, ast.dataEntities, diagramProps2);
41
+ state = dispatch(state, {
42
+ $kind: PositionFrameKind,
43
+ index,
44
+ frame,
45
+ textProps
46
+ });
47
+ let sourceFrames = void 0;
48
+ if (hasSourceFrame(frame)) {
49
+ log.debug(`source frame`, frame.sourceFrames);
50
+ sourceFrames = ast.frames.filter((currentFrame) => {
51
+ return frame.sourceFrames.some((sf) => sf.$refText === currentFrame.name);
52
+ });
53
+ sourceFrames.forEach((sourceFrame) => {
54
+ state = dispatch(state, {
55
+ $kind: PositionRelationKind,
56
+ index,
57
+ frame,
58
+ sourceFrame
59
+ });
60
+ });
61
+ } else {
62
+ state = dispatch(state, {
63
+ $kind: PositionRelationKind,
64
+ index,
65
+ frame
66
+ });
67
+ }
68
+ });
69
+ state = {
70
+ ...state,
71
+ sortedSwimlanesArray: sortedSwimlanesArray(state.swimlanes)
72
+ };
73
+ return state;
74
+ }
75
+ __name(getState, "getState");
76
+ function setAst(ast) {
77
+ store.ast = ast;
78
+ }
79
+ __name(setAst, "setAst");
80
+ var diagramProps = {
81
+ swimlaneMinHeight: 70,
82
+ swimlanePadding: 15,
83
+ swimlaneGap: 10,
84
+ boxPadding: 10,
85
+ boxOverlap: 90,
86
+ boxDefaultY: 0,
87
+ boxMinWidth: 80,
88
+ boxMaxWidth: 450,
89
+ boxMinHeight: 80,
90
+ boxMaxHeight: 750,
91
+ contentStartX: 250,
92
+ textMaxWidth: 450 - 2 * 10,
93
+ boxTextFontWeight: "bold",
94
+ boxTextPadding: 10,
95
+ swimlaneTextFontWeight: "bold",
96
+ labelUiAutomation: "UI/Automation",
97
+ labelUiAutomationPrefix: "UI/A: ",
98
+ labelCommandReadModel: "Command/Read Model",
99
+ labelCommandReadModelPrefix: "C/RM: ",
100
+ labelEvents: "Events",
101
+ labelEventsPrefix: "Stream: "
102
+ };
103
+ function getDiagramProps() {
104
+ return diagramProps;
105
+ }
106
+ __name(getDiagramProps, "getDiagramProps");
107
+ var initial = {
108
+ boxes: [],
109
+ swimlanes: {},
110
+ relations: [],
111
+ maxR: 0,
112
+ sortedSwimlanesArray: []
113
+ };
114
+ function extractNamespace(entityIdentifier) {
115
+ const spl = entityIdentifier.split(".");
116
+ if (spl.length === 2) {
117
+ return spl[0];
118
+ }
119
+ return void 0;
120
+ }
121
+ __name(extractNamespace, "extractNamespace");
122
+ function extractName(entityIdentifier) {
123
+ const spl = entityIdentifier.split(".");
124
+ if (spl.length === 2) {
125
+ return spl[1];
126
+ }
127
+ return entityIdentifier;
128
+ }
129
+ __name(extractName, "extractName");
130
+ function findSwimlaneByNamespace(swimlanes, namespace) {
131
+ if (!namespace || namespace.length === 0) {
132
+ return void 0;
133
+ }
134
+ return Object.values(swimlanes).find((swimlane) => swimlane.namespace === namespace);
135
+ }
136
+ __name(findSwimlaneByNamespace, "findSwimlaneByNamespace");
137
+ function findNextAvailableIndex(swimlanes, boundaryMin, boundaryMax) {
138
+ return Math.max(
139
+ boundaryMin,
140
+ ...Object.keys(swimlanes).filter((key) => {
141
+ const index = Number.parseInt(key);
142
+ return index > boundaryMin && index < boundaryMax;
143
+ }).map((key) => Number.parseInt(key))
144
+ ) + 1;
145
+ }
146
+ __name(findNextAvailableIndex, "findNextAvailableIndex");
147
+ function calculateSwimlaneProps(frame, swimlanes) {
148
+ const namespace = extractNamespace(frame.entityIdentifier);
149
+ const sw = findSwimlaneByNamespace(swimlanes, namespace);
150
+ switch (frame.modelEntityType) {
151
+ case "ui":
152
+ case "pcr":
153
+ case "processor":
154
+ if (sw) {
155
+ return {
156
+ index: sw.index,
157
+ label: sw.namespace || diagramProps.labelUiAutomation
158
+ };
159
+ } else if (namespace) {
160
+ return {
161
+ index: findNextAvailableIndex(swimlanes, 0, 100),
162
+ label: diagramProps.labelUiAutomationPrefix + namespace
163
+ };
164
+ }
165
+ return { index: 0, label: diagramProps.labelUiAutomation };
166
+ case "rmo":
167
+ case "readmodel":
168
+ case "cmd":
169
+ case "command":
170
+ if (sw) {
171
+ return {
172
+ index: sw.index,
173
+ label: sw.namespace || diagramProps.labelCommandReadModel
174
+ };
175
+ } else if (namespace) {
176
+ return {
177
+ index: findNextAvailableIndex(swimlanes, 100, 200),
178
+ label: diagramProps.labelCommandReadModelPrefix + namespace
179
+ };
180
+ }
181
+ return { index: 100, label: diagramProps.labelCommandReadModel };
182
+ case "evt":
183
+ case "event":
184
+ default:
185
+ if (sw) {
186
+ return {
187
+ index: sw.index,
188
+ label: sw.namespace || diagramProps.labelEvents
189
+ };
190
+ } else if (namespace) {
191
+ return {
192
+ index: findNextAvailableIndex(swimlanes, 200, 300),
193
+ label: diagramProps.labelEventsPrefix + namespace
194
+ };
195
+ }
196
+ return { index: 200, label: diagramProps.labelEvents };
197
+ }
198
+ }
199
+ __name(calculateSwimlaneProps, "calculateSwimlaneProps");
200
+ function calculateEntityVisualProps(frame) {
201
+ const { themeVariables } = getConfig();
202
+ switch (frame.modelEntityType) {
203
+ case "ui":
204
+ return {
205
+ fill: themeVariables.emUiFill ?? "white",
206
+ stroke: themeVariables.emUiStroke ?? "#dbdada"
207
+ };
208
+ case "pcr":
209
+ case "processor":
210
+ return {
211
+ fill: themeVariables.emProcessorFill ?? "#edb3f6",
212
+ stroke: themeVariables.emProcessorStroke ?? "#b88cbf"
213
+ };
214
+ case "rmo":
215
+ case "readmodel":
216
+ return {
217
+ fill: themeVariables.emReadModelFill ?? "#d3f1a2",
218
+ stroke: themeVariables.emReadModelStroke ?? "#a3b732"
219
+ };
220
+ case "cmd":
221
+ case "command":
222
+ return {
223
+ fill: themeVariables.emCommandFill ?? "#bcd6fe",
224
+ stroke: themeVariables.emCommandStroke ?? "#679ac3"
225
+ };
226
+ case "evt":
227
+ case "event":
228
+ return {
229
+ fill: themeVariables.emEventFill ?? "#ffb778",
230
+ stroke: themeVariables.emEventStroke ?? "#c19a0f"
231
+ };
232
+ default:
233
+ return {
234
+ fill: "red",
235
+ stroke: "black"
236
+ };
237
+ }
238
+ }
239
+ __name(calculateEntityVisualProps, "calculateEntityVisualProps");
240
+ function calculateTextProps(frame, dataEntities, diagramProps2) {
241
+ const config = getConfig();
242
+ const name = sanitizeText(extractName(frame.entityIdentifier) ?? "", config);
243
+ let toHtml;
244
+ const wrapLabelConfig = {
245
+ fontSize: 16,
246
+ fontWeight: 700,
247
+ fontFamily: '"trebuchet ms", verdana, arial, sans-serif',
248
+ joinWith: "<br/>"
249
+ };
250
+ const wrappedName = wrapLabel(name, diagramProps2.textMaxWidth, wrapLabelConfig);
251
+ let content = `<b>${wrappedName}</b>`;
252
+ if (frame.dataInlineValue) {
253
+ toHtml = frame.dataInlineValue;
254
+ toHtml = toHtml.substring(toHtml.indexOf("{") + 1);
255
+ toHtml = toHtml.substring(0, toHtml.lastIndexOf("}") - 1);
256
+ toHtml = sanitizeText(toHtml, config);
257
+ toHtml = wrapLabel(toHtml, diagramProps2.textMaxWidth, wrapLabelConfig);
258
+ toHtml = toHtml.replaceAll(" ", "&nbsp;");
259
+ }
260
+ if (frame.dataReference) {
261
+ const dataEntity = dataEntities.find(
262
+ (dataEntity2) => {
263
+ var _a;
264
+ return dataEntity2.name === ((_a = frame.dataReference) == null ? void 0 : _a.$refText);
265
+ }
266
+ );
267
+ if (dataEntity) {
268
+ toHtml = dataEntity.dataBlockValue;
269
+ toHtml = toHtml.substring(toHtml.indexOf("{\n") + 2);
270
+ toHtml = toHtml.substring(0, toHtml.lastIndexOf("}") - 1);
271
+ toHtml = sanitizeText(toHtml, config);
272
+ toHtml = wrapLabel(toHtml, diagramProps2.textMaxWidth, wrapLabelConfig);
273
+ toHtml = toHtml.replaceAll(" ", "&nbsp;");
274
+ toHtml += `<br/>`;
275
+ }
276
+ }
277
+ const hasRenderedData = toHtml !== void 0;
278
+ if (hasRenderedData) {
279
+ content += `<br/><br/><code style="text-align: left; display: block;max-width:${diagramProps2.textMaxWidth}px">${toHtml}</code>`;
280
+ }
281
+ const textDimensionConfig = {
282
+ fontSize: wrapLabelConfig.fontSize,
283
+ fontWeight: wrapLabelConfig.fontWeight,
284
+ fontFamily: wrapLabelConfig.fontFamily
285
+ };
286
+ const dimensions = calculateTextDimensions(content, textDimensionConfig);
287
+ const calculatedWidthFix = hasRenderedData ? dimensions.width / 3 : dimensions.width;
288
+ const props = {
289
+ content,
290
+ width: calculatedWidthFix,
291
+ height: dimensions.height
292
+ };
293
+ log.debug(`[${frame.name}] ${frame.entityIdentifier} text`, props);
294
+ return props;
295
+ }
296
+ __name(calculateTextProps, "calculateTextProps");
297
+ function decidePositionFrame(state, _command) {
298
+ const command = _command;
299
+ const visual = calculateEntityVisualProps(command.frame);
300
+ const dimension = {
301
+ width: command.textProps.width + 2 * diagramProps.boxTextPadding,
302
+ height: command.textProps.height + 2 * diagramProps.boxTextPadding
303
+ };
304
+ const event = {
305
+ $kind: FramePositionedKind,
306
+ frame: command.frame,
307
+ index: command.index,
308
+ visual,
309
+ dimension,
310
+ textProps: command.textProps
311
+ };
312
+ return [event];
313
+ }
314
+ __name(decidePositionFrame, "decidePositionFrame");
315
+ function calculateX(swimlane, previousSwimlane, lastBox) {
316
+ if (previousSwimlane === void 0) {
317
+ return diagramProps.contentStartX;
318
+ }
319
+ if (previousSwimlane.index === swimlane.index && swimlane.r) {
320
+ return swimlane.r + diagramProps.boxPadding;
321
+ }
322
+ if (lastBox === void 0) {
323
+ return diagramProps.contentStartX;
324
+ }
325
+ return lastBox.r - diagramProps.boxOverlap + diagramProps.boxPadding;
326
+ }
327
+ __name(calculateX, "calculateX");
328
+ function calculateMaxRight(swimlanes, swimlaneR) {
329
+ const rs = [...swimlanes.map((s) => s.r), swimlaneR];
330
+ return Math.max(...rs);
331
+ }
332
+ __name(calculateMaxRight, "calculateMaxRight");
333
+ function sortedSwimlanesArray(swimlanes) {
334
+ return Object.values(swimlanes).sort((a, b) => a.index - b.index);
335
+ }
336
+ __name(sortedSwimlanesArray, "sortedSwimlanesArray");
337
+ function evolveFramePositioned(state, _event) {
338
+ const event = _event;
339
+ const swimlaneProps = calculateSwimlaneProps(event.frame, state.swimlanes);
340
+ let swimlane;
341
+ if (swimlaneProps.index in state.swimlanes) {
342
+ swimlane = state.swimlanes[swimlaneProps.index];
343
+ } else {
344
+ swimlane = {
345
+ index: swimlaneProps.index,
346
+ label: swimlaneProps.label,
347
+ r: 0,
348
+ y: swimlaneProps.index * diagramProps.swimlaneMinHeight + diagramProps.swimlaneGap,
349
+ height: diagramProps.swimlaneMinHeight,
350
+ maxHeight: diagramProps.swimlaneMinHeight
351
+ };
352
+ }
353
+ const lastBox = state.boxes.length > 0 ? state.boxes[state.boxes.length - 1] : void 0;
354
+ const previousSwimlane = state.previousSwimlaneNumber !== void 0 ? state.swimlanes[state.previousSwimlaneNumber] : void 0;
355
+ const dimension = {
356
+ width: Math.max(
357
+ diagramProps.boxMinWidth,
358
+ Math.min(diagramProps.boxMaxWidth, event.dimension.width)
359
+ ) + 2 * diagramProps.boxPadding,
360
+ height: Math.max(
361
+ diagramProps.boxMinHeight,
362
+ Math.min(diagramProps.boxMaxHeight, event.dimension.height)
363
+ ) + 2 * diagramProps.boxPadding
364
+ };
365
+ const x = calculateX(swimlane, previousSwimlane, lastBox);
366
+ const r = x + dimension.width + diagramProps.boxPadding;
367
+ const maxR = calculateMaxRight(Object.values(state.swimlanes), r);
368
+ swimlane.r = x + dimension.width;
369
+ swimlane.maxHeight = Math.max(swimlane.maxHeight, dimension.height);
370
+ swimlane.height = Math.max(diagramProps.swimlaneMinHeight, swimlane.maxHeight) + 2 * diagramProps.swimlanePadding;
371
+ const box = {
372
+ x,
373
+ y: diagramProps.swimlanePadding + swimlane.y,
374
+ // y: diagramProps.swimlanePadding + (swimlane.y || diagramProps.boxDefaultY),
375
+ r,
376
+ dimension,
377
+ leftSibling: false,
378
+ swimlane,
379
+ visual: event.visual,
380
+ text: event.textProps.content,
381
+ frame: event.frame,
382
+ index: event.index
383
+ };
384
+ const newState = {
385
+ ...state,
386
+ boxes: [...state.boxes, box],
387
+ swimlanes: {
388
+ ...state.swimlanes,
389
+ [`${swimlane.index}`]: swimlane
390
+ },
391
+ previousSwimlaneNumber: swimlaneProps.index,
392
+ previousFrame: event.frame,
393
+ maxR
394
+ };
395
+ const swimlanes = sortedSwimlanesArray(newState.swimlanes);
396
+ if (swimlanes.length > 0) {
397
+ swimlanes[0].y = 0;
398
+ }
399
+ for (let i = 1; i < swimlanes.length; i++) {
400
+ const sw = swimlanes[i];
401
+ const prevSw = swimlanes[i - 1];
402
+ sw.y = prevSw.y + prevSw.height + diagramProps.swimlaneGap;
403
+ }
404
+ return newState;
405
+ }
406
+ __name(evolveFramePositioned, "evolveFramePositioned");
407
+ function isFirstFrame(index, frame) {
408
+ if (index === 0 && frame.sourceFrames.length === 0) {
409
+ return true;
410
+ }
411
+ return false;
412
+ }
413
+ __name(isFirstFrame, "isFirstFrame");
414
+ function hasSourceFrame(frame) {
415
+ return frame.sourceFrames !== void 0 && frame.sourceFrames !== null && frame.sourceFrames.length > 0;
416
+ }
417
+ __name(hasSourceFrame, "hasSourceFrame");
418
+ function findBoxByFrame(boxes, frame) {
419
+ if (frame === void 0 || frame === null) {
420
+ return void 0;
421
+ }
422
+ return boxes.find((box) => box.frame.name === frame.name);
423
+ }
424
+ __name(findBoxByFrame, "findBoxByFrame");
425
+ function findBoxByLineIndex(boxes, targetSwimlane, lineIndex) {
426
+ if (lineIndex < 0) {
427
+ return void 0;
428
+ }
429
+ for (let i = lineIndex; i >= 0; i--) {
430
+ const box = boxes[i];
431
+ if (box.swimlane.index !== targetSwimlane) {
432
+ return box;
433
+ }
434
+ }
435
+ return void 0;
436
+ }
437
+ __name(findBoxByLineIndex, "findBoxByLineIndex");
438
+ function decidePositionRelation(state, _command) {
439
+ const command = _command;
440
+ if (isEmResetFrame(command.frame) || isFirstFrame(command.index, command.frame)) {
441
+ return [];
442
+ }
443
+ const targetBox = findBoxByFrame(state.boxes, command.frame);
444
+ if (targetBox === void 0) {
445
+ throw new Error(`Target box not found for frame ${command.frame.name}`);
446
+ }
447
+ let sourceBox;
448
+ if (command.sourceFrame) {
449
+ sourceBox = findBoxByFrame(state.boxes, command.sourceFrame);
450
+ } else {
451
+ sourceBox = findBoxByLineIndex(state.boxes, targetBox.swimlane.index, command.index - 1);
452
+ }
453
+ if (sourceBox === void 0) {
454
+ return [];
455
+ }
456
+ const event = {
457
+ $kind: RelationPositionedKind,
458
+ frame: command.frame,
459
+ index: command.index,
460
+ sourceBox,
461
+ targetBox
462
+ };
463
+ return [event];
464
+ }
465
+ __name(decidePositionRelation, "decidePositionRelation");
466
+ function evolveRelationPositioned(state, _event) {
467
+ const event = _event;
468
+ const relation = {
469
+ visual: {
470
+ fill: "none",
471
+ stroke: "#000"
472
+ },
473
+ source: {
474
+ x: event.sourceBox.x,
475
+ y: event.sourceBox.y
476
+ },
477
+ target: {
478
+ x: event.targetBox.x,
479
+ y: event.targetBox.y
480
+ },
481
+ sourceBox: event.sourceBox,
482
+ targetBox: event.targetBox
483
+ };
484
+ const newState = {
485
+ ...state,
486
+ relations: [...state.relations, relation]
487
+ };
488
+ return newState;
489
+ }
490
+ __name(evolveRelationPositioned, "evolveRelationPositioned");
491
+ var deciders = {
492
+ [PositionFrameKind]: decidePositionFrame,
493
+ [PositionRelationKind]: decidePositionRelation
494
+ };
495
+ var evolvers = {
496
+ [FramePositionedKind]: evolveFramePositioned,
497
+ [RelationPositionedKind]: evolveRelationPositioned
498
+ };
499
+ function decide(state, command) {
500
+ const fn = deciders[command.$kind];
501
+ if (fn === void 0 || fn === null) {
502
+ return [];
503
+ }
504
+ const events = fn(state, command);
505
+ log.debug(`decided events`, events);
506
+ return events;
507
+ }
508
+ __name(decide, "decide");
509
+ function evolve(state, events) {
510
+ const newState = events.reduce((previousState, event) => {
511
+ const fn = evolvers[event.$kind];
512
+ if (fn === void 0 || fn === null) {
513
+ return previousState;
514
+ }
515
+ return fn(previousState, event);
516
+ }, state);
517
+ log.debug(`evolve events`, { state, newState, events });
518
+ return newState;
519
+ }
520
+ __name(evolve, "evolve");
521
+ function dispatch(state, command) {
522
+ const events = decide(state, command);
523
+ const newState = evolve(state, events);
524
+ return newState;
525
+ }
526
+ __name(dispatch, "dispatch");
527
+ var db = {
528
+ getConfig: getConfig3,
529
+ setOptions,
530
+ getOptions,
531
+ clear: clear2,
532
+ setAccTitle,
533
+ getAccTitle,
534
+ getAccDescription,
535
+ setAccDescription,
536
+ setDiagramTitle,
537
+ getDiagramTitle,
538
+ setAst,
539
+ getDiagramProps,
540
+ getState
541
+ };
542
+ var parser = {
543
+ parse: /* @__PURE__ */ __name(async (input) => {
544
+ const ast = await parse("eventmodeling", input);
545
+ log.debug(ast);
546
+ db.setAst(ast);
547
+ populateCommonDb(ast, db);
548
+ }, "parse")
549
+ };
550
+ var DEFAULT_CONFIG = getConfig2();
551
+ var DEFAULT_EVENTMODELING_CONFIG2 = DEFAULT_CONFIG == null ? void 0 : DEFAULT_CONFIG.eventmodeling;
552
+ function renderD3Box(diagram2, diagramProps2) {
553
+ return (box) => {
554
+ const y = box.swimlane.y + diagramProps2.swimlanePadding;
555
+ const g = diagram2.append("g").attr("class", "em-box");
556
+ g.append("rect").attr("x", box.x).attr("y", y).attr("rx", "3").attr("width", box.dimension.width).attr("height", box.dimension.height).attr("stroke", box.visual.stroke).attr("fill", box.visual.fill);
557
+ const f = g.append("foreignObject").attr("x", box.x + diagramProps2.boxPadding).attr("y", y + 10).attr("width", box.dimension.width - 2 * diagramProps2.boxPadding).attr("height", box.dimension.height - 2 * diagramProps2.boxPadding);
558
+ const text = f.append("xhtml:div").style("display", "table").style("height", "100%").style("width", "100%");
559
+ text.append("span").style("display", "table-cell").style("text-align", "center").style("vertical-align", "middle").html(box.text);
560
+ };
561
+ }
562
+ __name(renderD3Box, "renderD3Box");
563
+ function dirUpwards(sourceY, targetY) {
564
+ return sourceY > targetY;
565
+ }
566
+ __name(dirUpwards, "dirUpwards");
567
+ function renderD3Relation(diagram2, diagramProps2, arrowheadId, themeVariables) {
568
+ return (relation) => {
569
+ const sourceBoxY = relation.sourceBox.swimlane.y + diagramProps2.swimlanePadding;
570
+ const targetBoxY = relation.targetBox.swimlane.y + diagramProps2.swimlanePadding;
571
+ const upwards = dirUpwards(sourceBoxY, targetBoxY);
572
+ const sourceX = relation.sourceBox.x + relation.sourceBox.dimension.width * 2 / 3;
573
+ const targetX = relation.targetBox.x + relation.targetBox.dimension.width / 3;
574
+ let sourceY;
575
+ let targetY;
576
+ log.debug(`rendering relation up=${upwards} for `, {
577
+ sourceBox: relation.sourceBox,
578
+ targetBox: relation.targetBox
579
+ });
580
+ if (upwards) {
581
+ sourceY = sourceBoxY;
582
+ targetY = targetBoxY + relation.targetBox.dimension.height;
583
+ } else {
584
+ sourceY = sourceBoxY + relation.sourceBox.dimension.height;
585
+ targetY = targetBoxY;
586
+ }
587
+ const relationStroke = themeVariables.emRelationStroke ?? relation.visual.stroke;
588
+ diagram2.append("path").attr("class", "em-relation").attr("fill", relation.visual.fill).attr("stroke", relationStroke).attr("stroke-width", "1").attr("marker-end", `url(#${arrowheadId})`).attr("d", `M${sourceX} ${sourceY} L${targetX} ${targetY}`);
589
+ };
590
+ }
591
+ __name(renderD3Relation, "renderD3Relation");
592
+ function renderD3Swimlane(diagram2, maxR, diagramProps2, themeVariables) {
593
+ return (swimlane) => {
594
+ const g = diagram2.append("g").attr("class", "em-swimlane");
595
+ const oddBackground = themeVariables.emSwimlaneBackgroundOdd ?? "rgb(250,250,250)";
596
+ const backgroundStroke = themeVariables.emSwimlaneBackgroundStroke ?? "rgb(240,240,240)";
597
+ g.append("rect").attr("x", 0).attr("y", swimlane.y).attr("rx", "3").attr("width", maxR + diagramProps2.swimlanePadding).attr("height", swimlane.height).attr("fill", oddBackground).attr("stroke", backgroundStroke);
598
+ g.append("text").attr("font-weight", diagramProps2.swimlaneTextFontWeight).attr("x", 30).attr("y", swimlane.y + 30).text(swimlane.label);
599
+ };
600
+ }
601
+ __name(renderD3Swimlane, "renderD3Swimlane");
602
+ var draw = /* @__PURE__ */ __name(function(txt, id, ver, diagObj) {
603
+ log.debug("in eventmodeling renderer", txt + "\n", "id:", id, ver);
604
+ if (!DEFAULT_EVENTMODELING_CONFIG2) {
605
+ throw new Error("EventModeling config not found");
606
+ }
607
+ const db2 = diagObj.db;
608
+ const { themeVariables, eventmodeling: config } = getConfig2();
609
+ const diagram2 = select(`[id="${id}"]`);
610
+ const diagramProps2 = db2.getDiagramProps();
611
+ const state = db2.getState();
612
+ const arrowheadId = `em-arrowhead-${id}`;
613
+ const arrowheadColor = themeVariables.emArrowhead ?? "#000000";
614
+ state.sortedSwimlanesArray.forEach(
615
+ renderD3Swimlane(diagram2, state.maxR, diagramProps2, themeVariables)
616
+ );
617
+ state.boxes.forEach(renderD3Box(diagram2, diagramProps2));
618
+ state.relations.forEach(renderD3Relation(diagram2, diagramProps2, arrowheadId, themeVariables));
619
+ const marker = diagram2.append("defs").append("marker").attr("id", arrowheadId).attr("markerWidth", "10").attr("markerHeight", "7").attr("refX", "10").attr("refY", "3.5").attr("orient", "auto");
620
+ marker.append("polygon").attr("points", "0 0, 10 3.5, 0 7").attr("fill", arrowheadColor);
621
+ setupGraphViewbox2(void 0, diagram2, (config == null ? void 0 : config.padding) ?? 30, config == null ? void 0 : config.useMaxWidth);
622
+ }, "draw");
623
+ var renderer_default = {
624
+ draw
625
+ };
626
+ var getStyles = /* @__PURE__ */ __name((_options) => ``, "getStyles");
627
+ var styles_default = getStyles;
628
+ var diagram = {
629
+ parser,
630
+ db,
631
+ renderer: renderer_default,
632
+ styles: styles_default
633
+ };
634
+ export {
635
+ diagram
636
+ };