@diagrammo/dgmo 0.46.0 → 0.48.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 (534) hide show
  1. package/dist/advanced.d.ts +3 -855
  2. package/dist/advanced.js +541 -70107
  3. package/dist/analyzer-UYKBXAKR.js +15 -0
  4. package/dist/auto.js +1 -1
  5. package/dist/auto.mjs +1 -1
  6. package/dist/block.js +83 -69417
  7. package/dist/calculator-LDYQCDDY.js +11 -0
  8. package/dist/charts-d3-QOZHKTCT.js +25 -0
  9. package/dist/chunk-2DXMZRWJ.js +800 -0
  10. package/dist/chunk-2LACINWN.js +786 -0
  11. package/dist/chunk-33LCUH4H.js +893 -0
  12. package/dist/chunk-3CIOJ5YJ.js +35 -0
  13. package/dist/chunk-3HDBAXF5.js +86 -0
  14. package/dist/chunk-3JLKYGBQ.js +290 -0
  15. package/dist/chunk-3MQQNXPD.js +415 -0
  16. package/dist/chunk-3R5POCTZ.js +967 -0
  17. package/dist/chunk-3SMGIJDD.js +112 -0
  18. package/dist/chunk-44CM72SQ.js +409 -0
  19. package/dist/chunk-4GRI7MEB.js +1604 -0
  20. package/dist/chunk-4OHACBGX.js +606 -0
  21. package/dist/chunk-5DH3KYFH.js +21 -0
  22. package/dist/chunk-5MLYVTYM.js +76 -0
  23. package/dist/chunk-5QXL4NYS.js +553 -0
  24. package/dist/chunk-5WRI5ZAA.js +31 -0
  25. package/dist/chunk-6EK55ART.js +117 -0
  26. package/dist/chunk-6FZYCKXB.js +2065 -0
  27. package/dist/chunk-6HO5ZTXK.js +277 -0
  28. package/dist/chunk-6KFWC4CO.js +7 -0
  29. package/dist/chunk-6MTWIQVO.js +121 -0
  30. package/dist/chunk-6NYWYNBI.js +329 -0
  31. package/dist/chunk-6SM5NJQH.js +620 -0
  32. package/dist/chunk-725LDASD.js +422 -0
  33. package/dist/chunk-76OWZ3BA.js +130 -0
  34. package/{src/block/parser.ts → dist/chunk-7JEGTRLD.js} +100 -189
  35. package/dist/chunk-A44USUV7.js +923 -0
  36. package/dist/chunk-A4GOY3PE.js +25 -0
  37. package/dist/chunk-A4VFQH5G.js +251 -0
  38. package/dist/chunk-AELOBFW5.js +375 -0
  39. package/dist/chunk-AN2MOO5T.js +522 -0
  40. package/dist/chunk-BMR4CIEO.js +41 -0
  41. package/dist/chunk-BS7SV7C3.js +51 -0
  42. package/dist/chunk-BUPDIHML.js +613 -0
  43. package/dist/chunk-BUVJFRPY.js +887 -0
  44. package/dist/chunk-C3Z4DX3V.js +112 -0
  45. package/dist/chunk-CI2G3OEB.js +1818 -0
  46. package/dist/chunk-CKNVO24D.js +54 -0
  47. package/dist/chunk-CUVHQHZ7.js +391 -0
  48. package/dist/chunk-CXK4DZH3.js +114 -0
  49. package/dist/{editor.cjs → chunk-DKEPS5LH.js} +14 -225
  50. package/dist/chunk-DU7W62N5.js +487 -0
  51. package/dist/chunk-DZAQBW35.js +751 -0
  52. package/dist/chunk-EB6FPQUP.js +316 -0
  53. package/dist/chunk-EMS2SK26.js +376 -0
  54. package/dist/chunk-ERLBPDGU.js +510 -0
  55. package/dist/chunk-EVCVDTXE.js +732 -0
  56. package/dist/chunk-FCIIHT24.js +384 -0
  57. package/dist/chunk-FFUN5D66.js +97 -0
  58. package/dist/chunk-FITOLXSX.js +714 -0
  59. package/dist/chunk-FMDSF3OV.js +68 -0
  60. package/dist/chunk-FNB3PNGF.js +410 -0
  61. package/dist/chunk-G2H74XJZ.js +2104 -0
  62. package/dist/chunk-GMR5MFHJ.js +339 -0
  63. package/dist/chunk-H6PI3KJT.js +305 -0
  64. package/dist/chunk-I46X5VUA.js +59 -0
  65. package/dist/chunk-I5IGB56C.js +255 -0
  66. package/dist/chunk-IH6ZMVQ5.js +3950 -0
  67. package/dist/chunk-IJZFN3HM.js +463 -0
  68. package/dist/chunk-IPWPWM6R.js +3079 -0
  69. package/dist/chunk-IYULMRBE.js +23 -0
  70. package/dist/chunk-IZMRON6C.js +167 -0
  71. package/dist/chunk-J5FIXQRT.js +813 -0
  72. package/dist/chunk-JED6ZDEE.js +73 -0
  73. package/dist/chunk-JEUJOX5X.js +136 -0
  74. package/dist/chunk-JM4LEPY3.js +436 -0
  75. package/dist/chunk-L3UHP6TD.js +101 -0
  76. package/dist/chunk-L66GEFB6.js +524 -0
  77. package/dist/chunk-LIOHW36Z.js +469 -0
  78. package/dist/chunk-LP7EC4MI.js +16 -0
  79. package/dist/chunk-MITI6NOL.js +548 -0
  80. package/dist/chunk-MO5YHHMQ.js +168 -0
  81. package/dist/chunk-MZSBFAPJ.js +885 -0
  82. package/dist/chunk-NNAAJVBU.js +9 -0
  83. package/dist/chunk-NOTA6TEI.js +47 -0
  84. package/dist/chunk-NURGB5Z4.js +335 -0
  85. package/dist/chunk-NX4EQS3U.js +1062 -0
  86. package/dist/chunk-NXMESY4J.js +1 -0
  87. package/dist/chunk-OJR3MQYV.js +1458 -0
  88. package/dist/chunk-OURHMODR.js +454 -0
  89. package/dist/chunk-P235SVAH.js +1057 -0
  90. package/dist/chunk-P4RH4OSP.js +1038 -0
  91. package/dist/chunk-P6T66CCZ.js +226 -0
  92. package/dist/chunk-PBAHEPLQ.js +223 -0
  93. package/dist/chunk-PBHE5UG6.js +1530 -0
  94. package/dist/chunk-PDKUANDZ.js +35 -0
  95. package/dist/chunk-PWIHZ6NJ.js +296 -0
  96. package/{src/c4/layout.ts → dist/chunk-QEBUY5NY.js} +384 -1140
  97. package/dist/chunk-QLCCJEJI.js +253 -0
  98. package/dist/chunk-QOOUC2J5.js +52 -0
  99. package/dist/chunk-QYTPPDAO.js +402 -0
  100. package/dist/chunk-R3XI2VC7.js +801 -0
  101. package/dist/chunk-RCERWOJR.js +154 -0
  102. package/dist/chunk-RJE5JTVK.js +362 -0
  103. package/dist/chunk-RTLBSQ3G.js +1155 -0
  104. package/dist/chunk-RUNNI6VE.js +448 -0
  105. package/dist/chunk-RVMRZAPB.js +354 -0
  106. package/dist/chunk-RYEGFMUO.js +955 -0
  107. package/dist/chunk-RZCF2VVM.js +528 -0
  108. package/dist/chunk-SML67VPV.js +1025 -0
  109. package/dist/chunk-SQ7IY53Q.js +44 -0
  110. package/dist/chunk-SQAG3UXH.js +161 -0
  111. package/dist/chunk-SRTU6HMQ.js +1851 -0
  112. package/dist/chunk-T2OE3YQB.js +550 -0
  113. package/dist/chunk-T3UBLACL.js +299 -0
  114. package/dist/chunk-TLVIHFRO.js +296 -0
  115. package/dist/chunk-TYS6CSS5.js +52 -0
  116. package/dist/chunk-U6EQI3U6.js +130 -0
  117. package/dist/chunk-UJ4FJLBF.js +86 -0
  118. package/dist/chunk-ULOEATBZ.js +347 -0
  119. package/dist/chunk-UNCCZ3NU.js +127 -0
  120. package/dist/chunk-USZW2HHU.js +197 -0
  121. package/dist/chunk-UWN33VNX.js +1610 -0
  122. package/dist/chunk-UZ7EZW3B.js +40 -0
  123. package/dist/chunk-VOKGH627.js +37 -0
  124. package/dist/chunk-WBRZJOEC.js +204 -0
  125. package/dist/chunk-WCSOJFU3.js +380 -0
  126. package/dist/chunk-WCT3NYCV.js +160 -0
  127. package/dist/chunk-WVAJFAIA.js +529 -0
  128. package/dist/chunk-X5LCYCL5.js +394 -0
  129. package/dist/chunk-XAKEUMEJ.js +1256 -0
  130. package/dist/chunk-Y2ZE3MSG.js +590 -0
  131. package/dist/chunk-Y3J7VR52.js +646 -0
  132. package/dist/chunk-Y5QGVTVC.js +33 -0
  133. package/dist/chunk-YAA6IID3.js +548 -0
  134. package/dist/chunk-YGJTDXVR.js +692 -0
  135. package/{src/utils/time-ticks.ts → dist/chunk-YRYKTYMQ.js} +45 -112
  136. package/dist/chunk-YYVTBZZC.js +61 -0
  137. package/dist/chunk-Z5CGSFJB.js +647 -0
  138. package/{src/gantt/calculator.ts → dist/chunk-Z72XRXD4.js} +236 -428
  139. package/dist/chunk-ZGR7ULFJ.js +978 -0
  140. package/dist/chunk-ZJEL4H2R.js +851 -0
  141. package/dist/chunk-ZO27FGJS.js +554 -0
  142. package/dist/collapse-CLPJD2RL.js +11 -0
  143. package/dist/collapse-SLINJQW6.js +9 -0
  144. package/dist/collapse-ZWUFFCK2.js +9 -0
  145. package/dist/compute-G55RG53N.js +8 -0
  146. package/dist/dgmo-router-DZCIDUO5.js +73 -0
  147. package/dist/dimensions-J3FHIMJ6.js +22 -0
  148. package/dist/element.js +1 -1
  149. package/dist/element.mjs +1 -1
  150. package/dist/flowchart-parser-ZNSKIBVR.js +21 -0
  151. package/dist/flowchart-renderer-ZAEOL4DX.js +35 -0
  152. package/dist/index.d.ts +3 -469
  153. package/dist/index.js +137 -69685
  154. package/dist/layout-46N4JJYK.js +17 -0
  155. package/dist/layout-5RA6QWR6.js +26 -0
  156. package/dist/layout-5T6RH5M6.js +14 -0
  157. package/dist/layout-7QXCNOVS.js +13 -0
  158. package/dist/layout-EE6GE46Y.js +17 -0
  159. package/dist/layout-G23F7LDH.js +9 -0
  160. package/dist/layout-HRBZPFCN.js +23 -0
  161. package/dist/layout-HWDSRX5E.js +20 -0
  162. package/dist/layout-HYZPWAK5.js +18 -0
  163. package/dist/layout-N76NR4ZO.js +19 -0
  164. package/dist/layout-OB3RI63S.js +14 -0
  165. package/dist/layout-S2QBYSK2.js +15 -0
  166. package/dist/layout-UM5F4DJB.js +15 -0
  167. package/dist/layout-search-OYV77HHS.js +1655 -0
  168. package/dist/load-data-EHDDZ5ZS.js +8 -0
  169. package/dist/palettes-PRJ2RI6D.js +56 -0
  170. package/dist/parser-2MFP2H2E.js +11 -0
  171. package/dist/parser-3STE62GB.js +21 -0
  172. package/dist/parser-4FL2CMDG.js +18 -0
  173. package/dist/parser-4OGOBJJ4.js +13 -0
  174. package/dist/parser-6BTRLKRZ.js +15 -0
  175. package/dist/parser-AQETEVRW.js +21 -0
  176. package/dist/parser-CFZD5IBL.js +12 -0
  177. package/dist/parser-FUSKFGZN.js +16 -0
  178. package/dist/parser-I6KXEYFK.js +13 -0
  179. package/dist/parser-IXSZZQHY.js +18 -0
  180. package/dist/parser-JAL2HD4I.js +13 -0
  181. package/dist/parser-KNSQSKQO.js +20 -0
  182. package/dist/parser-N5O4IHUN.js +13 -0
  183. package/dist/parser-NGU3ETO6.js +16 -0
  184. package/dist/parser-NRAI6O25.js +19 -0
  185. package/dist/parser-O5J4VBII.js +11 -0
  186. package/dist/parser-OV7NOBW6.js +21 -0
  187. package/dist/parser-PQ3POX45.js +23 -0
  188. package/dist/parser-TFZFBVWN.js +11 -0
  189. package/dist/parser-TRTHDFPP.js +18 -0
  190. package/dist/parser-VQP2UJ6W.js +11 -0
  191. package/dist/parser-XDVELHRK.js +13 -0
  192. package/dist/parser-XKRP7QKP.js +11 -0
  193. package/dist/parser-Y6WTBU76.js +14 -0
  194. package/dist/parser-ZSDPZYQP.js +12 -0
  195. package/dist/renderer-2XQQQ6QR.js +28 -0
  196. package/dist/renderer-5NDVNDAZ.js +26 -0
  197. package/dist/renderer-6EEZHMH4.js +26 -0
  198. package/dist/renderer-6W5462RB.js +43 -0
  199. package/dist/renderer-7MVLWWQD.js +22 -0
  200. package/dist/renderer-AWWAF6XD.js +33 -0
  201. package/dist/renderer-BYCNMBF7.js +34 -0
  202. package/dist/renderer-CLJHQPBJ.js +29 -0
  203. package/dist/renderer-GHPZMFU2.js +15 -0
  204. package/dist/renderer-JGBKUCZD.js +16 -0
  205. package/dist/renderer-KQB7UGDS.js +19 -0
  206. package/dist/renderer-PGX2TKVS.js +24 -0
  207. package/dist/renderer-QIWVHWZO.js +15 -0
  208. package/dist/renderer-RPOA5YPZ.js +35 -0
  209. package/dist/renderer-SMIBCRVB.js +24 -0
  210. package/dist/renderer-T7YKC5VP.js +28 -0
  211. package/dist/renderer-TOCOVLHS.js +37 -0
  212. package/dist/renderer-UWA5XS74.js +39 -0
  213. package/dist/renderer-VACVQYML.js +25 -0
  214. package/dist/renderer-W4M6QLIJ.js +37 -0
  215. package/dist/renderer-WZRREQ2P.js +23 -0
  216. package/dist/renderer-YY2OSF6E.js +27 -0
  217. package/dist/renderer-Z7I3W2PP.js +24 -0
  218. package/dist/renderer-ZGNTUWC4.js +22 -0
  219. package/dist/renderer-ZTR3DER3.js +19 -0
  220. package/dist/renderer-radial-C32GPJQ7.js +21 -0
  221. package/dist/resolver-NOAA7ID7.js +13 -0
  222. package/dist/state-collapse-HCGD6IVJ.js +8 -0
  223. package/dist/state-parser-Z2V23ATR.js +18 -0
  224. package/dist/state-renderer-RFYHSP4K.js +34 -0
  225. package/dist/themes-1-CuKpeH.d.ts +908 -0
  226. package/package.json +19 -70
  227. package/dist/advanced.cjs +0 -71648
  228. package/dist/advanced.d.cts +0 -6571
  229. package/dist/auto.cjs +0 -70648
  230. package/dist/auto.d.cts +0 -54
  231. package/dist/block.cjs +0 -70208
  232. package/dist/block.d.cts +0 -115
  233. package/dist/editor.d.cts +0 -26
  234. package/dist/element.cjs +0 -70530
  235. package/dist/element.d.cts +0 -62
  236. package/dist/highlight.cjs +0 -852
  237. package/dist/highlight.d.cts +0 -49
  238. package/dist/index.cjs +0 -70491
  239. package/dist/index.d.cts +0 -626
  240. package/dist/pert.cjs +0 -325
  241. package/dist/pert.d.cts +0 -559
  242. package/src/advanced.ts +0 -873
  243. package/src/arc/parser.ts +0 -15
  244. package/src/arc/renderer.ts +0 -633
  245. package/src/auto/index.ts +0 -621
  246. package/src/auto/shared.ts +0 -370
  247. package/src/auto/styles.ts +0 -73
  248. package/src/block/layout.ts +0 -198
  249. package/src/block/renderer.ts +0 -484
  250. package/src/block/types.ts +0 -67
  251. package/src/boxes-and-lines/collapse.ts +0 -96
  252. package/src/boxes-and-lines/focus.ts +0 -257
  253. package/src/boxes-and-lines/label-placement.ts +0 -339
  254. package/src/boxes-and-lines/layout-grouped.ts +0 -912
  255. package/src/boxes-and-lines/layout-layered.ts +0 -722
  256. package/src/boxes-and-lines/layout-search.ts +0 -1678
  257. package/src/boxes-and-lines/layout.ts +0 -398
  258. package/src/boxes-and-lines/parser.ts +0 -1181
  259. package/src/boxes-and-lines/renderer.ts +0 -1465
  260. package/src/boxes-and-lines/types.ts +0 -66
  261. package/src/c4/parser.ts +0 -1158
  262. package/src/c4/renderer.ts +0 -2008
  263. package/src/c4/types.ts +0 -89
  264. package/src/chart-type-registry.ts +0 -529
  265. package/src/chart-types.ts +0 -225
  266. package/src/chart.ts +0 -685
  267. package/src/charts-d3/bar.ts +0 -338
  268. package/src/charts-d3/chord.ts +0 -140
  269. package/src/charts-d3/function.ts +0 -147
  270. package/src/charts-d3/funnel.ts +0 -104
  271. package/src/charts-d3/heatmap.ts +0 -145
  272. package/src/charts-d3/index.ts +0 -337
  273. package/src/charts-d3/interactions.ts +0 -477
  274. package/src/charts-d3/line.ts +0 -344
  275. package/src/charts-d3/mount.ts +0 -151
  276. package/src/charts-d3/pie.ts +0 -117
  277. package/src/charts-d3/polar.ts +0 -89
  278. package/src/charts-d3/radar.ts +0 -0
  279. package/src/charts-d3/sankey.ts +0 -0
  280. package/src/charts-d3/scatter.ts +0 -185
  281. package/src/charts-d3/shared.ts +0 -208
  282. package/src/class/layout.ts +0 -326
  283. package/src/class/parser.ts +0 -635
  284. package/src/class/renderer.ts +0 -793
  285. package/src/class/types.ts +0 -58
  286. package/src/cli-banner.ts +0 -106
  287. package/src/cli.ts +0 -1080
  288. package/src/colors-diagnostics.ts +0 -35
  289. package/src/colors.ts +0 -379
  290. package/src/completion-types.ts +0 -27
  291. package/src/completion.ts +0 -2668
  292. package/src/cycle/layout.ts +0 -1026
  293. package/src/cycle/parser.ts +0 -387
  294. package/src/cycle/renderer.ts +0 -653
  295. package/src/cycle/types.ts +0 -101
  296. package/src/d3.ts +0 -1434
  297. package/src/data-chart-parser.ts +0 -1007
  298. package/src/dgmo-router.ts +0 -296
  299. package/src/diagnostics-registry.ts +0 -108
  300. package/src/diagnostics.ts +0 -0
  301. package/src/dimensions.ts +0 -20
  302. package/src/directives-registry.ts +0 -396
  303. package/src/editor/dgmo.grammar +0 -76
  304. package/src/editor/dgmo.grammar.d.ts +0 -2
  305. package/src/editor/dgmo.grammar.js +0 -18
  306. package/src/editor/dgmo.grammar.terms.d.ts +0 -5
  307. package/src/editor/dgmo.grammar.terms.js +0 -35
  308. package/src/editor/highlight-api.ts +0 -596
  309. package/src/editor/highlight.ts +0 -36
  310. package/src/editor/index.ts +0 -27
  311. package/src/editor/keywords.ts +0 -128
  312. package/src/editor/tokens.ts +0 -30
  313. package/src/element/index.ts +0 -432
  314. package/src/embed/css.ts +0 -312
  315. package/src/embed/escape.ts +0 -15
  316. package/src/embed/index.ts +0 -280
  317. package/src/er/classify.ts +0 -228
  318. package/src/er/layout.ts +0 -530
  319. package/src/er/parser.ts +0 -750
  320. package/src/er/renderer.ts +0 -725
  321. package/src/er/types.ts +0 -52
  322. package/src/error-card.ts +0 -269
  323. package/src/event-line/diagnostics.ts +0 -117
  324. package/src/event-line/parser.ts +0 -643
  325. package/src/event-line/renderer.ts +0 -1742
  326. package/src/event-line/types.ts +0 -74
  327. package/src/fonts.ts +0 -3
  328. package/src/gantt/parser.ts +0 -1641
  329. package/src/gantt/renderer.ts +0 -3787
  330. package/src/gantt/resolver.ts +0 -172
  331. package/src/gantt/types.ts +0 -206
  332. package/src/graph/diagnostics.ts +0 -64
  333. package/src/graph/edge-spline.ts +0 -29
  334. package/src/graph/flowchart-parser.ts +0 -759
  335. package/src/graph/flowchart-renderer.ts +0 -817
  336. package/src/graph/layout.ts +0 -472
  337. package/src/graph/notes.ts +0 -21
  338. package/src/graph/state-collapse.ts +0 -78
  339. package/src/graph/state-parser.ts +0 -574
  340. package/src/graph/state-renderer.ts +0 -653
  341. package/src/graph/types.ts +0 -65
  342. package/src/index.ts +0 -261
  343. package/src/infra/compute.ts +0 -1385
  344. package/src/infra/layout.ts +0 -888
  345. package/src/infra/parser.ts +0 -1234
  346. package/src/infra/renderer.ts +0 -2534
  347. package/src/infra/roles.ts +0 -75
  348. package/src/infra/types.ts +0 -216
  349. package/src/infra/validation.ts +0 -201
  350. package/src/journey-map/layout.ts +0 -490
  351. package/src/journey-map/parser.ts +0 -557
  352. package/src/journey-map/renderer.ts +0 -1580
  353. package/src/journey-map/types.ts +0 -47
  354. package/src/kanban/mutations.ts +0 -175
  355. package/src/kanban/parser.ts +0 -509
  356. package/src/kanban/renderer.ts +0 -1449
  357. package/src/kanban/types.ts +0 -39
  358. package/src/label-layout.ts +0 -368
  359. package/src/map/colorize.ts +0 -54
  360. package/src/map/completion.ts +0 -316
  361. package/src/map/context-labels.ts +0 -609
  362. package/src/map/data/PROVENANCE.json +0 -1
  363. package/src/map/data/README.md +0 -40
  364. package/src/map/data/airport-collisions.json +0 -1
  365. package/src/map/data/airports.json +0 -1
  366. package/src/map/data/gazetteer.json +0 -1
  367. package/src/map/data/lakes.json +0 -1
  368. package/src/map/data/mountain-ranges.json +0 -1
  369. package/src/map/data/na-lakes.json +0 -1
  370. package/src/map/data/na-land.json +0 -1
  371. package/src/map/data/region-names.json +0 -1
  372. package/src/map/data/rivers.json +0 -1
  373. package/src/map/data/types.ts +0 -121
  374. package/src/map/data/us-states.json +0 -1
  375. package/src/map/data/water-bodies.json +0 -1
  376. package/src/map/data/world-coarse.json +0 -1
  377. package/src/map/data/world-detail.json +0 -1
  378. package/src/map/diagnostics.ts +0 -134
  379. package/src/map/dimensions.ts +0 -150
  380. package/src/map/geo-query.ts +0 -295
  381. package/src/map/geo.ts +0 -438
  382. package/src/map/invert.ts +0 -111
  383. package/src/map/layout.ts +0 -5069
  384. package/src/map/legend-band.ts +0 -127
  385. package/src/map/load-data.ts +0 -186
  386. package/src/map/parser.ts +0 -783
  387. package/src/map/renderer.ts +0 -1445
  388. package/src/map/resolved-types.ts +0 -160
  389. package/src/map/resolver.ts +0 -1146
  390. package/src/map/types.ts +0 -194
  391. package/src/mindmap/collapse.ts +0 -67
  392. package/src/mindmap/layout.ts +0 -649
  393. package/src/mindmap/parser.ts +0 -430
  394. package/src/mindmap/renderer.ts +0 -637
  395. package/src/mindmap/text-wrap.ts +0 -218
  396. package/src/mindmap/types.ts +0 -56
  397. package/src/org/collapse.ts +0 -151
  398. package/src/org/layout.ts +0 -1262
  399. package/src/org/parser.ts +0 -519
  400. package/src/org/renderer.ts +0 -866
  401. package/src/org/resolver.ts +0 -636
  402. package/src/palettes/atlas.ts +0 -77
  403. package/src/palettes/blueprint.ts +0 -73
  404. package/src/palettes/catppuccin.ts +0 -84
  405. package/src/palettes/color-utils.ts +0 -443
  406. package/src/palettes/index.ts +0 -67
  407. package/src/palettes/nord.ts +0 -67
  408. package/src/palettes/registry.ts +0 -114
  409. package/src/palettes/slate.ts +0 -73
  410. package/src/palettes/tidewater.ts +0 -73
  411. package/src/palettes/tokyo-night.ts +0 -86
  412. package/src/palettes/types.ts +0 -88
  413. package/src/pert/analyzer.ts +0 -1183
  414. package/src/pert/diagnostics.ts +0 -110
  415. package/src/pert/index.ts +0 -43
  416. package/src/pert/internal.ts +0 -252
  417. package/src/pert/layout.ts +0 -971
  418. package/src/pert/monte-carlo.ts +0 -446
  419. package/src/pert/parser.ts +0 -1606
  420. package/src/pert/renderer.ts +0 -4009
  421. package/src/pert/share-normalize.ts +0 -62
  422. package/src/pert/types.ts +0 -604
  423. package/src/pyramid/parser.ts +0 -185
  424. package/src/pyramid/renderer.ts +0 -768
  425. package/src/pyramid/types.ts +0 -28
  426. package/src/quadrant/parser.ts +0 -18
  427. package/src/quadrant/renderer.ts +0 -638
  428. package/src/raci/diagnostics.ts +0 -213
  429. package/src/raci/index.ts +0 -23
  430. package/src/raci/mutations.ts +0 -321
  431. package/src/raci/parser.ts +0 -699
  432. package/src/raci/renderer.ts +0 -1627
  433. package/src/raci/types.ts +0 -82
  434. package/src/raci/variants.ts +0 -320
  435. package/src/render.ts +0 -268
  436. package/src/ring/parser.ts +0 -212
  437. package/src/ring/renderer.ts +0 -490
  438. package/src/ring/types.ts +0 -27
  439. package/src/sequence/collapse.ts +0 -174
  440. package/src/sequence/parser.ts +0 -1596
  441. package/src/sequence/participant-inference.ts +0 -152
  442. package/src/sequence/renderer.ts +0 -3168
  443. package/src/sequence/tag-resolution.ts +0 -164
  444. package/src/sharing.ts +0 -211
  445. package/src/sitemap/collapse.ts +0 -100
  446. package/src/sitemap/layout.ts +0 -925
  447. package/src/sitemap/parser.ts +0 -755
  448. package/src/sitemap/renderer.ts +0 -828
  449. package/src/sitemap/types.ts +0 -42
  450. package/src/slope/parser.ts +0 -18
  451. package/src/slope/renderer.ts +0 -378
  452. package/src/swimlane/diagnostics.ts +0 -94
  453. package/src/swimlane/layout.ts +0 -597
  454. package/src/swimlane/parser.ts +0 -613
  455. package/src/swimlane/renderer.ts +0 -681
  456. package/src/swimlane/types.ts +0 -151
  457. package/src/tech-radar/interactive.ts +0 -1129
  458. package/src/tech-radar/layout.ts +0 -197
  459. package/src/tech-radar/parser.ts +0 -436
  460. package/src/tech-radar/renderer.ts +0 -1239
  461. package/src/tech-radar/shared.ts +0 -151
  462. package/src/tech-radar/types.ts +0 -86
  463. package/src/themes.ts +0 -22
  464. package/src/timeline/parser.ts +0 -472
  465. package/src/timeline/renderer.ts +0 -3024
  466. package/src/timeline/types.ts +0 -33
  467. package/src/timeline/viz-parser.ts +0 -21
  468. package/src/treemap/diagnostics.ts +0 -62
  469. package/src/treemap/layout-radial.ts +0 -233
  470. package/src/treemap/layout.ts +0 -189
  471. package/src/treemap/parser.ts +0 -463
  472. package/src/treemap/renderer-radial.ts +0 -438
  473. package/src/treemap/renderer.ts +0 -572
  474. package/src/treemap/treemap-shared.ts +0 -309
  475. package/src/treemap/types.ts +0 -60
  476. package/src/utils/arrow-markers.ts +0 -51
  477. package/src/utils/arrows-diagnostics.ts +0 -62
  478. package/src/utils/arrows.ts +0 -227
  479. package/src/utils/brand.ts +0 -61
  480. package/src/utils/card.ts +0 -183
  481. package/src/utils/collapse-engine/tree-edges.ts +0 -115
  482. package/src/utils/collapse-engine/tree.ts +0 -117
  483. package/src/utils/d3-helpers.ts +0 -219
  484. package/src/utils/d3-types.ts +0 -9
  485. package/src/utils/description-helpers.ts +0 -38
  486. package/src/utils/duration.ts +0 -312
  487. package/src/utils/export-container.ts +0 -41
  488. package/src/utils/expr-eval.ts +0 -27
  489. package/src/utils/fit-canvas.ts +0 -64
  490. package/src/utils/hover-styles.ts +0 -673
  491. package/src/utils/inline-markdown.ts +0 -96
  492. package/src/utils/legend-constants.ts +0 -48
  493. package/src/utils/legend-d3.ts +0 -618
  494. package/src/utils/legend-integration.ts +0 -107
  495. package/src/utils/legend-layout.ts +0 -776
  496. package/src/utils/legend-svg.ts +0 -214
  497. package/src/utils/legend-types.ts +0 -272
  498. package/src/utils/name-normalize.ts +0 -163
  499. package/src/utils/note-box/constants.ts +0 -25
  500. package/src/utils/note-box/index.ts +0 -11
  501. package/src/utils/note-box/metrics.ts +0 -90
  502. package/src/utils/note-box/svg.ts +0 -331
  503. package/src/utils/notes/bounds.ts +0 -30
  504. package/src/utils/notes/build.ts +0 -131
  505. package/src/utils/notes/index.ts +0 -18
  506. package/src/utils/notes/model.ts +0 -19
  507. package/src/utils/notes/parse.ts +0 -131
  508. package/src/utils/notes/place.ts +0 -177
  509. package/src/utils/notes/resolve.ts +0 -88
  510. package/src/utils/number-format.ts +0 -36
  511. package/src/utils/parsing.ts +0 -953
  512. package/src/utils/reserved-key-registry.ts +0 -239
  513. package/src/utils/safe-href.ts +0 -38
  514. package/src/utils/scaling.ts +0 -97
  515. package/src/utils/svg-embed.ts +0 -251
  516. package/src/utils/tag-groups.ts +0 -607
  517. package/src/utils/text-measure.ts +0 -122
  518. package/src/utils/title-constants.ts +0 -24
  519. package/src/utils/visual-conventions.ts +0 -61
  520. package/src/utils/wrapped-desc.ts +0 -87
  521. package/src/venn/parser.ts +0 -18
  522. package/src/venn/renderer.ts +0 -1047
  523. package/src/version-control/diagnostics.ts +0 -67
  524. package/src/version-control/parser.ts +0 -544
  525. package/src/version-control/renderer.ts +0 -724
  526. package/src/version-control/types.ts +0 -100
  527. package/src/visualizations/parse.ts +0 -1560
  528. package/src/visualizations/types.ts +0 -262
  529. package/src/wireframe/layout.ts +0 -479
  530. package/src/wireframe/parser.ts +0 -1114
  531. package/src/wireframe/renderer.ts +0 -1318
  532. package/src/wireframe/types.ts +0 -110
  533. package/src/wordcloud/parser.ts +0 -18
  534. package/src/wordcloud/renderer.ts +0 -357
@@ -0,0 +1,1851 @@
1
+ import {
2
+ renderInlineText
3
+ } from "./chunk-3HDBAXF5.js";
4
+ import {
5
+ wrapDescriptionLines
6
+ } from "./chunk-BMR4CIEO.js";
7
+ import {
8
+ renderIntegratedLegend
9
+ } from "./chunk-PWIHZ6NJ.js";
10
+ import {
11
+ ScaleContext
12
+ } from "./chunk-YYVTBZZC.js";
13
+ import {
14
+ getMaxLegendReservedHeight
15
+ } from "./chunk-YAA6IID3.js";
16
+ import {
17
+ TITLE_FONT_SIZE,
18
+ TITLE_FONT_WEIGHT,
19
+ TITLE_Y
20
+ } from "./chunk-A4GOY3PE.js";
21
+ import {
22
+ FONT_FAMILY
23
+ } from "./chunk-6KFWC4CO.js";
24
+ import {
25
+ measureText,
26
+ truncateText
27
+ } from "./chunk-WCT3NYCV.js";
28
+ import {
29
+ contrastText,
30
+ mix,
31
+ shapeFill,
32
+ themeBaseBg
33
+ } from "./chunk-P6T66CCZ.js";
34
+ import {
35
+ isSequenceBlock,
36
+ isSequenceNote,
37
+ isSequenceSection
38
+ } from "./chunk-SML67VPV.js";
39
+ import {
40
+ resolveActiveTagGroup,
41
+ tagAttrKey
42
+ } from "./chunk-QLCCJEJI.js";
43
+
44
+ // src/sequence/renderer.ts
45
+ import * as d3Selection from "d3-selection";
46
+
47
+ // src/sequence/collapse.ts
48
+ function applyCollapseProjection(parsed, collapsedGroups) {
49
+ if (collapsedGroups.size === 0) {
50
+ return {
51
+ participants: parsed.participants,
52
+ messages: parsed.messages,
53
+ elements: parsed.elements,
54
+ groups: parsed.groups,
55
+ collapsedGroupIds: /* @__PURE__ */ new Map()
56
+ };
57
+ }
58
+ const memberToGroup = /* @__PURE__ */ new Map();
59
+ const collapsedGroupNames = /* @__PURE__ */ new Set();
60
+ for (const group of parsed.groups) {
61
+ if (collapsedGroups.has(group.lineNumber)) {
62
+ collapsedGroupNames.add(group.name);
63
+ for (const memberId of group.participantIds) {
64
+ memberToGroup.set(memberId, group.name);
65
+ }
66
+ }
67
+ }
68
+ const participants = [];
69
+ const insertedGroups = /* @__PURE__ */ new Set();
70
+ for (const p of parsed.participants) {
71
+ const groupName = memberToGroup.get(p.id);
72
+ if (groupName) {
73
+ if (!insertedGroups.has(groupName)) {
74
+ insertedGroups.add(groupName);
75
+ const group = parsed.groups.find(
76
+ (g) => g.name === groupName && collapsedGroups.has(g.lineNumber)
77
+ );
78
+ participants.push({
79
+ id: groupName,
80
+ // already ParticipantId from memberToGroup value type
81
+ label: groupName,
82
+ type: "default",
83
+ lineNumber: group.lineNumber
84
+ });
85
+ }
86
+ } else if (collapsedGroupNames.has(p.id)) {
87
+ } else {
88
+ participants.push(p);
89
+ }
90
+ }
91
+ const remap = (id) => memberToGroup.get(id) ?? id;
92
+ const messages = parsed.messages.map((msg) => ({
93
+ ...msg,
94
+ from: remap(msg.from),
95
+ to: remap(msg.to)
96
+ }));
97
+ const elements = remapElements(parsed.elements, memberToGroup);
98
+ const groups = parsed.groups.filter(
99
+ (g) => !collapsedGroups.has(g.lineNumber)
100
+ );
101
+ return {
102
+ participants,
103
+ messages,
104
+ elements,
105
+ groups,
106
+ collapsedGroupIds: memberToGroup
107
+ };
108
+ }
109
+ function remapElements(elements, memberToGroup) {
110
+ const remap = (id) => memberToGroup.get(id) ?? id;
111
+ const result = [];
112
+ for (const el of elements) {
113
+ if (isSequenceSection(el)) {
114
+ result.push(el);
115
+ } else if (isSequenceNote(el)) {
116
+ result.push({
117
+ ...el,
118
+ participantId: remap(el.participantId)
119
+ });
120
+ } else if (isSequenceBlock(el)) {
121
+ result.push({
122
+ ...el,
123
+ children: remapElements(el.children, memberToGroup),
124
+ elseChildren: remapElements(el.elseChildren, memberToGroup),
125
+ ...el.elseIfBranches ? {
126
+ elseIfBranches: el.elseIfBranches.map((branch) => ({
127
+ ...branch,
128
+ children: remapElements(branch.children, memberToGroup)
129
+ }))
130
+ } : {}
131
+ });
132
+ } else {
133
+ const msg = el;
134
+ const from = remap(msg.from);
135
+ const to = remap(msg.to);
136
+ if (from === to && from !== msg.from && !msg.label) {
137
+ continue;
138
+ }
139
+ result.push({ ...msg, from, to });
140
+ }
141
+ }
142
+ return result;
143
+ }
144
+
145
+ // src/sequence/tag-resolution.ts
146
+ function propagateGroupTags(participantMeta, groups) {
147
+ for (const group of groups) {
148
+ if (!group.metadata) continue;
149
+ for (const id of group.participantIds) {
150
+ const meta = participantMeta.get(id);
151
+ if (!meta) continue;
152
+ for (const [key, value] of Object.entries(group.metadata)) {
153
+ if (!(key in meta)) {
154
+ meta[key] = value;
155
+ }
156
+ }
157
+ }
158
+ }
159
+ }
160
+ function computeReceiverInheritance(participants, messages, groupKey, participantMeta) {
161
+ const inheritance = /* @__PURE__ */ new Map();
162
+ for (const p of participants) {
163
+ const meta = participantMeta.get(p.id);
164
+ if (meta?.[groupKey]) continue;
165
+ const incomingValues = /* @__PURE__ */ new Set();
166
+ for (const msg of messages) {
167
+ if (msg.to === p.id && msg.metadata?.[groupKey]) {
168
+ incomingValues.add(msg.metadata[groupKey]);
169
+ }
170
+ }
171
+ if (incomingValues.size === 1) {
172
+ inheritance.set(p.id, [...incomingValues][0]);
173
+ }
174
+ }
175
+ return inheritance;
176
+ }
177
+ function resolveSequenceTags(parsed, activeTagGroup) {
178
+ const result = {
179
+ participants: /* @__PURE__ */ new Map(),
180
+ messages: /* @__PURE__ */ new Map()
181
+ };
182
+ const group = parsed.tagGroups.find(
183
+ (g) => g.name.toLowerCase() === activeTagGroup.toLowerCase()
184
+ );
185
+ if (!group) {
186
+ for (const p of parsed.participants) {
187
+ result.participants.set(p.id, void 0);
188
+ }
189
+ for (const m of parsed.messages) {
190
+ result.messages.set(m.lineNumber, void 0);
191
+ }
192
+ return result;
193
+ }
194
+ const groupKey = tagAttrKey(group.name);
195
+ const participantMeta = /* @__PURE__ */ new Map();
196
+ for (const p of parsed.participants) {
197
+ participantMeta.set(p.id, { ...p.metadata || {} });
198
+ }
199
+ propagateGroupTags(participantMeta, parsed.groups);
200
+ const inherited = computeReceiverInheritance(
201
+ parsed.participants,
202
+ parsed.messages,
203
+ groupKey,
204
+ participantMeta
205
+ );
206
+ for (const [id, value] of inherited) {
207
+ const meta = participantMeta.get(id);
208
+ meta[groupKey] = value;
209
+ }
210
+ if (group.defaultValue) {
211
+ for (const p of parsed.participants) {
212
+ const meta = participantMeta.get(p.id);
213
+ if (!(groupKey in meta)) {
214
+ meta[groupKey] = group.defaultValue;
215
+ }
216
+ }
217
+ }
218
+ for (const p of parsed.participants) {
219
+ const meta = participantMeta.get(p.id);
220
+ result.participants.set(p.id, meta[groupKey] || void 0);
221
+ }
222
+ for (const msg of parsed.messages) {
223
+ result.messages.set(msg.lineNumber, msg.metadata?.[groupKey] || void 0);
224
+ }
225
+ return result;
226
+ }
227
+
228
+ // src/sequence/renderer.ts
229
+ var PARTICIPANT_GAP = 160;
230
+ var PARTICIPANT_BOX_WIDTH = 120;
231
+ var PARTICIPANT_BOX_HEIGHT = 50;
232
+ var LABEL_FONT_SIZE = 13;
233
+ var TOP_MARGIN = 20;
234
+ var TITLE_HEIGHT = 30;
235
+ var PARTICIPANT_Y_OFFSET = 10;
236
+ var MESSAGE_START_OFFSET = 50;
237
+ var LIFELINE_TAIL = 30;
238
+ var ARROWHEAD_SIZE = 8;
239
+ var NOTE_MAX_W = 200;
240
+ var NOTE_FOLD = 10;
241
+ var NOTE_PAD_H = 8;
242
+ var NOTE_PAD_V = 6;
243
+ var NOTE_FONT_SIZE = 10;
244
+ var NOTE_LINE_H = 14;
245
+ var NOTE_GAP = 15;
246
+ var ACTIVATION_WIDTH = 10;
247
+ var SELF_CALL_HEIGHT = 25;
248
+ var SELF_CALL_WIDTH = 30;
249
+ var ACTOR_LABEL_CLEARANCE = 22;
250
+ function wrapTextLines(text, maxWidth, fontSize) {
251
+ const rawLines = text.split("\n").map((l) => l.startsWith("- ") ? "\u2022 " + l.slice(2) : l);
252
+ return wrapDescriptionLines(
253
+ rawLines,
254
+ maxWidth,
255
+ (s) => measureText(s, fontSize)
256
+ );
257
+ }
258
+ var labelTextWidth = (boxW) => boxW - 10;
259
+ function splitParticipantLabel(label, maxWidth, fontSize) {
260
+ if (measureText(label, fontSize) <= maxWidth) return [label];
261
+ if (label.includes(" ")) {
262
+ return wrapLabelWords(label.split(" "), maxWidth, fontSize);
263
+ }
264
+ if (/[-_:/]/.test(label)) {
265
+ const parts = label.split(/[-_:/]+/);
266
+ return wrapLabelWords(parts, maxWidth, fontSize);
267
+ }
268
+ const camelParts = label.replace(/([a-z])([A-Z])/g, "$1\0$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1\0$2").split("\0");
269
+ if (camelParts.length > 1) {
270
+ return wrapLabelWords(camelParts, maxWidth, fontSize);
271
+ }
272
+ return [label];
273
+ }
274
+ function wrapLabelWords(words, maxWidth, fontSize) {
275
+ const lines = [];
276
+ let current = "";
277
+ for (const word of words) {
278
+ const test = current ? current + word : word;
279
+ if (measureText(test, fontSize) > maxWidth && current) {
280
+ lines.push(current);
281
+ current = word;
282
+ } else {
283
+ current = test;
284
+ }
285
+ }
286
+ if (current) lines.push(current);
287
+ return lines;
288
+ }
289
+ var fill = (palette, isDark, color, solid) => color ? shapeFill(palette, color, isDark, {
290
+ ...solid !== void 0 && { solid }
291
+ }) : isDark ? mix(palette.overlay, palette.surface, 50) : mix(palette.bg, palette.surface, 50);
292
+ var stroke = (palette, color) => color || palette.border;
293
+ var SW = 1.5;
294
+ var W = PARTICIPANT_BOX_WIDTH;
295
+ var H = PARTICIPANT_BOX_HEIGHT;
296
+ function renderRectParticipant(g, palette, isDark, color, solid, w = W, h = H) {
297
+ g.append("rect").attr("x", -w / 2).attr("y", 0).attr("width", w).attr("height", h).attr("rx", 2).attr("ry", 2).attr("fill", fill(palette, isDark, color, solid)).attr("stroke", stroke(palette, color)).attr("stroke-width", SW);
298
+ }
299
+ function renderActorParticipant(g, palette, color, h = H) {
300
+ const sc = h / H;
301
+ const headR = 8 * sc;
302
+ const cx = 0;
303
+ const headY = 10 * sc;
304
+ const bodyTopY = 19 * sc;
305
+ const bodyBottomY = h * 0.65;
306
+ const legY = h - 2 * sc;
307
+ const armY = 24 * sc;
308
+ const armSpan = 16 * sc;
309
+ const legSpan = 12 * sc;
310
+ const s = stroke(palette, color);
311
+ const actorSW = Math.max(1.2, 2.5 * sc);
312
+ g.append("circle").attr("cx", cx).attr("cy", headY).attr("r", headR).attr("fill", "none").attr("stroke", s).attr("stroke-width", actorSW);
313
+ g.append("line").attr("x1", cx).attr("y1", bodyTopY).attr("x2", cx).attr("y2", bodyBottomY).attr("stroke", s).attr("stroke-width", actorSW);
314
+ g.append("line").attr("x1", cx - armSpan).attr("y1", armY).attr("x2", cx + armSpan).attr("y2", armY).attr("stroke", s).attr("stroke-width", actorSW);
315
+ g.append("line").attr("x1", cx).attr("y1", bodyBottomY).attr("x2", cx - legSpan).attr("y2", legY).attr("stroke", s).attr("stroke-width", actorSW);
316
+ g.append("line").attr("x1", cx).attr("y1", bodyBottomY).attr("x2", cx + legSpan).attr("y2", legY).attr("stroke", s).attr("stroke-width", actorSW);
317
+ }
318
+ function renderDatabaseParticipant(g, palette, isDark, color, solid, w = W, h = H) {
319
+ const ry = 7;
320
+ const topY = ry;
321
+ const bodyH = h - ry * 2;
322
+ const f = fill(palette, isDark, color, solid);
323
+ const s = stroke(palette, color);
324
+ g.append("ellipse").attr("cx", 0).attr("cy", topY + bodyH).attr("rx", w / 2).attr("ry", ry).attr("fill", f).attr("stroke", s).attr("stroke-width", SW);
325
+ g.append("rect").attr("class", "participant-body").attr("x", -w / 2).attr("y", topY).attr("width", w).attr("height", bodyH).attr("fill", f).attr("stroke", "none");
326
+ g.append("line").attr("x1", -w / 2).attr("y1", topY).attr("x2", -w / 2).attr("y2", topY + bodyH).attr("stroke", s).attr("stroke-width", SW);
327
+ g.append("line").attr("x1", w / 2).attr("y1", topY).attr("x2", w / 2).attr("y2", topY + bodyH).attr("stroke", s).attr("stroke-width", SW);
328
+ g.append("ellipse").attr("cx", 0).attr("cy", topY).attr("rx", w / 2).attr("ry", ry).attr("fill", f).attr("stroke", s).attr("stroke-width", SW);
329
+ }
330
+ function renderQueueParticipant(g, palette, isDark, color, solid, w = W, h = H) {
331
+ const rx = 10;
332
+ const leftX = -w / 2 + rx;
333
+ const bodyW = w - rx * 2;
334
+ const f = fill(palette, isDark, color, solid);
335
+ const s = stroke(palette, color);
336
+ g.append("ellipse").attr("cx", leftX + bodyW).attr("cy", h / 2).attr("rx", rx).attr("ry", h / 2).attr("fill", f).attr("stroke", s).attr("stroke-width", SW);
337
+ g.append("rect").attr("class", "participant-body").attr("x", leftX).attr("y", 0).attr("width", bodyW).attr("height", h).attr("fill", f).attr("stroke", "none");
338
+ g.append("line").attr("x1", leftX).attr("y1", 0).attr("x2", leftX + bodyW).attr("y2", 0).attr("stroke", s).attr("stroke-width", SW);
339
+ g.append("line").attr("x1", leftX).attr("y1", h).attr("x2", leftX + bodyW).attr("y2", h).attr("stroke", s).attr("stroke-width", SW);
340
+ g.append("ellipse").attr("cx", leftX).attr("cy", h / 2).attr("rx", rx).attr("ry", h / 2).attr("fill", f).attr("stroke", s).attr("stroke-width", SW);
341
+ }
342
+ function renderCacheParticipant(g, palette, isDark, color, solid, w = W, h = H) {
343
+ const ry = 7;
344
+ const topY = ry;
345
+ const bodyH = h - ry * 2;
346
+ const f = fill(palette, isDark, color, solid);
347
+ const s = stroke(palette, color);
348
+ const dash = "4 3";
349
+ g.append("ellipse").attr("cx", 0).attr("cy", topY + bodyH).attr("rx", w / 2).attr("ry", ry).attr("fill", f).attr("stroke", s).attr("stroke-width", SW).attr("stroke-dasharray", dash);
350
+ g.append("rect").attr("class", "participant-body").attr("x", -w / 2).attr("y", topY).attr("width", w).attr("height", bodyH).attr("fill", f).attr("stroke", "none");
351
+ g.append("line").attr("x1", -w / 2).attr("y1", topY).attr("x2", -w / 2).attr("y2", topY + bodyH).attr("stroke", s).attr("stroke-width", SW).attr("stroke-dasharray", dash);
352
+ g.append("line").attr("x1", w / 2).attr("y1", topY).attr("x2", w / 2).attr("y2", topY + bodyH).attr("stroke", s).attr("stroke-width", SW).attr("stroke-dasharray", dash);
353
+ g.append("ellipse").attr("cx", 0).attr("cy", topY).attr("rx", w / 2).attr("ry", ry).attr("fill", f).attr("stroke", s).attr("stroke-width", SW).attr("stroke-dasharray", dash);
354
+ }
355
+ function groupMessagesBySection(elements, messages) {
356
+ const groups = [];
357
+ let currentGroup = null;
358
+ const msgLineToIdx = /* @__PURE__ */ new Map();
359
+ messages.forEach((m, i) => msgLineToIdx.set(m.lineNumber, i));
360
+ const collectIndices = (els) => {
361
+ const indices = [];
362
+ for (const el of els) {
363
+ if (isSequenceBlock(el)) {
364
+ indices.push(
365
+ ...collectIndices(el.children),
366
+ ...collectIndices(el.elseChildren)
367
+ );
368
+ if (el.elseIfBranches) {
369
+ for (const branch of el.elseIfBranches) {
370
+ indices.push(...collectIndices(branch.children));
371
+ }
372
+ }
373
+ } else if (isSequenceSection(el) || isSequenceNote(el)) {
374
+ continue;
375
+ } else {
376
+ const idx = msgLineToIdx.get(el.lineNumber) ?? -1;
377
+ if (idx >= 0) indices.push(idx);
378
+ }
379
+ }
380
+ return indices;
381
+ };
382
+ for (const el of elements) {
383
+ if (isSequenceSection(el)) {
384
+ currentGroup = { section: el, messageIndices: [] };
385
+ groups.push(currentGroup);
386
+ } else if (currentGroup) {
387
+ if (isSequenceBlock(el)) {
388
+ currentGroup.messageIndices.push(...collectIndices([el]));
389
+ } else if (!isSequenceNote(el)) {
390
+ const idx = msgLineToIdx.get(el.lineNumber) ?? -1;
391
+ if (idx >= 0) currentGroup.messageIndices.push(idx);
392
+ }
393
+ }
394
+ }
395
+ return groups;
396
+ }
397
+ function buildRenderSequence(messages) {
398
+ const steps = [];
399
+ const stack = [];
400
+ for (let mi = 0; mi < messages.length; mi++) {
401
+ const msg = messages[mi];
402
+ while (stack.length > 0) {
403
+ const top = stack[stack.length - 1];
404
+ if (top.to === msg.from) break;
405
+ stack.pop();
406
+ steps.push({
407
+ type: "return",
408
+ from: top.to,
409
+ to: top.from,
410
+ label: "",
411
+ messageIndex: top.messageIndex
412
+ });
413
+ }
414
+ if (stack.length > 0 && !msg.async && msg.from !== msg.to) {
415
+ const top = stack[stack.length - 1];
416
+ if (top.from === msg.to && top.to === msg.from) {
417
+ stack.pop();
418
+ steps.push({
419
+ type: "return",
420
+ from: msg.from,
421
+ to: msg.to,
422
+ label: msg.label,
423
+ messageIndex: mi
424
+ });
425
+ continue;
426
+ }
427
+ }
428
+ steps.push({
429
+ type: "call",
430
+ from: msg.from,
431
+ to: msg.to,
432
+ label: msg.label,
433
+ messageIndex: mi,
434
+ ...msg.async ? { async: true } : {}
435
+ });
436
+ if (msg.async) {
437
+ continue;
438
+ }
439
+ if (msg.from === msg.to) {
440
+ steps.push({
441
+ type: "return",
442
+ from: msg.to,
443
+ to: msg.from,
444
+ label: "",
445
+ messageIndex: mi
446
+ });
447
+ } else {
448
+ stack.push({
449
+ from: msg.from,
450
+ to: msg.to,
451
+ messageIndex: mi
452
+ });
453
+ }
454
+ }
455
+ while (stack.length > 0) {
456
+ const top = stack.pop();
457
+ steps.push({
458
+ type: "return",
459
+ from: top.to,
460
+ to: top.from,
461
+ label: "",
462
+ messageIndex: top.messageIndex
463
+ });
464
+ }
465
+ return steps;
466
+ }
467
+ function computeActivations(steps) {
468
+ const activations = [];
469
+ const stacks = /* @__PURE__ */ new Map();
470
+ const getStack = (id) => {
471
+ if (!stacks.has(id)) stacks.set(id, []);
472
+ return stacks.get(id);
473
+ };
474
+ for (let i = 0; i < steps.length; i++) {
475
+ const step = steps[i];
476
+ if (step.type === "call") {
477
+ const s = getStack(step.to);
478
+ s.push(i);
479
+ } else {
480
+ const s = getStack(step.from);
481
+ if (s.length > 0) {
482
+ const startIdx = s.pop();
483
+ activations.push({
484
+ participantId: step.from,
485
+ startStep: startIdx,
486
+ endStep: i,
487
+ depth: s.length
488
+ });
489
+ }
490
+ }
491
+ }
492
+ return activations;
493
+ }
494
+ function applyPositionOverrides(participants) {
495
+ if (!participants.some((p) => p.position !== void 0))
496
+ return [...participants];
497
+ const total = participants.length;
498
+ const positioned = [];
499
+ const unpositioned = [];
500
+ for (const p of participants) {
501
+ if (p.position !== void 0) {
502
+ let idx = p.position < 0 ? total + p.position : p.position;
503
+ idx = Math.max(0, Math.min(total - 1, idx));
504
+ positioned.push({ participant: p, index: idx });
505
+ } else {
506
+ unpositioned.push(p);
507
+ }
508
+ }
509
+ positioned.sort((a, b) => a.index - b.index);
510
+ const result = new Array(total).fill(null);
511
+ const usedIndices = /* @__PURE__ */ new Set();
512
+ for (const { participant, index } of positioned) {
513
+ let idx = index;
514
+ if (usedIndices.has(idx)) {
515
+ for (let offset = 1; offset < total; offset++) {
516
+ if (idx + offset < total && !usedIndices.has(idx + offset)) {
517
+ idx = idx + offset;
518
+ break;
519
+ }
520
+ if (idx - offset >= 0 && !usedIndices.has(idx - offset)) {
521
+ idx = idx - offset;
522
+ break;
523
+ }
524
+ }
525
+ }
526
+ result[idx] = participant;
527
+ usedIndices.add(idx);
528
+ }
529
+ let uIdx = 0;
530
+ for (let i = 0; i < total; i++) {
531
+ if (result[i] === null) {
532
+ result[i] = unpositioned[uIdx++];
533
+ }
534
+ }
535
+ return result;
536
+ }
537
+ function applyGroupOrdering(participants, groups, messages = []) {
538
+ if (groups.length === 0) return [...participants];
539
+ const idToGroup = /* @__PURE__ */ new Map();
540
+ for (const group of groups) {
541
+ for (const id of group.participantIds) {
542
+ idToGroup.set(id, group);
543
+ }
544
+ }
545
+ const appearanceOrder = [];
546
+ const seen = /* @__PURE__ */ new Set();
547
+ for (const msg of messages) {
548
+ for (const id of [msg.from, msg.to]) {
549
+ if (!seen.has(id)) {
550
+ seen.add(id);
551
+ appearanceOrder.push(id);
552
+ }
553
+ }
554
+ }
555
+ for (const p of participants) {
556
+ if (!seen.has(p.id)) {
557
+ seen.add(p.id);
558
+ appearanceOrder.push(p.id);
559
+ }
560
+ }
561
+ const result = [];
562
+ const placed = /* @__PURE__ */ new Set();
563
+ const placedGroups = /* @__PURE__ */ new Set();
564
+ for (const id of appearanceOrder) {
565
+ if (placed.has(id)) continue;
566
+ const group = idToGroup.get(id);
567
+ if (group && !placedGroups.has(group)) {
568
+ placedGroups.add(group);
569
+ for (const gid of group.participantIds) {
570
+ const p = participants.find((pp) => pp.id === gid);
571
+ if (p && !placed.has(gid)) {
572
+ result.push(p);
573
+ placed.add(gid);
574
+ }
575
+ }
576
+ } else if (!group) {
577
+ const p = participants.find((pp) => pp.id === id);
578
+ if (p) {
579
+ result.push(p);
580
+ placed.add(id);
581
+ }
582
+ }
583
+ }
584
+ return result;
585
+ }
586
+ function renderSequenceDiagram(container, parsed, palette, isDark, _onNavigateToLine, options) {
587
+ d3Selection.select(container).selectAll("*").remove();
588
+ const { title, options: parsedOptions } = parsed;
589
+ const solid = parsedOptions["solid-fill"] === "on";
590
+ const effectiveCollapsedGroups = options?.collapsedGroups ? new Set(options.collapsedGroups) : new Set(
591
+ parsed.groups.filter((g) => g.collapsed).map((g) => g.lineNumber)
592
+ );
593
+ const collapsed = effectiveCollapsedGroups.size > 0 ? applyCollapseProjection(parsed, effectiveCollapsedGroups) : null;
594
+ const messages = collapsed ? collapsed.messages : parsed.messages;
595
+ const elements = collapsed ? collapsed.elements : parsed.elements;
596
+ const groups = collapsed ? collapsed.groups : parsed.groups;
597
+ const collapsedSections = options?.collapsedSections;
598
+ const sourceParticipants = collapsed ? collapsed.participants : parsed.participants;
599
+ const participants = applyPositionOverrides(
600
+ applyGroupOrdering(sourceParticipants, groups, messages)
601
+ );
602
+ if (participants.length === 0) return;
603
+ const groupBoundaryIds = /* @__PURE__ */ new Set();
604
+ if (groups.length > 0) {
605
+ const pToG = /* @__PURE__ */ new Map();
606
+ for (let gi = 0; gi < groups.length; gi++) {
607
+ for (const pid of groups[gi].participantIds) pToG.set(pid, gi);
608
+ }
609
+ const LOOSE = -1;
610
+ for (let i = 1; i < participants.length; i++) {
611
+ const prevGi = pToG.get(participants[i - 1].id) ?? LOOSE;
612
+ const gi = pToG.get(participants[i].id) ?? LOOSE;
613
+ if (gi !== prevGi && !(gi === LOOSE && prevGi === LOOSE)) {
614
+ groupBoundaryIds.add(participants[i].id);
615
+ }
616
+ }
617
+ }
618
+ const numGroupGaps = groupBoundaryIds.size;
619
+ const MAX_BOX_WIDTH = 225;
620
+ let uniformBoxWidth = PARTICIPANT_BOX_WIDTH;
621
+ for (const p of participants) {
622
+ const lines = splitParticipantLabel(
623
+ p.label,
624
+ labelTextWidth(PARTICIPANT_BOX_WIDTH),
625
+ LABEL_FONT_SIZE
626
+ );
627
+ if (lines.length === 0) continue;
628
+ const widest = Math.max(
629
+ ...lines.map((l) => measureText(l, LABEL_FONT_SIZE))
630
+ );
631
+ const labelWidth = widest + 10;
632
+ uniformBoxWidth = Math.max(uniformBoxWidth, labelWidth);
633
+ }
634
+ uniformBoxWidth = Math.min(MAX_BOX_WIDTH, uniformBoxWidth);
635
+ const effectiveGap = Math.max(PARTICIPANT_GAP, uniformBoxWidth + 30);
636
+ const idealWidth = Math.max(
637
+ participants.length * effectiveGap,
638
+ uniformBoxWidth + 40
639
+ );
640
+ const containerWidth = options?.exportWidth ?? container.getBoundingClientRect().width;
641
+ const ctx = options?.exportWidth ? ScaleContext.identity() : ScaleContext.from(containerWidth, idealWidth);
642
+ const sGap = ctx.structural(effectiveGap);
643
+ const sBoxW = ctx.structural(uniformBoxWidth);
644
+ const sBoxH = ctx.structural(PARTICIPANT_BOX_HEIGHT);
645
+ const sTopMargin = ctx.aesthetic(TOP_MARGIN);
646
+ const sTitleHeight = ctx.aesthetic(TITLE_HEIGHT);
647
+ const sParticipantYOffset = ctx.aesthetic(PARTICIPANT_Y_OFFSET);
648
+ const sMsgStartOffset = ctx.structural(MESSAGE_START_OFFSET);
649
+ const sLifelineTail = ctx.structural(LIFELINE_TAIL);
650
+ const sArrowheadSize = ctx.structural(ARROWHEAD_SIZE);
651
+ const sNoteMaxW = ctx.structural(NOTE_MAX_W);
652
+ const sNoteFold = ctx.structural(NOTE_FOLD);
653
+ const sNotePadH = ctx.structural(NOTE_PAD_H);
654
+ const sNotePadV = ctx.structural(NOTE_PAD_V);
655
+ const sNoteFontSize = ctx.text(NOTE_FONT_SIZE);
656
+ const sNoteLineH = ctx.structural(NOTE_LINE_H);
657
+ const sNoteGap = ctx.structural(NOTE_GAP);
658
+ const sActivationWidth = ctx.structural(ACTIVATION_WIDTH);
659
+ const sSelfCallHeight = SELF_CALL_HEIGHT;
660
+ const sSelfCallWidth = ctx.structural(SELF_CALL_WIDTH);
661
+ const sNoteTextWidthMax = sNoteMaxW - sNotePadH * 2 - sNoteFold;
662
+ const sNoteLaneMax = sGap - sActivationWidth - sNoteGap;
663
+ const sLabelFontSize = ctx.text(LABEL_FONT_SIZE);
664
+ const sLabelTextWidth = labelTextWidth(sBoxW);
665
+ const participantIndexMap = /* @__PURE__ */ new Map();
666
+ participants.forEach((p, i) => participantIndexMap.set(p.id, i));
667
+ const effectiveNotePosition = (note) => {
668
+ const idx = participantIndexMap.get(note.participantId);
669
+ if (idx === void 0) return note.position;
670
+ if (note.position === "right" && idx === participants.length - 1 && idx > 0)
671
+ return "left";
672
+ if (note.position === "left" && idx === 0 && participants.length > 1)
673
+ return "right";
674
+ return note.position;
675
+ };
676
+ const SELF_CALL_NOTE_X_SHIFT = sActivationWidth / 2 + sSelfCallWidth + sNoteGap - (sActivationWidth + sNoteGap);
677
+ const noteEffectiveMaxW = (participantId, position, afterSelfCall = false) => {
678
+ const idx = participantIndexMap.get(participantId);
679
+ if (idx === void 0) return sNoteMaxW;
680
+ const hasNeighbor = position === "right" ? idx < participants.length - 1 : idx > 0;
681
+ if (!hasNeighbor) return sNoteMaxW;
682
+ const laneMax = afterSelfCall && position === "right" ? sNoteLaneMax - SELF_CALL_NOTE_X_SHIFT : sNoteLaneMax;
683
+ return Math.min(sNoteMaxW, laneMax);
684
+ };
685
+ const noteTextWidth = (maxW) => maxW - sNotePadH * 2 - sNoteFold;
686
+ const activationsOff = parsedOptions["activations"]?.toLowerCase() === "off";
687
+ const activeTagGroup = resolveActiveTagGroup(
688
+ parsed.tagGroups.filter((tg) => tg.entries.length > 0),
689
+ parsedOptions["active-tag"],
690
+ options?.activeTagGroup
691
+ ) ?? void 0;
692
+ let tagMap;
693
+ const tagValueToColor = /* @__PURE__ */ new Map();
694
+ if (activeTagGroup) {
695
+ tagMap = resolveSequenceTags(parsed, activeTagGroup);
696
+ const tg = parsed.tagGroups.find(
697
+ (g) => g.name.toLowerCase() === activeTagGroup.toLowerCase()
698
+ );
699
+ if (tg) {
700
+ for (const entry of tg.entries) {
701
+ tagValueToColor.set(entry.value.toLowerCase(), entry.color);
702
+ }
703
+ }
704
+ }
705
+ const getTagColor = (value) => value ? tagValueToColor.get(value.toLowerCase()) : void 0;
706
+ const tagKey = activeTagGroup ? tagAttrKey(activeTagGroup) : void 0;
707
+ const hiddenMsgIndices = /* @__PURE__ */ new Set();
708
+ if (collapsedSections && collapsedSections.size > 0) {
709
+ const sectionGroups = groupMessagesBySection(elements, messages);
710
+ for (const grp of sectionGroups) {
711
+ if (collapsedSections.has(grp.section.lineNumber)) {
712
+ for (const idx of grp.messageIndices) {
713
+ hiddenMsgIndices.add(idx);
714
+ }
715
+ }
716
+ }
717
+ }
718
+ const allRenderSteps = buildRenderSequence(messages);
719
+ const stepSurvives = (s) => (hiddenMsgIndices.size === 0 || !hiddenMsgIndices.has(s.messageIndex)) && (s.type === "call" || !!s.label);
720
+ const renderSteps = [];
721
+ const allToFiltered = new Array(allRenderSteps.length);
722
+ for (let j = 0; j < allRenderSteps.length; j++) {
723
+ const s = allRenderSteps[j];
724
+ allToFiltered[j] = renderSteps.length;
725
+ if (stepSurvives(s)) renderSteps.push(s);
726
+ }
727
+ const lastStepIdx = Math.max(renderSteps.length - 1, 0);
728
+ const clampStep = (i) => Math.min(Math.max(i, 0), lastStepIdx);
729
+ const activations = activationsOff ? [] : computeActivations(allRenderSteps).map((a) => ({
730
+ ...a,
731
+ startStep: clampStep(allToFiltered[a.startStep] ?? 0),
732
+ endStep: clampStep(allToFiltered[a.endStep] ?? 0)
733
+ }));
734
+ const stepSpacing = 35;
735
+ const BLOCK_HEADER_SPACE = 30;
736
+ const BLOCK_AFTER_SPACE = 15;
737
+ const FRAME_PADDING_TOP = 42;
738
+ const msgToFirstStep = /* @__PURE__ */ new Map();
739
+ const msgToLastStep = /* @__PURE__ */ new Map();
740
+ renderSteps.forEach((step, si) => {
741
+ if (!msgToFirstStep.has(step.messageIndex)) {
742
+ msgToFirstStep.set(step.messageIndex, si);
743
+ }
744
+ msgToLastStep.set(step.messageIndex, si);
745
+ });
746
+ const findAssociatedLastStep = (note) => {
747
+ let closestMsgIndex = -1;
748
+ let closestLine = -1;
749
+ for (let mi = 0; mi < messages.length; mi++) {
750
+ const m = messages[mi];
751
+ if (m.lineNumber < note.lineNumber && m.lineNumber > closestLine) {
752
+ closestLine = m.lineNumber;
753
+ closestMsgIndex = mi;
754
+ }
755
+ }
756
+ if (closestMsgIndex >= 0 && hiddenMsgIndices.has(closestMsgIndex)) {
757
+ return -1;
758
+ }
759
+ if (closestMsgIndex < 0) return -1;
760
+ return msgToLastStep.get(closestMsgIndex) ?? -1;
761
+ };
762
+ const isNoteAfterSelfCall = (note) => {
763
+ let closestMsgIndex = -1;
764
+ let closestLine = -1;
765
+ for (let mi = 0; mi < messages.length; mi++) {
766
+ const m = messages[mi];
767
+ if (m.lineNumber < note.lineNumber && m.lineNumber > closestLine) {
768
+ closestLine = m.lineNumber;
769
+ closestMsgIndex = mi;
770
+ }
771
+ }
772
+ if (closestMsgIndex < 0) return false;
773
+ const msg = messages[closestMsgIndex];
774
+ return msg.from === msg.to;
775
+ };
776
+ const SELF_CALL_NOTE_GAP = ctx.structural(8);
777
+ const noteOffsetBelow = (note) => isNoteAfterSelfCall(note) ? sSelfCallHeight + NOTE_OFFSET_BELOW + SELF_CALL_NOTE_GAP : NOTE_OFFSET_BELOW;
778
+ const msgLineToIdx = /* @__PURE__ */ new Map();
779
+ messages.forEach((m, i) => msgLineToIdx.set(m.lineNumber, i));
780
+ const findFirstMsgIndex = (els) => {
781
+ for (const el of els) {
782
+ if (isSequenceBlock(el)) {
783
+ const idx = findFirstMsgIndex(el.children);
784
+ if (idx >= 0) return idx;
785
+ if (el.elseIfBranches) {
786
+ for (const branch of el.elseIfBranches) {
787
+ const branchIdx = findFirstMsgIndex(branch.children);
788
+ if (branchIdx >= 0) return branchIdx;
789
+ }
790
+ }
791
+ const elseIdx = findFirstMsgIndex(el.elseChildren);
792
+ if (elseIdx >= 0) return elseIdx;
793
+ } else if (!isSequenceSection(el) && !isSequenceNote(el)) {
794
+ const idx = msgLineToIdx.get(el.lineNumber) ?? -1;
795
+ if (idx >= 0 && !hiddenMsgIndices.has(idx)) return idx;
796
+ }
797
+ }
798
+ return -1;
799
+ };
800
+ const SECTION_TOP_PAD = 35;
801
+ const SECTION_BOTTOM_PAD = 45;
802
+ const extraBeforeMsg = /* @__PURE__ */ new Map();
803
+ const addExtra = (msgIdx, amount) => {
804
+ extraBeforeMsg.set(msgIdx, (extraBeforeMsg.get(msgIdx) || 0) + amount);
805
+ };
806
+ const markBlockSpacing = (els) => {
807
+ for (let i = 0; i < els.length; i++) {
808
+ const el = els[i];
809
+ if (isSequenceSection(el)) continue;
810
+ if (!isSequenceBlock(el)) continue;
811
+ const firstIdx = findFirstMsgIndex(el.children);
812
+ if (firstIdx >= 0) addExtra(firstIdx, BLOCK_HEADER_SPACE);
813
+ if (el.elseIfBranches) {
814
+ for (const branch of el.elseIfBranches) {
815
+ const firstBranchIdx = findFirstMsgIndex(branch.children);
816
+ if (firstBranchIdx >= 0) addExtra(firstBranchIdx, BLOCK_HEADER_SPACE);
817
+ markBlockSpacing(branch.children);
818
+ }
819
+ }
820
+ const firstElseIdx = findFirstMsgIndex(el.elseChildren);
821
+ if (firstElseIdx >= 0) addExtra(firstElseIdx, BLOCK_HEADER_SPACE);
822
+ markBlockSpacing(el.children);
823
+ markBlockSpacing(el.elseChildren);
824
+ if (i + 1 < els.length) {
825
+ const nextIdx = findFirstMsgIndex([els[i + 1]]);
826
+ if (nextIdx >= 0) addExtra(nextIdx, BLOCK_AFTER_SPACE);
827
+ }
828
+ }
829
+ };
830
+ if (elements && elements.length > 0) {
831
+ markBlockSpacing(elements);
832
+ }
833
+ const NOTE_OFFSET_BELOW = ctx.structural(14);
834
+ const NOTE_TRAILING_GAP = ctx.aesthetic(35);
835
+ const computeNoteHeight = (text, textWidth = sNoteTextWidthMax) => {
836
+ const lines = wrapTextLines(text, textWidth, sNoteFontSize);
837
+ return lines.length * sNoteLineH + sNotePadV * 2;
838
+ };
839
+ let trailingNoteSpace = 0;
840
+ const markNoteSpacing = (els) => {
841
+ for (let i = 0; i < els.length; i++) {
842
+ const el = els[i];
843
+ if (isSequenceNote(el)) {
844
+ const firstOffset = noteOffsetBelow(el);
845
+ let totalExtent = firstOffset;
846
+ let j = i;
847
+ while (j < els.length && isSequenceNote(els[j])) {
848
+ const note = els[j];
849
+ const sc = isNoteAfterSelfCall(note);
850
+ const maxW = noteEffectiveMaxW(note.participantId, note.position, sc);
851
+ const noteH = computeNoteHeight(note.text, noteTextWidth(maxW));
852
+ totalExtent += noteH + NOTE_OFFSET_BELOW;
853
+ j++;
854
+ }
855
+ const trailingGap = Math.max(NOTE_TRAILING_GAP, totalExtent * 0.3);
856
+ totalExtent += trailingGap - NOTE_OFFSET_BELOW;
857
+ let extraNeeded = Math.max(0, totalExtent - stepSpacing);
858
+ let nextMsgIdx = -1;
859
+ for (let k = j; k < els.length; k++) {
860
+ nextMsgIdx = findFirstMsgIndex([els[k]]);
861
+ if (nextMsgIdx >= 0) break;
862
+ }
863
+ if (j < els.length && isSequenceBlock(els[j])) {
864
+ extraNeeded += FRAME_PADDING_TOP - BLOCK_HEADER_SPACE;
865
+ }
866
+ if (nextMsgIdx >= 0) {
867
+ addExtra(nextMsgIdx, extraNeeded);
868
+ } else {
869
+ trailingNoteSpace = Math.max(trailingNoteSpace, extraNeeded);
870
+ }
871
+ i = j - 1;
872
+ } else if (isSequenceBlock(el)) {
873
+ markNoteSpacing(el.children);
874
+ if (el.elseIfBranches) {
875
+ for (const branch of el.elseIfBranches) {
876
+ markNoteSpacing(branch.children);
877
+ }
878
+ }
879
+ markNoteSpacing(el.elseChildren);
880
+ }
881
+ }
882
+ };
883
+ if (elements && elements.length > 0) {
884
+ markNoteSpacing(elements);
885
+ }
886
+ const preSectionMsgIndices = [];
887
+ const sectionRegions = [];
888
+ {
889
+ const msgLineToIndex = /* @__PURE__ */ new Map();
890
+ messages.forEach((m, i) => msgLineToIndex.set(m.lineNumber, i));
891
+ const findMsgIndex = (child) => msgLineToIndex.get(child.lineNumber) ?? -1;
892
+ const collectMsgIndicesFromBlock = (block) => {
893
+ const indices = [];
894
+ for (const child of block.children) {
895
+ if (isSequenceBlock(child)) {
896
+ indices.push(...collectMsgIndicesFromBlock(child));
897
+ } else if (!isSequenceSection(child) && !isSequenceNote(child)) {
898
+ const idx = findMsgIndex(child);
899
+ if (idx >= 0) indices.push(idx);
900
+ }
901
+ }
902
+ if (block.elseIfBranches) {
903
+ for (const branch of block.elseIfBranches) {
904
+ for (const child of branch.children) {
905
+ if (isSequenceBlock(child)) {
906
+ indices.push(...collectMsgIndicesFromBlock(child));
907
+ } else if (!isSequenceSection(child) && !isSequenceNote(child)) {
908
+ const idx = findMsgIndex(child);
909
+ if (idx >= 0) indices.push(idx);
910
+ }
911
+ }
912
+ }
913
+ }
914
+ for (const child of block.elseChildren) {
915
+ if (isSequenceBlock(child)) {
916
+ indices.push(...collectMsgIndicesFromBlock(child));
917
+ } else if (!isSequenceSection(child) && !isSequenceNote(child)) {
918
+ const idx = findMsgIndex(child);
919
+ if (idx >= 0) indices.push(idx);
920
+ }
921
+ }
922
+ return indices;
923
+ };
924
+ let currentTarget = preSectionMsgIndices;
925
+ for (const el of elements) {
926
+ if (isSequenceSection(el)) {
927
+ const region = { section: el, msgIndices: [] };
928
+ sectionRegions.push(region);
929
+ currentTarget = region.msgIndices;
930
+ } else if (isSequenceBlock(el)) {
931
+ currentTarget.push(...collectMsgIndicesFromBlock(el));
932
+ } else {
933
+ const idx = findMsgIndex(el);
934
+ if (idx >= 0) currentTarget.push(idx);
935
+ }
936
+ }
937
+ }
938
+ const allMsgToFirstStep = /* @__PURE__ */ new Map();
939
+ allRenderSteps.forEach((step, si) => {
940
+ if (!allMsgToFirstStep.has(step.messageIndex)) {
941
+ allMsgToFirstStep.set(step.messageIndex, si);
942
+ }
943
+ });
944
+ const originalToFiltered = /* @__PURE__ */ new Map();
945
+ {
946
+ let fi = 0;
947
+ for (let oi = 0; oi < allRenderSteps.length; oi++) {
948
+ const step = allRenderSteps[oi];
949
+ if (!hiddenMsgIndices.has(step.messageIndex) && (step.type === "call" || step.label)) {
950
+ originalToFiltered.set(oi, fi);
951
+ fi++;
952
+ }
953
+ }
954
+ }
955
+ const findFilteredInsertionPoint = (origStep) => {
956
+ for (let i = origStep; i < allRenderSteps.length; i++) {
957
+ const fi = originalToFiltered.get(i);
958
+ if (fi !== void 0) return fi;
959
+ }
960
+ return null;
961
+ };
962
+ const sectionsBeforeStep = /* @__PURE__ */ new Map();
963
+ const trailingSections = [];
964
+ for (const region of sectionRegions) {
965
+ if (region.msgIndices.length === 0) {
966
+ trailingSections.push(region.section);
967
+ continue;
968
+ }
969
+ const firstMsgIdx = region.msgIndices[0];
970
+ const origStep = allMsgToFirstStep.get(firstMsgIdx);
971
+ if (origStep === void 0) {
972
+ trailingSections.push(region.section);
973
+ continue;
974
+ }
975
+ const filteredStep = findFilteredInsertionPoint(origStep);
976
+ if (filteredStep === null) {
977
+ trailingSections.push(region.section);
978
+ continue;
979
+ }
980
+ const existing = sectionsBeforeStep.get(filteredStep) || [];
981
+ existing.push(region.section);
982
+ sectionsBeforeStep.set(filteredStep, existing);
983
+ }
984
+ const sectionMsgCounts = /* @__PURE__ */ new Map();
985
+ for (const region of sectionRegions) {
986
+ sectionMsgCounts.set(region.section.lineNumber, region.msgIndices.length);
987
+ }
988
+ const GROUP_PADDING_X = 15;
989
+ const GROUP_PADDING_TOP = 22;
990
+ const GROUP_PADDING_BOTTOM = 8;
991
+ const GROUP_LABEL_SIZE = 11;
992
+ const showTitle = !!title && parsedOptions["no-title"] !== "on";
993
+ const titleOffset = showTitle ? sTitleHeight : 0;
994
+ const LEGEND_FIXED_GAP = 8;
995
+ const resolvedGroups = parsed.tagGroups.filter((tg) => tg.entries.length > 0).map((tg) => ({
996
+ name: tg.name,
997
+ entries: tg.entries.map((e) => ({ value: e.value, color: e.color }))
998
+ }));
999
+ const legendConfig = {
1000
+ groups: resolvedGroups,
1001
+ position: { placement: "top-center", titleRelation: "below-title" },
1002
+ mode: "preview"
1003
+ };
1004
+ const legendTopSpace = parsed.tagGroups.length > 0 ? getMaxLegendReservedHeight(legendConfig, containerWidth) + LEGEND_FIXED_GAP : 0;
1005
+ const groupOffset = parsed.groups.length > 0 ? GROUP_PADDING_TOP + GROUP_LABEL_SIZE : 0;
1006
+ const participantStartY = sTopMargin + titleOffset + legendTopSpace + sParticipantYOffset + groupOffset;
1007
+ const lifelineStartY0 = participantStartY + sBoxH;
1008
+ const hasActors = participants.some((p) => p.type === "actor");
1009
+ const messageStartOffset = sMsgStartOffset + (hasActors ? 20 : 0) + (parsed.groups.length > 0 ? GROUP_PADDING_BOTTOM : 0);
1010
+ const stepYPositions = [];
1011
+ const sectionYPositions = /* @__PURE__ */ new Map();
1012
+ let layoutEndY;
1013
+ {
1014
+ let curY = lifelineStartY0 + messageStartOffset;
1015
+ for (let i = 0; i < renderSteps.length; i++) {
1016
+ const sections = sectionsBeforeStep.get(i);
1017
+ if (sections) {
1018
+ for (const sec of sections) {
1019
+ curY += SECTION_TOP_PAD;
1020
+ sectionYPositions.set(sec.lineNumber, curY);
1021
+ curY += SECTION_BOTTOM_PAD;
1022
+ }
1023
+ }
1024
+ const step = renderSteps[i];
1025
+ if (msgToFirstStep.get(step.messageIndex) === i) {
1026
+ const extra = extraBeforeMsg.get(step.messageIndex) || 0;
1027
+ curY += extra;
1028
+ }
1029
+ stepYPositions.push(curY);
1030
+ const isSelfCall = step.type === "call" && step.from === step.to;
1031
+ curY += isSelfCall ? sSelfCallHeight + 25 : stepSpacing;
1032
+ }
1033
+ for (const sec of trailingSections) {
1034
+ curY += SECTION_TOP_PAD;
1035
+ sectionYPositions.set(sec.lineNumber, curY);
1036
+ curY += SECTION_BOTTOM_PAD;
1037
+ }
1038
+ curY += trailingNoteSpace;
1039
+ layoutEndY = curY;
1040
+ }
1041
+ const stepY = (i) => stepYPositions[i];
1042
+ const noteYMap = /* @__PURE__ */ new Map();
1043
+ {
1044
+ const computeNotePositions = (els) => {
1045
+ for (let i = 0; i < els.length; i++) {
1046
+ const el = els[i];
1047
+ if (isSequenceNote(el)) {
1048
+ const si = findAssociatedLastStep(el);
1049
+ if (si < 0) continue;
1050
+ const prevNote = i > 0 && isSequenceNote(els[i - 1]) ? els[i - 1] : null;
1051
+ const prevNoteY = prevNote ? noteYMap.get(prevNote) : void 0;
1052
+ let noteTopY;
1053
+ if (prevNoteY !== void 0 && prevNote) {
1054
+ const prevMaxW = noteEffectiveMaxW(
1055
+ prevNote.participantId,
1056
+ effectiveNotePosition(prevNote),
1057
+ isNoteAfterSelfCall(prevNote)
1058
+ );
1059
+ const prevNoteH = computeNoteHeight(
1060
+ prevNote.text,
1061
+ noteTextWidth(prevMaxW)
1062
+ );
1063
+ noteTopY = prevNoteY + prevNoteH + NOTE_OFFSET_BELOW;
1064
+ } else {
1065
+ noteTopY = stepY(si) + noteOffsetBelow(el);
1066
+ }
1067
+ noteYMap.set(el, noteTopY);
1068
+ } else if (isSequenceBlock(el)) {
1069
+ computeNotePositions(el.children);
1070
+ if (el.elseIfBranches) {
1071
+ for (const branch of el.elseIfBranches) {
1072
+ computeNotePositions(branch.children);
1073
+ }
1074
+ }
1075
+ computeNotePositions(el.elseChildren);
1076
+ }
1077
+ }
1078
+ };
1079
+ if (elements && elements.length > 0) {
1080
+ computeNotePositions(elements);
1081
+ }
1082
+ }
1083
+ const lastStep = renderSteps[renderSteps.length - 1];
1084
+ const lastIsSelfCall = lastStep?.type === "call" && lastStep.from === lastStep.to;
1085
+ const lastStepTrailing = lastIsSelfCall ? sSelfCallHeight + 25 : stepSpacing;
1086
+ let contentBottomY = renderSteps.length > 0 ? Math.max(
1087
+ // In-bounds: renderSteps.length > 0 guarantees stepYPositions is
1088
+ // non-empty (1:1 with renderSteps in the layout loop above).
1089
+ stepYPositions[stepYPositions.length - 1] + lastStepTrailing,
1090
+ layoutEndY
1091
+ ) : layoutEndY;
1092
+ for (const [note, noteTopY] of noteYMap) {
1093
+ const maxW = noteEffectiveMaxW(
1094
+ note.participantId,
1095
+ effectiveNotePosition(note),
1096
+ isNoteAfterSelfCall(note)
1097
+ );
1098
+ const noteH = computeNoteHeight(note.text, noteTextWidth(maxW));
1099
+ contentBottomY = Math.max(
1100
+ contentBottomY,
1101
+ noteTopY + noteH + NOTE_TRAILING_GAP
1102
+ );
1103
+ }
1104
+ const messageAreaHeight = contentBottomY - lifelineStartY0;
1105
+ const lifelineLength = messageAreaHeight + sLifelineTail;
1106
+ const totalGaps = participants.length > 1 ? participants.length - 1 : 0;
1107
+ const numWithinGaps = totalGaps - numGroupGaps;
1108
+ let sWithinGap = sGap;
1109
+ let sBetweenGap = sGap;
1110
+ if (numGroupGaps > 0 && totalGaps > 0) {
1111
+ sWithinGap = sGap * 0.88;
1112
+ sBetweenGap = (totalGaps * sGap - numWithinGaps * sWithinGap) / numGroupGaps;
1113
+ }
1114
+ const rightmostId = participants[participants.length - 1]?.id;
1115
+ let rightProjection = sBoxW / 2;
1116
+ if (rightmostId) {
1117
+ if (parsed.groups.some(
1118
+ (g) => g.participantIds.includes(rightmostId)
1119
+ ))
1120
+ rightProjection = Math.max(rightProjection, sBoxW / 2 + GROUP_PADDING_X);
1121
+ for (const step of renderSteps) {
1122
+ if (step.from === step.to && step.from === rightmostId) {
1123
+ const selfProj = sActivationWidth + sSelfCallWidth;
1124
+ let labelProj = 0;
1125
+ if (step.label) labelProj = measureText(step.label, 12) + 15;
1126
+ rightProjection = Math.max(rightProjection, selfProj + labelProj);
1127
+ }
1128
+ }
1129
+ const blockFramePadX = 30;
1130
+ const hasBlockWithRightmost = (els) => {
1131
+ for (const el of els) {
1132
+ if (isSequenceBlock(el)) {
1133
+ const involvesRightmost = (children) => children.some(
1134
+ (c) => !isSequenceBlock(c) && !isSequenceNote(c) && !isSequenceSection(c) && "from" in c && (c.from === rightmostId || c.to === rightmostId)
1135
+ );
1136
+ if (involvesRightmost(el.children) || involvesRightmost(el.elseChildren) || el.elseIfBranches?.some((b) => involvesRightmost(b.children)))
1137
+ return true;
1138
+ if (hasBlockWithRightmost(el.children) || hasBlockWithRightmost(el.elseChildren) || el.elseIfBranches?.some((b) => hasBlockWithRightmost(b.children)))
1139
+ return true;
1140
+ }
1141
+ }
1142
+ return false;
1143
+ };
1144
+ if (elements && hasBlockWithRightmost(elements))
1145
+ rightProjection = Math.max(rightProjection, sBoxW / 2 + blockFramePadX);
1146
+ }
1147
+ let rightMargin = Math.max(rightProjection + 10, sGap / 2);
1148
+ let leftMargin = sGap / 2;
1149
+ const diagramWidth = participants.length * sGap;
1150
+ let totalWidth = Math.max(
1151
+ leftMargin + diagramWidth + rightMargin,
1152
+ sBoxW + 40
1153
+ );
1154
+ const contentHeight = participantStartY + sBoxH + Math.max(lifelineLength, 40) + 40;
1155
+ const totalHeight = contentHeight;
1156
+ let svgWidth = Math.max(totalWidth, containerWidth);
1157
+ let offsetX = leftMargin + Math.max(0, (svgWidth - totalWidth) / 2);
1158
+ const participantX = /* @__PURE__ */ new Map();
1159
+ const buildParticipantX = () => {
1160
+ let px = offsetX;
1161
+ participantX.clear();
1162
+ participants.forEach((p, i) => {
1163
+ participantX.set(p.id, px);
1164
+ if (i < participants.length - 1) {
1165
+ const nextId = participants[i + 1].id;
1166
+ px += groupBoundaryIds.has(nextId) ? sBetweenGap : sWithinGap;
1167
+ }
1168
+ });
1169
+ };
1170
+ buildParticipantX();
1171
+ let contentLeft = 0;
1172
+ let contentRight = svgWidth;
1173
+ for (const step of renderSteps) {
1174
+ if (!step.label) continue;
1175
+ const labelW = measureText(step.label, 12);
1176
+ if (step.from === step.to) {
1177
+ const px = participantX.get(step.from);
1178
+ if (px !== void 0) {
1179
+ const loopRight = px + sActivationWidth / 2 + sSelfCallWidth + 5 + labelW;
1180
+ contentRight = Math.max(contentRight, loopRight);
1181
+ }
1182
+ } else {
1183
+ const fromX = participantX.get(step.from);
1184
+ const toX = participantX.get(step.to);
1185
+ if (fromX !== void 0 && toX !== void 0) {
1186
+ const midX = (fromX + toX) / 2;
1187
+ contentLeft = Math.min(contentLeft, midX - labelW / 2);
1188
+ contentRight = Math.max(contentRight, midX + labelW / 2);
1189
+ }
1190
+ }
1191
+ }
1192
+ if (elements) {
1193
+ const scanNotes = (els) => {
1194
+ for (const el of els) {
1195
+ if (isSequenceNote(el)) {
1196
+ const note = el;
1197
+ const pos = effectiveNotePosition(note);
1198
+ if (pos === "right") {
1199
+ const px = participantX.get(note.participantId);
1200
+ if (px !== void 0) {
1201
+ const sc = isNoteAfterSelfCall(note);
1202
+ const rOff = sc ? sActivationWidth / 2 + sSelfCallWidth + sNoteGap : sActivationWidth + sNoteGap;
1203
+ const maxW = noteEffectiveMaxW(note.participantId, pos, sc);
1204
+ contentRight = Math.max(contentRight, px + rOff + maxW);
1205
+ }
1206
+ }
1207
+ } else if (isSequenceBlock(el)) {
1208
+ scanNotes(el.children);
1209
+ scanNotes(el.elseChildren);
1210
+ if (el.elseIfBranches) {
1211
+ for (const b of el.elseIfBranches) scanNotes(b.children);
1212
+ }
1213
+ }
1214
+ }
1215
+ };
1216
+ scanNotes(elements);
1217
+ }
1218
+ const neededLeftPad = Math.max(0, -contentLeft);
1219
+ const neededRightPad = Math.max(0, contentRight - svgWidth);
1220
+ if (neededLeftPad > 0 || neededRightPad > 0) {
1221
+ leftMargin += neededLeftPad;
1222
+ rightMargin += neededRightPad;
1223
+ totalWidth = Math.max(leftMargin + diagramWidth + rightMargin, sBoxW + 40);
1224
+ svgWidth = Math.max(totalWidth, containerWidth);
1225
+ offsetX = leftMargin + Math.max(0, (svgWidth - totalWidth) / 2);
1226
+ buildParticipantX();
1227
+ }
1228
+ const svg = d3Selection.select(container).append("svg").attr("width", "100%").attr("height", totalHeight).attr("viewBox", `0 0 ${svgWidth} ${totalHeight}`).attr("preserveAspectRatio", "xMidYMin meet").attr("class", "sequence-diagram").style("font-family", FONT_FAMILY);
1229
+ const defs = svg.append("defs");
1230
+ defs.append("marker").attr("id", "seq-arrowhead").attr("viewBox", `0 0 ${sArrowheadSize} ${sArrowheadSize}`).attr("refX", sArrowheadSize).attr("refY", sArrowheadSize / 2).attr("markerWidth", sArrowheadSize).attr("markerHeight", sArrowheadSize).attr("orient", "auto").append("polygon").attr(
1231
+ "points",
1232
+ `0,0 ${sArrowheadSize},${sArrowheadSize / 2} 0,${sArrowheadSize}`
1233
+ ).attr("fill", palette.text);
1234
+ defs.append("marker").attr("id", "seq-arrowhead-open").attr("viewBox", `0 0 ${sArrowheadSize} ${sArrowheadSize}`).attr("refX", sArrowheadSize).attr("refY", sArrowheadSize / 2).attr("markerWidth", sArrowheadSize).attr("markerHeight", sArrowheadSize).attr("orient", "auto").append("polyline").attr(
1235
+ "points",
1236
+ `0,0 ${sArrowheadSize},${sArrowheadSize / 2} 0,${sArrowheadSize}`
1237
+ ).attr("fill", "none").attr("stroke", palette.textMuted).attr("stroke-width", 1.2);
1238
+ defs.append("marker").attr("id", "seq-arrowhead-async").attr("viewBox", `0 0 ${sArrowheadSize} ${sArrowheadSize}`).attr("refX", sArrowheadSize).attr("refY", sArrowheadSize / 2).attr("markerWidth", sArrowheadSize).attr("markerHeight", sArrowheadSize).attr("orient", "auto").append("polyline").attr(
1239
+ "points",
1240
+ `0,0 ${sArrowheadSize},${sArrowheadSize / 2} 0,${sArrowheadSize}`
1241
+ ).attr("fill", "none").attr("stroke", palette.text).attr("stroke-width", 1.2);
1242
+ const arrowPoints = `0,0 ${sArrowheadSize},${sArrowheadSize / 2} 0,${sArrowheadSize}`;
1243
+ for (const [, color] of tagValueToColor) {
1244
+ const hex = color.replace("#", "");
1245
+ defs.append("marker").attr("id", `seq-arrowhead-c${hex}`).attr("viewBox", `0 0 ${sArrowheadSize} ${sArrowheadSize}`).attr("refX", sArrowheadSize).attr("refY", sArrowheadSize / 2).attr("markerWidth", sArrowheadSize).attr("markerHeight", sArrowheadSize).attr("orient", "auto").append("polygon").attr("points", arrowPoints).attr("fill", color);
1246
+ defs.append("marker").attr("id", `seq-arrowhead-async-c${hex}`).attr("viewBox", `0 0 ${sArrowheadSize} ${sArrowheadSize}`).attr("refX", sArrowheadSize).attr("refY", sArrowheadSize / 2).attr("markerWidth", sArrowheadSize).attr("markerHeight", sArrowheadSize).attr("orient", "auto").append("polyline").attr("points", arrowPoints).attr("fill", "none").attr("stroke", color).attr("stroke-width", 1.2);
1247
+ defs.append("marker").attr("id", `seq-arrowhead-open-c${hex}`).attr("viewBox", `0 0 ${sArrowheadSize} ${sArrowheadSize}`).attr("refX", sArrowheadSize).attr("refY", sArrowheadSize / 2).attr("markerWidth", sArrowheadSize).attr("markerHeight", sArrowheadSize).attr("orient", "auto").append("polyline").attr("points", arrowPoints).attr("fill", "none").attr("stroke", color).attr("stroke-width", 1.2);
1248
+ }
1249
+ const coloredMarker = (type, tagColor) => {
1250
+ if (tagColor) {
1251
+ const hex = tagColor.replace("#", "");
1252
+ switch (type) {
1253
+ case "call":
1254
+ return `url(#seq-arrowhead-c${hex})`;
1255
+ case "async":
1256
+ return `url(#seq-arrowhead-async-c${hex})`;
1257
+ case "return":
1258
+ return `url(#seq-arrowhead-open-c${hex})`;
1259
+ }
1260
+ }
1261
+ switch (type) {
1262
+ case "call":
1263
+ return "url(#seq-arrowhead)";
1264
+ case "async":
1265
+ return "url(#seq-arrowhead-async)";
1266
+ case "return":
1267
+ return "url(#seq-arrowhead-open)";
1268
+ }
1269
+ };
1270
+ if (showTitle) {
1271
+ const titleEl = svg.append("text").attr("class", "chart-title").attr("x", svgWidth / 2).attr("y", ctx.structural(TITLE_Y)).attr("text-anchor", "middle").attr("fill", palette.text).attr("font-size", ctx.text(TITLE_FONT_SIZE)).attr("font-weight", TITLE_FONT_WEIGHT).text(title);
1272
+ if (parsed.titleLineNumber) {
1273
+ titleEl.attr("data-line-number", parsed.titleLineNumber);
1274
+ }
1275
+ }
1276
+ const hasTagGroups = parsed.tagGroups.length > 0;
1277
+ const collapsedGroupNames = /* @__PURE__ */ new Set();
1278
+ const collapsedGroupMeta = /* @__PURE__ */ new Map();
1279
+ for (const group of parsed.groups) {
1280
+ if (effectiveCollapsedGroups.has(group.lineNumber)) {
1281
+ collapsedGroupNames.add(group.name);
1282
+ collapsedGroupMeta.set(group.name, {
1283
+ lineNumber: group.lineNumber,
1284
+ ...group.metadata !== void 0 && { metadata: group.metadata }
1285
+ });
1286
+ }
1287
+ }
1288
+ for (const group of groups) {
1289
+ if (group.participantIds.length === 0) continue;
1290
+ const memberXs = group.participantIds.map((id) => participantX.get(id)).filter((x) => x !== void 0);
1291
+ if (memberXs.length === 0) continue;
1292
+ const minX = Math.min(...memberXs) - sBoxW / 2 - GROUP_PADDING_X;
1293
+ const maxX = Math.max(...memberXs) + sBoxW / 2 + GROUP_PADDING_X;
1294
+ const boxY = participantStartY - GROUP_PADDING_TOP;
1295
+ const boxH = sBoxH + GROUP_PADDING_TOP + GROUP_PADDING_BOTTOM;
1296
+ const groupTagValue = tagKey && group.metadata?.[tagKey];
1297
+ const groupTagColor = getTagColor(groupTagValue || void 0);
1298
+ const fillColor = groupTagColor ? mix(groupTagColor, themeBaseBg(palette, isDark), isDark ? 15 : 20) : isDark ? palette.surface : palette.bg;
1299
+ const strokeColor = groupTagColor || palette.textMuted;
1300
+ const groupG = svg.append("g").attr("class", "group-box-wrapper").attr("data-group-toggle", "").attr("data-group-line", String(group.lineNumber)).attr("tabindex", "0").attr("role", "button").attr("aria-expanded", "true").attr("cursor", "pointer");
1301
+ groupG.append("title").text("Click to collapse");
1302
+ groupG.append("rect").attr("x", minX).attr("y", boxY).attr("width", maxX - minX).attr("height", boxH).attr("rx", 6).attr("fill", fillColor).attr("stroke", strokeColor).attr("stroke-width", 1).attr("stroke-opacity", 0.5).attr("pointer-events", "none").attr("class", "group-box");
1303
+ groupG.append("rect").attr("x", minX).attr("y", boxY).attr("width", maxX - minX).attr("height", participantStartY - boxY).attr("fill", "transparent").attr("class", "group-label-hit");
1304
+ groupG.append("text").attr("x", (minX + maxX) / 2).attr("y", boxY + GROUP_LABEL_SIZE + 4).attr("text-anchor", "middle").attr("fill", strokeColor).attr("font-size", GROUP_LABEL_SIZE).attr("font-weight", "bold").attr("opacity", 0.7).attr("pointer-events", "none").attr("class", "group-label").text(group.name);
1305
+ }
1306
+ const lifelineStartY = lifelineStartY0;
1307
+ participants.forEach((participant) => {
1308
+ const cx = participantX.get(participant.id);
1309
+ const cy = participantStartY;
1310
+ const pTagValue = tagMap?.participants.get(participant.id);
1311
+ const pTagColor = getTagColor(pTagValue);
1312
+ const pTagAttr = tagKey && pTagValue ? { key: tagKey, value: pTagValue.toLowerCase() } : void 0;
1313
+ const isCollapsedGroup = collapsedGroupNames.has(participant.id);
1314
+ let effectiveTagColor = pTagColor;
1315
+ if (isCollapsedGroup && !effectiveTagColor) {
1316
+ const meta = collapsedGroupMeta.get(participant.id);
1317
+ if (meta?.metadata && tagKey) {
1318
+ effectiveTagColor = getTagColor(meta.metadata[tagKey]);
1319
+ }
1320
+ }
1321
+ renderParticipant(
1322
+ svg,
1323
+ participant,
1324
+ cx,
1325
+ cy,
1326
+ palette,
1327
+ isDark,
1328
+ effectiveTagColor,
1329
+ pTagAttr,
1330
+ solid,
1331
+ sBoxW,
1332
+ sBoxH,
1333
+ sLabelTextWidth,
1334
+ sLabelFontSize
1335
+ );
1336
+ if (isCollapsedGroup) {
1337
+ const meta = collapsedGroupMeta.get(participant.id);
1338
+ const drillColor = effectiveTagColor || palette.textMuted;
1339
+ const drillBarH = 6;
1340
+ const boxW = sBoxW;
1341
+ const fullH = sBoxH + GROUP_PADDING_TOP + GROUP_PADDING_BOTTOM;
1342
+ const clipId = `clip-drill-group-${participant.id.replace(/[^a-zA-Z0-9-]/g, "-")}`;
1343
+ const participantG = svg.select(
1344
+ `.participant[data-participant-id="${participant.id}"]`
1345
+ );
1346
+ participantG.attr("data-group-toggle", "").attr("data-group-line", String(meta.lineNumber)).attr("tabindex", "0").attr("role", "button").attr("aria-expanded", "false").attr("cursor", "pointer");
1347
+ participantG.append("title").text("Click to expand");
1348
+ const pFill = effectiveTagColor ? mix(effectiveTagColor, themeBaseBg(palette, isDark), isDark ? 30 : 40) : isDark ? mix(palette.overlay, palette.surface, 50) : mix(palette.bg, palette.surface, 50);
1349
+ const pStroke = effectiveTagColor || palette.border;
1350
+ participantG.append("rect").attr("x", -boxW / 2).attr("y", -GROUP_PADDING_TOP).attr("width", boxW).attr("height", fullH).attr("rx", 6).attr("fill", pFill).attr("stroke", pStroke).attr("stroke-width", 1.5);
1351
+ participantG.append("text").attr("x", 0).attr("y", -GROUP_PADDING_TOP + fullH / 2).attr("text-anchor", "middle").attr("dominant-baseline", "central").attr("fill", palette.text).attr("font-size", ctx.text(13)).attr("font-weight", 500).text(participant.label);
1352
+ participantG.append("clipPath").attr("id", clipId).append("rect").attr("x", -boxW / 2).attr("y", -GROUP_PADDING_TOP).attr("width", boxW).attr("height", fullH).attr("rx", 6);
1353
+ participantG.append("rect").attr("class", "sequence-drill-bar").attr("x", -boxW / 2).attr("y", -GROUP_PADDING_TOP + fullH - drillBarH).attr("width", boxW).attr("height", drillBarH).attr("fill", drillColor).attr("clip-path", `url(#${clipId})`);
1354
+ }
1355
+ const llY = isCollapsedGroup ? lifelineStartY + GROUP_PADDING_BOTTOM : participant.type === "actor" ? lifelineStartY + ACTOR_LABEL_CLEARANCE : lifelineStartY;
1356
+ const llColor = isCollapsedGroup ? effectiveTagColor || palette.textMuted : pTagColor || palette.textMuted;
1357
+ const lifelineEl = svg.append("line").attr("x1", cx).attr("y1", llY).attr("x2", cx).attr("y2", lifelineStartY + lifelineLength).attr("stroke", llColor).attr("stroke-width", 1).attr("stroke-dasharray", "6 4").attr("class", "lifeline").attr("data-participant-id", participant.id);
1358
+ if (tagKey && pTagValue) {
1359
+ lifelineEl.attr(`data-tag-${tagKey}`, pTagValue.toLowerCase());
1360
+ }
1361
+ });
1362
+ const FRAME_PADDING_X = 30;
1363
+ const FRAME_PADDING_BOTTOM = 15;
1364
+ const FRAME_LABEL_HEIGHT = 18;
1365
+ const SELF_ARROW_PROJECTION = sActivationWidth / 2 + sSelfCallWidth;
1366
+ const SELF_ARROW_FRAME_PAD = 10;
1367
+ const frameRightmostX = Math.max(...Array.from(participantX.values()));
1368
+ const collectMsgIndices = (els) => {
1369
+ const indices = [];
1370
+ for (const el of els) {
1371
+ if (isSequenceBlock(el)) {
1372
+ indices.push(
1373
+ ...collectMsgIndices(el.children),
1374
+ ...collectMsgIndices(el.elseChildren)
1375
+ );
1376
+ if (el.elseIfBranches) {
1377
+ for (const branch of el.elseIfBranches) {
1378
+ indices.push(...collectMsgIndices(branch.children));
1379
+ }
1380
+ }
1381
+ } else if (!isSequenceSection(el) && !isSequenceNote(el)) {
1382
+ const idx = messages.indexOf(el);
1383
+ if (idx >= 0) indices.push(idx);
1384
+ }
1385
+ }
1386
+ return indices;
1387
+ };
1388
+ const deferredLabels = [];
1389
+ const deferredLines = [];
1390
+ const renderBlockFrames = (els, depth) => {
1391
+ for (const el of els) {
1392
+ if (!isSequenceBlock(el)) continue;
1393
+ const ifIndices = collectMsgIndices(el.children);
1394
+ const elseIfBranchData = [];
1395
+ if (el.elseIfBranches) {
1396
+ for (const branch of el.elseIfBranches) {
1397
+ elseIfBranchData.push({
1398
+ label: branch.label,
1399
+ indices: collectMsgIndices(branch.children),
1400
+ lineNumber: branch.lineNumber
1401
+ });
1402
+ }
1403
+ }
1404
+ const elseIndices = collectMsgIndices(el.elseChildren);
1405
+ const allIndices = [
1406
+ ...ifIndices,
1407
+ ...elseIfBranchData.flatMap((b) => b.indices),
1408
+ ...elseIndices
1409
+ ];
1410
+ if (allIndices.length === 0) continue;
1411
+ let minStep = Infinity;
1412
+ let maxStep = -Infinity;
1413
+ for (const mi of allIndices) {
1414
+ const first = msgToFirstStep.get(mi);
1415
+ const last = msgToLastStep.get(mi);
1416
+ if (first !== void 0) minStep = Math.min(minStep, first);
1417
+ if (last !== void 0) maxStep = Math.max(maxStep, last);
1418
+ }
1419
+ if (minStep === Infinity) continue;
1420
+ const involved = /* @__PURE__ */ new Set();
1421
+ for (const mi of allIndices) {
1422
+ const m = messages[mi];
1423
+ involved.add(m.from);
1424
+ involved.add(m.to);
1425
+ }
1426
+ let minPX = Infinity;
1427
+ let maxPX = -Infinity;
1428
+ for (const pid of involved) {
1429
+ const px = participantX.get(pid);
1430
+ if (px !== void 0) {
1431
+ minPX = Math.min(minPX, px);
1432
+ maxPX = Math.max(maxPX, px);
1433
+ }
1434
+ }
1435
+ let extraRight = 0;
1436
+ let maxStepIsSelfCall = false;
1437
+ for (const mi of allIndices) {
1438
+ const m = messages[mi];
1439
+ if (m.from === m.to) {
1440
+ const px = participantX.get(m.from);
1441
+ if (px !== void 0) {
1442
+ const loopMax = px + SELF_ARROW_PROJECTION;
1443
+ const need = loopMax - (maxPX + FRAME_PADDING_X) + SELF_ARROW_FRAME_PAD;
1444
+ if (need > 0) extraRight = Math.max(extraRight, need);
1445
+ }
1446
+ if (msgToLastStep.get(mi) === maxStep) {
1447
+ maxStepIsSelfCall = true;
1448
+ }
1449
+ }
1450
+ }
1451
+ const frameX = minPX - FRAME_PADDING_X;
1452
+ const frameY = stepY(minStep) - FRAME_PADDING_TOP;
1453
+ const frameW = maxPX - minPX + FRAME_PADDING_X * 2 + extraRight;
1454
+ const frameH = stepY(maxStep) - stepY(minStep) + FRAME_PADDING_TOP + FRAME_PADDING_BOTTOM + (maxStepIsSelfCall ? sSelfCallHeight : 0);
1455
+ svg.append("rect").attr("x", frameX).attr("y", frameY).attr("width", frameW).attr("height", frameH).attr("fill", "none").attr("stroke", palette.textMuted).attr("stroke-width", 1).attr("stroke-dasharray", "2 3").attr("rx", 3).attr("ry", 3).attr("class", "block-frame").attr("data-block-line", String(el.lineNumber));
1456
+ deferredLabels.push({
1457
+ x: frameX + 6,
1458
+ y: frameY + FRAME_LABEL_HEIGHT - 4,
1459
+ text: `${el.type} ${el.label}`,
1460
+ bold: false,
1461
+ italic: false,
1462
+ blockLine: el.lineNumber
1463
+ });
1464
+ for (const branchData of elseIfBranchData) {
1465
+ if (branchData.indices.length > 0) {
1466
+ let firstBranchStep = Infinity;
1467
+ for (const mi of branchData.indices) {
1468
+ const first = msgToFirstStep.get(mi);
1469
+ if (first !== void 0)
1470
+ firstBranchStep = Math.min(firstBranchStep, first);
1471
+ }
1472
+ if (firstBranchStep < Infinity) {
1473
+ const dividerY = stepY(firstBranchStep) - BLOCK_HEADER_SPACE;
1474
+ deferredLines.push({
1475
+ x1: frameX,
1476
+ y1: dividerY,
1477
+ x2: frameX + frameW,
1478
+ y2: dividerY,
1479
+ blockLine: branchData.lineNumber
1480
+ });
1481
+ deferredLabels.push({
1482
+ x: frameX + 6,
1483
+ y: dividerY + 14,
1484
+ text: `else if ${branchData.label}`,
1485
+ bold: false,
1486
+ italic: false,
1487
+ blockLine: branchData.lineNumber
1488
+ });
1489
+ }
1490
+ }
1491
+ }
1492
+ if (elseIndices.length > 0) {
1493
+ let firstElseStep = Infinity;
1494
+ for (const mi of elseIndices) {
1495
+ const first = msgToFirstStep.get(mi);
1496
+ if (first !== void 0)
1497
+ firstElseStep = Math.min(firstElseStep, first);
1498
+ }
1499
+ if (firstElseStep < Infinity) {
1500
+ const dividerY = stepY(firstElseStep) - BLOCK_HEADER_SPACE;
1501
+ deferredLines.push({
1502
+ x1: frameX,
1503
+ y1: dividerY,
1504
+ x2: frameX + frameW,
1505
+ y2: dividerY,
1506
+ ...el.elseLineNumber !== void 0 && {
1507
+ blockLine: el.elseLineNumber
1508
+ }
1509
+ });
1510
+ deferredLabels.push({
1511
+ x: frameX + 6,
1512
+ y: dividerY + 14,
1513
+ text: "else",
1514
+ bold: false,
1515
+ italic: false,
1516
+ ...el.elseLineNumber !== void 0 && {
1517
+ blockLine: el.elseLineNumber
1518
+ }
1519
+ });
1520
+ }
1521
+ }
1522
+ renderBlockFrames(el.children, depth + 1);
1523
+ if (el.elseIfBranches) {
1524
+ for (const branch of el.elseIfBranches) {
1525
+ renderBlockFrames(branch.children, depth + 1);
1526
+ }
1527
+ }
1528
+ renderBlockFrames(el.elseChildren, depth + 1);
1529
+ }
1530
+ };
1531
+ if (elements && elements.length > 0) {
1532
+ renderBlockFrames(elements, 0);
1533
+ }
1534
+ const ACTIVATION_NEST_OFFSET = ctx.structural(6);
1535
+ activations.forEach((act) => {
1536
+ const px = participantX.get(act.participantId);
1537
+ if (px === void 0) return;
1538
+ const x = px - sActivationWidth / 2 + act.depth * ACTIVATION_NEST_OFFSET;
1539
+ const y1 = stepY(act.startStep);
1540
+ const y2 = stepY(act.endStep);
1541
+ const coveredLines = [];
1542
+ for (let si = act.startStep; si <= act.endStep; si++) {
1543
+ const step = renderSteps[si];
1544
+ if (!step) continue;
1545
+ const msg = messages[step.messageIndex];
1546
+ if (msg) coveredLines.push(msg.lineNumber);
1547
+ }
1548
+ const triggerStep = renderSteps[act.startStep];
1549
+ const triggerMsg = triggerStep !== void 0 ? messages[triggerStep.messageIndex] : void 0;
1550
+ const actTagValue = triggerMsg ? tagMap?.messages.get(triggerMsg.lineNumber) : void 0;
1551
+ const actTagColor = getTagColor(actTagValue);
1552
+ const actBaseColor = actTagColor || palette.primary;
1553
+ svg.append("rect").attr("x", x).attr("y", y1).attr("width", sActivationWidth).attr("height", y2 - y1).attr("fill", themeBaseBg(palette, isDark));
1554
+ const actFill = shapeFill(palette, actBaseColor, isDark, { solid });
1555
+ const actRect = svg.append("rect").attr("x", x).attr("y", y1).attr("width", sActivationWidth).attr("height", y2 - y1).attr("fill", actFill).attr("stroke", actBaseColor).attr("stroke-width", 1).attr("stroke-opacity", 0.5).attr("data-participant-id", act.participantId).attr("data-msg-lines", coveredLines.join(",")).attr("data-line-number", coveredLines[0] ?? "").attr("class", "activation");
1556
+ if (tagKey && actTagValue) {
1557
+ actRect.attr(`data-tag-${tagKey}`, actTagValue.toLowerCase());
1558
+ }
1559
+ });
1560
+ for (const ln of deferredLines) {
1561
+ const line = svg.append("line").attr("x1", ln.x1).attr("y1", ln.y1).attr("x2", ln.x2).attr("y2", ln.y2).attr("stroke", palette.textMuted).attr("stroke-width", 1).attr("stroke-dasharray", "2 3").attr("class", "block-divider");
1562
+ if (ln.blockLine !== void 0)
1563
+ line.attr("data-block-line", String(ln.blockLine));
1564
+ }
1565
+ for (const lbl of deferredLabels) {
1566
+ const t = svg.append("text").attr("x", lbl.x).attr("y", lbl.y).attr("fill", palette.text).attr("font-size", 11).attr("class", "block-label").text(lbl.text);
1567
+ if (lbl.bold) t.attr("font-weight", "bold");
1568
+ if (lbl.italic) t.attr("font-style", "italic");
1569
+ if (lbl.blockLine !== void 0)
1570
+ t.attr("data-block-line", String(lbl.blockLine));
1571
+ }
1572
+ const activeDepthAt = (pid, stepIdx) => {
1573
+ let maxDepth = -1;
1574
+ for (const act of activations) {
1575
+ if (act.participantId === pid && act.startStep <= stepIdx && stepIdx <= act.endStep && act.depth > maxDepth) {
1576
+ maxDepth = act.depth;
1577
+ }
1578
+ }
1579
+ return maxDepth;
1580
+ };
1581
+ const arrowEdgeX = (pid, stepIdx, side) => {
1582
+ const px = participantX.get(pid);
1583
+ const depth = activeDepthAt(pid, stepIdx);
1584
+ if (depth < 0) return px;
1585
+ const offset = depth * ACTIVATION_NEST_OFFSET;
1586
+ return side === "right" ? px + sActivationWidth / 2 + offset : px - sActivationWidth / 2 + offset;
1587
+ };
1588
+ const leftmostX = Math.min(...Array.from(participantX.values()));
1589
+ const rightmostX = frameRightmostX;
1590
+ const sectionLineX1 = leftmostX - sBoxW / 2 - 10;
1591
+ const sectionLineX2 = rightmostX + sBoxW / 2 + 10;
1592
+ for (const region of sectionRegions) {
1593
+ const sec = region.section;
1594
+ const secY = sectionYPositions.get(sec.lineNumber);
1595
+ if (secY === void 0) continue;
1596
+ const isCollapsed = collapsedSections?.has(sec.lineNumber) ?? false;
1597
+ const lineColor = palette.textMuted;
1598
+ const sectionG = svg.append("g").attr("data-section-toggle", "").attr("data-line-number", String(sec.lineNumber)).attr("data-section", "").attr("tabindex", "0").attr("role", "button").attr("aria-expanded", String(!isCollapsed));
1599
+ const BAND_HEIGHT = 22;
1600
+ const bandX = sectionLineX1 - 10;
1601
+ const bandWidth = sectionLineX2 - sectionLineX1 + 20;
1602
+ const bandOpacity = isCollapsed ? isDark ? 0.35 : 0.25 : isDark ? 0.1 : 0.08;
1603
+ sectionG.append("rect").attr("x", bandX).attr("y", secY - BAND_HEIGHT / 2).attr("width", bandWidth).attr("height", BAND_HEIGHT).attr("fill", lineColor).attr("opacity", bandOpacity).attr("rx", 2).attr("pointer-events", "none").attr("class", "section-divider");
1604
+ const msgCount = sectionMsgCounts.get(sec.lineNumber) ?? 0;
1605
+ const labelText = isCollapsed ? `${sec.label} (${msgCount} ${msgCount === 1 ? "message" : "messages"})` : sec.label;
1606
+ const labelX = (sectionLineX1 + sectionLineX2) / 2;
1607
+ const labelHitW = Math.max(80, measureText(labelText, 11) + 24);
1608
+ sectionG.append("rect").attr("x", labelX - labelHitW / 2).attr("y", secY - BAND_HEIGHT / 2).attr("width", labelHitW).attr("height", BAND_HEIGHT).attr("fill", "transparent").attr("class", "section-label-hit");
1609
+ sectionG.append("text").attr("x", labelX).attr("y", secY + 4).attr("text-anchor", "middle").attr("fill", lineColor).attr("font-size", 11).attr("font-weight", "bold").attr("class", "section-label").text(labelText);
1610
+ }
1611
+ renderSteps.forEach((step, i) => {
1612
+ const fromX = participantX.get(step.from);
1613
+ const toX = participantX.get(step.to);
1614
+ if (fromX === void 0 || toX === void 0) return;
1615
+ const y = stepY(i);
1616
+ const HIT_H = 20;
1617
+ const msg = messages[step.messageIndex];
1618
+ const msgTagValue = msg ? tagMap?.messages.get(msg.lineNumber) : void 0;
1619
+ const msgTagColor = getTagColor(msgTagValue);
1620
+ if (step.type === "call") {
1621
+ const arrowColor = msgTagColor || palette.text;
1622
+ if (step.from === step.to) {
1623
+ const x = arrowEdgeX(step.from, i, "right");
1624
+ const loopX = x + sSelfCallWidth;
1625
+ const hitX = x;
1626
+ svg.append("rect").attr("x", hitX).attr("y", y - 5).attr("width", sSelfCallWidth).attr("height", sSelfCallHeight + 10).attr("fill", "transparent").attr("class", "message-hit-area").attr("data-line-number", String(msg.lineNumber)).attr("data-msg-index", String(step.messageIndex)).attr("data-step-index", String(i));
1627
+ const selfCallEl = svg.append("path").attr("d", `M ${x} ${y} H ${loopX} V ${y + sSelfCallHeight} H ${x}`).attr("fill", "none").attr("stroke", arrowColor).attr("stroke-width", 1.2).attr("marker-end", coloredMarker("call", msgTagColor)).attr("class", "message-arrow self-call").attr("data-line-number", String(msg.lineNumber)).attr("data-msg-index", String(step.messageIndex)).attr("data-step-index", String(i)).attr("data-from", step.from).attr("data-to", step.to);
1628
+ if (tagKey && msgTagValue) {
1629
+ selfCallEl.attr(`data-tag-${tagKey}`, msgTagValue.toLowerCase());
1630
+ }
1631
+ if (step.label) {
1632
+ const labelEl = svg.append("text").attr("x", loopX + 5).attr("y", y + sSelfCallHeight / 2 + 4).attr("text-anchor", "start").attr("fill", arrowColor).attr("paint-order", "stroke fill").attr("stroke", palette.bg).attr("stroke-width", 4).attr("stroke-linejoin", "round").attr("font-size", 12).attr("class", "message-label").attr("data-line-number", String(msg.lineNumber)).attr("data-msg-index", String(step.messageIndex)).attr("data-step-index", String(i));
1633
+ if (tagKey && msgTagValue) {
1634
+ labelEl.attr(`data-tag-${tagKey}`, msgTagValue.toLowerCase());
1635
+ }
1636
+ labelEl.text(step.label);
1637
+ }
1638
+ } else {
1639
+ const goingRight = fromX < toX;
1640
+ const x1 = arrowEdgeX(step.from, i, goingRight ? "right" : "left");
1641
+ const x2 = arrowEdgeX(step.to, i, goingRight ? "left" : "right");
1642
+ svg.append("rect").attr("x", Math.min(x1, x2)).attr("y", y - HIT_H / 2).attr("width", Math.abs(x2 - x1)).attr("height", HIT_H).attr("fill", "transparent").attr("class", "message-hit-area").attr("data-line-number", String(msg.lineNumber)).attr("data-msg-index", String(step.messageIndex)).attr("data-step-index", String(i));
1643
+ const markerRef = step.async ? coloredMarker("async", msgTagColor) : coloredMarker("call", msgTagColor);
1644
+ const arrowEl = svg.append("line").attr("x1", x1).attr("y1", y).attr("x2", x2).attr("y2", y).attr("stroke", arrowColor).attr("stroke-width", 1.2).attr("marker-end", markerRef).attr("class", "message-arrow").attr("data-line-number", String(msg.lineNumber)).attr("data-msg-index", String(step.messageIndex)).attr("data-step-index", String(i)).attr("data-from", step.from).attr("data-to", step.to);
1645
+ if (tagKey && msgTagValue) {
1646
+ arrowEl.attr(`data-tag-${tagKey}`, msgTagValue.toLowerCase());
1647
+ }
1648
+ if (step.label) {
1649
+ const midX = (x1 + x2) / 2;
1650
+ const labelEl = svg.append("text").attr("x", midX).attr("y", y - 8).attr("text-anchor", "middle").attr("fill", arrowColor).attr("paint-order", "stroke fill").attr("stroke", palette.bg).attr("stroke-width", 4).attr("stroke-linejoin", "round").attr("font-size", 12).attr("class", "message-label").attr("data-line-number", String(msg.lineNumber)).attr("data-msg-index", String(step.messageIndex)).attr("data-step-index", String(i));
1651
+ if (tagKey && msgTagValue) {
1652
+ labelEl.attr(`data-tag-${tagKey}`, msgTagValue.toLowerCase());
1653
+ }
1654
+ labelEl.text(step.label);
1655
+ }
1656
+ }
1657
+ } else {
1658
+ if (step.from === step.to) {
1659
+ return;
1660
+ }
1661
+ const goingRight = fromX < toX;
1662
+ const x1 = arrowEdgeX(step.from, i, goingRight ? "right" : "left");
1663
+ const x2 = arrowEdgeX(step.to, i, goingRight ? "left" : "right");
1664
+ const returnColor = msgTagColor || palette.textMuted;
1665
+ svg.append("rect").attr("x", Math.min(x1, x2)).attr("y", y - HIT_H / 2).attr("width", Math.abs(x2 - x1)).attr("height", HIT_H).attr("fill", "transparent").attr("class", "message-hit-area").attr("data-line-number", String(msg.lineNumber)).attr("data-msg-index", String(step.messageIndex)).attr("data-step-index", String(i));
1666
+ const returnEl = svg.append("line").attr("x1", x1).attr("y1", y).attr("x2", x2).attr("y2", y).attr("stroke", returnColor).attr("stroke-width", 1).attr("stroke-dasharray", "6 4").attr("marker-end", coloredMarker("return", msgTagColor)).attr("class", "return-arrow").attr("data-line-number", String(msg.lineNumber)).attr("data-msg-index", String(step.messageIndex)).attr("data-step-index", String(i)).attr("data-from", step.from).attr("data-to", step.to);
1667
+ if (tagKey && msgTagValue) {
1668
+ returnEl.attr(`data-tag-${tagKey}`, msgTagValue.toLowerCase());
1669
+ }
1670
+ if (step.label) {
1671
+ const midX = (x1 + x2) / 2;
1672
+ const labelEl = svg.append("text").attr("x", midX).attr("y", y - 6).attr("text-anchor", "middle").attr("fill", returnColor).attr("paint-order", "stroke fill").attr("stroke", palette.bg).attr("stroke-width", 4).attr("stroke-linejoin", "round").attr("font-size", 11).attr("class", "message-label").attr("data-line-number", String(msg.lineNumber)).attr("data-msg-index", String(step.messageIndex)).attr("data-step-index", String(i));
1673
+ if (tagKey && msgTagValue) {
1674
+ labelEl.attr(`data-tag-${tagKey}`, msgTagValue.toLowerCase());
1675
+ }
1676
+ labelEl.text(step.label);
1677
+ }
1678
+ }
1679
+ });
1680
+ const noteFill = isDark ? mix(palette.surface, palette.bg, 50) : mix(palette.bg, palette.surface, 15);
1681
+ const renderNoteElements = (els) => {
1682
+ for (const el of els) {
1683
+ if (isSequenceNote(el)) {
1684
+ const px = participantX.get(el.participantId);
1685
+ if (px === void 0) continue;
1686
+ const noteTopY = noteYMap.get(el);
1687
+ if (noteTopY === void 0) continue;
1688
+ const position = effectiveNotePosition(el);
1689
+ const isRight = position === "right";
1690
+ const afterSelfCall = isNoteAfterSelfCall(el);
1691
+ const maxW = noteEffectiveMaxW(
1692
+ el.participantId,
1693
+ position,
1694
+ afterSelfCall
1695
+ );
1696
+ const textWidth = noteTextWidth(maxW);
1697
+ const wrappedLines = wrapTextLines(el.text, textWidth, sNoteFontSize);
1698
+ const noteH = wrappedLines.length * sNoteLineH + sNotePadV * 2;
1699
+ const maxLineW = Math.max(
1700
+ ...wrappedLines.map((l) => measureText(l.text, sNoteFontSize))
1701
+ );
1702
+ const noteW = Math.min(
1703
+ maxW,
1704
+ Math.max(80, maxLineW + sNotePadH * 2 + sNoteFold)
1705
+ );
1706
+ const rightOffset = afterSelfCall && isRight ? sActivationWidth / 2 + sSelfCallWidth + sNoteGap : sActivationWidth + sNoteGap;
1707
+ const noteX = isRight ? px + rightOffset : px - sActivationWidth - sNoteGap - noteW;
1708
+ const noteG = svg.append("g").attr("class", "note").attr("data-note-toggle", "").attr("data-line-number", String(el.lineNumber)).attr("data-line-end", String(el.endLineNumber));
1709
+ noteG.append("path").attr(
1710
+ "d",
1711
+ [
1712
+ `M ${noteX} ${noteTopY}`,
1713
+ `L ${noteX + noteW - sNoteFold} ${noteTopY}`,
1714
+ `L ${noteX + noteW} ${noteTopY + sNoteFold}`,
1715
+ `L ${noteX + noteW} ${noteTopY + noteH}`,
1716
+ `L ${noteX} ${noteTopY + noteH}`,
1717
+ "Z"
1718
+ ].join(" ")
1719
+ ).attr("fill", noteFill).attr("stroke", palette.textMuted).attr("stroke-width", 0.75).attr("class", "note-box");
1720
+ noteG.append("path").attr(
1721
+ "d",
1722
+ [
1723
+ `M ${noteX + noteW - sNoteFold} ${noteTopY}`,
1724
+ `L ${noteX + noteW - sNoteFold} ${noteTopY + sNoteFold}`,
1725
+ `L ${noteX + noteW} ${noteTopY + sNoteFold}`
1726
+ ].join(" ")
1727
+ ).attr("fill", "none").attr("stroke", palette.textMuted).attr("stroke-width", 0.75).attr("class", "note-fold");
1728
+ const BULLET_BODY_INDENT = 10;
1729
+ wrappedLines.forEach((line, li) => {
1730
+ const textY = noteTopY + sNotePadV + (li + 1) * sNoteLineH - 3;
1731
+ const indent = line.kind === "plain" ? 0 : BULLET_BODY_INDENT;
1732
+ if (line.kind === "bullet-first") {
1733
+ noteG.append("text").attr("x", noteX + sNotePadH).attr("y", textY).attr("fill", palette.text).attr("font-size", sNoteFontSize).text("\u2022");
1734
+ }
1735
+ const textEl = noteG.append("text").attr("x", noteX + sNotePadH + indent).attr("y", textY).attr("fill", palette.text).attr("font-size", sNoteFontSize).attr("class", "note-text");
1736
+ renderInlineText(textEl, line.text, palette, sNoteFontSize);
1737
+ });
1738
+ } else if (isSequenceBlock(el)) {
1739
+ renderNoteElements(el.children);
1740
+ if (el.elseIfBranches) {
1741
+ for (const branch of el.elseIfBranches) {
1742
+ renderNoteElements(branch.children);
1743
+ }
1744
+ }
1745
+ renderNoteElements(el.elseChildren);
1746
+ }
1747
+ }
1748
+ };
1749
+ if (elements && elements.length > 0) {
1750
+ renderNoteElements(elements);
1751
+ }
1752
+ if (hasTagGroups) {
1753
+ const legendY = sTopMargin + titleOffset;
1754
+ const legendCallbacks = {};
1755
+ const legendG = svg.append("g").attr("class", "sequence-legend").attr("transform", `translate(0,${legendY})`);
1756
+ renderIntegratedLegend(legendG, {
1757
+ ...legendConfig,
1758
+ palette,
1759
+ isDark,
1760
+ width: svgWidth,
1761
+ activeGroup: activeTagGroup ?? null,
1762
+ controlsExpanded: false,
1763
+ callbacks: legendCallbacks
1764
+ });
1765
+ }
1766
+ }
1767
+ function buildNoteMessageMap(elements) {
1768
+ const map = /* @__PURE__ */ new Map();
1769
+ let lastMessageLine = -1;
1770
+ const walk = (els) => {
1771
+ for (const el of els) {
1772
+ if (isSequenceNote(el)) {
1773
+ if (lastMessageLine >= 0) {
1774
+ map.set(el.lineNumber, lastMessageLine);
1775
+ }
1776
+ } else if (isSequenceBlock(el)) {
1777
+ walk(el.children);
1778
+ if (el.elseIfBranches) {
1779
+ for (const branch of el.elseIfBranches) {
1780
+ walk(branch.children);
1781
+ }
1782
+ }
1783
+ walk(el.elseChildren);
1784
+ } else if (!isSequenceSection(el)) {
1785
+ lastMessageLine = el.lineNumber;
1786
+ }
1787
+ }
1788
+ };
1789
+ walk(elements);
1790
+ return map;
1791
+ }
1792
+ function renderParticipant(svg, participant, cx, cy, palette, isDark, color, tagAttr, solid, boxW = W, boxH = H, labelTextW = labelTextWidth(W), labelFontSize = LABEL_FONT_SIZE) {
1793
+ const g = svg.append("g").attr("transform", `translate(${cx}, ${cy})`).attr("class", "participant").attr("data-participant-id", participant.id);
1794
+ if (tagAttr) {
1795
+ g.attr(`data-tag-${tagAttr.key}`, tagAttr.value);
1796
+ }
1797
+ switch (participant.type) {
1798
+ case "actor":
1799
+ renderActorParticipant(g, palette, color, boxH);
1800
+ break;
1801
+ case "database":
1802
+ renderDatabaseParticipant(g, palette, isDark, color, solid, boxW, boxH);
1803
+ break;
1804
+ case "queue":
1805
+ renderQueueParticipant(g, palette, isDark, color, solid, boxW, boxH);
1806
+ break;
1807
+ case "cache":
1808
+ renderCacheParticipant(g, palette, isDark, color, solid, boxW, boxH);
1809
+ break;
1810
+ default:
1811
+ renderRectParticipant(g, palette, isDark, color, solid, boxW, boxH);
1812
+ break;
1813
+ }
1814
+ const isActor = participant.type === "actor";
1815
+ const labelLines = splitParticipantLabel(
1816
+ participant.label,
1817
+ labelTextW,
1818
+ labelFontSize
1819
+ );
1820
+ const fontSize = labelFontSize;
1821
+ const lineHeight = fontSize + 2;
1822
+ const labelFill = isActor ? palette.text : contrastText(
1823
+ fill(palette, isDark, color, solid),
1824
+ palette.textOnFillLight,
1825
+ palette.textOnFillDark
1826
+ );
1827
+ const textEl = g.append("text").attr("x", 0).attr("text-anchor", "middle").attr("fill", labelFill).attr("font-size", fontSize).attr("font-weight", 500);
1828
+ const maxLabelW = labelTextWidth(boxW);
1829
+ const truncLine = (text) => truncateText(text, fontSize, maxLabelW);
1830
+ if (labelLines.length === 1) {
1831
+ textEl.attr("y", isActor ? boxH + 14 : boxH / 2 + 5).text(truncLine(participant.label));
1832
+ } else {
1833
+ const totalHeight = labelLines.length * lineHeight;
1834
+ const baseY = isActor ? boxH + 14 - (labelLines.length - 1) * lineHeight / 2 : boxH / 2 + 5 - (totalHeight - lineHeight) / 2;
1835
+ labelLines.forEach((line, i) => {
1836
+ textEl.append("tspan").attr("x", 0).attr("dy", i === 0 ? `${baseY}px` : `${lineHeight}px`).text(truncLine(line));
1837
+ });
1838
+ }
1839
+ }
1840
+
1841
+ export {
1842
+ applyCollapseProjection,
1843
+ groupMessagesBySection,
1844
+ buildRenderSequence,
1845
+ computeActivations,
1846
+ applyPositionOverrides,
1847
+ applyGroupOrdering,
1848
+ renderSequenceDiagram,
1849
+ buildNoteMessageMap
1850
+ };
1851
+ //# sourceMappingURL=chunk-SRTU6HMQ.js.map