@emaarco/bpmn-js-data-simulation 0.0.0 → 0.2.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 (103) hide show
  1. package/README.md +99 -0
  2. package/dist/assets/bpmn-js-data-simulation.css +127 -0
  3. package/dist/domain/GatewayRouter.d.ts +11 -0
  4. package/dist/domain/GatewayRouter.d.ts.map +1 -0
  5. package/dist/domain/ScenarioError.d.ts +4 -0
  6. package/dist/domain/ScenarioError.d.ts.map +1 -0
  7. package/dist/domain/ScenarioParser.d.ts +7 -0
  8. package/dist/domain/ScenarioParser.d.ts.map +1 -0
  9. package/dist/domain/StartFieldCodec.d.ts +7 -0
  10. package/dist/domain/StartFieldCodec.d.ts.map +1 -0
  11. package/dist/domain/StartFieldDeriver.d.ts +7 -0
  12. package/dist/domain/StartFieldDeriver.d.ts.map +1 -0
  13. package/dist/domain/model.d.ts +64 -0
  14. package/dist/domain/model.d.ts.map +1 -0
  15. package/dist/engines/EngineRegistry.d.ts +6 -0
  16. package/dist/engines/EngineRegistry.d.ts.map +1 -0
  17. package/dist/engines/camunda7/Camunda7Engine.d.ts +17 -0
  18. package/dist/engines/camunda7/Camunda7Engine.d.ts.map +1 -0
  19. package/dist/engines/camunda7/juel/JuelError.d.ts +4 -0
  20. package/dist/engines/camunda7/juel/JuelError.d.ts.map +1 -0
  21. package/dist/engines/camunda7/juel/JuelEvaluator.d.ts +18 -0
  22. package/dist/engines/camunda7/juel/JuelEvaluator.d.ts.map +1 -0
  23. package/dist/engines/camunda7/juel/JuelLexer.d.ts +6 -0
  24. package/dist/engines/camunda7/juel/JuelLexer.d.ts.map +1 -0
  25. package/dist/engines/camunda7/juel/JuelParser.d.ts +19 -0
  26. package/dist/engines/camunda7/juel/JuelParser.d.ts.map +1 -0
  27. package/dist/engines/camunda7/juel/JuelTemplate.d.ts +11 -0
  28. package/dist/engines/camunda7/juel/JuelTemplate.d.ts.map +1 -0
  29. package/dist/engines/camunda7/juel/juelSyntax.d.ts +34 -0
  30. package/dist/engines/camunda7/juel/juelSyntax.d.ts.map +1 -0
  31. package/dist/engines/engines.d.ts +5 -0
  32. package/dist/engines/engines.d.ts.map +1 -0
  33. package/dist/engines/types.d.ts +21 -0
  34. package/dist/engines/types.d.ts.map +1 -0
  35. package/dist/engines/zeebe/ZeebeEngine.d.ts +21 -0
  36. package/dist/engines/zeebe/ZeebeEngine.d.ts.map +1 -0
  37. package/dist/index.cjs +2099 -0
  38. package/dist/index.cjs.map +1 -0
  39. package/dist/index.d.ts +17 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +2084 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/integration/DataGateways.d.ts +21 -0
  44. package/dist/integration/DataGateways.d.ts.map +1 -0
  45. package/dist/integration/DataSimulation.d.ts +35 -0
  46. package/dist/integration/DataSimulation.d.ts.map +1 -0
  47. package/dist/integration/DataSimulationOverlays.d.ts +23 -0
  48. package/dist/integration/DataSimulationOverlays.d.ts.map +1 -0
  49. package/dist/integration/DataSimulationPanel.d.ts +14 -0
  50. package/dist/integration/DataSimulationPanel.d.ts.map +1 -0
  51. package/dist/integration/DataSimulationToggle.d.ts +19 -0
  52. package/dist/integration/DataSimulationToggle.d.ts.map +1 -0
  53. package/dist/integration/DataStartForm.d.ts +19 -0
  54. package/dist/integration/DataStartForm.d.ts.map +1 -0
  55. package/dist/integration/IoMappings.d.ts +11 -0
  56. package/dist/integration/IoMappings.d.ts.map +1 -0
  57. package/dist/integration/VariableUsageCollector.d.ts +11 -0
  58. package/dist/integration/VariableUsageCollector.d.ts.map +1 -0
  59. package/dist/integration/behaviors/DataContextPads.d.ts +29 -0
  60. package/dist/integration/behaviors/DataContextPads.d.ts.map +1 -0
  61. package/dist/integration/behaviors/DataGatewayBehaviors.d.ts +13 -0
  62. package/dist/integration/behaviors/DataGatewayBehaviors.d.ts.map +1 -0
  63. package/dist/integration/behaviors/DataGatewaySettings.d.ts +18 -0
  64. package/dist/integration/behaviors/DataGatewaySettings.d.ts.map +1 -0
  65. package/dist/integration/index.d.ts +7 -0
  66. package/dist/integration/index.d.ts.map +1 -0
  67. package/dist/integration/tokenSimulation.d.ts +95 -0
  68. package/dist/integration/tokenSimulation.d.ts.map +1 -0
  69. package/dist/simulation/DataSimulationStore.d.ts +85 -0
  70. package/dist/simulation/DataSimulationStore.d.ts.map +1 -0
  71. package/dist/simulation/GatewayDecisionView.d.ts +10 -0
  72. package/dist/simulation/GatewayDecisionView.d.ts.map +1 -0
  73. package/dist/ui/DecisionCard.d.ts +8 -0
  74. package/dist/ui/DecisionCard.d.ts.map +1 -0
  75. package/dist/ui/OutcomeBadge.d.ts +6 -0
  76. package/dist/ui/OutcomeBadge.d.ts.map +1 -0
  77. package/dist/ui/SimpleStartForm.d.ts +16 -0
  78. package/dist/ui/SimpleStartForm.d.ts.map +1 -0
  79. package/dist/ui/SimpleStartFormRenderer.d.ts +6 -0
  80. package/dist/ui/SimpleStartFormRenderer.d.ts.map +1 -0
  81. package/dist/ui/StartDialog.d.ts +40 -0
  82. package/dist/ui/StartDialog.d.ts.map +1 -0
  83. package/dist/ui/VariablesPanel.d.ts +34 -0
  84. package/dist/ui/VariablesPanel.d.ts.map +1 -0
  85. package/dist/ui/startForm.d.ts +17 -0
  86. package/dist/ui/startForm.d.ts.map +1 -0
  87. package/dist/utils/badgePosition.d.ts +10 -0
  88. package/dist/utils/badgePosition.d.ts.map +1 -0
  89. package/dist/utils/diagramElements.d.ts +7 -0
  90. package/dist/utils/diagramElements.d.ts.map +1 -0
  91. package/dist/utils/dom.d.ts +5 -0
  92. package/dist/utils/dom.d.ts.map +1 -0
  93. package/dist/utils/moddle.d.ts +8 -0
  94. package/dist/utils/moddle.d.ts.map +1 -0
  95. package/dist/utils/objects.d.ts +3 -0
  96. package/dist/utils/objects.d.ts.map +1 -0
  97. package/dist/utils/popoverPlacement.d.ts +18 -0
  98. package/dist/utils/popoverPlacement.d.ts.map +1 -0
  99. package/dist/utils/shadow.d.ts +2 -0
  100. package/dist/utils/shadow.d.ts.map +1 -0
  101. package/dist/utils/variables.d.ts +5 -0
  102. package/dist/utils/variables.d.ts.map +1 -0
  103. package/package.json +80 -3
package/dist/index.js ADDED
@@ -0,0 +1,2084 @@
1
+ import { evaluate, parseExpression } from 'feelin';
2
+
3
+ class GatewayRouter {
4
+ route(kind, outgoing, evaluateCondition) {
5
+ const conditional = outgoing.filter((flow) => !flow.isDefault);
6
+ const defaultFlow = outgoing.find((flow) => flow.isDefault);
7
+ const evaluations = [];
8
+ for (const flow of conditional) {
9
+ const alreadyDecided = kind === "exclusive" && evaluations.some((evaluation) => this.isDecisive(evaluation));
10
+ evaluations.push(alreadyDecided ? { flow, outcome: "skipped" } : this.evaluateFlow(flow, evaluateCondition));
11
+ }
12
+ const failed = evaluations.find((evaluation) => evaluation.outcome === "error");
13
+ if (failed) {
14
+ return this.stuck(
15
+ evaluations,
16
+ defaultFlow,
17
+ `Condition of "${failed.flow.name ?? failed.flow.id}" failed: ${failed.reason}`
18
+ );
19
+ }
20
+ const taken = evaluations.filter((evaluation) => evaluation.outcome === "taken");
21
+ if (taken.length) {
22
+ return this.withDefault(
23
+ evaluations,
24
+ defaultFlow,
25
+ "not-taken",
26
+ taken.map((evaluation) => evaluation.flow.id)
27
+ );
28
+ }
29
+ if (defaultFlow) {
30
+ return this.withDefault(evaluations, defaultFlow, "taken", [defaultFlow.id]);
31
+ }
32
+ return this.stuck(evaluations, defaultFlow, "No condition is true and there is no default flow");
33
+ }
34
+ evaluateFlow(flow, evaluateCondition) {
35
+ if (flow.expression === void 0) {
36
+ return { flow, outcome: "error", reason: "Missing condition" };
37
+ }
38
+ const evaluation = evaluateCondition(flow.expression);
39
+ if (!evaluation.ok) {
40
+ return { flow, outcome: "error", reason: evaluation.reason };
41
+ }
42
+ if (typeof evaluation.value !== "boolean") {
43
+ return {
44
+ flow,
45
+ outcome: "error",
46
+ value: evaluation.value,
47
+ reason: `Expected a boolean but got ${this.describe(evaluation.value)}`
48
+ };
49
+ }
50
+ return { flow, outcome: evaluation.value ? "taken" : "not-taken", value: evaluation.value };
51
+ }
52
+ isDecisive(evaluation) {
53
+ return evaluation.outcome === "taken" || evaluation.outcome === "error";
54
+ }
55
+ withDefault(evaluations, defaultFlow, defaultOutcome, takenFlowIds) {
56
+ const flows = defaultFlow ? [...evaluations, { flow: defaultFlow, outcome: defaultOutcome }] : evaluations;
57
+ return { flows, takenFlowIds };
58
+ }
59
+ stuck(evaluations, defaultFlow, stuckReason) {
60
+ return { ...this.withDefault(evaluations, defaultFlow, "skipped", []), stuckReason };
61
+ }
62
+ describe(value) {
63
+ if (value === null || value === void 0) return "null";
64
+ return `${typeof value} ${JSON.stringify(value)}`;
65
+ }
66
+ }
67
+
68
+ class ScenarioError extends Error {
69
+ constructor() {
70
+ super(...arguments);
71
+ this.name = "ScenarioError";
72
+ }
73
+ }
74
+
75
+ function setVariable(variables, path, value) {
76
+ const [head, ...rest] = path.split(".");
77
+ if (!rest.length) {
78
+ return { ...variables, [head]: value };
79
+ }
80
+ const nested = variables[head];
81
+ const nestedVariables = isVariables(nested) ? nested : {};
82
+ return { ...variables, [head]: setVariable(nestedVariables, rest.join("."), value) };
83
+ }
84
+ function isVariables(value) {
85
+ return typeof value === "object" && value !== null && !Array.isArray(value);
86
+ }
87
+ function withoutKeys(variables, keys) {
88
+ return Object.fromEntries(Object.entries(variables).filter(([key]) => !keys.includes(key)));
89
+ }
90
+
91
+ class ScenarioParser {
92
+ parse(input) {
93
+ const list = isVariables(input) ? input.scenarios : input;
94
+ if (!Array.isArray(list)) {
95
+ throw new ScenarioError('Expected an array of scenarios or an object with a "scenarios" array');
96
+ }
97
+ const scenarios = list.map((raw, index) => this.parseScenario(raw, index));
98
+ this.assertUniqueIds(scenarios);
99
+ return scenarios;
100
+ }
101
+ parseScenario(raw, index) {
102
+ if (!isVariables(raw)) {
103
+ throw new ScenarioError(`Scenario #${index + 1} must be an object`);
104
+ }
105
+ const { id, name, description, variables = {}, taskResults = {} } = raw;
106
+ const label = typeof id === "string" ? `"${id}"` : `#${index + 1}`;
107
+ if (typeof id !== "string" || !id) {
108
+ throw new ScenarioError(`Scenario ${label} needs a non-empty string "id"`);
109
+ }
110
+ if (name !== void 0 && typeof name !== "string") {
111
+ throw new ScenarioError(`Scenario ${label}: "name" must be a string`);
112
+ }
113
+ if (description !== void 0 && typeof description !== "string") {
114
+ throw new ScenarioError(`Scenario ${label}: "description" must be a string`);
115
+ }
116
+ if (!isVariables(variables)) {
117
+ throw new ScenarioError(`Scenario ${label}: "variables" must be an object`);
118
+ }
119
+ if (!isVariables(taskResults) || !Object.values(taskResults).every(isVariables)) {
120
+ throw new ScenarioError(`Scenario ${label}: "taskResults" must map element ids to objects`);
121
+ }
122
+ return {
123
+ id,
124
+ name: name ?? id,
125
+ ...description === void 0 ? {} : { description },
126
+ variables,
127
+ taskResults
128
+ };
129
+ }
130
+ assertUniqueIds(scenarios) {
131
+ const seen = /* @__PURE__ */ new Set();
132
+ for (const { id } of scenarios) {
133
+ if (seen.has(id)) {
134
+ throw new ScenarioError(`Duplicate scenario id "${id}"`);
135
+ }
136
+ seen.add(id);
137
+ }
138
+ }
139
+ }
140
+
141
+ class StartFieldCodec {
142
+ parse(field, raw) {
143
+ if (typeof raw === "boolean") return { ok: true, value: raw };
144
+ const text = raw.trim();
145
+ if (!text) return { ok: true, value: void 0 };
146
+ switch (field.type) {
147
+ case "number": {
148
+ const value = Number(text);
149
+ return Number.isNaN(value) ? { ok: false, reason: `${field.name} must be a number` } : { ok: true, value };
150
+ }
151
+ case "json":
152
+ try {
153
+ return { ok: true, value: JSON.parse(text) };
154
+ } catch {
155
+ return { ok: false, reason: `${field.name} must be valid JSON` };
156
+ }
157
+ case "auto":
158
+ try {
159
+ return { ok: true, value: JSON.parse(text) };
160
+ } catch {
161
+ return { ok: true, value: raw };
162
+ }
163
+ default:
164
+ return { ok: true, value: raw };
165
+ }
166
+ }
167
+ format(field, value) {
168
+ if (field.type === "boolean") return value === true;
169
+ if (value === void 0 || value === null) return "";
170
+ if (typeof value === "string" && field.type !== "json") return value;
171
+ return field.type === "number" ? String(value) : JSON.stringify(value);
172
+ }
173
+ apply(base, values) {
174
+ const variables = { ...base };
175
+ for (const [name, value] of Object.entries(values)) {
176
+ if (value === void 0) delete variables[name];
177
+ else variables[name] = value;
178
+ }
179
+ return variables;
180
+ }
181
+ }
182
+
183
+ function findExtension(element, type) {
184
+ const extensionElements = element.extensionElements;
185
+ return extensionElements?.values?.find((value) => value.$type === type);
186
+ }
187
+ function listProperty(element, property) {
188
+ const value = element?.[property];
189
+ return Array.isArray(value) ? value : [];
190
+ }
191
+ function readConditionExpression(sequenceFlow) {
192
+ const condition = sequenceFlow.conditionExpression;
193
+ if (!condition) return void 0;
194
+ return {
195
+ body: typeof condition.body === "string" ? condition.body : void 0,
196
+ language: typeof condition.language === "string" ? condition.language : void 0
197
+ };
198
+ }
199
+
200
+ class JuelError extends Error {
201
+ constructor() {
202
+ super(...arguments);
203
+ this.name = "JuelError";
204
+ }
205
+ }
206
+
207
+ function hasOwn(object, key) {
208
+ return Object.prototype.hasOwnProperty.call(object, key);
209
+ }
210
+ function deepEqual(left, right) {
211
+ if (left === right) return true;
212
+ if (typeof left !== "object" || typeof right !== "object" || left === null || right === null) return false;
213
+ if (Array.isArray(left) !== Array.isArray(right)) return false;
214
+ const leftKeys = Object.keys(left);
215
+ const rightKeys = Object.keys(right);
216
+ return leftKeys.length === rightKeys.length && leftKeys.every(
217
+ (key) => hasOwn(right, key) && deepEqual(left[key], right[key])
218
+ );
219
+ }
220
+
221
+ class JuelEvaluator {
222
+ constructor(variables) {
223
+ this.variables = variables;
224
+ }
225
+ evaluate(node) {
226
+ switch (node.type) {
227
+ case "literal":
228
+ return node.value;
229
+ case "identifier":
230
+ if (!hasOwn(this.variables, node.name)) {
231
+ throw new JuelError(`Unknown property used in expression: ${node.name}`);
232
+ }
233
+ return this.variables[node.name];
234
+ case "member":
235
+ return this.readMember(this.evaluate(node.object), this.evaluate(node.property));
236
+ case "unary":
237
+ return this.evaluateUnary(node.operator, this.evaluate(node.operand));
238
+ case "conditional":
239
+ return this.coerceToBoolean(this.evaluate(node.test)) ? this.evaluate(node.consequent) : this.evaluate(node.alternate);
240
+ case "binary":
241
+ return this.evaluateBinary(node);
242
+ }
243
+ }
244
+ coerceToString(value) {
245
+ if (value === null || value === void 0) return "";
246
+ return typeof value === "object" ? JSON.stringify(value) : String(value);
247
+ }
248
+ readMember(object, property) {
249
+ if (object === null || object === void 0) return null;
250
+ const key = Array.isArray(object) ? Number(property) : String(property);
251
+ return hasOwn(object, key) ? object[key] ?? null : null;
252
+ }
253
+ evaluateUnary(operator, operand) {
254
+ if (operator === "!") return !this.coerceToBoolean(operand);
255
+ if (operator === "-") return -this.coerceToNumber(operand);
256
+ return this.isEmpty(operand);
257
+ }
258
+ evaluateBinary(node) {
259
+ const { operator } = node;
260
+ if (operator === "&&") {
261
+ return this.coerceToBoolean(this.evaluate(node.left)) && this.coerceToBoolean(this.evaluate(node.right));
262
+ }
263
+ if (operator === "||") {
264
+ return this.coerceToBoolean(this.evaluate(node.left)) || this.coerceToBoolean(this.evaluate(node.right));
265
+ }
266
+ const left = this.evaluate(node.left);
267
+ const right = this.evaluate(node.right);
268
+ const eitherIsNull = this.isNull(left) || this.isNull(right);
269
+ const bothAreNull = this.isNull(left) && this.isNull(right);
270
+ switch (operator) {
271
+ case "==":
272
+ return this.areEqual(left, right);
273
+ case "!=":
274
+ return !this.areEqual(left, right);
275
+ case "<":
276
+ return eitherIsNull ? false : this.compare(left, right) < 0;
277
+ case ">":
278
+ return eitherIsNull ? false : this.compare(left, right) > 0;
279
+ case "<=":
280
+ return eitherIsNull ? bothAreNull : this.compare(left, right) <= 0;
281
+ case ">=":
282
+ return eitherIsNull ? bothAreNull : this.compare(left, right) >= 0;
283
+ case "+":
284
+ return this.coerceToNumber(left) + this.coerceToNumber(right);
285
+ case "-":
286
+ return this.coerceToNumber(left) - this.coerceToNumber(right);
287
+ case "*":
288
+ return this.coerceToNumber(left) * this.coerceToNumber(right);
289
+ case "/":
290
+ return this.coerceToNumber(left) / this.coerceToNumber(right);
291
+ default:
292
+ return this.coerceToNumber(left) % this.coerceToNumber(right);
293
+ }
294
+ }
295
+ isNull(value) {
296
+ return value === null || value === void 0;
297
+ }
298
+ areEqual(left, right) {
299
+ if (left === right) return true;
300
+ if (this.isNull(left) || this.isNull(right)) return this.isNull(left) && this.isNull(right);
301
+ if (typeof left === "number" || typeof right === "number") {
302
+ return this.coerceToNumber(left) === this.coerceToNumber(right);
303
+ }
304
+ if (typeof left === "boolean" || typeof right === "boolean") {
305
+ return this.coerceToBoolean(left) === this.coerceToBoolean(right);
306
+ }
307
+ if (typeof left === "object" || typeof right === "object") return deepEqual(left, right);
308
+ return String(left) === String(right);
309
+ }
310
+ compare(left, right) {
311
+ if (typeof left === "string" && typeof right === "string") return left < right ? -1 : left > right ? 1 : 0;
312
+ return this.coerceToNumber(left) - this.coerceToNumber(right);
313
+ }
314
+ coerceToNumber(value) {
315
+ if (value === null || value === void 0 || value === "") return 0;
316
+ const number = typeof value === "number" ? value : Number(value);
317
+ if (typeof value === "boolean" || Number.isNaN(number)) {
318
+ throw new JuelError(`Cannot coerce ${JSON.stringify(value)} to a number`);
319
+ }
320
+ return number;
321
+ }
322
+ coerceToBoolean(value) {
323
+ if (typeof value === "boolean") return value;
324
+ if (value === null || value === void 0 || value === "") return false;
325
+ if (typeof value === "string") return value.toLowerCase() === "true";
326
+ throw new JuelError(`Cannot coerce ${JSON.stringify(value)} to a boolean`);
327
+ }
328
+ isEmpty(value) {
329
+ if (value === null || value === void 0 || value === "") return true;
330
+ if (Array.isArray(value)) return value.length === 0;
331
+ if (typeof value === "object") return Object.keys(value).length === 0;
332
+ return false;
333
+ }
334
+ }
335
+
336
+ const KEYWORD_OPERATORS = {
337
+ and: "&&",
338
+ or: "||",
339
+ not: "!",
340
+ eq: "==",
341
+ ne: "!=",
342
+ lt: "<",
343
+ gt: ">",
344
+ le: "<=",
345
+ ge: ">=",
346
+ div: "/",
347
+ mod: "%",
348
+ empty: "empty"
349
+ };
350
+ const SYMBOL_OPERATORS = [
351
+ "==",
352
+ "!=",
353
+ "<=",
354
+ ">=",
355
+ "&&",
356
+ "||",
357
+ "<",
358
+ ">",
359
+ "!",
360
+ "+",
361
+ "-",
362
+ "*",
363
+ "/",
364
+ "%",
365
+ "(",
366
+ ")",
367
+ "[",
368
+ "]",
369
+ ".",
370
+ "?",
371
+ ":"
372
+ ];
373
+ const BINARY_PRECEDENCE = [
374
+ ["||"],
375
+ ["&&"],
376
+ ["==", "!="],
377
+ ["<", ">", "<=", ">="],
378
+ ["+", "-"],
379
+ ["*", "/", "%"]
380
+ ];
381
+
382
+ class JuelLexer {
383
+ tokenize(source) {
384
+ const tokens = [];
385
+ let index = 0;
386
+ while (index < source.length) {
387
+ const char = source[index];
388
+ if (/\s/.test(char)) {
389
+ index++;
390
+ } else if (/[0-9]/.test(char) || char === "." && /[0-9]/.test(source[index + 1] ?? "")) {
391
+ const match = /^[0-9]*\.?[0-9]+(?:[eE][+-]?[0-9]+)?/.exec(source.slice(index));
392
+ tokens.push({ kind: "number", text: match[0], value: Number(match[0]) });
393
+ index += match[0].length;
394
+ } else if (char === "'" || char === '"') {
395
+ const { value, length } = this.readString(source, index);
396
+ tokens.push({ kind: "string", text: source.slice(index, index + length), value });
397
+ index += length;
398
+ } else if (/[A-Za-z_$]/.test(char)) {
399
+ const match = /^[A-Za-z_$][A-Za-z0-9_$]*/.exec(source.slice(index));
400
+ const word = match[0];
401
+ const keywordOperator = hasOwn(KEYWORD_OPERATORS, word) ? KEYWORD_OPERATORS[word] : void 0;
402
+ tokens.push(keywordOperator ? { kind: "operator", text: keywordOperator } : { kind: "identifier", text: word });
403
+ index += word.length;
404
+ } else {
405
+ const operator = SYMBOL_OPERATORS.find((candidate) => source.startsWith(candidate, index));
406
+ if (!operator) throw new JuelError(`Unexpected character "${char}"`);
407
+ tokens.push({ kind: "operator", text: operator });
408
+ index += operator.length;
409
+ }
410
+ }
411
+ return tokens;
412
+ }
413
+ readString(source, start) {
414
+ const quote = source[start];
415
+ let value = "";
416
+ for (let index = start + 1; index < source.length; index++) {
417
+ const char = source[index];
418
+ if (char === "\\") {
419
+ value += source[index + 1] ?? "";
420
+ index++;
421
+ } else if (char === quote) {
422
+ return { value, length: index - start + 1 };
423
+ } else {
424
+ value += char;
425
+ }
426
+ }
427
+ throw new JuelError("Unterminated string literal");
428
+ }
429
+ }
430
+
431
+ class JuelParser {
432
+ constructor(source) {
433
+ this.position = 0;
434
+ this.tokens = new JuelLexer().tokenize(source);
435
+ }
436
+ parse() {
437
+ const node = this.parseExpression();
438
+ const token = this.peek();
439
+ if (token) throw new JuelError(`Unexpected "${token.text}"`);
440
+ return node;
441
+ }
442
+ parseExpression() {
443
+ const test = this.parseBinary(0);
444
+ if (!this.accept("?")) return test;
445
+ const consequent = this.parseExpression();
446
+ this.expect(":");
447
+ const alternate = this.parseExpression();
448
+ return { type: "conditional", test, consequent, alternate };
449
+ }
450
+ parseBinary(level) {
451
+ if (level === BINARY_PRECEDENCE.length) return this.parseUnary();
452
+ let left = this.parseBinary(level + 1);
453
+ let operator = this.acceptAny(BINARY_PRECEDENCE[level]);
454
+ while (operator) {
455
+ const right = this.parseBinary(level + 1);
456
+ left = { type: "binary", operator, left, right };
457
+ operator = this.acceptAny(BINARY_PRECEDENCE[level]);
458
+ }
459
+ return left;
460
+ }
461
+ parseUnary() {
462
+ const operator = this.acceptAny(["!", "-", "empty"]);
463
+ if (operator) return { type: "unary", operator, operand: this.parseUnary() };
464
+ return this.parseMember();
465
+ }
466
+ parseMember() {
467
+ let node = this.parsePrimary();
468
+ for (; ; ) {
469
+ if (this.accept(".")) {
470
+ const property = this.next();
471
+ if (property?.kind !== "identifier") throw new JuelError('Expected a property name after "."');
472
+ node = { type: "member", object: node, property: { type: "literal", value: property.text } };
473
+ } else if (this.accept("[")) {
474
+ node = { type: "member", object: node, property: this.parseExpression() };
475
+ this.expect("]");
476
+ } else if (this.peek()?.text === "(") {
477
+ throw new JuelError("Method calls are not supported");
478
+ } else {
479
+ return node;
480
+ }
481
+ }
482
+ }
483
+ parsePrimary() {
484
+ const token = this.next();
485
+ if (!token) throw new JuelError("Unexpected end of expression");
486
+ if (token.kind === "number" || token.kind === "string") return { type: "literal", value: token.value };
487
+ if (token.kind === "identifier") return this.identifierOrLiteral(token.text);
488
+ if (token.text === "(") {
489
+ const node = this.parseExpression();
490
+ this.expect(")");
491
+ return node;
492
+ }
493
+ throw new JuelError(`Unexpected "${token.text}"`);
494
+ }
495
+ identifierOrLiteral(name) {
496
+ if (name === "true") return { type: "literal", value: true };
497
+ if (name === "false") return { type: "literal", value: false };
498
+ if (name === "null") return { type: "literal", value: null };
499
+ return { type: "identifier", name };
500
+ }
501
+ peek() {
502
+ return this.tokens[this.position];
503
+ }
504
+ next() {
505
+ return this.tokens[this.position++];
506
+ }
507
+ accept(text) {
508
+ if (this.peek()?.kind !== "operator" || this.peek()?.text !== text) return false;
509
+ this.position++;
510
+ return true;
511
+ }
512
+ acceptAny(operators) {
513
+ return operators.find((operator) => this.accept(operator));
514
+ }
515
+ expect(text) {
516
+ if (!this.accept(text)) throw new JuelError(`Expected "${text}"`);
517
+ }
518
+ }
519
+
520
+ class JuelTemplate {
521
+ constructor(parts) {
522
+ this.parts = parts;
523
+ }
524
+ static parse(text) {
525
+ const parts = [];
526
+ let cursor = 0;
527
+ while (cursor < text.length) {
528
+ const start = JuelTemplate.findExpressionStart(text, cursor);
529
+ if (start === -1) {
530
+ parts.push(text.slice(cursor));
531
+ break;
532
+ }
533
+ if (start > cursor) parts.push(text.slice(cursor, start));
534
+ const end = JuelTemplate.findExpressionEnd(text, start + 2);
535
+ parts.push(new JuelParser(text.slice(start + 2, end)).parse());
536
+ cursor = end + 1;
537
+ }
538
+ return new JuelTemplate(parts);
539
+ }
540
+ evaluate(variables) {
541
+ const evaluator = new JuelEvaluator(variables);
542
+ const [onlyPart] = this.parts;
543
+ if (this.parts.length === 1 && typeof onlyPart !== "string") {
544
+ return evaluator.evaluate(onlyPart);
545
+ }
546
+ return this.parts.map((part) => typeof part === "string" ? part : evaluator.coerceToString(evaluator.evaluate(part))).join("");
547
+ }
548
+ variableNames() {
549
+ const names = /* @__PURE__ */ new Set();
550
+ const visit = (node) => {
551
+ if (node.type === "identifier") names.add(node.name);
552
+ if (node.type === "member") {
553
+ visit(node.object);
554
+ visit(node.property);
555
+ }
556
+ if (node.type === "unary") visit(node.operand);
557
+ if (node.type === "binary") {
558
+ visit(node.left);
559
+ visit(node.right);
560
+ }
561
+ if (node.type === "conditional") {
562
+ visit(node.test);
563
+ visit(node.consequent);
564
+ visit(node.alternate);
565
+ }
566
+ };
567
+ this.parts.forEach((part) => typeof part !== "string" && visit(part));
568
+ return [...names];
569
+ }
570
+ static findExpressionStart(text, from) {
571
+ const dollar = text.indexOf("${", from);
572
+ const hash = text.indexOf("#{", from);
573
+ if (dollar === -1) return hash;
574
+ if (hash === -1) return dollar;
575
+ return Math.min(dollar, hash);
576
+ }
577
+ static findExpressionEnd(text, from) {
578
+ let quote = null;
579
+ for (let index = from; index < text.length; index++) {
580
+ const char = text[index];
581
+ if (quote) {
582
+ if (char === "\\") index++;
583
+ else if (char === quote) quote = null;
584
+ } else if (char === "'" || char === '"') {
585
+ quote = char;
586
+ } else if (char === "}") {
587
+ return index;
588
+ }
589
+ }
590
+ throw new JuelError('Unterminated expression, missing "}"');
591
+ }
592
+ }
593
+
594
+ class Camunda7Engine {
595
+ constructor() {
596
+ this.id = "camunda7";
597
+ this.label = "Camunda 7";
598
+ this.expressionLanguage = "JUEL";
599
+ this.taskResultPropagation = "always";
600
+ }
601
+ writeVariable(variables, target, value) {
602
+ return { ...variables, [target]: value };
603
+ }
604
+ readInputMappings(element) {
605
+ return this.readMappings(element, "inputParameters");
606
+ }
607
+ readOutputMappings(element) {
608
+ return this.readMappings(element, "outputParameters");
609
+ }
610
+ readCondition(sequenceFlow) {
611
+ const condition = readConditionExpression(sequenceFlow);
612
+ const isJuel = !condition?.language || condition.language.toLowerCase() === "juel";
613
+ return isJuel ? condition?.body?.trim() || void 0 : void 0;
614
+ }
615
+ canEvaluate(expression) {
616
+ try {
617
+ JuelTemplate.parse(expression);
618
+ return true;
619
+ } catch {
620
+ return false;
621
+ }
622
+ }
623
+ evaluate(expression, variables) {
624
+ if (!expression) {
625
+ return { ok: true, value: null };
626
+ }
627
+ try {
628
+ return { ok: true, value: JuelTemplate.parse(expression).evaluate(variables) };
629
+ } catch (error) {
630
+ return { ok: false, reason: error.message };
631
+ }
632
+ }
633
+ readVariableNames(expression) {
634
+ try {
635
+ return JuelTemplate.parse(expression).variableNames();
636
+ } catch {
637
+ return [];
638
+ }
639
+ }
640
+ readMappings(element, property) {
641
+ const inputOutput = findExtension(element, "camunda:InputOutput");
642
+ return listProperty(inputOutput, property).filter((parameter) => typeof parameter.name === "string" && parameter.name && !parameter.definition).map((parameter) => ({
643
+ source: typeof parameter.value === "string" ? parameter.value : "",
644
+ target: parameter.name
645
+ }));
646
+ }
647
+ }
648
+
649
+ const EXPRESSION_PREFIX = "=";
650
+ class ZeebeEngine {
651
+ constructor() {
652
+ this.id = "zeebe";
653
+ this.label = "Zeebe";
654
+ this.expressionLanguage = "FEEL";
655
+ this.taskResultPropagation = "without-output-mappings";
656
+ }
657
+ writeVariable(variables, target, value) {
658
+ return setVariable(variables, target, value);
659
+ }
660
+ readInputMappings(element) {
661
+ return this.readMappings(element, "inputParameters");
662
+ }
663
+ readOutputMappings(element) {
664
+ return this.readMappings(element, "outputParameters");
665
+ }
666
+ readCondition(sequenceFlow) {
667
+ return readConditionExpression(sequenceFlow)?.body?.trim() || void 0;
668
+ }
669
+ canEvaluate(expression) {
670
+ return this.isFeel(expression) && this.parsesAsFeel(expression);
671
+ }
672
+ evaluate(expression, variables) {
673
+ if (!this.isFeel(expression)) {
674
+ return { ok: true, value: expression };
675
+ }
676
+ try {
677
+ const { value, warnings } = evaluate(this.feelBody(expression), variables);
678
+ const missingVariable = warnings.find((warning) => warning.type === "NO_VARIABLE_FOUND");
679
+ if (value === null && missingVariable) {
680
+ return { ok: false, reason: missingVariable.message };
681
+ }
682
+ return { ok: true, value: this.toVariableValue(value) };
683
+ } catch (error) {
684
+ return { ok: false, reason: `Invalid FEEL: ${error.message}` };
685
+ }
686
+ }
687
+ readVariableNames(expression) {
688
+ if (!this.isFeel(expression)) return [];
689
+ const body = this.feelBody(expression);
690
+ const read = /* @__PURE__ */ new Set();
691
+ const bound = /* @__PURE__ */ new Set();
692
+ parseExpression(body, {}, void 0).iterate({
693
+ enter(node) {
694
+ const text = body.slice(node.from, node.to);
695
+ if (node.name === "Name") bound.add(text);
696
+ if (node.name !== "VariableName") return;
697
+ const isCallee = node.node.parent?.name === "FunctionInvocation" && node.node.prevSibling === null;
698
+ if (!isCallee) read.add(text);
699
+ }
700
+ });
701
+ return [...read].filter((name) => !bound.has(name));
702
+ }
703
+ readMappings(element, property) {
704
+ const ioMapping = findExtension(element, "zeebe:IoMapping");
705
+ return listProperty(ioMapping, property).filter((parameter) => typeof parameter.target === "string" && parameter.target).map((parameter) => ({ source: String(parameter.source ?? ""), target: parameter.target }));
706
+ }
707
+ toVariableValue(value) {
708
+ if (value === void 0) return null;
709
+ return typeof value === "object" && value !== null ? JSON.parse(JSON.stringify(value)) : value;
710
+ }
711
+ parsesAsFeel(expression) {
712
+ try {
713
+ evaluate(this.feelBody(expression), {});
714
+ return true;
715
+ } catch {
716
+ return false;
717
+ }
718
+ }
719
+ isFeel(expression) {
720
+ return expression.trimStart().startsWith(EXPRESSION_PREFIX);
721
+ }
722
+ feelBody(expression) {
723
+ return expression.trimStart().slice(EXPRESSION_PREFIX.length);
724
+ }
725
+ }
726
+
727
+ const zeebeEngine = new ZeebeEngine();
728
+ const camunda7Engine = new Camunda7Engine();
729
+
730
+ class EngineRegistry {
731
+ constructor() {
732
+ this.engines = {
733
+ zeebe: zeebeEngine,
734
+ camunda7: camunda7Engine
735
+ };
736
+ }
737
+ resolve(engine) {
738
+ if (typeof engine !== "string") return engine;
739
+ const adapter = this.engines[engine];
740
+ if (!adapter) {
741
+ throw new Error(`Unknown engine "${engine}", expected one of: ${Object.keys(this.engines).join(", ")}`);
742
+ }
743
+ return adapter;
744
+ }
745
+ }
746
+
747
+ class DataSimulationStore {
748
+ constructor() {
749
+ this.engineLabel = "";
750
+ this.expressionLanguage = "";
751
+ this.scenarios = [];
752
+ this.selectedScenarioId = null;
753
+ this.startVariables = {};
754
+ this.instances = /* @__PURE__ */ new Map();
755
+ this.selectedInstanceId = null;
756
+ this.log = [];
757
+ this.nextLogId = 1;
758
+ this.listeners = /* @__PURE__ */ new Set();
759
+ }
760
+ setEngine(label, expressionLanguage) {
761
+ this.engineLabel = label;
762
+ this.expressionLanguage = expressionLanguage;
763
+ this.emit();
764
+ }
765
+ setScenarios(scenarios) {
766
+ this.scenarios = scenarios;
767
+ this.selectScenario(scenarios[0]?.id ?? null);
768
+ }
769
+ selectScenario(scenarioId) {
770
+ const scenario = this.scenarios.find((candidate) => candidate.id === scenarioId);
771
+ this.selectedScenarioId = scenario?.id ?? null;
772
+ this.startVariables = scenario ? structuredClone(scenario.variables) : {};
773
+ this.emit();
774
+ }
775
+ setStartVariables(variables) {
776
+ this.startVariables = structuredClone(variables);
777
+ this.emit();
778
+ }
779
+ startInstance(id, processName) {
780
+ this.instances.set(id, {
781
+ id,
782
+ number: this.instances.size + 1,
783
+ processName,
784
+ scenarioId: this.selectedScenarioId,
785
+ status: "running",
786
+ variables: structuredClone(this.startVariables),
787
+ waiting: []
788
+ });
789
+ this.selectedInstanceId = id;
790
+ this.emit();
791
+ }
792
+ selectInstance(instanceId) {
793
+ if (!this.instances.has(instanceId)) return;
794
+ this.selectedInstanceId = instanceId;
795
+ this.emit();
796
+ }
797
+ completeInstance(id) {
798
+ this.updateInstance(id, (instance) => ({ ...instance, status: "completed", waiting: [] }));
799
+ }
800
+ hasInstance(id) {
801
+ return this.instances.has(id);
802
+ }
803
+ getTaskResult(instanceId, elementId) {
804
+ const scenarioId = this.instances.get(instanceId)?.scenarioId;
805
+ return this.scenarios.find((scenario) => scenario.id === scenarioId)?.taskResults[elementId];
806
+ }
807
+ getVariables(instanceId) {
808
+ return this.instances.get(instanceId)?.variables ?? {};
809
+ }
810
+ setVariables(instanceId, variables) {
811
+ this.updateInstance(instanceId, (instance) => ({ ...instance, variables: structuredClone(variables) }));
812
+ }
813
+ addWaiting(instanceId, waiting) {
814
+ this.updateInstance(instanceId, (instance) => ({ ...instance, waiting: [...instance.waiting, waiting] }));
815
+ }
816
+ removeWaiting(scopeId) {
817
+ const instance = [...this.instances.values()].find(
818
+ (candidate) => candidate.waiting.some((waiting) => waiting.scopeId === scopeId)
819
+ );
820
+ if (!instance) return;
821
+ this.updateInstance(instance.id, (current) => ({
822
+ ...current,
823
+ waiting: current.waiting.filter((waiting) => waiting.scopeId !== scopeId)
824
+ }));
825
+ }
826
+ record(entry) {
827
+ this.log = [...this.log, { ...entry, id: this.nextLogId++ }];
828
+ this.emit();
829
+ }
830
+ reset() {
831
+ this.instances.clear();
832
+ this.selectedInstanceId = null;
833
+ this.log = [];
834
+ this.emit();
835
+ }
836
+ getSnapshot() {
837
+ return {
838
+ engineLabel: this.engineLabel,
839
+ expressionLanguage: this.expressionLanguage,
840
+ scenarios: this.scenarios,
841
+ selectedScenarioId: this.selectedScenarioId,
842
+ startVariables: this.startVariables,
843
+ instances: [...this.instances.values()].map((instance) => this.withStatus(instance)),
844
+ selectedInstanceId: this.selectedInstanceId,
845
+ log: this.log
846
+ };
847
+ }
848
+ subscribe(listener) {
849
+ this.listeners.add(listener);
850
+ return () => this.listeners.delete(listener);
851
+ }
852
+ updateInstance(id, update) {
853
+ const instance = this.instances.get(id);
854
+ if (!instance) return;
855
+ this.instances.set(id, update(instance));
856
+ this.emit();
857
+ }
858
+ emit() {
859
+ const snapshot = this.getSnapshot();
860
+ for (const listener of [...this.listeners]) listener(snapshot);
861
+ }
862
+ withStatus(instance) {
863
+ if (instance.status === "completed") return instance;
864
+ return { ...instance, status: instance.waiting.length ? "waiting" : "running" };
865
+ }
866
+ }
867
+
868
+ function h(tag, attributes = {}, ...children) {
869
+ const element = document.createElement(tag);
870
+ for (const [name, value] of Object.entries(attributes)) {
871
+ if (name === "className") element.className = value;
872
+ else element.setAttribute(name, value);
873
+ }
874
+ for (const child of children) {
875
+ if (child) element.append(child);
876
+ }
877
+ return element;
878
+ }
879
+ function formatValue(value) {
880
+ if (value === void 0) return "undefined";
881
+ return JSON.stringify(value) ?? String(value);
882
+ }
883
+
884
+ class SimpleStartForm {
885
+ constructor(container, fields, values) {
886
+ this.fields = fields;
887
+ this.codec = new StartFieldCodec();
888
+ this.inputs = /* @__PURE__ */ new Map();
889
+ this.form = h("div", { className: "bds-form" });
890
+ for (const field of fields) {
891
+ const input = this.createInput(field);
892
+ this.inputs.set(field.name, input);
893
+ this.form.append(this.renderField(field, input));
894
+ }
895
+ for (const field of fields)
896
+ this.writeInput(this.inputs.get(field.name), this.codec.format(field, values[field.name]));
897
+ container.append(this.form);
898
+ }
899
+ readValues() {
900
+ const result = {};
901
+ for (const field of this.fields) {
902
+ const input = this.inputs.get(field.name);
903
+ const parsed = this.codec.parse(
904
+ field,
905
+ input.type === "checkbox" ? input.checked : input.value
906
+ );
907
+ if (!parsed.ok) return parsed;
908
+ result[field.name] = parsed.value;
909
+ }
910
+ return { ok: true, values: result };
911
+ }
912
+ focus() {
913
+ this.inputs.values().next().value?.focus();
914
+ }
915
+ destroy() {
916
+ this.form.remove();
917
+ }
918
+ renderField(field, input) {
919
+ const id = `bds-field-${field.name}`;
920
+ input.id = id;
921
+ const hint = h("span", { className: "bds-field-hint" }, `Used by ${field.usedBy.join(", ")}`);
922
+ if (field.type === "boolean") {
923
+ return h(
924
+ "div",
925
+ { className: "bds-field bds-field--checkbox" },
926
+ h(
927
+ "label",
928
+ { className: "bds-checkbox", for: id },
929
+ input,
930
+ h("span", { className: "bds-field-name" }, field.name)
931
+ ),
932
+ hint
933
+ );
934
+ }
935
+ return h(
936
+ "div",
937
+ { className: "bds-field" },
938
+ h("label", { className: "bds-field-name", for: id }, field.name),
939
+ input,
940
+ hint
941
+ );
942
+ }
943
+ createInput(field) {
944
+ if (field.type === "boolean") return h("input", { type: "checkbox", name: field.name });
945
+ if (field.type === "json") {
946
+ return h("textarea", { className: "bds-input bds-json", name: field.name, rows: "2", spellcheck: "false" });
947
+ }
948
+ const type = field.type === "number" ? "number" : "text";
949
+ return h("input", { className: "bds-input", type, name: field.name, step: "any", autocomplete: "off" });
950
+ }
951
+ writeInput(input, value) {
952
+ if (typeof value === "boolean") input.checked = value;
953
+ else input.value = value;
954
+ }
955
+ }
956
+
957
+ class SimpleStartFormRenderer {
958
+ render(container, fields, values) {
959
+ return new SimpleStartForm(container, fields, values);
960
+ }
961
+ }
962
+
963
+ const FLOW_CHOICE_TYPES = ["bpmn:ExclusiveGateway", "bpmn:InclusiveGateway"];
964
+ const TRIGGER_TYPE = "bpmn:Event";
965
+ class DataContextPads {
966
+ constructor(contextPads, dataGateways, startForm, dataSimulation) {
967
+ this.dataGateways = dataGateways;
968
+ this.startForm = startForm;
969
+ this.dataSimulation = dataSimulation;
970
+ for (const { handler, type } of contextPads._handlers) {
971
+ if (FLOW_CHOICE_TYPES.includes(type)) this.hideOnDataDrivenGateways(handler);
972
+ if (type === TRIGGER_TYPE) this.openStartFormOnProcessStart(handler);
973
+ }
974
+ }
975
+ hideOnDataDrivenGateways(handler) {
976
+ const createContextPads = handler.createContextPads.bind(handler);
977
+ handler.createContextPads = (element) => this.dataGateways.isDataDriven(element) ? void 0 : createContextPads(element);
978
+ }
979
+ openStartFormOnProcessStart(handler) {
980
+ const createContextPads = handler.createContextPads.bind(handler);
981
+ handler.createContextPads = (element) => {
982
+ const pads = createContextPads(element);
983
+ if (!this.dataSimulation.isEnabled() || !this.startForm.isProcessStart(element)) return pads;
984
+ return [].concat(pads).map(
985
+ (pad) => pad?.action ? { ...pad, action: (contexts) => this.startForm.open(element, () => pad.action(contexts)) } : pad
986
+ );
987
+ };
988
+ }
989
+ }
990
+ DataContextPads.$inject = ["contextPads", "dataGateways", "dataStartForm", "dataSimulation"];
991
+
992
+ class DataGatewayBehaviors {
993
+ constructor(exclusive, inclusive, dataGateways) {
994
+ this.dataGateways = dataGateways;
995
+ this.routeByData(exclusive, "exclusive");
996
+ this.routeByData(inclusive, "inclusive");
997
+ }
998
+ routeByData(behavior, kind) {
999
+ const exitByClick = behavior.exit.bind(behavior);
1000
+ behavior.exit = (context) => {
1001
+ if (this.dataGateways.isDataDriven(context.element)) {
1002
+ this.dataGateways.exit(context, kind);
1003
+ } else {
1004
+ this.dataGateways.recordClickDecision(context, kind);
1005
+ exitByClick(context);
1006
+ }
1007
+ };
1008
+ }
1009
+ }
1010
+ DataGatewayBehaviors.$inject = ["exclusiveGatewayBehavior", "inclusiveGatewayBehavior", "dataGateways"];
1011
+
1012
+ class DataGatewaySettings {
1013
+ constructor(exclusive, inclusive, dataGateways) {
1014
+ this.dataGateways = dataGateways;
1015
+ exclusive.setSequenceFlow = this.onlyForClickGateways(exclusive.setSequenceFlow.bind(exclusive));
1016
+ inclusive._setGatewayDefaults = this.onlyForClickGateways(inclusive._setGatewayDefaults.bind(inclusive));
1017
+ inclusive.toggleSequenceFlow = this.onlyForClickGateways(inclusive.toggleSequenceFlow.bind(inclusive));
1018
+ }
1019
+ onlyForClickGateways(method) {
1020
+ return (gateway, ...rest) => {
1021
+ if (!this.dataGateways.isDataDriven(gateway)) method(gateway, ...rest);
1022
+ };
1023
+ }
1024
+ }
1025
+ DataGatewaySettings.$inject = ["exclusiveGatewaySettings", "inclusiveGatewaySettings", "dataGateways"];
1026
+
1027
+ function findProcessInstance(scope) {
1028
+ let current = scope;
1029
+ while (current.parent) current = current.parent;
1030
+ return current;
1031
+ }
1032
+ function elementName(element) {
1033
+ const name = element.businessObject.name;
1034
+ return typeof name === "string" && name.trim() ? name.trim() : element.id;
1035
+ }
1036
+ function is(element, type) {
1037
+ const businessObject = element.businessObject;
1038
+ return typeof businessObject?.$instanceOf === "function" && businessObject.$instanceOf(type);
1039
+ }
1040
+ function isGateway(element) {
1041
+ return element.type === "bpmn:ExclusiveGateway" || element.type === "bpmn:InclusiveGateway";
1042
+ }
1043
+ function gatewayOf(element) {
1044
+ if (isGateway(element)) return element.id;
1045
+ if (element.type === "bpmn:SequenceFlow" && element.source && isGateway(element.source)) return element.source.id;
1046
+ return void 0;
1047
+ }
1048
+
1049
+ class DataGateways {
1050
+ constructor(dataSimulation, store, simulator) {
1051
+ this.dataSimulation = dataSimulation;
1052
+ this.store = store;
1053
+ this.simulator = simulator;
1054
+ this.router = new GatewayRouter();
1055
+ }
1056
+ isDataDriven(gateway) {
1057
+ const engine = this.dataSimulation.getEngine();
1058
+ const outgoing = this.outgoingFlows(gateway);
1059
+ return this.dataSimulation.isEnabled() && outgoing.length > 1 && outgoing.filter((flow) => !flow.isDefault).every((flow) => flow.expression !== void 0 && engine.canEvaluate(flow.expression));
1060
+ }
1061
+ exit(context, kind) {
1062
+ const { element: gateway, scope } = context;
1063
+ const decision = this.decide(gateway, scope, kind);
1064
+ if (decision.stuckReason) {
1065
+ this.waitForRetry(gateway, scope);
1066
+ return;
1067
+ }
1068
+ for (const flowId of decision.takenFlowIds) {
1069
+ const flow = this.sequenceFlows(gateway).find((candidate) => candidate.id === flowId);
1070
+ this.simulator.enter({ element: flow, scope: scope.parent });
1071
+ }
1072
+ }
1073
+ recordClickDecision(context, kind) {
1074
+ if (!this.dataSimulation.isEnabled()) return;
1075
+ const { element: gateway, scope } = context;
1076
+ const { activeOutgoing } = this.simulator.getConfig(gateway);
1077
+ const chosen = [].concat(activeOutgoing ?? []);
1078
+ const outgoing = this.outgoingFlows(gateway);
1079
+ if (outgoing.length < 2 || !chosen.length) return;
1080
+ const flows = outgoing.map(
1081
+ (flow) => chosen.some((candidate) => candidate.id === flow.id) ? { flow, outcome: "taken", reason: "Chosen by click" } : { flow, outcome: "skipped", reason: "Not chosen by click" }
1082
+ );
1083
+ const decision = {
1084
+ flows,
1085
+ takenFlowIds: flows.filter((flow) => flow.outcome === "taken").map((flow) => flow.flow.id)
1086
+ };
1087
+ this.record(gateway, scope, kind, "click", decision, []);
1088
+ }
1089
+ decide(gateway, scope, kind) {
1090
+ const engine = this.dataSimulation.getEngine();
1091
+ const variables = this.dataSimulation.getVariables(scope);
1092
+ const outgoing = this.outgoingFlows(gateway);
1093
+ const decision = this.router.route(kind, outgoing, (expression) => engine.evaluate(expression, variables));
1094
+ const names = outgoing.flatMap((flow) => flow.expression ? engine.readVariableNames(flow.expression) : []);
1095
+ const inputs = [...new Set(names)].map((name) => ({ name, value: structuredClone(variables[name]) }));
1096
+ this.record(gateway, scope, kind, "data", decision, inputs);
1097
+ return decision;
1098
+ }
1099
+ record(gateway, scope, gatewayKind, chosenBy, decision, inputs) {
1100
+ this.store.record({
1101
+ kind: "decision",
1102
+ instanceId: findProcessInstance(scope).id,
1103
+ elementId: gateway.id,
1104
+ elementName: elementName(gateway),
1105
+ gatewayKind,
1106
+ chosenBy,
1107
+ decision,
1108
+ inputs
1109
+ });
1110
+ }
1111
+ waitForRetry(gateway, scope) {
1112
+ const waitingScope = this.simulator.createScope({ element: gateway, parent: scope.parent, initiator: scope }).start();
1113
+ this.store.addWaiting(findProcessInstance(scope).id, {
1114
+ scopeId: waitingScope.id,
1115
+ gatewayId: gateway.id,
1116
+ gatewayName: elementName(gateway)
1117
+ });
1118
+ const retry = { element: gateway, type: "continue", interrupting: false, boundary: false };
1119
+ const subscription = this.simulator.subscribe(waitingScope, retry, (initiator) => {
1120
+ subscription.remove();
1121
+ this.store.removeWaiting(waitingScope.id);
1122
+ this.simulator.exit({ element: gateway, scope: waitingScope, initiator });
1123
+ });
1124
+ }
1125
+ outgoingFlows(gateway) {
1126
+ const engine = this.dataSimulation.getEngine();
1127
+ const defaultFlow = gateway.businessObject.default;
1128
+ return this.sequenceFlows(gateway).map((flow) => {
1129
+ const name = flow.businessObject.name;
1130
+ return {
1131
+ id: flow.id,
1132
+ ...typeof name === "string" && name ? { name } : {},
1133
+ expression: engine.readCondition(flow.businessObject),
1134
+ isDefault: flow.businessObject === defaultFlow
1135
+ };
1136
+ });
1137
+ }
1138
+ sequenceFlows(gateway) {
1139
+ return (gateway.outgoing ?? []).filter((flow) => is(flow, "bpmn:SequenceFlow"));
1140
+ }
1141
+ }
1142
+ DataGateways.$inject = ["dataSimulation", "dataSimulationStore", "simulator"];
1143
+
1144
+ class IoMappings {
1145
+ constructor(engine, store) {
1146
+ this.engine = engine;
1147
+ this.store = store;
1148
+ }
1149
+ apply(element, instanceId) {
1150
+ const inputs = this.engine.readInputMappings(element.businessObject);
1151
+ const outputs = this.engine.readOutputMappings(element.businessObject);
1152
+ const taskResult = this.store.getTaskResult(instanceId, element.id);
1153
+ if (!inputs.length && !outputs.length && !taskResult) return;
1154
+ const processVariables = this.store.getVariables(instanceId);
1155
+ const localVariables = this.evaluate(element, instanceId, inputs, {}, (current) => ({
1156
+ ...processVariables,
1157
+ ...current
1158
+ }));
1159
+ const context = { ...processVariables, ...localVariables, ...taskResult };
1160
+ const propagatesTaskResult = taskResult && (this.engine.taskResultPropagation === "always" || !outputs.length);
1161
+ const withTaskResult = propagatesTaskResult ? { ...processVariables, ...withoutKeys(taskResult, Object.keys(localVariables)) } : processVariables;
1162
+ this.store.setVariables(
1163
+ instanceId,
1164
+ this.evaluate(element, instanceId, outputs, withTaskResult, () => context)
1165
+ );
1166
+ }
1167
+ evaluate(element, instanceId, mappings, target, contextOf) {
1168
+ let result = target;
1169
+ for (const mapping of mappings) {
1170
+ const evaluation = this.engine.evaluate(mapping.source, contextOf(result));
1171
+ if (evaluation.ok) {
1172
+ result = this.engine.writeVariable(result, mapping.target, evaluation.value);
1173
+ } else {
1174
+ this.store.record({
1175
+ kind: "mapping-issue",
1176
+ instanceId,
1177
+ elementId: element.id,
1178
+ elementName: elementName(element),
1179
+ target: mapping.target,
1180
+ reason: evaluation.reason
1181
+ });
1182
+ }
1183
+ }
1184
+ return result;
1185
+ }
1186
+ }
1187
+
1188
+ const TOGGLE_MODE_EVENT = "tokenSimulation.toggleMode";
1189
+ const RESET_SIMULATION_EVENT = "tokenSimulation.resetSimulation";
1190
+ const SCOPE_CREATE_EVENT = "tokenSimulation.simulator.createScope";
1191
+ const SCOPE_DESTROYED_EVENT = "tokenSimulation.simulator.destroyScope";
1192
+ const TRACE_EVENT = "tokenSimulation.simulator.trace";
1193
+ const DATA_TOGGLE_EVENT = "dataSimulation.toggle";
1194
+
1195
+ class DataSimulation {
1196
+ constructor(config, eventBus, store) {
1197
+ this.eventBus = eventBus;
1198
+ this.store = store;
1199
+ this.scenarioParser = new ScenarioParser();
1200
+ this.engine = new EngineRegistry().resolve(config?.engine ?? "zeebe");
1201
+ this.ioMappings = new IoMappings(this.engine, store);
1202
+ this.enabled = config?.enabled ?? true;
1203
+ this.store.setEngine(this.engine.label, this.engine.expressionLanguage);
1204
+ if (config?.scenarios !== void 0) this.setScenarios(config.scenarios);
1205
+ eventBus.on(SCOPE_CREATE_EVENT, ({ scope }) => this.onScopeCreated(scope));
1206
+ eventBus.on(SCOPE_DESTROYED_EVENT, ({ scope }) => {
1207
+ this.store.completeInstance(scope.id);
1208
+ this.store.removeWaiting(scope.id);
1209
+ });
1210
+ eventBus.on(TRACE_EVENT, (event) => {
1211
+ if (event.action === "exit") this.applyMappings(event.element, event.scope);
1212
+ });
1213
+ eventBus.on([RESET_SIMULATION_EVENT, TOGGLE_MODE_EVENT], () => this.store.reset());
1214
+ }
1215
+ getEngine() {
1216
+ return this.engine;
1217
+ }
1218
+ isEnabled() {
1219
+ return this.enabled;
1220
+ }
1221
+ setEnabled(enabled) {
1222
+ if (enabled === this.enabled) return;
1223
+ this.enabled = enabled;
1224
+ this.store.reset();
1225
+ this.eventBus.fire(DATA_TOGGLE_EVENT, { enabled });
1226
+ }
1227
+ setScenarios(input) {
1228
+ this.store.setScenarios(this.scenarioParser.parse(input));
1229
+ }
1230
+ selectScenario(scenarioId) {
1231
+ this.store.selectScenario(scenarioId);
1232
+ }
1233
+ setStartVariables(variables) {
1234
+ this.store.setStartVariables(variables);
1235
+ }
1236
+ selectInstance(instanceId) {
1237
+ this.store.selectInstance(instanceId);
1238
+ }
1239
+ setInstanceVariables(instanceId, variables) {
1240
+ this.store.setVariables(instanceId, variables);
1241
+ }
1242
+ getVariables(scope) {
1243
+ return this.store.getVariables(findProcessInstance(scope).id);
1244
+ }
1245
+ getSnapshot() {
1246
+ return this.store.getSnapshot();
1247
+ }
1248
+ subscribe(listener) {
1249
+ return this.store.subscribe(listener);
1250
+ }
1251
+ onScopeCreated(scope) {
1252
+ if (!this.enabled || scope.parent || !is(scope.element, "bpmn:Process") && !is(scope.element, "bpmn:Participant"))
1253
+ return;
1254
+ this.store.startInstance(scope.id, elementName(scope.element));
1255
+ }
1256
+ applyMappings(element, scope) {
1257
+ if (!is(element, "bpmn:FlowNode") || scope.failed || scope.canceled) return;
1258
+ const instanceId = findProcessInstance(scope).id;
1259
+ if (this.store.hasInstance(instanceId)) this.ioMappings.apply(element, instanceId);
1260
+ }
1261
+ }
1262
+ DataSimulation.$inject = ["config.dataSimulation", "eventBus", "dataSimulationStore"];
1263
+
1264
+ class GatewayDecisionView {
1265
+ constructor(snapshot) {
1266
+ this.snapshot = snapshot;
1267
+ this.decisions = this.latestDecisionPerGateway();
1268
+ const shownPerGateway = new Map(this.decisions.map((entry) => [entry.elementId, entry]));
1269
+ for (const entry of this.latestStuckDecisionPerGateway()) shownPerGateway.set(entry.elementId, entry);
1270
+ this.shown = [...shownPerGateway.values()];
1271
+ }
1272
+ latestDecisionPerGateway() {
1273
+ const { log, selectedInstanceId } = this.snapshot;
1274
+ const latest = /* @__PURE__ */ new Map();
1275
+ for (const entry of log) {
1276
+ if (entry.kind === "decision" && entry.instanceId === selectedInstanceId) latest.set(entry.elementId, entry);
1277
+ }
1278
+ return [...latest.values()];
1279
+ }
1280
+ latestStuckDecisionPerGateway() {
1281
+ const { instances, log } = this.snapshot;
1282
+ const latest = /* @__PURE__ */ new Map();
1283
+ for (const instance of instances) {
1284
+ for (const { gatewayId } of instance.waiting) {
1285
+ const decision = [...log].reverse().find(
1286
+ (entry) => entry.kind === "decision" && entry.instanceId === instance.id && entry.elementId === gatewayId
1287
+ );
1288
+ if (decision && (latest.get(gatewayId)?.id ?? 0) < decision.id) latest.set(gatewayId, decision);
1289
+ }
1290
+ }
1291
+ return [...latest.values()];
1292
+ }
1293
+ }
1294
+
1295
+ const OUTCOME_LABELS = {
1296
+ taken: { symbol: "\u2713", title: "Taken" },
1297
+ "not-taken": { symbol: "\u2717", title: "Condition is false" },
1298
+ error: { symbol: "!", title: "Condition could not be evaluated" },
1299
+ skipped: { symbol: "\u2013", title: "Not evaluated" }
1300
+ };
1301
+ const DEFAULT_FLOW_TITLES = {
1302
+ taken: "Default flow taken, no condition is true",
1303
+ "not-taken": "Default flow not needed"
1304
+ };
1305
+ class OutcomeBadge {
1306
+ constructor(outcome, detail, isDefault = false) {
1307
+ this.element = document.createElement("span");
1308
+ const title = isDefault && DEFAULT_FLOW_TITLES[outcome] || OUTCOME_LABELS[outcome].title;
1309
+ this.element.className = `bds-outcome bds-outcome--${outcome}`;
1310
+ this.element.textContent = OUTCOME_LABELS[outcome].symbol;
1311
+ this.element.title = detail ? `${title}: ${detail}` : title;
1312
+ }
1313
+ }
1314
+
1315
+ class DecisionCard {
1316
+ constructor({ elementName, gatewayKind, chosenBy, decision, inputs }, onClose) {
1317
+ this.element = h(
1318
+ "div",
1319
+ { className: `bds-decision${decision.stuckReason ? " bds-decision--stuck" : ""}`, role: "note" },
1320
+ h(
1321
+ "div",
1322
+ { className: "bds-decision-title" },
1323
+ h("span", {}, elementName),
1324
+ h("span", { className: "bds-tag" }, chosenBy === "click" ? `${gatewayKind} \xB7 by click` : gatewayKind),
1325
+ onClose ? this.closeButton(onClose) : null
1326
+ ),
1327
+ decision.stuckReason ? h(
1328
+ "p",
1329
+ { className: "bds-error" },
1330
+ `${decision.stuckReason}. Change the variables in Process Data, then press \u25B6 on the gateway.`
1331
+ ) : null,
1332
+ h(
1333
+ "ul",
1334
+ { className: "bds-flows" },
1335
+ ...decision.flows.map(
1336
+ ({ flow, outcome, reason }) => h(
1337
+ "li",
1338
+ { className: `bds-flow bds-flow--${outcome}` },
1339
+ new OutcomeBadge(outcome, reason, flow.isDefault).element,
1340
+ h("span", { className: "bds-flow-name" }, flow.name ?? flow.id),
1341
+ flow.isDefault ? h("span", { className: "bds-tag" }, "default") : flow.expression && h("code", {}, flow.expression)
1342
+ )
1343
+ )
1344
+ ),
1345
+ inputs.length ? this.inputList(inputs) : null
1346
+ );
1347
+ }
1348
+ closeButton(onClose) {
1349
+ const button = h(
1350
+ "button",
1351
+ { className: "bds-icon-button bds-decision-close", type: "button", "aria-label": "Close" },
1352
+ "\xD7"
1353
+ );
1354
+ button.addEventListener("click", onClose);
1355
+ return button;
1356
+ }
1357
+ inputList(inputs) {
1358
+ return h(
1359
+ "dl",
1360
+ { className: "bds-decision-inputs" },
1361
+ ...inputs.flatMap(({ name, value }) => [
1362
+ h("dt", {}, name),
1363
+ h(
1364
+ "dd",
1365
+ {},
1366
+ value === void 0 ? h("span", { className: "bds-hint" }, "not set") : h("code", {}, formatValue(value))
1367
+ )
1368
+ ])
1369
+ );
1370
+ }
1371
+ }
1372
+
1373
+ function badgePosition(waypoints, distanceFromStart) {
1374
+ const [start, next] = waypoints;
1375
+ const length = Math.hypot(next.x - start.x, next.y - start.y) || 1;
1376
+ const distance = Math.min(distanceFromStart, length / 2);
1377
+ const x = start.x + (next.x - start.x) / length * distance;
1378
+ const y = start.y + (next.y - start.y) / length * distance;
1379
+ const minX = Math.min(...waypoints.map((point) => point.x));
1380
+ const minY = Math.min(...waypoints.map((point) => point.y));
1381
+ return { left: x - minX, top: y - minY };
1382
+ }
1383
+
1384
+ const GAP$1 = 12;
1385
+ const MARGIN = 8;
1386
+ function placePopover(anchor, popover, bounds) {
1387
+ const below = anchor.y + anchor.height + GAP$1;
1388
+ const above = anchor.y - GAP$1 - popover.height;
1389
+ const fitsBelow = below + popover.height <= bounds.height - MARGIN;
1390
+ const fitsAbove = above >= MARGIN;
1391
+ const height = Math.min(popover.height, bounds.height - 2 * MARGIN);
1392
+ return {
1393
+ left: clamp(anchor.x + anchor.width / 2 - popover.width / 2, MARGIN, bounds.width - popover.width - MARGIN),
1394
+ top: fitsBelow ? below : fitsAbove ? above : clamp(below, MARGIN, bounds.height - height - MARGIN),
1395
+ maxHeight: height < popover.height ? height : void 0,
1396
+ hidden: !isInView(anchor, bounds)
1397
+ };
1398
+ }
1399
+ function clamp(value, min, max) {
1400
+ return Math.max(min, Math.min(value, max));
1401
+ }
1402
+ function isInView(anchor, bounds) {
1403
+ return anchor.x + anchor.width > 0 && anchor.x < bounds.width && anchor.y + anchor.height > 0 && anchor.y < bounds.height;
1404
+ }
1405
+
1406
+ var componentStyles = ":host {\n all: initial;\n display: contents;\n}\n\n.bds-panel {\n position: absolute;\n top: 30%;\n right: 20px;\n bottom: 50px;\n z-index: 10000;\n display: flex;\n flex-direction: column;\n width: 300px;\n overflow: hidden;\n font-family: var(--bds-font);\n font-size: 13px;\n color: var(--bds-ink);\n background: var(--token-simulation-control-background, #f1f2f4);\n border-radius: var(--surface-border-radius, 4px);\n}\n\n.bds-panel[hidden] {\n display: none;\n}\n\n.bds-panel-header {\n display: flex;\n flex: 0 0 auto;\n align-items: center;\n gap: var(--bds-space-2);\n box-sizing: border-box;\n height: 30px;\n padding: 6px 8px;\n font-size: 16px;\n color: var(--token-simulation-control-surface, #fff);\n background: var(--token-simulation-primary, #0067cc);\n}\n\n.bds-panel-heading {\n flex: 1;\n margin: 0;\n font: inherit;\n text-align: center;\n}\n\n.bds-panel-close {\n display: inline-flex;\n align-items: center;\n padding: 0;\n color: inherit;\n background: none;\n border: none;\n cursor: pointer;\n}\n\n.bds-variables-icon svg,\n.bds-panel-close svg {\n width: 1em;\n height: 1em;\n fill: none;\n stroke: currentColor;\n stroke-width: 1.6;\n stroke-linecap: round;\n stroke-linejoin: round;\n}\n\n.bds-variables-icon {\n display: inline-flex;\n align-items: center;\n}\n\n.bds-panel-body {\n display: flex;\n flex: 1;\n flex-direction: column;\n gap: var(--bds-space-2);\n margin: 7px 3px 7px 12px;\n padding: 5px 9px 5px 0;\n overflow-y: auto;\n}\n\n.bds-panel-engine {\n margin: 0;\n}\n\n.bds-panel .bds-section {\n padding: var(--bds-space-2);\n background: var(--token-simulation-control-surface, #fff);\n border-radius: var(--surface-border-radius, 4px);\n}\n\n.bds-panel-title {\n margin: 0;\n font-size: 14px;\n font-weight: 600;\n}\n\n.bds-engine {\n padding: 2px 8px;\n font-size: 11px;\n font-weight: 600;\n color: var(--bds-accent-ink);\n background: var(--bds-accent-soft);\n border-radius: var(--bds-radius-pill);\n}\n\n.bds-icon-button {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n margin-left: auto;\n width: 26px;\n height: 26px;\n padding: 0;\n color: var(--bds-muted);\n background: transparent;\n border: 1px solid transparent;\n border-radius: var(--bds-radius-sm);\n cursor: pointer;\n}\n\n.bds-icon-button svg {\n width: 16px;\n height: 16px;\n fill: none;\n stroke: currentColor;\n stroke-width: 1.5;\n stroke-linecap: round;\n stroke-linejoin: round;\n transition: transform var(--bds-motion-fast) var(--bds-ease);\n}\n\n.bds-icon-button:hover {\n color: var(--bds-accent-ink);\n background: var(--bds-accent-soft);\n}\n\n.bds-section {\n display: flex;\n flex-direction: column;\n gap: var(--bds-space-1);\n}\n\n.bds-section[hidden] {\n display: none;\n}\n\n.bds-section-title,\n.bds-label {\n display: flex;\n flex-direction: column;\n gap: var(--bds-space-1);\n margin: 0;\n font-size: 12px;\n font-weight: 600;\n letter-spacing: 0.01em;\n color: var(--bds-muted);\n}\n\n.bds-section-title {\n flex-direction: row;\n align-items: center;\n justify-content: space-between;\n}\n\n.bds-hint {\n margin: 0;\n font-size: 12px;\n color: var(--bds-muted);\n}\n\n.bds-hint[hidden],\n.bds-error[hidden] {\n display: none;\n}\n\n.bds-error {\n margin: 0;\n font-size: 12px;\n color: var(--bds-danger);\n}\n\n.bds-input {\n box-sizing: border-box;\n width: 100%;\n padding: 6px 10px;\n font-family: inherit;\n font-size: 13px;\n font-weight: 400;\n color: var(--bds-ink);\n background: var(--bds-surface);\n border: 1px solid var(--bds-line);\n border-radius: var(--bds-radius-sm);\n transition:\n border-color var(--bds-motion-fast) var(--bds-ease),\n box-shadow var(--bds-motion-fast) var(--bds-ease);\n}\n\n.bds-input:focus,\n.bds-input:focus-visible {\n outline: none;\n border-color: var(--bds-accent);\n box-shadow: 0 0 0 3px var(--bds-accent-soft);\n}\n\n.bds-input--invalid,\n.bds-input--invalid:focus {\n border-color: var(--bds-danger);\n box-shadow: 0 0 0 3px var(--bds-danger-soft);\n}\n\n.bds-json {\n min-height: 72px;\n font-family: var(--bds-font-mono);\n font-size: 12px;\n line-height: 1.5;\n resize: vertical;\n}\n\n.bds-instance-select[hidden] {\n display: none;\n}\n\n.bds-instance-select {\n padding: 4px 8px;\n font-size: 12px;\n}\n\n.bds-actions {\n display: flex;\n justify-content: flex-end;\n gap: var(--bds-space-2);\n margin-top: var(--bds-space-2);\n}\n\n.bds-button {\n padding: 5px 12px;\n font-family: inherit;\n font-size: 12px;\n font-weight: 600;\n color: var(--bds-ink);\n background: var(--bds-surface);\n border: 1px solid var(--bds-line);\n border-radius: var(--bds-radius-sm);\n box-shadow: var(--bds-shadow-1);\n cursor: pointer;\n transition:\n background var(--bds-motion-fast) var(--bds-ease),\n border-color var(--bds-motion-fast) var(--bds-ease),\n color var(--bds-motion-fast) var(--bds-ease);\n}\n\n.bds-button:hover {\n color: var(--bds-accent-ink);\n border-color: var(--bds-accent);\n background: var(--bds-accent-soft);\n}\n\n.bds-button--primary {\n color: var(--bds-on-accent);\n background: var(--bds-accent);\n border-color: var(--bds-accent);\n}\n\n.bds-button--primary:hover {\n color: var(--bds-on-accent);\n background: var(--bds-accent-ink);\n}\n\n.bds-button:focus-visible,\n.bds-icon-button:focus-visible {\n outline: none;\n box-shadow: 0 0 0 3px var(--bds-accent-soft);\n}\n\n.bds-status {\n margin: 0 0 var(--bds-space-1);\n font-size: 12px;\n font-weight: 600;\n}\n\n.bds-status--running {\n color: var(--bds-accent-ink);\n}\n\n.bds-status--completed {\n color: var(--bds-success);\n}\n\n.bds-status--waiting {\n color: var(--bds-danger);\n}\n\n.bds-variables {\n width: 100%;\n border-collapse: collapse;\n}\n\n.bds-variables th,\n.bds-variables td {\n padding: 4px 0;\n text-align: left;\n vertical-align: top;\n border-bottom: 1px solid var(--bds-line);\n}\n\n.bds-variables tr:last-child th,\n.bds-variables tr:last-child td {\n border-bottom: none;\n}\n\n.bds-variables th {\n width: 1%;\n padding-right: var(--bds-space-3);\n font-weight: 500;\n white-space: nowrap;\n}\n\n.bds-variables code,\n.bds-flow code {\n font-family: var(--bds-font-mono);\n font-size: 12px;\n overflow-wrap: anywhere;\n}\n\n.bds-log {\n display: flex;\n flex-direction: column;\n gap: var(--bds-space-2);\n margin: 0;\n padding: 0;\n list-style: none;\n}\n\n.bds-log-entry {\n padding: var(--bds-space-2);\n background: var(--bds-surface);\n border: 1px solid var(--bds-line);\n border-radius: var(--bds-radius-sm);\n}\n\n.bds-log-entry--issue {\n border-color: var(--bds-danger-soft);\n background: linear-gradient(var(--bds-danger-soft), var(--bds-danger-soft)), var(--bds-surface);\n}\n\n.bds-log-title {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: var(--bds-space-2);\n margin-bottom: var(--bds-space-1);\n font-weight: 600;\n}\n\n.bds-tag {\n padding: 1px 6px;\n font-size: 11px;\n font-weight: 500;\n color: var(--bds-muted);\n background: var(--bds-code-bg);\n border-radius: var(--bds-radius-pill);\n}\n\n.bds-flows {\n display: flex;\n flex-direction: column;\n gap: 2px;\n margin: 0;\n padding: 0;\n list-style: none;\n}\n\n.bds-flow {\n display: grid;\n grid-template-columns: 18px 1fr;\n align-items: center;\n column-gap: var(--bds-space-2);\n row-gap: 2px;\n}\n\n.bds-flow code,\n.bds-flow .bds-tag {\n grid-column: 2;\n justify-self: start;\n}\n\n.bds-flow code {\n padding: 1px 4px;\n color: var(--bds-muted);\n background: var(--bds-code-bg);\n border-radius: 4px;\n}\n\n.bds-flow--skipped,\n.bds-flow--not-taken {\n color: var(--bds-muted);\n}\n\n.bds-outcome {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n box-sizing: border-box;\n width: 18px;\n height: 18px;\n font-family: var(--bds-font);\n font-size: 11px;\n font-weight: 700;\n line-height: 1;\n border-radius: var(--bds-radius-pill);\n border: 1px solid transparent;\n cursor: default;\n}\n\n.bds-outcome--taken {\n color: var(--bds-on-accent);\n background: var(--bds-success);\n}\n\n.bds-outcome--not-taken {\n color: var(--bds-muted);\n background: var(--bds-surface);\n border-color: var(--bds-line);\n}\n\n.bds-outcome--error {\n color: var(--bds-on-accent);\n background: var(--bds-danger);\n}\n\n.bds-outcome--skipped {\n color: var(--bds-muted);\n background: var(--bds-code-bg);\n}\n\n.bds-outcome--on-flow {\n display: flex;\n box-shadow: var(--bds-shadow-1);\n transform: translate(-50%, -50%);\n}\n\n.bds-popover {\n position: absolute;\n z-index: 100;\n overflow-y: auto;\n}\n\n.bds-popover[hidden] {\n display: none;\n}\n\n.bds-decision {\n display: flex;\n flex-direction: column;\n gap: var(--bds-space-2);\n box-sizing: border-box;\n width: 300px;\n padding: 12px;\n font-family: var(--bds-font);\n font-size: 12px;\n line-height: 1.4;\n color: var(--bds-ink);\n background: var(--bds-surface);\n border: 1px solid var(--bds-line);\n border-radius: var(--bds-radius-md);\n box-shadow: var(--bds-shadow-3);\n}\n\n.bds-decision--stuck {\n border-color: var(--bds-danger);\n}\n\n.bds-decision-title {\n display: flex;\n align-items: center;\n gap: var(--bds-space-2);\n font-size: 13px;\n font-weight: 600;\n}\n\n.bds-decision-title .bds-tag {\n margin-left: auto;\n}\n\n.bds-decision-close {\n margin-left: 0;\n width: 22px;\n height: 22px;\n font-size: 16px;\n line-height: 1;\n}\n\n.bds-decision-inputs {\n display: grid;\n grid-template-columns: auto 1fr;\n gap: 2px var(--bds-space-3);\n margin: 0;\n padding-top: var(--bds-space-2);\n border-top: 1px solid var(--bds-line);\n}\n\n.bds-decision-inputs dt {\n font-family: var(--bds-font-mono);\n color: var(--bds-muted);\n}\n\n.bds-decision-inputs dd {\n margin: 0;\n overflow-wrap: anywhere;\n}\n\n.bds-decision-inputs code {\n font-family: var(--bds-font-mono);\n}\n\n.bds-dialog-backdrop {\n position: fixed;\n inset: 0;\n z-index: 10010;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: var(--bds-space-3);\n background: rgba(29, 29, 29, 0.24);\n}\n\n.bds-dialog {\n display: flex;\n flex-direction: column;\n gap: var(--bds-space-3);\n box-sizing: border-box;\n width: 420px;\n max-width: 100%;\n max-height: 100%;\n margin: 0;\n padding: 20px;\n font-family: var(--bds-font);\n font-size: 13px;\n color: var(--bds-ink);\n background: var(--bds-surface);\n border: 1px solid var(--bds-line);\n border-radius: var(--bds-radius-lg);\n box-shadow: var(--bds-shadow-3);\n}\n\n.bds-dialog-content {\n display: flex;\n flex-direction: column;\n gap: var(--bds-space-3);\n min-height: 0;\n overflow-y: auto;\n}\n\n.bds-dialog-header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: var(--bds-space-2);\n}\n\n.bds-dialog .bds-actions {\n margin-top: 0;\n}\n\n.bds-form {\n display: flex;\n flex-direction: column;\n gap: 12px;\n}\n\n.bds-field {\n display: flex;\n flex-direction: column;\n gap: var(--bds-space-1);\n}\n\n.bds-field-name {\n font-family: var(--bds-font-mono);\n font-size: 12px;\n font-weight: 600;\n}\n\n.bds-field-hint {\n font-size: 11px;\n color: var(--bds-muted);\n}\n\n.bds-checkbox {\n display: inline-flex;\n align-items: center;\n gap: var(--bds-space-2);\n cursor: pointer;\n}\n\n.bds-checkbox input {\n width: 16px;\n height: 16px;\n margin: 0;\n accent-color: var(--bds-accent);\n}\n\n@media (prefers-reduced-motion: reduce) {\n * {\n transition-duration: 0.001ms !important;\n }\n}\n\n.bds-form .bds-json {\n min-height: 0;\n}\n";
1407
+
1408
+ let sharedSheet;
1409
+ function inShadow(...children) {
1410
+ const host = h("div", { className: "bds-host" });
1411
+ const root = host.attachShadow({ mode: "open" });
1412
+ adoptComponentStyles(root);
1413
+ root.append(...children);
1414
+ return host;
1415
+ }
1416
+ function adoptComponentStyles(root) {
1417
+ if ("adoptedStyleSheets" in root && "replaceSync" in CSSStyleSheet.prototype) {
1418
+ sharedSheet ?? (sharedSheet = createSheet());
1419
+ root.adoptedStyleSheets = [sharedSheet];
1420
+ } else {
1421
+ root.append(h("style", {}, componentStyles));
1422
+ }
1423
+ }
1424
+ function createSheet() {
1425
+ const sheet = new CSSStyleSheet();
1426
+ sheet.replaceSync(componentStyles);
1427
+ return sheet;
1428
+ }
1429
+
1430
+ const OUTCOME_OVERLAY = "bds-flow-outcome";
1431
+ const DECIDED_MARKER = "bds-gateway--decided";
1432
+ const STUCK_MARKER = "bds-gateway--stuck";
1433
+ const BADGE_DISTANCE = 38;
1434
+ const BADGE_MIN_SCALE = 1;
1435
+ class DataSimulationOverlays {
1436
+ constructor(eventBus, overlays, elementRegistry, canvas, dataSimulation) {
1437
+ this.overlays = overlays;
1438
+ this.elementRegistry = elementRegistry;
1439
+ this.canvas = canvas;
1440
+ this.pinnedGatewayIds = /* @__PURE__ */ new Set();
1441
+ this.markedGateways = [];
1442
+ this.popovers = [];
1443
+ this.popoverLayer = inShadow();
1444
+ this.renderedState = "";
1445
+ this.snapshot = dataSimulation.getSnapshot();
1446
+ const unsubscribe = dataSimulation.subscribe((snapshot) => {
1447
+ this.snapshot = snapshot;
1448
+ this.render();
1449
+ });
1450
+ eventBus.on("element.hover", ({ element }) => {
1451
+ this.hoveredGatewayId = gatewayOf(element);
1452
+ this.render();
1453
+ });
1454
+ eventBus.on("element.click", ({ element }) => {
1455
+ if (!isGateway(element)) return;
1456
+ if (!this.pinnedGatewayIds.delete(element.id)) this.pinnedGatewayIds.add(element.id);
1457
+ this.render();
1458
+ });
1459
+ eventBus.on(["canvas.viewbox.changed", "canvas.resized"], () => this.placePopovers());
1460
+ canvas.getContainer().append(this.popoverLayer);
1461
+ eventBus.on("diagram.destroy", () => {
1462
+ unsubscribe();
1463
+ this.popoverLayer.remove();
1464
+ });
1465
+ }
1466
+ render() {
1467
+ const { decisions, shown } = new GatewayDecisionView(this.snapshot);
1468
+ const cards = shown.filter(
1469
+ ({ elementId }) => elementId === this.hoveredGatewayId || this.pinnedGatewayIds.has(elementId)
1470
+ );
1471
+ const state = JSON.stringify([
1472
+ decisions.map((entry) => entry.id),
1473
+ shown.map((entry) => entry.id),
1474
+ cards.map((entry) => [entry.id, this.pinnedGatewayIds.has(entry.elementId)])
1475
+ ]);
1476
+ if (state === this.renderedState) return;
1477
+ this.renderedState = state;
1478
+ this.overlays.remove({ type: OUTCOME_OVERLAY });
1479
+ this.unmarkGateways();
1480
+ for (const entry of decisions) this.showOutcomes(entry.decision);
1481
+ for (const entry of shown) this.markGateway(entry);
1482
+ this.showCards(cards);
1483
+ }
1484
+ markGateway({ elementId, decision }) {
1485
+ const gateway = this.elementRegistry.get(elementId);
1486
+ if (!gateway) return;
1487
+ this.canvas.addMarker(gateway, decision.stuckReason ? STUCK_MARKER : DECIDED_MARKER);
1488
+ this.markedGateways.push(gateway);
1489
+ }
1490
+ unmarkGateways() {
1491
+ for (const gateway of this.markedGateways) {
1492
+ this.canvas.removeMarker(gateway, DECIDED_MARKER);
1493
+ this.canvas.removeMarker(gateway, STUCK_MARKER);
1494
+ }
1495
+ this.markedGateways = [];
1496
+ }
1497
+ showOutcomes(decision) {
1498
+ for (const { flow, outcome, reason } of decision.flows) {
1499
+ const connection = this.elementRegistry.get(flow.id);
1500
+ if (!connection?.waypoints) continue;
1501
+ const badge = new OutcomeBadge(outcome, reason, flow.isDefault).element;
1502
+ badge.classList.add("bds-outcome--on-flow");
1503
+ this.overlays.add(connection, OUTCOME_OVERLAY, {
1504
+ position: badgePosition(connection.waypoints, BADGE_DISTANCE),
1505
+ scale: { min: BADGE_MIN_SCALE },
1506
+ html: inShadow(badge)
1507
+ });
1508
+ }
1509
+ }
1510
+ showCards(entries) {
1511
+ this.popovers = entries.flatMap((entry) => {
1512
+ const gateway = this.elementRegistry.get(entry.elementId);
1513
+ if (!gateway) return [];
1514
+ const close = () => {
1515
+ this.pinnedGatewayIds.delete(entry.elementId);
1516
+ this.render();
1517
+ };
1518
+ const card = new DecisionCard(entry, this.pinnedGatewayIds.has(entry.elementId) ? close : void 0).element;
1519
+ card.classList.add("bds-popover");
1520
+ card.dataset.elementId = entry.elementId;
1521
+ return [{ gateway, card }];
1522
+ });
1523
+ this.popoverLayer.shadowRoot.replaceChildren(...this.popovers.map(({ card }) => card));
1524
+ this.placePopovers();
1525
+ }
1526
+ placePopovers() {
1527
+ const container = this.canvas.getContainer();
1528
+ const bounds = { width: container.clientWidth, height: container.clientHeight };
1529
+ for (const { gateway, card } of this.popovers) {
1530
+ card.style.maxHeight = "";
1531
+ const { left, top, maxHeight, hidden } = placePopover(
1532
+ this.canvas.getAbsoluteBBox(gateway),
1533
+ { width: card.offsetWidth, height: card.offsetHeight },
1534
+ bounds
1535
+ );
1536
+ card.hidden = hidden;
1537
+ card.style.left = `${left}px`;
1538
+ card.style.top = `${top}px`;
1539
+ card.style.maxHeight = maxHeight === void 0 ? "" : `${maxHeight}px`;
1540
+ }
1541
+ }
1542
+ }
1543
+ DataSimulationOverlays.$inject = ["eventBus", "overlays", "elementRegistry", "canvas", "dataSimulation"];
1544
+
1545
+ const VARIABLES_ICON = '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M5.5 2.5C4 2.5 4 3.5 4 5v1c0 1-.8 2-2 2 1.2 0 2 1 2 2v1c0 1.5 0 2.5 1.5 2.5M10.5 2.5c1.5 0 1.5 1 1.5 2.5v1c0 1 .8 2 2 2-1.2 0-2 1-2 2v1c0 1.5 0 2.5-1.5 2.5" /></svg>';
1546
+ const CLOSE_ICON = '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M4 4l8 8M12 4l-8 8" /></svg>';
1547
+ class VariablesPanel {
1548
+ constructor(actions) {
1549
+ this.actions = actions;
1550
+ this.paletteEntry = h("button", {
1551
+ className: "bts-entry bds-palette-entry",
1552
+ type: "button",
1553
+ title: "Toggle Process Data",
1554
+ "aria-label": "Toggle Process Data"
1555
+ });
1556
+ this.engineBadge = h("span", { className: "bds-engine" });
1557
+ this.closeButton = h("button", { className: "bds-panel-close", type: "button", "aria-label": "Close" });
1558
+ this.instanceTitle = h("h3", { className: "bds-section-title" }, "Instance");
1559
+ this.instancePicker = h("select", {
1560
+ className: "bds-input bds-instance-select",
1561
+ "aria-label": "Process instance"
1562
+ });
1563
+ this.instanceBody = h("div", { className: "bds-instance-body" });
1564
+ this.issueList = h("ol", { className: "bds-log" });
1565
+ this.issueSection = h(
1566
+ "section",
1567
+ { className: "bds-section bds-issues" },
1568
+ h("h3", { className: "bds-section-title" }, "Issues"),
1569
+ this.issueList
1570
+ );
1571
+ this.shownInstances = "";
1572
+ this.paletteEntry.innerHTML = `<span class="bts-icon bds-variables-icon">${VARIABLES_ICON}</span>`;
1573
+ this.closeButton.innerHTML = CLOSE_ICON;
1574
+ const icon = h("span", { className: "bds-variables-icon" });
1575
+ icon.innerHTML = VARIABLES_ICON;
1576
+ this.element = h(
1577
+ "aside",
1578
+ { className: "bds-panel", "aria-label": "Process Data" },
1579
+ h(
1580
+ "header",
1581
+ { className: "bds-panel-header" },
1582
+ icon,
1583
+ h("h2", { className: "bds-panel-heading" }, "Process Data"),
1584
+ this.closeButton
1585
+ ),
1586
+ h(
1587
+ "div",
1588
+ { className: "bds-panel-body" },
1589
+ h("p", { className: "bds-panel-engine" }, this.engineBadge),
1590
+ h("section", { className: "bds-section bds-instance" }, this.instanceTitle, this.instanceBody),
1591
+ this.issueSection
1592
+ )
1593
+ );
1594
+ this.paletteEntry.addEventListener("click", () => this.toggle());
1595
+ this.closeButton.addEventListener("click", () => this.toggle(false));
1596
+ this.instancePicker.addEventListener("change", () => this.actions.selectInstance(this.instancePicker.value));
1597
+ this.toggle(false);
1598
+ }
1599
+ toggle(shown = this.element.hidden === true) {
1600
+ this.element.hidden = !shown;
1601
+ this.paletteEntry.classList.toggle("active", shown);
1602
+ }
1603
+ render(snapshot) {
1604
+ this.snapshot = snapshot;
1605
+ this.engineBadge.textContent = `${snapshot.engineLabel} \xB7 ${snapshot.expressionLanguage}`;
1606
+ this.renderInstance(snapshot);
1607
+ this.renderIssues(snapshot);
1608
+ }
1609
+ renderInstance({ instances, selectedInstanceId, scenarios }) {
1610
+ const editedInstance = instances.find((candidate) => candidate.id === this.editingInstanceId);
1611
+ if (editedInstance && editedInstance.status !== "completed" && editedInstance.id !== selectedInstanceId) {
1612
+ this.actions.selectInstance(editedInstance.id);
1613
+ return;
1614
+ }
1615
+ const instance = instances.find((candidate) => candidate.id === selectedInstanceId);
1616
+ this.renderInstancePicker(instances, selectedInstanceId, scenarios);
1617
+ if (this.editingInstanceId && this.editingInstanceId === instance?.id && instance.status !== "completed") return;
1618
+ this.editingInstanceId = void 0;
1619
+ this.instanceBody.replaceChildren(
1620
+ instance ? this.instanceView(instance) : h("p", { className: "bds-hint" }, "Press \u25B6 on a start event to start a process instance.")
1621
+ );
1622
+ }
1623
+ renderInstancePicker(instances, selectedInstanceId, scenarios) {
1624
+ const signature = JSON.stringify(instances.map((instance) => [instance.id, instance.status]));
1625
+ if (signature !== this.shownInstances) {
1626
+ this.shownInstances = signature;
1627
+ this.instancePicker.replaceChildren(
1628
+ ...instances.map((instance) => {
1629
+ const scenarioName = scenarios.find((scenario) => scenario.id === instance.scenarioId)?.name ?? "no scenario";
1630
+ return h("option", { value: instance.id }, `#${instance.number} ${scenarioName} (${instance.status})`);
1631
+ })
1632
+ );
1633
+ }
1634
+ this.instancePicker.value = selectedInstanceId ?? "";
1635
+ this.instancePicker.hidden = instances.length < 2;
1636
+ if (!this.instancePicker.isConnected) this.instanceTitle.after(this.instancePicker);
1637
+ }
1638
+ instanceView(instance) {
1639
+ const scenarioName = this.snapshot?.scenarios.find((scenario) => scenario.id === instance.scenarioId)?.name;
1640
+ const entries = Object.entries(instance.variables);
1641
+ const editButton = h("button", { className: "bds-button", type: "button" }, "Edit");
1642
+ editButton.addEventListener("click", () => this.editInstance(instance));
1643
+ return h(
1644
+ "div",
1645
+ {},
1646
+ h("p", { className: `bds-status bds-status--${instance.status}` }, this.describeStatus(instance)),
1647
+ scenarioName ? h("p", { className: "bds-hint" }, `Scenario: ${scenarioName}`) : null,
1648
+ entries.length ? h(
1649
+ "table",
1650
+ { className: "bds-variables" },
1651
+ h(
1652
+ "tbody",
1653
+ {},
1654
+ ...entries.map(
1655
+ ([name, value]) => h("tr", {}, h("th", { scope: "row" }, name), h("td", {}, h("code", {}, formatValue(value))))
1656
+ )
1657
+ )
1658
+ ) : h("p", { className: "bds-hint" }, "No variables yet."),
1659
+ h("p", { className: "bds-hint" }, "Hover a gateway to see why it took its flow, click it to keep the card open."),
1660
+ instance.status !== "completed" ? h("div", { className: "bds-actions" }, editButton) : null
1661
+ );
1662
+ }
1663
+ editInstance(instance) {
1664
+ this.editingInstanceId = instance.id;
1665
+ const editor = h("textarea", {
1666
+ className: "bds-input bds-json bds-instance-editor",
1667
+ spellcheck: "false",
1668
+ rows: "8",
1669
+ "aria-label": "Instance variables (JSON)"
1670
+ });
1671
+ editor.value = JSON.stringify(instance.variables, null, 2);
1672
+ const error = h("p", { className: "bds-error", role: "alert" });
1673
+ this.showError(error, editor, "");
1674
+ const applyButton = h("button", { className: "bds-button bds-button--primary", type: "button" }, "Apply");
1675
+ const cancelButton = h("button", { className: "bds-button", type: "button" }, "Cancel");
1676
+ applyButton.addEventListener("click", () => {
1677
+ const parsed = this.parseVariables(editor.value);
1678
+ if (typeof parsed === "string") {
1679
+ this.showError(error, editor, parsed);
1680
+ return;
1681
+ }
1682
+ this.editingInstanceId = void 0;
1683
+ this.actions.setInstanceVariables(instance.id, parsed);
1684
+ });
1685
+ cancelButton.addEventListener("click", () => {
1686
+ this.editingInstanceId = void 0;
1687
+ if (this.snapshot) this.renderInstance(this.snapshot);
1688
+ });
1689
+ this.instanceBody.replaceChildren(editor, error, h("div", { className: "bds-actions" }, cancelButton, applyButton));
1690
+ editor.focus();
1691
+ }
1692
+ renderIssues({ log, selectedInstanceId }) {
1693
+ const issues = log.filter(
1694
+ (entry) => entry.kind === "mapping-issue" && entry.instanceId === selectedInstanceId
1695
+ );
1696
+ this.issueSection.hidden = !issues.length;
1697
+ this.issueList.replaceChildren(
1698
+ ...issues.slice().reverse().map((issue) => this.renderMappingIssue(issue))
1699
+ );
1700
+ }
1701
+ describeStatus({ processName, status, waiting }) {
1702
+ if (status !== "waiting") return `${processName} \xB7 ${status}`;
1703
+ return `${processName} \xB7 waiting at ${waiting.map((gateway) => gateway.gatewayName).join(", ")}`;
1704
+ }
1705
+ showError(error, input, message) {
1706
+ error.textContent = message;
1707
+ error.hidden = !message;
1708
+ input.classList.toggle("bds-input--invalid", Boolean(message));
1709
+ }
1710
+ renderMappingIssue({ elementName, target, reason }) {
1711
+ return h(
1712
+ "li",
1713
+ { className: "bds-log-entry bds-log-entry--issue" },
1714
+ h("div", { className: "bds-log-title" }, elementName, h("span", { className: "bds-tag" }, "mapping")),
1715
+ h("p", { className: "bds-error" }, `${target}: ${reason}`)
1716
+ );
1717
+ }
1718
+ parseVariables(text) {
1719
+ try {
1720
+ const value = JSON.parse(text || "{}");
1721
+ return isVariables(value) ? value : "Variables must be a JSON object";
1722
+ } catch (error) {
1723
+ return `Invalid JSON: ${error.message}`;
1724
+ }
1725
+ }
1726
+ }
1727
+
1728
+ const PALETTE_INDEX = 4;
1729
+ class DataSimulationPanel {
1730
+ constructor(eventBus, canvas, palette, dataSimulation) {
1731
+ this.dataSimulation = dataSimulation;
1732
+ this.panel = new VariablesPanel({
1733
+ selectInstance: (instanceId) => dataSimulation.selectInstance(instanceId),
1734
+ setInstanceVariables: (instanceId, variables) => dataSimulation.setInstanceVariables(instanceId, variables)
1735
+ });
1736
+ this.panel.render(dataSimulation.getSnapshot());
1737
+ const host = inShadow(this.panel.element);
1738
+ canvas.getContainer().append(host);
1739
+ palette.addEntry(this.panel.paletteEntry, PALETTE_INDEX);
1740
+ this.showPaletteEntry();
1741
+ const unsubscribe = dataSimulation.subscribe((snapshot) => this.panel.render(snapshot));
1742
+ eventBus.on(TOGGLE_MODE_EVENT, () => this.panel.toggle(false));
1743
+ eventBus.on(DATA_TOGGLE_EVENT, () => this.showPaletteEntry());
1744
+ eventBus.on("diagram.destroy", () => {
1745
+ unsubscribe();
1746
+ host.remove();
1747
+ this.panel.paletteEntry.remove();
1748
+ });
1749
+ }
1750
+ showPaletteEntry() {
1751
+ this.panel.paletteEntry.hidden = !this.dataSimulation.isEnabled();
1752
+ }
1753
+ }
1754
+ DataSimulationPanel.$inject = ["eventBus", "canvas", "tokenSimulationPalette", "dataSimulation"];
1755
+
1756
+ const LABEL = "Data Simulation";
1757
+ const GAP = 8;
1758
+ const TOGGLE_ON = '<svg viewBox="0 0 26 14" aria-hidden="true"><rect x="1" y="1" width="24" height="12" rx="6" /><circle cx="18" cy="7" r="3.5" /></svg>';
1759
+ const TOGGLE_OFF = '<svg viewBox="0 0 26 14" aria-hidden="true"><rect x="1" y="1" width="24" height="12" rx="6" /><circle cx="8" cy="7" r="3.5" /></svg>';
1760
+ class DataSimulationToggle {
1761
+ constructor(eventBus, canvas, toggleMode, dataSimulation) {
1762
+ this.canvas = canvas;
1763
+ this.dataSimulation = dataSimulation;
1764
+ this.button = h("button", { className: "bds-data-toggle", type: "button" });
1765
+ this.simulating = false;
1766
+ this.render();
1767
+ canvas.getContainer().append(this.button);
1768
+ this.button.addEventListener("click", () => dataSimulation.setEnabled(!dataSimulation.isEnabled()));
1769
+ eventBus.on(TOGGLE_MODE_EVENT, ({ active }) => {
1770
+ this.simulating = active;
1771
+ if (active) this.placeNextToTokenSimulationToggle();
1772
+ });
1773
+ eventBus.on(DATA_TOGGLE_EVENT, () => {
1774
+ this.render();
1775
+ if (!this.simulating) return;
1776
+ toggleMode.toggleMode(false);
1777
+ toggleMode.toggleMode(true);
1778
+ });
1779
+ eventBus.on("diagram.destroy", () => {
1780
+ this.tokenToggleObserver?.disconnect();
1781
+ this.button.remove();
1782
+ });
1783
+ }
1784
+ render() {
1785
+ const enabled = this.dataSimulation.isEnabled();
1786
+ this.button.innerHTML = `${LABEL} <span class="bds-data-toggle-icon">${enabled ? TOGGLE_ON : TOGGLE_OFF}</span>`;
1787
+ this.button.classList.toggle("active", enabled);
1788
+ this.button.setAttribute("aria-pressed", String(enabled));
1789
+ }
1790
+ placeNextToTokenSimulationToggle() {
1791
+ const container = this.canvas.getContainer();
1792
+ const tokenToggle = container.querySelector(".bts-toggle-mode");
1793
+ if (!tokenToggle) return;
1794
+ const containerBox = container.getBoundingClientRect();
1795
+ const toggleBox = tokenToggle.getBoundingClientRect();
1796
+ const scale = containerBox.width / container.offsetWidth || 1;
1797
+ this.button.style.fontSize = getComputedStyle(tokenToggle).fontSize;
1798
+ this.button.style.left = `${(toggleBox.right - containerBox.left) / scale + GAP}px`;
1799
+ this.button.style.top = `${(toggleBox.top + toggleBox.height / 2 - containerBox.top) / scale - this.button.offsetHeight / 2}px`;
1800
+ this.observeTokenToggle(tokenToggle);
1801
+ }
1802
+ observeTokenToggle(tokenToggle) {
1803
+ if (this.tokenToggleObserver || typeof ResizeObserver !== "function") return;
1804
+ this.tokenToggleObserver = new ResizeObserver(() => this.placeNextToTokenSimulationToggle());
1805
+ this.tokenToggleObserver.observe(tokenToggle);
1806
+ }
1807
+ }
1808
+ DataSimulationToggle.$inject = ["eventBus", "canvas", "toggleMode", "dataSimulation"];
1809
+
1810
+ class StartFieldDeriver {
1811
+ derive(usages, { examples = [], taskResultNames = [] } = {}) {
1812
+ const written = /* @__PURE__ */ new Set([
1813
+ ...usages.flatMap((usage) => usage.outputTargets.map((target) => this.topLevelName(target))),
1814
+ ...taskResultNames
1815
+ ]);
1816
+ const usedBy = /* @__PURE__ */ new Map();
1817
+ for (const usage of usages) {
1818
+ const localNames = new Set(usage.inputTargets.map((target) => this.topLevelName(target)));
1819
+ for (const name of [...usage.conditionReads, ...usage.inputReads, ...usage.outputReads]) {
1820
+ if (written.has(name) || localNames.has(name)) continue;
1821
+ if (!usedBy.has(name)) usedBy.set(name, /* @__PURE__ */ new Set());
1822
+ usedBy.get(name).add(usage.elementName);
1823
+ }
1824
+ }
1825
+ return [...usedBy.entries()].map(([name, elements]) => ({
1826
+ name,
1827
+ type: this.inferType(examples.map((example) => example[name]).find((value) => value !== void 0)),
1828
+ usedBy: [...elements]
1829
+ }));
1830
+ }
1831
+ topLevelName(path) {
1832
+ return path.split(".")[0];
1833
+ }
1834
+ inferType(example) {
1835
+ if (typeof example === "number") return "number";
1836
+ if (typeof example === "boolean") return "boolean";
1837
+ if (typeof example === "string") return "text";
1838
+ if (Array.isArray(example) || isVariables(example)) return "json";
1839
+ return "auto";
1840
+ }
1841
+ }
1842
+
1843
+ const NO_SCENARIO = "";
1844
+ class StartDialog {
1845
+ constructor(options) {
1846
+ this.options = options;
1847
+ this.codec = new StartFieldCodec();
1848
+ this.scenarioSelect = h("select", {
1849
+ className: "bds-input bds-scenario-select",
1850
+ "aria-label": "Scenario"
1851
+ });
1852
+ this.scenarioDescription = h("p", { className: "bds-hint" });
1853
+ this.formContainer = h("div", { className: "bds-dialog-form" });
1854
+ this.noFieldsHint = h("p", { className: "bds-hint" }, "The process reads no start variables.");
1855
+ this.error = h("p", { className: "bds-error", role: "alert" });
1856
+ this.cancelButton = h("button", { className: "bds-button", type: "button" }, "Cancel");
1857
+ this.startButton = h(
1858
+ "button",
1859
+ { className: "bds-button bds-button--primary", type: "submit" },
1860
+ "Start instance"
1861
+ );
1862
+ this.fields = [];
1863
+ this.baseVariables = options.startVariables;
1864
+ this.scenarioSelect.append(
1865
+ h("option", { value: NO_SCENARIO }, "No scenario"),
1866
+ ...options.scenarios.map((scenario) => h("option", { value: scenario.id }, scenario.name))
1867
+ );
1868
+ this.scenarioSelect.value = options.selectedScenarioId ?? NO_SCENARIO;
1869
+ this.error.hidden = true;
1870
+ this.form = this.createForm();
1871
+ this.backdrop = h("div", { className: "bds-dialog-backdrop" }, this.form);
1872
+ this.rendered = this.renderForm();
1873
+ this.listen();
1874
+ }
1875
+ open(container) {
1876
+ this.showScenarioDescription();
1877
+ container.append(this.backdrop);
1878
+ if (this.fields.length) this.rendered.focus();
1879
+ else this.startButton.focus();
1880
+ }
1881
+ close() {
1882
+ this.rendered.destroy();
1883
+ this.backdrop.remove();
1884
+ }
1885
+ createForm() {
1886
+ const titleId = `bds-start-title-${Math.random().toString(36).slice(2)}`;
1887
+ return h(
1888
+ "form",
1889
+ { className: "bds-dialog", role: "dialog", "aria-modal": "true", "aria-labelledby": titleId },
1890
+ h(
1891
+ "header",
1892
+ { className: "bds-dialog-header" },
1893
+ h("h2", { className: "bds-panel-title", id: titleId }, `Start \u201C${this.options.processName}\u201D`),
1894
+ h("span", { className: "bds-engine" }, this.options.engineLabel)
1895
+ ),
1896
+ h(
1897
+ "div",
1898
+ { className: "bds-dialog-content" },
1899
+ this.options.scenarios.length ? h(
1900
+ "section",
1901
+ { className: "bds-section" },
1902
+ h("label", { className: "bds-label" }, "Scenario", this.scenarioSelect),
1903
+ this.scenarioDescription
1904
+ ) : null,
1905
+ h(
1906
+ "section",
1907
+ { className: "bds-section" },
1908
+ h("h3", { className: "bds-section-title" }, "Start variables"),
1909
+ this.formContainer,
1910
+ this.noFieldsHint
1911
+ ),
1912
+ this.error
1913
+ ),
1914
+ h("footer", { className: "bds-actions" }, this.cancelButton, this.startButton)
1915
+ );
1916
+ }
1917
+ listen() {
1918
+ this.scenarioSelect.addEventListener("change", () => this.switchScenario());
1919
+ this.cancelButton.addEventListener("click", () => this.close());
1920
+ this.backdrop.addEventListener("mousedown", (event) => {
1921
+ if (event.target === this.backdrop) this.close();
1922
+ });
1923
+ this.backdrop.addEventListener("keydown", (event) => {
1924
+ event.stopPropagation();
1925
+ if (event.key === "Escape") this.close();
1926
+ });
1927
+ this.form.addEventListener("submit", (event) => {
1928
+ event.preventDefault();
1929
+ this.submit();
1930
+ });
1931
+ }
1932
+ selectedScenarioId() {
1933
+ return this.scenarioSelect.value || null;
1934
+ }
1935
+ selectedScenario() {
1936
+ return this.options.scenarios.find((scenario) => scenario.id === this.scenarioSelect.value);
1937
+ }
1938
+ renderForm() {
1939
+ this.fields = this.options.fieldsFor(this.selectedScenarioId());
1940
+ this.noFieldsHint.hidden = this.fields.length > 0;
1941
+ return this.options.renderer.render(this.formContainer, this.fields, this.baseVariables);
1942
+ }
1943
+ switchScenario() {
1944
+ this.baseVariables = this.selectedScenario()?.variables ?? {};
1945
+ this.rendered.destroy();
1946
+ this.rendered = this.renderForm();
1947
+ this.showScenarioDescription();
1948
+ }
1949
+ showScenarioDescription() {
1950
+ const description = this.selectedScenario()?.description ?? "";
1951
+ this.scenarioDescription.textContent = description;
1952
+ this.scenarioDescription.hidden = !description;
1953
+ }
1954
+ submit() {
1955
+ const values = this.rendered.readValues();
1956
+ if (!values.ok) {
1957
+ this.error.textContent = values.reason;
1958
+ this.error.hidden = false;
1959
+ return;
1960
+ }
1961
+ this.close();
1962
+ this.options.onStart(this.selectedScenarioId(), this.codec.apply(this.baseVariables, values.values));
1963
+ }
1964
+ }
1965
+
1966
+ class VariableUsageCollector {
1967
+ constructor(engine) {
1968
+ this.engine = engine;
1969
+ }
1970
+ collect(container) {
1971
+ const usages = [];
1972
+ const visit = (element) => {
1973
+ if (element.type === "label") return;
1974
+ const usage = this.usageOf(element);
1975
+ if (usage) usages.push(usage);
1976
+ element.children?.forEach(visit);
1977
+ };
1978
+ container.children?.forEach(visit);
1979
+ return usages;
1980
+ }
1981
+ usageOf(element) {
1982
+ const businessObject = element.businessObject;
1983
+ if (is(element, "bpmn:SequenceFlow")) {
1984
+ const condition = this.engine.readCondition(businessObject);
1985
+ if (!condition) return void 0;
1986
+ return this.usage(element.source ?? element, { conditionReads: this.engine.readVariableNames(condition) });
1987
+ }
1988
+ if (!is(element, "bpmn:FlowNode")) return void 0;
1989
+ const inputs = this.engine.readInputMappings(businessObject);
1990
+ const outputs = this.engine.readOutputMappings(businessObject);
1991
+ return this.usage(element, {
1992
+ inputReads: inputs.flatMap((mapping) => this.engine.readVariableNames(mapping.source)),
1993
+ inputTargets: inputs.map((mapping) => mapping.target),
1994
+ outputReads: outputs.flatMap((mapping) => this.engine.readVariableNames(mapping.source)),
1995
+ outputTargets: outputs.map((mapping) => mapping.target)
1996
+ });
1997
+ }
1998
+ usage(element, reads) {
1999
+ return {
2000
+ elementName: elementName(element),
2001
+ conditionReads: [],
2002
+ inputReads: [],
2003
+ inputTargets: [],
2004
+ outputReads: [],
2005
+ outputTargets: [],
2006
+ ...reads
2007
+ };
2008
+ }
2009
+ }
2010
+
2011
+ class DataStartForm {
2012
+ constructor(config, eventBus, dataSimulation, store) {
2013
+ this.store = store;
2014
+ this.fieldDeriver = new StartFieldDeriver();
2015
+ this.renderer = config?.startFormRenderer ?? new SimpleStartFormRenderer();
2016
+ this.usageCollector = new VariableUsageCollector(dataSimulation.getEngine());
2017
+ eventBus.on(TOGGLE_MODE_EVENT, () => this.closeDialog());
2018
+ eventBus.on("diagram.destroy", () => {
2019
+ this.closeDialog();
2020
+ this.dialogHost?.remove();
2021
+ });
2022
+ }
2023
+ isProcessStart(element) {
2024
+ return is(element, "bpmn:StartEvent") && Boolean(element.parent) && (is(element.parent, "bpmn:Process") || is(element.parent, "bpmn:Participant"));
2025
+ }
2026
+ fieldsFor(startEvent, scenarioId) {
2027
+ const snapshot = this.store.getSnapshot();
2028
+ const examples = [snapshot.startVariables, ...snapshot.scenarios.map((scenario) => scenario.variables)];
2029
+ const taskResults = snapshot.scenarios.find((scenario) => scenario.id === scenarioId)?.taskResults ?? {};
2030
+ const taskResultNames = Object.values(taskResults).flatMap((result) => Object.keys(result));
2031
+ return this.fieldDeriver.derive(this.usageCollector.collect(startEvent.parent), { examples, taskResultNames });
2032
+ }
2033
+ open(startEvent, start) {
2034
+ this.closeDialog();
2035
+ const snapshot = this.store.getSnapshot();
2036
+ this.dialogHost ?? (this.dialogHost = document.body.appendChild(inShadow()));
2037
+ this.dialog = new StartDialog({
2038
+ processName: elementName(startEvent.parent),
2039
+ engineLabel: `${snapshot.engineLabel} \xB7 ${snapshot.expressionLanguage}`,
2040
+ scenarios: snapshot.scenarios,
2041
+ selectedScenarioId: snapshot.selectedScenarioId,
2042
+ startVariables: snapshot.startVariables,
2043
+ fieldsFor: (scenarioId) => this.fieldsFor(startEvent, scenarioId),
2044
+ renderer: this.renderer,
2045
+ onStart: (scenarioId, variables) => {
2046
+ this.dialog = void 0;
2047
+ this.store.selectScenario(scenarioId);
2048
+ this.store.setStartVariables(variables);
2049
+ start();
2050
+ }
2051
+ });
2052
+ this.dialog.open(this.dialogHost.shadowRoot);
2053
+ }
2054
+ closeDialog() {
2055
+ this.dialog?.close();
2056
+ this.dialog = void 0;
2057
+ }
2058
+ }
2059
+ DataStartForm.$inject = ["config.dataSimulation", "eventBus", "dataSimulation", "dataSimulationStore"];
2060
+
2061
+ const DataSimulationModule = {
2062
+ __init__: [
2063
+ "dataSimulation",
2064
+ "dataSimulationOverlays",
2065
+ "dataSimulationPanel",
2066
+ "dataSimulationToggle",
2067
+ "dataGatewayBehaviors",
2068
+ "dataGatewaySettings",
2069
+ "dataContextPads"
2070
+ ],
2071
+ dataSimulationStore: ["type", DataSimulationStore],
2072
+ dataSimulation: ["type", DataSimulation],
2073
+ dataSimulationOverlays: ["type", DataSimulationOverlays],
2074
+ dataSimulationPanel: ["type", DataSimulationPanel],
2075
+ dataSimulationToggle: ["type", DataSimulationToggle],
2076
+ dataGateways: ["type", DataGateways],
2077
+ dataStartForm: ["type", DataStartForm],
2078
+ dataGatewayBehaviors: ["type", DataGatewayBehaviors],
2079
+ dataGatewaySettings: ["type", DataGatewaySettings],
2080
+ dataContextPads: ["type", DataContextPads]
2081
+ };
2082
+
2083
+ export { Camunda7Engine, DataSimulationStore, EngineRegistry, GatewayRouter, ScenarioError, ScenarioParser, SimpleStartFormRenderer, StartFieldCodec, ZeebeEngine, camunda7Engine, DataSimulationModule as default, zeebeEngine };
2084
+ //# sourceMappingURL=index.js.map