agentic-mermaid 0.5.1 → 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 (175) hide show
  1. package/AGENT_NATIVE.md +63 -375
  2. package/CHANGELOG.md +73 -0
  3. package/README.md +87 -50
  4. package/assets/hero.png +0 -0
  5. package/dist/agent-core.d.ts +7 -7
  6. package/dist/agent-core.js +1 -1
  7. package/dist/agent.d.ts +7 -7
  8. package/dist/agent.js +1 -1
  9. package/dist/agentic-mermaid-mcp.js +1 -1
  10. package/dist/am.js +1 -1
  11. package/dist/browser-lazy/chunks/agentic-producer-core-ECZ3CMZM.js +1 -0
  12. package/dist/browser-lazy/chunks/architecture-H5LTMKQW.js +13 -0
  13. package/dist/browser-lazy/chunks/block-566X6FNV.js +11 -0
  14. package/dist/browser-lazy/chunks/builtin-backends-VAFEZXKY.js +12 -0
  15. package/dist/browser-lazy/chunks/c4-ZXFDLBFK.js +10 -0
  16. package/dist/browser-lazy/chunks/{chunk-REBVEXI2.js → chunk-2JQXRKBC.js} +1 -1
  17. package/dist/browser-lazy/chunks/chunk-37FZNMPR.js +1 -0
  18. package/dist/browser-lazy/chunks/chunk-3JTYTXA6.js +22 -0
  19. package/dist/browser-lazy/chunks/{chunk-2J5K6NIP.js → chunk-4NILRBC7.js} +1 -1
  20. package/dist/browser-lazy/chunks/chunk-5LKPDHPC.js +4 -0
  21. package/dist/browser-lazy/chunks/chunk-62MR3LWJ.js +1 -0
  22. package/dist/browser-lazy/chunks/chunk-64JFHCJC.js +1 -0
  23. package/dist/browser-lazy/chunks/chunk-6GPDLZFQ.js +1 -0
  24. package/dist/browser-lazy/chunks/chunk-6UOOATQR.js +1 -0
  25. package/dist/browser-lazy/chunks/chunk-7TTFBJYA.js +1 -0
  26. package/dist/browser-lazy/chunks/chunk-7UFOFWBA.js +20 -0
  27. package/dist/browser-lazy/chunks/{chunk-HR5TE7TE.js → chunk-A7V5VDKN.js} +1 -1
  28. package/dist/browser-lazy/chunks/chunk-CPO5P4L2.js +1 -0
  29. package/dist/browser-lazy/chunks/chunk-EIYLJ4FI.js +20 -0
  30. package/dist/browser-lazy/chunks/{chunk-GMTB5UTY.js → chunk-G4JBA7HU.js} +3 -3
  31. package/dist/browser-lazy/chunks/chunk-HJVO5VC3.js +1 -0
  32. package/dist/browser-lazy/chunks/chunk-IUI4DYC3.js +3 -0
  33. package/dist/browser-lazy/chunks/{chunk-SBXYR7Z3.js → chunk-J57YRC2M.js} +1 -1
  34. package/dist/browser-lazy/chunks/chunk-LBXXKLIR.js +3 -0
  35. package/dist/browser-lazy/chunks/chunk-NKW2ZNCD.js +1 -0
  36. package/dist/browser-lazy/chunks/chunk-O34YYEQV.js +1 -0
  37. package/dist/browser-lazy/chunks/{chunk-E7UIB4SZ.js → chunk-OBI5U5XU.js} +1 -1
  38. package/dist/browser-lazy/chunks/{chunk-LLPBKBIG.js → chunk-OFOS57WQ.js} +1 -1
  39. package/dist/browser-lazy/chunks/chunk-PSZEE64O.js +16 -0
  40. package/dist/browser-lazy/chunks/chunk-PXTLV57R.js +1 -0
  41. package/dist/browser-lazy/chunks/chunk-QVSZOF5M.js +1 -0
  42. package/dist/browser-lazy/chunks/chunk-TLFX3U6S.js +1 -0
  43. package/dist/browser-lazy/chunks/{chunk-MSP3S2VS.js → chunk-TT5GR5EJ.js} +1 -1
  44. package/dist/browser-lazy/chunks/{chunk-KXPF5KIU.js → chunk-V6I2VGNQ.js} +5 -5
  45. package/dist/browser-lazy/chunks/{chunk-HDKHAM2V.js → chunk-VRZKI33U.js} +1 -1
  46. package/dist/browser-lazy/chunks/chunk-XHU3A432.js +1 -0
  47. package/dist/browser-lazy/chunks/chunk-YVNJDVQO.js +1 -0
  48. package/dist/browser-lazy/chunks/chunk-Z7UHFVKN.js +6 -0
  49. package/dist/browser-lazy/chunks/class-XIFNVBFE.js +13 -0
  50. package/dist/{zenuml/chunks/decode-BWERFDGK.js → browser-lazy/chunks/decode-5MFOG3AZ.js} +1 -1
  51. package/dist/browser-lazy/chunks/{elk.bundled-L4CADV5W.js → elk.bundled-RYWHIS5N.js} +8 -8
  52. package/dist/browser-lazy/chunks/er-VEUYJBGG.js +11 -0
  53. package/dist/browser-lazy/chunks/eventmodeling-G7DITZX7.js +19 -0
  54. package/dist/browser-lazy/chunks/flowchart-SSFIU4EU.js +4 -0
  55. package/dist/browser-lazy/chunks/{forest-implementation-AEP24AIP.js → forest-implementation-RWFF7XDV.js} +1 -1
  56. package/dist/browser-lazy/chunks/gantt-HQNVDX2B.js +11 -0
  57. package/dist/browser-lazy/chunks/{gitgraph-W26QIMTY.js → gitgraph-Z5MN6M6L.js} +4 -4
  58. package/dist/browser-lazy/chunks/ishikawa-UEERNFQV.js +6 -0
  59. package/dist/browser-lazy/chunks/journey-3BEWWGB5.js +16 -0
  60. package/dist/browser-lazy/chunks/kanban-2WFNCWLB.js +20 -0
  61. package/dist/{zenuml/chunks/mermaid-yaml-runtime-KZVU74WU.js → browser-lazy/chunks/mermaid-yaml-runtime-IK4ET4BT.js} +8 -8
  62. package/dist/browser-lazy/chunks/{mindmap-5A3MVHNH.js → mindmap-R2C6SNYR.js} +6 -6
  63. package/dist/browser-lazy/chunks/{packet-AL6VDOMY.js → packet-GMVCI5YZ.js} +5 -5
  64. package/dist/browser-lazy/chunks/pie-WER45DKC.js +15 -0
  65. package/dist/browser-lazy/chunks/{quadrant-RJ56XFBR.js → quadrant-NCUPSFKN.js} +5 -5
  66. package/dist/browser-lazy/chunks/radar-WLYS4YC5.js +16 -0
  67. package/dist/browser-lazy/chunks/render-core-42UVWIPF.js +3 -0
  68. package/dist/browser-lazy/chunks/requirement-AK3NWMJ6.js +19 -0
  69. package/dist/browser-lazy/chunks/{sankey-WKTBEZSS.js → sankey-C2DY6WVU.js} +8 -8
  70. package/dist/browser-lazy/chunks/sequence-D4WJB44W.js +5 -0
  71. package/dist/browser-lazy/chunks/state-YUQVESE7.js +4 -0
  72. package/dist/browser-lazy/chunks/{timeline-PRV5PWGP.js → timeline-BMBJJXWR.js} +4 -4
  73. package/dist/browser-lazy/chunks/{treemap-BVME3JLI.js → treemap-B66XBZZ6.js} +4 -4
  74. package/dist/browser-lazy/chunks/{xychart-XBI2RNHD.js → xychart-HAVFROGT.js} +6 -6
  75. package/dist/browser-lazy/chunks/{zenuml-GQKPRQFJ.js → zenuml-62RLYFWP.js} +8 -8
  76. package/dist/browser-lazy/index.d.ts +10 -0
  77. package/dist/browser-lazy/index.js +1 -1
  78. package/dist/browser.global.js +541 -541
  79. package/dist/{chunk-AVS4T4NO.js → chunk-2DNGDTJD.js} +2 -2
  80. package/dist/{chunk-AWZBTOV6.js → chunk-4F2UGYTM.js} +2 -2
  81. package/dist/{chunk-6JBQYHWB.js → chunk-7XYB2LNC.js} +2 -2
  82. package/dist/chunk-DOFB572I.js +58 -0
  83. package/dist/chunk-EHJI3QYE.js +52 -0
  84. package/dist/{chunk-YISEN5SO.js → chunk-HINRNKPO.js} +2 -2
  85. package/dist/{chunk-ORYXYGDV.js → chunk-KXMANAST.js} +33 -33
  86. package/dist/chunk-U4MT3RRE.js +2 -0
  87. package/dist/{chunk-AIWXP4OF.js → chunk-WYIB6BUR.js} +2 -2
  88. package/dist/{cli-BOEN5YAF.js → cli-ZYIDBYNS.js} +2 -2
  89. package/dist/{index-Cr3xjRw9.d.ts → index-Bvhprdxz.d.ts} +3 -3
  90. package/dist/index.d.ts +4 -4
  91. package/dist/index.js +1 -1
  92. package/dist/{mcp-cli-NM3P4VPC.js → mcp-cli-YVDCORWA.js} +2 -2
  93. package/dist/{paint-certification-C33LRvWT.d.ts → paint-certification-BoLyr006.d.ts} +22 -2
  94. package/dist/{server-FY5Z7F32.js → server-4JGAVXR3.js} +2 -2
  95. package/dist/{svg-styles-C_v2tnxG.d.ts → svg-styles-BnCoXyYe.d.ts} +1 -1
  96. package/dist/svg-styles.d.ts +1 -1
  97. package/dist/svg-styles.js +1 -1
  98. package/dist/svg.d.ts +4 -4
  99. package/dist/svg.js +1 -1
  100. package/dist/{types-DxOTIgwg.d.ts → types-CLVJCaH2.d.ts} +11 -1
  101. package/dist/zenuml/chunks/{appearance-FTQ2722O.js → appearance-5RM5MVM2.js} +1 -1
  102. package/dist/zenuml/chunks/{builtin-backends-QLY75JCL.js → builtin-backends-UTNWL4N3.js} +11 -11
  103. package/dist/zenuml/chunks/{chunk-LYIRUTCM.js → chunk-3A6S6GNB.js} +2 -2
  104. package/dist/zenuml/chunks/{chunk-6OONHTSD.js → chunk-55WS466K.js} +9 -9
  105. package/dist/zenuml/chunks/chunk-6J4BGPB2.js +29 -0
  106. package/dist/zenuml/chunks/chunk-CNLL4BGF.js +1 -0
  107. package/dist/zenuml/chunks/{chunk-YFCDP4ZS.js → chunk-IARQ24W3.js} +13 -13
  108. package/dist/zenuml/chunks/chunk-ZNZRIISS.js +4 -0
  109. package/dist/{browser-lazy/chunks/decode-63UIZGD2.js → zenuml/chunks/decode-LDNNXEAO.js} +1 -1
  110. package/dist/{browser-lazy/chunks/mermaid-yaml-runtime-QVYX4EWK.js → zenuml/chunks/mermaid-yaml-runtime-A5CNJ3IE.js} +8 -8
  111. package/dist/zenuml/chunks/render-core-ECIWU5ZS.js +3 -0
  112. package/dist/zenuml/chunks/{zenuml-URQ4HIMD.js → zenuml-N3LZMB2G.js} +9 -9
  113. package/dist/zenuml.d.ts +2 -2
  114. package/dist/zenuml.js +1 -1
  115. package/docs/MCP-DIRECTORY-LISTINGS.md +81 -12
  116. package/docs/README.md +59 -110
  117. package/docs/api.md +3 -1
  118. package/docs/config.md +37 -0
  119. package/docs/getting-started.md +27 -44
  120. package/examples/styles/readme-hero.md +25 -0
  121. package/examples/styles/readme-hero.mmd +13 -0
  122. package/examples/styles/readme-hero.style.json +7 -0
  123. package/package.json +1 -1
  124. package/server.json +2 -2
  125. package/dist/browser-lazy/chunks/agentic-producer-core-MGU4FD6J.js +0 -1
  126. package/dist/browser-lazy/chunks/architecture-KZTC3672.js +0 -13
  127. package/dist/browser-lazy/chunks/block-J5PD6HQM.js +0 -11
  128. package/dist/browser-lazy/chunks/builtin-backends-GSGJPT5A.js +0 -12
  129. package/dist/browser-lazy/chunks/c4-VNQSIA5M.js +0 -10
  130. package/dist/browser-lazy/chunks/chunk-4C2BVM5Y.js +0 -1
  131. package/dist/browser-lazy/chunks/chunk-5GE2SFLQ.js +0 -4
  132. package/dist/browser-lazy/chunks/chunk-6YGQR6R4.js +0 -16
  133. package/dist/browser-lazy/chunks/chunk-7AHX3HH7.js +0 -1
  134. package/dist/browser-lazy/chunks/chunk-B5PDJUJG.js +0 -3
  135. package/dist/browser-lazy/chunks/chunk-CXQWSLJV.js +0 -1
  136. package/dist/browser-lazy/chunks/chunk-DWDYWUAS.js +0 -1
  137. package/dist/browser-lazy/chunks/chunk-EUBVLDYV.js +0 -29
  138. package/dist/browser-lazy/chunks/chunk-FBL4ONAL.js +0 -20
  139. package/dist/browser-lazy/chunks/chunk-NQF75XGM.js +0 -3
  140. package/dist/browser-lazy/chunks/chunk-P7DO3MRP.js +0 -13
  141. package/dist/browser-lazy/chunks/chunk-QQ2U2KAY.js +0 -1
  142. package/dist/browser-lazy/chunks/chunk-SJYDRC6G.js +0 -1
  143. package/dist/browser-lazy/chunks/chunk-UUTB6MDK.js +0 -1
  144. package/dist/browser-lazy/chunks/chunk-WEREIH5P.js +0 -1
  145. package/dist/browser-lazy/chunks/chunk-WHNTP27R.js +0 -6
  146. package/dist/browser-lazy/chunks/chunk-YXGB25MZ.js +0 -1
  147. package/dist/browser-lazy/chunks/class-FNDNJGYH.js +0 -13
  148. package/dist/browser-lazy/chunks/er-P263BDFG.js +0 -11
  149. package/dist/browser-lazy/chunks/eventmodeling-XX3VCGSC.js +0 -19
  150. package/dist/browser-lazy/chunks/flowchart-GTLWJA3P.js +0 -4
  151. package/dist/browser-lazy/chunks/gantt-SRIHFAIC.js +0 -11
  152. package/dist/browser-lazy/chunks/ishikawa-NTHJ7BUO.js +0 -6
  153. package/dist/browser-lazy/chunks/journey-3T62IEHN.js +0 -16
  154. package/dist/browser-lazy/chunks/kanban-U6DQ7LWQ.js +0 -20
  155. package/dist/browser-lazy/chunks/pie-4QYMTQ7W.js +0 -15
  156. package/dist/browser-lazy/chunks/radar-L5B4CNEL.js +0 -16
  157. package/dist/browser-lazy/chunks/render-core-CIGKBI2T.js +0 -3
  158. package/dist/browser-lazy/chunks/requirement-5QVLRI6Z.js +0 -19
  159. package/dist/browser-lazy/chunks/sequence-G6DQHPR7.js +0 -5
  160. package/dist/browser-lazy/chunks/state-6DEA5BXE.js +0 -4
  161. package/dist/chunk-PNL435CH.js +0 -58
  162. package/dist/chunk-XCEEF3NJ.js +0 -2
  163. package/dist/chunk-YQKNJNU4.js +0 -52
  164. package/dist/zenuml/chunks/chunk-4VRUBLG4.js +0 -29
  165. package/dist/zenuml/chunks/chunk-7QDAZ2HL.js +0 -4
  166. package/dist/zenuml/chunks/chunk-GDLMM3YO.js +0 -1
  167. package/dist/zenuml/chunks/render-core-DNCYYOIB.js +0 -3
  168. /package/dist/browser-lazy/chunks/{chunk-5FQ534HP.js → chunk-BMZ24VPS.js} +0 -0
  169. /package/dist/browser-lazy/chunks/{chunk-2I4UPL7Q.js → chunk-D6MQ7QSU.js} +0 -0
  170. /package/dist/browser-lazy/chunks/{chunk-LH7HUDKW.js → chunk-L4UC3KGS.js} +0 -0
  171. /package/dist/browser-lazy/chunks/{chunk-NMQQMRIR.js → chunk-MFTQWHUB.js} +0 -0
  172. /package/dist/browser-lazy/chunks/{chunk-N5ELX7LR.js → chunk-PJJSDGLB.js} +0 -0
  173. /package/dist/browser-lazy/chunks/{chunk-CSFUKSU6.js → chunk-QCU5G5PZ.js} +0 -0
  174. /package/dist/browser-lazy/chunks/{chunk-5UVGUSD6.js → chunk-YHMTSXIR.js} +0 -0
  175. /package/dist/zenuml/chunks/{chunk-EVPSMEKN.js → chunk-GC7IPQ5P.js} +0 -0
@@ -1 +0,0 @@
1
- import{a as e,c as t}from"./chunk-NMQQMRIR.js";import{a as i,b as n,d as r,e as o}from"./chunk-YXGB25MZ.js";import{$ as a,A as s,B as l,C as d,D as h,E as g,F as u,G as f,H as c,I as p,J as y,K as m,L as x,N as b,O as w,P as M,Q as v,R as S,S as k,T as E,U as N,V as P,W as C,X as R,Y as I,Z as L,_ as O,a as $,aa as z,b as A,ba as B,c as F,ca as T,da as _,ea as D,fa as H,ga as W,h as j,ha as X,i as V,ia as G,j as U,ja as Y,k as q,ka as K,l as Q,la as J,m as Z,ma as ee,n as et,na as ei,oa as en,pa as er,qa as eo,r as ea,ra as es,s as el,sa as ed,t as eh,ta as eg,u as eu,ua as ef,v as ec,w as ep,x as ey,y as em,z as ex}from"./chunk-CXQWSLJV.js";import{A as eb,B as ew,C as eM,D as ev,E as eS,G as ek,H as eE,I as eN,J as eP,K as eC,L as eR,M as eI,N as eL,O as eO,P as e$,Q as ez,l as eA,m as eB,n as eF,q as eT,u as e_,v as eD,w as eH,z as eW}from"./chunk-SJYDRC6G.js";import{L as ej,P as eX,ja as eV,ka as eG,la as eU}from"./chunk-GMTB5UTY.js";import{Ra as eY,ea as eq,ha as eK,ma as eQ,oa as eJ,u as eZ,va as e0}from"./chunk-EUBVLDYV.js";import{A as e1,L as e2,M as e5,Q as e6,R as e4,S as e8,W as e3,_ as e9,aa as e7,ba as te,l as tt,u as ti,w as tn}from"./chunk-P7DO3MRP.js";function tr(e){throw Error(`LAYOUT_HINT_INVALID: ${e}`)}var to=class extends Error{constructor(e,t,i){super(i),this.pass=e,this.contract=t,this.name="LayoutPassContractError"}pass;contract;code="LAYOUT_PASS_CONTRACT_VIOLATION"},ta=class extends to{constructor(e,t,i,n,r){super(e,"metric-budget",`Layout pass '${e}' worsened ${t} from ${i} to ${n} (allowance ${r})`),this.metric=t,this.before=i,this.after=n,this.allowance=r,this.name="LayoutMetricBudgetError"}metric;before;after;allowance;code="LAYOUT_METRIC_BUDGET_EXCEEDED"},ts=e=>{let t=[...e.nodes],i=e=>{for(let n of e)t.push(n),i(n.children??[])};return i(e.groups??[]),t},tl=["unreadableTitles","edgeCrossings","labelConflicts","totalBends","nonCanonicalEndpointRate","peerBarycenterDelta","area"];function td(e,t){let i=new Map,n=e=>{for(let t of e)i.set(t.id,t),n(t.children)};n(e.subgraphs);let r=t=>{for(let n of t)n.nodeIds=i.get(n.id).nodeIds.filter(t=>e.nodes.has(t)&&!i.has(t)),r(n.children)};r(t.groups)}function th(e,t){let i=[];if(![e.width,e.height].every(Number.isFinite)||e.width<0||e.height<0)return["non-finite or negative canvas"];let n=(t,n,r,o,a)=>{![n,r,o,a].every(Number.isFinite)||o<0||a<0?i.push(`${t}: non-finite or negative geometry`):(n<-.5||r<-.5||n+o>e.width+.5||r+a>e.height+.5)&&i.push(`${t}: outside canvas`)};for(let t of e.nodes)n(`node ${t.id}`,t.x,t.y,t.width,t.height);let r=e=>{n(`group ${e.id}`,e.x,e.y,e.width,e.height),e.children.forEach(r)};for(let o of(e.groups.forEach(r),e.edges)){for(let e of("invisible"!==o.style&&o.points.length<2&&i.push(`edge ${o.source}->${o.target}: missing route`),!o.label||o.labelPosition&&o.labelBlock||i.push(`label ${o.source}->${o.target}: missing retained geometry`),o.points))n(`edge ${o.source}->${o.target}`,e.x,e.y,0,0);if(void 0!==o.label&&o.labelPosition&&o.labelBlock){let e=Z(o,t);e&&n(`label ${o.source}->${o.target}`,e.x,e.y,e.w,e.h)}}for(let t of e.notes??[])n(`note ${t.id}`,t.x,t.y,t.width,t.height);if(e.title?.block){let t=e.title,i=t.block;n("diagram title",t.x-i.width/2,t.y-i.height/2,i.width,i.height)}return i}function tg(e,t){let i,n,r,o=th(e,t);return o.length?o:(i=[],n=(e,t,i,n)=>{let r=0,o=1;for(let[a,s,l,d]of[[e.x,t.x-e.x,i.x,i.x+i.width],[e.y,t.y-e.y,i.y,i.y+n]]){if(0===s){if(a<=l||a>=d)return!1;continue}let e=(l-a)/s,t=(d-a)/s;if((r=Math.max(r,Math.min(e,t)))>=(o=Math.min(o,Math.max(e,t))))return!1}return r<o},r=o=>{if(!o.concurrencyRegion){let r=o.labelBlock??F(tn(o.label,o.labelContent),t,"group"),a=o.headerHeight??t.groupHeaderFontSize+16+r.height-r.lineHeight;if(!Number.isFinite(a)||a<0)i.push(`group-header ${o.id}: invalid retained height`);else if(a>0&&o.width>0){for(let t of e.edges)if("invisible"!==t.style){for(let e=1;e<t.points.length;e++)if(n(t.points[e-1],t.points[e],o,a)){i.push(`group-header ${o.id}: edge ${t.source}->${t.target} segment ${e} enters reserved band`);break}}}}o.children.forEach(r)},e.groups.forEach(r),i)}function tu(e,t,i,n=!1){return tf(e,t,i,n)}function tf(e,t,i,n=!1,r="final"){try{var o;let a=i.produce(),s=function(e,t,i){let n=[],r=(e,t,r,o)=>{if(!r)return;let a=e1(t,"formatted","node"===o?i.nodeTextTransform:"edge"===o?i.edgeTextTransform:i.groupTextTransform),s=r.prepared,l=s.lines.length===a.lines.length&&s.lines.every((e,t)=>e.length===a.lines[t].length&&e.every((e,i)=>{let n=a.lines[t][i];return e.text===n.text&&e.bold===n.bold&&e.italic===n.italic&&e.underline===n.underline&&e.strikethrough===n.strikethrough&&e.sourceStart===n.sourceStart&&e.sourceEnd===n.sourceEnd&&e.clusters?.length===n.clusters?.length&&(e.clusters?.every((e,t)=>{let i=n.clusters[t];return e.text===i.text&&e.sourceStart===i.sourceStart&&e.sourceEnd===i.sourceEnd})??!0)}));(s.source!==a.source||s.display!==a.display||s.transform!==a.transform||s.lineStarts.length!==a.lineStarts.length||s.lineStarts.some((e,t)=>e!==a.lineStarts[t])||!l)&&n.push(`${e}: changed retained prepared text`)},o=new Map,a=new Map,s=new Map,l=new Map,d=(e,t="")=>{for(let i of e)o.set(i.id,t),s.set(i.id,i),d(i.children,i.id)},h=(e,t="")=>{for(let i of e)a.has(i.id)&&n.push(`group ${i.id}: duplicate identity`),a.set(i.id,t),l.set(i.id,i),h(i.children,i.id)};for(let[i,r]of(d(e.subgraphs),h(t.groups),o))a.get(i)!==r&&n.push(`group ${i}: missing or changed parent`);for(let e of a.keys())o.has(e)||n.push(`group ${e}: unexpected identity`);let g=new Set,u=new Map(t.nodes.map(e=>[e.id,e]));for(let i of t.nodes)if(g.has(i.id)&&n.push(`node ${i.id}: duplicate identity`),g.add(i.id),e.nodes.has(i.id))if(i.label!==e.nodes.get(i.id).label)n.push(`node ${i.id}: changed label`);else{let t=e.nodes.get(i.id);r(`node ${i.id}`,tn(t.label,t.labelContent),i.labelBlock,"node")}else n.push(`node ${i.id}: unexpected identity`);for(let t of e.nodes.keys())g.has(t)||a.has(t)||n.push(`node ${t}: missing identity`);for(let[e,t]of s){let i=l.get(e);if(!i)continue;i.label!==t.label&&n.push(`group ${e}: changed label`),r(`group ${e}`,tn(t.label,t.labelContent),i.labelBlock,"group");let a=l.get(o.get(e)??"");for(let r of(a&&(i.x<a.x-.5||i.y<a.y-.5||i.x+i.width>a.x+a.width+.5||i.y+i.height>a.y+a.height+.5)&&n.push(`group ${e}: outside authored parent ${a.id}`),t.nodeIds)){if(s.has(r))continue;let t=u.get(r);t&&(t.x<i.x-.5||t.y<i.y-.5||t.x+t.width>i.x+i.width+.5||t.y+t.height>i.y+i.height+.5)&&n.push(`member ${r}: outside authored group ${e}`)}}let f=new Set;for(let[i,o]of t.edges.entries()){let t=o.edgeIndex??i,a=e.edges[t];if(f.has(t)&&n.push(`edge ${t}: duplicate identity`),f.add(t),!a){n.push(`edge ${t}: unexpected identity`);continue}void 0!==a.label&&r(`edge ${t}`,tn(a.label,a.labelContent),o.labelBlock,"edge"),(o.source!==a.source||o.target!==a.target||(o.id??"")!==(a.id??"")||(o.label??"")!==(a.label??"")||o.style!==a.style||o.hasArrowStart!==a.hasArrowStart||o.hasArrowEnd!==a.hasArrowEnd||(o.startMarker??"arrow")!==(a.startMarker??"arrow")||(o.endMarker??"arrow")!==(a.endMarker??"arrow"))&&n.push(`edge ${t}: changed endpoints, identity, label, shaft or markers`)}return e.edges.forEach((e,t)=>{f.has(t)||n.push(`edge ${t}: missing identity`)}),n}(e,a,t);if(n&&s.length)throw TypeError(`Owned layout changed authored meaning: ${s.join("; ")}`);let l=[...s,..."placement"===r?th(a,t):tg(a,t)],d=0===l.length?T(e,a,t):void 0;d&&l.push(...D(d).map(e=>`${e.metric}: ${e.detail}`));let h=0===l.length&&(i.preferNext?.(a)??!1);return{attempt:{strategy:i.strategy,violations:l},...0===l.length&&d?{certified:{positioned:a,strategy:i.strategy,score:(o=d.metrics,{unreadableTitles:+!!h,labelConflicts:o.labelConflicts,edgeCrossings:o.edgeCrossings,totalBends:o.totalBends,nonCanonicalEndpointRate:1-o.portEndpointRate,peerBarycenterDelta:Math.round(1e3*o.peerBarycenterDelta)/1e3,area:a.width*a.height})}}:{}}}catch(e){if(n||e instanceof to||e instanceof ej||e instanceof e8)throw e;return{attempt:{strategy:i.strategy,violations:[e instanceof Error?e.message:String(e)]}}}}function tc(e,t){for(let i of tl){if(t.score[i]<e.score[i])return{selected:t,reason:i};if(t.score[i]>e.score[i])return{selected:e,reason:i}}return{selected:e,reason:"candidate-order"}}function tp(e,t,i,n,r="final"){let o=[],a=i.slice(0,4),s=n?[n,...a]:a,l,d,h=!1,g=[],u=(e,t)=>({selected:e,reason:t,compared:g,attempts:o.length});for(let[i,n]of s.entries()){if(l&&"routing"===d&&!1===n.qualityAlternative)continue;h&&(e0("layout-candidate","candidate-rejected",o.length+1),h=!1);let a=tf(e,t,n,!1,r);o.push(a.attempt);let f=a.certified;if(f){if(g.push({strategy:f.strategy,score:f.score}),l){let e=tc(l,f);return u(e.selected,e.reason)}let t=s.slice(i+1);if(f.score.unreadableTitles&&t.length>0){l=f,d="readability";continue}if(0===f.score.edgeCrossings&&0===f.score.labelConflicts)return u(f,"first-certified");if(!ep(e))return u(f,"work-budget");if(!t.some(e=>!1!==e.qualityAlternative))return u(f,"no-alternative");l=f,d="routing";continue}if(l)return u(l,"alternative-invalid");h=!0}if(l)return u(l,"no-alternative");throw new e4(o)}function ty(e,t){let{selected:i,reason:n,compared:r,attempts:o}=t;return td(e,i.positioned),i.positioned.certification={status:"passed",strategy:i.strategy,attempts:o,hardViolations:0,preference:{selectedScore:i.score,reason:n,compared:r}},i.positioned}function tm(e,t,i){let n=e.labelBlock??A(tn(e.label,e.labelContent),i);return{x:t.x-(n.width+16)/2,y:t.y-(n.height+16)/2,width:n.width+16,height:n.height+16}}function tx(e){let t=[e[0],e[e.length-1]],i=-1;for(let n=1;n<e.length;n++){let r=e[n-1],o=e[n],a=Math.hypot(o.x-r.x,o.y-r.y);a>i&&(i=a,t=[r,o])}return{x:(t[0].x+t[1].x)/2,y:(t[0].y+t[1].y)/2}}function tb(e){return Math.max(8,.75*e.edgeLabelFontSize)}function tw(e){return Math.max(12,e.edgeLabelFontSize)}function tM(e){let t=(e.lineWidth??1)*2;return Math.max(18,e.edgeLabelFontSize+eB.width+2*t)}function tv(e){return tM(e)+(3*eF.dash+2*eF.gap)}function tS(e,t,i){return Math.abs(i.x-t.x)>=Math.abs(i.y-t.y)?e.width/2:e.height/2}function tk(e,t,i,n,r,o){let a,s,l=(a=o.lineWidth??1,s="thick"===e.style?2*a:a,Math.max(18,o.edgeLabelFontSize+eB.width+2*s));if(e.hasArrowStart&&1===i){let e=t[0],i=tS(r,e,t[1]);if(Math.hypot(n.x-e.x,n.y-e.y)<i+l)return!1}if(e.hasArrowEnd&&i===t.length-1){let e=t[t.length-1],i=tS(r,t[t.length-2],e);if(Math.hypot(n.x-e.x,n.y-e.y)<i+l)return!1}return!0}function tE(e,t,i,n,r){if(!e.label)return[];let o=eM(t);if(0===o)return[];let a=o/2,s=[],l=[.5,.45,.55,.4,.6,.35,.65,.3,.7,.25,.75,.2,.8,1/6,5/6],d=0;for(let o=1;o<t.length;o++){var h;let g=t[o-1],u=t[o],f=Math.hypot(u.x-g.x,u.y-g.y);if(0===f)continue;let c=eS(n).isHorizontal?.01>Math.abs(g.y-u.y):.01>Math.abs(g.x-u.x),p=e.hasArrowStart&&1===o||e.hasArrowEnd&&o===t.length-1,y=tm(e,{x:0,y:0},r),m=(h=o,{start:e.hasArrowStart&&1===h?tM(r):tw(r),end:e.hasArrowEnd&&h===t.length-1?tv(r):tw(r)}),x=[...l,...function(e,t,i,n){let r=Math.hypot(i.x-t.x,i.y-t.y);if(0===r)return[];let o=tS(e,t,i),a=(o+n.start)/r,s=1-(o+n.end)/r;return a>s?[]:[(a+s)/2]}(y,g,u,m)].filter((e,t,i)=>e>=0&&e<=1&&i.findIndex(t=>.001>Math.abs(t-e))===t);for(let n=0;n<x.length;n++){let l=x[n],h={x:g.x+(u.x-g.x)*l,y:g.y+(u.y-g.y)*l},y=tm(e,h,r);if(i.some(e=>eI(y,e,2))||!tk(e,t,o,h,y,r))continue;let b=function(e,t,i,n,r){let o=tS(e,i,n);return Math.hypot(t.x-i.x,t.y-i.y)>=o+r.start&&Math.hypot(t.x-n.x,t.y-n.y)>=o+r.end}(y,h,g,u,m);s.push({point:h,box:y,order:n,rank:0,pathDistance:d+f*l,routeMidpointDistance:Math.abs(d+f*l-a),segmentMidpointDistance:Math.abs(f*(l-.5)),straightRunPenalty:c&&b?0:c?2:10,terminalSegmentPenalty:+!!p})}d+=f}return s.sort((e,t)=>e.straightRunPenalty-t.straightRunPenalty||e.terminalSegmentPenalty-t.terminalSegmentPenalty||e.segmentMidpointDistance-t.segmentMidpointDistance||e.routeMidpointDistance-t.routeMidpointDistance||e.order-t.order||e.pathDistance-t.pathDistance),s.map((e,t)=>({...e,rank:t}))}function tN(e,t,i,n,r){return tE(e,t,i,n,r)[0]?.point??ev(t)}function tP(e,t){let i=0,n=[];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);n.push(r),i+=r}let r=1/0,o=0,a=0;for(let i=1;i<t.length;i++){let s=t[i-1],l=t[i],d=l.x-s.x,h=l.y-s.y,g=d*d+h*h,u=g?((e.x-s.x)*d+(e.y-s.y)*h)/g:0;u=Math.max(0,Math.min(1,u));let f=s.x+u*d,c=s.y+u*h,p=Math.hypot(e.x-f,e.y-c);p<r&&(r=p,o=a+u*n[i-1]),a+=n[i-1]}return i?o/i:.5}function tC(e,t,i,n,r=!1){let o=e.filter(({edge:e})=>e.label);if(0===o.length)return;if(1===o.length){let e=o[0];e.edge.labelPosition=tN(e.edge,e.points,t,i,n)}else{let e=o.map(({edge:e,points:r})=>tE(e,r,t,i,n));if(e.some(e=>0===e.length))for(let{edge:e,points:r}of o)e.labelPosition=tN(e,r,t,i,n);else{let r=tb(n),a,s=1/0,l=[],d=t=>{if(t===e.length){let e,t,n,r,o,d,h,g=(e=eS(i),n=Math.max(...t=l.map(t=>t.point[e.main]))-Math.min(...t),r=l.reduce((e,t)=>e+t.straightRunPenalty,0),o=l.reduce((e,t)=>e+t.terminalSegmentPenalty,0),d=l.reduce((e,t)=>e+t.segmentMidpointDistance,0),h=l.reduce((e,t)=>e+t.routeMidpointDistance,0),1e4*r+100*n+1e3*o+4*d+.25*l.reduce((e,t)=>e+t.rank,0)+.1*h);g<s&&(s=g,a=l.slice());return}for(let i of e[t])l.some(e=>eI(i.box,e.box,r))||(l.push(i),d(t+1),l.pop())};if(d(0),a)for(let e=0;e<o.length;e++)o[e].edge.labelPosition=a[e].point;else for(let{edge:e,points:r}of o)e.labelPosition=tN(e,r,t,i,n)}}if(!r)return;let a=[],s=tb(n);for(let{edge:e}of o)e.labelPosition&&a.push(tm(e,e.labelPosition,n));for(let e=0;e<o.length;e++){let{edge:r,points:l}=o[e],d=r.labelPosition;(function(e,t,i,n,r,o=[],a=0){if(!e.label||!e.labelPosition)return;let s=function(e,t){let i=eS(t),n=e.map(e=>e[i.main]),r=(Math.min(...n)+Math.max(...n))/2,o=null;for(let t=1;t<e.length;t++){let n=e[t-1],a=e[t],s=Math.min(n[i.main],a[i.main]),l=Math.max(n[i.main],a[i.main]);if(r<s-1e-6||r>l+1e-6)continue;let d=a[i.main]-n[i.main];if(1e-6>=Math.abs(d))continue;let h=(r-n[i.main])/d,g={[i.main]:r,[i.cross]:n[i.cross]+h*(a[i.cross]-n[i.cross])};if(.01>Math.abs(n[i.cross]-a[i.cross]))return g;o??=g}return o}(t,n);if(!s)return;let l=Math.abs(tP(e.labelPosition,t)-.5);if(Math.abs(tP(s,t)-.5)>=l-1e-6)return;let d=tm(e,s,r);if(i.some(e=>eI(d,e,2))||o.some(e=>eI(d,e,a)))return;let h=eS(n);for(let i=1;i<t.length;i++){let n=t[i-1],o=t[i],a=Math.min(n[h.main],o[h.main]),l=Math.max(n[h.main],o[h.main]);if(!(1e-6>=Math.abs(o[h.main]-n[h.main]))&&!(s[h.main]<a-1e-6||s[h.main]>l+1e-6)){if(!tk(e,t,i,s,d,r))return;break}}e.labelPosition=s})(r,l,t,i,n,a.filter((t,i)=>i!==e),s),r.labelPosition&&r.labelPosition!==d&&(a[e]=tm(r,r.labelPosition,n))}}function tR(e,t,i,n){let r=new Map;if(eO("APL_NO_CORANK_FANIN"))return r;let o=eb(n.edges),a=new Map(e.map(e=>[e.id,e])),s=e=>!!e&&ey.has(e.shape)&&!G(e,i),l=e=>!!e&&"rectangle"===e.shape&&!G(e,i),d=new Map;for(let e of t)e.source!==e.target&&H(e,a,n.direction)&&(d.has(e.target)||d.set(e.target,[]),d.get(e.target).push(e));for(let[e,t]of d){if(t.length<2||t.length>6||!s(a.get(e)))continue;let i=t.filter(e=>!!e.label);if(0===i.length||i.length===t.length)continue;let d=t[0].style;if(t.some(e=>e.style!==d))continue;let h=t.map(e=>a.get(e.source)).filter(e=>!!e);if(h.length!==t.length||new Set(h.map(e=>e.id)).size!==h.length||!h.every(l)||!W(h,n.direction,28))continue;let g=!0;for(let e=0;e<h.length&&g;e++)for(let t=0;t<h.length;t++)if(e!==t&&o(h[e].id,h[t].id)){g=!1;break}g&&r.set(e,t)}return r}function tI(e,t,i){if(e.length>eu||t.length>ec)return!1;let n=eu-e.length,r=e=>e.every(e=>--n>=0&&r(e.children));return r(i)}var tL=(e,t)=>e.points.length!==t.points.length||e.points.some((e,i)=>e.x!==t.points[i].x||e.y!==t.points[i].y);function tO(){return{remaining:eu*ec}}function t$(e,t,i,n,r,o,a=tO()){let l=e.map((e,t)=>e.x!==i[t].x||e.y!==i[t].y),d=t.map((e,t)=>tL(e,n[t]));if(!l.some(Boolean)&&!d.some(Boolean))return!0;let h=()=>--a.remaining>=0,g=new Map,y=e=>(g.has(e)||g.set(e,p(e,o,h)),g.get(e)),m=new Map,x=e=>{if(!m.has(e)){let t=et(e,{fill:e.inlineStyle?.fill??o.nodeFillColor??"var(--_node-fill)",stroke:e.inlineStyle?.stroke??o.nodeBorderColor??"var(--_node-stroke)",strokeWidth:e5("stroke-width",e.inlineStyle?.["stroke-width"]??String(o.nodeLineWidth??eA.innerBox))},o.cornerRadius);m.set(e,eJ({kind:"shape",id:e.id,role:"node",geometry:u(t.geometry),paint:t.paint,...t.childPaints?{childPaints:t.childPaints}:{}}))}return m.get(e)};try{let o,a,g;for(let t=0;t<e.length;t++){if(!l[t])continue;let i=x(e[t]);if(!f(i))return!1;for(let n=0;n<e.length;n++){if(n===t||l[n]&&n<t)continue;if(!h())return!1;let r=x(e[n]);if(!f(r)||c(i,r))return!1}}for(let r=0;r<e.length;r++){let o=e[r];for(let e=0;e<t.length;e++){let a=t[e];if(!l[r]&&!d[e]||"invisible"===a.style)continue;if(!h()||a.source===o.id&&s(a,o)>s(n[e],i[r])||a.target===o.id&&s(a,void 0,o)>s(n[e],void 0,i[r]))return!1;let g=y(a);if(!g)return!1;let u=x(o);if(!f(u))return!1;if(a.source!==o.id&&a.target!==o.id){for(let e of g.shafts)if(!h()||c(u,e))return!1}for(let e of g.markers)if(("start"===e.position?a.source:a.target)!==o.id&&(!h()||!f(e.bounds)||c(u,e.bounds)))return!1;if(g.label&&(!h()||c(u,g.label)))return!1}}return o=e.filter((e,t)=>e.x!==i[t].x||e.y!==i[t].y),a=t.filter((e,t)=>"invisible"!==e.style&&tL(e,n[t])),g=e=>{if(!h())return!1;if(!e.concurrencyRegion&&0!==e.width){let t=e.headerHeight??e.height;if(!Number.isFinite(e.width)||e.width<0||!Number.isFinite(t)||t<0)return!1;if(t>0&&e.width>0){let i=eq({x0:e.x,y0:e.y,x1:e.x+e.width,y1:e.y+t},eK(u({kind:"rect",x:e.x,y:e.y,width:e.width,height:t})));if(!f(i))return!1;for(let e of o){if(!h())return!1;let t=x(e);if(!f(t))return!1;let n=eq(t,{x0:e.x,y0:e.y,x1:e.x+e.width,y1:e.y+e.height});if(!f(n)||c(n,i))return!1}for(let e of a){let t=y(e);if(!t)return!1;for(let e of t.shafts)if(!h()||c(e,i))return!1;for(let e of t.markers)if(!h()||!f(e.bounds)||c(e.bounds,i))return!1}}}return e.children.every(g)},r.every(g)}catch{return!1}}function tz(e,t){return{nodes:e.map(e=>({...e})),edges:t.map(e=>({...e,points:e.points.map(e=>({...e})),...e.labelPosition?{labelPosition:{...e.labelPosition}}:{}}))}}function tA(e,t,i,n){e.forEach((e,t)=>{e.x!==i[t].x&&(e.x=i[t].x),e.y!==i[t].y&&(e.y=i[t].y)}),t.forEach((e,t)=>{let i=n[t];tL(i,e)&&(e.points=i.points),(i.labelPosition?.x!==e.labelPosition?.x||i.labelPosition?.y!==e.labelPosition?.y)&&(e.labelPosition=i.labelPosition),i.routeCertificate!==e.routeCertificate&&(e.routeCertificate=i.routeCertificate)})}function tB(e,t,i){for(let n of i)if(n!==e){for(let e=1;e<n.points.length;e++)if(function(e,t,i,n=2){let r=i.x-n,o=i.x+i.w+n,a=i.y-n,s=i.y+i.h+n;if(.01>Math.abs(e.x-t.x)){let i=Math.min(e.y,t.y),n=Math.max(e.y,t.y);return e.x>=r&&e.x<=o&&n>=a&&i<=s}if(.01>Math.abs(e.y-t.y)){let i=Math.min(e.x,t.x),n=Math.max(e.x,t.x);return e.y>=a&&e.y<=s&&n>=r&&i<=o}return!1}(n.points[e-1],n.points[e],t))return!0}return!1}function tF(e,t){for(let i=1;i<e.length;i++)for(let n=1;n<t.length;n++){let r=e[i-1],o=e[i],a=t[n-1],s=t[n],l=(o.x-r.x)*(s.y-a.y)-(o.y-r.y)*(s.x-a.x);if(1e-9>Math.abs(l))continue;let d=((a.x-r.x)*(s.y-a.y)-(a.y-r.y)*(s.x-a.x))/l,h=((a.x-r.x)*(o.y-r.y)-(a.y-r.y)*(o.x-r.x))/l;if(d>.001&&d<.999&&h>.001&&h<.999)return!0}return!1}function tT(e,t,i){let n=new Map(t.map(e=>[e.edge,e])),r=new Set,o=e.map((e,t)=>{let i=n.get(e);return i?(r.add(t),{...e,points:i.points,labelPosition:i.label}):e}),{nodes:a,style:s}=i;return I({nodes:a,edges:o},s,r).total<=I({nodes:a,edges:e},s,r).total}function t_(e,t,i,n){let r=new Map(t.map(e=>[e.edge,e.points])),o=new Set,s=e.map((e,t)=>{let i=r.get(e);return i?(o.add(t),{...e,points:i}):e});for(let t of o){let n=e[t],r=s[t];if(U(n,r.points,s,i,r))return"marker-blocked"}if(n?.labelClearance&&!tT(e,t,n.labelClearance))return!1;let l=a(s,o)-a(e,o);if(!n?.allowCrossingsForOverlap)return l<=0;let d=z(e,o)-z(s,o);return!(d<0)&&(l<=0||l<=d)}function tD(e,t,i){if(!t)return;let n=i?0:e.length-1,r=i?1:-1,o=e[n];if(!o)return!1;for(let i=n+r;i>=0&&i<e.length;i+=r){let n=e[i];if(n.x!==o.x||n.y!==o.y)return ea(t,o,n)}return!1}function tH(e,t,i){let n={...e,points:e.points.filter((t,i)=>0===i||t.x!==e.points[i-1].x||t.y!==e.points[i-1].y).map(e=>({...e}))};return l(n,t,i),t&&(n.points=eh(n.points,t,!0)),i&&(n.points=eh(n.points,i,!1)),n}function tW(e,t,i,n){if(e.length<2||void 0===i&&void 0===n)return e;let r=e.map(e=>({...e})),o=t?"x":"y";for(let[e,t,a]of[[i,0,1],[n,r.length-1,r.length-2]]){if(void 0===e)continue;let i=r[t],n=r[a];i[o]+=e,n[o]===i[o]-e&&(n[o]+=e)}return r}function tj(e,t,i){let n=[];for(let r of i)e>=r.x&&e<=r.x+r.width&&t>=r.y&&t<=r.y+r.height&&(n.push(r),n.push(...tj(e,t,r.children)));return n}function tX(e,t,i,n,r){let o="LR"===r,a="RL"===r,s=o||a,l=new Set(tj(t,i,n).map(e=>e.id)),d=tj(s?e:t,s?i:e,n).find(e=>!l.has(e.id));return d?o?d.x-12:a?d.x+d.width+12:"BT"===r?d.y+d.height+12:d.y-12:e}function tV(e,t){let i=new Set(e),n=new Map(e.map((e,t)=>[e,t])),r=new Map(e.map(e=>[e,new Set])),o=new Map(e.map(e=>[e,0])),a=(e,t)=>{let i=new Set,n=[e];for(;n.length>0;){let e=n.pop();if(e===t)return!0;if(!i.has(e))for(let t of(i.add(e),r.get(e)??[]))n.push(t)}return!1};for(let e of t){if(e.source===e.target||!i.has(e.source)||!i.has(e.target))continue;let t=e.source,n=e.target,s=r.get(t);s.has(n)||a(n,t)||(s.add(n),o.set(n,(o.get(n)??0)+1))}let s=(e,t)=>(n.get(e)??0)-(n.get(t)??0),l=e.filter(e=>(o.get(e)??0)===0).sort(s),d=e=>{let t=l.length;for(l.push(e);t>0;){let i=t-1>>>1;if(0>=s(l[i],e))break;l[t]=l[i],t=i}l[t]=e},h=[];for(;l.length>0;){let e=l[0],t=l.pop();if(l.length){let e=0;for(;2*e+1<l.length;){let i=2*e+1;if(i+1<l.length&&0>s(l[i+1],l[i])&&i++,0>=s(t,l[i]))break;l[e]=l[i],e=i}l[e]=t}for(let t of(h.push(e),Array.from(r.get(e)??[]).sort(s))){let e=(o.get(t)??0)-1;o.set(t,e),0===e&&d(t)}}if(h.length<e.length){let t=new Set(h);h.push(...e.filter(e=>!t.has(e)).sort(s))}return h}function tG(e,t,i,n,r="TB",o,a){let s=a??F(t,n,"node");if("state-fork"===i||"state-join"===i){let e=o?.forkWidth??70,t=o?.forkHeight??10;return"LR"===r||"RL"===r?{width:t,height:e}:{width:e,height:t}}if("state-choice"===i)return{width:36,height:36};if("state-history"===i)return{width:32,height:32};let l=s.width+2*n.nodePaddingX,d=s.height+2*n.nodePaddingY;if("service"===i&&(l=Math.max(l+34,120),d=Math.max(d+6,48)),"diamond"===i){let e=Math.max(l,d)+n.diamondExtraPadding;l=e,d=e}if("circle"===i||"doublecircle"===i){let e=Math.ceil(Math.sqrt(l*l+d*d))+8;d=l="doublecircle"===i?e+12:e}return"ellipse"===i&&(l=Math.ceil(l*Math.SQRT2),d=Math.ceil(d*Math.SQRT2)),"hexagon"===i&&(l+=n.nodePaddingX),("trapezoid"===i||"trapezoid-alt"===i||"lean-r"===i||"lean-l"===i)&&(l+=n.nodePaddingX),"asymmetric"===i&&(l+=12),"cylinder"===i&&(d+=14),"state-start"===i||"state-end"===i?{width:28,height:28}:{width:l=Math.max(l,60),height:d=Math.max(d,36)}}function tU(e,t){let i=new Map;if(eO("APL_NO_CORANK_FANIN"))return i;let n=new Map;for(let t=0;t<e.edges.length;t++){let i=e.edges[t];i.source!==i.target&&(n.has(i.target)||n.set(i.target,[]),n.get(i.target).push(t))}for(let[r,o]of n){if(o.length<2)continue;let n=o.filter(t=>!!e.edges[t].label),a=o.filter(t=>!e.edges[t].label);if(0===n.length||0===a.length)continue;let s=e.nodes.get(r)?.shape;if(void 0===s||!ey.has(s))continue;let l=t=>e.nodes.get(t)?.shape==="rectangle";if(!o.every(t=>l(e.edges[t].source)))continue;let d=0,h=0;for(let i of n){let n=F(tn(e.edges[i].label,e.edges[i].labelContent),t,"edge");n.text,d=Math.max(d,n.width+8),h=Math.max(h,n.height+6)}for(let e of a)i.set(e,{width:d,height:h})}return i}function tY(e){return{text:" ",width:e.width,height:e.height,layoutOptions:{"elk.edgeLabels.inline":"true","elk.edgeLabels.placement":"CENTER"}}}function tq(e,t,i){var n;let r,o,a,s,l,h,g;t={...t,markerPortExtents:t.preserveSubgraphChildOrder||t.stateVisual?void 0:function(e,t){let i=new Map;for(let n=0;n<e.edges.length;n++){let r=e.edges[n],o=e.nodes.get(r.target);if(!o||"rectangle"!==o.shape||o.semanticShape||"invisible"===r.style||r.source===r.target)continue;let a=i.get(o.id)??{count:0,span:0,known:!0};a.count++;let s="thick"===r.style?2:1,l=t.lineWidth*s,d=(Number.isFinite(l)&&l>0?j({...r,curve:void 0,points:[{x:0,y:0},{x:100,y:0}],inlineStyle:eU(n,e)},{...t,lineWidth:Number(e2(l))/s,edgeBendRadius:0}):void 0)?.find(e=>"end"===e.position);!r.hasArrowEnd||d?.bounds&&Object.values(d.bounds).every(Number.isFinite)?d?.bounds&&(a.span=Math.max(a.span,d.bounds.y1-d.bounds.y0)):a.known=!1,i.set(o.id,a)}let n=new Map;for(let[e,t]of i)t.count<2||!t.known||t.span<=0||n.set(e,{count:t.count,span:t.span});return n}(e,i)};let u=new Set,f=new Set;for(let t of e.subgraphs)f.add(t.id),function e(t,i,n){for(let e of t.nodeIds)i.add(e);for(let r of t.children)n.add(r.id),e(r,i,n)}(t,u,f);let c=new Map;for(let t of e.edges)t.source===t.target&&c.set(t.source,(c.get(t.source)??0)+1);let p=Math.max(0,...c.values());p>4&&(t={...t,layerSpacing:Math.max(t.layerSpacing,t.layerSpacing+(p-4)*16)});let y=t.disableCorankFanIn?new Map:tU(e,i),m=function(e){let t=new Map;for(let i of e)!function e(i){for(let e of i.nodeIds)t.set(e,i.id);for(let t of i.children)e(t)}(i);return t}(e.subgraphs),x=function(e){let t=new Map;for(let i of e)!function e(i,n){for(let e of i.nodeIds)t.set(e,n);for(let t of i.children)e(t,n)}(i,i.id);return t}(e.subgraphs),b=function(e){let t=new Map;for(let i of e)!function e(i,n){let r=[...n,i.id];for(let e of i.nodeIds)t.set(e,r);for(let t of i.children)e(t,r)}(i,[]);return t}(e.subgraphs),w=function(e){let t=new Map;for(let i of e)!function e(i,n){for(let r of(t.set(i.id,n),i.children))e(r,i.id)}(i,void 0);return t}(e.subgraphs),M=function(e){let t=new Map;for(let i of e)!function e(i,n){let r=[...n,i.id];for(let n of(t.set(i.id,r),i.children))e(n,r)}(i,[]);return t}(e.subgraphs),v=e=>m.get(e)??w.get(e),S=e=>b.get(e)??M.get(e)?.slice(0,-1)??[],k=t2(e,t),E=function(e,t){let i=d(e),n=new Set,r=new Set,o=function(e){let t=new Set,i=(e,n)=>{let r=n||void 0!==e.direction;if(r)for(let i of e.nodeIds)t.add(i);for(let t of e.children)i(t,r)};for(let t of e)i(t,!1);return t}(e.subgraphs),a=new Set;for(let t=0;t<e.edges.length;t++){let o=e.edges[t],s=i[t]??"primary-forward";"primary-forward"===s&&o.label&&a.add(`${o.source}\0${o.target}`),"primary-forward"!==s&&(n.add(o.source),n.add(o.target)),"primary-forward"!==s&&"feedback"!==s&&(r.add(o.source),r.add(o.target))}let s=[],l=[],h=e=>e.replace(/[^A-Za-z0-9_\-]/g,"_"),g=(e,t,i)=>{l.push({edgeIndex:e,routeClass:t,reason:i})};for(let l=0;l<e.edges.length;l++){let d=e.edges[l],u=i[l]??"primary-forward";if(d.source===d.target){g(l,u,"self-loop");continue}if(t.has(d.source)||t.has(d.target)){g(l,u,"subgraph-endpoint");continue}if(!e.nodes.has(d.source)||!e.nodes.has(d.target)){g(l,u,"missing-node");continue}if("primary-forward"!==u&&"feedback"!==u){g(l,u,"unsupported-route-class");continue}if("primary-forward"===u&&(n.has(d.source)||n.has(d.target))){g(l,u,"unsafe-non-primary-incident");continue}if("feedback"===u&&d.label){g(l,u,"unsupported-route-class");continue}if("feedback"===u&&a.has(`${d.target}\0${d.source}`)){g(l,u,"labeled-reciprocal-primary");continue}if("feedback"===u&&(!tQ(e.nodes.get(d.source))||!tQ(e.nodes.get(d.target)))){g(l,u,"unsupported-shape");continue}if(r.has(d.source)||r.has(d.target)){g(l,u,"unsafe-non-primary-incident");continue}if(o.has(d.source)||o.has(d.target)){g(l,u,"direction-override-node");continue}let f=function(e,t){let i=function(e){switch(e){case"RL":return{source:"W",target:"E"};case"BT":return{source:"N",target:"S"};case"TD":case"TB":return{source:"S",target:"N"};default:return{source:"E",target:"W"}}}(e);return"feedback"===t?{source:i.target,target:i.source}:i}(e.direction,u);s.push({nodeId:d.source,portId:`rp_${h(d.source)}_${l}_s`,side:f.source,edgeIndex:l,sourceId:d.source,targetId:d.target,endpoint:"source",slotIndex:0,routeClass:u,labeled:!!d.label,constraint:"FIXED_SIDE"}),s.push({nodeId:d.target,portId:`rp_${h(d.target)}_${l}_t`,side:f.target,edgeIndex:l,sourceId:d.source,targetId:d.target,endpoint:"target",slotIndex:0,routeClass:u,labeled:!!d.label,constraint:"FIXED_SIDE"})}let u=new Map;for(let e of s){let t=u.get(e.nodeId)??[];t.push(e),u.set(e.nodeId,t)}for(let t of u.values()){var f;t.sort((e,t)=>tJ(e.side)-tJ(t.side)||e.edgeIndex-t.edgeIndex||tZ(e.endpoint)-tZ(t.endpoint));let i=new Map;for(let e of t){let t=i.get(e.side)??0;e.slotIndex=t,i.set(e.side,t+1)}let n=(f=e.nodes.get(t[0].nodeId),f?.shape==="rectangle"&&function(e){if(e.length<2||!e.every(e=>"primary-forward"===e.routeClass&&!e.labeled))return!1;let t=e[0].side;if(!e.every(e=>e.side===t))return!1;let i=new Map;for(let t of e){let e=`${t.sourceId}\0${t.targetId}`;i.set(e,(i.get(e)??0)+1)}return!![...i.values()].some(e=>e>=2)&&(!!e.every(e=>"target"===e.endpoint)||!!e.every(e=>"source"===e.endpoint)&&e.every(e=>(i.get(`${e.sourceId}\0${e.targetId}`)??0)>=2))}(t));for(let e of t)n?(e.constraint="FIXED_ORDER",e.orderReason="primary-duplicate-face"):(e.constraint="FIXED_SIDE",e.orderReason=void 0)}let c=new Map;for(let e of s)c.set(tK(e.edgeIndex,e.endpoint),e);return{byEndpoint:c,byNode:u,relaxations:l}}(e,f),N=new Map,P=new Map,C,R=t=>{C??=new Set([...e.nodes.keys(),...f,...[...E.byEndpoint.values()].map(e=>e.portId)]);let i=t;for(;C.has(i);)i+="_";return C.add(i),i},I=(e,t,i)=>{let n=R(`${e}_${i}_${t}`),r=N.get(e)??[];return r.push({id:n,direction:i}),N.set(e,r),n},L=(e,t)=>{let n=f.has(e.source)&&S(e.target).includes(e.source),r=f.has(e.target)&&S(e.source).includes(e.target),o=n?M.get(e.source):S(e.source),a=r?M.get(e.target):S(e.target),s=t4(o,a),l=s?o.indexOf(s)+1:0,d=n?I(e.source,t,"in"):E.byEndpoint.get(tK(t,"source"))?.portId??e.source,h=r?I(e.target,t,"out"):E.byEndpoint.get(tK(t,"target"))?.portId??e.target,g=0,u=(n,r,o,a=!1)=>{let s=a?function(e,t,i,n,r,o){let a={id:`e${e}`,sources:[i],targets:[n]};if(t.label&&!eO("APL_DECOUPLE_LABELS")){let e=F(tn(t.label,t.labelContent),r,"edge");a.labels=[{text:e.text,width:e.width+8,height:e.height+6,layoutOptions:{"elk.edgeLabels.inline":"true","elk.edgeLabels.placement":"CENTER"}}]}else!t.label&&o?.has(e)&&(a.labels=[tY(o.get(e))]);return a}(t,e,r,o,i,y):{id:`e${t}_internal_${g}`,sources:[r],targets:[o]},l={...s,id:R(s.id),hierarchySegment:{edgeIndex:t,order:g++}},d=P.get(n??null)??[];d.push(l),P.set(n??null,d)};for(let e of o.slice(l).reverse()){let i=I(e,t,"out");u(e,d,i),d=i}let c=a.slice(l).map(e=>({scope:e,port:I(e,t,"in")}));u(s,d,c[0]?.port??h,!0);for(let e=0;e<c.length;e++){let t=c[e];u(t.scope,t.port,c[e+1]?.port??h)}},O=new Map;O.set(null,[]);for(let t=0;t<e.edges.length;t++){let i=e.edges[t],n=v(i.source),r=v(i.target);if(n&&n===r)O.has(n)||O.set(n,[]),O.get(n).push({index:t,edge:i});else if(n||r)if(k)L(i,t);else{let e=t4(S(i.source),S(i.target));e?(O.has(e)||O.set(e,[]),O.get(e).push({index:t,edge:i})):O.get(null).push({index:t,edge:i})}else O.get(null).push({index:t,edge:i})}let $={id:"root",layoutOptions:{"elk.algorithm":"layered","elk.direction":te(e.direction),"elk.spacing.nodeNode":String(t.nodeSpacing),"elk.layered.spacing.nodeNodeBetweenLayers":String(t.layerSpacing),"elk.spacing.edgeEdge":"12","elk.layered.spacing.edgeEdgeBetweenLayers":"12","elk.layered.spacing.edgeNodeBetweenLayers":"12","elk.padding":`[top=${t.padding},left=${t.padding},bottom=${t.padding},right=${t.padding}]`,"elk.edgeRouting":"ORTHOGONAL","elk.layered.nodePlacement.bk.fixedAlignment":"BALANCED","elk.contentAlignment":"H_CENTER V_CENTER","elk.layered.thoroughness":String(eW.thoroughness),"elk.layered.highDegreeNodes.treatment":"true","elk.layered.highDegreeNodes.threshold":"8","elk.layered.compaction.postCompaction.strategy":"LEFT_RIGHT_CONSTRAINT_LOCKING","elk.layered.considerModelOrder.strategy":"NODES_AND_EDGES","elk.layered.cycleBreaking.strategy":"MODEL_ORDER","elk.layered.feedbackEdges":"true","elk.layered.crossingMinimization.forceNodeModelOrder":"true","elk.layered.wrapping.strategy":"OFF","elk.hierarchyHandling":k?"SEPARATE":"INCLUDE_CHILDREN"},children:[],edges:[]},z=!t.preserveSubgraphChildOrder,A=new Map(e.subgraphs.map(e=>[e.id,e]));for(let d of(n=!!t.preserveSubgraphChildOrder,r=[],o=new Set,a=e=>{o.has(e)||(o.add(e),r.push(e))},s=()=>{for(let t of e.nodes.keys()){let e=x.get(t);e?a(e):u.has(t)||f.has(t)||a(t)}},l=()=>{for(let t of e.subgraphs)a(t.id)},n?(l(),s()):(s(),l()),tV(r,e.edges.map(e=>({source:x.get(e.source)??e.source,target:x.get(e.target)??e.target}))))){let n=A.get(d);if(n){$.children.push(function e(t,i,n,r,o,a,s,l,d,h,g,u="TB"){let f=t6(t,r),c=t.concurrencyRegion?n.stateVisual?.dividerMargin??0:0,p=t.direction??u,y={"elk.algorithm":"layered","elk.padding":`[top=${f+r.groupPaddingY+c},left=${r.groupPaddingX+c},bottom=${r.groupPaddingY+c},right=${r.groupPaddingX+c}]`,"elk.edgeRouting":"ORTHOGONAL","elk.contentAlignment":"H_CENTER V_CENTER","elk.spacing.edgeEdge":"12","elk.layered.spacing.edgeEdgeBetweenLayers":"12","elk.layered.spacing.edgeNodeBetweenLayers":"12","elk.layered.nodePlacement.bk.fixedAlignment":"BALANCED","elk.layered.spacing.nodeNodeBetweenLayers":String(n.layerSpacing),"elk.spacing.nodeNode":String(n.nodeSpacing)};(t.direction||g)&&(y["elk.direction"]=te(p));let m=t5(t,r);m>0&&g&&(y["elk.nodeSize.constraints"]="MINIMUM_SIZE",y["elk.nodeSize.minimum"]=`(${m}, 0)`);let x={id:t.id,layoutOptions:y,labels:t.label?[{text:t.label}]:void 0,children:[],edges:[],...void 0!==t.headerMinHeight&&0===t.nodeIds.length&&0===t.children.length?{width:Math.max(m,2*r.groupPaddingX),height:f+2*r.groupPaddingY}:{}},b=a.get(t.id)??[];if(b.length>0){let e=f>0,t=eS(i.direction);x.ports=b.map(i=>{let n="in"===i.direction?t.targetSide:t.sourceSide,r="N"===n?"in"===i.direction?"W":"E":n;return{id:i.id,...e&&("N"===n||"BT"===p)?{layoutOptions:{"elk.port.side":t0(r)}}:{}}}),e&&(x.layoutOptions["elk.portConstraints"]="FIXED_SIDE")}for(let e of d?tV(t.nodeIds,i.edges):t.nodeIds){let t=i.nodes.get(e);t&&x.children.push(t1(e,t,r,l,p,n.stateVisual,n.nodeSizes?.get(e),n.markerPortExtents?.get(e)))}for(let u of t.children)x.children.push(e(u,i,n,r,o,a,s,l,d,h,g,p));for(let{index:e,edge:i}of o.get(t.id)??[]){let t={id:`e${e}`,sources:[l.byEndpoint.get(tK(e,"source"))?.portId??i.source],targets:[l.byEndpoint.get(tK(e,"target"))?.portId??i.target]};if(i.label&&!eO("APL_DECOUPLE_LABELS")){let e=F(tn(i.label,i.labelContent),r,"edge");t.labels=[{text:e.text,width:e.width+8,height:e.height+6,layoutOptions:{"elk.edgeLabels.inline":"true","elk.edgeLabels.placement":"CENTER"}}]}else!i.label&&h.has(e)&&(t.labels=[tY(h.get(e))]);x.edges.push(t)}for(let e of s.get(t.id)??[])x.edges.push(e);return x}(n,e,t,i,O,N,P,E,z,y,k,e.direction));continue}let r=e.nodes.get(d);!r||u.has(d)||f.has(d)||$.children.push(t1(d,r,i,E,e.direction,t.stateVisual,t.nodeSizes?.get(d),t.markerPortExtents?.get(d)))}for(let{index:e,edge:t}of O.get(null)){let n={id:`e${e}`,sources:[E.byEndpoint.get(tK(e,"source"))?.portId??t.source],targets:[E.byEndpoint.get(tK(e,"target"))?.portId??t.target]};if(t.label&&!eO("APL_DECOUPLE_LABELS")){let e=F(tn(t.label,t.labelContent),i,"edge");n.labels=[{text:e.text,width:e.width+8,height:e.height+6,layoutOptions:{"elk.edgeLabels.inline":"true","elk.edgeLabels.placement":"CENTER"}}]}else!t.label&&y.has(e)&&(n.labels=[tY(y.get(e))]);$.edges.push(n)}for(let e of P.get(null)??[])$.edges.push(e);return function(e,t,i){if(!i)return;let n=new Map,r=e=>{for(let t of e.children??[])n.set(t.id,{node:t,parent:e}),r(t)};r(e);let o=e=>{let i=n.get(e);return i&&t.nodes.has(e)||tr(`unknown node "${e}"`),i},a=new Set;if(i.ranks)for(let[e,t]of Object.entries(i.ranks)){let{node:i,parent:n}=o(e);(!Number.isSafeInteger(t)||t<0||t>1e4)&&tr(`rank for "${e}" must be an integer in [0,10000]`),a.add(n),n.layoutOptions={...n.layoutOptions,"elk.partitioning.activate":"true"},i.layoutOptions={...i.layoutOptions,"elk.partitioning.partition":String(t)}}for(let e of a)for(let t of e.children??[])t.layoutOptions={"elk.partitioning.partition":"0",...t.layoutOptions};let s=new Set;for(let e of i.adjacent??[]){e.length<2&&tr("adjacent needs two or more nodes");let t=e.map(o),i=t[0].parent;for(let n of(t.some(e=>e.parent!==i)&&tr("adjacent nodes need the same container"),e))s.has(n)&&tr("a node cannot repeat in adjacency groups"),s.add(n);let n=i.children,r=Math.min(...t.map(e=>n.indexOf(e.node)));i.children=[...n.slice(0,r),...t.map(e=>e.node),...n.slice(r).filter(t=>!e.includes(t.id))],i.layoutOptions={...i.layoutOptions,"elk.layered.crossingMinimization.forceNodeModelOrder":"true"}}let l=ez(t.edges),d=new Set((i.shortEdges??[]).map(e=>{let t=l.get(e);return void 0===t&&tr(`unknown edge "${e}"`),t})),h=e=>{for(let t of e.edges??[]){let e=/^e(\d+)(?:_|$)/.exec(t.id);e&&d.has(Number(e[1]))&&(t.layoutOptions={...t.layoutOptions,"elk.layered.priority.shortness":"100","elk.layered.priority.direction":"100"})}e.children?.forEach(h)};h(e)}($,e,t.layoutHints),k&&N.size>0&&(h=e=>"RIGHT"===e||"LEFT"===e,(g=e=>{let t=h(e.layoutOptions?.["elk.direction"]),i=!1;for(let n of e.children??[])void 0!==n.children&&(!i&&N.has(n.id)&&(i=h(n.layoutOptions?.["elk.direction"])!==t||(n.ports??[]).some(e=>{let i=e.layoutOptions?.["elk.port.side"];return t?"NORTH"===i||"SOUTH"===i:"EAST"===i||"WEST"===i})),g(n));i&&e.layoutOptions?.["elk.layered.crossingMinimization.forceNodeModelOrder"]==="true"&&(e.layoutOptions["elk.layered.crossingMinimization.forceNodeModelOrder"]="false",e.layoutOptions["elk.layered.considerModelOrder.strategy"]??="NODES_AND_EDGES")})($)),$}function tK(e,t){return`${e}:${t}`}function tQ(e){return e?.shape==="rectangle"||e?.shape==="diamond"}function tJ(e){return({N:0,E:1,S:2,W:3})[e]}function tZ(e){return+("source"!==e)}function t0(e){switch(e){case"N":return"NORTH";case"E":return"EAST";case"S":return"SOUTH";case"W":return"WEST"}}function t1(e,t,i,n,r="TB",o,a,s){let l=a??tG(e,tn(t.label,t.labelContent),t.shape,i,r,o,t.labelBlock),d="LR"===r||"RL"===r,h=d?l.height:l.width;if(!a&&s){let e=Math.max(s.span,Math.min(i.cornerRadius??0,(d?l.width:l.height)/2));if(!(h/(s.count+1)>e)){let t=(s.count+1)*(e+1);Number.isFinite(t)&&t>h&&(h=t)}}let g={id:e,width:d?l.width:h,height:d?h:l.height,labels:[{text:t.label}]},u=n.byNode.get(e);if(u&&u.length>0){let e=u.some(e=>"FIXED_ORDER"===e.constraint)?"FIXED_ORDER":"FIXED_SIDE";g.layoutOptions={...g.layoutOptions??{},"elk.portConstraints":e},g.ports=u.map(e=>({id:e.portId,width:0,height:0,layoutOptions:{"elk.port.side":t0(e.side),"elk.port.index":String(e.slotIndex)}}))}return g}function t2(e,t){let i=e=>void 0!==e.direction||e.children.some(i);return!0===t.separateHierarchy||e.subgraphs.some(i)}function t5(e,t){if(!e.label||e.concurrencyRegion||void 0===e.headerMinHeight&&0===e.nodeIds.length&&0===e.children.length)return 0;let i=F(tn(e.label,e.labelContent),t,"group").width;return Math.ceil((e.titleOffset??t.groupLabelPaddingX)+i+t.groupLabelPaddingX)}function t6(e,t,i=F(tn(e.label,e.labelContent),t,"group")){if(e.concurrencyRegion)return 0;let n=t.groupHeaderFontSize+16+i.height-i.lineHeight;if(void 0===e.headerMinHeight)return n;if(!Number.isFinite(e.headerMinHeight)||e.headerMinHeight<=0)throw RangeError("Invalid internal group header minimum");return Math.max(n,e.headerMinHeight)}function t4(e,t){let i;for(let n=0;n<Math.min(e.length,t.length)&&e[n]===t[n];n++)i=e[n];return i}function t8(e,t=!1){let i=new Set;for(let n of e){if(n.source===n.target||t&&!n.label)continue;let e=JSON.stringify([n.source,n.target]);if(i.has(e))return!0;i.add(e)}return!1}var t3=[{id:"extractEdgesRecursively",after:[],mutates:["extract"],determinism:"pure-order",run:e=>{e.elkResult&&function(e,t,i,n,r,o){let a=new Map,s=new Map,l=(e,t,i)=>{for(let n of(s.set(e.id,{x:t,y:i}),e.children??[]))l(n,t+(n.x??0),i+(n.y??0))};l(e,0,0),function e(t,i,n,r,o){if(t.edges)for(let e of t.edges){let t,a=e.hierarchySegment,s=a?.edgeIndex??parseInt(e.id.substring(1),10);if(isNaN(s))continue;let l=e.container?o.get(e.container):void 0,d=l?.x??n,h=l?.y??r,g=[];if(e.sections&&e.sections.length>0){let t=e.sections[0];if(g.push({x:t.startPoint.x+d,y:t.startPoint.y+h}),t.bendPoints)for(let e of t.bendPoints)g.push({x:e.x+d,y:e.y+h});g.push({x:t.endPoint.x+d,y:t.endPoint.y+h})}if(e.labels&&e.labels.length>0){let i=e.labels[0];null!=i.x&&null!=i.y&&(t={x:i.x+(i.width??0)/2+d,y:i.y+(i.height??0)/2+h})}let u=i.get(s)??[];u.push({order:a?.order??0,points:g,labelPosition:t}),i.set(s,u)}if(t.children)for(let a of t.children)e(a,i,n+(a.x??0),r+(a.y??0),o)}(e,a,0,0,s);let d=0;for(let[e,n]of a){let r,a=t.edges[e];if(!a)continue;let s=[];for(let e of n.sort((e,t)=>e.order-t.order)){let t=s.at(-1),i=e.points[0],n=e.points[1],r=t&&i&&1e-6>Math.abs(t.x-i.x)&&1e-6>Math.abs(t.y-i.y),o=t&&i&&n&&(t.x===i.x&&i.x===n.x&&i.y>=Math.min(t.y,n.y)&&i.y<=Math.max(t.y,n.y)||t.y===i.y&&i.y===n.y&&i.x>=Math.min(t.x,n.x)&&i.x<=Math.max(t.x,n.x));s.push(...r||o?e.points.slice(1):e.points)}a.label&&s.length>=2&&(r=n.find(e=>e.labelPosition)?.labelPosition??ev(s));let l=function(e,t,i=0){if(e.length<2)return e;let n=!1;for(let t=1;t<e.length;t++){let i=Math.abs(e[t].x-e[t-1].x),r=Math.abs(e[t].y-e[t-1].y);if(i>1&&r>1){n=!0;break}}if(!n)return e;let r=[e[0]];for(let n=1;n<e.length;n++){let o=r[r.length-1],a=e[n],s=Math.abs(a.x-o.x),l=Math.abs(a.y-o.y);if(s>1&&l>1)if(t){let e=i%2==0,n=12*Math.floor(i/2),s=e?t.rightX+n:t.leftX-n;r.push({x:s,y:o.y}),r.push({x:s,y:a.y})}else{let e=(o.y+a.y)/2;r.push({x:o.x,y:e}),r.push({x:a.x,y:e})}r.push(a)}return r}(s,o,d);l!==s&&d++,a.label&&l!==s&&l.length>=2&&(r=ev(l)),i.push({source:a.source,target:a.target,...void 0!==a.id?{id:a.id}:{},label:a.label,...a.labelContent?{labelContent:a.labelContent}:{},style:a.style,hasArrowStart:a.hasArrowStart,hasArrowEnd:a.hasArrowEnd,startMarker:a.startMarker,endMarker:a.endMarker,...a.curve?{curve:a.curve}:{},...a.animate?{animate:!0}:{},...a.animation?{animation:a.animation}:{},points:l,labelPosition:r,inlineStyle:eU(e,t),...a.id&&t.classAssignments.has(a.id)?{classNames:t.classAssignments.get(a.id).split(/\s+/).filter(Boolean)}:{},edgeIndex:e})}}(e.elkResult,e.graph,e.edges,0,0,e.margins),t9(e,e.style)}},{id:"alignLayerNodes",after:["extractEdgesRecursively"],mutates:["positions","edges"],determinism:"in-place",enabled:e=>!!e.elkResult||e.mergeEdges,mayChangeMetrics:{bends:"improve-only",straight:"improve-only"},run:e=>{!function(e,t,i){if(0===e.length)return;let n="LR"===i||"RL"===i,r=new Set,o=new Map;for(let e of t)for(let t of(r.add(`${e.source}:${e.target}`),r.add(`${e.target}:${e.source}`),new Set([e.source,e.target]))){let i=o.get(t)??[];i.push(e),o.set(t,i)}let a=new Map(e.map(e=>[e.id,e])),s=.6*eW.layerSpacing,l=[...e].sort((e,t)=>n?e.x-t.x:e.y-t.y),d=[],h=[l[0]];for(let e=1;e<l.length;e++){let t=(n?l[e].x:l[e].y)-(n?l[e-1].x:l[e-1].y),i=h.some(t=>r.has(`${t.id}:${l[e].id}`));t<=s&&!i?h.push(l[e]):(d.push(h),h=[l[e]])}d.push(h);let g=new Map,u=(e,i)=>{let r=n?i:e.x,o=n?e.y:i;for(let i of t)if(i.source!==e.id&&i.target!==e.id)for(let t=1;t<i.points.length;t++){let n=i.points[t-1],a=i.points[t],s=Math.min(n.x,a.x),l=Math.max(n.x,a.x),d=Math.min(n.y,a.y),h=Math.max(n.y,a.y);if(l>r+.5&&s<r+e.width-.5&&h>o+.5&&d<o+e.height-.5)return!0}return!1};for(let e of d){if(e.length<=1)continue;let t=e.map(e=>n?e.x:e.y),i=Math.min(...t),r=Math.max(...t);if(r-i<=1)continue;let s=(i+r)/2;if(e.some(e=>Math.abs(s-(n?e.x:e.y))>.5&&u(e,s)))continue;let l=new Map(e.flatMap(e=>{let t=s-(n?e.x:e.y);return Math.abs(t)>.5?[[e.id,t]]:[]})),d=new Map(e.map(e=>[e.id,{...e,...n?{x:e.x+(l.get(e.id)??0)}:{y:e.y+(l.get(e.id)??0)}}])),h=new Set,f=!1;for(let e of l.keys())for(let t of o.get(e)??[]){if(h.has(t)||"invisible"===t.style)continue;h.add(t);let e={...t,points:tW(t.points,n,g.get(t.source),g.get(t.target))},i={...t,points:tW(t.points,n,l.get(t.source)??g.get(t.source),l.get(t.target)??g.get(t.target))},r,o;for(let n of[!0,!1]){let s=n?t.source:t.target,l=a.get(s),h=d.get(s)??l,g=tD(e.points,l,n),u;!0===g?u=tD(i.points,h,n):(r??=tH(e,a.get(t.source),a.get(t.target)),o??=tH(i,d.get(t.source)??a.get(t.source),d.get(t.target)??a.get(t.target)),g=tD(r.points,l,n),u=tD(o.points,h,n)),!0===g&&!0!==u&&(f=!0)}}if(!f)for(let t of e){let e=s-(n?t.x:t.y);Math.abs(e)>.5&&(n?t.x=s:t.y=s,g.set(t.id,e))}}if(0!==g.size)for(let e of t)e.points=tW(e.points,n,g.get(e.source),g.get(e.target))}(e.nodes,e.edges,e.graph.direction)}},{id:"equalizePeerNodeDimensions",after:["alignLayerNodes"],mutates:["positions","dimensions"],determinism:"in-place",enabled:e=>!!e.elkResult||e.mergeEdges,run:e=>{!function(e,t,i,n,r){let o=eb(n.edges),a=new Map(e.map(e=>[e.id,e])),s=new Map,l=new Map;for(let e of t)H(e,a,n.direction)&&(s.has(e.target)||s.set(e.target,[]),s.get(e.target).push(e),l.has(e.source)||l.set(e.source,[]),l.get(e.source).push(e));let d=[],h=e=>{if(e.length<2||e.length>5||!e.every(e=>"rectangle"===e.shape)||e.some(e=>G(e,i))||!W(e,n.direction))return;let t=e.map(e=>e.id).sort().join("\0");d.some(e=>e.map(e=>e.id).sort().join("\0")===t)||d.push(e)};for(let e of s.values()){let i=e[0]?.target,n=e.map(e=>a.get(e.source)).filter(Boolean);i&&n.every(e=>t.every(t=>t.source!==e.id||t.target===i))&&h(n)}for(let e of l.values()){let i=e[0]?.source,n=e.map(e=>a.get(e.target)).filter(Boolean);if(!i||!n.every(e=>t.every(t=>t.target!==e.id||t.source===i)&&t.every(t=>t.source!==e.id)))continue;let r=!0;for(let e=0;e<n.length;e++)for(let t=0;t<n.length;t++)e!==t&&o(n[e].id,n[t].id)&&(r=!1);r&&h(n)}let g=!1,u,f=eS(n.direction);for(let t of d){let i=Math.max(...t.map(e=>e.width)),r=Math.max(...t.map(e=>e.height));if(t.every(e=>.5>Math.abs(e.width-i)&&.5>Math.abs(e.height-r)))continue;u??=e.map(e=>({...e}));let o=[...t].sort((e,t)=>eE(e,n.direction)-eE(t,n.direction)),a=Math.min(...o.map(e=>eE(e,n.direction))),l=Math.min(...o.map(e=>ek(e,n.direction))),d=[];for(let e of o)d.push({node:e,x:f.isHorizontal?l:a,y:f.isHorizontal?a:l}),a+=(f.isHorizontal?r:i)+24;let h=new Set(t.map(e=>e.id)),c=(e,t,i,n)=>e<n-.01&&i<t-.01,p=e=>{let t=f.isHorizontal?e.x:e.y;return[t,t+(f.isHorizontal?e.width:e.height)]},y=e=>{let t=f.isHorizontal?e.y:e.x;return[t,t+(f.isHorizontal?e.height:e.width)]},m=d.map(({node:e,x:t,y:n})=>({id:e.id,x:t,y:n,width:i,height:r,orig:p(e)})),x=0,b=new Set;for(let t of m){let[i,n]=p(t),[r,o]=y(t),[a,s]=t.orig;for(let t of e){if(h.has(t.id))continue;let[e,l]=p(t),[d,g]=y(t);c(i,n,e,l)&&!c(a,s,e,l)&&c(r,o,d,g)&&(b.add(t.id),x=Math.max(x,n+24-e))}}let w=new Set,M=e=>{if(!(w.has(e)||h.has(e)))for(let t of(w.add(e),s.get(e)??[]))M(t.source)};for(let e of b)M(e);let v=e.filter(e=>w.has(e.id)),S=new Map(v.map(e=>[e.id,p(e)])),k=[...t,...v].map(e=>({n:e,x:e.x,y:e.y,w:e.width,h:e.height}));if(x>0)for(let e of v)e[f.main]+=x;for(let{node:e,x:t,y:n}of d)e.x=t,e.y=n,e.width=i,e.height=r;let E=new Set([...h,...w]);if([...t,...v].some(t=>{let[i,n]=p(t),[r,o]=y(t),[a,s]=S.get(t.id)??m.find(e=>e.id===t.id).orig;return e.some(e=>{if(E.has(e.id))return!1;let[t,l]=p(e),[d,h]=y(e);return c(i,n,t,l)&&!c(a,s,t,l)&&c(r,o,d,h)})})){for(let e of k)e.n.x=e.x,e.n.y=e.y,e.n.width=e.w,e.n.height=e.h;continue}g=!0}g&&(X(e,n.direction),function(e,t,i,n,r){let o=(e,t)=>Math.min(e.x1,t.x1)-Math.max(e.x0,t.x0)>1e-6&&Math.min(e.y1,t.y1)-Math.max(e.y0,t.y0)>1e-6,a=e=>({x0:e.x,y0:e.y,x1:e.x+e.width,y1:e.y+e.height}),s=new Map(e.map(e=>[e.id,e])),l=new Map(t.map(e=>[e.id,e])),d=i.flatMap(e=>{let t=Z(e,r);if(!t)return[];let i=Math.max(4,r.lineWidth*("thick"===e.style?2:1)*2);return[{x0:t.x-i,y0:t.y-i,x1:t.x+t.w+i,y1:t.y+t.h+i}]});for(let i of d)if(t.some((t,n)=>o(i,a(t))&&!o(i,a(e[n]))))return!1;for(let h of i){let i=j(h,r);if(0===i.length)continue;let g=h.points,u=l.get(h.source),f=l.get(h.target);u&&(g=el(g,u,!0)),f&&(g=el(g,f,!1));let c={...h,points:g};for(let e of(ed(t,[c],n),g=c.points,[!0,!1])){if(!(e?h.hasArrowStart:h.hasArrowEnd))continue;let t=e?h.source:h.target,i=s.get(t),n=l.get(t),r=e?h.points:[...h.points].reverse(),o=e?g:[...g].reverse(),a=r[0],d=o[0],u=a&&r.find(e=>e.x!==a.x||e.y!==a.y),f=d&&o.find(e=>e.x!==d.x||e.y!==d.y);if(i&&a&&u&&!0===ea(i,a,u)&&(!n||!d||!f||!0!==ea(n,d,f)))return!1}let p=j(c,r);for(let n=0;n<i.length;n++){let r=i[n],s=p[n];if(!r.bounds)continue;if(!s?.bounds)return!1;let l="start"===s.position?h.source:h.target;if(t.some((t,i)=>t.id!==l&&o(s.bounds,a(t))&&!o(r.bounds,a(e[i])))||d.some(e=>o(e,s.bounds)&&!o(e,r.bounds)))return!1}}return!0}(u,e,t,n,r)||e.forEach((e,t)=>{let i=u[t];e.x=i.x,e.y=i.y,e.width=i.width,e.height=i.height}))}(e.nodes,e.edges,e.groups,e.graph,e.style)}},{id:"alignForkRejoinPeerCenters",after:["equalizePeerNodeDimensions"],mutates:["positions"],determinism:"in-place",mayChangeMetrics:{symErr:"improve-only",bends:{worsenBy:2}},enabled:e=>!!e.elkResult||e.mergeEdges,run:e=>{!function(e,t,i,n,r){let o=eb(n.edges),a=new Map(e.map(e=>[e.id,e])),s=new Map;for(let e of t)H(e,a,n.direction)&&(s.has(e.source)||s.set(e.source,[]),s.get(e.source).push(e));let l=e=>t.filter(t=>t.target===e&&H(t,a,n.direction)).length,d=e=>t.filter(t=>t.source===e&&t.target!==e&&H(t,a,n.direction)),h=(e,t)=>{let i=[],n=new Set(t),r=[e];for(;r.length>0;){let e=r.shift();if(!n.has(e.id))for(let t of(n.add(e.id),i.push(e),d(e.id))){let e=a.get(t.target);!e||n.has(e.id)||1===l(e.id)&&r.push(e)}}return i};for(let[l,g]of s){if(3!==g.length)continue;let s=a.get(l);if(!s||"diamond"!==s.shape||G(s,i))continue;let u=[...g].sort((e,t)=>eC(a.get(e.target),n.direction)-eC(a.get(t.target),n.direction)),f=u.map(e=>a.get(e.target)).filter(e=>!!e);if(f.length!==u.length||!f.every(e=>"rectangle"===e.shape&&!G(e,i))||!W(f,n.direction,28))continue;let c=!0;for(let e=0;e<f.length;e++)for(let t=0;t<f.length;t++)e!==t&&o(f[e].id,f[t].id)&&(c=!1);if(!c)continue;let p=f.map(e=>d(e.id));if(!p.every(e=>1===e.length))continue;let y=p[0][0].target;if(!p.every(e=>e[0].target===y))continue;let m=a.get(y);if(!m||G(m,i))continue;let x=new Set(f.map(e=>e.id));for(let e of h(m,x))x.add(e.id);if([...x].some(e=>{let t=a.get(e);return!t||G(t,i)}))continue;let b=(eC(f[0],n.direction)+eC(f[f.length-1],n.direction))/2,w=eC(s,n.direction)-b;.5>=Math.abs(w)||es(x,e,t,n.direction,w,r)&&(e$("[fork-rejoin] center",s.id,"peer island by",w.toFixed(1)),eo(x,e,t,n.direction,w))}}(e.nodes,e.edges,e.groups,e.graph,e.style)}},{id:"alignPortLanes",after:["alignForkRejoinPeerCenters"],mutates:["positions","edges"],determinism:"in-place",enabled:e=>!!e.elkResult,mayChangeMetrics:{straight:"improve-only",portRate:"improve-only",bends:"improve-only"},run:e=>{!function(e,t,i,n,r){if(!tI(e,t,i))return;let{nodes:o,edges:a}=tz(e,t);!function(e,t,i,n,r){let o="LR"===n||"RL"===n,a=o?"y":"x",s=o?"x":"y",l="LR"===n||"TD"===n?1:-1,d=new Set,g=e=>o?e.height:e.width,u=e=>e[a]+g(e)/2,f=new Map(e.map(e=>[e.id,e])),c=[],p=e=>{for(let t of e)c.push(t),p(t.children)};p(i);let y=e=>c.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),m=(e,t,i,n,r,o,a,s)=>e<r+a&&e+i>r&&t<o+s&&t+n>o,x=e=>o?e.width:e.height,b=(t,i,n,r)=>e.some(e=>!r.has(e.id)&&t>e[a]-4&&t<e[a]+g(e)+4&&n>e[s]-4&&i<e[s]+x(e)+4),w=(t,i,n,r)=>e.some(e=>!r.has(e.id)&&t>e[s]-4&&t<e[s]+x(e)+4&&n>e[a]-4&&i<e[a]+g(e)+4),M=(e,t)=>{let i=t?e.length-1:0,n=t?-1:1,r=e[i][a],o=i;for(;o>=0&&o<e.length&&.5>=Math.abs(e[o][a]-r);)o+=n;if(o<0||o>=e.length)return null;let l=e[o],d=e[o-n];return{mainPos:l[s],far:l[a],orthogonal:.5>=Math.abs(l[s]-d[s])}},v=(e,t)=>{let i=t?e.length-1:0,n=t?-1:1,r=e[i][a],o=1/0,l=-1/0;for(let t=i;t>=0&&t<e.length&&!(Math.abs(e[t][a]-r)>.5);t+=n)o=Math.min(o,e[t][s]),l=Math.max(l,e[t][s]);return{ref:r,lo:o,hi:l}},S=(e,t,i,n,r=!1)=>{let o=e.points,s=t?o.length-1:0,l=t?-1:1,d=t?0:o.length-1,h=o[s][a],g=1/0,u=-1/0;for(let e=s;e>=0&&e<o.length&&.5>=Math.abs(o[e][a]-h)&&!(r&&e===d);e+=l)g=Math.min(g,e),u=Math.max(u,e);if(u<g)return!1;let f=e=>e>=g&&e<=u?{...o[e],[a]:o[e][a]+i}:o[e];for(let e=Math.max(1,g);e<=Math.min(o.length-1,u+1);e++)if(O(f(e-1),f(e),n))return!0;return!1},k=(i,n,l,h=!1)=>{if(d.has(i.id)||y(i))return!1;let g=f.get(l.source),c=f.get(l.target);if(b(u(i.id===l.source?c:g),Math.min(g[s]+x(g)/2,c[s]+x(c)/2),Math.max(g[s]+x(g)/2,c[s]+x(c)/2),new Set([l.source,l.target])))return!1;for(let e of t){let t=e.source===i.id,r=e.target===i.id;if(!t&&!r)continue;let o=e===l;if(o&&2===e.points.length&&.5>=Math.abs(e.points[0][a]-e.points[1][a]))continue;if(!o){if(e.points.length<3)return!1;let t=r?e.points[e.points.length-1]:e.points[0];if(!e.points.some(e=>Math.abs(e[a]-t[a])>.5))return!1}let s=new Set([e.source,e.target]),d=v(e.points,r);if(b(d.ref+n,d.lo,d.hi,s))return!1;let g=M(e.points,r);if(g){if(!g.orthogonal)return!1;let e=Math.min(d.ref+n,g.far),t=Math.max(d.ref+n,g.far);if(w(g.mainPos,e,t,s))return!1}let u=f.get(r?e.source:e.target);if(u&&u!==i&&!(o&&h)&&S(e,r,n,u))return!1}let p=o?i.x:i.x+n,k=o?i.y+n:i.y;for(let t of e)if(t!==i&&m(p-8,k-8,i.width+16,i.height+16,t.x,t.y,t.width,t.height))return!1;for(let e of t)if(e.source!==i.id&&e.target!==i.id)for(let t=1;t<e.points.length;t++){let n=e.points[t-1],r=e.points[t];if(Math.max(n.x,r.x)>p+.5&&Math.min(n.x,r.x)<p+i.width-.5&&Math.max(n.y,r.y)>k+.5&&Math.min(n.y,r.y)<k+i.height-.5)return!1}for(let e of t){if(e===l)continue;let t=Z(e,r);if(t&&m(p-8,k-8,i.width+16,i.height+16,t.x,t.y,t.w,t.h))return!1}return!0},E=(e,t,i,n=!1)=>{let r=e.points,o=t?r.length-1:0,l=t?-1:1,d=t?0:r.length-1,h=r[o][a],g=1/0,u=-1/0;for(let e=o;e>=0&&e<r.length&&!(Math.abs(r[e][a]-h)>.5||n&&e===d);e+=l)g=Math.min(g,r[e][s]),u=Math.max(u,r[e][s]),r[e][a]+=i;e.labelPosition&&12>=Math.abs(e.labelPosition[a]-h)&&e.labelPosition[s]>=g-.5&&e.labelPosition[s]<=u+.5&&(e.labelPosition[a]+=i)},N=(e,i,n)=>{for(let r of(o?e.y+=i:e.x+=i,t)){if(r===n||0===r.points.length)continue;let t=r.source===e.id,o=r.target===e.id;if(t&&o){for(let e of r.points)e[a]+=i;r.labelPosition&&(r.labelPosition[a]+=i);continue}o&&E(r,!0,i),t&&E(r,!1,i)}let r=n.points[0],s=n.points[n.points.length-1];2===n.points.length&&.5>=Math.abs(r[a]-s[a])?(n.points=[em(f.get(n.source))[o?l>0?"E":"W":l>0?"S":"N"],em(f.get(n.target))[o?l>0?"W":"E":l>0?"N":"S"]],n.labelPosition&&(n.labelPosition[a]=u(f.get(n.source)))):E(n,n.target===e.id,i)},P=e=>{if(e.points.length<2||e.source===e.target)return!1;let t=h(e.points);for(let e=1;e<t.length;e++)if((t[e][s]-t[e-1][s])*l<-.5)return!1;return!0},C=(i,n,a)=>{let s=o?i.x:i.x+n,l=o?i.y+n:i.y;for(let t of e)if(t!==i&&m(s-8,l-8,i.width+16,i.height+16,t.x,t.y,t.width,t.height))return!1;for(let e of t)if(!a.has(`${e.source}->${e.target}`))for(let t=1;t<e.points.length;t++){let n=e.points[t-1],r=e.points[t];if(Math.max(n.x,r.x)>s+.5&&Math.min(n.x,r.x)<s+i.width-.5&&Math.max(n.y,r.y)>l+.5&&Math.min(n.y,r.y)<l+i.height-.5)return!1}for(let e of t){if(a.has(`${e.source}->${e.target}`))continue;let t=Z(e,r);if(t&&m(s-8,l-8,i.width+16,i.height+16,t.x,t.y,t.w,t.h))return!1}return!0},R=new Set,I=e=>t.filter(t=>t.source===e&&P(t)),L=e=>t.filter(t=>t.target===e&&P(t)).length,$=e=>{let t=[],i=new Set,n=[e];for(;n.length>0;){let e=n.shift();if(!i.has(e.id))for(let r of(i.add(e.id),t.push(e),I(e.id))){let e=f.get(r.target);!e||i.has(e.id)||1===L(e.id)&&n.push(e)}}return t},z=e=>2===e.points.length&&Number(e2(e.points[0][a]))===Number(e2(e.points[1][a]))&&Number(e2(e.points[0][s]))!==Number(e2(e.points[1][s])),A=(e,t,i)=>{if(e.routeCertificate)return;let n=f.get(e.source),r=f.get(e.target);if(!n||!r)return;let d=t.has(n.id)?{...n,[a]:n[a]+i}:n,h=t.has(r.id)?{...r,[a]:r[a]+i}:r,g=em(d)[o?l>0?"E":"W":l>0?"S":"N"],u=em(h)[o?l>0?"W":"E":l>0?"N":"S"];if(!(![g.x,g.y,u.x,u.y].every(Number.isFinite)||Number(e2(g[a]))!==Number(e2(u[a])))&&!(l>0?Number(e2(g[s]))>=Number(e2(u[s])):Number(e2(g[s]))<=Number(e2(u[s]))))return[g,u]},B=(i,n)=>{let r=new Set(i.map(e=>e.id));for(let t of i){let i=o?t.x:t.x+n,a=o?t.y+n:t.y;for(let n of e)if(!r.has(n.id)&&m(i-8,a-8,t.width+16,t.height+16,n.x,n.y,n.width,n.height))return!1}for(let e of t){let t=r.has(e.source),i=r.has(e.target);if(t===i||0===e.points.length)continue;if(z(e)&&!A(e,r,n))return!1;let o=f.get(i?e.source:e.target);if(o&&S(e,i,n,o,!0))return!1}return!0},F=(e,i)=>{let n=new Set(e.map(e=>e.id)),r=new Map;for(let e of t)if(n.has(e.source)!==n.has(e.target)&&z(e)){let t=A(e,n,i);if(!t)return!1;r.set(e,t)}for(let t of e)o?t.y+=i:t.x+=i;for(let e of t){let t=n.has(e.source),o=n.has(e.target);if(t&&o){for(let t of e.points)t[a]+=i;e.labelPosition&&(e.labelPosition[a]+=i)}else r.has(e)?(e.points=r.get(e),e.labelPosition&&(e.labelPosition[a]=e.points[0][a])):o?E(e,!0,i,!0):t&&E(e,!1,i,!0)}return!0};for(let i of eO("APL_NO_CENTER")?[]:e){if(d.has(i.id)||y(i)||!ey.has(i.shape))continue;let e=t.filter(e=>e.target===i.id&&e.source!==i.id&&e.points.length>=2),n=new Map,r=e.length>=2;for(let t of e){if(t.label||!P(t)){r=!1;break}let e=f.get(t.source);if(!e||!ey.has(e.shape)){r=!1;break}n.set(e.id,e)}if(!r||n.size<2||t.filter(e=>e.source===i.id&&e.target!==i.id&&P(e)).length>1)continue;let o=[...n.values()],a=o.map(e=>e[s]+x(e)/2);if(Math.max(...a)-Math.min(...a)>Math.max(...o.map(x))+.6*eW.layerSpacing)continue;let l=o.reduce((e,t)=>e+u(t),0)/o.length-u(i);if(.5>=Math.abs(l)){R.add(i.id);continue}let h=$(i),g=new Set(t.filter(e=>e.source===i.id||e.target===i.id).map(e=>`${e.source}->${e.target}`));if(!(!C(i,l,g)||!B(h,l))&&(e$("[apl] center hub",i.id,"by",l.toFixed(1),"over",o.length,"sources"),F(h,l))){for(let e of h)R.add(e.id),d.add(e.id);for(let t of e)d.add(t.source)}}let T=new Set;if(!eO("APL_NO_FACET")){let i=()=>o?l>0?["NE","SE"]:["NW","SW"]:l>0?["SW","SE"]:["NW","NE"];for(let n of e){if("diamond"!==n.shape||d.has(n.id)||y(n))continue;let e=t.filter(e=>e.source===n.id&&e.target!==n.id&&e.points.length>=2&&P(e));if(2!==e.length||e.some(e=>{let t=f.get(e.target);return!t||!ey.has(t.shape)})||e.some(e=>d.has(e.target)||R.has(e.target)||y(f.get(e.target))))continue;let r=[...e].sort((e,t)=>u(f.get(e.target))-u(f.get(t.target))),[s,h]=i(),g=ex(n),c=[[r[0],s],[r[1],h]],p=em(n),x=c.map(([e,t])=>({edge:e,src:{x:g[t].x,y:g[t].y},cross:g[t][a]})),b=!o&&c[0]&&c[1]?[{edge:c[0][0],src:{x:p.W.x,y:p.W.y},cross:p.W[a]},{edge:c[1][0],src:{x:p.E.x,y:p.E.y},cross:p.E[a]}]:null,w=e=>{let[t,i]=e.map(e=>{let t=f.get(e.edge.target),i=e.cross-u(t);return{x:o?t.x:t.x+i,y:o?t.y+i:t.y,w:t.width,h:t.height}});return!!(t&&i&&m(t.x-8,t.y-8,t.w+16,t.h+16,i.x,i.y,i.w,i.h))},M=e=>e.every(e=>{let t=f.get(e.edge.target),i=e.cross-u(t);return .5>=Math.abs(i)||k(t,i,e.edge,!0)}),v=e=>!!e&&M(e)&&!w(e),S;if(v(x))S=x;else{if(!v(b))continue;S=b}let N=o?l>0?"W":"E":l>0?"N":"S";for(let e of S){let i=e.edge,n=f.get(i.target),r=e.cross-u(n);if(Math.abs(r)>.5)for(let e of(o?n.y+=r:n.x+=r,t)){if(e===i)continue;let t=e.source===n.id,o=e.target===n.id;if(t&&o){for(let t of e.points)t[a]+=r;e.labelPosition&&(e.labelPosition[a]+=r)}else o?E(e,!0,r):t&&E(e,!1,r)}i.points=[{x:e.src.x,y:e.src.y},em(n)[N]],i.labelPosition&&(i.labelPosition[a]=e.cross),T.add(i),d.add(i.target)}d.add(n.id)}}if(!eO("APL_NO_SVERTEX"))for(let e of t){if(T.has(e)||e.points.length<2||e.source===e.target)continue;let i=f.get(e.source),n=f.get(e.target);if(!i||!n||"diamond"!==n.shape||d.has(i.id)||d.has(n.id)||y(i)||y(n)||!P(e)||e.label)continue;let r=n[a]+g(n)/2;if(!t.some(t=>{if(t===e||t.target!==n.id||!P(t)||t.points.length<2)return!1;let i=f.get(t.source);return!!i&&Math.abs(i[a]+g(i)/2-r)<=g(n)/2}))continue;let h=n[a]+g(n)/2,c=i[a]+g(i)/2,p=c>h,m=o?p?"S":"N":p?"E":"W",x=em(n)[m];if(Math.abs(c-h)<.5*(g(n)/2))continue;let w=x[a]-u(i);if(Math.abs(w)>.5&&!k(i,w,e,!0))continue;let M=o?l>0?"E":"W":l>0?"S":"N",v=em(i)[M],S=Math.min(v[s],x[s]),N=Math.max(v[s],x[s]);if(!((x[s]-v[s])*l<=.5)&&!b(x[a],S,N,new Set([i.id,n.id]))){if(e$("[apl] svertex",e.source,"->",e.target,"into",m,"vertex"),Math.abs(w)>.5)for(let n of(o?i.y+=w:i.x+=w,t)){if(n===e)continue;let t=n.source===i.id,r=n.target===i.id;if(t&&r){for(let e of n.points)e[a]+=w;n.labelPosition&&(n.labelPosition[a]+=w)}else r?E(n,!0,w):t&&E(n,!1,w)}e.points=[{x:em(i)[M].x,y:em(i)[M].y},{x:x.x,y:x.y}],T.add(e),d.add(i.id),d.add(n.id)}}for(let e of t){if(T.has(e)||e.points.length<2||e.source===e.target)continue;let i=f.get(e.source),n=f.get(e.target);if(!i||!n||!ey.has(i.shape)||!ey.has(n.shape)||R.has(n.id)||"diamond"===i.shape&&t.some(t=>t!==e&&t.source===e.source&&P(t)))continue;let r=u(i)-u(n);if(.5>=Math.abs(r)||!P(e)||h(e.points).length>4)continue;let o=k(n,r,e)?n:k(i,-r,e)?i:null;o&&(e$("[apl] slide",o.id,"by",(o===n?r:-r).toFixed(1),"for",e.source,"->",e.target),N(o,o===n?r:-r,e),d.add(e.source),d.add(e.target))}}(o,a,i,n,r);let s=tO();(t$(o,a,e,t,i,r,s)||!(s.remaining<0)&&(ed(o,a.filter((e,i)=>tL(e,t[i])),{direction:n}),t$(o,a,e,t,i,r,s)))&&(B({nodes:o,edges:a},!0)+1e-6<B({nodes:e,edges:t},!0)||tA(e,t,o,a))}(e.nodes,e.edges,e.groups,e.graph.direction,e.style)}},{id:"centerPeerBarycenters",proposal:!0,after:["alignPortLanes"],mutates:["positions"],determinism:"in-place",mayChangeMetrics:{symErr:"improve-only",bends:{worsenBy:2}},enabled:e=>!!e.elkResult||e.mergeEdges,run:e=>{let t;return function(e,t,i,n,r,o){let a=eb(n.edges),s=new Map(e.map(e=>[e.id,e])),l=!eO("APL_NO_CORANK_FANIN"),d=(e,t,r=!1)=>{if(e.length<2||e.length>6)return;let o=e[0].style;if(e.some(e=>e.style!==o)||!r&&e.some(e=>e.label))return;let l=e.map(e=>e[t]);if(new Set(l).size!==l.length)return;let d=l.map(e=>s.get(e)).filter(e=>!!e);if(d.length!==l.length)return;let h="source"===t?e=>ey.has(e.shape):e=>"rectangle"===e.shape;if(d.every(e=>h(e)&&!G(e,i))&&W(d,n.direction,28)){for(let e=0;e<d.length;e++)for(let t=0;t<d.length;t++)if(e!==t&&a(d[e].id,d[t].id))return;return d}};for(let a=0;a<3;a++){let a=new Map,h=new Map;for(let e of t)H(e,s,n.direction)&&(a.has(e.source)||a.set(e.source,[]),a.get(e.source).push(e),h.has(e.target)||h.set(e.target,[]),h.get(e.target).push(e));let g=!1,u=e=>e.reduce((e,t)=>e+eC(t,n.direction),0)/e.length,f=(e,i)=>i.every(i=>t.every(t=>t.source!==i.id&&(t.target!==i.id||t.source===e))),c=(e,t)=>t.length>=2&&t.length<=3&&f(e,t),p=(a,s,l)=>{if(!a||!ey.has(a.shape)||G(a,i))return;let d=l?u(l):void 0,h=s?u(s):void 0;if(void 0!==d&&void 0!==h&&s.length>=4&&f(a.id,s)&&Math.abs(d-h)>1.5){let i=new Set(s.map(e=>e.id)),l=new Set([a.id]),u=d-h,f=d-eC(a,n.direction);if(es(i,e,t,n.direction,u,r)&&es(l,e,t,n.direction,f,r)){o?.(),eo(i,e,t,n.direction,u),Math.abs(f)>.5&&eo(l,e,t,n.direction,f),e$("[peer-barycenter] trunk-shift",a.id,"outs by",u.toFixed(1)),g=!0;return}}let p=[];if(void 0!==d&&p.push(d),void 0===h||s&&c(a.id,s)||p.push(h),0===p.length&&void 0!==h&&p.push(h),0===p.length)return;let y=(1===p.length?p[0]:(Math.min(...p)+Math.max(...p))/2)-eC(a,n.direction);if(.5>=Math.abs(y))return;let m=new Set([a.id]);es(m,e,t,n.direction,y,r)&&(e$("[peer-barycenter] center",a.id,"by",y.toFixed(1),2===p.length?"(mixed)":""),o?.(),eo(m,e,t,n.direction,y),g=!0)};for(let e of[...new Set([...a.keys(),...h.keys()])].sort()){let t=a.get(e),i=h.get(e),n=t?d(t,"target"):void 0,r=i?d(i,"source",l):void 0;p(s.get(e),n,r)}if(!g)break}}(e.nodes,e.edges,e.groups,e.graph,e.style,()=>{let i,n;t??=(i=e.nodes.map(e=>({node:e,x:e.x,y:e.y})),n=e.edges.map(e=>({edge:e,points:e.points.map(e=>({...e})),labelPosition:e.labelPosition?{...e.labelPosition}:void 0})),()=>{for(let{node:e,x:t,y:n}of i)e.x=t,e.y=n;for(let{edge:e,points:t,labelPosition:i}of n)e.points=t,e.labelPosition=i})}),t}},{id:"honorLinkRankDistance",after:["centerPeerBarycenters"],mutates:["positions"],determinism:"in-place",enabled:e=>!!e.elkResult||e.mergeEdges,run:e=>{!function(e,t,i,n){if(!n.edges.some(e=>(e.length??1)>1))return;let r=d(n),o=eS(n.direction),a=new Map(e.map(e=>[e.id,e])),s=new Map,l=e=>{for(let t of e)s.set(t.id,t),l(t.children)};l(i);let g=(e,t)=>{for(let i of e.nodeIds)t.push(i);for(let i of e.children)g(i,t)},u=e=>{if(a.has(e))return[e];let t=eL(n.subgraphs,e);if(!t)return[];let i=[];return g(t,i),i},f=new Map,c=(e,t)=>{for(let i of e){let e=[...t,i.id];for(let t of i.nodeIds)f.set(t,e);c(i.children,e)}};c(n.subgraphs,[]);let p=(e,t)=>{if(s.has(t))return u(t);let i=f.get(t)??[],n=new Set(f.get(e)??[]);for(let t of(s.has(e)&&n.add(e),i))if(!n.has(t))return u(t);return[t]},y=e=>{let t=n.edges[e];return"feedback"===r[e]?{source:t.target,target:t.source}:{source:t.source,target:t.target}},m=e=>{let t=a.get(e);if(t)return{start:t[o.main],size:eP(t,n.direction)};let i=s.get(e);return i?{start:i[o.main],size:"x"===o.main?i.width:i.height}:null},x=e=>{let t=m(e);return t?1===o.sign?t.start:t.start+t.size:null},b=e=>{let t=m(e);return t?1===o.sign?t.start+t.size:t.start:null},w=(e,t)=>{let i=b(e),n=x(t);return null!==i&&null!==n&&(n-i)*o.sign>0},M=new Map;for(let e=0;e<n.edges.length;e++){let t=y(e);if(w(t.source,t.target))for(let e of u(t.source))for(let i of u(t.target))M.has(e)||M.set(e,[]),M.get(e).push(i)}let v=new Map,S=new Set,k=(e,t)=>{if(.5>Math.abs(t))return;let i=new Set,n=[...e];for(;n.length>0;){let e=n.pop();if(i.has(e))continue;i.add(e);let r=a.get(e);if(r){let i=r[o.main];r[o.main]+=t,r[o.main]!==i&&S.add(r),v.set(e,(v.get(e)??0)+t)}for(let t of M.get(e)??[])n.push(t)}},E=new Map,N=e=>{let t=1/0,i=1/0,r=-1/0,o=-1/0,s=eL(n.subgraphs,e.id);for(let e of s?.nodeIds??[]){let n=a.get(e);n&&(t=Math.min(t,n.x),i=Math.min(i,n.y),r=Math.max(r,n.x+n.width),o=Math.max(o,n.y+n.height))}for(let n of e.children)t=Math.min(t,n.x),i=Math.min(i,n.y),r=Math.max(r,n.x+n.width),o=Math.max(o,n.y+n.height);return Number.isFinite(t)?{x:t,y:i,r:r,b:o}:null},P=e=>{for(let t of e.children)P(t);let t=N(e);t&&E.set(e.id,{l:t.x-e.x,t:t.y-e.y,r:e.x+e.width-t.r,b:e.y+e.height-t.b})},C=e=>{for(let t of e.children)C(t);let t=N(e),i=E.get(e.id);t&&i&&(e.x=t.x-i.l,e.y=t.y-i.t,e.width=t.r+i.r-e.x,e.height=t.b+i.b-e.y)};for(let e of i)P(e);let R=(e,t)=>{let i=Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x),n=Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y);return i>.5&&n>.5},I=(e,t)=>e.id<t.id?`${e.id}\0${t.id}`:`${t.id}\0${e.id}`,$=new Set;for(let t=0;t<e.length;t++)for(let i=t+1;i<e.length;i++)R(e[t],e[i])&&$.add(I(e[t],e[i]));let z=new Map,A=(t,i)=>{let n=e[t],r=e[i],o=t*e.length+i,a=I(n,r);$.has(a)||!R(n,r)?z.delete(o):z.has(o)||z.set(o,{a:n,b:r,key:a,index:o})},B=()=>{if(S.size){if(S.size>e.length/2)for(let t=0;t<e.length;t++)for(let i=t+1;i<e.length;i++)A(t,i);else for(let t=0;t<e.length;t++)if(S.has(e[t]))for(let i=0;i<e.length;i++)t===i||i<t&&S.has(e[i])||A(Math.min(t,i),Math.max(t,i));S.clear()}};for(let e=0;e<n.edges.length;e++){let t=n.edges[e],i=y(e),r=t.length??1;if(r<=1||!w(i.source,i.target))continue;let a=b(i.source),s=x(i.target);if(null===a||null===s)continue;let l=(s-a)*o.sign,d=e3(r,eW.layerSpacing);l<d&&k(p(i.source,i.target),(d-l)*o.sign)}if(!S.size)return;B();let F=(e,t)=>{let i=new Set(f.get(t)??[]);for(let t of f.get(e)??[])if(!i.has(t))return u(t);return[e]};for(let t=0;t<4*e.length;t++){let e;for(let t of z.values())(!e||t.key<e.key||t.key===e.key&&t.index<e.index)&&(e=t);if(!e)break;let{a:t,b:i}=e,r=(eR(t,n.direction)-eR(i,n.direction))*o.sign,[a,s]=(0!==r?r>0:t.id>i.id)?[i,t]:[t,i],l=1===o.sign?a[o.main]+eP(a,n.direction)+eW.nodeSpacing-s[o.main]:s[o.main]+eP(s,n.direction)+eW.nodeSpacing-a[o.main];k(F(s.id,a.id),1===o.sign?l:-l),B()}let T=new Map;for(let[e,t]of s)T.set(e,{start:t[o.main],size:"x"===o.main?t.width:t.height});for(let e of i)C(e);let _=e=>eC(e,n.direction)+eN(e,n.direction)/2,D=e=>eC(e,n.direction)-eN(e,n.direction)/2,H=Math.max(...e.map(_))+10,W=Math.min(...e.map(D))-10,j=(e,t)=>"x"===o.main?{x:e,y:t}:{x:t,y:e},X=(e,t)=>{let i=a.get(e);if(i)return em(i)[t];let n=s.get(e);if(!n)return null;let r=n.x+n.width/2,o=n.y+n.height/2;switch(t){case"E":return{x:n.x+n.width,y:o};case"W":return{x:n.x,y:o};case"S":return{x:r,y:n.y+n.height};default:return{x:r,y:n.y}}},V=e=>{for(let t of s.values()){if(t.concurrencyRegion||0===t.width)continue;let i=t.headerHeight??t.height;if(!Number.isFinite(i)||i<0)return!1;if(!(0===i||t.width<=0))for(let n=1;n<e.length;n++){let r=e[n-1],o=e[n];if(Math.max(r.x,o.x)>t.x&&Math.min(r.x,o.x)<t.x+t.width&&Math.max(r.y,o.y)>t.y&&Math.min(r.y,o.y)<t.y+i)return!1}}return!0},G=t=>{let i=new Set;for(let n of e)i.add(n[t]),i.add(n[t]+("x"===t?n.width:n.height));for(let e of s.values()){let n=e.concurrencyRegion?0:e.headerHeight??e.height;n>0&&Number.isFinite(n)&&e.width>0&&(i.add(e[t]),i.add(e[t]+("x"===t?e.width:n)))}let n=[...i].sort((e,t)=>e-t),r=[];for(let e=1;e<n.length;e++)n[e]-n[e-1]>2&&r.push((n[e]+n[e-1])/2);return t===o.cross&&s.size&&n.length>0&&r.push(n[0]-10,n.at(-1)+10),r},U="x"===o.main?"y":"x",Y=(e,t)=>[...e].sort((e,i)=>Math.abs(e-t)-Math.abs(i-t)||e-i).slice(0,16),q=new Map,K=(e,t)=>{for(let i of e)q.set(i.id,t),K(i.children,i.id)};K(n.subgraphs);let Q=(e,t)=>{if((f.get(t)??[]).includes(e))return!0;for(let i=q.get(t);void 0!==i;i=q.get(i))if(i===e)return!0;return!1},J=(e,t)=>{for(let i of[t.source,t.target]){let t=a.get(i);if(t){for(let i=1;i<e.length;i++)if(O(e[i-1],e[i],t))return!1}}return!0},Z=e=>{let t=a.get(e),i=s.get(e),n=T.get(e);return t?v.get(e)??0:i&&n?i[o.main]-n.start:void 0},ee=(e,t)=>{let i=a.get(e),r=v.get(e)??0,l=new Set(f.get(t)??[]);s.has(t)&&l.add(t);let d=s.has(e)?e:(f.get(e)??[]).find(e=>!l.has(e));if(d&&s.has(d)){let e=T.get(d),t=s.get(d),n=u(d),r=n.length?v.get(n[0])??0:0;if(n.every(e=>(v.get(e)??0)===r)&&("x"===o.main?t.width:t.height)===e.size)return{...e,delta:t[o.main]-e.start};if(!i)return null}return i?{start:i[o.main]-r,size:eP(i,n.direction),delta:r}:null},et=t=>{let i=ee(t.source,t.target),n=ee(t.target,t.source);if(!i||!n||t.points.length<2)return null;let[r,a]=i.start<=n.start?[i,n]:[n,i],s=r.start+r.size,l=a.start,d=l-s,h=l+a.delta-(s+r.delta),g=i.delta===n.delta&&Number.isFinite(i.delta);if(!g&&!(d>0&&h>0&&[s,l,d,h,r.delta,a.delta].every(Number.isFinite)))return null;let u=g?1:h/d;if(!(u>0&&Number.isFinite(u)))return null;let f=e=>g?e+i.delta:e<=s?e+r.delta:e>=l?e+a.delta:s+r.delta+(e-s)*u,c=t.points.map(e=>({...e,[o.main]:f(e[o.main])}));if(c.some(e=>!Number.isFinite(e.x)||!Number.isFinite(e.y)))return null;let p=t.points.map(e=>e[o.main]).sort((e,t)=>e<t?-1:+(e>t));for(let e=1;e<p.length;e++)if(p[e]>p[e-1]&&!(f(p[e])>f(p[e-1])))return null;for(let t=1;t<c.length;t++){let i=c[t-1],n=c[t];if(i.x!==n.x&&i.y!==n.y)return null;for(let t of e)if(O(i,n,t))return null}let y=Z(t.source),m=Z(t.target);return void 0!==y&&void 0!==m&&c[0][o.main]===t.points[0][o.main]+y&&c.at(-1)[o.main]===t.points.at(-1)[o.main]+m&&eo(c,t)&&er(c,e,new Set([t.source,t.target]))&&V(c)?c:null},ei=(e,t)=>{if(!t)return null;let i=Z(e);return void 0===i?null:{...t,[o.main]:t[o.main]+i}},eo=(e,t)=>{for(let[i,n]of[[t.source,!0],[t.target,!1]]){let r,o=a.get(i),l=s.get(i),d=o??(l?{id:l.id,label:l.label,shape:"rectangle",x:l.x,y:l.y,width:l.width,height:l.height}:void 0);if(!d)return!1;let h=n?e[0]:e.at(-1);if(!h)return!1;for(let t=n?1:e.length-2;t>=0&&t<e.length;t+=n?1:-1){let i=e[t];if(i.x!==h.x||i.y!==h.y){r=i;break}}if(!r||!L(d,h))return!1;let g=!o&&Q(i,n?t.target:t.source)?{x:h.x-(r.x-h.x),y:h.y-(r.y-h.y)}:r;if(!Number.isFinite(g.x)||!Number.isFinite(g.y)||!ea(d,h,g))return!1}return!0};for(let i of t){let t=void 0!==i.edgeIndex?r[i.edgeIndex]??"primary-forward":"primary-forward";if("self-loop"===t){let e=v.get(i.source)??0;0!==e&&(i.points=i.points.map(t=>({...t,[o.main]:t[o.main]+e}))),0!==e&&i.labelPosition&&(i.labelPosition[o.main]+=e);continue}let l=s.size>0&&("cross-hierarchy"===t||"container"===t),d=l?et(i):null;if(d){i.points=d,i.label&&(i.labelPosition=ev(d));continue}if("feedback"===t){let t=a.get(i.source),r=a.get(i.target);if(!t||!r)continue;let s=eR(t,n.direction),l=eR(r,n.direction),d=(e,i)=>[j(s,i(t)),j(s,e),j(l,e),j(l,i(r))],g=(e,i,n,o)=>[j(s,i(t)),j(s,e),j(n,e),j(n,o),j(l,o),j(l,i(r))],u=(e,i,n,o)=>[j(s,i(t)),j(s,o),j(n,o),j(n,e),j(l,e),j(l,i(r))],f=new Set([i.source,i.target]),c=t=>er(h(t),e,f)&&V(t),p=[[H,_],[W,D]],y;for(let[e,t]of p){let i=d(e,t);if(c(i)){y=i;break}}if(!y){let e=Y(G("x"===o.main?"x":"y"),l);e:for(let[t,i]of p){let n=Y(G(U),i(r));for(let r of[g,u])for(let o of e)for(let e of n){let n=r(t,i,o,e);if(c(n)){y=h(n);break e}}}}i.points=y??d(H,_),i.label&&(i.labelPosition=ev(i.points));continue}let g=l?ei(i.source,i.points[0]):X(i.source,o.sourceSide),u=l?ei(i.target,i.points.at(-1)):X(i.target,o.targetSide);if(!g||!u)continue;let f=new Set([i.source,i.target]),c=t=>er(t,e,f)&&V(t)&&(!l||eo(t,i)&&J(t,i)),p=Math.min(g[o.main],u[o.main]),y=Math.max(g[o.main],u[o.main]),m=en(g,u,n.direction,(p+y)/2),x=c(m);if(!x){let e,t=Y(G("x"===o.main?"x":"y").filter(e=>e>p&&e<y),(p+y)/2);for(let i of t){let t=en(g,u,n.direction,i);if(c(t)){e=t;break}}if(!e){let i=g[U],n=u[U],r=Y(G(U),(i+n)/2);e:for(let a of r)for(let r of t)for(let s of Y(t.filter(e=>(e-r)*o.sign>0),u[o.main])){let t=h([g,j(r,i),j(r,a),j(s,a),j(s,n),u]);if(c(t)){e=t;break e}}}e&&(m=e,x=!0)}if(l&&!x)throw new e4([{strategy:"link-rank-reconnect",violations:[`edge ${i.source}->${i.target}: no proven contact-preserving route after rank move`]}]);i.points=m,i.label&&(i.labelPosition=ev(i.points))}}(e.nodes,e.edges,e.groups,e.graph)}},{id:"alignLabeledSourcePort",after:["honorLinkRankDistance"],mutates:["positions","edges"],determinism:"in-place",mayChangeMetrics:{portRate:"improve-only"},enabled:e=>!!e.elkResult||e.mergeEdges,run:e=>{!function(e,t,i,n,r,o){if(eO("APL_NO_LABELED_SOURCE_PORT")||!tI(e,t,i)||!t.some(e=>e.label))return;let a=tz(e,t);!function(e,t,i,n,r,o){let a=new Set;for(let[r]of tR(e,t,i,n))a.add(r);let s="LR"===r||"RL"===r,l=s?"y":"x",d=s?"x":"y",h=s?"LR"===r?"E":"W":"BT"===r?"N":"S",g=e=>e[l]+(s?e.height:e.width)/2,u=[],f=e=>{for(let t of e)u.push(t),f(t.children)};f(i);let c=e=>u.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),p=new Map(e.map(e=>[e.id,e])),y=e=>"x"===d?"E"===h?e.x+e.width:e.x:"S"===h?e.y+e.height:e.y,m=(e,i)=>{let n=new Set([e.id]),r=[e.id];for(;r.length;){let e=r.pop();for(let o of t){if(o.target!==e||o===i)continue;let a=p.get(o.source);if(!(!a||n.has(a.id))){if(1!==t.filter(e=>e.source===a.id).length||!ey.has(a.shape)||c(a))return null;n.add(a.id),r.push(a.id)}}}return n};for(let n of t){if(!n.label||n.points.length<2||n.source===n.target||a.has(n.target))continue;let u=p.get(n.source);if(!u||!ey.has(u.shape)||c(u)||t.some(e=>e!==n&&e.source===u.id&&e.target!==u.id)||Math.abs(n.points[0][d]-y(u))>1)continue;let f=p.get(n.target);if(!f||!ey.has(f.shape)||c(f))continue;let{ctx:x,axis:b}=M(e,t,r,o,i),v=0,S=!1,k={...u};for(let e=0;e<4;e++){let e=w(n,k,f,x,b);if(null===e)break;let t=e-g(k);if(v+=t,k[l]+=t,.5>=Math.abs(t)){S=!0;break}}if(!S||1>=Math.abs(v))continue;let E=m(u,n);if(!E)continue;let N=[...E].map(e=>p.get(e)).filter(Boolean),P=e=>({x:s?e.x:e.x+v,y:s?e.y+v:e.y,width:e.width,height:e.height});if(!(e.some(e=>!E.has(e.id)&&N.some(t=>{let i=P(t);return i.x-2<e.x+e.width&&i.x+i.width+2>e.x&&i.y-2<e.y+e.height&&i.y+i.height+2>e.y}))||t.some(e=>!E.has(e.source)&&!E.has(e.target)&&N.some(t=>{let i=P(t);return e.points.some((t,n)=>{if(0===n)return!1;let r=e.points[n-1];return Math.max(t.x,r.x)>i.x+.5&&Math.min(t.x,r.x)<i.x+i.width-.5&&Math.max(t.y,r.y)>i.y+.5&&Math.min(t.y,r.y)<i.y+i.height-.5})})))){for(let e of N)s?e.y+=v:e.x+=v;for(let e of t)if(E.has(e.source)&&E.has(e.target))for(let t of e.points)t[l]+=v;n.points[0]=em(u)[h]}}}(a.nodes,a.edges,i,n,r,o);let s=tO();if(!t$(a.nodes,a.edges,e,t,i,o,s)){if(s.remaining<0)return;let{ctx:n,axis:l}=M(a.nodes,a.edges,r,o,i);for(let e=0;e<a.edges.length;e++){let i=a.edges[e];if(!i.label||!tL(i,t[e]))continue;let r=a.nodes.find(e=>e.id===i.source),o=a.nodes.find(e=>e.id===i.target);if(!r||!o||!b(i,r,o,n,l,i.points[0][l.cross]).applied)return;S(i,i.routeCertificate,r,o)}let d=Symbol(),h=()=>--s.remaining>=0,g=()=>{if(!h())throw d};try{let n=E({...a,groups:i},o,g),r=(t,r)=>{g();let l=Z(t,o);if(!l)return!1;let d=n.clearPaintRect(l,Q(t,o.lineWidth??1));if(!d)return!1;let u={x0:d.x,y0:d.y,x1:d.x+d.w,y1:d.y+d.h};for(let e of a.edges){g();let i=p(e,o,h);if(!i||i.markers.some(e=>(g(),c(u,e.bounds))))return!1;if(e===t)continue;if(i.shafts.some(e=>(g(),c(u,e))))return!1;let n=Z(e,o);if(n){g();let t=Q(e,o.lineWidth??1);if(c(u,{x0:n.x-t,y0:n.y-t,x1:n.x+n.w+t,y1:n.y+n.h+t}))return!1}}return t$(a.nodes,[t],e,[r],i,o,s)};for(let e=0;e<a.edges.length;e++){g();let i=a.edges[e],n=t[e];if(!i.label||!tL(i,n)||r(i,n))continue;let s=Z(i,o),d=i.points[0],h=i.points[1];if(!s||2!==i.points.length)return;let u=Math.hypot(h.x-d.x,h.y-d.y),f=("x"===l.main?s.w:s.h)/2;if(!(u>2*f))return;let c=!1;for(let e of k(f/u,g))if(g(),i.labelPosition={x:d.x+(h.x-d.x)*e,y:d.y+(h.y-d.y)*e},r(i,n)){c=!0;break}if(!c)return}}catch(e){if(e===d)return;throw e}if(!t$(a.nodes,a.edges,e,t,i,o,s))return}tA(e,t,a.nodes,a.edges)}(e.nodes,e.edges,e.groups,e.graph,e.graph.direction,e.style)}},{id:"bundleEdgePaths",after:["alignLabeledSourcePort"],mutates:["edges"],determinism:"pure-order",enabled:e=>e.mergeEdges,run:e=>{e.bundled=function(e,t,i,n,r){let o=new Map(t.map(e=>[e.id,e])),a=new Set,s=(n,a)=>{for(let[e,t]of a){let i=o.get(e.source),n=o.get(e.target);a.set(e,eh(eh(t,i,!0),n,!1))}let s=e.map(e=>a.has(e)?{...e,points:a.get(e)}:e);return n.filter(n=>{let o=a.get(n.edge),l=s[e.indexOf(n.edge)];return function(e,t,i,n){let r=(e,t)=>{if(void 0!==e&&!/^\s*[+]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?(?:px)?\s*$/i.test(e))return;let i=void 0===e?t:Number.parseFloat(e);return Number.isFinite(i)&&i>=0?Number(e2(i)):void 0},o=r(e.inlineStyle?.["stroke-width"],n.lineWidth*("thick"===e.style?2:1)),a=n.edgeBendRadius;if(void 0===o||!Number.isFinite(a)||a<0)return!1;let s=eQ({stroke:"#000",strokeWidth:String(o)},!0);if(void 0===s)return!1;let l=s+a,d=e.points.map(e=>({x:Number(e2(e.x)),y:Number(e2(e.y))}));if(!d.every(e=>Number.isFinite(e.x)&&Number.isFinite(e.y)))return!1;let h=d.slice(1).map((e,t)=>{let i=d[t];return{x0:Math.min(i.x,e.x)-l,x1:Math.max(i.x,e.x)+l,y0:Math.min(i.y,e.y)-l,y1:Math.max(i.y,e.y)+l}}),g=(e,t)=>{let i=(Math.abs(e.x0)+Math.abs(e.x1)+Math.abs(e.y0)+Math.abs(e.y1)+Math.abs(t.x0)+Math.abs(t.x1)+Math.abs(t.y0)+Math.abs(t.y1))*1e-10+1e-9;return!Number.isFinite(i)||e.x1+i>t.x0&&e.x0<t.x1+i&&e.y1+i>t.y0&&e.y0<t.y1+i},u=V(e,n);if(!u||u.length!==+!!e.hasArrowStart+ +!!e.hasArrowEnd)return!1;for(let i of t){let t=r(i.inlineStyle?.["stroke-width"],n.nodeLineWidth);if(void 0===t)return!1;let o=et(i,{fill:"#000",stroke:"#000",strokeWidth:String(t)},n.cornerRadius),a=eJ(eY({id:i.id,role:"node",geometry:o.geometry,paint:o.paint,...o.childPaints?{childPaints:o.childPaints}:{}}));if(!a||i.id!==e.source&&i.id!==e.target&&h.some(e=>g(e,a)))return!1;for(let t of u)if(("start"===t.position?e.source:e.target)!==i.id&&(!t.bounds||g(t.bounds,a)))return!1}let f=e=>{let t=e.concurrencyRegion?0:e.headerHeight??e.height;if(t>0){let i={x0:e.x,x1:e.x+e.width,y0:e.y,y1:e.y+t};if(h.some(e=>g(e,i))||u.some(e=>!e.bounds||g(e.bounds,i)))return!1}return e.children.every(f)};return i.every(f)}(l,t,i,r)&&!U(n.edge,o,s,r,l)})},l="LR"===n,d="RL"===n,h="BT"===n,g=l||d,u=new Map;for(let t of e)t.source!==t.target&&(u.has(t.source)||u.set(t.source,[]),u.get(t.source).push(t));for(let[e,t]of u){if(t.length<2)continue;let r=t[0].style;if(t.some(e=>e.label||e.style!==r))continue;let u=o.get(e);if(!u)continue;let f=t.filter(e=>{let t=o.get(e.target);return!!t&&(l?t.x>u.x+u.width:d?t.x+t.width<u.x:h?t.y+t.height<u.y:t.y>u.y+u.height)});if(f.length<2||new Set(f.map(e=>e.target)).size<2)continue;let c=u.x+u.width/2,p=u.y+u.height/2,m=f.map(e=>({edge:e,node:o.get(e.target)}));for(;m.length>=2;){let e=new Map;if(g){let t=l?u.x+u.width:u.x,r=t+((l?Math.min(...m.map(e=>e.node.x)):Math.max(...m.map(e=>e.node.x+e.node.width)))-t)/2;for(let{edge:o,node:a}of(r=tX(r,c,p,i,n),m)){let i=l?a.x:a.x+a.width,n=a.y+a.height/2;e.set(o,[{x:t,y:p},{x:r,y:p},{x:r,y:n},{x:i,y:n}])}}else{let t=h?u.y:u.y+u.height,r=t+((h?Math.max(...m.map(e=>e.node.y+e.node.height)):Math.min(...m.map(e=>e.node.y)))-t)/2;for(let{edge:o,node:a}of(r=tX(r,c,p,i,n),m)){let i=a.x+a.width/2,n=h?a.y+a.height:a.y;e.set(o,[{x:c,y:t},{x:c,y:r},{x:i,y:r},{x:i,y:n}])}}let t=s(m,e);if(t.length===m.length){for(let{edge:t}of m)t.points=e.get(t);y(m.map(e=>e.edge),a);break}if(new Set((m=t).map(e=>e.edge.target)).size<2)break}}let f=new Map;for(let t of e)a.has(t)||t.source===t.target||(f.has(t.target)||f.set(t.target,[]),f.get(t.target).push(t));for(let[e,t]of f){if(t.length<2)continue;let r=t[0].style;if(t.some(e=>e.label||e.style!==r))continue;let u=o.get(e);if(!u)continue;let f=t.filter(e=>{let t=o.get(e.source);return!!t&&(l?t.x+t.width<u.x:d?t.x>u.x+u.width:h?t.y>u.y+u.height:t.y+t.height<u.y)});if(f.length<2||new Set(f.map(e=>e.source)).size<2)continue;let c=u.x+u.width/2,p=u.y+u.height/2,m=f.map(e=>({edge:e,node:o.get(e.source)}));for(;m.length>=2;){let e=new Map;if(g){let t=l?u.x:u.x+u.width,r=l?Math.max(...m.map(e=>e.node.x+e.node.width)):Math.min(...m.map(e=>e.node.x)),o=r+(t-r)/2;for(let{edge:r,node:a}of(o=tX(o,c,p,i,n),m)){let i=l?a.x+a.width:a.x,n=a.y+a.height/2;e.set(r,[{x:i,y:n},{x:o,y:n},{x:o,y:p},{x:t,y:p}])}}else{let t=h?u.y+u.height:u.y,r=h?Math.min(...m.map(e=>e.node.y)):Math.max(...m.map(e=>e.node.y+e.node.height)),o=r+(t-r)/2;for(let{edge:r,node:a}of(o=tX(o,c,p,i,n),m)){let i=a.x+a.width/2,n=h?a.y:a.y+a.height;e.set(r,[{x:i,y:n},{x:i,y:o},{x:c,y:o},{x:c,y:t}])}}let t=s(m,e);if(t.length===m.length){for(let{edge:t}of m)t.points=e.get(t);y(m.map(e=>e.edge),a);break}if(new Set((m=t).map(e=>e.edge.source)).size<2)break}}return a}(e.edges,e.nodes,e.groups,e.graph.direction,e.style),e.genericBundled=e.bundled.size>0}},{id:"markCorankFanInBundles",after:["bundleEdgePaths"],mutates:["edges"],determinism:"in-place",enabled:e=>!!e.elkResult||e.mergeEdges,run:e=>{!function(e,t,i,n,r,o){let a=new Map(e.map(e=>[e.id,e])),s=eS(n.direction);for(let[l,d]of tR(e,t,i,n)){let t=a.get(l),i=[...d].sort((e,t)=>eC(a.get(e.source),n.direction)-eC(a.get(t.source),n.direction)),h=i.map(e=>a.get(e.source)),g=em(t)[s.targetSide],u=(s.isHorizontal?t.height:t.width)/2*1.6,f=Math.min(28,i.length>1?u/(i.length-1):0),c=ei(i.length,f),p=e=>s.isHorizontal?{x:g.x,y:g.y+e}:{x:g.x+e,y:g.y};c.every(e=>L(t,p(e)))||(c=c.map(()=>0));let m=s.isHorizontal?"E"===s.sourceSide?Math.max(...h.map(e=>e.x+e.width)):Math.min(...h.map(e=>e.x)):"S"===s.sourceSide?Math.max(...h.map(e=>e.y+e.height)):Math.min(...h.map(e=>e.y)),x=m+((s.isHorizontal?g.x:g.y)-m)/2,b=[],w=!0;for(let t=0;t<i.length;t++){let r=i[t],o=en(em(h[t])[s.sourceSide],p(c[t]),n.direction,x);if(!er(o,e,new Set([r.source,r.target]))){w=!1;break}b.push({edge:r,points:o})}if(w){for(let{edge:e,points:t}of b)e.points=t,e.routeCertificate=void 0;y(b.map(e=>e.edge),r),tC(b,e,n.direction,o,!0)}}}(e.nodes,e.edges,e.groups,e.graph,e.bundled,e.style)}},{id:"clipEdgeToShape",after:["bundleEdgePaths"],mutates:["edges"],determinism:"in-place",mayChangeMetrics:{portRate:{worsenBy:1,whenImproves:"endpointApproaches"},endpointApproaches:"improve-only"},run:e=>{let t=new Map(e.nodes.map(e=>[e.id,e]));for(let i of e.edges){let n=e.bundled.has(i)?m(i):void 0;i.points=i.points.filter((e,t,i)=>0===t||e.x!==i[t-1].x||e.y!==i[t-1].y);let r=t.get(i.source),o=t.get(i.target);l(i,r,o),r&&(i.points=eh(i.points,r,!0)),o&&(i.points=eh(i.points,o,!1)),x(i,n)}}},{id:"applySymmetricFanoutEmissions",after:["clipEdgeToShape"],mutates:["edges"],determinism:"in-place",mayChangeMetrics:{symErr:"improve-only",bends:{worsenBy:2}},enabled:e=>!!e.elkResult||e.mergeEdges,run:e=>{!function(e,t,i,n,r,o){let a=eb(n.edges),s=new Map(e.map(e=>[e.id,e])),l=new Map;for(let e of t)H(e,s,n.direction)&&(l.has(e.source)||l.set(e.source,[]),l.get(e.source).push(e));let d=eS(n.direction);for(let[h,g]of l){if(g.length<2||g.length>3)continue;let l=s.get(h);if(!l||"rectangle"!==l.shape&&"diamond"!==l.shape)continue;let u=G(l,i);if("diamond"!==l.shape&&u)continue;let f=[...g].sort((e,t)=>eC(s.get(e.target),n.direction)-eC(s.get(t.target),n.direction)),c=f.map(e=>s.get(e.target)).filter(Boolean);if(c.length!==f.length||!c.every(e=>"rectangle"===e.shape&&("diamond"===l.shape||!G(e,i)))||!W(c,n.direction,40)||!c.every(e=>t.every(t=>t.source!==e.id&&(t.target!==e.id||t.source===l.id))))continue;let p=!0;for(let e=0;e<c.length;e++)for(let t=0;t<c.length;t++)e!==t&&a(c[e].id,c[t].id)&&(p=!1);if(!p)continue;let m=c.map(e=>({t:e,x:e.x,y:e.y,width:e.width,height:e.height})),x=Y(i).map(e=>({group:e,x:e.x,y:e.y,width:e.width,height:e.height})),b=()=>{for(let e of m)e.t.x=e.x,e.t.y=e.y,e.t.width=e.width,e.t.height=e.height;for(let e of x)e.group.x=e.x,e.group.y=e.y,e.group.width=e.width,e.group.height=e.height},w=Math.max(...c.map(e=>e.width)),M=Math.max(...c.map(e=>e.height)),v=eC(l,n.direction),S=Math.min(...c.map(e=>ek(e,n.direction))),k=(d.isHorizontal?M:w)+28,E=ei(c.length,k),N="diamond"===l.shape?f.map((e,t)=>J(l,n.direction,t,f.length)[d.cross]):void 0,P=e=>{for(let t=0;t<c.length;t++){let i=c[t];i.width=w,i.height=M,d.isHorizontal?(i.x=S,i.y=e[t]-M/2):(i.x=e[t]-w/2,i.y=S)}};P(N??E.map(e=>v+e));let C=new Set(c.map(e=>e.id)),R=()=>{for(let e=0;e<c.length;e++){let t=c[e];if(t.x<0||t.y<0)return!1;for(let i=e+1;i<c.length;i++)if(eI(t,c[i],8))return!1}for(let t of c)for(let i of e)if(!C.has(i.id)&&eI(t,i,8))return!1;return!0},I=R();if(!I&&N&&(P(E.map(e=>v+e)),I=R()),!I){b();continue}let L=d.isHorizontal?"E"===d.sourceSide?l.x+l.width:l.x:"S"===d.sourceSide?l.y+l.height:l.y,O=d.isHorizontal?d.sign>0?Math.min(...c.map(e=>e.x)):Math.max(...c.map(e=>e.x+e.width)):d.sign>0?Math.min(...c.map(e=>e.y)):Math.max(...c.map(e=>e.y+e.height)),$=Math.max(0,...f.map(e=>(function(e,t,i){if(!e.label)return 0;let n=tm(e,{x:0,y:0},i);return(eS(t).isHorizontal?n.width:n.height)+3*Math.max(tw(i),e.hasArrowEnd?tv(i):tw(i))})(e,n.direction,o))),z=(O-L)*d.sign;if($>z+.001){let e=$-z,t=c.map(e=>({x:e.x,y:e.y,width:e.width,height:e.height}));for(let t of c)d.isHorizontal?t.x+=e*d.sign:t.y+=e*d.sign;if(K(i,t,n.direction,e),!(I=R())){b();continue}O=d.isHorizontal?d.sign>0?Math.min(...c.map(e=>e.x)):Math.max(...c.map(e=>e.x+e.width)):d.sign>0?Math.min(...c.map(e=>e.y)):Math.max(...c.map(e=>e.y+e.height))}let A=Math.max(0,...f.map(e=>(function(e,t,i,n,r){if(!e.label)return 0;let o=eS(t),a=tm(e,{x:0,y:0},i),s=o.isHorizontal?a.width:a.height,l=Math.max(tw(i),e.hasArrowEnd?tv(i):tw(i)),d=((r-n)*o.sign-s)/3;return d>=l-.001?s+2*d:s+tw(i)+l+2})(e,n.direction,o,L,O))),B=L+(O-L)*.5,F=O-d.sign*A,T=(F-B)*d.sign<0?F:B,_=[];for(let t=0;t<f.length;t++){let i=f[t],r=s.get(i.target),o=en(J(l,n.direction,t,f.length),ee(r,n.direction),n.direction,T);if(!er(o,e,new Set([i.source,i.target]))){I=!1;break}_.push({edge:i,points:o})}if(!I){b();continue}for(let{edge:e,points:t}of _)e.points=t,e.routeCertificate=void 0;y(_.map(e=>e.edge),r),tC(_,e,n.direction,o)}}(e.nodes,e.edges,e.groups,e.graph,e.bundled,e.style)}},{id:"applySymmetricParallelEdgeLanes",after:["clipEdgeToShape"],mutates:["edges"],determinism:"in-place",enabled:e=>(!!e.elkResult||e.mergeEdges)&&t8(e.edges,!0),mayChangeMetrics:{symErr:"improve-only",crossings:"improve-only"},run:e=>{!function(e,t,i,n,r,o){let a=new Map(e.map(e=>[e.id,e])),s=eS(n.direction),l=new Map;for(let e of t){if(e.source===e.target||!e.label)continue;let t=a.get(e.source),n=a.get(e.target);if(!t||!n||!ey.has(t.shape)||!ey.has(n.shape)||G(t,i)||G(n,i))continue;let r=`${e.source}\0${e.target}`;l.has(r)||l.set(r,[]),l.get(r).push(e)}for(let i of l.values()){if(i.sort((e,t)=>(e.edgeIndex??0)-(t.edgeIndex??0)),2!==i.length)continue;let l=a.get(i[0].source),d=a.get(i[0].target),g=i.map(e=>tm(e,{x:0,y:0},o)),u=g.map(e=>e.width),f=g.map(e=>e.height),c=(s.isHorizontal?Math.max(...f):Math.max(...u))/2+18,p=[[1/3,2/3],[1/6,1/3],[2/3,5/6]],m=[c,c+16,c+32,c+52].map(e=>({lanes:s.isHorizontal?[Math.min(l.y,d.y)-e,Math.max(l.y+l.height,d.y+d.height)+e]:[Math.min(l.x,d.x)-e,Math.max(l.x+l.width,d.x+d.width)+e],sourceSlots:p[0],targetSlots:p[0]}));if("diamond"===l.shape)for(let e of[...m])for(let t of p)for(let i of p){let r=i.map(e=>d[s.cross]+eN(d,n.direction)*e),o=t.map(e=>l[s.cross]+eN(l,n.direction)*e);for(let n of[e.lanes,[e.lanes[0],r[1]],[r[0],e.lanes[1]],[e.lanes[0],o[1]],[o[0],e.lanes[1]]])m.push({lanes:n,sourceSlots:t,targetSlots:i})}for(let{lanes:a,sourceSlots:s,targetSlots:g}of m){let u=[],f=!0;for(let t=0;t<i.length;t++){let r=i[t],o=h(eh(eh(function(e,t,i,n,r,o,a=(r+1)/(o+1),s=a){let l=eS(i);if(l.isHorizontal){let i={x:"E"===l.sourceSide?e.x+e.width:e.x,y:e.y+e.height*a},r={x:"W"===l.targetSide?t.x:t.x+t.width,y:t.y+t.height*s},o=Math.min(28,Math.max(14,.18*Math.abs(r.x-i.x))),d=i.x+l.sign*o,g=r.x-l.sign*o;return h([i,{x:d,y:i.y},{x:d,y:n},{x:g,y:n},{x:g,y:r.y},r])}let d={x:e.x+e.width*a,y:"S"===l.sourceSide?e.y+e.height:e.y},g={x:t.x+t.width*s,y:"N"===l.targetSide?t.y:t.y+t.height},u=Math.min(28,Math.max(14,.18*Math.abs(g.y-d.y))),f=d.y+l.sign*u,c=g.y-l.sign*u;return h([d,{x:d.x,y:f},{x:n,y:f},{x:n,y:c},{x:g.x,y:c},g])}(l,d,n.direction,a[t],t,i.length,s[t],g[t]),l,!0),d,!1));if(!L(l,o[0])||!L(d,o.at(-1))||!er(o,e,new Set([l.id,d.id]))){f=!1;break}u.push({edge:r,points:o,label:tx(o)})}if(f){if("diamond"===l.shape){let r=t.filter(e=>!i.includes(e));if(tF(u[0].points,u[1].points)||u.some(e=>r.some(t=>tF(e.points,t.points))))continue;let a=u.map(t=>{let i=[...r,...u.filter(e=>e!==t).map(e=>({...e.edge,points:e.points}))];return tE(t.edge,t.points,e,n.direction,o).filter(e=>!tB(t.edge,{x:e.box.x,y:e.box.y,w:e.box.width,h:e.box.height},i))}),s;for(let e of a[0]){let t=a[1].find(t=>!eI(e.box,t.box,tb(o)));if(t){s=[e,t];break}}if(!s)continue;u[0].label=s[0].point,u[1].label=s[1].point}for(let e of u){let i=tm(e.edge,e.label,o);"diamond"!==l.shape&&tB(e.edge,{x:i.x,y:i.y,w:i.width,h:i.height},t)&&(f=!1)}if(!(!f||!0!==t_(t,u,o))){for(let{edge:e,points:t,label:i}of u)e.points=t,e.labelPosition=i,e.routeCertificate=void 0;y(u.map(e=>e.edge),r);break}}}}}(e.nodes,e.edges,e.groups,e.graph,e.bundled,e.style)}},{id:"applyParallelDuplicateLanes",after:["clipEdgeToShape"],mutates:["edges"],determinism:"in-place",enabled:e=>(!!e.elkResult||e.mergeEdges)&&t8(e.edges),mayChangeMetrics:{crossings:{worsenBy:1,whenImproves:"parallelOverlaps",perImprovement:!0},parallelOverlaps:"improve-only"},run:e=>{!function(e,t,i,n,r,o,a){let s=new Map(e.map(e=>[e.id,e])),l=eS(n.direction),d={allowCrossingsForOverlap:!0,...a?{labelClearance:{nodes:e,style:a}}:{}},g=e=>l.isHorizontal?e.height:e.width,u=(e,t)=>l.isHorizontal?{x:e,y:t}:{x:t,y:e},f=e=>e[l.main]+(l.isHorizontal?e.width:e.height),c=e=>e[l.main],p="E"===l.sourceSide||"S"===l.sourceSide,m="W"===l.targetSide||"N"===l.targetSide,x=(e,t)=>p!==t?f(e):c(e),b=(e,t)=>m!==t?c(e):f(e),w=new Set,M=(e,t)=>{for(let i=1;i<e.points.length;i++){let n=e.points[i-1],r=e.points[i],o=.5>Math.abs(n.x-r.x),a=.5>Math.abs(n.y-r.y);if(!(!o&&!a))for(let e=1;e<t.points.length;e++){let i=t.points[e-1],s=t.points[e];if(o){if(Math.abs(i.x-s.x)>=.5||Math.abs(n.x-i.x)>=1)continue;if(Math.min(Math.max(n.y,r.y),Math.max(i.y,s.y))-Math.max(Math.min(n.y,r.y),Math.min(i.y,s.y))>1)return!0}else if(a){if(Math.abs(i.y-s.y)>=.5||Math.abs(n.y-i.y)>=1)continue;if(Math.min(Math.max(n.x,r.x),Math.max(i.x,s.x))-Math.max(Math.min(n.x,r.x),Math.min(i.x,s.x))>1)return!0}}}return!1},v=new Map;for(let e of t){if(e.source===e.target)continue;let t=s.get(e.source),n=s.get(e.target);if(!t||!n||!ey.has(t.shape)||!ey.has(n.shape)||G(t,i)||G(n,i))continue;let r=(b(n,!1)-x(t,!1))*l.sign,o=(x(t,!0)-b(n,!0))*l.sign;if(r<=16&&o<=16)continue;let a=`${e.source}\0${e.target}`;v.has(a)||v.set(a,[]),v.get(a).push(e)}let S=(e,t)=>{let i=tm(e,t,o),n=Q(e,o.lineWidth??1);return{x:i.x-n,y:i.y-n,width:i.width+2*n,height:i.height+2*n}},E=(i,a,f,c,p=0)=>{i.sort((e,t)=>(e.edgeIndex??0)-(t.edgeIndex??0));let m=s.get(i[0].source),M=s.get(i[0].target),v=x(m,a),k=b(M,a),E=i.length;if(f<4)return!1;let N=i.every(e=>e.label)?Math.max(f,...i.map(e=>{let t=S(e,{x:0,y:0});return(l.isHorizontal?t.width:t.height)+tb(o)})):f,P="target"===c,C=m[l.cross]+g(m)/2+p,R=M[l.cross]+g(M)/2+p,I=[],O=[];for(let e=0;e<E;e++){let t=C+(e-(E-1)/2)*f,n=R+(e-(E-1)/2)*f,r=(a?-1:1)*l.sign,o=P?k-r*(16+e*N):v+r*(16+e*N),s=Math.min(v,k),d=Math.max(v,k);(o<=s+4||o>=d-4)&&(o=(v+k)/2),I.push({edge:i[e],sCross:t,tCross:n}),O.push(o)}I[0].tCross-I[0].sCross>0!==P&&O.reverse();let $=[];for(let t=0;t<E;t++){let{edge:i,sCross:n,tCross:r}=I[t],o=O[t],a=h(eh(eh(n===r?[u(v,n),u(k,r)]:[u(v,n),u(o,n),u(o,r),u(k,r)],m,!0),M,!1));if(a.length<2||!L(m,a[0])||!L(M,a[a.length-1])||!er(a,e,new Set([m.id,M.id])))return!1;$.push({edge:i,points:a,label:i.label?tx(a):void 0})}let z=t_(t,$,o,{allowCrossingsForOverlap:!0});if(!0!==z)return z;if("original"!==c){let r=t.filter(e=>!i.includes(e)),a=[...r,...$.map(e=>({...e.edge,points:e.points}))].flatMap(e=>j(e,o)).flatMap(e=>e.bounds?[{x:e.bounds.x0,y:e.bounds.y0,width:e.bounds.x1-e.bounds.x0,height:e.bounds.y1-e.bounds.y0}]:[]),s=r.filter(e=>e.label).map(e=>S(e,e.labelPosition??ev(e.points)));for(let t of $){if(!t.edge.label)continue;let i=[...r,...$.filter(e=>e!==t).map(e=>({...e.edge,points:e.points}))],l=tE(t.edge,t.points,e,n.direction,o).find(n=>{let r=S(t.edge,n.point);return!e.some(e=>eI(r,e,2))&&!a.some(e=>eI(r,e,0))&&!s.some(e=>eI(r,e,2))&&!tB(t.edge,{x:r.x,y:r.y,w:r.width,h:r.height},i)});if(!l)return!1;t.label=l.point,s.push(S(t.edge,t.label))}}if(d.labelClearance&&!tT(t,$,d.labelClearance))return!1;for(let{edge:e,points:t,label:i}of $)e.points=t,e.labelPosition=i,e.routeCertificate=void 0,w.add(e);return y($.map(e=>e.edge),r),!0};for(let n of v.values()){if(n.length<2||!n.some(e=>e.label)||!n.some(e=>e.label&&n.some(t=>t!==e&&M(e,t)))||n.every(e=>e.label)&&0===I({nodes:[],edges:n},o).labelLabel)continue;let r=s.get(n[0].source),a=s.get(n[0].target);if(!r||!a)continue;let d=!((b(a,!1)-x(r,!1))*l.sign>16),h=(Math.min(g(r),g(a))-10)/(n.length-1),u=Math.max(14,...n.filter(e=>e.label).map(e=>{let t=S(e,{x:0,y:0});return(l.isHorizontal?t.height:t.width)/2+3})),f=(r,o)=>{let a=E(n,d,r,o);if(!0===a)return!0;if("marker-blocked"!==a||!tI(e,t,i))return!1;let s=(h-r)*(n.length-1)/2;return s>0&&k(0).some(e=>{let t=(2*e-1)*s;return 0!==t&&!0===E(n,d,r,o,t)})};if(!(u<=h&&(f(u,"source")||f(u,"target")))&&!f(Math.min(14,h),"original")&&n.every(e=>e.label)){let e=Math.min(7,h);f(e,"source")||f(e,"target")||f(e,"original")}}let N=new Map,P=new Map;for(let e of t){if(w.has(e)||e.source===e.target||e.label)continue;let t=s.get(e.source),n=s.get(e.target);if(!t||!n||!ey.has(t.shape)||!ey.has(n.shape)||G(t,i)||G(n,i))continue;let r=t=>{t.has(e.target)||t.set(e.target,[]),t.get(e.target).push(e)};(b(n,!1)-x(t,!1))*l.sign>16?r(N):(x(t,!0)-b(n,!0))*l.sign>16&&r(P)}let C=(n,a)=>{if(n.length<2)return;let f=new Map;for(let e of n)f.set(e.source,(f.get(e.source)??0)+1);if(![...f.values()].some(e=>e>=2))return;let c=s.get(n[0].target),p=b(c,a),m=c[l.cross]+g(c)/2,w=e=>{let t=s.get(e.source);return t[l.cross]+g(t)/2};n.sort((e,t)=>w(e)-w(t)||(e.edgeIndex??0)-(t.edgeIndex??0));let M=n.length,v=Math.min(14,(g(c)-10)/(M-1));if(v<4)return;let S=new Map;for(let e of n)S.has(e.source)||S.set(e.source,[]),S.get(e.source).push(e);let k=[],E=[];for(let e=0;e<M;e++){let t=n[e],i=s.get(t.source),r=x(i,a),o=m+(e-(M-1)/2)*v,d=S.get(t.source),h=d.length>1?Math.min(v,(g(i)-10)/(d.length-1)):0,u=i[l.cross]+g(i)/2+(d.indexOf(t)-(d.length-1)/2)*h,f=r+(a?-1:1)*l.sign*(16+e*v),c=Math.min(r,p),y=Math.max(r,p);(f<=c+4||f>=y-4)&&(f=(r+p)/2),k.push({edge:t,source:i,exitMain:r,sCross:u,tCross:o}),E.push(f)}for(let e=0;e<M;){let t=e;for(;t+1<M&&n[t+1].source===n[e].source;)t++;if(t>e&&k[e].tCross-k[e].sCross>0){let i=E.slice(e,t+1).reverse();for(let n=e;n<=t;n++)E[n]=i[n-e]}e=t+1}let N=t=>{let i=[];for(let n=0;n<M;n++){let{edge:r,source:o,exitMain:a}=k[n],s=k[n].sCross,l=k[n].tCross+t,d=E[n],g;if(g=eh(g=s===l?[u(a,s),u(p,l)]:[u(a,s),u(d,s),u(d,l),u(p,l)],o,!0),(g=h(g=eh(g,c,!1))).length<2||!L(o,g[0])||!L(c,g[g.length-1])||!er(g,e,new Set([o.id,c.id])))return;i.push({edge:r,points:g})}return i},P=N(0);if(!P)return;let C=t_(t,P,o,d);if(!0!==C){if("marker-blocked"!==C||!tI(e,t,i))return;let n=-1/0,r=1/0;for(let e of k)n=Math.max(n,e.source[l.cross]+5-e.sCross,c[l.cross]+5-e.tCross),r=Math.min(r,e.source[l.cross]+g(e.source)-5-e.sCross,c[l.cross]+g(c)-5-e.tCross);if(!Number.isFinite(n)||!Number.isFinite(r)||n>0||r<0)return;let a=tO(),s={...d,labelClearance:{nodes:e,style:o}},h;for(let l of[n,r]){if(a.remaining<=0)break;if(0===l)continue;let n=N(l);if(!n||!0!==t_(t,n,o,s))continue;let r=new Map(n.map(e=>[e.edge,e.points]));if(t$(e,t.map(e=>r.has(e)?{...e,points:r.get(e)}:e),e,t,i,o,a)){h=n;break}}if(!h)return;P=h}for(let{edge:e,points:t}of P)e.points=t,e.labelPosition=void 0,e.routeCertificate=void 0;y(P.map(e=>e.edge),r)};for(let e of N.values())C(e,!1);for(let e of P.values())C(e,!0)}(e.nodes,e.edges,e.groups,e.graph,e.bundled,e.style,e.elkResult?void 0:e.style)}},{id:"collapseTinyBundledHitches",after:["applySymmetricFanoutEmissions","applySymmetricParallelEdgeLanes","applyParallelDuplicateLanes"],mutates:["edges"],determinism:"in-place",mayChangeMetrics:{bends:"improve-only"},run:e=>{ef(e.nodes,e.edges,e.bundled)}},{id:"reassignBundledSiblingLabels",after:["collapseTinyBundledHitches"],mutates:["edges"],determinism:"in-place",run:e=>{!function(e,t,i,n,r){let o=new Map(e.map(e=>[e.id,e])),a=new Map;for(let e of t)i.has(e)&&e.label&&H(e,o,n)&&(a.has(e.source)||a.set(e.source,[]),a.get(e.source).push(e));for(let t of a.values())t.length<2||t.length>3||new Set(t.map(e=>e.target)).size<t.length||tC([...t].sort((e,t)=>{let i=o.get(e.target),r=o.get(t.target);return i&&r?eC(i,n)-eC(r,n):(e.edgeIndex??0)-(t.edgeIndex??0)}).map(e=>({edge:e,points:e.points})),e,n,r)}(e.nodes,e.edges,e.bundled,e.graph.direction,e.style)}},{id:"applyRouteContracts",after:["reassignBundledSiblingLabels"],mutates:["edges"],determinism:"fixed-point",freezesNodes:!0,mayChangeMetrics:{straight:{worsenBy:1,whenImproves:["hard","crossings","endpointApproaches"],perImprovement:!0},bends:{worsenBy:4,whenImproves:["hard","crossings","endpointApproaches"],perImprovement:!0},portRate:{worsenBy:1,whenImproves:["hard","crossings","bends","endpointApproaches","opposingOverlaps"]}},run:e=>{v({nodes:e.nodes,edges:e.edges,groups:e.groups},e.graph,e.bundled,e.style,e.elkResult?void 0:{preserveSelfLoops:!0,preserveLabels:!0,preserveStraightRoutes:!0})}},{id:"reanchorOffOutlineEndpoints",after:["applyRouteContracts"],mutates:["edges"],determinism:"in-place",run:e=>{ed(e.nodes,e.edges,e.graph)}},{id:"rerouteEdgesThroughNodes",after:["reanchorOffOutlineEndpoints"],mutates:["edges"],determinism:"in-place",run:e=>{eg(e.nodes,e.edges,e.graph,void 0,e.groups)}},{id:"repairLabelsOnSharedTrunks",after:["rerouteEdgesThroughNodes"],mutates:["edges"],determinism:"in-place",run:e=>{N({nodes:e.nodes,edges:e.edges,groups:e.groups},e.graph,e.style)}},{id:"repairLabelsOffOwnRoute",after:["repairLabelsOnSharedTrunks"],mutates:["edges"],determinism:"in-place",run:e=>{P({nodes:e.nodes,edges:e.edges,groups:e.groups},e.graph,e.style)}},{id:"separateEdgeLabelPills",after:["repairLabelsOffOwnRoute"],mutates:["edges"],determinism:"in-place",run:e=>{C({nodes:e.nodes,edges:e.edges,groups:e.groups},e.graph,e.style,e.elkResult?void 0:{preserveRouteClearance:!0})}},{id:"closeRouteContracts",after:["separateEdgeLabelPills"],mutates:["edges"],determinism:"fixed-point",mayChangeMetrics:{straight:"improve-only",bends:"improve-only"},run:e=>{R({nodes:e.nodes,edges:e.edges,groups:e.groups},e.graph,e.style)}},{id:"translateGeometryToNonNegativeOrigin",after:["closeRouteContracts"],mutates:["translate"],determinism:"in-place",run:e=>{g(e.nodes,e.edges,e.groups,e.layoutPadding,e.style)}},{id:"placeStateNotes",after:["translateGeometryToNonNegativeOrigin"],mutates:["translate"],determinism:"in-place",enabled:e=>!!e.graph.stateNotes?.length,run:e=>{e.notes=function(e,t,i,n,r,o,a){let s=n.stateNotes??[];if(0===s.length)return[];let l=[],d=e=>{for(let t of e)l.push(t),d(t.children)};d(i);let h=[];for(let t of e)h.push({x:t.x,y:t.y,w:t.width,h:t.height});for(let e of l)h.push({x:e.x,y:e.y,w:e.width,h:e.height});for(let e of t){if("invisible"===e.style)continue;for(let t=1;t<e.points.length;t++){let i=e.points[t-1],n=e.points[t];h.push({x:Math.min(i.x,n.x)-2,y:Math.min(i.y,n.y)-2,w:Math.abs(i.x-n.x)+4,h:Math.abs(i.y-n.y)+4})}let t=e.label?Z(e,r):null;t&&h.push(t)}let g=(e,t)=>e.x<t.x+t.w&&e.x+e.w>t.x&&e.y<t.y+t.h&&e.y+e.h>t.y,u=[];for(let t of s){let i=e.find(e=>e.id===t.target),n=i?void 0:l.find(e=>e.id===t.target),o=i??n;if(!o)continue;let s=F(tn(t.text,t.textContent),r,"note"),d=s.width+20,f=s.height+16,c=o.y+(o.height-f)/2,p="left"===t.side?o.x-a-d:o.x+o.width+a;for(let e=0;e<h.length+u.length+4;e++){let e={x:p-6,y:c-6,w:d+12,h:f+12},i=h.find(t=>g(e,t))??u.map(e=>({x:e.x,y:e.y,w:e.width,h:e.height})).find(t=>g(e,t));if(!i)break;p="left"===t.side?i.x-6-d:i.x+i.w+6}u.push({id:t.id,target:t.target,side:t.side,text:t.text,...t.textContent?{textContent:t.textContent}:{},textBlock:s,x:p,y:c,width:d,height:f})}let f=0,c=0;for(let e of u)f=Math.min(f,e.x),c=Math.min(c,e.y);if(f<0||c<0){let n=f<0?-f+o:0,r=c<0?-c+o:0,a=e=>{e.x+=n,e.y+=r,e.children.forEach(a)};for(let t of e)t.x+=n,t.y+=r;for(let e of i)a(e);for(let e of t){for(let t of e.points)t.x+=n,t.y+=r;e.labelPosition&&(e.labelPosition.x+=n,e.labelPosition.y+=r)}for(let e of u)e.x+=n,e.y+=r}return u}(e.nodes,e.edges,e.groups,e.graph,e.style,e.layoutPadding,e.stateNoteMargin)}}];function t9(i,n){for(let r of i.nodes)r.labelBlock??=F(tn(r.label,r.labelContent),n,"node"),!r.icon||r.iconFallbackBlock||t(r.icon)||(r.iconFallbackBlock=eZ(e(r.icon),{fontSize:10,fontWeight:400}));for(let e of i.edges)void 0!==e.label&&(e.labelBlock??=F(tn(e.label,e.labelContent),n,"edge"));let r=e=>{e.labelBlock??=F(tn(e.label,e.labelContent),n,"group"),e.headerHeight=t6(e,n,e.labelBlock),e.children.forEach(r)};i.groups.forEach(r)}function t7(e,t){let i={nodes:e.nodes,edges:e.edges,groups:e.groups,width:0,height:0};return _(e.graph,i,t,e.style,e.bundled)}function ie(e,t,i=!1,n=eW.padding,r=eT({}),o=18){let a=[],s=[],l=new Set;for(let e of t.subgraphs)!function e(t,i){for(let n of(i.add(t.id),t.children))e(n,i)}(e,l);return function e(t,i,n,r,o,a,s){if(t.children)for(let l of t.children){let t=(l.x??0)+a,d=(l.y??0)+s,h=l.width??0,g=l.height??0;if(n.has(l.id)){let a=[];e(l,i,n,r,a,t,d);let s=eL(i.subgraphs,l.id),u=s?.stateComposite?eG(l.id,i):void 0;o.push({id:l.id,label:s?.label??"",...s?.labelContent?{labelContent:s.labelContent}:{},x:t,y:d,width:h,height:g,children:a,...s?.headerMinHeight===void 0?{}:{headerMinHeight:s.headerMinHeight},...s?.concurrencyRegion?{concurrencyRegion:!0}:{},...u?{inlineStyle:u}:{}})}else{let a=i.nodes.get(l.id);if(a){let e=eV(l.id,i),n=i.classAssignments.get(l.id),o=n?n.split(/\s+/).filter(Boolean):void 0;r.push({id:l.id,label:a.label,...a.labelContent?{labelContent:a.labelContent}:{},...a.labelBlock?{labelBlock:a.labelBlock}:{},shape:a.shape,...void 0!==a.floatingNoteId?{floatingNoteId:a.floatingNoteId}:{},...void 0!==a.semanticShape?{semanticShape:a.semanticShape}:{},x:t,y:d,width:h,height:g,inlineStyle:e,classNames:o,...a.icon?{icon:a.icon}:{},...a.image?{image:a.image}:{},...a.iconForm?{iconForm:a.iconForm}:{},...a.href?{href:a.href}:{}})}l.children&&l.children.length>0&&e(l,i,n,r,o,t,d)}}}(e,t,l,a,s,0,0),it({width:e.width??800,height:e.height??600,nodes:a,edges:[],groups:s},t,i,n,r,o,e)}function it(e,t,i,n,r,o,a,s){let{nodes:l,edges:d,groups:h}=e,g=ew(h),u={elkResult:a,graph:t,nodes:l,edges:d,groups:h,notes:[],margins:g.length>0?{leftX:Math.min(...g.map(e=>e.x))-20,rightX:Math.max(...g.map(e=>e.right))+20}:void 0,bundled:new Set,genericBundled:!1,mergeEdges:i,style:r,layoutPadding:n,stateNoteMargin:o,frozen:!1};if(s)for(let e of s)u.bundled.add(d[e]);t9(u,r),function(e,t,i={}){let n=new Set,r=e.frozen;for(let o of t){if(o.enabled&&!o.enabled(e)){n.add(o.id);continue}for(let e of o.after)if(!n.has(e))throw new to(o.id,"ordering",`LayoutPass ordering: '${o.id}' must run after '${e}', which has not run`);let t=Object.entries(o.mayChangeMetrics??{}),a=e=>"improve-only"!==e&&e.whenImproves?"string"==typeof e.whenImproves?[e.whenImproves]:e.whenImproves:[],s=[];for(let[e,i]of t)for(let t of(s.includes(e)||s.push(e),a(i)))s.includes(t)||s.push(t);let l=o.proposal?s.includes("hard")?[...s]:[...s,"hard"]:s;if((t.length||o.proposal)&&!i.measureMetrics)throw new to(o.id,"measurement",`Layout pass '${o.id}' declares metric budgets but no geometry measurement was supplied`);let d=(t=s)=>{try{return i.measureMetrics(e,t)}catch(e){throw e instanceof to?e:new to(o.id,"measurement",`Layout pass '${o.id}' could not measure its declared geometry: ${e instanceof Error?e.message:String(e)}`)}},h=t.length||o.proposal?d(l):void 0,g=r?ts(e).map(({id:e,x:t,y:i,width:n,height:r})=>({id:e,x:t,y:i,width:n,height:r})):void 0,u=r?(e.edges??[]).map(e=>({points:e.points?.map(e=>({...e})),labelPosition:e.labelPosition?{...e.labelPosition}:void 0,certificate:e.routeCertificate})):void 0,f=(e=!1)=>{let i;if(h){let n=d(e?l:s),r=e=>{let t=h[e],i=n[e];if(void 0===t||void 0===i||!Number.isFinite(t)||!Number.isFinite(i))throw new to(o.id,"measurement",`Layout pass '${o.id}' has no finite measurement for ${e}`);return("straight"===e||"portRate"===e?-1:1)*(i-t)};for(let[s,l]of e&&o.proposal?[...t,["hard","improve-only"]]:t){let e=Math.max(0,...a(l).map(e=>-r(e))),t="improve-only"===l||l.whenImproves&&e<=1e-6?0:l.worsenBy*(l.perImprovement?Math.floor(e+1e-6):1);if(r(s)>t+1e-6){let e=new ta(o.id,s,h[s],n[s],t);if("hard"===s)throw e;i??=e}}}return i},c=()=>{if(g){let t=ts(e),i=o.mutates.includes("translate"),n=i&&g[0]&&t[0]?t[0].x-g[0].x:0,r=i&&g[0]&&t[0]?t[0].y-g[0].y:0,a=(e,t)=>i?1e-6>=Math.abs(t.x-e.x-n)&&1e-6>=Math.abs(t.y-e.y-r):e.x===t.x&&e.y===t.y;if(t.length!==g.length||!e.frozen)throw new to(o.id,"freeze",`LayoutPass freeze: '${o.id}' changed frozen geometry membership or state`);for(let e=0;e<g.length;e++){let i=g[e],n=t[e];if(i.id!==n.id||i.width!==n.width||i.height!==n.height||!a(i,n))throw new to(o.id,"freeze",`LayoutPass freeze: '${o.id}' moved frozen geometry without a uniform translation`)}if(u){if((e.edges?.length??0)!==u.length)throw new to(o.id,"freeze",`LayoutPass freeze: '${o.id}' changed frozen edge membership`);for(let t=0;t<u.length;t++){let n=u[t],r=e.edges[t],s=n.points?.length===r.points?.length&&(n.points??[]).every((e,t)=>r.points?.[t]&&a(e,r.points[t]));if(i){if(!s||!!n.labelPosition!=!!r.labelPosition||n.labelPosition&&!a(n.labelPosition,r.labelPosition))throw new to(o.id,"freeze",`LayoutPass freeze: '${o.id}' did not translate all frozen routes and labels uniformly`)}else if(!s&&(!o.mutates.includes("edges")||void 0===r.routeCertificate||r.routeCertificate===n.certificate))throw new to(o.id,"certificate",`LayoutPass certificate: '${o.id}' rewrote edge geometry after the route-contract freeze without re-issuing routeCertificate`)}}}},p=o.run(e);if(p&&!o.proposal)throw new to(o.id,"metric-budget",`Layout pass '${o.id}' returned a rollback without declaring a cosmetic proposal`);let y=f();if(c(),y){if(!p)throw y;p();let e=f(!0);if(e)throw e;c()}o.freezesNodes&&(e.frozen=!0),r||=e.frozen,n.add(o.id),i.onAfterPass?.(o,e)}}(u,t3,{measureMetrics:t7});let f=e.width,c=e.height,p=eB.width;for(let e of l)f=Math.max(f,e.x+e.width+n),c=Math.max(c,e.y+e.height+n);for(let e of ew(h))f=Math.max(f,e.right+n),c=Math.max(c,e.bottom+n);for(let e of d){for(let t of e.points)f=Math.max(f,t.x+p+n),c=Math.max(c,t.y+p+n);let t=e.labelBlock?Z(e,r):null;t&&(f=Math.max(f,e.labelPosition.x+60+n,t.x+t.w+n),c=Math.max(c,e.labelPosition.y+20+n,t.y+t.h+n))}for(let e of u.notes)f=Math.max(f,e.x+e.width+n),c=Math.max(c,e.y+e.height+n);return{genericBundled:u.genericBundled,positioned:{width:f,height:c,nodes:l,edges:d,groups:h,...u.notes.length>0?{notes:u.notes}:{}}}}function ii(e,t={}){eX(e);let i=t.graphLayout?e7(t,()=>{let i=eT(t,t.stateVisual?.styleDefaults,t.styleFace);return r(e,t,i,is)},()=>il(e,t),!0,(e,t)=>{e.layoutDecision=t}):il(e,t),n=eT(t,t.stateVisual?.styleDefaults,t.styleFace);t9(i,n);let o=e_(t.diagramTitle,eT(t,t.stateVisual?.styleDefaults,t.styleFace));if(!o)return i;let a=t.padding??eW.padding;if(0===i.width&&0===i.height)return Object.assign(i,eD(o,a));(function(e,t){let i=e=>{for(let n of(e.y+=t,e.children))i(n)};for(let i of e.nodes)i.y+=t;for(let t of e.groups)i(t);for(let i of e.edges){for(let e of i.points)e.y+=t;i.labelPosition&&(i.labelPosition.y+=t)}for(let i of e.notes??[])i.y+=t})(i,o.height),i.height+=o.height,i.width=Math.max(i.width,o.width+2*a),i.title=eH(o,i.width,a);let s=tg(i,n);if(s.length)throw new e4([{strategy:"final-title-projection",violations:s}]);return i}function ir(e,t={}){eX(e);let i=il(e,t,"placement");return t9({...i,edges:[]},eT(t,void 0,t.styleFace)),i}function io(e,t={}){eX(e);let i=eT(t,void 0,t.styleFace);return o(e,t,i,is)}function ia(e,t,r,o=!1){let a=t.stateVisual,s={...eW,...t,...a?{stateVisual:a}:{}},l=eT(t,a?.styleDefaults,t.styleFace),d=tq(e,s,l);if(o&&!a){let t=((...e)=>n().indexedForestLayout(...e))(e,d,s.padding,s.nodeSpacing,s.layerSpacing);if(!t)throw Error("Graph is ineligible for indexed forest layout");let i=ie(t,e,eW.mergeEdges,s.padding,l,18);return i.genericBundled&&r?.(i.positioned,()=>ie(t,e,!1,s.padding,l,18).positioned),i.positioned}if(1===e.nodes.size&&0===e.edges.length&&0===e.subgraphs.length&&!e.stateNotes?.length&&!a&&d.children?.length===1){let t=d.children[0];return ie({...d,width:t.width+2*s.padding,height:t.height+2*s.padding,children:[{...t,x:s.padding,y:s.padding}]},e,eW.mergeEdges,s.padding,l,18).positioned}let h,g,u="exception",f=0;for(let t of[{},{"elk.layered.feedbackEdges":"false"},{"elk.layered.feedbackEdges":"false","elk.layered.compaction.postCompaction.strategy":"NONE"},{"elk.layered.feedbackEdges":"false","elk.layered.compaction.postCompaction.strategy":"NONE","elk.layered.crossingMinimization.forceNodeModelOrder":"false","elk.layered.highDegreeNodes.treatment":"false"}]){++f>1&&e0("elk-degradation",u,f);let n=0===Object.keys(t).length?d:tq(e,s,l);Object.keys(t).length>0&&(n.layoutOptions={...n.layoutOptions,...t});try{let e=i(n);if(id(e)){g=Error("ELK returned non-finite layout geometry"),u="non-finite-geometry";continue}h=e;break}catch(e){if(e instanceof ej||e instanceof e8)throw e;g=e,u="exception"}}if(!h)throw g;let c=h,p=a?.noteMargin??18,y=ie(c,e,eW.mergeEdges,s.padding,l,p);return y.genericBundled&&r?.(y.positioned,()=>ie(c,e,!1,s.padding,l,p).positioned),y.positioned}var is={edgeSelectorIndices:ez,graphEdgeMarkerPaintRegions:j,customTextMeasurementActive:tt,certifyCandidate:tu,retainSelection:ty,countEdgeCrossings:a,countOpposingRouteOverlaps:$,countParallelRouteOverlaps:z,measureLabelConflicts:I,DEFAULTS:eW,LABEL_PILL_PADDING:q,measureRenderStage:e6,graphTextBlock:F,resolveLabelContent:tn,groupTitleWidth:t5,groupHeaderHeight:t6,estimateNodeSize:tG,resolveNodeInlineStyle:eV,resolveEdgeInlineStyle:eU,resolveClassInlineStyle:eG,containsNonFiniteNumber:id,finishGraphGeometry:it,unsupported:e=>{throw new e9(e)}};function il(e,t,i){let r=eT(t,t.stateVisual?.styleDefaults,t.styleFace),o=t=>(function e(t,i,n){return t.some(t=>{let r=eL(i.subgraphs,t.id);return void 0!==r&&t.width+.5<t5(r,n)||e(t.children,i,n)})})(t.groups,e,r),a=!1!==t.compareRoutePreferences,s=new WeakMap,l=a&&ep(e)&&!t8(e.edges)?(e,t)=>{s.set(e,t)}:void 0,d=e.subgraphs.length>0&&!t2(e,t),h=[{strategy:"default",produce:()=>ia(e,t,l),preferNext:o}],g=(t.nodeSpacing??eW.nodeSpacing)>0&&(t.layerSpacing??eW.layerSpacing)>0,u=void 0===t.graphLayout&&ti("indexed-layout")&&g&&!t.stateVisual&&!t.preserveSubgraphChildOrder&&function(e){if(e.nodes.size<2||e.subgraphs.length>0||e.stateNotes?.length||e.edges.length>=e.nodes.size||[...e.nodes.values()].some(e=>"rectangle"!==e.shape))return!1;let t=new Map,i=new Map;for(let n of e.edges){if(void 0!==n.label||(n.length??1)!==1||n.source===n.target||!e.nodes.has(n.source)||!e.nodes.has(n.target)||t.has(n.target))return!1;t.set(n.target,1);let r=i.get(n.source);r?r.push(n.target):i.set(n.source,[n.target])}let n=[...e.nodes.keys()].filter(e=>!t.has(e));for(let e=0;e<n.length;e++)for(let t of i.get(n[e])??[])n.push(t);return n.length===e.nodes.size}(e)&&(n(),1)?{strategy:"indexed-forest",produce:()=>ia(e,t,l,!0),preferNext:o}:void 0;return t.separateHierarchy||h.push({strategy:"separate-hierarchy",produce:()=>ia(e,{...t,separateHierarchy:!0},l),preferNext:o,qualityAlternative:a&&d}),t.disableCorankFanIn||eO("APL_NO_CORANK_FANIN")||(h.push({strategy:"without-corank",produce:()=>ia(e,{...t,disableCorankFanIn:!0},l),preferNext:o,qualityAlternative:a&&tU(e,r).size>0}),t.separateHierarchy||h.push({strategy:"separate-without-corank",produce:()=>ia(e,{...t,separateHierarchy:!0,disableCorankFanIn:!0},l),preferNext:o,qualityAlternative:a&&d})),"placement"===i?function(e,t,i,n){let{selected:r}=tp(e,t,i,n,"placement");td(e,r.positioned);let{width:o,height:a,nodes:s,groups:l}=r.positioned;return{width:o,height:a,nodes:s,groups:l}}(e,r,h,u):function(e,t,i,n,r){let o=tp(e,t,i,r),a=ty(e,o),s=n(a,o.selected.score);if(!s)return a;let l={...o.selected,strategy:"bundled"},d=tu(e,t,s),h=[{strategy:l.strategy,score:l.score}];d.certified&&h.push({strategy:d.certified.strategy,score:d.certified.score});let g=d.certified?tc(l,d.certified):{selected:l,reason:"alternative-invalid"},u=g.selected.positioned;return td(e,u),u.certification={...a.certification,preference:{...a.certification.preference,selectedScore:g.selected.score,routing:{strategy:g.selected===l?"bundled":s.strategy,preference:{selectedScore:g.selected.score,reason:g.reason,compared:h}}}},u}(e,r,h,(e,t)=>{let i=s.get(e);if(!(!i||0===t.edgeCrossings&&0===t.labelConflicts))return{strategy:"without-generic-bundling",produce:i,preferNext:o}},u)}function id(e,t=new Set){return"number"==typeof e?!Number.isFinite(e):!(null===e||"object"!=typeof e||t.has(e))&&(t.add(e),Array.isArray(e)?e.some(e=>id(e,t)):Object.values(e).some(e=>id(e,t)))}export{ii as a,ir as b,io as c};
@@ -1,6 +0,0 @@
1
- import{b as e,c as t}from"./chunk-MSP3S2VS.js";import{b as n,d as i}from"./chunk-SBXYR7Z3.js";import{q as o,r as a,w as r}from"./chunk-KXPF5KIU.js";import{b as l,c as s,f as d,g as c}from"./chunk-HDKHAM2V.js";import{S as h,e as p,g as g,i as u,j as f,k as x,l as b,m as m,p as y,q as k,u as w,v as v,w as M,x as S}from"./chunk-SJYDRC6G.js";import{c as I,h as $,i as L,k as C,ma as P,oa as W,r as q,s as H,y as F}from"./chunk-GMTB5UTY.js";import{F as E,H as z,I as Y,R as B,U as T,V as _,W as N,bb as O,ib as j,jb as X,kb as A,m as D,mb as R,o as U,qb as V,u as Z,ub as G}from"./chunk-EUBVLDYV.js";import{A as J,B as K,G as Q,H as ee,I as et,S as en,X as ei,r as eo,s as ea,w as er,y as el,z as es}from"./chunk-P7DO3MRP.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("#")||L.has(t)||n(t)?`#38;${t.replace("#","#35;")}#59;`:`&${t};`;if(!i.startsWith("#")&&!L.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+;|${$.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=el(J(K(e)),eu,e=>i(e,eg));return{value:t,content:Object.freeze({value:t,authored:e,prepared:n})}}(e),n=i(K(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 E||!!/^(?:#|(?:rgb|rgba|hsl|hsla)\()/i.test(e)&&null!==T(e)}function ek(e){let t=E[e.toLowerCase()];if(t)return t;let n=z(e);if(n)return Y(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?Y(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(["--|","-|","--/","-/","--\\","-\\","|--","|-","/--","/-","\\--","\\-"]),eS=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]})),eI=[...ev.keys()].sort((e,t)=>t.length-e.length),e$=eI.map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|"),eL=new RegExp(String.raw`^(\S+?)(\(\))?\s*(${e$})`),eC=new RegExp(String.raw`^(\S+?)\s+(\(\))\s*(${e$})`),eP=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"]),eW=new Set([...eP,"acctitle","accdescr"]),eq=/(?:#\w+;|[^\/\\\+\()\+<\->\->:\n,;])+((?!(\-x|\-\-x|\-\)|\-\-\)|\-\|\\|\-\\|\-\/|\-\/\/|\-\|\/|\/\|\-|\\\|\-|\/\/\-|\\\\\-|\/\|\-|\-\-\|\\|\-\-|\(\)))[\-]*(?:#\w+;|[^\+<\->\->:\n,;])+)*/iy;function eH(e,t){return eq.lastIndex=t,eq.exec(e)?.[0].trim()??""}function eF(e,t){if(!e||e.trim()!==e||/[\r\n]/.test(e))return!1;let n=C(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&&eP.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)||eP.has(i)&&!["title","link","links","properties","details"].includes(i)||"receiver"===t&&["acctitle","accdescr"].includes(i)||/^(?:left|right) of\b/.test(i))&&eH(`${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=F(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:K(l.accessibility.title)}:{},...void 0!==l.accessibility.descr?{accessibilityDescription:K(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 H({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(C(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=eI.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)||eP.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("()")||eW.has(h.toLowerCase())))return null;let u=C(e),f=C(i),x=C(h),b=C(e.slice(0,e.length-l.length)).length,m=eH(u,0);return m.length<=f.length&&(m!==f||eH(u,b)!==x)?null:{from:i,arrow:eS.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 en)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]])eF(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)),m=b.issues.find(e=>"sequence_block_boundary"===e.syntax);if(m)throw Error(`SEQUENCE_BLOCK_BOUNDARY: line ${d(m.line+1)}: ${m.message}`);let y=new Map,k=[],w=new Map,v={visible:!0===i.showSequenceNumbers,next:1,step:1},M=[],S=[],I=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),v.visible&&(a.number=v.next),v.next=Math.round((v.next+v.step)*100)/100,eD(M,e=>e===n,e=>{f.set(e,c.messages.length),p("sequence")&&u("sequence","bind-create",{id:e,messageIndex:c.messages.length})}),eD(S,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&&M.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":v.visible=null!==a.numbering,a.numbering?.next!==void 0&&(v.next=a.numbering.next,v.step=a.numbering.step??1),p("sequence")&&u("sequence","set-autonumber",v);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":S.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=y.get(e)?.parent)y.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=O(e);if(!t)return;let n=t.toLowerCase();if("transparent"===n||Object.hasOwn(E,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");y.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:y.get(t.parent)?.dividers.length??0,noteIndices:[],childBlockIndices:[],childSectionIndices:[]}),k.push({kind:"open",blockId:e,messageIndex:c.messages.length,noteIndex:c.notes.length}),p("sequence")&&u("sequence","open-block",{id:e,block:y.get(e)});break}case"continuation":{let e=void 0!==t.parent?y.get(t.parent):void 0;e&&(k.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=y.get(t.closes);if(e){let n=c.blocks.length;w.set(t.closes,n),k.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&&(y.get(e.parent)?.childBlockIndices.push(n),y.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":I(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,k.map(({blockId:e,...t})=>({...t,blockIndex:w.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(C(e))}function ej(e){let t=eO(e);return t&&eF(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 q{};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=Z(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 eV(e,t,n){return{x:e.x+t,y:e.y+n,width:e.width,height:e.height}}function eZ(e,t,n){return{...e,x:e.x+t,y:e.y+n,bounds:eV(e.bounds,t,n)}}function eG(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 eK(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*eo/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 S=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 S=w+o.firstLineOffset+(o.metrics.lines.length-1)/2*o.metrics.lineHeight,I=eR(o.displayLabel,m+8,S,"start",d.edgeLabelFontSize,d.edgeLabelFontWeight,d.edgeLetterSpacing,o.block);return M=Math.max(M,I.bounds.y+I.bounds.height+d.groupPaddingY),{y:w,label:o.label,labelPosition:{...I,text:o.displayLabel}}}),I="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:S,...I?{header:I}:{},bounds:$}}function eQ(e,t,n){for(let i of e.actors)i.x+=t,i.y+=n,i.bounds=eV(i.bounds,t,n),i.labelPosition=eZ(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=eZ(e.labelPosition,t,n),e.bounds=eV(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=eV(i.bounds,t,n),i.header&&(i.header={...i.header,x:i.header.x+t,y:i.header.y+n,label:eZ(i.header.label,t,n)}),i.dividers))e.y+=n,e.labelPosition&&(e.labelPosition=eZ(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:f.nodeLabel,edgeLabelFontSize:f.edgeLabel,groupHeaderFontSize:f.edgeLabel,nodeLabelFontWeight:x.nodeLabel,edgeLabelFontWeight:x.edgeLabel,groupHeaderFontWeight:x.groupHeader,nodePaddingX:16,nodePaddingY:6,nodeCornerRadius:4,nodeLineWidth:b.outerBox,edgeLineWidth:b.connector,groupCornerRadius:0,groupPaddingX:10,groupPaddingY:8,groupLabelPaddingX:6,groupLineWidth:b.outerBox};function e1(e,t={},n={},i){let o=k(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=>D(i,"actor",{category:e.id},{includeFallback:!1})),h=Math.max(n.height??40,...c.map(e=>ea("Mg",e?.fontSize??o.nodeLabelFontSize,e?.fontWeight??o.nodeLabelFontWeight).height+(e?.paddingY??o.nodePaddingY)*2)),p=ea("Mg",e0.edgeLabelFontSize,e0.edgeLabelFontWeight).height,g=ea("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),y=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:er(e.title,e.titleContent),o,a,r);let w=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=Z(er(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:Z("⋯",{display:"literal",fontSize:10,fontWeight:400})}:{},labelMetrics:f,width:b,height:m}}),v=w.map(e=>e.width),M=new Map;for(let t=0;t<e.actors.length;t++)M.set(e.actors[t].id,t);let S=e.messages.map(e=>{var t;let i,a,r,l,s,c,h,p,g,u,f,x,b,y,k;return s=(l=Z((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:J((i=er(t.label,t.labelContent),void 0!==t.number?es([`${t.number}. `,"string"==typeof i?J(i):i]):i))})).prepared,{transform:o.edgeTextTransform,fontSize:o.edgeLabelFontSize,fontWeight:o.edgeLabelFontWeight,letterSpacing:o.edgeLetterSpacing,...t.wrap?{maxWidth:240}:{}})).text,c=o.edgeLabelFontSize*eo,h=a?l:{width:0,height:0,lines:[],lineHeight:c},p=Math.max("none"!==t.startHead?m.width:0,5*!!t.centralStart),g=Math.max("none"!==t.endHead?m.width:0,5*!!t.centralEnd),u=Math.max(o.lineWidth/2,"none"!==t.startHead||"none"!==t.endHead?m.height/2:0,t.centralStart||t.centralEnd?4.75:0),f=Math.max(16,p+g+8),x=h.width+f,y=(b=30+(h.width>0?8+h.width:0))+Math.max(12,d/2+8),k=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:y,extraAboveHeight:k}}),I=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=S[t],o=M.get(n.from),a=M.get(n.to);if(void 0===o||void 0===a)continue;if(o===a){o<e.actors.length-1&&(I[o]=Math.max(I[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?v[a]/2:0,c=(i.requiredSpanWidth+d)/s;for(let e=r;e<l;e++)I[e]=Math.max(I[e],c)}let $=[],L=a+v[0]/2;for(let t=0;t<e.actors.length;t++){if(t>0){let e=(v[t-1]+v[t])/2;L+=Math.max(void 0!==n.actorMargin?e+n.actorMargin:Math.max(140,e+40),I[t-1]??0)}$.push(L)}let C=(e.boxes??[]).flatMap((t,i)=>{let a=e.actors.flatMap((e,t)=>e.box===i?[t]:[]),r=t.label?Z(er(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}]:[]}),P=Math.max(22,...C.map(e=>(e.block?.height??0)+8)),W=r+(C.length>0?P+6:0),q=e.actors.map((e,t)=>eG(e,w[t],$[t],W)),H=e.actors.flatMap((t,n)=>{if(void 0!==t.createMessageIndex&&t.createMessageIndex<e.messages.length)return[];let i=q[n].bounds;return[i.y+i.height]}),F=H.length>0?Math.max(...H):W+h,E=F+26,z=[],Y=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=Z("rect"===(t={...e,wrap:e.wrap??n.wrap,dividers:e.dividers.map(e=>({...e,wrap:e.wrap??n.wrap}))}).type?"":t.label?es([`${t.type} [`,J(er(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*eo,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=Z(e.label?es(["[",J(er(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:y+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,X=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=Y[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 A=new Set,R=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=Y[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)||R.add(n),r=t,l=s}o.childBlockIndices.some(t=>e.blocks[t].startIndex===Y[t].endMessageExclusive&&0===Y[t].noteIndices.length)&&R.add(n)}for(let t=0;t<e.blocks.length;t++){let e=j.get(t);R.has(t)&&void 0!==e&&R.add(e)}}let U=e=>(N.get(e)??[]).filter(t=>!A.has(t)&&Y[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(R.has(t)||"par_over"===e.blocks[t].type)continue;let n=B[t],i=Y[t];for(let[o,a]of n.dividers.entries()){let n=eJ(e.blocks[t],i,e,o);if(void 0!==n){X.set(n,Math.max(X.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 G=new Map,K=new Map,Q=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=G.get(n.createMessageIndex)??[];e.push(t),G.set(n.createMessageIndex,e)}if(void 0!==n.destroyMessageIndex&&n.destroyMessageIndex<e.messages.length){let e=K.get(n.destroyMessageIndex)??[];e.push(n.id),K.set(n.destroyMessageIndex,e)}}let ee=new Map;for(let t=0;t<e.notes.length;t++){let n=e.notes[t],i=ee.get(n.afterIndex)??[];i.push({note:n,index:t}),ee.set(n.afterIndex,i)}let et=Array(e.notes.length),en=new Map,ei=[],el=new Map;for(let t of e.activationEvents??[]){let e=el.get(t.messageIndex)??[];e.push(t),el.set(t.messageIndex,e)}let ed=(e,t)=>{let n=en.get(e)??[];n.push({startY:t,depth:n.length}),en.set(e,n)},ec=(e,t)=>{let n=en.get(e);if(!n||0===n.length)return;let{startY:i,depth:o}=n.pop(),a=M.get(e);void 0===a||t<=i||ei.push({actorId:e,x:$[a]-d/2+4*o,topY:i,bottomY:t,width:d})},eh=(e,t)=>{for(let n of el.get(e)??[])"activate"===n.kind?ed(n.actorId,t):ec(n.actorId,t)},ep=(e,t)=>{let i=Z(er(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=M.get(e.actorIds[0]??"")??0,d;if("left"===e.position)d=$[l]-v[l]/2-a-s;else if("right"===e.position)d=$[l]+v[l]/2+s;else if(e.actorIds.length>1){let t=M.get(e.actorIds[e.actorIds.length-1]??"")??l;d=($[l]+$[t])/2-a/2}else d=$[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=F,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++)z[e]&&a.push(z[e].bounds);for(let e of Y[o].noteIndices)e<r.noteEnd&&et[e]&&a.push(et[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,Y[o],e,s),p=void 0!==h&&h<r.noteEnd?et[h]:void 0===h&&d.index<r.messageEnd?z[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},eS=e=>{let t=[];for(let n=e;void 0!==n&&!A.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:[]},A.add(n),ex=eb=i+B[n].enclosingHeaderStep}},eI=t=>{let n=e.blocks[t],i=Y[t],a=eu[t]?.top,r=void 0!==a&&n.startIndex===i.endMessageExclusive&&0===i.noteIndices.length?a+B[t].blockPadTop:et[i.noteIndices[0]??-1]?.y??E;A.add(t);let l=eK(n,B[t],i,e,M,q,z,et,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),E=Math.max(E,ex+f/2),ev.delete(t))},e$=()=>{if(T){for(;ek<T.length;){let t=T[ek];if(t.messageIndex>z.length||t.noteIndex>em)break;let n=t.blockIndex;if("open"===t.kind&&R.has(n)&&eS(n),"open"===t.kind&&"par_over"===e.blocks[n].type){eS(n);let i=Math.max(0,...B[n].dividers.map(e=>e.noteContentOffset));eb+=i,ex=eb,E=Math.max(E,eb+f/2),ev.set(n,{messageY:E,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=Y[n].childBlockIndices.filter(e=>eg[e]),({messageY:E,contentBottom:ex,completedBottom:ef,reservedBottom:eb}=e),ew++,ek++;continue}let i=B[n].dividers[t.dividerIndex],o=Math.max(ex,ef,eb)+8;R.has(n)?(eu[n].dividerY[t.dividerIndex]=o,ex=eb=o+i.noteContentOffset):eb=o+i.noteContentOffset}"close"===t.kind&&eI(n),ek++}return}for(;ey<e.blocks.length;){let e=ey,t=Y[e];if(t.endMessageExclusive>z.length||t.endNoteExclusive>em)break;eI(e),ey++}},eL=(e,t)=>{let n=t;for(let{note:t,index:i}of ee.get(e)??[]){let e=ew;for(let t of(e$(),e!==ew&&(n=E),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=>!A.has(e)),a=X.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))A.add(t)}let r=ep(t,n),l=eM(r,void 0,i);l>0&&(n+=l,r=ep(t,n)),et[i]=r,ex=Math.max(ex,r.y+r.height),em=i+1,n=r.y+r.height+4}ee.has(e)&&(E=Math.max(E,n+f/2))};eL(-1,E);for(let t=0;t<e.messages.length;t++){let n=e.messages[t],i=S[t],a=M.get(n.from)??0,r=M.get(n.to)??0,l=n.from===n.to;e$();let s=U(t),d=Math.max(_.get(t)??0,V(s));for(let e of G.get(t)??[]){let t=q[e].height/2;d=d>0?d+Math.max(0,t-12):t+8}E+=d+i.extraAboveHeight;let c=$[a],h=$[r],p=e.actors[r].createMessageIndex!==t||"participant"!==e.actors[r].type||l?h:h-Math.sign(h-c)*v[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,E);for(let n of(z[t]=a,G.get(t)??[]))q[n]=eG(e.actors[n],w[n],$[n],E-q[n].height/2);return a},b=u(),m=b.bounds.y,y=0,k=new Set(s),I=(N.get(t)??[]).filter(e=>k.has(e)||eu[e]?.top!==void 0&&!eg[e]);if(I.length>0){let t=[];for(let n of I){for(let e of Y[n].childBlockIndices)eg[e]&&(t[e]=eg[e]);t[n]=eK(e.blocks[n],B[n],Y[n],e,M,q,z,et,t,o,g,E,eu[n]);let i=eu[n]?.top;void 0!==i?y=Math.max(y,i-t[n].y):m=Math.min(m,t[n].y)}}let L=Math.max(0,y,(s.length>0?Math.max(ex,ef,eb):Math.max(ef,eb))+8*(s.length>0)-m);L>0&&(E+=L,b=u());let C=eM(b.bounds,t);for(let e of(C>0&&(E+=C,b=u()),s))A.add(e);ex=Math.max(ex,b.bounds.y+b.bounds.height,...(G.get(t)??[]).map(e=>q[e].bounds.y+q[e].bounds.height)),eh(t,E);let P=K.get(t);if(P)for(let e of P)Q.set(e,E);n.activate&&ed(n.to,E),n.deactivate&&ec(n.from,E);let W=l?Math.max(x,Math.ceil(i.labelMetrics.height)+10):0;E+=l?W+f:f;let H=G.get(t);if(H){let e=Math.max(...H.map(e=>{let t=q[e];return t.bounds.height-t.height/2}));E+=e}let F=H?ex+8:b.y+W+14;eL(t,F)}e$();let eC=Math.max(z[z.length-1]?.y??E,E-f/2);for(let[t,n]of(eh(e.messages.length,eC),en))for(;n.length>0;)ec(t,eC);for(let t of q)e.actors[M.get(t.id)]?.external&&(t.external=!0);for(let[t,n]of z.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 et.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 eP=et.filter(e=>void 0!==e),eW=eg.reduce((e,t)=>Math.max(e,t.y+t.height),0);eW>0&&(E=Math.max(E,eW+8));let eq=E,eH=C.map(({box:e,memberIdxs:t,block:n})=>{let i=Math.min(...t.map(e=>q[e].bounds.x))-8,o=Math.max(...t.map(e=>q[e].bounds.x+q[e].bounds.width))+8;return e.label&&(o=Math.max(o,i+n.width+16)),{label:e.label,block:n,labelY:r+P/2,color:e.color,x:i,y:r,width:o-i,height:eq+8-r}}),eF=E+r,eY=a,eB=0;for(let e of q){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 eP)eY=Math.min(eY,e.x),eB=Math.max(eB,e.x+e.width);for(let e of eH)eY=Math.min(eY,e.x),eB=Math.max(eB,e.x+e.width);for(let e of ei)eY=Math.min(eY,e.x),eB=Math.max(eB,e.x+e.width);for(let e of z){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){eQ({actors:q,messages:z,blocks:eg,notes:eP,boxes:eH,activations:ei,lifelines:[],destructions:[]},eT,0);for(let e=0;e<$.length;e++)$[e]+=eT}let e_=e.actors.map((e,t)=>{let n=q[t],i=n.bounds.y+n.bounds.height;return{actorId:e.id,x:$[t],topY:i,bottomY:Q.get(e.id)??eF-r}}),eN=e.actors.filter(e=>Q.has(e.id)).map(e=>({actorId:e.id,x:$[M.get(e.id)],y:Q.get(e.id)}));return e2({width:Math.max(eB+eT+a,200),height:Math.max(eF,100),accessibilityTitle:e.accessibilityTitle,accessibilityDescription:e.accessibilityDescription,actors:q,lifelines:e_,messages:z,activations:ei,blocks:eg,notes:eP,boxes:eH,destructions:eN},void 0===e.title?void 0:er(e.title,e.titleContent),o,a,r)}function e2(e,t,n,i,o){let a=w(t,n);if(!a)return e;if(0===e.width&&0===e.height)return{...e,...v(a,i,o)};let r=a.height;eQ(e,0,r);let l=Math.max(e.width,a.width+2*i);return{...e,width:l,height:e.height+r,title:M(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=k(c,e0,d.styleFace),f=`seq-${ei(l.width,l.height,l.actors.length,l.messages.length)}`,x=`${f}-title`,w=`${f}-desc`,v=V(l.accessibilityTitle,l.accessibilityDescription,x,w);g.push(e.documentOpen({id:"prelude",width:l.width,height:l.height,colors:s,transparent:p,font:h,hasMonoFont:!1},A(l.width,l.height,s,p,v)+`
4
- `+X(h,!1,s.shadow,s.embedFontImport)));let M=[];M.push("<defs>");let I=(n=m.width,i=m.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"}}]);M.push(G(I));let $=j(s);$&&M.push($),M.push("</defs>"),g.push(e.definitions({id:"defs",markerResources:I},M.join(`
5
- `))),l.accessibilityTitle&&g.push(e.documentContent({id:"a11y-title",role:"chrome",nonPaint:"accessibility"},`<title id="${x}">${Q(l.accessibilityTitle)}</title>`)),l.accessibilityDescription&&g.push(e.documentContent({id:"a11y-desc",role:"chrome",nonPaint:"accessibility"},`<desc id="${w}">${Q(l.accessibilityDescription)}</desc>`));let L=l.blocks.some(e=>"rect"===e.type),C=L?[...l.blocks].reverse().sort((e,t)=>t.width*t.height-e.width*e.height):l.blocks,q=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=R("var(--bg)",i)??"#ffffff";for(let e of t){let t=e6(e,n),l=void 0===t?void 0:R(t,i)??t,s=void 0===l?null:T(l);if(!s||0===s[3])continue;let d=e.x+e.width/2,c=e.y+e.height/2,h=_(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:Y(...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=R(t,i),d=s?B(s,r.hex):P(r.hex)??t;return r.authored||l?{ink:d,halo:r.hex}:{ink:d}}}(l.boxes,C,u,s);l.title&&g.push(e.text(S(l.title,u)));let H=new Map;for(let t of l.boxes){let n=t.label??"",i=H.get(n)??0;H.set(n,i+1),g.push(function(e,t,n,i){let o=[],a=`<g class="box"${t.label?` data-label="${et(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??y(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=N(o,i);if(null!==e&&e>=4.5)return o}return P(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 F=new Map,E=new Map;for(let e of l.blocks){let t=F.get(e.type)??0;F.set(e.type,t+1),E.set(e,e.id??`block:${e.type}#${t}`)}for(let t of C)g.push(e9(e,t,u,E.get(t),L?"background":"all"));if(L){for(let t of C)"rect"!==t.type&&g.push(e9(e,t,u,E.get(t),"frame"));for(let t of l.blocks)t.dividers.length>0&&g.push(e9(e,t,u,E.get(t),"dividers"))}let z=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),O=new Set(l.actors.filter(e=>e.external).map(e=>e.id));for(let t of l.lifelines){if(O.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="${ee(t.actorId)}">`,close:"</g>",children:i.map(n=>{let i=(n.top-t.topY)%10;return{indent:2,node:e.connector({id:n.after?U(r,"after",n.after):U(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,z({x:t.x-n/2,y:t.topY,width:n,height:t.bottomY-t.topY},"x")))}let Z=new Map;for(let t of l.activations){let n=Z.get(t.actorId)??0;Z.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:U(i,"fill"),role:"activation",surfaceFragment:!0,geometry:{kind:"path",d:t},paint:{fill:a,stroke:"none"}})}),n.push({indent:2,node:e.shape({id:U(i,"border"),role:"activation",geometry:{kind:"path",d:o},paint:{fill:"none",stroke:r,strokeWidth:String(b.innerBox)}})})}return e.group({id:i,role:"activation",open:`<g class="activation" data-actor="${ee(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(b.innerBox)},attributes:{className:"activation",data:{actor:t.actorId}}})}(e,t,u,`activation:${t.actorId}#${n}`,z({x:t.x-b.innerBox/2,y:t.topY,width:t.width+b.innerBox,height:t.bottomY-t.topY},"y")))}let J=new Map;for(let t of l.blocks){let n=J.get(t.type)??0;J.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,E.get(t)))}let K=new Map;for(let t of l.blocks){let n=K.get(t.type)??0;K.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(e8(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,...e5(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,E.get(t),q))}let en=new Map;for(let t of l.messages){let n=`${t.from}->${t.to}`,i=en.get(n)??0;en.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="${et(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="${ee(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(e8(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,...e5(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(e8(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,...e5(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}`,q,I))}let eo=new Map;for(let t of l.notes){let n=`${(t.actors??[]).join(",")}@${t.position??"over"}`,i=eo.get(n)??0;eo.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(ee).join(",")}"`:"",c=t.position?` data-position="${ee(t.position)}"`:"",h=n.nodeFillColor??"var(--bg)",p=n.nodeBorderColor??"var(--_node-stroke)",g=n.nodeTextColor??W("var(--_text-muted)",h,i),u=n.cornerRadius??0,f=t.block?.text??y(t.text,n.nodeTextTransform);return e.group({id:o,role:"note",open:`<g class="note"${c}${d}${void 0===t.parentId?"":` data-parent-id="${ee(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(b.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=D(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),k=f?.fillColor??n.nodeFillColor??"var(--_node-fill)",w=f?.borderColor??n.nodeBorderColor??"var(--_node-stroke)",v=f?.textColor??n.nodeTextColor??"var(--_text)",M=f?.textColor??n.nodeTextColor??W("var(--_text)",k,i),S=a&&t.links?` data-links="${ee(JSON.stringify(t.links))}" role="link" tabindex="0"`:"",I=`<g class="actor" data-id="${ee(l)}" data-label="${et(p)}" data-type="${g}"${S}>`,{text:$,x:L,y:C,bounds:P}=t.labelPosition,q=r(e8(P),v);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:$,block:t.labelPosition.block,x:L,y:C,fontSize:x,fontWeight:b,letterSpacing:m,anchor:"middle",paint:{fill:q.ink,...e5(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"},w={fill:k,stroke:f?.borderColor??n.edgeStrokeColor??"var(--_line)",strokeWidth:String(y)},v=t=>{r.push(e.shape({id:U(`actor:${l}:icon`,"part",r.length),role:"icon",owner:p,geometry:t,paint:w}))},M=e=>v({kind:"path",d:e}),S=(e,t,n)=>v({kind:"circle",cx:e,cy:t,r:n}),I=(e,t,n,i)=>v({kind:"line",x1:e,y1:t,x2:n,y2:i}),P=(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?(P(i+6,o,c-6,a-6),P(i,o+6,c-6,a-6)):"queue"===g?(P(i,o,c,a,a/2),I(i+8,o+a/2,i+c-8,o+a/2)):"entity"===g?(S(s,o+a/2-3,Math.min(c,a)/2-3),I(i+5,o+a,i+c-5,o+a)):"boundary"===g?(S(s+3,o+a/2,Math.min(c,a)/2-3),I(i+3,o+2,i+3,o+a-2)):"control"===g?(S(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}`)):S(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:$,block:t.labelPosition.block,x:L,y:C,fontSize:x,fontWeight:b,letterSpacing:m,anchor:"middle",paint:{fill:q.ink,...e5(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:k,stroke:w,strokeWidth:String(y)},channels:{category:l}})}),u.push({indent:2,node:e.text({id:`actor:${l}:label`,role:"label",text:$,block:t.labelPosition.block,x:L,y:C,fontSize:x,fontWeight:b,letterSpacing:m,anchor:"middle",paint:{fill:M},channels:{category:l}})})}let H="participant"===g?M:v;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:H},channels:{category:l},baselineShift:0,attributes:{className:"sequence-actor-menu"}})}),e.group({id:`actor:${l}`,role:"actor",open:I,close:"</g>",children:u,channels:{category:l}})}(e,t,u,s,d.styleFace,"strict"!==c.security,q));return g.push(e.documentClose()),{family:"sequence",width:l.width,height:l.height,colors:s,transparent:p,parts:g}}function e5(e){return e.halo?{stroke:e.halo,strokeWidth:"3",strokeLinejoin:"round",paintOrder:"stroke"}:{}}function e8(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="${et(t.label)}"`:"",l="dividers"===o?`<g class="sequence-block-divider-overlay" data-owner="${ee(i)}">`:"frame"===o?`<g class="sequence-block-frame-overlay" data-owner="${ee(i)}">`:`<g class="block" data-type="${ee(t.type)}"${r}${void 0===t.parentId?"":` data-parent-id="${ee(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=I(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};
@@ -1 +0,0 @@
1
- import{Q as t}from"./chunk-GMTB5UTY.js";import{gb as e,ua as a}from"./chunk-EUBVLDYV.js";import{Q as r,S as o,_ as n,v as i}from"./chunk-P7DO3MRP.js";async function s(){u=(await import("./elk.bundled-L4CADV5W.js")).default}var u,l,c,h,d,f=null,m=null;function p(o){return r("elk",()=>(function(r){if(t(r),!g)return a("elk-layout","bypass","disabled"),k(r);let o=JSON.stringify(r,(t,e)=>void 0===e?"\0undefined":"number"!=typeof e||Number.isFinite(e)?"string"==typeof e&&e.startsWith("\0")?`\0${e}`:e:`\0${e}`),n=w.get(o);if(n)return a("elk-layout","hit"),structuredClone(n);a("elk-layout","miss");let i=k(r);if(o.length<=1048576){let t=Math.max(8*o.length,2*o.length+e(i,8388608));t<=8388608?w.set(o,structuredClone(i),t):a("elk-layout","store-skipped","weight-limit")}else a("elk-layout","store-skipped","key-limit");return i})(o))}var y=globalThis,g=(y.process?.env?.AGENTIC_MERMAID_ELK_CACHE??y.AGENTIC_MERMAID_ELK_CACHE)!=="0",w=new i(64,8388608);function k(t){!function(){if(f)return;let t=function(){if(!u)throw new o("ELK",s);return u}(),e=[],a=globalThis.setTimeout;globalThis.setTimeout=(t,r)=>0===r?(e.push(t),0):a(t,r);let r=globalThis,n="u">typeof r.document;n||(r.document={}),f=new t,n||delete r.document,globalThis.setTimeout=a,e.forEach(t=>t()),m=f.worker.worker}();let e,a,r=m.onmessage;if(m.onmessage=t=>{t.data.error?a=t.data.error:e=t.data.data},m.dispatcher.saveDispatch({data:{id:0,cmd:"layout",graph:t}}),m.onmessage=r,a)throw a;if(!e)throw Error("ELK layout did not return synchronously");return e}async function E(){await (c??=import("./forest-implementation-AEP24AIP.js").then(t=>{l=t}).catch(t=>{throw c=void 0,t}))}function b(){if(!l)throw new o("Forest layout",E);return l}async function v(){await (d??=Promise.all([import("./agentic-producer-core-MGU4FD6J.js"),E()]).then(([t])=>{let e=b();h={candidate:t.layoutNativeGraphCandidate,placement:t.layoutNativeGraphPlacement,architectureSlots:t.improveArchitectureSiblingSlots,graph:t.createMeasuredLayoutCache(a=>t.layoutLayeredGraph(a,e.layoutMeasuredForest,t=>{throw new n(t)}))}}).catch(t=>{throw d=void 0,t}))}function T(){if(!h)throw new o("Agentic layout",v);return h}function A(t){return T().graph(t)}var C=(t,e,a,r)=>T().candidate(t,e,a,A,r),M=(t,e,a,r)=>T().placement(t,e,a,A,r),L=(...t)=>T().architectureSlots(...t);export{p as a,b as b,A as c,C as d,M as e,L as f};