agentic-mermaid 0.5.3 → 0.5.4

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 (135) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/agent-core.d.ts +7 -7
  3. package/dist/agent-core.js +1 -1
  4. package/dist/agent.d.ts +7 -7
  5. package/dist/agent.js +1 -1
  6. package/dist/agentic-mermaid-mcp.js +1 -1
  7. package/dist/am.js +1 -1
  8. package/dist/browser-lazy/chunks/{agentic-producer-core-CC6OOLDW.js → agentic-producer-core-ECZ3CMZM.js} +1 -1
  9. package/dist/browser-lazy/chunks/{architecture-QUFVKYJR.js → architecture-H5LTMKQW.js} +6 -6
  10. package/dist/browser-lazy/chunks/{block-6J3Q63BO.js → block-566X6FNV.js} +5 -5
  11. package/dist/browser-lazy/chunks/{builtin-backends-7SOZZHPF.js → builtin-backends-VAFEZXKY.js} +6 -6
  12. package/dist/browser-lazy/chunks/{c4-SQVBZAKJ.js → c4-ZXFDLBFK.js} +5 -5
  13. package/dist/browser-lazy/chunks/{chunk-5X6MJX3H.js → chunk-2JQXRKBC.js} +1 -1
  14. package/dist/browser-lazy/chunks/{chunk-E2WMJZNM.js → chunk-37FZNMPR.js} +1 -1
  15. package/dist/browser-lazy/chunks/{chunk-TYZOZXUJ.js → chunk-3JTYTXA6.js} +6 -6
  16. package/dist/browser-lazy/chunks/{chunk-PQGPS2YV.js → chunk-4NILRBC7.js} +1 -1
  17. package/dist/browser-lazy/chunks/{chunk-AMJLVPUB.js → chunk-5LKPDHPC.js} +2 -2
  18. package/dist/browser-lazy/chunks/{chunk-BY2CPG6B.js → chunk-62MR3LWJ.js} +1 -1
  19. package/dist/browser-lazy/chunks/{chunk-J7FFAFQF.js → chunk-64JFHCJC.js} +1 -1
  20. package/dist/browser-lazy/chunks/chunk-6GPDLZFQ.js +1 -0
  21. package/dist/browser-lazy/chunks/{chunk-VWVZGQE2.js → chunk-6UOOATQR.js} +1 -1
  22. package/dist/browser-lazy/chunks/chunk-7TTFBJYA.js +1 -0
  23. package/dist/browser-lazy/chunks/chunk-7UFOFWBA.js +20 -0
  24. package/dist/browser-lazy/chunks/{chunk-5B2Z7575.js → chunk-A7V5VDKN.js} +1 -1
  25. package/dist/browser-lazy/chunks/chunk-CPO5P4L2.js +1 -0
  26. package/dist/browser-lazy/chunks/chunk-EIYLJ4FI.js +20 -0
  27. package/dist/browser-lazy/chunks/{chunk-X2UYKWKM.js → chunk-G4JBA7HU.js} +3 -3
  28. package/dist/browser-lazy/chunks/{chunk-2UIA2IME.js → chunk-IUI4DYC3.js} +1 -1
  29. package/dist/browser-lazy/chunks/{chunk-QA6GJQ4X.js → chunk-J57YRC2M.js} +1 -1
  30. package/dist/browser-lazy/chunks/{chunk-BU5LHXNJ.js → chunk-LBXXKLIR.js} +3 -3
  31. package/dist/browser-lazy/chunks/chunk-NKW2ZNCD.js +1 -0
  32. package/dist/browser-lazy/chunks/{chunk-ICC7HBJX.js → chunk-O34YYEQV.js} +1 -1
  33. package/dist/browser-lazy/chunks/{chunk-UL6NDWLL.js → chunk-OBI5U5XU.js} +1 -1
  34. package/dist/browser-lazy/chunks/{chunk-YCEICNM6.js → chunk-OFOS57WQ.js} +1 -1
  35. package/dist/browser-lazy/chunks/{chunk-OZ443IVJ.js → chunk-PSZEE64O.js} +7 -7
  36. package/dist/browser-lazy/chunks/{chunk-SZELX2EJ.js → chunk-PXTLV57R.js} +1 -1
  37. package/dist/browser-lazy/chunks/{chunk-HLWUNUCM.js → chunk-QVSZOF5M.js} +1 -1
  38. package/dist/browser-lazy/chunks/{chunk-2GPK4VFF.js → chunk-TT5GR5EJ.js} +1 -1
  39. package/dist/browser-lazy/chunks/{chunk-DF6765YX.js → chunk-V6I2VGNQ.js} +5 -5
  40. package/dist/browser-lazy/chunks/{chunk-CN7WTBWB.js → chunk-VRZKI33U.js} +1 -1
  41. package/dist/browser-lazy/chunks/{chunk-2SH76OTH.js → chunk-XHU3A432.js} +1 -1
  42. package/dist/browser-lazy/chunks/{chunk-NO7ZIVRU.js → chunk-YVNJDVQO.js} +1 -1
  43. package/dist/browser-lazy/chunks/chunk-Z7UHFVKN.js +6 -0
  44. package/dist/browser-lazy/chunks/{class-5QA4SCTS.js → class-XIFNVBFE.js} +8 -8
  45. package/dist/{zenuml/chunks/decode-BWERFDGK.js → browser-lazy/chunks/decode-5MFOG3AZ.js} +1 -1
  46. package/dist/browser-lazy/chunks/{elk.bundled-L4CADV5W.js → elk.bundled-RYWHIS5N.js} +8 -8
  47. package/dist/browser-lazy/chunks/er-VEUYJBGG.js +11 -0
  48. package/dist/browser-lazy/chunks/{eventmodeling-2BPLHWRN.js → eventmodeling-G7DITZX7.js} +10 -10
  49. package/dist/browser-lazy/chunks/{flowchart-NEIMZTB5.js → flowchart-SSFIU4EU.js} +1 -1
  50. package/dist/browser-lazy/chunks/{forest-implementation-AEP24AIP.js → forest-implementation-RWFF7XDV.js} +1 -1
  51. package/dist/browser-lazy/chunks/{gantt-RDPIFYAF.js → gantt-HQNVDX2B.js} +6 -6
  52. package/dist/browser-lazy/chunks/{gitgraph-N4Y5RYB7.js → gitgraph-Z5MN6M6L.js} +4 -4
  53. package/dist/browser-lazy/chunks/{ishikawa-LD3YBDJN.js → ishikawa-UEERNFQV.js} +2 -2
  54. package/dist/browser-lazy/chunks/{journey-6YQR5DJX.js → journey-3BEWWGB5.js} +6 -6
  55. package/dist/browser-lazy/chunks/{kanban-PLMJ7NBW.js → kanban-2WFNCWLB.js} +10 -10
  56. package/dist/browser-lazy/chunks/{mermaid-yaml-runtime-QVYX4EWK.js → mermaid-yaml-runtime-IK4ET4BT.js} +8 -8
  57. package/dist/browser-lazy/chunks/{mindmap-K2UBFO3Y.js → mindmap-R2C6SNYR.js} +4 -4
  58. package/dist/browser-lazy/chunks/{packet-CUW4QY6Y.js → packet-GMVCI5YZ.js} +3 -3
  59. package/dist/browser-lazy/chunks/{pie-7F7UUCG3.js → pie-WER45DKC.js} +7 -7
  60. package/dist/browser-lazy/chunks/{quadrant-TOONO2WC.js → quadrant-NCUPSFKN.js} +4 -4
  61. package/dist/browser-lazy/chunks/{radar-J6JVWVAX.js → radar-WLYS4YC5.js} +8 -8
  62. package/dist/browser-lazy/chunks/render-core-42UVWIPF.js +3 -0
  63. package/dist/browser-lazy/chunks/{requirement-CMAKDJPO.js → requirement-AK3NWMJ6.js} +7 -7
  64. package/dist/browser-lazy/chunks/{sankey-AWXQEP3F.js → sankey-C2DY6WVU.js} +4 -4
  65. package/dist/browser-lazy/chunks/{sequence-Q2RJRB4L.js → sequence-D4WJB44W.js} +1 -1
  66. package/dist/browser-lazy/chunks/{state-WRBFQEDX.js → state-YUQVESE7.js} +2 -2
  67. package/dist/browser-lazy/chunks/{timeline-D2KILFXM.js → timeline-BMBJJXWR.js} +4 -4
  68. package/dist/browser-lazy/chunks/{treemap-N3VYX5D4.js → treemap-B66XBZZ6.js} +3 -3
  69. package/dist/browser-lazy/chunks/{xychart-G73OGK66.js → xychart-HAVFROGT.js} +6 -6
  70. package/dist/browser-lazy/chunks/{zenuml-H4BXNYXR.js → zenuml-62RLYFWP.js} +7 -7
  71. package/dist/browser-lazy/index.js +1 -1
  72. package/dist/browser.global.js +507 -507
  73. package/dist/{chunk-DQDKA5ND.js → chunk-2DNGDTJD.js} +2 -2
  74. package/dist/{chunk-GVCHLSHH.js → chunk-4F2UGYTM.js} +2 -2
  75. package/dist/{chunk-H3NCS2XZ.js → chunk-7XYB2LNC.js} +2 -2
  76. package/dist/chunk-DOFB572I.js +58 -0
  77. package/dist/chunk-EHJI3QYE.js +52 -0
  78. package/dist/{chunk-UA234O4M.js → chunk-HINRNKPO.js} +2 -2
  79. package/dist/{chunk-JZOJ4YGS.js → chunk-KXMANAST.js} +33 -33
  80. package/dist/{chunk-7CRDX2QR.js → chunk-U4MT3RRE.js} +2 -2
  81. package/dist/{chunk-NKNFOREZ.js → chunk-WYIB6BUR.js} +2 -2
  82. package/dist/{cli-YGGTJZH7.js → cli-ZYIDBYNS.js} +2 -2
  83. package/dist/{index-EeXqJXr5.d.ts → index-Bvhprdxz.d.ts} +3 -3
  84. package/dist/index.d.ts +4 -4
  85. package/dist/index.js +1 -1
  86. package/dist/{mcp-cli-63DYXTVD.js → mcp-cli-YVDCORWA.js} +2 -2
  87. package/dist/{paint-certification-6rwQjIv_.d.ts → paint-certification-BoLyr006.d.ts} +2 -2
  88. package/dist/{server-5NEOHOFS.js → server-4JGAVXR3.js} +2 -2
  89. package/dist/{svg-styles-BdnoM7AT.d.ts → svg-styles-BnCoXyYe.d.ts} +1 -1
  90. package/dist/svg-styles.d.ts +1 -1
  91. package/dist/svg-styles.js +1 -1
  92. package/dist/svg.d.ts +4 -4
  93. package/dist/svg.js +1 -1
  94. package/dist/{types-BcS52Mjt.d.ts → types-CLVJCaH2.d.ts} +1 -1
  95. package/dist/zenuml/chunks/{appearance-UOQ5KA6O.js → appearance-5RM5MVM2.js} +1 -1
  96. package/dist/zenuml/chunks/{builtin-backends-KDKE7YHO.js → builtin-backends-UTNWL4N3.js} +11 -11
  97. package/dist/zenuml/chunks/{chunk-QWX77U7G.js → chunk-3A6S6GNB.js} +2 -2
  98. package/dist/zenuml/chunks/{chunk-OXQWRSBM.js → chunk-55WS466K.js} +11 -11
  99. package/dist/zenuml/chunks/chunk-6J4BGPB2.js +29 -0
  100. package/dist/zenuml/chunks/chunk-CNLL4BGF.js +1 -0
  101. package/dist/zenuml/chunks/{chunk-RZ6XK5CD.js → chunk-IARQ24W3.js} +13 -13
  102. package/dist/zenuml/chunks/{chunk-42DXZ5C6.js → chunk-ZNZRIISS.js} +2 -2
  103. package/dist/{browser-lazy/chunks/decode-63UIZGD2.js → zenuml/chunks/decode-LDNNXEAO.js} +1 -1
  104. package/dist/zenuml/chunks/{mermaid-yaml-runtime-KZVU74WU.js → mermaid-yaml-runtime-A5CNJ3IE.js} +8 -8
  105. package/dist/zenuml/chunks/render-core-ECIWU5ZS.js +3 -0
  106. package/dist/zenuml/chunks/{zenuml-EA2ZFRUX.js → zenuml-N3LZMB2G.js} +8 -8
  107. package/dist/zenuml.d.ts +2 -2
  108. package/dist/zenuml.js +1 -1
  109. package/docs/MCP-DIRECTORY-LISTINGS.md +81 -12
  110. package/docs/api.md +1 -1
  111. package/package.json +1 -1
  112. package/server.json +2 -2
  113. package/dist/browser-lazy/chunks/chunk-4LHYF3BS.js +0 -1
  114. package/dist/browser-lazy/chunks/chunk-FAIMVOX5.js +0 -6
  115. package/dist/browser-lazy/chunks/chunk-GVOEAY52.js +0 -1
  116. package/dist/browser-lazy/chunks/chunk-J35HAQQF.js +0 -20
  117. package/dist/browser-lazy/chunks/chunk-RIVTHZAQ.js +0 -1
  118. package/dist/browser-lazy/chunks/chunk-Z3FDIVLN.js +0 -20
  119. package/dist/browser-lazy/chunks/er-7ZSKGN7Y.js +0 -11
  120. package/dist/browser-lazy/chunks/render-core-BZOM3K7D.js +0 -3
  121. package/dist/chunk-EHCMJUMD.js +0 -52
  122. package/dist/chunk-OMY6NRQD.js +0 -58
  123. package/dist/zenuml/chunks/chunk-7TVYPTDW.js +0 -1
  124. package/dist/zenuml/chunks/chunk-RLJEI7YN.js +0 -29
  125. package/dist/zenuml/chunks/render-core-V5RQ737O.js +0 -3
  126. /package/dist/browser-lazy/chunks/{chunk-5FQ534HP.js → chunk-BMZ24VPS.js} +0 -0
  127. /package/dist/browser-lazy/chunks/{chunk-2I4UPL7Q.js → chunk-D6MQ7QSU.js} +0 -0
  128. /package/dist/browser-lazy/chunks/{chunk-CQE4HQEW.js → chunk-HJVO5VC3.js} +0 -0
  129. /package/dist/browser-lazy/chunks/{chunk-LH7HUDKW.js → chunk-L4UC3KGS.js} +0 -0
  130. /package/dist/browser-lazy/chunks/{chunk-NMQQMRIR.js → chunk-MFTQWHUB.js} +0 -0
  131. /package/dist/browser-lazy/chunks/{chunk-N5ELX7LR.js → chunk-PJJSDGLB.js} +0 -0
  132. /package/dist/browser-lazy/chunks/{chunk-CSFUKSU6.js → chunk-QCU5G5PZ.js} +0 -0
  133. /package/dist/browser-lazy/chunks/{chunk-VQYYGAXP.js → chunk-TLFX3U6S.js} +0 -0
  134. /package/dist/browser-lazy/chunks/{chunk-5UVGUSD6.js → chunk-YHMTSXIR.js} +0 -0
  135. /package/dist/zenuml/chunks/{chunk-EVPSMEKN.js → chunk-GC7IPQ5P.js} +0 -0
package/docs/api.md CHANGED
@@ -56,7 +56,7 @@ The resolved-scene API's separate `marker-mid` limitation still applies.
56
56
  ## Versions
57
57
 
58
58
  <!-- BEGIN GENERATED: api-versions -->
59
- This reference describes source version **0.5.3**. The latest release recorded in the [changelog](../CHANGELOG.md) is **0.5.3** (2026-10-29). [Read that version's reference](https://github.com/adewale/agentic-mermaid/blob/v0.5.3/docs/api.md). Changes under **Unreleased**, including new exports, are not part of that recorded release.
59
+ This reference describes source version **0.5.4**. The latest release recorded in the [changelog](../CHANGELOG.md) is **0.5.4** (2026-10-30). [Read that version's reference](https://github.com/adewale/agentic-mermaid/blob/v0.5.4/docs/api.md). Changes under **Unreleased**, including new exports, are not part of that recorded release.
60
60
  <!-- END GENERATED: api-versions -->
61
61
 
62
62
  ```bash
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "agentic-mermaid",
3
3
  "mcpName": "io.github.adewale/agentic-mermaid",
4
- "version": "0.5.3",
4
+ "version": "0.5.4",
5
5
  "license": "MIT",
6
6
  "description": "Agentic Mermaid: render, verify, and safely edit Mermaid diagrams as ASCII, PNG, SVG, or structured agent workflows — with composable styles (hand-drawn, excalidraw, watercolor, or your own as JSON).",
7
7
  "type": "module",
package/server.json CHANGED
@@ -7,13 +7,13 @@
7
7
  "url": "https://github.com/adewale/agentic-mermaid",
8
8
  "source": "github"
9
9
  },
10
- "version": "0.5.3",
10
+ "version": "0.5.4",
11
11
  "websiteUrl": "https://agentic-mermaid.dev/",
12
12
  "packages": [
13
13
  {
14
14
  "registryType": "npm",
15
15
  "identifier": "agentic-mermaid",
16
- "version": "0.5.3",
16
+ "version": "0.5.4",
17
17
  "runtimeHint": "npx",
18
18
  "runtimeArguments": [
19
19
  {
@@ -1 +0,0 @@
1
- import{a as e,b as t}from"./chunk-CQE4HQEW.js";import{b as n,c as i}from"./chunk-LH7HUDKW.js";import{d as r}from"./chunk-5FQ534HP.js";import{a as a}from"./chunk-BY2CPG6B.js";import{a as o,b as s,c as l,d as h,f as u,g as d,h as x,i as y,j as c}from"./chunk-SZELX2EJ.js";import{i as f}from"./chunk-AMJLVPUB.js";import{l as g,o as p,p as m,q as M,r as b,s as $,t as w,x as k}from"./chunk-HLWUNUCM.js";import{r as v}from"./chunk-TYZOZXUJ.js";import{c as S,d as C,h as P}from"./chunk-NO7ZIVRU.js";import{C as N,Ma as W,Na as L,Q as E,Qa as I,R as B,Ua as R,Wa as H,ca as A,da as F,ga as O,t as z}from"./chunk-Z3FDIVLN.js";function j(e,t){return"invisible"===e.style?[]:e.points.slice(1).flatMap((n,i)=>{let r=e.points[i],a=.01>=Math.abs(r.y-n.y);if(!a&&Math.abs(r.x-n.x)>.01)return[];let o=a?r.x:r.y,s=a?n.x:n.y;if(.01>=Math.abs(s-o))return[];let l=a?r.y:r.x;return[{edgeIndex:t,horizontal:a,cross:l,bucket:Math.floor(l/.01),lo:Math.min(o,s),hi:Math.max(o,s),sign:Math.sign(s-o)}]})}function Y(e){let t=e.flatMap(j).sort((e,t)=>e.lo-t.lo||e.edgeIndex-t.edgeIndex),n=new Map,i=new Set;for(let e of t){for(let t=-1;t<=1;t++){let r=`${e.horizontal}:${e.bucket+t}`,a=(n.get(r)??[]).filter(t=>t.hi-e.lo>.01);for(let t of(n.set(r,a),a))t.edgeIndex===e.edgeIndex||t.sign===e.sign||Math.abs(t.cross-e.cross)>.01||Math.min(e.hi,t.hi)-e.lo<=.01||i.add(`${Math.min(e.edgeIndex,t.edgeIndex)}:${Math.max(e.edgeIndex,t.edgeIndex)}`)}let t=`${e.horizontal}:${e.bucket}`;n.get(t).push(e)}return i.size}function Q(e,t){let n=j(e,0),i=[];if(0===n.length)return i;let r=Z(e);for(let e of t){let t=Z(e);t.x0>r.x1+.01||t.x1<r.x0-.01||t.y0>r.y1+.01||t.y1<r.y0-.01||j(e,1).some(e=>n.some(t=>t.horizontal===e.horizontal&&t.sign!==e.sign&&.01>=Math.abs(t.cross-e.cross)&&Math.min(t.hi,e.hi)-Math.max(t.lo,e.lo)>.01))&&i.push(e)}return i}function Z(e){let t=1/0,n=1/0,i=-1/0,r=-1/0;for(let a of e.points)t=Math.min(t,a.x),i=Math.max(i,a.x),n=Math.min(n,a.y),r=Math.max(r,a.y);return{x0:t,y0:n,x1:i,y1:r}}function q(e,t=!1){let n=C.width,i=t?n:C.height,r=e??"var(--_arrow)",a=`${e?`-${_(e)}`:""}${t?"-fixed":""}`,o={fill:r,stroke:r,strokeWidth:String(C.strokeWidth),strokeLinejoin:"round"};return[v(`arrowhead${a}`,{width:n,height:i},"end",o,t?"userSpaceOnUse":void 0),v(`arrowhead-start${a}`,{width:n,height:i},"start",o,t?"userSpaceOnUse":void 0)]}function V(e,t=!1){let n=C.width,i=`${e?`-${_(e)}`:""}${t?"-fixed":""}`,r=e??"var(--_arrow)",a={shape:"circle",size:{width:n,height:n},...t?{units:"userSpaceOnUse"}:{},orient:"auto",geometry:{kind:"circle",cx:n/2,cy:n/2,r:n/2-.75},paint:{fill:"none",stroke:r,strokeWidth:"1"}};return[{...a,id:`circlehead${i}`,ref:{x:n-.5,y:n/2}},{...a,id:`circlehead-start${i}`,ref:{x:.5,y:n/2}}]}function U(e,t=!1){let n=C.width,i=`${e?`-${_(e)}`:""}${t?"-fixed":""}`,r=e??"var(--_arrow)",a=n-1.25,o={shape:"cross",size:{width:n,height:n},...t?{units:"userSpaceOnUse"}:{},orient:"auto",geometry:{kind:"compound",children:[{kind:"line",x1:1.25,y1:1.25,x2:a,y2:a},{kind:"line",x1:1.25,y1:a,x2:a,y2:1.25}]},paint:{stroke:r,strokeWidth:String(1.25),strokeLinecap:"round"}};return[{...o,id:`crosshead${i}`,ref:{x:a+.625,y:n/2}},{...o,id:`crosshead-start${i}`,ref:{x:.625,y:n/2}}]}function J(e,t,n,i){let r=[...q()];for(let t of(n&&r.push(...V()),i&&r.push(...U()),e))r.push(...q(t)),n&&r.push(...V(t)),i&&r.push(...U(t));for(let e of t)r.push(...q(e,!0)),n&&r.push(...V(e,!0)),i&&r.push(...U(e,!0));return r}function T(e){return"circle"===e?"circlehead":"cross"===e?"crosshead":"arrowhead"}function _(e){if(/^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(e))return`23${e.slice(1)}`;if(/^[a-z]+$/i.test(e))return e;let t=`color-u-${Array.from(e,e=>e.codePointAt(0).toString(16)).join("-")}`;return t.length<=233?t:`color-h-${f(e).slice(8)}`}var X=a(J(new Set,new Set([void 0]),!0,!0));function D(e,t){let n=e.inlineStyle?.["stroke-width"]?"-fixed":"",i=(t.lineWidth??1)*("thick"===e.style?2:1);return{start:e.hasArrowStart?X(`${T(e.startMarker??"arrow")}-start${n}`,i,"start"):0,end:e.hasArrowEnd?X(`${T(e.endMarker??"arrow")}${n}`,i,"end"):0}}function G(e,t){return e.curve?function(e){let t=e[0],n=`M ${t.x} ${t.y}`,i=[];for(let t=1;t<e.length;t++){let r=e[t-1],a=e[t],o=(r.x+a.x)/2;n+=` C ${o} ${r.y}, ${o} ${a.y}, ${a.x} ${a.y}`,i.push({kind:"cubic",control1:{x:o,y:r.y},control2:{x:o,y:a.y},end:a})}return A(n,t,i)}(e.points):(t.edgeBendRadius??0)>0?F(e.points,t.edgeBendRadius,{terminalClearance:D(e,t)}):void 0}function K(e,t){if("invisible"===e.style||e.points.length<2||!e.hasArrowStart&&!e.hasArrowEnd)return[];let n=e.inlineStyle?.stroke??t.edgeStrokeColor,i=!!e.inlineStyle?.["stroke-width"],r=J(new Set(n?[n]:[]),new Set(i?[n]:[]),"circle"===e.startMarker||"circle"===e.endMarker,"cross"===e.startMarker||"cross"===e.endMarker),a=`${n?`-${_(n)}`:""}${i?"-fixed":""}`,o=e.hasArrowStart?r.find(t=>t.id===`${T(e.startMarker??"arrow")}-start${a}`):void 0,s=e.hasArrowEnd?r.find(t=>t.id===`${T(e.endMarker??"arrow")}${a}`):void 0,l=G(e,t),h=l?.geometry??{kind:"polyline",points:e.points};return I({route:{geometry:h,closed:!1,contours:l?.contours??O(h,!1)},stroke:{width:e.inlineStyle?.["stroke-width"]??String((t.lineWidth??1)*("thick"===e.style?2:1))},markers:{start:o,mid:[],end:s}})}var ee=new WeakMap,et=e=>({fill:e.fill,stroke:e.stroke,strokeWidth:e.strokeWidth}),en=e=>({stroke:e.stroke,strokeWidth:e.strokeWidth}),ei=(e,t)=>({geometry:{kind:"polygon",points:e},paint:et(t),routing:{kind:"polygon",points:e}}),er=(e,t,n,i={})=>({geometry:{kind:"path",d:t},paint:{...et(n),fill:"none"===i.fill?"none":n.fill},routing:{kind:"envelope",x:e.x,y:e.y,width:e.width,height:e.height,reason:i.reason??"closed curved path uses a conservative routing envelope"}});function ea(e,t,n){var i,r,a,o;let s=function(e,t){var n,i,r,a;let{x:o,y:s,width:l,height:h}=e,u=o+l,d=s+h,x=o+l/2,y=s+h/2;switch(e.semanticShape){case"bang":return ei(Array.from({length:16},(e,t)=>{let n=-Math.PI/2+t*Math.PI/8,i=t%2==0?1:.62;return{x:x+Math.cos(n)*l/2*i,y:y+Math.sin(n)*h/2*i}}),t);case"notch-rect":case"tag-rect":return ei([{x:o+10,y:s},{x:u,y:s},{x:u,y:d},{x:o,y:d},{x:o,y:s+10}],t);case"cloud":return er(e,`M${o+.18*l} ${d}C${o-4} ${d} ${o-4} ${y} ${o+.12*l} ${y}C${o+.08*l} ${s+.15*h} ${o+.38*l} ${s-4} ${o+.48*l} ${s+.18*h}C${o+.65*l} ${s-5} ${u} ${s+.16*h} ${o+.88*l} ${y}C${u+5} ${y} ${u+5} ${d} ${o+.72*l} ${d}Z`,t);case"hourglass":return ei([{x:o,y:s},{x:u,y:s},{x:o+.62*l,y:y},{x:u,y:d},{x:o,y:d},{x:o+.38*l,y:y}],t);case"bolt":return ei([{x:o+.55*l,y:s},{x:o+.25*l,y:y},{x:o+.48*l,y:y},{x:o+.35*l,y:d},{x:o+.78*l,y:s+.4*h},{x:o+.55*l,y:s+.4*h}],t);case"brace":return ep(e,`M${u} ${s}C${o+.4*l} ${s} ${o+.7*l} ${y} ${o} ${y}C${o+.7*l} ${y} ${o+.4*l} ${d} ${u} ${d}`,t);case"brace-r":return ep(e,`M${o} ${s}C${o+.6*l} ${s} ${o+.3*l} ${y} ${u} ${y}C${o+.3*l} ${y} ${o+.6*l} ${d} ${o} ${d}`,t);case"braces":return ep(e,`M${o+.25*l} ${s}C${o} ${s} ${o+.15*l} ${y} ${o} ${y}C${o+.15*l} ${y} ${o} ${d} ${o+.25*l} ${d}M${o+.75*l} ${s}C${u} ${s} ${o+.85*l} ${y} ${u} ${y}C${o+.85*l} ${y} ${u} ${d} ${o+.75*l} ${d}`,t);case"datastore":return ep(e,`M${o+8} ${s}H${u}V${d}H${o+8}M${o+8} ${s}C${o-2} ${s+.2*h} ${o-2} ${d-.2*h} ${o+8} ${d}`,t);case"delay":return er(e,`M${o} ${s}H${u-h/2}A${h/2} ${h/2} 0 0 1 ${u-h/2} ${d}H${o}Z`,t);case"h-cyl":return er(e,`M${o+10} ${s}H${u-10}A10 ${h/2} 0 0 1 ${u-10} ${d}H${o+10}A10 ${h/2} 0 0 1 ${o+10} ${s}Z M${u-10} ${s}A10 ${h/2} 0 0 0 ${u-10} ${d}`,t);case"lin-cyl":return er(e,`M${o} ${s+8}A${l/2} 8 0 0 1 ${u} ${s+8}V${d-8}A${l/2} 8 0 0 1 ${o} ${d-8}Z M${o} ${s+8}A${l/2} 8 0 0 0 ${u} ${s+8}M${o} ${d-16}A${l/2} 8 0 0 0 ${u} ${d-16}`,t);case"curv-trap":return er(e,`M${o+12} ${s}Q${x} ${s+8} ${u-12} ${s}L${u} ${d}Q${x} ${d-8} ${o} ${d}Z`,t);case"div-rect":return em(e,`M${o} ${s}H${u}V${d}H${o}ZM${o} ${y}H${u}`,t);case"doc":return er(e,`M${o} ${s}H${u}V${d-8}Q${o+.75*l} ${d+2} ${x} ${d-8}Q${o+.25*l} ${d-18} ${o} ${d-8}Z`,t);case"tri":return ei([{x:x,y:s},{x:u,y:d},{x:o,y:d}],t);case"fork":return{geometry:{kind:"rect",x:o,y:n=y-4,width:l,height:8},paint:{fill:i=t.stroke,stroke:i,strokeWidth:t.strokeWidth},routing:{kind:"rect",x:o,y:n,width:l,height:8}};case"win-pane":return em(e,`M${o} ${s}H${u}V${d}H${o}ZM${o+.28*l} ${s}V${d}M${o} ${s+.32*h}H${u}`,t);case"f-circ":return{geometry:{kind:"circle",cx:x,cy:y,r:r=Math.min(l,h)/2},paint:{fill:a=t.stroke,stroke:a,strokeWidth:t.strokeWidth},routing:{kind:"ellipse",cx:x,cy:y,rx:r,ry:r}};case"lin-doc":return er(e,`M${o} ${s}H${u}V${d-8}Q${o+.75*l} ${d+2} ${x} ${d-8}Q${o+.25*l} ${d-18} ${o} ${d-8}ZM${o+8} ${s+8}H${u-8}`,t);case"lin-rect":return em(e,`M${o} ${s}H${u}V${d}H${o}ZM${o+6} ${s}V${d}M${u-6} ${s}V${d}`,t);case"notch-pent":return ei([{x:o,y:s},{x:u-10,y:s},{x:u,y:y},{x:u-10,y:d},{x:o,y:d},{x:o+8,y:y}],t);case"flip-tri":return ei([{x:o,y:s},{x:u,y:s},{x:x,y:d}],t);case"docs":return er(e,`M${o+8} ${s}H${u}V${d-8}Q${o+.7*l} ${d} ${o+.45*l} ${d-8}Q${o+.22*l} ${d-16} ${o+8} ${d-8}ZM${o} ${s+8}H${o+8}M${o} ${s+8}V${d}`,t);case"st-rect":return er(e,`M${o+8} ${s}H${u}V${d-8}H${o+8}ZM${o} ${s+8}H${u-8}V${d}H${o}Z`,t);case"flag":return er(e,`M${o} ${s+6}Q${o+.25*l} ${s-4} ${x} ${s+6}Q${o+.75*l} ${s+16} ${u} ${s+6}V${d-6}Q${o+.75*l} ${d+4} ${x} ${d-6}Q${o+.25*l} ${d-16} ${o} ${d-6}Z`,t);case"sm-circ":return ec(x,y,.22*Math.min(l,h),t);case"cross-circ":{let n=er(e,`M${x} ${s}A${l/2} ${h/2} 0 1 1 ${x-.01} ${s}M${o+.28*l} ${s+.28*h}L${o+.72*l} ${s+.72*h}M${o+.72*l} ${s+.28*h}L${o+.28*l} ${s+.72*h}`,t);return n.routing={kind:"ellipse",cx:x,cy:y,rx:l/2,ry:h/2},n}case"bow-rect":return er(e,`M${o} ${s}Q${o+12} ${y} ${o} ${d}H${u}Q${u-12} ${y} ${u} ${s}Z`,t);case"tag-doc":return er(e,`M${o+10} ${s}H${u}V${d-8}Q${o+.7*l} ${d} ${x} ${d-8}Q${o+.25*l} ${d-16} ${o} ${d-8}V${s+10}ZM${o} ${s+10}L${o+10} ${s}`,t);case"text":return{geometry:{kind:"path",d:`M${o} ${s}`},paint:{fill:"none",stroke:"none"},routing:{kind:"none",reason:"text blocks have no painted enclosure"}};default:return null}}(e,t);if(s)return s;let{x:l,y:h,width:u,height:d}=e,x=l+u/2,y=h+d/2;switch(e.shape){case"state-note":{let e=Math.min(12,u/6,d/4);return ei([{x:l,y:h},{x:l+u-e,y:h},{x:l+u,y:h+e},{x:l+u,y:h+d},{x:l,y:h+d}],t)}case"diamond":case"state-choice":return ei([{x:x,y:y-d/2},{x:x+u/2,y:y},{x:x,y:y+d/2},{x:x-u/2,y:y}],t);case"stadium":{let e=d/2;return{geometry:{kind:"rect",x:l,y:h,width:u,height:d,rx:e,ry:e},paint:et(t),routing:{kind:"stadium",cx:x,cy:y,halfWidth:u/2,radius:e}}}case"ellipse":return{geometry:{kind:"ellipse",cx:x,cy:y,rx:u/2,ry:d/2},paint:et(t),routing:{kind:"ellipse",cx:x,cy:y,rx:u/2,ry:d/2}};case"circle":case"state-history":return ec(x,y,Math.min(u,d)/2,t);case"doublecircle":let c;return c=Math.max(0,(i=Math.min(u,d)/2)-5),{geometry:{kind:"compound",children:[{kind:"circle",cx:x,cy:y,r:i},{kind:"circle",cx:x,cy:y,r:c}]},paint:et(t),routing:{kind:"ellipse",cx:x,cy:y,rx:i,ry:i}};case"hexagon":{let e=d/4;return ei([{x:l+e,y:h},{x:l+u-e,y:h},{x:l+u,y:y},{x:l+u-e,y:h+d},{x:l+e,y:h+d},{x:l,y:y}],t)}case"cylinder":let f,g,p;return f=l+u/2,{geometry:{kind:"compound",children:[{kind:"rect",x:l,y:g=h+7,width:u,height:p=d-14},{kind:"line",x1:l,y1:g,x2:l,y2:g+p},{kind:"line",x1:l+u,y1:g,x2:l+u,y2:g+p},{kind:"ellipse",cx:f,cy:h+d-7,rx:u/2,ry:7},{kind:"ellipse",cx:f,cy:g,rx:u/2,ry:7}]},paint:et(t),childPaints:[{fill:t.fill,stroke:"none"},en(t),en(t),et(t),et(t)],routing:{kind:"cylinder",cx:f,y:h,width:u,height:d,capRadiusY:7}};case"asymmetric":return ei([{x:l+12,y:h},{x:l+u,y:h},{x:l+u,y:h+d},{x:l+12,y:h+d},{x:l,y:y}],t);case"trapezoid":{let e=.15*u;return ei([{x:l+e,y:h},{x:l+u-e,y:h},{x:l+u,y:h+d},{x:l,y:h+d}],t)}case"trapezoid-alt":{let e=.15*u;return ei([{x:l,y:h},{x:l+u,y:h},{x:l+u-e,y:h+d},{x:l+e,y:h+d}],t)}case"lean-r":{let e=.15*u;return ei([{x:l+e,y:h},{x:l+u,y:h},{x:l+u-e,y:h+d},{x:l,y:h+d}],t)}case"lean-l":{let e=.15*u;return ei([{x:l,y:h},{x:l+u-e,y:h},{x:l+u,y:h+d},{x:l+e,y:h+d}],t)}case"subroutine":return{geometry:{kind:"compound",children:[{kind:"rect",x:l,y:h,width:u,height:d,rx:r=n??0,ry:r},{kind:"line",x1:l+8,y1:h,x2:l+8,y2:h+d},{kind:"line",x1:l+u-8,y1:h,x2:l+u-8,y2:h+d}]},paint:et(t),childPaints:[et(t),en(t),en(t)],routing:{kind:"rect",x:l,y:h,width:u,height:d}};case"state-start":return{geometry:{kind:"circle",cx:x,cy:y,r:a=Math.max(0,Math.min(u,d)/2-2)},paint:{fill:"var(--_text)",stroke:"none"},routing:{kind:"ellipse",cx:x,cy:y,rx:a,ry:a}};case"state-end":let m;return m=Math.max(0,(o=Math.max(0,Math.min(u,d)/2-2))-4),{geometry:{kind:"compound",children:[{kind:"circle",cx:x,cy:y,r:o},{kind:"circle",cx:x,cy:y,r:m}]},paint:{fill:"var(--_text)",stroke:"var(--_text)"},childPaints:[{fill:"none",stroke:"var(--_text)",strokeWidth:String(2*S.innerBox)},{fill:"var(--_text)",stroke:"none"}],routing:{kind:"ellipse",cx:x,cy:y,rx:o,ry:o}};case"state-fork":case"state-join":let M;return M=Math.min(u,d)/2,{geometry:{kind:"rect",x:l,y:h,width:u,height:d,rx:M,ry:M},paint:{fill:"var(--_text)",stroke:"none"},routing:{kind:"rect",x:l,y:h,width:u,height:d}};case"rounded":return ey(l,h,u,d,t,n??6);default:return ey(l,h,u,d,t,n??0)}}function eo(e){let t,n,i=ee.get(e);if(i&&i.x===e.x&&i.y===e.y&&i.width===e.width&&i.height===e.height&&i.shape===e.shape&&i.semanticShape===e.semanticShape)return i.profile;let r=ea(e,{fill:"",stroke:"",strokeWidth:""}).routing,a=(t=e.x+e.width/2,n=e.y+e.height/2,{N:{x:t,y:e.y},E:{x:e.x+e.width,y:n},S:{x:t,y:e.y+e.height},W:{x:e.x,y:n}}),o={};for(let e of["N","E","S","W"]){let t=function(e,t){let n=ed(e);if(!n)return null;let i="E"===t||"W"===t?"x":"y",r="x"===i?n.y+n.height/2:n.x+n.width/2;return ex(e,i,r,"E"===t||"S"===t)}(r,e)??a[e];if("none"===r.kind){o[e]={kind:"none",preferred:t};continue}if("envelope"===r.kind){let[n,i]=eh(r,e);o[e]={kind:"envelope",lo:n,hi:i,preferred:t};continue}let n=function(e,t,n){let[i,r]=eh(t,n);if("rect"===t.kind)return eu(i,r,4);if("stadium"===t.kind&&("N"===n||"S"===n))return eu(t.cx-(t.halfWidth-t.radius),t.cx+(t.halfWidth-t.radius),2);if("cylinder"===t.kind&&("E"===n||"W"===n))return eu(t.y+t.capRadiusY,t.y+t.height-t.capRadiusY,2);if("polygon"!==t.kind)return null;let a=ed(t),o="E"===n||"W"===n?"x":"y",s="x"===o?"E"===n?a.x+a.width:a.x:"S"===n?a.y+a.height:a.y,l=[];for(let e=0;e<t.points.length;e++){let n=t.points[e],i=t.points[(e+1)%t.points.length];if(Math.abs(n[o]-s)>1e-9||Math.abs(i[o]-s)>1e-9)continue;let r="x"===o?n.y:n.x,a="x"===o?i.y:i.x;l.push([Math.min(r,a),Math.max(r,a)])}if(l.length>0){let e=l.sort((e,t)=>t[1]-t[0]-(e[1]-e[0]))[0];return eu(e[0],e[1],2)}if(4===t.points.length&&function(e,t){let n=t.x+t.width/2,i=t.y+t.height/2,r=[{x:n,y:t.y},{x:t.x+t.width,y:i},{x:n,y:t.y+t.height},{x:t.x,y:i}];return e.every(e=>r.some(t=>1e-8>Math.abs(e.x-t.x)&&1e-8>Math.abs(e.y-t.y)))}(t.points,a)){let e=r-i;return eu(i,r,e<=40?e/4:10)}return null}(0,r,e);o[e]=n?{kind:"dynamic",...n,preferred:t}:{kind:"port",point:t,preferred:t}}let s={boundary:r,sides:o};return ee.set(e,{x:e.x,y:e.y,width:e.width,height:e.height,shape:e.shape,semanticShape:e.semanticShape,profile:s}),s}function es(e){let t=eo(e);return{N:{...t.sides.N.preferred},E:{...t.sides.E.preferred},S:{...t.sides.S.preferred},W:{...t.sides.W.preferred}}}function el(e,t,n){return ex(e,"E"===t||"W"===t?"x":"y",n,"E"===t||"S"===t)}function eh(e,t){let n=ed(e);return"E"===t||"W"===t?[n.y,n.y+n.height]:[n.x,n.x+n.width]}function eu(e,t,n){return t-e>2*n?{lo:e+n,hi:t-n}:null}function ed(e){switch(e.kind){case"rect":case"envelope":return{x:e.x,y:e.y,width:e.width,height:e.height};case"ellipse":return{x:e.cx-e.rx,y:e.cy-e.ry,width:2*e.rx,height:2*e.ry};case"stadium":return{x:e.cx-e.halfWidth,y:e.cy-e.radius,width:2*e.halfWidth,height:2*e.radius};case"cylinder":return{x:e.cx-e.width/2,y:e.y,width:e.width,height:e.height};case"polygon":{if(0===e.points.length)return null;let t=e.points.map(e=>e.x),n=e.points.map(e=>e.y),i=Math.min(...t),r=Math.min(...n);return{x:i,y:r,width:Math.max(...t)-i,height:Math.max(...n)-r}}case"none":return null}}function ex(e,t,n,i){let r=e=>"x"===t?{x:e,y:n}:{x:n,y:e};switch(e.kind){case"rect":case"envelope":{let a="x"===t?e.y:e.x,o=a+("x"===t?e.height:e.width);return n<a-1e-9||n>o+1e-9?null:r("x"===t?i?e.x+e.width:e.x:i?e.y+e.height:e.y)}case"ellipse":{let a="x"===t?e.cy:e.cx,o="x"===t?e.ry:e.rx,s="x"===t?e.cx:e.cy,l="x"===t?e.rx:e.ry;if(o<=0||l<=0)return null;let h=(n-a)/o;return Math.abs(h)>1+1e-9?null:r(s+(i?1:-1)*l*Math.sqrt(Math.max(0,1-h*h)))}case"stadium":{if("x"===t){let t=n-e.cy;if(Math.abs(t)>e.radius+1e-9)return null;let a=e.halfWidth-e.radius+Math.sqrt(Math.max(0,e.radius**2-t**2));return r(e.cx+(i?a:-a))}let a=Math.abs(n-e.cx);if(a>e.halfWidth+1e-9)return null;let o=Math.max(0,a-(e.halfWidth-e.radius));return r(e.cy+(i?1:-1)*Math.sqrt(Math.max(0,e.radius**2-o**2)))}case"cylinder":{let a=e.width/2,o=e.y+e.capRadiusY,s=e.y+e.height-e.capRadiusY;if("x"===t){if(n<e.y-1e-9||n>e.y+e.height+1e-9)return null;let t=n<o?o:n>s?s:n,l=t===n?0:(n-t)/e.capRadiusY;return r(e.cx+(i?1:-1)*a*Math.sqrt(Math.max(0,1-l*l)))}let l=(n-e.cx)/a;if(Math.abs(l)>1+1e-9)return null;let h=e.capRadiusY*Math.sqrt(Math.max(0,1-l*l));return r(i?s+h:o-h)}case"polygon":{let a=[];for(let i=0;i<e.points.length;i++){let r=e.points[i],o=e.points[(i+1)%e.points.length],s="x"===t?r.y:r.x,l="x"===t?o.y:o.x,h=r[t],u=o[t],d=l-s;if(1e-9>Math.abs(d)){1e-9>Math.abs(n-s)&&a.push(h,u);continue}let x=(n-s)/d;x>=-1e-9&&x<=1+1e-9&&a.push(h+x*(u-h))}let o=0===a.length?null:i?Math.max(...a):Math.min(...a);return null===o?null:r(o)}case"none":return null}}function ey(e,t,n,i,r,a){return{geometry:{kind:"rect",x:e,y:t,width:n,height:i,rx:a,ry:a},paint:et(r),routing:{kind:"rect",x:e,y:t,width:n,height:i}}}function ec(e,t,n,i){return{geometry:{kind:"circle",cx:e,cy:t,r:n},paint:et(i),routing:{kind:"ellipse",cx:e,cy:t,rx:n,ry:n}}}var ef=new Set(["text","brace","brace-r","braces","datastore","fork","f-circ","state-start","state-end","state-fork","state-join"]);function eg(e){return!ef.has(e.semanticShape??e.shape)}function ep(e,t,n){let i=er(e,t,n,{fill:"none",reason:"open symbol has no enclosing painted boundary"});return i.routing={kind:"envelope",x:e.x,y:e.y,width:e.width,height:e.height,reason:"open symbol routes to its layout envelope"},i}function em(e,t,n){let i=er(e,t,n);return i.routing={kind:"rect",x:e.x,y:e.y,width:e.width,height:e.height},i}function eM(e,t,n,i=1e-6){let r=eo(e).boundary;if("envelope"!==r.kind&&"none"!==r.kind)return eb(r,t,n,i)}function eb(e,t,n,i){let r=n.x-t.x,a=n.y-t.y,o=Math.hypot(r,a);if(o<=1e-9||Math.abs(r)>i&&Math.abs(a)>i)return!1;let s=Math.abs(r)>Math.abs(a)?r>0?"E":"W":a>0?"S":"N",l="E"===s||"W"===s?t.y:t.x,h=el(e,s,l);if(!h||Math.hypot(h.x-t.x,h.y-t.y)>i)return!1;let u=0,d=0;if("ellipse"===e.kind)u=(t.x-e.cx)/e.rx/e.rx,d=(t.y-e.cy)/e.ry/e.ry;else if("stadium"===e.kind){let n=e.halfWidth-e.radius;u=t.x-Math.max(e.cx-n,Math.min(e.cx+n,t.x)),d=t.y-e.cy}else{if("cylinder"!==e.kind)return!0;let n=e.y+e.capRadiusY,i=e.y+e.height-e.capRadiusY;t.y>=n&&t.y<=i?u=t.x-e.cx:(u=(t.x-e.cx)/(e.width/2)/(e.width/2),d=(t.y-(t.y<n?n:i))/e.capRadiusY/e.capRadiusY)}let x=Math.hypot(u,d);return x>0&&Number.isFinite(x)&&(r/o*u+a/o*d)/x>0}function e$(e,t){if("polygon"===e.kind){let n=!1;for(let i=0,r=e.points.length-1;i<e.points.length;r=i++){let a=e.points[i],o=e.points[r],s=o.x-a.x,l=o.y-a.y;if(Math.abs((t.x-a.x)*l-(t.y-a.y)*s)<=1e-6*Math.hypot(s,l)&&(t.x-a.x)*(t.x-o.x)+(t.y-a.y)*(t.y-o.y)<=1e-6)return!0;a.y>t.y!=o.y>t.y&&t.x<(o.x-a.x)*(t.y-a.y)/(o.y-a.y)+a.x&&(n=!n)}return n}let n=el(e,"W",t.y),i=el(e,"E",t.y);return!!(n&&i&&t.x>=n.x-1e-6&&t.x<=i.x+1e-6)}function ew(e,t,n){if(!e$(e,t)||!e$(e,n))return!0;if("polygon"!==e.kind)return!1;let i=n.x-t.x,r=n.y-t.y,a=1e-6>=Math.abs(i),o=a?r:i;if(1e-9>=Math.abs(o))return!1;let s=[0,1];for(let n=0;n<e.points.length;n++){let i=e.points[n],r=e.points[(n+1)%e.points.length],l=a?eW(t.x,i,r):eN(t.y,i,r);if(l){let e=(a?l.y-t.y:l.x-t.x)/o;e>0&&e<1&&s.push(e)}}return s.sort((e,t)=>e-t),s.some((n,a)=>{let o=s[a+1];if(void 0===o||o-n<=1e-9)return!1;let l=(n+o)/2;return!e$(e,{x:t.x+i*l,y:t.y+r*l})})}function ek(e,t,n){if(e.length<2)return e;let i=eo(t).boundary;if("envelope"===i.kind||"none"===i.kind)return e;let r=n?e:[...e].reverse(),a=r[0];if(!e$(i,a))return e;let o=r.find(e=>Math.hypot(e.x-a.x,e.y-a.y)>1e-9);if(!o||eb(i,a,o,1e-6))return e;for(let t=0;t<r.length-1;t++){let a=r[t],o=r[t+1],s=o.x-a.x,l=o.y-a.y,h=Math.hypot(s,l);if(h<=1e-9)continue;if(Math.abs(s)>1e-6&&Math.abs(l)>1e-6)break;let u=Math.abs(s)>Math.abs(l)?s>0?"E":"W":l>0?"S":"N",d="polygon"===i.kind?eP(a,o,i.points):el(i,u,"E"===u||"W"===u?a.y:a.x);if(d){let u=((d.x-a.x)*s+(d.y-a.y)*l)/h**2,x=r.slice(t+1),y=x.find(e=>Math.hypot(e.x-d.x,e.y-d.y)>1e-9);if(u>=-1e-9&&u<=1+1e-9&&y&&eb(i,d,y,1e-6)){if(ew(i,a,d))return e;let t=1e-9>=Math.hypot(d.x-o.x,d.y-o.y)?x:[d,...x];return n?t:t.reverse()}}if(ew(i,a,o))break}return e}function ev(e,t,n){if(e.length<2)return e;let i=eo(t).boundary;if("rect"===i.kind||"envelope"===i.kind||"none"===i.kind)return e;let r=[...e];if(n)r[0]=eS(e[0],e[1],t,i);else{let n=e.length-1;r[n]=eS(e[n],e[n-1],t,i)}return r}function eS(e,t,n,i){let r=function(e,t,n){switch(n.kind){case"ellipse":return function(e,t,n){let{cx:i,cy:r,rx:a,ry:o}=n;if(a<=0||o<=0)return null;let{vertical:s,dir:l}=eC(e,t);if(s){let t=(e.x-i)/a;return Math.abs(t)>1?null:{x:e.x,y:r-l*o*Math.sqrt(Math.max(0,1-t*t))}}let h=(e.y-r)/o;return Math.abs(h)>1?null:{x:i-l*a*Math.sqrt(Math.max(0,1-h*h)),y:e.y}}(e,t,n);case"stadium":return function(e,t,n){let{cx:i,cy:r,halfWidth:a,radius:o}=n,{vertical:s,dir:l}=eC(e,t);if(s){let t=Math.abs(e.x-i);if(t<=a-o)return{x:e.x,y:r-l*o};let n=t-(a-o);return n>o?null:{x:e.x,y:r-l*Math.sqrt(Math.max(0,o*o-n*n))}}let h=Math.abs(e.y-r);return h>o?null:{x:i-l*(a-o+Math.sqrt(Math.max(0,o*o-h*h))),y:e.y}}(e,t,n);case"cylinder":return function(e,t,n){let{cx:i,y:r,width:a,height:o,capRadiusY:s}=n,l=a/2,h=r+s,u=r+o-s,{vertical:d,dir:x}=eC(e,t);if(!d){if(e.y>=h&&e.y<=u)return{x:i-x*l,y:e.y};let t=e.y<h?h:u,n=(e.y-t)/s;return Math.abs(n)>1?null:{x:i-x*l*Math.sqrt(Math.max(0,1-n*n)),y:e.y}}let y=(e.x-i)/l;if(Math.abs(y)>1)return null;let c=s*Math.sqrt(Math.max(0,1-y*y));return x>0?{x:e.x,y:h-c}:{x:e.x,y:u+c}}(e,t,n);case"polygon":return eP(e,t,n.points);case"rect":case"envelope":case"none":return e}}(e,t,i);if(null!==r)return r;if(e.x<n.x-1e-6||e.x>n.x+n.width+1e-6||e.y<n.y-1e-6||e.y>n.y+n.height+1e-6)return e;let a=[1e-6>=Math.abs(e.y-n.y)?"N":void 0,1e-6>=Math.abs(e.y-n.y-n.height)?"S":void 0,1e-6>=Math.abs(e.x-n.x)?"W":void 0,1e-6>=Math.abs(e.x-n.x-n.width)?"E":void 0].filter(e=>void 0!==e),o=1===a.length?a[0]:void 0;return o?el(i,o,"N"===o||"S"===o?e.x:e.y)??e:e}function eC(e,t){let n=e.x-t.x,i=e.y-t.y,r=Math.abs(n)<Math.abs(i);return{vertical:r,dir:(r?i:n)>=0?1:-1}}function eP(e,t,n){let{vertical:i}=eC(e,t),r=null,a=1/0;for(let o=0;o<n.length;o++){let s=n[o],l=n[(o+1)%n.length],h=l.x-s.x,u=l.y-s.y,d=e.x-s.x,x=e.y-s.y;if(1e-6>Math.abs(d*u-x*h)&&d*(e.x-l.x)+x*(e.y-l.y)<=1e-6){let i=Math.hypot(t.x-e.x,t.y-e.y),r=i>0?Math.min(1e-4/i,.5):0,a={x:e.x+(t.x-e.x)*r,y:e.y+(t.y-e.y)*r},o=!1,s=!1;for(let r=0,l=n.length-1;r<n.length;l=r++){let h=n[r],u=n[l],d=t.x-e.x,x=t.y-e.y,y=u.x-h.x,c=u.y-h.y,f=d*c-x*y;if(Math.abs(f)>1e-9){let t=h.x-e.x,n=h.y-e.y,r=(t*c-n*y)/f,a=(t*x-n*d)/f;r*i>1e-6&&r<=1&&a>=0&&a<=1&&(s=!0)}h.y>a.y!=u.y>a.y&&a.x<(u.x-h.x)*(a.y-h.y)/(u.y-h.y)+h.x&&(o=!o)}if(!o&&!s)return e}let y=i?eW(e.x,s,l):eN(e.y,s,l);if(!y)continue;let c=Math.hypot(y.x-t.x,y.y-t.y);c<a&&(r=y,a=c)}return r}function eN(e,t,n){let i=n.y-t.y;if(1e-6>Math.abs(i))return null;let r=(e-t.y)/i;return r<0||r>1?null:{x:t.x+r*(n.x-t.x),y:e}}function eW(e,t,n){let i=n.x-t.x;if(1e-6>Math.abs(i))return null;let r=(e-t.x)/i;return r<0||r>1?null:{x:e,y:t.y+r*(n.y-t.y)}}var eL=new Set(["cloud","brace","brace-r","braces","datastore","delay","h-cyl","lin-cyl","curv-trap","doc","lin-doc","docs","st-rect","flag","bow-rect","tag-doc"]);function eE(e,t,n=1.5){if("text"===e.semanticShape)return{policy:"none",onBoundary:!1};if(e.semanticShape&&eL.has(e.semanticShape))return{policy:"envelope",onBoundary:eI(t,e.x,e.y,e.width,e.height,n)};let i=function(e){let{x:t,y:n,width:i,height:r}=e,a=t+i,o=n+r,s=t+i/2,l=n+r/2;switch(e.semanticShape){case"bang":return Array.from({length:16},(e,t)=>{let n=-Math.PI/2+t*Math.PI/8,a=t%2==0?1:.62;return{x:s+Math.cos(n)*i/2*a,y:l+Math.sin(n)*r/2*a}});case"notch-rect":case"tag-rect":return[{x:t+10,y:n},{x:a,y:n},{x:a,y:o},{x:t,y:o},{x:t,y:n+10}];case"hourglass":return[{x:t,y:n},{x:a,y:n},{x:t+.62*i,y:l},{x:a,y:o},{x:t,y:o},{x:t+.38*i,y:l}];case"bolt":return[{x:t+.55*i,y:n},{x:t+.25*i,y:l},{x:t+.48*i,y:l},{x:t+.35*i,y:o},{x:t+.78*i,y:n+.4*r},{x:t+.55*i,y:n+.4*r}];case"tri":return[{x:s,y:n},{x:a,y:o},{x:t,y:o}];case"notch-pent":return[{x:t,y:n},{x:a-10,y:n},{x:a,y:l},{x:a-10,y:o},{x:t,y:o},{x:t+8,y:l}];case"flip-tri":return[{x:t,y:n},{x:a,y:n},{x:s,y:o}];default:return null}}(e);if(i)return{policy:"exact",onBoundary:eR(t,i,n)};let r=e.x+e.width/2,a=e.y+e.height/2,o=Math.min(e.width,e.height)/2;if("fork"===e.semanticShape)return{policy:"exact",onBoundary:eI(t,e.x,a-4,e.width,8,n)};if("sm-circ"===e.semanticShape){let i=.22*Math.min(e.width,e.height);return{policy:"exact",onBoundary:eB(t,r,a,i,i,n)}}if("cross-circ"===e.semanticShape)return{policy:"exact",onBoundary:eB(t,r,a,e.width/2,e.height/2,n)};if("f-circ"===e.semanticShape)return{policy:"exact",onBoundary:eB(t,r,a,o,o,n)};switch(e.shape){case"diamond":case"state-choice":return{policy:"exact",onBoundary:Math.abs(Math.abs(t.x-r)/(e.width/2)+Math.abs(t.y-a)/(e.height/2)-1)*Math.min(e.width,e.height)/2<n};case"circle":case"doublecircle":case"state-history":return{policy:"exact",onBoundary:eB(t,r,a,o,o,n)};case"state-start":case"state-end":{let e=Math.max(0,o-2);return{policy:"exact",onBoundary:eB(t,r,a,e,e,n)}}case"stadium":{let i=e.height/2,o=e.width/2-i,s=Math.abs(t.x-r);return{policy:"exact",onBoundary:s<=o?Math.abs(Math.abs(t.y-a)-i)<n:Math.abs(Math.hypot(s-o,t.y-a)-i)<n}}case"hexagon":{let i=e.height/4;return{policy:"exact",onBoundary:eR(t,[{x:e.x+i,y:e.y},{x:e.x+e.width-i,y:e.y},{x:e.x+e.width,y:a},{x:e.x+e.width-i,y:e.y+e.height},{x:e.x+i,y:e.y+e.height},{x:e.x,y:a}],n)}}case"cylinder":return{policy:"exact",onBoundary:function(e,t,n){let i=e.x+e.width/2,r=e.y+e.height/2,a=e.width/2;if(t.y>=e.y+7-n&&t.y<=e.y+e.height-7+n&&Math.abs(Math.abs(t.x-i)-a)<n)return!0;let o=t.y<r?e.y+7:e.y+e.height-7;return Math.abs(Math.hypot((t.x-i)/a,(t.y-o)/7)-1)*Math.min(a,7)<2*n}(e,t,n)};case"trapezoid":case"trapezoid-alt":case"lean-r":case"lean-l":case"asymmetric":return{policy:"exact",onBoundary:eR(t,function(e){let{x:t,y:n,width:i,height:r}=e,a=t+i,o=n+r,s=.15*i;switch(e.shape){case"trapezoid":return[{x:t+s,y:n},{x:a-s,y:n},{x:a,y:o},{x:t,y:o}];case"trapezoid-alt":return[{x:t,y:n},{x:a,y:n},{x:a-s,y:o},{x:t+s,y:o}];case"lean-r":return[{x:t+s,y:n},{x:a,y:n},{x:a-s,y:o},{x:t,y:o}];case"lean-l":return[{x:t,y:n},{x:a-s,y:n},{x:a,y:o},{x:t+s,y:o}];default:return[{x:t+12,y:n},{x:a,y:n},{x:a,y:o},{x:t+12,y:o},{x:t,y:n+r/2}]}}(e),n)};default:return{policy:"exact",onBoundary:eI(t,e.x,e.y,e.width,e.height,n)}}}function eI(e,t,n,i,r,a){let o=Math.abs(e.x-t)<a||Math.abs(e.x-(t+i))<a,s=Math.abs(e.y-n)<a||Math.abs(e.y-(n+r))<a;return o&&e.y>=n-a&&e.y<=n+r+a||s&&e.x>=t-a&&e.x<=t+i+a}function eB(e,t,n,i,r,a){return!(i<=0)&&!(r<=0)&&Math.abs(Math.hypot((e.x-t)/i,(e.y-n)/r)-1)*Math.min(i,r)<a}function eR(e,t,n){let i=1/0;for(let n=0;n<t.length;n++)i=Math.min(i,function(e,t,n){let i=n.x-t.x,r=n.y-t.y,a=i*i+r*r;if(0===a)return Math.hypot(e.x-t.x,e.y-t.y);let o=Math.max(0,Math.min(1,((e.x-t.x)*i+(e.y-t.y)*r)/a));return Math.hypot(e.x-(t.x+o*i),e.y-(t.y+o*r))}(e,t[n],t[(n+1)%t.length]));return i<=n}var eH=64,eA=128;function eF(e){let t=e.nodes.size,n=e=>{for(let i of e)t++,n(i.children)};return n(e.subgraphs),t<=eH&&e.edges.length<=eA}function eO(e,t,n="end"){return Math.max(12,D(t??{style:"solid",hasArrowStart:!0,hasArrowEnd:!0},e)[n]+(e.edgeBendRadius??0))}var ez=new Set([...new Set(["rectangle","service","rounded","subroutine","state-fork","state-join"]),"diamond","circle","ellipse","doublecircle","stadium","hexagon","cylinder","state-start","state-end","state-choice","state-history","trapezoid","trapezoid-alt","asymmetric","lean-r","lean-l"]);function ej(e){return es(e)}function eY(e){let t=e.x+e.width/2,n=e.y+e.height/2,i=e.width/4,r=e.height/4;return{NE:{x:t+i,y:n-r},SE:{x:t+i,y:n+r},SW:{x:t-i,y:n+r},NW:{x:t-i,y:n-r}}}function eQ(e,t){let n=eo(e);if("envelope"!==n.boundary.kind&&"none"!==n.boundary.kind){for(let e of["N","E","S","W"]){let i=n.sides[e].preferred;if(.5>=Math.abs(i.x-t.x)&&.5>=Math.abs(i.y-t.y))return e}if(eU(e)){let n=eY(e);for(let e of["NE","SE","SW","NW"])if(.5>=Math.abs(n[e].x-t.x)&&.5>=Math.abs(n[e].y-t.y))return e}}}function eZ(e,t,n){let i=0;for(let[r,a]of[[t,!0],[n,!1]]){if(!r)continue;let t=eo(r);if("envelope"===t.boundary.kind||"none"===t.boundary.kind)continue;let n=a?e.points:[...e.points].reverse(),o=n[0],s=o&&n.find(e=>Math.hypot(e.x-o.x,e.y-o.y)>.01);if(!o||!s){i++;continue}let l=s.x-o.x,h=s.y-o.y;Math.abs(l)>.01&&Math.abs(h)>.01||eM(r,o,s,.5)||i++}return i}function eq(e,t,n){for(let[i,r]of[[t,!0],[n,!1]]){if(!i)continue;let t=eo(i);if("envelope"!==t.boundary.kind&&"none"!==t.boundary.kind)for(;e.points.length>2;){let[t,n]=r?e.points:[...e.points].reverse(),a={x:(t.x+n.x)/2,y:(t.y+n.y)/2};if(![t,n,a].every(e=>eE(i,e,.01).onBoundary))break;let o={...e,points:r?e.points.slice(1):e.points.slice(0,-1)};if(0!==eZ(o,r?i:void 0,r?void 0:i))break;e.points=o.points}}}function eV(e){let t=eo(e).boundary;return"envelope"!==t.kind&&"none"!==t.kind}function eU(e){let t=eo(e);return"polygon"===t.boundary.kind&&["N","E","S","W"].every(e=>"dynamic"===t.sides[e].kind)}function eJ(e){let t=new Set,n=new Map,i=(e,r)=>{for(let r of e){for(let e of(t.add(r.id),r.nodeIds))n.set(e,r.id);i(r.children,r.id)}};i(e.subgraphs,"");let r=new Map;return e.edges.map(e=>{if(e.source===e.target)return"self-loop";if(t.has(e.source)||t.has(e.target))return"container";let i=((e,t)=>{let n=new Set,i=[e];for(;i.length>0;){let e=i.pop();if(e===t)return!0;if(!n.has(e))for(let t of(n.add(e),r.get(e)??[]))i.push(t)}return!1})(e.target,e.source)?"feedback":(n.get(e.source)??"")!==(n.get(e.target)??"")?"cross-hierarchy":"primary-forward";return"feedback"!==i&&(r.has(e.source)||r.set(e.source,new Set),r.get(e.source).add(e.target)),i})}function eT(e){let t="LR"===e||"RL"===e;return{main:t?"x":"y",cross:t?"y":"x",sign:"RL"===e||"BT"===e?-1:1}}function e_(e,t,n){return e.x!==n.x&&e.y!==n.y&&(e.x===t.x&&t.y===n.y||e.y===t.y&&t.x===n.x)}function eX(e){let t=e;for(let e=0;e<8&&!(t.length<3);e++){let e=[t[0]];for(let n=1;n<t.length;n++){let i=t[n],r=e[e.length-1];if(.01>Math.abs(i.x-r.x)&&.01>Math.abs(i.y-r.y)){let e=t[n+1];if(e?!e_(r,i,e):i.x===r.x&&i.y===r.y)continue}e.push(i)}let n=e.length<3?e:[e[0]];if(e.length>=3){for(let t=1;t<e.length-1;t++){let i=n[n.length-1],r=e[t],a=e[t+1];.01>Math.abs((r.x-i.x)*(a.y-i.y)-(r.y-i.y)*(a.x-i.x))&&!e_(i,r,a)||n.push(r)}n.push(e[e.length-1])}if(n.length===t.length)return n;t=n}return t}function eD(e){let t=!1;for(let n=1;n<e.length;n++){let i=e[n-1],r=e[n];if(Math.abs(i.x-r.x)>.01&&Math.abs(i.y-r.y)>.01){t=!0;break}}if(!t)return e;let n=[e[0]];for(let t=1;t<e.length;t++){let i=n[n.length-1],r=e[t];if(Math.abs(i.x-r.x)>.01&&Math.abs(i.y-r.y)>.01){let e=n.length>=2?n[n.length-2]:void 0,t=!e||.01>Math.abs(e.y-i.y);n.push(t?{x:r.x,y:i.y}:{x:i.x,y:r.y})}n.push(r)}return n}function eG(e){return Math.max(0,eX(e).length-2)}function eK(e,t){for(let n=1;n<e.length;n++){let i=e[n-1],r=e[n],a=(r[t.main]-i[t.main])*t.sign,o=Math.abs(r[t.cross]-i[t.cross]);if(a>.01&&o>.01||a<-.01)return!1}return!0}function e1(e,t,n){let i=eo(e).sides[e2(t,n)];if("dynamic"===i.kind)return{lo:i.lo,hi:i.hi};if("port"===i.kind){let e=i.point[t.cross];return{lo:e-.5,hi:e+.5}}return null}function e0(e,t,n,i){var r,a;let o;return(r=eo(e),a=e2(n,i),"none"===(o=r.sides[a]).kind?null:"port"===o.kind?o.point:el(r.boundary,a,t))?.[n.main]??null}function e2(e,t){let n=t*e.sign>0;return"x"===e.main?n?"E":"W":n?"S":"N"}function e5(e,t,n){return{role:`${"feedback"===e||"self-loop"===e||"container"===e||"cross-hierarchy"===e?e:"flow"}-${t}`,side:e2(n,"source"===t!=("feedback"===e)?1:-1)}}function e8(e,t,n){return n?"N"===e||"S"===e?n.x:n.y:"N"===e||"S"===e?t.x+t.width/2:t.y+t.height/2}function e6(e,t,n=eJ(t)){return tt(e,t,n,!0)}function e4(e,t,n,i,r,a=!1){let o=eT(t.direction),s=tt(e,t,i,!1).sideUse;for(let t of e.edges){if(!r(t)||void 0===t.edgeIndex)continue;let e=i[t.edgeIndex];if("primary-forward"===e||"feedback"===e&&!t.label)for(let n of["source","target"]){let i="source"===n?t.source:t.target,{side:r}=e5(e,n,o),a=`${i}:${r}`,l=(s.get(a)??0)-1;l>0?s.set(a,l):s.delete(a)}}return{axis:o,ctx:{nodes:e.nodes,edges:e.edges,groups:e.groups,axis:o,style:n,classes:i,sideUse:s,finalLabelClearance:a,nodeLaneIndexes:z()?void 0:{},routeChannelGeometry:z()?void 0:new WeakMap}}}function e3(e,t,n){return"x"===e.main?{x:t,y:n}:{x:n,y:t}}function e7(e,t,n){return{main:e.cross,cross:e.main,sign:t<n?1:-1}}function e9(e,t,n){e.routeChannelGeometry?.delete(t),t.points=n}function te(e){let t=new Map;return e.forEach(e=>t.set(e.id,e)),t}function tt(e,t,n,i){let r=eT(t.direction),a=te(e.nodes),o=[],s=new Map,l=(e,t)=>{let n=`${e}:${t}`;s.set(n,(s.get(n)??0)+1)};for(let t of e.edges){if(void 0===t.edgeIndex)continue;let e=n[t.edgeIndex]??"primary-forward";for(let n of["source","target"]){let s="source"===n?t.source:t.target,h=a.get(s);if(!h)continue;let{role:u,side:d}=e5(e,n,r),x="source"===n?t.points[0]:t.points[t.points.length-1],y=x?eQ(h,x):void 0,c=y?"N"===y||"E"===y||"S"===y||"W"===y?y:y.includes(d)?d:y[0]:d;if("primary-forward"!==e&&("feedback"!==e||t.label)||l(s,d),!i){e8(c,h,x);continue}o.push({edge:t,endpoint:n,nodeId:s,side:c,role:u,coord:e8(c,h,x),edgeIndex:t.edgeIndex,port:y})}}if(!i)return{byEdge:new Map,sideUse:s};let h=new Map;for(let e of o){let t=`${e.nodeId}:${e.side}`;h.has(t)||h.set(t,[]),h.get(t).push(e)}let u=new Map,d=e=>+("source"!==e);for(let e of h.values()){e.sort((e,t)=>e.coord-t.coord||e.edgeIndex-t.edgeIndex||d(e.endpoint)-d(t.endpoint));let t=e.length;e.forEach((e,n)=>{let i={side:e.side,slotIndex:n,slotCount:t,role:e.role,...e.port?{port:e.port}:{}},r=u.get(e.edge)??{};r[e.endpoint]=i,u.set(e.edge,r)})}return{byEdge:u,sideUse:s}}function tn(e,t,n,i,r){let a=0,o=0,s=e=>{for(let t of(a=Math.min(a,e.x),o=Math.min(o,e.y),e.children))s(t)};for(let t of e)a=Math.min(a,t.x),o=Math.min(o,t.y);for(let e of n)s(e);for(let e of t){for(let t of e.points)a=Math.min(a,t.x),o=Math.min(o,t.y);let t=r&&e.labelBlock?x(e,r):null;t?(a=Math.min(a,t.x),o=Math.min(o,t.y)):e.labelPosition&&(a=Math.min(a,e.labelPosition.x),o=Math.min(o,e.labelPosition.y))}if(a>=0&&o>=0)return;let l=a<0?-a+i:0,h=o<0?-o+i:0,u=e=>{for(let t of(e.x+=l,e.y+=h,e.children))u(t)};for(let t of e)t.x+=l,t.y+=h;for(let e of n)u(e);for(let e of t){for(let t of e.points)t.x+=l,t.y+=h;e.labelPosition&&(e.labelPosition.x+=l,e.labelPosition.y+=h)}}var ti=new WeakMap;function tr(e){let t=e.points[0];if(!t)return;let n=[];for(let i of e.points)n.push(i.x-t.x,i.y-t.y);ti.set(e,{source:e.source,target:e.target,edgeIndex:e.edgeIndex,coordinates:n})}function ta(e,t){let n=e[0];if(!n||e.length<2||!(e.every(e=>e.source===n.source)||e.every(e=>e.target===n.target)||e.every(e=>e.source===n.source&&e.target===n.target||e.source===n.target&&e.target===n.source)))throw Error("Bundle construction requires related fan or parallel routes");for(let n of e)tr(n),t.add(n)}function to(e){let t=ti.get(e);if(!t||e.source!==t.source||e.target!==t.target||e.edgeIndex!==t.edgeIndex||2*e.points.length!==t.coordinates.length)return!1;let n=e.points[0];if(!n)return!1;for(let i=0;i<e.points.length;i++){let r=e.points[i];if(!(1e-6>=Math.abs(r.x-n.x-t.coordinates[2*i]))||!(1e-6>=Math.abs(r.y-n.y-t.coordinates[2*i+1])))return!1}return!0}function ts(e){return to(e)?ti.get(e):void 0}function tl(e,t){t&&ti.get(e)===t&&e.source===t.source&&e.target===t.target&&e.edgeIndex===t.edgeIndex&&tr(e)}function th(e,t){for(let n=1;n<e.length;n++){let i=e[n-1],a=e[n],o=Math.min(i.x,a.x),s=Math.max(i.x,a.x),l=Math.min(i.y,a.y),h=Math.max(i.y,a.y);for(let n=1;n<t.length;n++){let u=t[n-1],d=t[n];if(!(s<Math.min(u.x,d.x)||o>Math.max(u.x,d.x)||h<Math.min(u.y,d.y)||l>Math.max(u.y,d.y))&&(i.x!==a.x||u.x!==d.x)&&(i.y!==a.y||u.y!==d.y))return r([{points:e},{points:t}])}}return 0}function tu(e,t){let n=e.points.map(e=>({x:Number(E(e.x)),y:Number(E(e.y))})),i="thick"===e.style?2:1,r=Number(E((t.lineWidth??1)*i))/i,a={...t,lineWidth:r},o=!e.curve&&!(t.edgeBendRadius&&t.edgeBendRadius>0);return o?{regions:K({...e,points:n},a),points:n,directional:o}:{regions:K(e,a).map(e=>{let t="start"===e.position?n[0]:n.at(-1),i=e.bounds;if(!i)return{...e,anchor:t};let r=Math.max(...[i.x0,i.x1].flatMap(t=>[i.y0,i.y1].map(n=>Math.hypot(t-e.anchor.x,n-e.anchor.y))));return{...e,anchor:t,bounds:{x0:t.x-r,y0:t.y-r,x1:t.x+r,y1:t.y+r}}}),points:n,directional:o}}function td(e,t){if("invisible"===e.style||!e.hasArrowStart&&!e.hasArrowEnd)return[];if(!tx(e,t))return;let{regions:n}=tu(e,t);return n.length===+!!e.hasArrowStart+ +!!e.hasArrowEnd&&n.every(ty)?n:void 0}function tx(e,t){if(!e.points.every(e=>Number.isFinite(e.x)&&Number.isFinite(e.y))||void 0!==t.edgeBendRadius&&!(Number.isFinite(t.edgeBendRadius)&&t.edgeBendRadius>=0))return!1;let n=(t.lineWidth??1)*("thick"===e.style?2:1);return!!e.inlineStyle?.["stroke-width"]||Number.isFinite(n)&&n>0}function ty(e){let t=e.bounds;return!!t&&[t.x0,t.y0,t.x1,t.y1].every(Number.isFinite)&&t.x0<=t.x1&&t.y0<=t.y1}function tc(e,t,n){if("mid"===n)return!1;let i=e=>"start"===n?e[0]:e.at(-1),r=i(e),a=i(t);if(!r||!a||r.x!==a.x||r.y!==a.y)return!1;let o=e=>{for(let t=1;t<e.length;t++){let i=e["start"===n?t:e.length-t-1];if(i.x!==r.x||i.y!==r.y)return i}},s=o(e),l=o(t);return!!s&&!!l&&(s.x===l.x&&s.y===l.y||(r.x===s.x||r.y===s.y)&&(r.x===l.x||r.y===l.y)&&Math.sign(s.x-r.x)===Math.sign(l.x-r.x)&&Math.sign(s.y-r.y)===Math.sign(l.y-r.y))}function tf(e,t){let n=e.bounds,i=t.bounds;if(!n||!i||!ty(e)||!ty(t))return!1;let r=[n.x0,n.y0,n.x1,n.y1,i.x0,i.y0,i.x1,i.y1];if(!r.every(Number.isFinite))return!1;let a=1e-10*r.reduce((e,t)=>e+Math.abs(t),0)+1e-9;return Number.isFinite(a)&&(n.x1+a<i.x0||i.x1+a<n.x0||n.y1+a<i.y0||i.y1+a<n.y0)}function tg(e,t){if(e.label&&t.label||e.style!==t.style||e.curve!==t.curve||e.animate!==t.animate||e.animation!==t.animation)return!1;let n=e.inlineStyle??{},i=t.inlineStyle??{};for(let e in n)if(!(e in i)||i[e]!==n[e])return!1;for(let e in i)if(!(e in n))return!1;let r=e.classNames??[],a=t.classNames??[];if(r.length!==a.length)return!1;for(let e=0;e<r.length;e++)if(r[e]!==a[e])return!1;return!0}function tp(e,t,n,i,r=e){if(!e.hasArrowStart&&!e.hasArrowEnd||"invisible"===e.style)return;let a=(e,t,i)=>({kind:"port",id:`${i}:${e.id??`${e.source}->${e.target}[${e.edgeIndex??n.indexOf(e)}]`}:${t}`});if(!tx({...e,points:t},i))return a(r,"mapping","marker");let o=tu(e,i),s=tu({...e,points:t},i),l=o.regions,h=s.regions;if(h.length!==+!!e.hasArrowStart+ +!!e.hasArrowEnd)return a(r,"unmeasured","marker");for(let u of h){let d=l.find(e=>e.position===u.position);if(!(d&&d.resource===u.resource&&d.repaint===u.repaint&&d.anchor.x===u.anchor.x&&d.anchor.y===u.anchor.y&&(o.directional&&s.directional?tc(o.points,s.points,u.position):e.curve?e.points.length===t.length&&e.points.every((e,n)=>e.x===t[n].x&&e.y===t[n].y):function(e,t,n){if("mid"===n||e.length<2||t.length<2)return!1;let i=e=>"start"===n?[e[0],e[1]]:[e.at(-1),e.at(-2)],[r,a]=i(e),[o,s]=i(t);return r.x===o.x&&r.y===o.y&&a.x===s.x&&a.y===s.y}(e.points,t,u.position)))){if(!ty(u))return a(r,u.position,"marker");for(let e of h)if(e!==u&&!tf(u,e))return a(r,e.position,"opposite-marker");for(let t of n){if(t===r||"invisible"===t.style||!t.hasArrowStart&&!t.hasArrowEnd)continue;if(!tx(t,i))return a(t,"mapping","peer-marker");let n=tu(t,i);for(let i of n.regions){let r="start"===u.position?e.source:e.target,o="start"===i.position?t.source:t.target;if(!(s.directional&&n.directional&&ty(i)&&u.position===i.position&&r===o&&u.resource===i.resource&&u.repaint===i.repaint&&u.anchor.x===i.anchor.x&&u.anchor.y===i.anchor.y&&tc(s.points,n.points,u.position)&&tg(e,t))&&!tf(u,i))return a(t,i.position,"peer-marker")}}}}}function tm(e,t,n,i,r=e){return void 0===tp(e,t,n,i,r)}function tM(e){return eU(e)?2:1}function tb(e,t){return eU(e)&&("NE"===t||"SE"===t||"SW"===t||"NW"===t)?eY(e)[t]:ej(e)[t]}function t$(e,t,n,i){let r=eo(t).boundary;if("rect"!==r.kind||e.points.length<2)return;let a=n?0:e.points.length-1,o=e.points[a],s=r.x,l=r.x+r.width,h=r.y,u=r.y+r.height,d=(e,t)=>.5>=Math.abs(e-t),x=(t,r)=>{let o=[...e.points];if(o[a]=t,Math.abs(t.x-r.x)>.01||Math.abs(t.y-r.y)>.01)if(n){let e=o[1];(!e||Math.abs(e.x-r.x)>.01||Math.abs(e.y-r.y)>.01)&&o.splice(1,0,r)}else{let e=o[o.length-2];(!e||Math.abs(e.x-r.x)>.01||Math.abs(e.y-r.y)>.01)&&o.splice(o.length-1,0,r)}tm(e,o,i.edges,i.style)&&e9(i,e,o)};if(d(o.x,s)||d(o.x,l)){let e=d(o.x,s)?s:l;o.y<h-.5?x({x:e,y:h},{x:e,y:o.y}):o.y>u+.5&&x({x:e,y:u},{x:e,y:o.y});return}if(d(o.y,h)||d(o.y,u)){let e=d(o.y,h)?h:u;o.x<s-.5?x({x:s,y:e},{x:o.x,y:e}):o.x>l+.5&&x({x:l,y:e},{x:o.x,y:e})}}function tw(e,t,n,i){if(!eU(t)||void 0===e.edgeIndex||n.classes?.[e.edgeIndex]!=="primary-forward")return null;let r=te(n.nodes),a=n.edges.filter(t=>t.source===e.source&&void 0!==t.edgeIndex&&n.classes?.[t.edgeIndex]==="primary-forward"&&r.has(t.target)).sort((e,t)=>{let n=r.get(e.target),a=r.get(t.target);return n[i.cross]+("y"===i.cross?n.height:n.width)/2-(a[i.cross]+("y"===i.cross?a.height:a.width)/2)||(e.edgeIndex??0)-(t.edgeIndex??0)}),o=function(e,t){if(2!==t&&3!==t)return null;let n=e2(e,1),i="E"===n?"NE":"S"===n?"SW":"NW",r="W"===n?"SW":"N"===n?"NE":"SE";return 2===t?[i,r]:[i,n,r]}(i,a.length);if(!o)return null;let s=a.indexOf(e);if(s<0)return null;let l=o[s],h=a.map(e=>{let t=r.get(e.target);return t[i.main]+("x"===i.main?t.width:t.height)/2});return{sourcePort:l,sourceLane:tb(t,l)[i.cross],targetsShareRank:Math.max(...h)-Math.min(...h)<=1}}function tk(e,t,n,i,r){let a=tw(e,t,i,r);if(!a||!a.targetsShareRank)return null;let o=e2(r,-1),s=ej(n)[o][r.cross];return .5>=Math.abs(a.sourceLane-s)?null:{sourcePort:a.sourcePort,sourceLane:a.sourceLane,targetPort:o,targetLane:s}}function tv(e,t,n){return!n.fixedLabels&&!n.finalLabelClearance&&!!n.classes&&void 0!==e.edgeIndex&&void 0!==t.edgeIndex&&"primary-forward"===n.classes[e.edgeIndex]&&"feedback"===n.classes[t.edgeIndex]&&t.source===e.target&&t.target===e.source}function tS(e){return`${e.source}->${e.target}`}function tC(e,t,n,i,r,a=r.axis){return tN(e,t,n,i,r,a,!1)}function tP(e,t,n,i,r,a){return tN(e,t,n,i,r,a,!0)}function tN(e,t,r,a,s,h,u){let d=u?void 0:[],x=i(s.nodeLaneIndexes,s.nodes,h.cross,4),y=x?n(x,t):null,c=x&&null!==y,f=c?x.offsets[y]??0:0,g=c?x.offsets[y+1]??0:s.nodes.length;for(let n=f;n<g;n++){let i=s.nodes[c?x.ordinals[n]:n];if(i.id===e.source||i.id===e.target)continue;let o=("x"===h.cross?i.x:i.y)-4,l=("x"===h.cross?i.x:i.y)+("y"===h.cross?i.height:i.width)+4;if(t>o&&t<l){let e=("x"===h.main?i.x:i.y)-4;if(Math.min(a,("x"===h.main?i.x:i.y)+("x"===h.main?i.width:i.height)+4)-Math.max(r,e)>.01){if(u)return!0;d.push({kind:"node",id:i.id})}}}if(s.groups?.length&&"invisible"!==e.style){let e=n=>{let i=n.concurrencyRegion?0:n.headerHeight??n.height,o=!Number.isFinite(i)||i<0,s="x"===h.cross?n.x:n.y,l=s+("x"===h.cross?n.width:i),x="x"===h.main?n.x:n.y,y=x+("x"===h.main?n.width:i);if(o||i>0&&n.width>0&&t>s&&t<l&&Math.min(a,y)>Math.max(r,x)){if(u)return!0;d.push({kind:"group-header",id:n.id})}for(let t of n.children)if(e(t))return!0;return!1};for(let t of s.groups)if(e(t))return!0}let p=s.routeChannelGeometry;for(let n=0;n<s.edges.length;n++){let i=s.edges[n];if(i===e||void 0!==e.edgeIndex&&i.edgeIndex===e.edgeIndex)continue;let x=!tv(e,i,s)&&i.label&&i.labelPosition?i.labelBlock??o(N(i.label,i.labelContent),s.style):void 0;if(x){let e=x.width+2*l,n=x.height+2*l,o=i.labelPosition.x-e/2,s=i.labelPosition.y-n/2,y=("x"===h.main?o:s)-4,c=y+("x"===h.main?e:n)+8,f=("y"===h.cross?s:o)-4,g=f+("y"===h.cross?n:e)+8;if(t>f&&t<g&&Math.min(a,c)-Math.max(r,y)>.01){if(u)return!0;d.push({kind:"label",id:tS(i)})}}if(!(p&&!function(e,t,n,i,r,a,o,s){if(!Number.isFinite(i)||!Number.isFinite(r)||!Number.isFinite(a))return!0;if(t.points.length<2)return!1;let l=e.get(t);if(void 0===l&&(l=function(e){let t=1/0,n=-1/0,i=1/0,r=-1/0;for(let a of e){let e=a.x,o=a.y;if(!Number.isFinite(e)||!Number.isFinite(o))return null;t=Math.min(t,e),n=Math.max(n,e),i=Math.min(i,o),r=Math.max(r,o)}return{minX:t,maxX:n,minY:i,maxY:r}}(t.points),e.set(t,l)),!l)return!0;let h="x"===n?l.minX:l.minY,u="x"===n?l.maxX:l.maxY;if(i<h&&h-i>=4||i>u&&i-u>=4)return!1;let d="x"===n?l.minY:l.minX;return Math.min(a,"x"===n?l.maxY:l.maxX)-Math.max(r,d)>.01}(p,i,h.cross,t,r,a,0,0)))for(let n=1;n<i.points.length;n++){let o=i.points[n-1],s=i.points[n];if(Math.abs(("x"===h.cross?o.x:o.y)-("x"===h.cross?s.x:s.y))>.01||Math.abs(("x"===h.cross?o.x:o.y)-t)>=4)continue;let l=Math.min("x"===h.main?o.x:o.y,"x"===h.main?s.x:s.y);if(Math.min(a,Math.max("x"===h.main?o.x:o.y,"x"===h.main?s.x:s.y))-Math.max(r,l)>.01){if(i.target===e.target&&i.source!==e.source&&tg(e,i)&&.01>Math.abs(("x"===h.cross?o.x:o.y)-t)&&n===i.points.length-1)continue;if(u)return!0;d.push({kind:"channel",id:tS(i)});break}}}if(e.label){let t=e.labelBlock??o(N(e.label,e.labelContent),s.style);if(a-r<("x"===h.main?t.width:t.height)+2*l+8){if(u)return!0;d.push({kind:"label",id:tS(e)})}}return!u&&tI(d)}function tW(e,t,n,i){if(!e.label)return{x:(t.x+n.x)/2,y:(t.y+n.y)/2};let r=e.labelBlock??o(N(e.label,e.labelContent),i.style),a=2,s=i.style.lineWidth??1,h=u(e,s,"start"),y=u(e,s,"end"),c=t=>Math.max(i.finalLabelClearance?8:a,t.id===e.source?h:0,t.id===e.target?y:0),f=i.finalLabelClearance?16:a,g=i.finalLabelClearance?8:a,p=i.edges.filter(t=>t!==e&&(void 0===e.edgeIndex||t.edgeIndex!==e.edgeIndex)),m=t=>!i.finalLabelClearance&&tv(e,t,i)?null:x(t,i.style),M=.01>Math.abs(t.x-n.x),b=M!==.01>Math.abs(t.y-n.y),$=M?"y":"x",w=M?"x":"y",k=M?"x1":"y1",v=M?"y1":"x1",S=(M?r.height:r.width)/2+l,C=(M?r.width:r.height)/2+l,P=Math.min(t[w],n[w])-C-1e-6,W=Math.max(t[w],n[w])+C+1e-6,L=Math.min(t[$],n[$])-S-1e-6,E=Math.max(t[$],n[$])+S+1e-6,I,B=()=>{if(I)return I;let e=I=[],t=(t,n,i,r,a,o,s)=>{(!b||(M?a:o)+s>=P&&(M?t:n)-s<=W&&(M?o:a)+s>=L&&(M?n:t)-s<=E)&&e.push({x:t,y:n,w:i,h:r,x1:a,y1:o,gap:s})};for(let e of i.nodes)t(e.x,e.y,e.width,e.height,e.x+e.width,e.y+e.height,c(e));for(let e of p){let n=m(e);n&&t(n.x,n.y,n.w,n.h,n.x+n.w,n.y+n.h,f);for(let n=1;n<e.points.length;n++){let i=e.points[n-1],r=e.points[n],a=Math.min(i.x,r.x),o=Math.max(i.x,r.x),s=Math.min(i.y,r.y),l=Math.max(i.y,r.y);t(a,s,o-a,l-s,o,l,g)}}return e},R=(e,t)=>{let n=d(e,t,r);return!B().some(e=>((e,t,n,i,r,o,s,l,h=a)=>e<r+s+h&&e+n+h>r&&t<o+l+h&&t+i+h>o)(n.x,n.y,n.w,n.h,e.x,e.y,e.w,e.h,e.gap))};for(let e of[.5,1/3,2/3,.25,.75,1/6,5/6]){let i=t.x+(n.x-t.x)*e,r=t.y+(n.y-t.y)*e;if(R(i,r))return{x:i,y:r}}if(!b)return null;let H=Math.min(t[$],n[$]),A=Math.max(t[$],n[$]),F=(H+A)/2;if(A-H<2*S-.02)return null;let O=[F];for(let e of B())e[k]+e.gap<=t[w]-C||e[w]-e.gap>=t[w]+C||O.push(e[$]-e.gap-S-.01,e[v]+e.gap+S+.01);for(let e of O.filter(e=>e>=H+S-.01&&e<=A-S+.01).sort((e,t)=>Math.abs(e-F)-Math.abs(t-F)||e-t).slice(0,16)){let n="x"===$?{x:e,y:t.y}:{x:t.x,y:e};if(R(n.x,n.y))return n}return null}function tL(e,t,n,i=1/0){if("invisible"===t.style)return 0;let r=0;for(let a of n.edges)if(a!==t&&"invisible"!==a.style&&(void 0===t.edgeIndex||a.edgeIndex!==t.edgeIndex)&&(r+=th(e,a.points))>i)break;return r}function tE(e,t){for(let n of t.nodes)if(n.id!==e.source&&n.id!==e.target&&tj(e.points,n))return!0;return!1}function tI(e){let t=new Set;return e.filter(e=>{let n=`${e.kind}:${e.id}`;return!t.has(n)&&(t.add(n),!0)})}function tB(e,t,n,i,r,a){let o=e1(t,r,1),s=e1(n,r,-1);if(!o||!s)return null;let l=Math.max(o.lo,s.lo),h=Math.min(o.hi,s.hi),u=(e,t)=>eU(e)?{lo:e[r.cross]+2,hi:e[r.cross]+("y"===r.cross?e.height:e.width)-2}:t,d=Math.max(u(t,o).lo,u(n,s).lo),x=Math.min(u(t,o).hi,u(n,s).hi),y=e=>e[r.cross]+("y"===r.cross?e.height:e.width)/2,c=e=>.5>=Math.abs(e-y(n))||.5>=Math.abs(e-y(t));if(d>x)return{overlapLo:l,overlapHi:h,relaxedLo:d,relaxedHi:x,candidates:[],isPortLane:c,emptyRelaxed:!0};let f=[],g=e=>{f.every(t=>Math.abs(t-e)>.5)&&f.push(e)},p=n[r.cross]+("y"===r.cross?n.height:n.width)/2,m=t[r.cross]+("y"===r.cross?t.height:t.width)/2,M=i.sideUse?.get(`${t.id}:${e2(r,1)}`)??1,b=eU(t)&&1===M&&tM(t)>=tM(n),$=i.classes&&i.edges.some(t=>t!==e&&t.source===e.target&&t.target===e.source&&!t.label&&!e.label&&void 0!==t.edgeIndex&&void 0!==e.edgeIndex),w=$&&eU(t)&&eU(n);if(void 0!==a)f.push(a);else if(w){let n="feedback"===i.classes[e.edgeIndex]?1:-1;g(t[r.cross]+("y"===r.cross?t.height:t.width)/2+n*(("y"===r.cross?t.height:t.width)/4)),g((l+h)/2+12*n/2),g(p),g(m)}else if($)g((l+h)/2+("feedback"===i.classes[e.edgeIndex]?1:-1)*12/2),g(p),g(m);else if(b)g(m),g(p);else{let n=tw(e,t,i,r)?.sourceLane;void 0!==n&&g(n),g(p),g(m)}if(void 0===a){if(e.points.length>0){g(e.points[e.points.length-1][r.cross]),g(e.points[0][r.cross]);let t=e.points.map(e=>e[r.cross]);g(Math.min(...t)),g(Math.max(...t))}g((l+h)/2),g((l+(l+h)/2)/2),g(((l+h)/2+h)/2)}return{overlapLo:l,overlapHi:h,relaxedLo:d,relaxedHi:x,candidates:f,isPortLane:c,emptyRelaxed:!1}}function tR(e,t,n,i,r,a,o){let s=o.isPortLane(i)?o.relaxedLo:o.overlapLo,l=o.isPortLane(i)?o.relaxedHi:o.overlapHi;if(i<s-.01||i>l+.01)return{blockers:[{kind:"span",id:tS(e)}]};let h=e0(t,i,a,1),u=e0(n,i,a,-1);if(null===h||null===u||(u-h)*a.sign<=.01)return{blockers:[{kind:"span",id:tS(e)}]};let d=tC(e,i,Math.min(h,u),Math.max(h,u),r,a);if(d.length>0)return{blockers:d};let x=e3(a,h,i),y=e3(a,u,i),c=r.nodeLaneIndexes&&!z()?o.priorCrossings??=tL(e.points,e,r):tL(e.points,e,r);if(tL([x,y],e,r,c)>c)return{blockers:[{kind:"crossing",id:tS(e)}]};let f=tW(e,x,y,r);return null===f?{blockers:[{kind:"label",id:tS(e)}]}:{start:x,end:y,slot:f}}function tH(e,t,n,i,r=i.axis,a,o=e){let s=tB(e,t,n,i,r,a);if(!s)return{applied:!1,blockers:[]};if(s.emptyRelaxed)return{applied:!1,blockers:[{kind:"span",id:tS(e)}]};let l=[];for(let a=0;a<s.candidates.length;a++){let h=tR(e,t,n,s.candidates[a],i,r,s);if("blockers"in h){l.push(...h.blockers);continue}let u=tp(e,[h.start,h.end],i.edges,i.style,o);if(u){l.push(u);continue}let d=eX(e.points);if(2===d.length&&.01>=Math.abs(d[0][r.cross]-d[1][r.cross])){let a=+!!eQ(t,d[0])+ +!!eQ(n,d[1]),o=+!!eQ(t,h.start)+ +!!eQ(n,h.end)<a,u=()=>{let t=i.edges.filter(t=>t!==e);return Y([{...e,points:[h.start,h.end]},...t])<Y([{...e,points:d},...t])};if(o&&tL([h.start,h.end],e,i)>=tL(d,e,i)&&!u()){let a=d[0][r.cross],o=tR(e,t,n,a,i,r,{...s,overlapLo:Math.min(s.overlapLo,a),overlapHi:Math.max(s.overlapHi,a),relaxedLo:Math.min(s.relaxedLo,a),relaxedHi:Math.max(s.relaxedHi,a)});if(!("blockers"in o)&&.01>=Math.hypot(o.start.x-d[0].x,o.start.y-d[0].y)&&.01>=Math.hypot(o.end.x-d[1].x,o.end.y-d[1].y))return e.label&&(e.labelPosition=o.slot??void 0),{applied:!0,blockers:[]};"blockers"in o&&l.push(...o.blockers);continue}}return e9(i,e,[h.start,h.end]),e.label&&(e.labelPosition=h.slot??void 0),{applied:!0,blockers:[],usedCandidateIndex:a}}return{applied:!1,blockers:tI(l)}}function tA(e,t,n,i,r=i.axis){let a=tB(e,t,n,i,r);if(!a||a.emptyRelaxed||!eV(t)||!eV(n)||!eK(e.points,r))return null;for(let o of a.candidates)if(!("blockers"in tR(e,t,n,o,i,r,a)))return o;return null}function tF(e,t,n,i,r){let a=eT(n);return{ctx:{nodes:e,edges:t,groups:r,axis:a,style:i},axis:a}}function tO(e,t,n,i=e.labelPosition){if(!e.label||!i)return null;let r=e.labelBlock??o(N(e.label,e.labelContent),n),a=d(i.x,i.y,r);for(let n of t)if(n!==e&&(void 0===e.edgeIndex||n.edgeIndex!==e.edgeIndex))for(let t=1;t<n.points.length;t++){let i=n.points[t-1],r=n.points[t],o=.01>Math.abs(i.x-r.x),s=.01>Math.abs(i.y-r.y);if(!o&&!s)continue;let l=Math.min(i.x,r.x),h=Math.max(i.x,r.x),u=Math.min(i.y,r.y),d=Math.max(i.y,r.y);if(h>=a.x&&l<=a.x+a.w&&d>=a.y&&u<=a.y+a.h)for(let t=1;t<e.points.length;t++){let r=e.points[t-1],a=e.points[t];if(!(o?.01>Math.abs(r.x-a.x)&&4>Math.abs(r.x-i.x):.01>Math.abs(r.y-a.y)&&4>Math.abs(r.y-i.y)))continue;let s=o?Math.min(r.y,a.y):Math.min(r.x,a.x),x=o?Math.max(r.y,a.y):Math.max(r.x,a.x),y=o?u:l;if(Math.min(x,o?d:h)-Math.max(s,y)>.01)return n}}return null}function tz(e,t,n){let i=tL(t.points,t,n);return tL(e,t,n,i)>i}function tj(e,t){let n="cylinder"===t.shape?eo(t).boundary:void 0,i=.5*("rectangle"!==t.shape&&"subroutine"!==t.shape||void 0!==t.semanticShape&&"rect"!==t.semanticShape&&"fr-rect"!==t.semanticShape&&"lin-rect"!==t.semanticShape&&"div-rect"!==t.semanticShape&&"win-pane"!==t.semanticShape);for(let r=1;r<e.length;r++){let a=e[r-1],o=e[r],s=Math.min(a.x,o.x),l=Math.max(a.x,o.x),h=Math.min(a.y,o.y),u=Math.max(a.y,o.y);if(n?.kind==="cylinder"&&n.height>2*n.capRadiusY&&l>t.x&&s<t.x+t.width&&u>n.y+n.capRadiusY&&h<n.y+n.height-n.capRadiusY||l>t.x+i&&s<t.x+t.width-i&&u>t.y+i&&h<t.y+t.height-i)return!0}return!1}function tY(e){return"compound"===e.kind?{...e,children:e.children.map(tY)}:"path"===e.kind?{...e,d:B("d",e.d)}:"polygon"===e.kind||"polyline"===e.kind?{...e,points:e.points.map(tQ)}:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,"number"==typeof t?Number(E(t)):t]))}var tQ=e=>({x:Number(E(e.x)),y:Number(E(e.y))}),tZ=e=>!!e&&Object.values(e).every(Number.isFinite)&&e.x0<=e.x1&&e.y0<=e.y1,tq=(e,t)=>{let n=(Math.abs(e.x0)+Math.abs(e.y0)+Math.abs(e.x1)+Math.abs(e.y1)+Math.abs(t.x0)+Math.abs(t.y0)+Math.abs(t.x1)+Math.abs(t.y1))*1e-10+1e-9;return!Number.isFinite(n)||e.x0<t.x1+n&&t.x0<e.x1+n&&e.y0<t.y1+n&&t.y0<e.y1+n};function tV(e,t,n){if("invisible"===e.style)return{shafts:[],markers:[]};if(e.points.length>eH*eA||void 0!==t.edgeBendRadius&&!(Number.isFinite(t.edgeBendRadius)&&t.edgeBendRadius>=0))return;let i={stroke:e.inlineStyle?.stroke??t.edgeStrokeColor??"var(--_line)",strokeWidth:B("stroke-width",e.inlineStyle?.["stroke-width"]??String((t.lineWidth??1)*("thick"===e.style?2:1)))},r=R(i,e.points.length>2||!!e.curve||(t.edgeBendRadius??0)>0);if(void 0===r||e.points.length<2||(e.hasArrowStart||e.hasArrowEnd)&&void 0===R({...i,stroke:"black"},!1))return;let a=[],o=e=>{if(!n())return!1;let t=W(e,r);return!!tZ(t)&&(r>0&&a.push(t),!0)},s=G(e,t);if(s){if(!L(B("d",s.geometry.d),e=>o(e.bounds),n))return}else{let t=e.points.map(tQ);for(let e=1;e<t.length;e++){let n=t[e-1],i=t[e];if(!o({x0:Math.min(n.x,i.x),y0:Math.min(n.y,i.y),x1:Math.max(n.x,i.x),y1:Math.max(n.y,i.y)}))return}}let l=td(e,t);if(!l)return;for(let e of l)if(!n()||!tZ(e.bounds))return;let u=x(e,t),d=u?h(e,t.lineWidth??1):0,y=u?{x0:u.x-d,y0:u.y-d,x1:u.x+u.w+d,y1:u.y+u.h+d}:void 0;if(!(y&&!tZ(y)))return{shafts:a,markers:l,...y?{label:y}:{}}}function tU(e,t,n,i,r){if(!r(16))return;let a=[],o=[],s=new Map,l=new Map,u=e=>!!r(32)&&("compound"===e.kind?r(e.children.length+1)&&e.children.every(u):"path"===e.kind?r(6*e.d.length+16):"polygon"===e.kind||"polyline"===e.kind?r(772*e.points.length+4):r(3104));for(let t of e){let e=t.inlineStyle?.["stroke-width"]??String(i.nodeLineWidth??S.innerBox);if(!r(512+6*e.length+t.id.length))return;let n=ea(t,{fill:t.inlineStyle?.fill??i.nodeFillColor??"var(--_node-fill)",stroke:t.inlineStyle?.stroke??i.nodeBorderColor??"var(--_node-stroke)",strokeWidth:B("stroke-width",e)},i.cornerRadius);if(!u(n.geometry))return;let o=H({kind:"shape",id:t.id,role:"node",geometry:tY(n.geometry),paint:n.paint,...n.childPaints?{childPaints:n.childPaints}:{}});if(!tZ(o))return;a.push(o)}let d=(e,t=0)=>{if(t>64||!r(e.length+1))return!1;for(let n of e){let e=n.concurrencyRegion?0:n.headerHeight??n.height,a=n.inlineStyle?.["stroke-width"]??String(i.groupLineWidth??S.innerBox);if(!r(3072+6*a.length+88)||!Number.isFinite(e)||e<0||void 0!==i.groupCornerRadius&&!(Number.isFinite(i.groupCornerRadius)&&i.groupCornerRadius>=0))return!1;if(e>0){let t=tY({kind:"rect",x:n.x,y:n.y,width:n.width,height:e}),r={fill:"black",stroke:n.inlineStyle?.stroke??"black",strokeWidth:B("stroke-width",a)},s;if(0===i.groupCornerRadius)s=H({kind:"shape",id:n.id,role:"group-header",geometry:t,paint:r});else{let e=R(r,!0),i=H({kind:"shape",id:n.id,role:"group-header",geometry:t,paint:{fill:"black",stroke:"none"}});if(void 0===e||!tZ(i))return!1;s=W(i,e)}if(!tZ(s))return!1;o.push(s)}if(!d(n.children,t+1))return!1}return!0};if(!d(n))return;for(let e of t){if(e.label&&!e.labelPosition)return;let t=e.inlineStyle?.["stroke-width"]??"",n=e.curve||(i.edgeBendRadius??0)>0?18:4,a=e.inlineStyle?.stroke??i.edgeStrokeColor??"";if(!r(2048+e.points.length*(384*n+32)+8*t.length+(e.label?.length??0)*12+(a.length+e.source.length+e.target.length+(e.id?.length??0))*8))return;let o=tV(e,i,()=>r(1));if(!o)return;s.set(e,o)}let y=(e,t)=>{if(!r(4))return;let n=l.get(e);if(n&&n.x===t.x&&n.y===t.y)return n.box;if(!r(64+(e.label?.length??0)*12))return;let a=x({...e,labelPosition:t},i);if(!a)return;let o=h(e,i.lineWidth??1),s={x0:a.x-o,y0:a.y-o,x1:a.x+a.w+o,y1:a.y+a.h+o};if(!(!tZ(s)||!r(6)))return l.set(e,{x:t.x,y:t.y,box:s}),s};return{clear:(e,n,i,l,h)=>{let u=y(e,n);if(!u)return!1;for(let e of a)if(!r(1)||tq(u,e))return!1;for(let e of o)if(!r(1)||tq(u,e))return!1;let d=!0;for(let n of t){if(!r(1))return!1;let t=s.get(n);for(let e of t.markers)if(!r(1)||!tZ(e.bounds)||tq(u,e.bounds))return!1;if(n===e)continue;for(let e of t.shafts)if(!r(1)||tq(u,e))return!1;if(h instanceof Set?h.has(n):n===h)continue;let a=i.get(n)??n.labelPosition;if(!n.label||!a)continue;let o=y(n,a);if(!o)return!1;if(tq(u,o)){if(l&&!l.has(n)){if(!r(1))return!1;l.add(n)}d=!1}}return d},label:y}}function tJ(e,t,n,i,r){if("feedback"!==t)return null;if(!n||!i)return"feedback-detour";let a=e=>"y"===r.cross?e.height:e.width,o=Math.min(n[r.cross],i[r.cross])-2,s=Math.max(n[r.cross]+a(n),i[r.cross]+a(i))+2;return e.points.some(e=>e[r.cross]<o||e[r.cross]>s)?"outer-feedback":"feedback-detour"}function tT(e){return e.routeCertificate?.invariant==="bundle"&&to(e)}function t_(e){return e.some((t,n)=>n>0&&Math.abs(t.x-e[n-1].x)>.01&&Math.abs(t.y-e[n-1].y)>.01)}function tX(e,t=!1){e.invariant="straight",e.bendCount=0,e.directLaneClear=!0,t&&(e.straightened=!0),e.directLaneBlockedBy=void 0}function tD(e,t,n,i,r){let a,s,u,d,y,c=eJ(t),{axis:f,ctx:g}=e4(e,t,i,c,e=>n.has(e)&&to(e),!!r?.preserveLabels);g.fixedLabels=!!r?.preserveLabels;let p=te(e.nodes),m=function e(t,n=new Map){for(let i of t)n.set(i.id,i),e(i.children,n);return n}(e.groups),M=[],b,$=(e,t)=>{let n="feedback"===t.routeClass?{...f,sign:1===f.sign?-1:1}:f,i=p.get(e.source),a=p.get(e.target);if(!(i&&a&&eV(i)&&eV(a)&&("feedback"===t.routeClass||eK(eD(e.points),n))))return t.invariant=tJ(e,t.routeClass,i,a,g.axis)??"unverified-shape",{applied:!1,mutated:!1};if(r?.preserveStraightRoutes&&2===e.points.length){let r=e.points[0],o=e.points[1],s=f.main,l=f.cross;if(r[l]===o[l]&&0===eZ(e,i,a)&&!tP(e,r[l],Math.min(r[s],o[s]),Math.max(r[s],o[s]),g,n))return tX(t),{applied:!0,mutated:!1}}let o=g.sideUse?.get(`${i.id}:${e2(n,1)}`)??1,s="primary-forward"===t.routeClass&&eU(i)&&1===o&&tM(i)>=tM(a),l=JSON.stringify(e.points);if(s){let r=i[n.cross]+("y"===n.cross?i.height:i.width)/2,o=tH(e,i,a,g,n,r);if(o.applied){let n=JSON.stringify(e.points)!==l;return tX(t,n),{applied:!0,mutated:n}}if(function(e,t,n,i,r){if(e.points.length<2)return!1;let a=t[r.cross]+("y"===r.cross?t.height:t.width)/2,o=n[r.cross],s=o+("y"===r.cross?n.height:n.width),l;if(a<o-.01)l="y"===r.cross?"N":"W";else{if(!(a>s+.01))return!1;l="y"===r.cross?"S":"E"}let h=ej(n)[l][r.cross];if(8>Math.abs(h-a))return!1;let u=ej(n)[e2(r,-1)];if(i.edges.some(t=>t!==e&&t.target===e.target&&t.source!==e.source&&t.points.length>0&&tg(e,t)&&.5>=Math.abs(t.points[t.points.length-1].x-u.x)&&.5>=Math.abs(t.points[t.points.length-1].y-u.y)))return!1;let d=ej(n)[l][r.main],x=e0(t,a,r,1);if(null===x||(d-x)*r.sign<=.01)return!1;let y={...e,points:[],label:void 0};if(tP(e,a,Math.min(x,d),Math.max(x,d),i,r))return!1;let c=e7(r,a,h);if(tP(y,d,Math.min(a,h),Math.max(a,h),i,c))return!1;let f=[e3(r,x,a),e3(r,d,a),e3(r,d,h)];if(!tm(e,f,i.edges,i.style)||!tE(e,i)&&tz(f,e,i))return!1;if(e.label){let t=tW(e,f[0],f[1],i);if(!t)return!1;e.labelPosition=t}return e9(i,e,f),!0}(e,i,a,g,n)||k(e,i,a,g,n,!0))return t.invariant="explained-detour",t.directLaneClear=!1,t.directLaneBlockedBy=tI(o.blockers),t.bendCount=eG(e.points),{applied:!1,mutated:JSON.stringify(e.points)!==l}}let h=tk(e,i,a,g,n);if(h&&k(e,i,a,g,n,!1,{sourceLane:h.sourceLane,targetLane:h.targetLane,preferSourceJog:!0}))return t.invariant="explained-detour",t.directLaneClear=!1,t.directLaneBlockedBy=[{kind:"port",id:tS(e)}],t.bendCount=eG(e.points),{applied:!1,mutated:JSON.stringify(e.points)!==l};let u=tH(e,i,a,g,n);if(u.applied){let n=JSON.stringify(e.points)!==l;return tX(t,n),{applied:!0,mutated:n,upgradeable:(u.usedCandidateIndex??0)>0}}t.invariant=tJ(e,t.routeClass,i,a,g.axis)??"explained-detour",t.directLaneClear=!1,t.directLaneBlockedBy=u.blockers;let d=!1;if("outer-feedback"===t.invariant||"feedback-detour"===t.invariant)"outer-feedback"===t.invariant&&(d=function(e,t,n){let i=eX(e.points);if(i.length<4)return!1;let r=t.axis,a=e=>e[r.cross],o=e=>e[r.main],s=-1,l=.01;for(let e=1;e<i.length;e++){if(Math.abs(a(i[e-1])-a(i[e]))>=.01)continue;let t=(o(i[e-1])-o(i[e]))*r.sign;t>l&&(l=t,s=e-1)}if(s<1)return!1;let h=a(i[s]),u=[i[s],i[s+1]],d=Math.sign(o(u[1])-o(u[0])),y=i[0],c=t.nodes.find(t=>t.id===e.source),f=e=>d>0?e>=o(u[0])-.01&&e<o(u[1])-.01:e<=o(u[0])+.01&&e>o(u[1])+.01,g=(n,i)=>{if(.01>Math.abs(i-h))return!0;let a="x"===r.main?{main:"y",cross:"x",sign:i<h?1:-1}:{main:"x",cross:"y",sign:i<h?1:-1};return 0===tC({...e,points:[],label:void 0},n,Math.min(i,h),Math.max(i,h),t,a).length},p=(e,t,n)=>{let a=e3(r,e,h);return .01>Math.abs(t-h)?[a,...i.slice(s+1)]:[n,a,...i.slice(s+1)]},m=null;if(c&&eV(c)){let e=c[r.cross],t="y"===r.cross?h>e?"S":"N":h>e?"E":"W",n=ej(c)[t],i=n[r.cross],a=n[r.main];f(a)&&g(a,i)&&(m=p(a,i,n))}if(!m&&c){let e=d===r.sign?1:-1,t=e1(c,r,e);if("dynamic"===eo(c).sides[e2(r,e)].kind&&t&&h>=t.lo-.01&&h<=t.hi+.01){let t=e0(c,h,r,e);if(null!==t&&f(t)&&g(t,h)){let e=e3(r,t,h);m=p(t,h,e)}}}if(!m&&f(o(y))&&g(o(y),a(y))&&(m=p(o(y),a(y),y)),!m&&2===s&&.01>Math.abs(a(i[1])-a(y))&&t.edges.some(n=>n.source===e.source&&n!==e&&tO(n,t.edges,t.style))){let n=Math.sign(o(i[1])-o(y)),l=[o(y)+12*n];for(let i of t.edges){if(i===e)continue;for(let e of i.points)l.push(o(e)+12*n);let a=x(i,t.style);a&&l.push(("x"===r.main?a.x+(n>0?a.w:0):a.y+(n>0?a.h:0))+4.01*n)}for(let u of(l.sort((e,t)=>(e-t)*n),l)){if((u-o(y))*n<11.99||(o(i[1])-u)*n<=.01||!f(u)||!g(u,a(y)))continue;let l="x"===r.main?{x:u,y:a(y)}:{x:a(y),y:u},d=[y,l,"x"===r.main?{x:u,y:h}:{x:h,y:u},...i.slice(s+1)];if(!(tL(d,e,t)>tL(i,e,t))){m=d;break}}}let M=m??i;{let n=-1;for(let e=1;e<M.length;e++)if(.01>Math.abs(a(M[e-1])-h)&&.01>Math.abs(a(M[e])-h)){n=e-1;break}let i=t.nodes.find(t=>t.id===e.target);if(n>=0&&n+1<M.length-1&&i&&eV(i)){let e=i[r.cross],t="y"===r.cross?h>e?"S":"N":h>e?"E":"W",a=ej(i)[t],s=a[r.cross],l=a[r.main],u=M[n],d=M[n+1];if((Math.sign(o(d)-o(u))>0?l>o(u)+.01&&l<=o(d)+.01:l<o(u)-.01&&l>=o(d)-.01)&&g(l,s)){let e=e3(r,l,h);m=[...M.slice(0,n+1),e,a]}}}if(!m)return!1;let b=eX(m),$=n.get(e.target);if(eZ({...e,points:b},c,$)>0)return!1;let w=R({stroke:"black",strokeWidth:B("stroke-width",e.inlineStyle?.["stroke-width"]??String((t.style.lineWidth??S.connector)*("thick"===e.style?2:1)))},!0);if(!c||!$||void 0===w)return!1;let k=e=>{let n=R({stroke:"black",strokeWidth:B("stroke-width",e.inlineStyle?.["stroke-width"]??String(t.style.nodeLineWidth??S.innerBox))},!0);if(void 0===n)return;let i=Math.max(4,n+w)+.01,r=e.x-i,a=e.y-i,o=e.width+2*i,s=e.height+2*i;if([r,a,o,s].every(Number.isFinite))return{...e,shape:"rectangle",semanticShape:void 0,x:r,y:a,width:o,height:s}},v=k(c),C=k($);if(!v||!C||tj(b.slice(1),v)||tj(b.slice(0,-1),C)||tz(b,e,t)||!tm(e,b,t.edges,t.style))return!1;let P=e.points;if(e9(t,e,b),e.label&&e.labelPosition){let n=e.labelPosition;if(!e.points.some((t,i)=>{if(0===i)return!1;let r=e.points[i-1],a=Math.min(r.x,t.x)-1,o=Math.max(r.x,t.x)+1,s=Math.min(r.y,t.y)-1,l=Math.max(r.y,t.y)+1;return n.x>=a&&n.x<=o&&n.y>=s&&n.y<=l})){let n=null;for(let i=1;i<e.points.length;i++){let r=e.points[i-1],o=e.points[i];if(.01>Math.abs(a(r)-h)&&.01>Math.abs(a(o)-h)){n=tW(e,r,o,t);break}}if(!n)return e9(t,e,P),!1;e.labelPosition=n}}return JSON.stringify(e.points)!==JSON.stringify(P)}(e,g,p),t.bendCount=eG(e.points)),tE(e,g)&&k(e,i,a,g,n)&&(t.bendCount=eG(e.points),d=!0);else if("explained-detour"===t.invariant&&(t.bendCount>2||t_(e.points)||tE(e,g)||!eQ(i,e.points[0])||!eQ(a,e.points[e.points.length-1]))){let r=k(e,i,a,g,n)||function(e,t,n,i,r){if(!tE(e,i))return!1;let a=e1(t,r,1),o=e1(n,r,-1);if(!a||!o)return!1;let s={...e,points:[],label:void 0},l=e=>"y"===r.cross?e.height:e.width,h=e=>"x"===r.main?e.width:e.height,u=t[r.cross]+l(t)/2,d=e0(t,u,r,1),x=n[r.cross]+l(n)/2,y=e0(n,x,r,-1);if(null===d||null===y||Math.abs(u-a.lo)>.01&&Math.abs(u-a.hi)>.01&&(u<a.lo-.01||u>a.hi+.01))return!1;let c=[];for(let t of i.nodes){if(t.id===e.source||t.id===e.target)continue;let n=t[r.main],i=n+h(t),a=(n-d)*r.sign>.01||(i-d)*r.sign>.01,o=(y-n)*r.sign>.01||(y-i)*r.sign>.01;if(!a||!o)continue;let s=r.sign>0?n:i;c.push({mainNear:s,crossLo:t[r.cross],crossHi:t[r.cross]+l(t)})}let f=c.filter(e=>u>e.crossLo-4&&u<e.crossHi+4);if(0===f.length)return!1;let g=f.reduce((e,t)=>(t.mainNear-d)*r.sign<(e-d)*r.sign?t.mainNear:e,f[0].mainNear);if((g-d)*r.sign<=4)return!1;let p=d+(g-d)/2,m=[x];w(e,x,r)&&m.push(x+12,x-12);let M=[],b=e=>{M.every(t=>Math.abs(t-e)>.5)&&M.push(e)};for(let e of c)b(e.crossLo-4-.01),b(e.crossHi+4+.01);let $=[...c].sort((e,t)=>e.crossLo-t.crossLo);for(let e=1;e<$.length;e++){let t=$[e-1].crossHi,n=$[e].crossLo;n-t>8&&b((t+n)/2)}M.sort((e,t)=>Math.abs(e-u)-Math.abs(t-u));let k=null;for(let t of m){if(t<o.lo-.01||t>o.hi+.01)continue;let a=e0(n,t,r,-1);if(null===a)continue;let l=a-r.sign*eO(i.style,e,"end");if(!((l-p)*r.sign<=.01))for(let n of M){if(4>Math.abs(n-u)||tP(s,u,Math.min(d,p),Math.max(d,p),i,r)||tP(s,p,Math.min(u,n),Math.max(u,n),i,e7(r,u,n))||tP(s,n,Math.min(p,l),Math.max(p,l),i,r)||tP(s,l,Math.min(n,t),Math.max(n,t),i,e7(r,n,t))||tP(s,t,Math.min(l,a),Math.max(l,a),i,r))continue;let o=eX([e3(r,d,u),e3(r,p,u),e3(r,p,n),e3(r,l,n),e3(r,l,t),e3(r,a,t)]);if(!tm(e,o,i.edges,i.style))continue;let h=[e3(r,p,n),e3(r,l,n)];if(e.label){let t=tW(e,h[0],h[1],i);if(t)return e.labelPosition=t,e9(i,e,o),!0;k||(k={route:o,labelMid:{x:(h[0].x+h[1].x)/2,y:(h[0].y+h[1].y)/2}});continue}return e9(i,e,o),!0}}return!!k&&(e9(i,e,k.route),e.label&&(e.labelPosition=k.labelMid),!0)}(e,i,a,g,n);((function(e,t,n,i){let r;if(e.points.length<3||!n.edges.some(t=>t!==e&&t.target===e.target))return!1;let a=ej(t);if(!(w(e,r=a[e2(i,-1)][i.cross],i)||g.edges.some(t=>{if(t===e||t.target!==e.target||t.source===e.target||tg(e,t))return!1;let n=p.get(t.source);return void 0!==n&&.5>=Math.abs(n[i.cross]+("y"===i.cross?n.height:n.width)/2-r)})))return!1;let o=t[i.cross],s=o+("y"===i.cross?t.height:t.width),l=-1;for(let t=e.points.length-1;t>0&&l<0;t--){let n=e.points[t-1],r=e.points[t],a=r[i.cross];.01>=Math.abs(n[i.cross]-a)&&Math.abs(n[i.main]-r[i.main])>.01&&(a<=o-4||a>=s+4)&&(l=t)}if(l<1)return!1;let h=e.points[l][i.cross],u=a["y"===i.cross?h<o?"N":"S":h<o?"W":"E"],d=e.points[l-1];if((u[i.main]-d[i.main])*Math.sign(e.points[l][i.main]-d[i.main])<=.01)return!1;let x={...e,points:[],label:void 0};if(tP(x,h,Math.min(d[i.main],u[i.main]),Math.max(d[i.main],u[i.main]),n,i))return!1;let y=e7(i,h,u[i.cross]);if(tP(x,u[i.main],Math.min(h,u[i.cross]),Math.max(h,u[i.cross]),n,y))return!1;let c=eX([...e.points.slice(0,l),e3(i,u[i.main],h),u]);if(eG(c)>eG(e.points)||tz(c,e,n)||!tm(e,c,n.edges,n.style))return!1;if(e.label){let t;for(let e=1;e<c.length;e++){let n=Math.abs(c[e].x-c[e-1].x)+Math.abs(c[e].y-c[e-1].y);(!t||n>Math.abs(t[1].x-t[0].x)+Math.abs(t[1].y-t[0].y))&&(t=[c[e-1],c[e]])}let i=t&&tW(e,t[0],t[1],n);if(!i)return!1;e.labelPosition=i}return e9(n,e,c),!0})(e,a,g,n)||r)&&(t.bendCount=eG(e.points),d=!0)}return{applied:!1,mutated:d}},w=(e,t,n)=>g.edges.some(i=>i!==e&&i.target===e.target&&i.points.length>1&&.5>=Math.abs(i.points.at(-1)[n.cross]-t)&&!tg(e,i));function k(e,t,n,i,r,a=!1,o){if(e.points.length<2)return!1;let s=e1(t,r,1),l=e1(n,r,-1);if(!s||!l)return!1;let h=e.points.map(e=>e[r.cross]),u=[],d=[],x=(e,t)=>{e.every(e=>Math.abs(e-t)>.5)&&e.push(t)};if(o?.sourceLane!==void 0)x(u,o.sourceLane);else if(x(u,t[r.cross]+("y"===r.cross?t.height:t.width)/2),!a)for(let t of(x(u,e.points[0][r.cross]),h))x(u,t);if(o?.targetLane!==void 0)x(d,o.targetLane);else{let t=n[r.cross]+("y"===r.cross?n.height:n.width)/2;if(i.edges.some(n=>{if(n===e||n.target!==e.target||n.source===e.target||tg(e,n))return!1;let i=p.get(n.source);return void 0!==i&&.5>=Math.abs(i[r.cross]+("y"===r.cross?i.height:i.width)/2-t)})&&x(d,e.points[e.points.length-1][r.cross]),x(d,t),x(d,e.points[e.points.length-1][r.cross]),w(e,t,r))for(let e of[12,-12])x(d,t+e)}let y=e=>{let t=e[r.main];return[t,t+("x"===r.main?e.width:e.height)]},[c,f]=y(t),[g,m]=y(n),M=Math.min(c,f,g,m),b=Math.max(c,f,g,m),$=(t,n)=>{if(n)for(let a of i.nodes){if(a.id===e.source||a.id===e.target)continue;let[i,o]=y(a);if(o<=M+.01||i>=b-.01)continue;let s=a[r.cross],l=s+("y"===r.cross?a.height:a.width);for(let e of[s-4-.01,l+4+.01])e>=n.lo-.01&&e<=n.hi+.01&&x(t,e)}};$(u,o?.sourceLane===void 0?s:null),$(d,o?.targetLane===void 0?l:null);let v=(e,t)=>eU(e)?{lo:e[r.cross]+2,hi:e[r.cross]+("y"===r.cross?e.height:e.width)-2}:t,S=v(t,s),C=v(n,l),P=!o?.requireFewerCrossings&&tE(e,i),N=null,W={...e,points:[],label:void 0},L,E=!z(),I,B=eO(i.style,e,"start"),R=eO(i.style,e,"end");for(let a of d){if(a<C.lo-.01||a>C.hi+.01)continue;let s=e0(n,a,r,-1);if(null!==s)for(let l=0;l<u.length;l++){let h=u[l];if(h<S.lo-.01||h>S.hi+.01||4>Math.abs(h-a))continue;let d=e0(t,h,r,1);if(null===d||o?.requireFewerCrossings&&(d!==(1===r.sign?f:c)||s!==(1===r.sign?g:m))||(s-d)*r.sign<=.01)continue;let x=o?.preferSourceJog?[d+r.sign*B,(d+s)/2,s-r.sign*R]:[s-r.sign*R,(d+s)/2,d+r.sign*B];for(let u=0;u<x.length;u++){let y=x[u];if((y-d)*r.sign<=.01||(s-y)*r.sign<=.01)continue;let c=Math.abs(y-d)>=Math.abs(s-y),f=E?(3*l+u)*2+Number(c):0,g=E?I?.[f]:void 0,p;if(g&&Object.is(g.jog,y)?p=g.blocked:(p=tP(c?e:W,h,Math.min(d,y),Math.max(d,y),i,r),E&&(g?(g.jog=y,g.blocked=p):(I??=[])[f]={jog:y,blocked:p})),p)continue;let m=e7(r,h,a);if(tP(W,y,Math.min(h,a),Math.max(h,a),i,m)||tP(c?W:e,a,Math.min(y,s),Math.max(y,s),i,r))continue;let M=[e3(r,d,h),e3(r,y,h),e3(r,y,a),e3(r,s,a)],b=c?[M[0],M[1]]:[M[2],M[3]],$=null;if(e.label){if(!($=tW(e,b[0],b[1],i))){let t=c?tW(e,M[2],M[3],i):tW(e,M[0],M[1],i);t&&!tP(e,c?a:h,Math.min(c?y:d,c?s:y),Math.max(c?y:d,c?s:y),i,r)&&($=t)}if(!$&&!(P&&!N))continue}if(!tm(e,M,i.edges,i.style))continue;let w=+!!eQ(t,e.points[0])+ +!!eQ(n,e.points.at(-1)),k=+!!eQ(t,M[0])+ +!!eQ(n,M.at(-1));L??=P?0:tL(e.points,e,i);let v=P?0:tL(M,e,i,L);if(!(!P&&v>L)&&!(o?.requireFewerCrossings&&v>=L)&&!(!P&&v>=L&&eZ({...e,points:M},t,n)>=eZ(e,t,n)&&(eG(M)>eG(e.points)||eG(M)===eG(e.points)&&k<w))){if(e.label){if(!$){P&&!N&&(N={route:M,labelMid:{x:(b[0].x+b[1].x)/2,y:(b[0].y+b[1].y)/2}});continue}e.labelPosition=$}return e9(i,e,M),!0}}}}return!!N&&(e9(i,e,N.route),e.label&&(e.labelPosition=N.labelMid),!0)}let v=[],C=(a=g.style,s=new Map,u=[],d=new Map,y=(e,t)=>Math.min(e.x+e.w,t.x+t.w)>Math.max(e.x,t.x)&&Math.min(e.y+e.h,t.y+t.h)>Math.max(e.y,t.y),e=>{let t=p.get(e.source);if(!t)return null;let n=t.x+t.width/2,i=t.y+t.height/2,r=e.points.slice(1,-1),c=r.length>0?{x:r.reduce((e,t)=>e+t.x,0)/r.length,y:r.reduce((e,t)=>e+t.y,0)/r.length}:e.points[0]??{x:t.x,y:i},f=(c.x-n)/Math.max(t.width/2,1),M=(c.y-i)/Math.max(t.height/2,1),b=Math.abs(f)>=Math.abs(M)?f<0?"W":"E":M<0?"N":"S",$=[b,function(e){switch(e){case"N":return"S";case"S":return"N";case"E":return"W";case"W":return"E"}}(b),..."W"===b||"E"===b?["N","S"]:["W","E"]],w=e.label?e.labelBlock??o(N(e.label,e.labelContent),a):null,k=e=>w?("N"===e||"S"===e?w.height:w.width)+2*l:0,C=e=>"N"===e||"S"===e?t.width:t.height,P=e=>`${t.id}:${e}`,W=e=>s.get(P(e))??0,L=e=>Math.min(Math.max(C(e)/4,6),10,Math.max(C(e)/2-2,3)),E=e=>L(e)+6*W(e)<=C(e)/2-2,I=r=>{let o=W(r),s=L(r)+6*o;return{d:s,desired:24+o*Math.max(14,k(r)+8),clear:((r,o)=>{let s="N"===r||"S"===r,l=s?n:i,h=l-o-6,u=l+o+6,d="W"===r?t.x:"E"===r?t.x+t.width:"N"===r?t.y:t.y+t.height,y="W"===r||"N"===r?-1:1,c=1e3,f=(e,t,n,i)=>{if(t<h||e>u)return;let r=(n-d)*y;r>0&&(c=Math.min(c,r-(i?2:6)))};for(let e of g.nodes)e.id!==t.id&&f(s?e.x:e.y,s?e.x+e.width:e.y+e.height,s?y<0?e.y+e.height:e.y:y<0?e.x+e.width:e.x,!1);for(let e of m.values())if(n>e.x&&n<e.x+e.width&&i>e.y&&i<e.y+e.height){let t=((s?y<0?e.y:e.y+e.height:y<0?e.x:e.x+e.width)-d)*y;t>0&&(c=Math.min(c,t-4))}else f(s?e.x:e.y,s?e.x+e.width:e.y+e.height,s?y<0?e.y+e.height:e.y:y<0?e.x+e.width:e.x,!1);for(let t of g.edges){if(t===e||t.source===t.target||!t.label)continue;let n=x(t,a);n&&f(s?n.x:n.y,s?n.x+n.w:n.y+n.h,s?y<0?n.y+n.h:n.y:y<0?n.x+n.w:n.x,!1)}return c})(r,s)}},B=(r,o)=>{let s=Math.max(Math.min(o.desired,o.clear),8),c=o.d,f=ev(ev((()=>{switch(r){case"W":return[{x:t.x,y:i-c},{x:t.x-s,y:i-c},{x:t.x-s,y:i+c},{x:t.x,y:i+c}];case"E":return[{x:t.x+t.width,y:i-c},{x:t.x+t.width+s,y:i-c},{x:t.x+t.width+s,y:i+c},{x:t.x+t.width,y:i+c}];case"N":return[{x:n-c,y:t.y},{x:n-c,y:t.y-s},{x:n+c,y:t.y-s},{x:n+c,y:t.y}];default:return[{x:n-c,y:t.y+t.height},{x:n-c,y:t.y+t.height+s},{x:n+c,y:t.y+t.height+s},{x:n+c,y:t.y+t.height}]}})(),t,!0),t,!1),p=tp(e,f,g.edges,a);if(p)return v?.push(p),null;let M=((r,o,s)=>{if(!e.label||!w)return[];let c="N"===r||"S"===r,f="W"===r||"N"===r?-1:1,p="W"===r||"S"===r?-1:1,M=("W"===r?t.x:"E"===r?t.x+t.width:"N"===r?t.y:t.y+t.height)+f*(o+k(r)/2+4),b=(c?w.width:w.height)+2*l+2,$=W(r),v=c?{x:n,y:M}:{x:M,y:i},C=e=>({x:e.x-w.width/2-l,y:e.y-w.height/2-l,w:w.width+2*l,h:w.height+2*l}),N=P(r),L=d.get(N)??[],E=[],I=u.slice();if($>0){for(let e of L){let t=e.edge.labelPosition,r=c?{x:n-p*b,y:t.y}:{x:t.x,y:i-p*b};E.push({edge:e.edge,position:r,rectIndex:e.rectIndex}),I[e.rectIndex]=x({...e.edge,labelPosition:r},a)}v=c?{x:n+p*b*$,y:M}:{x:M,y:i+p*b*$}}if(I.some(e=>y(C(v),e)))for(let e=0;e<8;e++){let t=e%2==0?p:-p,r=(1+Math.floor(e/2))*b,a=c?{x:n+t*r,y:M}:{x:M,y:i+t*r};if(!I.some(e=>y(C(a),e))){v=a;break}}E.push({edge:e,position:v});let B=new Map(E.map(e=>[e.edge,e.position])),A=(e,t)=>{let n=x({...e,labelPosition:t},a);if(!n)return null;let i=h(e,a.lineWidth??1);return{x:n.x-i,y:n.y-i,w:n.w+2*i,h:n.h+2*i}};for(let t of E){let n=A(t.edge,t.position),i=x({...t.edge,labelPosition:t.position},a);if(!n||!i||!Object.values(n).every(Number.isFinite))return null;let r=t.edge===e?s:t.edge.points,o=1/0;for(let e=1;e<r.length;e++){let t=r[e-1],n=r[e];if(t.x!==n.x&&t.y!==n.y)return null;o=Math.min(o,Math.max(i.x-Math.max(t.x,n.x),Math.min(t.x,n.x)-i.x-i.w,0)+Math.max(i.y-Math.max(t.y,n.y),Math.min(t.y,n.y)-i.y-i.h,0))}if(!(o<=i.h/2+4))return null;let l=(e,t,i,r)=>{let a=(Math.abs(e)+Math.abs(t)+Math.abs(i)+Math.abs(r)+Math.abs(n.x)+Math.abs(n.y)+n.w+n.h)*1e-10+1e-9;return!Number.isFinite(a)||y(n,{x:e-a,y:t-a,w:i+2*a,h:r+2*a})};for(let e of g.nodes){let t=ea(e,{fill:e.inlineStyle?.fill??a.nodeFillColor??"var(--_node-fill)",stroke:e.inlineStyle?.stroke??a.nodeBorderColor??"var(--_node-stroke)",strokeWidth:e.inlineStyle?.["stroke-width"]??String(a.nodeLineWidth??S.innerBox)},a.cornerRadius??0),n=H({kind:"shape",id:e.id,role:"node",geometry:t.geometry,paint:t.paint,...t.childPaints?{childPaints:t.childPaints}:{}});if(!n||l(n.x0,n.y0,n.x1-n.x0,n.y1-n.y0))return null}for(let e of m.values()){let t=e.concurrencyRegion?0:e.headerHeight??e.height;if(!Number.isFinite(t)||t<0)return null;let n=R({stroke:e.inlineStyle?.stroke??"black",strokeWidth:e.inlineStyle?.["stroke-width"]??String(a.groupLineWidth??S.innerBox)},!0);if(void 0===n||t>0&&l(e.x-n,e.y-n,e.width+2*n,t+2*n))return null}for(let n of g.edges){let i=td(n===e?{...n,points:s}:n,a);if(!i||i.some(e=>!e.bounds||l(e.bounds.x0,e.bounds.y0,e.bounds.x1-e.bounds.x0,e.bounds.y1-e.bounds.y0)))return null;if(n===t.edge||!n.label)continue;let r=B.get(n)??n.labelPosition;if(!r)continue;let o=A(n,r);if(!o||l(o.x,o.y,o.w,o.h))return null}}return E})(r,s,f);return M?{points:f,labels:M}:null},A=null,F=null,O=null,z=[],j=$.map((e,t)=>({side:e,preference:t,rank:W(e)})).sort((e,t)=>e.rank-t.rank||e.preference-t.preference).map(e=>e.side);for(let e of j){if(!E(e))continue;let t=I(e);if(t.clear<Math.min(t.desired,14))continue;let n=B(e,t);if(n){A=e,F=t,O=n.points,z=n.labels;break}}if(!A||!F||!O){let e=j.filter(E);if(0===e.length)return null;let t=e.reduce((e,t)=>I(t).clear>I(e).clear?t:e,e[0]),n=I(t),i=B(t,n);if(!i)return null;A=t,F=n,O=i.points,z=i.labels}s.set(P(A),W(A)+1),e9(g,e,O);let Y=P(A),Q=d.get(Y)??[];for(let e of z){e.edge.labelPosition=e.position;let t=x(e.edge,a);if(void 0!==e.rectIndex)u[e.rectIndex]=t;else{let n=u.push(t)-1;Q.push({edge:e.edge,rectIndex:n})}}return z.length&&d.set(Y,Q),A}),P=[];for(let i of e.edges){let a=n.has(i)?ts(i):void 0,o=eX(eD(i.points)),s=p.get(i.source),l=p.get(i.target);s&&(o=ek(o,s,!0)),l&&(o=ek(o,l,!1)),tm(i,o,g.edges,g.style)&&e9(g,i,o),tl(i,a);let h=i.edgeIndex??-1,u=c[h]??"primary-forward",d={edgeIndex:h,routeClass:u,bendCount:eG(i.points),invariant:"straight"};if(n.has(i)&&to(i))d.invariant="bundle";else if("self-loop"===u){let e;if(r?.preserveSelfLoops){let t=p.get(i.source),n=(e,t)=>.01>=Math.abs(e.x-t.x)&&Math.abs(e.y-t.y)>.01?t.y>e.y?"S":"N":.01>=Math.abs(e.y-t.y)&&Math.abs(e.x-t.x)>.01?t.x>e.x?"E":"W":void 0,r=i.points[0],a=i.points.at(-1),o=r&&i.points.find(e=>Math.hypot(e.x-r.x,e.y-r.y)>.01),s=a&&[...i.points].reverse().find(e=>Math.hypot(e.x-a.x,e.y-a.y)>.01);e=t&&r&&a&&o&&s&&Math.hypot(r.x-a.x,r.y-a.y)>=8&&n(r,o)===n(a,s)?n(r,o):void 0}v.length=0;let t=e??C(i);t?(d.invariant="self-loop",d.loopSide=t,d.bendCount=eG(i.points)):(d.invariant="explained-detour",v.length&&(d.directLaneBlockedBy=[...v]))}else if("container"===u){d.invariant="container-attach";let n=function(e,t,n){let i=e=>{let i=t.get(e);if(i)return{id:e,label:"",shape:"rectangle",x:i.x,y:i.y,width:i.width,height:i.height};let r=n.get(e);return r&&eV(r)?r:null},r=i(e.source),a=i(e.target);if(!r||!a)return null;let o=eX(e.points);if(2===o.length&&t1(o[0],r.x,r.y,r.width,r.height,1)&&t1(o[1],a.x,a.y,a.width,a.height,1))return null;let s=[{gap:a.y-(r.y+r.height),axis:{main:"y",cross:"x",sign:1}},{gap:r.y-(a.y+a.height),axis:{main:"y",cross:"x",sign:-1}},{gap:a.x-(r.x+r.width),axis:{main:"x",cross:"y",sign:1}},{gap:r.x-(a.x+a.width),axis:{main:"x",cross:"y",sign:-1}}].filter(e=>e.gap>.01).sort((e,t)=>t.gap-e.gap)[0];return s?{source:r,target:a,axis:s.axis}:null}(i,m,p);if(n){let r=tH(i,n.source,n.target,g,n.axis).applied,a=!r&&(b??=eF(t)&&!z()&&!e.edges.some(e=>e.label))&&tL(i.points,i,g)>0&&k(i,n.source,n.target,g,n.axis,!1,{requireFewerCrossings:!0});(r||a)&&(d.bendCount=eG(i.points),r&&(d.directLaneClear=!0,d.straightened=!0))}}else if("primary-forward"===u||"feedback"===u)if(d.bendCount>0){let e=$(i,d);(!e.applied||e.upgradeable)&&P.push({edge:i,cert:d})}else{let t=p.get(i.source),n=p.get(i.target),r=!i.label&&void 0!==i.edgeIndex&&e.edges.some(e=>e!==i&&e.source===i.target&&e.target===i.source&&!e.label&&void 0!==e.edgeIndex),[a,o]=[i.points[0],i.points[i.points.length-1]];if(t&&n&&(t_(i.points)||!eQ(t,a)||!eQ(n,o)||eZ(i,t,n)>0||tE(i,g)||r)){let e=$(i,d);(!e.applied||e.upgradeable)&&P.push({edge:i,cert:d})}}M.push({edge:i,cert:d})}for(let e=0;e<4&&P.length>0;e++){let e=[],t=!1;for(let n of P){if("unverified-shape"===n.cert.invariant)continue;let i=$(n.edge,n.cert);i.mutated&&(t=!0),(!i.applied||i.upgradeable)&&e.push(n)}if(!t)break;P.length=0,P.push(...e)}for(let t of e.edges){let e=n.has(t)?ts(t):void 0,i=p.get(t.source),r=p.get(t.target);i&&t$(t,i,!0,g),r&&t$(t,r,!1,g);let a=t.points;i&&(a=ek(a,i,!0)),r&&(a=ek(a,r,!1)),tm(t,a,g.edges,g.style)&&e9(g,t,a),tl(t,e)}let W=[],L=e6(e,t,c),E=(e,t)=>{let n=eG(e.points),i=p.get(e.source),r=p.get(e.target),a=L.byEdge.get(e),o={edgeIndex:t.edgeIndex,routeClass:t.routeClass,bendCount:n,directLaneClear:t.directLaneClear,directLaneBlockedBy:t.directLaneBlockedBy,sourcePort:i&&e.points.length>0?eQ(i,e.points[0]):void 0,targetPort:r&&e.points.length>0?eQ(r,e.points[e.points.length-1]):void 0,sourcePortAssignment:a?.source,targetPortAssignment:a?.target,...void 0!==t.loopSide?{loopSide:t.loopSide}:{}};return"straight"===t.invariant&&0===n&&2===e.points.length?{...o,invariant:"straight",...t.straightened?{straightened:!0}:{}}:{...o,invariant:"straight"===t.invariant?"explained-detour":t.invariant}};for(let{edge:e,cert:t}of M){let n=E(e,t);e.routeCertificate=n,W.push(n)}return W}function tG(e,t,n,i){if(!t){e.routeCertificate=void 0;return}let r={edgeIndex:t.edgeIndex,routeClass:t.routeClass,bendCount:eG(e.points),directLaneClear:t.directLaneClear,directLaneBlockedBy:t.directLaneBlockedBy,sourcePort:n&&e.points.length>0?eQ(n,e.points[0]):t.sourcePort,targetPort:i&&e.points.length>0?eQ(i,e.points[e.points.length-1]):t.targetPort,sourcePortAssignment:t.sourcePortAssignment,targetPortAssignment:t.targetPortAssignment,...void 0!==t.loopSide?{loopSide:t.loopSide}:{}};if(2===e.points.length&&0===eG(e.points)){e.routeCertificate={...r,invariant:"straight"};return}e.routeCertificate={...r,invariant:"straight"!==t.invariant&&("bundle"!==t.invariant||to(e))?t.invariant:"explained-detour"}}function tK(e,t,n,i){let r=[];for(let t of e.edges)void 0!==t.edgeIndex&&t.routeCertificate&&(r[t.edgeIndex]=t.routeCertificate.routeClass);let{axis:a,ctx:o}=e4(e,t,n,r,tT,!0),s=te(e.nodes),l=o.sideUse,h=[],u=new Set;for(let t of e.edges){let e=t.routeCertificate;if(!e||tT(t)||"primary-forward"!==e.routeClass&&"feedback"!==e.routeClass)continue;let n="feedback"===e.routeClass?{...a,sign:1===a.sign?-1:1}:a,r=eX(t.points);if(r.length<=2)continue;let d=s.get(t.source),x=s.get(t.target);if(!d||!x||!eV(d)||!eV(x)||"feedback"!==e.routeClass&&!eK(r,n))continue;let y=tk(t,d,x,o,n);if(y&&function(e,t,n,i){if(e.points.length<=2)return!1;let r=e.points[0],a=e.points[e.points.length-1],o=tb(t,i.sourcePort),s=ej(n)[i.targetPort];return .5>=Math.abs(r.x-o.x)&&.5>=Math.abs(r.y-o.y)&&.5>=Math.abs(a.x-s.x)&&.5>=Math.abs(a.y-s.y)}(t,d,x,y))continue;let c=l.get(`${t.source}:${e2(n,1)}`)??1,f="primary-forward"===e.routeClass&&eU(d)&&1===c&&tM(d)>=tM(x)?d[n.cross]+("y"===n.cross?d.height:d.width)/2:void 0;tH(i?t:{...t,points:r.map(e=>({...e}))},d,x,o,n,f,t).applied&&(h.push({edge:tS(t),deviationPx:Math.round(10*function(e,t){let n=1/0,i=-1/0;for(let r of e)n=Math.min(n,r[t.cross]),i=Math.max(i,r[t.cross]);return i-n}(r,n))/10}),i&&u.add(t))}if(u.size>0){let n=e6(e,t,r);for(let e of u){let t=e.routeCertificate;if(!t||2!==e.points.length||0!==eG(e.points))continue;let i=s.get(e.source),r=s.get(e.target),a=n.byEdge.get(e);e.routeCertificate={edgeIndex:t.edgeIndex,routeClass:t.routeClass,invariant:"straight",bendCount:0,directLaneClear:!0,sourcePort:i?eQ(i,e.points[0]):void 0,targetPort:r?eQ(r,e.points[1]):void 0,sourcePortAssignment:a?.source,targetPortAssignment:a?.target,straightened:!0}}}return h}function t1(e,t,n,i,r,a){let o=(Math.abs(e.x-t)<=a||Math.abs(e.x-(t+i))<=a)&&e.y>=n-a&&e.y<=n+r+a,s=(Math.abs(e.y-n)<=a||Math.abs(e.y-(n+r))<=a)&&e.x>=t-a&&e.x<=t+i+a;return o||s}var t0=Symbol("label-seat-sort-denied");function t2(e,t){if(t&&!t(1))return;let n=[];for(let i=1;i<e.points.length;i++){if(t&&!t(2))return;let r=e.points[i-1],a=e.points[i],o=.01>Math.abs(r.x-a.x);if(o||.01>Math.abs(r.y-a.y)){if(t&&!t(12))return;n.push({a:r,b:a,vertical:o,len:Math.abs(r.x-a.x)+Math.abs(r.y-a.y),i:i})}}if(!t||t(2*n.length+1)){try{n.sort((e,n)=>{if(t&&!t(4))throw t0;return n.len-e.len||e.i-n.i})}catch(e){if(e===t0)return;throw e}return n}}function t5(e,t){t?.();let n=[];for(let i=0;i<11;i++)t?.(),n.push(e+i/10*(1-2*e));return n.sort((e,n)=>(t?.(),Math.abs(e-.5)-Math.abs(n-.5)))}function t8(e,t){return h(e,t.lineWidth??1)}function t6(e,t,n){n?.();let i,r=(e,t)=>t.some(t=>{n?.();let i=t.concurrencyRegion?0:t.headerHeight??t.height;return i>0&&e.x<t.x+t.width&&e.x+e.w>t.x&&e.y<t.y+i&&e.y+e.h>t.y||r(e,t.children)}),a=r=>{for(let a of z()?e.edges.flatMap(e=>(n?.(),K(e,t))):i??=e.edges.flatMap(e=>(n?.(),K(e,t)))){n?.();let e=a.bounds;if(e&&r.x<e.x1&&r.x+r.w>e.x0&&r.y<e.y1&&r.y+r.h>e.y0)return!0}return!1};return{overlapsMarker:a,clearPaintRect:(i,o,s)=>{n?.();let l={x:i.x-o,y:i.y-o,w:i.w+2*o,h:i.h+2*o},h=t.lineWidth??1,d=u(s,h,"start")-o,x=u(s,h,"end")-o;if(!(e.nodes.some(e=>{n?.();let t=Math.max(0,e.id===s.source?d:0,e.id===s.target?x:0);return l.x<e.x+e.width+t&&l.x+l.w+t>e.x&&l.y<e.y+e.height+t&&l.y+l.h+t>e.y})||r(l,e.groups)||a(l)))return l}}}function t4(e,t,n){let i;for(let t of e.edges){if(!t.label||!t.labelPosition||t.points.length<2||!tO(t,e.edges,n))continue;let r=i??=t6(e,n),a=t8(t,n),s=t.labelBlock??o(N(t.label,t.labelContent),n),h=s.width+2*l,u=s.height+2*l,x=t2(t),y=t.labelPosition,c=!1,f=Math.min(h,u)/2-1;for(let i of[0,f,-f]){if(c)break;for(let o of x){if(c)break;let l=(o.vertical?u:h)/2;if(o.len<=2*l)continue;let x=l/o.len;for(let l of[5,4,6,3,7,2,8,1,9,0,10]){let h=x+l/10*(1-2*x),u=o.a.x+(o.b.x-o.a.x)*h+(o.vertical?i:0),y=o.a.y+(o.b.y-o.a.y)*h+(o.vertical?0:i);if(t.labelPosition={x:u,y:y},r.clearPaintRect(d(u,y,s),a,t)&&!tO(t,e.edges,n)){c=!0;break}}}}c||(t.labelPosition=y)}}function t3(e,t,n){let i=(e,t,n)=>{let i=n.x-t.x,r=n.y-t.y,a=i*i+r*r;if(0===a)return Math.hypot(e.x-t.x,e.y-t.y);let o=Math.max(0,Math.min(1,((e.x-t.x)*i+(e.y-t.y)*r)/a));return Math.hypot(e.x-(t.x+o*i),e.y-(t.y+o*r))},r;for(let t of e.edges){if(!t.label||!t.labelPosition||t.points.length<2||t.source===t.target)continue;let a=t.labelBlock??o(N(t.label,t.labelContent),n),s=a.width+2*l,h=a.height+2*l,u=h/2+4,x=e=>{let n=1/0;for(let r=1;r<t.points.length;r++)n=Math.min(n,i(e,t.points[r-1],t.points[r]));return n};if(x(t.labelPosition)<=u)continue;let y=r??=t6(e,n),c=t8(t,n),f=(i,r)=>x({x:i,y:r})<=u&&!!y.clearPaintRect(d(i,r,a),c,t)&&!tO(t,e.edges,n,{x:i,y:r}),g=t2(t),p=!1;for(let e of g){if(p)break;let n=(e.vertical?h:s)/2;if(!(e.len<=2*n))for(let i of t5(n/e.len)){let n=e.a.x+(e.b.x-e.a.x)*i,r=e.a.y+(e.b.y-e.a.y)*i;if(f(n,r)){t.labelPosition={x:n,y:r},p=!0;break}}}if(!p){let e=t.points[0],n=1/0;for(let i of g.length?g:[]){let r=i.b.x-i.a.x,a=i.b.y-i.a.y,o=r*r+a*a||1,s=Math.max(0,Math.min(1,((t.labelPosition.x-i.a.x)*r+(t.labelPosition.y-i.a.y)*a)/o)),l=i.a.x+s*r,h=i.a.y+s*a,u=Math.hypot(t.labelPosition.x-l,t.labelPosition.y-h);u<n&&(n=u,e={x:l,y:h})}let i=n>.01?(t.labelPosition.x-e.x)/n:0,r=n>.01?(t.labelPosition.y-e.y)/n:-1,a=u-1;for(let n of[1,-1]){let o=e.x+i*a*n,s=e.y+r*a*n;if(f(o,s)){t.labelPosition={x:o,y:s};break}}}}}function t7(e,t,n=P({}),i){let r=1e6,a=e.edges.filter(e=>e.label&&e.labelPosition&&e.points.length>=2);if(0===a.length)return;let s=e=>{let t=x(e,n),i=t8(e,n);return t&&{x:t.x-i,y:t.y-i,w:t.w+2*i,h:t.h+2*i}},h=(e,t)=>Math.min(e.x+e.w,t.x+t.w)-Math.max(e.x,t.x)>.5&&Math.min(e.y+e.h,t.y+t.h)-Math.max(e.y,t.y)>.5,{overlapsMarker:u,clearPaintRect:y}=t6(e,n),f=function*(t,a,u=!1,x,f=!0){if(x&&!x.pay(16))return;let g=t.labelBlock??o(N(t.label,t.labelContent),n),p=g.width+2*l,m=g.height+2*l,M=t8(t,n),b=(o,l,u)=>{if(x)return x.pay(3)&&x.clear({x:o,y:l});if(i?.preserveRouteClearance&&r<=0)return!1;let f=y(d(o,l,g),M,t);if(!f)return!1;for(let e of a){let t=s(e);if(t&&h(f,t))return!1}if(tO(t,e.edges,n,{x:o,y:l}))return!1;if(i?.preserveRouteClearance||u){for(let n of e.edges)if(n!==t&&"invisible"!==n.style){for(let e=1;e<n.points.length;e++)if(i?.preserveRouteClearance&&--r<0||c(n.points[e-1],n.points[e],f))return!1}}return!0},$=x?t2(t,x.pay):t2(t);if(!$)return;let w=m/2+4,k=[w-1,-(w-1),(w-1)/2,-(w-1)/2];for(let[e,t]of[[0,!1],...k.map(e=>[e,!0]),...f?k.map(e=>[e,!1]):[]])for(let n of $){let a=(n.vertical?m:p)/2;if(!u&&n.len<=2*a)continue;let o=+!!n.vertical,s=+!n.vertical,l=u?0:a/n.len;if(x&&!x.pay(160))return;for(let a of t5(l)){let l=n.a.x+(n.b.x-n.a.x)*a+o*e,h=n.a.y+(n.b.y-n.a.y)*a+s*e;if(i?.preserveRouteClearance&&r<=0)return;b(l,h,t)&&(yield{x:l,y:h})}}},g=(e,t,n=!0)=>{for(let i of f(e,t,!1,void 0,n))return e.labelPosition=i,!0;return!1},p=(e,t)=>{let n=a.filter(n=>n!==e&&n!==t);for(let i of[!1,!0]){let r=e=>{let t=[];for(let r of f(e,n,i))if(t.push(r),64===t.length)break;return t},a=r(e),o=r(t);for(let n of a)for(let i of o)if(!h(s({...e,labelPosition:n}),s({...t,labelPosition:i})))return e.labelPosition=n,t.labelPosition=i,!0}return!1},m=()=>{if(z())return;let t=e=>e>r?(r=0,!1):(r-=e,!0);if(!t(8))return;let i=(n,i)=>{for(let r of e.edges){if(!t(1))break;if(r!==n&&"invisible"!==r.style)for(let e=1;e<r.points.length;e++){if(!t(1))return!1;if(c(r.points[e-1],r.points[e],i))return!0}}return!1},o;for(let l of a){if(!t(64+(l.label?.length??0)*12+2*e.edges.length))return;let h=s(l);if(!h||!u(h)&&!i(l,h))continue;if(!t(l.points.length+2))return;if(l.curve||(n.edgeBendRadius??0)!==0||l.points.some((e,t)=>t>0&&e.x!==l.points[t-1].x&&e.y!==l.points[t-1].y))continue;if(!(o??=tU(e.nodes,e.edges,e.groups,n,t))||!t(8))return;let d=new Set,y=new Map,c=(e,i,a,s)=>{if(!t(8))return;let l=[],h=new Map,u=i=>{if(e.source===e.target){if(!t(e.points.length+8))return!1;let r=x({...e,labelPosition:i},n);if(!r||e.points.some((t,n)=>{var i;return n>0&&(.01>=Math.abs((i=e.points[n-1]).x-t.x)?i.x>r.x+.01&&i.x<r.x+r.w-.01&&Math.min(Math.max(i.y,t.y),r.y+r.h)-Math.max(Math.min(i.y,t.y),r.y)>.01:.01>=Math.abs(i.y-t.y)&&i.y>r.y+.01&&i.y<r.y+r.h-.01&&Math.min(Math.max(i.x,t.x),r.x+r.w)-Math.max(Math.min(i.x,t.x),r.x)>.01)}))return!1}return o.clear(e,i,h,s,a)};for(let n of f(e,[],i,{clear:u,pay:t})){if(!t(1))return;if(l.push(n),64===l.length)break}return r>0?l:void 0},g=!1,p=c(l,!0,void 0,d);if(!p)return;for(let e of p){if(!t(3))return;if(y.set(l,e),o.clear(l,e,y)){l.labelPosition=e,g=!0;break}}if(g)continue;let m=a.filter(e=>d.has(e)&&!e.curve&&!e.points.some((t,n)=>n>0&&t.x!==e.points[n-1].x&&t.y!==e.points[n-1].y));for(let e of a){if(!t(1))return;if(m.includes(e)){if(!t(e.points.length+6))return;for(let n of[!1,!0]){let i=c(l,n,e),r=c(e,n,l);if(!i||!r)return;e:for(let n of i)for(let i of r){if(!t(16))return;let r=new Map([[l,n],[e,i]]);if(!(!o.clear(l,n,r)||!o.clear(e,i,r))){l.labelPosition=n,e.labelPosition=i,g=!0;break e}}if(g)break}if(g)break}}if(g||m.length<2)continue;let M=new Set(m);for(let e of[!1,!0]){let n=c(l,e,M);if(!n)return;e:for(let i of n){if(!t(8+4*m.length))return;let n=new Map([[l,i]]);for(let t of m){let i=c(t,e,l);if(!i)return;let r=i.find(e=>o.clear(t,e,new Map(n).set(t,e)));if(!r)continue e;n.set(t,r)}if([...n].every(([e,t])=>o.clear(e,t,n))){for(let[e,t]of n)e.labelPosition=t;g=!0;break}}if(g)break}}};for(let e=0;e<3;e++){if(i?.preserveRouteClearance&&r<=0)return;let t=0;for(let e of a){let n=s(e);n&&u(n)&&(t++,g(e,a.filter(t=>t!==e),!1))}for(let e=0;e<a.length;e++)for(let n=e+1;n<a.length;n++){let i=a[e],r=a[n],o=s(i),l=s(r);!o||!l||!h(o,l)||(t++,g(r,a.filter(e=>e!==r))||g(i,a.filter(e=>e!==i))||p(i,r))}if(0===t){m();break}2===e&&m()}}function t9(n,i,r){let a;for(let o of n.edges){if("invisible"===o.style||o.points.length<3||!o.hasArrowStart&&!o.hasArrowEnd)continue;let s=D(o,r);if(e(o.points,!0)+1e-7>=s.start&&e(o.points,!1)+1e-7>=s.end)continue;let l=t(o.points,s);if(!l)continue;let{ctx:h}=a??=tF(n.nodes,n.edges,i.direction,r,n.groups),u=h.nodes.find(e=>e.id===o.source),d=h.nodes.find(e=>e.id===o.target);if(eZ({...o,points:l},u,d)||tz(l,o,h)||!tm(o,l,n.edges,r))continue;let x=!0;for(let e=1;e<l.length&&x;e++){let t=l[e-1],n=l[e],i=eT(t.x===n.x?"TB":"LR");x=!tP(o,t[i.cross],Math.min(t[i.main],n[i.main]),Math.max(t[i.main],n[i.main]),h,i)}x&&(o.points=l,tG(o,o.routeCertificate,u,d))}}function ne(e,t,n){for(let i=0;i<e.edges.length&&0!==tK(e,t,n,!0).length;i++);return function(e,t,n){let i=te(e);for(let e of t){let r=e.routeCertificate,a=!1,o=e.points;for(let t of[!0,!1]){let[n,r,s]=(t?[...o].reverse():o).slice(-3),l=i.get(t?e.source:e.target);if(!l||"rectangle"!==l.shape||void 0!==l.semanticShape&&"rect"!==l.semanticShape||!n||!r||!s||Math.hypot(s.x-r.x,s.y-r.y)>=1)continue;let h=(.01>Math.abs(r.x-l.x)||.01>Math.abs(r.x-l.x-l.width))&&.01>Math.abs(s.x-r.x)&&.01>Math.abs(n.y-r.y)&&r.y>l.y&&r.y<l.y+l.height&&s.y>l.y&&s.y<l.y+l.height&&(n.x-r.x)*(r.x-l.x-l.width/2)>0,u=(.01>Math.abs(r.y-l.y)||.01>Math.abs(r.y-l.y-l.height))&&.01>Math.abs(s.y-r.y)&&.01>Math.abs(n.x-r.x)&&r.x>l.x&&r.x<l.x+l.width&&s.x>l.x&&s.x<l.x+l.width&&(n.y-r.y)*(r.y-l.y-l.height/2)>0;(h||u)&&(o=t?o.slice(1):o.slice(0,-1),a=!0)}a&&tm(e,o,t,n)&&(e.points=o,tG(e,r,i.get(e.source),i.get(e.target)))}}(e.nodes,e.edges,n),e.edges.flatMap(e=>e.routeCertificate?[e.routeCertificate]:[])}function nt(){return{total:0,labelLabel:0,labelNode:0,labelEdge:0}}function nn(e,t){return Math.min(e.x+e.w,t.x+t.w)-Math.max(e.x,t.x)>y&&Math.min(e.y+e.h,t.y+t.h)-Math.max(e.y,t.y)>y}function ni(e,t,n){let i=e.edges.flatMap((e,n)=>{if(!e.label)return[];let i=x(e.labelPosition?e:{...e,labelPosition:p(e.points)},t);return i?[{edgeIndex:n,rect:i}]:[]});return 0===i.length?nt():function(e,t,n,i){let r=nt(),a=i?e.filter(e=>i.has(e.edgeIndex)):e,o=i?[...i].filter(e=>void 0!==n[e]):[];for(let s=0;s<e.length;s++){let l=e[s],h=!i||i.has(l.edgeIndex),u=h?e:a;for(let e=h?s+1:0;e<u.length;e++){let t=u[e];!h&&t.edgeIndex<=l.edgeIndex||nn(l.rect,t.rect)&&r.labelLabel++}if(h)for(let e of t)nn(l.rect,e)&&r.labelNode++;for(let e=0;e<(h?n.length:o.length);e++){let t=h?e:o[e],i=n[t];if(!(t===l.edgeIndex||i.hidden)){for(let e=1;e<i.points.length;e++)if(c(i.points[e-1],i.points[e],l.rect)){r.labelEdge++;break}}}}return r.total=r.labelLabel+r.labelNode+r.labelEdge,r}(i,e.nodes.map(e=>({x:e.x,y:e.y,w:e.width,h:e.height})),e.edges.map(e=>({points:e.points,hidden:"invisible"===e.style})),n)}var nr={edgeThroughNode:"primary",nodeOverlaps:"primary",diagonalSegments:"secondary",unexplainedBends:"secondary",hitches:"secondary",offOutlineEndpoints:"cosmetic",endpointApproaches:"primary",labelOffRoute:"cosmetic"},na={primary:0,secondary:1,cosmetic:2};function no(e,t){let n=e=>.5>=Math.abs(e.x-t.x)&&.5>=Math.abs(e.y-t.y);return!!(Object.values(ej(e)).some(n)||"diamond"===e.shape&&Object.values(eY(e)).some(n))}function ns(e,t,n=1.5){let i=eE(e,t,n);return"none"===i.policy||i.onBoundary}function nl(e,t,n){let i=n.x+n.width/2,r=n.y+n.height/2,a=n.width/2,o=n.height/2,s=Math.min(e.x,t.x),l=Math.max(e.x,t.x),h=Math.min(e.y,t.y),u=Math.max(e.y,t.y);if("cylinder"===n.shape&&(void 0===n.semanticShape||"cyl"===n.semanticShape)&&n.height>14&&l>n.x&&s<n.x+n.width&&u>n.y+7&&h<n.y+n.height-7)return!0;let d=.5*("rectangle"!==n.shape&&"subroutine"!==n.shape||void 0!==n.semanticShape&&"rect"!==n.semanticShape&&"fr-rect"!==n.semanticShape&&"lin-rect"!==n.semanticShape&&"div-rect"!==n.semanticShape&&"win-pane"!==n.semanticShape);if(!(l>n.x+d&&s<n.x+n.width-d&&u>n.y+d&&h<n.y+n.height-d))return!1;switch(n.shape){case"ellipse":case"circle":case"doublecircle":case"state-start":case"state-end":return nc({x:0,y:0},{x:(e.x-i)/a,y:(e.y-r)/o},{x:(t.x-i)/a,y:(t.y-r)/o})<1-2.5/Math.min(a,o);case"stadium":return nh(e,t,{x:i-(a-o),y:r},{x:i+(a-o),y:r})<o-2.5;case"diamond":case"hexagon":case"trapezoid":case"trapezoid-alt":case"lean-r":case"lean-l":case"asymmetric":{let s,l="diamond"===n.shape?[{x:i,y:n.y},{x:n.x+n.width,y:r},{x:i,y:n.y+n.height},{x:n.x,y:r}]:"hexagon"===n.shape?(s=n.height/4,[{x:n.x+s,y:n.y},{x:n.x+n.width-s,y:n.y},{x:n.x+n.width,y:r},{x:n.x+n.width-s,y:n.y+n.height},{x:n.x+s,y:n.y+n.height},{x:n.x,y:r}]):function(e){let{x:t,y:n,width:i,height:r}=e,a=.15*i;switch(e.shape){case"trapezoid":return[{x:t+a,y:n},{x:t+i-a,y:n},{x:t+i,y:n+r},{x:t,y:n+r}];case"trapezoid-alt":return[{x:t,y:n},{x:t+i,y:n},{x:t+i-a,y:n+r},{x:t+a,y:n+r}];case"lean-r":return[{x:t+a,y:n},{x:t+i,y:n},{x:t+i-a,y:n+r},{x:t,y:n+r}];case"lean-l":return[{x:t,y:n},{x:t+i-a,y:n},{x:t+i,y:n+r},{x:t+a,y:n+r}];default:return[{x:t+12,y:n},{x:t+i,y:n},{x:t+i,y:n+r},{x:t+12,y:n+r},{x:t,y:n+r/2}]}}(n),h=Math.max(0,1-2.5/Math.min(a,o));return function(e,t,n){let i=e=>{for(let t=0;t<n.length;t++){let i=n[t],r=n[(t+1)%n.length];if((r.x-i.x)*(e.y-i.y)-(r.y-i.y)*(e.x-i.x)<-.5)return!1}return!0},r={x:(e.x+t.x)/2,y:(e.y+t.y)/2};if(i(e)||i(t)||i(r))return!0;for(let i=0;i<n.length;i++)if(nu(e,t,n[i],n[(i+1)%n.length]))return!0;return!1}(e,t,l.map(e=>({x:i+(e.x-i)*h,y:r+(e.y-r)*h})))}default:return!0}}function nh(e,t,n,i){return nu(e,t,n,i)?0:Math.min(nc(e,n,i),nc(t,n,i),nc(n,e,t),nc(i,e,t))}function nu(e,t,n,i){let r=(t.x-e.x)*(i.y-n.y)-(t.y-e.y)*(i.x-n.x);if(1e-9>Math.abs(r))return!1;let a=((n.x-e.x)*(i.y-n.y)-(n.y-e.y)*(i.x-n.x))/r,o=((n.x-e.x)*(t.y-e.y)-(n.y-e.y)*(t.x-e.x))/r;return a>.001&&a<.999&&o>.001&&o<.999}function nd(e,t){return r(e.map(e=>({points:e.points,visible:"invisible"!==e.style})),t)}function nx(e,t){let n=new Map;e.forEach((e,t)=>{if("invisible"===e.style||e.source===e.target)return;let i=JSON.stringify([e.source,e.target]),r=n.get(i)??[];r.push({edge:e,index:t}),n.set(i,r)});let i=(e,t)=>{for(let n=1;n<e.points.length;n++)for(let i=1;i<t.points.length;i++){let r=e.points[n-1],a=e.points[n],o=t.points[i-1],s=t.points[i];if(.01>=Math.abs(r.x-a.x)&&.01>=Math.abs(o.x-s.x)&&.5>=Math.abs(r.x-o.x)&&Math.min(Math.max(r.y,a.y),Math.max(o.y,s.y))-Math.max(Math.min(r.y,a.y),Math.min(o.y,s.y))>1||.01>=Math.abs(r.y-a.y)&&.01>=Math.abs(o.y-s.y)&&.5>=Math.abs(r.y-o.y)&&Math.min(Math.max(r.x,a.x),Math.max(o.x,s.x))-Math.max(Math.min(r.x,a.x),Math.min(o.x,s.x))>1)return!0}return!1},r=0;for(let e of n.values())for(let n=0;n<e.length;n++)for(let a=n+1;a<e.length;a++){let o=e[n],s=e[a];(!t||t.has(o.index)||t.has(s.index))&&i(o.edge,s.edge)&&r++}return r}function ny(e,t=!1){let n=new Map(e.nodes.map(e=>[e.id,e])),i=0,r=0;for(let a of e.edges)if(!(t&&"invisible"===a.style))for(let[e,t]of[[a.source,a.points[0]],[a.target,a.points.at(-1)]]){let a=n.get(e);a&&(i++,t&&no(a,t)&&r++)}return 0===i?1:r/i}function nc(e,t,n){let i=n.x-t.x,r=n.y-t.y,a=i*i+r*r;if(0===a)return Math.hypot(e.x-t.x,e.y-t.y);let o=Math.max(0,Math.min(1,((e.x-t.x)*i+(e.y-t.y)*r)/a));return Math.hypot(e.x-(t.x+o*i),e.y-(t.y+o*r))}function nf(e,t){return"LR"===t||"RL"===t?e.y+e.height/2:e.x+e.width/2}function ng(e,t){return"LR"===t||"RL"===t?e.x:e.y}function np(e,t){return"LR"===t||"RL"===t?e.x+e.width:e.y+e.height}function nm(e,t){let n=t=>t.some(t=>e.x>=t.x-.5&&e.y>=t.y-.5&&e.x+e.width<=t.x+t.width+.5&&e.y+e.height<=t.y+t.height+.5||n(t.children));return n(t)}function nM(e,t){let n=g(t.edges),i=new Map(e.nodes.map(e=>[e.id,e])),r=new Map,a=new Map;for(let n of e.edges){var o;let e=i.get(n.source),s=i.get(n.target);e&&s&&("LR"===(o=t.direction)?ng(s,o)>np(e,o):"RL"===o||"BT"===o?np(s,o)<ng(e,o):ng(s,o)>np(e,o))&&(r.has(n.source)||r.set(n.source,[]),r.get(n.source).push(s),a.has(n.target)||a.set(n.target,[]),a.get(n.target).push(e))}let s=0,l=(i,r,a)=>{if(!i||r.length<2||r.length>6||!function(e,t,n=1){if(e.length<2)return!1;let i=e.map(e=>ng(e,t));return Math.max(...i)-Math.min(...i)<=n}(r,t.direction,28)||!ez.has(i.shape)||nm(i,e.groups)||!r.every(t=>("in"===a?ez.has(t.shape):"rectangle"===t.shape)&&!nm(t,e.groups))||new Set(r.map(e=>e.id)).size!==r.length)return;for(let e=0;e<r.length;e++)for(let t=0;t<r.length;t++)if(e!==t&&n(r[e].id,r[t].id))return;let o=r.reduce((e,n)=>e+nf(n,t.direction),0)/r.length;s=Math.max(s,Math.abs(nf(i,t.direction)-o))};for(let[e,t]of r)l(i.get(e),t,"out");for(let[e,t]of a)l(i.get(e),t,"in");return s}function nb(e,t,n=P({})){return n$(e,t,n,!0)}function n$(e,t,n,i){let r=[],a=new Map(t.nodes.map(e=>[e.id,e])),o=0,l=0,h=0,u=0,d=0,x=0,y=0,c=0,f=0;for(let e of t.edges){let t=`${e.source}->${e.target}`,g=Math.max(0,e.points.length-2);if("invisible"!==e.style){let n=eZ(e,a.get(e.source),a.get(e.target));n&&(l+=n,r.push({metric:"endpointApproaches",detail:`${t}: ${n} inward or tangent exact endpoint shaft(s)`}))}let p=tT(e);"invisible"===e.style||p||(x+=g,y=Math.max(y,g)),g>0&&e.routeCertificate?.invariant==="straight"&&(u+=g,r.push({metric:"unexplainedBends",detail:`${t} certified straight with ${g} bends`}));for(let n=1;n<e.points.length;n++){let i=e.points[n-1],a=e.points[n];Math.abs(i.x-a.x)>.01&&Math.abs(i.y-a.y)>.01&&(h++,r.push({metric:"diagonalSegments",detail:`${t} segment ${n}`}))}for(let[n,i,s]of[[e.source,e.points[0],"source"],[e.target,e.points[e.points.length-1],"target"]]){let e=a.get(n);!e||i&&ns(e,i)||(o++,r.push({metric:"offOutlineEndpoints",detail:i?`${t} ${s} on ${n}(${e.shape}) at (${i.x.toFixed(1)},${i.y.toFixed(1)})`:`${t} missing ${s} endpoint on ${n}`}))}let m=a.get(e.source),M=a.get(e.target),b=(e,t)=>!!e&&!!t&&no(e,t);if((b(m,e.points[0])||b(M,e.points[e.points.length-1]))&&c++,e.label&&e.labelPosition&&e.points.length>=2){let a=e.labelBlock??s(e.label,n,"edge"),o=(a.height+16)/2+4,l=e.source===e.target,h=1/0;for(let t=1;t<e.points.length;t++)h=Math.min(h,l?function(e,t,n,i,r,a){let o=r=>r.x>=e-n&&r.x<=e+n&&r.y>=t-i&&r.y<=t+i;if(o(r)||o(a))return 0;let s=[{x:e-n,y:t-i},{x:e+n,y:t-i},{x:e+n,y:t+i},{x:e-n,y:t+i}],l=1/0;for(let e=0;e<4;e++)l=Math.min(l,nh(s[e],s[(e+1)%4],r,a));return l}(e.labelPosition.x,e.labelPosition.y,(a.width+16)/2,(a.height+16)/2,e.points[t-1],e.points[t]):nc(e.labelPosition,e.points[t-1],e.points[t]));h>o&&(d++,r.push({metric:"labelOffRoute",detail:`${t} label ${h.toFixed(1)}px from its route (allowed ${o.toFixed(1)})`})),i&&(f=Math.max(f,e.label&&e.labelPosition&&!(e.points.length<2)?Math.abs(function(e,t){let n=0,i=[];for(let e=1;e<t.length;e++){let r=Math.hypot(t[e].x-t[e-1].x,t[e].y-t[e-1].y);i.push(r),n+=r}let r=1/0,a=0,o=0;for(let n=1;n<t.length;n++){let s=t[n-1],l=t[n],h=l.x-s.x,u=l.y-s.y,d=h*h+u*u,x=d?((e.x-s.x)*h+(e.y-s.y)*u)/d:0;x=Math.max(0,Math.min(1,x));let y=s.x+x*h,c=s.y+x*u,f=Math.hypot(e.x-y,e.y-c);f<r&&(r=f,a=o+x*i[n-1]),o+=i[n-1]}return n?a/n:.5}(e.labelPosition,e.points)-.5):0))}}let g=0;for(let e of t.edges)for(let n of t.nodes)if(n.id!==e.source&&n.id!==e.target){for(let t=1;t<e.points.length;t++)if(nl(e.points[t-1],e.points[t],n)){g++,r.push({metric:"edgeThroughNode",detail:`${e.source}->${e.target} segment ${t} through ${n.id}`});break}}let p=i?nd(t.edges):0,m=0;for(let e=0;e<t.nodes.length;e++)for(let n=e+1;n<t.nodes.length;n++){let i=t.nodes[e],a=t.nodes[n],o=Math.min(i.x+i.width,a.x+a.width)-Math.max(i.x,a.x),s=Math.min(i.y+i.height,a.y+a.height)-Math.max(i.y,a.y);o>.5&&s>.5&&(m++,r.push({metric:"nodeOverlaps",detail:`${i.id} overlaps ${a.id}`}))}let M=function(e,t,n=P({})){return tK(e,t,n,!1)}(t,e,n);for(let e of M)r.push({metric:"hitches",detail:`${e.edge} deviates ${e.deviationPx}px with a clear lane`});return{metrics:{edges:t.edges.length,offOutlineEndpoints:o,endpointApproaches:l,diagonalSegments:h,unexplainedBends:u,hitches:M.length,nodeOverlaps:m,labelOffRoute:d,edgeThroughNode:g,labelConflicts:i?ni(t,n).total:0,edgeCrossings:p,totalBends:x,maxBendsPerEdge:y,portEndpointRate:ny(t),portAnchoredEdgeRate:0===t.edges.length?1:c/t.edges.length,peerBarycenterDelta:i?nM(t,e):0,worstLabelOffset:f},violations:r.map(e=>({...e,severity:nr[e.metric]??"secondary"})).sort((e,t)=>na[e.severity]-na[t.severity])}}function nw(e,t,n,i,r=new Set){let a={};for(let o of n)switch(o){case"hard":a.hard=nv(n$(e,t,i,!1)).length;break;case"crossings":a.crossings=nd(t.edges);break;case"portRate":a.portRate=ny(t,!0);break;case"symErr":a.symErr=nM(t,e);break;case"parallelOverlaps":a.parallelOverlaps=nx(t.edges);break;case"opposingOverlaps":a.opposingOverlaps=Y(t.edges);break;case"endpointApproaches":{let e=new Map(t.nodes.map(e=>[e.id,e]));a.endpointApproaches=t.edges.reduce((t,n)=>t+("invisible"===n.style?0:eZ(n,e.get(n.source),e.get(n.target))),0);break}case"bends":a.bends=t.edges.reduce((e,t)=>e+("invisible"===t.style||(t.routeCertificate?tT(t):r.has(t)&&to(t))?0:Math.max(0,t.points.length-2)),0);break;case"straight":a.straight=t.edges.filter(e=>"invisible"!==e.style&&2===e.points.length).length}return a}var nk=["offOutlineEndpoints","endpointApproaches","diagonalSegments","unexplainedBends","hitches","nodeOverlaps","labelOffRoute","edgeThroughNode"];function nv(e){let t=new Set(nk);return e.violations.filter(e=>t.has(e.metric))}function nS(e,t,n){if(e.source===e.target)return!1;let i=t.get(e.source),r=t.get(e.target);if(!i||!r)return!1;let a=m(n),o=M(i),s=M(r);return(a.isHorizontal?s.x-o.x:s.y-o.y)*a.sign>8}function nC(e,t,n=18){if(e.length<2)return!1;let i=e.map(e=>b(e,t));return Math.max(...i)-Math.min(...i)<=n}function nP(e,t){let n=m(t),i=[];for(let n of[...e].sort((e,n)=>b(e,t)-b(n,t)||$(e,t)-$(n,t))){let e=b(n,t),r=i.find(n=>18>=Math.abs(b(n[0],t)-e));r||(r=[],i.push(r)),r.push(n)}for(let e of i){let i=[...e].sort((e,n)=>$(e,t)-$(n,t)),r=$(i[0],t);for(let e of i){let i=$(e,t);if(i<r){let t=r-i;n.isHorizontal?e.y+=t:e.x+=t}r=$(e,t)+w(e,t)+24}}}function nN(e,t){let n=t=>t.some(t=>e.x>=t.x-.5&&e.y>=t.y-.5&&e.x+e.width<=t.x+t.width+.5&&e.y+e.height<=t.y+t.height+.5||n(t.children));return n(t)}function nW(e,t=[]){for(let n of e)t.push(n),nW(n.children,t);return t}function nL(e,t){return e.x>=t.x-.5&&e.y>=t.y-.5&&e.x+e.width<=t.x+t.width+.5&&e.y+e.height<=t.y+t.height+.5}function nE(e,t,n,i){if(i<=0)return;let r=m(n),a=new Set;for(let n of nW(e))a.has(n)||!t.some(e=>nL(e,n))||(a.add(n),r.isHorizontal?(r.sign>0||(n.x-=i),n.width+=i):(r.sign>0||(n.y-=i),n.height+=i))}function nI(e,t,n,i){if("diamond"===e.shape){let r=(2===i?{LR:["NE","SE"],RL:["NW","SW"],BT:["NW","NE"],TD:["SW","SE"],TB:["SW","SE"]}:3===i?{LR:["NE","E","SE"],RL:["NW","W","SW"],BT:["NW","N","NE"],TD:["SW","S","SE"],TB:["SW","S","SE"]}:{})[t]?.[n];if(r)return"diamond"===e.shape&&("NE"===r||"SE"===r||"SW"===r||"NW"===r)?eY(e)[r]:ej(e)[r]}let r=m(t),a=(n+1)/(i+1);return r.isHorizontal?{x:"E"===r.sourceSide?e.x+e.width:e.x,y:e.y+e.height*a}:{x:e.x+e.width*a,y:"S"===r.sourceSide?e.y+e.height:e.y}}function nB(e,t){return ej(e)[m(t).targetSide]}function nR(e,t){return Array.from({length:e},(n,i)=>(i-(e-1)/2)*t)}function nH(e,t,n,i){let r=Math.abs(t-e);return r/2>=i||r<n+i?e+(t-e)/2:t-Math.sign(t-e)*i}function nA(e,t,n,i){return m(n).isHorizontal?eX([e,{x:i,y:e.y},{x:i,y:t.y},t]):eX([e,{x:e.x,y:i},{x:t.x,y:i},t])}function nF(e,t,n,i){for(let r=1;r<e.length;r++)if(!function(e,t,n,i,r=1,a){let o=Math.min(e.x,t.x),s=Math.max(e.x,t.x),l=Math.min(e.y,t.y),h=Math.max(e.y,t.y);for(let u of n){if(a?.(1),i.has(u.id))continue;let n=u.x-r,d=u.x+u.width+r,x=u.y-r,y=u.y+u.height+r;if(.01>Math.abs(e.x-t.x)){if(e.x>=n&&e.x<=d&&l<y&&h>x)return!1}else if(.01>Math.abs(e.y-t.y)&&e.y>=x&&e.y<=y&&o<d&&s>n)return!1}return!0}(e[r-1],e[r],t,n,1,i))return!1;return!0}function nO(e,t,n,i){if(0===e.points.length)return;let r=m(t),a=n?e.points.length-1:0,o=n?-1:1,s=e.points[a][r.cross],l=1/0,h=-1/0;for(let t=a;t>=0&&t<e.points.length&&!(Math.abs(e.points[t][r.cross]-s)>.5);t+=o)l=Math.min(l,e.points[t][r.main]),h=Math.max(h,e.points[t][r.main]),e.points[t][r.cross]+=i;e.labelPosition&&12>=Math.abs(e.labelPosition[r.cross]-s)&&e.labelPosition[r.main]>=l-.5&&e.labelPosition[r.main]<=h+.5&&(e.labelPosition[r.cross]+=i)}function nz(e,t,n,i,r){let a=m(i);for(let n of t)e.has(n.id)&&(n[a.cross]+=r);for(let t of n){let n=e.has(t.source),o=e.has(t.target);if(n&&o){for(let e of t.points)e[a.cross]+=r;t.labelPosition&&(t.labelPosition[a.cross]+=r)}else o?nO(t,i,!0,r):n&&nO(t,i,!1,r)}}function nj(e,t,n,i,r,a){let o=m(i),s=t.filter(t=>e.has(t.id)),l=new Map(s.map(e=>[e.id,{x:o.isHorizontal?e.x:e.x+r,y:o.isHorizontal?e.y+r:e.y,width:e.width,height:e.height}]));for(let e of l.values())if(e.x<0||e.y<0)return!1;for(let n=0;n<s.length;n++){let i=l.get(s[n].id);for(let e=n+1;e<s.length;e++)if(k(i,l.get(s[e].id),8))return!1;for(let n of t)if(!e.has(n.id)&&k(i,n,8))return!1}for(let t of s){let i=l.get(t.id);for(let t of n){if(e.has(t.source)||e.has(t.target))continue;for(let e=1;e<t.points.length;e++){let n=t.points[e-1],r=t.points[e];if(Math.max(n.x,r.x)>i.x+.5&&Math.min(n.x,r.x)<i.x+i.width-.5&&Math.max(n.y,r.y)>i.y+.5&&Math.min(n.y,r.y)<i.y+i.height-.5)return!1}let n=x(t,a);if(n&&k(i,{x:n.x,y:n.y,width:n.w,height:n.h},8))return!1}}return!0}function nY(e,t,n,i={}){let r=new Map(e.map(e=>[e.id,e])),a=m(n.direction);for(let o of t){if(o.source===o.target||o.points.length<2)continue;let t=r.get(o.source),s=r.get(o.target);if(!t||!s)continue;let l=!ns(t,o.points[0]),h=!ns(s,o.points[o.points.length-1]);if(!l&&!h)continue;let u=ej(t)[a.sourceSide],d=ej(s)[a.targetSide],x=nH(u[a.main],d[a.main],eO(i,o,"start"),eO(i,o,"end")),y=nA(u,d,n.direction,x);if(!nF(y,e,new Set([o.source,o.target])))continue;let c=o.routeCertificate;o.points=y,tG(o,c,t,s),o.label&&(o.labelPosition=p(y))}}function nQ(e,t,n,i,r=[]){let a=m(n.direction);i?.(e.length);let o=new Map(e.map(e=>[e.id,e])),s=(t,n)=>{for(let r of e)if(i?.(1),!n.has(r.id)){for(let e=1;e<t.length;e++)if(i?.(1),nl(t[e-1],t[e],r))return!0}return!1},l=e=>{let t=n=>{i?.(1);let r=n.concurrencyRegion?0:n.headerHeight;if(0!==n.width&&(void 0===r||!Number.isFinite(r)||r<0))return!1;if(void 0!==r&&r>0&&n.width>0)for(let t=1;t<e.length;t++){i?.(1);let a=e[t-1],o=e[t];if(Math.max(a.x,o.x)>n.x&&Math.min(a.x,o.x)<n.x+n.width&&Math.max(a.y,o.y)>n.y&&Math.min(a.y,o.y)<n.y+r)return!1}for(let e of n.children)if(!t(e))return!1;return!0};for(let e of r)if(!t(e))return!1;return!0},h=(t,n)=>{for(let r=1;r<=t.length-3;r++){let a=t[r],o=t[r+1],h=t[r-1],u=t[r+2],d=.5>Math.abs(a.x-o.x);if(d===.5>Math.abs(a.y-o.y)||!s([a,o],n))continue;let x=d?"x":"y",y=d?"y":"x";if(Math.abs(h[y]-a[y])>.5||Math.abs(u[y]-o[y])>.5)continue;let c=a[x],f=[];for(let t of e)i?.(1),n.has(t.id)||f.push(t[x]-10,t[x]+("x"===x?t.width:t.height)+10);for(let a of(f.sort((e,t)=>Math.abs(e-c)-Math.abs(t-c)),f)){let o=t.map(e=>({...e}));if(o[r][x]=a,o[r+1][x]=a,!s(o,n)&&nF(o,e,n,i)&&l(o))return eX(o)}}return null},u=(t,r)=>{let o=t[0],h=t[t.length-1],u=Math.min(o[a.main],h[a.main]),d=Math.max(o[a.main],h[a.main]),x=1/0,y=-1/0,c=[];for(let t of e){if(i?.(1),r.has(t.id))continue;let e=t[a.main];if(t[a.main]+("x"===a.main?t.width:t.height)<=u||e>=d)continue;let o=$(t,n.direction),s=o+w(t,n.direction);x=Math.min(x,o),y=Math.max(y,s),c.push(o-10,s+10)}if(!Number.isFinite(x))return null;c.push(x-10,y+10);let f=(e,t)=>"x"===a.main?{x:e,y:t}:{x:t,y:e},g=Math.sign(h[a.main]-o[a.main])||1,p=Math.min(12,Math.abs(h[a.main]-o[a.main])/3),m=o[a.main]+g*p,M=h[a.main]-g*p,b=(o[a.cross]+h[a.cross])/2;for(let t of[...new Set(c)].sort((e,t)=>Math.abs(e-b)-Math.abs(t-b))){let n=eX([o,f(m,o[a.cross]),f(m,t),f(M,t),f(M,h[a.cross]),h]);if(!s(n,r)&&nF(n,e,r,i)&&l(n))return n}return null},d=e=>{for(let t=1;t<e.length;t++){i?.(1);let n=e[t-1],r=e[t];if(!Number.isFinite(n.x)||!Number.isFinite(n.y)||!Number.isFinite(r.x)||!Number.isFinite(r.y)||n.x!==r.x&&n.y!==r.y||n.x===r.x&&n.y===r.y)return!1;let a=n.x===r.x;for(let o=1;o<t;o++){i?.(1);let s=e[o-1],l=e[o];if(a===(s.x===l.x)){let e=a?"y":"x",i=a?"x":"y";if(n[i]!==s[i])continue;let h=Math.max(Math.min(n[e],r[e]),Math.min(s[e],l[e])),u=Math.min(Math.max(n[e],r[e]),Math.max(s[e],l[e]));if(o===t-1?h<u:h<=u)return!1}else if(o!==t-1){let e=a?n.x:s.x,t=a?s.y:n.y;if(e>=Math.min(n.x,r.x)&&e<=Math.max(n.x,r.x)&&t>=Math.min(n.y,r.y)&&t<=Math.max(n.y,r.y)&&e>=Math.min(s.x,l.x)&&e<=Math.max(s.x,l.x)&&t>=Math.min(s.y,l.y)&&t<=Math.max(s.y,l.y))return!1}}}return!0};i?.(1);let x=new Set,y=(t,n)=>{if(t.length<3)return null;let r=t.at(-1),a=t.at(-2),o=t.at(-3),h=a.y===r.y&&a.x!==r.x?"x":a.x===r.x&&a.y!==r.y?"y":void 0;if(!h)return null;let u="x"===h?"y":"x";if(o[h]!==a[h]||o[u]===a[u]||!s([a,r],n))return null;let y=[];for(let t of e)i?.(1),n.has(t.id)||!nl(a,r,t)||(i?.(2),y.push(t[u]-10,t[u]+("x"===u?t.width:t.height)+10));y.sort((e,t)=>(i?.(1),Math.abs(e-a[u])-Math.abs(t-a[u])));let c=r[h]+Math.sign(a[h]-r[h])*Math.min(10,Math.abs(a[h]-r[h])/2);for(let o of y){i?.(2*t.length+12);let y={...a,[u]:o},f={...r,[h]:c,[u]:o},g={...r,[h]:c},p=eX([...t.slice(0,-2),y,f,g,r]),m=(e,t,n)=>t.x===e.x&&n.x===e.x&&Math.sign(t.y-e.y)===Math.sign(n.y-e.y)||t.y===e.y&&n.y===e.y&&Math.sign(t.x-e.x)===Math.sign(n.x-e.x);if(!(!m(t[0],t[1],p[1])||!m(r,a,p.at(-2)))&&!s(p,x)&&nF(p,e,n,i)&&l(p)&&d(p))return p}return null};for(let e of t){if(i?.(1),e.source===e.target||e.points.length<2)continue;let t=o.get(e.source),n=o.get(e.target);if(!t||!n)continue;let r=new Set([e.source,e.target]);if(!s(e.points,r)||!ns(t,e.points[0])||!ns(n,e.points[e.points.length-1]))continue;let a=h(e.points,r)??u(e.points,r)??y(e.points,r);if(a||(i?.(e.points.length),a=y(e.points.toReversed(),r)?.reverse()??null),!a)continue;let l=e.routeCertificate;e.points=a,tG(e,l,t,n),e.label&&(e.labelPosition=p(a))}}function nZ(e,t,n){let i=new Map(e.map(e=>[e.id,e]));for(let r of t){if(!n.has(r)||r.label||4!==r.points.length)continue;let t=ts(r),[a,o,s,l]=r.points;if(!a||!o||!s||!l)continue;let h=i.get(r.target);if(!h||"rectangle"!==h.shape)continue;let u=new Set([r.source,r.target]);if(.01>Math.abs(a.y-o.y)&&.01>Math.abs(o.x-s.x)&&.01>Math.abs(s.y-l.y)&&6>=Math.abs(o.y-s.y)){let n={x:l.x,y:a.y};(.01>Math.abs(l.x-h.x)||.01>Math.abs(l.x-(h.x+h.width)))&&n.y>=h.y-.5&&n.y<=h.y+h.height+.5&&nF([a,n],e,u)&&(r.points=[a,n],r.routeCertificate=void 0,tl(r,t));continue}if(.01>Math.abs(a.x-o.x)&&.01>Math.abs(o.y-s.y)&&.01>Math.abs(s.x-l.x)&&6>=Math.abs(o.x-s.x)){let n={x:a.x,y:l.y};(.01>Math.abs(l.y-h.y)||.01>Math.abs(l.y-(h.y+h.height)))&&n.x>=h.x-.5&&n.x<=h.x+h.width+.5&&nF([a,n],e,u)&&(r.points=[a,n],r.routeCertificate=void 0,tl(r,t))}}}export{Y as a,Q as b,J as c,T as d,_ as e,D as f,G as g,K as h,td as i,tg as j,tp as k,ea as l,es as m,el as n,eg as o,eM as p,ek as q,ev as r,eH as s,eA as t,eF as u,eO as v,ez as w,ej as x,eY as y,eZ as z,eq as A,eJ as B,eX as C,tn as D,tY as E,tZ as F,tq as G,tV as H,tU as I,ta as J,ts as K,tl as L,th as M,tW as N,tH as O,tA as P,tF as Q,tD as R,tG as S,t5 as T,t6 as U,t4 as V,t3 as W,t7 as X,t9 as Y,ne as Z,ni as _,ns as $,nl as aa,nd as ba,nx as ca,ny as da,nb as ea,nw as fa,nv as ga,nS as ha,nC as ia,nP as ja,nN as ka,nW as la,nL as ma,nE as na,nI as oa,nB as pa,nR as qa,nH as ra,nA as sa,nF as ta,nz as ua,nj as va,nY as wa,nQ as xa,nZ as ya};
@@ -1,6 +0,0 @@
1
- import{b as e,c as t}from"./chunk-2GPK4VFF.js";import{b as n,d as i}from"./chunk-QA6GJQ4X.js";import{q as o,r as a,w as r}from"./chunk-DF6765YX.js";import{b as l,c as s,f as d,g as c}from"./chunk-CN7WTBWB.js";import{D as h,e as p,g as g,i as u}from"./chunk-HLWUNUCM.js";import{c as f,h as x,i as b,k as m,ma as y,oa as k,r as w,s as v,y as M}from"./chunk-X2UYKWKM.js";import{b as I,i as S,j as $,k as L,m as C,q as W,u as P}from"./chunk-TYZOZXUJ.js";import{a as q,b as F,c as H,d as E,g as z,h as Y,l as B,m as T,n as _,o as N}from"./chunk-NO7ZIVRU.js";import{Aa as O,Ba as j,C as X,E as A,F as D,G as R,H as U,M as Z,N as G,O as V,Ob as J,T as Q,Tb as K,Z as ee,ja as et,la as en,ma as ei,o as eo,va as ea,x as er,y as el,za as es}from"./chunk-Z3FDIVLN.js";import{e as ed}from"./chunk-N5ELX7LR.js";import{a as ec}from"./chunk-5UVGUSD6.js";var eh=/&amp;(#\d+|#[xX][0-9a-fA-F]+|[a-zA-Z][a-zA-Z\d]{0,31});|&(#\d+|#[xX][0-9a-fA-F]+|[a-zA-Z][a-zA-Z\d]{0,31});/g;function ep(e,t){let i=e.originalText;if(!i.includes("&"))return e;let o=i.includes("&")?i.replace(eh,(e,t,i)=>{if(void 0!==t)return t.startsWith("#")||b.has(t)||n(t)?`#38;${t.replace("#","#35;")}#59;`:`&${t};`;if(!i.startsWith("#")&&!b.has(i))return n(i)?`#${i};`:e;let o=ec(e);return"#"===o?"#35;":";"===o?"#59;":o}):i;return o===("decoded"===t?ec(i):i)?e:r(o)}var eg={subject:"Sequence text entity",example:"A->>B: #35;"},eu=RegExp(`#\\w+;|${x.source}`,"g");function ef(e){let t=e.trim(),n=/^:?(wrap|nowrap):/.exec(t);return n?{text:t.slice(n[0].length).trim(),wrap:"wrap"===n[1]}:{text:t}}function ex(e){let t=function(e){let t=i(e,eg);if(t===e)return{value:t};let n=A(R(U(e)),eu,e=>i(e,eg));return{value:t,content:Object.freeze({value:t,authored:e,prepared:n})}}(e),n=i(U(e),eg);return{label:n,...t.content?{labelContent:Object.freeze({...t.content,value:n})}:{}}}var eb=/^(loop|alt|opt|par_over|par|critical|break|rect|box)\b\s*([\s\S]*)$/i,em=/^(else|and|option)\b\s*([\s\S]*)$/i;function ey(e){let t=e.toLowerCase();return"transparent"===t||t in et||!!/^(?:#|(?:rgb|rgba|hsl|hsla)\()/i.test(e)&&null!==es(e)}function ek(e){let t=et[e.toLowerCase()];if(t)return t;let n=en(e);if(n)return ei(n[0],n[1],n[2]);let i=e.match(/^rgba?\(\s*(\d{1,3})\s*[, ]\s*(\d{1,3})\s*[, ]\s*(\d{1,3})/i);return i?ei(Math.min(255,Number.parseInt(i[1],10)),Math.min(255,Number.parseInt(i[2],10)),Math.min(255,Number.parseInt(i[3],10))):null}var ew=class{constructor(e={}){this.options=e}options;records=new Map;order=[];boxes=[];currentBox;apply(e){if("links"===e.kind){let t=this.records.get(e.id);t&&(t.links={...t.links,...e.links});return}this.addActor(e.id,"declare"===e.kind?e:void 0)}applyAll(e){for(let t of e)this.apply(t)}openBox(e){this.boxes.push(e),this.currentBox=this.boxes.length-1}closeBox(){this.currentBox=void 0}has(e){return this.records.has(e)}indexOf(e){return this.order.indexOf(e)}list(){return this.order.map(e=>this.records.get(e))}addActor(e,t){let n=this.records.get(e),i=this.currentBox;if(n&&(void 0!==i&&void 0!==n.box&&i!==n.box&&this.options.onBoxConflict?.(e),void 0!==(i=n.box??i)&&(n.box=i),t?.label===void 0||t.create))return;let o={id:e,label:t?.label??e,...t?.wrap===void 0?{}:{wrap:t.wrap},type:t?.type??"participant",...t?{keyword:t.keyword}:{},...n?.links&&!this.options.upstreamLinks?{links:n.links}:{},...void 0!==i?{box:i}:{}};this.records.set(e,o),n||this.order.push(e),void 0!==this.currentBox&&i===this.currentBox&&this.boxes[this.currentBox].actorIds.push(e)}},ev=new Map([["<<--\x3e>",["filled","filled"]],["<<->>",["filled","filled"]],["--\x3e>",["none","filled"]],["->>",["none","filled"]],["--\x3e",["none","none"]],["->",["none","none"]],["--x",["none","cross"]],["-x",["none","cross"]],["--)",["none","open"]],["-)",["none","open"]],["--|\\",["none","half-top"]],["-|\\",["none","half-top"]],["--|/",["none","half-bottom"]],["-|/",["none","half-bottom"]],["--\\\\",["none","stick-top"]],["-\\\\",["none","stick-top"]],["--//",["none","stick-bottom"]],["-//",["none","stick-bottom"]],["/|--",["half-bottom","none"]],["/|-",["half-bottom","none"]],["\\|--",["half-top","none"]],["\\|-",["half-top","none"]],["//--",["stick-bottom","none"]],["//-",["stick-bottom","none"]],["\\\\--",["stick-top","none"]],["\\\\-",["stick-top","none"]],["--|",["none","stick-top"]],["-|",["none","stick-top"]],["--/",["none","stick-bottom"]],["-/",["none","stick-bottom"]],["--\\",["none","stick-top"]],["-\\",["none","stick-top"]],["|--",["stick-top","none"]],["|-",["stick-top","none"]],["/--",["stick-bottom","none"]],["/-",["stick-bottom","none"]],["\\--",["stick-top","none"]],["\\-",["stick-top","none"]]]),eM=new Set(["--|","-|","--/","-/","--\\","-\\","|--","|-","/--","/-","\\--","\\-"]),eI=new Map([...eM].map(e=>{let[t,n]=ev.get(e),i=[...ev].find(([i,o])=>!eM.has(i)&&o[0]===t&&o[1]===n&&i.includes("--")===e.includes("--"))[0];return[e,i]})),eS=[...ev.keys()].sort((e,t)=>t.length-e.length),e$=eS.map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|"),eL=new RegExp(String.raw`^(\S+?)(\(\))?\s*(${e$})`),eC=new RegExp(String.raw`^(\S+?)\s+(\(\))\s*(${e$})`),eW=new Set(["participant","actor","note","alt","else","loop","rect","opt","par","and","end","activate","deactivate","autonumber","box","create","destroy","link","links","critical","break","option","title","over","off","properties","details","sequencediagram","par_over"]),eP=new Set([...eW,"acctitle","accdescr"]),eq=/(?:#\w+;|[^\/\\\+\()\+<\->\->:\n,;])+((?!(\-x|\-\-x|\-\)|\-\-\)|\-\|\\|\-\\|\-\/|\-\/\/|\-\|\/|\/\|\-|\\\|\-|\/\/\-|\\\\\-|\/\|\-|\-\-\|\\|\-\-|\(\)))[\-]*(?:#\w+;|[^\+<\->\->:\n,;])+)*/iy;function eF(e,t){return eq.lastIndex=t,eq.exec(e)?.[0].trim()??""}function eH(e,t){if(!e||e.trim()!==e||/[\r\n]/.test(e))return!1;let n=m(e);if(n.startsWith("#"))return!1;if("declaration"===t)return eO(e)&&!/:/.test(n)&&!n.includes("%%{");if(n.startsWith("%")||n.includes("%%"))return!1;let i=n.toLowerCase(),o=/^(\w+)\b/.exec(i)?.[1];return!(o&&eW.has(o)&&(!["title","link","links","properties","details"].includes(o)||/\s/.test(i.slice(o.length,o.length+1)))||/^(?:\d+(?:\.\d{1,2})?|\.\d{1,2})(?=\s)/.test(n)||eW.has(i)&&!["title","link","links","properties","details"].includes(i)||"receiver"===t&&["acctitle","accdescr"].includes(i)||/^(?:left|right) of\b/.test(i))&&eF(`${n}${"sender"===t?"->>Z:":":"}`,0)===n}var eE=new WeakMap,ez=new WeakMap;function eY(e,t){eE.set(e,t)}function eB(e,t){ez.set(e,t)}function eT(n,i={}){let r=a(n),l=M(r.map(e=>e.raw)),s=l.familyLines.flatMap((e,t)=>e.trim()?[{text:e.trim(),origin:r[l.familyOrigins[t]].line}]:[]);n=s.map(e=>e.text);let d=e=>{let t=s[e]?.origin??e;return i.authoredLine?.(t)??t+1};p("sequence")&&void 0!==n[0]&&g("sequence","header",n[0],{line:1,unit:"normalized"});let c={actors:[],messages:[],blocks:[],notes:[],activationEvents:[],boxes:[],...void 0!==l.accessibility.title?{accessibilityTitle:U(l.accessibility.title)}:{},...void 0!==l.accessibility.descr?{accessibilityDescription:U(l.accessibility.descr)}:{}},h=new ew,f=new Map,x=new Map,b=function(n){let i=a(n).map(n=>{if(!n.raw.trim()||o(n.raw))return{...n,syntax:null};try{return{...n,syntax:function(n){let i=function(n){let i=n.match(/^(participant|actor)\s+([^\s@]+)\s*@\{/i);if(i){let o=i[1].toLowerCase(),a=i[2];eA(a);let r=e(n,i[0].length-1,"sequence"),l=r.ok?n.slice(r.end+1):"",s=l.match(/^\s+as(?:\s+(.*))?$/i);if(!r.ok||""!==l.trim()&&!s)throw v({what:`Invalid participant metadata in "${n}": ${r.ok?`unexpected "${l.trim()}" after it`:r.message}`,expectedForm:'a YAML mapping in @{…} with no "}" inside, then optionally `as <label>`',example:'participant DB@{ "type": "database", "alias": "Orders" }'});let d=s?ef(s[1]??""):void 0,c=d?d.text||null:void 0;if(null===c)return null;let{entries:h}=r,p=h.get("type"),g="string"==typeof p?p.toLowerCase():o;if(!eN.has(g))throw Error(`Unknown sequence actor type '${g}'`);let u=t(h.get("alias")),f=void 0!==u&&(void 0===c||c===a)?u:c,x=[...h.keys()].filter(e=>"type"!==e&&"alias"!==e);return{id:a,label:f??a,type:g,keyword:o,aliased:void 0!==f,...d?.wrap===void 0?{}:{wrap:d.wrap},...x.length?{unmodeledMetadata:x}:{}}}if(n.includes("@{"))return null;let o=n.match(/^(participant|actor)\s+/i);if(!o)return null;let a=n.slice(o[0].length),r=a.match(/^(\S+?)\s+as(\s*)(.+)$/i);if(!r&&(!a||/\s/.test(a)&&/[<>:\n,;@]/.test(m(a))))return null;let l=r?r[1]:a.trim();eA(l);let s=o[1].toLowerCase(),d=r?.[3]===void 0?void 0:ef(r[3]);return{id:l,label:d?.text??l,type:s,keyword:s,aliased:!!r,...r?.[2]===""?{unspacedAlias:!0}:{},...d?.wrap===void 0?{}:{wrap:d.wrap}}}(n);if(i)return{kind:"declaration",declaration:i};let o=function(e){let t=e.match(/^link\s+(\S+)\s*:\s*(.+?)\s*@\s*(\S+)$/i);if(t)return/^(?:https?:|mailto:)/i.test(t[3])?{actorId:t[1],links:{[t[2].trim()]:t[3]}}:null;let n=e.match(/^links\s+(\S+)\s*:\s*(\{.*\})$/i);if(!n)return null;try{let e=JSON.parse(n[2]),t={};for(let[n,i]of Object.entries(e))"string"==typeof i&&/^(?:https?:|mailto:)/i.test(i)&&(t[n]=i);return Object.keys(t).length>0?{actorId:n[1],links:t}:null}catch{return null}}(n);if(o)return{kind:"links",...o};let a=n.match(/^(?:properties|details)\s+(\S+)\s*:/i);if(a)return{kind:"actor-data",actorId:a[1]};let r=n.match(/^title(?:\s*:\s*|\s+)(.+)$/i);if(r)return{kind:"title",text:r[1].trim()};let l=n.match(/^autonumber(?:\s+(.*))?$/i);if(l){let e=l[1]?.trim()??"";if(/^off$/i.test(e))return{kind:"autonumber",numbering:null};let t=e.match(/^((?:\d+(?:\.\d{1,2})?|\.\d{1,2}))(?:\s+((?:\d+(?:\.\d{1,2})?|\.\d{1,2})))?$/);return(!e||t)&&(!t||Number.isFinite(Number(t[1]))&&(void 0===t[2]||Number.isFinite(Number(t[2]))))?{kind:"autonumber",numbering:t?{next:Number.parseFloat(t[1]),...void 0===t[2]?{}:{step:Number.parseFloat(t[2])}}:{}}:null}let s=n.match(/^box(?:\s+(.*))?$/i);if(s)return{kind:"box",text:s[1]?.trim()??""};let d=function(e){let t=e.match(/^create\s+(participant|actor)\s+(\S+?)(?:\s+as\s+(.+))?$/i);if(!t)return null;let n=t[2];eA(n);let i=void 0===t[3]?void 0:ef(t[3]);return{id:n,label:i?.text??n,type:t[1].toLowerCase(),...i?.wrap===void 0?{}:{wrap:i.wrap}}}(n);if(d)return{kind:"create",declaration:d};let c=n.match(/^destroy\s+(\S+)$/i);if(c)return{kind:"destroy",actorId:c[1]};let h=function(e){let t=e.match(/^Note\s+(left of|right of|over)\s+([^:]+):\s*(.*)$/i);if(!t)return null;let n=t[1].toLowerCase();return{actorIds:t[2].trim().split(",").map(e=>e.trim()),...ef(t[3]),position:"left of"===n?"left":"right of"===n?"right":"over"}}(n);if(h)return{kind:"note",note:h};let p=function(e){let t=eb.exec(e);if(!t)return null;let n=t[1].toLowerCase(),i=t[2]?.trim()??"";if("box"===n)return{type:n,label:i};let o=ef(i);return{type:n,label:o.text,...void 0===o.wrap?{}:{wrap:o.wrap}}}(n);if(p&&"box"!==p.type)return{kind:"block",opener:{type:p.type,label:p.label,...void 0===p.wrap?{}:{wrap:p.wrap}}};let g=function(e){let t=em.exec(e);if(!t)return null;let n=ef(t[2]??"");return{type:t[1].toLowerCase(),label:n.text,...void 0===n.wrap?{}:{wrap:n.wrap}}}(n);if(g)return{kind:"continuation",continuation:g};if("end"===n)return{kind:"end"};let u=function(e){var t;let n=function(e){eq.lastIndex=0;let t=eq.exec(e);if(!t)return;let n=t[0].length,i=e.startsWith("()",n),o=i&&/\s$/.test(t[0]);for(i&&(n+=2);n<e.length&&/\s/.test(e[n]);)n++;let a=eS.find(t=>e.startsWith(t,n));if(a)return n+=a.length,{from:t[0].trim(),arrow:a,end:n,centralStart:i,spacedCentral:o}}(e);if(!n){let t=e.match(eL),i=t??e.match(eC);i&&(n={from:i[1],centralStart:!!i[2],arrow:i[3],end:i[0].length,spacedCentral:!t})}if(!n||(t=n.arrow,!ev.has(t)))return null;let{from:i,arrow:o,centralStart:a,spacedCentral:r}=n;if(r&&(/^(?:[0-9]+(?:\.[0-9]{1,2})?|\.[0-9]{1,2})$/.test(i)||eW.has(i.toLowerCase())))return null;let l=e.slice(n.end).trimStart(),s=l.startsWith("()");s&&(l=l.slice(2).trimStart());let d="+"===l[0]||"-"===l[0]?l[0]:void 0;if(r&&d)return null;d&&(l=l.slice(1).trimStart());let c=l.indexOf(":");if(c<1)return null;let h=l.slice(0,c).trimEnd(),{text:p,wrap:g}=ef(l.slice(c+1));if(!h||r&&(/[+<>]/.test(h)||h.includes("()")||eP.has(h.toLowerCase())))return null;let u=m(e),f=m(i),x=m(h),b=m(e.slice(0,e.length-l.length)).length,y=eF(u,0);return y.length<=f.length&&(y!==f||eF(u,b)!==x)?null:{from:i,arrow:eI.get(o)??o,activationMark:d,to:h,label:p,centralStart:a,centralEnd:s,...void 0===g?{}:{wrap:g},...eM.has(o)?{localArrow:o}:{}}}(n);if(u)return{kind:"message",message:u};let f=n.match(/^(activate|deactivate)\s+(\S+)$/i);return f?{kind:"activation",actorId:f[2],activate:"activate"===f[1].toLowerCase()}:null}(n.raw.trim())}}catch(e){if(e instanceof J)throw e;return{...n,syntax:null,error:e}}}),r=[],l=[],s=(e,t,n)=>{l.push({line:e.line,syntax:t,message:n})};for(let[e,t]of i.entries()){let{syntax:n}=t;if(r.length&&(t.parent=r.at(-1)),!n){t.error instanceof eX?s(t,"sequence_participant_id",t.error.message):t.raw.trim()&&!o(t.raw)&&s(t,"sequence_statement",`Sequence statement is preserved in source but not drawn: ${t.raw.trim()}`);continue}if("block"===n.kind||"box"===n.kind)r.push(e);else if("end"===n.kind){let n=r.pop();void 0===n?s(t,"sequence_block_boundary","Sequence end has no open block or box"):(t.closes=n,i[n].endIndex=e)}else if("continuation"===n.kind){var d,c;let e=void 0!==t.parent?i[t.parent].syntax:null;e?.kind==="block"&&(d=n.continuation.type,c=e.opener.type,"else"===d&&"alt"===c||"and"===d&&("par"===c||"par_over"===c)||"option"===d&&"critical"===c)||s(t,"sequence_block_boundary",`Sequence ${n.continuation.type} does not belong to the enclosing block`)}else if("declaration"===n.kind&&n.declaration.unmodeledMetadata?.length)s(t,"sequence_participant_metadata",`Participant metadata fields ${n.declaration.unmodeledMetadata.join(", ")} are not modeled; the declaration is preserved as source`);else if("message"===n.kind&&n.message.localArrow){let{localArrow:e,arrow:i}=n.message;s(t,"sequence_local_arrow",`The arrow ${e} is a local spelling pinned Mermaid does not read, so it rejects this line. Ours draws it as Mermaid's ${i} and writes ${i}`)}else"declaration"===n.kind&&n.declaration.unspacedAlias&&s(t,"sequence_unspaced_alias","Participant text immediately following as is read as its alias. Pinned Mermaid can reject this or read it as part of the ID; write as <label> with a separating space");if("declaration"===n.kind||"create"===n.kind){let e=ej(n.declaration.id);e&&s(t,"sequence_participant_id_extension",e)}if("message"===n.kind)for(let[e,i]of[["sender",n.message.from],["receiver",n.message.to]])eH(i,e)||s(t,"sequence_message_id_extension",`Participant "${i}" is read as the ${e}, but pinned Mermaid reads another token there; rename it before typed editing`)}for(let e of r)s(i[e],"sequence_block_boundary","Sequence block or box is never closed by end");return{statements:i,issues:l}}(n.slice(1)),y=b.issues.find(e=>"sequence_block_boundary"===e.syntax);if(y)throw Error(`SEQUENCE_BLOCK_BOUNDARY: line ${d(y.line+1)}: ${y.message}`);let k=new Map,w=[],S=new Map,$={visible:!0===i.showSequenceNumbers,next:1,step:1},L=[],C=[],W=e=>{let{from:t,to:n}=e,o=function(e){let t=e.includes("--")?"dashed":"solid",[n,i]=ev.get(e)??["none","none"];return{lineStyle:t,startHead:n,endHead:i}}(e.arrow),a={from:t,to:n,...ex(e.label.trim()),...(e.wrap??i.wrap)===void 0?{}:{wrap:e.wrap??i.wrap},lineStyle:o.lineStyle,startHead:o.startHead,endHead:o.endHead,centralStart:e.centralStart,centralEnd:e.centralEnd};"+"===e.activationMark&&(a.activate=!0),"-"===e.activationMark&&(a.deactivate=!0),$.visible&&(a.number=$.next),$.next=Math.round(($.next+$.step)*100)/100,eD(L,e=>e===n,e=>{f.set(e,c.messages.length),p("sequence")&&u("sequence","bind-create",{id:e,messageIndex:c.messages.length})}),eD(C,e=>e===t||e===n,e=>{x.set(e,c.messages.length),p("sequence")&&u("sequence","bind-destroy",{id:e,messageIndex:c.messages.length})}),c.messages.push(a),p("sequence")&&u("sequence","add-message",a)};for(let[e,t]of b.statements.entries()){let n=t.raw.trim();if(p("sequence")&&g("sequence",t.syntax?.kind??"unrecognized",t.raw,{line:t.line+2,column:t.column+1,unit:"normalized"}),t.error)throw t.error;let a=t.syntax;if(!a){if(void 0!==l.unclosedIndex&&n===l.familyLines[l.unclosedIndex]?.trim())continue;if(n&&!o(n))throw Error(`SEQUENCE_UNSUPPORTED_STATEMENT: line ${d(t.line+1)}: ${n}`);continue}for(let e of function(e){switch(e?.kind){case"declaration":{let{id:t,label:n,type:i,keyword:o,aliased:a,wrap:r}=e.declaration;return[{kind:"declare",id:t,keyword:o,type:i,...a?{label:n}:{},...void 0===r?{}:{wrap:r}}]}case"create":{let{id:t,label:n,type:i,wrap:o}=e.declaration;return[{kind:"declare",id:t,keyword:"actor"===i?"actor":"participant",type:i,label:n,...void 0===o?{}:{wrap:o},create:!0}]}case"links":return[{kind:"mention",id:e.actorId},{kind:"links",id:e.actorId,links:e.links}];case"actor-data":return[{kind:"mention",id:e.actorId}];case"note":return e.note.actorIds.map(e=>({kind:"mention",id:e}));case"message":return[{kind:"mention",id:e.message.from},{kind:"mention",id:e.message.to}];default:return[]}}(a))h.apply(e),p("sequence")&&u("sequence","participant.apply",e);switch(a.kind){case"declaration":case"create":"create"===a.kind&&L.push(a.declaration.id);break;case"links":case"actor-data":break;case"title":{let e=ex(a.text);c.title=e.label,c.titleContent=e.labelContent,p("sequence")&&u("sequence","set-title",c.title);break}case"autonumber":$.visible=null!==a.numbering,a.numbering?.next!==void 0&&($.next=a.numbering.next,$.step=a.numbering.step??1),p("sequence")&&u("sequence","set-autonumber",$);break;case"box":{let e=a.text,t={actorIds:[]},n=e.match(/^((?:rgb|rgba|hsl|hsla)\([^)]*\))\s*(.*)$/i),o=e;if(n&&ey(n[1]))t.color=n[1],o=n[2]?.trim()??"";else{let n=e.split(/\s+/,1)[0]??"";n&&ey(n)&&(t.color=n,o=e.slice(n.length).trim())}if(o){let e=ef(o);Object.assign(t,ex(e.text)),(e.wrap??i.wrap)!==void 0&&(t.wrap=e.wrap??i.wrap)}c.boxes.push(t),h.openBox(t),p("sequence")&&u("sequence","open-box",{index:c.boxes.length-1,box:t});break}case"destroy":C.push(a.actorId),p("sequence")&&u("sequence","pending-destroy",a.actorId);break;case"note":{let{note:e}=a,n=ex(e.text),o=c.notes.length;c.notes.push({actorIds:e.actorIds,text:n.label,...(e.wrap??i.wrap)===void 0?{}:{wrap:e.wrap??i.wrap},...n.labelContent?{textContent:n.labelContent}:{},position:e.position,afterIndex:c.messages.length-1}),p("sequence")&&u("sequence","add-note",{note:c.notes.at(-1),parent:t.parent});for(let e=t.parent;void 0!==e;e=k.get(e)?.parent)k.get(e)?.noteIndices.push(o);break}case"block":{let{opener:n}=a,o=n.type,r=ex("rect"===n.type?"":n.label),l="rect"===n.type&&n.label.startsWith("#")?"":n.label,s="rect"===n.type?function(e){let t=I(e);if(!t)return;let n=t.toLowerCase();if("transparent"===n||Object.hasOwn(et,n))return t;let i=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i.exec(t);if(i&&i.slice(1).every(e=>255>=Number(e)))return t;let o=/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0(?:\.\d+)?|\.\d+|1(?:\.0+)?)\s*\)$/i.exec(t);if(o&&o.slice(1,4).every(e=>255>=Number(e)))return t}(l):void 0;if("rect"===n.type&&l&&!s)throw Error("SEQUENCE_RECT_COLOR_UNSUPPORTED: rect requires a safe concrete CSS color");k.set(e,{type:o,...r,...(n.wrap??i.wrap)===void 0?{}:{wrap:n.wrap??i.wrap},...s?{color:s}:{},startIndex:c.messages.length,dividers:[],dividerNoteIndices:[],parent:t.parent,parentSection:void 0===t.parent?0:k.get(t.parent)?.dividers.length??0,noteIndices:[],childBlockIndices:[],childSectionIndices:[]}),w.push({kind:"open",blockId:e,messageIndex:c.messages.length,noteIndex:c.notes.length}),p("sequence")&&u("sequence","open-block",{id:e,block:k.get(e)});break}case"continuation":{let e=void 0!==t.parent?k.get(t.parent):void 0;e&&(w.push({kind:"divider",blockId:t.parent,messageIndex:c.messages.length,noteIndex:c.notes.length,dividerIndex:e.dividers.length}),e.dividerNoteIndices.push(c.notes.length),e.dividers.push({index:c.messages.length,...ex(a.continuation.label),...(a.continuation.wrap??i.wrap)===void 0?{}:{wrap:a.continuation.wrap??i.wrap}}),p("sequence")&&u("sequence","divide-block",{parent:t.parent,divider:e.dividers.at(-1),type:a.continuation.type}));break}case"end":{let e=k.get(t.closes);if(e){let n=c.blocks.length;S.set(t.closes,n),w.push({kind:"close",blockId:t.closes,messageIndex:c.messages.length,noteIndex:c.notes.length});let i={type:e.type,label:e.label,...void 0===e.wrap?{}:{wrap:e.wrap},...e.labelContent?{labelContent:e.labelContent}:{},...e.color?{color:e.color}:{},startIndex:e.startIndex,endIndex:Math.max(c.messages.length-1,e.startIndex),dividers:e.dividers};eE.set(i,{endMessageExclusive:c.messages.length,endNoteExclusive:c.notes.length,dividerNoteIndices:e.dividerNoteIndices,noteIndices:e.noteIndices,childBlockIndices:e.childBlockIndices,childSectionIndices:e.childSectionIndices}),void 0!==e.parent&&(k.get(e.parent)?.childBlockIndices.push(n),k.get(e.parent)?.childSectionIndices.push(e.parentSection)),c.blocks.push(i),p("sequence")&&u("sequence","close-block",{id:t.closes,parent:e.parent,parentSection:e.parentSection,block:i,notes:e.noteIndices,children:e.childBlockIndices})}else h.closeBox(),p("sequence")&&u("sequence","close-box",null);break}case"message":W(a.message);break;case"activation":c.activationEvents.push({actorId:a.actorId,kind:a.activate?"activate":"deactivate",messageIndex:c.messages.length}),p("sequence")&&u("sequence","activation",c.activationEvents.at(-1))}}return c.actors=h.list().map(({id:e,label:t,type:n,links:o,box:a,wrap:r})=>({id:e,...ex(t),type:n,...(r??i.wrap)===void 0?{}:{wrap:r??i.wrap},...o?{links:o}:{},...void 0!==a?{box:a}:{},...f.has(e)?{createMessageIndex:f.get(e)}:{},...x.has(e)?{destroyMessageIndex:x.get(e)}:{}})),ez.set(c,w.map(({blockId:e,...t})=>({...t,blockIndex:S.get(e)}))),c}function e_(e){let t;return n=>{if(!t){let n=e.originalText.split(/\r?\n/),i=e.wrapperSource?e.wrapperSource.split(/\r?\n/).length-1:0,o=n.slice(i).flatMap((e,t)=>(0===t?ed(e).split(`
2
- `):[e]).map(e=>({text:e.trim(),line:i+t+1}))),a=0;t=e.familyLines.map(e=>{let t=e.trim();for(let e=a;e<o.length;e++){let n=o[e].text;if(n===t||n.slice(n.indexOf("}")+1).trim()===t)return a=e+1,o[e].line}})}return t[n]}}var eN=new Set(["participant","actor","boundary","control","entity","database","collections","queue"]);function eO(e){return"string"==typeof e&&""!==e&&e.trim()===e&&!/[<>,;@#\r\n]/.test(m(e))}function ej(e){let t=eO(e);return t&&eH(e,"declaration")?null:`Sequence participant ID ${JSON.stringify(e)} ${t?"is read as authored, but pinned Mermaid rejects colons in declaration IDs":"has ambiguous declaration delimiters or whitespace"}. Typed editing and serialization require a portable ID; rename this ID and its references, and put display punctuation in an alias`}var eX=class extends w{};function eA(e){if(!eO(e))throw new eX(ej(e))}function eD(e,t,n){for(let i=e.length-1;i>=0;i--){let o=e[i];t(o)&&(n(o),e.splice(i,1))}}function eR(e,t,n,i,o,a,r=0,l=ee(e,{fontSize:o,fontWeight:a,letterSpacing:r})){let s="middle"===i?t-l.width/2:"start"===i?t:t-l.width;return{text:l.text,block:l,x:t,y:n,anchor:i,fontSize:o,fontWeight:a,letterSpacing:r,bounds:{x:s,y:n-l.height/2,width:l.width,height:l.height},metrics:l}}function eU(e,t){let n=Math.min(e.x,t.x),i=Math.min(e.y,t.y);return{x:n,y:i,width:Math.max(e.x+e.width,t.x+t.width)-n,height:Math.max(e.y+e.height,t.y+t.height)-i}}function eZ(e,t,n){return{x:e.x+t,y:e.y+n,width:e.width,height:e.height}}function eG(e,t,n){return{...e,x:e.x+t,y:e.y+n,bounds:eZ(e.bounds,t,n)}}function eV(e,t,n,i){if("participant"===e.type){let o=eR(t.displayLabel,n,i+t.height/2,"middle",t.fontSize,t.fontWeight,t.letterSpacing,t.block),a={x:n-t.width/2,y:i,width:t.width,height:t.height};return{id:e.id,label:e.label,type:e.type,...e.links?{links:{...e.links}}:{},...t.menuBlock?{menuBlock:t.menuBlock}:{},x:n,y:i,width:t.width,height:t.height,bounds:a,labelPosition:o}}let o="actor"===e.type?i+t.height:Math.max(i+t.height,i+26),a=o+Math.max(14,t.labelMetrics.lineHeight/2+5.5)+(t.labelMetrics.lines.length-1)/2*t.labelMetrics.lineHeight,r=eR(t.displayLabel,n,a,"middle",t.fontSize,t.fontWeight,t.letterSpacing,t.block),l=eU({x:n-t.width/2,y:i,width:t.width,height:o-i},r.bounds),s={x:l.x,y:l.y,width:l.width,height:l.height+4};return{id:e.id,label:e.label,type:e.type,...e.links?{links:{...e.links}}:{},...t.menuBlock?{menuBlock:t.menuBlock}:{},x:n,y:i,width:t.width,height:t.height,bounds:s,labelPosition:r}}function eJ(e,t,n,i){let o=t.dividerNoteIndices[i]??-1,a=t.dividerNoteIndices[i+1]??t.endNoteExclusive;return o>=0&&o<a&&n.notes[o].afterIndex<e.dividers[i].index?o:void 0}function eQ(e,t,n,i,o,a,r,l,s,d,c,h,p){let g,u,f=e.startIndex<n.endMessageExclusive?r[e.startIndex]:void 0,x=e.startIndex<n.endMessageExclusive?r[n.endMessageExclusive-1]:void 0,b=new Set;for(let t=e.startIndex;t<n.endMessageExclusive;t++){let e=i.messages[t];e&&(b.add(o.get(e.from)??0),b.add(o.get(e.to)??0))}for(let e of n.noteIndices){let t=i.notes[e];if(t)for(let e of t.actorIds){let t=o.get(e);void 0!==t&&b.add(t)}}if(0===b.size)for(let e=0;e<i.actors.length;e++)b.add(e);let m=1/0,y=-1/0;for(let e of b){let t=a[e];if(!t)continue;let n=t.bounds;m=Math.min(m,n.x-d.groupPaddingX),y=Math.max(y,n.x+n.width+d.groupPaddingX)}for(let t=e.startIndex;t<n.endMessageExclusive;t++){let e=r[t];e&&(m=Math.min(m,e.bounds.x-d.groupPaddingX),y=Math.max(y,e.bounds.x+e.bounds.width+d.groupPaddingX))}for(let e of n.noteIndices){let t=l[e];t&&(m=Math.min(m,t.x-d.groupPaddingX),y=Math.max(y,t.x+t.width+d.groupPaddingX))}for(let e of n.childBlockIndices){let t=s[e];t&&(m=Math.min(m,t.x-d.groupPaddingX),y=Math.max(y,t.x+t.width+d.groupPaddingX))}for(let n of("rect"!==e.type&&(y=Math.max(y,m+t.tabWidth+d.groupPaddingX)),t.dividers))n.label&&(y=Math.max(y,m+8+n.metrics.width+d.groupPaddingX));let k=f&&!f.isSelf&&f.labelPosition.text.includes(`
3
- `)?Math.ceil(Math.max(0,f.labelPosition.y-f.labelPosition.bounds.y-d.edgeLabelFontSize*er/2-1e-6)):0,w=n.noteIndices.length>0?t.contentTopPadding:t.blockPadTop,v=p?.top??(f?f.y-(t.blockPadTop+k):h-w),M=(x?.y??h)+d.groupPaddingY+12;for(let i=e.startIndex;i<n.endMessageExclusive;i++){let e=r[i];if(!e)continue;v=Math.min(v,e.bounds.y-Math.max(t.tabHeight,d.groupPaddingY));let n=e.isSelf?d.groupPaddingY+4:d.groupPaddingY;M=Math.max(M,e.bounds.y+e.bounds.height+n)}for(let o of b){let l=i.actors[o],s=a[o];if(!(!s||l?.createMessageIndex===void 0||!r[l.createMessageIndex])&&l.createMessageIndex>=e.startIndex&&l.createMessageIndex<n.endMessageExclusive){let e=t.contentTopPadding;v=Math.min(v,s.bounds.y-e),M=Math.max(M,s.bounds.y+s.bounds.height+d.groupPaddingY)}}for(let e of n.noteIndices){let n=l[e];if(!n)continue;let i=t.contentTopPadding;v=Math.min(v,n.y-i),M=Math.max(M,n.y+n.height+d.groupPaddingY)}for(let e of n.childBlockIndices){let n=s[e];n&&(v=Math.min(v,n.y-t.enclosingHeaderStep),M=Math.max(M,n.y+n.height+d.groupPaddingY))}let I=t.dividers.map((o,a)=>{let g=eJ(e,n,i,a),u=void 0===g?void 0:l[g],f=o.index<n.endMessageExclusive?r[o.index]:void 0;if("par_over"===e.type){if(!o.label)return{y:v+t.tabHeight,label:""};let e=u??f?.bounds;for(let[t,r]of n.childBlockIndices.entries()){let l=s[r];l&&n.childSectionIndices[t]===a+1&&i.blocks[r].startIndex===o.index&&(!e||l.y<e.y)&&(e=l)}let r=e?.x??m+8,l=e?e.y-o.metrics.height-8:v+t.tabHeight+8+a*(o.metrics.height+8),c=eR(o.displayLabel,r,l+o.metrics.height/2,"start",d.edgeLabelFontSize,d.edgeLabelFontWeight,d.edgeLetterSpacing,o.block);return y=Math.max(y,c.bounds.x+c.bounds.width+d.groupPaddingX),M=Math.max(M,c.bounds.y+c.bounds.height+d.groupPaddingY),{y:l,label:o.label,labelPosition:c}}let x=f?.y??h,b=28+o.extraLinesHeight+o.extraFontOffset;if(o.label&&f?.label){let e=m+8,t=e+o.metrics.width,n=f.labelPosition.bounds,i=n.x,a=n.x+n.width;if(t+8>i&&e-8<a){let e=Math.max(0,Math.ceil(x-10-(n.y+n.height/2)));b=Math.max(36+o.extraLinesHeight+o.extraFontOffset+e,Math.ceil(24+c+o.extraLinesHeight+o.extraFontOffset+e))}}let k=p?.dividerY[a],w=k??(u?u.y-o.noteContentOffset:x-b);for(let[e,t]of n.childBlockIndices.entries()){let r=s[t],l=i.blocks[t];if(void 0===k&&r&&l?.startIndex===o.index&&n.childSectionIndices[e]===a+1){let e=o.noteContentOffset;w=Math.min(w,r.y-e)}}if(!o.label)return{y:w,label:o.label};let I=w+o.firstLineOffset+(o.metrics.lines.length-1)/2*o.metrics.lineHeight,S=eR(o.displayLabel,m+8,I,"start",d.edgeLabelFontSize,d.edgeLabelFontWeight,d.edgeLetterSpacing,o.block);return M=Math.max(M,S.bounds.y+S.bounds.height+d.groupPaddingY),{y:w,label:o.label,labelPosition:{...S,text:o.displayLabel}}}),S="rect"===e.type?void 0:(g=v+t.tabHeight/2,u=eR(t.headerText,m+d.groupLabelPaddingX,g,"start",d.groupHeaderFontSize,d.groupHeaderFontWeight,d.groupLetterSpacing,t.block),{x:m,y:v,width:t.tabWidth,height:t.tabHeight,label:{...u,text:t.headerText}}),$={x:m,y:v,width:y-m,height:M-v};return{type:e.type,label:e.label,...e.color?{color:e.color}:{},x:$.x,y:$.y,width:$.width,height:$.height,dividers:I,...S?{header:S}:{},bounds:$}}function eK(e,t,n){for(let i of e.actors)i.x+=t,i.y+=n,i.bounds=eZ(i.bounds,t,n),i.labelPosition=eG(i.labelPosition,t,n);for(let i of e.messages)!function(e,t,n){e.x1+=t,e.x2+=t,e.y+=n,e.points=e.points.map(e=>({x:e.x+t,y:e.y+n})),e.labelPosition=eG(e.labelPosition,t,n),e.bounds=eZ(e.bounds,t,n)}(i,t,n);for(let i of e.blocks)for(let e of(i.x+=t,i.y+=n,i.bounds=eZ(i.bounds,t,n),i.header&&(i.header={...i.header,x:i.header.x+t,y:i.header.y+n,label:eG(i.header.label,t,n)}),i.dividers))e.y+=n,e.labelPosition&&(e.labelPosition=eG(e.labelPosition,t,n));for(let i of e.notes)i.x+=t,i.y+=n;for(let i of e.boxes)i.x+=t,i.y+=n,void 0!==i.labelY&&(i.labelY+=n);for(let i of e.activations)i.x+=t,i.topY+=n,i.bottomY+=n;for(let i of e.lifelines)i.x+=t,i.topY+=n,i.bottomY+=n;for(let i of e.destructions)i.x+=t,i.y+=n}var e0={nodeLabelFontSize:q.nodeLabel,edgeLabelFontSize:q.edgeLabel,groupHeaderFontSize:q.edgeLabel,nodeLabelFontWeight:F.nodeLabel,edgeLabelFontWeight:F.edgeLabel,groupHeaderFontWeight:F.groupHeader,nodePaddingX:16,nodePaddingY:6,nodeCornerRadius:4,nodeLineWidth:H.outerBox,edgeLineWidth:H.connector,groupCornerRadius:0,groupPaddingX:10,groupPaddingY:8,groupLabelPaddingX:6,groupLineWidth:H.outerBox};function e1(e,t={},n={},i){let o=Y(t,e0,i),a=n.diagramMarginX??30,r=n.diagramMarginY??30,l=n.width??80,s=n.noteMargin??10,d=n.activationWidth??10,c=e.actors.map(e=>eo(i,"actor",{category:e.id},{includeFallback:!1})),h=Math.max(n.height??40,...c.map(e=>el("Mg",e?.fontSize??o.nodeLabelFontSize,e?.fontWeight??o.nodeLabelFontWeight).height+(e?.paddingY??o.nodePaddingY)*2)),p=el("Mg",e0.edgeLabelFontSize,e0.edgeLabelFontWeight).height,g=el("Mg",o.edgeLabelFontSize,o.edgeLabelFontWeight).height,u=n.messageMargin??40,f=Math.max(u,u+g-p),x=Math.max(30,f-10),b=Math.max(40,40+(o.groupHeaderFontSize-e0.groupHeaderFontSize)+(o.groupPaddingY-e0.groupPaddingY)*2),m=Math.max(28,b+o.groupPaddingY+20-f);if(0===e.actors.length)return e2({width:0,height:0,accessibilityTitle:e.accessibilityTitle,accessibilityDescription:e.accessibilityDescription,actors:[],lifelines:[],messages:[],activations:[],blocks:[],notes:[],boxes:[],destructions:[]},void 0===e.title?void 0:X(e.title,e.titleContent),o,a,r);let y=e.actors.map((e,t)=>{var i,a;let r,s,d,p,g,u,f,x,b,m;return i=void 0===e.wrap&&void 0!==n.wrap?{...e,wrap:n.wrap}:e,a=c[t],r=a?.textTransform??o.nodeTextTransform,s=a?.fontSize??o.nodeLabelFontSize,d=a?.fontWeight??o.nodeLabelFontWeight,p=a?.letterSpacing??o.nodeLetterSpacing,g=a?.paddingX??o.nodePaddingX,u=a?.paddingY??o.nodePaddingY,x=(f=ee(X(i.label,i.labelContent),{transform:r,fontSize:s,fontWeight:d,letterSpacing:p,...i.wrap?{maxWidth:240}:{}})).text,b=Math.max(f.width+2*g,l),m="participant"===i.type?Math.max(h,Math.ceil(f.height+2*u)):h,{fontSize:s,fontWeight:d,letterSpacing:p,paddingX:g,paddingY:u,displayLabel:x,block:f,...i.links?{menuBlock:ee("⋯",{display:"literal",fontSize:10,fontWeight:400})}:{},labelMetrics:f,width:b,height:m}}),k=y.map(e=>e.width),w=new Map;for(let t=0;t<e.actors.length;t++)w.set(e.actors[t].id,t);let v=e.messages.map(e=>{var t;let i,a,r,l,s,c,h,p,g,u,f,x,b,m,y;return s=(l=ee((r=Object.freeze({value:a=void 0!==(t=void 0===e.wrap&&void 0!==n.wrap?{...e,wrap:n.wrap}:e).number?`${t.number}. ${t.label}`:t.label,prepared:R((i=X(t.label,t.labelContent),void 0!==t.number?D([`${t.number}. `,"string"==typeof i?R(i):i]):i))})).prepared,{transform:o.edgeTextTransform,fontSize:o.edgeLabelFontSize,fontWeight:o.edgeLabelFontWeight,letterSpacing:o.edgeLetterSpacing,...t.wrap?{maxWidth:240}:{}})).text,c=o.edgeLabelFontSize*er,h=a?l:{width:0,height:0,lines:[],lineHeight:c},p=Math.max("none"!==t.startHead?E.width:0,5*!!t.centralStart),g=Math.max("none"!==t.endHead?E.width:0,5*!!t.centralEnd),u=Math.max(o.lineWidth/2,"none"!==t.startHead||"none"!==t.endHead?E.height/2:0,t.centralStart||t.centralEnd?4.75:0),f=Math.max(16,p+g+8),x=h.width+f,m=(b=30+(h.width>0?8+h.width:0))+Math.max(12,d/2+8),y=t.from===t.to?0:Math.ceil(Math.max(0,h.height-c)),{label:a,labelContent:r,displayLabel:s,block:l,labelMetrics:h,startPad:p,endPad:g,markerHalfHeight:u,requiredSpanWidth:x,selfRightExtent:b,requiredSelfNeighborGap:m,extraAboveHeight:y}}),M=Array.from({length:Math.max(0,e.actors.length-1)},()=>0);for(let t=0;t<e.messages.length;t++){let n=e.messages[t],i=v[t],o=w.get(n.from),a=w.get(n.to);if(void 0===o||void 0===a)continue;if(o===a){o<e.actors.length-1&&(M[o]=Math.max(M[o],i.requiredSelfNeighborGap));continue}let r=Math.min(o,a),l=Math.max(o,a),s=l-r,d=e.actors[a].createMessageIndex===t&&"participant"===e.actors[a].type?k[a]/2:0,c=(i.requiredSpanWidth+d)/s;for(let e=r;e<l;e++)M[e]=Math.max(M[e],c)}let I=[],S=a+k[0]/2;for(let t=0;t<e.actors.length;t++){if(t>0){let e=(k[t-1]+k[t])/2;S+=Math.max(void 0!==n.actorMargin?e+n.actorMargin:Math.max(140,e+40),M[t-1]??0)}I.push(S)}let $=(e.boxes??[]).flatMap((t,i)=>{let a=e.actors.flatMap((e,t)=>e.box===i?[t]:[]),r=t.label?ee(X(t.label,t.labelContent),{transform:o.groupTextTransform,fontSize:o.groupHeaderFontSize,fontWeight:o.groupHeaderFontWeight,letterSpacing:o.groupLetterSpacing,fontFamily:o.groupFont,...t.wrap??n.wrap?{maxWidth:240}:{}}):void 0;return a.length>0?[{box:t,memberIdxs:a,block:r}]:[]}),L=Math.max(22,...$.map(e=>(e.block?.height??0)+8)),C=r+($.length>0?L+6:0),W=e.actors.map((e,t)=>eV(e,y[t],I[t],C)),P=e.actors.flatMap((t,n)=>{if(void 0!==t.createMessageIndex&&t.createMessageIndex<e.messages.length)return[];let i=W[n].bounds;return[i.y+i.height]}),q=P.length>0?Math.max(...P):C+h,F=q+26,H=[],z=e.blocks.map((t,n)=>{let i=eE.get(t);if(i)return i;let o=[];for(let n=0;n<e.notes.length;n++){let i=e.notes[n];i.afterIndex>=t.startIndex&&i.afterIndex<=t.endIndex&&o.push(n)}let a=[];for(let i=0;i<n;i++){let o=e.blocks[i];o.startIndex>=t.startIndex&&o.endIndex<=t.endIndex&&(e.blocks.some((e,a)=>a>i&&a<n&&o.startIndex>=e.startIndex&&o.endIndex<=e.endIndex&&e.startIndex>=t.startIndex&&e.endIndex<=t.endIndex)||a.push(i))}return{endMessageExclusive:Math.min(t.endIndex+1,e.messages.length),dividerNoteIndices:t.dividers.map(()=>-1),endNoteExclusive:o.length>0?o.at(-1)+1:e.notes.filter(e=>e.afterIndex<=t.endIndex).length,noteIndices:o,childBlockIndices:a,childSectionIndices:a.map(n=>t.dividers.filter(t=>e.blocks[n].startIndex>=t.index).length)}}),B=e.blocks.map(e=>{var t;let i,a,r,l,s,d,c,h,p,u,f;return a=(i=ee("rect"===(t={...e,wrap:e.wrap??n.wrap,dividers:e.dividers.map(e=>({...e,wrap:e.wrap??n.wrap}))}).type?"":t.label?D([`${t.type} [`,R(X(t.label,t.labelContent)),"]"]):t.type,{transform:o.groupTextTransform,fontSize:o.groupHeaderFontSize,fontWeight:o.groupHeaderFontWeight,letterSpacing:o.groupLetterSpacing,fontFamily:o.groupFont,...t.wrap?{maxWidth:240}:{}})).text,r=o.groupHeaderFontSize*er,s=Math.ceil(Math.max(0,((l=a?i:{width:0,height:0,lines:[],lineHeight:r}).lines.length-1)*l.lineHeight)),d=Math.max(2*o.groupPaddingX,2*o.groupLabelPaddingX),c="rect"===t.type?0:l.width+d,h="rect"===t.type?0:Math.max(18,o.groupHeaderFontSize+o.groupPaddingY)+s,p=b+s,u="rect"===t.type?o.groupPaddingY:h+o.groupPaddingY,f=t.dividers.map(e=>{let t=ee(e.label?D(["[",R(X(e.label,e.labelContent)),"]"]):"",{transform:o.edgeTextTransform,fontSize:o.edgeLabelFontSize,fontWeight:o.edgeLabelFontWeight,letterSpacing:o.edgeLetterSpacing,...e.wrap?{maxWidth:240}:{}}),n=t.text,i=e.label?t:{width:0,height:0,lines:[],lineHeight:g},a=Math.max(14,Math.ceil(i.lineHeight/2+6)),r=Math.max(0,a-14),l=Math.ceil(Math.max(0,(i.lines.length-1)*i.lineHeight));return{index:e.index,label:e.label,displayLabel:n,block:t,metrics:i,firstLineOffset:a,extraFontOffset:r,extraLinesHeight:l,requiredExtraBefore:24+l+r,noteContentOffset:Math.ceil(Math.max(28+l+r,a+(i.lines.length-1)/2*i.lineHeight+i.height/2+o.groupPaddingY))}}),{headerText:a,block:i,headerMetrics:l,tabWidth:c,tabHeight:h,extraHeaderLinesHeight:s,blockPadTop:p,blockHeaderExtra:m+s,enclosingHeaderStep:u,contentTopPadding:"rect"===t.type?o.groupPaddingY:Math.max(p,h+o.groupPaddingY),dividers:f}}),T=ez.get(e),_=new Map,N=new Map,O=new Map,j=new Map,A=new Map;for(let t=0;t<e.blocks.length;t++){let n=e.blocks[t],i=N.get(n.startIndex)??[];i.push(t),N.set(n.startIndex,i);let o=z[t],a=o.noteIndices[0];if(void 0!==a){let e=O.get(a)??[];e.push(t),O.set(a,e)}for(let e of o.childBlockIndices)j.set(e,t)}let U=new Set,Z=new Set;if(T){let t=new Map(T.filter(e=>"open"===e.kind).map(e=>[e.blockIndex,e.noteIndex]));for(let n=0;n<e.blocks.length;n++){let i=e.blocks[n],o=z[n],a=new Set(o.childSectionIndices),r=i.startIndex,l=t.get(n);for(let e=0;e<=i.dividers.length;e++){let t=i.dividers[e]?.index??o.endMessageExclusive,s=o.dividerNoteIndices[e]??o.endNoteExclusive;r!==t||l!==s||a.has(e)||Z.add(n),r=t,l=s}o.childBlockIndices.some(t=>e.blocks[t].startIndex===z[t].endMessageExclusive&&0===z[t].noteIndices.length)&&Z.add(n)}for(let t=0;t<e.blocks.length;t++){let e=j.get(t);Z.has(t)&&void 0!==e&&Z.add(e)}}let G=e=>(N.get(e)??[]).filter(t=>!U.has(t)&&z[t].endMessageExclusive>e),V=e=>0===e.length?0:B[e[0]].blockHeaderExtra+e.slice(1).reduce((e,t)=>e+B[t].enclosingHeaderStep,0);for(let t=0;t<e.blocks.length;t++){if(Z.has(t)||"par_over"===e.blocks[t].type)continue;let n=B[t],i=z[t];for(let[o,a]of n.dividers.entries()){let n=eJ(e.blocks[t],i,e,o);if(void 0!==n){A.set(n,Math.max(A.get(n)??0,a.noteContentOffset));continue}if(a.index>=i.endMessageExclusive)continue;let r=a.requiredExtraBefore;for(let t of i.childBlockIndices)e.blocks[t]?.startIndex===a.index&&(r+=B[t].blockHeaderExtra);let l=_.get(a.index)??0;_.set(a.index,Math.max(l,r))}}let J=new Map,Q=new Map,K=new Map;for(let t=0;t<e.actors.length;t++){let n=e.actors[t];if(void 0!==n.createMessageIndex&&n.createMessageIndex<e.messages.length){let e=J.get(n.createMessageIndex)??[];e.push(t),J.set(n.createMessageIndex,e)}if(void 0!==n.destroyMessageIndex&&n.destroyMessageIndex<e.messages.length){let e=Q.get(n.destroyMessageIndex)??[];e.push(n.id),Q.set(n.destroyMessageIndex,e)}}let et=new Map;for(let t=0;t<e.notes.length;t++){let n=e.notes[t],i=et.get(n.afterIndex)??[];i.push({note:n,index:t}),et.set(n.afterIndex,i)}let en=Array(e.notes.length),ei=new Map,ea=[],es=new Map;for(let t of e.activationEvents??[]){let e=es.get(t.messageIndex)??[];e.push(t),es.set(t.messageIndex,e)}let ed=(e,t)=>{let n=ei.get(e)??[];n.push({startY:t,depth:n.length}),ei.set(e,n)},ec=(e,t)=>{let n=ei.get(e);if(!n||0===n.length)return;let{startY:i,depth:o}=n.pop(),a=w.get(e);void 0===a||t<=i||ea.push({actorId:e,x:I[a]-d/2+4*o,topY:i,bottomY:t,width:d})},eh=(e,t)=>{for(let n of es.get(e)??[])"activate"===n.kind?ed(n.actorId,t):ec(n.actorId,t)},ep=(e,t)=>{let i=ee(X(e.text,e.textContent),{transform:o.nodeTextTransform,fontSize:o.nodeLabelFontSize,fontWeight:o.nodeLabelFontWeight,letterSpacing:o.nodeLetterSpacing,...e.wrap??n.wrap?{maxWidth:240}:{}}),a=Math.max(60,i.width+2*o.nodePaddingX),r=i.height+2*o.nodePaddingY,l=w.get(e.actorIds[0]??"")??0,d;if("left"===e.position)d=I[l]-k[l]/2-a-s;else if("right"===e.position)d=I[l]+k[l]/2+s;else if(e.actorIds.length>1){let t=w.get(e.actorIds[e.actorIds.length-1]??"")??l;d=(I[l]+I[t])/2-a/2}else d=I[l]-a/2;return{text:e.text,block:i,x:d,y:t,width:a,height:r,position:e.position,actors:e.actorIds}},eg=Array(e.blocks.length),eu=[],ef=-1/0,ex=q,eb=-1/0,em=0,ey=0,ek=0,ew=0,ev=new Map,eM=(t,n,i)=>{let o=0,a=[];for(let[o,r]of ev){let l=e.blocks[o];for(let e=l.startIndex;e<r.messageEnd;e++)H[e]&&a.push(H[e].bounds);for(let e of z[o].noteIndices)e<r.noteEnd&&en[e]&&a.push(en[e]);for(let e of r.priorChildren)eg[e]&&a.push(eg[e]);for(let[s,d]of l.dividers.entries()){let c=B[o].dividers[s];if(!d.label)continue;let h=eJ(l,z[o],e,s),p=void 0!==h&&h<r.noteEnd?en[h]:void 0===h&&d.index<r.messageEnd?H[d.index]?.bounds:void 0;if(p&&a.push({x:p.x,y:p.y-c.metrics.height-8,width:c.metrics.width,height:c.metrics.height}),void 0===h&&n===d.index||void 0!==h&&i===h){let e=c.metrics.height+8;t={x:t.x,y:t.y-e,width:Math.max(t.width,c.metrics.width),height:t.height+e}}}}for(let e=0;e<=a.length;e++){let e=a.find(e=>t.x<e.x+e.width+8&&t.x+t.width+8>e.x&&t.y+o<e.y+e.height+8&&t.y+t.height+o+8>e.y);if(!e)break;o=e.y+e.height+8-t.y}return o},eI=e=>{let t=[];for(let n=e;void 0!==n&&!U.has(n);n=j.get(n))t.push(n);for(let e=t.length-1;e>=0;e--){let n=t[e],i=Math.max(ex,ef,eb)+8;eu[n]={top:i,dividerY:[]},U.add(n),ex=eb=i+B[n].enclosingHeaderStep}},eS=t=>{let n=e.blocks[t],i=z[t],a=eu[t]?.top,r=void 0!==a&&n.startIndex===i.endMessageExclusive&&0===i.noteIndices.length?a+B[t].blockPadTop:en[i.noteIndices[0]??-1]?.y??F;U.add(t);let l=eQ(n,B[t],i,e,w,W,H,en,eg,o,g,r,eu[t]);eg[t]=l,ef=Math.max(ef,l.y+l.height);let s=ev.get(t);s&&(ex=Math.max(ex,s.bottom,ef),F=Math.max(F,ex+f/2),ev.delete(t))},e$=()=>{if(T){for(;ek<T.length;){let t=T[ek];if(t.messageIndex>H.length||t.noteIndex>em)break;let n=t.blockIndex;if("open"===t.kind&&Z.has(n)&&eI(n),"open"===t.kind&&"par_over"===e.blocks[n].type){eI(n);let i=Math.max(0,...B[n].dividers.map(e=>e.noteContentOffset));eb+=i,ex=eb,F=Math.max(F,eb+f/2),ev.set(n,{messageY:F,contentBottom:ex,completedBottom:ef,reservedBottom:eb,bottom:ex,messageEnd:e.blocks[n].startIndex,noteEnd:t.noteIndex,priorChildren:[]}),ew++}if("divider"===t.kind){let e=ev.get(n);if(e){e.bottom=Math.max(e.bottom,ex,ef,eb),e.messageEnd=t.messageIndex,e.noteEnd=t.noteIndex,e.priorChildren=z[n].childBlockIndices.filter(e=>eg[e]),({messageY:F,contentBottom:ex,completedBottom:ef,reservedBottom:eb}=e),ew++,ek++;continue}let i=B[n].dividers[t.dividerIndex],o=Math.max(ex,ef,eb)+8;Z.has(n)?(eu[n].dividerY[t.dividerIndex]=o,ex=eb=o+i.noteContentOffset):eb=o+i.noteContentOffset}"close"===t.kind&&eS(n),ek++}return}for(;ey<e.blocks.length;){let e=ey,t=z[e];if(t.endMessageExclusive>H.length||t.endNoteExclusive>em)break;eS(e),ey++}},eL=(e,t)=>{let n=t;for(let{note:t,index:i}of et.get(e)??[]){let e=ew;for(let t of(e$(),e!==ew&&(n=F),n=Math.max(n,ef+8,eb),O.get(i)??[])){let e=eu[t]?.top;void 0!==e&&(n=Math.max(n,e+B[t].contentTopPadding))}let o=(O.get(i)??[]).filter(e=>!U.has(e)),a=A.get(i)??0;if(o.length>0||a>0){let e=a+(o.length>0?B[o[0]].contentTopPadding+o.slice(1).reduce((e,t)=>e+B[t].enclosingHeaderStep,0):0);for(let t of(n=Math.max(n,Math.max(ex,ef)+8+e),o))U.add(t)}let r=ep(t,n),l=eM(r,void 0,i);l>0&&(n+=l,r=ep(t,n)),en[i]=r,ex=Math.max(ex,r.y+r.height),em=i+1,n=r.y+r.height+4}et.has(e)&&(F=Math.max(F,n+f/2))};eL(-1,F);for(let t=0;t<e.messages.length;t++){let n=e.messages[t],i=v[t],a=w.get(n.from)??0,r=w.get(n.to)??0,l=n.from===n.to;e$();let s=G(t),d=Math.max(_.get(t)??0,V(s));for(let e of J.get(t)??[]){let t=W[e].height/2;d=d>0?d+Math.max(0,t-12):t+8}F+=d+i.extraAboveHeight;let c=I[a],h=I[r],p=e.actors[r].createMessageIndex!==t||"participant"!==e.actors[r].type||l?h:h-Math.sign(h-c)*k[r]/2,u=()=>{let a=function(e,t,n,i,o,a){let r=e.from===e.to;if(r){let l=a+Math.max(20,t.labelMetrics.height)/2,s=eR(t.displayLabel,i+30+8,l,"start",n.edgeLabelFontSize,n.edgeLabelFontWeight,n.edgeLetterSpacing,t.block),d={x:i-t.startPad,y:a-t.markerHalfHeight,width:30+t.startPad+n.lineWidth/2,height:20+2*t.markerHalfHeight},c=t.label?eU(d,s.bounds):d;return{from:e.from,to:e.to,label:t.label,labelContent:t.labelContent,lineStyle:e.lineStyle,startHead:e.startHead,endHead:e.endHead,centralStart:e.centralStart??!1,centralEnd:e.centralEnd??!1,x1:i,x2:o,y:a,isSelf:r,points:[{x:i,y:a},{x:i+30,y:a},{x:i+30,y:a+20},{x:o,y:a+20}],labelPosition:s,bounds:c}}let l=Math.max(2.85,n.lineWidth/2+2),s=Math.max(10,t.labelMetrics.height/2+l),d=eR(t.displayLabel,(i+o)/2,a-s,"middle",n.edgeLabelFontSize,n.edgeLabelFontWeight,n.edgeLetterSpacing,t.block),c=i<=o?t.startPad:t.endPad,h=i<=o?t.endPad:t.startPad,p=Math.min(i,o)-c,g=Math.max(i,o)+h,u={x:p,y:a-t.markerHalfHeight,width:g-p,height:2*t.markerHalfHeight},f=t.label?eU(u,d.bounds):u;return{from:e.from,to:e.to,label:t.label,labelContent:t.labelContent,lineStyle:e.lineStyle,startHead:e.startHead,endHead:e.endHead,centralStart:e.centralStart??!1,centralEnd:e.centralEnd??!1,x1:i,x2:o,y:a,isSelf:r,points:[{x:i,y:a},{x:o,y:a}],labelPosition:d,bounds:f}}(n,i,o,c,p,F);for(let n of(H[t]=a,J.get(t)??[]))W[n]=eV(e.actors[n],y[n],I[n],F-W[n].height/2);return a},b=u(),m=b.bounds.y,M=0,S=new Set(s),$=(N.get(t)??[]).filter(e=>S.has(e)||eu[e]?.top!==void 0&&!eg[e]);if($.length>0){let t=[];for(let n of $){for(let e of z[n].childBlockIndices)eg[e]&&(t[e]=eg[e]);t[n]=eQ(e.blocks[n],B[n],z[n],e,w,W,H,en,t,o,g,F,eu[n]);let i=eu[n]?.top;void 0!==i?M=Math.max(M,i-t[n].y):m=Math.min(m,t[n].y)}}let L=Math.max(0,M,(s.length>0?Math.max(ex,ef,eb):Math.max(ef,eb))+8*(s.length>0)-m);L>0&&(F+=L,b=u());let C=eM(b.bounds,t);for(let e of(C>0&&(F+=C,b=u()),s))U.add(e);ex=Math.max(ex,b.bounds.y+b.bounds.height,...(J.get(t)??[]).map(e=>W[e].bounds.y+W[e].bounds.height)),eh(t,F);let P=Q.get(t);if(P)for(let e of P)K.set(e,F);n.activate&&ed(n.to,F),n.deactivate&&ec(n.from,F);let q=l?Math.max(x,Math.ceil(i.labelMetrics.height)+10):0;F+=l?q+f:f;let E=J.get(t);if(E){let e=Math.max(...E.map(e=>{let t=W[e];return t.bounds.height-t.height/2}));F+=e}let Y=E?ex+8:b.y+q+14;eL(t,Y)}e$();let eC=Math.max(H[H.length-1]?.y??F,F-f/2);for(let[t,n]of(eh(e.messages.length,eC),ei))for(;n.length>0;)ec(t,eC);for(let t of W)e.actors[w.get(t.id)]?.external&&(t.external=!0);for(let[t,n]of H.entries()){let i=e.messages[t];void 0!==i.id&&(n.id=i.id),void 0!==i.parentId&&(n.parentId=i.parentId)}for(let[t,n]of eg.entries()){let i=e.blocks[t];void 0!==i.id&&(n.id=i.id),void 0!==i.parentId&&(n.parentId=i.parentId)}for(let[t,n]of en.entries()){let i=e.notes[t];n&&i?.id!==void 0&&(n.id=i.id),n&&i?.parentId!==void 0&&(n.parentId=i.parentId)}let eW=en.filter(e=>void 0!==e),eP=eg.reduce((e,t)=>Math.max(e,t.y+t.height),0);eP>0&&(F=Math.max(F,eP+8));let eq=F,eF=$.map(({box:e,memberIdxs:t,block:n})=>{let i=Math.min(...t.map(e=>W[e].bounds.x))-8,o=Math.max(...t.map(e=>W[e].bounds.x+W[e].bounds.width))+8;return e.label&&(o=Math.max(o,i+n.width+16)),{label:e.label,block:n,labelY:r+L/2,color:e.color,x:i,y:r,width:o-i,height:eq+8-r}}),eH=F+r,eY=a,eB=0;for(let e of W){let t=e.bounds;eY=Math.min(eY,t.x),eB=Math.max(eB,t.x+t.width)}for(let e of eg)eY=Math.min(eY,e.x),eB=Math.max(eB,e.x+e.width);for(let e of eW)eY=Math.min(eY,e.x),eB=Math.max(eB,e.x+e.width);for(let e of eF)eY=Math.min(eY,e.x),eB=Math.max(eB,e.x+e.width);for(let e of ea)eY=Math.min(eY,e.x),eB=Math.max(eB,e.x+e.width);for(let e of H){eY=Math.min(eY,e.bounds.x);let t=e.isSelf&&e.label?8:0;eB=Math.max(eB,e.bounds.x+e.bounds.width+t)}let eT=eY<a?a-eY:0;if(eT>0){eK({actors:W,messages:H,blocks:eg,notes:eW,boxes:eF,activations:ea,lifelines:[],destructions:[]},eT,0);for(let e=0;e<I.length;e++)I[e]+=eT}let e_=e.actors.map((e,t)=>{let n=W[t],i=n.bounds.y+n.bounds.height;return{actorId:e.id,x:I[t],topY:i,bottomY:K.get(e.id)??eH-r}}),eN=e.actors.filter(e=>K.has(e.id)).map(e=>({actorId:e.id,x:I[w.get(e.id)],y:K.get(e.id)}));return e2({width:Math.max(eB+eT+a,200),height:Math.max(eH,100),accessibilityTitle:e.accessibilityTitle,accessibilityDescription:e.accessibilityDescription,actors:W,lifelines:e_,messages:H,activations:ea,blocks:eg,notes:eW,boxes:eF,destructions:eN},void 0===e.title?void 0:X(e.title,e.titleContent),o,a,r)}function e2(e,t,n,i,o){let a=B(t,n);if(!a)return e;if(0===e.width&&0===e.height)return{...e,...T(a,i,o)};let r=a.height;eK(e,0,r);let l=Math.max(e.width,a.width+2*i);return{...e,width:l,height:e.height+r,title:_(a,l,o)}}function e3(e,t){let n,i,o,a,r,{positioned:l,colors:s,resolved:d}=t,c=d.renderOptions,h=s.font??"Inter",p=c.transparent??!1,g=[],u=Y(c,e0,d.styleFace),f=`seq-${K(l.width,l.height,l.actors.length,l.messages.length)}`,x=`${f}-title`,b=`${f}-desc`,m=W(l.accessibilityTitle,l.accessibilityDescription,x,b);g.push(e.documentOpen({id:"prelude",width:l.width,height:l.height,colors:s,transparent:p,font:h,hasMonoFont:!1},L(l.width,l.height,s,p,m)+`
4
- `+$(h,!1,s.shadow,s.embedFontImport)));let w=[];w.push("<defs>");let v=(n=E.width,i=E.height,o=u.edgeStrokeColor??"var(--_arrow)",a={size:{width:n,height:i},orient:"auto-start-reverse"},r=[{x:0,y:0},{x:n,y:i/2},{x:0,y:i}],[{...a,id:"seq-arrow",shape:"arrow",ref:{x:n,y:i/2},geometry:{kind:"polygon",points:r},paint:{fill:o}},{...a,id:"seq-arrow-open",shape:"open-arrow",ref:{x:n,y:i/2},geometry:{kind:"polyline",points:r},paint:{fill:"none",stroke:o,strokeWidth:"1"}},{...a,id:"seq-arrow-cross",shape:"cross",ref:{x:n/2,y:i/2},orient:"auto",geometry:{kind:"path",d:`M1 1 L${n-1} ${i-1} M1 ${i-1} L${n-1} 1`},paint:{fill:"none",stroke:o,strokeWidth:"1.5"}},{...a,id:"seq-arrow-half-top",shape:"arrow",ref:{x:n,y:i/2},geometry:{kind:"polygon",points:[{x:0,y:0},{x:n,y:i/2},{x:0,y:i/2}]},paint:{fill:o}},{...a,id:"seq-arrow-half-bottom",shape:"arrow",ref:{x:n,y:i/2},geometry:{kind:"polygon",points:[{x:0,y:i/2},{x:n,y:i/2},{x:0,y:i}]},paint:{fill:o}},{...a,id:"seq-arrow-stick-top",shape:"open-arrow",ref:{x:n,y:i/2},geometry:{kind:"path",d:`M0 0 L${n} ${i/2}`},paint:{fill:"none",stroke:o,strokeWidth:"1.5"}},{...a,id:"seq-arrow-stick-bottom",shape:"open-arrow",ref:{x:n,y:i/2},geometry:{kind:"path",d:`M0 ${i} L${n} ${i/2}`},paint:{fill:"none",stroke:o,strokeWidth:"1.5"}}]);w.push(P(v));let M=S(s);M&&w.push(M),w.push("</defs>"),g.push(e.definitions({id:"defs",markerResources:v},w.join(`
5
- `))),l.accessibilityTitle&&g.push(e.documentContent({id:"a11y-title",role:"chrome",nonPaint:"accessibility"},`<title id="${x}">${Z(l.accessibilityTitle)}</title>`)),l.accessibilityDescription&&g.push(e.documentContent({id:"a11y-desc",role:"chrome",nonPaint:"accessibility"},`<desc id="${b}">${Z(l.accessibilityDescription)}</desc>`));let I=l.blocks.some(e=>"rect"===e.type),q=I?[...l.blocks].reverse().sort((e,t)=>t.width*t.height-e.width*e.height):l.blocks,F=function(e,t,n,i){let o=(e,t,n)=>t>=e.x&&t<=e.x+e.width&&n>=e.y&&n<=e.y+e.height,a=e.flatMap(e=>{let t=e.color&&"transparent"!==e.color.toLowerCase()?ek(e.color):void 0;return t?[{x:e.x,y:e.y,width:e.width,height:e.height,hex:t,authored:!0}]:[]}),r=C("var(--bg)",i)??"#ffffff";for(let e of t){let t=e6(e,n),l=void 0===t?void 0:C(t,i)??t,s=void 0===l?null:es(l);if(!s||0===s[3])continue;let d=e.x+e.width/2,c=e.y+e.height/2,h=O(l,a.findLast(e=>o(e,d,c))?.hex??r);h&&a.push({x:e.x,y:e.y,width:e.width,height:e.height,hex:ei(...h),authored:"rect"===e.type})}return(e,t)=>{let n=a.findLastIndex(t=>o(t,e.x,e.y)),r=a[n],l=void 0!==r&&!(o(r,e.x-e.width/2,e.y-e.height/2)&&o(r,e.x+e.width/2,e.y+e.height/2))||a.some((t,i)=>i>n&&t.hex!==r?.hex&&e.x-e.width/2<t.x+t.width&&e.x+e.width/2>t.x&&e.y-e.height/2<t.y+t.height&&e.y+e.height/2>t.y);if(!r)return l?{ink:t,halo:"var(--bg)"}:{ink:t};let s=C(t,i),d=s?ea(s,r.hex):y(r.hex)??t;return r.authored||l?{ink:d,halo:r.hex}:{ink:d}}}(l.boxes,q,u,s);l.title&&g.push(e.text(N(l.title,u)));let B=new Map;for(let t of l.boxes){let n=t.label??"",i=B.get(n)??0;B.set(n,i+1),g.push(function(e,t,n,i){let o=[],a=`<g class="box"${t.label?` data-label="${V(t.label)}"`:""}>`,r=t.color?.toLowerCase()==="transparent"?"none":t.color,l=r??"color-mix(in srgb, var(--fg) 5%, var(--bg))";if(o.push({indent:2,node:e.shape({id:`${i}:rect`,role:"group",geometry:{kind:"rect",x:t.x,y:t.y,width:t.width,height:t.height,rx:n.groupCornerRadius,ry:n.groupCornerRadius},paint:{fill:l,stroke:"none"}})}),t.label){let a=t.block?.text??z(t.label,n.groupTextTransform),l=function(e,t){let n=t.groupTextColor??"var(--_text-sec)";if(!e||"none"===e)return n;let i=ek(e);if(!i)return n;let o=t.groupTextColor;if(o){let e=j(o,i);if(null!==e&&e>=4.5)return o}return y(i)??n}(r,n),s=t.x+t.width/2,d=t.labelY??t.y+13;o.push({indent:2,node:e.text({id:`${i}:title`,role:"label",text:a,block:t.block,x:s,y:d,fontSize:n.groupHeaderFontSize,fontWeight:n.groupHeaderFontWeight,letterSpacing:n.groupLetterSpacing,anchor:"middle",paint:{fill:l}})})}return e.group({id:i,role:"group",open:a,close:"</g>",children:o})}(e,t,u,`box:${n}#${i}`))}let T=new Map,_=new Map;for(let e of l.blocks){let t=T.get(e.type)??0;T.set(e.type,t+1),_.set(e,e.id??`block:${e.type}#${t}`)}for(let t of q)g.push(e9(e,t,u,_.get(t),I?"background":"all"));if(I){for(let t of q)"rect"!==t.type&&g.push(e9(e,t,u,_.get(t),"frame"));for(let t of l.blocks)t.dividers.length>0&&g.push(e9(e,t,u,_.get(t),"dividers"))}let X=function(e){let t=new Map,n=[];for(let i of e){let e=`${i.from}->${i.to}`,o=t.get(e)??0;if(t.set(e,o+1),!i.labelPosition.text.trim())continue;let a=i.labelPosition.bounds;n.push({key:`${e}#${o}`,x:a.x-2,y:a.y-2,width:a.width+4,height:a.height+4})}let i=e=>{let t="x"===e?"width":"height",i=[...n].sort((t,n)=>t[e]-n[e]),o=(n,a)=>{if(n>=a)return;let r=n+a>>>1,l=i[r],s=o(n,r),d=o(r+1,a);return{area:l,left:s,right:d,end:Math.max(l[e]+l[t],s?.end??-1/0,d?.end??-1/0)}},a=o(0,i.length);return n=>{let i=[],o=a=>{if(!a||a.end<n[e])return;o(a.left);let r=a.area;r[e]>n[e]+n[t]||(r.x<=n.x+n.width&&r.x+r.width>=n.x&&r.y<=n.y+n.height&&r.y+r.height>=n.y&&i.push(r),o(a.right))};return o(a),i}},o=i("x"),a=i("y");return(e,t)=>{let n=("x"===t?o:a)(e).sort((e,t)=>e.y-t.y),i=[],r=e.y+e.height,l=e.y,s;for(let t of n){let n=Math.max(e.y,t.y);n>l&&i.push({top:l,bottom:n,after:s});let o=Math.min(r,t.y+t.height);o>l&&(l=o,s=t.key)}return l<r&&i.push({top:l,bottom:r,after:s}),i}}(l.messages),A=new Set(l.actors.filter(e=>e.external).map(e=>e.id));for(let t of l.lifelines){if(A.has(t.actorId))continue;let n=Math.max(.75,.75*u.lineWidth);g.push(function(e,t,n,i){let o=n.edgeStrokeColor??"var(--_line)",a=Math.max(.75,.75*n.lineWidth),r=`lifeline:${t.actorId}`;return 1!==i.length||i[0].top!==t.topY||i[0].bottom!==t.bottomY?e.group({id:r,role:"lifeline",open:`<g class="lifeline" data-actor="${G(t.actorId)}">`,close:"</g>",children:i.map(n=>{let i=(n.top-t.topY)%10;return{indent:2,node:e.connector({id:n.after?Q(r,"after",n.after):Q(r,"start"),role:"lifeline",geometry:{kind:"line",x1:t.x,y1:n.top,x2:t.x,y2:n.bottom},lineStyle:"dashed",paint:{stroke:o,strokeWidth:String(a),strokeDasharray:"6 4",strokeDashoffset:String(i)}})}})}):e.connector({id:r,role:"lifeline",geometry:{kind:"line",x1:t.x,y1:t.topY,x2:t.x,y2:t.bottomY},lineStyle:"dashed",paint:{stroke:o,strokeWidth:String(a),strokeDasharray:"6 4"},attributes:{className:"lifeline",data:{actor:t.actorId}}})}(e,t,u,X({x:t.x-n/2,y:t.topY,width:n,height:t.bottomY-t.topY},"x")))}let D=new Map;for(let t of l.activations){let n=D.get(t.actorId)??0;D.set(t.actorId,n+1),g.push(function(e,t,n,i,o){let a=n.nodeFillColor??"var(--_node-fill)",r=n.nodeBorderColor??"var(--_node-stroke)";if(1!==o.length||o[0].top!==t.topY||o[0].bottom!==t.bottomY){let n=[],l=[],s=[];for(let e of o)for(let n of(l.push(`M ${t.x} ${e.top} h ${t.width} V ${e.bottom} h ${-t.width} Z`),[{x1:t.x,y1:e.top,x2:t.x,y2:e.bottom},{x1:t.x+t.width,y1:e.top,x2:t.x+t.width,y2:e.bottom},...e.top===t.topY?[{x1:t.x,y1:e.top,x2:t.x+t.width,y2:e.top}]:[],...e.bottom===t.bottomY?[{x1:t.x,y1:e.bottom,x2:t.x+t.width,y2:e.bottom}]:[]]))s.push(`M ${n.x1} ${n.y1} L ${n.x2} ${n.y2}`);if(l.length){let t=l.join(" "),o=s.join(" ");n.push({indent:2,node:e.shape({id:Q(i,"fill"),role:"activation",surfaceFragment:!0,geometry:{kind:"path",d:t},paint:{fill:a,stroke:"none"}})}),n.push({indent:2,node:e.shape({id:Q(i,"border"),role:"activation",geometry:{kind:"path",d:o},paint:{fill:"none",stroke:r,strokeWidth:String(H.innerBox)}})})}return e.group({id:i,role:"activation",open:`<g class="activation" data-actor="${G(t.actorId)}">`,close:"</g>",children:n})}return e.shape({id:i,role:"activation",geometry:{kind:"rect",x:t.x,y:t.topY,width:t.width,height:t.bottomY-t.topY},paint:{fill:a,stroke:r,strokeWidth:String(H.innerBox)},attributes:{className:"activation",data:{actor:t.actorId}}})}(e,t,u,`activation:${t.actorId}#${n}`,X({x:t.x-H.innerBox/2,y:t.topY,width:t.width+H.innerBox,height:t.bottomY-t.topY},"y")))}let R=new Map;for(let t of l.blocks){let n=R.get(t.type)??0;R.set(t.type,n+1),"rect"!==t.type&&t.header&&g.push(function(e,t,n,i){let{x:o,y:a,width:r,height:l,label:s}=t,{text:d,x:c,y:h}=s,p=n.groupHeaderFillColor??"var(--_group-hdr)",g=n.groupBorderColor??"var(--_node-stroke)",u=n.groupTextColor??"var(--_text-sec)";return e.group({id:`${i}:header-overlay`,role:"block",open:'<g class="sequence-block-header-overlay" pointer-events="none" aria-hidden="true">',close:"</g>",children:[{indent:0,node:e.shape({id:`${i}:tab`,role:"block",geometry:{kind:"rect",x:o,y:a,width:r,height:l},paint:{fill:p,stroke:g,strokeWidth:String(n.groupLineWidth)}})},{indent:0,node:e.text({id:`${i}:label`,role:"label",text:d,block:s.block,x:c,y:h,fontSize:n.groupHeaderFontSize,fontWeight:n.groupHeaderFontWeight,letterSpacing:n.groupLetterSpacing,anchor:"start",paint:{fill:u}})}]})}(e,t.header,u,_.get(t)))}let U=new Map;for(let t of l.blocks){let n=U.get(t.type)??0;U.set(t.type,n+1),t.dividers.some(e=>e.label)&&g.push(function(e,t,n,i,o){let a=n.edgeTextColor??"var(--_text-muted)",r=[];return t.dividers.forEach((t,l)=>{if(!t.label||!t.labelPosition)return;let{text:s,x:d,y:c,bounds:h}=t.labelPosition,p=o(e5(h),a),g={ink:p.ink,halo:p.halo??n.groupFillColor??"var(--bg)"};r.push({indent:2,node:e.text({id:`${i}:divider#${l}:label`,role:"label",text:s,block:t.labelPosition.block,x:d,y:c,fontSize:n.edgeLabelFontSize,fontWeight:n.edgeLabelFontWeight,letterSpacing:n.edgeLetterSpacing,anchor:"start",paint:{fill:g.ink,...e8(g)}})})}),e.group({id:`${i}:divider-labels`,role:"block",open:'<g class="sequence-block-divider-labels" pointer-events="none">',close:"</g>",children:r})}(e,t,u,_.get(t),F))}let J=new Map;for(let t of l.messages){let n=`${t.from}->${t.to}`,i=J.get(n)??0;J.set(n,i+1),g.push(function(e,t,n,i,o,a){let r=[],l=e4(a,t.startHead),s=e4(a,t.endHead),d=n.edgeStrokeColor??"var(--_line)",c=n.edgeTextColor??"var(--_text-muted)",{text:h,x:p,y:g,bounds:u}=t.labelPosition,f={stroke:d,strokeWidth:String(n.lineWidth),..."dashed"===t.lineStyle?{strokeDasharray:"6 4"}:{}},x={endpoints:{from:t.from,to:t.to},relationship:{kind:"sequence-message",direction:t.isSelf?"self":l&&s?"bidirectional":l?"reverse":s?"forward":"undirected"},route:{ownership:"layout"},labels:t.label?[{text:t.label,...t.labelContent?{textContent:t.labelContent}:{}}]:[]},b=`<g class="message" data-label="${V(t.label)}" data-line-style="${t.lineStyle}" data-start-head="${t.startHead}" data-end-head="${t.endHead}" data-central-start="${t.centralStart}" data-central-end="${t.centralEnd}" data-self="${t.isSelf}"${void 0===t.parentId?"":` data-parent-id="${G(t.parentId)}"`}>`;if(t.isSelf){r.push({indent:2,node:e.connector({id:`${i}:line`,role:"message",geometry:{kind:"polyline",points:t.points},lineStyle:t.lineStyle,paint:f,markers:{...l?{start:l}:{},mid:[],...s?{end:s}:{}},...x})});let a=o(e5(u),c);r.push({indent:2,node:e.text({id:`${i}:label`,role:"label",text:h,block:t.labelPosition.block,x:p,y:g,fontSize:n.edgeLabelFontSize,fontWeight:n.edgeLabelFontWeight,letterSpacing:n.edgeLetterSpacing,anchor:"start",paint:{fill:a.ink,...e8(a)}})})}else{let a=t.points[0],d=t.points[t.points.length-1];r.push({indent:2,node:e.connector({id:`${i}:line`,role:"message",geometry:{kind:"line",x1:a.x,y1:a.y,x2:d.x,y2:d.y},lineStyle:t.lineStyle,paint:f,markers:{...l?{start:l}:{},mid:[],...s?{end:s}:{}},...x})});let b=o(e5(u),c);r.push({indent:2,node:e.text({id:`${i}:label`,role:"label",text:h,block:t.labelPosition.block,x:p,y:g,fontSize:n.edgeLabelFontSize,fontWeight:n.edgeLabelFontWeight,letterSpacing:n.edgeLetterSpacing,anchor:"middle",paint:{fill:b.ink,...e8(b)}})})}return t.centralStart&&r.push({indent:2,node:e.shape({id:`${i}:central-start`,role:"chrome",geometry:{kind:"circle",cx:t.x1,cy:t.y,r:4},paint:{fill:"var(--bg)",stroke:d,strokeWidth:"1.5"},attributes:{className:"sequence-central-connection",data:{side:"start"}}})}),t.centralEnd&&r.push({indent:2,node:e.shape({id:`${i}:central-end`,role:"chrome",geometry:{kind:"circle",cx:t.x2,cy:t.y,r:4},paint:{fill:"var(--bg)",stroke:d,strokeWidth:"1.5"},attributes:{className:"sequence-central-connection",data:{side:"end"}}})}),e.group({id:i,role:"message",open:b,close:"</g>",children:r})}(e,t,u,t.id??`message:${n}#${i}`,F,v))}let ee=new Map;for(let t of l.notes){let n=`${(t.actors??[]).join(",")}@${t.position??"over"}`,i=ee.get(n)??0;ee.set(n,i+1),g.push(function(e,t,n,i,o){let{x:a,y:r,width:l,height:s}=t,d=t.actors&&t.actors.length>0?` data-actors="${t.actors.map(G).join(",")}"`:"",c=t.position?` data-position="${G(t.position)}"`:"",h=n.nodeFillColor??"var(--bg)",p=n.nodeBorderColor??"var(--_node-stroke)",g=n.nodeTextColor??k("var(--_text-muted)",h,i),u=n.cornerRadius??0,f=t.block?.text??z(t.text,n.nodeTextTransform);return e.group({id:o,role:"note",open:`<g class="note"${c}${d}${void 0===t.parentId?"":` data-parent-id="${G(t.parentId)}"`}>`,close:"</g>",children:[{indent:2,node:e.shape({id:`${o}:rect`,role:"note",geometry:{kind:"rect",x:a,y:r,width:l,height:s,rx:u,ry:u},paint:{fill:h,stroke:p,strokeWidth:String(H.innerBox)}})},{indent:2,node:e.text({id:`${o}:text`,role:"label",text:f,block:t.block,x:a+l/2,y:r+s/2,fontSize:n.nodeLabelFontSize,fontWeight:n.nodeLabelFontWeight,letterSpacing:n.nodeLetterSpacing,anchor:"middle",paint:{fill:g}})}]})}(e,t,u,s,t.id??`note:${n}#${i}`))}for(let t of l.destructions)g.push(function(e,t,n){let i=n.edgeStrokeColor??"var(--_line)",o=Math.max(1.5,n.lineWidth),a=`M ${t.x-8} ${t.y-8} L ${t.x+8} ${t.y+8} M ${t.x-8} ${t.y+8} L ${t.x+8} ${t.y-8}`;return e.shape({id:`destroy:${t.actorId}`,role:"icon",geometry:{kind:"path",d:a},paint:{fill:"none",stroke:i,strokeWidth:String(o)},channels:{category:t.actorId},attributes:{className:"destroy-cross",data:{actor:t.actorId}}})}(e,t,u));for(let t of l.actors)t.external||g.push(function(e,t,n,i,o,a,r){let{id:l,x:s,y:d,width:c,height:h,label:p,type:g}=t,u=[],f=eo(o,"actor",{category:l},{includeFallback:!1}),x=f?.fontSize??n.nodeLabelFontSize,b=f?.fontWeight??n.nodeLabelFontWeight,m=f?.letterSpacing??n.nodeLetterSpacing,y=(f?.textTransform??n.nodeTextTransform,f?.lineWidth??n.nodeLineWidth),w=f?.fillColor??n.nodeFillColor??"var(--_node-fill)",v=f?.borderColor??n.nodeBorderColor??"var(--_node-stroke)",M=f?.textColor??n.nodeTextColor??"var(--_text)",I=f?.textColor??n.nodeTextColor??k("var(--_text)",w,i),S=a&&t.links?` data-links="${G(JSON.stringify(t.links))}" role="link" tabindex="0"`:"",$=`<g class="actor" data-id="${G(l)}" data-label="${V(p)}" data-type="${g}"${S}>`,{text:L,x:C,y:W,bounds:P}=t.labelPosition,q=r(e5(P),M);if("actor"===g){let i=h/24*.9,o=s-12*i,a=d+(h-24*i)/2,r=y/i;u.push({indent:2,node:e.pathArtwork({id:`actor:${l}:icon`,owner:{id:l,role:"actor"},channels:{category:l},open:`<g transform="translate(${o},${a}) scale(${i})">`,transform:{kind:"matrix",a:i,b:0,c:0,d:i,e:o,f:a},paint:{fill:"none",stroke:f?.borderColor??n.edgeStrokeColor??"var(--_line)",strokeWidth:String(r)},join:`
6
- `,indent:2,paths:["M21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3C16.9706 3 21 7.02944 21 12Z","M15 10C15 11.6569 13.6569 13 12 13C10.3431 13 9 11.6569 9 10C9 8.34315 10.3431 7 12 7C13.6569 7 15 8.34315 15 10Z","M5.62842 18.3563C7.08963 17.0398 9.39997 16 12 16C14.6 16 16.9104 17.0398 18.3716 18.3563"]})}),u.push({indent:2,node:e.text({id:`actor:${l}:label`,role:"label",text:L,block:t.labelPosition.block,x:C,y:W,fontSize:x,fontWeight:b,letterSpacing:m,anchor:"middle",paint:{fill:q.ink,...e8(q)},channels:{category:l}})})}else if("participant"!==g){let i=s-c/2,o=d+2,a=Math.max(24,h-4),r=[],p={id:l,role:"actor"},k={fill:w,stroke:f?.borderColor??n.edgeStrokeColor??"var(--_line)",strokeWidth:String(y)},v=t=>{r.push(e.shape({id:Q(`actor:${l}:icon`,"part",r.length),role:"icon",owner:p,geometry:t,paint:k}))},M=e=>v({kind:"path",d:e}),I=(e,t,n)=>v({kind:"circle",cx:e,cy:t,r:n}),S=(e,t,n,i)=>v({kind:"line",x1:e,y1:t,x2:n,y2:i}),$=(e,t,n,i,o)=>v({kind:"rect",x:e,y:t,width:n,height:i,...void 0===o?{}:{rx:o}});"database"===g?(v({kind:"ellipse",cx:s,cy:o+5,rx:c/2,ry:5}),M(`M${i} ${o+5}V${o+a-5}A${c/2} 5 0 0 0 ${i+c} ${o+a-5}V${o+5}`),v({kind:"ellipse",cx:s,cy:o+a-5,rx:c/2,ry:5})):"collections"===g?($(i+6,o,c-6,a-6),$(i,o+6,c-6,a-6)):"queue"===g?($(i,o,c,a,a/2),S(i+8,o+a/2,i+c-8,o+a/2)):"entity"===g?(I(s,o+a/2-3,Math.min(c,a)/2-3),S(i+5,o+a,i+c-5,o+a)):"boundary"===g?(I(s+3,o+a/2,Math.min(c,a)/2-3),S(i+3,o+2,i+3,o+a-2)):"control"===g?(I(s,o+a/2,Math.min(c,a)/2-3),M(`M${s-4} ${o+4}L${s+4} ${o}L${s+2} ${o+8}`)):I(s,o+a/2,Math.min(c,a)/2-3),u.push({indent:2,node:e.group({id:`actor:${l}:icon`,role:"icon",owner:p,channels:{category:l},open:`<g class="sequence-actor-glyph sequence-actor-${g}">`,close:"</g>",join:"",children:r.map(e=>({node:e,indent:0}))})}),u.push({indent:2,node:e.text({id:`actor:${l}:label`,role:"label",text:L,block:t.labelPosition.block,x:C,y:W,fontSize:x,fontWeight:b,letterSpacing:m,anchor:"middle",paint:{fill:q.ink,...e8(q)},channels:{category:l}})})}else{let i=s-c/2,o=f?.cornerRadius??n.cornerRadius??4;u.push({indent:2,node:e.shape({id:`actor:${l}:box`,role:"actor",geometry:{kind:"rect",x:i,y:d,width:c,height:h,rx:o,ry:o},paint:{fill:w,stroke:v,strokeWidth:String(y)},channels:{category:l}})}),u.push({indent:2,node:e.text({id:`actor:${l}:label`,role:"label",text:L,block:t.labelPosition.block,x:C,y:W,fontSize:x,fontWeight:b,letterSpacing:m,anchor:"middle",paint:{fill:I},channels:{category:l}})})}let F="participant"===g?I:M;return t.links&&u.push({indent:2,node:e.text({id:`actor:${l}:menu`,role:"icon",text:"⋯",block:t.menuBlock,x:s+c/2-7,y:d+10,fontSize:10,anchor:"middle",paint:{fill:F},channels:{category:l},baselineShift:0,attributes:{className:"sequence-actor-menu"}})}),e.group({id:`actor:${l}`,role:"actor",open:$,close:"</g>",children:u,channels:{category:l}})}(e,t,u,s,d.styleFace,"strict"!==c.security,F));return g.push(e.documentClose()),{family:"sequence",width:l.width,height:l.height,colors:s,transparent:p,parts:g}}function e8(e){return e.halo?{stroke:e.halo,strokeWidth:"3",strokeLinejoin:"round",paintOrder:"stroke"}:{}}function e5(e){return{x:e.x+e.width/2,y:e.y+e.height/2,width:e.width,height:e.height}}function e4(e,t){if("none"===t)return;let n="filled"===t?"seq-arrow":"cross"===t?"seq-arrow-cross":"half-top"===t?"seq-arrow-half-top":"half-bottom"===t?"seq-arrow-half-bottom":"stick-top"===t?"seq-arrow-stick-top":"stick-bottom"===t?"seq-arrow-stick-bottom":"seq-arrow-open";return e.find(e=>e.id===n)}function e6(e,t){return"rect"===e.type?e.color??t.groupFillColor??"rgba(128, 128, 128, 0.5)":t.groupFillColor}function e9(e,t,n,i,o="all"){let a=[],r=t.label?` data-label="${V(t.label)}"`:"",l="dividers"===o?`<g class="sequence-block-divider-overlay" data-owner="${G(i)}">`:"frame"===o?`<g class="sequence-block-frame-overlay" data-owner="${G(i)}">`:`<g class="block" data-type="${G(t.type)}"${r}${void 0===t.parentId?"":` data-parent-id="${G(t.parentId)}"`}>`,s=e6(t,n)??"none",d="rect"===t.type?"none":n.groupBorderColor??"var(--_node-stroke)";"dividers"!==o&&a.push({indent:2,node:e.shape({id:"frame"===o?`${i}:frame`:`${i}:rect`,role:"block",geometry:{kind:"rect",x:t.x,y:t.y,width:t.width,height:t.height,rx:n.groupCornerRadius,ry:n.groupCornerRadius},paint:{fill:"frame"===o?"none":s,stroke:"background"===o?"none":d,strokeWidth:String(n.groupLineWidth)}})});let c=n.edgeStrokeColor??"var(--_line)",h=0;for(let r of"background"===o||"frame"===o||"par_over"===t.type?[]:t.dividers){let o=`${i}:divider#${h}`;h++;let l=Math.max(.75,.75*n.lineWidth);a.push({indent:2,node:e.connector({id:o,role:"block",geometry:{kind:"line",x1:t.x,y1:r.y,x2:t.x+t.width,y2:r.y},lineStyle:"dashed",paint:{stroke:c,strokeWidth:String(l),strokeDasharray:"6 4"}})})}return e.group({id:"dividers"===o?`${i}:divider-overlay`:"frame"===o?`${i}:frame-overlay`:i,role:"block",open:l,close:"</g>",children:a})}var e7=f(e3);function te({positioned:e,options:t}){let n=new Map(e.lifelines.map(e=>[e.actorId,e.x])),i=new Map;for(let t of e.messages)for(let e of[t.from,t.to])i.has(e)||i.set(e,t.y);let o=new Map;for(let t of e.notes)if(void 0!==t.parentId&&void 0!==t.id){let e=o.get(t.parentId)??[];e.push(t.id),o.set(t.parentId,e)}return{version:1,nodes:[...e.actors.map(e=>({id:e.id,x:s(e.external?e.x:e.bounds.x),y:s(e.external?i.get(e.id)??e.y:e.bounds.y),w:s(e.external?0:e.bounds.width),h:s(e.external?0:e.bounds.height),shape:e.external?"external-anchor":"rectangle",label:e.label,labelBounds:l(e.labelPosition.bounds),labelContainer:l(e.bounds),...e.external?{labelVisibility:"semantic"}:{},role:e.external?"mark":"box"})),...e.notes.map((e,t)=>({id:e.id??`note#${t}`,...void 0===e.parentId?{}:{parentId:e.parentId},x:s(e.x),y:s(e.y),w:s(e.width),h:s(e.height),shape:"note",label:e.text,...h(e.block,e.x+e.width/2,e.y+e.height/2,e),role:"box"}))],edges:e.messages.map((e,i)=>{var o;let a,r,h,p,g,u,f,x;return{id:e.id??`msg#${i}:${e.from}->${e.to}`,...void 0===e.parentId?{}:{parentId:e.parentId},from:e.from,to:e.to,path:e.points.map(e=>[s(e.x),s(e.y)]),label:e.label?{x:s(e.labelPosition.x),y:s(e.labelPosition.y),text:e.label,bounds:l(e.labelPosition.bounds)}:void 0,route:t.debug?(o=e.points,a=n.get(e.from),r=n.get(e.to),h=o[0],p=o[o.length-1],g=void 0!==a&&void 0!==h&&1>=Math.abs(h.x-a),u=void 0!==r&&void 0!==p&&1>=Math.abs(p.x-r),f=!e.isSelf&&o.every(t=>1>=Math.abs(t.y-e.y)),x=d(o),{family:"sequence",edgeIndex:i,routeClass:"family-layout",invariant:g&&u&&x?e.isSelf?"self-message":"lifeline-message":"unverified-family-route",bendCount:c(o),horizontal:f,sourceLifeline:g,targetLifeline:u,selfMessage:e.isSelf}):void 0}}),groups:e.blocks.map((e,t)=>({id:e.id??`block#${t}:${e.type}`,...void 0===e.parentId?{}:{parentId:e.parentId},x:s(e.bounds.x),y:s(e.bounds.y),w:s(e.bounds.width),h:s(e.bounds.height),members:void 0===e.id?[]:o.get(e.id)??[],label:e.label})),bounds:{w:s(e.width),h:s(e.height)}}}export{ep as a,eY as b,eB as c,eT as d,e_ as e,e1 as f,e3 as g,e7 as h,te as i};