@rotorsoft/act-diagram 0.1.2 → 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.
@@ -1,4 +1,8 @@
1
1
  import type { DomainModel, FileTab } from "../types/index.js";
2
+ /** Replace non-executable content with same-length whitespace (preserving offsets).
3
+ * `level: "full"` strips comments + strings + template literals (for scanning).
4
+ * `level: "nav"` strips comments + template literals only (for navigation). */
5
+ export declare const stripNonCode: (src: string, level?: "full" | "nav") => string;
2
6
  export declare function extractModel(files: FileTab[]): {
3
7
  model: DomainModel;
4
8
  error?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../../../src/client/lib/evaluate.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAmN9D,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG;IAC9C,KAAK,EAAE,WAAW,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAsBA"}
1
+ {"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../../../src/client/lib/evaluate.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAK9D;;gFAEgF;AAChF,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,EAAE,QAAO,MAAM,GAAG,KAAc,WAYvE,CAAC;AA8NF,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG;IAC9C,KAAK,EAAE,WAAW,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAGA"}
@@ -1 +1 @@
1
- {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../../../src/client/lib/layout.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,WAAW,EAAa,MAAM,mBA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,OAsEpD;AAWD,+CAA+C;AAC/C,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAoB3D,CAAC;AAEF;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAmB5D"}
1
+ {"version":3,"file":"mock-builders.d.ts","sourceRoot":"","sources":["../../../../src/client/lib/mock-builders.ts"],"names":[],"mappings":"AAQA,4FAA4F;AAC5F,wBAAgB,WAAW,SAAK;AA2DhC,wBAAgB,SAAS,CACvB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC1B,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI;qBAyCV,GAAG;sBACJ,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;EAatC;AAuDD,wBAAgB,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,OAkDtD;AAED,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,OA8B5E;AAED,wBAAgB,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,OAsEpD;AAWD,+CAA+C;AAC/C,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAoB3D,CAAC;AAEF;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAmB5D"}
@@ -1 +1 @@
1
- {"version":3,"file":"navigate.d.ts","sourceRoot":"","sources":["../../../../src/client/lib/navigate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAkIjD,KAAK,cAAc,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,EAAE,EAChB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,GAAG,SAAS,CAqJ5B"}
1
+ {"version":3,"file":"navigate.d.ts","sourceRoot":"","sources":["../../../../src/client/lib/navigate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAoFjD,KAAK,cAAc,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAElE,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,EAAE,EAChB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,GAAG,SAAS,CA8J5B"}
package/dist/index.cjs CHANGED
@@ -417,7 +417,10 @@ function captureDispatches(handler) {
417
417
  if (typeof actionName === "string" && !dispatches.includes(actionName))
418
418
  dispatches.push(actionName);
419
419
  return Promise.resolve([]);
420
- }
420
+ },
421
+ load: () => Promise.resolve({}),
422
+ query: () => Promise.resolve({ count: 0 }),
423
+ query_array: () => Promise.resolve([])
421
424
  };
422
425
  const mockEvent = new Proxy({}, {
423
426
  get: (_, prop) => prop === "stream" ? "mock" : prop === "data" ? new Proxy({}, { get: () => "" }) : ""
@@ -710,6 +713,15 @@ function resolve(imp, fromPath, byKey) {
710
713
  }
711
714
 
712
715
  // src/client/lib/evaluate.ts
716
+ var stripNonCode = (src, level = "full") => {
717
+ const blank = (m) => m.replace(/[^\n]/g, " ");
718
+ let result = src.replace(/\/\/[^\n]*/g, blank).replace(/\/\*[\s\S]*?\*\//g, blank).replace(/`(?:\\[\s\S]|[^`])*`/g, blank);
719
+ if (level === "full") {
720
+ result = result.replace(/"(?:\\[\s\S]|[^"])*"/g, blank).replace(/'(?:\\[\s\S]|[^'])*'/g, blank);
721
+ }
722
+ return result;
723
+ };
724
+ var isSourceFile = (f) => f.path.endsWith(".ts") && !f.path.endsWith(".d.ts") && !f.path.endsWith(".tsx") && !f.path.endsWith(".spec.ts") && !f.path.endsWith(".test.ts") && !f.path.includes("node_modules/") && !f.path.includes("__tests__/") && !f.path.includes("/test/") && !f.path.startsWith("test/");
713
725
  function transpile(code) {
714
726
  try {
715
727
  const safe = code.replace(/\bimport\.meta\.\w+/g, "'__import_meta__'");
@@ -731,7 +743,8 @@ function execute(files) {
731
743
  projections: [],
732
744
  acts: [],
733
745
  error: void 0,
734
- fileErrors: /* @__PURE__ */ new Map()
746
+ fileErrors: /* @__PURE__ */ new Map(),
747
+ expectedSlices: /* @__PURE__ */ new Map()
735
748
  };
736
749
  try {
737
750
  const __built__ = {
@@ -783,11 +796,7 @@ function execute(files) {
783
796
  }
784
797
  return unknownModuleProxy();
785
798
  };
786
- const sorted = topoSort(
787
- files.filter(
788
- (f) => f.path.endsWith(".ts") && !f.path.endsWith(".d.ts") && !f.path.endsWith(".tsx") && !f.path.endsWith(".spec.ts") && !f.path.endsWith(".test.ts") && !f.path.includes("node_modules/") && !f.path.includes("__tests__/") && !f.path.includes("/test/") && !f.path.startsWith("test/")
789
- )
790
- );
799
+ const sorted = topoSort(files.filter(isSourceFile));
791
800
  for (const file of sorted) {
792
801
  _currentFile = file.path;
793
802
  const js = transpile(file.content);
@@ -797,10 +806,19 @@ function execute(files) {
797
806
  const sliceNamesInAct = [];
798
807
  const wsRe = /\.withSlice\(\s*(?:\w+\.)*(\w+)\s*\)/g;
799
808
  let wsm;
800
- while ((wsm = wsRe.exec(js)) !== null) {
809
+ const codeOnly = stripNonCode(js);
810
+ while ((wsm = wsRe.exec(codeOnly)) !== null) {
801
811
  if (!sliceNamesInAct.includes(wsm[1])) sliceNamesInAct.push(wsm[1]);
802
812
  }
803
- const fileRequire = (mod) => resolveModule(mod, key);
813
+ for (const m of codeOnly.matchAll(
814
+ /(?:exports\.)?(\w+)\s*=\s*(?:\w+\.)?slice(?:\s*\(\s*\)|\.call\(void 0,\s*\))/g
815
+ )) {
816
+ result.expectedSlices.set(m[1], file.path);
817
+ }
818
+ const fileRequire = Object.assign(
819
+ (mod) => resolveModule(mod, key),
820
+ { resolve: (mod) => mod, cache: {}, main: void 0 }
821
+ );
804
822
  try {
805
823
  const cleanJs = js.replace(/\bconst\s+__dirname\b/g, "var __dirname").replace(/\bconst\s+__filename\b/g, "var __filename");
806
824
  const fn = new Function(
@@ -846,48 +864,10 @@ function execute(files) {
846
864
  }
847
865
  function extractModel(files) {
848
866
  const result = execute(files);
849
- const expectedSlices = /* @__PURE__ */ new Map();
850
- for (const file of files) {
851
- if (!file.path.endsWith(".ts") || file.path.endsWith(".d.ts") || file.path.endsWith(".spec.ts") || file.path.endsWith(".test.ts") || file.path.includes("node_modules/"))
852
- continue;
853
- for (const m of file.content.matchAll(
854
- /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*=\s*slice\s*\(\s*\)/g
855
- )) {
856
- expectedSlices.set(m[1], file.path);
857
- }
858
- }
859
- return buildModel(result, files, expectedSlices);
867
+ return buildModel(result, files, result.expectedSlices);
860
868
  }
861
869
 
862
870
  // src/client/lib/navigate.ts
863
- function isInsideComment(content, matchIndex) {
864
- const before = content.slice(0, matchIndex);
865
- const lastNl = before.lastIndexOf("\n");
866
- const lineStart = lastNl >= 0 ? lastNl + 1 : 0;
867
- const lineEnd = content.indexOf("\n", matchIndex);
868
- const lineText = content.slice(lineStart, lineEnd >= 0 ? lineEnd : content.length).trimStart();
869
- if (lineText.startsWith("//") || lineText.startsWith("*") || lineText.startsWith("/*")) {
870
- return true;
871
- }
872
- const lastBlockOpen = before.lastIndexOf("/*");
873
- if (lastBlockOpen >= 0) {
874
- const lastBlockClose = before.lastIndexOf("*/");
875
- if (lastBlockClose < lastBlockOpen) return true;
876
- }
877
- return false;
878
- }
879
- function findNonCommentMatch(content, re, startFrom = 0) {
880
- const globalRe = new RegExp(
881
- re.source,
882
- re.flags.includes("g") ? re.flags : re.flags + "g"
883
- );
884
- globalRe.lastIndex = startFrom;
885
- let match;
886
- while ((match = globalRe.exec(content)) !== null) {
887
- if (!isInsideComment(content, match.index)) return match.index;
888
- }
889
- return -1;
890
- }
891
871
  function positionAt(content, index) {
892
872
  const before = content.slice(0, index);
893
873
  const line = before.split("\n").length;
@@ -963,10 +943,19 @@ function buildPatterns(esc, type) {
963
943
  }
964
944
  }
965
945
  function navigateToCode(files, name, type, targetFile) {
946
+ const stripped = /* @__PURE__ */ new Map();
947
+ const code = (f) => {
948
+ let c = stripped.get(f.path);
949
+ if (c === void 0) {
950
+ c = stripNonCode(f.content, "nav");
951
+ stripped.set(f.path, c);
952
+ }
953
+ return c;
954
+ };
966
955
  if (type === "file") {
967
956
  const file = files.find((f) => f.path === name || f.path.endsWith(name));
968
957
  if (file) {
969
- const actMatch = /\bact\s*\(\s*\)/.exec(file.content);
958
+ const actMatch = /\bact\s*\(\s*\)/.exec(code(file));
970
959
  if (actMatch) {
971
960
  const { line, col } = positionAt(file.content, actMatch.index);
972
961
  return { file: file.path, line, col };
@@ -978,31 +967,35 @@ function navigateToCode(files, name, type, targetFile) {
978
967
  if (targetFile) {
979
968
  const file = files.find((f) => f.path === targetFile);
980
969
  if (file) {
970
+ const c = code(file);
981
971
  const esc2 = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
982
972
  if (type === "event") {
983
973
  const emitsBlockRe = new RegExp(
984
974
  `\\.emits\\([\\s\\S]*?(${esc2})\\s*[,:}]`
985
975
  );
986
- const blockMatch = emitsBlockRe.exec(file.content);
976
+ const blockMatch = emitsBlockRe.exec(c);
987
977
  if (blockMatch) {
988
978
  const nameIdx = blockMatch.index + blockMatch[0].lastIndexOf(name);
989
979
  const { line, col } = positionAt(file.content, nameIdx);
990
980
  return { file: file.path, line, col };
991
981
  }
992
982
  const nameRe2 = new RegExp(`\\b${esc2}\\b`, "g");
993
- if (findNonCommentMatch(file.content, nameRe2) >= 0) {
994
- const emitsIdx = findNonCommentMatch(file.content, /\.emits\s*\(/);
995
- if (emitsIdx >= 0) {
996
- const { line, col } = positionAt(file.content, emitsIdx + 1);
983
+ if (nameRe2.exec(c)) {
984
+ const emitsMatch = /\.emits\s*\(/.exec(c);
985
+ if (emitsMatch) {
986
+ const { line, col } = positionAt(
987
+ file.content,
988
+ emitsMatch.index + 1
989
+ );
997
990
  return { file: file.path, line, col };
998
991
  }
999
992
  }
1000
993
  }
1001
994
  if (type === "guard") {
1002
995
  const descRe = new RegExp(`description:\\s*["'\`]${esc2}["'\`]`);
1003
- const descMatch = descRe.exec(file.content);
996
+ const descMatch = descRe.exec(c);
1004
997
  if (descMatch) {
1005
- const before = file.content.slice(0, descMatch.index);
998
+ const before = c.slice(0, descMatch.index);
1006
999
  const declRe = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*Invariant[^=]*)?\s*=/g;
1007
1000
  let lastDecl = null;
1008
1001
  let m;
@@ -1020,19 +1013,20 @@ function navigateToCode(files, name, type, targetFile) {
1020
1013
  }
1021
1014
  if (type === "action") {
1022
1015
  const nameRe2 = new RegExp(`\\b${esc2}\\b`, "g");
1023
- const blockStart = file.content.indexOf(".on(");
1016
+ const blockStart = c.indexOf(".on(");
1024
1017
  if (blockStart >= 0) {
1025
- const idx2 = findNonCommentMatch(file.content, nameRe2, blockStart);
1026
- if (idx2 >= 0) {
1027
- const { line, col } = positionAt(file.content, idx2);
1018
+ nameRe2.lastIndex = blockStart;
1019
+ const match2 = nameRe2.exec(c);
1020
+ if (match2) {
1021
+ const { line, col } = positionAt(file.content, match2.index);
1028
1022
  return { file: file.path, line, col };
1029
1023
  }
1030
1024
  }
1031
1025
  }
1032
- const nameRe = new RegExp(`\\b${esc2}\\b`, "g");
1033
- const idx = findNonCommentMatch(file.content, nameRe);
1034
- if (idx >= 0) {
1035
- const { line, col } = positionAt(file.content, idx);
1026
+ const nameRe = new RegExp(`\\b${esc2}\\b`);
1027
+ const match = nameRe.exec(c);
1028
+ if (match) {
1029
+ const { line, col } = positionAt(file.content, match.index);
1036
1030
  return { file: file.path, line, col };
1037
1031
  }
1038
1032
  }
@@ -1047,9 +1041,10 @@ function navigateToCode(files, name, type, targetFile) {
1047
1041
  const descRe = new RegExp(`description:\\s*["'\`]${esc}["'\`]`);
1048
1042
  for (const f of sortedFiles) {
1049
1043
  if (!/\.tsx?$/.test(f.path)) continue;
1050
- const descMatch = descRe.exec(f.content);
1051
- if (descMatch && !isInsideComment(f.content, descMatch.index)) {
1052
- const before = f.content.slice(0, descMatch.index);
1044
+ const c = code(f);
1045
+ const descMatch = descRe.exec(c);
1046
+ if (descMatch) {
1047
+ const before = c.slice(0, descMatch.index);
1053
1048
  const declRe = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*Invariant[^=]*)?\s*=/g;
1054
1049
  let lastDecl = null;
1055
1050
  let m;
@@ -1066,18 +1061,17 @@ function navigateToCode(files, name, type, targetFile) {
1066
1061
  }
1067
1062
  const patterns = buildPatterns(esc, type);
1068
1063
  for (const re of patterns) {
1069
- for (let i = 0; i < sortedFiles.length; i++) {
1070
- if (!/\.tsx?$/.test(sortedFiles[i].path)) continue;
1071
- const content = sortedFiles[i].content;
1064
+ for (const f of sortedFiles) {
1065
+ if (!/\.tsx?$/.test(f.path)) continue;
1066
+ const c = code(f);
1072
1067
  const globalRe = new RegExp(re.source, re.flags + "g");
1073
1068
  let match;
1074
- while ((match = globalRe.exec(content)) !== null) {
1075
- if (isInsideComment(content, match.index)) continue;
1069
+ while ((match = globalRe.exec(c)) !== null) {
1076
1070
  const matchText = match[0];
1077
1071
  const nameOffsetInMatch = matchText.lastIndexOf(name);
1078
1072
  const nameStart = match.index + Math.max(0, nameOffsetInMatch);
1079
- const { line, col } = positionAt(content, nameStart);
1080
- return { file: sortedFiles[i].path, line, col };
1073
+ const { line, col } = positionAt(f.content, nameStart);
1074
+ return { file: f.path, line, col };
1081
1075
  }
1082
1076
  }
1083
1077
  }
@@ -1286,7 +1280,9 @@ function placeChain(measure, rDef, reactionY, rX, triggeredFromX, triggeredFromY
1286
1280
  nextX += STATE_W + GAP;
1287
1281
  }
1288
1282
  const evtX = nextX;
1289
- let emitY = rowCenterY - row.emitsH / 2;
1283
+ const nEvents = row.emitInfos.length;
1284
+ const eventsOnlyH = nEvents * H + (nEvents - 1) * (GAP / 2);
1285
+ let emitY = rowCenterY - eventsOnlyH / 2;
1290
1286
  for (const emit of row.emitInfos) {
1291
1287
  ns.push({
1292
1288
  key: `e:${emit.name}:dispatched:${rDef.handlerName}:${row.an}`,
@@ -1316,7 +1312,7 @@ function placeChain(measure, rDef, reactionY, rX, triggeredFromX, triggeredFromY
1316
1312
  sliceRightXRef
1317
1313
  );
1318
1314
  }
1319
- emitY += emit.h;
1315
+ emitY += H + GAP / 2;
1320
1316
  }
1321
1317
  if (row.emitInfos.length > 0) nextX = evtX + W + GAP;
1322
1318
  sliceRightXRef.value = Math.max(sliceRightXRef.value, nextX);
@@ -1448,28 +1444,27 @@ function computeLayout(viewModel) {
1448
1444
  const measuredEvents = [];
1449
1445
  let evtBlockH = 0;
1450
1446
  for (const { eventName: en, actionName } of eventRows) {
1451
- const rDef = sliceReactionByEvent.get(en);
1452
- let eventH = H;
1453
- let chain;
1454
- let chainReaction;
1455
- if (rDef && !visitedEvents.has(en) && !visitedReactions.has(rDef.handlerName)) {
1456
- visitedEvents.add(en);
1457
- visitedReactions.add(rDef.handlerName);
1458
- chain = measureChain(
1459
- rDef,
1460
- sliceReactionByEvent,
1461
- visitedReactions,
1462
- viewModel.states
1463
- );
1464
- chainReaction = rDef;
1465
- eventH = Math.max(H, chain.groupH);
1447
+ const chains = [];
1448
+ if (!visitedEvents.has(en)) {
1449
+ const rDefs = sliceReactionsByEvent.get(en) ?? [];
1450
+ for (const rDef of rDefs) {
1451
+ if (visitedReactions.has(rDef.handlerName)) continue;
1452
+ visitedReactions.add(rDef.handlerName);
1453
+ const chain = measureChain(
1454
+ rDef,
1455
+ sliceReactionByEvent,
1456
+ visitedReactions,
1457
+ viewModel.states
1458
+ );
1459
+ chains.push({ chain, reaction: rDef });
1460
+ }
1461
+ if (rDefs.length > 0) visitedEvents.add(en);
1466
1462
  }
1467
1463
  measuredEvents.push({
1468
1464
  eventName: en,
1469
1465
  actionName,
1470
- h: eventH,
1471
- chain,
1472
- chainReaction
1466
+ h: H,
1467
+ chains
1473
1468
  });
1474
1469
  if (evtBlockH > 0) evtBlockH += GAP / 2;
1475
1470
  evtBlockH += H;
@@ -1491,12 +1486,7 @@ function computeLayout(viewModel) {
1491
1486
  let chainWatermark = -Infinity;
1492
1487
  const eventYMap = /* @__PURE__ */ new Map();
1493
1488
  for (let ei = 0; ei < measuredEvents.length; ei++) {
1494
- const {
1495
- eventName: en,
1496
- actionName,
1497
- chain,
1498
- chainReaction
1499
- } = measuredEvents[ei];
1489
+ const { eventName: en, actionName, chains } = measuredEvents[ei];
1500
1490
  ns.push({
1501
1491
  key: `e:${en}:${slice.name}:${actionName}`,
1502
1492
  pos: { x: eventColX, y: evtY },
@@ -1507,7 +1497,7 @@ function computeLayout(viewModel) {
1507
1497
  reactions: eventReactions.get(en)
1508
1498
  });
1509
1499
  eventYMap.set(en, evtY);
1510
- if (chain && chainReaction) {
1500
+ for (const { chain, reaction: chainReaction } of chains) {
1511
1501
  const rX = eventColX + W + GAP * 3;
1512
1502
  const minReactionY = chainWatermark + chain.dispatchBlockH / 2 - H / 2;
1513
1503
  const reactionY = Math.max(evtY, minReactionY);
@@ -1589,33 +1579,18 @@ function computeLayout(viewModel) {
1589
1579
  y += primaryBlockH + GAP / 2;
1590
1580
  partIdx++;
1591
1581
  }
1592
- const remainingYByEvent = /* @__PURE__ */ new Map();
1593
1582
  for (const r of slice.reactions) {
1594
1583
  if (r.isVoid || visitedReactions.has(r.handlerName)) continue;
1595
- const trigNode = ns.find(
1596
- (n) => n.type === "event" && n.label === r.event && n.key.includes(slice.name)
1597
- );
1598
- const baseY = trigNode ? trigNode.pos.y : y;
1599
- const rY = remainingYByEvent.get(r.event) ?? baseY;
1600
1584
  const rX = sliceRightX + GAP * 2;
1601
- const rp = { x: rX, y: rY };
1585
+ const rp = { x: rX, y };
1602
1586
  ns.push({
1603
1587
  key: `r:${r.handlerName}:${slice.name}`,
1604
1588
  pos: rp,
1605
1589
  type: "reaction",
1606
1590
  label: r.handlerName
1607
1591
  });
1608
- if (trigNode) {
1609
- es.push({
1610
- from: { x: trigNode.pos.x + W, y: trigNode.pos.y + H / 2 },
1611
- to: { x: rp.x, y: rp.y + H / 2 },
1612
- color: COLORS.reaction.border,
1613
- dash: true
1614
- });
1615
- }
1616
- remainingYByEvent.set(r.event, rY + H + GAP / 2);
1617
1592
  sliceRightX = Math.max(sliceRightX, rX + W + GAP);
1618
- y = Math.max(y, rY + H + GAP / 2);
1593
+ y += H + GAP / 2;
1619
1594
  }
1620
1595
  const bbox = {
1621
1596
  minX: Infinity,