agentic-mermaid 0.5.3 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/agent-core.d.ts +7 -7
  3. package/dist/agent-core.js +1 -1
  4. package/dist/agent.d.ts +7 -7
  5. package/dist/agent.js +1 -1
  6. package/dist/agentic-mermaid-mcp.js +1 -1
  7. package/dist/am.js +1 -1
  8. package/dist/browser-lazy/chunks/{agentic-producer-core-CC6OOLDW.js → agentic-producer-core-ECZ3CMZM.js} +1 -1
  9. package/dist/browser-lazy/chunks/{architecture-QUFVKYJR.js → architecture-H5LTMKQW.js} +6 -6
  10. package/dist/browser-lazy/chunks/{block-6J3Q63BO.js → block-566X6FNV.js} +5 -5
  11. package/dist/browser-lazy/chunks/{builtin-backends-7SOZZHPF.js → builtin-backends-VAFEZXKY.js} +6 -6
  12. package/dist/browser-lazy/chunks/{c4-SQVBZAKJ.js → c4-ZXFDLBFK.js} +5 -5
  13. package/dist/browser-lazy/chunks/{chunk-5X6MJX3H.js → chunk-2JQXRKBC.js} +1 -1
  14. package/dist/browser-lazy/chunks/{chunk-E2WMJZNM.js → chunk-37FZNMPR.js} +1 -1
  15. package/dist/browser-lazy/chunks/{chunk-TYZOZXUJ.js → chunk-3JTYTXA6.js} +6 -6
  16. package/dist/browser-lazy/chunks/{chunk-PQGPS2YV.js → chunk-4NILRBC7.js} +1 -1
  17. package/dist/browser-lazy/chunks/{chunk-AMJLVPUB.js → chunk-5LKPDHPC.js} +2 -2
  18. package/dist/browser-lazy/chunks/{chunk-BY2CPG6B.js → chunk-62MR3LWJ.js} +1 -1
  19. package/dist/browser-lazy/chunks/{chunk-J7FFAFQF.js → chunk-64JFHCJC.js} +1 -1
  20. package/dist/browser-lazy/chunks/chunk-6GPDLZFQ.js +1 -0
  21. package/dist/browser-lazy/chunks/{chunk-VWVZGQE2.js → chunk-6UOOATQR.js} +1 -1
  22. package/dist/browser-lazy/chunks/chunk-7TTFBJYA.js +1 -0
  23. package/dist/browser-lazy/chunks/chunk-7UFOFWBA.js +20 -0
  24. package/dist/browser-lazy/chunks/{chunk-5B2Z7575.js → chunk-A7V5VDKN.js} +1 -1
  25. package/dist/browser-lazy/chunks/chunk-CPO5P4L2.js +1 -0
  26. package/dist/browser-lazy/chunks/chunk-EIYLJ4FI.js +20 -0
  27. package/dist/browser-lazy/chunks/{chunk-X2UYKWKM.js → chunk-G4JBA7HU.js} +3 -3
  28. package/dist/browser-lazy/chunks/{chunk-2UIA2IME.js → chunk-IUI4DYC3.js} +1 -1
  29. package/dist/browser-lazy/chunks/{chunk-QA6GJQ4X.js → chunk-J57YRC2M.js} +1 -1
  30. package/dist/browser-lazy/chunks/{chunk-BU5LHXNJ.js → chunk-LBXXKLIR.js} +3 -3
  31. package/dist/browser-lazy/chunks/chunk-NKW2ZNCD.js +1 -0
  32. package/dist/browser-lazy/chunks/{chunk-ICC7HBJX.js → chunk-O34YYEQV.js} +1 -1
  33. package/dist/browser-lazy/chunks/{chunk-UL6NDWLL.js → chunk-OBI5U5XU.js} +1 -1
  34. package/dist/browser-lazy/chunks/{chunk-YCEICNM6.js → chunk-OFOS57WQ.js} +1 -1
  35. package/dist/browser-lazy/chunks/{chunk-OZ443IVJ.js → chunk-PSZEE64O.js} +7 -7
  36. package/dist/browser-lazy/chunks/{chunk-SZELX2EJ.js → chunk-PXTLV57R.js} +1 -1
  37. package/dist/browser-lazy/chunks/{chunk-HLWUNUCM.js → chunk-QVSZOF5M.js} +1 -1
  38. package/dist/browser-lazy/chunks/{chunk-2GPK4VFF.js → chunk-TT5GR5EJ.js} +1 -1
  39. package/dist/browser-lazy/chunks/{chunk-DF6765YX.js → chunk-V6I2VGNQ.js} +5 -5
  40. package/dist/browser-lazy/chunks/{chunk-CN7WTBWB.js → chunk-VRZKI33U.js} +1 -1
  41. package/dist/browser-lazy/chunks/{chunk-2SH76OTH.js → chunk-XHU3A432.js} +1 -1
  42. package/dist/browser-lazy/chunks/{chunk-NO7ZIVRU.js → chunk-YVNJDVQO.js} +1 -1
  43. package/dist/browser-lazy/chunks/chunk-Z7UHFVKN.js +6 -0
  44. package/dist/browser-lazy/chunks/{class-5QA4SCTS.js → class-XIFNVBFE.js} +8 -8
  45. package/dist/{zenuml/chunks/decode-BWERFDGK.js → browser-lazy/chunks/decode-5MFOG3AZ.js} +1 -1
  46. package/dist/browser-lazy/chunks/{elk.bundled-L4CADV5W.js → elk.bundled-RYWHIS5N.js} +8 -8
  47. package/dist/browser-lazy/chunks/er-VEUYJBGG.js +11 -0
  48. package/dist/browser-lazy/chunks/{eventmodeling-2BPLHWRN.js → eventmodeling-G7DITZX7.js} +10 -10
  49. package/dist/browser-lazy/chunks/{flowchart-NEIMZTB5.js → flowchart-SSFIU4EU.js} +1 -1
  50. package/dist/browser-lazy/chunks/{forest-implementation-AEP24AIP.js → forest-implementation-RWFF7XDV.js} +1 -1
  51. package/dist/browser-lazy/chunks/{gantt-RDPIFYAF.js → gantt-HQNVDX2B.js} +6 -6
  52. package/dist/browser-lazy/chunks/{gitgraph-N4Y5RYB7.js → gitgraph-Z5MN6M6L.js} +4 -4
  53. package/dist/browser-lazy/chunks/{ishikawa-LD3YBDJN.js → ishikawa-UEERNFQV.js} +2 -2
  54. package/dist/browser-lazy/chunks/{journey-6YQR5DJX.js → journey-3BEWWGB5.js} +6 -6
  55. package/dist/browser-lazy/chunks/{kanban-PLMJ7NBW.js → kanban-2WFNCWLB.js} +10 -10
  56. package/dist/browser-lazy/chunks/{mermaid-yaml-runtime-QVYX4EWK.js → mermaid-yaml-runtime-IK4ET4BT.js} +8 -8
  57. package/dist/browser-lazy/chunks/{mindmap-K2UBFO3Y.js → mindmap-R2C6SNYR.js} +4 -4
  58. package/dist/browser-lazy/chunks/{packet-CUW4QY6Y.js → packet-GMVCI5YZ.js} +3 -3
  59. package/dist/browser-lazy/chunks/{pie-7F7UUCG3.js → pie-WER45DKC.js} +7 -7
  60. package/dist/browser-lazy/chunks/{quadrant-TOONO2WC.js → quadrant-NCUPSFKN.js} +4 -4
  61. package/dist/browser-lazy/chunks/{radar-J6JVWVAX.js → radar-WLYS4YC5.js} +8 -8
  62. package/dist/browser-lazy/chunks/render-core-42UVWIPF.js +3 -0
  63. package/dist/browser-lazy/chunks/{requirement-CMAKDJPO.js → requirement-AK3NWMJ6.js} +7 -7
  64. package/dist/browser-lazy/chunks/{sankey-AWXQEP3F.js → sankey-C2DY6WVU.js} +4 -4
  65. package/dist/browser-lazy/chunks/{sequence-Q2RJRB4L.js → sequence-D4WJB44W.js} +1 -1
  66. package/dist/browser-lazy/chunks/{state-WRBFQEDX.js → state-YUQVESE7.js} +2 -2
  67. package/dist/browser-lazy/chunks/{timeline-D2KILFXM.js → timeline-BMBJJXWR.js} +4 -4
  68. package/dist/browser-lazy/chunks/{treemap-N3VYX5D4.js → treemap-B66XBZZ6.js} +3 -3
  69. package/dist/browser-lazy/chunks/{xychart-G73OGK66.js → xychart-HAVFROGT.js} +6 -6
  70. package/dist/browser-lazy/chunks/{zenuml-H4BXNYXR.js → zenuml-62RLYFWP.js} +7 -7
  71. package/dist/browser-lazy/index.js +1 -1
  72. package/dist/browser.global.js +507 -507
  73. package/dist/{chunk-DQDKA5ND.js → chunk-2DNGDTJD.js} +2 -2
  74. package/dist/{chunk-GVCHLSHH.js → chunk-4F2UGYTM.js} +2 -2
  75. package/dist/{chunk-H3NCS2XZ.js → chunk-7XYB2LNC.js} +2 -2
  76. package/dist/chunk-DOFB572I.js +58 -0
  77. package/dist/chunk-EHJI3QYE.js +52 -0
  78. package/dist/{chunk-UA234O4M.js → chunk-HINRNKPO.js} +2 -2
  79. package/dist/{chunk-JZOJ4YGS.js → chunk-KXMANAST.js} +33 -33
  80. package/dist/{chunk-7CRDX2QR.js → chunk-U4MT3RRE.js} +2 -2
  81. package/dist/{chunk-NKNFOREZ.js → chunk-WYIB6BUR.js} +2 -2
  82. package/dist/{cli-YGGTJZH7.js → cli-ZYIDBYNS.js} +2 -2
  83. package/dist/{index-EeXqJXr5.d.ts → index-Bvhprdxz.d.ts} +3 -3
  84. package/dist/index.d.ts +4 -4
  85. package/dist/index.js +1 -1
  86. package/dist/{mcp-cli-63DYXTVD.js → mcp-cli-YVDCORWA.js} +2 -2
  87. package/dist/{paint-certification-6rwQjIv_.d.ts → paint-certification-BoLyr006.d.ts} +2 -2
  88. package/dist/{server-5NEOHOFS.js → server-4JGAVXR3.js} +2 -2
  89. package/dist/{svg-styles-BdnoM7AT.d.ts → svg-styles-BnCoXyYe.d.ts} +1 -1
  90. package/dist/svg-styles.d.ts +1 -1
  91. package/dist/svg-styles.js +1 -1
  92. package/dist/svg.d.ts +4 -4
  93. package/dist/svg.js +1 -1
  94. package/dist/{types-BcS52Mjt.d.ts → types-CLVJCaH2.d.ts} +1 -1
  95. package/dist/zenuml/chunks/{appearance-UOQ5KA6O.js → appearance-5RM5MVM2.js} +1 -1
  96. package/dist/zenuml/chunks/{builtin-backends-KDKE7YHO.js → builtin-backends-UTNWL4N3.js} +11 -11
  97. package/dist/zenuml/chunks/{chunk-QWX77U7G.js → chunk-3A6S6GNB.js} +2 -2
  98. package/dist/zenuml/chunks/{chunk-OXQWRSBM.js → chunk-55WS466K.js} +11 -11
  99. package/dist/zenuml/chunks/chunk-6J4BGPB2.js +29 -0
  100. package/dist/zenuml/chunks/chunk-CNLL4BGF.js +1 -0
  101. package/dist/zenuml/chunks/{chunk-RZ6XK5CD.js → chunk-IARQ24W3.js} +13 -13
  102. package/dist/zenuml/chunks/{chunk-42DXZ5C6.js → chunk-ZNZRIISS.js} +2 -2
  103. package/dist/{browser-lazy/chunks/decode-63UIZGD2.js → zenuml/chunks/decode-LDNNXEAO.js} +1 -1
  104. package/dist/zenuml/chunks/{mermaid-yaml-runtime-KZVU74WU.js → mermaid-yaml-runtime-A5CNJ3IE.js} +8 -8
  105. package/dist/zenuml/chunks/render-core-ECIWU5ZS.js +3 -0
  106. package/dist/zenuml/chunks/{zenuml-EA2ZFRUX.js → zenuml-N3LZMB2G.js} +8 -8
  107. package/dist/zenuml.d.ts +2 -2
  108. package/dist/zenuml.js +1 -1
  109. package/docs/MCP-DIRECTORY-LISTINGS.md +81 -12
  110. package/docs/api.md +1 -1
  111. package/package.json +1 -1
  112. package/server.json +2 -2
  113. package/dist/browser-lazy/chunks/chunk-4LHYF3BS.js +0 -1
  114. package/dist/browser-lazy/chunks/chunk-FAIMVOX5.js +0 -6
  115. package/dist/browser-lazy/chunks/chunk-GVOEAY52.js +0 -1
  116. package/dist/browser-lazy/chunks/chunk-J35HAQQF.js +0 -20
  117. package/dist/browser-lazy/chunks/chunk-RIVTHZAQ.js +0 -1
  118. package/dist/browser-lazy/chunks/chunk-Z3FDIVLN.js +0 -20
  119. package/dist/browser-lazy/chunks/er-7ZSKGN7Y.js +0 -11
  120. package/dist/browser-lazy/chunks/render-core-BZOM3K7D.js +0 -3
  121. package/dist/chunk-EHCMJUMD.js +0 -52
  122. package/dist/chunk-OMY6NRQD.js +0 -58
  123. package/dist/zenuml/chunks/chunk-7TVYPTDW.js +0 -1
  124. package/dist/zenuml/chunks/chunk-RLJEI7YN.js +0 -29
  125. package/dist/zenuml/chunks/render-core-V5RQ737O.js +0 -3
  126. /package/dist/browser-lazy/chunks/{chunk-5FQ534HP.js → chunk-BMZ24VPS.js} +0 -0
  127. /package/dist/browser-lazy/chunks/{chunk-2I4UPL7Q.js → chunk-D6MQ7QSU.js} +0 -0
  128. /package/dist/browser-lazy/chunks/{chunk-CQE4HQEW.js → chunk-HJVO5VC3.js} +0 -0
  129. /package/dist/browser-lazy/chunks/{chunk-LH7HUDKW.js → chunk-L4UC3KGS.js} +0 -0
  130. /package/dist/browser-lazy/chunks/{chunk-NMQQMRIR.js → chunk-MFTQWHUB.js} +0 -0
  131. /package/dist/browser-lazy/chunks/{chunk-N5ELX7LR.js → chunk-PJJSDGLB.js} +0 -0
  132. /package/dist/browser-lazy/chunks/{chunk-CSFUKSU6.js → chunk-QCU5G5PZ.js} +0 -0
  133. /package/dist/browser-lazy/chunks/{chunk-VQYYGAXP.js → chunk-TLFX3U6S.js} +0 -0
  134. /package/dist/browser-lazy/chunks/{chunk-5UVGUSD6.js → chunk-YHMTSXIR.js} +0 -0
  135. /package/dist/zenuml/chunks/{chunk-EVPSMEKN.js → chunk-GC7IPQ5P.js} +0 -0
@@ -0,0 +1,52 @@
1
+ import{$ as am,$a as Kx,$b as eC,$c as xC,A as I1,Aa as Vx,Ac as Zx,Ba as Yr,Bc as Ms,Ca as W1,Cc as bm,Da as Bc,Dc as eb,Dd as da,Ea as z1,Fa as $n,Ga as G1,Gc as ks,H as qx,Ha as Ei,Hc as hC,Hd as EC,I as F1,Ia as Cu,Ja as Xe,Jc as mC,Ka as Xn,La as Pu,Ma as yt,Na as H1,Oa as j1,P as N1,Pa as ws,Qa as Y1,Qc as tb,Qd as RC,Ra as At,Rb as K1,S as $1,Sa as Ye,Sb as It,Sc as pC,Sd as vC,T as ml,Ta as hn,Tb as mm,Td as TC,U as vr,Ua as jt,Ub as xn,Ud as LC,Va as xl,Vb as zc,Wa as q1,X as Su,Xa as Eu,Xb as Tr,Y as Xx,Ya as Ru,Yb as J1,Yd as AC,Z as _1,Za as bl,Zb as Q1,_ as hi,_a as Wc,_b as Z1,a as rm,aa as D1,ab as X1,ac as tC,b as v1,ba as Dc,bc as fr,c as fl,ca as wu,cb as U1,d as Yn,db as vu,dc as pm,dd as bC,e as tr,ea as jr,eb as xo,ec as mi,f as om,fa as qe,fb as um,fc as gm,ga as ca,gb as Sl,gc as nC,ha as ur,hb as mn,hc as iC,hd as SC,i as sm,ia as O1,ib as Tu,ic as rC,id as wC,j as T1,ja as Mu,jb as Zn,jc as ym,jd as MC,k as yu,ka as Rt,kb as wl,kc as Wo,kd as kC,l as $c,la as lm,lc as Jx,ld as pi,ma as cm,mc as oC,n as L1,na as Be,nb as en,nc as sC,o as xs,oa as Ux,oc as aC,p as Nn,pa as pl,pb as Dt,pc as lC,q as A1,qa as ku,qb as Ot,qc as cC,ra as gl,rb as Ml,rc as dC,s as Kt,sa as yl,sc as uC,t as xu,ta as dm,tb as _n,tc as kl,td as CC,u as bu,ub as V1,v as la,vb as fm,vc as hr,vd as Pl,w as hl,wa as bs,wb as hm,wc as Qx,wd as Sm,x as _c,xa as Oc,xb as Bn,xc as Cl,xd as qr,y as qn,ya as Ss,yc as xm,yd as PC,za as B1,zc as fC}from"./chunk-DOFB572I.js";import{I as wm,a as gC,b as yC,z as rt}from"./chunk-O7H2UX5K.js";function Lu(e,t,n){let i=1;for(;i<e.length;i++){n();if(t(e[i-1],e[i])>0)break}if(i>=e.length)return;n(e.length);const r=Math.floor(e.length/2),o=e.slice(0,r),s=e.slice(r);Lu(o,t,n);Lu(s,t,n);let a=0,l=0;for(let c=0;c<e.length;c++){n();let d=a<o.length&&l===s.length;if(a<o.length&&l<s.length){n();d=!(t(o[a],s[l])>0)}e[c]=d?o[a++]:s[l++]}}function nb(e,t,n,i){const r=o=>{n?.(o.length+1);const s={x0:Infinity,y0:Infinity,x1:-Infinity,y1:-Infinity};for(const d of o){const u=t(d);s.x0=Math.min(s.x0,u.x0);s.y0=Math.min(s.y0,u.y0);s.x1=Math.max(s.x1,u.x1);s.y1=Math.max(s.y1,u.y1)}if(o.length<=8)return{bounds:s,leaves:o};const a=s.x1-s.x0>=s.y1-s.y0?"x0":"y0";const l=(d,u)=>t(d)[a]-t(u)[a]||i?.(d,u)||0;if(n)Lu(o,l,n);else o.sort(l);const c=Math.floor(o.length/2);return{bounds:s,left:r(o.slice(0,c)),right:r(o.slice(c))}};return e.length?r(e):void 0}function Xr(e,t,n,i){let r;const o=Math.ceil(Math.log2(Math.max(2,e.length)));const s=e.length>8&&i>o*o;return a=>{const l=[];const c=u=>{n();return a.x0<u.x1&&a.x1>u.x0&&a.y0<u.y1&&a.y1>u.y0};const d=u=>{if(!c(u.bounds))return;if(!u.leaves){d(u.left);d(u.right)}else for(const f of u.leaves)if(c(t(f)))l.push(f)};if(!r){if(!s){for(const u of e)if(c(t(u)))l.push(u);return l}r=nb([...e],t,n)}d(r);return l}}var ib=new WeakMap;var rb=new WeakMap;function Cs(e){return rb.get(e)??ib.get(e)}var ob=new WeakMap;var FC=new WeakSet;var yB=Object.freeze([1,0,0,1,0,0]);function ua(e){return ob.get(e)}function NC(e){return FC.has(e)}function IC(e){return[e.x0,e.x1,e.y0,e.y1].every(Number.isFinite)&&e.x0<=e.x1&&e.y0<=e.y1}function Mm(e){return e==="none"||e==="transparent"||!!e&&Kt(e)?.[3]===0}function Pn(e){if(e===void 0)return 1;const t=e.trim();if(!/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/.test(t))return Number.NaN;const n=Number(t);return Number.isFinite(n)?Math.max(0,Math.min(1,n)):Number.NaN}function sb(e,t){return e===0||t===0?0:e*t}function $C(e,t){return e&&Number(t.opacity??1)!==0&&(!Mm(t.fill)||t.stroke!==void 0&&!Mm(t.stroke)&&Number.parseFloat(t.strokeWidth??"1")!==0)}function xB(e){if(e.kind==="document")return e.element!=="content"||e.nonPaint!==void 0||J1(e).trim()==="";if(e.kind==="text")return!$C(DC(e.block,e.text),e.paint);if(e.kind==="connector")return e.lineStyle==="invisible";if(e.kind==="shape"){if(e.conditionalPaint)return false;return[e.paint,...e.childPaints??[]].every(t=>t.opacity!==void 0&&Number(t.opacity)===0||Mm(t.fill)&&(t.stroke===void 0||Mm(t.stroke)))}return false}function _C(e){return SB(e)}function DC(e,t){return e?e.lineBlocks.some(n=>n.runs.some(i=>i.text.trim()!=="")):t.trim()!==""}var km=new WeakSet;var ab=Object.freeze([]);km.add(ab);function Cm(e){return Object.freeze({id:e.id,role:e.role})}function OC(e,t){const n=Cm(t);const i=e===void 0?ab:km.has(e)?e:Array.from(e,Cm);const r=Object.freeze([...i,n]);km.add(r);return r}function BC(e){const t=WC(e,void 0,true);return{leaf(n,i,r,o=ab,s=false,a=1,l){if(!km.has(o))throw new TypeError("Native paint ancestors must be owned snapshots");t.leaf(n,i,r,o,s,a,l)},finish:t.finish}}function bB(e){switch(e.kind){case"shape":return Object.freeze({kind:e.kind,geometry:e.geometry,paint:e.paint,...e.childPaints?{childPaints:e.childPaints}:{},...e.transform?{transform:e.transform}:{}});case"connector":return Object.freeze({kind:e.kind,lineStyle:e.lineStyle,endpoints:e.endpoints,route:e.route,stroke:e.stroke,markers:e.markers,...e.transform?{transform:e.transform}:{}});case"text":return Object.freeze({kind:e.kind,paint:e.paint});case"document":return Object.freeze({kind:e.kind})}}function WC(e,t,n=false){const i=[];const r={measured:0,unmeasured:0,nonPainting:0,preparedText:0,fallbackText:0};const o=(s,a,l,c,d,u,f,h=l===void 0)=>{const m=f??s.owner??c.at(-1)??s.identity??{id:s.id,role:s.role};const p=n?bB(s):void 0;const g=u===0||xB(s);const[y,w,S,x,M,b]=l??pl;const C=l||s.transform?{kind:"matrix",a:y,b:w,c:S,d:x,e:M,f:b}:void 0;const P=!l&&!s.transform?yB:Object.freeze(gl(l??pl,ku(s.transform)));const E=g?void 0:Ei(s,C);const k=!!E&&IC(E);const v=g?"non-painting":k?"measured":"unmeasured";const T=Object.freeze({key:a,id:s.id,kind:s.kind,role:s.role,owner:n&&c.includes(m)?m:Cm(m),ancestors:c,order:i.length,coverage:v,...d||s.visibility==="conditional"||!Number.isFinite(u)?{visibility:"conditional"}:{},...u<1?{groupOpacity:u}:{},...k?{bounds:Object.freeze(E)}:{},...!g&&!k?{reason:s.kind==="document"?"opaque-visible-content":"missing-paint-geometry"}:{},...s.kind==="text"?{text:Object.freeze({measurement:s.measurement??"unavailable",...t?.(s.text,s.block,true)})}:{}});if(p)rb.set(T,p);else ib.set(T,s);ob.set(T,P);if(h&&!s.transform)FC.add(T);i.push(T);if(g)r.nonPainting++;else if(k)r.measured++;else r.unmeasured++;if(s.kind==="text"&&!g){if(s.measurement==="prepared")r.preparedText++;else r.fallbackText++}if(s.kind==="connector")s.labels.forEach((A,R)=>{if(A.visual?.kind!=="inline")return;const I={...A.paint,...A.halo?{stroke:A.halo.color??"var(--bg)",strokeWidth:String(A.halo.width)}:{}};const L=u===0||!$C(DC(A.block,A.text),I);const $=L?void 0:W1(A);const[B,F,z,_,H,D]=P;const j=$&&Bc($,{kind:"matrix",a:B,b:F,c:z,d:_,e:H,f:D});const W=!!j&&IC(j);const O=Object.freeze({key:`${a}.label.${R}`,id:A.id??`${s.id}:label:${R}`,kind:"text",role:"label",owner:T.owner,ancestors:T.ancestors,order:i.length,coverage:L?"non-painting":W?"measured":"unmeasured",...T.visibility?{visibility:T.visibility}:{},...u<1?{groupOpacity:u}:{},...W?{bounds:Object.freeze(j)}:!L?{reason:"missing-inline-label-geometry"}:{},text:Object.freeze({measurement:A.block?"prepared":"fallback",...t?.(A.text,A.block)})});if(p)rb.set(O,p);else ib.set(O,s);ob.set(O,P);i.push(O);if(L)r.nonPainting++;else{if(W)r.measured++;else r.unmeasured++;if(A.block)r.preparedText++;else r.fallbackText++}})};return{leaf:o,finish:()=>Object.freeze({version:1,family:e.family,bounds:Object.freeze({width:e.width,height:e.height}),primitives:Object.freeze(i),coverage:Object.freeze(r)})}}function SB(e,t){const n=WC(e,t);const i=(r,o,s,a,l=false,c=1,d=true)=>{r.forEach((u,f)=>{const h=`${o}.${f}`;if(u.kind==="group"){const m=tC(u);const p=u.identity??{id:u.id,role:u.role};i(u.children.map(g=>g.node),h,gl(s,ku(u.transform)),Object.freeze([...a,Cm(p)]),l||u.visibility==="conditional"||m.style||u.paint?.fill!==void 0,sb(c,Pn(u.paint?.opacity)),d&&!u.transform)}else n.leaf(u,h,s,a,l,c,void 0,d)})};i(e.parts,"scene",pl,Object.freeze([]));return n.finish()}function zo(e,t,n,i,r,o){o?.();const s=e.geometry;if(!s)return[];const a=i==="start"&&e.orient==="auto-start-reverse"?-1:1,l=Math.hypot(n.x,n.y);if(!l)return[];const c=a*n.x/l,d=a*n.y/l,u=e.viewBox,f=(e.units==="userSpaceOnUse"?1:r)*Math.max(1,e.scale??1)*(u&&e.size?Math.min(e.size.width/u.width,e.size.height/u.height):1);if(!Number.isFinite(f))throw new TypeError("Nonfinite Class marker scale");if(f<=0)return[];const h=b=>{o?.();const C=(b.x-(e.ref?.x??0))*f,P=(b.y-(e.ref?.y??0))*f;return{x:t.x+c*C-d*P,y:t.y+d*C+c*P}};const m=e.paint??{},p=m.stroke&&m.stroke!=="none"&&m.stroke!=="transparent"?Number.parseFloat(m.strokeWidth??"1")/2:0,g=m.fill!==void 0&&m.fill!=="none"&&m.fill!=="transparent";if(s.kind==="circle"){const b=h({x:s.cx,y:s.cy});return[{kind:"circle",cx:b.x,cy:b.y,r:(s.r+p)*f}]}if(s.kind!=="polygon"&&s.kind!=="polyline")throw new TypeError("Unmeasured Class marker geometry");const y=s.points,w=[];if(g&&s.kind==="polygon"){for(let b=0;b<y.length;b++)o?.();w.push([...y])}const S=s.kind==="polygon"?y.length:y.length-1;const x=(b,C)=>{o?.();const P=Math.hypot(C.x-b.x,C.y-b.y);return{x:(C.x-b.x)/P,y:(C.y-b.y)/P}};if(p>0){for(let b=0;b<S;b++){o?.();const C=y[b],P=y[(b+1)%y.length],E=x(C,P),k={x:-E.y*p,y:E.x*p};w.push([{x:C.x+k.x,y:C.y+k.y},{x:P.x+k.x,y:P.y+k.y},{x:P.x-k.x,y:P.y-k.y},{x:C.x-k.x,y:C.y-k.y}])}for(let b=s.kind==="polygon"?0:1;b<(s.kind==="polygon"?y.length:y.length-1);b++){o?.();const C=y[b],P=y[(b-1+y.length)%y.length],E=y[(b+1)%y.length],k=x(P,C),v=x(C,E),T=k.x*v.y-k.y*v.x;if(!T)continue;const A=T>0?-1:1,R={x:C.x-A*k.y*p,y:C.y+A*k.x*p},I={x:C.x-A*v.y*p,y:C.y+A*v.x*p},L=((I.x-R.x)*v.y-(I.y-R.y)*v.x)/T,$={x:R.x+L*k.x,y:R.y+L*k.y};w.push(Math.hypot($.x-C.x,$.y-C.y)<=Number(m.strokeMiterlimit??"4")*p?[C,R,$,I]:[C,R,I])}}const M=(b,C,P,E)=>{const k=[];for(let v=0;v<b.length;v++){o?.();const T=b[v],A=b[(v+1)%b.length],R=$=>E?$[C]>=P:$[C]<=P,I=R(T),L=R(A);if(I)k.push(T);if(I!==L){const $=(P-T[C])/(A[C]-T[C]);k.push({x:T.x+$*(A.x-T.x),y:T.y+$*(A.y-T.y)})}}return k};return w.flatMap(b=>{o?.();if(e.overflow==="hidden"&&u){for(const[E,k,v]of[["x",u.x,true],["x",u.x+u.width,false],["y",u.y,true],["y",u.y+u.height,false]]){o?.();b=M(b,E,k,v)}}const C=b[0];let P=0;if(C)for(let E=0;E<b.length;E++){o?.();const k=b[E],v=b[(E+1)%b.length];P+=(k.x-C.x)*(v.y-C.y)-(k.y-C.y)*(v.x-C.x)}return b.length>=3&&P!==0?[{kind:"polygon",points:b.map(h)}]:[]})}var Ps=4e5;var zC=new WeakSet;function GC(e){return zC.has(e)}var HC=new WeakMap;function jC(e){return HC.get(e)}function YC(e){let t=0,n=false,i=false;const r=new Map;const o=[];const s=(f=1)=>{if(n)return false;if(!Number.isSafeInteger(f)||f<0||f>e-t){n=true;return false}t+=f;return true};const a=Symbol("unsupported-emission");const l=(f,h=0,m=new Set)=>{if(h>64)throw a;if(f===null||f===void 0||typeof f==="boolean")return f;if(typeof f==="number"||typeof f==="string")return f;if(typeof f!=="object"||!s()||m.has(f))throw a;if(lm(f))return f;const p=Object.getPrototypeOf(f);if(p!==Object.prototype&&p!==null&&p!==Array.prototype)throw a;const g=Object.getOwnPropertyNames(f);if(!s(g.length))throw a;m.add(f);const y=Array.isArray(f)?[]:{};let w;const S=nC(f);for(const x of g){if(!s())throw a;const M=Object.getOwnPropertyDescriptor(f,x);if(!M)continue;if(x==="length"&&Array.isArray(f)){w=M;continue}if(x==="terminalProjection"&&S)continue;if(!("value"in M))throw a;Object.defineProperty(y,x,{value:l(M.value,h+1,m),enumerable:M.enumerable,configurable:false,writable:false})}if(Array.isArray(f)){if(!w||!("value"in w))throw a;Object.defineProperty(y,"length",{value:w.value,writable:false})}if(S){if(!s(3)||!iC(f,y))throw a;const x=Object.getOwnPropertyDescriptor(y,"terminalProjection");Object.defineProperty(y,"terminalProjection",{...x,configurable:false})}cm(f,y);m.delete(f);return Object.preventExtensions(y)};const c=f=>{try{return l(f)}catch{return void 0}};const d=(f,h)=>{if(!s())return false;if(typeof f==="string"&&typeof h==="string")return s(f.length+h.length)&&f===h;if(f===h)return true;if(!f||!h||typeof f!=="object"||typeof h!=="object")return false;let m=0,p=0;if(!s(2))return false;const g=Object.getOwnPropertyNames(f),y=Object.getOwnPropertyNames(h);if(!s(g.length+y.length))return false;for(const w of g){if(!s(3))return false;const S=Object.getOwnPropertyDescriptor(f,w),x=Object.getOwnPropertyDescriptor(h,w);if(!S)continue;m++;if(!x||!("value"in S)||!("value"in x)||S.enumerable!==x.enumerable||!d(S.value,x.value))return false}for(const w of y){if(!s())return false;if(Object.hasOwn(h,w))p++}return m===p};const u=f=>{if(!s())return void 0;if(typeof f==="string")return f.length*6+2;if(typeof f==="number")return 32;if(!f||typeof f!=="object")return 8;let h=64;if(!s())return void 0;const m=Object.getOwnPropertyNames(f);if(!s(m.length))return void 0;for(const p of m){if(!s(3))return void 0;const g=Object.getOwnPropertyDescriptor(f,p);if(!g||!("value"in g))return void 0;const y=u(g.value);if(y===void 0)return void 0;h+=p.length+16+y;if(!Number.isSafeInteger(h)||h>e)return void 0}return h};return{snapshot:c,same:d,retainFragment(){return s()},parts(f,h){if(!s()){i=true;return f}if(!Array.isArray(f)){i=true;return f}const m=Object.getOwnPropertyDescriptor(f,"length")?.value;if(!Number.isSafeInteger(m)||m<0||m>h)throw new RangeError("Native drawing contains too many emitted nodes");if(!s(m*4)){i=true;return f}const p=[];for(let g=0;g<m;g++){const y=Object.getOwnPropertyDescriptor(f,String(g));if(!y||!("value"in y)){i=true;p.push(f[g])}else p.push(y.value)}return Object.freeze(p)},uncertain(){i=true},header(f,h){if(!s(h.length*8+128))return f;const m=Eu(h).find(b=>b.name==="svg");if(!m){i=true;return f}const p=Xe(f.width),g=Xe(f.height);const y=Wc(m,"viewBox");if(y!==void 0?y!==`0 0 ${p} ${g}`:Wc(m,"width")!==p||Wc(m,"height")!==g)i=true;for(const b of m.attributes){if(!s())return f;if(!["xmlns","width","height","viewBox","style","role","class","id"].includes(b.name)&&!b.name.startsWith("data-")&&!b.name.startsWith("aria-"))i=true}const w=Object.freeze({...f,width:Number(p),height:Number(g)});const S=f.colors;const x=Wc(m,"style");if(x===void 0)return w;const M=new Set;for(const b of x.split(";")){if(!s(b.length+4))return w;if(!b.trim())continue;const C=b.indexOf(":");const P=b.slice(0,C).trim(),E=b.slice(C+1).trim();if(C<0||M.has(P)){i=true;continue}M.add(P);if(P==="background"&&E==="var(--bg)")continue;if(P==="--font"){if(!s(typeof S.font==="string"?S.font.length*4:1)||xo(S.font)!==E)i=true;continue}if(!["bg","fg","line","accent","muted","surface","border","font"].some(k=>`--${k}`===P)||S[P.slice(2)]!==E)i=true}return w},group(f,h){const m=h&&rC(h);if(!s(3))return void 0;if(!m||m.open!==f.open||m.opacity!==f.paint?.opacity){i=true;return void 0}if(m.style||f.paint?.fill!==void 0)i=true;return m.matrix},observe(f,h){if(!s(2*(1+(f.kind==="connector"?f.labels.length:0))))return false;if(f.kind==="connector"){const m=p=>{if(p&&s(2))o.push(p)};m(f.markers.start);for(const p of f.markers.mid){if(!s())break;m(p)}m(f.markers.end)}else if(f.kind==="document"&&f.element==="definitions"){if(!s(h.length*8))return false;for(const m of Eu(h)){if(!s(m.attributes.length+1))break;if(m.name!=="marker")continue;const p=Wc(m,"id");const g=h.indexOf("</marker>",m.end);if(!p||g<0||r.has(p)){i=true;continue}const y=h.slice(m.start,g+9).replace(/(^|\n)[ \t]+(?=<)/g,"$1");if(!s(2))break;r.set(p,y)}}return!n},leaf(f){const h=c(f);if(!h)return{node:f,conditional:true};Z1(f,h);return{node:h,conditional:false}},finish(f,h){const m=new Map;for(const p of o){if(!s())break;try{if(!s(2))break;const g=m.get(p.id);if(g&&d(g,p))continue;const y=u(p);if(y===void 0||!s(y*2)){i=true;break}const w=pm(p,{indent:0}).replace(/(^|\n)[ \t]+(?=<)/g,"$1");if(!s(w.length*3)||r.get(p.id)!==w)i=true;else if(s(2))m.set(p.id,p)}catch{i=true}}for(const p of f.primitives)if(p.visibility!=="conditional")zC.add(p);HC.set(f,Object.freeze({operations:t,exhausted:n,uncertain:i,header:h}))}}}var ZC=new WeakMap;function v7(e,t){ZC.set(e,t)}function T7(e){return e.paintCertification??ZC.get(e)}var Go=1e5;var wB=64;var MB=.5;var Gc=1e-6;var Hc=(e,t,n=0)=>e.x0<=t.x0+n&&e.y0<=t.y0+n&&e.x1>=t.x1-n&&e.y1>=t.y1-n;var Ur=(e,t)=>e.x0<t.x1&&t.x0<e.x1&&e.y0<t.y1&&t.y0<e.y1;var qC=e=>({x0:e.x,y0:e.y,x1:e.x+e.w,y1:e.y+e.h});var kB=e=>({x0:e.x,y0:e.y,x1:e.x+e.width,y1:e.y+e.height});function CB(e,t){const n=nb(e,r=>r.bounds);const i=r=>{if(!t())return-Infinity;let o=-Infinity;if(r.leaves)for(const s of r.leaves){if(!t())break;o=Math.max(o,s.primitive.order)}else o=Math.max(i(r.left),i(r.right));return r.lastOrder=o};if(n)i(n);return n}var XC=Symbol("paint query work limit");function UC(e,t,n){const i=(o=1)=>{for(let s=0;s<o;s++)if(!t())throw XC};const r=Xr(e,o=>o.bounds,i,n);return o=>{try{const s=r(o);Lu(s,(a,l)=>a.index-l.index,i);return s}catch(s){if(s!==XC)throw s;return[]}}}function PB(e,t,n,i,r,o,s){if(!s()||!o.every(Number.isFinite)||o[0]!==1||o[1]!==0||o[2]!==0||o[3]!==1||n.nonScaling||!["butt","round","square"].includes(n.lineCap??"butt")||!["miter","round","bevel"].includes(n.lineJoin??"miter")||!Number.isFinite(i)||i<=0||!Number.isFinite(r)||r<i/2)return false;const[a,l]=e;if(![a.x,a.y,l.x,l.y].every(Number.isFinite)||a.x!==l.x&&a.y!==l.y||a.x===l.x&&a.y===l.y)return false;const c=i/2;const d={x0:Math.min(a.x,l.x)-c,y0:Math.min(a.y,l.y)-c,x1:Math.max(a.x,l.x)+c,y1:Math.max(a.y,l.y)+c};if(!s()||!Object.values(d).every(Number.isFinite)||Ur(d,t))return false;for(const u of e){if(!s())return false;const f={x0:u.x-r,y0:u.y-r,x1:u.x+r,y1:u.y+r};if(!Object.values(f).every(Number.isFinite)||Ur(f,t))return false}return true}function VC(e,t){const n=Pn(t.opacity),i=Pn(t.fillOpacity);const r=t.fill?Kt(t.fill):null;return e.kind!=="line"&&t.fill!=="none"&&t.fill!=="transparent"&&!(n<1||i<1||r&&r[3]<1)}function KC(e,t){return Pn(t.opacity)!==0&&Pn(t.strokeOpacity)!==0&&$n(t,["polygon","polyline","path","compound"].includes(e.kind))!==0}function EB(e,t){const n=new Map;const i=l=>{if(n.has(l))return n.get(l);const c=fm(l,e.colors);const d=!!c&&Kt(c)?.[3]===1;n.set(l,d);return d};const r=l=>{if(l.vectorEffect==="non-scaling-stroke"||!l.stroke||!i(l.stroke)||Number(l.opacity??1)!==1||Number(l.strokeOpacity??1)!==1||l.strokeDasharray)return 0;const c=Number(l.strokeWidth?.replace(/px$/,"")??1);return Number.isFinite(c)&&c>0?c:0};const o=new Map;const s=(l,c)=>JSON.stringify([l.owner,c,ua(l)]);for(const l of t){const c=Cs(l);if(c?.kind!=="shape"||l.coverage!=="measured"||l.visibility==="conditional"||l.groupOpacity!==void 0)continue;const d=c.geometry.kind==="compound"?c.geometry.children:[c.geometry];for(let u=0;u<d.length;u++){const f=c.geometry.kind==="compound"?c.childPaints?.[u]??c.paint:c.paint;const h=r(f);if(h>0)o.set(s(l,d[u]),h)}}const a=[];for(const l of t){const c=Cs(l);if(!c||c.kind!=="shape"||l.visibility==="conditional"||l.coverage!=="measured")continue;if(l.groupOpacity!==void 0)continue;const{geometry:d,paint:u,childPaints:f}=c;const h=d.kind==="compound"?d.children:void 0;const m=h?void 0:d;const p=h?.map((B,F)=>f?.[F]??u);const g=h?void 0:u;const y=h?.map((B,F)=>VC(B,p[F]));const w=h?false:VC(m,g);const S=h?.map((B,F)=>KC(B,p[F]));const x=h?false:KC(m,g);if(!(y?y.some(Boolean):w)&&!(S?S.some(Boolean):x))continue;const M=ua(l);const[b,C,P,E,k,v]=M;const T={kind:"matrix",a:b,b:C,c:P,d:E,e:k,f:v};let A;const R=h?[]:void 0;for(let B=0,F=h?.length??1;B<F;B++){if(h&&!(B in h))continue;const z=h?h[B]:m,_=p?p[B]:g;if(!(y?y[B]:w)&&!(S?S[B]:x))continue;const H=Ei({kind:"shape",id:l.id,role:l.role,geometry:z,paint:_},T);const D=H??l.bounds;if(R)R[B]=D;A=bs(A,D)}if(!A)continue;const I={primitive:l,bounds:A,borderWidth:o.get(s(l,d)),...h?{partBorderWidths:h.map(B=>o.get(s(l,B))??0),partOwnBorderWidths:p.map(r),partFilled:y,partBounds:R}:{}};if(Math.abs(M[1])>1e-12||Math.abs(M[2])>1e-12){a.push(I);continue}const L=[],$=[];for(let B=0,F=h?.length??1;B<F;B++){if(h&&!(B in h))continue;const z=h?h[B]:m,_=p?p[B]:g;if(z.kind==="rect"&&M[0]===1&&M[3]===1&&M[1]===0&&M[2]===0&&_.vectorEffect!=="non-scaling-stroke"&&_.stroke&&i(_.stroke)&&Pn(_.opacity)===1&&Pn(_.strokeOpacity)===1&&!_.strokeDasharray&&$n(_,false)!==void 0){const O=Number.parseFloat(_.strokeWidth??"1")/2;const N=Math.max(0,Math.min(z.width/2,z.rx??z.ry??0)),G=Math.max(0,Math.min(z.height/2,z.ry??z.rx??0));if(O>0){for(const Y of[{x0:z.x-O,y0:z.y+G,x1:z.x+O,y1:z.y+z.height-G},{x0:z.x+z.width-O,y0:z.y+G,x1:z.x+z.width+O,y1:z.y+z.height-G},{x0:z.x+N,y0:z.y-O,x1:z.x+z.width-N,y1:z.y+O},{x0:z.x+N,y0:z.y+z.height-O,x1:z.x+z.width-N,y1:z.y+z.height+O}])if(Y.x0<Y.x1&&Y.y0<Y.y1)$.push(Bc(Y,T))}}if(!(y?y[B]:w)||z.kind!=="rect"||Pn(_.opacity)!==1||Pn(_.fillOpacity)!==1||!_.fill||!i(_.fill))continue;const H=Math.min(z.width/2,z.rx??z.ry??0),D=Math.min(z.height/2,z.ry??z.rx??0);const j=yl({x:z.x+H,y:z.y+D},M);const W=yl({x:z.x+z.width-H,y:z.y+z.height-D},M);L.push({x0:Math.min(j.x,W.x),y0:Math.min(j.y,W.y),x1:Math.max(j.x,W.x),y1:Math.max(j.y,W.y)})}a.push({...I,interiors:L,strokeInteriors:$})}return a}function JC(e,t,n,i,r=0,o=()=>true,s,a,l=false){const c=Cs(e.primitive);if(c?.kind!=="shape")return false;const d=dm(ua(e.primitive));if(!d)return false;const{geometry:u,paint:f,childPaints:h}=c;const m=(i??[{x:t.x0,y:t.y0},{x:t.x0,y:t.y1},{x:t.x1,y:t.y0},{x:t.x1,y:t.y1}]).map(k=>yl(k,d));const[p,g,y,w]=d;const S=(Math.hypot(p+w,g-y)+Math.hypot(p-w,g+y))/2;const x=r*S;const M=a?yl(a,d):void 0;let b=false;let C;let P=[];const E=(k,v=e.borderWidth??0,T=f,A=true,R=e.bounds,I)=>{if(!o())return false;if(!I&&P.includes(k))return true;if(I&&(I.x<R.x0||I.x>R.x1||I.y<R.y0||I.y>R.y1))return true;const L=I?[yl(I,d)]:m;let $=I?0:x;const B=I?-1e-8:l?0:1e-8;const F=I?-1e-8:0;if(k.kind==="compound")return k===u&&k.children.length<=64&&k.children.every((O,N)=>O.kind!=="compound"&&E(O,e.partBorderWidths?.[N]??0,h?.[N]??f,e.partFilled?.[N]??true,e.partBounds?.[N]??e.bounds,I));if(!A){if(Pn(T.opacity)===0||Pn(T.strokeOpacity)===0||$n(T,k.kind!=="line")===0)return true}if(k.kind==="line"){if(!I&&C&&M&&["butt","round","square"].includes(T.strokeLinecap??"butt")){if(!o())return false;const G=k.x2-k.x1,Y=k.y2-k.y1;const q=M.x===k.x1&&M.y===k.y1?1:M.x===k.x2&&M.y===k.y2?-1:0;if(q&&Number.isFinite(G)&&Number.isFinite(Y)&&(G!==0||Y!==0)&&m.every(V=>{if(!o())return false;const ne=((V.x-M.x)*G+(V.y-M.y)*Y)*q;return Number.isFinite(ne)&&ne<=0}))return E(k,v,T,A,R,C)}const O=$n(T,false);if(O===void 0)return false;if(O===0)return true;const N=O*(T.vectorEffect==="non-scaling-stroke"?S:1);return L.every(G=>o()&&G.x+$<=Math.min(k.x1,k.x2)-N+F)||L.every(G=>o()&&G.x-$>=Math.max(k.x1,k.x2)+N-F)||L.every(G=>o()&&G.y+$<=Math.min(k.y1,k.y2)-N+F)||L.every(G=>o()&&G.y-$>=Math.max(k.y1,k.y2)+N-F)}const z=$n(T,["polygon","polyline","path"].includes(k.kind));if(z===void 0)return false;if(I)$=z*(T.vectorEffect==="non-scaling-stroke"?S:1);else if(z>0&&Pn(T.opacity)!==0&&Pn(T.strokeOpacity)!==0&&!(n&&b&&v>0)&&Ur(R,t))return false;const _=!I&&n&&b?Math.max(0,v/2):0;if(k.kind==="rect"){const O=Math.min(k.width/2,k.rx??k.ry??0),N=Math.min(k.height/2,k.ry??k.rx??0);if(O>0&&N>0){const G=!c.transform&&NC(e.primitive)&&d.every((K,Z)=>K===[1,0,0,1,0,0][Z])&&Number(Xe(v))===v&&Number.parseFloat(Xn("stroke-width",T.strokeWidth??"1"))===Number.parseFloat(T.strokeWidth??"1");const Y=G&&Number(Xe(k.x))===k.x&&Number(Xe(k.width))===k.width;const q=G&&Number(Xe(k.y))===k.y&&Number(Xe(k.height))===k.height;if(Y&&(L.every(K=>o()&&K.x+$<=k.x+_+B)||L.every(K=>o()&&K.x-$>=k.x+k.width-_-B))||q&&(L.every(K=>o()&&K.y+$<=k.y+_+B)||L.every(K=>o()&&K.y-$>=k.y+k.height-_-B)))return true;const V=k.x+k.width/2,ne=k.y+k.height/2;const X=k.width/2-O,U=k.height/2-N;for(const K of L){if(!o())return false;const Z=K.x-V,Q=K.y-ne;const se=(Z-Math.max(-X,Math.min(X,Z)))/(O*O);const te=(Q-Math.max(-U,Math.min(U,Q)))/(N*N);const ee=Math.hypot(se,te);if(!ee)continue;const ae=se/ee,ie=te/ee;const oe=X*Math.abs(ae)+U*Math.abs(ie)+Math.hypot(O*ae,N*ie)-_+$;if(L.every(ue=>o()&&(ue.x-V)*ae+(ue.y-ne)*ie>=oe-B))return true}return false}}if(k.kind==="ellipse"||k.kind==="circle"){const O=k.kind==="circle"?k.r:k.rx,N=k.kind==="circle"?k.r:k.ry;if(!(O>0&&N>0))return false;if(k.kind==="circle"){const G=Math.max(Math.min(...L.map(q=>q.x)),Math.min(k.cx,Math.max(...L.map(q=>q.x))));const Y=Math.max(Math.min(...L.map(q=>q.y)),Math.min(k.cy,Math.max(...L.map(q=>q.y))));if(Math.hypot(G-k.cx,Y-k.cy)>=O-_+$-B)return true}for(const G of L){if(!o())return false;const Y=(G.x-k.cx)/(O*O),q=(G.y-k.cy)/(N*N),V=Math.hypot(Y,q);if(!V)continue;const ne=Y/V,X=q/V;const U=Math.hypot(O*ne,N*X)-_+$;if(L.every(K=>o()&&(K.x-k.cx)*ne+(K.y-k.cy)*X>=U-B))return true}return false}const H=k.kind==="rect"?[{x:k.x,y:k.y},{x:k.x+k.width,y:k.y},{x:k.x+k.width,y:k.y+k.height},{x:k.x,y:k.y+k.height}]:k.kind==="polygon"?k.points:void 0;if(!H||H.length<3||H.length>64)return false;const D=(O,N,G)=>(N.x-O.x)*(G.y-O.y)-(N.y-O.y)*(G.x-O.x);const j=H.reduce((O,N,G)=>{const Y=H[(G+1)%H.length];return O+N.x*Y.y-Y.x*N.y},0);const W=Math.sign(j);if(!W||!H.every((O,N)=>H.every(G=>o()&&W*D(O,H[(N+1)%H.length],G)>=-(I||l?0:1e-8))))return false;return H.some((O,N)=>{const G=H[(N+1)%H.length],Y=Math.hypot(G.x-O.x,G.y-O.y);return Y>0&&L.every(q=>o()&&W*D(O,G,q)<=(_-$+B)*Y)})};if(n)C=s?.find(k=>o()&&E(u,e.borderWidth??0,f,true,e.bounds,k));b=C!==void 0;if(b&&M&&u.kind==="compound"&&d.every((k,v)=>k===[1,0,0,1,0,0][v])){const k=u.children[0];if(o()&&k?.kind==="rect"&&!k.rx&&!k.ry&&e.partFilled?.[0]&&$n(h?.[0]??f,false)===0){const v=M.x===k.x?1:M.x===k.x+k.width?2:0;const T=u.children[v],A=e.partOwnBorderWidths?.[v]??0;if(v&&T?.kind==="line"&&A>0&&T.x1===T.x2&&T.x1===M.x&&Math.min(T.y1,T.y2)===k.y&&Math.max(T.y1,T.y2)===k.y+k.height&&M.y>k.y&&M.y<k.y+k.height&&m.every(R=>o()&&(v===1?-1:1)*(R.x-T.x1)>=x-A/2))P=[k,T]}}return E(u)}function RB(e,t,n,i){const{position:r,anchor:o}=n;for(let E=0;E<18;E++)if(!i())return void 0;if(!t||r==="mid"||e.transform||e.route.closed||e.stroke.nonScaling||t.overflow==="visible"||(t.scale??1)!==1||t.paint?.vectorEffect==="non-scaling-stroke"||t.orient!==void 0&&t.orient!=="auto"&&t.orient!=="auto-start-reverse"||!t.size||!t.ref||!(t.size.width>0)||!(t.size.height>0)||!Number.isFinite(t.size.width+t.size.height+t.ref.x+t.ref.y)||t.ref.y<0||t.ref.y>t.size.height||t.ref.x!==0&&t.ref.x!==t.size.width||t.viewBox&&(t.viewBox.x!==0||t.viewBox.y!==0||t.viewBox.width!==t.size.width||t.viewBox.height!==t.size.height))return void 0;const s=e.route.geometry;let a,l;const c=(E,k)=>{if(!i()||!Number.isFinite(E)||!Number.isFinite(k))return false;if(!a)a={x:E,y:k};else if(E!==a.x||k!==a.y){l={x:E,y:k};return false}return true};if(s.kind==="line"){if(!c(r==="start"?s.x1:s.x2,r==="start"?s.y1:s.y2))return void 0;c(r==="start"?s.x2:s.x1,r==="start"?s.y2:s.y1)}else if(s.kind==="polyline"){for(let E=0;E<s.points.length;E++){const k=s.points[r==="start"?E:s.points.length-E-1];if(!c(k.x,k.y))break}}else return void 0;if(!a||!l||a.x!==o.x||a.y!==o.y||a.x!==l.x&&a.y!==l.y)return void 0;const d=E=>({x:Number(Xe(E.x)),y:Number(Xe(E.y))});const u=d(a),f=d(l);const h=a.y===l.y;if(![u.x,u.y,f.x,f.y].every(Number.isFinite)||h&&(u.x!==a.x||u.y!==f.y||Math.sign(f.x-u.x)!==Math.sign(l.x-a.x))||!h&&(u.y!==a.y||u.x!==f.x||Math.sign(f.y-u.y)!==Math.sign(l.y-a.y)))return void 0;let m=1;if(t.units!=="userSpaceOnUse"){const E=String(e.stroke.width);if(!/^\s*(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?(?:px)?\s*$/i.test(E))return void 0;m=Number.parseFloat(typeof e.stroke.width==="number"?Xe(e.stroke.width):Xn("stroke-width",e.stroke.width));if(!(m>0)||!Number.isFinite(m)||m!==Number.parseFloat(E))return void 0}const p=r==="start"?u:f,g=r==="start"?f:u;const y={x:g.x-p.x,y:g.y-p.y};const w=Yr({route:{geometry:{kind:"line",x1:p.x,y1:p.y,x2:g.x,y2:g.y},closed:false,contours:[{start:p,end:g,closed:false,startTangent:y,endTangent:y}]},stroke:{width:m},markers:{mid:[],...r==="start"?{start:t}:{end:t}}})[0];if(!i()||!w?.bounds||!n.bounds)return void 0;const S=bs(n.bounds,w.bounds);const x=r==="end"?-1:t.orient==="auto-start-reverse"?-1:1;const M=t.ref.x===0?1:-1;const b=Math.sign(l.x-a.x)*x*M;const C=Math.sign(l.y-a.y)*x*M;if(!i())return void 0;const P={x0:b>0?Math.max(S.x0,w.anchor.x):S.x0,y0:C>0?Math.max(S.y0,w.anchor.y):S.y0,x1:b<0?Math.min(S.x1,w.anchor.x):S.x1,y1:C<0?Math.min(S.y1,w.anchor.y):S.y1};return P.x0<=P.x1&&P.y0<=P.y1?{region:{...w,bounds:S},clipped:P}:void 0}function vB(e,t,n,i){if(!e||!t||e.geometry?.kind!=="polygon"||(e.scale??1)>1||Pn(e.paint?.opacity)!==1||Pn(e.paint?.fillOpacity)!==1||!e.paint?.fill)return void 0;const r=n(e.paint.fill);if(!r||Kt(r)?.[3]!==1)return void 0;const o=e.geometry.points;if(o.length<3||o.length>64||o.length!==t.length)return void 0;const s=o.reduce((h,m,p)=>{const g=o[(p+1)%o.length];return h+m.x*g.y-g.x*m.y},0);const a=Math.sign(s);if(!a||!o.every((h,m)=>o.every(p=>i()&&a*((o[(m+1)%o.length].x-h.x)*(p.y-h.y)-(o[(m+1)%o.length].y-h.y)*(p.x-h.x))>=0)))return void 0;const l=h=>({x:h.reduce((m,p)=>m+p.x,0)/h.length,y:h.reduce((m,p)=>m+p.y,0)/h.length});const c=l(o),d=l(t);const u=e.viewBox??(e.size?{x:0,y:0,width:e.size.width,height:e.size.height}:void 0);const f=[];for(let h=-1,m=o.length;h<m;h++){if(!i())continue;const p=h<0?c:{x:(c.x+o[h].x)/2,y:(c.y+o[h].y)/2};if(e.overflow!=="visible"&&(!u||!(p.x>u.x&&p.x<u.x+u.width&&p.y>u.y&&p.y<u.y+u.height)))continue;f.push(h<0?d:{x:(d.x+t[h].x)/2,y:(d.y+t[h].y)/2})}return f}function TB(e,t,n,i){if(t?.length)return true;if(!e?.geometry||Pn(e.paint?.opacity)!==1)return false;const r=e.viewBox??(e.size?{x:0,y:0,width:e.size.width,height:e.size.height}:void 0);const o=c=>Number.isFinite(c.x)&&Number.isFinite(c.y)&&(e.overflow==="visible"||!!r&&c.x>r.x&&c.x<r.x+r.width&&c.y>r.y&&c.y<r.y+r.height);const s=c=>{if(!c||!i())return false;const d=n(c);return!!d&&Kt(d)?.[3]===1};const a=e.geometry;if(Pn(e.paint?.fillOpacity)===1&&s(e.paint?.fill)){if(a.kind==="circle"&&a.r>0&&o({x:a.cx,y:a.cy}))return true;if(a.kind==="ellipse"&&a.rx>0&&a.ry>0&&o({x:a.cx,y:a.cy}))return true;if(a.kind==="rect"&&a.width>0&&a.height>0&&o({x:a.x+a.width/2,y:a.y+a.height/2}))return true}if(Pn(e.paint?.strokeOpacity)!==1||!s(e.paint?.stroke)||e.paint?.strokeDasharray||!(Number.parseFloat(e.paint?.strokeWidth??"1")>0)||$n(e.paint??{},true)===void 0)return false;const l=(c,d)=>i()&&Math.hypot(d.x-c.x,d.y-c.y)>0&&o({x:(c.x+d.x)/2,y:(c.y+d.y)/2});if(a.kind==="line")return l({x:a.x1,y:a.y1},{x:a.x2,y:a.y2});if(a.kind==="polygon"||a.kind==="polyline")return a.points.length<=64&&a.points.some((c,d)=>d>0&&l(a.points[d-1],c));if(a.kind==="path"){let c=false;const d=Ss(a.d,u=>{if(u.line&&l(u.line[0],u.line[1]))c=true;return i()},i);return d&&c}return false}function lb(e,t,n,i,r,o=void 0){const s=W=>{for(let O=0;O<W;O++)if(!r())return false;return true};if(!s(3)||!n||i==="mid"||n.geometry?.kind!=="polygon"&&n.geometry?.kind!=="polyline"||n.geometry.points.length<3||n.geometry.points.length>64||t.transform||n.geometry.kind==="polyline"&&n.paint?.strokeLinecap!==void 0&&!["butt","round"].includes(n.paint.strokeLinecap)||t.route.closed||t.stroke.nonScaling||t.stroke.mixBlendMode&&t.stroke.mixBlendMode!=="normal"||(n.scale??1)!==1||n.paint?.vectorEffect==="non-scaling-stroke"||n.paint?.strokeLinejoin&&!["miter","round","bevel"].includes(n.paint.strokeLinejoin)||!n.size||!n.ref||!(n.size.width>0)||!(n.size.height>0)||!Number.isFinite(n.size.width+n.size.height+n.ref.x+n.ref.y)||n.viewBox&&(!(n.viewBox.width>0)||!(n.viewBox.height>0)||!Number.isFinite(n.viewBox.x+n.viewBox.y+n.viewBox.width+n.viewBox.height)))return void 0;const a=String(t.stroke.width);if(!/^\s*(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?(?:px)?\s*$/i.test(a))return void 0;const l=W=>Number(Xe(W));const c=Number.parseFloat(typeof t.stroke.width==="number"?Xe(t.stroke.width):Xn("stroke-width",t.stroke.width));if(!(c>0)||!Number.isFinite(c)||!s(12+5*n.geometry.points.length))return void 0;const d=t.route.geometry;let u,f;const h=(W,O)=>{if(!r())return false;const N={x:l(W),y:l(O)};if(!Number.isFinite(N.x)||!Number.isFinite(N.y))return false;if(!u)u=N;else if(N.x!==u.x||N.y!==u.y){f=N;return false}return true};if(d.kind==="line"){h(i==="start"?d.x1:d.x2,i==="start"?d.y1:d.y2);h(i==="start"?d.x2:d.x1,i==="start"?d.y2:d.y1)}else if(d.kind==="polyline"){for(let W=0;W<d.points.length;W++){const O=d.points[i==="start"?W:d.points.length-W-1];if(!h(O.x,O.y))break}}else return void 0;if(!u||!f||!r()||u.x!==f.x&&u.y!==f.y)return void 0;const m=n.geometry.points;const p=n.geometry.kind==="polygon"?n:{...n,geometry:{kind:"polygon",points:m}};const g=i==="start"?{x:f.x-u.x,y:f.y-u.y}:{x:u.x-f.x,y:u.y-f.y};const y=i==="start"?u:f,w=i==="start"?f:u;const S={kind:"line",x1:y.x,y1:y.y,x2:w.x,y2:w.y};const x=Yr({route:{...t.route,geometry:S,contours:[{start:y,end:w,closed:false,startTangent:g,endTangent:g}]},stroke:{...t.stroke,width:c},markers:{mid:[],...i==="start"?{start:p}:{end:p}}})[0];const M=x?.hull;if(!M||M.length!==m.length||!s(M.length))return void 0;let b=0;for(let W=0;W<M.length;W++){const O=M[W],N=M[(W+1)%M.length];for(const G of M){if(!r())return void 0;const Y=(N.x-O.x)*(G.y-O.y)-(N.y-O.y)*(G.x-O.x);if(!Number.isFinite(Y))return void 0;if(Y){if(b&&Math.sign(Y)!==b)return void 0;b||=Math.sign(Y)}}}if(!b)return void 0;const C=p.viewBox??(p.size?{x:0,y:0,...p.size}:void 0);const P=W=>p.overflow==="visible"||!!C&&W.x>C.x&&W.x<C.x+C.width&&W.y>C.y&&W.y<C.y+C.height;const E=n.paint??{};const k=W=>{if(!W||!r())return void 0;const O=o?o(W):fm(W,e.colors);return O?Kt(O)??void 0:void 0};const v=k(E.fill),T=k(E.stroke);const A=Pn(E.opacity);const R=E.fill==="none"||A<1||!!v&&v[3]<1?"absent":v?.[3]===1&&A===1&&m.every(W=>r()&&P(W))?"opaque":"unknown";const I=E.stroke===void 0||E.stroke==="none"||A===0||T?.[3]===0;const L=E.strokeWidth??"1";const $=/^\s*(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?(?:px)?\s*$/i.test(L)?Number.parseFloat(L):void 0;const B=(p.units==="userSpaceOnUse"?1:c)*(p.viewBox&&p.size?Math.min(p.size.width/p.viewBox.width,p.size.height/p.viewBox.height):1);const F=I?0:$!==void 0&&Number.isFinite($*B)?$*B/2:void 0;const z=I||$===0?"absent":$!==void 0&&$>0&&T?.[3]===1&&A===1&&!E.strokeDasharray?"visible":"unknown";const _=[];if(!I&&$!==void 0&&$>0&&T?.[3]===1&&A===1&&!E.strokeDasharray){for(let N=0;N<m.length-(n.geometry.kind==="polyline"?1:0);N++){const G=m[N],Y=m[(N+1)%m.length];if(G.x===Y.x&&G.y===Y.y)continue;for(let q=1;q<4;q++){if(!s(3))return void 0;const V=q/4,ne={x:G.x*(1-V)+Y.x*V,y:G.y*(1-V)+Y.y*V};if(P(ne))_.push({x:M[N].x*(1-V)+M[(N+1)%M.length].x*V,y:M[N].y*(1-V)+M[(N+1)%M.length].y*V})}}const W=n.geometry.kind==="polygon"?0:1;const O=m.length-(n.geometry.kind==="polygon"?0:1);for(let N=W;N<O;N++){if(!s(2))return void 0;const G=m[(N+m.length-1)%m.length],Y=m[N],q=m[(N+1)%m.length];if((G.x!==Y.x||G.y!==Y.y)&&(Y.x!==q.x||Y.y!==q.y)&&P(Y))_.push(M[N])}}let H=false;if(n.overflow==="hidden"){if(!s(5))return void 0;H=n.viewBox?.x===0&&n.viewBox.y===0&&n.viewBox.width===n.size.width&&n.viewBox.height===n.size.height}let D;if((n.overflow==="visible"||H)&&(n.orient===void 0||n.orient==="auto"||n.orient==="auto-start-reverse")&&R!=="unknown"&&z!=="unknown"&&A===1&&(n.geometry.kind==="polygon"||E.fill==="none"||v?.[3]===0)&&!E.strokeDasharray&&(E.strokeLinecap===void 0||E.strokeLinecap==="butt")&&(E.strokeLinejoin===void 0||E.strokeLinejoin==="miter")&&(E.strokeMiterlimit===void 0||Number(E.strokeMiterlimit)===4)){if(H&&!s(16))return void 0;const W=H?{id:n.id,shape:n.shape,geometry:n.geometry,paint:n.paint,units:n.units,size:n.size,ref:n.ref,orient:n.orient,viewBox:n.viewBox,scale:n.scale,overflow:"visible"}:n;D={marker:W,anchor:u,tangent:g,position:i,width:c}}if(D&&!r())return void 0;if(!s(6))return void 0;const j={resource:x.repaint,anchor:u,geometry:n.geometry.kind};return{repaint:j,hull:M,fill:R,stroke:z,fillColor:v,strokeColor:T,innerStroke:F,strokeWitnesses:_,padding:x.padding,...D?{paintPieceSource:D}:{}}}function QC(e,t){const n=e.marker.geometry;if(n.kind!=="polygon"&&n.kind!=="polyline")return void 0;const i=n.points,r=n.kind==="polygon"?i.length:i.length-2;for(let a=0;a<r;a++){for(let S=0;S<8;S++)if(!t())return void 0;const l=n.kind==="polygon"?a:a+1;const c=i[(l+i.length-1)%i.length],d=i[l],u=i[(l+1)%i.length];const f=d.x-c.x,h=d.y-c.y,m=u.x-d.x,p=u.y-d.y;const g=Math.hypot(f,h),y=Math.hypot(m,p),w=f/g*(m/y)+h/g*(p/y);if(!(g>0)||!(y>0)||!Number.isFinite(w)||w<=-.875+128*Number.EPSILON)return void 0}const o={};let s;try{s=zo(e.marker,e.anchor,e.tangent,e.position,e.width,()=>{if(!t())throw o})}catch(a){if(a===o)return void 0;throw a}for(const a of s){if(!t()||a.kind!=="polygon"||a.points.length<3)return void 0;let l=0;for(let c=0;c<a.points.length;c++){if(!t())return void 0;const d=a.points[c],u=a.points[(c+1)%a.points.length];if(!Number.isFinite(d.x)||!Number.isFinite(d.y))return void 0;l+=(d.x-a.points[0].x)*(u.y-a.points[0].y)-(d.y-a.points[0].y)*(u.x-a.points[0].x)}if(!Number.isFinite(l)||l===0)return void 0}return s}function LB(e,t,n){for(const i of e)for(const r of t){if(!n()||i.kind!=="polygon"||r.kind!=="polygon")return false;let o=false;for(const s of[i.points,r.points]){for(let a=0;a<s.length;a++){if(!n())return false;const l=s[a],c=s[(a+1)%s.length],d=l.y-c.y,u=c.x-l.x,f=Math.hypot(d,u);if(!(f>0)||!Number.isFinite(f))continue;const h=d/f,m=u/f,p=i.points[0];let g=Infinity,y=-Infinity,w=Infinity,S=-Infinity,x=1;for(const b of i.points){if(!n())return false;const C=(b.x-p.x)*h+(b.y-p.y)*m;g=Math.min(g,C);y=Math.max(y,C);x=Math.max(x,Math.abs(b.x),Math.abs(b.y))}for(const b of r.points){if(!n())return false;const C=(b.x-p.x)*h+(b.y-p.y)*m;w=Math.min(w,C);S=Math.max(S,C);x=Math.max(x,Math.abs(b.x),Math.abs(b.y))}const M=1e-8+128*Number.EPSILON*x;if(Number.isFinite(g+y+w+S)&&(y+M<w||S+M<g)){o=true;break}}if(o)break}if(!o)return false}return true}function eP(e,t,n){if(!n())return"exhausted";const i=s=>s?.fill==="absent"&&s.stroke==="absent"&&(s.fillColor?.[3]===0||s.paintPieceSource?.marker.paint?.fill==="none");if(i(e)||i(t))return"clear";if(!e?.paintPieceSource||!t?.paintPieceSource)return"unknown";const r={};const o=()=>{if(!n())throw r;return true};try{const s=QC(e.paintPieceSource,o);if(s){const a=QC(t.paintPieceSource,o);if(a&&LB(s,a,o))return"clear"}}catch(s){if(s===r)return"exhausted";throw s}return"unknown"}function cb(e,t,n,i=0){if(!n()||!Number.isSafeInteger(i)||i<0)return"unknown";if(t?.fill==="absent"||e?.stroke==="absent"&&e.fill==="absent")return"clear";if(!e||!t)return"unknown";const r=t.hull;if(e.innerStroke!==void 0){let s=0;for(let a=0;a<e.hull.length;a++){if(!n())return"unknown";const l=e.hull[a],c=e.hull[(a+1)%e.hull.length],d=e.hull[(a+2)%e.hull.length];const u=(c.x-l.x)*(d.y-c.y)-(c.y-l.y)*(d.x-c.x);if(u){s=Math.sign(u);break}}if(s)for(let a=0;a<e.hull.length;a++){if(!n())return"unknown";const l=e.hull[a],c=e.hull[(a+1)%e.hull.length],d=c.x-l.x,u=c.y-l.y,f=Math.hypot(d,u);if(!f)continue;let h=true;for(const m of r){if(!n())return"unknown";const p=s*(d*(m.y-l.y)-u*(m.x-l.x))/f;const g=1e-8+64*Number.EPSILON*Math.max(1,Math.abs(m.x),Math.abs(m.y),Math.abs(l.x),Math.abs(l.y),Math.abs(c.x),Math.abs(c.y));if(!Number.isFinite(p)||p>=-e.innerStroke-g){h=false;break}}if(h)return"clear"}}if(e.padding!==void 0&&Number.isFinite(e.padding)){for(const s of[e.hull,r])for(let a=0;a<s.length;a++){if(!n())return"unknown";const l=s[a],c=s[(a+1)%s.length],d=c.y-l.y,u=l.x-c.x,f=Math.hypot(d,u);if(!f)continue;let h=Infinity,m=-Infinity,p=Infinity,g=-Infinity;for(const y of e.hull){if(!n())return"unknown";const w=(y.x-l.x)*d+(y.y-l.y)*u;h=Math.min(h,w);m=Math.max(m,w)}for(const y of r){if(!n())return"unknown";const w=(y.x-l.x)*d+(y.y-l.y)*u;p=Math.min(p,w);g=Math.max(g,w)}if(m+e.padding*f<p||g<h-e.padding*f)return"clear"}}if(e.paintPieceSource&&t.paintPieceSource){const s=eP(e,t,n);if(s==="clear")return"clear";if(s==="exhausted")return"unknown"}if(e.stroke!=="visible"||t.fill!=="opaque"||t.innerStroke===void 0)return"unknown";if(!e.strokeColor||!t.fillColor)return"unknown";let o=true;for(let s=0;s<3;s++){if(!n())return"unknown";if(e.strokeColor[s]!==t.fillColor[s])o=false}if(o)return"unknown";for(let s=i;s<e.strokeWitnesses.length;s++){if(!n())return"unknown";const a=e.strokeWitnesses[s];let l=0,c=true;for(let d=0;d<r.length;d++){if(!n())return"unknown";const u=r[d],f=r[(d+1)%r.length],h=f.x-u.x,m=f.y-u.y,p=Math.hypot(h,m);const g=h*(a.y-u.y)-m*(a.x-u.x);const y=1e-8+64*Number.EPSILON*Math.max(1,Math.abs(a.x),Math.abs(a.y),Math.abs(u.x),Math.abs(u.y),Math.abs(f.x),Math.abs(f.y));if(!Number.isFinite(g)||!p||Math.abs(g)/p<=t.innerStroke+y||l&&Math.sign(g)!==l){c=false;break}l||=Math.sign(g)}if(c&&l)return a}return"unknown"}function AB(e,t,n){if(!e||e.innerStroke===void 0)return false;const i=e.hull;let r=0;for(let o=0;o<i.length;o++){if(!n())return false;const s=i[o],a=i[(o+1)%i.length],l=i[(o+2)%i.length];const c=(a.x-s.x)*(l.y-a.y)-(a.y-s.y)*(l.x-a.x);if(c){r=Math.sign(c);break}}if(!r)return false;for(let o=0;o<i.length;o++){if(!n())return false;const s=i[o],a=i[(o+1)%i.length],l=a.x-s.x,c=a.y-s.y;const d=Math.hypot(l,c),u=r*(l*(t.y-s.y)-c*(t.x-s.x))/d;const f=1e-8+64*Number.EPSILON*Math.max(1,Math.abs(t.x),Math.abs(t.y),Math.abs(s.x),Math.abs(s.y),Math.abs(a.x),Math.abs(a.y));if(Number.isFinite(u)&&u<-e.innerStroke-f)return true}return false}function IB(e,t,n){if(!n()||!t)return true;if(t.geometry?.kind==="line"||t.paint?.fill==="none"||t.paint?.fill==="transparent"||Pn(t.paint?.opacity)<1)return false;const i=t.paint?.fill;if(!i||!n())return true;const r=e(i),o=r?Kt(r):null;return!o||o[3]===1}function FB(e,t,n){const i=e?.paint;if(!n()||!i||!Number.isFinite(Pn(i.opacity))||$n(i,true)===void 0||i.strokeDasharray!==void 0&&i.strokeDasharray!=="none"||i.strokeDashoffset!==void 0||i.paintOrder!==void 0&&i.paintOrder!=="normal")return void 0;if(!i.fill||!i.stroke||!n())return void 0;const r=t(i.fill);if(!r||r!=="none"&&!Kt(r)||!n())return void 0;const o=t(i.stroke);if(!o||o!=="none"&&!Kt(o))return void 0;return`${r}\0${o}`}function NB(e,t){const[n,i]=e;let r=0,o=1;for(const[s,a,l,c]of[[n.x,i.x-n.x,t.x0,t.x1],[n.y,i.y-n.y,t.y0,t.y1]]){if(Math.abs(a)<1e-12){if(s<=l+1e-8||s>=c-1e-8)return false}else{const d=(l-s)/a,u=(c-s)/a;r=Math.max(r,Math.min(d,u));o=Math.min(o,Math.max(d,u))}}return(o-r)*Math.hypot(i.x-n.x,i.y-n.y)>1e-8}var tP=new Set(["node","service","class-box","entity"]);var $B=new Set([...tP,"group","note","actor","junction"]);function nP(e,t,n={}){return db(e,_C(e),t,n)}function db(e,t,n,i={}){const r=[];let o=false,s=false;const a=(X,U=false)=>{if(r.length<wB)r.push(Object.freeze(X));if(U)o=true;else s=true};const l=(X,U,K)=>a({code:"POTENTIAL_OCCLUSION",id:X,by:U,message:K});const c=(X,U,K=false)=>a({code:"UNMEASURED_PAINT",id:X,message:U},K);const d=X=>a({code:"OUTPUT_SCOPE",message:X});const u=jC(t);if(u&&e!==u.header){d("Retained emission is paired with a different document header");e=u.header}let f=0,h=0,m=e.width,p=e.height,g=0;for(const X of t.primitives){if(!u&&GC(X))d("Native paint occurrences have no bound emission context");if(X.visibility==="conditional"){g++;continue}if(X.coverage==="unmeasured")c(X.id,X.reason??"Paint geometry is unavailable");if(X.text&&X.coverage!=="non-painting"&&X.text.measurement!=="prepared")a({code:"UNPREPARED_TEXT",id:X.id,message:"Text was not retained from layout preparation"});const U=X.bounds;if(U){f=Math.min(f,U.x0);h=Math.min(h,U.y0);m=Math.max(m,U.x1);p=Math.max(p,U.y1)}}if(g)a({code:"CONDITIONAL_PAINT",message:`${g} primitives depend on unresolved paint or interaction state`});if(i.outputSupported===false||e.family.startsWith("family:"))d("Selected backend, style or external family has no native final-paint proof");f=Math.min(0,f+Gc);h=Math.min(0,h+Gc);m=Math.max(e.width,m-Gc);p=Math.max(e.height,p-Gc);const y=f<0||h<0||m>e.width||p>e.height;const w={x:Math.floor(f),y:Math.floor(h),width:Math.ceil(m)-Math.floor(f),height:Math.ceil(p)-Math.floor(h)};if(y&&e.width>0&&e.height>0){const X=e.width/e.height;if(w.width/w.height>X)w.height=w.width/X;else w.width=w.height*X}const S=Object.freeze(y?w:{x:0,y:0,width:e.width,height:e.height});const x=kB(S);if(y&&t.primitives.some(X=>{const U=Cs(X);return U?.kind==="connector"?U.stroke.nonScaling:U?.kind==="shape"||U?.kind==="text"?U.paint.vectorEffect==="non-scaling-stroke":false}))d("Viewport expansion changes the user-unit extent of non-scaling strokes; final painted containment is unverified");let M=0;const b=(X,U,K)=>{M++;if(!U||!K){c(X,"Projected label has no retained occupied or available region");return}let Z=qC(K);if(Z.x0===0&&Z.y0===0&&Z.x1===e.width&&Z.y1===e.height)Z=x;if(!Hc(Z,qC(U),MB))a({code:"LABEL_CONTAINMENT",id:X,message:"Retained text extends beyond its declared available region"},true)};if(n){for(const X of n.nodes)if(X.label?.trim()&&X.labelVisibility!=="hidden"&&X.labelVisibility!=="semantic")b(String(X.id),X.labelBounds,X.labelContainer);for(const X of n.labels??[])if(X.text.trim()&&X.visibility!=="hidden"&&X.visibility!=="semantic")b(X.id,X.bounds,X.container)}if(u?.uncertain)d("Emitted document context or marker resource differs from retained paint evidence");let C=0,P=u?.operations??0,E=u?.exhausted??false;const k=()=>{if(P>=Ps){E=true;return false}P++;return true};const v=CB(EB(e,t.primitives),k);const T=new Map,A=[],R=[];for(const X of t.primitives){if(!k())break;if(X.kind==="connector")R.push(X);if(X.kind!=="text"||X.coverage!=="measured"||X.visibility==="conditional")continue;A.push(X);if(!X.ancestors.length)continue;const U=T.get(X.ancestors);if(U){U.bounds=bs(U.bounds,X.bounds);U.order=Math.min(U.order,X.order);U.count++}else T.set(X.ancestors,{bounds:X.bounds,order:X.order,count:1})}let I;const L=X=>{if(!I){I=new Map;for(const U of t.primitives){if(E)break;for(const K of[U.owner,...U.ancestors]){if(!k())break;if(!$B.has(K.role))continue;const Z=I.get(K.id)??new Set;Z.add(K.role);I.set(K.id,Z)}}}return E||(I.get(X)?.size??0)>1};const $=(X,U)=>{let K=false;for(const[Z,Q]of[[X.endpoints.from,X.endpoints.start],[X.endpoints.to,X.endpoints.end]]){if(Z!==U.id)continue;if(Q?.owner){if(Q.owner.id!==Z){K=true;continue}if(Q.owner.role===U.role)return"attached"}else if(L(Z))K=true;else return"attached"}return K?"ambiguous":"unrelated"};const B=(X,U,K,Z,Q)=>{if(E||Q&&(Q.remaining--<=0||Z.length>16)||!k()||!X||X.lastOrder<=K||!Ur(X.bounds,U))return;if(!X.leaves){B(X.left,U,K,Z,Q);B(X.right,U,K,Z,Q);return}for(const se of X.leaves){if(Q&&Q.remaining--<=0||!k())return;if(se.primitive.order>K&&Ur(se.bounds,U)){Z.push(se);if(Q&&Z.length>16)return}}};for(const X of A){const U=T.get(X.ancestors);let K;if(U&&U.count>1&&U.count<=8&&U.surfaces!==null){if(!U.surfaces){K=[];const Z={remaining:64};B(v,U.bounds,U.order,K,Z);U.surfaces=Z.remaining>=0&&K.length<=16?K:null}K=U.surfaces??void 0}if(!K){K=[];B(v,X.bounds,X.order,K)}for(const Z of K){if(!k())break;if(Z.primitive.order<=X.order||!Ur(Z.bounds,X.bounds))continue;if(++C>Go){E=true;break}if(Z.interiors?.some(Q=>k()&&Hc(Q,X.bounds)))a({code:"TEXT_OCCLUDED",id:X.id,by:Z.primitive.id,message:`Retained text is fully covered by later opaque artwork owned by ${Z.primitive.owner.id}`},true);else l(X.id,Z.primitive.id,"Later filled artwork overlaps the occupied text band; its exact ink intersection is unverified")}}const F=new Map;for(const X of R){if(!k())break;const U=Cs(X);if(U?.kind!=="connector"||!["edge","relationship"].includes(X.role)||U.lineStyle==="invisible"||X.visibility==="conditional"||X.coverage!=="measured")continue;const K=Number.parseFloat(String(U.stroke.width)),Z=Number(U.stroke.opacity??1);if(K===0||Z===0||U.stroke.color==="none"||U.stroke.color==="transparent")continue;if(!F.has(U.stroke.color)){const ve=fm(U.stroke.color,e.colors);F.set(U.stroke.color,ve?Kt(ve)?.[3]:void 0)}const Q=F.get(U.stroke.color);if(Q===0)continue;const se=i.outputSupported!==false&&!e.family.startsWith("family:")&&!!U.endpoints?.from&&!!U.endpoints.to&&Q!==void 0&&Q>0&&K>0&&Z>0&&!U.stroke.dash;const te=ua(X);const[ee,ae,ie,oe,ue,ye]=te;const Se={kind:"matrix",a:ee,b:ae,c:ie,d:oe,e:ue,f:ye};const Te=$n({stroke:U.stroke.color,strokeWidth:String(U.stroke.width),strokeLinecap:U.stroke.lineCap,strokeLinejoin:U.stroke.lineJoin,strokeMiterlimit:String(U.stroke.miterLimit)},z1(U.route));if(Te===void 0){c(X.id,"Final connector stroke has no bounded cap/join extent");continue}const Ie=ve=>{if(!k())return false;const $e=U.stroke.nonScaling?Oc(Bc(ve.bounds,Se),Te):Bc(Oc(ve.bounds,Te),Se);const De=ve.line?.map(me=>yl(me,te));const fe=me=>{if(E||!k()||!me||!Ur(me.bounds,$e))return;if(!me.leaves){fe(me.left);fe(me.right);return}for(const de of me.leaves){if(!k())return;if(++C>Go){E=true;return}const be=se&&de.primitive.role==="note"&&!!de.interiors?.length;if(!tP.has(de.primitive.role)&&!be||de.primitive.owner.id===X.owner.id&&de.primitive.owner.role===X.owner.role||!Ur(de.bounds,$e))continue;const pe=$(U,de.primitive.owner);if(pe==="attached")continue;if(se&&De&&PB(De,de.bounds,U.stroke,K,Te,te,k))continue;if(se&&pe==="unrelated"&&De&&de.interiors?.some(Re=>k()&&NB(De,Re)))a({code:"CONNECTOR_CARD_CROSSING",id:X.id,by:de.primitive.id,message:`Final connector shaft crosses opaque artwork owned by unrelated ${be?"note":"card"} ${de.primitive.owner.id}`},true);else l(X.id,de.primitive.id,be?"Final connector envelope intersects unrelated filled note artwork; actual route/note crossing is unverified":"Final connector envelope intersects unrelated filled card artwork; actual route/card crossing is unverified")}};fe(v);return!E};const Ee=U.route.geometry;if(Ee.kind==="path"){if(!Ss(Ee.d,Ie,k)&&!E)c(X.id,"Final connector segments could not be measured from typed path geometry")}else{const ve=Ee.kind==="line"?[{x:Ee.x1,y:Ee.y1},{x:Ee.x2,y:Ee.y2}]:Ee.points;for(let $e=1;$e<ve.length;$e++){const De=ve[$e-1],fe=ve[$e];if(!Ie({bounds:{x0:Math.min(De.x,fe.x),y0:Math.min(De.y,fe.y),x1:Math.max(De.x,fe.x),y1:Math.max(De.y,fe.y)},line:[De,fe]}))break}}}const z=new Map;let _;const H=X=>(_??=hm())(X,e.colors);for(const X of R){const U=Cs(X);if(X.kind!=="connector"||U?.kind!=="connector"||U.lineStyle==="invisible"||X.coverage==="non-painting")continue;const K=dm(ku(U.transform));if(!K)continue;const[Z,Q,se,te,ee,ae]=gl(ua(X),K);const ie={kind:"matrix",a:Z,b:Q,c:se,d:te,e:ee,f:ae};for(const oe of Yr(U,ie)){if(!oe.bounds){c(X.id,"Endpoint marker has no painted footprint");continue}const ue=JSON.stringify([X.owner.id,X.owner.role,oe.position,oe.resource,oe.anchor,oe.repaint]);const ye=typeof U.stroke.width==="number"?Number.isFinite(U.stroke.width)&&U.stroke.width>0:/^\s*(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?(?:px)?\s*$/i.test(U.stroke.width)&&Number.parseFloat(U.stroke.width)>0;const Se=oe.position==="start"?U.markers.start:oe.position==="end"?U.markers.end:U.markers.mid.length===1?U.markers.mid[0]:void 0;const Te=X.coverage==="measured"&&!!dm(ua(X));const Ie=Se?.units==="userSpaceOnUse"||ye;const Ee=z.get(ue);const ve=i.outputSupported!==false&&!e.family.startsWith("family:")&&(["edge","relationship"].includes(X.role)&&!!U.endpoints?.from&&!!U.endpoints.to||Ee?.semantic===true);const $e=ua(X);const De=X.coverage==="measured"&&X.visibility!=="conditional"&&(X.groupOpacity??1)===1&&X.ancestors.length===0&&!!$e&&$e[0]===1&&$e[1]===0&&$e[2]===0&&$e[3]===1&&$e[4]===0&&$e[5]===0;const fe=ve&&De&&Ie?RB(U,Se,oe,k):void 0;const me=fe?.region??oe;const de=Te&&Ie?vB(Se,me.hull,H,k):void 0;const be=Te&&Ie&&Se?.paint?.vectorEffect!=="non-scaling-stroke"&&TB(Se,de,H,k);const pe=IB(H,Se,k);const Re=ve&&(X.groupOpacity??1)===1&&X.ancestors.length===0&&(!U.stroke.mixBlendMode||U.stroke.mixBlendMode==="normal")?FB(Se,H,k):void 0;const Ne=ve&&De?lb(e,U,Se,oe.position,k,H):void 0;z.set(ue,{primitive:X,position:oe.position,clipped:fe?.clipped,anchor:me.anchor,repaint:me.repaint,bounds:me.bounds,hull:me.hull,padding:me.padding,witnesses:de,actualInk:be,strokeProof:Ne,paintIdentity:Re,semantic:ve,mayFill:pe})}}const D=(X,U)=>{if(U.primitive.visibility==="conditional")return;if(E||!k()||!X||X.lastOrder<=U.primitive.order||!Ur(X.bounds,U.bounds))return;if(!X.leaves){D(X.left,U);D(X.right,U);return}for(const K of X.leaves){if(!k())return;if(K.primitive.order<=U.primitive.order||!Ur(K.bounds,U.bounds))continue;if(++C>Go){E=true;return}if(U.actualInk&&(K.interiors?.some(se=>k()&&Hc(se,U.bounds))||K.strokeInteriors?.some(se=>k()&&Hc(se,U.bounds)))){a({code:"MARKER_OCCLUDED",id:U.primitive.id,by:K.primitive.id,message:"Endpoint marker is fully covered by later opaque artwork with no owned repaint"},true);continue}const Z=Cs(U.primitive);const Q=Z?.kind==="connector"&&$(Z,K.primitive.owner)==="attached";if(JC(K,U.bounds,Q,U.hull,U.padding,k,U.witnesses,U.anchor))continue;if(U.clipped&&JC(K,U.clipped,Q,void 0,0,k,U.witnesses,U.anchor,true))continue;l(U.primitive.id,K.primitive.id,"Later filled artwork overlaps an endpoint marker; its exact ink intersection is unverified")}};const j=Array.from(z.values());for(let X=0;X<j.length;X++)D(v,j[X]);let W=0,O=0;for(const X of j){if(!k())break;if(!X.semantic||X.primitive.visibility==="conditional")continue;W++;if(!(X.strokeProof?.fill==="absent"&&X.strokeProof.stroke==="absent"))O++}const N=O>Math.ceil(Math.log2(t.primitives.length+1))**2;const G=W>Math.ceil(Math.log2(W+1))**2;const Y=[];if(N)for(const[X,U]of t.primitives.entries()){if(!k())break;if(U.kind==="text"&&U.coverage==="measured"&&U.visibility!=="conditional"&&U.bounds)Y.push({primitive:U,bounds:U.bounds,index:X})}const q=N?UC(Y,k,O):void 0;const V=[];if(G)for(const[X,U]of j.entries()){if(!k())break;if(U.semantic&&U.primitive.visibility!=="conditional")V.push({primitive:U.primitive,bounds:U.bounds,target:U,index:X})}const ne=G?UC(V,k,W):void 0;for(let X=0;X<j.length;X++){const U=j[X];if(!k())break;if(!U.semantic||U.primitive.visibility==="conditional"||U.strokeProof?.fill==="absent"&&U.strokeProof.stroke==="absent")continue;const K=q?q(U.bounds).map(Z=>Z.primitive):t.primitives;for(const Z of K){if(!k())break;if(Z.kind!=="text"||Z.coverage!=="measured"||Z.visibility==="conditional"||!Z.bounds||!Ur(Z.bounds,U.bounds))continue;if(++C>Go){E=true;break}const Q=U.primitive.order>Z.order;l(Q?Z.id:U.primitive.id,Q?U.primitive.id:Z.id,Q?"Later endpoint-marker ink overlaps occupied text; actual text visibility is unverified.":"Later occupied text or its halo overlaps an endpoint marker; actual marker ink visibility is unverified.")}}for(let X=0;X<j.length;X++){const U=j[X];if(E)break;if(!U.semantic||U.primitive.visibility==="conditional")continue;const K=ne?ne(U.bounds).map(Z=>Z.target):j;for(const Z of K){if(!k())break;const Q=U.strokeProof?.repaint,se=Z.strokeProof?.repaint;const te=U.paintIdentity!==void 0&&U.paintIdentity===Z.paintIdentity;if(!Z.semantic||Z.primitive.visibility==="conditional"||Z.primitive.order<=U.primitive.order||te&&(U.anchor.x===Z.anchor.x&&U.anchor.y===Z.anchor.y&&U.repaint===Z.repaint||Q&&se&&Q.resource===se.resource&&Q.geometry===se.geometry&&Q.anchor.x===se.anchor.x&&Q.anchor.y===se.anchor.y)||!Ur(U.bounds,Z.bounds))continue;if(++C>Go){E=true;break}let ee=0,ae="unknown";while(!E){let ie=Z.mayFill?cb(U.strokeProof,Z.strokeProof,k,ee):eP(U.strokeProof,Z.strokeProof,k);if(ie==="exhausted")ie="unknown";if(typeof ie==="string"){ae=ie;break}let oe=false;const ue=t.primitives;for(let Te=0;Te<ue.length;Te++){const Ie=ue[Te];if(!k())break;const Ee=Ie.bounds;if(Ie.order<=Z.primitive.order||Ie.coverage==="non-painting")continue;if(!Ee){oe=true;break}if(Ee.x0>ie.x||ie.x>Ee.x1||Ee.y0>ie.y||ie.y>Ee.y1)continue;const ve=Cs(Ie);if(ve?.kind==="connector"&&Number(ve.stroke.opacity)===0){let $e=false;for(let De=0;De<j.length;De++){const fe=j[De];if(!k())break;if(fe.primitive.order!==Ie.order||fe.bounds.x0>ie.x||ie.x>fe.bounds.x1||fe.bounds.y0>ie.y||ie.y>fe.bounds.y1)continue;if(!AB(fe.strokeProof,ie,k)){$e=true;break}}if(!$e&&!E)continue}oe=true;break}if(!oe&&!E){ae="covered";break}const ye=U.strokeProof.strokeWitnesses;let Se=false;for(;ee<ye.length;ee++){if(!k())break;if(ye[ee]===ie){ee++;Se=true;break}}if(!Se)break}if(ae==="covered"&&!E)a({code:"MARKER_OCCLUDED",id:U.primitive.id,by:Z.primitive.id,message:"Later opaque endpoint-marker fill covers actual stroke ink of a distinct marker."},true);else if(ae==="unknown")l(U.primitive.id,Z.primitive.id,"Distinct endpoint-marker envelopes overlap; actual marker ink separation is unverified.")}}if(E)a({code:"CHECK_BUDGET",message:`Occlusion checking reached its ${Go}-pair or ${Ps}-operation limit`});for(const X of t.primitives)if(X.bounds&&X.visibility!=="conditional"&&!Hc(x,X.bounds,Gc))c(X.id,"Final viewport does not contain retained paint",true);for(const X of j)if(X.primitive.visibility!=="conditional"&&!Hc(x,X.bounds,Gc))c(X.primitive.id,"Final viewport does not contain serialized marker paint",true);return Object.freeze({version:1,unit:"px",scope:"native-scene",status:o?"failed":s?"unverified":"passed",viewport:S,attempts:y?2:1,repairs:Object.freeze(y?["expand-viewport"]:[]),coverage:Object.freeze({measured:t.coverage.measured,unmeasured:t.coverage.unmeasured,preparedText:t.coverage.preparedText,fallbackText:t.coverage.fallbackText,conditional:g}),checks:Object.freeze({primitives:t.primitives.length,labels:M,occlusionPairs:Math.min(C,Go),maxOcclusionPairs:Go,operations:P,maxOperations:Ps,markers:z.size}),issues:Object.freeze(r),limitations:Object.freeze(["Prepared occupied text regions bound native geometry; exact glyph ink depends on the resolved font.","Declared transparency, intentional data-mark overlap and externally modified CSS are outside this proof."])})}var Pm=class extends Error{constructor(n){super(`Final paint certification failed: ${n.issues.map(i=>`${i.id??"scene"}: ${i.message}`).join("; ")}`);this.certification=n;this.name="PaintLayoutCertificationError"}certification;code="PAINT_LAYOUT_CERTIFICATION_FAILED"};var Qe=class extends Error{constructor(n){super(`No certified layout after ${n.length} bounded attempts: ${n.map(i=>`${i.strategy}: ${i.violations.join("; ")}`).join(" | ")}`);this.attempts=n;this.name="LayoutCertificationError"}attempts;code="LAYOUT_CERTIFICATION_FAILED"};var Ri=class extends Error{constructor(n,i){super(`${n} has not loaded`);this.dependency=n;this.load=i}dependency;load};function I7(e){const t=new Set;while(e instanceof Error&&!t.has(e)){if(e instanceof Ri)return e;t.add(e);e=e.cause}return void 0}var iP={schemaVersion:2,provenance:{version:"12.2.0"},families:[{id:"flowchart",headers:[{value:"flowchart",agenticStatus:"native"},{value:"graph",agenticStatus:"native"},{value:"flowchart-elk",agenticStatus:"unsupported"}]},{id:"swimlane",headers:[{value:"swimlane-beta",agenticStatus:"unsupported"}]},{id:"sequence",headers:[{value:"sequenceDiagram",agenticStatus:"native"}]},{id:"class",headers:[{value:"classDiagram",agenticStatus:"native"},{value:"classDiagram-v2",agenticStatus:"native"}]},{id:"state",headers:[{value:"stateDiagram",agenticStatus:"native"},{value:"stateDiagram-v2",agenticStatus:"native"}]},{id:"er",headers:[{value:"erDiagram",agenticStatus:"native"}]},{id:"journey",headers:[{value:"journey",agenticStatus:"native"}]},{id:"gantt",headers:[{value:"gantt",agenticStatus:"native"}]},{id:"pie",headers:[{value:"pie",agenticStatus:"native"}]},{id:"quadrant",headers:[{value:"quadrantChart",agenticStatus:"native"}]},{id:"requirement",headers:[{value:"requirementDiagram",agenticStatus:"native"},{value:"requirement",agenticStatus:"native"}]},{id:"gitgraph",headers:[{value:"gitGraph",agenticStatus:"native"}]},{id:"c4",headers:[{value:"C4Context",agenticStatus:"native"},{value:"C4Container",agenticStatus:"native"},{value:"C4Component",agenticStatus:"native"},{value:"C4Dynamic",agenticStatus:"native"},{value:"C4Deployment",agenticStatus:"native"}]},{id:"mindmap",headers:[{value:"mindmap",agenticStatus:"native"}]},{id:"timeline",headers:[{value:"timeline",agenticStatus:"native"}]},{id:"zenuml",headers:[{value:"zenuml",agenticStatus:"native"}]},{id:"sankey",headers:[{value:"sankey",agenticStatus:"native"},{value:"sankey-beta",agenticStatus:"native"}]},{id:"xychart",headers:[{value:"xychart",agenticStatus:"native"},{value:"xychart-beta",agenticStatus:"native"}]},{id:"block",headers:[{value:"block",agenticStatus:"native"},{value:"block-beta",agenticStatus:"native"}]},{id:"packet",headers:[{value:"packet",agenticStatus:"native"},{value:"packet-beta",agenticStatus:"native"}]},{id:"kanban",headers:[{value:"kanban",agenticStatus:"native"}]},{id:"architecture",headers:[{value:"architecture",agenticStatus:"native"},{value:"architecture-beta",agenticStatus:"native"}]},{id:"radar",headers:[{value:"radar-beta",agenticStatus:"native"}]},{id:"eventmodeling",headers:[{value:"eventmodeling",agenticStatus:"native"}]},{id:"treemap",headers:[{value:"treemap",agenticStatus:"native"},{value:"treemap-beta",agenticStatus:"native"}]},{id:"venn",headers:[{value:"venn-beta",agenticStatus:"unsupported"}]},{id:"ishikawa",headers:[{value:"ishikawa",agenticStatus:"native"},{value:"ishikawa-beta",agenticStatus:"native"}]},{id:"wardley",headers:[{value:"wardley-beta",agenticStatus:"unsupported"}]},{id:"cynefin",headers:[{value:"cynefin-beta",agenticStatus:"unsupported"}]},{id:"treeview",headers:[{value:"treeView-beta",agenticStatus:"unsupported"}]},{id:"railroad",headers:[{value:"railroad-beta",agenticStatus:"unsupported"},{value:"railroad-ebnf-beta",agenticStatus:"unsupported"},{value:"railroad-abnf-beta",agenticStatus:"unsupported"},{value:"railroad-peg-beta",agenticStatus:"unsupported"}]},{id:"agentflow",headers:[{value:"agentflow-beta",agenticStatus:"unsupported"}]},{id:"usecase",headers:[{value:"usecase-beta",agenticStatus:"unsupported"}]}]};var ub=iP;function DB(e){return(e.split(";")[0]??"").trim().toLowerCase()}function OB(e,t){const n=t.trim().toLowerCase();if(e===n)return true;if(!e.startsWith(n))return false;const i=e[n.length];return i!==void 0&&/[\s:]/.test(i)}function rP(e,t=ub){const n=DB(e);const i=t.families.flatMap(r=>r.headers.map(o=>({family:r,header:o}))).sort((r,o)=>o.header.value.length-r.header.value.length||Bn(r.family.id,o.family.id));return i.find(r=>OB(n,r.header.value))??null}var Es;function re(e){return Es?.family===e}function oP(e,t,n,i){const r=Es;Es={family:e,observer:t,mutations:i?.mutations?new Set(i.mutations):void 0};try{const o=n();if(o!==null&&typeof o==="object"&&"then"in o&&typeof o.then==="function"){void Promise.resolve(o).catch(()=>{});throw new TypeError("Parser observation scopes must be synchronous")}return o}finally{Es=r}}function jc(e,t=new Map,n="$"){if(e===null||e===void 0)return null;if(typeof e==="number")return Number.isFinite(e)?e:{$number:String(e)};if(typeof e==="string"||typeof e==="boolean")return e;if(typeof e!=="object")return String(e);const i=t.get(e);if(i!==void 0)return{$ref:i};t.set(e,n);let r;if(e instanceof Date)r=e.toISOString();else if(e instanceof Map)r=[...e].map(([o,s],a)=>[jc(o,t,`${n}.${a}.0`),jc(s,t,`${n}.${a}.1`)]);else if(e instanceof Set)r=[...e].map((o,s)=>jc(o,t,`${n}.${s}`));else if(Array.isArray(e))r=e.map((o,s)=>jc(o,t,`${n}.${s}`));else{const o=Object.create(null);for(const[s,a]of Object.entries(e)){if(typeof a!=="function"&&a!==void 0)o[s]=jc(a,t,`${n}.${s}`)}r=o}t.delete(e);return r}function fb(e,t){const n=Es;if(!n||n.family!==e)return;Es=void 0;try{n.observer(t)}finally{Es=n}}function Ge(e,t,n,i){if(!re(e))return;fb(e,{family:e,unit:"statement",kind:t,text:n,...i?{source:{...i}}:{}})}function Ho(e,t,n,i){if(!re(e))return;fb(e,{family:e,unit:"token",kind:t,text:n,...i?{source:{...i}}:{}})}function he(e,t,n,i){if(!re(e))return;if(Es?.mutations&&!Es.mutations.has(t))return;fb(e,{family:e,unit:"mutation",kind:t,value:jc(n),...i?{source:{...i}}:{}})}var hb={"zenuml":["upsert_participant","remove_participant","rename_participant","insert_statement","remove_statement","set_statement","set_title","set_accessibility_title","set_accessibility_description"],"eventmodeling":["insert_frame","remove_frame","move_frame","set_frame","set_entities","set_notes","set_specifications","set_data","set_title","set_accessibility_title","set_accessibility_description"],"flowchart":["add_node","remove_node","rename_node","set_label","add_edge","remove_edge","set_shape","set_direction","add_subgraph","remove_subgraph","move_node","define_class","set_node_class","set_node_style"],"state":["add_state","remove_state","rename_state","set_state_label","add_transition","remove_transition","set_transition_label","make_composite","set_direction","move_state","dissolve_composite","add_note","remove_note","set_note_text","add_floating_note","remove_floating_note","set_floating_note_text","define_class","set_state_class","set_state_style","set_transition_style"],"sequence":["add_participant","remove_participant","add_message","remove_message","set_message_text","set_message_wrap","move_message","set_participant_label","add_fragment","remove_fragment","set_fragment_label","add_fragment_branch","set_fragment_branch_label","add_fragment_message","remove_fragment_message","set_fragment_message_text","set_fragment_message_wrap"],"timeline":["set_title","add_section","remove_section","set_section_label","add_period","remove_period","set_period_label","add_event","remove_event","set_event_text","move_period","move_event","move_section","set_accessibility_title","set_accessibility_description"],"class":["set_title","add_class","remove_class","rename_class","set_class_generic","add_member","remove_member","add_interface","add_relation","remove_relation","add_note","remove_note","set_class_namespace","define_class","set_css_class","set_class_style"],"er":["add_entity","remove_entity","rename_entity","set_entity_label","add_attribute","remove_attribute","add_relation","remove_relation","set_direction","define_class","set_entity_class","set_entity_style"],"journey":["set_title","add_section","remove_section","set_section_label","add_task","remove_task","set_task_text","set_task_score","set_task_actors","rename_actor","move_task","move_section","set_accessibility_title","set_accessibility_description"],"architecture":["set_title","set_accessibility_title","set_accessibility_description","add_service","remove_service","rename_service","set_service_label","set_service_icon","set_service_icon_text","move_service","add_junction","remove_junction","rename_junction","move_junction","add_group","set_group_label","remove_group","add_edge","update_edge","remove_edge"],"xychart":["set_title","set_x_axis","set_y_axis","add_series","remove_series","set_series_values","set_series_name","reorder_series","set_orientation","set_data_point"],"pie":["set_title","set_show_data","add_slice","remove_slice","rename_slice","set_slice_value","reorder_slice"],"quadrant":["set_title","set_axis_labels","set_quadrant_label","add_point","remove_point","move_point","rename_point"],"gantt":["set_title","add_section","rename_section","remove_section","add_task","remove_task","rename_task","set_task_status","set_task_dates","set_task_flags","set_task_id","move_task","move_section"],"mindmap":["add_node","remove_node","rename_node","set_label","move_node","set_shape","set_icon","set_node_class","set_accessibility_title","set_accessibility_description"],"gitgraph":["append_commit","create_branch","checkout_branch","merge_branch","cherry_pick","set_commit_message","set_commit_type","set_commit_tags","rename_branch","set_accessibility_title","set_accessibility_description"],"radar":["set_title","add_axis","remove_axis","rename_axis","set_axis_label","reorder_axis","add_curve","remove_curve","set_curve_values","set_curve_value","set_curve_label","rename_curve","reorder_curve","set_config"],"sankey":["add_link","remove_link","set_link_value","rename_node"],"c4":["add_element","update_element","rename_element","reparent_element","remove_element","add_boundary","update_boundary","rename_boundary","reparent_boundary","remove_boundary","add_relationship","update_relationship","remove_relationship","set_title","set_variant","add_directive","update_directive","remove_directive"],"packet":["set_title","set_accessibility_title","set_accessibility_description","add_field","remove_field","set_field_label","set_field_bits","move_field"],"kanban":["add_column","remove_column","set_column_label","move_column","add_task","remove_task","set_task_label","set_task_metadata","move_task","set_icon","set_class","set_accessibility_title","set_accessibility_description"],"requirement":["set_direction","add_requirement","update_requirement","add_element","update_element","rename_node","remove_node","add_relation","remove_relation","define_class","set_node_class","set_node_style"],"treemap":["set_title","add_node","remove_node","set_label","set_value","move_node","define_class","set_node_class","set_accessibility_title","set_accessibility_description"],"ishikawa":["set_effect","add_cause","remove_cause","set_label","move_cause","set_accessibility_title","set_accessibility_description"],"block":["set_columns","add_block","update_block","rename_block","remove_block","move_block","add_edge","remove_edge","define_class","set_node_class","set_node_style"]};function sP(e,t,n){if(Array.isArray(t)){return`Expected a single ${e} op, got an array of ${t.length}. Ops apply one at a time: call mutate() once per op, or pass the whole list to a batch entrypoint \u2014 applyOps({ source, family, ops }) to edit source, or buildMermaid(kind, ops) to author \u2014 valid ${e} ops: ${n}`}const i=t?.kind;const r=typeof i==="string"?`"${i}"`:JSON.stringify(t);return`Unknown ${e} op ${r} \u2014 valid ops: ${n}`}function BB(e){const t=hb[e];return t?t.join(", "):"(none \u2014 this family has no structured ops)"}function aP(e,t){return sP(e,t,BB(e))}function Lr(e){const t=[0];for(let n=0;n<e.length;n++){if(e.charCodeAt(n)===13){if(e.charCodeAt(n+1)===10)n++;t.push(n+1)}else if(e.charCodeAt(n)===10)t.push(n+1)}return t}function Rs(e,t){let n=0;let i=e.length;while(n<i){const o=n+Math.floor((i-n)/2);if(e[o]<=t)n=o+1;else i=o}const r=Math.max(0,n-1);return Object.freeze({offset:t,line:r+1,col:t-e[r]+1})}function vs(e,t,n){return Object.freeze({start:Rs(e,t),end:Rs(e,n)})}function Au(e){const t=/%%\{\s*(\w+)/.exec(e)?.[1];return t!==void 0&&(t.match(/(?:init\b)|(?:initialize\b)/)!==null||t.match("wrap")!==null)}import{decodeXML as xP}from"entities";function mb(e){const t=(e.split(";")[0]??"").trim().toLowerCase();return/^(?:flowchart|graph|swimlane)(?:\s|$)/.test(t)}function pb(e){const t=(e.split(";")[0]??"").trim().toLowerCase();return/^statediagram(?:-v2)?\s*$/.test(t)}function gb(e){const t=(e.split(";")[0]??"").trim().toLowerCase();return/^statediagram(?:-v2)?(?:\s|$)/.test(t)}var X7=e=>/^sequencediagram\s*$/.test(e);var U7=e=>/^sequencediagram(?:\s|$)/.test(e);var V7=e=>/^timeline(?=$|[\s;#%])/.test(e);var K7=e=>/^timeline(?=$|[\s;#%])/.test(e);var J7=e=>/^classdiagram(?:-v2)?\s*$/.test(e);var Q7=e=>/^classdiagram(?:-v2)?(?:\s|$)/.test(e);var Z7=e=>/^erdiagram(?:\s+subgraph\b.*)?\s*$/.test(e);var eJ=e=>/^erdiagram(?:\s|$)/.test(e);var tJ=e=>/^journey\s*$/.test(e);var nJ=e=>/^journey(?:\s|$)/.test(e);var iJ=e=>/^architecture(?:-beta)?\s*$/.test(e);var rJ=e=>/^architecture(?:-beta)?(?:\s|$)/.test(e);var oJ=e=>/^xychart(?:-beta)?(?:\s|$)/.test(e);var sJ=e=>/^pie(?:\s|$)/.test(e);var aJ=e=>/^quadrant(?:chart)?\s*$/.test(e);var lJ=e=>/^quadrant(?:chart)?(?:\s|$)/.test(e);var cJ=e=>/^gantt\s*$/.test(e);var dJ=e=>/^gantt(?:\s|$)/.test(e);var uJ=e=>/^mindmap\s*$/.test(e);var fJ=e=>/^mindmap(?:\s|$)/.test(e);var hJ=e=>/^gitgraph(?:\s+(?:lr|tb|bt))?\s*:?\s*$/.test(e);var mJ=e=>/^gitgraph(?:\s|:|$)/.test(e);var pJ=e=>/^radar-beta(?:\s|:|$)/.test(e);var gJ=e=>/^sankey(?:-beta)?\s*$/.test(e);var yJ=e=>/^sankey(?:-beta)?(?:\s|$)/.test(e);var xJ=e=>/^c4(?:context|container|component|dynamic|deployment)(?:\s|$)/.test(e);var bJ=e=>/^c4(?:context|container|component|dynamic|deployment)(?:\s|$)/.test(e);var SJ=e=>/^packet(?:-beta)?\s*$/.test(e);var wJ=e=>/^kanban\s*$/.test(e);var MJ=e=>/^requirement(?:diagram)?\s*$/.test(e);var kJ=e=>/^treemap(?:-beta)?\s*$/.test(e);var CJ=e=>/^ishikawa(?:-beta)?\s*$/.test(e);var PJ=e=>/^block(?:-beta)?\s*$/.test(e);var EJ=e=>/^zenuml\s*$/.test(e);var RJ=e=>/^eventmodeling\s*$/.test(e);function pr(e){const t=/^(?:[^\S\r\n]*(?:\r\n?|\n))*[^\S\r\n]*---[^\S\r\n]*(?:\r\n?|\n)/.exec(e)?.[0].length;if(!t)return void 0;let n=-1;let i="";const r=/([^\S\r\n]*)([^\r\n]*)(?:\r\n?|\n|$)/g;r.lastIndex=t;for(let o=r.exec(e);o?.[0];o=r.exec(e)){const s=o[1].length;const a=o[2].trimEnd();if(!a)continue;if(s<=n)n=-1;if(a==="---"&&n<0){return{source:e.slice(0,r.lastIndex),yaml:e.slice(t,o.index)}}if(n>=0||!i&&a[0]==="#")continue;const l=/^((?:-[ \t]+)*)(?:("(?:[^"\\]|\\.)*"|'(?:[^']|'')*'|[^"':](?:[^:]|:(?![ \t]))*):[ \t]+)?(?:[!&][^ \t]+[ \t]+)*/.exec(a);const c=i?i+a:a.slice(l[0].length);if(/^["'[{]/.test(c)){i="";let d=true,u="";for(let f=0;f<c.length;f++){const h=c[f];if(i){if(i==='"'&&h==="\\")f++;else if(h===i){if(i==="'"&&c[f+1]==="'")f++;else{i="";u=h}}}else if(h==="#"&&(f===0||/[ \t,]/.test(c[f-1])))break;else if(d&&h==="?"&&/[ \t]/.test(c[f+1]??""))continue;else if(d&&(h==="&"||h==="!")){const m=/^(?:!<[^>]*>|[!&][^ \t,[\]{}]*)/.exec(c.slice(f));f+=m[0].length-1}else if((h==='"'||h==="'")&&d){i=h;d=false}else if(!/[ \t]/.test(h)){d="[{,".includes(h)||h===":"&&(u==='"'||u==="'"||/[ \t]/.test(c[f+1]??""));u=h}}continue}if(/^[|>](?:[+-][1-9]?|[1-9][+-]?)?(?:[ \t]+#.*)?$/.test(c)){n=s+(l[2]?l[1].length:0)}}return void 0}var mr=/^[^\S\r\n]*%%\{\s*\w+\s*(?::\s*([\s\S]*?))?\}\s*%%[^\S\r\n]*(?:\r\n?|\n)?|%%\{\s*\w+\s*(?::\s*([\s\S]*?))?\}\s*%%/gm;var WB=/%%\{\s*\w+(?:(?!\}%%)[\s\S])*\}%%/g;function yb(e,t){const n=t?e.replace(mr,(i,r,o)=>{t(r??o);return""}):e.replace(mr,"");return n.replace(WB,"")}function Iu(e){return e.split(/\r\n?|\n/).map(t=>t.trim()).filter(t=>t&&!t.startsWith("%%"))}var zB=/^[^\S\r\n]*(?:sequenceDiagram|stateDiagram(?:-v2)?|mindmap|architecture(?:-beta)?|gitGraph(?:[^\S\r\n]+(?:LR|TB|BT))?(?:[^\S\r\n]*:)?|gantt(?=[^\S\r\n]+(?:(?:dateFormat|inclusiveEndDates|topAxis|axisFormat|tickInterval|includes|excludes|todayMarker|weekday|weekend|title|accTitle|accDescr|section|click)\b|[^\r\n]*:))|journey|quadrantChart|timeline(?:[^\S\r\n]+(?:LR|TD))?(?=[^\S\r\n]+(?:(?:title|section|accTitle|accDescr)\b|[^\r\n]*:))|pie(?:[^\S\r\n]+showData)?|xychart(?:-beta)?(?:[^\S\r\n]+(?:horizontal|vertical))?|radar-beta(?:[^\S\r\n]*:)?|erDiagram)/i;function El(e){const t=e.split(/\r\n?|\n/);const n=t.findIndex(l=>l.trim()!==""&&!l.trim().startsWith("%%"));const i=n<0?null:zB.exec(t[n]);const r=i?t[n].slice(i[0].length):"";if(!i||!r.trim())return e;if(/^\s*(?:erDiagram|stateDiagram)/i.test(i[0])&&/direction\s+(?:TB|BT|LR|RL)/i.test(r))return e;if(/^\s*gitGraph\s+(?:LR|TB|BT)$/i.test(i[0]))return e;const o=/^\s*stateDiagram/i.test(i[0])&&/^[^\S\r\n]*;/.test(r);const s=/^\s*quadrantChart/i.test(i[0])&&/^[^\S\r\n]*;/.test(r);const a=i[0].endsWith(":")?/^[^\S\r\n]*(?!%%)\S/:/^[^\S\r\n]+(?!%%)\S/;if(!o&&!s&&!a.test(r))return e;t.splice(n,1,i[0],/^\s*mindmap/i.test(i[0])?r.trimEnd():s?r.replace(/^[^\S\r\n]*;/,"").trim():r.trim());return t.join("\n")}function Fu(e){return e.replace(/%%.*$/,"").split(";",1)[0].trim().toLowerCase()}function Yc(e){return Iu(El(yb(e.slice(pr(e)?.source.length??0))))[0]?.toLowerCase()??""}var lP;var cP;var xb=new Map;function dP(e,t="strict"){if(mb(e))return"flowchart";if(t==="loose"?gb(e):pb(e))return"state";return null}function FJ(e){lP=e}function NJ(e){cP=e}function $J(e){xb.set(e.id,e)}function bb(e){return cP?.(e)??xb.get(e)}function qc(e,t="strict"){const n=lP?.(e,t);if(n)return n;const i=Fu(e);const r=[...xb.values()].sort((o,s)=>s.collisionPriority-o.collisionPriority||Bn(o.id,s.id));return r.find(o=>t==="loose"?(o.detectLoose??o.detect)(i):o.detect(i))??null}function Rl(e,t,n){if(!t.some(r=>/acc(?:Title|Descr)/i.test(r)))return void 0;const i=n===void 0?qc(e,"loose"):n;return i?.statementEnds?.(t)}var bo=/[\u0000-\u001f\u007f-\u009f]/;var GB=/#\w+;/g;var vl=/fl°°(\d+)¶ß|fl°(\w+)¶ß/g;var Nu=new Map([["amp","&"],["apos","'"],["gt",">"],["lt","<"],["quot",'"']]);function Un(e){return e.replace(/[^\r\n\u2028\u2029]+/g,t=>uP(uP(t,"style"),"classDef"))}function fP(e){const t=e("");if(Un(t)===t)return t;const n=e(":");if(Un(n)!==n)throw new Error("Mermaid statement cannot protect its text from the global entity prepass");return n}function uP(e,t){const n=e.lastIndexOf(";");if(n<0||!e.includes(t))return e;const i=new Uint8Array(e.length+1);let r=-1;let o=false;for(let s=e.length-1;s>=0;s--){const a=e[s];if(/\s/.test(a))r=-1;else if(a==="#")r=s;if(a===":"&&r>=0&&r<n)o=true;i[s]=o?1:0}for(let s=e.indexOf(t);s>=0;s=e.indexOf(t,s+t.length)){if(i[s+t.length]===1){return e.slice(0,n)+e.slice(n+1)}}return e}function Dn(e){return e.replace(GB,t=>{const n=t.slice(1,-1);return/^\+?\d+$/.test(n)?`\uFB02\xB0\xB0${n}\xB6\xDF`:`\uFB02\xB0${n}\xB6\xDF`})}function wb(e){return e.replace(vl,(t,n,i)=>`#${n??i};`)}var HB={'"':"quot","&":"amp","<":"lt",">":"gt"};function Sb(e){const t=HB[e];return t?`#${t};`:`#${e.codePointAt(0)};`}var jB=/\w/;function dn(e,t=""){const n=new Set(t);for(const a of n){const l=a.codePointAt(0);if(bo.test(a)||l>=55296&&l<=57343){throw new RangeError(`encodeMermaidEntities cannot reserve U+${l.toString(16).toUpperCase().padStart(4,"0")}: no entity displays it`)}}const i=[...e];const r=a=>{const l=i[a];return l!==void 0&&!n.has(l)?l:void 0};const o=a=>{let l=a+1;while(r(l)!==void 0&&jB.test(r(l)))l++;return l>a+1&&r(l)===";"};let s="";for(let a=0;a<i.length;a++){const l=i[a];if(n.has(l))s+=Sb(l);else if(l==="#"&&o(a))s+=Sb("#");else if(l==="\uFB02"&&r(a+1)==="\xB0"||l==="\xB6"&&r(a+1)==="\xDF")s+=Sb(l);else s+=l}return s}function gr(e,t=""){return e.split(/(#\w+;)/g).map((n,i)=>i%2?n:dn(n,t)).join("")}import{decodeXML as YB}from"entities";function jo(e){return YB(wb(e))}var hP=new Set([...`#&:;,%{}"'\\\``,"\uFB02","\xB6"]);var qB={amp:"&",quot:'"',apos:"'"};function So(e,t=""){const n=wb(e);return n.replace(/#(\w+);/g,(i,r,o)=>{if(o>0&&n[o-1]==="&")return i;const s=qB[r]??(/^\d+$/.test(r)&&Number(r)<=1114111?String.fromCodePoint(Number(r)):void 0);return s&&(hP.has(s)||t.includes(s)||o===0&&/^[A-Za-z]$/.test(s))?s:i})}function mP(e,t="",n,i=""){for(const o of t)if(!hP.has(o)&&!i.includes(o))throw new TypeError("Grammar text escapes must be formatting-neutral or owned by the family text reader");let r=dn(e,"#&:"+t);if(n?.test(r))r=`#${r.codePointAt(0)};${r.slice(1)}`;return r}function Mb(e){return{...e.title!==void 0?{title:So(e.title)}:{},...e.descr!==void 0?{descr:So(e.descr)}:{}}}function Yo(e){return Mb({...e.title!==void 0?{title:jo(e.title)}:{},...e.descr!==void 0?{descr:jo(e.descr)}:{}})}function GJ(e){return{...e.accessibilityTitle!==void 0?{title:e.accessibilityTitle}:{},...e.accessibilityDescription!==void 0?{descr:e.accessibilityDescription}:{}}}var XB=/^\s*accTitle(?:\s*:\s*|\s+)([^\r\n]+)$/i;var UB=/^\s*accDescr(?=\s|:|\{|$)/i;function vt(e,t){const n=e[t];if(n===void 0)return null;const i=n.match(/^\s*%% agentic-mermaid (accTitle|accDescr): ("[^\r\n]*")\s*$/);if(i){try{const s=JSON.parse(i[2]);if(typeof s==="string")return{title:i[1]==="accTitle",form:"native",value:s,endIndex:t}}catch{}}const r=n.match(UB);if(r){let s=n.slice(r[0].length).trimStart();if(s.startsWith(":"))s=s.slice(1).trimStart();if(!s.startsWith("{")){const l=s.trim();return l?{title:false,form:"inline",value:l,endIndex:t}:null}const a=[];for(let l=t;l<e.length;l++){const c=l===t?s.slice(1):e[l];const d=c.indexOf("}");if(d<0){if(c.trim())a.push(c.trim());continue}const u=c.slice(0,d).trim();if(u)a.push(u);const f=c.slice(d+1);const h=e[l].match(/^\s*/)?.[0]??"";return{title:false,form:"block",value:a.join("\n").trim(),endIndex:l,...f.trim()?{suffixLine:h+f.trimStart()}:{}}}return void 0}const o=n.match(XB);if(o)return{title:true,form:"inline",value:o[1].trim(),endIndex:t};return null}function zt(e,t,n){const i={};const r=[];const o=[];let s;for(let a=0;a<e.length;a++){const l=vt(e,a);if(l===void 0){s=a;r.push(...e.slice(a));for(let d=a;d<e.length;d++)o.push(d);break}if(l===null){const d=Xc(t,a,e.length);r.push(...e.slice(a,d+1));for(let u=a;u<=d;u++)o.push(u);a=d;continue}const c=n?n(l):l.value;if(l.title)i.title=c;else i.descr=c;if(l.suffixLine){r.push(l.suffixLine);o.push(l.endIndex)}a=l.endIndex}return{accessibility:i,familyLines:r,familyOrigins:o,...s!==void 0?{unclosedIndex:s}:{}}}function Xc(e,t,n){const i=e?.[t]??t;return i>t?Math.min(i,n-1):t}function yr(e){if(e.unclosedIndex!==void 0)throw new Error("Unclosed accDescr block")}function Ar(e){return{...e.title!==void 0?{accessibilityTitle:e.title}:{},...e.descr!==void 0?{accessibilityDescription:e.descr}:{}}}function Vr(e,t){if(t.title===void 0&&t.descr===void 0){return e}return{...e,...Ar(t)}}function Em(e,t){if(t.title===void 0&&t.descr===void 0){return e}return{...e,accessibility:{...e.accessibility,...t.title!==void 0?{title:t.title}:{},...t.descr!==void 0?{description:t.descr}:{}}}}function Tl(e,t){for(const[n,i]of[["accTitle",t.accessibilityTitle],["accDescr",t.accessibilityDescription]]){if(i===void 0)continue;const r=pP(mP(i,":;,%{}"));e.push(` %% agentic-mermaid ${n}: ${r}`)}}function pP(e){return JSON.stringify(e).replace(/[&<>#%\u2028\u2029]/g,t=>`\\u${t.charCodeAt(0).toString(16).padStart(4,"0")}`)}function gP(e,t){return kb(e,t).native.map(n=>{const i=e.slice(n.start,n.end);const r=n.start+i.indexOf('"');return{start:r,end:n.start+i.trimEnd().length,text:pP(n.directive.value)}}).filter(n=>n.text!==e.slice(n.start,n.end))}function kb(e,t){const{openers:n,closings:i}=yP(e);const r=[],o=[];const s=e.split(/\r\n?|\n/);let a=0,l=0,c=0,d=0,u=-1;const f=h=>{while(l<n.length&&n[l]<h){const m=n[l++];if(m<d)continue;while(c<i.length&&i[c].start<m)c++;if(c===i.length)continue;d=i[c].end;r.push({start:m,end:d})}};for(let h=0;h<s.length;h++){const m=s[h];f(a);if(d<=a&&h>u){const p=vt(s,h);if(p?.form==="native"){const g=a+m.length;o.push({start:a,end:g,directive:p});while(l<n.length&&n[l]<g)l++}else u=p===void 0?s.length:Math.max(Xc(t,h,s.length),p?.endIndex??h)}a+=m.length;if(e[a]==="\r")a++;if(e[a]==="\n")a++}f(Infinity);return{native:o,directives:r}}function yP(e){const t=[...e.matchAll(/%%\{\s*\w+/g)].map(i=>i.index);const n=[...e.matchAll(/\}\s*%%/g)].map(i=>({start:i.index,end:i.index+i[0].length}));return{openers:t,closings:n}}function Rm(e){const{openers:t,closings:n}=yP(e),i=e.split("");let r=0,o=0;for(const s of t){if(s<o)continue;while(r<n.length&&n[r].start<s)r++;if(r===n.length)break;o=n[r].end;for(let a=s;a<o;a++)if(i[a]!=="\r"&&i[a]!=="\n")i[a]=" "}return i.join("")}function Cb(e,t="strict"){const n=Fu(e);const i=qc(n,t);if(i)return{kind:"registered",family:i};const r=rP(n);if(r)return{kind:"upstream",match:r};return{kind:"unknown",header:e}}function VB(e,t,n=0,i=Lr(e)){const r=[];const o=new RegExp(t.source,t.flags.includes("g")?t.flags:`${t.flags}g`);let s;while((s=o.exec(e))!==null){r.push(vs(i,n+s.index,n+s.index+s[0].length));if(s[0].length===0)o.lastIndex++}return Object.freeze(r)}function SP(e,t,n=Lr(e),i=Yc(e),r){const o=[...e.slice(t).matchAll(/[^\r\n]*(?:\r\n?|\n|$)/g)];const s=o.map(p=>p[0]);const a=e.slice(t);const l=Rl(xP(i),Rm(a).split(/\r\n?|\n/),r);const c=kb(a,l);const d=a.split("");for(const p of c.directives)for(let g=p.start;g<p.end;g++)if(d[g]!=="\r"&&d[g]!=="\n")d[g]=" ";const u=d.join("").split(/\r\n?|\n/);const f=o.map(p=>t+p.index);const h=[];const m=Rl(xP(i),u,r);for(let p=0;p<u.length;p++){const g=vt(u,p);if(g===void 0)break;if(g===null){p=Xc(m,p,u.length);continue}const y=f[p];let w;if(g.form==="block"){w=f[g.endIndex]+u[g.endIndex].indexOf("}")+1}else{w=y+s[p].length}h.push(vs(n,y,w));p=g.endIndex}return Object.freeze(h)}function KB(e,t,n,i=Lr(e),r){const o=pr(e);const s=o?.source.length??0;const a=SP(e,s,i,n,r);const l=e.split("");for(const d of a)if(/^\s*%% agentic-mermaid (?:accTitle|accDescr):/.test(e.slice(d.start.offset,d.end.offset))){for(let u=d.start.offset;u<d.end.offset;u++)if(l[u]!=="\r"&&l[u]!=="\n")l[u]=" "}const c=VB(l.join("").slice(s),new RegExp(mr.source,"gm"),s,i).filter(d=>Au(e.slice(d.start.offset,d.end.offset)));return{...o?{frontmatter:vs(i,0,s)}:{},...c.length>0?{initDirectives:c}:{},...a.length>0?{accessibilityDirectives:Object.freeze(a)}:{}}}function eQ(e,t){const n=e.split("");const i=Lr(e);for(const r of SP(e,pr(e)?.source.length??0,i,void 0,t)){for(let o=r.start.offset;o<r.end.offset;o++){if(n[o]!=="\n"&&n[o]!=="\r")n[o]=" "}}return n.join("")}function bP(e,t,n,i){const r=Lr(e);let o=-1;let s=-1;let a=e.length;const l=Math.max(0,Math.min(e.length,n??0));let c=l;while(c<=e.length){const d=/\r\n?|\n/g;d.lastIndex=c;const u=d.exec(e);const f=u?.index??-1;const h=f<0?e.length:f;const m=e.slice(c,h).replace(/\r$/,"");const p=m.trim();const g=p.startsWith(t)?p.slice(t.length):"";const y=/^\s*;/.test(g);if(p===t||y||/^\s/.test(g)&&El(p)!==p){const w=m.indexOf(t);o=c+w;s=o+t.length;if(p===t){a=u?u.index+u[0].length:e.length}else{a=y?e.indexOf(";",s)+1:s;while(a<h&&/[ \t]/.test(e[a]))a++}break}if(f<0)break;c=u.index+u[0].length}if(o<0){const d=e.indexOf(t,l);o=d<0?l:d;s=Math.min(e.length,o+t.length);const u=e.indexOf("\n",s);a=u<0?e.length:u+1;c=o;while(c>0&&e.charCodeAt(c-1)!==10)c--}return Object.freeze({source:vs(r,0,e.length),...(n??c)>0?{wrapper:vs(r,0,n??c)}:{},...KB(e,a,t,r,i),header:vs(r,o,s),body:vs(r,a,e.length)})}function wP(e,t="strict"){const n=Cb(e,t);return n.kind==="registered"?{kind:"registered",familyId:n.family.id}:n}function MP(e,t,n,i,r){const o=ub.provenance.version;if(e.kind==="unknown"){return{code:"UNKNOWN_HEADER",message:`Unrecognized Mermaid header: "${e.header}"`,line:1,preservation:{version:1,classification:"unknown",source:t,header:e.header,mermaidVersion:o,spans:bP(t,i??e.header,n,r)},help:"Check for a Mermaid upgrade or register a namespaced family descriptor; the source was preserved unchanged."}}const{family:s,header:a}=e.match;const l=a.agenticStatus==="inventory-only"?"inventory-only":"unsupported";const c=a.agenticStatus==="native";return{code:c?"FAMILY_DESCRIPTOR_MISMATCH":"UNSUPPORTED_FAMILY",message:c?`Mermaid ${o} header "${a.value}" is marked native but no installed family descriptor claimed it`:`Mermaid ${o} family "${s.id}" is ${l} in Agentic Mermaid`,line:1,preservation:{version:1,classification:l,source:t,header:a.value,upstreamFamilyId:s.id,mermaidVersion:o,spans:bP(t,i??a.value,n,r)},help:c?"Report a descriptor/manifest mismatch; the source was preserved unchanged.":`Install a family descriptor for "${a.value}" or use a currently native family; the source was preserved unchanged.`}}function tQ(e){return{code:e.diagnostic.code,message:e.diagnostic.message,line:1,preservation:e.preservation,help:e.diagnostic.help}}var vm=class extends Error{name="MermaidFamilyDetectionError";code;line;preservation;help;constructor(t){super(t.message);this.code=t.code;this.line=t.line;this.preservation=t.preservation;this.help=t.help}toJSON(){return{code:this.code,message:this.message,line:this.line,preservation:this.preservation,help:this.help}}};var Uc=Object.freeze({nodes:5e3,edges:5e3,nesting:64,sourceCharacters:2e6});var Ts=class extends RangeError{code="DIAGRAM_WORK_LIMIT";resource;requested;constructor(t,n,i=false){const r=t==="sourceCharacters"?`authored plus normalized source of ${n} characters${i?", with its configuration,":""}`:`expanded graph ${t} ${n}`;super(`DIAGRAM_WORK_LIMIT: ${r} exceeds the host limit of ${Uc[t]}; split the diagram${t==="sourceCharacters"?"":` or reduce its ${t}`}`);this.name="DiagramWorkLimitError";this.resource=t;this.requested=n}};function Ve(e,t){if(t>Uc[e])throw new Ts(e,t)}function kP(e){Ve("nodes",e.requirements.length+e.elements.length);Ve("edges",e.relations.length)}function CP(e){Ve("edges",e.edges.length);Ve("nodes",e.root.children?.length??0);const t=(e.root.children??[]).map(r=>({node:r,depth:0}));const n=new Set([e.root]);let i=0;while(t.length){const{node:r,depth:o}=t.pop();if(n.has(r))throw new TypeError("Block children must form a tree without repeated objects");n.add(r);const s=o+(r.type==="composite"?1:0);Ve("nesting",s);Ve("nodes",++i+t.length+(r.children?.length??0));for(const a of r.children??[])t.push({node:a,depth:s})}}function Tm(e){Ve("nodes",e.nodes.size);Ve("edges",e.edges.length);Ve("nodes",e.nodes.size+e.subgraphs.length);const t=e.subgraphs.map(r=>({group:r,depth:1}));const n=new Set;let i=e.nodes.size;while(t.length){const{group:r,depth:o}=t.pop();if(n.has(r))throw new TypeError("Graph groups must form a tree without repeated group objects");n.add(r);Ve("nesting",o);Ve("nodes",++i);Ve("nodes",i+t.length+r.children.length);for(const s of r.children)t.push({group:s,depth:o+1})}}function PP(e){Ve("nodes",e.children?.length??0);const t=(e.children??[]).map(o=>({node:o,depth:1}));const n=new Set([e]);let i=0;let r=e.edges?.length??0;Ve("edges",r);while(t.length){const{node:o,depth:s}=t.pop();if(n.has(o))throw new TypeError("Layout graph must form a tree without repeated node objects");n.add(o);Ve("nesting",o.children===void 0?s-1:s);Ve("nodes",++i);r+=o.edges?.length??0;Ve("edges",r);Ve("nodes",i+t.length+(o.children?.length??0));for(const a of o.children??[])t.push({node:a,depth:s+1})}}function Lm(e){let t=e.classes.length+e.notes.length;Ve("nodes",t+e.namespaces.length);Ve("edges",e.relationships.length);const n=e.namespaces.map(r=>({namespace:r,depth:1}));const i=new Set;while(n.length){const{namespace:r,depth:o}=n.pop();if(i.has(r))throw new TypeError("Class namespaces must form a tree without repeated namespace objects");i.add(r);Ve("nesting",o);Ve("nodes",++t+n.length+r.children.length);for(const s of r.children)n.push({namespace:s,depth:o+1})}}function Am(e){Pb(e.entities.length,e.relationships.length,e.groups,"ER")}function Im(e){Pb(e.services.length+e.junctions.length,e.edges.length,e.groups,"Architecture")}function Fm(e){Pb(e.elements.length,e.relationships.length+e.layout.hints.length,e.boundaries,"C4");const t=new Set(e.boundaries.map(i=>i.id));const n=new Set(t);for(const i of e.elements){if(n.has(i.id))throw new TypeError(`C4 elements and boundaries must have distinct identities: ${i.id}`);n.add(i.id)}for(const i of[...e.elements,...e.boundaries]){if(i.parentId!==void 0&&!t.has(i.parentId))throw new TypeError(`C4 ${i.id} has no boundary parent ${i.parentId}`)}}function Pb(e,t,n,i){Ve("nodes",e+n.length);Ve("edges",t);const r=new Map(n.map(s=>[s.id,s]));if(r.size!==n.length)throw new TypeError(`${i} groups must have distinct identities`);const o=new Map;for(const s of n){const a=[];const l=new Set;let c=s;while(c&&!o.has(c.id)){if(l.has(c.id))throw new TypeError(`${i} groups must form an acyclic hierarchy`);l.add(c.id);a.push(c.id);Ve("nesting",a.length);c=c.parentId===void 0?void 0:r.get(c.parentId)}let d=c?o.get(c.id):0;for(const u of a.reverse()){Ve("nesting",++d);o.set(u,d)}}}var Ls=class extends Error{constructor(t){super(t);this.name="MermaidSyntaxError"}};function Je(e){const t=e.known&&e.known.length>0?` (known: ${e.known.join(", ")})`:"";return new Ls(`${e.what} \u2014 expected ${e.expectedForm}, e.g. ${e.example}${t}`)}var RP=/[\s[({,:=]/;function sQ(e){return e.replace(/^(\s*%%)\{/,"$1 {").replace(/^(\s*%%) (?=agentic-mermaid (?:accTitle|accDescr):)/,"$1 ")}function Kr(e,t){let n=null;for(let i=0;i<e.length-1;i++){const r=e[i];if(n){if(r==="\\")i++;else if(r===n)n=null;continue}if((r==='"'||r==="'")&&(i===0||RP.test(e[i-1]))){n=r;continue}if(r==="%"&&e[i+1]==="%")return i;if(t&&(t.lastIndex=i,t.test(e))){const o=e.indexOf("}",t.lastIndex);if(o<0)return-1;i=o}}return-1}function Ht(e){const t=Kr(e);return t<0?e:e.slice(0,t).trimEnd()}function EP(e,t,n,i,r,o,s){for(let a=0;a<e.length;a++){const l=e[a];if(t==="{"){if(l==="}")t=null}else if(t){if(l==="\\"&&n)a++;else if(l===t)t=null}else if(l==="%"&&e[a+1]==="%"){break}else if(r&&(r.lastIndex=a,r.test(e))){break}else if(o&&(o.lastIndex=a,o.test(e))){t="{";a=o.lastIndex-1}else if((l==='"'||l==="'")&&(s?s(e,a):i.test(a===0?"\n":e[a-1]))){t=l}}return t}function Ir(e,t={}){const n=[...t.spanning??'"',...t.block?"{":""];const i=t.escapes??true;const r=t.opensAfter??RP;const o=new Array(e.length);let s=new Map(n.map(a=>[a,-1]));for(let a=e.length-1;a>=0;a--){const l=e[a];const c=t.wholeLine?.(l.trim())?null:EP(l,null,i,r,t.restOfLine,t.block,t.opensAt);const d=c?s.get(c)??-1:-1;o[a]=d<0?a:d;s=new Map(n.map(u=>{const f=EP(l,u,i,r,t.restOfLine,t.block,t.opensAt);return[u,f&&s.has(f)?s.get(f):a]}))}return o}function Ll(e,t,n){if(n===t)return e[t];return[e[t].trimEnd(),...e.slice(t+1,n+1).map(i=>i.trim())].join("\n")}function Eb(e,t){const n=[...e];for(let i=0;i<e.length;i++){const r=t[i];if(r===i)continue;n[i]=Ll(e,i,r);n.fill("",i+1,r+1);i=r}return n}function fa(e,t={}){return Eb(e,Ir(e,t))}var vP=/^align(?:\s|$)/;var JB=/^[\w-]+$/;function TP(e){const t=e.trim().split(/\s+/);const n=t[1];if(n!=="row"&&n!=="column"){return{ok:false,reason:`expected "align row" or "align column", got "${n??""}"`}}const i=t.slice(2);if(i.length<2){return{ok:false,reason:"an align directive needs at least two members"}}const r=new Set;for(const o of i){if(!JB.test(o)){return{ok:false,reason:`align member "${o}" must match [A-Za-z0-9_-]+`}}if(r.has(o)){return{ok:false,reason:`align member "${o}" is listed twice`}}r.add(o)}return{ok:true,alignment:{axis:n,members:i}}}function lQ(e){return`align ${e.axis} ${e.members.join(" ")}`}var QB="'JetBrains Mono'";var gQ=`${QB}, 'SF Mono', 'Fira Code', ui-monospace, monospace`;var nr={nodeLabel:13,edgeLabel:11,groupHeader:12};var Fr={nodeLabel:500,edgeLabel:400,groupHeader:600};var Nm={horizontal:20,vertical:10,diamondExtra:24};var et={outerBox:1,innerBox:.75,connector:1};var bn={width:8,height:5,strokeWidth:.75};var Vc={dash:4,gap:4};var zi={nodeLabelFontSize:nr.nodeLabel,edgeLabelFontSize:nr.edgeLabel,groupHeaderFontSize:nr.groupHeader,nodeLabelFontWeight:Fr.nodeLabel,edgeLabelFontWeight:Fr.edgeLabel,groupHeaderFontWeight:Fr.groupHeader,nodePaddingX:Nm.horizontal,nodePaddingY:Nm.vertical,diamondExtraPadding:Nm.diamondExtra,edgeLineWidth:et.connector,groupCornerRadius:0,groupPaddingX:16,groupPaddingY:16,groupLabelPaddingX:12,groupLineWidth:et.outerBox};function ma(e){return typeof e==="number"&&Number.isFinite(e)?e:void 0}function As(e,...t){for(const n of t){const i=ma(n);if(i!=null&&i>0)return i}return e}function ha(e,...t){for(const n of t){const i=ma(n);if(i!=null&&i>=0)return i}return e}function wo(...e){for(const t of e){if(typeof t==="string"&&t.trim().length>0)return t}return void 0}function Rb(...e){for(const t of e){const n=wo(t)?.toLowerCase();if(n==="uppercase"||n==="lowercase"||n==="capitalize"){return n}}return void 0}function gi(e,t){if(typeof e!=="string")return Rt(e,e.display,t);if(!t)return e;const n=Rt(e,"formatted",t);let i=0,r="";for(const o of n.lines)for(const s of o){r+=e.slice(i,s.sourceStart)+s.text;i=s.sourceEnd}return r+e.slice(i)}function Ue(e={},t=zi,n){const i=n??e.styleFace;const r=i?.text;const o=i?.node;const s=i?.edge;const a=i?.group;const l=ha(void 0,a?.paddingX);const c=t.nodeCornerRadius==null?ha(void 0,o?.cornerRadius):ha(t.nodeCornerRadius,o?.cornerRadius);return{nodeLabelFontSize:As(t.nodeLabelFontSize,o?.fontSize,r?.fontSize),edgeLabelFontSize:As(t.edgeLabelFontSize,s?.fontSize,r?.fontSize),groupHeaderFontSize:As(t.groupHeaderFontSize,a?.fontSize,r?.fontSize),nodeLabelFontWeight:As(t.nodeLabelFontWeight,o?.fontWeight,r?.fontWeight),edgeLabelFontWeight:As(t.edgeLabelFontWeight,s?.fontWeight,r?.fontWeight),groupHeaderFontWeight:As(t.groupHeaderFontWeight,a?.fontWeight,r?.fontWeight),nodeTextTransform:Rb(o?.textTransform,r?.textTransform,t.nodeTextTransform),edgeTextTransform:Rb(s?.textTransform,r?.textTransform,t.edgeTextTransform),nodeLetterSpacing:ma(o?.letterSpacing)??ma(r?.letterSpacing)??t.nodeLetterSpacing??0,edgeLetterSpacing:ma(s?.letterSpacing)??ma(r?.letterSpacing)??t.edgeLetterSpacing??0,groupLetterSpacing:ma(a?.letterSpacing)??ma(r?.letterSpacing)??t.groupLetterSpacing??0,nodePaddingX:ha(t.nodePaddingX,o?.paddingX),nodePaddingY:ha(t.nodePaddingY,o?.paddingY),diamondExtraPadding:t.diamondExtraPadding??Nm.diamondExtra,cornerRadius:c,nodeLineWidth:As(t.nodeLineWidth??et.innerBox,o?.lineWidth),nodeFillColor:wo(o?.fillColor,t.nodeFillColor),nodeBorderColor:wo(o?.borderColor,t.nodeBorderColor),nodeTextColor:wo(o?.textColor,r?.textColor,t.nodeTextColor),lineWidth:As(t.edgeLineWidth,s?.lineWidth),edgeBendRadius:ha(t.edgeBendRadius??0,s?.bendRadius),edgeStrokeColor:wo(s?.strokeColor,t.edgeStrokeColor),edgeTextColor:wo(s?.textColor,r?.textColor,t.edgeTextColor),groupFont:wo(a?.fontFamily,t.groupFont),groupTextTransform:Rb(a?.textTransform,r?.textTransform,t.groupTextTransform),groupCornerRadius:ha(t.groupCornerRadius,a?.cornerRadius),groupBorderColor:wo(a?.borderColor,t.groupBorderColor),groupFillColor:wo(a?.fillColor,t.groupFillColor),groupHeaderFillColor:wo(a?.headerFillColor,t.groupHeaderFillColor),groupTextColor:wo(a?.textColor,r?.textColor,t.groupTextColor),groupPaddingX:l??t.groupPaddingX,groupPaddingY:ha(t.groupPaddingY,a?.paddingY),groupLabelPaddingX:l??t.groupLabelPaddingX??t.groupPaddingX,groupLineWidth:As(t.groupLineWidth??et.outerBox,a?.lineWidth)}}var $m=18;var _m=600;var Al=12;function tn(e,t){if(e===void 0)return void 0;const n=Be(e,{display:"formatted",transform:t.groupTextTransform,fontSize:$m,fontWeight:_m,letterSpacing:t.groupLetterSpacing,fontFamily:t.groupFont});return{text:n.text,width:n.width,height:n.height+Al,block:n}}function pa(e,t,n=t){const i=e.width+2*t;return{width:i,height:e.height-Al+2*n,title:on(e,i,n)}}function on(e,t,n){return{text:e.text,x:t/2,y:n+(e.height-Al)/2,...e.block?{block:e.block}:{}}}function En(e,t){const n=t.groupTextColor??"var(--_text)";return{id:"diagram-title",role:"title",text:e.text,block:e.block,x:e.x,y:e.y,fontSize:$m,fontWeight:_m,letterSpacing:t.groupLetterSpacing,anchor:"middle",paint:{fill:n},attributes:{className:"diagram-title"}}}var Bm=36;var vb=56;var ZB=1.5;var Wm=36;var un={groupHeaderHeight:28,groupFontSize:12,groupFontWeight:600,groupLetterSpacing:0,groupPaddingX:16,groupPaddingY:16,groupLabelPaddingX:12,groupCornerRadius:0,groupLineWidth:1,serviceFontSize:13,serviceFontWeight:500,serviceLetterSpacing:0,servicePaddingX:20,servicePaddingY:10,serviceCornerRadius:0,serviceLineWidth:1,edgeFontSize:11,edgeFontWeight:400,edgeLetterSpacing:0,edgeLineWidth:1,edgeBendRadius:0,iconSize:16,serviceIconSize:18,junctionOuterRadius:8,junctionInnerRadius:4.5};function AP(e,t,n={},i){const r=LP(e,"themeVariables");const o=LP(e,"architecture");const s=ga(Om(o,"fontSize")??Om(e,"fontSize")??Om(r,"fontSize")??un.serviceFontSize,10,24);const a=ga(Om(o,"iconSize")??un.serviceIconSize,12,40);const l=ga(Math.round(a*(un.iconSize/un.serviceIconSize)),10,36);const c=ga(Math.round(s*.92),10,22);const d=ga(Math.round(s*.85),10,20);const u=Math.max(un.groupHeaderHeight,Math.round(Math.max(c,l)+12));const f=ga(Math.round(a*.44),8,18);const h=Number((f*.56).toFixed(1));const m={nodeLabelFontSize:s,edgeLabelFontSize:d,groupHeaderFontSize:c,nodeLabelFontWeight:un.serviceFontWeight,edgeLabelFontWeight:un.edgeFontWeight,groupHeaderFontWeight:un.groupFontWeight,nodePaddingX:un.servicePaddingX,nodePaddingY:un.servicePaddingY,nodeCornerRadius:un.serviceCornerRadius,nodeLineWidth:un.serviceLineWidth,edgeLineWidth:un.edgeLineWidth,edgeBendRadius:un.edgeBendRadius,groupCornerRadius:un.groupCornerRadius,groupPaddingX:un.groupPaddingX,groupPaddingY:un.groupPaddingY,groupLabelPaddingX:un.groupLabelPaddingX,groupLineWidth:un.groupLineWidth};const p=Ue(n,m,i);const g={groupHeaderHeight:Math.max(u,p.groupHeaderFontSize+12),groupFontSize:p.groupHeaderFontSize,groupFontWeight:p.groupHeaderFontWeight,groupLetterSpacing:p.groupLetterSpacing,groupFont:p.groupFont,groupTextTransform:p.groupTextTransform,groupPaddingX:p.groupPaddingX,groupPaddingY:p.groupPaddingY,groupLabelPaddingX:p.groupLabelPaddingX,groupCornerRadius:p.groupCornerRadius,groupLineWidth:p.groupLineWidth,serviceFontSize:p.nodeLabelFontSize,serviceFontWeight:p.nodeLabelFontWeight,serviceLetterSpacing:p.nodeLetterSpacing,serviceTextTransform:p.nodeTextTransform,servicePaddingX:p.nodePaddingX,servicePaddingY:p.nodePaddingY,serviceCornerRadius:p.cornerRadius??0,serviceLineWidth:p.nodeLineWidth,edgeFontSize:p.edgeLabelFontSize,edgeFontWeight:p.edgeLabelFontWeight,edgeLetterSpacing:p.edgeLetterSpacing,edgeTextTransform:p.edgeTextTransform,edgeLineWidth:p.lineWidth,edgeBendRadius:p.edgeBendRadius,iconSize:l,serviceIconSize:a,junctionOuterRadius:f,junctionInnerRadius:h,groupSurface:p.groupFillColor??Dm(r,"clusterBkg")??t.surface,groupHeaderSurface:p.groupHeaderFillColor,groupBorder:p.groupBorderColor??Dm(r,"clusterBorder"),groupText:p.groupTextColor,serviceSurface:p.nodeFillColor??Dm(r,"mainBkg","secondaryColor")??t.surface,serviceBorder:p.nodeBorderColor??Dm(r,"primaryBorderColor"),serviceText:p.nodeTextColor,edgeStroke:p.edgeStrokeColor,edgeText:p.edgeTextColor};const y={...g,...n.architecture?.visual};if(y.junctionInnerRadius>y.junctionOuterRadius){throw new RangeError("architecture.visual.junctionInnerRadius must not exceed junctionOuterRadius")}return{visual:y,layout:Tb(y),padding:iW(o,"padding"),nodeSpacing:eW(o),layerSpacing:tW(o)}}function eW(e){const t=zm(e,"nodeSeparation");if(t===void 0||!Number.isFinite(t)||t<0)return void 0;return ga(Math.round(t),0,512)}function tW(e){const t=zm(e,"idealEdgeLengthMultiplier");if(t===void 0||!Number.isFinite(t)||t<=0)return void 0;return ga(Math.round(vb*t/ZB),8,512)}function Tb(e){return{iconSize:e.iconSize,serviceIconSize:e.serviceIconSize,junctionOuterRadius:e.junctionOuterRadius,groupFontSize:e.groupFontSize,groupFontWeight:e.groupFontWeight,groupLetterSpacing:e.groupLetterSpacing,groupFont:e.groupFont,groupTextTransform:e.groupTextTransform,groupPaddingX:e.groupPaddingX,groupPaddingY:e.groupPaddingY,groupCornerRadius:e.groupCornerRadius,groupLineWidth:e.groupLineWidth,serviceFontSize:e.serviceFontSize,serviceFontWeight:e.serviceFontWeight,serviceLetterSpacing:e.serviceLetterSpacing,serviceTextTransform:e.serviceTextTransform,servicePaddingX:e.servicePaddingX,servicePaddingY:e.servicePaddingY,serviceCornerRadius:e.serviceCornerRadius,serviceLineWidth:e.serviceLineWidth,edgeFontSize:e.edgeFontSize,edgeFontWeight:e.edgeFontWeight,edgeLetterSpacing:e.edgeLetterSpacing,edgeTextTransform:e.edgeTextTransform,edgeLineWidth:e.edgeLineWidth,edgeBendRadius:e.edgeBendRadius}}function Dm(e,...t){for(const n of t){const i=nW(e,n);if(i)return i}return void 0}function nW(e,t){const n=e?.[t];return typeof n==="string"?n:void 0}function zm(e,t){return rW(e?.[t])}function Om(e,t){const n=zm(e,t);return n!==void 0&&n>0?n:void 0}function iW(e,t){const n=zm(e,t);return n!==void 0&&n>=0?n:void 0}function LP(e,t){const n=e?.[t];return oW(n)?n:void 0}function rW(e){if(typeof e==="number")return e;if(typeof e!=="string")return void 0;const t=e.trim();const n=t.match(/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:px)?$/i);return n?Number.parseFloat(t):void 0}function ga(e,t,n){return Math.min(n,Math.max(t,e))}function oW(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}var qo="[\\w-]+";var NP="\\((?<icon>[^)]+)\\)";var $P="\\[(?<content>.+)\\]";var sW=String.raw`(?<iconText>"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')`;var _P=new RegExp(`^group\\s+(?<id>${qo})(?:${NP})?(?:${$P})?(?:\\s+in\\s+(?<parentId>${qo}))?\\s*$`,"s");var DP=new RegExp(`^service\\s+(?<id>${qo})(?:\\s*(?:${NP}|${sW}))?\\s*(?:${$P})?(?:\\s+in\\s+(?<parentId>${qo}))?\\s*$`,"s");var OP=new RegExp(`^junction\\s+(${qo})(?:\\s+in\\s+(${qo}))?\\s*$`);var aW=new RegExp(`^(${qo})(\\{group\\})?:(L|R|T|B)$`);var lW=new RegExp(`^(L|R|T|B):(${qo})(\\{group\\})?$`);var BP=/^(<)?-\[(.*)\]-(>)?$/s;var WP=new RegExp(`^(${qo}(?:\\{group\\})?:[LRTB])\\s*(.+?)\\s*([LRTB]:${qo}(?:\\{group\\})?)$`,"s");var cW={spanning:`"'`,opensAt:(e,t)=>e[t-1]==="["||/^service\s+[\w-]+\s*$/.test(e.slice(0,t)),wholeLine:e=>/^title\s/i.test(e)};function Fb(e){return Ir(e,cW)}function zP(e){const t=e.familyBody.split(/\r?\n/);const n=t.findIndex(i=>i.trim()===e.familyLines[0]);return[t[n]?.trim()??e.familyLines[0]??"",...t.slice(n+1)]}var dW=/^\w(?:[\w-]*\w)?$/;var uW=new Set(["architecture-beta","group","service","junction","in","align","row","column"]);var fW=/^(?:[LRTB]|title)/;var hW=/^[\w:-]+$/;var mW=/^[\w ]+$/;var pW=/^[^[\]\r\n]+$/;var GP=/^(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')$/;function gW(e){if(!dW.test(e))return Je({what:`Architecture id "${e}" must start and end with a letter, digit or _`,expectedForm:"letters, digits and _, with - only between them",example:e.replace(/^-+|-+$/g,"")||"api"});return uW.has(e)||fW.test(e)?Je({what:`Architecture id "${e}" is read as a reserved token by Mermaid`,expectedForm:"an id other than an architecture keyword, not starting with L, R, T, B or title",example:`node_${e}`}):void 0}function yW(e){return hW.test(e)?void 0:Je({what:`Architecture icon (${e}) has a character an icon name cannot hold`,expectedForm:"letters, digits, _, - and : only",example:"(logos:aws-lambda)"})}function HP(e){if(GP.test(e))return e.slice(1,-1).replace(/\\"/g,'"').replace(/\\'/g,"'").trim();return e.trim()}function vQ(e){return mW.test(e)?e:`"${e.replace(/"/g,'\\"')}"`}function IP(e){const{id:t,icon:n,iconText:i,content:r,parentId:o}=e.groups;const s=n?.trim()||void 0;const a=r===void 0?t:HP(r);return{id:t,...s!==void 0?{icon:s}:{},...i!==void 0?{iconText:xW(i)}:{},title:a,...o!==void 0?{parentId:o}:{}}}function xW(e){const t={b:"\b",f:"\f",n:"\n",r:"\r",t:" ",v:"\v",0:"\0"};return e.slice(1,-1).replace(/\\(.)/gs,(n,i)=>t[i]??i)}function TQ(e){const t={"\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r"," ":"\\t","\v":"\\v","\0":"\\0","\\":"\\\\",'"':'\\"'};return`"${e.replace(/[\b\f\n\r\t\v\0\\"]/g,n=>t[n])}"`}function LQ(e){const t=Ht(e.trim());const n=[];const i=l=>{if(l!==void 0&&gW(l))n.push({terminal:"id",what:`Architecture id "${l}" is not a portable Mermaid id and is read as written`})};const r=l=>{if(l!==void 0&&!pW.test(l)&&!GP.test(l)){n.push({terminal:"title",what:`Architecture title [${l}] has unquoted brackets or a line break, and is read as written`})}};const o=t.match(_P)??t.match(DP);if(o){const{id:l,icon:c,content:d,parentId:u}=o.groups;i(l);const f=c?.trim();if(f&&yW(f))n.push({terminal:"icon",what:`Architecture icon (${f}) has a character an icon name cannot hold, and is read as written`});r(d);i(u);return n}const s=t.match(OP);if(s){i(s[1]);i(s[2]);return n}const a=t.match(WP);if(a)r(a[2].trim().match(BP)?.[2]);return n}function jP(e){const t=[];const n=Fb(e);for(let i=0;i<e.length;i++){const r=i;const o=e[i];const s=(u,f=e.slice(r,i+1))=>{t.push({...u,raw:f,startLine:r+1,endLine:i+1})};const a=o.trim();if(!a||a.startsWith("%%")){s({kind:a?"comment":"blank"});continue}const l=vt(e,i);if(l===void 0){const u=e.slice(i);i=e.length-1;s({kind:"invalid",error:new Error("Unclosed accDescr block")},u);break}if(l!==null){i=l.endIndex;const u=e.slice(r,i+1);if(l.suffixLine)u[u.length-1]=u.at(-1).slice(0,u.at(-1).indexOf("}")+1);s({kind:"accessibility",directive:l},u);if(l.suffixLine){const f=e[i];const h=f.slice(f.indexOf("}")+1);t.push(...jP([h]).map(m=>({...m,startLine:i+1,endLine:i+1})))}continue}i=n[i];const c=/^service\s+[\w-]+\s*["']/.test(a);const d=Ht((c?e.slice(r,i+1).join("\n"):Ll(e,r,i)).trim());try{const u=d.match(/^title\s+(.+)$/i);const f=d.match(_P);const h=d.match(DP);const m=d.match(OP);if(u)s({kind:"title",value:u[1].trim()});else if(f)s({kind:"group",declaration:IP(f)});else if(h)s({kind:"service",declaration:IP(h)});else if(m)s({kind:"junction",id:m[1],parentId:m[2]});else if(vP.test(d)){const p=TP(d);if(!p.ok)throw Je({what:`Invalid architecture align directive "${d}" \u2014 ${p.reason}`,expectedForm:"align row|column memberA memberB ..., listing at least two distinct services or junctions",example:"align row db1 db2 db3"});s({kind:"align",alignment:p.alignment})}else{const p=d.match(WP);if(!p)throw Je({what:`Invalid architecture edge: "${d}"`,expectedForm:"source:SIDE <op> SIDE:target, where SIDE is L, R, T, or B",example:"api:R --> L:db"});s({kind:"edge",edge:{source:SW(p[1]),target:wW(p[3]),...MW(p[2])}})}}catch(u){s({kind:"invalid",error:u instanceof Error?u:new Error(String(u))})}}return t}function YP(e){if(e.length===0){throw new Error("Empty mermaid diagram")}if(!/^architecture(?:-beta)?\s*$/i.test(Ht(e[0]))){throw new Error(`Invalid mermaid header: "${e[0]}". Expected "architecture" or "architecture-beta".`)}if(re("architecture"))Ge("architecture","header",e[0],{line:1,unit:"normalized"});const t=new Map;const n=new Map;const i=new Map;const r=[];const o=[];const s=[];let a;let l;let c;for(const d of jP(e.slice(1))){const u=Ht(d.raw.join("\n").trim());if(re("architecture"))Ge("architecture",d.kind,d.raw.join("\n"),{line:d.startLine+1,unit:"normalized"});if(d.kind==="invalid")throw d.error;if(d.kind==="blank"||d.kind==="comment")continue;if(d.kind==="accessibility"){if(d.directive.title)l=yt(d.directive.value);else c=yt(d.directive.value);if(re("architecture"))he("architecture",d.directive.title?"setAccessibilityTitle":"setAccessibilityDescription",d.directive.title?l:c,{line:d.startLine+1,unit:"normalized"});continue}if(d.kind==="title"){a=yt(d.value);if(re("architecture"))he("architecture","setTitle",a,{line:d.startLine+1,unit:"normalized"});continue}if(d.kind==="group"){const f=d.declaration;const{id:h,icon:m,parentId:p}=f;const g=yt(f.title);Lb(h,t,n,i);const y={id:h,label:g,icon:m,parentId:p,children:[]};Ab(p,t,u);t.set(h,y);if(re("architecture"))he("architecture","addGroup",y,{line:d.startLine+1,unit:"normalized"});Ib({kind:"group",id:h},p,t,r);if(re("architecture"))he("architecture","attachChild",{kind:"group",id:h,parentId:p},{line:d.startLine+1,unit:"normalized"});continue}if(d.kind==="service"){const f=d.declaration;const{id:h,icon:m,iconText:p,parentId:g}=f;const y=yt(f.title);Lb(h,t,n,i);const w={id:h,label:y,icon:m,...p!==void 0?{iconText:p}:{},parentId:g};Ab(g,t,u);n.set(h,w);if(re("architecture"))he("architecture","addService",w,{line:d.startLine+1,unit:"normalized"});Ib({kind:"service",id:h},g,t,r);if(re("architecture"))he("architecture","attachChild",{kind:"service",id:h,parentId:g},{line:d.startLine+1,unit:"normalized"});continue}if(d.kind==="junction"){const{id:f,parentId:h}=d;Lb(f,t,n,i);const m={id:f,parentId:h};Ab(h,t,u);i.set(f,m);if(re("architecture"))he("architecture","addJunction",m,{line:d.startLine+1,unit:"normalized"});Ib({kind:"junction",id:f},h,t,r);if(re("architecture"))he("architecture","attachChild",{kind:"junction",id:f,parentId:h},{line:d.startLine+1,unit:"normalized"});continue}if(d.kind==="align"){s.push(bW(d.alignment,u,t,n,i));if(re("architecture"))he("architecture","addAlignment",s.at(-1),{line:d.startLine+1,unit:"normalized"});continue}if(d.kind==="edge"){FP(d.edge.source,n,i,u);FP(d.edge.target,n,i,u);o.push({...d.edge,label:d.edge.label===void 0?void 0:yt(d.edge.label)});if(re("architecture"))he("architecture","addEdge",o.at(-1),{line:d.startLine+1,unit:"normalized"})}}return{title:a,groups:[...t.values()],services:[...n.values()],junctions:[...i.values()],edges:o,alignments:s,rootChildren:r,accessibilityTitle:l,accessibilityDescription:c}}function bW(e,t,n,i,r){for(const o of e.members){if(i.has(o)||r.has(o))continue;if(n.has(o)){throw new Error(`Architecture align members must be services or junctions; "${o}" is a group in line "${t}"`)}throw Je({what:`Unknown architecture align member "${o}" in line "${t}"`,expectedForm:"a service or junction declared earlier",example:`service ${o}(server)[${o}]`,known:[...i.keys(),...r.keys()]})}return e}function Lb(e,t,n,i){if(t.has(e)||n.has(e)||i.has(e)){throw Je({what:`Duplicate architecture identifier "${e}"`,expectedForm:"a unique id for each service, group, and junction",example:`${e}2`,known:[...t.keys(),...n.keys(),...i.keys()]})}}function Ab(e,t,n){if(e&&!t.has(e)){throw Je({what:`Unknown architecture group "${e}" in line "${n}"`,expectedForm:"a group declared earlier with group id(icon)[Label]",example:`group ${e}(cloud)[${e}]`,known:[...t.keys()]})}}function Ib(e,t,n,i){if(t){n.get(t).children.push(e)}else{i.push(e)}}function SW(e){const t=e.trim().match(aW);if(!t){throw new Error(`Invalid architecture edge source "${e}" \u2014 expected id then side, e.g. "api:R" in "api:R -- L:db"`)}return{id:t[1],boundary:t[2]?"group":"item",side:t[3]}}function wW(e){const t=e.trim().match(lW);if(!t){throw new Error(`Invalid architecture edge target "${e}" \u2014 expected side then id, e.g. "L:db" in "api:R -- L:db"`)}return{id:t[2],boundary:t[3]?"group":"item",side:t[1]}}function MW(e){const t=e.trim();if(t==="<-->")return{hasArrowStart:true,hasArrowEnd:true};if(t==="-->")return{hasArrowStart:false,hasArrowEnd:true};if(t==="<--")return{hasArrowStart:true,hasArrowEnd:false};if(t==="--")return{hasArrowStart:false,hasArrowEnd:false};const n=t.match(BP);if(!n){throw Je({what:`Invalid architecture edge operator "${e}"`,expectedForm:"one of --, -->, <--, <-->, or -[label]-",example:"api:R --> L:db"})}const i=HP(n[2]).trim()||void 0;return{label:i,hasArrowStart:Boolean(n[1]),hasArrowEnd:Boolean(n[3])}}function FP(e,t,n,i){const r=t.get(e.id);const o=n.get(e.id);if(!r&&!o){throw Je({what:`Unknown architecture item "${e.id}" in line "${i}"`,expectedForm:"a service or junction declared earlier",example:`service ${e.id}(server)[${e.id}]`,known:[...t.keys(),...n.keys()]})}if(e.boundary==="group"){if(!r){throw new Error(`Architecture group boundary modifier only applies to services: "${i}"`)}if(!r.parentId){throw new Error(`Service "${r.id}" is not inside a group, so "{group}" is invalid in line "${i}"`)}}}function qP(e){Im(e);const t=new Map;for(const i of e.services){t.set(i.id,{id:i.id,label:i.label,shape:i.icon?"service":"rectangle"})}for(const i of e.junctions){t.set(i.id,{id:i.id,label:"",shape:"state-start"})}const n=CW(e.edges);return{direction:n,nodes:t,edges:e.edges.map(i=>({source:i.source.id,target:i.target.id,label:i.label,style:"solid",hasArrowStart:i.hasArrowStart,hasArrowEnd:i.hasArrowEnd})),subgraphs:kW(e.groups),classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map}}function kW(e){const t=new Map(e.map(r=>[r.id,r]));const n=new Set;function i(r,o){if(n.has(r))throw new TypeError("Architecture groups must form a tree without repeated groups");n.add(r);Ve("nesting",o);const s=[];const a=[];for(const l of r.children){if(l.kind==="group"){const c=t.get(l.id);if(c)a.push(i(c,o+1))}else{s.push(l.id)}}return{id:r.id,label:r.label,nodeIds:s,children:a,...r.icon?{titleOffset:Wm}:{}}}return e.filter(r=>!r.parentId).map(r=>i(r,1))}function CW(e){let t=0;let n=0;for(const i of e){if(i.source.side==="L"||i.source.side==="R")t++;else n++;if(i.target.side==="L"||i.target.side==="R")t++;else n++}return t>=n?"LR":"TD"}var Gm=Object.freeze({maxIcons:32,maxNameBytes:128,maxPathBytes:4096});var Hm=Object.freeze({account:"M12 4a4 4 0 0 1 4 4a4 4 0 0 1-4 4a4 4 0 0 1-4-4a4 4 0 0 1 4-4m0 10c4.42 0 8 1.79 8 4v2H4v-2c0-2.21 3.58-4 8-4",api:"M7 7H5a2 2 0 0 0-2 2v8h2v-4h2v4h2V9a2 2 0 0 0-2-2m0 4H5V9h2m7-2h-4v10h2v-4h2a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2m0 4h-2V9h2m6 0v6h1v2h-4v-2h1V9h-1V7h4v2Z","application-brackets":"M21 2H3a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h18a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2M11 17.5L9.5 19L5 14.5L9.5 10l1.5 1.5l-3 3zm3.5 1.5L13 17.5l3-3l-3-3l1.5-1.5l4.5 4.5zM21 7H3V4h18z",archive:"M3 3h18v4H3zm1 5h16v13H4zm5.5 3a.5.5 0 0 0-.5.5V13h6v-1.5a.5.5 0 0 0-.5-.5z",cellphone:"M17 19H7V5h10m0-4H7c-1.11 0-2 .89-2 2v18a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2",cloud:"M6.5 20q-2.28 0-3.89-1.57Q1 16.85 1 14.58q0-1.95 1.17-3.48q1.18-1.53 3.08-1.95q.63-2.3 2.5-3.72Q9.63 4 12 4q2.93 0 4.96 2.04Q19 8.07 19 11q1.73.2 2.86 1.5q1.14 1.28 1.14 3q0 1.88-1.31 3.19T18.5 20Z",cog:"M12 15.5A3.5 3.5 0 0 1 8.5 12A3.5 3.5 0 0 1 12 8.5a3.5 3.5 0 0 1 3.5 3.5a3.5 3.5 0 0 1-3.5 3.5m7.43-2.53c.04-.32.07-.64.07-.97s-.03-.66-.07-1l2.11-1.63c.19-.15.24-.42.12-.64l-2-3.46c-.12-.22-.39-.31-.61-.22l-2.49 1c-.52-.39-1.06-.73-1.69-.98l-.37-2.65A.506.506 0 0 0 14 2h-4c-.25 0-.46.18-.5.42l-.37 2.65c-.63.25-1.17.59-1.69.98l-2.49-1c-.22-.09-.49 0-.61.22l-2 3.46c-.13.22-.07.49.12.64L4.57 11c-.04.34-.07.67-.07 1s.03.65.07.97l-2.11 1.66c-.19.15-.25.42-.12.64l2 3.46c.12.22.39.3.61.22l2.49-1.01c.52.4 1.06.74 1.69.99l.37 2.65c.04.24.25.42.5.42h4c.25 0 .46-.18.5-.42l.37-2.65c.63-.26 1.17-.59 1.69-.99l2.49 1.01c.22.08.49 0 .61-.22l2-3.46c.12-.22.07-.49-.12-.64z",database:"M12 3C7.58 3 4 4.79 4 7s3.58 4 8 4s8-1.79 8-4s-3.58-4-8-4M4 9v3c0 2.21 3.58 4 8 4s8-1.79 8-4V9c0 2.21-3.58 4-8 4s-8-1.79-8-4m0 5v3c0 2.21 3.58 4 8 4s8-1.79 8-4v-3c0 2.21-3.58 4-8 4s-8-1.79-8-4",dns:"M7 9a2 2 0 0 1-2-2a2 2 0 0 1 2-2a2 2 0 0 1 2 2a2 2 0 0 1-2 2m13-6H4a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h16a1 1 0 0 0 1-1V4a1 1 0 0 0-1-1M7 19a2 2 0 0 1-2-2a2 2 0 0 1 2-2a2 2 0 0 1 2 2a2 2 0 0 1-2 2m13-6H4a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h16a1 1 0 0 0 1-1v-6a1 1 0 0 0-1-1",email:"m20 8l-8 5l-8-5V6l8 5l8-5m0-2H4c-1.11 0-2 .89-2 2v12a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2","folder-network":"M3 15V5a2 2 0 0 1 2-2h6l2 2h6a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-6v2h1a1 1 0 0 1 1 1h7v2h-7a1 1 0 0 1-1 1h-4a1 1 0 0 1-1-1H2v-2h7a1 1 0 0 1 1-1h1v-2H5a2 2 0 0 1-2-2","function-variant":"M12.42 5.29c-1.1-.1-2.07.71-2.17 1.82L10 10h2.82v2h-3l-.44 5.07A4.001 4.001 0 0 1 2 18.83l1.5-1.5c.33 1.05 1.46 1.64 2.5 1.3c.78-.24 1.33-.93 1.4-1.74L7.82 12h-3v-2H8l.27-3.07a4.01 4.01 0 0 1 4.33-3.65c1.26.11 2.4.81 3.06 1.89l-1.5 1.5c-.25-.77-.93-1.31-1.74-1.38M22 13.65l-1.41-1.41l-2.83 2.83l-2.83-2.83l-1.43 1.41l2.85 2.85l-2.85 2.81l1.43 1.41l2.83-2.83l2.83 2.83L22 19.31l-2.83-2.81z","google-cloud":"M23 14.75C23 18.2 20.2 21 16.75 21h-9.5C3.8 21 1 18.2 1 14.75c0-2.14 1.08-4.03 2.71-5.15C4.58 5.82 7.96 3 12 3s7.42 2.82 8.29 6.6A6.22 6.22 0 0 1 23 14.75M16.63 17c1.31 0 2.37-1.06 2.37-2.37c0-1.28-1-2.33-2.28-2.38l.03-.5a4.754 4.754 0 0 0-8.32-3.14c1.5.29 2.8 1.11 3.71 2.25L9.5 13.5c-.42-.73-1.21-1.25-2.12-1.25c-1.32 0-2.38 1.06-2.38 2.38c0 1.27 1 2.3 2.25 2.37z",harddisk:"M6 2h12a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2m6 2a6 6 0 0 0-6 6c0 3.31 2.69 6 6.1 6l-.88-2.23a1.01 1.01 0 0 1 .37-1.37l.86-.5a1.01 1.01 0 0 1 1.37.37l1.92 2.42A5.98 5.98 0 0 0 18 10a6 6 0 0 0-6-6m0 5a1 1 0 0 1 1 1a1 1 0 0 1-1 1a1 1 0 0 1-1-1a1 1 0 0 1 1-1m-5 9a1 1 0 0 0-1 1a1 1 0 0 0 1 1a1 1 0 0 0 1-1a1 1 0 0 0-1-1m5.09-4.73l2.49 6.31l2.59-1.5l-4.22-5.31z",lan:"M10 2c-1.11 0-2 .89-2 2v3c0 1.11.89 2 2 2h1v2H2v2h4v2H5c-1.11 0-2 .89-2 2v3c0 1.11.89 2 2 2h4c1.11 0 2-.89 2-2v-3c0-1.11-.89-2-2-2H8v-2h8v2h-1c-1.11 0-2 .89-2 2v3c0 1.11.89 2 2 2h4c1.11 0 2-.89 2-2v-3c0-1.11-.89-2-2-2h-1v-2h4v-2h-9V9h1c1.11 0 2-.89 2-2V4c0-1.11-.89-2-2-2zm0 2h4v3h-4zM5 17h4v3H5zm10 0h4v3h-4z",lock:"M12 17a2 2 0 0 0 2-2a2 2 0 0 0-2-2a2 2 0 0 0-2 2a2 2 0 0 0 2 2m6-9a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V10a2 2 0 0 1 2-2h1V6a5 5 0 0 1 5-5a5 5 0 0 1 5 5v2zm-6-5a3 3 0 0 0-3 3v2h6V6a3 3 0 0 0-3-3",memory:"M17 17H7V7h10m4 4V9h-2V7a2 2 0 0 0-2-2h-2V3h-2v2h-2V3H9v2H7c-1.11 0-2 .89-2 2v2H3v2h2v2H3v2h2v2a2 2 0 0 0 2 2h2v2h2v-2h2v2h2v-2h2a2 2 0 0 0 2-2v-2h2v-2h-2v-2m-6 2h-2v-2h2m2-2H9v6h6z","message-processing":"M17 11h-2V9h2m-4 2h-2V9h2m-4 2H7V9h2m11-7H4a2 2 0 0 0-2 2v18l4-4h14a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2","microsoft-azure":"M13.05 4.24L6.56 18.05L2 18l5.09-8.76zm.7 1.09L22 19.76H6.74l9.3-1.66l-4.87-5.79z",monitor:"M21 16H3V4h18m0-2H3c-1.11 0-2 .89-2 2v12a2 2 0 0 0 2 2h7v2H8v2h8v-2h-2v-2h7a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2","queue-first-in-last-out":"M6 6h12v2H6zm0 4.5h12v2H6zM6 15h12v2H6zm3 4h6l-3 3zM9 2h6l-3 3z","router-network":"M5 9c-1.1 0-2 .9-2 2v4a2 2 0 0 0 2 2h6v2h-1c-.55 0-1 .45-1 1H2v2h7c0 .55.45 1 1 1h4c.55 0 1-.45 1-1h7v-2h-7c0-.55-.45-1-1-1h-1v-2h6c1.11 0 2-.89 2-2v-4a2 2 0 0 0-2-2zm1 3h2v2H6zm3.5 0h2v2h-2zm3.5 0h2v2h-2z",server:"M4 1h16a1 1 0 0 1 1 1v4a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1m0 8h16a1 1 0 0 1 1 1v4a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1v-4a1 1 0 0 1 1-1m0 8h16a1 1 0 0 1 1 1v4a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1v-4a1 1 0 0 1 1-1M9 5h1V3H9zm0 8h1v-2H9zm0 8h1v-2H9zM5 3v2h2V3zm0 8v2h2v-2zm0 8v2h2v-2z","shield-lock":"M12 1L3 5v6c0 5.55 3.84 10.74 9 12c5.16-1.26 9-6.45 9-12V5zm0 6c1.4 0 2.8 1.1 2.8 2.5V11c.6 0 1.2.6 1.2 1.3v3.5c0 .6-.6 1.2-1.3 1.2H9.2c-.6 0-1.2-.6-1.2-1.3v-3.5c0-.6.6-1.2 1.2-1.2V9.5C9.2 8.1 10.6 7 12 7m0 1.2c-.8 0-1.5.5-1.5 1.3V11h3V9.5c0-.8-.7-1.3-1.5-1.3",web:"M16.36 14c.08-.66.14-1.32.14-2s-.06-1.34-.14-2h3.38c.16.64.26 1.31.26 2s-.1 1.36-.26 2m-5.15 5.56c.6-1.11 1.06-2.31 1.38-3.56h2.95a8.03 8.03 0 0 1-4.33 3.56M14.34 14H9.66c-.1-.66-.16-1.32-.16-2s.06-1.35.16-2h4.68c.09.65.16 1.32.16 2s-.07 1.34-.16 2M12 19.96c-.83-1.2-1.5-2.53-1.91-3.96h3.82c-.41 1.43-1.08 2.76-1.91 3.96M8 8H5.08A7.92 7.92 0 0 1 9.4 4.44C8.8 5.55 8.35 6.75 8 8m-2.92 8H8c.35 1.25.8 2.45 1.4 3.56A8 8 0 0 1 5.08 16m-.82-2C4.1 13.36 4 12.69 4 12s.1-1.36.26-2h3.38c-.08.66-.14 1.32-.14 2s.06 1.34.14 2M12 4.03c.83 1.2 1.5 2.54 1.91 3.97h-3.82c.41-1.43 1.08-2.77 1.91-3.97M18.92 8h-2.95a15.7 15.7 0 0 0-1.38-3.56c1.84.63 3.37 1.9 4.33 3.56M12 2C6.47 2 2 6.5 2 12a10 10 0 0 0 10 10a10 10 0 0 0 10-10A10 10 0 0 0 12 2"});var PW=Object.freeze({"logos:aws":"cloud","logos:aws-lambda":"function-variant","logos:aws-aurora":"database","logos:aws-glacier":"archive","logos:aws-s3":"harddisk","logos:aws-ec2":"server","logos:microsoft-azure":"microsoft-azure","logos:google-cloud":"google-cloud"});var EW=/^[MmZzLlHhVvCcSsQqTtAa0-9eE+.,\s-]+$/;var XP=/^[a-z0-9][a-z0-9:_/-]*$/;function RW(){const e=Object.entries(Hm);if(e.length>Gm.maxIcons)throw new Error("Architecture icon registry exceeds maxIcons");for(const[t,n]of e){if(t.length>Gm.maxNameBytes||!XP.test(t)){throw new Error(`Unsafe Architecture icon name: ${t}`)}if(n.length>Gm.maxPathBytes||!EW.test(n)){throw new Error(`Unsafe or oversized Architecture icon path: ${t}`)}}}RW();function vW(e){const t=e.trim().toLowerCase();if(!t||t.length>Gm.maxNameBytes||!XP.test(t))return void 0;const n=PW[t];if(n)return n;const i=t.startsWith("mdi:")?t.slice(4):t.startsWith("mdi/")?t.slice(4):t;if(i.includes(":")||i.includes("/"))return void 0;return Object.prototype.hasOwnProperty.call(Hm,i)?i:void 0}function ya(e){const t=vW(e);if(!t)return null;return{canonicalName:`mdi:${t}`,viewBox:"0 0 24 24",path:Hm[t],source:"@iconify-json/mdi@1.2.3",license:"Apache-2.0"}}function IQ(){return Object.keys(Hm).sort().map(e=>ya(`mdi:${e}`))}function yi(e){const t=new Set(e),n=new Map;return(i,r=i)=>{const o=typeof r==="string"?r:[...r];if(typeof o!=="string"&&o.some(d=>typeof d==="number"&&!Number.isFinite(d))){throw new TypeError("Generated identity key numeric components must be finite")}const s=JSON.stringify(o);const a=n.get(s);if(a!==void 0)return a;let l=i,c=1;while(t.has(l))l=`${i}#${c++}`;t.add(l);n.set(s,l);return l}}function xa(e){if(e.source==="merge"&&e.customId)return e.sourceId||e.id;return e.message||e.sourceId||e.id}var Rn=class extends Error{constructor(n,i){super(n);this.line=i;this.name="GitGraphParseError"}line};var Nb=class extends Rn{constructor(n,i){super(`Duplicate gitGraph commit id '${n}' on line ${i}; commit IDs must be unique.`,i);this.id=n}id;code="GITGRAPH_DUPLICATE_COMMIT_ID"};var JP={spanning:`"'`,wholeLine:e=>/^title(?:\s|$)/i.test(e)};function $b(e){return Ir(e,JP)}function QP(e,t={}){const n=e.replace(/^\uFEFF/,"").split(/\r?\n/);const i=zt(n,$b(n));if(i.unclosedIndex!==void 0){throw new Rn("Unclosed accDescr block",i.unclosedIndex+1)}const r=fa(i.familyLines,JP).map(Ht);const o=r.findIndex(P=>/^\s*gitgraph\b/i.test(P));if(o<0)throw new Rn("gitGraph source must start with a gitGraph header");const s=r[o].trim().match(/^gitGraph(?:\s+(LR|TB|BT))?\s*:?[ \t]*$/i);if(!s)throw new Rn("Invalid gitGraph header; expected gitGraph, gitGraph LR:, gitGraph TB:, or gitGraph BT:",o+1);if(re("gitgraph"))Ge("gitgraph","header",r[o],{line:o+1,unit:"normalized"});const a=s[1]?.toUpperCase()??"LR";const l=typeof t.mainBranchName==="string"&&t.mainBranchName.trim()?t.mainBranchName.trim():"main";const c=TW(t.mainBranchOrder,0);const d=typeof t.title==="string"&&t.title.trim()?t.title.trim():void 0;const u=[];const f=new Map([[l,{name:l,order:c,sequence:0}]]);const h=[];const m=new Map;const p=[];const g=new Map;for(let P=o+1;P<r.length;P++){const E=r[P].trim();const k=E.match(UP);const v=k?void 0:E.match(VP);if(!k&&!v)continue;const T=k?k[1]??"":v[2]??"";if(k&&/^(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')$/.test(T))continue;try{const A=jm(T,P+1,k?["id","tag","type","msg"]:["id","tag","type"]);g.set(P,A);if(A.id!==void 0)p.push(A.id)}catch{}}const y=yi(p);const w=new Map;let S=l;let x=0;const M=i.accessibility.title;const b=i.accessibility.descr;if(re("gitgraph"))he("gitgraph","initialize",{direction:a,mainBranchName:l,title:d,branch:f.get(l),currentBranch:S,accessibilityTitle:M,accessibilityDescription:b});const C=(P,E,k,v={},T)=>{const A=P.id!==void 0;const R=P.id??`c${x}`;if(E==="merge"&&A&&w.has(R))throw new Nb(R,k);const I=A&&!m.has(R)?R:y(R,["commit",x]);const L=E==="merge"?"MERGE":E==="cherry-pick"?"CHERRY_PICK":P.type??"NORMAL";const $=f.get(S);const B={id:I,...A&&I!==P.id?{sourceId:P.id}:{},...P.msg?{message:P.msg}:{},type:L,tags:P.tags,branch:S,parents:T??($.head?[$.head]:[]),sequence:x++,source:E,customId:A,...v};u.push(B);if(re("gitgraph"))he("gitgraph","addCommit",B,{line:k,unit:"normalized"});m.set(I,B);w.set(P.id??I,B);$.head=I;if(re("gitgraph"))he("gitgraph","setBranchHead",{branch:S,head:I},{line:k,unit:"normalized"});return B};for(let P=o+1;P<r.length;P++){const E=r[P].trim();if(!E||E.startsWith("%%"))continue;const k=E.match(UP);if(k){if(re("gitgraph"))Ge("gitgraph","commit",E,{line:P+1,unit:"normalized"});const I=k[1]??"";const L=/^(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')$/.test(I);const $=L?{tags:[],msg:$u(I)}:g.get(P)??jm(I,P+1,["id","tag","type","msg"]);const B=C($,"commit",P+1);h.push({kind:"commit",ref:B.id});if(re("gitgraph"))he("gitgraph","appendStatement",h.at(-1),{line:P+1,unit:"normalized"});continue}const v=E.match(/^branch\s+("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\S+)(?:\s+order\s*:\s*(-?\d+))?$/i);if(v){if(re("gitgraph"))Ge("gitgraph","branch",E,{line:P+1,unit:"normalized"});const I=$u(v[1]);if(f.has(I))throw new Rn(`Trying to create existing branch '${I}'; use checkout ${Ym(I)} instead.`,P+1);const L=v[2]===void 0?void 0:Number(v[2]);if(L!==void 0&&L<=0)throw new Rn("Branch order must be a positive integer.",P+1);const $=L??AW(f.size);f.set(I,{name:I,order:$,sequence:f.size,...f.get(S)?.head?{head:f.get(S).head}:{}});if(re("gitgraph"))he("gitgraph","addBranch",f.get(I),{line:P+1,unit:"normalized"});S=I;if(re("gitgraph"))he("gitgraph","setCurrentBranch",I,{line:P+1,unit:"normalized"});h.push({kind:"branch",name:I,...v[2]!==void 0?{order:$}:{}});if(re("gitgraph"))he("gitgraph","appendStatement",h.at(-1),{line:P+1,unit:"normalized"});continue}const T=E.match(/^(checkout|switch)\s+("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\S+)$/i);if(T){if(re("gitgraph"))Ge("gitgraph","checkout",E,{line:P+1,unit:"normalized"});const I=$u(T[2]);if(!f.has(I))throw new Rn(`Trying to checkout branch '${I}' before it is created.`,P+1);S=I;if(re("gitgraph"))he("gitgraph","setCurrentBranch",I,{line:P+1,unit:"normalized"});h.push({kind:"checkout",branch:I,keyword:T[1].toLowerCase()});if(re("gitgraph"))he("gitgraph","appendStatement",h.at(-1),{line:P+1,unit:"normalized"});continue}const A=E.match(VP);if(A){if(re("gitgraph"))Ge("gitgraph","merge",E,{line:P+1,unit:"normalized"});const I=$u(A[1]);const L=g.get(P)??jm(A[2]??"",P+1,["id","tag","type"]);if(I===S)throw new Rn(`Cannot merge branch '${I}' into itself.`,P+1);const $=f.get(S);const B=f.get(I);if(!B)throw new Rn(`Branch to be merged ('${I}') does not exist.`,P+1);if(!$.head)throw new Rn(`Current branch '${S}' has no commits.`,P+1);if(!B.head)throw new Rn(`Branch to be merged ('${I}') has no commits.`,P+1);if(B.head===$.head)throw new Rn("Cannot merge branches with the same head commit.",P+1);const F=C(L,"merge",P+1,{mergeBranch:I,message:`merged branch ${I} into ${S}`,...L.type?{customType:L.type}:{}},[$.head,B.head]);h.push({kind:"merge",ref:F.id,branch:I});if(re("gitgraph"))he("gitgraph","appendStatement",h.at(-1),{line:P+1,unit:"normalized"});continue}const R=E.match(/^cherry-pick\s+(.+)$/is);if(R){if(re("gitgraph"))Ge("gitgraph","cherry-pick",E,{line:P+1,unit:"normalized"});const I=jm(R[1],P+1,["id","tag","parent"]);if(!I.id)throw new Rn('cherry-pick requires id:"existing commit".',P+1);const L=w.get(I.id);if(!L)throw new Rn(`Cherry-pick source commit '${I.id}' does not exist.`,P+1);const $=f.get(S);if(!$.head)throw new Rn(`Current branch '${S}' has no commits.`,P+1);if(LW($.head,L.id,m))throw new Rn(`Cherry-pick source '${L.id}' is already reachable from current branch '${S}'.`,P+1);const B=I.parent?w.get(I.parent)?.id:void 0;if(L.parents.length===2){if(!I.parent)throw new Rn(`Cherry-picking merge commit '${L.id}' requires parent:"immediate parent".`,P+1);if(!B||!L.parents.includes(B))throw new Rn(`Cherry-pick parent '${I.parent}' is not an immediate parent of '${L.id}'.`,P+1)}const F=I.tags.length===0?`cherry-pick:${L.sourceId??L.id}${I.parent?`|parent:${I.parent}`:""}`:void 0;const z={tags:F?[F]:I.tags};const _=C(z,"cherry-pick",P+1,{message:`cherry-picked ${xa(L)} into ${S}`,cherrySource:L.id,...B?{cherryParent:B}:{},...F?{syntheticCherryTag:F}:{}},[$.head,L.id]);h.push({kind:"cherry-pick",ref:_.id,source:L.id,...B?{parent:B}:{}});if(re("gitgraph"))he("gitgraph","appendStatement",h.at(-1),{line:P+1,unit:"normalized"});continue}if(re("gitgraph"))Ge("gitgraph","invalid",E,{line:P+1,unit:"normalized"});throw new Rn(`Unsupported gitGraph statement on line ${P+1}: ${E}`,P+1)}return{direction:a,mainBranchName:l,...d?{title:d}:{},commits:u,branches:[...f.values()],statements:h,...M?{accessibilityTitle:M}:{},...b?{accessibilityDescription:b}:{}}}var UP=/^commit(?:\s+(.*))?$/is;var VP=/^merge\s+("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\S+)(?:\s+(.*))?$/is;function jm(e,t,n){const i={tags:[]};let r=0;const o=/([A-Za-z][\w-]*)\s*:\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\S+)/gy;while(r<e.length){while(/\s/.test(e[r]??""))r++;if(r>=e.length)break;o.lastIndex=r;const s=o.exec(e);if(!s)throw new Rn(`Invalid gitGraph attribute syntax near '${e.slice(r)}'.`,t);const a=s[1].toLowerCase();if(!n.includes(a))throw new Rn(`Attribute '${a}' is not valid for this gitGraph statement.`,t);const l=$u(s[2]);if(a==="id")i.id=l;else if(a==="msg")i.msg=l;else if(a==="tag")i.tags.push(l);else if(a==="parent")i.parent=l;else{const c=l.toUpperCase();if(!["NORMAL","REVERSE","HIGHLIGHT"].includes(c))throw new Rn(`Invalid commit type '${l}'.`,t);i.type=c}r=o.lastIndex}return i}function $u(e){if(!/^(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')$/.test(e))return e;const t={b:"\b",f:"\f",n:"\n",r:"\r",t:" ",v:"\v",0:"\0"};return e.slice(1,-1).replace(/\\(.)/g,(n,i)=>t[i]??i)}function Ym(e){return/^[A-Za-z_](?:[-./\w]*[-\w])?$/.test(e)&&!/^(?:title|(?:gitGraph|commit|branch|checkout|switch|merge|cherry-pick|LR|TB|BT|NORMAL|REVERSE|HIGHLIGHT)$)/i.test(e)?e:Il(e)}function TW(e,t){return typeof e==="number"&&Number.isFinite(e)?e:t}function LW(e,t,n){const i=[e];const r=new Set;while(i.length>0){const o=i.pop();if(o===t)return true;if(r.has(o))continue;r.add(o);const s=n.get(o);if(s)i.push(...s.source==="cherry-pick"?s.parents.slice(0,1):s.parents)}return false}function zQ(e){const t=e.direction==="LR"?"gitGraph":`gitGraph ${e.direction}:`;const n=[t];if(e.accessibilityTitle)n.push(` accTitle: ${e.accessibilityTitle}`);if(e.accessibilityDescription?.includes("\n")){n.push(" accDescr {",...e.accessibilityDescription.split("\n").map(r=>` ${r}`)," }")}else if(e.accessibilityDescription)n.push(` accDescr: ${e.accessibilityDescription}`);const i=new Map(e.commits.map(r=>[r.id,r]));for(const r of e.statements){if(r.kind==="branch")n.push(` branch ${Ym(r.name)}${r.order!==void 0?` order: ${r.order}`:""}`);else if(r.kind==="checkout")n.push(` ${r.keyword} ${Ym(r.branch)}`);else{const o=i.get(r.ref);if(!o)continue;if(r.kind==="commit")n.push(` commit${KP(o)}`);else if(r.kind==="merge")n.push(` merge ${Ym(r.branch)}${KP(o,false)}`);else{const s=o.tags.filter(a=>a!==o.syntheticCherryTag);n.push(` cherry-pick id:${Il(i.get(o.cherrySource??r.source)?.sourceId??o.cherrySource??r.source)}${r.parent?` parent:${Il(i.get(r.parent)?.sourceId??r.parent)}`:""}${s.map(a=>` tag:${Il(a)}`).join("")}`)}}}return n.join("\n")+"\n"}function KP(e,t=true){const n=[];if(e.customId)n.push(`id:${Il(e.sourceId??e.id)}`);const i=e.type==="MERGE"?e.customType:e.type;if(i&&i!=="NORMAL"&&i!=="CHERRY_PICK")n.push(`type:${i}`);for(const r of e.tags)n.push(`tag:${Il(r)}`);if(t&&e.message)n.push(`msg:${Il(e.message)}`);return n.length?` ${n.join(" ")}`:""}function AW(e){return e<=9?e/10:1-1/(e+1)}function IW(e){const t={"\b":"b","\f":"f","\n":"n","\r":"r"," ":"t","\v":"v","\0":"0"};const n=e.replace(/[\\"%\b\f\n\r\t\v\0]/g,i=>`\\${t[i]??i}`).replace(/#\w+;/g,i=>`${i.slice(0,-1)}\\;`).replace(/style/g,"sty\\le").replace(/classDef/g,"class\\Def");return`"${n}"`}var Il=IW;var ir=class extends Error{constructor(n,i){super(n);this.line=i;this.name="MindmapParseError"}line};var _b=class extends ir{constructor(n,i){super(`Duplicate mindmap node identity '${n}' on line ${i}; every node identity must be unique.`,i);this.id=n}id;code="MINDMAP_DUPLICATE_ID"};function eE(e){const t=e.replace(/^\uFEFF/,"").split(/\r?\n/);const n=t.map(h=>vt([h],0)?.form==="inline"?tE(h,false):h);const i=zt(n,qm(n));if(i.unclosedIndex!==void 0){throw new ir("Unclosed accDescr block",i.unclosedIndex+1)}const r=Yo(i.accessibility);const o=i.familyLines;const s=o.findIndex(h=>/^\s*mindmap\s*$/i.test(h));if(s<0)throw new ir("Mindmap source must start with the mindmap header");if(re("mindmap"))Ge("mindmap","header",o[s],{line:s+1,unit:"normalized"});const a=[];const l=new Set;let c;let d;const u=r.title;const f=r.descr;if(re("mindmap"))he("mindmap","initialize",{accessibilityTitle:u,accessibilityDescription:f});for(const{raw:h,start:m,end:p}of _u(o,s+1)){const g=m+1;const y=h.trim();if(!y||y.startsWith("%%"))continue;if(/^acc(?:Title|Descr)\b/i.test(y)){const M=/^accTitle\b/i.test(y)?"accTitle":"accDescr";throw new ir(`Mindmap ${M} must contain a non-empty value`,p+1)}if(/^::icon\b/i.test(y)){if(re("mindmap"))Ge("mindmap","icon",y,{line:g,unit:"normalized"});const M=y.match(/^::icon\(([^)]*)\)$/i);const b=M?.[1]?.trim();if(!M||!b)throw new ir("Mindmap icon decoration must contain a non-empty value without closing parentheses",p+1);if(!d)throw new ir("Mindmap icon decoration requires a preceding node",p+1);d.icon=b;if(re("mindmap"))he("mindmap","setIcon",{id:d.id,icon:b},{line:g,unit:"normalized"});continue}if(y.startsWith(":::")){if(re("mindmap"))Ge("mindmap","class",y,{line:g,unit:"normalized"});const M=y.match(/^:::\s*(.+)$/);if(!M)throw new ir("Mindmap class decoration must contain at least one class name",p+1);if(!d)throw new ir("Mindmap class decoration requires a preceding node",p+1);d.className=M[1].trim().replace(/\s+/g," ");if(re("mindmap"))he("mindmap","setClass",{id:d.id,className:d.className},{line:g,unit:"normalized"});continue}const w=nE(y);if(re("mindmap"))Ge("mindmap",w?"node":"invalid",y,{line:g,unit:"normalized"});if(!w){throw new ir(`Invalid mindmap node syntax on line ${p+1}: ${y}`,p+1)}if(l.has(w.id))throw new _b(w.id,p+1);l.add(w.id);const S={...w,children:[]};if(re("mindmap"))he("mindmap","createNode",S,{line:g,unit:"normalized"});const x=FW(h);while(a.length>0&&a[a.length-1].indent>=x)a.pop();if(a.length===0){if(c)throw new ir(`There can be only one mindmap root; '${S.label}' has no parent on line ${p+1}.`,p+1);c=S;if(re("mindmap"))he("mindmap","setRoot",{id:S.id},{line:g,unit:"normalized"})}else{a[a.length-1].node.children.push(S);if(re("mindmap"))he("mindmap","attachChild",{id:S.id,parentId:a[a.length-1].node.id},{line:g,unit:"normalized"})}a.push({indent:x,node:S});d=S}if(!c)throw new ir("Mindmap requires exactly one root node");return{root:c,...u?{accessibilityTitle:u}:{},...f?{accessibilityDescription:f}:{}}}function qm(e){const t=e.map((n,i)=>i);try{for(const{start:n,end:i}of _u(e,0))t[n]=i}catch{}return t}function*_u(e,t){let n;let i;for(let r=t;r<e.length;r++){const o=r;let s=e[r];if(s.includes('["`')&&!s.includes('`"]')){const a=[s];let l=false;while(++r<e.length){a.push(e[r]);if(e[r].includes('`"]')){l=true;break}}if(!l)throw new ir("Unclosed mindmap Markdown String",r+1);s=a.join("\n")}if(Db(s.trimStart())==="open"){const a=d=>/^\s*%%/.test(d);n??=e.map(d=>a(d)?"":d).join("\n");i??=e.reduce((d,u,f)=>(d.push(f===0?0:d[f-1]+(a(e[f-1])?0:e[f-1].length)+1),d),[]);const l=i[r]+s.length-s.trimStart().length;const c=Db(n.slice(l));if(c&&c!=="open"){const d=r+n.slice(l,l+c.end).split("\n").length-1;s=[e[r].trimEnd(),...e.slice(r+1,d+1).filter(u=>!a(u)).map(u=>u.trim())].join("\n");r=d}}yield{raw:tE(s),start:o,end:r}}}function UQ(e){const t=e.split(/\r?\n/);const n=t.findIndex(r=>/^\s*mindmap\s*$/i.test(r));if(n<0)return[];for(let r=n+1;r<t.length;r++){const o=vt(t,r);if(o===void 0)break;if(o===null)continue;t.fill("",r,o.endIndex+1);r=o.endIndex}const i=[];for(const{raw:r,start:o}of _u(t,n+1)){const s=r.trim();if(!s||s.startsWith("%%")||/^::icon\b/i.test(s)||s.startsWith(":::"))continue;if(Xm(s)?.nested)i.push(o+1)}return i}function Bb(e){const t=Db(e);return t==="open"?null:t}function Db(e){const t=e.match(/^([^()[{}]*?)(\(\(|\{\{|\[|\)\)|\)|\()/);if(!t)return null;const n=t[2];const i=t[0].length;let r=i;if(e.startsWith('"`',i)){const c=e.indexOf('`"',i+2);if(c<0)return"open";r=c+2}else if(e[i]==='"'){r=i+1;while(r<e.length){if(e[r]==="\\"){r+=2;continue}if(e[r++]==='"')break}if(e[r-1]!=='"'||r===i+1)return"open"}else{while(r<e.length&&!/[)\](}]/.test(e[r]))r++}const o=e.slice(i,r);const s=e[i]==='"';while(r<e.length&&(s?/[ \t]/:/\s/).test(e[r]))r++;if(r===e.length)return s?null:"open";const a=["))","}}","((","(-","-)",")","]","("].find(c=>e.startsWith(c,r));if(!a)return null;const l=n==="["?"rect":n==="{{"?"hexagon":n==="(("?"circle":n==="))"?"bang":n===")"||a!==")"?"cloud":"rounded";return{id:t[1].trim(),label:o,shape:l,end:r+a.length}}function tE(e,t=true){if(e.trimStart().startsWith(":::"))return e;const n=vt([e],0)?.form==="inline";const i=e.trimStart();const r=t&&!i.startsWith("::")?Bb(i):null;if(r){const a=e.indexOf("%%",e.length-i.length+r.end);return a<0?e:e.slice(0,a)}let o=false;let s=false;for(let a=0;a<e.length-1;a++){const l=e[a];if(s){s=false;continue}if(l==="\\"){s=true;continue}if(l==='"'){o=!o;continue}if(o||l!=="%"||e[a+1]!=="%")continue;const c=e.slice(0,a).trim();if(!c||n||/^::icon\([^)]*\)$/.test(c))return e.slice(0,a);const d=nE(c);if(d&&d.shape!=="default")return e.slice(0,a)}return e}function FW(e){let t=0;for(const n of e){if(n===" ")t++;else if(n===" ")t+=4;else break}return t}var Wb=/^(?!mindmap\b)[^([\r\n){}]*$/i;function nE(e){return Xm(e)?.node??null}var NW=[{regex:/^(.*?)\(\((.*)\)\)$/,shape:"circle"},{regex:/^(.*?)\{\{(.*)\}\}$/,shape:"hexagon"},{regex:/^(.*?)\[([\s\S]*)\]$/,shape:"rect"},{regex:/^(.*?)\)\)(.*)\(\($/,shape:"bang"},{regex:/^(.*?)\)(.*)\($/,shape:"cloud"},{regex:/^(.*?)\((.*)\)$/,shape:"rounded"}];function Xm(e){const t=Bb(e);if(t&&!e.slice(t.end).trim()){const r=ZP(t.id,t.label,t.shape);return r&&{node:r}}for(const{regex:r,shape:o}of NW){const s=e.match(r);if(!s)continue;const a=s[2];const l=!a.includes('"')&&$W(a)?ZP(s[1].trim(),a,o):null;return l&&{node:l,nested:true}}if(!Wb.test(e))return null;const n=zb(e);const i=Um(n.label);return i?{node:{id:i,label:n.label,shape:"default",...n.markdown?{markdown:true}:{}}}:null}function ZP(e,t,n){if(!Wb.test(e))return null;const i=zb(t);const r=e||Um(i.label);return r&&i.label?{id:r,label:i.label,shape:n,...i.markdown?{markdown:true}:{}}:null}function $W(e){const t=[];for(const n of e){const i=n==="("?")":n==="["?"]":n==="{"?"}":void 0;if(i)t.push(i);else if((n===")"||n==="]"||n==="}")&&t.pop()!==n)return false}return t.length===0}function zb(e){let t=e.trim();const n=t.startsWith('"`')&&t.endsWith('`"');if(n)t=_W(jo(t.slice(2,-2)));else{if(t.startsWith('"')&&t.endsWith('"'))t=t.slice(1,-1);t=jo(t);t=t.replace(/\*\*([^*]+)\*\*/g,"$1").replace(/\*([^*]+)\*/g,"$1")}return{label:So(yt(t),"*()[]").trim(),markdown:n}}function _W(e){return e.replace(/\*\*([\s\S]+?)\*\*/g,"<b>$1</b>").replace(/\*([\s\S]+?)\*/g,"<i>$1</i>")}function DW(e,t,n=""){const i=r=>{const o=(t==="bare"?"*()[{}":"#&*"+(t==="unquoted"?"":'"`'))+n+(r.includes("%%{")||t==="bare"&&/^%%/.test(e)?"%":"");let s=dn(t==="markdown"?r:r.replace(/\n/g,"<br/>"),o);if(t==="bare"&&/^mindmap\b/i.test(s))s=`#${s.codePointAt(0)};${s.slice(1)}`;return s};return t==="markdown"?e.split(/(<\/?[bi]>)/gi).map(r=>/^<\/?b>$/i.test(r)?"**":/^<\/?i>$/i.test(r)?"*":i(r)).join(""):i(e)}function Um(e){return e.replace(/<\/?(?:b|i)>/gi,"").trim()}function Ob(e){const t=e.markdown;const n=t?"markdown":e.shape==="default"?"bare":/[()\]}]/.test(e.label)||e.label.startsWith('"')?"quoted":"unquoted";const i=e.id===Um(e.label)&&(/[()[\]{}\r\n]/.test(e.id)||e.id.includes("%%{")||!Wb.test(e.id))?"":e.id;return fP(r=>{const o=DW(e.label,n,r);const s=t?`"\`${o}\`"`:n==="quoted"?`"${o}"`:o;return e.shape==="default"?s:e.shape==="rect"?`${i}[${s}]`:e.shape==="rounded"?`${i}(${s})`:e.shape==="circle"?`${i}((${s}))`:e.shape==="hexagon"?`${i}{{${s}}}`:e.shape==="cloud"?`${i})${s}(`:`${i}))${s}((`})}function iE(e,t){const n=a=>{if(a.shape==="default"&&(Ob(a)!==a.label.replace(/\n/g,"<br/>")||zb(a.label).label!==a.label))return`Mindmap default node "${a.id}" needs text escapes that would change its identity; choose a bordered shape with an explicit identity before editing this text`;const l=a.shape!=="default"&&a.id===Um(a.label);if(!l&&a.id.includes("%%{")||[a.icon,a.className].some(c=>c?.includes("%%{"))){return`Mindmap node "${a.id}" has an explicit identity or decoration containing a directive opener; rename that identity before editing its text`}for(const c of a.children){const d=n(c);if(d)return d}return void 0};const i=n(e.root);if(i||t===void 0)return i;const r=t.split(/\r?\n/);const o=r.findIndex(a=>/^\s*mindmap\s*$/i.test(a));const s=zt(r,qm(r));for(const{raw:a}of _u(s.familyLines,o+1)){const l=a.trim();if(!l||l.startsWith("%%")||l.startsWith("::"))continue;const c=Xm(l)?.node;if(!c||c.shape!=="default")continue;const d=h=>Dn(Un(h)).replace(/<br\s*\/?>/gi,"<br>");const u=d(l);const f=d(Ob({...c,children:[]}));if(f!==u)return`Mindmap default node "${c.id}" has an authored identity that cannot be reconstructed without changing its token; its source remains preserved`}return void 0}function VQ(e){const t=e.split(/\r?\n/);const n=t.findIndex(r=>/^\s*mindmap\s*$/i.test(r));const i=[];if(n<0)return i;for(const{raw:r,start:o}of _u(t,n+1)){const s=r.trim();if(!s||s.startsWith("%%")||/^acc(?:Title|Descr)\b/i.test(s))continue;const a=Xm(s)?.node;const l=Bb(s)?.label;const c=s.includes("%%{")||l!==void 0&&/^"[\s\S]*"$/.test(l)&&/["`]/.test(l.slice(l.startsWith('"`')?2:1,l.endsWith('`"')?-2:-1));const d=c?"Mindmap label delimiters need grammar escapes for pinned Mermaid; the writer preserves their literal text":a?iE({root:{...a,children:[]}},`mindmap
2
+ ${s}`):/^::/.test(s)&&s.includes("%%{")?"Mindmap decoration contains a directive opener with no portable spelling that preserves its text":void 0;if(d)i.push({line:o+1,message:d})}return i}function KQ(e){const t=iE(e);if(t)throw new ir(t);const n=["mindmap"];Tl(n,e);const i=(r,o)=>{const s=" ".repeat(o+1);const a=Ob(r);n.push(s+a);if(r.icon)n.push(`${s} ::icon(${r.icon})`);if(r.className)n.push(`${s} :::${r.className}`);for(const l of r.children)i(l,o+1)};i(e.root,0);return n.join("\n")+"\n"}function eZ(e,t){return e&&Object.hasOwn(e,t)?e[t]:void 0}function OW(e){const t=new Map;const n=[];for(let i=e.length-1;i>=0;i--){const[r,o]=e[i];let s=t.get(r);if(!s){s=new Set;t.set(r,s)}if(!s.has(o))n.push([r,o]);s.add(o)}return n.reverse()}function tZ(e){const t=OW(e);return new Set(t.map(([n])=>n)).size<t.length?t:void 0}function Vm(e){const t=new Map;for(const[n,i]of e){t.delete(n);t.set(n,i)}return Object.fromEntries(t)}function Ou(...e){const t=new Map;for(const n of e)for(const[i,r]of Object.entries(n??{})){t.delete(i);t.set(i,r)}return Object.fromEntries(t)}function BW(e){const t=[];let n=0;let i=0;let r=false;let o="";for(let s=0;s<e.length;s++){const a=e[s];if(r){r=false;continue}if(a==="\\"){r=true;continue}if(o){if(a===o)o="";continue}if(a==='"'||a==="'"){o=a;continue}if(a==="(")n++;else if(a===")")n=Math.max(0,n-1);else if((a===","||a===";")&&n===0){t.push(e.slice(i,s));i=s+1}}t.push(e.slice(i));return t.map(s=>s.replace(/\\,/g,","))}function vn(e,t={}){return Vm(WW(e,t))}function WW(e,t={}){const n=e.replace(/;\s*$/,"");const i=[];for(const r of BW(n)){const o=r.indexOf(":");if(o<=0)continue;const s=r.slice(0,o).trim();const a=t.caseInsensitive?s.toLowerCase():s;const l=r.slice(o+1).trim();if(a&&l)i.push([a,l])}return i}var zW=["fill","stroke","color"];function rE(e){for(const t of zW){const n=e[t];if(n!==void 0&&mn(n,t!=="color")===void 0)return{property:t,value:n}}return void 0}var Du=class extends Error{code="INVALID_STYLE_COLOR";subject;property;value;constructor(t,n,i,r){super(Je({what:`${t}: ${n} ${JSON.stringify(i)} is not a CSS color`,expectedForm:Tu(n!=="color"),example:`${r?`${r} `:""}${n}:#f96`}).message);this.name="AuthoredStyleColorError";this.subject=t;this.property=n;this.value=i}};function GW(e,t,n){return new Du(e,t.property,t.value,n)}function Tt(e,t){const n=e&&rE(e);if(n)throw GW(t,n,t);return e}function Km(e){for(const[t,n]of e.classDefs)Tt(n,`classDef ${t}`);for(const[t,n]of e.nodeStyles)Tt(n,`style ${t}`);for(const[t,n]of e.linkStyles)Tt(n,`linkStyle ${t}`)}function Jm(e,t){for(const[n,i]of e)Tt(i,`classDef ${n}`);for(const n of t)Tt(n.inlineStyle,`style ${n.id}`)}function nZ(e){if(typeof e!=="string")return{ok:false,reason:"NOT_STRING"};if(/[\r\n]/.test(e))return{ok:false,reason:"MULTILINE"};const t=vn(e);if(Object.keys(t).length===0)return{ok:false,reason:"EMPTY"};const n=rE(t);return n?{ok:false,reason:"UNSAFE_PAINT",paint:n}:{ok:true,value:t}}function iZ(e){return Object.entries(e).map(([t,n])=>`${t}:${n}`).join(",")}function Qm(e){return e?.split(/\s+/).filter(Boolean)??[]}function Is(e,t,n){const i=e.get(t);e.set(t,i?`${i} ${n}`:n)}var HW={default:{bg:wl.bg,fg:wl.fg},base:{bg:wl.bg,fg:wl.fg},neutral:{bg:"#ffffff",fg:"#1f2937",line:"#9ca3af",accent:"#6b7280",muted:"#6b7280"},dark:{bg:"#18181B",fg:"#FAFAFA"},forest:{bg:"#f0fdf4",fg:"#14532d",line:"#4d7c0f",accent:"#15803d",muted:"#65a30d",border:"#86efac"}};var Gi={bg:["background","mainBkg"],fg:["primaryTextColor","textColor","nodeTextColor"],line:["lineColor","defaultLinkColor"],accent:["arrowheadColor","primaryColor"],muted:["secondaryTextColor","tertiaryTextColor"],surface:["primaryColor","nodeBkg","mainBkg"],border:["primaryBorderColor","secondaryBorderColor"]};function Zm(e,t,n,i=false){const r=jW(t.theme);const o=t.themeVariables;const s=(...a)=>{const l=Gb(o,...a);return i?l:Zn(l)};return{bg:e.bg??s(...Gi.bg)??r?.bg??wl.bg,fg:e.fg??s(...Gi.fg)??r?.fg??wl.fg,line:e.line??s(...Gi.line)??r?.line,accent:e.accent??s(...Gi.accent)??r?.accent,muted:e.muted??s(...Gi.muted)??r?.muted,surface:e.surface??s(...Gi.surface)??r?.surface,border:e.border??s(...Gi.border)??r?.border,shadow:e.shadow??r?.shadow,font:n,embedFontImport:e.embedFontImport}}function jW(e){if(typeof e!=="string"||!e)return void 0;return HW[e.toLowerCase()]}function Gb(e,...t){if(!e)return void 0;for(const n of t){const i=e[n];if(typeof i==="string"&&i.length>0)return i}return void 0}function Hb(e,t){let n;for(const r of Qm(t.classAssignments.get(e))){const o=Tt(t.classDefs.get(r),`classDef ${r}`);if(o)n={...n,...o}}const i=Tt(t.nodeStyles.get(e),`style ${e}`);if(i)n=n?{...n,...i}:{...i};return n}function jb(e,t){let n;for(const i of Qm(t.classAssignments.get(e))){const r=Tt(t.classDefs.get(i),`classDef ${i}`);if(r)n={...n,...r}}return n}function Kc(e,t){let n;const i=t.edges[e]?.id;for(const s of Qm(i?t.classAssignments.get(i):void 0)){const a=Tt(t.classDefs.get(s),`classDef ${s}`);if(a)n={...n,...a}}const r=Tt(t.linkStyles.get("default"),"linkStyle default");if(r)n=n?{...n,...r}:{...r};const o=Tt(t.linkStyles.get(e),`linkStyle ${e}`);if(o)n=n?{...n,...o}:{...o};return n}function YW(e){const t=fl(e);return t?{r:t[0],g:t[1],b:t[2]}:null}function qW(e){const t=e.match(/^rgba?\(\s*(\d{1,3})(?:\s*,\s*|\s+)(\d{1,3})(?:\s*,\s*|\s+)(\d{1,3})/i);if(!t)return null;const n={r:Number.parseInt(t[1],10),g:Number.parseInt(t[2],10),b:Number.parseInt(t[3],10)};return Object.values(n).every(i=>i>=0&&i<=255)?n:null}function Xo(e){const t=YW(e)??qW(e);if(!t)return void 0;const n=sm(`rgb(${t.r}, ${t.g}, ${t.b})`);return(n+.05)/.05>=1.05/(n+.05)?"#000000":"#FFFFFF"}function Bu(e,t="var(--_text)"){if(e?.color)return e.color;if(e?.fill)return Xo(e.fill)??t;return t}var XW=new Set(["var(--_text)","var(--_text-sec)","var(--_text-muted)","var(--_text-faint)"]);function xi(e,t,n){if(!XW.has(e))return e;const i=_n(e,n);const r=_n(t,n);const o=i&&r?xu(r,_n("var(--bg)",n)??"#ffffff"):null;if(!o)return e;const s=e==="var(--_text-faint)"?L1:$c;const a=xs(i,Yn(...o),s);return a===i?e:a}function Fs(e,t,n){const i=e?.color;if(i)return()=>i;if(!e?.fill)return n===void 0?s=>s:s=>xi(s,n,t);const r=xu(e.fill,_n("var(--bg)",t)??"#ffffff");if(!r)return s=>s;const o=Yn(...r);return s=>{const a=_n(s,t);return a?xs(a,o):Xo(o)??s}}function Jr(e){const t=new Map,n=new Map;return(i,r,o=false)=>{const s=o?n:t;let a=s.get(r);const l=a?.get(i);if(l!==void 0)return l;const c=o?Fs({fill:r},e,r)(i):xi(i,r,e);if(!a)s.set(r,a=new Map);a.set(i,c);return c}}var Wu=new WeakMap;function Yb(e){return Object.freeze({...e,attempts:Object.freeze(e.attempts.map(t=>Object.freeze({...t})))})}function ep(e,t){const n=Wu.get(e)??[];const i=Yb(t);if(n.some(r=>JSON.stringify(r)===JSON.stringify(i)))return;Wu.set(e,Object.freeze([...n,i]))}function Uo(e){return Wu.get(e)??Object.freeze([])}function zu(e,t){const n=Wu.get(e);if(n)Wu.set(t,n)}var UW;var qb;var Xb=0;function ei(e,t){const n=UW;if(!n)return t();const i=qb,r=Xb;qb=e;Xb++;const o=performance.now();try{return t()}finally{const s=performance.now()-o;qb=i;Xb=r;n(Object.freeze({stage:e,ms:s,depth:r,...i?{parent:i}:{}}))}}var VW="agentic-layered@28";var Mo=class extends Error{constructor(n){super(`Agentic graph layout does not support this input: ${n}`);this.reason=n;this.name="GraphLayoutUnsupportedError"}reason;code="GRAPH_LAYOUT_UNSUPPORTED"};var tp;function oE(e,t){const n=tp;tp=e;try{return t()}finally{tp=n}}function KW(e){tp?.(Yb(e))}function Qr(e,t,n,i=false,r){const o=e.graphLayout;if(!o)return n();const s=[];let a,l=o.backend,c;if(o.backend==="agentic"){try{a=t()}catch(u){const f=u instanceof Mo;if(!f&&!(i&&u instanceof Qe)||o.fallback!=="elk")throw u;c=f?u.reason:"candidate failed mandatory geometry certification";s.push({backend:"agentic",outcome:f?"unsupported":"candidate-rejected",reason:c});a=n();l="elk"}}else{a=n()}s.push({backend:l,outcome:"selected"});const d={requested:o.backend,fallback:o.fallback??"none",selected:l,attempts:s,implementation:l==="agentic"?VW:"elk-layered@1",...c?{reason:c}:{}};r?.(a,d);KW(d);return a}function ba(e){switch(e){case"LR":return"RIGHT";case"RL":return"LEFT";case"BT":return"UP";case"TD":case"TB":default:return"DOWN"}}function Ns(e){return hr(e)?e:void 0}function sE(e,t){const n=e.$ref;if(typeof n!=="string"||!n.startsWith("#/"))return void 0;let i=t;for(const r of n.slice(2).split("/")){if(!hr(i))return void 0;i=i[r.replaceAll("~1","/").replaceAll("~0","~")]}return Ns(i)}function Ub(e,t,n){const i=sE(t,n);if(i)return Ub(e,i,n);const r=Array.isArray(t.anyOf)?t.anyOf.map(Ns).filter(o=>o!==void 0):[];if(r.length>0)return r.some(o=>Ub(e,o,n));switch(t.type){case"null":return e===null;case"string":return typeof e==="string";case"number":case"integer":return typeof e==="number";case"boolean":return typeof e==="boolean";case"array":return Array.isArray(e);case"object":return hr(e);default:return true}}function Vb(e,t,n=t,i=[],r={}){const o=r.diagnostics==="field";const s=(a,l,c,d,u)=>{const f=Ns(l.$defs)?l:c;const h=(S,x=true)=>[{path:d,message:S,generic:x}];if(l.$ref!==void 0){const S=sE(l,f);return S?s(a,S,f,d,u):h(o?"uses an unresolved schema reference":`uses unresolved schema reference ${String(l.$ref)}`,false)}const m=Array.isArray(l.anyOf)?l.anyOf.map(Ns).filter(S=>S!==void 0):[];if(m.length>0){const S=o?m.filter(b=>Ub(a,b,f)):[];const x=S.length>0?S:m;const M=x.map(b=>s(a,b,f,d,new Set(u)));if(!M.some(b=>b.length===0)){const b=l["x-agentic-mermaid-validation-expectation"];if((!o||S.length===0)&&typeof b==="string")return h(`must be ${b}`);return M.sort((C,P)=>C.length-P.length)[0]??h("must match an allowed shape")}}const p=Array.isArray(l.oneOf)?l.oneOf.map(Ns).filter(S=>S!==void 0):[];if(p.length>0&&!o){const S=p.filter(x=>s(a,x,f,d,new Set(u)).length===0);if(S.length!==1)return h(`must match exactly one allowed shape (matched ${S.length})`)}const g=o?(S,x)=>S===x:Object.is;if(Object.prototype.hasOwnProperty.call(l,"const")&&!g(a,l.const))return h(`must equal ${String(l.const)}`);if(Array.isArray(l.enum)&&!(o?l.enum.includes(a):l.enum.some(S=>Object.is(S,a)))){return h(`must be one of ${l.enum.map(String).join(" | ")}`)}const y=l.type;const w=y===void 0||y==="null"&&a===null||y==="string"&&typeof a==="string"||y==="number"&&typeof a==="number"&&Number.isFinite(a)||y==="integer"&&typeof a==="number"&&Number.isFinite(a)&&Number.isInteger(a)||y==="boolean"&&typeof a==="boolean"||y==="array"&&Array.isArray(a)||y==="object"&&hr(a);if(!w){const S=y==="number"?"a finite number":y==="integer"?"a finite integer":y==="object"?"a plain JSON object":y==="array"?"an array":y==="null"?"null":`a ${String(y)}`;return h(`must be ${S}`)}if(typeof a==="number"){if(typeof l.minimum==="number"&&a<l.minimum)return h(`must be at least ${l.minimum}`);if(typeof l.exclusiveMinimum==="number"&&a<=l.exclusiveMinimum)return h(`must be greater than ${l.exclusiveMinimum}`);if(typeof l.maximum==="number"&&a>l.maximum)return h(`must be at most ${l.maximum}`)}if(typeof a==="string"){if(typeof l.minLength==="number"&&a.length<l.minLength)return h(`must contain at least ${l.minLength} character${l.minLength===1?"":"s"}`);if(typeof l.pattern==="string"){let S;try{S=new RegExp(l.pattern,o?void 0:"u").test(a)}catch{return h("uses an invalid schema pattern",false)}if(!S)return h(r.patternMismatch?.(l)??`must match ${l.pattern}`)}if(typeof l.maxLength==="number"&&a.length>l.maxLength)return h(`must contain at most ${l.maxLength} characters`)}if(Array.isArray(a)&&y==="array"){if(typeof l.minItems==="number"&&a.length<l.minItems)return h(`must contain at least ${l.minItems} item${l.minItems===1?"":"s"}`);if(typeof l.maxItems==="number"&&a.length>l.maxItems)return h(`must contain at most ${l.maxItems} items`);if(u.has(a))return h("must be acyclic",false);const S=Ns(l.items);if(S){u.add(a);try{const x=a.flatMap((M,b)=>s(M,S,f,[...d,b],u));if(x.length>0)return x}finally{u.delete(a)}}}if(hr(a)&&(y==="object"||l.properties!==void 0||l.required!==void 0||l.additionalProperties!==void 0)){if(u.has(a))return h("must be acyclic",false);u.add(a);try{const S=Ns(l.properties)??{};const x=Array.isArray(l.required)?l.required.filter(b=>typeof b==="string"):[];const M=[];for(const b of x){if(!Object.prototype.hasOwnProperty.call(a,b))M.push({path:[...d,b],message:"is required",generic:false})}for(const[b,C]of Object.entries(a)){if(xm(b)){M.push({path:[...d,b],message:"uses a forbidden prototype key",generic:false});continue}const P=Ns(S[b]);if(P){M.push(...s(C,P,f,[...d,b],u));continue}if(l.additionalProperties===false){M.push({path:[...d,b],message:"is not allowed",generic:false});continue}const E=Ns(l.additionalProperties);if(E)M.push(...s(C,E,f,[...d,b],u))}if(M.length>0)return M}finally{u.delete(a)}}return r.validateRuntime?.(a,l,d)??[]};return s(e,t,n,i,new Set)}import{decodeXML as qu}from"entities";function aE(){let e=1e5;function t(){if(--e<0){const J=new Error("Configuration validation exceeded 100000 loop steps");J.name="MermaidConfigWorkLimitError";throw J}}var n=(J,ge,{depth:Ce=2}={})=>{let Me={depth:Ce};if(Array.isArray(ge)&&!Array.isArray(J))return ge.forEach(le=>n(J,le,Me)),J;else if(Array.isArray(ge)&&Array.isArray(J))return ge.forEach(le=>{if(!J.includes(le))J.push(le)}),J;if(J===void 0||J===null||Ce<=0)if(J!==void 0&&J!==null&&typeof J==="object"&&typeof ge==="object")return Object.assign(J,ge);else return ge;if(ge!==void 0&&ge!==null&&typeof J==="object"&&typeof ge==="object"){let le=J;Object.entries(ge).forEach(([we,ke])=>{if(typeof ke==="object"){if(ke===null)return;if(!Object.hasOwn(J,we))Object.defineProperty(J,we,{value:void 0,writable:true,enumerable:true,configurable:true});if(le[we]===void 0)le[we]=Array.isArray(ke)?[]:{};if(typeof le[we]==="object")le[we]=n(le[we],ke,{depth:Ce-1})}else if(typeof le[we]!=="object")if(Object.hasOwn(J,we))le[we]=ke;else Object.defineProperty(J,we,{value:ke,writable:true,enumerable:true,configurable:true})})}return J},i=n;var r=new Set(["flowchart","useMaxWidth","theme","look","titleTopMargin","subGraphTitleMargin","top","bottom","diagramPadding","htmlLabels","nodeSpacing","rankSpacing","curve","padding","wrappingWidth","minNodeWidth","inheritDir","swimlane","layout","lineHops","ignoreCrossLaneEdges","optimizeRanksByCrossings","automaticLaneOrdering","agentflow","sequence","hideUnusedParticipants","activationWidth","diagramMarginX","diagramMarginY","actorMargin","width","height","boxMargin","boxTextMargin","noteMargin","messageMargin","messageAlign","mirrorActors","forceMenus","bottomMarginAdj","rightAngles","showSequenceNumbers","actorFontSize","actorFontFamily","actorFontWeight","noteFontSize","noteFontFamily","noteFontWeight","noteAlign","messageFontSize","messageFontFamily","messageFontWeight","wrap","wrapPadding","labelBoxWidth","labelBoxHeight","messageFont","noteFont","actorFont","gantt","barHeight","barGap","topPadding","rightPadding","leftPadding","gridLineStartPadding","fontSize","sectionFontSize","numberSectionStyles","axisFormat","topAxis","displayMode","weekday","tickInterval","useWidth","journey","leftMargin","maxLabelWidth","taskFontSize","taskFontFamily","taskMargin","textPlacement","titleColor","titleFontFamily","titleFontSize","class","hideEmptyMembersBox","hierarchicalNamespaces","state","dividerMargin","sizeUnit","textHeight","titleShift","forkWidth","forkHeight","miniPadding","fontSizeFactor","labelHeight","edgeLengthFactor","compositTitleSize","radius","er","layoutDirection","minEntityWidth","minEntityHeight","entityPadding","stroke","fill","pie","textPosition","donutHole","legendPosition","highlightSlice","quadrantChart","chartWidth","chartHeight","titlePadding","quadrantPadding","xAxisLabelPadding","yAxisLabelPadding","xAxisLabelFontSize","yAxisLabelFontSize","quadrantLabelFontSize","quadrantTextTopPadding","pointTextPadding","pointLabelFontSize","pointRadius","xAxisPosition","yAxisPosition","quadrantInternalBorderStrokeWidth","quadrantExternalBorderStrokeWidth","xyChart","showDataLabel","showDataLabelOutsideBar","showTitle","showLegend","legendFontSize","legendPadding","xAxis","$ref","showLabel","labelFontSize","labelPadding","showTick","tickLength","tickWidth","showAxisLine","axisLineWidth","labelRotation","yAxis","chartOrientation","plotReservedSpacePercent","requirement","rect_fill","text_color","rect_border_size","rect_border_color","rect_min_width","rect_min_height","rect_padding","line_height","mindmap","colorBy","maxNodeWidth","layoutAlgorithm","ishikawa","kanban","sectionWidth","ticketBaseUrl","timeline","disableMulticolor","gitGraph","nodeLabel","x","y","mainBranchName","mainBranchOrder","showCommitLabel","showBranches","rotateCommitLabel","parallelCommits","arrowMarkerAbsolute","c4","c4ShapeMargin","c4ShapePadding","c4ShapeInRow","nextLinePaddingX","c4BoundaryInRow","personFontSize","personFontFamily","personFontWeight","external_personFontSize","external_personFontFamily","external_personFontWeight","systemFontSize","systemFontFamily","systemFontWeight","external_systemFontSize","external_systemFontFamily","external_systemFontWeight","system_dbFontSize","system_dbFontFamily","system_dbFontWeight","external_system_dbFontSize","external_system_dbFontFamily","external_system_dbFontWeight","system_queueFontSize","system_queueFontFamily","system_queueFontWeight","external_system_queueFontSize","external_system_queueFontFamily","external_system_queueFontWeight","boundaryFontSize","boundaryFontFamily","boundaryFontWeight","containerFontSize","containerFontFamily","containerFontWeight","external_containerFontSize","external_containerFontFamily","external_containerFontWeight","container_dbFontSize","container_dbFontFamily","container_dbFontWeight","external_container_dbFontSize","external_container_dbFontFamily","external_container_dbFontWeight","container_queueFontSize","container_queueFontFamily","container_queueFontWeight","external_container_queueFontSize","external_container_queueFontFamily","external_container_queueFontWeight","componentFontSize","componentFontFamily","componentFontWeight","external_componentFontSize","external_componentFontFamily","external_componentFontWeight","component_dbFontSize","component_dbFontFamily","component_dbFontWeight","external_component_dbFontSize","external_component_dbFontFamily","external_component_dbFontWeight","component_queueFontSize","component_queueFontFamily","component_queueFontWeight","external_component_queueFontSize","external_component_queueFontFamily","external_component_queueFontWeight","person_bg_color","person_border_color","external_person_bg_color","external_person_border_color","system_bg_color","system_border_color","system_db_bg_color","system_db_border_color","system_queue_bg_color","system_queue_border_color","external_system_bg_color","external_system_border_color","external_system_db_bg_color","external_system_db_border_color","external_system_queue_bg_color","external_system_queue_border_color","container_bg_color","container_border_color","container_db_bg_color","container_db_border_color","container_queue_bg_color","container_queue_border_color","external_container_bg_color","external_container_border_color","external_container_db_bg_color","external_container_db_border_color","external_container_queue_bg_color","external_container_queue_border_color","component_bg_color","component_border_color","component_db_bg_color","component_db_border_color","component_queue_bg_color","component_queue_border_color","external_component_bg_color","external_component_border_color","external_component_db_bg_color","external_component_db_border_color","external_component_queue_bg_color","external_component_queue_border_color","personFont","external_personFont","systemFont","external_systemFont","system_dbFont","external_system_dbFont","system_queueFont","external_system_queueFont","containerFont","external_containerFont","container_dbFont","external_container_dbFont","container_queueFont","external_container_queueFont","componentFont","external_componentFont","component_dbFont","external_component_dbFont","component_queueFont","external_component_queueFont","boundaryFont","sankey","linkColor","nodeAlignment","showValues","prefix","suffix","nodeWidth","nodePadding","labelStyle","nodeColors","block","packet","rowHeight","bitWidth","bitsPerRow","showBits","bitOrder","paddingX","paddingY","treeView","rowIndent","lineThickness","showIcons","defaultIconPack","filenameIcons","extensionIcons","architecture","iconSize","randomize","nodeSeparation","idealEdgeLengthMultiplier","edgeElasticity","numIter","seed","eventmodeling","radar","marginTop","marginRight","marginBottom","marginLeft","axisScaleFactor","axisLabelFactor","curveTension","usecase","usecaseFontSize","usecaseFontFamily","usecaseFontWeight","colorScheme","venn","useDebugLayout","cynefin","showDomainDescriptions","boundaryAmplitude","handDrawnSeed","maxTextSize","maxEdges","darkMode","fontFamily","logLevel","securityLevel","startOnLoad","legacyMathML","forceLegacyMathML","deterministicIds","markdownAutoWrap","suppressErrorRendering","deterministicIDSeed","elk","mergeEdges","straightenEdges","preset","nodePlacementStrategy","layeringStrategy","cycleBreakingStrategy","layeringLayerBound","nodePlacementAlignment","forceNodeModelOrder","considerModelOrder","keepEntryNodeOnTop","orientFeedbackEdges","themeCSS","themeVariables","background","primaryColor","secondaryColor","tertiaryColor","primaryBorderColor","secondaryBorderColor","tertiaryBorderColor","primaryTextColor","secondaryTextColor","tertiaryTextColor","lineColor","textColor","mainBkg","secondBkg","border1","border2","arrowheadColor","labelBackground","THEME_COLOR_LIMIT","strokeWidth","nodeBkg","nodeBorder","clusterBkg","clusterBorder","defaultLinkColor","edgeLabelBackground","actorBorder","actorBkg","actorTextColor","actorLineColor","signalColor","signalTextColor","labelBoxBkgColor","labelBoxBorderColor","labelTextColor","loopTextColor","noteBorderColor","noteBkgColor","noteTextColor","activationBorderColor","activationBkgColor","sequenceNumberColor","sectionBkgColor","altSectionBkgColor","sectionBkgColor2","excludeBkgColor","taskBorderColor","taskBkgColor","taskTextLightColor","taskTextColor","taskTextDarkColor","taskTextOutsideColor","taskTextClickableColor","activeTaskBorderColor","activeTaskBkgColor","gridColor","doneTaskBkgColor","doneTaskBorderColor","critBorderColor","critBkgColor","todayLineColor","vertLineColor","fontWeight","personBorder","personBkg","archEdgeColor","archEdgeArrowColor","archEdgeWidth","archGroupBorderColor","archGroupBorderWidth","rowOdd","rowEven","labelColor","errorBkgColor","errorTextColor","useGradient","gradientStart","gradientStop","dropShadow","cScale0","cScale1","cScale2","cScale3","cScale4","cScale5","cScale6","cScale7","cScale8","cScale9","cScale10","cScale11","cScalePeer1","cScalePeer2","cScalePeer0","cScalePeer3","cScalePeer4","cScalePeer5","cScalePeer6","cScalePeer7","cScalePeer8","cScalePeer9","cScalePeer10","cScalePeer11","cScaleInv0","cScaleInv1","cScaleInv2","cScaleInv3","cScaleInv4","cScaleInv5","cScaleInv6","cScaleInv7","cScaleInv8","cScaleInv9","cScaleInv10","cScaleInv11","surface0","surfacePeer0","surface1","surfacePeer1","surface2","surfacePeer2","surface3","surfacePeer3","surface4","surfacePeer4","scaleLabelColor","flowContainerStroke","rectBkgColor","transitionColor","transitionLabelColor","stateLabelColor","stateBkg","labelBackgroundColor","compositeBackground","altBackground","compositeTitleBackground","compositeBorder","innerEndBackground","specialStateColor","classText","fillType0","fillType1","fillType2","fillType3","fillType4","fillType5","fillType6","fillType7","pie1","pie2","pie3","pie4","pie5","pie6","pie7","pie8","pie9","pie10","pie11","pie12","pieTitleTextSize","pieTitleTextColor","pieSectionTextSize","pieSectionTextColor","pieLegendTextSize","pieLegendTextColor","pieStrokeColor","pieStrokeWidth","pieOuterStrokeWidth","pieOuterStrokeColor","pieOpacity","venn1","venn2","venn3","venn4","venn5","venn6","venn7","venn8","vennTitleTextColor","vennSetTextColor","domainFontSize","itemFontSize","boundaryColor","boundaryWidth","cliffColor","cliffWidth","arrowColor","arrowWidth","complexBg","complicatedBg","chaoticBg","clearBg","confusionBg","quadrant1Fill","quadrant2Fill","quadrant3Fill","quadrant4Fill","quadrant1TextFill","quadrant2TextFill","quadrant3TextFill","quadrant4TextFill","quadrantPointFill","quadrantPointTextFill","quadrantXAxisTextFill","quadrantYAxisTextFill","quadrantInternalBorderStrokeFill","quadrantExternalBorderStrokeFill","quadrantTitleFill","axisColor","axisStrokeWidth","axisLabelFontSize","curveOpacity","curveStrokeWidth","graticuleColor","graticuleStrokeWidth","graticuleOpacity","legendBoxSize","wardleyEvolutionColor","wardley","backgroundColor","axisTextColor","componentFill","componentStroke","componentLabelColor","linkStroke","evolutionStroke","annotationStroke","annotationTextColor","annotationFill","dataLabelColor","legendTextColor","xAxisTitleColor","xAxisLabelColor","xAxisTickColor","xAxisLineColor","yAxisTitleColor","yAxisLabelColor","yAxisTickColor","yAxisLineColor","plotColorPalette","requirementBackground","requirementBorderColor","requirementBorderSize","requirementTextColor","relationColor","relationLabelBackground","relationLabelColor","git0","git1","git2","git3","git4","git5","git6","git7","gitInv0","gitInv1","gitInv2","gitInv3","gitInv4","gitInv5","gitInv6","gitInv7","gitBranchLabel0","gitBranchLabel1","gitBranchLabel2","gitBranchLabel3","gitBranchLabel4","gitBranchLabel5","gitBranchLabel6","gitBranchLabel7","tagLabelColor","tagLabelBackground","tagLabelBorder","tagLabelFontSize","commitLabelColor","commitLabelBackground","commitLabelFontSize","emUiFill","emUiStroke","emProcessorFill","emProcessorStroke","emReadModelFill","emReadModelStroke","emCommandFill","emCommandStroke","emEventFill","emEventStroke","emSwimlaneBackgroundOdd","emSwimlaneBackgroundStroke","emArrowhead","emRelationStroke","attributeBackgroundColorOdd","attributeBackgroundColorEven","cScaleLabel0","cScaleLabel3","cScaleLabel1","cScaleLabel2","cScaleLabel4","cScaleLabel5","cScaleLabel6","cScaleLabel7","cScaleLabel8","cScaleLabel9","cScaleLabel10","cScaleLabel11","railroad","terminalFill","terminalStroke","terminalTextColor","nonTerminalFill","nonTerminalStroke","nonTerminalTextColor","markerFill","commentFill","commentStroke","commentTextColor","specialFill","specialStroke","ruleNameColor","treemap","nodeHeight","borderWidth","valueFontSize","valueFormat"]);var o={trace(){},debug(){},info(){},warn(){},error(){},fatal(){}};var s={nodeColors:/^#[\da-f]{3,8}$|^rgb\([\d\s%,.]+\)$|^hsl\([\d\s%,.]+\)$|^[a-z]+$/i,filenameIcons:/^[\w-]+(?::[\w-]+)?$/,extensionIcons:/^[\w-]+(?::[\w-]+)?$/},a=(J,ge)=>{for(let Ce of Object.keys(J)){t();let Me=J[Ce];if(Ce.startsWith("__")||Ce.includes("proto")||Ce.includes("constr")||typeof Me!=="string"||!ge.test(Me))o.debug("sanitize deleting dictionary entry:",Ce,Me),delete J[Ce]}},l=J=>{if(o.debug("sanitizeDirective called with",J),typeof J!=="object"||J==null)return;if(Array.isArray(J)){J.forEach(ge=>l(ge));return}for(let ge of Object.keys(J)){t();if(o.debug("Checking key",ge),ge.startsWith("__")||ge.includes("proto")||ge.includes("constr")||!r.has(ge)||J[ge]==null){o.debug("sanitize deleting key: ",ge),delete J[ge];continue}if(typeof J[ge]==="object"){let Me=s[ge];if(Me)a(J[ge],Me);else o.debug("sanitizing object",ge),l(J[ge]);continue}let Ce=["themeCSS","fontFamily","altFontFamily"];for(let Me of Ce){t();if(ge.includes(Me))o.debug("sanitizing css option",ge),J[ge]=c(J[ge])}}if(J.themeVariables)for(let ge of Object.keys(J.themeVariables)){t();let Ce=J.themeVariables[ge];if(Ce?.match&&!Ce.match(/^[\d "#%(),.;A-Za-z]+$/))J.themeVariables[ge]=""}o.debug("After sanitization",J)},c=J=>{let ge=0,Ce=0;for(let Me of J){t();if(ge<Ce)return"{ /* ERROR: Unbalanced CSS */ }";if(Me==="{")ge++;else if(Me==="}")Ce++}if(ge!==Ce)return"{ /* ERROR: Unbalanced CSS */ }";return J};function d(){}function u(J){return J==null||typeof J!=="object"&&typeof J!=="function"}function f(J){return Object.getOwnPropertySymbols(J).filter(ge=>Object.prototype.propertyIsEnumerable.call(J,ge))}var h=typeof globalThis==="object"&&globalThis||typeof window==="object"&&window||typeof self==="object"&&self||typeof global==="object"&&global||(function(){return this})();function m(J){return typeof h.Buffer<"u"&&h.Buffer.isBuffer(J)}function p(J){return J==="__proto__"}function g(J){if(typeof J!=="object")return false;if(J==null)return false;if(Object.getPrototypeOf(J)===null)return true;if(Object.prototype.toString.call(J)!=="[object Object]"){var ge;let Me=J[Symbol.toStringTag];if(Me==null)return false;if(!((ge=Object.getOwnPropertyDescriptor(J,Symbol.toStringTag))===null||ge===void 0?void 0:ge.writable))return false;return J.toString()===`[object ${Me}]`}let Ce=J;while(Object.getPrototypeOf(Ce)!==null){t();Ce=Object.getPrototypeOf(Ce)}return Object.getPrototypeOf(J)===Ce}function y(J){return ArrayBuffer.isView(J)&&!(J instanceof DataView)}function w(J){return y(J)}function S(J){if(J==null)return J===void 0?"[object Undefined]":"[object Null]";return Object.prototype.toString.call(J)}var x="[object RegExp]",M="[object String]",b="[object Number]",C="[object Boolean]",P="[object Arguments]",E="[object Symbol]",k="[object Date]",v="[object Map]",T="[object Set]",A="[object Array]";var R="[object ArrayBuffer]",I="[object Object]";var L="[object DataView]",$="[object Uint8Array]",B="[object Uint8ClampedArray]",F="[object Uint16Array]",z="[object Uint32Array]";var _="[object Int8Array]",H="[object Int16Array]",D="[object Int32Array]";var j="[object Float32Array]",W="[object Float64Array]";var O=Object.prototype.hasOwnProperty;function N(J,ge){return O.call(J,ge)}function G(J){return m(J)}function Y(J,ge){return q(J,void 0,J,new Map,ge)}function q(J,ge,Ce,Me,le){if(le!=null){let ke=le(J,ge,Ce,Me);if(ke!==void 0)return ke}if(u(J))return J;if(Me.has(J))return Me.get(J);if(Array.isArray(J)){let ke=Array(J.length);Me.set(J,ke);for(let Le=0;Le<J.length;Le++){t();ke[Le]=q(J[Le],Le,Ce,Me,le)}if(N(J,"index"))ke.index=J.index;if(N(J,"input"))ke.input=J.input;return ke}if(J instanceof Date)return new Date(J.getTime());if(J instanceof RegExp){let ke=new RegExp(J.source,J.flags);return ke.lastIndex=J.lastIndex,ke}if(J instanceof Map){let ke=new Map;return Me.set(J,ke),J.forEach((Le,Fe)=>{ke.set(Fe,q(Le,Fe,Ce,Me,le))}),ke}if(J instanceof Set){let ke=new Set;return Me.set(J,ke),J.forEach(Le=>{ke.add(q(Le,void 0,Ce,Me,le))}),ke}if(G(J))return J.subarray();if(w(J)){let ke=new(Object.getPrototypeOf(J)).constructor(J.length);Me.set(J,ke);for(let Le=0;Le<J.length;Le++){t();ke[Le]=q(J[Le],Le,Ce,Me,le)}return ke}if(J instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&J instanceof SharedArrayBuffer)return J.slice(0);if(J instanceof DataView){let ke=new DataView(J.buffer.slice(0),J.byteOffset,J.byteLength);return Me.set(J,ke),V(ke,J,Ce,Me,le),ke}if(typeof File<"u"&&J instanceof File){let ke=new File([J],J.name,{type:J.type});return Me.set(J,ke),V(ke,J,Ce,Me,le),ke}if(typeof Blob<"u"&&J instanceof Blob){let ke=new Blob([J],{type:J.type});return Me.set(J,ke),V(ke,J,Ce,Me,le),ke}let we=S(J);if(we==="[object Error]"){if(J===Ce)return{};return J}switch(we){case b:case M:case C:{let ke=new J.constructor(J.valueOf());return Me.set(J,ke),V(ke,J,Ce,Me,le),ke}case P:{let ke={};return Me.set(J,ke),V(ke,J,Ce,Me,le),ke.length=J.length,ke[Symbol.iterator]=J[Symbol.iterator],ke}}if(typeof J==="object"&&ne(we)){let ke=we==="[object Object]"&&typeof J.constructor!=="function"?{}:Object.create(Object.getPrototypeOf(J));return Me.set(J,ke),V(ke,J,Ce,Me,le),ke}return J}function V(J,ge,Ce,Me,le){let we=[...Object.keys(ge),...f(ge)];for(let ke=0;ke<we.length;ke++){t();let Le=we[ke],Fe=Object.getOwnPropertyDescriptor(J,Le);if(Fe==null||Fe.writable)J[Le]=q(ge[Le],Le,Ce,Me,le)}}function ne(J){switch(J){case P:case A:case R:case L:case C:case k:case j:case W:case _:case H:case D:case v:case b:case I:case x:case T:case M:case E:case $:case B:case F:case z:return true;default:return false}}function X(J){return Y(J)}function U(J){return J!==null&&typeof J==="object"&&S(J)==="[object Arguments]"}function K(J){return typeof J==="object"&&J!==null}function Z(J){return Number.isSafeInteger(J)&&J>=0}function Q(J){return J!=null&&typeof J!=="function"&&Z(J.length)}function se(J){return K(J)&&Q(J)}function te(J){if(u(J))return J;if(Array.isArray(J)||y(J)||J instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&J instanceof SharedArrayBuffer)return J.slice(0);let ge=Object.getPrototypeOf(J);if(ge==null)return Object.assign(Object.create(ge),J);let Ce=ge.constructor;if(J instanceof Date||J instanceof Map||J instanceof Set)return new Ce(J);if(J instanceof RegExp){let Me=new Ce(J);return Me.lastIndex=J.lastIndex,Me}if(J instanceof DataView)return new Ce(J.buffer.slice(0));if(J instanceof Error){let Me;if(typeof AggregateError<"u"&&J instanceof AggregateError)Me=new Ce(J.errors,J.message,{cause:J.cause});else Me=new Ce(J.message,{cause:J.cause});return Me.stack=J.stack,Object.assign(Me,J),Me}if(typeof File<"u"&&J instanceof File)return new Ce([J],J.name,{type:J.type,lastModified:J.lastModified});if(typeof J==="object"){let Me=Object.create(ge);return Object.assign(Me,J)}return J}function ee(J,...ge){let Ce=ge.slice(0,-1),Me=ge[ge.length-1],le=J;for(let we=0;we<Ce.length;we++){t();let ke=Ce[we];le=ae(le,ke,Me,new Map)}return le}function ae(J,ge,Ce,Me){if(u(J))J=Object(J);if(ge==null||typeof ge!=="object")return J;if(Me.has(ge))return te(Me.get(ge));if(Me.set(ge,J),Array.isArray(ge)){ge=ge.slice();for(let we=0;we<ge.length;we++){t();if(!(we in ge))ge[we]=void 0}}let le=[...Object.keys(ge),...f(ge)];for(let we=0;we<le.length;we++){t();let ke=le[we];if(p(ke))continue;let Le=ge[ke],Fe=J[ke];if(U(Le))Le=Object.assign({},Le);if(U(Fe))Fe=Object.assign({},Fe);if(m(Le))Le=X(Le);if(Array.isArray(Le))if(Array.isArray(Fe)){let We=[],ce=Reflect.ownKeys(Fe);for(let Ae=0;Ae<ce.length;Ae++){t();let Pe=ce[Ae];We[Pe]=Fe[Pe]}Fe=We}else if(se(Fe)){let We=[];for(let ce=0;ce<Fe.length;ce++){t();We[ce]=Fe[ce]}Fe=We}else Fe=[];let Oe=Ce(Fe,Le,ke,J,ge,Me);if(Oe!==void 0)J[ke]=Oe;else if(Array.isArray(Le))J[ke]=ae(Fe,Le,Ce,Me);else if(K(Fe)&&K(Le)&&(g(Fe)||g(Le)||w(Fe)||w(Le)))J[ke]=ae(Fe,Le,Ce,Me);else if(Fe==null&&g(Le))J[ke]=ae({},Le,Ce,Me);else if(Fe==null&&w(Le))J[ke]=X(Le);else if(Fe===void 0||Le!==void 0)J[ke]=Le}return J}function ie(J,...ge){return ee(J,...ge,d)}var oe={debug(){},error(){}},ue="",ye=false,Se=()=>ue;function Te(J,ge){if(!J||!ge||typeof J!=="object"||typeof ge!=="object")return;for(let Ce of Object.keys(ge)){t();if(typeof J[Ce]==="string"&&typeof ge[Ce]==="string")ge[Ce]=J[Ce];else Te(J[Ce],ge[Ce])}}function Ie(J){let ge=ye?structuredClone(J):void 0;if(l(J),ge)Te(ge,J)}var Ee=/%{2}{\s*(?:(\w+)\s*:|(\w+))\s*(?:(\w+)|((?:(?!}%{2}).|\r?\n)*))?\s*(?:}%{2})?/gi,ve=/\s*(?:(\w+)(?=:):|(\w+))\s*(?:(\w+)|((?:(?!}%{2}).|\r?\n)*))?\s*(?:}%{2})?/gi,$e=function(J,ge=null){try{let Ce=new RegExp(`[%]{2}(?![{]${ve.source})(?=[}][%]{2}).*
3
+ `,"ig");J=J.trim().replace(Ce,"").replace(/'/gm,'"'),oe.debug(`Detecting diagram directive${ge!==null?" type:"+ge:""} based on the text:${J}`);let Me,le=[];while((Me=Ee.exec(J))!==null){t();if(Me.index===Ee.lastIndex)Ee.lastIndex++;if(Me&&!ge||ge&&Me[1]?.match(ge)||ge&&Me[2]?.match(ge)){let we=Me[1]?Me[1]:Me[2],ke=Me[3]?Me[3].trim():Me[4]?JSON.parse(Me[4].trim()):null;le.push({type:we,args:ke})}}if(le.length===0)return{type:J,args:null};return le.length===1?le[0]:le}catch(Ce){return oe.error(`ERROR: ${Ce.message} - Unable to parse directive type: '${ge}' based on the text: '${J}'`),{type:void 0,args:null}}},De=function(J,ge){let Ce=$e(J,/(?:init\b)|(?:initialize\b)/),Me={};if(Array.isArray(Ce)){let ke=Ce.map(Le=>Le.args);Ie(ke),Me=i(Me,[...ke])}else Me=Ce.args;if(!Me)return;let le=Se(J,ge),we="config";if(Me[we]!==void 0){if(le==="flowchart-v2")le="flowchart";Me[le]=Me[we],delete Me[we]}return Me},fe=function(J){return J.replace(Ee,"")},me={detectInit:De,detectDirective:$e},de=J=>{let ge=me.detectInit(J)??{},Ce=me.detectDirective(J,"wrap");if(Array.isArray(Ce))ge.wrap=Ce.some(({type:Me})=>Me==="wrap");else if(Ce?.type==="wrap")ge.wrap=true;return{text:fe(J),directive:ge}};function be(J,ge,Ce=true){if(!/^\w+$/.test(J))throw Error("Invalid directive name");if(!Ce)return"%%{"+J+"}%%";let Me=(Object.is(ge,-0)?"-0":JSON.stringify(ge)).replace(/[&<>#%'\u2028\u2029]/g,Le=>"\\u"+Le.charCodeAt(0).toString(16).padStart(4,"0")),le="%%{"+J+": "+Me+"}%%";Ee.lastIndex=0;let we=Ee.exec(le);Ee.lastIndex=0;let ke=$e(le,J);if(!we||we[0]!==le||!Object.is(typeof ke.args,typeof ge))throw Error("init argument has no complete pinned scalar token");return le}function pe(J){return be("init",J)}function Re(J,ge,Ce,Me=false){ue=Ce,ye=Me;try{return ie({},structuredClone(J),de(ge).directive)}finally{ye=false}}function Ne(J,ge,Ce,Me=false,le=false){ue=Ce,ye=le;try{let we=ge.map(pe).join(`
4
+ `)+(Me?`
5
+ %%{wrap}%%`:"");return Re(J,we,Ce,le)}finally{ye=false}}return{configDirective:be,initDirective:pe,mergeConfig:Ne,mergeConfigSource:Re}}function lE(...e){return aE().configDirective(...e)}function cE(...e){return aE().mergeConfigSource(...e)}function dE(e){const t=e.split(/[;:\s]/,1)[0].replace(/-(?:v2|beta)$/i,"").toLowerCase();if(/^c4(?:context|container|component|dynamic|deployment)?$/.test(t))return"c4";return{graph:"flowchart-v2",flowchart:"flowchart-v2",class:"classDiagram",classdiagram:"classDiagram",state:"stateDiagram",statediagram:"stateDiagram",sequencediagram:"sequence",erdiagram:"er",requirementdiagram:"requirement",quadrant:"quadrantChart",quadrantchart:"quadrantChart",gitgraph:"gitGraph"}[t]??t}var np=/^note\s+(left|right)\s+of\s+([\w\p{L}-]+)\s*$/iu;var Kb=/^note\s+(left|right)\s+of\s+([\w\p{L}-]+)\s+([^\s:].*)$/iu;var Gu=/^end\s+note$/i;function uE(e,t=false){for(let n=0;n<e.length;n++){const i=e[n];if(i==='"'){t=!t;continue}if(t)continue;if(i==="%"&&e[n+1]==="%")return{comment:n,quoted:t};if(i!==":"||e[n-1]===":"||e[n+1]===":")continue;const r=e.slice(0,n).trim();if(/^[\w\p{L}-]+$/u.test(r)||r.includes("-->")||/^note\s+(?:left|right)\s+of\s+[\w\p{L}-]+$/iu.test(r))return{comment:-1,quoted:false}}return{comment:-1,quoted:t}}function JW(e){return uE(e).comment}function fE(e){const t=JW(e);return(t<0?e:e.slice(0,t)).trim()}function Sa(e){const t=[];const n=[];for(let o=e.length-1,s=false,a=false;o>=0;o--){t[o]=s;n[o]=a;s||=Gu.test(fE(e[o]));a||=e[o].includes('"')}let i=false;let r=false;return e.map((o,s)=>{const a=r;const l=uE(o,!i&&a);const c=(l.comment<0?o:o.slice(0,l.comment)).trim();const d=i&&!Gu.test(c);const u=d?o.trim():c;let f=false;if(i){if(!d)i=false}else if(!a&&(np.test(u)||t[s]&&Kb.test(u))){i=f=true}r=!i&&l.quoted&&n[s]&&(a||/^(?:state|note)\s/i.test(u));const h=!d&&l.comment>0&&!/\s/.test(o[l.comment-1]);return{text:u,commentIndex:d?-1:l.comment,noteBody:d,noteOpen:f,openQuote:r,commentGlued:h}})}function wa(e,t,n,i){if(e[t]!=="{")throw new RangeError(`scanMetadataBlock: no "{" at ${t}`);if(n==="sequence"){const o=e.indexOf("}",t+1);if(o<0)return{kind:"unclosed"};if(o===t+1)return{kind:"invalid",message:"empty @{} participant metadata"};return{kind:"closed",body:e.slice(t+1,o).trim(),end:o}}let r="";for(let o=t+1;o<e.length;o++){const s=e[o];if(s==='"'){const a=e.indexOf('"',o+1);if(a<0)return{kind:"unclosed"};const l=o+1;r+=`"${e.slice(l,a).replace(/\n\s*/g,(c,d)=>{i?.(l+d,l+d+c.length,5);return"<br/>"})}"`;o=a}else if(s==="}"){return{kind:"closed",body:r,end:o}}else if(s==="^"){return{kind:"invalid",message:'unquoted "^" in @{} metadata'}}else{r+=s}}return{kind:"unclosed"}}function Hu(e){return/^(?:%(?!\{)|#(?![a-z\d]+;))/i.test(e.trimStart())}function Jb(e){return mE(e,QW)}function Qb(e){return mE(e,ZW)}function QW(e){return e}function ZW(e,t,n){return{raw:e,line:t,column:n,endColumn:n+e.length}}function mE(e,t){const n=[];let i=false;for(const[r,o]of e.entries()){let s=0;const a=!o.trim();const l=(h,m)=>{if(!h.trim()&&!a)return;const p=s+m;n.push(t(h,r,p))};let c=o;if(i){const h=c.indexOf("}");if(h<0){l(c,0);continue}l(c.slice(0,h+1),0);c=c.slice(h+1);s=h+1;i=false}let d=0;let u=false;let f=-1;for(let h=0;h<c.length;h++){if(h===d){const p=c.slice(d).trimStart();const g=/^accDescr\s*:?\s*\{/i.exec(p);if(g){const w=c.indexOf("{",d);const S=c.indexOf("}",w+1);if(S<0){l(c.slice(d),d);i=true;u=true;break}l(c.slice(d,S+1),d);d=S+1;h=S;continue}const y=/^\s*end(?=[^\S\r\n]+\S)/i.exec(c.slice(d));if(y){l(c.slice(d,d+y[0].length),d);d+=y[0].length;h=d-1;continue}if(/^(?:rect|box)\s+#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8});/i.test(p)||Hu(p)||/^(?:accTitle|accDescr)(?:\s*:|\s+)/i.test(p)){l(c.slice(d),d);u=true;break}}const m=c[h];if(m==="@"&&c[h+1]==="{"&&/^(?:participant|actor)\b/i.test(c.slice(d,h).trimStart())){const p=wa(c,h+1,"sequence");h=p.kind==="closed"?p.end:p.kind==="unclosed"?c.length:h+1;continue}if(m==="#"&&f<0)f=h;if(m==="#"&&!pE(c,h)&&!(/^\s*(?:rect|box)\s*$/i.test(c.slice(d,h))&&/^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})(?=\s|;|$)/i.test(c.slice(h)))){l(c.slice(d,h),d);l(c.slice(h),h);u=true;break}if(c[h]!==";"||ez(c,d,h,f))continue;l(c.slice(d,h),d);d=h+1;f=-1}if(!u)l(c.slice(d),d)}return n}function ez(e,t,n,i){let r=n-1;while(r>=t&&/[a-z\d]/i.test(e[r]))r--;if(e[r]!=="#"||r===n-1)return false;if(!pE(e,r))return false;if(i===r&&/^\s*(?:rect|box)\s+#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(e.slice(t,n)))return false;return true}var hE=/#(?:\d+|[a-z][a-z\d]*);/iy;function pE(e,t){hE.lastIndex=t;return hE.test(e)}import{Document as tz,Scalar as yE,isMap as xE,isScalar as tS,parse as nz,parseDocument as bE,visit as ip}from"yaml";import{stringifyNumber as SE}from"yaml/util";var nS=/^[-+]?(?:0b[01]+|0x[0-9a-fA-F]+|0o[0-7]+|[0-9]+)$/;var iS=/^(?:[-+]?[0-9]+(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?|\.[0-9]+(?:[eE][-+]?[0-9]+)?|[-+]?\.(?:inf|Inf|INF)|\.(?:nan|NaN|NAN))$/;function iz(e,t){if(!nS.test(e)){t(`cannot resolve ${JSON.stringify(e)} as an integer`);return Number.NaN}let n=e;const i=n[0]==="-"?-1:1;if(n[0]==="-"||n[0]==="+")n=n.slice(1);const r=n[1]==="b"?2:n[1]==="x"?16:n[1]==="o"?8:10;const o=i*Number.parseInt(r===10?n:n.slice(2),r);return Number.isFinite(o)?o:e}function rz(e,t){if(!iS.test(e)){t(`cannot resolve ${JSON.stringify(e)} as a float`);return Number.NaN}let n=e.toLowerCase();const i=n[0]==="-"?-1:1;if(n[0]==="-"||n[0]==="+")n=n.slice(1);if(n===".inf")return i*Number.POSITIVE_INFINITY;if(n===".nan")return Number.NaN;const r=i*Number.parseFloat(n);return Number.isFinite(r)?r:e}var Zb={identify:e=>typeof e==="number"&&Number.isInteger(e),default:true,tag:"tag:yaml.org,2002:int",test:nS,resolve:iz,stringify:SE};var eS={identify:e=>typeof e==="number",default:true,tag:"tag:yaml.org,2002:float",test:iS,resolve:rz,stringify:SE};var wE={schema:"core",customTags:e=>[...e.filter(t=>typeof t==="string"||t.tag!==Zb.tag&&t.tag!==eS.tag),Zb,eS]};var oz="Comments must be separated from other tokens by white space characters";function sz(e,t){return e.code==="MISSING_CHAR"&&e.message.startsWith(oz)&&!/[|>][-+0-9]*$/.test(t.slice(0,e.pos[0]))}function az(e,t){let n=false;ip(e,{Pair(i,r,o){const s=o[o.length-1];const a=r.key;const l=tS(a)&&a.source===""&&a.range?.[0]===a.range?.[1]?a.range[0]:-1;if(l>=0&&xE(s)&&!s.flow&&/^[ \t]*:/.test(t.slice(l))&&/^[ \t]*$/.test(t.slice(t.lastIndexOf("\n",l-1)+1,l))){n=true;return ip.BREAK}return void 0}});return n}var lz=/(?:^|[[{,]|[:?-][ \t])[ \t]*$/;var cz=/(?:^|[:?-][ \t])[ \t]*[|>][-+0-9]*[ \t]*(?:#.*)?$/;function dz(e){const t=e.split("\n");const n=a=>a.match(/^[ \t]*/)[0];let i;let r="";let o;let s=false;for(let a=0;a<t.length;a++){const l=t[a];if(o!==void 0){if(l.trim()===""||n(l).length>o)continue;o=void 0}if(i){t[a]=r+l;s=true}let c=0;for(;c<l.length;c++){const d=l[c];if(i==='"'){if(d==="\\")c++;else if(d==='"')i=void 0}else if(i==="'"){if(d==="'"&&l[c+1]==="'")c++;else if(d==="'")i=void 0}else if(d==="#"&&(c===0||/[ \t]/.test(l[c-1]))){break}else if((d==='"'||d==="'")&&lz.test(l.slice(0,c))){i=d;r=`${n(l)} `}}if(!i&&cz.test(l))o=n(l).length}return s?t.join("\n"):void 0}function gE(e){const t=bE(e,{...wE,logLevel:"silent"});const n=t.errors.find(r=>!sz(r,e))??t.warnings[0];if(n)return{ok:false,message:n.message.split("\n")[0]};if(az(t,e))return{ok:false,message:"a block mapping entry has no key"};let i;ip(t,{Scalar(r,o){const s=o.tag===Zb.tag?nS:o.tag===eS.tag?iS:void 0;if(s&&(!s.test(o.source??"")||typeof o.value!=="number")){i=`cannot resolve ${JSON.stringify(o.source)} as ${o.tag}`}},Pair(r,o){if(tS(o.key)&&o.key.value===null)o.key=new yE("null")}});if(i)return{ok:false,message:i};try{return{ok:true,value:t.toJS()}}catch(r){return{ok:false,message:r instanceof Error?r.message:String(r)}}}function $s(e){const t=e.length>0&&!/[\n\r]$/.test(e)?`${e}
6
+ `:e;const n=gE(t);if(n.ok)return n;const i=dz(t);const r=i===void 0?void 0:gE(i);return r?.ok?r:n}function rS(e){return nz(e)}function oS(e){const t=bE(e,{keepSourceTokens:true});const n=[];if(!xE(t.contents))return n;for(const i of t.contents.items){if(!tS(i.key)||!i.key.range||!i.value||!("range"in i.value)||!i.value.range)continue;const r=i.srcToken?.sep?.find(o=>o.type==="anchor"||o.type==="tag");n.push({name:String(i.key.value),keyStart:i.key.range[0],keyEnd:i.key.range[1],valueStart:r?.offset??i.value.range[0],valueEnd:i.value.range[1]})}return n}function uz(e){const t=new tz(e,wE);ip(t,{Scalar(n,i){if(typeof i.value==="string"&&/(?:^|\n)[ \t]+\r?(?:\n|$)/.test(i.value)){i.type=yE.QUOTE_DOUBLE}}});return t.toString()}import{decodeXML as fz}from"entities";function Fl(e,t){const n=/[\r\n]/g;n.lastIndex=t;return n.exec(e)?.index??-1}var ju=Object.freeze([]);var hz=Object.freeze([]);var mz=Object.freeze([]);function ME(e){return Object.freeze({originalText:e,text:e,payloadText:e,authoredPayloadText:e,lineText:e,upstreamText:e,prepassedText:e,changes:hz,mappings:ju,lineMappings:ju,upstreamMappings:ju,prepassedMappings:ju})}function Yu(e,t,n){if(t.length===0)return e;const i=[];const r=[];let o=0;let s=0;for(const l of t){i.push(e.text.slice(o,l.start),l.text);const c=l.start+s;r.push(Object.freeze({originalStart:l.start,originalEnd:l.end,cleanedStart:c,cleanedEnd:c+l.text.length}));s+=l.text.length-(l.end-l.start);o=l.end}i.push(e.text.slice(o));const a=e.mappings.length;return{text:i.join(""),mappings:[...e.mappings,Object.freeze({edits:Object.freeze(r)})],changes:[...e.changes,...r.map(l=>({reason:n,stage:a,edit:l}))]}}function CE(e,t,n){const i=[];for(const r of e.matchAll(t)){const o=n(r[0]);if(o!==r[0])i.push({start:r.index,end:r.index+r[0].length,text:o})}return i}function kE(e){return e.text.includes("\r")?Yu(e,CE(e.text,/\r\n?/g,()=>"\n"),"line-ending"):e}function pz(e){const t=e.text.includes("<")?e.text.lastIndexOf(">"):-1;if(t<0)return e;const n=[];for(const i of e.text.slice(0,t+1).matchAll(/<(\w+)([^>]*)>/g)){const r=i.index+1+i[1].length;for(const o of i[2].matchAll(/="([^"]*)"/g)){const s=r+o.index+1;n.push({start:s,end:s+1,text:"'"},{start:s+o[0].length-2,end:s+o[0].length-1,text:"'"})}}return Yu(e,n,"html-attribute-quotes")}function gz(e){if(!e.text.includes(";")||!e.text.includes("style")&&!e.text.includes("classDef"))return e;const t=[];for(const i of e.text.matchAll(/[^\r\n\u2028\u2029]+/g)){if(!i[0].includes(";")||!i[0].includes("style")&&!i[0].includes("classDef"))continue;const r=Un(i[0]);let o=i[0].length;const s=[];for(let a=i[0].length-r.length;a>0;a--){const l=i[0].lastIndexOf(";",o-1);s.push({start:i.index+l,end:i.index+l+1,text:""});o=l}t.push(...s.reverse())}const n=[];for(const i of t){const r=n.at(-1);if(r&&r.end===i.start)r.end=i.end;else n.push(i)}return Yu(e,n,"style-semicolon")}function rp(e,t,n,i=false){const r=e.edits;let o=0;let s=r.length;while(o<s){const f=o+Math.floor((s-o)/2);const h=i?r[f].originalStart:r[f].cleanedStart;if(h<=t)o=f+1;else s=f}if(o===0)return t;const a=r[o-1];const l=i?a.originalStart:a.cleanedStart;const c=i?a.originalEnd:a.cleanedEnd;const d=i?a.cleanedStart:a.originalStart;const u=i?a.cleanedEnd:a.originalEnd;if(t>c)return t+u-c;if(t===l&&l!==c)return d;if(t===c&&l!==c)return u;return n==="start"?d:u}function aS(e,t,n,i=e.length){for(let r=i-1;r>=0;r--)t=rp(e[r],t,n);return t}function PE(e,t){return t==="text"||t==="payloadText"?e.mappings:t==="lineText"||t==="authoredPayloadText"?e.lineMappings:t==="upstreamText"?e.upstreamMappings:e.prepassedMappings}function Jc(e,t,n="start",i="text"){if(!Number.isInteger(t)||t<0||t>e[i].length)throw new RangeError("Cleanup offset is outside the selected source view");return aS(PE(e,i),t,n)}function lS(e,t,n="start",i="text"){if(!Number.isInteger(t)||t<0||t>e.originalText.length)throw new RangeError("Cleanup offset is outside the original source");for(const r of PE(e,i))t=rp(r,t,n,true);return t}function yz(e,t,n,i="text"){if(n<t)throw new RangeError("Cleanup range ends before it starts");return{start:Jc(e,t,"start",i),end:Jc(e,n,"end",i)}}function EE(e,t,n,i="text"){const r=yz(e,t,n,i);return e.originalText.slice(r.start,r.end)}function sS(e,t,n,i){const r=[];for(const{reason:o,stage:s,edit:a}of e.changes){if(i!==void 0&&o!==i)continue;const l=aS(e.mappings,a.originalStart,"start",s);const c=aS(e.mappings,a.originalEnd,"end",s);let d=a.cleanedStart;let u=a.cleanedEnd;for(let p=s+1;p<e.mappings.length;p++){d=rp(e.mappings[p],d,"start",true);u=rp(e.mappings[p],u,"end",true)}let f=0;let h=n.length;while(f<h){const p=f+Math.floor((h-f)/2);if(n[p]<=l)f=p+1;else h=p}const m=Math.max(1,f);r.push(Object.freeze({reason:o,view:t,originalStart:l,originalEnd:c,cleanedStart:d,cleanedEnd:u,line:m,col:l-n[m-1]+1}))}return r}function op(e,t=[]){const n=e.includes("\r");const i=e.includes("&");const r=e.includes("<")&&e.includes('="')&&e.includes(">");const o=e.includes(";")&&(e.includes("style")||e.includes("classDef"));if(!t.length&&!n&&!i&&!r&&!o)return ME(e);const s={text:e,mappings:ju,changes:mz};const a=Yu(s,t,"native-accessibility");const l=kE(a);const c=i?Yu(a,CE(a.text,/&(?:#[xX][0-9a-fA-F]+|#[0-9]+|[A-Za-z][A-Za-z0-9]*);/g,fz),"xml-entity"):a;const d=c===a?l:kE(c);const u=o?gz(l):l;const f=r?pz(l):l;if(d===s&&u===s&&f===s)return ME(e);const h=[0];for(let p=0;p<e.length;p++){if(e[p]==="\r"){if(e[p+1]==="\n")p++;h.push(p+1)}else if(e[p]==="\n")h.push(p+1)}const m=[...sS(d,"text",h),...sS(u,"prepassedText",h,"style-semicolon"),...sS(f,"upstreamText",h,"html-attribute-quotes")];return Object.freeze({originalText:e,text:d.text,payloadText:c.text.includes("\r")?c.text.replace(/\r\n/g,"\n"):c.text,authoredPayloadText:n?a.text.replace(/\r\n/g,"\n"):a.text,lineText:l.text,upstreamText:f.text,prepassedText:u.text,changes:Object.freeze(m),mappings:Object.freeze(d.mappings),lineMappings:Object.freeze(l.mappings),upstreamMappings:Object.freeze(f.mappings),prepassedMappings:Object.freeze(u.mappings)})}function Tn(e,t){const n=Nr(t);return e.title!==void 0||n===void 0?e:{...e,title:n}}function Nr(e){const t=e?.title;return typeof t==="string"&&t.trim()!==""?t:void 0}var sp=/^\s*%%(?!\{)\s*(.*)\r?$/;function eee(e){return vE(e)}function vE(e,t){return t?e.replace(mr,(n,i,r,o)=>{t(o,n.length);return""}):e.replace(mr,"")}function xz(e,t="render"){const n=e.cleanup??op(e.originalText);const i=e.wrapperSource?.length??0;const r=e.cleanup&&e.authoredWrapperLength!==void 0?Jc(n,i,"end","text"):i;const o=e.cleanup&&t==="render"?"payloadText":"authoredPayloadText";const s=lS(n,r,"end",o);const a=n[o].slice(s);let l;let c=0;const d=vE(a,(u,f)=>{const h=u-c;const m=l?.at(-1);if(m?.at===h)m.after=u+f;else(l??=[]).push({at:h,before:u,after:u+f});c+=f});return{text:d,sourceOffset:(u,f="start")=>{if(!Number.isInteger(u)||u<0||u>d.length)throw new RangeError("Family source offset is outside the preserved payload");let h=0,m=l?.length??0;while(h<m){const y=h+Math.floor((m-h)/2);if(l[y].at<=u)h=y+1;else m=y}const p=l?.[h-1];const g=p?u===p.at?f==="start"?p.before:p.after:u+p.after-p.at:u;return Jc(n,s+g,f,o)},familyOffset:(u,f="start")=>{const h=lS(n,u,f,o)-s;if(h<0||h>a.length)throw new RangeError("Authored offset is outside the preserved family");let m=0,p=l?.length??0;while(m<p){const y=m+Math.floor((p-m)/2);if(l[y].before<=h)m=y+1;else p=y}const g=l?.[m-1];return g?h<=g.after?g.at:h-g.after+g.at:h}}}function Ma(e,t="render"){return xz(e,t).text}function TE(e){const t=[];const n=new RegExp(mr.source,"gm");let i;while((i=n.exec(e))!==null){if(!Au(i[0]))continue;t.push({raw:i[0],parsed:bz(i[0])??{}})}return t}function bz(e){const t=new RegExp(mr.source,"m").exec(e);return t?t[1]!==void 0||t[2]!==void 0?OE(t[1]??t[2]):/%%\{\s*wrap\s*\}/.test(t[0])?{wrap:true}:{}:void 0}function Sz(e){const t=new RegExp(mr.source,"m").exec(e);if(!t)return void 0;const n=t[1]??t[2];if(n===void 0)return null;if(!n.trim())return{};if(/^\w+$/.test(n.trim()))return n.trim();bm(n,"Mermaid init directive",{trackFlowDepth:true});try{const i=JSON.parse(n.replace(/'/g,'"'));Ms(i,"Mermaid init directive");return hS(i)}catch(i){if(i instanceof Zx)throw i;return OE(n)}}function LE(e){const t=new RegExp(mr.source,"m").exec(e);const n=Sz(e);if(!t||n===void 0)return void 0;return{kind:/%%\{\s*(\w+)/.exec(t[0])[1],hasArgs:t[1]!==void 0||t[2]!==void 0,payload:n}}function tee(e){const t=pr(e);return t?DE(t.yaml):{}}function nee(e){const t=LE(e.raw);return t?`${t.kind}:${t.hasArgs}:${cS(t.payload)}`:`raw:${e.raw.trim().replace(/\s+/g," ")}`}function cS(e){if(Array.isArray(e)){return`[${e.map(cS).join(",")}]`}if(e!==null&&typeof e==="object"){const t=Object.entries(e).filter(n=>n[1]!==void 0).sort(([n],[i])=>n<i?-1:n>i?1:0);return`{${t.map(([n,i])=>`${JSON.stringify(n)}:${cS(i)}`).join(",")}}`}return JSON.stringify(e)}function Xu(e,t={},n="authored",i){const r=dS(e,null);const o=op(e,r);const s=Yc(n==="render"?o.text:o.lineText);const a=i?i(s,"loose"):qc(n==="authored"?qu(s):s,"loose");const l=dS(e,a);const c=r.length>0||l.length>0?op(e,l):o;return AE(e,t,n,c,a)}function dS(e,t){if(!e.includes("%% agentic-mermaid "))return[];const n=pr(e)?.source.length??0;const i=e.slice(n);return gP(i,Rl(qu(Yc(e)),Rm(i).split(/\r\n?|\n/),t)).map(r=>({...r,start:n+r.start,end:n+r.end}))}function AE(e,t,n,i,r){const o=n==="render"?i.text:i.lineText;const s=kz(o,$E(t),r);const a=s.body.split(/\r?\n/);const l=/^sequenceDiagram\b/i.test(s.lines[0]??"");const c=l&&/;\s*acc(?:Title|Descr)\b/i.test(s.body)?Jb(a):a;const d=zt(c,Rl(qu(s.lines[0]??""),c,r),n==="render"?w=>(w.form==="native"?Yo:Mb)({title:w.value}).title:void 0);const u=Mz(o,d.accessibility,r);const f=o===i.lineText;if(f&&o!==e){if(u.wrapperSource!==void 0){u.wrapperSource=e.slice(0,Jc(i,u.wrapperSource.length,"end","lineText"))}const w=pr(o)?.source.length??(o.startsWith("\uFEFF")?1:0);const S=[...o.slice(w).matchAll(new RegExp(mr.source,"gm"))].filter(x=>Au(x[0])).values();for(const x of u.initDirectives){const M=w+S.next().value.index;const b=M+x.raw.length;x.raw=EE(i,M,b,"lineText")}}const h=d.familyLines.join("\n");const m=/^stateDiagram(?:-v2)?(?=$|[\s;%])/i.test(s.lines[0]??"");const p=/^timeline(?=$|[\s;#%])/i.test(s.lines[0]??"");const g=m?Sa(d.familyLines).filter(w=>w.noteBody||w.text.length>0).map(w=>w.text):p?d.familyLines.map(w=>w.trimStart()).filter(w=>w.trim().length>0&&!sp.test(w)):Iu(h);const y=f?void 0:AE(e,t,"authored",i,r);return{originalText:e,cleanup:i,...y?{authoredFamilyLines:y.familyLines,authoredFamilyBody:y.familyBody,authoredHeader:y.lines[0]??"",authoredWrapperLength:y.wrapperSource?.length??0}:{},text:s.lines.join("\n"),body:s.body,lines:s.lines,familyBody:h,familyText:g.join("\n"),familyLines:g,firstLine:s.lines[0]?.toLowerCase()??"",config:_E(s.frontmatter),frontmatter:s.frontmatter,...u.wrapperSource!==void 0?{wrapperSource:u.wrapperSource}:{},initDirectives:u.initDirectives,comments:u.comments,accessibility:u.accessibility}}function wz(e,t={},n="authored",i){const r=Xu(e,{},n,i);if(Object.keys(t).length===0)return r;const o=Qc(r.frontmatter,$E(t));return{...r,frontmatter:o,config:_E(o)}}function IE(e,t,n){return wz(e,t,"render",n)}function Mz(e,t,n){const i=pr(e);const r=i?.source.length??(e.startsWith("\uFEFF")?1:0);const o=TE(e.slice(r));const s=S=>S.replace(/[^\r\n]/g," ");const a=(i?s(i.source)+e.slice(i.source.length):e).replace(new RegExp(mr.source,"gm"),s);const l=[];const c=a.split(/\r?\n/);const d=c.find(S=>S.trim().length>0&&!sp.test(S))?.trim()??"";const u=/^stateDiagram(?:-v2)?(?=$|[\s;%])/i.test(d);const f=/^sequenceDiagram\b/i.test(d);const h=u?Sa(c):void 0;const m=(S,x)=>{if(!f)return;const M=Jb([S]).find(b=>b.trimStart().startsWith("%%"));if(M)l.push({text:M.trimStart().slice(2).trim(),line:x})};const p=Rl(qu(d),c,n);let g=-1;for(let S=0;S<c.length;S++){const x=S>g?vt(c,S):null;if(x===void 0)break;if(x!==null){if(x.suffixLine)m(x.suffixLine,x.endIndex+1);S=x.endIndex;continue}if(S>g)g=Xc(p,S,c.length);const M=c[S];const b=h?.[S];if(b){if(b.commentIndex>=0)l.push({text:M.slice(b.commentIndex+2).trim(),line:S+1});continue}const C=M.match(sp);if(C)l.push({text:C[1],line:S+1});else if(f)m(M,S+1)}let y=r;const w=new RegExp(mr.source);for(;;){const S=e.slice(y);if(S.length===0)break;const x=S.match(w);if(x?.index===0&&x[0].length>0){y+=x[0].length;continue}const M=S.indexOf("\n");const b=M===-1?S:S.slice(0,M);if(vt([b],0)?.form==="native")break;if(/^\s*$/.test(b)||sp.test(b)){y+=M===-1?S.length:M+1;continue}break}return{...y>0?{wrapperSource:e.slice(0,y)}:{},initDirectives:o,comments:l,accessibility:t}}function kz(e,t={},n=qc(qu(Yc(e)),"loose")){const i=dS(e,n);for(const d of i.toReversed())e=e.slice(0,d.start)+d.text+e.slice(d.end);const r=pr(e);const o=r?uS(DE(r.yaml)):{};const s=r?e.slice(r.source.length):e;const a=Ez(s,Qc(uS(t),o),n);const l=El(a.body);const c=a.frontmatter;return{body:l,lines:Iu(l),frontmatter:c}}function Qc(e,t){return FE(e,t)}function FE(e,t){const n=Nl(e);for(const[i,r]of Object.entries(t)){if(r===void 0)continue;const o=n[i];if(ko(o)&&ko(r)){n[i]=FE(o,r);continue}n[i]=mS(r)}return n}function Sn(e,t){let n=e;for(const i of t){if(!ko(n))return void 0;n=n[i]}return ko(n)?n:void 0}function Mt(e,t){let n=e;for(const i of t){if(!ko(n))return void 0;n=n[i]}return n!==void 0&&!Array.isArray(n)&&(typeof n!=="object"||n===null)?n:void 0}function NE(e,t){let n=e;for(const i of t){if(!ko(n))return void 0;n=n[i]}return Array.isArray(n)?n:void 0}function $E(e){Ms(e,"Mermaid runtime configuration");return uS(lp(e)??{})}function _E(e){const t=Nl(e);if(ko(t.themeVariables)){t.themeVariables=Nl(t.themeVariables)}if(ko(t.timeline)){t.timeline=Cz(t.timeline)}if(ko(t.journey)){t.journey=Pz(t.journey)}return t}function Cz(e){const t=Nl(e);if(typeof t.disableMulticolor!=="boolean"){delete t.disableMulticolor}const n=ap(t.sectionFills);if(n.length>0){t.sectionFills=n}else{delete t.sectionFills}const i=ap(t.sectionColours);const r=ap(t.sectionColors);if(i.length>0){t.sectionColours=i}else if(r.length>0){t.sectionColours=r}else{delete t.sectionColours}delete t.sectionColors;return t}function Pz(e){const t=Nl(e);for(const r of["diagramMarginX","diagramMarginY","leftMargin","maxLabelWidth","width","height","boxMargin","boxTextMargin","noteMargin","messageMargin","bottomMarginAdj","taskMargin","activationWidth"]){const o=t[r];if(typeof o!=="number"||!Number.isFinite(o)||o<0){delete t[r]}}if(typeof t.useMaxWidth!=="boolean")delete t.useMaxWidth;if(typeof t.rightAngles!=="boolean")delete t.rightAngles;if(t.messageAlign!=="left"&&t.messageAlign!=="center"&&t.messageAlign!=="right"){delete t.messageAlign}const n=RE(t.taskFontSize);if(n!==void 0)t.taskFontSize=n;else delete t.taskFontSize;for(const r of["taskFontFamily","textPlacement","titleColor","titleFontFamily"]){if(typeof t[r]!=="string"||t[r].trim().length===0)delete t[r]}const i=RE(t.titleFontSize);if(i!==void 0)t.titleFontSize=i;else delete t.titleFontSize;for(const r of["actorColours","sectionFills","sectionColours"]){const o=ap(t[r]);if(o.length>0)t[r]=o;else delete t[r]}return t}function RE(e){if(typeof e==="number"&&Number.isFinite(e)&&e>0)return e;if(typeof e==="string"&&e.trim().length>0)return e.trim();return void 0}function ap(e){return Array.isArray(e)?e.filter(t=>typeof t==="string"):[]}function uS(e){Ms(e,"Mermaid configuration");const t=Nl(e);const n=ko(t.config)?t.config:void 0;delete t.config;return n?Qc(n,t):t}var fS=class extends Error{};function DE(e){bm(e,"Mermaid frontmatter");const t=$s(e);if(!t.ok){throw new fS(Je({what:`Mermaid frontmatter is not valid YAML: ${t.message}`,expectedForm:"a YAML mapping between the two `---` lines",example:'---\ntitle: "Order flow: v2"\n---'}).message)}Ms(t.value,"Mermaid frontmatter");return lp(t.value)??{}}function Ez(e,t,n){const i=TE(e).flatMap(c=>{const d=LE(c.raw);return d?[d]:[]});const r=yb(e);const o=Iu(r)[0]?.split(/\s/)[0]??"";const s=dE(n?.id??o);if(i.length===0&&Object.keys(t).length===0)return{body:r,frontmatter:t};const a=i.filter(c=>/(?:init\b)|(?:initialize\b)/.test(c.kind)).map(c=>c.payload);const l=i.some(c=>c.kind==="wrap");try{return{body:r,frontmatter:cE(t,i.map(c=>lE(c.kind,c.payload,c.hasArgs)).join("\n"),s,true)}}catch{let c=Qc({},t);for(const d of a){if(!d||typeof d!=="object"||Array.isArray(d))continue;const u=Qc({},d);if(u.config!==void 0){if(a.length===1)u[s==="flowchart-v2"?"flowchart":s]=u.config;delete u.config}c=Qc(c,u)}if(l)c.wrap=true;return{body:r,frontmatter:c}}}function OE(e){return e===void 0?{wrap:true}:e.trim()===""?{}:Rz(e.trim())}function Rz(e){bm(e,"Mermaid init directive",{trackFlowDepth:true});try{const t=rS(e);Ms(t,"Mermaid init directive");return lp(t)}catch(t){if(t instanceof Zx||t instanceof Ri)throw t;const n=Lz(e);if(n!==void 0)Ms(n,"Mermaid init directive");return n}}function lp(e){if(!vz(e))return void 0;const t={};for(const[n,i]of Object.entries(e)){const r=hS(i);if(r!==void 0)t[n]=r}return t}function hS(e){if(e===null)return null;if(typeof e==="string"||typeof e==="number"||typeof e==="boolean")return e;if(Array.isArray(e)){const t=[];for(const n of e){const i=hS(n);if(i===void 0)return void 0;t.push(i)}return t}return lp(e)}function Nl(e){const t={};for(const[n,i]of Object.entries(e)){t[n]=mS(i)}return t}function mS(e){if(e===void 0||e===null)return e;if(typeof e==="string"||typeof e==="number"||typeof e==="boolean")return e;if(Array.isArray(e))return e.map(t=>mS(t));return Nl(e)}function ko(e){return!!e&&typeof e==="object"&&!Array.isArray(e)}function vz(e){return!!e&&typeof e==="object"&&!Array.isArray(e)}function Tz(e){if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'")){return WE(e)}if(e==="true")return true;if(e==="false")return false;if(e==="null")return null;if(/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/.test(e))return Number(e);return e}function Lz(e){const t=pS(e.trim());return ko(t)?t:void 0}function pS(e){const t=e.trim();if(t.length===0)return void 0;if(t.startsWith("{")&&t.endsWith("}")){return Az(t.slice(1,-1))}if(t.startsWith("[")&&t.endsWith("]")){return Iz(t.slice(1,-1))}return Tz(t)}function Az(e){const t={};for(const n of BE(e)){const i=Nz(n,":");if(i===-1)return void 0;const r=n.slice(0,i).trim();const o=n.slice(i+1).trim();const s=Fz(r);if(!s)return void 0;const a=pS(o);if(a===void 0)return void 0;t[s]=a}return t}function Iz(e){const t=[];for(const n of BE(e)){const i=pS(n);if(i===void 0)return void 0;t.push(i)}return t}function Fz(e){const t=e.trim();if(!t)return void 0;if(t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")){return WE(t)}return t}function BE(e){const t=[];let n="";let i=null;let r=0;let o=0;for(let a=0;a<e.length;a++){const l=e[a];if(i){n+=l;if(l===i&&e[a-1]!=="\\")i=null;continue}if(l==='"'||l==="'"){i=l;n+=l;continue}if(l==="{"){r++;n+=l;continue}if(l==="}"){r--;n+=l;continue}if(l==="["){o++;n+=l;continue}if(l==="]"){o--;n+=l;continue}if(l===","&&r===0&&o===0){const c=n.trim();if(c)t.push(c);n="";continue}n+=l}const s=n.trim();if(s)t.push(s);return t}function Nz(e,t){let n=null;let i=0;let r=0;for(let o=0;o<e.length;o++){const s=e[o];if(n){if(s===n&&e[o-1]!=="\\")n=null;continue}if(s==='"'||s==="'"){n=s;continue}if(s==="{"){i++;continue}if(s==="}"){i--;continue}if(s==="["){r++;continue}if(s==="]"){r--;continue}if(s===t&&i===0&&r===0)return o}return-1}function WE(e){try{if(e.startsWith("'")){return e.slice(1,-1).replace(/\\\\/g,"\\").replace(/\\'/g,"'")}return JSON.parse(e)}catch{return e.slice(1,-1)}}var zE=new Set(Object.values(Gi).flat());var $z=new Set(["primaryTextColor","textColor","nodeTextColor","secondaryTextColor","tertiaryTextColor"]);var _z=new Set([...Array.from({length:12},(e,t)=>`pie${t+1}`),"pieStrokeColor","pieOuterStrokeColor","pieSectionTextColor","pieTitleTextColor","pieLegendTextColor"]);var Dz=new Set(["pieSectionTextColor","pieTitleTextColor","pieLegendTextColor"]);var Oz=new Set([...Array.from({length:8},(e,t)=>[`git${t}`,`gitBranchLabel${t}`,`gitInv${t}`]).flat(),"commitLabelColor","commitLabelBackground"]);var Bz=new Set([...Array.from({length:8},(e,t)=>`gitBranchLabel${t}`),"commitLabelColor"]);var GE=new Set(Array.from({length:12},(e,t)=>[`cScale${t}`,`cScaleLabel${t}`,`cScaleInv${t}`]).flat());var HE=new Set([...Array.from({length:12},(e,t)=>`cScale${t}`),"titleColor"]);var Wz=new Set(["clusterBkg","clusterBorder"]);var zz=["backgroundColor","titleColor","xAxisLabelColor","xAxisTickColor","xAxisLineColor","xAxisTitleColor","yAxisLabelColor","yAxisTickColor","yAxisLineColor","yAxisTitleColor","legendTextColor","dataLabelColor"];var Gz=new Set(["xAxisTickColor","xAxisLineColor","yAxisTickColor","yAxisLineColor"]);var Hz=[["bg",Gi.bg],["surface",Gi.surface],["line",Gi.line],["accent",Gi.accent]];function Ca(e,t=false){const n=typeof e==="string"?e:JSON.stringify(e)??String(e);return t&&n.length>256?`${n.slice(0,256)}\u2026`:n}var ka=class extends Error{code="INVALID_THEME_COLOR";key;value;constructor(t,n,i){const r=Ca(n,true);super(Je({what:`themeVariables.${t}: ${JSON.stringify(r)} is not a CSS color`,expectedForm:Tu(i),example:`themeVariables.${t}:#f96`}).message);this.name="ThemeVariableColorError";this.key=t;this.value=r}};var Vu=class extends Error{code="INVALID_RENDER_COLOR";field;value;constructor(t,n){const i=Ca(n,true);super(Je({what:`render option "${t}": ${JSON.stringify(i)} is not a CSS color for Architecture derived paint`,expectedForm:"a drawable CSS color or var(--name)",example:`${t}:#f96`}).message);this.name="RenderOptionColorError";this.field=t;this.value=i}};function jE(e,t,n){if(t!=="architecture"||!e)return;const i=n?.edgeStroke;if(typeof i==="string"&&i.trim().toLowerCase()==="none"){throw new Vu("architecture.visual.edgeStroke",i)}for(const o of["bg","surface","line","accent"]){const s=e[o];if(typeof s!=="string"||s.trim().toLowerCase()!=="none")continue;if(o==="surface"&&n?.groupSurface?.trim().toLowerCase()!=="none")continue;if(o==="surface"&&n?.groupHeaderSurface)continue;if((o==="line"||o==="accent")&&i)continue;throw new Vu(o,s)}const r=n?.groupSurface;if(!n?.groupHeaderSurface&&typeof r==="string"&&r.trim().toLowerCase()==="none"){throw new Vu("architecture.visual.groupSurface",r)}}var $l=class extends Error{code="INVALID_CONFIG_COLOR";path;value;constructor(t,n,i,r){const o=Ca(n,true);const s=Ca(t,true);super(Je({what:`${s}: ${JSON.stringify(o)} is not ${r==="array"?"an array of CSS colors":r==="map"?"a map of CSS colors":"a CSS color"}`,expectedForm:r?r==="array"?"an array of drawable CSS colors":"an object mapping node labels to drawable CSS colors":Tu(i),example:`${s}${r==="array"?': ["#f96"]':r==="map"?': {"A":"#f96"}':": #f96"}`}).message);this.name="FamilyConfigColorError";this.path=s;this.value=o}};function cp(e){return e!==null&&typeof e==="object"&&!Array.isArray(e)?e:void 0}function jz(e,t){return t.find(n=>{const i=e[n];return typeof i==="string"&&i.length>0})}function Uu(e,t,n,i){const r=e[n];if(r===void 0)return;if(mn(r,i)===void 0){throw new $l(`${t}.${n}`,r,i)}}function Zc(e,t,n,i){const r=e[n];if(r===void 0)return;if(!Array.isArray(r))throw new $l(`${t}.${n}`,r,i,"array");for(let o=0;o<r.length;o++){const s=r[o];if(mn(s,i)===void 0){throw new $l(`${t}.${n}[${o}]`,s,i)}}}function YE(e,t){const n=cp(e[t]);if(!n)return;if(t==="timeline"){Zc(n,"timeline","sectionFills",false);Zc(n,"timeline","sectionColours",false);if(n.sectionColours===void 0||Array.isArray(n.sectionColours)&&n.sectionColours.length===0){Zc(n,"timeline","sectionColors",false)}}else if(t==="journey"){Zc(n,"journey","actorColours",true);Zc(n,"journey","sectionFills",false);Zc(n,"journey","sectionColours",false);Uu(n,"journey","titleColor",false)}else if(t==="requirement"){Uu(n,"requirement","rect_fill",true);Uu(n,"requirement","rect_border_color",true);Uu(n,"requirement","text_color",false)}else if(t==="sankey"){const i=n.linkColor;if(i!=="source"&&i!=="target"&&i!=="gradient"){Uu(n,"sankey","linkColor",true)}if(n.nodeColors===void 0)return;const r=cp(n.nodeColors);if(!r)throw new $l("sankey.nodeColors",n.nodeColors,false,"map");const o=i!==void 0&&i!=="gradient";for(const[s,a]of Object.entries(r)){if(mn(a,o)===void 0){const l=/^[\w-]+$/.test(s)?`sankey.nodeColors.${s}`:`sankey.nodeColors[${JSON.stringify(s)}]`;throw new $l(l,a,o)}}}}function gS(e,t,n,i){if(!e)return;const r=t==="pie"?_z:t==="gitgraph"?Oz:t==="timeline"?GE:t==="radar"?HE:t==="architecture"?Wz:void 0;const o=r?new Set([...zE,...r]):zE;const s=t==="architecture"?new Set(Hz.flatMap(([a,l])=>{if(n?.[a]!==void 0)return[];if(a==="surface"&&i&&(i?.groupHeaderSurface||i?.groupSurface?.trim().toLowerCase()!=="none"))return[];if((a==="line"||a==="accent")&&i?.edgeStroke)return[];return jz(e,l)??[]})):void 0;for(const a of o){if(!Object.hasOwn(e,a))continue;const l=e[a];if(l===void 0)continue;const c=Ca(l);const d=$z.has(a)||Dz.has(a)||Bz.has(a)||t==="timeline"&&GE.has(a)||t==="radar"&&HE.has(a)||t==="architecture"&&(a==="clusterBkg"&&(!i||!i.groupHeaderSurface&&i.groupSurface?.trim().toLowerCase()==="none")||s?.has(a));if(mn(l,!d)===void 0){throw new ka(a,c,!d)}}if(t==="radar"){const a=cp(e.radar);if(!a)return;for(const l of["axisColor","graticuleColor"]){const c=a[l];if(c===void 0)continue;const d=l==="graticuleColor";const u=Ca(c);if(mn(c,d)===void 0){throw new ka(`radar.${l}`,u,d)}}}if(t==="xychart"){const a=cp(e.xyChart);if(!a)return;for(const c of zz){if(c==="backgroundColor"&&n?.bg!==void 0)continue;const d=a[c];if(d===void 0)continue;const u=Gz.has(c);const f=Ca(d);if(mn(d,u)===void 0){throw new ka(`xyChart.${c}`,f,u)}}const l=a.plotColorPalette;if(l!==void 0&&!(typeof l==="string"&&l.trim().length===0)){const c=typeof l==="string"?um(l):l;if(!Array.isArray(c)){throw new ka("xyChart.plotColorPalette",JSON.stringify(l)??String(l),false)}for(const[d,u]of c.entries()){const f=typeof u==="string"?u.trim():JSON.stringify(u)??String(u);if(mn(u)===void 0){throw new ka(`xyChart.plotColorPalette[${d}]`,f,false)}}}}if(t==="architecture"&&(typeof e.mainBkg!=="string"||e.mainBkg.length===0)){const a=e.secondaryColor;if(a!==void 0){const l=Ca(a);if(mn(a,true)===void 0){throw new ka("secondaryColor",l,true)}}}}function Zr(e,t){if(!e||typeof e!=="object"||Array.isArray(e))return void 0;const n=e[t];return n&&typeof n==="object"&&!Array.isArray(n)?n:void 0}function yS(e,t,n){if(!n)return[];const i=t&&typeof t==="object"&&!Array.isArray(t)?t:void 0;const r=Zr(t,n.section);if(!r)return i&&n.section in i?[{code:"INEFFECTIVE_CONFIG",field:n.section,message:`${e} config section "${n.section}" must be an object; the invalid value has no effect.`}]:[];const o=new Set(n.keys);return Object.keys(r).filter(s=>!o.has(s)).sort().map(s=>({code:"INEFFECTIVE_CONFIG",field:`${n.section}.${s}`,message:`${e} config field "${s}" is unknown and has no effect; check the spelling or remove it.`}))}function xt(e,{root:t,config:n},i={}){const r=yS(e,t,n);const o=Zr(t,n.section);if(o){for(const[s,a]of Object.entries(i)){if(s in o&&!a.valid(o[s])){const l=`${n.section}.${s}`;r.push({code:"INEFFECTIVE_CONFIG",field:l,message:`${l} must be ${a.expected}; the invalid value has no effect.`})}}}return[...r,...Yz(e,t,n,i)]}function Yz(e,t,n,i={}){if(!n)return[];const r=Zr(t,n.section);if(!r)return[];const o=new Set(n.noopKeys??[]);return Object.keys(r).filter(s=>{if(!o.has(s))return false;const a=i[s];return!a||a.valid(r[s])}).sort().map(s=>({code:"INEFFECTIVE_CONFIG",field:`${n.section}.${s}`,message:`${e} config field "${s}" is accepted for ${e.includes(":")?"compatibility":"Mermaid compatibility"} but has no effect on this renderer.`}))}function qz(e){const t=new Set;return e.sort((n,i)=>Bn(n.field,i.field)||Bn(n.message,i.message)).filter(n=>{const i=`${n.code}\0${n.field}\0${n.message}`;if(t.has(i))return false;t.add(i);return true})}function Xz(e,t,n,i){if(!n)return[];const r=i??bb(e)?.configDiagnostics;return qz(t.flatMap(o=>r?[...r({root:o,config:n})]:xt(e,{root:o,config:n})))}function qE(e,t,n,i){const r=bb(e);const o=n??r?.config;return Xz(e,[t],o,i??r?.configDiagnostics)}var Uz=["onConfigDiagnostic"];var dp=(e,t)=>({type:"string",description:e,...t===void 0?{}:{default:t}});var Dl=(e,t,n={})=>({type:"number",description:e,...t===void 0?{}:{default:t},...n});var Hi=(e,t)=>Dl(e,t,{minimum:0});var to=(e,t)=>Dl(e,t,{exclusiveMinimum:0});var xS=e=>Dl(e,void 0,{minimum:1,maximum:1e3});var _s=(e,t)=>({type:"boolean",description:e,...t===void 0?{}:{default:t}});var ji=(e,t)=>({...dp(e,t),"x-agentic-mermaid-runtime-validator":"safeCssPaint"});var nR=(e,t)=>({...dp(e,t),"x-agentic-mermaid-runtime-validator":"safeCssFontFamily"});var Co=(e,t,n=[])=>({type:"object",description:t,additionalProperties:false,properties:e,...n.length===0?{}:{required:n}});var bS={type:"string",enum:["uppercase","lowercase","capitalize"]};var iR={groupHeaderHeight:to("Requested minimum Architecture group-header height; expands to fit measured title text."),groupFontSize:to("Architecture group-label font size."),groupFontWeight:xS("Architecture group-label font weight."),groupLetterSpacing:Dl("Architecture group-label letter spacing."),groupFont:nR("Architecture group-label font family."),groupTextTransform:{...bS,description:"Architecture group-label text transform."},groupPaddingX:Hi("Horizontal padding inside architecture groups."),groupPaddingY:Hi("Vertical padding inside architecture groups."),groupLabelPaddingX:Hi("Horizontal padding around architecture group labels."),groupCornerRadius:Hi("Architecture group corner radius."),groupLineWidth:Hi("Architecture group border width."),groupText:ji("Architecture group-label color."),serviceFontSize:to("Architecture service-label font size."),serviceFontWeight:xS("Architecture service-label font weight."),serviceLetterSpacing:Dl("Architecture service-label letter spacing."),serviceTextTransform:{...bS,description:"Architecture service-label text transform."},servicePaddingX:Hi("Horizontal padding inside architecture services."),servicePaddingY:Hi("Vertical padding inside architecture services."),serviceCornerRadius:Hi("Architecture service corner radius."),serviceLineWidth:Hi("Architecture service border width."),serviceText:ji("Architecture service-label color."),edgeFontSize:to("Architecture connector-label font size."),edgeFontWeight:xS("Architecture connector-label font weight."),edgeLetterSpacing:Dl("Architecture connector-label letter spacing."),edgeTextTransform:{...bS,description:"Architecture connector-label text transform."},edgeLineWidth:Hi("Architecture connector width."),edgeBendRadius:Hi("Architecture connector bend radius."),edgeStroke:ji("Architecture connector color."),edgeText:ji("Architecture connector-label color."),iconSize:to("Architecture group icon size."),serviceIconSize:to("Architecture service icon size."),junctionOuterRadius:to("Architecture junction outer radius."),junctionInnerRadius:Hi("Architecture junction inner radius."),groupSurface:ji("Architecture group surface color."),groupHeaderSurface:ji("Architecture group-header surface color."),groupBorder:ji("Architecture group border color."),serviceSurface:ji("Architecture service surface color."),serviceBorder:ji("Architecture service border color.")};var Vz={...Co(iR,"Sparse architecture visual overrides merged over resolved defaults."),"x-agentic-mermaid-runtime-validator":"architectureVisual"};var Kz=(()=>{const e=xC();const t=e.$defs;const n=a=>{if(Array.isArray(a))return a.map(n);if(a===null||typeof a!=="object")return a;const l=a;const c=l.$ref;if(typeof c==="string"&&c.startsWith("#/$defs/")){const d=t?.[c.slice("#/$defs/".length)];if(!d)throw new Error(`StyleSpec schema has unresolved local reference ${c}`);return n(d)}return Object.fromEntries(Object.entries(l).filter(([d])=>d!=="$defs").map(([d,u])=>[d,n(u)]))};const{$schema:i,$id:r,title:o,...s}=e;return n(s)})();var XE={anyOf:[{type:"string",description:"Registered Style or Palette name."},Kz],"x-agentic-mermaid-validation-expectation":"a registered Style name or StyleSpec"};var rR={anyOf:[XE,{type:"array",items:XE,description:"Style stack merged from left to right."}],description:"A registered name, inline StyleSpec, or left-to-right stack of either.","x-agentic-mermaid-runtime-validator":"styleInput"};var wS={anyOf:[{type:"null"},{type:"string"},{type:"number"},{type:"boolean"},{type:"array",items:{$ref:"#/$defs/jsonValue"}},{type:"object",additionalProperties:{$ref:"#/$defs/jsonValue"}}],description:"A finite, acyclic JSON value without prototype keys.","x-agentic-mermaid-validation-expectation":"a finite, acyclic JSON value without prototype keys"};var UE=["flowchart","state","class","er","architecture","c4"];var Jz=["flowchart","state","sequence","timeline","class","er","journey","xychart","pie","quadrant","gantt","mindmap","gitgraph","sankey"];var Ol=Qx({layoutHints:{typeScript:"{ ranks?: Record<string, number>; adjacent?: string[][]; shortEdges?: string[] }",description:"Relative ranks, sibling adjacency and short-edge preferences.",defaultLabel:"unset",validationExpectation:"contain integer ranks, node groups and edge IDs",schema:{type:"object",additionalProperties:false,properties:{ranks:{type:"object",additionalProperties:{type:"integer",minimum:0,maximum:1e4}},adjacent:{type:"array",items:{type:"array",minItems:2,items:{type:"string"}}},shortEdges:{type:"array",items:{type:"string"}}}},terminal:"not-applicable",terminalNote:"not used by terminals",applicableBuiltinFamilies:["flowchart","state"]},graphLayout:{typeScript:"{ backend: 'elk' | 'agentic'; fallback?: 'none' | 'elk' }",description:"Graph geometry producer and explicit Agentic fallback policy.",defaultLabel:"`elk`, no fallback",validationExpectation:"be a graph layout selection object",schema:{anyOf:[Co({backend:{type:"string",const:"elk"},fallback:{type:"string",enum:["none"]}},"ELK graph layout.",["backend"]),Co({backend:{type:"string",const:"agentic"},fallback:{type:"string",enum:["none","elk"]}},"Owned graph layout with optional ELK fallback.",["backend"])]},terminal:"projected",terminalNote:"selects pixel placement and optional graphical companion evidence, not terminal-cell placement",applicableBuiltinFamilies:["flowchart","state","architecture","class","er","requirement"]},layoutSafety:{typeScript:"'report' | 'strict'",description:"Report bounded layout evidence, or require a passed final certificate. Strict mode rejects missing or unverified evidence.",defaultLabel:"`report`",validationExpectation:"be report or strict",schema:{type:"string",enum:["report","strict"],default:"report",description:"Require a passed final native layout certificate."},terminal:"consumed"},bg:{typeScript:"string",description:"Background color or CSS variable.",defaultLabel:"`#FFFFFF`",validationExpectation:"be a safe non-fetching CSS paint",schema:ji("Background color or CSS variable.","#FFFFFF"),terminal:"consumed"},fg:{typeScript:"string",description:"Primary foreground and text color.",defaultLabel:"`#27272A`",validationExpectation:"be a safe non-fetching CSS paint",schema:ji("Primary foreground and text color.","#27272A"),terminal:"consumed"},line:{typeScript:"string",description:"Connector and secondary-line color.",defaultLabel:"derived",validationExpectation:"be a safe non-fetching CSS paint",schema:ji("Connector and secondary-line color."),terminal:"consumed"},accent:{typeScript:"string",description:"Arrowhead, highlight, and data accent color.",defaultLabel:"derived",validationExpectation:"be a safe non-fetching CSS paint",schema:ji("Arrowhead, highlight, and data accent color."),terminal:"consumed"},muted:{typeScript:"string",description:"Secondary text and label color.",defaultLabel:"derived",validationExpectation:"be a safe non-fetching CSS paint",schema:ji("Secondary text and label color."),terminal:"projected",terminalNote:"terminal themes have no dedicated muted-text role"},surface:{typeScript:"string",description:"Node and group surface color.",defaultLabel:"derived",validationExpectation:"be a safe non-fetching CSS paint",schema:ji("Node and group surface color."),terminal:"projected",terminalNote:"terminal cells do not paint graphical surfaces"},border:{typeScript:"string",description:"Node and group border color.",defaultLabel:"derived",validationExpectation:"be a safe non-fetching CSS paint",schema:ji("Node and group border color."),terminal:"consumed"},font:{typeScript:"string",description:"CSS font family or stack.",defaultLabel:"`Inter`",validationExpectation:"be a safe non-fetching CSS font family or stack",schema:nR("CSS font family or stack.","Inter"),terminal:"projected",terminalNote:"the host terminal owns the font face"},style:{typeScript:"StyleInput | StyleInput[]",description:"Registered Style/Palette name, inline StyleSpec, or left-to-right stack.",defaultLabel:"`crisp`",validationExpectation:"be a registered Style name or StyleSpec, or an array of them",schema:rR,terminal:"consumed"},padding:{typeScript:"number",description:"Canvas padding in SVG user units.",defaultLabel:"`40`",validationExpectation:"be a non-negative finite number",schema:Hi("Canvas padding in SVG user units.",40),terminal:"not-applicable",terminalNote:"terminal output uses paddingX, paddingY, and boxBorderPadding",applicableBuiltinFamilies:["flowchart","state","architecture","c4"]},nodeSpacing:{typeScript:"number",description:"Horizontal spacing between sibling nodes.",defaultLabel:"`24`",validationExpectation:"be a non-negative finite number",schema:Hi("Horizontal spacing between sibling nodes.",24),terminal:"not-applicable",terminalNote:"terminal layout has a cell-grid spacing contract",applicableBuiltinFamilies:UE},layerSpacing:{typeScript:"number",description:"Vertical spacing between graph layers.",defaultLabel:"`40`",validationExpectation:"be a non-negative finite number",schema:Hi("Vertical spacing between graph layers.",40),terminal:"not-applicable",terminalNote:"terminal layout has a cell-grid spacing contract",applicableBuiltinFamilies:UE},wrappingWidth:{typeScript:"number",description:"Flowchart measured-label wrapping budget in pixels.",defaultLabel:"unset",validationExpectation:"be a positive finite number",schema:to("Flowchart measured-label wrapping budget in pixels."),terminal:"not-applicable",terminalNote:"terminal output uses maxWidth or targetWidth",applicableBuiltinFamilies:["flowchart"]},componentSpacing:{typeScript:"number",description:"Spacing between disconnected graph components for compatible extension families; no built-in family currently consumes it.",defaultLabel:"extension-defined",validationExpectation:"be a non-negative finite number",schema:Hi("Spacing between disconnected graph components for compatible extension families; no built-in family currently consumes it."),terminal:"not-applicable",terminalNote:"terminal layout has a cell-grid spacing contract",applicableBuiltinFamilies:[]},transparent:{typeScript:"boolean",description:"Omit the painted SVG canvas background.",defaultLabel:"`false`",validationExpectation:"be a boolean",schema:_s("Omit the painted SVG canvas background.",false),terminal:"projected",terminalNote:"terminal output has no painted canvas background"},interactive:{typeScript:"boolean",description:"Enable hover tooltips for supported chart data points.",defaultLabel:"`false`",validationExpectation:"be a boolean",schema:_s("Enable hover tooltips for supported chart data points.",false),terminal:"projected",terminalNote:"terminal output is a static semantic projection",applicableBuiltinFamilies:["xychart","pie","quadrant"]},shadow:{typeScript:"boolean",description:"Paint explicit drop shadows on node shapes.",defaultLabel:"`false`",validationExpectation:"be a boolean",schema:_s("Paint explicit drop shadows on node shapes.",false),terminal:"projected",terminalNote:"elevation projects to borders and labels",applicableBuiltinFamilies:Jz},class:{typeScript:"{ hierarchicalNamespaces?: boolean }",description:"Class-diagram rendering controls.",defaultLabel:"`hierarchicalNamespaces: true`",validationExpectation:"be a class options object",schema:Co({hierarchicalNamespaces:_s("Nest namespace compounds.",true)},"Class-diagram rendering controls."),terminal:"not-applicable",terminalNote:"this option configures graphical class layout",applicableBuiltinFamilies:["class"]},kanban:{typeScript:"{ maxWidth?: number }",description:"Opt-in Kanban column wrapping with readable column widths.",defaultLabel:"`maxWidth`: unset",validationExpectation:"be a kanban options object",schema:Co({maxWidth:to("Best-effort width budget for wrapping whole Kanban columns into rows.")},"Kanban layout controls."),terminal:"not-applicable",terminalNote:"terminal layout uses its own targetWidth",applicableBuiltinFamilies:["kanban"]},pie:{typeScript:"{ maxWidth?: number }",description:"Opt-in Pie title and legend fitting without shrinking typography.",defaultLabel:"`maxWidth`: unset",validationExpectation:"be a pie options object",schema:Co({maxWidth:to("Best-effort graphical width budget; authored legend placement retains precedence.")},"Pie layout controls."),terminal:"not-applicable",terminalNote:"terminal layout uses its own targetWidth",applicableBuiltinFamilies:["pie"]},radar:{typeScript:"{ maxWidth?: number }",description:"Opt-in Radar plot and legend fitting without shrinking typography.",defaultLabel:"`maxWidth`: unset",validationExpectation:"be a radar options object",schema:Co({maxWidth:to("Best-effort graphical width budget; authored frames retain precedence.")},"Radar layout controls."),terminal:"not-applicable",terminalNote:"terminal layout uses its own targetWidth",applicableBuiltinFamilies:["radar"]},architecture:{typeScript:"{ visual?: ArchitectureVisualOverrides }",description:"Sparse architecture renderer visual metric and paint overrides.",defaultLabel:"built-in metrics",validationExpectation:"be an architecture options object",schema:Co({visual:Vz},"Architecture renderer visual metric and paint overrides."),terminal:"not-applicable",terminalNote:"this option configures graphical architecture rendering",applicableBuiltinFamilies:["architecture"]},timeline:{typeScript:"{ maxWidth?: number }",description:"Timeline layout controls.",defaultLabel:"`maxWidth`: unset",validationExpectation:"be a timeline options object",schema:Co({maxWidth:to("Best-effort width budget for horizontal timelines.")},"Timeline layout controls."),terminal:"not-applicable",terminalNote:"terminal output uses maxWidth or targetWidth",applicableBuiltinFamilies:["timeline"]},journey:{typeScript:"{ experienceCurve?: boolean }",description:"User-journey graphical controls.",defaultLabel:"`experienceCurve: true`",validationExpectation:"be a journey options object",schema:Co({experienceCurve:_s("Connect journey score markers with an experience curve.",true)},"User-journey graphical controls."),terminal:"not-applicable",terminalNote:"experience curves are graphical-only",applicableBuiltinFamilies:["journey"]},gantt:{typeScript:"{ dependencyArrows?: boolean; criticalPath?: boolean }",description:"Gantt dependency and critical-path overlays.",defaultLabel:"both `false`",validationExpectation:"be a Gantt options object",schema:Co({dependencyArrows:_s("Draw scheduled dependency connectors.",false),criticalPath:_s("Emphasize critical-path tasks and connectors.",false)},"Gantt dependency and critical-path overlays."),terminal:"not-applicable",terminalNote:"graphical Gantt connector emphasis is not represented in cells",applicableBuiltinFamilies:["gantt"]},mermaidConfig:{typeScript:"MermaidRuntimeConfig",description:"Mermaid-style recursive runtime configuration.",defaultLabel:"source config",validationExpectation:"be a plain JSON object",schema:{type:"object",description:"Mermaid-style recursive runtime configuration.",additionalProperties:{$ref:"#/$defs/jsonValue"}},terminal:"consumed"},embedFontImport:{typeScript:"boolean",description:"Embed the Google Fonts import in SVG styles; PNG forces this off for offline rasterization.",defaultLabel:"`false`",validationExpectation:"be a boolean",schema:_s("Embed the Google Fonts import in SVG styles; PNG forces this off for offline rasterization.",false),terminal:"not-applicable",terminalNote:"terminal output embeds no web-font import"},compact:{typeScript:"boolean",description:"Compact SVG serialization while preserving agent hooks.",defaultLabel:"`false`",validationExpectation:"be a boolean",schema:_s("Compact SVG serialization while preserving agent hooks.",false),terminal:"not-applicable",terminalNote:"compact controls SVG serialization"},idPrefix:{typeScript:"string",description:"Non-empty namespace for generated SVG definition IDs and local references.",defaultLabel:"unset",validationExpectation:"be non-empty and contain only ASCII letters, digits, underscore, hyphen, dot, and colon",schema:{...dp("Non-empty namespace for generated SVG definition IDs and local references."),pattern:"^[A-Za-z0-9_.:-]+$"},terminal:"not-applicable",terminalNote:"terminal output has no SVG definition ids"},security:{typeScript:"'default' | 'strict'",description:"Active SVG content is rejected in every mode; strict additionally rejects every external reference. Raw Mermaid themeCSS is rejected in both modes.",defaultLabel:"`default`",validationExpectation:"be default or strict",schema:{type:"string",enum:["default","strict"],description:"Active SVG content is rejected in every mode; strict additionally rejects every external reference. Raw Mermaid themeCSS is rejected in both modes.",default:"default"},terminal:"not-applicable",terminalNote:"terminal text has its own control-character and HTML-color safety projection"},ganttToday:{typeScript:"string",description:"Explicit deterministic date for the Gantt today marker.",defaultLabel:"unset",validationExpectation:"be a string",schema:dp("Explicit deterministic date for the Gantt today marker."),terminal:"consumed",applicableBuiltinFamilies:["gantt"]},seed:{typeScript:"number",description:"Deterministic re-roll seed for stochastic Styles.",defaultLabel:"`0`",validationExpectation:"be a finite number",schema:Dl("Deterministic re-roll seed for stochastic Styles.",0),terminal:"not-applicable",terminalNote:"terminal glyph geometry is deterministic and has no stochastic ink"}});var nd=Object.freeze(Object.keys(Ol));var oR=Object.freeze(nd.filter(e=>"applicableBuiltinFamilies"in Ol[e]));function $ee(e){const t=e.applicableRenderOptions;if(t===void 0)return;if(!Array.isArray(t)){throw new TypeError(`Family "${e.id}" applicableRenderOptions must be an array`)}const n=new Set;for(const i of t){if(typeof i!=="string"||!oR.includes(i)){throw new Error(`Family "${e.id}" applicableRenderOptions contains unknown family-scoped field "${String(i)}"`)}if(n.has(i)){throw new Error(`Family "${e.id}" applicableRenderOptions repeats "${i}"`)}n.add(i)}}function _ee(){const e=nd.map(t=>` ${t}?: ${Ol[t].typeScript}`);return`interface SharedRenderOptions {
7
+ ${e.join("\n")}
8
+ }`}function Qz(e){if(Array.isArray(e.enum))return e.enum.map(t=>JSON.stringify(t)).join(" | ");if(e.type==="string")return"string";if(e.type==="number"||e.type==="integer")return"number";if(e.type==="boolean")return"boolean";return"unknown"}function Dee(){const e=Object.entries(iR).map(([t,n])=>` ${t}?: ${Qz(n)}`);return`interface ArchitectureVisualOverrides {
9
+ ${e.join("\n")}
10
+ }`}function MS(e){const t=n=>{if(Array.isArray(n))return n.map(t);if(hr(n))return Object.fromEntries(Object.entries(n).map(([i,r])=>[i,t(r)]));return n};return t(e)}function sR(e){let t=String(e[0]??"");for(const n of e.slice(1))t+=typeof n==="number"?`[${n}]`:`.${n}`;return`render option "${t}"`}function aR(e){return eb(fC(e).map(t=>t.path.length>0?`${sR(t.path)} ${t.message}`:`render options ${t.message}`),"render options")}function lR(e,t,n){const i=t["x-agentic-mermaid-runtime-validator"];if(i==="safeCssColor"&&Sl(e)===void 0){return[{path:n,message:"must be a safe, non-fetching CSS color",generic:false}]}if(i==="safeCssPaint"&&Zn(e)===void 0){return[{path:n,message:"must be a safe, non-fetching CSS paint",generic:false}]}if(i==="safeCssFontFamily"&&xo(e)===void 0){return[{path:n,message:"must be a safe, non-fetching CSS font family or stack",generic:false}]}if(i==="styleInput"){try{wC(e)}catch(r){return[{path:n,message:`is invalid: ${r instanceof Error?r.message:String(r)}`,generic:false}]}}if(i==="architectureVisual"&&hr(e)){const r=e.junctionOuterRadius;const o=e.junctionInnerRadius;if(typeof r==="number"&&typeof o==="number"&&o>r){return[{path:[...n,"junctionInnerRadius"],message:"must not exceed junctionOuterRadius",generic:false}]}}return[]}var Zz;function cR(e){if(!hr(e))return["render options must be a plain JSON object"];const t=aR(e);if(t.length>0)return t;const n=[];const i=Zz??=Qx(eG());for(const[r,o]of Object.entries(e)){if(!Object.hasOwn(Ol,r)){n.push(`unknown render option "${r}"`);continue}if(o===null){n.push(`render option "${r}" must be omitted instead of null`);continue}const s=Ol[r];const a=Vb(o,s.schema,i,[r],{diagnostics:"field",validateRuntime:lR});if(a.length>0&&a.every(l=>l.generic&&l.path.length===1)){n.push(`render option "${r}" must ${s.validationExpectation}`)}else{n.push(...a.map(l=>`${sR(l.path)} ${l.message}`))}}return eb(n,"render options")}function eG(){const e={};for(const t of nd){const n=Ol[t];const i="terminalNote"in n?n.terminalNote:void 0;const r="applicableBuiltinFamilies"in n?n.applicableBuiltinFamilies:void 0;e[t]={...MS(n.schema),"x-agentic-mermaid-terminal":n.terminal,...i===void 0?{}:{"x-agentic-mermaid-terminal-note":i},...r===void 0?{}:{"x-agentic-mermaid-applicable-builtin-families":[...r]}}}return{$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://agentic-mermaid.dev/schemas/render-options.schema.json",type:"object",additionalProperties:false,properties:e,$defs:{jsonValue:MS(wS)}}}function Oee(e){return{...MS(rR),...e===void 0?{}:{description:e}}}var kS=class extends Error{constructor(n,i){super(`Parsed Mermaid family "${n}" serialized as family "${i}"`);this.expectedFamilyId=n;this.detectedFamilyId=i}expectedFamilyId;detectedFamilyId;name="ParsedDiagramFamilyMismatchError";code="PARSED_DIAGRAM_FAMILY_MISMATCH"};var _l=class extends Error{name="RenderCapabilityError";code="UNSATISFIED_RENDER_CAPABILITIES";output;family;decision;constructor(t,n,i,r){super(t);this.output=n;this.family=Object.freeze({id:i.identity.id,version:i.identity.version});this.decision=r}toJSON(){return{name:this.name,code:this.code,message:this.message,output:this.output,family:this.family,decision:this.decision}}};var $r=class extends TypeError{constructor(t){super(t);this.name="RenderConfigError"}};var Ku=new WeakMap;function Yi(e){const t=Ku.get(e);if(!t)throw new Error("Resolved render request has no internal execution plan");return t}function tG(e,t){if(e.id.startsWith("family:")){const i=new Set(e.applicableRenderOptions??[]);return Object.freeze(t.flatMap(r=>{if(!oR.includes(r)||i.has(r))return[];return[Object.freeze({code:"RENDER_OPTION_NOT_APPLICABLE",feature:`render-option:${r}`,message:`Render option "${r}" does not apply to extension family "${e.id}". Its FamilyDescriptor does not list the field in applicableRenderOptions.`})]}))}const n=e.id;return Object.freeze(t.flatMap(i=>{const r=Ol[i];if(!("applicableBuiltinFamilies"in r))return[];const o=r.applicableBuiltinFamilies;if(o.includes(n))return[];const s=o.length===0?"No built-in family currently consumes this option.":`Applicable built-in families: ${o.join(", ")}.`;return[Object.freeze({code:"RENDER_OPTION_NOT_APPLICABLE",feature:`render-option:${i}`,message:`Render option "${i}" does not apply to built-in Mermaid family "${n}". ${s}`})]}))}function nG(e,t){const n=new Set;return Object.freeze([...Object.hasOwn(e,"resolutionDiagnostics")?e.resolutionDiagnostics:[],...t,...Uo(e).flatMap(i=>i.requested==="agentic"&&i.selected==="elk"?[{code:"GRAPH_LAYOUT_FALLBACK",feature:"graph-layout",message:`Agentic graph layout used the requested ELK fallback: ${i.reason??"candidate rejected"}`}]:[])].flatMap(i=>{const r=Bl(i);if(n.has(r))return[];n.add(r);return[Object.freeze({...i})]}))}function dR(e,t=[]){const n=Ku.get(e);const i=n?.executionDecision;const r=n&&Object.hasOwn(n,"textMeasurement")?n.textMeasurement:void 0;return Object.freeze({version:e.version,output:e.output,sharedRequestDigest:e.sharedRequestDigest,requestDigest:e.requestDigest,appearanceDigest:e.appearance.digest,capabilityDecision:e.capabilityDecision,diagnostics:nG(e,t),...i?{executionDecision:i}:{},...r?{textMeasurement:r.identity}:{},...Uo(e).length?{layoutDecisions:Uo(e)}:{}})}function Wl(e){const t=VE.get(e);if(t)return t;const n=Ku.get(e)?.backend?.identity.id??(e.output==="layout"?`backend:${e.appearance.inferredBackend}`:void 0);const i=Object.freeze({renderOptions:e.renderOptions,...e.appearance.face?{styleFace:e.appearance.face}:{},...n?{paintBackendId:n}:{},...e.familyConfig?{familyConfig:e.familyConfig}:{},...e.appearance.family?{familyAppearance:e.appearance.family}:{}});if(Ku.has(e))VE.set(e,i);return i}var VE=new WeakMap;function iG(e,t,n){const i={...e};const r=s=>Gi[s].some(a=>n?.[a]!==void 0);const o=["bg","fg","line","accent","muted","surface","border"];for(const s of o){if(i[s]===void 0&&!r(s)&&t.colors?.[s]!==void 0){i[s]=t.colors[s]}}if(i.font===void 0&&t.font!==void 0)i.font=t.font;return i}function CS(e){const t={};for(const n of nd){const i=e[n];if(i!==void 0)t[n]=i}return t}var rG=new Set(["padding","nodeSpacing","layerSpacing","wrappingWidth","class"]);function oG(e){return Object.fromEntries(Object.entries(e).filter(([t,n])=>n!==void 0&&!Uz.includes(t)))}function sG(e,t){if(t.kind==="registered")return t.family;throw new vm(MP(t.kind==="unknown"?{...t,header:e.lines[0]??e.firstLine}:t,e.originalText,e.authoredWrapperLength??e.wrapperSource?.length??0,e.authoredHeader??e.lines[0]??e.firstLine,null))}function aG(e,t,n){if(n.onConfigDiagnostic!==void 0){throw new TypeError(`Family "${e.id}" request normalizer may not return executable option "onConfigDiagnostic"`)}const i=cR(oG(n));if(i.length>0){throw new $r(`Family "${e.id}" returned invalid normalized RenderOptions: ${i.join("; ")}`)}const r=CS(t);const o=CS(n);for(const s of nd){if(rG.has(s))continue;if(Bl(r[s])!==Bl(o[s])){throw new TypeError(`Family "${e.id}" request normalizer may not rewrite non-geometry option "${s}"`)}}}function lG(e,t,n){const i=new Set(["bg","fg","line","accent","muted","surface","border","shadow","font","embedFontImport"]);const r=Object.keys(t).find(s=>!i.has(s));if(r)throw new TypeError(`Family "${e.id}" returned unknown appearance color field "${r}"`);const o={...n};for(const s of["bg","fg","line","accent","muted","surface","border"]){const a=t[s];if(a===void 0)continue;const l=Zn(a);if(l===void 0)throw new $r(`Family "${e.id}" returned an unsafe ${s} paint`);o[s]=l}if(t.font!==void 0){const s=xo(t.font);if(s===void 0)throw new $r(`Family "${e.id}" returned an unsafe font family`);if(s!==n.font){throw new TypeError(`Family "${e.id}" request normalizer may not rewrite appearance field "font"`)}}if(t.shadow!==void 0){if(typeof t.shadow!=="boolean")throw new TypeError(`Family "${e.id}" returned a non-boolean shadow value`);if(t.shadow!==n.shadow){throw new TypeError(`Family "${e.id}" request normalizer may not rewrite appearance field "shadow"`)}}if(t.embedFontImport!==void 0){if(typeof t.embedFontImport!=="boolean")throw new TypeError(`Family "${e.id}" returned a non-boolean embedFontImport value`);if(t.embedFontImport!==n.embedFontImport){throw new TypeError(`Family "${e.id}" request normalizer may not rewrite appearance field "embedFontImport"`)}}return o}var KE=64;var ed=1e5;var td=2e6;function Ju(e,t="$",n=0,i=new Set,r={nodes:0,chars:0,opaque:false,admission:void 0}){const o=r.admission;if(o?.valid){if(++o.nodes>Cl.maxNodes||n>Cl.maxDepth)o.valid=false;switch(typeof e){case"number":if(e-e!==0)o.valid=false;break;case"undefined":case"bigint":case"symbol":case"function":o.valid=false}}if(typeof e==="string"){r.chars+=e.length;if(r.chars>td)throw new TypeError(`data exceeds the ${td}-character aggregate limit at ${t}`);return e}if(e===null||typeof e!=="object")return e;if(n>KE)throw new TypeError(`data exceeds maximum depth ${KE} at ${t}`);if(++r.nodes>ed)throw new TypeError(`data exceeds the ${ed}-node aggregate limit at ${t}`);if(i.has(e))throw new TypeError(`data must be acyclic at ${t}`);if(Array.isArray(e)){if(e.length>ed)throw new TypeError(`data array exceeds the ${ed}-entry limit at ${t}`);i.add(e);try{const s=[];const a=Object.create(null);a.enumerable=a.configurable=a.writable=true;for(let l=0;l<e.length;l++){if(l>=ed)throw new TypeError(`data array exceeds the ${ed}-entry limit at ${t}`);if(!Object.prototype.hasOwnProperty.call(e,l))throw new TypeError(`data must not contain a sparse array at ${t}[${l}]`);const c=Ju(e[l],`${t}[${l}]`,n+1,i,r);a.value=c;Object.defineProperty(s,l,a)}if(o&&s.length>Cl.maxItemsPerContainer)o.valid=false;return PS(s,!r.opaque)}finally{i.delete(e)}}if(!hr(e)){r.opaque=true;if(o)o.valid=false;return e}i.add(e);try{const s={};let a=0;for(const[l,c]of Object.entries(e)){r.chars+=l.length;if(r.chars>td)throw new TypeError(`data exceeds the ${td}-character aggregate limit at ${t}.${l}`);if(c!==void 0){if(o&&(++a>Cl.maxItemsPerContainer||xm(l)))o.valid=false;const d=Ju(c,`${t}.${l}`,n+1,i,r);if(l in s)Object.defineProperty(s,l,{value:d,enumerable:true});else s[l]=d}}return PS(s,!r.opaque)}finally{i.delete(e)}}function JE(e,t,n,i=false){if(t===void 0)return void 0;if(!hr(t)){throw new TypeError(`Family "${e.id}" returned ${n} data that is not a plain object`)}if(i)return t;let r;try{r=Ju(t)}catch(a){throw new TypeError(`Family "${e.id}" returned invalid ${n} data: ${a instanceof Error?a.message:String(a)}`)}const o={...wS,$defs:{jsonValue:wS}};const s=Vb(r,o,o,[`family${n==="config"?"Config":"Appearance"}`],{diagnostics:"field",validateRuntime:lR});if(s.length>0){const a=s.map(l=>`${l.path.join(".")} ${l.message}`).join("; ");throw new TypeError(`Family "${e.id}" returned invalid ${n} data: ${a}`)}return ti(r)}function cG(e,t,n,i,r,o){if(!e.normalizeRequest)return{renderOptions:n,colors:i};const s=Object.freeze({source:ti(t),renderOptions:ti(n),colors:ti(i),...r?{style:ti(r)}:{},...o?{styleFace:ti(o)}:{}});const a=e.normalizeRequest(s);if(a===void 0)return{renderOptions:n,colors:i};let l;const c={nodes:0,valid:true};try{l=ES(a,`Family "${e.id}" request normalizer result`,c)}catch(y){throw new TypeError(`Family "${e.id}" request normalizer returned invalid data: ${y instanceof Error?y.message:String(y)}`)}if(!hr(l)){throw new TypeError(`Family "${e.id}" request normalizer must return a plain object`)}const d=Object.keys(l).find(y=>!["renderOptions","familyConfig","appearance"].includes(y));if(d){throw new TypeError(`Family "${e.id}" request normalizer returned unknown field "${d}"`)}const u=l;const f=u.appearance;if(f!==void 0){const y=f;if(!hr(y)){throw new TypeError(`Family "${e.id}" request normalizer returned a non-object appearance`)}const w=Object.keys(y).find(S=>!["colors","family"].includes(S));if(w){throw new TypeError(`Family "${e.id}" request normalizer returned unknown appearance field "${w}"`)}}const h=u.renderOptions??n;aG(e,n,h);const m=f?.colors?lG(e,f.colors,i):i;const p=JE(e,u.familyConfig,"config",c.valid);const g=JE(e,f?.family,"appearance",c.valid);return{renderOptions:h,colors:m,...p?{familyConfig:p}:{},...g?{familyAppearance:g}:{}}}function Bl(e){if(e===null||typeof e!=="object")return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(Bl).join(",")}]`;const t=e;let n="{",i="";for(const r of Object.keys(t).sort()){const o=t[r];if(o===void 0)continue;n+=`${i}${JSON.stringify(r)}:${Bl(o)}`;i=","}return`${n}}`}function QE(e,t){try{return dG(e)}catch(n){if(n instanceof TypeError&&/aggregate limit/.test(n.message)){throw new Ts("sourceCharacters",t.originalText.length+t.text.length,true)}throw n}}function uR(e){return id(Bl(fR(e)))}function dG(e){let t=fR(e);let n;return()=>{if(n===void 0){n=id(Bl(t));t=void 0}return n}}function fR(e){let t;const n={nodes:0,valid:td<=Cl.maxAggregateTextCharacters&&td*3<=Cl.maxAggregateTextBytes};try{t=ES(e,"render contract digest input",n)}catch(i){const r=(i instanceof Error?i.message:String(i)).replace("data exceeds maximum depth","data exceeds maximum nesting depth");throw new TypeError(r)}if(!n.valid)Ms(t,"render contract digest input",{allowUndefinedObjectProperties:true});return t}function id(e){let t=3421674724|0;let n=2216829733|0;for(let i=0;i<e.length;i++){const r=n^e.charCodeAt(i);const o=(r>>>16)*435+((r&65535)*435>>>16)>>>16;n=Math.imul(r,435);t=Math.imul(t,435)+o+(r<<8)|0}return`fnv1a64:${(t>>>0).toString(16).padStart(8,"0")}${(n>>>0).toString(16).padStart(8,"0")}`}var hR=new WeakSet;function PS(e,t=true){Object.freeze(e);if(t)hR.add(e);return e}function ti(e,t="$",n,i){if(e===null||typeof e!=="object")return e;if(hR.has(e))return e;n??=new Set;i??=new WeakMap;if(n.has(e))throw new TypeError(`render request contains a cycle at ${t}`);const r=i.get(e);if(r)return r;const o=Object.getPrototypeOf(e);if(!Array.isArray(e)&&o!==Object.prototype&&o!==null){throw new TypeError(`render request contains a non-JSON object at ${t}`)}n.add(e);let s;if(Array.isArray(e)){const a=e.length;const l=new Array(a);for(let c=0;c<a;c++){if(c in e)l[c]=ti(e[c],`${t}[${c}]`,n,i)}s=l}else{const a={};for(const[l,c]of Object.entries(e)){const d=ti(c,`${t}.${l}`,n,i);if(l in a)Object.defineProperty(a,l,{value:d,enumerable:true});else a[l]=d}s=a}n.delete(e);i.set(e,s);return PS(s)}function ES(e,t,n){try{return ti(n?Ju(e,"$",0,new Set,{nodes:0,chars:0,opaque:false,admission:n}):Ju(e))}catch(i){throw new TypeError(`${t} could not be snapshotted: ${i instanceof Error?i.message:String(i)}`)}}var uG=Object.freeze({serializable:ti({})});var fG=new WeakMap;var hG=new WeakMap;function mG(e){if(typeof e!=="object"&&typeof e!=="function"||e===null){throw new $r("Invalid RenderOptions: render options must be an object")}const t=fG.get(e);if(t)return t;const n=[];let i;for(const[s,a]of Object.entries(e)){if(s==="onConfigDiagnostic"){i=a}else if(a!==void 0){n.push([s,a])}}if(i!==void 0&&typeof i!=="function"){throw new $r("Invalid RenderOptions: onConfigDiagnostic must be a function")}if(n.length===0&&i===void 0)return uG;const r=Object.fromEntries(n);let o;try{o=ES(r,"RenderOptions")}catch(s){const a=(s instanceof Error?s.message:String(s)).replace("data exceeds maximum depth","render option tree exceeds maximum nesting depth");throw new $r(`Invalid RenderOptions: ${a}`)}return Object.freeze({serializable:o,...i===void 0?{}:{onConfigDiagnostic:i}})}function pG(e){const t=e===void 0?[]:Array.isArray(e)?e:[e];return ti(t.flatMap(n=>{if(typeof n!=="string"||n==="crisp")return[];const i=bC(n);if(!i)return[];return[{input:n,canonicalId:i.canonicalId}]}))}function gG(e){const t=new Set;for(const n of Object.values(Gi)){for(const i of n){const r=e.config.themeVariables?.[i];if(typeof r==="string"&&r.length>0&&Sl(r)===void 0)t.add(i)}}return Object.freeze([...t].sort())}var RS="1.0.0";function Pa(e,t,n=RS){return t?[{id:e,version:n}]:[]}function eo(e,t=`^${RS}`){return{id:e,range:t,level:"required"}}function ZE(e){return`scene-primitive:${e.primitive}/${e.feature}/${e.operation}`}function yG(e){const t=new Set(e.scenePrimitiveEvidence.filter(n=>n.applicability==="applicable").map(n=>n.primitive));return tb.filter(n=>t.has(n.primitive))}var eR=new WeakMap;function tR(e,t){let n=eR.get(e.backend);if(!n){n=new Set(tb.filter(i=>e.backend.capabilities.some(r=>r.primitive===i.primitive&&r.feature===i.feature&&r.operation===i.operation&&r.realization!=="unsupported")));eR.set(e.backend,n)}return n.has(t)}function xG(e){return e.resolutions.filter(t=>t.level==="required"&&t.status!=="selected").map(t=>t.id).join(", ")}function bG(e,t,n,i,r,o){const s=xG(o);const a=s?` (unsatisfied capabilities: ${s})`:"";if(e==="layout"){return new _l(`No public layout projection registered for Mermaid family "${t.id}"${a}`,e,t,o)}if(e==="ascii"||e==="unicode"||e==="html"){return new _l(`No ASCII renderer registered for Mermaid family ${t.id}${a}`,e,t,o)}if(n.styled&&!t.lowerScene){return new _l(`Family "${t.id}" does not support styled rendering (no SceneGraph lowering registered). Render without the style option, or register a lowerScene hook for the family.${a}`,e,t,o)}if(i==="scene"&&t.layout&&t.lowerScene&&!r){return new _l(n.styled?`Style "${n.style?.name??"(inline)"}" requires an unavailable SceneGraph backend${a}`:`Default SceneGraph backend is not registered${a}`,e,t,o)}return new _l(`No SVG renderer registered for Mermaid family ${t.id}${a}`,e,t,o)}var SS=new Map;function SG(e,t,n,i){const r=t.length+n.length;if(typeof e!=="string"||r>256)return void 0;let o=e.length+r*16;if(o>16384)return void 0;let s=`${e.length}:${e};${i};${t.length};${n.length};`;for(const a of t){if(typeof a.id!=="string"||typeof a.version!=="string")return void 0;o+=a.id.length+a.version.length;if(o>16384)return void 0;s+=`${a.id.length}:${a.id}${a.version.length}:${a.version}`}for(const a of n){if(typeof a.id!=="string"||typeof a.range!=="string"||typeof a.level!=="string")return void 0;o+=a.id.length+a.range.length+a.level.length;if(o>16384)return void 0;s+=`${a.id.length}:${a.id}${a.range.length}:${a.range}${a.level.length}:${a.level}`}return s.length<=8192?s:void 0}function wG(e,t,n,i){const r=SG(e,t,n,i);const o=r===void 0?void 0:SS.get(r);jt("capability-decision",r===void 0?"bypass":o?"hit":"miss",r===void 0?"tuple-budget":void 0);if(o)return o;const s=N1(e,{offers:t,requirements:n,outputAvailable:i});if(r!==void 0){if(SS.size<32)SS.set(r,s);else jt("capability-decision","store-skipped","capacity")}return s}function MG(e,t,n,i,r,o){let s;let a;let l;if(n==="svg"||n==="png"){s=t.styled||e.lowerScene?"scene":"family-svg";if(s==="scene"){l=t.styled?t.inferredBackend:"default";a=AC(l,i.backendPolicy)}}else if(n==="layout"){s="layout"}else{s="terminal"}const c=s==="scene"?yG(e):[];const d=a?c.flatMap(w=>Pa(ZE(w),tR(a,w))):[];const u=[{id:e.identity.id,version:e.identity.version},...Pa("operation:layout",e.layout!==void 0),...Pa("operation:project-positioned",e.projectPositioned!==void 0),...Pa("operation:lower-scene",e.lowerScene!==void 0),...Pa("operation:render-svg",e.renderSvg!==void 0),...Pa("operation:render-terminal",e.renderAscii!==void 0),...Pa("core:scene",s==="scene"),...Pa("backend:scene-renderer",a!==void 0,a?.identity.version),...d];const f=[eo("core:family-descriptor"),eo(e.identity.id,e.identity.version)];let h;switch(s){case"scene":f.push(eo("core:scene"),eo("operation:layout"),eo("operation:lower-scene"),eo("backend:scene-renderer",a?.identity.version??RS),...c.map(w=>eo(ZE(w))));h=Boolean(e.layout&&e.lowerScene&&a&&c.every(w=>tR(a,w)));break;case"family-svg":f.push(eo("operation:layout"),eo("operation:render-svg"));h=Boolean(e.layout&&e.renderSvg);break;case"terminal":f.push(eo("operation:render-terminal"));h=e.renderAscii!==void 0;break;case"layout":f.push(eo("operation:layout"),eo("operation:project-positioned"));h=Boolean(e.layout&&e.projectPositioned);break}const m=wG(n,u,f,h);if(!m.accepted){throw bG(n,e,t,s,a,m)}const p=s==="terminal"?void 0:$1(i.textMeasurement,t.font);let g;if(s==="scene"||s==="family-svg"){const w=s==="scene"?Object.freeze({mode:"scene",requestedId:l,selectedId:a.identity.id,version:a.identity.version,hostPolicy:i.backendPolicy!==void 0}):Object.freeze({mode:"family-svg"});const S={family:Object.freeze({id:e.identity.id,version:e.identity.version}),backend:w,...p?{textMeasurement:p.identity}:{}};g=Object.freeze({...S,digest:uR(S)})}const y=r===void 0?void 0:Object.freeze(qE(e.id,r,e.config,e.configDiagnostics).map(w=>Object.freeze({...w})));return Object.freeze({output:n,mode:s,family:e,...a?{backend:a}:{},...l?{requestedBackendId:l}:{},...y===void 0?{}:{configDiagnostics:y},...o?{onConfigDiagnostic:o}:{},capabilityDecision:m,...g?{executionDecision:g}:{},...p?{textMeasurement:p}:{}})}function kG(e){return!e.id.startsWith("output:")&&!e.id.startsWith("operation:")&&!e.id.startsWith("backend:")&&!e.id.startsWith("scene-primitive:")&&e.id!=="core:scene"}function CG(e){const{family:t,source:n,options:i,style:r,styleFace:o}=e;let s=i.security==="strict"?{...i,embedFontImport:false}:{...i};if(i.graphLayout)s.graphLayout={...i.graphLayout,fallback:i.graphLayout.fallback??"none"};const a=r!==void 0&&kC(r);if(a)s=iG(s,r,n.config.themeVariables);const l=i.font??n.config.fontFamily??Gb(n.config.themeVariables,"fontFamily")??s.font??"Inter";const c=xo(l)??l;const{style:d,...u}=s;const f={...u,...r?{style:r}:{},font:c,mermaidConfig:n.config};const h={...Zm(f,n.config,c)};const m=cG(t,n,f,h,r,o);const p=ti(m.colors);const g=hG.get(i)??pG(i.style);const y=gG(n);const w={version:wm,colors:p,font:c,style:ti(r),face:ti(o),styled:a,inferredBackend:r?SC(r):"default",styleReferences:g,...y.length>0?{unsafeThemeColorKeys:y}:{},...m.familyAppearance?{family:m.familyAppearance}:{}};const S=ti({...w,digest:uR(w)});return ti({renderOptions:ti(m.renderOptions),appearance:S,...m.familyConfig?{familyConfig:m.familyConfig}:{}})}function Bee(e,t={},n="svg",i){return vS(e,t,n,i)}function vS(e,t={},n="svg",i,r={}){const o=mG(t);const s=o.serializable;const a=s;const l=aR(a);if(l.length>0){throw new $r(`Invalid RenderOptions: ${l.join("; ")}`)}const c=o.capturedStyle??MC(s.style);const d=c.style;const u=ti(c.face);const f=o.capturedStyle?[]:cR(a);if(f.length>0){throw new $r(`Invalid RenderOptions: ${f.join("; ")}`)}let h;const m=IE(e,s.mermaidConfig??{},F=>{if(r.familyDescriptor)return r.familyDescriptor;h=Cb(F);return h.kind==="registered"?h.family:null});const p=ti(m);const g=r.familyDescriptor??sG(p,h);const y=p;if(r.expectedFamilyId!==void 0&&g.id!==r.expectedFamilyId){throw new kS(r.expectedFamilyId,g.id)}Ve("sourceCharacters",y.originalText.length+y.text.length);const w=hC(y.config.themeCSS,s.security??"default");if(w)throw new $r(w);if(g.id!=="architecture")gS(y.config.themeVariables,g.id,s);YE(y.frontmatter,g.id);const S=Object.freeze(nd.filter(F=>s[F]!==void 0));const x=tG(g,S);const M=CG({family:g,source:y,options:s,...d?{style:d}:{},...u?{styleFace:u}:{}});const{appearance:b,renderOptions:C,familyConfig:P}=M;const E=b.family?.visual;if(g.id==="architecture"){gS(y.config.themeVariables,g.id,s,E)}jE(s,g.id,E);const k=MG(g,b,n,r,s.mermaidConfig,o.onConfigDiagnostic);const v=k.capabilityDecision;const T=Object.freeze(v.resolutions.filter(kG));const A=Object.freeze({version:v.version,accepted:T.every(F=>F.level!=="required"||F.status==="selected"),resolutions:T});const R={version:wm,authoredSource:y.originalText,source:y.text,options:CS(C),appearance:b.digest,...P?{familyConfig:P}:{},...k.textMeasurement?{textMeasurement:k.textMeasurement.identity}:{},capabilities:A};const I=QE(R,y);const L={...R,output:n,outputOptions:i,capabilities:v};const $=QE(L,y);const B=Object.freeze({version:wm,output:n,source:ti(y),renderOptions:C,appearance:b,...P?{familyConfig:P}:{},capabilityDecision:v,explicitOptionFields:S,...x.length===0?{}:{resolutionDiagnostics:x},get sharedRequestDigest(){return I()},get requestDigest(){return $()}});Ku.set(B,k);return B}var TS=128;function zl(e,t,n,i){if(e.length<32||e.length>268435456)return null;let r=Infinity,o=-Infinity,s=0;i?.(2*e.length,"capacity");const a=new Float64Array(e.length),l=new Float64Array(e.length);for(let h=0;h<e.length;h++){i?.(1,"work");const m=e[h];const p=m[t]-n;const g=m[t]+(t==="x"?m.width:m.height)+n;const y=Math.floor(p/TS),w=Math.floor(g/TS);if(!Number.isSafeInteger(y)||!Number.isSafeInteger(w)||w<y)return null;s+=w-y+1;if(s>8*e.length)return null;a[h]=y;l[h]=w;r=Math.min(r,y);o=Math.max(o,w)}i?.(1,"work");const c=o-r+1;if(!Number.isSafeInteger(c)||c>8*e.length)return null;i?.(c+1,"capacity");const d=new Uint32Array(c+1);for(let h=0;h<e.length;h++){for(let m=a[h]-r;m<=l[h]-r;m++){i?.(1,"work");d[m+1]++}}for(let h=1;h<=c;h++){i?.(1,"work");d[h]+=d[h-1]}i?.(c+s,"capacity");const u=d.slice(0,c),f=new Uint32Array(s);for(let h=0;h<e.length;h++){for(let m=a[h]-r;m<=l[h]-r;m++){i?.(1,"work");f[u[m]++]=h}}return{firstCell:r,offsets:d,ordinals:f}}function up(e,t){const n=Math.floor(t/TS);return Number.isSafeInteger(n)?n-e.firstCell:null}function mR(e,t,n,i){if(!e)return void 0;if(e[n]===void 0)e[n]=zl(t,n,i);return e[n]}function PG(e){let t=Infinity,n=-Infinity,i=Infinity,r=-Infinity;for(const o of e){const s=o.x,a=o.y;if(!Number.isFinite(s)||!Number.isFinite(a))return null;t=Math.min(t,s);n=Math.max(n,s);i=Math.min(i,a);r=Math.max(r,a)}return{minX:t,maxX:n,minY:i,maxY:r}}function pR(e,t,n,i,r,o,s,a){if(!Number.isFinite(i)||!Number.isFinite(r)||!Number.isFinite(o))return true;if(t.points.length<2)return false;let l=e.get(t);if(l===void 0){l=PG(t.points);e.set(t,l)}if(!l)return true;const c=n==="x"?l.minX:l.minY;const d=n==="x"?l.maxX:l.maxY;if(i<c&&c-i>=s)return false;if(i>d&&i-d>=s)return false;const u=n==="x"?l.minY:l.minX;const f=n==="x"?l.maxY:l.maxX;return Math.min(o,f)-Math.max(r,u)>a}var gR=new WeakMap;var no=e=>({fill:e.fill,stroke:e.stroke,strokeWidth:e.strokeWidth});var hp=e=>({stroke:e.stroke,strokeWidth:e.strokeWidth});var qi=(e,t)=>({geometry:{kind:"polygon",points:e},paint:no(t),routing:{kind:"polygon",points:e}});var rr=(e,t,n,i={})=>({geometry:{kind:"path",d:t},paint:{...no(n),fill:i.fill==="none"?"none":n.fill},routing:{kind:"envelope",x:e.x,y:e.y,width:e.width,height:e.height,reason:i.reason??"closed curved path uses a conservative routing envelope"}});function _r(e,t,n){const i=LG(e,t);if(i)return i;const{x:r,y:o,width:s,height:a}=e;const l=r+s/2,c=o+a/2;switch(e.shape){case"state-note":{const d=Math.min(12,s/6,a/4);return qi([{x:r,y:o},{x:r+s-d,y:o},{x:r+s,y:o+d},{x:r+s,y:o+a},{x:r,y:o+a}],t)}case"diamond":case"state-choice":return qi([{x:l,y:c-a/2},{x:l+s/2,y:c},{x:l,y:c+a/2},{x:l-s/2,y:c}],t);case"stadium":{const d=a/2;return{geometry:{kind:"rect",x:r,y:o,width:s,height:a,rx:d,ry:d},paint:no(t),routing:{kind:"stadium",cx:l,cy:c,halfWidth:s/2,radius:d}}}case"ellipse":return{geometry:{kind:"ellipse",cx:l,cy:c,rx:s/2,ry:a/2},paint:no(t),routing:{kind:"ellipse",cx:l,cy:c,rx:s/2,ry:a/2}};case"circle":case"state-history":return wR(l,c,Math.min(s,a)/2,t);case"doublecircle":return IG(l,c,Math.min(s,a)/2,t);case"hexagon":{const d=a/4;return qi([{x:r+d,y:o},{x:r+s-d,y:o},{x:r+s,y:c},{x:r+s-d,y:o+a},{x:r+d,y:o+a},{x:r,y:c}],t)}case"cylinder":return NG(r,o,s,a,t);case"asymmetric":return qi([{x:r+12,y:o},{x:r+s,y:o},{x:r+s,y:o+a},{x:r+12,y:o+a},{x:r,y:c}],t);case"trapezoid":{const d=s*.15;return qi([{x:r+d,y:o},{x:r+s-d,y:o},{x:r+s,y:o+a},{x:r,y:o+a}],t)}case"trapezoid-alt":{const d=s*.15;return qi([{x:r,y:o},{x:r+s,y:o},{x:r+s-d,y:o+a},{x:r+d,y:o+a}],t)}case"lean-r":{const d=s*.15;return qi([{x:r+d,y:o},{x:r+s,y:o},{x:r+s-d,y:o+a},{x:r,y:o+a}],t)}case"lean-l":{const d=s*.15;return qi([{x:r,y:o},{x:r+s-d,y:o},{x:r+s,y:o+a},{x:r+d,y:o+a}],t)}case"subroutine":return FG(r,o,s,a,t,n??0);case"state-start":return $G(l,c,Math.max(0,Math.min(s,a)/2-2));case"state-end":return _G(l,c,Math.max(0,Math.min(s,a)/2-2));case"state-fork":case"state-join":return DG(r,o,s,a);case"rounded":return yR(r,o,s,a,t,n??6);case"service":case"rectangle":default:return yR(r,o,s,a,t,n??0)}}function bi(e){const t=gR.get(e);if(t&&t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height&&t.shape===e.shape&&t.semanticShape===e.semanticShape){return t.profile}const n=_r(e,{fill:"",stroke:"",strokeWidth:""}).routing;const i=TG(e);const r={};for(const s of["N","E","S","W"]){const a=EG(n,s)??i[s];if(n.kind==="none"){r[s]={kind:"none",preferred:a};continue}if(n.kind==="envelope"){const[c,d]=bR(n,s);r[s]={kind:"envelope",lo:c,hi:d,preferred:a};continue}const l=RG(e,n,s);r[s]=l?{kind:"dynamic",...l,preferred:a}:{kind:"port",point:a,preferred:a}}const o={boundary:n,sides:r};gR.set(e,{x:e.x,y:e.y,width:e.width,height:e.height,shape:e.shape,semanticShape:e.semanticShape,profile:o});return o}function rd(e){const t=bi(e);return{N:{...t.sides.N.preferred},E:{...t.sides.E.preferred},S:{...t.sides.S.preferred},W:{...t.sides.W.preferred}}}function Ds(e,t,n){return SR(e,t==="E"||t==="W"?"x":"y",n,t==="E"||t==="S")}function xR(e,t,n){const i=e.sides[t];if(i.kind==="none")return null;if(i.kind==="port")return i.point;return Ds(e.boundary,t,n)}function EG(e,t){const n=AS(e);if(!n)return null;const i=t==="E"||t==="W"?"x":"y";const r=i==="x"?n.y+n.height/2:n.x+n.width/2;return SR(e,i,r,t==="E"||t==="S")}function bR(e,t){const n=AS(e);return t==="E"||t==="W"?[n.y,n.y+n.height]:[n.x,n.x+n.width]}function RG(e,t,n){const[i,r]=bR(t,n);if(t.kind==="rect")return Qu(i,r,4);if(t.kind==="stadium"&&(n==="N"||n==="S")){return Qu(t.cx-(t.halfWidth-t.radius),t.cx+(t.halfWidth-t.radius),2)}if(t.kind==="cylinder"&&(n==="E"||n==="W")){return Qu(t.y+t.capRadiusY,t.y+t.height-t.capRadiusY,2)}if(t.kind!=="polygon")return null;const o=AS(t);const s=n==="E"||n==="W"?"x":"y";const a=s==="x"?n==="E"?o.x+o.width:o.x:n==="S"?o.y+o.height:o.y;const l=[];for(let c=0;c<t.points.length;c++){const d=t.points[c];const u=t.points[(c+1)%t.points.length];if(Math.abs(d[s]-a)>1e-9||Math.abs(u[s]-a)>1e-9)continue;const f=s==="x"?d.y:d.x;const h=s==="x"?u.y:u.x;l.push([Math.min(f,h),Math.max(f,h)])}if(l.length>0){const c=l.sort((d,u)=>u[1]-u[0]-(d[1]-d[0]))[0];return Qu(c[0],c[1],2)}if(t.points.length===4&&vG(t.points,o)){const c=r-i;const d=c<=40?c/4:10;return Qu(i,r,d)}return null}function Qu(e,t,n){return t-e>n*2?{lo:e+n,hi:t-n}:null}function vG(e,t){const n=t.x+t.width/2;const i=t.y+t.height/2;const r=[{x:n,y:t.y},{x:t.x+t.width,y:i},{x:n,y:t.y+t.height},{x:t.x,y:i}];return e.every(o=>r.some(s=>Math.abs(o.x-s.x)<1e-8&&Math.abs(o.y-s.y)<1e-8))}function AS(e){switch(e.kind){case"rect":case"envelope":return{x:e.x,y:e.y,width:e.width,height:e.height};case"ellipse":return{x:e.cx-e.rx,y:e.cy-e.ry,width:e.rx*2,height:e.ry*2};case"stadium":return{x:e.cx-e.halfWidth,y:e.cy-e.radius,width:e.halfWidth*2,height:e.radius*2};case"cylinder":return{x:e.cx-e.width/2,y:e.y,width:e.width,height:e.height};case"polygon":{if(e.points.length===0)return null;const t=e.points.map(o=>o.x);const n=e.points.map(o=>o.y);const i=Math.min(...t),r=Math.min(...n);return{x:i,y:r,width:Math.max(...t)-i,height:Math.max(...n)-r}}case"none":return null}}function SR(e,t,n,i){const r=s=>s.length===0?null:i?Math.max(...s):Math.min(...s);const o=s=>t==="x"?{x:s,y:n}:{x:n,y:s};switch(e.kind){case"rect":case"envelope":{const s=t==="x"?e.y:e.x;const a=s+(t==="x"?e.height:e.width);if(n<s-1e-9||n>a+1e-9)return null;return o(t==="x"?i?e.x+e.width:e.x:i?e.y+e.height:e.y)}case"ellipse":{const s=t==="x"?e.cy:e.cx;const a=t==="x"?e.ry:e.rx;const l=t==="x"?e.cx:e.cy;const c=t==="x"?e.rx:e.ry;if(a<=0||c<=0)return null;const d=(n-s)/a;if(Math.abs(d)>1+1e-9)return null;return o(l+(i?1:-1)*c*Math.sqrt(Math.max(0,1-d*d)))}case"stadium":{if(t==="x"){const l=n-e.cy;if(Math.abs(l)>e.radius+1e-9)return null;const c=e.halfWidth-e.radius+Math.sqrt(Math.max(0,e.radius**2-l**2));return o(e.cx+(i?c:-c))}const s=Math.abs(n-e.cx);if(s>e.halfWidth+1e-9)return null;const a=Math.max(0,s-(e.halfWidth-e.radius));return o(e.cy+(i?1:-1)*Math.sqrt(Math.max(0,e.radius**2-a**2)))}case"cylinder":{const s=e.width/2;const a=e.y+e.capRadiusY;const l=e.y+e.height-e.capRadiusY;if(t==="x"){if(n<e.y-1e-9||n>e.y+e.height+1e-9)return null;const u=n<a?a:n>l?l:n;const f=u===n?0:(n-u)/e.capRadiusY;return o(e.cx+(i?1:-1)*s*Math.sqrt(Math.max(0,1-f*f)))}const c=(n-e.cx)/s;if(Math.abs(c)>1+1e-9)return null;const d=e.capRadiusY*Math.sqrt(Math.max(0,1-c*c));return o(i?l+d:a-d)}case"polygon":{const s=[];for(let l=0;l<e.points.length;l++){const c=e.points[l];const d=e.points[(l+1)%e.points.length];const u=t==="x"?c.y:c.x;const f=t==="x"?d.y:d.x;const h=c[t],m=d[t];const p=f-u;if(Math.abs(p)<1e-9){if(Math.abs(n-u)<1e-9)s.push(h,m);continue}const g=(n-u)/p;if(g>=-1e-9&&g<=1+1e-9)s.push(h+g*(m-h))}const a=r(s);return a===null?null:o(a)}case"none":return null}}function TG(e){const t=e.x+e.width/2;const n=e.y+e.height/2;return{N:{x:t,y:e.y},E:{x:e.x+e.width,y:n},S:{x:t,y:e.y+e.height},W:{x:e.x,y:n}}}function LG(e,t){const{x:n,y:i,width:r,height:o}=e;const s=n+r,a=i+o,l=n+r/2,c=i+o/2;switch(e.semanticShape){case"bang":return qi(Array.from({length:16},(d,u)=>{const f=-Math.PI/2+u*Math.PI/8;const h=u%2===0?1:.62;return{x:l+Math.cos(f)*r/2*h,y:c+Math.sin(f)*o/2*h}}),t);case"notch-rect":return qi([{x:n+10,y:i},{x:s,y:i},{x:s,y:a},{x:n,y:a},{x:n,y:i+10}],t);case"cloud":return rr(e,`M${n+r*.18} ${a}C${n-4} ${a} ${n-4} ${c} ${n+r*.12} ${c}C${n+r*.08} ${i+o*.15} ${n+r*.38} ${i-4} ${n+r*.48} ${i+o*.18}C${n+r*.65} ${i-5} ${s} ${i+o*.16} ${n+r*.88} ${c}C${s+5} ${c} ${s+5} ${a} ${n+r*.72} ${a}Z`,t);case"hourglass":return qi([{x:n,y:i},{x:s,y:i},{x:n+r*.62,y:c},{x:s,y:a},{x:n,y:a},{x:n+r*.38,y:c}],t);case"bolt":return qi([{x:n+r*.55,y:i},{x:n+r*.25,y:c},{x:n+r*.48,y:c},{x:n+r*.35,y:a},{x:n+r*.78,y:i+o*.4},{x:n+r*.55,y:i+o*.4}],t);case"brace":return fp(e,`M${s} ${i}C${n+r*.4} ${i} ${n+r*.7} ${c} ${n} ${c}C${n+r*.7} ${c} ${n+r*.4} ${a} ${s} ${a}`,t);case"brace-r":return fp(e,`M${n} ${i}C${n+r*.6} ${i} ${n+r*.3} ${c} ${s} ${c}C${n+r*.3} ${c} ${n+r*.6} ${a} ${n} ${a}`,t);case"braces":return fp(e,`M${n+r*.25} ${i}C${n} ${i} ${n+r*.15} ${c} ${n} ${c}C${n+r*.15} ${c} ${n} ${a} ${n+r*.25} ${a}M${n+r*.75} ${i}C${s} ${i} ${n+r*.85} ${c} ${s} ${c}C${n+r*.85} ${c} ${s} ${a} ${n+r*.75} ${a}`,t);case"datastore":return fp(e,`M${n+8} ${i}H${s}V${a}H${n+8}M${n+8} ${i}C${n-2} ${i+o*.2} ${n-2} ${a-o*.2} ${n+8} ${a}`,t);case"delay":return rr(e,`M${n} ${i}H${s-o/2}A${o/2} ${o/2} 0 0 1 ${s-o/2} ${a}H${n}Z`,t);case"h-cyl":return rr(e,`M${n+10} ${i}H${s-10}A10 ${o/2} 0 0 1 ${s-10} ${a}H${n+10}A10 ${o/2} 0 0 1 ${n+10} ${i}Z M${s-10} ${i}A10 ${o/2} 0 0 0 ${s-10} ${a}`,t);case"lin-cyl":return rr(e,`M${n} ${i+8}A${r/2} 8 0 0 1 ${s} ${i+8}V${a-8}A${r/2} 8 0 0 1 ${n} ${a-8}Z M${n} ${i+8}A${r/2} 8 0 0 0 ${s} ${i+8}M${n} ${a-16}A${r/2} 8 0 0 0 ${s} ${a-16}`,t);case"curv-trap":return rr(e,`M${n+12} ${i}Q${l} ${i+8} ${s-12} ${i}L${s} ${a}Q${l} ${a-8} ${n} ${a}Z`,t);case"div-rect":return LS(e,`M${n} ${i}H${s}V${a}H${n}ZM${n} ${c}H${s}`,t);case"doc":return rr(e,`M${n} ${i}H${s}V${a-8}Q${n+r*.75} ${a+2} ${l} ${a-8}Q${n+r*.25} ${a-18} ${n} ${a-8}Z`,t);case"tri":return qi([{x:l,y:i},{x:s,y:a},{x:n,y:a}],t);case"fork":return OG(n,c-4,r,8,t.stroke,t.strokeWidth);case"win-pane":return LS(e,`M${n} ${i}H${s}V${a}H${n}ZM${n+r*.28} ${i}V${a}M${n} ${i+o*.32}H${s}`,t);case"f-circ":return AG(l,c,Math.min(r,o)/2,t.stroke,t.strokeWidth);case"lin-doc":return rr(e,`M${n} ${i}H${s}V${a-8}Q${n+r*.75} ${a+2} ${l} ${a-8}Q${n+r*.25} ${a-18} ${n} ${a-8}ZM${n+8} ${i+8}H${s-8}`,t);case"lin-rect":return LS(e,`M${n} ${i}H${s}V${a}H${n}ZM${n+6} ${i}V${a}M${s-6} ${i}V${a}`,t);case"notch-pent":return qi([{x:n,y:i},{x:s-10,y:i},{x:s,y:c},{x:s-10,y:a},{x:n,y:a},{x:n+8,y:c}],t);case"flip-tri":return qi([{x:n,y:i},{x:s,y:i},{x:l,y:a}],t);case"docs":return rr(e,`M${n+8} ${i}H${s}V${a-8}Q${n+r*.7} ${a} ${n+r*.45} ${a-8}Q${n+r*.22} ${a-16} ${n+8} ${a-8}ZM${n} ${i+8}H${n+8}M${n} ${i+8}V${a}`,t);case"st-rect":return rr(e,`M${n+8} ${i}H${s}V${a-8}H${n+8}ZM${n} ${i+8}H${s-8}V${a}H${n}Z`,t);case"flag":return rr(e,`M${n} ${i+6}Q${n+r*.25} ${i-4} ${l} ${i+6}Q${n+r*.75} ${i+16} ${s} ${i+6}V${a-6}Q${n+r*.75} ${a+4} ${l} ${a-6}Q${n+r*.25} ${a-16} ${n} ${a-6}Z`,t);case"sm-circ":return wR(l,c,Math.min(r,o)*.22,t);case"cross-circ":{const d=rr(e,`M${l} ${i}A${r/2} ${o/2} 0 1 1 ${l-.01} ${i}M${n+r*.28} ${i+o*.28}L${n+r*.72} ${i+o*.72}M${n+r*.72} ${i+o*.28}L${n+r*.28} ${i+o*.72}`,t);d.routing={kind:"ellipse",cx:l,cy:c,rx:r/2,ry:o/2};return d}case"bow-rect":return rr(e,`M${n} ${i}Q${n+12} ${c} ${n} ${a}H${s}Q${s-12} ${c} ${s} ${i}Z`,t);case"tag-doc":return rr(e,`M${n+10} ${i}H${s}V${a-8}Q${n+r*.7} ${a} ${l} ${a-8}Q${n+r*.25} ${a-16} ${n} ${a-8}V${i+10}ZM${n} ${i+10}L${n+10} ${i}`,t);case"tag-rect":return qi([{x:n+10,y:i},{x:s,y:i},{x:s,y:a},{x:n,y:a},{x:n,y:i+10}],t);case"text":return{geometry:{kind:"path",d:`M${n} ${i}`},paint:{fill:"none",stroke:"none"},routing:{kind:"none",reason:"text blocks have no painted enclosure"}};default:return null}}function yR(e,t,n,i,r,o){return{geometry:{kind:"rect",x:e,y:t,width:n,height:i,rx:o,ry:o},paint:no(r),routing:{kind:"rect",x:e,y:t,width:n,height:i}}}function wR(e,t,n,i){return{geometry:{kind:"circle",cx:e,cy:t,r:n},paint:no(i),routing:{kind:"ellipse",cx:e,cy:t,rx:n,ry:n}}}function AG(e,t,n,i,r){return{geometry:{kind:"circle",cx:e,cy:t,r:n},paint:{fill:i,stroke:i,strokeWidth:r},routing:{kind:"ellipse",cx:e,cy:t,rx:n,ry:n}}}function IG(e,t,n,i){const r=Math.max(0,n-5);return{geometry:{kind:"compound",children:[{kind:"circle",cx:e,cy:t,r:n},{kind:"circle",cx:e,cy:t,r}]},paint:no(i),routing:{kind:"ellipse",cx:e,cy:t,rx:n,ry:n}}}function FG(e,t,n,i,r,o){const s=8;return{geometry:{kind:"compound",children:[{kind:"rect",x:e,y:t,width:n,height:i,rx:o,ry:o},{kind:"line",x1:e+s,y1:t,x2:e+s,y2:t+i},{kind:"line",x1:e+n-s,y1:t,x2:e+n-s,y2:t+i}]},paint:no(r),childPaints:[no(r),hp(r),hp(r)],routing:{kind:"rect",x:e,y:t,width:n,height:i}}}function NG(e,t,n,i,r){const o=7,s=e+n/2,a=t+o,l=i-2*o;return{geometry:{kind:"compound",children:[{kind:"rect",x:e,y:a,width:n,height:l},{kind:"line",x1:e,y1:a,x2:e,y2:a+l},{kind:"line",x1:e+n,y1:a,x2:e+n,y2:a+l},{kind:"ellipse",cx:s,cy:t+i-o,rx:n/2,ry:o},{kind:"ellipse",cx:s,cy:a,rx:n/2,ry:o}]},paint:no(r),childPaints:[{fill:r.fill,stroke:"none"},hp(r),hp(r),no(r),no(r)],routing:{kind:"cylinder",cx:s,y:t,width:n,height:i,capRadiusY:o}}}function $G(e,t,n){return{geometry:{kind:"circle",cx:e,cy:t,r:n},paint:{fill:"var(--_text)",stroke:"none"},routing:{kind:"ellipse",cx:e,cy:t,rx:n,ry:n}}}function _G(e,t,n){const i=Math.max(0,n-4);return{geometry:{kind:"compound",children:[{kind:"circle",cx:e,cy:t,r:n},{kind:"circle",cx:e,cy:t,r:i}]},paint:{fill:"var(--_text)",stroke:"var(--_text)"},childPaints:[{fill:"none",stroke:"var(--_text)",strokeWidth:String(et.innerBox*2)},{fill:"var(--_text)",stroke:"none"}],routing:{kind:"ellipse",cx:e,cy:t,rx:n,ry:n}}}function DG(e,t,n,i){const r=Math.min(n,i)/2;return{geometry:{kind:"rect",x:e,y:t,width:n,height:i,rx:r,ry:r},paint:{fill:"var(--_text)",stroke:"none"},routing:{kind:"rect",x:e,y:t,width:n,height:i}}}function OG(e,t,n,i,r,o){return{geometry:{kind:"rect",x:e,y:t,width:n,height:i},paint:{fill:r,stroke:r,strokeWidth:o},routing:{kind:"rect",x:e,y:t,width:n,height:i}}}var BG=new Set(["text","brace","brace-r","braces","datastore","fork","f-circ","state-start","state-end","state-fork","state-join"]);function MR(e){return!BG.has(e.semanticShape??e.shape)}function fp(e,t,n){const i=rr(e,t,n,{fill:"none",reason:"open symbol has no enclosing painted boundary"});i.routing={kind:"envelope",x:e.x,y:e.y,width:e.width,height:e.height,reason:"open symbol routes to its layout envelope"};return i}function LS(e,t,n){const i=rr(e,t,n);i.routing={kind:"rect",x:e.x,y:e.y,width:e.width,height:e.height};return i}function Os(e,t,n,i=1e-6){const r=bi(e).boundary;if(r.kind==="envelope"||r.kind==="none")return void 0;return IS(r,t,n,i)}function IS(e,t,n,i){const r=n.x-t.x,o=n.y-t.y;const s=Math.hypot(r,o);if(s<=1e-9||Math.abs(r)>i&&Math.abs(o)>i)return false;const a=Math.abs(r)>Math.abs(o)?r>0?"E":"W":o>0?"S":"N";const l=a==="E"||a==="W"?t.y:t.x;const c=Ds(e,a,l);if(!c||Math.hypot(c.x-t.x,c.y-t.y)>i)return false;let d=0,u=0;if(e.kind==="ellipse"){d=(t.x-e.cx)/e.rx/e.rx;u=(t.y-e.cy)/e.ry/e.ry}else if(e.kind==="stadium"){const h=e.halfWidth-e.radius;d=t.x-Math.max(e.cx-h,Math.min(e.cx+h,t.x));u=t.y-e.cy}else if(e.kind==="cylinder"){const h=e.y+e.capRadiusY,m=e.y+e.height-e.capRadiusY;if(t.y>=h&&t.y<=m)d=t.x-e.cx;else{d=(t.x-e.cx)/(e.width/2)/(e.width/2);u=(t.y-(t.y<h?h:m))/e.capRadiusY/e.capRadiusY}}else return true;const f=Math.hypot(d,u);return f>0&&Number.isFinite(f)&&(d*(r/s)+u*(o/s))/f>0}function mp(e,t){if(e.kind==="polygon"){let r=false;for(let o=0,s=e.points.length-1;o<e.points.length;s=o++){const a=e.points[o],l=e.points[s];const c=l.x-a.x,d=l.y-a.y;const u=(t.x-a.x)*d-(t.y-a.y)*c;if(Math.abs(u)<=1e-6*Math.hypot(c,d)&&(t.x-a.x)*(t.x-l.x)+(t.y-a.y)*(t.y-l.y)<=1e-6)return true;if(a.y>t.y!==l.y>t.y&&t.x<(l.x-a.x)*(t.y-a.y)/(l.y-a.y)+a.x)r=!r}return r}const n=Ds(e,"W",t.y),i=Ds(e,"E",t.y);return Boolean(n&&i&&t.x>=n.x-1e-6&&t.x<=i.x+1e-6)}function kR(e,t,n){if(!mp(e,t)||!mp(e,n))return true;if(e.kind!=="polygon")return false;const i=n.x-t.x,r=n.y-t.y;const o=Math.abs(i)<=1e-6;const s=o?r:i;if(Math.abs(s)<=1e-9)return false;const a=[0,1];for(let l=0;l<e.points.length;l++){const c=e.points[l],d=e.points[(l+1)%e.points.length];const u=o?RR(t.x,c,d):ER(t.y,c,d);if(u){const f=(o?u.y-t.y:u.x-t.x)/s;if(f>0&&f<1)a.push(f)}}a.sort((l,c)=>l-c);return a.some((l,c)=>{const d=a[c+1];if(d===void 0||d-l<=1e-9)return false;const u=(l+d)/2;return!mp(e,{x:t.x+i*u,y:t.y+r*u})})}function Ea(e,t,n){if(e.length<2)return e;const i=bi(t).boundary;if(i.kind==="envelope"||i.kind==="none")return e;const r=n?e:[...e].reverse();const o=r[0];if(!mp(i,o))return e;const s=r.find(a=>Math.hypot(a.x-o.x,a.y-o.y)>1e-9);if(!s||IS(i,o,s,1e-6))return e;for(let a=0;a<r.length-1;a++){const l=r[a],c=r[a+1];const d=c.x-l.x,u=c.y-l.y,f=Math.hypot(d,u);if(f<=1e-9)continue;if(Math.abs(d)>1e-6&&Math.abs(u)>1e-6)return e;const h=Math.abs(d)>Math.abs(u)?d>0?"E":"W":u>0?"S":"N";const m=i.kind==="polygon"?PR(l,c,i.points):Ds(i,h,h==="E"||h==="W"?l.y:l.x);if(m){const p=((m.x-l.x)*d+(m.y-l.y)*u)/f**2;const g=r.slice(a+1);const y=g.find(w=>Math.hypot(w.x-m.x,w.y-m.y)>1e-9);if(p>=-1e-9&&p<=1+1e-9&&y&&IS(i,m,y,1e-6)){if(kR(i,l,m))return e;const w=Math.hypot(m.x-c.x,m.y-c.y)<=1e-9?g:[m,...g];return n?w:w.reverse()}}if(kR(i,l,c))return e}return e}function si(e,t,n){if(e.length<2)return e;const i=bi(t).boundary;if(i.kind==="rect"||i.kind==="envelope"||i.kind==="none")return e;const r=[...e];if(n)r[0]=CR(e[0],e[1],t,i);else{const o=e.length-1;r[o]=CR(e[o],e[o-1],t,i)}return r}function CR(e,t,n,i){const r=WG(e,t,i);if(r!==null)return r;const o=1e-6;if(e.x<n.x-o||e.x>n.x+n.width+o||e.y<n.y-o||e.y>n.y+n.height+o)return e;const s=[Math.abs(e.y-n.y)<=o?"N":void 0,Math.abs(e.y-n.y-n.height)<=o?"S":void 0,Math.abs(e.x-n.x)<=o?"W":void 0,Math.abs(e.x-n.x-n.width)<=o?"E":void 0].filter(l=>l!==void 0);const a=s.length===1?s[0]:void 0;if(!a)return e;return Ds(i,a,a==="N"||a==="S"?e.x:e.y)??e}function WG(e,t,n){switch(n.kind){case"ellipse":return zG(e,t,n);case"stadium":return GG(e,t,n);case"cylinder":return HG(e,t,n);case"polygon":return PR(e,t,n.points);case"rect":case"envelope":return e;case"none":return e}}function pp(e,t){const n=e.x-t.x;const i=e.y-t.y;const r=Math.abs(n)<Math.abs(i);return{vertical:r,dir:(r?i:n)>=0?1:-1}}function zG(e,t,n){const{cx:i,cy:r,rx:o,ry:s}=n;if(o<=0||s<=0)return null;const{vertical:a,dir:l}=pp(e,t);if(a){const d=(e.x-i)/o;if(Math.abs(d)>1)return null;return{x:e.x,y:r-l*s*Math.sqrt(Math.max(0,1-d*d))}}const c=(e.y-r)/s;if(Math.abs(c)>1)return null;return{x:i-l*o*Math.sqrt(Math.max(0,1-c*c)),y:e.y}}function GG(e,t,n){const{cx:i,cy:r,halfWidth:o,radius:s}=n;const{vertical:a,dir:l}=pp(e,t);if(a){const d=Math.abs(e.x-i);if(d<=o-s)return{x:e.x,y:r-l*s};const u=d-(o-s);if(u>s)return null;return{x:e.x,y:r-l*Math.sqrt(Math.max(0,s*s-u*u))}}const c=Math.abs(e.y-r);if(c>s)return null;return{x:i-l*(o-s+Math.sqrt(Math.max(0,s*s-c*c))),y:e.y}}function HG(e,t,n){const{cx:i,y:r,width:o,height:s,capRadiusY:a}=n;const l=o/2;const c=r+a;const d=r+s-a;const{vertical:u,dir:f}=pp(e,t);if(!u){if(e.y>=c&&e.y<=d)return{x:i-f*l,y:e.y};const p=e.y<c?c:d;const g=(e.y-p)/a;if(Math.abs(g)>1)return null;return{x:i-f*l*Math.sqrt(Math.max(0,1-g*g)),y:e.y}}const h=(e.x-i)/l;if(Math.abs(h)>1)return null;const m=a*Math.sqrt(Math.max(0,1-h*h));return f>0?{x:e.x,y:c-m}:{x:e.x,y:d+m}}function PR(e,t,n){const{vertical:i}=pp(e,t);let r=null;let o=Infinity;for(let s=0;s<n.length;s++){const a=n[s];const l=n[(s+1)%n.length];const c=l.x-a.x,d=l.y-a.y;const u=e.x-a.x,f=e.y-a.y;if(Math.abs(u*d-f*c)<1e-6&&u*(e.x-l.x)+f*(e.y-l.y)<=1e-6){const p=Math.hypot(t.x-e.x,t.y-e.y);const g=p>0?Math.min(1e-4/p,.5):0;const y={x:e.x+(t.x-e.x)*g,y:e.y+(t.y-e.y)*g};let w=false,S=false;for(let x=0,M=n.length-1;x<n.length;M=x++){const b=n[x],C=n[M];const P=t.x-e.x,E=t.y-e.y;const k=C.x-b.x,v=C.y-b.y,T=P*v-E*k;if(Math.abs(T)>1e-9){const A=b.x-e.x,R=b.y-e.y;const I=(A*v-R*k)/T,L=(A*E-R*P)/T;if(I*p>1e-6&&I<=1&&L>=0&&L<=1)S=true}if(b.y>y.y!==C.y>y.y&&y.x<(C.x-b.x)*(y.y-b.y)/(C.y-b.y)+b.x)w=!w}if(!w&&!S)return e}const h=i?RR(e.x,a,l):ER(e.y,a,l);if(!h)continue;const m=Math.hypot(h.x-t.x,h.y-t.y);if(m<o){r=h;o=m}}return r}function ER(e,t,n){const i=n.y-t.y;if(Math.abs(i)<1e-6)return null;const r=(e-t.y)/i;if(r<0||r>1)return null;return{x:t.x+r*(n.x-t.x),y:e}}function RR(e,t,n){const i=n.x-t.x;if(Math.abs(i)<1e-6)return null;const r=(e-t.x)/i;if(r<0||r>1)return null;return{x:e,y:t.y+r*(n.y-t.y)}}var jG=new Set(["cloud","brace","brace-r","braces","datastore","delay","h-cyl","lin-cyl","curv-trap","doc","lin-doc","docs","st-rect","flag","bow-rect","tag-doc"]);function od(e,t,n=1.5){if(e.semanticShape==="text")return{policy:"none",onBoundary:false};if(e.semanticShape&&jG.has(e.semanticShape)){return{policy:"envelope",onBoundary:FS(t,e.x,e.y,e.width,e.height,n)}}const i=YG(e);if(i)return{policy:"exact",onBoundary:NS(t,i,n)};const r=e.x+e.width/2;const o=e.y+e.height/2;const s=Math.min(e.width,e.height)/2;if(e.semanticShape==="fork"){return{policy:"exact",onBoundary:FS(t,e.x,o-4,e.width,8,n)}}if(e.semanticShape==="sm-circ"){const a=Math.min(e.width,e.height)*.22;return{policy:"exact",onBoundary:Zu(t,r,o,a,a,n)}}if(e.semanticShape==="cross-circ"){return{policy:"exact",onBoundary:Zu(t,r,o,e.width/2,e.height/2,n)}}if(e.semanticShape==="f-circ"){return{policy:"exact",onBoundary:Zu(t,r,o,s,s,n)}}switch(e.shape){case"diamond":case"state-choice":return{policy:"exact",onBoundary:Math.abs(Math.abs(t.x-r)/(e.width/2)+Math.abs(t.y-o)/(e.height/2)-1)*Math.min(e.width,e.height)/2<n};case"circle":case"doublecircle":case"state-history":return{policy:"exact",onBoundary:Zu(t,r,o,s,s,n)};case"state-start":case"state-end":{const a=Math.max(0,s-2);return{policy:"exact",onBoundary:Zu(t,r,o,a,a,n)}}case"stadium":{const a=e.height/2;const l=e.width/2-a;const c=Math.abs(t.x-r);const d=c<=l?Math.abs(Math.abs(t.y-o)-a)<n:Math.abs(Math.hypot(c-l,t.y-o)-a)<n;return{policy:"exact",onBoundary:d}}case"hexagon":{const a=e.height/4;return{policy:"exact",onBoundary:NS(t,[{x:e.x+a,y:e.y},{x:e.x+e.width-a,y:e.y},{x:e.x+e.width,y:o},{x:e.x+e.width-a,y:e.y+e.height},{x:e.x+a,y:e.y+e.height},{x:e.x,y:o}],n)}}case"cylinder":return{policy:"exact",onBoundary:XG(e,t,n)};case"trapezoid":case"trapezoid-alt":case"lean-r":case"lean-l":case"asymmetric":return{policy:"exact",onBoundary:NS(t,qG(e),n)};default:return{policy:"exact",onBoundary:FS(t,e.x,e.y,e.width,e.height,n)}}}function YG(e){const{x:t,y:n,width:i,height:r}=e;const o=t+i,s=n+r,a=t+i/2,l=n+r/2;switch(e.semanticShape){case"bang":return Array.from({length:16},(c,d)=>{const u=-Math.PI/2+d*Math.PI/8;const f=d%2===0?1:.62;return{x:a+Math.cos(u)*i/2*f,y:l+Math.sin(u)*r/2*f}});case"notch-rect":return[{x:t+10,y:n},{x:o,y:n},{x:o,y:s},{x:t,y:s},{x:t,y:n+10}];case"hourglass":return[{x:t,y:n},{x:o,y:n},{x:t+i*.62,y:l},{x:o,y:s},{x:t,y:s},{x:t+i*.38,y:l}];case"bolt":return[{x:t+i*.55,y:n},{x:t+i*.25,y:l},{x:t+i*.48,y:l},{x:t+i*.35,y:s},{x:t+i*.78,y:n+r*.4},{x:t+i*.55,y:n+r*.4}];case"tri":return[{x:a,y:n},{x:o,y:s},{x:t,y:s}];case"notch-pent":return[{x:t,y:n},{x:o-10,y:n},{x:o,y:l},{x:o-10,y:s},{x:t,y:s},{x:t+8,y:l}];case"flip-tri":return[{x:t,y:n},{x:o,y:n},{x:a,y:s}];case"tag-rect":return[{x:t+10,y:n},{x:o,y:n},{x:o,y:s},{x:t,y:s},{x:t,y:n+10}];default:return null}}function qG(e){const{x:t,y:n,width:i,height:r}=e;const o=t+i,s=n+r,a=n+r/2;const l=i*.15;switch(e.shape){case"trapezoid":return[{x:t+l,y:n},{x:o-l,y:n},{x:o,y:s},{x:t,y:s}];case"trapezoid-alt":return[{x:t,y:n},{x:o,y:n},{x:o-l,y:s},{x:t+l,y:s}];case"lean-r":return[{x:t+l,y:n},{x:o,y:n},{x:o-l,y:s},{x:t,y:s}];case"lean-l":return[{x:t,y:n},{x:o-l,y:n},{x:o,y:s},{x:t+l,y:s}];default:return[{x:t+12,y:n},{x:o,y:n},{x:o,y:s},{x:t+12,y:s},{x:t,y:a}]}}function FS(e,t,n,i,r,o){const s=Math.abs(e.x-t)<o||Math.abs(e.x-(t+i))<o;const a=Math.abs(e.y-n)<o||Math.abs(e.y-(n+r))<o;return s&&e.y>=n-o&&e.y<=n+r+o||a&&e.x>=t-o&&e.x<=t+i+o}function Zu(e,t,n,i,r,o){if(i<=0||r<=0)return false;return Math.abs(Math.hypot((e.x-t)/i,(e.y-n)/r)-1)*Math.min(i,r)<o}function NS(e,t,n){let i=Infinity;for(let r=0;r<t.length;r++){i=Math.min(i,UG(e,t[r],t[(r+1)%t.length]))}return i<=n}function XG(e,t,n){const i=e.x+e.width/2;const r=e.y+e.height/2;const o=e.width/2;const s=7;if(t.y>=e.y+s-n&&t.y<=e.y+e.height-s+n&&Math.abs(Math.abs(t.x-i)-o)<n)return true;const a=t.y<r?e.y+s:e.y+e.height-s;return Math.abs(Math.hypot((t.x-i)/o,(t.y-a)/s)-1)*Math.min(o,s)<n*2}function UG(e,t,n){const i=n.x-t.x,r=n.y-t.y;const o=i*i+r*r;if(o===0)return Math.hypot(e.x-t.x,e.y-t.y);const s=Math.max(0,Math.min(1,((e.x-t.x)*i+(e.y-t.y)*r)/o));return Math.hypot(e.x-(t.x+s*i),e.y-(t.y+s*r))}function vi(e,t){return Be(e,{transform:t.edgeTextTransform,fontSize:t.edgeLabelFontSize,fontWeight:t.edgeLabelFontWeight,letterSpacing:t.edgeLetterSpacing})}function Wn(e,t,n){if(n==="group")return Be(e,{transform:t.groupTextTransform,fontSize:t.groupHeaderFontSize,fontWeight:t.groupHeaderFontWeight,letterSpacing:t.groupLetterSpacing,fontFamily:t.groupFont});if(n==="edge")return vi(e,t);if(n==="note")return Be(e,{transform:t.nodeTextTransform,fontSize:t.edgeLabelFontSize,fontWeight:t.edgeLabelFontWeight,letterSpacing:t.edgeLetterSpacing});return Be(e,{transform:t.nodeTextTransform,fontSize:t.nodeLabelFontSize,fontWeight:t.nodeLabelFontWeight,letterSpacing:t.nodeLetterSpacing})}var nn=8;function Ti(e,t){return Math.max(4,t*(e.style==="thick"?2:1)*2)}function VG(e,t){return e.inlineStyle?.["stroke-width"]?bn.width:bn.width*t*(e.style==="thick"?2:1)}var sd=4;function ad(e,t,n){const i=n==="start"?e.hasArrowStart:e.hasArrowEnd;return Ti(e,t)+(i?VG(e,t):0)+sd}function Bs(e,t,n){const i=n.width+2*nn;const r=n.height+2*nn;return{x:e-i/2,y:t-r/2,w:i,h:r}}function kt(e,t){if(!e.label||!e.labelPosition)return null;const n=e.labelBlock??vi(qe(e.label,e.labelContent),t);return Bs(e.labelPosition.x,e.labelPosition.y,n)}var Gl=.5;function ef(e,t,n){const i=n.x+Gl,r=n.x+n.w-Gl;const o=n.y+Gl,s=n.y+n.h-Gl;const a=t.x-e.x,l=t.y-e.y;if(a===0)return l!==0&&e.x>i&&e.x<r&&Math.max(e.y,t.y)>o&&Math.min(e.y,t.y)<s;if(l===0)return e.y>o&&e.y<s&&Math.max(e.x,t.x)>i&&Math.min(e.x,t.x)<r;const c=(i-e.x)/a,d=(r-e.x)/a;const u=(o-e.y)/l,f=(s-e.y)/l;return Math.max(0,Math.min(c,d),Math.min(u,f))<Math.min(1,Math.max(c,d),Math.max(u,f))}function xr(e){const t=new Map(e.map(n=>[n.id,{start:Vx(n,"start"),end:Vx(n,"end"),fixed:n.units==="userSpaceOnUse"}]));return(n,i,r)=>{if(!n)return 0;const o=t.get(n);if(!o)throw new Error(`Missing terminal marker ${n}`);return o[r]*(o.fixed?1:i)+sd}}function $S(e,t=false){const n=bn.width;const i=t?n:bn.height;const r=e??"var(--_arrow)";const o=`${e?`-${ld(e)}`:""}${t?"-fixed":""}`;const s={fill:r,stroke:r,strokeWidth:String(bn.strokeWidth),strokeLinejoin:"round"};return[fr(`arrowhead${o}`,{width:n,height:i},"end",s,t?"userSpaceOnUse":void 0),fr(`arrowhead-start${o}`,{width:n,height:i},"start",s,t?"userSpaceOnUse":void 0)]}function _S(e,t=false){const n=bn.width;const i=`${e?`-${ld(e)}`:""}${t?"-fixed":""}`;const r=e??"var(--_arrow)";const o=n/2-.75;const s={shape:"circle",size:{width:n,height:n},...t?{units:"userSpaceOnUse"}:{},orient:"auto",geometry:{kind:"circle",cx:n/2,cy:n/2,r:o},paint:{fill:"none",stroke:r,strokeWidth:"1"}};return[{...s,id:`circlehead${i}`,ref:{x:n-.5,y:n/2}},{...s,id:`circlehead-start${i}`,ref:{x:.5,y:n/2}}]}function DS(e,t=false){const n=bn.width;const i=`${e?`-${ld(e)}`:""}${t?"-fixed":""}`;const r=e??"var(--_arrow)";const o=1.25;const s=1.25;const a=o;const l=n-o;const c={shape:"cross",size:{width:n,height:n},...t?{units:"userSpaceOnUse"}:{},orient:"auto",geometry:{kind:"compound",children:[{kind:"line",x1:a,y1:a,x2:l,y2:l},{kind:"line",x1:a,y1:l,x2:l,y2:a}]},paint:{stroke:r,strokeWidth:String(s),strokeLinecap:"round"}};return[{...c,id:`crosshead${i}`,ref:{x:l+s/2,y:n/2}},{...c,id:`crosshead-start${i}`,ref:{x:a-s/2,y:n/2}}]}function gp(e,t,n,i){const r=[...$S()];if(n)r.push(..._S());if(i)r.push(...DS());for(const o of e){r.push(...$S(o));if(n)r.push(..._S(o));if(i)r.push(...DS(o))}for(const o of t){r.push(...$S(o,true));if(n)r.push(..._S(o,true));if(i)r.push(...DS(o,true))}return r}function Hl(e){if(e==="circle")return"circlehead";if(e==="cross")return"crosshead";return"arrowhead"}function ld(e){if(/^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(e))return`23${e.slice(1)}`;if(/^[a-z]+$/i.test(e))return e;const t=`color-u-${Array.from(e,n=>n.codePointAt(0).toString(16)).join("-")}`;return t.length<=233?t:`color-h-${id(e).slice("fnv1a64:".length)}`}var KG=gp(new Set,new Set([void 0]),true,true);var vR=xr(KG);function Ws(e,t){const n=e.inlineStyle?.["stroke-width"]?"-fixed":"";const i=(t.lineWidth??1)*(e.style==="thick"?2:1);return{start:e.hasArrowStart?vR(`${Hl(e.startMarker??"arrow")}-start${n}`,i,"start"):0,end:e.hasArrowEnd?vR(`${Hl(e.endMarker??"arrow")}${n}`,i,"end"):0}}function JG(e){const t=e[0];let n=`M ${t.x} ${t.y}`;const i=[];for(let r=1;r<e.length;r++){const o=e[r-1];const s=e[r];const a=(o.x+s.x)/2;n+=` C ${a} ${o.y}, ${a} ${s.y}, ${s.x} ${s.y}`;i.push({kind:"cubic",control1:{x:a,y:o.y},control2:{x:a,y:s.y},end:s})}return _c(n,t,i)}function tf(e,t){return e.curve?JG(e.points):(t.edgeBendRadius??0)>0?qn(e.points,t.edgeBendRadius,{terminalClearance:Ws(e,t)}):void 0}function br(e,t){if(e.style==="invisible"||e.points.length<2||!e.hasArrowStart&&!e.hasArrowEnd)return[];const n=e.inlineStyle?.stroke??t.edgeStrokeColor;const i=!!e.inlineStyle?.["stroke-width"];const r=gp(new Set(n?[n]:[]),new Set(i?[n]:[]),e.startMarker==="circle"||e.endMarker==="circle",e.startMarker==="cross"||e.endMarker==="cross");const o=`${n?`-${ld(n)}`:""}${i?"-fixed":""}`;const s=e.hasArrowStart?r.find(d=>d.id===`${Hl(e.startMarker??"arrow")}-start${o}`):void 0;const a=e.hasArrowEnd?r.find(d=>d.id===`${Hl(e.endMarker??"arrow")}${o}`):void 0;const l=tf(e,t);const c=l?.geometry??{kind:"polyline",points:e.points};return Yr({route:{geometry:c,closed:false,contours:l?.contours??I1(c,false)},stroke:{width:e.inlineStyle?.["stroke-width"]??String((t.lineWidth??1)*(e.style==="thick"?2:1))},markers:{start:s,mid:[],end:a}})}var zs=64;var Ra=128;function Gs(e){let t=e.nodes.size;const n=i=>{for(const r of i){t++;n(r.children)}};n(e.subgraphs);return t<=zs&&e.edges.length<=Ra}var _e=.01;var Bt=4;var AR=8;var QG=12;function Si(e,t,n="end"){const i=Ws(t??{style:"solid",hasArrowStart:true,hasArrowEnd:true},e);return Math.max(QG,i[n]+(e.edgeBendRadius??0))}var OS=new Set(["rectangle","service","rounded","subroutine","state-fork","state-join"]);var gn=new Set([...OS,"diamond","circle","ellipse","doublecircle","stadium","hexagon","cylinder","state-start","state-end","state-choice","state-history","trapezoid","trapezoid-alt","asymmetric","lean-r","lean-l"]);var pn=.5;var va=12;var IR=8;function Ft(e){return rd(e)}function Vo(e){const t=e.x+e.width/2;const n=e.y+e.height/2;const i=e.width/4;const r=e.height/4;return{NE:{x:t+i,y:n-r},SE:{x:t+i,y:n+r},SW:{x:t-i,y:n+r},NW:{x:t-i,y:n-r}}}function Vn(e,t){const n=bi(e);if(n.boundary.kind==="envelope"||n.boundary.kind==="none")return void 0;for(const i of["N","E","S","W"]){const r=n.sides[i].preferred;if(Math.abs(r.x-t.x)<=pn&&Math.abs(r.y-t.y)<=pn)return i}if(Dr(e)){const i=Vo(e);for(const r of["NE","SE","SW","NW"]){if(Math.abs(i[r].x-t.x)<=pn&&Math.abs(i[r].y-t.y)<=pn)return r}}return void 0}function ai(e,t,n){let i=0;for(const[r,o]of[[t,true],[n,false]]){if(!r)continue;const s=bi(r);if(s.boundary.kind==="envelope"||s.boundary.kind==="none")continue;const a=o?e.points:[...e.points].reverse();const l=a[0];const c=l&&a.find(f=>Math.hypot(f.x-l.x,f.y-l.y)>_e);if(!l||!c){i++;continue}const d=c.x-l.x,u=c.y-l.y;if(Math.abs(d)>_e&&Math.abs(u)>_e)continue;if(!Os(r,l,c,pn))i++}return i}function nf(e,t,n){for(const[i,r]of[[t,true],[n,false]]){if(!i)continue;const o=bi(i);if(o.boundary.kind==="envelope"||o.boundary.kind==="none")continue;while(e.points.length>2){const s=r?e.points:[...e.points].reverse();const[a,l]=s;const c={x:(a.x+l.x)/2,y:(a.y+l.y)/2};if(![a,l,c].every(u=>od(i,u,_e).onBoundary))break;const d={...e,points:r?e.points.slice(1):e.points.slice(0,-1)};if(ai(d,r?i:void 0,r?void 0:i)!==0)break;e.points=d.points}}}function io(e){const t=bi(e).boundary;return t.kind!=="envelope"&&t.kind!=="none"}function Dr(e){const t=bi(e);return t.boundary.kind==="polygon"&&["N","E","S","W"].every(n=>t.sides[n].kind==="dynamic")}function Ta(e){const t=new Set;const n=new Map;const i=(s,a)=>{for(const l of s){t.add(l.id);for(const c of l.nodeIds)n.set(c,l.id);i(l.children,l.id)}};i(e.subgraphs,"");const r=new Map;const o=(s,a)=>{const l=new Set;const c=[s];while(c.length>0){const d=c.pop();if(d===a)return true;if(l.has(d))continue;l.add(d);for(const u of r.get(d)??[])c.push(u)}return false};return e.edges.map(s=>{if(s.source===s.target)return"self-loop";if(t.has(s.source)||t.has(s.target))return"container";const a=o(s.target,s.source)?"feedback":(n.get(s.source)??"")!==(n.get(s.target)??"")?"cross-hierarchy":"primary-forward";if(a!=="feedback"){if(!r.has(s.source))r.set(s.source,new Set);r.get(s.source).add(s.target)}return a})}function cd(e){const t=e==="LR"||e==="RL";return{main:t?"x":"y",cross:t?"y":"x",sign:e==="RL"||e==="BT"?-1:1}}function TR(e,t,n){return e.x!==n.x&&e.y!==n.y&&(e.x===t.x&&t.y===n.y||e.y===t.y&&t.x===n.x)}function pt(e){let t=e;for(let n=0;n<8;n++){if(t.length<3)return t;const i=[t[0]];for(let o=1;o<t.length;o++){const s=t[o];const a=i[i.length-1];if(Math.abs(s.x-a.x)<_e&&Math.abs(s.y-a.y)<_e){const l=t[o+1];if(l?!TR(a,s,l):s.x===a.x&&s.y===a.y)continue}i.push(s)}const r=i.length<3?i:[i[0]];if(i.length>=3){for(let o=1;o<i.length-1;o++){const s=r[r.length-1],a=i[o],l=i[o+1];const c=(a.x-s.x)*(l.y-s.y)-(a.y-s.y)*(l.x-s.x);if(Math.abs(c)<_e&&!TR(s,a,l))continue;r.push(a)}r.push(i[i.length-1])}if(r.length===t.length)return r;t=r}return t}function BS(e){let t=false;for(let i=1;i<e.length;i++){const r=e[i-1],o=e[i];if(Math.abs(r.x-o.x)>_e&&Math.abs(r.y-o.y)>_e){t=true;break}}if(!t)return e;const n=[e[0]];for(let i=1;i<e.length;i++){const r=n[n.length-1],o=e[i];if(Math.abs(r.x-o.x)>_e&&Math.abs(r.y-o.y)>_e){const s=n.length>=2?n[n.length-2]:void 0;const a=s?Math.abs(s.y-r.y)<_e:true;n.push(a?{x:o.x,y:r.y}:{x:r.x,y:o.y})}n.push(o)}return n}function li(e){return e.length<3?0:Math.max(0,pt(e.map(t=>({x:Number(Xe(t.x)),y:Number(Xe(t.y))}))).length-2)}function FR(e,t){let n=Infinity,i=-Infinity;for(const r of e){n=Math.min(n,r[t.cross]);i=Math.max(i,r[t.cross])}return i-n}function rf(e,t){for(let n=1;n<e.length;n++){const i=e[n-1],r=e[n];const o=(r[t.main]-i[t.main])*t.sign;const s=Math.abs(r[t.cross]-i[t.cross]);if(o>_e&&s>_e)return false;if(o<-_e)return false}return true}function Ko(e,t,n){const i=bi(e).sides[Sr(t,n)];if(i.kind==="dynamic")return{lo:i.lo,hi:i.hi};if(i.kind==="port"){const r=i.point[t.cross];return{lo:r-pn,hi:r+pn}}return null}function ro(e,t,n,i){const r=xR(bi(e),Sr(n,i),t);return r?.[n.main]??null}function Sr(e,t){const n=t*e.sign>0;return e.main==="x"?n?"E":"W":n?"S":"N"}function NR(e){switch(e){case"N":return"S";case"S":return"N";case"E":return"W";case"W":return"E"}}function ZG(e,t){if(!e)return t;if(e==="N"||e==="E"||e==="S"||e==="W")return e;return e.includes(t)?t:e[0]}function $R(e,t,n){const i=e==="feedback"||e==="self-loop"||e==="container"||e==="cross-hierarchy"?e:"flow";const r=t==="source"!==(e==="feedback")?1:-1;return{role:`${i}-${t}`,side:Sr(n,r)}}function LR(e,t,n){if(n)return e==="N"||e==="S"?n.x:n.y;return e==="N"||e==="S"?t.x+t.width/2:t.y+t.height/2}function yp(e,t,n=Ta(t)){return _R(e,t,n,true)}function WS(e,t,n,i,r,o=false){const s=cd(t.direction);const a=_R(e,t,i,false).sideUse;for(const l of e.edges){if(!r(l)||l.edgeIndex===void 0)continue;const c=i[l.edgeIndex];if(c!=="primary-forward"&&!(c==="feedback"&&!l.label))continue;for(const d of["source","target"]){const u=d==="source"?l.source:l.target;const{side:f}=$R(c,d,s);const h=`${u}:${f}`;const m=(a.get(h)??0)-1;if(m>0)a.set(h,m);else a.delete(h)}}return{axis:s,ctx:{nodes:e.nodes,edges:e.edges,groups:e.groups,axis:s,style:n,classes:i,sideUse:a,finalLabelClearance:o,nodeLaneIndexes:vr()?void 0:{},routeChannelGeometry:vr()?void 0:new WeakMap}}}function Ln(e,t,n){return e.main==="x"?{x:t,y:n}:{x:n,y:t}}function dd(e,t,n){return{main:e.cross,cross:e.main,sign:t<n?1:-1}}function eH(e,t){e.routeChannelGeometry?.delete(t)}function wi(e,t,n){eH(e,t);t.points=n}function Hs(e){const t=new Map;e.forEach(n=>t.set(n.id,n));return t}function _R(e,t,n,i){const r=cd(t.direction);const o=Hs(e.nodes);const s=[];const a=new Map;const l=(f,h)=>{const m=`${f}:${h}`;a.set(m,(a.get(m)??0)+1)};for(const f of e.edges){if(f.edgeIndex===void 0)continue;const h=n[f.edgeIndex]??"primary-forward";for(const m of["source","target"]){const p=m==="source"?f.source:f.target;const g=o.get(p);if(!g)continue;const{role:y,side:w}=$R(h,m,r);const S=m==="source"?f.points[0]:f.points[f.points.length-1];const x=S?Vn(g,S):void 0;const M=ZG(x,w);const b=h==="primary-forward"||h==="feedback"&&!f.label;if(b)l(p,w);if(!i){LR(M,g,S);continue}s.push({edge:f,endpoint:m,nodeId:p,side:M,role:y,coord:LR(M,g,S),edgeIndex:f.edgeIndex,port:x})}}if(!i)return{byEdge:new Map,sideUse:a};const c=new Map;for(const f of s){const h=`${f.nodeId}:${f.side}`;if(!c.has(h))c.set(h,[]);c.get(h).push(f)}const d=new Map;const u=f=>f==="source"?0:1;for(const f of c.values()){f.sort((m,p)=>m.coord-p.coord||m.edgeIndex-p.edgeIndex||u(m.endpoint)-u(p.endpoint));const h=f.length;f.forEach((m,p)=>{const g={side:m.side,slotIndex:p,slotCount:h,role:m.role,...m.port?{port:m.port}:{}};const y=d.get(m.edge)??{};y[m.endpoint]=g;d.set(m.edge,y)})}return{byEdge:d,sideUse:a}}function of(e,t,n,i,r){let o=0;let s=0;const a=u=>{o=Math.min(o,u.x);s=Math.min(s,u.y);for(const f of u.children)a(f)};for(const u of e){o=Math.min(o,u.x);s=Math.min(s,u.y)}for(const u of n)a(u);for(const u of t){for(const h of u.points){o=Math.min(o,h.x);s=Math.min(s,h.y)}const f=r&&u.labelBlock?kt(u,r):null;if(f){o=Math.min(o,f.x);s=Math.min(s,f.y)}else if(u.labelPosition){o=Math.min(o,u.labelPosition.x);s=Math.min(s,u.labelPosition.y)}}if(o>=0&&s>=0)return;const l=o<0?-o+i:0;const c=s<0?-s+i:0;const d=u=>{u.x+=l;u.y+=c;for(const f of u.children)d(f)};for(const u of e){u.x+=l;u.y+=c}for(const u of n)d(u);for(const u of t){for(const f of u.points){f.x+=l;f.y+=c}if(u.labelPosition){u.labelPosition.x+=l;u.labelPosition.y+=c}}}function sf(e,t){const n=(i,r,o,s)=>{const a=Math.abs(i.x-r.x)<=_e;const l=Math.abs(o.x-s.x)<=_e;if(a===l){const h=a?Math.abs(i.x-o.x)<=_e:Math.abs(i.y-o.y)<=_e;if(!h)return false;const[m,p]=a?[Math.min(i.y,r.y),Math.max(i.y,r.y)]:[Math.min(i.x,r.x),Math.max(i.x,r.x)];const[g,y]=a?[Math.min(o.y,s.y),Math.max(o.y,s.y)]:[Math.min(o.x,s.x),Math.max(o.x,s.x)];return Math.min(p,y)-Math.max(m,g)>_e}const c=a?{a:i,b:r}:{a:o,b:s};const d=a?{a:o,b:s}:{a:i,b:r};const u=c.a.x;const f=d.a.y;return u>Math.min(d.a.x,d.b.x)+_e&&u<Math.max(d.a.x,d.b.x)-_e&&f>Math.min(c.a.y,c.b.y)+_e&&f<Math.max(c.a.y,c.b.y)-_e};return e.some((i,r)=>r>0&&t.some((o,s)=>s>0&&n(e[r-1],i,t[s-1],o)))}function xp(e,t){for(let n=1;n<e.length;n++){t?.(1);const i=e[n-1],r=e[n];if(!Number.isFinite(i.x)||!Number.isFinite(i.y)||!Number.isFinite(r.x)||!Number.isFinite(r.y)||i.x!==r.x&&i.y!==r.y||i.x===r.x&&i.y===r.y)return false;const o=i.x===r.x;for(let s=1;s<n;s++){t?.(1);const a=e[s-1],l=e[s],c=a.x===l.x;if(o===c){const d=o?"y":"x",u=o?"x":"y";if(i[u]!==a[u])continue;const f=Math.max(Math.min(i[d],r[d]),Math.min(a[d],l[d]));const h=Math.min(Math.max(i[d],r[d]),Math.max(a[d],l[d]));if(s===n-1?f<h:f<=h)return false}else if(s!==n-1){const d=o?i.x:a.x,u=o?a.y:i.y;if(d>=Math.min(i.x,r.x)&&d<=Math.max(i.x,r.x)&&u>=Math.min(i.y,r.y)&&u<=Math.max(i.y,r.y)&&d>=Math.min(a.x,l.x)&&d<=Math.max(a.x,l.x)&&u>=Math.min(a.y,l.y)&&u<=Math.max(a.y,l.y))return false}}}return true}var Xi=class extends Error{constructor(n,i,r){super(r);this.pass=n;this.contract=i;this.name="LayoutPassContractError"}pass;contract;code="LAYOUT_PASS_CONTRACT_VIOLATION"};var zS=class extends Xi{constructor(n,i,r,o,s){super(n,"metric-budget",`Layout pass '${n}' worsened ${i} from ${r} to ${o} (allowance ${s})`);this.metric=i;this.before=r;this.after=o;this.allowance=s;this.name="LayoutMetricBudgetError"}metric;before;after;allowance;code="LAYOUT_METRIC_BUDGET_EXCEEDED"};var DR=e=>{const t=[...e.nodes];const n=i=>{for(const r of i){t.push(r);n(r.children??[])}};n(e.groups??[]);return t};function OR(e,t,n={}){const i=new Set;let r=e.frozen;for(const o of t){if(o.enabled&&!o.enabled(e)){i.add(o.id);continue}for(const w of o.after){if(!i.has(w)){throw new Xi(o.id,"ordering",`LayoutPass ordering: '${o.id}' must run after '${w}', which has not run`)}}const s=Object.entries(o.mayChangeMetrics??{});const a=w=>w==="improve-only"||!w.whenImproves?[]:typeof w.whenImproves==="string"?[w.whenImproves]:w.whenImproves;const l=[];for(const[w,S]of s){if(!l.includes(w))l.push(w);for(const x of a(S)){if(!l.includes(x))l.push(x)}}const c=o.proposal?l.includes("hard")?[...l]:[...l,"hard"]:l;if((s.length||o.proposal)&&!n.measureMetrics)throw new Xi(o.id,"measurement",`Layout pass '${o.id}' declares metric budgets but no geometry measurement was supplied`);const d=(w=l)=>{try{return n.measureMetrics(e,w)}catch(S){if(S instanceof Xi)throw S;throw new Xi(o.id,"measurement",`Layout pass '${o.id}' could not measure its declared geometry: ${S instanceof Error?S.message:String(S)}`)}};const u=s.length||o.proposal?d(c):void 0;const f=r?DR(e).map(({id:w,x:S,y:x,width:M,height:b})=>({id:w,x:S,y:x,width:M,height:b})):void 0;const h=r?(e.edges??[]).map(w=>({points:w.points?.map(S=>({...S})),labelPosition:w.labelPosition?{...w.labelPosition}:void 0,certificate:w.routeCertificate})):void 0;const m=(w=false)=>{let S;if(u){const x=d(w?c:l);const M=C=>{const P=u[C],E=x[C];if(P===void 0||E===void 0||!Number.isFinite(P)||!Number.isFinite(E)){throw new Xi(o.id,"measurement",`Layout pass '${o.id}' has no finite measurement for ${C}`)}return(C==="straight"||C==="portRate"?-1:1)*(E-P)};const b=w&&o.proposal?[...s,["hard","improve-only"]]:s;for(const[C,P]of b){const E=Math.max(0,...a(P).map(v=>-M(v)));const k=P==="improve-only"||P.whenImproves&&E<=1e-6?0:P.worsenBy*(P.perImprovement?Math.floor(E+1e-6):1);if(M(C)>k+1e-6){const v=new zS(o.id,C,u[C],x[C],k);if(C==="hard")throw v;S??=v}}}return S};const p=()=>{if(f){const w=DR(e);const S=o.mutates.includes("translate");const x=S&&f[0]&&w[0]?w[0].x-f[0].x:0;const M=S&&f[0]&&w[0]?w[0].y-f[0].y:0;const b=(C,P)=>S?Math.abs(P.x-C.x-x)<=1e-6&&Math.abs(P.y-C.y-M)<=1e-6:C.x===P.x&&C.y===P.y;if(w.length!==f.length||!e.frozen)throw new Xi(o.id,"freeze",`LayoutPass freeze: '${o.id}' changed frozen geometry membership or state`);for(let C=0;C<f.length;C++){const P=f[C],E=w[C];if(P.id!==E.id||P.width!==E.width||P.height!==E.height||!b(P,E)){throw new Xi(o.id,"freeze",`LayoutPass freeze: '${o.id}' moved frozen geometry without a uniform translation`)}}if(h){if((e.edges?.length??0)!==h.length)throw new Xi(o.id,"freeze",`LayoutPass freeze: '${o.id}' changed frozen edge membership`);for(let C=0;C<h.length;C++){const P=h[C],E=e.edges[C];const k=P.points?.length===E.points?.length&&(P.points??[]).every((v,T)=>E.points?.[T]&&b(v,E.points[T]));if(S){if(!k||Boolean(P.labelPosition)!==Boolean(E.labelPosition)||P.labelPosition&&!b(P.labelPosition,E.labelPosition)){throw new Xi(o.id,"freeze",`LayoutPass freeze: '${o.id}' did not translate all frozen routes and labels uniformly`)}}else if(!k&&(!o.mutates.includes("edges")||E.routeCertificate===void 0||E.routeCertificate===P.certificate)){throw new Xi(o.id,"certificate",`LayoutPass certificate: '${o.id}' rewrote edge geometry after the route-contract freeze without re-issuing routeCertificate`)}}}}};const g=o.run(e);if(g&&!o.proposal)throw new Xi(o.id,"metric-budget",`Layout pass '${o.id}' returned a rollback without declaring a cosmetic proposal`);const y=m();p();if(y){if(!g)throw y;g();const w=m(true);if(w)throw w;p()}if(o.freezesNodes)e.frozen=true;r||=e.frozen;i.add(o.id);n.onAfterPass?.(o,e)}}function GS(e,t){return e.style==="invisible"?[]:e.points.slice(1).flatMap((n,i)=>{const r=e.points[i];const o=Math.abs(r.y-n.y)<=.01;if(!o&&Math.abs(r.x-n.x)>.01)return[];const s=o?r.x:r.y,a=o?n.x:n.y;if(Math.abs(a-s)<=.01)return[];const l=o?r.y:r.x;return[{edgeIndex:t,horizontal:o,cross:l,bucket:Math.floor(l/.01),lo:Math.min(s,a),hi:Math.max(s,a),sign:Math.sign(a-s)}]})}function Jo(e){const t=e.flatMap(GS).sort((r,o)=>r.lo-o.lo||r.edgeIndex-o.edgeIndex);const n=new Map;const i=new Set;for(const r of t){for(let s=-1;s<=1;s++){const a=`${r.horizontal}:${r.bucket+s}`;const l=(n.get(a)??[]).filter(c=>c.hi-r.lo>.01);n.set(a,l);for(const c of l){if(c.edgeIndex===r.edgeIndex||c.sign===r.sign||Math.abs(c.cross-r.cross)>.01||Math.min(r.hi,c.hi)-r.lo<=.01)continue;i.add(`${Math.min(r.edgeIndex,c.edgeIndex)}:${Math.max(r.edgeIndex,c.edgeIndex)}`)}}const o=`${r.horizontal}:${r.bucket}`;n.get(o).push(r)}return i.size}function HS(e,t){const n=GS(e,0);const i=[];if(n.length===0)return i;const r=BR(e);for(const o of t){const s=BR(o);if(s.x0>r.x1+.01||s.x1<r.x0-.01||s.y0>r.y1+.01||s.y1<r.y0-.01)continue;if(GS(o,1).some(a=>n.some(l=>l.horizontal===a.horizontal&&l.sign!==a.sign&&Math.abs(l.cross-a.cross)<=.01&&Math.min(l.hi,a.hi)-Math.max(l.lo,a.lo)>.01)))i.push(o)}return i}function BR(e){let t=Infinity,n=Infinity,i=-Infinity,r=-Infinity;for(const o of e.points){t=Math.min(t,o.x);i=Math.max(i,o.x);n=Math.min(n,o.y);r=Math.max(r,o.y)}return{x0:t,y0:n,x1:i,y1:r}}var Sp=.01;function bp(e,t){return 8*Number.EPSILON*Math.max(1,Math.abs(e.x),Math.abs(e.y),Math.abs(t.x),Math.abs(t.y))}function jS(e,t,n=0){const i=Math.max(n,bp(e,t));return Math.abs(e.x-t.x)<=i&&Math.abs(e.y-t.y)<=i}function ud(e,t){return e.x-t.x||e.y-t.y}function wp(e,t){const n=e.find(i=>i.x===t.x&&i.y===t.y);if(n)n.error=Math.max(n.error,t.error);else e.push(t)}function Mp(e){e.sort(ud);const t=[];for(const n of e){if(!t.some(i=>jS(i,n,Math.max(i.error,n.error))))t.push(n)}return t.length}function WR(e,t,n){const i=n[e.edgeIndex].points;const r=c=>Math.hypot(c.x-t.x,c.y-t.y)<=Sp+Math.max(t.error,bp(c,t));if(r(i[0])||r(i[i.length-1]))return void 0;const o=c=>jS(c,t,t.error);const s=o(e.a)?e.pointIndex:o(e.b)?e.pointIndex+1:-1;if(s<0)return[e.a,e.b];let a=s-1,l=s+1;while(a>=0&&o(i[a]))a--;while(l<i.length&&o(i[l]))l++;if(a<0||l>=i.length)return void 0;return[i[a],i[l]]}function fd(e,t,n){let i=e.a,r=e.b,o=t.a,s=t.b;if(ud(i,r)>0)[i,r]=[r,i];if(ud(o,s)>0)[o,s]=[s,o];if((ud(i,o)||ud(r,s))>0)[i,r,o,s]=[o,s,i,r];const a=r.x-i.x,l=r.y-i.y;const c=s.x-o.x,d=s.y-o.y;const u=a*d,f=l*c;const h=u-f;if(Math.abs(h)<=Number.EPSILON*(Math.abs(u)+Math.abs(f)))return void 0;const m=o.x-i.x,p=o.y-i.y;const g=m*d,y=p*c,w=m*l,S=p*a;const x=(g-y)/h,M=(w-S)/h;const b=Math.abs(u)+Math.abs(f);const C=($,B,F)=>8*Number.EPSILON*(1+(Math.abs(B)+Math.abs(F)+Math.abs($)*b)/Math.abs(h));const P=C(x,g,y),E=C(M,w,S);if(x<-P||x>1+P||M<-E||M>1+E)return void 0;const k=Math.abs(x)<=P?i:Math.abs(x-1)<=P?r:void 0;const v=Math.abs(M)<=E?o:Math.abs(M-1)<=E?s:void 0;const T=Math.max(bp(i,r),bp(o,s),P*(Math.abs(a)+Math.abs(l)),E*(Math.abs(c)+Math.abs(d)));const A={...k??v??{x:i.x+x*a,y:i.y+x*l},error:T};const R=WR(e,A,n),I=WR(t,A,n);if(!R||!I)return void 0;if(R[0]===e.a&&R[1]===e.b&&I[0]===t.a&&I[1]===t.b)return A;const L=[...R.map($=>({angle:Math.atan2($.y-A.y,$.x-A.x),edge:0})),...I.map($=>({angle:Math.atan2($.y-A.y,$.x-A.x),edge:1}))].sort(($,B)=>$.angle-B.angle);for(let $=0;$<L.length;$++){const B=L[$],F=L[($+1)%L.length];const z=(F.angle-B.angle+2*Math.PI)%(2*Math.PI);if(B.edge===F.edge||z<1e-9)return void 0}return A}function Or(e,t){const n=[];e.forEach((s,a)=>{if(s.visible===false)return;for(let l=0;l+1<s.points.length;l++){const c=s.points[l],d=s.points[l+1];if(c.x===d.x&&c.y===d.y)continue;n.push({a:c,b:d,edgeIndex:a,pointIndex:l,minX:Math.min(c.x,d.x),maxX:Math.max(c.x,d.x),minY:Math.min(c.y,d.y),maxY:Math.max(c.y,d.y)})}});n.sort((s,a)=>s.minX-a.minX||s.minY-a.minY||s.edgeIndex-a.edgeIndex||s.pointIndex-a.pointIndex);const i=[];const r=new Map;for(const s of n){let a=0;for(let l=0;l<i.length;l++){const c=i[l];if(!(c.maxX>=s.minX))continue;i[a++]=c;if(c.edgeIndex===s.edgeIndex||t&&!t.has(c.edgeIndex)&&!t.has(s.edgeIndex)||c.maxY<s.minY||c.minY>s.maxY)continue;const d=fd(s,c,e);if(!d)continue;const u=`${Math.min(s.edgeIndex,c.edgeIndex)}:${Math.max(s.edgeIndex,c.edgeIndex)}`;const f=r.get(u);if(f){const h=f.find(m=>m.x===d.x&&m.y===d.y);if(h)h.error=Math.max(h.error,d.error);else f.push(d)}else r.set(u,[d])}i.length=a;i.push(s)}let o=0;for(const s of r.values()){s.sort(ud);const a=[];for(const l of s){if(!a.some(c=>jS(c,l,Math.max(c.error,l.error))))a.push(l)}o+=a.length}return o}function jl(e,t){let n;let i;for(let r=0;r+1<e.length;r++){const o=e[r],s=e[r+1];if(o.x===s.x&&o.y===s.y)continue;const a=Math.min(o.x,s.x),l=Math.max(o.x,s.x),c=Math.min(o.y,s.y),d=Math.max(o.y,s.y);for(let u=0;u+1<t.length;u++){const f=t[u],h=t[u+1];if(f.x===h.x&&f.y===h.y)continue;if(l<Math.min(f.x,h.x)||a>Math.max(f.x,h.x)||d<Math.min(f.y,h.y)||c>Math.max(f.y,h.y))continue;if(o.x===s.x&&f.x===h.x||o.y===s.y&&f.y===h.y)continue;n??=[{points:e},{points:t}];const m=fd({a:o,b:s,edgeIndex:0,pointIndex:r},{a:f,b:h,edgeIndex:1,pointIndex:u},n);if(!m)continue;if(!i)i=[m];else wp(i,m)}}return i?Mp(i):0}function Yl(e,t){const n=t?e[0]:e.at(-1);if(!n)return 0;let i=0,r=0,o=0;for(let s=1;s<e.length;s++){const a=e[t?s:e.length-1-s];const l=a.x-n.x,c=a.y-n.y,d=Math.hypot(l,c);if(!d)continue;if(!o){i=l/d;r=c/d}const u=l*i+c*r;if(Math.abs(l*r-c*i)>1e-7||u<o)break;o=u}return o}function La(e,t){let n=e;for(const i of[true,false]){const r=i?t.start:t.end;if(Yl(n,i)+1e-7>=r)continue;if(n.length<4)return void 0;const o=i?0:n.length-1,s=i?1:-1;const a=n[o],l=n[o+s],c=n[o+2*s];const d=Math.abs(l.x-a.x)>1e-7?Math.sign(l.x-a.x):0,u=Math.abs(l.y-a.y)>1e-7?Math.sign(l.y-a.y):0;if(Number(!d)+Number(!u)!==1||(d?Math.abs(l.x-c.x)>1e-7:Math.abs(l.y-c.y)>1e-7))return void 0;if(n===e)n=e.map(m=>({...m}));const f=d?"x":"y",h=a[f]+(d||u)*r;n[o+s][f]=h;n[o+2*s][f]=h}if(n===e)return e;for(const i of[true,false]){if(Yl(n,i)+1e-7<(i?t.start:t.end))return void 0;const r=i?0:e.length-1,o=i?1:r-1;const s=e[r],a=e[o],l=n[o];if((a.x-s.x)*(l.x-s.x)+(a.y-s.y)*(l.y-s.y)<=0)return void 0}return n}function kp(e,t){const n=e.points.map(l=>({x:Number(Xe(l.x)),y:Number(Xe(l.y))}));const i=e.style==="thick"?2:1;const r=Number(Xe((t.lineWidth??1)*i))/i;const o={...t,lineWidth:r};const s=!e.curve&&!(t.edgeBendRadius&&t.edgeBendRadius>0);if(s)return{regions:br({...e,points:n},o),points:n,directional:s};const a=br(e,o).map(l=>{const c=l.position==="start"?n[0]:n.at(-1);const d=l.bounds;if(!d)return{...l,anchor:c};const u=Math.max(...[d.x0,d.x1].flatMap(f=>[d.y0,d.y1].map(h=>Math.hypot(f-l.anchor.x,h-l.anchor.y))));return{...l,anchor:c,bounds:{x0:c.x-u,y0:c.y-u,x1:c.x+u,y1:c.y+u}}});return{regions:a,points:n,directional:s}}function Aa(e,t){if(e.style==="invisible"||!e.hasArrowStart&&!e.hasArrowEnd)return[];if(!YS(e,t))return void 0;const{regions:n}=kp(e,t);return n.length===Number(Boolean(e.hasArrowStart))+Number(Boolean(e.hasArrowEnd))&&n.every(af)?n:void 0}function YS(e,t){if(!e.points.every(i=>Number.isFinite(i.x)&&Number.isFinite(i.y)))return false;if(t.edgeBendRadius!==void 0&&!(Number.isFinite(t.edgeBendRadius)&&t.edgeBendRadius>=0))return false;const n=(t.lineWidth??1)*(e.style==="thick"?2:1);return!!e.inlineStyle?.["stroke-width"]||Number.isFinite(n)&&n>0}function af(e){const t=e.bounds;return!!t&&[t.x0,t.y0,t.x1,t.y1].every(Number.isFinite)&&t.x0<=t.x1&&t.y0<=t.y1}function zR(e,t,n){if(n==="mid")return false;const i=c=>n==="start"?c[0]:c.at(-1);const r=i(e),o=i(t);if(!r||!o||r.x!==o.x||r.y!==o.y)return false;const s=c=>{for(let d=1;d<c.length;d++){const u=c[n==="start"?d:c.length-d-1];if(u.x!==r.x||u.y!==r.y)return u}return void 0};const a=s(e),l=s(t);if(!a||!l)return false;if(a.x===l.x&&a.y===l.y)return true;if(r.x!==a.x&&r.y!==a.y||r.x!==l.x&&r.y!==l.y)return false;return Math.sign(a.x-r.x)===Math.sign(l.x-r.x)&&Math.sign(a.y-r.y)===Math.sign(l.y-r.y)}function tH(e,t,n){if(n==="mid"||e.length<2||t.length<2)return false;const i=l=>n==="start"?[l[0],l[1]]:[l.at(-1),l.at(-2)];const[r,o]=i(e),[s,a]=i(t);return r.x===s.x&&r.y===s.y&&o.x===a.x&&o.y===a.y}function GR(e,t){const n=e.bounds,i=t.bounds;if(!n||!i||!af(e)||!af(t))return false;const r=[n.x0,n.y0,n.x1,n.y1,i.x0,i.y0,i.x1,i.y1];if(!r.every(Number.isFinite))return false;const o=r.reduce((s,a)=>s+Math.abs(a),0)*1e-10+1e-9;return Number.isFinite(o)&&(n.x1+o<i.x0||i.x1+o<n.x0||n.y1+o<i.y0||i.y1+o<n.y0)}function Po(e,t){if(e.label&&t.label)return false;if(e.style!==t.style||e.curve!==t.curve||e.animate!==t.animate||e.animation!==t.animation)return false;const n=e.inlineStyle??{},i=t.inlineStyle??{};for(const s in n)if(!(s in i)||i[s]!==n[s])return false;for(const s in i)if(!(s in n))return false;const r=e.classNames??[],o=t.classNames??[];if(r.length!==o.length)return false;for(let s=0;s<r.length;s++)if(r[s]!==o[s])return false;return true}function js(e,t,n,i,r=e){if(!e.hasArrowStart&&!e.hasArrowEnd||e.style==="invisible")return void 0;const o=(d,u,f)=>({kind:"port",id:`${f}:${d.id??`${d.source}->${d.target}[${d.edgeIndex??n.indexOf(d)}]`}:${u}`});if(!YS({...e,points:t},i))return o(r,"mapping","marker");const s=kp(e,i),a=kp({...e,points:t},i);const l=s.regions,c=a.regions;if(c.length!==Number(Boolean(e.hasArrowStart))+Number(Boolean(e.hasArrowEnd)))return o(r,"unmeasured","marker");for(const d of c){const u=l.find(f=>f.position===d.position);if(u&&u.resource===d.resource&&u.repaint===d.repaint&&u.anchor.x===d.anchor.x&&u.anchor.y===d.anchor.y&&(s.directional&&a.directional?zR(s.points,a.points,d.position):e.curve?e.points.length===t.length&&e.points.every((f,h)=>f.x===t[h].x&&f.y===t[h].y):tH(e.points,t,d.position)))continue;if(!af(d))return o(r,d.position,"marker");for(const f of c)if(f!==d&&!GR(d,f))return o(r,f.position,"opposite-marker");for(const f of n){if(f===r||f.style==="invisible"||!f.hasArrowStart&&!f.hasArrowEnd)continue;if(!YS(f,i))return o(f,"mapping","peer-marker");const h=kp(f,i);for(const m of h.regions){const p=d.position==="start"?e.source:e.target;const g=m.position==="start"?f.source:f.target;if(a.directional&&h.directional&&af(m)&&d.position===m.position&&p===g&&d.resource===m.resource&&d.repaint===m.repaint&&d.anchor.x===m.anchor.x&&d.anchor.y===m.anchor.y&&zR(a.points,h.points,d.position)&&Po(e,f))continue;if(!GR(d,m))return o(f,m.position,"peer-marker")}}}return void 0}function wr(e,t,n,i,r=e){return js(e,t,n,i,r)===void 0}function hd(e){if(e.kind==="compound")return{...e,children:e.children.map(hd)};if(e.kind==="path")return{...e,d:Xn("d",e.d)};if(e.kind==="polygon"||e.kind==="polyline")return{...e,points:e.points.map(HR)};return Object.fromEntries(Object.entries(e).map(([t,n])=>[t,typeof n==="number"?Number(Xe(n)):n]))}var HR=e=>({x:Number(Xe(e.x)),y:Number(Xe(e.y))});var Li=e=>!!e&&Object.values(e).every(Number.isFinite)&&e.x0<=e.x1&&e.y0<=e.y1;var Ui=(e,t)=>{const n=(Math.abs(e.x0)+Math.abs(e.y0)+Math.abs(e.x1)+Math.abs(e.y1)+Math.abs(t.x0)+Math.abs(t.y0)+Math.abs(t.x1)+Math.abs(t.y1))*1e-10+1e-9;return!Number.isFinite(n)||e.x0<t.x1+n&&t.x0<e.x1+n&&e.y0<t.y1+n&&t.y0<e.y1+n};function Cp(e,t,n){if(e.style==="invisible")return{shafts:[],markers:[]};if(e.points.length>zs*Ra)return void 0;if(t.edgeBendRadius!==void 0&&!(Number.isFinite(t.edgeBendRadius)&&t.edgeBendRadius>=0))return void 0;const i={stroke:e.inlineStyle?.stroke??t.edgeStrokeColor??"var(--_line)",strokeWidth:Xn("stroke-width",e.inlineStyle?.["stroke-width"]??String((t.lineWidth??1)*(e.style==="thick"?2:1)))};const r=$n(i,e.points.length>2||!!e.curve||(t.edgeBendRadius??0)>0);if(r===void 0||e.points.length<2)return void 0;if((e.hasArrowStart||e.hasArrowEnd)&&$n({...i,stroke:"black"},false)===void 0)return void 0;const o=[];const s=f=>{if(!n())return false;const h=Oc(f,r);if(!Li(h))return false;if(r>0)o.push(h);return true};const a=tf(e,t);if(a){if(!Ss(Xn("d",a.geometry.d),f=>s(f.bounds),n))return void 0}else{const f=e.points.map(HR);for(let h=1;h<f.length;h++){const m=f[h-1],p=f[h];if(!s({x0:Math.min(m.x,p.x),y0:Math.min(m.y,p.y),x1:Math.max(m.x,p.x),y1:Math.max(m.y,p.y)}))return void 0}}const l=Aa(e,t);if(!l)return void 0;for(const f of l)if(!n()||!Li(f.bounds))return void 0;const c=kt(e,t);const d=c?Ti(e,t.lineWidth??1):0;const u=c?{x0:c.x-d,y0:c.y-d,x1:c.x+c.w+d,y1:c.y+c.h+d}:void 0;if(u&&!Li(u))return void 0;return{shafts:o,markers:l,...u?{label:u}:{}}}function Pp(e,t,n,i,r){if(!r(16))return void 0;const o=[],s=[];const a=new Map;const l=new Map;const c=h=>{if(!r(32))return false;if(h.kind==="compound")return r(h.children.length+1)&&h.children.every(c);if(h.kind==="path")return r(6*h.d.length+16);if(h.kind==="polygon"||h.kind==="polyline")return r(h.points.length*(2*384+4)+4);return r(8*384+32)};for(const h of e){const m=h.inlineStyle?.["stroke-width"]??String(i.nodeLineWidth??et.innerBox);if(!r(512+m.length*6+h.id.length))return void 0;const p=_r(h,{fill:h.inlineStyle?.fill??i.nodeFillColor??"var(--_node-fill)",stroke:h.inlineStyle?.stroke??i.nodeBorderColor??"var(--_node-stroke)",strokeWidth:Xn("stroke-width",m)},i.cornerRadius);if(!c(p.geometry))return void 0;const g=Ei({kind:"shape",id:h.id,role:"node",geometry:hd(p.geometry),paint:p.paint,...p.childPaints?{childPaints:p.childPaints}:{}});if(!Li(g))return void 0;o.push(g)}const d=(h,m=0)=>{if(m>64||!r(h.length+1))return false;for(const p of h){const g=p.concurrencyRegion?0:p.headerHeight??p.height;const y=p.inlineStyle?.["stroke-width"]??String(i.groupLineWidth??et.innerBox);if(!r(8*384+y.length*6+88)||!Number.isFinite(g)||g<0||i.groupCornerRadius!==void 0&&!(Number.isFinite(i.groupCornerRadius)&&i.groupCornerRadius>=0))return false;if(g>0){const w=hd({kind:"rect",x:p.x,y:p.y,width:p.width,height:g});const S={fill:"black",stroke:p.inlineStyle?.stroke??"black",strokeWidth:Xn("stroke-width",y)};let x;if(i.groupCornerRadius===0)x=Ei({kind:"shape",id:p.id,role:"group-header",geometry:w,paint:S});else{const M=$n(S,true);const b=Ei({kind:"shape",id:p.id,role:"group-header",geometry:w,paint:{fill:"black",stroke:"none"}});if(M===void 0||!Li(b))return false;x=Oc(b,M)}if(!Li(x))return false;s.push(x)}if(!d(p.children,m+1))return false}return true};if(!d(n))return void 0;for(const h of t){if(h.label&&!h.labelPosition)return void 0;const m=h.inlineStyle?.["stroke-width"]??"";const p=h.curve||(i.edgeBendRadius??0)>0?18:4;const g=h.inlineStyle?.stroke??i.edgeStrokeColor??"";if(!r(2048+h.points.length*(p*384+32)+m.length*8+(h.label?.length??0)*12+(g.length+h.source.length+h.target.length+(h.id?.length??0))*8))return void 0;const y=Cp(h,i,()=>r(1));if(!y)return void 0;a.set(h,y)}const u=(h,m)=>{if(!r(4))return void 0;const p=l.get(h);if(p&&p.x===m.x&&p.y===m.y)return p.box;if(!r(64+(h.label?.length??0)*12))return void 0;const g=kt({...h,labelPosition:m},i);if(!g)return void 0;const y=Ti(h,i.lineWidth??1);const w={x0:g.x-y,y0:g.y-y,x1:g.x+g.w+y,y1:g.y+g.h+y};if(!Li(w)||!r(6))return void 0;l.set(h,{x:m.x,y:m.y,box:w});return w};const f=(h,m,p,g,y)=>{const w=u(h,m);if(!w)return false;for(const x of o)if(!r(1)||Ui(w,x))return false;for(const x of s)if(!r(1)||Ui(w,x))return false;let S=true;for(const x of t){if(!r(1))return false;const M=a.get(x);for(const P of M.markers)if(!r(1)||!Li(P.bounds)||Ui(w,P.bounds))return false;if(x===h)continue;for(const P of M.shafts)if(!r(1)||Ui(w,P))return false;if(y instanceof Set?y.has(x):x===y)continue;const b=p.get(x)??x.labelPosition;if(!x.label||!b)continue;const C=u(x,b);if(!C)return false;if(Ui(w,C)){if(g&&!g.has(x)){if(!r(1))return false;g.add(x)}S=false}}return S};return{clear:f,label:u}}var Ep=new WeakMap;function jR(e){const t=e.points[0];if(!t)return;const n=[];for(const i of e.points)n.push(i.x-t.x,i.y-t.y);Ep.set(e,{source:e.source,target:e.target,edgeIndex:e.edgeIndex,coordinates:n})}function Eo(e,t){const n=e[0];if(!n||e.length<2||!(e.every(i=>i.source===n.source)||e.every(i=>i.target===n.target)||e.every(i=>i.source===n.source&&i.target===n.target||i.source===n.target&&i.target===n.source))){throw new Error("Bundle construction requires related fan or parallel routes")}for(const i of e){jR(i);t.add(i)}}function Ia(e){const t=Ep.get(e);if(!t||e.source!==t.source||e.target!==t.target||e.edgeIndex!==t.edgeIndex||e.points.length*2!==t.coordinates.length)return false;const n=e.points[0];if(!n)return false;for(let i=0;i<e.points.length;i++){const r=e.points[i];if(!(Math.abs(r.x-n.x-t.coordinates[i*2])<=1e-6)||!(Math.abs(r.y-n.y-t.coordinates[i*2+1])<=1e-6))return false}return true}function ql(e){return Ia(e)?Ep.get(e):void 0}function Fa(e,t){if(t&&Ep.get(e)===t&&e.source===t.source&&e.target===t.target&&e.edgeIndex===t.edgeIndex)jR(e)}function Xl(e){return Dr(e)?2:1}function YR(e,t){if(Dr(e)&&(t==="NE"||t==="SE"||t==="SW"||t==="NW")){return Vo(e)[t]}return Ft(e)[t]}function XS(e,t,n,i){const r=bi(t).boundary;if(r.kind!=="rect"||e.points.length<2)return;const o=n?0:e.points.length-1;const s=e.points[o];const a=r.x;const l=r.x+r.width;const c=r.y;const d=r.y+r.height;const u=(h,m)=>Math.abs(h-m)<=pn;const f=(h,m)=>{const p=[...e.points];p[o]=h;if(Math.abs(h.x-m.x)>_e||Math.abs(h.y-m.y)>_e){if(n){const g=p[1];if(!g||Math.abs(g.x-m.x)>_e||Math.abs(g.y-m.y)>_e)p.splice(1,0,m)}else{const g=p[p.length-2];if(!g||Math.abs(g.x-m.x)>_e||Math.abs(g.y-m.y)>_e)p.splice(p.length-1,0,m)}}if(wr(e,p,i.edges,i.style))wi(i,e,p)};if(u(s.x,a)||u(s.x,l)){const h=u(s.x,a)?a:l;if(s.y<c-pn)f({x:h,y:c},{x:h,y:s.y});else if(s.y>d+pn)f({x:h,y:d},{x:h,y:s.y});return}if(u(s.y,c)||u(s.y,d)){const h=u(s.y,c)?c:d;if(s.x<a-pn)f({x:a,y:h},{x:s.x,y:h});else if(s.x>l+pn)f({x:l,y:h},{x:s.x,y:h})}}function nH(e,t){if(t!==2&&t!==3)return null;const n=Sr(e,1);const i=n==="E"?"NE":n==="S"?"SW":"NW";const r=n==="W"?"SW":n==="N"?"NE":"SE";return t===2?[i,r]:[i,n,r]}function qR(e,t,n,i){if(!Dr(t)||e.edgeIndex===void 0||n.classes?.[e.edgeIndex]!=="primary-forward"){return null}const r=Hs(n.nodes);const o=n.edges.filter(d=>d.source===e.source&&d.edgeIndex!==void 0&&n.classes?.[d.edgeIndex]==="primary-forward"&&r.has(d.target)).sort((d,u)=>{const f=r.get(d.target);const h=r.get(u.target);const m=f[i.cross]+(i.cross==="y"?f.height:f.width)/2;const p=h[i.cross]+(i.cross==="y"?h.height:h.width)/2;return m-p||(d.edgeIndex??0)-(u.edgeIndex??0)});const s=nH(i,o.length);if(!s)return null;const a=o.indexOf(e);if(a<0)return null;const l=s[a];const c=o.map(d=>{const u=r.get(d.target);return u[i.main]+(i.main==="x"?u.width:u.height)/2});return{sourcePort:l,sourceLane:YR(t,l)[i.cross],targetsShareRank:Math.max(...c)-Math.min(...c)<=1}}function iH(e,t,n,i){return qR(e,t,n,i)?.sourceLane}function US(e,t,n,i,r){const o=qR(e,t,i,r);if(!o||!o.targetsShareRank)return null;const s=Sr(r,-1);const a=Ft(n)[s][r.cross];if(Math.abs(o.sourceLane-a)<=pn)return null;return{sourcePort:o.sourcePort,sourceLane:o.sourceLane,targetPort:s,targetLane:a}}function XR(e,t,n,i){if(e.points.length<=2)return false;const r=e.points[0];const o=e.points[e.points.length-1];const s=YR(t,i.sourcePort);const a=Ft(n)[i.targetPort];return Math.abs(r.x-s.x)<=pn&&Math.abs(r.y-s.y)<=pn&&Math.abs(o.x-a.x)<=pn&&Math.abs(o.y-a.y)<=pn}function UR(e,t,n){if(n.fixedLabels||n.finalLabelClearance)return false;if(!n.classes||e.edgeIndex===void 0||t.edgeIndex===void 0)return false;return n.classes[e.edgeIndex]==="primary-forward"&&n.classes[t.edgeIndex]==="feedback"&&t.source===e.target&&t.target===e.source}function Ai(e){return`${e.source}->${e.target}`}function Rp(e,t,n,i,r,o=r.axis){return VR(e,t,n,i,r,o,false)}function Ii(e,t,n,i,r,o){return VR(e,t,n,i,r,o,true)}function VR(e,t,n,i,r,o,s){const a=s?void 0:[];const l=r.nodeLaneIndexes;const c=mR(l,r.nodes,o.cross,Bt);const d=c?up(c,t):null;const u=c&&d!==null;const f=u?c.offsets[d]??0:0;const h=u?c.offsets[d+1]??0:r.nodes.length;for(let p=f;p<h;p++){const g=r.nodes[u?c.ordinals[p]:p];if(g.id===e.source||g.id===e.target)continue;const y=(o.cross==="x"?g.x:g.y)-Bt;const w=(o.cross==="x"?g.x:g.y)+(o.cross==="y"?g.height:g.width)+Bt;if(t>y&&t<w){const S=(o.main==="x"?g.x:g.y)-Bt;const x=(o.main==="x"?g.x:g.y)+(o.main==="x"?g.width:g.height)+Bt;if(Math.min(i,x)-Math.max(n,S)>_e){if(s)return true;a.push({kind:"node",id:g.id})}}}if(r.groups?.length&&e.style!=="invisible"){const p=g=>{const y=g.concurrencyRegion?0:g.headerHeight??g.height;const w=!Number.isFinite(y)||y<0;const S=o.cross==="x"?g.x:g.y;const x=S+(o.cross==="x"?g.width:y);const M=o.main==="x"?g.x:g.y;const b=M+(o.main==="x"?g.width:y);if(w||y>0&&g.width>0&&t>S&&t<x&&Math.min(i,b)>Math.max(n,M)){if(s)return true;a.push({kind:"group-header",id:g.id})}for(const C of g.children)if(p(C))return true;return false};for(const g of r.groups)if(p(g))return true}const m=r.routeChannelGeometry;for(let p=0;p<r.edges.length;p++){const g=r.edges[p];if(g===e||e.edgeIndex!==void 0&&g.edgeIndex===e.edgeIndex)continue;const y=!UR(e,g,r)&&g.label&&g.labelPosition?g.labelBlock??vi(qe(g.label,g.labelContent),r.style):void 0;if(y){const w=y.width+2*nn,S=y.height+2*nn;const x=g.labelPosition.x-w/2,M=g.labelPosition.y-S/2;const b=(o.main==="x"?x:M)-Bt;const C=b+(o.main==="x"?w:S)+2*Bt;const P=(o.cross==="y"?M:x)-Bt;const E=P+(o.cross==="y"?S:w)+2*Bt;if(t>P&&t<E&&Math.min(i,C)-Math.max(n,b)>_e){if(s)return true;a.push({kind:"label",id:Ai(g)})}}if(m&&!pR(m,g,o.cross,t,n,i,Bt,_e))continue;for(let w=1;w<g.points.length;w++){const S=g.points[w-1],x=g.points[w];if(Math.abs((o.cross==="x"?S.x:S.y)-(o.cross==="x"?x.x:x.y))>_e)continue;if(Math.abs((o.cross==="x"?S.x:S.y)-t)>=Bt)continue;const M=Math.min(o.main==="x"?S.x:S.y,o.main==="x"?x.x:x.y);const b=Math.max(o.main==="x"?S.x:S.y,o.main==="x"?x.x:x.y);if(Math.min(i,b)-Math.max(n,M)>_e){if(g.target===e.target&&g.source!==e.source&&Po(e,g)&&Math.abs((o.cross==="x"?S.x:S.y)-t)<_e&&w===g.points.length-1){continue}if(s)return true;a.push({kind:"channel",id:Ai(g)});break}}}if(e.label){const p=e.labelBlock??vi(qe(e.label,e.labelContent),r.style);const g=(o.main==="x"?p.width:p.height)+2*nn;if(i-n<g+AR){if(s)return true;a.push({kind:"label",id:Ai(e)})}}return s?false:vp(a)}function Vi(e,t,n,i){if(!e.label)return{x:(t.x+n.x)/2,y:(t.y+n.y)/2};const r=e.labelBlock??vi(qe(e.label,e.labelContent),i.style);const o=2;const s=(F,z,_,H,D,j,W,O,N=o)=>F<D+W+N&&F+_+N>D&&z<j+O+N&&z+H+N>j;const a=i.style.lineWidth??1;const l=ad(e,a,"start"),c=ad(e,a,"end");const d=F=>Math.max(i.finalLabelClearance?8:o,F.id===e.source?l:0,F.id===e.target?c:0);const u=i.finalLabelClearance?16:o,f=i.finalLabelClearance?8:o;const h=i.edges.filter(F=>F!==e&&!(e.edgeIndex!==void 0&&F.edgeIndex===e.edgeIndex));const m=F=>!i.finalLabelClearance&&UR(e,F,i)?null:kt(F,i.style);const p=Math.abs(t.x-n.x)<_e,g=p!==Math.abs(t.y-n.y)<_e;const y=p?"y":"x",w=p?"x":"y",S=p?"x1":"y1",x=p?"y1":"x1";const M=(p?r.height:r.width)/2+nn,b=(p?r.width:r.height)/2+nn;const C=Math.min(t[w],n[w])-b-1e-6,P=Math.max(t[w],n[w])+b+1e-6;const E=Math.min(t[y],n[y])-M-1e-6,k=Math.max(t[y],n[y])+M+1e-6;let v;const T=()=>{if(v)return v;const F=v=[];const z=(_,H,D,j,W,O,N)=>{if(!g||(p?W:O)+N>=C&&(p?_:H)-N<=P&&(p?O:W)+N>=E&&(p?H:_)-N<=k)F.push({x:_,y:H,w:D,h:j,x1:W,y1:O,gap:N})};for(const _ of i.nodes)z(_.x,_.y,_.width,_.height,_.x+_.width,_.y+_.height,d(_));for(const _ of h){const H=m(_);if(H)z(H.x,H.y,H.w,H.h,H.x+H.w,H.y+H.h,u);for(let D=1;D<_.points.length;D++){const j=_.points[D-1],W=_.points[D];const O=Math.min(j.x,W.x),N=Math.max(j.x,W.x);const G=Math.min(j.y,W.y),Y=Math.max(j.y,W.y);z(O,G,N-O,Y-G,N,Y,f)}}return F};const A=(F,z)=>{const _=Bs(F,z,r);return!T().some(H=>s(_.x,_.y,_.w,_.h,H.x,H.y,H.w,H.h,H.gap))};for(const F of[.5,1/3,2/3,.25,.75,1/6,5/6]){const z=t.x+(n.x-t.x)*F;const _=t.y+(n.y-t.y)*F;if(A(z,_))return{x:z,y:_}}if(!g)return null;const R=Math.min(t[y],n[y]),I=Math.max(t[y],n[y]),L=(R+I)/2;if(I-R<2*M-2*_e)return null;const $=[L];for(const F of T()){if(F[S]+F.gap<=t[w]-b||F[w]-F.gap>=t[w]+b)continue;$.push(F[y]-F.gap-M-_e,F[x]+F.gap+M+_e)}const B=$.filter(F=>F>=R+M-_e&&F<=I-M+_e).sort((F,z)=>Math.abs(F-L)-Math.abs(z-L)||F-z);for(const F of B.slice(0,16)){const z=y==="x"?{x:F,y:t.y}:{x:t.x,y:F};if(A(z.x,z.y))return z}return null}function or(e,t,n,i=Infinity){if(t.style==="invisible")return 0;let r=0;for(const o of n.edges){if(o===t||o.style==="invisible"||t.edgeIndex!==void 0&&o.edgeIndex===t.edgeIndex)continue;r+=jl(e,o.points);if(r>i)return r}return r}function Ul(e,t){for(const n of t.nodes){if(n.id===e.source||n.id===e.target)continue;if(Na(e.points,n))return true}return false}function vp(e){const t=new Set;return e.filter(n=>{const i=`${n.kind}:${n.id}`;if(t.has(i))return false;t.add(i);return true})}function KR(e,t,n,i,r,o){const s=Ko(t,r,1);const a=Ko(n,r,-1);if(!s||!a)return null;const l=Math.max(s.lo,a.lo);const c=Math.min(s.hi,a.hi);const d=(C,P)=>{if(!Dr(C))return P;return{lo:C[r.cross]+2,hi:C[r.cross]+(r.cross==="y"?C.height:C.width)-2}};const u=Math.max(d(t,s).lo,d(n,a).lo);const f=Math.min(d(t,s).hi,d(n,a).hi);const h=C=>C[r.cross]+(r.cross==="y"?C.height:C.width)/2;const m=C=>Math.abs(C-h(n))<=pn||Math.abs(C-h(t))<=pn;if(u>f){return{overlapLo:l,overlapHi:c,relaxedLo:u,relaxedHi:f,candidates:[],isPortLane:m,emptyRelaxed:true}}const p=[];const g=C=>{if(p.every(P=>Math.abs(P-C)>.5))p.push(C)};const y=n[r.cross]+(r.cross==="y"?n.height:n.width)/2;const w=t[r.cross]+(r.cross==="y"?t.height:t.width)/2;const S=i.sideUse?.get(`${t.id}:${Sr(r,1)}`)??1;const x=Dr(t)&&S===1&&Xl(t)>=Xl(n);const M=i.classes&&i.edges.some(C=>C!==e&&C.source===e.target&&C.target===e.source&&!C.label&&!e.label&&C.edgeIndex!==void 0&&e.edgeIndex!==void 0);const b=M&&Dr(t)&&Dr(n);if(o!==void 0){p.push(o)}else if(b){const C=i.classes[e.edgeIndex]==="feedback"?1:-1;const P=t[r.cross]+(r.cross==="y"?t.height:t.width)/2;const E=(r.cross==="y"?t.height:t.width)/4;g(P+C*E);g((l+c)/2+C*va/2);g(y);g(w)}else if(M){const C=(l+c)/2;const P=i.classes[e.edgeIndex]==="feedback"?1:-1;g(C+P*va/2);g(y);g(w)}else if(x){g(w);g(y)}else{const C=iH(e,t,i,r);if(C!==void 0)g(C);g(y);g(w)}if(o===void 0){if(e.points.length>0){g(e.points[e.points.length-1][r.cross]);g(e.points[0][r.cross]);const C=e.points.map(P=>P[r.cross]);g(Math.min(...C));g(Math.max(...C))}g((l+c)/2);g((l+(l+c)/2)/2);g(((l+c)/2+c)/2)}return{overlapLo:l,overlapHi:c,relaxedLo:u,relaxedHi:f,candidates:p,isPortLane:m,emptyRelaxed:false}}function qS(e,t,n,i,r,o,s){const a=s.isPortLane(i)?s.relaxedLo:s.overlapLo;const l=s.isPortLane(i)?s.relaxedHi:s.overlapHi;if(i<a-_e||i>l+_e)return{blockers:[{kind:"span",id:Ai(e)}]};const c=ro(t,i,o,1);const d=ro(n,i,o,-1);if(c===null||d===null)return{blockers:[{kind:"span",id:Ai(e)}]};if((d-c)*o.sign<=_e)return{blockers:[{kind:"span",id:Ai(e)}]};const u=Math.min(c,d);const f=Math.max(c,d);const h=Rp(e,i,u,f,r,o);if(h.length>0)return{blockers:h};const m=Ln(o,c,i);const p=Ln(o,d,i);const g=r.nodeLaneIndexes&&!vr()?s.priorCrossings??=or(e.points,e,r):or(e.points,e,r);const y=or([m,p],e,r,g);if(y>g){return{blockers:[{kind:"crossing",id:Ai(e)}]}}const w=Vi(e,m,p,r);if(w===null)return{blockers:[{kind:"label",id:Ai(e)}]};return{start:m,end:p,slot:w}}function Vl(e,t,n,i,r=i.axis,o,s=e){const a=KR(e,t,n,i,r,o);if(!a)return{applied:false,blockers:[]};if(a.emptyRelaxed)return{applied:false,blockers:[{kind:"span",id:Ai(e)}]};const l=[];for(let c=0;c<a.candidates.length;c++){const d=a.candidates[c];const u=qS(e,t,n,d,i,r,a);if("blockers"in u){l.push(...u.blockers);continue}const f=js(e,[u.start,u.end],i.edges,i.style,s);if(f){l.push(f);continue}const h=pt(e.points);if(h.length===2&&Math.abs(h[0][r.cross]-h[1][r.cross])<=_e){const m=Number(Boolean(Vn(t,h[0])))+Number(Boolean(Vn(n,h[1])));const p=Number(Boolean(Vn(t,u.start)))+Number(Boolean(Vn(n,u.end)));const g=p<m;const y=()=>{const w=i.edges.filter(S=>S!==e);return Jo([{...e,points:[u.start,u.end]},...w])<Jo([{...e,points:h},...w])};if(g&&or([u.start,u.end],e,i)>=or(h,e,i)&&!y()){const w=h[0][r.cross];const S=qS(e,t,n,w,i,r,{...a,overlapLo:Math.min(a.overlapLo,w),overlapHi:Math.max(a.overlapHi,w),relaxedLo:Math.min(a.relaxedLo,w),relaxedHi:Math.max(a.relaxedHi,w)});if(!("blockers"in S)&&Math.hypot(S.start.x-h[0].x,S.start.y-h[0].y)<=_e&&Math.hypot(S.end.x-h[1].x,S.end.y-h[1].y)<=_e){if(e.label)e.labelPosition=S.slot??void 0;return{applied:true,blockers:[]}}if("blockers"in S)l.push(...S.blockers);continue}}wi(i,e,[u.start,u.end]);if(e.label)e.labelPosition=u.slot??void 0;return{applied:true,blockers:[],usedCandidateIndex:c}}return{applied:false,blockers:vp(l)}}function lf(e,t,n,i,r=i.axis){const o=KR(e,t,n,i,r);if(!o||o.emptyRelaxed)return null;if(!io(t)||!io(n))return null;if(!rf(e.points,r))return null;for(const s of o.candidates){const a=qS(e,t,n,s,i,r,o);if(!("blockers"in a))return s}return null}function Ro(e,t,n,i,r){const o=cd(n);return{ctx:{nodes:e,edges:t,groups:r,axis:o,style:i},axis:o}}function oo(e,t,n,i=e.labelPosition){if(!e.label||!i)return null;const r=e.labelBlock??vi(qe(e.label,e.labelContent),n);const o=Bs(i.x,i.y,r);for(const s of t){if(s===e||e.edgeIndex!==void 0&&s.edgeIndex===e.edgeIndex)continue;for(let a=1;a<s.points.length;a++){const l=s.points[a-1],c=s.points[a];const d=Math.abs(l.x-c.x)<_e;const u=Math.abs(l.y-c.y)<_e;if(!d&&!u)continue;const f=Math.min(l.x,c.x),h=Math.max(l.x,c.x);const m=Math.min(l.y,c.y),p=Math.max(l.y,c.y);const g=h>=o.x&&f<=o.x+o.w&&p>=o.y&&m<=o.y+o.h;if(!g)continue;for(let y=1;y<e.points.length;y++){const w=e.points[y-1],S=e.points[y];const x=d?Math.abs(w.x-S.x)<_e&&Math.abs(w.x-l.x)<Bt:Math.abs(w.y-S.y)<_e&&Math.abs(w.y-l.y)<Bt;if(!x)continue;const M=d?Math.min(w.y,S.y):Math.min(w.x,S.x);const b=d?Math.max(w.y,S.y):Math.max(w.x,S.x);const C=d?m:f;const P=d?p:h;if(Math.min(b,P)-Math.max(M,C)>_e)return s}}}return null}function md(e,t,n){const i=or(t.points,t,n);return or(e,t,n,i)>i}function Na(e,t){const n=t.shape==="cylinder"?bi(t).boundary:void 0;const i=(t.shape==="rectangle"||t.shape==="subroutine")&&(t.semanticShape===void 0||t.semanticShape==="rect"||t.semanticShape==="fr-rect"||t.semanticShape==="lin-rect"||t.semanticShape==="div-rect"||t.semanticShape==="win-pane");const r=i?0:.5;for(let o=1;o<e.length;o++){const s=e[o-1],a=e[o];const l=Math.min(s.x,a.x),c=Math.max(s.x,a.x);const d=Math.min(s.y,a.y),u=Math.max(s.y,a.y);if(n?.kind==="cylinder"&&n.height>2*n.capRadiusY&&c>t.x&&l<t.x+t.width&&u>n.y+n.capRadiusY&&d<n.y+n.height-n.capRadiusY)return true;if(c>t.x+r&&l<t.x+t.width-r&&u>t.y+r&&d<t.y+t.height-r)return true}return false}function JR(e,t,n){const i=pt(e.points);if(i.length<4)return false;const r=t.axis;const o=T=>T[r.cross];const s=T=>T[r.main];let a=-1;let l=_e;for(let T=1;T<i.length;T++){if(Math.abs(o(i[T-1])-o(i[T]))>=_e)continue;const A=(s(i[T-1])-s(i[T]))*r.sign;if(A>l){l=A;a=T-1}}if(a<1)return false;const c=o(i[a]);const d=[i[a],i[a+1]];const u=Math.sign(s(d[1])-s(d[0]));const f=i[0];const h=t.nodes.find(T=>T.id===e.source);const m=T=>u>0?T>=s(d[0])-_e&&T<s(d[1])-_e:T<=s(d[0])+_e&&T>s(d[1])+_e;const p=(T,A)=>{if(Math.abs(A-c)<_e)return true;const R=r.main==="x"?{main:"y",cross:"x",sign:A<c?1:-1}:{main:"x",cross:"y",sign:A<c?1:-1};const I={...e,points:[],label:void 0};return Rp(I,T,Math.min(A,c),Math.max(A,c),t,R).length===0};const g=(T,A,R)=>{const I=Ln(r,T,c);return Math.abs(A-c)<_e?[I,...i.slice(a+1)]:[R,I,...i.slice(a+1)]};let y=null;if(h&&io(h)){const T=h[r.cross];const A=r.cross==="y"?c>T?"S":"N":c>T?"E":"W";const R=Ft(h)[A];const I=R[r.cross];const L=R[r.main];if(m(L)&&p(L,I)){y=g(L,I,R)}}if(!y&&h){const T=u===r.sign?1:-1;const A=Ko(h,r,T);const R=bi(h).sides[Sr(r,T)];if(R.kind==="dynamic"&&A&&c>=A.lo-_e&&c<=A.hi+_e){const I=ro(h,c,r,T);if(I!==null&&m(I)&&p(I,c)){const L=Ln(r,I,c);y=g(I,c,L)}}}if(!y&&m(s(f))&&p(s(f),o(f))){y=g(s(f),o(f),f)}if(!y&&a===2&&Math.abs(o(i[1])-o(f))<_e&&t.edges.some(T=>T.source===e.source&&T!==e&&oo(T,t.edges,t.style))){const T=Math.sign(s(i[1])-s(f));const A=[s(f)+T*12];for(const R of t.edges){if(R===e)continue;for(const L of R.points)A.push(s(L)+T*12);const I=kt(R,t.style);if(I)A.push((r.main==="x"?I.x+(T>0?I.w:0):I.y+(T>0?I.h:0))+T*(Bt+_e))}A.sort((R,I)=>(R-I)*T);for(const R of A){if((R-s(f))*T<12-_e||(s(i[1])-R)*T<=_e||!m(R))continue;if(!p(R,o(f)))continue;const I=r.main==="x"?{x:R,y:o(f)}:{x:o(f),y:R};const L=r.main==="x"?{x:R,y:c}:{x:c,y:R};const $=[f,I,L,...i.slice(a+1)];if(or($,e,t)>or(i,e,t))continue;y=$;break}}const w=y??i;let S=false;{let T=-1;for(let R=1;R<w.length;R++){if(Math.abs(o(w[R-1])-c)<_e&&Math.abs(o(w[R])-c)<_e){T=R-1;break}}const A=t.nodes.find(R=>R.id===e.target);if(T>=0&&T+1<w.length-1&&A&&io(A)){const R=A[r.cross];const I=r.cross==="y"?c>R?"S":"N":c>R?"E":"W";const L=Ft(A)[I];const $=L[r.cross];const B=L[r.main];const F=w[T],z=w[T+1];const _=Math.sign(s(z)-s(F));const H=_>0?B>s(F)+_e&&B<=s(z)+_e:B<s(F)-_e&&B>=s(z)-_e;if(H&&p(B,$)){const D=Ln(r,B,c);y=[...w.slice(0,T+1),D,L];S=true}}}if(!y)return false;const x=pt(y);const M=n.get(e.target);if(ai({...e,points:x},h,M)>0)return false;const b=e.inlineStyle?.["stroke-width"]??String((t.style.lineWidth??et.connector)*(e.style==="thick"?2:1));const C=$n({stroke:"black",strokeWidth:Xn("stroke-width",b)},true);if(!h||!M||C===void 0)return false;const P=T=>{const A=T.inlineStyle?.["stroke-width"]??String(t.style.nodeLineWidth??et.innerBox);const R=$n({stroke:"black",strokeWidth:Xn("stroke-width",A)},true);if(R===void 0)return void 0;const I=Math.max(Bt,R+C)+_e;const L=T.x-I,$=T.y-I;const B=T.width+2*I,F=T.height+2*I;if(![L,$,B,F].every(Number.isFinite))return void 0;return{...T,shape:"rectangle",semanticShape:void 0,x:L,y:$,width:B,height:F}};const E=P(h),k=P(M);if(!E||!k||Na(x.slice(1),E)||Na(x.slice(0,-1),k))return false;if(md(x,e,t))return false;if(!wr(e,x,t.edges,t.style))return false;const v=e.points;wi(t,e,x);if(e.label&&e.labelPosition){const T=e.labelPosition;const A=e.points.some((R,I)=>{if(I===0)return false;const L=e.points[I-1],$=R;const B=Math.min(L.x,$.x)-1,F=Math.max(L.x,$.x)+1;const z=Math.min(L.y,$.y)-1,_=Math.max(L.y,$.y)+1;return T.x>=B&&T.x<=F&&T.y>=z&&T.y<=_});if(!A){let R=null;for(let I=1;I<e.points.length;I++){const L=e.points[I-1],$=e.points[I];if(Math.abs(o(L)-c)<_e&&Math.abs(o($)-c)<_e){R=Vi(e,L,$,t);break}}if(R){e.labelPosition=R}else{wi(t,e,v);return false}}}return JSON.stringify(e.points)!==JSON.stringify(v)}function VS(e,t,n,i,r){if(t!=="feedback")return null;if(!n||!i)return"feedback-detour";const o=c=>r.cross==="y"?c.height:c.width;const s=Math.min(n[r.cross],i[r.cross])-2;const a=Math.max(n[r.cross]+o(n),i[r.cross]+o(i))+2;const l=e.points.some(c=>c[r.cross]<s||c[r.cross]>a);return l?"outer-feedback":"feedback-detour"}function QR(e,t,n,i,r=new Set){const o=n.style;const s=new Map;const a=[];const l=new Map;const c=(u,f)=>Math.min(u.x+u.w,f.x+f.w)>Math.max(u.x,f.x)&&Math.min(u.y+u.h,f.y+f.h)>Math.max(u.y,f.y);const d=u=>{const f=e.get(u.source);if(!f)return null;const h=f.x+f.width/2;const m=f.y+f.height/2;const p=u.points.slice(1,-1);const g=p.length>0?{x:p.reduce((D,j)=>D+j.x,0)/p.length,y:p.reduce((D,j)=>D+j.y,0)/p.length}:u.points[0]??{x:f.x,y:m};const y=(g.x-h)/Math.max(f.width/2,1);const w=(g.y-m)/Math.max(f.height/2,1);const S=Math.abs(y)>=Math.abs(w)?y<0?"W":"E":w<0?"N":"S";const x=[S,NR(S),...S==="W"||S==="E"?["N","S"]:["W","E"]];const M=u.label?u.labelBlock??vi(qe(u.label,u.labelContent),o):null;const b=D=>M?(D==="N"||D==="S"?M.height:M.width)+2*nn:0;const C=(D,j)=>{const W=D==="N"||D==="S";const O=W?h:m;const N=O-j-6;const G=O+j+6;const Y=D==="W"?f.x:D==="E"?f.x+f.width:D==="N"?f.y:f.y+f.height;const q=D==="W"||D==="N"?-1:1;let V=1e3;const ne=(X,U,K,Z)=>{if(U<N||X>G)return;const Q=(K-Y)*q;const se=Z?2:6;if(Q>0)V=Math.min(V,Q-se)};for(const X of n.nodes){if(X.id===f.id)continue;ne(W?X.x:X.y,W?X.x+X.width:X.y+X.height,W?q<0?X.y+X.height:X.y:q<0?X.x+X.width:X.x,false)}for(const X of t.values()){const U=h>X.x&&h<X.x+X.width&&m>X.y&&m<X.y+X.height;if(U){const K=W?q<0?X.y:X.y+X.height:q<0?X.x:X.x+X.width;const Z=(K-Y)*q;if(Z>0)V=Math.min(V,Z-4)}else{ne(W?X.x:X.y,W?X.x+X.width:X.y+X.height,W?q<0?X.y+X.height:X.y:q<0?X.x+X.width:X.x,false)}}for(const X of n.edges){if(X===u||X.source===X.target||!X.label)continue;const U=kt(X,o);if(!U)continue;ne(W?U.x:U.y,W?U.x+U.w:U.y+U.h,W?q<0?U.y+U.h:U.y:q<0?U.x+U.w:U.x,false)}return V};const P=D=>D==="N"||D==="S"?f.width:f.height;const E=D=>`${f.id}:${D}`;const k=D=>s.get(E(D))??0;const v=D=>Math.min(Math.max(P(D)/4,6),10,Math.max(P(D)/2-2,3));const T=D=>v(D)+k(D)*6<=P(D)/2-2;const A=D=>{const j=k(D);const W=v(D)+j*6;const O=24+j*Math.max(14,b(D)+8);return{d:W,desired:O,clear:C(D,W)}};const R=(D,j,W)=>{if(!u.label||!M)return[];const O=D==="N"||D==="S";const N=D==="W"||D==="N"?-1:1;const G=D==="W"||D==="S"?-1:1;const Y=D==="W"?f.x:D==="E"?f.x+f.width:D==="N"?f.y:f.y+f.height;const q=Y+N*(j+b(D)/2+4);const V=(O?M.width:M.height)+2*nn+2;const ne=k(D);let X=O?{x:h,y:q}:{x:q,y:m};const U=ie=>({x:ie.x-M.width/2-nn,y:ie.y-M.height/2-nn,w:M.width+2*nn,h:M.height+2*nn});const K=E(D);const Z=l.get(K)??[];const Q=[];const se=a.slice();if(ne>0){for(const ie of Z){const oe=ie.edge.labelPosition;const ue=O?{x:h-G*V,y:oe.y}:{x:oe.x,y:m-G*V};Q.push({edge:ie.edge,position:ue,rectIndex:ie.rectIndex});se[ie.rectIndex]=kt({...ie.edge,labelPosition:ue},o)}X=O?{x:h+G*V*ne,y:q}:{x:q,y:m+G*V*ne}}if(se.some(ie=>c(U(X),ie))){for(let ie=0;ie<8;ie++){const oe=ie%2===0?G:-G;const ue=(1+Math.floor(ie/2))*V;const ye=O?{x:h+oe*ue,y:q}:{x:q,y:m+oe*ue};if(!se.some(Se=>c(U(ye),Se))){X=ye;break}}}Q.push({edge:u,position:X});const te=new Map(Q.map(ie=>[ie.edge,ie.position]));const ee=(ie,oe)=>{const ue=kt({...ie,labelPosition:oe},o);if(!ue)return null;const ye=Ti(ie,o.lineWidth??1);return{x:ue.x-ye,y:ue.y-ye,w:ue.w+2*ye,h:ue.h+2*ye}};const ae=o;for(const ie of Q){const oe=ee(ie.edge,ie.position);const ue=kt({...ie.edge,labelPosition:ie.position},o);if(!oe||!ue||!Object.values(oe).every(Number.isFinite))return null;const ye=ie.edge===u?W:ie.edge.points;let Se=Infinity;for(let Ie=1;Ie<ye.length;Ie++){const Ee=ye[Ie-1],ve=ye[Ie];if(Ee.x!==ve.x&&Ee.y!==ve.y)return null;Se=Math.min(Se,Math.max(ue.x-Math.max(Ee.x,ve.x),Math.min(Ee.x,ve.x)-ue.x-ue.w,0)+Math.max(ue.y-Math.max(Ee.y,ve.y),Math.min(Ee.y,ve.y)-ue.y-ue.h,0))}if(!(Se<=ue.h/2+4))return null;const Te=(Ie,Ee,ve,$e)=>{const De=(Math.abs(Ie)+Math.abs(Ee)+Math.abs(ve)+Math.abs($e)+Math.abs(oe.x)+Math.abs(oe.y)+oe.w+oe.h)*1e-10+1e-9;return!Number.isFinite(De)||c(oe,{x:Ie-De,y:Ee-De,w:ve+2*De,h:$e+2*De})};for(const Ie of n.nodes){const Ee=_r(Ie,{fill:Ie.inlineStyle?.fill??ae.nodeFillColor??"var(--_node-fill)",stroke:Ie.inlineStyle?.stroke??ae.nodeBorderColor??"var(--_node-stroke)",strokeWidth:Ie.inlineStyle?.["stroke-width"]??String(ae.nodeLineWidth??et.innerBox)},ae.cornerRadius??0);const ve=Ei({kind:"shape",id:Ie.id,role:"node",geometry:Ee.geometry,paint:Ee.paint,...Ee.childPaints?{childPaints:Ee.childPaints}:{}});if(!ve||Te(ve.x0,ve.y0,ve.x1-ve.x0,ve.y1-ve.y0))return null}for(const Ie of t.values()){const Ee=Ie.concurrencyRegion?0:Ie.headerHeight??Ie.height;if(!Number.isFinite(Ee)||Ee<0)return null;const ve=$n({stroke:Ie.inlineStyle?.stroke??"black",strokeWidth:Ie.inlineStyle?.["stroke-width"]??String(ae.groupLineWidth??et.innerBox)},true);if(ve===void 0)return null;if(Ee>0&&Te(Ie.x-ve,Ie.y-ve,Ie.width+2*ve,Ee+2*ve))return null}for(const Ie of n.edges){const Ee=Ie===u?{...Ie,points:W}:Ie;const ve=Aa(Ee,o);if(!ve||ve.some(fe=>!fe.bounds||Te(fe.bounds.x0,fe.bounds.y0,fe.bounds.x1-fe.bounds.x0,fe.bounds.y1-fe.bounds.y0)))return null;if(Ie===ie.edge||!Ie.label)continue;const $e=te.get(Ie)??Ie.labelPosition;if(!$e)continue;const De=ee(Ie,$e);if(!De||Te(De.x,De.y,De.w,De.h))return null}}return Q};const I=(D,j)=>{const W=Math.max(Math.min(j.desired,j.clear),8);const O=j.d;const N=(()=>{switch(D){case"W":return[{x:f.x,y:m-O},{x:f.x-W,y:m-O},{x:f.x-W,y:m+O},{x:f.x,y:m+O}];case"E":return[{x:f.x+f.width,y:m-O},{x:f.x+f.width+W,y:m-O},{x:f.x+f.width+W,y:m+O},{x:f.x+f.width,y:m+O}];case"N":return[{x:h-O,y:f.y},{x:h-O,y:f.y-W},{x:h+O,y:f.y-W},{x:h+O,y:f.y}];default:return[{x:h-O,y:f.y+f.height},{x:h-O,y:f.y+f.height+W},{x:h+O,y:f.y+f.height+W},{x:h+O,y:f.y+f.height}]}})();const G=si(si(N,f,true),f,false);if([...r].some(V=>V!==u&&sf(G,V.points)))return null;const Y=js(u,G,n.edges,o);if(Y){i?.push(Y);return null}const q=R(D,W,G);return q?{points:G,labels:q}:null};let L=null;let $=null;let B=null;let F=[];const z=x.map((D,j)=>({side:D,preference:j,rank:k(D)})).sort((D,j)=>D.rank-j.rank||D.preference-j.preference).map(D=>D.side);for(const D of z){if(!T(D))continue;const j=A(D);if(j.clear<Math.min(j.desired,14))continue;const W=I(D,j);if(!W)continue;L=D;$=j;B=W.points;F=W.labels;break}if(!L||!$||!B){const D=z.filter(T);if(D.length===0)return null;const j=D.reduce((N,G)=>A(G).clear>A(N).clear?G:N,D[0]);const W=A(j);const O=I(j,W);if(!O)return null;L=j;$=W;B=O.points;F=O.labels}r.add(u);s.set(E(L),k(L)+1);wi(n,u,B);const _=E(L);const H=l.get(_)??[];for(const D of F){D.edge.labelPosition=D.position;const j=kt(D.edge,o);if(D.rectIndex!==void 0)a[D.rectIndex]=j;else{const W=a.push(j)-1;H.push({edge:D.edge,rectIndex:W})}}if(F.length)l.set(_,H);return L};return d}function cf(e){return e.routeCertificate?.invariant==="bundle"&&Ia(e)}function ZR(e){return e.some((t,n)=>n>0&&Math.abs(t.x-e[n-1].x)>_e&&Math.abs(t.y-e[n-1].y)>_e)}function KS(e,t=false){e.invariant="straight";e.bendCount=0;e.directLaneClear=true;if(t)e.straightened=true;e.directLaneBlockedBy=void 0}function Tp(e,t,n,i,r){const o=Ta(t);const{axis:s,ctx:a}=WS(e,t,i,o,k=>n.has(k)&&Ia(k),Boolean(r?.preserveLabels));a.fixedLabels=Boolean(r?.preserveLabels);const l=Hs(e.nodes);const c=QS(e.groups);const d=[];let u;const f=(k,v)=>{const T=v.routeClass==="feedback"?{...s,sign:s.sign===1?-1:1}:s;const A=l.get(k.source);const R=l.get(k.target);const I=A&&R&&io(A)&&io(R)&&(v.routeClass==="feedback"||rf(BS(k.points),T));if(!I){v.invariant=VS(k,v.routeClass,A,R,a.axis)??"unverified-shape";return{applied:false,mutated:false}}if(r?.preserveStraightRoutes&&k.points.length===2){const H=k.points[0],D=k.points[1],j=s.main,W=s.cross;if(H[W]===D[W]&&ai(k,A,R)===0&&!Ii(k,H[W],Math.min(H[j],D[j]),Math.max(H[j],D[j]),a,T)){KS(v);return{applied:true,mutated:false}}}const L=a.sideUse?.get(`${A.id}:${Sr(T,1)}`)??1;const $=v.routeClass==="primary-forward"&&Dr(A)&&L===1&&Xl(A)>=Xl(R);const B=JSON.stringify(k.points);if($){const H=A[T.cross]+(T.cross==="y"?A.height:A.width)/2;const D=Vl(k,A,R,a,T,H);if(D.applied){const j=JSON.stringify(k.points)!==B;KS(v,j);return{applied:true,mutated:j}}if(w(k,A,R,a,T)||g(k,A,R,a,T,true)){v.invariant="explained-detour";v.directLaneClear=false;v.directLaneBlockedBy=vp(D.blockers);v.bendCount=li(k.points);return{applied:false,mutated:JSON.stringify(k.points)!==B}}}const F=US(k,A,R,a,T);if(F&&g(k,A,R,a,T,false,{sourceLane:F.sourceLane,targetLane:F.targetLane,preferSourceJog:true})){v.invariant="explained-detour";v.directLaneClear=false;v.directLaneBlockedBy=[{kind:"port",id:Ai(k)}];v.bendCount=li(k.points);return{applied:false,mutated:JSON.stringify(k.points)!==B}}const z=Vl(k,A,R,a,T);if(z.applied){const H=JSON.stringify(k.points)!==B;KS(v,H);return{applied:true,mutated:H,upgradeable:(z.usedCandidateIndex??0)>0}}v.invariant=VS(k,v.routeClass,A,R,a.axis)??"explained-detour";v.directLaneClear=false;v.directLaneBlockedBy=z.blockers;let _=false;if(v.invariant==="outer-feedback"||v.invariant==="feedback-detour"){if(v.invariant==="outer-feedback"){_=JR(k,a,l);v.bendCount=li(k.points)}if(Ul(k,a)&&g(k,A,R,a,T)){v.bendCount=li(k.points);_=true}}else if(v.invariant==="explained-detour"&&(v.bendCount>2||ZR(k.points)||Ul(k,a)||!Vn(A,k.points[0])||!Vn(R,k.points[k.points.length-1]))){const H=g(k,A,R,a,T)||y(k,A,R,a,T);if(p(k,R,a,T)||H){v.bendCount=li(k.points);_=true}}return{applied:false,mutated:_}};const h=(k,v,T)=>a.edges.some(A=>A!==k&&A.target===k.target&&A.points.length>1&&Math.abs(A.points.at(-1)[T.cross]-v)<=pn&&!Po(k,A));const m=(k,v,T)=>h(k,v,T)||a.edges.some(A=>{if(A===k||A.target!==k.target||A.source===k.target||Po(k,A))return false;const R=l.get(A.source);return R!==void 0&&Math.abs(R[T.cross]+(T.cross==="y"?R.height:R.width)/2-v)<=pn});function p(k,v,T,A){if(k.points.length<3||!T.edges.some(O=>O!==k&&O.target===k.target))return false;const R=Ft(v);const I=R[Sr(A,-1)];if(!m(k,I[A.cross],A))return false;const L=v[A.cross],$=L+(A.cross==="y"?v.height:v.width);let B=-1;for(let O=k.points.length-1;O>0&&B<0;O--){const N=k.points[O-1],G=k.points[O],Y=G[A.cross];if(Math.abs(N[A.cross]-Y)<=_e&&Math.abs(N[A.main]-G[A.main])>_e&&(Y<=L-Bt||Y>=$+Bt))B=O}if(B<1)return false;const F=k.points[B][A.cross];const z=A.cross==="y"?F<L?"N":"S":F<L?"W":"E";const _=R[z];const H=k.points[B-1];if((_[A.main]-H[A.main])*Math.sign(k.points[B][A.main]-H[A.main])<=_e)return false;const D={...k,points:[],label:void 0};if(Ii(D,F,Math.min(H[A.main],_[A.main]),Math.max(H[A.main],_[A.main]),T,A))return false;const j=dd(A,F,_[A.cross]);if(Ii(D,_[A.main],Math.min(F,_[A.cross]),Math.max(F,_[A.cross]),T,j))return false;const W=pt([...k.points.slice(0,B),Ln(A,_[A.main],F),_]);if(li(W)>li(k.points)||md(W,k,T)||!wr(k,W,T.edges,T.style))return false;if(k.label){let O;for(let G=1;G<W.length;G++){const Y=Math.abs(W[G].x-W[G-1].x)+Math.abs(W[G].y-W[G-1].y);if(!O||Y>Math.abs(O[1].x-O[0].x)+Math.abs(O[1].y-O[0].y))O=[W[G-1],W[G]]}const N=O&&Vi(k,O[0],O[1],T);if(!N)return false;k.labelPosition=N}wi(T,k,W);return true}function g(k,v,T,A,R,I=false,L){if(k.points.length<2)return false;const $=Ko(v,R,1);const B=Ko(T,R,-1);if(!$||!B)return false;const F=k.points.map(ie=>ie[R.cross]);const z=[];const _=[];const H=(ie,oe)=>{if(ie.every(ue=>Math.abs(ue-oe)>.5))ie.push(oe)};if(L?.sourceLane!==void 0){H(z,L.sourceLane)}else{H(z,v[R.cross]+(R.cross==="y"?v.height:v.width)/2);if(!I){H(z,k.points[0][R.cross]);for(const ie of F)H(z,ie)}}if(L?.targetLane!==void 0){H(_,L.targetLane)}else{const ie=T[R.cross]+(R.cross==="y"?T.height:T.width)/2;const oe=A.edges.some(ue=>{if(ue===k||ue.target!==k.target||ue.source===k.target||Po(k,ue))return false;const ye=l.get(ue.source);return ye!==void 0&&Math.abs(ye[R.cross]+(R.cross==="y"?ye.height:ye.width)/2-ie)<=pn});if(oe)H(_,k.points[k.points.length-1][R.cross]);H(_,ie);H(_,k.points[k.points.length-1][R.cross]);if(h(k,ie,R))for(const ue of[va,-va])H(_,ie+ue)}const D=ie=>{const oe=ie[R.main];return[oe,oe+(R.main==="x"?ie.width:ie.height)]};const[j,W]=D(v);const[O,N]=D(T);const G=Math.min(j,W,O,N);const Y=Math.max(j,W,O,N);const q=(ie,oe)=>{if(!oe)return;for(const ue of A.nodes){if(ue.id===k.source||ue.id===k.target)continue;const[ye,Se]=D(ue);if(Se<=G+_e||ye>=Y-_e)continue;const Te=ue[R.cross];const Ie=Te+(R.cross==="y"?ue.height:ue.width);for(const Ee of[Te-Bt-_e,Ie+Bt+_e]){if(Ee>=oe.lo-_e&&Ee<=oe.hi+_e)H(ie,Ee)}}};q(z,L?.sourceLane===void 0?$:null);q(_,L?.targetLane===void 0?B:null);const V=(ie,oe)=>Dr(ie)?{lo:ie[R.cross]+2,hi:ie[R.cross]+(R.cross==="y"?ie.height:ie.width)-2}:oe;const ne=V(v,$);const X=V(T,B);const U=!L?.requireFewerCrossings&&Ul(k,A);let K=null;const Z={...k,points:[],label:void 0};let Q;const se=!vr();let te;const ee=Si(A.style,k,"start"),ae=Si(A.style,k,"end");for(const ie of _){if(ie<X.lo-_e||ie>X.hi+_e)continue;const oe=ro(T,ie,R,-1);if(oe===null)continue;for(let ue=0;ue<z.length;ue++){const ye=z[ue];if(ye<ne.lo-_e||ye>ne.hi+_e)continue;if(Math.abs(ye-ie)<Bt)continue;const Se=ro(v,ye,R,1);if(Se===null)continue;if(L?.requireFewerCrossings&&(Se!==(R.sign===1?W:j)||oe!==(R.sign===1?O:N)))continue;if((oe-Se)*R.sign<=_e)continue;const Te=L?.preferSourceJog?[Se+R.sign*ee,(Se+oe)/2,oe-R.sign*ae]:[oe-R.sign*ae,(Se+oe)/2,Se+R.sign*ee];for(let Ie=0;Ie<Te.length;Ie++){const Ee=Te[Ie];if((Ee-Se)*R.sign<=_e||(oe-Ee)*R.sign<=_e)continue;const ve=Math.abs(Ee-Se)>=Math.abs(oe-Ee);const $e=se?(ue*3+Ie)*2+Number(ve):0;const De=se?te?.[$e]:void 0;let fe;if(De&&Object.is(De.jog,Ee))fe=De.blocked;else{fe=Ii(ve?k:Z,ye,Math.min(Se,Ee),Math.max(Se,Ee),A,R);if(se){if(De){De.jog=Ee;De.blocked=fe}else(te??=[])[$e]={jog:Ee,blocked:fe}}}if(fe)continue;const me=dd(R,ye,ie);if(Ii(Z,Ee,Math.min(ye,ie),Math.max(ye,ie),A,me))continue;if(Ii(ve?Z:k,ie,Math.min(Ee,oe),Math.max(Ee,oe),A,R))continue;const de=[Ln(R,Se,ye),Ln(R,Ee,ye),Ln(R,Ee,ie),Ln(R,oe,ie)];const be=ve?[de[0],de[1]]:[de[2],de[3]];let pe=null;if(k.label){pe=Vi(k,be[0],be[1],A);if(!pe){const ge=ve?Vi(k,de[2],de[3],A):Vi(k,de[0],de[1],A);if(ge&&!Ii(k,ve?ie:ye,Math.min(ve?Ee:Se,ve?oe:Ee),Math.max(ve?Ee:Se,ve?oe:Ee),A,R))pe=ge}if(!pe&&!(U&&!K))continue}if(!wr(k,de,A.edges,A.style))continue;const Re=Number(Boolean(Vn(v,k.points[0])))+Number(Boolean(Vn(T,k.points.at(-1))));const Ne=Number(Boolean(Vn(v,de[0])))+Number(Boolean(Vn(T,de.at(-1))));Q??=U?0:or(k.points,k,A);const J=U?0:or(de,k,A,Q);if(!U&&J>Q)continue;if(L?.requireFewerCrossings&&J>=Q)continue;if(!U&&J>=Q&&ai({...k,points:de},v,T)>=ai(k,v,T)&&(li(de)>li(k.points)||li(de)===li(k.points)&&Ne<Re))continue;if(k.label){if(!pe){if(U&&!K){K={route:de,labelMid:{x:(be[0].x+be[1].x)/2,y:(be[0].y+be[1].y)/2}}}continue}k.labelPosition=pe}wi(A,k,de);return true}}}if(K){wi(A,k,K.route);if(k.label)k.labelPosition=K.labelMid;return true}return false}function y(k,v,T,A,R){if(!Ul(k,A))return false;const I=Ko(v,R,1);const L=Ko(T,R,-1);if(!I||!L)return false;const $={...k,points:[],label:void 0};const B=X=>R.cross==="y"?X.height:X.width;const F=X=>R.main==="x"?X.width:X.height;const z=v[R.cross]+B(v)/2;const _=ro(v,z,R,1);const H=T[R.cross]+B(T)/2;const D=ro(T,H,R,-1);if(_===null||D===null)return false;if(Math.abs(z-I.lo)>_e&&Math.abs(z-I.hi)>_e&&(z<I.lo-_e||z>I.hi+_e))return false;const j=[];for(const X of A.nodes){if(X.id===k.source||X.id===k.target)continue;const U=X[R.main],K=U+F(X);const Z=(U-_)*R.sign>_e||(K-_)*R.sign>_e;const Q=(D-U)*R.sign>_e||(D-K)*R.sign>_e;if(!Z||!Q)continue;const se=R.sign>0?U:K;j.push({mainNear:se,crossLo:X[R.cross],crossHi:X[R.cross]+B(X)})}const W=j.filter(X=>z>X.crossLo-Bt&&z<X.crossHi+Bt);if(W.length===0)return false;const O=W.reduce((X,U)=>(U.mainNear-_)*R.sign<(X-_)*R.sign?U.mainNear:X,W[0].mainNear);if((O-_)*R.sign<=Bt)return false;const N=_+(O-_)/2;const G=[H];if(h(k,H,R))G.push(H+va,H-va);const Y=[];const q=X=>{if(Y.every(U=>Math.abs(U-X)>.5))Y.push(X)};for(const X of j){q(X.crossLo-Bt-_e);q(X.crossHi+Bt+_e)}const V=[...j].sort((X,U)=>X.crossLo-U.crossLo);for(let X=1;X<V.length;X++){const U=V[X-1].crossHi,K=V[X].crossLo;if(K-U>2*Bt)q((U+K)/2)}Y.sort((X,U)=>Math.abs(X-z)-Math.abs(U-z));let ne=null;for(const X of G){if(X<L.lo-_e||X>L.hi+_e)continue;const U=ro(T,X,R,-1);if(U===null)continue;const K=U-R.sign*Si(A.style,k,"end");if((K-N)*R.sign<=_e)continue;for(const Z of Y){if(Math.abs(Z-z)<Bt)continue;if(Ii($,z,Math.min(_,N),Math.max(_,N),A,R))continue;if(Ii($,N,Math.min(z,Z),Math.max(z,Z),A,dd(R,z,Z)))continue;if(Ii($,Z,Math.min(N,K),Math.max(N,K),A,R))continue;if(Ii($,K,Math.min(Z,X),Math.max(Z,X),A,dd(R,Z,X)))continue;if(Ii($,X,Math.min(K,U),Math.max(K,U),A,R))continue;const Q=pt([Ln(R,_,z),Ln(R,N,z),Ln(R,N,Z),Ln(R,K,Z),Ln(R,K,X),Ln(R,U,X)]);if(!wr(k,Q,A.edges,A.style))continue;const se=[Ln(R,N,Z),Ln(R,K,Z)];if(k.label){const te=Vi(k,se[0],se[1],A);if(te){k.labelPosition=te;wi(A,k,Q);return true}if(!ne)ne={route:Q,labelMid:{x:(se[0].x+se[1].x)/2,y:(se[0].y+se[1].y)/2}};continue}wi(A,k,Q);return true}}if(ne){wi(A,k,ne.route);if(k.label)k.labelPosition=ne.labelMid;return true}return false}function w(k,v,T,A,R){if(k.points.length<2)return false;const I=v[R.cross]+(R.cross==="y"?v.height:v.width)/2;const L=T[R.cross];const $=L+(R.cross==="y"?T.height:T.width);let B;if(I<L-_e)B=R.cross==="y"?"N":"W";else if(I>$+_e)B=R.cross==="y"?"S":"E";else return false;const F=Ft(T)[B][R.cross];if(Math.abs(F-I)<IR)return false;const z=Ft(T)[Sr(R,-1)];const _=A.edges.some(N=>N!==k&&N.target===k.target&&N.source!==k.source&&N.points.length>0&&Po(k,N)&&Math.abs(N.points[N.points.length-1].x-z.x)<=pn&&Math.abs(N.points[N.points.length-1].y-z.y)<=pn);if(_)return false;const H=Ft(T)[B][R.main];const D=ro(v,I,R,1);if(D===null)return false;if((H-D)*R.sign<=_e)return false;const j={...k,points:[],label:void 0};if(Ii(k,I,Math.min(D,H),Math.max(D,H),A,R))return false;const W=dd(R,I,F);if(Ii(j,H,Math.min(I,F),Math.max(I,F),A,W))return false;const O=[Ln(R,D,I),Ln(R,H,I),Ln(R,H,F)];if(!wr(k,O,A.edges,A.style))return false;if(!Ul(k,A)&&md(O,k,A))return false;if(k.label){const N=Vi(k,O[0],O[1],A);if(!N)return false;k.labelPosition=N}wi(A,k,O);return true}const S=[];const x=new Set;const M=QR(l,c,a,S,x);const b=[];for(const k of e.edges){const v=n.has(k)?ql(k):void 0;let T=pt(BS(k.points));const A=l.get(k.source),R=l.get(k.target);if(A)T=Ea(T,A,true);if(R)T=Ea(T,R,false);if(wr(k,T,a.edges,a.style))wi(a,k,T);Fa(k,v);const I=k.edgeIndex??-1;const L=o[I]??"primary-forward";const $={edgeIndex:I,routeClass:L,bendCount:li(k.points),invariant:"straight"};if(n.has(k)&&Ia(k)){$.invariant="bundle"}else if(L==="self-loop"){let B;if(r?.preserveSelfLoops){const z=l.get(k.source);const _=(O,N)=>{if(Math.abs(O.x-N.x)<=_e&&Math.abs(O.y-N.y)>_e)return N.y>O.y?"S":"N";if(Math.abs(O.y-N.y)<=_e&&Math.abs(O.x-N.x)>_e)return N.x>O.x?"E":"W";return void 0};const H=k.points[0],D=k.points.at(-1);const j=H&&k.points.find(O=>Math.hypot(O.x-H.x,O.y-H.y)>_e);const W=D&&[...k.points].reverse().find(O=>Math.hypot(O.x-D.x,O.y-D.y)>_e);B=z&&H&&D&&j&&W&&Math.hypot(H.x-D.x,H.y-D.y)>=8&&_(H,j)===_(D,W)?_(H,j):void 0}S.length=0;if(B&&e.edges.some(z=>z!==k&&z.source===z.target&&sf(k.points,z.points)))B=void 0;const F=B??M(k);if(F){x.add(k);$.invariant="self-loop";$.loopSide=F;$.bendCount=li(k.points)}else{$.invariant="explained-detour";if(S.length)$.directLaneBlockedBy=[...S]}}else if(L==="container"){$.invariant="container-attach";const B=rH(k,c,l);if(B){const F=Vl(k,B.source,B.target,a,B.axis).applied;const z=!F&&(u??=Gs(t)&&!vr()&&!e.edges.some(_=>_.label))&&or(k.points,k,a)>0&&g(k,B.source,B.target,a,B.axis,false,{requireFewerCrossings:true});if(F||z){$.bendCount=li(k.points);if(F){$.directLaneClear=true;$.straightened=true}}}}else if(L==="primary-forward"||L==="feedback"){if(k.points.length>2){const B=f(k,$);if(!B.applied||B.upgradeable)b.push({edge:k,cert:$})}else{const B=l.get(k.source);const F=l.get(k.target);const z=!k.label&&k.edgeIndex!==void 0&&e.edges.some(D=>D!==k&&D.source===k.target&&D.target===k.source&&!D.label&&D.edgeIndex!==void 0);const[_,H]=[k.points[0],k.points[k.points.length-1]];if(B&&F&&(ZR(k.points)||!Vn(B,_)||!Vn(F,H)||ai(k,B,F)>0||Ul(k,a)||z)){const D=f(k,$);if(!D.applied||D.upgradeable)b.push({edge:k,cert:$})}}}d.push({edge:k,cert:$})}for(let k=0;k<4&&b.length>0;k++){const v=[];let T=false;for(const A of b){if(A.cert.invariant==="unverified-shape")continue;const R=f(A.edge,A.cert);if(R.mutated)T=true;if(!R.applied||R.upgradeable)v.push(A)}if(!T)break;b.length=0;b.push(...v)}for(const k of e.edges){const v=n.has(k)?ql(k):void 0;const T=l.get(k.source);const A=l.get(k.target);if(T)XS(k,T,true,a);if(A)XS(k,A,false,a);let R=k.points;if(T)R=Ea(R,T,true);if(A)R=Ea(R,A,false);if(wr(k,R,a.edges,a.style))wi(a,k,R);Fa(k,v)}const C=[];const P=yp(e,t,o);const E=(k,v)=>{const T=li(k.points);const A=l.get(k.source);const R=l.get(k.target);const I=P.byEdge.get(k);const L={edgeIndex:v.edgeIndex,routeClass:v.routeClass,bendCount:T,directLaneClear:v.directLaneClear,directLaneBlockedBy:v.directLaneBlockedBy,sourcePort:A&&k.points.length>0?Vn(A,k.points[0]):void 0,targetPort:R&&k.points.length>0?Vn(R,k.points[k.points.length-1]):void 0,sourcePortAssignment:I?.source,targetPortAssignment:I?.target,...v.loopSide!==void 0?{loopSide:v.loopSide}:{}};if(v.invariant==="straight"&&T===0&&k.points.length===2){return{...L,invariant:"straight",...v.straightened?{straightened:true}:{}}}return{...L,invariant:v.invariant==="straight"?"explained-detour":v.invariant}};for(const{edge:k,cert:v}of d){const T=E(k,v);k.routeCertificate=T;C.push(T)}return C}function Qo(e,t,n,i){if(!t){e.routeCertificate=void 0;return}const r={edgeIndex:t.edgeIndex,routeClass:t.routeClass,bendCount:li(e.points),directLaneClear:t.directLaneClear,directLaneBlockedBy:t.directLaneBlockedBy,sourcePort:n&&e.points.length>0?Vn(n,e.points[0]):t.sourcePort,targetPort:i&&e.points.length>0?Vn(i,e.points[e.points.length-1]):t.targetPort,sourcePortAssignment:t.sourcePortAssignment,targetPortAssignment:t.targetPortAssignment,...t.loopSide!==void 0?{loopSide:t.loopSide}:{}};if(e.points.length===2&&li(e.points)===0){e.routeCertificate={...r,invariant:"straight"};return}e.routeCertificate={...r,invariant:t.invariant==="straight"||t.invariant==="bundle"&&!Ia(e)?"explained-detour":t.invariant}}function tv(e,t,n=Ue({})){return nv(e,t,n,false)}function nv(e,t,n,i){const r=[];for(const u of e.edges){if(u.edgeIndex!==void 0&&u.routeCertificate)r[u.edgeIndex]=u.routeCertificate.routeClass}const{axis:o,ctx:s}=WS(e,t,n,r,cf,true);const a=Hs(e.nodes);const l=s.sideUse;const c=[];const d=new Set;for(const u of e.edges){const f=u.routeCertificate;if(!f||cf(u))continue;if(f.routeClass!=="primary-forward"&&f.routeClass!=="feedback")continue;const h=f.routeClass==="feedback"?{...o,sign:o.sign===1?-1:1}:o;const m=pt(u.points);if(m.length<=2)continue;const p=a.get(u.source);const g=a.get(u.target);if(!p||!g)continue;if(!io(p))continue;if(!io(g))continue;if(f.routeClass!=="feedback"&&!rf(m,h))continue;const y=US(u,p,g,s,h);if(y&&XR(u,p,g,y))continue;const w=l.get(`${u.source}:${Sr(h,1)}`)??1;const S=f.routeClass==="primary-forward"&&Dr(p)&&w===1&&Xl(p)>=Xl(g);const x=S?p[h.cross]+(h.cross==="y"?p.height:p.width)/2:void 0;const M=i?u:{...u,points:m.map(C=>({...C}))};const b=Vl(M,p,g,s,h,x,u);if(b.applied){c.push({edge:Ai(u),deviationPx:Math.round(FR(m,h)*10)/10});if(i)d.add(u)}}if(d.size>0){const u=yp(e,t,r);for(const f of d){const h=f.routeCertificate;if(!h||f.points.length!==2||li(f.points)!==0)continue;const m=a.get(f.source);const p=a.get(f.target);const g=u.byEdge.get(f);f.routeCertificate={edgeIndex:h.edgeIndex,routeClass:h.routeClass,invariant:"straight",bendCount:0,directLaneClear:true,sourcePort:m?Vn(m,f.points[0]):void 0,targetPort:p?Vn(p,f.points[1]):void 0,sourcePortAssignment:g?.source,targetPortAssignment:g?.target,straightened:true}}}return c}function rH(e,t,n){const i=c=>{const d=t.get(c);if(d)return{id:c,label:"",shape:"rectangle",x:d.x,y:d.y,width:d.width,height:d.height};const u=n.get(c);if(u&&io(u))return u;return null};const r=i(e.source);const o=i(e.target);if(!r||!o)return null;const s=pt(e.points);if(s.length===2&&JS(s[0],r.x,r.y,r.width,r.height,1)&&JS(s[1],o.x,o.y,o.width,o.height,1)){return null}const a=[{gap:o.y-(r.y+r.height),axis:{main:"y",cross:"x",sign:1}},{gap:r.y-(o.y+o.height),axis:{main:"y",cross:"x",sign:-1}},{gap:o.x-(r.x+r.width),axis:{main:"x",cross:"y",sign:1}},{gap:r.x-(o.x+o.width),axis:{main:"x",cross:"y",sign:-1}}];const l=a.filter(c=>c.gap>_e).sort((c,d)=>d.gap-c.gap)[0];if(!l)return null;return{source:r,target:o,axis:l.axis}}function JS(e,t,n,i,r,o){const s=(Math.abs(e.x-t)<=o||Math.abs(e.x-(t+i))<=o)&&e.y>=n-o&&e.y<=n+r+o;const a=(Math.abs(e.y-n)<=o||Math.abs(e.y-(n+r))<=o)&&e.x>=t-o&&e.x<=t+i+o;return s||a}function QS(e,t=new Map){for(const n of e){t.set(n.id,n);QS(n.children,t)}return t}var oH=Symbol("label-seat-sort-denied");function df(e,t){if(t&&!t(1))return void 0;const n=[];for(let r=1;r<e.points.length;r++){if(t&&!t(2))return void 0;const o=e.points[r-1],s=e.points[r];const a=Math.abs(o.x-s.x)<_e;if(a||Math.abs(o.y-s.y)<_e){if(t&&!t(12))return void 0;n.push({a:o,b:s,vertical:a,len:Math.abs(o.x-s.x)+Math.abs(o.y-s.y),i:r})}}if(t&&!t(n.length*2+1))return void 0;const i=oH;try{n.sort((r,o)=>{if(t&&!t(4))throw i;return o.len-r.len||r.i-o.i})}catch(r){if(r===i)return void 0;throw r}return n}function ff(e,t){t?.();const n=[];const i=11;for(let r=0;r<i;r++){t?.();n.push(e+(1-2*e)*(r/(i-1)))}return n.sort((r,o)=>{t?.();return Math.abs(r-.5)-Math.abs(o-.5)})}function*ZS(e,t,n,i=0,r=false,o=false,s){if(!e)return;for(const a of e){const l=(a.vertical?n:t)/2;if(!r&&a.len<=2*l)continue;const c=r?0:l/a.len;if(s&&!s(160))return;const d=o?[5,4,6,3,7,2,8,1,9,0,10].map(u=>c+(1-2*c)*(u/10)):ff(c);for(const u of d)yield{x:a.a.x+(a.b.x-a.a.x)*u+(a.vertical?i:0),y:a.a.y+(a.b.y-a.a.y)*u+(a.vertical?0:i)}}}function uf(e,t){return Ti(e,t.lineWidth??1)}function Kl(e,t,n){n?.();let i;const r=(a,l)=>l.some(c=>{n?.();const d=c.concurrencyRegion?0:c.headerHeight??c.height;return d>0&&a.x<c.x+c.width&&a.x+a.w>c.x&&a.y<c.y+d&&a.y+a.h>c.y||r(a,c.children)});const o=a=>{const l=vr()?e.edges.flatMap(c=>{n?.();return br(c,t)}):i??=e.edges.flatMap(c=>{n?.();return br(c,t)});for(const c of l){n?.();const d=c.bounds;if(d&&a.x<d.x1&&a.x+a.w>d.x0&&a.y<d.y1&&a.y+a.h>d.y0)return true}return false};const s=(a,l,c)=>{n?.();const d={x:a.x-l,y:a.y-l,w:a.w+2*l,h:a.h+2*l};const u=t.lineWidth??1;const f=ad(c,u,"start")-l,h=ad(c,u,"end")-l;if(e.nodes.some(m=>{n?.();const p=Math.max(0,m.id===c.source?f:0,m.id===c.target?h:0);return d.x<m.x+m.width+p&&d.x+d.w+p>m.x&&d.y<m.y+m.height+p&&d.y+d.h+p>m.y})||r(d,e.groups)||o(d))return void 0;return d};return{overlapsMarker:o,clearPaintRect:s}}function iv(e,t,n){let i;const r=[];for(const o of e.edges){if(!o.label||!o.labelPosition||o.points.length<2)continue;if(!oo(o,e.edges,n))continue;const s=i??=Kl(e,n);const a=uf(o,n);const l=o.labelBlock??vi(qe(o.label,o.labelContent),n);const c=l.width+2*nn,d=l.height+2*nn;const u=df(o);const f=o.labelPosition;let h=false;const m=Math.min(c,d)/2-1;for(const p of[0,m,-m]){if(h)break;for(const g of ZS(u,c,d,p,false,true)){o.labelPosition=g;if(s.clearPaintRect(Bs(g.x,g.y,l),a,o)&&!oo(o,e.edges,n)){h=true;break}}}if(!h){o.labelPosition=f;r.push({edge:o,width:l.width})}}r.sort((o,s)=>o.width-s.width);for(const{edge:o}of r){if(!oo(o,e.edges,n))continue;if(!ev(o,e,t,n,i)){for(let s=0;s<e.edges.length;s++){const a=oo(o,e.edges,n);if(!a||!ev(a,e,t,n,i,o))break}}}}function ev(e,t,n,i,r,o=e){if(!Gs(n)||vr()||e.source===e.target||t.groups.length||e.curve||(i.edgeBendRadius??0)>0||(i.lineWidth??1)>2||e.inlineStyle?.["stroke-width"])return false;const s=e.points,a=s[0],l=s.at(-1),c=s[1],d=s.at(-2);const u=a.y===c.y?"x":"y",f=u==="x"?"y":"x";if(a[f]!==c[f]||l[f]!==d[f])return false;const h=Math.sign(c[u]-a[u]),m=Math.sign(d[u]-l[u]);if(!h||!m)return false;const p=h===m,g=p?u:f,y=p?f:u;const w=(e.label?e:o).labelBlock??vi(qe((e.label?e:o).label,(e.label?e:o).labelContent),i);const S=(g==="x"?w.width:w.height)/2+nn+8;const x=(e.labelPosition??o.labelPosition)[g];const M=(D,j,W)=>{const O=[];for(const N of t.nodes)O.push(N[D]-j-Bt,N[D]+(D==="x"?N.width:N.height)+j+Bt);for(const N of t.edges){if(W)for(const Y of N.points)O.push(Y[D]-j-Bt,Y[D]+j+Bt);const G=N===e&&!W?null:kt(N,i);if(G)O.push((D==="x"?G.x:G.y)-j-8-_e,(D==="x"?G.x+G.w:G.y+G.h)+j+8+_e)}return O};const b=[x-S-Bt,x+S+Bt,...M(g,S,true)];b.sort((D,j)=>Math.abs(D-x)-Math.abs(j-x)||D-j);const C=Ro(t.nodes,t.edges,n.direction,i,t.groups).ctx;C.fixedLabels=true;C.finalLabelClearance=true;const P=Hs(t.nodes),E=P.get(e.source),k=P.get(e.target);if(!E||!k)return false;const v={start:Si(i,e,"start"),end:Si(i,e,"end")};const T={start:Yl(s,true),end:Yl(s,false)};const A=p?f:u;const R=[c[A],d[A],...M(A,0,false)];const I=[];for(const D of t.edges){if(D===e)continue;const j=Aa(D,i);if(!j)return false;I.push(...j)}const L=(i.lineWidth??1)*(e.style==="thick"?2:1)/2+_e;const $=(D,j)=>{const W=D.x===j.x,O=W?"y":"x",N=W?"x":"y";let G=Math.min(D[O],j[O]),Y=Math.max(D[O],j[O]);for(let U=1;U<s.length;U++){const K=s[U-1],Z=s[U];if(K[N]!==D[N]||Z[N]!==D[N])continue;const Q=Math.min(K[O],Z[O]),se=Math.max(K[O],Z[O]);if(Q<=G&&se>=G)G=Math.min(Y,se);if(Q<=Y&&se>=Y)Y=Math.max(G,Q)}if(G>=Y)return true;const q=W?D.x:G,V=W?D.x:Y,ne=W?G:D.y,X=W?Y:D.y;if(I.some(U=>{const K=U.bounds;return q-L<=K.x1&&V+L>=K.x0&&ne-L<=K.y1&&X+L>=K.y0}))return false;return!Ii({...e,label:void 0},D[N],G,Y,C,{main:O,cross:N,sign:D[O]>j[O]?1:-1})};const B=(D,j,W,O,N)=>{let G=v[N];for(const X of I){const U=X.bounds;if(D.x<U.x0-L||D.x>U.x1+L||D.y<U.y0-L||D.y>U.y1+L)continue;const K=u==="x"?W>0?U.x1:U.x0:W>0?U.y1:U.y0;G=Math.max(G,W*(K-D[u])+L+_e)}const Y=Math.min(G,T[N]);const q={...D,[u]:D[u]+W*Y};const V=[...new Set([p?D[f]:q[u],...R])].filter(X=>p||W*(X-D[u])>=Y).sort((X,U)=>Math.abs(X-D[A])-Math.abs(U-D[A])||X-U);const ne=[];for(const X of V){const U={...p?q:D,[A]:X},K={...U,[g]:O};const Z=pt(p?[D,q,U,K]:[D,U,K]);if(t.nodes.some(Q=>Na(Q.id===e.source||Q.id===e.target?Z.slice(1):Z,Q)))continue;if(Z.slice(1).some((Q,se)=>!$(Q,Z[se])))continue;ne.push(Z);if(ne.length===8)break}return ne};const F=or(s,e,C);const z=t.edges.filter(D=>D!==e&&D.style!=="invisible");const _=z.map(D=>jl(s,D.points));let H;e:for(const D of[...new Set(b)].slice(0,128)){if(p&&(h*(D-a[u])<v.start||m*(D-l[u])<v.end))continue;const j=B(a,c,h,D,"start"),W=B(l,d,m,D,"end");for(const O of j)for(const N of W){const G=O.at(-1),Y=N.at(-1);const q=pt([...O,...N.toReversed()]);if(!xp(q)||q[1][f]!==a[f]||q.at(-2)[f]!==l[f]||Math.abs(G[y]-Y[y])<=_e||ai({...e,points:q},E,k))continue;if(t.nodes.some(U=>Na(U.id===e.source?q.slice(1):U.id===e.target?q.slice(0,-1):q,U)))continue;if(q.slice(1).some((U,K)=>!$(U,q[K]))||!wr(e,q,t.edges,i))continue;let V=0;if(z.some((U,K)=>{const Z=jl(q,U.points);V+=Z;return Z>_[K]+2})||H&&V>=H.crossings)continue;const ne={...e,points:q};let X;if(e.label)for(const U of df(ne)){const K=Vi(ne,U.a,U.b,C);if(K&&r.clearPaintRect(Bs(K.x,K.y,w),uf(e,i),e)&&!oo(ne,t.edges,i,K)){X=K;break}}if(e.label&&!X)continue;if(o!==e&&oo(o,[o,ne],i))continue;H={points:q,label:X,crossings:V};if(V<=F)break e}}if(H){const D=e.routeCertificate;e.points=H.points;if(e.label)e.labelPosition=H.label;Qo(e,D,E,k);return true}return false}function Lp(e,t,n){const i=(o,s,a)=>{const l=a.x-s.x,c=a.y-s.y,d=l*l+c*c;if(d===0)return Math.hypot(o.x-s.x,o.y-s.y);const u=Math.max(0,Math.min(1,((o.x-s.x)*l+(o.y-s.y)*c)/d));return Math.hypot(o.x-(s.x+u*l),o.y-(s.y+u*c))};let r;for(const o of e.edges){if(!o.label||!o.labelPosition||o.points.length<2)continue;if(o.source===o.target)continue;const s=o.labelBlock??vi(qe(o.label,o.labelContent),n);const a=s.width+2*nn,l=s.height+2*nn;const c=l/2+4;const d=g=>{let y=Infinity;for(let w=1;w<o.points.length;w++)y=Math.min(y,i(g,o.points[w-1],o.points[w]));return y};if(d(o.labelPosition)<=c)continue;const u=r??=Kl(e,n);const f=uf(o,n);const h=(g,y)=>d({x:g,y})<=c&&!!u.clearPaintRect(Bs(g,y,s),f,o)&&!oo(o,e.edges,n,{x:g,y});const m=df(o);let p=false;for(const g of ZS(m,a,l)){if(h(g.x,g.y)){o.labelPosition=g;p=true;break}}if(!p){let g=o.points[0],y=Infinity;for(const M of m.length?m:[]){const b=M.b.x-M.a.x,C=M.b.y-M.a.y,P=b*b+C*C||1;const E=Math.max(0,Math.min(1,((o.labelPosition.x-M.a.x)*b+(o.labelPosition.y-M.a.y)*C)/P));const k=M.a.x+E*b,v=M.a.y+E*C,T=Math.hypot(o.labelPosition.x-k,o.labelPosition.y-v);if(T<y){y=T;g={x:k,y:v}}}const w=y>_e?(o.labelPosition.x-g.x)/y:0;const S=y>_e?(o.labelPosition.y-g.y)/y:-1;const x=c-1;for(const M of[1,-1]){const b=g.x+w*x*M,C=g.y+S*x*M;if(h(b,C)){o.labelPosition={x:b,y:C};break}}}}}function rv(e,t,n){if(Math.abs(e.x-t.x)<=_e){return e.x>n.x+_e&&e.x<n.x+n.w-_e&&Math.min(Math.max(e.y,t.y),n.y+n.h)-Math.max(Math.min(e.y,t.y),n.y)>_e}if(Math.abs(e.y-t.y)<=_e){return e.y>n.y+_e&&e.y<n.y+n.h-_e&&Math.min(Math.max(e.x,t.x),n.x+n.w)-Math.max(Math.min(e.x,t.x),n.x)>_e}return false}function hf(e,t,n=Ue({}),i){let r=1e6;const o=e.edges.filter(m=>m.label&&m.labelPosition&&m.points.length>=2);if(o.length===0)return;const s=m=>{const p=kt(m,n);const g=uf(m,n);return p&&{x:p.x-g,y:p.y-g,w:p.w+2*g,h:p.h+2*g}};const a=(m,p)=>Math.min(m.x+m.w,p.x+p.w)-Math.max(m.x,p.x)>.5&&Math.min(m.y+m.h,p.y+p.h)-Math.max(m.y,p.y)>.5;const{overlapsMarker:l,clearPaintRect:c}=Kl(e,n);const d=function*(m,p,g=false,y,w=true){if(y&&!y.pay(16))return;const S=m.labelBlock??vi(qe(m.label,m.labelContent),n);const x=S.width+2*nn,M=S.height+2*nn;const b=uf(m,n);const C=(v,T,A)=>{if(y)return y.pay(3)&&y.clear({x:v,y:T});if(i?.preserveRouteClearance&&r<=0)return false;const R=c(Bs(v,T,S),b,m);if(!R)return false;for(const I of p){const L=s(I);if(L&&a(R,L))return false}if(oo(m,e.edges,n,{x:v,y:T}))return false;if(i?.preserveRouteClearance||A)for(const I of e.edges){if(I===m||I.style==="invisible")continue;for(let L=1;L<I.points.length;L++){if(i?.preserveRouteClearance&&--r<0)return false;if(ef(I.points[L-1],I.points[L],R))return false}}return true};const P=y?df(m,y.pay):df(m);if(!P)return;const E=M/2+4;const k=[E-1,-(E-1),(E-1)/2,-(E-1)/2];for(const[v,T]of[[0,false],...k.map(A=>[A,true]),...w?k.map(A=>[A,false]):[]]){for(const A of ZS(P,x,M,v,g,false,y?.pay)){if(i?.preserveRouteClearance&&r<=0)return;if(C(A.x,A.y,T))yield A}}};const u=(m,p,g=true)=>{for(const y of d(m,p,false,void 0,g)){m.labelPosition=y;return true}return false};const f=(m,p)=>{const g=o.filter(y=>y!==m&&y!==p);for(const y of[false,true]){const w=M=>{const b=[];for(const C of d(M,g,y)){b.push(C);if(b.length===64)break}return b};const S=w(m),x=w(p);for(const M of S)for(const b of x){const C=s({...m,labelPosition:M}),P=s({...p,labelPosition:b});if(a(C,P))continue;m.labelPosition=M;p.labelPosition=b;return true}}return false};const h=()=>{if(vr())return;const m=y=>{if(y>r){r=0;return false}r-=y;return true};if(!m(8))return;const p=(y,w)=>{for(const S of e.edges){if(!m(1))return false;if(S===y||S.style==="invisible")continue;for(let x=1;x<S.points.length;x++){if(!m(1))return false;if(ef(S.points[x-1],S.points[x],w))return true}}return false};let g;for(const y of o){if(!m(64+(y.label?.length??0)*12+2*e.edges.length))return;const w=s(y);if(!w||!l(w)&&!p(y,w))continue;if(!m(y.points.length+2))return;if(y.curve||(n.edgeBendRadius??0)!==0||y.points.some((v,T)=>T>0&&v.x!==y.points[T-1].x&&v.y!==y.points[T-1].y))continue;g??=Pp(e.nodes,e.edges,e.groups,n,m);if(!g||!m(8))return;const S=new Set,x=new Map;const M=g;const b=(v,T,A,R)=>{if(!m(8))return void 0;const I=[],L=new Map;const $=B=>{if(v.source===v.target){if(!m(v.points.length+8))return false;const F=kt({...v,labelPosition:B},n);if(!F||v.points.some((z,_)=>_>0&&rv(v.points[_-1],z,F)))return false}return M.clear(v,B,L,R,A)};for(const B of d(v,[],T,{clear:$,pay:m})){if(!m(1))return void 0;I.push(B);if(I.length===64)break}return r>0?I:void 0};let C=false;const P=b(y,true,void 0,S);if(!P)return;for(const v of P){if(!m(3))return;x.set(y,v);if(g.clear(y,v,x)){y.labelPosition=v;C=true;break}}if(C)continue;const E=o.filter(v=>S.has(v)&&!v.curve&&!v.points.some((T,A)=>A>0&&T.x!==v.points[A-1].x&&T.y!==v.points[A-1].y));for(const v of o){if(!m(1))return;if(!E.includes(v))continue;if(!m(v.points.length+6))return;for(const T of[false,true]){const A=b(y,T,v),R=b(v,T,y);if(!A||!R)return;e:for(const I of A)for(const L of R){if(!m(16))return;const $=new Map([[y,I],[v,L]]);if(!g.clear(y,I,$)||!g.clear(v,L,$))continue;y.labelPosition=I;v.labelPosition=L;C=true;break e}if(C)break}if(C)break}if(C||E.length<2)continue;const k=new Set(E);for(const v of[false,true]){const T=b(y,v,k);if(!T)return;e:for(const A of T){if(!m(8+4*E.length))return;const R=new Map([[y,A]]);for(const I of E){const L=b(I,v,y);if(!L)return;const $=L.find(B=>M.clear(I,B,new Map(R).set(I,B)));if(!$)continue e;R.set(I,$)}if(![...R].every(([I,L])=>M.clear(I,L,R)))continue;for(const[I,L]of R)I.labelPosition=L;C=true;break e}if(C)break}}};for(let m=0;m<3;m++){if(i?.preserveRouteClearance&&r<=0)return;let p=0;for(const g of o){const y=s(g);if(!y||!l(y))continue;p++;u(g,o.filter(w=>w!==g),false)}for(let g=0;g<o.length;g++){for(let y=g+1;y<o.length;y++){const w=o[g],S=o[y];const x=s(w),M=s(S);if(!x||!M||!a(x,M))continue;p++;if(!u(S,o.filter(b=>b!==S))&&!u(w,o.filter(b=>b!==w)))f(w,S)}}if(p===0){h();break}if(m===2)h()}}function sH(e,t,n){const i=Hs(e);for(const r of t){const o=r.routeCertificate;let s=false;let a=r.points;for(const l of[true,false]){const c=l?[...a].reverse():a;const[d,u,f]=c.slice(-3);const h=i.get(l?r.source:r.target);if(!h||h.shape!=="rectangle"||h.semanticShape!==void 0&&h.semanticShape!=="rect"||!d||!u||!f||Math.hypot(f.x-u.x,f.y-u.y)>=1)continue;const m=(Math.abs(u.x-h.x)<_e||Math.abs(u.x-h.x-h.width)<_e)&&Math.abs(f.x-u.x)<_e&&Math.abs(d.y-u.y)<_e&&u.y>h.y&&u.y<h.y+h.height&&f.y>h.y&&f.y<h.y+h.height&&(d.x-u.x)*(u.x-h.x-h.width/2)>0;const p=(Math.abs(u.y-h.y)<_e||Math.abs(u.y-h.y-h.height)<_e)&&Math.abs(f.y-u.y)<_e&&Math.abs(d.x-u.x)<_e&&u.x>h.x&&u.x<h.x+h.width&&f.x>h.x&&f.x<h.x+h.width&&(d.y-u.y)*(u.y-h.y-h.height/2)>0;if(!m&&!p)continue;a=l?a.slice(1):a.slice(0,-1);s=true}if(s&&wr(r,a,t,n)){r.points=a;Qo(r,o,i.get(r.source),i.get(r.target))}}}function Ap(e,t,n){let i;for(const r of e.edges){if(r.style==="invisible"||r.points.length<3||!r.hasArrowStart&&!r.hasArrowEnd)continue;const o=Ws(r,n);if(Yl(r.points,true)+1e-7>=o.start&&Yl(r.points,false)+1e-7>=o.end)continue;const s=La(r.points,o);if(!s)continue;i??=Ro(e.nodes,e.edges,t.direction,n,e.groups);const{ctx:a}=i;const l=a.nodes.find(f=>f.id===r.source),c=a.nodes.find(f=>f.id===r.target);const d={...r,points:s};if(ai(d,l,c)||md(s,r,a)||!wr(r,s,e.edges,n))continue;let u=true;for(let f=1;f<s.length&&u;f++){const h=s[f-1],m=s[f],p=cd(h.x===m.x?"TB":"LR");u=!Ii(r,h[p.cross],Math.min(h[p.main],m[p.main]),Math.max(h[p.main],m[p.main]),a,p)}if(!u)continue;r.points=s;Qo(r,r.routeCertificate,l,c)}}function Ip(e,t,n){for(let i=0;i<e.edges.length;i++){if(nv(e,t,n,true).length===0)break}sH(e.nodes,e.edges,n);return e.edges.flatMap(i=>i.routeCertificate?[i.routeCertificate]:[])}function One(e,t,n=Ue({})){const i=[];const r=Hs(e.nodes);const o=QS(e.groups);const s=1;for(const l of e.edges){if(l.points.length<2)continue;const c=l.routeCertificate;const d=Ai(l);if(c&&(c.routeClass==="primary-forward"||c.routeClass==="feedback")){for(let u=1;u<l.points.length;u++){const f=l.points[u-1],h=l.points[u];if(Math.abs(f.x-h.x)>_e&&Math.abs(f.y-h.y)>_e){i.push({code:"ROUTE_UNEXPLAINED_BEND",edge:d});break}}}if(c?.routeClass==="container"&&c.edgeIndex>=0){const u=t.edges[c.edgeIndex];if(u){for(const[f,h]of[[u.source,l.points[0]],[u.target,l.points[l.points.length-1]]]){const m=o.get(f);if(m&&!JS(h,m.x,m.y,m.width,m.height,s)){i.push({code:"ROUTE_CONTAINER_MISANCHOR",edge:d,container:f})}}}}if(c&&c.routeClass!=="container"){for(const[u,f]of[[l.source,l.points[0]],[l.target,l.points[l.points.length-1]]]){const h=r.get(u);if(!h)continue;const m=f.x>=h.x-2&&f.x<=h.x+h.width+2&&f.y>=h.y-2&&f.y<=h.y+h.height+2;if(!m){i.push({code:"ROUTE_STALE_AFTER_NODE_MOVE",edge:d,node:u});continue}const p=od(h,f,s);if(p.policy!=="none"&&!p.onBoundary){i.push({code:"ROUTE_SHAPE_MISANCHOR",edge:d,node:u})}}}for(const u of e.nodes){if(u.id===l.source||u.id===l.target)continue;if(Na(l.points,u))i.push({code:"ROUTE_STALE_AFTER_NODE_MOVE",edge:d,node:u.id})}if(l.label&&l.labelPosition){const u=oo(l,e.edges,n);if(u)i.push({code:"ROUTE_LABEL_ON_SHARED_TRUNK",edge:d,sharedWith:Ai(u)})}}const a=e.edges.filter(l=>l.source===l.target);for(let l=0;l<a.length;l++){const c=a[l];const d=c.routeCertificate;const u=Ai(c);const f=r.get(c.source);if(!d||d.invariant!=="self-loop"||!d.loopSide){i.push({code:"ROUTE_SELF_LOOP_OCCUPANCY",edge:u,kind:"allocation"});continue}if(f&&OS.has(f.shape)){const m=c.points[0];const p=c.points[c.points.length-1];const g=y=>d.loopSide==="N"?Math.abs(y.y-f.y)<=s:d.loopSide==="S"?Math.abs(y.y-(f.y+f.height))<=s:d.loopSide==="W"?Math.abs(y.x-f.x)<=s:Math.abs(y.x-(f.x+f.width))<=s;if(!g(m)||!g(p)||Math.hypot(m.x-p.x,m.y-p.y)<8){i.push({code:"ROUTE_SELF_LOOP_OCCUPANCY",edge:u,kind:"side"})}for(let y=1;y<c.points.length;y++){const w=c.points[y-1],S=c.points[y];const x=Math.abs(w.y-S.y)<=_e&&(Math.abs(w.y-f.y)<=s||Math.abs(w.y-(f.y+f.height))<=s)&&Math.min(Math.max(w.x,S.x),f.x+f.width)-Math.max(Math.min(w.x,S.x),f.x)>_e;const M=Math.abs(w.x-S.x)<=_e&&(Math.abs(w.x-f.x)<=s||Math.abs(w.x-(f.x+f.width))<=s)&&Math.min(Math.max(w.y,S.y),f.y+f.height)-Math.max(Math.min(w.y,S.y),f.y)>_e;if(x||M){i.push({code:"ROUTE_SELF_LOOP_OCCUPANCY",edge:u,kind:"boundary"});break}}}for(let m=l+1;m<a.length;m++){const p=a[m];if(sf(c.points,p.points))i.push({code:"ROUTE_SELF_LOOP_OCCUPANCY",edge:u,conflictWith:Ai(p),kind:"route-route"});const g=kt(c,n);const y=kt(p,n);if(g&&y&&g.x<y.x+y.w&&g.x+g.w>y.x&&g.y<y.y+y.h&&g.y+g.h>y.y){i.push({code:"ROUTE_SELF_LOOP_OCCUPANCY",edge:u,conflictWith:Ai(p),kind:"label-label"})}}const h=kt(c,n);if(h){const m=a.some(p=>p.points.some((g,y)=>y>0&&rv(p.points[y-1],g,h)));if(m)i.push({code:"ROUTE_SELF_LOOP_OCCUPANCY",edge:u,kind:"label-route"})}}return i}var ew=48;function Fp(e,t=ew){return t+(e-1)*(t+40)}var ni={font:"Inter",padding:40,nodeSpacing:28,layerSpacing:ew,mergeEdges:true,thoroughness:3};function vo(e){const t=new Map;const n=[];const i=a=>{let l=t.get(a);if(l===void 0){l=n.length;t.set(a,l);n.push([])}return l};for(const a of e)n[i(a.source)].push(i(a.target));const r=new Uint32Array(n.length);const o=[];let s=0;return(a,l)=>{if(a===l)return true;const c=t.get(a),d=t.get(l);if(c===void 0||d===void 0)return false;if(++s===4294967295){r.fill(0);s=1}o.length=0;o.push(c);r[c]=s;while(o.length){const u=n[o.pop()];for(const f of u){if(f===d)return true;if(r[f]!==s){r[f]=s;o.push(f)}}}return false}}function Np(e){const t=[];for(const n of e){t.push({x:n.x,y:n.y,right:n.x+n.width,bottom:n.y+n.height});t.push(...Np(n.children))}return t}function $p(e){let t=0;for(let n=1;n<e.length;n++){const i=e[n].x-e[n-1].x;const r=e[n].y-e[n-1].y;t+=Math.sqrt(i*i+r*r)}return t}function aH(e,t){if(e.length===0)return{point:{x:0,y:0},segmentIndex:0,pathDistance:0};if(e.length===1)return{point:e[0],segmentIndex:0,pathDistance:0};const n=Math.max(0,Math.min($p(e),t));let i=n;let r=0;for(let o=1;o<e.length;o++){const s=e[o].x-e[o-1].x;const a=e[o].y-e[o-1].y;const l=Math.sqrt(s*s+a*a);if(l===0)continue;if(i<=l){const c=i/l;return{point:{x:e[o-1].x+c*s,y:e[o-1].y+c*a},segmentIndex:o,pathDistance:r+i}}i-=l;r+=l}return{point:e[e.length-1],segmentIndex:e.length-1,pathDistance:r}}function sn(e){return aH(e,$p(e)/2).point}function _t(e){if(e==="LR")return{isHorizontal:true,main:"x",cross:"y",sign:1,sourceSide:"E",targetSide:"W"};if(e==="RL")return{isHorizontal:true,main:"x",cross:"y",sign:-1,sourceSide:"W",targetSide:"E"};if(e==="BT")return{isHorizontal:false,main:"y",cross:"x",sign:-1,sourceSide:"N",targetSide:"S"};return{isHorizontal:false,main:"y",cross:"x",sign:1,sourceSide:"S",targetSide:"N"}}function tw(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function To(e,t){const n=_t(t);return e[n.main]}function sr(e,t){const n=_t(t);return e[n.cross]}function Lo(e,t){return _t(t).isHorizontal?e.height:e.width}function pd(e,t){return _t(t).isHorizontal?e.width:e.height}function Kn(e,t){return sr(e,t)+Lo(e,t)/2}function mf(e,t){return To(e,t)+pd(e,t)/2}function Fi(e,t,n=0){return e.x<t.x+t.width+n&&e.x+e.width+n>t.x&&e.y<t.y+t.height+n&&e.y+e.height+n>t.y}function Jl(e,t){for(const n of e){if(n.id===t)return n;const i=Jl(n.children,t);if(i)return i}return void 0}function ar(e){const t=globalThis.process?.env;const n=t?.[e];return n==="1"||n==="true"}function $a(...e){if(ar("APL_DEBUG"))console.error(...e)}function nw(){return{total:0,labelLabel:0,labelNode:0,labelEdge:0}}function ov(e,t){return Math.min(e.x+e.w,t.x+t.w)-Math.max(e.x,t.x)>Gl&&Math.min(e.y+e.h,t.y+t.h)-Math.max(e.y,t.y)>Gl}function _a(e,t,n){const i=e.edges.flatMap((r,o)=>{if(!r.label)return[];const s=kt(r.labelPosition?r:{...r,labelPosition:sn(r.points)},t);return s?[{edgeIndex:o,rect:s}]:[]});if(i.length===0)return nw();return sv(i,e.nodes.map(r=>({x:r.x,y:r.y,w:r.width,h:r.height})),e.edges.map(r=>({points:r.points,hidden:r.style==="invisible"})),n)}function Une(e){if(e.edges.some(i=>i.label?.text&&!i.label.bounds))return void 0;const t=e.kind==="flowchart"||e.kind==="state"?nn:0;const n=e.edges.flatMap((i,r)=>{const o=i.label?.bounds;return i.label?.text&&o?[{edgeIndex:r,rect:{x:o.x-t,y:o.y-t,w:o.w+2*t,h:o.h+2*t}}]:[]});if(n.length===0)return nw();return sv(n,e.nodes,e.edges.map(i=>({points:i.path.map(([r,o])=>({x:r,y:o})),hidden:i.visibility==="hidden"})))}function sv(e,t,n,i){const r=nw();const o=i?e.filter(a=>i.has(a.edgeIndex)):e;const s=i?[...i].filter(a=>n[a]!==void 0):[];for(let a=0;a<e.length;a++){const l=e[a];const c=!i||i.has(l.edgeIndex);const d=c?e:o;for(let u=c?a+1:0;u<d.length;u++){const f=d[u];if(!c&&f.edgeIndex<=l.edgeIndex)continue;if(ov(l.rect,f.rect))r.labelLabel++}if(c)for(const u of t){if(ov(l.rect,u))r.labelNode++}for(let u=0;u<(c?n.length:s.length);u++){const f=c?u:s[u];const h=n[f];if(f===l.edgeIndex||h.hidden)continue;for(let m=1;m<h.points.length;m++){if(ef(h.points[m-1],h.points[m],l.rect)){r.labelEdge++;break}}}}r.total=r.labelLabel+r.labelNode+r.labelEdge;return r}var lH={edgeThroughNode:"primary",nodeOverlaps:"primary",diagonalSegments:"secondary",unexplainedBends:"secondary",hitches:"secondary",offOutlineEndpoints:"cosmetic",endpointApproaches:"primary",labelOffRoute:"cosmetic"};var av={primary:0,secondary:1,cosmetic:2};function cH(e){return lH[e]??"secondary"}function dv(e,t){const n=i=>Math.abs(i.x-t.x)<=.5&&Math.abs(i.y-t.y)<=.5;if(Object.values(Ft(e)).some(n))return true;if(e.shape==="diamond"&&Object.values(Vo(e)).some(n))return true;return false}function Ni(e,t,n=1.5){const i=od(e,t,n);return i.policy==="none"||i.onBoundary}function dH(e){const{x:t,y:n,width:i,height:r}=e;const o=i*.15;switch(e.shape){case"trapezoid":return[{x:t+o,y:n},{x:t+i-o,y:n},{x:t+i,y:n+r},{x:t,y:n+r}];case"trapezoid-alt":return[{x:t,y:n},{x:t+i,y:n},{x:t+i-o,y:n+r},{x:t+o,y:n+r}];case"lean-r":return[{x:t+o,y:n},{x:t+i,y:n},{x:t+i-o,y:n+r},{x:t,y:n+r}];case"lean-l":return[{x:t,y:n},{x:t+i-o,y:n},{x:t+i,y:n+r},{x:t+o,y:n+r}];default:return[{x:t+12,y:n},{x:t+i,y:n},{x:t+i,y:n+r},{x:t+12,y:n+r},{x:t,y:n+r/2}]}}function $i(e,t,n){const i=n.x+n.width/2;const r=n.y+n.height/2;const o=n.width/2;const s=n.height/2;const a=Math.min(e.x,t.x),l=Math.max(e.x,t.x);const c=Math.min(e.y,t.y),d=Math.max(e.y,t.y);if(n.shape==="cylinder"&&(n.semanticShape===void 0||n.semanticShape==="cyl")&&n.height>14&&l>n.x&&a<n.x+n.width&&d>n.y+7&&c<n.y+n.height-7)return true;const u=(n.shape==="rectangle"||n.shape==="subroutine")&&(n.semanticShape===void 0||n.semanticShape==="rect"||n.semanticShape==="fr-rect"||n.semanticShape==="lin-rect"||n.semanticShape==="div-rect"||n.semanticShape==="win-pane");const f=u?0:.5;const h=l>n.x+f&&a<n.x+n.width-f&&d>n.y+f&&c<n.y+n.height-f;if(!h)return false;const m=2.5;switch(n.shape){case"ellipse":case"circle":case"doublecircle":case"state-start":case"state-end":{const p={x:(e.x-i)/o,y:(e.y-r)/s};const g={x:(t.x-i)/o,y:(t.y-r)/s};return gd({x:0,y:0},p,g)<1-m/Math.min(o,s)}case"stadium":{const p=s;const g={x:i-(o-p),y:r};const y={x:i+(o-p),y:r};return uv(e,t,g,y)<p-m}case"diamond":case"hexagon":case"trapezoid":case"trapezoid-alt":case"lean-r":case"lean-l":case"asymmetric":{const p=n.shape==="diamond"?[{x:i,y:n.y},{x:n.x+n.width,y:r},{x:i,y:n.y+n.height},{x:n.x,y:r}]:n.shape==="hexagon"?(()=>{const w=n.height/4;return[{x:n.x+w,y:n.y},{x:n.x+n.width-w,y:n.y},{x:n.x+n.width,y:r},{x:n.x+n.width-w,y:n.y+n.height},{x:n.x+w,y:n.y+n.height},{x:n.x,y:r}]})():dH(n);const g=Math.max(0,1-m/Math.min(o,s));const y=p.map(w=>({x:i+(w.x-i)*g,y:r+(w.y-r)*g}));return uH(e,t,y)}default:return true}}function uH(e,t,n){const i=o=>{for(let s=0;s<n.length;s++){const a=n[s],l=n[(s+1)%n.length];if((l.x-a.x)*(o.y-a.y)-(l.y-a.y)*(o.x-a.x)<-.5)return false}return true};const r={x:(e.x+t.x)/2,y:(e.y+t.y)/2};if(i(e)||i(t)||i(r))return true;for(let o=0;o<n.length;o++){if(fv(e,t,n[o],n[(o+1)%n.length]))return true}return false}function uv(e,t,n,i){if(fv(e,t,n,i))return 0;return Math.min(gd(e,n,i),gd(t,n,i),gd(n,e,t),gd(i,e,t))}function fv(e,t,n,i){const r=(t.x-e.x)*(i.y-n.y)-(t.y-e.y)*(i.x-n.x);if(Math.abs(r)<1e-9)return false;const o=((n.x-e.x)*(i.y-n.y)-(n.y-e.y)*(i.x-n.x))/r;const s=((n.x-e.x)*(t.y-e.y)-(n.y-e.y)*(t.x-e.x))/r;return o>.001&&o<.999&&s>.001&&s<.999}function Ql(e,t){return Or(e.map(n=>({points:n.points,visible:n.style!=="invisible"})),t)}function Da(e,t){const n=new Map;e.forEach((o,s)=>{if(o.style==="invisible"||o.source===o.target)return;const a=JSON.stringify([o.source,o.target]);const l=n.get(a)??[];l.push({edge:o,index:s});n.set(a,l)});const i=(o,s)=>{for(let a=1;a<o.points.length;a++)for(let l=1;l<s.points.length;l++){const c=o.points[a-1],d=o.points[a],u=s.points[l-1],f=s.points[l];if(Math.abs(c.x-d.x)<=.01&&Math.abs(u.x-f.x)<=.01&&Math.abs(c.x-u.x)<=.5&&Math.min(Math.max(c.y,d.y),Math.max(u.y,f.y))-Math.max(Math.min(c.y,d.y),Math.min(u.y,f.y))>1)return true;if(Math.abs(c.y-d.y)<=.01&&Math.abs(u.y-f.y)<=.01&&Math.abs(c.y-u.y)<=.5&&Math.min(Math.max(c.x,d.x),Math.max(u.x,f.x))-Math.max(Math.min(c.x,d.x),Math.min(u.x,f.x))>1)return true}return false};let r=0;for(const o of n.values())for(let s=0;s<o.length;s++)for(let a=s+1;a<o.length;a++){const l=o[s],c=o[a];if((!t||t.has(l.index)||t.has(c.index))&&i(l.edge,c.edge))r++}return r}function gf(e,t=false){const n=new Map(e.nodes.map(o=>[o.id,o]));let i=0,r=0;for(const o of e.edges){if(t&&o.style==="invisible")continue;for(const[s,a]of[[o.source,o.points[0]],[o.target,o.points.at(-1)]]){const l=n.get(s);if(!l)continue;i++;if(a&&dv(l,a))r++}}return i===0?1:r/i}function gd(e,t,n){const i=n.x-t.x;const r=n.y-t.y;const o=i*i+r*r;if(o===0)return Math.hypot(e.x-t.x,e.y-t.y);const s=Math.max(0,Math.min(1,((e.x-t.x)*i+(e.y-t.y)*r)/o));return Math.hypot(e.x-(t.x+s*i),e.y-(t.y+s*r))}function fH(e,t,n,i,r,o){const s=c=>c.x>=e-n&&c.x<=e+n&&c.y>=t-i&&c.y<=t+i;if(s(r)||s(o))return 0;const a=[{x:e-n,y:t-i},{x:e+n,y:t-i},{x:e+n,y:t+i},{x:e-n,y:t+i}];let l=Infinity;for(let c=0;c<4;c++)l=Math.min(l,uv(a[c],a[(c+1)%4],r,o));return l}function hH(e,t){let n=0;const i=[];for(let a=1;a<t.length;a++){const l=Math.hypot(t[a].x-t[a-1].x,t[a].y-t[a-1].y);i.push(l);n+=l}let r=Infinity,o=0,s=0;for(let a=1;a<t.length;a++){const l=t[a-1],c=t[a],d=c.x-l.x,u=c.y-l.y,f=d*d+u*u;let h=f?((e.x-l.x)*d+(e.y-l.y)*u)/f:0;h=Math.max(0,Math.min(1,h));const m=l.x+h*d,p=l.y+h*u,g=Math.hypot(e.x-m,e.y-p);if(g<r){r=g;o=s+h*i[a-1]}s+=i[a-1]}return n?o/n:.5}function mH(e){if(!e.label||!e.labelPosition||e.points.length<2)return 0;return Math.abs(hH(e.labelPosition,e.points)-.5)}function lv(e,t){return t==="LR"||t==="RL"?e.y+e.height/2:e.x+e.width/2}function pf(e,t){return t==="LR"||t==="RL"?e.x:e.y}function _p(e,t){return t==="LR"||t==="RL"?e.x+e.width:e.y+e.height}function pH(e,t,n){if(n==="LR")return pf(t,n)>_p(e,n);if(n==="RL")return _p(t,n)<pf(e,n);if(n==="BT")return _p(t,n)<pf(e,n);return pf(t,n)>_p(e,n)}function gH(e,t,n=1){if(e.length<2)return false;const i=e.map(r=>pf(r,t));return Math.max(...i)-Math.min(...i)<=n}function cv(e,t){const n=i=>i.some(r=>e.x>=r.x-.5&&e.y>=r.y-.5&&e.x+e.width<=r.x+r.width+.5&&e.y+e.height<=r.y+r.height+.5||n(r.children));return n(t)}var yH=28;function hv(e,t){const n=vo(t.edges);const i=new Map(e.nodes.map(l=>[l.id,l]));const r=new Map;const o=new Map;for(const l of e.edges){const c=i.get(l.source);const d=i.get(l.target);if(!c||!d||!pH(c,d,t.direction))continue;if(!r.has(l.source))r.set(l.source,[]);r.get(l.source).push(d);if(!o.has(l.target))o.set(l.target,[]);o.get(l.target).push(c)}let s=0;const a=(l,c,d)=>{if(!l||c.length<2||c.length>6||!gH(c,t.direction,yH))return;if(!gn.has(l.shape)||cv(l,e.groups))return;const u=h=>d==="in"?gn.has(h.shape):h.shape==="rectangle";if(!c.every(h=>u(h)&&!cv(h,e.groups)))return;if(new Set(c.map(h=>h.id)).size!==c.length)return;for(let h=0;h<c.length;h++)for(let m=0;m<c.length;m++){if(h!==m&&n(c[h].id,c[m].id))return}const f=c.reduce((h,m)=>h+lv(m,t.direction),0)/c.length;s=Math.max(s,Math.abs(lv(l,t.direction)-f))};for(const[l,c]of r)a(i.get(l),c,"out");for(const[l,c]of o)a(i.get(l),c,"in");return s}function mv(e,t,n=Ue({})){return pv(e,t,n,true)}function pv(e,t,n,i){const r=[];const o=new Map(t.nodes.map(S=>[S.id,S]));let s=0;let a=0;let l=0;let c=0;let d=0;let u=0;let f=0;let h=0;let m=0;for(const S of t.edges){const x=`${S.source}->${S.target}`;const M=Math.max(0,S.points.length-2);if(S.style!=="invisible"){const k=ai(S,o.get(S.source),o.get(S.target));if(k){a+=k;r.push({metric:"endpointApproaches",detail:`${x}: ${k} inward or tangent exact endpoint shaft(s)`})}}const b=cf(S);if(S.style!=="invisible"&&!b){u+=M;f=Math.max(f,M)}if(M>0&&S.routeCertificate?.invariant==="straight"){c+=M;r.push({metric:"unexplainedBends",detail:`${x} certified straight with ${M} bends`})}for(let k=1;k<S.points.length;k++){const v=S.points[k-1],T=S.points[k];if(Math.abs(v.x-T.x)>.01&&Math.abs(v.y-T.y)>.01){l++;r.push({metric:"diagonalSegments",detail:`${x} segment ${k}`})}}for(const[k,v,T]of[[S.source,S.points[0],"source"],[S.target,S.points[S.points.length-1],"target"]]){const A=o.get(k);if(!A)continue;if(!v||!Ni(A,v)){s++;r.push({metric:"offOutlineEndpoints",detail:v?`${x} ${T} on ${k}(${A.shape}) at (${v.x.toFixed(1)},${v.y.toFixed(1)})`:`${x} missing ${T} endpoint on ${k}`})}}const C=o.get(S.source);const P=o.get(S.target);const E=(k,v)=>k&&v?dv(k,v):false;if(E(C,S.points[0])||E(P,S.points[S.points.length-1]))h++;if(S.label&&S.labelPosition&&S.points.length>=2){const k=S.labelBlock??Wn(S.label,n,"edge");const v=(k.height+16)/2+4;const T=S.source===S.target;let A=Infinity;for(let R=1;R<S.points.length;R++){A=Math.min(A,T?fH(S.labelPosition.x,S.labelPosition.y,(k.width+16)/2,(k.height+16)/2,S.points[R-1],S.points[R]):gd(S.labelPosition,S.points[R-1],S.points[R]))}if(A>v){d++;r.push({metric:"labelOffRoute",detail:`${x} label ${A.toFixed(1)}px from its route (allowed ${v.toFixed(1)})`})}if(i)m=Math.max(m,mH(S))}}let p=0;for(const S of t.edges){for(const x of t.nodes){if(x.id===S.source||x.id===S.target)continue;for(let M=1;M<S.points.length;M++){if($i(S.points[M-1],S.points[M],x)){p++;r.push({metric:"edgeThroughNode",detail:`${S.source}->${S.target} segment ${M} through ${x.id}`});break}}}}const g=i?Ql(t.edges):0;let y=0;for(let S=0;S<t.nodes.length;S++){for(let x=S+1;x<t.nodes.length;x++){const M=t.nodes[S],b=t.nodes[x];const C=Math.min(M.x+M.width,b.x+b.width)-Math.max(M.x,b.x);const P=Math.min(M.y+M.height,b.y+b.height)-Math.max(M.y,b.y);if(C>.5&&P>.5){y++;r.push({metric:"nodeOverlaps",detail:`${M.id} overlaps ${b.id}`})}}}const w=tv(t,e,n);for(const S of w)r.push({metric:"hitches",detail:`${S.edge} deviates ${S.deviationPx}px with a clear lane`});return{metrics:{edges:t.edges.length,offOutlineEndpoints:s,endpointApproaches:a,diagonalSegments:l,unexplainedBends:c,hitches:w.length,nodeOverlaps:y,labelOffRoute:d,edgeThroughNode:p,labelConflicts:i?_a(t,n).total:0,edgeCrossings:g,totalBends:u,maxBendsPerEdge:f,portEndpointRate:gf(t),portAnchoredEdgeRate:t.edges.length===0?1:h/t.edges.length,peerBarycenterDelta:i?hv(t,e):0,worstLabelOffset:m},violations:r.map(S=>({...S,severity:cH(S.metric)})).sort((S,x)=>av[S.severity]-av[x.severity])}}function gv(e,t,n,i,r=new Set){const o={};for(const s of n){switch(s){case"hard":o.hard=iw(pv(e,t,i,false)).length;break;case"crossings":o.crossings=Ql(t.edges);break;case"portRate":o.portRate=gf(t,true);break;case"symErr":o.symErr=hv(t,e);break;case"parallelOverlaps":o.parallelOverlaps=Da(t.edges);break;case"opposingOverlaps":o.opposingOverlaps=Jo(t.edges);break;case"endpointApproaches":{const a=new Map(t.nodes.map(l=>[l.id,l]));o.endpointApproaches=t.edges.reduce((l,c)=>l+(c.style==="invisible"?0:ai(c,a.get(c.source),a.get(c.target))),0);break}case"bends":o.bends=t.edges.reduce((a,l)=>a+(l.style==="invisible"||(l.routeCertificate?cf(l):r.has(l)&&Ia(l))?0:Math.max(0,l.points.length-2)),0);break;case"straight":o.straight=t.edges.filter(a=>a.style!=="invisible"&&a.points.length===2).length;break}}return o}var xH=["offOutlineEndpoints","endpointApproaches","diagonalSegments","unexplainedBends","hitches","nodeOverlaps","labelOffRoute","edgeThroughNode"];function iw(e){const t=new Set(xH);return e.violations.filter(n=>t.has(n.metric))}var bH=4;var SH=["unreadableTitles","edgeCrossings","labelConflicts","totalBends","nonCanonicalEndpointRate","peerBarycenterDelta","area"];function wH(e,t,n){const i=[];const r=(m,p,g,y)=>{if(!g)return;const w=y==="node"?n.nodeTextTransform:y==="edge"?n.edgeTextTransform:n.groupTextTransform;const S=Rt(p,"formatted",w),x=g.prepared;const M=x.lines.length===S.lines.length&&x.lines.every((b,C)=>b.length===S.lines[C].length&&b.every((P,E)=>{const k=S.lines[C][E];return P.text===k.text&&P.bold===k.bold&&P.italic===k.italic&&P.underline===k.underline&&P.strikethrough===k.strikethrough&&P.sourceStart===k.sourceStart&&P.sourceEnd===k.sourceEnd&&P.clusters?.length===k.clusters?.length&&(P.clusters?.every((v,T)=>{const A=k.clusters[T];return v.text===A.text&&v.sourceStart===A.sourceStart&&v.sourceEnd===A.sourceEnd})??true)}));if(x.source!==S.source||x.display!==S.display||x.transform!==S.transform||x.lineStarts.length!==S.lineStarts.length||x.lineStarts.some((b,C)=>b!==S.lineStarts[C])||!M){i.push(`${m}: changed retained prepared text`)}};const o=new Map,s=new Map;const a=new Map,l=new Map;const c=(m,p="")=>{for(const g of m){o.set(g.id,p);a.set(g.id,g);c(g.children,g.id)}};const d=(m,p="")=>{for(const g of m){if(s.has(g.id))i.push(`group ${g.id}: duplicate identity`);s.set(g.id,p);l.set(g.id,g);d(g.children,g.id)}};c(e.subgraphs);d(t.groups);for(const[m,p]of o)if(s.get(m)!==p)i.push(`group ${m}: missing or changed parent`);for(const m of s.keys())if(!o.has(m))i.push(`group ${m}: unexpected identity`);const u=new Set;const f=new Map(t.nodes.map(m=>[m.id,m]));for(const m of t.nodes){if(u.has(m.id))i.push(`node ${m.id}: duplicate identity`);u.add(m.id);if(!e.nodes.has(m.id))i.push(`node ${m.id}: unexpected identity`);else if(m.label!==e.nodes.get(m.id).label)i.push(`node ${m.id}: changed label`);else{const p=e.nodes.get(m.id);r(`node ${m.id}`,qe(p.label,p.labelContent),m.labelBlock,"node")}}for(const m of e.nodes.keys())if(!u.has(m)&&!s.has(m))i.push(`node ${m}: missing identity`);for(const[m,p]of a){const g=l.get(m);if(!g)continue;if(g.label!==p.label)i.push(`group ${m}: changed label`);r(`group ${m}`,qe(p.label,p.labelContent),g.labelBlock,"group");const y=l.get(o.get(m)??"");if(y&&(g.x<y.x-.5||g.y<y.y-.5||g.x+g.width>y.x+y.width+.5||g.y+g.height>y.y+y.height+.5)){i.push(`group ${m}: outside authored parent ${y.id}`)}for(const w of p.nodeIds){if(a.has(w))continue;const S=f.get(w);if(S&&(S.x<g.x-.5||S.y<g.y-.5||S.x+S.width>g.x+g.width+.5||S.y+S.height>g.y+g.height+.5)){i.push(`member ${w}: outside authored group ${m}`)}}}const h=new Set;for(const[m,p]of t.edges.entries()){const g=p.edgeIndex??m,y=e.edges[g];if(h.has(g))i.push(`edge ${g}: duplicate identity`);h.add(g);if(!y){i.push(`edge ${g}: unexpected identity`);continue}if(y.label!==void 0)r(`edge ${g}`,qe(y.label,y.labelContent),p.labelBlock,"edge");if(p.source!==y.source||p.target!==y.target||(p.id??"")!==(y.id??"")||(p.label??"")!==(y.label??"")||p.style!==y.style||p.hasArrowStart!==y.hasArrowStart||p.hasArrowEnd!==y.hasArrowEnd||(p.startMarker??"arrow")!==(y.startMarker??"arrow")||(p.endMarker??"arrow")!==(y.endMarker??"arrow")){i.push(`edge ${g}: changed endpoints, identity, label, shaft or markers`)}}e.edges.forEach((m,p)=>{if(!h.has(p))i.push(`edge ${p}: missing identity`)});return i}function rw(e,t){const n=new Map;const i=o=>{for(const s of o){n.set(s.id,s);i(s.children)}};i(e.subgraphs);const r=o=>{for(const s of o){s.nodeIds=n.get(s.id).nodeIds.filter(a=>e.nodes.has(a)&&!n.has(a));r(s.children)}};r(t.groups)}function MH(e,t){const n=[];const i=(o,s,a,l)=>{let c=0,d=1;for(const[u,f,h,m]of[[o.x,s.x-o.x,a.x,a.x+a.width],[o.y,s.y-o.y,a.y,a.y+l]]){if(f===0){if(u<=h||u>=m)return false;continue}const p=(h-u)/f,g=(m-u)/f;c=Math.max(c,Math.min(p,g));d=Math.min(d,Math.max(p,g));if(c>=d)return false}return c<d};const r=o=>{if(!o.concurrencyRegion){const s=o.labelBlock??Wn(qe(o.label,o.labelContent),t,"group");const a=o.headerHeight??t.groupHeaderFontSize+16+s.height-s.lineHeight;if(!Number.isFinite(a)||a<0)n.push(`group-header ${o.id}: invalid retained height`);else if(a>0&&o.width>0)for(const l of e.edges){if(l.style==="invisible")continue;for(let c=1;c<l.points.length;c++)if(i(l.points[c-1],l.points[c],o,a)){n.push(`group-header ${o.id}: edge ${l.source}->${l.target} segment ${c} enters reserved band`);break}}}o.children.forEach(r)};e.groups.forEach(r);return n}function yv(e,t){const n=[];const i=s=>s.every(Number.isFinite);if(!i([e.width,e.height])||e.width<0||e.height<0)return["non-finite or negative canvas"];const r=(s,a,l,c,d)=>{if(!i([a,l,c,d])||c<0||d<0)n.push(`${s}: non-finite or negative geometry`);else if(a<-.5||l<-.5||a+c>e.width+.5||l+d>e.height+.5)n.push(`${s}: outside canvas`)};for(const s of e.nodes)r(`node ${s.id}`,s.x,s.y,s.width,s.height);const o=s=>{r(`group ${s.id}`,s.x,s.y,s.width,s.height);s.children.forEach(o)};e.groups.forEach(o);for(const s of e.edges){if(s.style!=="invisible"&&s.points.length<2)n.push(`edge ${s.source}->${s.target}: missing route`);if(s.label&&(!s.labelPosition||!s.labelBlock))n.push(`label ${s.source}->${s.target}: missing retained geometry`);for(const a of s.points)r(`edge ${s.source}->${s.target}`,a.x,a.y,0,0);if(s.label!==void 0&&s.labelPosition&&s.labelBlock){const a=kt(s,t);if(a)r(`label ${s.source}->${s.target}`,a.x,a.y,a.w,a.h)}}for(const s of e.notes??[])r(`note ${s.id}`,s.x,s.y,s.width,s.height);if(e.title?.block){const s=e.title,a=s.block;r("diagram title",s.x-a.width/2,s.y-a.height/2,a.width,a.height)}return n}function ow(e,t){const n=yv(e,t);return n.length?n:MH(e,t)}function kH(e,t,n){return{unreadableTitles:n?1:0,labelConflicts:t.labelConflicts,edgeCrossings:t.edgeCrossings,totalBends:t.totalBends,nonCanonicalEndpointRate:1-t.portEndpointRate,peerBarycenterDelta:Math.round(t.peerBarycenterDelta*1e3)/1e3,area:e.width*e.height}}function sw(e,t,n,i=false){return xv(e,t,n,i)}function xv(e,t,n,i=false,r="final"){try{const o=n.produce();const s=wH(e,o,t);if(i&&s.length)throw new TypeError(`Owned layout changed authored meaning: ${s.join("; ")}`);const a=[...s,...r==="placement"?yv(o,t):ow(o,t)];const l=a.length===0?mv(e,o,t):void 0;if(l)a.push(...iw(l).map(d=>`${d.metric}: ${d.detail}`));const c=a.length===0&&(n.preferNext?.(o)??false);return{attempt:{strategy:n.strategy,violations:a},...a.length===0&&l?{certified:{positioned:o,strategy:n.strategy,score:kH(o,l.metrics,c)}}:{}}}catch(o){if(i||o instanceof Xi||o instanceof Ts||o instanceof Ri)throw o;return{attempt:{strategy:n.strategy,violations:[o instanceof Error?o.message:String(o)]}}}}function bv(e,t){for(const n of SH){if(t.score[n]<e.score[n])return{selected:t,reason:n};if(t.score[n]>e.score[n])return{selected:e,reason:n}}return{selected:e,reason:"candidate-order"}}function Sv(e,t,n,i,r="final"){const o=[];const s=n.slice(0,bH);const a=i?[i,...s]:s;let l;let c;let d=false;const u=[];const f=(h,m)=>({selected:h,reason:m,compared:u,attempts:o.length});for(const[h,m]of a.entries()){if(l&&c==="routing"&&m.qualityAlternative===false)continue;if(d){xl("layout-candidate","candidate-rejected",o.length+1);d=false}const p=xv(e,t,m,false,r);o.push(p.attempt);const g=p.certified;if(g){u.push({strategy:g.strategy,score:g.score});if(l){const w=bv(l,g);return f(w.selected,w.reason)}const y=a.slice(h+1);if(g.score.unreadableTitles&&y.length>0){l=g;c="readability";continue}if(g.score.edgeCrossings===0&&g.score.labelConflicts===0)return f(g,"first-certified");if(!Gs(e))return f(g,"work-budget");if(!y.some(w=>w.qualityAlternative!==false))return f(g,"no-alternative");l=g;c="routing";continue}if(l)return f(l,"alternative-invalid");d=true}if(l)return f(l,"no-alternative");throw new Qe(o)}function aw(e,t){const{selected:n,reason:i,compared:r,attempts:o}=t;rw(e,n.positioned);n.positioned.certification={status:"passed",strategy:n.strategy,attempts:o,hardViolations:0,preference:{selectedScore:n.score,reason:i,compared:r}};return n.positioned}function wv(e,t,n,i){const{selected:r}=Sv(e,t,n,i,"placement");rw(e,r.positioned);const{width:o,height:s,nodes:a,groups:l}=r.positioned;return{width:o,height:s,nodes:a,groups:l}}function Mv(e,t,n,i,r){const o=Sv(e,t,n,r);const s=aw(e,o);const a=i(s,o.selected.score);if(!a)return s;const l={...o.selected,strategy:"bundled"};const c=sw(e,t,a);const d=[{strategy:l.strategy,score:l.score}];if(c.certified)d.push({strategy:c.certified.strategy,score:c.certified.score});const u=c.certified?bv(l,c.certified):{selected:l,reason:"alternative-invalid"};const f=u.selected.positioned;rw(e,f);f.certification={...s.certification,preference:{...s.certification.preference,selectedScore:u.selected.score,routing:{strategy:u.selected===l?"bundled":a.strategy,preference:{selectedScore:u.selected.score,reason:u.reason,compared:d}}}};return f}var kv=new WeakSet;function Cv(e){if(kv.has(e))return;kv.add(e);const t=Yi(e);const n=t.configDiagnostics??[];if(n.length===0)return;const i=t.onConfigDiagnostic??(r=>console.warn(r.message));for(const r of n)i(r)}function Pv(e){if(!Cu.test(e))return e;return Kx(e,({name:t,value:n})=>Xn(t,n))}function lw(e){const t=/<((?:[A-Za-z_][\w.-]*:)?(?:style|text|title|desc|metadata))\b[\s\S]*?<\/\1>/gi;const n=[];const i=s=>s.replace(/>\s*\r?\n\s*</g,"><");let r=0;let o;while((o=t.exec(e))!==null){if(o.index>r)n.push(i(e.slice(r,o.index)));n.push(o[0]);r=o.index+o[0].length}if(r<e.length)n.push(i(e.slice(r)));return n.join("")}function cw(e,t){if(!/^[A-Za-z0-9_.:-]+$/.test(t)){throw new Error("idPrefix must be non-empty and contain only ASCII letters, digits, underscore, hyphen, dot, and colon")}const n=new Set;for(const o of Eu(e)){for(const s of o.attributes){if(s.name==="id")n.add(s.value)}}const i=o=>o.startsWith(t)?o:`${t}${o}`;const r=Kx(e,o=>{if(o.name==="id")return i(o.value);if(o.name==="aria-labelledby"||o.name==="aria-describedby"){return o.value.split(/\s+/).map(s=>n.has(s)?i(s):s).join(" ")}if((o.name==="href"||o.name==="xlink:href")&&o.value.startsWith("#")){const s=o.value.slice(1);return n.has(s)?`#${i(s)}`:o.value}return void 0});return U1(r,o=>o.replace(/url\(#([^)]+)\)/g,(s,a)=>n.has(a)?`url(#${i(a)})`:s))}import{decodeXML as CH}from"entities";function Ev(e,t){return e.match(new RegExp(`\\b${t}\\s*=\\s*(["'])(.*?)\\1`,"i"))?.[2]}function yd(e,t){const n=Ev(e,"style");const i=n?.match(new RegExp(`(?:^|;)\\s*${t}\\s*:\\s*([^;]+)`,"i"))?.[1]?.trim();return i??Ev(e,t)}function Rv(e,t,n){const i=Number.parseFloat(yd(e,t)??"");return Number.isFinite(i)?i:n}function vv(e,t){const n=yd(e,"font-weight")?.trim().toLowerCase();if(n===void 0)return t;if(n==="normal")return 400;if(n==="bold")return 700;if(n==="bolder"){if(t<350)return 400;if(t<550)return 700;return 900}if(n==="lighter"){if(t<550)return 100;if(t<750)return 400;return 700}const i=Number.parseFloat(n);return Number.isFinite(i)?i:t}function PH(e){return/\bclass\s*=\s*(["'])[^"']*\bmono\b/i.test(e)||/(?:^|[,\s])monospace(?:[,\s]|$)/i.test(yd(e,"font-family")??"")}function EH(e,t){let n="";for(let i=t+1;i<e.length;i++){const r=e[i];if(n){if(r===n)n="";continue}if(r==='"'||r==="'"){n=r;continue}if(r===">")return i}return-1}function RH(e){const t=[];const n=[];let i=0;while(i<e.length){const r=e.indexOf("<",i);if(r<0){if(n.length>0&&i<e.length)n[n.length-1].children.push({kind:"text-node",raw:e.slice(i)});i=e.length;break}if(n.length>0&&r>i)n[n.length-1].children.push({kind:"text-node",raw:e.slice(i,r)});if(e.startsWith("<!--",r)){const d=e.indexOf("-->",r+4);if(d<0)return null;i=d+3;continue}const o=EH(e,r);if(o<0)return null;const s=e.slice(r,o+1);if(/^<\?/.test(s)||/^<!/.test(s)){i=o+1;continue}const a=s.match(/^<\/\s*([\w:-]+)\s*>$/);if(a){const d=n.pop();if(!d||d.name!==a[1].toLowerCase())return null;d.closeStart=r;i=o+1;continue}const l=s.match(/^<\s*([\w:-]+)([\s\S]*?)(\/?)>$/);if(!l)return null;const c={kind:"element",name:l[1].toLowerCase(),attrs:l[2],openEnd:o+1,closeStart:o+1,children:[]};if(n.length>0)n[n.length-1].children.push(c);else t.push(c);if(l[3]!=="/")n.push(c);i=o+1}return n.length===0?t:null}function Tv(e){return e.children.filter(t=>t.kind==="element")}function Lv(e,t){const n=t.name==="b"||t.name==="strong";const i=e.mono||PH(t.attrs);return{size:Rv(t.attrs,"font-size",e.size),weight:n?Math.max(700,vv(t.attrs,e.weight)):vv(t.attrs,e.weight),letterSpacing:Rv(t.attrs,"letter-spacing",e.letterSpacing),mono:i,fontFamily:yd(t.attrs,"font-family")??(i&&!e.mono?void 0:e.fontFamily),fontStyle:t.name==="i"||t.name==="em"||yd(t.attrs,"font-style")==="italic"?"italic":yd(t.attrs,"font-style")==="normal"?"normal":e.fontStyle}}function yf(e,t){return new RegExp(`\\b${t}\\s*=`,"i").test(e)}function dw(e){return e.name==="tspan"&&["x","y","dx","dy"].some(t=>yf(e.attrs,t))}function Av(e){return Tv(e).some(t=>dw(t)||Av(t))}function vH(e,t){const n=[];let i=false;const r=(o,s,a)=>{const l=Lv(s,o);if(!a&&dw(o))return;if(!a&&yf(o.attrs,"textLength")){i=true;return}for(const c of o.children){if(c.kind==="text-node"){const d=CH(c.raw);if(d.length>0)n.push({text:d,metrics:l})}else r(c,l,false)}};r(e,t,true);return{runs:n,blocked:i}}function TH(e,t=false){const n=e.filter(s=>s.text.length>0);if(n.length===0||n.every(s=>s.text.trim().length===0))return null;let i=0;let r=0;let o=0;for(const s of n){if(!(s.metrics.size>0))return null;const a=F1(s.text).length;if(r>0&&a>0)i+=o;i+=s.metrics.mono?Xx(s.text,s.metrics.size,s.metrics.letterSpacing,s.metrics.weight,s.metrics.fontStyle,s.metrics.fontFamily):t?Su(s.text,s.metrics.size,s.metrics.weight,s.metrics.fontStyle,s.metrics.fontFamily)+Math.max(0,a-1)*s.metrics.letterSpacing:_1(s.text,s.metrics.size,s.metrics.weight,s.metrics.letterSpacing,s.metrics.fontStyle,s.metrics.fontFamily);r=a;o=s.metrics.letterSpacing}return Math.round(i*1e3)/1e3}function Iv(e,t){const n=RH(e);if(!n)return e;const i=[];const r={size:0,weight:400,letterSpacing:0,mono:false,fontStyle:"normal",fontFamily:t};const o=(a,l,c,d=false)=>{if(yf(a.attrs,"data-prepared-text"))return;const u=Lv(l,a);const f=d||yf(a.attrs,"data-literal-text");const h=a.name==="text"&&!c;const m=h||c&&dw(a);const p=m&&yf(a.attrs,"textLength");if(p)return;if(m&&!(h&&Av(a))){const y=vH(a,l);const w=y.blocked?null:TH(y.runs,f);if(w!==null){i.push({offset:a.openEnd-1,text:` textLength="${w}" lengthAdjust="spacingAndGlyphs" data-font-metrics="deterministic-fit"`})}}const g=c||h;for(const y of Tv(a))o(y,u,g,f)};for(const a of n)o(a,r,false);let s=e;for(const a of i.sort((l,c)=>c.offset-l.offset)){s=s.slice(0,a.offset)+a.text+s.slice(a.offset)}return s}var Fv=new WeakSet;function Nv(e){Fv.add(e)}function $v(e){return Fv.has(e)}var xd=new WeakMap;function gt(e){const t=n=>e(kl,n);xd.set(t,{original:e,current:e});return t}function _v(e,t){const n=xd.get(e)?.current;if(n){const i=xd.get(t);if(i)i.current=n;else xd.set(t,{original:n,current:n})}return t}function Zo(e){return e&&xd.get(e)?.current}function bd(e){return e&&xd.get(e)?.original}var Dv=new WeakMap;var LH=0;var xf=new WeakMap;var Ov=0;var Dp=new WeakMap;var uw=16*1024*1024;var fw=8*1024*1024;var AH=128;var Sd=new wu(128,fw);var bf=new wu(128,uw,e=>{Sd.delete(e)});var hw=new WeakSet;function mw(e,t){let n=Dv.get(e);if(n===void 0){n=LH++;Dv.set(e,n)}return`${n}:${t}`}function Op(e,t=false){const n=structuredClone(e);const i=new WeakSet;const r=(o,s)=>{if(o===null||typeof o!=="object"||s===null||typeof s!=="object")return s;if(t&&lm(o))return o;if(i.has(o))return s;i.add(o);cm(o,s);if(o instanceof Map&&s instanceof Map){const a=s.entries();for(const[l,c]of o){const[d,u]=a.next().value;const f=r(l,d),h=r(c,u);s.delete(d);s.set(f,h)}}else if(o instanceof Set&&s instanceof Set){const a=s.values();for(const l of o){const c=a.next().value;s.delete(c);s.add(r(l,c))}}else for(const a of Object.keys(o))s[a]=r(o[a],s[a]);return s};return r(e,n)}function Bv(e){return hw.has(e)}function Wv(e,t,n=false,i=false){const r=bf.get(mw(e,t));if(!n)jt("positioned-layout",r?"hit":"miss");if(!r)return void 0;const o=Op(r.result,i);zu(r.result,o);return o}function zv(e,t,n){const i=mw(e,t);const r=bf.get(i);jt("positioned-layout",r?"hit":"miss");if(n&&r&&xf.has(r)){const o=Object.freeze({...r.result});zu(r.result,o);Dp.set(o,{key:i,snapshot:r,request:n});hw.add(o);return{...r,result:o}}return r}function Gv(e,t,n,i){jv(e,t,n,i,true)}function Hv(e,t,n,i){jv(e,t,n,i,false)}function jv(e,t,n,i,r){const o={result:n,...i?{projection:i}:{}};const s=t.length*2+Pu([o,Uo(n)],uw)+1024;if(s>uw){jt("positioned-layout","store-skipped","weight-limit");return}let a=o;if(r){try{a=Op(o,true)}catch(l){if(l instanceof Error&&l.name==="DataCloneError"){jt("positioned-layout","store-skipped","uncloneable");return}throw l}zu(n,a.result)}if(!r)xf.set(a,{locallyRepeated:false});bf.set(mw(e,t),a,s);hw.add(a.result)}function Bp(e,t,n){const i=Dp.get(t);if(!n){Dp.delete(t);return void 0}if(!i||i.request!==e||bf.get(i.key)!==i.snapshot)return void 0;const r=++Ov;const o=xf.get(i.snapshot);o.locallyRepeated=o.lastUse===r-1;o.lastUse=r;const s=Sd.get(i.key);return s?.owner===i.snapshot?s.drawing:void 0}function Yv(e,t,n){const i=Dp.get(t);if(!i||i.request!==e||bf.get(i.key)!==i.snapshot)return;const r=xf.get(i.snapshot);if(r.oversized){jt("native-drawing","store-skipped","weight-limit");return}const o=r.drawingWeight??i.key.length*2+n.svg.length*4+1024;const s=Sd.leastRecentlyUsed();const a=s&&xf.get(s.owner)?.lastUse;const l=a!==void 0&&Ov-a>=AH;if(!r.locallyRepeated&&!l&&!Sd.canFit(i.key,o)){jt("native-drawing","store-skipped","drawing-budget");return}const c={owner:i.snapshot,drawing:n};const d=i.key.length*2+Pu(n,fw)+1024;r.drawingWeight=d;if(d>fw){r.oversized=true;jt("native-drawing","store-skipped","weight-limit");return}if(!r.locallyRepeated&&!l&&!Sd.canFit(i.key,d)){jt("native-drawing","store-skipped","drawing-budget");return}Sd.set(i.key,c,d)}var Mi=.5;var IH=new Set(["rectangle","rounded","note","service","diamond","stadium","hexagon","cylinder"]);var FH={journey:"x",sequence:"none",xychart:"center",quadrant:"center"};function NH(e){return e.role?e.role==="box":IH.has(e.shape)}function Ys(e,t,n,i){return Number.isFinite(e)&&Number.isFinite(t)&&Number.isFinite(n)&&Number.isFinite(i)&&n>=0&&i>=0}function qv(e,t){const n=Math.min(e.x+e.w,t.x+t.w)-Math.max(e.x,t.x);const i=Math.min(e.y+e.h,t.y+t.h)-Math.max(e.y,t.y);return n>Mi&&i>Mi}function Wp(e,t,n="both"){const i=n==="center"?t.x+t.w/2>=e.x-Mi&&t.x+t.w/2<=e.x+e.w+Mi:t.x>=e.x-Mi&&t.x+t.w<=e.x+e.w+Mi;const r=n==="x"||(n==="center"?t.y+t.h/2>=e.y-Mi&&t.y+t.h/2<=e.y+e.h+Mi:t.y>=e.y-Mi&&t.y+t.h<=e.y+e.h+Mi);return i&&r}function Xv(e,t,n){let i=t;const r=new Set;while(i?.parentId&&!r.has(i.id)){r.add(i.id);if(i.parentId===e.id)return true;i=n.get(i.parentId)}return false}function Uv(e){return $H(e).violations}function $H(e){const t=[];if(!Ys(0,0,e.bounds.w,e.bounds.h)){t.push({metric:"nonFiniteGeometry",detail:`bounds ${e.bounds.w}\xD7${e.bounds.h}`})}const n=(s,a,l)=>{if(!l)return;if(!Ys(l.x,l.y,l.w,l.h)){t.push({metric:"nonFiniteGeometry",detail:`${s} ${a}`})}else if(l.x<-Mi||l.y<-Mi||l.x+l.w>e.bounds.w+Mi||l.y+l.h>e.bounds.h+Mi){t.push({metric:"offCanvas",detail:s==="node"?`node ${a} at (${l.x},${l.y}) ${l.w}\xD7${l.h}`:`${s} ${a}`})}};for(const s of e.nodes)n("node",s.id,s);for(const s of e.nodes){if(s.labelVisibility!=="hidden"&&s.labelVisibility!=="semantic")n("label",s.id,s.labelBounds)}for(const s of e.edges)n("label",s.id,s.label?.bounds);for(const s of e.labels??[]){if(s.visibility!=="hidden"&&s.visibility!=="semantic")n("label",s.id,s.bounds)}for(const s of e.edges){let a=false;for(const[l,c]of s.path){if(!Number.isFinite(l)||!Number.isFinite(c)){t.push({metric:"nonFiniteGeometry",detail:`edge ${s.id} path`});a=true;break}if(!a&&(l<-Mi||c<-Mi||l>e.bounds.w+Mi||c>e.bounds.h+Mi)){t.push({metric:"offCanvas",detail:`edge ${s.id} point (${l},${c})`});a=true}}}for(const s of e.groups)n("group",s.id,s);const i=e.nodes.filter(NH);for(let s=0;s<i.length;s++){for(let a=s+1;a<i.length;a++){const l=i[s],c=i[a];if(!Ys(l.x,l.y,l.w,l.h)||!Ys(c.x,c.y,c.w,c.h))continue;if(!qv(l,c))continue;t.push({metric:"nodeOverlaps",detail:`${l.id} overlaps ${c.id}`})}}const r=FH[e.kind]??"both";const o=new Map(e.groups.map(s=>[s.id,s]));if(r!=="none"){const s=new Map(e.nodes.map(a=>[a.id,a]));for(const a of e.groups){const l=a.parentId?o.get(a.parentId):void 0;if(l&&Ys(a.x,a.y,a.w,a.h)&&Ys(l.x,l.y,l.w,l.h)){if(!Wp(l,a,r)){t.push({metric:"groupBreaches",detail:`${a.id} outside parent ${l.id}`})}}for(const c of a.members){const d=s.get(c);if(!d||!Ys(d.x,d.y,d.w,d.h))continue;if(!Wp(a,d,r)){t.push({metric:"groupBreaches",detail:`${c} outside ${a.id}`})}}}}for(let s=0;s<e.groups.length;s++){for(let a=s+1;a<e.groups.length;a++){const l=e.groups[s],c=e.groups[a];if(!Ys(l.x,l.y,l.w,l.h)||!Ys(c.x,c.y,c.w,c.h))continue;if(!qv(l,c))continue;if(Wp(l,c)||Wp(c,l))continue;if(Xv(l,c,o)||Xv(c,l,o))continue;t.push({metric:"groupOverlaps",detail:`${l.id} partially overlaps ${c.id}`})}}return{violations:t,groupById:o}}var zp=new WeakMap;var Kv=new WeakMap;var Vv=new WeakSet;function pw(e,t,n){ep(e,{...t,role:n});if(t.requested!=="agentic"||t.selected!=="elk"||Vv.has(e))return;Vv.add(e);const i={code:"INEFFECTIVE_CONFIG",field:"graphLayout.backend",message:`Agentic graph layout declined this input; using the requested ELK fallback: ${t.reason??"candidate rejected"}`};const r=Yi(e).onConfigDiagnostic??(o=>console.warn(o.message));r(i)}function Gp(e){return zp.get(e)}function _H(e){return"positioned"in e?e:{positioned:e}}function Uie(e,t,n=t.source,i={}){return Zv(e,t,n,i,false)}function Jv(e){const t=Yi(e);const n=Zo(t.family.lowerScene);const i=t.mode==="scene"&&TC(t.backend?.backend)&&$v(t.family)&&!t.textMeasurement&&!!n&&n===bd(t.family.lowerScene)&&!da(e);const r=Zv(t.family.id,e,e.source,{},i,true);if(i&&Bv(r))Kv.set(r,n);return r}function Qv(e,t){const n=Kv.get(e);return n&&n!==t?Op(e.positioned,true):e.positioned}function Zv(e,t,n,i,r,o=false){const s=Yi(t);const a=s.family;if(a.id!==e){throw new Error(`Resolved request planned family ${a.id}, not ${e}`)}if(!a.layout)throw new Error(`No layout registered for Mermaid family ${e}`);const l=!e.startsWith("family:");const c=`${e}:final`;if(l&&!a.projectPositioned){throw new Qe([{strategy:c,violations:["missing final geometry projection"]}])}const d=Wl(t);const u=globalThis.process?.env;const f=Dc("position-cache")&&l&&e!=="gantt"&&!s.textMeasurement&&(u?.AGENTIC_MERMAID_ELK_CACHE??globalThis.AGENTIC_MERMAID_ELK_CACHE)!=="0";const h=f&&n===t.source?{...n,cleanup:void 0}:n;const m=f?JSON.stringify([h,t.renderOptions,t.appearance,t.familyConfig,i,e==="class"?d.paintBackendId??"backend:default":void 0,Object.entries(u??{}).filter(([g])=>g.startsWith("APL_")).sort(),D1.map(Dc)]):void 0;const p=m!==void 0&&m.length<=65536?m:void 0;if(p===void 0)jt("positioned-layout","bypass",!Dc("position-cache")?"disabled":!l?"external-family":e==="gantt"?"time-dependent-family":s.textMeasurement?"custom-text-measurement":m===void 0?"elk-cache-disabled":"key-limit");return ml(s.textMeasurement,()=>{const g=t.output==="ascii"||t.output==="unicode"||t.output==="html"?"companion":"primary";if(r&&p!==void 0){const x=zv(a,p,t.output==="svg"?t:void 0);if(x?.projection){for(const M of Uo(x.result))pw(t,M,g);zp.set(x.result,x.projection);return x.result}}const y=p===void 0?void 0:Wv(a,p,r,o);const w=[];const S=y??_H(oE(x=>{w.push(x);pw(t,x,g)},()=>a.layout({source:n,renderOptions:d.renderOptions,...d.styleFace?{styleFace:d.styleFace}:{},...d.paintBackendId?{paintBackendId:d.paintBackendId}:{},...d.familyConfig?{familyConfig:d.familyConfig}:{},...d.familyAppearance?{familyAppearance:d.familyAppearance}:{}})));if(y)for(const x of Uo(y))pw(t,x,g);else for(const x of w)ep(S,x);if(l){try{const x=a.projectPositioned({positioned:S.positioned,options:i});const M=Uv({...x,kind:e});if(M.length)throw new Qe([{strategy:c,violations:M.map(b=>`${b.metric}: ${b.detail}`)}]);zp.set(S,x)}catch(x){if(x instanceof Qe)throw x;throw new Qe([{strategy:c,violations:[x instanceof Error?x.message:String(x)]}])}}if(!y&&p!==void 0){const x=r&&t.output==="svg"&&(e==="sequence"||e==="flowchart"||e==="state")?Hv:Gv;x(a,p,S,zp.get(S))}return S})}var DH="am-";function OH(e){let t=3735928559;let n=1103547991;for(let i=0;i<e.length;i++){const r=e.charCodeAt(i);t=Math.imul(t^r,2654435761);n=Math.imul(n^r,1597334677)}t=Math.imul(t^t>>>16,2246822507);t^=Math.imul(n^n>>>13,3266489909);n=Math.imul(n^n>>>16,2246822507);n^=Math.imul(t^t>>>13,3266489909);return`${(n>>>0).toString(36).padStart(7,"0")}${(t>>>0).toString(36).padStart(7,"0")}`}function BH(e,t){const n=e.match(/^\s*/)[0];const i=e.slice(n.length);if(i.length===0)return e;const r=/^svg(?![\w-])/.exec(i);if(r)return`${n}svg.${t}${i.slice(3)}`;return`${n}.${t} ${i}`}function WH(e){const t=[];let n=0;let i;let r=0;for(let o=0;o<e.length;o++){const s=e[o];if(i){if(s==="\\")o++;else if(s===i)i=void 0}else if(s==='"'||s==="'"){i=s}else if(s==="("||s==="["){n++}else if(s===")"||s==="]"){n--}else if(s===","&&n===0){t.push(e.slice(r,o));r=o+1}}t.push(e.slice(r));return t}var zH=new Set(["media","supports","container","layer","document"]);function eT(e,t){let n="";let i=0;let r=0;let o;let s=0;while(i<e.length){const a=e[i];if(o){if(a==="\\")i++;else if(a===o)o=void 0;i++;continue}if(a==="/"&&e[i+1]==="*"){const l=e.indexOf("*/",i+2);i=l<0?e.length:l+2;continue}if(a==='"'||a==="'"){o=a}else if(a==="("){s++}else if(a===")"){s=Math.max(0,s-1)}else if(a===";"&&s===0){n+=e.slice(r,i+1);r=i+1}else if(a==="{"&&s===0){const l=HH(e,i);const c=e.slice(r,i);const d=e.slice(i+1,l);n+=GH(c,d,t);i=l+1;r=i;continue}i++}return n+e.slice(r)}function GH(e,t,n){const i=e.match(/^(?:\s*\/\*[\s\S]*?\*\/)*/)[0];const r=e.slice(i.length);const o=/^\s*@([\w-]+)/.exec(r);if(o){const a=o[1].toLowerCase();const l=zH.has(a)?eT(t,n):t;return`${e}{${l}}`}const s=WH(r).map(a=>BH(a,n)).join(",");return`${i}${s}{${t}}`}function HH(e,t){let n=0;let i;for(let r=t;r<e.length;r++){const o=e[r];if(i){if(o==="\\")r++;else if(o===i)i=void 0}else if(o==="/"&&e[r+1]==="*"){const s=e.indexOf("*/",r+2);if(s<0)return e.length;r=s+1}else if(o==='"'||o==="'"){i=o}else if(o==="{"){n++}else if(o==="}"){n--;if(n===0)return r}}return e.length}function tT(e){const t=Ru(e);if(!t)return e;const n=X1(e);if(n.length===0)return e;const i=`${DH}${OH(e)}`;let r=e;for(let l=n.length-1;l>=0;l--){const c=n[l];r=`${r.slice(0,c.start)}${eT(r.slice(c.start,c.end),i)}${r.slice(c.end)}`}const o=r.slice(t.start,t.end);const s=bl(t,"class");const a=s?`${o.slice(0,s.valueEnd-t.start)}${s.value?" ":""}${i}${o.slice(s.valueEnd-t.start)}`:`${o.slice(0,-1)} class="${i}">`;return vu(r,t,a)}function jH(e,t,n){const i=BC(e);const r=[];function o(s,a,l){for(let c=0;c<s.length;c++){const d=s[c];const u=`${a}.${c}`;if(d.kind==="group"){r.push(d);let f;let h=1;let m;for(let y=r.length-1;y>=0;y--){const w=r[y];if(w.matrix!==void 0||f!==void 0){f=gl(w.matrix??pl,f??pl)}h=sb(w.opacity,h);if(w.conditional)m=true}const p=OC(l?.ancestors,d.own);const g=d.owner?.id===d.own.id&&d.owner.role===d.own.role?p.at(-1):d.owner;o(d.children,u,{parentMatrix:f,ancestors:p,owner:g,conditional:m,groupOpacity:h});r.pop()}else if(l){const f=!d.conditional&&n(d.node,d.svg);i.leaf(d.node,u,l.parentMatrix,l.ancestors,l.conditional||!f,l.groupOpacity,d.node.owner??l.owner)}else{const f=!d.conditional&&n(d.node,d.svg);i.leaf(d.node,u,void 0,void 0,!f)}}}o(t,"scene");return i.finish()}function nT(e,t,n,i){const r={family:n,width:t.positioned.width,height:t.positioned.height,colors:t.colors,transparent:t.resolved.renderOptions.transparent??false};const o=YC(Ps);if(n.startsWith("family:"))o.uncertain();let s=o.snapshot(r);const a=PC(r);const l=new WeakSet;const c=P=>{if(o.retainFragment())l.add(P);return Object.freeze(P)};const d=P=>{const E=o.leaf(P);const k=a.node(E.node);return c({kind:"leaf",node:E.node,svg:k,conditional:E.conditional,nodeCount:1,depth:0,prepared:P.kind==="document"?!/<\s*text/i.test(k):P.kind!=="text"||P.measurement==="prepared"&&P.block!==void 0})};const u={shape:P=>d(ym(P)),text:P=>d(Jx(P)),connector:P=>d(Wo(P)),documentOpen:(P,E)=>{const k=o.snapshot(P);if(k){s=Object.freeze({family:n,width:k.width,height:k.height,colors:k.colors,transparent:k.transparent});s=o.header(s,E)}else o.uncertain();return d(dC(P,E))},documentContent:(P,E)=>d(oC(P,E)),documentText:P=>d(sC(P)),definitions:(P,E)=>d(aC(P,E)),documentClose:()=>d(lC()),group(P){const E=Object.getOwnPropertyDescriptor(P,"children");if(!E||!("value"in E))o.uncertain();const{children:k,...v}=P;const T=o.parts(k,Pl.maxNodes);const A=[];let R=1,I=0,L=1,$=true;const B=[];for(const W of T){const O=Object.getOwnPropertyDescriptor(W,"node"),N=Object.getOwnPropertyDescriptor(W,"indent");if(!O||!("value"in O)||!N||!("value"in N))o.uncertain();const G=Object.freeze({node:W.node,indent:W.indent});A.push(G);if(!l.has(G.node))o.uncertain();B.push(G.node);R+=G.node.nodeCount;I+=G.node.svg.length;L=Math.max(L,1+G.node.depth);$=$&&G.node.prepared}if(R>Pl.maxNodes)throw new RangeError("Native drawing contains too many emitted nodes");if(I>Pl.maxSerializationBytesPerNode)throw new RangeError("Native group has an oversized SVG serialization");const F=cC({...v,children:[]});a.node(F);a.depth(L);const z=o.snapshot(F);const _=z?o.group(z,F):void 0;const H=z?.identity??{id:F.id,role:F.role};for(const W of B){if(W.kind==="leaf"&&W.node.kind==="shape"&&!W.node.identity)a.enclosure(W.node.id,H)}const D=[F.open];for(const W of A)D.push(Q1(W.node.svg,W.indent));D.push(F.close);const j=D.join(F.join);a.serialization(j);return c({kind:"group",svg:j,children:Object.freeze(B),matrix:_,own:H,owner:z?.owner,conditional:!z||F.visibility==="conditional",opacity:Pn(z?.paint?.opacity),nodeCount:R,depth:L,prepared:!/<\s*text/i.test(F.open+F.close)&&$})},pathArtwork:P=>uC(u,P)};const f=gm(()=>e(u,t));for(const P of["parts","family","width","height","colors","transparent"]){const E=Object.getOwnPropertyDescriptor(f,P);if(!E||!("value"in E))o.uncertain()}const h=o.parts(f.parts,Pl.maxNodes);for(const P of h)if(!l.has(P))o.uncertain();const m=a.finish();if(!m.valid)throw new Sm(m.diagnostics);let p=0,g=-1,y=true;for(const P of h){p+=P.nodeCount;g+=P.svg.length+1;y=y&&P.prepared}if(p>Pl.maxNodes)throw new RangeError("Native drawing contains too many emitted nodes");if(g>Pl.maxFinalSvgBytes)throw new RangeError("Native drawing exceeds the final SVG limit");const w=RC(f,{seed:0,...i?{style:i}:{}});const S=h.map((P,E)=>E===0&&w?`${P.svg}
11
+ ${w}`:P.svg).join("\n");qr(S,"native drawing output");const x=s??Object.freeze({...r,colors:Object.freeze({bg:"none",fg:"none"})});const M=o.snapshot({family:f.family,width:f.width,height:f.height,colors:f.colors,transparent:f.transparent});const b=Object.freeze({...x,family:M?.family??n});if(!M||!o.same({...M,width:Number(Xe(M.width)),height:Number(Xe(M.height))},b))o.uncertain();const C=jH(b,h,o.observe);o.finish(C,b);return Object.freeze({svg:S,header:b,preparedText:y,paint:C})}function iT(e,t,n="scene.parts"){e.forEach((i,r)=>{const o=`${n}[${r}]`;t(i,o);if(i.kind==="group")iT(i.children.map(s=>s.node),t,`${o}.children`)})}function gw(e,t,n=da()){const i=e.id.startsWith("family:");const r=EC(t,i?"external":"internal",n);if(!i&&!n)return r;const o=[];if(i&&r.family!==e.id){o.push({code:"SCENE_DOCUMENT",path:"scene.family",message:`external family "${e.id}" emitted a document owned by "${r.family}"`})}const s=new Set(e.semanticRoles);const a=new Set(e.semanticChannels);const l=new Map(e.scenePrimitiveEvidence.map(c=>[`${c.role}\0${c.primitive}`,c]));iT(r.parts,(c,d)=>{if(!s.has(c.role)){o.push({code:"SCENE_PRIMITIVE_CLAIM",path:`${d}.role`,message:`emitted undeclared role "${c.role}"`});return}for(const u of Object.keys(c.channels??{})){if(!a.has(u)){o.push({code:"SCENE_CHANNEL_CLAIM",path:`${d}.channels.${u}`,message:`emitted undeclared semantic channel "${u}"`})}}for(const u of pC(c)){const f=l.get(`${c.role}\0${u}`);if(!f||f.applicability!=="applicable"||f.realization==="unsupported"){o.push({code:"SCENE_PRIMITIVE_CLAIM",path:d,message:`emitted undeclared ${c.role}/${u} primitive`})}}});if(o.length>0)throw new Sm(Object.freeze(o));return r}var Hp=new WeakMap;var yw=new WeakMap;var YH=256;function xw(e,t){let n=yw.get(t);if(!n){n=new WeakMap;yw.set(t,n)}const i=n.get(e);if(i){jt("positioned-scene","hit");if(da(e)&&!i.crossChecks){gw(Yi(e).family,i.scene,true);i.crossChecks=true}return i.scene}jt("positioned-scene","miss");const r=Yi(e);if(!r.family.lowerScene)throw new Error(`Resolved ${e.output} family has no Scene lowering`);const o=e.output==="png"&&e.appearance.colors.embedFontImport!==false?{...e.appearance.colors,embedFontImport:false}:e.appearance.colors;const s=da(e);const a=()=>r.family.lowerScene({positioned:t.positioned,colors:o,resolved:Wl(e)});const l=ml(r.textMeasurement,()=>gw(r.family,!s&&!r.family.id.startsWith("family:")?gm(a):a(),s));n.set(e,{scene:l,crossChecks:s});return l}function bw(e,t){const n=Yi(e);let i=da(e)?"scene-assertions":n.family.id.startsWith("family:")?"external-family":n.backend&&!vC(n.backend.backend)?"alternate-backend":!(n.mode==="layout"?e.appearance.inferredBackend==="default":n.mode==="scene"&&n.backend?.inputName==="default")?"unsupported-mode":void 0;if(!i&&n.family.id==="er"&&(Gp(t)?.nodes.length??0)>YH)i="paint-proof-capacity";let r=i?void 0:Zo(n.family.lowerScene);if(!r)i??="no-native-producer";if(i){jt("native-drawing","bypass",i);xl("native-drawing",i);return void 0}let o=Hp.get(t);if(!o){o=new WeakMap;Hp.set(t,o)}const s=o.get(e);if(s){jt("native-drawing","hit");if(s.producer===Zo(n.family.lowerScene))return s.drawing;jt("native-drawing","bypass","changed-producer");o.delete(e)}if(n.backend)LC(n.backend.conformance,n.backend.inputName);r=Zo(n.family.lowerScene);const a=Bp(e,t,r===bd(n.family.lowerScene));if(a){jt("native-drawing","hit",void 0,"positioned-owner");const u=r;if(u&&u===Zo(n.family.lowerScene)&&u===bd(n.family.lowerScene)){o.set(e,{drawing:a,producer:u,certification:a.certification});return a}jt("native-drawing","bypass","changed-producer");Bp(e,t,false);r=Zo(n.family.lowerScene)}jt("native-drawing","miss");r=Zo(n.family.lowerScene);if(!r){jt("native-drawing","bypass","no-native-producer");xl("native-drawing","no-native-producer");return void 0}const l=r;const c=e.output==="png"&&e.appearance.colors.embedFontImport!==false?{...e.appearance.colors,embedFontImport:false}:e.appearance.colors;const d=ml(n.textMeasurement,()=>nT(l,{positioned:Qv(t,l),colors:c,resolved:Wl(e)},n.family.id,e.appearance.styled?e.appearance.style:void 0));o.set(e,{drawing:d,producer:l,evidence:d});return d}function rT(e,t){const n=Hp.get(t)?.get(e);const i=n?.drawing??bw(e,t);if(i){const l=Hp.get(t).get(e);jt("paint-certification",l.certification?"hit":"miss",void 0,"native");if(l.certification)return l.certification;const c=l.evidence;const d=db(c.header,c.paint,Gp(t),{outputSupported:!e.appearance.colors.shadow});l.certification=d;const u=Object.freeze({svg:i.svg,preparedText:i.preparedText,certification:d});const f=Yi(e).family.lowerScene;if(l.producer===Zo(f)&&l.producer===bd(f))Yv(e,t,u);else{jt("native-drawing","store-skipped","changed-producer");Bp(e,t,false)}return d}const r=xw(e,t);const o=yw.get(t).get(e);jt("paint-certification",o.certification?"hit":"miss",void 0,"scene");if(o.certification)return o.certification;const s=Yi(e);const a=!e.appearance.colors.shadow&&(s.mode==="layout"?e.appearance.inferredBackend==="default":s.mode==="scene"&&s.backend?.inputName==="default");return o.certification=nP(r,Gp(t),{outputSupported:a})}function qH(e){qr(e,"graphical projection digest input");return id(JSON.stringify(e))}function XH(e,t){const n=e.appearance.colors;const i=e.output==="png"&&n.embedFontImport!==false?{...n,embedFontImport:false}:n;return{positioned:t.positioned,colors:i,resolved:Wl(e)}}function UH(e,t){const n=Yi(e);if(n.mode!=="scene")throw new Error(`Resolved ${e.output} request has no Scene execution plan`);return xw(e,t)}function Sw(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function VH(e,t,n,i){const r=`${n}svg-title`;const o=`${n}svg-desc`;const s=[];const a=[];if(t.title){s.push(`aria-labelledby="${r}"`);a.push(`<title id="${r}">${Sw(t.title)}</title>`)}if(t.descr){s.push(`aria-describedby="${o}"`);a.push(`<desc id="${o}">${Sw(t.descr)}</desc>`)}if(a.length===0&&!i)return e;const l=Ru(e);if(!l)return e;if(bl(l,"aria-labelledby")||bl(l,"aria-describedby"))return e;if(i&&!t.title&&!bl(l,"aria-label"))s.push(`aria-label="${Sw(i).replace(/"/g,"&quot;")}"`);const c=`${bl(l,"role")?"":' role="img"'} ${s.join(" ")}`;const d=e.slice(l.start,l.end);return vu(e,l,`${d.slice(0,-1)}${c}>${a.join("")}`)}function KH(e,t){const n=Ru(e);if(!n)throw new Error("Cannot certify a graphical output with no SVG root");const i=e.slice(n.start,n.end);const r=i.replace(/\sviewBox="[^"]*"/g,"");const o=` viewBox="${t.x} ${t.y} ${t.width} ${t.height}"`;return vu(e,n,r.slice(0,-1)+o+">")}function JH(e,t,n,i){return ml(Yi(e).textMeasurement,()=>QH(e,t,n,i))}function QH(e,t,n,i){const r=Yi(e);if(r.mode!=="scene"&&r.mode!=="family-svg"||!r.executionDecision){throw new Error(`Resolved ${e.output} request has no graphical execution plan`)}const o=e.renderOptions;const s=r.family;const a=XH(e,t);let l;let c=false;let d;if(r.mode==="scene"){const y=i?void 0:ei("drawing",()=>bw(e,t));const w=y?void 0:ei("scene",()=>UH(e,t));d=ei("paint-certification",()=>rT(e,t));if(o.layoutSafety==="strict"&&d.status!=="passed"||d.status==="failed"&&r.backend?.inputName==="default")throw new Pm(d);l=y?.svg??ei("backend",()=>{const S={seed:o.seed??0,...e.appearance.styled?{style:e.appearance.style}:{}};i?.begin(S,w);return r.backend.backend.render(w,S)});c=r.backend?.inputName==="default"&&!s.id.startsWith("family:")&&(y?.preparedText??eC(w))}else{if(o.layoutSafety==="strict")throw new $r("Strict layout safety requires native Scene evidence");l=ei("backend",()=>s.renderSvg(a))}qr(l,"backend/family SVG output");let u=V1(l,a.colors);if(d?.repairs.length&&r.backend?.inputName==="default")u=KH(u,d.viewport);qr(u,"color-resolved SVG output");if(!c)u=Iv(u,e.appearance.font);qr(u,"font-geometry-fitted SVG output");const f=o.idPrefix??"";if(f){u=cw(u,f);qr(u,"namespaced SVG output")}const h=e.source.accessibility;const m=s.id==="c4"?"C4 architecture diagram":void 0;if((t.injectAccessibility??true)&&(h.title||h.descr||m)){u=VH(u,h,f,m);qr(u,"accessibility-projected SVG output")}if(i)u=i.finish(u);u=tT(Pv(u));qr(u,"style-scoped SVG output");if(o.compact){u=lw(u);qr(u,"compacted SVG output")}const p=e.output==="png"?"strict":o.security;const g=ei("svg-security",()=>mC(u,p));n.push(...g.diagnostics);u=g.svg;qr(u,"final SVG output");return Object.freeze({svg:u,executionDecision:r.executionDecision,...d?{layoutCertification:d}:{}})}function ZH(e,t){return JH(e,ei("layout",()=>Jv(e)),t)}function Hre(e,t,n,i,r={}){return q1(()=>e4(e,t,n,i,r))}function e4(e,t,n,i,r){const o=ei("request",()=>vS(e,t,n,i,r));return t4(o)}function t4(e){Cv(e);const t=[];const n=ZH(e,t);return n4(e,n,t)}function n4(e,t,n){const i=Object.hasOwn(t,"layoutCertification")?t.layoutCertification:void 0;return i4(t.svg,()=>{const r=qH(t.svg);return Object.freeze({...dR(e,n),graphicalProjectionDigest:r,executionDecision:t.executionDecision,...i?{layoutCertification:Object.freeze({...i,outputDigest:r})}:{}})})}function i4(e,t){let n=t;let i;return Object.freeze({svg:e,get receipt(){if(i===void 0){i=n();n=void 0}return i}})}var Xre=["padding","sectionWidth","ticketBaseUrl","useMaxWidth"];function Sf(e={}){const t=Sn(e,["kanban"])??{};return{padding:typeof t.padding==="number"&&Number.isFinite(t.padding)&&t.padding>=0?t.padding:8,sectionWidth:typeof t.sectionWidth==="number"&&Number.isFinite(t.sectionWidth)&&t.sectionWidth>0?t.sectionWidth:240,ticketBaseUrl:typeof t.ticketBaseUrl==="string"?t.ticketBaseUrl:""}}function jp(e,t){if(!e||!t)return void 0;const n=e.replaceAll("#TICKET#",encodeURIComponent(t));return/^(?:https?:|mailto:|\/|#)/i.test(n)&&ks(n)&&!/[\u0000-\u0020\u007f-\u009f]/.test(n)?n:void 0}var an=(e,t)=>({expected:e,valid:t});var Jt=an("a finite positive number",e=>typeof e==="number"&&Number.isFinite(e)&&e>0);var Yt=an("a finite non-negative number",e=>typeof e==="number"&&Number.isFinite(e)&&e>=0);var Yp=an("a finite number",e=>typeof e==="number"&&Number.isFinite(e));var lt=an("a boolean",e=>typeof e==="boolean");var Br=an("a string",e=>typeof e==="string");var wd=an("a non-empty string",e=>typeof e==="string"&&e.trim().length>0);var oT=an("a CSS font-family list without url(), @import or other functions besides var()",e=>xo(e)!==void 0);var wf=an("a non-empty array of strings",e=>Array.isArray(e)&&e.length>0&&e.every(t=>typeof t==="string"));var qs=(...e)=>an(`one of: ${e.join(", ")}`,t=>typeof t==="string"&&e.includes(t));var qp=(...e)=>an(`one of: ${e.join(", ")} (case-insensitive)`,t=>typeof t==="string"&&e.some(n=>n.toLowerCase()===t.toLowerCase()));var wn=(e,t,n=true)=>an(`a finite number ${n?"from":"greater than"} ${e} through ${t}`,i=>typeof i==="number"&&Number.isFinite(i)&&(n?i>=e:i>e)&&i<=t);var es=e=>an(`a finite positive number no greater than ${e}`,t=>typeof t==="number"&&Number.isFinite(t)&&t>0&&t<=e);var Zl=e=>an(`a finite non-negative number no greater than ${e}`,t=>typeof t==="number"&&Number.isFinite(t)&&t>=0&&t<=e);var sT=an("a finite positive number or non-empty CSS size string",e=>typeof e==="number"&&Number.isFinite(e)&&e>0||typeof e==="string"&&e.trim().length>0);var Oa=(e,t=false)=>an(`a numeric value${t?` greater than ${e}`:` of at least ${e}`}`,n=>{const i=typeof n==="number"?n:typeof n==="string"&&/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:px)?$/i.test(n.trim())?Number.parseFloat(n):Number.NaN;return Number.isFinite(i)&&(t?i>e:i>=e)});var r4=new Map([["person","person"],["box","rectangle"],["rectangle","rectangle"],["cylinder","database"],["database","database"],["db","database"],["queue","queue"],["pipe","queue"]]);function ww(e){return e===void 0?void 0:r4.get(e.trim().toLowerCase())}function Ao(e){return ww(e.style.shape)??e.shape}var Wr=(e,t,n=0)=>{if(e===void 0)return t;if(typeof e!=="number"||!Number.isFinite(e)||e<n||e>1e4)throw new RangeError(`Invalid C4 numeric configuration ${JSON.stringify(e)}; expected a finite number from ${n} to 10000`);return e};var aT=(e,t)=>{const n=Wr(e,t,1);if(!Number.isSafeInteger(n))throw new RangeError(`Invalid C4 row count ${JSON.stringify(e)}; expected a positive integer`);return n};function Xp(e={},t={}){e=Object.fromEntries(Object.entries(e).filter(([i,r])=>Mw[i]?.valid(r)??true));const n=e.compact===true;return{compact:n,typeLegend:e.typeLegend!==false,...e.maxWidth===void 0?{}:{maxWidth:Wr(e.maxWidth,1e4,1)},marginX:Wr(e.diagramMarginX,n?16:24),marginY:Wr(e.diagramMarginY,n?16:24),gap:Wr(e.c4ShapeMargin,n?32:56),padding:Wr(e.c4ShapePadding,n?10:16,4),minimumWidth:Wr(e.width,n?120:150,24),minimumHeight:Wr(e.height,n?60:76,24),boundaryPadding:Wr(e.boxMargin,n?16:24,12),rowGap:Wr(e.nextLinePaddingX,n?36:56),shapesPerRow:aT(e.c4ShapeInRow,3),boundariesPerRow:aT(e.c4BoundaryInRow,2),...e.wrap===false?{}:{wrapWidth:Wr(e.wrapPadding,n?220:260,40)},input:e,themeVariables:t}}function o4(e){if(!("external"in e))return e.kind==="deployment"?"node":"boundary";return`${e.external?"external_":""}${e.kind}${e.shape==="database"?"_db":e.shape==="queue"?"_queue":""}`}function Xs(e,t){const n=o4(e),{input:i,themeVariables:r}=t;const o=(l,c)=>{if(l===void 0)return void 0;const d=mn(l,c!=="color");if(d===void 0)throw new Du(`C4 ${e.id}`,c,String(l),`UpdateElementStyle(${e.id})`);return d};const s=i[`${n}FontSize`],a=i[`${n}FontWeight`];return{fill:o(e.style.bgColor??i[`${n}_bg_color`]??r[`${n}_bg_color`],"fill"),stroke:o(e.style.borderColor??i[`${n}_border_color`]??r[`${n}_border_color`],"stroke"),text:o(e.style.fontColor??e.style.textColor,"color"),...s===void 0?{}:{fontSize:Wr(s,13,1)},...a===void 0?{}:{fontWeight:Wr(typeof a==="string"&&/^\d+$/.test(a)?Number(a):a,500,1)},dashed:e.style.lineStyle===void 0?"external"in e&&e.external:e.style.lineStyle==="dashed"||e.style.lineStyle==="dotted"}}var lT=["person","external_person",...["system","container","component"].flatMap(e=>["","external_"].flatMap(t=>["","_db","_queue"].map(n=>`${t}${e}${n}`))),"boundary","node"];var s4=Object.freeze(["diagramMarginX","diagramMarginY","c4ShapeMargin","c4ShapePadding","width","height","boxMargin","nextLinePaddingX","c4ShapeInRow","c4BoundaryInRow","wrap","wrapPadding","maxWidth","compact","typeLegend",...lT.flatMap(e=>[`${e}FontSize`,`${e}FontWeight`,`${e}_bg_color`,`${e}_border_color`])]);var eoe=Object.freeze(["useMaxWidth",...[...lT,"message"].flatMap(e=>[`${e}Font`,`${e}FontFamily`]),"messageFontSize","messageFontWeight"]);var a4=Object.freeze({maxWidth:1,diagramMarginX:0,diagramMarginY:0,c4ShapeMargin:0,c4ShapePadding:4,width:24,height:24,boxMargin:12,nextLinePaddingX:0,c4ShapeInRow:1,c4BoundaryInRow:1,wrapPadding:40});var Mw=(()=>{const e=Object.assign(Object.create(null),{wrap:lt,compact:lt,typeLegend:lt});for(const[t,n]of Object.entries(a4)){const i=wn(n,1e4);e[t]=t==="c4ShapeInRow"||t==="c4BoundaryInRow"?an("an integer from 1 through 10000",r=>Number.isSafeInteger(r)&&i.valid(r)):i}for(const t of s4){if(/FontSize$/.test(t))e[t]=wn(1,1e4);if(/FontWeight$/.test(t)){const n=wn(1,1e3);e[t]=an(n.expected,i=>n.valid(typeof i==="string"&&/^\d+$/.test(i)?Number(i):i))}}return Object.freeze(e)})();function Cw(e){if(!/#\w+;/.test(e))return{text:e,restore:f=>f,sourceOffset:f=>f};const t=new Map;const n=f=>{const h=f.codePointAt(0);if(h>=57344&&h<=63743)t.set(f,(t.get(f)??0)+1)};for(const f of e)n(f);for(const f of e.matchAll(/\\(?:u([\da-fA-F]{4})|U([\da-fA-F]{8}))/g)){const h=Number.parseInt(f[1]??f[2],16);if(h<=1114111)n(String.fromCodePoint(h))}let i="\uE000";let r=t.get(i)??0;for(let f=57345;r>0&&f<=63743;f++){const h=String.fromCodePoint(f),m=t.get(h)??0;if(m<r){i=h;r=m}}let o=e.length;const s=/#\w+;/g;while(s.test(e))o+=2*r;Ve("sourceCharacters",e.length+o);const a=i.repeat(r+1);const l=new RegExp(`${a}(\\w+)${a}`,"g");const c=[];let d=0;const u=e.replace(/#\w+;/g,(f,h)=>{const m=`${a}${f.slice(1,-1)}${a}`,p=h+d;c.push({start:p,end:p+m.length,sourceStart:h,sourceEnd:h+f.length});d+=m.length-f.length;return m});return{text:u,restore:f=>f.replace(l,(h,m)=>`#${m};`),sourceOffset:f=>{let h=0,m=c.length;while(h<m){const g=h+m>>>1;if(c[g].start<=f)h=g+1;else m=g}const p=c[h-1];return p?f<p.end?p.sourceStart:f-p.end+p.sourceEnd:f}}}function l4(e,t){const n=Cw(e);const i=n.text;const r=$s(i.includes("\n")?`${i}
12
+ `:`{
13
+ ${i}
14
+ }`);if(!r.ok)return r;const o=r.value;if(t==="flowchart"&&(o===null||o===void 0)){return{ok:false,message:"empty @{} metadata document"}}const s=new Map;if(o&&typeof o==="object"&&!Array.isArray(o)){try{for(const[a,l]of Object.entries(kw(o,n.restore)))s.set(a,l)}catch(a){return{ok:false,message:a instanceof Error?a.message:String(a)}}}return{ok:true,entries:s}}function kw(e,t){if(typeof e==="string")return t(e);if(Array.isArray(e))return e.map(n=>kw(n,t));if(e&&typeof e==="object"){const n=new Set;return Object.fromEntries(Object.entries(e).map(([i,r])=>{const o=t(i);if(n.has(o))throw new Error(`duplicate metadata key ${JSON.stringify(o)}`);n.add(o);return[o,kw(r,t)]}))}return e}function ec(e,t,n){const i=wa(e,t,n);if(i.kind==="unclosed")return{ok:false,unclosed:true,message:"unclosed @{ metadata block"};if(i.kind==="invalid")return{ok:false,unclosed:false,message:i.message};const r=l4(i.body,n);return r.ok?{ok:true,end:i.end,entries:r.entries}:{ok:false,unclosed:false,message:r.message}}function Mf(e){return e?String(e):void 0}function ooe(e){let t='"';const n=e.includes("%%{");for(const i of e){const r=i.codePointAt(0);if(i==="\\")t+="\\\\";else if(i==='"')t+="\\x22";else if(r<32||r>=127&&r<=159||n&&i==="%")t+=`\\x${r.toString(16).padStart(2,"0")}`;else if(r===8232||r===8233)t+=`\\u${r.toString(16)}`;else t+=i}return`${t}"`}import{decodeXML as dT}from"entities";import{decodeHTML as c4,decodeHTMLStrict as d4}from"entities/decode";var cT=class extends Error{loadHtmlEntityTable;constructor(t,n){super(`${t} needs the HTML entity table, which has not loaded`);this.loadHtmlEntityTable=n}};function Up(e){return c4(e)}function Pw(e){const t=`&${e};`;return d4(t)!==t}var u4=/&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 Ew(e){return e.startsWith("#")||Nu.has(e)||Pw(e)}function f4(e){if(!e.includes("&"))return e;return e.replace(u4,(t,n,i)=>{if(n!==void 0){if(!Ew(n))return`&${n};`;return`#38;${n.replace("#","#35;")}#59;`}if(!i.startsWith("#")&&!Nu.has(i))return Pw(i)?`#${i};`:t;const r=dT(t);return r==="#"?"#35;":r===";"?"#59;":r})}function uT(e,t){const n=e.originalText;if(!n.includes("&"))return e;const i=f4(n);return i===(t==="decoded"?dT(n):n)?e:Xu(i)}var h4=new TextDecoder("windows-1252");var fT={subject:"Mermaid entity",example:"#35;"};function so(e,t=fT){return e.replace(vl,(n,i,r)=>{let o;if(i!==void 0){const s=Number(i);o=s===0||s>1114111||s>=55296&&s<=57343?"\uFFFD":s>=128&&s<=159?h4.decode(Uint8Array.of(s)):String.fromCodePoint(s)}else{o=Nu.get(r)??Up(`&${r};`)}if(bo.test(o)){throw Je({what:`${t.subject} projects a terminal control character`,expectedForm:"an entity that displays printable text",example:t.example})}return o})}function rn(e,t=fT){return so(Dn(e),t)}var Rw={subject:"Sequence text entity",example:"A->>B: #35;"};var m4=new RegExp(`#\\w+;|${vl.source}`,"g");function ts(e){const t=e.trim();const n=/^:?(wrap|nowrap):/.exec(t);return n?{text:t.slice(n[0].length).trim(),wrap:n[1]==="wrap"}:{text:t}}function koe(e,t,n,i){const r=n===void 0?"":n?"wrap: ":"nowrap: ";let o=x4(e,t,i+r);if(!r&&/^:?(?:no)?wrap:/.test(o))o=`#${o.charCodeAt(0)};${o.slice(1)}`;return r+o}function p4(e){const t=rn(e,Rw);if(t===e)return{value:t};const n=ur(Rt(yt(e)),m4,i=>rn(i,Rw));return{value:t,content:Object.freeze({value:t,authored:e,prepared:n})}}function Ba(e){const t=p4(e);const n=rn(yt(e),Rw);return{label:n,...t.content?{labelContent:Object.freeze({...t.content,value:n})}:{}}}function g4(e){return e.replace(/\r\n|[\r\n]/g,"<br/>")}function y4(e){return dn(e,"#;")}function x4(e,t,n=""){let i;if(t?.value===e&&t.authored!==void 0){i=gr(t.authored,"#;")}else if(t?.value===e){i=O1(t.prepared,r=>dn(r,"#;*~_<").replace(/\\(?=n)/g,"#92;"),"<br/>")}else{i=y4(e)}i=i.replace(/&(?=#\d+;|#[xX][0-9a-fA-F]+;|([a-zA-Z][a-zA-Z\d]{0,31});)/g,(r,o)=>o===void 0||Ew(o)?"#38;":r);i=g4(i).replace(/^ +| +$/g,r=>"#32;".repeat(r.length));i=i.replace(/%%/g,"%#37;");return Un(n+i)===n+i?i:i.replace(/:/g,"#58;")}var b4=/^(loop|alt|opt|par_over|par|critical|break|rect|box)\b\s*([\s\S]*)$/i;var S4=/^(else|and|option)\b\s*([\s\S]*)$/i;function hT(e){const t=b4.exec(e);if(!t)return null;const n=t[1].toLowerCase();const i=t[2]?.trim()??"";if(n==="box")return{type:n,label:i};const r=ts(i);return{type:n,label:r.text,...r.wrap===void 0?{}:{wrap:r.wrap}}}function mT(e){const t=S4.exec(e);if(!t)return null;const n=ts(t[2]??"");return{type:t[1].toLowerCase(),label:n.text,...n.wrap===void 0?{}:{wrap:n.wrap}}}function pT(e,t){return e==="else"&&t==="alt"||e==="and"&&(t==="par"||t==="par_over")||e==="option"&&t==="critical"}function vw(e){const t=e.toLowerCase();if(t==="transparent"||t in rm)return true;if(!/^(?:#|(?:rgb|rgba|hsl|hsla)\()/i.test(e))return false;return Kt(e)!==null}function gT(e){const t=Sl(e);if(!t)return void 0;const n=t.toLowerCase();if(n==="transparent"||Object.hasOwn(rm,n))return t;const 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(o=>Number(o)<=255))return t;const r=/^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(r&&r.slice(1,4).every(o=>Number(o)<=255))return t;return void 0}function Tw(e){const t=rm[e.toLowerCase()];if(t)return t;const n=fl(e);if(n)return Yn(n[0],n[1],n[2]);const i=e.match(/^rgba?\(\s*(\d{1,3})\s*[, ]\s*(\d{1,3})\s*[, ]\s*(\d{1,3})/i);if(i)return Yn(Math.min(255,Number.parseInt(i[1],10)),Math.min(255,Number.parseInt(i[2],10)),Math.min(255,Number.parseInt(i[3],10)));return null}var Vp=class{constructor(t={}){this.options=t}options;records=new Map;order=[];boxes=[];currentBox;apply(t){if(t.kind==="links"){const n=this.records.get(t.id);if(n)n.links={...n.links,...t.links};return}this.addActor(t.id,t.kind==="declare"?t:void 0)}applyAll(t){for(const n of t)this.apply(n)}openBox(t){this.boxes.push(t);this.currentBox=this.boxes.length-1}closeBox(){this.currentBox=void 0}has(t){return this.records.has(t)}indexOf(t){return this.order.indexOf(t)}list(){return this.order.map(t=>this.records.get(t))}addActor(t,n){const i=this.records.get(t);let r=this.currentBox;if(i){if(r!==void 0&&i.box!==void 0&&r!==i.box){this.options.onBoxConflict?.(t)}r=i.box??r;if(r!==void 0)i.box=r;if(n?.label===void 0||n.create)return}const o={id:t,label:n?.label??t,...n?.wrap===void 0?{}:{wrap:n.wrap},type:n?.type??"participant",...n?{keyword:n.keyword}:{},...i?.links&&!this.options.upstreamLinks?{links:i.links}:{},...r!==void 0?{box:r}:{}};this.records.set(t,o);if(!i)this.order.push(t);if(this.currentBox!==void 0&&r===this.currentBox)this.boxes[this.currentBox].actorIds.push(t)}};var kf=new Map([["<<-->>",["filled","filled"]],["<<->>",["filled","filled"]],["-->>",["none","filled"]],["->>",["none","filled"]],["-->",["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"]]]);var Lw=new Set(["--|","-|","--/","-/","--\\","-\\","|--","|-","/--","/-","\\--","\\-"]);var w4=new Map([...Lw].map(e=>{const[t,n]=kf.get(e);const i=[...kf].find(([r,o])=>!Lw.has(r)&&o[0]===t&&o[1]===n&&r.includes("--")===e.includes("--"))[0];return[e,i]}));var xT=[...kf.keys()].sort((e,t)=>t.length-e.length);var bT=xT.map(e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|");var M4=new RegExp(String.raw`^(\S+?)(\(\))?\s*(${bT})`);var k4=new RegExp(String.raw`^(\S+?)\s+(\(\))\s*(${bT})`);var Kp=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"]);var C4=new Set([...Kp,"acctitle","accdescr"]);var Jp=/(?:#\w+;|[^\/\\\+\()\+<\->\->:\n,;])+((?!(\-x|\-\-x|\-\)|\-\-\)|\-\|\\|\-\\|\-\/|\-\/\/|\-\|\/|\/\|\-|\\\|\-|\/\/\-|\\\\\-|\/\|\-|\-\-\|\\|\-\-|\(\)))[\-]*(?:#\w+;|[^\+<\->\->:\n,;])+)*/iy;function Aw(e,t){Jp.lastIndex=t;return Jp.exec(e)?.[0].trim()??""}function P4(e){Jp.lastIndex=0;const t=Jp.exec(e);if(!t)return void 0;let n=t[0].length;const i=e.startsWith("()",n);const r=i&&/\s$/.test(t[0]);if(i)n+=2;while(n<e.length&&/\s/.test(e[n]))n++;const o=xT.find(s=>e.startsWith(s,n));if(!o)return void 0;n+=o.length;return{from:t[0].trim(),arrow:o,end:n,centralStart:i,spacedCentral:r}}function ST(e,t){if(!e||e.trim()!==e||/[\r\n]/.test(e))return false;const n=Dn(e);if(n.startsWith("#"))return false;if(t==="declaration")return $w(e)&&!/:/.test(n)&&!n.includes("%%{");if(n.startsWith("%")||n.includes("%%"))return false;const i=n.toLowerCase();const r=/^(\w+)\b/.exec(i)?.[1];if(r&&Kp.has(r)&&(!["title","link","links","properties","details"].includes(r)||/\s/.test(i.slice(r.length,r.length+1))))return false;if(/^(?:\d+(?:\.\d{1,2})?|\.\d{1,2})(?=\s)/.test(n))return false;if(Kp.has(i)&&!["title","link","links","properties","details"].includes(i))return false;if(t==="receiver"&&["acctitle","accdescr"].includes(i))return false;if(/^(?:left|right) of\b/.test(i))return false;return Aw(`${n}${t==="sender"?"->>Z:":":"}`,0)===n}var Fw=new WeakMap;var Nw=new WeakMap;function wT(e){return Nw.get(e)}function MT(e){return Fw.get(e)}function kT(e,t){Fw.set(e,t)}function CT(e,t){Nw.set(e,t)}function E4(e){let t=P4(e);if(!t){const w=e.match(M4);const S=w??e.match(k4);if(S)t={from:S[1],centralStart:Boolean(S[2]),arrow:S[3],end:S[0].length,spacedCentral:!w}}if(!t||!F4(t.arrow))return null;const{from:n,arrow:i,centralStart:r,spacedCentral:o}=t;if(o&&(/^(?:[0-9]+(?:\.[0-9]{1,2})?|\.[0-9]{1,2})$/.test(n)||Kp.has(n.toLowerCase())))return null;let s=e.slice(t.end).trimStart();const a=s.startsWith("()");if(a)s=s.slice(2).trimStart();const l=s[0]==="+"||s[0]==="-"?s[0]:void 0;if(o&&l)return null;if(l)s=s.slice(1).trimStart();const c=s.indexOf(":");if(c<1)return null;const d=s.slice(0,c).trimEnd();const{text:u,wrap:f}=ts(s.slice(c+1));if(!d)return null;if(o&&(/[+<>]/.test(d)||d.includes("()")||C4.has(d.toLowerCase())))return null;const h=Dn(e);const m=Dn(n),p=Dn(d);const g=Dn(e.slice(0,e.length-s.length)).length;const y=Aw(h,0);if(y.length<=m.length&&(y!==m||Aw(h,g)!==p))return null;return{from:n,arrow:w4.get(i)??i,activationMark:l,to:d,label:u,centralStart:r,centralEnd:a,...f===void 0?{}:{wrap:f},...Lw.has(i)?{localArrow:i}:{}}}function PT(e,t={}){const n=Qb(e);const i=zt(n.map(S=>S.raw));const r=i.familyLines.flatMap((S,x)=>S.trim()?[{text:S.trim(),origin:n[i.familyOrigins[x]].line}]:[]);e=r.map(S=>S.text);const o=S=>{const x=r[S]?.origin??S;return t.authoredLine?.(x)??x+1};if(re("sequence")&&e[0]!==void 0)Ge("sequence","header",e[0],{line:1,unit:"normalized"});const s={actors:[],messages:[],blocks:[],notes:[],activationEvents:[],boxes:[],...i.accessibility.title!==void 0?{accessibilityTitle:yt(i.accessibility.title)}:{},...i.accessibility.descr!==void 0?{accessibilityDescription:yt(i.accessibility.descr)}:{}};const a=new Vp;const l=new Map;const c=new Map;const d=R4(e.slice(1));const u=d.issues.find(S=>S.syntax==="sequence_block_boundary");if(u)throw new Error(`SEQUENCE_BLOCK_BOUNDARY: line ${o(u.line+1)}: ${u.message}`);const f=new Map;const h=[];const m=new Map;const p={visible:t.showSequenceNumbers===true,next:1,step:1};const g=[];const y=[];const w=S=>{const{from:x,to:M}=S;const b=N4(S.arrow);const C={from:x,to:M,...Ba(S.label.trim()),...(S.wrap??t.wrap)===void 0?{}:{wrap:S.wrap??t.wrap},lineStyle:b.lineStyle,startHead:b.startHead,endHead:b.endHead,centralStart:S.centralStart,centralEnd:S.centralEnd};if(S.activationMark==="+")C.activate=true;if(S.activationMark==="-")C.deactivate=true;if(p.visible)C.number=p.next;p.next=Math.round((p.next+p.step)*100)/100;yT(g,P=>P===M,P=>{l.set(P,s.messages.length);if(re("sequence"))he("sequence","bind-create",{id:P,messageIndex:s.messages.length})});yT(y,P=>P===x||P===M,P=>{c.set(P,s.messages.length);if(re("sequence"))he("sequence","bind-destroy",{id:P,messageIndex:s.messages.length})});s.messages.push(C);if(re("sequence"))he("sequence","add-message",C)};for(const[S,x]of d.statements.entries()){const M=x.raw.trim();if(re("sequence"))Ge("sequence",x.syntax?.kind??"unrecognized",x.raw,{line:x.line+2,column:x.column+1,unit:"normalized"});if(x.error)throw x.error;const b=x.syntax;if(!b){if(i.unclosedIndex!==void 0&&M===i.familyLines[i.unclosedIndex]?.trim())continue;if(M&&!Hu(M))throw new Error(`SEQUENCE_UNSUPPORTED_STATEMENT: line ${o(x.line+1)}: ${M}`);continue}for(const C of vT(b)){a.apply(C);if(re("sequence"))he("sequence","participant.apply",C)}switch(b.kind){case"declaration":case"create":{if(b.kind==="create")g.push(b.declaration.id);break}case"links":case"actor-data":break;case"title":{const C=Ba(b.text);s.title=C.label;s.titleContent=C.labelContent;if(re("sequence"))he("sequence","set-title",s.title);break}case"autonumber":p.visible=b.numbering!==null;if(b.numbering?.next!==void 0){p.next=b.numbering.next;p.step=b.numbering.step??1}if(re("sequence"))he("sequence","set-autonumber",p);break;case"box":{const C=b.text;const P={actorIds:[]};const E=C.match(/^((?:rgb|rgba|hsl|hsla)\([^)]*\))\s*(.*)$/i);let k=C;if(E&&vw(E[1])){P.color=E[1];k=E[2]?.trim()??""}else{const v=C.split(/\s+/,1)[0]??"";if(v&&vw(v)){P.color=v;k=C.slice(v.length).trim()}}if(k){const v=ts(k);Object.assign(P,Ba(v.text));if((v.wrap??t.wrap)!==void 0)P.wrap=v.wrap??t.wrap}s.boxes.push(P);a.openBox(P);if(re("sequence"))he("sequence","open-box",{index:s.boxes.length-1,box:P});break}case"destroy":y.push(b.actorId);if(re("sequence"))he("sequence","pending-destroy",b.actorId);break;case"note":{const{note:C}=b;const P=Ba(C.text);const E=s.notes.length;s.notes.push({actorIds:C.actorIds,text:P.label,...(C.wrap??t.wrap)===void 0?{}:{wrap:C.wrap??t.wrap},...P.labelContent?{textContent:P.labelContent}:{},position:C.position,afterIndex:s.messages.length-1});if(re("sequence"))he("sequence","add-note",{note:s.notes.at(-1),parent:x.parent});for(let k=x.parent;k!==void 0;k=f.get(k)?.parent){f.get(k)?.noteIndices.push(E)}break}case"block":{const{opener:C}=b;const P=C.type;const E=Ba(C.type==="rect"?"":C.label);const k=C.type==="rect"&&C.label.startsWith("#")?"":C.label;const v=C.type==="rect"?gT(k):void 0;if(C.type==="rect"&&k&&!v){throw new Error("SEQUENCE_RECT_COLOR_UNSUPPORTED: rect requires a safe concrete CSS color")}f.set(S,{type:P,...E,...(C.wrap??t.wrap)===void 0?{}:{wrap:C.wrap??t.wrap},...v?{color:v}:{},startIndex:s.messages.length,dividers:[],dividerNoteIndices:[],parent:x.parent,parentSection:x.parent===void 0?0:f.get(x.parent)?.dividers.length??0,noteIndices:[],childBlockIndices:[],childSectionIndices:[]});h.push({kind:"open",blockId:S,messageIndex:s.messages.length,noteIndex:s.notes.length});if(re("sequence"))he("sequence","open-block",{id:S,block:f.get(S)});break}case"continuation":{const C=x.parent!==void 0?f.get(x.parent):void 0;if(C){h.push({kind:"divider",blockId:x.parent,messageIndex:s.messages.length,noteIndex:s.notes.length,dividerIndex:C.dividers.length});C.dividerNoteIndices.push(s.notes.length);C.dividers.push({index:s.messages.length,...Ba(b.continuation.label),...(b.continuation.wrap??t.wrap)===void 0?{}:{wrap:b.continuation.wrap??t.wrap}});if(re("sequence"))he("sequence","divide-block",{parent:x.parent,divider:C.dividers.at(-1),type:b.continuation.type})}break}case"end":{const C=f.get(x.closes);if(C){const P=s.blocks.length;m.set(x.closes,P);h.push({kind:"close",blockId:x.closes,messageIndex:s.messages.length,noteIndex:s.notes.length});const E={type:C.type,label:C.label,...C.wrap===void 0?{}:{wrap:C.wrap},...C.labelContent?{labelContent:C.labelContent}:{},...C.color?{color:C.color}:{},startIndex:C.startIndex,endIndex:Math.max(s.messages.length-1,C.startIndex),dividers:C.dividers};Fw.set(E,{endMessageExclusive:s.messages.length,endNoteExclusive:s.notes.length,dividerNoteIndices:C.dividerNoteIndices,noteIndices:C.noteIndices,childBlockIndices:C.childBlockIndices,childSectionIndices:C.childSectionIndices});if(C.parent!==void 0){f.get(C.parent)?.childBlockIndices.push(P);f.get(C.parent)?.childSectionIndices.push(C.parentSection)}s.blocks.push(E);if(re("sequence"))he("sequence","close-block",{id:x.closes,parent:C.parent,parentSection:C.parentSection,block:E,notes:C.noteIndices,children:C.childBlockIndices})}else{a.closeBox();if(re("sequence"))he("sequence","close-box",null)}break}case"message":w(b.message);break;case"activation":s.activationEvents.push({actorId:b.actorId,kind:b.activate?"activate":"deactivate",messageIndex:s.messages.length});if(re("sequence"))he("sequence","activation",s.activationEvents.at(-1));break}}s.actors=a.list().map(({id:S,label:x,type:M,links:b,box:C,wrap:P})=>({id:S,...Ba(x),type:M,...(P??t.wrap)===void 0?{}:{wrap:P??t.wrap},...b?{links:b}:{},...C!==void 0?{box:C}:{},...l.has(S)?{createMessageIndex:l.get(S)}:{},...c.has(S)?{destroyMessageIndex:c.get(S)}:{}}));Nw.set(s,h.map(({blockId:S,...x})=>({...x,blockIndex:m.get(S)})));return s}function ET(e){let t;return n=>{if(!t){const i=e.originalText.split(/\r?\n/);const r=e.wrapperSource?e.wrapperSource.split(/\r?\n/).length-1:0;const o=i.slice(r).flatMap((a,l)=>(l===0?El(a).split("\n"):[a]).map(c=>({text:c.trim(),line:r+l+1})));let s=0;t=e.familyLines.map(a=>{const l=a.trim();for(let c=s;c<o.length;c++){const d=o[c].text;if(d!==l&&d.slice(d.indexOf("}")+1).trim()!==l)continue;s=c+1;return o[c].line}return void 0})}return t[n]}}function R4(e){const t=Qb(e).map(o=>{if(!o.raw.trim()||Hu(o.raw))return{...o,syntax:null};try{return{...o,syntax:RT(o.raw.trim())}}catch(s){if(s instanceof Ri)throw s;return{...o,syntax:null,error:s}}});const n=[];const i=[];const r=(o,s,a)=>{i.push({line:o.line,syntax:s,message:a})};for(const[o,s]of t.entries()){const{syntax:a}=s;if(n.length)s.parent=n.at(-1);if(!a){if(s.error instanceof Qp)r(s,"sequence_participant_id",s.error.message);else if(s.raw.trim()&&!Hu(s.raw))r(s,"sequence_statement",`Sequence statement is preserved in source but not drawn: ${s.raw.trim()}`);continue}if(a.kind==="block"||a.kind==="box"){n.push(o)}else if(a.kind==="end"){const l=n.pop();if(l===void 0)r(s,"sequence_block_boundary","Sequence end has no open block or box");else{s.closes=l;t[l].endIndex=o}}else if(a.kind==="continuation"){const l=s.parent!==void 0?t[s.parent].syntax:null;if(l?.kind!=="block"||!pT(a.continuation.type,l.opener.type)){r(s,"sequence_block_boundary",`Sequence ${a.continuation.type} does not belong to the enclosing block`)}}else if(a.kind==="declaration"&&a.declaration.unmodeledMetadata?.length){r(s,"sequence_participant_metadata",`Participant metadata fields ${a.declaration.unmodeledMetadata.join(", ")} are not modeled; the declaration is preserved as source`)}else if(a.kind==="message"&&a.message.localArrow){const{localArrow:l,arrow:c}=a.message;r(s,"sequence_local_arrow",`The arrow ${l} is a local spelling pinned Mermaid does not read, so it rejects this line. Ours draws it as Mermaid's ${c} and writes ${c}`)}else if(a.kind==="declaration"&&a.declaration.unspacedAlias){r(s,"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(a.kind==="declaration"||a.kind==="create"){const l=TT(a.declaration.id);if(l)r(s,"sequence_participant_id_extension",l)}if(a.kind==="message"){for(const[l,c]of[["sender",a.message.from],["receiver",a.message.to]]){if(!ST(c,l))r(s,"sequence_message_id_extension",`Participant "${c}" is read as the ${l}, but pinned Mermaid reads another token there; rename it before typed editing`)}}}for(const o of n)r(t[o],"sequence_block_boundary","Sequence block or box is never closed by end");return{statements:t,issues:i}}function RT(e){const t=T4(e);if(t)return{kind:"declaration",declaration:t};const n=A4(e);if(n)return{kind:"links",...n};const i=e.match(/^(?:properties|details)\s+(\S+)\s*:/i);if(i)return{kind:"actor-data",actorId:i[1]};const r=e.match(/^title(?:\s*:\s*|\s+)(.+)$/i);if(r)return{kind:"title",text:r[1].trim()};const o=e.match(/^autonumber(?:\s+(.*))?$/i);if(o){const m=o[1]?.trim()??"";if(/^off$/i.test(m))return{kind:"autonumber",numbering:null};const p=m.match(/^((?:\d+(?:\.\d{1,2})?|\.\d{1,2}))(?:\s+((?:\d+(?:\.\d{1,2})?|\.\d{1,2})))?$/);if(m&&!p)return null;if(p&&(!Number.isFinite(Number(p[1]))||p[2]!==void 0&&!Number.isFinite(Number(p[2]))))return null;return{kind:"autonumber",numbering:p?{next:Number.parseFloat(p[1]),...p[2]===void 0?{}:{step:Number.parseFloat(p[2])}}:{}}}const s=e.match(/^box(?:\s+(.*))?$/i);if(s)return{kind:"box",text:s[1]?.trim()??""};const a=L4(e);if(a)return{kind:"create",declaration:a};const l=e.match(/^destroy\s+(\S+)$/i);if(l)return{kind:"destroy",actorId:l[1]};const c=I4(e);if(c)return{kind:"note",note:c};const d=hT(e);if(d&&d.type!=="box")return{kind:"block",opener:{type:d.type,label:d.label,...d.wrap===void 0?{}:{wrap:d.wrap}}};const u=mT(e);if(u)return{kind:"continuation",continuation:u};if(e==="end")return{kind:"end"};const f=E4(e);if(f)return{kind:"message",message:f};const h=e.match(/^(activate|deactivate)\s+(\S+)$/i);if(h)return{kind:"activation",actorId:h[2],activate:h[1].toLowerCase()==="activate"};return null}function vT(e){switch(e?.kind){case"declaration":{const{id:t,label:n,type:i,keyword:r,aliased:o,wrap:s}=e.declaration;return[{kind:"declare",id:t,keyword:r,type:i,...o?{label:n}:{},...s===void 0?{}:{wrap:s}}]}case"create":{const{id:t,label:n,type:i,wrap:r}=e.declaration;return[{kind:"declare",id:t,keyword:i==="actor"?"actor":"participant",type:i,label:n,...r===void 0?{}:{wrap:r},create:true}]}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(t=>({kind:"mention",id:t}));case"message":return[{kind:"mention",id:e.message.from},{kind:"mention",id:e.message.to}];default:return[]}}function qoe(e){return vT(RT(e.trim()))}var v4=new Set(["participant","actor","boundary","control","entity","database","collections","queue"]);function $w(e){return typeof e==="string"&&e!==""&&e.trim()===e&&!/[<>,;@#\r\n]/.test(Dn(e))}function TT(e){const t=$w(e);if(t&&ST(e,"declaration"))return null;const n=t?"is read as authored, but pinned Mermaid rejects colons in declaration IDs":"has ambiguous declaration delimiters or whitespace";return`Sequence participant ID ${JSON.stringify(e)} ${n}. Typed editing and serialization require a portable ID; rename this ID and its references, and put display punctuation in an alias`}var Qp=class extends Ls{};function Iw(e){if(!$w(e))throw new Qp(TT(e))}function T4(e){const t=e.match(/^(participant|actor)\s+([^\s@]+)\s*@\{/i);if(t){const l=t[1].toLowerCase();const c=t[2];Iw(c);const d=ec(e,t[0].length-1,"sequence");const u=d.ok?e.slice(d.end+1):"";const f=u.match(/^\s+as(?:\s+(.*))?$/i);if(!d.ok||u.trim()!==""&&!f){throw Je({what:`Invalid participant metadata in "${e}": ${d.ok?`unexpected "${u.trim()}" after it`:d.message}`,expectedForm:'a YAML mapping in @{\u2026} with no "}" inside, then optionally `as <label>`',example:'participant DB@{ "type": "database", "alias": "Orders" }'})}const h=f?ts(f[1]??""):void 0;const m=h?h.text||null:void 0;if(m===null)return null;const{entries:p}=d;const g=p.get("type");const y=typeof g==="string"?g.toLowerCase():l;if(!v4.has(y))throw new Error(`Unknown sequence actor type '${y}'`);const w=y;const S=Mf(p.get("alias"));const x=S!==void 0&&(m===void 0||m===c)?S:m;const M=[...p.keys()].filter(b=>b!=="type"&&b!=="alias");return{id:c,label:x??c,type:w,keyword:l,aliased:x!==void 0,...h?.wrap===void 0?{}:{wrap:h.wrap},...M.length?{unmodeledMetadata:M}:{}}}if(e.includes("@{"))return null;const n=e.match(/^(participant|actor)\s+/i);if(!n)return null;const i=e.slice(n[0].length);const r=i.match(/^(\S+?)\s+as(\s*)(.+)$/i);if(!r&&(!i||/\s/.test(i)&&/[<>:\n,;@]/.test(Dn(i))))return null;const o=r?r[1]:i.trim();Iw(o);const s=n[1].toLowerCase();const a=r?.[3]===void 0?void 0:ts(r[3]);return{id:o,label:a?.text??o,type:s,keyword:s,aliased:Boolean(r),...r?.[2]===""?{unspacedAlias:true}:{},...a?.wrap===void 0?{}:{wrap:a.wrap}}}function L4(e){const t=e.match(/^create\s+(participant|actor)\s+(\S+?)(?:\s+as\s+(.+))?$/i);if(!t)return null;const n=t[2];Iw(n);const i=t[3]===void 0?void 0:ts(t[3]);return{id:n,label:i?.text??n,type:t[1].toLowerCase(),...i?.wrap===void 0?{}:{wrap:i.wrap}}}function A4(e){const t=e.match(/^link\s+(\S+)\s*:\s*(.+?)\s*@\s*(\S+)$/i);if(t){if(!/^(?:https?:|mailto:)/i.test(t[3]))return null;return{actorId:t[1],links:{[t[2].trim()]:t[3]}}}const n=e.match(/^links\s+(\S+)\s*:\s*(\{.*\})$/i);if(!n)return null;try{const i=JSON.parse(n[2]);const r={};for(const[o,s]of Object.entries(i))if(typeof s==="string"&&/^(?:https?:|mailto:)/i.test(s))r[o]=s;return Object.keys(r).length>0?{actorId:n[1],links:r}:null}catch{return null}}function I4(e){const t=e.match(/^Note\s+(left of|right of|over)\s+([^:]+):\s*(.*)$/i);if(!t)return null;const n=t[1].toLowerCase();return{actorIds:t[2].trim().split(",").map(i=>i.trim()),...ts(t[3]),position:n==="left of"?"left":n==="right of"?"right":"over"}}function F4(e){return kf.has(e)}function N4(e){const t=e.includes("--")?"dashed":"solid";const[n,i]=kf.get(e)??["none","none"];return{lineStyle:t,startHead:n,endHead:i}}function yT(e,t,n){for(let i=e.length-1;i>=0;i--){const r=e[i];if(!t(r))continue;n(r);e.splice(i,1)}}function LT(e){return e.number!==void 0?`${e.number}. ${e.label}`:e.label}function AT(e){const t=qe(e.label,e.labelContent);return e.number!==void 0?Mu([`${e.number}. `,typeof t==="string"?Rt(t):t]):t}var Md=class extends Error{};function Voe(e,t){if(!e.includes("%%{"))return void 0;const n=e.split(/\r?\n/);const i=zt(n,t?.(n)).accessibility;return[i.title,i.descr].some(r=>r?.includes("%%{"))?"Accessibility text contains an init-directive opener. Source is preserved for native reading; remove the literal opener before typed editing or portable export.":void 0}function Koe(e){if(typeof e!=="string"||!e.trim())throw new Md("Accessibility metadata must be non-empty text");return e.trim()}function Zp(e){if(typeof e!=="string"||!e.trim()||/[\r\n]/.test(e))throw new Md("Accessibility title must be non-empty single-line text");return e.trim()}function eg(e){if(typeof e!=="string")throw new Md("Accessibility description must be text");const t=e.replace(/\r\n?/g,"\n").split("\n").map(n=>n.trim()).join("\n").trim();if(!t)throw new Md("Accessibility description must be non-empty text");return t}function Joe(e){if(e.kind==="mindmap"||e.kind==="ishikawa"||e.kind==="block")return e;const t=D4(e);if(!t)return e;const n=t.title===void 0?void 0:Zp(t.title);const i=t.descr===void 0||t.descr===""?t.descr:eg(t.descr);return n===t.title&&i===t.descr?e:{...e,...n!==void 0?{accessibilityTitle:n}:{},...i!==void 0?{accessibilityDescription:i}:{}}}function $4(e,t){if(t.accessibilityTitle!==void 0)e.push(` accTitle: ${Zp(t.accessibilityTitle)}`);if(t.accessibilityDescription===void 0)return;const n=t.accessibilityDescription.trim()?eg(t.accessibilityDescription):"";if(!n){Tl(e,{accessibilityDescription:""});return}if(n&&!n.includes("\n")){e.push(` accDescr: ${n}`);return}e.push(" accDescr {");for(const i of n.split("\n"))e.push(` ${i}`);e.push(" }")}function Qoe(e,t){const n=e.split(/\r?\n/).find(u=>u.trim()&&!u.trimStart().startsWith("%%"))?.trim()??"";const i=/^(?:zenuml|eventmodeling|block(?:-beta)?|sankey(?:-beta)?|mindmap|ishikawa(?:-beta)?)(?:\s|$)/i.test(n);const r=new Set;const o=e.split(/\r?\n/);for(let u=0;u<o.length;u++){const f=vt(o,u);if(f){r.add(f.title?"title":"descr");u=f.endIndex}}const s=[];const a=i?Tl:$4;if(t.title!==void 0&&!r.has("title")){a(s,{accessibilityTitle:t.title})}if(t.descr!==void 0&&!r.has("descr")){a(s,{accessibilityDescription:t.descr})}if(s.length===0)return e;const l=e.endsWith("\n");const c=e.replace(/\n$/,"").split(/\r?\n/);const d=c.findIndex(u=>u.trim().length>0);c.splice(d<0?0:d+1,0,...s);return c.join("\n")+(l?"\n":"")}function _4(e,t){const n=[];if(e.title!==void 0&&t.title!==void 0&&e.title!==t.title)n.push("accTitle");if(e.descr!==void 0&&t.descr!==void 0&&e.descr!==t.descr)n.push("accDescr");return n}function Zoe(e,t){const n=e.accessibility;if(_4(t,n).length>0)return false;if(t.title!==void 0&&n.title===void 0||t.descr!==void 0&&n.descr===void 0){e.accessibility={...n,...t.title!==void 0?{title:t.title}:{},...t.descr!==void 0?{descr:t.descr}:{}}}return true}function D4(e){switch(e.kind){case"zenuml":case"timeline":case"journey":case"architecture":case"xychart":case"pie":case"quadrant":case"mindmap":case"gitgraph":case"c4":case"packet":case"kanban":case"requirement":case"treemap":case"ishikawa":case"block":return{...e.accessibilityTitle!==void 0?{title:e.accessibilityTitle}:{},...e.accessibilityDescription!==void 0?{descr:e.accessibilityDescription}:{}};default:return void 0}}function ese(e,t){switch(e.kind){case"timeline":case"journey":case"architecture":case"xychart":case"pie":case"quadrant":case"mindmap":case"gitgraph":case"c4":case"packet":case"kanban":case"requirement":case"treemap":case"ishikawa":case"block":if(t.title!==void 0)e.accessibilityTitle=t.title;if(t.descr!==void 0)e.accessibilityDescription=t.descr;break}}var ao=String.raw`(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[\p{L}_$][\p{L}\p{N}_$-]*?)`;var O4=new RegExp(`^${ao}$`,"u");var IT=new RegExp(`^(${ao})(?![\\p{L}\\p{N}_$-])`,"u");var B4=new RegExp(`^(${ao})\\s*(-->|->)\\s*(${ao})\\s*:\\s*([\\s\\S]*)$`,"u");var W4=new RegExp(`^(${ao})(?:\\s+as\\s+(${ao}))?$`,"u");var z4=new RegExp(`^(?:(${ao})\\s*->\\s*)?(${ao})\\s*\\.\\s*([\\s\\S]+)$`,"u");function _i(e){const t=e.trim();if(!O4.test(t))throw Error(`Invalid ZenUML identity: ${e}`);if(t.startsWith('"'))return JSON.parse(t);if(t.startsWith("'"))return t.slice(1,-1).replace(/\\'/g,"'").replace(/\\\\/g,"\\");return t}function On(e){if(!e||/[\r\n]/.test(e))throw Error("ZenUML identities must be non-empty single-line text");return/^[\p{L}_$][\p{L}\p{N}_$-]*$/u.test(e)&&!_w.has(e)?e:JSON.stringify(e)}var _w=new Set(["title","if","else","while","for","foreach","forEach","loop","par","opt","try","catch","finally","return","new","critical","group","ref","section","const","readonly","static","await","true","false","null","nil","as","in"]);function NT(e){const t=[];let n=0,i="",r=false,o=0,s=0,a=false,l=false,c=false;const d=u=>{const f=e.slice(n,u).trim();if(f)t.push({kind:"text",text:f,start:n+e.slice(n,u).indexOf(f),end:u-(e.slice(n,u).length-e.slice(n,u).trimEnd().length)})};for(let u=0;u<e.length;u++){const f=e[u];const h=!l&&/\S/.test(f);if(h){l=true;if(!o&&!s&&/^title(?:[ \t]|$)/.test(e.slice(u,u+6)))c="title"}if(i){if(r)r=false;else if(f==="\\")r=true;else if(f===i)i="";continue}if(!c&&(f==='"'||f==="'")){i=f;continue}if(!c&&e.startsWith("//",u)){d(u);const m=e.indexOf("\n",u);const p=m<0?e.length:m;t.push({kind:"comment",text:e.slice(u+2,p).replace(/^ /,""),start:u,end:p});u=p-1;n=p;l=false;a=false;continue}if(!c&&e.startsWith("%%",u)&&h){const m=e.indexOf("\n",u);u=m<0?e.length:m-1;n=u+1;l=false;a=false;continue}if(!c){if(f==="(")o++;if(f===")"){if(!o)throw Error("Unmatched ZenUML parenthesis");o--}if(f==="[")s++;if(f==="]"){if(!s)throw Error("Unmatched ZenUML bracket");s--}if(f===">"&&e[u-1]==="-"&&!o&&!s)a=true;if(f===":"&&!o&&!s&&a)c="event"}if(!o&&!s&&(!c&&(f==="{"||f==="}")||f==="\n"||f===";"&&c!=="title")){d(u);if(f==="{"||f==="}")t.push({kind:f==="{"?"open":"close",text:f,start:u,end:u+1});n=u+1;c=false;l=false;a=false}}if(i||o||s)throw Error("Unclosed ZenUML quote or parameter list");d(e.length);return t}function Dw(e){const t=e.join("\n"),n=e.map((i,r)=>r);try{let i=0,r=0;for(const o of NT(t)){while(r<o.start)if(t[r++]==="\n")i++;const s=i;while(r<o.end)if(t[r++]==="\n")i++;for(let a=s;a<i;a++)n[a]=i}}catch{}return n}function G4(e){const t=e.match(new RegExp(`^(?:(${ao})\\s+)?(${ao})\\s*=\\s*(?!=)([\\s\\S]+)$`,"u"));return t?{assignment:{name:_i(t[2]),...t[1]?{type:_i(t[1])}:{}},rest:t[3].trim()}:{rest:e}}function H4(e){const t=[];let n=e,i;while(/^@[\w]+\s+/.test(n)){const s=n.match(/^@([\w]+)\s+/);t.push(s[1]);n=n.slice(s[0].length)}if(n.startsWith("<<")){const s=n.indexOf(">>");if(s<0)return void 0;i=_i(n.slice(2,s).trim());n=n.slice(s+2).trim()}const r=n.match(W4);if(!r||!n.startsWith('"')&&_w.has(r[1]))return void 0;const o=_i(r[1]);return{id:o,label:r[2]?_i(r[2]):o,annotations:t,...i?{stereotype:i}:{}}}function tg(e,t){const n=Array.isArray(e)?e.join("\n"):e;let i=n.replace(/\r\n?/g,"\n");const r=Lr(n);let o=0;let s;const a=pr(i);if(a){const R=$s(a.yaml);if(!R.ok)throw Error(R.message);if(R.value&&typeof R.value==="object"&&"title"in R.value&&typeof R.value.title==="string")s=R.value.title;i=i.slice(a.source.length);o=a.source.split("\n").length-1}const l=zt(i.split("\n"),Dw(i.split("\n")));i=l.familyLines.join("\n");const c=i.match(/^(?:(?:[^\S\n]*(?:%%[^\n]*)?\n))*[^\S\n]*zenuml\b/);if(!c)throw Error("Expected zenuml header");const d=NT(i.slice(c[0].length));const u=Lr(i);const f=[];const h=R=>{const I=Rs(u,R+c[0].length);const L=(l.familyOrigins[I.line-1]??I.line-1)+o;return(r[L]??n.length)+I.col-1};const m=(R,I,L)=>{if(t)f.push({kind:R,id:I,start:h(L.start),end:h(L.end)})};const p={kind:"zenuml",participants:[],statements:[],...Ar(l.accessibility),...s===void 0?{}:{title:s}};let g=0,y=0,w=0,S=true;const x=()=>`statement:${++y}`;const M=R=>({offset:h(R.start),endOffset:h(R.end),unit:"physical"});const b=()=>{const R=d[g++];if(R&&re("zenuml")){const I=M(R);Ge("zenuml",R.kind,n.slice(I.offset,I.endOffset),I)}return R};const C=(R,I,L)=>{R.push(I);if(re("zenuml"))he("zenuml","append-statement",I,M(L))};const P=R=>{if(++w>128)throw Error("ZenUML nesting exceeds 128 scopes");const I=[];while(g<d.length){const L=b();if(L.kind==="close"){if(!R)throw Error("Unmatched ZenUML closing brace");w--;return I}if(L.kind==="open")throw Error("ZenUML scope has no owner");if(L.kind==="comment"){const G={kind:"comment",id:x(),text:L.text};C(I,G,L);m("labels",G.id,L);continue}let $=L.text;if(!R&&($==="title"||$.startsWith("title "))){p.title=$.slice(5).trim();if(re("zenuml"))he("zenuml","set-title",p.title,M(L));m("labels","title",L);continue}const B=$.match(new RegExp(`^@Starter\\(\\s*(${ao})\\s*\\)$`,"u"));if(!R&&B&&S){p.starter=_i(B[1]);if(re("zenuml"))he("zenuml","set-starter",p.starter,M(L));continue}if(!R&&S){const G=H4($);if(G){if(p.participants.some(q=>q.id===G.id))throw Error(`Duplicate ZenUML participant: ${G.id}`);const Y=[];while(I.at(-1)?.kind==="comment"){const q=I.pop();Y.unshift(q.text);if(re("zenuml"))he("zenuml","claim-participant-comment",{participant:G.id,comment:q})}if(Y.length)G.comments=Y;if(G.annotations.length>1)p.unsupportedSource=n;m("nodes",G.id,L);p.participants.push(G);if(re("zenuml"))he("zenuml","append-participant",G,M(L));continue}}S=false;const F=x();m("edges",F,L);let z=false;if(/^@(return|reply)(?:\s|$)/.test($)){z=true;$=$.replace(/^@(return|reply)\s*/,"");if(!$){const G=b();if(!G||G.kind!=="text")throw Error("ZenUML reply annotation requires a message");$=G.text}}const _=$.match(B4);if(_){m("nodes",_i(_[1]),L);m("nodes",_i(_[3]),L);C(I,{kind:"message",id:F,from:_i(_[1]),to:_i(_[3]),label:_[4],reply:z||_[2]==="-->"},L);continue}if(z)throw Error("ZenUML reply annotation requires a directed message");const H=$.match(/^(if|while|for|forEach|foreach|loop|par|opt|try|critical)\b([\s\S]*)$/);if(H){if(t)f.pop();m("groups",F,L);const G=H[1];const Y=FT(H[2]);if(d[g]?.kind!=="open")throw Error(`ZenUML ${G} requires a brace-delimited scope`);b();const q=[{kind:"body",statements:P(true)}];while(d[g]?.kind==="text"){const V=d[g].text.match(/^(else\s+if|else|catch|finally)\b([\s\S]*)$/);if(!V)break;const ne=V[1]==="else if"?"else-if":V[1];if(G==="if"?!["else-if","else"].includes(ne):G==="try"?!["catch","finally"].includes(ne):true)break;b();const X=FT(V[2]);if(b()?.kind!=="open")throw Error("ZenUML branch requires a brace-delimited scope");q.push({kind:ne,...X===void 0?{}:{condition:X},statements:P(true)})}C(I,{kind:"fragment",id:F,type:G,...Y===void 0?{}:{condition:Y},branches:q},L);continue}if(/^return\b/.test($)){C(I,{kind:"return",id:F,label:$.slice(6).trim()},L);continue}const D=G4($);const j=D.rest.match(new RegExp(`^new\\s+(${ao})(?:\\s*\\(([\\s\\S]*)\\))?$`,"u"));const W=()=>{if(d[g]?.kind!=="open")return[];b();return P(true)};if(j){m("nodes",D.assignment?`${D.assignment.name}:${_i(j[1])}`:_i(j[1]),L);C(I,{kind:"create",id:F,constructor:_i(j[1]),...j[2]===void 0?{}:{arguments:j[2]},...D.assignment?{assignment:D.assignment}:{},children:W()},L);continue}const O=D.rest.match(z4);const N=O?O[3]:D.rest;if(IT.test(N)&&j4(N)&&(O!==null||!_w.has(IT.exec(N)[1]))){if(O?.[1])m("nodes",_i(O[1]),L);if(O?.[2])m("nodes",_i(O[2]),L);C(I,{kind:"call",id:F,...O?.[1]?{from:_i(O[1])}:{},...O?.[2]?{to:_i(O[2])}:{},label:N,...D.assignment?{assignment:D.assignment}:{},children:W()},L);continue}C(I,{kind:"opaque",id:F,source:$},L);p.unsupportedSource=n;if(d[g]?.kind==="open"){b();P(true)}}w--;if(R)throw Error("Unclosed ZenUML scope");return I};p.statements=P(false);const E=new Set(p.participants.map(R=>R.id));if(p.starter)E.add(p.starter);const k=[];const v=R=>{for(const I of R){k.push(I);if(I.kind==="call"||I.kind==="message"){if(I.from)E.add(I.from);if(I.to)E.add(I.to)}if(I.kind==="create")E.add(I.assignment?`${I.assignment.name}:${I.constructor}`:I.constructor);if(I.kind==="call"||I.kind==="create")v(I.children);if(I.kind==="fragment")for(const L of I.branches)v(L.statements)}};v(p.statements);const T=new Map;let A=0;for(const R of k){const I=R.id;do{R.id=`statement:${++A}`}while(E.has(R.id));T.set(I,R.id);if(I!==R.id&&re("zenuml"))he("zenuml","readdress-statement",{from:I,to:R.id})}for(const R of f){if(R.kind!=="nodes"&&R.id!=="title")R.id=T.get(R.id)??R.id;t?.(R)}Ve("nodes",E.size);Ve("edges",y);return p}function FT(e){const t=e.trim();if(!t)return void 0;if(!t.startsWith("(")||!t.endsWith(")"))throw Error("ZenUML condition requires parentheses");return t.slice(1,-1).trim()}function j4(e){let t=0,n="",i=false,r="";for(const o of e){if(n){if(i)i=false;else if(o==="\\")i=true;else if(o===n)n="";continue}if(o==='"'||o==="'"){if(!t)return false;n=o;continue}if(o==="("){t++;if(t===1)r+="()";continue}if(o===")"){t--;continue}if(!t)r+=o}return/^[\p{L}_$][\p{L}\p{N}_$-]*(?:\(\))?(?:\s*\.\s*[\p{L}_$][\p{L}\p{N}_$-]*(?:\(\))?)*$/u.test(r.trim())}function Us(e,t){for(const n of e){t(n,e);if(n.kind==="call"||n.kind==="create")Us(n.children,t);if(n.kind==="fragment")for(const i of n.branches)Us(i.statements,t)}}function Cf(e,t=false){if(!e||e.kind!=="zenuml"||!Array.isArray(e.participants)||!Array.isArray(e.statements))throw Error("Invalid ZenUML body");for(const l of[e.title,e.accessibilityTitle,e.accessibilityDescription])if(l!==void 0&&typeof l!=="string")throw Error("ZenUML metadata must be text");if(e.starter!==void 0)On(e.starter);const n=new Set;for(const l of e.participants){On(l.id);if(typeof l.label!=="string"||/[\r\n]/.test(l.label))throw Error("ZenUML aliases must be single-line text");if(n.has(l.id))throw Error(`Duplicate ZenUML participant: ${l.id}`);n.add(l.id);if(!Array.isArray(l.annotations)||l.annotations.some(c=>typeof c!=="string"||!/^\w+$/.test(c)))throw Error("Invalid ZenUML annotator");if(l.annotations.length>1&&(t||e.unsupportedSource===void 0))throw Error("ZenUML declarations accept one participant annotator");if(l.stereotype!==void 0&&(typeof l.stereotype!=="string"||!l.stereotype||/[<>\r\n]/.test(l.stereotype)))throw Error("Invalid ZenUML stereotype");if(l.comments!==void 0&&(!Array.isArray(l.comments)||l.comments.some(c=>typeof c!=="string")))throw Error("Invalid ZenUML participant comments")}const i=new Set,r=new Set;const o=l=>{if(typeof l!=="string")throw Error("ZenUML content must be text")};const s=l=>{if(l){On(l.name);if(l.type!==void 0)On(l.type)}};const a=(l,c)=>{if(!Array.isArray(l)||c>128)throw Error("Invalid or excessive ZenUML scope nesting");for(const d of l){if(!d||typeof d!=="object"||r.has(d))throw Error("Cyclic or shared ZenUML statement");r.add(d);if(typeof d.id!=="string"||!d.id||i.has(d.id))throw Error("ZenUML statement identities must be unique");i.add(d.id);switch(d.kind){case"call":if(d.from!==void 0)On(d.from);if(d.to!==void 0)On(d.to);if(d.from!==void 0&&d.to===void 0)throw Error("An explicit ZenUML caller requires a target");o(d.label);s(d.assignment);a(d.children,c+1);break;case"create":On(d.constructor);if(d.arguments!==void 0)o(d.arguments);s(d.assignment);a(d.children,c+1);break;case"message":On(d.from);On(d.to);o(d.label);if(typeof d.reply!=="boolean")throw Error("ZenUML message reply flag must be boolean");break;case"return":o(d.label);break;case"comment":o(d.text);break;case"fragment":{if(!["if","opt","while","for","forEach","foreach","loop","par","try","critical"].includes(d.type)||!Array.isArray(d.branches)||!d.branches.length||d.branches[0]?.kind!=="body")throw Error("Invalid ZenUML fragment");if(d.condition!==void 0)o(d.condition);let u=false;for(const[f,h]of d.branches.entries()){if(f&&(u||(d.type==="if"?!["else-if","else"].includes(h.kind):d.type==="try"?!["catch","finally"].includes(h.kind):true)))throw Error("Invalid ZenUML branch order");if(h.kind==="else"||h.kind==="finally")u=true;if(h.condition!==void 0)o(h.condition);a(h.statements,c+1)}break}case"opaque":o(d.source);if(t||e.unsupportedSource===void 0)throw Error("Unsupported ZenUML syntax is retained; typed editing and rendering require a fully modelled document");break;default:throw Error("Unknown ZenUML statement kind")}}};a(e.statements,0);if(t&&e.unsupportedSource!==void 0)throw Error("Unsupported ZenUML source cannot be rewritten through typed editing");Ve("nodes",DT(e).size);Ve("edges",i.size)}function $T(e){return e?`${e.type?`${On(e.type)} `:""}${On(e.name)} = `:""}function Y4(e,t=true){Cf(e);if(e.unsupportedSource!==void 0)return e.unsupportedSource;const n=["zenuml"];Tl(n,e);if(e.title!==void 0&&t){if(/[\r\n]/.test(e.title)){n.unshift(`---
15
+ title: ${JSON.stringify(e.title)}
16
+ ---`)}else n.push(`title ${e.title}`)}for(const r of e.participants){for(const o of r.comments??[])for(const s of o.split("\n"))n.push(`//${s?` ${s}`:""}`);n.push(`${r.annotations.map(o=>`@${o} `).join("")}${r.stereotype?`<<${On(r.stereotype)}>> `:""}${On(r.id)}${r.label===r.id?"":` as ${r.label?On(r.label):'""'}`}`)}if(e.starter!==void 0)n.push(`@Starter(${On(e.starter)})`);const i=(r,o)=>{const s=" ".repeat(o);const a=(l,c)=>{if(!c.length){n.push(s+l);return}n.push(`${s}${l} {`);i(c,o+1);n.push(`${s}}`)};for(const l of r)switch(l.kind){case"comment":for(const c of l.text.split("\n"))n.push(`${s}//${c?` ${c}`:""}`);break;case"call":a(`${$T(l.assignment)}${l.to===void 0?"":`${l.from===void 0?"":`${On(l.from)}->`}${On(l.to)}.`}${l.label}`,l.children);break;case"create":a(`${$T(l.assignment)}new ${On(l.constructor)}${l.arguments===void 0?"":`(${l.arguments})`}`,l.children);break;case"return":n.push(`${s}return${l.label?` ${l.label}`:""}`);break;case"message":n.push(`${s}${On(l.from)}${l.reply?"-->":"->"}${On(l.to)}: ${l.label}`);break;case"fragment":for(const[c,d]of l.branches.entries()){const u=c===0?`${l.type}${l.condition===void 0?"":` (${l.condition})`}`:`${d.kind==="else-if"?"else if":d.kind}${d.condition===void 0?"":` (${d.condition})`}`;n.push(`${s}${c?"} ":""}${u} {`);i(d.statements,o+1)}n.push(`${s}}`);break;case"opaque":throw Error("Unsupported ZenUML source cannot be serialized partially")}};i(e.statements,0);return n.join("\n")+"\n"}function _T(e){const t=n=>{if(Array.isArray(n))return n.map(t);if(n&&typeof n==="object")return Object.fromEntries(Object.entries(n).filter(([i,r])=>r!==void 0&&!(i==="id"&&"kind"in n&&n.kind!=="zenuml")).sort(([i],[r])=>i<r?-1:i>r?1:0).map(([i,r])=>[i,t(r)]));return n};return JSON.stringify(t(e))}function pse(e,t){try{Cf(e,true);const n=structuredClone(e);const i=a=>{let l;Us(n.statements,(c,d)=>{if(c.id===a)l={statement:c,siblings:d}});if(!l)throw Error(`Unknown ZenUML statement: ${a}`);return l};const r=(a,l)=>{const c=a??l;if(!Number.isSafeInteger(c)||c<0||c>l)throw Error("Invalid ZenUML insertion position");return c};const o=a=>{const l=n.participants.findIndex(c=>c.id===a);if(l<0)throw Error(`Unknown declared ZenUML participant: ${a}`);return l};switch(t.kind){case"upsert_participant":{const a=n.participants.findIndex(l=>l.id===t.participant.id);if(a<0)n.participants.splice(r(t.index,n.participants.length),0,structuredClone(t.participant));else n.participants[a]=structuredClone(t.participant);break}case"remove_participant":{if(q4(n,t.id))throw Error("Cannot remove a participant referenced by ZenUML interactions");const a=o(t.id);n.participants.splice(a,1);break}case"rename_participant":{const a=DT(n);if(!a.has(t.id))throw Error(`Unknown ZenUML participant: ${t.id}`);On(t.newId);const l=new Map([[t.id,t.newId]]);Us(n.statements,d=>{if(d.kind!=="create")return;const u=d.assignment?`${d.assignment.name}:${d.constructor}`:d.constructor;if(u===t.id&&d.assignment){const f=`:${d.constructor}`;if(!t.newId.endsWith(f))throw Error("Renaming a created instance must retain its constructor suffix");d.assignment.name=t.newId.slice(0,-f.length);On(d.assignment.name)}else if(d.constructor===t.id){d.constructor=t.newId;l.set(u,d.assignment?`${d.assignment.name}:${d.constructor}`:d.constructor)}});const c=new Set;for(const[d,u]of l){if(c.has(u)||d!==u&&a.has(u)&&!l.has(u))throw Error("Renaming would merge distinct ZenUML participants");c.add(u)}for(const d of n.participants)if(l.has(d.id)){const u=d.id;d.id=l.get(u);if(d.label===u)d.label=d.id}if(n.starter!==void 0)n.starter=l.get(n.starter)??n.starter;Us(n.statements,d=>{if(d.kind==="call"||d.kind==="message"){if(d.from!==void 0)d.from=l.get(d.from)??d.from;if(d.to!==void 0)d.to=l.get(d.to)??d.to}});break}case"insert_statement":{let a=n.statements;if(t.parentId!==void 0){const l=i(t.parentId).statement;if(l.kind==="call"||l.kind==="create"){if(t.branchIndex!==void 0)throw Error("Only fragments own branch indices");a=l.children}else if(l.kind==="fragment"){const c=l.branches[r(t.branchIndex??0,l.branches.length-1)];if(!c)throw Error("Unknown ZenUML branch");a=c.statements}else throw Error("Statement cannot own nested ZenUML interactions")}else if(t.branchIndex!==void 0)throw Error("A branch index requires a parent fragment");a.splice(r(t.index,a.length),0,structuredClone(t.statement));break}case"remove_statement":{const a=i(t.id);a.siblings.splice(a.siblings.indexOf(a.statement),1);break}case"set_statement":{const a=i(t.id);if(t.statement.id!==t.id)throw Error("Statement replacement must retain its editing identity");a.siblings[a.siblings.indexOf(a.statement)]=structuredClone(t.statement);break}case"set_title":n.title=t.title;break;case"set_accessibility_title":n.accessibilityTitle=t.title===void 0?void 0:Zp(t.title);break;case"set_accessibility_description":n.accessibilityDescription=t.description===void 0?void 0:eg(t.description);break;default:throw Error(aP("zenuml",t))}Cf(n,true);const s=tg(Y4(n));if(_T(n)!==_T(s))throw Error("ZenUML edit cannot be written without changing owned meaning");return gC(s)}catch(n){return yC({code:"INVALID_OP",message:n instanceof Error?n.message:String(n)})}}function q4(e,t){let n=e.starter===t;Us(e.statements,i=>{if((i.kind==="call"||i.kind==="message")&&(i.from===t||i.to===t))n=true;if(i.kind==="create"&&(i.constructor===t||(i.assignment?`${i.assignment.name}:${i.constructor}`:i.constructor)===t))n=true});return n}function DT(e){const t=new Set(e.participants.map(n=>n.id));if(e.starter!==void 0)t.add(e.starter);Us(e.statements,n=>{if(n.kind==="call"||n.kind==="message"){if(n.from!==void 0)t.add(n.from);if(n.to!==void 0)t.add(n.to)}if(n.kind==="create")t.add(n.assignment?`${n.assignment.name}:${n.constructor}`:n.constructor)});return t}var OT={actor:"actor",boundary:"boundary",control:"control",entity:"entity",database:"database",collections:"collections",queue:"queue",participant:"participant"};var kd=e=>({value:e,prepared:Rt(e,"literal")});function WT(e,t){Cf(e,true);const n={actors:[],messages:[],blocks:[],notes:[],activationEvents:[],boxes:[],...e.title===void 0?{}:{title:e.title,titleContent:kd(e.title)},...e.accessibilityTitle===void 0?{}:{accessibilityTitle:e.accessibilityTitle},...e.accessibilityDescription===void 0?{}:{accessibilityDescription:e.accessibilityDescription}};const i=new Map,r=new Set(e.participants.map(g=>g.id));if(e.starter)r.add(e.starter);Us(e.statements,g=>{r.add(g.id);if(g.kind==="call"||g.kind==="message"){if(g.from)r.add(g.from);if(g.to)r.add(g.to)}if(g.kind==="create")r.add(BT(g))});let o="zenuml:outside";while(r.has(o))o+=":";const s=g=>{let y=g;while(r.has(y))y+=":";r.add(y);return y};const a=g=>{const y=g??o;if(!i.has(y)){const w={id:y,label:g===void 0?"":g,type:"participant",labelContent:kd(g??""),...g===void 0?{external:true}:{}};n.actors.push(w);i.set(y,w)}return y};for(const g of e.participants){a(g.id);const y=i.get(g.id);y.type=g.annotations.map(S=>OT[S.toLowerCase()]).find(Boolean)??"participant";const w=[...g.annotations.filter(S=>!OT[S.toLowerCase()]).map(S=>`@${S}`),...g.stereotype?[g.stereotype]:[]];y.label=[...w.map(S=>`\xAB${S}\xBB`),g.label].join("\n");y.labelContent=kd(y.label)}let l=e.starter;if(l===void 0)for(const g of e.statements){if(g.kind==="message"||g.kind==="call"&&g.from!==void 0){l=g.from;break}if(g.kind!=="comment")break}if(l!==void 0)a(l);const c=[],d=new Map,u=[];const f=(g,y,w,S,x,M,b=false,C=g)=>{const P=a(y),E=a(w);const k=M==="reply";const v={id:g,...x.parentId?{parentId:x.parentId}:{},from:P,to:E,label:S,labelContent:kd(S),lineStyle:k?"dashed":"solid",startHead:"none",endHead:k?"open":"filled",centralStart:false,centralEnd:false,...b?{activate:true}:{}};n.messages.push(v);t?.message?.({message:v,kind:M,sourceId:C,callAncestors:x.callAncestors,scopes:x.scopes})};const h=(g,y,w,S)=>{const x=H1(y);const M={id:g,...S.parentId?{parentId:S.parentId}:{},actorIds:[...new Set(w.length?w:[a(S.owner)])],text:x,textContent:{value:x,authored:y,prepared:Rt(x,"formatted")},position:"over",afterIndex:n.messages.length-1};const b=n.notes.length;n.notes.push(M);t?.note?.({note:M,sourceId:g,callAncestors:S.callAncestors,scopes:S.scopes});for(const C of u)d.get(C).noteIndices.push(b)};const m=(g,y,w)=>g.some(S=>S.kind==="return"||S.kind==="message"&&S.reply&&S.from===y&&S.to===w||S.kind==="fragment"&&S.branches.some(x=>m(x.statements,y,w)));const p=(g,y)=>{let w=[];const S=x=>{for(const M of w)h(M.id,M.text,x,y);w=[]};for(const x of g){if(x.kind==="comment"){w.push(x);continue}switch(x.kind){case"call":{const M=x.from??y.owner,b=x.to??y.owner;const C=a(M),P=a(b);S([C,P]);const E=C===P;const k=x.assignment&&!E&&m(x.children,b,M);f(x.id,M,b,x.assignment&&(E||k)?`${ng(x.assignment)} = ${x.label}`:x.label,y,"call",true);const v={...y,owner:b,returnTo:M,callAncestors:t?[...y.callAncestors,x.id]:y.callAncestors};p(x.children,v);if(x.assignment&&!E&&!k)f(s(`${x.id}:reply`),b,M,ng(x.assignment),v,"reply",false,x.id);n.activationEvents.push({actorId:P,kind:"deactivate",messageIndex:n.messages.length});break}case"create":{const M=BT(x),b=a(y.owner);a(M);S([b,M]);const C=i.get(M);if(C.createMessageIndex!==void 0)throw Error(`Repeated creation of ZenUML object ${M} cannot share one sequence lifeline`);C.createMessageIndex=n.messages.length;const P=x.assignment&&m(x.children,M,y.owner);const E=`\xAB${x.arguments||"create"}\xBB`;f(x.id,y.owner,M,x.assignment&&P?`${ng(x.assignment)} = ${E}`:E,y,"creation",true);const k={...y,owner:M,returnTo:y.owner,callAncestors:t?[...y.callAncestors,x.id]:y.callAncestors};p(x.children,k);if(x.assignment&&!P)f(s(`${x.id}:reply`),M,y.owner,ng(x.assignment),k,"reply",false,x.id);n.activationEvents.push({actorId:M,kind:"deactivate",messageIndex:n.messages.length});break}case"message":S([a(x.from),a(x.to)]);f(x.id,x.from,x.to,x.label,y,x.reply?"reply":"async");n.messages.at(-1).endHead="open";break;case"return":S([a(y.owner),a(y.returnTo)]);f(x.id,y.owner,y.returnTo,x.label,y,"reply");break;case"fragment":{if(w.length)S([a(y.owner)]);const M=n.blocks.length;const b=x.type==="if"?"alt":x.type==="par"?"par":x.type==="opt"?"opt":x.type==="try"?"break":x.type==="critical"?"critical":"loop";const C=["if","opt","par","critical"].includes(x.type)?x.condition??"":`${x.type}${x.condition===void 0?"":` (${x.condition})`}`;const P={id:x.id,...y.parentId?{parentId:y.parentId}:{},type:b,label:C,labelContent:kd(C),startIndex:n.messages.length,endIndex:n.messages.length-1,dividers:[]};n.blocks.push(P);const E={endMessageExclusive:0,endNoteExclusive:0,dividerNoteIndices:[],noteIndices:[],childBlockIndices:[],childSectionIndices:[]};d.set(M,E);if(y.blockIndex!==void 0){const v=d.get(y.blockIndex);v.childBlockIndices.push(M);v.childSectionIndices.push(y.section)}c.push({kind:"open",blockIndex:M,messageIndex:n.messages.length,noteIndex:n.notes.length});u.push(M);const k=x.type==="par"?X4(x.branches[0].statements):x.branches;t?.fragment?.({fragment:x,branches:k,callAncestors:y.callAncestors,scopes:y.scopes});for(const[v,T]of k.entries()){if(v){const R=T.kind==="else-if"?`else if (${T.condition??""})`:T.kind==="body"?"":`${T.kind}${T.condition===void 0?"":` (${T.condition})`}`;const I=P.dividers.length;P.dividers.push({index:n.messages.length,label:R,labelContent:kd(R)});E.dividerNoteIndices.push(n.notes.length);c.push({kind:"divider",blockIndex:M,dividerIndex:I,messageIndex:n.messages.length,noteIndex:n.notes.length})}const A=v===0?x.condition:T.condition;p(T.statements,{...y,parentId:x.id,blockIndex:M,section:v,scopes:t?[...y.scopes,{fragmentId:x.id,fragmentIndex:M,type:x.type,branchIndex:v,branchKind:T.kind,...A===void 0?{}:{condition:A}}]:y.scopes})}u.pop();P.endIndex=n.messages.length-1;E.endMessageExclusive=n.messages.length;E.endNoteExclusive=n.notes.length;kT(P,E);c.push({kind:"close",blockIndex:M,messageIndex:n.messages.length,noteIndex:n.notes.length});break}case"opaque":throw Error("Unsupported ZenUML syntax cannot be projected partially")}}if(w.length)S([a(y.owner)])};p(e.statements,{owner:l,section:0,callAncestors:[],scopes:[]});if(!n.actors.length&&(n.blocks.length||n.notes.length))a(void 0);CT(n,c);return n}function ng(e){return e.type===void 0?e.name:`${e.name}:${e.type}`}function BT(e){return e.assignment?`${e.assignment.name}:${e.constructor}`:e.constructor}function X4(e){const t=[];let n=[];for(const i of e){n.push(i);if(i.kind!=="comment"){t.push({kind:"body",statements:n});n=[]}}if(n.length||!t.length)t.push({kind:"body",statements:n});return t}import{decodeXML as U4}from"entities";var qT=String.raw`~{3,}|[xo]-?\.+-[xo]|-?\.+-[>xo]?|[xo]={2,}[xo]|={2,}[>xo]|={3,}|o-{2,}o|o-{2,}x|x-{2,}o|x-{2,}x|-{2,}[ox]|-{2,}>|-{3,}`;var V4=new RegExp(`(<)?(${qT})`,"y");var og=`<?(?:${qT})`;var XT=String.raw`(?!${og}|[xo]?(?:-{2,}|-\.|={2,}))[^\s"@[\](){}|<>;]+`;var UT=/([<xo])?(-{2,}|-\.+|={2,})/y;var zT={solid:"-{2,}[-ox>]",thick:"={2,}[=>xo]",dotted:"-?\\.+-[>xo]?"};var VT={...zT,mixed:Object.values(zT).join("|")};var K4=Object.fromEntries(Object.entries(VT).map(([e,t])=>[e,new RegExp(`(${t})`,"y")]));var J4=Object.fromEntries(Object.entries(VT).map(([e,t])=>[e,new RegExp(`\\s*(?:${t})`,"y")]));var Q4={solid:/--/y,thick:/==/y,dotted:void 0};function Ow(e){return e.includes(".")?"dotted":e.startsWith("=")?"thick":"solid"}function Cd(e,t,n){e.lastIndex=n;return e.exec(t)}var Bw=/[\p{L}\p{N}_!"#$%&'*+.`?\\/]/u;function tc(e,t=0){let n=t;for(;n<e.length;n++){const i=e[n];if(i==="-"){const r=e[n+1];if(r==="-"||r===".")break;continue}if(n===t&&i==='"')break;if(i===":"){if(e.startsWith(":::",n))break;continue}if(!Bw.test(i))break}return n-t}var Z4={text:/[[\](){}|"]/,trapezoid:/[[\](){}]/,"edge-text":/"/};function Pf(e,t){let n=e;if(e.startsWith('"')){const i=e.startsWith('"`');const r=i?e.indexOf('`"',2):e.indexOf('"',1);if(r<0)return false;n=e.slice(r+(i?2:1))}return Z4[t].test(n)}var ej=/^[\p{L}0-9\s!"#$%&'*+\-./:?\\^_`]*$/u;var tj=/(?:^|\s)(?:"|\.+-)|--|-\.|->|:::/;function Ww(e){let t=e;if(e.startsWith('"')){const n=e.startsWith('"`');const i=n?e.indexOf('`"',2):e.indexOf('"',1);if(i<0)return true;t=e.slice(i+(n?2:1))}return!ej.test(t)||tj.test(t)}function KT(e,t){const n=e[t-1];return e[t]===","&&n!==void 0&&(n==="-"||n===":"||Bw.test(n))}function ig(e,t){return(e[t]==="."||e[t]==='"')&&t>0&&Bw.test(e[t-1])}function sg(e,t){const n=Cd(V4,e,t);return n?{hasArrowStart:Boolean(n[1]),op:n[2],end:t+n[0].length}:null}function nj(e,t,n){let i=t;while(i<e.length&&/\s/.test(e[i]))i++;if(e[i]!=='"')return void 0;for(let r=e.indexOf('"',i+1);r>=0;r=e.indexOf('"',r+1)){if(Cd(J4[n],e,r+1))return{open:i,close:r}}return void 0}function zw(e,t){const n=Ef(e,t);return n&&"end"in n?n:null}function Ef(e,t){const n=Cd(UT,e,t);if(!n)return null;const i=GT(e,t,n,Ow(n[2]));return i&&"end"in i?i:GT(e,t,n,"mixed")}function ij(e){const t=Ef(e,0);return t!==null&&"stray"in t}function GT(e,t,n,i){const r=t+n[0].length;const o=nj(e,r,i);const s=Q4[Ow(n[2])];for(let a=o?o.close+1:r;a<e.length;a++){const l=Cd(K4[i],e,a);if(!l){if(s&&Cd(s,e,a))return{stray:a};continue}const c=e.slice(r,a);const d=c.trim();if(d.length===0)continue;const u=r+c.length-c.trimStart().length;return{hasArrowStart:Boolean(n[1]),...n[1]?{startMark:n[1]}:{},openOp:n[2],closeOp:l[1],labelStart:u,labelEnd:u+d.length,...o?{quote:o}:{},end:a+l[0].length,...i==="mixed"?{mixed:true}:{}}}return null}function rj(e,t){let n=t+1;while(n<e.length&&/\s/.test(e[n]))n++;if(e[n]==='"'){for(let r=e.indexOf('"',n+1);r>=0;r=e.indexOf('"',r+1)){let o=r+1;while(o<e.length&&/\s/.test(e[o]))o++;if(e[o]==="|")return{close:o,quote:{open:n,close:r}}}}const i=e.indexOf("|",t+1);return i<0?void 0:{close:i}}function oj(e,t){let n=t+1;while(n<e.length&&/\s/.test(e[n]))n++;return e[n]==="{"?n:-1}var HT=new Set(["[","(","{"]);var sj=new Set(["]",")","}"]);function Gw(e){return rg(e,0,false,false)}function JT(e,t){const n=rg(e,t,true,false).regions[0];return n?.start===t?n:void 0}function rg(e,t,n,i,r=-1){const o=[];const s=n?[]:Array(e.length).fill(false);const a=[];const l=[];const c=[];const d=(f,h,m)=>{o.push({kind:f,start:h,end:e.length,contentStart:m,contentEnd:e.length,closed:false,parent:c.at(-1)??-1});c.push(o.length-1)};const u=(f,h)=>{const m=o[c.pop()];m.contentEnd=f;m.end=h;m.closed=true};for(let f=t;f<e.length;f++){if(n&&o.length>0&&c.length===0)break;const h=e[f];const m=c.length>0?o[c.at(-1)]:void 0;if(m?.kind==="string"){if(h==='"')u(f,f+1);continue}if(m?.kind==="markdown"){if(h==="`"&&e[f+1]==='"'){u(f,f+2);f++}else if(h==='"')d("string",f,f+1);continue}if(h==='"'&&f!==r&&!(i&&m?.kind==="shape"&&f!==m.contentStart)&&!(m===void 0&&ig(e,f))){if(e[f+1]==="`"){d("markdown",f,f+2);f++}else d("string",f,f+1);continue}if(m?.kind==="shape"){if(HT.has(h))d("shape",f,f+1);else if(sj.has(h))u(f,f+1);continue}const p=h==="@"?oj(e,f):-1;if(p>=0){const g=wa(e,p,"flowchart");if(g.kind==="closed"){o.push({kind:"metadata",start:f,end:g.end+1,contentStart:p+1,contentEnd:g.end,closed:true,parent:-1});f=g.end;continue}if(g.kind==="unclosed"){d("metadata",f,p+1);break}}if(h==="|"){const g=rj(e,f);if(!g){d("pipe",f,f+1);break}const y=o.length;o.push({kind:"pipe",start:f,end:g.close+1,contentStart:f+1,contentEnd:g.close,closed:true,parent:-1});if(g.quote){o.push({kind:"string",start:g.quote.open,end:g.quote.close+1,contentStart:g.quote.open+1,contentEnd:g.quote.close,closed:true,parent:y})}f=g.close;continue}if(HT.has(h)){d("shape",f,f+1);continue}if(h==="-"||h==="="||h==="<"||h==="~"||h==="."&&!ig(e,f)){const g=sg(e,f);if(g){l.push({start:f,end:g.end});s.fill(true,f,g.end);f=g.end-1;continue}const y=Cd(UT,e,f);const w=y?Ef(e,f):null;const S=w&&"end"in w?w:null;if(S){const x=o.length;o.push({kind:"edge-text",start:f,end:S.end,contentStart:S.labelStart,contentEnd:S.labelEnd,closed:true,parent:-1});if(S.quote){o.push({kind:"string",start:S.quote.open,end:S.quote.close+1,contentStart:S.quote.open+1,contentEnd:S.quote.close,closed:true,parent:x})}s.fill(true,f,S.labelStart);const M=S.end-S.closeOp.length;s.fill(true,M,S.end);if(!n)for(let b=S.labelEnd;b<M;b++)s[b]=true;l.push({start:f,end:f+y[0].length},{start:M,end:S.end});f=S.end-1;continue}if(y){l.push({start:f,end:f+y[0].length});s.fill(true,f,f+y[0].length);if(w){f+=y[0].length-1;continue}d("edge-text",f,f+y[0].length);break}}if(h===">"){d("shape",f,f+1);continue}if(!n)s[f]=true;if(h===";")a.push(f)}return{regions:o,topLevel:s,separators:a,links:l,openAtEnd:c.map(f=>o[f].kind)}}var aj=/^(?:style|classDef|linkStyle)\s/;function lj(e){return!!e.trim()&&!/[\r\n:;,]/.test(e)&&QT(`${e}:`)}function Rse(e,t=false){const n=t?e.split(","):[e];return!!e.trim()&&!e.startsWith("::")&&!/[\r\n]/.test(e)&&n.every(i=>!!i.trim()&&QT(i))}function QT(e){if(/direction\s+(?:TB|BT|RL|LR|TD)|:::/.test(e))return false;let t=e;while(t){if(/^(?:acc(?:Title|Descr)\s*:|(?:call|href|click)\s|(?:classDef|class|linkStyle|default|end|graph|flowchart|subgraph|swimlane-beta|interpolate|_self|_blank|_parent|_top|v)\b|["&*]|[xo]?(?:--|-\.)|[xo]?-?\.+-)/.test(t))return false;const n=/^(?:style\b|[0-9]+|[:#]|[^\S\r\n]+)/.exec(t)??/^(?:[A-Za-z0-9!"#$%&'*+.`?\\_/]|-(?=[^>\-.]))+/.exec(t);if(!n)return false;t=t.slice(n[0].length)}return true}function ag(e){for(const t of Object.keys(e)){if(!lj(t))throw Je({what:`Invalid style property name ${JSON.stringify(t)}`,expectedForm:"property text that does not introduce Mermaid statements, links or shape delimiters",example:"style A background:#bbb,border:1px solid red"})}return e}var cj=new RegExp(String.raw`^[a-zA-Z][\w-]*\s*:(?!:)(?:(?!${og}|:::)[^&@"[\]{}|])*$`);function Rf(e,t=Gw(e)){const n=[];let i=0;for(const r of[...t.separators,e.length]){const o=e.slice(i,r);const s=o.trim();const a=i+o.length-o.trimStart().length;const l=/^end\s+/.exec(s);const c=n.at(-1);if(l)n.push({text:"end",start:a},{text:s.slice(l[0].length),start:a+l[0].length});else if(s&&c&&aj.test(c.text)&&cj.test(s))c.text=e.slice(c.start,a+s.length);else if(s)n.push({text:s,start:a});i=r+1}return n}function dj(e,t){const n=e.joined??[];let i=0;let r=n.length;while(i<r){const s=i+Math.floor((r-i)/2);if(n[s].at<=t)i=s+1;else r=s}const o=i===0?{at:0,line:e.line,col:0}:n[i-1];return{line:o.line,col:o.col+t-o.at}}var uj=5;var jT=/^(?:(?:end|subgraph|classDef|class|style|linkStyle|click|href|accTitle|accDescr)(?![\w-])|direction\s)/;function lg(e){const t=[];const n=p=>rg(p,0,false,true);let i;let r="";let o=n(r);let s=false;let a=false;let l;const c=new Map;const d=(p,g)=>{let y=c.get(g);if(!y){const{delimiter:w,closer:S,after:x}=hj[g];y=new Uint8Array(e.length+1);for(let M=e.length-1;M>=0;M--){const b=e[M];const C=b.search(w);y[M]=C<0?y[M+1]:Number(b[C]===S&&x.test(b.slice(C+1)))}c.set(g,y)}return y[p]===1};let u;const f=p=>{if(!u){u=new Uint8Array(e.length+1);for(let g=e.length-1;g>=0;g--){const y=e[g];const w=y.indexOf('"');u[g]=w<0?u[g+1]:Number(/^\s*[\])}]/.test(y.slice(w+1)))}}return u[p]===1};let h=false;const m=p=>{const g=e[p];if(!/^\s*acc(?:Title|Descr)/i.test(g)||h&&/^\s*accDescr\s*:?\s*\{[^}]*$/i.test(g))return void 0;const y=vt(e,p);if(y===void 0)h=true;return y?.endIndex};for(let p=0;p<e.length;p++){const g=e[p];const y=g.trim();const w=o.openAtEnd;const S=o.regions.some(T=>T.kind==="string"&&T.parent>=0&&T.start!==o.regions[T.parent].contentStart);const x=l!==void 0&&d(p,l);const M=i!==void 0&&w.length>0&&w.length<=uj&&!S&&(w[0]==="metadata"||w.includes("markdown")||!s||x||a&&w.length===1&&w[0]==="string")&&!(w[0]==="edge-text"&&ij(`${YT(r,o).prefix}${y}`));if(!M&&(!y||y.startsWith("%%"))){t.push({text:g,line:p});continue}const b=M?void 0:m(p);if(b!==void 0){i={text:g,line:p,directive:true};t.push(i);for(let T=p+1;T<=b;T++){;(i.joined??=[]).push({at:i.text.length+1,line:T,col:0});i.text+=`
17
+ ${e[T]}`}p=b;r="";o=n(r);s=true;a=false;l=void 0;continue}let C=y;let P;let E;if(M&&w[0]==="metadata"){C=`${r}
18
+ ${g}`;E=n(C);P="\n"}else if(M){const T=YT(r,o);C=`${T.prefix}${y}`;E=n(C);const A=E.regions[w.length-1];const R=A.closed&&C.slice(T.prefix.length,A.contentEnd).trim()==="";P=T.blank||R?" ":"<br>"}else{E=n(C);const T=w.length===0&&o.links.at(-1)?.end===r.trimEnd().length;if(i&&!s&&(T&&!jT.test(y)||E.links[0]?.start===0))P=" "}const k=fj(E);if(k!==void 0&&!f(p+1))E=rg(C,0,false,true,k);if(P===void 0){i={text:g,line:p};t.push(i)}else{const T=P==="\n"?g:y;const A=P==="\n"?0:g.length-g.trimStart().length;(i.joined??=[]).push({at:i.text.length+P.length,line:p,col:A});i.text+=`${P}${T}`}const v=Rf(C,E).at(-1);if(P===void 0||v&&v.start>0){s=v!==void 0&&jT.test(v.text);a=v!==void 0&&/^(?:click|href)\s/.test(v.text);l=v!==void 0&&/^subgraph\s/.test(v.text)?mj(C,E,v):void 0}r=C;o=E}return t}function ZT(e){const t=e.map((r,o)=>o);const n=[];const i=[];e.forEach((r,o)=>{const s=r.trim();if(s&&!s.startsWith("%%")){n.push(o);i.push(s)}});for(const r of lg(i)){const o=r.joined?.at(-1)?.line;if(o!==void 0)t[n[r.line]]=n[o]}return t}function fj(e){const t=e.regions.filter(i=>!i.closed).at(-1);const n=t&&t.parent>=0?e.regions[t.parent]:void 0;return t?.kind==="string"&&n?.kind==="shape"&&t.start===n.contentStart?t.start:void 0}var hj={bracket:{delimiter:/[[\](){}]/,closer:"]",after:/^\s*(?:;|$)/},string:{delimiter:/"/,closer:'"',after:/^\s*(?:;|$)/},bracketString:{delimiter:/"/,closer:'"',after:/^\s*\]\s*(?:;|$)/}};function mj(e,t,n){const i=t.regions.filter(a=>!a.closed);const[r,o]=i;const s=n.start+/^subgraph\s+/.exec(n.text)[0].length;if(i.length===1&&r.kind==="string"&&r.start===s)return"string";if(r?.kind!=="shape"||e[r.start]!=="["||/[[\]"]/.test(e.slice(s,r.start)))return void 0;if(i.length===1)return"bracket";return i.length===2&&o.kind==="string"&&o.start===r.contentStart?"bracketString":void 0}function YT(e,t){const n=t.regions.filter(a=>!a.closed);const i=n.at(-1);const r=e.slice(i.contentStart).trimStart()[0];const o=r===void 0?"":i.kind==="pipe"||i.kind==="edge-text"?`${r} `:"_ ";const s=a=>a.kind==="edge-text"?pj[Ow(e.slice(a.start,a.contentStart).replace(/^</,""))]:e.slice(a.start,a.contentStart);return{prefix:`${n.map(s).join("")} ${o}`,blank:r===void 0}}var pj={solid:"--",thick:"==",dotted:"-."};var gj=/&(?:(quot|amp|lt|gt|apos)|#(\d+)|#[xX]([0-9a-fA-F]+));/g;function eL(e){if(!e.includes("&"))return e;const t=e.split("\n");const n=new Map;for(const i of lg(t)){if(i.directive||!i.text.includes("&"))continue;const r=Gw(i.text);const o=Rf(i.text,r).filter(s=>/^(?:click|href)\s/i.test(s.text));for(const s of i.text.matchAll(gj)){const a=s.index;const l=o.some(m=>a>=m.start&&a<m.start+m.text.length);if(!l&&!r.regions.some(m=>a>=m.contentStart&&a+s[0].length<=m.contentEnd))continue;const c=s[1]===void 0?s[2]!==void 0?Number(s[2]):Number.parseInt(s[3],16):void 0;const d=!l&&(c===void 0||c>0&&c<=1114111&&(c<55296||c>57343)&&!bo.test(String.fromCodePoint(c)));const{line:u,col:f}=dj(i,a);const h=n.get(u)??[];h.unshift({col:f,length:s[0].length,code:d?`#${s[1]??c};`:U4(s[0])});n.set(u,h)}}for(const[i,r]of n){let o=t[i];for(const{col:s,length:a,code:l}of r)o=o.slice(0,s)+l+o.slice(s+a);t[i]=o}return t.join("\n")}function vse(e,t=Gw(e)){return t.regions.filter(n=>n.kind==="edge-text").map(n=>({start:n.contentStart,end:n.contentEnd}))}var cg={ui:"ui",pcr:"processor",processor:"processor",cmd:"command",command:"command",rmo:"readmodel",readmodel:"readmodel",evt:"event",event:"event"};var dg="[_a-zA-Z]\\w*(?:\\.[_a-zA-Z]\\w*)*";var yj=new RegExp(`^(tf|timeframe|rf|resetframe)\\s+(\\d{1,3})\\s+(\\w+)\\s+(${dg})`);var iL=new Set(["json","jsobj","figma","salt","uri","md","html","text"]);function tL(e){const t=Object.hasOwn(cg,e)?cg[e]:void 0;if(!t)throw Error(`Unknown Event Modeling type: ${e}`);return t}var xj={command:{allowed:["ui","processor"],target:"command",expected:"ui or processor"},event:{allowed:["command"],target:"event",expected:"command"},readmodel:{allowed:["event"],target:"read model",expected:"event"},processor:{allowed:["readmodel"],target:"processor",expected:"read model"},ui:{allowed:["readmodel"],target:"ui",expected:"read model"}};function Ose(e,t){const n=xj[e];return t.flatMap((i,r)=>i===void 0||n.allowed.includes(i)?[]:[{sourceIndex:r,message:`A ${n.target} can only receive input from a ${n.expected}, not from '${i}'.`}])}function nL(e,t){const n=e.match(/^(?:`(\w+)`\s*)?([\s\S]+)$/);if(!n||n[1]&&!iL.has(n[1]))throw Error("Invalid Event Modeling data type");const i=n[2];if(t?!/^\{\s*\n[\s\S]*\n?\}$/.test(i):!/^(?:\{.*\}|".*"|'.*')$/.test(i))throw Error("Invalid Event Modeling data");return{...n[1]?{type:n[1]}:{},text:i.slice(1,-1).replace(t?/^\n|\n$/g:/$^/g,"")}}function vf(e){const t=e.entity.split(".");const n=t.length>1?t.slice(0,-1).join("."):"";const i=e.type==="event"?"Events":e.type==="command"||e.type==="readmodel"?"Command / Read Model":"UI / Automation";return n?`${n} \xB7 ${i}`:i}function jw(e){const t=[];let n,i;for(const r of e.frames){const o=n!==void 0&&vf(n)===vf(r);const s=o?i:n;const a=[...r.sources];if(!r.reset&&s&&!a.length)a.unshift(s.id);for(const l of a)t.push({id:`relation:${l}:${r.id}`,from:l,to:r.id,explicit:r.sources.includes(l)});if(!o)i=n;n=r}Ve("edges",t.length);return t}function rL(e,t){const n=(Array.isArray(e)?e.join("\n"):e).replace(/\r\n/g,"\n");const i=Hw(n,t!==void 0);const r=i.text.split("\n");const o=[0];if(t){for(let x=0;x<i.text.length;x++)if(i.text[x]==="\n")o.push(x+1)}const s=x=>i.offsets?.[x]??n.length;const a=(x,M,b,C)=>t?.({kind:x,id:M,start:s(b),end:s(Math.max(b,C-1))+1});const l=t?new Map:void 0;const c=t?new Set:void 0;const d=zt(n.split("\n"),sL(n,i.protectedSpans));const u={kind:"eventmodeling",frames:[],entities:[],data:Object.create(null),notes:[],specifications:[],...Ar(Yo(d.accessibility))};const f=pr(n);if(f){const x=$s(f.yaml);if(!x.ok)throw Error(x.message);if(x.value&&typeof x.value==="object"&&"title"in x.value&&typeof x.value.title==="string")u.title=x.value.title}const h=new Set;let m=r.findIndex(x=>x.trim()==="eventmodeling");if(m<0)throw Error("Expected eventmodeling header");let p,g="given",y=0,w=-1,S=false;for(m++;m<r.length;m++){let x=r[m].trim();const M=t?o[m]+r[m].indexOf(x):0;if(!x||x.startsWith("%%")||x.startsWith("//"))continue;Ge("eventmodeling","statement",x,{line:m+1,unit:"normalized"});if(x.startsWith("title ")){if(t)a("labels","title",M,M+x.length);u.title=So(x.slice(6));continue}if(x.startsWith("accTitle:")){u.accessibilityTitle=x.slice(9).trim();continue}if(x.startsWith("accDescr:")){u.accessibilityDescription=x.slice(9).trim();continue}if(x.startsWith("accDescr {")){const k=[x.slice(10)];while(!k[k.length-1].includes("}")&&++m<r.length)k.push(r[m]);if(!k[k.length-1].includes("}"))throw Error("Unclosed accessibility description");u.accessibilityDescription=k.join("\n").replace(/}\s*$/,"").trim();continue}const b=x.match(yj);if(b){if(h.has(b[2])){const A=i.offsets??Hw(n,true).offsets;const R=r.slice(0,m).reduce((L,$)=>L+$.length+1,0)+r[m].indexOf(x);const I=Rs(Lr(n),A[R]??n.length);throw Error(`Duplicate event modeling frame ID "${b[2]}" on line ${I.line}`)}h.add(b[2]);p=void 0;let k=x.slice(b[0].length).trim();const v=[];while(k.startsWith("->>")){const A=k.match(/^->>\s*(\d{1,3})(?=\s|$)/);if(!A)throw Error("Invalid frame reference");v.push(A[1]);if(t){const R=`relation:${A[1]}:${b[2]}`;const I=M+x.length-k.length;a("edges",R,I,I+A[0].length);c.add(R)}k=k.slice(A[0].length).trim()}const T=k.match(/^\[\[(\w+)\]\]/);if(T)k=k.slice(T[0].length).trim();if(t){const A=M+b[0].indexOf(b[2]);a("nodes",b[2],A,M+x.length);l.set(b[2],[A,M+x.length]);const R=M+b[0].lastIndexOf(b[4]);a("labels",`node:${b[2]}`,R,R+b[4].length)}u.frames.push({id:b[2],reset:b[1]==="rf"||b[1]==="resetframe",type:tL(b[3]),entity:b[4],sources:v,...T?{dataReference:T[1]}:{},...k?{data:nL(k,false)}:{}});if(re("eventmodeling"))he("eventmodeling","append-frame",u.frames.at(-1));Ve("nodes",u.frames.length);continue}const C=x.match(new RegExp(`^entity\\s+(${dg})$`));if(C){u.entities.push(C[1]);p=void 0;continue}const P=x.match(/^(data\s+([_a-zA-Z]\w*)|note\s+(\d{1,3}))(?:\s+([\s\S]+))?$/);if(P){p=void 0;let k=P[4]??"";while(!k.includes("{")){if(++m>=r.length)throw Error("Unclosed Event Modeling data block");k+=(k?"\n":"")+r[m].trim()}const v=[k];while(!/^}\s*$/.test(r[++m]??"")){if(m>=r.length)throw Error("Unclosed Event Modeling data block");v.push(r[m])}v.push("}");const T=nL(v.join("\n"),true);if(P[2]){if(Object.hasOwn(u.data,P[2]))throw Error(`Duplicate data: ${P[2]}`);u.data[P[2]]=T}else u.notes.push({frame:P[3],data:T});if(t)a("labels",P[2]?`data:${P[2]}`:`note:${P[3]}:${u.notes.length-1}`,M,o[m]+r[m].length);continue}const E=x.match(/^gwt\s+(\d{1,3})\s*(.*)$/);if(E){g="given";w=-1;S=false;y=M;p={frame:E[1],given:[],when:[],then:[]};u.specifications.push(p);if(t)a("labels",`gwt:${E[1]}:${u.specifications.length-1}`,M,M+x.length);x=E[2]}if(p){const k=x.split(/\s+/).filter(Boolean);while(k.length){const v=k.shift();if(v==="given"||v==="when"||v==="then"){const A=["given","when","then"].indexOf(v);if(t&&(A<=w||w<0&&A!==0||w>=0&&!S))a("labels","unsupported-gwt",y,M+x.length);w=A;S=false;g=v;continue}if(t&&w<0)a("labels","unsupported-gwt",y,M+x.length);const T=k.shift();if(!T||!/^[_a-zA-Z]\w*$/.test(T))throw Error("Invalid specification entity");p[g].push({type:tL(v),entity:T});S=true}if(t)a("labels",`gwt:${p.frame}:${u.specifications.length-1}`,y,M+x.length);continue}throw Error(`Unsupported Event Modeling statement: ${x}`)}wj(u);if(t)for(const x of jw(u)){const M=l.get(x.to);if(!c.has(x.id))a("edges",x.id,M[0],M[1])}return u}var bj=new Set(["eventmodeling","rmo","readmodel","ui","cmd","command","evt","event","pcr","processor","json","jsobj","figma","salt","uri","md","html","text","tf","timeframe","rf","resetframe","entity","data","note","gwt","given","when","then","title"]);function Sj(e){return[...new Set([...e.frames.map(t=>t.entity),...e.entities,...Object.keys(e.data),...e.specifications.flatMap(t=>[...t.given,...t.when,...t.then].map(n=>n.entity))].filter(t=>t.split(".").some(n=>bj.has(n))))]}function wj(e,t=false){if(t&&Sj(e).length)throw Error("Event Modeling identifiers cannot use reserved Mermaid grammar keywords");const n=new Set;for(const o of[e.title,e.accessibilityTitle,e.accessibilityDescription])if(o!==void 0&&typeof o!=="string")throw Error("Metadata must be text");const i=(o,s)=>{if(!o||typeof o!=="object"||Array.isArray(o)||Object.keys(o).some(a=>!s.includes(a)))throw Error("Unknown or malformed Event Modeling record field")};const r=o=>{i(o,["text","type"]);if(!o||typeof o.text!=="string"||o.type!==void 0&&!iL.has(o.type))throw Error("Invalid data record")};for(const o of e.entities)if(typeof o!=="string"||!new RegExp(`^${dg}$`).test(o))throw Error("Invalid entity declaration");if(new Set(e.entities).size!==e.entities.length)throw Error("Duplicate entity declaration");for(const[o,s]of Object.entries(e.data)){if(!/^[_a-zA-Z]\w*$/.test(o))throw Error("Invalid data identifier");r(s)}for(const o of e.notes){i(o,["frame","data"]);r(o.data)}for(const o of e.frames){i(o,["id","reset","type","entity","sources","dataReference","data"]);if(typeof o.id!=="string"||!/^\d{1,3}$/.test(o.id)||n.has(o.id))throw Error(`Duplicate or invalid frame ID: ${o.id}`);n.add(o.id);if(typeof o.reset!=="boolean"||!Array.isArray(o.sources)||!o.sources.every(s=>typeof s==="string"))throw Error("Invalid frame record");if(o.data)r(o.data);if(typeof o.entity!=="string"||!new RegExp(`^${dg}$`).test(o.entity)||!Object.values(cg).includes(o.type))throw Error("Invalid frame entity or type")}for(const o of e.frames){for(const s of o.sources)if(!n.has(s)||s===o.id)throw Error(`Invalid source frame: ${s}`);if(new Set(o.sources).size!==o.sources.length)throw Error("Duplicate frame relation");if(o.dataReference!==void 0&&(typeof o.dataReference!=="string"||!/^[_a-zA-Z]\w*$/.test(o.dataReference)))throw Error("Invalid data reference");if(o.dataReference&&!Object.hasOwn(e.data,o.dataReference))throw Error(`Unknown data: ${o.dataReference}`)}for(const o of e.notes)if(!n.has(o.frame))throw Error(`Unknown note frame: ${o.frame}`);for(const o of e.specifications){i(o,["frame","given","when","then"]);if(!Array.isArray(o.given)||!Array.isArray(o.when)||!Array.isArray(o.then))throw Error("Invalid specification statements");if(!n.has(o.frame)||!o.given.length||!o.then.length)throw Error("Invalid Given/When/Then specification");for(const s of[...o.given,...o.when,...o.then]){i(s,["type","entity"]);if(!Object.values(cg).includes(s.type)||typeof s.entity!=="string"||!/^[_a-zA-Z]\w*$/.test(s.entity))throw Error("Invalid specification type or entity")}}}function Hw(e,t){const n=[];let i="";const r=t?[]:void 0;const o=(l,c)=>{i+=l;if(r)for(let d=0;d<l.length;d++)r.push(c+d)};let s=e.indexOf("\n");if(s<0)s=e.length;let a=true;for(let l=0;l<e.length;l++){const c=e[l],d=e[l+1];if(l>s){a=!i.slice(i.lastIndexOf("\n")+1).trim();const f=e.indexOf("\n",l);s=f<0?e.length:f}const u=a;a&&=/\s/.test(c);if(u&&(c==="t"||c==="a")&&/^(?:title(?:[ \t]|$)|accTitle[ \t]*:|accDescr[ \t]*:)/.test(e.slice(l,s))){const f=e.indexOf("%%",l);o(e.slice(l,f>=0&&f<s?f:s),l);l=s-1;continue}if(c==="/"&&d==="*"){const f=e.indexOf("*/",l+2);if(f<0)throw Error("Unclosed Event Modeling comment");n.push([l,f+2]);const h=e.slice(l,f+2);o(h.replace(/[^\n]/g," "),l);a=u||h.includes("\n");l=f+1;continue}if(c==="%"&&d==="%"||c==="/"&&d==="/"){l=s-1;continue}if(c==="{"){if(!e.slice(l+1,s).trim()&&s<e.length){const h=/^}[ \t]*(?=\n|$)/gm;h.lastIndex=s+1;const m=h.exec(e);if(!m)throw Error("Unclosed Event Modeling block");n.push([l,m.index+m[0].length]);o(e.slice(l,m.index+m[0].length),l);l=m.index+m[0].length-1;continue}const f=e.lastIndexOf("}",s-1);if(f<l)throw Error("Unclosed inline data");o(e.slice(l,f+1),l);l=f;continue}if(c==='"'||c==="'"||c==="`"){const f=c==="`"?e.indexOf(c,l+1):e.lastIndexOf(c,s-1);if(f<=l||f>=s)throw Error("Unclosed inline value");o(e.slice(l,f+1),l);l=f;continue}if(/\s/.test(e[l-1]??"")&&/[tredng]/.test(c)&&/^(?:tf|timeframe|rf|resetframe|entity|data|note|gwt)\s/.test(e.slice(l))){const f=i.slice(i.lastIndexOf("\n")+1);if(f.trim()){i=i.trimEnd();if(r)r.length=i.length;o("\n",l)}}o(c,l)}return{text:i,offsets:r,protectedSpans:n}}function oL(e){const t=e.join("\n");try{return sL(t,Hw(t,false).protectedSpans)}catch{return e.map((n,i)=>i)}}function sL(e,t){const n=Lr(e);const i=n.map((r,o)=>o);for(const[r,o]of t){const s=Rs(n,r).line-1;const a=Rs(n,Math.max(r,o-1)).line-1;i[s]=Math.max(i[s],a)}return i}function aL(e){const t=new Map;for(const n of e.frames){const i=vf(n);const r=t.get(i)??{id:`lane:${t.size}`,label:i,members:[]};r.members.push(n.id);t.set(i,r)}return[...t.values()]}var ug=["$end","INVALID","BLOCK_DIAGRAM_KEY","id-block","COLUMNS","MD_STR","STR","SPACE_BLOCK","DEFAULT","LINKSTYLE","INTERPOLATE","classDef","DEFAULT_CLASSDEF_ID","CLASSDEF_ID","CLASSDEF_STYLEOPTS","class","CLASSENTITY_IDS","STYLECLASS","style","STYLE_ENTITY_IDS","STYLE_DEFINITION_DATA","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","end","NODE_DSTART","NODE_DEND","BLOCK_ARROW_START","BLOCK_ARROW_END","DIR","NODE_ID","LINK","START_LINK","LINK_LABEL","SIZE","EOF"];function fg(e){if(e<128)return e===32||e>=9&&e<=13;return e===160||e===5760||e>=8192&&e<=8202||e===8232||e===8233||e===8239||e===8287||e===12288||e===65279}function Pd(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===95}var kj=["right","left","x","y","up","down"];var lL=new Uint8Array(128);for(const e of[9,10,11,12,13,32,40,41,45,58,60,61,62,91,123,125])lL[e]=1;function Yw(e,t){const n=e.length;const i=[];const r=[];const o=[];const s=[];let a=0;let l=0;const c=(k,v,T)=>{i.push(k);r.push(v);o.push(l);l=T;return true};const d=(k,v)=>c(k,e.slice(l,v),v);const u=k=>{s.push(a);a=k};const f=()=>{if(s.length>0)a=s.pop()};const h=k=>{while(k<n&&fg(e.charCodeAt(k)))k++;return k};const m=k=>{while(k<n){const v=e.charCodeAt(k);if(v<48||v>57)break;k++}return k};const p=k=>{while(k<n&&Pd(e.charCodeAt(k)))k++;return k};const g=k=>e.startsWith(k,l)&&!Pd(e.charCodeAt(l+k.length));const y=()=>{if(e.charCodeAt(l+1)===96){u(2);l+=2}else{u(1);l++}return true};const w=k=>{if(e.charCodeAt(k)!==46)return-1;do k++;while(e.charCodeAt(k)===46);if(e.charCodeAt(k)!==45)return-1;const v=e.charCodeAt(k+1);return v===120||v===111||v===62?k+2:k+1};const S=k=>{const v=e.charCodeAt(k);if(v===120||v===111||v===60)k++;const T=e.charCodeAt(k);if(T===46)return w(k);if(T!==45&&T!==61)return-1;let A=k+1;while(e.charCodeAt(A)===T)A++;if(A-k===1)return T===45?w(A):-1;const R=e.charCodeAt(A);if(R===120||R===111||R===62)return A+1;return A-k>=3?A:-1};const x=()=>{const k=S(l);if(k>=0)return d(33,h(k));const v=e.charCodeAt(l)===60?l+1:l;const T=e.charCodeAt(v);const A=e.charCodeAt(v+1);if(T===45&&(A===45||A===46)||T===61&&A===61){u(6);return d(34,h(v+2))}return false};const M=k=>{let v=e.indexOf("\n",l);if(v===-1)v=n;f();return d(k,v)};const b=(k,v)=>{let T=p(l);if(T===l)return false;while(e.charCodeAt(T)===44){const A=h(T+1);const R=p(A);if(R===A)break;T=R}a=v;return d(k,T)};const C=k=>{if(k===37&&e.charCodeAt(l+1)===37){const T=e.indexOf("\n",l+2);t?.(l,T<0?n:T);l=T<0?n:T;return true}if(fg(k)){l=h(l+1);return true}let v;switch(k){case 98:if(e.startsWith("block",l)){if(g("block-beta"))return d(2,l+10);if(e.charCodeAt(l+5)===58)return d(3,l+6);if(!Pd(e.charCodeAt(l+5)))return d(2,l+5)}break;case 99:if(e.startsWith("columns",l)){v=h(l+7);if(v>l+7){if(e.startsWith("auto",v)&&!Pd(e.charCodeAt(v+4)))return c(4,"-1",v+4);const T=m(v);if(T>v)return c(4,e.slice(v,T),T)}}else if(e.startsWith("class",l)){const T=e.startsWith("Def",l+5);const A=T?l+8:l+5;v=h(A);if(v>A){u(T?7:9);return d(T?11:15,v)}}break;case 34:return y();case 115:if(e.startsWith("space",l)){if(e.charCodeAt(l+5)===58){const T=m(l+6);if(T>l+6)return c(7,e.slice(l+6,T),T)}if(!Pd(e.charCodeAt(l+5)))return c(7,"1",l+5)}else if(e.startsWith("style",l)){v=h(l+5);if(v>l+5){u(11);return d(18,v)}}break;case 100:if(g("default"))return d(8,l+7);break;case 108:if(g("linkStyle"))return d(9,l+9);break;case 105:if(g("interpolate"))return d(10,l+11);break;case 97:if(e.startsWith("accTitle",l)){v=h(l+8);if(e.charCodeAt(v)===58){u(13);return d(21,h(v+1))}}else if(e.startsWith("accDescr",l)){v=h(l+8);const T=e.charCodeAt(v);if(T===58){u(14);return d(23,h(v+1))}if(T===123){u(15);l=h(v+1);return true}}break;case 101:if(g("end"))return d(26,h(l+3));break;case 45:if(e.charCodeAt(l+1)===41){u(3);return d(27,l+2)}return x();case 61:return x();case 60:if(e.charCodeAt(l+1)===91){u(4);return d(29,l+2)}return x();case 40:{const T=e.charCodeAt(l+1);const A=T===45||T===91?2:T===40?e.charCodeAt(l+2)===40?3:2:1;u(3);return d(27,l+A)}case 41:case 123:u(3);return d(27,e.charCodeAt(l+1)===k?l+2:l+1);case 62:u(3);return d(27,l+1);case 91:{const T=e.charCodeAt(l+1);u(3);return d(27,T===91||T===124||T===40||T===92||T===47?l+2:l+1)}case 58:{const T=m(l+1);if(T>l+1)return c(36,e.slice(l+1,T),T);return false}}v=l;while(v<n){const T=e.charCodeAt(v);if(T<128?lL[T]===1:fg(T))break;v++}return v>l&&d(32,v)};const P=k=>{const v=e.charCodeAt(l+1);let T=0;switch(k){case 34:return y();case 40:T=v===45?2:v===40?e.charCodeAt(l+2)===40?3:2:1;break;case 41:T=v===41?e.charCodeAt(l+2)===41?3:2:v===93?2:1;break;case 125:T=v===125?2:1;break;case 45:T=v===41?2:0;break;case 93:T=v===93||v===41||v===62?2:1;break;case 92:case 47:T=v===93?2:0;break}if(T===0)return false;f();return d(28,l+T)};const E=k=>{if(k===41){f();f();return c(30,"]>",h(l+1))}const v=h(k===44?l+1:l);for(const T of kj){if(e.startsWith(T,v)){const A=h(v+T.length);return c(31,e.slice(k===44?v:l,A),A)}}return false};while(true){if(l>=n){let T=-1;switch(a){case 0:T=37;break;case 1:T=6;break;case 8:T=14;break;case 10:T=17;break;case 12:T=20;break;case 13:T=22;break;case 14:T=24;break;case 15:T=25;break}l=n;if(T!==-1)c(T,"",n);break}const k=e.charCodeAt(l);let v=true;switch(a){case 0:v=C(k);break;case 1:if(k===34){f();l++}else{const T=e.indexOf('"',l);d(6,T===-1?n:T)}break;case 2:if(k===96){v=e.charCodeAt(l+1)===34;if(v){f();l+=2}}else if(k===34){v=false}else{let T=l+1;while(T<n){const A=e.charCodeAt(T);if(A===96||A===34)break;T++}d(5,T)}break;case 3:v=P(k);break;case 4:if(k===34){y()}else if(k===93&&e.charCodeAt(l+1)===62){const T=h(l+2);v=e.charCodeAt(T)===40;if(v){u(5);l=T+1}}else{v=false}break;case 5:v=E(k);break;case 6:if(k===34){if(e.charCodeAt(l+1)===96){y()}else{d(35,l+1);u(1)}}else{const T=S(h(l));v=T>=0;if(v){f();d(33,h(T))}}break;case 7:{let T=12;let A=e.startsWith("DEFAULT",l)?l+7:l;let R=h(A);if(A===l||R===A){T=13;A=p(l);R=h(A)}v=A>l&&R>A;if(v){a=8;d(T,R)}break}case 8:M(14);break;case 9:v=b(16,10);break;case 10:M(17);break;case 11:v=b(19,12);break;case 12:M(20);break;case 13:M(22);break;case 14:M(24);break;case 15:if(k===125){f();l++}else{const T=e.indexOf("}",l);d(25,T===-1?n:T)}break}if(!v){i.push(1);r.push("");o.push(l);return{types:i,texts:r,starts:o}}}i.push(0);r.push("");o.push(n);return{types:i,texts:r,starts:o}}var Ed=["$end","INVALID","title","acc_title","acc_title_value","acc_descr","acc_descr_value","acc_descr_multiline_value","direction_tb","direction_bt","direction_rl","direction_lr","NEWLINE","EOF","RD","STRUCT_START","STRUCT_STOP","STYLE_SEPARATOR","COLONSEP","ID","TEXT","RISK","VERIFYMTHD","REQUIREMENT","FUNCTIONAL_REQUIREMENT","INTERFACE_REQUIREMENT","PERFORMANCE_REQUIREMENT","PHYSICAL_REQUIREMENT","DESIGN_CONSTRAINT","LOW_RISK","MED_RISK","HIGH_RISK","VERIFY_ANALYSIS","VERIFY_DEMONSTRATION","VERIFY_INSPECTION","VERIFY_TEST","ELEMENT","CONTAINS","COPIES","DERIVES","SATISFIES","VERIFIES","REFINES","TRACES","TYPE","DOCREF","STYLE","CLASSDEF","CLASS","ALPHA","COLON","SEMICOLON","PERCENT","MINUS","BRKT","END_ARROW_L","END_ARROW_R","LINE","qString","unqString","COMMA"];var cL=new Map([["requirementdiagram",14],["id",19],["text",20],["risk",21],["verifymethod",22],["requirement",23],["functionalrequirement",24],["interfacerequirement",25],["performancerequirement",26],["physicalrequirement",27],["designconstraint",28],["low",29],["medium",30],["high",31],["analysis",32],["demonstration",33],["inspection",34],["test",35],["element",36],["contains",37],["copies",38],["derives",39],["satisfies",40],["verifies",41],["refines",42],["traces",43],["type",44],["docref",45],["style",46],["classdef",47],["class",48]]);function Tf(e){if(e<128)return e===32||e>=9&&e<=13;return e===160||e===5760||e>=8192&&e<=8202||e===8232||e===8233||e===8239||e===8287||e===12288||e===65279}function Lf(e){return e===10||e===13||e===8232||e===8233}function Rd(e){return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===95}function Kse(e){for(let t=0;t<e.length;t++){const n=e.charCodeAt(t);if(Rd(n))continue;switch(n){case 32:case 35:case 44:case 45:case 58:case 59:continue;default:return false}}return true}var Pj=/accTitle\s*:\s*/iy;var Ej=/accDescr\s*:\s*/iy;var Rj=/accDescr\s*\{\s*/iy;var hg=/direction\s+(?:(TB)|(BT)|(RL)|LR)/gi;var qw=/[\n\r\u2028\u2029]/g;var vj=22;var dL=new Uint8Array(128);for(const e of":,\r\n{<>-=")dL[e.charCodeAt(0)]=1;function Xw(e,t){const n=e.length;const i=[];const r=[];const o=[];const s=[];let a=0;let l=false;let c=0;const d=[[],[],[],[]];const u=[[],[],[],[]];const f=[0,0,0,0];let h=false;let m=-1;hg.lastIndex=0;for(let P=hg.exec(e);P!==null;P=hg.exec(e)){const E=P[1]!==void 0?0:P[2]!==void 0?1:P[3]!==void 0?2:3;d[E].push(P.index);u[E].push(hg.lastIndex);h=true}const p=(P,E,k)=>{i.push(P);r.push(e.slice(E,k));o.push(E);c=k};const g=P=>{s.push(a);a=P};const y=()=>{if(s.length>0)a=s.pop()};const w=(P,E)=>{P.lastIndex=E;return P.test(e)?P.lastIndex:-1};const S=P=>{const E=Fl(e,P);return E===-1?n:E};const x=()=>{if(m<c){qw.lastIndex=c;m=qw.test(e)?qw.lastIndex-1:n;for(let P=0;P<4;P++){const E=d[P];let k=f[P];while(k<E.length&&E[k]<=m)k++;f[P]=k}}for(let P=0;P<4;P++){const E=f[P]-1;if(E>=0&&d[P][E]>=c){p(8+P,c,S(u[P][E]));return true}}return false};const M=P=>{const E=P|32;if(E===116&&e.slice(c+1,c+5).toLowerCase()==="itle"&&Tf(e.charCodeAt(c+5))){let k=c+6;while(k<n){const v=e.charCodeAt(k);if(v===35||v===10||v===13||v===59)break;k++}if(k>c+6){p(2,c,k);return true}}if(E===97&&(e.charCodeAt(c+1)|32)===99&&(e.charCodeAt(c+2)|32)===99){let k;if((k=w(Pj,c))>=0){g(3);p(3,c,k);return true}if((k=w(Ej,c))>=0){g(4);p(5,c,k);return true}if((k=w(Rj,c))>=0){g(5);c=k;return true}}if(h&&!Lf(P)&&x())return true;if(P===10||P===13){let k=c;while(k<n){const v=e.charCodeAt(k);if(v===10)k++;else if(v===13)k+=e.charCodeAt(k+1)===10?2:1;else break}p(12,c,k);return true}if(Tf(P)){c++;while(c<n&&Tf(e.charCodeAt(c))&&!Lf(e.charCodeAt(c)))c++;return true}if(P===35||P===37){if(e.startsWith("%%",c))t?.(c,S(c));c=S(c);return true}if(Rd(P)){let k=c+1;while(k<n&&Rd(e.charCodeAt(k)))k++;if(k-c<=vj){const v=cL.get(e.slice(c,k).toLowerCase());if(v!==void 0){if(v===46||v===47||v===48){l=false;g(2)}p(v,c,k);return true}}while(k<n){const v=e.charCodeAt(k);if(v<128&&dL[v]===1)break;k++}i.push(59);r.push(e.slice(c,k).trim());o.push(c);c=k;return true}switch(P){case 123:p(15,c,c+1);return true;case 125:p(16,c,c+1);return true;case 58:if(e.charCodeAt(c+1)===58&&e.charCodeAt(c+2)===58)p(17,c,c+3);else p(18,c,c+1);return true;case 60:if(e.charCodeAt(c+1)!==45)return false;p(55,c,c+2);return true;case 45:if(e.charCodeAt(c+1)===62)p(56,c,c+2);else p(57,c,c+1);return true;case 34:g(1);c++;return true;case 44:p(60,c,c+1);return true}return false};const b=P=>{if(Rd(P)){let E=c+1;while(E<n&&Rd(e.charCodeAt(E)))E++;let k=E;while(k<n&&Tf(e.charCodeAt(k))&&!Lf(e.charCodeAt(k)))k++;if(l&&e.charCodeAt(k)===40){E=k;let v=0;while(E<n){const T=e.charCodeAt(E);if(Lf(T)||v===0&&(T===44||T===59))break;if(T===40)v++;else if(T===41)v=Math.max(0,v-1);E++}}p(49,c,E);return true}switch(P){case 58:l=true;p(50,c,c+1);return true;case 59:l=false;p(51,c,c+1);return true;case 37:p(52,c,c+1);return true;case 45:p(53,c,c+1);return true;case 35:p(54,c,c+1);return true;case 32:c++;return true;case 34:g(1);c++;return true;case 10:y();c++;return true;case 13:y();c+=e.charCodeAt(c+1)===10?2:1;return true;case 44:l=false;p(60,c,c+1);return true}return false};while(c<n){const P=e.charCodeAt(c);let E=true;switch(a){case 0:E=M(P);break;case 2:E=b(P);break;case 1:if(P===34){y();c++}else{const k=e.indexOf('"',c);p(58,c,k===-1?n:k)}break;case 3:y();p(4,c,S(c));break;case 4:y();p(6,c,S(c));break;case 5:if(P===125){y();c++}else{const k=e.indexOf("}",c);p(7,c,k===-1?n:k)}break}if(!E){i.push(1);r.push("");o.push(c);return{types:i,texts:r,starts:o}}}const C=a===0?13:a===1?58:a===3?4:a===4?6:a===5?7:-1;if(C!==-1)p(C,n,n);p(0,n,n);return{types:i,texts:r,starts:o}}function uL(e){const t=e.map((r,o)=>o);if(!e.length)return t;const n=["requirementDiagram",...e.slice(1)].join("\n");const i=[0];for(let r=0;r<n.length;r++)if(n[r]==="\n")i.push(r+1);try{const r=Xw(n);let o=0;for(let s=0;s<r.types.length;s++){if(r.types[s]!==58)continue;const a=r.starts[s],l=a+r.texts[s].length;while(o+1<i.length&&i[o+1]<=a)o++;let c=o;while(c+1<i.length&&i[c+1]<=l)c++;t[o]=Math.max(t[o],c);o=c}}catch{}return t}var Tj=/(\(\(|\{\{|\(-|-\)|\)\)|\[|\(|\))/;var Lj={"[":"]","(":")","((":"))","{{":"}}",")":"(","))":"((","(-":"-)","-)":"(-"};function Aj(e){return e?rn(gr(String(e))):void 0}function Ij(e,t){let n,i=0;const r=wa(e,1,"flowchart",(u,f,h)=>{const m=u-2+i;(n??=[]).push({start:m,end:m+h,sourceStart:u-2,sourceEnd:f-2});i+=h-(f-u)});if(r.kind!=="closed")return[];const o=[];const s=Cw(r.body);const a=s.text.includes("\n"),l=a?0:2;const c=a?`${s.text}
19
+ `:`{
20
+ ${s.text}
21
+ }`;const d=u=>{const f=s.sourceOffset(Math.max(0,Math.min(s.text.length,u-l)));let h=0,m=n?.length??0;while(h<m){const g=h+m>>>1;if(n[g].start<=f)h=g+1;else m=g}const p=n?.[h-1];return t+2+(p?f<p.end?p.sourceStart:f-p.end+p.sourceEnd:f)};for(const u of oS(c)){o.push({name:s.restore(u.name),keyStart:d(u.keyStart),keyEnd:d(u.keyEnd),valueStart:d(u.valueStart),valueEnd:d(u.valueEnd)})}return o}function Uw(e,t={},n,i){const r=typeof e==="string"?e:e.join("\n");const o=n?/\r|\n/g:/\r\n?|\n/g;const s=r.split(o);const a=r.match(o)??[];let l=2,c=0;while(s.length&&(!s[0].trim()||s[0].trim().startsWith("%%"))){c+=s[0].length+(a[0]?.length??0);s.shift();a.shift();l++}const d=c,u=s.shift()??"";c+=u.length+(a[0]?.length??0);const f=(b,C,P)=>{if(!i)return;const E=Kr(b);if(E>=0)i(b.slice(E+2).trim(),C,{start:P+E+2,end:P+b.length})};f(u,l-1,d);a.shift();let h=c;const m=re("kanban")||i?s.map((b,C)=>{const P=h;h+=b.length+(a[C]?.length??0);return P}):void 0;Ge("kanban","header",u,{line:l-1,unit:"normalized"});if(!/^kanban\s*$/i.test(Ht(u).trim()))throw Je({what:"Invalid Kanban header",expectedForm:"kanban",example:"kanban\nTodo\n task[Write documentation]"});const p={kind:"kanban",columns:[],accessibilityTitle:t.title,accessibilityDescription:t.descr};const g=new Set,y=new Map;let w,S,x;const M=(b,C)=>{if(!n)return`line ${l+b}, column ${C+1}`;const P=n.originalText.split(/\r\n?|\n/);let E=(n.wrapperSource?.match(/\r\n?|\n/g)?.length??0)+1;for(let k=0;k<=b;k++){const v=s[k].trim();while(E<P.length&&P[E].trim()!==v)E++;if(E>=P.length)break;if(k===b){const T=P[E].length-P[E].trimStart().length,A=s[k].length-s[k].trimStart().length;return`line ${E+1}, column ${C+T-A+1}`}E++}return`line ${l+b}, column ${C+1}`};for(let b=0;b<s.length;b++){let C=s[b],P=0,E=C.trim();if(!E||E.startsWith("%%"))continue;const k=vt(s,b);if(k){if(k.title&&t.title===void 0)p.accessibilityTitle=k.value;else if(!k.title&&t.descr===void 0)p.accessibilityDescription=k.value;b=k.endIndex;if(!k.suffixLine)continue;C=k.suffixLine;P=s[b].length-C.length;E=C.trim()}const v=b;const T=C.length-C.trimStart().length;const A=(G,Y,q,V=v)=>Je({what:`Kanban syntax at ${M(V,Y)}: ${G}`,expectedForm:q,example:"task[Work]@{ assigned: Alice }"});if(E.startsWith(":::")||E.startsWith("::icon(")){if(!x)throw A("Kanban decoration has no preceding item",T,"a column or task before its decoration");if(E.startsWith(":::")){f(E.slice(3),b+l,(m?.[b]??0)+P+T+3);x.className=Ht(E.slice(3)).trim()}else{const G=/^::icon\(([^)]*)\)\s*(?:%%.*)?$/.exec(E);if(!G)throw A("Invalid Kanban icon decoration",T,"::icon(icon-name)");f(E.slice(E.indexOf(")")+1),b+l,(m?.[b]??0)+P+T+E.indexOf(")")+1);x.icon=G[1].trim()}Ge("kanban",E.startsWith(":::")?"class":"icon",C,{line:b+l,unit:"normalized"});if(re("kanban"))he("kanban",E.startsWith(":::")?"set-class":"set-icon",{id:x.id,sourceId:x.sourceId,value:E.startsWith(":::")?x.className:x.icon});continue}let R="",I="",L=false,$=T,B="";const F=E.indexOf("@{"),z=Tj.exec(F<0?E:E.slice(0,F));if(z){R=E.slice(0,z.index).trim();L=!R;const G=z[0],Y=Lj[G];let q=E.slice(z.index+G.length),V;if(q.startsWith('"')){const ne=q.startsWith('"`'),X=ne?'`"':'"';const U=ne?2:1;$=T+z.index+G.length+U;while(q.indexOf(X,U)<0&&b+1<s.length)q+=(a[b]==="\r"?"\r":"\n")+s[++b];const K=q.indexOf(X,U);if(K<0)throw A("Unclosed Kanban quoted label",T+z.index+G.length,`closing ${X}${Y}`);I=q.slice(U,K);V=K+X.length;if(!q.slice(V).startsWith(Y))throw A("Unclosed Kanban label",T+z.index,`closing ${Y}`);V+=Y.length}else{$=T+z.index+G.length;while(!q.includes(Y)&&b+1<s.length)q+=(a[b]==="\r"?"\r":"\n")+s[++b];const ne=q.indexOf(Y);if(ne<0)throw A("Unclosed Kanban label",T+z.index,`closing ${Y}`);I=q.slice(0,ne);V=ne+Y.length}B=q.slice(V).trim();if(L)R=I}else{const G=F<0?E:E.slice(0,F);f(G,b+l,(m?.[b]??0)+P+T);const Y=Ht(G).trim();R=I=Y;B=F<0?"":E.slice(F)}if(!R||!I)throw A("Empty Kanban item",T,"a column or card with a non-empty label");const _=I;let H={};let D;if(B.startsWith("@{")){const G=s.slice(v,b+1).join("\n"),Y=G.lastIndexOf(B);let q=B,V=ec(q,1,"flowchart");while(!V.ok&&V.unclosed&&b+1<s.length){q+="\n"+s[++b];V=ec(q,1,"flowchart")}if(!V.ok){const ne=G.slice(0,Y),X=ne.split("\n").length-1,U=Y-(ne.lastIndexOf("\n")+1);throw A(`Invalid Kanban metadata (${V.message})`,U,"a closed @{ key: value } metadata mapping",v+X)}H=Object.fromEntries(V.entries);if(re("kanban"))D=Ij(q,Y);B=q.slice(V.end+1).trim();if(H.shape&&(typeof H.shape!=="string"||H.shape!==H.shape.toLowerCase()||H.shape.includes("_")))throw A("Invalid Kanban metadata shape",T,"a lowercase shape without underscores");if(H.label)I=String(H.label)}if(Ht(B).trim())throw A(`Unexpected Kanban suffix: ${B}`,T,"a node followed by optional @{ metadata }");const j=i?s[b].length-s[b].trimEnd().length:0;f(B,b+l,(m?.[b]??0)+s[b].length-j-B.length);if(re("kanban"))Ge("kanban","node",s.slice(v,b+1).join("\n"),{line:v+l,offset:m[v],endOffset:m[b]+s[b].length,unit:"normalized"});R=rn(R);I=Aj(H.label)??rn(I);const W=y.get(R)??0;y.set(R,W+1);let O=W?`${R}#${W+1}`:R;while(g.has(O))O+="#";g.add(O);const N={id:O,sourceId:R,...L?{implicitId:true}:{},label:I,metadata:H,...H.icon?{icon:String(H.icon)}:{}};w??=T;if(T<w)throw A(`Items without section detected, found section ("${I}")`,T,"columns at the first column indentation and cards indented beneath them");if(T===w){S={...N,tasks:[]};p.columns.push(S);x=S;if(re("kanban"))he("kanban","add-column",{...N,indent:T,declaredStart:P+T,declaredLabel:_,declaredLabelStart:P+$,...D?{metadataSpans:D}:{}})}else{if(!S)throw new Error("Kanban card has no column");S.tasks.push(N);x=N;if(re("kanban"))he("kanban","add-task",{...N,indent:T,declaredStart:P+T,declaredLabel:_,declaredLabelStart:P+$,parentId:S.sourceId,...D?{metadataSpans:D}:{}})}Ve("nodes",g.size)}return p}function fL(e){const t=e.map((n,i)=>i);try{oP("kanban",n=>{if(n.unit!=="statement"||n.kind!=="node"||!n.source?.line||n.text===void 0)return;const i=n.source.line-1;t[i]=Math.min(e.length-1,i+n.text.split("\n").length-1)},()=>Uw(e),{mutations:[]})}catch(n){if(n instanceof Ri)throw n}return t}import{decodeXML as hL}from"entities";var mL=["C4Context","C4Container","C4Component","C4Dynamic","C4Deployment"];var Zw=class extends Ls{};var Fj=/^(Person|System|Container|Component)(Db|Queue)?(_Ext)?$/;var Td={Boundary:"boundary",Enterprise_Boundary:"enterprise",System_Boundary:"system",Container_Boundary:"container",Deployment_Node:"deployment",Node:"deployment",Node_L:"deployment",Node_R:"deployment"};var Vw=new Set(["Rel","BiRel","Rel_U","Rel_Up","Rel_D","Rel_Down","Rel_L","Rel_Left","Rel_R","Rel_Right","Rel_Back","RelIndex"]);var pL={U:"BT",Up:"BT",D:"TB",Down:"TB",L:"RL",Left:"RL",R:"LR",Right:"LR"};var gL=["elementName","bgColor","fontColor","borderColor","shadowing","shape","sprite","techn","legendText","legendSprite"];var yL=["from","to","textColor","lineColor","offsetX","offsetY"];var xL=["tagStereo","bgColor","fontColor","borderColor","shadowing","shape","sprite","techn","legendText","legendSprite"];var bL=["tagStereo","textColor","lineColor","lineStyle","sprite","techn","legendText","legendSprite"];function Nj(e="C4Context"){return{kind:"c4",variant:e,elements:[],boundaries:[],relationships:[],directives:[],statements:[],diagnostics:[],layout:{hints:[]}}}function lo(e,t){if(!re("c4"))return;const{start:n,end:i,line:r,column:o}=e.span;Ge("c4",t,e.raw,{line:r,column:o,offset:n,endOffset:i,unit:"physical"})}function $j(e){const t=[];let n=0,i=1,r=1,o=true;const s=(a,l="unknown")=>{const c=e.slice(n,a);t.push({id:`c4-statement-${t.length+1}`,kind:l,raw:c,span:{start:n,end:a,line:i,column:r}});if(re("c4"))Ho("c4",`chunk:${l}`,c,{line:i,column:r,offset:n,endOffset:a,unit:"physical"});let d=e[n-1];for(const u of c){if(u==="\r"||u==="\n"&&d!=="\r"){i++;r=1}else if(u!=="\n")r++;d=u}n=a};while(n<e.length){const a=n;if(/\s|;/.test(e[a])){let f=a+1;while(f<e.length&&/\s|;/.test(e[f]))f++;s(f,"trivia");continue}if(e.startsWith("%%",a)){const f=Fl(e,a);const h=f<0?e.length:f;const m=!o&&vt([e.slice(a,h)],0)?.form==="native";s(h,m?"accessibility":"trivia");continue}if(o){o=false;const f=Fl(e,a);const h=f<0?e.length:f;let m=h;for(let g=a;g<h;g++){if(e[g]==="&"){const y=/^&(?:#\d+|#x[0-9a-f]+|[a-z][a-z0-9]*);/i.exec(e.slice(g,h));if(y){g+=y[0].length-1;continue}}if(e[g]===";"){m=g;break}}const p=hL(e.slice(a,m)).trim();if(mL.some(g=>g.toLowerCase()===p.toLowerCase())){s(m,"header");continue}}if(e[a]==="}"){s(a+1,"boundary-close");continue}const l=e.slice(a);const c=/^[A-Za-z_][A-Za-z_0-9]*/.exec(l)?.[0];let d=a+(c?.length??0);while(d<e.length&&/[ \t\r\n]/.test(e[d]))d++;if(c&&e[d]==="("){let f=0,h="";for(;d<e.length;d++){const p=e[d];if(h){if(p===h)h=""}else if(p==='"'||p==="'")h=p;else if(p==="(")f++;else if(p===")"&&--f===0){d++;break}}if(f||h)throw new Error(`C4: unclosed ${c} argument list at line ${i}`);let m=d;while(m<e.length&&/\s/.test(e[m]))m++;if(e[m]==="{"){if(Td[c]){s(m+1,"boundary-open");continue}let p=1;h="";d=m+1;for(;d<e.length&&p;d++){const g=e[d];if(h){if(g===h)h=""}else if(g==='"'||g==="'")h=g;else if(g==="%"&&e[d+1]==="%"){const y=Fl(e,d+2);d=y<0?e.length:y}else if(g==="{")p++;else if(g==="}")p--}if(p)throw new Error(`C4: unclosed ${c} block at line ${i}`)}s(d);continue}const u=Fl(e,a);if(/^accDescr[ \t]*:?[ \t]*\{/i.test(l)){const f=e.indexOf("}",a);if(f<0)throw new Error(`C4: unclosed accessibility block at line ${i}`);s(f+1,"accessibility");continue}s(u<0?e.length:u)}return t}function SL(e,t=true){const n=e.trim();if(n.length>=2&&(n[0]==='"'||n[0]==="'")&&n.at(-1)===n[0]){const i=n.slice(1,-1).trim();return t?rn(i):i}return t?rn(n):n}function Wa(e,t,n){let i;for(let o=0;o<e.length;o++)if((e[o].name??t[o])===n)i=e[o];if(!i)return void 0;const r=i.name?i.raw.replace(/^\s*\$[A-Za-z_][A-Za-z_0-9]*\s*=/,""):i.raw;return rn(ws(SL(r,false)))}function _j(e){if(!e.trim())return[];const t=[];let n=0,i=0,r="";for(let o=0;o<e.length;o++){const s=e[o];if(r){if(s===r)r=""}else if(s==='"'||s==="'")r=s;else if(s==="(")i++;else if(s===")")i--;else if(s===","&&i===0){t.push(e.slice(n,o));n=o+1}}t.push(e.slice(n));return t.map(o=>{const s=/^\s*\$([A-Za-z_][A-Za-z_0-9]*)\s*=([\s\S]*)$/.exec(o);return{...s?{name:s[1]}:{},value:SL(s?s[2]:o),raw:o}})}function $f(e,t=[]){return e.length>0&&e.length>=t.length&&e.every((n,i)=>{if(n.name&&(t.includes(n.name)||i<t.length&&t[i]!=="label"))return false;if(n.raw.includes("%%{"))return false;const r=(n.name?n.raw.replace(/^\s*\$[A-Za-z_][A-Za-z_0-9]*\s*=/,""):n.raw).trim();if(n.name)return/^ *\$[A-Za-z_][A-Za-z_0-9]* *= *"[^"]+"$/.test(n.raw);if(r.startsWith('"'))return/^ *"[^"]*"$/.test(n.raw);if(n.raw===""&&i<e.length-1)return true;return i<e.length-1&&r.length>0&&!/^[\$']|[(),\r\n]/.test(r)})}function Dj(e,t,n){if(!e.name&&t<n.length-1&&!/^["'$)]/.test(e.raw.trim())&&!e.raw.includes(","))return false;const i=e.name?e.raw.replace(/^\s*\$[A-Za-z_][A-Za-z_0-9]*\s*=/,""):e.raw;for(const r of i.matchAll(/"[^"]*"|'[^']*'|(\$[A-Za-z_][A-Za-z_0-9]*\s*(?:=|["']))/g))if(r[1])return true;return false}function Vs(e,t){const n=Object.create(null);for(let i=0;i<e.length;i++){const r=e[i];const o=r.name??t[i];if(o!==void 0)n[o]=r.value}return n}function Af(e){return e.startsWith("Person")||e.startsWith("System")?["alias","label","descr","sprite","tags","link"]:["alias","label","techn","descr","sprite","tags","link"]}function If(e){return Td[e]==="deployment"?["alias","label","type","descr","sprite","tags","link"]:e==="Boundary"?["alias","label","type","tags","link"]:["alias","label","tags","link"]}function Ff(e){return e==="RelIndex"?["index","from","to","label","tags","link"]:["from","to","label","techn","descr","sprite","tags","link"]}function Kw(e){return e?e.split("+").map(t=>t.trim()).filter(Boolean):[]}function co(e){return e===""?void 0:e}function vd(e,t,n){const i=e[t];if(i===void 0||t!=="label"&&!i.trim())throw new Error(`C4: ${n} requires ${t==="label"?"a":"a non-empty"} ${t}`);return i}function Jw(e,t,n,i){const r=Wa(e,t,"label");if(r!==void 0)return r;if(e[t.indexOf("label")]?.name)return"";return vd(n,"label",i)}function Nf(e){const{args:t,style:n,effectiveLink:i,statementId:r,...o}=e;if("name"in e)return JSON.stringify([e.name,e.args.map(s=>[s.name,s.value])]);return JSON.stringify(o)}function Mn(e,t,n,i,r="warning"){e.diagnostics.push({code:"UNSUPPORTED_SYNTAX",syntax:n,severity:r,statementId:t,message:i})}var Oj=new Set(["UpdateElementStyle","UpdateRelStyle","UpdateLayoutConfig"]);function wL(e){return e==="UpdateElementStyle"?gL:e==="UpdateRelStyle"?yL:e==="UpdateLayoutConfig"?["c4ShapeInRow","c4BoundaryInRow"]:void 0}function wae(e){const t=wL(e.name);if(!t)return $f(e.args);if(e.name==="UpdateLayoutConfig")return $f(e.args)&&e.args.every((i,r)=>!i.name||i.name===t[r]);const n=e.name==="UpdateElementStyle"?1:2;return $f(e.args,t.slice(0,n))}function Bj(e){if(e==="UpdateElementStyle")return"element-style";if(e==="UpdateRelStyle")return"relationship-style";if(e==="AddElementTag")return"element-tag";if(e==="AddRelTag")return"relationship-tag";if(e==="UpdateLayoutConfig"||e.startsWith("Lay_")||e.startsWith("LAYOUT_"))return"layout";if(e==="ShowLegend"||e==="SHOW_LEGEND"||e==="SHOW_FLOATING_LEGEND")return"legend";if(e==="AddElementLink"||e==="AddRelLink")return"link";return"unknown"}function Qw(e,t){return Object.fromEntries(Object.entries(e).filter(([n,i])=>!t.includes(n)&&i!==""))}function Wj(e,t=false){for(const c of[...e.elements,...e.boundaries,...e.relationships]){c.style={};delete c.effectiveLink;if(re("c4"))he("c4","reset-presentation",{id:c.id,style:c.style})}e.layout={hints:[]};if(re("c4"))he("c4","reset-layout",e.layout);const n=new Map([...e.elements,...e.boundaries].map(c=>[c.id,c]));const i=new Map;const r=(c,d)=>JSON.stringify([c,d]);for(const c of e.relationships){const d=r(c.from,c.to),u=i.get(d)??[];u.push(c);i.set(d,u)}const o=(c,d)=>{const u=Vs(c.args,d);for(const f of["techn","legendText"]){const h=Wa(c.args,d,f);if(h!==void 0)u[f]=h}return u};const s=new Map,a=new Map;for(const c of e.directives){if(c.category!=="element-tag"&&c.category!=="relationship-tag")continue;const d=o(c,c.category==="element-tag"?xL:bL);(c.category==="element-tag"?s:a).set(d.tagStereo??"",Qw(d,["tagStereo"]));if(re("c4"))he("c4","define-tag",{category:c.category,tag:d.tagStereo??"",style:(c.category==="element-tag"?s:a).get(d.tagStereo??"")})}for(const c of[...e.elements,...e.boundaries])for(const d of c.tags){Object.assign(c.style,s.get(d));if(re("c4"))he("c4","apply-tag",{id:c.id,tag:d,style:c.style})}for(const c of e.relationships)for(const d of c.tags){Object.assign(c.style,a.get(d));if(re("c4"))he("c4","apply-tag",{id:c.id,tag:d,style:c.style})}for(const c of e.directives){if(c.category==="element-style"){const d=o(c,gL);const u=n.get(d.elementName);if(!u)throw new Error(`C4: UpdateElementStyle references undeclared alias ${JSON.stringify(d.elementName)}`);Object.assign(u.style,Qw(d,["elementName"]));if(re("c4"))he("c4","set-element-style",{id:u.id,style:u.style})}else if(c.category==="relationship-style"){const d=Vs(c.args,yL);const u=i.get(r(d.from,d.to));if(!u)throw new Error("C4: UpdateRelStyle references an undeclared relationship pair");for(const f of["offsetX","offsetY"])if(d[f]!==void 0&&!Number.isFinite(Number(d[f])))throw new Error(`C4: ${f} must be finite`);for(const f of u){Object.assign(f.style,Qw(d,["from","to"]));if(re("c4"))he("c4","set-relationship-style",{id:f.id,style:f.style})}}else if(c.name==="UpdateLayoutConfig"){const d=Vs(c.args,["c4ShapeInRow","c4BoundaryInRow"]);for(const[u,f]of[["c4ShapeInRow","shapesPerRow"],["c4BoundaryInRow","boundariesPerRow"]]){if(d[u]===void 0||d[u]==="")continue;const h=Number(d[u]);if(!Number.isSafeInteger(h)||h<1)throw new Error(`C4: ${u} must be a positive integer`);e.layout[f]=h;if(re("c4"))he("c4","set-layout-option",{name:f,value:h})}}else if(c.name.startsWith("Lay_")){const d=pL[c.name.slice(4)];const u=Vs(c.args,["from","to"]);if(!d||!u.from||!u.to||!n.has(u.from)||!n.has(u.to))throw new Error(`C4: ${c.name} requires two declared aliases`);if(d&&u.from&&u.to){if(t)Ve("edges",e.relationships.length+e.layout.hints.length+1);e.layout.hints.push({from:u.from,to:u.to,direction:d,statementId:c.statementId});if(re("c4"))he("c4","add-layout-hint",e.layout.hints.at(-1))}}else if(c.name==="direction"){e.layout.direction=c.args[0]?.value;if(re("c4"))he("c4","set-direction",e.layout.direction)}else if(c.name==="LAYOUT_LEFT_RIGHT"||c.name==="LAYOUT_TOP_DOWN"){e.layout.direction=c.name==="LAYOUT_LEFT_RIGHT"?"LR":"TB";if(re("c4"))he("c4","set-direction",e.layout.direction)}else if(c.name==="AddElementLink"){const d=Vs(c.args,["alias","link"]);const u=n.get(d.alias);if(u){u.effectiveLink=d.link;if(re("c4"))he("c4","set-effective-link",{id:u.id,link:u.effectiveLink})}}else if(c.name==="AddRelLink"){const d=Vs(c.args,["from","to","link"]);for(const u of i.get(r(d.from,d.to))??[]){u.effectiveLink=d.link;if(re("c4"))he("c4","set-effective-link",{id:u.id,link:u.effectiveLink})}}}const l=yi([...e.elements,...e.boundaries,...e.relationships].map(c=>c.id));e.legend={visible:e.directives.some(c=>c.category==="legend"),entries:[...[...s.entries()].map(([c,d])=>({id:l(`c4-tag-${c}`,["element-tag",c]),label:d.legendText??c,kind:"element",style:{...d}})),...[...a.entries()].map(([c,d])=>({id:l(`c4-tag-${c}`,["relationship-tag",c]),label:d.legendText??c,kind:"relationship",style:{...d}}))]};if(re("c4"))he("c4","set-legend",e.legend)}function Mae(e){return ML(e,false)}function ML(e,t){const n=typeof e==="string"?e:e.join("\n");const i=Nj();if(re("c4"))he("c4","initialize",i);i.statements=$j(n);const r=[];const o=new Set;const s=new Set;let a=false;let l=false;let c=false;for(const f of i.statements){const h=f.raw.trim();if(f.kind==="trivia"){lo(f,"trivia");if(!h.startsWith("%%")&&h.includes(";")){Mn(i,f.id,"c4_semicolon_separator","Semicolon statement separators are a reader extension; pinned Mermaid C4 requires line breaks");l=c=false}else if(h.startsWith("%%"))c||=l;else if(/[\r\n]/.test(f.raw)&&!c)l=false;continue}if(l&&f.kind!=="boundary-close")Mn(i,f.id,"c4_statements_on_one_line","Statements sharing a line are a reader extension; pinned Mermaid C4 requires a line break after each statement and after `{`, and a comment after a statement takes its line break");l=true;c=false;if(!a){const b=hL(h);const C=mL.find(P=>P.toLowerCase()===b.toLowerCase());if(!C)throw new Error("C4: expected C4Context, C4Container, C4Component, C4Dynamic, or C4Deployment");lo(f,"header");i.variant=C;if(re("c4"))he("c4","set-variant",C);f.kind="header";f.signature=C;a=true;continue}if(f.kind==="boundary-close"){lo(f,"boundary-close");const b=r.pop();if(!b)throw new Error(`C4: unmatched closing boundary at line ${f.span.line}`);if(re("c4"))he("c4","close-boundary",{id:b});f.entityId=b;continue}if(Un(h)!==h)Mn(i,f.id,"c4_entity_prepass","The global Mermaid entity prepass changes this statement; the writer protects its text fields without changing their values");if(/^title\s/i.test(h)){lo(f,"title");if(r.length)Mn(i,f.id,"c4_nested_header_directive","Metadata inside a boundary is read as global. Pinned Mermaid requires it at document scope; the writer moves it after the header");if(/[#;]/.test(Un(h.replace(/^title\s+/i,""))))Mn(i,f.id,"c4_title_token","The title contains literal token delimiters; serialization writes entity escapes for pinned Mermaid");i.title=rn(ws(h.replace(/^title\s+/i,"")));if(re("c4"))he("c4","set-title",i.title);f.kind="title";f.signature=i.title;continue}const m=vt(h.split(/\r\n?|\n/),0);if(m){lo(f,"accessibility");if(r.length)Mn(i,f.id,"c4_nested_header_directive","Metadata inside a boundary is read as global. Pinned Mermaid requires it at document scope; the writer moves it after the header");if(!m.title&&m.form!=="native"&&m.value==="")Mn(i,f.id,"c4_empty_accessibility_description","An empty accessibility description block is a reader extension; the writer preserves its value in a native metadata comment");if(m.title)i.accessibilityTitle=m.value;else i.accessibilityDescription=m.value;if(re("c4"))he("c4",m.title?"set-accessibility-title":"set-accessibility-description",m.value);f.kind="accessibility";f.entityId=m.title?"title":"description";f.signature=m.value;continue}if(/^accDescription\s+/i.test(h)){lo(f,"accessibility");i.accessibilityDescription=h.replace(/^accDescription\s+/i,"");if(re("c4"))he("c4","set-accessibility-description",i.accessibilityDescription);f.kind="accessibility";f.entityId="description";f.signature=i.accessibilityDescription;continue}const p=/^direction\s+(LR|RL|TB|BT)\s*$/.exec(h);if(p){lo(f,"direction");const b={id:f.id,name:"direction",args:[{value:p[1],raw:p[1]}],category:"layout",statementId:f.id};i.directives.push(b);if(re("c4"))he("c4","add-directive",b);f.kind="directive";f.entityId=b.id;f.signature=Nf(b);continue}const g=/^([A-Za-z_][A-Za-z_0-9]*)\s*\(([\s\S]*)\)\s*(\{)?$/.exec(h);if(!g){lo(f,"unknown");Mn(i,f.id,"c4_unknown_statement","C4 statement is preserved but has no native interpretation","error");continue}const y=g[1],w=_j(g[2]);if(y==="UpdateLayoutConfig"&&(w.length===0||w.length===1&&!w[0].name&&w[0].value==="")&&!g[3]){if(r.length)o.add(r.at(-1));if(h[y.length]!=="("||!$f(w))Mn(i,f.id,"c4_empty_layout_arguments","An empty layout call is a no-op; the writer supplies the attribute required by pinned Mermaid");f.kind="trivia";continue}if(/[\r\n]/.test(g[2].replace(/"[^"]*"|'[^']*'/g,"")))Mn(i,f.id,"c4_multiline_arguments","Line breaks between C4 arguments are a reader extension; quoted multiline text remains supported");if(w.some(b=>b.name&&b.value===""))Mn(i,f.id,"c4_empty_named_argument","Empty named arguments are retained; pinned Mermaid requires a positional empty slot");const S=Fj.exec(y);const x=Boolean(S&&!(S[1]==="Person"&&S[2]))||Object.hasOwn(Td,y)||Vw.has(y)||Oj.has(y);if(x&&r.length)o.add(r.at(-1));if(x&&w.some(Dj))throw new Zw(`C4 argument is ambiguous in ${h}: separate named arguments with commas and use $name="value", or quote the entire value when it is literal text`);if(x&&w.some((b,C)=>{const P=b.raw.trim();if(b.name)return!/^\$[A-Za-z_][A-Za-z_0-9]*\s*=\s*"/.test(P)&&b.value!=="";return P.startsWith("$")||C===w.length-1&&P!==""&&!/^["']/.test(P)}))Mn(i,f.id,"c4_unquoted_argument","Unquoted C4 argument text is read literally here, but pinned Mermaid requires a quoted final argument and quoted named values; serialization writes those values in double quotes");if(x&&h[y.length]!=="(")Mn(i,f.id,"c4_space_before_arguments",`Pinned Mermaid reads "(" only straight after ${y} and rejects whitespace between them; ours reads the call. Write ${y}( with no space`);if(S&&!(S[1]==="Person"&&S[2])){lo(f,"element");if(g[3])throw new Error(`C4: ${y} cannot open a boundary`);const b=Vs(w,Af(y));const C=vd(b,"alias",y);if(s.has(C))throw new Error(`C4: duplicate declaration alias ${JSON.stringify(C)}`);s.add(C);const P={id:C,macro:y,kind:S[1].toLowerCase(),external:Boolean(S[3]),shape:S[1]==="Person"?"person":S[2]==="Db"?"database":S[2]==="Queue"?"queue":"rectangle",label:Jw(w,Af(y),b,y),technology:co(Wa(w,Af(y),"techn")),description:co(Wa(w,Af(y),"descr")),parentId:r.at(-1),tags:Kw(b.tags),link:co(b.link),sprite:co(b.sprite),style:{},args:w,statementId:f.id};if(t)Ve("nodes",i.elements.length+i.boundaries.length+1);i.elements.push(P);if(re("c4"))he("c4","add-element",P);f.kind="element";f.entityId=C;f.signature=Nf(P)}else if(Td[y]){lo(f,"boundary-open");if(!g[3])throw new Error(`C4: ${y} requires a boundary block`);const b=Vs(w,If(y));const C=vd(b,"alias",y);if(s.has(C))throw new Error(`C4: duplicate declaration alias ${JSON.stringify(C)}`);s.add(C);const P={id:C,macro:y,kind:Td[y],label:Jw(w,If(y),b,y),type:co(Wa(w,If(y),"type")),description:co(Wa(w,If(y),"descr")),parentId:r.at(-1),tags:Kw(b.tags),link:co(b.link),sprite:co(b.sprite),style:{},args:w,statementId:f.id,...y==="Node_L"?{alignment:"left"}:y==="Node_R"?{alignment:"right"}:{}};if(t){Ve("nodes",i.elements.length+i.boundaries.length+1);Ve("nesting",r.length+1)}i.boundaries.push(P);r.push(C);if(re("c4"))he("c4","open-boundary",P);f.entityId=C;f.signature=Nf(P)}else if(Vw.has(y)){lo(f,"relationship");const b=Vs(w,Ff(y));const C=vd(b,"from",y),P=vd(b,"to",y);const E=y==="Rel_Back";const k={id:"",macro:y,from:C,to:P,source:E?P:C,target:E?C:P,label:Jw(w,Ff(y),b,y),technology:co(Wa(w,Ff(y),"techn")),description:co(Wa(w,Ff(y),"descr")),tags:Kw(b.tags),link:co(b.link),sprite:co(b.sprite),style:{},args:w,statementId:f.id,index:y==="RelIndex"?vd(b,"index",y):void 0,order:i.relationships.length+1,bidirectional:y==="BiRel",reversed:E,direction:pL[y.slice(4)]};if(t)Ve("edges",i.relationships.length+i.layout.hints.length+1);i.relationships.push(k);if(re("c4"))he("c4","add-relationship",k);f.kind="relationship";if(y==="RelIndex"&&w.slice(4).some(v=>!v.name))Mn(i,f.id,"c4_relindex_positional_metadata","RelIndex positional metadata follows documented tags/link slots; pinned Mermaid instead treats them as technology/description. Named $tags/$link avoids this ambiguity")}else{lo(f,"directive");const b={id:f.id,name:y,args:w,category:Bj(y),statementId:f.id};i.directives.push(b);if(re("c4"))he("c4","add-directive",b);f.kind="directive";f.entityId=b.id;f.signature=Nf(b);if(b.category==="unknown")Mn(i,f.id,"c4_unknown_macro",`${y} is preserved but has no native interpretation`,"error");else if(!y.startsWith("Update"))Mn(i,f.id,"c4_directive_extension",`${y} is a reader extension; pinned Mermaid does not accept this directive`)}const M=S?Af(y):Td[y]?If(y):Vw.has(y)?Ff(y):wL(y)??(y==="AddElementTag"?xL:y==="AddRelTag"?bL:void 0);if(M){const b=new Set;for(let C=0;C<w.length;C++){const P=w[C],E=P.name??M[C];if(E===void 0||!M.includes(E)){Mn(i,f.id,"c4_unknown_argument",`${y} argument ${P.name??C+1} is retained but has no native interpretation`,"error")}else if(b.has(E)){Mn(i,f.id,"c4_duplicate_argument",`${y} assigns ${E} more than once; every argument is retained`,"error")}if(E)b.add(E)}}if(w.some(b=>/^\s*'/.test(b.raw)||/\\["']/.test(b.raw))){Mn(i,f.id,"c4_quoted_string_extension","Quoted-string extension is preserved; typed edits write Mermaid entity escapes")}else if(x&&!$f(w)&&!i.diagnostics.some(b=>b.statementId===f.id&&["c4_multiline_arguments","c4_empty_named_argument"].includes(b.syntax))){Mn(i,f.id,"c4_argument_spelling","Argument text is retained as its native value; the writer emits complete quoted argument tokens instead of ambiguous imported spelling")}}if(!a)throw new Error("C4: missing diagram header");if(r.length)throw new Error(`C4: unclosed boundary ${JSON.stringify(r.at(-1))}`);if(t)Fm(i);const d=yi(s);const u=new Map(i.statements.map(f=>[f.id,f]));for(const f of i.relationships){f.id=d(`c4-rel-${f.order}`,["c4-relationship",f.order]);if(re("c4"))he("c4","set-relationship-identity",{id:f.id,order:f.order});if(!s.has(f.from)||!s.has(f.to))throw new Error(`C4: relationship ${f.id} references an undeclared endpoint`);const h=u.get(f.statementId);h.entityId=f.id;h.signature=Nf(f)}Wj(i,t);for(const f of i.boundaries){if(!o.has(f.id))Mn(i,f.statementId,"c4_empty_boundary","An empty boundary is retained; the writer supplies a no-op layout statement because pinned Mermaid requires a statement inside its block")}if(i.directives.some(f=>f.name==="direction")){const f=i.directives.find(h=>h.name==="direction");Mn(i,f.statementId,"c4_direction","A standalone direction directive is a reader extension to legacy C4")}for(const f of[...i.elements,...i.boundaries,...i.relationships]){if(f.sprite)Mn(i,f.statementId,"c4_sprite","C4 sprite metadata is preserved; offline native output uses an explicit text fallback");if(f.style.lineStyle!==void 0&&!["solid","dashed","dotted"].includes(f.style.lineStyle)){Mn(i,f.statementId,"c4_line_style",`C4 lineStyle ${JSON.stringify(f.style.lineStyle)} is preserved but has no native paint effect; the route uses solid strokes`)}for(const h of Object.keys(f.style)){if(h==="shape"&&"external"in f&&ww(f.style.shape)!==void 0)continue;if(!["bgColor","fontColor","borderColor","textColor","lineColor","lineStyle","offsetX","offsetY","legendText","techn"].includes(h)){Mn(i,f.statementId,"c4_style_property",`C4 style ${h} is preserved as metadata but has no native paint effect`)}}}return i}function zj(e,t){const n=e.statements.find(i=>i.id===t.statementId);return n?`${t.message} (in: ${n.raw.trim()})`:t.message}function kL(e){const t=ML(e,true);const n=t.diagnostics.find(i=>i.severity==="error");if(n)throw new Error(`C4 unsupported syntax: ${zj(t,n)}`);return t}import{decodeXML as Io}from"entities";var Gj=/^direction\s+(TB|TD|BT|LR|RL)\s*$/i;function _f(e){const t=e.match(Gj);return t?t[1].toUpperCase():void 0}var Hj=/^\s*(?:fill|stroke|color)\s*:\s*$/;function PL(e){const t=[];let n=0;let i=0;let r="";let o=false;for(let s=0;s<e.length;s++){const a=e[s];if(a==="#"){const l=/^#\w+;/.exec(e.slice(s))?.[0];if(l&&!(Hj.test(e.slice(n,s))&&Kt(l.slice(0,-1))!==null)){s+=l.length-1;o=false;continue}}if(o){o=false;continue}if(a==="\\"){o=true;continue}if(r){if(a===r)r="";continue}if(a==='"'||a==="'"){r=a;continue}if(a==="(")i++;else if(a===")")i=Math.max(0,i-1);else if((a===","||a===";")&&i===0){t.push(e.slice(n,s));n=s+1}}t.push(e.slice(n));return t}function Tae(e){return PL(e).some(t=>t.slice(t.indexOf(":")+1).includes(","))}function Ld(e){return Vm(mg(e))}function mg(e){const t=[];const n=i=>so(Dn(i),{subject:"Style text entity",example:"font-family: Inter#44;serif"});for(const i of PL(e)){const r=i.indexOf(":");if(r<=0)continue;const o=n(i.slice(0,r).trim());const s=n(i.slice(r+1).trim().replace(/\\,/g,","));if(o&&s)t.push([o,s])}return t}function jj(e,t){if(t!==void 0){if(!Array.isArray(t)||t.some(r=>!Array.isArray(r)||r.length!==2||r.some(o=>typeof o!=="string"||!o.trim())))return;const n=Object.entries(Vm(t));const i=Object.entries(e);if(i.length!==n.length||i.some(([r,o],s)=>r!==n[s][0]||o!==n[s][1]))return}for(const[n,i]of t??Object.entries(e)){for(const r of[n,i]){if(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f\ufffe\uffff\r\n]/.test(r))return;for(const o of r){const s=o.codePointAt(0);if(s>=55296&&s<=57343)return}}}return{...e}}function CL(e){const t=dn(e,`,:;<>&%"'\\\u2028\u2029`);return t.replace(/direction(?=\s+(?:TB|BT|RL|LR))/gi,n=>`#${n.codePointAt(0)};${n.slice(1)}`)}function Yj(e,t=false,n){if(!jj(e,n))throw new Error("Style contains unrepresentable text or inconsistent ordered declarations");const i=(n??Object.entries(e)).map(([s,a])=>[s,a]);if(t)i.unshift(["style",""]);const r=i.map(([s,a])=>({name:s,value:a,key:CL(s),text:CL(a)}));const o=r.some(s=>s.key!==s.name||s.text!==s.value)?": ":":";return r.map(s=>`${s.key}${o}${s.text}`).join(",")}function Lae(e,t,n=false,i){return e+Yj(t,n,i)}function e0(e){if(e.markerAt==="from"&&(e.fromType??e.type)==="lollipop")return"from";if(e.markerAt==="to"&&(e.toType??e.type)==="lollipop")return"to";return void 0}function EL(e){const t=[...e];let n=false;while(t.length){const a=t.pop();if(a.value.kind==="relationship"&&e0(a.value.relationship)){n=true;break}if(a.children)t.push(...a.children)}if(!n)return()=>{throw new Error("No lollipop interface occurrence was declared")};const i=new Set;const r=[...e];while(r.length){const a=r.pop(),l=a.value;if(a.children)r.push(...a.children);if(l.kind==="class")i.add(l.declaration.id);else if(l.kind==="annotation")i.add(l.annotation.id);else if(l.kind==="member"||l.kind==="note"){if(l.reference)i.add(l.reference.id)}else if(l.kind==="interaction")i.add(l.interaction.id);else if(l.kind==="relationship"){i.add(l.relationship.from);i.add(l.relationship.to)}else if(l.kind==="style"||l.kind==="assignment")for(const c of l.references)i.add(c.id)}const o=yi(i);let s=0;return()=>{const a=s++;return o(`interface${a}`,["interface",a])}}function pg(e){return{id:"cls-lollipop",shape:"circle",size:{width:14,height:14},viewBox:{x:0,y:0,width:14,height:14},ref:{x:12,y:7},orient:"auto-start-reverse",overflow:"hidden",geometry:{kind:"circle",cx:7,cy:7,r:5},paint:{fill:"var(--bg)",stroke:e,strokeWidth:"1.5"}}}var vL=/&#(?:\d+|[xX][0-9a-fA-F]+);|#\w+;/g;var TL=/direction(?=\s+(?:TB|BT|RL|LR))/;var Oae=e=>TL.test(e);var LL=e=>e.startsWith("&")?e:rn(e,{subject:"Class text entity",example:'class A["I #9829; UML"]'});function za(e){return e.replace(vL,LL)}function Ga(e,t=true,n=true){const i=t?yt(e):e;const r=za(i);if(!/#\w+;/.test(e))return{label:r};const o=ur(Rt(n?yt(e):e),vL,LL);return{label:r,labelContent:{value:r,prepared:o,authored:e}}}function Bae(e,t,n='"'){const i=t?.value===e?t.authored:void 0;return(i===void 0?dn(e,n):gr(i,n)).replace(/\r\n?|\n/g,"<br/>").replace(/%%\{/g,"%%#123;").replace(new RegExp(TL.source,"g"),r=>`#${r.codePointAt(0)};${r.slice(1)}`)}function Df(e){if(!e.isMethod&&e.sourceText){const r=e.visibility&&e.sourceText.startsWith(e.visibility)?e.visibility:"";return za(r+qj(e.sourceText.slice(r.length)))}const t=e.visibility?`${e.visibility} `:"";const n=e.isMethod?`${e.name}(${e.params||""})`:e.name;const i=e.type?`: ${e.type}`:"";return za(`${t}${n}${i}`)}function qj(e){const t=e.split(/(,)/);const n=[];for(let i=0;i<t.length;i+=2){let r=t[i];let o=RL(r);while(o%2!==0&&i+2<t.length){const s=t[i+2];r+=`,${s}`;o+=RL(s);i+=2}n.push(Xj(r));if(i+1<t.length)n.push(",")}return n.join("")}function RL(e){let t=0;for(const n of e)if(n==="~")t++;return t}function Xj(e){const t=[...e];const n=[];for(let r=0;r<t.length;r++)if(t[r]==="~")n.push(r);if(n.length<=1)return e;const i=n.length%2!==0&&t[0]==="~"?1:0;for(let r=i,o=n.length-1;r<o;r++,o--){t[n[r]]="<";t[n[o]]=">"}return t.join("")}var $L=/^namespace\s+((?:`[^`\r\n]+`|[\w$]+)(?:\.(?:`[^`\r\n]+`|[\w$]+))*)(?:\s*\[\s*"?([^\]"]*)"?\s*\])?\s*\{/;function Uj(e){const t=e.match($L);if(!t||t[0].length!==e.length)return null;const n=[...t[1].matchAll(/`[^`]+`|[\w$]+/g)].map(i=>i[0].startsWith("`")?i[0].slice(1,-1):i[0]);return{path:n,label:t[2]||void 0}}function Of(e){return r0(e).map(t=>t.text)}function r0(e){const t=e.match($L);if(!t)return[{text:e}];const n=t[0];const i=e.slice(n.length).trim();if(!i||i.startsWith("%%"))return[{text:e}];const r=[];let o=0;let s;let a=0;let l=false;let c=false;const d=u=>{u=u.trim();if(u)r.push({text:u,...l?{followsNamespaceCloseOnSameLine:true}:{}})};for(let u=0;u<i.length;u++){const f=i[u];if(s){if(f==="\\"&&s==='"'){u++;continue}if(f===s)s=void 0}else if(f==='"'||f==="`"||f==="~")s=f;else if(f==="{")a++;else if(f==="}"&&a>0)a--;else if(a===0&&(f===";"||f==="}")){const h=i.slice(o,u);if(bg(h)>=0)break;d(h);if(f===";"&&!l)c=true;if(f==="}")r.push({text:"}"});if(f==="}")l=true;o=u+1}}d(i.slice(o));return[{text:n,...c?{compactSemicolon:true}:{}},...r]}function Vj(e){return e.replace(/&(?:#(?:[xX][0-9a-fA-F]+|[0-9]+)|[A-Za-z][A-Za-z0-9]+);/g,t=>{const n=Io(t);return/[\r\n]/.test(n)?n:t}).split(/\r\n|\r|\n/)}function Kj(e){const t=e.flatMap(Vj).map(o=>o.trim()).filter(o=>{const s=Io(o).trim();return s.length>0&&!s.startsWith("%%")});const n=t.map(o=>Io(o));const i=[];const r=(o,s)=>{const a=Of(s);const l=o===void 0?[]:Of(o);if(l.length===a.length&&l.every((c,d)=>Io(c)===a[d])){i.push(...l)}else{i.push(...a.map(()=>void 0))}};for(let o=0;o<t.length;o++){const s=vt(n,o);if(s===void 0){for(;o<t.length;o++)r(t[o],n[o]);break}if(s===null){r(t[o],n[o]);continue}if(s.suffixLine){const a=t[s.endIndex];const l=/}|&(?:#(?:[xX][0-9a-fA-F]+|[0-9]+)|[A-Za-z][A-Za-z0-9]+);/g;let c=-1;for(const u of a.matchAll(l)){if(Io(u[0])==="}"){c=u.index+u[0].length;break}}const d=c<0?void 0:a.slice(c).trim();r(d!==void 0&&Io(d).trim()===s.suffixLine.trim()?d:void 0,s.suffixLine.trim())}o=s.endIndex}return i}var _L="`[^`]+`|[\\w$\\p{L}\\p{N}\\p{M}]+(?:[.-][\\w$\\p{L}\\p{N}\\p{M}]+)*";var Jj=new RegExp(`^class\\s+(${_L})(?:\\s*~([^~]+)~)?(?:\\s*\\[\\s*"([^"]*)"\\s*\\])?(?:\\s+as\\s+"([^"]+)")?(?:\\s+~([^~]+)~)?(?:\\s*:::([\\w-]+))?\\s*(\\{\\s*\\}|\\{)?\\s*$`,"u");var Qj=new RegExp(`^(${_L})(?:~([^~]+)~)?$`,"u");function DL(e){const t=e.match(Jj);if(!t)return null;const n=t[1];return{id:n.startsWith("`")?n.slice(1,-1):n,generic:(t[2]??t[5])?.trim(),label:t[3]??t[4],...t[6]?{className:t[6]}:{},opensBody:t[7]==="{"}}function uo(e){const t=e.trim().match(Qj);if(!t)return null;const n=t[1];return{id:n.startsWith("`")?n.slice(1,-1):n,generic:t[2]?.trim()||void 0}}function AL(e){const t=e.trim().match(/^<<[ \t]*(\w+)[ \t]*>>$/);return t?.[1]??null}function OL(e){const t=e.trim();return t.startsWith("<<")&&t.endsWith(">>")?t.slice(2,-2):null}function Zj(e){let t=false;let n=false;let i=false;let r=0;for(let o=0;o<e.length-1;o++){const s=e[o];if(t){if(s==="`")t=false;continue}if(n){if(s==='"')n=false;continue}if(i){if(s==="~")i=false;continue}if(s==="`"){t=true;continue}if(s==='"'){n=true;continue}if(s==="~"&&r===0){i=true;continue}if(s==="["){r++;continue}if(s==="]"){r=Math.max(0,r-1);continue}if(r===0&&s==="<"&&e[o+1]==="<")return o}return-1}function eY(e){const t=e.trim();if(t.startsWith("<<")){const u=t.indexOf(">>",2);if(u<0)return null;const f=AL(t.slice(0,u+2));const h=uo(t.slice(u+2));return f&&h?{...h,annotation:f,placement:"separate"}:null}const n=t.match(/^class\s+/);if(!n)return null;const i=t.slice(n[0].length);const r=Zj(i);if(r<0)return null;let o=i.slice(0,r).trim();let s=i.slice(r).trim();const a=o.endsWith("{")&&s.endsWith("}");if(a){o=o.slice(0,-1).trim();s=s.slice(0,-1).trim()}const l=a?void 0:s.match(/\{\s*\}?$/)?.[0];if(l)s=s.slice(0,-l.length).trim();const c=DL(`class ${o}`);const d=a?OL(s):AL(s);return c&&!c.opensBody&&d!==null?{id:c.id,...c.generic?{generic:c.generic}:{},...c.label!==void 0?{label:c.label}:{},annotation:d,placement:a?"body-inline":"inline",...c.className!==void 0?{className:c.className}:{},...l==="{"?{opensBody:true}:{}}:null}function t0(e,t){if(e.annotation!==void 0){throw Je({what:`Multiple annotations for class "${e.id}" are not modeled without losing identity`,expectedForm:"one annotation per class",example:`class ${e.id} <<${t}>>`})}e.annotation=za(t)}function Zae(e){return e.some(t=>{const n=t.trim();return n.length>0&&!n.startsWith("%%")})}var n0=/(?:https?:\/\/|mailto:)\S*/iy;var tY={'"':'"',"`":"`","~":"~","(":")"};function bg(e){const t=/^class\b/.test(e);for(let n=0;n<e.length-1;n++){const i=e[n];const r=tY[i]??(t&&i==="{"?"}":void 0);if(r!==void 0){const o=e.indexOf(r,n+1);if(o<0)return-1;n=o;continue}if(i===":"){if(!e.startsWith(":::",n))return-1;n+=2;continue}if(n===0||/\s/.test(e[n-1])){n0.lastIndex=n;if(n0.test(e)){n=n0.lastIndex-1;continue}}if(i==="%"&&e[n+1]==="%")return n}return-1}function gg(e){const t=e.indexOf("%%");return t<0?e:e.slice(0,t).trimEnd()}function BL(e){const t=bg(e);return t<0?e:e.slice(0,t).trimEnd()}function o0(e,t){if(/^classDiagram(?:-v2)?\s*$/i.test(e))return{kind:"header"};if(!e||e.startsWith("%%"))return{kind:"trivia"};if(e==="}")return{kind:"close"};const n=t!==void 0?cY(t):null;if(n)return{kind:"interaction",interaction:n};if(/^callback\s+(?:`[^`]+`|[\w$]+)(?:~[^~]+~)?\s+"[^"\r\n]+"(?:\s+"[^"\r\n]*")?\s*$/i.test(e)||/^click\s+(?:`[^`]+`|[\w$]+)(?:~[^~]+~)?\s+call\s+.+$/i.test(e)||/^(?:click|link)\s+(?:`[^`]+`|[\w$]+)(?:~[^~]+~)?\s+(?:href\s+)?"(?!(?:https?:\/\/|mailto:))[^"\r\n]*"(?:\s+"[^"\r\n]*")?\s*$/i.test(e)){return{kind:"source-only",reason:"Class callback or unsafe/relative link is retained as inert source-only action metadata"}}const i=BL((t??e).trim());const r=i.match(/^note(?:\s+for\s+(\S+))?\s+"([^"]*)"\s*$/i);const o=r??i.match(/^note(?:\s+for\s+(\S+))?\s+"((?:\\.|[^"\\])*)"\s*$/i);if(o){const S=o[1]?uo(Io(o[1])):void 0;if(!o[1]||S)return{kind:"note",text:Io(r?o[2]:o[2].replace(/\\(["\\])/g,"$1")),...S?{reference:S}:{},...!r?{escapedQuotes:true}:{}}}const s=e.match(/^title\s+(.+)$/i);if(s)return{kind:"title",text:s[1].trim()};const a=_f(e);if(a)return{kind:"direction",direction:a};const l=Uj(e);if(l)return{kind:"namespace",...l};const c=S=>{const x=S.replace(/^"|"$/g,"").split(",").map(M=>uo(M.trim()));return x.every(M=>M!==null)?x:null};const d=e.match(/^classDef\s+([\w,-]+)\s+(.+)$/);if(d){const S=Ld(gg(d[2]));if(Object.keys(S).length>0)return{kind:"classDef",names:d[1].split(",").filter(Boolean),props:S,declarations:mg(gg(d[2]))}}const u=e.match(/^(class|cssClass)\s+(.+?)\s+([\w-]+)$/);if(u&&!e.includes("{")&&!e.includes("[")&&!e.includes(" as ")){const S=u[1]==="cssClass"&&/^"[^"]*"$/.test(u[2]);const x=S?u[2].slice(1,-1).split(",").map(M=>uo(M.trim())??(M.trim()?{id:M.trim()}:null)):c(u[2]);if(x?.every(M=>M!==null)){return{kind:"assignment",references:x,name:u[3],form:u[1]==="class"?"class":S?"cssClass":"cssClassUnquoted"}}}const f=e.match(/^style\s+(.+?)\s+(.+)$/);if(f){const S=c(f[1]);const x=Ld(gg(f[2]));if(S&&Object.keys(x).length>0)return{kind:"style",references:S,props:x,declarations:mg(gg(f[2]))}}const h=eY(e);if(h?.opensBody){const{id:S,generic:x,label:M,className:b}=h;return{kind:"class",declaration:{id:S,generic:x,label:M,...b!==void 0?{className:b}:{},annotation:h.annotation,opensBody:true}}}if(h)return{kind:"annotation",annotation:h};const m=DL(e);if(m&&!yg(m.id,/^class\s+`/.test(e),false)){return{kind:"unknown",reason:`Unrecognized class statement "${e}": Mermaid reads \`${m.id}\` there as a keyword, not a class name`}}if(m)return{kind:"class",declaration:m};const p=e.match(/^(.+?):::([\w-]+)$/);if(p){const S=uo(p[1]);if(S)return{kind:"assignment",references:[S],name:p[2],form:"shorthand"}}const g=e.match(/^(\S+?)\s*:\s*(.+)$/);if(g){const S=uo(g[1]);if(S&&(!yg(S.id,g[1].startsWith("`"),true)||/^call\s/.test(e))){return{kind:"unknown",reason:`Unrecognized class member statement "${e}": Mermaid reads \`${S.id}\` there as a keyword, not a class name`}}if(S)return{kind:"member",reference:S,text:g[2].trim()}}const y=uY(e);if(y)return{kind:"relationship",relationship:y};const w=e.includes("<<")||e.includes(">>")?"annotation":gY(e)||yY(e)||xY(e)?"relationship":/^(?:click|link)\b/i.test(e)?"link":"";return{kind:"unknown",reason:`Unrecognized class${w?` ${w}`:""} statement "${e}"`}}var nY=/^(?:note(?:\s+for\s+(?:`[^`]*`|\S+))?\s+|(?:class|namespace)\s[^"]*\[\s*)$/i;var iY=/^(?:class|namespace|note|click|link|callback|cssClass|style|classDef|title|direction)\b|^<</i;function rY(e){return[false,true].every(t=>{let n;let i=-1;for(let o=0;o<e.length;o++){const s=e[o];if(n){if(t&&s==="\\"&&n==='"')o++;else if(s===n)n=void 0}else if(s==='"'||s==="`"){n=s;i=o}}if(n!=='"')return false;const r=e.slice(0,i);return nY.test(r)||!iY.test(e)&&!r.includes(":")})}function oY(e){let t;for(let n=0;n<e.length;n++){const i=e[n];if(t){if(i===t)t=void 0}else if(i==='"'||i==="`"||i==="~")t=i;else if(i==="{")return n}return-1}function sY(e){const t=[];let n=0;let i=0;for(let r=0;r<e.length;r++){const o=e[r];if(o==="(")i++;else if(o===")")i=Math.max(0,i-1);else if(o===";"&&i===0){let s=r;while(s>n&&/\w/.test(e[s-1]))s--;if(s<r&&(e[s-1]==="#"||e[s-1]==="&"))continue;t.push(e.slice(n,r));n=r+1}}t.push(e.slice(n));return t.map(r=>r.trim()).filter(Boolean)}function aY(e,t){const n=/^class\s/.test(e)?oY(e):-1;const i=e.slice(0,n+1);const r=n<0?void 0:o0(i,void 0);if(r?.kind==="class"&&r.declaration.opensBody){const a=e.slice(n+1);const l=a.indexOf("}");if(a.slice(0,l<0?void 0:l).includes("{"))return null;const c=l<0?"":a.slice(l);const d=/^[\s}]*/.exec(c)[0];const u=c.slice(d.length).trim();return[i,...sY(l<0?a:a.slice(0,l)),...d.match(/\}/g)??[],...u?[u]:[]]}if(!t)return null;let o=e.length;while(o>0&&/[\s}]/.test(e[o-1]))o--;const s=e.slice(0,o);return o<e.length&&s&&o0(s,void 0).kind!=="unknown"?[s,...e.slice(o).match(/\}/g)]:null}function s0(e){const t=e.map((s,a)=>a);let n;try{n=Sg(e)}catch{return t}const i=[];let r=0;for(const s of e){i.push(r);r+=s.length+1}const o=s=>{for(const a of s){const l=a.source.line-1;let c=l;while(c+1<e.length&&i[c+1]<=a.source.end)c++;if(c>t[l])t[l]=c;o(a.children??[])}};o(n.statements);return t}var IL=/%{2}\{\s*(?:(\w+)\s*:|(\w+))\s*(?:(\w+)|((?:(?!\}%{2}).|\r?\n)*))?\s*(?:\}%{2})?/gi;function ele(e){const t=new Set;const n=[...Sg(e,void 0,false).statements];while(n.length>0){const i=n.pop();if((i.value.kind==="style"||i.value.kind==="classDef")&&i.raw.trim()===e[i.source.line-1]?.trim())t.add(i.source.line);for(const r of i.children??[])n.push(r)}return t}function Sg(e,t,n=true){const i={source:e.join("\n"),statements:[],diagnostics:[]};const r=[];let o=0;for(let s=0;s<e.length;s++){const a=e[s];const l={line:s+1,column:1,start:o,end:o+a.length};o+=a.length+1;let c=a.replace(IL,"");const d=t?t[s]?.replace(IL,""):c;const u=r0(c.trim());const f=d===void 0?[]:Of(d.trim());let h=u.map((b,C)=>({...b,authored:f.length===u.length?f[C]:void 0}));const m=h.at(-1);let p=s;let g=m.text;for(let b=0;b<2&&r.at(-1)?.value.kind!=="class"&&rY(g);b++){let C=p+1;while(C<e.length&&!e[C].includes('"'))C++;if(C===e.length)break;g=[g,...e.slice(p+1,C+1).map(P=>P.trim())].join("<br>");p=C}if(p>s){for(const b of e.slice(s+1,p+1))o+=b.length+1;l.end=o-1;s=p;c=g;h=[...h.slice(0,-1),...r0(g).map(b=>({...m,...b,authored:void 0}))]}const y=h.reverse();const w=y.length===1;let S=false;let x;const M=(b,C)=>{for(let P=C.length-1;P>=0;P--)y.push({...b,text:C[P],authored:void 0});S=true};while(y.length>0){const b=y.pop();const C=b.text;const P=r[r.length-1];const E=P?.value.kind==="class";const k=E?C.indexOf("}"):C.startsWith("}")?0:-1;if(k>=0&&C!=="}"&&!C.startsWith("%%")){M(b,[C.slice(0,k).trim(),"}",C.slice(k+1).trim()].filter(Boolean));continue}const v=E&&!C.startsWith("}")?C:BL(C);let T;if(!C||C.startsWith("%%"))T={kind:"trivia"};else if(E&&v!=="}"){const L=OL(v);T=v.includes("{")?{kind:"unknown",reason:`Unrecognized class member "${v}": a class body cannot hold "{"`}:L===null?{kind:"member",text:v}:{kind:"body-annotation",text:L}}else T=o0(v,b.authored);const A=T.kind==="unknown"&&!E?aY(v,P?.value.kind==="namespace"):null;if(A){M(b,A);continue}const R={raw:w&&!S?c:C,text:v,source:l,value:T};if(n&&re("class"))Ge("class",T.kind,v,{line:l.line,column:l.column,offset:l.start,endOffset:l.end,unit:"normalized"});if(b.followsNamespaceCloseOnSameLine||x==="namespace"&&T.kind!=="trivia"&&T.kind!=="close")R.followsNamespaceCloseOnSameLine=true;else if(x==="class"&&T.kind!=="trivia"&&T.kind!=="close")R.followsClassCloseOnSameLine=true;if(T.kind==="close"&&P)x=E?"class":"namespace";if(b.compactSemicolon)R.compactSemicolon=true;if(T.kind==="close"){if(P){P.closing=R;r.pop()}else{i.statements.push(R);i.diagnostics.push({reason:"Unexpected closing brace in class diagram",source:l})}continue}const I=P?P.children:i.statements;I.push(R);if(T.kind==="unknown")i.diagnostics.push({reason:T.reason,source:l});if(T.kind==="namespace"||T.kind==="class"&&T.declaration.opensBody){R.children=[];r.push(R)}}}for(const s of r)i.diagnostics.push({reason:`Unclosed ${s.value.kind==="namespace"?"namespace":"class"} block`,source:s.source});return i}function tle(e){const t=[];for(let s=0;s<e.length;s++){const a=vt(e,s);if(a===void 0)break;if(a!==null){t.push({text:"",index:s});s=a.endIndex;continue}for(const l of Of(e[s].trim())){if(l.length>0&&!l.startsWith("%%"))t.push({text:l,index:s})}}const n=[];const i=Sg(t.map(s=>s.text));const r=(s,a,l)=>{const c=s.source.line-1;const{text:d,index:u}=t[c];if(d===""||l&&!d.startsWith("}"))return;const f=bg(d);if(f>=0&&(a>0||/^(?:class|namespace)\b/.test(d)||d.startsWith("}"))){n.push({index:u,what:"A %% comment after a class declaration, a namespace or a statement inside one, or a closing brace is read as a comment"})}else if(f>=0&&c<t.length-1&&s.value.kind!=="direction"){n.push({index:u,what:"A trailing %% comment on a statement that another statement follows is read as a comment"})}};const o=(s,a=0,l=false)=>{const c=[{nodes:s,namespaces:a,inClassBody:l,index:0}];while(c.length){const d=c.at(-1);if(d.index===d.nodes.length){if(d.closing)r(d.closing,d.namespaces,d.inClassBody);c.pop();continue}const u=d.nodes[d.index++];const{namespaces:f,inClassBody:h}=d;r(u,f,h);if(u.children){const m=f+(u.value.kind==="namespace"?1:0);const p=u.value.kind==="class";c.push({nodes:u.children,namespaces:m,inClassBody:p,index:0,closing:u.closing})}}};o(i.statements);return n}var FL=/(?:%|&#(?:0*37|x0*25);){2}/iy;function i0(e,t=0){FL.lastIndex=t;return FL.test(e)}function lY(e){const t=e.trimStart().match(/^(?:click|link)\s+(`[^`]+`(?:~[^~]+~)?|[\w$]+(?:~[^~]+~)?)\s+(?:href\s+)?(?:"((?:\\.|[^"\\])*)"|((?:https?:\/\/|mailto:)[^\s"\\]+))/i);if(!t)return null;const n=e.trimStart().slice(t[0].length).trimStart();let i;if(n.startsWith('"')){if(t[3]!==void 0)return null;let s=-1;let a=0;for(let c=1;c<n.length;c++){if(n[c]!=='"')continue;let d=c+1;while(d<n.length&&/\s/.test(n[d]))d++;if(a%2===0&&(d===n.length||i0(n,d))){s=c;break}a++}if(s<0)return null;i=n.slice(1,s);if((i.match(/"/g)?.length??0)%2!==0)return null;const l=n.slice(s+1).trimStart();if(l&&!i0(l))return null}else if(n&&!i0(n))return null;const r=uo(t[1]);const o=(t[2]??t[3]??"").replace(/\\(["\\])/g,"$1");return r&&/^(?:https?:|mailto:)/i.test(o)&&ks(o)&&!/[\u0000-\u0020\u007f-\u009f]/.test(o)&&(i===void 0||!/[\u0000-\u001f\u007f-\u009f]/.test(i))?{id:r.id,...r.generic?{generic:r.generic}:{},href:o,...i?{tooltip:i}:{}}:null}function cY(e){const t=new Set;for(const u of Io(e)){const f=u.charCodeAt(0);if(f>=57344&&f<=63743)t.add(f)}let n=57344;while(t.has(n))n++;if(n>63743)return null;const i=String.fromCharCode(n);const r=Io(e.replace(/&quot;|&#0*34;|&#x0*22;/gi,u=>Io(u)==='"'?i:u));const o=u=>{const f=lY(u);if(!f||f.tooltip?.includes('"'))return null;if(f.href.includes(i))return null;const h=f.href;const m=f.tooltip?.replaceAll(i,'"');if(!ks(h)||/[\u0000-\u0020\u007f-\u009f]/.test(h)||m!==void 0&&/[\u0000-\u001f\u007f-\u009f]/.test(m))return null;return{...f,href:h,...m!==void 0?{tooltip:m}:{}}};const s=o(r);if(s)return s;const a=u=>{const f=u.indexOf(i);const h=f<0?-1:u.indexOf(i,f+1);if(h<0)return null;return u.slice(0,f)+'"'+u.slice(f+1,h)+'"'+u.slice(h+1)};const l=a(r);if(!l)return null;const c=o(l);if(c)return c;if([...l].filter(u=>u===i).length!==2)return null;const d=a(l);return d===null?null:o(d)}function WL(e,t){const n=zt(e,s0(e));yr(n);const i=n.familyLines;const r=t?Kj(t):void 0;const o=i.flatMap(Of);const s=Sg(o,r);if(s.diagnostics.length>0){const y=s.diagnostics[0];throw Je({what:`${y.reason} at line ${y.source.line}`,expectedForm:"supported class statements and balanced class/namespace blocks",example:"class A\nA --> B : linked"})}const a={classes:[],classDefs:new Map,relationships:[],notes:[],namespaces:[],...n.accessibility.title!==void 0?{accessibilityTitle:yt(n.accessibility.title)}:{},...n.accessibility.descr!==void 0?{accessibilityDescription:yt(n.accessibility.descr)}:{}};const l=new Map;const c=EL(s.statements);const d=new Map;const u=new Set;const f=[];const h=(y,w)=>{if(w&&!u.has(y)){d.get(w).classIds.push(y);u.add(y);if(re("class"))he("class","claim-member",{id:y,parent:w})}};const m=(y,w,S)=>{let x=y?d.get(y).children:a.namespaces;for(const M of w){y=y?`${y}.${M}`:M;let b=d.get(y);if(b&&b.name!==M){throw Je({what:`Class namespace path collision "${y}" between a quoted literal name and a dotted hierarchy`,expectedForm:"distinct namespace names that do not flatten to the same path",example:"namespace `Literal A.B` { class First }"})}if(!b){b={name:M,classIds:[],children:[]};x.push(b);d.set(y,b);if(re("class"))he("class","add-namespace",{id:y,parent:y.slice(0,-(M.length+1))||void 0,name:M})}x=b.children}if(S!==void 0){const M=d.get(y);delete M.labelContent;Object.assign(M,Ga(S));if(re("class"))he("class","set-namespace-label",{id:y,label:M.label})}return y};const p=(y,w)=>{const S=dY(w);if(S){;(S.isMethod?y.methods:y.attributes).push(S.member);if(re("class"))he("class","add-member",{id:y.id,method:S.isMethod,member:S.member})}};const g=(y,w="",S)=>{const x=[{nodes:y,path:w,owner:S,index:0}];while(x.length){const M=x.at(-1);if(M.index===M.nodes.length){x.pop();continue}const b=M.nodes[M.index++];const{path:C,owner:P}=M;const E=b.value;switch(E.kind){case"header":case"trivia":case"close":case"source-only":break;case"namespace":x.push({nodes:b.children,path:m(C,E.path,E.label),owner:void 0,index:0});break;case"class":{const k=E.declaration;const v=Ks(l,k.id,k.generic);if(k.label!==void 0){delete v.labelContent;Object.assign(v,Ga(k.label))}if(k.className!==void 0)v.className=k.className;if(re("class"))he("class","declare-class",v,{line:b.source.line,unit:"normalized"});if(k.annotation!==void 0){t0(v,k.annotation);if(re("class"))he("class","set-annotation",{id:v.id,annotation:v.annotation})}h(v.id,C);if(b.children)x.push({nodes:b.children,path:C,owner:v,index:0});break}case"member":{const k=E.reference?Ks(l,E.reference.id,E.reference.generic):P;p(k,E.text);break}case"body-annotation":t0(P,E.text);if(re("class"))he("class","set-annotation",{id:P.id,annotation:P.annotation});break;case"annotation":{const k=E.annotation;if(k.placement==="separate"&&!l.has(k.id)){throw Je({what:`Annotation targets undeclared class "${k.id}"`,expectedForm:"declare the class before a separate annotation",example:`class ${k.id}
22
+ <<${k.annotation}>> ${k.id}`})}const v=Ks(l,k.id,k.generic);if(k.label!==void 0){delete v.labelContent;Object.assign(v,Ga(k.label))}if(k.className!==void 0)v.className=k.className;t0(v,k.annotation);if(re("class"))he("class","set-annotation",{id:v.id,annotation:v.annotation,label:v.label});h(v.id,C);break}case"interaction":{const k=Ks(l,E.interaction.id,E.interaction.generic);k.href=E.interaction.href;if(E.interaction.tooltip!==void 0)k.tooltip=E.interaction.tooltip;if(re("class"))he("class","set-interaction",{id:k.id,href:k.href,tooltip:k.tooltip});h(k.id,C);break}case"note":if(E.reference)Ks(l,E.reference.id,E.reference.generic);{const{label:k,labelContent:v}=Ga(E.text);a.notes.push({text:k,...v?{textContent:v}:{},...E.reference?{for:E.reference.id}:{}})}if(re("class"))he("class","add-note",a.notes.at(-1));break;case"title":a.title=E.text;if(re("class"))he("class","set-title",a.title);break;case"direction":a.direction=E.direction;if(re("class"))he("class","set-direction",a.direction);break;case"relationship":{const{fromGeneric:k,toGeneric:v,...T}=E.relationship;const A=e0(T);if(A){const R=A==="from"?k:v;const I=T[A]+(R?`~${R}~`:"");const L=c();const $=A==="from"?"to":"from";Ks(l,T[$],$==="from"?k:v);const B={id:L,label:I,...R?{generic:R}:{},isInterface:true,attributes:[],methods:[]};l.set(L,B);if(re("class"))he("class","add-class",B);T[A]=L}else{Ks(l,T.from,k);Ks(l,T.to,v)}a.relationships.push(T);if(re("class"))he("class","add-relationship",T,{line:b.source.line,unit:"normalized"});break}case"classDef":for(const k of E.names){a.classDefs.set(k,Ou(a.classDefs.get(k),E.props));if(re("class"))he("class","define-class",{name:k,props:E.props})}break;case"assignment":case"style":for(const k of E.references){if(E.kind==="assignment"&&E.form.startsWith("cssClass")){const T=l.get(k.id);if(T)T.className=E.name;else f.push({id:k.id,name:E.name});continue}const v=Ks(l,k.id,k.generic);if(E.kind==="assignment")v.className=E.name;else v.inlineStyle=Ou(v.inlineStyle,E.props);if(re("class"))he("class",E.kind==="assignment"?"assign-class":"set-style",v);h(v.id,C)}break;case"unknown":break}}};g(s.statements);for(const{id:y,name:w}of f){const S=l.get(y);if(S&&S.className===void 0)S.className=w}a.classes=[...l.values()].filter(y=>!y.isInterface).concat([...l.values()].filter(y=>y.isInterface));Lm(a);return a}function Ks(e,t,n){let i=e.get(t);if(!i){i={id:t,label:n?`${t}<${n}>`:t,generic:n,attributes:[],methods:[]};e.set(t,i);if(re("class"))he("class","add-class",i)}else if(n&&!i.generic){i.generic=n;if(i.label===t)i.label=`${t}<${n}>`;if(re("class"))he("class","set-generic",i)}return i}function dY(e){const t=e.trim();const n=/#\w+;$/.test(t)?t:t.replace(/;$/,"");if(!n)return null;let i="";let r=n;if(/^[+\-#~]/.test(r)&&!/^#\w+;/.test(r)){i=r[0];r=r.slice(1).trim()}const o=r.match(/^(.+?)\(([^)]*)\)(?:\s*(.+))?$/);if(o){const u=o[1].trim();const f=o[2]?.trim()||void 0;const h=o[3]?.trim();const m=u.endsWith("$")||r.includes("$");const p=u.endsWith("*")||r.includes("*");return{member:{visibility:i,name:u.replace(/[$*]$/,""),type:h||void 0,isStatic:m,isAbstract:p,isMethod:true,params:f},isMethod:true}}const s=r.split(/\s+/);let a;let l;if(s.length>=2){l=s[0];a=s.slice(1).join(" ")}else{a=s[0]??r}const c=a.endsWith("$");const d=a.endsWith("*");return{member:{visibility:i,name:a.replace(/[$*]$/,""),sourceText:n.replace(/[$*]$/,""),type:l||void 0,isStatic:c,isAbstract:d,isMethod:false},isMethod:false}}function uY(e){const t=bg(e);if(t>=0)e=e.slice(0,t).trimEnd();return mY(e)??fY(e)}function fY(e){const t=Bf(e);if(t<0)return null;const n=e.slice(0,t);const i=e.slice(t+2);let r=n.match(/(<\||\(\)|[*o<>])$/)?.[1];let o=i.match(/^(\|>|\(\)|[*o<>])/)?.[1];if(r==="o"&&/[\w$]/.test(n[n.length-2]??""))r=void 0;if(o==="o"&&/[\w$]/.test(i[1]??""))o=void 0;if(!r&&!o)return null;const s=hY(n.slice(0,n.length-(r?.length??0)),i.slice(o?.length??0));if(!s)return null;const a=e[t]===".";const l=r?NL(r,a):void 0;const c=o?NL(o,a):void 0;const d=l??c;const u=l&&c?"both":l?"from":"to";const f=[l,c].some(h=>h==="dependency"||h==="realization");return{...s,type:d,markerAt:u,...u==="both"?{fromType:l,toType:c}:{},...a&&!f?{lineStyle:"dashed"}:{}}}function zL(e,t,n){const i=t===void 0?void 0:Ga(t);const r=n===void 0?void 0:Ga(n);return{...e?Ga(e):{},...i?{fromCardinality:i.label,...i.labelContent?{fromCardinalityContent:i.labelContent}:{}}:{},...r?{toCardinality:r.label,...r.labelContent?{toCardinalityContent:r.labelContent}:{}}:{}}}function hY(e,t){if(jL(e,t))return null;let n=e.trim();let i=t.trim();let r;if(n.endsWith('"')){const f=n.lastIndexOf('"',n.length-2);if(f>=0){r=n.slice(f+1,-1);n=n.slice(0,f).trimEnd()}}let o;let s=false;let a=false;let l=false;for(let f=0;f<i.length;f++){const h=i[f];if(s){if(h==="`")s=false;continue}if(a){if(h==='"')a=false;continue}if(l){if(h==="~")l=false;continue}if(h==="`"){s=true;continue}if(h==='"'){a=true;continue}if(h==="~"){l=true;continue}if(h===":"){const m=i.slice(f+1).trim();if(!m||/[:;]/.test(m.replace(/(?<!&)#\w+;/g,"")))return null;o=m;i=i.slice(0,f).trimEnd();break}}let c;if(i.startsWith('"')){const f=i.indexOf('"',1);if(f<0)return null;c=i.slice(1,f);i=i.slice(f+1).trimStart()}const d=uo(n);const u=uo(i);if(!d||!u||!xg(d.id,n)||!xg(u.id,i))return null;return{from:d.id,to:u.id,...zL(o,r,c),...d.generic?{fromGeneric:d.generic}:{},...u.generic?{toGeneric:u.generic}:{}}}function mY(e){const t=Bf(e);if(t<0||jL(e.slice(0,t),e.slice(t+2)))return null;const n=e.slice(0,t).trim();let i=e.slice(t+2).trim();let r=uo(n);let o;if(!r&&n.endsWith('"')){const f=n.lastIndexOf('"',n.length-2);if(f>=0){r=uo(n.slice(0,f).trimEnd());if(r)o=n.slice(f+1,-1)}}if(!r)return null;let s=false;let a=false;let l=false;let c;for(let f=0;f<i.length;f++){const h=i[f];if(s){if(h==="`")s=false;continue}if(a){if(h==='"')a=false;continue}if(l){if(h==="~")l=false;continue}if(h==="`"){s=true;continue}if(h==='"'){a=true;continue}if(h==="~"){l=true;continue}if(h===":"){const m=i.slice(f+1).trim();if(!m||/[:;]/.test(m.replace(/(?<!&)#\w+;/g,"")))return null;c=m;i=i.slice(0,f).trim();break}}let d;if(i.startsWith('"')){const f=i.indexOf('"',1);if(f<0)return null;d=i.slice(1,f);i=i.slice(f+1).trim()}const u=uo(i);if(!u)return null;if(!xg(r.id,n)||!xg(u.id,i))return null;return{from:r.id,to:u.id,type:e[t]==="."?"link-dashed":"link-solid",markerAt:"none",...zL(c,o,d),...r.generic?{fromGeneric:r.generic}:{},...u.generic?{toGeneric:u.generic}:{}}}var GL=new Set(["note","click","link","cssClass","href","callback"]);var HL=new Set([...GL,"o","_self","_blank","_parent","_top"]);var pY=new Set([...HL,"class","classDiagram","namespace","style","classDef"]);function yg(e,t,n){return!(t?GL:n?pY:HL).has(e)}function jL(e,t){return/^\s*call\s/.test(e)||/^\s*(?:"[^"]*"\s*)?call(?:\s|$)/.test(t)}function xg(e,t){return t.startsWith("`")?yg(e,true,true)&&!e.includes("~"):!e.includes("$")&&yg(e,false,true)}function Bf(e){let t=false;let n=false;let i=false;for(let r=0;r<e.length-1;r++){const o=e[r];if(t){if(o==="`")t=false;continue}if(n){if(o==='"')n=false;continue}if(i){if(o==="~")i=false;continue}if(o==="`"){t=true;continue}if(o==='"'){n=true;continue}if(o==="~"){i=true;continue}if((o==="-"||o===".")&&e[r+1]===o)return r}return-1}function a0(e,t){const n=e.slice(0,t).trimEnd();const i=e.slice(t+2);if(e[t]==="."){return/(?:<\||<)$/.test(n)||/^(?:>|\|>)/.test(i)}const r=n.endsWith("o")&&/\s/.test(n[n.length-2]??"")&&n.slice(0,-2).trim().length>0;return/(?:<\||<|\*|\(\))$/.test(n)||r||/^(?:>|\|>|\*|o\s+(?![:%])\S|\(\))/.test(i)}function gY(e){const t=Bf(e);return t>=0&&!a0(e,t)}function yY(e){const t=Bf(e);return t>=0&&a0(e,t)}function xY(e){if(!e.includes("`"))return false;const t=Bf(e);if(t<0)return false;const n=e.slice(0,t).trimEnd();const i=e.slice(t+2);const r=e[t]==="."&&/(?:\*|o)$/.test(n)&&/^(?:\*|o|>|\|>|<)/.test(i);if(!a0(e,t)&&!r)return false;if(e.slice(0,t).trimStart().startsWith("`"))return true;let o=e.slice(t+2).trimStart();o=o.replace(/^(?:\|>|[>*o]|\(\))\s*/,"");o=o.replace(/^"[^"]*"\s*/,"");return o.startsWith("`")}function NL(e,t){if(e==="()")return"lollipop";if(e==="*")return"composition";if(e==="o")return"aggregation";if(e.includes("|"))return t?"realization":"inheritance";return t?"dependency":"association"}function nc(e){return e.lineStyle??([e.type,e.fromType,e.toType].some(t=>t==="dependency"||t==="realization"||t==="link-dashed")?"dashed":"solid")}var bY=["stroke","stroke-width","opacity","stroke-dasharray"];var SY=/^[#\w][\w#(),.%\s/-]*$/;function wg(e){const t=[];const n=[];const i=vn(e,{caseInsensitive:true});Tt(i.stroke===void 0?{}:{stroke:i.stroke},"todayMarker");for(const[r,o]of Object.entries(i)){if(!bY.includes(r)||r!=="stroke"&&!SY.test(o)){n.push(r);continue}t.push([r,o])}return{applied:t,ignored:n}}var Di=class extends Error{code;line;constructor(t,n,i){super(`${t}: ${n}`);this.name="GanttError";this.code=t;this.line=i}};var YL=/^(?:(?:gantt|inclusiveEndDates|topAxis|dateFormat|axisFormat|tickInterval|includes|excludes|todayMarker|weekday|weekend|click|accTitle|accDescr)\b|\d{4}-\d{2}-\d{2}\b|(?:title|section|call|accDescription)\s|href\s+")/i;var lle=/^(?:call|title|section|accDescription)$/i;function cle(e){return YL.test(e)||e.includes("%%{")}function qL(e){return rn(e,{subject:"Gantt task text entity",example:"Task #35;1 : 1d"})}function dle(e){let t=dn(e,"#&:%");if(YL.test(t))t=`#${t.codePointAt(0)};${t.slice(1)}`;return t}var wY=["active","done","crit","milestone","vert"];var VL=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"];var d0=/^(\d+(?:\.\d+)?)(ms|s|m|h|d|w|M|y)$/;var l0=/^([1-9][0-9]*)(millisecond|second|minute|hour|day|week|month)$/;function MY(e){const t=e.split(",").map(l=>l.trim());if(t.some(l=>l.length===0))return null;const n=[];let i=0;while(i<t.length&&wY.includes(t[i])){const l=t[i];if(n.includes(l))return null;n.push(l);i++}const r=t.slice(i);if(r.length===0||r.length>3)return null;const o=l=>{const c=l.match(/^after\s+(.+)$/);if(c)return{kind:"after",refs:c[1].split(/\s+/).filter(Boolean)};return{kind:"date",raw:l}};const s=l=>{const c=l.match(/^until\s+(.+)$/);if(c)return{kind:"until",refs:c[1].split(/\s+/).filter(Boolean)};if(d0.test(l))return{kind:"duration",raw:l};return{kind:"date",raw:l}};if(r.length===1)return{tags:n,end:s(r[0])};if(r.length===2)return{tags:n,start:o(r[0]),end:s(r[1])};const a=r[0];if(!/^[\w-]+$/.test(a))return null;return{tags:n,id:a,start:o(r[1]),end:s(r[2])}}function ble(e){const t=[...e.tags];if(e.id!==void 0)t.push(e.id);if(e.start)t.push(e.start.kind==="after"?`after ${e.start.refs.join(" ")}`:e.start.raw);t.push(e.end.kind==="until"?`until ${e.end.refs.join(" ")}`:e.end.raw);return t.join(", ")}function XL(e){return e.split(/[,\s]+/).filter(Boolean).map(t=>{const n=t.toLowerCase();if(n==="weekends")return{kind:"weekends"};if(VL.includes(n))return{kind:"weekday",day:n};return{kind:"date",raw:t}})}var kY={title:/^title\s+(.+)$/i,dateFormat:/^dateFormat\s+(.+)$/i,axisFormat:/^axisFormat\s+(.+)$/i,tickInterval:/^tickInterval\s+(.+)$/i,excludes:/^excludes\s+(.+)$/i,includes:/^includes\s+(.+)$/i,todayMarker:/^todayMarker\s+(.+)$/i,weekday:/^weekday\s+(.+)$/i,weekend:/^weekend\s+(.+)$/i,section:/^section\s+(.+)$/i,click:/^click\s+([\w-]+)\s+(href|call)\s+(.+)$/i};var CY=/^(?:dateFormat|axisFormat|tickInterval|excludes|includes)\s/i;var PY=/^(?:title|section|click|todayMarker|weekday|weekend|acc(?:Title|Descr))\b/i;function UL(e){if(CY.test(e))return e.indexOf(";");const t=e.indexOf(":");if(PY.test(e)||t<=0)return-1;const n=e.indexOf(";",t+1);const i=Kr(e.slice(t+1));return i>=0&&n>t+i?-1:n}var EY=/^click\s+[\w-]+$/i;var RY=/^(?:href|call)\s/i;function vY(e,t){if(!EY.test(e[t].trim()))return-1;let n=t+1;while(n<e.length&&(!e[n].trim()||e[n].trim().startsWith("%%")))n++;return n<e.length&&RY.test(e[n].trim())?n:-1}function c0(e){const t=[];for(let n=0;n<e.length;n++){const i=n;const r=e[n];let o=r.trim();const s=(f,h=e.slice(i,n+1))=>{const m=f.kind==="section"||f.kind==="title"?r.indexOf(f.value,r.search(/\S/)+f.kind.length)+1:f.kind==="task"?r.search(/\S/)+1:void 0;t.push({...f,raw:h,startLine:i+1,endLine:n+1,valueColumn:m})};if(!o||o.startsWith("%%")){s({kind:o?"comment":"blank"});continue}const a=vt(e,n);if(a===void 0){const f=e.slice(n);n=e.length-1;s({kind:"invalid",code:"GANTT_BAD_DIRECTIVE",message:"Unclosed accDescr block",structural:true},f);break}if(a!==null){n=a.endIndex;const f=e.slice(i,n+1);if(a.suffixLine)f[f.length-1]=f.at(-1).slice(0,f.at(-1).indexOf("}")+1);s({kind:"accessibility",directive:a},f);if(a.suffixLine){const h=e[n];const m=h.indexOf("}")+1;const p=c0([h.slice(m)]);t.push(...p.map(g=>({...g,startLine:n+1,endLine:n+1,valueColumn:g.valueColumn===void 0?void 0:g.valueColumn+m})))}continue}if(UL(o)>=0){let f=r;let h=0;for(let m=0;;m++){const p=UL(f.trim());const g=p<0?f.length:f.length-f.trimStart().length+p;t.push(...c0([f.slice(0,g)]).map((y,w)=>({...y,startLine:n+1,endLine:n+1,valueColumn:y.valueColumn===void 0?void 0:y.valueColumn+h,...m>0&&w===0?{afterSemicolon:true}:{}})));if(p<0)break;h+=g+1;f=f.slice(g+1)}continue}const l=vY(e,n);if(l>n){n=l;o=`${o}
23
+ ${e[n].trim()}`}let c=false;for(const[f,h]of Object.entries(kY)){const m=f==="weekday"||f==="weekend"?Ht(o):o;const p=m.match(h);if(!p)continue;c=true;const g=p[1].trim();if(f==="title"||f==="section")s({kind:f,value:g});else if(f==="click")s({kind:"click",taskId:g,action:p[2].toLowerCase(),rest:p[3].trim()});else if(f==="weekday"&&!VL.includes(g.toLowerCase())){s({kind:"invalid",code:"GANTT_BAD_DIRECTIVE",message:`Invalid weekday "${g}"`})}else if(f==="weekend"&&!["friday","saturday"].includes(g.toLowerCase())){s({kind:"invalid",code:"GANTT_BAD_DIRECTIVE",message:`Invalid weekend "${g}" (friday or saturday)`})}else s({kind:"directive",name:f,value:g});break}if(c)continue;const d=Ht(o);if(/^(inclusiveEndDates|topAxis)\s*$/i.test(d)){s({kind:"directive",name:/^topAxis/i.test(d)?"topAxis":"inclusiveEndDates",value:""});continue}const u=o.indexOf(":");if(!/^(dateFormat|axisFormat|tickInterval|inclusiveEndDates|topAxis|excludes|includes|todayMarker|weekday|weekend|click)\b/i.test(o)&&u>0&&u<o.length-1){const f=o.slice(0,u).trim();const h=r.indexOf(":");const m=Kr(r.slice(h+1));const p=m<0?-1:h+1+m;const g=Ht(o.slice(u+1)).trim();const y=MY(g);if(y){s({kind:"task",label:qL(f),labelSource:f,meta:y},[p<0?r:r.slice(0,p)]);if(p>=0)s({kind:"comment"},[r.slice(p)])}else s({kind:"invalid",code:"GANTT_BAD_TASK",message:`Invalid task metadata "${g}"`})}else s({kind:"invalid",code:"GANTT_BAD_DIRECTIVE",message:`Unrecognized gantt line "${o}"`})}return t}function KL(e){const t=Ht((e[0]??"").trim());if(!/^gantt\s*$/i.test(t)){throw new Di("GANTT_BAD_DIRECTIVE",`Expected "gantt" header, got "${t}"`,1)}if(re("gantt"))Ge("gantt","header",e[0]??"",{line:1,unit:"normalized"});const n={dateFormat:"YYYY-MM-DD",inclusiveEndDates:false,topAxis:false,excludes:[],includes:[],weekendStart:"saturday",weekStart:"sunday",sections:[{taskIndexes:[]}],tasks:[],clicks:[]};if(re("gantt"))he("gantt","initialize",n);const i=new Set;let r=0;for(const o of c0(e.slice(1))){const s=o.startLine+1;if(re("gantt"))Ge("gantt",o.kind==="directive"?o.name:o.kind,o.raw.join("\n"),{line:s,unit:"normalized"});if(o.kind==="invalid")throw new Di(o.code,o.message,s);if(o.kind==="accessibility"){if(o.directive.title)n.accTitle=o.directive.value;else n.accDescr=o.directive.value.replace(/\s*\n\s*/g," ");if(re("gantt"))he("gantt",o.directive.title?"setAccessibilityTitle":"setAccessibilityDescription",o.directive.title?n.accTitle:n.accDescr,{line:s,unit:"normalized"})}else if(o.kind==="title"){n.title=o.value;if(re("gantt"))he("gantt","setTitle",n.title,{line:s,unit:"normalized"})}else if(o.kind==="directive"){const a=o.value;switch(o.name){case"dateFormat":n.dateFormat=a;break;case"axisFormat":n.axisFormat=a;break;case"tickInterval":{const l=a.match(l0);if(l)n.tickInterval={count:Number(l[1]),unit:l[2]};break}case"inclusiveEndDates":n.inclusiveEndDates=true;break;case"topAxis":n.topAxis=true;break;case"excludes":{const l=XL(a);n.excludes.push(...l);if(re("gantt"))he("gantt","appendExcludes",l,{line:s,unit:"normalized"});break}case"includes":{const l=XL(a);n.includes.push(...l);if(re("gantt"))he("gantt","appendIncludes",l,{line:s,unit:"normalized"});break}case"todayMarker":n.todayMarker=a.toLowerCase()==="off"?{off:true}:{off:false,style:a};break;case"weekday":n.weekStart=a.toLowerCase();break;case"weekend":n.weekendStart=a.toLowerCase();break}if(re("gantt")){const l=o.name==="weekday"?"weekStart":o.name==="weekend"?"weekendStart":o.name;if(o.name!=="excludes"&&o.name!=="includes"&&(o.name!=="tickInterval"||l0.test(a)))he("gantt",`set:${l}`,n[l],{line:s,unit:"normalized"})}}else if(o.kind==="click"){n.clicks.push({taskId:o.taskId,action:o.action,rest:o.rest,line:s});if(re("gantt"))he("gantt","addClick",n.clicks.at(-1),{line:s,unit:"normalized"})}else if(o.kind==="section"){n.sections.push({label:o.value,taskIndexes:[],line:s});r=n.sections.length-1;if(re("gantt"))he("gantt","addSection",{index:r,...n.sections[r]},{line:s,unit:"normalized"})}else if(o.kind==="task"){const{label:a,meta:l}=o;if(l.id!==void 0){if(i.has(l.id))throw new Di("GANTT_DUPLICATE_TASK_ID",`Duplicate task id "${l.id}"`,s);i.add(l.id)}const c={index:n.tasks.length,id:l.id,label:a,tags:l.tags,start:l.start,end:l.end,sectionIndex:r,line:s};n.tasks.push(c);if(re("gantt"))he("gantt","addTask",c,{line:s,unit:"normalized"});n.sections[r].taskIndexes.push(c.index);if(re("gantt"))he("gantt","attachTask",{sectionIndex:r,taskIndex:c.index,taskId:c.id},{line:s,unit:"normalized"})}}if(n.todayMarker?.style!==void 0)wg(n.todayMarker.style);return n}function Sle(e,t){return u0(e,Wf(t))}function Wf(e){if(!e)return{};const t={};const n=Mt(e,["title"]);if(typeof n==="string"&&n.trim()!=="")t.title=n;const i=Mt(e,["displayMode"]);const r=Sn(e,["gantt"]);const o=r?Mt(e,["gantt","displayMode"]):void 0;const s=o??i;if(typeof s==="string"&&s.toLowerCase()==="compact")t.displayMode="compact";const a=Mt(e,["gantt","barHeight"]);if(typeof a==="number"&&Number.isFinite(a)&&a>0)t.barHeight=a;const l=Mt(e,["gantt","topAxis"]);if(l===true)t.topAxis=true;const c=Mt(e,["gantt","axisFormat"]);if(typeof c==="string")t.axisFormat=c;const d=Mt(e,["gantt","tickInterval"]);if(typeof d==="string"){const u=d.match(l0);if(u)t.tickInterval={count:Number(u[1]),unit:u[2]}}return t}function u0(e,t){if(t.title!==void 0&&e.title===void 0)e.title=t.title;if(t.displayMode)e.displayMode=t.displayMode;if(t.barHeight!==void 0)e.barHeight=t.barHeight;if(t.topAxis)e.topAxis=true;if(t.axisFormat!==void 0&&e.axisFormat===void 0)e.axisFormat=t.axisFormat;if(t.tickInterval!==void 0&&e.tickInterval===void 0)e.tickInterval=t.tickInterval;return e}import{decodeXML as TY}from"entities";var LY=/&amp;((?: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 zf(e){return e.replace(LY,(t,n)=>{const i=n===void 0?TY(t):`&${n}`;return dn(i,i)})}var e2=1;var t2=5;var m0=256;var AY=/^title\s+(.+)$/i;var IY=/^section\s+(.+)$/i;var FY=/^([^:]+):\s*([+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?)\s*(?::\s*(.*))?$/;var NY=/^([^:]+):\s*([^:]+)(?::\s*(.*))?$/;function $Y(e){return e.replace(/<br\s*\/?>/gi,"\n").replace(/\\n/g,"\n").replace(/<\/?(?:sub|sup|small|mark)\s*>/gi,"").replace(/\*\*(.+?)\*\*/g,"<b>$1</b>").replace(/(?<!\*)\*([^\s*](?:[^*]*[^\s*])?)\*(?!\*)/g,"<i>$1</i>").replace(/~~(.+?)~~/g,"<s>$1</s>")}function Eg(e){return $Y(e).split(/\r?\n/).map(t=>t.trim()).join("\n")}function _Y(e){return Eg(e).split("\n").filter(Boolean).join(" / ")}function Pg(e){return so(Eg(e))}function Mg(e,t=false){const n=t?_Y(e):Eg(e);const i=so(n);if(i===n)return{value:i};const r=ur(Rt(n),vl,o=>so(o));return JSON.stringify(f0(r))===JSON.stringify(f0(Rt(i)))?{value:i}:{value:i,content:{value:i,prepared:r}}}function f0(e){return e.lines.map(t=>t.map(({text:n,bold:i,italic:r,underline:o,strikethrough:s})=>({text:n,bold:i,italic:r,underline:o,strikethrough:s})))}function Ha(e,t){return JSON.stringify([e,t?.value===e?f0(t.prepared):null])}function kg(e){return Dn(e)}function h0(e){return e.startsWith("%%")||e.startsWith("#")||e.startsWith("%")}function DY(e){return Number.isFinite(e)&&e>=e2&&e<=t2}function n2(e,t,n){for(let i=t;i<e.length;i++){const r=e[i].trim();if(h0(r)&&!/^#\w+;/.test(r))continue;const o=kg(zf(e[i].trim()));if(!o)continue;if(h0(o))continue;const s=vt(e,i);if(s===void 0){const a=n.issue?.({code:"unclosed_accdescr",lineIndex:i,statement:o,detail:'Journey accDescr block is missing a closing "}"'});if(a==="stop")return;return}if(s?.form==="block"){n.accDescr?.(Pg(kg(zf(s.value))),i);i=s.endIndex;const a=kg(zf(s.suffixLine??""));const l=vt([a],0);if(l?.form==="inline"){const c=Pg(l.value);if(l.title)n.accTitle?.(c,i);else n.accDescr?.(c,i);continue}if(ZL(a))n.statementDelimiter?.(i);if(n.entitySemicolon)Cg(s.suffixLine??"",()=>n.entitySemicolon(i));for(const c of Cg(a)){const d=JL(c,s.endIndex,n);if(d==="stop")return}continue}if(s?.form==="inline"){const a=Pg(kg(zf(s.value)));if(s.title)n.accTitle?.(a,i);else n.accDescr?.(a,i);continue}if(ZL(o))n.statementDelimiter?.(i);if(n.entitySemicolon)Cg(e[i].trim(),()=>n.entitySemicolon(i));for(const a of Cg(o)){const l=JL(a,i,n);if(l==="stop")return}}}function JL(e,t,n){const i=(c,d)=>n.issue?.({code:c,lineIndex:t,statement:e,detail:d});const r=vt([e],0);if(r){const c=Pg(r.value);if(r.title)n.accTitle?.(c,t);else n.accDescr?.(c,t);return}const o=e.match(AY);if(o){const c=Mg(o[1]);if(!c.value)return i("empty_title",`Journey title is empty: "${e}"`);n.title?.(c.value,t,c.content);return}const s=e.match(IY);if(s){const c=Mg(s[1]);if(!c.value){return i("section_colon",`Journey section labels must not contain ':': "${e}"`)}n.section?.(c.value,t,c.content);return}const a=e.match(FY);if(a){const c=Mg(a[1]);if(!c.value)return i("empty_task_text",`Journey task text is empty: "${e}"`);const d=a[2];const u=Number(d);if(!DY(u))return i("invalid_score",QL(c.value,d));const f=(a[3]??"").split(",").map(h=>Mg(h,true)).filter(h=>h.value);n.task?.(c.value,u,f.map(h=>h.value),t,c.content,f.some(h=>h.content)?f.map(h=>h.content):void 0);return}const l=e.match(NY);if(l){const c=Eg(l[1]);const d=l[2].trim();if(c&&d)return i("invalid_score",QL(c,d))}return i("unrecognized_line",`Invalid user journey line: "${e}". Expected title, section, accessibility metadata, or "Task name: 3: Actor"`)}function QL(e,t){return`Journey task "${e}" has invalid score ${t}. Expected a finite number from ${e2} through ${t2}`}var OY=/^&(?:[a-zA-Z][a-zA-Z0-9]{1,31}|#[0-9]{1,7}|#x[0-9a-fA-F]{1,6});$/;var BY=34;function i2(e,t,n,i=0){return t>=i&&n-t+1<=BY&&OY.test(e.slice(t,n+1))}function ZL(e){let t=-1;for(let n=0;n<e.length;n++){if(e[n]==="&")t=n;if(e[n]!==";")continue;if(i2(e,t,n))continue;return true}return false}function Cg(e,t){if(!e.trim())return[];if(!e.includes(";"))return[e.trim()];const n=[];let i=0;let r=-1;for(let o=0;o<e.length;o++){if(e[o]==="&")r=o;if(e[o]!==";")continue;if(i2(e,r,o,i)){t?.();continue}n.push(e.slice(i,o));i=o+1;r=-1}n.push(e.slice(i));return n.map(o=>o.trim()).filter(o=>o&&!h0(o))}import{decodeXML as Rg}from"entities";var vg={wholeLine:e=>/^(?:pie(?:\s+showData)?\s+)?title(?:\s|$)/i.test(e)};function r2(e){if(!e.authoredFamilyLines)return e.familyLines;const t=/^\s*"(?:[^"\\]|\\.)*"/;const n=fa(e.authoredFamilyLines,vg).map((i,r)=>{const o=WY(i,r===0?"header":"body");if(o)return o.decodedPrefix+o.authoredTitle;const s=t.exec(i)?.[0];return s===void 0?Rg(i):s+Rg(i.slice(s.length))}).join("\n");return Xu(n).familyLines}function WY(e,t){const n=Rg(e);const i=t==="header"?n.match(/^(\s*pie\b(?:\s+showData\b)?\s+title)(\s+)(.+)$/i):n.match(/^(\s*title)(\s+)(.+)$/i);if(!i)return null;const r=i[1].length;const o=r+i[2].length;let s=0;let a=0;const l=()=>{let d=e[a];let u=1;if(d==="&"){const f=e.slice(a).match(/^&(?:#(?:x[0-9a-f]+|\d+)|[a-z][a-z0-9]+);/i)?.[0];if(f){const h=Rg(f);if(h!==f){d=h;u=f.length}}}return{text:d,length:u,entity:u>1}};while(s<r&&a<e.length){const d=l();if(n.slice(s,s+d.text.length)!==d.text)return null;s+=d.text.length;a+=d.length}if(s!==r)return null;let c=false;while(s<o&&a<e.length){const d=l();if(d.entity&&c)break;if(!/^\s+$/u.test(d.text))return null;s+=d.text.length;a+=d.length;c=true}if(!c)return null;return{decodedPrefix:n.slice(0,s),authoredTitle:e.slice(a)}}var zY=128;var GY=256;var Tg=class extends Error{code="INVALID_STYLE_COLOR";subject;property;value;constructor(t,n,i){const r=t.slice(0,zY);const o=i.slice(0,GY);super(Je({what:`${r}: ${n} ${JSON.stringify(o)} is not a CSS color`,expectedForm:"a drawable color name, hex color, rgb()/rgba(), hsl()/hsla(), transparent, currentColor, none, or var(--name)",example:`${n}: #f96`}).message);this.name="QuadrantStyleColorError";this.subject=r;this.property=n;this.value=o}};var HY=/^[A-Za-z_][\w-]*$/;var jY=/^\d+(?:\.\d+)?$/;var YY=/^\d+(?:\.\d+)?(?:px)?$/;var qY=/^[#\w][\w#(),.%+\s/~-]*$/;function XY(e){const t=[];let n=0;let i=0;for(let r=0;r<e.length;r++){const o=e[r];if(o==="(")i++;else if(o===")"){i--;if(i<0)return null}else if(o===","&&i===0){t.push(e.slice(n,r));n=r+1}}if(i!==0)return null;t.push(e.slice(n));return t}function p0(e,t="quadrant point style"){const n=e.trim();if(n.length===0)return{ok:true,style:void 0};const i={};let r=false;const o=XY(n);if(!o)return{ok:false,error:"style functions have unbalanced parentheses"};for(const s of o){const a=s.trim();if(!a)continue;const l=a.match(/^([a-z][\w-]*)\s*:\s*(.+)$/i);if(!l)return{ok:false,error:`malformed style entry "${a}" (expected key: value)`};const c=l[1].toLowerCase();const d=l[2].trim();switch(c){case"radius":{if(!jY.test(d))return{ok:false,error:`radius must be a non-negative number, got "${d}"`};i.radius=Number.parseFloat(d);break}case"color":{if(mn(d,true)===void 0)throw new Tg(t,"color",d);i.color=d;break}case"stroke-color":{if(mn(d,true)===void 0)throw new Tg(t,"stroke-color",d);i.strokeColor=d;break}case"stroke-width":{if(!YY.test(d))return{ok:false,error:`stroke-width must be a number with optional px suffix, got "${d}"`};i.strokeWidth=d;break}default:{if(!qY.test(d))return{ok:false,error:`style property "${c}" has unsupported characters: "${d}"`};i.extra=i.extra??[];i.extra.push(`${c}: ${d}`);break}}r=true}return{ok:true,style:r?i:void 0}}function o2(e){const t=e.trim().match(/^([A-Za-z_][\w-]*)\s+(.+)$/);if(!t)return{ok:false,error:`expected "classDef <name> <styles>", got "classDef ${e.trim()}"`};const n=t[1];const i=p0(t[2],`quadrant classDef ${n}`);if(!i.ok)return{ok:false,error:`classDef ${n}: ${i.error}`};if(!i.style)return{ok:false,error:`classDef ${n} has no style entries`};return{ok:true,name:n,style:i.style}}function Dle(e){return HY.test(e)}var UY=/\s*:::\s*([A-Za-z_][\w-]*)\s*$/;function s2(e){const t=e.match(UY);if(!t)return{label:e};return{label:e.slice(0,t.index).trim(),className:t[1]}}function a2(e,t,n){const i=e.className&&t&&Object.hasOwn(t,e.className)?t[e.className]:void 0;const r={radius:e.style?.radius??i?.radius??n.radius};const o=e.style?.color??i?.color;const s=e.style?.strokeColor??i?.strokeColor;const a=e.style?.strokeWidth??i?.strokeWidth;if(o!==void 0)r.fill=o;if(s!==void 0)r.stroke=s;if(a!==void 0)r.strokeWidth=a;return r}function Ole(e){if(!e)return"";const t=[];if(e.radius!==void 0)t.push(`radius: ${e.radius}`);if(e.color!==void 0)t.push(`color: ${e.color}`);if(e.strokeColor!==void 0)t.push(`stroke-color: ${e.strokeColor}`);if(e.strokeWidth!==void 0)t.push(`stroke-width: ${e.strokeWidth}`);if(e.extra!==void 0)t.push(...e.extra);return t.join(", ")}var l2={subject:"Flowchart label entity",example:'A["#35;"]'};var c2=new RegExp(`(${qx})`,"i");var d2=/(&#(?:\d+|[xX][0-9a-fA-F]+);)/;function VY(e){return e.split(c2).map((t,n)=>n%2===1?t:t.split(d2).map((i,r)=>r%2===1?i:rn(i,l2)).join("")).join("")}function ja(e,t=false){const n=t?e:Lg(e);const i=t||n!==e;const r=i&&n.length>=2&&n.startsWith("`")&&n.endsWith("`");const o=r?`\`${n.slice(1,-1).trim()}\``:n.trim();const s=r?yt(n.slice(1,-1).trim(),false):j1(o);if(!s.includes("#")&&!s.includes("\uFB02\xB0"))return{text:s,markdown:r};const a=VY(s);const l=ur(Rt(s),/&#(?:\d+|[xX][0-9a-fA-F]+);|#\w+;/g,d=>d.startsWith("&")?d:rn(d,l2));const c=ca(l)===Y1(a)?void 0:{value:a,prepared:l,authored:o};return{text:a,markdown:r,...c?{labelContent:c}:{}}}function Lg(e){if(e.length<2||!e.startsWith('"'))return e;if(e.endsWith('"'))return e.slice(1,-1);const t=e.indexOf('"',1);return t>0&&!e.startsWith('"`')&&!e.includes('"',t+1)?e.slice(1,t)+e.slice(t+1):e}var u2='"<';function KY(e){return e.replace(/&+(?=#\d+;)/g,t=>"#amp;".repeat(t.length))}function JY(e){return e.split(d2).map((t,n)=>n%2===1?t:KY(dn(t,u2).replace(/\\(?=n)/g,"#92;"))).join("")}function Yle(e,t){if(t?.value===e&&t.authored!==void 0){const l=new RegExp(`(${qx}|<br\\s*\\/?>)`,"gi");return t.authored.split(l).map((c,d)=>d%2?c:gr(c,u2)).join("")}const n=e.split(/\r?\n/).map(l=>l.split(c2).map((c,d)=>d%2===1?c:JY(c)).join(""));const i=n.join("<br>");const r=i.length-i.trimStart().length;const o=i.trim()===""?0:i.length-i.trimEnd().length;if(r===0&&o===0)return i;const s=l=>[...l].map(c=>`#${c.codePointAt(0)};`).join("");const a=i.slice(r,i.length-o);return s(i.slice(0,r))+(o>0?a.replace(/&+$/,l=>"#amp;".repeat(l.length)):a)+s(i.slice(i.length-o))}var f2={"rect":{aliases:["proc","process","rectangle"],geometry:"rectangle",exact:true,description:"Process"},"rounded":{aliases:["event"],geometry:"rounded",exact:true,description:"Event"},"stadium":{aliases:["pill","terminal"],geometry:"stadium",exact:true,description:"Terminal point"},"cyl":{aliases:["cylinder","database","db"],geometry:"cylinder",exact:true,description:"Database"},"diam":{aliases:["decision","diamond","question"],geometry:"diamond",exact:true,description:"Decision"},"hex":{aliases:["hexagon","prepare"],geometry:"hexagon",exact:true,description:"Prepare conditional"},"lean-r":{aliases:["in-out","lean-right"],geometry:"lean-r",exact:true,description:"Data input/output"},"lean-l":{aliases:["lean-left","out-in"],geometry:"lean-l",exact:true,description:"Data output/input"},"trap-b":{aliases:["priority","trapezoid","trapezoid-bottom"],geometry:"trapezoid",exact:true,description:"Priority action"},"trap-t":{aliases:["inv-trapezoid","manual","trapezoid-top"],geometry:"trapezoid-alt",exact:true,description:"Manual operation"},"circle":{aliases:["circ"],geometry:"circle",exact:true,description:"Start"},"dbl-circ":{aliases:["double-circle"],geometry:"doublecircle",exact:true,description:"Stop"},"fr-rect":{aliases:["framed-rectangle","subproc","subprocess","subroutine"],geometry:"subroutine",exact:true,description:"Subprocess"},"odd":{aliases:[],geometry:"asymmetric",exact:true,description:"Odd"},"bang":{aliases:[],geometry:"circle",exact:true,description:"Bang"},"notch-rect":{aliases:["card","notched-rectangle"],geometry:"rectangle",exact:true,description:"Card"},"cloud":{aliases:[],geometry:"rounded",exact:true,description:"Cloud"},"hourglass":{aliases:["collate"],geometry:"diamond",exact:true,description:"Collate"},"bolt":{aliases:["com-link","lightning-bolt"],geometry:"rectangle",exact:true,description:"Com link"},"brace":{aliases:["brace-l","comment"],geometry:"rectangle",exact:true,description:"Comment"},"brace-r":{aliases:[],geometry:"rectangle",exact:true,description:"Comment right"},"braces":{aliases:[],geometry:"rectangle",exact:true,description:"Comment both"},"datastore":{aliases:["data-store"],geometry:"cylinder",exact:true,description:"Data store"},"delay":{aliases:["half-rounded-rectangle"],geometry:"rounded",exact:true,description:"Delay"},"h-cyl":{aliases:["das","horizontal-cylinder"],geometry:"cylinder",exact:true,description:"Direct access storage"},"lin-cyl":{aliases:["disk","lined-cylinder"],geometry:"cylinder",exact:true,description:"Disk storage"},"curv-trap":{aliases:["curved-trapezoid","display"],geometry:"rounded",exact:true,description:"Display"},"div-rect":{aliases:["div-proc","divided-process","divided-rectangle"],geometry:"rectangle",exact:true,description:"Divided process"},"doc":{aliases:["document"],geometry:"rectangle",exact:true,description:"Document"},"tri":{aliases:["extract","triangle"],geometry:"trapezoid",exact:true,description:"Extract"},"fork":{aliases:["join"],geometry:"rectangle",exact:true,description:"Fork/join"},"win-pane":{aliases:["internal-storage","window-pane"],geometry:"rectangle",exact:true,description:"Internal storage"},"f-circ":{aliases:["filled-circle","junction"],geometry:"circle",exact:true,description:"Junction"},"lin-doc":{aliases:["lined-document"],geometry:"rectangle",exact:true,description:"Lined document"},"lin-rect":{aliases:["lin-proc","lined-process","lined-rectangle","shaded-process"],geometry:"subroutine",exact:true,description:"Lined/shaded process"},"notch-pent":{aliases:["loop-limit","notched-pentagon"],geometry:"hexagon",exact:true,description:"Loop limit"},"flip-tri":{aliases:["flipped-triangle","manual-file"],geometry:"trapezoid-alt",exact:true,description:"Manual file"},"sl-rect":{aliases:["manual-input","sloped-rectangle"],geometry:"lean-r",exact:true,description:"Manual input"},"docs":{aliases:["documents","st-doc","stacked-document"],geometry:"rectangle",exact:true,description:"Multi-document"},"st-rect":{aliases:["processes","procs","stacked-rectangle"],geometry:"rectangle",exact:true,description:"Multi-process"},"flag":{aliases:["paper-tape"],geometry:"rectangle",exact:true,description:"Paper tape"},"sm-circ":{aliases:["small-circle","start"],geometry:"circle",exact:true,description:"Start (small)"},"fr-circ":{aliases:["framed-circle","stop"],geometry:"doublecircle",exact:true,description:"Stop (framed)"},"bow-rect":{aliases:["bow-tie-rectangle","stored-data"],geometry:"cylinder",exact:true,description:"Stored data"},"cross-circ":{aliases:["crossed-circle","summary"],geometry:"circle",exact:true,description:"Summary"},"tag-doc":{aliases:["tagged-document"],geometry:"rectangle",exact:true,description:"Tagged document"},"tag-rect":{aliases:["tag-proc","tagged-process","tagged-rectangle"],geometry:"rectangle",exact:true,description:"Tagged process"},"text":{aliases:[],geometry:"rectangle",exact:true,description:"Text block"}};var h2=(()=>{const e=new Map;for(const[t,n]of Object.entries(f2)){e.set(t,t);for(const i of n.aliases)e.set(i,t)}return e})();function m2(e){const t=h2.get(e.trim().toLowerCase());if(!t)return null;const n=f2[t];return{canonical:t,geometry:n.geometry,exact:n.exact,description:n.description}}function Xle(){return[...h2.keys()].sort()}var p2={subject:"State text entity",example:"A : I #9829; states"};var QY=/#\w+;/g;var ZY=e=>rn(e,p2);function Ag(e){return y2(yt(e),e)}function g2(e){const t=e.map(n=>n.startsWith('"')&&n.endsWith('"')?n.slice(1,-1):n);return y2(e.map(n=>yt(n)).join("\n"),t.join("\n").replace(/\r\n?|\n/g,"<br/>"))}function y2(e,t){const n=rn(e,p2);if(!/#\w+;/.test(t))return{text:n};const i=ur(Rt(e),QY,ZY);return{text:n,content:Object.freeze({value:n,prepared:i,authored:t})}}function eq(e,t,n=""){const i=t?.value===e?t.authored:void 0;const r=i!==void 0?gr(i,n):dn(e,n).replace(/\\(?=n)/g,"#92;");return r.replace(/%%(?=\{)/g,"#37;%")}function Zle(e,t,n){const i=eq(e,t,";").replace(/\r\n?|\n/g,"<br/>").replace(/:(?=:|$)/g,"#58;");return tq(i,n)}function tq(e,t=""){return Un(t+e)===t+e?e:e.replace(/:/g,"#58;")}var Ig=String.raw`[\p{L}\p{N}_-]+`;var tce=new RegExp(`^${Ig}$`,"u");var nq=new RegExp(`^(${Ig})`,"u");var iq=/^[\w-]+/;function rq(e){const t=e.match(nq);return t?{id:t[1],length:t[1].length}:null}function g0(e){if(!e.startsWith(":::"))return null;const t=e.slice(3).match(iq);return t?{className:t[0],length:3+t[0].length}:null}function Fg(e){const t=rq(e);if(!t)return null;const n=g0(e.slice(t.length));if(!n||t.length+n.length!==e.length)return null;return{id:t.id,className:n.className}}var oq=/^note\s+(left|right)\s+of\s+([\w\p{L}-]+)\s*:\s*(.+)$/iu;var sq=/^state\s+(?:"([^"]+)"\s+as\s+)?([\w\p{L}-]+)\s*<<\s*(fork|join|choice|history|deephistory|H\*|H)\s*>>$/iu;var aq=/^-{2,}$/;var w2=/^([\w\p{L}-]*)\[(H\*?)\]$/u;var lq=/^[\w\p{L}-]+$/u;function M2(e){return lq.test(e)}function Ng(e){const t=e.match(/^state\s+([\w\p{L}-]+)$/u);return t?.[1]??(M2(e)?e:null)}function k2(e){if(/^scale\s+\d+\s+width$/i.test(e))return"scale";if(/^hide empty description$/i.test(e))return"hide_empty_description";return null}function C2(e){const t=e.match(/^(?:class|cssClass)\s+(.+?)\s+([\w-]+)$/iu);if(!t)return null;const n=t[1].split(",").map(i=>i.trim());if(n.some(i=>!M2(i)))return null;return{ids:n,className:t[2]}}function cq(e){return Un(e).replace(/#\w+;/g,"#")}function $g(e){const t=e.match(oq);if(!t)return null;return{side:t[1].toLowerCase(),target:t[2],text:t[3].trim()}}function _g(e){const t=e.match(np);if(!t)return null;return{side:t[1].toLowerCase(),target:t[2]}}function P2(e){const t=/^note\s+"([^"]*)"\s+as\s+([\w\p{L}-]+)\s*$/iu.exec(e);return t?{id:t[2],text:t[1]}:null}function E2(e){return Gu.test(e)}function Dg(e){const t=e.match(sq);if(!t)return null;const n=t[3].toLowerCase();const i=n==="h"||n==="history"?"history":n==="h*"||n==="deephistory"?"deep-history":n;return{id:t[2],stereotype:i,...t[1]!==void 0?{label:t[1]}:{}}}function Og(e){return aq.test(e)}function R2(e){const t=e.match(w2);if(!t)return null;return{base:t[1],deep:t[2]==="H*"}}function y0(e){return e?"H*":"H"}var x2=String.raw`\[\*\]|[\w\p{L}-]+\[H\*?\]|\[H\*?\]|[\w\p{L}-]+`;var dq=new RegExp(`^(${x2})(?::::([\\w-]+))?\\s*-->\\s*(${x2})(?::::([\\w-]+))?(?:\\s*:\\s*(.+))?$`,"u");function Bg(e){const t=e.match(dq);if(!t)return null;const n=t[5]?.trim();return{from:t[1],...t[2]?{fromClass:t[2]}:{},to:t[3],...t[4]?{toClass:t[4]}:{},...n?{label:n}:{}}}function v2(e){return w2.test(e)}function oce(e){return e==="deep-history"?"<<deephistory>>":`<<${e}>>`}var T2=/^direction\s+(TD|TB|LR|BT|RL)\s*$/i;var Wg=/^state\s+"([^"]+)"\s+as\s+([\w\p{L}-]+)\s*$/u;var Gf=/^state\s+(?:"([^"]+)"\s+as\s+)?([\w\p{L}-]+)\s*\{$/u;var zg=/^([\w\p{L}-]+)\s*:\s*(.+)$/u;var L2=/^classDef\s+([\w,-]+)\s+(.+)$/i;var A2=/^style\s+([\w\p{L},-]+)\s+(.+)$/iu;var I2=/^linkStyle\s+(default|[\d,\s]+)\s+(.+)$/;var uq=/\[\*\]|\[H\*?\]|[\w\p{L}](?:[\w\p{L}]|-(?!->))*(?:\[H\*?\])?/uy;var fq=/(?:\w|-(?!->))+/y;var hq=/(?:(?:classDef|class|style|note|scale|click|direction)(?=[ \t]|$)|end(?=[ \t]+note(?:[ \t]|$))|hide(?=[ \t]+empty[ \t]+description(?:[ \t]|$)))/iy;var mq=/(?:cssClass|linkStyle)(?=[ \t]|$)/y;var pq=/state[ \t]+/iy;var gq=/[\w\p{L}-]+/uy;var yq=/[ \t]+as[ \t]+/iy;var xq=/[ \t]+as(?=[ \t]|$)/iy;var b2=/[ \t]*(?:<<[^>\n]*>>|\[\[(fork|join|choice)\]\])/iy;var bq=/[ \t]*\{/y;var S2=/:::[ \t]*([\w-]+)/y;var Sq=/-{2,}(?=[ \t;}]|$)/y;function ns(e,t,n){e.lastIndex=n;return e.exec(t)?.[0]??null}function Js(e,t){while(e[t]===" "||e[t]===" ")t++;return t}function wq(e,t){return t>=e.length||" ;}:".includes(e[t])||e.startsWith("-->",t)}function F2(e,t){let n=t;while(e[n].openQuote&&n+1<e.length)n++;return n}function N2(e){const t=Sa(e);return t.map((n,i)=>{if(!n.noteOpen)return F2(t,i);let r=i;while(r+1<t.length&&t[r+1].noteBody)r++;return Math.min(r+1,t.length-1)})}function $2(e){const t=[];for(let T=0;T<e.length;T++){const A=T;T=F2(e,A);const R=e.slice(A,T+1).map(I=>I.text).join("\n");if(R||e[A].noteBody)t.push({text:R,line:A,noteBody:e[A].noteBody,noteOpen:e[A].noteOpen,commentGlued:e[T].commentGlued})}const n=(T,A)=>{const R=t[T].text;let I=t[T].line;let L=0;for(let $=R.indexOf("\n");$>=0&&$<A;$=R.indexOf("\n",$+1)){I++;L=$+1}return{line:I,column:A-L}};const i=[];const r=new Set;const o=new Set;const s=new Set;const a=new Set;const l=new Set;const c=new Set;const d=new Set;const u=(T,A)=>{if(t[T].text[A]!=="}")return;s.add(t[T].line);d.add(`${T}:${A}`)};let f=t.length-1;while(f>0&&!t[f].noteBody&&t[f].text.startsWith("//"))f--;const h=(T,A,R)=>{let I=T.length;if(R!==f)return I;let L=0;for(let B=A+1;B<I;B++)L+=T[B]==="}"?1:T[B]==="{"?-1:0;const $=Js(T,A+1);for(let B=0;B<m&&L>0;B++,L--){let F=I-1;while(T[F]===" "||T[F]===" ")F--;if(T[F]!=="}"||F<=$)break;I=F}return I};let m=0;let p=0;let g=0;let y=true;const w=(T,A,R)=>{if(!y)o.add(A);i.push({text:T,line:A});y=R};const S=T=>{const A=t[T+1];return A!==void 0&&!A.noteBody&&!A.noteOpen};const x=T=>{for(;;){const A=t[T.row].text;T.column=Js(A,T.column);if(T.column<A.length||m===0||!S(T.row))return;T.row++;T.column=0}};const M=(T,A)=>{const R=ns(uq,t[T.row].text,T.column);if(R===null)return null;let I=R;const L={row:T.row,column:T.column+R.length};const $=t[T.row].text.slice(L.column,L.column+1);A.push(/^[ \t\n]/.test($)||$===""&&!t[T.row].commentGlued);const B={...L};x(B);if(t[B.row].text.startsWith(":::",B.column)){B.column+=3;x(B);const F=ns(fq,t[B.row].text,B.column);if(F===null)return null;I+=`:::${F}`;L.row=B.row;L.column=B.column+F.length}if(!wq(t[L.row].text,L.column))return null;u(L.row,L.column);T.row=L.row;T.column=L.column;return I};const b=()=>{const T={row:p,column:g};const A=[];const R=M(T,A);if(R===null)return null;let I=R;const L={...T};x(L);const $=t[L.row].text.startsWith("-->",L.column);let B;if($){L.column+=3;x(L);B=n(L.row,L.column).line;const H=M(L,A);if(H===null)return null;I+=` --> ${H}`;T.row=L.row;T.column=L.column}const F=t[T.row].text;const z=Js(F,T.column);const _={text:I,...B!==void 0?{toLine:B,nameBlanks:A}:{}};if(F[z]===":"){const H=h(F,z,T.row);if(H<F.length&&!/;|::/.test(cq(F.slice(z+1,H))))l.add(t[T.row].line);const D=F.slice(z,H).trimEnd();const j={start:n(T.row,z),end:n(T.row,H)};const W=$?-1:R.indexOf(":::");if(W<0)Object.assign(_,{text:`${I} ${D}`,textSpan:j});else Object.assign(_,{also:`${R.slice(0,W)} ${D}`,alsoSpan:j});T.column=H}p=T.row;g=T.column;return _};const C=(T,A,R,I)=>{const L=t[p].line;const $=`state ${A}${R}`;const B=Js(T,I);S2.lastIndex=B;const F=S2.exec(T);if(F!==null){const D=Js(T,B+F[0].length);if(D<T.length&&T[D]!==";"&&T[D]!=="}")return null;u(p,D);c.add(L);g=B+F[0].length;return{text:$,opens:false,also:`${R}:::${F[1]}`}}if(T.startsWith(":::",B)||T.includes("{",B))return null;const z=h(T,B,p);if(z<T.length)l.add(L);const _=T.slice(B+1,z).trim();if(_.includes(":"))c.add(L);const H={start:n(p,B),end:n(p,z)};g=z;return{text:$,opens:false,..._?{also:`${R} : ${_}`,alsoSpan:H}:{}}};const P=T=>{const A=t[p].text;let R=T;let I="";let L;if(A[R]==='"'){const D=A.indexOf('"',R+1);const j=D<0?null:ns(yq,A,D+1);if(j===null)return null;I=`${A.slice(R,D+1)} as `;L={start:n(p,R),end:n(p,D+1)};R=D+1+j.length}const $=ns(gq,A,R);if($===null)return null;R+=$.length;if(!I&&ns(xq,A,R)!==null)return null;if(I&&A[Js(A,R)]===":"){const D=C(A,I,$,R);return D&&{...D,textSpan:L}}b2.lastIndex=R;const B=b2.exec(A);if(B!==null)R+=B[0].length;const F=B===null?null:B[1]!==void 0?`<<${B[1]}>>`:B[0];const z=ns(bq,A,R);let _=z!==null;const H=Js(A,R);if(z!==null)R+=z.length;else if(R<A.length&&!" ;}".includes(A[R]))return null;else if(F===null&&H===A.length&&S(p)&&t[p+1].text.startsWith("{")){p++;R=1;_=true}else if(I&&F===null&&H<A.length){if(A[H]!==";"&&A[H]!=="}")return null;u(p,H)}g=R;return{text:`state ${I}${$}${F===null?"":` ${F.trim()}`}${_?" {":""}`,opens:_,...L?{textSpan:L}:{}}};let E={statements:0,depth:0,column:0};while(p<t.length){const T=t[p];if(g===0){y=true;E={statements:i.length,depth:m,column:0};if(T.noteBody){i.push({text:T.text,line:T.line,noteBody:true});p++;continue}const D=T.noteOpen?T.text.match(Kb):null;if(D){i.push({text:`note ${D[1]} of ${D[2]}`,line:T.line},{text:D[3],line:T.line,noteBody:true});p++;continue}}const A=T.text;g=Js(A,g);if(g>=A.length){p++;g=0;continue}const R=T.line;const I=A[g];if(I===";"){r.add(R);g++;y=true;continue}if(I==="}"){if(m===0&&!d.has(`${p}:${g}`))a.add(R);i.push({text:"}",line:R});m=Math.max(0,m-1);g++;y=true;continue}const L=m>0?ns(Sq,A,g):null;if(L!==null){i.push({text:L,line:R});g+=L.length;y=true;continue}if(ns(hq,A,g)!==null||ns(mq,A,g)!==null){const D=A.slice(g);w(D,R,false);p++;g=0;if(np.test(D)&&t[p]?.noteBody===false){const j=t.findIndex((W,O)=>O>=p&&Gu.test(W.text));for(;j>0&&p<j;p++)i.push({text:t[p].text,line:t[p].line,noteBody:true})}continue}const $=p;const B=g;const F=ns(pq,A,g);let z=F===null?null:P(g+F.length);const _=F!==null&&!F.startsWith("state");if(_&&z!==null&&!z.opens){const D=Js(t[p].text,g);if(t[p].text.startsWith("-->",D)||t[p].text[D]===":"){p=$;g=B;z=null}}const H=z??(F===null||_?b():null);if(H!==null){w(H.text,R,H.opens??false);const D=i.at(-1);if(H.textSpan)D.textSpan=H.textSpan;if(H.toLine!==void 0)D.toLine=H.toLine;if(H.nameBlanks)D.nameBlanks=H.nameBlanks;if(H.opens){D.opens=true;m++}if(H.also!==void 0)i.push({text:H.also,line:R,...H.alsoSpan?{textSpan:H.alsoSpan}:{},...z!==null?{afterAlias:true}:{}});if(p!==$)E={statements:i.length,depth:m,column:g};continue}i.length=E.statements;m=E.depth;o.delete(R);r.delete(R);s.delete(R);a.delete(R);l.delete(R);c.delete(R);i.push({text:A.slice(E.column).trim(),line:R});p++;g=0}const k=i.filter((T,A)=>{if(!T.noteBody||T.text)return true;const R=I=>{let L=A;while(i[L]?.noteBody&&!i[L].text)L+=I;return!i[L]?.noteBody};return!R(-1)&&!R(1)});const v=[];for(const T of k){if(T.opens)v.push(T.line);else if(T.text==="}"&&!T.noteBody)v.pop()}return{statements:k,semicolonLines:[...r],juxtaposedLines:[...o],braceNameLines:[...s],unopenedBraceLines:[...a],braceTextLines:[...l],aliasSuffixLines:[...c],unclosedLines:v}}function _2(e){const t=new Set;for(const m of e){const p=m.noteBody?null:m.text.match(Gf);if(p)t.add(p[2])}const n=new Set(t);const i=new Map;const r=new Map;const o=new Map;const s=[];let a;const l=(m,p)=>{n.add(m);if(p&&!i.has(m)&&!s.some(g=>g.parent===m))i.set(m,p)};for(const m of e){const p=s.at(-1);const g=p?{parent:p.parent,region:p.region}:void 0;r.set(m,g);if(m.noteBody)continue;const y=m.text;const w=y.match(Gf);if(w){const M=w[2];if(s.some(b=>b.parent===M)){a=`Duplicate State composite identity "${M}" cannot contain itself`;break}l(M,g);if(!i.has(M))i.set(M,g);Ve("nesting",s.length+1);s.push({parent:M,region:o.get(M)??0});continue}if(y==="}"){s.pop();continue}if(Og(y)&&p){o.set(p.parent,++p.region);continue}const S=Bg(y);if(S){for(const M of[S.from,S.to])if(M!=="[*]"&&!v2(M))l(M,g);continue}const x=$g(y)?.target??_g(y)?.target??Dg(y)?.id??Fg(y)?.id??y.match(Wg)?.[2]??y.match(zg)?.[1]??Ng(y);if(x)l(x,g)}const c=m=>m?{parent:m.parent,...(o.get(m.parent)??0)>0?{region:m.region??0}:{}}:void 0;const d=yi(n);const u=(m,p)=>d(`${m}__r${p+1}`,["state-region",m,p]);const f=m=>m.region===void 0?m.parent:u(m.parent,m.region);const h=new Map;for(const m of t){if(a||h.has(m))continue;const p=[],g=new Set;let y=m;while(y!==void 0&&!h.has(y)){if(g.has(y)){a=`State containment cycle: ${[...p,y].join(" -> ")}`;break}g.add(y);p.push(y);y=i.get(y)?.parent}if(a)break;let w=y===void 0?0:h.get(y);for(const S of p.reverse()){w+=c(i.get(S))?.region!==void 0?2:1;Ve("nesting",w);h.set(S,w)}}for(const[m,p]of h)if((o.get(m)??0)>0)Ve("nesting",p+1);return{compositeIds:t,issue:a,ownerOf:m=>c(i.get(m)),scopeOf:m=>c(r.get(m)),authored:n,ownedIds:()=>i.keys(),regionId:u,scopeId:f,floatingNoteId:m=>d(`note:${m}`,["state-floating-note",m]),pseudostateId:(m,p)=>{const g=c(r.get(p));const y=g?f(g):"";return d(`${y}_${m}`,["state-pseudo",g?.parent??"",g?.region??-1,m])}}}function Gg(){const e=new Map;return{close(t,n){const i=[];const r=new Set;for(const o of n){if(o.trim()===""||r.has(o)||e.has(o)&&e.get(o)!==t)continue;r.add(o);e.set(o,t);i.push(o)}return i},ownerOf:t=>e.get(t)}}function j2(e,t){if(e===t)return Hf(t);try{return Hf(eL(e))}catch(n){if(n instanceof Ri)throw n;return Hf(t)}}function Hf(e){const t=e.split("\n");const n=t.find(f=>f.trim().length>0&&!f.trim().startsWith("%%"))?.trim()??"";const i=/^stateDiagram(?:-v2)?(?=$|[\s;%])/i.test(n);const r=i?[]:Cq(t);const o=Mq(i?Sa(t).filter((f,h,m)=>f.noteBody||f.text.length>0&&(!f.text.startsWith("//")||m[h-1]?.openQuote===true)).map(f=>f.text):r.map(f=>f.text));const s=o.length-r.length;const a=s>0?[...Array(s+1),...r.slice(1).map(f=>f.breaks)]:r.map(f=>f.breaks);if(o.length===0){throw new Error("Empty mermaid diagram")}const l=o[0];const c=wP(l,"strict");const d=c.kind==="registered"?c.familyId:dP(l);if(d==="state"){return Dq(o)}if(d==="flowchart")return Lq(o,a);if(c.kind==="unknown")throw new Error(`Unknown Mermaid diagram header: ${l}`);const u=c.kind==="registered"?c.familyId:c.match.family.id;throw new Error(`Mermaid family "${u}" is not a graph family; use the family-neutral agent parser`)}function Mq(e){const t=e.length>0?kq(e[0]):void 0;return t?[t.header,...t.statements,...e.slice(1)]:e}function kq(e){if(!e.includes(";"))return void 0;const t=e.match(/^(?:(?:graph|flowchart|swimlane)(?:[ \t]+(?:TD|TB|LR|BT|RL|[<>^v])(?![\w-]))?|stateDiagram(?:-v2)?)(?=$|[\s;])/i);if(!t)return void 0;const n=e.slice(t[0].length).trim();if(!n.startsWith(";"))return void 0;return{header:t[0],statements:/^stateDiagram/i.test(t[0])?[n]:q2(n)}}function Cq(e){return lg(e).flatMap(t=>{const n=t.text.trim();if(!n||n.startsWith("%%"))return[];const i=t.text.length-t.text.trimStart().length;return[{text:n,...t.joined?{breaks:t.joined.map(r=>r.at-i)}:{}}]})}function Y2(e){const t=e.indexOf("[");return t>0&&t<e.length-1&&e.endsWith("]")?{id:e.slice(0,t).trim(),title:e.slice(t+1,-1)}:void 0}function Pq(e){const t=Y2(e);if(t){const o=ja(t.title);const s={label:o.text,...o.labelContent?{labelContent:o.labelContent}:{}};if(x0(t.id))return{id:t.id,...s,generated:false,identity:t.id,titled:true};if(Ww(t.id)){throw new Error(`Invalid flowchart subgraph identifier ${JSON.stringify(t.id)}`)}const a=Lg(t.id).trim();if(x0(a))return{id:a,...s,generated:false,identity:a,titled:true};return{id:D2(a),...s,generated:true,identity:a,titled:true}}const n=ja(e);const i=Lg(e).trim();const r=i!==e&&/^`[\s\S]*`$/.test(i)?i.slice(1,-1).trim():i;if(x0(r)){return{id:r,label:n.text,...n.labelContent?{labelContent:n.labelContent}:{},generated:false,identity:r,titled:false}}return{id:D2(r),label:n.text,...n.labelContent?{labelContent:n.labelContent}:{},generated:true,identity:r,titled:false}}function D2(e){return e.replace(/<\/?[a-z][^<>]*>/gi," ").trim().replace(/\s+/g,"_").replace(/[^\p{L}\p{N}_-]/gu,"").replace(/-{2,}/g,"_")||"group"}function x0(e){return e.length>0&&tc(e)===e.length}function q2(e){return Rf(e).map(t=>t.text)}function O2(e){return e&&e[1].split(",").every(t=>t===""||tc(t)===t.length)?e:null}function Eq(e){return/^(?:click|href)\s+/i.test(e.trim())}function Rq(e,t){const n=t.trim().match(/^(?:click\s+)?(\S+)\s+(?:href\s+)?(?:"((?:\\.|[^"])*)"|(https?:\/\/\S+|mailto:\S+))/i);if(!n)return;const i=(n[2]??n[3]??"").replace(/\\(["\\])/g,"$1");if(!/^(?:https?:|mailto:)/i.test(i))return;const r=e.nodes.get(n[1]);if(r){r.href=i;if(re("flowchart"))he("flowchart","set-interaction",{id:r.id,href:i})}}var w0=String.raw`\s*@\s*\{`;function M0(e,t){const n=ec(e,t,"flowchart");if(!n.ok){throw Je({what:`Invalid @{} metadata in "${e}": ${n.message}`,expectedForm:'a YAML mapping with "double-quoted" strings (a single-quoted one may not hold `"` or `}`)',example:'A@{ shape: rect, label: "Start: a}b" }'})}return n}function ic(e,t){return Mf(e.get(t))?.trim()||void 0}function vq(e,{id:t,entries:n}){const i=e.edges.find(a=>a.id===t);if(!i)return;const r=ic(n,"curve");if(r&&/^[a-z][a-z0-9-]*$/i.test(r))i.curve=r;const o=ic(n,"animate")?.toLowerCase();const s=ic(n,"animation")?.toLowerCase();if(o==="true"||o==="fast"||o==="slow"||s==="fast"||s==="slow"){i.animate=true;const a=o==="fast"||o==="slow"?o:s;if(a==="fast"||a==="slow")i.animation=a}if(re("flowchart"))he("flowchart","set-edge-metadata",i)}function Tq(e,t){const n=t.trim();const i=tc(n);const r=i>0?n.slice(i).match(new RegExp(`^${w0}`)):null;if(!r)return null;const{end:o,entries:s}=M0(n,i+r[0].length-1);if(n.slice(o+1).trim()!=="")return null;const a=n.slice(0,i);return e.edges.some(l=>l.id===a)?{id:a,entries:s}:null}var jf=new WeakMap;function Yf(e){Ve("nodes",e.nodes.size+(jf.get(e)??0)+1)}function Lq(e,t=[]){const n=e[0].match(/^(?:(?:graph|swimlane)\s+(TD|TB|LR|BT|RL|[<>^v])|flowchart(?:\s+(TD|TB|LR|BT|RL|[<>^v]))?)\s*$/i);if(!n){throw new Error(`Invalid mermaid header: "${e[0]}". Expected "graph TD", "flowchart LR", "stateDiagram-v2", etc.`)}const i=_q(n[1]??n[2]??"TD");if(re("flowchart")){Ge("flowchart","header",e[0],{line:1,unit:"normalized"});he("flowchart","set-direction",i)}const r={direction:i,nodes:new Map,edges:[],subgraphs:[],classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map};const o=[];const s=new Map;const a=new Set;const l=$q(e.slice(1),t.slice(1));let c=0;const d=new Set([...l.values()].map(m=>m.id));const u=Gg();const f=[];const h=()=>{const m=o.pop();if(!m)return;const p=s.get(m.id);const g=u.close(m.id,m.nodeIds);const y=g.filter(S=>d.has(S)&&S!==m.id);if(y.length)f.push({lister:m.id,ids:y});p.nodeIds=[...new Set([...p.nodeIds,...g.filter(S=>!d.has(S))])];for(const S of m.children)if(S!==p&&!p.children.some(x=>x.id===S.id))p.children.push(S);p.direction??=m.direction;const w=o.at(-1);if(!a.has(m.id)&&!o.some(S=>S.id===m.id)){if(w)w.children.push(p);else r.subgraphs.push(p);a.add(m.id);if(re("flowchart"))he("flowchart","attach-group",{id:m.id,parent:w?.id})}if(re("flowchart"))he("flowchart","close-group",{id:p.id,label:p.label,members:p.nodeIds,children:p.children.map(S=>S.id),direction:p.direction})};for(let m=1;m<e.length;m++){for(const p of q2(e[m])){if(re("flowchart"))Ge("flowchart","statement",p,{line:m+1,unit:"normalized"});if(Eq(p)){Rq(r,p);continue}const g=Tq(r,p);if(g){vq(r,g);continue}const y=p.match(/^classDef\s+([\w,-]+)\s+(.+)$/);if(y){const P=y[1].split(",").map(k=>k.trim()).filter(Boolean);const E=ag(vn(y[2]));if(Object.keys(E).length===0)continue;for(const k of P){r.classDefs.set(k,E);if(re("flowchart"))he("flowchart","define-class",{name:k,props:E})}continue}const w=O2(p.match(/^class\s+(\S+)\s+([\w-]+)\s*;?$/));if(w){const P=w[1].split(",").map(k=>k.trim());const E=w[2];for(const k of P){Is(r.classAssignments,k,E);if(re("flowchart"))he("flowchart","append-class",{id:k,name:E,classes:r.classAssignments.get(k)})}continue}const S=O2(p.match(/^style\s+(\S+)\s+(.+)$/));if(S){const P=S[1].split(",").map(k=>k.trim()).filter(Boolean);for(const k of P)Q2(r,k,d);const E=ag(vn(S[2]));if(Object.keys(E).length===0)continue;for(const k of P){r.nodeStyles.set(k,{...r.nodeStyles.get(k),...E});if(re("flowchart"))he("flowchart","set-node-style",{id:k,props:r.nodeStyles.get(k)})}continue}const x=p.match(/^linkStyle\s+(default|[\d,\s]+)\s+(.+)$/);if(x){const P=x[1].trim();const E=P==="default"?[]:P.split(",").map(v=>parseInt(v.trim(),10)).filter(v=>!isNaN(v));const k=ag(vn(x[2]));if(Object.keys(k).length===0)continue;if(P==="default"){r.linkStyles.set("default",{...r.linkStyles.get("default"),...k});if(re("flowchart"))he("flowchart","set-link-style",{target:P,props:r.linkStyles.get("default")})}else{for(const v of E){r.linkStyles.set(v,{...r.linkStyles.get(v),...k});if(re("flowchart"))he("flowchart","set-link-style",{target:v,props:r.linkStyles.get(v)})}}continue}const M=p.match(/^direction\s+(TD|TB|LR|BT|RL)\s*$/i);if(M){const P=M[1].toUpperCase();if(o.length>0)o[o.length-1].direction=P;else r.direction=P;if(re("flowchart"))he("flowchart","set-direction",{parent:o.at(-1)?.id,direction:P});continue}if(p==="subgraph"){throw Je({what:`Invalid flowchart statement "${p}": a subgraph needs an id or a title (upstream fails on one with neither)`,expectedForm:'subgraph id, subgraph id[Title] or subgraph "Title"',example:'subgraph S["Stage one"]'})}const b=p.match(/^subgraph\s+(.+)$/);if(b){const{id:P,label:E,labelContent:k}=l[c++];const v={id:P,label:E,...k?{labelContent:k}:{},nodeIds:[],children:[]};if(!s.has(P)){Ve("nodes",r.nodes.size+s.size+1);s.set(P,{id:P,label:E,...k?{labelContent:k}:{},nodeIds:[],children:[]});jf.set(r,s.size)}Ve("nesting",o.length+1);o.push(v);if(re("flowchart"))he("flowchart","open-group",{id:P,label:E,scope:o.at(-2)?.id});continue}if(p==="end"){h();continue}const C=V2(p,r,o,d);if(!C.ok)throw Nq(p,C)}}while(o.length>0)h();Aq(r,f.map(({lister:m,ids:p})=>({lister:s.get(m),ids:p.map(g=>s.get(g))})));return r}function Aq(e,t){const n=(i,r)=>i===r||i.children.some(o=>n(o,r));for(const{lister:i,ids:r}of t){for(const o of r){const s=o?e.subgraphs.indexOf(o):-1;if(s<0||n(o,i))continue;e.subgraphs.splice(s,1);i.children.push(o);if(re("flowchart"))he("flowchart","attach-group",{id:o.id,parent:i.id})}}}var Iq=/^(?:end$|(?:direction|classDef|class|style|linkStyle|click|href)\s)/i;function Fq(){return{direction:"TD",nodes:new Map,edges:[],subgraphs:[],classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map}}function $ce(e,t=Fq()){const n=new Set;const i=e.match(/^subgraph\s+(.+)$/);if(i){const r=i[1].trim();const o=Y2(r);if(o?Pf(o.title,"text"):Ww(r))n.add(o?"label-delimiter":"subgraph-title");if(jg.test(o?o.title:r))n.add("empty-string");const s=o?r.length-o.title.length-2:-1;if([...r.matchAll(/(?:^|\s)[^\s"]+@(?![{"])/g)].some(a=>a.index<s))n.add("node-edge-id");return n}if(Iq.test(e))return n;try{const r=V2(e,t,[],new Set,n);if(r.ok)return n;if(X2(e,r))return new Set(["comma-id"]);return new Set(U2(r)!==void 0?["link-markers"]:[])}catch(r){if(r instanceof Ri)throw r;return new Set}}function Nq(e,t){const n=`Invalid flowchart statement "${e}"`;if(/^<?(?:-{2,}|-\.+|={2,})/.test(t.remaining)){const r=Ef(t.remaining,0);if(r&&"stray"in r){const o=t.remaining.slice(r.stray,r.stray+2);return Je({what:`${n}: the link label in "${t.remaining}" holds a \`${o}\` before the link that closes it, which upstream's lexer rejects`,expectedForm:`a label without \`${o}\`, or a quoted one`,example:`A -- "x ${o} y" --> B`})}return Je({what:`${n}: "${t.remaining}" opens a link label that no link closes (\`--\` and \`-.\` always open a link, so a node id cannot hold them)`,expectedForm:"a label closed by a link of the same stroke, or an id without `--`",example:"A -- label --> B, A == label ==> B or A -. label .-> B"})}const i=U2(t);if(i!==void 0){return Je({what:`${n}: the link "${i}" starts with an \`${i[0]}\` marker and ends otherwise; upstream reads it as a link of no type, and ours reads an \`x\` or \`o\` start only before the same end`,expectedForm:"the same marker at both ends of a link label, or none",example:"A x-- label --x B or A -- label --> B"})}if(X2(e,t)){return Je({what:`${n}: upstream reads the "," before "${t.remaining.slice(1)}" as part of one node id (\`A,B\` is one node there), and ours reads no "," in a node id`,expectedForm:'a node id without ",", or `&` between nodes',example:"A & B --> C"})}return new Error(`${n}: could not fully consume ${t.reason}; remaining input: "${t.remaining}"`)}function X2(e,t){const n=e.trim().replace(/;\s*$/,"").trim();return t.remaining.startsWith(",")&&n.endsWith(t.remaining)&&(t.reason!=="expected edge operator"||KT(n,n.length-t.remaining.length))}function $q(e,t=[]){const n=[];const i=new Set;const r=new Set;for(const[s,a]of e.entries()){for(const{text:l,start:c}of Rf(a)){const d=l.match(/^subgraph\s+(.+)$/);if(d){const u=d[1].trim();const f=Pq(u);n.push(f);if(!f.generated)r.add(f.id);else if(!f.titled&&(/\s/.test(f.identity)||t[s]?.some(h=>h>c&&h<c+l.length)))i.add(f)}else{for(const u of l.matchAll(new RegExp(Ig,"gu")))r.add(u[0]);for(let u=0;u<l.length;){const f=tc(l,u);if(f>0)r.add(l.slice(u,u+f));u=sg(l,u)?.end??u+Math.max(f,1)}}}}const o=new Map;for(const s of n){if(!s.generated)continue;const a=i.has(s)?void 0:o.get(s.identity);if(a){s.id=a;continue}const l=s.id;let c=l;for(let d=2;r.has(c);d++)c=`${l}_${d}`;if(!i.has(s))o.set(s.identity,c);r.add(c);s.id=c}return n}function _q(e){const t=e.toUpperCase();if(t===">")return"LR";if(t==="<")return"RL";if(t==="^")return"BT";if(t==="V")return"TB";return t}function Dq(e){if(re("state"))Ge("state","header",e[0],{line:1,unit:"normalized"});const t={direction:"TD",nodes:new Map,edges:[],subgraphs:[],classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map};const n=[];const i=$2(Sa(e.slice(1))).statements;const r=_2(i);if(r.issue)throw new Error(r.issue);const o=r.compositeIds;const s=new Map;let a=0;const l=new Set;const c=new Map;const d=(b,C,P)=>{if(l.has(b)&&!P)return;const E=[...l.has(b)?c.get(b)??[]:[],C];c.set(b,E);l.add(b);const k=s.get(b);if(k)Object.assign(k,Ad(k,E))};const u=new Map;const f=new Map;const h=new Map;const m=new Set;const p=()=>{const b=n.at(-1);return b?h.get(b)??n.length:0};const g=(b,C=p()+1)=>{Ve("nesting",C);h.set(b,C);n.push(b)};let y=null;const w=(b,C,P)=>{if(!t.stateNotes)t.stateNotes=[];const{text:E,content:k}=Ag(P);t.stateNotes.push({id:`note#${t.stateNotes.length}`,target:b,side:C,text:E,...k?{textContent:k}:{}});if(re("state"))he("state","add-note",t.stateNotes.at(-1));if(!o.has(b))b0(t,n,b)};const S=new Set;const x=(b,C,P)=>{if(b==="[*]"){const k=r.pseudostateId(C==="source"?"start":"end",P);Id(t,n,{id:k,label:"",shape:C==="source"?"state-start":"state-end"});return k}const E=R2(b);if(E){const k=[...n].reverse().find(A=>!A.concurrencyRegion);const v=E.base!==""?E.base:k?.id??"";const T=`${v}[H${E.deep?"*":""}]`;Id(t,n,{id:T,label:y0(E.deep),shape:"state-history"});return T}if(!o.has(b))b0(t,n,b);return b};for(const b of i){const C=b.text;const P={line:b.line+2,unit:"normalized"};if(re("state"))Ge("state",y?"note-body":"statement",C,P);if(y){if(E2(C)){w(y.target,y.side,y.lines.join("\n"));y=null}else{y.lines.push(C)}continue}if(!C)continue;const E=P2(C);if(E){if(S.has(E.id))throw new Error(`Duplicate floating State note "${E.id}"`);S.add(E.id);const{text:O,content:N}=Ag(E.text);const G=r.scopeOf(b);const Y=r.floatingNoteId(E.id);const q={id:E.id,text:O,...N?{textContent:N}:{},...G?{scope:G}:{},nodeId:Y};if(!t.floatingStateNotes)t.floatingStateNotes=[];t.floatingStateNotes.push(q);Yf(t);t.nodes.set(Y,{id:Y,label:O,...N?{labelContent:N}:{},shape:"state-note",floatingNoteId:E.id});if(re("state")){he("state","add-floating-note",q);he("state","add-node",t.nodes.get(Y))}continue}if(k2(C))continue;const k=$g(C);if(k){w(k.target,k.side,k.text);continue}const v=_g(C);if(v){y={target:v.target,side:v.side,lines:[]};continue}const T=C.match(T2);if(T){const O=n.at(-1);if(O){if(!m.has(O))O.direction=T[1].toUpperCase()}else{t.direction=T[1].toUpperCase()}if(re("state"))he("state","set-direction",{parent:n.at(-1)?.id,direction:T[1].toUpperCase()});continue}const A=C.match(L2);if(A){const O=A[1].split(",").map(G=>G.trim()).filter(Boolean);const N=Ld(A[2]);for(const G of O){t.classDefs.set(G,Ou(t.classDefs.get(G),N));if(re("state"))he("state","define-class",{name:G,props:N})}continue}const R=C2(C);if(R){for(const O of R.ids){Is(t.classAssignments,O,R.className);if(re("state"))he("state","assign-class",{id:O,name:R.className})}continue}const I=C.match(A2);if(I){const O=I[1].split(",").map(G=>G.trim()).filter(Boolean);const N=Ld(I[2]);for(const G of O){t.nodeStyles.set(G,{...N});if(re("state"))he("state","set-node-style",{id:G,props:t.nodeStyles.get(G)})}continue}const L=C.match(I2);if(L){const O=L[1].trim();const N=vn(L[2]);if(Object.keys(N).length===0)continue;if(O==="default"){t.linkStyles.set("default",{...t.linkStyles.get("default"),...N});if(re("state"))he("state","set-link-style",{target:O,props:t.linkStyles.get("default")})}else{const G=O.split(",").map(Y=>parseInt(Y.trim(),10));for(const Y of G){if(!isNaN(Y)){t.linkStyles.set(Y,{...t.linkStyles.get(Y),...N});if(re("state"))he("state","set-link-style",{target:Y,props:t.linkStyles.get(Y)})}}}continue}const $=Dg(C);if($){const O=$.stereotype==="fork"?"state-fork":$.stereotype==="join"?"state-join":$.stereotype==="choice"?"state-choice":"state-history";const N=O==="state-history"?y0($.stereotype==="deep-history"):"";if(!t.nodes.has($.id))Yf(t);t.nodes.set($.id,{id:$.id,label:N,shape:O});if(re("state"))he("state","upsert-node",t.nodes.get($.id));k0(t,n,$.id);continue}if(Og(C)&&n.length>0){const O=n[n.length-1];let N;if(O.concurrencyRegion){n.pop();N=n[n.length-1]}else{N=O;Ve("nodes",t.nodes.size+ ++a);jf.set(t,a);const Y={id:r.regionId(N.id,B2(u,N.id)-1),label:"",nodeIds:N.nodeIds.splice(0),children:N.children.splice(0),concurrencyRegion:true};N.children.push(Y);h.set(Y,p()+1);if(re("state"))he("state","add-region",{id:Y.id,parent:N.id,members:Y.nodeIds,children:Y.children.map(q=>q.id)})}Ve("nodes",t.nodes.size+ ++a);jf.set(t,a);const G={id:r.regionId(N.id,B2(u,N.id)-1),label:"",nodeIds:[],children:[],concurrencyRegion:true};N.children.push(G);g(G);if(re("state"))he("state","add-region",{id:G.id,parent:N.id,members:G.nodeIds});continue}const B=C.match(Gf);if(B){const O=B[2];const N=s.get(O);if(N&&!n.includes(N)){if(B[1]!==void 0)d(O,B[1],true);if(N.direction!==void 0)m.add(N);t.nodes.delete(O);g(N,h.get(N));const V=N.children.at(-1);if(V?.concurrencyRegion)g(V,h.get(V));if(re("state"))he("state","open-group",{id:O,label:N.label,parent:f.get(N)});continue}if(B[1]!==void 0){c.set(O,[B[1]]);l.add(O)}const G=l.has(O)?c.get(O):void 0;const Y={id:O,label:O,nodeIds:[],children:[],stateComposite:true};if(G!==void 0)Object.assign(Y,Ad(Y,G));const q=Y.label;Ve("nodes",t.nodes.size-Number(t.nodes.has(O))+ ++a);jf.set(t,a);g(Y);s.set(O,Y);t.nodes.delete(O);if(re("state"))he("state","open-group",{id:O,label:q,parent:n.at(-2)?.id});continue}if(C==="}"){if(n.length>0&&n[n.length-1].concurrencyRegion){n.pop()}const O=n.pop();if(O){if(!f.has(O)){const N=n.at(-1);if(N)N.children.push(O);else t.subgraphs.push(O);f.set(O,N?.id)}if(re("state"))he("state","close-group",{id:O.id,label:O.label,members:O.nodeIds,children:O.children.map(N=>N.id),parent:f.get(O)})}continue}const F=C.match(Wg);if(F){const O=[F[1]];const N=F[2];if(o.has(N)){d(N,F[1],false);continue}const G=t.nodes.get(N);if(G?.shape==="rounded"&&!l.has(N)){c.set(N,O);t.nodes.set(N,Ad(G,O));if(re("state"))he("state","set-label",{id:N,label:t.nodes.get(N).label})}if(!G)c.set(N,O);Id(t,n,Ad({id:N,label:N,shape:"rounded"},O));l.add(N);continue}const z=Bg(C);if(z){const O=x(z.from,"source",b);const N=x(z.to,"target",b);if(z.fromClass){Is(t.classAssignments,O,z.fromClass);if(re("state"))he("state","assign-class",{id:O,name:z.fromClass})}if(z.toClass){Is(t.classAssignments,N,z.toClass);if(re("state"))he("state","assign-class",{id:N,name:z.toClass})}const G=z.label?Ag(z.label):void 0;Ve("edges",t.edges.length+1);t.edges.push({source:O,target:N,label:G?.text,...G?.content?{labelContent:G.content}:{},style:"solid",hasArrowStart:false,hasArrowEnd:true});if(re("state"))he("state","add-edge",t.edges.at(-1),P);continue}const _=Fg(C);if(_){if(!o.has(_.id))b0(t,n,_.id);Is(t.classAssignments,_.id,_.className);if(re("state"))he("state","assign-class",{id:_.id,name:_.className});continue}const H=C.match(zg);if(H){const O=H[1];const N=H[2].trim();if(o.has(O)){d(O,N,true);continue}const G=t.nodes.get(O);const Y=[...l.has(O)?c.get(O)??[]:[],N];if(G&&G.shape==="rounded"){c.set(O,Y);t.nodes.set(O,Ad(G,Y));if(re("state"))he("state","set-label",{id:O,label:t.nodes.get(O).label})}if(!G)c.set(O,Y);Id(t,n,Ad({id:O,label:O,shape:"rounded"},Y));l.add(O);continue}const D=Ng(C);if(D!==null){if(!o.has(D))Id(t,n,{id:D,label:D,shape:"rounded"});continue}const j=/^state\s+"[^"]*"\s+as\s+/.exec(C);const W=j?C.slice(j[0].length).replace(/\{$/,"").trimEnd():"";if(/\s/.test(W))throw Je({what:`Unsupported state syntax: "${C}"`,expectedForm:`one word after \`as\`; pinned Mermaid reads "${W}" as one name, which no transition can refer to`,example:'state "Long name" as LongName'});throw Je({what:`Unsupported state syntax: "${C}"`,expectedForm:"a state declaration, transition, composite, note, direction, or paint directive",example:"A --> B : continue"})}const M=n.find(b=>!b.concurrencyRegion);if(M){throw Je({what:`Composite state "${M.id}" is never closed`,expectedForm:"a `}` where the composite ends",example:"state X { A }"})}if(y)w(y.target,y.side,y.lines.join("\n"));Oq(t,s,r);return t}function Oq(e,t,n){const i=new Map(t);for(const o of t.values()){for(const s of o.children.filter(a=>a.concurrencyRegion))i.set(s.id,s)}for(const o of i.values()){o.nodeIds=o.nodeIds.filter(s=>!n.authored.has(s));o.children=o.children.filter(s=>!s.stateComposite);if(re("state"))he("state","reset-scope-membership",{id:o.id,members:o.nodeIds,children:o.children.map(s=>s.id)})}e.subgraphs=[];for(const o of t.values()){const s=n.ownerOf(o.id);const a=s?i.get(n.scopeId(s)):void 0;if(s&&!a)throw new Error(`Missing State scope for ${o.id}`);if(a)a.children.push(o);else e.subgraphs.push(o);if(re("state"))he("state","resolve-group-owner",{id:o.id,parent:a?.id})}for(const o of n.ownedIds()){if(!e.nodes.has(o))continue;const s=n.ownerOf(o);if(!s)continue;const a=i.get(n.scopeId(s));if(!a)throw new Error(`Missing State scope for ${o}`);a.nodeIds.push(o);if(re("state"))he("state","resolve-member-owner",{id:o,parent:a.id})}for(const o of e.floatingStateNotes??[]){if(!o.scope)continue;const s=i.get(n.scopeId(o.scope));if(!s)throw new Error(`Missing State scope for floating note ${o.id}`);s.nodeIds.push(o.nodeId);if(re("state"))he("state","resolve-member-owner",{id:o.nodeId,parent:s.id})}const r=e.subgraphs.map(o=>({group:o,depth:1}));while(r.length){const{group:o,depth:s}=r.pop();Ve("nesting",s);for(const a of o.children)r.push({group:a,depth:s+1})}}function B2(e,t){const n=(e.get(t)??0)+1;e.set(t,n);return n}function Ad(e,t){const{text:n,content:i}=g2(t);const{labelContent:r,...o}=e;return{...o,label:n,...i?{labelContent:i}:{}}}var W2=new WeakMap;function k0(e,t,n){const i=t.at(-1);if(!i||i.nodeIds.includes(n))return;let r=W2.get(e);if(!r)W2.set(e,r=new Map);if(r.has(n))return;r.set(n,i);i.nodeIds.push(n);if(re("state"))he("state","add-member",{parent:i.id,id:n})}function Id(e,t,n){const i=!e.nodes.has(n.id);if(i){Yf(e);e.nodes.set(n.id,n);if(re("state"))he("state","add-node",n)}k0(e,t,n.id)}function b0(e,t,n){if(!e.nodes.has(n)){Id(e,t,{id:n,label:n,shape:"rounded"})}else{k0(e,t,n)}}function Bq(e){const t=JT(e,0);if(t?.kind!=="pipe"||!t.closed)return null;return{rawLabel:e.slice(t.contentStart,t.contentEnd),consumed:t.end}}function Wq(e){const t=zw(e,0);if(!t)return null;const n=t.startMark==="x"?"cross":t.startMark==="o"?"circle":t.startMark?"arrow":void 0;if((t.startMark==="x"||t.startMark==="o")&&n!==Yg(t.closeOp))return null;return{startMarker:n,openOp:t.openOp,rawLabel:e.slice(t.labelStart,t.labelEnd),closeOp:t.closeOp,consumed:t.end}}var lr=e=>new RegExp(`^${e}`,"u");var zq=[{regex:lr(String.raw`\(\(\((.+?)\)\)\)`),shape:"doublecircle"},{regex:lr(String.raw`\(\[(.+?)\]\)`),shape:"stadium"},{regex:lr(String.raw`\(-(.+?)-\)`),shape:"ellipse"},{regex:lr(String.raw`\(\((.+?)\)\)`),shape:"circle"},{regex:lr(String.raw`\[\[(.+?)\]\]`),shape:"subroutine"},{regex:lr(String.raw`\[\((.+?)\)\]`),shape:"cylinder"},{regex:lr(String.raw`\[\/([^\]]+?)\\\]`),shape:"trapezoid"},{regex:lr(String.raw`\[\\([^\]]+?)\/\]`),shape:"trapezoid-alt"},{regex:lr(String.raw`\[\/([^\]]+?)\/\]`),shape:"lean-r"},{regex:lr(String.raw`\[\\([^\]]+?)\\\]`),shape:"lean-l"},{regex:lr(String.raw`>(.+?)\]`),shape:"asymmetric"},{regex:lr(String.raw`\{\{(.+?)\}\}`),shape:"hexagon"},{regex:lr(String.raw`\[(.+?)\]`),shape:"rectangle"},{regex:lr(String.raw`\((.+?)\)`),shape:"rounded"},{regex:lr(String.raw`\{(.+?)\}`),shape:"diamond"}];var Gq=new Set(["trapezoid","trapezoid-alt","lean-r","lean-l"]);function Hg(e){const t=tc(e);return t>0?{id:e.slice(0,t),length:t}:null}var Hq=new RegExp(String.raw`^(${XT})@\s*(?=${og}|(?:-{2,}|-\.+|={2,})\s+)`,"u");function U2(e){if(e.reason!=="expected edge operator")return void 0;const t=zw(e.remaining,0);if(t?.startMark!=="x"&&t?.startMark!=="o")return void 0;return Yg(t.closeOp)===(t.startMark==="x"?"cross":"circle")?void 0:e.remaining.slice(0,t.end)}function S0(e){const t=g0(e);if(!t)return null;const n=e.slice(3);const i=Math.min(t.className.length,tc(n));if(i===0)return null;return{className:n.slice(0,i),length:3+i}}function V2(e,t,n,i=new Set,r){let o=e.trim().replace(/;\s*$/,"").trim();const s=r?Xq(o,r):void 0;const a=z2(o,t,n,i,s);if(!a||a.ids.length===0){return{ok:false,remaining:o,reason:"expected node"}}o=a.remaining.trim();if(o.length===0)return{ok:true};let l=a.ids;while(o.length>0){let c;let d;let u;let f;let h;let m;let p;let g;const y=o.match(Hq);const w=y?.[1];if(y){if(re("flowchart"))Ho("flowchart","edge-id",y[0]);o=o.slice(y[0].length).trim()}const S=sg(o,0);if(S){const C=S.op;let P=S.end;const E=/^\s*/.exec(o.slice(P))[0].length;const k=o.slice(P+E);if(k.startsWith("|")){const v=Bq(k);if(!v)return{ok:false,remaining:k,reason:"expected edge target"};if(Pf(v.rawLabel,"text"))r?.add("label-delimiter");if(jg.test(v.rawLabel))r?.add("empty-string");if(v.rawLabel==="")r?.add("empty-pipe-label");if(Uq.test(v.rawLabel))r?.add("node-edge-id");const T=ja(v.rawLabel.trim());m=T.text||void 0;p=T.labelContent;P+=E+v.consumed}if(re("flowchart"))Ho("flowchart","link",o.slice(0,P));o=o.slice(P).trim();d=Vq(C);g=Kq(C);f=Qq(C,S.hasArrowStart);h=Yg(C);c=f!==void 0;u=h!==void 0}else{const C=Wq(o);if(!C)return{ok:false,remaining:o,reason:"expected edge operator"};if(Pf(C.rawLabel,"edge-text"))r?.add("label-delimiter");if(jg.test(C.rawLabel))r?.add("empty-string");const P=ja(C.rawLabel);m=P.text||void 0;p=P.labelContent;if(re("flowchart"))Ho("flowchart","text-link",o.slice(0,C.consumed));o=o.slice(C.consumed).trim();d=eA(C.openOp,C.closeOp);g=Jq(C.openOp,C.closeOp);f=C.startMarker;c=f!==void 0;h=Yg(C.closeOp);u=h!==void 0}const x=z2(o,t,n,i,s);if(!x||x.ids.length===0){return{ok:false,remaining:o,reason:"expected edge target"}}o=x.remaining.trim();Ve("edges",t.edges.length+l.length*x.ids.length);const M=w!==void 0&&t.edges.some(C=>C.id===w);if(M)r?.add("duplicate-edge-id");let b=M?void 0:w;for(const C of l){for(const P of x.ids){const E=C===l.at(-1)&&P===x.ids[0]?b:void 0;if(E!==void 0)b=void 0;t.edges.push({source:C,target:P,...E!==void 0?{id:E}:{},label:m,...p?{labelContent:p}:{},style:d,hasArrowStart:c,hasArrowEnd:u,startMarker:f,endMarker:h,...g!==void 0?{length:g}:{}});if(re("flowchart"))he("flowchart","add-edge",t.edges.at(-1))}}l=x.ids}return{ok:true}}function z2(e,t,n,i,r){const o=H2(e,t,n,i,r);if(!o)return null;const s=[o.id];let a=o.remaining.trim();while(a.startsWith("&")){if(re("flowchart"))Ho("flowchart","parallel-separator","&");const l=H2(a.slice(1).trim(),t,n,i,r);if(!l)break;s.push(l.id);a=l.remaining.trim()}return{ids:s,remaining:a}}function jq(e,t,n){const i=Hg(e);const r=i&&e.slice(i.length).match(new RegExp(`^${w0}`));if(!i||!r)return null;const o=i.id;const{end:s,entries:a}=M0(e,i.length+r[0].length-1);K2(o,a,t,n);return{id:o,remaining:e.slice(s+1)}}function K2(e,t,n,i){const r=t.get("label");const o=r===""?"":Mf(r);const s=o!==void 0?ja(o,true):void 0;const a=ic(t,"shape");const l=a!==void 0?m2(a):null;const c=ic(t,"icon");const d=ic(t,"img");const u=ic(t,"form");const f=u==="circle"||u==="rounded"||u==="square"?u:void 0;const h=l?{shape:l.geometry,semanticShape:l.canonical,authoredShape:a}:c||d?{shape:f==="circle"?"circle":f==="rounded"?"rounded":"rectangle",semanticShape:c?"icon":"image"}:{};const m={...c?{icon:c}:{},...d?{image:d}:{},...f?{iconForm:f}:{}};const p=n.nodes.get(e);if(p){n.nodes.set(e,{...p,...s!==void 0?{label:s.text,labelContent:s.labelContent,...s.markdown?{markdownLabel:true}:{}}:{},...h,...m});if(re("flowchart"))he("flowchart","set-node-metadata",n.nodes.get(e));qg(i,e)}else{Z2(n,i,{id:e,label:s?.text??e,...s?.labelContent?{labelContent:s.labelContent}:{},shape:"rectangle",...s?.markdown?{markdownLabel:true}:{},...h,...m})}}function G2(e,t,n,i){const r=t.match(new RegExp(`^${w0}`));if(!r)return null;const{end:o,entries:s}=M0(t,r[0].length-1);K2(e,s,n,i);return t.slice(o+1)}var Yq=[{open:"(((",close:")))",shape:"doublecircle"},{open:"([",close:"])",shape:"stadium"},{open:"(-",close:"-)",shape:"ellipse"},{open:"((",close:"))",shape:"circle"},{open:"[[",close:"]]",shape:"subroutine"},{open:"[(",close:")]",shape:"cylinder"},{open:"[/",close:"\\]",shape:"trapezoid"},{open:"[\\",close:"/]",shape:"trapezoid-alt"},{open:"[/",close:"/]",shape:"lean-r"},{open:"[\\",close:"\\]",shape:"lean-l"},{open:">",close:"]",shape:"asymmetric"},{open:"{{",close:"}}",shape:"hexagon"},{open:"[",close:"]",shape:"rectangle"},{open:"(",close:")",shape:"rounded"},{open:"{",close:"}",shape:"diamond"}];var jg=/^\s*""\s*$/;function qq(e,t,n,i){const r=Hg(e);if(!r)return null;const o=e.slice(r.length);for(const s of Yq){if(!o.startsWith(`${s.open}"`))continue;const a=s.open.length;const l=o.indexOf('"',a+1);if(l<0||!o.startsWith(s.close,l+1))continue;if(l===a+1)i?.add("empty-string");const c=ja(o.slice(a+1,l),true);J2(t,n,{id:r.id,label:c.text,...c.labelContent?{labelContent:c.labelContent}:{},shape:s.shape,...c.markdown?{markdownLabel:true}:{}});const d=r.length+l+1+s.close.length;return{id:r.id,remaining:e.slice(d)}}return null}function H2(e,t,n,i,r){const o=jq(e,t,n);if(o){let f=o.remaining;const h=S0(f);if(h){Is(t.classAssignments,o.id,h.className);if(re("flowchart"))he("flowchart","append-class",{id:o.id,name:h.className,classes:t.classAssignments.get(o.id)});f=f.slice(h.length)}if(re("flowchart"))Ho("flowchart","metadata-node",e.slice(0,e.length-f.length));return{id:o.id,remaining:f}}const s=qq(e,t,n,r);if(s){let f=G2(s.id,s.remaining,t,n)??s.remaining;const h=S0(f);if(h){Is(t.classAssignments,s.id,h.className);if(re("flowchart"))he("flowchart","append-class",{id:s.id,name:h.className,classes:t.classAssignments.get(s.id)});f=f.slice(h.length)}if(re("flowchart"))Ho("flowchart","quoted-node",e.slice(0,e.length-f.length));return{id:s.id,remaining:f}}let a=null;let l=e;const c=Hg(e);const d=c?e.slice(c.length):"";for(const{regex:f,shape:h}of c?zq:[]){const m=d.match(f);if(m){a=c.id;if(Pf(m[1],Gq.has(h)?"trapezoid":"text"))r?.add("label-delimiter");if(jg.test(m[1]))r?.add("empty-string");const{text:p,markdown:g,labelContent:y}=ja(m[1]);J2(t,n,{id:a,label:p,shape:h,...g?{markdownLabel:true}:{},...y?{labelContent:y}:{}});l=d.slice(m[0].length);break}}if(a===null){const f=Hg(e);if(f){a=f.id;Q2(t,a,i);qg(n,a);l=e.slice(f.length)}}if(a===null)return null;l=G2(a,l,t,n)??l;const u=S0(l);if(u){Is(t.classAssignments,a,u.className);if(re("flowchart"))he("flowchart","append-class",{id:a,name:u.className,classes:t.classAssignments.get(a)});l=l.slice(u.length)}if(ig(e,e.length-l.length))return null;if(r?.nodeEdgeId(e))r.add("node-edge-id");if(re("flowchart"))Ho("flowchart","node",e.slice(0,e.length-l.length));return{id:a,remaining:l}}function Xq(e,t){const n=new Uint8Array(e.length);let i=false;for(let r=e.length-1;r>=0;r--){const o=e[r];if(/[\s"]/.test(o))i=false;else{n[r]=i?1:0;if(o==="@"&&e[r+1]!=="{"&&e[r+1]!=='"')i=true}}return{add:r=>{t.add(r)},nodeEdgeId:r=>n[e.length-r.length]===1}}var Uq=/^[^\s"]*@(?![{"])/;function J2(e,t,n){const i=e.nodes.get(n.id);if(!i){Z2(e,t,n);return}const{markdownLabel:r,semanticShape:o,authoredShape:s,labelContent:a,...l}=i;e.nodes.set(n.id,{...l,label:n.label,shape:n.shape,...n.markdownLabel?{markdownLabel:true}:{},...n.labelContent?{labelContent:n.labelContent}:{}});if(re("flowchart"))he("flowchart","define-node",e.nodes.get(n.id));qg(t,n.id)}function Q2(e,t,n){if(e.nodes.has(t)||n.has(t))return false;Yf(e);e.nodes.set(t,{id:t,label:t,shape:"rectangle"});if(re("flowchart"))he("flowchart","add-node",e.nodes.get(t));return true}function Z2(e,t,n){const i=!e.nodes.has(n.id);if(i){Yf(e);e.nodes.set(n.id,n);if(re("flowchart"))he("flowchart","add-node",n)}qg(t,n.id)}function qg(e,t){if(e.length>0){const n=e[e.length-1];if(!n.nodeIds.includes(t)){n.nodeIds.push(t);if(re("flowchart"))he("flowchart","add-member",{parent:n.id,id:t})}}}function Vq(e){if(e[0]==="~")return"invisible";if(e.includes("."))return"dotted";if(e.includes("="))return"thick";return"solid"}function Kq(e){let t;if(e[0]==="~"){t=e.length-3}else if(e.includes(".")){t=(e.match(/\./g)?.length??1)-1}else if(e.includes("=")){const n=e.match(/=/g)?.length??2;t=/[>ox]$/.test(e)?n-2:n-3}else{const n=e.match(/-/g)?.length??2;const i=/[>ox]$/.test(e)||/^[ox]/.test(e);t=i?n-2:n-3}return t>0?t+1:void 0}function eA(e,t){if(e.includes(".")||t.includes("."))return"dotted";if(e.includes("=")||t.includes("="))return"thick";return"solid"}function Jq(e,t){const n=eA(e,t);const i=(a,l)=>(a.match(new RegExp(`\\${l}`,"g"))??[]).length;let r=0;let o=0;if(n==="dotted"){r=Math.max(0,i(e,".")-1);o=Math.max(0,i(t,".")-1)}else if(n==="thick"){r=Math.max(0,i(e,"=")-2);o=Math.max(0,i(t,"=")-(/[>ox]$/.test(t)?2:3))}else{r=Math.max(0,i(e,"-")-2);o=Math.max(0,i(t,"-")-(/[>ox]$/.test(t)?2:3))}const s=Math.max(r,o);return s>0?s+1:void 0}function Qq(e,t){if(t)return"arrow";if(e.startsWith("o"))return"circle";if(e.startsWith("x"))return"cross";return void 0}function Yg(e){const t=e[e.length-1];if(t===">")return"arrow";if(t==="o")return"circle";if(t==="x")return"cross";return void 0}function C0(e){const t=new Map;return e.map(n=>{const i=`${n.source}->${n.target}`;const r=t.get(i)??0;t.set(i,r+1);return`${i}#${r}`})}function Fd(e){const t=new Map;C0(e).forEach((n,i)=>{t.set(n,i);if(n.endsWith("#0"))t.set(n.slice(0,-2),i)});for(let n=e.length-1;n>=0;n--){const i=e[n].id;if(i)t.set(i,n)}return t}var tA=/^"((?:[^"\\]|\\.)*)"\s*:\s*(.+)$/;var Zq=/^\+?(?:\d+(?:\.\d+)?|\.\d+)$/;var E0=/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/;function R0(e){return Ir(e,vg)}function rA(e){e=fa(zt(e,R0(e)).familyLines,vg).map(Ht);if(e.length===0){throw new Error("Pie chart is empty")}const t=e[0].trim();const n=t.match(/^pie\b(.*)$/i);if(!n){throw new Error(`Pie chart must start with "pie", got: "${t}"`)}if(re("pie"))Ge("pie","header",t,{line:1,unit:"normalized"});let i=false;let r;let o;let s=n[1].trim();const a=s.match(/^showData\b\s*(.*)$/i);if(a){i=true;if(re("pie"))he("pie","setShowData",i,{line:1,unit:"normalized"});s=a[1].trim()}const l=s.match(/^title\s+(.+)$/i);if(l){const h=l[1].trim();r=h;if(re("pie"))he("pie","setTitle",r,{line:1,unit:"normalized"});o=iA(h);if(re("pie"))he("pie","resolveTitleDisplay",o,{line:1,unit:"normalized"})}else if(s.length>0){throw new Error(`Unexpected text after pie header: "${s}"`)}const c=[];const d=new Set;let u=false;let f=false;for(let h=1;h<e.length;h++){const m=e[h].trim();if(m.length===0||m.startsWith("%%"))continue;if(/^showData\s*$/i.test(m)){if(re("pie"))Ge("pie","showData",m,{line:h+1,unit:"normalized"});i=true;if(re("pie"))he("pie","setShowData",i,{line:h+1,unit:"normalized"});continue}const p=m.match(/^title\s+(.+)$/i);if(p){if(re("pie"))Ge("pie","title",m,{line:h+1,unit:"normalized"});const y=p[1].trim();r=y;if(re("pie"))he("pie","setTitle",r,{line:h+1,unit:"normalized"});o=iA(y);if(re("pie"))he("pie","resolveTitleDisplay",o,{line:h+1,unit:"normalized"});continue}const g=m.match(tA);if(g){if(re("pie"))Ge("pie","entry",m,{line:h+1,unit:"normalized"});const y=P0(g[1]);if(/[\u0000-\u001f]/.test(P0(g[1].replace(/\n/g,"")))){f=true;if(re("pie"))he("pie","setHasEscapedControlLabels",true,{line:h+1,unit:"normalized"})}const w=y;const S=g[2].trim();if(!Zq.test(S)){throw new Error(`Pie slice "${w}" has invalid value "${S}". Values must be non-negative numbers.`)}const x=Number.parseFloat(S);if(!Number.isFinite(x)||x<0){throw new Error(`Pie slice "${w}" has invalid value "${S}". Values must be non-negative numbers.`)}if(E0.test(y)){throw Je({what:"Pie slice label contains an XML-disallowed control character",expectedForm:"a label without XML-disallowed control characters",example:'"Alpha" : 10'})}const M=Un(m);const b=tA.exec(M)?.[1]??g[1];const C=P0(Dn(b));const P=so(C,oA);if(re("pie"))he("pie","resolveEntryDisplay",{sourceKey:C,label:P},{line:h+1,unit:"normalized"});if(t3(w,P)){throw Je({what:"Pie entity projection creates a terminal control character after escape decoding",expectedForm:"an entity that displays printable text",example:'"Alpha&#35;" : 10'})}if(E0.test(P)){throw Je({what:"Pie slice display label contains an XML-disallowed control character",expectedForm:"a label without XML-disallowed control characters",example:'"Alpha" : 10'})}const E=e3(P);if(d.has(C)){u=true;if(re("pie"))he("pie","setHasDuplicateSourceLabels",true,{line:h+1,unit:"normalized"})}else{d.add(C);if(re("pie"))he("pie","addSourceLabel",C,{line:h+1,unit:"normalized"});c.push({label:w,value:x,...E===w&&!nA(w)?{}:{displayLabel:E}});if(re("pie"))he("pie","appendEntry",c[c.length-1],{line:h+1,unit:"normalized"})}continue}if(m.includes(":")){if(re("pie"))Ge("pie","invalidEntry",m,{line:h+1,unit:"normalized"});throw new Error(`Invalid pie entry: "${m}". Expected: "label" : positiveNumber`)}if(re("pie"))Ge("pie","unrecognized",m,{line:h+1,unit:"normalized"});throw Je({what:`Unrecognized pie chart line: "${m}"`,expectedForm:'a title, showData, or a slice ("Label" : number)',example:'"Free" : 60'})}return{title:r,showData:i,entries:c,...o!==r||r!==void 0&&nA(r)?{displayTitle:o}:{},...u?{hasDuplicateSourceLabels:true}:{},...f?{hasEscapedControlLabels:true}:{}}}function nA(e){return/[<>*~]/.test(e)}function e3(e){if(!e.includes("\n"))return e;const t=[];for(const n of e.split("\n")){let i=0;let r=n.length;while(i<r&&(n[i]===" "||n[i]===" "))i++;while(r>i&&(n[r-1]===" "||n[r-1]===" "))r--;if(i<r)t.push(n.slice(i,r))}return t.join(" ")}function iA(e){const t=so(Dn(Un(e)),oA);if(E0.test(t)){throw Je({what:"Pie title display contains an XML-disallowed control character",expectedForm:"a title without XML-disallowed control characters",example:"title Safe chart"})}return t}var oA={subject:"Pie entity",example:'"Alpha&#35;" : 10'};function t3(e,t){if(!bo.test(t))return false;const n=new Uint32Array(160);for(const i of e){const r=i.charCodeAt(0);if(r<160&&bo.test(i)){n[r]=n[r]+1}}for(const i of t){const r=i.charCodeAt(0);if(r>=160||!bo.test(i))continue;if(n[r]===0)return true;n[r]=n[r]-1}return false}function P0(e){const t={n:"\n",t:" ",r:"\r",b:"\b",f:"\f",v:"\v","0":"\0"};return e.replace(/\\(.)/g,(n,i)=>t[i]??i)}function qf(e){const t=Math.max(0,...e.series.map(n=>n.data.length));if(e.xAxis.categories)return Math.max(1,e.xAxis.categories.length,t);return Math.max(1,t)}function v0(e,t=qf(e)){if(e.xAxis.range){const{min:n,max:i}=e.xAxis.range;const r=t>1?(i-n)/(t-1):0;return Array.from({length:t},(o,s)=>n+r*s)}return Array.from({length:t},(n,i)=>i)}function Xg(e,t=qf(e)){if(e.xAxis.categories)return Array.from({length:t},(n,i)=>e.xAxis.categories[i]??String(i+1));if(e.xAxis.range)return v0(e,t).map(n=>Xf(n));return Array.from({length:t},(n,i)=>String(i+1))}function sA(e,t,n){if(e.length<2)return n;let i=Number.POSITIVE_INFINITY;for(let r=1;r<e.length;r++){i=Math.min(i,Math.abs(t(e[r])-t(e[r-1])))}return Number.isFinite(i)&&i>0?i:n}function Ug(e,t){const n=Math.min(e.min,e.max);const i=Math.max(e.min,e.max);return Math.min(i,Math.max(n,t))}function aA(e){return Ug(e,0)}function rc(e){if(Number.isInteger(e))return String(e);const t=e.toFixed(Math.abs(e)<10?1:0);return Number(t)===0&&e!==0?String(e):t}function Vg(e,t,n=10){if(!(n>0))return[];if(e===t)return[e];const i=t<e;const r=i?t:e;const o=i?e:t;const[s,a,l]=lA(r,o,n);if(!(a>=s))return[];const c=a-s+1;const d=new Array(c);if(i){if(l<0){for(let u=0;u<c;u++)d[u]=(a-u)/-l}else{for(let u=0;u<c;u++)d[u]=(a-u)*l}}else if(l<0){for(let u=0;u<c;u++)d[u]=(s+u)/-l}else{for(let u=0;u<c;u++)d[u]=(s+u)*l}return d.map(n3)}function Xf(e){if(!Number.isFinite(e))return String(e);if(Number.isInteger(e))return String(e);return Number(e.toPrecision(12)).toString()}function lA(e,t,n){const i=(t-e)/Math.max(0,n);const r=Math.floor(Math.log10(i));const o=i/Math.pow(10,r);const s=o>=Math.sqrt(50)?10:o>=Math.sqrt(10)?5:o>=Math.sqrt(2)?2:1;let a;let l;let c;if(r<0){c=Math.pow(10,-r)/s;a=Math.round(e*c);l=Math.round(t*c);if(a/c<e)a++;if(l/c>t)l--;c=-c}else{c=Math.pow(10,r)*s;a=Math.round(e/c);l=Math.round(t/c);if(a*c<e)a++;if(l*c>t)l--}if(l<a&&.5<=n&&n<2){return lA(e,t,n*2)}return[a,l,c]}function n3(e){return Math.round(e*1e12)/1e12}function qt(e,t,n,i="middle"){if(!e)return void 0;return{x:rt(t-(i==="start"?0:i==="end"?e.width:e.width/2)),y:rt(n-e.height/2),w:rt(e.width),h:rt(e.height)}}function bt(e,t,n,i,r="middle"){const o=qt(e,t,n,r);return o?{labelBounds:o,labelContainer:{x:rt(i.x),y:rt(i.y),w:rt(i.width),h:rt(i.height)}}:{}}function i3(e){return{id:e.id,x:rt(e.x),y:rt(e.y),w:rt(e.width),h:rt(e.height),shape:e.shape,label:e.label,...bt(e.labelBlock,e.x+e.width/2,e.y+e.height/2,e)}}function r3(e,t,n){const i=e.label?e.labelPosition??sn(e.points):void 0;return{id:t,from:e.source,to:e.target,path:e.points.map(r=>[rt(r.x),rt(r.y)]),...e.style==="invisible"?{visibility:"hidden"}:{},label:e.label&&i?{x:rt(i.x),y:rt(i.y),text:e.label,bounds:qt(e.labelBlock,i.x,i.y)}:void 0,...n&&e.routeCertificate?{route:e.routeCertificate}:{}}}function cA(e,t={}){const n=e.edges.map((l,c)=>({value:l,index:c})).sort((l,c)=>(l.value.edgeIndex??l.index)-(c.value.edgeIndex??c.index)).map(l=>l.value);const i=C0(n);const r=Fd(n);const o=new Set(e.nodes.map(l=>l.id));const s=[...e.groups];for(const l of s){o.add(l.id);s.push(...l.children)}const a=new Map(n.map((l,c)=>{const d=l.id;const u=i[c];const f=u.replace(/#0$/,"");return[l,d&&!o.has(d)&&r.get(d)===c?d:r.get(f)===c?f:u]}));return{version:1,nodes:e.nodes.map(i3),edges:e.edges.map(l=>r3(l,a.get(l),t.debug===true)),groups:o3(e.groups,e.nodes),bounds:{w:rt(e.width),h:rt(e.height)}}}function o3(e,t){const n=[];const i=(o,s)=>s.x>=o.x-.5&&s.y>=o.y-.5&&s.x+s.width<=o.x+o.width+.5&&s.y+s.height<=o.y+o.height+.5;const r=(o,s)=>{const a=o.nodeIds?new Set(o.nodeIds):void 0;const l=t.filter(c=>a?a.has(c.id):i(o,c)&&!o.children.some(d=>i(d,c))).map(c=>c.id);n.push({id:o.id,x:rt(o.x),y:rt(o.y),w:rt(o.width),h:rt(o.height),members:l,label:o.label,...s?{parentId:s}:{}});for(const c of o.children)r(c,o.id)};for(const o of e)r(o);return n}function Jce(e){return{version:1,kind:e,nodes:[],edges:[],groups:[],bounds:{w:rt(0),h:rt(0)}}}var Ut=e=>({x:0,y:0,width:e.width,height:e.height});var ln=e=>({x:rt(e.x),y:rt(e.y),w:rt(e.width),h:rt(e.height)});function xe(e){return rt(Math.round(e))}function Gt(e,t){return rt(Math.round(e+t)-Math.round(e))}function Kg(e,t,n,i,r){const o=!!(i&&n[0]&&dA(n[0].x,n[0].y,i,1));const s=!!(r&&n[n.length-1]&&dA(n[n.length-1].x,n[n.length-1].y,r,1));const a=Uf(n);return{family:e,edgeIndex:t,routeClass:"family-layout",invariant:o&&s&&a?"orthogonal-box":"unverified-family-route",bendCount:Vf(n),orthogonal:a,sourceBoundary:o,targetBoundary:s}}function Uf(e){for(let t=1;t<e.length;t++){const n=e[t-1],i=e[t];if(Math.abs(n.x-i.x)>.5&&Math.abs(n.y-i.y)>.5)return false}return true}function Vf(e){if(e.length<3)return 0;let t=0;for(let n=1;n<e.length-1;n++){const i=e[n-1],r=e[n],o=e[n+1];const s=Math.abs(i.x-r.x)<=.5&&Math.abs(r.x-o.x)<=.5;const a=Math.abs(i.y-r.y)<=.5&&Math.abs(r.y-o.y)<=.5;if(!s&&!a)t++}return t}function dA(e,t,n,i){const r=(Math.abs(e-n.x)<=i||Math.abs(e-(n.x+n.width))<=i)&&t>=n.y-i&&t<=n.y+n.height+i;const o=(Math.abs(t-n.y)<=i||Math.abs(t-(n.y+n.height))<=i)&&e>=n.x-i&&e<=n.x+n.width+i;return r||o}function is(e,t,n,i,r="bounds"){const o=new Map;for(const s of t.groups){for(const a of s.members)o.set(a,s)}return t.nodes.map(s=>{const a=s3(s,t.bounds);const l=o.get(s.id)??i;const c=l?r==="center"?l3(s,l):a3(s,l):void 0;return{family:e,elementId:s.id,routeClass:"family-layout",invariant:a&&(c??true)?n:"unverified-family-layout",bounds:{x:s.x,y:s.y,w:s.w,h:s.h},center:{x:xe(s.x+s.w/2),y:xe(s.y+s.h/2)},containment:r,withinBounds:a,...l?{groupId:l.id,withinGroup:c}:{}}})}function s3(e,t,n=.5){return e.x>=-n&&e.y>=-n&&e.x+e.w<=t.w+n&&e.y+e.h<=t.h+n}function a3(e,t,n=.5){return e.x>=t.x-n&&e.y>=t.y-n&&e.x+e.w<=t.x+t.w+n&&e.y+e.h<=t.y+t.h+n}function l3(e,t,n=.5){const i=e.x+e.w/2;const r=e.y+e.h/2;return i>=t.x-n&&r>=t.y-n&&i<=t.x+t.w+n&&r<=t.y+t.h+n}function Jg({positioned:e,options:t}){const n=new Map(e.lifelines.map(s=>[s.actorId,s.x]));const i=new Map;for(const s of e.messages)for(const a of[s.from,s.to])if(!i.has(a))i.set(a,s.y);const r=new Map;for(const s of e.notes)if(s.parentId!==void 0&&s.id!==void 0){const a=r.get(s.parentId)??[];a.push(s.id);r.set(s.parentId,a)}const o=[...e.actors.map(s=>({id:s.id,x:xe(s.external?s.x:s.bounds.x),y:xe(s.external?i.get(s.id)??s.y:s.bounds.y),w:xe(s.external?0:s.bounds.width),h:xe(s.external?0:s.bounds.height),shape:s.external?"external-anchor":"rectangle",label:s.label,labelBounds:ln(s.labelPosition.bounds),labelContainer:ln(s.bounds),...s.external?{labelVisibility:"semantic"}:{},role:s.external?"mark":"box"})),...e.notes.map((s,a)=>({id:s.id??`note#${a}`,...s.parentId===void 0?{}:{parentId:s.parentId},x:xe(s.x),y:xe(s.y),w:xe(s.width),h:xe(s.height),shape:"note",label:s.text,...bt(s.block,s.x+s.width/2,s.y+s.height/2,s),role:"box"}))];return{version:1,nodes:o,edges:e.messages.map((s,a)=>({id:s.id??`msg#${a}:${s.from}->${s.to}`,...s.parentId===void 0?{}:{parentId:s.parentId},from:s.from,to:s.to,path:s.points.map(l=>[xe(l.x),xe(l.y)]),label:s.label?{x:xe(s.labelPosition.x),y:xe(s.labelPosition.y),text:s.label,bounds:ln(s.labelPosition.bounds)}:void 0,route:t.debug?c3(a,s,s.points,n):void 0})),groups:e.blocks.map((s,a)=>({id:s.id??`block#${a}:${s.type}`,...s.parentId===void 0?{}:{parentId:s.parentId},x:xe(s.bounds.x),y:xe(s.bounds.y),w:xe(s.bounds.width),h:xe(s.bounds.height),members:s.id===void 0?[]:r.get(s.id)??[],label:s.label})),bounds:{w:xe(e.width),h:xe(e.height)}}}function c3(e,t,n,i){const r=i.get(t.from);const o=i.get(t.to);const s=n[0];const a=n[n.length-1];const l=r!==void 0&&s!==void 0&&Math.abs(s.x-r)<=1;const c=o!==void 0&&a!==void 0&&Math.abs(a.x-o)<=1;const d=!t.isSelf&&n.every(f=>Math.abs(f.y-t.y)<=1);const u=Uf(n);return{family:"sequence",edgeIndex:e,routeClass:"family-layout",invariant:l&&c&&u?t.isSelf?"self-message":"lifeline-message":"unverified-family-route",bendCount:Vf(n),horizontal:d,sourceLifeline:l,targetLifeline:c,selfMessage:t.isSelf}}function oc(e){const t=new Map([...e.elements,...e.boundaries].map(i=>[i.id,i.id]));const n=new Map(e.relationships.map(i=>[i.id,i.id]));return{nodes:t,relationships:n,generated:yi([...t.keys(),...n.keys(),...e.legend?.entries.map(i=>i.id)??[]])}}function Kf(e){const t=`${e.external?"External ":""}${e.kind[0].toUpperCase()}${e.kind.slice(1)}${e.shape==="database"?": Database":e.shape==="queue"?": Queue":""}`;const n=e.style.techn??e.technology;return[e.label,`[${t}${n?`: ${n}`:""}]`,e.description,e.tags.length?`[tags: ${e.tags.join(", ")}]`:void 0,e.sprite?`[sprite: ${e.sprite}]`:void 0].filter(i=>i!==void 0&&i!=="").join("\n")}function Jf(e){const t=e.kind==="deployment"?"Deployment Node":`${e.kind==="boundary"?"":`${e.kind[0].toUpperCase()}${e.kind.slice(1)} `}Boundary`;return[e.label,`[${t}${e.type?`: ${e.type}`:""}]`,e.description,e.tags.length?`[tags: ${e.tags.join(", ")}]`:void 0,e.sprite?`[sprite: ${e.sprite}]`:void 0].filter(n=>n!==void 0&&n!=="").join("\n")}function Qf(e,t){const n=t.index??(e.variant==="C4Dynamic"?String(t.order):void 0);return[`${n!==void 0?`${n}: `:""}${t.label}`,t.technology?`[${t.technology}]`:void 0,t.description,t.tags.length?`[tags: ${t.tags.join(", ")}]`:void 0,t.sprite?`[sprite: ${t.sprite}]`:void 0].filter(i=>i!==void 0&&i!=="").join("\n")}function T0(e,t){return e.statements.find(n=>n.id===t)?.span.line}function uA(e,t=Xp()){for(const o of[...e.elements,...e.boundaries,...e.relationships,...e.legend?.entries??[]]){const s=o.style;Tt({...s.bgColor===void 0?{}:{fill:s.bgColor},...s.borderColor===void 0&&s.lineColor===void 0?{}:{stroke:s.borderColor??s.lineColor},...s.fontColor===void 0&&s.textColor===void 0?{}:{color:s.fontColor??s.textColor}},`C4 ${o.id}`)}const n=oc(e);const i={direction:e.layout.direction??e.layout.hints[0]?.direction??e.relationships.find(o=>o.direction)?.direction??"LR",nodes:new Map,edges:[],subgraphs:[],classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map};const r=new Map;for(const o of e.boundaries)r.set(o.id,{id:n.nodes.get(o.id)??o.id,label:Jf(o),nodeIds:[],children:[]});for(const o of e.boundaries){const s=r.get(o.id),a=o.parentId&&r.get(o.parentId);if(a)a.children.push(s);else i.subgraphs.push(s)}for(const o of e.elements){const s=n.nodes.get(o.id)??o.id,a=Xs(o,t),l=Ao(o);i.nodes.set(s,{id:s,label:Kf(o),shape:l==="database"?"cylinder":l==="queue"?"subroutine":"rectangle",href:o.effectiveLink??o.link});if(o.parentId)r.get(o.parentId)?.nodeIds.push(s);i.nodeStyles.set(s,{...a.fill?{fill:a.fill}:{},...a.stroke?{stroke:a.stroke}:{},...a.text?{color:a.text}:{},...a.dashed?{"stroke-dasharray":"5 3"}:{}})}for(const o of e.relationships){const s=Qf(e,o);i.edges.push({id:n.relationships.get(o.id)??o.id,source:o.source,target:o.target,label:s,labelContent:{value:s,prepared:Rt(s,"literal")},style:o.style.lineStyle==="dashed"||o.style.lineStyle==="dotted"?"dotted":"solid",hasArrowStart:o.bidirectional,hasArrowEnd:true});i.linkStyles.set(i.edges.length-1,Tt({...o.style.lineColor?{stroke:o.style.lineColor}:{},...o.style.textColor?{color:o.style.textColor}:{}},`UpdateRelStyle(${o.from}, ${o.to})`))}return i}var An=864e5;var Qg=1e4;function Zf(e){return Math.floor(e/An)}function eh(e){return Zf(e)*An}function sc(e){return((Zf(e)+4)%7+7)%7}var L0={sunday:0,monday:1,tuesday:2,wednesday:3,thursday:4,friday:5,saturday:6};function d3(e,t,n,i=0,r=0,o=0,s=0){if(t<1||t>12||n<1||n>31)return null;if(i<0||i>23||r<0||r>59||o<0||o>59)return null;const a=Date.UTC(e,t-1,n,i,r,o,s);const l=new Date(a);if(l.getUTCFullYear()!==e||l.getUTCMonth()!==t-1||l.getUTCDate()!==n)return null;return a}var u3=["YYYY","YY","MM","M","DD","D","HH","H","mm","m","ss","s","SSS","X","x"];var f3=new Set(["HH","H","mm","m","ss","s","SSS","X","x"]);function hA(e){const t=[];let n=0;e:while(n<e.length){for(const i of u3){if(e.startsWith(i,n)){t.push({kind:"field",field:i});n+=i.length;continue e}}t.push({kind:"literal",text:e[n]});n++}return t}function h3(e){return!hA(e).some(t=>t.kind==="field"&&f3.has(t.field))}function Nd(e,t){const n=hA(t);let i=0;const r={};const o=(s,a)=>{let l=0;while(l<a&&i+l<e.length&&e[i+l]>="0"&&e[i+l]<="9")l++;if(l<s)return null;const c=Number(e.slice(i,i+l));i+=l;return c};for(const s of n){if(s.kind==="literal"){if(e[i]!==s.text)return null;i++;continue}switch(s.field){case"YYYY":{const a=o(4,4);if(a===null)return null;r.year=a;break}case"YY":{const a=o(2,2);if(a===null)return null;r.year=2e3+a;break}case"MM":{const a=o(2,2);if(a===null)return null;r.month=a;break}case"M":{const a=o(1,2);if(a===null)return null;r.month=a;break}case"DD":{const a=o(2,2);if(a===null)return null;r.day=a;break}case"D":{const a=o(1,2);if(a===null)return null;r.day=a;break}case"HH":{const a=o(2,2);if(a===null)return null;r.hour=a;break}case"H":{const a=o(1,2);if(a===null)return null;r.hour=a;break}case"mm":{const a=o(2,2);if(a===null)return null;r.minute=a;break}case"m":{const a=o(1,2);if(a===null)return null;r.minute=a;break}case"ss":{const a=o(2,2);if(a===null)return null;r.second=a;break}case"s":{const a=o(1,2);if(a===null)return null;r.second=a;break}case"SSS":{const a=o(3,3);if(a===null)return null;r.msec=a;break}case"X":{const a=o(1,11);if(a===null)return null;r.unix=a;break}case"x":{const a=o(1,14);if(a===null)return null;r.unixMs=a;break}}}if(i!==e.length)return null;if(r.unixMs!==void 0)return r.unixMs;if(r.unix!==void 0)return r.unix*1e3;return d3(r.year??1970,r.month??1,r.day??1,r.hour??0,r.minute??0,r.second??0,r.msec??0)}var m3={ms:1,s:1e3,m:6e4,h:36e5,d:An,w:7*An};function p3(e,t){const n=t.match(d0);if(!n)return null;const i=Number(n[1]);const r=n[2];if(!Number.isFinite(i))return null;if(r==="M"||r==="y"){const o=r==="y"?i*12:i;const s=Math.trunc(o);const a=o-s;const l=new Date(e);const c=l.getUTCMonth()+s;const d=new Date(Date.UTC(l.getUTCFullYear(),c,1,l.getUTCHours(),l.getUTCMinutes(),l.getUTCSeconds(),l.getUTCMilliseconds()));const u=new Date(Date.UTC(d.getUTCFullYear(),d.getUTCMonth()+1,0)).getUTCDate();d.setUTCDate(Math.min(l.getUTCDate(),u));let f=d.getTime();if(a>0)f+=Math.round(a*30*An);return f}return e+Math.round(i*m3[r])}function g3(e){return{dateFormat:e.dateFormat,inclusiveEndDates:e.inclusiveEndDates,excludes:e.excludes,includes:e.includes,weekendStart:e.weekendStart,weekStart:e.weekStart}}function fA(e,t){const n=new Set;const i=new Set;let r=false;for(const o of e){if(o.kind==="weekends"){r=true;continue}if(o.kind==="weekday"){i.add(L0[o.day]);continue}const s=Nd(o.raw,t.dateFormat)??Nd(o.raw,"YYYY-MM-DD");if(s===null){throw new Di("GANTT_BAD_DATE",`Invalid calendar date "${o.raw}" for dateFormat "${t.dateFormat}"`)}n.add(Zf(s))}return{days:n,weekdays:i,weekends:r}}var mA=new WeakMap;function y3(e){const t=fA(e.excludes,e);const n=fA(e.includes,e);const i=e.weekendStart==="friday"?[5,6]:[6,0];const r=o=>{const s=Zf(o);const a=sc(o);const l=n.days.has(s)||n.weekdays.has(a)||n.weekends&&i.includes(a);if(l)return false;if(t.days.has(s))return true;if(t.weekdays.has(a))return true;if(t.weekends&&i.includes(a))return true;return false};if(e.excludes.length){let o;mA.set(r,()=>o??={weekdays:Array.from({length:7},(s,a)=>{if(n.weekdays.has(a)||n.weekends&&i.includes(a))return false;return t.weekdays.has(a)||t.weekends&&i.includes(a)}),exceptions:[...new Set([...t.days,...n.days])].sort((s,a)=>s-a)})}return r}function x3(e,t,n,i){let r=e+An;let o=t;let s=t;let a=false;let l=0;const c=t-e>=14*An&&Number.isSafeInteger(e)&&Number.isSafeInteger(t)&&Math.max(Math.abs(e),Math.abs(t))+Qg*An<Number.MAX_SAFE_INTEGER;const d=c?mA.get(n)?.():void 0;while(r<=o){if(d){const u=Zf(r);let f=0,h=d.exceptions.length;while(f<h){const g=f+h>>>1;if(d.exceptions[g]<u)f=g+1;else h=g}const m=f<d.exceptions.length?d.exceptions[f]-u:Infinity;const p=Math.floor(Math.min(Math.floor((o-r)/An)+1,Qg-l,m)/7);if(p>0){const g=sc(r);let y=0,w,S;let x=a,M=d.weekdays[(g+6)%7];for(let C=0;C<7;C++){if(!x)w=y;if(!M)S=y;x=M=d.weekdays[(g+C)%7];if(x)y++}const b=p>1&&S!==void 0?(p-1)*y+S:w;if(b!==void 0)s=o+b*An;o+=p*y*An;r+=p*7*An;l+=p*7;a=x;continue}}if(++l>Qg){throw new Di("GANTT_SCHEDULE_OVERFLOW",`Calendar exclusion walk exceeded ${Qg} days (is every day excluded?)`,i)}if(!a)s=o;a=n(r);if(a)o+=An;r+=An}return{end:o,renderEnd:s}}function b3(e,t,n){const i=[];if(e.start===void 0&&n)i.push(n.index);if(e.start?.kind==="after"){for(const r of e.start.refs){const o=t.get(r);if(!o)throw new Di("GANTT_UNKNOWN_TASK_REF",`Task "${e.label}" starts after unknown id "${r}"`,e.line);i.push(o.index)}}if(e.end.kind==="until"){for(const r of e.end.refs){const o=t.get(r);if(!o)throw new Di("GANTT_UNKNOWN_TASK_REF",`Task "${e.label}" runs until unknown id "${r}"`,e.line);i.push(o.index)}}return i}function S3(e,t,n){const i=new Array(e).fill(0);const r=[];const o=new Array(e).fill(0);const s=[];for(let a=0;a<e;a++){if(i[a]!==0)continue;i[a]=1;r.push(a);while(r.length){const l=r.at(-1);if(o[l]<t[l].length){const c=t[l][o[l]];o[l]=o[l]+1;if(i[c]===0){i[c]=1;r.push(c)}else if(i[c]===1){const d=r.indexOf(c);const u=r.slice(d).concat(c).map(n);throw new Di("GANTT_DEPENDENCY_CYCLE",`Dependency cycle: ${u.join(" -> ")}`)}}else{r.pop();i[l]=2;s.push(l)}}}return s}function pA(e,t={}){const n=g3(e);const i=y3(n);const r=h3(e.dateFormat);const o=new Map;for(const m of e.tasks){if(m.id!==void 0)o.set(m.id,m)}const s=e.tasks.map((m,p)=>b3(m,o,e.tasks[p-1]));const a=S3(e.tasks.length,s,m=>e.tasks[m].id??e.tasks[m].label);const l=new Array(e.tasks.length);const c=m=>{if(l[m.index])return l[m.index];let p;if(m.start===void 0){const x=m.index>0?l[m.index-1]:void 0;if(!x){throw new Di("GANTT_NO_START",`Task "${m.label}" has no start date and no previous task to follow`,m.line)}p=x.end}else if(m.start.kind==="after"){p=Math.max(...m.start.refs.map(x=>l[o.get(x).index].end))}else{const x=Nd(m.start.raw,e.dateFormat);if(x===null){throw new Di("GANTT_BAD_DATE",`Invalid start date "${m.start.raw}" for dateFormat "${e.dateFormat}"`,m.line)}p=x}let g;let y=false;if(m.end.kind==="until"){g=Math.min(...m.end.refs.map(x=>l[o.get(x).index].start));y=true}else if(m.end.kind==="duration"){const x=p3(p,m.end.raw);if(x===null){throw new Di("GANTT_BAD_DURATION",`Invalid duration "${m.end.raw}"`,m.line)}g=x}else{const x=Nd(m.end.raw,e.dateFormat);if(x===null){throw new Di("GANTT_BAD_DATE",`Invalid end date "${m.end.raw}" for dateFormat "${e.dateFormat}"`,m.line)}g=n.inclusiveEndDates&&r?x+An:x;y=true}let w=g;if(!y&&n.excludes.length>0){const x=x3(p,g,i,m.line);g=x.end;w=x.renderEnd}if(g<p)g=p;if(w<p)w=p;if(w>g)w=g;const S={index:m.index,id:m.id,label:m.label,tags:m.tags,sectionIndex:m.sectionIndex,start:p,end:g,renderEnd:w,manualEnd:y,line:m.line};l[m.index]=S;return S};for(const m of a)c(e.tasks[m]);const d=l;if(d.length===0)return{tasks:d,timeMin:0,timeMax:0,dateOnly:r,isExcludedDay:i};let u=Infinity;let f=-Infinity;for(const m of d){u=Math.min(u,m.start);f=Math.max(f,m.renderEnd)}if(f===u)f=u+(r?An:36e5);let h;if(t.today!==void 0&&!e.todayMarker?.off){const m=Nd(t.today,e.dateFormat)??Nd(t.today,"YYYY-MM-DD");if(m===null){throw new Di("GANTT_BAD_DATE",`Invalid clock value "${t.today}" for dateFormat "${e.dateFormat}"`)}h=m}return{tasks:d,timeMin:u,timeMax:f,dateOnly:r,today:h,analysis:w3(e,d,o,a),isExcludedDay:i}}function gA(e){const t=new Map;for(const o of e.tasks)if(o.id!==void 0)t.set(o.id,o);const n=[];const i=new Set;const r=(o,s,a)=>{const l=`${o}>${s}:${a}`;if(i.has(l))return;i.add(l);n.push({from:o,to:s,kind:a})};for(const o of e.tasks){if(o.start?.kind==="after"){for(const s of o.start.refs){const a=t.get(s);if(a)r(a.index,o.index,"after")}}if(o.end.kind==="until"){for(const s of o.end.refs){const a=t.get(s);if(a)r(o.index,a.index,"until")}}}return n}function w3(e,t,n,i){const r=[];const o=new Set;for(const g of e.tasks){if(g.start?.kind==="after"){for(const y of g.start.refs){const w=n.get(y);r.push({from:w.index,to:g.index});o.add(w.index)}}if(g.end.kind==="until")for(const y of g.end.refs)o.add(n.get(y).index)}if(r.length===0)return void 0;const s=Math.min(...t.map(g=>g.start));const a=Math.max(...t.map(g=>g.end));const l=t.map(()=>[]);for(const g of r)l[g.from].push(g.to);const c=new Array(t.length).fill(Number.NaN);for(let g=i.length-1;g>=0;g--){const y=i[g];const w=l[y];let S=a;for(const x of w){const M=t[x].end-t[x].start;S=Math.min(S,c[x]-M)}c[y]=S}const d={};const u=new Set;for(const g of r){u.add(g.from);u.add(g.to)}const f=[];for(const g of t){const y=c[g.index]-g.end;if(g.id!==void 0)d[g.id]=y;if(u.has(g.index)&&y===0&&g.id!==void 0)f.push(g.id)}const h=new Set(r.map(g=>g.to));const m=t.filter(g=>g.id!==void 0&&!h.has(g.index)).map(g=>g.id);const p=t.filter(g=>g.id!==void 0&&!o.has(g.index)).map(g=>g.id);return{criticalPathTaskIds:f,slackByTaskId:d,projectStart:s,projectEnd:a,entryTaskIds:m,sinkTaskIds:p}}var M3=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];var k3=["January","February","March","April","May","June","July","August","September","October","November","December"];var C3=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];var P3=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function A0(e,t){const n=new Date(e);const i=(a,l=2)=>String(a).padStart(l,"0");const r=()=>{const a=Date.UTC(n.getUTCFullYear(),0,1);return Math.floor((e-a)/An)+1};const o=a=>{const l=Date.UTC(n.getUTCFullYear(),0,1);const c=sc(l);const d=(7+c-a)%7;return Math.floor((r()-1+d)/7)};let s="";for(let a=0;a<t.length;a++){const l=t[a];if(l!=="%"){s+=l;continue}const c=t[++a];switch(c){case"Y":s+=String(n.getUTCFullYear());break;case"y":s+=i(n.getUTCFullYear()%100);break;case"m":s+=i(n.getUTCMonth()+1);break;case"d":s+=i(n.getUTCDate());break;case"e":s+=String(n.getUTCDate()).padStart(2," ");break;case"b":s+=M3[n.getUTCMonth()];break;case"B":s+=k3[n.getUTCMonth()];break;case"a":s+=C3[sc(e)];break;case"A":s+=P3[sc(e)];break;case"H":s+=i(n.getUTCHours());break;case"I":s+=i((n.getUTCHours()+11)%12+1);break;case"M":s+=i(n.getUTCMinutes());break;case"S":s+=i(n.getUTCSeconds());break;case"L":s+=i(n.getUTCMilliseconds(),3);break;case"p":s+=n.getUTCHours()<12?"AM":"PM";break;case"j":s+=i(r(),3);break;case"U":s+=i(o(0));break;case"W":s+=i(o(1));break;case"%":s+="%";break;default:s+=c===void 0?"%":`%${c}`}}return s}function xA({positioned:e,options:t}){const n=[...e.services.map(c=>({id:c.id,x:xe(c.x),y:xe(c.y),w:xe(c.width),h:xe(c.height),shape:"service",label:c.label,role:"box",...c.labelPosition?bt(c.labelBlock,c.labelPosition.x,c.labelPosition.y,c,"start"):{}})),...e.junctions.map(c=>({id:c.id,x:xe(c.x),y:xe(c.y),w:xe(c.width),h:xe(c.height),shape:"circle",label:void 0,role:"mark"}))];const i=new Map;const r=[];const o=c=>{i.set(c.id,c);r.push({id:c.id,x:xe(c.x),y:xe(c.y),w:xe(c.width),h:xe(c.height),members:[...e.services.filter(d=>d.parentId===c.id).map(d=>d.id),...e.junctions.filter(d=>d.parentId===c.id).map(d=>d.id)],label:c.label,parentId:c.parentId});for(const d of c.children)o(d)};for(const c of e.groups)o(c);const s=new Map(e.services.map(c=>[c.id,c]));const a=new Map(e.junctions.map(c=>[c.id,c]));const l=e.edges.map((c,d)=>({id:`edge#${d}:${c.source.id}->${c.target.id}`,from:c.source.id,to:c.target.id,path:c.points.map(u=>[xe(u.x),xe(u.y)]),label:c.label&&c.labelPosition?{x:xe(c.labelPosition.x),y:xe(c.labelPosition.y),text:c.label,bounds:qt(c.labelBlock,c.labelPosition.x,c.labelPosition.y)}:void 0,route:t.debug?E3(d,c,s,a,i):void 0}));return{version:1,nodes:n,edges:l,groups:r,bounds:{w:xe(e.width),h:xe(e.height)}}}function E3(e,t,n,i,r){const o=h=>{if(h.boundary==="group"){const m=n.get(h.id);return m?.parentId?r.get(m.parentId):void 0}return n.get(h.id)??i.get(h.id)};const s=o(t.source);const a=o(t.target);const l=t.points[0];const c=t.points[t.points.length-1];const d=!!(l&&s&&yA(l,s,t.source.side,1));const u=!!(c&&a&&yA(c,a,t.target.side,1));const f=Uf(t.points);return{family:"architecture",edgeIndex:e,routeClass:"family-layout",invariant:d&&u&&f&&t.obstacleFree?"side-anchored":"unverified-family-route",bendCount:Vf(t.points),orthogonal:f,sourceSide:t.source.side,targetSide:t.target.side,sourceBoundary:t.source.boundary,targetBoundary:t.target.boundary,sourceAnchored:d,targetAnchored:u,placement:t.placement,sourceFacesTarget:t.sourceFacesTarget,targetFacesSource:t.targetFacesSource,obstacleFree:t.obstacleFree}}function yA(e,t,n,i){switch(n){case"L":return Math.abs(e.x-t.x)<=i&&e.y>=t.y-i&&e.y<=t.y+t.height+i;case"R":return Math.abs(e.x-(t.x+t.width))<=i&&e.y>=t.y-i&&e.y<=t.y+t.height+i;case"T":return Math.abs(e.y-t.y)<=i&&e.x>=t.x-i&&e.x<=t.x+t.width+i;case"B":return Math.abs(e.y-(t.y+t.height))<=i&&e.x>=t.x-i&&e.x<=t.x+t.width+i}}function bA({positioned:e,options:t}){const n=e.classes.map(s=>{const a=s.interfaceBox??s;return{id:s.id,x:xe(a.x),y:xe(a.y),w:Gt(a.x,a.width),h:Gt(a.y,a.height),shape:s.isInterface?"circle":"rectangle",label:s.label,...bt(s.labelBlock,s.x+s.width/2,s.y+s.headerHeight/2+(s.annotation?6:0),{...s,height:s.headerHeight})}});const i=new Map(e.classes.map(s=>[s.id,s.interfaceBox??{x:s.x,y:s.y,width:s.width,height:s.height}]));const r=e.relationships.map((s,a)=>({id:`rel#${a}:${s.from}->${s.to}`,from:s.from,to:s.to,path:s.points.map(l=>[xe(l.x),xe(l.y)]),label:s.label&&s.labelPosition?{x:xe(s.labelPosition.x),y:xe(s.labelPosition.y-8),text:s.label,bounds:qt(s.labelBlock,s.labelPosition.x,s.labelPosition.y-8)}:void 0,route:t.debug?Kg("class",a,s.points,i.get(s.from),i.get(s.to)):void 0}));const o=e.namespaces.map(s=>({id:s.id,x:xe(s.x),y:xe(s.y),w:Gt(s.x,s.width),h:Gt(s.y,s.height),members:[...s.classIds],label:s.label,parentId:s.parentId}));return{version:1,nodes:n,edges:r,groups:o,bounds:{w:xe(e.width),h:xe(e.height)}}}function I0(e,t,n,i){const r=[];const o=e.x-t.x;const s=e.y-t.y;const a=Math.sqrt(o*o+s*s);if(a===0)return[];const l=o/a;const c=s/a;const d=-c;const u=l;if(n==="parent"){const S=(x,M)=>({x:e.x-l*x+d*M,y:e.y-c*x+u*M});return[{geometry:{kind:"polygon",points:[S(0,0),S(6,4),S(12,0),S(6,-4)]},paint:{fill:"var(--bg)",...i}}]}const f=e.x-l*4;const h=e.y-c*4;const m=e.x-l*16;const p=e.y-c*16;const g=n==="many"||n==="zero-many";const y=n==="zero-one"||n==="zero-many";const w=(S,x)=>{const M=6;const b=S+d*M;const C=x+u*M;const P=S-d*M;const E=x-u*M;r.push({geometry:{kind:"line",x1:b,y1:C,x2:P,y2:E},paint:i})};if(n==="one"){w(f,h);w(f-l*4,h-c*4)}else if(n==="zero-one"){w(f,h)}if(g){const S=7;const x=f;const M=h;const b=x+d*S;const C=M+u*S;r.push({geometry:{kind:"line",x1:b,y1:C,x2:m,y2:p},paint:i});r.push({geometry:{kind:"line",x1:x,y1:M,x2:m,y2:p},paint:i});const P=x-d*S;const E=M-u*S;r.push({geometry:{kind:"line",x1:P,y1:E,x2:m,y2:p},paint:i});if(n==="many"){w(e.x-l*20,e.y-c*20)}}if(y){const S=g?20:12;const x=e.x-l*S;const M=e.y-c*S;r.push({geometry:{kind:"circle",cx:x,cy:M,r:4},paint:{fill:"var(--bg)",...i}})}return r}function Fo(e,t,n,i){const r={stroke:"#000",strokeWidth:String(i+.25)};const o=I0(e,t,n,r);const s=[];for(const a of o){const l=Ei({kind:"shape",id:"cardinality",role:"cardinality",geometry:a.geometry,paint:a.paint});if(!l||!Object.values(l).every(Number.isFinite))return void 0;s.push(l)}return s}function Ya(e,t){const n=Fo({x:0,y:0},{x:1,y:0},e,t);return n?.reduce((i,r)=>bs(i,r),void 0)}function F0(e,t){const n=e.width+8,i=e.height+6;return{kind:"rect",x:t.x-n/2,y:t.y-i/2,width:n,height:i,rx:2,ry:2}}function N0(e,t){return Ei({kind:"shape",id:"label-pill",role:"chrome",geometry:F0(e,t),paint:{fill:"#000",stroke:"#000",strokeWidth:"0.5"}})}var $d=class extends RangeError{code="ER_ROUTE_WORK_LIMIT";constructor(){super("ER_ROUTE_WORK_LIMIT: frame corridor checks exceed 400000; split the diagram or reduce its relationships");this.name="ErRouteWorkLimitError"}};var Nt=class extends Error{code="ER_ROUTE_BLOCKED";constructor(t,n){super(`ER_ROUTE_BLOCKED: no clear frame corridor from ${t} to ${n}`);this.name="ErRouteGeometryError"}};var rs=class extends RangeError{code="ER_LABEL_WORK_LIMIT";constructor(){super("ER_LABEL_WORK_LIMIT: label-slot search exceeds 400000 operations; split the diagram or reduce its relationships");this.name="ErLabelWorkLimitError"}};import{elkConstructor as R3}from"#elk-constructor";var $0=null;var th=null;function v3(){if($0)return;const e=R3();const t=[];const n=globalThis.setTimeout;globalThis.setTimeout=(o,s)=>{if(s===0){t.push(o);return 0}return n(o,s)};const i=globalThis;const r=typeof i.document!=="undefined";if(!r)i.document={};$0=new e;if(!r)delete i.document;globalThis.setTimeout=n;t.forEach(o=>o());th=$0.worker.worker}function qa(e){return ei("elk",()=>I3(e))}var SA=globalThis;var T3=(SA.process?.env?.AGENTIC_MERMAID_ELK_CACHE??SA.AGENTIC_MERMAID_ELK_CACHE)!=="0";var L3=64;var A3=1024*1024;var _0=8*1024*1024;var wA=new wu(L3,_0);function I3(e){PP(e);if(!T3){jt("elk-layout","bypass","disabled");return MA(e)}const t=F3(e);const n=wA.get(t);if(n){jt("elk-layout","hit");return structuredClone(n)}jt("elk-layout","miss");const i=MA(e);if(t.length<=A3){const r=Math.max(t.length*8,t.length*2+Pu(i,_0));if(r<=_0)wA.set(t,structuredClone(i),r);else jt("elk-layout","store-skipped","weight-limit")}else jt("elk-layout","store-skipped","key-limit");return i}function F3(e){return JSON.stringify(e,(t,n)=>{if(n===void 0)return"\0undefined";if(typeof n==="number"&&!Number.isFinite(n))return`\0${n}`;if(typeof n==="string"&&n.startsWith("\0"))return`\0${n}`;return n})}function MA(e){v3();let t;let n;const i=th.onmessage;th.onmessage=r=>{if(r.data.error){n=r.data.error}else{t=r.data.data}};th.dispatcher.saveDispatch({data:{id:0,cmd:"layout",graph:e}});th.onmessage=i;if(n)throw n;if(!t)throw new Error("ELK layout did not return synchronously");return t}function Qs(e){let t;for(const n of["x","y"]){let i=e[0]?.[n];for(let r=1;r<e.length;r++){const o=e[r][n];if(o===i)continue;if(i!==void 0&&N3(o,i)){t??=e.map(s=>({...s}));t[r][n]=i}else i=o}}return t??e}function N3(e,t){return Math.abs(e-t)<=Math.min(1e-6,8*Number.EPSILON*Math.max(1,Math.abs(e),Math.abs(t)))}function nh(e,t,n){for(let i=0;i<e.length;i++)for(let r=0;r<t.length;r++){n?.(1);const o=e[i],s=t[r];if(o.kind==="circle"){if(s.kind==="circle"){const a=o.cx-s.cx,l=o.cy-s.cy,c=o.r+s.r;if(o.r>0&&s.r>0&&a*a+l*l<c*c)return true}else if(kA(o.cx,o.cy,o.r,s.points,n))return true}else if(s.kind==="circle"){if(kA(s.cx,s.cy,s.r,o.points,n))return true}else if($3(o.points,s.points,n))return true}return false}function $3(e,t,n){if(e.length<3||t.length<3)return false;const i=e[0];let r=0;for(let o=0;o<2;o++){const s=o===0?e:t;for(let a=0;a<s.length;a++){n?.(1);const l=s[a],c=s[(a+1)%s.length],d=l.y-c.y,u=c.x-l.x;if(d===0&&u===0)continue;r++;let f=Infinity,h=-Infinity,m=Infinity,p=-Infinity;for(let g=0;g<e.length;g++){n?.(1);const y=e[g],w=(y.x-i.x)*d+(y.y-i.y)*u;f=Math.min(f,w);h=Math.max(h,w)}for(let g=0;g<t.length;g++){n?.(1);const y=t[g],w=(y.x-i.x)*d+(y.y-i.y)*u;m=Math.min(m,w);p=Math.max(p,w)}if(Math.min(h,p)<=Math.max(f,m))return false}}return r>0}function kA(e,t,n,i,r){if(!(n>0)||i.length<3)return false;let o=0,s=true,a=0,l=Infinity;const c=i[0];for(let d=0;d<i.length;d++){r?.(1);const u=i[d],f=i[(d+1)%i.length],h=f.x-u.x,m=f.y-u.y,p=h*(t-u.y)-m*(e-u.x);a+=(u.x-c.x)*(f.y-c.y)-(u.y-c.y)*(f.x-c.x);if(p!==0){if(o!==0&&Math.sign(p)!==o)s=false;o||=Math.sign(p)}const g=h*h+m*m,y=g>0?Math.max(0,Math.min(1,((e-u.x)*h+(t-u.y)*m)/g)):0;l=Math.min(l,(u.x+y*h-e)**2+(u.y+y*m-t)**2)}return a!==0&&(s||l<n*n)}function ci(e,t,n){return e.x===t.x?e.x>n.x&&e.x<n.x+n.width&&Math.max(e.y,t.y)>n.y&&Math.min(e.y,t.y)<n.y+n.height:e.y>n.y&&e.y<n.y+n.height&&Math.max(e.x,t.x)>n.x&&Math.min(e.x,t.x)<n.x+n.width}function Ji(e,t,n){return(t.x===n.x?Math.abs(e.x-t.x)<1e-7:Math.abs(e.y-t.y)<1e-7)&&e.x>=Math.min(t.x,n.x)&&e.x<=Math.max(t.x,n.x)&&e.y>=Math.min(t.y,n.y)&&e.y<=Math.max(t.y,n.y)}function ey(e,t){return e.x<t.x+t.width&&t.x<e.x+e.width&&e.y<t.y+t.height&&t.y<e.y+e.height}function _3(e,t,n,i){return e.x===t.x&&n.x===i.x&&Math.abs(e.x-n.x)<=.5&&Math.min(Math.max(e.y,t.y),Math.max(n.y,i.y))-Math.max(Math.min(e.y,t.y),Math.min(n.y,i.y))>.01||e.y===t.y&&n.y===i.y&&Math.abs(e.y-n.y)<=.5&&Math.min(Math.max(e.x,t.x),Math.max(n.x,i.x))-Math.max(Math.min(e.x,t.x),Math.min(n.x,i.x))>.01}function _d(e,t,n,i,r){if(e){if(r?.(3)===false)return void 0;e.candidateSegment=t;e.peerIndex=n;e.peerSegment=i}return false}function ea(e,t="complete"){return t==="complete"&&e.maximumEdgeStrokeWidth!==void 0&&e.maximumEdgeBendRadius===0?1:3}function D3(e,t,n,i,r){if(e.x!==t.x&&e.y!==t.y||n.x!==i.x&&n.y!==i.y)return void 0;return vA(e,t,n,i,r)}function vA(e,t,n,i,r){const o=(Math.abs(e.x)+Math.abs(e.y)+Math.abs(t.x)+Math.abs(t.y)+Math.abs(n.x)+Math.abs(n.y)+Math.abs(i.x)+Math.abs(i.y)+r)*1e-10+1e-9,s=r+o,a=Math.min(e.x,t.x)-Math.max(n.x,i.x),l=Math.min(n.x,i.x)-Math.max(e.x,t.x),c=Math.min(e.y,t.y)-Math.max(n.y,i.y),d=Math.min(n.y,i.y)-Math.max(e.y,t.y);return Number.isFinite(s)&&Number.isFinite(a)&&Number.isFinite(l)&&Number.isFinite(c)&&Number.isFinite(d)&&(a>s||l>s||c>s||d>s)}function D0(e,t,n,i){if(n?.(1)===false)return void 0;const r=t.get(e);if(r)return r;if(n?.(128)===false||i?.(14)===false)return void 0;const o=/^(-?)(\d+)(?:\.(\d+))?(?:e([+-]?\d+))?$/.exec(e);const s={n:BigInt(o[1]+o[2]+(o[3]??"")),e:Number(o[4]??0)-(o[3]?.length??0)};if(i?.(2)===false||n?.(1)===false)return void 0;t.set(e,s);return s}function TA(e,t,n,i,r,o=false,s){if(i?.(8)===false)return void 0;const a=Number(e),l=Number(t),c=Number(n),d=Math.abs(a-l)*(o?2:1)-c;if(Math.abs(d)>8*Number.EPSILON*Math.max(1,Math.abs(a),Math.abs(l),c))return d<0?-1:1;let u,f,h;if(s){const w=D0(e,s,i,r);if(!w)return void 0;u=w;const S=D0(t,s,i,r);if(!S)return void 0;f=S;const x=D0(n,s,i,r);if(!x)return void 0;h=x}else{if(i?.(384)===false||r?.(42)===false)return void 0;const w=S=>{const x=/^(-?)(\d+)(?:\.(\d+))?(?:e([+-]?\d+))?$/.exec(S);return{n:BigInt(x[1]+x[2]+(x[3]??"")),e:Number(x[4]??0)-(x[3]?.length??0)}};u=w(e);f=w(t);h=w(n)}const m=Math.min(u.e,f.e,h.e);if(i?.(32+u.e-m+f.e-m+h.e-m)===false)return void 0;const p=u.n*10n**BigInt(u.e-m)-f.n*10n**BigInt(f.e-m),g=p<0n?-p:p;const y=g*(o?2n:1n)-h.n*10n**BigInt(h.e-m);return y<0n?-1:y>0n?1:0}function Dd(e,t,n,i,r){const o=TA(e,t,n,i,r);return o===void 0?void 0:o<0}function O3(e,t,n,i,r,o,s,a){const l=e.x===t.x;if(n.x===i.x!==l||!l&&(e.y!==t.y||n.y!==i.y))return false;if(s?.(2)===false)return void 0;const c=l?e.x:e.y,d=l?n.x:n.y,u=Math.abs(c-d),f=(Math.abs(c)+Math.abs(d)+r)*1e-10+1e-9;if(u>r+f)return false;const h=l?e.y:e.x,m=l?t.y:t.x,p=l?n.y:n.x,g=l?i.y:i.x,y=Math.min(Math.max(h,m),Math.max(p,g))-Math.max(Math.min(h,m),Math.min(p,g)),w=(Math.abs(h)+Math.abs(m)+Math.abs(p)+Math.abs(g))*1e-10+1e-9;if(y<-w)return false;if(y===0){if(s?.(2)===false)return void 0;if(Math.abs(h-m)>2*w&&Math.abs(p-g)>2*w)return false}if(s?.(2)===false)return void 0;if(u<r-f&&y>w)return true;if(s?.(6)===false)return void 0;if(!Number.isFinite(c)||!Number.isFinite(d)||!Number.isFinite(h)||!Number.isFinite(m)||!Number.isFinite(p)||!Number.isFinite(g))return void 0;if(a?.(10)===false)return void 0;if(s?.(256)===false)return void 0;const S=Dd(Xe(c),Xe(d),o,s,a);if(S!==true)return S;if(a?.(20)===false)return void 0;if(s?.(512)===false)return void 0;const x=Number(Xe(h)),M=Number(Xe(m)),b=Number(Xe(p)),C=Number(Xe(g)),P=Math.max(Math.min(x,M),Math.min(b,C)),E=Math.min(Math.max(x,M),Math.max(b,C));return P<E}function Xa(e,t){return e.x===t.x&&e.y===t.y}function Zs(e,t,n,i,r,o,s,a){if(o?.(3)===false)return void 0;const l=i-t;if(!l)return e<n;if(e===n)return l>0;if(e>n?l<0:l>0)return e<n;if(o?.(6)===false)return void 0;const c=Number(r),d=2*(e-n)-l*c,u=32*Number.EPSILON*Math.max(1,Math.abs(e)+Math.abs(n)+Math.abs(l*c));if(Number.isFinite(d)&&Math.abs(d)>u)return d<0;let f,h;if(a){const p=CA(e,a,o,s);if(p===void 0)return void 0;f=p;const g=CA(n,a,o,s);if(g===void 0)return void 0;h=g}else{if(s?.(10)===false||o?.(64)===false)return void 0;f=String(e);h=String(n)}const m=TA(f,h,r,o,s,Math.abs(l)===1,a?.parts);return m===void 0?void 0:l>0?m<0:m>0}function ih(e,t,n,i,r,o){if(o){if(o.width!==void 0){if(i?.(1)===false)return void 0;const h=o.width,m=h/2,p=(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)+h)*1e-10+1e-9;if(e.x0-t.x1+(e.ox0-t.ox1)*m>p||t.x0-e.x1+(t.ox0-e.ox1)*m>p||e.y0-t.y1+(e.oy0-t.oy1)*m>p||t.y0-e.y1+(t.oy0-e.oy1)*m>p)return false}if(i?.(4)===false)return void 0;const c=e.ox0===t.ox1,d=t.ox0===e.ox1,u=e.oy0===t.oy1,f=t.oy0===e.oy1;if(c){if(i?.(1)===false)return void 0;if(!(e.x0<t.x1))return false}if(d){if(i?.(1)===false)return void 0;if(!(t.x0<e.x1))return false}if(u){if(i?.(1)===false)return void 0;if(!(e.y0<t.y1))return false}if(f){if(i?.(1)===false)return void 0;if(!(t.y0<e.y1))return false}if(!c){const h=Zs(e.x0,e.ox0,t.x1,t.ox1,n,i,r,o);if(h!==true)return h}if(!d){const h=Zs(t.x0,t.ox0,e.x1,e.ox1,n,i,r,o);if(h!==true)return h}if(!u){const h=Zs(e.y0,e.oy0,t.y1,t.oy1,n,i,r,o);if(h!==true)return h}if(!f)return Zs(t.y0,t.oy0,e.y1,e.oy1,n,i,r,o);return true}const s=Zs(e.x0,e.ox0,t.x1,t.ox1,n,i,r,o);if(s!==true)return s;const a=Zs(t.x0,t.ox0,e.x1,e.ox1,n,i,r,o);if(a!==true)return a;const l=Zs(e.y0,e.oy0,t.y1,t.oy1,n,i,r,o);if(l!==true)return l;return Zs(t.y0,t.oy0,e.y1,e.oy1,n,i,r,o)}function Ki(e,t,n){if(t?.(2)===false)return void 0;if(Number.isSafeInteger(e.x)&&Number.isSafeInteger(e.y))return e;if(t?.(66)===false||n?.(13)===false)return void 0;if(!Number.isFinite(e.x)||!Number.isFinite(e.y))return void 0;let i=String(e.x),r=String(e.y);if(i.length>=14&&Cu.test(i)){if(n?.(5)===false||t?.(128)===false)return void 0;i=Xe(e.x)}if(r.length>=14&&Cu.test(r)){if(n?.(5)===false||t?.(128)===false)return void 0;r=Xe(e.y)}return{x:Number(i),y:Number(r)}}function O0(e,t,n){if(n?.(9)===false)return void 0;if(e.x===t.x&&e.y===t.y)return void 0;if(e.x===t.x)return{x0:e.x,x1:e.x,y0:Math.min(e.y,t.y),y1:Math.max(e.y,t.y),ox0:-1,ox1:1,oy0:0,oy1:0};if(e.y===t.y)return{x0:Math.min(e.x,t.x),x1:Math.max(e.x,t.x),y0:e.y,y1:e.y,ox0:0,ox1:0,oy0:-1,oy1:1};return void 0}function B0(e,t,n,i,r){if(i?.(8)===false)return void 0;const o=Math.sign(t.x-e.x),s=Math.sign(t.y-e.y),a=Math.sign(n.x-t.x),l=Math.sign(n.y-t.y),c=o*l-s*a;if(!c)return o*a+s*l<0?void 0:false;if(e.x!==t.x&&e.y!==t.y||t.x!==n.x&&t.y!==n.y)return void 0;if(r?.(9)===false)return void 0;const d=c>0?-1:1,u=(-s-l)*d,f=(o+a)*d;return{x0:t.x,x1:t.x,y0:t.y,y1:t.y,ox0:Math.min(0,u),ox1:Math.max(0,u),oy0:Math.min(0,f),oy1:Math.max(0,f)}}function CA(e,t,n,i){if(n?.(1)===false)return void 0;const r=t.texts.get(e);if(r!==void 0)return r;if(i?.(5)===false||n?.(32)===false)return void 0;const o=String(e);if(i?.(2)===false||n?.(1)===false)return void 0;t.texts.set(e,o);return o}function B3(e,t,n){if(n?.(2)===false)return void 0;return t.rows[e]}function ac(e,t,n,i,r,o){if(r?.(3)===false)return void 0;return i.rows[t]?.[n]}function PA(e,t,n,i,r,o,s,a){if(s?.(2)===false)return void 0;let l=o.strips[t];if(!l){if(a?.(e.length+1)===false)return void 0;l=o.strips[t]=new Array(e.length)}const c=l[n];if(c)return c;const d=O0(i,r,a);if(!d)return void 0;if(s?.(1)===false)return void 0;l[n]=d;return d}function EA(e,t,n,i,r,o,s,a){if(s?.(2)===false)return void 0;let l=o.joins[t];if(!l){if(a?.(e.length+1)===false)return void 0;l=o.joins[t]=new Array(e.length)}const c=l[n];if(c!==void 0)return c;const d=ac(e,t,n+1,o,s,a);if(!d)return void 0;const u=B0(i,r,d,s,a);if(u===void 0)return void 0;if(s?.(1)===false)return void 0;l[n]=u;return u}function Zg(e,t,n,i,r,o,s,a=-1){let l=t-1,c=t,d,u;while(l>=0){if(r?.(1)===false)return void 0;d=i?s?ac(e,a,l,s,r,o):Ki(e[l],r,o):e[l];if(!d)return void 0;if(d.x!==n.x||d.y!==n.y)break;l--}while(c<e.length){if(r?.(1)===false)return void 0;u=i?s?ac(e,a,c,s,r,o):Ki(e[c],r,o):e[c];if(!u)return void 0;if(u.x!==n.x||u.y!==n.y)break;c++}if(l<0||c>=e.length||!d||!u)return false;return d.x===n.x&&u.x===n.x&&Math.min(d.y,u.y)<n.y&&n.y<Math.max(d.y,u.y)||d.y===n.y&&u.y===n.y&&Math.min(d.x,u.x)<n.x&&n.x<Math.max(d.x,u.x)}function W3(e,t,n,i,r,o,s,a,l,c,d,u){const f=i.edges[t];let h,m;let p;if(d){const g=B3(t,d,a);if(!g)return void 0;p=g}else{if(l?.(e.length+2)===false)return void 0;p=new Array(e.length)}for(let g=0;g<s.length;g++){if(a?.(1)===false)return void 0;const y=s[g],w=n[y],S=i.edges[y];if(d&&a?.(1)===false)return void 0;let x=d?.rows[y];const M=u?.[y];let b=0;for(let C=1;u?!!M&&b<M.length:C<e.length;C++)for(let P=1;u?b<M.length:P<w.points.length;P++){const E=b;if(u){if(a?.(2)===false)return void 0;C=M[b];P=M[b+1];b+=3}if(a?.(1)===false)return void 0;const k=e[C-1],v=e[C],T=w.points[P-1],A=w.points[P],R=(Math.abs(k.x)+Math.abs(k.y)+Math.abs(v.x)+Math.abs(v.y)+Math.abs(T.x)+Math.abs(T.y)+Math.abs(A.x)+Math.abs(A.y)+r)*1e-10+1e-9,I=r+R;if(Math.min(k.x,v.x)-Math.max(T.x,A.x)>I||Math.min(T.x,A.x)-Math.max(k.x,v.x)>I||Math.min(k.y,v.y)-Math.max(T.y,A.y)>I||Math.min(T.y,A.y)-Math.max(k.y,v.y)>I)continue;const L=k.x===v.x,$=T.x===A.x;if(L!==$&&(k.x===v.x||k.y===v.y)&&(T.x===A.x||T.y===A.y)){const G=L?k.x:T.x,Y=L?T.y:k.y,q=L?T:k,V=L?A:v,ne=L?k:T,X=L?v:A;if(G>Math.min(q.x,V.x)+I&&G<Math.max(q.x,V.x)-I&&Y>Math.min(ne.y,X.y)+I&&Y<Math.max(ne.y,X.y)-I)continue}if(!x){if(d)return void 0;if(l?.(w.points.length+1)===false)return void 0;x=new Array(w.points.length)}if(a?.(4)===false)return void 0;const B=p[C-1]??(p[C-1]=d?ac(e,t,C-1,d,a,l):Ki(k,a,l));if(!B)return void 0;const F=p[C]??(p[C]=d?ac(e,t,C,d,a,l):Ki(v,a,l));if(!F)return void 0;const z=x[P-1]??(x[P-1]=d?ac(w.points,y,P-1,d,a,l):Ki(T,a,l));if(!z)return void 0;const _=x[P]??(x[P]=d?ac(w.points,y,P,d,a,l):Ki(A,a,l));if(!_)return void 0;const H=d?PA(e,t,C,B,F,d,a,l):O0(B,F,l);if(!H)return void 0;const D=d?PA(w.points,y,P,z,_,d,a,l):O0(z,_,l);if(!D)return void 0;const j=B.x===F.x,W=z.x===_.x;if(d?.contactOnly&&j===W){if(a?.(2)===false)return void 0;const G=Math.max(j?Math.min(B.y,F.y):Math.min(B.x,F.x),j?Math.min(z.y,_.y):Math.min(z.x,_.x)),Y=Math.min(j?Math.max(B.y,F.y):Math.max(B.x,F.x),j?Math.max(z.y,_.y):Math.max(z.x,_.x));if(G<Y){const q=j?B.x:B.y,V=j?z.x:z.y,ne=Zs(Math.max(q,V),-2,Math.min(q,V),0,o,a,l,d);if(ne!==false)return ne===void 0?void 0:_d(c,C,y,P,a)}}else if(j===W&&(k.x!==v.x&&k.y!==v.y||T.x!==A.x&&T.y!==A.y)){const G=ih(H,D,o,a,l,d);if(G!==false)return G===void 0?void 0:_d(c,C,y,P,a)}if(j!==W){const G=ih(H,D,o,a,l,d);if(G===void 0)return void 0;if(G){if(l?.(6)===false)return void 0;const Y={x:j?k.x:T.x,y:j?T.y:k.y},q={x:j?B.x:z.x,y:j?z.y:B.y};let V=false;if(d?.contactOnly&&d.numericSeed&&(k.x!==v.x&&k.y!==v.y||T.x!==A.x&&T.y!==A.y)){if(a?.(1)===false)return void 0;if(M?.[E+2]===1){if(!h){if(l?.(20)===false)return void 0;h=[{points:p},{points:x}];m=[{a:B,b:F,edgeIndex:0,pointIndex:C-1},{a:z,b:_,edgeIndex:1,pointIndex:P-1}]}if(a?.(7+p.length+x.length)===false||l?.(4)===false)return void 0;h[1].points=x;const Q=m[0],se=m[1];Q.a=B;Q.b=F;Q.pointIndex=C-1;se.a=z;se.b=_;se.pointIndex=P-1;V=!!fd(Q,se,h)}}else{const Q=Zg(e,C,Y,false,a,l);if(Q===void 0)return void 0;const se=Zg(w.points,P,Y,false,a,l);if(se===void 0)return void 0;if(Q&&se){const te=Zg(e,C,q,true,a,l,d,t);if(te===void 0)return void 0;const ee=Zg(w.points,P,q,true,a,l,d,y);if(ee===void 0)return void 0;V=te&&ee}}const ne=e[0],X=e.at(-1),U=w.points[0],K=w.points.at(-1);if(a?.(4)===false)return void 0;const Z=C===1&&P===1&&f.source===S.source&&Xa(Y,ne)&&Xa(Y,U)||C===1&&P===w.points.length-1&&f.source===S.target&&Xa(Y,ne)&&Xa(Y,K)||C===e.length-1&&P===1&&f.target===S.source&&Xa(Y,X)&&Xa(Y,U)||C===e.length-1&&P===w.points.length-1&&f.target===S.target&&Xa(Y,X)&&Xa(Y,K);if(!V&&!Z)return _d(c,C,y,P,a)}}let O=false,N=false;if(C+1<e.length){if(d){const G=EA(e,t,C,B,F,d,a,l);if(G===void 0)return void 0;O=G}else{if(a?.(1)===false)return void 0;const G=p[C+1]??(p[C+1]=Ki(e[C+1],a,l));if(!G)return void 0;const Y=B0(B,F,G,a,l);if(Y===void 0)return void 0;O=Y}}if(P+1<w.points.length){if(d){const G=EA(w.points,y,P,z,_,d,a,l);if(G===void 0)return void 0;N=G}else{if(a?.(1)===false)return void 0;const G=x[P+1]??(x[P+1]=Ki(w.points[P+1],a,l));if(!G)return void 0;const Y=B0(z,_,G,a,l);if(Y===void 0)return void 0;N=Y}}if(O){const G=ih(O,D,o,a,l,d);if(G!==false)return G===void 0?void 0:_d(c,C,y,P,a)}if(N){const G=ih(H,N,o,a,l,d);if(G!==false)return G===void 0?void 0:_d(c,C,y,P,a)}if(O&&N){const G=ih(O,N,o,a,l,d);if(G!==false)return G===void 0?void 0:_d(c,C,y,P,a)}}}return true}function RA(e){for(let t=0;t<e.length;t++){const n=e[t];if(!Number.isFinite(n.x)||!Number.isFinite(n.y)||t&&n.x!==e[t-1].x&&n.y!==e[t-1].y)return false}return true}function os(e,t,n,i,r,o,s,a=3,l=false){return W0(e,t,n,i,r,o,true,s,a,l)}function z3(e,t,n){let i=false;for(const u of e)for(let f=1;f<u.points.length;f++){if(t?.(1)===false)return void 0;const h=u.points[f-1],m=u.points[f];if(h.x!==m.x&&h.y!==m.y)i=true}if(!i)return false;if(n?.(e.length+18)===false)return void 0;const r=new Array(e.length),o=[],s=[],a=[],l=[];for(let u=0;u<e.length;u++){const f=e[u].points;if(t?.(1)===false||n?.(5*f.length+5)===false)return void 0;const h=new Array(f.length),m=new Array(f.length);for(let p=0;p<f.length;p++){if(t?.(3)===false)return void 0;const g=f[p],y=Ki(g,t,n);if(!y)return void 0;h[p]={x:g.x,y:g.y};if(y===g){if(n?.(3)===false)return void 0;m[p]={x:y.x,y:y.y}}else m[p]=y}r[u]={raw:h,points:m};for(let p=0;p+1<m.length;p++){if(t?.(4)===false)return void 0;const g=m[p],y=m[p+1];if(g.x===y.x===(g.y===y.y))return false;if(n?.(15)===false)return void 0;const w={owner:u,segment:p},S=g.x===y.x;(S?s:o).push({key:S?g.x:g.y,piece:w});(S?l:a).push({key:S?g.y:g.x,piece:w},{key:S?y.y:y.x,piece:w})}}const c={},d=(u,f)=>{if(t?.(1)===false)throw c;return u.key-f.key||u.piece.owner-f.piece.owner||u.piece.segment-f.piece.segment};try{for(const u of[o,s,a,l])u.sort(d)}catch(u){if(u===c)return void 0;throw u}return{routes:r,horizontal:o,vertical:s,horizontalEnds:a,verticalEnds:l}}function LA(e,t,n,i,r=false,o){if(!o&&t.maximumEdgeStrokeWidth!==void 0&&t.maximumEdgeBendRadius===0){const M=z3(e,n,i);if(M===void 0)return void 0;if(M)o=M}if(!o){if(r)for(const M of e){let b;for(const C of M.points){const P=Ki(C,n,i);if(!P)return void 0;if(n?.(2)===false)return void 0;if(b&&(P.x===b.x&&P.y===b.y||P.x!==b.x&&P.y!==b.y))return false;b=P}}if(i?.(1)===false)return void 0;return(M,b)=>{if(n?.(e.length)===false)return false;let C=0;for(let k=0;k<e.length;k++)if(k!==M&&e[k].style!=="invisible")C+=Math.max(0,e[k].points.length-1);const P=e[M].points,E=ea(t);if(n?.(E*Math.max(0,P.length-1)*C+P.length+C+e.length)===false)return false;return os(P,M,e,t,n,i,b,E,true)!==void 0}}if(n?.(e.length+1)===false)return void 0;if(o.routes.length!==e.length)return false;let s=0;for(const M of e)s+=Math.max(0,M.points.length-1);if(i?.(4*e.length+28+2*s+4)===false)return void 0;const a=new Array(e.length),l=new Array(e.length),c=[],d=[];let u=0,f=0;for(let M=0;M<e.length;M++){if(n?.(3)===false)return void 0;const b=e[M].points,C=o.routes[M];l[M]=f;f+=Math.max(0,b.length-1);if(b.length!==C.raw.length||b.length!==C.points.length)return false;a[M]=C.points;let P;for(let E=0;E<b.length;E++){if(n?.(7)===false)return void 0;const k=b[E],v=C.raw[E],T=C.points[E];if(k.x!==v.x||k.y!==v.y||!Number.isFinite(k.x)||!Number.isFinite(k.y)||!Number.isFinite(T.x)||!Number.isFinite(T.y))return false;if(P&&(T.x===P.x&&T.y===P.y||T.x!==P.x&&T.y!==P.y))return false;P=T;u+=Math.abs(k.x)+Math.abs(k.y)}}const h=t.maximumEdgeStrokeWidth;let m,p;if(Number.isSafeInteger(h)&&h>0){if(i?.(4)===false||n?.(h<10?2:17)===false)return void 0;m=h;p=String(h)}else{if(i?.(5)===false||n?.(128)===false)return void 0;p=Xe(h);m=Number(p)}if(!Number.isFinite(m)||m<=0||t.maximumEdgeBendRadius!==0)return false;const g=Math.max(m,Sp)+(u+m)*1e-10+1e-9,y=Sp+(u+m)*1e-10+1e-9,w=u>Math.sqrt(Number.MAX_VALUE)/4,S=new Uint8Array(s);for(let M=0;M<2;M++)for(const b of M?o.horizontal:o.vertical){if(n?.(3)===false)return void 0;const C=e[b.piece.owner].points,P=o.routes[b.piece.owner].points,E=G3(C,P,b.piece.segment,y,w,n);if(E===void 0)return void 0;if(E){if(i?.(1)===false||n?.(1)===false)return void 0;S[l[b.piece.owner]+b.piece.segment]=1;(M?c:d).push(b)}}const x={rows:a,rangeStarts:new Map,parts:new Map,texts:new Map,strips:new Array(e.length),joins:new Array(e.length),numericSeed:o,width:m,widthText:p,margin:g,offsets:l,driftHorizontal:c,driftVertical:d,seen:new Uint32Array(s),fullCandidates:S,epoch:0,contactOnly:true};return(M,b)=>W0(e[M].points,M,e,t,n,i,true,b,1,false,x)!==void 0}function rh(e,t,n,i,r,o){return W0(e,t,n,i,r,o,false)}function G3(e,t,n,i,r,o){if(o?.(4)===false)return void 0;const s=e[n],a=e[n+1],l=t[n],c=t[n+1];if(r||s.x!==a.x&&s.y!==a.y)return true;for(let d=0;d<2;d++){if(o?.(2)===false)return void 0;const u=d?e.length-1:0,f=e[u],h=t[u];if(f.x===s.x&&f.y===s.y&&h.x===l.x&&h.y===l.y||f.x===a.x&&f.y===a.y&&h.x===c.x&&h.y===c.y)continue;for(let m=0;m<2;m++){if(o?.(1)===false)return void 0;const p=m?l:s,g=m?c:a,y=m?h:f;if(y.x>=Math.min(p.x,g.x)-i&&y.x<=Math.max(p.x,g.x)+i&&y.y>=Math.min(p.y,g.y)-i&&y.y<=Math.max(p.y,g.y)+i)return true}}return false}function H3(e,t,n,i,r){if(i?.(2)===false)return void 0;let o=n.rangeStarts.get(e);const s=o?.get(t);if(s!==void 0)return s;let a=0,l=e.length;while(a<l){if(i?.(1)===false)return void 0;const c=a+l>>>1;if(e[c].key<t)a=c+1;else l=c}if(!o){if(r?.(3)===false||i?.(1)===false)return void 0;o=new Map;n.rangeStarts.set(e,o)}if(r?.(2)===false||i?.(1)===false)return void 0;o.set(t,a);return a}function j3(e,t,n,i,r,o){let s;const a=i.numericSeed,l=i.margin;for(let c=1;c<e.length;c++){if(r?.(4)===false)return void 0;const d=e[c-1],u=e[c];if(i.contactOnly&&r?.(1)===false)return void 0;const f=d.x===u.x,h=i.contactOnly&&!i.fullCandidates[i.offsets[t]+c-1];if(i.contactOnly){if(r?.(1)===false)return void 0;i.epoch++;if(i.epoch===4294967296){if(r?.(i.seen.length)===false)return void 0;i.seen.fill(0);i.epoch=1}}for(let m=0;m<(h?5:2);m++){if(r?.(4)===false)return void 0;let p,g,y;if(!h){p=m?a.horizontal:a.vertical;g=Math.min(m?d.y:d.x,m?u.y:u.x)-l;y=Math.max(m?d.y:d.x,m?u.y:u.x)+l}else if(m===0){p=f?a.vertical:a.horizontal;g=(f?d.x:d.y)-l;y=(f?d.x:d.y)+l}else if(m===1||m===2){p=f?a.horizontal:a.vertical;const S=m===1?d:u;g=(f?S.y:S.x)-l;y=(f?S.y:S.x)+l}else if(m===3){p=f?a.horizontalEnds:a.verticalEnds;g=(f?d.x:d.y)-l;y=(f?d.x:d.y)+l}else{p=f?i.driftHorizontal:i.driftVertical;g=Math.min(f?d.y:d.x,f?u.y:u.x)-l;y=Math.max(f?d.y:d.x,f?u.y:u.x)+l}const w=H3(p,g,i,r,o);if(w===void 0)return void 0;for(let S=w;S<p.length;S++){if(r?.(3)===false)return void 0;const x=p[S];if(x.key>y)break;const M=x.piece;if(M.owner===t||n[M.owner].style==="invisible")continue;if(i.contactOnly){if(r?.(2)===false)return void 0;const k=i.offsets[M.owner]+M.segment;if(i.seen[k]===i.epoch)continue;i.seen[k]=i.epoch}if(r?.(1)===false)return void 0;const b=n[M.owner].points,C=b[M.segment],P=b[M.segment+1];if(vA(d,u,C,P,i.width))continue;if(!s){if(o?.(n.length+1)===false)return void 0;s=new Array(n.length)}let E=s[M.owner];if(!E){if(o?.(1)===false)return void 0;E=s[M.owner]=[]}if(o?.(3)===false||r?.(1)===false)return void 0;E.push(c,M.segment+1,0)}}}return s??null}function W0(e,t,n,i,r,o,s,a,l=3,c=false,d){let u=0;let f,h;if(d){if(r?.(2)===false)return void 0;f=d.width;h=d.widthText}else if(i.maximumEdgeStrokeWidth!==void 0){if(o?.(4)===false)return void 0;const M=i.maximumEdgeStrokeWidth;if(Number.isSafeInteger(M)&&M>0){if(r?.(M<10?2:17)===false)return void 0;f=M;h=String(M)}else{if(r?.(128)===false)return void 0;h=Xe(M);f=Number(h)}if(!Number.isFinite(f)||f<=0)throw new TypeError("Measured stroke width must be finite and positive")}let m;let p=false;if(d){if(r?.(2)===false)return void 0;p=d.contactOnly&&f!==void 0&&i.maximumEdgeBendRadius===0}if(s&&f!==void 0&&i.maximumEdgeBendRadius===0){if(o?.(1)===false)return void 0;m=[]}let g=false;if(d){g=j3(e,t,n,d,r,o);if(g===void 0)return void 0;if(g===null)return 0}let y;let w;const S=i.edges[t],x=[{points:e},{points:[]}];if(d&&r?.(n.length)===false)return void 0;for(let M=0;M<n.length;M++){const b=n[M];if(M===t||b.style==="invisible")continue;let C=!c;if(g){if(r?.(1)===false)return void 0;if(!g[M]?.length)continue}if(m){if(o?.(1)===false||r?.(1)===false)return void 0;if(C)m.push(M)}const P=i.edges[M];let E;let k;if(d){if(r?.(1)===false)return void 0;x[1].points=b.points}let v=0;const T=g?g[M]:void 0;for(let R=1;g?v<T.length:R<e.length;R++)for(let I=1;g?v<T.length:I<b.points.length;I++){const L=v;if(g){if(r?.(2)===false)return void 0;R=T[v];I=T[v+1];v+=3}if(d&&!g&&r?.(l)===false)return void 0;const $=e[R-1],B=e[R],F=b.points[I-1],z=b.points[I];if(!g&&s&&f!==void 0&&i.maximumEdgeBendRadius===0){const K=D3($,B,F,z,f);if(K===void 0){const Z=Ki($,r,o);if(!Z)return void 0;const Q=Ki(B,r,o);if(!Q)return void 0;const se=Ki(F,r,o);if(!se)return void 0;const te=Ki(z,r,o);if(!te)return void 0;if(r?.(4)===false)return void 0;if(Z.x!==Q.x&&Z.y!==Q.y||se.x!==te.x&&se.y!==te.y)return void 0}if(K===true)continue;C=true}if((g||l===1)&&r?.(p?1:2)===false)return void 0;if(!p){if(f===void 0){if(_3($,B,F,z))return void 0}else{const K=O3($,B,F,z,f,h,r,o);if(K!==false)return void 0}}if(d){if(r?.(1)===false)return void 0;if(($.x!==B.x||$.y!==B.y)&&(F.x!==z.x||F.y!==z.y)&&Math.min($.x,B.x)<=Math.max(F.x,z.x)&&Math.min(F.x,z.x)<=Math.max($.x,B.x)&&Math.min($.y,B.y)<=Math.max(F.y,z.y)&&Math.min(F.y,z.y)<=Math.max($.y,B.y)){if(!y){if(o?.(13)===false)return void 0;y=[{a:$,b:B,edgeIndex:0,pointIndex:R-1},{a:F,b:z,edgeIndex:1,pointIndex:I-1}]}if(r?.(7+e.length+b.points.length)===false||o?.(4)===false)return void 0;const K=y[0],Z=y[1];K.a=$;K.b=B;K.pointIndex=R-1;Z.a=F;Z.b=z;Z.pointIndex=I-1;const Q=fd(K,Z,x);if(Q){if(!k){if(o?.(1)===false)return void 0;k=[]}if(r?.(k.length)===false||o?.(2)===false)return void 0;wp(k,Q);if(p&&($.x!==B.x&&$.y!==B.y||F.x!==z.x&&F.y!==z.y)){if(r?.(1)===false)return void 0;T[L+2]=1}}}}const _=$.x===B.x,H=F.x===z.x;let D=0,j=0,W=false;if(_!==H){D=_?$.x:F.x;j=_?F.y:$.y;W=D>=Math.min($.x,B.x)&&D<=Math.max($.x,B.x)&&j>=Math.min($.y,B.y)&&j<=Math.max($.y,B.y)&&D>=Math.min(F.x,z.x)&&D<=Math.max(F.x,z.x)&&j>=Math.min(F.y,z.y)&&j<=Math.max(F.y,z.y)}else if(_?$.x===F.x:$.y===F.y){const K=Math.max(_?Math.min($.y,B.y):Math.min($.x,B.x),_?Math.min(F.y,z.y):Math.min(F.x,z.x));const Z=Math.min(_?Math.max($.y,B.y):Math.max($.x,B.x),_?Math.max(F.y,z.y):Math.max(F.x,z.x));if(Z>=K){D=_?$.x:K;j=_?K:$.y;W=true}}if(!W)continue;const O=e[0],N=e.at(-1),G=b.points[0],Y=b.points.at(-1);const q=O.x===D&&O.y===j,V=N.x===D&&N.y===j;const ne=G.x===D&&G.y===j,X=Y.x===D&&Y.y===j;const U=S.source===P.source&&q&&ne||S.source===P.target&&q&&X||S.target===P.source&&V&&ne||S.target===P.target&&V&&X;if(!U)(E??=new Set).add(`${D},${j}`)}if(m&&c&&C)m.push(M);let A;if(d){if(k){const R=k.length;if(r?.(2*R*R+R)===false||o?.(2*R+1)===false)return void 0;A=Mp(k)}else A=0}else{if(!E&&(w??=RA(e))&&RA(b.points))continue;x[1].points=b.points;A=Or(x)}if(A<(E?.size??0))return void 0;u+=A}if(s&&f!==void 0&&i.maximumEdgeBendRadius===0&&m.length&&W3(e,t,n,i,f,h,m,r,o,a,d,g||void 0)!==true)return void 0;return u}function AA(e){if(!e||typeof e!=="object")throw new TypeError("Invalid measured marker paint");for(const t of[e.start,e.end]){if(t===void 0)continue;if(!Array.isArray(t)||t.length>64)throw new TypeError("Invalid measured marker pieces");for(const n of t){if(n.kind==="circle"){if(![n.cx,n.cy,n.r].every(i=>Number.isFinite(i*i*16))||!(n.r>0))throw new TypeError("Invalid measured marker circle")}else if(n.kind==="polygon"){if(!Array.isArray(n.points)||n.points.length<3||n.points.length>32)throw new TypeError("Invalid measured marker polygon");for(const r of n.points)if(!Number.isFinite(r.x*r.x*16)||!Number.isFinite(r.y*r.y*16))throw new TypeError("Invalid measured marker coordinate");let i=0;for(let r=0;r<n.points.length;r++){const o=n.points[r],s=n.points[(r+1)%n.points.length],a=n.points[(r+2)%n.points.length];const l=(s.x-o.x)*(a.y-s.y)-(s.y-o.y)*(a.x-s.x);if(!Number.isFinite(l)||l&&i&&Math.sign(l)!==i)throw new TypeError("Nonconvex measured marker polygon");if(l)i=Math.sign(l)}if(!i)throw new TypeError("Empty measured marker polygon")}else throw new TypeError("Invalid measured marker kind")}}}function Y3(e,t,n,i,r,o,s,a){s();const l=e.x===t.x;if(n.x===i.x!==l)return false;s(2);const c=l?e.x:e.y,d=l?n.x:n.y,u=(Math.abs(c)+Math.abs(d)+Math.abs(r))*1e-10+1e-9;if(Math.abs(c-d)>r+u)return false;s(2);const f=Math.min(l?e.y:e.x,l?t.y:t.x),h=Math.max(l?e.y:e.x,l?t.y:t.x),m=Math.min(l?n.y:n.x,l?i.y:i.x),p=Math.max(l?n.y:n.x,l?i.y:i.x),g=(Math.abs(f)+Math.abs(h)+Math.abs(m)+Math.abs(p))*1e-10+1e-9;if(Math.min(h,p)<Math.max(f,m)-g)return false;a(42);s(384);const y=Dd(Xe(c),Xe(d),Xe(o),s);if(y!==true)return y===void 0;a(20);s(512);const w=Number(Xe(l?e.y:e.x)),S=Number(Xe(l?t.y:t.x)),x=Number(Xe(l?n.y:n.x)),M=Number(Xe(l?i.y:i.x));return Math.min(Math.max(w,S),Math.max(x,M))>Math.max(Math.min(w,S),Math.min(x,M))}function IA(e,t,n,i,r,o,s,a,l,c,d=0,u,f){i.arcs-=18;if(i.arcs<0)o("agentic marker seating capacity limit");const h=(N=1)=>{i.pairs-=N;if(i.pairs<0)o("agentic marker seating work limit")};const m=N=>{i.arcs-=N;if(i.arcs<0)o("agentic marker seating capacity limit")};const p=[];let g=0;for(const N of e){h();if(N.visible!==false)g+=Number(!!N.markerPaint?.start?.length)+Number(!!N.markerPaint?.end?.length)}let y=0,w=0;if(c!==void 0){if(!Number.isFinite(c)||c<=0||!Number.isFinite(d)||d<0)throw new TypeError("Invalid measured marker carrier width");for(let N=0;N<t.length;N++){h();if(e[N].visible===false)continue;const G=t[N].points;h(2);if(G.length===2)w++;y+=Math.max(0,G.length-1);for(let Y=1;Y+1<G.length;Y++){h(4);const q=G[Y-1],V=G[Y],ne=G[Y+1];if(q.x===V.x!==(V.x===ne.x))y++}}}const S=4*(g+y+4*w+(u?.obstacles.length??0))+8;m(S);h(S);const x=new Float64Array(S);m(2*y+2*t.length+9);r(4);const M=[],b=[],C=[{kind:"polygon",points:[{x:0,y:0},{x:0,y:0},{x:0,y:0},{x:0,y:0}]}];const P=(c??0)/2;const E=(N,G,Y)=>{h(13);if(!Number.isFinite(G.x)||!Number.isFinite(G.y)||!Number.isFinite(Y.x)||!Number.isFinite(Y.y)||G.x!==Y.x&&G.y!==Y.y)o("Unsupported measured marker carrier");N.a=G;N.b=Y;const q=P+(N.join?d:0);N.minX=Math.min(G.x,Y.x)-q;N.maxX=Math.max(G.x,Y.x)+q;N.minY=Math.min(G.y,Y.y)-q;N.maxY=Math.max(G.y,Y.y)+q};const k=N=>{const G=b[N],Y=t[N].points;G.minX=G.minY=Infinity;G.maxX=G.maxY=-Infinity;h(4);for(let q=G.begin;q<G.end;q++){const V=M[q];E(V,Y[V.point],V.join?Y[V.point]:Y[V.point+1]);h(4);G.minX=Math.min(G.minX,V.minX);G.maxX=Math.max(G.maxX,V.maxX);G.minY=Math.min(G.minY,V.minY);G.maxY=Math.max(G.maxY,V.maxY)}};for(let N=0;N<t.length;N++){h();const G=M.length;if(c!==void 0&&e[N].visible!==false)for(let Y=1;Y<t[N].points.length;Y++){h();M.push({current:true,a:t[N].points[Y-1],b:t[N].points[Y],point:Y-1,join:false,minX:0,maxX:0,minY:0,maxY:0})}if(c!==void 0&&e[N].visible!==false)for(let Y=1;Y+1<t[N].points.length;Y++){h(4);const q=t[N].points[Y-1],V=t[N].points[Y],ne=t[N].points[Y+1];if(q.x===V.x!==(V.x===ne.x))M.push({current:true,a:V,b:V,point:Y,join:true,minX:0,maxX:0,minY:0,maxY:0})}b.push({begin:G,end:M.length,minX:Infinity,maxX:-Infinity,minY:Infinity,maxY:-Infinity});k(N)}m(1);const v=(N,G)=>{const Y=b[N],q=M.length;m(10);for(let V=0;V<3;V++){h();M.push({current:true,a:G[V],b:G[V+1],point:V,join:false,minX:0,maxX:0,minY:0,maxY:0})}for(let V=1;V<3;V++){h();M.push({current:true,a:G[V],b:G[V],point:V,join:true,minX:0,maxX:0,minY:0,maxY:0})}for(let V=Y.begin;V<Y.end;V++){h();M[V].current=false}Y.begin=q;Y.end=M.length};const T=(N,G)=>{h(5);return N.maxX>G.minX&&N.minX<G.maxX&&N.maxY>G.minY&&N.minY<G.maxY};const A=(N,G)=>{if(!T(N,G))return false;const Y=G.a,q=G.b,V=C[0].points;h(8);if(G.join){V[0].x=G.minX;V[0].y=G.minY;V[1].x=G.maxX;V[1].y=G.minY;V[2].x=G.maxX;V[2].y=G.maxY;V[3].x=G.minX;V[3].y=G.maxY}else if(Y.x===q.x){V[0].x=G.minX;V[0].y=Math.min(Y.y,q.y);V[1].x=G.maxX;V[1].y=V[0].y;V[2].x=G.maxX;V[2].y=Math.max(Y.y,q.y);V[3].x=G.minX;V[3].y=V[2].y}else{V[0].x=Math.min(Y.x,q.x);V[0].y=G.minY;V[1].x=Math.max(Y.x,q.x);V[1].y=G.minY;V[2].x=V[1].x;V[2].y=G.maxY;V[3].x=V[0].x;V[3].y=G.maxY}return nh(N.pieces,C,h)};let R=1;for(const N of b){h(4);if(N.begin<N.end)R=Math.max(R,Math.abs(N.minX),Math.abs(N.maxX),Math.abs(N.minY),Math.abs(N.maxY))}for(const N of n){h(4);R=Math.max(R,Math.abs(N.x),Math.abs(N.y),Math.abs(N.x+N.width),Math.abs(N.y+N.height))}if(u){h(4);R=Math.max(R,Math.abs(u.bounds.x),Math.abs(u.bounds.y),Math.abs(u.bounds.x+u.bounds.width),Math.abs(u.bounds.y+u.bounds.height))}const I=(R+Math.abs(c??0))*1e-10+1e-9;const L=N=>{m(5);h(128);return Number(Xe(N))};const $=c===void 0?0:L(c);const B=(N,G)=>{if(c===void 0||G.join)return true;const Y=G.a,q=G.b,V=Y.x===q.x,ne=V?Y.x:Y.y,X=Math.min(V?Y.y:Y.x,V?q.y:q.x),U=Math.max(V?Y.y:Y.x,V?q.y:q.x);for(let K=0;K<b.length;K++){h();if(K===N)continue;const Z=b[K];h(5);if(G.maxX<Z.minX-I||G.minX>Z.maxX+I||G.maxY<Z.minY-I||G.minY>Z.maxY+I)continue;for(let Q=Z.begin;Q<Z.end;Q++){h();const se=M[Q];if(se.join)continue;if(Y3(Y,q,se.a,se.b,c,$,h,m))return false}}return true};const F={current:true,a:void 0,b:void 0,point:0,join:false,minX:0,maxX:0,minY:0,maxY:0};const z=(N,G,Y,q,V)=>{h(10);if(!Number.isFinite(G.x)||!Number.isFinite(G.y)||!Number.isFinite(Y.x)||!Number.isFinite(Y.y))o("Nonfinite measured marker normal");const ne=Math.sign(Y.x-G.x),X=Math.sign(Y.y-G.y);if(Number(!ne)+Number(!X)!==1)o("Nonorthogonal measured marker normal");let U=0;for(const Z of N){h();if(Z.kind==="polygon")U+=Z.points.length}m(2+2*N.length+U);r(U);const K={owner:q,source:V,pieces:[],minX:Infinity,maxX:-Infinity,minY:Infinity,maxY:-Infinity};for(const Z of N){h();if(Z.kind==="circle"){const Q=G.x+ne*Z.cx-X*Z.cy,se=G.y+X*Z.cx+ne*Z.cy;K.pieces.push({kind:"circle",cx:Q,cy:se,r:Z.r});K.minX=Math.min(K.minX,Q-Z.r);K.maxX=Math.max(K.maxX,Q+Z.r);K.minY=Math.min(K.minY,se-Z.r);K.maxY=Math.max(K.maxY,se+Z.r)}else{const Q={kind:"polygon",points:[]};for(const se of Z.points){h();const te=G.x+ne*se.x-X*se.y,ee=G.y+X*se.x+ne*se.y;Q.points.push({x:te,y:ee});K.minX=Math.min(K.minX,te);K.maxX=Math.max(K.maxX,te);K.minY=Math.min(K.minY,ee);K.maxY=Math.max(K.maxY,ee)}K.pieces.push(Q)}}return K};m(g+1);const _=[];for(let N=0;N<e.length;N++){h();if(e[N].visible===false)continue;for(let G=0;G<2;G++){h();const Y=G===0?e[N].markerPaint?.start:e[N].markerPaint?.end;if(!Y?.length)continue;const q=t[N].points,V=G===0;_.push(z(Y,V?q[0]:q.at(-1),V?q[1]:q.at(-2),N,V))}}const H=(N,G,Y)=>{if(l&&!l(G,Y,N.pieces,N))return false;if(c!==void 0)for(let q=0;q<b.length;q++){h();const V=b[q];if(!T(N,V))continue;for(let ne=V.begin;ne<V.end;ne++){h();const X=M[ne];if(q===G&&(X.join?X.point===(Y?1:t[G].points.length-2):Y?X.point<=1:X.point>=t[G].points.length-3))continue;if(A(N,X))return false}}for(const q of p){h(5);if(N.maxX<=q.minX||N.minX>=q.maxX||N.maxY<=q.minY||N.minY>=q.maxY)continue;if(nh(N.pieces,q.pieces,h))return false}return true};let D=0;m(3*e.length+2);h(3*e.length);const j=new Uint8Array(3*e.length);const W=(N,G,Y,q,V,ne,X=-1,U,K=-1)=>{let Z=false;for(let Q=0;Q<b.length&&!Z&&D<8;Q++){h();if(U?Q!==K:V===0&&Q===N)continue;const se=b[Q],te=t[Q].points;for(let ee=se.begin;ee<se.end&&!Z&&D<8;ee++){h(8);const ae=M[ee],ie=ae.point;if(ae.join||ie<1||ie+2>=te.length)continue;const oe=te[ie],ue=te[ie+1],ye=te[ie-1],Se=te[ie+2],Te=oe.y===ue.y;let Ie=false;if(U){h(5);const le=Q===X?U.candidateSegment:U.peerSegment;Ie=le>=ie&&le<=ie+2}else{if(Te!==q)continue;h(4);const le=Q===N,we=le&&(G?ie<=1:ie>=te.length-3);Ie=!we&&A(Y,ae);if(V===0&&!Ie)continue;for(let ke=0;ke<2&&!Ie;ke++){h(8);const Le=M[se.begin+ie+(ke===0?-1:1)];if(le&&(G?Le.point<=1:Le.point>=te.length-3))continue;if(A(Y,Le))Ie=true}if(!Ie){h(3);let ke=se.begin+te.length-1,Le=se.end;while(ke<Le){h(3);const Fe=ke+Math.floor((Le-ke)/2);if(M[Fe].point<ie)ke=Fe+1;else Le=Fe}for(let Fe=ke;Fe<se.end&&!Ie;Fe++){h(8);const Oe=M[Fe];if(Oe.point>ie+1)break;if(le&&Oe.point===(G?1:te.length-2))continue;if(A(Y,Oe))Ie=true}}}if(!Ie)continue;const Ee=Te?Math.min(oe.x,ue.x):Math.min(oe.y,ue.y),ve=Te?Math.max(oe.x,ue.x):Math.max(oe.y,ue.y);if(Te?ye.x!==oe.x||Se.x!==ue.x:ye.y!==oe.y||Se.y!==ue.y)continue;const $e=e[Q].label,De=$e?t[Q].labelPosition:void 0;let fe=false,me=false;if(De&&V===0){let le=false;for(let we=ie-1;we<=ie+1;we++){h(6);if(Ji(De,te[we],te[we+1])){le=true;break}}if(le)continue}else if(De){h(18);if(Ji(De,oe,ue))continue;fe=Ji(De,ye,oe);me=Ji(De,ue,Se)}const de=Te?oe.y:oe.x,be=Te?ye.y:ye.x,pe=Te?Se.y:Se.x;let Re=Te?ne.bounds.y:ne.bounds.x,Ne=Re+(Te?ne.bounds.height:ne.bounds.width);if(de===be||de===pe)continue;if(de>be)Re=Math.max(Re,be);else Ne=Math.min(Ne,be);if(de>pe)Re=Math.max(Re,pe);else Ne=Math.min(Ne,pe);if(De&&$e&&(fe||me)){h();if(d!==0)continue;h(6);const le=Te?De.y:De.x,we=(Te?$e.height:$e.width)/2+2+P,ke=le-we,Le=le+we;let Fe=false;for(let Oe=0;Oe<2;Oe++){h(12);if(Oe===0?!fe:!me)continue;const We=Oe===0?be:pe;if(ke<Math.min(We,de)||Le>Math.max(We,de)){Fe=true;break}if(We<=ke)Re=Math.max(Re,Le);else if(We>=Le)Ne=Math.min(Ne,ke);else{Fe=true;break}}if(Fe)continue}if(!(Re<Ne))continue;let J=2;x[0]=Re;x[1]=0;x[2]=Ne;x[3]=0;m(1);const ge=(le,we)=>{h(2);le=Math.max(Re,le);we=Math.min(Ne,we);if(le<we){x[2*J]=le;x[2*J+1]=1;J++;x[2*J]=we;x[2*J+1]=-1;J++}};if(U){h(12);const le=Q===X?U.peerIndex:X,we=Q===X?U.peerSegment:U.candidateSegment,ke=M[b[le].begin+we-1];ge((Te?ke.minY:ke.minX)-P-.01,(Te?ke.maxY:ke.maxX)+P+.01)}for(const le of ne.obstacles){h(5);if(Te?le.x+le.width+P<Ee||le.x-P>ve:le.y+le.height+P<Ee||le.y-P>ve)continue;ge((Te?le.y:le.x)-P,(Te?le.y+le.height:le.x+le.width)+P)}for(const le of _){h(5);if(Te?le.maxX+P<Ee||le.minX-P>ve:le.maxY+P<Ee||le.minY-P>ve)continue;ge((Te?le.minY:le.minX)-P-.01,(Te?le.maxY:le.maxX)+P+.01)}for(let le=0;le<M.length;le++){h(5);const we=M[le];if(!we.current||le===ee||we.join||we.a.y===we.b.y!==Te)continue;if(Te?we.maxX<Ee||we.minX>ve:we.maxY<Ee||we.minY>ve)continue;ge((Te?we.minY:we.minX)-P-.01,(Te?we.maxY:we.maxX)+P+.01)}for(let le=1;le<J;le++){const we=x[2*le],ke=x[2*le+1];let Le=le;while(Le>0){h();if(x[2*(Le-1)]<=we)break;x[2*Le]=x[2*(Le-1)];x[2*Le+1]=x[2*(Le-1)+1];Le--}x[2*Le]=we;x[2*Le+1]=ke}let Ce=-1,Me=-1;for(let le=0;le<8&&D<8;le++){let we=0,ke=-1,Le=Infinity,Fe=0;for(let Pe=1;Pe<J;Pe++){h(3);we+=x[2*(Pe-1)+1];const He=x[2*(Pe-1)],je=x[2*Pe],Ke=He+(je-He)/2,ze=Math.abs(Ke-de);if(we!==0||!(He<je)||Ke===de||ze<Ce||ze===Ce&&Pe<=Me)continue;if(ze<Le){ke=Pe;Le=ze;Fe=Ke}}if(ke<0)break;Ce=Le;Me=ke;D++;m(te.length+1);r(2);h(te.length);const Oe=te.slice(),We={x:oe.x,y:oe.y},ce={x:ue.x,y:ue.y};if(Te){We.y=ce.y=Fe}else{We.x=ce.x=Fe}Oe[ie]=We;Oe[ie+1]=ce;let Ae=true;for(let Pe=ie-1;Pe<=ie+1&&Ae;Pe++){E(F,Oe[Pe],Oe[Pe+1]);if(!B(Q,F)){Ae=false;break}for(const He of _){h(2);const je=Pe!==ie&&He.owner===Q&&(He.source?Pe<=1:Pe>=te.length-3);if(!je&&A(He,F)){Ae=false;break}}if(!Ae)break;if(Pe!==ie){h(6);const He=Pe===ie-1?ye:Se,je=Pe===ie-1?oe:ue,Ke=Pe===ie-1?We:ce;const ze=Math.abs(je.x-He.x)+Math.abs(je.y-He.y),Ze=Math.abs(Ke.x-He.x)+Math.abs(Ke.y-He.y);if(Ze>ze){E(F,je,Ke);for(const tt of _){h(4);if(tt.owner===Q&&(tt.source?Pe===0:Pe===te.length-2))continue;if(tt.owner===Q&&(tt.source?Pe<=1:Pe>=te.length-3)&&A(tt,F)){Ae=false;break}}}}}h(4);for(let Pe=Math.max(1,ie-1);Pe<=Math.min(Oe.length-2,ie+2)&&Ae;Pe++){h(4);const He=Oe[Pe-1],je=Oe[Pe],Ke=Oe[Pe+1];if(He.x===je.x===(je.x===Ke.x))continue;F.join=true;E(F,je,je);for(const ze of _){h();const Ze=ze.owner===Q&&Pe!==ie&&Pe!==ie+1&&Pe===(ze.source?1:te.length-2);if(!Ze&&A(ze,F)){Ae=false;break}}F.join=false}if(!Ae||!s(Q,Oe))continue;t[Q].points=Oe;k(Q);a(Q);Z=true;break}}}return Z};let O=0;for(let N=0;N<e.length;N++){h();const G=e[N];if(G.visible===false)continue;e:for(let Y=0;Y<2;Y++){h();const q=Y===0?G.markerPaint?.start:G.markerPaint?.end;if(!q?.length)continue;let V=t[N].points;const ne=Y===0;let X=ne?V[0]:V.at(-1),U=ne?V[1]:V.at(-2);let K=_[O++];D=0;if(!H(K,N,ne)){const Z=n[ne?G.source:G.target],Q=U.x===X.x;const se=Q?Z.x:Z.y,te=se+(Q?Z.width:Z.height),ee=Q?X.x:X.y;const ae=(Q?K.minX:K.minY)-ee,ie=(Q?K.maxX:K.maxY)-ee;for(let oe=0;oe<2;oe++){h();if(c!==void 0&&u){let Ee=false;do{h(3);Ee=false;Ee=W(N,ne,K,Q,oe,u);if(!Ee)break;h(4);V=t[N].points;X=ne?V[0]:V.at(-1);U=ne?V[1]:V.at(-2);if(H(K,N,ne)){m(1);p.push(K);h();j[2*N+Y]=D;continue e}}while(oe===1&&D<8)}let ue=2;x[0]=se;x[1]=0;x[2]=te;x[3]=0;for(const Ee of p){h(6);if(Q?K.maxY<=Ee.minY||K.minY>=Ee.maxY:K.maxX<=Ee.minX||K.minX>=Ee.maxX)continue;const ve=Math.max(se,(Q?Ee.minX:Ee.minY)-ie-.01),$e=Math.min(te,(Q?Ee.maxX:Ee.maxY)-ae+.01);if(ve<$e){x[2*ue]=ve;x[2*ue+1]=1;ue++;x[2*ue]=$e;x[2*ue+1]=-1;ue++}}if(c!==void 0)for(let Ee=0;Ee<b.length;Ee++){h();if(Ee===N)continue;const ve=b[Ee];if(Q?K.maxY<=ve.minY||K.minY>=ve.maxY:K.maxX<=ve.minX||K.minX>=ve.maxX)continue;for(let $e=ve.begin;$e<ve.end;$e++){h(6);const De=M[$e];if(Q?K.maxY<=De.minY||K.minY>=De.maxY:K.maxX<=De.minX||K.minX>=De.maxX)continue;const fe=Math.max(se,(Q?De.minX:De.minY)-ie-.01),me=Math.min(te,(Q?De.maxX:De.maxY)-ae+.01);if(fe<me){x[2*ue]=fe;x[2*ue+1]=1;ue++;x[2*ue]=me;x[2*ue+1]=-1;ue++}}}for(let Ee=1;Ee<ue;Ee++){const ve=x[2*Ee],$e=x[2*Ee+1];let De=Ee;while(De>0){h();if(x[2*(De-1)]<=ve)break;x[2*De]=x[2*(De-1)];x[2*De+1]=x[2*(De-1)+1];De--}x[2*De]=ve;x[2*De+1]=$e}let ye=false,Se=Infinity,Te=-1,Ie=-1;for(let Ee=0;Ee<8&&D<8;Ee++){let ve=-1,$e=0,De=2,fe=0;for(let Fe=1;Fe<ue;Fe++){h(2);fe+=x[2*(Fe-1)+1];const Oe=x[2*Fe]-x[2*(Fe-1)],We=fe===0?0:1;const ce=We>Ie||We===Ie&&(Oe<Se||Oe===Se&&Fe>Te);if(Oe>0&&ce&&(We<De||We===De&&Oe>$e)){$e=Oe;ve=Fe;De=We}}if(ve<0)break;const me=x[2*(ve-1)]+$e/2;Se=$e;Te=ve;Ie=De;D++;const de=V.length===2;h(3);let be=0;if(de){const Fe=Q?X.y:X.x,Oe=Q?U.y:U.x,We=Math.sign(Oe-Fe);let ce=We>0?(Q?K.maxY:K.maxX)-Fe:Fe-(Q?K.minY:K.minX),Ae=0;for(const ze of _){h(5);if(ze.owner===N&&ze.source!==ne)Ae=Math.max(Ae,We>0?Oe-(Q?ze.minY:ze.minX):(Q?ze.maxY:ze.maxX)-Oe)}h(10);const Pe=P+d,He=Math.min(8,Math.abs(Oe-Fe)),je=Fe+We*Math.max(He,ce+Pe);let Ke=Oe-We*Math.max(He,Ae+Pe);if(G.label){h(9);const ze=t[N].labelPosition;if(!ze||!Ji(ze,X,U))continue;const Ze=Q?ze.y:ze.x,tt=(Q?G.label.height:G.label.width)/2+2+P;Ke=We>0?Math.min(Ke,Ze-tt):Math.max(Ke,Ze+tt)}if(!(We*(Ke-je)>0))continue;be=je+(Ke-je)/2}m((de?4:V.length)+1);r(de?4:3);h(V.length+6);const pe={x:X.x,y:X.y},Re={x:U.x,y:U.y};if(Q){pe.x=me;Re.x=me;if(de)Re.y=be;if(Math.abs(pe.y-Z.y)<1e-7)pe.y=Z.y;else if(Math.abs(pe.y-Z.y-Z.height)<1e-7)pe.y=Z.y+Z.height}else{pe.y=me;Re.y=me;if(de)Re.x=be;if(Math.abs(pe.x-Z.x)<1e-7)pe.x=Z.x;else if(Math.abs(pe.x-Z.x-Z.width)<1e-7)pe.x=Z.x+Z.width}const Ne=de?ne?[pe,Re,Q?{x:U.x,y:be}:{x:be,y:U.y},U]:[U,Q?{x:U.x,y:be}:{x:be,y:U.y},Re,pe]:V.slice();Ne[ne?0:Ne.length-1]=pe;Ne[ne?1:Ne.length-2]=Re;const J=ne?Ne.length-1:0,ge=ne?Ne.length-2:1,Ce=Ne[J],Me={x:Ce.x,y:Ce.y},le=n[ne?G.target:G.source];if(Ne[ge].x===Me.x){if(Math.abs(Me.y-le.y)<1e-7)Me.y=le.y;else if(Math.abs(Me.y-le.y-le.height)<1e-7)Me.y=le.y+le.height}else if(Ne[ge].y===Me.y){if(Math.abs(Me.x-le.x)<1e-7)Me.x=le.x;else if(Math.abs(Me.x-le.x-le.width)<1e-7)Me.x=le.x+le.width}if(Me.x!==Ce.x||Me.y!==Ce.y){m(16);h(256);if(Xe(Me.x)!==Xe(Ce.x)||Xe(Me.y)!==Xe(Ce.y))continue}Ne[J]=Me;const we=z(q,pe,Re,N,ne);if(!H(we,N,ne))continue;let ke=true,Le=false;if(c!==void 0)for(let Fe=1;Fe<Ne.length;Fe++){h();if(!de&&!Le&&(ne?Fe>2&&Fe!==Ne.length-1:Fe<Ne.length-2&&Fe!==1))continue;E(F,Ne[Fe-1],Ne[Fe]);if(!B(N,F)){h(5);if(!Le&&!de&&Fe===2&&Ne.length===4&&!G.label&&d===0){const Oe=Ne[ge],We=Q?pe.y:pe.x,ce=Q?Re.y:Re.x,Ae=Q?Me.y:Me.x,Pe=Math.sign(ce-We);h(6);if((Q?Oe.y===ce&&Oe.x===Me.x:Oe.x===ce&&Oe.y===Me.y)&&Pe*(Ae-ce)>0){h(10);const He=Pe>0?(Q?we.maxY:we.maxX)-We:We-(Q?we.minY:we.minX),je=Math.min(8,Math.abs(ce-We)),Ke=Math.min(8,Math.abs(Ae-ce));let ze=0;for(const $t of _){h(5);if($t.owner===N&&$t.source!==ne)ze=Math.max(ze,Pe>0?Ae-(Q?$t.minY:$t.minX):(Q?$t.maxY:$t.maxX)-Ae)}h(8);const Ze=We+Pe*Math.max(je,He+P),tt=Ae-Pe*Math.max(Ke,ze+P),nt=ce-Pe*c,it=Pe>0?Math.min(tt,nt):Math.max(tt,nt);if(Pe*(it-Ze)>0){h(4);const $t=Ze+(it-Ze)/2;m(2);r(1);const yn={x:Oe.x,y:Oe.y};if(Q)Re.y=yn.y=$t;else Re.x=yn.x=$t;Ne[ge]=yn;Le=true;Fe=0;continue}}}ke=false;break}for(const Oe of de||Le?_:p){h(Le?4:3);const We=Le&&Oe.owner===N&&Oe.source===ne?we:Oe;const ce=We.owner===N&&(de||Le?We.source?Fe===1:Fe===Ne.length-1:We.source?Fe<=2:Fe>=Ne.length-2);if(!ce&&A(We,F)){ke=false;break}}if(!ke)break}if(ke&&c!==void 0)for(let Fe=1;Fe+1<Ne.length;Fe++){h();if(!de&&!Le&&(ne?Fe>2&&Fe!==Ne.length-2:Fe<Ne.length-3&&Fe!==1))continue;const Oe=Ne[Fe-1],We=Ne[Fe],ce=Ne[Fe+1];h(4);if(Oe.x===We.x===(We.x===ce.x))continue;F.join=true;E(F,We,We);F.join=false;F.join=true;for(const Ae of de||Le?_:p){h(Le?4:3);const Pe=Le&&Ae.owner===N&&Ae.source===ne?we:Ae;const He=!de&&!Le&&Pe.owner===N&&(Pe.source?Fe===1:Fe===Ne.length-2);if(!He&&A(Pe,F)){ke=false;break}}F.join=false;if(!ke)break}if(!ke||!s(N,Ne))continue;if(de&&c!==void 0)v(N,Ne);t[N].points=Ne;if(c!==void 0)k(N);K=we;_[O-1]=we;a(N);ye=true;break}if(!ye){if(oe===0)continue;o("No physically clear measured marker seat at occurrence "+N+" role "+Y)}break}}m(1);p.push(K);h();j[2*N+Y]=D}}if(f&&u&&c!==void 0&&d===0){m(1);const N={candidateSegment:-1,peerIndex:-1,peerSegment:-1};for(let G=0;G<t.length;G++){h();if(e[G].visible===false)continue;while(f(G,N)){let Y=false;for(let q=0;q<2&&!Y;q++){h(3);const V=q===0?G:N.peerIndex,ne=e[V].markerPaint,X=!!(ne?.start?.length||ne?.end?.length);for(let U=0;U<(X?2:1)&&!Y;U++){h(4);if(X&&!(U===0?ne?.start?.length:ne?.end?.length))continue;const K=X?2*V+U:2*e.length+V;D=j[K];if(D>=8)continue;Y=W(V,U===0,void 0,false,1,u,G,N,V);h();j[K]=D}}if(!Y)o("No physically clear measured sharp contact repair at occurrence "+G)}}}}var FA=new WeakMap;function NA(e,t){if(!e)return false;const n=FA.get(e);if(!n||n.boxes!==t)return false;return Object.getOwnPropertyDescriptor(e,"containsPoint")?.value===n.containsPoint&&Object.getOwnPropertyDescriptor(e,"entersSegment")?.value===n.entersSegment&&Object.getOwnPropertyDescriptor(e,"projectPoint")?.value===n.projectPoint}function $A(e,t,n,i){const r=(m=1)=>{t.pairs-=m;if(t.pairs<0)n("agentic local cross-hierarchy obstacle-work limit")};const o=(m,p)=>{if(p==="work")r(m);else{t.arcs-=m;if(t.arcs<0)n("agentic local cross-hierarchy visibility-arc limit")}};const s=i?i.x:zl(e,"x",0,o),a=i?i.y:zl(e,"y",0,o);const l=(m,p,g)=>{if(!m)return null;g?.();r();return up(m,p)};const c=(m,p)=>p<0||p+1>=m.offsets.length;const d=(m,p,g)=>p>m.x&&p<m.x+m.width&&g>m.y&&g<m.y+m.height;const u=(m,p,g,y,w)=>p===y?p>m.x&&p<m.x+m.width&&Math.max(g,w)>m.y&&Math.min(g,w)<m.y+m.height:g>m.y&&g<m.y+m.height&&Math.max(p,y)>m.x&&Math.min(p,y)<m.x+m.width;const f=(m,p,g,y,w)=>{r(2);if(p){if(y>m.y&&y<m.y+m.height){if(m.x>=g)w.right=Math.min(w.right,m.x);if(m.x+m.width<=g)w.left=Math.max(w.left,m.x+m.width)}}else if(g>m.x&&g<m.x+m.width){if(m.y>=y)w.bottom=Math.min(w.bottom,m.y);if(m.y+m.height<=y)w.top=Math.max(w.top,m.y+m.height)}};const h={projectPoint(m,p,g,y){r(4);y.left=g.x;y.right=g.x+g.width;y.top=g.y;y.bottom=g.y+g.height;for(let w=0;w<2;w++){const S=w===0,x=S?a:s;const M=l(x,S?p:m);if(x&&M!==null){if(c(x,M))continue;for(let b=x.offsets[M];b<x.offsets[M+1];b++){f(e[x.ordinals[b]],S,m,p,y)}}else for(const b of e)f(b,S,m,p,y)}},containsPoint(m,p,g){const y=l(s,m,g),w=l(a,p,g);if(s&&y!==null&&c(s,y)||a&&w!==null&&c(a,w))return false;const S=s&&y!==null?s.offsets[y+1]-s.offsets[y]:Infinity;const x=a&&w!==null?a.offsets[w+1]-a.offsets[w]:Infinity;const M=S<=x?s:a,b=S<=x?y:w;if(M&&b!==null){for(let C=M.offsets[b];C<M.offsets[b+1];C++){g?.();r();if(d(e[M.ordinals[C]],m,p))return true}}else for(const C of e){g?.();r();if(d(C,m,p))return true}return false},entersSegment(m,p,g,y,w){const S=m===g?s:a,x=l(S,m===g?m:p,w);if(S&&x!==null){if(c(S,x))return false;for(let M=S.offsets[x];M<S.offsets[x+1];M++){w?.();r();if(u(e[S.ordinals[M]],m,p,g,y))return true}}else for(const M of e){w?.();r();if(u(M,m,p,g,y))return true}return false}};o(4,"capacity");FA.set(h,{boxes:e,containsPoint:h.containsPoint,entersSegment:h.entersSegment,projectPoint:h.projectPoint});return h}function _A(e,t,n){return $A(e,t,n)}function DA(e,t){e.arcs-=8;if(e.arcs<0)t("agentic local cross-hierarchy visibility-arc limit");const n=s=>{e.pairs-=s;if(e.pairs<0)t("agentic local cross-hierarchy obstacle-work limit")};const i=s=>{e.arcs-=s;if(e.arcs<0)t("agentic local cross-hierarchy visibility-arc limit")};let r;const o=(s,a)=>a==="capacity"?i(s):n(s);return s=>{i(7);const a=f=>{n(3);const h=r?.[f];if(h&&r.boxes.length===s.length){let m=true;for(let p=0;p<s.length;p++){n(3);const g=r.boxes[p],y=s[p];const w=g[f]-0,S=g[f]+(f==="x"?g.width:g.height)+0;const x=y[f]-0,M=y[f]+(f==="x"?y.width:y.height)+0;if(!Object.is(Math.floor(w/128),Math.floor(x/128))||!Object.is(Math.floor(S/128),Math.floor(M/128))){m=false;break}}if(m)return h}return zl(s,f,0,o)};const l=a("x"),c=a("y");const d={x:l,y:c};const u=$A(s,e,t,d);n(1);r={boxes:s,x:l,y:c};return u}}function ty(e,t,n,i,r,o,s,a,l,c,d,u,f=.5,h=false){s.arcs-=24+r.length+2;if(s.arcs<0)l("agentic local cross-hierarchy visibility-arc limit");const m=(L=1)=>{s.pairs-=L;if(s.pairs<0)l("agentic local cross-hierarchy obstacle-work limit")};const p=L=>{s.arcs-=L;if(s.arcs<0)l("agentic local cross-hierarchy visibility-arc limit")};const g=new Float64Array(r.length+2);const y=(L,$)=>{if(--s.swaps<0)l("agentic local cross-hierarchy coordinate-sort limit");return L===$?0:L-$};m(18);const w=n.stub.x-n.port.x,S=n.stub.y-n.port.y;if(w===0===(S===0))return;const x=S===0,M=Math.sign(x?w:S);const b=x?n.port.y:n.port.x,C=x?n.port.x:n.port.y;const P=u===void 0?x?n.stub.x:n.stub.y:C+M*u;const E=x?e.y:e.x,k=E+(x?e.height:e.width);const v=x?e.x:e.y,T=v+(x?e.width:e.height),A=M<0?v:T;if(!Number.isFinite(f)||f<.5||u!==void 0&&(!Number.isFinite(u)||u<0))return;if(!Number.isFinite(E+k+v+T+b+C+P)||k<=E||T<=v||b<E||b>k||C<v||C>T||P<v||P>T)return;const R=(L,$,B,F,z)=>{m(g.length);g.fill(Infinity);let _=2;g[0]=L;g[1]=$;for(const[j,W]of r){m(10);const O=x?j.y:j.x,N=x?j.x:j.y,G=x?W.y:W.x,Y=x?W.x:W.y;const q=B?O:N;if((B?O!==G:N!==Y)||Math.max(B?N:O,B?Y:G)<F-f||Math.min(B?N:O,B?Y:G)>z+f||q<=L||q>=$)continue;g[_++]=q}g.sort(y);let H=-Infinity,D;for(let j=1;j<_;j++){m(5);const W=g[j-1],O=g[j],N=O-W,G=W+N/2;if(N>2*f&&N>H&&G>W&&G<O){H=N;D=G}}return D};let I=0;for(let L=0;L<2;L++){if(I>=8)return;let $=0;for(const B of i){m(6);const F=x?B.stub.y-B.port.y:B.stub.x-B.port.x;const z=x?B.stub.x-B.port.x:B.stub.y-B.port.y;m(4);const _=L===1;if(_?z!==0||F===0:F!==0||Math.sign(z)!==M)continue;if(++$>4)break;const H=x?B.port.y:B.port.x,D=x?B.port.x:B.port.y,j=x?B.stub.x:B.stub.y,W=x?B.stub.y:B.stub.x;m(8);if(H<E||H>k||D<v||D>T||M*(D-C)<=0)continue;for(let O=0;O<2;O++){const N=O===0?-1:1,G=N<0?E:k;m();if(_&&N!==Math.sign(F))continue;const Y=Math.min(G,b),q=Math.max(G,b);let V=P,ne=false;for(let ie=0;ie<=t.length;ie++){let oe=V;for(const ue of t){m(12);const ye=x?ue.y:ue.x,Se=x?ue.x:ue.y,Te=x?ue.height:ue.width,Ie=x?ue.width:ue.height;if(!Number.isFinite(ye+Se+Te+Ie)||Te<0||Ie<0)return;if(ye>=q||ye+Te<=Y)continue;if(M>0&&Se<=V&&Se+Ie>V)oe=Math.max(oe,Se+Ie);if(M<0&&Se<V&&Se+Ie>=V)oe=Math.min(oe,Se)}m(3);if(oe===V){ne=true;break}V=oe;if(V<v||V>T)break}if(!ne)continue;let X=A;for(const ie of t){m(10);const oe=x?ie.y:ie.x,ue=x?ie.x:ie.y,ye=x?ie.height:ie.width,Se=x?ie.width:ie.height;if(oe>=q||oe+ye<=Y)continue;if(M>0&&ue>=V)X=Math.min(X,ue);if(M<0&&ue+Se<=V)X=Math.max(X,ue+Se)}const U=R(Math.min(V,X),Math.max(V,X),false,Y,q);m(4);if(U===void 0||M*(U-P)<=0||M*(D-U)<=0)continue;let K=N<0?k:E;const Z=Math.min(U,_?D:A),Q=Math.max(U,_?D:A);for(const ie of t){m(10);const oe=x?ie.y:ie.x,ue=x?ie.x:ie.y,ye=x?ie.height:ie.width,Se=x?ie.width:ie.height;if(ue>=Q||ue+Se<=Z||oe>k||oe+ye<E)continue;K=N<0?Math.min(K,Math.max(E,oe)):Math.max(K,Math.min(k,oe+ye))}m(2);if(N*(G-K)<=0)continue;const se=R(Math.max(Math.min(G,K),Y),Math.min(Math.max(G,K),q),true,Z,Q);if(se===void 0||N*(se-b)<0)continue;let te;if(_){m(4);if(N*(se-W)<0)continue;m(2);if(I>=8)return;I++;a(5);p(6);te=x?[{x:C,y:b},{x:U,y:b},{x:U,y:se},{x:D,y:se},{x:D,y:H}]:[{x:b,y:C},{x:b,y:U},{x:se,y:U},{x:se,y:D},{x:H,y:D}]}else{const ie=Math.min(se,H),oe=Math.max(se,H);let ue=j;for(const Se of t){m(10);const Te=x?Se.y:Se.x,Ie=x?Se.x:Se.y,Ee=x?Se.height:Se.width,ve=x?Se.width:Se.height;if(Te>=oe||Te+Ee<=ie||Ie>T||Ie+ve<v)continue;ue=M<0?Math.min(ue,Math.max(v,Ie)):Math.max(ue,Math.min(T,Ie+ve))}m(2);if(M*(A-ue)<=0)continue;const ye=R(Math.min(A,ue),Math.max(A,ue),false,ie,oe);if(ye===void 0)continue;m(2);if(I>=8)return;I++;a(6);p(7);te=x?[{x:C,y:b},{x:U,y:b},{x:U,y:se},{x:ye,y:se},{x:ye,y:H},{x:D,y:H}]:[{x:b,y:C},{x:b,y:U},{x:se,y:U},{x:se,y:ye},{x:H,y:ye},{x:H,y:D}]}m();if(h){m(2*te.length);te.reverse()}let ee=true,ae=0;for(let ie=0;ie<te.length;ie++){const oe=te[ie];if(o.containsPoint(oe.x,oe.y)){ee=false;break}if(ie===0)continue;const ue=te[ie-1],ye=ue.x===oe.x?2:1;m(4);if(ue.x===oe.x&&ue.y===oe.y||ue.x!==oe.x&&ue.y!==oe.y||o.entersSegment(ue.x,ue.y,oe.x,oe.y)||!c(ue,oe,ae||ye,ye)||(ie===1||ie===te.length-1)&&!ny(ue,oe,r,f,s,l)){ee=false;break}ae=ye}if(ee){const ie=d(te);if(ie)return ie}}}}}function OA(e,t,n,i,r,o,s,a,l,c,d,u,f,h,m,p){c.arcs-=24+e.length+1;if(c.arcs<0)h("agentic local cross-hierarchy visibility-arc limit");const g=(F=1)=>{c.pairs-=F;if(c.pairs<0)h("agentic local cross-hierarchy obstacle-work limit")};const y=F=>{c.arcs-=F;if(c.arcs<0)h("agentic local cross-hierarchy visibility-arc limit")};g(12);if(e.length<2||!Ji(n,e.at(-2),e.at(-1)))return;const w=e.at(-2),S=e.at(-1),x=S.x-w.x,M=S.y-w.y;if(x===0===(M===0))return;const b=x>0?i.x+i.width:x<0?i.x:S.x;const C=M>0?i.y+i.height:M<0?i.y:S.y;g(8);if(b<Math.min(w.x,S.x)||b>Math.max(w.x,S.x)||C<Math.min(w.y,S.y)||C>Math.max(w.y,S.y))return;const P=e[0],E=e[1],k=E.x-P.x,v=E.y-P.y;if(k===0===(v===0))return;const T=k>0?t.x+t.width:k<0?t.x:P.x;const A=v>0?t.y+t.height:v<0?t.y:P.y;g(4);if(Math.abs(T-P.x)>1e-7||Math.abs(A-P.y)>1e-7)return;f(3);y(3);const R=e.slice(),I={x:T,y:A},L={x:b,y:C},$={x:b+Math.sign(x)*d,y:C+Math.sign(M)*d};R[0]=I;R[R.length-1]=L;const B={port:L,stub:$,penalty:0};for(let F=1;F<R.length;F++){const z=R[F-1],_=R[F];g(4);if(!Number.isFinite(z.x+z.y+_.x+_.y)||z.x!==_.x&&z.y!==_.y)return;if(!ny(z,_,a,u,c,h))return;for(const H of o){g(4);if(H===i&&F===R.length-1)continue;const D=z.x===_.x?z.x>H.x&&z.x<H.x+H.width&&Math.max(z.y,_.y)>H.y&&Math.min(z.y,_.y)<H.y+H.height:z.y>H.y&&z.y<H.y+H.height&&Math.max(z.x,_.x)>H.x&&Math.min(z.x,_.x)<H.x+H.width;if(D)return}}return ty(r,o,B,s,a,l,c,f,h,m,F=>{y(R.length+F.length);const z=new Array(R.length+F.length-1);for(let H=0;H<R.length;H++){g();z[H]=R[H]}for(let H=1;H<F.length;H++){g();z[R.length+H-1]=F[H]}let _=0;for(let H=1;H<z.length;H++){const D=z[H-1],j=z[H],W=D.x===j.x?2:1;g(4);if(!m(D,j,_||W,W))return;_=W}return p(z)},0,u)}function ny(e,t,n,i,r,o){const s=e.x===t.x;for(const[a,l]of n){r.pairs-=3;if(r.pairs<0)o("agentic local cross-hierarchy crossing-work limit");if(s!==(a.x===l.x))continue;r.pairs-=4;if(r.pairs<0)o("agentic local cross-hierarchy crossing-work limit");const c=Math.abs(s?e.x-a.x:e.y-a.y);if(c>i)continue;r.pairs-=12;if(r.pairs<0)o("agentic local cross-hierarchy crossing-work limit");const d=Math.min(s?Math.max(e.y,t.y):Math.max(e.x,t.x),s?Math.max(a.y,l.y):Math.max(a.x,l.x))-Math.max(s?Math.min(e.y,t.y):Math.min(e.x,t.x),s?Math.min(a.y,l.y):Math.min(a.x,l.x));if(d>=-i)return false}return true}function z0(e,t,n){let i=0;for(let r=0;r<e.length;r++){if(--t.pairs<0)n("agentic local cross-hierarchy self-check limit");const o=e[r];e[i++]=o;while(i>=3){t.pairs-=12;if(t.pairs<0)n("agentic local cross-hierarchy self-check limit");const s=e[i-3],a=e[i-2],l=e[i-1];if(!(s.x===a.x&&a.x===l.x&&a.y>=Math.min(s.y,l.y)&&a.y<=Math.max(s.y,l.y)||s.y===a.y&&a.y===l.y&&a.x>=Math.min(s.x,l.x)&&a.x<=Math.max(s.x,l.x)))break;e[i-2]=l;i--}}if(--t.pairs<0)n("agentic local cross-hierarchy self-check limit");e.length=i;return e}function BA(e,t,n,i,r,o,s,a,l,c,d,u=.5){s.arcs-=40+r.length+3;if(s.arcs<0)l("agentic local cross-hierarchy visibility-arc limit");const f=(S=1)=>{s.pairs-=S;if(s.pairs<0)l("agentic local cross-hierarchy obstacle-work limit")};const h=S=>{s.arcs-=S;if(s.arcs<0)l("agentic local cross-hierarchy visibility-arc limit")};const m=new Float64Array(r.length+2);const p=(S,x)=>{if(--s.swaps<0)l("agentic local cross-hierarchy coordinate-sort limit");return S===x?0:S-x};const g=(S,x,M,b,C,P)=>{f(m.length);m.fill(Infinity);let E=2;m[0]=S;m[1]=x;for(const[T,A]of r){f(10);const R=P?T.y:T.x,I=P?T.x:T.y,L=P?A.y:A.x,$=P?A.x:A.y,B=M?R:I;if((M?R!==L:I!==$)||Math.max(M?I:R,M?$:L)<b-u||Math.min(M?I:R,M?$:L)>C+u||B<=S||B>=x)continue;m[E++]=B}m.sort(p);let k=-Infinity,v;for(let T=1;T<E;T++){f(5);const A=m[T-1],R=m[T],I=R-A,L=A+I/2;if(I>2*u&&I>k&&L>A&&L<R){k=I;v=L}}return v};f(2);if(!Number.isFinite(u)||u<.5)return;f(8);const y=e.x+e.width,w=e.y+e.height;if(!Number.isFinite(e.x)||!Number.isFinite(e.y)||!Number.isFinite(y)||!Number.isFinite(w)||y<=e.x||w<=e.y)return;for(let S=0;S<8;S++){const x=S>=4,M=S%4;const b=M%2===0?-1:1,C=M<2?1:-1;const P=x?e.y:e.x,E=x?w:y;const k=x?e.x:e.y,v=x?y:w;const T=b<0?P:E,A=C<0?k:v;let R,I;for(const X of n){f(6);const U=x?X.stub.y-X.port.y:X.stub.x-X.port.x;const K=x?X.stub.x-X.port.x:X.stub.y-X.port.y;if(K===0&&Math.sign(U)===b){R=X;break}}for(const X of i){f(6);const U=x?X.stub.y-X.port.y:X.stub.x-X.port.x;const K=x?X.stub.x-X.port.x:X.stub.y-X.port.y;if(U===0&&Math.sign(K)===C){I=X;break}}if(!R||!I)continue;const L=x?R.port.y:R.port.x,$=x?R.port.x:R.port.y;const B=x?R.stub.y:R.stub.x;const F=x?I.port.y:I.port.x,z=x?I.port.x:I.port.y;const _=x?I.stub.x:I.stub.y;f(9);if(C*(z-$)<=0){h(2);const X=ty(e,t,R,[I],r,o,s,a,l,c,d,void 0,u);if(X)return X;continue}if(L<P||L>E||$<k||$>v||F<P||F>E||z<k||z>v)continue;let H=b<0?E:P;const D=Math.min($,A),j=Math.max($,A);for(const X of t){f(12);const U=x?X.y:X.x,K=x?X.x:X.y;const Z=x?X.height:X.width,Q=x?X.width:X.height;if(!Number.isFinite(U)||!Number.isFinite(K)||!Number.isFinite(U+Z)||!Number.isFinite(K+Q)||Z<0||Q<0)return;if(K>=j||K+Q<=D||U>E||U+Z<P)continue;H=b<0?Math.min(H,Math.max(P,U)):Math.max(H,Math.min(E,U+Z))}f(2);if(b*(T-H)<=0)continue;const W=g(Math.min(T,H),Math.max(T,H),true,D,j,x);f(3);if(W===void 0||b*(W-B)<0)continue;let O=_;const N=Math.min(W,F),G=Math.max(W,F);for(const X of t){f(10);const U=x?X.y:X.x,K=x?X.x:X.y;const Z=x?X.height:X.width,Q=x?X.width:X.height;if(U>=G||U+Z<=N||K>v||K+Q<k)continue;O=C<0?Math.min(O,Math.max(k,K)):Math.max(O,Math.min(v,K+Q))}f(2);if(C*(A-O)<=0)continue;const Y=g(Math.min(A,O),Math.max(A,O),false,N,G,x);f(3);if(Y===void 0||C*(Y-_)<0)continue;a(5);h(6);const q=x?[{x:$,y:L},{x:$,y:W},{x:Y,y:W},{x:Y,y:F},{x:z,y:F}]:[{x:L,y:$},{x:W,y:$},{x:W,y:Y},{x:F,y:Y},{x:F,y:z}];let V=true,ne=0;for(let X=0;X<q.length;X++){const U=q[X];if(o.containsPoint(U.x,U.y)){V=false;break}if(X===0)continue;const K=q[X-1],Z=K.x===U.x?2:1;f(4);if(K.x===U.x&&K.y===U.y||K.x!==U.x&&K.y!==U.y||o.entersSegment(K.x,K.y,U.x,U.y)||!c(K,U,ne||Z,Z)||(X===1||X===q.length-1)&&!ny(K,U,r,u,s,l)){V=false;break}ne=Z}if(V){const X=d(q);if(X)return X}}h(12);for(let S=0;S<4;S++){f(12);const x=S<2,M=S%2===0?-1:1;let b,C;for(const T of n){f(6);const A=T.stub.x-T.port.x,R=T.stub.y-T.port.y;if(x?A===0&&Math.sign(R)===M:R===0&&Math.sign(A)===M){b=T;break}}for(const T of i){f(6);const A=T.stub.x-T.port.x,R=T.stub.y-T.port.y;if(x?A===0&&Math.sign(R)===M:R===0&&Math.sign(A)===M){C=T;break}}if(!b||!C)continue;const P=x?b.port.y:b.port.x,E=x?C.port.y:C.port.x;f(4);if(P===E)continue;const k=M*(E-P)<0;h(2);const v=ty(e,t,k?C:b,[k?b:C],r,o,s,a,l,c,d,void 0,u,k);if(v)return v}}var G0=class{constructor(t,n,i,r,o,s,a){this.canvasWidth=i;this.canvasHeight=r;this.work=o;this.reservePoints=s;this.fail=a;this.capacity(t.length+2);this.catalog=new Array(t.length);this.rails=[];this.capacity(1);this.onIndexCharge=(l,c)=>c==="capacity"?this.capacity(l):this.charge(l);this.capacity(2);this.x={cross:"x",enabled:false,seed:null,first:Infinity,last:-Infinity,memberships:0,safe:true,domainFirst:NaN,domainLast:NaN,heads:void 0};this.y={cross:"y",enabled:false,seed:null,first:Infinity,last:-Infinity,memberships:0,safe:true,domainFirst:NaN,domainLast:NaN,heads:void 0};for(let l=0;l<t.length;l++){this.charge();if(l!==n&&t[l].style!=="invisible")this.addGeometry(l,t[l].points)}this.seedAxis(this.x);this.seedAxis(this.y);this.updating=false}canvasWidth;canvasHeight;work;reservePoints;fail;catalog;rails;x;y;revision=0;active;geometrySafe=true;arcAllocated=1;pointAllocated=0;insertionVisits=0;flatMoves=0;flatSearches=0;seedBuilds=0;failed=false;updating=true;lastStart=0;lastCount=0;onIndexCharge;charge(t=1){this.work.pairs-=t;if(this.work.pairs<0){this.failed=true;this.fail("agentic local cross-hierarchy crossing-work limit")}}capacity(t){this.work.arcs-=t;if(this.work.arcs<0){this.failed=true;this.fail("agentic local cross-hierarchy visibility-arc limit")}this.arcAllocated+=t}point(){try{this.reservePoints(1);this.pointAllocated++}catch(t){this.failed=true;throw t}}axisEligible(t){this.charge(8);const n=this.rails.length,i=t.last-t.first+1;return this.geometrySafe&&n>=32&&n<=268435456&&t.safe&&Number.isSafeInteger(t.memberships)&&t.memberships<=8*n&&Number.isSafeInteger(i)&&i<=8*n}addTotals(t,n){this.charge(8);const i=t.cross==="x"?n.xLow:n.yLow;const r=t.cross==="x"?n.xHigh:n.yHigh;if(!Number.isSafeInteger(i)||!Number.isSafeInteger(r)||r<i){t.safe=false;return}t.memberships+=r-i+1;t.first=Math.min(t.first,i);t.last=Math.max(t.last,r);if(!Number.isSafeInteger(t.memberships))t.safe=false}addGeometry(t,n){this.charge(3);if(!Number.isInteger(t)||t<0||t>=this.catalog.length||this.catalog[t]!==void 0)throw new TypeError("Duplicate or invalid peer geometry publication");this.capacity(n.length+2);const i=new Array(n.length);let r=0;for(let l=0;l<n.length;l++){this.charge(4);const c=n[l],d=i[r-1];if(d?.x===c.x&&d.y===c.y)continue;this.point();i[r++]={x:c.x,y:c.y};while(r>2){this.charge(8);const u=i[r-3],f=i[r-2],h=i[r-1];if(!(u.x===f.x&&f.x===h.x&&f.y>=Math.min(u.y,h.y)&&f.y<=Math.max(u.y,h.y)||u.y===f.y&&f.y===h.y&&f.x>=Math.min(u.x,h.x)&&f.x<=Math.max(u.x,h.x)))break;i[r-2]=h;r--}}i.length=r;const o=Math.max(0,r-1);let s=0;while(s<this.rails.length){this.charge();this.flatSearches++;if(this.rails[s].route>t)break;s++}this.capacity(o);const a=this.rails.length;this.rails.length=a+o;for(let l=a-1;l>=s;l--){this.charge();this.flatMoves++;this.rails[l+o]=this.rails[l]}for(let l=0;l<o;l++){this.charge(12);const c=i[l],d=i[l+1];this.geometrySafe&&=Number.isFinite(c.x)&&Number.isFinite(c.y)&&Number.isFinite(d.x)&&Number.isFinite(d.y)&&(c.x===d.x||c.y===d.y)&&Number.isFinite(Math.abs(c.x-d.x))&&Number.isFinite(Math.abs(c.y-d.y));this.capacity(3);const u=[c,d];u.route=t;u.ordinal=l;u.x=Math.min(c.x,d.x)-.5;u.y=Math.min(c.y,d.y)-.5;u.width=Math.abs(c.x-d.x)+1;u.height=Math.abs(c.y-d.y)+1;u.xLow=Math.floor(u.x/128);u.xHigh=Math.floor((u.x+u.width)/128);u.yLow=Math.floor(u.y/128);u.yHigh=Math.floor((u.y+u.height)/128);this.rails[s+l]=u;this.addTotals(this.x,u);this.addTotals(this.y,u)}this.catalog[t]={points:i,segments:o};this.lastStart=s;this.lastCount=o}seedAxis(t){this.charge(12);const n=t.cross==="x"?this.canvasWidth:this.canvasHeight;const i=Math.min(t.first,Math.floor(-.5/128));const r=Math.max(t.last,Math.floor((n+.5)/128)),o=r-i+1;t.domainFirst=i;t.domainLast=r;if(!this.axisEligible(t)||!Number.isFinite(n)||n<0||!Number.isSafeInteger(i)||!Number.isSafeInteger(r)||!Number.isSafeInteger(o)||o>8*this.rails.length)return;this.seedBuilds++;t.seed=zl(this.rails,t.cross,0,this.onIndexCharge);if(!t.seed)return;this.capacity(o+1);this.charge(o);t.heads=new Array(o).fill(void 0);t.enabled=true;for(let s=0;s+1<t.seed.offsets.length;s++){this.charge();const a=t.seed.firstCell+s-t.domainFirst;for(let l=t.seed.offsets[s+1]-1;l>=t.seed.offsets[s];l--){this.charge();this.capacity(1);t.heads[a]={peer:this.rails[t.seed.ordinals[l]],next:t.heads[a]}}}}insert(t,n){const i=t.cross==="x"?n.xLow:n.yLow,r=t.cross==="x"?n.xHigh:n.yHigh;for(let o=i;o<=r;o++){this.charge(2);const s=o-t.domainFirst;let a,l=t.heads[s];while(l){this.charge(2);this.insertionVisits++;if(l.peer.route>n.route||l.peer.route===n.route&&l.peer.ordinal>=n.ordinal)break;a=l;l=l.next}this.capacity(1);const c={peer:n,next:l};if(a)a.next=c;else t.heads[s]=c}}assertLease(t){if(this.failed||this.updating||t.released||this.active!==t||t.revision!==this.revision)throw new TypeError("Stale peer geometry revision")}acquire(t){this.charge(4);if(this.failed||this.updating||this.active||!Number.isInteger(t)||t<0||t>=this.catalog.length||this.catalog[t]!==void 0)throw new TypeError("Peer geometry lease is already active or owns its current route");this.capacity(3);const n={index:t,revision:this.revision,released:false,queries:0,guardCalls:0,guard:void 0,release:void 0};n.guard=(i,r,o,s)=>this.canTraverse(n,i,r,o,s);n.release=()=>this.release(n);this.charge();this.active=n;return n}enterQuery(t){this.charge();this.assertLease(t);this.charge();t.queries++}leaveQuery(t){if(t.released||this.active!==t||t.revision!==this.revision||t.queries<=0){this.charge();throw new TypeError("Peer query lease was not entered or is stale")}t.queries--}release(t){if(t.released||this.active!==t||t.revision!==this.revision||t.queries||t.guardCalls){this.charge();throw new TypeError("Cannot release stale peer geometry or an active query")}t.released=true;this.active=void 0}publish(t,n,i){this.charge(4);if(this.failed||this.updating||this.active)throw new TypeError("Cannot publish peer geometry while a revision is leased or failed");if(!Number.isInteger(t)||t<0||t>=this.catalog.length||this.catalog[t]!==void 0)throw new TypeError("Duplicate or invalid peer geometry publication");this.updating=true;if(!i){this.catalog[t]=null;this.revision++;this.updating=false;return}this.addGeometry(t,n);const r=this.lastStart,o=this.lastCount;for(let s=0;s<2;s++){const a=s===0?this.x:this.y;let l=true;for(let c=r;c<r+o;c++){this.charge(4);const d=this.rails[c],u=s===0?d.xLow:d.yLow,f=s===0?d.xHigh:d.yHigh;if(!Number.isSafeInteger(u)||!Number.isSafeInteger(f)||u<a.domainFirst||f>a.domainLast)l=false}if(!this.axisEligible(a)||!l)a.enabled=false;if(a.enabled)for(let c=r;c<r+o;c++)this.insert(a,this.rails[c])}this.revision++;this.updating=false}blocked(t,n,i,r,o){const s=i[0],a=i[1];this.charge();if(r!==o&&Ji(t,s,a))return true;const l=t.x===n.x,c=s.x===a.x;if(l===c){const d=Math.abs(l?t.x-s.x:t.y-s.y);const u=Math.min(l?Math.max(t.y,n.y):Math.max(t.x,n.x),l?Math.max(s.y,a.y):Math.max(s.x,a.x))-Math.max(l?Math.min(t.y,n.y):Math.min(t.x,n.x),l?Math.min(s.y,a.y):Math.min(s.x,a.x));if(d<=.5&&u>.01||d===0&&u>=0)return true}else{const d=l?t.x:s.x,u=l?s.y:t.y;if((t.x===n.x?Math.abs(d-t.x)<1e-7:Math.abs(u-t.y)<1e-7)&&d>=Math.min(t.x,n.x)&&d<=Math.max(t.x,n.x)&&u>=Math.min(t.y,n.y)&&u<=Math.max(t.y,n.y)&&(s.x===a.x?Math.abs(d-s.x)<1e-7:Math.abs(u-s.y)<1e-7)&&d>=Math.min(s.x,a.x)&&d<=Math.max(s.x,a.x)&&u>=Math.min(s.y,a.y)&&u<=Math.max(s.y,a.y)&&(d===s.x&&u===s.y||d===a.x&&u===a.y))return true}return false}canTraverse(t,n,i,r,o){this.charge(2);this.assertLease(t);t.guardCalls++;try{const s=n.x===i.x?this.x:this.y;const a=n.x===i.x?n.x:n.y,l=Math.floor(a/128);if(!Number.isFinite(n.x)||!Number.isFinite(n.y)||!Number.isFinite(i.x)||!Number.isFinite(i.y)||n.x!==i.x&&n.y!==i.y||!s.enabled||!Number.isSafeInteger(l)){for(let d=0;d<this.rails.length;d++)if(this.blocked(n,i,this.rails[d],r,o))return false;return true}if(l<s.domainFirst||l>s.domainLast)return true;let c=s.heads[l-s.domainFirst];while(c){if(this.blocked(n,i,c.peer,r,o))return false;c=c.next}return true}finally{t.guardCalls--}}};function WA(e,t,n,i,r,o,s){r.arcs--;if(r.arcs<0)s("agentic local cross-hierarchy visibility-arc limit");const a=new G0(e,t,n,i,r,o,s);return a}function ii(e){const t=[];for(const n of e){if(t.at(-1)?.x===n.x&&t.at(-1)?.y===n.y)continue;t.push({...n});while(t.length>2){const i=t.at(-3),r=t.at(-2),o=t.at(-1);if(!(i.x===r.x&&r.x===o.x&&r.y>=Math.min(i.y,o.y)&&r.y<=Math.max(i.y,o.y)||i.y===r.y&&r.y===o.y&&r.x>=Math.min(i.x,o.x)&&r.x<=Math.max(i.x,o.x)))break;t.splice(t.length-2,1)}}return t}function zA(e,t){const n=[];let i=0;return{get arcs(){return i},acquire(r,o){const s=r*4;if(!Number.isSafeInteger(s)||s<4||s>2147483647)t("agentic local cross-hierarchy visibility-arc limit");let a;for(const l of n){o();if(!l.active&&l.capacity>=s&&(!a||l.capacity<a.capacity))a=l}if(!a){e(s);i+=s;a={active:false,capacity:s,nodes:new Int32Array(s),distances:new Float64Array(s)};n.push(a)}o(s);a.nodes.fill(-1,0,s);a.distances.fill(0,0,s);a.active=true;return a}}}function H0(e,t){const n=[];let i=0;const r=o=>{e(o);i+=o};return{get vertices(){return i},acquire(o,s){if(!Number.isSafeInteger(o)||o<1)throw new TypeError("Invalid sparse query capacity");let a;for(const l of n){s();if(!l.active&&l.capacity>=o&&(!a||l.capacity<a.capacity))a=l}if(!a){let l=Math.min(32,o);while(l<o)l*=2;if(!Number.isSafeInteger(l))t("agentic local cross-hierarchy visibility-expansion limit");r(l);a={active:false,capacity:l,distance:new Float64Array(l),parents:new Int32Array(l),roots:new Int32Array(l),slots:new Int32Array(l),heapPages:new Map,reserveHeap:r};n.push(a)}a.active=true;return a}}}function j0(e,t,n,i,r,o,s,a,l,c,d=false,u,f,h,m){s.pairs-=8;if(s.pairs<0)l("agentic local cross-hierarchy obstacle-work limit");const p=Math.max(e.x,Math.min(t.x-2*o,r.x-o));const g=Math.max(e.y,Math.min(t.y-2*o,r.y-o));const y=Math.min(e.x+e.width,Math.max(t.x+t.width+2*o,r.x+o));const w=Math.min(e.y+e.height,Math.max(t.y+t.height+2*o,r.y+o));if(y<=p||w<=g)l("cross-hierarchy route has no bounded clear corridor");return oh({x:p,y:g,width:y-p,height:w-g},n,i,[r],o,s,a,l,c,d,u,f,h,m)}function oh(e,t,n,i,r,o,s,a,l,c=false,d,u,f,h){const m=e.x+e.width,p=e.y+e.height;let g=0;const y=N=>{if(g+N>s)a("agentic local cross-hierarchy visibility-expansion limit");l?.(N);g+=N};const w=(N=1)=>{o.pairs-=N;if(o.pairs<0)a("agentic local cross-hierarchy obstacle-work limit")};const S=N=>N.x>=e.x&&N.x<=m&&N.y>=e.y&&N.y<=p;const x=t.filter(N=>{w();return N.x<=m&&N.x+N.width>=e.x&&N.y<=p&&N.y+N.height>=e.y});w();let M=x.length>0;for(const N of x){w(8);const G=N.x+N.width,Y=N.y+N.height;if(!Number.isFinite(N.x)||!Number.isFinite(N.y)||!Number.isFinite(G)||!Number.isFinite(Y)||G<=N.x||Y<=N.y){M=false;break}}const b=[],C=new Map;let P;const E=N=>`${N.x},${N.y}`;const k=N=>{if(d)return!(P??=d()).containsPoint(N.x,N.y);for(const G of x){w();if(N.x>G.x&&N.x<G.x+G.width&&N.y>G.y&&N.y<G.y+G.height)return false}return true};const v=N=>{w();if(!Number.isFinite(N.x+N.y))a("agentic local cross-hierarchy coordinate limit");if(!S(N)||C.has(E(N))||!k(N))return;y(1);C.set(E(N),b.length);b.push({...N})};const T=N=>{for(const G of[N.x,N.x+N.width])for(const Y of[N.y,N.y+N.height])v({x:G,y:Y})};T(e);for(const N of x)T(N);for(let N=0;N<x.length;N++)for(let G=N+1;G<x.length;G++){w();const Y=x[N],q=x[G];if(Y.x>q.x+q.width||q.x>Y.x+Y.width||Y.y>q.y+q.height||q.y>Y.y+Y.height)continue;for(const[V,ne]of[[Y,q],[q,Y]]){for(const X of[V.x,V.x+V.width])for(const U of[ne.y,ne.y+ne.height]){w();if(X>=ne.x&&X<=ne.x+ne.width&&U>=V.y&&U<=V.y+V.height)v({x:X,y:U})}}}for(const N of n){v(N.port);v(N.stub)}for(const N of i)v(N);const A=new Set;for(const N of n){w(2);A.add(E(N.port));A.add(E(N.stub))}for(const N of i){w();A.add(E(N))}if(c&&x.length){let N=m,G=e.x,Y=p,q=e.y;for(const K of x){w(8);N=Math.min(N,Math.max(e.x,K.x));G=Math.max(G,Math.min(m,K.x+K.width));Y=Math.min(Y,Math.max(e.y,K.y));q=Math.max(q,Math.min(p,K.y+K.height))}w(4);const V=(K,Z)=>K+(Z-K)/2;const ne=[...N>e.x?[V(e.x,N)]:[],...G<m?[V(G,m)]:[]];const X=[...Y>e.y?[V(e.y,Y)]:[],...q<p?[V(q,p)]:[]];const U=(K,Z,Q,se,te)=>{if(!f)return K;let ee;const ae=te>K?1:-1;for(const[oe,ue]of f){w();const ye=Q?oe.x:oe.y;if((Q?oe.x!==ue.x:oe.y!==ue.y)||Z<Math.min(Q?oe.y:oe.x,Q?ue.y:ue.x)||Z>Math.max(Q?oe.y:oe.x,Q?ue.y:ue.x)||Math.abs(ye-K)>.5||ye<=Math.min(se,te)||ye>=Math.max(se,te)||ae*(te-ye)<=0)continue;if(ee===void 0||ae*(ye-ee)>0)ee=ye}if(ee===void 0)return K;let ie=te;for(const[oe,ue]of f){w();const ye=Q?oe.x:oe.y;if((Q?oe.x!==ue.x:oe.y!==ue.y)||Z<Math.min(Q?oe.y:oe.x,Q?ue.y:ue.x)||Z>Math.max(Q?oe.y:oe.x,Q?ue.y:ue.x)||ae*(ye-ee)<=0||ae*(ie-ye)<=0)continue;ie=ye}return V(ee,ie)};for(const K of ne)for(const Z of X){const Q={x:U(K,Z,true,K<N?e.x:m,K<N?N:G),y:U(Z,K,false,Z<Y?e.y:p,Z<Y?Y:q)};v(Q);w();A.add(E(Q))}}const R=[],I=[],L=[],$=[];const B=(N,G,Y)=>{w();if(N.x===G.x&&N.y===G.y)return;if(--o.arcs<0)a("agentic local cross-hierarchy visibility-arc limit");const q=N.y===G.y;const V=q?{fixed:N.y,lower:Math.min(N.x,G.x),upper:Math.max(N.x,G.x)}:{fixed:N.x,lower:Math.min(N.y,G.y),upper:Math.max(N.y,G.y)};(q?R:I).push(V);if(Y)(q?L:$).push(V)};const F=b.length;let z;if(d){if(--o.arcs<0)a("agentic local cross-hierarchy visibility-arc limit");z={left:e.x,right:m,top:e.y,bottom:p}}for(let N=0;N<F;N++){const G=b[N];let Y=e.x,q=m,V=e.y,ne=p;if(z){const U=P??=d();U.projectPoint(G.x,G.y,e,z);Y=z.left;q=z.right;V=z.top;ne=z.bottom}else for(const U of x){w(4);if(G.y>U.y&&G.y<U.y+U.height){if(U.x>=G.x)q=Math.min(q,U.x);if(U.x+U.width<=G.x)Y=Math.max(Y,U.x+U.width)}if(G.x>U.x&&G.x<U.x+U.width){if(U.y>=G.y)ne=Math.min(ne,U.y);if(U.y+U.height<=G.y)V=Math.max(V,U.y+U.height)}}const X=A.has(E(G));for(const U of[{x:Y,y:G.y},{x:q,y:G.y},{x:G.x,y:V},{x:G.x,y:ne}]){v(U);B(G,U,X)}}const _=(N,G)=>{if(--o.swaps<0)a("agentic local cross-hierarchy coordinate-sort limit");return N-G};const H=N=>{const G=new Map;for(const Y of N){w();const q=G.get(Y.fixed)??[];q.push(Y);G.set(Y.fixed,q)}for(const[Y,q]of G){q.sort((ne,X)=>_(ne.lower,X.lower)||_(ne.upper,X.upper));const V=[];for(const ne of q){w();const X=V.at(-1);if(X&&ne.lower<=X.upper)X.upper=Math.max(X.upper,ne.upper);else{if(--o.arcs<0)a("agentic local cross-hierarchy visibility-arc limit");V.push({...ne})}}G.set(Y,V)}return{coordinates:[...G.keys()].sort(_),lines:G}};const D=(N,G,Y)=>{const q=H(G),V=H(N);for(const ne of V.lines.values())for(const X of ne){let U=0,K=q.coordinates.length;while(U<K){w();const Z=Math.floor((U+K)/2);if(q.coordinates[Z]<X.lower)U=Z+1;else K=Z}for(let Z=U;Z<q.coordinates.length;Z++){w();const Q=q.coordinates[Z];if(Q>X.upper)break;for(const se of q.lines.get(Q)){w();if(se.lower>X.fixed)break;if(se.upper>=X.fixed)v(Y?{x:Q,y:X.fixed}:{x:X.fixed,y:Q})}}}return q};const j=D(L,I,true);const W=D($,R,false);let O;try{O=h?.acquire(b.length,w);if(M&&d){w(10);M=NA(P,t)}const N=O?void 0:b.map(()=>[]);const G=(K,Z)=>{if(d)return!(P??=d()).entersSegment(K.x,K.y,Z.x,Z.y);for(const Q of x){w();if(ci(K,Z,Q))return false}return true};for(const K of[1,2]){const Z=new Map;b.forEach((Q,se)=>{w();const te=K===1?Q.y:Q.x,ee=Z.get(te)??[];ee.push(se);Z.set(te,ee)});for(const Q of Z.values()){if(M)w();const se=b[Q[0]];const te=M?(K===1?W:j).lines.get(K===1?se.y:se.x):void 0;let ee=0;Q.sort((ae,ie)=>{if(--o.swaps<0)a("agentic local cross-hierarchy coordinate-sort limit");return K===1?b[ae].x-b[ie].x:b[ae].y-b[ie].y});for(let ae=1;ae<Q.length;ae++){if(O)w();else{o.arcs-=2;if(o.arcs<0)a("agentic local cross-hierarchy visibility-arc limit")}const ie=Q[ae-1],oe=Q[ae];const ue=K===1?b[ie].x:b[ie].y,ye=K===1?b[oe].x:b[oe].y;let Se;while(M){w();if(!te||ee>=te.length)break;const Ee=te[ee];w();if(Ee.upper>=ue){Se=Ee;break}w();ee++}let Te=false;if(Se){w();if(Se.lower<=ue){w();Te=ye<=Se.upper}}if(!Te&&!G(b[ie],b[oe]))continue;const Ie=Math.abs(b[ie].x-b[oe].x)+Math.abs(b[ie].y-b[oe].y);if(O){const Ee=ie*4+(K===1?1:3),ve=oe*4+(K===1?0:2);O.nodes[Ee]=oe;O.distances[Ee]=Ie;O.nodes[ve]=ie;O.distances[ve]=Ie}else{N[ie].push({node:oe,axis:K,distance:Ie});N[oe].push({node:ie,axis:K,distance:Ie})}}}}const Y=K=>C.get(E(K))??-1;const q=b.length*3,V=32;const ne=u??H0(y,a);let X=false,U=0;return{get vertices(){return g},retire(){if(X)return;if(U)throw new TypeError("Cannot retire a sparse graph during an active query");X=true;if(O)O.active=false},route(K,Z,Q=()=>true,se=()=>true){if(X)throw new TypeError("Cannot query a retired sparse graph");U++;try{const te=Y(Z);if(te<0)a("cross-hierarchy route has no clear anchor");w(q);const ee=ne.acquire(q,w);try{const{distance:ae,parents:ie,roots:oe,slots:ue,heapPages:ye}=ee;ae.fill(Infinity,0,q);ie.fill(-1,0,q);oe.fill(-1,0,q);ue.fill(-1,0,q);let Se=0;const Te=me=>ye.get(Math.floor(me/V))[me%V];const Ie=(me,de)=>{const be=Math.floor(me/V);let pe=ye.get(be);if(!pe){const Re=Math.min(V,ee.capacity-be*V);ee.reserveHeap(Re);pe=new Int32Array(Re);ye.set(be,pe)}pe[me%V]=de};const Ee=me=>{const de=b[Math.floor(me/3)];return ae[me]+Math.abs(de.x-Z.x)+Math.abs(de.y-Z.y)};const ve=(me,de)=>{if(--o.swaps<0)a("agentic local cross-hierarchy heap-work limit");const be=Ee(me),pe=Ee(de);return be<pe||be===pe&&me<de};const $e=(me,de)=>{const be=Te(me);Ie(me,Te(de));Ie(de,be);ue[Te(me)]=me;ue[Te(de)]=de};const De=me=>{let de=ue[me];if(de===-2)return;if(de<0){de=Se;Ie(Se++,me);ue[me]=de}while(de>0){const be=Math.floor((de-1)/2);if(!ve(Te(de),Te(be)))break;$e(de,be);de=be}};const fe=()=>{const me=Te(0),de=Te(--Se);ue[me]=-2;if(Se){Ie(0,de);ue[de]=0;let be=0;for(;;){let pe=be*2+1;if(pe>=Se)break;if(pe+1<Se&&ve(Te(pe+1),Te(pe)))pe++;if(!ve(Te(pe),Te(be)))break;$e(be,pe);be=pe}}return me};for(let me=0;me<K.length;me++){w();const de=K[me],be=Y(de.stub);if(be<0||!S(de.port)||!k(de.port)||!G(de.port,de.stub))continue;const pe=de.port.x===de.stub.x?2:de.port.y===de.stub.y?1:0;if(!pe)throw new TypeError("Measured terminal lead must be orthogonal");if(!se(de.port,de.stub,pe,pe))continue;const Re=be*3+pe,Ne=Math.abs(de.stub.x-de.port.x)+Math.abs(de.stub.y-de.port.y)+de.penalty;if(Ne<ae[Re]){ae[Re]=Ne;oe[Re]=me;De(Re)}}while(Se){const me=fe(),de=Math.floor(me/3),be=me%3;if(de===te){const Re=[];let Ne=me;while(ie[Ne]>=0){w();Re.push(b[Math.floor(Ne/3)]);Ne=ie[Ne]}Re.push(b[Math.floor(Ne/3)],K[oe[Ne]].port);let J=0,ge;for(const Me of Re){w();if(!ge||ge.x!==Me.x||ge.y!==Me.y)J++;ge=Me}y(J);const Ce=ii(Re.reverse());if(Q(Ce))return Ce}const pe=N?.[de];for(let Re=0;Re<(O?4:pe.length);Re++){let Ne,J,ge;if(O){const le=de*4+Re;Ne=O.nodes[le];if(Ne<0){w();continue}J=Re<2?1:2;ge=O.distances[le]}else{const le=pe[Re];Ne=le.node;J=le.axis;ge=le.distance}if(--o.arcs<0)a("agentic local cross-hierarchy visibility-arc limit");if(ie[me]===-1){w();const le=K[oe[me]],we=b[de],ke=b[Ne];const Le=le.stub.x-le.port.x,Fe=le.stub.y-le.port.y;if(Le!==0&&J===1&&Math.sign(ke.x-we.x)===-Math.sign(Le)||Fe!==0&&J===2&&Math.sign(ke.y-we.y)===-Math.sign(Fe))continue}const Ce=Ne*3+J;const Me=ae[me]+ge+(be===J?0:r*2);if(ue[Ce]!==-2&&Me<ae[Ce]&&se(b[de],b[Ne],be,J)){ae[Ce]=Me;ie[Ce]=me;oe[Ce]=oe[me];De(Ce)}}}return a("cross-hierarchy route has no bounded clear corridor")}finally{ee.active=false}}finally{U--}}}}catch(N){if(O)O.active=false;throw N}}var fn=32;function GA(e,t,n,i,r,o,s,a,l){let c=0;const d=$=>{if(c+$>s)a("agentic local cross-hierarchy visibility-expansion limit");l?.($);c+=$};const u=e.x+e.width,f=e.y+e.height;const h=$=>$.x>=e.x&&$.x<=u&&$.y>=e.y&&$.y<=f;const m=t.filter($=>{if(--o.pairs<0)a("agentic local cross-hierarchy obstacle-work limit");return $.x<=u&&$.x+$.width>=e.x&&$.y<=f&&$.y+$.height>=e.y});const p=new Set([e.x,u]),g=new Set([e.y,f]);for(const $ of m){if(--o.pairs<0)a("agentic local cross-hierarchy obstacle-work limit");for(const B of[$.x,$.x+$.width])if(B>=e.x&&B<=u)p.add(B);for(const B of[$.y,$.y+$.height])if(B>=e.y&&B<=f)g.add(B)}const y=$=>{if(--o.pairs<0)a("agentic local cross-hierarchy obstacle-work limit");if(!Number.isFinite($.x+$.y))a("agentic local cross-hierarchy coordinate limit");if(h($)){p.add($.x);g.add($.y)}};for(const $ of n){y($.port);y($.stub)}for(const $ of i)y($);const w=($,B)=>{if(--o.swaps<0)a("agentic local cross-hierarchy coordinate-sort limit");return $-B};const S=[...p].sort(w),x=[...g].sort(w),M=S.length,b=M*x.length;if(!Number.isSafeInteger(b*3)||b*3>2147483647)a("agentic local cross-hierarchy coordinate limit");const C=($=false)=>{const B=new Map;return{get(F){return B.get(Math.floor(F/fn))?.[F%fn]??0},set(F,z){const _=Math.floor(F/fn);let H=B.get(_);if(!H){const D=Math.min(fn,b-_*fn);if($){o.arcs-=D;if(o.arcs<0)a("agentic local cross-hierarchy visibility-arc limit")}else d(D);H=new Int8Array(D);B.set(_,H)}H[F%fn]=z}}};const P=C(),E=C(true),k=C(true);let v;const T=()=>v??=_A(m,o,a);const A=$=>{const B=P.get($);if(B)return B===1;const F=S[$%M],z=x[Math.floor($/M)];if(T().containsPoint(F,z)){P.set($,-1);return false}P.set($,1);return true};const R=($,B,F,z)=>{return!T().entersSegment($,B,F,z)};const I=($,B)=>R(S[$%M],x[Math.floor($/M)],S[B%M],x[Math.floor(B/M)]);const L=$=>{const B=S.indexOf($.x),F=x.indexOf($.y);return B<0||F<0?-1:F*M+B};return{get vertices(){return c},virtualVertices:b*3,route($,B){const F=L(B);if(F<0||!A(F))a("cross-hierarchy route has no clear anchor");const z=new Map,_=new Map;const H=Q=>{const se=Math.floor(Q/fn);let te=z.get(se);if(!te){const ee=Math.min(fn,b*3-se*fn);d(ee);te={distance:new Float64Array(ee).fill(Infinity),parent:new Int32Array(ee).fill(-1),slots:new Int32Array(ee).fill(-1),roots:new Int32Array(ee).fill(-1)};z.set(se,te)}return te};const D=Q=>z.get(Math.floor(Q/fn));const j=Q=>D(Q)?.distance[Q%fn]??Infinity;const W=Q=>D(Q)?.parent[Q%fn]??-1;const O=Q=>D(Q)?.slots[Q%fn]??-1;const N=Q=>D(Q)?.roots[Q%fn]??-1;let G=0;const Y=Q=>_.get(Math.floor(Q/fn))[Q%fn];const q=(Q,se)=>{const te=Math.floor(Q/fn);let ee=_.get(te);if(!ee){const ae=Math.min(fn,b*3-te*fn);d(ae);ee=new Int32Array(ae);_.set(te,ee)}ee[Q%fn]=se};const V=Q=>{const se=Math.floor(Q/3);return j(Q)+Math.abs(S[se%M]-B.x)+Math.abs(x[Math.floor(se/M)]-B.y)};const ne=(Q,se)=>{if(--o.swaps<0)a("agentic local cross-hierarchy heap-work limit");return V(Q)<V(se)||V(Q)===V(se)&&Q<se};const X=(Q,se)=>{const te=Y(Q);q(Q,Y(se));q(se,te);H(Y(Q)).slots[Y(Q)%fn]=Q;H(Y(se)).slots[Y(se)%fn]=se};const U=Q=>{let se=O(Q);if(se===-2)return;if(se<0){se=G;q(G++,Q);H(Q).slots[Q%fn]=se}while(se>0){const te=Math.floor((se-1)/2);if(!ne(Y(se),Y(te)))break;X(se,te);se=te}};const K=()=>{const Q=Y(0),se=Y(--G);H(Q).slots[Q%fn]=-2;if(G){q(0,se);H(se).slots[se%fn]=0;let te=0;while(2*te+1<G){let ee=2*te+1;if(ee+1<G&&ne(Y(ee+1),Y(ee)))ee++;if(!ne(Y(ee),Y(te)))break;X(te,ee);te=ee}}return Q};for(let Q=0;Q<$.length;Q++){const se=$[Q],te=L(se.stub);if(te<0||!h(se.port)||!A(te))continue;if(!R(se.port.x,se.port.y,se.stub.x,se.stub.y))continue;const ee=se.port.x===se.stub.x?2:1,ae=te*3+ee;const ie=Math.abs(se.stub.x-se.port.x)+Math.abs(se.stub.y-se.port.y)+se.penalty;if(ie<j(ae)){const oe=H(ae),ue=ae%fn;oe.distance[ue]=ie;oe.roots[ue]=Q;U(ae)}}const Z=Q=>{d(1);return{x:S[Q%M],y:x[Math.floor(Q/M)]}};while(G){const Q=K(),se=Math.floor(Q/3),te=Q%3;if(se===F){const ie=[];let oe=Q;while(W(oe)>=0){ie.push(Z(Math.floor(oe/3)));oe=W(oe)}ie.push(Z(Math.floor(oe/3)));d(1);ie.push({...$[N(oe)].port});const ue=[];for(const ye of ie.reverse()){if(ue.at(-1)?.x===ye.x&&ue.at(-1)?.y===ye.y)continue;ue.push(ye);while(ue.length>2){const Se=ue.at(-3),Te=ue.at(-2),Ie=ue.at(-1);if(!(Se.x===Te.x&&Te.x===Ie.x&&Te.y>=Math.min(Se.y,Ie.y)&&Te.y<=Math.max(Se.y,Ie.y)||Se.y===Te.y&&Te.y===Ie.y&&Te.x>=Math.min(Se.x,Ie.x)&&Te.x<=Math.max(Se.x,Ie.x)))break;ue.splice(ue.length-2,1)}}return ue}const ee=se%M,ae=Math.floor(se/M);for(let ie=0;ie<4;ie++){const oe=ie===0?ee>0?se-1:-1:ie===1?ee+1<M?se+1:-1:ie===2?ae>0?se-M:-1:ae+1<x.length?se+M:-1;const ue=ie<2?1:2;if(--o.arcs<0)a("agentic local cross-hierarchy visibility-arc limit");if(oe<0||!A(oe))continue;const ye=Math.min(se,oe),Se=ue===1?E:k;if(!Se.get(ye))Se.set(ye,I(se,oe)?1:-1);if(Se.get(ye)!==1)continue;const Te=oe*3+ue;const Ie=j(Q)+Math.abs(S[se%M]-S[oe%M])+Math.abs(x[Math.floor(se/M)]-x[Math.floor(oe/M)])+(te===ue?0:r*2);if(O(Te)!==-2&&Ie<j(Te)){const Ee=H(Te),ve=Te%fn;Ee.distance[ve]=Ie;Ee.parent[ve]=Q;Ee.roots[ve]=N(Q);U(Te)}}}return a("cross-hierarchy route has no bounded clear corridor")}}}var iy=class extends Error{};function HA(e,t,n,i){const r=e.groups,o=e.nodes.length,s=Math.max(8,e.edgeSpacing??6,e.minimumTerminalLead??0);const a=new Map,l=new Map,c=new Map,d=new Map;const u=(f,h)=>{for(let m=t[h];m>=0;m=t[o+m]){if(--n.pairs<0)i("agentic local cross-hierarchy obstacle-work limit");if(m===f)return true}return false};for(const[f,h]of e.edges.entries()){if(--n.pairs<0)i("agentic local cross-hierarchy obstacle-work limit");const m=h.source>=o&&u(h.source-o,h.target);const p=h.target>=o&&u(h.target-o,h.source);if(!m&&!p)continue;let g=s;if(h.minSpan!==1){if(!Number.isSafeInteger(h.minSpan)||h.minSpan<1)throw new TypeError("Invalid measured compound edge dimensions");const C=Fp(h.minSpan);if(!Number.isSafeInteger(C)||C<0)i("agentic local coordinate-range limit");g=Math.max(s,C)}const y=(m?h.source:h.target)-o,w=r[y];const S=l.get(y)??0,x=Math.max(h.label?.height??0,h.boundaryMarker?.height??0);const M=x+2*s,b=Math.max(2*s,(h.boundaryMarker?.inset??0)+s);if(--n.arcs<0)i("agentic local cross-hierarchy visibility-arc limit");a.set(f,{edge:f,container:y,interior:m?h.target:h.source,containerEnd:m?"source":"target",rowOffset:w.padding.top+S+s+x/2,labelInset:b,minimumLead:g,...h.label?{label:{...h.label}}:{}});l.set(y,S+M);c.set(y,Math.max(c.get(y)??0,b+(h.label?.width??0)+2*s));d.set(y,Math.max(d.get(y)??0,g))}return{connections:a,clearance:s,groups:a.size?r.map((f,h)=>l.has(h)?{...f,headerHeight:f.headerHeight??f.padding.top,padding:{...f.padding,top:f.padding.top+l.get(h),left:Math.max(f.padding.left+c.get(h),d.get(h)+s)}}:f):r}}function jA(e,t,n,i){const r=e.connections.get(t),o=n[r.container],s=e.clearance;const a=o.y+r.rowOffset;i?.(r.label?3:2);const l=[{x:o.x,y:a},{x:o.x+e.groups[r.container].padding.left-s,y:a}];return{points:r.containerEnd==="source"?l:l.reverse(),...r.label?{labelPosition:{x:o.x+r.labelInset+r.label.width/2,y:a}}:{}}}function YA(e,t,n,i,r,o){const{work:s,fail:a}=o,l=i.connections.get(r),c=i.clearance;const d=e.nodes.length,u=t.groups,f=u[l.container];let h=0;const m=z=>{if(h+z>o.remainingVertices)a("agentic local cross-hierarchy visibility-expansion limit");o.reserveVertices(z);h+=z};const p=()=>{if(--s.pairs<0)a("agentic local cross-hierarchy obstacle-work limit")};const g=(z,_)=>{m(1);return{x:z,y:_}};const y=e.nodes.map((z,_)=>{p();return{...t.nodes[_],width:z.width,height:z.height}});const w=[...y,...u],S=w[l.interior];const x=new Set;for(let z=n[l.interior];z>=0;z=n[d+z]){p();x.add(z)}const M=(z,_)=>({x:z.x-_,y:z.y-_,width:z.width+2*_,height:z.height+2*_});const b=y.map((z,_)=>{p();return _===l.interior?z:M(z,c)});u.forEach((z,_)=>{p();if(!x.has(_))b.push(_+d===l.interior?z:M(z,c));else{const H=i.groups[_].headerHeight??i.groups[_].padding.top;if(H>0)b.push(M({...z,height:H},2))}});for(const[z,_]of e.edges.entries()){p();if(!_.label)continue;const H=i.connections.get(z),D=H&&u[H.container];const j=H&&D?D.x+H.labelInset+_.label.width/2:t.edges[z]?.labelPosition?.x;const W=H&&D?D.y+H.rowOffset:t.edges[z]?.labelPosition?.y;if(_.label&&j!==void 0&&W!==void 0)b.push(M({x:j-_.label.width/2,y:W-_.label.height/2,width:_.label.width,height:_.label.height},2))}const C=i.groups[l.container].headerHeight??i.groups[l.container].padding.top;const P={x:f.x,y:f.y+C+2,width:f.width,height:f.height-C-2};const E=f.y+l.rowOffset;const k=g(f.x,E),v=g(f.x+i.groups[l.container].padding.left-c,E);let T=0,A=0;for(const[z,_]of e.edges.entries()){p();if(_.source===l.interior||_.target===l.interior){T++;if(z<r)A++}}const R=[...new Set([(A+1)/(T+1),.5,.25,.75])];const I=[];const L=l.interior>=d?i.groups[l.interior-d]:void 0;const $=S.y+(L?(L.headerHeight??L.padding.top)+2:0);for(const z of["L","R","B","T"])for(const _ of R){p();if(z==="T"&&L&&(L.headerHeight??L.padding.top)>0)continue;const H=z==="L"?S.x:z==="R"?S.x+S.width:S.x+_*S.width;const D=z==="T"?S.y:z==="B"?S.y+S.height:$+_*(S.y+S.height-$);const j=g(H,D),W=g(H+(z==="L"?-c:z==="R"?c:0),D+(z==="T"?-c:z==="B"?c:0));if(--s.arcs<0)a("agentic local cross-hierarchy visibility-arc limit");I.push({port:j,stub:W,penalty:0})}const B=z=>{if(z==="cross-hierarchy route has no bounded clear corridor")throw new iy(z);return a(z)};const F=oh(P,b,I,[v],c,s,o.remainingVertices,B,m,false,void 0,o.queryWorkspaces);for(const z of I){let _;const H=(D,j)=>{p();const{port:W,stub:O}=z;if(D.x===W.x&&D.y===W.y&&j.x===O.x&&j.y===O.y)return true;const N=W.y===O.y,G=N?D.y===j.y:D.x===j.x;if(G){if(N?D.y!==W.y:D.x!==W.x)return true;const ne=Math.max(Math.min(N?D.x:D.y,N?j.x:j.y),Math.min(N?W.x:W.y,N?O.x:O.y));const X=Math.min(Math.max(N?D.x:D.y,N?j.x:j.y),Math.max(N?W.x:W.y,N?O.x:O.y));return ne>X||ne===X&&ne===(N?O.x:O.y)}const Y=N?D.x:W.x,q=N?W.y:D.y;const V=Y>=Math.min(D.x,j.x)&&Y<=Math.max(D.x,j.x)&&q>=Math.min(D.y,j.y)&&q<=Math.max(D.y,j.y)&&Y>=Math.min(W.x,O.x)&&Y<=Math.max(W.x,O.x)&&q>=Math.min(W.y,O.y)&&q<=Math.max(W.y,O.y);return!V||Y===O.x&&q===O.y};try{F.route([z],v,D=>{const j=l.containerEnd==="source"?[k,...D.toReversed()]:[...D,k];let W=0,O;for(const K of j){p();if(!O||O.x!==K.x||O.y!==K.y)W++;O=K}m(W);const N=ii(j);const G=l.containerEnd==="source"?N[0]:N.at(-1);const Y=l.containerEnd==="source"?N[1]:N.at(-2);if(G.x!==f.x||G.y!==E||Y.y!==E||Y.x-G.x<l.minimumLead)return false;const q=l.containerEnd==="source"?N.at(-1):N[0];const V=l.containerEnd==="source"?N.at(-2):N[1];const ne=q.x>=S.x&&q.x<=S.x+S.width&&q.y>=S.y&&q.y<=S.y+S.height&&(q.x===S.x&&V.y===q.y&&V.x<q.x||q.x===S.x+S.width&&V.y===q.y&&V.x>q.x||q.y===S.y&&V.x===q.x&&V.y<q.y||q.y===S.y+S.height&&V.x===q.x&&V.y>q.y);if(!ne||Math.abs(V.x-q.x)+Math.abs(V.y-q.y)<c)return false;const X=l.label?g(f.x+l.labelInset+l.label.width/2,E):void 0;if(X&&!N.some((K,Z)=>Z>0&&Ji(X,N[Z-1],K)))return false;for(const[K,Z]of u.entries())if(x.has(K)){const Q=i.groups[K].headerHeight??i.groups[K].padding.top;for(let se=1;se<N.length;se++){p();if(Q>0&&ci(N[se-1],N[se],{...Z,height:Q}))return false}}const U={points:N,...X?{labelPosition:X}:{}};if(!o.accept(U))return false;_=U;return true},H)}catch(D){if(!(D instanceof iy))throw D}if(_)return _}return a("cross-hierarchy route has no bounded clear corridor")}var sh=(e,t)=>({x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t});var fo=(e,t,n)=>(t.x===n.x?Math.abs(e.x-t.x)<1e-7:Math.abs(e.y-t.y)<1e-7)&&e.x>=Math.min(t.x,n.x)&&e.x<=Math.max(t.x,n.x)&&e.y>=Math.min(t.y,n.y)&&e.y<=Math.max(t.y,n.y);function lc(e,t,n,i,r=[.5,.25,.75]){const o=t==="LR"?"E":t==="RL"?"W":t==="BT"?"N":"S";const s={N:"S",E:"W",S:"N",W:"E"};const a=n?o:s[o];const l=[a,...["N","E","S","W"].filter(c=>c!==a)];return l.flatMap((c,d)=>r.map(u=>{const f=c==="N"||c==="S"?{x:e.x+u*e.width,y:c==="N"?e.y:e.y+e.height}:{x:c==="W"?e.x:e.x+e.width,y:e.y+u*e.height};const h={x:f.x+(c==="E"?i:c==="W"?-i:0),y:f.y+(c==="S"?i:c==="N"?-i:0)};return{port:f,stub:h,penalty:d*i*2+Math.abs(u-.5)*i}}))}function ah(e,t,n){for(let i=2;i<e.length;i++){if(--t.pairs<0)n("agentic local cross-hierarchy self-check limit");const r=e[i-2],o=e[i-1],s=e[i];if(r.x===o.x&&o.x===s.x&&Math.sign(o.y-r.y)!==Math.sign(s.y-o.y)||r.y===o.y&&o.y===s.y&&Math.sign(o.x-r.x)!==Math.sign(s.x-o.x))return true}for(let i=1;i<e.length;i++)for(let r=i+2;r<e.length;r++){if(--t.pairs<0)n("agentic local cross-hierarchy self-check limit");const o=e[i-1],s=e[i],a=e[r-1],l=e[r];if(o.x===s.x&&a.x===l.x){if(o.x===a.x&&Math.min(Math.max(o.y,s.y),Math.max(a.y,l.y))>=Math.max(Math.min(o.y,s.y),Math.min(a.y,l.y)))return true}else if(o.y===s.y&&a.y===l.y){if(o.y===a.y&&Math.min(Math.max(o.x,s.x),Math.max(a.x,l.x))>=Math.max(Math.min(o.x,s.x),Math.min(a.x,l.x)))return true}else{const c=o.x===s.x?o.x:a.x,d=o.x===s.x?a.y:o.y;if(fo({x:c,y:d},o,s)&&fo({x:c,y:d},a,l))return true}}return false}function q3(e,t,n){let i=ii(e);for(;;){let r;for(let o=2;o<i.length;o++){if(--t.pairs<0)n("agentic local cross-hierarchy self-check limit");const s=i[o-2],a=i[o-1],l=i[o];if(s.x===a.x&&a.x===l.x||s.y===a.y&&a.y===l.y){r=[...i.slice(0,o-1),...i.slice(o)];break}}for(let o=1;!r&&o<i.length;o++)for(let s=o+2;s<i.length;s++){if(--t.pairs<0)n("agentic local cross-hierarchy self-check limit");const a=i[o-1],l=i[o],c=i[s-1],d=i[s];let u;if(a.x===l.x&&c.x===d.x){const f=Math.max(Math.min(a.y,l.y),Math.min(c.y,d.y)),h=Math.min(Math.max(a.y,l.y),Math.max(c.y,d.y));if(a.x===c.x&&f<=h)u={x:a.x,y:Math.max(f,Math.min(h,a.y))}}else if(a.y===l.y&&c.y===d.y){const f=Math.max(Math.min(a.x,l.x),Math.min(c.x,d.x)),h=Math.min(Math.max(a.x,l.x),Math.max(c.x,d.x));if(a.y===c.y&&f<=h)u={x:Math.max(f,Math.min(h,a.x)),y:a.y}}else{const f={x:a.x===l.x?a.x:c.x,y:a.x===l.x?c.y:a.y};if(fo(f,a,l)&&fo(f,c,d))u=f}if(u){r=[...i.slice(0,o),u,...i.slice(s)];break}}if(!r)return i;i=ii(r)}}function cc(e,t,n,i,r,o,s,a,l,c=()=>true,d=false,u){const f=e.x+e.width,h=e.y+e.height;const m={};const p=()=>{if(a.pairs<=0)throw m;a.pairs--};const g=(y,w=true)=>{if(a.candidates<=0||a.pairs<=0)return;a.candidates--;const S=ii(y);for(const x of S)if(!Number.isFinite(x.x+x.y)||x.x<e.x||x.x>f||x.y<e.y||x.y>h)return;if(ah(S,s,l))return;for(let x=1;x<S.length;x++){if(--s.arcs<0)l("agentic local cross-hierarchy direct-arc limit");const M=S[x-1],b=S[x];if(u){try{if(u().entersSegment(M.x,M.y,b.x,b.y,p))return}catch(C){if(C===m)return;throw C}}else for(const C of t){if(a.pairs<=0)return;a.pairs--;if(--s.pairs<0)l("agentic local cross-hierarchy direct-pair limit");if(ci(M,b,C))return}}return!w||c(S)?S:void 0};if(d){const y=[];for(let S=0;S<3;S++)for(let x=0;x<4;x++){const M=n[x*3+S];if(g([M.port,M.stub],false))y.push(M)}const w=S=>{if(a.pairs<=0||a.candidates<=0)return;for(const{port:x,stub:M}of y){const b=g([x,M,...S(M),i]);if(b)return b;if(a.pairs<=0||a.candidates<=0)return}};for(const S of[x=>[{x:i.x,y:x.y}],x=>[{x:x.x,y:i.y}]]){const x=w(S);if(x)return x}for(const S of r){const x=[S.x-o*2,S.x+S.width+o*2,S.x-o,S.x+S.width+o];const M=[S.y-o,S.y+S.height+o];for(const b of x){const C=w(P=>[{x:b,y:P.y},{x:b,y:i.y}]);if(C)return C}for(const b of M){const C=w(P=>[{x:P.x,y:b},{x:i.x,y:b}]);if(C)return C}for(const b of x)for(const C of M){const P=w(E=>[{x:b,y:E.y},{x:b,y:C},{x:i.x,y:C}]);if(P)return P}if(a.pairs<=0||a.candidates<=0)return}return}for(let y=0;y<3;y++)for(let w=0;w<4;w++){const{port:S,stub:x}=n[w*3+y];if(!g([S,x],false)){if(a.pairs<=0||a.candidates<=0)return;continue}for(const M of[{x:i.x,y:x.y},{x:x.x,y:i.y}]){const b=g([S,x,M,i]);if(b)return b;if(a.pairs<=0||a.candidates<=0)return}for(const M of r){const b=[M.x-o,M.x+M.width+o];const C=[M.y-o,M.y+M.height+o];for(const P of b){const E=g([S,x,{x:P,y:x.y},{x:P,y:i.y},i]);if(E)return E;if(a.pairs<=0||a.candidates<=0)return}for(const P of C){const E=g([S,x,{x:x.x,y:P},{x:i.x,y:P},i]);if(E)return E;if(a.pairs<=0||a.candidates<=0)return}for(const P of b)for(const E of C){const k=g([S,x,{x:P,y:x.y},{x:P,y:E},{x:i.x,y:E},i]);if(k)return k;if(a.pairs<=0||a.candidates<=0)return}}}return void 0}var Od=class{constructor(t){this.reason=t}reason};function Mr(e,t,n=1){e.arcs-=n;if(e.arcs<0)t("agentic local cross-hierarchy visibility-arc limit")}function Y0(e,t,n){n();t.orthogonal=e.length>=2;t.minX=Infinity;t.maxX=-Infinity;t.minY=Infinity;t.maxY=-Infinity;for(let i=0;t.orthogonal&&i<e.length;i++){n(9);const r=e[i];if(!Number.isFinite(r.x)||!Number.isFinite(r.y)||i>0&&r.x!==e[i-1].x&&r.y!==e[i-1].y){t.orthogonal=false;return}t.minX=Math.min(t.minX,r.x);t.maxX=Math.max(t.maxX,r.x);t.minY=Math.min(t.minY,r.y);t.maxY=Math.max(t.maxY,r.y)}}function qA(e,t,n,i){if(!e?.orthogonal||!t?.orthogonal)return false;n(i===void 0?8:20);const r=e.minX-t.maxX,o=t.minX-e.maxX,s=e.minY-t.maxY,a=t.minY-e.maxY;const l=i===void 0?.5:Math.max(.5,i+(Math.abs(e.minX)+Math.abs(e.maxX)+Math.abs(e.minY)+Math.abs(e.maxY)+Math.abs(t.minX)+Math.abs(t.maxX)+Math.abs(t.minY)+Math.abs(t.maxY)+i)*1e-10+1e-9);return Number.isFinite(r)&&Number.isFinite(o)&&Number.isFinite(s)&&Number.isFinite(a)&&(r>l||o>l||s>l||a>l)}function X3(e,t,n,i,r){return U3(e,t,n,i,r,rh)}function U3(e,t,n,i,r,o){const s=ea(e,o===rh?"proposal":"complete");let a=0,l=0,c=0;for(let g=0;g<n.length;g++){if(--i.pairs<0)r("agentic local cross-hierarchy crossing-work limit");if(g!==t&&n[g].style!=="invisible"){a+=Math.max(0,n[g].points.length-1);l+=n[g].points.length;c++}}const d=(g=1)=>{i.pairs-=g;if(i.pairs<0)r("agentic local cross-hierarchy crossing-work limit")};if(e.maximumEdgeStrokeWidth!==void 0)Mr(i,r);const u=e.maximumEdgeStrokeWidth===void 0?void 0:g=>Mr(i,r,g);const f=g=>{i.pairs-=s*Math.max(0,g.length-1)*a+g.length+a;if(i.pairs<0)r("agentic local cross-hierarchy crossing-work limit");return o(g,t,n,e,d,u,void 0,s)!==void 0};if(a<32)return f;let h;let m;let p;return g=>{const y=Math.max(0,g.length-1);const w=1+9*g.length+(e.maximumEdgeStrokeWidth===void 0?8:20)*c+n.length;const S=h?0:9*l+c+3*n.length;const x=(s*y+1)*a;if(!Number.isSafeInteger(x)||x<=w+S)return f(g);if(!h){Mr(i,r,2*n.length);d(2*n.length);h=n.slice();m=new Array(n.length);for(let b=0;b<n.length;b++){d();const C=n[b];if(b===t||C.style==="invisible")continue;Mr(i,r);const P={points:C.points,style:C.style,originalStyle:C.style,orthogonal:false,minX:Infinity,maxX:-Infinity,minY:Infinity,maxY:-Infinity};Y0(C.points,P,d);h[b]=P;m[b]=P}Mr(i,r);p={orthogonal:false,minX:Infinity,maxX:-Infinity,minY:Infinity,maxY:-Infinity}}Y0(g,p,d);let M=0;for(let b=0;b<h.length;b++){d();const C=m[b];if(!C)continue;C.style=qA(p,C,d,e.maximumEdgeStrokeWidth)?"invisible":C.originalStyle;if(C.style!=="invisible")M+=Math.max(0,C.points.length-1)}d(s*y*M+g.length+M);return o(g,t,h,e,d,u,void 0,s)!==void 0}}function lh(e,t,n,i,r,o){const s=(g=1)=>{i.pairs-=g;if(i.pairs<0)r("agentic local cross-hierarchy crossing-work limit")};if(e.maximumEdgeStrokeWidth!==void 0)Mr(i,r,2*t.edges.length+3);const a=e.maximumEdgeStrokeWidth===void 0?void 0:g=>Mr(i,r,g);const l=ea(e);let c=0,d=0,u=0;const f=t.edges.map((g,y)=>{s();let w=g.points.length>=2;for(let x=0;w&&x<g.points.length;x++){s();const M=g.points[x];if(!Number.isFinite(M.x)||!Number.isFinite(M.y)||x>0&&M.x!==g.points[x-1].x&&M.y!==g.points[x-1].y)w=false}const S=e.edges[y].visible!==false;if(S){c+=Math.max(0,g.points.length-1);d+=g.points.length;u++}return{...g,style:S?"solid":"invisible",orthogonal:w,covered:false}});let h;if(e.maximumEdgeStrokeWidth!==void 0&&e.maximumEdgeBendRadius===0){Mr(i,r,n.size+f.length+1);h=[];for(const g of n){s();h.push(g)}for(let g=0;g<f.length;g++){s();if(e.edges[g].visible!==false){s();if(!n.has(g))h.push(g)}}}const m=h??n;let p;if(c>=32){let g=0;for(const S of m){s();if(o){s();if(f[S].orthogonal&&e.edges[S].visible!==false&&o.has(S))continue}g=Math.max(g,f[S].points.length-1)}const y=(l*g+1)*c;const w=9*d+u+2*f.length+(e.maximumEdgeStrokeWidth===void 0?8:20)*u;if(Number.isSafeInteger(y)&&y>w){Mr(i,r,f.length);s(f.length);p=new Array(f.length);for(let S=0;S<f.length;S++){s();const x=f[S];if(x.style==="invisible"||!x.orthogonal)continue;Mr(i,r);const M={orthogonal:false,minX:Infinity,maxX:-Infinity,minY:Infinity,maxY:-Infinity};Y0(x.points,M,s);p[S]=M}}}for(const g of m){const y=f[g],w=y.points;const S=y.orthogonal&&e.edges[g].visible!==false;if(o){s();if(S&&o.has(g))continue}let x=0;for(let M=0;M<f.length;M++){s();const b=f[M];if(o)s();b.style=e.edges[M].visible===false||S&&(b.covered||b.orthogonal&&o?.has(M))?"invisible":"solid";if(p&&M!==g&&b.style!=="invisible"&&qA(p[g],p[M],s,e.maximumEdgeStrokeWidth))b.style="invisible";if(M!==g&&b.style!=="invisible")x+=Math.max(0,b.points.length-1)}s(l*Math.max(0,w.length-1)*x+w.length+x+f.length);if(os(w,g,f,e,s,a,void 0,l)===void 0)r("cross-hierarchy routes have an uncertified shared contact");if(S)y.covered=true}}function V3(e,t,n,i,r,o){for(let s=0;s<e.edges.length;s++)for(let a=0;a<2;a++){i.pairs-=10;if(i.pairs<0)o("agentic marker endpoint work limit");const l=t.edges[s].points,c=e.edges[s],d=a===0;if(l.length<2)continue;const u=d?0:l.length-1,f=l[u],h=d?l[1]:l.at(-2),m=n[d?c.source:c.target];let p,g;if(f.x===h.x&&f.y!==h.y){p="y";g=h.y>f.y?m.y+m.height:m.y}else if(f.y===h.y&&f.x!==h.x){p="x";g=h.x>f.x?m.x+m.width:m.x}else continue;if(f[p]===g)continue;i.arcs-=10;i.pairs-=256;if(i.arcs<0)o("agentic marker endpoint capacity limit");if(i.pairs<0)o("agentic marker endpoint work limit");if(Xe(f[p])!==Xe(g))continue;r(1);if(--i.arcs<0)o("agentic marker endpoint capacity limit");i.pairs-=3;if(i.pairs<0)o("agentic marker endpoint work limit");l[u]={x:f.x,y:f.y,[p]:g}}}function XA(e,t,n,i,r,o,s,a,l,c,d,u,f=false){if(f||e.maximumEdgeBendRadius===0)V3(e,t,r,s,a,l);s.arcs-=14;if(s.arcs<0)l("agentic marker full-proof capacity limit");const h=(b=1)=>{s.pairs-=b;if(s.pairs<0)l("agentic marker full-proof work limit")};const m=b=>Mr(s,l,b);const p=new Set;a(4);let g=0;for(let b=0;b<e.edges.length;b++){if(--s.pairs<0)l("agentic marker full-proof work limit");if(e.edges[b].label&&t.edges[b].labelPosition)g++}s.arcs-=2*(n.length+i.length+g)+3;if(s.arcs<0)l("agentic marker full-proof capacity limit");const y=[],w={x:0,y:0,width:t.width,height:t.height};for(let b=0;b<n.length;b++){if(--s.pairs<0)l("agentic marker full-proof work limit");const C=n[b],P=(e.nodes[b].paintStrokeWidth??0)/2;y.push({x:C.x-P,y:C.y-P,width:C.width+2*P,height:C.height+2*P})}for(let b=0;b<i.length;b++){if(--s.pairs<0)l("agentic marker full-proof work limit");const C=i[b],P=(e.groups[b].paintStrokeWidth??0)/2,E=o[b].headerHeight??o[b].padding.top;y.push({x:C.x-P,y:C.y-P,width:C.width+2*P,height:E+2*P})}for(let b=0;b<e.edges.length;b++){if(--s.pairs<0)l("agentic marker full-proof work limit");const C=e.edges[b].label,P=t.edges[b].labelPosition;if(C&&P)y.push({x:P.x-C.width/2-2,y:P.y-C.height/2-2,width:C.width+4,height:C.height+4})}const S={x:0,y:0,width:0,height:0};const x=[{kind:"polygon",points:[{x:0,y:0},{x:0,y:0},{x:0,y:0},{x:0,y:0}]}];const M=(b,C,P,E=false)=>{const k=e.edges[b],v=t.edges[b];h();if(E){if(C!==v.points||k.visible===false||C.length<2)return false;for(let I=0;I<C.length;I++){h(3);const L=C[I];if(!Number.isFinite(L.x)||!Number.isFinite(L.y)||I&&L.x!==C[I-1].x&&L.y!==C[I-1].y)return false}}else{if(ah(C,s,l))return false;for(let $=0;$<C.length;$++){h();const B=C[$];if(!Number.isFinite(B.x)||!Number.isFinite(B.y)||$&&B.x!==C[$-1].x&&B.y!==C[$-1].y)return false}for(let $=0;$<2;$++){h(8);const B=$===0,F=r[B?k.source:k.target];const z=B?C[0]:C.at(-1),_=B?C[1]:C.at(-2);const H=B?v.points[0]:v.points.at(-1),D=B?v.points[1]:v.points.at(-2);if(Math.sign(_.x-z.x)!==Math.sign(D.x-H.x)||Math.sign(_.y-z.y)!==Math.sign(D.y-H.y)||Math.abs(_.x-z.x)+Math.abs(_.y-z.y)<Math.min(d,Math.abs(D.x-H.x)+Math.abs(D.y-H.y)))return false;if(z.x<F.x||z.x>F.x+F.width||z.y<F.y||z.y>F.y+F.height)return false;if(!(Math.abs(z.x-F.x)<1e-7&&_.y===z.y&&_.x<z.x||Math.abs(z.x-F.x-F.width)<1e-7&&_.y===z.y&&_.x>z.x||Math.abs(z.y-F.y)<1e-7&&_.x===z.x&&_.y<z.y||Math.abs(z.y-F.y-F.height)<1e-7&&_.x===z.x&&_.y>z.y))return false}let I=false;if(k.label){if(!v.labelPosition)return false;for(let $=1;$<v.points.length;$++){h();if(fo(v.labelPosition,v.points[$-1],v.points[$])){I=true;break}}if(k.source!==k.target||I){let $=false;for(let B=1;B<C.length;B++){h();if(fo(v.labelPosition,C[B-1],C[B])){$=true;break}}if(!$)return false}}const L=(u??1)/2;for(let $=1;$<C.length;$++){const B=C[$-1],F=C[$];for(let z=0;z<n.length;z++){h(5);const _=n[z],H=z===k.source&&$===1||z===k.target&&$===C.length-1,D=H?0:L+(e.nodes[z].paintStrokeWidth??0)/2;S.x=_.x-D;S.y=_.y-D;S.width=_.width+2*D;S.height=_.height+2*D;if(ci(B,F,S))return false}for(let z=0;z<i.length;z++){h(5);const _=i[z],H=o[z].headerHeight??o[z].padding.top;S.x=_.x-L;S.y=_.y-L;S.width=_.width+2*L;S.height=H+2*L;if(H>0&&ci(B,F,S))return false}for(let z=0;z<e.edges.length;z++){h();const _=e.edges[z].label,H=t.edges[z].labelPosition;if(!_||!H)continue;if(z===b&&I&&fo(H,B,F))continue;h(4);S.x=H.x-_.width/2-2;S.y=H.y-_.height/2-2;S.width=_.width+4;S.height=_.height+4;if(ci(B,F,S))return false}}}s.arcs-=2*t.edges.length+1;if(s.arcs<0)l("agentic marker full-proof capacity limit");h(3);const T=C===v.points&&k.visible!==false;let A=0;const R=t.edges.map((I,L)=>{h();let $=e.edges[L].visible!==false;if(T&&$&&L!==b){h(2);if(p.has(L))$=false}if(L!==b&&$)A+=Math.max(0,I.points.length-1);return{...I,style:$?"solid":"invisible"}});h(ea(e)*(C.length-1)*A+C.length+A);return os(C,b,R,e,h,m,P,ea(e))!==void 0};m(1);IA(e.edges,t.edges,r,s,a,l,M,b=>{h(2);if(!p.has(b)){if(--s.arcs<0)l("agentic marker full-proof capacity limit");p.add(b)}if(!c.has(b)){s.arcs--;if(s.arcs<0)l("agentic marker full-proof capacity limit");c.add(b)}},(b,C,P,E)=>{s.arcs--;if(s.arcs<0)l("agentic marker full-proof capacity limit");const k=(T,A,R,I)=>{h(5);if(E.maxX<=T||E.minX>=T+R||E.maxY<=A||E.minY>=A+I)return true;h(8);const L=x[0].points;L[0].x=T;L[0].y=A;L[1].x=T+R;L[1].y=A;L[2].x=T+R;L[2].y=A+I;L[3].x=T;L[3].y=A+I;return!nh(P,x,h)};const v=C?e.edges[b].source:e.edges[b].target;for(let T=0;T<n.length;T++){h();if(T===v)continue;const A=n[T],R=(e.nodes[T].paintStrokeWidth??0)/2;if(!k(A.x-R,A.y-R,A.width+2*R,A.height+2*R))return false}for(let T=0;T<i.length;T++){h();const A=i[T],R=o[T].headerHeight??o[T].padding.top,I=(e.groups[T].paintStrokeWidth??0)/2;if(R>0&&!k(A.x-I,A.y-I,A.width+2*I,R+2*I))return false}for(let T=0;T<e.edges.length;T++){h();const A=e.edges[T].label,R=t.edges[T].labelPosition;if(A&&R&&!k(R.x-A.width/2-2,R.y-A.height/2-2,A.width+4,A.height+4))return false}return true},u,e.maximumEdgeBendRadius??0,{bounds:w,obstacles:y},e.maximumEdgeBendRadius===0?(b,C)=>{h(5);C.candidateSegment=C.peerIndex=C.peerSegment=-1;if(p.has(b))return false;if(M(b,t.edges[b].points,C,!f)){m(1);p.add(b);return false}h(6);if(C.peerIndex<0||C.peerIndex>=t.edges.length||C.peerIndex===b||C.candidateSegment<1||C.candidateSegment>=t.edges[b].points.length||C.peerSegment<1||C.peerSegment>=t.edges[C.peerIndex].points.length)l("Measured final route violates its owned path or contact reservation");return true}:void 0);if(f)for(let b=0;b<t.edges.length;b++){h(2);if(p.has(b))continue;if(!M(b,t.edges[b].points))l("Measured final route violates its owned path or contact reservation");if(--s.arcs<0)l("agentic marker full-proof capacity limit");p.add(b)}return p}function UA(e,t,n,i,r){if(e.placementOnly||e.groups?.length||e.maximumEdgeStrokeWidth===void 0)return t;let o=false;for(const y of e.edges){if(--n.pairs<0)r("agentic marker metadata work limit");if(y.markerPaint?.start?.length||y.markerPaint?.end?.length){o=true;break}}if(!o){if(e.maximumEdgeBendRadius===0){Mr(n,r);if(--n.pairs<0)r("agentic marker full-proof work limit");lh(e,t,new Set,n,r)}return t}const s=e.nodes.length,a=e.edges.length;n.arcs-=3*s+a+7;n.pairs-=2*s+a+4;if(n.arcs<0)r("agentic flat marker metadata capacity limit");if(n.pairs<0)r("agentic flat marker metadata work limit");let l=t.expandedVertices??0;const c=y=>{if(!Number.isSafeInteger(y)||y<0)throw new TypeError("Invalid measured marker point reservation");if(l+y>i)r("agentic local cross-hierarchy visibility-expansion limit");l+=y};const d=t.nodes.map((y,w)=>({...y,width:e.nodes[w].width,height:e.nodes[w].height})),u=[...d];const f=[],h=[],m=new Set;for(let y=0;y<a;y++)m.add(y);for(const y of t.edges){if(--n.pairs<0)r("agentic flat marker path work limit");z0(y.points,n,r)}const p=XA(e,t,d,f,u,h,n,c,r,m,Math.max(8,e.edgeSpacing??6),e.maximumEdgeStrokeWidth,true);lh(e,t,m,n,r,p);n.arcs-=a+2;n.pairs-=a;if(n.arcs<0)r("agentic marker full-proof capacity limit");if(n.pairs<0)r("agentic marker full-proof work limit");const g=[];for(let y=0;y<a;y++)g.push(y);return{...t,expandedVertices:l,boundaryRoutes:g}}function VA(e,t,n,i,r,o,s,a,l){const c=e.nodes.length,d=t.groups,u=e.groups;const f=l?.groups??u;const h=u.length>16||i.size>16||e.edges.length>128;let m=t.edges.reduce((F,z)=>F+z.points.length,0);if(m>2048)a("agentic local cross-hierarchy route-point limit");let p=t.expandedVertices??0;let g=p;const y=F=>{if(!Number.isSafeInteger(F)||F<0)throw new TypeError("Invalid compound visibility reservation");if(p+F>s)a("agentic local cross-hierarchy visibility-expansion limit");p+=F};let w;const S=()=>w??=H0(y,a);let x;const M=()=>x??=zA(F=>{if(!Number.isSafeInteger(F)||F<0)throw new TypeError("Invalid compound adjacency reservation");o.arcs-=F;if(o.arcs<0)a("agentic local cross-hierarchy visibility-arc limit")},a);const b=e.maximumEdgeStrokeWidth;if(b!==void 0){Mr(o,a,2);if(--o.pairs<0)a("agentic local cross-hierarchy crossing-work limit")}const C=b===void 0?void 0:F=>Mr(o,a,F);const P=b===void 0?void 0:F=>{o.pairs-=F;if(o.pairs<0)a("agentic local cross-hierarchy crossing-work limit")};let E=false;if(b!==void 0)for(const F of e.edges){if(--o.pairs<0)a("agentic marker metadata work limit");if(F.markerPaint?.start?.length||F.markerPaint?.end?.length){E=true;break}}const k=Math.max(8,e.edgeSpacing??6);const v=t.nodes.map((F,z)=>({...F,width:e.nodes[z].width,height:e.nodes[z].height}));const T=[...v,...d];const A=new Set;const R=new Set;let I;let L;let $;for(const[F,z]of i)for(let _=0;_<2;_++){let H;let D=false;let j;const W=O=>{j??=[];j.push(O);return O};try{o.pairs-=v.length+d.length;if(o.pairs<0)a("agentic local cross-hierarchy obstacle-work limit");const O=e.edges[F],N=t.edges[F];const G=ii(N.points);if(G.length<2||O.label&&!N.labelPosition)throw new TypeError("Compound quotient lost its route or label");const Y=O.source!==z.source,q=O.target!==z.target;const V=(de,be,pe=k)=>{const Re=Math.abs(de.x-be.x)+Math.abs(de.y-be.y),Ne=Math.min(pe,Re/2);return{x:de.x+Math.sign(be.x-de.x)*Ne,y:de.y+Math.sign(be.y-de.y)*Ne}};const ne=Y?V(G[0],G[1]):G[0];const X=q?V(G.at(-1),G.at(-2)):G.at(-1);const U=[ne,...G.slice(1,-1),X];const K=new Set;for(const de of[O.source,O.target])for(let be=n[de];be>=0;be=n[c+be])K.add(be);const Z=v.map((de,be)=>be===O.source||be===O.target?de:sh(de,k));for(let de=0;de<d.length;de++){const be=d[de];if(c+de===O.source||c+de===O.target)Z.push(be);else if(!K.has(de))Z.push(sh(be,k));else if(u[de].padding.top>0)Z.push(sh({...be,height:l||c>64?f[de].headerHeight??f[de].padding.top:u[de].padding.top},Math.max(2,(e.edgeSpacing??6)/2)))}const Q=[...Z];let se;if(O.label&&--o.arcs<0)a("agentic local cross-hierarchy visibility-arc limit");for(let de=0;de<t.edges.length;de++){if(--o.pairs<0)a("agentic local cross-hierarchy obstacle-work limit");const be=t.edges[de],pe=e.edges[de];if(pe.label&&be.labelPosition){const Re=sh({x:be.labelPosition.x-pe.label.width/2,y:be.labelPosition.y-pe.label.height/2,width:pe.label.width,height:pe.label.height},2);Z.push(Re);Q.push(Re);if(de===F)se=Re}if(de===F||pe.visible===false||l?.connections.has(de))continue;for(let Re=1;Re<be.points.length;Re++){if(--o.pairs<0)a("agentic local cross-hierarchy obstacle-work limit");const Ne=be.points[Re-1],J=be.points[Re];Z.push(sh({x:Math.min(Ne.x,J.x),y:Math.min(Ne.y,J.y),width:Math.abs(Ne.x-J.x),height:Math.abs(Ne.y-J.y)},Math.max(2,(e.edgeSpacing??6)/2)))}}let te;const ee=()=>te??=(I??=DA(o,a))(Q);const ae=z.host,ie=ae<0?void 0:d[ae],oe=ae<0?void 0:f[ae].padding;o.pairs-=8;if(o.pairs<0)a("agentic local cross-hierarchy obstacle-work limit");const ue=ae<0?void 0:u[ae].paintCornerRadius;const ye=b===void 0||ue===void 0?Infinity:(b+(u[ae].paintStrokeWidth??0))/2+ue+1;const Se=ie&&oe?_===0?{x:ie.x+oe.left,y:ie.y+oe.top,width:ie.width-oe.left-oe.right,height:ie.height-oe.top-oe.bottom}:{x:ie.x+ye,y:ie.y+oe.top,width:ie.width-2*ye,height:ie.height-oe.top-ye}:{x:0,y:0,width:t.width,height:t.height};const Te=Y?lc(T[O.source],r[n[O.source]+1],true,k):[];const Ie=q?lc(T[O.target],r[n[O.target]+1],false,k):[];const Ee=de=>{const be=[];for(let pe=n[de];pe>=0;pe=n[c+pe]){if(--o.pairs<0)a("agentic local cross-hierarchy obstacle-work limit");be.push(d[pe])}return be};let ve;let $e;let De="agentic local cross-hierarchy size limit";const fe=de=>{if(de==="agentic local cross-hierarchy visibility-expansion limit"||de==="cross-hierarchy route has no bounded clear corridor"||de==="cross-hierarchy route needs an unsupported self-contact repair")throw new Od(de);return a(de)};if(!h)try{let de=Y?void 0:[ne];let be=q?void 0:[X];if(c>64){const pe={pairs:Math.min(16384,Math.floor(o.pairs/8)),candidates:64};if(!de)de=cc(Se,Z,Te,ne,Ee(O.source),k,o,pe,a);if(!be)be=cc(Se,Z,Ie,X,Ee(O.target),k,o,pe,a)?.reverse();if(!de||!be)a("large cross-hierarchy route has no bounded direct corridor")}if(!de||!be){const pe=s-p;const Re=GA(Se,Z,[...Te,...Ie],[ne,X],k,o,pe,fe,y);if(Re.virtualVertices>pe||Re.virtualVertices>s-g)fe("agentic local cross-hierarchy visibility-expansion limit");g+=Re.virtualVertices;de??=Re.route(Te,ne);be??=Re.route(Ie,X).reverse()}ve=ii([...de,...U.slice(1,-1),...be]);if(ah(ve,o,a)){$e=ve;fe("cross-hierarchy route needs an unsupported self-contact repair")}}catch(de){if(!(de instanceof Od))throw de;De=de.reason;ve=void 0}if(!ve){const de={pairs:Math.min(16384,Math.floor(o.pairs/8)),candidates:64};let be=Y?V(G[0],G[1],k*2):ne;let pe=q?V(G.at(-1),G.at(-2),k*2):X;let Re=[be,...G.slice(1,-1),pe];if(O.label&&!Re.some((le,we)=>we>0&&fo(N.labelPosition,Re[we-1],le))){be=ne;pe=X;Re=U}const Ne=t.edges.map((le,we)=>({...le,style:e.edges[we].visible===false||l?.connections.has(we)||i.has(we)&&!A.has(we)?"invisible":"solid"}));const J=X3(e,F,Ne,o,a);const ge=le=>{const we=ah(le,o,a)?q3(le,o,a):le;if(we.length<2)return;for(const ke of[true,false]){o.pairs-=4;if(o.pairs<0)a("agentic local cross-hierarchy self-check limit");const Le=ke?le[0]:le.at(-1),Fe=ke?le[1]:le.at(-2);const Oe=ke?we[0]:we.at(-1),We=ke?we[1]:we.at(-2);const ce=T[ke?O.source:O.target];const Ae=Fe.x-Le.x,Pe=Fe.y-Le.y;const He=Math.abs(Ae)+Math.abs(Pe),je=Math.min(k,He);const Ke={x:Le.x+Math.sign(Ae)*je,y:Le.y+Math.sign(Pe)*je};if(Oe.x!==Le.x||Oe.y!==Le.y||!fo(Ke,Oe,We))return;if(Oe.x<ce.x-1e-7||Oe.x>ce.x+ce.width+1e-7||Oe.y<ce.y-1e-7||Oe.y>ce.y+ce.height+1e-7)return;const ze=Math.abs(Oe.x-ce.x)<1e-7&&We.y===Oe.y&&We.x<Oe.x||Math.abs(Oe.x-ce.x-ce.width)<1e-7&&We.y===Oe.y&&We.x>Oe.x||Math.abs(Oe.y-ce.y)<1e-7&&We.x===Oe.x&&We.y<Oe.y||Math.abs(Oe.y-ce.y-ce.height)<1e-7&&We.x===Oe.x&&We.y>Oe.y;if(!ze)return}if(O.label&&!we.some((ke,Le)=>Le>0&&fo(N.labelPosition,we[Le-1],ke)))return;return J(we)?we:void 0};if($e)ve=ge($e);const Ce=le=>{if(!q){const we=ii([...le,...Re.slice(1)]);const ke=ge(we);if(ke){ve=ke;return true}return false}return cc(Se,Q,Ie,pe,Ee(O.target),k,o,de,a,we=>{const ke=ii([...le,...Re.slice(1,-1),...we.toReversed()]);const Le=ge(ke);if(Le){ve=Le;return true}return false},true,ee)!==void 0};let Me;if(b!==void 0&&!ve){o.arcs-=32;if(o.arcs<0)a("agentic local cross-hierarchy visibility-arc limit");Me=()=>{if(!ve&&!O.label){const le=lc(T[O.source],r[n[O.source]+1],true,k);const we=lc(T[O.target],r[n[O.target]+1],false,k);const ke=[...Ee(O.source),...Ee(O.target)];for(let Le=0;Le<3&&!ve&&de.candidates>0;Le++)for(let Fe=0;Fe<4&&!ve&&de.candidates>0;Fe++){const Oe=we[Fe*3+Le];let We=true;for(const ce of Q){if(de.pairs--<=0){We=false;break}if(--o.pairs<0)a("agentic local cross-hierarchy direct-pair limit");if(ci(Oe.stub,Oe.port,ce)){We=false;break}}if(!We)continue;cc(Se,Q,le,Oe.stub,ke,k,o,de,a,ce=>{const Ae=ii([...ce,Oe.port]);const Pe=ge(Ae);if(Pe){ve=Pe;return true}return false},true,ee)}}else if(!ve&&Y)cc(Se,Q,Te,be,Ee(O.source),k,o,de,a,Ce,true,ee);else if(!ve)Ce([be])}}else if(b===void 0){if(!ve&&!O.label){const le=lc(T[O.source],r[n[O.source]+1],true,k);const we=lc(T[O.target],r[n[O.target]+1],false,k);const ke=[...Ee(O.source),...Ee(O.target)];for(let Le=0;Le<3&&!ve&&de.candidates>0;Le++)for(let Fe=0;Fe<4&&!ve&&de.candidates>0;Fe++){const Oe=we[Fe*3+Le];let We=true;for(const ce of Q){if(de.pairs--<=0){We=false;break}if(--o.pairs<0)a("agentic local cross-hierarchy direct-pair limit");if(ci(Oe.stub,Oe.port,ce)){We=false;break}}if(!We)continue;cc(Se,Q,le,Oe.stub,ke,k,o,de,a,ce=>{const Ae=ii([...ce,Oe.port]);const Pe=ge(Ae);if(Pe){ve=Pe;return true}return false},true,ee)}}else if(!ve&&Y)cc(Se,Q,Te,be,Ee(O.source),k,o,de,a,Ce,true,ee);else if(!ve)Ce([be])}if(!ve)try{const le=(Pe,He)=>{let je=0,Ke=0,ze=0;const Ze=Ne.map((nt,it)=>{if(--o.pairs<0)a("agentic local cross-hierarchy obstacle-work limit");const $t=e.edges[it],yn=$t.source===Pe||$t.target===Pe;if(yn){je++;if(it<F)Ke++}const St=yn?nt.style:"invisible";if(it!==F&&St!=="invisible")ze+=Math.max(0,nt.points.length-1);return{...nt,style:St}});const tt=[...new Set([(Ke+1)/(je+1),.5,.25,.75])];return lc(T[Pe],r[n[Pe]+1],He,k,tt).filter(nt=>{o.pairs-=4*ze+2;if(o.pairs<0)a("agentic local cross-hierarchy crossing-work limit");return rh(He?[nt.port,nt.stub]:[nt.stub,nt.port],F,Ze,e,P,C)!==void 0})};const we=(Pe,He)=>{let je=0,Ke=0;for(let St=0;St<e.edges.length;St++){if(--o.pairs<0)a("agentic local cross-hierarchy obstacle-work limit");const fi=e.edges[St];if(fi.source===Pe||fi.target===Pe){je++;if(St<F)Ke++}}o.arcs-=8;if(o.arcs<0)a("agentic local cross-hierarchy visibility-arc limit");y(8);const ze=T[Pe],Ze=r[n[Pe]+1],tt=(Ke+.5)/(je+1);const nt=Ze==="LR"?"E":Ze==="RL"?"W":Ze==="BT"?"N":"S";const it=He?nt:nt==="N"?"S":nt==="S"?"N":nt==="E"?"W":"E";const $t=new Array(4);const yn=St=>St===0?it:it==="N"?St===1?"E":St===2?"S":"W":it==="E"?St===1?"N":St===2?"S":"W":it==="S"?St===1?"N":St===2?"E":"W":St===1?"N":St===2?"E":"S";for(let St=0;St<4;St++){if(--o.pairs<0)a("agentic local cross-hierarchy obstacle-work limit");const fi=yn(St);const ul=fi==="N"||fi==="S"?{x:ze.x+tt*ze.width,y:fi==="N"?ze.y:ze.y+ze.height}:{x:fi==="W"?ze.x:ze.x+ze.width,y:ze.y+tt*ze.height};const Hx={x:ul.x+(fi==="E"?k*2:fi==="W"?-k*2:0),y:ul.y+(fi==="S"?k*2:fi==="N"?-k*2:0)};$t[St]={port:ul,stub:Hx,penalty:St*k*2+Math.abs(tt-.5)*k}}return $t};let ke=ge;if(b!==void 0){o.arcs-=4;if(o.arcs<0)a("agentic local cross-hierarchy visibility-arc limit");ke=Pe=>ge(z0(Pe,o,a))}const Le=O.label&&!Y?[]:le(O.source,true);const Fe=O.label&&!q?[]:le(O.target,false);L??=WA(Ne,F,t.width,t.height,o,y,a);H=L.acquire(F);const Oe=L.rails;const We=H.guard;const ce=Pe=>{const He=je=>je.x>=Se.x&&je.x<=Se.x+Se.width&&je.y>=Se.y&&je.y<=Se.y+Se.height;for(const je of Pe){o.pairs-=8;if(o.pairs<0)a("agentic local cross-hierarchy obstacle-work limit");const{port:Ke,stub:ze}=je;if(!He(Ke)||!He(ze))continue;const Ze=ee();if(Ze.containsPoint(Ke.x,Ke.y)||Ze.containsPoint(ze.x,ze.y)||Ze.entersSegment(Ke.x,Ke.y,ze.x,ze.y))continue;const tt=Ke.x===ze.x?2:Ke.y===ze.y?1:0;if(!tt)throw new TypeError("Measured terminal lead must be orthogonal");if(We(Ke,ze,tt,tt))return true}return false};const Ae=Pe=>{try{Pe();return ve!==void 0}catch(He){if(!(He instanceof Od))throw He;De=He.reason;return false}};if(!O.label){if(b!==void 0){o.pairs-=2;if(o.pairs<0)a("agentic local cross-hierarchy obstacle-work limit");L.enterQuery(H);try{ve=BA(Se,Q,Le,Fe,Oe,ee(),o,y,a,We,ke,Math.max(.5,b))}finally{L.leaveQuery(H)}}if(b!==void 0){o.pairs-=2;if(o.pairs<0)a("agentic local cross-hierarchy crossing-work limit")}if(!ve&&Me)Me();const Pe=He=>{const je=W(oh(Se,Q,[...Le,...Fe],[be,pe],k,o,s-p,fe,y,He,ee,S(),Oe,M()));try{for(const Ke of Fe){if(ve)break;if(!ee().entersSegment(Ke.stub.x,Ke.stub.y,Ke.port.x,Ke.port.y))Ae(()=>{L.enterQuery(H);try{je.route(Le,Ke.stub,ze=>{const Ze=ge(ii([...ze,Ke.port]));if(Ze){ve=Ze;return true}return false},We)}finally{L.leaveQuery(H)}})}}finally{je.retire()}};if(!ve)Pe(false);if(!ve&&De==="cross-hierarchy route has no bounded clear corridor")Pe(true)}else{if(b!==void 0&&!Y&&q&&se){o.pairs-=2;if(o.pairs<0)a("agentic local cross-hierarchy obstacle-work limit");L.enterQuery(H);try{ve=OA(Re,T[O.source],N.labelPosition,se,Se,Q,Fe,Oe,ee(),o,k,Math.max(.5,b),y,a,We,ke)}finally{L.leaveQuery(H)}}if(b!==void 0){o.pairs-=2;if(o.pairs<0)a("agentic local cross-hierarchy crossing-work limit")}if(!ve&&Me)Me();if(!ve){const Pe=nt=>n[nt]<0?T[nt]:d[n[nt]];const He={roots:Fe,interiorChannels:false,paths:[],complete:false};const je={roots:Fe,interiorChannels:true,paths:[],complete:false};const Ke=[];const ze=(nt,it=He)=>{if(!q){const St=ge(ii([...nt,...Re.slice(1)]));if(St){ve=St;return true}return false}const $t=St=>{const fi=ge(ii([...nt,...Re.slice(1,-1),...St.toReversed()]));if(fi){ve=fi;return true}return false};for(const St of it.paths)if($t(St))return true;if(it.complete)return false;if(!it.graph&&!ce(it.roots)){it.complete=true;De="cross-hierarchy route has no bounded clear corridor";return false}const yn=Ae(()=>{it.graph??=W(j0(Se,Pe(O.target),Q,it.roots,pe,k,o,s-p,fe,y,it.interiorChannels,ee,S(),Oe,M()));L.enterQuery(H);try{it.graph.route(it.roots,pe,St=>{if(it.late&&--o.arcs<0)a("agentic local cross-hierarchy visibility-arc limit");it.paths.push(St);return $t(St)},We)}finally{L.leaveQuery(H)}});if(!yn&&De==="cross-hierarchy route has no bounded clear corridor")it.complete=true;if(it.complete||yn)it.graph?.retire();return yn};const Ze=(nt,it,$t)=>{if(!ce(nt)){De="cross-hierarchy route has no bounded clear corridor";return false}return Ae(()=>{const yn=W(j0(Se,Pe(O.source),Q,nt,be,k,o,s-p,fe,y,it,ee,S(),Oe,M()));L.enterQuery(H);try{yn.route(nt,be,$t,We)}finally{try{L.leaveQuery(H)}finally{yn.retire()}}})};const tt=nt=>{Ke.push(nt);return ze(nt)};if(Y)Ze(Le,false,tt);else tt([be]);if(!ve&&De==="cross-hierarchy route has no bounded clear corridor"){if(q){for(const nt of Ke)if(ze(nt,je))break}if(!ve&&Y)Ze(Le,true,nt=>{if(--o.arcs<0)a("agentic local cross-hierarchy visibility-arc limit");Ke.push(nt);return ze(nt)||ze(nt,je)})}if(!ve&&De==="cross-hierarchy route has no bounded clear corridor"){let nt;if(q){const it=we(O.target,false);if(--o.arcs<0)a("agentic local cross-hierarchy visibility-arc limit");nt={roots:it,interiorChannels:false,late:true,paths:[],complete:false}}if(nt){for(const it of Ke)if(ze(it,nt))break}if(!ve&&Y)Ze(we(O.source,true),false,it=>ze(it)||q&&(ze(it,je)||ze(it,nt)))}}}}catch(le){if(!(le instanceof Od))throw le;De=le.reason}if(!ve){if(_===0&&ie&&oe&&b!==void 0&&u[ae].paintStrokeWidth!==void 0&&ye<oe.left&&ye<oe.right&&ye<oe.bottom&&De==="cross-hierarchy route has no bounded clear corridor")continue;a(De)}R.add(F)}const me=ve;if(O.label&&!me.some((de,be)=>be>0&&fo(N.labelPosition,me[be-1],de)))a("cross-hierarchy route lost its reserved label corridor");m+=me.length-N.points.length;if(m>2048)a("agentic local cross-hierarchy route-point limit");t.edges[F]={...N,points:me};A.add(F);D=true}finally{try{if(j)for(const O of j)O.retire()}finally{H?.release()}}if(D&&L)L.publish(F,t.edges[F].points,e.edges[F].visible!==false&&!l?.connections.has(F));break}if(l?.connections.size){const F=new Set;for(const[z,_]of l.connections){const H=e.edges[z],D=t.edges[z];const j=t.edges.map((Y,q)=>({...Y,style:e.edges[q].visible===false||l.connections.has(q)&&!F.has(q)?"invisible":"solid"}));const W=j.reduce((Y,q,V)=>Y+(V===z||q.style==="invisible"?0:Math.max(0,q.points.length-1)),0);const O=new Set;for(let Y=n[_.interior];Y>=0;Y=n[c+Y]){if(--o.pairs<0)a("agentic local cross-hierarchy obstacle-work limit");O.add(Y)}const N=[...v];for(let Y=0;Y<d.length;Y++){if(--o.pairs<0)a("agentic local cross-hierarchy obstacle-work limit");const q=f[Y].headerHeight??f[Y].padding.top;if(!O.has(Y))N.push(d[Y]);else if(q>0)N.push({...d[Y],height:q})}const G=YA(e,t,n,l,z,{work:o,remainingVertices:s-p,reserveVertices:y,queryWorkspaces:S(),fail:a,accept(Y){const q=Y.points;if(q.length<2||q.some((ee,ae)=>!Number.isFinite(ee.x+ee.y)||ae>0&&ee.x!==q[ae-1].x&&ee.y!==q[ae-1].y))throw new TypeError("Ancestor boundary producer returned invalid points");if(ah(q,o,a))return false;const V=_.containerEnd==="source",ne=d[_.container];const X=V?q[0]:q.at(-1),U=V?q[1]:q.at(-2);const K=f[_.container].headerHeight??f[_.container].padding.top;if(Math.abs(X.x-ne.x)>1e-7||X.y<ne.y+K||X.y>ne.y+ne.height||U.y!==X.y||U.x-X.x<_.minimumLead)return false;const Z=V?q.at(-1):q[0],Q=V?q.at(-2):q[1],se=T[_.interior];if(Z.x<se.x-1e-7||Z.x>se.x+se.width+1e-7||Z.y<se.y-1e-7||Z.y>se.y+se.height+1e-7)return false;const te=Math.abs(Z.x-se.x)<1e-7&&Q.y===Z.y&&Q.x<Z.x||Math.abs(Z.x-se.x-se.width)<1e-7&&Q.y===Z.y&&Q.x>Z.x||Math.abs(Z.y-se.y)<1e-7&&Q.x===Z.x&&Q.y<Z.y||Math.abs(Z.y-se.y-se.height)<1e-7&&Q.x===Z.x&&Q.y>Z.y;if(!te||Math.abs(Q.x-Z.x)+Math.abs(Q.y-Z.y)<l.clearance)return false;if(H.label&&(!Y.labelPosition||!q.some((ee,ae)=>ae>0&&fo(Y.labelPosition,q[ae-1],ee))))return false;for(let ee=1;ee<q.length;ee++)for(const ae of N){if(--o.pairs<0)a("agentic local cross-hierarchy obstacle-work limit");if(ci(q[ee-1],q[ee],ae))return false}o.pairs-=ea(e,"proposal")*Math.max(0,q.length-1)*W+q.length+W;if(o.pairs<0)a("agentic local cross-hierarchy crossing-work limit");return rh(q,z,j,e,P,C)!==void 0}});m+=G.points.length-D.points.length;if(m>2048)a("agentic local cross-hierarchy route-point limit");t.edges[z]={...D,...G};F.add(z);R.add(z)}}if(E)$=XA(e,t,v,d,T,f,o,y,a,R,k,b);if(R.size||b!==void 0&&e.maximumEdgeBendRadius===0)lh(e,t,R,o,a,$);const B=[...i.keys()];if(l?.connections.size){for(const F of l.connections.keys())if(!i.has(F))B.push(F);B.sort((F,z)=>F-z)}if(E){let F=false;for(const z of R){o.pairs-=B.length+1;if(o.pairs<0)a("agentic marker full-proof work limit");if(B.includes(z))continue;if(--o.arcs<0)a("agentic marker full-proof capacity limit");B.push(z);F=true}if(F)B.sort((z,_)=>{if(--o.pairs<0)a("agentic marker full-proof work limit");return z-_})}if(E){o.arcs-=e.edges.length+1;o.pairs-=e.edges.length;if(o.arcs<0)a("agentic marker full-proof capacity limit");if(o.pairs<0)a("agentic marker full-proof work limit");const F=new Array(e.edges.length);for(let z=0;z<e.edges.length;z++)F[z]=z;return{...t,expandedVertices:p,boundaryRoutes:F}}return{...t,expandedVertices:p,boundaryRoutes:B}}function KA(e,t,n,i){const r=new Int32Array(t.length);for(const o of n){if((i.blockPairs??2e6)<=0)return;const s=o.slice(1,-1);if(s.length<2||s.some((x,M)=>t[x].incoming.length!==1||t[x].outgoing.length!==1||t[x].incoming[0]!==o[M]||t[x].outgoing[0]!==o[M+2]||t[x].rank!==t[o[M]].rank+1))continue;for(const x of e)for(let M=0;M<x.length;M++)r[x[M]]=M;const a=s.map(x=>e[t[x].rank].filter(M=>M!==x));const l=s.map(x=>r[x]);const c=[];for(let x=0;x<=s.length;x++){const M=o[x],b=o[x+1],C=[];for(const P of e[t[M].rank]){for(const E of t[P].outgoing){if(P===M&&E===b)continue;const k=r[P],v=r[E];C.push(k-Number(x>0&&k>r[M]),v-Number(x<s.length&&v>r[b]))}}c.push(Int32Array.from(C))}let d=false;const u=(x,M,b)=>{const C=c[x],P=1+C.length/2;if((i.blockPairs??2e6)<P){d=true;return Infinity}i.blockPairs=(i.blockPairs??2e6)-P;let E=0;for(let k=0;k<C.length;k+=2){const v=C[k],T=C[k+1];const A=v+Number(x>0&&v>=M),R=T+Number(x<s.length&&T>=b);if((M-A)*(b-R)<0)E++}return E};let f=0;for(let x=0;x<=s.length;x++)f+=u(x,x===0?r[o[0]]:l[x-1],x===s.length?r[o.at(-1)]:l[x]);if(d)return;if(f===0)continue;let h=Float64Array.from({length:a[0].length+1},(x,M)=>u(0,r[o[0]],M));let m=Float64Array.from(h,(x,M)=>Math.abs(M-l[0]));const p=[];for(let x=1;x<s.length&&!d;x++){const M=new Float64Array(a[x].length+1).fill(Infinity),b=new Int32Array(M.length);const C=new Float64Array(M.length).fill(Infinity);for(let P=0;P<M.length&&!d;P++)for(let E=0;E<h.length;E++){if(h[E]>=f)continue;const k=h[E]+u(x,E,P);const v=m[E]+Math.abs(P-l[x]);if(k<M[P]||k===M[P]&&v<C[P]){M[P]=k;b[P]=E;C[P]=v}if(d)break}h=M;m=C;p.push(b)}if(d)return;let g=Infinity,y=Infinity,w=0;for(let x=0;x<h.length;x++){const M=h[x]+u(s.length,x,r[o.at(-1)]);if(M<g||M===g&&m[x]<y){g=M;y=m[x];w=x}}if(d)return;if(g>=f)continue;const S=new Int32Array(s.length);S[s.length-1]=w;for(let x=s.length-2;x>=0;x--)S[x]=p[x][S[x+1]];for(let x=0;x<s.length;x++){const M=a[x];M.splice(S[x],0,s[x]);e[t[s[x]].rank]=M}}}var q0=4096;function ho(e,t=false){return(t&&!e.label?1:2)*e.minSpan}function JA(e,t,n=false){const i=e.nodes.length,r=e.edges;if(i===0)return new Float64Array(0);if(t.rankPairs<=0||i>64||r.length>128||r.reduce((c,d)=>c+d.minSpan,0)>128)return;const o=n?Int32Array.from(r,c=>c.short?100:1):new Int32Array(r.length).fill(1);const s=new Float64Array(i),a=new Int32Array(i),l=new Int32Array(i);for(let c=0;c<128;c++){s.fill(0);a.fill(-1);l.fill(0);let d=-1;for(let g=0;g<i;g++){d=-1;for(let y=0;y<r.length;y++){const w=r[y];t.rankPairs-=2;if(t.rankPairs<0)return;const S=ho(w,e.compactPrivateRanks);if(s[w.target]<s[w.source]+S){s[w.target]=s[w.source]+S;a[w.target]=w.source;l[w.target]=y+1;d=w.target}if(o[y]>0&&s[w.source]<s[w.target]-S){s[w.source]=s[w.target]-S;a[w.source]=w.target;l[w.source]=-y-1;d=w.source}}if(d<0){const y=n?r.reduce((S,x)=>S+(x.short?100:1)*(s[x.target]-s[x.source]),0):r.reduce((S,x)=>S+s[x.target]-s[x.source],0),w=r.reduce((S,x,M)=>S+o[M]*ho(x,e.compactPrivateRanks),0);if(y!==w)throw new Error(`dual rank mismatch ${y} ${w}`);return s}}let u=d;for(let g=0;g<i;g++)u=a[u];const f=u,h=[];let m=Infinity,p=0;do{const g=l[u],y=Math.abs(g)-1;if(y<0)throw new Error("missing residual predecessor");h.push(g);p+=Math.sign(g)*ho(r[y],e.compactPrivateRanks);if(g<0)m=Math.min(m,o[y]);u=a[u]}while(u!==f&&h.length<=i);if(u!==f||p<=0||!Number.isFinite(m)||m<=0)throw new Error(`invalid positive residual cycle ${p} ${m}`);for(const g of h)o[Math.abs(g)-1]=o[Math.abs(g)-1]+Math.sign(g)*m}}function QA(e,t,n){if(n.loopPairs<=0||e.groups?.length||e.nodes.length>256||e.edges.length>128||t.edges.reduce((b,C)=>b+C.points.length,0)>2048)return t;const i=b=>(n.loopPairs-=b)>=0;const r=e.direction==="LR"||e.direction==="RL",o=e.direction==="RL"||e.direction==="BT"?-1:1;const s=r?"x":"y",a=r?"y":"x";const l=(b,C)=>r?{x:b,y:C}:{x:C,y:b};const c=e.nodes.map((b,C)=>({...t.nodes[C],width:b.width,height:b.height}));const d=e.edges.map((b,C)=>{const P=t.edges[C].labelPosition;return b.label&&P?{x:P.x-b.label.width/2,y:P.y-b.label.height/2,width:b.label.width,height:b.label.height}:void 0});const u=t.edges.map((b,C)=>({points:b.points,style:e.edges[C].visible===false?"invisible":"solid"}));const f=()=>u.map(b=>({points:b.points,visible:b.style!=="invisible"}));const h=(b,C)=>Math.min(...C.slice(1).map((P,E)=>{const k=C[E];const v=Math.max(Math.min(k.x,P.x),Math.min(Math.max(k.x,P.x),b.x));const T=Math.max(Math.min(k.y,P.y),Math.min(Math.max(k.y,P.y),b.y));return Math.abs(b.x-v)+Math.abs(b.y-T)}));let m=false;for(const[b,C]of e.edges.entries()){const P=t.edges[b],E=P.points;if(C.source!==C.target||C.visible===false||E.length<=4)continue;const k=E[0],v=E.at(-1);if(Math.abs(k[s]-v[s])>1e-7||Math.abs(k[a]-v[a])<8-1e-7)continue;const T=[...c,...d.filter(($,B)=>Boolean($)&&B!==b)];const A=[...new Set([...E.map($=>$[s]),...T.flatMap($=>r?[$.x-8,$.x+$.width+8]:[$.y-8,$.y+$.height+8]),k[s]+24*o])].filter($=>($-k[s])*o>=24);A.sort(($,B)=>($-B)*o);const R=new Set([b]),I=u.reduce(($,B)=>$+B.points.length,0);n.loopPairs-=I*I;if(n.loopPairs<0)return t;const L=Or(f(),R);for(const $ of A.slice(0,32)){const B=[{...k},l($,k[a]),l($,v[a]),{...v}];if(B.some(D=>D.x<e.padding||D.y<e.padding||D.x>t.width-e.padding||D.y>t.height-e.padding))continue;n.loopPairs-=B.length*T.length+B.length*I;if(n.loopPairs<0)return t;if(B.slice(1).some((D,j)=>T.some(W=>ci(B[j],D,W))))continue;let F=P.labelPosition,z=d[b];const _=D=>B.slice(1).some((j,W)=>ci(B[W],j,D));if(F&&C.label&&(h(F,B)>h(F,E)+1e-7||z&&_(z))){const D=(r?C.label.width:C.label.height)/2,j=(r?C.label.height:C.label.width)/2;const W=D+16,O=($-k[s])*o-D-8;if(W>O)continue;const N=k[s]+o*Math.max(W,Math.min(O,(F[s]-k[s])*o));const G=[l(N,Math.min(k[a],v[a])-j-4),l(N,Math.max(k[a],v[a])+j+4)];G.sort((Y,q)=>Math.abs(Y.x-P.labelPosition.x)+Math.abs(Y.y-P.labelPosition.y)-Math.abs(q.x-P.labelPosition.x)-Math.abs(q.y-P.labelPosition.y));F=void 0;for(const Y of G){const q={x:Y.x-C.label.width/2,y:Y.y-C.label.height/2,width:C.label.width,height:C.label.height};n.loopPairs-=T.length+I;if(n.loopPairs<0)return t;if(q.x<e.padding||q.y<e.padding||q.x+q.width>t.width-e.padding||q.y+q.height>t.height-e.padding)continue;if(T.some(V=>ey(q,V))||_(q)||u.some((V,ne)=>ne!==b&&V.style!=="invisible"&&V.points.slice(1).some((X,U)=>ci(V.points[U],X,q))))continue;F=Y;z=q;break}if(!F)continue}const H=os(B,b,u,e,i,i);if(n.loopPairs<0)return t;if(H===void 0||H>L)continue;P.points=B;u[b].points=B;if(F)P.labelPosition={...F};d[b]=z;m=true;break}}if(!m)return t;let p=Infinity,g=Infinity,y=-Infinity,w=-Infinity;const S=(b,C,P=0,E=0)=>{p=Math.min(p,b);g=Math.min(g,C);y=Math.max(y,b+P);w=Math.max(w,C+E)};c.forEach(b=>S(b.x,b.y,b.width,b.height));t.edges.forEach((b,C)=>{b.points.forEach(k=>S(k.x,k.y));const P=b.labelPosition,E=e.edges[C].label;if(P&&E)S(P.x-E.width/2,P.y-E.height/2,E.width,E.height)});const x=e.padding-p,M=e.padding-g;t.nodes=t.nodes.map(b=>({x:b.x+x,y:b.y+M}));t.edges=t.edges.map(b=>({...b,points:b.points.map(C=>({x:C.x+x,y:C.y+M})),...b.labelPosition?{labelPosition:{x:b.labelPosition.x+x,y:b.labelPosition.y+M}}:{}}));t.width=y-p+2*e.padding;t.height=w-g+2*e.padding;return t}function ZA(e,t,n,i){if(!e.shareCompleteFans||e.edges.some(k=>k.label||k.minSpan!==1))return void 0;const r=[],o=[];for(let k=0;k<e.nodes.length;k++){if(!t[k].length&&n[k].length)r.push(k);else if(!n[k].length&&t[k].length)o.push(k);else return void 0}if(!r.length||!o.length||r.length===1&&o.length===1||e.edges.length!==r.length*o.length)return void 0;const s=new Map(r.map((k,v)=>[k,v]));const a=new Map(o.map((k,v)=>[k,v]));const l=new Set;for(const k of e.edges){if(!s.has(k.source)||!a.has(k.target))return void 0;const v=k.source*e.nodes.length+k.target;if(l.has(v))return void 0;l.add(v)}const c=e.direction==="LR"||e.direction==="RL";const d=e.direction==="BT"||e.direction==="RL";const u=k=>c?e.nodes[k].height:e.nodes[k].width;const f=k=>c?e.nodes[k].width:e.nodes[k].height;const h=k=>k.reduce((v,T)=>v+u(T),0)+(k.length-1)*e.nodeSpacing;const m=h(r),p=h(o),g=Math.max(m,p);const y=Math.max(...r.map(f)),w=Math.max(...o.map(f));const S=Math.max(e.layerSpacing,2*Math.max(12,e.edgeSpacing??6)+(e.edgeSpacing??6));const x=y+S+w;if(!Number.isFinite(x+g+2*e.padding))i("agentic local coordinate-range limit");const M=new Float64Array(e.nodes.length),b=new Float64Array(e.nodes.length);for(const[k,v,T,A]of[[r,m,0,y],[o,p,y+S,w]]){let R=(g-v)/2;for(const I of k){M[I]=R+u(I)/2;b[I]=T+(A-f(I))/2;R+=u(I)+e.nodeSpacing}}const C=(k,v)=>c?{x:e.padding+(d?x-v:v),y:e.padding+k}:{x:e.padding+k,y:e.padding+(d?x-v:v)};const P=e.nodes.map((k,v)=>C(M[v]-u(v)/2,b[v]+(d?f(v):0)));const E=e.edges.map(k=>{if(e.placementOnly&&!e.cycleOriented&&!e.loopPorts?.length)return{points:[]};const v=[];const T=g/2,A=y+S/3,R=y+2*S/3;for(const[I,L]of[[M[k.source],b[k.source]+f(k.source)],[M[k.source],A],[T,A],[T,R],[M[k.target],R],[M[k.target],b[k.target]]]){const $=C(I,L);const B=v.at(-1),F=v.at(-2);if(B?.x===$.x&&B.y===$.y)continue;if(F&&B&&(F.x===B.x&&B.x===$.x&&(B.y-F.y)*($.y-B.y)>=0||F.y===B.y&&B.y===$.y&&(B.x-F.x)*($.x-B.x)>=0))v.pop();v.push($)}return{points:v}});return{topology:"layered",width:2*e.padding+(c?x:g),height:2*e.padding+(c?g:x),nodes:P,edges:E,expandedVertices:P.length,sharedEdges:e.edges.map((k,v)=>v)}}function eI(e,t,n=2){const i=e.nodes.length,r=e.edges;if(!i||i>20||r.length>48||(t.blockPairs??2e6)<=0)return[];const o=new Uint16Array(i),s=new Uint16Array(i),a=new Uint16Array(i);const l=new Float64Array(i),c=new Int32Array(i);for(const M of r)o[M.target]=o[M.target]+1;let d=false;const u=M=>{const b=t.blockPairs??2e6;if(b<M){d=true;return false}t.blockPairs=b-M;return true};const f=(M,b,C=-1)=>{if(!u(i+4))return;s.set(o);l.fill(0);for(const k of[M,b,C])if(k>=0){const v=r[k];s[v.target]=s[v.target]-1;s[v.source]=s[v.source]+1}let P=0;for(let k=0;k<i;k++)if(!s[k])a[P++]=k;for(let k=0;k<P;k++){if(!u(r.length))return;const v=a[k];c[v]=k;for(let T=0;T<r.length;T++){const A=r[T],R=T===M||T===b||T===C;const I=R?A.target:A.source,L=R?A.source:A.target;if(I!==v)continue;l[L]=Math.max(l[L],l[v]+ho(A,e.compactPrivateRanks));s[L]=s[L]-1;if(!s[L])a[P++]=L}}if(P!==i)return;if(!u(r.length))return;let E=0;for(const k of r)E+=Math.abs(l[k.target]-l[k.source]);return{order:c.slice(),span:E}};const h=[];for(let M=0;M<r.length&&!d;M++){const b=f(M,-1);if(b)h.push(b)}if(h.length||d)return h;for(let M=0;M<r.length&&!d;M++){for(let b=M+1;b<r.length&&!d;b++){const C=f(M,b);if(C)h.push(C)}}if(h.length||d||n<3)return h;const m=new Uint8Array(r.length),p=new Uint8Array(i),g=new Int32Array(i);const y=[],w=new Set;const S=()=>{p.fill(0);g.fill(-1);const M=b=>{p[b]=1;for(let C=0;C<r.length;C++){if(!u(1))return;const P=r[C];if(m[C]||P.source!==b)continue;if(p[P.target]===1){const E=[C];for(let k=b;k!==P.target;){const v=g[k];E.push(v);k=r[v].source}return E}if(p[P.target]===0){g[P.target]=C;const E=M(P.target);if(E||d)return E}}p[b]=2;return};for(let b=0;b<i;b++)if(!p[b]){const C=M(b);if(C||d)return C}return};const x=()=>{if(d)return;const M=y.slice().sort((C,P)=>C-P).join(",");if(w.has(M))return;w.add(M);const b=S();if(d)return;if(!b){const C=f(y[0]??-1,y[1]??-1,y[2]??-1);if(C)h.push(C);return}if(y.length===3)return;for(const C of b){m[C]=1;y.push(C);x();y.pop();m[C]=0;if(d)return}};x();return h}function X0(e,t){const n=new Uint8Array(e.length),i=new Uint32Array(e.length);const r=new Int32Array(e.length),o=[];let s=e.length-1;for(let a=0;a<e.length;a++){if(n[a])continue;n[a]=1;o.push(a);while(o.length){const l=o.at(-1);if(i[l]<e[l].length){const c=t[e[l][i[l]]];i[l]=i[l]+1;if(!n[c.target]){n[c.target]=1;o.push(c.target)}}else{o.pop();n[l]=2;r[l]=s--}}}return r}function dc(e,t,n){const i=e.length,r=n.length;const o=new Int32Array(2*r+1).fill(-1);const s=new Int32Array(i).fill(-1),a=new Int32Array(i).fill(-1);const l=Uint32Array.from(e,M=>M.length),c=Uint32Array.from(t,M=>M.length);const d=new Uint8Array(i).fill(1),u=new Int32Array(i);const f=[],h=[];let m=0,p=0,g=i-1;const y=M=>r+c[M]-l[M];const w=M=>{const b=y(M),C=o[b];a[M]=-1;s[M]=C;if(C>=0)a[C]=M;o[b]=M;m=Math.max(m,b)};const S=M=>{const b=a[M],C=s[M];if(b>=0)s[b]=C;else o[y(M)]=C;if(C>=0)a[C]=b};const x=M=>{S(M);d[M]=0;for(const b of e[M]){const C=n[b].source;if(!d[C])continue;S(C);c[C]=c[C]-1;w(C);if(c[C]===0)h.push(C)}for(const b of t[M]){const C=n[b].target;if(!d[C])continue;S(C);l[C]=l[C]-1;w(C);if(l[C]===0)f.push(C)}};for(let M=i-1;M>=0;M--){w(M);if(!l[M])f.push(M);if(!c[M])h.push(M)}while(p<=g){while(h.length){const b=h.pop();if(d[b]){u[b]=g--;x(b)}}while(f.length){const b=f.pop();if(d[b]){u[b]=p++;x(b)}}if(p>g)break;while(m>=0&&o[m]===-1)m--;const M=o[m];if(M===void 0||M<0)throw new TypeError("Feedback ordering lost an active vertex");u[M]=p++;x(M)}return u}var ry=class extends Error{};function tI(e,t,n,i,r,o,s){const{nodes:a,edges:l}=e;const c=dc(t,n,l),d=X0(n,l);const u=R=>l.reduce((I,L)=>I+Number(R[L.source]>R[L.target]),0);const f=(R,I,L,$=false,B=false)=>{const F=l.map(W=>R[W.source]>R[W.target]);const z=a.map((W,O)=>$?a.length-1-O:O);const _=new Uint32Array(a.length);z.forEach((W,O)=>{_[W]=O});const H=l.map((W,O)=>B?l.length-1-O:O);const D=new Uint32Array(l.length);H.forEach((W,O)=>{D[W]=O});const j=i({...e,shareCompleteFans:false,cycleOriented:true,nodes:z.map(W=>a[W]),edges:H.map(W=>{const O=l[W],N=F[W]?O.target:O.source,G=F[W]?O.source:O.target;return{...O,source:_[N],target:_[G]}}),loopPorts:e.loopPorts?.map(([W,O])=>[D[W],D[O]])},I,L);return{...j,nodes:a.map((W,O)=>j.nodes[_[O]]),edges:l.map((W,O)=>{const N=j.edges[D[O]];return F[O]?{...N,points:[...N.points].reverse()}:N})}};if(e.authoredCycleOrder)return f(Uint32Array.from(a,(R,I)=>I),r,o,false,true);const h=u(d)<=u(c)?d:c;let m=f(h,r,o);if(a.length>48||l.length>128||l.reduce((R,I)=>R+I.minSpan,0)>128||(m.expandedVertices??0)>1024||s.attempts<=0)return m;const p=R=>{const I=R.edges.reduce((L,$,B)=>L+(l[B].visible===false?0:$.points.length),0);if(I>2048||I*I>s.scorePairs)return void 0;s.scorePairs-=I*I;return Or(R.edges.map((L,$)=>({...L,visible:l[$].visible})))};let g=p(m);if(g===void 0||g===0)return m;const y=R=>R.edges.reduce((I,L,$)=>I+(l[$].visible===false?0:Math.max(0,L.points.length-2)),0);let w=y(m),S=m.width*m.height;const x=(R,I,L)=>l.map($=>R[$.source]>R[$.target]?1:0).join("")+":"+I+":"+L;let M=e.compactPrivateRanks&&a.length>16?2:12;const b=new Set([x(h,false,false)]);const C=a.length<=12?a.map((R,I)=>I):a.length<=20?[0,Math.floor(a.length/4),Math.floor(a.length/2),Math.floor(3*a.length/4),a.length-1]:[];const P=C.flatMap(R=>{const I=_=>(_-R+a.length)%a.length;const L=l.map(_=>({..._,source:I(_.source),target:I(_.target)}));const $=n.slice(R).concat(n.slice(0,R)),B=t.slice(R).concat(t.slice(0,R));const F=X0($,L),z=dc(B,$,L);return[Uint32Array.from(a,(_,H)=>F[I(H)]),Uint32Array.from(a,(_,H)=>z[I(H)])]});const E=e.compactPrivateRanks&&a.length>16;const k=E&&u(h)<=3?eI(e,s,3):[];k.sort((R,I)=>I.span-R.span);const v=k.length>1?[k[0].order,k.at(-1).order,...k.slice(1,-1).map(R=>R.order)]:k.map(R=>R.order);const T=[...v,c,d,...P,Uint32Array.from(a,(R,I)=>I)];const A=k.length?[[false,false],[true,true],[true,false],[false,true]]:[[true,true],[true,false],[false,true],[false,false]];for(let R=0;R<T.length*A.length;R++){const I=T[E?R%T.length:Math.floor(R/A.length)];const[L,$]=A[E?Math.floor(R/T.length):R%A.length];const B=x(I,L,$);if(b.has(B))continue;b.add(B);if(M--<=0||s.attempts--<=0||s.routing.pairs<0||s.routing.arcs<0||s.routing.swaps<0)return m;try{const F=f(I,D=>{throw new ry(D)},s.routing,L,$);const z=p(F);if(z===void 0)return m;const _=y(F),H=F.width*F.height;if(z<g||z===g&&(_<w||_===w&&H<S)){m=F;g=z;w=_;S=H}if(g===0)return m}catch(F){if(!(F instanceof ry))throw F}}return m}function nI(e,t,n,i,r){let o=e.groups;const s=e.nodes.length;const a=s+o.length;const l=new Int32Array(a).fill(-1);const c=Array.from({length:o.length+1},()=>[]);const d=Array.from({length:o.length+1},()=>[]);const u=new Map;let f;const h=new Set;for(let E=0;E<a;E++){const k=E<s?e.nodes[E]:o[E-s];if(h.has(k.id))throw new TypeError("Measured compound identities must be unique");h.add(k.id);if(k.modelOrder!==void 0&&(!Number.isSafeInteger(k.modelOrder)||k.modelOrder<0))throw new TypeError("Invalid measured model order");if(k.partition!==void 0&&(!Number.isSafeInteger(k.partition)||k.partition<0||k.partition>1e4))throw new TypeError("Invalid measured partition");const v=k.parent??-1;if(!Number.isInteger(v)||v<-1||v>=o.length||v>=0&&E===s+v)throw new TypeError("Invalid measured compound parent");if(E<s){const T=e.nodes[E];if(![T.width,T.height].every(A=>Number.isFinite(A)&&A>0))throw new TypeError("Invalid measured compound leaf dimensions")}l[E]=v;c[v+1].push(E)}for(let E=0;E<o.length;E++){const k=new Set;for(let T=E;T>=0;T=l[s+T]){if(k.has(T))throw new TypeError("Measured compound parents must be acyclic");k.add(T);if(k.size>64)n("agentic local compound-depth limit")}const v=o[E];if(v.direction!==void 0&&!["TD","TB","BT","LR","RL"].includes(v.direction))throw new TypeError("Invalid measured compound direction");if(![v.minWidth,...Object.values(v.padding)].every(T=>Number.isFinite(T)&&T>=0))throw new TypeError("Invalid measured compound dimensions");if(v.headerHeight!==void 0&&(!Number.isFinite(v.headerHeight)||v.headerHeight<0||v.headerHeight>v.padding.top))throw new TypeError("Invalid measured compound header")}for(let E=0;E<e.edges.length;E++){const k=e.edges[E];if(!Number.isInteger(k.source)||!Number.isInteger(k.target)||k.source<0||k.target<0||k.source>=a||k.target>=a)throw new TypeError("Invalid measured compound endpoint");if(!Number.isSafeInteger(k.minSpan)||k.minSpan<1||k.label&&![k.label.width,k.label.height].every(T=>Number.isFinite(T)&&T>=0))throw new TypeError("Invalid measured compound edge dimensions");if(k.short!==void 0&&k.short!==true)throw new TypeError("Invalid measured short-edge preference");if(k.boundaryMarker!==void 0&&![k.boundaryMarker.inset,k.boundaryMarker.height].every(T=>Number.isFinite(T)&&T>=0))throw new TypeError("Invalid measured ancestor marker dimensions");let v=l[k.source];if(v!==l[k.target]){const T=new Set([-1]);for(let L=v;L>=0;L=l[s+L])T.add(L);v=l[k.target];while(!T.has(v))v=l[s+v];const A=L=>{while(l[L]!==v)L=s+l[L];return L};const R=A(k.source),I=A(k.target);if(R===I){(f??=[]).push(E);continue}u.set(E,{source:R,target:I,host:v})}d[v+1].push(E)}const m=f?HA(e,l,r,n):void 0;if(m){if(f.some(E=>!m.connections.has(E)))throw new TypeError("Ancestor planner lost an authored endpoint occurrence");o=m.groups}const p=new Array(o.length+1);let g=0;const y=(E,k)=>{const v=o[E-1];const T=v?.direction??k;const A=c[E],R=new Map(A.map((H,D)=>[H,D]));const I=A.map(H=>{if(H<s){const{id:j,width:W,height:O,partition:N,modelOrder:G,minimumPortSpacing:Y}=e.nodes[H];return{id:j,width:W,height:O,partition:N,modelOrder:G,...Y!==void 0?{minimumPortSpacing:Y}:{}}}const D=y(H-s+1,T);return{id:o[H-s].id,width:D.width,height:D.height,partition:o[H-s].partition,modelOrder:o[H-s].modelOrder}});const L=d[E].map(H=>{const D=e.edges[H];const j=u.get(H)??D;return{...D,source:R.get(j.source),target:R.get(j.target)}});const $={nodes:I,edges:L,padding:0,direction:T,nodeSpacing:e.nodeSpacing,layerSpacing:e.layerSpacing,edgeSpacing:e.edgeSpacing,...e.minimumTerminalLead!==void 0?{minimumTerminalLead:e.minimumTerminalLead}:{},...e.placementOnly?{placementOnly:true}:{}};if(u.size&&d[E].some(H=>u.has(H)))$.compactPrivateRanks=true;const B=t($);g+=B.expandedVertices??I.length;if(g>i)n("agentic local compound-expansion limit");const F=v?.padding??{top:e.padding,right:e.padding,bottom:e.padding,left:e.padding};const z=Math.max(v?.minWidth??0,B.width+F.left+F.right,1);const _={direction:T,placed:B,width:z,height:Math.max(B.height+F.top+F.bottom,1),dx:F.left+(z-B.width-F.left-F.right)/2,dy:F.top};if(!Number.isFinite(_.width+_.height+_.dx+_.dy))n("agentic local coordinate-range limit");p[E]=_;return _};const w=y(0,e.direction);const S=new Array(s);const x=new Array(o.length);const M=new Array(e.edges.length);const b=(E,k,v)=>{const T=p[E],A=k+T.dx,R=v+T.dy;c[E].forEach((I,L)=>{const $=T.placed.nodes[L],B={x:$.x+A,y:$.y+R};if(I<s)S[I]=B;else{const F=I-s,z=p[F+1];x[F]={...B,width:z.width,height:z.height};b(F+1,B.x,B.y)}});d[E].forEach((I,L)=>{const $=T.placed.edges[L];M[I]={points:$.points.map(B=>({x:B.x+A,y:B.y+R})),...$.labelPosition?{labelPosition:{x:$.labelPosition.x+A,y:$.labelPosition.y+R}}:{}}})};b(0,0,0);if(m)for(const E of m.connections.keys())M[E]=jA(m,E,x,k=>{if(!Number.isSafeInteger(k)||k<0)throw new TypeError("Invalid ancestor placeholder reservation");if(g+k>i)n("agentic local compound-expansion limit");g+=k});const C={topology:"layered",width:w.width,height:w.height,nodes:S,groups:x,edges:M,expandedVertices:g};let P=false;if(e.maximumEdgeStrokeWidth!==void 0)for(const E of e.edges){if(--r.pairs<0)n("agentic marker metadata work limit");if(E.markerPaint?.start?.length||E.markerPaint?.end?.length){P=true;break}}if(e.placementOnly)return C;if(!u.size&&!m&&!P){if(e.maximumEdgeStrokeWidth!==void 0&&e.maximumEdgeBendRadius===0){if(--r.arcs<0)n("agentic local cross-hierarchy visibility-arc limit");if(--r.pairs<0)n("agentic local cross-hierarchy crossing-work limit");lh(e,C,new Set,r,n)}return C}return VA(e,C,l,u,p.map(E=>E.direction),r,i,n,m)}function iI(e,t,n,i,r,o,s){const a=.01;const l=e.filter(v=>Math.abs(v.sourceCross-v.targetCross)>a);if(!l.length)return t;r.pairs-=l.length*e.length;if(r.pairs<0)o("agentic local channel-pair limit");const c=v=>Math.min(v.sourceCross,v.targetCross);const d=v=>Math.max(v.sourceCross,v.targetCross);const u=(v,T)=>Math.min(d(v),d(T))>=Math.max(c(v),c(T))-.5;const f=(v,T)=>v>=c(T)-a&&v<=d(T)+a;const h=l.map(()=>[]),m=l.map(()=>[]);const p=[];const g=(v,T)=>{if(--r.arcs<0)o("agentic local channel-constraint limit");const A=p.length;p.push({source:v,target:T,minSpan:1});m[v].push(A);h[T].push(A)};for(let v=0;v<l.length;v++)for(let T=v+1;T<l.length;T++){const A=l[v],R=l[T];if(!u(A,R))continue;if(f(R.sourceCross,A)&&Math.abs(R.sourceCross-A.sourceCross)>a)g(T,v);if(f(R.targetCross,A)&&Math.abs(R.targetCross-A.targetCross)>a)g(v,T);if(f(A.sourceCross,R)&&Math.abs(A.sourceCross-R.sourceCross)>a)g(v,T);if(f(A.targetCross,R)&&Math.abs(A.targetCross-R.targetCross)>a)g(T,v)}const y=dc(h,m,p);const w=l.map((v,T)=>T).sort((v,T)=>y[v]-y[T]||v-T);let S=0;for(let v=0;v<w.length;v++){const T=l[w[v]];for(let A=0;A<v;A++){const R=l[w[A]];if(u(T,R))T.track=Math.max(T.track,R.track+1)}S=Math.max(S,T.track)}let x=false;const M=Math.max(1,Math.min(2,n/2));const b=e.flatMap(v=>[v.sourceCross,v.targetCross]).sort((v,T)=>v-T);for(const v of l){if(!e.some(L=>L!==v&&Math.abs(L.sourceCross-v.targetCross)<=.5&&(Math.abs(L.sourceCross-L.targetCross)<=a||L.track>=v.track)))continue;let T=v.targetCross-n,A=v.targetCross+n;for(let L=b.length-1;L>=0;L--){const $=b[L];if(Math.abs($-T)<M)T=$-M}for(const L of b)if(Math.abs(L-A)<M)A=L+M;const R=T>=0?v.targetCross-T:Infinity;const I=A<=i?A-v.targetCross:Infinity;if(!Number.isFinite(Math.min(R,I)))o("agentic local channel-terminal clearance");v.targetEscape=I<R||I===R&&v.sourceCross>v.targetCross?A:T;x=true}const C=Math.max(12,n,s??0);const P=2*C+S*n+(x?n:0);const E=Math.max(t,P),k=(E-P)/2;for(const v of e){v.offset=C+k+v.track*n;if(v.targetEscape!==void 0)v.targetExit=E-C}return E}var U0=4096;var rI=16384;var oy=32768;var K3=4;var J3=8;function kr(e,t){return Number.isFinite(e)&&(t?e>0:e>=0)}function uc(e,t,n,i={pairs:1e6,arcs:65536,swaps:1e6},r={attempts:128,scorePairs:8e6,loopPairs:2e6,rankPairs:2e5,blockPairs:2e6,routing:{pairs:5e5,arcs:32768,swaps:5e5}}){const{nodes:o,edges:s,padding:a,nodeSpacing:l,layerSpacing:c}=e;if(o.length>U0||s.length>rI)n("agentic local graph-size limit");if(![a,l,c].every(fe=>kr(fe,false))){throw new TypeError("Measured graph spacing must be finite and nonnegative")}if(e.edgeSpacing!==void 0&&!kr(e.edgeSpacing,true))throw new TypeError("Measured edge spacing must be finite and positive");if(e.minimumTerminalLead!==void 0&&!kr(e.minimumTerminalLead,true))throw new TypeError("Measured terminal lead must be finite and positive");if(e.maximumEdgeStrokeWidth!==void 0&&!kr(e.maximumEdgeStrokeWidth,true))throw new TypeError("Measured maximum edge stroke width must be finite and positive");if(e.maximumEdgeBendRadius!==void 0&&!kr(e.maximumEdgeBendRadius,false))throw new TypeError("Invalid measured edge bend radius");for(const fe of e.nodes)if(fe.paintStrokeWidth!==void 0&&!kr(fe.paintStrokeWidth,true))throw new TypeError("Invalid measured node paint stroke");for(const fe of e.nodes)if(fe.paintCornerRadius!==void 0&&!kr(fe.paintCornerRadius,false))throw new TypeError("Invalid measured node corner radius");for(const fe of e.nodes)if(fe.minimumPortSpacing!==void 0&&!kr(fe.minimumPortSpacing,true))throw new TypeError("Invalid measured node port spacing");for(const fe of e.groups??[])if(fe.paintStrokeWidth!==void 0&&!kr(fe.paintStrokeWidth,true))throw new TypeError("Invalid measured group paint stroke");for(const fe of e.groups??[])if(fe.paintCornerRadius!==void 0&&!kr(fe.paintCornerRadius,false))throw new TypeError("Invalid measured group corner radius");for(const fe of e.edges)if(fe.markerPaint!==void 0)AA(fe.markerPaint);if(!["TD","TB","BT","LR","RL"].includes(e.direction))throw new TypeError("Invalid measured graph direction");if(e.groups?.length){if(o.length+e.groups.length>U0)n("agentic local compound-size limit");return nI(e,fe=>uc(fe,t,n,i,r),n,oy,i)}const d=e.direction==="LR"||e.direction==="RL";const u=e.direction==="BT"||e.direction==="RL";const f=new Set;let h=false;for(const fe of o){if(fe.parent!==void 0)throw new TypeError("Measured parent requires a compound scope");if(fe.modelOrder!==void 0){if(!Number.isSafeInteger(fe.modelOrder)||fe.modelOrder<0)throw new TypeError("Invalid measured model order");h=true}if(fe.partition!==void 0&&(!Number.isSafeInteger(fe.partition)||fe.partition<0||fe.partition>1e4))throw new TypeError("Invalid measured partition");if(f.has(fe.id))throw new TypeError("Measured graph node identities must be unique");f.add(fe.id);if(!kr(fe.width,true)||!kr(fe.height,true))throw new TypeError("Measured node dimensions must be finite and positive")}const m=o.map(()=>[]);const p=o.map(()=>[]);const g=new Uint32Array(o.length);let y=false,w=false;for(let fe=0;fe<s.length;fe++){const me=s[fe];if(!Number.isInteger(me.source)||!Number.isInteger(me.target)||me.source<0||me.source>=o.length||me.target<0||me.target>=o.length){throw new TypeError("Measured edge endpoint is outside the node array")}if(!Number.isSafeInteger(me.minSpan)||me.minSpan<1)throw new TypeError("Measured edge minimum span must be a positive integer");if(me.short!==void 0&&me.short!==true)throw new TypeError("Invalid measured short-edge preference");if(me.boundaryMarker!==void 0&&![me.boundaryMarker.inset,me.boundaryMarker.height].every(de=>Number.isFinite(de)&&de>=0))throw new TypeError("Invalid measured ancestor marker dimensions");w||=me.short===true;if(me.label&&(!kr(me.label.width,false)||!kr(me.label.height,false))){throw new TypeError("Measured edge label dimensions must be finite and nonnegative")}if(me.source===me.target){y=true;continue}p[me.source].push(fe);m[me.target].push(fe);g[me.target]=g[me.target]+1}const S=o.some(fe=>(fe.partition??0)!==(o[0]?.partition??0));if(S&&s.some(fe=>(o[fe.source].partition??0)>(o[fe.target].partition??0))){const fe=s.map(de=>(o[de.source].partition??0)>(o[de.target].partition??0));const me=uc({...e,edges:s.map((de,be)=>fe[be]?{...de,source:de.target,target:de.source}:de)},t,n,i,r);return{...me,edges:me.edges.map((de,be)=>fe[be]?{...de,points:[...de.points].reverse()}:de)}}if(y){const fe=[...o],me=[...s];const de=[...e.loopPorts??[]];const be=new Int32Array(s.length).fill(-1);let pe=0;for(let J=0;J<s.length;J++){const ge=s[J];if(ge.source!==ge.target)continue;if(fe.length===U0||me.length===rI)n("agentic local loop-expansion limit");let Ce;do{Ce=`\0agentic-loop:${pe++}`}while(f.has(Ce));f.add(Ce);const Me=fe.length;fe.push({id:Ce,width:d?1:40,height:d?40:1,...S?{partition:o[ge.source].partition??0}:{}});me[J]={...ge,target:Me,...ge.label?{label:d?{width:ge.label.width,height:2*ge.label.height+8}:{width:2*ge.label.width+8,height:ge.label.height}}:{}};be[J]=me.length;de.push([J,me.length]);me.push({source:ge.source,target:Me,minSpan:ge.minSpan})}const Re=uc({...e,nodes:fe,edges:me,loopPorts:de},t,n,i,r);const Ne={...Re,topology:"layered",nodes:Re.nodes.slice(0,o.length),edges:Re.edges.slice(0,s.length).map((J,ge)=>{const Ce=be[ge];if(Ce<0)return J;const Me=Re.edges[Ce].points;let le=J.labelPosition;if(le&&s[ge].label){const we=d?le.x:le.y,ke=d?le.y:le.x;let Le=-1;for(let Oe=1;Oe<Me.length;Oe++){const We=Me[Oe-1],ce=Me[Oe];const Ae=d?We.x:We.y,Pe=d?ce.x:ce.y;const He=d?We.y:We.x,je=d?ce.y:ce.x;if(He===je&&we>=Math.min(Ae,Pe)&&we<=Math.max(Ae,Pe)){Le=ke<He?-1:1;break}}const Fe=((d?s[ge].label.height:s[ge].label.width)/2+4)*Le;le=d?{x:le.x,y:le.y+Fe}:{x:le.x+Fe,y:le.y}}return{...J,...le?{labelPosition:le}:{},points:J.points.concat([...Me].reverse())}})};return QA(e,Ne,r)}const x=!S&&!h&&!w&&ZA(e,m,p,n);if(x)return x;const M=!S&&!h&&!w&&t(e);if(M)return{...M,expandedVertices:o.length};const b=new Uint32Array(o.length);const C=o.flatMap((fe,me)=>g[me]===0?[me]:[]);let P=0;for(let fe=0;fe<C.length;fe++){const me=C[fe];for(const de of p[me]){const be=s[de];const pe=b[me]+ho(be,e.compactPrivateRanks);if(pe>=q0)n("agentic local rank-expansion limit");b[be.target]=Math.max(b[be.target],pe);P=Math.max(P,pe);g[be.target]=g[be.target]-1;if(g[be.target]===0)C.push(be.target)}}if(C.length!==o.length){if(S){const fe=e.authoredCycleOrder?Uint32Array.from(o,(be,pe)=>pe):dc(m,p,s);const me=s.map(be=>(o[be.source].partition??0)===(o[be.target].partition??0)&&fe[be.source]>fe[be.target]);const de=uc({...e,cycleOriented:true,edges:s.map((be,pe)=>me[pe]?{...be,source:be.target,target:be.source}:be)},t,n,i,r);return{...de,edges:de.edges.map((be,pe)=>me[pe]?{...be,points:[...be.points].reverse()}:be)}}return tI(e,m,p,(fe,me,de)=>uc(fe,t,me,de,r),n,i,r)}const E=w?new Uint32Array(o.length):void 0;const k=w?new Uint32Array(o.length):void 0;if(w)for(const fe of s){const me=fe.short?100:1;E[fe.target]=E[fe.target]+me;k[fe.source]=k[fe.source]+me}for(let fe=0;!S&&fe<4;fe++){let me=false;for(const de of[true,false]){for(let be=0;be<C.length;be++){const pe=C[de?C.length-1-be:be];let Re=0,Ne=P;for(const Ce of m[pe]){const Me=s[Ce];Re=Math.max(Re,b[Me.source]+ho(Me,e.compactPrivateRanks))}for(const Ce of p[pe]){const Me=s[Ce];Ne=Math.min(Ne,b[Me.target]-ho(Me,e.compactPrivateRanks))}const J=w?k[pe]>=E[pe]:p[pe].length>=m[pe].length;const ge=p[pe].length&&J?Ne:Re;if(ge!==b[pe]){b[pe]=ge;me=true}}}if(!me)break}if(S){const fe=new Map;for(const de of C){const be=o[de].partition??0;const pe=fe.get(be)??[];pe.push(de);fe.set(be,pe)}let me=0;for(const de of[...fe.keys()].sort((be,pe)=>be-pe)){let be=me;for(const pe of fe.get(de)){let Re=me;for(const Ne of m[pe]){const J=s[Ne];Re=Math.max(Re,b[J.source]+ho(J,e.compactPrivateRanks))}if(Re>=q0)n("agentic local rank-expansion limit");b[pe]=Re;be=Math.max(be,Re)}me=be+1}}if(S&&w){const fe=new Map;for(const[me,de]of o.entries()){const be=de.partition??0,pe=fe.get(be);if(pe){pe.lower=Math.min(pe.lower,b[me]);pe.upper=Math.max(pe.upper,b[me])}else fe.set(be,{lower:b[me],upper:b[me]})}for(let me=0;me<4;me++){let de=false;for(const be of[true,false])for(let pe=0;pe<C.length;pe++){const Re=C[be?C.length-1-pe:pe],Ne=fe.get(o[Re].partition??0);let J=Ne.lower,ge=Ne.upper;for(const Me of m[Re]){const le=s[Me];J=Math.max(J,b[le.source]+ho(le,e.compactPrivateRanks))}for(const Me of p[Re]){const le=s[Me];ge=Math.min(ge,b[le.target]-ho(le,e.compactPrivateRanks))}const Ce=p[Re].length&&k[Re]>=E[Re]?ge:J;if(Ce!==b[Re]){b[Re]=Ce;de=true}}if(!de)break}}const v=!S&&JA(e,r,w);if(v)b.set(v);P=b.reduce((fe,me)=>Math.max(fe,me),0);let T=o.length;for(const fe of s){T+=b[fe.target]-b[fe.source]-1;if(T>oy)n("agentic local expanded-graph limit")}if(o.length===0){if(!Number.isFinite(2*a))n("agentic local coordinate-range limit");return{topology:"layered",width:2*a,height:2*a,nodes:[],edges:[],expandedVertices:0}}const A=o.map((fe,me)=>({rank:b[me],crossSize:d?fe.height:fe.width,mainSize:d?fe.width:fe.height,incoming:[],outgoing:[]}));const R=[];const I=[];for(let fe=0;fe<s.length;fe++){const me=s[fe];const de=[me.source];const be=me.label?Math.floor((b[me.source]+b[me.target])/2):-1;for(let pe=b[me.source]+1;pe<b[me.target];pe++){const Re=pe===be;const Ne=A.length;A.push({rank:pe,crossSize:Re?(d?me.label.height:me.label.width)+2*J3:4,mainSize:Re?d?me.label.width:me.label.height:0,incoming:[],outgoing:[]});if(Re)I[fe]=Ne;de.push(Ne)}de.push(me.target);for(let pe=1;pe<de.length;pe++){const Re=de[pe-1],Ne=de[pe];A[Re].outgoing.push(Ne);A[Ne].incoming.push(Re)}R.push(de)}const L=Array.from({length:P+1},()=>[]);const $=new Float64Array(L.length);const B=new Float64Array(L.length);for(let fe=0;fe<A.length;fe++)L[A[fe].rank].push(fe);const F=h?fe=>{const me=fe.filter(be=>o[be]?.modelOrder!==void 0);me.sort((be,pe)=>o[be].modelOrder-o[pe].modelOrder);let de=0;for(let be=0;be<fe.length;be++)if(o[fe[be]]?.modelOrder!==void 0)fe[be]=me[de++]}:void 0;if(F)for(const fe of L)F(fe);let z=0;for(let fe=0;fe<L.length;fe++){const me=L[fe];let de=Math.max(0,me.length-1)*l;for(const be of me){const pe=A[be];de+=pe.crossSize;B[fe]=Math.max(B[fe],pe.mainSize)}$[fe]=de;z=Math.max(z,de)}const _=new Float64Array(A.length);const H=fe=>{let me=(z-$[fe])/2;const de=L[fe];for(let be=0;be<de.length;be++){const pe=de[be];const Re=A[pe].crossSize;_[pe]=me+Re/2;me+=Re+l}};for(let fe=0;fe<L.length;fe++)H(fe);const D=new Float64Array(A.length);const j=(fe,me)=>{const de=L[fe];let be=true;for(let pe=0;pe<de.length;pe++){const Re=de[pe];const Ne=me?A[Re].incoming:A[Re].outgoing;let J=0;for(let Ce=0;Ce<Ne.length;Ce++)J+=_[Ne[Ce]];const ge=Ne.length?J/Ne.length:_[Re];D[Re]=ge;be&&=Number.isFinite(ge)}if(de.length<=16&&be){for(let pe=1;pe<de.length;pe++){const Re=de[pe],Ne=D[Re];let J=pe;while(J>0){const ge=de[J-1];if((D[ge]-Ne||ge-Re)<=0)break;de[J--]=ge}de[J]=Re}}else de.sort((pe,Re)=>D[pe]-D[Re]||pe-Re);F?.(de);H(fe)};const W=new Uint32Array(A.length);const O=L.slice(1).map(fe=>new Uint32Array(fe.length+1));const N=()=>{for(let fe=0;fe<L.length;fe++){const me=L[fe];for(let de=0;de<me.length;de++)W[me[de]]=de}};const G=()=>{N();let fe=0;for(let me=0;me+1<L.length;me++){const de=O[me];de.fill(0);let be=0;const pe=L[me];for(let Re=0;Re<pe.length;Re++){const Ne=A[pe[Re]].outgoing;for(let J=0;J<Ne.length;J++){const ge=Ne[J];let Ce=0;for(let Me=W[ge]+1;Me>0;Me-=Me&-Me)Ce+=de[Me];fe+=be-Ce}for(let J=0;J<Ne.length;J++){for(let ge=W[Ne[J]]+1;ge<de.length;ge+=ge&-ge)de[ge]=de[ge]+1}be+=Ne.length}}return fe};let Y=G(),q=L.map(fe=>[...fe]);const V=()=>{const fe=G();if(fe<Y){Y=fe;q=L.map(me=>[...me])}};for(let fe=0;fe<K3;fe++){for(let me=1;me<L.length;me++)j(me,true);V();for(let me=L.length-2;me>=0;me--)j(me,false);V()}q.forEach((fe,me)=>{L[me]=fe;fe.forEach((de,be)=>{W[de]=be})});const ne=()=>{N();for(let fe=0;fe<4;fe++){let me=false;for(let de=0;de<L.length;de++){const be=L[de];for(let pe=0;pe+1<be.length;pe++){if(h&&o[be[pe]]?.modelOrder!==void 0&&o[be[pe+1]]?.modelOrder!==void 0)continue;const Re=A[be[pe]],Ne=A[be[pe+1]];const J=Re.incoming.length*Ne.incoming.length+Re.outgoing.length*Ne.outgoing.length;if(J>i.swaps)continue;i.swaps-=J;let ge=0;for(let Ce=0;Ce<Re.incoming.length;Ce++)for(let Me=0;Me<Ne.incoming.length;Me++)ge+=Math.sign(W[Re.incoming[Ce]]-W[Ne.incoming[Me]]);for(let Ce=0;Ce<Re.outgoing.length;Ce++)for(let Me=0;Me<Ne.outgoing.length;Me++)ge+=Math.sign(W[Re.outgoing[Ce]]-W[Ne.outgoing[Me]]);if(ge>0){const Ce=be[pe],Me=be[pe+1];be[pe]=Me;be[pe+1]=Ce;W[Ce]=pe+1;W[Me]=pe;me=true}}}if(!me)break}};ne();if(e.compactPrivateRanks&&o.length<=20&&s.length<=64&&A.length<=256){let fe=G(),me=128;const de=R.map(be=>be.slice(1,-1)).filter(be=>be.length>1).sort((be,pe)=>pe.length-be.length);for(const be of de){if(fe===0)break;const pe=new Map(be.map(ge=>[A[ge].rank,[...L[A[ge].rank]]]));let Re=fe,Ne,J=false;for(const ge of[0,1,.25,.5,.75]){const Ce=L.length+A.length+16*(A.length-o.length+s.length);if(me--<=0||(r.blockPairs??2e6)<Ce){J=true;break}r.blockPairs=(r.blockPairs??2e6)-Ce;for(const le of be){const we=A[le].rank,ke=L[we],Le=pe.get(we);for(let We=0;We<ke.length;We++)ke[We]=Le[We];const Fe=ke.indexOf(le),Oe=Math.floor((ke.length-1)*ge);if(Fe<Oe)for(let We=Fe;We<Oe;We++)ke[We]=ke[We+1];else for(let We=Fe;We>Oe;We--)ke[We]=ke[We-1];ke[Oe]=le}const Me=G();if(Me<Re){Re=Me;Ne=new Map([...pe].map(([le])=>[le,[...L[le]]]))}}for(const[ge,Ce]of Ne??pe)L[ge]=Ce;fe=Re;if(J)break}}if(e.compactPrivateRanks&&o.length>12&&o.length<=20&&s.length<=64&&A.length<=256){KA(L,A,R,r)}if(e.compactPrivateRanks&&!e.cycleOriented)ne();for(let fe=0;fe<L.length;fe++)H(fe);const X=new Int32Array(A.length).fill(-1),U=new Int32Array(A.length).fill(-1);for(const fe of L){let me=-1;for(const de of fe){X[de]=me;if(de<o.length)me=de}me=-1;for(let de=fe.length-1;de>=0;de--){const be=fe[de];U[be]=me;if(be<o.length)me=be}}let K=new Float64Array(0);const Z=Math.min(4,l);for(let fe=0;fe<4;fe++)for(const me of[true,false]){for(let de=0;de<L.length;de++){const be=L[me?de:L.length-1-de];for(let pe=0;pe<be.length;pe++){const Re=me?pe:be.length-1-pe,Ne=be[Re],J=A[Ne];const ge=J.incoming.length+J.outgoing.length;if(!ge)continue;let Ce;if(ge<=2){const Le=J.incoming[0]??J.outgoing[0];const Fe=ge===1?Le:J.incoming.length===2?J.incoming[1]:J.outgoing[J.incoming.length===1?0:1];const Oe=_[Le],We=_[Fe];Ce=me?Math.min(Oe,We):Math.max(Oe,We)}else{if(K.length<ge)K=new Float64Array(ge);const Le=K.subarray(0,ge);let Fe=0,Oe=true;for(let ce=0;ce<J.incoming.length;ce++){const Ae=_[J.incoming[ce]];Le[Fe++]=Ae;Oe&&=Number.isFinite(Ae)&&!Object.is(Ae,-0)}for(let ce=0;ce<J.outgoing.length;ce++){const Ae=_[J.outgoing[ce]];Le[Fe++]=Ae;Oe&&=Number.isFinite(Ae)&&!Object.is(Ae,-0)}const We=Oe?Le.sort():Array.from(Le).sort((ce,Ae)=>ce-Ae);Ce=We[Math.floor((ge-Number(me))/2)]}const Me=be[Re-1],le=be[Re+1];let we=Me===void 0?J.crossSize/2:_[Me]+(A[Me].crossSize+J.crossSize)/2+Z;let ke=le===void 0?z-J.crossSize/2:_[le]-(A[le].crossSize+J.crossSize)/2-Z;if(Ne<o.length){const Le=X[Ne],Fe=U[Ne];if(Le>=0)we=Math.max(we,_[Le]+(A[Le].crossSize+J.crossSize)/2+l);if(Fe>=0)ke=Math.min(ke,_[Fe]-(A[Fe].crossSize+J.crossSize)/2-l)}if(we<=ke)_[Ne]=Math.max(we,Math.min(ke,Ce))}}}const Q=new Uint32Array(A.length);for(const fe of L)fe.forEach((me,de)=>{Q[me]=de});const se=Math.min(4,l);for(const fe of R){if(fe.length<4)continue;let me=1;while(me<fe.length-1){let de=-Infinity,be=Infinity,pe=me;while(pe<fe.length-1){const Re=fe[pe],Ne=A[Re],J=L[Ne.rank],ge=Q[Re];const Ce=J[ge-1],Me=J[ge+1];const le=Ce===void 0?Ne.crossSize/2:_[Ce]+(A[Ce].crossSize+Ne.crossSize)/2+se;const we=Me===void 0?z-Ne.crossSize/2:_[Me]-(A[Me].crossSize+Ne.crossSize)/2-se;const ke=Math.max(de,le),Le=Math.min(be,we);if(ke>Le)break;de=ke;be=Le;pe++}if(pe>me+1){const Re=(_[fe[me-1]]+_[fe[pe]])/2;const Ne=Math.max(de,Math.min(be,Re));for(let J=me;J<pe;J++)_[fe[J]]=Ne}me=Math.max(me+1,pe)}}const te=new Float64Array(s.length),ee=new Float64Array(s.length);const ae=new Map;for(const fe of e.loopPorts??[]){const me=s[fe[0]],de=s[fe[1]];if(!me||!de||me.source!==de.source)throw new TypeError("Invalid measured loop port pair");const be=ae.get(me.source)??[];be.push(fe);ae.set(me.source,be)}for(let fe=0;fe<o.length;fe++){const me=A[fe].crossSize;const de=(be,pe)=>{const Re=[...be].sort((Ce,Me)=>{const le=R[Ce],we=R[Me];const ke=pe?le[1]:le[le.length-2];const Le=pe?we[1]:we[we.length-2];return _[ke]-_[Le]||Ce-Me});const Ne=pe?ae.get(fe):void 0;if(Ne?.length){const Ce=new Map(Re.map((le,we)=>[le,we]));const Me=Ne.map(([le,we])=>[Math.min(Ce.get(le),Ce.get(we)),Math.max(Ce.get(le),Ce.get(we))]);if(Me.some(([le,we])=>me*(we-le)/(Re.length+1)<8)){const le=new Float64Array(Re.length);const we=new Map;for(const[Fe,Oe]of Me){const We=we.get(Oe)??[];We.push(Fe);we.set(Oe,We)}for(let Fe=0;Fe<Re.length;Fe++){le[Fe]=Fe?le[Fe-1]+2:0;for(const Oe of we.get(Fe)??[])le[Fe]=Math.max(le[Fe],le[Oe]+8)}const ke=Math.min(8,me/6);const Le=me-2*ke-(le.at(-1)??0);if(Le<0)n("agentic local loop-attachment capacity");Re.forEach((Fe,Oe)=>{te[Fe]=_[fe]-me/2+ke+le[Oe]+Le*(Oe+1)/(Re.length+1)});return}}if(o[fe].minimumPortSpacing!==void 0){i.pairs-=3;if(i.pairs<0)n("agentic node port-spacing work limit")}const J=Math.min(8,me/6),ge=Math.max(8,o[fe].minimumPortSpacing??8);if(!Ne?.length&&me-2*J>=(Re.length-1)*ge){const Ce=_[fe]-me/2+J,Me=_[fe]+me/2-J;const le=Re.map((we,ke)=>{const Le=R[we],Fe=pe?Le[1]:Le[Le.length-2];return Math.max(Ce+ke*ge,Math.min(Me-(Re.length-1-ke)*ge,_[Fe]))});for(let we=1;we<le.length;we++)le[we]=Math.max(le[we],le[we-1]+ge);Re.forEach((we,ke)=>{(pe?te:ee)[we]=le[ke]});return}for(let Ce=0;Ce<Re.length;Ce++){const Me=_[fe]-me/2+me*(Ce+1)/(Re.length+1);(pe?te:ee)[Re[Ce]]=Me}};de(p[fe],true);de(m[fe],false)}const ie=Math.max(4,c/2);const oe=Array.from({length:P},()=>[]);const ue=R.map((fe,me)=>fe.slice(1).map((de,be)=>{const pe=fe[be];const Re={sourceCross:be===0?te[me]:_[pe],targetCross:be===fe.length-2?ee[me]:_[de],offset:ie/2,track:0};oe[A[pe].rank].push(Re);return Re}));const ye=oe.map(fe=>{if(e.minimumTerminalLead!==void 0){i.pairs-=3;if(i.pairs<0)n("agentic terminal-lead work limit")}return iI(fe,ie,e.edgeSpacing??6,z,i,n,e.minimumTerminalLead)});const Se=new Float64Array(A.length);let Te=0;for(let fe=0;fe<L.length;fe++){for(const me of L[fe])Se[me]=Te+B[fe]/2;Te+=B[fe]+(ye[fe]??0)}if(!Number.isFinite(Te+z+2*a))n("agentic local coordinate-range limit");const Ie=(fe,me)=>{const de=a+(u?Te-me:me);return d?{x:de,y:a+fe}:{x:a+fe,y:de}};const Ee=o.map((fe,me)=>{const de=Ie(_[me],Se[me]);return{x:de.x-fe.width/2,y:de.y-fe.height/2}});const ve=(fe,me)=>{const de=A[me].crossSize,be=Math.min(8,de/6);const pe=d?Ee[me].y:Ee[me].x;if(fe===_[me]-de/2+be)return pe+be;if(fe===_[me]+de/2-be)return pe+de-be;return a+fe};const $e=(fe,me)=>{const de=Ee[fe],be=o[fe];return d?de.x+(me!==u?be.width:0):de.y+(me!==u?be.height:0)};const De=e.placementOnly&&!e.cycleOriented&&!e.loopPorts?.length?s.map(()=>({points:[]})):s.map((fe,me)=>{const de=R[me];const be=[];const pe=(J,ge,Ce,Me)=>{const le=Ie(J,ge);if(Ce!==void 0){if(d)le.y=Ce;else le.x=Ce}if(Me!==void 0){if(d)le.x=Me;else le.y=Me}const we=be.at(-1);if(we?.x===le.x&&we.y===le.y)return;const ke=be.at(-2);if(ke&&we&&(ke.x===we.x&&we.x===le.x&&(we.y-ke.y)*(le.y-we.y)>=0||ke.y===we.y&&we.y===le.y&&(we.x-ke.x)*(le.x-we.x)>=0))be.pop();be.push(le)};for(let J=1;J<de.length;J++){const ge=de[J-1],Ce=de[J];const Me=ue[me][J-1];const le=Me.sourceCross,we=Me.targetCross;const ke=Se[ge]+A[ge].mainSize/2;const Le=Se[Ce]-A[Ce].mainSize/2;const Fe=Se[ge]+B[A[ge].rank]/2;const Oe=Fe+Me.offset;const We=ge<o.length?ve(le,ge):void 0;const ce=Ce<o.length?ve(we,Ce):void 0;pe(le,ke,We,ge<o.length?$e(ge,true):void 0);pe(le,Oe,We);pe(Me.targetEscape??we,Oe,Me.targetEscape===void 0?ce:void 0);if(Me.targetEscape!==void 0){pe(Me.targetEscape,Fe+Me.targetExit);pe(we,Fe+Me.targetExit,ce)}pe(we,Le,ce,Ce<o.length?$e(Ce,false):void 0)}const Re=I[me];const Ne=Re===void 0?void 0:Ie(_[Re],Se[Re]);return{points:be,...Ne?{labelPosition:Ne}:{}}});return{topology:"layered",expandedVertices:A.length,width:2*a+(d?Te:z),height:2*a+(d?z:Te),nodes:Ee,edges:De}}function Q3(e){const t=[];for(const n of e){const i=t.at(-1),r=t.at(-2);if(i?.x===n.x&&i.y===n.y)continue;if(r&&i&&(r.x===i.x&&i.x===n.x&&(i.y-r.y)*(n.y-i.y)>=0||r.y===i.y&&i.y===n.y&&(i.x-r.x)*(n.x-i.x)>=0))t.pop();t.push(n)}return t}function oI(e,t){if(t.topology==="forest"||t.sharedEdges?.length||e.edges.length>128||t.edges.reduce((f,h)=>f+h.points.length,0)>2048)return t;const n=e.nodes.map((f,h)=>({...t.nodes[h],width:f.width,height:f.height}));const i=(t.groups??[]).map((f,h)=>({...f,height:e.groups[h].padding.top}));const r=e.edges.map((f,h)=>{const m=t.edges[h].labelPosition;return f.label&&m?{x:m.x-f.label.width/2-2,y:m.y-f.label.height/2-2,width:f.label.width+4,height:f.label.height+4}:void 0});const o=t.edges.map((f,h)=>({points:f.points,source:String(e.edges[h].source),target:String(e.edges[h].target),style:e.edges[h].visible===false?"invisible":"solid"}));const s=()=>o.map(f=>({points:f.points,visible:f.style!=="invisible"}));const a=f=>f.slice(1).reduce((h,m,p)=>h+Math.abs(m.x-f[p].x)+Math.abs(m.y-f[p].y),0);const l=(f,h)=>`${Math.sign(h.x-f.x)},${Math.sign(h.y-f.y)}`;let c=512,d=8e6;const u=f=>(d-=f)>=0;for(const[f,h]of e.edges.entries()){if(t.boundaryRoutes?.includes(f))continue;if(h.source===h.target||h.visible===false||o[f].points.length<5)continue;let m=24;const p=[...n,...i,...r.filter((w,S)=>Boolean(w)&&S!==f)];const g=new Set([f]);let y;for(let w=0;w<4;w++){const S=o[f].points,x=t.edges[f].labelPosition;const M=[...S];let b=-1;if(x){b=M.findIndex(E=>E.x===x.x&&E.y===x.y);if(b<0)for(let E=1;E<M.length;E++){if(Ji(x,M[E-1],M[E])){b=E;M.splice(E,0,{...x});break}}if(b<0)break}const C=[[0,M.length-1],...b>0&&b<M.length-1?[[0,b],[b,M.length-1]]:[]];let P=false;e:for(const[E,k]of C)for(let v=E;v+2<k;v++){for(let T=k;T>v+2;T--)for(const A of[false,true]){d-=M.length;if(d<0)return t;const R=M[v],I=M[T];const L=A?{x:I.x,y:R.y}:{x:R.x,y:I.y};const $=Q3([...M.slice(0,v+1),L,...M.slice(T)]);if($.length>=S.length||a($)>a(S)+1e-7||l($[0],$[1])!==l(S[0],S[1])||l($.at(-2),$.at(-1))!==l(S.at(-2),S.at(-1)))continue;d-=$.length*p.length;if(d<0)return t;if($.slice(1).some((H,D)=>p.some(j=>ci($[D],H,j))))continue;d-=$.length*o.reduce((H,D)=>H+D.points.length,0);if(d<0)return t;const B=o.reduce((H,D)=>H+D.points.length,0);if(m--<=0)break e;if(c--<=0)return t;d-=B*B;if(d<0)return t;const F=os($,f,o,e,u,u);if(d<0)return t;if(F===void 0)continue;let z=x,_=r[f];if(x&&h.label&&!$.slice(1).some((H,D)=>Ji(x,$[D],H))){const H=[];for(let D=1;D<$.length;D++){const j=$[D-1],W=$[D],O=j.y===W.y;const N=(O?h.label.width:h.label.height)/2+2;const G=Math.min(O?j.x:j.y,O?W.x:W.y)+N;const Y=Math.max(O?j.x:j.y,O?W.x:W.y)-N;if(G>Y)continue;const q=Math.max(G,Math.min(Y,O?x.x:x.y));H.push(O?{x:q,y:j.y}:{x:j.x,y:q});H.push({x:(j.x+W.x)/2,y:(j.y+W.y)/2})}H.sort((D,j)=>Math.abs(D.x-x.x)+Math.abs(D.y-x.y)-Math.abs(j.x-x.x)-Math.abs(j.y-x.y));z=void 0;for(const D of H){const j={x:D.x-h.label.width/2-2,y:D.y-h.label.height/2-2,width:h.label.width+4,height:h.label.height+4};d-=p.length+o.reduce((W,O)=>W+O.points.length,0);if(d<0)return t;if(j.x<0||j.y<0||j.x+j.width>t.width||j.y+j.height>t.height||p.some(W=>ey(j,W)))continue;if(o.some((W,O)=>O!==f&&W.style!=="invisible"&&W.points.slice(1).some((N,G)=>ci(W.points[G],N,j))))continue;z=D;_=j;break}if(!z)continue}y??=Or(s(),g);o[f].points=$;if(F>y){o[f].points=S;continue}t.edges[f].points=$;if(z)t.edges[f].labelPosition={...z};r[f]=_;y=F;P=true;break e}}if(!P)break}}return t}function sy(e,t,n,i,r,o){if(t.length>16||t.length+e.junctions.length+e.groups.length>24||n.length>32||e.alignments.length||e.edges.some(a=>a.label!==void 0||a.source.boundary==="group"||a.target.boundary==="group"))return n;let s=8;if(Or(n)!==1||o(n))return n;for(let a=0;a<t.length&&s>0;a++){const l=t[a];for(let c=a+1;c<t.length&&s>0;c++){const d=t[c];if(l.parentId!==d.parentId||l.width!==d.width||l.height!==d.height)continue;for(const u of["x","y"]){if(s<=0||l[u]===d[u])continue;s--;const f=l[u];l[u]=d[u];d[u]=f;if(r()){const h=i();if(Or(h)===0&&!o(h)&&h.every((m,p)=>m.obstacleFree&&(!n[p].sourceFacesTarget||m.sourceFacesTarget)&&(!n[p].targetFacesSource||m.targetFacesSource))){return h}}d[u]=l[u];l[u]=f}}}return n}var ay=class{#e=new Map;#t=0;#n;constructor(t){this.#n=t}get(t){const n=this.#e.get(t);if(!n)return void 0;this.#e.delete(t);this.#e.set(t,n);return n.value}set(t,n,i){if(i>this.#n)return;const r=this.#e.get(t);if(r){this.#e.delete(t);this.#t-=r.weight}this.#e.set(t,{value:n,weight:i});this.#t+=i;while(this.#e.size>64||this.#t>this.#n){const o=this.#e.keys().next().value;this.#t-=this.#e.get(o).weight;this.#e.delete(o)}}};var ly=globalThis;var aI=(ly.process?.env?.AGENTIC_MERMAID_ELK_CACHE??ly.AGENTIC_MERMAID_ELK_CACHE)!=="0";function lI(e){return JSON.stringify(e,(t,n)=>{if(n===void 0)return"\0undefined";if(typeof n==="number"&&!Number.isFinite(n))return`\0${n}`;if(typeof n==="string"&&n.startsWith("\0"))return`\0${n}`;if(n instanceof Map)return{mapEntries:[...n]};if(n instanceof Set)return{setValues:[...n]};return n})}var sI=new WeakMap;var cy=new WeakMap;function cI(e){const t=new ay(8*1024*1024);return n=>{if(!aI)return e(n);const i=lI(n);if(i.length>1024*1024)return e(n);const r=t.get(i);if(r)return structuredClone(r);const o=e(n);const s=i.length*2+JSON.stringify(o).length*4+512;if(s<=8*1024*1024)t.set(i,structuredClone(o),s);return o}}function dI(e,t,n,i){const r=i;const o=cy.get(e);try{if(o&&i&&i!==o){o.pairs-=24;const l=i.pairs,c=i.arcs,d=i.swaps;o.pairs=Math.min(o.pairs,l-(1e6-o.pairs));o.arcs=Math.min(o.arcs,c-(65536-o.arcs));o.swaps=Math.min(o.swaps,d-(1e6-o.swaps));if(!Number.isFinite(o.pairs)||!Number.isFinite(o.arcs)||!Number.isFinite(o.swaps)||o.pairs<0||o.arcs<0||o.swaps<0)n("agentic marker preparation work limit")}i=cy.get(e)??i??{pairs:1e6,arcs:65536,swaps:1e6};const s=uc(e,t,n,i);const a=e.placementOnly?s:UA(e,s,i,oy,n);return e.placementOnly?a:oI(e,a)}finally{if(o&&r&&r!==o){r.pairs=o.pairs;r.arcs=o.arcs;r.swaps=o.swaps}}}function ch(e,t,n,i,r,o=false,s="primary"){const{edgeSelectorIndices:a,graphEdgeMarkerPaintRegions:l,DEFAULTS:c,LABEL_PILL_PADDING:d,measureRenderStage:u,graphTextBlock:f,resolveLabelContent:h,groupTitleWidth:m,groupHeaderHeight:p,estimateNodeSize:g,resolveNodeInlineStyle:y,resolveEdgeInlineStyle:w,resolveClassInlineStyle:S,containsNonFiniteNumber:x,finishGraphGeometry:M}=r;if(t.preserveSubgraphChildOrder)r.unsupported("family-specific graph geometry");const b={...c,...t};const C=[];const P={pairs:1e6,arcs:65536,swaps:1e6};P.arcs-=2;const E=($,B=0)=>{P.pairs-=$;P.arcs-=B;if(P.pairs<0||P.arcs<0)r.unsupported("agentic marker preparation work limit")};const k=u("graph-preparation",()=>{const $=[];const B=new Map;const F=new Map;const z=(ee,ae,ie)=>{const oe=$.length,ue=ee.direction??ie;const ye=p(ee,n);const Se=ee.concurrencyRegion?t.stateVisual?.dividerMargin??0:0;B.set(ee.id,oe);C.push(ee);$.push({id:ee.id,parent:ae,direction:ue,minWidth:m(ee,n),headerHeight:ye,padding:{top:ye+n.groupPaddingY+Se,bottom:n.groupPaddingY+Se,left:n.groupPaddingX+Se,right:n.groupPaddingX+Se}});for(const Te of ee.nodeIds)F.set(Te,{parent:oe,direction:ue});ee.children.forEach(Te=>z(Te,oe,ue))};e.subgraphs.forEach(ee=>z(ee,void 0,e.direction));const _=[...e.nodes].map(([ee,ae])=>{if(B.has(ee))r.unsupported("overlapping node and frame identities");const ie=F.get(ee);return{id:ee,...ie?{parent:ie.parent}:{},...t.nodeSizes?.get(ee)??g(ee,h(ae.label,ae.labelContent),ae.shape,n,ie?.direction??e.direction,t.stateVisual,ae.labelBlock)}});const H=new Map(_.map((ee,ae)=>[ee.id,ae]));for(const[ee,ae]of B)H.set(ee,_.length+ae);const D=new Set;for(const[ee,ae]of Object.entries(t.layoutHints?.ranks??{})){const ie=H.get(ee);if(ie===void 0||!e.nodes.has(ee))throw new Error(`LAYOUT_HINT_INVALID: unknown node "${ee}"`);if(!Number.isSafeInteger(ae)||ae<0||ae>1e4)throw new Error(`LAYOUT_HINT_INVALID: rank for "${ee}" must be an integer in [0,10000]`);const oe=_[ie];oe.partition=ae;D.add(oe.parent??-1)}for(const ee of _)if(D.has(ee.parent??-1)&&ee.partition===void 0)ee.partition=0;for(const ee of $)if(D.has(ee.parent??-1))ee.partition=0;if(t.layoutHints?.adjacent?.length){const ee=new Map;const ae=[..._,...$];ae.forEach((ye,Se)=>{const Te=ye.parent??-1,Ie=ee.get(Te)??[];Ie.push(Se);ee.set(Te,Ie)});const ie=new Map;for(const ye of ee.values())ye.forEach((Se,Te)=>ie.set(Se,Te));const oe=new Set,ue=new Map;for(const ye of t.layoutHints.adjacent){if(ye.length<2)throw new Error("LAYOUT_HINT_INVALID: adjacent needs two or more nodes");const Se=ye.map(Ee=>{const ve=H.get(Ee);if(ve===void 0||!e.nodes.has(Ee))throw new Error(`LAYOUT_HINT_INVALID: unknown node "${Ee}"`);return ve});const Te=_[Se[0]].parent??-1;if(Se.some(Ee=>(_[Ee].parent??-1)!==Te))throw new Error("LAYOUT_HINT_INVALID: adjacent nodes need the same container");for(const Ee of Se){if(oe.has(Ee))throw new Error("LAYOUT_HINT_INVALID: a node cannot repeat in adjacency groups");oe.add(Ee)}const Ie=ue.get(Te)??new Map;Ie.set(Math.min(...Se.map(Ee=>ie.get(Ee))),Se);ue.set(Te,Ie)}for(const[ye,Se]of ue){let Te=0;ee.get(ye).forEach((Ie,Ee)=>{const ve=Se.get(Ee);if(ve)for(const $e of ve)ae[$e].modelOrder=Te++;else if(!oe.has(Ie))ae[Ie].modelOrder=Te++})}}let j;if(t.layoutHints?.shortEdges?.length){j=new Set;const ee=a(e.edges);for(const ae of t.layoutHints.shortEdges){const ie=ee.get(ae);if(ie===void 0)throw new Error(`LAYOUT_HINT_INVALID: unknown edge "${ae}"`);j.add(ie)}}const W=$.length?(ee,ae)=>{const ie=(oe,ue)=>{for(let ye=ue<_.length?_[ue].parent:$[ue-_.length].parent;ye!==void 0;ye=$[ye].parent){if(ye===oe)return true}return false};if(ee>=_.length&&ie(ee-_.length,ae))return"start";if(ae>=_.length&&ie(ae-_.length,ee))return"end";return void 0}:void 0;let O=0,N=0,G=0;E(0,3*_.length+5);const Y=new Float64Array(_.length),q=new Uint32Array(_.length),V=new Uint32Array(_.length);const ne=new Map;const X=ee=>{E(4+(typeof ee==="string"?ee.length:0),1);if(typeof ee==="string"&&!/^\s*(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?(?:px)?\s*$/i.test(ee))return void 0;const ae=typeof ee==="number"?ee:Number.parseFloat(ee);return Number.isFinite(ae)&&ae>0?ae:void 0};const U=e.edges.map((ee,ae)=>{const ie=H.get(ee.source),oe=H.get(ee.target);if(ie===void 0||oe===void 0)r.unsupported("unknown endpoint");const ue=ee.label?f(h(ee.label,ee.labelContent),n,"edge"):void 0;const ye=W?.(ie,oe);let Se;const Te=w(ae,e);const Ie=!o&&ee.style!=="invisible"&&(ee.hasArrowStart||ee.hasArrowEnd);const Ee=X(Te?.["stroke-width"]??n.lineWidth*(ee.style==="thick"?2:1));if(ee.style!=="invisible"&&Ee!==void 0)G=Math.max(G,Ee);let ve;if((Ie||ye)&&Ee!==void 0){E(12,15);const De=(Te?.stroke??n.edgeStrokeColor)==="none";const fe=Boolean(Te?.["stroke-width"]);const me=JSON.stringify([ye??null,ee.style,ee.hasArrowStart,ee.hasArrowEnd,ee.startMarker,ee.endMarker,De,fe]);ve=ne.get(me);if(!ve){E(De?4096:2048,De?2048:1024);const Re=ye==="end"?[{x:1,y:0},{x:0,y:0}]:[{x:0,y:0},{x:1,y:0}];const Ne=l({...ee,id:"marker-room",source:"",target:"",points:Re,inlineStyle:fe?{"stroke-width":"1"}:void 0},{lineWidth:n.lineWidth,...De?{edgeStrokeColor:"none"}:{}});let J=0,ge=0,Ce=0,Me=0,le=0,we=0;for(const ke of Ne){E(18);const Le=ke.bounds;if(!Le||!Number.isFinite(Le.x0)||!Number.isFinite(Le.x1)||!Number.isFinite(Le.y0)||!Number.isFinite(Le.y1)||Le.x0>Le.x1||Le.y0>Le.y1)r.unsupported("agentic marker paint bounds");const Fe=ke.position==="start"?ye==="end"?1-Le.x0:Le.x1:ye==="end"?Le.x1:1-Le.x0;if(ke.position==="start")J=Math.max(J,Fe);else if(ke.position==="end")ge=Math.max(ge,Fe);Ce=Math.max(Ce,Le.y1-Le.y0);if(ke.position===ye){we++;Me=Math.max(Me,Le.x1);le=Math.max(le,2*Math.max(Math.abs(Le.y0),Math.abs(Le.y1)))}}E(0,7);ve={start:J,end:ge,span:Ce,boundaryInset:Me,boundaryHeight:le,boundaryCount:we};ne.set(me,ve)}const{start:de,end:be,span:pe}=ve;if(Ie){O=Math.max(O,de+sd+n.edgeBendRadius,be+sd+n.edgeBendRadius,pe);N=Math.max(N,de+be);if(ee.hasArrowStart&&ie<_.length)Y[ie]=Math.max(Y[ie],pe);if(ee.hasArrowEnd&&oe<_.length)Y[oe]=Math.max(Y[oe],pe)}}if(ee.style!=="invisible"){E(2);if(ie<_.length)V[ie]=V[ie]+1;if(oe<_.length)q[oe]=q[oe]+1}if(ye){const De=ee.style!=="invisible"&&(ye==="start"?ee.hasArrowStart:ee.hasArrowEnd);if(De&&(!ve||!ve.boundaryCount))r.unsupported("ancestor marker paint bounds");Se={inset:De?ve.boundaryInset:0,height:De?ve.boundaryHeight:0}}const $e=ye&&ue?Math.max(4,n.lineWidth*(ee.style==="thick"?2:1)*2):0;return{source:ie,target:oe,minSpan:ee.length??1,...j?.has(ae)?{short:true}:{},...Se?{boundaryMarker:Se}:{},...ee.style==="invisible"?{visible:false}:{},...ue?{label:{width:ue.width+2*d+2*$e,height:ue.height+2*d+2*$e}}:{}}});const K=!t.stateVisual&&!$.length&&[...e.nodes.values()].every(ee=>ee.shape==="rectangle"&&!ee.semanticShape)&&e.edges.every((ee,ae)=>{if(ee.label||ee.style!=="solid"||ee.hasArrowStart||!ee.hasArrowEnd||ee.endMarker&&ee.endMarker!=="arrow")return false;const ie=w(ae,e);return!ie||Object.keys(ie).length===0});let Z=Math.max(n.nodeLineWidth,n.groupLineWidth)/2;for(const[ee]of e.nodes){const ae=X(y(ee,e)?.["stroke-width"]??n.nodeLineWidth);E(3);if(ae!==void 0)Z=Math.max(Z,ae/2)}for(const ee of C)if(ee.stateComposite){const ae=X(S(ee.id,e)?.["stroke-width"]??n.groupLineWidth);if(ae!==void 0)Z=Math.max(Z,ae/2)}const Q=Z+G/2;const se=Math.max(6,n.lineWidth+4);const te=O+Q>Math.max(12,se)?O+Q:void 0;for(let ee=0;ee<_.length;ee++){E(6);const ae=_[ee],ie=e.nodes.get(ae.id),oe=Math.max(q[ee],V[ee]);const ue=Y[ee]+G;if(oe<2||Y[ee]<=8||ie.shape!=="rectangle"||ie.semanticShape||t.nodeSizes?.has(ae.id))continue;const ye=(F.get(ae.id)?.direction??e.direction)==="LR"||(F.get(ae.id)?.direction??e.direction)==="RL";const Se=(oe-1)*ue,Te=Se<=32?Se*1.5:Se+16;if(!Number.isFinite(Te))r.unsupported("agentic marker spacing range");if(ye)ae.height=Math.max(ae.height,Te);else ae.width=Math.max(ae.width,Te);ae.minimumPortSpacing=ue}if(!Number.isFinite(N+Q)||!Number.isFinite(te??0)||!Number.isFinite(2*(N+Q)))r.unsupported("agentic marker spacing range");return{nodes:_,groups:$,edges:U,shareCompleteFans:K,direction:e.direction,padding:b.padding,nodeSpacing:b.nodeSpacing,layerSpacing:Math.max(b.layerSpacing,2*(N+Q)),edgeSpacing:se,...te!==void 0?{minimumTerminalLead:te}:{},...s==="authored"?{authoredCycleOrder:true}:s==="compact"?{compactPrivateRanks:true}:{},...o?{placementOnly:true}:{}}});E(0,2);cy.set(k,P);let v;try{v=u("agentic",()=>i(k))}finally{cy.delete(k)}if(v.nodes.length!==k.nodes.length||(v.groups?.length??0)!==k.groups.length||v.edges.length!==e.edges.length||x(v)||v.sharedEdges?.some($=>!Number.isInteger($)||$<0||$>=e.edges.length)||!o&&v.edges.some(($,B)=>$.points.length<2||k.edges[B].label&&!$.labelPosition)){throw new TypeError("Agentic graph producer returned malformed geometry")}const T=k.nodes.map(($,B)=>{const F=e.nodes.get($.id);const z=e.classAssignments.get($.id);return{...F,id:$.id,width:$.width,height:$.height,...v.nodes[B],inlineStyle:y($.id,e),classNames:z?.split(/\s+/).filter(Boolean)}});const A=o?[]:e.edges.map(($,B)=>({...$,...v.edges[B],edgeIndex:B,inlineStyle:w(B,e),...$.id&&e.classAssignments.has($.id)?{classNames:e.classAssignments.get($.id).split(/\s+/).filter(Boolean)}:{}}));const R=C.map(($,B)=>{const F={id:$.id,label:$.label,...$.labelContent?{labelContent:$.labelContent}:{},...v.groups[B],children:[],...$.concurrencyRegion?{concurrencyRegion:true}:{},...$.headerMinHeight===void 0?{}:{headerMinHeight:$.headerMinHeight},...$.stateComposite?{inlineStyle:S($.id,e)}:{}};if(o)F.headerHeight=k.groups[B].headerHeight;return F});const I=[];R.forEach(($,B)=>{const F=k.groups[B].parent;if(F===void 0)I.push($);else R[F].children.push($)});if(o)return{width:v.width,height:v.height,nodes:T,edges:[],groups:I};const L=M({width:v.width,height:v.height,nodes:T,edges:A,groups:I},e,v.topology==="forest",b.padding,n,t.stateVisual?.noteMargin??18,void 0,v.sharedEdges).positioned;if(x(L))throw new TypeError("Agentic graph pipeline returned non-finite geometry");return L}function Z3(e,t,n,i,r){const o=t.compareRoutePreferences!==false&&!t.stateVisual&&!e.subgraphs.length&&e.nodes.size<=20&&e.edges.length<=64;let s,a;if(o&&aI&&!r.customTextMeasurementActive()){const f=lI([e,t,n,Object.keys(ly.process?.env??{}).filter(h=>h.startsWith("APL_")).map(h=>[h,ly.process.env[h]]).sort()]);if(f.length<=65536){s=f;a=sI.get(r);if(!a){a=new ay(1024*1024);sI.set(r,a)}const h=a.get(s);if(h)return ch(e,t,n,i,r,false,h)}}const l=ch(e,t,n,i,r);if(!o)return l;const c=[{strategy:"agentic-authored-order",produce:()=>ch(e,t,n,i,r,false,"authored")}];if(e.edges.some(f=>!f.label))c.push({strategy:"agentic-compact-ranks",produce:()=>ch(e,t,n,i,r,false,"compact")});const d=eX(e,n,l,c,r);const u=d===l?"primary":d.certification?.strategy==="agentic-authored-order"?"authored":d.certification?.strategy==="agentic-compact-ranks"?"compact":void 0;if(s&&a&&u)a.set(s,u,s.length*2+128);return d}function eX(e,t,n,i,r){const{countEdgeCrossings:o,countOpposingRouteOverlaps:s,countParallelRouteOverlaps:a,measureLabelConflicts:l}=r;const c=m=>m.edges.reduce((p,g)=>p+g.points.length,0);if(e.subgraphs.length||e.nodes.size>20||e.edges.length>64||e.edges.reduce((m,p)=>m+(p.length??1),0)>128||c(n)>2048||o(n.edges)===0)return n;V0(e,t,{strategy:"agentic-layered",produce:()=>n},r);const d=m=>[l(m,t).total,s(m.edges),a(m.edges),o(m.edges),m.edges.reduce((p,g)=>p+(g.style==="invisible"?0:Math.max(0,g.points.length-2)),0),m.width*m.height];let u=n,f=d(n);const h=typeof i==="function"?[{strategy:"agentic-authored-order",produce:i}]:i;for(const m of h.slice(0,2)){let p;try{p=V0(e,t,m,r)}catch(y){if(!(y instanceof Mo)&&!(y instanceof Qe))throw y;continue}if(c(p)>2048)continue;const g=d(p);for(let y=0;y<f.length;y++){if(g[y]<f[y]){u=p;f=g;break}if(g[y]>f[y])break}if(f[3]===0)break}return u}function V0(e,t,n,i){const r=i.certifyCandidate(e,t,n,true);if(!r.certified)throw new Qe([r.attempt]);return i.retainSelection(e,{selected:r.certified,reason:"first-certified",attempts:1,compared:[{strategy:r.certified.strategy,score:r.certified.score}]})}function uI(e,t,n,i,r){const o=Z3(e,t,n,i,r);return V0(e,n,{strategy:"agentic-layered",produce:()=>o},r)}function fI(e,t,n,i,r){const o=ch(e,t,n,i,r,true);return{width:o.width,height:o.height,nodes:o.nodes,groups:o.groups}}function dy(e){const{nodes:t,edges:n,padding:i,nodeSpacing:r,layerSpacing:o}=e;if(t.length<2||n.length>=t.length||r<=0||o<=0||![i,r,o].every(E=>Number.isFinite(E)&&E>=0)||t.some(E=>!Number.isFinite(E.width)||!Number.isFinite(E.height)||E.width<=0||E.height<=0))return void 0;const s=t.map(()=>[]);const a=new Uint32Array(t.length);for(const E of n){if(E.label!==void 0||E.minSpan!==1||E.source===E.target||!Number.isInteger(E.source)||!Number.isInteger(E.target)||E.source<0||E.source>=t.length||E.target<0||E.target>=t.length)return void 0;a[E.target]=a[E.target]+1;if(a[E.target]>1)return void 0;s[E.source].push(E.target)}const l=t.flatMap((E,k)=>a[k]===0?[k]:[]);const c=[...l];const d=new Uint32Array(t.length);for(let E=0;E<c.length;E++){const k=c[E];for(const v of s[k]){d[v]=d[k]+1;c.push(v)}}if(c.length!==t.length)return void 0;const u=e.direction==="LR"||e.direction==="RL";const f=e.direction==="RL"||e.direction==="BT";const h=E=>u?t[E].width:t[E].height;const m=E=>u?t[E].height:t[E].width;if(t.some((E,k)=>E.minimumPortSpacing!==void 0&&(s[k].length-1)*E.minimumPortSpacing>m(k)-2*(E.paintCornerRadius??0)))return void 0;const p=new Float64Array(t.length),g=[];for(let E=c.length-1;E>=0;E--){const k=c[E],v=s[k];let T=Math.max(0,v.length-1)*r;for(const A of v)T+=p[A];p[k]=Math.max(m(k),T);g[d[k]]=Math.max(g[d[k]]??0,h(k))}const y=[];let w=0;for(let E=0;E<g.length;E++){y.push(w);w+=g[E]+(E+1<g.length?o:0)}const S=new Float64Array(t.length);let x=0;for(const E of l){S[E]=x;x+=p[E]+r}x-=r;if(!Number.isFinite(w+x+2*i))return void 0;const M=t.map(()=>({x:0,y:0}));for(const E of c){const k=s[E];const v=i+S[E]+(p[E]-m(E))/2;let T=y[d[E]]+(g[d[E]]-h(E))/2;if(f)T=w-T-h(E);T+=i;M[E]=u?{x:T,y:v}:{x:v,y:T};let A=Math.max(0,k.length-1)*r;for(const I of k)A+=p[I];let R=S[E]+(p[E]-A)/2;for(const I of k){S[I]=R;R+=p[I]+r}}const b=new Float64Array(t.length);const C=e.edgeSpacing??6;for(let E=0;E<t.length;E++){const k=t[E].minimumPortSpacing,v=s[E];if(!k||v.length<2)continue;const T=[],A=[];const R=(u?M[E].y:M[E].x)+m(E)/2;for(const[L,$]of v.entries()){const B=R+(L-(v.length-1)/2)*k;const F=(u?M[$].y:M[$].x)+m($)/2;if(F<B)T.push($);else if(F>B)A.push($)}const I=Math.max(T.length,A.length);if((I-1)*C>o-2*Math.max(12,e.minimumTerminalLead??0))return void 0;T.forEach((L,$)=>{b[L]=($-(T.length-1)/2)*C});A.forEach((L,$)=>{b[L]=((A.length-1)/2-$)*C})}const P=new Uint32Array(t.length);return{topology:"forest",width:2*i+(u?w:x),height:2*i+(u?x:w),nodes:M,edges:n.map(E=>{if(e.placementOnly&&!e.cycleOriented&&!e.loopPorts?.length)return{points:[]};const k=M[E.source],v=M[E.target];const T=t[E.source],A=t[E.target];const R=u?{x:k.x+(f?0:T.width),y:k.y+T.height/2}:{x:k.x+T.width/2,y:k.y+(f?0:T.height)};const I=u?{x:v.x+(f?A.width:0),y:v.y+A.height/2}:{x:v.x+A.width/2,y:v.y+(f?A.height:0)};const L=P[E.source],$=s[E.source].length;P[E.source]=L+1;if(T.minimumPortSpacing&&$>1){const H=(L-($-1)/2)*T.minimumPortSpacing;if(u)R.y+=H;else R.x+=H}let B=u?(R.x+I.x)/2:(R.y+I.y)/2;const F=d[E.source];const z=i+(f?w-(y[F]+g[F]):y[F]+g[F]);const _=i+(f?w-y[F+1]:y[F+1]);if(B<=Math.min(z,_)||B>=Math.max(z,_))B=z+(_-z)/2;if(T.minimumPortSpacing&&$>1)B=(z+_)/2+(f?-1:1)*b[E.target];return{points:u?[R,{x:B,y:R.y},{x:B,y:I.y},I]:[R,{x:R.x,y:B},{x:I.x,y:B},I]}})}}function tX(e){throw new Mo(e)}var Ua=cI(e=>dI(e,dy,tX));function hI(e,t,n,i){return uI(e,t,n,Ua,i)}function mI(e,t,n,i){return fI(e,t,n,Ua,i)}function Bd(e,t,n){const i=Mt(e,[t,n]);return typeof i==="number"&&Number.isFinite(i)&&i>=0?i:void 0}var nX={subject:"ER text entity",example:'A["I #9829; ER"]'};var iX='"%\\';function pI(e){return e.replace(/\\(["\\])/g,"$1")}function dh(e,t,n){const i=e.slice(1,-1);if(i.includes("\\"))n?.(`${t} ${e} contains a backslash, and \\" reads as "`,'write " as #quot; and \\ as #92;');else if(i.includes("%"))n?.(`${t} ${e} contains a % and is read as written`,"write % as #37;");else if(i==="")n?.(`${t} ${e} is empty and is read as no text`,"give the name some text");return pI(i)}function gI(e,t){const n=e.trim();if(!n.startsWith('"'))return n;if(/^"[^"]*"$/.test(n))return n.slice(1,-1);if(/^"(?:\\.|[^"\\])*"$/.test(n)){t?.(`ER relation label ${n} contains \\", which reads as "`,'write " as #quot;');return pI(n.slice(1,-1))}throw Je({what:`ER relation label ${n} is not one quoted string`,expectedForm:'one pair of quotes, with " written as #quot;',example:'A ||--o{ B : "says #quot;hi#quot;"'})}function uh(e){return rn(e,nX)}function yI(e){return yt(e).replace(/\*\*([\s\S]+?)\*\*/g,"<b>$1</b>").replace(/_([^_\n]+)_/g,"<i>$1</i>").replace(/(?<!\*)\*([^*\n]+)\*(?!\*)/g,"<i>$1</i>")}function rX(e){return uh(yI(e))}function K0(e,t,n=false){if(!/#\w+;/.test(e))return void 0;const i=n?yt(e):yI(e);const r=ur(Rt(i,n?"literal":"formatted"),/#\w+;/g,uh);return{value:t,prepared:r,authored:e}}function fh(e,t=false){const n=t?rX(e):uh(e);const i=K0(e,n);return{label:n,...i?{labelContent:i}:{}}}function hh(e,t){const n=qe(e,t);if(typeof n!=="string")return ca(n).replace(/\s+/g," ").trim();return ws(e).replace(/\s+/g," ").trim()}function xI(e,t,n){return n?.value===e&&n.authored!==void 0?gr(n.authored,t):dn(e,t)}function oX(e,t){return`"${xI(e,iX,t)}"`}var sX=/^(?:(?:one|many|to|style|classDef|class|subgraph|end|erDiagram)(?!\w)|u-)/i;function bI(e){return/^[A-Za-z_][\w-]*$/.test(e)&&!sX.test(e)}function wfe(e,t){return bI(e)?e:`"${xI(e,'"',t)}"`}function Mfe(e,t){return e.split(" ").every(bI)?e:oX(e,t)}function mo(e,t,n){if(e.source===e.target)return false;const i=t.get(e.source);const r=t.get(e.target);if(!i||!r)return false;const o=_t(n);const s=tw(i);const a=tw(r);return(o.isHorizontal?a.x-s.x:a.y-s.y)*o.sign>8}function fc(e,t,n=18){if(e.length<2)return false;const i=e.map(r=>To(r,t));return Math.max(...i)-Math.min(...i)<=n}function wI(e,t){const n=_t(t);const i=[];const r=18;const o=[...e].sort((a,l)=>To(a,t)-To(l,t)||sr(a,t)-sr(l,t));for(const a of o){const l=To(a,t);let c=i.find(d=>Math.abs(To(d[0],t)-l)<=r);if(!c){c=[];i.push(c)}c.push(a)}const s=24;for(const a of i){const l=[...a].sort((d,u)=>sr(d,t)-sr(u,t));let c=sr(l[0],t);for(const d of l){const u=sr(d,t);if(u<c){const f=c-u;if(n.isHorizontal)d.y+=f;else d.x+=f}c=sr(d,t)+Lo(d,t)+s}}}function zn(e,t){const n=i=>i.some(r=>e.x>=r.x-.5&&e.y>=r.y-.5&&e.x+e.width<=r.x+r.width+.5&&e.y+e.height<=r.y+r.height+.5||n(r.children));return n(t)}function Wd(e,t=[]){for(const n of e){t.push(n);Wd(n.children,t)}return t}function uy(e,t){return e.x>=t.x-.5&&e.y>=t.y-.5&&e.x+e.width<=t.x+t.width+.5&&e.y+e.height<=t.y+t.height+.5}function MI(e,t,n,i){if(i<=0)return;const r=_t(n);const o=new Set;for(const s of Wd(e)){if(o.has(s)||!t.some(a=>uy(a,s)))continue;o.add(s);if(r.isHorizontal){if(r.sign>0)s.width+=i;else{s.x-=i;s.width+=i}}else if(r.sign>0)s.height+=i;else{s.y-=i;s.height+=i}}}function aX(e,t){if(e.shape==="diamond"&&(t==="NE"||t==="SE"||t==="SW"||t==="NW"))return Vo(e)[t];return Ft(e)[t]}function J0(e,t,n,i){if(e.shape==="diamond"){const s=i===2?{LR:["NE","SE"],RL:["NW","SW"],BT:["NW","NE"],TD:["SW","SE"],TB:["SW","SE"]}:i===3?{LR:["NE","E","SE"],RL:["NW","W","SW"],BT:["NW","N","NE"],TD:["SW","S","SE"],TB:["SW","S","SE"]}:{};const a=s[t]?.[n];if(a)return aX(e,a)}const r=_t(t);const o=(n+1)/(i+1);if(r.isHorizontal)return{x:r.sourceSide==="E"?e.x+e.width:e.x,y:e.y+e.height*o};return{x:e.x+e.width*o,y:r.sourceSide==="S"?e.y+e.height:e.y}}function kI(e,t){return Ft(e)[_t(t).targetSide]}function fy(e,t){return Array.from({length:e},(n,i)=>(i-(e-1)/2)*t)}function hc(e,t,n,i){const r=Math.abs(t-e);if(r/2>=i||r<n+i)return e+(t-e)/2;return t-Math.sign(t-e)*i}function ta(e,t,n,i){const r=_t(n);return r.isHorizontal?pt([e,{x:i,y:e.y},{x:i,y:t.y},t]):pt([e,{x:e.x,y:i},{x:t.x,y:i},t])}function lX(e,t,n,i,r=1,o){const s=Math.min(e.x,t.x),a=Math.max(e.x,t.x);const l=Math.min(e.y,t.y),c=Math.max(e.y,t.y);for(const d of n){o?.(1);if(i.has(d.id))continue;const u=d.x-r,f=d.x+d.width+r;const h=d.y-r,m=d.y+d.height+r;if(Math.abs(e.x-t.x)<.01){if(e.x>=u&&e.x<=f&&l<m&&c>h)return false}else if(Math.abs(e.y-t.y)<.01){if(e.y>=h&&e.y<=m&&s<f&&a>u)return false}}return true}function di(e,t,n,i){for(let r=1;r<e.length;r++){if(!lX(e[r-1],e[r],t,n,1,i))return false}return true}function SI(e,t,n,i){if(e.points.length===0)return;const r=_t(t);const o=n?e.points.length-1:0;const s=n?-1:1;const a=e.points[o][r.cross];let l=Infinity;let c=-Infinity;for(let d=o;d>=0&&d<e.points.length;d+=s){if(Math.abs(e.points[d][r.cross]-a)>.5)break;l=Math.min(l,e.points[d][r.main]);c=Math.max(c,e.points[d][r.main]);e.points[d][r.cross]+=i}if(e.labelPosition&&Math.abs(e.labelPosition[r.cross]-a)<=12&&e.labelPosition[r.main]>=l-.5&&e.labelPosition[r.main]<=c+.5){e.labelPosition[r.cross]+=i}}function mh(e,t,n,i,r){const o=_t(i);for(const s of t){if(!e.has(s.id))continue;s[o.cross]+=r}for(const s of n){const a=e.has(s.source);const l=e.has(s.target);if(a&&l){for(const c of s.points)c[o.cross]+=r;if(s.labelPosition)s.labelPosition[o.cross]+=r}else if(l){SI(s,i,true,r)}else if(a){SI(s,i,false,r)}}}function ph(e,t,n,i,r,o){const s=_t(i);const a=t.filter(c=>e.has(c.id));const l=new Map(a.map(c=>[c.id,{x:s.isHorizontal?c.x:c.x+r,y:s.isHorizontal?c.y+r:c.y,width:c.width,height:c.height}]));for(const c of l.values()){if(c.x<0||c.y<0)return false}for(let c=0;c<a.length;c++){const d=l.get(a[c].id);for(let u=c+1;u<a.length;u++){if(Fi(d,l.get(a[u].id),8))return false}for(const u of t){if(e.has(u.id))continue;if(Fi(d,u,8))return false}}for(const c of a){const d=l.get(c.id);for(const u of n){if(e.has(u.source)||e.has(u.target))continue;for(let h=1;h<u.points.length;h++){const m=u.points[h-1],p=u.points[h];if(Math.max(m.x,p.x)>d.x+.5&&Math.min(m.x,p.x)<d.x+d.width-.5&&Math.max(m.y,p.y)>d.y+.5&&Math.min(m.y,p.y)<d.y+d.height-.5)return false}const f=kt(u,o);if(f&&Fi(d,{x:f.x,y:f.y,width:f.w,height:f.h},8))return false}}return true}function mc(e,t,n,i={}){const r=new Map(e.map(s=>[s.id,s]));const o=_t(n.direction);for(const s of t){if(s.source===s.target||s.points.length<2)continue;const a=r.get(s.source),l=r.get(s.target);if(!a||!l)continue;const c=!Ni(a,s.points[0]);const d=!Ni(l,s.points[s.points.length-1]);if(!c&&!d)continue;const u=Ft(a)[o.sourceSide];const f=Ft(l)[o.targetSide];const h=hc(u[o.main],f[o.main],Si(i,s,"start"),Si(i,s,"end"));const m=ta(u,f,n.direction,h);if(!di(m,e,new Set([s.source,s.target])))continue;const p=s.routeCertificate;s.points=m;Qo(s,p,a,l);if(s.label)s.labelPosition=sn(m)}}function No(e,t,n,i,r=[]){const o=_t(n.direction);i?.(e.length);const s=new Map(e.map(m=>[m.id,m]));const a=10;const l=(m,p)=>{for(const g of e){i?.(1);if(p.has(g.id))continue;for(let y=1;y<m.length;y++){i?.(1);if($i(m[y-1],m[y],g))return true}}return false};const c=m=>{const p=g=>{i?.(1);const y=g.concurrencyRegion?0:g.headerHeight;if(g.width!==0&&(y===void 0||!Number.isFinite(y)||y<0))return false;if(y!==void 0&&y>0&&g.width>0)for(let w=1;w<m.length;w++){i?.(1);const S=m[w-1],x=m[w];if(Math.max(S.x,x.x)>g.x&&Math.min(S.x,x.x)<g.x+g.width&&Math.max(S.y,x.y)>g.y&&Math.min(S.y,x.y)<g.y+y)return false}for(const w of g.children)if(!p(w))return false;return true};for(const g of r)if(!p(g))return false;return true};const d=(m,p)=>{for(let g=1;g<=m.length-3;g++){const y=m[g],w=m[g+1],S=m[g-1],x=m[g+2];const M=Math.abs(y.x-w.x)<.5,b=Math.abs(y.y-w.y)<.5;if(M===b)continue;if(!l([y,w],p))continue;const C=M?"x":"y";const P=M?"y":"x";if(Math.abs(S[P]-y[P])>.5||Math.abs(x[P]-w[P])>.5)continue;const E=y[C];const k=[];for(const v of e){i?.(1);if(p.has(v.id))continue;k.push(v[C]-a,v[C]+(C==="x"?v.width:v.height)+a)}k.sort((v,T)=>Math.abs(v-E)-Math.abs(T-E));for(const v of k){const T=m.map(A=>({...A}));T[g][C]=v;T[g+1][C]=v;if(!l(T,p)&&di(T,e,p,i)&&c(T))return pt(T)}}return null};const u=(m,p)=>{const g=m[0],y=m[m.length-1];const w=Math.min(g[o.main],y[o.main]),S=Math.max(g[o.main],y[o.main]);let x=Infinity,M=-Infinity;const b=[];for(const R of e){i?.(1);if(p.has(R.id))continue;const I=R[o.main],L=R[o.main]+(o.main==="x"?R.width:R.height);if(L<=w||I>=S)continue;const $=sr(R,n.direction),B=$+Lo(R,n.direction);x=Math.min(x,$);M=Math.max(M,B);b.push($-a,B+a)}if(!Number.isFinite(x))return null;b.push(x-a,M+a);const C=(R,I)=>o.main==="x"?{x:R,y:I}:{x:I,y:R};const P=Math.sign(y[o.main]-g[o.main])||1;const E=Math.min(12,Math.abs(y[o.main]-g[o.main])/3);const k=g[o.main]+P*E,v=y[o.main]-P*E;const T=(g[o.cross]+y[o.cross])/2;const A=[...new Set(b)].sort((R,I)=>Math.abs(R-T)-Math.abs(I-T));for(const R of A){const I=pt([g,C(k,g[o.cross]),C(k,R),C(v,R),C(v,y[o.cross]),y]);if(!l(I,p)&&di(I,e,p,i)&&c(I))return I}return null};i?.(1);const f=new Set;const h=(m,p)=>{if(m.length<3)return null;const g=m.at(-1),y=m.at(-2),w=m.at(-3);const S=y.y===g.y&&y.x!==g.x?"x":y.x===g.x&&y.y!==g.y?"y":void 0;if(!S)return null;const x=S==="x"?"y":"x";if(w[S]!==y[S]||w[x]===y[x]||!l([y,g],p))return null;const M=[];for(const C of e){i?.(1);if(p.has(C.id)||!$i(y,g,C))continue;i?.(2);M.push(C[x]-a,C[x]+(x==="x"?C.width:C.height)+a)}M.sort((C,P)=>{i?.(1);return Math.abs(C-y[x])-Math.abs(P-y[x])});const b=g[S]+Math.sign(y[S]-g[S])*Math.min(a,Math.abs(y[S]-g[S])/2);for(const C of M){i?.(2*m.length+12);const P={...y,[x]:C},E={...g,[S]:b,[x]:C},k={...g,[S]:b};const v=pt([...m.slice(0,-2),P,E,k,g]);const T=(A,R,I)=>R.x===A.x&&I.x===A.x&&Math.sign(R.y-A.y)===Math.sign(I.y-A.y)||R.y===A.y&&I.y===A.y&&Math.sign(R.x-A.x)===Math.sign(I.x-A.x);if(!T(m[0],m[1],v[1])||!T(g,y,v.at(-2)))continue;if(!l(v,f)&&di(v,e,p,i)&&c(v)&&xp(v,i))return v}return null};for(const m of t){i?.(1);if(m.source===m.target||m.points.length<2)continue;const p=s.get(m.source),g=s.get(m.target);if(!p||!g)continue;const y=new Set([m.source,m.target]);if(!l(m.points,y))continue;if(!Ni(p,m.points[0])||!Ni(g,m.points[m.points.length-1]))continue;let w=d(m.points,y)??u(m.points,y)??h(m.points,y);if(!w){i?.(m.points.length);w=h(m.points.toReversed(),y)?.reverse()??null}if(!w)continue;const S=m.routeCertificate;m.points=w;Qo(m,S,p,g);if(m.label)m.labelPosition=sn(w)}}function Q0(e,t,n){const i=new Map(e.map(r=>[r.id,r]));for(const r of t){if(!n.has(r)||r.label||r.points.length!==4)continue;const o=ql(r);const[s,a,l,c]=r.points;if(!s||!a||!l||!c)continue;const d=i.get(r.target);if(!d||d.shape!=="rectangle")continue;const u=new Set([r.source,r.target]);if(Math.abs(s.y-a.y)<.01&&Math.abs(a.x-l.x)<.01&&Math.abs(l.y-c.y)<.01&&Math.abs(a.y-l.y)<=6){const f={x:c.x,y:s.y};const h=Math.abs(c.x-d.x)<.01||Math.abs(c.x-(d.x+d.width))<.01;if(h&&f.y>=d.y-.5&&f.y<=d.y+d.height+.5&&di([s,f],e,u)){r.points=[s,f];r.routeCertificate=void 0;Fa(r,o)}continue}if(Math.abs(s.x-a.x)<.01&&Math.abs(a.y-l.y)<.01&&Math.abs(l.x-c.x)<.01&&Math.abs(a.x-l.x)<=6){const f={x:s.x,y:c.y};const h=Math.abs(c.y-d.y)<.01||Math.abs(c.y-(d.y+d.height))<.01;if(h&&f.x>=d.x-.5&&f.x<=d.x+d.width+.5&&di([s,f],e,u)){r.points=[s,f];r.routeCertificate=void 0;Fa(r,o)}}}}function Qi(e,t){return It(t,"relationship",{category:e.identifying?"identifying":"non-identifying"},{includeFallback:false})}function Cr(e,t,n){const i=Qi(e,n);return Be(qe(e.label,e.labelContent),{transform:i?.textTransform??t.edgeTextTransform,fontSize:i?.fontSize??t.edgeLabelFontSize,fontWeight:i?.fontWeight??t.edgeLabelFontWeight,letterSpacing:i?.letterSpacing??t.edgeLetterSpacing})}function hy(e,t,n,i){const r=[];const o=Z0(e,t,n,i??{operations:0},true,r);for(const s of e.relationships){const a=o.get(s);if(a)s.finalLabelPosition={...a};else delete s.finalLabelPosition}return r}function CI(e,t,n,i,r,o){const s=e.relationships[t];if(!s.label)return true;o.operations+=e.relationships.length+n.length*2+2;if(o.operations>4e5)throw new rs;const a={...s,points:n};const l=Math.max(e.width,...n.map(f=>f.x+40)),c=Math.max(e.height,...n.map(f=>f.y+40));const d={...e,width:l,height:c,relationships:e.relationships.map((f,h)=>h===t?a:f)};const u=[];Z0(d,i,r,o,true,u);return!u.includes(a)}function Va(e){const t=new Map;for(const n of e.relationships){if(!n.label||n.points.length<2)continue;const i=n.finalLabelPosition;if(!i||!Number.isFinite(i.x)||!Number.isFinite(i.y))return void 0;t.set(n,i)}return t}function na(e,t,n,i={operations:0}){return Z0(e,t,n,i,e.labelPlacement==="shaft-aware")}function Z0(e,t,n,i,r,o){const s=new Map;const a=(p=1)=>{i.operations+=p;if(i.operations>4e5)throw new rs};a(e.relationships.length);const l=e.relationships.filter(p=>p.label&&p.points.length>1).length;if(!l)return s;const c=(p,g)=>Math.min(p.x1,g.x1)-Math.max(p.x0,g.x0)>.5&&Math.min(p.y1,g.y1)-Math.max(p.y0,g.y0)>.5;const d=[...e.entities.map(p=>{const g=Number.parseFloat(p.inlineStyle?.["stroke-width"]??"");const y=(Number.isFinite(g)&&g>0?g:t.nodeLineWidth)/2;return{x0:p.x-y,y0:p.y-y,x1:p.x+p.width+y,y1:p.y+p.height+y}}),...e.groups.flatMap(p=>[{x0:p.x,y0:p.y,x1:p.x+p.width,y1:p.y+p.headerHeight},{x0:p.x-.75,y0:p.y-.75,x1:p.x+.75,y1:p.y+p.height+.75},{x0:p.x+p.width-.75,y0:p.y-.75,x1:p.x+p.width+.75,y1:p.y+p.height+.75},{x0:p.x-.75,y0:p.y-.75,x1:p.x+p.width+.75,y1:p.y+.75},{x0:p.x-.75,y0:p.y+p.height-.75,x1:p.x+p.width+.75,y1:p.y+p.height+.75}])];const u=e.relationships.flatMap(p=>{if(p.points.length===0)return[];const g=[p.points[0],p.points[p.points.length-1]];const y=g.map(S=>({x0:S.x-18,y0:S.y-18,x1:S.x+18,y1:S.y+18}));if(p.points.length<2)return y;const w=[Fo(g[0],p.points[1],p.cardinality1,t.lineWidth),Fo(g[1],p.points.at(-2),p.cardinality2,t.lineWidth)];a(2);return[...y,...w.flatMap(S=>S??[])]});const f=[];a(d.length+u.length);const h=r?e.relationships.flatMap(p=>{if(p.points.length<2)return[];const g=Qi(p,n);const y=g?.bendRadius??t.edgeBendRadius,w=g?.lineWidth??t.lineWidth;if(w<=0)return[];const S=y>0&&p.points.length>2;const x=Math.max(.5,w/2)+(S?.5:0);if(S){a(p.points.length);const M=qn(p.points,y,{metric:"manhattan"}).geometry;const b=[];if(!Ss(M.d,C=>{a();b.push({owner:p,box:{x0:C.bounds.x0-x,y0:C.bounds.y0-x,x1:C.bounds.x1+x,y1:C.bounds.y1+x}});return true},()=>{a();return true}))throw new rs;return b}return p.points.slice(1).map((M,b)=>{a();const C=p.points[b];return{owner:p,box:{x0:Math.min(C.x,M.x)-x,y0:Math.min(C.y,M.y)-x,x1:Math.max(C.x,M.x)+x,y1:Math.max(C.y,M.y)+x}}})}):[];const m=Xr([...d.map(p=>({box:p,owner:void 0})),...u.map(p=>({box:p,owner:void 0})),...h],p=>p.box,a,l*2);for(const p of e.relationships){if(!p.label||p.points.length<2)continue;const g=p.labelBlock??Cr(p,t,n);const y=g.width+16,w=g.height+16;const S=(R,I)=>({x0:R-y/2,y0:I-w/2,x1:R+y/2,y1:I+w/2});const x=R=>{a();return R.x0<0||R.y0<0||R.x1>e.width||R.y1>e.height||f.some(I=>{a();return c(R,I)})||m(R).some(I=>{a();return I.owner!==p&&c(R,I.box)})};const M=p.points;const b=[];let C=0;for(let R=1;R<M.length;R++){a();const I=Math.hypot(M[R].x-M[R-1].x,M[R].y-M[R-1].y);b.push(I);C+=I}const P=R=>{let I=R;for(let L=0;L<b.length;L++){a();if(I<=b[L]||L===b.length-1){const $=b[L]===0?0:Math.max(0,Math.min(1,I/b[L]));return{x:M[L].x+(M[L+1].x-M[L].x)*$,y:M[L].y+(M[L+1].y-M[L].y)*$}}I-=b[L]}return M[M.length-1]};a(M.length*2);const E=eM(M);let k={x:E.x,y:E.y};let v=S(E.x,E.y);const T=r?p.labelPosition:void 0;if(T&&Number.isFinite(T.x)&&Number.isFinite(T.y)&&M.slice(1).some((R,I)=>{a();const L=M[I],$=R.x-L.x,B=R.y-L.y,F=$*$+B*B;const z=F?Math.max(0,Math.min(1,((T.x-L.x)*$+(T.y-L.y)*B)/F)):0;return Math.hypot(T.x-L.x-z*$,T.y-L.y-z*B)<=.001})&&!x(S(T.x,T.y))){k={...T};v=S(k.x,k.y)}let A=x(v);if(A){for(const R of[.4,.6,.3,.7,.25,.75,.2,.8,.15,.85]){const I=P(C*R);const L=S(I.x,I.y);if(!x(L)){k=I;v=L;A=false;break}}}if(A){const R=[];for(const B of h){a();if(B.owner!==p)R.push(B.box)}a(d.length+u.length+f.length+R.length);const I=[...d,...u,...f,...R];let L,$=0;for(let B=1;B<M.length;B++){a();const F=M[B-1],z=M[B],_=b[B-1];const H=F.x===z.x,D=F.y===z.y;if(_===0||!H&&!D){$+=_;continue}const j=H?F.x:F.y,W=(H?y:w)/2,O=(H?w:y)/2;const N=H?e.width:e.height,G=H?e.height:e.width;if(j-W<0||j+W>N){$+=_;continue}const Y=Math.max(Math.min(H?F.y:F.x,H?z.y:z.x),O);const q=Math.min(Math.max(H?F.y:F.x,H?z.y:z.x),G-O);if(Y>=q){$+=_;continue}const V=[];for(const Q of I){a();const se=H?Q.x0:Q.y0,te=H?Q.x1:Q.y1;if(Math.min(j+W,te)-Math.max(j-W,se)<=.5)continue;V.push([(H?Q.y0:Q.x0)-O+.5,(H?Q.y1:Q.x1)+O-.5])}V.sort((Q,se)=>{a();return Q[0]-se[0]||Q[1]-se[1]});const ne=H?F.y:F.x,X=Math.sign((H?z.y:z.x)-ne);const U=ne+X*(C/2-$);const K=(Q,se)=>{a();const te=Math.max(1e-6,Number.EPSILON*Math.max(1,Math.abs(Q),Math.abs(se))*8);if(se-Q<=te*2)return;const ee=Math.max(Q+te,Math.min(se-te,U));const ae=Math.abs($+Math.abs(ee-ne)-C/2);if(!L||ae<L.distance)L={point:H?{x:j,y:ee}:{x:ee,y:j},distance:ae}};let Z=Y;for(const[Q,se]of V){a();if(se<=Z)continue;if(Q>q)break;if(Q>Z)K(Z,Math.min(q,Q));Z=Math.max(Z,se);if(Z>=q)break}if(Z<q)K(Z,q);$+=_}if(L&&!x(S(L.point.x,L.point.y))){k=L.point;v=S(k.x,k.y);A=false}}if(A&&o){a();o.push(p)}f.push(v);s.set(p,k)}return s}function eM(e){if(e.length===0)return{x:0,y:0};if(e.length===1)return e[0];let t=0;for(let r=1;r<e.length;r++){const o=e[r].x-e[r-1].x;const s=e[r].y-e[r-1].y;t+=Math.sqrt(o*o+s*s)}if(t===0)return e[0];const n=t/2;let i=0;for(let r=1;r<e.length;r++){const o=e[r].x-e[r-1].x;const s=e[r].y-e[r-1].y;const a=Math.sqrt(o*o+s*s);if(i+a>=n){const l=a>0?(n-i)/a:0;return{x:e[r-1].x+o*l,y:e[r-1].y+s*l}}i+=a}return e[e.length-1]}var Ct={padding:40,boxPadX:14,headerHeight:34,rowHeight:22,minWidth:140,attrFontSize:11,attrFontWeight:400,nodeSpacing:70,layerSpacing:90};var zd={nodeLabelFontSize:nr.nodeLabel,edgeLabelFontSize:nr.edgeLabel,groupHeaderFontSize:nr.groupHeader,nodeLabelFontWeight:700,edgeLabelFontWeight:Fr.edgeLabel,groupHeaderFontWeight:Fr.groupHeader,nodePaddingX:Ct.boxPadX,nodePaddingY:8,nodeCornerRadius:0,nodeLineWidth:et.outerBox,edgeLineWidth:et.connector,groupCornerRadius:0,groupPaddingX:Ct.boxPadX,groupPaddingY:8,groupLineWidth:et.outerBox};function vI(e,t){if(!t)return e;const n=Mt(t,["er","layoutDirection"]);const i=typeof n==="string"&&/^(TB|TD|BT|LR|RL)$/i.test(n)?n.toUpperCase():void 0;return e.direction===void 0&&i!==void 0?{...e,direction:i}:e}function TI(e,t){if(!e)return t;const n=Bd(e,"er","nodeSpacing");const i=Bd(e,"er","rankSpacing");return n===void 0&&i===void 0?t:{...t,nodeSpacing:t.nodeSpacing??n,layerSpacing:t.layerSpacing??i}}function yy(e,t){return Be(e,{transform:t.nodeTextTransform,fontSize:t.nodeLabelFontSize,fontWeight:t.nodeLabelFontWeight,letterSpacing:t.nodeLetterSpacing})}function Gd(e,t){return Be(e,{transform:t.groupTextTransform,fontSize:t.groupHeaderFontSize,fontWeight:t.groupHeaderFontWeight,letterSpacing:t.groupLetterSpacing})}function gh(e){const t={display:"literal",fontSize:Ct.attrFontSize,fontWeight:Ct.attrFontWeight,monospace:true};return{type:Be(e.type,t),name:Be(e.name,t),keys:Be(e.keys.join(","),{display:"literal",fontSize:9,fontWeight:600}),...e.comment?{comment:Be(hh(e.comment,e.commentContent),{display:"literal",fontSize:Ct.attrFontSize,fontWeight:400})}:{}}}function xy(){return Be("<i>(no attributes)</i>",{fontSize:Ct.attrFontSize,fontWeight:Ct.attrFontWeight})}function PI(e,t,n){for(const i of e.entities){i.labelBlock=yy(qe(i.label,i.labelContent),t);i.attributeBlocks=i.attributes.map(gh);if(i.attributes.length===0)i.emptyAttributeBlock=xy()}for(const i of e.groups)i.labelBlock??=Gd(qe(i.label,i.labelContent),t);for(const i of e.relationships)i.labelBlock??=Cr(i,t,n);return e}function LI(e,t){const n=new Map(e.groups.map(c=>[c.id,c.parentId]));const i=new Map([...e.entities.map(c=>[c.id,c.groupId]),...n]);const r=(c,d)=>{for(let u=i.get(d),f=0;u!==void 0&&n.has(u)&&f<Uc.nesting;u=n.get(u),f++)if(u===c)return true;return false};const o=new Map,s=new Map,a=new Map;for(const[c,d]of e.relationships.entries()){const u=r(d.entity1,d.entity2)?d.entity1:r(d.entity2,d.entity1)?d.entity2:void 0;if(!u)continue;o.set(u,(o.get(u)??0)+t[c].height+56);const f=u===d.entity1?d.entity2:d.entity1;s.set(f,Math.max(s.get(f)??0,t[c].height+40));const h=a.get(u)??[];h.push(c);a.set(u,h)}const l=new Map;for(const c of a.values())c.forEach((d,u)=>l.set(d,(u+1)/(c.length+1)));return{padding:o,exits:s,lanes:l}}function AI(e,t,n){const i=Math.max(e.x,t.x)+(Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x))*n;return[{x:i,y:e.y+e.height},{x:i,y:t.y+t.height}]}function II(e,t){return e.flatMap((n,i)=>{if(!n.label||n.points.length<2)return[];const r=n.labelPosition??sn(n.points),o=t[i];return[{x0:r.x-o.width/2-8,x1:r.x+o.width/2+8,y0:r.y-o.height/2-8,y1:r.y+o.height/2+8}]})}function Qt(e,t=1){e.operations+=t;if(e.operations>4e5)throw new $d}function my(e,t){for(let n=1;n<e.length;n++){const i=e[n-1],r=e[n],o=i.x===r.x;Qt(t);if(![i.x,i.y,r.x,r.y].every(Number.isFinite)||i.x!==r.x&&i.y!==r.y||i.x===r.x&&i.y===r.y)return false;for(let s=1;s<n;s++){Qt(t);const a=e[s-1],l=e[s],c=a.x===l.x;if(o===c){const d=o?"x":"y",u=o?"y":"x";if(i[d]!==a[d])continue;const f=Math.max(Math.min(i[u],r[u]),Math.min(a[u],l[u]));const h=Math.min(Math.max(i[u],r[u]),Math.max(a[u],l[u]));if(s===n-1?f<h:f<=h)return false}else if(s!==n-1){const d=o?i.x:a.x,u=o?a.y:i.y;if(d>=Math.min(i.x,r.x)&&d<=Math.max(i.x,r.x)&&u>=Math.min(i.y,r.y)&&u<=Math.max(i.y,r.y)&&d>=Math.min(a.x,l.x)&&d<=Math.max(a.x,l.x)&&u>=Math.min(a.y,l.y)&&u<=Math.max(a.y,l.y))return false}}}return true}function FI(e,t,n,i){const r=new Map([...e,...t].map(c=>[c.id,c]));const o=new Set(t.map(c=>c.id));const s=(c=1)=>Qt(i,c);const a=new Map([...e.map(c=>[c.id,c.groupId]),...t.map(c=>[c.id,c.parentId])]);const l=(c,d)=>{for(let u=a.get(d),f=0;u!==void 0&&f<Uc.nesting;u=a.get(u),f++){s();if(u===c)return true}return false};for(const c of n)for(const d of[false,true]){const u=d?c.entity2:c.entity1,f=d?c.entity1:c.entity2,h=r.get(u);const m=d?c.points.at(-1):c.points[0];if(!h||!m)continue;const p=(d?[...c.points].reverse():c.points).find(g=>g.x!==m.x||g.y!==m.y);s(c.points.length);if(!p)continue;if(o.has(u)&&l(u,f)){if(p.x!==m.x)throw new Nt(c.entity1,c.entity2);m.y=h.y+h.height}else{const g=p.y===m.y&&p.x!==m.x||(m.x===h.x||m.x===h.x+h.width)&&p.x!==m.x;const y=p.x===m.x&&p.y!==m.y||(m.y===h.y||m.y===h.y+h.height)&&p.y!==m.y;if(g){m.x=p.x>m.x?h.x+h.width:h.x;p.y=m.y}else if(y){m.y=p.y>m.y?h.y+h.height:h.y;p.x=m.x}}}}function py(e,t,n,i,r,o,s={operations:0},a){FI(e,t,n,s);const l=r.lineWidth;const c=yi([...e.map(p=>p.id),...t.map(p=>p.id)]);const d=new Set(t.map(p=>p.id)),u=new Map,f=new Map;const h=[...e.map(p=>{const g=c(`er-entity:${p.id}`,["er","entity",p.id]);u.set(g,p.id);const y=Number.parseFloat(p.inlineStyle?.["stroke-width"]??"");const w=(Number.isFinite(y)&&y>0?y:r.nodeLineWidth)/2;return{...p,id:g,x:p.x-w,y:p.y-w,width:p.width+2*w,height:p.height+2*w,shape:"rectangle"}}),...t.map(p=>{const g=c(`er-header:${p.id}`,["er","header",p.id]);f.set(g,p.id);return{...p,id:g,height:p.headerHeight,shape:"rectangle"}})];const m=p=>Qt(s,p);for(const[p,g]of n.entries()){if(a&&!a.indices.has(p))continue;if(g.points.length<2)continue;const[y,w]=[g.points[0],g.points.at(-1)];const S=Qi(g,o);const x=(S?.bendRadius??r.edgeBendRadius)+2*(S?.lineWidth??r.lineWidth);const M=h.filter(W=>{const O=u.get(W.id);return O===void 0||d.has(O)||O!==g.entity1&&O!==g.entity2}).map(W=>x&&f.get(W.id)!==g.entity1&&f.get(W.id)!==g.entity2?{...W,x:W.x-x,y:W.y-x,width:W.width+2*x,height:W.height+2*x}:W);const b=W=>W.slice(1).some((O,N)=>M.some(G=>{m(1);return $i(W[N],O,G)}));const C=(W,O,N)=>{const G=Fo(W,O,N,l);m(2+(G?.length??0));if(!G?.length)return false;const Y=W.y===O.y,q=Math.sign(Y?O.x-W.x:O.y-W.y);const V=Math.max(...G.map(Q=>q>0?Y?Q.x1-W.x:Q.y1-W.y:Y?W.x-Q.x0:W.y-Q.y0));const ne=Math.abs(Y?O.x-W.x:O.y-W.y),X=S?.bendRadius??r.edgeBendRadius;const U=W===y?g.points[2]:g.points.at(-3);const K=U?Math.abs(U.x-O.x)+Math.abs(U.y-O.y):ne;const Z=ne-(g.points.length>2?Math.min(X,ne/2,K/2):0);return Z>=V};if(!b(g.points)&&my(g.points,s)&&C(y,g.points[1],g.cardinality1)&&C(w,g.points.at(-2),g.cardinality2)&&(!a||a.admit(p,g.points)))continue;delete g.labelPosition;const P=g.points.find(W=>W.x!==y.x||W.y!==y.y),E=[...g.points].reverse().find(W=>W.x!==w.x||W.y!==w.y);const k=[];const v=1;const T=l+.25;const A=(W,O,N,G)=>{const Y={x:Math.sign(O.x-W.x),y:Math.sign(O.y-W.y)};const q=Fo(W,O,G,l);m(2+(q?.length??0));if(!q?.length)throw new Nt(g.entity1,g.entity2);const V=Math.max(0,...q.map(ee=>Y.x>0?ee.x1-W.x:Y.x<0?W.x-ee.x0:Y.y>0?ee.y1-W.y:W.y-ee.y0));const ne=V+(S?.bendRadius??r.edgeBendRadius)+T;const X=i[p],U=(Y.x?X.width:X.height)/2+8;const K=g.entity1===g.entity2&&g.label?V+U+v+T+r.nodeLineWidth/2:0;const Z=Math.max(ne+v+T,K);let Q=Math.max(20,Z);for(const ee of M){m(1);if(!(Y.x?W.y>ee.y&&W.y<ee.y+ee.height:W.x>ee.x&&W.x<ee.x+ee.width))continue;const ae=Y.x>0?ee.x-W.x:Y.x<0?W.x-ee.x-ee.width:Y.y>0?ee.y-W.y:W.y-ee.y-ee.height;if(ae>=0)Q=Math.min(Q,ae-v-T)}if(Q<Z)throw new Nt(g.entity1,g.entity2);const se=Math.max(0,...q.map(ee=>Y.x?Math.max(W.y-ee.y0,ee.y1-W.y):Math.max(W.x-ee.x0,ee.x1-W.x)));const te={x:W.x+Y.x*ne,y:W.y+Y.y*ne};m(q.length+2);k.push({id:c(`er-terminal:${p}:${k.length}`,["er","terminal",p,k.length]),label:"",shape:"rectangle",x:Y.x?Math.min(W.x,te.x):W.x-se,y:Y.y?Math.min(W.y,te.y):W.y-se,width:Y.x?ne:se*2,height:Y.y?ne:se*2});return{id:N,label:"",shape:"rectangle",x:W.x+Y.x*Q,y:W.y+Y.y*Q,width:0,height:0}};const R=A(y,P,g.entity1,g.cardinality1),I=A(w,E,g.entity2,g.cardinality2);const L=W=>b(W)||W.slice(1).some((O,N)=>k.some(G=>{m(1);return $i(W[N],O,G)}));const $=i[p],B=$.width/2+8,F=$.height/2+8;const z=M.map(W=>({...W,x:W.x-B,y:W.y-F,width:W.width+B*2,height:W.height+F*2}));const _=[z];m(M.length);const H={source:R.id,target:I.id,style:"solid",hasArrowStart:false,hasArrowEnd:false,points:[{x:R.x,y:R.y},...g.points.slice(1,-1),{x:I.x,y:I.y}]};const D=Math.abs(w.x-y.x)>=Math.abs(w.y-y.y)?w.x>=y.x?"LR":"RL":w.y>=y.y?"TB":"BT";No([...z,...k,R,I],[H],{direction:D},m);if(L(H.points)){m(M.length);const W=M.map(O=>D==="TB"||D==="BT"?{...O,x:O.x-B,width:O.width+B*2}:{...O,y:O.y-F,height:O.height+F*2});_.push(W);No([...W,...k,R,I],[H],{direction:D},m)}if(L(H.points)){const W=D==="LR"||D==="RL"?w.y>=y.y?"TB":"BT":w.x>=y.x?"LR":"RL";m(M.length);const O=M.map(N=>W==="TB"||W==="BT"?{...N,x:N.x-B,width:N.width+B*2}:{...N,y:N.y-F,height:N.height+F*2});_.push(O);No([...O,...k,R,I],[H],{direction:W},m)}const j=W=>{if(L(W))return false;const O=pt([y,...W,w]);return my(O,s)&&(!a||a.admit(p,O))};if(!j(H.points)){let W;for(const O of[..._,M]){const N=[R.x,I.x],G=[R.y,I.y];for(const q of[...O,...k]){m(4);N.push(q.x-T,q.x+q.width+T);G.push(q.y-T,q.y+q.height+T)}N.sort((q,V)=>{m(1);return Math.abs(q-(R.x+I.x)/2)-Math.abs(V-(R.x+I.x)/2)||q-V});G.sort((q,V)=>{m(1);return Math.abs(q-(R.y+I.y)/2)-Math.abs(V-(R.y+I.y)/2)||q-V});m((N.length+G.length+2)*4);const Y=[[R,{x:I.x,y:R.y},I],[R,{x:R.x,y:I.y},I],...N.map(q=>[R,{x:q,y:R.y},{x:q,y:I.y},I]),...G.map(q=>[R,{x:R.x,y:q},{x:I.x,y:q},I])];for(const q of Y){const V=pt(q);const ne=V.slice(1).some((X,U)=>O.some(K=>{m(1);return $i(V[U],X,K)}));if(!ne&&j(V)){W=V;break}}if(W)break}if(!W)throw new Nt(g.entity1,g.entity2);H.points=W}g.points=pt([y,...H.points,w]);if(b(g.points))throw new Nt(g.entity1,g.entity2)}}var NI=12;function nM(e){const t=e.map(i=>i.comment?gh(i).comment.width:0);const n=Math.max(0,...t);return n>0?n+NI:0}function cX(e,t){const n=new Map;for(const i of e.entities){const r=yy(qe(i.label,i.labelContent),t);const o=r.width;let s=i.attributes.length===0?xy().width:0;const a=nM(i.attributes);for(const u of i.attributes){const f=gh(u);const h=u.keys.length?f.keys.width+14:0;const m=f.type.width+f.name.width+h+NI+a;if(m>s)s=m}const l=Math.max(Ct.minWidth,o+t.nodePaddingX*2,s+Math.max(8,t.nodePaddingX)*2);const c=Math.max(Ct.headerHeight,r.height+t.nodePaddingY*2);const d=c+Math.max(i.attributes.length,1)*Ct.rowHeight;n.set(i.id,{width:l,height:d,headerHeight:c})}return n}function dX(e,t,n,i,r={operations:0}){const o=Ue(t,zd,i);let s=0;const a=new Map;for(const d of e.relationships){const u=Qi(d,i);for(const[f,h]of[[d.entity1,d.cardinality1],[d.entity2,d.cardinality2]]){Qt(r,12);const m=Ya(h,o.lineWidth);if(!m)throw new Nt(d.entity1,d.entity2);s=Math.max(s,m.x1+(u?.bendRadius??o.edgeBendRadius)+(u?.lineWidth??o.lineWidth)/2);if(n.has(f))a.set(f,(a.get(f)??0)+m.y1-m.y0+o.lineWidth+.25)}}const l={id:"root",layoutOptions:{"elk.algorithm":"layered","elk.direction":ba(e.direction??"LR"),"elk.spacing.nodeNode":String(t.nodeSpacing??Ct.nodeSpacing),"elk.layered.spacing.nodeNodeBetweenLayers":String(t.layerSpacing??Ct.layerSpacing),"elk.padding":`[top=${Ct.padding},left=${Ct.padding},bottom=${Ct.padding},right=${Ct.padding}]`,"elk.edgeRouting":"ORTHOGONAL",...s>10?{"elk.layered.spacing.edgeNodeBetweenLayers":String(s)}:{},"elk.edgeLabels.placement":"CENTER"},children:[],edges:[]};for(const d of e.entities){const u=n.get(d.id),f=(a.get(d.id)??0)+2*Math.max(8,o.cornerRadius??0);Qt(r);l.children.push({id:d.id,width:Math.max(u.width,f),height:Math.max(u.height,f)})}const c=new Set(e.entities.map(d=>d.id));for(let d=0;d<e.relationships.length;d++){const u=e.relationships[d];if(!c.has(u.entity1)||!c.has(u.entity2))continue;const f={id:`e${d}`,sources:[u.entity1],targets:[u.entity2]};if(u.label){const h=Cr(u,o,i);const m=h.text;f.labels=[{text:m,width:h.width+8,height:h.height+6}]}l.edges.push(f)}return{elkGraph:l,entitySizes:n}}function uX(e,t,n,i,r,o={operations:0}){const s=new Map;for(const E of t.entities)s.set(E.id,E);const a=[];const l=Tt(t.classDefs.get("default"),"classDef default");for(const E of e.entities){const k=s.get(E.id);if(k){const v={...l};for(const T of k.className?.split(/[ \t]+/)??[])Object.assign(v,Tt(t.classDefs.get(T),`classDef ${T}`));a.push({id:k.id,label:k.label,...k.labelContent?{labelContent:k.labelContent}:{},attributes:k.attributes,x:E.x??0,y:E.y??0,width:E.width??n.get(k.id).width,height:E.height??n.get(k.id).height,headerHeight:n.get(k.id).headerHeight,rowHeight:Ct.rowHeight,...k.className?{className:k.className}:{},...Object.keys(v).length>0||k.inlineStyle?{inlineStyle:{...v,...Tt(k.inlineStyle,`style ${k.id}`)}}:{},...k.groupId?{groupId:k.groupId}:{}})}}const c=new Map(a.map(E=>[E.id,{x:E.x,y:E.y,width:E.width,height:E.height}]));const d=t.relationships.map(E=>Cr(E,i,r));const u=LI(t,d);const f=$I(t,i,r,o);hX(t,a,d,i,r,o);const h=mX(t,a,i,u.padding,f);const m=e.preserveTerminalNormals?20+2*Math.max(i.edgeBendRadius,...t.relationships.map(E=>Qi(E,r)?.bendRadius??i.edgeBendRadius)):20;_I(t,a,h,i,d,u.padding,u.exits,m,r,o,f);const p=new Map;a.forEach(E=>p.set(E.id,E));h.forEach(E=>p.set(E.id,E));const g=e.routes;const y=[];for(let E=0;E<t.relationships.length;E++){const k=t.relationships[E];const v=p.get(k.entity1),T=p.get(k.entity2);const A=c.get(k.entity1),R=c.get(k.entity2);const I=v&&A?v.x-A.x:void 0;const L=v&&A?v.y-A.y:void 0;const $=I!==void 0&&L!==void 0&&T&&R&&Math.abs(T.x-R.x-I)<.001&&Math.abs(T.y-R.y-L)<.001&&v.width===A.width&&v.height===A.height&&T.width===R.width&&T.height===R.height?g.get(E):void 0;const B=[];let F;if(v&&T&&u.lanes.has(E)){B.push(...AI(v,T,u.lanes.get(E)))}else if($?.length){B.push(...$.map(_=>({x:_.x+I,y:_.y+L})));const z=e.labelPositions?.get(E);if(z)F={x:z.x+I,y:z.y+L}}else{if(v&&T){B.push(...gy(v,T))}}y.push({entity1:k.entity1,entity2:k.entity2,cardinality1:k.cardinality1,cardinality2:k.cardinality2,label:k.label,...k.labelContent?{labelContent:k.labelContent}:{},labelBlock:d[E],identifying:k.identifying,points:B,...F?{labelPosition:F}:{}})}py(a,h,y,d,i,r,o);const w=[...a.flatMap(E=>[E.x,E.x+E.width]),...h.flatMap(E=>[E.x,E.x+E.width]),...y.flatMap(E=>E.points.map(k=>k.x))];const S=[...a.flatMap(E=>[E.y,E.y+E.height]),...h.flatMap(E=>[E.y,E.y+E.height]),...y.flatMap(E=>E.points.map(k=>k.y))];const x=II(y,d);const M=Math.max(0,w.length?Ct.padding-Math.min(...w):0,...x.map(E=>-E.x0));const b=Math.max(0,S.length?Ct.padding-Math.min(...S):0,...x.map(E=>-E.y0));if(M!==0||b!==0){for(const E of a){E.x+=M;E.y+=b}for(const E of h){E.x+=M;E.y+=b}for(const E of y){for(const k of E.points){k.x+=M;k.y+=b}if(E.labelPosition){E.labelPosition.x+=M;E.labelPosition.y+=b}}}const C=Math.max((e.width??600)+M,...a.map(E=>E.x+E.width+Ct.padding),...h.map(E=>E.x+E.width+Ct.padding),...y.flatMap(E=>E.points.map(k=>k.x+Ct.padding)),...x.map(E=>E.x1+M));const P=Math.max((e.height??400)+b,...a.map(E=>E.y+E.height+Ct.padding),...h.map(E=>E.y+E.height+Ct.padding),...y.flatMap(E=>E.points.map(k=>k.y+Ct.padding)),...x.map(E=>E.y1+b));return{width:C,height:P,accessibilityTitle:t.accessibilityTitle,accessibilityDescription:t.accessibilityDescription,entities:a,relationships:y,groups:h,...e.labelPlacement?{labelPlacement:e.labelPlacement}:{}}}function EI(e,t){const n={x:e.x+e.width/2,y:e.y+e.height/2};const i=t.x-n.x,r=t.y-n.y;if(Math.abs(i)*e.height>=Math.abs(r)*e.width){return{point:{x:i>=0?e.x+e.width:e.x,y:n.y+r/(Math.abs(i)||1)*e.width/2},horizontal:true}}return{point:{x:n.x+i/(Math.abs(r)||1)*e.height/2,y:r>=0?e.y+e.height:e.y},horizontal:false}}function gy(e,t){const n=EI(e,{x:t.x+t.width/2,y:t.y+t.height/2});const i=EI(t,{x:e.x+e.width/2,y:e.y+e.height/2});return fX(n.point,i.point,n.horizontal,i.horizontal)}function fX(e,t,n,i){const r=[e];if(e.x!==t.x&&e.y!==t.y){if(n!==i)r.push(n?{x:t.x,y:e.y}:{x:e.x,y:t.y});else if(n){const o=(e.x+t.x)/2;r.push({x:o,y:e.y},{x:o,y:t.y})}else{const o=(e.y+t.y)/2;r.push({x:e.x,y:o},{x:t.x,y:o})}}r.push(t);return r}function hX(e,t,n,i,r,o){const s=new Set;for(const a of e.groups){if(!a.direction)continue;const l=a.entityIds.map(g=>t.find(y=>y.id===g)).filter(g=>Boolean(g));if(l.length<2)continue;for(const g of l)s.add(g.id);const c=a.direction==="LR"||a.direction==="RL";const d=a.direction==="RL"||a.direction==="BT"?[...l].reverse():l;const u=new Set(l.map(g=>g.id));const f=Math.max(48,...e.relationships.flatMap((g,y)=>{Qt(o);if(!u.has(g.entity1)||!u.has(g.entity2))return[];const w=Ya(g.cardinality1,i.lineWidth),S=Ya(g.cardinality2,i.lineWidth);Qt(o,2);if(!w||!S)throw new Nt(g.entity1,g.entity2);const x=Qi(g,r)?.bendRadius??i.edgeBendRadius;const M=Math.max(18,w.x1)+Math.max(18,S.x1)+2*x+2*(i.lineWidth+.25);return[Math.max(g.label?n[y][c?"width":"height"]+56:0,M+(g.label?n[y][c?"width":"height"]+20:0))]}));const h=Math.min(...l.map(g=>g.x));const m=Math.min(...l.map(g=>g.y));let p=c?h:m;for(const g of d){if(c){g.x=p;g.y=m;p+=g.width+f}else{g.x=h;g.y=p;p+=g.height+f}}}return s}function $I(e,t,n,i){const r=new Map([...e.entities.map(s=>[s.id,s.groupId]),...e.groups.map(s=>[s.id,s.parentId])]);const o=new Map;Qt(i,r.size);for(const s of e.relationships){Qt(i);if(s.label){const l=Cr(s,t,n);const c=l.width+16+t.nodeLineWidth+1.5+2*(t.lineWidth+.25);for(const[d,u]of[[s.entity1,s.entity2],[s.entity2,s.entity1]]){for(let f=r.get(u),h=0;f!==void 0&&h<Uc.nesting;f=r.get(f),h++){Qt(i);if(f===d){o.set(f,Math.max(o.get(f)??20,c));break}}}}const a=Qi(s,n)?.bendRadius??t.edgeBendRadius;for(const[l,c]of[[s.entity1,s.cardinality1],[s.entity2,s.cardinality2]]){const d=r.get(l);if(!d)continue;const u=Ya(c,t.lineWidth);Qt(i);if(!u)throw new Nt(s.entity1,s.entity2);const f=Qi(s,n)?.lineWidth??t.lineWidth;const h=u.x1+2*a+2*f+3*(t.lineWidth+.25)+2+.75;o.set(d,Math.max(o.get(d)??20,h))}}return o}function mX(e,t,n,i,r){const o=[];for(const s of[...e.groups].reverse()){const a=[...t.filter(p=>p.groupId===s.id),...o.filter(p=>p.parentId===s.id)];const l=r.get(s.id)??20;const c=Gd(qe(s.label,s.labelContent),n);const d=n.groupHeaderFontSize+16+c.height-c.lineHeight;const u=a.length?Math.min(...a.map(p=>p.x))-l:Ct.padding;const f=a.length?Math.min(...a.map(p=>p.y))-l-d:Ct.padding;const h=Math.max(u+c.width+20,a.length?Math.max(...a.map(p=>p.x+p.width))+l:u+140);const m=a.length?Math.max(...a.map(p=>p.y+p.height))+Math.max(l,i.get(s.id)??0):f+90;o.unshift({id:s.id,label:s.label,...s.labelContent?{labelContent:s.labelContent}:{},labelBlock:c,...s.parentId?{parentId:s.parentId}:{},x:u,y:f,width:h-u,height:m-f,headerHeight:d})}return o}function _I(e,t,n,i,r,o,s,a=20,l,c={operations:0},d=new Map){if(n.length===0)return false;const u=new Map(n.map(b=>[b.id,b]));const f=new Map(e.groups.map(b=>[b.id,b]));const h=new Map;const m=new Map;for(const b of n){const C=b.parentId&&u.has(b.parentId)?b.parentId:void 0;const P=h.get(C)??[];P.push(b);h.set(C,P)}for(const b of t){const C=b.groupId&&u.has(b.groupId)?b.groupId:void 0;const P=m.get(C)??[];P.push(b);m.set(C,P)}const p=new Map([...t,...n].map(b=>[b.id,b]));const g=b=>{Qt(c);const C=e.relationships[b],P=p.get(C.entity1),E=p.get(C.entity2);const k=gy(P,E);const v=Fo(k[0],k[1],C.cardinality1,i.lineWidth);const T=Fo(k.at(-1),k.at(-2),C.cardinality2,i.lineWidth);if(!v?.length||!T?.length)return true;const A=(I,L)=>{Qt(c);return I.x0<L.x1&&I.x1>L.x0&&I.y0<L.y1&&I.y1>L.y0};if(v.some(I=>T.some(L=>A(I,L))))return true;const R=(I,L)=>({x0:L.x,y0:L.y,x1:L.x+L.width,y1:L.y+(u.has(I)?L.headerHeight:L.height)});if(v.some(I=>A(I,R(C.entity2,E)))||T.some(I=>A(I,R(C.entity1,P))))return true;if(C.label){const I=N0(r[b],sn(k));if(!I||A(I,R(C.entity1,P))||A(I,R(C.entity2,E)))return true}return false};let y=false;const w=(b,C,P)=>{b.x+=C;b.y+=P;for(const E of m.get(b.id)??[]){E.x+=C;E.y+=P}for(const E of h.get(b.id)??[])w(E,C,P)};const S=b=>new Set([b.id,...(m.get(b.id)??[]).map(C=>C.id),...(h.get(b.id)??[]).flatMap(C=>[...S(C)])]);const x=(b,C)=>{const P=C==="LR"||C==="RL";const E=P?"y":"x";const k=P?"height":"width";const v=P?"x":"y";const T=O=>{const N=[];for(const G of e.relationships){Qt(c);if(!O.ids.has(G.entity1)&&!O.ids.has(G.entity2))continue;const Y=p.get(G.entity1),q=p.get(G.entity2);if(!Y||!q)continue;const V=gy(Y,q);const ne=Qi(G,l)?.bendRadius??i.edgeBendRadius;const X=2*ne+2*i.lineWidth+4*(i.lineWidth+.25)+2;for(const[U,K,Z,Q]of[[G.entity1,V[0],V[1],G.cardinality1],[G.entity2,V.at(-1),V.at(-2),G.cardinality2]]){if(!O.ids.has(U))continue;const se=Fo(K,Z,Q,i.lineWidth);Qt(c,2+(se?.length??0));if(!se)throw new Nt(G.entity1,G.entity2);N.push(...se.map(te=>({...te,overhead:X})))}}return N};const A=O=>Math.max(0,...[...O.ids].map(N=>{Qt(c);if(u.has(N))return .75;const G=p.get(N);const Y=Number.parseFloat(G?.inlineStyle?.["stroke-width"]??"");return(Number.isFinite(Y)&&Y>0?Y:i.nodeLineWidth)/2}));const R=new Map;const I=new Map(b.map(O=>[O,Math.max(0,...[...O.ids].map(N=>s.get(N)??0))]));const L=new Map;for(const O of b)for(const N of O.ids)R.set(N,O);for(const[O,N]of e.relationships.entries()){Qt(c);const G=R.get(N.entity1),Y=R.get(N.entity2);if(!G||!Y||G===Y)continue;const q=Ya(N.cardinality1,i.lineWidth),V=Ya(N.cardinality2,i.lineWidth);if(!q||!V)throw new Nt(N.entity1,N.entity2);const ne=Qi(N,l)?.bendRadius??i.edgeBendRadius;const X=Q=>Math.max(0,Q.x1,-Q.x0,Q.y1,-Q.y0)+ne;const U=X(q)+X(V)+2*(i.lineWidth+.25);const K=N.label?Math.max(r[O][P?"height":"width"]+56,r[O][P?"height":"width"]+20+U):U;const Z=U+(N.label?r[O][P?"width":"height"]+20:0);for(const[Q,se]of[[G,Y],[Y,G]]){const te=L.get(Q)??new Map,ee=te.get(se);te.set(se,{cross:Math.max(ee?.cross??0,K),main:Math.max(ee?.main??0,Z),indices:[...ee?.indices??[],O]});L.set(Q,te)}}const $=new Map(b.map(O=>[O,new Set]));for(const O of e.relationships){Qt(c);const N=R.get(O.entity1),G=R.get(O.entity2);if(N&&G&&N!==G)$.get(N).add(G)}const B=(O,N)=>{const G=[O],Y=new Set;while(G.length){Qt(c);const q=G.pop();if(q===N)return true;if(Y.has(q))continue;Y.add(q);for(const V of $.get(q)){Qt(c);G.push(V)}}return false};const F=new Map(b.map(O=>[O,[]])),z=new Map(b.map(O=>[O,[]]));for(const[O,N]of $)for(const G of N){Qt(c);if(B(G,O))continue;F.get(G).push(O);z.get(O).push(G)}const _=new Map(b.map(O=>[O,F.get(O).length])),H=b.filter(O=>_.get(O)===0);const D=C==="BT"||C==="RL",j=P?"width":"height";for(let O=0;O<H.length;O++){const N=H[O];let G=0;for(const Y of F.get(N)){Qt(c);const q=Math.max(a,L.get(N)?.get(Y)?.main??0);G=D?Math.min(G,Y.box[v]-q-N.box[v]-N.box[j]):Math.max(G,Y.box[v]+Y.box[j]+q-N.box[v])}if(G!==0){N.move(P?G:0,P?0:G);y=true}for(const Y of z.get(N)){Qt(c);_.set(Y,_.get(Y)-1);if(_.get(Y)===0)H.push(Y)}}b.sort((O,N)=>O.box[E]-N.box[E]||O.box[v]-N.box[v]);const W=[];for(const O of b){for(let N=0;N<W.length;N++){let G=0;for(const Y of W){Qt(c);const q=L.get(O)?.get(Y);const V=T(O),ne=T(Y);const X=A(O),U=A(Y);const K=(oe,ue,ye)=>{Qt(c);return oe.x0<ue.x+ue.width+ye&&oe.x1>ue.x-ye&&oe.y0<ue.y+ue.height+ye&&oe.y1>ue.y-ye};const Z=V.some(oe=>K(oe,Y.box,U))||ne.some(oe=>K(oe,O.box,X));const Q=(oe,ue,ye,Se)=>Math.max(0,...oe.map(Te=>{Qt(c);const Ie=ye?(P?Te.y1:Te.x1)-ue[E]-ue[k]:ue[E]-(P?Te.y0:Te.x0);return Ie>0?Ie+Te.overhead+Se:0}));const se=Z?Q(ne,Y.box,true,X)+Q(V,O.box,false,U):0;const te=Math.max(q?.cross??0,I.get(O),I.get(Y),se);const ee=P?"width":"height";const ae=Math.min(O.box[v]+O.box[ee],Y.box[v]+Y.box[ee])-Math.max(O.box[v],Y.box[v]);const ie=Math.min(O.box[E]+O.box[k],Y.box[E]+Y.box[k])-Math.max(O.box[E],Y.box[E]);if((ae>.5||Z||q&&ae>-q.main&&q.indices.some(g))&&ie>-Math.max(te,a>20?a:0)+.5){G=Math.max(G,Y.box[E]+Y.box[k]+Math.max(a,te)-O.box[E])}}if(G===0)break;O.move(P?0:G,P?G:0);y=true}W.push(O)}};const M=(b,C)=>{const P=h.get(b)??[];for(const H of P)M(H.id,f.get(H.id)?.direction??C);const E=m.get(b)??[];const k=new Map(E.map(H=>[H.id,H]));const v=new Map(E.map(H=>[H.id,[]]));for(const H of e.relationships){if(!k.has(H.entity1)||!k.has(H.entity2))continue;v.get(H.entity1).push(H.entity2);v.get(H.entity2).push(H.entity1)}const T=new Set;const A=[];for(const H of E){if(T.has(H.id))continue;const D=[];const j=[H.id];while(j.length){const G=j.pop();if(T.has(G))continue;T.add(G);D.push(k.get(G));j.push(...v.get(G))}const W=Math.min(...D.map(G=>G.x)),O=Math.min(...D.map(G=>G.y));const N={x:W,y:O,width:Math.max(...D.map(G=>G.x+G.width))-W,height:Math.max(...D.map(G=>G.y+G.height))-O};A.push({box:N,ids:new Set(D.map(G=>G.id)),move:(G,Y)=>{N.x+=G;N.y+=Y;for(const q of D){q.x+=G;q.y+=Y}}})}const R=[...A,...P.map(H=>({box:H,ids:S(H),move:(D,j)=>w(H,D,j)}))];x(R,C);if(b===void 0||R.length===0)return;const I=u.get(b);const L=d.get(I.id)??20;const $=Math.min(...R.map(H=>H.box.x))-L;const B=Math.min(...R.map(H=>H.box.y))-L-I.headerHeight;const F=Math.max($+(I.labelBlock?.width??Gd(I.label,i).width)+20,Math.max(...R.map(H=>H.box.x+H.box.width))+L);const z=F-$;const _=Math.max(...R.map(H=>H.box.y+H.box.height))+Math.max(L,o.get(I.id)??0)-B;if(I.x!==$||I.y!==B||I.width!==z||I.height!==_)y=true;Object.assign(I,{x:$,y:B,width:z,height:_})};M(void 0,e.direction??"LR");return y}function pX(e,t,n,i={operations:0}){const r=e.relationships.map(C=>Cr(C,t,n));const o=LI(e,r);const s=$I(e,t,n,i);const a=(e.direction??"LR")==="LR"||(e.direction??"LR")==="RL";const l=e.direction==="RL"||e.direction==="BT";const c=e.groups.filter(C=>!C.parentId);const d=l?[...c].reverse():c;const u=[];const f=(C,P,E)=>{const k=Gd(qe(C.label,C.labelContent),t);const v=t.groupHeaderFontSize+16+k.height-k.lineHeight;const T={id:C.id,label:C.label,...C.labelContent?{labelContent:C.labelContent}:{},labelBlock:k,...C.parentId?{parentId:C.parentId}:{},x:P,y:E,width:Math.max(160,k.width+20),height:Math.max(100,v+20),headerHeight:v};u.push(T);const A=s.get(C.id)??20;let R=P+A;let I=E+v+A;for(const L of e.groups.filter($=>$.parentId===C.id)){const $=f(L,R,I);T.width=Math.max(T.width,$.x+$.width-P+A);T.height=Math.max(T.height,$.y+$.height-E+Math.max(A,o.padding.get(C.id)??0));if(a)R+=$.width+20;else I+=$.height+Math.max(20,o.exits.get(L.id)??0)}return T};let h=Ct.padding;let m=Ct.padding;for(const C of d){const P=f(C,h,m);if(a)h+=P.width+40;else m+=P.height+30}_I(e,[],u,t,r,o.padding,o.exits,20,n,i,s);const p=new Map(u.map(C=>[C.id,C]));const g=e.relationships.map((C,P)=>{const E=p.get(C.entity1),k=p.get(C.entity2);const v=[];if(E&&k&&o.lanes.has(P)){v.push(...AI(E,k,o.lanes.get(P)))}else if(E&&k){v.push(...gy(E,k))}return{entity1:C.entity1,entity2:C.entity2,cardinality1:C.cardinality1,cardinality2:C.cardinality2,label:C.label,...C.labelContent?{labelContent:C.labelContent}:{},identifying:C.identifying,points:v}});py([],u,g,r,t,n,i);const y=g.flatMap(C=>C.points);const w=II(g,r);const S=Math.max(0,Ct.padding-Math.min(...u.map(C=>C.x),...y.map(C=>C.x)),...w.map(C=>-C.x0));const x=Math.max(0,Ct.padding-Math.min(...u.map(C=>C.y),...y.map(C=>C.y)),...w.map(C=>-C.y0));for(const C of u){C.x+=S;C.y+=x}for(const C of y){C.x+=S;C.y+=x}const M=Math.max(...u.map(C=>C.x+C.width+Ct.padding),...y.map(C=>C.x+Ct.padding),...w.map(C=>C.x1+S),0);const b=Math.max(...u.map(C=>C.y+C.height+Ct.padding),...y.map(C=>C.y+Ct.padding),...w.map(C=>C.y1+x),0);return{width:M,height:b,accessibilityTitle:e.accessibilityTitle,accessibilityDescription:e.accessibilityDescription,entities:[],relationships:g,groups:u}}function DI(e,t={},n){Am(e);const i=Ue(t,zd,n);const r={operations:0};const o=d=>{try{return d()}catch(u){if(t.graphLayout?.backend!=="agentic"||t.graphLayout.fallback!=="elk"||!(u instanceof Nt||u instanceof $d||u instanceof rs))throw u;const f=new Qe([{strategy:"er-final-geometry",violations:[u.message]}]);f.cause=u;throw f}};if(e.entities.length===0){const d=()=>tM({width:0,height:0,accessibilityTitle:e.accessibilityTitle,accessibilityDescription:e.accessibilityDescription,entities:[],relationships:[],groups:[]},e.title,i);const u=()=>e.groups.length?RI(tM(PI(pX(e,i,n,r),i,n),e.title,i),i,n,r):d();return Qr(t,()=>o(u),()=>{Qt(r,0);return u()},true)}const s=cX(e,i);const a=()=>{const d=new Map(e.entities.map((S,x)=>[S.id,x]));const u=new Set(e.groups.map(S=>S.id));const f=new Set([...d.keys(),...u]);const h=new Map;let m=t.layerSpacing??Ct.layerSpacing;let p=0;for(const S of e.relationships){const x=Qi(S,n);for(const[M,b]of[[S.entity1,S.cardinality1],[S.entity2,S.cardinality2]]){const C=Ya(b,i.lineWidth);Qt(r);if(!C)throw new Nt(S.entity1,S.entity2);const P=C.x1+(x?.lineWidth??i.lineWidth)/2+i.lineWidth+.25;const E=P+Math.min(x?.bendRadius??i.edgeBendRadius,P);p=Math.max(p,E);m=Math.max(m,4*E);if(!u.has(M))h.set(M,(h.get(M)??0)+C.y1-C.y0+i.lineWidth+.25)}}const g=new Map(e.entities.map(S=>{const x=s.get(S.id),M=(h.get(S.id)??0)+2*Math.max(8,i.cornerRadius??0);return[S.id,{...x,width:Math.max(x.width,M),height:Math.max(x.height,M)}]}));const y=e.relationships.flatMap((S,x)=>{const M=u.has(S.entity1)?void 0:d.get(S.entity1),b=u.has(S.entity2)?void 0:d.get(S.entity2);if(!f.has(S.entity1)||!f.has(S.entity2))throw new Error("ER relationship references an undeclared entity or frame");if(M===void 0||b===void 0)return[];const C=Cr(S,i,n);return[{relationshipIndex:x,source:M,target:b,minSpan:1,...S.label?{label:{width:C.width+16,height:C.height+16}}:{}}]});const w=ei("agentic",()=>Ua({nodes:e.entities.map(S=>({id:S.id,...g.get(S.id)})),edges:y,direction:e.direction??"LR",padding:Ct.padding,nodeSpacing:t.nodeSpacing??Ct.nodeSpacing,layerSpacing:m,...p>0?{minimumTerminalLead:p}:{},edgeSpacing:Math.max(6,i.lineWidth+4)}));return{width:w.width,height:w.height,preserveTerminalNormals:true,labelPlacement:"shaft-aware",entities:w.nodes.map((S,x)=>({id:e.entities[x].id,...S,...g.get(e.entities[x].id)})),routes:new Map(w.edges.map((S,x)=>[y[x].relationshipIndex,S.points])),labelPositions:new Map(w.edges.flatMap((S,x)=>S.labelPosition?[[y[x].relationshipIndex,{...S.labelPosition}]]:[]))}};const l=()=>{Qt(r,0);const{elkGraph:d}=dX(e,t,s,n,r);const u=qa(d);return{width:u.width,height:u.height,entities:u.children??[],routes:new Map((u.edges??[]).map(f=>{const h=f.sections?.[0];return[Number(f.id.slice(1)),h?Qs([h.startPoint,...h.bendPoints??[],h.endPoint]):[]]}))}};const c=d=>{const u=tM(PI(uX(d,e,s,i,n,r),i,n),e.title,i);return RI(u,i,n,r)};return Qr(t,()=>o(()=>c(a())),()=>c(l()),true)}function tM(e,t,n){const i=tn(t,n);if(!i)return e;if(e.width===0&&e.height===0)return{...e,...pa(i,Ct.padding)};const r=i.height;for(const s of e.entities)s.y+=r;for(const s of e.groups)s.y+=r;for(const s of e.relationships){for(const a of s.points)a.y+=r;if(s.labelPosition)s.labelPosition.y+=r}const o=Math.max(e.width,i.width+2*Ct.padding);return{...e,width:o,height:e.height+r,title:on(i,o,Ct.padding)}}function RI(e,t,n,i){const r=e.relationships;if(!r.length)return e;const o=(L=1)=>Qt(i,L);const s=(L,$)=>{o();return L.x0<$.x1&&L.x1>$.x0&&L.y0<$.y1&&L.y1>$.y0};const a=new Map([...e.entities,...e.groups].map(L=>[L.id,L]));const l=new Set(e.groups.map(L=>L.id));FI(e.entities,e.groups,r,i);const c=[...e.entities.map(L=>{const $=Number.parseFloat(L.inlineStyle?.["stroke-width"]??"");const B=(Number.isFinite($)&&$>0?$:t.nodeLineWidth)/2;return{id:L.id,box:{x0:L.x-B,y0:L.y-B,x1:L.x+L.width+B,y1:L.y+L.height+B}}}),...e.groups.flatMap(L=>{const $=L.x,B=L.y,F=$+L.width,z=B+L.height,_=.75;return[{id:L.id,group:true,box:{x0:$,y0:B,x1:F,y1:B+L.headerHeight}},{id:L.id,group:true,border:true,box:{x0:$-_,y0:B-_,x1:$+_,y1:z+_}},{id:L.id,group:true,border:true,box:{x0:F-_,y0:B-_,x1:F+_,y1:z+_}},{id:L.id,group:true,border:true,box:{x0:$-_,y0:B-_,x1:F+_,y1:B+_}},{id:L.id,group:true,border:true,box:{x0:$-_,y0:z-_,x1:F+_,y1:z+_}}]})];o(c.length+a.size);const d=()=>r.flatMap((L,$)=>{o();if(L.points.length<2)throw new Nt(L.entity1,L.entity2);return[0,1].map(B=>{const F=B?L.points.at(-1):L.points[0],z=B?L.points.at(-2):L.points[1];const _=Fo(F,z,B?L.cardinality2:L.cardinality1,t.lineWidth);o(2+(_?.length??0));if(!_?.length)throw new Nt(L.entity1,L.entity2);return{index:$,end:B,rel:L,id:B?L.entity2:L.entity1,point:F,toward:z,pieces:_}})});const u=(L,$,B,F)=>Math.max(0,...L.map(z=>{o();return F>0?B?z.x1-$.x:z.y1-$.y:B?$.x-z.x0:$.y-z.y0}));const f=()=>r.flatMap((L,$)=>{const B=Qi(L,n);const F=(B?.lineWidth??t.lineWidth)/2;const z=B?.bendRadius??t.edgeBendRadius;const _=(H,D,j,W)=>{o();if(D.y===j.y){if(j.x>D.x===W)H.x0=W?D.x:j.x;else H.x1=W?D.x:j.x}else if(D.x===j.x){if(j.y>D.y===W)H.y0=W?D.y:j.y;else H.y1=W?D.y:j.y}};if(z>0&&L.points.length>2){const H=qn(L.points,z,{metric:"manhattan"}).geometry;const D=[];let j;if(H.kind!=="path"||!Ss(H.d,W=>{o();const O={x0:W.bounds.x0-F,y0:W.bounds.y0-F,x1:W.bounds.x1+F,y1:W.bounds.y1+F};if(!D.length&&W.line)_(O,W.line[0],W.line[1],true);j=W.line;D.push({index:$,box:O,first:false,last:false,...W.line?{line:W.line}:{}});return true},()=>{o();return true}))throw new Nt(L.entity1,L.entity2);if(D.length){D[0].first=true;D.at(-1).last=true;if(j)_(D.at(-1).box,j[0],j[1],false)}return D}return L.points.slice(1).map((H,D)=>{o();const j=L.points[D];if(j.x!==H.x&&j.y!==H.y||![j.x,j.y,H.x,H.y,F].every(Number.isFinite))throw new Nt(L.entity1,L.entity2);const W={x0:Math.min(j.x,H.x)-F,y0:Math.min(j.y,H.y)-F,x1:Math.max(j.x,H.x)+F,y1:Math.max(j.y,H.y)+F};if(D===0)_(W,j,H,true);if(D===L.points.length-2)_(W,j,H,false);return{index:$,box:W,first:D===0,last:D===L.points.length-2,line:[j,H]}})});let h=hy(e,t,n,i);let m=Va(e)??na(e,t,n,i);const p=L=>r.flatMap(($,B)=>{o();const F=m.get($);if(!$.label||!F)return[];const z=$.labelBlock??Cr($,t,n);const _=L?{x0:F.x-z.width/2-8,y0:F.y-z.height/2-8,x1:F.x+z.width/2+8,y1:F.y+z.height/2+8}:N0(z,F);if(!_)throw new Nt($.entity1,$.entity2);return[{index:B,box:_}]});const g=L=>{o(L.pieces.length);return{x0:Math.min(...L.pieces.map($=>$.x0)),y0:Math.min(...L.pieces.map($=>$.y0)),x1:Math.max(...L.pieces.map($=>$.x1)),y1:Math.max(...L.pieces.map($=>$.y1))}};const y=Xr(c,L=>L.box,o,r.length*8);const w=()=>{const L=d(),$=f();const B=new Map(L.map(F=>[F,g(F)]));return{currentGlyphs:L,glyphQuery:Xr(L,F=>B.get(F),o,L.length),shaftQuery:Xr($,F=>F.box,o,L.length)}};let S=w();let x=false;const M=new Map;for(const L of d()){o();const $=L.point.y===L.toward.y;const B=$?L.toward.x>L.point.x?"E":"W":L.toward.y>L.point.y?"S":"N";const F=M.get(L.id)??new Map;const z=F.get(B)??[];z.push(L);F.set(B,z);M.set(L.id,F)}const b=[...M.values()].flatMap(L=>[...L.values()].flatMap($=>$.sort((B,F)=>{o();const z=B.point.y===B.toward.y;return(z?B.point.y-F.point.y:B.point.x-F.point.x)||B.index*2+B.end-F.index*2-F.end})));const C=new Map(b.map((L,$)=>[L.index*2+L.end,$]));o(b.length*2);for(const L of b){o();const $=a.get(L.id),B=L.end?L.rel.points.at(-1):L.rel.points[0];const F=L.end?L.rel.points.at(-2):L.rel.points[1];const z=F.y===B.y&&F.x!==B.x,_=F.x===B.x&&F.y!==B.y;const H=z?Math.sign(F.x-B.x):Math.sign(F.y-B.y);const D=z?B.x===(H>0?$.x+$.width:$.x):B.y===(H>0?$.y+$.height:$.y);if(!z&&!_||!D)continue;const j=z?B.y:B.x;const W=l.has(L.id)?6:Math.min(t.cornerRadius??0,$.width/2,$.height/2);let O=(z?$.y:$.x)+W,N=(z?$.y+$.height:$.x+$.width)-W;const{currentGlyphs:G,glyphQuery:Y,shaftQuery:q}=S,V=G.find(J=>J.index===L.index&&J.end===L.end);const ne=[...M.get(L.id).values()].flat().map(J=>G[J.index*2+J.end]).filter(J=>{o();if(J.id!==L.id||C.get(J.index*2+J.end)<=C.get(L.index*2+L.end))return false;return z?J.point.x===B.x&&J.toward.y===J.point.y&&Math.sign(J.toward.x-J.point.x)===H:J.point.y===B.y&&J.toward.x===J.point.x&&Math.sign(J.toward.y-J.point.y)===H});const X=new Set(ne);o(ne.length);const U=Qi(L.rel,n);const K=(U?.lineWidth??t.lineWidth)/2;const Z=u(V.pieces,B,z,H);const Q=Z+(U?.bendRadius??t.edgeBendRadius)+K+t.lineWidth+.25;const se=Math.min(Math.abs(z?F.x-B.x:F.y-B.y),Q);const te=z?{x:B.x+H*se,y:B.y}:{x:B.x,y:B.y+H*se};const ee={x0:Math.min(B.x,te.x)-(z?0:K),x1:Math.max(B.x,te.x)+(z?0:K),y0:Math.min(B.y,te.y)-(z?K:0),y1:Math.max(B.y,te.y)+(z?K:0)};const ae=[...V.pieces,ee];o(ae.length);const ie={x0:Math.min(...ae.map(J=>J.x0)),x1:Math.max(...ae.map(J=>J.x1)),y0:Math.min(...ae.map(J=>J.y0)),y1:Math.max(...ae.map(J=>J.y1))};if(z){ie.y0+=O-j;ie.y1+=N-j}else{ie.x0+=O-j;ie.x1+=N-j}const oe=t.lineWidth+.25;if(z){ie.y0-=oe;ie.y1+=oe}else{ie.x0-=oe;ie.x1+=oe}const ue=[...Y(ie).filter(J=>{o();return(J.index!==L.index||J.end!==L.end)&&!X.has(J)}).flatMap(J=>J.pieces),...q(ie).filter(J=>J.index!==L.index&&!ne.some(ge=>{o();return ge.index===J.index&&(ge.end?J.last:J.first)})).map(J=>J.box)];const ye=[...y(ie).filter(J=>J.id!==L.id||!!J.group!==l.has(L.id)).map(J=>J.box),...ue];const Se=new Set(G.filter(J=>J.index===L.index).flatMap(J=>J.pieces));o(Se.size);const Te=[...y(ie).filter(J=>(J.id!==L.id||!!J.group!==l.has(L.id))&&!J.border).map(J=>J.box),...ue.filter(J=>!Se.has(J))];const Ie=[...V.pieces.map(J=>({piece:J,occupied:ye})),{piece:ee,occupied:Te}];o(ye.length+Te.length+Ie.length);if(j>=O&&j<=N&&!Ie.some(({piece:J,occupied:ge})=>ge.some(Ce=>s(J,Ce))))continue;const Ee=G.find(J=>J.index===L.index&&J.end!==L.end);const ve=Ee.point.y===Ee.toward.y;if(z!==ve){const J=Math.sign(ve?Ee.toward.x-Ee.point.x:Ee.toward.y-Ee.point.y);const ge=Qi(L.rel,n);const Ce=u(Ee.pieces,Ee.point,ve,J)+(ge?.lineWidth??t.lineWidth)/2+t.lineWidth+.25;const Me=Ce+Math.min(ge?.bendRadius??t.edgeBendRadius,Ce);const le=ve?Ee.point.x:Ee.point.y;if(J>0)O=Math.max(O,le+Me);else N=Math.min(N,le-Me)}let $e=Math.max(O,Math.min(j,N));const De=[];for(const{piece:J,occupied:ge}of Ie)for(const Ce of ge){o();const Me=z?J.x0:J.y0,le=z?J.x1:J.y1;const we=z?Ce.x0:Ce.y0,ke=z?Ce.x1:Ce.y1;if(Me>=ke||le<=we)continue;const Le=t.lineWidth+.25;De.push([(z?Ce.y0:Ce.x0)-((z?J.y1:J.x1)-j)-Le,(z?Ce.y1:Ce.x1)-((z?J.y0:J.x0)-j)+Le])}De.sort((J,ge)=>{o();return J[0]-ge[0]||J[1]-ge[1]});for(const[J,ge]of De){o();if($e>J&&$e<ge)$e=ge}if($e>N){$e=Math.max(O,Math.min(j,N));for(let J=De.length-1;J>=0;J--){o();const[ge,Ce]=De[J];if($e>ge&&$e<Ce)$e=ge}if($e<O)throw new Nt(L.rel.entity1,L.rel.entity2)}if($e===j)continue;if($e>N)throw new Nt(L.rel.entity1,L.rel.entity2);const fe=L.rel.points.map(J=>({...J})),me=L.end?-1:1,de=L.end?fe.length-1:0;const be=z?"y":"x",pe=B[be],Re=$e-pe;let Ne=de;for(let J=de;J>=0&&J<fe.length&&fe[J][be]===pe;J+=me){o();Ne=J}if(Ne===(L.end?0:fe.length-1)){const J=fe[0],ge=fe.at(-1);fe[de][be]=$e;const Ce=G.find(ce=>ce.index===L.index&&ce.end===0),Me=G.find(ce=>ce.index===L.index&&ce.end===1);const le=Qi(L.rel,n);const we=ce=>{const Ae=Math.sign(z?ce.toward.x-ce.point.x:ce.toward.y-ce.point.y);const Pe=u(ce.pieces,ce.point,z,Ae)+(le?.lineWidth??t.lineWidth)/2+t.lineWidth+.25;return Pe+Math.min(le?.bendRadius??t.edgeBendRadius,Pe)};const ke=z?"x":"y",Le=Math.sign(ge[ke]-J[ke]),Fe=J[ke]+Le*we(Ce),Oe=ge[ke]-Le*we(Me);if((Oe-Fe)*Le<0)throw new Nt(L.rel.entity1,L.rel.entity2);const We=Math.max(Math.min(Fe,Oe),Math.min(Math.max(Fe,Oe),(J[ke]+ge[ke])/2));L.rel.points=pt(z?[J,{x:We,y:J.y},{x:We,y:ge.y},ge]:[J,{x:J.x,y:We},{x:ge.x,y:We},ge])}else{for(let J=de;J!==Ne+me;J+=me){o();fe[J][be]+=Re}L.rel.points=pt(fe)}if(!my(L.rel.points,i))throw new Nt(L.rel.entity1,L.rel.entity2);delete L.rel.finalLabelPosition;x=true;S=w()}if(x){py(e.entities,e.groups,r,r.map(L=>L.labelBlock??Cr(L,t,n)),t,n,i);h=hy(e,t,n,i);m=Va(e)??na(e,t,n,i)}if(h.length){o(r.length+h.length);const L=new Set(h);const $=new Set(r.flatMap((B,F)=>L.has(B)?[F]:[]));py(e.entities,e.groups,r,r.map(B=>B.labelBlock??Cr(B,t,n)),t,n,i,{indices:$,admit:(B,F)=>CI(e,B,F,t,n,i)});e.width=Math.max(e.width,...r.flatMap(B=>B.points.map(F=>F.x+Ct.padding)));e.height=Math.max(e.height,...r.flatMap(B=>B.points.map(F=>F.y+Ct.padding)));hy(e,t,n,i);m=Va(e)??na(e,t,n,i)}const P=d(),E=f(),k=p(false);for(const L of r)if(!my(L.points,i))throw new Nt(L.entity1,L.entity2);for(const L of r)for(let $=1;$<L.points.length;$++){for(const B of e.entities){o();if($i(L.points[$-1],L.points[$],{...B,label:"",shape:"rectangle"}))throw new Nt(L.entity1,L.entity2)}for(const B of e.groups){o();if(B.headerHeight>0&&$i(L.points[$-1],L.points[$],{...B,height:B.headerHeight,label:"",shape:"rectangle"}))throw new Nt(L.entity1,L.entity2)}}const v=(L,$,B,F,z,_)=>{if(l.has($)!==_)return false;const H=r[L.index];const D=L.first&&H.entity1===$?0:L.last&&H.entity2===$?1:void 0;if(D===void 0)return false;const j=D?H.points.at(-1):H.points[0],W=D?H.points.at(-2):H.points[1];const O=j.y>=B.y+z&&j.y<=B.y+B.height-z;const N=j.x>=B.x+z&&j.x<=B.x+B.width-z;o();return O&&W.y===j.y&&(j.x===B.x&&W.x<j.x&&L.box.x1<=B.x+F||j.x===B.x+B.width&&W.x>j.x&&L.box.x0>=B.x+B.width-F)||N&&W.x===j.x&&(j.y===B.y&&W.y<j.y&&L.box.y1<=B.y+F||j.y===B.y+B.height&&W.y>j.y&&L.box.y0>=B.y+B.height-F)};for(const L of E){const $=r[L.index];for(const B of e.entities){const F=Number.parseFloat(B.inlineStyle?.["stroke-width"]??"");const z=(Number.isFinite(F)&&F>0?F:t.nodeLineWidth)/2;const _={x0:B.x-z,y0:B.y-z,x1:B.x+B.width+z,y1:B.y+B.height+z};if(s(L.box,_)&&!v(L,B.id,B,z,Math.min(t.cornerRadius??0,B.width/2,B.height/2),false))throw new Nt($.entity1,$.entity2)}for(const B of e.groups){const F={x0:B.x,y0:B.y,x1:B.x+B.width,y1:B.y+B.headerHeight};if(B.headerHeight>0&&s(L.box,F)&&!v(L,B.id,B,.75,6,true))throw new Nt($.entity1,$.entity2)}}const T=new Map(P.map(L=>{o(L.pieces.length*4+1);return[L,{x0:Math.min(...L.pieces.map($=>$.x0)),y0:Math.min(...L.pieces.map($=>$.y0)),x1:Math.max(...L.pieces.map($=>$.x1)),y1:Math.max(...L.pieces.map($=>$.y1))}]}));const A=Xr(P,L=>T.get(L),o,P.length+k.length);const R=Xr(E,L=>L.box,o,P.length*4+k.length);const I=Xr(k,L=>L.box,o,k.length);for(const L of P)for(const $ of A(T.get(L))){o();if($.index*2+$.end<=L.index*2+L.end)continue;for(const B of L.pieces)if($.pieces.some(F=>s(B,F)))throw new Nt(L.rel.entity1,L.rel.entity2)}for(const L of P){const $=L.toward.x-L.point.x,B=L.toward.y-L.point.y;const F=B===0&&$!==0,z=$===0&&B!==0;const _=Math.sign(F?$:B);const H=E.find(O=>{o();return O.index===L.index&&(L.end?O.last:O.first)});const D=H?.line,j=D&&(L.end?D[0]:D[1]),W=D&&(L.end?D[1]:D[0]);if(!F&&!z||!j||!W||(F?j.y!==W.y||Math.sign(j.x-W.x)!==_:j.x!==W.x||Math.sign(j.y-W.y)!==_)||_*((F?j.x:j.y)-(F?L.point.x:L.point.y))<u(L.pieces,L.point,F,_))throw new Nt(L.rel.entity1,L.rel.entity2);for(const O of L.pieces){for(const N of y(O))if((N.id!==L.id||!!N.group!==l.has(L.id))&&s(O,N.box))throw new Nt(L.rel.entity1,L.rel.entity2);for(const N of R(O))if((N.index!==L.index||!(L.end?N.last:N.first))&&s(O,N.box))throw new Nt(L.rel.entity1,L.rel.entity2)}}for(const L of k){const $=r[L.index];for(const B of y(L.box))if(s(L.box,B.box))throw new Nt($.entity1,$.entity2);for(const B of A(L.box))if(s(L.box,T.get(B))&&B.pieces.some(F=>s(L.box,F)))throw new Nt($.entity1,$.entity2);for(const B of R(L.box))if(B.index!==L.index&&s(L.box,B.box))throw new Nt($.entity1,$.entity2);for(const B of I(L.box))if(B.index<L.index&&s(L.box,B.box))throw new Nt($.entity1,$.entity2)}return e}function OI({positioned:e,options:t}){const n=e.entities.map(l=>({id:l.id,x:xe(l.x),y:xe(l.y),w:Gt(l.x,l.width),h:Gt(l.y,l.height),shape:"rectangle",label:l.label,...bt(l.labelBlock,l.x+l.width/2,l.y+l.headerHeight/2,{...l,height:l.headerHeight})}));const i=new Map(e.entities.map(l=>[l.id,{x:l.x,y:l.y,width:l.width,height:l.height}]));const r=Va(e);if(e.labelPlacement==="shaft-aware"&&!r)throw new Error("ER_LABEL_LAYOUT_MISSING: project the complete native family layout artifact");const o=r??na(e,Ue({},zd));const s=e.relationships.map((l,c)=>{const d=o.get(l);return{id:`rel#${c}:${l.entity1}->${l.entity2}`,from:l.entity1,to:l.entity2,path:l.points.map(u=>[xe(u.x),xe(u.y)]),label:l.label&&d?{x:xe(d.x),y:xe(d.y),text:l.label,bounds:qt(l.labelBlock,d.x,d.y)}:void 0,route:t.debug?Kg("er",c,l.points,i.get(l.entity1),i.get(l.entity2)):void 0}});const a=e.groups.map(l=>({id:l.id,x:xe(l.x),y:xe(l.y),w:Gt(l.x,l.width),h:Gt(l.y,l.height),members:[...e.entities.filter(c=>c.groupId===l.id).map(c=>c.id),...e.groups.filter(c=>c.parentId===l.id).map(c=>c.id)],label:l.label,parentId:l.parentId}));return{version:1,nodes:n,edges:s,groups:a,bounds:{w:xe(e.width),h:xe(e.height)}}}function by({positioned:e,options:t}){return cA(e,t)}function BI({positioned:e,options:t}){const n=e.plot.x+e.plot.w;const i=e.bars.map(s=>{const a=s.id??`task#${s.taskIndex}`;const l=s.labelPosition;const c=l&&!e.compact&&s.labelBlock?l.y+(s.labelBlock.height-s.labelBlock.lineHeight)/2:l?.y;const d=l&&c!==void 0?bt(s.labelBlock,l.x,c,Ut(e),l.anchor):{};if(s.milestoneX!==void 0){const h=s.h/2;return{id:a,x:xe(s.milestoneX-h),y:xe(s.y),w:Gt(s.milestoneX-h,s.h),h:Gt(s.y,s.h),shape:"diamond",label:s.label,...d}}const u=Math.max(2,s.w);const f=Math.min(s.x,n-u);return{id:a,x:xe(f),y:xe(s.y),w:Gt(f,u),h:Gt(s.y,s.h),shape:"rectangle",label:s.label,...d}});const r=e.sections.map((s,a)=>({id:`section#${a}`,x:xe(e.plot.x),y:xe(s.y),w:Gt(e.plot.x,e.plot.w),h:Gt(s.y,s.h),members:e.bars.filter(l=>l.sectionIndex===a).map(l=>l.id??`task#${l.taskIndex}`),label:s.label}));const o={version:1,nodes:i,edges:[],groups:r,bounds:{w:xe(e.width),h:xe(e.height)}};if(t.debug)o.certificates=is("gantt",o,"section-contained");return o}var yh=12;function Pr(e,t,n,i={}){return Be(e,{display:"literal",fontSize:t,fontWeight:n,...i})}function Sy(e,t){return-6-e[t].fontSize-e.slice(0,t).reduce((n,i)=>n+i.height+5,0)-(e[t].height-e[t].lineHeight)/2}function Ka(e,t){const n=e.height-e.lineHeight;return t==="LR"?24+n:4+n/2}function zI(e,t={}){const n=yX(t.padding,44);const i=t.showBranches!==false;const r=t.showCommitLabel!==false;const o=t.rotateCommitLabel!==false;const s=xX(t.commitLabelFontSize,11);const a=Ue(t.renderOptions??{},{...zi,nodeLabelFontSize:s,nodeLabelFontWeight:500,groupHeaderFontSize:12,groupHeaderFontWeight:600},t.styleFace);const l=Ue(t.renderOptions??{},{...zi,nodeLabelFontSize:10,nodeLabelFontWeight:600},t.styleFace);const c=Ue(t.renderOptions??{},{...zi,groupHeaderFontSize:16,groupHeaderFontWeight:600},t.styleFace);const d=_=>({..._,labelBlock:Pr(xa(_),a.nodeLabelFontSize,a.nodeLabelFontWeight,{transform:a.nodeTextTransform,letterSpacing:a.nodeLetterSpacing}),tagBlocks:_.tags.map(H=>Pr(H,l.nodeLabelFontSize,l.nodeLabelFontWeight,{transform:l.nodeTextTransform,letterSpacing:l.nodeLetterSpacing}))});const u=e.commits.map(d);const f=e.title?Pr(e.title,c.groupHeaderFontSize,c.groupHeaderFontWeight,{transform:c.groupTextTransform,letterSpacing:c.groupLetterSpacing}):void 0;const h=f?40-16*hi+f.height:0;const m=e.branches.map(_=>({..._,labelBlock:Pr(_.name,a.groupHeaderFontSize,a.groupHeaderFontWeight,{transform:a.groupTextTransform,letterSpacing:a.groupLetterSpacing})})).sort((_,H)=>_.order-H.order||_.sequence-H.sequence||Bn(_.name,H.name));const p=new Map(m.map((_,H)=>[_.name,H]));const g=new Map(u.map(_=>[_.id,_]));const y=new Map;for(const _ of u){const H=_.parents.length===0?0:Math.max(..._.parents.map(D=>y.get(D)??0))+1;y.set(_.id,H)}const w=_=>t.parallelCommits?y.get(_.id):_.sequence;const S=Math.max(0,...u.map(w));const x=Math.max(82,...m.map(_=>_.labelBlock.height+20),...u.map(_=>{const H=WI(_,e.direction,o,s,r);return H.maxY-H.minY+20}));const M=Math.max(150,...m.map(_=>_.labelBlock.width+20));const b=94;const C=i?Math.max(80,...m.map(_=>_.labelBlock.width+24)):20;const P=new Map;for(const _ of u){const H=w(_);const D=WI(_,e.direction,o,s,r);const j=P.get(H);P.set(H,j?{minX:Math.min(j.minX,D.minX),minY:Math.min(j.minY,D.minY),maxX:Math.max(j.maxX,D.maxX),maxY:Math.max(j.maxY,D.maxY)}:D)}const E=new Map;const k=Array.from({length:S+1},(_,H)=>e.direction==="BT"?S-H:H);for(const[_,H]of k.entries()){const D=P.get(H)??{minX:-10,minY:-10,maxX:10,maxY:10};const j=e.direction==="LR"?D.minX:D.minY;if(_===0){E.set(H,e.direction==="LR"?Math.max(0,-j):0);continue}const W=k[_-1];const O=P.get(W)??{minX:-10,minY:-10,maxX:10,maxY:10};const N=E.get(W);const G=e.direction==="LR"?O.maxX:O.maxY;E.set(H,Math.max(N+b,N+G-j+18))}const v=n+C+20;const T=n+h+38;const A=u.map(_=>{const H=p.get(_.branch)??0;const D=w(_);if(e.direction==="LR"){return{..._,lane:H,x:v+E.get(D),y:n+h+H*x}}return{..._,lane:H,x:n+C+H*M,y:T+E.get(D)}});const R=new Map(A.map(_=>[_.id,_]));const I=[];const L=new Map;for(const _ of A){const H=e.direction==="LR"?_.x:_.y;L.set(_.branch,Math.max(L.get(_.branch)??-Infinity,H));for(const[D,j]of[...new Set(_.parents)].entries()){const W=R.get(j);if(!W)continue;const O=e.direction==="LR"?(W.x+_.x)/2:(W.y+_.y)/2;const N=e.direction==="LR"?[{x:W.x,y:W.y},{x:O,y:W.y},{x:O,y:_.y},{x:_.x,y:_.y}]:[{x:W.x,y:W.y},{x:W.x,y:O},{x:_.x,y:O},{x:_.x,y:_.y}];const G=D===0?"parent":_.source==="cherry-pick"?"cherry-pick":"merge";I.push({from:W.id,to:_.id,kind:G,points:N})}}const $=m.map((_,H)=>{const D=L.get(_.name)??-Infinity;if(e.direction==="LR"){const W=n+h+H*x;return{..._,lane:H,x1:v-14,y1:W,x2:Math.max(v,D),y2:W}}const j=n+C+H*M;return{..._,lane:H,x1:j,y1:n+h-14,x2:j,y2:Math.max(T,D)}});let B;let F;if(e.direction==="LR"){B=Math.max(n*2+C+80,...A.map(_=>_.x+(r?Math.max(26,_.labelBlock.width*.75):18)))+n;F=n*2+h+Math.max(0,m.length-1)*x+82+(r?s*2+26:0)}else{B=n*2+C+Math.max(1,m.length)*M;F=Math.max(n*2+h+80,...A.map(_=>_.y+(r?38:18)))+n}if(e.title)B=Math.max(B,f.width+n*2);const z=[...A.flatMap(_=>[...r?[gX(_,e.direction,o,s)]:[],..._.tags.map((H,D)=>rM(_.tagBlocks[D],_.x+14,_.y+Sy(_.tagBlocks,D),10,600,"start",0))]),...i?$.map(_=>rM(_.labelBlock,e.direction==="LR"?_.x1-10:_.x1,e.direction==="LR"?_.y1:_.y1-16,12,600,e.direction==="LR"?"end":"middle",0)):[]];if(z.length>0){const _=Math.min(...z.map(G=>G.minX));const H=Math.min(...z.map(G=>G.minY));const D=Math.max(...z.map(G=>G.maxX));const j=Math.max(...z.map(G=>G.maxY));const W=_<n?n-_:0;const O=n+h;const N=H<O?O-H:0;if(W!==0||N!==0){for(const G of A){G.x+=W;G.y+=N}for(const G of $){G.x1+=W;G.x2+=W;G.y1+=N;G.y2+=N}for(const G of I)for(const Y of G.points){Y.x+=W;Y.y+=N}}B=Math.max(B+W,D+W+n);F=Math.max(F+N,j+N+n)}for(const _ of A){_.x=ss(_.x);_.y=ss(_.y)}for(const _ of $){_.x1=ss(_.x1);_.y1=ss(_.y1);_.x2=ss(_.x2);_.y2=ss(_.y2)}for(const _ of I)for(const H of _.points){H.x=ss(H.x);H.y=ss(H.y)}return{width:ss(B),height:ss(F),direction:e.direction,...e.title?{title:e.title,titleBlock:f}:{},commits:A,branches:$,edges:I,accessibilityTitle:e.accessibilityTitle,accessibilityDescription:e.accessibilityDescription,showBranches:i,showCommitLabel:r,rotateCommitLabel:o}}function WI(e,t,n,i,r){const o=[{minX:-10,minY:-10,maxX:10,maxY:10}];if(r){const a=e.labelBlock??Pr(xa(e),i,500);o.push(iM(a,t==="LR"?0:14,Ka(a,t),i,t==="LR"?"middle":"start",t==="LR"&&n?45:0))}const s=e.tagBlocks??e.tags.map(a=>Pr(a,10,600));for(const[a,l]of e.tags.entries()){const c=rM(s[a],14,Sy(s,a),10,600,"start",0);o.push({...c,minX:c.minX-4,maxX:c.maxX+6,minY:c.minY-2,maxY:c.maxY+2})}return{minX:Math.min(...o.map(a=>a.minX)),minY:Math.min(...o.map(a=>a.minY)),maxX:Math.max(...o.map(a=>a.maxX)),maxY:Math.max(...o.map(a=>a.maxY))}}function gX(e,t,n,i){const r=e.labelBlock??Pr(xa(e),i,500);return t==="LR"?iM(r,e.x,e.y+Ka(r,t),i,"middle",n?45:0):iM(r,e.x+14,e.y+Ka(r,t),i,"start",0)}function iM(e,t,n,i,r,o){const s=typeof e==="string"?Pr(e,i,500):e;i=s.fontSize;const a=s.height-s.lineHeight;const l=Math.max(18,s.width+yh*2);const c=r==="middle"?-l/2:-yh;const d=hl({x0:t+c,y0:n-i-a/2,x1:t+c+l,y1:n+6+a/2},{x:t,y:n},o);return{minX:d.x0,minY:d.y0,maxX:d.x1,maxY:d.y1}}function rM(e,t,n,i,r,o,s){const a=typeof e==="string"?Pr(e,i,r):e;i=a.fontSize;const l=a.height-a.lineHeight;const c=a.width;const d=o==="middle"?-c/2:o==="end"?-c:0;const u=-i-l/2;const f=i*.28+l/2;const h=hl({x0:t+d,y0:n+u,x1:t+d+c,y1:n+f},{x:t,y:n},s);return{minX:h.x0,minY:h.y0,maxX:h.x1,maxY:h.y1}}function yX(e,t){return typeof e==="number"&&Number.isFinite(e)&&e>=0?e:t}function xX(e,t){return typeof e==="number"&&Number.isFinite(e)&&e>0?e:t}function ss(e){return Math.round(e*1e3)/1e3}function GI({positioned:e}){const t=e.commits.map(r=>{const o=r.customType??r.type;const s=r.labelBlock;let a=s&&e.showCommitLabel?qt(s,e.direction==="LR"?r.x:r.x+14,r.y+Ka(s,e.direction)-s.fontSize*.35,e.direction==="LR"?"middle":"start"):void 0;if(a&&e.direction==="LR"&&e.rotateCommitLabel&&s){const l=hl({x0:a.x,y0:a.y,x1:a.x+a.w,y1:a.y+a.h},{x:r.x,y:r.y+Ka(s,e.direction)},45);a=ln({x:l.x0,y:l.y0,width:l.x1-l.x0,height:l.y1-l.y0})}return{id:r.id,x:xe(r.x-10),y:xe(r.y-10),w:xe(20),h:xe(20),shape:o==="CHERRY_PICK"?"diamond":o==="HIGHLIGHT"?"rectangle":"ellipse",label:r.message||r.id,labelVisibility:e.showCommitLabel?"visible":"hidden",labelBounds:a,labelContainer:ln(Ut(e))}});const n=e.edges.map((r,o)=>({id:`edge#${o}:${r.from}->${r.to}`,from:r.from,to:r.to,path:r.points.map(s=>[xe(s.x),xe(s.y)])}));const i=e.showBranches?e.branches.map(r=>{const o=e.commits.filter(d=>d.branch===r.name);const s=Math.min(r.x1,r.x2,...o.map(d=>d.x-10));const a=Math.min(r.y1,r.y2,...o.map(d=>d.y-10));const l=Math.max(r.x1,r.x2,...o.map(d=>d.x+10));const c=Math.max(r.y1,r.y2,...o.map(d=>d.y+10));return{id:`branch:${r.name}`,x:xe(s),y:xe(a),w:Gt(s,Math.max(1,l-s)),h:Gt(a,Math.max(1,c-a)),members:o.map(d=>d.id),label:r.name}}):[];return{version:1,nodes:t,edges:n,groups:i,bounds:{w:xe(e.width),h:xe(e.height)}}}function HI({positioned:e}){const t=[];const n=[];for(const i of e.sections){const r=[];for(const s of i.tasks){t.push({id:s.id,x:xe(s.x),y:xe(s.y),w:xe(s.width),h:xe(s.height),shape:"rectangle",label:s.text,...bt(s.block,s.textX,s.textY,s)});r.push(s.id)}const o=i.tasks.length>0?Math.max(i.y+i.height,...i.tasks.map(s=>s.y+s.height)):i.y+i.height;n.push({id:i.id,x:xe(i.x),y:xe(i.y),w:xe(i.width),h:xe(o-i.y),members:r,label:i.label})}return{version:1,nodes:t,edges:[],groups:n,bounds:{w:xe(e.width),h:xe(e.height)}}}function jI({positioned:e}){const t=e.nodes.map(i=>({id:i.id,x:xe(i.x),y:xe(i.y),w:xe(i.width),h:xe(i.height),shape:i.shape==="circle"?"ellipse":"rectangle",label:i.label,...bt(i.labelBlock,i.x+i.width/2,i.y+i.height/2+(i.icon?5:0),i)}));const n=e.edges.map((i,r)=>({id:`edge#${r}:${i.from}->${i.to}`,from:i.from,to:i.to,path:i.points.map(o=>[xe(o.x),xe(o.y)])}));return{version:1,nodes:t,edges:n,groups:[],bounds:{w:xe(e.width),h:xe(e.height)}}}var Oi={fontSize:15,fontWeight:500,height:32,padX:14,offsetY:12,rx:8,minY:4,pointerSize:6};var Hd=e=>(Math.round(e*100)/100).toString();function Ja(e,t,n){const i=Be(n.replace(/[\t\n\r ]+/g," ").trim(),{display:"literal",fontSize:Oi.fontSize,fontWeight:Oi.fontWeight});const r=i.width+Oi.padX*2;const o=e-r/2;const s=Math.max(Oi.minY,t-Oi.offsetY-Oi.height);const a=s+Oi.height;const l=Oi.pointerSize;const c=`M${Hd(e-l)},${Hd(a)} L${Hd(e+l)},${Hd(a)} L${Hd(e)},${Hd(a+l)} Z`;return{text:n,block:i,bgW:r,bgX:o,bgY:s,textX:e,textY:s+Oi.height/2,ptrPath:c}}function jd(e){if(Number.isInteger(e))return String(e);const t=Math.round(e*100)/100;return String(Number.isFinite(t)&&(t!==0||e===0)?t:e)}function YI(e){const t=e.reduce((n,i)=>n+i.value,0);if(!Number.isFinite(t))throw new Error("Pie total exceeds the finite numeric range; rescale the values");if(e.some(n=>n.value>0&&n.value/t===0))throw new Error("Pie slice share underflows the finite numeric range; rescale the values");return t}var oM={textPosition:.75,donutHole:0,legendPosition:"right",paletteOverrides:[]};var bX=["top","bottom","left","right","center"];function xh(e){if(typeof e==="number"&&Number.isFinite(e)&&e>0)return e;if(typeof e==="string"){const t=/^([+-]?(?:\d+(?:\.\d+)?|\.\d+))(?:px)?$/.exec(e.trim());if(t){const n=Number.parseFloat(t[1]);if(Number.isFinite(n)&&n>0)return n}}return void 0}function sM(e={}){const t=Sn(e,["pie"])??{};const n=Sn(e,["themeVariables"])??{};const i={...oM,paletteOverrides:[]};const r=t.textPosition;if(typeof r==="number"&&Number.isFinite(r)&&r>=0&&r<=1){i.textPosition=r}const o=t.donutHole;if(typeof o==="number"&&Number.isFinite(o)&&o>0&&o<=.9){i.donutHole=o}const s=t.legendPosition;if(typeof s==="string"&&bX.includes(s)){i.legendPosition=s;i.legendPositionExplicit=true}if(typeof t.highlightSlice==="string"&&t.highlightSlice.trim()){i.highlightSlice=t.highlightSlice.trim()}for(let w=0;w<12;w++){const S=Zn(n[`pie${w+1}`]);if(S!==void 0)i.paletteOverrides[w]=S}i.paletteOverrides=Array.from(i.paletteOverrides,w=>w??null);const a=Zn(n.pieStrokeColor);if(a!==void 0)i.strokeColor=a;const l=xh(n.pieStrokeWidth);if(l!==void 0)i.strokeWidth=l;const c=xh(n.pieOuterStrokeWidth);if(c!==void 0)i.outerStrokeWidth=c;const d=Zn(n.pieOuterStrokeColor);if(d!==void 0)i.outerStrokeColor=d;const u=n.pieOpacity;if(typeof u==="number"&&Number.isFinite(u)&&u>=0&&u<=1){i.opacity=u}const f=xh(n.pieSectionTextSize);if(f!==void 0)i.sectionTextSize=f;const h=Zn(n.pieSectionTextColor);if(h!==void 0)i.sectionTextColor=h;const m=xh(n.pieTitleTextSize);if(m!==void 0)i.titleTextSize=m;const p=Zn(n.pieTitleTextColor);if(p!==void 0)i.titleTextColor=p;const g=xh(n.pieLegendTextSize);if(g!==void 0)i.legendTextSize=g;const y=Zn(n.pieLegendTextColor);if(y!==void 0)i.legendTextColor=y;return i}function Yd(e,t){let n=t.top??0,i=0,r=0;const o=e.map(l=>{const c=Math.max(t.minRowHeight??0,l.block.height);const d={item:l,top:n,height:c,textY:n+(t.align==="start"?l.block.height:c)/2};i=Math.max(i,l.block.width,l.reservedWidth??0);r+=c;n+=c+t.gap;return d});const s=Math.max(0,e.length-(t.trailingGap?0:1));const a=n-(e.length&&!t.trailingGap?t.gap:0);return{width:i,height:r+s*t.gap,bottom:a,rows:o}}function qd(e,t){const n=Yd(e,t);const i={width:t.leadingWidth+n.width,height:n.height,columns:1,rows:n.rows};if(t.maxWidth===void 0||e.length<4)return i;const r=[0,0];for(const[c,d]of e.entries()){if(d.block.lines.length!==1)return i;const u=c%2;r[u]=Math.max(r[u],t.leadingWidth+d.block.width,t.leadingWidth+(d.reservedWidth??0))}const o=r[0]+t.columnGap+r[1];if(o>t.maxWidth+.01)return i;const s=[];let a=t.top??0,l=0;for(let c=0;c<e.length;c+=2){const d=e.slice(c,c+2);const u=Math.max(t.minRowHeight??0,...d.map(f=>f.block.height));for(const[f,h]of d.entries())s.push({item:h,x:f?r[0]+t.columnGap:0,top:a,height:u,textY:a+u/2});l+=u;a+=u+t.gap}l+=(Math.ceil(e.length/2)-1)*t.gap;return l<n.height?{width:o,height:l,columns:2,rows:s}:i}function wy(e,t,n){let i=e,r=e,o=1;if(e.width>t+.01){for(const s of[1,2]){const a=n(s,r);if(!a)break;o++;r=a;if(a.width<i.width)i=a;if(a.width<=t+.01){i=a;break}}}return Object.assign(i,{widthFit:{maxWidth:t,width:i.width,attempts:o,status:i.width<=t+.01?"fitted":"exceeded"}})}var ct={paddingX:24,paddingY:24,titleFontSize:18,titleFontWeight:600,titleGap:20,radius:95,circleToLegendGap:32,circleToLegendStackGap:24,legendFontSize:13,legendFontWeight:500,sliceStrokeWidth:1.5,legendLineHeight:13*1.3,legendSwatch:14,legendRowGap:8,legendColumnGap:16,legendSwatchToText:8,legendHighlightWidthScale:1.1,sliceLabelFontSize:12,sliceLabelFontWeight:500,sliceLabelFitPad:4};var XI=ct.sliceLabelFontWeight;var bh=700;var aM={nodeLabelFontSize:ct.legendFontSize,edgeLabelFontSize:ct.legendFontSize,groupHeaderFontSize:ct.titleFontSize,nodeLabelFontWeight:ct.legendFontWeight,edgeLabelFontWeight:ct.legendFontWeight,groupHeaderFontWeight:ct.titleFontWeight,nodePaddingX:0,nodePaddingY:0,nodeLineWidth:ct.sliceStrokeWidth,edgeLineWidth:et.connector,groupCornerRadius:0,groupPaddingX:0,groupPaddingY:0,groupLineWidth:et.outerBox};function ky(e){return jd(e)}function pc(e){if(!(e>0))return"0.0%";const t=Math.max(.1,Math.round(e*1e3)/10);return`${t.toFixed(1)}%`}function SX(e){return`${(e*100).toFixed(0)}%`}function wX(e,t,n,i,r,o=0){const s=r-i;const a=o>0?Math.min(o,n):0;if(s>=Math.PI*2-1e-9){const h=dt(e);const m=dt(t-n);const p=dt(t+n);const g=`M ${h} ${m} A ${dt(n)} ${dt(n)} 0 1 1 ${h} ${p} A ${dt(n)} ${dt(n)} 0 1 1 ${h} ${m} Z`;if(a<=0)return g;const y=dt(t-a);const w=dt(t+a);const S=`M ${h} ${y} A ${dt(a)} ${dt(a)} 0 1 0 ${h} ${w} A ${dt(a)} ${dt(a)} 0 1 0 ${h} ${y} Z`;return`${g} ${S}`}const l=My(e,t,n,i);const c=My(e,t,n,r);const d=s>Math.PI?1:0;if(a<=0){return`M ${dt(e)} ${dt(t)} L ${dt(l.x)} ${dt(l.y)} A ${dt(n)} ${dt(n)} 0 ${d} 1 ${dt(c.x)} ${dt(c.y)} Z`}const u=My(e,t,a,i);const f=My(e,t,a,r);return`M ${dt(l.x)} ${dt(l.y)} A ${dt(n)} ${dt(n)} 0 ${d} 1 ${dt(c.x)} ${dt(c.y)} L ${dt(f.x)} ${dt(f.y)} A ${dt(a)} ${dt(a)} 0 ${d} 0 ${dt(u.x)} ${dt(u.y)} Z`}function My(e,t,n,i){return{x:e+n*Math.sin(i),y:t-n*Math.cos(i)}}function dt(e){return Math.round(e*100)/100}function UI(e,t={},n=oM,i){const r=qI(e,t,n,i);const o=t.pie?.maxWidth;if(o===void 0)return r;return wy(r,o,s=>{if(s!==1)return void 0;const a=n.legendPositionExplicit||n.legendPosition!=="right"?n.legendPosition:"bottom";return qI(e,t,{...n,legendPosition:a},i,o)})}function qI(e,t,n,i,r){const o=Ue(t,aM,i);const s=YI(e.entries);const a=ct.radius;const l=a*2;const c=n.donutHole>0?dt(n.donutHole*a):0;const d=r===void 0?void 0:Math.max(r,l+ct.paddingX*2);const u=ct.paddingX*2+ct.legendSwatch+ct.legendSwatchToText+(n.legendPosition==="left"||n.legendPosition==="right"?l+ct.circleToLegendGap:0);const f=d===void 0||d<=u?void 0:d-u;const h=n.titleTextSize??o.groupHeaderFontSize;const m=n.legendTextSize??o.nodeLabelFontSize;const p=m*1.3;let g=e.title?Be(e.displayTitle??e.title,{display:e.displayTitle===void 0?"formatted":"literal",transform:o.groupTextTransform,fontSize:h,fontWeight:o.groupHeaderFontWeight,letterSpacing:o.groupLetterSpacing,safeFont:true,...d===void 0?{}:{maxWidth:d-ct.paddingX*2}}):void 0;if(g&&d!==void 0&&g.width>d-ct.paddingX*2+.01){g=Be(g.prepared,g)}const y=g?.text;const w=g?g.height:0;const S=g?w+ct.titleGap:0;const x=g?.width??0;const M=n.highlightSlice==="hover"?void 0:n.highlightSlice;const b=e.entries.map(D=>{const j=s>0?D.value/s:0;const W=e.showData?` [${ky(D.value)}]`:"";const O=`${W} (${pc(j)})`;const N=(D.displayLabel??D.label).split("\n");const G=M===D.label?bh:o.nodeLabelFontWeight;const Y=N.map((Z,Q)=>Q===N.length-1?`${Z}${O}`:Z).join("\n");const q=G===bh?ct.legendHighlightWidthScale:1;const V=n.legendPosition==="center"?void 0:f===void 0?void 0:f/q;let ne=Be(Y,{display:D.displayLabel===void 0?"formatted":"literal",transform:o.nodeTextTransform,fontSize:m,fontWeight:G,letterSpacing:o.nodeLetterSpacing,safeFont:true,...V===void 0?{}:{maxWidth:V}});if(V!==void 0&&ne.width>V+.01)ne=Be(ne.prepared,ne);const X=ne.lines;const U=ne.width;const K=G===bh?U*ct.legendHighlightWidthScale:U;return{block:ne,lines:X,fraction:j,textWidth:K,reservedWidth:K}});const C={gap:ct.legendRowGap,minRowHeight:ct.legendSwatch,leadingWidth:ct.legendSwatch+ct.legendSwatchToText,columnGap:ct.legendColumnGap,...d!==void 0&&(n.legendPosition==="top"||n.legendPosition==="bottom")?{maxWidth:d-ct.paddingX*2}:{}};const P=qd(b,C);const E=P.width;const k=P.height;const v=ct.paddingY+S;const T=n.legendPosition;let A;let R;let I;let L;let $;let B;if(T==="left"||T==="right"){const D=Math.max(l,k);R=v+D/2;L=v+(D-k)/2;if(T==="right"){A=ct.paddingX+a;I=ct.paddingX+l+ct.circleToLegendGap;$=I+E+ct.paddingX}else{I=ct.paddingX;A=ct.paddingX+E+ct.circleToLegendGap+a;$=A+a+ct.paddingX}$=Math.max($,x+2*ct.paddingX);B=v+D+ct.paddingY}else{const D=Math.max(l,E);$=Math.max(ct.paddingX*2+D,x+2*ct.paddingX);const j=($-D)/2;A=j+D/2;I=A-E/2;if(T==="top"){L=v;R=v+k+ct.circleToLegendStackGap+a;B=R+a+ct.paddingY}else if(T==="bottom"){R=v+a;L=v+l+ct.circleToLegendStackGap;B=L+k+ct.paddingY}else{const W=Math.max(l,k);R=v+W/2;L=R-k/2;B=v+W+ct.paddingY}}const F=[];let z=0;e.entries.forEach(D=>{const j=s>0?D.value/s:0;const W=z;const O=s>0?z+j*Math.PI*2:z;z=O;F.push({label:D.label,...D.displayLabel===void 0?{}:{displayLabel:D.displayLabel},value:D.value,fraction:j,startAngle:W,endAngle:O,path:wX(A,R,a,W,O,c)})});for(const D of F){const j=(D.startAngle+D.endAngle)/2;const W=a*n.textPosition;const O=`${(D.displayLabel??D.label).replace(/\n/g," ")}: ${ky(D.value)} (${pc(D.fraction)})`;D.tooltip=Ja(dt(dt(A)+W*Math.sin(j)),dt(dt(R)-W*Math.cos(j)),O)}MX(F,A,R,a,n);for(const D of F)if(D.pctLabel)D.pctLabel.block=Be(D.pctLabel.text,{display:"literal",fontSize:D.pctLabel.fontSize,fontWeight:ct.sliceLabelFontWeight});const _=qd(b,{...C,top:L});const H=_.rows.map(({item:D,x:j=0,top:W,textY:O},N)=>{const G=e.entries[N];const Y={label:G.label,...G.displayLabel===void 0?{}:{literalText:true},value:G.value,fraction:D.fraction,x:dt(I+j),y:dt(W),swatchSize:ct.legendSwatch,textX:dt(I+j+ct.legendSwatch+ct.legendSwatchToText),textY:dt(O),lines:D.lines,block:D.block,textWidth:dt(D.textWidth)};return Y});return{width:dt($),height:dt(B),title:e.title?{text:y,block:g,x:dt($/2),y:ct.paddingY+w/2,...e.displayTitle===void 0?{}:{literalText:true}}:void 0,cx:dt(A),cy:dt(R),radius:a,innerRadius:c,slices:F,legend:H,showData:e.showData,total:s,visual:n}}function MX(e,t,n,i,r){const o=i*r.textPosition;const s=r.sectionTextSize??ct.sliceLabelFontSize;const a=s*1.1;const l=[];for(let d=0;d<e.length;d++){const u=e[d];if(u.fraction<.01)continue;const f=SX(u.fraction);if(f==="0%")continue;const h=u.endAngle-u.startAngle;if(!(h>0))continue;const m=Su(f,s,ct.sliceLabelFontWeight);const p=2*o*Math.sin(Math.min(h,Math.PI)/2);if(m+ct.sliceLabelFitPad>p)continue;const g=(u.startAngle+u.endAngle)/2;l.push({index:d,fraction:u.fraction,halfWidth:m/2,label:{text:f,x:dt(t+o*Math.sin(g)),y:dt(n-o*Math.cos(g)),fontSize:s}})}l.sort((d,u)=>u.fraction-d.fraction||d.index-u.index);const c=[];for(const d of l){const u={x0:d.label.x-d.halfWidth,y0:d.label.y-a/2,x1:d.label.x+d.halfWidth,y1:d.label.y+a/2};const f=c.some(h=>Math.min(u.x1,h.x1)-Math.max(u.x0,h.x0)>1&&Math.min(u.y1,h.y1)-Math.max(u.y0,h.y0)>1);if(f)continue;c.push(u);e[d.index].pctLabel=d.label}}function VI({positioned:e,options:t}){const n=e.legend.map((r,o)=>{const s=`${r.label} (${pc(r.fraction)})`;const a=Math.max(r.swatchSize,r.textX-r.x+r.textWidth);return{id:`slice#${o}:${r.label}`,x:xe(r.x),y:xe(r.y),w:xe(a),h:xe(r.swatchSize),shape:"rectangle",label:s,...bt(r.block,r.textX,r.textY,Ut(e),"start")}});const i={version:1,nodes:n,edges:[],groups:[],bounds:{w:xe(e.width),h:xe(e.height)}};if(t.debug)i.certificates=is("pie",i,"legend-contained");return i}function KI({positioned:e,options:t}){const n=e.points.map((o,s)=>({id:`point#${s}:${o.label}`,x:xe(o.cx-o.radius),y:xe(o.cy-o.radius),w:xe(o.radius*2),h:xe(o.radius*2),shape:"circle",label:o.label,role:"labelled-mark",labelVisibility:o.labelHidden?"hidden":"visible",labelBounds:o.labelBox?{x:rt(o.labelBox.x0),y:rt(o.labelBox.y0),w:rt(o.labelBox.x1-o.labelBox.x0),h:rt(o.labelBox.y1-o.labelBox.y0)}:void 0,labelContainer:ln(Ut(e)),dataPosition:{x:rt(o.nx),y:rt(o.ny)}}));const i=e.regions.map(o=>({id:`quadrant#${o.number}`,x:xe(o.x),y:xe(o.y),w:xe(o.width),h:xe(o.height),members:e.points.map((s,a)=>({point:s,index:a})).filter(({point:s})=>o.number===(s.nx>=.5?s.ny>=.5?1:4:s.ny>=.5?2:3)).map(({point:s,index:a})=>`point#${a}:${s.label}`),label:o.label}));const r={version:1,nodes:n,edges:[],groups:i,bounds:{w:xe(e.width),h:xe(e.height)}};if(t.debug)r.certificates=is("quadrant",r,"plot-contained");return r}function JI({positioned:e}){const t=[];const n=e.rings.map((o,s)=>({id:`ring:${s}`,x:xe(e.cx-o.r),y:xe(e.cy-o.r),w:xe(o.r*2),h:xe(o.r*2),members:[]}));e.axes.forEach((o,s)=>{const a=Math.max(8,o.block?.width??o.labelWidth);const l=o.block?.height??0;const c=o.anchor==="start"?o.labelX:o.anchor==="end"?o.labelX-a:o.labelX-a/2;t.push({id:`axis#${s}:${o.id}`,x:xe(c),y:xe(o.labelY-l/2),w:xe(a),h:xe(l),shape:"rectangle",label:o.label,role:"labelled-mark",...bt(o.block,o.labelX,o.labelY,Ut(e),o.anchor)})});e.tickLabels.forEach((o,s)=>{const a=o.block?.width??o.w;const l=o.block?.height??o.h;t.push({id:`tick:${s}`,x:xe(o.x-a/2),y:xe(o.y-l/2),w:xe(a),h:xe(l),shape:"rectangle",label:o.text,role:"labelled-mark",...bt(o.block,o.x,o.y,Ut(e))})});const i=new Map;for(const o of e.curves)i.set(o.id,(i.get(o.id)??0)+1);const r=new Map;e.curves.forEach(o=>{const s=r.get(o.id)??0;r.set(o.id,s+1);const a=(i.get(o.id)??0)>1?`${o.id}#${s}`:o.id;o.vertices.forEach((l,c)=>{t.push({id:`dot:${a}:${c}`,x:xe(l.x-3),y:xe(l.y-3),w:xe(6),h:xe(6),shape:"circle",role:"mark"})})});for(const[o,s]of e.legend.entries()){t.push({id:`legend-swatch#${o}`,x:xe(s.x),y:xe(s.y),w:xe(s.swatchSize),h:xe(s.swatchSize),shape:"rectangle",role:"mark"});const a=Math.max(8,s.block?.width??0);const l=s.block?.height??0;t.push({id:`legend-label#${o}`,x:xe(s.textX),y:xe(s.textY-l/2),w:xe(a),h:xe(l),shape:"rectangle",label:s.lines.join(" "),role:"labelled-mark",...bt(s.block,s.textX,s.textY,Ut(e),"start")})}if(e.title){const o=e.title.block?.width??0;const s=e.title.block?.height??0;t.push({id:"title",x:xe(e.title.x-o/2),y:xe(e.title.y-s/2),w:xe(o),h:xe(s),shape:"rectangle",label:e.title.text,role:"labelled-mark",...bt(e.title.block,e.title.x,e.title.y,Ut(e))})}return{version:1,nodes:t,edges:[],groups:n,bounds:{w:xe(e.width),h:xe(e.height)}}}function QI({positioned:e}){const t=e.nodes.map(i=>({id:i.label,x:xe(i.x0),y:xe(i.y0),w:Gt(i.x0,i.x1-i.x0),h:Gt(i.y0,i.y1-i.y0),shape:"rectangle",label:i.label,role:"labelled-mark",...bt(i.labelBlock,i.labelX,i.labelY,Ut(e),i.labelAnchor)}));const n=e.links.map(i=>({id:i.id,from:i.source,to:i.target,path:i.points.map(r=>[xe(r.x),xe(r.y)])}));if(e.title){const i=e.title.block?.width??0;const r=e.title.block?.height??0;t.push({id:e.title.id,x:xe(e.title.x-i/2),y:xe(e.title.y-r/2),w:xe(i),h:xe(r),shape:"rectangle",label:e.title.text,role:"labelled-mark",...bt(e.title.block,e.title.x,e.title.y,Ut(e))})}return{version:1,nodes:t,edges:n,groups:[],bounds:{w:xe(e.width),h:xe(e.height)}}}function ZI({positioned:e,options:t}){const n=[];const i=[];for(const o of e.sections){const s=[];for(const a of o.periods){const l=`${a.id}:period`;n.push({id:l,x:xe(a.pillX),y:xe(a.pillY),w:xe(a.pillWidth),h:xe(a.pillHeight),shape:"rounded",label:a.label,...bt(a.block,a.centerX,a.pillY+a.pillHeight/2,{x:a.pillX,y:a.pillY,width:a.pillWidth,height:a.pillHeight})});s.push(l);for(const c of a.events){n.push({id:c.id,x:xe(c.x),y:xe(c.y),w:xe(c.width),h:xe(c.height),shape:"rectangle",label:c.text,...c.labelX===void 0?{}:bt(c.block,c.labelX,c.y+c.height/2,c,"start")});s.push(c.id)}}if(o.framed){i.push({id:o.id,x:xe(o.x),y:xe(o.y),w:xe(o.width),h:xe(o.height),members:s,label:o.label})}}const r={version:1,nodes:n,edges:[],groups:i,bounds:{w:xe(e.width),h:xe(e.height)}};if(t.debug)r.certificates=is("timeline",r,"timeline-interval");return r}var Gr={showLabel:true,labelFontSize:14,labelPadding:5,showTitle:true,titleFontSize:16,titlePadding:5,showTick:true,tickLength:5,tickWidth:2,showAxisLine:true,axisLineWidth:2};var zr={width:700,height:500,useMaxWidth:true,useWidth:void 0,titleFontSize:20,titlePadding:10,chartOrientation:"vertical",plotReservedSpacePercent:50,showDataLabel:false,showDataLabelOutsideBar:false,showTitle:true,showLegend:true,legendFontSize:14,legendPadding:5,xAxis:{...Gr},yAxis:{...Gr}};function eF(e){return{showLabel:ia(e?.showLabel,Gr.showLabel),labelFontSize:Qa(e?.labelFontSize,Gr.labelFontSize),labelPadding:Sh(e?.labelPadding,Gr.labelPadding),showTitle:ia(e?.showTitle,Gr.showTitle),titleFontSize:Qa(e?.titleFontSize,Gr.titleFontSize),titlePadding:Sh(e?.titlePadding,Gr.titlePadding),showTick:ia(e?.showTick,Gr.showTick),tickLength:Sh(e?.tickLength,Gr.tickLength),tickWidth:Qa(e?.tickWidth,Gr.tickWidth),showAxisLine:ia(e?.showAxisLine,Gr.showAxisLine),axisLineWidth:Qa(e?.axisLineWidth,Gr.axisLineWidth)}}function tF(e){return{width:Qa(e.width,zr.width),height:Qa(e.height,zr.height),useMaxWidth:ia(e.useMaxWidth,zr.useMaxWidth),useWidth:kX(e.useWidth),titleFontSize:Qa(e.titleFontSize,zr.titleFontSize),titlePadding:Sh(e.titlePadding,zr.titlePadding),chartOrientation:e.chartOrientation==="vertical"||e.chartOrientation==="horizontal"?e.chartOrientation:zr.chartOrientation,plotReservedSpacePercent:CX(e.plotReservedSpacePercent,zr.plotReservedSpacePercent,10,100),showDataLabel:ia(e.showDataLabel,zr.showDataLabel),showDataLabelOutsideBar:ia(e.showDataLabelOutsideBar,zr.showDataLabelOutsideBar),showTitle:ia(e.showTitle,zr.showTitle),showLegend:ia(e.showLegend,zr.showLegend),legendFontSize:Qa(e.legendFontSize,zr.legendFontSize),legendPadding:Sh(e.legendPadding,zr.legendPadding),xAxis:eF(e.xAxis),yAxis:eF(e.yAxis)}}function Qa(e,t){return typeof e==="number"&&Number.isFinite(e)&&e>0?e:t}function Sh(e,t){return typeof e==="number"&&Number.isFinite(e)&&e>=0?e:t}function kX(e){return typeof e==="number"&&Number.isFinite(e)&&e>0?e:void 0}function CX(e,t,n,i){return typeof e==="number"&&Number.isFinite(e)&&e>0&&e<=i?Math.max(n,e):t}function ia(e,t){return typeof e==="boolean"?e:t}function PX(e){return e.length>1||e.some(t=>t.label!==void 0&&t.label.length>0)}function nF(e){if(!PX(e))return[];const t=[];let n=0;let i=0;for(let r=0;r<e.length;r++){const o=e[r];const s=o.type==="bar"?n++:i++;const a=o.type==="bar"?`Bar ${s+1}`:`Line ${s+1}`;t.push({label:o.label!==void 0&&o.label.length>0?o.label:a,type:o.type,seriesIndex:s,colorIndex:r})}return t}var EX=.05;var RX=.6;var Ey=4;var po=12;var wh=6;var lM={nodeLabelFontSize:14,edgeLabelFontSize:16,groupHeaderFontSize:20,nodeLabelFontWeight:400,edgeLabelFontWeight:400,groupHeaderFontWeight:500,nodePaddingX:0,nodePaddingY:0,nodeLineWidth:0,edgeLineWidth:3,groupCornerRadius:0,groupPaddingX:0,groupPaddingY:0,groupLineWidth:et.outerBox};function vX(e){const t=new Map;const n=(i,r,o,s)=>{const a=JSON.stringify([i,r,o,s]);let l=t.get(a);if(!l){const c=i==="axisTitle";l=Be(r,{display:"literal",fontSize:o,fontWeight:c?e.edgeLabelFontWeight:e.nodeLabelFontWeight,letterSpacing:c?e.edgeLetterSpacing:e.nodeLetterSpacing,transform:i==="axisTitle"||i==="tick"?e.edgeTextTransform:e.nodeTextTransform,maxWidth:s});t.set(a,l)}return l};return{block:n,wrapTitle:(i,r,o)=>Be(i,{display:"literal",transform:e.groupTextTransform,fontSize:r,fontWeight:e.groupHeaderFontWeight,letterSpacing:e.groupLetterSpacing,maxWidth:o}),tick:(i,r)=>n("tick",i,r).width,legend:(i,r)=>n("legend",i,r).width}}function oF(e,t={},n){const i=Ue(t,lM,n);const r=tF(e.config);const o=n;if(o?.group?.fontSize!=null||o?.text?.fontSize!=null){r.titleFontSize=i.groupHeaderFontSize}if(o?.node?.fontSize!=null||o?.text?.fontSize!=null){r.xAxis.labelFontSize=i.nodeLabelFontSize;r.yAxis.labelFontSize=i.nodeLabelFontSize}if(o?.edge?.fontSize!=null||o?.text?.fontSize!=null){r.xAxis.titleFontSize=i.edgeLabelFontSize;r.yAxis.titleFontSize=i.edgeLabelFontSize}if(o?.edge?.lineWidth!=null){r.xAxis.axisLineWidth=i.lineWidth;r.yAxis.axisLineWidth=i.lineWidth;r.xAxis.tickWidth=i.lineWidth;r.yAxis.tickWidth=i.lineWidth}const s=vX(i);let a=0;const l=Math.max(0,...e.series.flatMap(d=>{if(d.type!=="line")return[];const u=It(n,"series",{category:`line-${a++}`},{includeFallback:false})?.lineWidth??i.lineWidth;const f=t.interactive||d.pointLabels?.some(h=>h!==void 0);return[Math.max(u/2,f?Ey+1:0)]}));const c=e.horizontal?AX(e,r,s,l):LX(e,r,s,l);for(const d of[c.xAxis,c.yAxis]){if(d.title){const u=d.title.block??=s.block("axisTitle",d.title.text,d.config.titleFontSize);const f=(u.lines.length-1)*u.lineHeight/2+(u.lineHeight-d.config.titleFontSize*hi)/2;if(d.title.rotate)d.title.x+=f;else d.title.y+=e.horizontal?f:-f}for(const u of d.ticks){const f=u.block=s.block("tick",u.label,d.config.labelFontSize);const h=u.textAnchor==="start"?0:u.textAnchor==="end"?f.width:f.width/2;u.labelX=Math.max(h,Math.min(c.width-f.width+h,u.labelX));u.labelY=Math.max(f.height/2,Math.min(c.height-f.height/2,u.labelY))}}for(const d of c.legend)d.block=s.block("legend",d.label,c.config.legendFontSize);for(const d of c.dataLabels)d.block=s.block("data",d.text,d.fontSize);for(const d of c.lines)for(const u of d.points){if(u.textLabel!==void 0){const f=u.textBlock=s.block("data",u.textLabel,12,Math.max(1,c.width-8));const h=(m,p,g)=>Math.max(p,Math.min(g,m));if(c.horizontal){const m=u.x+8+f.width<=c.width-4;const p=m?"start":"end";u.textPosition={x:m?h(u.x+8,4,c.width-4-f.width):h(u.x-8,f.width+4,c.width-4),y:h(u.y,f.height/2,c.height-f.height/2),anchor:p,placement:m?"right":"left"}}else{const m=u.y-8-f.height>=c.plotArea.y;u.textPosition={x:h(u.x,f.width/2,c.width-f.width/2),y:h(u.y+(m?-1:1)*(8+f.height/2),f.height/2,c.height-f.height/2),anchor:"middle",placement:m?"above":"below"}}}}{for(const d of c.bars)d.tooltip=Ja(c.horizontal?d.x+d.width:d.x+d.width/2,c.horizontal?d.y+d.height/2:d.y,rc(d.value));for(const d of c.lines)for(const u of d.points)u.tooltip=Ja(u.x,u.y-Ey,rc(u.value))}return c}var TX=1;function sF(e,t,n,i){const r=e.series.some(s=>s.type==="line")?t:0;const o=s=>s.showLabel&&s.showTick?s.tickWidth/2:0;return{value:Math.max(TX/2,o(n),r),position:i?Math.max(o(i),r):0}}function Ry(e){return e.showAxisLine?e.axisLineWidth/2:0}function LX(e,t,n,i){const r=t.width;const o=t.height;const s=qf(e);const a=Xg(e,s);const l=v0(e,s);const c=e.yAxis.range;const d=Vg(c.min,c.max);const u=d.map(Xf);const f=e.xAxis.range?Vg(e.xAxis.range.min,e.xAxis.range.max):void 0;const h=f?.map(Xf)??a;let m=Math.max(0,o-Math.floor(o*t.plotReservedSpacePercent/100));let p=Math.max(0,r-Math.floor(r*t.plotReservedSpacePercent/100));const g=lF(e.title,t,m,n);const y=g.height;m=Math.max(0,m-y);const w=dF(t.xAxis,e.xAxis.title,h,m,n);m=Math.max(0,m-w.size);const S=uF(t.yAxis,e.yAxis.title,u,p,n,o);p=Math.max(0,p-S.size);const x=S.config.showLabel&&u.length>0?t.yAxis.labelFontSize/2:0;const M=sF(e,i,S.config,e.xAxis.range?w.config:void 0);const b=Math.max(y,x,M.value);const C=Math.max(0,o-b-Math.max(w.size,x,M.value,Ry(w.config)));const P=aF(e,t,p,r,b,C,n);const E=Math.max(S.size,M.position,Ry(S.config));const k={x:E,y:b,width:Math.max(0,r-E-Math.max(P.size,M.position)),height:C};const v=e.xAxis.range&&e.series.some(H=>H.type==="bar")?k.width/Math.max(1,s)/2:0;const T=e.xAxis.range?H=>k.x+v+(H-e.xAxis.range.min)/(e.xAxis.range.max-e.xAxis.range.min||1)*(k.width-2*v):void 0;const A=H=>T?T(l[H]):k.x+(H+.5)*(k.width/s);const R=T?sA(l,T,k.width/Math.max(2,s)):k.width/Math.max(1,s);const I=H=>k.y+k.height-(H-c.min)/(c.max-c.min||1)*k.height;const L=!w.config.showLabel?[]:e.xAxis.range&&f&&T?iF(f,h,T,k,w.config,n,r):iF(a.map((H,D)=>D),a,A,k,w.config,n,r);const $=S.config.showLabel?fF(d,u,I,k,S.config):[];const B=d.map(H=>({x1:k.x,y1:I(H),x2:k.x+k.width,y2:I(H)}));const F=e.series.map((H,D)=>D);const z=yF(e,A,R,I,c,a,F,false);const _=xF(e,A,I,c,a,F,false);return{width:r,height:o,accessibility:e.accessibility,title:g.title,hiddenTitle:e.title&&t.showTitle&&!g.title?e.title:void 0,xAxis:{ticks:L,line:NX(k,w.config),title:_X(e.xAxis.title,k,o,w.config),config:w.config},yAxis:{ticks:$,line:hF(k,S.config),title:mF(e.yAxis.title,k,S.config,o,n),config:S.config},plotArea:k,bars:z,lines:_,gridLines:B,legend:P.items,hiddenLegendLabels:P.hiddenLabels,hiddenCategoryLabels:pF(e,t,w.config,L),...gF(z,false,k,t,n),config:t,theme:e.theme}}function AX(e,t,n,i){const r=t.width;const o=t.height;const s=qf(e);const a=Xg(e,s);const l=e.yAxis.range;const c=Vg(l.min,l.max);const d=c.map(Xf);let u=Math.max(0,o-Math.floor(o*t.plotReservedSpacePercent/100));let f=Math.max(0,r-Math.floor(r*t.plotReservedSpacePercent/100));const h=lF(e.title,t,u,n);const m=h.height;u=Math.max(0,u-m);const p=IX(t.yAxis,e.yAxis.title,d,u,n);u=Math.max(0,u-p.size);const g=uF(t.xAxis,e.xAxis.title,a,f,n,o);f=Math.max(0,f-g.size);const y=sF(e,i,p.config);const w=Math.max(m+p.size,Ry(p.config));const S=Math.max(0,o-w);const x=Math.max(1,s);const M=g.config.showLabel?t.xAxis.labelFontSize*OX:0;const b=Math.min(S,Math.max(0,(M-S/(2*x))/(1-1/(2*x))));const C=Math.max(0,S-b);const P=aF(e,t,f,r,w,C,n);const E=p.config.showLabel&&d.length>0?Math.max(...[d[0],d[d.length-1]].map(H=>n.tick(H,t.yAxis.labelFontSize)/2)):0;const k=Math.max(0,Math.max(E,y.value,Ry(g.config))-g.size);const v=Math.max(0,E-P.size,y.value-P.size);const T={x:g.size+k,y:w,width:Math.max(0,r-g.size-k-P.size-v),height:C};const A=H=>T.x+(H-l.min)/(l.max-l.min||1)*T.width;const R=H=>T.y+(H+.5)*(T.height/s);const I=T.height/Math.max(1,s);const L=p.config.showLabel?FX(c,d,A,T,p.config):[];const $=g.config.showLabel?fF(a.map((H,D)=>D),a,R,T,g.config):[];const B=c.map(H=>({x1:A(H),y1:T.y,x2:A(H),y2:T.y+T.height}));const F=e.series.map((H,D)=>D);const z=yF(e,R,I,A,l,a,F,true);const _=xF(e,R,A,l,a,F,true);return{width:r,height:o,accessibility:e.accessibility,horizontal:true,title:h.title,hiddenTitle:e.title&&t.showTitle&&!h.title?e.title:void 0,xAxis:{ticks:$,line:hF(T,g.config),title:mF(e.xAxis.title,T,g.config,o,n),config:g.config},yAxis:{ticks:L,line:$X(T,p.config),title:DX(e.yAxis.title,T,m,p.config),config:p.config},plotArea:T,bars:z,lines:_,gridLines:B,legend:P.items,hiddenLegendLabels:P.hiddenLabels,hiddenCategoryLabels:pF(e,t,g.config,$),...gF(z,true,T,t,n),config:t,theme:e.theme}}function aF(e,t,n,i,r,o,s){if(!t.showLegend)return{items:[],size:0,hiddenLabels:[]};const a=nF(e.series);if(a.length===0)return{items:[],size:0,hiddenLabels:[]};const l=Math.ceil(Math.max(...a.map(m=>s.legend(m.label,t.legendFontSize))));const c=t.legendPadding*2+po+wh+l;const d=Math.max(...a.map(m=>s.block("legend",m.label,t.legendFontSize).height),po)+t.legendPadding;const u=t.legendPadding+a.length*d;if(c>n||u>o)return{items:[],size:0,hiddenLabels:a.map(m=>m.label)};const f=i-c+t.legendPadding;const h=a.map((m,p)=>({label:m.label,x:f,y:r+t.legendPadding+p*d,type:m.type,seriesIndex:m.seriesIndex,colorIndex:m.colorIndex}));return{items:h,size:c,hiddenLabels:[]}}function lF(e,t,n,i){if(!e||!t.showTitle)return{height:0};const r=i.wrapTitle(e,t.titleFontSize,Math.max(1,t.width-t.titlePadding*2));const o=r.height-r.lineHeight;const s=r.height+t.titlePadding*2;if(s>n)return{height:0};return{height:s,title:{text:r.text,block:r,x:t.width/2,y:t.titlePadding+r.height/2}}}function cF(e,t,n,i,r,o=e.titleFontSize){let s=i;const a={...e,showAxisLine:false,showLabel:false,showTick:false,showTitle:false};if(e.showAxisLine&&s>e.axisLineWidth){a.showAxisLine=true;s-=e.axisLineWidth}if(e.showLabel&&n.length>0){const l=r()+e.labelPadding*2;if(l<=s){a.showLabel=true;s-=l}}if(e.showTick&&s>=e.tickLength){a.showTick=true;s-=e.tickLength}if(e.showTitle&&t){const l=o+e.titlePadding*2;if(l<=s){a.showTitle=true;s-=l}}return{config:a,size:i-s}}function dF(e,t,n,i,r){const o=t?r.block("axisTitle",t,e.titleFontSize).height-e.titleFontSize*(hi-1):e.titleFontSize;return cF(e,t,n,i,()=>Math.max(e.labelFontSize,...n.map(s=>r.block("tick",s,e.labelFontSize).height-e.labelFontSize*(hi-1))),o)}function IX(e,t,n,i,r){return dF(e,t,n,i,r)}function uF(e,t,n,i,r,o){return cF(e,t,n,i,()=>Math.max(...n.map(s=>r.tick(s,e.labelFontSize))),t?r.block("axisTitle",t,e.titleFontSize,Math.max(1,o-4)).height-e.titleFontSize*(hi-1):e.titleFontSize)}function iF(e,t,n,i,r,o,s){const a=r.showAxisLine?r.axisLineWidth:0;const l=r.showTick?r.tickLength:0;const c=i.y+i.height+a+l+r.labelPadding+r.labelFontSize*(1-RX);const d=t.map(p=>o.tick(p,r.labelFontSize));const u=d.length?Math.max(...d):0;const f=e.map(p=>n(p));let h=Infinity;for(let p=1;p<f.length;p++)h=Math.min(h,Math.abs(f[p]-f[p-1]));const m=Number.isFinite(h)&&h>0?Math.max(1,Math.ceil((u+6)/h)):1;return e.map((p,g)=>{const y=g%m===0?t[g]:"";let w=n(p);if(s!==void 0&&y){const S=d[g]/2;w=Math.max(2+S,Math.min(s-2-S,w))}return{label:y,x:n(p),y:i.y+i.height+a,tx:n(p),ty:i.y+i.height+a+l,labelX:w,labelY:c,textAnchor:"middle"}})}function FX(e,t,n,i,r){const o=r.showAxisLine?r.axisLineWidth:0;const s=r.showTick?r.tickLength:0;const a=i.y-o-s-r.labelPadding;return e.map((l,c)=>({label:t[c],x:n(l),y:i.y-o,tx:n(l),ty:i.y-o-s,labelX:n(l),labelY:a,textAnchor:"middle"}))}function fF(e,t,n,i,r){const o=r.showAxisLine?r.axisLineWidth:0;const s=r.showTick?r.tickLength:0;const a=i.x-o-s-r.labelPadding;return e.map((l,c)=>({label:t[c],x:i.x-o,y:n(l),tx:i.x-o-s,ty:n(l),labelX:a,labelY:n(l),textAnchor:"end"}))}function NX(e,t){const n=e.y+e.height+(t.showAxisLine?t.axisLineWidth/2:0);return{x1:e.x,y1:n,x2:e.x+e.width,y2:n}}function $X(e,t){const n=e.y-(t.showAxisLine?t.axisLineWidth/2:0);return{x1:e.x,y1:n,x2:e.x+e.width,y2:n}}function hF(e,t){const n=e.x-(t.showAxisLine?t.axisLineWidth/2:0);return{x1:n,y1:e.y,x2:n,y2:e.y+e.height}}function _X(e,t,n,i){if(!e||!i.showTitle)return void 0;return{text:e,x:t.x+t.width/2,y:n-i.titlePadding-i.titleFontSize/2}}function DX(e,t,n,i){if(!e||!i.showTitle)return void 0;return{text:e,x:t.x+t.width/2,y:n+i.titlePadding+i.titleFontSize}}function mF(e,t,n,i,r){if(!e||!n.showTitle)return void 0;const o=r.block("axisTitle",e,n.titleFontSize,Math.max(1,i-4));const s=o.width/2;const a=t.y+t.height/2;return{text:e,block:o,x:n.titlePadding+n.titleFontSize*.8,y:2*s+4>=i?i/2:Math.min(i-2-s,Math.max(2+s,a)),rotate:-90}}function pF(e,t,n,i){const r=e.xAxis.categories;if(!r||e.xAxis.range||!t.xAxis.showLabel)return[];const o=(a,l)=>l<r.length&&a!=="";const s=Xg(e);if(!n.showLabel)return s.filter(o);return s.filter((a,l)=>o(a,l)&&i[l]?.label==="")}var OX=.6;var rF=8;var BX=16;var Cy=8;var Py=4;function gF(e,t,n,i,r){if(!i.showDataLabel||e.length===0)return{dataLabels:[],unlabeledBars:[]};const o=e.map(c=>rc(c.value));let s=BX;for(;s>=rF;s--){if(e.every((c,d)=>{const u=r.block("data",o[d],s);return t?u.height<=c.height-4:u.width<=c.width-Cy}))break}if(s<rF)return{dataLabels:[],unlabeledBars:[...e]};const a=[];const l=[];e.forEach((c,d)=>{const u=o[d];const f=r.block("data",u,s);const h=f.width;const m=t?c.width-12>=h:c.height-10>=f.height;const p=x=>{const M=t?x?n.x+n.width-(c.x+c.width):c.x-n.x:x?c.y-n.y:n.y+n.height-(c.y+c.height);return M>=(t?h:f.height)+Py};const g=c.value>0||c.value===0&&(p(true)||!p(false));const y=p(g);const w=i.showDataLabelOutsideBar?y?"outside":m?"inside":void 0:m?"inside":y?"outside":void 0;if(!w){l.push(c);return}if(t){const x=w==="outside"===g;const M=g?c.x+c.width:c.x;const b=w==="outside"?Py:-Cy;a.push({bar:c,text:u,fontSize:s,placement:w,x:M+(g?b:-b),y:c.y+c.height/2,anchor:x?"start":"end",dominantBaseline:"middle"});return}const S=w==="inside"?g:!g;a.push({bar:c,text:u,fontSize:s,placement:w,x:c.x+c.width/2,y:w==="inside"?g?c.y+Cy:c.y+c.height-Cy:g?c.y-Py:c.y+c.height+Py,anchor:"middle",...S?{dominantBaseline:"hanging"}:{}})});return{dataLabels:a,unlabeledBars:l}}function yF(e,t,n,i,r,o,s,a){const l=e.series.filter(g=>g.type==="bar");const c=l.length;if(c===0)return[];const d=n*(1-EX);const u=d/Math.max(1,c);const f=[];let h=0;let m=0;const p=i(aA(r));for(const g of e.series){if(g.type!=="bar"){m++;continue}for(let y=0;y<g.data.length;y++){const w=t(y)-d/2+h*u;const S=i(Ug(r,g.data[y]));const x=Math.min(S,p);const M=Math.abs(p-S);f.push({x:a?x:w,y:a?w:x,width:a?M:u,height:a?u:M,value:g.data[y],label:o[y],seriesIndex:h,colorIndex:s[m]})}h++;m++}return f}function xF(e,t,n,i,r,o,s){const a=[];let l=0;let c=0;for(const d of e.series){if(d.type!=="line"){c++;continue}a.push({points:d.data.map((u,f)=>{const h=t(f);const m=n(Ug(i,u));return{x:s?m:h,y:s?h:m,value:u,label:r[f],...d.pointLabels?.[f]!==void 0?{textLabel:d.pointLabels[f]}:{}}}),seriesIndex:l,colorIndex:o[c]});l++;c++}return a}function bF({positioned:e,options:t}){const n=[];const i=[];const r=ln(Ut(e));const o=(c,d,u,f,h,m="middle",p=0)=>{if(!d)return;let g=qt(u,f,h,m);if(g&&p){const y=hl({x0:g.x,y0:g.y,x1:g.x+g.w,y1:g.y+g.h},{x:f,y:h},p);g=ln({x:y.x0,y:y.y0,width:y.x1-y.x0,height:y.y1-y.y0})}i.push({id:c,text:d,...g?{bounds:g}:{},container:r})};const s=new Map;e.bars.forEach(c=>{const d=s.get(c.seriesIndex)??0;s.set(c.seriesIndex,d+1);n.push({id:`bar#${c.seriesIndex}:pt#${d}`,x:xe(c.x),y:xe(c.y),w:Gt(c.x,c.width),h:Gt(c.y,c.height),shape:"rectangle",label:c.label,role:"labelled-mark",labelVisibility:"semantic"})});e.lines.forEach(c=>{c.points.forEach((d,u)=>{const f=e.plotArea;const h=Math.max(f.x,Math.min(f.x+f.width,d.x-3)),m=Math.max(f.y,Math.min(f.y+f.height,d.y-3));const p=Math.max(h,Math.min(f.x+f.width,d.x+3)),g=Math.max(m,Math.min(f.y+f.height,d.y+3));n.push({id:`line#${c.seriesIndex}:pt#${u}`,x:xe(h),y:xe(m),w:Gt(h,p-h),h:Gt(m,g-m),shape:"circle",label:d.label,role:d.label?"labelled-mark":"mark",labelVisibility:"semantic"});if(d.textLabel!==void 0){const y=d.textPosition;o(`point-label:${c.seriesIndex}:${u}`,d.textBlock?.text??d.textLabel,y?d.textBlock:void 0,y?.x??d.x,y?.y??d.y,y?.anchor??"middle")}})});if(e.title){const c=e.title;o("title",c.block?.text??c.text,c.block,c.x,c.y)}for(const[c,d]of[["x",e.xAxis],["y",e.yAxis]]){if(d.title){const u=d.title;o(`axis:${c}:title`,u.block?.text??u.text,u.block,u.x,u.y,"middle",u.rotate)}d.ticks.forEach((u,f)=>o(`axis:${c}:label:${f}`,u.block?.text??u.label,u.block,u.labelX,u.labelY,u.textAnchor))}for(const c of e.legend){o(`legend:label:${c.colorIndex}`,c.block?.text??c.label,c.block,c.x+po+wh,c.y+Math.max(po,c.block?.height??0)/2,"start")}e.dataLabels.forEach((c,d)=>{const u=c.dominantBaseline==="hanging"?c.y+(c.block?.height??0)/2:c.dominantBaseline==="middle"?c.y:c.y-c.fontSize*.35;o(`data-label:${d}`,c.block?.text??c.text,c.block,c.x,u,c.anchor)});const a=[{id:"plot",x:xe(e.plotArea.x),y:xe(e.plotArea.y),w:Gt(e.plotArea.x,e.plotArea.width),h:Gt(e.plotArea.y,e.plotArea.height),members:n.filter(c=>c.x+c.w/2>=e.plotArea.x&&c.x+c.w/2<=e.plotArea.x+e.plotArea.width&&c.y+c.h/2>=e.plotArea.y&&c.y+c.h/2<=e.plotArea.y+e.plotArea.height).map(c=>c.id)}];const l={version:1,nodes:n,edges:[],groups:a,bounds:{w:xe(e.width),h:xe(e.height)},labels:i};if(t.debug)l.certificates=is("xychart",l,"plot-contained",a[0],"center");return l}var _me=["bitsPerRow","bitOrder","showBits","rowHeight","bitWidth","paddingX","paddingY","useMaxWidth"];function Mh(e={}){const t=Sn(e,["packet"])??{};const n=(r,o)=>typeof t[r]==="number"&&Number.isFinite(t[r])&&t[r]>0?t[r]:o;const i=r=>typeof t[r]==="number"&&Number.isFinite(t[r])&&t[r]>=0?t[r]:5;return{bitsPerRow:typeof t.bitsPerRow==="number"&&Number.isSafeInteger(t.bitsPerRow)&&t.bitsPerRow>0?t.bitsPerRow:32,bitOrder:t.bitOrder==="descending"?"descending":"ascending",showBits:t.showBits!==false,rowHeight:n("rowHeight",32),bitWidth:n("bitWidth",32),paddingX:i("paddingX"),paddingY:i("paddingY")}}var gc=fr("eventmodeling-arrow",{width:8,height:8},"end",{fill:"var(--_line)"},"userSpaceOnUse");var SF=xr([gc]);function WX(e,t){const n=typeof t==="string"?e.frames.find(a=>a.id===t):t;const i=n.id;const r=n.data??(n.dataReference?e.data[n.dataReference]:void 0);const o=e.notes.filter(a=>a.frame===i).map(a=>`Note: ${a.data.text}`);const s=e.specifications.filter(a=>a.frame===i).flatMap(a=>["given","when","then"].filter(l=>a[l].length).map(l=>`${l}: ${a[l].map(c=>`${c.type} ${c.entity}`).join(", ")}`));return[`${n.id} \xB7 ${n.type}${n.reset?" \xB7 reset":""}`,n.entity,...r?[r.text]:[],...o,...s].join("\n")}function wF(e,t={},n,i=0,r){const o=Ue(t,void 0,n),s=t.padding??24;const a=$n({stroke:o.nodeBorderColor??(r?Ml(r).nodeStroke:"var(--_node-stroke)"),strokeWidth:String(o.nodeLineWidth)},false)??0;const l=T=>Be(T,{display:"literal",fontFamily:t.font,fontSize:o.nodeLabelFontSize,fontWeight:o.nodeLabelFontWeight,letterSpacing:o.nodeLetterSpacing,transform:o.nodeTextTransform,maxWidth:220});const c=T=>Be(T,{display:"literal",fontFamily:o.groupFont??t.font,fontSize:o.groupHeaderFontSize,fontWeight:o.groupHeaderFontWeight,letterSpacing:o.groupLetterSpacing,transform:o.groupTextTransform,maxWidth:220});const d=aL(e).map(T=>({...T,block:c(T.label),x:s,y:0,width:0,height:0}));const u=new Map(d.map(T=>[T.label,T]));const f=jw(e);const h=new Map(e.frames.map(T=>[T.id,{incoming:0,outgoing:0}]));for(const T of f){h.get(T.from).outgoing++;h.get(T.to).incoming++}const m=Math.max(12,8+o.lineWidth);const p=tn(e.title,o);const g=Math.max(140,...d.map(T=>o.groupLabelPaddingX+T.block.width+o.groupPaddingX))+a;const y=e.frames.map((T,A)=>{const R=l(WX(e,T));const I=Math.max(120,R.width+2*(o.nodePaddingX+a));const L=h.get(T.id);const $=Math.max(L.incoming,L.outgoing);const B=Math.max(6+a,o.nodePaddingY+a,Math.min(o.cornerRadius??5,I/2));const F=$>1?($-1)*m+2*B:0;return{id:T.id,frame:T,block:R,lane:u.get(vf(T)).id,x:0,y:0,width:I,height:Math.max(64,R.height+2*(o.nodePaddingY+a),F),index:A}});const w=Math.max(160,...y.map(T=>T.width));const S=Math.max(48,t.nodeSpacing??48,2*a+16);const x=Math.max(s*2+g+Math.max(1,y.length)*w+Math.max(0,y.length-1)*S+Math.max(o.groupPaddingX+a,S/2+o.lineWidth),(p?.width??0)+2*s);const M=new Map;for(const T of y){const A=M.get(T.lane)??[];A.push(T);M.set(T.lane,A)}let b=s+(p?.height??0)+S/2+Math.max(4,o.lineWidth);for(const T of d){const A=M.get(T.id)??[];T.y=b;T.height=Math.max(i,T.block.height+2*o.groupPaddingY,...A.map(R=>R.height+2*(o.groupPaddingY+a)));T.width=x-2*s;for(const R of A){R.x=s+g+R.index*(w+S);R.y=b+(T.height-R.height)/2}b+=T.height+S}const C=new Map(y.map(T=>[T.id,T]));const P=new Map(d.map(T=>[T.id,T]));const E=new Map,k=new Map;const v=f.map((T,A)=>{const R=C.get(T.from),I=C.get(T.to);const L=k.get(R.id)??0,$=E.get(I.id)??0;k.set(R.id,L+1);E.set(I.id,$+1);const B={x:R.x+R.width+a,y:R.y+R.height/2+(L-(h.get(R.id).outgoing-1)/2)*m};const F={x:I.x-a,y:I.y+I.height/2+($-(h.get(I.id).incoming-1)/2)*m};const z=R.x+w+S/2;const _=I.x-S/2;const H=P.get(R.lane).y-S/2;const D=R.lane===I.lane&&I.index===R.index+1&&B.y===F.y?[B,F]:I.index===R.index+1?[B,{x:z,y:B.y},{x:z,y:F.y},F]:[B,{x:z,y:B.y},{x:z,y:H},{x:_,y:H},{x:_,y:F.y},F];const j=o.edgeBendRadius>0?qn(D,o.edgeBendRadius,{precision:3,terminalClearance:{end:SF(gc.id,o.lineWidth,"end")}}):void 0;return{...T,points:j?.geometry.points??D,projection:j,index:A}});return{style:o,laneWidth:g,width:x,height:Math.max(b+s,2*s+40),lanes:d,nodes:y,edges:v,...p?{title:on(p,x,s)}:{}}}function vy(e){return e.replace(/#(?:quot|0*(?:34|37|96));/g,t=>t==="#quot;"?'"':String.fromCodePoint(Number(t.slice(1,-1))))}function Kme(e){return gr(e,'"%`')}var kh=class extends Error{constructor(t,n,i){super(t)}};function cM(e,t,n=0,i="",r=false){const o=t.slice(0,n),s=o.split("\n").length,a=n-o.lastIndexOf("\n");return new Error(`${e} ${r?"lexical":"parse"} error at line ${s}, column ${a}: ${i||"unrecognized input"}`)}function zX(e){switch(e){case"[]":return"square";case"()":return"round";case"(())":return"circle";case">]":return"rect_left_inv_arrow";case"{}":return"diamond";case"{{}}":return"hexagon";case"([])":return"stadium";case"[[]]":return"subroutine";case"[()]":return"cylinder";case"((()))":return"doublecircle";case"[//]":return"lean_right";case"[\\\\]":return"lean_left";case"[/\\]":return"trapezoid";case"[\\/]":return"inv_trapezoid";case"<[]>":return"block_arrow";default:return"na"}}function GX(e){switch(e.trim().slice(-1)){case"x":return"arrow_cross";case"o":return"arrow_circle";case">":return"arrow_point";default:return""}}function HX(e){switch(e.trim().charAt(0)){case"x":return"arrow_cross";case"o":return"arrow_circle";case"<":return"arrow_point";default:return"arrow_open"}}function jX(e){return e.includes("==")?"thick":"normal"}function YX(e){return e.includes(".-")?"dotted":"solid"}function MF(e,t){const n=e.flat();let i=-1;for(const r of n){if(r.type==="column-setting"){i=r.columns??-1;break}}return{list:n,at:0,parent:t,children:[],columns:i}}var Ty=class{type="block";title;root={id:"root",type:"composite",children:[],columns:-1};blocks=[];edges=[];classes=new Map;byId=new Map;typeStr2Type=zX;edgeStrToEdgeData=GX;edgeStrToEdgeStartData=HX;edgeStrToThickness=jX;edgeStrToPattern=YX;warn;pending=new Set;workIds=new Set;admitNode(t){if(this.workIds.has(t))return;Ve("nodes",this.workIds.size+1);this.workIds.add(t)}edgeCount=new Map;ids=0;colors=0;reservedIds=new Set;constructor(t={}){this.warn=t.warn}generateId(){let t;do t="block_generated_"+ ++this.ids;while(this.reservedIds.has(t)||this.byId.has(t));this.reservedIds.add(t);if(re("block"))he("block","generate-id",t);return t}addStyleClass(t,n=""){let i=this.classes.get(t);if(!i){i={id:t,styles:[],textStyles:[]};this.classes.set(t,i)}for(const r of n.split(",")){const o=r.indexOf(";");const s=(o===-1?r:r.slice(0,o)+r.slice(o+1)).trim();if(r.includes("color"))i.textStyles.push(s.replace("fill","bgFill").replace("color","fill"));i.styles.push(s);if(re("block"))he("block","define-class",{id:t,attribute:s})}}addStyle2Node(t,n=""){this.named(t).styles=n.replace(/;\s*$/,"").split(",");if(re("block"))he("block","set-node-style",{id:t,styles:this.named(t).styles})}setCssClass(t,n){for(const i of t.split(",")){;(this.named(i.trim()).classes??=[]).push(n);if(re("block"))he("block","add-node-class",{id:i.trim(),className:n})}}named(t){let n=this.byId.get(t);if(n===void 0){this.admitNode(t);n={id:t,type:"na",children:[]};this.byId.set(t,n);this.pending.add(t)}return n}unresolvedStyleTargets(){return[...this.pending]}setHierarchy(t){const n=[MF(t,this.root)];while(n.length>0){const i=n[n.length-1];if(i.at===i.list.length){i.parent.children=i.children;if(re("block"))he("block","set-children",{id:i.parent.id,children:i.children.map(l=>l.id)});n.pop();continue}const r=i.list[i.at++];if(i.columns>0&&r.type!=="column-setting"&&typeof r.widthInColumns==="number"&&r.widthInColumns>i.columns){this.warn?.(`Block ${r.id} width ${r.widthInColumns} exceeds configured column width ${i.columns}`)}switch(r.type){case"classDef":this.addStyleClass(r.id,r.css);continue;case"applyClass":this.setCssClass(r.id,r.styleClass??"");continue;case"applyStyles":if(r.stylesStr)this.addStyle2Node(r.id,r.stylesStr);continue;case"column-setting":i.parent.columns=r.columns??-1;if(re("block"))he("block","set-columns",{id:i.parent.id,columns:i.parent.columns});continue;case"edge":{Ve("edges",this.edges.length+1);const l=(this.edgeCount.get(r.id)??0)+1;this.edgeCount.set(r.id,l);r.id=l+"-"+r.id;this.edges.push(r);if(re("block"))he("block","add-edge",r);continue}}r.id??=this.generateId();if(r.type!=="space")this.admitNode(r.id);if(!r.label)r.label=r.type==="composite"?"":r.id;const o=this.byId.get(r.id);const s=o===void 0||this.pending.delete(r.id);if(!s){if(r.type!=="na")o.type=r.type;if(r.label!==r.id)o.label=r.label}else{if(o){r.classes=o.classes;r.styles=o.styles}if(r.type==="composite")r.colorIndex=this.colors++;this.byId.set(r.id,r)}if(re("block"))he("block","upsert-block",{parentId:i.parent.id,block:this.byId.get(r.id)});const a=r.children;r.children=[];if(r.type==="space"){const l=r.width??1;Ve("nodes",this.workIds.size+Math.max(l,0));for(let c=0;c<l;c++){const d={...r,id:r.id+"-"+c,width:1,children:[]};this.admitNode(d.id);this.byId.set(d.id,d);i.children.push(d);if(re("block"))he("block","attach-space",{parentId:i.parent.id,block:d})}}else if(s){i.children.push(r);if(re("block"))he("block","attach-child",{parentId:i.parent.id,block:r})}if(a&&a.length>0)n.push(MF(a,r))}this.blocks=this.root.children??[];if(re("block"))he("block","complete-hierarchy",{root:this.root,edges:this.edges,classes:this.classes})}};function CF(e){const t=Array.isArray(e)?e.join("\n"):e;const n=new Ty;const i=Yw(t);n.reservedIds=new Set(i.texts.filter((o,s)=>i.types[s]===32));qX(t.endsWith("\n")?t:t+"\n",n);if(n.unresolvedStyleTargets().length)throw new Error("Block style/class references undeclared targets: "+n.unresolvedStyleTargets().join(", "));for(const o of n.classes.values())Tt(vn(o.styles.join(",")),`classDef ${o.id}`);const r=[n.root];for(let o=0;o<r.length;o++){const s=r[o];Tt(vn((s.styles??[]).join(",")),`style ${s.id}`);r.push(...s.children??[])}return{kind:"block",root:n.root,edges:n.edges,classDefs:[...n.classes.values()],title:n.title}}var Ch="'NODE_ID', 'COLUMNS', 'SPACE_BLOCK', 'BLOCK_DIAGRAM_KEY', 'id-block', 'classDef', 'class', 'style'";function kF(e){const t=e[e.length-1];if(!Array.isArray(t))return e;e.pop();return e.concat(t)}function qX(e,t){const{types:n,texts:i,starts:r}=Yw(e);let o=0;const s=f=>{const h=n[o];if(h===1)throw cM("block",e,r[o],"",true);throw cM("block",e,r[o],`Expecting ${f}, got '${ug[h]}'`)};const a=f=>{if(n[o]!==f)s(`'${ug[f]}'`);return i[o++]};const l=()=>{const f=a(32);if(n[o]===27){const h=i[o++];const m=vy(a(6));return{id:f,label:m,typeStr:h+a(28)}}if(n[o]===29){const h=i[o++];const m=vy(a(6));const p=[a(31)];while(n[o]===31)p.push(i[o++]);return{id:f,label:m,typeStr:h+a(30),directions:p}}return{id:f}};const c=()=>{const f=l();const h=n[o]===36?parseInt(i[o++],10):1;let m={id:f.id,label:f.label,type:t.typeStr2Type(f.typeStr),directions:f.directions,widthInColumns:h};let p;while(n[o]===33||n[o]===34){let g="";if(n[o++]===34){a(35);g=vy(a(6));a(33)}const y=i[o-1];const w=l();const S=t.edgeStrToEdgeData(y);const x=t.edgeStrToEdgeStartData(y);const M=t.edgeStrToThickness(y);const b=t.edgeStrToPattern(y);p??=[{id:m.id,label:m.label,type:m.type,directions:m.directions}];m={id:w.id,label:w.label,type:t.typeStr2Type(w.typeStr),directions:w.directions};p.push({id:p[p.length-1].id+"-"+w.id,start:p[p.length-1].id,end:w.id,label:g,type:"edge",thickness:M,pattern:b,directions:w.directions,arrowTypeEnd:S,arrowTypeStart:x},m)}return p??m};a(2);if(re("block"))Ge("block","header",i[0],{offset:r[0],endOffset:r[0]+i[0].length,unit:"physical"});const d=[];let u=[];while(true){const f=o,h=n[o];if(h!==37&&re("block"))Ge("block",ug[h],i[f],{offset:r[f],endOffset:r[f]+i[f].length,unit:"physical"});switch(n[o]){case 32:u.push(c());break;case 4:u.push({type:"column-setting",columns:parseInt(i[o++],10)});break;case 7:{const m=parseInt(i[o++],10);u.push({id:t.generateId(),type:"space",label:"",width:m,children:[]});break}case 2:o++;Ve("nesting",d.length+1);d.push({list:u,header:void 0});u=[];break;case 3:o++;Ve("nesting",d.length+1);if(n[o]!==32)s("'NODE_ID'");d.push({list:u,header:c()});u=[];break;case 26:{const m=d.pop();if(m===void 0||u.length===0)return s(Ch);o++;const p=t.generateId();const g=kF(u);u=m.list;u.push(m.header===void 0?{id:p,type:"composite",label:"",children:g}:{...m.header,type:"composite",children:g});break}case 11:{o++;const m=a(13).trim();u.push({type:"classDef",id:m,css:a(14).trim()});break}case 15:{o++;const m=a(16).trim();u.push({type:"applyClass",id:m,styleClass:a(17).trim()});break}case 18:{o++;const m=a(19).trim();u.push({type:"applyStyles",id:m,stylesStr:a(20).trim()});break}case 37:if(d.length>0)s(Ch+", 'end'");if(u.length===0)s(Ch);t.setHierarchy(kF(u));return;default:s(u.length===0?Ch:Ch+(d.length>0?", 'end'":", 'EOF'"))}}}var XX=e=>/^ishikawa(?:-beta)?\s*(?:%%.*)?$/i.test(e.trim());function PF(e){const t=zt(typeof e==="string"?e.split(/\r?\n/):e);yr(t);const n=t.familyLines;const i=n.findIndex(a=>a.trim()&&!a.trim().startsWith("%%"));if(!XX(n[i]??""))throw new Error("Ishikawa source must start with ishikawa");const r={kind:"ishikawa",nodes:[],...Ar(Yo(t.accessibility))};const o=[];let s;for(let a=i+1;a<n.length;a++){const l=n[a];const c=l.trim();if(!c||c.startsWith("%%"))continue;const d=So(jo(c));Ge("ishikawa","node",l,{line:a+1,unit:"normalized"});Ve("nodes",r.nodes.length+1);const u=l.match(/^[\t ]*/)?.[0].length??0;if(r.nodes.length===0){const m={id:"effect",label:d};r.nodes.push(m);he("ishikawa","add-node",m);o.push({level:0,node:m});continue}s??=u;const f=Math.max(1,u-s+1);while(o.length>1&&o.at(-1).level>=f)o.pop();Ve("nesting",o.length);const h={id:`cause-${r.nodes.length}`,label:d,parentId:o.at(-1).node.id};r.nodes.push(h);o.push({level:f,node:h});he("ishikawa","add-node",h)}return r}function ra(e){const t=new Map;for(const n of e){const i=t.get(n.parentId)??[];i.push(n);t.set(n.parentId,i)}return t}function ype(e,t){const n=ra(e);const i=new Set;const r=[t];while(r.length){const o=r.pop();if(i.has(o))throw new Error("Hierarchy contains a cycle");i.add(o);for(const s of n.get(o)??[])r.push(s.id)}return i}function Ly(e,t){Ve("nodes",e.length);const n=new Map(e.map(o=>[o.id,o]));if(n.size!==e.length)throw new Error("Hierarchy contains duplicate identities");const i=new Set(e.map(o=>o.parentId));const r=new Map;for(const o of e){const s=new Set;const a=t?.(o)??i.has(o.id);let l=o;while(l&&!r.has(l.id)){if(s.has(l.id))throw new Error("Hierarchy contains a cycle");s.add(l.id);Ve("nesting",s.size-(a?0:1));if(l.parentId&&!n.has(l.parentId))throw new Error(`Unknown parent ${l.parentId}`);l=l.parentId?n.get(l.parentId):void 0}let c=l?r.get(l.id):0;for(const d of[...s].reverse()){const u=n.get(d);c+=t?.(u)??i.has(d)?1:0;Ve("nesting",c);r.set(d,c)}}}var Ay=class extends Error{constructor(t,n,i){super(t)}};function dM(e,t,n=0,i="",r=false){const o=t.slice(0,n).split(/\r\n?|\n/),s=o.length,a=o.at(-1).length+1;return new Error(`${e} ${r?"lexical":"parse"} error at line ${s}, column ${a}: ${i||"unrecognized input"}`)}var yc={REQUIREMENT:"Requirement",FUNCTIONAL_REQUIREMENT:"Functional Requirement",INTERFACE_REQUIREMENT:"Interface Requirement",PERFORMANCE_REQUIREMENT:"Performance Requirement",PHYSICAL_REQUIREMENT:"Physical Requirement",DESIGN_CONSTRAINT:"Design Constraint"};var Fy={LOW_RISK:"Low",MED_RISK:"Medium",HIGH_RISK:"High"};var Ph={VERIFY_ANALYSIS:"Analysis",VERIFY_DEMONSTRATION:"Demonstration",VERIFY_INSPECTION:"Inspection",VERIFY_TEST:"Test"};var Za={CONTAINS:"contains",COPIES:"copies",DERIVES:"derives",SATISFIES:"satisfies",VERIFIES:"verifies",REFINES:"refines",TRACES:"traces"};var UX=1e6;var Iy=class{type="requirement";direction="TB";requirements=new Map;elements=new Map;relations=[];classes=new Map;authoredStyles=new Map;title;accTitle;accDescr;newId="";newText="";newRisk="";newVerifyMethod="";newElementType="";newDocRef="";styleCopies=0;copy(t,n){this.styleCopies+=n.length;if(this.styleCopies>UX){throw new Ay("Requirement diagram applies too many style declarations.","limit",{type:"requirement"})}for(const i of n)t.push(i)}setDirection(t){this.direction=t;if(re("requirement"))he("requirement","setDirection",t)}addRequirement(t,n){let i=this.requirements.get(t);if(i===void 0){Ve("nodes",this.requirements.size+this.elements.size+1);i={name:t,type:n,requirementId:this.newId,text:this.newText,risk:this.newRisk,verifyMethod:this.newVerifyMethod,cssStyles:[],classes:["default"]};this.requirements.set(t,i);if(re("requirement"))he("requirement","addRequirement",i)}this.newId=this.newText=this.newRisk=this.newVerifyMethod="";return i}setNewReqId(t){this.newId=t;if(re("requirement"))he("requirement","setNewReqId",t)}setNewReqText(t){this.newText=t;if(re("requirement"))he("requirement","setNewReqText",t)}setNewReqRisk(t){this.newRisk=t;if(re("requirement"))he("requirement","setNewReqRisk",t)}setNewReqVerifyMethod(t){this.newVerifyMethod=t;if(re("requirement"))he("requirement","setNewReqVerifyMethod",t)}addElement(t){let n=this.elements.get(t);if(n===void 0){Ve("nodes",this.requirements.size+this.elements.size+1);n={name:t,type:this.newElementType,docRef:this.newDocRef,cssStyles:[],classes:["default"]};this.elements.set(t,n);if(re("requirement"))he("requirement","addElement",n)}this.newElementType=this.newDocRef="";return n}setNewElementType(t){this.newElementType=t;if(re("requirement"))he("requirement","setNewElementType",t)}setNewElementDocRef(t){this.newDocRef=t;if(re("requirement"))he("requirement","setNewElementDocRef",t)}addRelationship(t,n,i){Ve("edges",this.relations.length+1);this.relations.push({type:t,src:n,dst:i});if(re("requirement"))he("requirement","addRelationship",{type:t,src:n,dst:i})}node(t){return this.requirements.get(t)??this.elements.get(t)}setCssStyle(t,n){for(const i of t){const r=this.authoredStyles.get(i)??[];this.copy(r,n);this.authoredStyles.set(i,r)}for(const i of t){const r=this.node(i);if(!n||!r)return;(r.directStyles??=[]).push(...n.flatMap(o=>o.split(",")));for(const o of n){this.copy(r.cssStyles,o.includes(",")?o.split(","):[o]);if(re("requirement"))he("requirement","setCssStyle",{id:i,style:o,node:r})}}}setClass(t,n){for(const i of t){const r=this.node(i);if(!r)continue;for(const o of n){r.classes.push(o);if(re("requirement"))he("requirement","setClass",{id:i,className:o});const s=this.classes.get(o)?.styles;if(s)this.copy(r.cssStyles,s)}}}defineClass(t,n){for(const i of t){let r=this.classes.get(i);if(r===void 0){r={id:i,styles:[],textStyles:[]};this.classes.set(i,r)}for(const s of n){if(s.includes("color"))r.textStyles.push(s.replace("fill","bgFill"));r.styles.push(s)}if(re("requirement"))he("requirement","defineClass",r);const o=n.flatMap(s=>s.split(","));for(const s of this.requirements.values()){if(s.classes.includes(i))this.copy(s.cssStyles,o)}for(const s of this.elements.values()){if(s.classes.includes(i))this.copy(s.cssStyles,o)}}}setAccTitle(t){this.accTitle=t.replace(/^\s+/g,"");if(re("requirement"))he("requirement","setAccTitle",this.accTitle)}setAccDescription(t){this.accDescr=t.replace(/\n\s+/g,"\n");if(re("requirement"))he("requirement","setAccDescription",this.accDescr)}};var VX=[yc.REQUIREMENT,yc.FUNCTIONAL_REQUIREMENT,yc.INTERFACE_REQUIREMENT,yc.PERFORMANCE_REQUIREMENT,yc.PHYSICAL_REQUIREMENT,yc.DESIGN_CONSTRAINT,Fy.LOW_RISK,Fy.MED_RISK,Fy.HIGH_RISK,Ph.VERIFY_ANALYSIS,Ph.VERIFY_DEMONSTRATION,Ph.VERIFY_INSPECTION,Ph.VERIFY_TEST,"",Za.CONTAINS,Za.COPIES,Za.DERIVES,Za.SATISFIES,Za.VERIFIES,Za.REFINES,Za.TRACES];function EF(e){return e===49||e===50||e===54||e===53||e===51}function RF(e,t,n){const i=Array.isArray(e)?e.join("\n"):e;const r=i.replace(/^[^\S\r\n]*requirement[^\S\r\n]*(?=\r\n?|\n|$)/i,"requirementDiagram");const o=r.length-i.length;const s=new Iy;KX(r.endsWith("\n")?r:r+"\n",s,t,n?a=>n(a-o):void 0);for(const a of s.classes.values())Tt(vn(a.styles.join(",")),`classDef ${a.id}`);for(const[a,l]of s.authoredStyles){Tt(vn(l.join(",")),`style ${a}`)}for(const a of[...s.requirements.values(),...s.elements.values()]){Tt(vn((a.directStyles??[]).join(",")),`style ${a.name}`)}return{kind:"requirement",direction:s.direction,requirements:[...s.requirements.values()],elements:[...s.elements.values()],relations:s.relations.map((a,l)=>({...a,id:`relation-${l+1}`})),classDefs:[...s.classes.values()],title:s.title,accessibilityTitle:s.accTitle,accessibilityDescription:s.accDescr}}function KX(e,t,n,i){const{types:r,texts:o,starts:s}=Xw(e);let a=0;const l=[];const c=[];const d=(x,M=x,...b)=>{const C=r[a];if(C===1)throw dM("requirement",e,s[a],"",true);for(let E=M;E>=x;E--)b.unshift(E);const P=b.map(E=>`'${Ed[E]}'`).join(", ");throw dM("requirement",e,s[a],`Expecting ${P}, got '${Ed[C]}'`)};const u=x=>{if(r[a]!==x)d(x);if(x===12&&r[a-1]!==59)i?.(s[a]);return o[a++]};const f=(x,M)=>{const b=r[a];if(b<x||b>M)d(x,M);a++;return VX[b-23]};const h=()=>{const x=r[a];if(x!==59&&x!==58)d(58,59);return o[a++]};const m=()=>{const x=a;const M=r[a];if(M===3){a++;t.setAccTitle(u(4).trim())}else if(M===5){a++;t.setAccDescription(u(6).trim())}else if(M===7){t.setAccDescription(o[a++].trim())}else{return false}if(re("requirement"))Ge("requirement",Ed[M],e.slice(s[x],s[a]??e.length),{offset:s[x],endOffset:s[a]??e.length,unit:"physical"});return true};const p=()=>{const x=[];while(true){const M=r[a];if(M!==49&&M!==59&&M!==58)d(58,59,49);x.push(o[a++]);if(r[a]!==60)return x;a++}};const g=()=>{const x=[];while(true){if(!EF(r[a]))d(49,51,53,54);let M=o[a++];while(EF(r[a])){const b=s[a-1]+o[a-1].length;if(M.includes(":")&&!M.endsWith(":")&&s[a]>b)M+=e.slice(b,s[a]);M+=o[a++]}x.push(M);if(r[a]!==60)return x;a++}};const y=()=>{let x;if(r[a]===17){a++;x=p();u(15)}else if(r[a]===15){a++}else{d(15,15,17)}u(12);return x};const w=x=>{l.length=0;c.length=0;while(true){const M=r[a];if(M===16){a++;break}if(M===12){a++;continue}if(x?M<19||M>22:M!==44&&M!==45){if(x)d(19,22,12,16);d(44,45,12,16)}const b=a;a++;u(18);c.push(M===21?f(29,31):M===22?f(32,35):h());l.push(M);u(12);if(re("requirement"))Ge("requirement",Ed[M],e.slice(s[b],s[a]??e.length),{offset:s[b],endOffset:s[a]??e.length,unit:"physical"})}for(let M=l.length-1;M>=0;M--){const b=c[M];switch(l[M]){case 19:t.setNewReqId(b);break;case 20:t.setNewReqText(b);break;case 21:t.setNewReqRisk(b);break;case 22:t.setNewReqVerifyMethod(b);break;case 44:t.setNewElementType(b);break;default:t.setNewElementDocRef(b)}}};while(m()){if(r[a]===12)a++}if(r[a]!==14)d(14,14,3,5,7);const S=a++;u(12);if(re("requirement"))Ge("requirement","header",e.slice(s[S],s[a]??e.length),{offset:s[S],endOffset:s[a]??e.length,unit:"physical"});while(true){const x=a;const M=r[a];if(M===13)return;if(M!==12&&M!==3&&M!==5&&M!==7&&re("requirement"))Ge("requirement",Ed[M],o[x],{offset:s[x],endOffset:s[x]+o[x].length,unit:"physical"});if(M===12){a++}else if(m()){continue}else if(M>=8&&M<=11){a++;t.setDirection(M===8?"TB":M===9?"BT":M===10?"RL":"LR")}else if(M>=23&&M<=28){const b=f(23,28);const C=h();const P=y();w(true);t.addRequirement(C,b);if(P)t.setClass([C],P)}else if(M===36){a++;const b=h();const C=y();w(false);t.addElement(b);if(C)t.setClass([b],C)}else if(M===46){a++;const b=p();const C=e.slice(s[x],s[a]);const P=g();n?.({prefix:C,styles:P});t.setCssStyle(b,P)}else if(M===47){a++;const b=p();const C=e.slice(s[x],s[a]);const P=g();n?.({prefix:C,styles:P});t.defineClass(b,P)}else if(M===48){a++;const b=p();t.setClass(b,p())}else if(M===59||M===58){const b=o[a++];const C=r[a];if(C===17){a++;t.setClass([b],p())}else if(C===55||C===57){a++;const P=f(37,43);u(C===57?56:57);const E=h();if(C===57)t.addRelationship(P,b,E);else t.addRelationship(P,E,b)}else{d(17,17,55,57)}}else{d(12,13,3,5,7,8,9,10,11,23,24,25,26,27,28,36,47,48,46,59,58)}}}function vF(){const e=[];const t=new Set;const n=new Map;const i=[];const r=new Set;const o=[];const s=new Map;const a=Gg();const l=d=>{if(!t.has(d)){t.add(d);e.push(d)}};const c=(d,u)=>{l(d);if(u!==void 0&&!n.has(d))n.set(d,u);o.at(-1)?.names.push(d)};return{open(d){if(r.has(d))throw new Error(`Duplicate ER subgraph id '${d}'`);r.add(d);i.push(d);o.push({id:d,names:[]})},close(){const d=o.pop();if(!d)throw new Error("ER `end` closes no subgraph");s.set(d.id,a.close(d.id,d.names));o.at(-1)?.names.push(d.id)},get innermost(){return o.at(-1)?.id},declare:c,relationEnd(d,u){if(r.has(d))return false;c(d,u);return true},style:l,created:d=>t.has(d),finish(){const d=o.at(-1);if(d){throw Je({what:`ER subgraph '${d.id}' is never closed`,expectedForm:"each subgraph closed by an end line",example:"subgraph G\n A\nend"})}const u=new Map;for(const f of[...e,...i]){const h=a.ownerOf(f);if(h!==void 0)u.set(f,h)}return{order:e,alias:n,owner:u,groups:i.map(f=>({id:f,...u.has(f)?{parentId:u.get(f)}:{},entityIds:s.get(f).filter(h=>t.has(h))}))}}}}var DF=String.raw`[A-Za-z0-9_][\w.-]*(?![\w.-])`;var Eh=String.raw`"(?:\\.|[^"\\])*"`;var JX=new RegExp(`^${Eh}$`);var OF=`(?:${Eh}|${DF})`;var BF=new RegExp(`^${DF}$`);var Ny=String.raw`${OF}(?:\[\s*(?:${Eh}|[^\]"\r\n]+)\s*\])?(?::::[\w-]+(?:,[\w-]+)*)?`;var QX=new RegExp(String.raw`^(${OF})(?:\[\s*(?:(${Eh})|([^\]"\r\n]+))\s*\])?(?::::([\w-]+(?:,[\w-]+)*))?$`);var TF=String.raw`(?:one or zero|zero or one|one or more|one or many|zero or more|zero or many|only one|many\(0\)|many\(1\)|1\+|0\+|many|one|1|u(?=[.\-|])|[|o}{]+)`;var LF=String.raw`(?:\|\||\|o|o\||\}o|o\{|\}\||\|\{|\bu(?=[.\-|]))`;var ZX=new RegExp(`^(${Ny})(?:[ \\t]+(${TF})|(${LF}))(?:([ \\t]*(?:--|\\.\\.|\\.-|-\\.)[ \\t]*)|([ \\t]+(?:optionally to|to)[ \\t]+))(?:(${TF})[ \\t]+|(${LF}))(${Ny})(?:[ \\t]*:[ \\t]*(.*))?$`,"i");function xc(e,t){const n=e.trim().match(QX);if(!n)return null;const i=n[1].startsWith('"')?dh(n[1],"ER entity name",t):n[1];const r=n[2]!==void 0?dh(n[2],"ER entity alias",t):n[3]?.trim();return{id:i,...r!==void 0?{alias:r}:{},...n[4]?{className:n[4].replaceAll(","," ")}:{},...n[1].startsWith('"')?{quoted:true}:{}}}function e5(e,t){if(t!==void 0)return fh(t,true);return BF.test(e)?{label:e}:fh(e,true)}function jpe(e){const t=e.trim();return BF.test(t)?t:null}function t5(e,t){const n=/^class[ \t]+/i.exec(e);if(!n)return null;const i=e.slice(n[0].length).trimEnd();let r=i.length;const o=[];const s=a=>/[A-Za-z0-9_-]/.test(a);while(r>0){const a=r;while(r>0&&s(i[r-1]))r--;if(r===a)return null;o.push(i.slice(r,a));const l=r;while(r>0&&(i[r-1]===" "||i[r-1]===" "))r--;if(i[r-1]===","){r--;while(r>0&&(i[r-1]===" "||i[r-1]===" "))r--;continue}if(r===l||r===0)return null;const c=i.slice(0,r).split(",").map(d=>xc(d.trim(),t));if(c.length===0||c.some(d=>d===null))return null;return{ids:c.map(d=>d.id),classNames:o.reverse()}}return null}function AF(e,t,n){const i=e.get(t);if(i)for(const r of n)i.push(r);else e.set(t,[...n])}var n5=new RegExp(String.raw`^subgraph\s+(${Eh}|\S+?)(?:\s*\[([^\]]+)\])?$`,"i");function i5(e,t){const n=e.match(n5);if(!n)return null;const i=n[1].startsWith('"')?dh(n[1],"ER subgraph id",t):n[1];const r=n[2]?.trim();if(!r)return{id:i};return{id:i,title:JX.test(r)?dh(r,"ER subgraph title",t):r}}var r5=/[^\x80-\uFFFF\w\s*#:,;-]/;var o5=/#(\d{2}|\d{5}|\d{7});/g;function s5(e){const t=e.codePointAt(0);if(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f\ud800-\udfff\ufffe\uffff]/u.test(e))return void 0;return`#${String(t).padStart(t<=99?2:t<=99999?5:7,"0")};`}function IF(e){let t="ER_STYLE_ENTITY_";while(e.includes(t))t+="_";const n=[];const i=e.replace(o5,(s,a)=>{const l=Number(a);n.push(l<=1114111?String.fromCodePoint(l):"\uFFFD");return`${t}${n.length-1}_`});const r=new RegExp(`${t}(\\d+)_`,"g");const o=s=>s.replace(r,(a,l)=>n[Number(l)]);return Object.fromEntries(Object.entries(vn(i)).map(([s,a])=>[o(s),o(a)]))}function a5(e){const t=[];const n=i=>{let r="";for(const o of i){const s=s5(o);if(!s)return void 0;if(!r5.test(o)&&!",:;\uFB02\xB6".includes(o)&&!/\s/.test(o)){r+=o;continue}r+=s}return r};for(const[i,r]of Object.entries(e)){const o=n(i),s=n(r);if(o===void 0||s===void 0)return void 0;t.push(`${o}:${s}`)}return t.join(",")}function Ype(e,t){const n=a5(t);if(n===void 0)return void 0;const i=`${e} ${n}`,r=`${i};;`;const o=r.length-Un(r).length;const s=i+";".repeat(o);if(Un(s)!==i)throw new Error("ER style statement did not preserve its fields through the entity prepass");return s}function l5(e){return _f(Ht(e))}function qpe(e){return Kr(e)>=0&&l5(e)===void 0}function uM(e,t,n){const i=_f(e);if(i)return{kind:"direction",direction:i};const r=i5(e,n);if(r)return{kind:"group-open",...r};if(e==="end"&&t)return{kind:"end"};const o=e.match(/^classDef\s+([\w,-]+)\s+(.+)$/is);if(o){return{kind:"class-def",names:o[1].split(",").map(f=>f.trim()).filter(Boolean),props:IF(o[2])}}const s=t5(e,n);if(s)return{kind:"class",...s};if(/^class(?:[ \t]|$)/i.test(e))throw new Error(`Invalid ER class assignment: ${e}`);const a=e.match(/^style\s+(.+?)\s+(.+)$/is);if(a){const f=a[1].split(",").map(m=>xc(m.trim(),n));if(f.some(m=>m===null))throw new Error(`Invalid ER style assignment: ${e}`);const h=f.map(m=>m.id);return{kind:"style",ids:h,props:IF(a[2])}}const l=b5(e,n);if(l)return{kind:"relation",relation:l};const c=e.match(WF);const d=c?xc(c[1],n):null;if(d)return{kind:"block-open",reference:d};const u=xc(e,n);return u?{kind:"entity",reference:u}:null}var WF=new RegExp(`^(${Ny})\\s*\\{`);var c5=new RegExp(`^${Ny}`);var zF=new RegExp(String.raw`^(?:\|\||\|o|o\||\}o|o\{|\}\||\|\{|--|\.\.|\.-|-\.|u(?=[.|-])|1\+|0\+|1(?=\s+[\w"']|--|\.\.|\.-|-\.)|(?:one or zero|zero or one|one or more|one or many|zero or more|zero or many|only one|many\(0\)|many\(1\)|many|one|optionally to|to)(?!\w))`,"i");var GF=/^(?:(?:subgraph|end|style|classDef|class|erDiagram)(?!\w)|direction\s+(?:TB|BT|LR|RL))/i;function HF(e){return GF.test(e)||zF.test(e)}function Xpe(e){return e==="1"||HF(e)||/^\d/.test(e)&&!/^\d+(?:\.\d+)?$/.test(e)}function hM(e){let t=false;for(let n=0;n<e.length;n++){const i=e[n];if(t){if(i==='"')t=false}else if(i==='"')t=true;else if(i==="`"&&(n===0||/\s/.test(e[n-1]))){const r=e.indexOf("`",n+1);if(r>n+1&&!/\s/.test(e.slice(n+1,r)))n=r}else if(i==="}")return n}return-1}var d5=/[\w*\u00C0-\uFFFF]/;function jF(e,t,n,i){const r=e.slice(n,i);const o=new Map;const s=[];for(let d=0,u=false;d<r.length;d++){if(r[d]==='"')u=!u;else if(r[d]!=="~"||u)continue;else if(d5.test(r[d+1]??""))s.push(d);else if(s.length>0)o.set(s.pop(),d)}const a=d=>{let u=d;while(u<r.length&&!/[\s"]/.test(r[u]))u++;return u};const l=[];const c=(d,u,f)=>{l.push({kind:d,text:r.slice(u,f),line:t,start:n+u,end:n+f})};for(let d=0;d<r.length;){if(/\s/.test(r[d]))d++;else if(r[d]==='"'){const u=r.indexOf('"',d+1);c(u<0?"stray":"comment",d,u<0?d+1:u+1);d=u<0?d+1:u+1}else{let u=a(d);const f=r.slice(d,u).indexOf("~");const h=f<0?void 0:o.get(d+f);if(h!==void 0&&h>=u)u=a(h+1);c("word",d,u);d=u}}return l}var u5=/^[*A-Za-z_\u00C0-\uFFFF][\w\-[\]().,\u00C0-\uFFFF*]*$/;var f5=/^`[^`]+`$/;var FF=(e,t=e.text)=>e.kind==="word"&&((t.match(/~/g)?.length??0)>=2||u5.test(t)||f5.test(t))&&!/^(?:PK|FK|UK)\b/i.test(t);var h5=e=>e.kind==="word"&&e.text.split(",").every(t=>!t||/^(?:PK|FK|UK)$/i.test(t));function YF(e,t){const n=[];let i=e&&{tokens:[...e.tokens],last:e.last};for(const r of t){if(i?.last==="type"){if(r.text==="?"&&i.tokens.length===1&&!i.tokens[0].text.endsWith("?"))i.tokens.push(r);else if(FF(r))i={tokens:[...i.tokens,r],last:"name"};else return null}else if(i?.last==="name"&&h5(r))i.tokens.push(r);else if(i?.last==="name"&&r.kind==="comment")i={tokens:[...i.tokens,r],last:"comment"};else if(FF(r,r.text.replace(/\?$/,""))){if(i)n.push(i);i={tokens:[r],last:"type"}}else return null}return{done:n,...i?{open:i}:{}}}function qF(e,t,n,i){const r=a=>a.replace(/^`([^`]+)`(\?)?$/,(l,c,d)=>c+(d??""));const o=i===void 0?void 0:uh(yt(i));const s=i===void 0?void 0:K0(i,o,true);return{type:r(e),name:r(t),keys:n,comment:o,...s?{commentContent:s}:{}}}function XF({tokens:e}){const t=e[1]?.text==="?"?1:0;const n=e.slice(2+t).filter(i=>i.kind==="word").map(i=>i.text).join(" ");return n===""||/^(?:PK|FK|UK)(?:\s*,\s*(?:PK|FK|UK))*$/i.test(n)}function UF({tokens:e}){const t=e[1]?.text==="?"?1:0;const n=e.slice(2+t).filter(r=>r.kind==="word").flatMap(r=>r.text.split(",")).filter(Boolean).map(r=>r.toUpperCase());const i=e.find(r=>r.kind==="comment");return qF(e[0].text+(t?"?":""),e[1+t].text,n,i?.text.slice(1,-1))}function m5(e,{tokens:t}){return t.map((n,i)=>{const r=t[i-1];if(!r)return n.text;return((r.endLine??r.line)===n.line?e[n.line].slice(r.end,n.start):" ")+n.text}).join("")}function VF(e,t,n){const i=(c,d)=>({syntax:c,start:d,end:c.kind==="block-open"?d+WF.exec(e.slice(d))[0].length:e.length});const r=NF(e,t,n);if(r)return r;const o=uM(e,t,n);if(o)return[i(o,0)];const s=[];const a=[];const l=[{syntax:{kind:"unknown"},start:0,end:e.length}];for(let c=0;c<e.length;){const d=e.slice(c);if(zF.test(d))return l;if(c>0){const h=[];const m=NF(d,t,(g,y)=>h.push([g,y]));if(m){s.push(...m.map(g=>({...g,start:g.start+c,end:g.end+c})));a.push(...h);break}const p=uM(d,t,(g,y)=>h.push([g,y]));if(p){s.push(i(p,c));a.push(...h);break}}if(GF.test(d))return l;const u=c5.exec(d);const f=u&&xc(u[0],(h,m)=>a.push([h,m]));if(!f)return l;s.push({syntax:{kind:"entity",reference:f},start:c,end:c+u[0].length});c+=u[0].length;c+=e.slice(c).length-e.slice(c).trimStart().length}if(n)for(const[c,d]of a)n(c,d);return s}var p5=/^(?:[^":]|"[^"]*")*?:\s*"[^"]*"/;function NF(e,t,n){const i=p5.exec(e)?.[0].length??-1;if(i<0||!e.slice(i).trim())return null;const r=[];const o=(c,d)=>{r.push([c,d])};let s;let a;const l=e.length-e.slice(i).trimStart().length;try{s=uM(e.slice(0,i),t,o);if(s?.kind!=="relation")return null;a=VF(e.slice(l),t,o)}catch{return null}if(a.some(c=>c.syntax.kind==="unknown"))return null;if(n)for(const[c,d]of r)n(c,d);return[{syntax:s,start:0,end:i},...a.map(c=>({...c,syntax:c.syntax,start:c.start+l,end:c.end+l}))]}function KF(e,t,n){const i=[];let r=0;let o;const s=e.findLastIndex(l=>l.includes('"'));const a=l=>{const c=l.tokens[0];const d=l.tokens.at(-1);i.push({syntax:l.last==="type"?{kind:"unknown"}:{kind:"attribute",attribute:UF(l),text:m5(e,l),...XF(l)?{}:{generous:true}},line:c.line,start:c.start,endLine:d.endLine??d.line,end:d.end})};for(let l=0;l<e.length;l++){const c=e[l];const d=c.trim();const u=[];let f=0;const h=o?.comment;if(h&&d&&!d.startsWith("%%")){const y=c.indexOf('"');h.parts.push((y<0?c:c.slice(0,y)).trim());n?.set(l,y<0?c.length:y+1);if(y<0)continue;u.push({kind:"comment",text:`"${h.parts.join("\n")}"`,line:h.line,start:h.start,endLine:l,end:y+1});o.comment=void 0;f=y+1}else if(!d||d.startsWith("%%")){i.push({syntax:{kind:d?"comment":"blank"},line:l,start:0,endLine:l,end:c.length});continue}const m=c.slice(f);const p=f+m.length-m.trimStart().length+Ht(m.trim()).length;const g=y=>{while(y<p&&/\s/.test(c[y]))y++;return y};for(let y=g(f);y<p||u.length>0;){if(o){const w=hM(c.slice(y,p));const S=w<0?p:y+w;let x=[...u.splice(0),...jF(c,l,y,S)];const M=l<s?x.findIndex(C=>C.kind==="stray"):-1;if(M>=0){o.comment={line:l,start:x[M].start,parts:[c.slice(x[M].start+1,p).trimEnd()]};x=x.slice(0,M)}const b=YF(o.open,x);if(b){for(const C of b.done)a(C);o.open=b.open}else{if(o.open)a(o.open);o.open=void 0;o.comment=void 0;const C=c.slice(y,S).trimEnd();const P=QF(C);i.push({syntax:P?{kind:"attribute",attribute:P,text:C,generous:true}:{kind:"unknown"},line:l,start:y,endLine:l,end:y+C.length})}if(w<0)break;if(o.open)a(o.open);i.push({syntax:{kind:"block-close"},line:l,start:S,endLine:l,end:S+1});o=void 0;y=g(S+1)}else{const w=VF(c.slice(y,p),r>0,t?(S,x)=>t(S,x,l):void 0);for(const{syntax:S,start:x,end:M}of w){i.push({syntax:S,line:l,start:y+x,endLine:l,end:y+M});if(S.kind==="group-open")r++;else if(S.kind==="end")r--;else if(S.kind==="block-open")o={}}y=g(y+w.at(-1).end)}}}return i.sort((l,c)=>l.line-c.line||l.start-c.start)}function Upe(e){const t=new Set;for(const n of KF(e)){if((n.syntax.kind==="style"||n.syntax.kind==="class-def")&&n.line===n.endLine&&e[n.line].slice(n.start,n.end).trim()===e[n.line].trim()){t.add(n.line+1)}}return t}function g5(e,t){const n=new Map;const i=KF(e,t,n);const r=[];const o=new Set;for(let u=i.length-1;u>=0;u--){r[u]=o.has(i[u].endLine);o.add(i[u].line)}const s=new Map;const a=[];const l=vF();let c;for(const[u,{syntax:f,line:h,endLine:m,end:p}]of i.entries()){const g=s.get(h)??0;const y=r[u]?p:e[m].length;s.set(m,y);const w=h===m?e[h].slice(g,y):[e[h].slice(g),...e.slice(h+1,m),e[m].slice(0,y)].join("\n");const S={line:h,column:g,endLine:m,endColumn:y,...l.innermost!==void 0?{groupId:l.innermost}:{},...c!==void 0?{entityId:c}:{}};const x={raw:w,...S,syntax:f};a.push(x);if(re("er"))Ge("er",f.kind,x.raw,{line:h+2,unit:"normalized"});switch(f.kind){case"group-open":l.open(f.id);if(re("er"))he("er","openGroup",{id:f.id,enclosingGroupId:S.groupId},{line:h+2,unit:"normalized"});break;case"end":l.close();if(re("er"))he("er","closeGroup",{id:S.groupId,enclosingGroupId:l.innermost},{line:h+2,unit:"normalized"});break;case"block-open":c=f.reference.id;l.declare(c,f.reference.alias);if(re("er"))he("er","declareEntity",{...f.reference,groupId:S.groupId},{line:h+2,unit:"normalized"});break;case"block-close":c=void 0;break;case"entity":l.declare(f.reference.id,f.reference.alias);if(re("er"))he("er","declareEntity",{...f.reference,groupId:S.groupId},{line:h+2,unit:"normalized"});break;case"relation":x.relationEntityIds=[f.relation.entity1,f.relation.entity2].filter(M=>{const b=l.relationEnd(M.id,M.alias);if(re("er"))he("er","nameRelationshipEndpoint",{...M,isEntity:b,groupId:S.groupId},{line:h+2,unit:"normalized"});return b}).map(M=>M.id);break;case"style":for(const M of f.ids){l.style(M);if(re("er"))he("er","ensureStyledEntity",{id:M},{line:h+2,unit:"normalized"})}break}}if(c!==void 0)throw new Error(`ER_UNCLOSED_ENTITY: entity '${c}' needs a closing }`);const d=l.finish();if(re("er"))he("er","resolvePlacement",d);return{statements:a,placement:d,continuedComments:n}}function JF(e){const t=zt(e);yr(t);e=t.familyLines;const n={entities:[],classDefs:new Map,relationships:[],groups:[],...t.accessibility.title!==void 0?{accessibilityTitle:yt(t.accessibility.title)}:{},...t.accessibility.descr!==void 0?{accessibilityDescription:yt(t.accessibility.descr)}:{}};if(re("er")){Ge("er","header",e[0]??"",{line:1,unit:"normalized"});he("er","initialize",n)}const i=g5(e.slice(1));const r=new Map;const o=new Map;const s=(d,u)=>{const f=$F(r,d);if(u){AF(o,d,u.split(" "));if(re("er"))he("er","appendEntityClasses",{id:d,classNames:o.get(d)})}return f};const a=d=>{return s(d.id,d.className)};const l=new Map;for(const d of i.statements){const u=d.syntax;switch(u.kind){case"unknown":throw new Error(`ER_UNSUPPORTED_STATEMENT: line ${d.line+2}: ${d.raw.trim()}`);case"attribute":r.get(d.entityId).attributes.push(u.attribute);if(re("er"))he("er","addAttribute",{entityId:d.entityId,attribute:u.attribute},{line:d.line+2,unit:"normalized"});break;case"direction":{const f=d.groupId!==void 0?l.get(d.groupId):void 0;if(f)f.direction=u.direction;else n.direction=u.direction;if(re("er"))he("er","setDirection",{direction:u.direction,groupId:f?.id},{line:d.line+2,unit:"normalized"});break}case"group-open":l.set(u.id,{id:u.id,...fh(u.title??u.id,true)});if(re("er"))he("er","upsertGroup",l.get(u.id),{line:d.line+2,unit:"normalized"});break;case"end":break;case"class-def":for(const f of u.names){n.classDefs.set(f,{...u.props});if(re("er"))he("er","setClassDefinition",{name:f,props:n.classDefs.get(f)},{line:d.line+2,unit:"normalized"})}break;case"class":for(const f of u.ids){if(r.has(f)){AF(o,f,u.classNames);if(re("er"))he("er","appendEntityClasses",{id:f,classNames:o.get(f)},{line:d.line+2,unit:"normalized"})}}break;case"style":for(const f of u.ids){const h=$F(r,f);h.inlineStyle={...h.inlineStyle,...u.props};if(re("er"))he("er","setEntityStyle",{id:f,props:h.inlineStyle},{line:d.line+2,unit:"normalized"})}break;case"block-open":a(u.reference);break;case"relation":{n.relationships.push(S5(u.relation,d.raw));if(re("er"))he("er","addRelationship",n.relationships.at(-1),{line:d.line+2,unit:"normalized"});for(const f of[u.relation.entity1,u.relation.entity2]){if(d.relationEntityIds.includes(f.id))s(f.id,f.className)}break}case"entity":a(u.reference);break}}const c=i.placement;for(const[d,u]of o){r.get(d).className=u.join(" ");if(re("er"))he("er","resolveEntityClasses",{id:d,className:r.get(d).className})}n.entities=c.order.map(d=>{const u=r.get(d);Object.assign(u,e5(d,c.alias.get(d)));const f=c.owner.get(d);if(re("er"))he("er","resolveEntity",{...u,groupId:f});return f!==void 0?{...u,groupId:f}:u});n.groups=c.groups.map(d=>{const u={...l.get(d.id),...d.parentId!==void 0?{parentId:d.parentId}:{},entityIds:d.entityIds};if(re("er"))he("er","resolveGroup",u);return u});Am(n);return n}function $F(e,t){let n=e.get(t);if(!n){n={id:t,label:t,attributes:[]};e.set(t,n);if(re("er"))he("er","createEntity",n)}return n}function y5(e){if(Kr(e)>=0||hM(e)>=0)return null;return fM(e)??QF(e)}function fM(e){const t=YF(void 0,jF(e,0,0,e.length));return t?.done.length===0&&t.open&&t.open.last!=="type"&&XF(t.open)?UF(t.open):null}function Vpe(e){if(fM(e))return e;const t=y5(e);if(!t)return e;const n=(e.match(/^\S+\s+\S+\s+(.+)$/)?.[1]??"").match(/"[^"]*"/)?.[0];const i=[t.type,t.name,t.keys.join(", "),n??""].filter(Boolean).join(" ");const r=fM(i);const o=r&&r.type===t.type&&r.name===t.name&&r.keys.join()===t.keys.join()&&r.comment===t.comment;return o?i:e}function QF(e){const t=e.match(/^(\S+)\s+(\S+)(?:\s+(.+))?$/);if(!t||/^(?:"|(?:PK|FK|UK)\b)/i.test(t[1])||!t.slice(1,3).every(a=>/[^\W_]|[\u00C0-\uFFFF]/.test(a)))return null;if(Kr(e)>=0||hM(e)>=0)return null;const n=t[1];const i=t[2];const r=t[3]?.trim()??"";const o=r.match(/"([^"]*)"/);const s=[];for(const a of r.replace(/"[^"]*"/,"").trim().split(/[\s,]+/)){const l=a.toUpperCase();if(l==="PK"||l==="FK"||l==="UK"){s.push(l)}else if(a)return null}return qF(n,i,s,o?.[1])}function x5(e){const t=e.replace(/#\w+;/g,"\xA7");if(t.startsWith('"')||/direction\s+(?:TB|BT|LR|RL)/i.test(t))return false;const n=/^(?:\P{ASCII}|[\w*.-])*/u.exec(t)[0];const i=t.slice(n.length);return n===""||/^\d/.test(n)||HF(t)||/^[^\s"]/.test(i)||(i.match(/"/g)?.length??0)%2===1}function b5(e,t){const n=e.match(ZX);if(!n)return null;const i=n[2]??n[3];if(i==="1"&&/^[ \t]/.test(n[4]??""))return null;const r=xc(n[1],t);const o=xc(n[8],t);if(!r||!o)return null;const s=(n[4]??n[5]).trim().replace(/[ \t]+/g," ").toLowerCase();return{entity1:r,entity2:o,leftToken:i,rightToken:n[6]??n[7],identifying:s==="--"||s==="to",label:gI(n[9]??"",t),...x5(n[9]?.trim()??"")?{unreadLabel:true}:/^[^"\s][^\s"]*(?:\s+\S|")/.test(n[9]?.trim()??"")?{unquotedWords:true}:{}}}function S5(e,t){const n=_F(e.leftToken);const i=_F(e.rightToken);if(!n||!i){throw new Error(`Invalid ER cardinality "${e.leftToken}${e.identifying?"--":".."}${e.rightToken}" in "${t}" (valid tokens include ||, |o, o|, }o, o{, }|, |{ and Mermaid's word/numeric aliases)`)}return{entity1:e.entity1.id,entity2:e.entity2.id,cardinality1:n,cardinality2:i,...fh(e.label,true),identifying:e.identifying}}function _F(e){switch(e.toLowerCase()){case"u":return"parent";case"||":case"only one":case"1":case"one":return"one";case"|o":case"o|":case"one or zero":case"zero or one":return"zero-one";case"}|":case"|{":case"one or more":case"one or many":case"many(1)":case"1+":return"many";case"}o":case"o{":case"zero or more":case"zero or many":case"many(0)":case"0+":case"many":return"zero-many";default:return null}}var Xd=/^title\s+(.+)$/i;var mM=/^([xy])-axis\s+(.+)$/is;var pM=/^quadrant-([1-4])\s+(.+)$/is;var gM=/^(.+?)\s*:\s*\[\s*([^,\]]+)\s*,\s*([^,\]]+)\s*\]\s*(.*)$/s;var yM=/^classDef\s+(.+)$/i;function ZF(e){if(!e.includes(";")||Xd.test(e))return[e];const t=[];let n=0,i=false,r=0;for(let a=0;a<e.length;a++){const l=e[a];if(l==='"')i=!i;if(i)continue;if(l==="%"&&e[a+1]==="%")break;if(l==="(")r++;else if(l===")")r--;else if(l===";"&&r===0){t.push(e.slice(n,a));n=a+1;if(/^\s*title\s/i.test(e.slice(n)))break}}t.push(e.slice(n));const o=[];let s=[];for(let a=0;a<t.length;a++){const l=t[a];if(!l.trim()&&s.length===0)continue;s.push(l);const c=t[a+1]?.trim()??"";const d=gM.test(l.trim());const u=d||yM.test(l.trim())||/^quadrant(?:Chart)?$/i.test(l.trim());const f=mM.test(s[0].trim())||pM.test(s[0].trim());const h=gM.test(c)||yM.test(c)||Xd.test(c)||mM.test(c)||pM.test(c);if(u||f&&h||a===t.length-1){const m=s.join(";").trim();if(m)o.push(m);s=[]}}return o}var w5=/^[\d.,+\s-]*$/;var M5=/^[\d.,+\s-]*\]/;function $y(e){const t=Ir(e,{escapes:false,wholeLine:n=>Xd.test(n)});for(let n=0;n<e.length;n=t[n]+1){const i=t[n];const r=Ht(Ll(e,n,i).trim()).replace(/"[^"]*"/g,'""');const o=r.lastIndexOf("[");if(Xd.test(r)||o<0||r.includes("]",o)||!r.slice(0,o).trimEnd().endsWith(":"))continue;let s=i+1;while(s<e.length&&w5.test(e[s]))s++;if(s<e.length&&M5.test(e[s].trim()))t[n]=s}return t}var k5=/^"[^"]*"/;var C5=/[<>()[\]{}|@^~:;"\n\r\x00-\x08\x0e-\x1f\x7f]/;var P5=/(?<![A-Za-z])(?:[xy]-axis|quadrant-[1-4]|quadrantChart|(?:classDef|title)(?![A-Za-z0-9_]))/i;function tN(e,t=false){const n=t?e.replace(k5,""):e;return n.match(C5)?.[0]??n.match(P5)?.[0]??(e.startsWith("-")?"-":void 0)}function E5(e,t=false){const n=/(?:^|[^A-Za-z])(?:x-axis|y-axis|quadrant-[1-4]|quadrantChart|classDef|accTitle|accDescr|title)/i;return tN(e)!==void 0||t&&(e!==e.trim()||n.test(e))?`"${e}"`:e}function ige(e){const t=E5(e,true).startsWith('"');return!e.startsWith("%%")&&!e.includes("%%{")&&!(t&&e.startsWith("`"))&&(!t||!e.includes('"'))}function Rh(e,t,n){const i=tN(e,true);if(i!==void 0)n?.(`Quadrant ${t} ${JSON.stringify(e)} has ${JSON.stringify(i)} outside a quoted string`);const r=/^"([^"]*)"/.exec(e);return yt(r?r[1]+e.slice(r[0].length):e)}function nN(e,t,n){const i=n?[0]:void 0;if(i)for(const g of e)i.push(i[i.length-1]+g.length+1);const r=zt(e,$y(e));yr(r);const o=r.familyLines;e=Eb(o,$y(o));if(e.length===0){throw new Error("Quadrant chart is empty")}const s=ZF(e[0].trim());const a=Ht(s[0]??"");if(!/^quadrant(?:Chart)?\b\s*$/i.test(a)){throw new Error(`Quadrant chart must start with "quadrant" or "quadrantChart", got: "${a}"`)}if(re("quadrant"))Ge("quadrant","header",a,{line:1,unit:"normalized"});let l;const c={...r.accessibility.title!==void 0?{title:yt(r.accessibility.title)}:{},...r.accessibility.descr!==void 0?{description:yt(r.accessibility.descr)}:{}};let d;let u;const f=[void 0,void 0,void 0,void 0];const h=[];const m=Object.create(null);const p=new Set;for(let g=0;g<e.length;g++){let y=g,w=0,S=n?e[g].indexOf("\n"):-1;let x=g===0?e[g].indexOf(s[0])+s[0].length:0;for(const M of g===0?s.slice(1):ZF(e[g].trim())){const b=n?e[g].indexOf(M,x):0;if(n)x=b+M.length;const C=Xd.test(M)?M:Ht(M);if(C.length===0||C.startsWith("%%"))continue;let P;if(P=C.match(yM)){if(re("quadrant"))Ge("quadrant","classDef",C,{line:g+1,unit:"normalized"});const E=o2(P[1]);if(!E.ok){throw new Error(`Invalid quadrant classDef: ${E.error}`)}m[E.name]=E.style;if(re("quadrant"))he("quadrant","setClassDef",{name:E.name,style:E.style},{line:g+1,unit:"normalized"});continue}if(P=C.match(Xd)){if(re("quadrant"))Ge("quadrant","title",C,{line:g+1,unit:"normalized"});l=yt(P[1].trim());if(re("quadrant"))he("quadrant","setTitle",l,{line:g+1,unit:"normalized"});continue}if(P=C.match(mM)){if(re("quadrant"))Ge("quadrant","axis",C,{line:g+1,unit:"normalized"});const E=R5(P[2].trim(),P[1].toLowerCase(),t);if(P[1].toLowerCase()==="x")d=E;else u=E;if(re("quadrant"))he("quadrant","setAxis",{axis:P[1].toLowerCase(),value:E},{line:g+1,unit:"normalized"});continue}if(P=C.match(pM)){if(re("quadrant"))Ge("quadrant","quadrant",C,{line:g+1,unit:"normalized"});const E=Number.parseInt(P[1],10)-1;f[E]=Rh(P[2].trim(),`quadrant-${P[1]} label`,t);if(re("quadrant"))he("quadrant","setQuadrant",{quadrant:E+1,label:f[E]},{line:g+1,unit:"normalized"});continue}if(P=C.match(gM)){if(re("quadrant"))Ge("quadrant","point",C,{line:g+1,unit:"normalized"});const{label:E,className:k}=s2(P[1].trim());const v=Rh(E,"point label",t);const T=P[4].trim();const A=p0(T,`quadrant point ${v}`);if(!A.ok){throw new Error(`Unsupported quadrant point style metadata: "${T}" \u2014 ${A.error}. Expected comma-separated radius/color/stroke-color/stroke-width entries.`)}const R=eN(v,P[2].trim());const I=eN(v,P[3].trim());if(p.has(v)){throw new Error(`Duplicate quadrant point label: "${v}"`)}p.add(v);if(re("quadrant"))he("quadrant","addPointLabel",v,{line:g+1,unit:"normalized"});const L={label:v,x:R,y:I};if(re("quadrant"))he("quadrant","createPoint",L,{line:g+1,unit:"normalized"});if(k!==void 0){L.className=k;if(re("quadrant"))he("quadrant","setPointClass",{label:v,className:k},{line:g+1,unit:"normalized"})}if(A.style!==void 0){L.style=A.style;if(re("quadrant"))he("quadrant","setPointStyle",{label:v,style:A.style},{line:g+1,unit:"normalized"})}h.push(L);if(n){const $=F=>{while(S>=0&&S<F){y++;w=S+1;S=e[g].indexOf("\n",w)}const z=y===g?0:o[y].length-o[y].trimStart().length;return i[y]+z+F-w};const B=b+C.indexOf(E);n(L,{start:$(B),end:$(B+E.length)})}if(re("quadrant"))he("quadrant","appendPoint",L,{line:g+1,unit:"normalized"});continue}if(C.includes(":")){if(re("quadrant"))Ge("quadrant","invalidPoint",C,{line:g+1,unit:"normalized"});throw new Error(`Invalid quadrant point: "${C}". Expected: Label: [x, y] with x,y in [0,1]`)}if(re("quadrant"))Ge("quadrant","unrecognized",C,{line:g+1,unit:"normalized"});throw Je({what:`Unrecognized quadrant chart line: "${C}"`,expectedForm:"a title, x-axis/y-axis, a quadrant-N label, a point (Label: [x, y]), or a classDef",example:"Quick win: [0.2, 0.8]"})}}return{title:l,...c.title||c.description?{accessibility:c}:{},xAxis:d,yAxis:u,quadrants:f,points:h,classDefs:m}}function R5(e,t,n){const i=t==="x"?"left":"bottom";let r=false,o=-1,s=0;for(let l=0;l<e.length;l++){if(e[l]==='"')r=!r;if(r||e[l]!=="-")continue;const c=/^--+>/.exec(e.slice(l));if(c){o=l;s=c[0].length;break}}if(o>=0){const l=Rh(e.slice(0,o).trim(),`${t}-axis text`,n);const c=e.slice(o+s).trim();if(!l)throw new Error(`Quadrant ${t}-axis is missing its ${i} label: "${e}"`);if(!c)return{near:l+" \u27F6 "};return{near:l,far:Rh(c,`${t}-axis text`,n)}}const a=Rh(e.trim(),`${t}-axis text`,n);if(!a)throw new Error(`Quadrant ${t}-axis is missing its ${i} label`);return{near:a}}function eN(e,t){if(!/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)$/.test(t)){throw new Error(`Quadrant point "${e}" has non-numeric coordinate "${t}". Coordinates must be numbers in [0, 1].`)}const n=Number.parseFloat(t);if(!Number.isFinite(n)||n<0||n>1){throw new Error(`Quadrant point "${e}" coordinate "${t}" is out of range. Coordinates must be in [0, 1].`)}return n}function iN(e){return e.map(t=>Dn(t.trimStart()))}function rN(e){return e.replace(/<br>/g,"\n")}function bc(e,t){const n=t==="title"||t==="accessibility"?e:rN(e);return so(n,{subject:"Timeline text entity",example:"2025 : #35;"})}function age(e,t){if(e===""&&t==="section")return" ";if(!e.length)throw new Error(`Timeline ${t} text must be non-empty`);const n=t==="section"||t==="period"||t==="event";const i="#&"+(n?":<>":"")+(t==="accessibility"?"{}":"")+(e.includes("%%")||t==="period"&&e.startsWith("%")?"%":"");let r=n?e.split("\n").map(o=>dn(o,i)).join("<br>"):dn(e,i);if(t==="period"&&/^(?:timeline\b|title(?:\s|$)|section(?:\s|$)|acc(?:Title|Descr)(?:\s|$|[:{]))/i.test(r)){r=`#${r.codePointAt(0)};${r.slice(1)}`}return r}function oN(e){const t=e.trim().match(/^timeline(?=$|[\s;#%])(.*)$/i);if(!t)return null;const n=t[1];const i=n.search(/#|%(?!\{)/);const r=i>=0;const o=(i<0?n:n.slice(0,i)).trim();if(!o)return{kind:"supported",hasInlineComment:r};if(o.startsWith(";"))return{kind:"unsupported",suffix:o};if(/^(?:LR|TD)$/i.test(o))return{kind:"supported",direction:o.toUpperCase(),hasInlineComment:r};return{kind:"unsupported",suffix:o}}function sN(e){return Je({what:`Unsupported timeline header suffix "${e}"; only LR and TD are direction tokens`,expectedForm:"timeline [LR|TD]",example:"timeline TD"})}var aN=/^title\s+(.+)$/i;var lN=/^:\s+(.+)$/;function cN(e){const t=/^section\s([^:\n]+)/i.exec(e);return t?{label:t[1],eventSource:e.slice(t[0].length)}:null}function dN(e){return/^(?:%(?!\{)|#)/.test(e.trimStart())}var uN=/^([^:#\n]+?)(\s*:\s+.+)$/;function _y(e){const t=[];let n=0;while(n<e.length){while(n<e.length&&/\s/.test(e[n]))n++;if(n>=e.length)break;if(e[n]!==":"){throw Je({what:`Invalid timeline event list: "${e}"`,expectedForm:'events separated by " : "',example:"Launch : Beta"})}n++;if(n>=e.length||!/\s/.test(e[n])){throw new Error(`Timeline events must use ": " separators: "${e}"`)}while(n<e.length&&/\s/.test(e[n]))n++;const i=n;while(n<e.length){if(e[n]===":"&&/\s/.test(e[n+1]??""))break;n++}const r=e.slice(i,n).trim();if(!r||n>=e.length&&r.endsWith(":")){throw Je({what:`Invalid timeline event separator in "${e}"`,expectedForm:"a non-empty event after every separator, without a trailing colon",example:"2024 : Launch : Beta"})}t.push(r)}return t}var fN=64;var vh=256;var v5=/^radar-beta(?:[\t ]*:)?(?=$|\s)/i;var T5=/^title(?:[\t ]+(.*))?$/i;var L5=/^axis\s+([\s\S]+)$/i;var A5=/^curve\s+([\s\S]+)$/i;var hN=/^(showLegend|ticks|max|min|graticule)\b(.*)$/i;var I5=/^(?:0|[1-9]\d*|\d+\.\d+|0\.\d+)$/;var xM=String.raw`[\w](?:[\w-]*[\w])?`;var pN=String.raw`(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')`;var F5=new RegExp(String.raw`^(${xM})\s*(?:\[\s*(${pN})\s*\])?$`);var N5=new RegExp(String.raw`^(${xM})\s*(?:\[\s*(${pN})\s*\])?\s*\{([\s\S]*)\}$`);var $5=new RegExp(String.raw`^(${xM})(?:\s*:\s*|\s+)(.+)$`);var gN={spanning:`"'`,wholeLine:e=>/^(?:title|accTitle|accDescr)(?=[\s:{]|$)/i.test(e)};function yN(e){return Ir(e,gN)}function Dy(e,t){const n=[];let i=0;let r=0;let o=null;let s=false;let a="";for(const l of e){if(s){a+=l;s=false;continue}if(o&&l==="\\"){a+=l;s=true;continue}if(l==='"'||l==="'"){if(o===l)o=null;else if(o===null)o=l;a+=l;continue}if(!o){if(l==="[")i++;else if(l==="]")i--;else if(l==="{")r++;else if(l==="}")r--}if(l===","&&!o&&i===0&&r===0){n.push(a.trim());a=""}else{a+=l}}n.push(a.trim());if(o||i!==0||r!==0){throw new Error(`Radar ${t} has unbalanced quotes or delimiters.`)}if(n.some(l=>l.length===0)){throw new Error(`Radar ${t} contains an empty comma-separated entry.`)}return n}function xN(e,t){const n=e[0];if(n!=='"'&&n!=="'"||e.at(-1)!==n){throw new Error(`Radar ${t} must use a quoted label.`)}let i="";for(let r=1;r<e.length-1;r++){const o=e[r];if(o!=="\\"){i+=o;continue}r++;if(r>=e.length-1)throw new Error(`Radar ${t} has an incomplete escape.`);const s=e[r];i+=s==="n"?"\n":s==="r"?"\r":s==="t"?" ":s==="b"?"\b":s==="f"?"\f":s}return i}var _5=["showLegend","graticule","accTitle","accDescr","title","ticks","curve","axis","max","min"];function mN(e,t){for(const n of _5){if(e.slice(t,t+n.length).toLowerCase()!==n.toLowerCase())continue;const i=e[t+n.length];if(i===void 0||/[\s:]/.test(i))return n}return void 0}function D5(e,t){const n=[];let i=0;while(i<e.length){while(i<e.length&&/\s/.test(e[i]))i++;if(i>=e.length)break;const r=i;const o=mN(e,i);if(o&&/^(?:title|accTitle)$/i.test(o)){while(i<e.length&&e[i]!=="\n"&&e[i]!=="\r")i++;const u=e.slice(r,i).trim();if(u){n.push(u);if(re("radar"))Ge("radar",o,u,{offset:r+t,endOffset:i+t,unit:"normalized"})}continue}if(o?.toLowerCase()==="accdescr"){let u=i+o.length;while(u<e.length&&/[\t ]/.test(e[u]))u++;if(e[u]===":"){u++;while(u<e.length&&/[\t ]/.test(e[u]))u++}if(e[u]==="{"){const h=e.indexOf("}",u+1);if(h<0)throw new Error(`Radar statement is missing a closing "}": "${e.slice(r).trim()}"`);i=h+1;n.push(e.slice(r,i).trim());if(re("radar"))Ge("radar",o,n[n.length-1],{offset:r+t,endOffset:i+t,unit:"normalized"});continue}while(i<e.length&&e[i]!=="\n"&&e[i]!=="\r")i++;const f=e.slice(r,i).trim();if(f){n.push(f);if(re("radar"))Ge("radar",o,f,{offset:r+t,endOffset:i+t,unit:"normalized"})}continue}let s=0;let a=0;let l=null;let c=false;for(;i<e.length;i++){const u=e[i];if(c){c=false;continue}if(l&&u==="\\"){c=true;continue}if(u==='"'||u==="'"){if(l===u)l=null;else if(l===null)l=u;continue}if(l)continue;if(u==="[")s++;else if(u==="]")s--;else if(u==="{")a++;else if(u==="}")a--;if(s<0||a<0){throw new Error(`Radar statement has an unexpected closing delimiter: "${e.slice(r,i+1).trim()}"`)}if((u==="\n"||u==="\r")&&s===0&&a===0)break;if(/[\t ]/.test(u)&&s===0&&a===0){let f=i+1;while(f<e.length&&/[\t ]/.test(e[f]))f++;let h=i-1;while(h>=r&&/[\t ]/.test(e[h]))h--;if(e[h]!==","&&mN(e,f))break}}if(l||s!==0||a!==0){throw new Error(`Radar statement has unbalanced quotes or delimiters: "${e.slice(r,i).trim()}"`)}const d=e.slice(r,i).trim();if(d){n.push(d);if(re("radar"))Ge("radar",o??"unrecognized",d,{offset:r+t,endOffset:i+t,unit:"normalized"})}}return n}function Th(e,t){const n=e.trim();if(n.startsWith("-")||n.startsWith("+")){throw new Error(`Radar ${t} "${n}" has a sign \u2014 radar numbers must be non-negative (the grammar has no sign token).`)}if(!I5.test(n))throw new Error(`Radar ${t} "${n}" is not a valid number.`);const i=Number.parseFloat(n);if(!Number.isFinite(i))throw new Error(`Radar ${t} "${n}" is not finite.`);return i}function O5(e){const t=Th(e,"ticks");if(!Number.isInteger(t)||t<1||t>fN){throw new Error(`Radar ticks must be an integer from 1 through ${fN}, got "${e.trim()}".`)}return t}function B5(e){const t=e.match(F5);if(!t){throw Je({what:`Invalid radar axis: "${e}"`,expectedForm:'an id (not ending in "-") with an optional quoted label',example:'axis speed["Top Speed"], range'})}const n=t[1];const i=t[2]!==void 0?yt(xN(t[2],`axis "${n}" label`)):n;return{id:n,label:i}}function W5(e,t){const n=e.match(N5);if(!n){throw Je({what:`Invalid radar curve: "${e}"`,expectedForm:'an id (not ending in "-") with an optional quoted label and a `{\u2026}` value block',example:'curve a["Alice"]{85, 90, 80}'})}const i=n[1];const r=n[2]!==void 0?yt(xN(n[2],`curve "${i}" label`)):i;const o=Dy(n[3],`curve "${i}" value block`);const s=o.map(u=>!/^[+-]?(?:\d|\.)/.test(u));const a=s.some(Boolean);const l=s.every(Boolean);if(a&&!l){throw new Error(`Radar curve "${i}" mixes positional and keyed entries \u2014 use one form.`)}if(!a)return{id:i,label:r,values:o.map(u=>Th(u,`curve "${i}" value`))};if(t.length===0){throw new Error(`Radar curve "${i}" uses keyed entries (axis: value) but no axes are declared.`)}const c=new Map;for(const u of o){const f=u.match($5);if(!f)throw new Error(`Radar curve "${i}" has an invalid keyed entry: "${u}".`);const h=f[1];const m=Th(f[2],`curve "${i}" entry for "${h}"`);if(!c.has(h)){c.set(h,m);if(re("radar"))he("radar","setCurveAxisValue",{curve:i,axis:h,value:m})}}const d=t.map(u=>{const f=c.get(u.id);if(f===void 0)throw new Error(`Radar curve "${i}" is missing an entry for axis "${u.id}".`);if(re("radar"))he("radar","resolveCurveAxisValue",{curve:i,axis:u.id,value:f});return f});return{id:i,label:r,values:d}}function bN(e,t={}){const n=fa(e.join("\n").split(/\r?\n/),gN);const i=zt(n.map(Ht));yr(i);const r=i.familyLines.join("\n").trimStart();if(!r)throw new Error("Radar chart is empty");const o=r.match(v5);if(!o)throw new Error(`Radar chart must start with "radar-beta", got: "${r.split(/\r?\n/,1)[0]}"`);if(re("radar"))Ge("radar","header",o[0],{offset:0,endOffset:o[0].length,unit:"normalized"});const s=D5(r.slice(o[0].length),o[0].length);let a=t.title;if(a!==void 0&&re("radar"))he("radar","setFrontmatterTitle",a);const l={...i.accessibility.title!==void 0?{title:yt(i.accessibility.title)}:{},...i.accessibility.descr!==void 0?{description:yt(i.accessibility.descr)}:{}};const c=[];const d=[];let u=0;let f;let h=5;let m="circle";let p=true;const g={};for(let w=0;w<s.length;w++){const S=s[w];let x;const M=vt(S.split("\n"),0);if(M===void 0)throw new Error('Radar accDescr block is missing a closing "}"');if(M!==null){const b=yt(M.value);if(M.title){g.title=M.value;if(i.accessibility.title===void 0)l.title=b}else{g.descr=M.value;if(i.accessibility.descr===void 0)l.description=b}if(re("radar"))he("radar",M.title?"setAccessibilityTitle":"setAccessibilityDescription",b);continue}if(x=S.match(T5)){a=yt((x[1]??"").trim());if(re("radar"))he("radar","setTitle",a);continue}if(x=S.match(L5)){for(const b of Dy(x[1],"axis list")){if(c.length>=vh){throw new Error(`Radar charts support at most ${vh} axes.`)}c.push(B5(b));if(re("radar"))he("radar","appendAxis",c[c.length-1])}continue}if(x=S.match(A5)){for(const b of Dy(x[1],"curve list")){d.push(b);if(re("radar"))he("radar","appendPendingCurve",b)}continue}if(hN.test(S)){for(const b of Dy(S,"option list")){const C=b.match(hN);if(!C)throw new Error(`Invalid radar option: "${b}"`);const P=C[1].toLowerCase();const E=C[2].trim();switch(P){case"showlegend":if(!/^(true|false)$/i.test(E))throw new Error(`Radar showLegend must be true or false, got "${E}".`);p=E.toLowerCase()==="true";if(re("radar"))he("radar","setShowLegend",p);break;case"ticks":h=O5(E);if(re("radar"))he("radar","setTicks",h);break;case"max":f=Th(E,"max");if(re("radar"))he("radar","setMax",f);break;case"min":u=Th(E,"min");if(re("radar"))he("radar","setMin",u);break;case"graticule":if(E!=="circle"&&E!=="polygon")throw new Error(`Radar graticule must be circle or polygon, got "${E}".`);m=E;if(re("radar"))he("radar","setGraticule",m);break}}continue}throw Je({what:`Unrecognized radar chart line: "${S}"`,expectedForm:"a title, accessibility directive, axis, curve, or option (min/max/ticks/graticule/showLegend)",example:"axis a, b, c"})}const y=d.map(w=>{const S=W5(w,c);if(re("radar"))he("radar","resolveCurve",S);return S});if(f!==void 0&&f<=u)throw new Error(`Radar max (${f}) must be greater than min (${u}).`);return{title:a,...l.title||l.description?{accessibility:l}:{},...Object.keys(g).length>0?{statementAccessibility:g}:{},axes:c,curves:y,min:u,max:f,ticks:h,graticule:m,showLegend:p}}function SN(e){if(!Number.isFinite(e.min)||e.min<0)throw new Error(`Radar min must be a finite non-negative number, got ${e.min}.`);if(e.max!==void 0&&(!Number.isFinite(e.max)||e.max<0)){throw new Error(`Radar max must be a finite non-negative number, got ${e.max}.`)}let t=false;let n=1;for(const r of e.curves){for(const o of r.values){if(!Number.isFinite(o)||o<0)throw new Error(`Radar curve "${r.id}" contains a non-finite or negative value.`);if(!t||o>n)n=o;t=true}}const i=e.max??(t?n:1);if(!(i>e.min)){throw new Error(`Radar scale is degenerate: max (${i}) must be greater than min (${e.min}). Set an explicit \`max\`, or ensure curve values span a range.`)}return{min:e.min,max:i}}function wN(e,t){const n=Math.min(Math.max(e,t.min),t.max);return(n-t.min)/(t.max-t.min)}var z5=/^\+?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/;var MN=e=>/^sankey(?:-beta)?\s*$/i.test(e.trim());function kN(e,t={}){const n=e.findIndex(d=>d.trim().length>0&&!d.trim().startsWith("%%"));if(n<0){throw new Error("Sankey diagram is empty")}const i=e[n].trim();if(!MN(i)){throw new Error(`Sankey diagram must start with "sankey" or "sankey-beta", got: "${i}"`)}if(re("sankey"))Ge("sankey","header",i,{line:n+1,unit:"physical"});const r=[];const o=new Set;const s=[];const a=(d,u)=>{if(!o.has(d)){o.add(d);r.push(d);if(re("sankey"))he("sankey","appendNode",d,{line:u,unit:"physical"})}};for(let d=n+1;d<e.length;d++){let u=e[d].replace(/\r$/,"");const f=d+1;const h=u.trim();if(MN(h)){if(re("sankey"))Ge("sankey","header",u,{line:f,unit:"physical"});continue}if(h.length===0||h.startsWith("%%"))continue;const m=vt(e,d);if(m){if(re("sankey"))Ge("sankey",m.title?"accTitle":"accDescr",e.slice(d,m.endIndex+1).join("\n"),{line:f,unit:"physical"});d=m.endIndex;continue}while(H5(u)&&d+1<e.length){d++;u+=`
24
+ ${e[d].replace(/\r$/,"")}`}const p=u.trim();if(re("sankey"))Ge("sankey","csvRecord",u,{line:f,unit:"physical"});const g=G5(u,f);if(g.length!==3){throw Je({what:`Sankey row ${f} has ${g.length} column${g.length===1?"":"s"}: "${p}"`,expectedForm:"exactly three CSV columns: source,target,value",example:"Electricity grid,Industry,342.165"})}const[y,w,S]=g;if(y.length===0||w.length===0){throw new Error(`Sankey row ${f} has an empty ${y.length===0?"source":"target"} label: "${p}"`)}if(!z5.test(S)){throw new Error(`Sankey flow "${y}" -> "${w}" has invalid value "${S}". Values must be non-negative numbers.`)}const x=Number(S);if(!Number.isFinite(x)||x<0){throw new Error(`Sankey flow "${y}" -> "${w}" has invalid value "${S}". Values must be non-negative numbers.`)}if(y===w){throw new Error(`Sankey flow "${y}" -> "${w}" is a self-loop. Sankey diagrams must be acyclic (upstream rejects circular links).`)}a(y,f);a(w,f);s.push({source:y,target:w,value:x});if(re("sankey"))he("sankey","appendLink",s[s.length-1],{line:f,unit:"physical"})}if(s.length===0){throw new Error("Sankey diagram must include at least one source,target,value row")}const l=j5(s);if(re("sankey"))he("sankey","resolveCycle",l);if(l){throw new Error(`Sankey diagram contains a cycle: ${l.map(d=>`"${d}"`).join(" -> ")}. Sankey diagrams must be acyclic (upstream rejects circular links).`)}const c={...t.title!==void 0?{title:t.title}:{},nodes:r,links:s};if(t.title!==void 0&&re("sankey"))he("sankey","setFrontmatterTitle",c.title);return c}function G5(e,t){const n=[];let i=0;while(true){let r=i;while(r<e.length&&(e[r]===" "||e[r]===" "))r++;if(e[r]==='"'){let o=r+1;let s="";let a=false;while(o<e.length){const c=e[o];if(c==='"'){if(e[o+1]==='"'){s+='"';o+=2;continue}a=true;o++;break}s+=c;o++}if(!a){throw new Error(`Sankey row ${t} has an unterminated quoted field: "${e.trim()}"`)}let l=o;while(l<e.length&&(e[l]===" "||e[l]===" "))l++;if(l<e.length&&e[l]!==","){throw new Error(`Sankey row ${t} has text after a closing quote: "${e.trim()}". Escape a literal quote by doubling it ("").`)}n.push(s.trim());i=l}else{let o=e.indexOf(",",r);if(o===-1)o=e.length;const s=e.slice(i,o).trim();if(s.includes('"')){throw new Error(`Sankey row ${t} has a quote inside the unquoted field "${s}": "${e.trim()}". Quote the whole field and double each quote inside it ("").`)}n.push(s);i=o}if(i>=e.length)break;i++;if(i>=e.length){n.push("");break}}return n}function H5(e){let t=false;for(let n=0;n<e.length;n++){if(e[n]!=='"')continue;if(t&&e[n+1]==='"'){n++;continue}t=!t}return t}function j5(e){const t=[];const n=new Set;const i=new Map;for(const o of e){for(const a of[o.source,o.target]){if(!n.has(a)){n.add(a);t.push(a)}}const s=i.get(o.source);if(s)s.push(o.target);else i.set(o.source,[o.target])}const r=new Map;for(const o of t){if(r.has(o))continue;const s=[{label:o,next:0}];r.set(o,"active");while(s.length>0){const a=s[s.length-1];const l=i.get(a.label)??[];if(a.next>=l.length){r.set(a.label,"done");s.pop();continue}const c=l[a.next];a.next++;const d=r.get(c);if(d==="active"){const u=s.findIndex(f=>f.label===c);return[...s.slice(u).map(f=>f.label),c]}if(d===void 0){r.set(c,"active");s.push({label:c,next:0})}}}return void 0}function CN(e,t={}){const n=zt(iN(e));yr(n);e=n.familyLines;const i={sections:[],...Ar(Object.fromEntries(Object.entries({...t,...n.accessibility}).map(([h,m])=>[h,bc(Dn(m),"accessibility")])))};const r=oN(e[0]??"");if(r?.kind==="unsupported")throw sN(r.suffix);if(r?.direction)i.direction=r.direction;if(re("timeline")){Ge("timeline","header",e[0]??"",{line:1,unit:"normalized"});he("timeline","initialize",i)}let o;let s;let a=0;let l=0;let c=0;let d=1;const u=()=>{if(o)return o;o={id:`section-${a++}`,periods:[]};i.sections.push(o);if(re("timeline"))he("timeline","addImplicitSection",o,{line:d,unit:"normalized"});return o};const f=(h,m)=>{for(const p of m){const g=bc(p.trim(),"event");if(!g)continue;const y={id:`event-${c++}`,text:g};h.events.push(y);if(re("timeline"))he("timeline","addEvent",{...y,periodId:h.id},{line:d,unit:"normalized"})}};for(let h=1;h<e.length;h++){const m=e[h];d=h+1;if(dN(m))continue;const p=m.match(aN);if(p){if(re("timeline"))Ge("timeline","title",m,{line:h+1,unit:"normalized"});i.title=bc(p[1].trim(),"title");if(re("timeline"))he("timeline","setTitle",i.title,{line:h+1,unit:"normalized"});continue}const g=cN(m);if(g){if(re("timeline"))Ge("timeline","section",m,{line:h+1,unit:"normalized"});o={id:`section-${a++}`,label:bc(g.label.trim(),"section"),periods:[]};i.sections.push(o);if(re("timeline"))he("timeline","addSection",o,{line:h+1,unit:"normalized"});if(g.eventSource){if(!s)throw new Error("Timeline continuation found before any period was declared");f(s,_y(g.eventSource))}continue}const y=m.match(lN);if(y){if(re("timeline"))Ge("timeline","continuation",m,{line:h+1,unit:"normalized"});if(!s){throw new Error("Timeline continuation found before any period was declared")}f(s,_y(`: ${y[1]}`));continue}const w=m.match(uN);if(w){if(re("timeline"))Ge("timeline","period",m,{line:h+1,unit:"normalized"});const S=bc(w[1].trim(),"period");const x=_y(w[2]);if(!S){throw Je({what:`Invalid timeline period: "${m}"`,expectedForm:"Period : Event[ : Event\u2026]",example:"2025 : Launch : Beta"})}const M={id:`period-${l++}`,label:S,events:[]};f(M,x);if(M.events.length===0){throw new Error(`Timeline period "${S}" must include at least one event`)}u().periods.push(M);if(re("timeline"))he("timeline","addPeriod",{...M,sectionId:o.id},{line:h+1,unit:"normalized"});s=M;continue}if(!m.includes(":")&&m.trim().length>0){if(re("timeline"))Ge("timeline","bare-period",m,{line:h+1,unit:"normalized"});const S={id:`period-${l++}`,label:bc(m.trim(),"period"),events:[]};u().periods.push(S);if(re("timeline"))he("timeline","addPeriod",{...S,sectionId:o.id},{line:h+1,unit:"normalized"});s=S;continue}if(re("timeline"))Ge("timeline","invalid",m,{line:h+1,unit:"normalized"});throw Je({what:`Unsupported timeline syntax: "${m}"`,expectedForm:"a title, a section, or a period (Period : Event\u2026)",example:"2025 : Launch"})}return i}function LN(e,t={}){const n=Oy(e,t.strict===true);const i=zt(n);const r=i.accessibility;let o=i.familyLines;if(i.unclosedIndex!==void 0){if(t.strict)throw new Error('XYChart accDescr block is missing a closing "}"');const p=i.unclosedIndex;o=i.familyLines.slice(0,p-n.length);r.descr=n.slice(p).join("\n").replace(/^[^{]*\{/,"").trim()||void 0}const s={};const a={};const l=[];const c=Oy(o,t.strict===true);let d;let u=false;let f;const h=c[0];const m=h?.match(/^xychart(?:-beta)?(?:\s+(horizontal|vertical))?$/i);if(!m&&t.strict){throw new Error(`Invalid XYChart header: "${h??""}"`)}if(m&&re("xychart"))Ge("xychart","header",h,{line:1,unit:"normalized"});if(m?.[1]){f=m[1].toLowerCase();if(re("xychart"))he("xychart","setHeaderOrientation",f,{line:1,unit:"normalized"});u=f==="horizontal";if(re("xychart"))he("xychart","setHorizontal",u,{line:1,unit:"normalized"})}for(let p=m?1:0;p<c.length;p++){const g=c[p];const y=g.match(/^title\s+([\s\S]+)$/i);if(y){if(re("xychart"))Ge("xychart","title",g,{line:p+1,unit:"normalized"});const M=Sc(y[1]);if(M===null){if(t.strict)throw new Error(`Invalid XYChart title directive: "${g}"`)}else{d=M;if(re("xychart"))he("xychart","setTitle",d,{line:p+1,unit:"normalized"})}continue}const w=g.match(/^x-axis\s+([\s\S]+)$/i);if(w){if(re("xychart"))Ge("xychart","x-axis",g,{line:p+1,unit:"normalized"});if(!wM(s,w[1],"x",p+1)&&t.strict){throw new Error(`Invalid XYChart x-axis directive: "${g}"`)}continue}const S=g.match(/^y-axis\s+([\s\S]+)$/i);if(S){if(re("xychart"))Ge("xychart","y-axis",g,{line:p+1,unit:"normalized"});if(!wM(a,S[1],"y",p+1)&&t.strict){throw new Error(`Invalid XYChart y-axis directive: "${g}"`)}continue}const x=NN(g);if(x?.type==="bar"){if(re("xychart"))Ge("xychart","bar",g,{line:p+1,unit:"normalized"});const M=PN(x.points,t.strict===true,p+1);l.push({type:"bar",label:x.label,data:M.values,...M.labels.some(b=>b!==void 0)?{pointLabels:M.labels}:{}});if(re("xychart"))he("xychart","appendSeries",l[l.length-1],{line:p+1,unit:"normalized"});continue}if(x?.type==="line"){if(re("xychart"))Ge("xychart","line",g,{line:p+1,unit:"normalized"});const M=PN(x.points,t.strict===true,p+1);l.push({type:"line",label:x.label,data:M.values,...M.labels.some(b=>b!==void 0)?{pointLabels:M.labels}:{}});if(re("xychart"))he("xychart","appendSeries",l[l.length-1],{line:p+1,unit:"normalized"});continue}if(re("xychart"))Ge("xychart","unrecognized",g,{line:p+1,unit:"normalized"});throw new Error(`Unrecognized XYChart line: "${g}"`)}if(!a.range&&l.length>0){const p=l.flatMap(b=>b.data);const g=l.some(b=>b.type==="bar");let y=g?Math.min(0,...p):Math.min(...p);let w=g?Math.max(0,...p):Math.max(...p);const S=w-y||1;const x=g&&y===0;const M=g&&w===0&&y<0;if(!x)y=y-S*.1;if(!M)w=w+S*.1;if(y>0&&y<S*.5)y=0;a.range={min:y,max:w};if(re("xychart"))he("xychart","deriveYAxisRange",a.range)}if(!a.range){a.range={min:0,max:100};if(re("xychart"))he("xychart","setFallbackYAxisRange",a.range)}return{title:d,accessibility:r.title||r.descr?{...r.title!==void 0?{title:r.title}:{},...r.descr!==void 0?{description:r.descr}:{}}:void 0,horizontal:u,headerOrientation:f,xAxis:s,yAxis:a,series:l,config:Ih({}),theme:Fh({})}}function Oge(e,t={}){const n=Ih(t);return CM(e,n,Fh(t))}function CM(e,t,n){const i={...e,horizontal:e.headerOrientation?e.horizontal:t.chartOrientation==="horizontal",config:t,theme:n};if(re("xychart"))he("xychart","applyConfig",{horizontal:i.horizontal,config:t,theme:n});return i}var AN=/^([+-]?(?:\d+(?:\.\d+)?|\.\d+))(?:\s+([\s\S]+))?$/;function PN(e,t=false,n){const i=[];const r=[];for(const o of Wy(e)){const s=o.trim().match(AN);if(!s)throw new Error(`Invalid XYChart point: "${o.trim()}"`);const a=Number(s[1]);if(!Number.isFinite(a))throw new Error(`XYChart point must be finite: "${o.trim()}"`);const l=s[2]?.trim();if(t&&l!==void 0&&!l.startsWith('"')){throw new Error(`XYChart point labels must be double-quoted: "${o.trim()}"`)}const c=l===void 0?void 0:Sc(l);if(c===null)throw new Error(`Invalid XYChart point label: "${o.trim()}"`);i.push(a);if(re("xychart"))he("xychart","appendSeriesValue",{index:i.length-1,value:a},{line:n,unit:"normalized"});r.push(c);if(re("xychart"))he("xychart","appendSeriesPointLabel",{index:r.length-1,label:c},{line:n,unit:"normalized"})}if(i.length===0)throw new Error("XYChart series must contain at least one point");return{values:i,labels:r}}var EN=String.raw`[+-]?(?:\d+(?:\.\d+)?|\.\d+)`;var bM=new RegExp(`^(${EN})\\s*-->\\s*(${EN})$`);var Y5=/[^A-Za-z0-9&+=*.#_\s-]/;var q5=/[^A-Za-z&+=*.#_\s-]/;var X5=/(?<![A-Za-z])(?:xychart-beta|xychart|vertical|horizontal|[xy]-axis|title|line|bar)(?![A-Za-z0-9_])/i;function Lh(e,t,n,i,r){if(!r||e.startsWith('"'))return;const o=e.startsWith("'")?"'":(i==="xychart_unquoted_axis_title"?q5:Y5).exec(t)?.[0];if(o!==void 0)return r(i,`${n} ${JSON.stringify(t)} has ${JSON.stringify(o)} outside a double-quoted string, which pinned Mermaid rejects`);const s=X5.exec(t)?.[0];if(s!==void 0)r(i,`${n} ${JSON.stringify(t)} has the keyword ${JSON.stringify(s)} outside a double-quoted string, where pinned Mermaid ends the text: it rejects the line or reads another statement there`)}function wM(e,t,n,i,r){const o=t.trim();if(o.length===0)return false;const s=By(o);if(s&&n==="x"){const l=s.prefix;const c=l.length>0?Sc(l):void 0;if(c===null)return false;const d=K5(s.contents);if(d.length===0)return false;if(r)for(const u of Wy(s.contents))Lh(u,u,"XY chart category","xychart_unquoted_text",r);if(c!==void 0){Lh(l,c,`XY chart ${n}-axis title`,"xychart_unquoted_axis_title",r);e.title=c;if(re("xychart"))he("xychart","setAxisTitle",{axis:n,title:c},{line:i,unit:"normalized"})}e.categories=d;if(re("xychart"))he("xychart","setAxisCategories",{axis:n,categories:d},{line:i,unit:"normalized"});delete e.range;if(re("xychart"))he("xychart","deleteAxisRange",n,{line:i,unit:"normalized"});delete e.rangeAuthored;if(re("xychart"))he("xychart","deleteAxisRangeAuthored",n,{line:i,unit:"normalized"});e.authored=true;if(re("xychart"))he("xychart","setAxisAuthored",{axis:n,authored:true},{line:i,unit:"normalized"});return true}const a=IN(o);if(!a)return false;if(a.title!==void 0){Lh(o,a.title,`XY chart ${n}-axis title`,"xychart_unquoted_axis_title",r);e.title=a.title;if(re("xychart"))he("xychart","setAxisTitle",{axis:n,title:e.title},{line:i,unit:"normalized"})}if(a.range){e.range=a.range;if(re("xychart"))he("xychart","setAxisRange",{axis:n,range:e.range},{line:i,unit:"normalized"});e.rangeAuthored=true;if(re("xychart"))he("xychart","setAxisRangeAuthored",{axis:n,authored:true},{line:i,unit:"normalized"});delete e.categories;if(re("xychart"))he("xychart","deleteAxisCategories",n,{line:i,unit:"normalized"})}e.authored=true;if(re("xychart"))he("xychart","setAxisAuthored",{axis:n,authored:true},{line:i,unit:"normalized"});return true}function IN(e){const t=l=>({min:parseFloat(l[1]),max:parseFloat(l[2])});const n=e.match(bM);if(n)return{range:t(n),words:false};const i=FN(e);if(!i)return null;const r=i.rest.match(bM);if(r)return{title:i.value,range:t(r),words:false};if(i.rest.length===0)return{title:i.value,words:false};if(/^["']/.test(e))return null;let o=e;let s;const a=e.lastIndexOf("-->");if(a>=0){const l=e.slice(0,a).trimEnd();let c=l.length;while(c>0&&!/\s/.test(l[c-1]))c--;const d=`${l.slice(c)} --> ${e.slice(a+3).trim()}`.match(bM);if(!d)return null;o=l.slice(0,c).trim();s=t(d)}return/^[^"[\]]+$/.test(o)&&!o.includes("-->")?{title:o,...s?{range:s}:{},words:true}:null}var U5={subject:"XYChart text entity",example:'title "Say #quot;hi#quot;"'};function FN(e){const t=e.trim();if(t.length===0)return void 0;if(t.startsWith('"')||t.startsWith("'")){const i=J5(t);if(!i)return void 0;return{value:rn(i.value,U5),rest:t.slice(i.endIndex+1).trim()}}const n=t.match(/^([^\s]+)(?:\s+(.*))?$/);if(!n)return void 0;return{value:n[1],rest:(n[2]??"").trim()}}function Sc(e){const t=e.trim();if(!t)return null;if(!t.startsWith('"')&&!t.startsWith("'"))return t;const n=FN(t);return n&&n.rest.length===0?n.value:null}function V5(e){if(!e)return void 0;const t=e.trim();return t?Sc(t):void 0}function NN(e){const t=e.match(/^(bar|line)\b/i);if(!t)return null;const n=e.slice(t[0].length).trim();const i=By(n);if(!i)return null;const r=i.prefix.length>0?V5(i.prefix):void 0;if(r===null)return null;return{type:t[1].toLowerCase(),label:r,points:i.contents}}function By(e){let t=null;let n=false;let i=-1;let r=0;let o=-1;for(let s=0;s<e.length;s++){const a=e[s];if(t){if(n){n=false;continue}if(a==="\\"){n=true;continue}if(a===t)t=null;continue}if(a==='"'||a==="'"){t=a;continue}if(a==="["){if(r===0)i=s;r++;continue}if(a==="]"){if(r===0)return null;r--;if(r===0)o=s}}if(t||r!==0||i<0||o<i||e.slice(o+1).trim())return null;return{prefix:e.slice(0,i).trim(),contents:e.slice(i+1,o)}}function K5(e){const t=Wy(e);const n=[];for(const i of t){const r=Sc(i);if(r===null||r.length===0)throw Je({what:`Invalid XYChart category ${JSON.stringify(i)}`,expectedForm:"nonempty categories separated by commas",example:'x-axis ["A", "B"]'});n.push(r)}return n}function Wy(e){const t=[];let n="";let i=null;let r=false;for(let o=0;o<e.length;o++){const s=e[o];if(i){n+=s;if(r){r=false;continue}if(s==="\\"){r=true;continue}if(s===i)i=null;continue}if(s==='"'||s==="'"){i=s;n+=s;continue}if(s===","){RN(t,n);n="";continue}n+=s}if(i)throw new Error("Unclosed quoted XYChart value");RN(t,n);return t}function J5(e){const t=e[0];if(t!=='"'&&t!=="'")return null;let n="";let i=false;for(let r=1;r<e.length;r++){const o=e[r];if(i){if(o===t||o==="\\")n+=o;else n+=`\\${o}`;i=false;continue}if(o==="\\"){i=true;continue}if(o===t)return{value:n,endIndex:r};n+=o}return null}function Bge(e,t){if(!e.length)throw new Error("Empty XYChart text has no portable quoted spelling");const n=`"${dn(e,e.includes("%%")?'"\\%':'"\\')}"`;if(t==="quoted")return n;const i=/^[A-Za-z_][A-Za-z0-9_]*$/.test(e)&&(t!=="token"||!/\d/.test(e))&&!/^(?:title|bar|line|xychart|horizontal|vertical|accTitle|accDescr)/i.test(e);return i&&e.length>0?e:n}function RN(e,t){e.push(t.trim())}function Ih(e){const t=Sn(e,["config"])??e;const n=Sn(e,["config","xyChart"])??Sn(e,["xyChart"])??{};const i=cr(n,["chartOrientation"]);const r={width:$o(n,["width"]),height:$o(n,["height"]),useMaxWidth:as(n,["useMaxWidth"])??as(t,["useMaxWidth"]),useWidth:$o(n,["useWidth"])??$o(t,["useWidth"]),titleFontSize:$o(n,["titleFontSize"]),titlePadding:Ah(n,["titlePadding"]),chartOrientation:i==="horizontal"||i==="vertical"?i:void 0,plotReservedSpacePercent:$o(n,["plotReservedSpacePercent"]),showDataLabel:as(n,["showDataLabel"]),showDataLabelOutsideBar:as(n,["showDataLabelOutsideBar"]),showTitle:as(n,["showTitle"]),showLegend:as(n,["showLegend"]),legendFontSize:$o(n,["legendFontSize"]),legendPadding:Ah(n,["legendPadding"]),xAxis:vN(n,"xAxis"),yAxis:vN(n,"yAxis")};if(re("xychart"))he("xychart","resolveConfig",r);return r}function Fh(e){const t=Sn(e,["config"])??e;const n=Sn(e,["config","themeVariables","xyChart"])??Sn(e,["themeVariables","xyChart"])??{};const i={backgroundColor:cr(n,["backgroundColor"]),themeCss:cr(t,["themeCSS"]),titleColor:cr(n,["titleColor"]),xAxisLabelColor:cr(n,["xAxisLabelColor"]),xAxisTickColor:cr(n,["xAxisTickColor"]),xAxisLineColor:cr(n,["xAxisLineColor"]),xAxisTitleColor:cr(n,["xAxisTitleColor"]),yAxisLabelColor:cr(n,["yAxisLabelColor"]),yAxisTickColor:cr(n,["yAxisTickColor"]),yAxisLineColor:cr(n,["yAxisLineColor"]),yAxisTitleColor:cr(n,["yAxisTitleColor"]),legendTextColor:cr(n,["legendTextColor"]),dataLabelColor:cr(n,["dataLabelColor"]),plotColorPalette:Z5(n,["plotColorPalette"])};if(re("xychart"))he("xychart","resolveTheme",i);return i}function vN(e,t){const n=Sn(e,[t]);if(!n)return void 0;const i=as(n,["showLabel"]);const r=$o(n,["labelFontSize"]);const o=Ah(n,["labelPadding"]);const s=as(n,["showTitle"]);const a=$o(n,["titleFontSize"]);const l=Ah(n,["titlePadding"]);const c=as(n,["showTick"]);const d=Ah(n,["tickLength"]);const u=$o(n,["tickWidth"]);const f=as(n,["showAxisLine"]);const h=$o(n,["axisLineWidth"]);if(i===void 0&&r===void 0&&o===void 0&&s===void 0&&a===void 0&&l===void 0&&c===void 0&&d===void 0&&u===void 0&&f===void 0&&h===void 0){return void 0}return{showLabel:i,labelFontSize:r,labelPadding:o,showTitle:s,titleFontSize:a,titlePadding:l,showTick:c,tickLength:d,tickWidth:u,showAxisLine:f,axisLineWidth:h}}function Q5(e){if(!e)return void 0;const t=um(e).map(n=>n.trim()).filter(Boolean);return t.length>0?t:void 0}function Z5(e,t){const n=NE(e,t);if(n&&n.length>0){const i=n.filter(r=>typeof r==="string").map(r=>r.trim()).filter(Boolean);if(i.length>0)return i}return Q5(cr(e,t))}function as(e,t){const n=Mt(e,t);return typeof n==="boolean"?n:void 0}function $o(e,t){const n=Mt(e,t);return typeof n==="number"&&Number.isFinite(n)&&n>0?n:void 0}function Ah(e,t){const n=Mt(e,t);return typeof n==="number"&&Number.isFinite(n)&&n>=0?n:void 0}function cr(e,t){const n=Mt(e,t);return typeof n==="string"&&n.trim().length>0?n.trim():void 0}function Wge(e){const t=[];const n=(o,s)=>{const a=(f,h)=>t.push({index:s,syntax:f,what:h});const l=o.match(/^title\s+([\s\S]+)$/i);if(l)return Lh(l[1].trim(),l[1].trim(),"XY chart title","xychart_unquoted_text",a);const c=o.match(/^(bar|line)\s+([\s\S]+)$/i);if(c){const f=By(c[2].trim())?.prefix;if(f)Lh(f,f,`XY chart ${c[1].toLowerCase()} label`,"xychart_unquoted_text",a);return}const d=o.match(/^([xy])-axis\s+([\s\S]+)$/i);if(!d)return;const u=d[1].toLowerCase();try{wM({},d[2],u,s+1,a)}catch(f){if(!(f instanceof Ls))throw f}};const i=[];const r=Oy([...e],false,i);for(let o=1;o<r.length;o++){const s=vt(r,o);if(s===void 0)break;if(s===null){n(r[o],i[o]);continue}o=s.endIndex;if(s.suffixLine){for(const a of Oy([s.suffixLine],false))n(a,i[o])}}return t}function PM(e){return Ir(e,{escapes:false,restOfLine:/(?<!\w)acc(?:Title|Descr)\s*:/iy,block:$N})}function Oy(e,t,n){const i=[];let r=false;const o=PM(e);for(let s=0;s<e.length;s++){const a=s;let l=e[s].trim();if(!l)continue;if(l.startsWith("%%"))continue;if(r){i.push(l);n?.push(a);if(l.includes("}"))r=false;continue}const c=/^acc(?:Title|Descr)\b/i.test(l);if(!c){const u=o[s];if(u>s){l=Ll(e,s,u).trim();s=u}}const d=c?kM(l,t):e6(l,t);for(const u of d){i.push(u);n?.push(a);const f=u.match(/^accDescr\s*:?\s*\{(.*)$/i);if(f&&!f[1].includes("}"))r=true}}return i}function e6(e,t){const n=Kr(e,$N);if(n<0)return kM(e,t);const i=e.slice(0,n).trimEnd();const r=kM(i,t);const o=r.length-1;if(o>=0&&t6.test(r[o]))r[o]=e.slice(i.length-r[o].length).trim();return r}var t6=/^acc(?:Title|Descr)\s*:/i;var $N=/(?<!\w)accDescr\s*\{/iy;var TN=/(?:title|[xy]-axis|bar|line)(?!\w)|acc(?:Title\s*:|Descr\s*[:{])/iy;function SM(e,t,n){let i=0;if(n.length>0){let o=MM(t.slice(0,n[0]).trim());for(let s=0;s<n.length;s++){const a=MM(t.slice(n[s],n[s+1]).trim());if(o&&a&&(o!=="title"||a==="data")){const l=t.slice(i,n[s]).trim();if(l)e.push(l);i=n[s];o=a}else if(o!=="title"){o=a}}}const r=t.slice(i).trim();if(r)e.push(r)}function MM(e){const t=e.match(/^(title|x-axis|y-axis)\s+([\s\S]+)$/i);if(!t){const s=NN(e);return s&&Wy(s.points).every(a=>AN.test(a.trim()))?"data":void 0}const n=t[2].trim();const i=n.startsWith('"')||n.startsWith("'");if(/^title$/i.test(t[1]))return Sc(n)===null?void 0:i?"data":"title";const r=/^x/i.test(t[1])?By(n):null;if(r)return r.prefix&&Sc(r.prefix)===null?void 0:"data";const o=IN(n);return!o?void 0:o.range||i?"data":o.words?"title":"text"}function kM(e,t){const n=[];let i="";let r=null;let o=0;let s=0;let a=false;let l=[];let c=false;let d=true;for(let u=0;u<e.length;u++){const f=e[u];if(r){i+=f;if(a){a=false;continue}if(f==="\\"){a=true;continue}if(f===r)r=null;continue}if(f==='"'||f==="'"){r=f;i+=f;continue}if(f==="["){o++;i+=f;continue}if(f==="]"){o--;i+=f;continue}if(f==="{"){s++;i+=f;continue}if(f==="}"){s--;i+=f;continue}if(f===";"&&o===0&&s===0){SM(n,i,l);i="";l=[];c=false;d=true;continue}if(d&&o===0&&s===0&&/[abltxy]/i.test(f)&&!/\w/.test(e[u-1]??" ")){TN.lastIndex=u;const h=TN.exec(e);if(h&&/^acc/i.test(h[0])){const m=[];SM(m,i,l);if(m.length===0||MM(m[m.length-1])!==void 0){n.push(...m);i="";l=[];if(!h[0].endsWith("{")){n.push(e.slice(u).trim());return n}const p=e.indexOf("}",u+h[0].length);if(p>=0){i+=e.slice(u,p+1);u=p;c=true;d=false;continue}}d=false}else if(h&&c)l.push(i.length)}if(!c&&!/\s/.test(f))c=true;i+=f}if(t&&(r||o!==0||s!==0)){throw new Error(`Unclosed XYChart delimiter in line: "${e}"`)}SM(n,i,l);return n}function ut(e){return t=>e(t)}function ft(e){return _v(e,t=>e(t))}function ht(e,t={}){return{positioned:e,...t}}function jge(e,t){const n=Object.freeze({...e,...t,contractVersion:2,capabilityEvidence:Object.freeze([])});Nv(n);return n}var Nh={width:30,height:20,labelPadding:8};var Mc=240;function wc(e,t,n,i,r,o,s=0,a=Be(e,{fontSize:r,fontWeight:o,letterSpacing:s})){const l=a;const c=i==="middle"?t-l.width/2:i==="start"?t:t-l.width;return{text:a.text,block:a,x:t,y:n,anchor:i,fontSize:r,fontWeight:o,letterSpacing:s,bounds:{x:c,y:n-l.height/2,width:l.width,height:l.height},metrics:l}}function EM(e,t){const n=Math.min(e.x,t.x);const i=Math.min(e.y,t.y);const r=Math.max(e.x+e.width,t.x+t.width);const o=Math.max(e.y+e.height,t.y+t.height);return{x:n,y:i,width:r-n,height:o-i}}function Gy(e,t,n){return{x:e.x+t,y:e.y+n,width:e.width,height:e.height}}function zy(e,t,n){return{...e,x:e.x+t,y:e.y+n,bounds:Gy(e.bounds,t,n)}}function _N(e,t,n,i,r){const o=n?.textTransform??t.nodeTextTransform;const s=n?.fontSize??t.nodeLabelFontSize;const a=n?.fontWeight??t.nodeLabelFontWeight;const l=n?.letterSpacing??t.nodeLetterSpacing;const c=n?.paddingX??t.nodePaddingX;const d=n?.paddingY??t.nodePaddingY;const u=Be(qe(e.label,e.labelContent),{transform:o,fontSize:s,fontWeight:a,letterSpacing:l,...e.wrap?{maxWidth:Mc}:{}});const f=u.text;const h=u;const m=Math.max(h.width+c*2,i);const p=e.type==="participant"?Math.max(r,Math.ceil(h.height+d*2)):r;return{fontSize:s,fontWeight:a,letterSpacing:l,paddingX:c,paddingY:d,displayLabel:f,block:u,...e.links?{menuBlock:Be("\u22EF",{display:"literal",fontSize:10,fontWeight:400})}:{},labelMetrics:h,width:m,height:p}}function RM(e,t,n,i){if(e.type==="participant"){const u=wc(t.displayLabel,n,i+t.height/2,"middle",t.fontSize,t.fontWeight,t.letterSpacing,t.block);const f={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:f,labelPosition:u}}const r=e.type==="actor"?i+t.height:Math.max(i+t.height,i+26);const o=Math.max(14,t.labelMetrics.lineHeight/2+5.5);const s=r+o+(t.labelMetrics.lines.length-1)/2*t.labelMetrics.lineHeight;const a=wc(t.displayLabel,n,s,"middle",t.fontSize,t.fontWeight,t.letterSpacing,t.block);const l={x:n-t.width/2,y:i,width:t.width,height:r-i};const c=EM(l,a.bounds);const d={x:c.x,y:c.y,width:c.width,height:c.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:d,labelPosition:a}}function n6(e,t,n){e.x+=t;e.y+=n;e.bounds=Gy(e.bounds,t,n);e.labelPosition=zy(e.labelPosition,t,n)}function DN(e,t,n){const i=LT(e);const r=Object.freeze({value:i,prepared:Rt(AT(e))});const o=Be(r.prepared,{transform:t.edgeTextTransform,fontSize:t.edgeLabelFontSize,fontWeight:t.edgeLabelFontWeight,letterSpacing:t.edgeLetterSpacing,...e.wrap?{maxWidth:Mc}:{}});const s=o.text;const a=t.edgeLabelFontSize*hi;const l=i?o:{width:0,height:0,lines:[],lineHeight:a};const c=Math.max(e.startHead!=="none"?bn.width:0,e.centralStart?5:0);const d=Math.max(e.endHead!=="none"?bn.width:0,e.centralEnd?5:0);const u=Math.max(t.lineWidth/2,e.startHead!=="none"||e.endHead!=="none"?bn.height/2:0,e.centralStart||e.centralEnd?4.75:0);const f=Math.max(16,c+d+8);const h=l.width+f;const m=Nh.width+(l.width>0?Nh.labelPadding+l.width:0);const p=m+Math.max(12,n/2+8);const g=e.from===e.to?0:Math.ceil(Math.max(0,l.height-a));return{label:i,labelContent:r,displayLabel:s,block:o,labelMetrics:l,startPad:c,endPad:d,markerHalfHeight:u,requiredSpanWidth:h,selfRightExtent:m,requiredSelfNeighborGap:p,extraAboveHeight:g}}function ON(e,t,n,i,r,o){const s=e.from===e.to;if(s){const S=Nh.width;const x=Nh.height;const M=[{x:i,y:o},{x:i+S,y:o},{x:i+S,y:o+x},{x:r,y:o+x}];const b=i+S+Nh.labelPadding;const C=o+Math.max(x,t.labelMetrics.height)/2;const P=wc(t.displayLabel,b,C,"start",n.edgeLabelFontSize,n.edgeLabelFontWeight,n.edgeLetterSpacing,t.block);const E={x:i-t.startPad,y:o-t.markerHalfHeight,width:S+t.startPad+n.lineWidth/2,height:x+t.markerHalfHeight*2};const k=t.label?EM(E,P.bounds):E;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??false,centralEnd:e.centralEnd??false,x1:i,x2:r,y:o,isSelf:s,points:M,labelPosition:P,bounds:k}}const a=[{x:i,y:o},{x:r,y:o}];const l=(i+r)/2;const c=Math.max(2.85,n.lineWidth/2+2);const d=Math.max(10,t.labelMetrics.height/2+c);const u=o-d;const f=wc(t.displayLabel,l,u,"middle",n.edgeLabelFontSize,n.edgeLabelFontWeight,n.edgeLetterSpacing,t.block);const h=i<=r?t.startPad:t.endPad;const m=i<=r?t.endPad:t.startPad;const p=Math.min(i,r)-h;const g=Math.max(i,r)+m;const y={x:p,y:o-t.markerHalfHeight,width:g-p,height:t.markerHalfHeight*2};const w=t.label?EM(y,f.bounds):y;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??false,centralEnd:e.centralEnd??false,x1:i,x2:r,y:o,isSelf:s,points:a,labelPosition:f,bounds:w}}function i6(e,t,n){e.x1+=t;e.x2+=t;e.y+=n;e.points=e.points.map(i=>({x:i.x+t,y:i.y+n}));e.labelPosition=zy(e.labelPosition,t,n);e.bounds=Gy(e.bounds,t,n)}function BN(e){return e.blocks.map((t,n)=>{const i=MT(t);if(i)return i;const r=[];for(let s=0;s<e.notes.length;s++){const a=e.notes[s];if(a.afterIndex>=t.startIndex&&a.afterIndex<=t.endIndex){r.push(s)}}const o=[];for(let s=0;s<n;s++){const a=e.blocks[s];if(a.startIndex>=t.startIndex&&a.endIndex<=t.endIndex){const l=e.blocks.some((c,d)=>d>s&&d<n&&a.startIndex>=c.startIndex&&a.endIndex<=c.endIndex&&c.startIndex>=t.startIndex&&c.endIndex<=t.endIndex);if(!l)o.push(s)}}return{endMessageExclusive:Math.min(t.endIndex+1,e.messages.length),dividerNoteIndices:t.dividers.map(()=>-1),endNoteExclusive:r.length>0?r.at(-1)+1:e.notes.filter(s=>s.afterIndex<=t.endIndex).length,noteIndices:r,childBlockIndices:o,childSectionIndices:o.map(s=>t.dividers.filter(a=>e.blocks[s].startIndex>=a.index).length)}})}function WN(e,t,n,i,r,o){const s=e.type==="rect"?"":e.label?Mu([`${e.type} [`,Rt(qe(e.label,e.labelContent)),"]"]):e.type;const a=Be(s,{transform:t.groupTextTransform,fontSize:t.groupHeaderFontSize,fontWeight:t.groupHeaderFontWeight,letterSpacing:t.groupLetterSpacing,fontFamily:t.groupFont,...e.wrap?{maxWidth:Mc}:{}});const l=a.text;const c=t.groupHeaderFontSize*hi;const d=l?a:{width:0,height:0,lines:[],lineHeight:c};const u=Math.ceil(Math.max(0,(d.lines.length-1)*d.lineHeight));const f=Math.max(t.groupPaddingX*2,t.groupLabelPaddingX*2);const h=e.type==="rect"?0:d.width+f;const m=e.type==="rect"?0:Math.max(18,t.groupHeaderFontSize+t.groupPaddingY)+u;const p=n+u;const g=i+u;const y=e.type==="rect"?t.groupPaddingY:m+t.groupPaddingY;const w=e.dividers.map(S=>{const x=Be(S.label?Mu(["[",Rt(qe(S.label,S.labelContent)),"]"]):"",{transform:t.edgeTextTransform,fontSize:t.edgeLabelFontSize,fontWeight:t.edgeLabelFontWeight,letterSpacing:t.edgeLetterSpacing,...S.wrap?{maxWidth:Mc}:{}});const M=x.text;const b=S.label?x:{width:0,height:0,lines:[],lineHeight:o};const C=Math.max(14,Math.ceil(b.lineHeight/2+6));const P=Math.max(0,C-14);const E=Math.ceil(Math.max(0,(b.lines.length-1)*b.lineHeight));return{index:S.index,label:S.label,displayLabel:M,block:x,metrics:b,firstLineOffset:C,extraFontOffset:P,extraLinesHeight:E,requiredExtraBefore:r+E+P,noteContentOffset:Math.ceil(Math.max(28+E+P,C+(b.lines.length-1)/2*b.lineHeight+b.height/2+t.groupPaddingY))}});return{headerText:l,block:a,headerMetrics:d,tabWidth:h,tabHeight:m,extraHeaderLinesHeight:u,blockPadTop:p,blockHeaderExtra:g,enclosingHeaderStep:y,contentTopPadding:e.type==="rect"?t.groupPaddingY:Math.max(p,m+t.groupPaddingY),dividers:w}}function Hy(e,t,n,i){const r=t.dividerNoteIndices[i]??-1;const o=t.dividerNoteIndices[i+1]??t.endNoteExclusive;return r>=0&&r<o&&n.notes[r].afterIndex<e.dividers[i].index?r:void 0}function vM(e,t,n,i,r,o,s,a,l,c,d,u,f){const h=e.startIndex<n.endMessageExclusive?s[e.startIndex]:void 0;const m=e.startIndex<n.endMessageExclusive?s[n.endMessageExclusive-1]:void 0;const p=new Set;for(let E=e.startIndex;E<n.endMessageExclusive;E++){const k=i.messages[E];if(k){p.add(r.get(k.from)??0);p.add(r.get(k.to)??0)}}for(const E of n.noteIndices){const k=i.notes[E];if(k){for(const v of k.actorIds){const T=r.get(v);if(T!==void 0)p.add(T)}}}if(p.size===0){for(let E=0;E<i.actors.length;E++)p.add(E)}let g=Number.POSITIVE_INFINITY;let y=Number.NEGATIVE_INFINITY;for(const E of p){const k=o[E];if(!k)continue;const v=k.bounds;g=Math.min(g,v.x-c.groupPaddingX);y=Math.max(y,v.x+v.width+c.groupPaddingX)}for(let E=e.startIndex;E<n.endMessageExclusive;E++){const k=s[E];if(!k)continue;g=Math.min(g,k.bounds.x-c.groupPaddingX);y=Math.max(y,k.bounds.x+k.bounds.width+c.groupPaddingX)}for(const E of n.noteIndices){const k=a[E];if(!k)continue;g=Math.min(g,k.x-c.groupPaddingX);y=Math.max(y,k.x+k.width+c.groupPaddingX)}for(const E of n.childBlockIndices){const k=l[E];if(!k)continue;g=Math.min(g,k.x-c.groupPaddingX);y=Math.max(y,k.x+k.width+c.groupPaddingX)}if(e.type!=="rect"){y=Math.max(y,g+t.tabWidth+c.groupPaddingX)}for(const E of t.dividers){if(E.label){y=Math.max(y,g+8+E.metrics.width+c.groupPaddingX)}}const w=h&&!h.isSelf&&h.labelPosition.text.includes("\n")?Math.ceil(Math.max(0,h.labelPosition.y-h.labelPosition.bounds.y-c.edgeLabelFontSize*hi/2-1e-6)):0;const S=n.noteIndices.length>0?t.contentTopPadding:t.blockPadTop;let x=f?.top??(h?h.y-(t.blockPadTop+w):u-S);let M=(m?.y??u)+c.groupPaddingY+12;for(let E=e.startIndex;E<n.endMessageExclusive;E++){const k=s[E];if(!k)continue;x=Math.min(x,k.bounds.y-Math.max(t.tabHeight,c.groupPaddingY));const v=k.isSelf?c.groupPaddingY+4:c.groupPaddingY;M=Math.max(M,k.bounds.y+k.bounds.height+v)}for(const E of p){const k=i.actors[E];const v=o[E];if(!v||k?.createMessageIndex===void 0||!s[k.createMessageIndex])continue;if(k.createMessageIndex>=e.startIndex&&k.createMessageIndex<n.endMessageExclusive){const T=t.contentTopPadding;x=Math.min(x,v.bounds.y-T);M=Math.max(M,v.bounds.y+v.bounds.height+c.groupPaddingY)}}for(const E of n.noteIndices){const k=a[E];if(!k)continue;const v=t.contentTopPadding;x=Math.min(x,k.y-v);M=Math.max(M,k.y+k.height+c.groupPaddingY)}for(const E of n.childBlockIndices){const k=l[E];if(!k)continue;x=Math.min(x,k.y-t.enclosingHeaderStep);M=Math.max(M,k.y+k.height+c.groupPaddingY)}const b=t.dividers.map((E,k)=>{const v=Hy(e,n,i,k);const T=v===void 0?void 0:a[v];const A=E.index<n.endMessageExclusive?s[E.index]:void 0;if(e.type==="par_over"){if(!E.label)return{y:x+t.tabHeight,label:""};let z=T??A?.bounds;for(const[j,W]of n.childBlockIndices.entries()){const O=l[W];if(O&&n.childSectionIndices[j]===k+1&&i.blocks[W].startIndex===E.index&&(!z||O.y<z.y))z=O}const _=z?.x??g+8;const H=z?z.y-E.metrics.height-8:x+t.tabHeight+8+k*(E.metrics.height+8);const D=wc(E.displayLabel,_,H+E.metrics.height/2,"start",c.edgeLabelFontSize,c.edgeLabelFontWeight,c.edgeLetterSpacing,E.block);y=Math.max(y,D.bounds.x+D.bounds.width+c.groupPaddingX);M=Math.max(M,D.bounds.y+D.bounds.height+c.groupPaddingY);return{y:H,label:E.label,labelPosition:D}}const R=A?.y??u;let I=28+E.extraLinesHeight+E.extraFontOffset;if(E.label&&A?.label){const z=g+8;const _=z+E.metrics.width;const H=A.labelPosition.bounds;const D=H.x;const j=H.x+H.width;const W=8;if(_+W>D&&z-W<j){const O=Math.max(0,Math.ceil(R-10-(H.y+H.height/2)));I=Math.max(36+E.extraLinesHeight+E.extraFontOffset+O,Math.ceil(24+d+E.extraLinesHeight+E.extraFontOffset+O))}}const L=f?.dividerY[k];let $=L??(T?T.y-E.noteContentOffset:R-I);for(const[z,_]of n.childBlockIndices.entries()){const H=l[_];const D=i.blocks[_];if(L===void 0&&H&&D?.startIndex===E.index&&n.childSectionIndices[z]===k+1){const j=E.noteContentOffset;$=Math.min($,H.y-j)}}if(!E.label){return{y:$,label:E.label}}const B=$+E.firstLineOffset+(E.metrics.lines.length-1)/2*E.metrics.lineHeight;const F=wc(E.displayLabel,g+8,B,"start",c.edgeLabelFontSize,c.edgeLabelFontWeight,c.edgeLetterSpacing,E.block);M=Math.max(M,F.bounds.y+F.bounds.height+c.groupPaddingY);return{y:$,label:E.label,labelPosition:{...F,text:E.displayLabel}}});const C=e.type==="rect"?void 0:(()=>{const E=x+t.tabHeight/2;const k=wc(t.headerText,g+c.groupLabelPaddingX,E,"start",c.groupHeaderFontSize,c.groupHeaderFontWeight,c.groupLetterSpacing,t.block);return{x:g,y:x,width:t.tabWidth,height:t.tabHeight,label:{...k,text:t.headerText}}})();const P={x:g,y:x,width:y-g,height:M-x};return{type:e.type,label:e.label,...e.color?{color:e.color}:{},x:P.x,y:P.y,width:P.width,height:P.height,dividers:b,...C?{header:C}:{},bounds:P}}function r6(e,t,n){e.x+=t;e.y+=n;e.bounds=Gy(e.bounds,t,n);if(e.header){e.header={...e.header,x:e.header.x+t,y:e.header.y+n,label:zy(e.header.label,t,n)}}for(const i of e.dividers){i.y+=n;if(i.labelPosition){i.labelPosition=zy(i.labelPosition,t,n)}}}function TM(e,t,n){for(const i of e.actors)n6(i,t,n);for(const i of e.messages)i6(i,t,n);for(const i of e.blocks)r6(i,t,n);for(const i of e.notes){i.x+=t;i.y+=n}for(const i of e.boxes){i.x+=t;i.y+=n;if(i.labelY!==void 0)i.labelY+=n}for(const i of e.activations){i.x+=t;i.topY+=n;i.bottomY+=n}for(const i of e.lifelines){i.x+=t;i.topY+=n;i.bottomY+=n}for(const i of e.destructions){i.x+=t;i.y+=n}}var Gn={padding:30,actorGap:140,actorHeight:40,actorPadX:16,headerGap:26,messageRowHeight:40,selfMessageHeight:30,activationWidth:10,blockPadX:10,blockPadTop:40,blockPadBottom:8,blockHeaderExtra:28,dividerExtra:24,noteWidth:60,notePadX:12,notePadY:6,noteGap:10,boxPadX:8,boxTitleSpace:22,boxPadBottom:8};var kc={nodeLabelFontSize:nr.nodeLabel,edgeLabelFontSize:nr.edgeLabel,groupHeaderFontSize:nr.edgeLabel,nodeLabelFontWeight:Fr.nodeLabel,edgeLabelFontWeight:Fr.edgeLabel,groupHeaderFontWeight:Fr.groupHeader,nodePaddingX:Gn.actorPadX,nodePaddingY:Gn.notePadY,nodeCornerRadius:4,nodeLineWidth:et.outerBox,edgeLineWidth:et.connector,groupCornerRadius:0,groupPaddingX:Gn.blockPadX,groupPaddingY:8,groupLabelPaddingX:6,groupLineWidth:et.outerBox};function jy(e,t={},n={},i){const r=Ue(t,kc,i);const o=n.diagramMarginX??Gn.padding;const s=n.diagramMarginY??Gn.padding;const a=n.width??80;const l=n.noteMargin??Gn.noteGap;const c=n.activationWidth??Gn.activationWidth;const d=e.actors.map(ce=>It(i,"actor",{category:ce.id},{includeFallback:false}));const u=Math.max(n.height??Gn.actorHeight,...d.map(ce=>am("Mg",ce?.fontSize??r.nodeLabelFontSize,ce?.fontWeight??r.nodeLabelFontWeight).height+(ce?.paddingY??r.nodePaddingY)*2));const f=am("Mg",kc.edgeLabelFontSize,kc.edgeLabelFontWeight).height;const h=am("Mg",r.edgeLabelFontSize,r.edgeLabelFontWeight).height;const m=n.messageMargin??Gn.messageRowHeight;const p=Math.max(m,m+h-f);const g=Math.max(Gn.selfMessageHeight,p-10);const y=Math.max(Gn.blockPadTop,Gn.blockPadTop+(r.groupHeaderFontSize-kc.groupHeaderFontSize)+(r.groupPaddingY-kc.groupPaddingY)*2);const w=Math.max(Gn.blockHeaderExtra,y+r.groupPaddingY+20-p);if(e.actors.length===0){return zN({width:0,height:0,accessibilityTitle:e.accessibilityTitle,accessibilityDescription:e.accessibilityDescription,actors:[],lifelines:[],messages:[],activations:[],blocks:[],notes:[],boxes:[],destructions:[]},e.title===void 0?void 0:qe(e.title,e.titleContent),r,o,s)}const S=e.actors.map((ce,Ae)=>_N(ce.wrap===void 0&&n.wrap!==void 0?{...ce,wrap:n.wrap}:ce,r,d[Ae],a,u));const x=S.map(ce=>ce.width);const M=new Map;for(let ce=0;ce<e.actors.length;ce++)M.set(e.actors[ce].id,ce);const b=e.messages.map(ce=>DN(ce.wrap===void 0&&n.wrap!==void 0?{...ce,wrap:n.wrap}:ce,r,c));const C=Array.from({length:Math.max(0,e.actors.length-1)},()=>0);for(let ce=0;ce<e.messages.length;ce++){const Ae=e.messages[ce];const Pe=b[ce];const He=M.get(Ae.from);const je=M.get(Ae.to);if(He===void 0||je===void 0)continue;if(He===je){if(He<e.actors.length-1){C[He]=Math.max(C[He],Pe.requiredSelfNeighborGap)}continue}const Ke=Math.min(He,je);const ze=Math.max(He,je);const Ze=ze-Ke;const tt=e.actors[je].createMessageIndex===ce&&e.actors[je].type==="participant"?x[je]/2:0;const nt=(Pe.requiredSpanWidth+tt)/Ze;for(let it=Ke;it<ze;it++){C[it]=Math.max(C[it],nt)}}const P=[];let E=o+x[0]/2;for(let ce=0;ce<e.actors.length;ce++){if(ce>0){const Ae=(x[ce-1]+x[ce])/2;const Pe=n.actorMargin!==void 0?Ae+n.actorMargin:Math.max(Gn.actorGap,Ae+40);E+=Math.max(Pe,C[ce-1]??0)}P.push(E)}const k=(e.boxes??[]).flatMap((ce,Ae)=>{const Pe=e.actors.flatMap((je,Ke)=>je.box===Ae?[Ke]:[]);const He=ce.label?Be(qe(ce.label,ce.labelContent),{transform:r.groupTextTransform,fontSize:r.groupHeaderFontSize,fontWeight:r.groupHeaderFontWeight,letterSpacing:r.groupLetterSpacing,fontFamily:r.groupFont,...ce.wrap??n.wrap?{maxWidth:Mc}:{}}):void 0;return Pe.length>0?[{box:ce,memberIdxs:Pe,block:He}]:[]});const v=Math.max(Gn.boxTitleSpace,...k.map(ce=>(ce.block?.height??0)+8));const T=s+(k.length>0?v+6:0);const A=e.actors.map((ce,Ae)=>RM(ce,S[Ae],P[Ae],T));const R=e.actors.flatMap((ce,Ae)=>{if(ce.createMessageIndex!==void 0&&ce.createMessageIndex<e.messages.length)return[];const Pe=A[Ae].bounds;return[Pe.y+Pe.height]});const I=R.length>0?Math.max(...R):T+u;let L=I+Gn.headerGap;const $=[];const B=BN(e);const F=e.blocks.map(ce=>WN({...ce,wrap:ce.wrap??n.wrap,dividers:ce.dividers.map(Ae=>({...Ae,wrap:Ae.wrap??n.wrap}))},r,y,w,Gn.dividerExtra,h));const z=wT(e);const _=new Map;const H=new Map;const D=new Map;const j=new Map;const W=new Map;for(let ce=0;ce<e.blocks.length;ce++){const Ae=e.blocks[ce];const Pe=H.get(Ae.startIndex)??[];Pe.push(ce);H.set(Ae.startIndex,Pe);const He=B[ce];const je=He.noteIndices[0];if(je!==void 0){const Ke=D.get(je)??[];Ke.push(ce);D.set(je,Ke)}for(const Ke of He.childBlockIndices)j.set(Ke,ce)}const O=new Set;const N=new Set;if(z){const ce=new Map(z.filter(Ae=>Ae.kind==="open").map(Ae=>[Ae.blockIndex,Ae.noteIndex]));for(let Ae=0;Ae<e.blocks.length;Ae++){const Pe=e.blocks[Ae];const He=B[Ae];const je=new Set(He.childSectionIndices);let Ke=Pe.startIndex;let ze=ce.get(Ae);for(let Ze=0;Ze<=Pe.dividers.length;Ze++){const tt=Pe.dividers[Ze]?.index??He.endMessageExclusive;const nt=He.dividerNoteIndices[Ze]??He.endNoteExclusive;if(Ke===tt&&ze===nt&&!je.has(Ze))N.add(Ae);Ke=tt;ze=nt}if(He.childBlockIndices.some(Ze=>e.blocks[Ze].startIndex===B[Ze].endMessageExclusive&&B[Ze].noteIndices.length===0))N.add(Ae)}for(let Ae=0;Ae<e.blocks.length;Ae++){const Pe=j.get(Ae);if(N.has(Ae)&&Pe!==void 0)N.add(Pe)}}const G=ce=>(H.get(ce)??[]).filter(Ae=>!O.has(Ae)&&B[Ae].endMessageExclusive>ce);const Y=ce=>ce.length===0?0:F[ce[0]].blockHeaderExtra+ce.slice(1).reduce((Ae,Pe)=>Ae+F[Pe].enclosingHeaderStep,0);for(let ce=0;ce<e.blocks.length;ce++){if(N.has(ce)||e.blocks[ce].type==="par_over")continue;const Ae=F[ce];const Pe=B[ce];for(const[He,je]of Ae.dividers.entries()){const Ke=Hy(e.blocks[ce],Pe,e,He);if(Ke!==void 0){W.set(Ke,Math.max(W.get(Ke)??0,je.noteContentOffset));continue}if(je.index>=Pe.endMessageExclusive)continue;let ze=je.requiredExtraBefore;for(const tt of Pe.childBlockIndices){if(e.blocks[tt]?.startIndex===je.index){ze+=F[tt].blockHeaderExtra}}const Ze=_.get(je.index)??0;_.set(je.index,Math.max(Ze,ze))}}const q=new Map;const V=new Map;const ne=new Map;for(let ce=0;ce<e.actors.length;ce++){const Ae=e.actors[ce];if(Ae.createMessageIndex!==void 0&&Ae.createMessageIndex<e.messages.length){const Pe=q.get(Ae.createMessageIndex)??[];Pe.push(ce);q.set(Ae.createMessageIndex,Pe)}if(Ae.destroyMessageIndex!==void 0&&Ae.destroyMessageIndex<e.messages.length){const Pe=V.get(Ae.destroyMessageIndex)??[];Pe.push(Ae.id);V.set(Ae.destroyMessageIndex,Pe)}}const X=new Map;for(let ce=0;ce<e.notes.length;ce++){const Ae=e.notes[ce];const Pe=X.get(Ae.afterIndex)??[];Pe.push({note:Ae,index:ce});X.set(Ae.afterIndex,Pe)}const U=new Array(e.notes.length);const K=new Map;const Z=[];const Q=4;const se=new Map;for(const ce of e.activationEvents??[]){const Ae=se.get(ce.messageIndex)??[];Ae.push(ce);se.set(ce.messageIndex,Ae)}const te=(ce,Ae)=>{const Pe=K.get(ce)??[];Pe.push({startY:Ae,depth:Pe.length});K.set(ce,Pe)};const ee=(ce,Ae)=>{const Pe=K.get(ce);if(!Pe||Pe.length===0)return;const{startY:He,depth:je}=Pe.pop();const Ke=M.get(ce);if(Ke===void 0||Ae<=He)return;Z.push({actorId:ce,x:P[Ke]-c/2+je*Q,topY:He,bottomY:Ae,width:c})};const ae=(ce,Ae)=>{for(const Pe of se.get(ce)??[]){if(Pe.kind==="activate")te(Pe.actorId,Ae);else ee(Pe.actorId,Ae)}};const ie=(ce,Ae)=>{const Pe=Be(qe(ce.text,ce.textContent),{transform:r.nodeTextTransform,fontSize:r.nodeLabelFontSize,fontWeight:r.nodeLabelFontWeight,letterSpacing:r.nodeLetterSpacing,...ce.wrap??n.wrap?{maxWidth:Mc}:{}});const He=Pe;const je=Math.max(Gn.noteWidth,He.width+r.nodePaddingX*2);const Ke=He.height+r.nodePaddingY*2;const ze=M.get(ce.actorIds[0]??"")??0;let Ze;if(ce.position==="left"){Ze=P[ze]-x[ze]/2-je-l}else if(ce.position==="right"){Ze=P[ze]+x[ze]/2+l}else if(ce.actorIds.length>1){const tt=M.get(ce.actorIds[ce.actorIds.length-1]??"")??ze;Ze=(P[ze]+P[tt])/2-je/2}else{Ze=P[ze]-je/2}return{text:ce.text,block:Pe,x:Ze,y:Ae,width:je,height:Ke,position:ce.position,actors:ce.actorIds}};const oe=new Array(e.blocks.length);const ue=[];let ye=Number.NEGATIVE_INFINITY;let Se=I;let Te=Number.NEGATIVE_INFINITY;let Ie=0;let Ee=0;let ve=0;let $e=0;const De=new Map;const fe=(ce,Ae,Pe)=>{let He=0;const je=[];for(const[Ke,ze]of De){const Ze=e.blocks[Ke];for(let tt=Ze.startIndex;tt<ze.messageEnd;tt++)if($[tt])je.push($[tt].bounds);for(const tt of B[Ke].noteIndices)if(tt<ze.noteEnd&&U[tt])je.push(U[tt]);for(const tt of ze.priorChildren)if(oe[tt])je.push(oe[tt]);for(const[tt,nt]of Ze.dividers.entries()){const it=F[Ke].dividers[tt];if(!nt.label)continue;const $t=Hy(Ze,B[Ke],e,tt);const yn=$t!==void 0&&$t<ze.noteEnd?U[$t]:$t===void 0&&nt.index<ze.messageEnd?$[nt.index]?.bounds:void 0;if(yn)je.push({x:yn.x,y:yn.y-it.metrics.height-8,width:it.metrics.width,height:it.metrics.height});if($t===void 0&&Ae===nt.index||$t!==void 0&&Pe===$t){const St=it.metrics.height+8;ce={x:ce.x,y:ce.y-St,width:Math.max(ce.width,it.metrics.width),height:ce.height+St}}}}for(let Ke=0;Ke<=je.length;Ke++){const ze=je.find(Ze=>ce.x<Ze.x+Ze.width+8&&ce.x+ce.width+8>Ze.x&&ce.y+He<Ze.y+Ze.height+8&&ce.y+ce.height+He+8>Ze.y);if(!ze)break;He=ze.y+ze.height+8-ce.y}return He};const me=ce=>{const Ae=[];for(let Pe=ce;Pe!==void 0&&!O.has(Pe);Pe=j.get(Pe))Ae.push(Pe);for(let Pe=Ae.length-1;Pe>=0;Pe--){const He=Ae[Pe];const je=Math.max(Se,ye,Te)+8;ue[He]={top:je,dividerY:[]};O.add(He);Se=Te=je+F[He].enclosingHeaderStep}};const de=ce=>{const Ae=e.blocks[ce];const Pe=B[ce];const He=ue[ce]?.top;const je=He!==void 0&&Ae.startIndex===Pe.endMessageExclusive&&Pe.noteIndices.length===0?He+F[ce].blockPadTop:U[Pe.noteIndices[0]??-1]?.y??L;O.add(ce);const Ke=vM(Ae,F[ce],Pe,e,M,A,$,U,oe,r,h,je,ue[ce]);oe[ce]=Ke;ye=Math.max(ye,Ke.y+Ke.height);const ze=De.get(ce);if(ze){Se=Math.max(Se,ze.bottom,ye);L=Math.max(L,Se+p/2);De.delete(ce)}};const be=()=>{if(z){while(ve<z.length){const ce=z[ve];if(ce.messageIndex>$.length||ce.noteIndex>Ie)break;const Ae=ce.blockIndex;if(ce.kind==="open"&&N.has(Ae))me(Ae);if(ce.kind==="open"&&e.blocks[Ae].type==="par_over"){me(Ae);const Pe=Math.max(0,...F[Ae].dividers.map(He=>He.noteContentOffset));Te+=Pe;Se=Te;L=Math.max(L,Te+p/2);De.set(Ae,{messageY:L,contentBottom:Se,completedBottom:ye,reservedBottom:Te,bottom:Se,messageEnd:e.blocks[Ae].startIndex,noteEnd:ce.noteIndex,priorChildren:[]});$e++}if(ce.kind==="divider"){const Pe=De.get(Ae);if(Pe){Pe.bottom=Math.max(Pe.bottom,Se,ye,Te);Pe.messageEnd=ce.messageIndex;Pe.noteEnd=ce.noteIndex;Pe.priorChildren=B[Ae].childBlockIndices.filter(Ke=>oe[Ke]);({messageY:L,contentBottom:Se,completedBottom:ye,reservedBottom:Te}=Pe);$e++;ve++;continue}const He=F[Ae].dividers[ce.dividerIndex];const je=Math.max(Se,ye,Te)+8;if(N.has(Ae)){ue[Ae].dividerY[ce.dividerIndex]=je;Se=Te=je+He.noteContentOffset}else{Te=je+He.noteContentOffset}}if(ce.kind==="close")de(Ae);ve++}return}while(Ee<e.blocks.length){const ce=Ee;const Ae=B[ce];if(Ae.endMessageExclusive>$.length||Ae.endNoteExclusive>Ie)break;de(ce);Ee++}};const pe=(ce,Ae)=>{let Pe=Ae;for(const{note:He,index:je}of X.get(ce)??[]){const Ke=$e;be();if(Ke!==$e)Pe=L;Pe=Math.max(Pe,ye+8,Te);for(const it of D.get(je)??[]){const $t=ue[it]?.top;if($t!==void 0)Pe=Math.max(Pe,$t+F[it].contentTopPadding)}const ze=(D.get(je)??[]).filter(it=>!O.has(it));const Ze=W.get(je)??0;if(ze.length>0||Ze>0){const it=Ze+(ze.length>0?F[ze[0]].contentTopPadding+ze.slice(1).reduce(($t,yn)=>$t+F[yn].enclosingHeaderStep,0):0);Pe=Math.max(Pe,Math.max(Se,ye)+8+it);for(const $t of ze)O.add($t)}let tt=ie(He,Pe);const nt=fe(tt,void 0,je);if(nt>0){Pe+=nt;tt=ie(He,Pe)}U[je]=tt;Se=Math.max(Se,tt.y+tt.height);Ie=je+1;Pe=tt.y+tt.height+4}if(X.has(ce))L=Math.max(L,Pe+p/2)};pe(-1,L);for(let ce=0;ce<e.messages.length;ce++){const Ae=e.messages[ce];const Pe=b[ce];const He=M.get(Ae.from)??0;const je=M.get(Ae.to)??0;const Ke=Ae.from===Ae.to;be();const ze=G(ce);let Ze=Math.max(_.get(ce)??0,Y(ze));for(const Fn of q.get(ce)??[]){const Qn=A[Fn].height/2;Ze=Ze>0?Ze+Math.max(0,Qn-12):Qn+8}L+=Ze+Pe.extraAboveHeight;const tt=P[He];const nt=P[je];const it=e.actors[je].createMessageIndex===ce&&e.actors[je].type==="participant";const $t=it&&!Ke?nt-Math.sign(nt-tt)*x[je]/2:nt;const yn=()=>{const Fn=ON(Ae,Pe,r,tt,$t,L);$[ce]=Fn;for(const Qn of q.get(ce)??[]){A[Qn]=RM(e.actors[Qn],S[Qn],P[Qn],L-A[Qn].height/2)}return Fn};let St=yn();let fi=St.bounds.y;let ul=0;const Hx=new Set(ze);const k1=(H.get(ce)??[]).filter(Fn=>Hx.has(Fn)||ue[Fn]?.top!==void 0&&!oe[Fn]);if(k1.length>0){const Fn=[];for(const Qn of k1){for(const Yx of B[Qn].childBlockIndices)if(oe[Yx])Fn[Yx]=oe[Yx];Fn[Qn]=vM(e.blocks[Qn],F[Qn],B[Qn],e,M,A,$,U,Fn,r,h,L,ue[Qn]);const gu=ue[Qn]?.top;if(gu!==void 0)ul=Math.max(ul,gu-Fn[Qn].y);else fi=Math.min(fi,Fn[Qn].y)}}const pB=ze.length>0?Math.max(Se,ye,Te):Math.max(ye,Te);const C1=Math.max(0,ul,pB+(ze.length>0?8:0)-fi);if(C1>0){L+=C1;St=yn()}const P1=fe(St.bounds,ce);if(P1>0){L+=P1;St=yn()}for(const Fn of ze)O.add(Fn);Se=Math.max(Se,St.bounds.y+St.bounds.height,...(q.get(ce)??[]).map(Fn=>A[Fn].bounds.y+A[Fn].bounds.height));ae(ce,L);const E1=V.get(ce);if(E1)for(const Fn of E1)ne.set(Fn,L);if(Ae.activate)te(Ae.to,L);if(Ae.deactivate)ee(Ae.from,L);const R1=Ke?Math.max(g,Math.ceil(Pe.labelMetrics.height)+10):0;L+=Ke?R1+p:p;const jx=q.get(ce);if(jx){const Fn=Math.max(...jx.map(Qn=>{const gu=A[Qn];return gu.bounds.height-gu.height/2}));L+=Fn}const gB=jx?Se+8:St.y+R1+14;pe(ce,gB)}be();const Re=Math.max($[$.length-1]?.y??L,L-p/2);ae(e.messages.length,Re);for(const[ce,Ae]of K){while(Ae.length>0)ee(ce,Re)}for(const ce of A)if(e.actors[M.get(ce.id)]?.external)ce.external=true;for(const[ce,Ae]of $.entries()){const Pe=e.messages[ce];if(Pe.id!==void 0)Ae.id=Pe.id;if(Pe.parentId!==void 0)Ae.parentId=Pe.parentId}for(const[ce,Ae]of oe.entries()){const Pe=e.blocks[ce];if(Pe.id!==void 0)Ae.id=Pe.id;if(Pe.parentId!==void 0)Ae.parentId=Pe.parentId}for(const[ce,Ae]of U.entries()){const Pe=e.notes[ce];if(Ae&&Pe?.id!==void 0)Ae.id=Pe.id;if(Ae&&Pe?.parentId!==void 0)Ae.parentId=Pe.parentId}const Ne=U.filter(ce=>ce!==void 0);const J=oe.reduce((ce,Ae)=>Math.max(ce,Ae.y+Ae.height),0);if(J>0){L=Math.max(L,J+8)}const ge=L;const Ce=k.map(({box:ce,memberIdxs:Ae,block:Pe})=>{const He=Math.min(...Ae.map(ze=>A[ze].bounds.x))-Gn.boxPadX;let je=Math.max(...Ae.map(ze=>A[ze].bounds.x+A[ze].bounds.width))+Gn.boxPadX;if(ce.label){const ze=Pe.width;je=Math.max(je,He+ze+Gn.boxPadX*2)}const Ke=s;return{label:ce.label,block:Pe,labelY:s+v/2,color:ce.color,x:He,y:Ke,width:je-He,height:ge+Gn.boxPadBottom-Ke}});const Me=L+s;let le=o;let we=0;for(const ce of A){const Ae=ce.bounds;le=Math.min(le,Ae.x);we=Math.max(we,Ae.x+Ae.width)}for(const ce of oe){le=Math.min(le,ce.x);we=Math.max(we,ce.x+ce.width)}for(const ce of Ne){le=Math.min(le,ce.x);we=Math.max(we,ce.x+ce.width)}for(const ce of Ce){le=Math.min(le,ce.x);we=Math.max(we,ce.x+ce.width)}for(const ce of Z){le=Math.min(le,ce.x);we=Math.max(we,ce.x+ce.width)}for(const ce of $){le=Math.min(le,ce.bounds.x);const Ae=ce.isSelf&&ce.label?8:0;we=Math.max(we,ce.bounds.x+ce.bounds.width+Ae)}const ke=le<o?o-le:0;if(ke>0){TM({actors:A,messages:$,blocks:oe,notes:Ne,boxes:Ce,activations:Z,lifelines:[],destructions:[]},ke,0);for(let ce=0;ce<P.length;ce++)P[ce]+=ke}const Le=e.actors.map((ce,Ae)=>{const Pe=A[Ae];const He=Pe.bounds.y+Pe.bounds.height;return{actorId:ce.id,x:P[Ae],topY:He,bottomY:ne.get(ce.id)??Me-s}});const Fe=e.actors.filter(ce=>ne.has(ce.id)).map(ce=>({actorId:ce.id,x:P[M.get(ce.id)],y:ne.get(ce.id)}));const Oe=we+ke+o;const We=Me;return zN({width:Math.max(Oe,200),height:Math.max(We,100),accessibilityTitle:e.accessibilityTitle,accessibilityDescription:e.accessibilityDescription,actors:A,lifelines:Le,messages:$,activations:Z,blocks:oe,notes:Ne,boxes:Ce,destructions:Fe},e.title===void 0?void 0:qe(e.title,e.titleContent),r,o,s)}function zN(e,t,n,i,r){const o=tn(t,n);if(!o)return e;if(e.width===0&&e.height===0)return{...e,...pa(o,i,r)};const s=o.height;TM(e,0,s);const a=Math.max(e.width,o.width+2*i);return{...e,width:a,height:e.height+s,title:on(o,a,r)}}function ki(e,t,n,i,r){const o={};if(r){o["role"]="img";o["aria-roledescription"]=r}else if(e||t){o["role"]="img"}if(e)o["aria-labelledby"]=n;if(t)o["aria-describedby"]=i;return o}function GN(e){const t=new Map;const n=[];for(const s of e){const a=`${s.from}->${s.to}`;const l=t.get(a)??0;t.set(a,l+1);if(!s.labelPosition.text.trim())continue;const c=s.labelPosition.bounds;n.push({key:`${a}#${l}`,x:c.x-2,y:c.y-2,width:c.width+4,height:c.height+4})}const i=s=>{const a=s==="x"?"width":"height";const l=[...n].sort((u,f)=>u[s]-f[s]);const c=(u,f)=>{if(u>=f)return void 0;const h=u+f>>>1;const m=l[h];const p=c(u,h);const g=c(h+1,f);return{area:m,left:p,right:g,end:Math.max(m[s]+m[a],p?.end??-Infinity,g?.end??-Infinity)}};const d=c(0,l.length);return u=>{const f=[];const h=m=>{if(!m||m.end<u[s])return;h(m.left);const p=m.area;if(p[s]>u[s]+u[a])return;if(p.x<=u.x+u.width&&p.x+p.width>=u.x&&p.y<=u.y+u.height&&p.y+p.height>=u.y)f.push(p);h(m.right)};h(d);return f}};const r=i("x");const o=i("y");return(s,a)=>{const l=(a==="x"?r:o)(s).sort((h,m)=>h.y-m.y);const c=[];const d=s.y+s.height;let u=s.y;let f;for(const h of l){const m=Math.max(s.y,h.y);if(m>u)c.push({top:u,bottom:m,after:f});const p=Math.min(d,h.y+h.height);if(p>u){u=p;f=h.key}}if(u<d)c.push({top:u,bottom:d,after:f});return c}}function AM(e,t){const{positioned:n,colors:i,resolved:r}=t;const o=r.renderOptions;const s=i.font??"Inter";const a=o.transparent??false;const l=[];const c=Ue(o,kc,r.styleFace);const d=`seq-${pi(n.width,n.height,n.actors.length,n.messages.length)}`;const u=`${d}-title`;const f=`${d}-desc`;const h=ki(n.accessibilityTitle,n.accessibilityDescription,u,f);l.push(e.documentOpen({id:"prelude",width:n.width,height:n.height,colors:i,transparent:a,font:s,hasMonoFont:false},Ot(n.width,n.height,i,a,h)+"\n"+Dt(s,false,i.shadow,i.embedFontImport)));const m=[];m.push("<defs>");const p=s6(c);m.push(mi(p));const g=en(i);if(g)m.push(g);m.push("</defs>");l.push(e.definitions({id:"defs",markerResources:p},m.join("\n")));if(n.accessibilityTitle){l.push(e.documentContent({id:"a11y-title",role:"chrome",nonPaint:"accessibility"},`<title id="${u}">${At(n.accessibilityTitle)}</title>`))}if(n.accessibilityDescription){l.push(e.documentContent({id:"a11y-desc",role:"chrome",nonPaint:"accessibility"},`<desc id="${f}">${At(n.accessibilityDescription)}</desc>`))}const y=n.blocks.some(R=>R.type==="rect");const w=y?[...n.blocks].reverse().sort((R,I)=>I.width*I.height-R.width*R.height):n.blocks;const S=o6(n.boxes,w,c,i);if(n.title)l.push(e.text(En(n.title,c)));const x=new Map;for(const R of n.boxes){const I=R.label??"";const L=x.get(I)??0;x.set(I,L+1);l.push(h6(e,R,c,`box:${I}#${L}`))}const M=new Map;const b=new Map;for(const R of n.blocks){const I=M.get(R.type)??0;M.set(R.type,I+1);b.set(R,R.id??`block:${R.type}#${I}`)}for(const R of w){l.push(LM(e,R,c,b.get(R),y?"background":"all"))}if(y){for(const R of w){if(R.type!=="rect")l.push(LM(e,R,c,b.get(R),"frame"))}for(const R of n.blocks){if(R.dividers.length>0)l.push(LM(e,R,c,b.get(R),"dividers"))}}const C=GN(n.messages);const P=new Set(n.actors.filter(R=>R.external).map(R=>R.id));for(const R of n.lifelines){if(P.has(R.actorId))continue;const I=Math.max(.75,c.lineWidth*.75);l.push(l6(e,R,c,C({x:R.x-I/2,y:R.topY,width:I,height:R.bottomY-R.topY},"x")))}const E=new Map;for(const R of n.activations){const I=E.get(R.actorId)??0;E.set(R.actorId,I+1);l.push(c6(e,R,c,`activation:${R.actorId}#${I}`,C({x:R.x-et.innerBox/2,y:R.topY,width:R.width+et.innerBox,height:R.bottomY-R.topY},"y")))}const k=new Map;for(const R of n.blocks){const I=k.get(R.type)??0;k.set(R.type,I+1);if(R.type!=="rect"&&R.header)l.push(f6(e,R.header,c,b.get(R)))}const v=new Map;for(const R of n.blocks){const I=v.get(R.type)??0;v.set(R.type,I+1);if(R.dividers.some(L=>L.label))l.push(u6(e,R,c,b.get(R),S))}const T=new Map;for(const R of n.messages){const I=`${R.from}->${R.to}`;const L=T.get(I)??0;T.set(I,L+1);l.push(d6(e,R,c,R.id??`message:${I}#${L}`,S,p))}const A=new Map;for(const R of n.notes){const I=`${(R.actors??[]).join(",")}@${R.position??"over"}`;const L=A.get(I)??0;A.set(I,L+1);l.push(g6(e,R,c,i,R.id??`note:${I}#${L}`))}for(const R of n.destructions){l.push(p6(e,R,c))}for(const R of n.actors){if(R.external)continue;l.push(a6(e,R,c,i,r.styleFace,o.security!=="strict",S))}l.push(e.documentClose());return{family:"sequence",width:n.width,height:n.height,colors:i,transparent:a,parts:l}}function $h(e){return e.halo?{stroke:e.halo,strokeWidth:"3",strokeLinejoin:"round",paintOrder:"stroke"}:{}}function Yy(e){return{x:e.x+e.width/2,y:e.y+e.height/2,width:e.width,height:e.height}}function o6(e,t,n,i){const r=(c,d,u)=>d>=c.x&&d<=c.x+c.width&&u>=c.y&&u<=c.y+c.height;const o=e.flatMap(c=>{const d=c.color&&c.color.toLowerCase()!=="transparent"?Tw(c.color):void 0;return d?[{x:c.x,y:c.y,width:c.width,height:c.height,hex:d,authored:true}]:[]});const s=_n("var(--bg)",i)??"#ffffff";for(const c of t){const d=jN(c,n);const u=d===void 0?void 0:_n(d,i)??d;const f=u===void 0?null:Kt(u);if(!f||f[3]===0)continue;const h=c.x+c.width/2;const m=c.y+c.height/2;const p=o.findLast(y=>r(y,h,m))?.hex??s;const g=xu(u,p);if(!g)continue;o.push({x:c.x,y:c.y,width:c.width,height:c.height,hex:Yn(...g),authored:c.type==="rect"})}const a=(c,d)=>d.x-d.width/2<c.x+c.width&&d.x+d.width/2>c.x&&d.y-d.height/2<c.y+c.height&&d.y+d.height/2>c.y;const l=(c,d)=>r(c,d.x-d.width/2,d.y-d.height/2)&&r(c,d.x+d.width/2,d.y+d.height/2);return(c,d)=>{const u=o.findLastIndex(g=>r(g,c.x,c.y));const f=o[u];const h=f!==void 0&&!l(f,c)||o.some((g,y)=>y>u&&g.hex!==f?.hex&&a(g,c));if(!f)return h?{ink:d,halo:"var(--bg)"}:{ink:d};const m=_n(d,i);const p=m?xs(m,f.hex):Xo(f.hex)??d;return f.authored||h?{ink:p,halo:f.hex}:{ink:p}}}function s6(e){const t=bn.width;const n=bn.height;const i=e.edgeStrokeColor??"var(--_arrow)";const r={size:{width:t,height:n},orient:"auto-start-reverse"};const o=[{x:0,y:0},{x:t,y:n/2},{x:0,y:n}];return[{...r,id:"seq-arrow",shape:"arrow",ref:{x:t,y:n/2},geometry:{kind:"polygon",points:o},paint:{fill:i}},{...r,id:"seq-arrow-open",shape:"open-arrow",ref:{x:t,y:n/2},geometry:{kind:"polyline",points:o},paint:{fill:"none",stroke:i,strokeWidth:"1"}},{...r,id:"seq-arrow-cross",shape:"cross",ref:{x:t/2,y:n/2},orient:"auto",geometry:{kind:"path",d:`M1 1 L${t-1} ${n-1} M1 ${n-1} L${t-1} 1`},paint:{fill:"none",stroke:i,strokeWidth:"1.5"}},{...r,id:"seq-arrow-half-top",shape:"arrow",ref:{x:t,y:n/2},geometry:{kind:"polygon",points:[{x:0,y:0},{x:t,y:n/2},{x:0,y:n/2}]},paint:{fill:i}},{...r,id:"seq-arrow-half-bottom",shape:"arrow",ref:{x:t,y:n/2},geometry:{kind:"polygon",points:[{x:0,y:n/2},{x:t,y:n/2},{x:0,y:n}]},paint:{fill:i}},{...r,id:"seq-arrow-stick-top",shape:"open-arrow",ref:{x:t,y:n/2},geometry:{kind:"path",d:`M0 0 L${t} ${n/2}`},paint:{fill:"none",stroke:i,strokeWidth:"1.5"}},{...r,id:"seq-arrow-stick-bottom",shape:"open-arrow",ref:{x:t,y:n/2},geometry:{kind:"path",d:`M0 ${n} L${t} ${n/2}`},paint:{fill:"none",stroke:i,strokeWidth:"1.5"}}]}function HN(e,t){if(t==="none")return void 0;const n=t==="filled"?"seq-arrow":t==="cross"?"seq-arrow-cross":t==="half-top"?"seq-arrow-half-top":t==="half-bottom"?"seq-arrow-half-bottom":t==="stick-top"?"seq-arrow-stick-top":t==="stick-bottom"?"seq-arrow-stick-bottom":"seq-arrow-open";return e.find(i=>i.id===n)}function a6(e,t,n,i,r,o,s){const{id:a,x:l,y:c,width:d,height:u,label:f,type:h}=t;const m=[];const p=It(r,"actor",{category:a},{includeFallback:false});const g=p?.fontSize??n.nodeLabelFontSize;const y=p?.fontWeight??n.nodeLabelFontWeight;const w=p?.letterSpacing??n.nodeLetterSpacing;const S=p?.textTransform??n.nodeTextTransform;const x=p?.lineWidth??n.nodeLineWidth;const M=p?.fillColor??n.nodeFillColor??"var(--_node-fill)";const b=p?.borderColor??n.nodeBorderColor??"var(--_node-stroke)";const C=p?.textColor??n.nodeTextColor??"var(--_text)";const P=p?.textColor??n.nodeTextColor??xi("var(--_text)",M,i);const E=o&&t.links?` data-links="${Ye(JSON.stringify(t.links))}" role="link" tabindex="0"`:"";const k=`<g class="actor" data-id="${Ye(a)}" data-label="${hn(f)}" data-type="${h}"${E}>`;const{text:v,x:T,y:A,bounds:R}=t.labelPosition;const I=s(Yy(R),C);if(h==="actor"){const $=u/24*.9;const B=l-12*$;const F=c+(u-24*$)/2;const z=x/$;m.push({indent:2,node:e.pathArtwork({id:`actor:${a}:icon`,owner:{id:a,role:"actor"},channels:{category:a},open:`<g transform="translate(${B},${F}) scale(${$})">`,transform:{kind:"matrix",a:$,b:0,c:0,d:$,e:B,f:F},paint:{fill:"none",stroke:p?.borderColor??n.edgeStrokeColor??"var(--_line)",strokeWidth:String(z)},join:"\n",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"]})});m.push({indent:2,node:e.text({id:`actor:${a}:label`,role:"label",text:v,block:t.labelPosition.block,x:T,y:A,fontSize:g,fontWeight:y,letterSpacing:w,anchor:"middle",paint:{fill:I.ink,...$h(I)},channels:{category:a}})})}else if(h!=="participant"){const $=l-d/2;const B=c+2;const F=d;const z=Math.max(24,u-4);const _=[];const H={id:a,role:"actor"};const D={fill:M,stroke:p?.borderColor??n.edgeStrokeColor??"var(--_line)",strokeWidth:String(x)};const j=Y=>{_.push(e.shape({id:xn(`actor:${a}:icon`,"part",_.length),role:"icon",owner:H,geometry:Y,paint:D}))};const W=Y=>j({kind:"path",d:Y});const O=(Y,q,V)=>j({kind:"circle",cx:Y,cy:q,r:V});const N=(Y,q,V,ne)=>j({kind:"line",x1:Y,y1:q,x2:V,y2:ne});const G=(Y,q,V,ne,X)=>j({kind:"rect",x:Y,y:q,width:V,height:ne,...X===void 0?{}:{rx:X}});if(h==="database"){j({kind:"ellipse",cx:l,cy:B+5,rx:F/2,ry:5});W(`M${$} ${B+5}V${B+z-5}A${F/2} 5 0 0 0 ${$+F} ${B+z-5}V${B+5}`);j({kind:"ellipse",cx:l,cy:B+z-5,rx:F/2,ry:5})}else if(h==="collections"){G($+6,B,F-6,z-6);G($,B+6,F-6,z-6)}else if(h==="queue"){G($,B,F,z,z/2);N($+8,B+z/2,$+F-8,B+z/2)}else if(h==="entity"){O(l,B+z/2-3,Math.min(F,z)/2-3);N($+5,B+z,$+F-5,B+z)}else if(h==="boundary"){O(l+3,B+z/2,Math.min(F,z)/2-3);N($+3,B+2,$+3,B+z-2)}else if(h==="control"){O(l,B+z/2,Math.min(F,z)/2-3);W(`M${l-4} ${B+4}L${l+4} ${B}L${l+2} ${B+8}`)}else O(l,B+z/2,Math.min(F,z)/2-3);m.push({indent:2,node:e.group({id:`actor:${a}:icon`,role:"icon",owner:H,channels:{category:a},open:`<g class="sequence-actor-glyph sequence-actor-${h}">`,close:"</g>",join:"",children:_.map(Y=>({node:Y,indent:0}))})});m.push({indent:2,node:e.text({id:`actor:${a}:label`,role:"label",text:v,block:t.labelPosition.block,x:T,y:A,fontSize:g,fontWeight:y,letterSpacing:w,anchor:"middle",paint:{fill:I.ink,...$h(I)},channels:{category:a}})})}else{const $=l-d/2;const B=M;const F=b;const z=p?.cornerRadius??n.cornerRadius??4;m.push({indent:2,node:e.shape({id:`actor:${a}:box`,role:"actor",geometry:{kind:"rect",x:$,y:c,width:d,height:u,rx:z,ry:z},paint:{fill:B,stroke:F,strokeWidth:String(x)},channels:{category:a}})});m.push({indent:2,node:e.text({id:`actor:${a}:label`,role:"label",text:v,block:t.labelPosition.block,x:T,y:A,fontSize:g,fontWeight:y,letterSpacing:w,anchor:"middle",paint:{fill:P},channels:{category:a}})})}const L=h==="participant"?P:C;if(t.links)m.push({indent:2,node:e.text({id:`actor:${a}:menu`,role:"icon",text:"\u22EF",block:t.menuBlock,x:l+d/2-7,y:c+10,fontSize:10,anchor:"middle",paint:{fill:L},channels:{category:a},baselineShift:0,attributes:{className:"sequence-actor-menu"}})});return e.group({id:`actor:${a}`,role:"actor",open:k,close:"</g>",children:m,channels:{category:a}})}function l6(e,t,n,i){const r=n.edgeStrokeColor??"var(--_line)";const o=Math.max(.75,n.lineWidth*.75);const s=`lifeline:${t.actorId}`;if(i.length!==1||i[0].top!==t.topY||i[0].bottom!==t.bottomY){return e.group({id:s,role:"lifeline",open:`<g class="lifeline" data-actor="${Ye(t.actorId)}">`,close:"</g>",children:i.map(a=>{const l=(a.top-t.topY)%10;return{indent:2,node:e.connector({id:a.after?xn(s,"after",a.after):xn(s,"start"),role:"lifeline",geometry:{kind:"line",x1:t.x,y1:a.top,x2:t.x,y2:a.bottom},lineStyle:"dashed",paint:{stroke:r,strokeWidth:String(o),strokeDasharray:"6 4",strokeDashoffset:String(l)}})}})})}return e.connector({id:s,role:"lifeline",geometry:{kind:"line",x1:t.x,y1:t.topY,x2:t.x,y2:t.bottomY},lineStyle:"dashed",paint:{stroke:r,strokeWidth:String(o),strokeDasharray:"6 4"},attributes:{className:"lifeline",data:{actor:t.actorId}}})}function c6(e,t,n,i,r){const o=n.nodeFillColor??"var(--_node-fill)";const s=n.nodeBorderColor??"var(--_node-stroke)";if(r.length!==1||r[0].top!==t.topY||r[0].bottom!==t.bottomY){const a=[];const l=[];const c=[];for(const d of r){l.push(`M ${t.x} ${d.top} h ${t.width} V ${d.bottom} h ${-t.width} Z`);const u=[{x1:t.x,y1:d.top,x2:t.x,y2:d.bottom},{x1:t.x+t.width,y1:d.top,x2:t.x+t.width,y2:d.bottom},...d.top===t.topY?[{x1:t.x,y1:d.top,x2:t.x+t.width,y2:d.top}]:[],...d.bottom===t.bottomY?[{x1:t.x,y1:d.bottom,x2:t.x+t.width,y2:d.bottom}]:[]];for(const f of u){c.push(`M ${f.x1} ${f.y1} L ${f.x2} ${f.y2}`)}}if(l.length){const d=l.join(" ");const u=c.join(" ");a.push({indent:2,node:e.shape({id:xn(i,"fill"),role:"activation",surfaceFragment:true,geometry:{kind:"path",d},paint:{fill:o,stroke:"none"}})});a.push({indent:2,node:e.shape({id:xn(i,"border"),role:"activation",geometry:{kind:"path",d:u},paint:{fill:"none",stroke:s,strokeWidth:String(et.innerBox)}})})}return e.group({id:i,role:"activation",open:`<g class="activation" data-actor="${Ye(t.actorId)}">`,close:"</g>",children:a})}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:o,stroke:s,strokeWidth:String(et.innerBox)},attributes:{className:"activation",data:{actor:t.actorId}}})}function d6(e,t,n,i,r,o){const s=[];const a=HN(o,t.startHead);const l=HN(o,t.endHead);const c=n.edgeStrokeColor??"var(--_line)";const d=n.edgeTextColor??"var(--_text-muted)";const{text:u,x:f,y:h,bounds:m}=t.labelPosition;const p={stroke:c,strokeWidth:String(n.lineWidth),...t.lineStyle==="dashed"?{strokeDasharray:"6 4"}:{}};const g={endpoints:{from:t.from,to:t.to},relationship:{kind:"sequence-message",direction:t.isSelf?"self":a&&l?"bidirectional":a?"reverse":l?"forward":"undirected"},route:{ownership:"layout"},labels:t.label?[{text:t.label,...t.labelContent?{textContent:t.labelContent}:{}}]:[]};const y=`<g class="message" data-label="${hn(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}"${t.parentId===void 0?"":` data-parent-id="${Ye(t.parentId)}"`}>`;if(t.isSelf){s.push({indent:2,node:e.connector({id:`${i}:line`,role:"message",geometry:{kind:"polyline",points:t.points},lineStyle:t.lineStyle,paint:p,markers:{...a?{start:a}:{},mid:[],...l?{end:l}:{}},...g})});const w=r(Yy(m),d);s.push({indent:2,node:e.text({id:`${i}:label`,role:"label",text:u,block:t.labelPosition.block,x:f,y:h,fontSize:n.edgeLabelFontSize,fontWeight:n.edgeLabelFontWeight,letterSpacing:n.edgeLetterSpacing,anchor:"start",paint:{fill:w.ink,...$h(w)}})})}else{const w=t.points[0];const S=t.points[t.points.length-1];s.push({indent:2,node:e.connector({id:`${i}:line`,role:"message",geometry:{kind:"line",x1:w.x,y1:w.y,x2:S.x,y2:S.y},lineStyle:t.lineStyle,paint:p,markers:{...a?{start:a}:{},mid:[],...l?{end:l}:{}},...g})});const x=r(Yy(m),d);s.push({indent:2,node:e.text({id:`${i}:label`,role:"label",text:u,block:t.labelPosition.block,x:f,y:h,fontSize:n.edgeLabelFontSize,fontWeight:n.edgeLabelFontWeight,letterSpacing:n.edgeLetterSpacing,anchor:"middle",paint:{fill:x.ink,...$h(x)}})})}if(t.centralStart)s.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:c,strokeWidth:"1.5"},attributes:{className:"sequence-central-connection",data:{side:"start"}}})});if(t.centralEnd)s.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:c,strokeWidth:"1.5"},attributes:{className:"sequence-central-connection",data:{side:"end"}}})});return e.group({id:i,role:"message",open:y,close:"</g>",children:s})}function jN(e,t){return e.type==="rect"?e.color??t.groupFillColor??"rgba(128, 128, 128, 0.5)":t.groupFillColor}function LM(e,t,n,i,r="all"){const o=[];const s=t.label?` data-label="${hn(t.label)}"`:"";const a=r==="dividers"?`<g class="sequence-block-divider-overlay" data-owner="${Ye(i)}">`:r==="frame"?`<g class="sequence-block-frame-overlay" data-owner="${Ye(i)}">`:`<g class="block" data-type="${Ye(t.type)}"${s}${t.parentId===void 0?"":` data-parent-id="${Ye(t.parentId)}"`}>`;const l=jN(t,n)??"none";const c=t.type==="rect"?"none":n.groupBorderColor??"var(--_node-stroke)";const d=r==="frame"?"none":l;const u=r==="background"?"none":c;if(r!=="dividers")o.push({indent:2,node:e.shape({id:r==="frame"?`${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:d,stroke:u,strokeWidth:String(n.groupLineWidth)}})});const f=n.edgeStrokeColor??"var(--_line)";let h=0;for(const m of r==="background"||r==="frame"||t.type==="par_over"?[]:t.dividers){const p=`${i}:divider#${h}`;h++;const g=Math.max(.75,n.lineWidth*.75);o.push({indent:2,node:e.connector({id:p,role:"block",geometry:{kind:"line",x1:t.x,y1:m.y,x2:t.x+t.width,y2:m.y},lineStyle:"dashed",paint:{stroke:f,strokeWidth:String(g),strokeDasharray:"6 4"}})})}return e.group({id:r==="dividers"?`${i}:divider-overlay`:r==="frame"?`${i}:frame-overlay`:i,role:"block",open:a,close:"</g>",children:o})}function u6(e,t,n,i,r){const o=n.edgeTextColor??"var(--_text-muted)";const s=[];t.dividers.forEach((a,l)=>{if(!a.label||!a.labelPosition)return;const{text:c,x:d,y:u,bounds:f}=a.labelPosition;const h=r(Yy(f),o);const m={ink:h.ink,halo:h.halo??n.groupFillColor??"var(--bg)"};s.push({indent:2,node:e.text({id:`${i}:divider#${l}:label`,role:"label",text:c,block:a.labelPosition.block,x:d,y:u,fontSize:n.edgeLabelFontSize,fontWeight:n.edgeLabelFontWeight,letterSpacing:n.edgeLetterSpacing,anchor:"start",paint:{fill:m.ink,...$h(m)}})})});return e.group({id:`${i}:divider-labels`,role:"block",open:`<g class="sequence-block-divider-labels" pointer-events="none">`,close:"</g>",children:s})}function f6(e,t,n,i){const{x:r,y:o,width:s,height:a,label:l}=t;const{text:c,x:d,y:u}=l;const f=n.groupHeaderFillColor??"var(--_group-hdr)";const h=n.groupBorderColor??"var(--_node-stroke)";const m=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:r,y:o,width:s,height:a},paint:{fill:f,stroke:h,strokeWidth:String(n.groupLineWidth)}})},{indent:0,node:e.text({id:`${i}:label`,role:"label",text:c,block:l.block,x:d,y:u,fontSize:n.groupHeaderFontSize,fontWeight:n.groupHeaderFontWeight,letterSpacing:n.groupLetterSpacing,anchor:"start",paint:{fill:m}})}]})}function h6(e,t,n,i){const r=[];const o=t.label?` data-label="${hn(t.label)}"`:"";const s=`<g class="box"${o}>`;const a=t.color?.toLowerCase()==="transparent"?"none":t.color;const l=a??"color-mix(in srgb, var(--fg) 5%, var(--bg))";r.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"}})});if(t.label){const c=t.block?.text??gi(t.label,n.groupTextTransform);const d=m6(a,n);const u=t.x+t.width/2;const f=t.labelY??t.y+13;r.push({indent:2,node:e.text({id:`${i}:title`,role:"label",text:c,block:t.block,x:u,y:f,fontSize:n.groupHeaderFontSize,fontWeight:n.groupHeaderFontWeight,letterSpacing:n.groupLetterSpacing,anchor:"middle",paint:{fill:d}})})}return e.group({id:i,role:"group",open:s,close:"</g>",children:r})}function m6(e,t){const n=t.groupTextColor??"var(--_text-sec)";if(!e||e==="none")return n;const i=Tw(e);if(!i)return n;const r=t.groupTextColor;if(r){const o=bu(r,i);if(o!==null&&o>=4.5)return r}return Xo(i)??n}function p6(e,t,n){const i=8;const r=n.edgeStrokeColor??"var(--_line)";const o=Math.max(1.5,n.lineWidth);const s=`M ${t.x-i} ${t.y-i} L ${t.x+i} ${t.y+i} M ${t.x-i} ${t.y+i} L ${t.x+i} ${t.y-i}`;return e.shape({id:`destroy:${t.actorId}`,role:"icon",geometry:{kind:"path",d:s},paint:{fill:"none",stroke:r,strokeWidth:String(o)},channels:{category:t.actorId},attributes:{className:"destroy-cross",data:{actor:t.actorId}}})}function g6(e,t,n,i,r){const{x:o,y:s,width:a,height:l}=t;const c=t.actors&&t.actors.length>0?` data-actors="${t.actors.map(Ye).join(",")}"`:"";const d=t.position?` data-position="${Ye(t.position)}"`:"";const u=n.nodeFillColor??"var(--bg)";const f=n.nodeBorderColor??"var(--_node-stroke)";const h=n.nodeTextColor??xi("var(--_text-muted)",u,i);const m=n.cornerRadius??0;const p=t.block?.text??gi(t.text,n.nodeTextTransform);return e.group({id:r,role:"note",open:`<g class="note"${d}${c}${t.parentId===void 0?"":` data-parent-id="${Ye(t.parentId)}"`}>`,close:"</g>",children:[{indent:2,node:e.shape({id:`${r}:rect`,role:"note",geometry:{kind:"rect",x:o,y:s,width:a,height:l,rx:m,ry:m},paint:{fill:u,stroke:f,strokeWidth:String(et.innerBox)}})},{indent:2,node:e.text({id:`${r}:text`,role:"label",text:p,block:t.block,x:o+a/2,y:s+l/2,fontSize:n.nodeLabelFontSize,fontWeight:n.nodeLabelFontWeight,letterSpacing:n.nodeLetterSpacing,anchor:"middle",paint:{fill:h}})}]})}var YN=gt(AM);function qN(e,t={},n,i={}){return jy(WT(e),t,i,n)}var XN=gt((e,t)=>({...AM(e,t),family:"zenuml"}));function UN(e){const t=Jg(e);return{...t,edges:t.edges.map(n=>{const i=n.route;return i&&"family"in i&&i.family==="sequence"?{...n,route:{...i,family:"zenuml"}}:n})}}var Gye={statementEnds:Dw,layout:e=>{const t=tg(Ma(e.source));t.title??=Nr(e.source.frontmatter);t.accessibilityTitle=e.source.accessibility.title??t.accessibilityTitle;t.accessibilityDescription=e.source.accessibility.descr??t.accessibilityDescription;return ht(qN(t,e.renderOptions,e.styleFace))},projectPositioned:ut(UN),lowerScene:ft(XN)};function ls(e,t,n,i,r,o){const s=i.font??"Inter";const a=en(i);return{family:t,width:n.width,height:n.height,colors:i,transparent:r,parts:[e.documentOpen({id:"prelude",width:n.width,height:n.height,colors:i,transparent:r,font:s,hasMonoFont:false},`${Ot(n.width,n.height,i,r)}
25
+ ${Dt(s,false,i.shadow,i.embedFontImport)}${a?`
26
+ <defs>${a}</defs>`:""}`),...o,e.documentClose()]}}function y6(e,{positioned:t,colors:n,resolved:i}){const r=t.style;const o=Jr(n);const s=r.edgeStrokeColor?{...gc,paint:{...gc.paint,fill:r.edgeStrokeColor}}:gc;const a=[e.definitions({id:"defs",markerResources:[s]},`<defs>${mi([s])}</defs>`)];if(t.title)a.push(e.text(En(t.title,r)));for(const l of t.lanes){const c={id:l.id,role:"group"};a.push(e.group({id:l.id,role:"group",open:"<g>",close:"</g>",children:[{node:e.shape({id:`${l.id}:surface`,role:"group",identity:false,owner:c,geometry:{kind:"rect",x:l.x,y:l.y,width:l.width,height:l.height,rx:r.groupCornerRadius},paint:{fill:r.groupFillColor??"var(--_group-fill)",stroke:r.groupBorderColor??"var(--_node-stroke)",strokeWidth:String(r.groupLineWidth)}}),indent:2},...r.groupHeaderFillColor?[{node:e.shape({id:`${l.id}:header`,role:"chrome",owner:c,geometry:{kind:"rect",x:l.x,y:l.y,width:t.laneWidth,height:l.height,rx:r.groupCornerRadius},paint:{fill:r.groupHeaderFillColor,stroke:"none"}}),indent:2}]:[],{node:e.text({id:`${l.id}:label`,role:"label",owner:c,text:l.block.text,block:l.block,x:l.x+r.groupLabelPaddingX,y:l.y+l.height/2,anchor:"start",fontSize:l.block.fontSize,fontWeight:l.block.fontWeight,letterSpacing:l.block.letterSpacing,paint:{fill:r.groupTextColor??o("var(--_text)",r.groupHeaderFillColor??r.groupFillColor??"var(--_group-fill)")}}),indent:2}]}))}for(const l of t.edges)a.push(e.connector({id:l.id,role:"edge",geometry:l.projection?.geometry??{kind:"polyline",points:l.points},route:{ownership:"layout",bendRadius:r.edgeBendRadius,...l.projection?{contours:l.projection.contours}:{}},lineStyle:"solid",paint:{stroke:r.edgeStrokeColor??"var(--_line)",strokeWidth:String(r.lineWidth)},endpoints:{from:l.from,to:l.to},relationship:{kind:l.explicit?"explicit":"inferred",direction:"forward"},markers:{end:s}}));for(const l of t.nodes){const c={id:l.id,role:"node"},d=r.nodeFillColor??"var(--_node-fill)";a.push(e.group({id:l.id,role:"node",open:`<g data-parent="${l.lane}">`,close:"</g>",children:[{node:e.shape({id:`${l.id}:surface`,role:"node",identity:false,owner:c,geometry:{kind:"rect",x:l.x,y:l.y,width:l.width,height:l.height,rx:r.cornerRadius??5},paint:{fill:d,stroke:r.nodeBorderColor??"var(--_node-stroke)",strokeWidth:String(r.nodeLineWidth)}}),indent:2},{node:e.text({id:`${l.id}:label`,role:"label",owner:c,text:l.block.text,block:l.block,x:l.x+l.width/2,y:l.y+l.height/2,anchor:"middle",fontSize:l.block.fontSize,fontWeight:l.block.fontWeight,letterSpacing:l.block.letterSpacing,paint:{fill:r.nodeTextColor??o("var(--_text)",d)}}),indent:2}]}))}return ls(e,"eventmodeling",t,n,i.renderOptions.transparent??false,a)}var VN=gt(y6);var rxe={normalizeRequest:e=>{const t=e.source.config.eventmodeling;const n=t?.padding;const i=t?.rowHeight;return{renderOptions:{...e.renderOptions,...e.renderOptions.padding===void 0&&typeof n==="number"&&Number.isFinite(n)&&n>=0?{padding:n}:{}},familyConfig:{rowHeight:typeof i==="number"&&Number.isFinite(i)&&i>=0?i:0},appearance:{family:{palette:e.colors}}}},statementEnds:oL,layout:e=>{const t=rL(e.source.authoredFamilyBody??e.source.familyBody);if(t.title===void 0&&typeof e.source.frontmatter.title==="string")t.title=e.source.frontmatter.title;return ht(wF(t,e.renderOptions,e.styleFace,e.familyConfig?.rowHeight,e.familyAppearance?.palette))},projectPositioned:ut(({positioned:e})=>({version:1,bounds:{w:xe(e.width),h:xe(e.height)},nodes:e.nodes.map(t=>({id:t.id,x:xe(t.x),y:xe(t.y),w:xe(t.width),h:xe(t.height),shape:"rectangle",label:t.frame.entity,parentId:t.lane,...bt(t.block,t.x+t.width/2,t.y+t.height/2,t)})),edges:e.edges.map(t=>({id:t.id,from:t.from,to:t.to,path:t.points.map(n=>[xe(n.x),xe(n.y)])})),groups:e.lanes.map(t=>({id:t.id,label:t.label,x:xe(t.x),y:xe(t.y),w:xe(t.width),h:xe(t.height),members:e.nodes.filter(n=>n.lane===t.id).map(n=>n.id)})),labels:[]})),lowerScene:ft(VN)};var KN=e=>xt("packet",e,{bitsPerRow:an("a positive safe integer",t=>Number.isSafeInteger(t)&&Number(t)>=1),bitOrder:qs("ascending","descending"),showBits:lt,rowHeight:Jt,bitWidth:Jt,paddingX:Yt,paddingY:Yt,useMaxWidth:lt});function JN(e,t={},n=Mh(),i){const r=e.fields.length?Math.floor(e.fields.at(-1).end/n.bitsPerRow)+1:0;Ve("nodes",r+e.fields.length);const o=Ue(t,void 0,i);const s=t.padding??24;const a=tn(e.title,o);const l=i?.node?.paddingX,c=i?.node?.paddingY??8;const d=Math.max(8,Math.min(11,o.edgeLabelFontSize));const u=n.showBits?d*1.5+4:0;const f=[];const h=Array.from({length:r},()=>n.rowHeight);const m={display:"formatted",transform:o.nodeTextTransform,fontSize:o.nodeLabelFontSize,fontWeight:o.nodeLabelFontWeight,letterSpacing:o.nodeLetterSpacing,fontFamily:t.font};for(const w of e.fields){let S;for(let x=w.start;x<=w.end;){const M=Math.floor(x/n.bitsPerRow),b=M*n.bitsPerRow;const C=Math.min(w.end,b+n.bitsPerRow-1);const P=(C-x+1)*n.bitWidth;const E=Math.min(n.paddingX,P-1),k=P-E;if(x===C)S??=Be(w.label,m);const v=x===C&&S.lines.length===1&&S.text.length<=4;const T=Math.max(1,k-(l===void 0?v?2:8:l*2));const A=v?Math.max(9,Math.min(m.fontSize,Math.floor(m.fontSize*T/Math.max(1,S.width)))):m.fontSize;const R=Be(w.label,{...m,fontSize:A,maxWidth:T});const I=s+(n.bitOrder==="descending"?n.bitsPerRow-(C-b+1):x-b)*n.bitWidth+E/2;f.push({...w,id:`${w.id}:row-${M}`,fieldId:w.id,start:x,end:C,row:M,x:I,y:0,width:k,slotWidth:P,height:0,labelBlock:R,bitLabels:[]});h[M]=Math.max(h[M],R.height+c*2);Ve("nodes",f.length);x=C+1}}let p=s+(a?.height??0);let g=0;for(let w=0;w<r;w++){while(g<f.length&&f[g].row===w){const S=f[g++];S.y=p+u;S.height=h[w];if(n.showBits){const x=S.start===S.end;const M=n.bitOrder==="descending"?S.end:S.start;const b=n.bitOrder==="descending"?S.start:S.end;const C=x?[{bit:S.start,x:S.x+S.width/2,anchor:"middle"}]:[{bit:M,x:S.x+2,anchor:"start"},{bit:b,x:S.x+S.width-2,anchor:"end"}];S.bitLabels=C.map(P=>({text:String(P.bit),x:P.x,y:p+u/2,anchor:P.anchor,block:Be(String(P.bit),{display:"literal",fontSize:d,fontWeight:400})}))}}p+=u+h[w]+n.paddingY}const y=Math.max(s*2+n.bitsPerRow*n.bitWidth,(a?.width??0)+2*s);return{width:y,height:Math.max(s*2+(a?.height??0),p+s),rows:r,fields:f,visual:n,...a?{title:on(a,y,s)}:{},accessibility:{title:e.accessibilityTitle,descr:e.accessibilityDescription}}}function QN(e,t={}){const n=zt(typeof e==="string"?e.split(/\r?\n/):[...e]);const i=[...n.familyLines];while(i.length&&(!i[0].trim()||i[0].trim().startsWith("%%")))i.shift();const r=i.shift()??"";Ge("packet","header",r,{line:1,unit:"normalized"});if(!/^packet(?:-beta)?\s*$/i.test(Ht(r).trim()))throw Je({what:"Invalid packet header",expectedForm:"packet",example:'packet\n+8: "Byte"'});const o={kind:"packet",fields:[],accessibilityTitle:t.title??n.accessibility.title,accessibilityDescription:t.descr??n.accessibility.descr};const s=i.join("\n");const a=/(?:title(?:[ \t]+([^\n]*))?(?:\n|$)|(\+)?(0|[1-9]\d*)[ \t]*(?:-[ \t]*(0|[1-9]\d*))?[ \t]*:[ \t]*("(?:[^"\\]|\\[\s\S])*"|'(?:[^'\\]|\\[\s\S])*')[ \t]*(?:%%[^\n]*)?(?:\n|$))/gy;let l=0,c=-1,d=0,u=2;while(l<s.length){const f=/^(?:\s+|%%[^\n]*(?:\n|$))/.exec(s.slice(l));if(f){l+=f[0].length;continue}a.lastIndex=l;const h=a.exec(s);if(!h){if(!s.slice(l).trim())break;throw Je({what:`Invalid packet statement: ${s.slice(l).split("\n")[0]}`,expectedForm:'start-end: "label" or +bits: "label"',example:'+16: "Source Port"'})}l=a.lastIndex;if(re("packet")){for(;d<h.index;d++)if(s.charCodeAt(d)===10)u++;Ge("packet",h[2]===void 0&&h[3]===void 0?"title":"field",h[0],{line:u,offset:h.index,endOffset:a.lastIndex,unit:"normalized"})}if(h[2]===void 0&&h[3]===void 0){o.title=Ht(h[1]??"").trim();he("packet","set-title",o.title);continue}const m=Number(h[3]),p=h[2]==="+";const g=p?c+1:m;const y=p?g+m-1:h[4]===void 0?g:Number(h[4]);if(p&&h[4]!==void 0||!Number.isSafeInteger(g)||!Number.isSafeInteger(y)||g<0||y<g)throw Je({what:`Invalid packet bit range ${g}-${y}`,expectedForm:"a positive bit count or increasing inclusive bit range",example:'+8: "Byte"'});if(g!==c+1)throw Je({what:`Packet block ${g}-${y} is not contiguous; it must start from ${c+1}`,expectedForm:`a field starting at ${c+1}`,example:`+8: "Next byte"`});let w=h[5].slice(1,-1);w=w.replace(/\\([\s\S])/g,(x,M)=>({n:"\n",r:"\r",t:" ",b:"\b",f:"\f",v:"\v"})[M]??M);const S={id:`field-${o.fields.length}`,start:g,end:y,label:w};o.fields.push(S);he("packet","add-field",S);Ve("nodes",o.fields.length);c=y}return o}function ZN({positioned:e}){return{version:1,nodes:e.fields.map(t=>({id:t.id,x:xe(t.x),y:xe(t.y),w:xe(t.width),h:xe(t.height),shape:"rectangle",label:t.label,...bt(t.labelBlock,t.x+t.width/2,t.y+t.height/2,Ut(e),"middle")})),edges:[],groups:[],bounds:{w:xe(e.width),h:xe(e.height)}}}function x6(e,{positioned:t,colors:n,resolved:i}){const r=Ue(i.renderOptions,void 0,i.styleFace);const o=i.renderOptions.transparent??false;const s=[];if(t.title)s.push(e.text(En(t.title,r)));const a=r.nodeFillColor??"var(--_node-fill)";const l=r.nodeTextColor??Fs(void 0,n,a)("var(--_text)");for(const c of t.fields){const d=[e.shape({id:`${c.id}:box`,role:"node",identity:false,owner:{id:c.id,role:"node"},geometry:{kind:"rect",x:c.x,y:c.y,width:c.width,height:c.height,rx:r.cornerRadius},paint:{fill:a,stroke:r.nodeBorderColor??"var(--_node-stroke)",strokeWidth:String(r.nodeLineWidth)}}),e.text({id:`${c.id}:label`,role:"label",owner:{id:c.id,role:"node"},text:c.labelBlock.text,block:c.labelBlock,x:c.x+c.width/2,y:c.y+c.height/2,fontSize:c.labelBlock.fontSize,fontWeight:c.labelBlock.fontWeight,letterSpacing:c.labelBlock.letterSpacing,anchor:"middle",paint:{fill:l}})];for(const[u,f]of c.bitLabels.entries())d.push(e.text({id:`${c.id}:bit-${u}`,role:"label",text:f.text,block:f.block,x:f.x,y:f.y,fontSize:f.block.fontSize,fontWeight:f.block.fontWeight,anchor:f.anchor,paint:{fill:r.edgeTextColor??"var(--_text-muted)"}}));s.push(e.group({id:c.id,role:"node",open:`<g data-id="${Ye(c.id)}" data-field-id="${Ye(c.fieldId)}" data-start="${c.start}" data-end="${c.end}" data-field-label="${Ye(ca(c.labelBlock.prepared))}">`,close:"</g>",children:d.map(u=>({node:u,indent:2}))}))}return ls(e,"packet",t,n,o,s)}var e$=gt(x6);var Oxe={configDiagnostics:KN,normalizeRequest:e=>({familyConfig:{visual:Mh(e.source.frontmatter)}}),layout:e=>ht(JN(Tn(QN(e.source.familyBody,e.source.accessibility),e.source.frontmatter),e.renderOptions,e.familyConfig?.visual??Mh(),e.styleFace)),projectPositioned:ut(ZN),lowerScene:ft(e$)};var t$=e=>{const t=xt("kanban",e,{padding:Yt,sectionWidth:Jt,ticketBaseUrl:Br,useMaxWidth:lt});const n=Zr(e.root,"kanban")?.ticketBaseUrl;if(typeof n==="string"&&n&&!jp(n,"TICKET"))t.push({code:"INEFFECTIVE_CONFIG",field:"kanban.ticketBaseUrl",message:"kanban.ticketBaseUrl is not a safe inert link; ticket text is preserved without navigation."});return t};function b6(e){const t=[{text:e.label,kind:"label"}];if(e.metadata.ticket)t.push({text:String(e.metadata.ticket),kind:"ticket"});if(e.metadata.assigned)t.push({text:`Assigned: ${e.metadata.assigned}`,kind:"assigned"});if(e.metadata.priority)t.push({text:`Priority: ${e.metadata.priority}`,kind:"priority"});const n=e.icon??e.metadata.icon;if(n)t.push({text:`Icon: ${n}`,kind:"icon"});return t}function n$(e,t={},n=Sf(),i){Ve("nodes",e.columns.reduce((v,T)=>v+T.tasks.length+1,0));const r=Ue(t,void 0,i);const o=t.padding??24,s=Math.max(4,n.padding),a=Math.max(8,r.nodePaddingX),l=Math.max(8,r.nodePaddingY),c=i?.group?.paddingX??s,d=i?.group?.paddingY??s,u=i?.group?.paddingX??s+a,f=i?.group?.paddingY??l;const h=Math.max(160,c*2+a*2+24,u*2+24),m=t.kanban?.maxWidth,p=Math.max(m===void 0?0:h,Math.min(Math.max(n.sectionWidth,c*2+a*2+24,u*2+24),m===void 0?Infinity:m-2*o)),g=Math.max(16,s*2);const y=tn(e.title,r);const w=(v,T)=>b6(v).map(({text:A,kind:R})=>{const I=R==="label";const L=Be(A,{display:"formatted",transform:T?r.groupTextTransform:r.nodeTextTransform,fontSize:T?r.groupHeaderFontSize:I?r.nodeLabelFontSize:r.edgeLabelFontSize,fontWeight:T?r.groupHeaderFontWeight:I?r.nodeLabelFontWeight:r.edgeLabelFontWeight,letterSpacing:T?r.groupLetterSpacing:r.nodeLetterSpacing,fontFamily:T?r.groupFont??t.font:t.font,maxWidth:p-2*(T?u:c+a)});return{text:A,kind:R,block:L,x:0,y:0}});const S=e.columns.map(v=>Yd(w(v,true),{top:o+(y?.height??0)+f,gap:6,trailingGap:true}));const x=Math.max(32,...S.map(v=>v.height+2*f));const M=[];e.columns.forEach((v,T)=>{const A=o+T*(p+g),R=o+(y?.height??0);const I=S[T].rows.map(({item:B,textY:F})=>{B.x=A+u;B.y=F;return B});let L=R+x+d;const $=v.tasks.map(B=>{const F=Yd(w(B,false),{top:L+l,gap:6}),z=Math.max(40,F.height+2*l);const _=F.rows.map(({item:D,textY:j})=>{D.x=A+c+a;D.y=j;return D});const H={...B,parentId:v.id,x:A+c,y:L,width:p-c*2,height:z,texts:_,...B.metadata.ticket?{ticketUrl:jp(n.ticketBaseUrl,String(B.metadata.ticket))}:{}};L+=z+s;return H});M.push({...v,x:A,y:R,width:p,height:L-R+d,headerHeight:x,texts:I,tasks:$})});const b=Math.max(x+d*2,...M.map(v=>v.height));for(const v of M)v.height=b;const C=m===void 0?Math.max(1,M.length):Math.max(1,Math.floor((m-2*o+g)/(p+g)));let P=b;if(C<M.length){let v=o+(y?.height??0);for(let T=0;T<M.length;T+=C){const A=M.slice(T,T+C);for(const[R,I]of A.entries()){const L=o+R*(p+g)-I.x,$=v-I.y;I.x+=L;I.y+=$;for(const B of I.texts){B.x+=L;B.y+=$}for(const B of I.tasks){B.x+=L;B.y+=$;for(const F of B.texts){F.x+=L;F.y+=$}}}v+=b+g}P=v-g-o-(y?.height??0)}const E=Math.min(M.length,C);const k=Math.max(o*2+Math.max(0,E*p+Math.max(0,E-1)*g),(y?.width??0)+2*o);return{columns:M,visual:n,width:k,height:o*2+(y?.height??0)+P,...y?{title:on(y,k,o)}:{}}}function i$({positioned:e}){return{version:1,nodes:e.columns.flatMap(t=>t.tasks.map(n=>({id:n.id,parentId:t.id,x:xe(n.x),y:xe(n.y),w:xe(n.width),h:xe(n.height),shape:"rectangle",label:n.label,...bt(n.texts[0]?.block,n.texts[0]?.x??n.x,n.texts[0]?.y??n.y,Ut(e),"start")}))),edges:[],groups:e.columns.map(t=>({id:t.id,label:t.label,x:xe(t.x),y:xe(t.y),w:xe(t.width),h:xe(t.height),members:t.tasks.map(n=>n.id)})),bounds:{w:xe(e.width),h:xe(e.height)}}}function S6(e,{positioned:t,colors:n,resolved:i}){const r=Ue(i.renderOptions,void 0,i.styleFace);const o=Jr(n);const s=i.renderOptions.transparent??false;const a=[];if(t.title)a.push(e.text(En(t.title,r)));const l=(c,d,u,f)=>e.text({id:c,role:"label",owner:f,text:d.block.text,block:d.block,x:d.x,y:d.y,fontSize:d.block.fontSize,fontWeight:d.block.fontWeight,letterSpacing:d.block.letterSpacing,anchor:"start",paint:{fill:u}});for(const c of t.columns){const d=r.groupFillColor??"var(--_group-fill)",u=r.groupHeaderFillColor??"var(--_group-hdr)";const f=[e.shape({id:`${c.id}:surface`,role:"group",identity:false,owner:{id:c.id,role:"group"},geometry:{kind:"rect",x:c.x,y:c.y,width:c.width,height:c.height,rx:r.groupCornerRadius},paint:{fill:d,stroke:r.groupBorderColor??"var(--_node-stroke)",strokeWidth:String(r.groupLineWidth)}}),e.shape({id:`${c.id}:header`,role:"group-header",owner:{id:c.id,role:"group"},geometry:{kind:"rect",x:c.x,y:c.y,width:c.width,height:c.headerHeight,rx:r.groupCornerRadius},paint:{fill:u,stroke:"none"}})];const h=r.groupTextColor??o("var(--_text)",u);c.texts.forEach((p,g)=>f.push(l(`${c.id}:text-${g}`,p,h,{id:c.id,role:"group"})));for(const p of c.tasks){const g=r.nodeFillColor??"var(--_node-fill)",y=r.nodeTextColor??o("var(--_text)",g);const w=[e.shape({id:`${p.id}:surface`,role:"node",identity:false,owner:{id:p.id,role:"node"},geometry:{kind:"rect",x:p.x,y:p.y,width:p.width,height:p.height,rx:r.cornerRadius??5},paint:{fill:g,stroke:r.nodeBorderColor??"var(--_node-stroke)",strokeWidth:String(r.nodeLineWidth)}})];p.texts.forEach((M,b)=>w.push(l(`${p.id}:text-${b}`,M,y,{id:p.id,role:"node"})));const S=p.className?.split(/\s+/).filter(M=>/^[\w-]+$/.test(M)).join(" ");const x=p.ticketUrl&&i.renderOptions.security!=="strict"?` data-href="${Ye(p.ticketUrl)}" role="link" tabindex="0"`:"";f.push(e.group({id:p.id,role:"node",open:`<g data-id="${Ye(p.id)}" data-parent="${Ye(c.id)}"${S?` class="${Ye(S)}"`:""}${x}>`,close:"</g>",children:w.map(M=>({node:M,indent:2}))}))}const m=c.className?.split(/\s+/).filter(p=>/^[\w-]+$/.test(p)).join(" ");a.push(e.group({id:c.id,role:"group",open:`<g data-id="${Ye(c.id)}"${m?` class="${Ye(m)}"`:""}>`,close:"</g>",children:f.map(p=>({node:p,indent:2}))}))}return ls(e,"kanban",t,n,s,a)}var r$=gt(S6);var hbe={statementEnds:fL,configDiagnostics:t$,normalizeRequest:e=>({familyConfig:{visual:Sf(e.source.frontmatter)}}),layout:e=>ht(n$(Tn(Uw(Ma(e.source),e.source.accessibility,e.source),e.source.frontmatter),e.renderOptions,e.familyConfig?.visual??Sf(),e.styleFace)),projectPositioned:ut(i$),lowerScene:ft(r$)};var o$=e=>xt("requirement",e,{rect_fill:Br,text_color:Br,rect_border_color:Br,rect_border_size:Oa(0),rect_min_width:Jt,rect_min_height:Yt,rect_padding:Yt,line_height:Yt,fontSize:Jt,maxWidth:Jt,nodeSpacing:Yt,rankSpacing:Yt,useMaxWidth:lt,look:Br,theme:Br});var el=fr("requirement-arrow",{width:9,height:7},"end",{fill:"none",stroke:"var(--_arrow)",strokeWidth:"1"},"userSpaceOnUse");var qy=xr([el]);function s$(e,t={},n,i={}){kP(e);const r=It(n,"relationship",{},{includeFallback:false}),o=Ue(t,void 0,r?{...n,edge:{...n?.edge,...r}}:n),s=t.padding??32;const a=typeof i.maxWidth==="number"&&i.maxWidth>0?i.maxWidth:320;const l=(T,A,R=0,I=2e3)=>typeof i[T]==="number"&&Number.isFinite(i[T])&&i[T]>=R?Math.min(i[T],I):A;const c=l("rect_padding",16),d=i.rect_padding===void 0?n?.node?.paddingX??c:c,u=i.rect_padding===void 0?n?.node?.paddingY??c:c,f=l("rect_min_width",140,1),h=l("rect_min_height",0),m=l("line_height",0);const p={};for(const[T,A]of[["rect_fill","fill"],["text_color","color"],["rect_border_color","stroke"],["rect_border_size","stroke-width"]])if(typeof i[T]==="string"||T==="rect_border_size"&&typeof i[T]==="number"&&Number.isFinite(i[T]))p[A]=String(i[T]);Tt(p,"requirement config");const g=[...e.requirements.map(T=>({requirement:T,element:void 0})),...e.elements.map(T=>({requirement:void 0,element:T}))].map(({requirement:T,element:A})=>{const R=T??A,I=Tt({...p,...vn(R.cssStyles.join(","))},`style ${R.name}`);const L=Number.parseFloat(I["font-size"]??"")||l("fontSize",o.nodeLabelFontSize,1);const $=I["font-weight"]?.trim().toLowerCase(),B=$===void 0?void 0:$==="normal"?400:$==="bold"?700:Number($);if(B!==void 0&&(!Number.isFinite(B)||B<1||B>1e3))throw new Error(`style ${R.name}: font-weight must be normal, bold, or a number from 1 to 1000`);const F=Be(`<<${T?.type??"Element"}>>
27
+ ${R.name}`,{fontSize:L,fontWeight:B??o.nodeLabelFontWeight,maxWidth:a,transform:o.nodeTextTransform,letterSpacing:o.nodeLetterSpacing,fontFamily:t.font});const z=T?[["ID",T.requirementId],["Text",T.text],["Risk",T.risk],["Verification",T.verifyMethod]]:[["Type",A.type],["Doc Ref",A.docRef]];const _=F.height+Math.max(12,u*1.5);const H=Yd(z.filter(([,O])=>O).map(([O,N])=>{const G=Be(`${O}: ${N}`,{fontSize:L,fontWeight:B??400,maxWidth:a,transform:o.nodeTextTransform,letterSpacing:o.nodeLetterSpacing,fontFamily:t.font});return{label:O,block:G}}),{top:_+8,gap:9,minRowHeight:m,align:"start",trailingGap:true});const D=H.rows.map(({item:O,textY:N})=>({...O,y:N}));const j=Math.max(h,H.bottom+8),W=Math.max(f,F.width+d*2,H.width+d*2);return{id:R.name,requirement:T,element:A,x:0,y:0,width:W,height:j,header:F,rows:D,paddingX:d,headerHeight:_,style:I}});const y=new Map(g.map((T,A)=>[T.id,A]));const w=e.relations.map(T=>Be(`<<${T.type}>>`,{fontSize:o.edgeLabelFontSize,fontWeight:o.edgeLabelFontWeight,transform:o.edgeTextTransform,letterSpacing:o.edgeLetterSpacing}));for(const T of e.relations){if(!y.has(T.src)||!y.has(T.dst))throw new Error(`Requirement relation ${T.id} references an undeclared endpoint`)}const S=t.nodeSpacing??l("nodeSpacing",40,0,Infinity),x=t.layerSpacing??l("rankSpacing",72,0,Infinity);const M=e.relations.some(T=>T.type!=="contains")?qy(el.id,o.lineWidth,"end")+o.edgeBendRadius:0;const b=Qr(t,()=>{return ei("agentic",()=>Ua({nodes:g.map(T=>({id:T.id,width:T.width,height:T.height})),edges:e.relations.map((T,A)=>({source:y.get(T.src),target:y.get(T.dst),minSpan:1,label:{width:w[A].width+16,height:w[A].height+10}})),direction:e.direction,padding:s,nodeSpacing:S,layerSpacing:x,...M?{minimumTerminalLead:M}:{},edgeSpacing:Math.max(6,o.lineWidth+4)}))},()=>{const T=new Map(g.map(($,B)=>[$.id,`n${B}`]));const A=e.relations.map(($,B)=>({id:`e${B}`,sources:[T.get($.src)],targets:[T.get($.dst)],labels:[{text:w[B].text,width:w[B].width+16,height:w[B].height+10}]}));const R={id:"requirement-layout",layoutOptions:{"elk.algorithm":"layered","elk.direction":{TB:"DOWN",BT:"UP",LR:"RIGHT",RL:"LEFT"}[e.direction],"elk.edgeRouting":"ORTHOGONAL","elk.spacing.edgeNode":String(M),"elk.layered.spacing.edgeNodeBetweenLayers":String(M),"elk.spacing.nodeNode":String(S),"elk.layered.spacing.nodeNodeBetweenLayers":String(x),"elk.padding":`[top=${s},left=${s},bottom=${s},right=${s}]`},children:g.map($=>({id:T.get($.id),width:$.width,height:$.height})),edges:A};const I=g.length?qa(R):{...R,width:s*2,height:s*2};const L=g.map(()=>({x:0,y:0}));for(const $ of I.children??[])L[Number($.id.slice(1))]={x:$.x??0,y:$.y??0};return{width:I.width??0,height:I.height??s*2,nodes:L,edges:e.relations.map(($,B)=>{const F=I.edges?.[B],z=F?.labels?.[0];return{points:Qs((F?.sections??[]).flatMap(_=>[_.startPoint,..._.bendPoints??[],_.endPoint])),...z?.x!==void 0?{labelPosition:{x:z.x+(z.width??0)/2,y:(z.y??0)+(z.height??0)/2}}:{}}})}});const C=tn(e.title,o),P=C?.height??0;const E=Math.max(b.width??0,(C?.width??0)+s*2,s*2),k=(b.height??s*2)+P;for(const[T,A]of b.nodes.entries()){const R=g[T];R.x=A.x+(E-b.width)/2;R.y=A.y+P}const v=e.relations.map((T,A)=>{const R=b.edges[A];const I=(R?.points??[]).map(z=>({x:z.x+(E-b.width)/2,y:z.y+P}));if(I.length<2)throw new Error(`No route for requirement relation ${T.id}`);const L=w[A],$=R?.labelPosition,B=I[Math.floor(I.length/2)];const F=$?{x:$.x+(E-b.width)/2,y:$.y+P}:B;return{...T,points:I,label:L,labelPosition:F}});return{model:e,width:E,height:k,nodes:g,edges:v,style:o,...C?{title:on(C,E,s)}:{}}}var IM={id:"requirement-contains",shape:"circle",size:{width:12,height:12},ref:{x:0,y:6},orient:"auto",units:"userSpaceOnUse",geometry:{kind:"compound",children:[{kind:"circle",cx:6,cy:6,r:5},{kind:"path",d:"M2 6H10M6 2V10"}]},paint:{fill:"var(--bg)",stroke:"var(--_arrow)",strokeWidth:"1"}};function w6(e,t){const{positioned:n,colors:i}=t,r=t.resolved.renderOptions.transparent??false,o=i.font??"Inter",s=[],a=n.style.edgeStrokeColor?{...el,paint:{...el.paint,stroke:n.style.edgeStrokeColor}}:el,l=n.style.edgeStrokeColor?{...IM,paint:{...IM.paint,stroke:n.style.edgeStrokeColor}}:IM,c=[a,l];const d=Jr(i);let u=Ot(n.width,n.height,i,r);if(n.model.accessibilityTitle)u+=`<title>${At(n.model.accessibilityTitle)}</title>`;if(n.model.accessibilityDescription)u+=`<desc>${At(n.model.accessibilityDescription)}</desc>`;u+=Dt(o,false,void 0,i.embedFontImport);s.push(e.documentOpen({id:"prelude",width:n.width,height:n.height,colors:i,transparent:r,font:o,hasMonoFont:false},u),e.definitions({id:"defs",markerResources:c},`<defs>${mi(c)}</defs>`));for(const f of n.nodes){const h=f.style.fill??n.style.nodeFillColor??"var(--_node-fill)",m=f.style.stroke??n.style.nodeBorderColor??"var(--_node-stroke)",p=f.style.color??n.style.nodeTextColor??d("var(--_text)",h);const g=[{indent:2,node:e.shape({id:`frame:${f.id}`,role:"node",identity:false,owner:{id:f.id,role:"node"},geometry:{kind:"rect",x:f.x,y:f.y,width:f.width,height:f.height,rx:n.style.cornerRadius},paint:{fill:h,stroke:m,strokeWidth:f.style["stroke-width"]??String(n.style.nodeLineWidth),...f.style["stroke-dasharray"]!==void 0?{strokeDasharray:f.style["stroke-dasharray"]}:{}}})},{indent:2,node:e.shape({id:`separator:${f.id}`,role:"chrome",geometry:{kind:"line",x1:f.x,y1:f.y+f.headerHeight,x2:f.x+f.width,y2:f.y+f.headerHeight},paint:{stroke:m,strokeWidth:"0.75"}})},{indent:2,node:e.text({id:`header:${f.id}`,role:"label",owner:{id:f.id,role:"node"},text:f.header.text,block:f.header,x:f.x+f.width/2,y:f.y+f.headerHeight/2,fontSize:f.header.fontSize,anchor:"middle",paint:{fill:p}})},...f.rows.map((w,S)=>({indent:2,node:e.text({id:`field:${f.id}:${S}`,role:"attribute",owner:{id:f.id,role:"node"},text:w.block.text,block:w.block,x:f.x+f.paddingX,y:f.y+w.y,fontSize:w.block.fontSize,anchor:"start",paint:{fill:p}})}))];const y=["requirement-node",...(f.requirement??f.element).classes.filter(w=>/^[\w-]+$/.test(w))];s.push(e.group({id:`node:${f.id}`,role:"node",open:`<g class="${Ye(y.join(" "))}" data-id="${Ye(f.id)}">`,close:"</g>",children:g}))}for(const f of n.edges){const h=n.style.edgeBendRadius>0&&f.points.length>2?qn(f.points,n.style.edgeBendRadius,{terminalClearance:{end:f.type==="contains"?0:qy(el.id,n.style.lineWidth,"end")}}):void 0;s.push(e.connector({id:f.id,role:"relationship",geometry:h?.geometry??{kind:"polyline",points:f.points},lineStyle:f.type==="contains"?"solid":"dashed",paint:{stroke:n.style.edgeStrokeColor??"var(--_line)",strokeWidth:String(n.style.lineWidth),fill:"none",...f.type!=="contains"?{strokeDasharray:"6 4"}:{}},endpoints:{from:f.src,to:f.dst},relationship:{kind:f.type,direction:"forward"},markers:f.type==="contains"?{start:l}:{end:a},labels:[{text:f.label.text,anchor:f.labelPosition}],route:{ownership:"layout",bendRadius:n.style.edgeBendRadius,labelAnchors:[f.labelPosition],...h?{contours:h.contours}:{}}}))}for(const f of n.edges){const h=f.label,m=f.labelPosition;s.push(e.group({id:`edge-label:${f.id}`,role:"edge-label",open:'<g class="requirement-edge-label">',close:"</g>",children:[{indent:2,node:e.shape({id:`label-bg:${f.id}`,role:"chrome",owner:{id:f.id,role:"relationship"},geometry:{kind:"rect",x:m.x-h.width/2-6,y:m.y-h.height/2-4,width:h.width+12,height:h.height+8},paint:{fill:"var(--bg)",stroke:"none"}})},{indent:2,node:e.text({id:`label:${f.id}`,role:"edge-label",owner:{id:f.id,role:"relationship"},text:h.text,block:h,x:m.x,y:m.y,fontSize:h.fontSize,anchor:"middle",paint:{fill:n.style.edgeTextColor??"var(--_text)"}})}]}))}if(n.title)s.push(e.text(En(n.title,n.style)));s.push(e.documentClose());return{family:"requirement",width:n.width,height:n.height,colors:i,transparent:r,parts:s}}function a$({positioned:e}){const t=e.nodes.flatMap(n=>n.rows.map((i,r)=>({id:`field:${n.id}:${r}`,text:i.block.text,bounds:qt(i.block,n.x+n.paddingX,n.y+i.y,"start"),container:ln(n)})));if(e.title)t.push({id:"title",text:e.title.text,bounds:qt(e.title.block,e.title.x,e.title.y),container:ln(Ut(e))});return{version:1,bounds:{w:xe(e.width),h:xe(e.height)},nodes:e.nodes.map(n=>({id:n.id,x:xe(n.x),y:xe(n.y),w:xe(n.width),h:xe(n.height),shape:"rectangle",label:n.header.text,role:"box",...bt(n.header,n.x+n.width/2,n.y+n.headerHeight/2,n)})),edges:e.edges.map(n=>({id:n.id,from:n.src,to:n.dst,path:n.points.map(i=>[xe(i.x),xe(i.y)]),label:{x:xe(n.labelPosition.x),y:xe(n.labelPosition.y),text:n.label.text,bounds:qt(n.label,n.labelPosition.x,n.labelPosition.y)}})),groups:[],labels:t}}var l$=gt(w6);var Qbe={configDiagnostics:o$,statementEnds:uL,layout:e=>{const t=RF(Ma(e.source));t.title??=Nr(e.source.frontmatter);t.accessibilityTitle=e.source.accessibility.title??t.accessibilityTitle;t.accessibilityDescription=e.source.accessibility.descr??t.accessibilityDescription;return ht(s$(t,e.renderOptions,e.styleFace,e.source.config.requirement))},projectPositioned:ut(a$),lowerScene:ft(l$)};function c$(e){const t=zt(typeof e==="string"?e.split(/\r?\n/):e);yr(t);const n=t.familyLines;const i=n.findIndex(s=>s.trim()&&!s.trim().startsWith("%%"));if(!/^treemap(?:-beta)?\s*$/i.test(Ht(n[i]?.trim()??"")))throw new Error("Treemap source must start with treemap");const r={kind:"treemap",nodes:[],classDefs:Object.create(null),...Ar(Yo(t.accessibility))};const o=[];for(let s=i+1;s<n.length;s++){const a=n[s];const l=Ht(a).trim();if(!l)continue;Ge("treemap","statement",a,{line:s+1,unit:"normalized"});const c=/^title(?:\s+(.*))?$/i.exec(l);if(c){r.title=So(jo(c[1]??""),"\r\n");he("treemap","set-title",r.title);continue}const d=/^classDef\s+([A-Za-z_]\w*)\s+(.+?);?$/.exec(l);if(d){const m=Tt(vn(d[2]),`classDef ${d[1]}`);r.classDefs[d[1]]={...r.classDefs[d[1]]??{},...m};he("treemap","define-class",{name:d[1],style:m});continue}const u=a.match(/^[\t ]*/)?.[0].length??0;let f=u;let h=l;while(h){const m=/^(?:"([^"]*)"|'([^']*)')(?:\s*[:,]\s*([0-9_.,]+))?(?:\s*:::\s*([A-Za-z_]\w*))?/.exec(h);if(!m)throw new Error(`Invalid Treemap statement at line ${s+1}: ${h}`);Ve("nodes",r.nodes.length+1);while(o.length&&o.at(-1).indent>=f)o.pop();const p=o.at(-1)?.node.id;const g=m[3]===void 0?void 0:Number(m[3].replace(/[,_]/g,""));Ve("nesting",o.length+(g===void 0?1:0));if(g!==void 0&&(!Number.isFinite(g)||g<0))throw new Error(`Invalid Treemap value at line ${s+1}`);const y={id:`treemap-${r.nodes.length}`,label:So(jo(m[1]??m[2]),"\r\n"),...p?{parentId:p}:{},...g===void 0?{}:{value:g},...m[4]?{className:m[4]}:{}};r.nodes.push(y);if(re("treemap"))he("treemap","add-node",y,{line:s+1,column:u+l.length-h.length+1,unit:"normalized"});if(g===void 0)o.push({indent:f,node:y});const w=h.slice(m[0].length);f=w.match(/^[\t ]*/)?.[0].length??0;h=w.slice(f)}}return r}import{format as M6}from"d3-format";function FM(e={}){const t=(n,i,r=0)=>{const o=e[n];if(o===void 0)return i;if(typeof o!=="number"||!Number.isFinite(o)||o<r||o>1e4)return i;return o};return{width:t("nodeWidth",96,1)*10,height:t("nodeHeight",50,1)*10,padding:t("padding",10),diagramPadding:t("diagramPadding",16),showValues:e.showValues!==false,labelFontSize:t("labelFontSize",14,1),valueFontSize:t("valueFontSize",12,1),borderWidth:t("borderWidth",1),valueFormat:typeof e.valueFormat==="string"?e.valueFormat:","}}function k6(e){if(e==="$0,0")e="$,";try{return M6(e)}catch{throw new Error(`Invalid treemap.valueFormat ${JSON.stringify(e)}`)}}function C6(e,t){const n=e.map((f,h)=>({...f,index:h})).filter(f=>f.value>0).sort((f,h)=>h.value-f.value||f.index-h.index);const i=n.reduce((f,h)=>f+h.value,0);if(!Number.isFinite(i))throw new Error("Treemap total exceeds the finite numeric range");const r=i>0?t.width*t.height/i:0;const o=n.map(f=>({...f,area:f.value*r}));const s=[];let{x:a,y:l,width:c,height:d}=t;let u=0;while(u<o.length&&c>0&&d>0){const f=Math.min(c,d);let h=u+1;let m=o[u].area;let p=m;const g=m;const y=(b,C)=>Math.max(f*f*g/(b*b),b*b/(f*f*C));let w=y(m,p);while(h<o.length){const b=o[h].area;const C=y(m+b,Math.min(p,b));if(C>w)break;w=C;m+=b;p=Math.min(p,b);h++}const S=c>=d;const x=S?Math.min(c,m/d):Math.min(d,m/c);let M=S?l:a;for(let b=u;b<h;b++){const C=o[b];const P=b===h-1?(S?l+d:a+c)-M:C.area/x;s.push({id:C.id,value:C.value,x:S?a:M,y:S?M:l,width:S?x:P,height:S?P:x});M+=P}if(S){a+=x;c=Math.max(0,c-x)}else{l+=x;d=Math.max(0,d-x)}u=h}for(;u<o.length;u++){const f=o[u];s.push({id:f.id,value:f.value,x:t.x,y:t.y,width:0,height:0})}for(const f of e)if(f.value<=0)s.push({...f,x:t.x,y:t.y,width:0,height:0});return s}function d$(e,t={},n=FM(),i){Ly(e.nodes,S=>S.value===void 0);const r=Ue(t,{...zi,nodeLabelFontSize:n.labelFontSize,groupHeaderFontSize:n.labelFontSize,groupHeaderFontWeight:zi.nodeLabelFontWeight},i);const o=ra(e.nodes);const s=new Map;for(const S of[...e.nodes].reverse())s.set(S.id,S.value??(o.get(S.id)??[]).reduce((x,M)=>x+(s.get(M.id)??0),0));const a=tn(e.title,r);const l=n.diagramPadding;const c=Math.max(n.width,(a?.width??0)+l*2);const d=n.height+(a?.height??0)+l*2;const u=[];const f=[];let h;const m=o.get(void 0)??[];const p=new Map(m.map((S,x)=>[S.id,x]));const g=new Map(e.nodes.map(S=>[S.id,S]));const y=[{items:m,box:{x:l,y:l+(a?.height??0),width:c-l*2,height:n.height},depth:0}];while(y.length){const S=y.pop();const x=C6(S.items.map(M=>({id:M.id,value:s.get(M.id)??0})),S.box);for(const M of x){const b=g.get(M.id);const C=S.category??p.get(b.id)??0;const P={node:b,total:M.value,x:M.x,y:M.y,width:M.width,height:M.height,depth:S.depth,category:C};const E=o.get(b.id);let k=0;if(M.width>0&&M.height>0){const v=b.value===void 0,T=v?i?.group:i?.node,A=T?.paddingX??6,R=T?.paddingY??6,I=Math.max(1,M.width-A*2),L=v?r.groupFont??t.font:t.font,$=v?r.groupLetterSpacing:r.nodeLetterSpacing,B=v?r.groupTextTransform:r.nodeTextTransform;const F=Be(b.label,{fontSize:v?r.groupHeaderFontSize:r.nodeLabelFontSize,fontWeight:v?r.groupHeaderFontWeight:r.nodeLabelFontWeight,letterSpacing:$,transform:B,fontFamily:L,maxWidth:I});const z=n.showValues?Be((h??=k6(n.valueFormat))(M.value),{fontSize:T?.fontSize??i?.text?.fontSize??n.valueFontSize,fontWeight:T?.fontWeight??i?.text?.fontWeight??400,letterSpacing:$,transform:B,fontFamily:L,maxWidth:I}):void 0;k=F.height+(z?z.height+4:0)+R*2;if(F.width<=M.width-A*2&&k<=M.height){P.label=F;P.valueLabel=z;P.labelY=M.y+R+F.height/2;if(z)P.valueY=M.y+R+4+F.height+z.height/2;if(v&&r.groupHeaderFillColor!==void 0)P.headerHeight=k}else f.push(b.label)}else f.push(b.label);u.push(P);if(E?.length){const v=P.label?k:0;const T=Math.min(n.padding,M.width/4,Math.max(0,M.height-v)/4);const A=i?.group?.paddingX===void 0?T:Math.min(i.group.paddingX,M.width/4),R=i?.group?.paddingY===void 0?T:Math.min(i.group.paddingY,Math.max(0,M.height-v)/4);y.push({items:E,box:{x:M.x+A,y:M.y+v+R,width:Math.max(0,M.width-2*A),height:Math.max(0,M.height-v-2*R)},depth:S.depth+1,category:C})}}}const w=new Map(e.nodes.map((S,x)=>[S.id,x]));u.sort((S,x)=>w.get(S.node.id)-w.get(x.node.id));return{width:c,height:d,body:e,cells:u,config:n,hiddenLabels:f,options:t,...a?{title:on(a,c,l)}:{}}}var oa="#3b82f6";function Xy(e){const[t,n,i]=v1(e);const r=t/255;const o=n/255;const s=i/255;const a=Math.max(r,o,s);const l=Math.min(r,o,s);const c=(a+l)/2;if(a===l)return[0,0,c*100];const d=a-l;const u=c>.5?d/(2-a-l):d/(a+l);let f;if(a===r)f=((o-s)/d+(o<s?6:0))/6;else if(a===o)f=((s-r)/d+2)/6;else f=((r-o)/d+4)/6;return[f*360,u*100,c*100]}function NM(e,t,n){const i=t/100;const r=n/100;const o=(1-Math.abs(2*r-1))*i;const s=o*(1-Math.abs(e/60%2-1));const a=r-o/2;let l,c,d;if(e<60){l=o;c=s;d=0}else if(e<120){l=s;c=o;d=0}else if(e<180){l=0;c=o;d=s}else if(e<240){l=0;c=s;d=o}else if(e<300){l=s;c=0;d=o}else{l=o;c=0;d=s}const u=f=>Math.round((f+a)*255).toString(16).padStart(2,"0");return`#${u(l)}${u(c)}${u(d)}`}function _h(e){return A1(e)}function $M(e){return Xy(e)[2]<50}function u$(e,t,n){if(e===0)return t;const i=_h(t)?t:oa;const r=n&&_h(n)?n:void 0;const[o,s]=Xy(i);const a=Math.max(55,Math.min(85,s));const l=Math.ceil(e/2);const c=e%2===1;const d=r&&$M(r)?!c:c;const u=d?Math.max(25,48-l*13):Math.min(78,55+l*11);const f=(d?-8:12)*l;const h=((o+f)%360+360)%360;return NM(h,a,u)}function _M(e){return e<=.0031308?12.92*e:1.055*e**(1/2.4)-.055}function Er(e){const t=fl(e);if(!t)return null;const n=om(t[0]/255);const i=om(t[1]/255);const r=om(t[2]/255);const o=.4122214708*n+.5363325363*i+.0514459929*r;const s=.2119034982*n+.6806995451*i+.1073969566*r;const a=.0883024619*n+.2817188376*i+.6299787005*r;const l=Math.cbrt(o);const c=Math.cbrt(s);const d=Math.cbrt(a);return{L:.2104542553*l+.793617785*c-.0040720468*d,a:1.9779984951*l-2.428592205*c+.4505937099*d,b:.0259040371*l+.7827717662*c-.808675766*d}}function P6(e){const t=e.L+.3963377774*e.a+.2158037573*e.b;const n=e.L-.1055613458*e.a-.0638541728*e.b;const i=e.L-.0894841775*e.a-1.291485548*e.b;const r=t*t*t;const o=n*n*n;const s=i*i*i;const a=4.0767416621*r-3.3077115913*o+.2309699292*s;const l=-1.2684380046*r+2.6097574011*o-.3413193965*s;const c=-.0041960863*r-.7034186147*o+1.707614701*s;return Yn(_M(a)*255,_M(l)*255,_M(c)*255)}function E6(e){const t=Math.hypot(e.a,e.b);const n=(Math.atan2(e.b,e.a)*180/Math.PI+360)%360;return{L:e.L,C:t,h:n}}function R6(e){const t=e.h*Math.PI/180;return{L:e.L,a:e.C*Math.cos(t),b:e.C*Math.sin(t)}}function Cc(e){return P6(R6(e))}function Ud(e){const t=Er(e);return t?E6(t):null}function OM(e,t){const n=Er(e);const i=Er(t);if(!n||!i)return null;return Math.hypot(n.L-i.L,n.a-i.a,n.b-i.b)}function Dh(e){let t=Infinity;for(let n=0;n<e.length;n++){for(let i=n+1;i<e.length;i++){const r=OM(e[n],e[i]);if(r!==null&&r<t)t=r}}return t}var DM=2.4;var v6=.2126729;var T6=.7151522;var L6=.072175;var f$=.022;var A6=1.414;var I6=1.14;var F6=1.14;var N6=.027;var $6=.027;var _6=5e-4;var h$=.1;function m$(e){const t=fl(e);if(!t)return null;const n=v6*(t[0]/255)**DM+T6*(t[1]/255)**DM+L6*(t[2]/255)**DM;return n<f$?n+(f$-n)**A6:n}function D6(e,t){const n=m$(e);const i=m$(t);if(n===null||i===null)return null;if(Math.abs(i-n)<_6)return 0;let r;let o;if(i>n){r=(i**.56-n**.57)*I6;o=r<h$?0:r-N6}else{r=(i**.65-n**.62)*F6;o=r>-h$?0:r+$6}return o*100}function tl(e,t){const n=D6(e,t);return n===null?null:Math.abs(n)}var O6=6;var B6=1.25;var W6=15;var nl=.1;var g$=24;var p$=264;var z6=.11;var BM=.16;function Zi(e,t={}){return G6(e,t)}function G6(e,t,n){const i=Vd(t.labelInk);let r;const o=i===void 0?void 0:()=>r??=HM(Vd(t.bg),n,i);if(e<=O6){const l=t.accent??oa;const c=Array.from({length:Math.max(0,e)},(d,u)=>u$(u,l,t.bg));return H6(c,t.bg,n,i,o)}const s=Vd(t.bg);const a=Vd(t.accent,s)??oa;return j6(e,a,s,n,i,o)}function H6(e,t,n,i,r){const o=Vd(t);const s=e.map(u=>Vd(u,o));if(s.some(u=>u===void 0))return e;const a=s;const l=((o===void 0?null:Er(o))?.L??1)<.55;const c=a.map(u=>{if(cs(u,o,i))return u;const f=Ud(u);return f?zM(f,o,l,n,i,r):u});const d=c.length>1?x$(c,o,l,n,i,r):c;return d.map((u,f)=>u===a[f]?e[f]:u)}function Vd(e,t){if(e===void 0)return void 0;const n=Kt(e);if(!n)return void 0;if(n[3]===1)return Yn(n[0],n[1],n[2]);if(t===void 0)return void 0;const i=Kt(t);if(!i||i[3]!==1)return void 0;return Yn(n[0]*n[3]+i[0]*(1-n[3]),n[1]*n[3]+i[1]*(1-n[3]),n[2]*n[3]+i[2]*(1-n[3]))}function j6(e,t,n,i,r,o){const s=Ud(t)??{L:.6,C:BM,h:p$};const a=s.C<.03;const l=a?p$:s.h;const c=Math.max(z6,Math.min(BM,a?BM:s.C));const d=((n===void 0?null:Er(n))?.L??1)<.55;const u=d?[.74,.6]:[.56,.7];const f=360/e;const h=Array.from({length:e},(m,p)=>{if(p===0&&cs(t,n,r))return t;const g=p===0?l:((l+p*f)%360+360)%360;const y=p===0?s.L:u[p%2];return zM({L:y,C:c,h:g},n,d,i,r,o)});return e<=g$?x$(h,n,d,i,r,o):U6(h,n,d,i,r,o)}function cs(e,t,n){if(n!==void 0&&(bu(e,n)??0)<$c)return false;if(t===void 0)return true;const i=bu(e,t);const r=tl(e,t);return i!==null&&r!==null&&i>=B6&&r>=W6}function zM(e,t,n,i,r,o){if(i)i.candidateEvaluations++;const s=Cc(e);if(cs(s,t,r))return s;const a=(t===void 0?void 0:Er(t))?.L??(n?0:1);const l=e.L>=a?1:-1;for(let d=1;d<=24;d++){const u=d*.04;for(const f of[l,-l]){if(i)i.candidateEvaluations++;const h=Cc({...e,L:Kd(e.L+f*u)});if(cs(h,t,r))return h}}const c=["#000000","#ffffff"].filter(d=>cs(d,t,r));if(c.length>0){return c.sort((d,u)=>t===void 0?0:(tl(u,t)??0)-(tl(d,t)??0))[0]}if(r!==void 0){const d=Er(s);let u;let f=Infinity;for(const h of o?.()??HM(t,i,r)){if(i){i.candidateEvaluations++;if(d)i.pairDistanceChecks++}const m=d?b$(h.lab,d):0;if(m<f){u=h;f=m}}if(u)return u.hex;y$()}return s}function y$(){throw new Error("Cannot derive categorical fills within bounded search with readable label ink, page visibility and distinct peer colors; select a different textColor or explicit fillColor")}function GM(e,t,n){const i=t===void 0?null:Kt(t);if(!i||i[3]!==1)return e;const r=Yn(i[0],i[1],i[2]);const o=Kt(e);if(!o||o[3]!==1)return e;const s=Yn(o[0],o[1],o[2]);const a=u=>tr(u,r,n);if(cs(a(s),r))return e;const l=Ud(s);if(!l)return e;const c=Er(r)?.L??1;const d=l.L>=c?1:-1;for(let u=1;u<=24;u++){const f=u*.04;for(const h of[d,-d]){const m=Cc({...l,L:Kd(l.L+h*f)});if(cs(a(m),r))return m}}return["#000000","#ffffff"].sort((u,f)=>(tl(a(f),r)??0)-(tl(a(u),r)??0))[0]}function x$(e,t,n,i,r,o){const s=[];for(let l=0;l<e.length;l++){const c=e[l];const d=l===0&&cs(c,t,r);s.push(d||WM(c,s,i)>=nl?c:Y6(c,s,t,n,i,r))}if(i)i.pairDistanceChecks+=s.length*(s.length-1)/2;if(Dh(s)>=nl)return s;const a=X6(s,t,i,r,o);if(r!==void 0&&Uy(a,i)<nl)y$();return a}function Uy(e,t){if(t)t.pairDistanceChecks+=e.length*(e.length-1)/2;return Dh(e)}function WM(e,t,n){let i=Infinity;for(const r of t){if(n)n.pairDistanceChecks++;const o=OM(e,r);if(o!==null&&o<i)i=o}return i}var Kd=e=>Math.max(.08,Math.min(.97,e));function Y6(e,t,n,i,r,o){const s=Ud(e);if(!s)return e;let a=e;let l=WM(e,t,r);for(let c=1;c<=12;c++){const d=c*.03;const u=c*7;const f=[{...s,L:Kd(s.L+d)},{...s,L:Kd(s.L-d)},{...s,h:(s.h+u)%360},{...s,h:(s.h-u+360)%360},{...s,L:Kd(i?s.L+d:s.L-d),h:(s.h+u)%360}];for(const h of f){if(r)r.candidateEvaluations++;const m=Cc(h);if(!cs(m,n,o))continue;const p=WM(m,t,r);if(p>=nl)return m;if(p>l){l=p;a=m}}}return a}function HM(e,t,n){const i=new Map;const r=l=>{if(t)t.candidateEvaluations++;if(i.has(l)||!cs(l,e,n))return;const c=Er(l);if(c)i.set(l,{hex:l,lab:c})};r("#000000");r("#ffffff");const o=n!==void 0;const s=o?44:22;const a=o?Array.from({length:14},(l,c)=>(c+1)*.02):[.04,.08,.12,.16,.2,.24,.28];for(let l=0;l<=s;l++){const c=.08+l*(o?.02:.04);r(Cc({L:c,C:0,h:0}));for(const d of a){for(let u=0;u<360;u+=o?5:10)r(Cc({L:c,C:d,h:u}))}}if(n!==void 0){for(let l=0;l<=255;l+=17){for(let c=0;c<=255;c+=17){for(let d=0;d<=255;d+=17)r(Yn(l,c,d))}}}return[...i.values()]}var q6=(e,t)=>Math.hypot(e.L-t.L,e.a-t.a,e.b-t.b);var b$=(e,t)=>{const n=e.L-t.L,i=e.a-t.a,r=e.b-t.b;return Math.sqrt(n*n+i*i+r*r)};function X6(e,t,n,i,r){if(e.length<2)return e;const o=i===void 0?q6:b$;const s=r?.()??HM(t,n,i);const a=Er(e[0]);if(!a)return e;const l={hex:e[0],lab:a};const c=i===void 0?void 0:Float64Array.from(s,w=>{if(n)n.pairDistanceChecks++;return o(w.lab,l.lab)});const d=w=>{const S=w?[l,w]:[l];const x=new Set(S.map(C=>C.hex.toLowerCase()));const M=c?.slice();const b=C=>{if(!M)return;for(let P=0;P<s.length;P++){if(n)n.pairDistanceChecks++;M[P]=Math.min(M[P],o(s[P].lab,C.lab))}};if(w)b(w);while(S.length<e.length){let C;let P=-1;let E=Infinity;const k=Er(e[S.length]);for(let v=0;v<s.length;v++){const T=s[v];if(x.has(T.hex.toLowerCase()))continue;if(n)n.candidateEvaluations++;let A=M?.[v]??Infinity;if(!M){for(const I of S){if(n)n.pairDistanceChecks++;A=Math.min(A,o(T.lab,I.lab))}}if(k&&i!==void 0&&n)n.pairDistanceChecks++;const R=k?o(T.lab,k):0;if(A>P+1e-12||Math.abs(A-P)<=1e-12&&R<E){C=T;P=A;E=R}}if(!C)return e;S.push(C);x.add(C.hex.toLowerCase());b(C)}return S.map(C=>C.hex)};const u=d();if(i===void 0)return u;let f=Uy(u,n);if(f>=nl)return u;let h=u;for(const w of u.slice(2)){const S=Er(w);if(!S)continue;if(n)n.pairDistanceChecks++;if(o(l.lab,S)<nl)continue;const x=d({hex:w,lab:S});const M=Uy(x,n);if(M>=nl)return x;if(M>f){h=x;f=M}}const m=h.map(w=>({hex:w,lab:Er(w)}));const p=m.length;const g=new Float64Array(s.length*p);const y=w=>{for(let S=0;S<s.length;S++){if(n)n.pairDistanceChecks++;g[S*p+w]=o(s[S].lab,m[w].lab)}};for(let w=0;w<p;w++)y(w);for(let w=0;w<g$;w++){let S=false;for(let M=1;M<p;M++){let b=Infinity;for(let P=0;P<p;P++)if(P!==M){if(n)n.pairDistanceChecks++;b=Math.min(b,o(m[M].lab,m[P].lab))}let C;for(let P=0;P<s.length;P++){if(n)n.candidateEvaluations++;let E=Infinity;for(let k=0;k<p;k++)if(k!==M){E=Math.min(E,g[P*p+k]);if(E<=b+1e-12)break}if(E>b+1e-12){b=E;C=s[P]}}if(C){m[M]=C;y(M);S=true}}const x=m.map(M=>M.hex);if(Uy(x,n)>=nl)return x;if(!S)break}return m.map(w=>w.hex)}function U6(e,t,n,i,r,o){const s=new Set;return e.map((a,l)=>{if(i)i.tailItems++;if(!s.has(a.toLowerCase())){s.add(a.toLowerCase());return a}const c=Ud(a);if(c){for(let d=1;d<=24;d++){if(i)i.candidateEvaluations++;const u=zM({...c,L:Kd(c.L+(d%2===0?1:-1)*Math.ceil(d/2)*.008),h:(c.h+d*137.508+l*.01)%360},t,n,i,r,o);if(!s.has(u.toLowerCase())){s.add(u.toLowerCase());return u}}}return a})}function V6(e,{positioned:t,colors:n,resolved:i}){const r=Ue(i.renderOptions,{...zi,nodeLabelFontSize:t.config.labelFontSize},i.styleFace);const o=t.body.nodes.filter(w=>!w.parentId).length,s={accent:n.accent,bg:n.bg},a=Zi(o,s);const l=[];const c=new Map;const d=Jr(n);const u=new Map,f=(i.paintBackendId==="backend:rough"||i.paintBackendId==="backend:hybrid")&&K1("label").textHalo,h=f?Kt(_n("var(--bg)",n)??n.bg):void 0;const m=w=>{if(w===void 0)return a;const S=u.get(w);if(S)return S;const x=Kt(_n(w,n)??w);const M=x?.[3]===1?Yn(x[0],x[1],x[2]):void 0,b=M!==void 0&&h?.[3]===1&&T1(M,Yn(h[0],h[1],h[2]))>=$c,C=M!==void 0&&!b?Zi(o,{...s,labelInk:M}):a;u.set(w,C);return C};const p=ra(t.body.nodes);const g=t.cells.filter(w=>!w.node.parentId).reduce((w,S)=>w+S.total,0);if(t.title)l.push(e.text(En(t.title,r)));for(const w of t.cells){if(w.width<=0||w.height<=0){c.set(w.node.id,[]);continue}const S=w.node.value===void 0,x={value:g>0?w.total/g:0,category:String(w.category)},M=It(i.styleFace,"bar",x,{includeFallback:false});const b=w.node.className?t.body.classDefs[w.node.className]:void 0;const C=S?r.groupFillColor:r.nodeFillColor,P=S?r.groupTextColor:r.nodeTextColor,E=b?.color??P,k=S&&w.headerHeight?b?.fill??r.groupHeaderFillColor:void 0,v=b?.fill??M?.fillColor??C,T=v===void 0&&k===void 0&&b?.color===void 0?m(P):a,A=v??T[w.category]??"var(--_node-fill)",R=b?.stroke??M?.strokeColor??M?.borderColor??(S?r.groupBorderColor:r.nodeBorderColor)??"var(--bg)",I=b?.["stroke-width"]??String(M?.lineWidth??(S?i.styleFace?.group?.lineWidth:i.styleFace?.node?.lineWidth)??t.config.borderWidth),L=Math.min((S?r.groupCornerRadius:r.cornerRadius)??0,w.width/2,w.height/2,k?w.headerHeight/2:Infinity);const $=k??A;const B=E??d("var(--_text)",$,Boolean(b?.fill||M?.fillColor||k||!C));const F={id:w.node.id,role:S?"group":"node"};const z=[];if(w.width>0&&w.height>0)z.push(e.shape({id:`cell:${w.node.id}`,role:"bar",owner:F,geometry:{kind:"rect",x:w.x,y:w.y,width:w.width,height:w.height,...L>0?{rx:L,ry:L}:{}},paint:{fill:A,stroke:R,strokeWidth:I},channels:x}));if(k&&w.width>0&&w.height>0){const _=Math.min((Number.parseFloat(I)||0)/2,w.width/2,w.headerHeight/2),H=w.x+_,D=w.y+_,j=w.width-_*2,W=w.headerHeight-_,O=Math.max(0,L-_);if(j>0&&W>0)z.push(e.shape({id:`header:${w.node.id}`,role:"chrome",owner:F,geometry:O>0?{kind:"path",d:`M${H+O} ${D}H${H+j-O}Q${H+j} ${D} ${H+j} ${D+O}V${D+W}H${H}V${D+O}Q${H} ${D} ${H+O} ${D}Z`}:{kind:"rect",x:H,y:D,width:j,height:W},paint:{fill:k,stroke:"none"}}))}if(w.label)z.push(e.text({id:`label:${w.node.id}`,role:"label",owner:F,text:w.label.text,block:w.label,x:w.x+w.width/2,y:w.labelY,fontSize:w.label.fontSize,fontWeight:w.label.fontWeight,anchor:"middle",paint:{fill:B}}));if(w.valueLabel)z.push(e.text({id:`value:${w.node.id}`,role:"label",owner:F,text:w.valueLabel.text,block:w.valueLabel,x:w.x+w.width/2,y:w.valueY,fontSize:w.valueLabel.fontSize,fontWeight:w.valueLabel.fontWeight,anchor:"middle",paint:{fill:B}}));c.set(w.node.id,z)}const y=new Map;for(const w of[...t.cells].reverse()){const S=c.get(w.node.id);for(const b of p.get(w.node.id)??[]){const C=y.get(b.id);if(C)S.push(C)}const x=w.node.value===void 0,M=!w.label?Ye(`${w.node.label}: ${w.total}`):void 0;y.set(w.node.id,e.group({id:w.node.id,role:x?"group":"node",open:`<g${w.node.parentId?` data-parent="${Ye(w.node.parentId)}"`:""}${M===void 0?"":` role="${x?"group":"graphics-symbol"}" aria-roledescription="treemap ${x?"section":"cell"}"`}>${M===void 0?"":`<title>${M}</title>`}`,close:"</g>",children:S.map(b=>({node:b,indent:2}))}))}for(const w of t.cells)if(!w.node.parentId)l.push(y.get(w.node.id));return ls(e,"treemap",t,n,i.renderOptions.transparent??false,l)}var S$=gt(V6);function w$({positioned:e}){const t=ra(e.body.nodes);return{version:1,bounds:{w:xe(e.width),h:xe(e.height)},nodes:e.cells.filter(n=>n.node.value!==void 0).map(n=>({id:n.node.id,...n.node.parentId?{parentId:n.node.parentId}:{},x:xe(n.x),y:xe(n.y),w:Gt(n.x,n.width),h:Gt(n.y,n.height),shape:"rectangle",label:n.node.label,role:"mark",labelVisibility:n.label?"visible":"hidden",...n.label?bt(n.label,n.x+n.width/2,n.labelY,n):{}})),edges:[],groups:e.cells.filter(n=>n.node.value===void 0).map(n=>({id:n.node.id,...n.node.parentId?{parentId:n.node.parentId}:{},x:xe(n.x),y:xe(n.y),w:Gt(n.x,n.width),h:Gt(n.y,n.height),members:(t.get(n.node.id)??[]).map(i=>i.id),label:n.node.label,regionKind:"compartment"})),labels:[...e.title?[{id:"title",text:e.title.text,bounds:qt(e.title.block,e.title.x,e.title.y),container:ln(Ut(e))}]:[],...e.cells.flatMap(n=>[...n.node.value===void 0&&n.label?[{id:`section-label:${n.node.id}`,text:n.label.text,bounds:qt(n.label,n.x+n.width/2,n.labelY),container:ln(n)}]:[],...n.valueLabel?[{id:`value:${n.node.id}`,text:n.valueLabel.text,bounds:qt(n.valueLabel,n.x+n.width/2,n.valueY),container:ln(n)}]:[]])]}}var M$=e=>xt("treemap",e,{nodeWidth:wn(1,1e4),nodeHeight:wn(1,1e4),padding:wn(0,1e4),diagramPadding:wn(0,1e4),labelFontSize:wn(1,1e4),valueFontSize:wn(1,1e4),borderWidth:wn(0,1e4),showValues:lt,valueFormat:Br,useMaxWidth:lt});var jSe={configDiagnostics:M$,normalizeRequest:e=>({familyConfig:{treemap:FM(e.source.config.treemap)}}),layout:e=>{const t=c$(e.source.authoredFamilyBody??e.source.familyBody);t.title??=typeof e.source.frontmatter.title==="string"?e.source.frontmatter.title:void 0;return ht(d$(t,e.renderOptions,e.familyConfig.treemap,e.styleFace))},projectPositioned:ut(w$),lowerScene:ft(S$)};function k$(e,t={},n,i,r=24){Ly(e.nodes);const o=Ue(t,zi,n);const s=n?.node?.paddingX??12,a=n?.node?.paddingY??8,l=n?.node?.paddingX??16,c=n?.node?.paddingY??12;const d=ra(e.nodes);const u=(B,F=false)=>Be(B,{fontSize:o.nodeLabelFontSize,fontWeight:F&&n?.node?.fontWeight===void 0&&n?.text?.fontWeight===void 0?Math.max(600,o.nodeLabelFontWeight):o.nodeLabelFontWeight,letterSpacing:o.nodeLetterSpacing,transform:o.nodeTextTransform,maxWidth:220});const f=tn(i,o);const h=e.nodes[0];if(!h)return{width:Math.max(100,(f?.width??0)+r*2),height:80+(f?.height??0),body:e,nodes:[],branches:[],spine:[],options:t,...f?{title:on(f,Math.max(100,f.width+r*2),r)}:{}};const m=(B,F)=>{const z=u(B.label,true);const _=[];const H=[];const D=[];const j=(N,G,Y)=>{for(let q=N.length-1;q>=0;q--)D.push({node:N[F?N.length-1-q:q],depth:G,parent:Y,slot:q,bone:-1})};j(d.get(B.id)??[],2,-1);while(D.length){const N=D.pop();if(N.bone!==-1){H.push(N.bone);continue}const G=_.length;const Y=d.get(N.node.id)??[];_.push({node:N.node,block:u(N.node.label),depth:N.depth,parent:N.parent,slot:N.slot,kids:Y.length,rise:0,at:0,textEnd:0});if(N.depth%2===0)H.push(G);else D.push({...N,bone:G});j(Y,N.depth+1,G)}let W=16;for(const N of H){const G=_[N].block.height+14;_[N].rise=W+G/2;W+=G}let O=(z.width+s*2)/2;for(const N of _){const G=N.parent<0?void 0:_[N.parent];if(N.depth%2===0){N.at=G?.at??0;N.textEnd=N.at-(N.kids?(N.kids+1)*24:20)-6}else{N.at=G.at-(G.kids-N.slot)*24;N.textEnd=N.at-6}O=Math.max(O,N.block.width-N.textEnd)}return{node:B,block:z,width:z.width+s*2,height:z.height+a*2,bones:_,rise:Math.max(64,W+12),reach:O}};const p=(d.get(h.id)??[]).map((B,F)=>m(B,F%2===0));const g=u(h.label,true);const y=g.width+l*2;const w=Math.max(52,g.height+c*2);const S=[{node:h,block:g,x:0,y:-w/2,width:y,height:w,depth:0}];const x=[];let M=-40;let b=y;let C=-w/2;let P=w/2;let E=-40;const k=[];for(let B=0;B<p.length;B+=2){if(B>0){let F=0;for(let z=0;z<2;z++){const _=p[B-2+z];const H=p[B+z];if(_)F=Math.max(F,_.reach+(H?.width??0)/2+Math.abs((H?.rise??0)-_.rise)/2)}E-=F+32}k.push(E,E)}const v=(B,F,z,_,H,D,j)=>{S.push({node:B,block:F,x:z,y:_,width:H,height:D,depth:j});M=Math.min(M,z);b=Math.max(b,z+H);C=Math.min(C,_);P=Math.max(P,_+D)};p.forEach((B,F)=>{const z=F%2===0?-1:1;const _=k[F];const H=(W,O)=>_+W-O/2;const D=H(0,B.rise);const j=z*B.rise;v(B.node,B.block,D-B.width/2,j+(z<0?-B.height:0),B.width,B.height,1);x.push({id:`branch:${B.node.id}`,from:B.node.id,to:h.id,points:[{x:D,y:j},{x:_,y:0}]});for(const W of B.bones){const O=z*W.rise;const N=H(W.textEnd,W.rise);v(W.node,W.block,N-W.block.width,O-W.block.height/2,W.block.width,W.block.height,W.depth);const G=W.depth%2===0?[{x:N+6,y:O},{x:H(W.at,W.rise),y:O}]:[{x:H(W.at,W.rise),y:O},{x:H(W.at,B.bones[W.parent].rise),y:z*B.bones[W.parent].rise}];x.push({id:`branch:${W.node.id}`,from:W.node.id,to:W.node.parentId,points:G})}});const T=Math.min(M-28,E-28);M=Math.min(M,T);const A=Math.max(b-M,f?.width??0);const R=Math.ceil(A+2*r);const I=Math.ceil(P-C+(f?.height??0)+r*2);const L=r-M+(A-(b-M))/2;const $=r-C+(f?.height??0);for(const B of S){B.x+=L;B.y+=$}for(const B of x)for(const F of B.points){F.x+=L;F.y+=$}return{width:R,height:I,body:e,nodes:S,branches:x,spine:[{x:T+L,y:$},{x:L,y:$}],options:t,...f?{title:on(f,R,r)}:{}}}var jM=fr("ishikawa-arrow",{width:8,height:8},"end",{fill:"var(--_line)"},"userSpaceOnUse");function K6(e,{positioned:t,colors:n,resolved:i}){const r=Ue(i.renderOptions,zi,i.styleFace);const o=Jr(n);const s=r.edgeStrokeColor?{...jM,paint:{...jM.paint,fill:r.edgeStrokeColor}}:jM;const a=[];a.push(e.definitions({id:"defs",markerResources:[s]},`<defs>${mi([s])}</defs>`));if(t.title)a.push(e.text(En(t.title,r)));const l=t.nodes.find(c=>c.depth===0);if(t.spine.length)a.push(e.connector({id:"spine",role:"rail",geometry:{kind:"polyline",points:t.spine},lineStyle:"solid",paint:{stroke:r.edgeStrokeColor??"var(--_line)",strokeWidth:String(r.lineWidth)},...l?{endpoints:{to:l.node.id,end:{owner:{id:l.node.id,role:"node"},point:t.spine.at(-1)}}}:{},relationship:{kind:"effect-spine",direction:"forward"},markers:{end:s}}));for(const c of t.branches)a.push(e.connector({id:c.id,role:"edge",geometry:{kind:"polyline",points:c.points},lineStyle:"solid",paint:{stroke:r.edgeStrokeColor??"var(--_line)",strokeWidth:String(r.lineWidth)},endpoints:{from:c.from,to:c.to},relationship:{kind:"cause",direction:"forward"}}));for(const c of t.nodes){const d={id:c.node.id,role:"node"};const u=[];const f=r.nodeFillColor??"var(--_node-fill)";const h=r.nodeTextColor??(c.depth<=1?o("var(--_text)",f):"var(--_text)");if(c.depth<=1)u.push(e.shape({id:`box:${c.node.id}`,role:"node",identity:false,owner:d,geometry:{kind:"rect",x:c.x,y:c.y,width:c.width,height:c.height,rx:r.cornerRadius??(c.depth===0?8:3)},paint:{fill:r.nodeFillColor??"var(--_node-fill)",stroke:r.nodeBorderColor??"var(--_node-stroke)",strokeWidth:String(r.nodeLineWidth)}}));u.push(e.text({id:`label:${c.node.id}`,role:"label",owner:d,text:c.block.text,block:c.block,x:c.x+c.width/2,y:c.y+c.height/2,fontSize:c.block.fontSize,fontWeight:c.block.fontWeight,anchor:"middle",paint:{fill:h}}));a.push(e.group({id:c.node.id,role:"node",open:"<g>",close:"</g>",children:u.map(m=>({node:m,indent:2}))}))}return ls(e,"ishikawa",t,n,i.renderOptions.transparent??false,a)}var C$=gt(K6);function P$({positioned:e}){return{version:1,bounds:{w:xe(e.width),h:xe(e.height)},nodes:e.nodes.map(t=>({id:t.node.id,x:xe(t.x),y:xe(t.y),w:xe(t.width),h:xe(t.height),shape:"rectangle",label:t.node.label,role:t.depth<=1?"box":"labelled-mark",...bt(t.block,t.x+t.width/2,t.y+t.height/2,t)})),edges:e.branches.map(t=>({id:t.id,from:t.from,to:t.to,path:t.points.map(n=>[xe(n.x),xe(n.y)])})),groups:[],labels:e.title?[{id:"title",text:e.title.text,bounds:qt(e.title.block,e.title.x,e.title.y),container:ln(Ut(e))}]:[]}}var E$=e=>xt("ishikawa",e,{diagramPadding:Yt,useMaxWidth:lt});var hwe={configDiagnostics:E$,layout:e=>{const t=e.source.config.ishikawa;return ht(k$(PF(e.source.authoredFamilyBody??e.source.familyBody),e.renderOptions,e.styleFace,typeof e.source.frontmatter.title==="string"?e.source.frontmatter.title:void 0,typeof t?.diagramPadding==="number"&&Number.isFinite(t.diagramPadding)&&t.diagramPadding>=0?t.diagramPadding:void 0))},projectPositioned:ut(P$),lowerScene:ft(C$)};var R$=e=>xt("block",e,{padding:Yt,useMaxWidth:lt});var ds={};for(const e of["start","end"]){ds[`arrow_point:${e}`]=fr(`block-arrow-${e}`,{width:8,height:7},e,{fill:"var(--_arrow)",stroke:"none"},"userSpaceOnUse");ds[`arrow_circle:${e}`]={id:`block-circle-${e}`,shape:"circle",size:{width:9,height:9},ref:{x:4.5,y:4.5},orient:"auto",geometry:{kind:"circle",cx:4.5,cy:4.5,r:3.5},paint:{fill:"var(--bg)",stroke:"var(--_arrow)",strokeWidth:"1"},units:"userSpaceOnUse"};ds[`arrow_cross:${e}`]={id:`block-cross-${e}`,shape:"cross",size:{width:9,height:9},ref:{x:4.5,y:4.5},orient:"auto",geometry:{kind:"path",d:"M1 1L8 8M1 8L8 1"},paint:{fill:"none",stroke:"var(--_arrow)",strokeWidth:"1"},units:"userSpaceOnUse"}}var Jd=xr(Object.values(ds));var us=1;var fs=2;var hs=4;var ms=8;var Vy=7;var Ky=20;var rl=12;function Qd(e){let t=0;if(e){for(const n of e){switch(n.trim()){case"right":t|=us;break;case"left":t|=fs;break;case"up":t|=hs;break;case"down":t|=ms;break;case"x":t|=us|fs;break;case"y":t|=hs|ms;break}}}return t}var il=(e,t)=>e&t?1:0;function v$(e){if(e!==0&&(e&(hs|ms))===0)return"x";if(e!==0&&(e&(us|fs))===0)return"y";return""}function Oh(e,t,n){const i=v$(e);const r=il(e,fs)-il(e,us);const o=il(e,hs)-il(e,ms);if(i==="x"){const s=Math.max(n+8,14)+2*Vy;const a=Math.min(s/2,Ky);return{w:Math.max(t+12,16)+a*(e===(us|fs)?2:1),h:s,dx:r*a/2,dy:0}}if(i==="y"){const s=Math.max(t+16,14)+2*Vy;const a=Math.min(s/2,Ky);return{w:s,h:Math.max(n+8,16)+a*(e===(hs|ms)?2:1),dx:0,dy:o*a/2}}return{w:Math.max(t+16,24)+rl*(il(e,fs)+il(e,us)),h:Math.max(n+8,24)+rl*(il(e,hs)+il(e,ms)),dx:r*rl/2,dy:o*rl/2}}function Jy(e,t,n){const i=v$(e);const r=t/2;const o=n/2;let s;if(i==="x"){const l=Math.min(o,Ky);const c=o-Vy;const d=e&fs?-r+l:-r;const u=e&us?r-l:r;s=[d,-c,u,-c];if(e&us)s.push(u,-o,r,0,u,o);s.push(u,c,d,c);if(e&fs)s.push(d,o,-r,0,d,-o)}else if(i==="y"){const l=Math.min(r,Ky);const c=r-Vy;const d=e&hs?-o+l:-o;const u=e&ms?o-l:o;s=[c,d,c,u];if(e&ms)s.push(r,u,0,o,-r,u);s.push(-c,u,-c,d);if(e&hs)s.push(-r,d,0,-o,r,d)}else{const l=e&fs?-r+rl:-r;const c=e&us?r-rl:r;const d=e&hs?-o+rl:-o;const u=e&ms?o-rl:o;const f=(l+c)/2;const h=(d+u)/2;const m=Math.min(10,(c-l)/2);const p=Math.min(10,(u-d)/2);s=[l,d];if(e&hs)s.push(f-m,d,f,-o,f+m,d);s.push(c,d);if(e&us)s.push(c,h-p,r,h,c,h+p);s.push(c,u);if(e&ms)s.push(f+m,u,f,o,f-m,u);s.push(l,u);if(e&fs)s.push(l,h+p,-r,h,l,h-p)}const a=[];for(let l=0;l<s.length;l+=2)a.push({x:s[l],y:s[l+1]});return a}var J6=1e3;function Q6(e,t){if(e===0||!Number.isInteger(e)){throw new kh("Columns must be an integer !== 0.","semantic",{type:"block"})}if(t<0||!Number.isInteger(t)){throw new kh("Position must be a non-negative integer."+t,"semantic",{type:"block"})}if(e<0)return{px:t,py:0};return{px:t%e,py:Math.floor(t/e)}}function Z6(e,t,n,i){const r=e.columns;const o=[];let s=0;let a=0;let l=0;let c=0;for(const u of e.children){const{px:f,py:h}=Q6(r,s);let m=u.span>=1?Math.min(u.span,J6):1;if(r>0&&m>r-f)m=r-f;u.span=m;u.col=f;u.row=h;s+=m;if(f+m>a)a=f+m;if(h===o.length)o.push(0);if(u.children.length===0)o[h]=-1;else if(o[h]>=0&&u.nh>o[h])o[h]=u.nh;if(u.space)continue;const p=(u.nw-t*(m-1))/m;if(p>l)l=p;if(u.nh>c)c=u.nh}let d=(o.length-1)*t;for(let u=0;u<o.length;u++){if(o[u]<0)o[u]=c;d+=o[u]}e.cols=a;e.heights=o;e.nw=Math.max(e.nw,a*l+(a-1)*t+2*n);e.nh=d+2*i+e.head}function e8(e,t,n,i){const{cols:r,heights:o}=e;const s=o.length;const a=(e.w-2*n-(r-1)*t)/r;const l=e.h-2*i-e.head-(s-1)*t;let c=0;for(const p of o)c+=p;const d=c>0?l/c:0;const u=c>0?0:l/s;const f=e.x-e.w/2+n;let h=e.y-e.h/2+i+e.head;let m=0;for(const p of e.children){for(;m<p.row;m++)h+=o[m]*d+u+t;p.w=a*p.span+t*(p.span-1);p.h=o[m]*d+u;p.x=f+p.col*(a+t)+p.w/2;p.y=h+p.h/2}}function T$(e,t){const n=[e];for(let i=0;i<n.length;i++){for(const r of n[i].children)n.push(r)}for(let i=n.length-1;i>=0;i--){const r=n[i];if(r.children.length>0)Z6(r,t,i===0?0:r.insetX??t,i===0?0:r.insetY??t)}e.w=e.nw;e.h=e.nh;e.x=e.w/2;e.y=e.h/2;for(let i=0;i<n.length;i++){const r=n[i];if(r.children.length>0)e8(r,t,i===0?0:r.insetX??t,i===0?0:r.insetY??t)}return{width:e.w,height:e.h}}function Qy(e){return ur(Rt(yt(e)),/&(?:#[xX][0-9a-fA-F]+|#\d+|[a-zA-Z][a-zA-Z0-9]+);|#\w+;/g,t=>{const n=t.startsWith("&")?Up(t):rn(t);if(bo.test(n))throw new SyntaxError("Block label entity must display printable text");return n})}function Twe(e){return ca(Qy(e))}var t8={na:"rectangle",square:"rectangle",round:"rounded",circle:"circle",rect_left_inv_arrow:"asymmetric",diamond:"diamond",hexagon:"hexagon",stadium:"stadium",subroutine:"subroutine",cylinder:"cylinder",doublecircle:"doublecircle",lean_right:"lean-r",lean_left:"lean-l",trapezoid:"trapezoid",inv_trapezoid:"trapezoid-alt"};function Zd(e){return{id:e.id,label:e.block.label??e.id,shape:t8[e.block.type??"na"]??"rectangle",x:e.x,y:e.y,width:e.width,height:e.height}}function L$(e,t={},n,i={}){CP(e);const r=Ue(t,void 0,n),o=t.padding??32;const s=e.edges.map(D=>Be(Qy(D.label??""),{fontSize:r.edgeLabelFontSize,fontWeight:r.edgeLabelFontWeight,maxWidth:320,transform:r.edgeTextTransform,letterSpacing:r.edgeLetterSpacing}));let a=0;for(const D of e.edges)a=Math.max(a,Jd(ds[`${D.arrowTypeStart}:start`]?.id,r.lineWidth,"start"),Jd(ds[`${D.arrowTypeEnd}:end`]?.id,r.lineWidth,"end"));const l=Math.max(a?2*(a+r.edgeBendRadius):0,typeof i.padding==="number"&&i.padding>=0?Math.min(i.padding,200):20,...s.filter(D=>D.text).map(D=>D.width+40));const c=new Map(e.classDefs.map(D=>[D.id,D])),d=[];const u=(D,j)=>{const W=D.type==="composite";const O=[...c.get("default")?.styles??[],...(D.classes??[]).flatMap(K=>c.get(K)?.styles??[]),...D.styles??[]];const N=Tt(vn(O.join(",")),`style ${D.id}`),G=Number.parseFloat(N["font-size"]??"")||(W?r.groupHeaderFontSize:r.nodeLabelFontSize);const Y=N["font-weight"]?.trim().toLowerCase(),q=Y===void 0?W?r.groupHeaderFontWeight:r.nodeLabelFontWeight:Y==="normal"?400:Y==="bold"?700:Number(Y);if(!Number.isFinite(q)||q<1||q>1e3)throw new Error(`style ${D.id}: font-weight must be normal, bold, or a number from 1 to 1000`);const V=Be(Qy(D.label??(W?"":D.id)),{fontSize:G,fontWeight:q,maxWidth:320,transform:W?r.groupTextTransform:r.nodeTextTransform,letterSpacing:W?r.groupLetterSpacing:r.nodeLetterSpacing,fontFamily:W?r.groupFont??t.font:t.font});let ne=Math.max(80,V.width+(W?r.groupLabelPaddingX:r.nodePaddingX)*2),X=Math.max(44,V.height+(W?r.groupPaddingY:r.nodePaddingY)*2);if(["diamond","hexagon","lean_right","lean_left","trapezoid","inv_trapezoid"].includes(D.type??"")){ne+=48;X+=24}if(["circle","doublecircle"].includes(D.type??""))ne=X=Math.max(ne,X);if(D.type==="cylinder")X+=24;if(D.type==="block_arrow"){const K=Oh(Qd(D.directions),V.width,V.height);ne=K.w;X=K.h}if(D.type==="space"){ne=40;X=24}const U=D.type==="composite"&&V.text?V.height+16:0;return{block:D,parentId:j,label:V,style:N,children:[],columns:D.columns??-1,span:D.widthInColumns??1,space:D.type==="space",head:U,insetX:n?.group?.paddingX,insetY:n?.group?.paddingY,nw:D===e.root?0:ne,nh:D===e.root?0:X,col:0,row:0,cols:0,heights:[],x:0,y:0,w:0,h:0}};const f=u(e.root),h=[f];for(let D=0;D<h.length;D++){const j=h[D];for(const W of j.block.children??[]){const O=u(W,j===f?void 0:j.block.id);j.children.push(O);h.push(O);d.push(O)}}const m=T$(f,l),p=tn(e.title,r),g=Math.max(m.width+o*2,(p?.width??0)+o*2),y=p?.height??0;const w=o+(g-o*2-m.width)/2,S=o+y;const x=d.map(D=>{let j=D.w,W=D.h;if(["circle","doublecircle"].includes(D.block.type??""))j=W=Math.min(D.w,D.h);return{id:D.block.id,block:D.block,parentId:D.parentId,x:D.x-j/2+w,y:D.y-W/2+S,width:j,height:W,label:D.label,style:D.style}});const M=new Map(x.map(D=>[D.id,D])),b=x.filter(D=>D.block.type!=="space").map(Zd),C=new Map(b.map(D=>[D.id,rd(D)])),P=new Map(x.filter(D=>D.block.type==="block_arrow").map(D=>[D.id,{kind:"polygon",points:Jy(Qd(D.block.directions),D.width,D.height).map(j=>({x:j.x+D.x+D.width/2,y:j.y+D.y+D.height/2}))}])),E=b.filter(D=>M.get(D.id).block.type!=="composite"),k=new Map;const v=D=>D.start<D.end?`${D.start}\0${D.end}`:`${D.end}\0${D.start}`;e.edges.forEach((D,j)=>{const W=v(D),O=k.get(W)??[];O.push(j);k.set(W,O)});const T=new Map;for(const D of k.values()){const j=Math.max(...D.map(O=>s[O].width)),W=Math.max(...D.map(O=>s[O].height));D.forEach((O,N)=>T.set(O,{slot:N,count:D.length,width:j,height:W}))}const A=new Set,R=new Set;const I=(D,j)=>`${D}\0${j.x}\0${j.y}`;const L=e.edges.map((D,j)=>{const W=M.get(D.start),O=M.get(D.end);if(!W||!O)throw new Error(`Block edge ${D.id} references undeclared endpoints`);const N=s[j];const{slot:G,count:Y,width:q,height:V}=T.get(j),ne=G-(Y-1)/2,X=C.get(W.id)??rd(Zd(W)),U=C.get(O.id)??rd(Zd(O));let K;const Z={x:W.x+W.width/2,y:W.y+W.height/2},Q={x:O.x+O.width/2,y:O.y+O.height/2};let se=Math.abs(Q.x-Z.x)>=Math.abs(Q.y-Z.y);const te=[Q.x>=Z.x?X.E:X.W,Q.x>=Z.x?U.W:U.E],ee=[Q.y>=Z.y?X.S:X.N,Q.y>=Z.y?U.N:U.S],ae=Ie=>A.has(I(W.id,Ie[0]))||R.has(I(O.id,Ie[1]));if(Y===1&&W!==O&&ae(se?te:ee)&&!ae(se?ee:te))se=!se;if(W===O){const Ie=28+G*(Math.max(q,V)+24);K=[X.E,{x:X.E.x+Ie,y:X.E.y},{x:X.E.x+Ie,y:W.y-Ie},{x:X.N.x,y:W.y-Ie},X.N]}else if(Y>1&&ne!==0){const Ie=(se?V:q)+24;if(se){const Ee=ne<0?Math.min(W.y,O.y)+ne*Ie:Math.max(W.y+W.height,O.y+O.height)+ne*Ie;const ve=ne<0?X.N:X.S,$e=ne<0?U.N:U.S;K=[ve,{x:ve.x,y:Ee},{x:$e.x,y:Ee},$e]}else{const Ee=ne<0?Math.min(W.x,O.x)+ne*Ie:Math.max(W.x+W.width,O.x+O.width)+ne*Ie;const ve=ne<0?X.W:X.E,$e=ne<0?U.W:U.E;K=[ve,{x:Ee,y:ve.y},{x:Ee,y:$e.y},$e]}}else if(se){const Ie=Q.x>=Z.x?X.E:X.W,Ee=Q.x>=Z.x?U.W:U.E,ve=(Ie.x+Ee.x)/2+G*12;K=[Ie,{x:ve,y:Ie.y},{x:ve,y:Ee.y},Ee]}else{const Ie=Q.y>=Z.y?X.S:X.N,Ee=Q.y>=Z.y?U.N:U.S,ve=(Ie.y+Ee.y)/2+G*12;K=[Ie,{x:Ie.x,y:ve},{x:Ee.x,y:ve},Ee]}R.add(I(W.id,K[0]));A.add(I(O.id,K.at(-1)));const ie={id:D.id,source:W.id,target:O.id,style:"solid",hasArrowStart:D.arrowTypeStart!=="none",hasArrowEnd:D.arrowTypeEnd!=="none",points:pt(K.map(Ie=>({...Ie})))};const oe=W.block.type==="composite"||O.block.type==="composite"?b.filter(Ie=>M.get(Ie.id).block.type!=="composite"||Ie.id===W.id||Ie.id===O.id):E;No(oe,[ie],{direction:se?"LR":"TB"});K=ie.points;for(const[Ie,Ee,ve]of[[W,0,1],[O,K.length-1,K.length-2]]){const $e=P.get(Ie.id);if(!$e)continue;const De=K[Ee],fe=K[ve],me=fe.x-De.x,de=fe.y-De.y,be=Math.abs(me)>Math.abs(de),pe=be?me>0?"E":"W":de>0?"S":"N",Re=Ds($e,pe,be?De.y:De.x);if(Re)K[Ee]=Re}let ue=0;for(let Ie=1;Ie<K.length-1;Ie++)if(Math.hypot(K[Ie+1].x-K[Ie].x,K[Ie+1].y-K[Ie].y)>Math.hypot(K[ue+1].x-K[ue].x,K[ue+1].y-K[ue].y))ue=Ie;const ye=K[ue],Se=K[ue+1],Te={x:(ye.x+Se.x)/2,y:(ye.y+Se.y)/2};return{...D,points:K,labelBlock:N,labelPosition:Te}});if(L.some(D=>D.label)){const D=L.map(j=>({...j,source:j.start,target:j.end,style:"solid",hasArrowStart:false,hasArrowEnd:false}));for(let j=0;j<L.length;j++){const W=L[j],O=D[j];if(!W.label)continue;const N=W.points.slice(1).map((G,Y)=>({start:W.points[Y],end:G})).sort((G,Y)=>Math.hypot(Y.end.x-Y.start.x,Y.end.y-Y.start.y)-Math.hypot(G.end.x-G.start.x,G.end.y-G.start.y));for(const{start:G,end:Y}of N){const q=Vi(O,G,Y,{nodes:E,edges:D,axis:{main:"x",cross:"y",sign:1},style:r,finalLabelClearance:true});if(!q)continue;W.labelPosition=O.labelPosition=q;break}}}const $=Math.min(o,...L.flatMap(D=>D.points.map(j=>j.x))),B=Math.min(o+y,...L.flatMap(D=>D.points.map(j=>j.y))),F=Math.max(0,o-$),z=Math.max(0,o+y-B);if(F||z){for(const D of x){D.x+=F;D.y+=z}for(const D of L){for(const j of D.points){j.x+=F;j.y+=z}D.labelPosition.x+=F;D.labelPosition.y+=z}}let _=m.height+o*2+y+z,H=g+F;for(const D of L)for(const j of D.points){_=Math.max(_,j.y+o);H=Math.max(H,j.x+o)}return{model:e,width:H,height:_,nodes:x,edges:L,style:r,...p?{title:on(p,H,o)}:{}}}function n8(e,t){const{positioned:n,colors:i}=t,r=t.resolved.renderOptions.transparent??false,o=i.font??"Inter",s=[],a=n.style.edgeStrokeColor?Object.fromEntries(Object.entries(ds).map(([h,m])=>[h,{...m,paint:{...m.paint,...m.paint?.fill==="var(--_arrow)"?{fill:n.style.edgeStrokeColor}:{},...m.paint?.stroke==="var(--_arrow)"?{stroke:n.style.edgeStrokeColor}:{}}}])):ds,l=Object.values(a);const c=Jr(i);let d=Ot(n.width,n.height,i,r);if(n.model.accessibilityTitle)d+=`<title>${At(n.model.accessibilityTitle)}</title>`;if(n.model.accessibilityDescription)d+=`<desc>${At(n.model.accessibilityDescription)}</desc>`;d+=Dt(o,false,void 0,i.embedFontImport);s.push(e.documentOpen({id:"prelude",width:n.width,height:n.height,colors:i,transparent:r,font:o,hasMonoFont:false},d),e.definitions({id:"defs",markerResources:l},`<defs>${mi(l)}</defs>`));const u=(h,m)=>{const p=h.block.type==="composite",g=p?"group":"node",y=h.style.fill??(p?n.style.groupFillColor:n.style.nodeFillColor)??(p?"var(--_group-fill)":"var(--_node-fill)"),w=h.style.stroke??(p?n.style.groupBorderColor:n.style.nodeBorderColor)??"var(--_node-stroke)",S=h.style.fill??n.style.groupHeaderFillColor,x=h.style.color??(p?n.style.groupTextColor:n.style.nodeTextColor)??c("var(--_text)",p?S??y:y);const M=_r(Zd(h),{fill:y,stroke:w,strokeWidth:h.style["stroke-width"]??String(p?n.style.groupLineWidth:n.style.nodeLineWidth)},p?n.style.groupCornerRadius:n.style.cornerRadius);const b=h.style["stroke-dasharray"];if(b!==void 0){M.paint.strokeDasharray=b;if(M.childPaints)M.childPaints=M.childPaints.map(T=>({...T,strokeDasharray:b}))}const C=Qd(h.block.directions),P=h.block.type==="block_arrow",E=P?Oh(C,h.label.width,h.label.height):{dx:0,dy:0};const k=P?{kind:"polygon",points:Jy(C,h.width,h.height).map(T=>({x:T.x+h.x+h.width/2,y:T.y+h.y+h.height/2}))}:M.geometry;const v=[`block-${p?"composite":"node"}`,...(h.block.classes??[]).filter(T=>/^[\w-]+$/.test(T))];return e.group({id:`block:${h.id}`,role:g,open:`<g class="${Ye(v.join(" "))}" data-id="${Ye(h.id)}"${h.parentId?` data-parent="${Ye(h.parentId)}"`:""}>`,close:"</g>",children:[{indent:2,node:e.shape({id:`frame:${h.id}`,role:g,identity:false,owner:{id:h.id,role:g},geometry:k,paint:M.paint,...M.childPaints?{childPaints:M.childPaints}:{}})},...p&&h.label.text&&n.style.groupHeaderFillColor?[{indent:2,node:e.shape({id:`header:${h.id}`,role:"chrome",owner:{id:h.id,role:g},geometry:{kind:"rect",x:h.x+n.style.groupLineWidth,y:h.y+n.style.groupLineWidth,width:Math.max(0,h.width-n.style.groupLineWidth*2),height:h.label.height+16-n.style.groupLineWidth,rx:Math.max(0,n.style.groupCornerRadius-n.style.groupLineWidth)},paint:{fill:S,stroke:"none"}})}]:[],...h.label.text?[{indent:2,node:e.text({id:`label:${h.id}`,role:"label",owner:{id:h.id,role:g},text:h.label.text,block:h.label,x:h.x+h.width/2+E.dx,y:p?h.y+h.label.height/2+8:h.y+h.height/2+E.dy,fontSize:h.label.fontSize,anchor:"middle",paint:{fill:x}})}]:[],...m.map(T=>({node:T,indent:2}))]})};const f=new Map;for(let h=n.nodes.length-1;h>=0;h--){const m=n.nodes[h];if(m.block.type==="space")continue;const p=f.get(m.parentId)??[];p.push(u(m,(f.get(m.id)??[]).reverse()));f.set(m.parentId,p)}s.push(...(f.get(void 0)??[]).reverse());for(const h of n.edges){const m=a[`${h.arrowTypeStart}:start`],p=a[`${h.arrowTypeEnd}:end`],g=n.style.edgeBendRadius>0&&h.points.length>2?qn(h.points,n.style.edgeBendRadius,{terminalClearance:{start:Jd(m?.id,n.style.lineWidth,"start"),end:Jd(p?.id,n.style.lineWidth,"end")}}):void 0;s.push(e.connector({id:h.id,role:"edge",geometry:g?.geometry??{kind:"polyline",points:h.points},lineStyle:h.pattern==="dotted"?"dotted":"solid",paint:{fill:"none",stroke:n.style.edgeStrokeColor??"var(--_line)",strokeWidth:h.thickness==="thick"?"3":String(n.style.lineWidth),...h.pattern==="dotted"?{strokeDasharray:"2 4"}:{}},endpoints:{from:h.start,to:h.end},relationship:{kind:"block-link"},markers:{...m?{start:m}:{},...p?{end:p}:{}},labels:h.label?[{text:h.labelBlock.text,anchor:h.labelPosition}]:[],route:{ownership:"layout",bendRadius:n.style.edgeBendRadius,labelAnchors:h.label?[h.labelPosition]:[],...g?{contours:g.contours}:{}}}))}for(const h of n.edges)if(h.label){const m=h.labelBlock,p=h.labelPosition;s.push(e.group({id:`edge-label:${h.id}`,role:"edge-label",open:'<g class="block-edge-label">',close:"</g>",children:[{indent:2,node:e.shape({id:`label-bg:${h.id}`,role:"chrome",owner:{id:h.id,role:"edge"},geometry:{kind:"rect",x:p.x-m.width/2-6,y:p.y-m.height/2-4,width:m.width+12,height:m.height+8},paint:{fill:"var(--bg)",stroke:"none"}})},{indent:2,node:e.text({id:`label:${h.id}`,role:"edge-label",owner:{id:h.id,role:"edge"},text:m.text,block:m,x:p.x,y:p.y,fontSize:m.fontSize,anchor:"middle",paint:{fill:n.style.edgeTextColor??"var(--_text)"}})}]}))}if(n.title)s.push(e.text(En(n.title,n.style)));s.push(e.documentClose());return{family:"block",width:n.width,height:n.height,colors:i,transparent:r,parts:s}}function A$({positioned:e}){const t=i=>{const r=i.block.type==="block_arrow"?Oh(Qd(i.block.directions),i.label.width,i.label.height):{dx:0,dy:0};return{x:i.x+i.width/2+r.dx,y:i.block.type==="composite"?i.y+i.label.height/2+8:i.y+i.height/2+r.dy}};const n=e.nodes.filter(i=>i.block.type==="composite"&&i.label.text).map(i=>{const r=t(i);return{id:`label:${i.id}`,text:i.label.text,bounds:qt(i.label,r.x,r.y),container:ln(i)}});if(e.title)n.push({id:"title",text:e.title.text,bounds:qt(e.title.block,e.title.x,e.title.y),container:ln(Ut(e))});return{version:1,bounds:{w:xe(e.width),h:xe(e.height)},nodes:e.nodes.filter(i=>!["composite","space"].includes(i.block.type??"")).map(i=>{const r=t(i);return{id:i.id,x:xe(i.x),y:xe(i.y),w:xe(i.width),h:xe(i.height),shape:Zd(i).shape,label:i.label.text,role:"box",...bt(i.label,r.x,r.y,i),...i.parentId?{parentId:i.parentId}:{}}}),edges:e.edges.map(i=>({id:i.id,from:i.start,to:i.end,path:i.points.map(r=>[xe(r.x),xe(r.y)]),...i.label?{label:{x:xe(i.labelPosition.x),y:xe(i.labelPosition.y),text:i.labelBlock.text,bounds:qt(i.labelBlock,i.labelPosition.x,i.labelPosition.y)}}:{}})),groups:e.nodes.filter(i=>i.block.type==="composite").map(i=>({id:i.id,x:xe(i.x),y:xe(i.y),w:xe(i.width),h:xe(i.height),label:i.block.label,members:e.nodes.filter(r=>r.parentId===i.id&&r.block.type!=="space").map(r=>r.id),parentId:i.parentId})),labels:n}}var I$=gt(n8);var c0e={configDiagnostics:R$,layout:e=>{const t=CF(e.source.familyLines);t.title??=Nr(e.source.frontmatter);t.accessibilityTitle=e.source.accessibility.title;t.accessibilityDescription=e.source.accessibility.descr;return ht(L$(t,e.renderOptions,e.styleFace,e.source.config.block))},projectPositioned:ut(A$),lowerScene:ft(I$)};var Bh=class extends RangeError{code="C4_ROUTE_WORK_LIMIT";constructor(){super("C4_ROUTE_WORK_LIMIT: physical corridor checks exceed 400000; split the diagram or reduce its relationships");this.name="C4RouteWorkLimitError"}};var F$=e=>xt("c4",e,Mw);function Zy(e,t){const n=oc(e),i=new Map;for(const o of e.elements){const s=`${o.external?"external-":""}${o.kind}:${o.shape}`;const a=`${o.external?"External ":""}${o.kind[0].toUpperCase()}${o.kind.slice(1)}${o.shape==="database"?" / Database":o.shape==="queue"?" / Queue":""}`;if(!i.has(s)){const l=t?Xs(o,t):void 0;i.set(s,{id:n.generated(`c4:legend:${s}`,["c4","legend",s]),label:a,kind:"element",shape:Ao(o),external:o.external,style:{...o.style,...l?.fill?{bgColor:l.fill}:{},...l?.stroke?{borderColor:l.stroke}:{}}})}}const r=t?.typeLegend!==false&&i.size>1||e.legend?.visible?[...i.values()]:[];return[...r,...e.legend?.visible?e.legend.entries:[]]}function N$({positioned:e,options:t}){const n=e.body;const i=e.textContext;const r=(m,p,g,y)=>{if(!g||g.prepared.source!==p||g.prepared.display!=="literal"||g.prepared.transform!==y)throw new Error("C4 "+m+" changed its retained prepared text")};const o=new Map(n.elements.map(m=>[m.id,m]));const s=new Map(n.relationships.map(m=>[m.id,m]));const a=new Map;const l=new Map;const c=(m,p)=>{for(const g of m){if(a.has(g.id))throw new Error(`C4 boundary "${g.id}" has a repeated positioned frame`);a.set(g.id,g);l.set(g.id,p);c(g.children,g.id)}};c(e.groups);const d=new Set(e.nodes.map(m=>m.id));if(d.size!==e.nodes.length||d.size!==o.size||n.elements.some(m=>!d.has(m.id)))throw new Error("C4 positioned cards do not match the authored identities");if(a.size!==n.boundaries.length)throw new Error("C4 positioned frames do not match the authored boundaries");const u=new Set(e.edges.map(m=>m.id));if(u.size!==e.edges.length||u.size!==s.size)throw new Error("C4 positioned relationships do not match the authored identities");for(const m of e.nodes){const p=Kf(o.get(m.id));if(m.label!==p)throw new Error("C4 card "+m.id+" changed its authored text");r(m.id,p,m.labelBlock,i.node)}for(const m of e.edges){const p=m.id===void 0?void 0:s.get(m.id);if(!p)throw new Error("C4 positioned relationship has no authored interaction identity");const g=Qf(n,p);const y=p.style.lineStyle==="dashed"||p.style.lineStyle==="dotted"?"dotted":"solid";if(m.source!==p.source||m.target!==p.target||m.label!==g||m.style!==y||m.hasArrowStart!==p.bidirectional||!m.hasArrowEnd||(m.startMarker??"arrow")!=="arrow"||(m.endMarker??"arrow")!=="arrow")throw new Error("C4 relationship "+m.id+" changed its authored endpoints, label, shaft or markers");r(m.id,g,m.labelBlock,i.edge)}const f=[];for(const m of n.boundaries){const p=a.get(m.id);if(!p||l.get(m.id)!==m.parentId)throw new Error(`C4 boundary "${m.id}" changed its authored parent`);const g=Jf(m);if(p.label!==g)throw new Error("C4 boundary "+m.id+" changed its authored text");r(m.id,g,p.labelBlock,i.group);const y=m.alignment==="left"?"start":m.alignment==="right"?"end":"middle";const w=m.alignment==="left"?p.x+e.config.padding:m.alignment==="right"?p.x+p.width-e.config.padding:p.x+p.width/2;const S=p.headerHeight??36;f.push({id:`boundary-label:${m.id}`,text:p.labelBlock?.text??p.label,bounds:qt(p.labelBlock,w,p.y+S/2,y),container:ln({...p,height:S})})}if(i.title!==void 0!==(e.title!==void 0))throw new Error("C4 positioned title does not match the authored title");if(e.title){const m=e.title;r("title",i.title,m.block,i.group);f.push({id:"title",text:m.text,bounds:qt(m.block,m.x,m.y),container:ln(Ut(e))})}const h=Zy(n,e.config);if(h.length>0!==(e.legend!==void 0))throw new Error("C4 positioned legend does not match the authored legend");if(e.legend){const m=e.legend;if(m.entries.length!==h.length||m.entries.some((y,w)=>y.id!==h[w].id))throw new Error("C4 positioned legend entries do not match the authored legend");r("legend heading","Legend",m.heading,i.legendHeading);const p=ln(m);f.push({id:"legend:heading",text:m.heading.text,bounds:qt(m.heading,m.x+12,m.y+8+m.heading.height/2,"start"),container:p});let g=m.y+20+m.heading.height;for(const[y,w]of m.entries.entries()){r(w.id,h[y].label,w.block,i.edge);f.push({id:`legend:entry:${w.id}`,text:w.block.text,bounds:qt(w.block,m.x+38,g+w.block.height/2,"start"),container:p});g+=w.block.height+10}}return{version:1,nodes:e.nodes.map(m=>{const p=o.get(m.id);const g=Ao(p);const y=m.y+m.height/2+(g==="person"?19:g==="database"?4:0);return{id:p.id,x:rt(m.x),y:rt(m.y),w:rt(m.width),h:rt(m.height),shape:g,label:p.label,role:"box",...bt(m.labelBlock,m.x+m.width/2,y,m),...p.parentId!==void 0?{parentId:p.parentId}:{}}}),edges:e.edges.map(m=>{const p=m.id===void 0?void 0:s.get(m.id);if(!p)throw new Error("C4 positioned relationship has no authored interaction identity");return{id:p.id,from:m.source,to:m.target,path:m.points.map(g=>[rt(g.x),rt(g.y)]),...m.label!==void 0&&m.labelPosition?{label:{x:rt(m.labelPosition.x),y:rt(m.labelPosition.y),text:m.label,bounds:qt(m.labelBlock,m.labelPosition.x,m.labelPosition.y)}}:{},...t.debug&&m.routeCertificate?{route:m.routeCertificate}:{}}}),groups:n.boundaries.map(m=>{const p=a.get(m.id);if(!p)throw new Error(`C4 boundary "${m.id}" has no positioned frame`);return{id:m.id,label:m.label,x:rt(p.x),y:rt(p.y),w:rt(p.width),h:rt(p.height),members:n.elements.filter(g=>g.parentId===m.id).map(g=>g.id),...m.parentId!==void 0?{parentId:m.parentId}:{}}}),bounds:{w:rt(e.width),h:rt(e.height)},labels:f}}function $$(e,t,n){const i=new Map([...t].map(([h,m])=>[h,{...m}])),r=[];const o=new Map(e.statements.map((h,m)=>[h.id,m]));const s=[...e.boundaries,...e.elements].sort((h,m)=>(o.get(h.statementId)??0)-(o.get(m.statementId)??0)),a=new Map(s.map(h=>[h.id,h.parentId]));const l=[...e.layout.hints,...e.relationships.filter(h=>h.direction).map(h=>({from:h.from,to:h.to,direction:h.direction,statementId:h.statementId}))];const c=(h,m)=>{const p=new Set;while(a.get(h)!==m){if(p.has(h))return void 0;p.add(h);const g=a.get(h);if(!g)return void 0;h=g}return h};const d=(h,m,p)=>{const g=s.filter(k=>k.parentId===h&&i.has(k.id));for(const k of g)if(i.get(k.id).container&&!m.has(k.id)){const v=new Set(m);v.add(k.id);const T=d(k.id,v,p===void 0?void 0:Math.max(1,p-n.padding*2)),A=i.get(k.id);A.width=Math.max(A.width,T.width+n.padding*2);A.height=Math.max(A.height,T.height+(A.headerHeight??0)+n.padding+Math.max(n.padding,A.bottomPadding??0))}let y=g.some(k=>i.get(k.id).container)?n.boundariesPerRow:n.shapesPerRow;const w=n.direction,S=w==="LR"||w==="RL";if(!S&&p!==void 0){const k=Math.max(1,...g.map(T=>i.get(T.id).width));const v=Math.max(1,Math.floor((p+n.gapX)/(k+n.gapX)));y=Math.max(y,Math.ceil(g.length/v))}let x=0,M=0,b=0,C=0,P=0;g.forEach(k=>{const v=i.get(k.id);if(P&&(P>=y||S&&p!==void 0&&x+v.width>p)){if(S){x=0;M+=b+n.gapY;b=0}else{M=0;x+=C+n.gapX;C=0};P=0}v.x=x;v.y=M;if(S)x+=v.width+n.gapX;else M+=v.height+n.gapY;b=Math.max(b,v.height);C=Math.max(C,v.width);P++});const E=[];for(const k of l){const v=c(k.from,h),T=c(k.to,h);if(!v||!T||v===T||!i.has(v)||!i.has(T))continue;const A=k.direction==="LR"||k.direction==="RL"?"x":"y";const R=k.direction==="RL"||k.direction==="BT";const I=R?T:v,L=R?v:T;const $=(B,F,z=new Set)=>B===F||!z.has(B)&&(z.add(B),E.some(_=>_.axis===A&&_.before===B&&$(_.after,F,z)));if($(L,I)){r.push({code:"C4_LAYOUT_CONFLICT",severity:"warning",statementId:k.statementId,message:`Conflicting C4 ${A==="x"?"horizontal":"vertical"} direction for ${k.from} and ${k.to}; the earlier constraint is retained.`});continue}E.push({before:I,after:L,axis:A,statementId:k.statementId})}if(E.length){for(const v of g){const T=i.get(v.id);if(E.some(A=>A.axis==="x"&&(A.before===v.id||A.after===v.id)))T.x=0;if(E.some(A=>A.axis==="y"&&(A.before===v.id||A.after===v.id)))T.y=0}const k=()=>{for(let v=0;v<g.length;v++)for(const T of E){const A=i.get(T.before),R=i.get(T.after);R[T.axis]=Math.max(R[T.axis],A[T.axis]+(T.axis==="x"?A.width+n.gapX:A.height+n.gapY))}};k();for(let v=0;v<g.length;v++){let T=false;for(let A=0;A<g.length;A++)for(let R=A+1;R<g.length;R++){const I=i.get(g[A].id),L=i.get(g[R].id);if(I.x<L.x+L.width&&L.x<I.x+I.width&&I.y<L.y+L.height&&L.y<I.y+I.height){L.y=I.y+I.height+n.gapY;T=true}}k();if(!T)break}}else if(w==="RL"||w==="BT"){const k=Math.max(0,...g.map(v=>{const T=i.get(v.id);return w==="RL"?T.x+T.width:T.y+T.height}));for(const v of g){const T=i.get(v.id);if(w==="RL")T.x=k-T.x-T.width;else T.y=k-T.y-T.height}}return{width:Math.max(0,...g.map(k=>{const v=i.get(k.id);return v.x+v.width})),height:Math.max(0,...g.map(k=>{const v=i.get(k.id);return v.y+v.height}))}};const u=d(void 0,new Set,n.maxWidth===void 0?void 0:Math.max(1,n.maxWidth-n.marginX*2));const f=(h,m,p,g)=>{for(const y of s.filter(w=>w.parentId===h)){const w=i.get(y.id);if(!w||g.has(y.id))continue;g.add(y.id);w.x+=m;w.y+=p;if(w.container)f(y.id,w.x+n.padding,w.y+(w.headerHeight??0)+n.padding,g)}};f(void 0,n.marginX,n.marginY,new Set);return{boxes:i,width:u.width+n.marginX*2,height:u.height+n.marginY*2,diagnostics:r}}var _$={T:{x:0,y:-1},R:{x:1,y:0},B:{x:0,y:1},L:{x:-1,y:0}};var tx=(e,t)=>e.x<=t.x&&e.y<=t.y&&e.x+e.width>=t.x+t.width&&e.y+e.height>=t.y+t.height;var ps=e=>({x:e.x+e.width/2,y:e.y+e.height/2});function i8(e,t){if(e.id===t.id)return["R","B"];if(e.container&&tx(e,t))return["B","B"];if(t.container&&tx(t,e))return["B","B"];const n=ps(e),i=ps(t);if(Math.abs(n.x-i.x)>=Math.abs(n.y-i.y))return n.x<=i.x?["R","L"]:["L","R"];return n.y<=i.y?["B","T"]:["T","B"]}function ex(e,t,n){if(t==="T"||t==="B"){const r=e.cylinder?8*(1-Math.sqrt(Math.max(0,1-(2*n-1)**2))):0;return{x:e.x+e.width*n,y:e.y+(t==="B"?e.height-r:r)}}const i=e.container?e.headerHeight??0:e.cylinder?8:0;return{x:e.x+(t==="R"?e.width:0),y:e.y+i+(e.height-i-(e.cylinder?8:0))*n}}function nx(e,t,n,i){return ex(e,t,(n+1)/(i+1))}var D$=8;var r8={T:"B",R:"L",B:"T",L:"R"};function o8(e,t,n,i,r,o){const s=nx(n,i,r,o);if(r8[t]!==i)return s;const a=i==="L"||i==="R"?"y":"x";const l=e[a]-s[a];if(l===0||Math.abs(l)>=D$)return s;const c=ex(n,i,0),d=ex(n,i,1);const u=(e[a]-c[a])/(d[a]-c[a]);if(!(u>0&&u<1))return s;const f=ex(n,i,u);for(let h=0;h<o;h++){if(h!==r&&Math.abs(nx(n,i,h,o)[a]-f[a])<D$)return s}return f}function s8(e,t,n,i){const r=(y,w)=>{const S=[...new Set(n.flatMap(b=>[b[y]-10,b[y]+b[w]+10]))];const x=[Math.min(e[y],t[y],...S),Math.max(e[y],t[y],...S)];const M=b=>Math.min(Math.abs(b-e[y]),Math.abs(b-t[y]));return[...new Set([...x,...S.sort((b,C)=>M(b)-M(C)||b-C).slice(0,14)])]};const o=r("x","width"),s=r("y","height");const a=[];for(const y of o)a.push([e,{x:y,y:e.y},{x:y,y:t.y},t]);for(const y of s)a.push([e,{x:e.x,y},{x:t.x,y},t]);for(const y of o)for(const w of s){a.push([e,{x:e.x,y:w},{x:y,y:w},{x:y,y:t.y},t]);a.push([e,{x:y,y:e.y},{x:y,y:w},{x:t.x,y:w},t])}const l=y=>y.slice(1).reduce((w,S,x)=>w+Math.hypot(S.x-y[x].x,S.y-y[x].y),0);const c=(y,w)=>n.every(S=>!i(y,w,S));const d=y=>y.map(pt).sort((w,S)=>l(w)-l(S)||w.length-S.length).find(w=>w.slice(1).every((S,x)=>c(w[x],S)));const u=d(a);if(u)return u;const f=s.filter(y=>c(e,{x:e.x,y})),h=s.filter(y=>c({x:t.x,y},t));const m=o.filter(y=>c(e,{x:y,y:e.y})),p=o.filter(y=>c({x:y,y:t.y},t));const g=[];for(const y of o)for(const w of f)for(const S of h)g.push([e,{x:e.x,y:w},{x:y,y:w},{x:y,y:S},{x:t.x,y:S},t]);for(const y of s)for(const w of m)for(const S of p)g.push([e,{x:w,y:e.y},{x:w,y},{x:S,y},{x:S,y:t.y},t]);return d(g)}function O$(e,t,n,i,r){const{edges:o}=t;const s=[...e.values()].filter(x=>x.container).map(x=>({...x,id:r.generated(`c4-header-obstacle:${x.id}`,["c4","header-obstacle",x.id]),height:x.headerHeight??1,shape:"rectangle",label:""}));const a=[...t.nodes,...s];let l=0;const c=()=>{if(++l>4e5)throw new Bh};const d=(x,M,b)=>{c();return $i(x,M,b)};const u=(x,M,b,C,P)=>{const E={x:_$[M].x*b,y:_$[M].y*b};let k=C;for(const v of a){c();if(v.id===P)continue;const T=E.x?x.y>v.y&&x.y<v.y+v.height:x.x>v.x&&x.x<v.x+v.width;if(!T)continue;const A=E.x>0?v.x-x.x:E.x<0?x.x-v.x-v.width:E.y>0?v.y-x.y:x.y-v.y-v.height;if(A>=0)k=Math.min(k,Math.max(0,A-2))}return{x:x.x+E.x*k,y:x.y+E.y*k}};const f=new Map;const h=new Map,m=new Map;const p=o.flatMap(x=>{const M=e.get(x.source),b=e.get(x.target);if(!M||!b)return[];const[C,P]=i8(M,b);for(const[E,k]of[[M.id,C],[b.id,P]]){const v=`${E}\0${k}`;h.set(v,(h.get(v)??0)+1)};return[{edge:x,source:M,target:b,startSide:C,endSide:P}]});const g=new Map;for(const x of p){const M=JSON.stringify([x.source.id,x.target.id].sort());const b=g.get(M)??[];b.push(x);g.set(M,b)}for(const[x,M]of p.entries()){const{edge:b,source:C,target:P,startSide:E,endSide:k}=M;const v=(O,N)=>{const G=`${O.id}\0${N}`,Y=m.get(G)??0;m.set(G,Y+1);return{index:Y,count:h.get(G)}};const T=v(C,E),A=v(P,k);const R=nx(C,E,T.index,T.count);const I=C.id===P.id?nx(P,k,A.index,A.count):o8(R,E,P,k,A.index,A.count);const L=C.container&&C.id!==P.id&&tx(C,P)?-1:1;const $=P.container&&C.id!==P.id&&tx(P,C)?-1:1;const B=g.get(JSON.stringify([C.id,P.id].sort()));const F=E==="R"||E==="L"?Math.max(24,...B.map(O=>(O.edge.labelBlock?.width??0)+32)):Math.max(24,...B.map(O=>(O.edge.labelBlock?.height??0)+24));const z=(B.indexOf(M)-(B.length-1)/2)*F;const _=14+x%5*4;const H=Ws(b,i);const D=u(R,E,L,Math.max(_,H.start?H.start+(i.edgeBendRadius??0):0),C.id);const j=u(I,k,$,Math.max(_,H.end?H.end+(i.edgeBendRadius??0):0),P.id);f.set(b,{start:R,end:I,startExit:D,endExit:j});let W;if(C.id===P.id){const O=C.x+C.width+_+(b.labelBlock?.width??0)/2;const N=C.y+C.height+_+(b.labelBlock?.height??0)/2;W=[D,{x:O,y:D.y},{x:O,y:N},{x:j.x,y:N},j]}else if(E==="R"||E==="L"){const O=(D.x+j.x)/2+z;W=[D,{x:O,y:D.y},{x:O,y:j.y},j]}else{const O=(D.y+j.y)/2+z;W=[D,{x:D.x,y:O},{x:j.x,y:O},j]}b.points=pt([R,...W,I]);f.get(b).seed=b.points;if(b.label)b.labelPosition=sn(b.points)}Tp(t,n,new Set,i);Lp(t,n,i);hf(t,n,i);Ip(t,n,i);for(const x of o){const M=f.get(x);const b=e.get(x.source),C=e.get(x.target);const P=Math.abs(ps(b).x-ps(C).x)>=Math.abs(ps(b).y-ps(C).y);const E=P?ps(b).x<=ps(C).x?"LR":"RL":ps(b).y<=ps(C).y?"TB":"BT";const k={id:r.generated(`${x.id}:routing-source`,["c4",x.id,"routing-source"]),label:"",shape:"rectangle",...M.startExit,width:0,height:0};const v={id:r.generated(`${x.id}:routing-target`,["c4",x.id,"routing-target"]),label:"",shape:"rectangle",...M.endExit,width:0,height:0};const T={...x,source:k.id,target:v.id,points:pt([M.startExit,...M.seed.slice(1,-1),M.endExit])};const A=(x.labelBlock?.width??0)/2+10,R=(x.labelBlock?.height??0)/2+8;const I=[...t.nodes,...s].map($=>$.id===x.source||$.id===x.target?$:{...$,x:$.x-A,y:$.y-R,width:$.width+A*2,height:$.height+R*2});No([...I,k,v],[T],{...n,direction:E});const L=T.points.slice(1).some(($,B)=>a.some(F=>d(T.points[B],$,F)));if(L)T.points=s8(M.startExit,M.endExit,a,d)??T.points;x.points=pt([M.start,...T.points,M.end]);x.labelPosition=sn(x.points)}Ap(t,n,i);const y=[...t.nodes,...s],w={...t,nodes:y};const{ctx:S}=Ro(y,o,n.direction,i,t.groups);S.finalLabelClearance=true;for(const x of o){if(!x.label)continue;const M=x.points.slice(1).map((b,C)=>({start:x.points[C],end:b})).sort((b,C)=>Math.abs(C.end.x-C.start.x)+Math.abs(C.end.y-C.start.y)-(Math.abs(b.end.x-b.start.x)+Math.abs(b.end.y-b.start.y)));for(const{start:b,end:C}of M){const P=Vi(x,b,C,S);if(P){x.labelPosition=P;break}}}hf(w,n,i);for(const x of o){const M=e.get(x.source),b=e.get(x.target);Qo(x,x.routeCertificate,{...M,label:"",shape:"rectangle"},{...b,label:"",shape:"rectangle"})}}function sl(e){if(!e.label||!e.labelPosition||!e.labelBlock)return void 0;const t=e.labelBlock.width+20,n=e.labelBlock.height+16;return{x:e.labelPosition.x-t/2,y:e.labelPosition.y-n/2,width:t,height:n}}var ol=(e,t)=>Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x))*Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));var ix=(e,t)=>({x:e.x-t,y:e.y-t,width:e.width+t*2,height:e.height+t*2});var YM=e=>e.flatMap(t=>[t,...YM(t.children)]);function B$(e,t,n){let i=0,r=1;for(const o of["x","y"]){const s=t[o]-e[o],a=n[o]+.01,l=n[o]+(o==="x"?n.width:n.height)-.01;if(Math.abs(s)<.001){if(e[o]<=a||e[o]>=l)return false;continue}const c=(a-e[o])/s,d=(l-e[o])/s;i=Math.max(i,Math.min(c,d));r=Math.min(r,Math.max(c,d));if(i>=r)return false}return i<r}function rx(e,t){const n=[];const i=e.inlineStyle?.["stroke-width"]?1:t*(e.style==="thick"?2:1);const r=bn.width*i,o=(e.inlineStyle?.["stroke-width"]?bn.width:bn.height)*i/2,s=.375*i;for(const a of[true,false]){if(!(a?e.hasArrowStart:e.hasArrowEnd))continue;const l=e.points.at(a?0:-1);const c=(a?e.points.slice(1):e.points.slice(0,-1).reverse()).find(g=>l&&Math.hypot(g.x-l.x,g.y-l.y)>.01);if(!l||!c)continue;const d=Math.hypot(l.x-c.x,l.y-c.y),u=(l.x-c.x)/d,f=(l.y-c.y)/d;const h=[l,{x:l.x-u*r-f*o,y:l.y-f*r+u*o},{x:l.x-u*r+f*o,y:l.y-f*r-u*o}];const m=Math.min(...h.map(g=>g.x)),p=Math.min(...h.map(g=>g.y));n.push({...ix({x:m,y:p,width:Math.max(...h.map(g=>g.x))-m,height:Math.max(...h.map(g=>g.y))-p},s),endpoint:a?e.source:e.target,polygon:h,strokePadding:s})}return n}function a8(e,t){if(ol(e,t)<=.01)return false;for(const n of[e.polygon,t.polygon])for(const[i,r]of n.entries()){const o=n[(i+1)%n.length],s=-(o.y-r.y),a=o.x-r.x,l=Math.hypot(s,a);if(l<.001)continue;const c=f=>f.polygon.map(h=>(h.x*s+h.y*a)/l);const d=c(e),u=c(t);if(Math.max(...d)+e.strokePadding<=Math.min(...u)-t.strokePadding+.01||Math.max(...u)+t.strokePadding<=Math.min(...d)-e.strokePadding+.01)return false}return true}function W$(e,t){return[...e,...YM(t).flatMap(n=>[{x:n.x,y:n.y,width:n.width,height:n.headerHeight??0},{x:n.x,y:n.y,width:1,height:n.height},{x:n.x+n.width-1,y:n.y,width:1,height:n.height},{x:n.x,y:n.y+n.height-1,width:n.width,height:1}])]}function z$(e,t,n){const{edges:i}=e,r=W$(e.nodes,e.groups),o=i.flatMap(d=>rx(d,t)),s=[];const a=new Map(n.relationships.map(d=>[d.id,d.style]));const l=i.flatMap(d=>d.points.slice(1).map((u,f)=>({edge:d,start:d.points[f],end:u})));const c=i.map((d,u)=>({edge:d,index:u,rect:sl(d)})).filter(d=>d.rect).sort((d,u)=>u.rect.width*u.rect.height-d.rect.width*d.rect.height||d.index-u.index);for(const{edge:d,rect:u}of c){const f=a.get(d.id);const h=E=>Number.isFinite(Number(E))?Number(E):0;const m=h(f?.offsetX),p=h(f?.offsetY);const g=E=>({x:E.x+m,y:E.y+p});const y=g(d.labelPosition),w=[y],S=u.width,x=u.height;const M=E=>{const k={x:E.x-S/2,y:E.y-x/2,width:S,height:x},v=ix(k,3);return[o.reduce((T,A)=>T+ol(v,A),0),r.reduce((T,A)=>T+ol(v,A),0),s.reduce((T,A)=>T+ol(ix(k,4),A),0),l.reduce((T,A)=>T+(A.edge!==d&&B$(A.start,A.end,ix(k,2))?1:0),0)]};let b=y,C=M(y);if(C.every(E=>E===0)){d.labelPosition=y;s.push(sl(d));continue}const P=l.filter(E=>E.edge===d).sort((E,k)=>Math.hypot(k.end.x-k.start.x,k.end.y-k.start.y)-Math.hypot(E.end.x-E.start.x,E.end.y-E.start.y));for(const{start:E,end:k}of P){const v=Math.hypot(k.x-E.x,k.y-E.y);if(v<.01)continue;const T=-(k.y-E.y)/v,A=(k.x-E.x)/v;const R=Math.abs(T)*S/2+Math.abs(A)*x/2;for(const I of[.5,.25,.75,.1,.9])for(const L of[0,R+6,-R-6,R+20,-R-20]){w.push(g({x:E.x+(k.x-E.x)*I+T*L,y:E.y+(k.y-E.y)*I+A*L}))}}w.sort((E,k)=>Math.hypot(E.x-y.x,E.y-y.y)-Math.hypot(k.x-y.x,k.y-y.y));for(const E of w){const k=M(E),v=k.findIndex((T,A)=>T!==C[A]);if(v>=0&&k[v]<C[v]){b=E;C=k}if(k.every(T=>T===0))break}d.labelPosition=b;s.push(sl(d))}}function G$(e,t,n,i){const r=[],{edges:o,nodes:s,groups:a}=t,l=W$(s,a),c=o.map(h=>({edge:h,box:sl(h)})).filter(h=>h.box);const d=h=>e.relationships.find(m=>m.id===h.id)?.statementId;for(const{edge:h,box:m}of c){if(l.some(p=>ol(m,p)>.01)||c.some(p=>p.edge!==h&&ol(m,p.box)>.01)||o.some(p=>p!==h&&p.points.slice(1).some((g,y)=>B$(p.points[y],g,m))))r.push({code:"C4_LABEL_COLLISION",severity:"warning",statementId:d(h),message:`Relationship ${h.id} has a label halo overlapping another label, card, boundary header/frame or relationship route; all authored text is retained.`})}const u=YM(a).map(h=>({...h,height:h.headerHeight??0}));const f=o.flatMap(h=>rx(h,n).map(m=>({edge:h,head:m})));for(const h of o){const m=f.filter(p=>p.edge===h).map(p=>p.head);if((h.hasArrowEnd||h.hasArrowStart)&&!m.length||m.some(p=>c.some(g=>ol(p,g.box)>.01)||[...s,...u].some(g=>g.id!==p.endpoint&&ol(p,g)>.01)||f.some(g=>g.head!==p&&a8(p,g.head))||i&&(p.x<-.01||p.y<-.01||p.x+p.width>i.width+.01||p.y+p.height>i.height+.01)))r.push({code:"C4_ARROW_OCCLUDED",severity:"warning",statementId:d(h),message:`Relationship ${h.id} has an arrowhead overlapping a label, card, boundary header or another arrowhead, exceeds the final canvas, or lacks a nonzero terminal segment.`})}return r}function H$(e,t={},n,i={},r={}){Fm(e);const o=Xp({...t.padding===void 0?{}:{diagramMarginX:t.padding,diagramMarginY:t.padding},...t.nodeSpacing===void 0?{}:{c4ShapeMargin:t.nodeSpacing},...t.layerSpacing===void 0?{}:{nextLinePaddingX:t.layerSpacing},...i},r),s=Ue(t,void 0,n);const a=uA(e,o),l=new Map;const c=new Map([...e.elements,...e.boundaries].map(_=>[_.id,_.parentId]));const d=_=>{const H=[];for(let D=c.get(_);D&&!H.includes(D);D=c.get(D))H.push(D);return H};const u=_=>o.input.c4ShapePadding!==void 0?o.padding:o.compact&&n?.node?.[_==="X"?"paddingX":"paddingY"]===void 0?Math.min(o.padding,s[_==="X"?"nodePaddingX":"nodePaddingY"]):s[_==="X"?"nodePaddingX":"nodePaddingY"];const f=_=>{if(o.wrapWidth===void 0)return void 0;if(o.maxWidth===void 0)return o.wrapWidth;const H=_===void 0?0:d(_).length;return Math.max(24,o.minimumWidth-u("X")*2-20,Math.min(o.wrapWidth,o.maxWidth-(o.marginX+40)*2-H*o.boundaryPadding*2-u("X")*2-20))};const h=(_,H,D=false)=>{const j=Xs(_,o);return Be(H,{display:"literal",fontSize:j.fontSize??(D?s.groupHeaderFontSize:s.nodeLabelFontSize),fontWeight:j.fontWeight??(D?s.groupHeaderFontWeight:s.nodeLabelFontWeight),transform:D?s.groupTextTransform:s.nodeTextTransform,maxWidth:f(_.id),letterSpacing:D?s.groupLetterSpacing:s.nodeLetterSpacing,fontFamily:j.fontFamily??(D?s.groupFont:void 0)})};const m=e.elements.map(_=>{const H=Kf(_),D=h(_,H),j=Ao(_),W=j==="person"?38:j==="database"?16:0;const O=Math.max(o.minimumWidth,D.width+u("X")*2+(j==="queue"?20:0)),N=Math.max(o.minimumHeight,D.height+u("Y")*2+W);l.set(_.id,{id:_.id,x:0,y:0,width:O,height:N,...j==="database"?{cylinder:true}:{}});return{...a.nodes.get(_.id),x:0,y:0,width:O,height:N,labelBlock:D,inlineStyle:a.nodeStyles.get(_.id)}});const p=new Map;for(const _ of e.boundaries){const H=Jf(_),D=h(_,H,true),j=D.height+o.padding*2;const W={id:_.id,label:H,labelBlock:D,x:0,y:0,width:Math.max(o.minimumWidth,D.width+o.padding*2),height:j+o.boundaryPadding*2,headerHeight:j,children:[]};p.set(_.id,W);l.set(_.id,{...W,container:true})}const g=a.edges.map((_,H)=>({..._,points:[],labelBlock:Be(Qf(e,e.relationships[H]),{display:"literal",fontSize:s.edgeLabelFontSize,fontWeight:s.edgeLabelFontWeight,letterSpacing:s.edgeLetterSpacing,transform:s.edgeTextTransform,...o.maxWidth===void 0?{}:{maxWidth:f()}}),inlineStyle:a.linkStyles.get(H),edgeIndex:H}));for(const _ of e.boundaries){const H=g.filter(D=>D.source===_.id&&d(D.target).includes(_.id)||D.target===_.id&&d(D.source).includes(_.id));if(H.length)l.get(_.id).bottomPadding=Math.max(o.boundaryPadding,...H.map(D=>(D.labelBlock?.height??0)+48))*H.length}const y=a.direction==="LR"||a.direction==="RL";for(const[_,H]of l){const D=g.filter(G=>G.source===_||G.target===_);const j=Math.max(0,...D.map(G=>(G.labelBlock?.height??0)+28));const W=Math.max(0,...D.map(G=>(G.labelBlock?.width??0)+24));const O=new Map;for(const G of D){const Y=G.source===_?G.target:G.source;O.set(Y,(O.get(Y)??0)+1)}const N=Math.max(0,...O.values());if(y)H.height=Math.max(H.height,(N+1)*j+(H.headerHeight??0),(D.length+1)*16+(H.headerHeight??0));else H.width=Math.max(H.width,(N+1)*W,(D.length+1)*16)}const w=t.diagramTitle??e.title;const S=w===void 0?void 0:Be(w,{display:"literal",fontSize:$m,fontWeight:_m,transform:s.groupTextTransform,letterSpacing:s.groupLetterSpacing,fontFamily:s.groupFont,...o.maxWidth===void 0?{}:{maxWidth:Math.max(24,o.maxWidth-o.marginX*2)}});const x=S?{text:S.text,width:S.width,height:S.height+Al,block:S}:void 0,M=Math.max(o.gap,...g.map(_=>(_.labelBlock?.width??0)*2+48)),b=Math.max(o.rowGap,...g.map(_=>(_.labelBlock?.height??0)*2+48));const C=new Map;for(const _ of g){const H=JSON.stringify([_.source,_.target].sort());C.set(H,(C.get(H)??0)+1)}const P=Math.max(1,...C.values());const E=P>1?P+1:1;const k=$$(e,l,{gapX:M*E,gapY:b*E,padding:o.boundaryPadding,marginX:o.marginX+40,marginY:o.marginY+40+(x?.height??0),shapesPerRow:e.layout.shapesPerRow??o.shapesPerRow,boundariesPerRow:e.layout.boundariesPerRow??o.boundariesPerRow,direction:a.direction==="TD"?"TB":a.direction,maxWidth:o.maxWidth});for(const _ of m)Object.assign(_,k.boxes.get(_.id));const v=[];for(const _ of e.boundaries){const H=p.get(_.id);Object.assign(H,k.boxes.get(_.id));const D=_.parentId&&p.get(_.parentId);if(D)D.children.push(H);else v.push(H)}O$(k.boxes,{nodes:m,groups:v,edges:g},a,s,oc(e));z$({nodes:m,groups:v,edges:g},s.lineWidth,e);const T=g.flatMap(_=>{const H=sl(_);return H?[{...H,id:_.id,label:"",shape:"rectangle"}]:[]});const A=g.flatMap(_=>rx(_,s.lineWidth).map(H=>({...H,id:_.id,label:"",shape:"rectangle"})));of([...m,...T,...A],g,v,Math.max(o.marginX,o.marginY)+(x?.height??0));const R=[...m,...p.values(),...T,...A];let I=Math.max(k.width,...R.map(_=>_.x+_.width+o.marginX),...g.flatMap(_=>[..._.points.map(H=>H.x+o.marginX),(_.labelPosition?.x??0)+(_.labelBlock?.width??0)/2+o.marginX]),x?x.width+o.marginX*2:0);let L=Math.max(k.height,...R.map(_=>_.y+_.height+o.marginY),...g.flatMap(_=>[..._.points.map(H=>H.y+o.marginY),(_.labelPosition?.y??0)+(_.labelBlock?.height??0)/2+o.marginY]));const $=Zy(e,o).map(_=>({..._,block:Be(_.label,{display:"literal",fontSize:s.edgeLabelFontSize,fontWeight:s.edgeLabelFontWeight,letterSpacing:s.edgeLetterSpacing,transform:s.edgeTextTransform,...o.maxWidth===void 0?{}:{maxWidth:Math.max(24,o.maxWidth-o.marginX*2-64)}})}));const B=Be("Legend",{display:"literal",fontSize:n?.text?.fontSize??13,fontWeight:n?.text?.fontWeight??600,letterSpacing:n?.text?.letterSpacing??0,transform:n?.text?.textTransform,...o.maxWidth===void 0?{}:{maxWidth:Math.max(24,o.maxWidth-o.marginX*2-24)}});const F=$.length?{x:o.marginX,y:L+12,width:Math.max(B.width+24,...$.map(_=>_.block.width+64)),height:B.height+20+$.reduce((_,H)=>_+H.block.height+10,0),heading:B,entries:$}:void 0;if(F){I=Math.max(I,F.x+F.width+o.marginX);L=F.y+F.height+o.marginY}const z=[...k.diagnostics,...G$(e,{nodes:m,groups:v,edges:g},s.lineWidth,{width:I,height:L})];if(o.maxWidth!==void 0&&I>o.maxWidth+.01)z.push({code:"C4_WIDTH_EXCEEDED",severity:"warning",message:`The requested C4 width ${o.maxWidth}px cannot contain the ${Math.ceil(I)}px artifact without shrinking or clipping content; minimum card widths, nesting, explicit direction constraints and authored offsets retain precedence.`});return{width:I,height:L,...F?{legend:F}:{},nodes:m,groups:v,edges:g,...x?{title:on(x,I,o.marginY)}:{},body:e,config:o,diagnostics:z,identities:oc(e),textContext:{node:s.nodeTextTransform,edge:s.edgeTextTransform,group:s.groupTextTransform,legendHeading:n?.text?.textTransform,title:w}}}function al(e){return e.split(/[:/\s-]+/).filter(Boolean).at(-1)?.slice(0,2).toUpperCase()||"?"}var l8=Object.freeze({book:Object.freeze(["M3 5.5C6 4.5 9 4.8 12 6V20C9 18.8 6 18.5 3 19.5Z","M21 5.5C18 4.5 15 4.8 12 6V20C15 18.8 18 18.5 21 19.5Z"]),skull:Object.freeze(["M5 11A7 7 0 1 1 19 11C19 15 17 17 15 18V21H9V18C7 17 5 15 5 11Z","M8 11A1.5 1.5 0 1 0 11 11A1.5 1.5 0 1 0 8 11ZM13 11A1.5 1.5 0 1 0 16 11A1.5 1.5 0 1 0 13 11Z","M10 17V20M12 17V20M14 17V20"])});function ll(e){const t=e.trim().toLowerCase().split(/\s+/).filter(Boolean);const n=t.findLast(a=>!["fa","fas","far","fab","mdi"].includes(a))??"";const i=n.replace(/^(?:fa-|mdi-)/,"");const r=i==="book-open"?"book":i==="skull-outline"?"skull":i;const o=l8[r];if(o)return{viewBox:"0 0 24 24",paths:o,source:"bundled-symbol"};const s=ya(e)??ya(`mdi:${i}`);return s?{viewBox:s.viewBox,paths:[s.path],source:s.source}:null}function XM(e,t,n){const{positioned:i,colors:r,resolved:o}=t;const s=o.renderOptions;const a=r.font??"Inter";const l=s.transparent??false;const c=[];const d=o.familyAppearance?.visual??s.stateVisual;const u=Ue(s,d?.styleDefaults,o.styleFace);c.push(e.documentOpen({id:"prelude",width:i.width,height:i.height,colors:r,transparent:l,font:a,hasMonoFont:false},Ot(i.width,i.height,r,l)+"\n"+Dt(a,false,r.shadow,r.embedFontImport)));const f=[];f.push("<defs>");const h=en(r);if(h)f.push(h);const m=new Set;const p=new Set;if(u.edgeStrokeColor)m.add(u.edgeStrokeColor);let g=false;let y=false;for(const C of i.edges){if(C.inlineStyle?.stroke)m.add(C.inlineStyle.stroke);if(C.inlineStyle?.["stroke-width"])p.add(C.inlineStyle.stroke??u.edgeStrokeColor);if(C.startMarker==="circle"||C.endMarker==="circle")g=true;if(C.startMarker==="cross"||C.endMarker==="cross")y=true}const w=gp(m,p,g,y);f.splice(1,0,mi(w));f.push("</defs>");c.push(e.definitions({id:"defs",markerResources:w},f.join("\n")));if(i.title)c.push(e.text(En(i.title,u)));for(const C of n?.surfaces===false?[]:i.groups){c.push(qM(e,C,a,u))}if(n?.beforeEdges)c.push(...n.beforeEdges());const S=new Set(i.nodes.map(C=>C.id));const x=C=>C.forEach(P=>{S.add(P.id);x(P.children)});x(i.groups);const M=new Map;const b=new Map;for(const C of i.edges){if(C.points.length<2)continue;const P=`${C.source}->${C.target}`;const E=M.get(P)??0;M.set(P,E+1);const k=`edge:${P}#${E}`;b.set(C,k);const v=C.id!==void 0&&!S.has(C.id)?C.id:k;c.push(u8(e,C,u,k,v,w))}for(const C of i.edges){const P=b.get(C);if(n?.edgeLabels!==false&&C.label&&P)c.push(f8(e,C,a,u,j$(P)))}for(const C of n?.surfaces===false?[]:i.nodes){c.push(h8(e,C,a,u,r,s.security!=="strict"))}for(const C of i.notes??[]){c.push(d8(e,C,a,u))}c.push(e.documentClose());return{family:"flowchart",width:i.width,height:i.height,colors:r,transparent:l,parts:c}}function qM(e,t,n,i,r){if(t.concurrencyRegion){return e.group({id:`group:${t.id}`,role:"group",open:`<g class="concurrency-region" data-id="${Ye(t.id)}"${r?` data-parent-id="${Ye(r)}"`:""}>`,close:"</g>",children:t.children.map(y=>({indent:0,node:qM(e,y,n,i,t.id)}))})}const o=t.labelBlock??Wn(qe(t.label,t.labelContent),i,"group");const s=t.headerHeight??i.groupHeaderFontSize+16+o.height-o.lineHeight;const a=[];const l=`<g class="subgraph" data-id="${Ye(t.id)}" data-region="subgraph" data-label="${hn(t.label)}"${r?` data-parent-id="${Ye(r)}"`:""}>`;const c=t.inlineStyle;const d=c?.fill??i.groupFillColor??"var(--_group-fill)";const u=c?.stroke??i.groupBorderColor??"var(--_node-stroke)";const f=c?.["stroke-width"]??String(i.groupLineWidth);a.push({indent:2,node:e.shape({id:`group-rect:${t.id}`,role:"group",geometry:{kind:"rect",x:t.x,y:t.y,width:t.width,height:t.height,rx:i.groupCornerRadius,ry:i.groupCornerRadius},paint:{fill:d,stroke:u,strokeWidth:f}})});const h=i.groupHeaderFillColor??"var(--_group-hdr)";const m=Tr(t.x,t.y,t.width,s,i.groupCornerRadius);a.push({indent:2,node:e.shape({id:`group-header:${t.id}`,role:"group-header",geometry:{kind:"path",d:m},paint:{fill:h,stroke:u,strokeWidth:f}})});const p=o.text;const g=c?.color??i.groupTextColor??"var(--_text-sec)";a.push({indent:2,node:e.text({id:`group-label:${t.id}`,role:"group-header",text:p,block:o,x:t.x+i.groupLabelPaddingX,y:t.y+s/2,fontSize:i.groupHeaderFontSize,anchor:"start",paint:{fill:g}})});for(const y of c8(t,s)){a.push({indent:2,node:e.shape({id:`region-separator:${t.id}:${y.index}`,role:"group",geometry:{kind:"line",x1:y.x1,y1:y.y1,x2:y.x2,y2:y.y2},paint:{stroke:u,strokeWidth:String(i.groupLineWidth),strokeDasharray:"6 4"},attributes:{className:"region-separator"}})})}for(const y of t.children){a.push({indent:0,node:qM(e,y,n,i,t.id)})}return e.group({id:`group:${t.id}`,role:"group",open:l,close:"</g>",children:a})}function c8(e,t){const n=e.children.filter(l=>l.concurrencyRegion);if(n.length<2)return[];const i=l=>Math.max(...n.map(l))-Math.min(...n.map(l));const r=i(l=>l.x+l.width/2)>=i(l=>l.y+l.height/2);const o=[...n].sort((l,c)=>r?l.x-c.x:l.y-c.y);const s=4;const a=[];for(let l=1;l<o.length;l++){const c=o[l-1],d=o[l];if(r){const u=(c.x+c.width+d.x)/2;a.push({index:l-1,x1:u,y1:e.y+t+s,x2:u,y2:e.y+e.height-s})}else{const u=(c.y+c.height+d.y)/2;a.push({index:l-1,x1:e.x+s,y1:u,x2:e.x+e.width-s,y2:u})}}return a}function d8(e,t,n,i){void n;const{x:r,y:o,width:s,height:a}=t;const l=i.groupHeaderFillColor??"var(--_group-hdr)";const c=i.groupBorderColor??"var(--_node-stroke)";const d=i.edgeTextColor??"var(--_text-sec)";const u=t.textBlock??Wn(qe(t.text,t.textContent),i,"note");const f=u.text;const h=`state-note:${t.id}`;return e.group({id:h,role:"note",open:`<g class="state-note" data-id="${Ye(t.id)}" data-target="${Ye(t.target)}" data-side="${t.side}">`,close:"</g>",children:[{indent:2,node:e.shape({id:`${h}:rect`,role:"note",geometry:{kind:"rect",x:r,y:o,width:s,height:a,rx:4,ry:4},paint:{fill:l,stroke:c,strokeWidth:String(et.innerBox)}})},{indent:2,node:e.text({id:`${h}:text`,role:"label",text:f,block:u,x:r+s/2,y:o+a/2,fontSize:i.edgeLabelFontSize,anchor:"middle",paint:{fill:d}})}]})}function u8(e,t,n,i,r,o){const s=t.style==="dotted"?"dotted":t.style==="thick"?"thick":t.style==="invisible"?"invisible":"solid";const a=j$(i);const l=t.labelPosition??sn(t.points);const c=n.edgeTextColor??"var(--_text-sec)";const d=t.label?[{id:`${i}:label`,text:t.label,textContent:{value:t.label,prepared:Rt(qe(t.label,t.labelContent))},anchor:l,paint:{fill:c},fontSize:n.edgeLabelFontSize,textAnchor:"middle",visual:{kind:"companion",markId:`${a}:text`}}]:[];const u=(t.classNames??[]).map(b=>b.replace(/[^A-Za-z0-9_-]/g,"")).filter(Boolean);const f={identity:{id:r,...u.length?{classNames:u}:{}},endpoints:{from:t.source,to:t.target},relationship:{kind:"flowchart-edge",direction:t.source===t.target?"self":t.hasArrowStart&&t.hasArrowEnd?"bidirectional":t.hasArrowStart?"reverse":t.hasArrowEnd?"forward":"undirected"},route:{ownership:"layout",bendRadius:n.edgeBendRadius,labelAnchors:t.labelPosition?[t.labelPosition]:[]},labels:d};if(t.style==="invisible"){return e.connector({id:i,role:"edge",geometry:{kind:"polyline",points:t.points},lineStyle:"invisible",paint:{},...f})}const h=tf(t,n);const m=t.style==="dotted"?`${Vc.dash} ${Vc.gap}`:t.animate?"8 4":void 0;const p=t.style==="thick"?n.lineWidth*2:n.lineWidth;const g=t.inlineStyle?.stroke??n.edgeStrokeColor;const y=`${g?`-${ld(g)}`:""}${t.inlineStyle?.["stroke-width"]?"-fixed":""}`;let w;let S;if(t.hasArrowEnd){const b=Hl(t.endMarker??"arrow");w=o.find(C=>C.id===`${b}${y}`);if(!w)throw new Error(`Missing marker resource "${b}${y}"`)}if(t.hasArrowStart){const b=Hl(t.startMarker??"arrow");S=o.find(C=>C.id===`${b}-start${y}`);if(!S)throw new Error(`Missing marker resource "${b}-start${y}"`)}const x={className:["edge",...u].join(" "),data:{style:t.style,"arrow-start":String(t.hasArrowStart),"arrow-end":String(t.hasArrowEnd),...t.hasArrowStart?{"marker-start":t.startMarker??"arrow"}:{},...t.hasArrowEnd?{"marker-end":t.endMarker??"arrow"}:{},...t.label?{label:jr(t.label)}:{},...t.curve?{curve:t.curve}:{},...t.animate?{animate:"true",animation:t.animation??"slow"}:{}}};const M={stroke:g??"var(--_line)",strokeWidth:t.inlineStyle?.["stroke-width"]??String(p),...m?{strokeDasharray:m}:{}};if(n.edgeBendRadius>0||t.curve){if(!h)throw new Error(`Missing path projection for flowchart edge "${i}"`);return e.connector({id:i,role:"edge",geometry:h.geometry,lineStyle:s,paint:M,markers:{...S?{start:S}:{},mid:[],...w?{end:w}:{}},...f,route:{...f.route,contours:h.contours},attributes:x})}return e.connector({id:i,role:"edge",geometry:{kind:"polyline",points:t.points},lineStyle:s,paint:M,markers:{...S?{start:S}:{},mid:[],...w?{end:w}:{}},...f,attributes:x})}function j$(e){return e.startsWith("edge:")?`edge-label:${e.slice("edge:".length)}`:`${e}:label`}function f8(e,t,n,i,r){const o=t.labelPosition??sn(t.points);const s=t.labelBlock??Wn(qe(t.label,t.labelContent),i,"edge");const a=s.text;const l=nn;const c=l+Ti(t,i.lineWidth);const d=s;const u=d.width+c*2;const f=d.height+c*2;const h=o.x-u/2;const m=o.y-f/2;const p=e.shape({id:`${r}:halo`,role:"chrome",geometry:{kind:"rect",x:h,y:m,width:u,height:f,rx:4,ry:4},paint:{fill:"var(--bg)",stroke:"none"},attributes:{className:"edge-label-halo"}});const g=d.width+l*2;const y=d.height+l*2;const w=e.shape({id:`${r}:pill`,role:"chrome",geometry:{kind:"rect",x:o.x-g/2,y:o.y-y/2,width:g,height:y,rx:2,ry:2},paint:{fill:"var(--bg)",stroke:"var(--_inner-stroke)",strokeWidth:"1"}});const S=i.edgeTextColor??"var(--_text-sec)";const x=e.text({id:`${r}:text`,role:"label",text:a,block:s,x:o.x,y:o.y,fontSize:i.edgeLabelFontSize,anchor:"middle",paint:{fill:S}});return e.group({id:r,role:"edge-label",open:`<g class="edge-label" data-from="${Ye(t.source)}" data-to="${Ye(t.target)}" data-label="${hn(t.label)}">`,close:"</g>",children:[{indent:2,node:p},{indent:2,node:w},{indent:2,node:x}]})}function h8(e,t,n,i,r,o){const s=p8(e,t,i);const a=g8(t,i,r);const l=y8(e,t,n,i,a);const c=(t.classNames??[]).map(y=>y.replace(/[^A-Za-z0-9_-]/g,"")).filter(Boolean);const d=["node",...t.shape==="state-note"?["state-note"]:[],...c].join(" ");const u=t.shape==="state-start"?{status:"start"}:t.shape==="state-end"?{status:"end"}:void 0;const f=[{indent:2,node:s}];const h=m8(e,t,a);if(h)f.push({indent:2,node:h});if(l){f.push({indent:2,node:l})}const m=t.semanticShape?` data-semantic-shape="${Ye(t.semanticShape)}"`:"";const p=o&&t.href?` data-href="${Ye(t.href)}" role="link" tabindex="0"`:"";const g=t.floatingNoteId===void 0?"":` data-floating-note-id="${Ye(t.floatingNoteId)}"`;return e.group({id:`node:${t.id}`,role:t.shape==="state-note"?"note":"node",open:`<g class="${d}" data-id="${Ye(t.id)}" data-label="${hn(t.label)}" data-shape="${t.shape}"${m}${p}${g}>`,close:"</g>",children:f,channels:u})}function m8(e,t,n){const i=Math.min(28,t.height*.4);const r=t.x+t.width/2;const o=t.y+6;if(t.icon){const s=ll(t.icon);if(s){const l=i/24;return e.pathArtwork({id:`node:${t.id}:icon`,paths:s.paths,owner:{id:t.id,role:"node"},open:`<g class="flowchart-icon" data-icon="${Ye(t.icon)}" transform="translate(${r-i/2} ${o}) scale(${l})">`,transform:{kind:"matrix",a:l,b:0,c:0,d:l,e:r-i/2,f:o},paint:{fill:n,stroke:n,strokeWidth:"0.8"}})}const a=al(t.icon);return e.text({id:`node:${t.id}:icon`,role:"icon",owner:{id:t.id,role:"node"},text:a,block:t.iconFallbackBlock,x:r,y:o+i/2,fontSize:10,anchor:"middle",paint:{fill:n},baselineShift:0,attributes:{className:"flowchart-icon-fallback",data:{icon:t.icon}}})}if(t.image){const s=r-i/2;const a=`M${s+2} ${o+i*.66}L${s+i*.36} ${o+i*.36}L${s+i*.52} ${o+i*.5}L${s+i*.7} ${o+i*.32}L${s+i-2} ${o+i*.66}`;const l={fill:"none",stroke:n,strokeWidth:"1.2"};const c={id:t.id,role:"node"};return e.group({id:`node:${t.id}:image`,role:"icon",owner:c,open:`<g class="flowchart-image-placeholder" data-image-src="${Ye(t.image)}">`,close:"</g>",join:"",children:[{indent:0,node:e.shape({id:`node:${t.id}:image:frame`,role:"icon",owner:c,geometry:{kind:"rect",x:s,y:o,width:i,height:i*.72,rx:2},paint:l})},{indent:0,node:e.shape({id:`node:${t.id}:image:sun`,role:"icon",owner:c,geometry:{kind:"circle",cx:s+i*.72,cy:o+i*.2,r:i*.08},paint:l})},{indent:0,node:e.shape({id:`node:${t.id}:image:landscape`,role:"icon",owner:c,geometry:{kind:"path",d:a},paint:l})}]})}return null}function p8(e,t,n){const{x:i,y:r,width:o,height:s,shape:a,inlineStyle:l}=t;const c=l?.fill??n.nodeFillColor??"var(--_node-fill)";const d=l?.stroke??n.nodeBorderColor??"var(--_node-stroke)";const u=l?.["stroke-width"]??String(n.nodeLineWidth);const f=_r(t,{fill:c,stroke:d,strokeWidth:u},n.cornerRadius);return e.shape({id:`node-shape:${t.id}`,role:t.shape==="state-note"?"note":"node",geometry:f.geometry,paint:f.paint,...f.childPaints?{childPaints:f.childPaints}:{}})}function g8(e,t,n){const i=t.nodeTextColor??(e.inlineStyle?.fill||!MR(e)?"var(--_text)":xi("var(--_text)",t.nodeFillColor??"var(--_node-fill)",n));return Bu(e.inlineStyle,i)}function y8(e,t,n,i,r){if(t.shape==="state-start"||t.shape==="state-end"||t.shape==="state-fork"||t.shape==="state-join"||t.shape==="state-choice"){if(!t.label)return null}const o=t.x+t.width/2;const s=t.y+t.height/2;const a=t.labelBlock??Wn(qe(t.label,t.labelContent),i,"node");const l=a.text;return e.text({id:`node-label:${t.id}`,role:"label",text:l,block:a,x:o,y:s,fontSize:i.nodeLabelFontSize,anchor:"middle",paint:{fill:r}})}var ox=gt(XM);function x8(e,t){const n=t.positioned,{body:i,config:r,identities:o}=n;const s=Ue(t.resolved.renderOptions,void 0,t.resolved.styleFace);const a=S=>S&&t.resolved.renderOptions.security!=="strict"&&ks(S)?` data-href="${Ye(S)}" role="link" tabindex="0"`:"";const l=(S,x)=>o.generated(`c4:${S}:${x}`,["c4",S,x]);const c=(S,x,M,b,C=false)=>e.shape({id:l(S,x),role:C?"group":"node",geometry:M,paint:b});const d=S=>[`data-id="${Ye(S.id)}"`,`data-c4-kind="${Ye(S.kind)}"`,`data-c4-macro="${Ye(S.macro)}"`,...S.parentId?[`data-parent-id="${Ye(S.parentId)}"`]:[],...S.tags.length?[`data-tags="${Ye(JSON.stringify(S.tags))}"`]:[],...a(S.effectiveLink??S.link)?[a(S.effectiveLink??S.link)]:[],...S.sprite?[`data-sprite="${Ye(S.sprite)}"`]:[],...T0(i,S.statementId)!==void 0?[`data-source-line="${T0(i,S.statementId)}"`]:[],..."external"in S?[`data-external="${S.external}"`,`data-c4-shape="${S.shape}"`,`data-effective-c4-shape="${Ao(S)}"`]:[`data-alignment="${S.alignment??"center"}"`]].join(" ");const u=(S,x)=>{const{x:M,y:b,width:C,height:P}=x,E=Xs(S,r),k=Ao(S);const v=E.fill??s.nodeFillColor??"var(--_node-fill)",T=E.stroke??s.nodeBorderColor??"var(--_node-stroke)",A=E.text??Bu(E.fill?{fill:E.fill}:void 0,s.nodeTextColor??xi("var(--_text)",v,t.colors)),R=String(s.nodeLineWidth);const I={fill:v,stroke:T,strokeWidth:R,...E.dashed?{strokeDasharray:"5 3"}:{}};const L=[],$=_=>L.push({node:_,indent:2});if(k==="database"){const _=8,H=`M ${M} ${b+_} A ${C/2} ${_} 0 0 1 ${M+C} ${b+_} L ${M+C} ${b+P-_} A ${C/2} ${_} 0 0 1 ${M} ${b+P-_} Z`;$(c(S.id,"surface",{kind:"path",d:H},I));$(c(S.id,"database-rim",{kind:"ellipse",cx:M+C/2,cy:b+_,rx:C/2,ry:_},{fill:"none",stroke:T,strokeWidth:"1"}))}else{$(c(S.id,"surface",{kind:"rect",x:M,y:b,width:C,height:P,rx:s.cornerRadius??0,ry:s.cornerRadius??0},I));if(k==="queue")for(const[_,H]of[M+8,M+C-8].entries())$(c(S.id,`queue-end:${_}`,{kind:"line",x1:H,y1:b,x2:H,y2:b+P},{stroke:T,strokeWidth:"1"}));if(k==="person"){const _=M+C/2,H=b+P/2+19-x.labelBlock.height/2,D=H-31;const j={fill:A,stroke:A,strokeWidth:"1"};$(c(S.id,"person-head",{kind:"circle",cx:_,cy:D,r:7},j));const W=`M ${_-16} ${D+26} Q ${_-16} ${D+11} ${_} ${D+11} Q ${_+16} ${D+11} ${_+16} ${D+26} Z`;$(c(S.id,"person-shoulders",{kind:"path",d:W},j))}}const B=x.labelBlock,F=M+C/2,z=b+P/2+(k==="person"?19:k==="database"?4:0);$(e.text({id:l(S.id,"text"),role:"label",text:B.text,block:B,x:F,y:z,fontSize:B.fontSize,fontWeight:B.fontWeight,letterSpacing:B.letterSpacing,anchor:"middle",paint:{fill:A}}));return e.group({id:l(S.id,"card"),role:"node",open:`<g class="node c4-${S.kind}" ${d(S)}>`,close:"</g>",children:L,channels:{category:`${S.external?"external-":""}${S.kind}`,...S.tags.length?{status:S.tags.join(",")}:{}}})};const f=new Map(i.boundaries.map(S=>[S.id,S]));const h=S=>{const x=f.get(S.id),M=Xs(x,r),{x:b,y:C,width:P,height:E}=S;const k=M.stroke??s.groupBorderColor??"var(--_node-stroke)",v=M.fill??s.groupFillColor??"var(--_group-fill)",T=M.fill??s.groupHeaderFillColor??"var(--_group-hdr)",A=M.text??Bu(M.fill?{fill:M.fill}:void 0,s.groupTextColor??xi("var(--_text-sec)",T,t.colors)),R=S.headerHeight??36;const I=[],L=W=>I.push({node:W,indent:2});const $=x.style.lineStyle==="solid"?void 0:x.style.lineStyle==="dotted"?"1 3":x.style.lineStyle==="dashed"?"5 3":x.kind==="deployment"?void 0:"6 4";L(c(x.id,"boundary-frame",{kind:"rect",x:b,y:C,width:P,height:E,rx:s.groupCornerRadius,ry:s.groupCornerRadius},{fill:v,stroke:k,strokeWidth:String(s.groupLineWidth),...$?{strokeDasharray:$}:{}},true));const B=Tr(b,C,P,R,s.groupCornerRadius);const F={kind:"path",d:B},z={fill:T,stroke:k,strokeWidth:String(s.groupLineWidth)};L(e.shape({id:l(x.id,"boundary-band"),role:"group-header",geometry:F,paint:z}));const _=S.labelBlock,H=x.alignment==="left"?"start":x.alignment==="right"?"end":"middle",D=x.alignment==="left"?b+r.padding:x.alignment==="right"?b+P-r.padding:b+P/2,j=C+R/2;L(e.text({id:l(x.id,"boundary-text"),role:"group-header",text:_.text,block:_,x:D,y:j,fontSize:_.fontSize,fontWeight:_.fontWeight,letterSpacing:_.letterSpacing,anchor:H,paint:{fill:A}}));for(const W of S.children)L(h(W));return e.group({id:l(x.id,"frame"),role:"group",open:`<g class="cluster c4-boundary" ${d(x)}>`,close:"</g>",children:I,channels:{category:x.kind}})};const m=new Map(i.relationships.map(S=>[S.id,S]));const p=S=>{const x=Wo(S);const M=m.get(x.identity?.id??"");if(!M)return e.connector(S);const b=M.style.lineStyle==="dotted"?{...x.stroke,dash:{array:"1 3"}}:x.stroke;const C=t.resolved.renderOptions.security==="strict"?void 0:M.effectiveLink??M.link;const{markers:P}=x,E=x.labels[0];const k={className:"edge",data:{style:x.lineStyle,"arrow-start":String(!!P.start),"arrow-end":String(!!P.end),...P.start?{"marker-start":P.start.shape}:{},...P.end?{"marker-end":P.end.shape}:{},...E?{label:jr(E.text)}:{},"c4-macro":M.macro,"authored-from":M.from,"authored-to":M.to,order:String(M.order),...M.index!==void 0?{index:M.index}:{},...M.tags.length?{tags:JSON.stringify(M.tags)}:{},...C&&ks(C)?{href:C}:{}},...C&&ks(C)?{tabIndex:0}:{}};const v={id:l(M.id,"relationship"),role:"edge",identity:x.identity,geometry:x.route.geometry,paint:{stroke:b.color,strokeWidth:String(b.width)},lineStyle:x.lineStyle,endpoints:x.endpoints,relationship:{...x.relationship,kind:`c4-${M.macro}`},route:x.route,stroke:b,markers:x.markers,hit:x.hit,labels:x.labels.map(T=>({...T,visual:{kind:"companion",markId:l(M.id,"label-text")},...M.style.textColor?{paint:{...T.paint,fill:M.style.textColor}}:{}})),channels:{category:"relationship",...M.tags.length?{status:M.tags.join(",")}:{}},attributes:k};return e.connector(v)};const g=XM({...e,connector:p},t,{surfaces:false,edgeLabels:false,beforeEdges:()=>n.groups.map(h)});const y=g.parts;const w=n.edges.flatMap(S=>{if(!S.label||!S.labelBlock||!S.labelPosition)return[];const x=m.get(S.id),M=S.labelBlock,{x:b,y:C}=S.labelPosition,P=x.style.textColor??x.style.fontColor??s.edgeTextColor??"var(--_text-sec)";const E=sl(S),k={kind:"rect",...E,rx:3,ry:3},v={fill:"var(--bg)",stroke:"var(--_inner-stroke)",strokeWidth:"1"};return[e.group({id:l(x.id,"relationship-label"),role:"edge-label",open:`<g class="edge-label" data-id="${Ye(l(x.id,"label"))}" data-role="edge-label" data-edge-id="${Ye(x.id)}" data-from="${Ye(x.source)}" data-to="${Ye(x.target)}">`,close:"</g>",children:[{indent:2,node:e.shape({id:l(x.id,"label-halo"),role:"chrome",geometry:k,paint:v})},{indent:2,node:e.text({id:l(x.id,"label-text"),role:"label",text:M.text,block:M,x:b,y:C,fontSize:M.fontSize,fontWeight:M.fontWeight,letterSpacing:M.letterSpacing,anchor:"middle",paint:{fill:P},pageFill:x.style.textColor??x.style.fontColor??xi("var(--_text-sec)","var(--bg)",t.colors)})}]})]});y.splice(y.length-1,0,...w,...n.nodes.map(S=>u(i.elements.find(x=>x.id===S.id),S)));if(n.legend){const S=n.legend,x=[];const M=It(t.resolved.styleFace,"legend",{},{includeFallback:false});const b=M?.textColor??"var(--_text)";const C=S.heading,P=S.x+12,E=S.y+8+C.height/2;const k=e.text({id:l("legend","heading"),role:"legend",text:C.text,block:C,x:P,y:E,fontSize:C.fontSize,fontWeight:C.fontWeight,letterSpacing:C.letterSpacing,anchor:"start",paint:{fill:b}});x.push({node:k,indent:2});let v=S.y+20+C.height;for(const T of S.entries){const{block:A}=T,R=S.x+38,I=v+A.height/2;const L=T.style.borderColor??T.style.lineColor??M?.strokeColor??M?.borderColor??s.nodeBorderColor??"var(--_line)";const $=T.style.bgColor??M?.fillColor??s.nodeFillColor??"var(--_node-fill)",B=String(M?.lineWidth??1);const F=T.style.lineStyle==="dotted"?"1 3":T.style.lineStyle==="dashed"||T.external?"5 3":void 0;const z={fill:$,stroke:L,strokeWidth:B,...F?{strokeDasharray:F}:{}};const _=S.x+10,H=18,D=A.height;const j=(O,N)=>x.push({indent:2,node:e.shape({id:l(T.id,O),role:"legend",geometry:N,paint:z})});if(T.kind==="relationship")j("legend-swatch",{kind:"line",x1:_,y1:I,x2:_+H,y2:I});else if(T.shape==="database"){const O=Math.min(3,D/4),N=`M ${_} ${v+O} A 9 ${O} 0 0 1 ${_+H} ${v+O} L ${_+H} ${v+D-O} A 9 ${O} 0 0 1 ${_} ${v+D-O} Z`;j("legend-swatch",{kind:"path",d:N});j("legend-rim",{kind:"ellipse",cx:_+9,cy:v+O,rx:9,ry:O})}else if(T.shape==="person"){const O=Math.min(3,D/5),N=_+9;j("legend-head",{kind:"circle",cx:N,cy:v+O,r:O});const G=`M ${_+3} ${v+D} Q ${_+3} ${v+O*2.5} ${N} ${v+O*2.5} Q ${_+15} ${v+O*2.5} ${_+15} ${v+D} Z`;j("legend-swatch",{kind:"path",d:G})}else{j("legend-swatch",{kind:"rect",x:_,y:v,width:H,height:D});if(T.shape==="queue")for(const[O,N]of[_+3,_+15].entries())j(`legend-end:${O}`,{kind:"line",x1:N,y1:v,x2:N,y2:v+D})}const W=b;x.push({indent:2,node:e.text({id:l(T.id,"legend-text"),role:"legend",text:A.text,block:A,x:R,y:I,fontSize:A.fontSize,fontWeight:A.fontWeight,letterSpacing:A.letterSpacing,anchor:"start",paint:{fill:W}})});v+=A.height+10}y.splice(y.length-1,0,e.group({id:l("legend","container"),role:"legend",open:'<g class="c4-legend">',close:"</g>",children:x}))}return{...g,family:"c4",parts:y}}var Y$=gt(x8);var $Me={configDiagnostics:F$,normalizeRequest:e=>{const t=e.source.authoredWrapperLength??e.source.wrapperSource?.length??0;const n=e.source.originalText.slice(0,t);const i=kL(e.source.originalText.slice(t));const r=n.split(/\r\n?|\n/).length-1;for(const s of i.statements){s.span.start+=n.length;s.span.end+=n.length;s.span.line+=r}const o=Nr(e.source.frontmatter);if(i.title===void 0&&o!==void 0)i.title=o;if(e.source.accessibility.title!==void 0)i.accessibilityTitle=e.source.accessibility.title;if(e.source.accessibility.descr!==void 0)i.accessibilityDescription=e.source.accessibility.descr;return{familyConfig:{model:i,c4:e.source.config.c4??{},themeVariables:e.source.config.themeVariables??{}}}},layout:e=>{const t=e.familyConfig;return ht(H$(t.model,e.renderOptions,e.styleFace,t.c4,t.themeVariables))},projectPositioned:ut(N$),lowerScene:ft(Y$)};function eu(e,t={}){const n=e<=6?{accent:t.accent&&_h(t.accent)?t.accent:oa,bg:t.bg&&_h(t.bg)?t.bg:void 0}:t;const i=Zi(e,n);const r=t.overrides;if(!r||r.length===0)return i;return i.map((o,s)=>r[s%12]??o)}function q$(e,t){return Object.hasOwn(e.nodeColors,t)?e.nodeColors[t]:void 0}var UM={width:600,height:400,linkColor:{mode:"gradient"},nodeAlignment:"justify",showValues:true,prefix:"",suffix:"",labelStyle:"legacy",nodeWidth:10,nodePadding:12,nodeColors:{}};var b8=["justify","center","left","right"];var S8=["legacy","outlined"];var w8=["source","target","gradient"];var er=Object.freeze({width:{min:1,max:1e4},height:{min:1,max:1e4},nodeWidth:{min:1,max:200},nodePadding:{min:0,max:200}});function sx(e,t,n){if(typeof e!=="number"||!Number.isFinite(e))return void 0;if(e<t||e>n)return void 0;return e}function VM(e={}){const t=Sn(e,["sankey"])??{};const n={...UM};const i=sx(t.width,er.width.min,er.width.max);if(i!==void 0)n.width=i;const r=sx(t.height,er.height.min,er.height.max);if(r!==void 0)n.height=r;const o=sx(t.nodeWidth,er.nodeWidth.min,er.nodeWidth.max);if(o!==void 0)n.nodeWidth=o;const s=sx(t.nodePadding,er.nodePadding.min,er.nodePadding.max);if(s!==void 0)n.nodePadding=s;const a=t.nodeAlignment;if(typeof a==="string"&&b8.includes(a)){n.nodeAlignment=a}const l=t.labelStyle;if(typeof l==="string"&&S8.includes(l)){n.labelStyle=l}if(typeof t.showValues==="boolean")n.showValues=t.showValues;if(typeof t.prefix==="string")n.prefix=t.prefix;if(typeof t.suffix==="string")n.suffix=t.suffix;const c=t.linkColor;if(typeof c==="string"){if(w8.includes(c)){n.linkColor={mode:c}}else{const u=mn(c,true);if(u!==void 0)n.linkColor={mode:"static",color:u}}}const d=Sn(e,["sankey","nodeColors"]);if(d){const u={};for(const[f,h]of Object.entries(d)){const m=mn(h,n.linkColor.mode!=="gradient");if(m!==void 0)u[f]=m}if(Object.keys(u).length>0)n.nodeColors=Object.freeze(u)}return n}function ax(e){const t=e&&typeof e==="object"&&!Array.isArray(e)?e:{};const n=t.commitLabelFontSize;const i=typeof n==="number"?n:typeof n==="string"?Number.parseFloat(n):11;return Number.isFinite(i)&&i>0?i:11}function KM(e,t){const n={commitLabelFontSize:ax(t)};if(!e||typeof e!=="object"||Array.isArray(e))return n;const i=e;for(const r of["showBranches","showCommitLabel","rotateCommitLabel","parallelCommits"]){if(typeof i[r]==="boolean")n[r]=i[r]}if(typeof i.mainBranchName==="string"&&i.mainBranchName.trim())n.mainBranchName=i.mainBranchName.trim();if(typeof i.mainBranchOrder==="number"&&Number.isFinite(i.mainBranchOrder))n.mainBranchOrder=i.mainBranchOrder;return n}function X$(e,t,n={},i){return zI(e,{...t,renderOptions:n,styleFace:i})}function U$(e){const t=Ma(e);if(!t.includes("\r"))return t.split("\n");const n=t.split(/\r|\n/);const i=t.match(/\r|\n/g)??[];const r=[];let o="";let s=0;let a=false;let l=-1;for(let c=0;c<n.length;c++){const d=n[c];o+=d;if(!a&&c>l){if(d.trimStart().startsWith("%%"))l=c;else{const u=vt(n,c);if(u)l=u.endIndex;else if(u===void 0)l=n.length-1}}if(c>l){for(let u=0;u<d.length;u++){if(d[u]!=='"')continue;if(a&&d[u+1]==='"')u++;else a=!a}}if(a&&i[c]!==void 0){o+=i[c]==="\r"?"\r":"\n";s++}else{r.push(o);while(s>0){r.push("");s--}o=""}}return r}var V$=["actorMargin","width","height","diagramMarginX","diagramMarginY","messageMargin","noteMargin","activationWidth"];var VMe=[...V$,"showSequenceNumbers","wrap"];function K$(e){if(!e)return{};const t={};for(const o of V$){const s=Mt(e,["sequence",o]);if(typeof s==="number"&&Number.isFinite(s)&&s>=0)t[o]=s}const n=Mt(e,["sequence","showSequenceNumbers"]);if(n===true)t.showSequenceNumbers=true;const i=Mt(e,["wrap"]);const r=Mt(e,["sequence","wrap"]);if(typeof i==="boolean")t.wrap=i;else if(typeof r==="boolean")t.wrap=r;return t}var M8={padding:Oa(0),iconSize:Oa(0,true),fontSize:Oa(0,true),nodeSeparation:Oa(0),idealEdgeLengthMultiplier:Oa(0,true)};var J$=e=>xt("architecture",e,M8);var Q$={fill:"var(--arch-edge-stroke, var(--_arrow))",stroke:"var(--arch-edge-stroke, var(--_arrow))",strokeWidth:"0.75",strokeLinejoin:"round"};var tu=[fr("architecture-arrow-end",{width:8,height:5},"end",Q$),fr("architecture-arrow-start",{width:8,height:5},"start",Q$)];var nu=xr(tu);var lx=e=>e.trim().toLowerCase().split(/[:/]/).pop()??e.trim().toLowerCase();function JM(e){const t=lx(e).replace(/[^a-z0-9]/g,"");return(t[0]??"?").toUpperCase()}function QM(e,t){if(!e||ya(e)||["cloud","database","disk","internet","server"].includes(lx(e)))return void 0;return Be(JM(e),{fontSize:Math.max(10,t*.56),fontWeight:700})}function iu(e){throw new Error(`LAYOUT_HINT_INVALID: ${e}`)}function Z$(e,t,n){if(!n)return;const i=new Map;const r=u=>{for(const f of u.children??[]){i.set(f.id,{node:f,parent:u});r(f)}};r(e);const o=u=>{const f=i.get(u);if(!f||!t.nodes.has(u))iu(`unknown node "${u}"`);return f};const s=new Set;if(n.ranks){for(const[u,f]of Object.entries(n.ranks)){const{node:h,parent:m}=o(u);if(!Number.isSafeInteger(f)||f<0||f>1e4)iu(`rank for "${u}" must be an integer in [0,10000]`);s.add(m);m.layoutOptions={...m.layoutOptions,"elk.partitioning.activate":"true"};h.layoutOptions={...h.layoutOptions,"elk.partitioning.partition":String(f)}}}for(const u of s)for(const f of u.children??[]){f.layoutOptions={"elk.partitioning.partition":"0",...f.layoutOptions}}const a=new Set;for(const u of n.adjacent??[]){if(u.length<2)iu("adjacent needs two or more nodes");const f=u.map(o);const h=f[0].parent;if(f.some(g=>g.parent!==h))iu("adjacent nodes need the same container");for(const g of u){if(a.has(g))iu("a node cannot repeat in adjacency groups");a.add(g)}const m=h.children;const p=Math.min(...f.map(g=>m.indexOf(g.node)));h.children=[...m.slice(0,p),...f.map(g=>g.node),...m.slice(p).filter(g=>!u.includes(g.id))];h.layoutOptions={...h.layoutOptions,"elk.layered.crossingMinimization.forceNodeModelOrder":"true"}}const l=Fd(t.edges);const c=new Set((n.shortEdges??[]).map(u=>{const f=l.get(u);if(f===void 0)iu(`unknown edge "${u}"`);return f}));const d=u=>{for(const f of u.edges??[]){const h=/^e(\d+)(?:_|$)/.exec(f.id);if(h&&c.has(Number(h[1])))f.layoutOptions={...f.layoutOptions,"elk.layered.priority.shortness":"100","elk.layered.priority.direction":"100"}}u.children?.forEach(d)};d(e)}function ZM(e){if(e.nodes.size<2||e.subgraphs.length>0||e.stateNotes?.length||e.edges.length>=e.nodes.size||[...e.nodes.values()].some(r=>r.shape!=="rectangle"))return false;const t=new Map,n=new Map;for(const r of e.edges){if(r.label!==void 0||(r.length??1)!==1||r.source===r.target||!e.nodes.has(r.source)||!e.nodes.has(r.target)||t.has(r.target))return false;t.set(r.target,1);const o=n.get(r.source);if(o)o.push(r.target);else n.set(r.source,[r.target])}const i=[...e.nodes.keys()].filter(r=>!t.has(r));for(let r=0;r<i.length;r++)for(const o of n.get(i[r])??[])i.push(o);return i.length===e.nodes.size}function ek(e,t,n,i,r){const o=t.children;if(!o||o.length<2||e.subgraphs.length>0||e.stateNotes?.length||o.length!==e.nodes.size||e.edges.some(c=>c.label!==void 0||(c.length??1)!==1)||[...e.nodes.values()].some(c=>c.shape!=="rectangle")||![n,i,r].every(c=>Number.isFinite(c)&&c>=0)||i===0||r===0)return void 0;const s=new Map(o.map((c,d)=>[c.id,d]));const a=e.edges.map(c=>({source:s.get(c.source)??-1,target:s.get(c.target)??-1,minSpan:1}));const l=dy({nodes:o.map(c=>({id:c.id,width:c.width,height:c.height})),edges:a,direction:e.direction,padding:n,nodeSpacing:i,layerSpacing:r});if(!l)return void 0;return{...t,width:l.width,height:l.height,children:o.map((c,d)=>({...c,...l.nodes[d]})),edges:e.edges.map((c,d)=>{const u=l.edges[d].points;return{id:`e${d}`,sources:[c.source],targets:[c.target],sections:[{id:`e${d}_s0`,startPoint:u[0],bendPoints:u.slice(1,-1),endPoint:u.at(-1)}]}})}}function _o(e,t,n){const i=e.labelBlock??vi(qe(e.label,e.labelContent),n);return{x:t.x-(i.width+16)/2,y:t.y-(i.height+16)/2,width:i.width+16,height:i.height+16}}function tk(e){let t=[e[0],e[e.length-1]];let n=-1;for(let i=1;i<e.length;i++){const r=e[i-1],o=e[i];const s=Math.hypot(o.x-r.x,o.y-r.y);if(s>n){n=s;t=[r,o]}}return{x:(t[0].x+t[1].x)/2,y:(t[0].y+t[1].y)/2}}function Wh(e){return Math.max(8,e.edgeLabelFontSize*.75)}function Pc(e){return Math.max(12,e.edgeLabelFontSize)}function k8(e,t){const n=e.lineWidth??1;const i=t.style==="thick"?n*2:n;return Math.max(18,e.edgeLabelFontSize+bn.width+i*2)}function n_(e){const t=e.lineWidth??1;const n=t*2;return Math.max(18,e.edgeLabelFontSize+bn.width+n*2)}function C8(){return Vc.dash*3+Vc.gap*2}function nk(e){return n_(e)+C8()}function cx(e,t,n){return Math.abs(n.x-t.x)>=Math.abs(n.y-t.y)?e.width/2:e.height/2}function i_(e,t,n,i,r,o){const s=k8(o,e);if(e.hasArrowStart&&n===1){const a=t[0];const l=cx(r,a,t[1]);if(Math.hypot(i.x-a.x,i.y-a.y)<l+s)return false}if(e.hasArrowEnd&&n===t.length-1){const a=t[t.length-1];const l=cx(r,t[t.length-2],a);if(Math.hypot(i.x-a.x,i.y-a.y)<l+s)return false}return true}function P8(e,t,n,i){return{start:e.hasArrowStart&&n===1?n_(i):Pc(i),end:e.hasArrowEnd&&n===t.length-1?nk(i):Pc(i)}}function E8(e,t,n){return _t(n).isHorizontal?Math.abs(e.y-t.y)<.01:Math.abs(e.x-t.x)<.01}function R8(e,t,n,i,r){const o=cx(e,n,i);return Math.hypot(t.x-n.x,t.y-n.y)>=o+r.start&&Math.hypot(t.x-i.x,t.y-i.y)>=o+r.end}function v8(e,t,n,i){const r=Math.hypot(n.x-t.x,n.y-t.y);if(r===0)return[];const o=cx(e,t,n);const s=(o+i.start)/r;const a=1-(o+i.end)/r;if(s>a)return[];return[(s+a)/2]}function r_(e,t,n,i,r){if(!e.label)return 0;const o=_t(t);const s=_o(e,{x:0,y:0},n);const a=o.isHorizontal?s.width:s.height;const l=Math.max(Pc(n),e.hasArrowEnd?nk(n):Pc(n));const c=(r-i)*o.sign;const d=(c-a)/3;if(d>=l-.001)return a+d*2;return a+Pc(n)+l+2}function o_(e,t,n){if(!e.label)return 0;const i=_o(e,{x:0,y:0},n);const r=_t(t).isHorizontal?i.width:i.height;const o=Math.max(Pc(n),e.hasArrowEnd?nk(n):Pc(n));return r+o*3}function ru(e,t,n,i,r,o){if(!e.label)return[];const s=$p(t);if(s===0)return[];const a=s/2;const l=[];const c=[.5,.45,.55,.4,.6,.35,.65,.3,.7,.25,.75,.2,.8,1/6,5/6];let d=0;for(let u=1;u<t.length;u++){const f=t[u-1],h=t[u];const m=Math.hypot(h.x-f.x,h.y-f.y);if(m===0)continue;const p=E8(f,h,i);const g=e.hasArrowStart&&u===1||e.hasArrowEnd&&u===t.length-1;const y=_o(e,{x:0,y:0},r);const w=P8(e,t,u,r);const S=[...c,...v8(y,f,h,w)].filter((C,P,E)=>C>=0&&C<=1&&E.findIndex(k=>Math.abs(k-C)<.001)===P);const x=Math.abs(f.x-h.x)<.01;const M=Math.min(y.height/2+3,(x?y.width:y.height)/2-1);const b=o?[0,M/4,-M/4,M/2,-M/2,M,-M]:[0];for(let C=0;C<S.length;C++){const P=S[C];for(const E of b){const k={x:f.x+(h.x-f.x)*P+(x?E:0),y:f.y+(h.y-f.y)*P+(x?0:E)};const v=_o(e,k,r);if(n.some(R=>Fi(v,R,2)))continue;if(!i_(e,t,u,k,v,r))continue;const T=R8(v,k,f,h,w);const A=x?v.y>=Math.min(f.y,h.y)&&v.y+v.height<=Math.max(f.y,h.y):v.x>=Math.min(f.x,h.x)&&v.x+v.width<=Math.max(f.x,h.x);if(o&&(!T||!A||!o(e,k)))continue;l.push({point:k,box:v,order:C,rank:0,pathDistance:d+m*P,routeMidpointDistance:Math.abs(d+m*P-a),segmentMidpointDistance:Math.abs(m*(P-.5)),straightRunPenalty:p&&T?0:p?2:10,terminalSegmentPenalty:g?1:0})}}d+=m}l.sort((u,f)=>u.straightRunPenalty-f.straightRunPenalty||u.terminalSegmentPenalty-f.terminalSegmentPenalty||u.segmentMidpointDistance-f.segmentMidpointDistance||u.routeMidpointDistance-f.routeMidpointDistance||u.order-f.order||u.pathDistance-f.pathDistance);return l.map((u,f)=>({...u,rank:f}))}function e_(e,t,n,i,r){return ru(e,t,n,i,r)[0]?.point??sn(t)}function T8(e,t){const n=_t(t);const i=e.map(d=>d.point[n.main]);const r=Math.max(...i)-Math.min(...i);const o=e.reduce((d,u)=>d+u.straightRunPenalty,0);const s=e.reduce((d,u)=>d+u.terminalSegmentPenalty,0);const a=e.reduce((d,u)=>d+u.segmentMidpointDistance,0);const l=e.reduce((d,u)=>d+u.routeMidpointDistance,0);const c=e.reduce((d,u)=>d+u.rank,0);return o*1e4+r*100+s*1e3+a*4+c*.25+l*.1}function t_(e,t){let n=0;const i=[];for(let a=1;a<t.length;a++){const l=Math.hypot(t[a].x-t[a-1].x,t[a].y-t[a-1].y);i.push(l);n+=l}let r=Infinity,o=0,s=0;for(let a=1;a<t.length;a++){const l=t[a-1],c=t[a],d=c.x-l.x,u=c.y-l.y,f=d*d+u*u;let h=f?((e.x-l.x)*d+(e.y-l.y)*u)/f:0;h=Math.max(0,Math.min(1,h));const m=l.x+h*d,p=l.y+h*u,g=Math.hypot(e.x-m,e.y-p);if(g<r){r=g;o=s+h*i[a-1]}s+=i[a-1]}return n?o/n:.5}function L8(e,t){const n=_t(t);const i=e.map(s=>s[n.main]);const r=(Math.min(...i)+Math.max(...i))/2;let o=null;for(let s=1;s<e.length;s++){const a=e[s-1],l=e[s];const c=Math.min(a[n.main],l[n.main]),d=Math.max(a[n.main],l[n.main]);if(r<c-1e-6||r>d+1e-6)continue;const u=l[n.main]-a[n.main];if(Math.abs(u)<=1e-6)continue;const f=(r-a[n.main])/u;const h={[n.main]:r,[n.cross]:a[n.cross]+f*(l[n.cross]-a[n.cross])};if(Math.abs(a[n.cross]-l[n.cross])<.01)return h;o??=h}return o}function A8(e,t,n,i,r,o=[],s=0){if(!e.label||!e.labelPosition)return;const a=L8(t,i);if(!a)return;const l=Math.abs(t_(e.labelPosition,t)-.5);const c=Math.abs(t_(a,t)-.5);if(c>=l-1e-6)return;const d=_o(e,a,r);if(n.some(f=>Fi(d,f,2)))return;if(o.some(f=>Fi(d,f,s)))return;const u=_t(i);for(let f=1;f<t.length;f++){const h=t[f-1],m=t[f];const p=Math.min(h[u.main],m[u.main]),g=Math.max(h[u.main],m[u.main]);if(Math.abs(m[u.main]-h[u.main])<=1e-6)continue;if(a[u.main]<p-1e-6||a[u.main]>g+1e-6)continue;if(!i_(e,t,f,a,d,r))return;break}e.labelPosition=a}function ou(e,t,n,i,r=false,o){const s=e.filter(({edge:c})=>c.label);if(s.length===0)return true;if(s.length===1){const c=s[0];const d=ru(c.edge,c.points,t,n,i,o);if(o&&d.length===0)return false;c.edge.labelPosition=d[0]?.point??sn(c.points)}else{const c=s.map(({edge:d,points:u})=>ru(d,u,t,n,i,o));if(c.some(d=>d.length===0)){if(o)return false;for(const{edge:d,points:u}of s)d.labelPosition=e_(d,u,t,n,i)}else{const d=Wh(i);let u;let f=Number.POSITIVE_INFINITY;const h=[];const m=p=>{if(p===c.length){const g=T8(h,n);if(g<f){f=g;u=h.slice()}return}for(const g of c[p]){if(h.some(y=>Fi(g.box,y.box,d)))continue;h.push(g);m(p+1);h.pop()}};m(0);if(!u){if(o)return false;for(const{edge:p,points:g}of s)p.labelPosition=e_(p,g,t,n,i)}else{for(let p=0;p<s.length;p++)s[p].edge.labelPosition=u[p].point}}}if(!r)return true;const a=[];const l=Wh(i);for(const{edge:c}of s){if(c.labelPosition)a.push(_o(c,c.labelPosition,i))}for(let c=0;c<s.length;c++){const{edge:d,points:u}=s[c];const f=d.labelPosition;const h=a.filter((m,p)=>p!==c);A8(d,u,t,n,i,h,l);if(d.labelPosition&&d.labelPosition!==f)a[c]=_o(d,d.labelPosition,i)}return true}function I8(e,t,n,i,r){const o=(d,u)=>Math.min(d.x1,u.x1)-Math.max(d.x0,u.x0)>1e-6&&Math.min(d.y1,u.y1)-Math.max(d.y0,u.y0)>1e-6;const s=d=>({x0:d.x,y0:d.y,x1:d.x+d.width,y1:d.y+d.height});const a=new Map(e.map(d=>[d.id,d]));const l=new Map(t.map(d=>[d.id,d]));const c=n.flatMap(d=>{const u=kt(d,r);if(!u)return[];const f=Math.max(4,r.lineWidth*(d.style==="thick"?2:1)*2);return[{x0:u.x-f,y0:u.y-f,x1:u.x+u.w+f,y1:u.y+u.h+f}]});for(const d of c){if(t.some((u,f)=>o(d,s(u))&&!o(d,s(e[f]))))return false}for(const d of n){const u=br(d,r);if(u.length===0)continue;let f=d.points;const h=l.get(d.source),m=l.get(d.target);if(h)f=Ea(f,h,true);if(m)f=Ea(f,m,false);const p={...d,points:f};mc(t,[p],i,r);f=p.points;for(const y of[true,false]){if(!(y?d.hasArrowStart:d.hasArrowEnd))continue;const w=y?d.source:d.target;const S=a.get(w),x=l.get(w);const M=y?d.points:[...d.points].reverse();const b=y?f:[...f].reverse();const C=M[0],P=b[0];const E=C&&M.find(v=>v.x!==C.x||v.y!==C.y);const k=P&&b.find(v=>v.x!==P.x||v.y!==P.y);if(S&&C&&E&&Os(S,C,E)===true&&(!x||!P||!k||Os(x,P,k)!==true))return false}const g=br(p,r);for(let y=0;y<u.length;y++){const w=u[y],S=g[y];if(!w.bounds)continue;if(!S?.bounds)return false;const x=S.position==="start"?d.source:d.target;if(t.some((M,b)=>M.id!==x&&o(S.bounds,s(M))&&!o(w.bounds,s(e[b]))))return false;if(c.some(M=>o(M,S.bounds)&&!o(M,w.bounds)))return false}}return true}function ik(e,t,n,i,r){const o=vo(i.edges);const s=new Map(e.map(m=>[m.id,m]));const a=new Map;const l=new Map;for(const m of t){if(!mo(m,s,i.direction))continue;if(!a.has(m.target))a.set(m.target,[]);a.get(m.target).push(m);if(!l.has(m.source))l.set(m.source,[]);l.get(m.source).push(m)}const c=[];const d=m=>{if(m.length<2||m.length>5)return;if(!m.every(g=>g.shape==="rectangle"))return;if(m.some(g=>zn(g,n)))return;if(!fc(m,i.direction))return;const p=m.map(g=>g.id).sort().join("\0");if(c.some(g=>g.map(y=>y.id).sort().join("\0")===p))return;c.push(m)};for(const m of a.values()){const p=m[0]?.target;const g=m.map(y=>s.get(y.source)).filter(Boolean);if(!p||!g.every(y=>t.every(w=>w.source!==y.id||w.target===p)))continue;d(g)}for(const m of l.values()){const p=m[0]?.source;const g=m.map(w=>s.get(w.target)).filter(Boolean);if(!p||!g.every(w=>t.every(S=>S.target!==w.id||S.source===p)&&t.every(S=>S.source!==w.id)))continue;let y=true;for(let w=0;w<g.length;w++)for(let S=0;S<g.length;S++){if(w!==S&&o(g[w].id,g[S].id))y=false}if(y)d(g)}let u=false;let f;const h=_t(i.direction);for(const m of c){const p=Math.max(...m.map(F=>F.width));const g=Math.max(...m.map(F=>F.height));if(m.every(F=>Math.abs(F.width-p)<.5&&Math.abs(F.height-g)<.5))continue;f??=e.map(F=>({...F}));const y=[...m].sort((F,z)=>sr(F,i.direction)-sr(z,i.direction));let w=Math.min(...y.map(F=>sr(F,i.direction)));const S=Math.min(...y.map(F=>To(F,i.direction)));const x=[];for(const F of y){x.push({node:F,x:h.isHorizontal?S:w,y:h.isHorizontal?w:S});w+=(h.isHorizontal?g:p)+24}const M=new Set(m.map(F=>F.id));const b=(F,z,_,H)=>F<H-.01&&_<z-.01;const C=F=>{const z=h.isHorizontal?F.x:F.y;return[z,z+(h.isHorizontal?F.width:F.height)]};const P=F=>{const z=h.isHorizontal?F.y:F.x;return[z,z+(h.isHorizontal?F.height:F.width)]};const E=x.map(({node:F,x:z,y:_})=>({id:F.id,x:z,y:_,width:p,height:g,orig:C(F)}));let k=0;const v=new Set;for(const F of E){const[z,_]=C(F),[H,D]=P(F),[j,W]=F.orig;for(const O of e){if(M.has(O.id))continue;const[N,G]=C(O),[Y,q]=P(O);if(b(z,_,N,G)&&!b(j,W,N,G)&&b(H,D,Y,q)){v.add(O.id);k=Math.max(k,_+24-N)}}}const T=new Set;const A=F=>{if(T.has(F)||M.has(F))return;T.add(F);for(const z of a.get(F)??[])A(z.source)};for(const F of v)A(F);const R=e.filter(F=>T.has(F.id));const I=new Map(R.map(F=>[F.id,C(F)]));const L=[...m,...R].map(F=>({n:F,x:F.x,y:F.y,w:F.width,h:F.height}));if(k>0)for(const F of R)F[h.main]+=k;for(const{node:F,x:z,y:_}of x){F.x=z;F.y=_;F.width=p;F.height=g}const $=new Set([...M,...T]);const B=[...m,...R].some(F=>{const[z,_]=C(F),[H,D]=P(F);const[j,W]=I.get(F.id)??E.find(O=>O.id===F.id).orig;return e.some(O=>{if($.has(O.id))return false;const[N,G]=C(O),[Y,q]=P(O);return b(z,_,N,G)&&!b(j,W,N,G)&&b(H,D,Y,q)})});if(B){for(const F of L){F.n.x=F.x;F.n.y=F.y;F.n.width=F.w;F.n.height=F.h};continue}u=true}if(u){wI(e,i.direction);if(!I8(f,e,t,i,r)){e.forEach((m,p)=>{const g=f[p];m.x=g.x;m.y=g.y;m.width=g.width;m.height=g.height})}}}function rk(e,t,n,i,r,o){const s=vo(i.edges);const a=new Map(e.map(d=>[d.id,d]));const l=!ar("APL_NO_CORANK_FANIN");const c=(d,u,f=false)=>{if(d.length<2||d.length>6)return void 0;const h=d[0].style;if(d.some(y=>y.style!==h))return void 0;if(!f&&d.some(y=>y.label))return void 0;const m=d.map(y=>y[u]);if(new Set(m).size!==m.length)return void 0;const p=m.map(y=>a.get(y)).filter(y=>!!y);if(p.length!==m.length)return void 0;const g=u==="source"?y=>gn.has(y.shape):y=>y.shape==="rectangle";if(!p.every(y=>g(y)&&!zn(y,n)))return void 0;if(!fc(p,i.direction,28))return void 0;for(let y=0;y<p.length;y++)for(let w=0;w<p.length;w++){if(y!==w&&s(p[y].id,p[w].id))return void 0}return p};for(let d=0;d<3;d++){const u=new Map;const f=new Map;for(const x of t){if(!mo(x,a,i.direction))continue;if(!u.has(x.source))u.set(x.source,[]);u.get(x.source).push(x);if(!f.has(x.target))f.set(x.target,[]);f.get(x.target).push(x)}let h=false;const m=x=>x.reduce((M,b)=>M+Kn(b,i.direction),0)/x.length;const p=(x,M)=>M.every(b=>t.every(C=>C.source!==b.id&&(C.target!==b.id||C.source===x)));const g=(x,M)=>M.length>=2&&M.length<=3&&p(x,M);const y=1.5;const w=(x,M,b)=>{if(!x||!gn.has(x.shape)||zn(x,n))return;const C=b?m(b):void 0;const P=M?m(M):void 0;if(C!==void 0&&P!==void 0&&M.length>=4&&p(x.id,M)&&Math.abs(C-P)>y){const A=new Set(M.map($=>$.id));const R=new Set([x.id]);const I=C-P;const L=C-Kn(x,i.direction);if(ph(A,e,t,i.direction,I,r)&&ph(R,e,t,i.direction,L,r)){o?.();mh(A,e,t,i.direction,I);if(Math.abs(L)>.5)mh(R,e,t,i.direction,L);$a("[peer-barycenter] trunk-shift",x.id,"outs by",I.toFixed(1));h=true;return}}const E=[];if(C!==void 0)E.push(C);if(P!==void 0&&!(M&&g(x.id,M)))E.push(P);if(E.length===0&&P!==void 0)E.push(P);if(E.length===0)return;const k=E.length===1?E[0]:(Math.min(...E)+Math.max(...E))/2;const v=k-Kn(x,i.direction);if(Math.abs(v)<=.5)return;const T=new Set([x.id]);if(!ph(T,e,t,i.direction,v,r))return;$a("[peer-barycenter] center",x.id,"by",v.toFixed(1),E.length===2?"(mixed)":"");o?.();mh(T,e,t,i.direction,v);h=true};const S=[...new Set([...u.keys(),...f.keys()])].sort();for(const x of S){const M=u.get(x);const b=f.get(x);const C=M?c(M,"target"):void 0;const P=b?c(b,"source",l):void 0;w(a.get(x),C,P)}if(!h)break}}function dx(e,t,n,i){const r=new Map;if(ar("APL_NO_CORANK_FANIN"))return r;const o=vo(i.edges);const s=new Map(e.map(d=>[d.id,d]));const a=d=>!!d&&gn.has(d.shape)&&!zn(d,n);const l=d=>!!d&&d.shape==="rectangle"&&!zn(d,n);const c=new Map;for(const d of t){if(d.source===d.target)continue;if(!mo(d,s,i.direction))continue;if(!c.has(d.target))c.set(d.target,[]);c.get(d.target).push(d)}for(const[d,u]of c){if(u.length<2||u.length>6)continue;const f=s.get(d);if(!a(f))continue;const h=u.filter(y=>!!y.label);if(h.length===0||h.length===u.length)continue;const m=u[0].style;if(u.some(y=>y.style!==m))continue;const p=u.map(y=>s.get(y.source)).filter(y=>!!y);if(p.length!==u.length)continue;if(new Set(p.map(y=>y.id)).size!==p.length)continue;if(!p.every(l))continue;if(!fc(p,i.direction,28))continue;let g=true;for(let y=0;y<p.length&&g;y++)for(let w=0;w<p.length;w++)if(y!==w&&o(p[y].id,p[w].id)){g=false;break}if(!g)continue;r.set(d,u)}return r}function ok(e,t,n,i,r,o){const s=new Map(e.map(l=>[l.id,l]));const a=_t(i.direction);for(const[l,c]of dx(e,t,n,i)){const d=s.get(l);const u=[...c].sort((P,E)=>Kn(s.get(P.source),i.direction)-Kn(s.get(E.source),i.direction));const f=u.map(P=>s.get(P.source));const h=Ft(d)[a.targetSide];const m=(a.isHorizontal?d.height:d.width)/2;const p=m*1.6;const g=Math.min(28,u.length>1?p/(u.length-1):0);let y=fy(u.length,g);const w=P=>a.isHorizontal?{x:h.x,y:h.y+P}:{x:h.x+P,y:h.y};if(!y.every(P=>Ni(d,w(P))))y=y.map(()=>0);const S=a.isHorizontal?a.sourceSide==="E"?Math.max(...f.map(P=>P.x+P.width)):Math.min(...f.map(P=>P.x)):a.sourceSide==="S"?Math.max(...f.map(P=>P.y+P.height)):Math.min(...f.map(P=>P.y));const x=a.isHorizontal?h.x:h.y;const M=S+(x-S)/2;const b=[];let C=true;for(let P=0;P<u.length;P++){const E=u[P];const k=f[P];const v=Ft(k)[a.sourceSide];const T=w(y[P]);const A=ta(v,T,i.direction,M);if(!di(A,e,new Set([E.source,E.target]))){C=false;break}b.push({edge:E,points:A})}if(!C)continue;for(const{edge:P,points:E}of b){P.points=E;P.routeCertificate=void 0}Eo(b.map(P=>P.edge),r);ou(b,e,i.direction,o,true)}}function sk(e,t,n,i,r){const o=vo(i.edges);const s=new Map(e.map(u=>[u.id,u]));const a=new Map;for(const u of t){if(!mo(u,s,i.direction))continue;if(!a.has(u.source))a.set(u.source,[]);a.get(u.source).push(u)}const l=u=>t.filter(f=>f.target===u&&mo(f,s,i.direction)).length;const c=u=>t.filter(f=>f.source===u&&f.target!==u&&mo(f,s,i.direction));const d=(u,f)=>{const h=[];const m=new Set(f);const p=[u];while(p.length>0){const g=p.shift();if(m.has(g.id))continue;m.add(g.id);h.push(g);for(const y of c(g.id)){const w=s.get(y.target);if(!w||m.has(w.id))continue;if(l(w.id)===1)p.push(w)}}return h};for(const[u,f]of a){if(f.length!==3)continue;const h=s.get(u);if(!h||h.shape!=="diamond"||zn(h,n))continue;const m=[...f].sort((C,P)=>Kn(s.get(C.target),i.direction)-Kn(s.get(P.target),i.direction));const p=m.map(C=>s.get(C.target)).filter(C=>!!C);if(p.length!==m.length)continue;if(!p.every(C=>C.shape==="rectangle"&&!zn(C,n)))continue;if(!fc(p,i.direction,28))continue;let g=true;for(let C=0;C<p.length;C++)for(let P=0;P<p.length;P++){if(C!==P&&o(p[C].id,p[P].id))g=false}if(!g)continue;const y=p.map(C=>c(C.id));if(!y.every(C=>C.length===1))continue;const w=y[0][0].target;if(!y.every(C=>C[0].target===w))continue;const S=s.get(w);if(!S||zn(S,n))continue;const x=new Set(p.map(C=>C.id));for(const C of d(S,x))x.add(C.id);if([...x].some(C=>{const P=s.get(C);return!P||zn(P,n)}))continue;const M=(Kn(p[0],i.direction)+Kn(p[p.length-1],i.direction))/2;const b=Kn(h,i.direction)-M;if(Math.abs(b)<=.5)continue;if(!ph(x,e,t,i.direction,b,r))continue;$a("[fork-rejoin] center",h.id,"peer island by",b.toFixed(1));mh(x,e,t,i.direction,b)}}function ak(e,t,n,i){if(!i.edges.some(te=>(te.length??1)>1))return;const r=Ta(i);const o=_t(i.direction);const s=new Map(e.map(te=>[te.id,te]));const a=new Map;const l=te=>{for(const ee of te){a.set(ee.id,ee);l(ee.children)}};l(n);const c=(te,ee)=>{for(const ae of te.nodeIds)ee.push(ae);for(const ae of te.children)c(ae,ee)};const d=te=>{if(s.has(te))return[te];const ee=Jl(i.subgraphs,te);if(!ee)return[];const ae=[];c(ee,ae);return ae};const u=new Map;const f=(te,ee)=>{for(const ae of te){const ie=[...ee,ae.id];for(const oe of ae.nodeIds)u.set(oe,ie);f(ae.children,ie)}};f(i.subgraphs,[]);const h=(te,ee)=>{if(a.has(ee))return d(ee);const ae=u.get(ee)??[];const ie=new Set(u.get(te)??[]);if(a.has(te))ie.add(te);for(const oe of ae)if(!ie.has(oe))return d(oe);return[ee]};const m=te=>{const ee=i.edges[te];if(r[te]==="feedback")return{source:ee.target,target:ee.source};return{source:ee.source,target:ee.target}};const p=te=>{const ee=s.get(te);if(ee)return{start:ee[o.main],size:pd(ee,i.direction)};const ae=a.get(te);if(ae)return{start:ae[o.main],size:o.main==="x"?ae.width:ae.height};return null};const g=te=>{const ee=p(te);return ee?o.sign===1?ee.start:ee.start+ee.size:null};const y=te=>{const ee=p(te);return ee?o.sign===1?ee.start+ee.size:ee.start:null};const w=(te,ee)=>{const ae=y(te),ie=g(ee);return ae!==null&&ie!==null&&(ie-ae)*o.sign>0};const S=new Map;for(let te=0;te<i.edges.length;te++){const ee=m(te);if(!w(ee.source,ee.target))continue;for(const ae of d(ee.source))for(const ie of d(ee.target)){if(!S.has(ae))S.set(ae,[]);S.get(ae).push(ie)}}const x=new Map;const M=new Set;const b=(te,ee)=>{if(Math.abs(ee)<.5)return;const ae=new Set;const ie=[...te];while(ie.length>0){const oe=ie.pop();if(ae.has(oe))continue;ae.add(oe);const ue=s.get(oe);if(ue){const ye=ue[o.main];ue[o.main]+=ee;if(ue[o.main]!==ye)M.add(ue);x.set(oe,(x.get(oe)??0)+ee)}for(const ye of S.get(oe)??[])ie.push(ye)}};const C=new Map;const P=te=>{let ee=Infinity,ae=Infinity,ie=-Infinity,oe=-Infinity;const ue=Jl(i.subgraphs,te.id);for(const ye of ue?.nodeIds??[]){const Se=s.get(ye);if(!Se)continue;ee=Math.min(ee,Se.x);ae=Math.min(ae,Se.y);ie=Math.max(ie,Se.x+Se.width);oe=Math.max(oe,Se.y+Se.height)}for(const ye of te.children){ee=Math.min(ee,ye.x);ae=Math.min(ae,ye.y);ie=Math.max(ie,ye.x+ye.width);oe=Math.max(oe,ye.y+ye.height)}return Number.isFinite(ee)?{x:ee,y:ae,r:ie,b:oe}:null};const E=te=>{for(const ae of te.children)E(ae);const ee=P(te);if(ee)C.set(te.id,{l:ee.x-te.x,t:ee.y-te.y,r:te.x+te.width-ee.r,b:te.y+te.height-ee.b})};const k=te=>{for(const ie of te.children)k(ie);const ee=P(te);const ae=C.get(te.id);if(!ee||!ae)return;te.x=ee.x-ae.l;te.y=ee.y-ae.t;te.width=ee.r+ae.r-te.x;te.height=ee.b+ae.b-te.y};for(const te of n)E(te);const v=(te,ee)=>{const ae=Math.min(te.x+te.width,ee.x+ee.width)-Math.max(te.x,ee.x);const ie=Math.min(te.y+te.height,ee.y+ee.height)-Math.max(te.y,ee.y);return ae>.5&&ie>.5};const T=(te,ee)=>te.id<ee.id?`${te.id}\0${ee.id}`:`${ee.id}\0${te.id}`;const A=new Set;for(let te=0;te<e.length;te++)for(let ee=te+1;ee<e.length;ee++){if(v(e[te],e[ee]))A.add(T(e[te],e[ee]))}const R=new Map;const I=(te,ee)=>{const ae=e[te],ie=e[ee],oe=te*e.length+ee;const ue=T(ae,ie);if(A.has(ue)||!v(ae,ie))R.delete(oe);else if(!R.has(oe))R.set(oe,{a:ae,b:ie,key:ue,index:oe})};const L=()=>{if(!M.size)return;if(M.size>e.length/2){for(let te=0;te<e.length;te++)for(let ee=te+1;ee<e.length;ee++)I(te,ee)}else{for(let te=0;te<e.length;te++){if(!M.has(e[te]))continue;for(let ee=0;ee<e.length;ee++){if(te===ee||ee<te&&M.has(e[ee]))continue;I(Math.min(te,ee),Math.max(te,ee))}}}M.clear()};for(let te=0;te<i.edges.length;te++){const ee=i.edges[te];const ae=m(te);const ie=ee.length??1;if(ie<=1)continue;if(!w(ae.source,ae.target))continue;const oe=y(ae.source),ue=g(ae.target);if(oe===null||ue===null)continue;const ye=(ue-oe)*o.sign;const Se=Fp(ie,ni.layerSpacing);if(ye<Se)b(h(ae.source,ae.target),(Se-ye)*o.sign)}if(!M.size)return;L();const $=(te,ee)=>{const ae=new Set(u.get(ee)??[]);for(const ie of u.get(te)??[])if(!ae.has(ie))return d(ie);return[te]};for(let te=0;te<e.length*4;te++){let ee;for(const Te of R.values()){if(!ee||Te.key<ee.key||Te.key===ee.key&&Te.index<ee.index)ee=Te}if(!ee)break;const{a:ae,b:ie}=ee;const oe=(mf(ae,i.direction)-mf(ie,i.direction))*o.sign;const[ue,ye]=(oe!==0?oe>0:ae.id>ie.id)?[ie,ae]:[ae,ie];const Se=o.sign===1?ue[o.main]+pd(ue,i.direction)+ni.nodeSpacing-ye[o.main]:ye[o.main]+pd(ye,i.direction)+ni.nodeSpacing-ue[o.main];b($(ye.id,ue.id),o.sign===1?Se:-Se);L()}const B=new Map;for(const[te,ee]of a)B.set(te,{start:ee[o.main],size:o.main==="x"?ee.width:ee.height});for(const te of n)k(te);const F=10;const z=te=>Kn(te,i.direction)+Lo(te,i.direction)/2;const _=te=>Kn(te,i.direction)-Lo(te,i.direction)/2;const H=Math.max(...e.map(z))+F;const D=Math.min(...e.map(_))-F;const j=(te,ee)=>o.main==="x"?{x:te,y:ee}:{x:ee,y:te};const W=(te,ee)=>{const ae=s.get(te);if(ae)return Ft(ae)[ee];const ie=a.get(te);if(!ie)return null;const oe=ie.x+ie.width/2,ue=ie.y+ie.height/2;switch(ee){case"E":return{x:ie.x+ie.width,y:ue};case"W":return{x:ie.x,y:ue};case"S":return{x:oe,y:ie.y+ie.height};default:return{x:oe,y:ie.y}}};const O=te=>{for(const ee of a.values()){if(ee.concurrencyRegion||ee.width===0)continue;const ae=ee.headerHeight??ee.height;if(!Number.isFinite(ae)||ae<0)return false;if(ae===0||ee.width<=0)continue;for(let ie=1;ie<te.length;ie++){const oe=te[ie-1],ue=te[ie];if(Math.max(oe.x,ue.x)>ee.x&&Math.min(oe.x,ue.x)<ee.x+ee.width&&Math.max(oe.y,ue.y)>ee.y&&Math.min(oe.y,ue.y)<ee.y+ae)return false}}return true};const N=te=>{const ee=new Set;for(const oe of e){ee.add(oe[te]);ee.add(oe[te]+(te==="x"?oe.width:oe.height))}for(const oe of a.values()){const ue=oe.concurrencyRegion?0:oe.headerHeight??oe.height;if(!(ue>0&&Number.isFinite(ue)&&oe.width>0))continue;ee.add(oe[te]);ee.add(oe[te]+(te==="x"?oe.width:ue))}const ae=[...ee].sort((oe,ue)=>oe-ue);const ie=[];for(let oe=1;oe<ae.length;oe++)if(ae[oe]-ae[oe-1]>2)ie.push((ae[oe]+ae[oe-1])/2);if(te===o.cross&&a.size&&ae.length>0){ie.push(ae[0]-F,ae.at(-1)+F)}return ie};const G=o.main==="x"?"y":"x";const Y=(te,ee)=>[...te].sort((ae,ie)=>Math.abs(ae-ee)-Math.abs(ie-ee)||ae-ie).slice(0,16);const q=new Map;const V=(te,ee)=>{for(const ae of te){q.set(ae.id,ee);V(ae.children,ae.id)}};V(i.subgraphs);const ne=(te,ee)=>{if((u.get(ee)??[]).includes(te))return true;for(let ae=q.get(ee);ae!==void 0;ae=q.get(ae))if(ae===te)return true;return false};const X=(te,ee)=>{for(const ae of[ee.source,ee.target]){const ie=s.get(ae);if(!ie)continue;for(let oe=1;oe<te.length;oe++)if($i(te[oe-1],te[oe],ie))return false}return true};const U=te=>{const ee=s.get(te),ae=a.get(te),ie=B.get(te);return ee?x.get(te)??0:ae&&ie?ae[o.main]-ie.start:void 0};const K=(te,ee)=>{const ae=s.get(te),ie=x.get(te)??0;const oe=new Set(u.get(ee)??[]);if(a.has(ee))oe.add(ee);const ue=a.has(te)?te:(u.get(te)??[]).find(ye=>!oe.has(ye));if(ue&&a.has(ue)){const ye=B.get(ue),Se=a.get(ue),Te=d(ue);const Ie=Te.length?x.get(Te[0])??0:0;if(Te.every(Ee=>(x.get(Ee)??0)===Ie)&&(o.main==="x"?Se.width:Se.height)===ye.size){return{...ye,delta:Se[o.main]-ye.start}}if(!ae)return null}return ae?{start:ae[o.main]-ie,size:pd(ae,i.direction),delta:ie}:null};const Z=te=>{const ee=K(te.source,te.target),ae=K(te.target,te.source);if(!ee||!ae||te.points.length<2)return null;const[ie,oe]=ee.start<=ae.start?[ee,ae]:[ae,ee];const ue=ie.start+ie.size,ye=oe.start;const Se=ye-ue,Te=ye+oe.delta-(ue+ie.delta);const Ie=ee.delta===ae.delta&&Number.isFinite(ee.delta);if(!Ie&&!(Se>0&&Te>0&&[ue,ye,Se,Te,ie.delta,oe.delta].every(Number.isFinite)))return null;const Ee=Ie?1:Te/Se;if(!(Ee>0&&Number.isFinite(Ee)))return null;const ve=pe=>Ie?pe+ee.delta:pe<=ue?pe+ie.delta:pe>=ye?pe+oe.delta:ue+ie.delta+(pe-ue)*Ee;const $e=te.points.map(pe=>({...pe,[o.main]:ve(pe[o.main])}));if($e.some(pe=>!Number.isFinite(pe.x)||!Number.isFinite(pe.y)))return null;const De=te.points.map(pe=>pe[o.main]).sort((pe,Re)=>pe<Re?-1:pe>Re?1:0);for(let pe=1;pe<De.length;pe++)if(De[pe]>De[pe-1]&&!(ve(De[pe])>ve(De[pe-1])))return null;const fe=(pe,Re)=>pe===Re||Math.abs(pe-Re)<=8*Number.EPSILON*Math.max(1,Math.abs(pe),Math.abs(Re))&&Xe(pe)===Xe(Re);for(let pe=1;pe<$e.length;pe++){const Re=$e[pe-1],Ne=$e[pe];if(!fe(Re.x,Ne.x)&&!fe(Re.y,Ne.y))return null;for(const J of e)if($i(Re,Ne,J))return null}const me=U(te.source),de=U(te.target);if(me===void 0||de===void 0||$e[0][o.main]!==te.points[0][o.main]+me||$e.at(-1)[o.main]!==te.points.at(-1)[o.main]+de)return null;if(!se($e,te))return null;const be=new Set([te.source,te.target]);return di($e,e,be)&&O($e)?$e:null};const Q=(te,ee)=>{if(!ee)return null;const ae=U(te);if(ae===void 0)return null;return{...ee,[o.main]:ee[o.main]+ae}};const se=(te,ee)=>{for(const[ae,ie]of[[ee.source,true],[ee.target,false]]){const oe=s.get(ae),ue=a.get(ae);const ye=oe??(ue?{id:ue.id,label:ue.label,shape:"rectangle",x:ue.x,y:ue.y,width:ue.width,height:ue.height}:void 0);if(!ye)return false;const Se=ie?te[0]:te.at(-1);if(!Se)return false;let Te;for(let ve=ie?1:te.length-2;ve>=0&&ve<te.length;ve+=ie?1:-1){const $e=te[ve];if($e.x!==Se.x||$e.y!==Se.y){Te=$e;break}}if(!Te||!Ni(ye,Se))return false;const Ie=!oe&&ne(ae,ie?ee.target:ee.source);const Ee=Ie?{x:Se.x-(Te.x-Se.x),y:Se.y-(Te.y-Se.y)}:Te;if(!Number.isFinite(Ee.x)||!Number.isFinite(Ee.y)||!Os(ye,Se,Ee))return false}return true};for(const te of t){const ee=te.edgeIndex!==void 0?r[te.edgeIndex]??"primary-forward":"primary-forward";if(ee==="self-loop"){const $e=x.get(te.source)??0;if($e!==0)te.points=te.points.map(De=>({...De,[o.main]:De[o.main]+$e}));if($e!==0&&te.labelPosition)te.labelPosition[o.main]+=$e;continue}const ae=a.size>0&&(ee==="cross-hierarchy"||ee==="container");const ie=ae?Z(te):null;if(ie){te.points=ie;if(te.label)te.labelPosition=sn(ie);continue}if(ee==="feedback"){const $e=s.get(te.source),De=s.get(te.target);if(!$e||!De)continue;const fe=mf($e,i.direction),me=mf(De,i.direction);const de=(Ce,Me)=>[j(fe,Me($e)),j(fe,Ce),j(me,Ce),j(me,Me(De))];const be=(Ce,Me,le,we)=>[j(fe,Me($e)),j(fe,Ce),j(le,Ce),j(le,we),j(me,we),j(me,Me(De))];const pe=(Ce,Me,le,we)=>[j(fe,Me($e)),j(fe,we),j(le,we),j(le,Ce),j(me,Ce),j(me,Me(De))];const Re=new Set([te.source,te.target]);const Ne=Ce=>di(pt(Ce),e,Re)&&O(Ce);const J=[[H,z],[D,_]];let ge;for(const[Ce,Me]of J){const le=de(Ce,Me);if(Ne(le)){ge=le;break}}if(!ge){const Ce=Y(N(o.main==="x"?"x":"y"),me);e:for(const[Me,le]of J){const we=Y(N(G),le(De));for(const ke of[be,pe]){for(const Le of Ce){for(const Fe of we){const Oe=ke(Me,le,Le,Fe);if(Ne(Oe)){ge=pt(Oe);break e}}}}}}te.points=ge??de(H,z);if(te.label)te.labelPosition=sn(te.points);continue}const oe=ae?Q(te.source,te.points[0]):W(te.source,o.sourceSide);const ue=ae?Q(te.target,te.points.at(-1)):W(te.target,o.targetSide);if(!oe||!ue)continue;const ye=new Set([te.source,te.target]);const Se=$e=>di($e,e,ye)&&O($e)&&(!ae||se($e,te)&&X($e,te));const Te=Math.min(oe[o.main],ue[o.main]),Ie=Math.max(oe[o.main],ue[o.main]);let Ee=ta(oe,ue,i.direction,(Te+Ie)/2);let ve=Se(Ee);if(!ve){let $e;const De=Y(N(o.main==="x"?"x":"y").filter(fe=>fe>Te&&fe<Ie),(Te+Ie)/2);for(const fe of De){const me=ta(oe,ue,i.direction,fe);if(Se(me)){$e=me;break}}if(!$e){const fe=oe[G],me=ue[G];const de=Y(N(G),(fe+me)/2);e:for(const be of de){for(const pe of De){for(const Re of Y(De.filter(Ne=>(Ne-pe)*o.sign>0),ue[o.main])){const Ne=pt([oe,j(pe,fe),j(pe,be),j(Re,be),j(Re,me),ue]);if(Se(Ne)){$e=Ne;break e}}}}}if($e){Ee=$e;ve=true}}if(ae&&!ve)throw new Qe([{strategy:"link-rank-reconnect",violations:[`edge ${te.source}->${te.target}: no proven contact-preserving route after rank move`]}]);te.points=Ee;if(te.label)te.labelPosition=sn(te.points)}}function a_(e,t,n,i,r,o){let s=4e6;const a=Pp(t,n,i,o,p=>(s-=p)>=0);if(!a)return false;const l=Kl({nodes:t,edges:n,groups:i},o);const c=new Set(e.map(({edge:p})=>p));const d=t.find(p=>p.id===e[0].edge.source);const u=Wd(i).filter(p=>uy(d,p));const f=(p,g)=>{const y=kt({...p,labelPosition:g},o);const w=y&&l.clearPaintRect(y,Ti(p,o.lineWidth??1),p);return!!w&&u.every(S=>w.x>S.x&&w.y>S.y&&w.x+w.w<S.x+S.width&&w.y+w.h<S.y+S.height)&&a.clear(p,g,new Map,void 0,c)};const h=()=>e.every(({edge:p})=>!p.label||!!p.labelPosition&&a.clear(p,p.labelPosition,new Map));const m=e.every(({edge:p,points:g})=>{if(!p.label)return true;if(!p.labelPosition||!f(p,p.labelPosition))return false;const y=kt(p,o);return g.some((w,S)=>{if(!S)return false;const x=g[S-1];return x.x===w.x&&x.x>=y.x&&x.x<=y.x+y.w&&y.y>=Math.min(x.y,w.y)&&y.y+y.h<=Math.max(x.y,w.y)||x.y===w.y&&x.y>=y.y&&x.y<=y.y+y.h&&y.x>=Math.min(x.x,w.x)&&y.x+y.w<=Math.max(x.x,w.x)})});return m&&h()||ou(e,t,r,o,false,f)&&h()}function lk(e,t,n,i,r,o=[]){const s=new Map(e.map(l=>[l.id,l]));const a=new Map;for(const l of t){if(!n.has(l)||!l.label||!mo(l,s,i))continue;if(!a.has(l.source))a.set(l.source,[]);a.get(l.source).push(l)}for(const l of a.values()){if(l.length<2||l.length>3)continue;if(new Set(l.map(u=>u.target)).size<l.length)continue;const c=[...l].sort((u,f)=>{const h=s.get(u.target);const m=s.get(f.target);if(!h||!m)return(u.edgeIndex??0)-(f.edgeIndex??0);return Kn(h,i)-Kn(m,i)});const d=s.get(c[0].source);if(d?.shape==="rectangle"&&zn(d,o)){const u=c.map(h=>({edge:{...h},points:h.points}));const f=new Map(c.map((h,m)=>[h,u[m].edge]));if(a_(u,e,t.map(h=>f.get(h)??h),o,i,r)){c.forEach((h,m)=>{h.labelPosition=u[m].edge.labelPosition})}}else ou(c.map(u=>({edge:u,points:u.points})),e,i,r)}}function s_(e,t){return Wd(t).filter(n=>uy(e,n)).map(n=>n.id).join("\0")}function ck(e,t,n,i,r,o,s){if(t.length<2||t.length>3)return void 0;if(e.shape!=="rectangle"&&e.shape!=="diamond")return void 0;const a=e.shape!=="diamond"&&zn(e,r);const l=[...t].sort((u,f)=>Kn(i.get(u.target),o)-Kn(i.get(f.target),o));const c=l.map(u=>i.get(u.target)).filter(Boolean);if(c.length!==l.length)return void 0;const d=a?s_(e,r):"";if(!c.every(u=>u.shape==="rectangle"&&(a?s_(u,r)===d:e.shape==="diamond"||!zn(u,r))))return void 0;if(!fc(c,o,40))return void 0;if(!c.every(u=>n.every(f=>f.source!==u.id&&(f.target!==u.id||f.source===e.id))))return void 0;for(let u=0;u<c.length;u++)for(let f=0;f<c.length;f++){if(u!==f&&s(c[u].id,c[f].id))return void 0}return l}function dk(e,t,n,i,r,o){const s=vo(i.edges);const a=new Map(e.map(d=>[d.id,d]));const l=new Map;for(const d of t){if(!mo(d,a,i.direction))continue;if(!l.has(d.source))l.set(d.source,[]);l.get(d.source).push(d)}const c=_t(i.direction);for(const[d,u]of l){const f=a.get(d);const h=f&&ck(f,u,t,a,n,i.direction,s);if(!f||!h)continue;const m=h.map(j=>a.get(j.target));const p=f.shape!=="diamond"&&zn(f,n);if(p){const{ctx:j,axis:W}=Ro(e,t,i.direction,o,n);const O=Kn(f,i.direction);const N=h.map(G=>lf(G,f,a.get(G.target),j,W));if(N.every((G,Y)=>G!==null&&Math.abs(G-O+(N[N.length-1-Y]-O))<=1))continue}const g=m.map(j=>({t:j,x:j.x,y:j.y,width:j.width,height:j.height}));const y=Wd(n).map(j=>({group:j,x:j.x,y:j.y,width:j.width,height:j.height}));const w=()=>{for(const j of g){j.t.x=j.x;j.t.y=j.y;j.t.width=j.width;j.t.height=j.height}for(const j of y){j.group.x=j.x;j.group.y=j.y;j.group.width=j.width;j.group.height=j.height}};const S=Math.max(...m.map(j=>j.width));const x=Math.max(...m.map(j=>j.height));const M=Kn(f,i.direction);const b=Math.min(...m.map(j=>To(j,i.direction)));const C=(c.isHorizontal?x:S)+28;const P=fy(m.length,C);const E=f.shape==="diamond"?h.map((j,W)=>J0(f,i.direction,W,h.length)[c.cross]):void 0;const k=j=>{for(let W=0;W<m.length;W++){const O=m[W];O.width=S;O.height=x;if(c.isHorizontal){O.x=b;O.y=j[W]-x/2}else{O.x=j[W]-S/2;O.y=b}}};if(!p)k(E??P.map(j=>M+j));const v=new Set(m.map(j=>j.id));const T=()=>{for(let j=0;j<m.length;j++){const W=m[j];if(W.x<0||W.y<0)return false;for(let O=j+1;O<m.length;O++){if(Fi(W,m[O],8))return false}}for(const j of m){for(const W of e){if(v.has(W.id))continue;if(Fi(j,W,8))return false}}return true};let A=p||T();if(!A&&E){k(P.map(j=>M+j));A=T()}if(!A){w();continue}const R=c.isHorizontal?c.sourceSide==="E"?f.x+f.width:f.x:c.sourceSide==="S"?f.y+f.height:f.y;let I=c.isHorizontal?c.sign>0?Math.min(...m.map(j=>j.x)):Math.max(...m.map(j=>j.x+j.width)):c.sign>0?Math.min(...m.map(j=>j.y)):Math.max(...m.map(j=>j.y+j.height));const L=Math.max(0,...h.map(j=>o_(j,i.direction,o)));const $=(I-R)*c.sign;if(!p&&L>$+.001){const j=L-$;const W=m.map(O=>({x:O.x,y:O.y,width:O.width,height:O.height}));for(const O of m){if(c.isHorizontal)O.x+=j*c.sign;else O.y+=j*c.sign}MI(n,W,i.direction,j);A=T();if(!A){w();continue}I=c.isHorizontal?c.sign>0?Math.min(...m.map(O=>O.x)):Math.max(...m.map(O=>O.x+O.width)):c.sign>0?Math.min(...m.map(O=>O.y)):Math.max(...m.map(O=>O.y+O.height))}const B=Math.max(0,...h.map(j=>r_(j,i.direction,o,R,I)));const F=R+(I-R)*.5;const z=I-c.sign*B;const _=(z-F)*c.sign<0?z:F;if(p&&(_-R)*c.sign<Math.max(...h.map(j=>Si(o,j,"start")))-.001)continue;const H=[];for(let j=0;j<h.length;j++){const W=h[j];const O=a.get(W.target);const N=ta(J0(f,i.direction,j,h.length),kI(O,i.direction),i.direction,_);if(!di(N,e,new Set([W.source,W.target]))){A=false;break}H.push({edge:W,points:N})}if(A&&p){const j=t.filter(O=>!u.includes(O)&&O.style!=="invisible");const W=O=>j.reduce((N,G)=>N+jl(O,G.points),0);A=H.reduce((O,{points:N})=>O+W(N),0)<=H.reduce((O,{edge:N})=>O+W(N.points),0)}if(!A){w();continue}const D=H.map(({edge:j,points:W})=>({edge:{...j,points:W},points:W}));if(p&&D.some(({edge:j})=>j.label)){const j=new Map(H.map(({edge:O},N)=>[O,D[N].edge]));const W=t.map(O=>j.get(O)??O);if(!a_(D,e,W,n,i.direction,o)){w();continue}}else ou(D,e,i.direction,o);for(let j=0;j<H.length;j++){const{edge:W,points:O}=H[j];W.points=O;W.labelPosition=D[j].edge.labelPosition;W.routeCertificate=void 0}Eo(H.map(j=>j.edge),r)}}function zh(e,t,n){if(e.length>zs||t.length>Ra)return false;let i=zs-e.length;const r=o=>o.every(s=>--i>=0&&r(s.children));return r(n)}var su=(e,t)=>e.points.length!==t.points.length||e.points.some((n,i)=>n.x!==t.points[i].x||n.y!==t.points[i].y);function Gh(){return{remaining:zs*Ra}}function Ec(e,t,n,i,r,o,s=Gh()){const a=e.map((m,p)=>m.x!==n[p].x||m.y!==n[p].y);const l=t.map((m,p)=>su(m,i[p]));if(!a.some(Boolean)&&!l.some(Boolean))return true;const c=()=>--s.remaining>=0;const d=new Map;const u=m=>{if(!d.has(m))d.set(m,Cp(m,o,c));return d.get(m)};const f=new Map;const h=m=>{if(!f.has(m)){const p=_r(m,{fill:m.inlineStyle?.fill??o.nodeFillColor??"var(--_node-fill)",stroke:m.inlineStyle?.stroke??o.nodeBorderColor??"var(--_node-stroke)",strokeWidth:Xn("stroke-width",m.inlineStyle?.["stroke-width"]??String(o.nodeLineWidth??et.innerBox))},o.cornerRadius);f.set(m,Ei({kind:"shape",id:m.id,role:"node",geometry:hd(p.geometry),paint:p.paint,...p.childPaints?{childPaints:p.childPaints}:{}}))}return f.get(m)};try{for(let m=0;m<e.length;m++){if(!a[m])continue;const p=h(e[m]);if(!Li(p))return false;for(let g=0;g<e.length;g++){if(g===m||a[g]&&g<m)continue;if(!c())return false;const y=h(e[g]);if(!Li(y)||Ui(p,y))return false}}for(let m=0;m<e.length;m++){const p=e[m];for(let g=0;g<t.length;g++){const y=t[g];if(!a[m]&&!l[g]||y.style==="invisible")continue;if(!c())return false;if(y.source===p.id&&ai(y,p)>ai(i[g],n[m]))return false;if(y.target===p.id&&ai(y,void 0,p)>ai(i[g],void 0,n[m]))return false;const w=u(y);if(!w)return false;const S=h(p);if(!Li(S))return false;if(y.source!==p.id&&y.target!==p.id){for(const x of w.shafts)if(!c()||Ui(S,x))return false}for(const x of w.markers){const M=x.position==="start"?y.source:y.target;if(M!==p.id&&(!c()||!Li(x.bounds)||Ui(S,x.bounds)))return false}if(w.label&&(!c()||Ui(S,w.label)))return false}}return N8(e,t,n,i,r,u,h,c)}catch{return false}}function l_(e,t){return{nodes:e.map(n=>({...n})),edges:t.map(n=>({...n,points:n.points.map(i=>({...i})),...n.labelPosition?{labelPosition:{...n.labelPosition}}:{}}))}}function c_(e,t,n,i){e.forEach((r,o)=>{if(r.x!==n[o].x)r.x=n[o].x;if(r.y!==n[o].y)r.y=n[o].y});t.forEach((r,o)=>{const s=i[o];if(su(s,r))r.points=s.points;if(s.labelPosition?.x!==r.labelPosition?.x||s.labelPosition?.y!==r.labelPosition?.y)r.labelPosition=s.labelPosition;if(s.routeCertificate!==r.routeCertificate)r.routeCertificate=s.routeCertificate})}function uk(e,t,n,i,r,o){if(ar("APL_NO_LABELED_SOURCE_PORT"))return;if(!zh(e,t,n))return;if(!t.some(l=>l.label))return;const s=l_(e,t);F8(s.nodes,s.edges,n,i,r,o);const a=Gh();if(!Ec(s.nodes,s.edges,e,t,n,o,a)){if(a.remaining<0)return;const{ctx:l,axis:c}=Ro(s.nodes,s.edges,r,o,n);for(let h=0;h<s.edges.length;h++){const m=s.edges[h];if(!m.label||!su(m,t[h]))continue;const p=s.nodes.find(y=>y.id===m.source),g=s.nodes.find(y=>y.id===m.target);if(!p||!g||!Vl(m,p,g,l,c,m.points[0][c.cross]).applied)return;Qo(m,m.routeCertificate,p,g)}const d=Symbol();const u=()=>--a.remaining>=0;const f=()=>{if(!u())throw d};try{const h=Kl({...s,groups:n},o,f);const m=(p,g)=>{f();const y=kt(p,o);if(!y)return false;const w=h.clearPaintRect(y,Ti(p,o.lineWidth??1),p);if(!w)return false;const S={x0:w.x,y0:w.y,x1:w.x+w.w,y1:w.y+w.h};for(const x of s.edges){f();const M=Cp(x,o,u);if(!M||M.markers.some(C=>{f();return Ui(S,C.bounds)}))return false;if(x===p)continue;if(M.shafts.some(C=>{f();return Ui(S,C)}))return false;const b=kt(x,o);if(b){f();const C=Ti(x,o.lineWidth??1);if(Ui(S,{x0:b.x-C,y0:b.y-C,x1:b.x+b.w+C,y1:b.y+b.h+C}))return false}}return Ec(s.nodes,[p],e,[g],n,o,a)};for(let p=0;p<s.edges.length;p++){f();const g=s.edges[p],y=t[p];if(!g.label||!su(g,y)||m(g,y))continue;const w=kt(g,o),S=g.points[0],x=g.points[1];if(!w||g.points.length!==2)return;const M=Math.hypot(x.x-S.x,x.y-S.y),b=(c.main==="x"?w.w:w.h)/2;if(!(M>2*b))return;let C=false;for(const P of ff(b/M,f)){f();g.labelPosition={x:S.x+(x.x-S.x)*P,y:S.y+(x.y-S.y)*P};if(m(g,y)){C=true;break}}if(!C)return}}catch(h){if(h===d)return;throw h}if(!Ec(s.nodes,s.edges,e,t,n,o,a))return}c_(e,t,s.nodes,s.edges)}function F8(e,t,n,i,r,o){const s=new Set;for(const[x]of dx(e,t,n,i))s.add(x);const a=r==="LR"||r==="RL";const l=a?"y":"x";const c=a?"x":"y";const d=a?r==="LR"?"E":"W":r==="BT"?"N":"S";const u=x=>a?x.height:x.width;const f=x=>x[l]+u(x)/2;const h=2;const m=[];const p=x=>{for(const M of x){m.push(M);p(M.children)}};p(n);const g=x=>m.some(M=>x.x>=M.x-.5&&x.y>=M.y-.5&&x.x+x.width<=M.x+M.width+.5&&x.y+x.height<=M.y+M.height+.5);const y=new Map(e.map(x=>[x.id,x]));const w=x=>c==="x"?d==="E"?x.x+x.width:x.x:d==="S"?x.y+x.height:x.y;const S=(x,M)=>{const b=new Set([x.id]);const C=[x.id];while(C.length){const P=C.pop();for(const E of t){if(E.target!==P||E===M)continue;const k=y.get(E.source);if(!k||b.has(k.id))continue;if(t.filter(v=>v.source===k.id).length!==1)return null;if(!gn.has(k.shape)||g(k))return null;b.add(k.id);C.push(k.id)}}return b};for(const x of t){if(!x.label||x.points.length<2||x.source===x.target)continue;if(s.has(x.target))continue;const M=y.get(x.source);if(!M||!gn.has(M.shape)||g(M))continue;if(t.some($=>$!==x&&$.source===M.id&&$.target!==M.id))continue;if(Math.abs(x.points[0][c]-w(M))>1)continue;const b=y.get(x.target);if(!b||!gn.has(b.shape)||g(b))continue;const{ctx:C,axis:P}=Ro(e,t,r,o,n);let E=0;let k=false;const v={...M};for(let $=0;$<4;$++){const B=lf(x,v,b,C,P);if(B===null)break;const F=B-f(v);E+=F;v[l]+=F;if(Math.abs(F)<=.5){k=true;break}}if(!k||Math.abs(E)<=1)continue;const T=S(M,x);if(!T)continue;const A=[...T].map($=>y.get($)).filter(Boolean);const R=$=>({x:a?$.x:$.x+E,y:a?$.y+E:$.y,width:$.width,height:$.height});const I=e.some($=>!T.has($.id)&&A.some(B=>{const F=R(B);return F.x-h<$.x+$.width&&F.x+F.width+h>$.x&&F.y-h<$.y+$.height&&F.y+F.height+h>$.y}));if(I)continue;const L=t.some($=>!T.has($.source)&&!T.has($.target)&&A.some(B=>{const F=R(B);return $.points.some((z,_)=>{if(_===0)return false;const H=$.points[_-1];return Math.max(z.x,H.x)>F.x+.5&&Math.min(z.x,H.x)<F.x+F.width-.5&&Math.max(z.y,H.y)>F.y+.5&&Math.min(z.y,H.y)<F.y+F.height-.5})}));if(L)continue;for(const $ of A){if(a)$.y+=E;else $.x+=E}for(const $ of t){if(T.has($.source)&&T.has($.target))for(const B of $.points)B[l]+=E}x.points[0]=Ft(M)[d]}}function N8(e,t,n,i,r,o,s,a){const l=e.filter((u,f)=>u.x!==n[f].x||u.y!==n[f].y);const c=t.filter((u,f)=>u.style!=="invisible"&&su(u,i[f]));const d=u=>{if(!a())return false;if(!u.concurrencyRegion&&u.width!==0){const f=u.headerHeight??u.height;if(!Number.isFinite(u.width)||u.width<0||!Number.isFinite(f)||f<0)return false;if(f>0&&u.width>0){const h=bs({x0:u.x,y0:u.y,x1:u.x+u.width,y1:u.y+f},B1(hd({kind:"rect",x:u.x,y:u.y,width:u.width,height:f})));if(!Li(h))return false;for(const m of l){if(!a())return false;const p=s(m);if(!Li(p))return false;const g=bs(p,{x0:m.x,y0:m.y,x1:m.x+m.width,y1:m.y+m.height});if(!Li(g)||Ui(g,h))return false}for(const m of c){const p=o(m);if(!p)return false;for(const g of p.shafts)if(!a()||Ui(g,h))return false;for(const g of p.markers)if(!a()||!Li(g.bounds)||Ui(g.bounds,h))return false}}}return u.children.every(d)};return r.every(d)}function fk(e,t,n,i,r){if(!zh(e,t,n))return;const{nodes:o,edges:s}=l_(e,t);$8(o,s,n,i,r);const a=Gh();if(!Ec(o,s,e,t,n,r,a)){if(a.remaining<0)return;const l=s.filter((c,d)=>su(c,t[d]));mc(o,l,{direction:i},r);if(!Ec(o,s,e,t,n,r,a))return}if(gf({nodes:o,edges:s},true)+1e-6<gf({nodes:e,edges:t},true))return;c_(e,t,o,s)}function $8(e,t,n,i,r){const o=i==="LR"||i==="RL";const s=o?"y":"x";const a=o?"x":"y";const l=i==="LR"||i==="TD"?1:-1;const c=new Set;const d=8;const u=W=>o?W.height:W.width;const f=W=>W[s]+u(W)/2;const h=new Map(e.map(W=>[W.id,W]));const m=[];const p=W=>{for(const O of W){m.push(O);p(O.children)}};p(n);const g=W=>m.some(O=>W.x>=O.x-.5&&W.y>=O.y-.5&&W.x+W.width<=O.x+O.width+.5&&W.y+W.height<=O.y+O.height+.5);const y=(W,O,N,G,Y,q,V,ne)=>W<Y+V&&W+N>Y&&O<q+ne&&O+G>q;const w=W=>o?W.width:W.height;const S=(W,O,N,G)=>e.some(Y=>!G.has(Y.id)&&W>Y[s]-4&&W<Y[s]+u(Y)+4&&N>Y[a]-4&&O<Y[a]+w(Y)+4);const x=(W,O,N,G)=>e.some(Y=>!G.has(Y.id)&&W>Y[a]-4&&W<Y[a]+w(Y)+4&&N>Y[s]-4&&O<Y[s]+u(Y)+4);const M=(W,O)=>{const N=O?W.length-1:0;const G=O?-1:1;const Y=W[N][s];let q=N;while(q>=0&&q<W.length&&Math.abs(W[q][s]-Y)<=.5)q+=G;if(q<0||q>=W.length)return null;const V=W[q];const ne=W[q-G];return{mainPos:V[a],far:V[s],orthogonal:Math.abs(V[a]-ne[a])<=.5}};const b=(W,O)=>{const N=O?W.length-1:0;const G=O?-1:1;const Y=W[N][s];let q=Infinity;let V=-Infinity;for(let ne=N;ne>=0&&ne<W.length;ne+=G){if(Math.abs(W[ne][s]-Y)>.5)break;q=Math.min(q,W[ne][a]);V=Math.max(V,W[ne][a])}return{ref:Y,lo:q,hi:V}};const C=(W,O,N,G,Y=false)=>{const q=W.points,V=O?q.length-1:0,ne=O?-1:1;const X=O?0:q.length-1,U=q[V][s];let K=Infinity,Z=-Infinity;for(let se=V;se>=0&&se<q.length&&Math.abs(q[se][s]-U)<=.5;se+=ne){if(Y&&se===X)break;K=Math.min(K,se);Z=Math.max(Z,se)}if(Z<K)return false;const Q=se=>se>=K&&se<=Z?{...q[se],[s]:q[se][s]+N}:q[se];for(let se=Math.max(1,K);se<=Math.min(q.length-1,Z+1);se++){if($i(Q(se-1),Q(se),G))return true}return false};const P=(W,O,N,G=false)=>{if(c.has(W.id)||g(W))return false;const Y=h.get(N.source);const q=h.get(N.target);const V=f(W.id===N.source?q:Y);const ne=Math.min(Y[a]+w(Y)/2,q[a]+w(q)/2);const X=Math.max(Y[a]+w(Y)/2,q[a]+w(q)/2);if(S(V,ne,X,new Set([N.source,N.target])))return false;for(const Z of t){const Q=Z.source===W.id;const se=Z.target===W.id;if(!Q&&!se)continue;const te=Z===N;if(te&&Z.points.length===2&&Math.abs(Z.points[0][s]-Z.points[1][s])<=.5)continue;if(!te){if(Z.points.length<3)return false;const ue=se?Z.points[Z.points.length-1]:Z.points[0];if(!Z.points.some(ye=>Math.abs(ye[s]-ue[s])>.5))return false}const ee=new Set([Z.source,Z.target]);const ae=b(Z.points,se);if(S(ae.ref+O,ae.lo,ae.hi,ee))return false;const ie=M(Z.points,se);if(ie){if(!ie.orthogonal)return false;const ue=Math.min(ae.ref+O,ie.far);const ye=Math.max(ae.ref+O,ie.far);if(x(ie.mainPos,ue,ye,ee))return false}const oe=h.get(se?Z.source:Z.target);if(oe&&oe!==W&&!(te&&G)&&C(Z,se,O,oe))return false}const U=o?W.x:W.x+O;const K=o?W.y+O:W.y;for(const Z of e){if(Z===W)continue;if(y(U-d,K-d,W.width+2*d,W.height+2*d,Z.x,Z.y,Z.width,Z.height))return false}for(const Z of t){if(Z.source===W.id||Z.target===W.id)continue;for(let Q=1;Q<Z.points.length;Q++){const se=Z.points[Q-1],te=Z.points[Q];if(Math.max(se.x,te.x)>U+.5&&Math.min(se.x,te.x)<U+W.width-.5&&Math.max(se.y,te.y)>K+.5&&Math.min(se.y,te.y)<K+W.height-.5)return false}}for(const Z of t){if(Z===N)continue;const Q=kt(Z,r);if(Q&&y(U-d,K-d,W.width+2*d,W.height+2*d,Q.x,Q.y,Q.w,Q.h))return false}return true};const E=(W,O,N,G=false)=>{const Y=W.points;const q=O?Y.length-1:0;const V=O?-1:1;const ne=O?0:Y.length-1;const X=Y[q][s];let U=Infinity;let K=-Infinity;for(let Z=q;Z>=0&&Z<Y.length;Z+=V){if(Math.abs(Y[Z][s]-X)>.5)break;if(G&&Z===ne)break;U=Math.min(U,Y[Z][a]);K=Math.max(K,Y[Z][a]);Y[Z][s]+=N}if(W.labelPosition&&Math.abs(W.labelPosition[s]-X)<=12&&W.labelPosition[a]>=U-.5&&W.labelPosition[a]<=K+.5){W.labelPosition[s]+=N}};const k=(W,O,N)=>{if(o)W.y+=O;else W.x+=O;for(const q of t){if(q===N||q.points.length===0)continue;const V=q.source===W.id;const ne=q.target===W.id;if(V&&ne){for(const X of q.points)X[s]+=O;if(q.labelPosition)q.labelPosition[s]+=O;continue}if(ne)E(q,true,O);if(V)E(q,false,O)}const G=N.points[0];const Y=N.points[N.points.length-1];if(N.points.length===2&&Math.abs(G[s]-Y[s])<=.5){const q=o?l>0?"E":"W":l>0?"S":"N";const V=o?l>0?"W":"E":l>0?"N":"S";N.points=[Ft(h.get(N.source))[q],Ft(h.get(N.target))[V]];if(N.labelPosition)N.labelPosition[s]=f(h.get(N.source))}else{E(N,N.target===W.id,O)}};const v=W=>{if(W.points.length<2||W.source===W.target)return false;const O=pt(W.points);for(let N=1;N<O.length;N++){if((O[N][a]-O[N-1][a])*l<-.5)return false}return true};const T=(W,O,N)=>{const G=o?W.x:W.x+O;const Y=o?W.y+O:W.y;for(const q of e){if(q===W)continue;if(y(G-d,Y-d,W.width+2*d,W.height+2*d,q.x,q.y,q.width,q.height))return false}for(const q of t){if(N.has(`${q.source}->${q.target}`))continue;for(let V=1;V<q.points.length;V++){const ne=q.points[V-1],X=q.points[V];if(Math.max(ne.x,X.x)>G+.5&&Math.min(ne.x,X.x)<G+W.width-.5&&Math.max(ne.y,X.y)>Y+.5&&Math.min(ne.y,X.y)<Y+W.height-.5)return false}}for(const q of t){if(N.has(`${q.source}->${q.target}`))continue;const V=kt(q,r);if(V&&y(G-d,Y-d,W.width+2*d,W.height+2*d,V.x,V.y,V.w,V.h))return false}return true};const A=new Set;const R=W=>t.filter(O=>O.source===W&&v(O));const I=W=>t.filter(O=>O.target===W&&v(O)).length;const L=W=>{const O=[];const N=new Set;const G=[W];while(G.length>0){const Y=G.shift();if(N.has(Y.id))continue;N.add(Y.id);O.push(Y);for(const q of R(Y.id)){const V=h.get(q.target);if(!V||N.has(V.id))continue;if(I(V.id)===1)G.push(V)}}return O};const $=W=>Number(Xe(W));const B=W=>W.points.length===2&&$(W.points[0][s])===$(W.points[1][s])&&$(W.points[0][a])!==$(W.points[1][a]);const F=(W,O,N)=>{if(W.routeCertificate)return void 0;const G=h.get(W.source),Y=h.get(W.target);if(!G||!Y)return void 0;const q=O.has(G.id)?{...G,[s]:G[s]+N}:G;const V=O.has(Y.id)?{...Y,[s]:Y[s]+N}:Y;const ne=o?l>0?"E":"W":l>0?"S":"N";const X=o?l>0?"W":"E":l>0?"N":"S";const U=Ft(q)[ne],K=Ft(V)[X];if(![U.x,U.y,K.x,K.y].every(Number.isFinite)||$(U[s])!==$(K[s]))return void 0;if(l>0?$(U[a])>=$(K[a]):$(U[a])<=$(K[a]))return void 0;return[U,K]};const z=(W,O)=>{const N=new Set(W.map(G=>G.id));for(const G of W){const Y=o?G.x:G.x+O;const q=o?G.y+O:G.y;for(const V of e){if(N.has(V.id))continue;if(y(Y-d,q-d,G.width+2*d,G.height+2*d,V.x,V.y,V.width,V.height))return false}}for(const G of t){const Y=N.has(G.source),q=N.has(G.target);if(Y===q||G.points.length===0)continue;if(B(G)&&!F(G,N,O))return false;const V=h.get(q?G.source:G.target);if(V&&C(G,q,O,V,true))return false}return true};const _=(W,O)=>{const N=new Set(W.map(Y=>Y.id));const G=new Map;for(const Y of t)if(N.has(Y.source)!==N.has(Y.target)&&B(Y)){const q=F(Y,N,O);if(!q)return false;G.set(Y,q)}for(const Y of W){if(o)Y.y+=O;else Y.x+=O}for(const Y of t){const q=N.has(Y.source);const V=N.has(Y.target);if(q&&V){for(const ne of Y.points)ne[s]+=O;if(Y.labelPosition)Y.labelPosition[s]+=O}else if(G.has(Y)){Y.points=G.get(Y);if(Y.labelPosition)Y.labelPosition[s]=Y.points[0][s]}else if(V){E(Y,true,O,true)}else if(q){E(Y,false,O,true)}}return true};for(const W of ar("APL_NO_CENTER")?[]:e){if(c.has(W.id)||g(W)||!gn.has(W.shape))continue;const O=t.filter(Q=>Q.target===W.id&&Q.source!==W.id&&Q.points.length>=2);const N=new Map;let G=O.length>=2;for(const Q of O){if(Q.label||!v(Q)){G=false;break}const se=h.get(Q.source);if(!se||!gn.has(se.shape)){G=false;break}N.set(se.id,se)}if(!G||N.size<2)continue;if(t.filter(Q=>Q.source===W.id&&Q.target!==W.id&&v(Q)).length>1)continue;const Y=[...N.values()];const q=Y.map(Q=>Q[a]+w(Q)/2);const V=Math.max(...q)-Math.min(...q);const ne=Math.max(...Y.map(w));if(V>ne+ni.layerSpacing*.6)continue;const X=Y.reduce((Q,se)=>Q+f(se),0)/Y.length;const U=X-f(W);if(Math.abs(U)<=.5){A.add(W.id);continue}const K=L(W);const Z=new Set(t.filter(Q=>Q.source===W.id||Q.target===W.id).map(Q=>`${Q.source}->${Q.target}`));if(!T(W,U,Z)||!z(K,U))continue;$a("[apl] center hub",W.id,"by",U.toFixed(1),"over",Y.length,"sources");if(!_(K,U))continue;for(const Q of K){A.add(Q.id);c.add(Q.id)}for(const Q of O)c.add(Q.source)}const H=new Set;if(!ar("APL_NO_FACET")){const W=()=>{if(o)return l>0?["NE","SE"]:["NW","SW"];return l>0?["SW","SE"]:["NW","NE"]};for(const O of e){if(O.shape!=="diamond"||c.has(O.id)||g(O))continue;const N=t.filter(ae=>ae.source===O.id&&ae.target!==O.id&&ae.points.length>=2&&v(ae));if(N.length!==2)continue;if(N.some(ae=>{const ie=h.get(ae.target);return!ie||!gn.has(ie.shape)}))continue;if(N.some(ae=>c.has(ae.target)||A.has(ae.target)||g(h.get(ae.target))))continue;const G=[...N].sort((ae,ie)=>f(h.get(ae.target))-f(h.get(ie.target)));const[Y,q]=W();const V=Vo(O);const ne=[[G[0],Y],[G[1],q]];const X=Ft(O);const U=ne.map(([ae,ie])=>({edge:ae,src:{x:V[ie].x,y:V[ie].y},cross:V[ie][s]}));const K=!o&&ne[0]&&ne[1]?[{edge:ne[0][0],src:{x:X.W.x,y:X.W.y},cross:X.W[s]},{edge:ne[1][0],src:{x:X.E.x,y:X.E.y},cross:X.E[s]}]:null;const Z=ae=>{const ie=ae.map(ye=>{const Se=h.get(ye.edge.target);const Te=ye.cross-f(Se);return{x:o?Se.x:Se.x+Te,y:o?Se.y+Te:Se.y,w:Se.width,h:Se.height}});const[oe,ue]=ie;return!!(oe&&ue&&y(oe.x-d,oe.y-d,oe.w+2*d,oe.h+2*d,ue.x,ue.y,ue.w,ue.h))};const Q=ae=>ae.every(ie=>{const oe=h.get(ie.edge.target);const ue=ie.cross-f(oe);return Math.abs(ue)<=.5||P(oe,ue,ie.edge,true)});const se=ae=>!!ae&&Q(ae)&&!Z(ae);let te;if(se(U))te=U;else if(se(K))te=K;else continue;const ee=o?l>0?"W":"E":l>0?"N":"S";for(const ae of te){const ie=ae.edge;const oe=h.get(ie.target);const ue=ae.cross-f(oe);if(Math.abs(ue)>.5){if(o)oe.y+=ue;else oe.x+=ue;for(const ye of t){if(ye===ie)continue;const Se=ye.source===oe.id,Te=ye.target===oe.id;if(Se&&Te){for(const Ie of ye.points)Ie[s]+=ue;if(ye.labelPosition)ye.labelPosition[s]+=ue}else if(Te)E(ye,true,ue);else if(Se)E(ye,false,ue)}}ie.points=[{x:ae.src.x,y:ae.src.y},Ft(oe)[ee]];if(ie.labelPosition)ie.labelPosition[s]=ae.cross;H.add(ie);c.add(ie.target)}c.add(O.id)}}if(!ar("APL_NO_SVERTEX")){for(const W of t){if(H.has(W)||W.points.length<2||W.source===W.target)continue;const O=h.get(W.source);const N=h.get(W.target);if(!O||!N||N.shape!=="diamond")continue;if(c.has(O.id)||c.has(N.id)||g(O)||g(N))continue;if(!v(W)||W.label)continue;const G=N[s]+u(N)/2;const Y=t.some(ae=>{if(ae===W||ae.target!==N.id||!v(ae)||ae.points.length<2)return false;const ie=h.get(ae.source);if(!ie)return false;return Math.abs(ie[s]+u(ie)/2-G)<=u(N)/2});if(!Y)continue;const q=N[s]+u(N)/2;const V=O[s]+u(O)/2;const ne=V>q;const X=o?ne?"S":"N":ne?"E":"W";const U=Ft(N)[X];const K=u(N)/2;if(Math.abs(V-q)<K*.5)continue;const Z=U[s]-f(O);if(Math.abs(Z)>.5&&!P(O,Z,W,true))continue;const Q=o?l>0?"E":"W":l>0?"S":"N";const se=Ft(O)[Q];const te=Math.min(se[a],U[a]);const ee=Math.max(se[a],U[a]);if((U[a]-se[a])*l<=.5)continue;if(S(U[s],te,ee,new Set([O.id,N.id])))continue;$a("[apl] svertex",W.source,"->",W.target,"into",X,"vertex");if(Math.abs(Z)>.5){if(o)O.y+=Z;else O.x+=Z;for(const ae of t){if(ae===W)continue;const ie=ae.source===O.id,oe=ae.target===O.id;if(ie&&oe){for(const ue of ae.points)ue[s]+=Z;if(ae.labelPosition)ae.labelPosition[s]+=Z}else if(oe)E(ae,true,Z);else if(ie)E(ae,false,Z)}}W.points=[{x:Ft(O)[Q].x,y:Ft(O)[Q].y},{x:U.x,y:U.y}];H.add(W);c.add(O.id);c.add(N.id)}}let D;const j=W=>ck(W,t.filter(O=>O.source===W.id&&mo(O,h,i)),t,h,n,i,D??=vo(t))!==void 0;for(const W of t){if(H.has(W))continue;if(W.points.length<2||W.source===W.target)continue;const O=h.get(W.source);const N=h.get(W.target);if(!O||!N)continue;if(!gn.has(O.shape)||!gn.has(N.shape))continue;if(A.has(N.id))continue;if(O.shape==="diamond"&&t.some(q=>q!==W&&q.source===W.source&&v(q)))continue;const G=f(O)-f(N);if(Math.abs(G)<=.5)continue;if(!v(W)||pt(W.points).length>4)continue;const Y=P(N,G,W)?N:!j(O)&&P(O,-G,W)?O:null;if(Y){$a("[apl] slide",Y.id,"by",(Y===N?G:-G).toFixed(1),"for",W.source,"->",W.target);k(Y,Y===N?G:-G,W);c.add(W.source);c.add(W.target)}}}function _8(e,t,n,i=2){const r=n.x-i,o=n.x+n.w+i,s=n.y-i,a=n.y+n.h+i;if(Math.abs(e.x-t.x)<.01){const l=Math.min(e.y,t.y),c=Math.max(e.y,t.y);return e.x>=r&&e.x<=o&&c>=s&&l<=a}if(Math.abs(e.y-t.y)<.01){const l=Math.min(e.x,t.x),c=Math.max(e.x,t.x);return e.y>=s&&e.y<=a&&c>=r&&l<=o}return false}function hk(e,t,n){for(const i of n){if(i===e)continue;for(let r=1;r<i.points.length;r++){if(_8(i.points[r-1],i.points[r],t))return true}}return false}function d_(e,t){for(let n=1;n<e.length;n++)for(let i=1;i<t.length;i++){const r=e[n-1],o=e[n],s=t[i-1],a=t[i];const l=(o.x-r.x)*(a.y-s.y)-(o.y-r.y)*(a.x-s.x);if(Math.abs(l)<1e-9)continue;const c=((s.x-r.x)*(a.y-s.y)-(s.y-r.y)*(a.x-s.x))/l;const d=((s.x-r.x)*(o.y-r.y)-(s.y-r.y)*(o.x-r.x))/l;if(c>.001&&c<.999&&d>.001&&d<.999)return true}return false}function D8(e,t,n,i,r,o,s=(r+1)/(o+1),a=s){const l=_t(n);if(l.isHorizontal){const m={x:l.sourceSide==="E"?e.x+e.width:e.x,y:e.y+e.height*s};const p={x:l.targetSide==="W"?t.x:t.x+t.width,y:t.y+t.height*a};const g=Math.min(28,Math.max(14,Math.abs(p.x-m.x)*.18));const y=m.x+l.sign*g;const w=p.x-l.sign*g;return pt([m,{x:y,y:m.y},{x:y,y:i},{x:w,y:i},{x:w,y:p.y},p])}const c={x:e.x+e.width*s,y:l.sourceSide==="S"?e.y+e.height:e.y};const d={x:t.x+t.width*a,y:l.targetSide==="N"?t.y:t.y+t.height};const u=Math.min(28,Math.max(14,Math.abs(d.y-c.y)*.18));const f=c.y+l.sign*u;const h=d.y-l.sign*u;return pt([c,{x:c.x,y:f},{x:i,y:f},{x:i,y:h},{x:d.x,y:h},d])}function mk(e,t,n,i,r,o){const s=new Map(e.map(c=>[c.id,c]));const a=_t(i.direction);const l=new Map;for(const c of t){if(c.source===c.target||!c.label)continue;const d=s.get(c.source);const u=s.get(c.target);if(!d||!u||!gn.has(d.shape)||!gn.has(u.shape))continue;if(zn(d,n)||zn(u,n))continue;const f=`${c.source}\0${c.target}`;if(!l.has(f))l.set(f,[]);l.get(f).push(c)}for(const c of l.values()){c.sort((S,x)=>(S.edgeIndex??0)-(x.edgeIndex??0));if(c.length!==2)continue;const d=s.get(c[0].source);const u=s.get(c[0].target);const f=c.map(S=>_o(S,{x:0,y:0},o));const h=f.map(S=>S.width);const m=f.map(S=>S.height);const p=(a.isHorizontal?Math.max(...m):Math.max(...h))/2+18;const g=[p,p+16,p+32,p+52];const y=[[1/3,2/3],[1/6,1/3],[2/3,5/6]];const w=g.map(S=>({lanes:a.isHorizontal?[Math.min(d.y,u.y)-S,Math.max(d.y+d.height,u.y+u.height)+S]:[Math.min(d.x,u.x)-S,Math.max(d.x+d.width,u.x+u.width)+S],sourceSlots:y[0],targetSlots:y[0]}));if(d.shape==="diamond")for(const S of[...w]){for(const x of y)for(const M of y){const b=M.map(P=>u[a.cross]+Lo(u,i.direction)*P);const C=x.map(P=>d[a.cross]+Lo(d,i.direction)*P);for(const P of[S.lanes,[S.lanes[0],b[1]],[b[0],S.lanes[1]],[S.lanes[0],C[1]],[C[0],S.lanes[1]]]){w.push({lanes:P,sourceSlots:x,targetSlots:M})}}}for(const{lanes:S,sourceSlots:x,targetSlots:M}of w){const b=[];let C=true;for(let P=0;P<c.length;P++){const E=c[P];const k=pt(si(si(D8(d,u,i.direction,S[P],P,c.length,x[P],M[P]),d,true),u,false));if(!Ni(d,k[0])||!Ni(u,k.at(-1))){C=false;break}if(!di(k,e,new Set([d.id,u.id]))){C=false;break}b.push({edge:E,points:k,label:tk(k)})}if(!C)continue;if(d.shape==="diamond"){const P=t.filter(v=>!c.includes(v));if(d_(b[0].points,b[1].points)||b.some(v=>P.some(T=>d_(v.points,T.points))))continue;const E=b.map(v=>{const T=[...P,...b.filter(A=>A!==v).map(A=>({...A.edge,points:A.points}))];return ru(v.edge,v.points,e,i.direction,o).filter(A=>!hk(v.edge,{x:A.box.x,y:A.box.y,w:A.box.width,h:A.box.height},T))});let k;for(const v of E[0]){const T=E[1].find(A=>!Fi(v.box,A.box,Wh(o)));if(T){k=[v,T];break}}if(!k)continue;b[0].label=k[0].point;b[1].label=k[1].point}for(const P of b){const E=_o(P.edge,P.label,o);if(d.shape!=="diamond"&&hk(P.edge,{x:E.x,y:E.y,w:E.width,h:E.height},t))C=false}if(!C||ux(t,b,o)!==true)continue;for(const{edge:P,points:E,label:k}of b){P.points=E;P.labelPosition=k;P.routeCertificate=void 0}Eo(b.map(P=>P.edge),r);break}}}function u_(e,t,n){const i=new Map(t.map(l=>[l.edge,l]));const r=new Set;const o=e.map((l,c)=>{const d=i.get(l);if(!d)return l;r.add(c);return{...l,points:d.points,labelPosition:d.label}});const{nodes:s,style:a}=n;return _a({nodes:s,edges:o},a,r).total<=_a({nodes:s,edges:e},a,r).total}function ux(e,t,n,i){const r=new Map(t.map(c=>[c.edge,c.points]));const o=new Set;const s=e.map((c,d)=>{const u=r.get(c);if(!u)return c;o.add(d);return{...c,points:u}});for(const c of o){const d=e[c],u=s[c];if(js(d,u.points,s,n,u))return"marker-blocked"}if(i?.labelClearance&&!u_(e,t,i.labelClearance))return false;const a=Ql(s,o)-Ql(e,o);if(!i?.allowCrossingsForOverlap)return a<=0;const l=Da(e,o)-Da(s,o);if(l<0)return false;if(a<=0)return true;return a<=l}function pk(e,t,n,i,r,o,s){const a=new Map(e.map(R=>[R.id,R]));const l=_t(i.direction);const c=14;const d=5;const u=16;const f={allowCrossingsForOverlap:true,...s?{labelClearance:{nodes:e,style:s}}:{}};const h=R=>l.isHorizontal?R.width:R.height;const m=R=>l.isHorizontal?R.height:R.width;const p=(R,I)=>l.isHorizontal?{x:R,y:I}:{x:I,y:R};const g=R=>R[l.main]+h(R);const y=R=>R[l.main];const w=l.sourceSide==="E"||l.sourceSide==="S";const S=l.targetSide==="W"||l.targetSide==="N";const x=(R,I)=>w!==I?g(R):y(R);const M=(R,I)=>S!==I?y(R):g(R);const b=new Set;const C=(R,I)=>{for(let L=1;L<R.points.length;L++){const $=R.points[L-1],B=R.points[L];const F=Math.abs($.x-B.x)<.5;const z=Math.abs($.y-B.y)<.5;if(!F&&!z)continue;for(let _=1;_<I.points.length;_++){const H=I.points[_-1],D=I.points[_];if(F){if(Math.abs(H.x-D.x)>=.5||Math.abs($.x-H.x)>=1)continue;const j=Math.min(Math.max($.y,B.y),Math.max(H.y,D.y))-Math.max(Math.min($.y,B.y),Math.min(H.y,D.y));if(j>1)return true}else if(z){if(Math.abs(H.y-D.y)>=.5||Math.abs($.y-H.y)>=1)continue;const j=Math.min(Math.max($.x,B.x),Math.max(H.x,D.x))-Math.max(Math.min($.x,B.x),Math.min(H.x,D.x));if(j>1)return true}}}return false};const P=new Map;for(const R of t){if(R.source===R.target)continue;const I=a.get(R.source);const L=a.get(R.target);if(!I||!L)continue;if(!gn.has(I.shape)||!gn.has(L.shape))continue;if(zn(I,n)||zn(L,n))continue;const $=(M(L,false)-x(I,false))*l.sign;const B=(x(I,true)-M(L,true))*l.sign;if($<=u&&B<=u)continue;const F=`${R.source}\0${R.target}`;if(!P.has(F))P.set(F,[]);P.get(F).push(R)}const E=(R,I)=>{const L=_o(R,I,o),$=Ti(R,o.lineWidth??1);return{x:L.x-$,y:L.y-$,width:L.width+2*$,height:L.height+2*$}};const k=(R,I,L,$,B=0)=>{R.sort((ne,X)=>(ne.edgeIndex??0)-(X.edgeIndex??0));const F=a.get(R[0].source);const z=a.get(R[0].target);const _=x(F,I);const H=M(z,I);const D=R.length;if(L<4)return false;const j=R.every(ne=>ne.label)?Math.max(L,...R.map(ne=>{const X=E(ne,{x:0,y:0});return(l.isHorizontal?X.width:X.height)+Wh(o)})):L;const W=$==="target";const O=F[l.cross]+m(F)/2+B;const N=z[l.cross]+m(z)/2+B;const G=[];const Y=[];for(let ne=0;ne<D;ne++){const X=O+(ne-(D-1)/2)*L;const U=N+(ne-(D-1)/2)*L;const K=(I?-1:1)*l.sign;let Z=W?H-K*(u+ne*j):_+K*(u+ne*j);const Q=Math.min(_,H),se=Math.max(_,H);if(Z<=Q+4||Z>=se-4)Z=(_+H)/2;G.push({edge:R[ne],sCross:X,tCross:U});Y.push(Z)}if(G[0].tCross-G[0].sCross>0!==W)Y.reverse();const q=[];for(let ne=0;ne<D;ne++){const{edge:X,sCross:U,tCross:K}=G[ne];const Z=Y[ne];const Q=U===K?[p(_,U),p(H,K)]:[p(_,U),p(Z,U),p(Z,K),p(H,K)];const se=pt(si(si(Q,F,true),z,false));if(se.length<2||!Ni(F,se[0])||!Ni(z,se[se.length-1])||!di(se,e,new Set([F.id,z.id]))){return false}q.push({edge:X,points:se,label:X.label?tk(se):void 0})}const V=ux(t,q,o,{allowCrossingsForOverlap:true});if(V!==true)return V;if($!=="original"){const ne=t.filter(Z=>!R.includes(Z));const X=[...ne,...q.map(Z=>({...Z.edge,points:Z.points}))];const U=X.flatMap(Z=>br(Z,o)).flatMap(Z=>Z.bounds?[{x:Z.bounds.x0,y:Z.bounds.y0,width:Z.bounds.x1-Z.bounds.x0,height:Z.bounds.y1-Z.bounds.y0}]:[]);const K=ne.filter(Z=>Z.label).map(Z=>E(Z,Z.labelPosition??sn(Z.points)));for(const Z of q){if(!Z.edge.label)continue;const Q=[...ne,...q.filter(te=>te!==Z).map(te=>({...te.edge,points:te.points}))];const se=ru(Z.edge,Z.points,e,i.direction,o).find(te=>{const ee=E(Z.edge,te.point);return!e.some(ae=>Fi(ee,ae,2))&&!U.some(ae=>Fi(ee,ae,0))&&!K.some(ae=>Fi(ee,ae,2))&&!hk(Z.edge,{x:ee.x,y:ee.y,w:ee.width,h:ee.height},Q)});if(!se)return false;Z.label=se.point;K.push(E(Z.edge,Z.label))}}if(f.labelClearance&&!u_(t,q,f.labelClearance))return false;for(const{edge:ne,points:X,label:U}of q){ne.points=X;ne.labelPosition=U;ne.routeCertificate=void 0;b.add(ne)}Eo(q.map(ne=>ne.edge),r);return true};for(const R of P.values()){if(R.length<2||!R.some(_=>_.label))continue;if(!R.some(_=>_.label&&R.some(H=>H!==_&&C(_,H))))continue;if(R.every(_=>_.label)&&_a({nodes:[],edges:R},o).labelLabel===0)continue;const I=a.get(R[0].source);const L=a.get(R[0].target);if(!I||!L)continue;const $=!((M(L,false)-x(I,false))*l.sign>u);const B=(Math.min(m(I),m(L))-2*d)/(R.length-1);const F=Math.max(c,...R.filter(_=>_.label).map(_=>{const H=E(_,{x:0,y:0});return(l.isHorizontal?H.height:H.width)/2+3}));const z=(_,H)=>{const D=k(R,$,_,H);if(D===true)return true;if(D!=="marker-blocked"||!zh(e,t,n))return false;const j=(B-_)*(R.length-1)/2;return j>0&&ff(0).some(W=>{const O=(2*W-1)*j;return O!==0&&k(R,$,_,H,O)===true})};if(F<=B&&(z(F,"source")||z(F,"target")))continue;if(z(Math.min(c,B),"original"))continue;if(R.every(_=>_.label)){const _=Math.min(c/2,B);z(_,"source")||z(_,"target")||z(_,"original")}}const v=new Map;const T=new Map;for(const R of t){if(b.has(R))continue;if(R.source===R.target||R.label)continue;const I=a.get(R.source);const L=a.get(R.target);if(!I||!L)continue;if(!gn.has(I.shape)||!gn.has(L.shape))continue;if(zn(I,n)||zn(L,n))continue;const $=B=>{if(!B.has(R.target))B.set(R.target,[]);B.get(R.target).push(R)};if((M(L,false)-x(I,false))*l.sign>u)$(v);else if((x(I,true)-M(L,true))*l.sign>u)$(T)}const A=(R,I)=>{if(R.length<2)return;const L=new Map;for(const Y of R)L.set(Y.source,(L.get(Y.source)??0)+1);if(![...L.values()].some(Y=>Y>=2))return;const $=a.get(R[0].target);const B=M($,I);const F=$[l.cross]+m($)/2;const z=Y=>{const q=a.get(Y.source);return q[l.cross]+m(q)/2};R.sort((Y,q)=>z(Y)-z(q)||(Y.edgeIndex??0)-(q.edgeIndex??0));const _=R.length;const H=Math.min(c,(m($)-2*d)/(_-1));if(H<4)return;const D=new Map;for(const Y of R){if(!D.has(Y.source))D.set(Y.source,[]);D.get(Y.source).push(Y)}const j=[];const W=[];for(let Y=0;Y<_;Y++){const q=R[Y];const V=a.get(q.source);const ne=x(V,I);const X=F+(Y-(_-1)/2)*H;const U=D.get(q.source);const K=U.length>1?Math.min(H,(m(V)-2*d)/(U.length-1)):0;const Z=V[l.cross]+m(V)/2+(U.indexOf(q)-(U.length-1)/2)*K;let Q=ne+(I?-1:1)*l.sign*(u+Y*H);const se=Math.min(ne,B),te=Math.max(ne,B);if(Q<=se+4||Q>=te-4)Q=(ne+B)/2;j.push({edge:q,source:V,exitMain:ne,sCross:Z,tCross:X});W.push(Q)}for(let Y=0;Y<_;){let q=Y;while(q+1<_&&R[q+1].source===R[Y].source)q++;if(q>Y&&j[Y].tCross-j[Y].sCross>0){const V=W.slice(Y,q+1).reverse();for(let ne=Y;ne<=q;ne++)W[ne]=V[ne-Y]}Y=q+1}const O=Y=>{const q=[];for(let V=0;V<_;V++){const{edge:ne,source:X,exitMain:U}=j[V];const K=j[V].sCross,Z=j[V].tCross+Y;const Q=W[V];let se;if(K===Z){se=[p(U,K),p(B,Z)]}else{se=[p(U,K),p(Q,K),p(Q,Z),p(B,Z)]}se=si(se,X,true);se=si(se,$,false);se=pt(se);const te=La(se,Ws(ne,o));if(!te)return void 0;se=te;if(se.length<2||!Ni(X,se[0])||!Ni($,se[se.length-1])||!di(se,e,new Set([X.id,$.id])))return void 0;q.push({edge:ne,points:se})}return q};let N=O(0);if(!N)return;const G=ux(t,N,o,f);if(G!==true){if(G!=="marker-blocked"||!zh(e,t,n))return;let Y=-Infinity,q=Infinity;for(const U of j){Y=Math.max(Y,U.source[l.cross]+d-U.sCross,$[l.cross]+d-U.tCross);q=Math.min(q,U.source[l.cross]+m(U.source)-d-U.sCross,$[l.cross]+m($)-d-U.tCross)}if(!Number.isFinite(Y)||!Number.isFinite(q)||Y>0||q<0)return;const V=Gh();const ne={...f,labelClearance:{nodes:e,style:o}};let X;for(const U of[Y,q]){if(V.remaining<=0)break;if(U===0)continue;const K=O(U);if(!K||ux(t,K,o,ne)!==true)continue;const Z=new Map(K.map(se=>[se.edge,se.points]));const Q=t.map(se=>Z.has(se)?{...se,points:Z.get(se)}:se);if(!Ec(e,Q,e,t,n,o,V))continue;X=K;break}if(!X)return;N=X}for(const{edge:Y,points:q}of N){Y.points=q;Y.labelPosition=void 0;Y.routeCertificate=void 0}Eo(N.map(Y=>Y.edge),r)};for(const R of v.values())A(R,false);for(const R of T.values())A(R,true)}function fx(e,t,n){if(!t)return void 0;const i=n?0:e.length-1,r=n?1:-1;const o=e[i];if(!o)return false;for(let s=i+r;s>=0&&s<e.length;s+=r){const a=e[s];if(a.x!==o.x||a.y!==o.y)return Os(t,o,a)}return false}function f_(e,t,n){const i={...e,points:e.points.filter((r,o)=>o===0||r.x!==e.points[o-1].x||r.y!==e.points[o-1].y).map(r=>({...r}))};nf(i,t,n);if(t)i.points=si(i.points,t,true);if(n)i.points=si(i.points,n,false);return i}function gk(e,t,n,i){if(e.length<2||n===void 0&&i===void 0)return e;const r=e.map(s=>({...s}));const o=t?"x":"y";for(const[s,a,l]of[[n,0,1],[i,r.length-1,r.length-2]]){if(s===void 0)continue;const c=r[a],d=r[l];c[o]+=s;if(d[o]===c[o]-s)d[o]+=s}return r}function hx(e,t,n){if(e.length===0)return;const i=n==="LR"||n==="RL";const r=new Set;const o=new Map;for(const h of t){r.add(`${h.source}:${h.target}`);r.add(`${h.target}:${h.source}`);for(const m of new Set([h.source,h.target])){const p=o.get(m)??[];p.push(h);o.set(m,p)}}const s=new Map(e.map(h=>[h.id,h]));const a=ni.layerSpacing*.6;const l=[...e].sort((h,m)=>i?h.x-m.x:h.y-m.y);const c=[];let d=[l[0]];for(let h=1;h<l.length;h++){const m=i?l[h].x:l[h].y;const p=i?l[h-1].x:l[h-1].y;const g=m-p;const y=d.some(w=>r.has(`${w.id}:${l[h].id}`));if(g<=a&&!y){d.push(l[h])}else{c.push(d);d=[l[h]]}}c.push(d);const u=new Map;const f=(h,m)=>{const p=i?m:h.x;const g=i?h.y:m;for(const y of t){if(y.source===h.id||y.target===h.id)continue;for(let w=1;w<y.points.length;w++){const S=y.points[w-1],x=y.points[w];const M=Math.min(S.x,x.x),b=Math.max(S.x,x.x);const C=Math.min(S.y,x.y),P=Math.max(S.y,x.y);if(b>p+.5&&M<p+h.width-.5&&P>g+.5&&C<g+h.height-.5){return true}}}return false};for(const h of c){if(h.length<=1)continue;const m=h.map(b=>i?b.x:b.y);const p=Math.min(...m);const g=Math.max(...m);if(g-p<=1)continue;const y=(p+g)/2;if(h.some(b=>{const C=i?b.x:b.y;return Math.abs(y-C)>.5&&f(b,y)}))continue;const w=new Map(h.flatMap(b=>{const C=y-(i?b.x:b.y);return Math.abs(C)>.5?[[b.id,C]]:[]}));const S=new Map(h.map(b=>[b.id,{...b,...i?{x:b.x+(w.get(b.id)??0)}:{y:b.y+(w.get(b.id)??0)}}]));const x=new Set;let M=false;for(const b of w.keys()){for(const C of o.get(b)??[]){if(x.has(C)||C.style==="invisible")continue;x.add(C);const P={...C,points:gk(C.points,i,u.get(C.source),u.get(C.target))};const E={...C,points:gk(C.points,i,w.get(C.source)??u.get(C.source),w.get(C.target)??u.get(C.target))};let k,v;for(const T of[true,false]){const A=T?C.source:C.target;const R=s.get(A),I=S.get(A)??R;let L=fx(P.points,R,T),$;if(L===true)$=fx(E.points,I,T);else{k??=f_(P,s.get(C.source),s.get(C.target));v??=f_(E,S.get(C.source)??s.get(C.source),S.get(C.target)??s.get(C.target));L=fx(k.points,R,T);$=fx(v.points,I,T)}if(L===true&&$!==true)M=true}}}if(M)continue;for(const b of h){const C=i?b.x:b.y;const P=y-C;if(Math.abs(P)>.5){if(i){b.x=y}else{b.y=y}u.set(b.id,P)}}}if(u.size===0)return;for(const h of t){h.points=gk(h.points,i,u.get(h.source),u.get(h.target))}}function yk(e,t,n){const i=[];for(const r of n){if(e>=r.x&&e<=r.x+r.width&&t>=r.y&&t<=r.y+r.height){i.push(r);i.push(...yk(e,t,r.children))}}return i}function O8(e,t,n,i){const r=(m,p)=>{if(m!==void 0&&!/^\s*[+]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?(?:px)?\s*$/i.test(m))return void 0;const g=m===void 0?p:Number.parseFloat(m);return Number.isFinite(g)&&g>=0?Number(Xe(g)):void 0};const o=r(e.inlineStyle?.["stroke-width"],i.lineWidth*(e.style==="thick"?2:1));const s=i.edgeBendRadius;if(o===void 0||!Number.isFinite(s)||s<0)return false;const a=$n({stroke:"#000",strokeWidth:String(o)},true);if(a===void 0)return false;const l=a+s;const c=e.points.map(m=>({x:Number(Xe(m.x)),y:Number(Xe(m.y))}));if(!c.every(m=>Number.isFinite(m.x)&&Number.isFinite(m.y)))return false;const d=c.slice(1).map((m,p)=>{const g=c[p];return{x0:Math.min(g.x,m.x)-l,x1:Math.max(g.x,m.x)+l,y0:Math.min(g.y,m.y)-l,y1:Math.max(g.y,m.y)+l}});const u=(m,p)=>{const g=(Math.abs(m.x0)+Math.abs(m.x1)+Math.abs(m.y0)+Math.abs(m.y1)+Math.abs(p.x0)+Math.abs(p.x1)+Math.abs(p.y0)+Math.abs(p.y1))*1e-10+1e-9;return!Number.isFinite(g)||m.x1+g>p.x0&&m.x0<p.x1+g&&m.y1+g>p.y0&&m.y0<p.y1+g};const f=Aa(e,i);if(!f||f.length!==Number(Boolean(e.hasArrowStart))+Number(Boolean(e.hasArrowEnd)))return false;for(const m of t){const p=r(m.inlineStyle?.["stroke-width"],i.nodeLineWidth);if(p===void 0)return false;const g=_r(m,{fill:"#000",stroke:"#000",strokeWidth:String(p)},i.cornerRadius);const y=Ei(ym({id:m.id,role:"node",geometry:g.geometry,paint:g.paint,...g.childPaints?{childPaints:g.childPaints}:{}}));if(!y)return false;if(m.id!==e.source&&m.id!==e.target&&d.some(w=>u(w,y)))return false;for(const w of f){const S=w.position==="start"?e.source:e.target;if(S!==m.id&&(!w.bounds||u(w.bounds,y)))return false}}const h=m=>{const p=m.concurrencyRegion?0:m.headerHeight??m.height;if(p>0){const g={x0:m.x,x1:m.x+m.width,y0:m.y,y1:m.y+p};if(d.some(y=>u(y,g))||f.some(y=>!y.bounds||u(y.bounds,g)))return false}return m.children.every(h)};return n.every(h)}function mx(e,t,n,i,r){const o=12;const s=r==="LR";const a=r==="RL";const l=r==="BT";const c=s||a;const d=new Set(yk(t,n,i).map(p=>p.id));const u=c?e:t;const f=c?n:e;const h=yk(u,f,i);const m=h.find(p=>!d.has(p.id));if(!m)return e;if(s)return m.x-o;if(a)return m.x+m.width+o;if(l)return m.y+m.height+o;return m.y-o}function xk(e,t,n,i,r){const o=new Map(t.map(p=>[p.id,p]));const s=new Set;const a=(p,g)=>{for(const[M,b]of g){const C=o.get(M.source),P=o.get(M.target);g.set(M,si(si(b,C,true),P,false))}const y=e.map(M=>g.has(M)?{...M,points:g.get(M)}:M);const w=(M,b,C)=>e.some(P=>P.source===M&&P.target===b&&P.style!=="invisible"&&Po(C,P)&&P.hasArrowStart===C.hasArrowStart&&P.hasArrowEnd===C.hasArrowEnd&&(P.startMarker??"arrow")===(C.startMarker??"arrow")&&(P.endMarker??"arrow")===(C.endMarker??"arrow"));const S=(M,b)=>!Po(M,b)||!w(M.source,b.target,M)||!w(b.source,M.target,b);const x=(M,b)=>{const C=e.filter(E=>E!==M);const P=new Set(HS(M,C));return HS(b,C).some(E=>!P.has(E)&&S(M,E))};return p.filter(M=>{const b=g.get(M.edge);const C=y[e.indexOf(M.edge)];return O8(C,t,n,r)&&!js(M.edge,b,y,r,C)&&!x(M.edge,C)})};const l=i==="LR";const c=i==="RL";const d=i==="BT";const u=l||c;const f=(p,g)=>Math.max(...p.map(({edge:y})=>Si(r,y,g)));const h=new Map;for(const p of e){if(p.source===p.target)continue;if(!h.has(p.source))h.set(p.source,[]);h.get(p.source).push(p)}for(const[p,g]of h){if(g.length<2)continue;const y=g[0].style;if(g.some(C=>C.label||C.style!==y))continue;const w=o.get(p);if(!w)continue;const S=g.filter(C=>{const P=o.get(C.target);if(!P)return false;if(l)return P.x>w.x+w.width;if(c)return P.x+P.width<w.x;if(d)return P.y+P.height<w.y;return P.y>w.y+w.height});if(S.length<2)continue;if(new Set(S.map(C=>C.target)).size<2)continue;const x=w.x+w.width/2;const M=w.y+w.height/2;let b=S.map(C=>({edge:C,node:o.get(C.target)}));while(b.length>=2){const C=new Map;if(u){const E=l?w.x+w.width:w.x;const k=M;const v=l?Math.min(...b.map(A=>A.node.x)):Math.max(...b.map(A=>A.node.x+A.node.width));let T=hc(E,v,f(b,"start"),f(b,"end"));T=mx(T,x,M,n,i);for(const{edge:A,node:R}of b){const I=l?R.x:R.x+R.width;const L=R.y+R.height/2;C.set(A,[{x:E,y:k},{x:T,y:k},{x:T,y:L},{x:I,y:L}])}}else{const E=x;const k=d?w.y:w.y+w.height;const v=d?Math.max(...b.map(A=>A.node.y+A.node.height)):Math.min(...b.map(A=>A.node.y));let T=hc(k,v,f(b,"start"),f(b,"end"));T=mx(T,x,M,n,i);for(const{edge:A,node:R}of b){const I=R.x+R.width/2;const L=d?R.y+R.height:R.y;C.set(A,[{x:E,y:k},{x:E,y:T},{x:I,y:T},{x:I,y:L}])}}const P=a(b,C);if(P.length===b.length){for(const{edge:E}of b){E.points=C.get(E)}Eo(b.map(E=>E.edge),s);break}b=P;if(new Set(b.map(E=>E.edge.target)).size<2)break}}const m=new Map;for(const p of e){if(s.has(p)||p.source===p.target)continue;if(!m.has(p.target))m.set(p.target,[]);m.get(p.target).push(p)}for(const[p,g]of m){if(g.length<2)continue;const y=g[0].style;if(g.some(C=>C.label||C.style!==y))continue;const w=o.get(p);if(!w)continue;const S=g.filter(C=>{const P=o.get(C.source);if(!P)return false;if(l)return P.x+P.width<w.x;if(c)return P.x>w.x+w.width;if(d)return P.y>w.y+w.height;return P.y+P.height<w.y});if(S.length<2)continue;if(new Set(S.map(C=>C.source)).size<2)continue;const x=w.x+w.width/2;const M=w.y+w.height/2;let b=S.map(C=>({edge:C,node:o.get(C.source)}));while(b.length>=2){const C=new Map;if(u){const E=l?w.x:w.x+w.width;const k=M;const v=l?Math.max(...b.map(A=>A.node.x+A.node.width)):Math.min(...b.map(A=>A.node.x));let T=hc(v,E,f(b,"start"),f(b,"end"));T=mx(T,x,M,n,i);for(const{edge:A,node:R}of b){const I=l?R.x+R.width:R.x;const L=R.y+R.height/2;C.set(A,[{x:I,y:L},{x:T,y:L},{x:T,y:k},{x:E,y:k}])}}else{const E=x;const k=d?w.y+w.height:w.y;const v=d?Math.min(...b.map(A=>A.node.y)):Math.max(...b.map(A=>A.node.y+A.node.height));let T=hc(v,k,f(b,"start"),f(b,"end"));T=mx(T,x,M,n,i);for(const{edge:A,node:R}of b){const I=R.x+R.width/2;const L=d?R.y:R.y+R.height;C.set(A,[{x:I,y:L},{x:I,y:T},{x:E,y:T},{x:E,y:k}])}}const P=a(b,C);if(P.length===b.length){for(const{edge:E}of b){E.points=C.get(E)}Eo(b.map(E=>E.edge),s);break}b=P;if(new Set(b.map(E=>E.edge.source)).size<2)break}}return s}function px(e,t,n=0){if(e.length<2)return e;let i=false;for(let s=1;s<e.length;s++){const a=Math.abs(e[s].x-e[s-1].x);const l=Math.abs(e[s].y-e[s-1].y);if(a>1&&l>1){i=true;break}}if(!i)return e;const r=12;const o=[e[0]];for(let s=1;s<e.length;s++){const a=o[o.length-1];const l=e[s];const c=Math.abs(l.x-a.x);const d=Math.abs(l.y-a.y);if(c>1&&d>1){if(t){const u=n%2===0;const f=Math.floor(n/2)*r;const h=u?t.rightX+f:t.leftX-f;o.push({x:h,y:a.y});o.push({x:h,y:l.y})}else{const u=(a.y+l.y)/2;o.push({x:a.x,y:u});o.push({x:l.x,y:u})}}o.push(l)}return o}function bk(e,t,n,i,r,o){const s=new Map;const a=new Map;const l=(d,u,f)=>{a.set(d.id,{x:u,y:f});for(const h of d.children??[])l(h,u+(h.x??0),f+(h.y??0))};l(e,i,r);h_(e,s,i,r,a);let c=0;for(const[d,u]of s){const f=t.edges[d];if(!f)continue;const h=[];for(const g of u.sort((y,w)=>y.order-w.order)){const y=h.at(-1);const w=y?Qs([y,...g.points]).slice(1):Qs(g.points);const S=w[0],x=w[1];const M=y&&S&&Math.abs(y.x-S.x)<1e-6&&Math.abs(y.y-S.y)<1e-6;const b=y&&S&&x&&(y.x===S.x&&S.x===x.x&&S.y>=Math.min(y.y,x.y)&&S.y<=Math.max(y.y,x.y)||y.y===S.y&&S.y===x.y&&S.x>=Math.min(y.x,x.x)&&S.x<=Math.max(y.x,x.x));h.push(...M||b?w.slice(1):w)}let m;if(f.label&&h.length>=2){const g=u.find(y=>y.labelPosition)?.labelPosition;m=g??sn(h)}const p=px(h,o,c);if(p!==h){c++}if(f.label&&p!==h&&p.length>=2){m=sn(p)}n.push({source:f.source,target:f.target,...f.id!==void 0?{id:f.id}:{},label:f.label,...f.labelContent?{labelContent:f.labelContent}:{},style:f.style,hasArrowStart:f.hasArrowStart,hasArrowEnd:f.hasArrowEnd,startMarker:f.startMarker,endMarker:f.endMarker,...f.curve?{curve:f.curve}:{},...f.animate?{animate:true}:{},...f.animation?{animation:f.animation}:{},points:p,labelPosition:m,inlineStyle:Kc(d,t),...f.id&&t.classAssignments.has(f.id)?{classNames:t.classAssignments.get(f.id).split(/\s+/).filter(Boolean)}:{},edgeIndex:d})}}function h_(e,t,n,i,r){if(e.edges){for(const o of e.edges){const s=o.hierarchySegment;const a=s?.edgeIndex??parseInt(o.id.substring(1),10);if(isNaN(a))continue;const l=o.container?r.get(o.container):void 0;const c=l?.x??n,d=l?.y??i;const u=[];if(o.sections&&o.sections.length>0){const m=o.sections[0];u.push({x:m.startPoint.x+c,y:m.startPoint.y+d});if(m.bendPoints){for(const p of m.bendPoints){u.push({x:p.x+c,y:p.y+d})}}u.push({x:m.endPoint.x+c,y:m.endPoint.y+d})}let f;if(o.labels&&o.labels.length>0){const m=o.labels[0];if(m.x!=null&&m.y!=null){f={x:m.x+(m.width??0)/2+c,y:m.y+(m.height??0)/2+d}}}const h=t.get(a)??[];h.push({order:s?.order??0,points:u,labelPosition:f});t.set(a,h)}}if(e.children){for(const o of e.children){h_(o,t,n+(o.x??0),i+(o.y??0),r)}}}function b_(e,t){const n=new Set(e);const i=new Map(e.map((u,f)=>[u,f]));const r=new Map(e.map(u=>[u,new Set]));const o=new Map(e.map(u=>[u,0]));const s=(u,f)=>{const h=new Set;const m=[u];while(m.length>0){const p=m.pop();if(p===f)return true;if(h.has(p))continue;h.add(p);for(const g of r.get(p)??[])m.push(g)}return false};for(const u of t){if(u.source===u.target||!n.has(u.source)||!n.has(u.target))continue;const f=u.source;const h=u.target;const m=r.get(f);if(m.has(h))continue;if(s(h,f))continue;m.add(h);o.set(h,(o.get(h)??0)+1)}const a=(u,f)=>(i.get(u)??0)-(i.get(f)??0);const l=e.filter(u=>(o.get(u)??0)===0).sort(a);const c=u=>{let f=l.length;l.push(u);while(f>0){const h=f-1>>>1;if(a(l[h],u)<=0)break;l[f]=l[h];f=h}l[f]=u};const d=[];while(l.length>0){const u=l[0];const f=l.pop();if(l.length){let h=0;while(h*2+1<l.length){let m=h*2+1;if(m+1<l.length&&a(l[m+1],l[m])<0)m++;if(a(f,l[m])<=0)break;l[h]=l[m];h=m}l[h]=f}d.push(u);for(const h of Array.from(r.get(u)??[]).sort(a)){const m=(o.get(h)??0)-1;o.set(h,m);if(m===0){c(h)}}}if(d.length<e.length){const u=new Set(d);d.push(...e.filter(f=>!u.has(f)).sort(a))}return d}function S_(e,t,n,i,r="TB",o,s){void e;const a=s??Wn(t,i,"node");if(n==="state-fork"||n==="state-join"){const d=r==="LR"||r==="RL";const u=o?.forkWidth??70;const f=o?.forkHeight??10;return d?{width:f,height:u}:{width:u,height:f}}if(n==="state-choice"){return{width:36,height:36}}if(n==="state-history"){return{width:32,height:32}}let l=a.width+i.nodePaddingX*2;let c=a.height+i.nodePaddingY*2;if(n==="service"){l=Math.max(l+34,120);c=Math.max(c+6,48)}if(n==="diamond"){const d=Math.max(l,c)+i.diamondExtraPadding;l=d;c=d}if(n==="circle"||n==="doublecircle"){const d=Math.ceil(Math.sqrt(l*l+c*c))+8;l=n==="doublecircle"?d+12:d;c=l}if(n==="ellipse"){l=Math.ceil(l*Math.SQRT2);c=Math.ceil(c*Math.SQRT2)}if(n==="hexagon"){l+=i.nodePaddingX}if(n==="trapezoid"||n==="trapezoid-alt"||n==="lean-r"||n==="lean-l"){l+=i.nodePaddingX}if(n==="asymmetric"){l+=12}if(n==="cylinder"){c+=14}if(n==="state-start"||n==="state-end"){return{width:28,height:28}}l=Math.max(l,60);c=Math.max(c,36);return{width:l,height:c}}function w_(e,t){const n=new Map;if(ar("APL_NO_CORANK_FANIN"))return n;const i=new Map;for(let r=0;r<e.edges.length;r++){const o=e.edges[r];if(o.source===o.target)continue;if(!i.has(o.target))i.set(o.target,[]);i.get(o.target).push(r)}for(const[r,o]of i){if(o.length<2)continue;const s=o.filter(f=>!!e.edges[f].label);const a=o.filter(f=>!e.edges[f].label);if(s.length===0||a.length===0)continue;const l=e.nodes.get(r)?.shape;if(l===void 0||!gn.has(l))continue;const c=f=>e.nodes.get(f)?.shape==="rectangle";if(!o.every(f=>c(e.edges[f].source)))continue;let d=0;let u=0;for(const f of s){const h=Wn(qe(e.edges[f].label,e.edges[f].labelContent),t,"edge");const m=h.text;d=Math.max(d,h.width+8);u=Math.max(u,h.height+6)}for(const f of a)n.set(f,{width:d,height:u})}return n}function kk(e){return{text:" ",width:e.width,height:e.height,layoutOptions:{"elk.edgeLabels.inline":"true","elk.edgeLabels.placement":"CENTER"}}}function B8(e,t){const n=new Map;for(let r=0;r<e.edges.length;r++){const o=e.edges[r],s=e.nodes.get(o.target);if(!s||s.shape!=="rectangle"||s.semanticShape||o.style==="invisible"||o.source===o.target)continue;const a=n.get(s.id)??{count:0,span:0,known:true};a.count++;const l=o.style==="thick"?2:1;const c=t.lineWidth*l;const d=Number.isFinite(c)&&c>0?br({...o,curve:void 0,points:[{x:0,y:0},{x:100,y:0}],inlineStyle:Kc(r,e)},{...t,lineWidth:Number(Xe(c))/l,edgeBendRadius:0}):void 0;const u=d?.find(f=>f.position==="end");if(o.hasArrowEnd&&(!u?.bounds||!Object.values(u.bounds).every(Number.isFinite)))a.known=false;else if(u?.bounds)a.span=Math.max(a.span,u.bounds.y1-u.bounds.y0);n.set(s.id,a)}const i=new Map;for(const[r,o]of n){if(o.count<2||!o.known||o.span<=0)continue;i.set(r,{count:o.count,span:o.span})}return i}function M_(e,t){return t>Si({})&&z8(e.edges)?{"elk.spacing.edgeNode":String(t)}:{}}function W8(e,t){let n=Si(e);let i=0;for(const[r,o]of t.edges.entries()){if(o.style==="invisible")continue;const s={...o,inlineStyle:Kc(r,t)};const a=Si(e,s,"start"),l=Si(e,s,"end");n=Math.max(n,a,l);i=Math.max(i,(o.hasArrowStart?a-(e.edgeBendRadius??0):0)+(o.hasArrowEnd?l-(e.edgeBendRadius??0):0))}return{hook:n,corridor:i}}function z8(e){const t=new Map,n=new Map;for(const{source:o,target:s}of e){if(o===s)return true;t.set(o,t.get(o)??0);t.set(s,(t.get(s)??0)+1);n.set(o,[...n.get(o)??[],s])}const i=[...t].filter(([,o])=>o===0).map(([o])=>o);let r=0;for(let o=i.pop();o!==void 0;o=i.pop()){r++;for(const s of n.get(o)??[]){const a=t.get(s)-1;t.set(s,a);if(a===0)i.push(s)}}return r<t.size}function m_(e,t,n){const{hook:i,corridor:r}=W8(n,e);t={...t,layerSpacing:Math.max(t.layerSpacing??ni.layerSpacing,r),markerPortExtents:t.preserveSubgraphChildOrder||t.stateVisual?void 0:B8(e,n)};const o=new Set;const s=new Set;for(const R of e.subgraphs){s.add(R.id);R_(R,o,s)}const a=new Map;for(const R of e.edges){if(R.source!==R.target)continue;a.set(R.source,(a.get(R.source)??0)+1)}const l=Math.max(0,...a.values());if(l>4){t={...t,layerSpacing:Math.max(t.layerSpacing,t.layerSpacing+(l-4)*16)}}const c=t.disableCorankFanIn?new Map:w_(e,n);const d=K8(e.subgraphs);const u=J8(e.subgraphs);const f=Q8(e.subgraphs);const h=Z8(e.subgraphs);const m=eU(e.subgraphs);const p=R=>d.get(R)??h.get(R);const g=R=>f.get(R)??m.get(R)?.slice(0,-1)??[];const y=P_(e,t);const w=X8(e,s);const S=new Map;const x=new Map;let M;const b=R=>{M??=new Set([...e.nodes.keys(),...s,...[...w.byEndpoint.values()].map(L=>L.portId)]);let I=R;while(M.has(I))I+="_";M.add(I);return I};const C=(R,I,L)=>{const $=b(`${R}_${L}_${I}`);const B=S.get(R)??[];B.push({id:$,direction:L});S.set(R,B);return $};const P=(R,I)=>{const L=s.has(R.source)&&g(R.target).includes(R.source);const $=s.has(R.target)&&g(R.source).includes(R.target);const B=L?m.get(R.source):g(R.source);const F=$?m.get(R.target):g(R.target);const z=x_(B,F);const _=z?B.indexOf(z)+1:0;let H=L?C(R.source,I,"in"):w.byEndpoint.get(Rc(I,"source"))?.portId??R.source;const D=$?C(R.target,I,"out"):w.byEndpoint.get(Rc(I,"target"))?.portId??R.target;let j=0;const W=(N,G,Y,q=false)=>{const V=q?U8(I,R,G,Y,n,c):{id:`e${I}_internal_${j}`,sources:[G],targets:[Y]};const ne={...V,id:b(V.id),hierarchySegment:{edgeIndex:I,order:j++}};const X=x.get(N??null)??[];X.push(ne);x.set(N??null,X)};for(const N of B.slice(_).reverse()){const G=C(N,I,"out");W(N,H,G);H=G}const O=F.slice(_).map(N=>({scope:N,port:C(N,I,"in")}));W(z,H,O[0]?.port??D,true);for(let N=0;N<O.length;N++){const G=O[N];W(G.scope,G.port,O[N+1]?.port??D)}};const E=new Map;E.set(null,[]);for(let R=0;R<e.edges.length;R++){const I=e.edges[R];const L=p(I.source);const $=p(I.target);if(L&&L===$){if(!E.has(L)){E.set(L,[])}E.get(L).push({index:R,edge:I})}else if(!L&&!$){E.get(null).push({index:R,edge:I})}else if(!y){const B=x_(g(I.source),g(I.target));if(B){if(!E.has(B))E.set(B,[]);E.get(B).push({index:R,edge:I})}else{E.get(null).push({index:R,edge:I})}}else{P(I,R)}}const k={id:"root",layoutOptions:{"elk.algorithm":"layered","elk.direction":ba(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":String(i),...M_(e,i),"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(ni.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":y?"SEPARATE":"INCLUDE_CHILDREN"},children:[],edges:[]};const v=!t.preserveSubgraphChildOrder;const T=new Map(e.subgraphs.map(R=>[R.id,R]));const A=tU(e,o,s,u,Boolean(t.preserveSubgraphChildOrder));for(const R of A){const I=T.get(R);if(I){k.children.push(E_(I,e,t,n,i,E,S,x,w,v,c,y,e.direction));continue}const L=e.nodes.get(R);if(L&&!o.has(R)&&!s.has(R)){k.children.push(C_(R,L,n,w,e.direction,t.stateVisual,t.nodeSizes?.get(R),t.markerPortExtents?.get(R)))}}for(const{index:R,edge:I}of E.get(null)){const L={id:`e${R}`,sources:[w.byEndpoint.get(Rc(R,"source"))?.portId??I.source],targets:[w.byEndpoint.get(Rc(R,"target"))?.portId??I.target]};if(I.label&&!ar("APL_DECOUPLE_LABELS")){const $=Wn(qe(I.label,I.labelContent),n,"edge");const B=$.text;L.labels=[{text:B,width:$.width+8,height:$.height+6,layoutOptions:{"elk.edgeLabels.inline":"true","elk.edgeLabels.placement":"CENTER"}}]}else if(!I.label&&c.has(R)){L.labels=[kk(c.get(R))]}k.edges.push(L)}for(const R of x.get(null)??[]){k.edges.push(R)}Z$(k,e,t.layoutHints);if(y&&S.size>0)V8(k,S);return k}function Rc(e,t){return`${e}:${t}`}function G8(e){const t=new Set;const n=(i,r)=>{const o=r||i.direction!==void 0;if(o)for(const s of i.nodeIds)t.add(s);for(const s of i.children)n(s,o)};for(const i of e)n(i,false);return t}function H8(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"};case"LR":default:return{source:"E",target:"W"}}}function j8(e,t){const n=H8(e);if(t==="feedback")return{source:n.target,target:n.source};return n}function p_(e){return e?.shape==="rectangle"||e?.shape==="diamond"}function Y8(e){return e?.shape==="rectangle"}function q8(e){if(e.length<2)return false;if(!e.every(r=>r.routeClass==="primary-forward"&&!r.labeled))return false;const t=e[0].side;if(!e.every(r=>r.side===t))return false;const n=new Map;for(const r of e){const o=`${r.sourceId}\0${r.targetId}`;n.set(o,(n.get(o)??0)+1)}const i=[...n.values()].some(r=>r>=2);if(!i)return false;if(e.every(r=>r.endpoint==="target"))return true;if(e.every(r=>r.endpoint==="source")){return e.every(r=>(n.get(`${r.sourceId}\0${r.targetId}`)??0)>=2)}return false}function X8(e,t){const n=Ta(e);const i=new Set;const r=new Set;const o=G8(e.subgraphs);const s=new Set;for(let h=0;h<e.edges.length;h++){const m=e.edges[h];const p=n[h]??"primary-forward";if(p==="primary-forward"&&m.label)s.add(`${m.source}\0${m.target}`);if(p!=="primary-forward"){i.add(m.source);i.add(m.target)}if(p!=="primary-forward"&&p!=="feedback"){r.add(m.source);r.add(m.target)}}const a=[];const l=[];const c=h=>h.replace(/[^A-Za-z0-9_\-]/g,"_");const d=(h,m,p)=>{l.push({edgeIndex:h,routeClass:m,reason:p})};for(let h=0;h<e.edges.length;h++){const m=e.edges[h];const p=n[h]??"primary-forward";if(m.source===m.target){d(h,p,"self-loop");continue}if(t.has(m.source)||t.has(m.target)){d(h,p,"subgraph-endpoint");continue}if(!e.nodes.has(m.source)||!e.nodes.has(m.target)){d(h,p,"missing-node");continue}if(p!=="primary-forward"&&p!=="feedback"){d(h,p,"unsupported-route-class");continue}if(p==="primary-forward"&&(i.has(m.source)||i.has(m.target))){d(h,p,"unsafe-non-primary-incident");continue}if(p==="feedback"&&m.label){d(h,p,"unsupported-route-class");continue}if(p==="feedback"&&s.has(`${m.target}\0${m.source}`)){d(h,p,"labeled-reciprocal-primary");continue}if(p==="feedback"&&(!p_(e.nodes.get(m.source))||!p_(e.nodes.get(m.target)))){d(h,p,"unsupported-shape");continue}if(r.has(m.source)||r.has(m.target)){d(h,p,"unsafe-non-primary-incident");continue}if(o.has(m.source)||o.has(m.target)){d(h,p,"direction-override-node");continue}const g=j8(e.direction,p);a.push({nodeId:m.source,portId:`rp_${c(m.source)}_${h}_s`,side:g.source,edgeIndex:h,sourceId:m.source,targetId:m.target,endpoint:"source",slotIndex:0,routeClass:p,labeled:Boolean(m.label),constraint:"FIXED_SIDE"});a.push({nodeId:m.target,portId:`rp_${c(m.target)}_${h}_t`,side:g.target,edgeIndex:h,sourceId:m.source,targetId:m.target,endpoint:"target",slotIndex:0,routeClass:p,labeled:Boolean(m.label),constraint:"FIXED_SIDE"})}const u=new Map;for(const h of a){const m=u.get(h.nodeId)??[];m.push(h);u.set(h.nodeId,m)}for(const h of u.values()){h.sort((g,y)=>g_(g.side)-g_(y.side)||g.edgeIndex-y.edgeIndex||y_(g.endpoint)-y_(y.endpoint));const m=new Map;for(const g of h){const y=m.get(g.side)??0;g.slotIndex=y;m.set(g.side,y+1)}const p=Y8(e.nodes.get(h[0].nodeId))&&q8(h);for(const g of h){if(p){g.constraint="FIXED_ORDER";g.orderReason="primary-duplicate-face"}else{g.constraint="FIXED_SIDE";g.orderReason=void 0}}}const f=new Map;for(const h of a)f.set(Rc(h.edgeIndex,h.endpoint),h);return{byEndpoint:f,byNode:u,relaxations:l}}function g_(e){return{N:0,E:1,S:2,W:3}[e]}function y_(e){return e==="source"?0:1}function k_(e){switch(e){case"N":return"NORTH";case"E":return"EAST";case"S":return"SOUTH";case"W":return"WEST"}}function C_(e,t,n,i,r="TB",o,s,a){const l=s??S_(e,qe(t.label,t.labelContent),t.shape,n,r,o,t.labelBlock);const c=r==="LR"||r==="RL";let d=c?l.height:l.width;if(!s&&a){const h=Math.max(a.span,Math.min(n.cornerRadius??0,(c?l.width:l.height)/2));if(!(d/(a.count+1)>h)){const m=(a.count+1)*(h+1);if(Number.isFinite(m)&&m>d)d=m}}const u={id:e,width:c?l.width:d,height:c?d:l.height,labels:[{text:t.label}]};const f=i.byNode.get(e);if(f&&f.length>0){const h=f.some(m=>m.constraint==="FIXED_ORDER")?"FIXED_ORDER":"FIXED_SIDE";u.layoutOptions={...u.layoutOptions??{},"elk.portConstraints":h};u.ports=f.map(m=>({id:m.portId,width:0,height:0,layoutOptions:{"elk.port.side":k_(m.side),"elk.port.index":String(m.slotIndex)}}))}return u}function U8(e,t,n,i,r,o){const s={id:`e${e}`,sources:[n],targets:[i]};if(t.label&&!ar("APL_DECOUPLE_LABELS")){const a=Wn(qe(t.label,t.labelContent),r,"edge");const l=a.text;s.labels=[{text:l,width:a.width+8,height:a.height+6,layoutOptions:{"elk.edgeLabels.inline":"true","elk.edgeLabels.placement":"CENTER"}}]}else if(!t.label&&o?.has(e)){s.labels=[kk(o.get(e))]}return s}function P_(e,t){const n=i=>i.direction!==void 0||i.children.some(n);return t.separateHierarchy===true||e.subgraphs.some(n)}function V8(e,t){const n=r=>r==="RIGHT"||r==="LEFT";const i=r=>{const o=n(r.layoutOptions?.["elk.direction"]);let s=false;for(const a of r.children??[]){if(a.children===void 0)continue;if(!s&&t.has(a.id)){s=n(a.layoutOptions?.["elk.direction"])!==o||(a.ports??[]).some(l=>{const c=l.layoutOptions?.["elk.port.side"];return o?c==="NORTH"||c==="SOUTH":c==="EAST"||c==="WEST"})}i(a)}if(s&&r.layoutOptions?.["elk.layered.crossingMinimization.forceNodeModelOrder"]==="true"){r.layoutOptions["elk.layered.crossingMinimization.forceNodeModelOrder"]="false";r.layoutOptions["elk.layered.considerModelOrder.strategy"]??="NODES_AND_EDGES"}};i(e)}function Ck(e,t){if(!e.label||e.concurrencyRegion||e.headerMinHeight===void 0&&e.nodeIds.length===0&&e.children.length===0)return 0;const n=Wn(qe(e.label,e.labelContent),t,"group").width;return Math.ceil((e.titleOffset??t.groupLabelPaddingX)+n+t.groupLabelPaddingX)}function Pk(e,t,n=Wn(qe(e.label,e.labelContent),t,"group")){if(e.concurrencyRegion)return 0;const i=t.groupHeaderFontSize+16+n.height-n.lineHeight;if(e.headerMinHeight===void 0)return i;if(!Number.isFinite(e.headerMinHeight)||e.headerMinHeight<=0)throw new RangeError("Invalid internal group header minimum");return Math.max(i,e.headerMinHeight)}function E_(e,t,n,i,r,o,s,a,l,c,d,u,f="TB"){const h=Pk(e,i);const m=e.concurrencyRegion?n.stateVisual?.dividerMargin??0:0;const p=e.direction??f;const g={"elk.algorithm":"layered","elk.padding":`[top=${h+i.groupPaddingY+m},left=${i.groupPaddingX+m},bottom=${i.groupPaddingY+m},right=${i.groupPaddingX+m}]`,"elk.edgeRouting":"ORTHOGONAL","elk.contentAlignment":"H_CENTER V_CENTER","elk.spacing.edgeEdge":"12","elk.layered.spacing.edgeEdgeBetweenLayers":"12","elk.layered.spacing.edgeNodeBetweenLayers":String(r),...M_(t,r),"elk.layered.nodePlacement.bk.fixedAlignment":"BALANCED","elk.layered.spacing.nodeNodeBetweenLayers":String(n.layerSpacing),"elk.spacing.nodeNode":String(n.nodeSpacing)};if(e.direction||u){g["elk.direction"]=ba(p)}const y=Ck(e,i);if(y>0&&u){g["elk.nodeSize.constraints"]="MINIMUM_SIZE";g["elk.nodeSize.minimum"]=`(${y}, 0)`}const w={id:e.id,layoutOptions:g,labels:e.label?[{text:e.label}]:void 0,children:[],edges:[],...e.headerMinHeight!==void 0&&e.nodeIds.length===0&&e.children.length===0?{width:Math.max(y,2*i.groupPaddingX),height:h+2*i.groupPaddingY}:{}};const S=s.get(e.id)??[];if(S.length>0){const b=h>0;const C=_t(t.direction);w.ports=S.map(P=>{const E=P.direction==="in"?C.targetSide:C.sourceSide;const k=E==="N"?P.direction==="in"?"W":"E":E;return{id:P.id,...b&&(E==="N"||p==="BT")?{layoutOptions:{"elk.port.side":k_(k)}}:{}}});if(b)w.layoutOptions["elk.portConstraints"]="FIXED_SIDE"}const x=c?b_(e.nodeIds,t.edges):e.nodeIds;for(const b of x){const C=t.nodes.get(b);if(C){w.children.push(C_(b,C,i,l,p,n.stateVisual,n.nodeSizes?.get(b),n.markerPortExtents?.get(b)))}}for(const b of e.children){w.children.push(E_(b,t,n,i,r,o,s,a,l,c,d,u,p))}const M=o.get(e.id)??[];for(const{index:b,edge:C}of M){const P={id:`e${b}`,sources:[l.byEndpoint.get(Rc(b,"source"))?.portId??C.source],targets:[l.byEndpoint.get(Rc(b,"target"))?.portId??C.target]};if(C.label&&!ar("APL_DECOUPLE_LABELS")){const E=Wn(qe(C.label,C.labelContent),i,"edge");const k=E.text;P.labels=[{text:k,width:E.width+8,height:E.height+6,layoutOptions:{"elk.edgeLabels.inline":"true","elk.edgeLabels.placement":"CENTER"}}]}else if(!C.label&&d.has(b)){P.labels=[kk(d.get(b))]}w.edges.push(P)}for(const b of a.get(e.id)??[]){w.edges.push(b)}return w}function R_(e,t,n){for(const i of e.nodeIds){t.add(i)}for(const i of e.children){n.add(i.id);R_(i,t,n)}}function K8(e){const t=new Map;function n(i){for(const r of i.nodeIds){t.set(r,i.id)}for(const r of i.children){n(r)}}for(const i of e){n(i)}return t}function J8(e){const t=new Map;function n(i,r){for(const o of i.nodeIds)t.set(o,r);for(const o of i.children)n(o,r)}for(const i of e)n(i,i.id);return t}function Q8(e){const t=new Map;function n(i,r){const o=[...r,i.id];for(const s of i.nodeIds)t.set(s,o);for(const s of i.children)n(s,o)}for(const i of e)n(i,[]);return t}function Z8(e){const t=new Map;function n(i,r){t.set(i.id,r);for(const o of i.children)n(o,i.id)}for(const i of e)n(i,void 0);return t}function eU(e){const t=new Map;function n(i,r){const o=[...r,i.id];t.set(i.id,o);for(const s of i.children)n(s,o)}for(const i of e)n(i,[]);return t}function x_(e,t){let n;for(let i=0;i<Math.min(e.length,t.length);i++){if(e[i]!==t[i])break;n=e[i]}return n}function tU(e,t,n,i,r){const o=[];const s=new Set;const a=u=>{if(s.has(u))return;s.add(u);o.push(u)};const l=()=>{for(const u of e.nodes.keys()){const f=i.get(u);if(f)a(f);else if(!t.has(u)&&!n.has(u))a(u)}};const c=()=>{for(const u of e.subgraphs)a(u.id)};if(r){c();l()}else{l();c()}const d=e.edges.map(u=>({source:i.get(u.source)??u.source,target:i.get(u.target)??u.target}));return b_(o,d)}function Sk(e,t=false){const n=new Set;for(const i of e){if(i.source===i.target||t&&!i.label)continue;const r=JSON.stringify([i.source,i.target]);if(n.has(r))return true;n.add(r)}return false}function nU(e){const t=e.nodes.map(i=>({node:i,x:i.x,y:i.y}));const n=e.edges.map(i=>({edge:i,points:i.points.map(r=>({...r})),labelPosition:i.labelPosition?{...i.labelPosition}:void 0}));return()=>{for(const{node:i,x:r,y:o}of t){i.x=r;i.y=o}for(const{edge:i,points:r,labelPosition:o}of n){i.points=r;i.labelPosition=o}}}var iU=[{id:"extractEdgesRecursively",doc:"flatten ELK edges to absolute coords (+orthogonalize cross-hierarchy)",after:[],mutates:["extract"],determinism:"pure-order",run:e=>{if(e.elkResult)bk(e.elkResult,e.graph,e.edges,0,0,e.margins);yx(e,e.style)}},{id:"alignLayerNodes",doc:"snap same-layer nodes onto a shared flow-axis line",after:["extractEdgesRecursively"],mutates:["positions","edges"],determinism:"in-place",enabled:e=>Boolean(e.elkResult)||e.mergeEdges,mayChangeMetrics:{bends:"improve-only",straight:"improve-only"},run:e=>{hx(e.nodes,e.edges,e.graph.direction)}},{id:"equalizePeerNodeDimensions",doc:"equalize peer box sizes + pack layers so symmetry is visible downstream",after:["alignLayerNodes"],mutates:["positions","dimensions"],determinism:"in-place",enabled:e=>Boolean(e.elkResult)||e.mergeEdges,run:e=>{ik(e.nodes,e.edges,e.groups,e.graph,e.style)}},{id:"alignForkRejoinPeerCenters",doc:"center fork/rejoin hubs on their peer barycenter",after:["equalizePeerNodeDimensions"],mutates:["positions"],determinism:"in-place",mayChangeMetrics:{symErr:"improve-only",bends:{worsenBy:2}},enabled:e=>Boolean(e.elkResult)||e.mergeEdges,run:e=>{sk(e.nodes,e.edges,e.groups,e.graph,e.style)}},{id:"alignPortLanes",doc:"slide one endpoint node so a floating-straight edge becomes port-exact (Ruegg GD15)",after:["alignForkRejoinPeerCenters"],mutates:["positions","edges"],determinism:"in-place",enabled:e=>Boolean(e.elkResult),mayChangeMetrics:{straight:"improve-only",portRate:"improve-only",bends:"improve-only"},run:e=>{fk(e.nodes,e.edges,e.groups,e.graph.direction,e.style)}},{id:"centerPeerBarycenters",proposal:true,doc:"center peer fan-in/fan-out trunks over peer barycenters (#57/#61)",after:["alignPortLanes"],mutates:["positions"],determinism:"in-place",mayChangeMetrics:{symErr:"improve-only",bends:{worsenBy:2}},enabled:e=>Boolean(e.elkResult)||e.mergeEdges,run:e=>{let t;rk(e.nodes,e.edges,e.groups,e.graph,e.style,()=>{t??=nU(e)});return t}},{id:"honorLinkRankDistance",doc:"shove target sub-DAG to honor variable-length link rank distance; push ahead anything the shove lands on and rebuild blocked reconnect routes through free channels (#81)",after:["centerPeerBarycenters"],mutates:["positions"],determinism:"in-place",enabled:e=>Boolean(e.elkResult)||e.mergeEdges,run:e=>{ak(e.nodes,e.edges,e.groups,e.graph)}},{id:"alignLabeledSourcePort",doc:"slide a single-outgoing labelled source onto the lane the straightener will use so the exit stays mid-port (alignPortLanes excludes labelled edges)",after:["honorLinkRankDistance"],mutates:["positions","edges"],determinism:"in-place",mayChangeMetrics:{portRate:"improve-only"},enabled:e=>Boolean(e.elkResult)||e.mergeEdges,run:e=>{uk(e.nodes,e.edges,e.groups,e.graph,e.graph.direction,e.style)}},{id:"bundleEdgePaths",doc:"bundle fan-out/fan-in edges into shared trunks (when mergeEdges)",after:["alignLabeledSourcePort"],mutates:["edges"],determinism:"pure-order",enabled:e=>e.mergeEdges,run:e=>{e.bundled=xk(e.edges,e.nodes,e.groups,e.graph.direction,e.style);e.genericBundled=e.bundled.size>0}},{id:"markCorankFanInBundles",doc:"re-route + mark co-ranked mixed-label fan-in spokes bundle-owned (justified symmetric-convergence bend)",after:["bundleEdgePaths"],mutates:["edges"],determinism:"in-place",enabled:e=>Boolean(e.elkResult)||e.mergeEdges,run:e=>{ok(e.nodes,e.edges,e.groups,e.graph,e.bundled,e.style)}},{id:"clipEdgeToShape",doc:"clip edge endpoints to real (non-rect) shape outlines",after:["bundleEdgePaths"],mutates:["edges"],determinism:"in-place",mayChangeMetrics:{portRate:{worsenBy:1,whenImproves:"endpointApproaches"},endpointApproaches:"improve-only"},run:e=>{const t=new Map(e.nodes.map(n=>[n.id,n]));for(const n of e.edges){const i=e.bundled.has(n)?ql(n):void 0;n.points=n.points.filter((s,a,l)=>a===0||s.x!==l[a-1].x||s.y!==l[a-1].y);const r=t.get(n.source);const o=t.get(n.target);nf(n,r,o);if(r)n.points=si(n.points,r,true);if(o)n.points=si(n.points,o,false);Fa(n,i)}}},{id:"applySymmetricFanoutEmissions",doc:"re-route small equivalent fan-outs symmetrically; mark bundle-owned",after:["clipEdgeToShape"],mutates:["edges"],determinism:"in-place",mayChangeMetrics:{symErr:"improve-only",bends:{worsenBy:2}},enabled:e=>Boolean(e.elkResult)||e.mergeEdges,run:e=>{dk(e.nodes,e.edges,e.groups,e.graph,e.bundled,e.style)}},{id:"applySymmetricParallelEdgeLanes",doc:"separate parallel edges into symmetric non-crossing lanes",after:["clipEdgeToShape"],mutates:["edges"],determinism:"in-place",enabled:e=>(Boolean(e.elkResult)||e.mergeEdges)&&Sk(e.edges,true),mayChangeMetrics:{symErr:"improve-only",crossings:"improve-only"},run:e=>{mk(e.nodes,e.edges,e.groups,e.graph,e.bundled,e.style)}},{id:"applyParallelDuplicateLanes",doc:"split exact duplicate edges into separated lanes",after:["clipEdgeToShape"],mutates:["edges"],determinism:"in-place",enabled:e=>(Boolean(e.elkResult)||e.mergeEdges)&&Sk(e.edges),mayChangeMetrics:{crossings:{worsenBy:1,whenImproves:"parallelOverlaps",perImprovement:true},parallelOverlaps:"improve-only"},run:e=>{pk(e.nodes,e.edges,e.groups,e.graph,e.bundled,e.style,e.elkResult?void 0:e.style)}},{id:"collapseTinyBundledHitches",doc:"remove sub-perceptual hitches introduced by bundling",after:["applySymmetricFanoutEmissions","applySymmetricParallelEdgeLanes","applyParallelDuplicateLanes"],mutates:["edges"],determinism:"in-place",mayChangeMetrics:{bends:"improve-only"},run:e=>{Q0(e.nodes,e.edges,e.bundled)}},{id:"reassignBundledSiblingLabels",doc:"re-home labels onto the correct bundled sibling segment",after:["collapseTinyBundledHitches"],mutates:["edges"],determinism:"in-place",run:e=>{lk(e.nodes,e.edges,e.bundled,e.graph.direction,e.style,e.groups)}},{id:"applyRouteContracts",doc:"classify -> simplify -> straighten (fixed-point) -> certify; FREEZES node geometry",after:["reassignBundledSiblingLabels"],mutates:["edges"],determinism:"fixed-point",freezesNodes:true,mayChangeMetrics:{straight:{worsenBy:1,whenImproves:["hard","crossings","endpointApproaches"],perImprovement:true},bends:{worsenBy:4,whenImproves:["hard","crossings","endpointApproaches"],perImprovement:true},portRate:{worsenBy:1,whenImproves:["hard","crossings","bends","endpointApproaches","opposingOverlaps"]}},run:e=>{Tp({nodes:e.nodes,edges:e.edges,groups:e.groups},e.graph,e.bundled,e.style,e.elkResult?void 0:{preserveSelfLoops:true,preserveLabels:true,preserveStraightRoutes:true})}},{id:"reanchorOffOutlineEndpoints",doc:"re-route an edge whose endpoint dangles off a moved node onto that node's flow port (edge-only, freeze-safe)",after:["applyRouteContracts"],mutates:["edges"],determinism:"in-place",run:e=>{mc(e.nodes,e.edges,e.graph,e.style)}},{id:"rerouteEdgesThroughNodes",doc:"re-route an edge left running through a node by a node-mover (honorLinkRankDistance/alignPortLanes) around the obstacle and restore protected marker leads before label placement (edge-only, freeze-safe)",after:["reanchorOffOutlineEndpoints"],mutates:["edges"],determinism:"in-place",run:e=>{No(e.nodes,e.edges,e.graph,void 0,e.groups);Ap({nodes:e.nodes,edges:e.edges,groups:e.groups},e.graph,e.style)}},{id:"repairLabelsOnSharedTrunks",doc:"give a shared-trunk label a clear seat or a proved private channel (edge-only, freeze-safe)",after:["rerouteEdgesThroughNodes"],mutates:["edges"],determinism:"in-place",run:e=>{iv({nodes:e.nodes,edges:e.edges,groups:e.groups},e.graph,e.style)}},{id:"repairLabelsOffOwnRoute",doc:"re-slot a labeled edge whose pill sits off its OWN route onto it \u2014 ELK offset placement on an already-straight edge (label-only, freeze-safe)",after:["repairLabelsOnSharedTrunks"],mutates:["edges"],determinism:"in-place",run:e=>{Lp({nodes:e.nodes,edges:e.edges,groups:e.groups},e.graph,e.style)}},{id:"separateEdgeLabelPills",doc:"slide colliding edge-label pills along their own routes into clear slots \u2014 parallel/reciprocal lane labels stack at midpoints (label-only, freeze-safe)",after:["repairLabelsOffOwnRoute"],mutates:["edges"],determinism:"in-place",run:e=>{hf({nodes:e.nodes,edges:e.edges,groups:e.groups},e.graph,e.style,e.elkResult?void 0:{preserveRouteClearance:true})}},{id:"closeRouteContracts",doc:"re-prove settled final routes and re-certify only auditor-proven hitches; each scan monotonically removes bends (edge-only)",after:["separateEdgeLabelPills"],mutates:["edges"],determinism:"fixed-point",mayChangeMetrics:{straight:"improve-only",bends:"improve-only"},run:e=>{Ip({nodes:e.nodes,edges:e.edges,groups:e.groups},e.graph,e.style)}},{id:"translateGeometryToNonNegativeOrigin",doc:"shift whole graph to a non-negative origin (allowed after freeze)",after:["closeRouteContracts"],mutates:["translate"],determinism:"in-place",run:e=>{of(e.nodes,e.edges,e.groups,e.layoutPadding,e.style)}},{id:"placeStateNotes",doc:"place state-diagram note boxes on their declared side, clear of nodes/groups/routes (state diagrams only; translate-only)",after:["translateGeometryToNonNegativeOrigin"],mutates:["translate"],determinism:"in-place",enabled:e=>Boolean(e.graph.stateNotes?.length),run:e=>{e.notes=aU(e.nodes,e.edges,e.groups,e.graph,e.style,e.layoutPadding,e.stateNoteMargin)}}];function yx(e,t){for(const i of e.nodes){i.labelBlock??=Wn(qe(i.label,i.labelContent),t,"node");if(i.icon&&!i.iconFallbackBlock&&!ll(i.icon))i.iconFallbackBlock=Be(al(i.icon),{fontSize:10,fontWeight:400})}for(const i of e.edges)if(i.label!==void 0)i.labelBlock??=Wn(qe(i.label,i.labelContent),t,"edge");const n=i=>{i.labelBlock??=Wn(qe(i.label,i.labelContent),t,"group");i.headerHeight=Pk(i,t,i.labelBlock);i.children.forEach(n)};e.groups.forEach(n)}function rU(e,t){const n={nodes:e.nodes,edges:e.edges,groups:e.groups,width:0,height:0};return gv(e.graph,n,t,e.style,e.bundled)}var au=6;var oU=10;var sU=8;function aU(e,t,n,i,r,o,s){const a=i.stateNotes??[];if(a.length===0)return[];const l=[];const c=p=>{for(const g of p){l.push(g);c(g.children)}};c(n);const d=[];for(const p of e)d.push({x:p.x,y:p.y,w:p.width,h:p.height});for(const p of l)d.push({x:p.x,y:p.y,w:p.width,h:p.height});for(const p of t){if(p.style==="invisible")continue;for(let y=1;y<p.points.length;y++){const w=p.points[y-1],S=p.points[y];d.push({x:Math.min(w.x,S.x)-2,y:Math.min(w.y,S.y)-2,w:Math.abs(w.x-S.x)+4,h:Math.abs(w.y-S.y)+4})}const g=p.label?kt(p,r):null;if(g)d.push(g)}const u=(p,g)=>p.x<g.x+g.w&&p.x+p.w>g.x&&p.y<g.y+g.h&&p.y+p.h>g.y;const f=[];for(const p of a){const g=e.find(P=>P.id===p.target);const y=g?void 0:l.find(P=>P.id===p.target);const w=g??y;if(!w)continue;const S=Wn(qe(p.text,p.textContent),r,"note");const x=S.width+oU*2;const M=S.height+sU*2;const b=w.y+(w.height-M)/2;let C=p.side==="left"?w.x-s-x:w.x+w.width+s;for(let P=0;P<d.length+f.length+4;P++){const E={x:C-au,y:b-au,w:x+au*2,h:M+au*2};const k=d.find(v=>u(E,v))??f.map(v=>({x:v.x,y:v.y,w:v.width,h:v.height})).find(v=>u(E,v));if(!k)break;C=p.side==="left"?k.x-au-x:k.x+k.w+au}f.push({id:p.id,target:p.target,side:p.side,text:p.text,...p.textContent?{textContent:p.textContent}:{},textBlock:S,x:C,y:b,width:x,height:M})}let h=0;let m=0;for(const p of f){h=Math.min(h,p.x);m=Math.min(m,p.y)}if(h<0||m<0){const p=h<0?-h+o:0;const g=m<0?-m+o:0;const y=w=>{w.x+=p;w.y+=g;w.children.forEach(y)};for(const w of e){w.x+=p;w.y+=g}for(const w of n)y(w);for(const w of t){for(const S of w.points){S.x+=p;S.y+=g}if(w.labelPosition){w.labelPosition.x+=p;w.labelPosition.y+=g}}for(const w of f){w.x+=p;w.y+=g}}return f}function Hh(e,t,n=false,i=ni.padding,r=Ue({}),o=18){const s=[];const a=[];const l=[];const c=new Set;for(const d of t.subgraphs){T_(d,c)}wk(e,t,c,s,l,0,0);return v_({width:e.width??800,height:e.height??600,nodes:s,edges:a,groups:l},t,n,i,r,o,e)}function v_(e,t,n,i,r,o,s,a){const{nodes:l,edges:c,groups:d}=e;const u=Np(d);const f=u.length>0?{leftX:Math.min(...u.map(w=>w.x))-20,rightX:Math.max(...u.map(w=>w.right))+20}:void 0;const h={elkResult:s,graph:t,nodes:l,edges:c,groups:d,notes:[],margins:f,bundled:new Set,genericBundled:false,mergeEdges:n,style:r,layoutPadding:i,stateNoteMargin:o,frozen:false};if(a)for(const w of a)h.bundled.add(c[w]);yx(h,r);OR(h,iU,{measureMetrics:rU});let m=e.width;let p=e.height;const g=bn.width;const y=i;for(const w of l){m=Math.max(m,w.x+w.width+y);p=Math.max(p,w.y+w.height+y)}for(const w of Np(d)){m=Math.max(m,w.right+y);p=Math.max(p,w.bottom+y)}for(const w of c){for(const x of w.points){m=Math.max(m,x.x+g+y);p=Math.max(p,x.y+g+y)}const S=w.labelBlock?kt(w,r):null;if(S){m=Math.max(m,w.labelPosition.x+60+y,S.x+S.w+y);p=Math.max(p,w.labelPosition.y+20+y,S.y+S.h+y)}}for(const w of h.notes){m=Math.max(m,w.x+w.width+y);p=Math.max(p,w.y+w.height+y)}return{genericBundled:h.genericBundled,positioned:{width:m,height:p,nodes:l,edges:c,groups:d,...h.notes.length>0?{notes:h.notes}:{}}}}function wk(e,t,n,i,r,o,s){if(!e.children)return;for(const a of e.children){const l=(a.x??0)+o;const c=(a.y??0)+s;const d=a.width??0;const u=a.height??0;if(n.has(a.id)){const f=[];wk(a,t,n,i,f,l,c);const h=Jl(t.subgraphs,a.id);const m=h?.stateComposite?jb(a.id,t):void 0;r.push({id:a.id,label:h?.label??"",...h?.labelContent?{labelContent:h.labelContent}:{},x:l,y:c,width:d,height:u,children:f,...h?.headerMinHeight===void 0?{}:{headerMinHeight:h.headerMinHeight},...h?.concurrencyRegion?{concurrencyRegion:true}:{},...m?{inlineStyle:m}:{}})}else{const f=t.nodes.get(a.id);if(f){const h=Hb(a.id,t);const m=t.classAssignments.get(a.id);const p=m?m.split(/\s+/).filter(Boolean):void 0;i.push({id:a.id,label:f.label,...f.labelContent?{labelContent:f.labelContent}:{},...f.labelBlock?{labelBlock:f.labelBlock}:{},shape:f.shape,...f.floatingNoteId!==void 0?{floatingNoteId:f.floatingNoteId}:{},...f.semanticShape!==void 0?{semanticShape:f.semanticShape}:{},x:l,y:c,width:d,height:u,inlineStyle:h,classNames:p,...f.icon?{icon:f.icon}:{},...f.image?{image:f.image}:{},...f.iconForm?{iconForm:f.iconForm}:{},...f.href?{href:f.href}:{}})}if(a.children&&a.children.length>0){wk(a,t,n,i,r,l,c)}}}}function T_(e,t){t.add(e.id);for(const n of e.children){T_(n,t)}}function xx(e,t={}){Tm(e);const n=cU(e,t);const i=Ue(t,t.stateVisual?.styleDefaults,t.styleFace);yx(n,i);const r=tn(t.diagramTitle,Ue(t,t.stateVisual?.styleDefaults,t.styleFace));if(!r)return n;const o=t.padding??ni.padding;if(n.width===0&&n.height===0)return Object.assign(n,pa(r,o));lU(n,r.height);n.height+=r.height;n.width=Math.max(n.width,r.width+2*o);n.title=on(r,n.width,o);const s=ow(n,i);if(s.length)throw new Qe([{strategy:"final-title-projection",violations:s}]);return n}function L_(e,t={}){Tm(e);const n=Mk(e,t,"placement");yx({...n,edges:[]},Ue(t,void 0,t.styleFace));return n}function A_(e,t={}){Tm(e);const n=Ue(t,void 0,t.styleFace);return mI(e,t,n,I_)}function lU(e,t){const n=i=>{i.y+=t;for(const r of i.children)n(r)};for(const i of e.nodes)i.y+=t;for(const i of e.groups)n(i);for(const i of e.edges){for(const r of i.points)r.y+=t;if(i.labelPosition)i.labelPosition.y+=t}for(const i of e.notes??[])i.y+=t}function jh(e,t,n,i=false){const r=t.stateVisual;const o={...ni,...t,...r?{stateVisual:r}:{}};const s=Ue(t,r?.styleDefaults,t.styleFace);const a=m_(e,o,s);if(i&&!r){const g=ek(e,a,o.padding,o.nodeSpacing,o.layerSpacing);if(!g)throw new Error("Graph is ineligible for indexed forest layout");const y=Hh(g,e,ni.mergeEdges,o.padding,s,18);if(y.genericBundled){n?.(y.positioned,()=>Hh(g,e,false,o.padding,s,18).positioned)}return y.positioned}if(e.nodes.size===1&&e.edges.length===0&&e.subgraphs.length===0&&!e.stateNotes?.length&&!r&&a.children?.length===1){const g=a.children[0];const y={...a,width:g.width+2*o.padding,height:g.height+2*o.padding,children:[{...g,x:o.padding,y:o.padding}]};return Hh(y,e,ni.mergeEdges,o.padding,s,18).positioned}const l=[{},{"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"}];let c;let d;let u="exception";let f=0;for(const g of l){if(++f>1)xl("elk-degradation",u,f);const y=Object.keys(g).length===0?a:m_(e,o,s);if(Object.keys(g).length>0){y.layoutOptions={...y.layoutOptions,...g}}try{const w=qa(y);if(gx(w)){d=new Error("ELK returned non-finite layout geometry");u="non-finite-geometry";continue}c=w;break}catch(w){if(w instanceof Ts||w instanceof Ri)throw w;d=w;u="exception"}}if(!c)throw d;const h=c;const m=r?.noteMargin??18;const p=Hh(h,e,ni.mergeEdges,o.padding,s,m);if(p.genericBundled){n?.(p.positioned,()=>Hh(h,e,false,o.padding,s,m).positioned)}return p.positioned}var I_={edgeSelectorIndices:Fd,graphEdgeMarkerPaintRegions:br,customTextMeasurementActive:vr,certifyCandidate:sw,retainSelection:aw,countEdgeCrossings:Ql,countOpposingRouteOverlaps:Jo,countParallelRouteOverlaps:Da,measureLabelConflicts:_a,DEFAULTS:ni,LABEL_PILL_PADDING:nn,measureRenderStage:ei,graphTextBlock:Wn,resolveLabelContent:qe,groupTitleWidth:Ck,groupHeaderHeight:Pk,estimateNodeSize:S_,resolveNodeInlineStyle:Hb,resolveEdgeInlineStyle:Kc,resolveClassInlineStyle:jb,containsNonFiniteNumber:gx,finishGraphGeometry:v_,unsupported:e=>{throw new Mo(e)}};function cU(e,t){if(!t.graphLayout)return Mk(e,t);return Qr(t,()=>{const n=Ue(t,t.stateVisual?.styleDefaults,t.styleFace);return hI(e,t,n,I_)},()=>Mk(e,t),true,(n,i)=>{n.layoutDecision=i})}function Mk(e,t,n){const i=Ue(t,t.stateVisual?.styleDefaults,t.styleFace);const r=f=>F_(f.groups,e,i);const o=t.compareRoutePreferences!==false;const s=new WeakMap;const a=o&&Gs(e)&&!Sk(e.edges)?(f,h)=>{s.set(f,h)}:void 0;const l=e.subgraphs.length>0&&!P_(e,t);const c=[{strategy:"default",produce:()=>jh(e,t,a),preferNext:r}];const d=(t.nodeSpacing??ni.nodeSpacing)>0&&(t.layerSpacing??ni.layerSpacing)>0;const u=t.graphLayout===void 0&&Dc("indexed-layout")&&d&&!t.stateVisual&&!t.preserveSubgraphChildOrder&&ZM(e)?{strategy:"indexed-forest",produce:()=>jh(e,t,a,true),preferNext:r}:void 0;if(!t.separateHierarchy){c.push({strategy:"separate-hierarchy",produce:()=>jh(e,{...t,separateHierarchy:true},a),preferNext:r,qualityAlternative:o&&l})}if(!t.disableCorankFanIn&&!ar("APL_NO_CORANK_FANIN")){c.push({strategy:"without-corank",produce:()=>jh(e,{...t,disableCorankFanIn:true},a),preferNext:r,qualityAlternative:o&&w_(e,i).size>0});if(!t.separateHierarchy)c.push({strategy:"separate-without-corank",produce:()=>jh(e,{...t,separateHierarchy:true,disableCorankFanIn:true},a),preferNext:r,qualityAlternative:o&&l})}if(n==="placement")return wv(e,i,c,u);return Mv(e,i,c,(f,h)=>{const m=s.get(f);if(!m||h.edgeCrossings===0&&h.labelConflicts===0)return void 0;return{strategy:"without-generic-bundling",produce:m,preferNext:r}},u)}function F_(e,t,n){return e.some(i=>{const r=Jl(t.subgraphs,i.id);return r!==void 0&&i.width+.5<Ck(r,n)||F_(i.children,t,n)})}function gx(e,t=new Set){if(typeof e==="number")return!Number.isFinite(e);if(e===null||typeof e!=="object")return false;if(t.has(e))return false;t.add(e);if(Array.isArray(e))return e.some(n=>gx(n,t));return Object.values(e).some(n=>gx(n,t))}var Ek=16;var Rr=18;var N_=6;var Yh=18;var Tk=600;var $_=20;var dU=40;function W_(e,t={},n){Im(e);const i=n??Tb(un);const r=(S,x)=>Be(S,{display:"formatted",transform:i[`${x}TextTransform`],fontSize:i[`${x}FontSize`],fontWeight:i[`${x}FontWeight`],letterSpacing:i[`${x}LetterSpacing`],fontFamily:x==="group"?i.groupFont:void 0});const o=new Map(e.services.map(S=>[S.id,r(S.label,"service")]));const s=new Map(e.groups.map(S=>[S.id,r(S.label,"group")]));const a=e.edges.map(S=>S.label===void 0?void 0:r(S.label,"edge"));const l=qP(e);const c=t.architecture?.visual?.groupHeaderHeight;if(c!==void 0&&(!Number.isFinite(c)||c<=0))throw new RangeError("Invalid Architecture group-header minimum");const d=c===void 0?void 0:Math.max(Rr,i.groupPaddingY);const u=2*(i.junctionOuterRadius??un.junctionOuterRadius);for(const[S,x]of o)l.nodes.get(S).label=x.text;const f=new Map(e.services.filter(S=>S.iconText!==void 0).map(S=>[S.id,Be(S.iconText,{display:"literal",fontSize:i.serviceFontSize,fontWeight:700})]));for(const[S,x]of f){const M=o.get(S);l.nodes.get(S).labelBlock={...M,width:M.width+x.width+(x.width?10:0),height:Math.max(M.height,x.height)}}const h=S=>{S.label=s.get(S.id).text;if(c!==void 0)S.headerMinHeight=c;S.children.forEach(h)};l.subgraphs.forEach(h);l.edges.forEach((S,x)=>{S.label=a[x]?.text});const m={nodeSizes:new Map(e.junctions.map(S=>[S.id,{width:u+2*N_,height:u+2*N_}])),padding:t.padding??40,nodeSpacing:t.nodeSpacing??Bm,layerSpacing:t.layerSpacing??vb,compareRoutePreferences:false,styleFace:n?{node:{fontSize:n.serviceFontSize,fontWeight:n.serviceFontWeight,letterSpacing:n.serviceLetterSpacing,textTransform:void 0,paddingX:n.servicePaddingX,paddingY:n.servicePaddingY,cornerRadius:n.serviceCornerRadius,lineWidth:n.serviceLineWidth},edge:{fontSize:n.edgeFontSize,fontWeight:n.edgeFontWeight,letterSpacing:n.edgeLetterSpacing,textTransform:void 0,lineWidth:n.edgeLineWidth,bendRadius:n.edgeBendRadius},group:{fontSize:n.groupFontSize,fontWeight:n.groupFontWeight,letterSpacing:n.groupLetterSpacing,fontFamily:n.groupFont,textTransform:void 0,paddingX:n.groupPaddingX,paddingY:n.groupPaddingY,cornerRadius:n.groupCornerRadius,lineWidth:n.groupLineWidth}}:void 0};const p=new Map(e.services.map(S=>[S.id,S]));const g=new Map(e.groups.map(S=>[S.id,S]));const y=new Map(e.junctions.map(S=>[S.id,S]));const w=(S,x)=>{const M=[];const b=[];const C=new Map;const P=new Map;for(const D of S.nodes){if(p.has(D.id)){const j=p.get(D.id);const W={x:D.x,y:D.y,width:D.width,height:D.height,id:j.id,label:j.label,labelBlock:o.get(j.id),...j.iconText!==void 0?{iconText:j.iconText,iconTextBlock:f.get(j.id)}:{},iconFallbackBlock:QM(j.icon,i.serviceIconSize??un.serviceIconSize),icon:j.icon,parentId:j.parentId};M.push(W);C.set(D.id,W)}else if(y.has(D.id)){const j=y.get(D.id);const W={x:D.x+(D.width-u)/2,y:D.y+(D.height-u)/2,width:u,height:u,id:j.id,parentId:j.parentId};b.push(W);P.set(D.id,W)}}const E=new Map(e.services.map((D,j)=>[D.id,j]));M.sort((D,j)=>{const W=Number(Boolean(D.parentId))-Number(Boolean(j.parentId));return W||(E.get(D.id)??0)-(E.get(j.id)??0)});uU(e,M,b,t.nodeSpacing??Bm);const k=new Map;const v=S.groups.map(D=>z_(D,g,k));for(const D of k.values()){D.labelBlock=s.get(D.id);D.iconFallbackBlock=QM(D.icon,i.iconSize??un.iconSize)}qh(v,M,b,e.alignments.length>0,d);let T;const A=fU(e,M,b,k,t.nodeSpacing??Bm,p,g,y,C,P,x?D=>{T=D}:void 0,d);if(A){qh(v,M,b,true,d)}if(e.alignments.length){const D=new Map([...M,...b].map(W=>[W.id,W]));const j=e.alignments.flatMap(W=>{const O=W.members.map(N=>{const G=D.get(N);return W.axis==="row"?G.y+G.height/2:G.x+G.width/2});return Math.max(...O)-Math.min(...O)<=Zt?[]:[`${W.axis} alignment lost for ${W.members.join(", ")}`]});if(j.length)throw new Qe([{strategy:"architecture-final-alignments",violations:j}])}const R=()=>e.edges.map(D=>hU(D,p,C,P,k,M,P,{start:D.hasArrowStart?nu("architecture-arrow-start",i.edgeLineWidth,"start"):0,end:D.hasArrowEnd?nu("architecture-arrow-end",i.edgeLineWidth,"end"):0},i.edgeBendRadius));let I=R();if(T)I=sy(e,M,I,R,T,D=>{const j=D.map(({points:W})=>({points:W,style:"solid",source:"",target:"_"}));return Jo(j)||Da(j)});I.forEach((D,j)=>{D.labelBlock=a[j]});gU(I,M,n);const L=e.title?Be(e.title,{display:"formatted",transform:n?.groupTextTransform,fontSize:Yh,fontWeight:Tk,safeFont:true}):void 0;const $=L?.text;const B=L?L.height-(L.lineHeight-L.fontSize):0;let F=S.width;let z=S.height;if(e.alignments.length>0||A){F=Math.max(80,...M.map(D=>D.x+D.width+40),...b.map(D=>D.x+D.width+40),...v.map(D=>D.x+D.width+40));z=Math.max(80,...M.map(D=>D.y+D.height+40),...b.map(D=>D.y+D.height+40),...v.map(D=>D.y+D.height+40))}if($){F=Math.max(F,L.width+dU*2);const D=$_-Yh/2;const j=Math.min(...M.map(N=>N.y),...b.map(N=>N.y),...[...k.values()].map(N=>N.y));const W=Math.max(0,D+B+11-j);const O=N=>{N.y+=W;N.children.forEach(O)};v.forEach(O);for(const N of M)N.y+=W;for(const N of b)N.y+=W;for(const N of I){for(const G of N.points)G.y+=W;if(N.labelPosition)N.labelPosition.y+=W}z=Math.max(z+W,D+B+20)}for(const D of I){for(const j of D.points){F=Math.max(F,j.x+40);z=Math.max(z,j.y+40)}if(D.labelPosition){F=Math.max(F,D.labelPosition.x+72);z=Math.max(z,D.labelPosition.y+28)}}for(const D of M){const j=D.x+i.servicePaddingX;D.labelPosition={x:D.iconTextBlock?j+D.iconTextBlock.width+(D.iconTextBlock.width?10:0):D.icon?j+(i.serviceIconSize??un.serviceIconSize)+Math.max(10,i.servicePaddingX*.7):j,y:D.y+D.height/2}}const _=[...k.values()].flatMap(D=>{const j=H_(D);return j?[j]:[]});const H=I.flatMap(D=>_.filter(j=>!wx(D.points,[j])).map(j=>`edge ${D.source.id}->${D.target.id}: crosses group ${j.id} header`));if(d!==void 0)for(const D of k.values()){const j=[...D.children,...M.filter(W=>W.parentId===D.id),...b.filter(W=>W.parentId===D.id)];for(const W of j)if(W.y<D.y+D.headerHeight+d)H.push(`group ${D.id}: child ${W.id} lacks reserved header clearance`)}if(H.length)throw new Qe([{strategy:"architecture-final-headers",violations:H}]);return{width:F,height:z,...$?{title:{text:$,x:F/2,y:$_+(B-Yh)/2,block:L}}:{},groups:v,services:M,junctions:b,edges:I,accessibilityTitle:e.accessibilityTitle,accessibilityDescription:e.accessibilityDescription}};return Qr(t,()=>w(A_(l,m),true),()=>w(L_(l,{...m,preserveSubgraphChildOrder:true}),false),true)}function uU(e,t,n,i){const r=new Map;for(const h of t)r.set(h.id,h);for(const h of n)r.set(h.id,h);const o=new Set(e.alignments.filter(h=>h.axis==="row").flatMap(h=>h.members));const s=[...e.alignments.filter(h=>h.axis==="row"),...e.alignments.filter(h=>h.axis==="column")];for(const h of s){const m=h.members.map(p=>r.get(p)).filter(p=>p!==void 0);if(m.length<2)continue;if(h.axis==="row"){const p=Math.min(...m.map(y=>y.y+y.height/2));let g=Math.min(...m.map(y=>y.x));for(const y of m){y.x=g;y.y=p-y.height/2;g+=y.width+i}}else{const p=Math.min(...m.map(w=>w.x+w.width/2));const g=m.every(w=>!o.has(w.id));let y=Math.min(...m.map(w=>w.y));for(const w of m){w.x=p-w.width/2;if(g){w.y=y;y+=w.height+i}}}}const a=new Map;const l=h=>{const m=a.get(h)??h;if(m===h){a.set(h,h);return h}const p=l(m);a.set(h,p);return p};const c=(h,m)=>{const p=l(h),g=l(m);if(p!==g)a.set(g,p)};for(const h of e.alignments){if(h.axis!=="column")continue;for(let m=1;m<h.members.length;m++)c(h.members[0],h.members[m])}const d=new Map;const u=h=>{const m=d.get(h)??h;if(m===h){d.set(h,h);return h}const p=u(m);d.set(h,p);return p};const f=(h,m)=>{const p=u(h),g=u(m);if(p!==g)d.set(g,p)};for(const h of e.alignments){if(h.axis!=="row")continue;for(let m=1;m<h.members.length;m++)f(h.members[0],h.members[m])}if(e.alignments.length){const h=new Map;for(const m of r.values()){const p=u(m.id),g=l(m.id);let y=h.get(p);if(!y){y=new Map;h.set(p,y)}const w=y.get(g);if(w!==void 0)throw new Qe([{strategy:"architecture-alignments",violations:[`incompatible row and column constraints tie distinct items ${w} and ${m.id}`]}]);y.set(g,m.id)}}if(e.alignments.length){for(const h of["row","column"]){const m=h==="row"?u:l;const p=new Map;for(const g of r.values()){const y=m(g.id),w=h==="row"?g.y+g.height/2:g.x+g.width/2;p.set(y,Math.min(p.get(y)??Infinity,w))}for(const g of r.values()){const y=p.get(m(g.id));const w=h==="row"?g.y+g.height/2:g.x+g.width/2;if(Math.abs(w-y)<=Zt)continue;if(h==="row")g.y=y-g.height/2;else g.x=y-g.width/2}}}if(e.alignments.length)for(const h of["row","column"]){const m=h==="row"?u:l,p=h==="row"?l:u;const g=h==="row"?"x":"y",y=h==="row"?"width":"height";const w=new Map,S=new Map;for(const E of r.values()){const k=p(E.id),v=m(E.id);const T=w.get(k)??[];T.push(E);w.set(k,T);const A=S.get(v)??[];A.push(E);S.set(v,A)}const x=new Map,M=new Map;for(const[E,k]of w){x.set(E,Math.min(...k.map(v=>v[g]+v[y]/2)));M.set(E,k.map(v=>v.id).sort(Bn)[0])}const b=[...w.keys()].sort((E,k)=>x.get(E)-x.get(k)||Bn(M.get(E),M.get(k)));const C=new Map(b.map((E,k)=>[E,k]));const P=new Map;for(const E of S.values()){E.sort((k,v)=>C.get(p(k.id))-C.get(p(v.id)));for(let k=1;k<E.length;k++){const v=E[k-1],T=E[k],A=p(T.id);const R=P.get(A)??[];R.push({before:v,after:T});P.set(A,R)}}for(const E of b){let k=0;for(const{before:v,after:T}of P.get(E)??[])k=Math.max(k,v[g]+v[y]+i-T[g]);if(k>0)for(const v of w.get(E))v[g]+=k}}for(let h=0;h<2;h++){for(const m of e.alignments){if(m.axis!=="row")continue;const p=m.members.map(M=>r.get(M)).filter(M=>M!==void 0);if(p.length<2)continue;const g=u(p[0].id);const y=Math.min(...p.map(M=>M.x));const w=Math.max(...p.map(M=>M.x+M.width));const S=Math.min(...p.map(M=>M.y));const x=Math.max(...p.map(M=>M.y+M.height));for(const M of r.values()){if(u(M.id)===g)continue;const b=M.x<w&&M.x+M.width>y&&M.y<x&&M.y+M.height>S;if(!b)continue;const C=u(M.id);const P=[...r.values()].filter(v=>u(v.id)===C);const E=Math.min(...P.map(v=>v.y));const k=x+i-E;for(const v of P)v.y+=k}}}}function fU(e,t,n,i,r,o,s,a,l,c,d,u){let f=false;const h=(A,R)=>`${A}:${R}`;const m=A=>{const R=A.indexOf(":");return{kind:A.slice(0,R),id:A.slice(R+1)}};const p=A=>{const R=[];let I=A;while(I){R.push(h("group",I));I=s.get(I)?.parentId}return R.reverse()};const g=(A,R="item")=>{const I=o.get(A);if(I){const $=p(I.parentId);return R==="group"?$:[...$,h("service",A)]}const L=a.get(A);if(L)return[...p(L.parentId),h("junction",A)];return null};const y=[];for(const A of e.edges){const R=g(A.source.id,A.source.boundary);const I=g(A.target.id,A.target.boundary);if(!R||!I)continue;let L=0;while(L<R.length&&L<I.length&&R[L]===I[L])L++;if(L>=R.length||L>=I.length)continue;const $=L===0?void 0:m(R[L-1]).id;const B=R[L];const F=I[L];const z=(_,H,D)=>{const j=D==="L"||D==="R"?"x":"y";const W=D==="R"||D==="B";y.push({axis:j,parentId:$,before:W?_:H,after:W?H:_,depth:L})};z(B,F,A.source.side);z(F,B,A.target.side)}const w=A=>A?s.get(A)?.children??[]:e.rootChildren;const S=A=>{const{kind:R,id:I}=m(A);if(R==="group")return i.get(I);if(R==="service")return l.get(I);return c.get(I)};const x=(A,R,I)=>{if(Math.abs(I)<=Zt)return;const{kind:L,id:$}=m(A);if(L!=="group"){const F=L==="service"?l.get($):c.get($);if(F)F[R]+=I;return}const B=F=>{const z=i.get(F);if(z)z[R]+=I;for(const _ of s.get(F)?.children??[]){if(_.kind==="group")B(_.id);else x(h(_.kind,_.id),R,I)}};B($)};const M=[...i.values()].filter(A=>!A.parentId);const b=A=>w(A).map(R=>h(R.kind,R.id)).filter(R=>S(R)!==void 0);const C=(A,R,I)=>{const L=new Map(A.map(z=>[z,z]));const $=z=>{const _=L.get(z)??z;if(_===z)return z;const H=$(_);L.set(z,H);return H};for(const z of e.alignments){if(z.axis!==I)continue;const _=z.members.map(H=>{const D=g(H);if(!D)return void 0;if(!R)return D[0];const j=D.indexOf(h("group",R));return j>=0?D[j+1]:void 0}).filter(H=>H!==void 0&&L.has(H));for(const H of _.slice(1))L.set($(H),$(_[0]))}const B=new Map;for(const z of A){const _=$(z);const H=B.get(_)??[];H.push(z);B.set(_,H)}const F=z=>{const _=B.get(z).map(O=>S(O));const H=Math.min(..._.map(O=>O.x));const D=Math.min(..._.map(O=>O.y));const j=Math.max(..._.map(O=>O.x+O.width));const W=Math.max(..._.map(O=>O.y+O.height));return{x:H,y:D,width:j-H,height:W-D}};return{find:$,members:B,bounds:F}};const P=new Map;for(const A of y){const R=`${A.depth}:${A.parentId??""}:${A.axis}`;const I=P.get(R)??[];I.push(A);P.set(R,I)}const E=[...P.values()].sort((A,R)=>R[0].depth-A[0].depth||Bn(A[0].parentId??"",R[0].parentId??"")||Bn(A[0].axis,R[0].axis));for(const A of E){const{axis:R,parentId:I}=A[0];const L=b(I);if(L.length<2)continue;const{find:$,members:B,bounds:F}=C(L,I,R==="x"?"column":"row");const z=new Map;let _=false;for(const G of A){const Y=$(G.before);const q=$(G.after);if(Y===q){_=true;break}const V=z.get(Y)??new Set;V.add(q);z.set(Y,V)}if(_)continue;const H=[...B.keys()];const D=(G,Y)=>{const q=F(G),V=F(Y);return R==="x"?q.x+q.width+r<=V.x+Zt:q.y+q.height+r<=V.y+Zt};if([...z].every(([G,Y])=>[...Y].every(q=>D(G,q))))continue;const j=new Map(H.map(G=>[G,0]));for(const G of z.values())for(const Y of G)j.set(Y,(j.get(Y)??0)+1);const W=[];while(W.length<H.length){const G=H.filter(q=>!W.includes(q)&&j.get(q)===0).sort((q,V)=>{const ne=F(q),X=F(V);const U=R==="x"?ne.x-X.x:ne.y-X.y;return U||Bn(q,V)});if(G.length===0)break;const Y=G[0];W.push(Y);for(const q of z.get(Y)??[])j.set(q,j.get(q)-1)}if(W.length!==H.length)continue;const O=H.map(F);let N=Math.min(...O.map(G=>R==="x"?G.x:G.y));for(const G of W){const Y=F(G);const q=R==="x"?Y.x:Y.y;const V=N-q;if(Math.abs(V)>Zt)f=true;for(const ne of B.get(G))x(ne,R,V);N+=(R==="x"?Y.width:Y.height)+r}qh(M,t,n,true,u)}let k=false;for(const A of e.alignments){const R=A.axis==="row"?"y":"x";const I=R==="y"?"height":"width";const L=[...new Set(A.members)].flatMap(B=>{const F=g(B);const z=l.get(B)??c.get(B);return F&&z?[{path:F,item:z}]:[]});const $=(B,F)=>{if(B.length<2)return;const z=Math.min(...B.map(D=>D.path.length));while(F<z&&B.every(D=>D.path[F]===B[0].path[F]))F++;if(F>=z)return;const _=new Map;for(const D of B){const j=D.path[F];const W=_.get(j)??[];W.push(D);_.set(j,W)}for(const D of _.values())$(D,F+1);const H=Math.max(...B.map(D=>D.item[R]+D.item[I]/2));for(const[D,j]of _){const W=H-(j[0].item[R]+j[0].item[I]/2);if(W>Zt){x(D,R,W);k=f=true}}};$(L,0)}if(k)qh(M,t,n,true,u);const v=[...e.groups.map(A=>({parentId:A.id,depth:p(A.id).length})),{parentId:void 0,depth:0}].sort((A,R)=>R.depth-A.depth||Bn(A.parentId??"",R.parentId??""));const T=(A,R)=>A.x<R.x+R.width-Zt&&R.x<A.x+A.width-Zt&&A.y<R.y+R.height-Zt&&R.y<A.y+A.height-Zt;for(const A of v){const R=b(A.parentId);if(R.length<2)continue;const{members:I,bounds:L}=C(R,A.parentId,"row");const{find:$,members:B}=C(R,A.parentId,"column");for(let _=0;_<R.length;_++){let H=false;for(const D of I.values()){const j=[...D].sort((N,G)=>S(N).x-S(G).x||Bn(N,G));let W=-Infinity;const O=new Set;for(const N of j){const G=$(N);if(O.has(G))continue;O.add(G);const Y=S(N);if(Y.x<W-Zt){const q=W-Y.x;for(const V of B.get(G))x(V,"x",q);H=f=true}W=Y.x+Y.width+r}}if(!H)break}const F=[...I.keys()].sort((_,H)=>{const D=L(_),j=L(H);return D.y-j.y||D.x-j.x||Bn(_,H)});const z=[];for(const _ of F){for(let H=0;H<=z.length;H++){const D=L(_);const j=z.map(L).filter(N=>T(D,N));if(j.length===0)break;const W=Math.max(...j.map(N=>N.y+N.height+r));const O=W-D.y;for(const N of I.get(_))x(N,"y",O);f=true}z.push(_)}qh(M,t,n,true,u)}d?.(()=>y.every(({axis:A,before:R,after:I})=>{const L=S(R),$=S(I);return L[A]+(A==="x"?L.width:L.height)+r<=$[A]+Zt})&&(u===void 0||[...i.values()].every(A=>w(A.id).every(R=>{const I=S(h(R.kind,R.id));return I===void 0||I.y>=A.y+A.headerHeight+u})))&&v.every(A=>{const R=w(A.parentId).map(I=>S(h(I.kind,I.id))).filter(I=>I!==void 0);return R.every((I,L)=>R.slice(L+1).every($=>!T(I,$)))}));return f}function z_(e,t,n){const i=t.get(e.id);const r={id:e.id,label:i?.label??e.id,icon:i?.icon,parentId:i?.parentId,x:e.x,y:e.y,width:e.width,height:e.height,headerHeight:e.headerHeight,children:e.children.map(o=>z_(o,t,n))};n.set(r.id,r);return r}function qh(e,t,n,i,r){for(const o of e)G_(o,t,n,i,r)}function G_(e,t,n,i,r){const o=[];for(const u of e.children)o.push(G_(u,t,n,i,r));for(const u of t){if(u.parentId===e.id)o.push(u)}for(const u of n){if(u.parentId===e.id)o.push(u)}if(o.length===0)return e;const s=Math.min(e.x,...o.map(u=>u.x-Rr));const a=r===void 0?Rr:e.headerHeight+r;const l=Math.min(e.y,...o.map(u=>u.y-a));const c=Math.max(e.x+e.width,...o.map(u=>u.x+u.width+Rr));const d=i?Math.max(e.y+48,...o.map(u=>u.y+u.height+Rr)):Math.max(e.y+e.height,...o.map(u=>u.y+u.height+Rr));e.x=s;e.y=l;e.width=c-s;e.height=d-l;return e}function hU(e,t,n,i,r,o,s,a,l){const c=D_(e.source,t,n,i,r,a.start?a.start+l:0);const d=D_(e.target,t,n,i,r,a.end?a.end+l:0);const u=mU(e,t,r,o,s);for(const w of[e.source,e.target]){const S=w.boundary==="group"?r.get(t.get(w.id).parentId):void 0;const x=S??n.get(w.id)??i.get(w.id);u.push({...x,id:S?.id??w.id,kind:S?"group":n.has(w.id)?"service":"junction"})}for(const[w,S]of[[c,e.source.side],[d,e.target.side]]){const x=S==="L"||S==="R";const M=S==="R"||S==="B";let b=Math.abs(x?w.exit.x-w.anchor.x:w.exit.y-w.anchor.y);for(const C of u){const P=x?w.anchor.y:w.anchor.x;const E=x?C.y:C.x;const k=x?C.height:C.width;if(P<=E+Zt||P>=E+k-Zt)continue;const v=x?C.x+(M?0:C.width):C.y+(M?0:C.height);const T=(v-(x?w.anchor.x:w.anchor.y))*(M?1:-1);if(T>Zt)b=Math.min(b,T)}w.exit=Mx(w.anchor,S,b)}const f=vk([c.exit,...SU(c.exit,d.exit,e.source.side,e.target.side),d.exit]);const h=wx(f,u)?f:pU(c.exit,d.exit,u)??f;let m=vk([c.anchor,...h,d.anchor]);const p=La(m,a);if(p&&p!==m&&wx(p,u))m=p;const g=__(c.anchor,e.source.side,d.anchor);const y=__(d.anchor,e.target.side,c.anchor);return{source:e.source,target:e.target,label:e.label,hasArrowStart:e.hasArrowStart,hasArrowEnd:e.hasArrowEnd,points:m,labelPosition:e.label?Lk(m):void 0,placement:g&&y?"satisfied":"conflicted",sourceFacesTarget:g,targetFacesSource:y,obstacleFree:wx(m,u)}}var bx=6;var Zt=.001;function H_(e){const t=e.headerHeight;if(t===void 0||!Number.isFinite(t)||t<0){throw new Qe([{strategy:"architecture-final-headers",violations:[`group ${e.id}: missing or invalid measured header height`]}])}return t>0?{id:e.id,kind:"group-header",x:e.x,y:e.y,width:e.width,height:t}:void 0}function mU(e,t,n,i,r){const o=new Set;const s=c=>{let d=c;while(d){if(o.has(d))break;o.add(d);d=n.get(d)?.parentId}};s(t.get(e.source.id)?.parentId??r.get(e.source.id)?.parentId);s(t.get(e.target.id)?.parentId??r.get(e.target.id)?.parentId);const a=(c,d,u)=>({id:c,kind:d,x:u.x-bx,y:u.y-bx,width:u.width+bx*2,height:u.height+bx*2});const l=[];for(const c of i){if(c.id===e.source.id||c.id===e.target.id)continue;l.push(a(c.id,"service",c))}for(const c of r.values()){if(c.id===e.source.id||c.id===e.target.id)continue;l.push(a(c.id,"junction",c))}for(const c of n.values()){if(o.has(c.id)){const d=H_(c);if(d)l.push(d)}else l.push(a(c.id,"group",c))}return l}function __(e,t,n){switch(t){case"L":return n.x<e.x-Zt;case"R":return n.x>e.x+Zt;case"T":return n.y<e.y-Zt;case"B":return n.y>e.y+Zt}}function wx(e,t){for(let n=1;n<e.length;n++){if(t.some(i=>j_(e[n-1],e[n],i)))return false}return true}function j_(e,t,n){if(n.kind==="group-header"){let i=0,r=1;for(const[o,s,a,l]of[[e.x,t.x-e.x,n.x,n.x+n.width],[e.y,t.y-e.y,n.y,n.y+n.height]]){if(s===0){if(o<=a||o>=l)return false;continue}const c=(a-o)/s,d=(l-o)/s;i=Math.max(i,Math.min(c,d));r=Math.min(r,Math.max(c,d));if(i>=r)return false}return i<r}if(Math.abs(e.y-t.y)<=Zt){return e.y>n.y+Zt&&e.y<n.y+n.height-Zt&&Math.min(e.x,t.x)<n.x+n.width-Zt&&Math.max(e.x,t.x)>n.x+Zt}if(Math.abs(e.x-t.x)<=Zt){return e.x>n.x+Zt&&e.x<n.x+n.width-Zt&&Math.min(e.y,t.y)<n.y+n.height-Zt&&Math.max(e.y,t.y)>n.y+Zt}return true}var Rk=class{entries=[];push(t){this.entries.push(t);let n=this.entries.length-1;while(n>0){const i=Math.floor((n-1)/2);if(!this.before(t,this.entries[i]))break;this.entries[n]=this.entries[i];n=i}this.entries[n]=t}pop(){const t=this.entries[0];const n=this.entries.pop();if(!t||!n||this.entries.length===0)return t;let i=0;this.entries[0]=n;while(true){const r=i*2+1;const o=r+1;if(r>=this.entries.length)break;let s=r;if(o<this.entries.length&&this.before(this.entries[o],this.entries[r]))s=o;if(!this.before(this.entries[s],this.entries[i]))break;const a=this.entries[i];this.entries[i]=this.entries[s];this.entries[s]=a;i=s}return t}before(t,n){return t.cost<n.cost||t.cost===n.cost&&t.state<n.state}};function pU(e,t,n){const i=[...new Set([e.x,t.x,...n.flatMap(x=>[x.x,x.x+x.width])])].sort((x,M)=>x-M);const r=[...new Set([e.y,t.y,...n.flatMap(x=>[x.y,x.y+x.height])])].sort((x,M)=>x-M);const o=[];const s=new Map;const a=(x,M)=>`${x}\0${M}`;const l=(x,M)=>n.some(b=>{const C=b.kind==="group-header"?0:Zt;return x>b.x+C&&x<b.x+b.width-C&&M>b.y+C&&M<b.y+b.height-C});for(const x of r){for(const M of i){if(l(M,x)&&!(M===e.x&&x===e.y)&&!(M===t.x&&x===t.y))continue;s.set(a(M,x),o.length);o.push({x:M,y:x})}}const c=s.get(a(e.x,e.y));const d=s.get(a(t.x,t.y));if(c===void 0||d===void 0)return null;const u=o.map(()=>[]);const f=(x,M)=>{for(let b=1;b<x.length;b++){const C=x[b-1];const P=x[b];const E=o[C];const k=o[P];if(n.some(T=>j_(E,k,T)))continue;const v=Math.abs(E.x-k.x)+Math.abs(E.y-k.y);u[C].push({point:P,direction:M,length:v});u[P].push({point:C,direction:M,length:v})}};for(const x of r){const M=o.map((b,C)=>({point:b,index:C})).filter(b=>b.point.y===x).sort((b,C)=>b.point.x-C.point.x).map(b=>b.index);f(M,1)}for(const x of i){const M=o.map((b,C)=>({point:b,index:C})).filter(b=>b.point.x===x).sort((b,C)=>b.point.y-C.point.y).map(b=>b.index);f(M,2)}const h=o.length*3;const m=new Array(h).fill(Infinity);const p=new Array(h).fill(-1);const g=c*3;m[g]=0;const y=new Rk;y.push({state:g,cost:0});let w=-1;while(true){const x=y.pop();if(!x)break;if(x.cost!==m[x.state])continue;const M=Math.floor(x.state/3);const b=x.state%3;if(M===d){w=x.state;break}for(const C of u[M]){const P=C.point*3+C.direction;const E=b!==0&&b!==C.direction?8:0;const k=x.cost+C.length+E;if(k>=m[P])continue;m[P]=k;p[P]=x.state;y.push({state:P,cost:k})}}if(w<0)return null;const S=[];for(let x=w;x>=0;x=p[x]){S.push(o[Math.floor(x/3)]);if(x===g)break}return vk(S.reverse())}function gU(e,t,n){const i=n?.edgeFontSize??11;const r=n?.edgeFontWeight??400;const o=6;const s=(u,f,h)=>{const m=u.labelBlock??Be(u.label,{display:"formatted",fontSize:i,fontWeight:r,letterSpacing:n?.edgeLetterSpacing});const p=m.width+o*2;const g=m.height+o*2;return{x0:f-p/2,y0:h-g/2,x1:f+p/2,y1:h+g/2}};const a=(u,f)=>Math.min(u.x1,f.x1)-Math.max(u.x0,f.x0)>.5&&Math.min(u.y1,f.y1)-Math.max(u.y0,f.y0)>.5;const l=t.map(u=>({x0:u.x,y0:u.y,x1:u.x+u.width,y1:u.y+u.height}));const c=e.filter(u=>u.label&&u.labelPosition&&u.points.length>=2);const d=[];for(const u of c){const f=s(u,u.labelPosition.x,u.labelPosition.y);const h=x=>d.some(M=>a(x,M))||l.some(M=>a(x,M));if(!h(f)){d.push(f);continue}const m=u.points;const p=[];let g=0;for(let x=1;x<m.length;x++){const M=Math.hypot(m[x].x-m[x-1].x,m[x].y-m[x-1].y);p.push(M);g+=M}const y=x=>{let M=x;for(let b=0;b<p.length;b++){if(M<=p[b]||b===p.length-1){const C=p[b]===0?0:Math.max(0,Math.min(1,M/p[b]));return{x:m[b].x+(m[b+1].x-m[b].x)*C,y:m[b].y+(m[b+1].y-m[b].y)*C}}M-=p[b]}return m[m.length-1]};const w=[.5,.4,.6,.3,.7,.25,.75,.2,.8,.15,.85];let S=f;for(const x of w){const M=y(g*x);const b=s(u,M.x,M.y);if(!h(b)){u.labelPosition={x:M.x,y:M.y};S=b;break}}d.push(S)}}function D_(e,t,n,i,r,o=0){if(e.boundary==="group"){const c=t.get(e.id);const d=n.get(e.id);const u=r.get(c.parentId);const f=bU(u,d,e.side);return{anchor:f,exit:Mx(f,e.side,Math.max(Ek,o))}}const s=n.get(e.id);if(s){const c=yU(s,e.side);return{anchor:c,exit:Mx(c,e.side,Math.max(Ek,o))}}const a=i.get(e.id);if(!a){throw new Error(`Unknown architecture endpoint "${e.id}"`)}const l=xU(a,e.side);return{anchor:l,exit:Mx(l,e.side,Math.max(Ek*.75,o))}}function yU(e,t){switch(t){case"L":return{x:e.x,y:e.y+e.height/2};case"R":return{x:e.x+e.width,y:e.y+e.height/2};case"T":return{x:e.x+e.width/2,y:e.y};case"B":return{x:e.x+e.width/2,y:e.y+e.height}}}function xU(e,t){const n=e.x+e.width/2;const i=e.y+e.height/2;const r=Math.min(e.width,e.height)/2;switch(t){case"L":return{x:n-r,y:i};case"R":return{x:n+r,y:i};case"T":return{x:n,y:i-r};case"B":return{x:n,y:i+r}}}function bU(e,t,n){const i=t.x+t.width/2;const r=t.y+t.height/2;switch(n){case"L":return{x:e.x,y:Sx(r,e.y+Rr,e.y+e.height-Rr)};case"R":return{x:e.x+e.width,y:Sx(r,e.y+Rr,e.y+e.height-Rr)};case"T":return{x:Sx(i,e.x+Rr,e.x+e.width-Rr),y:e.y};case"B":return{x:Sx(i,e.x+Rr,e.x+e.width-Rr),y:e.y+e.height}}}function SU(e,t,n,i){if(e.x===t.x||e.y===t.y)return[];const r=O_(n);const o=O_(i);if(r!==o){return r==="horizontal"?[{x:t.x,y:e.y}]:[{x:e.x,y:t.y}]}if(r==="horizontal"){const a=(e.x+t.x)/2;return[{x:a,y:e.y},{x:a,y:t.y}]}const s=(e.y+t.y)/2;return[{x:e.x,y:s},{x:t.x,y:s}]}function O_(e){return e==="L"||e==="R"?"horizontal":"vertical"}function Mx(e,t,n){switch(t){case"L":return{x:e.x-n,y:e.y};case"R":return{x:e.x+n,y:e.y};case"T":return{x:e.x,y:e.y-n};case"B":return{x:e.x,y:e.y+n}}}function vk(e){const t=[];let n;for(const i of e){if(n&&n.x===i.x&&n.y===i.y)continue;n=i;while(t.length>1){const r=t[t.length-2],o=t[t.length-1];if(r.x===o.x&&o.x===i.x||r.y===o.y&&o.y===i.y)t.pop();else break}t.push(i)}return t}function Lk(e){if(e.length===0)return{x:0,y:0};if(e.length===1)return e[0];let t=0;for(let i=1;i<e.length;i++){t+=B_(e[i-1],e[i])}let n=t/2;for(let i=1;i<e.length;i++){const r=e[i-1];const o=e[i];const s=B_(r,o);if(n<=s){const a=s===0?0:n/s;return{x:r.x+(o.x-r.x)*a,y:r.y+(o.y-r.y)*a}}n-=s}return e[e.length-1]}function B_(e,t){return Math.abs(t.x-e.x)+Math.abs(t.y-e.y)}function Sx(e,t,n){return Math.max(t,Math.min(n,e))}function wU(e,t){const{positioned:n,colors:i,resolved:r}=t;const o=r.renderOptions;const s=i.font??"Inter";const a=o.transparent??false;const l={...un,...r.familyAppearance?.visual??o.architecture?.visual};const c=[];const d=[l.groupSurface?`--arch-group-fill:${l.groupSurface}`:"",l.groupHeaderSurface?`--arch-group-band:${l.groupHeaderSurface}`:"",l.groupBorder?`--arch-group-stroke:${l.groupBorder}`:"",l.groupText?`--arch-group-label:${l.groupText}`:"",l.serviceSurface?`--arch-service-fill:${l.serviceSurface}`:"",l.serviceBorder?`--arch-service-stroke:${l.serviceBorder}`:"",l.serviceText?`--arch-service-label:${l.serviceText}`:"",l.edgeStroke?`--arch-edge-stroke:${l.edgeStroke}`:"",l.edgeText?`--arch-edge-label:${l.edgeText}`:""].filter(Boolean).join(";");const u=MU(l,i);const f=n.accessibilityTitle??n.title?.text;const h=Boolean(f);const m=Boolean(n.accessibilityDescription);const p=`arch-${pi(n.width,n.height,n.title?.text??"",n.services.map(b=>b.id).join(","),n.groups.map(b=>b.id).join(","))}`;const g=`${p}-title`;const y=`${p}-desc`;const w={};if(h||m){w["role"]="img";w["aria-roledescription"]="architecture"}if(h)w["aria-labelledby"]=g;if(m)w["aria-describedby"]=y;const S=[];S.push(Ot(n.width,n.height,i,a,{style:d,attrs:w}));if(h)S.push(`<title id="${g}">${At(f)}</title>`);if(m)S.push(`<desc id="${y}">${At(n.accessibilityDescription)}</desc>`);S.push(Dt(s,false,void 0,i.embedFontImport));c.push(e.documentOpen({id:"prelude",width:n.width,height:n.height,colors:i,transparent:a,font:s,hasMonoFont:false},S.join("\n")));c.push(e.definitions({id:"defs",markerResources:tu},["<defs>",mi(tu),"</defs>"].join("\n")));if(n.title){c.push(e.text({id:"title",role:"title",text:n.title.text,x:n.title.x,y:n.title.y,fontSize:Yh,block:n.title.block,anchor:"middle",fontWeight:Tk,paint:{fill:"var(--arch-service-label, var(--_text))"},attributes:{className:"architecture-title"}}))}for(const b of n.groups){c.push(Y_(e,b,l,u))}const x=new Map;for(const b of n.edges){const C=`${b.source.id}->${b.target.id}`;const P=x.get(C)??0;x.set(C,P+1);c.push(PU(e,b,l,`edge:${C}#${P}`))}const M=new Map;for(const b of n.edges){if(!b.label)continue;const C=`${b.source.id}->${b.target.id}`;const P=M.get(C)??0;M.set(C,P+1);for(const E of EU(e,b,l,`edge-label:${C}#${P}`)){c.push(E)}}for(const b of n.junctions){c.push(CU(e,b,l))}for(const b of n.services){c.push(kU(e,b,l,u))}c.push(e.documentClose());return{family:"architecture",width:n.width,height:n.height,colors:i,transparent:a,parts:c}}function MU(e,t){const n=_n("var(--bg)",t);const i=_n("var(--_node-fill)",t);const r=n?_n(e.groupSurface??n,t):void 0;const o=_n(e.edgeStroke??"var(--_arrow)",t);const s=e.groupHeaderSurface??(r&&o?tr(o,r,5):void 0);const a=e.serviceSurface??(n&&i?tr(i,n,92):void 0);return{group:`var(--arch-group-label, ${s?xi("var(--_text-sec)",s,t):"var(--_text-sec)"})`,service:`var(--arch-service-label, ${a?xi("var(--_text)",a,t):"var(--_text)"})`}}function Y_(e,t,n,i){const r=[];const o=`<g class="architecture-group" data-id="${Ye(t.id)}" data-label="${hn(t.label)}">`;r.push({indent:2,node:e.shape({id:`group-frame:${t.id}`,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:"var(--arch-group-fill, color-mix(in srgb, var(--_node-fill) 82%, var(--bg)))",stroke:"none"},attributes:{className:"architecture-group-frame"}})});const s=Tr(t.x,t.y,t.width,t.headerHeight??n.groupHeaderHeight,n.groupCornerRadius);r.push({indent:2,node:e.shape({id:`group-band:${t.id}`,role:"group-header",geometry:{kind:"path",d:s},paint:{fill:"var(--arch-group-band, color-mix(in srgb, var(--arch-edge-stroke, var(--_arrow)) 5%, var(--arch-group-fill, var(--bg))))",stroke:"none"},attributes:{className:"architecture-group-band"}})});r.push({indent:2,node:e.shape({id:`group-outline:${t.id}`,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:"none",stroke:"var(--arch-group-stroke, var(--_node-stroke))",strokeWidth:String(n.groupLineWidth)},attributes:{className:"architecture-group-outline"}})});if(t.icon){r.push({indent:0,node:q_(e,t.x+10,t.y+6,n.iconSize,t.icon,true,`icon:${t.id}`,{id:t.id,role:"group"},t.iconFallbackBlock)})}const a=t.labelBlock??Be(t.label,{display:"formatted",transform:n.groupTextTransform,fontSize:n.groupFontSize,fontWeight:n.groupFontWeight,letterSpacing:n.groupLetterSpacing,fontFamily:n.groupFont});const l=a.text;const c=t.x+(t.icon?Wm:n.groupLabelPaddingX);const d=t.y+(t.headerHeight??n.groupHeaderHeight)/2;r.push({indent:2,node:e.text({id:`group-label:${t.id}`,role:"label",text:l,x:c,y:d,fontSize:n.groupFontSize,block:a,anchor:"start",paint:{fill:i.group},attributes:{className:"architecture-group-label"}})});for(const u of t.children){r.push({indent:0,node:Y_(e,u,n,i)})}return e.group({id:`group:${t.id}`,role:"group",open:o,close:"</g>",children:r})}function kU(e,t,n,i){const r=[];const o=Boolean(t.icon);const s=t.iconText===void 0?void 0:t.iconTextBlock??Be(t.iconText,{display:"literal",fontSize:n.serviceFontSize,fontWeight:700});const a=t.x+n.servicePaddingX;const l=t.y+t.height/2-n.serviceIconSize/2;const c=t.labelPosition?.x??(s?a+s.width+(s.width?10:0):o?a+n.serviceIconSize+Math.max(10,n.servicePaddingX*.7):t.x+n.servicePaddingX);const d=`<g class="architecture-service" data-id="${Ye(t.id)}" data-label="${hn(t.label)}">`;r.push({indent:2,node:e.shape({id:`service-card:${t.id}`,role:"service",geometry:{kind:"rect",x:t.x,y:t.y,width:t.width,height:t.height,rx:n.serviceCornerRadius,ry:n.serviceCornerRadius},paint:{fill:"var(--arch-service-fill, color-mix(in srgb, var(--_node-fill) 92%, var(--bg)))",stroke:"none"},attributes:{className:"architecture-service-card"}})});r.push({indent:2,node:e.shape({id:`service-outline:${t.id}`,role:"service",geometry:{kind:"rect",x:t.x,y:t.y,width:t.width,height:t.height,rx:n.serviceCornerRadius,ry:n.serviceCornerRadius},paint:{fill:"none",stroke:"var(--arch-service-stroke, var(--_node-stroke))",strokeWidth:String(n.serviceLineWidth)},attributes:{className:"architecture-service-outline"}})});if(t.icon){r.push({indent:0,node:q_(e,a,l,n.serviceIconSize,t.icon,false,`icon:${t.id}`,{id:t.id,role:"service"},t.iconFallbackBlock)})}if(s){const m=s;r.push({indent:2,node:e.text({id:`icon-text:${t.id}`,role:"icon",text:m.text,block:m,x:a,y:t.y+t.height/2,anchor:"start",fontSize:n.serviceFontSize,fontWeight:700,paint:{fill:i.service},attributes:{className:"architecture-icon-text"}})})}const u=t.labelPosition?.y??t.y+t.height/2;const f=t.labelBlock??Be(t.label,{display:"formatted",transform:n.serviceTextTransform,fontSize:n.serviceFontSize,fontWeight:n.serviceFontWeight,letterSpacing:n.serviceLetterSpacing});const h=f.text;r.push({indent:2,node:e.text({id:`service-label:${t.id}`,role:"label",text:h,x:c,y:u,fontSize:n.serviceFontSize,block:f,anchor:"start",paint:{fill:i.service},attributes:{className:"architecture-service-label"}})});return e.group({id:`service:${t.id}`,role:"service",open:d,close:"</g>",children:r})}function CU(e,t,n){const i=t.x+t.width/2;const r=t.y+t.height/2;const o=e.shape({id:`junction-ring:${t.id}`,role:"junction",geometry:{kind:"circle",cx:i,cy:r,r:t.width/2},paint:{fill:"var(--bg)",stroke:"var(--arch-edge-stroke, var(--_arrow))",strokeWidth:"1.25"},attributes:{className:"architecture-junction-ring"}});const s=e.shape({id:`junction-core:${t.id}`,role:"junction",geometry:{kind:"circle",cx:i,cy:r,r:n.junctionInnerRadius},paint:{fill:"color-mix(in srgb, var(--arch-edge-stroke, var(--_arrow)) 24%, var(--bg))",stroke:"var(--arch-edge-stroke, var(--_arrow))",strokeWidth:"0.75"},attributes:{className:"architecture-junction-core"}});return e.group({id:`junction:${t.id}`,role:"junction",open:`<g class="architecture-junction" data-id="${Ye(t.id)}">`,close:"</g>",children:[{indent:2,node:o},{indent:2,node:s}]})}function PU(e,t,n,i){const r=t.hasArrowStart?tu[1]:void 0;const o=t.hasArrowEnd?tu[0]:void 0;const s={className:"architecture-edge",data:{"from-side":t.source.side,"to-side":t.target.side,"from-boundary":t.source.boundary,"to-boundary":t.target.boundary,...t.label?{label:jr(t.label)}:{}}};const a={stroke:"var(--arch-edge-stroke, var(--_line))",strokeWidth:String(n.edgeLineWidth),strokeLinejoin:"round"};const l={endpoints:{from:t.source.id,to:t.target.id},relationship:{kind:"architecture-edge"},route:{ownership:"layout",bendRadius:n.edgeBendRadius,labelAnchors:t.labelPosition?[t.labelPosition]:[]},labels:t.label?[{text:t.label,...t.labelPosition?{anchor:t.labelPosition}:{}}]:[],attributes:s};if(n.edgeBendRadius>0&&t.points.length>2){const c=qn(t.points,n.edgeBendRadius,{terminalClearance:{start:nu(r?.id,n.edgeLineWidth,"start"),end:nu(o?.id,n.edgeLineWidth,"end")},metric:"manhattan"});return e.connector({id:i,role:"edge",geometry:c.geometry,lineStyle:"solid",paint:a,markers:{...r?{start:r}:{},mid:[],...o?{end:o}:{}},...l,route:{...l.route,contours:c.contours}})}return e.connector({id:i,role:"edge",geometry:{kind:"polyline",points:t.points},lineStyle:"solid",paint:a,markers:{...r?{start:r}:{},mid:[],...o?{end:o}:{}},...l})}function EU(e,t,n,i){const r=t.labelBlock??Be(t.label,{display:"formatted",transform:n.edgeTextTransform,fontSize:n.edgeFontSize,fontWeight:n.edgeFontWeight,letterSpacing:n.edgeLetterSpacing});const o=r.text;const s=t.labelPosition??Lk(t.points);const a=7;const l=r.width+a*2;const c=r.height+a*2;return[e.shape({id:`${i}:bg`,role:"chrome",geometry:{kind:"rect",x:s.x-l/2,y:s.y-c/2,width:l,height:c,rx:0,ry:0},paint:{fill:"color-mix(in srgb, var(--bg) 90%, var(--_group-hdr))",stroke:"color-mix(in srgb, var(--arch-edge-stroke, var(--_line)) 18%, var(--bg))",strokeWidth:"0.75"},attributes:{className:"architecture-edge-label-bg"}}),e.text({id:i,role:"label",text:o,x:s.x,y:s.y,fontSize:n.edgeFontSize,block:r,anchor:"middle",paint:{fill:"var(--arch-edge-label, var(--_text-muted))"},attributes:{className:"architecture-edge-label-text"}})]}function q_(e,t,n,i,r,o,s,a,l){const c=r.trim().toLowerCase();const d=!c.includes(":")&&!c.includes("/")&&["cloud","database","disk","internet","server"].includes(c);const u=d?null:ya(r);const f=u?` data-icon-source="${u.source}" data-icon-license="${u.license}"`:"";const h="var(--arch-edge-stroke, var(--_arrow))";const m={fill:"none",stroke:h,strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"};const p=[];const g=(P,E="architecture-icon-mark",k=m,v)=>{p.push(e.shape({id:xn(s,"part",p.length),role:"icon",owner:a,geometry:P,paint:k,...v?{transform:v}:{},attributes:{className:E}}))};const y=P=>g({kind:"path",d:P});const w=(P,E,k)=>g({kind:"circle",cx:P,cy:E,r:k});const S=(P,E,k,v)=>g({kind:"ellipse",cx:P,cy:E,rx:k,ry:v});const x=lx(r),M=t+i/2,b=n+i/2,C=o?i*.92:i;if(u){const P=(i-C)/2,E=C/24;g({kind:"path",d:u.path},"architecture-icon-glyph",{fill:h},{kind:"matrix",a:E,b:0,c:0,d:E,e:t+P,f:n+P})}else switch(x){case"cloud":w(M-C*.18,b+C*.02,C*.16);w(M+C*.02,b-C*.08,C*.2);w(M+C*.2,b+C*.02,C*.15);y(`M ${M-C*.34} ${b+C*.16} H ${M+C*.33}`);break;case"database":S(M,b-C*.16,C*.24,C*.1);y(`M ${M-C*.24} ${b-C*.16} V ${b+C*.2}`);y(`M ${M+C*.24} ${b-C*.16} V ${b+C*.2}`);S(M,b+C*.02,C*.24,C*.1);S(M,b+C*.2,C*.24,C*.1);break;case"disk":w(M,b,C*.26);w(M,b,C*.09);break;case"internet":w(M,b,C*.26);y(`M ${M-C*.26} ${b} H ${M+C*.26}`);y(`M ${M} ${b-C*.26} V ${b+C*.26}`);y(`M ${M-C*.14} ${b-C*.22} Q ${M} ${b} ${M-C*.14} ${b+C*.22}`);y(`M ${M+C*.14} ${b-C*.22} Q ${M} ${b} ${M+C*.14} ${b+C*.22}`);break;case"server":g({kind:"rect",x:M-C*.22,y:b-C*.24,width:C*.44,height:C*.48,rx:0,ry:0});y(`M ${M-C*.16} ${b-C*.08} H ${M+C*.16}`);y(`M ${M-C*.16} ${b+C*.06} H ${M+C*.16}`);break;default:{const P=JM(r),E=Math.max(10,i*.56);const k=l;p.push(e.text({id:xn(s,"fallback"),role:"icon",owner:a,text:P,block:k,x:M,y:b,fontSize:E,fontWeight:700,anchor:"middle",paint:{fill:h},attributes:{className:"architecture-icon-glyph architecture-icon-fallback",data:{fallback:"true"}}}))}}return e.group({id:s,role:"icon",owner:a,open:` <g class="architecture-icon" data-icon="${Ye(r)}"${f}>`,close:"</g>",children:p.map((P,E)=>({node:P,indent:E===0?2:0}))})}var X_=gt(wU);var qPe={configDiagnostics:J$,statementEnds:Fb,normalizeRequest:e=>{const t=AP(e.source.frontmatter,e.colors,e.renderOptions,e.styleFace);const n={...e.renderOptions,padding:e.renderOptions.padding??t.padding,nodeSpacing:e.renderOptions.nodeSpacing??t.nodeSpacing,layerSpacing:e.renderOptions.layerSpacing??t.layerSpacing};return{renderOptions:n,familyConfig:{layout:t.layout},appearance:{family:{visual:t.visual}}}},layout:e=>{const t=e.familyConfig;const n=Tn(Vr(YP(zP(e.source)),e.source.accessibility),e.source.frontmatter);return ht(W_(n,e.renderOptions,t?.layout),{injectAccessibility:false})},projectPositioned:ut(xA),lowerScene:ft(X_)};var RU={nodeSpacing:Yt,rankSpacing:Yt,hierarchicalNamespaces:lt};var U_=e=>xt("class",e,RU);function Do(e){const t=e.edgeStrokeColor??"var(--_arrow)";const n=[{x:0,y:0},{x:12,y:5},{x:0,y:10}];const i=[{x:7,y:1},{x:13,y:6},{x:7,y:11},{x:1,y:6}];return[{id:"cls-inherit",shape:"triangle",size:{width:12,height:10},ref:{x:12,y:5},orient:"auto-start-reverse",overflow:"visible",geometry:{kind:"polygon",points:n},paint:{fill:"var(--bg)",stroke:t,strokeWidth:"1.5"}},{id:"cls-composition",shape:"diamond",size:{width:14,height:12},viewBox:{x:0,y:0,width:14,height:12},ref:{x:13,y:6},orient:"auto-start-reverse",overflow:"hidden",geometry:{kind:"polygon",points:i},paint:{fill:t,stroke:t,strokeWidth:"1"}},{id:"cls-aggregation",shape:"diamond-open",size:{width:14,height:12},viewBox:{x:0,y:0,width:14,height:12},ref:{x:13,y:6},orient:"auto-start-reverse",overflow:"hidden",geometry:{kind:"polygon",points:i},paint:{fill:"var(--bg)",stroke:t,strokeWidth:"1.5"}},{id:"cls-arrow",shape:"open-arrow",size:{width:8,height:6},ref:{x:8,y:3},orient:"auto-start-reverse",overflow:"visible",geometry:{kind:"polyline",points:[{x:0,y:0},{x:8,y:3},{x:0,y:6}]},paint:{fill:"none",stroke:t,strokeWidth:"1.5"}},pg(t)]}var V_=xr(Do({}));function vc(e,t){return{start:V_(e.markerAt==="from"||e.markerAt==="both"?Pi(e.fromType??e.type)??void 0:void 0,t.lineWidth,"start"),end:V_(e.markerAt==="to"||e.markerAt==="both"?Pi(e.toType??e.type)??void 0:void 0,t.lineWidth,"end")}}function Pi(e){switch(e){case"inheritance":case"realization":return"cls-inherit";case"composition":return"cls-composition";case"aggregation":return"cls-aggregation";case"association":case"dependency":return"cls-arrow";case"lollipop":return"cls-lollipop";default:return null}}var lu=3;var sa=8;function cu(e){return e.label&&e.points.length>=2?e.labelPosition??e.points[Math.floor(e.points.length/2)]:void 0}function Tc(e,t){if(!e[`${t}Cardinality`]||e.points.length<2)return void 0;const n=e[`${t}CardinalityPosition`];if(n)return n;const i=t==="from"?e.points[0]:e.points.at(-1),r=t==="from"?e.points[1]:e.points.at(-2),o=r.x-i.x,s=r.y-i.y;return Math.abs(o)>Math.abs(s)?{x:i.x+(o>0?14:-14),y:i.y-10}:{x:i.x-14,y:i.y+(s>0?14:-14)}}var Ak=(Math.floor((150-14)/10)+1)*2*(Math.floor((190-10)/12)+1);function*kx(e,t){const n=t.x-e.x,i=t.y-e.y,r=Math.abs(n)>=Math.abs(i),o=r?Math.sign(n||1):0,s=r?0:Math.sign(i||1);for(let a=14;a<=150;a+=10)for(let l=10;l<=190;l+=12)for(const c of[-l,l])yield{x:e.x+o*a-s*c,y:e.y+s*a+o*c}}var Ik=Symbol("Class header numeric snapshot");function Cx(e,t){e[Ik]=t}var K_=Symbol("Class header candidate authority");var Fk=class{#e;#t;#n;#i;constructor(t,n,i,r,o){if(t!==K_)throw new TypeError("Unauthorized Class header candidate proof");this.#e=n;this.#t=i;this.#n=r;this.#i=o}clear(t){st(this.#i);if(!this.#e.active)throw new Qe([{strategy:"class-header-lanes",violations:["Stale Class header candidate proof"]}]);return NU(t,this.#t,this.#n,this.#i)}};var cn=e=>Number(Xe(e));var st=e=>{if(!e())throw new Qe([{strategy:"class-header-lanes",violations:["Class header carrier proof work limit"]}])};var vU=(e,t)=>Math.max(e.x0,t.x0)<Math.min(e.x1,t.x1)&&Math.max(e.y0,t.y0)<Math.min(e.y1,t.y1);var du=(e,t)=>e.x===t.x&&e.y===t.y;function Nk(e,t,n,i,r,o=e){const s=[];for(let a=1;a<e.length;a++){st(r);const l=e[a-1],c=e[a];if(du(l,c)||l.x!==c.x&&l.y!==c.y)return void 0;if(n>0)s.push({owner:t,kind:"strip",segment:a-1,axis:l.y===c.y?"x":"y",box:l.y===c.y?{x0:Math.min(l.x,c.x),x1:Math.max(l.x,c.x),y0:l.y-n,y1:l.y+n}:{x0:l.x-n,x1:l.x+n,y0:Math.min(l.y,c.y),y1:Math.max(l.y,c.y)}});if(a+1===e.length)continue;const d=e[a+1],u=Math.sign(c.x-l.x),f=Math.sign(c.y-l.y),h=Math.sign(d.x-c.x),m=Math.sign(d.y-c.y),p=u*m-f*h;if(!p||n<=0)continue;if(i>0){const g=o[a-1],y=o[a],w=o[a+1],S=Math.abs(y.x-g.x)+Math.abs(y.y-g.y),x=Math.abs(w.x-y.x)+Math.abs(w.y-y.y),M=Math.min(i,S/2,x/2);const b={x:cn(y.x+(g.x-y.x)*(M/S)),y:cn(y.y+(g.y-y.y)*(M/S))},C={x:cn(y.x+(w.x-y.x)*(M/x)),y:cn(y.y+(w.y-y.y)*(M/x))};s.push({owner:t,kind:"curve",segment:a-1,axis:"x",box:{x0:Math.min(b.x,c.x,C.x)-n,x1:Math.max(b.x,c.x,C.x)+n,y0:Math.min(b.y,c.y,C.y)-n,y1:Math.max(b.y,c.y,C.y)+n}})}else{const g=p>0?-1:1,y=(-f*g+-m*g)*n,w=(u*g+h*g)*n;s.push({owner:t,kind:"join",segment:a-1,axis:"x",box:{x0:Math.min(c.x,c.x+y),x1:Math.max(c.x,c.x+y),y0:Math.min(c.y,c.y+w),y1:Math.max(c.y,c.y+w)}})}}return s}function $k(e,t,n){const i=cn(t.lineWidth)/2,r=t.edgeBendRadius,o=[],s=[];if(![i,r].every(Number.isFinite)||i<0||r<0)throw new TypeError("Nonfinite Class header stroke");for(let a=0;a<e.length;a++){st(n);const l=e[a],c=[],d=[];for(const f of l.points){st(n);if(![f.x,f.y].every(Number.isFinite))throw new TypeError("Nonfinite Class header carrier");c.push({x:f.x,y:f.y});d.push({x:cn(f.x),y:cn(f.y)})}o.push({from:l.from,to:l.to,dashed:nc(l)==="dashed",raw:c,points:d});const u=Nk(d,a,i,r,n,c);if(!u)throw new Qe([{strategy:"class-header-lanes",violations:["Unproved noncardinal Class header carrier"]}]);s.push(...u)}return{...J_(s,o,n),routes:o,pieces:s,half:i,radius:r}}function J_(e,t,n){const i=[],r=[],o=[],s=[],a=[],l=[];let c=0,d=0;for(const u of e){st(n);if(u.kind==="strip"){const f=t[u.owner].points[u.segment],h=t[u.owner].points[u.segment+1];if(u.axis==="x"){i.push({key:f.y,piece:u});o.push({key:f.x,piece:u},{key:h.x,piece:u})}else{r.push({key:f.x,piece:u});s.push({key:f.y,piece:u},{key:h.y,piece:u})}}else{a.push({key:(u.box.x0+u.box.x1)/2,piece:u});l.push({key:(u.box.y0+u.box.y1)/2,piece:u});c=Math.max(c,(u.box.x1-u.box.x0)/2);d=Math.max(d,(u.box.y1-u.box.y0)/2)}}for(const u of[i,r,o,s,a,l])u.sort((f,h)=>{st(n);return f.key-h.key||f.piece.owner-h.piece.owner||f.piece.segment-h.piece.segment});return{horizontal:i,vertical:r,horizontalEnds:o,verticalEnds:s,cornersX:a,cornersY:l,cornerHalfX:c,cornerHalfY:d}}function*Hr(e,t,n,i){let r=0,o=e.length;while(r<o){st(i);const s=r+o>>>1;if(e[s].key<t)r=s+1;else o=s}for(;r<e.length;r++){st(i);const s=e[r];if(s.key>n)break;yield s.piece}}function*TU(e,t,n){const i=e.box,r=t.half;const o=new Set;const s=[];if(e.kind==="strip"&&e.axis==="x")s.push(Hr(t.horizontal,i.y0-r,i.y1+r,n),Hr(t.vertical,i.x0-r,i.x0+r,n),Hr(t.vertical,i.x1-r,i.x1+r,n),Hr(t.verticalEnds,i.y0-r,i.y1+r,n),Hr(t.cornersY,i.y0-t.cornerHalfY,i.y1+t.cornerHalfY,n));else if(e.kind==="strip")s.push(Hr(t.vertical,i.x0-r,i.x1+r,n),Hr(t.horizontal,i.y0-r,i.y0+r,n),Hr(t.horizontal,i.y1-r,i.y1+r,n),Hr(t.horizontalEnds,i.x0-r,i.x1+r,n),Hr(t.cornersX,i.x0-t.cornerHalfX,i.x1+t.cornerHalfX,n));else s.push(Hr(t.horizontal,i.y0-r,i.y1+r,n),Hr(t.vertical,i.x0-r,i.x1+r,n),Hr(t.cornersX,i.x0-t.cornerHalfX,i.x1+t.cornerHalfX,n));for(const a of s)for(const l of a){st(n);if(!o.has(l)){o.add(l);yield l}}}function LU(e,t,n,i){if(e.x===t.x&&n.y===i.y)return Math.min(e.y,t.y)<n.y&&n.y<Math.max(e.y,t.y)&&Math.min(n.x,i.x)<e.x&&e.x<Math.max(n.x,i.x);return e.y===t.y&&n.x===i.x&&Math.min(e.x,t.x)<n.x&&n.x<Math.max(e.x,t.x)&&Math.min(n.y,i.y)<e.y&&e.y<Math.max(n.y,i.y)}function AU(e,t,n,i,r,o,s){if(i.kind!=="strip"||r.kind!=="strip"||i.axis===r.axis)return false;for(const a of[true,false])for(const l of[true,false]){st(s);if(i.segment!==(a?0:t.points.length-2)||r.segment!==(l?0:n.points.length-2))continue;if((a?t.from:t.to)!==(l?n.from:n.to))continue;const c=t.points[a?0:t.points.length-1],d=n.points[l?0:n.points.length-1];if(du(c,d)&&e.x0>=c.x-o&&e.x1<=c.x+o&&e.y0>=c.y-o&&e.y1<=c.y+o)return true}return false}function IU(e,t,n,i){if(e.routes.length!==t.length||e.half!==cn(n.lineWidth)/2||e.radius!==n.edgeBendRadius)return false;for(let r=0;r<t.length;r++){st(i);const o=t[r],s=e.routes[r];if(o.from!==s.from||o.to!==s.to||nc(o)==="dashed"!==s.dashed||o.points.length!==s.raw.length)return false;for(let a=0;a<o.points.length;a++){st(i);if(!du(o.points[a],s.raw[a]))return false}}return true}function FU(e,t,n,i){if(IU(e,t,n,i))return e;if(e.routes.length!==t.length||e.half!==cn(n.lineWidth)/2||e.radius!==n.edgeBendRadius)return $k(t,n,i);st(i);const r=new Set,o=[],s=[],a=[];for(let d=0;d<t.length;d++){st(i);const u=t[d],f=e.routes[d],h=nc(u)==="dashed";let m=u.from===f.from&&u.to===f.to&&h===f.dashed&&u.points.length===f.raw.length;if(m)for(let w=0;w<u.points.length;w++){st(i);if(!du(u.points[w],f.raw[w])){m=false;break}}if(m){o.push(f);continue}r.add(d);const p=[],g=[];for(const w of u.points){st(i);if(![w.x,w.y].every(Number.isFinite))throw new TypeError("Nonfinite Class header carrier");p.push({x:w.x,y:w.y});g.push({x:cn(w.x),y:cn(w.y)})}o.push({from:u.from,to:u.to,dashed:h,raw:p,points:g});const y=Nk(g,d,e.half,e.radius,i,p);if(!y)throw new Qe([{strategy:"class-header-lanes",violations:["Unproved noncardinal Class header carrier"]}]);for(const w of y){st(i);a.push(w)}}for(const d of e.pieces){st(i);if(!r.has(d.owner))s.push(d)}for(const d of a){st(i);s.push(d)}const l=J_(a,o,i);const c=(d,u)=>{st(i);const f=[];let h=0;for(const m of d){st(i);if(r.has(m.piece.owner))continue;while(h<u.length){st(i);const p=u[h];if((p.key-m.key||p.piece.owner-m.piece.owner||p.piece.segment-m.piece.segment)>0)break;f.push(p);h++}f.push(m)}for(;h<u.length;h++){st(i);f.push(u[h])}return f};return{routes:o,pieces:s,half:e.half,radius:e.radius,horizontal:c(e.horizontal,l.horizontal),vertical:c(e.vertical,l.vertical),horizontalEnds:c(e.horizontalEnds,l.horizontalEnds),verticalEnds:c(e.verticalEnds,l.verticalEnds),cornersX:c(e.cornersX,l.cornersX),cornersY:c(e.cornersY,l.cornersY),cornerHalfX:Math.max(e.cornerHalfX,l.cornerHalfX),cornerHalfY:Math.max(e.cornerHalfY,l.cornerHalfY)}}function Q_(e,t,n,i){st(i);const r=e[Ik];if(!r)return void 0;st(i);e[Ik]=void 0;st(i);const o=S=>{for(let x=0;x<S;x++)st(i)};if(n.edgeBendRadius!==0||r.radius!==0||r.routes.length!==t.length)return void 0;let s;if(Number.isSafeInteger(n.lineWidth)){o(2);s=n.lineWidth/2}else{o(133);s=cn(n.lineWidth)/2}if(r.half!==s)return void 0;let a;for(let S=0;S<t.length;S++){st(i);const x=t[S],M=r.routes[S];if(x.from!==M.from||x.to!==M.to||nc(x)==="dashed"!==M.dashed)return void 0;let b=x.points.length===M.raw.length;if(b)for(let C=0;C<x.points.length;C++){st(i);if(!du(x.points[C],M.raw[C])){b=false;break}}if(!b){if(!a){st(i);a=new Set}st(i);a.add(S)}}if(!a){o(6);return{routes:r.routes,horizontal:r.horizontal,vertical:r.vertical,horizontalEnds:r.horizontalEnds,verticalEnds:r.verticalEnds}}o(r.routes.length+5);const l=r.routes.slice(),c=[],d=[],u=[],f=[];for(const S of a){st(i);const x=t[S];o(5);const M=[],b=[];for(const C of x.points){st(i);const P=Ki(C,o,o);if(!P)return void 0;o(P===C?8:5);M.push({x:C.x,y:C.y});b.push(P===C?{x:C.x,y:C.y}:P)}l[S]={raw:M,points:b};for(let C=1;C<b.length;C++){st(i);const P=b[C-1],E=b[C];if(du(P,E)||P.x!==E.x&&P.y!==E.y)return void 0;o(15);const k={owner:S,segment:C-1},v=P.y===E.y;(v?c:d).push({key:v?P.y:P.x,piece:k});(v?u:f).push({key:v?P.x:P.y,piece:k},{key:v?E.x:E.y,piece:k})}}st(i);const h=(S,x)=>{st(i);return S.key-x.key||S.piece.owner-x.piece.owner||S.piece.segment-x.piece.segment};c.sort(h);d.sort(h);u.sort(h);f.sort(h);st(i);const m=(S,x)=>{st(i);const M=[];let b=0;for(const C of S){st(i);if(a.has(C.piece.owner))continue;while(b<x.length&&h(x[b],C)<=0){st(i);M.push(x[b++])}st(i);M.push(C)}for(;b<x.length;b++){o(2);M.push(x[b])}return M};const p=m(r.horizontal,c),g=m(r.vertical,d),y=m(r.horizontalEnds,u),w=m(r.verticalEnds,f);o(6);return{routes:l,horizontal:p,vertical:g,horizontalEnds:y,verticalEnds:w}}function NU(e,t,n,i){const r=n.routes[t],o={from:r.from,to:r.to,dashed:r.dashed,raw:e.map(s=>{st(i);return{...s}}),points:e.map(s=>{st(i);return{x:cn(s.x),y:cn(s.y)}})};return Z_(o,t,n,i)}function Z_(e,t,n,i){const r=Nk(e.points,t,n.half,n.radius,i,e.raw);if(!r)return false;for(const o of r)for(const s of TU(o,n,i)){st(i);if(s.owner===t||!vU(o.box,s.box))continue;const a=n.routes[s.owner];if(o.kind==="strip"&&s.kind==="strip"){st(i);if(LU(e.points[o.segment],e.points[o.segment+1],a.points[s.segment],a.points[s.segment+1]))continue}const l={x0:Math.max(o.box.x0,s.box.x0),x1:Math.min(o.box.x1,s.box.x1),y0:Math.max(o.box.y0,s.box.y0),y1:Math.min(o.box.y1,s.box.y1)};if(!AU(l,e,a,o,s,n.half,i))return false}return true}function*eD(e){const{charge:t}=e,n=e.peerContext?FU(e.peerContext,e.relationships,e.style,t):$k(e.relationships,e.style,t),i={x:cn(e.a.x),y:cn(e.a.y)},r={x:cn(e.b.x),y:cn(e.b.y)};const o=i.x===r.x;if(!o&&i.y!==r.y)return;const s=o?"y":"x",a=o?"x":"y",l=e.header;const c=cn(l[s]),d=cn(o?l.height:l.width),u=cn(c-e.gap),f=cn(c+d+e.gap);if(Math.min(i[s],r[s])>=u||Math.max(i[s],r[s])<=f)return;const h=[{side:"low",lane:cn(l[a]-e.escape)},{side:"high",lane:cn(l[a]+(o?l.width:l.height)+e.escape)}].sort((S,x)=>Math.abs(S.lane-i[a])-Math.abs(x.lane-i[a]));const m=Math.min(u-Math.min(i[s],r[s]),Math.max(i[s],r[s])-f),p=Math.max(1,cn(e.style.lineWidth)),g=new Set([0]);const y=S=>{if(S>0&&Number.isFinite(S)){const x=Math.ceil(S/p)*p;if(x<m)g.add(x)}};for(const S of n.pieces){st(t);if(S.owner===e.owner)continue;const x=o?S.box.y0:S.box.x0,M=o?S.box.y1:S.box.x1,b=o?S.box.x0:S.box.y0,C=o?S.box.x1:S.box.y1;y(u+n.half-x);y(M+n.half-f);y(h.find(P=>P.side==="low").lane+n.half-b);y(C+n.half-h.find(P=>P.side==="high").lane)}const w=[...g].sort((S,x)=>{st(t);return S-x});for(const S of w)for(const x of h){st(t);const M=cn(u-S),b=cn(f+S),C=cn(x.lane+(x.side==="low"?-S:S));const P={...i,[s]:i[s]<r[s]?M:b},E={...r,[s]:i[s]<r[s]?b:M};const k=[P,{...P,[a]:C},{...E,[a]:C},E];if(k.some(A=>A.x<n.half||A.y<n.half||A.x>e.width-n.half||A.y>e.height-n.half))continue;st(t);st(t);st(t);const v={active:true},T=new Fk(K_,v,e.owner,n,t);try{yield{points:k,side:x.side,offset:S,lane:C,low:M,high:b,peerContext:n,peerProof:T}}finally{v.active=false}}}function tD(e,t,n,i){if(!t.size)return;const r=$k(e.relationships,n,i);for(const o of t){st(i);if(!Z_(r.routes[o],o,r,i))throw new Qe([{strategy:"class-header-lanes",violations:[`No proved final header carrier separation for ${r.routes[o].from} -> ${r.routes[o].to}`]}])}}var wt=e=>{if(!Number.isFinite(e))throw new Qe([{strategy:"class-owned-surfaces",violations:["Nonfinite retained Class geometry"]}]);return Number(Xe(e))};var kn=e=>({x:wt(e.x),y:wt(e.y)});function _k(e,t){const n=t?.get(e);if(n)return n;const i=Xe(e),r=/^(-?)(\d+)(?:\.(\d+))?(?:e([+-]?\d+))?$/.exec(i);const o={n:BigInt(r[1]+r[2]+(r[3]??"")),e:Number(r[4]??0)-(r[3]?.length??0)};t?.set(e,o);return o}function Xh(e,t,n,i){const r=t+n,o=e-r;if(Math.abs(o)>8*Number.EPSILON*Math.max(1,Math.abs(e),Math.abs(t),Math.abs(n)))return Math.sign(o);const s=_k(e,i),a=_k(t,i),l=_k(n,i),c=Math.min(s.e,a.e,l.e),d=s.e===c?s.n:s.n*10n**BigInt(s.e-c),u=a.e===c?a.n:a.n*10n**BigInt(a.e-c),f=l.e===c?l.n:l.n*10n**BigInt(l.e-c),h=d-u-f;return h<0n?-1:h>0n?1:0}function ys(e,t,n){return Xh(wt(e),wt(t),wt(n))}function vx(e,t){const n=[e,t].map(s=>{const a=/^(-?)(\d+)(?:\.(\d+))?(?:e([+-]?\d+))?$/.exec(Xe(wt(s)));return{n:BigInt(a[1]+a[2]+(a[3]??"")),e:Number(a[4]??0)-(a[3]?.length??0)}});const i=Math.min(...n.map(s=>s.e)),r=n.reduce((s,a)=>s+a.n*10n**BigInt(a.e-i),0n),o=Number(`${r}e${i}`);return Number.isFinite(o)&&ys(o,e,t)===0?o:void 0}var go=e=>{if(e.width<0||e.height<0||!Number.isFinite(e.x+e.width)||!Number.isFinite(e.y+e.height))throw new Qe([{strategy:"class-owned-surfaces",violations:["Invalid retained Class surface"]}]);return{x:wt(e.x),y:wt(e.y),width:wt(e.width),height:wt(e.height)}};var Ex=(e,t)=>{const n=go(e),i=go(t);return n.x<i.x+i.width&&n.x+n.width>i.x&&n.y<i.y+i.height&&n.y+n.height>i.y};var Tx=4;var $U=8;var cl=(e,t)=>({x:e.x-t,y:e.y-t,width:e.width+2*t,height:e.height+2*t});function dl(e,t,n){return Rx(kn(e),kn(t),go(n))}function Rx(e,t,n,i){if(!(n.width>0&&n.height>0))return false;let r=0,o=1;for(let s=0;s<2;s++){const a=s===0?"x":"y";const l=a==="x"?n.width:n.height,c=n[a];if(e[a]<=c&&t[a]<=c)return false;const d=Xh(e[a],c,l,i),u=e[a]===t[a]?d:Xh(t[a],c,l,i);if(d>=0&&u>=0)return false;const f=d===0?l:e[a]-c,h=u===0?l:t[a]-c,m=h-f;if(m===0){if(e[a]<=c||d>=0)return false}else{const p=-f/m,g=(l-f)/m;r=Math.max(r,Math.min(p,g));o=Math.min(o,Math.max(p,g))}}return r<o}var uu=(e,t)=>e.some((n,i)=>i>0&&dl(e[i-1],n,t));function Px(e,t,n,i,r,o){const s=(e.x-n)/r,a=(e.y-i)/o,l=(t.x-e.x)/r,c=(t.y-e.y)/o,d=l*l+c*c;const u=d?Math.max(0,Math.min(1,-(s*l+a*c)/d)):0;return(s+u*l)**2+(a+u*c)**2<1}function nD(e,t,n,i){return iD({emitted:kn(e)},{emitted:kn(t)},{source:n,radius:i})}function iD(e,t,n,i){const r=n.emitted??=go(n.inflation===void 0?n.source:cl(n.source,n.inflation));const o=n.rx??=Math.min(Math.max(0,n.radius),r.width/2),s=n.ry??=Math.min(Math.max(0,n.radius),r.height/2);const a=e.clipped??=kn(e.emitted),l=t.clipped??=kn(t.emitted);if(!o||!s)return Rx(a,l,n.unrounded??=go(r),i);const c=n.firstStrip??=go({x:r.x+o,y:r.y,width:r.width-2*o,height:r.height});if(Rx(a,l,c,i))return true;const d=n.secondStrip??=go({x:r.x,y:r.y+s,width:r.width,height:r.height-2*s});if(Rx(a,l,d,i))return true;const u=n.left??=r.x+o,f=n.right??=r.x+r.width-o,h=n.top??=r.y+s,m=n.bottom??=r.y+r.height-s;if(e.emitted.x===t.emitted.x&&Math.abs((e.emitted.x-u)/o)>=1&&Math.abs((e.emitted.x-f)/o)>=1||e.emitted.y===t.emitted.y&&Math.abs((e.emitted.y-h)/s)>=1&&Math.abs((e.emitted.y-m)/s)>=1)return false;return Px(e.emitted,t.emitted,u,h,o,s)||Px(e.emitted,t.emitted,u,m,o,s)||Px(e.emitted,t.emitted,f,h,o,s)||Px(e.emitted,t.emitted,f,m,o,s)}function rD(e,t,n){if(e.length<3||t.length<3)return false;const i=e[0],r=e.map(a=>{n?.();return{x:a.x-i.x,y:a.y-i.y}}),o=t.map(a=>{n?.();return{x:a.x-i.x,y:a.y-i.y}}),s=[];for(const a of[r,o])for(let l=0;l<a.length;l++){n?.();const c=a[l],d=a[(l+1)%a.length];if(c.x!==d.x||c.y!==d.y)s.push({x:c.y-d.y,y:d.x-c.x})}for(const a of s){n?.();let l=Infinity,c=-Infinity,d=Infinity,u=-Infinity;for(const f of r){n?.();const h=f.x*a.x+f.y*a.y;l=Math.min(l,h);c=Math.max(c,h)}for(const f of o){n?.();const h=f.x*a.x+f.y*a.y;d=Math.min(d,h);u=Math.max(u,h)}if(Math.min(c,u)<=Math.max(l,d))return false}return s.length>0}function oD(e,t,n){if(t.width<=0||t.height<=0)return false;return rD(e,[{x:t.x,y:t.y},{x:t.x+t.width,y:t.y},{x:t.x+t.width,y:t.y+t.height},{x:t.x,y:t.y+t.height}],n)}function sD(e,t,n,i){if(n<=0||i.length<3)return false;let r=0,o=true,s=0;for(let a=0;a<i.length;a++){const l=i[a],c=i[(a+1)%i.length],d=c.x-l.x,u=c.y-l.y,f=d*(t-l.y)-u*(e-l.x);s+=(l.x-i[0].x)*(c.y-i[0].y)-(l.y-i[0].y)*(c.x-i[0].x);if(f){if(r&&Math.sign(f)!==r)o=false;r||=Math.sign(f)}const h=d*d+u*u,m=h?Math.max(0,Math.min(1,((e-l.x)*d+(t-l.y)*u)/h)):0;if((l.x+m*d-e)**2+(l.y+m*u-t)**2<n*n)return true}return s!==0&&o}function Uh(e,t,n){const i=go(t);return e.some(r=>{n?.();return r.kind==="polygon"?oD(r.points,i,n):DU(r.cx,r.cy,r.r,i)})}function Dk(e,t,n,i){e=kn(e);t=kn(t);const r=t.x-e.x,o=t.y-e.y,s=Math.hypot(r,o),a=i/2;if(!s||!(a>0))return false;const l=-o/s*a,c=r/s*a,d=[{x:e.x+l,y:e.y+c},{x:t.x+l,y:t.y+c},{x:t.x-l,y:t.y-c},{x:e.x-l,y:e.y-c}];return n.some(u=>u.kind==="polygon"?rD(d,u.points):sD(u.cx,u.cy,u.r,d))}function _U(e,t,n,i){const r=i/2;if(!(r>0))return false;for(let o=1;o+1<e.length;o++){const s=kn(e[o-1]),a=kn(e[o]),l=kn(e[o+1]);if(!(s.x===a.x&&a.y===l.y||s.y===a.y&&a.x===l.x))continue;if(t.some((c,d)=>d>0&&d+1<t.length&&wt(c.x)===a.x&&wt(c.y)===a.y&&wt(t[d-1].x)===s.x&&wt(t[d-1].y)===s.y&&wt(t[d+1].x)===l.x&&wt(t[d+1].y)===l.y))continue;if(Uh(n,{x:a.x-r,y:a.y-r,width:i,height:i}))return true}return false}function aD(e,t,n,i,r,o){if(!(r.edgeBendRadius>0))return true;const s=wt(r.lineWidth)/2;for(let a=1;a+1<e.length;a++){o?.();const l=e[a-1],c=e[a],d=e[a+1];if(t.some((w,S)=>{o?.();return S>0&&S+1<t.length&&w.x===c.x&&w.y===c.y&&t[S-1].x===l.x&&t[S-1].y===l.y&&t[S+1].x===d.x&&t[S+1].y===d.y}))continue;const u=qn([l,c,d],r.edgeBendRadius,{metric:"manhattan"});if(u.geometry.kind!=="path")return false;const f=/L([^LQ]+)Q([^LQ]+)/.exec(u.geometry.d);if(!f)continue;const h=(f[1]+" "+f[2]).trim().split(/[ ,]+/).map(Number);if(h.length!==6||h.some(w=>!Number.isFinite(w)))return false;const m=[{x:wt(h[0]),y:wt(h[1])},{x:wt(h[2]),y:wt(h[3])},{x:wt(h[4]),y:wt(h[5])}];if(n.some(w=>{o?.();return oD(m,cl(go(w),s),o)}))return false;const p=m.map(w=>w.x),g=m.map(w=>w.y),y={x:Math.min(...p)-s,y:Math.min(...g)-s,width:Math.max(...p)-Math.min(...p)+2*s,height:Math.max(...g)-Math.min(...g)+2*s};if(i.some(w=>{o?.();return Uh(w,y,o)}))return false}return true}function lD(e,t){const n=go(t),i=Math.min(2,n.width/2,n.height/2);if(!i)return false;const r=[{x:n.x+i,y:n.y,width:n.width-2*i,height:n.height},{x:n.x,y:n.y+i,width:n.width,height:n.height-2*i}];if(r.some(o=>Uh(e,o)))return true;for(const o of[n.x+i,n.x+n.width-i])for(const s of[n.y+i,n.y+n.height-i])for(const a of e){if(a.kind==="circle"?(a.cx-o)**2+(a.cy-s)**2<(a.r+i)**2:sD(o,s,i,a.points))return true}return false}function DU(e,t,n,i){if(n<=0||i.width<=0||i.height<=0)return false;const r=e-Math.max(i.x,Math.min(i.x+i.width,e)),o=t-Math.max(i.y,Math.min(i.y+i.height,t));return r*r+o*o<n*n}function Oo(e,t,n=true,i,r=true){const o=[],s=n?Do(t):[],a=lu/2;e.relationships.forEach((l,c)=>{i?.();const d=cu(l);if(r&&l.label&&d&&l.labelBlock?.text)o.push({edge:c,kind:"label",box:{x:d.x-l.labelBlock.width/2-a,y:d.y-sa-l.labelBlock.height/2-a,width:l.labelBlock.width+2*a,height:l.labelBlock.height+2*a}});for(const w of["from","to"]){i?.();const S=l[`${w}CardinalityBlock`],x=Tc(l,w);if(r&&S?.text&&x)o.push({edge:c,kind:"cardinality",box:{x:x.x-S.width/2-a,y:x.y-S.height/2-a,width:S.width+2*a,height:S.height+2*a}})}if(!n)return;const u=l.markerAt==="from"||l.markerAt==="both"?Pi(l.fromType??l.type):null,f=l.markerAt==="to"||l.markerAt==="both"?Pi(l.toType??l.type):null;const h=kn(l.points[0]??{x:0,y:0}),m=kn(l.points.at(-1)??h);let p=h,g=m;for(let w=1;w<l.points.length;w++){i?.();const S=kn(l.points[w]);if(S.x!==h.x||S.y!==h.y){p=S;break}}for(let w=l.points.length-2;w>=0;w--){i?.();const S=kn(l.points[w]);if(S.x!==m.x||S.y!==m.y){g=S;break}}const y=Wo({id:"class-owned-paint",role:"relationship",geometry:{kind:"polyline",points:[h,p,g,m]},lineStyle:"solid",paint:{strokeWidth:String(wt(t.lineWidth))},markers:{...u?{start:s.find(w=>w.id===u)}:{},...f?{end:s.find(w=>w.id===f)}:{}}});for(const w of Yr(y)){i?.();const S=w.bounds;if(!S)throw new TypeError("Class marker paint has no finite bound");const x=w.position==="start",M=s.find(A=>A.id===w.resource);const b=x?h:m,C=x?{x:p.x-h.x,y:p.y-h.y}:{x:m.x-g.x,y:m.y-g.y};const P=zo(M,b,C,x?"start":"end",wt(t.lineWidth),i);let E=S.x0,k=S.y0,v=S.x1,T=S.y1;for(const A of P){i?.();if(A.kind==="circle"){E=Math.min(E,A.cx-A.r);v=Math.max(v,A.cx+A.r);k=Math.min(k,A.cy-A.r);T=Math.max(T,A.cy+A.r)}else for(const R of A.points){i?.();E=Math.min(E,R.x);v=Math.max(v,R.x);k=Math.min(k,R.y);T=Math.max(T,R.y)}}o.push({edge:c,kind:"marker",endpoint:x?"from":"to",pieces:P,box:{x:E,y:k,width:v-E,height:T-k}})}});return o}function OU(e){const t=ii(e.map(kn));for(let n=1;n<t.length;n++){const i=t[n-1],r=t[n],o=i.x===r.x;if(!o&&i.y!==r.y)return false;for(let s=1;s<n;s++){const a=t[s-1],l=t[s],c=a.x===l.x;if(o===c){const d=o?"y":"x",u=o?"x":"y";if(i[u]!==a[u])continue;const f=Math.max(Math.min(i[d],r[d]),Math.min(a[d],l[d])),h=Math.min(Math.max(i[d],r[d]),Math.max(a[d],l[d]));if(s===n-1?f<h:f<=h)return false}else if(s!==n-1){const d=o?i.x:a.x,u=o?a.y:i.y;if(d>=Math.min(i.x,r.x)&&d<=Math.max(i.x,r.x)&&u>=Math.min(i.y,r.y)&&u<=Math.max(i.y,r.y)&&d>=Math.min(a.x,l.x)&&d<=Math.max(a.x,l.x)&&u>=Math.min(a.y,l.y)&&u<=Math.max(a.y,l.y))return false}}}return true}function Ok(e,t,n){n();if(!(t>0)||!Number.isFinite(t))return void 0;let i=Infinity,r=Infinity,o=-Infinity,s=-Infinity;for(const a of e){n();if(!Number.isFinite(a.x)||!Number.isFinite(a.y))return void 0;i=Math.min(i,a.x);r=Math.min(r,a.y);o=Math.max(o,a.x);s=Math.max(s,a.y)}i-=t;r-=t;o+=t;s+=t;if(!Number.isFinite(i)||!Number.isFinite(r)||!Number.isFinite(o)||!Number.isFinite(s))return void 0;for(let a=0;a<5;a++)n();return{x0:i,y0:r,x1:o,y1:s}}function Bk(e,t,n){n();if(!e||!(t.width>=0&&t.height>=0))return true;const i=t.x+t.width,r=t.y+t.height,o=(Math.abs(e.x0)+Math.abs(e.y0)+Math.abs(e.x1)+Math.abs(e.y1)+Math.abs(t.x)+Math.abs(t.y)+Math.abs(i)+Math.abs(r))*1e-10+1e-9,s=t.x-e.x1,a=e.x0-i,l=t.y-e.y1,c=e.y0-r;return!Number.isFinite(o)||!Number.isFinite(s)||!Number.isFinite(a)||!Number.isFinite(l)||!Number.isFinite(c)||!(s>o||a>o||l>o||c>o)}function cD(e,t,n,i){const r=new Set;if(!e.namespaces.length){if(i){const y=n??gs();if(!ri(y))throw new Qe([{strategy:"class-header-lanes",violations:["Class header proof work limit"]}]);Cx(i,void 0)}return r}const o=n??gs(),s=()=>ri(o),a=()=>{if(!s())throw new Qe([{strategy:"class-header-lanes",violations:["Class header proof work limit"]}])};if(i){a();Cx(i,void 0)}const l=e.namespaces.map(y=>{a();return cl({x:y.x,y:y.y,width:y.width,height:y.headerHeight},t.lineWidth/2)}),c=Oo(e,t,true,a,false),d=e.classes.filter(y=>{a();return!y.isInterface}),u=[];const f=c;let h=0;for(const y of e.classes){a();if(!y.isInterface)continue;if(y.interfaceBox)u.push(y.interfaceBox);const w=y.labelBlock;if(w)u.push({x:y.x+(y.width-w.width)/2,y:y.y+y.headerHeight/2-w.height/2,width:w.width,height:w.height})}if(e.title){a();const y=e.title,w=y.block??tn(y.text,t)?.block;if(w){u.push({x:y.x-w.width/2,y:y.y-w.height/2,width:w.width,height:w.height});h=y.y+w.height/2+t.lineWidth/2}}const m=[...d.map(y=>{a();return cl(y,t.lineWidth/2)}),...l,...u.map(y=>{a();return cl(y,t.lineWidth/2)})];let p;const g=e.relationships.map((y,w)=>{a();let S=Infinity;for(const x of l)for(let M=1;M<y.points.length;M++){a();const b=kn(y.points[M-1]),C=kn(y.points[M]);if(!dl(b,C,x))continue;const P=b.x===C.x;if(!P&&b.y!==C.y)continue;const E=P?"y":"x",k=wt(x[E]),v=wt(P?x.height:x.width),T=Math.max(Tx,t.lineWidth/2),A=wt(k-T),R=wt(k+v+T);S=Math.min(S,A-Math.min(b[E],C[E]),Math.max(b[E],C[E])-R)}return{ri:w,slack:S}}).sort((y,w)=>{a();return y.slack-w.slack||y.ri-w.ri});for(const{ri:y}of g){a();const w=e.relationships[y];for(const S of l){a();if(!uu(w.points,S))continue;for(let x=1;x<w.points.length;x++){a();const M=w.points[x-1],b=w.points[x];if(!dl(M,b,S))continue;const C=Math.max(Tx,t.lineWidth/2),P=Math.max($U,t.edgeBendRadius+t.lineWidth/2);let E;for(const k of eD({header:S,a:M,b,owner:y,relationships:e.relationships,width:e.width,height:e.height,style:t,gap:C,escape:P,charge:s,peerContext:p})){p=k.peerContext;a();const v=k.points;if(v.some(I=>{a();return I.y<h}))continue;if(m.some(I=>{a();return uu(v,I)}))continue;const T=Ok(v,t.lineWidth,a);if(f.some(I=>Bk(T,I.box,a)&&v.some((L,$)=>{a();return $>0&&Dk(v[$-1],L,I.pieces??[],t.lineWidth)})))continue;const A=ii([...w.points.slice(0,x),...v,...w.points.slice(x)]);const R=La(A,vc(w,t));if(!R)continue;if(R!==A&&f.some(I=>R.some((L,$)=>{a();if(!$||I.edge===y&&(I.endpoint==="from"&&$===1||I.endpoint==="to"&&$===R.length-1))return false;const B=R[$-1],F=A[$-1],z=A[$];if(B.x===F.x&&B.y===F.y&&L.x===z.x&&L.y===z.y)return false;return Dk(B,L,I.pieces??[],t.lineWidth)})))continue;if(!OU(R)||t.edgeBendRadius<=0&&f.some(I=>{a();return _U(R,w.points,I.pieces??[],t.lineWidth)}))continue;if(t.edgeBendRadius>0&&!aD(R,w.points,m,c.filter(I=>I.kind==="marker").map(I=>I.pieces??[]),t,a))continue;if(R[0].x!==w.points[0].x||R[0].y!==w.points[0].y||R.at(-1).x!==w.points.at(-1).x||R.at(-1).y!==w.points.at(-1).y)continue;if([...d,...u,...l.filter(I=>I!==S&&!uu(w.points,I))].some(I=>{a();return uu(R,I)}))continue;if(!k.peerProof.clear(R))continue;a();E={points:R,length:v.length};break}if(E){a();w.points=E.points;r.add(y);x+=Math.max(0,E.length-2)}}}}if(i){a();Cx(i,p)}return r}function Wk(e,t,n,i){if(!e.notes.length)return;const r=i??gs(),o=()=>{if(!ri(r))throw new Qe([{strategy:"class-owned-note",violations:["Class note proof work limit"]}])},s=e.title?e.title.block??tn(e.title.text,t)?.block:void 0,a=Math.max(n,e.title&&s?e.title.y+s.height/2+Al:n),l=e.namespaces.map(f=>{o();return{x:f.x,y:f.y,width:f.width,height:f.headerHeight}});let c=Oo(e,t,true,o,false);const d=e.classes.filter(f=>{o();return f.isInterface}).map(f=>{o();const h=f.labelBlock;return h?{x:f.x+(f.width-h.width)/2,y:f.y+f.headerHeight/2-h.height/2,width:h.width,height:h.height}:{x:f.x,y:f.y,width:f.width,height:f.height}});const u=(f,h,m=false)=>{o();if(!m&&f.y<a)return false;const p=e.notes.filter((y,w)=>{o();return w!==h}),g=[...e.classes.filter(y=>{o();return!y.isInterface}),...d,...l,...p];if(g.some(y=>{o();return Ex(f,y)})||c.some(y=>{o();return y.kind==="marker"&&lD(y.pieces??[],f)}))return false;for(const y of e.relationships)for(let w=1;w<y.points.length;w++){o();if(nD(y.points[w-1],y.points[w],f,2))return false}if(t.edgeBendRadius>0)for(const y of e.relationships){o();if(!aD(y.points,[],[f],[],t,o))return false}if(f.targetX!==void 0&&f.targetY!==void 0){const y={x:f.targetX,y:f.targetY},w={x:f.noteX??f.x,y:f.noteY??f.y+f.height/2};if(g.some(C=>{o();return dl(y,w,C)})||c.some(C=>{o();return C.kind==="marker"&&Dk(y,w,C.pieces??[],1)}))return false;const S=kn(y),x=kn(w),M=S.y===x.y,b=S.x===x.x;if(M&&b)return false;if((M||b)&&t.lineWidth>0)for(const C of e.relationships)for(let P=1;P<C.points.length;P++){o();const E=kn(C.points[P-1]),k=kn(C.points[P]),v=(1+wt(t.lineWidth))/2;const T=M?E.y===k.y&&Math.abs(E.y-S.y)<v:E.x===k.x&&Math.abs(E.x-S.x)<v;if(!T)continue;const A=M?"x":"y";if(Math.max(Math.min(S[A],x[A]),Math.min(E[A],k[A]))<Math.min(Math.max(S[A],x[A]),Math.max(E[A],k[A])))return false}}return true};for(let f=0;f<e.notes.length;f++){o();const h=e.notes[f];if(u(h,f))continue;const m=e.classes.find(S=>{o();return S.id===h.for}),p=[];if(m){for(let x=0;x<Math.max(4,e.notes.length+1);x++){o();const M=x*(h.height+12);p.push({...h,x:m.x+m.width+24,y:m.y+M,targetX:m.x+m.width,targetY:m.y+m.height/2,noteX:m.x+m.width+24,noteY:m.y+M+h.height/2},{...h,x:m.x-h.width-24,y:m.y+M,targetX:m.x,targetY:m.y+m.height/2,noteX:m.x-24,noteY:m.y+M+h.height/2},{...h,x:m.x,y:m.y+m.height+24+M,targetX:m.x+m.width/2,targetY:m.y+m.height,noteX:m.x+h.width/2,noteY:m.y+m.height+24+M})}p.push({...h,x:e.width+24,y:m.y,targetX:m.x+m.width,targetY:m.y+m.height/2,noteX:e.width+24,noteY:m.y+h.height/2});const S=Math.min(t.cornerRadius??0,m.width/2,m.height/2);for(let x=0;x<Math.max(4,e.notes.length+1);x++){const M=m.y+m.height+12+x*(h.height+12);for(const b of[true,false]){o();const C=m.x+(b?m.width:0),P=m.x+(b?Math.min(m.width*.75,m.width-S):Math.max(m.width*.25,S));p.push({...h,x:C-h.width/2,y:M,targetX:P,targetY:m.y+m.height,noteX:C,noteY:M})}}}else p.push({...h,x:n,y:e.height+16});let g=p.find(S=>{o();return S.x>=n&&S.y>=a&&u(S,f)});if(!g)g=p.find(S=>{o();return S.x<n&&S.y>=a&&u(S,f)});if(!g&&m&&!m.isInterface){const S=Math.min(t.cornerRadius??0,m.width/2,m.height/2);e:for(let x=0;x<Math.max(4,e.notes.length+1);x++)for(const M of[true,false]){o();const b=m.x+(M?m.width:0),C=m.x+(M?Math.min(m.width*.75,m.width-S):Math.max(m.width*.25,S)),P=m.y-h.height-12-x*(h.height+12),E={...h,x:b-h.width/2,y:P,targetX:C,targetY:m.y,noteX:b,noteY:P+h.height};if(u(E,f,true)){g=E;break e}}}if(!g)throw new Qe([{strategy:"class-owned-note",violations:[`No safe note seat for ${h.for??"unattached annotation"}`]}]);const y=Math.max(0,n-g.x),w=Math.max(0,a-g.y);if(!Number.isFinite(e.width+y)||!Number.isFinite(e.height+w))throw new Qe([{strategy:"class-owned-note",violations:["No finite leading room for note"]}]);for(const S of Object.keys(g))o();Object.assign(h,g);if(y>0||w>0){const S=[];for(const x of e.notes){o();const M=e.classes.find(C=>{o();return C.id===x.for});if(!M||M.isInterface||x.targetX===void 0||x.targetY===void 0)continue;const b=x.x>M.x+M.width?"E":x.x+x.width<M.x?"W":x.y>M.y+M.height?"S":x.y+x.height<M.y?"N":void 0;if(b){o();S.push({note:x,node:M,side:b})}}for(const x of e.classes){o();x.x+=y;x.y+=w;if(x.interfaceBox){o();x.interfaceBox.x+=y;x.interfaceBox.y+=w}}for(const x of e.namespaces){o();x.x+=y;x.y+=w}for(const x of e.notes){o();x.x+=y;x.y+=w;if(x.targetX!==void 0)x.targetX+=y;if(x.targetY!==void 0)x.targetY+=w;if(x.noteX!==void 0)x.noteX+=y;if(x.noteY!==void 0)x.noteY+=w}for(const x of e.relationships){o();for(const M of x.points){o();M.x+=y;M.y+=w}for(const M of[x.labelPosition,x.fromCardinalityPosition,x.toCardinalityPosition])if(M){o();M.x+=y;M.y+=w}}for(const x of l){o();x.x+=y;x.y+=w}for(const x of d){o();x.x+=y;x.y+=w}e.width+=y;e.height+=w;for(const{note:x,node:M,side:b}of S){o();const C=b==="E"||b==="S",P=b==="E"||b==="W"?"x":"y",E=M[P],k=P==="x"?M.width:M.height,v=C?vx(E,k):wt(E),T=C?wt(x[P]):vx(x[P],P==="x"?x.width:x.height);if(v===void 0||T===void 0)throw new Qe([{strategy:"class-owned-note",violations:["Exact note contact is not representable"]}]);if(P==="x"){x.targetX=v;x.noteX=T}else{x.targetY=v;x.noteY=T}}c=Oo(e,t,true,o,false)}e.width=Math.max(e.width,h.x+h.width+n);e.height=Math.max(e.height,h.y+h.height+n);if(e.title)e.title.x=e.width/2;if(!u(h,f))throw new Qe([{strategy:"class-owned-note",violations:["Unproved translated note seat"]}])}}function dD(e,t){const n=[],i=e.namespaces.map(d=>({id:d.id,x:d.x,y:d.y,width:d.width,height:d.headerHeight})),r=Oo(e,t,i.length>0||e.notes.length>0),o=t.lineWidth/2;for(const d of[...e.classes,...e.notes,...i])go(d);const s=new Map(e.classes.map(d=>[d.id,d]));const a=new Map;const l=[],c=[];for(let d=0;d<e.relationships.length;d++){const u=e.relationships[d];if(u.points.length<2){n.push(`Relationship ${u.from} -> ${u.to} has no visible route`);continue}for(const m of[true,false]){const p=s.get(m?u.from:u.to);if(!p){n.push("Undeclared Class endpoint");continue}if(p.isInterface)continue;const g=kn(m?u.points[0]:u.points.at(-1)),y=kn(m?u.points[1]:u.points.at(-2)),w=go(p),S=w.x+w.width,x=w.y+w.height;if(!(g.x===w.x&&g.y>=w.y&&g.y<=x&&y.x<g.x&&y.y===g.y||Xh(g.x,w.x,w.width,a)===0&&g.y>=w.y&&g.y<=x&&y.x>g.x&&y.y===g.y||g.y===w.y&&g.x>=w.x&&g.x<=S&&y.y<g.y&&y.x===g.x||Xh(g.y,w.y,w.height,a)===0&&g.x>=w.x&&g.x<=S&&y.y>g.y&&y.x===g.x))n.push(`Relationship ${u.from} -> ${u.to} lacks an outward Class contact`)}const f=[];const h=m=>f[m]??={emitted:kn(u.points[m])};for(let m=1;m<u.points.length;m++){const p=u.points[m-1],g=u.points[m];for(const y of i)if(dl(p,g,cl(y,o)))n.push(`Relationship ${u.from} -> ${u.to} enters namespace header ${y.id}`);for(const y of e.notes)if(nD(p,g,cl(y,o),2+o))n.push(`Relationship ${u.from} -> ${u.to} enters note ${y.for??""}`);for(let y=0;y<e.classes.length;y++){const w=e.classes[y];if(w.isInterface)continue;const S=m===1&&w.id===u.from||m===u.points.length-1&&w.id===u.to;const x=t.cornerRadius??0,M=S?l:c;const b=M[y]??={source:w,...S?{}:{inflation:o},radius:S?x:x+o};if(iD(h(m-1),h(m),b,a))n.push(`Relationship ${u.from} -> ${u.to} enters card ${w.id}`)}}}for(let d=0;d<r.length;d++){const u=r[d],f=e.relationships[u.edge];for(const h of i)if(u.kind==="marker"?Uh(u.pieces??[],h):Ex(u.box,h))n.push(`${u.kind} enters namespace header ${h.id}`);for(const h of e.notes)if(u.kind==="marker"?lD(u.pieces??[],h):Ex(u.box,h))n.push(`${u.kind} enters note ${h.for??""}`);if(u.kind!=="marker"){for(const h of e.classes)if(!h.isInterface&&Ex(u.box,h))n.push(`${u.kind} enters card ${h.id}`)}}return n}function uD(e,t,n,i){const r=new Map(n),o=Oo(e,t).filter(h=>h.kind==="marker"),s=new Map(e.namespaces.map(h=>[h.id,h])),a=new Map(e.namespaces.flatMap(h=>h.classIds.map(m=>[m,h.id])));for(const h of e.namespaces){const m={x:h.x,y:h.y,width:h.width,height:h.headerHeight},p=e.relationships.some(y=>uu(y.points,m))?Tx+t.lineWidth/2:0,g={...m,height:m.height+p};for(const y of o){if(!Uh(y.pieces??[],g))continue;const w=e.relationships[y.edge],S=y.endpoint==="from"?w.from:w.to,x=e.classes.find(C=>C.id===S);let M=a.get(S);for(let C=0;M&&M!==h.id&&C<=s.size;C++)M=s.get(M)?.parentId;if(M!==h.id||!x||x.y<m.y+m.height)continue;const b=m.y+m.height+p-y.box.y;if(b>0&&Number.isFinite(b))r.set(h.id,Math.max(r.get(h.id)??t.groupPaddingY,Math.ceil((n.get(h.id)??t.groupPaddingY)+b)))}}const l=wt(t.lineWidth)/2;if(!(l>0))return r;const c=()=>{if(i&&!ri(i))throw new Qe([{strategy:"class-header-capacity",violations:["Class header capacity proof work limit"]}])},d=new Map(e.classes.map(h=>{c();return[h.id,h]})),u=new Map(o.map(h=>{c();return[`${h.edge}:${h.endpoint}`,h]})),f=new Map;for(let h=0;h<e.relationships.length;h++){const m=e.relationships[h];for(const p of[true,false]){c();const g=d.get(p?m.from:m.to);if(!g||g.isInterface||m.points.length<2)continue;const y=p?m.points[0]:m.points.at(-1),w=p?m.points[1]:m.points.at(-2);if(ys(y.y,g.y,0)!==0||wt(w.x)!==wt(y.x)||wt(w.y)>=wt(y.y))continue;let S=l;const x=u.get(`${h}:${p?"from":"to"}`);for(const P of x?.pieces??[]){c();if(P.kind==="circle")S=Math.max(S,wt(y.y)-P.cy+P.r);else for(const E of P.points){c();S=Math.max(S,wt(y.y)-E.y)}}const M=Math.max(0,t.edgeBendRadius);let b=wt(y.y)-S-Math.min(M,l+S),C=a.get(g.id);for(let P=0;C&&P<=s.size;P++){c();const E=s.get(C);const k={x:E.x,y:E.y,width:E.width,height:E.headerHeight};if(uu(m.points,cl(k,l))){const v=b-wt(E.y)-wt(E.headerHeight),T=f.get(C);f.set(C,{count:(T?.count??0)+1,free:Math.min(T?.free??Infinity,v)});b=wt(E.y)-M-l}C=E.parentId}}}for(const[h,m]of f){c();const p=Math.ceil(m.count/2),g=Tx+2*l+(p-1)*Math.max(1,wt(t.lineWidth));if(m.free<g){const y=Math.ceil((n.get(h)??t.groupPaddingY)+g-m.free);if(Number.isFinite(y))r.set(h,Math.max(r.get(h)??t.groupPaddingY,y))}}return r}function gs(){return{operations:0,pairs:0,exhausted:false}}function ri(e){if(e.exhausted||e.operations>=Ps){e.exhausted=true;return false}e.operations++;return true}var fD=(e,t)=>e.x0<=t.x&&t.x<=e.x1&&e.y0<=t.y&&t.y<=e.y1;var BU=(e,t)=>e.x0<t.x1&&t.x0<e.x1&&e.y0<t.y1&&t.y0<e.y1;function hD(e,t,n,i=gs()){if(t.edgeBendRadius>0||i.exhausted)return;const r=()=>ri(i);const o=hm();const s=u=>o(u,n);const a=Xn("stroke-width",String(t.lineWidth)),l=Do(t),c=[];for(let u=0;u<e.relationships.length;u++){if(!r())return;const f=e.relationships[u];if(f.points.length<2)continue;const h=f.markerAt==="from"||f.markerAt==="both"?l.find(x=>x.id===Pi(f.fromType??f.type)):void 0;const m=f.markerAt==="to"||f.markerAt==="both"?l.find(x=>x.id===Pi(f.toType??f.type)):void 0;if(!h&&!m)continue;const p={x:Number(Xe(f.points[0].x)),y:Number(Xe(f.points[0].y))},g={x:Number(Xe(f.points.at(-1).x)),y:Number(Xe(f.points.at(-1).y))};let y=p,w=g;for(let x=1;x<f.points.length;x++){if(!r())return;const M=f.points[x],b=Number(Xe(M.x)),C=Number(Xe(M.y));if(b!==p.x||C!==p.y){y={x:b,y:C};break}}for(let x=f.points.length-2;x>=0;x--){if(!r())return;const M=f.points[x],b=Number(Xe(M.x)),C=Number(Xe(M.y));if(b!==g.x||C!==g.y){w={x:b,y:C};break}}const S=Wo({id:`class-marker-proof:${u}`,role:"chrome",owner:{id:`relationship:${u}`,role:"relationship"},geometry:{kind:"polyline",points:[p,y,w,g]},lineStyle:"solid",paint:{fill:"none",stroke:t.edgeStrokeColor??"var(--_line)",strokeWidth:a},stroke:{opacity:0},endpoints:{from:f.from,to:f.to},markers:{...h?{start:h}:{},mid:[],...m?{end:m}:{}}});for(const x of Yr(S)){if(!r()||!x.bounds)return;const M=x.position==="start"?h:x.position==="end"?m:void 0;const b=lb({colors:n},S,M,x.position,r,s);if(i.exhausted)return;c.push({owner:`relationship ${u} ${f.from}->${f.to} ${x.position}`,bounds:x.bounds,proof:b})}}if(c.length<2)return;if(e.relationships.some(u=>!!u.label&&!u.labelPosition))return;const d=Oo(e,t,false).map(u=>({x0:u.box.x,y0:u.box.y,x1:u.box.x+u.box.width,y1:u.box.y+u.box.height}));for(const u of e.notes){if(!r())return;d.push({x0:u.x-1,y0:u.y-1,x1:u.x+u.width+1,y1:u.y+u.height+1});if(u.targetX!==void 0&&u.targetY!==void 0){const f=u.noteX??u.x,h=u.noteY??u.y+u.height/2;d.push({x0:Math.min(u.targetX,f)-1,y0:Math.min(u.targetY,h)-1,x1:Math.max(u.targetX,f)+1,y1:Math.max(u.targetY,h)+1})}}for(let u=0;u<c.length;u++)for(let f=u+1;f<c.length;f++){if(!r())return;const h=c[u],m=c[f];if(!BU(h.bounds,m.bounds))continue;if(i.pairs>=Go){i.exhausted=true;return}i.pairs++;let p=0;while(h.proof&&p<h.proof.strokeWitnesses.length){const g=cb(h.proof,m.proof,r,p);if(i.exhausted)return;if(typeof g==="string")break;let y=p;for(;y<h.proof.strokeWitnesses.length;y++){if(!r())return;if(h.proof.strokeWitnesses[y]===g)break}if(y===h.proof.strokeWitnesses.length)return;p=y+1;let w=false;for(let S=f+1;S<c.length;S++){if(!r())return;if(fD(c[S].bounds,g)){w=true;break}}if(!w)for(const S of d){if(!r())return;if(fD(S,g)){w=true;break}}if(!w)throw new Qe([{strategy:"class-marker-meaning",violations:[`Later marker ${m.owner} covers actual stroke ink of ${h.owner}`]}])}}}var yo=e=>Number(Xe(e));var zk=(e,t)=>e.x<t.x+t.width&&t.x<e.x+e.width&&e.y<t.y+t.height&&t.y<e.y+e.height;var Gk=(e,t)=>{const n=yo(e.block.width),i=yo(e.block.height),r=lu/2;return{x:t.x-n/2-r,y:t.y-i/2-r,width:n+2*r,height:i+2*r}};var mD=(e,t)=>({x:yo(e.x),y:yo(e.y-(t==="caption"?sa:0))});function Hk(e,t,n,i){if(!e.relationships.some(f=>f.markerAt!=="none")&&!i?.size||!e.relationships.some(f=>f.label||f.fromCardinality||f.toCardinality))return;const r=()=>{if(!ri(n))throw new Qe([{strategy:"class-owned-annotation",violations:["Class annotation proof work limit"]}])};const o=[];for(const[f,h]of e.relationships.entries()){r();if(h.points.length<2)continue;const m=(p,g,y)=>{if(!g||!y.text)return;r();o.push({rel:h,edge:f,role:p,original:g,block:y,center:mD(g,p)})};if(h.label)m("caption",cu(h),h.labelBlock??ui(qe(h.label,h.labelContent),t,"edge"));for(const p of["from","to"])if(h[`${p}Cardinality`])m(p,Tc(h,p),h[`${p}CardinalityBlock`]??Be(qe(h[`${p}Cardinality`],h[`${p}CardinalityContent`]),{fontSize:t.edgeLabelFontSize,fontWeight:t.edgeLabelFontWeight,letterSpacing:t.edgeLetterSpacing}))}const s=Oo(e,t,true,r,false).filter(f=>{r();return f.kind==="marker"});const a=[];if(e.title){r();const f=e.title,h=f.block??tn(f.text,t)?.block;if(h)a.push({x:yo(f.x)-yo(h.width)/2,y:yo(f.y)-yo(h.height)/2,width:yo(h.width),height:yo(h.height)})}for(const f of e.classes){r();if(!f.isInterface)a.push({x:f.x-1,y:f.y-1,width:f.width+2,height:f.height+2});else{if(f.interfaceBox)a.push(f.interfaceBox);const h=f.labelBlock;if(h)a.push({x:f.x+(f.width-h.width)/2,y:f.y+f.headerHeight/2-h.height/2,width:h.width,height:h.height})}}for(const f of e.namespaces){r();a.push({x:f.x,y:f.y,width:f.width,height:f.headerHeight})}for(const f of e.notes){r();a.push(f)}const l=(f,h)=>{r();const m=Gk(f,h);if(f.role==="caption"&&i?.has(f.edge)){const p={x:m.x-8,y:m.y-8,width:m.width+16,height:m.height+16};let g=false;for(let y=1;y<f.rel.points.length;y++){r();if(dl(f.rel.points[y-1],f.rel.points[y],p)){g=true;break}}if(!g)return false}if(m.x<0||m.y<0||m.x+m.width>e.width||m.y+m.height>e.height)return false;for(const p of a){r();if(zk(m,p))return false}for(const p of e.notes){r();if(p.targetX!==void 0&&p.targetY!==void 0&&dl({x:p.targetX,y:p.targetY},{x:p.noteX??p.x,y:p.noteY??p.y+p.height/2},{x:m.x-.5,y:m.y-.5,width:m.width+1,height:m.height+1}))return false}for(const p of s){r();if(zk(m,p.box))return false}return true};const c=(f,h,m)=>{r();return!zk(Gk(f,h),Gk(m,m.next??m.center))};for(const f of o){if(!l(f,f.center))continue;f.fixed=true;for(const h of o)if(h!==f&&!c(f,f.center,h)){f.fixed=false;break}}const d=o.filter(f=>{r();return f.fixed});const u=(f,h)=>{if(!l(f,h))return false;for(const m of d)if(!c(f,h,m))return false;f.next=h;d.push(f);return true};for(const f of o){r();if(f.fixed)continue;if(u(f,f.center))continue;let h=false,m=0;if(f.role!=="caption"){const p=f.role==="from",g=f.rel.points,y=p?g[0]:g.at(-1),w=p?g[1]:g.at(-2);const S=[];for(const x of kx(y,w)){r();const M=mD(x,f.role);S.push({point:M,distance:(M.x-f.center.x)**2+(M.y-f.center.y)**2,order:S.length})}S.sort((x,M)=>{r();return x.distance-M.distance||x.order-M.order});for(const{point:x}of S){r();if(++m>Ak)break;if(u(f,x)){h=true;break}}}else{const p=[];for(let g=1;g<f.rel.points.length;g++){r();const y=f.rel.points[g-1],w=f.rel.points[g],S=w.x-y.x,x=w.y-y.y,M=S*S+x*x?Math.max(0,Math.min(1,((f.center.x-y.x)*S+(f.center.y-y.y)*x)/(S*S+x*x))):0;p.push({a:y,b:w,index:g,distance:(f.center.x-y.x-S*M)**2+(f.center.y-y.y-x*M)**2})}p.sort((g,y)=>{r();return g.distance-y.distance||g.index-y.index});e:for(const{a:g,b:y}of p){r();if(g.x!==y.x&&g.y!==y.y)continue;for(const w of[.5,1/3,2/3,.25,.75,1/6,5/6])for(const S of[-1,1]){r();if(++m>Ak)break e;const x=g.x===y.x,M={x:yo(g.x+(y.x-g.x)*w+(x?S*(f.block.width/2+sa):0)),y:yo(g.y+(y.y-g.y)*w+(x?0:S*sa))};if(u(f,M)){h=true;break e}}}}if(!h)throw new Qe([{strategy:"class-owned-annotation",violations:[`No separated ${f.role} text seat for ${f.rel.from} -> ${f.rel.to} in the existing bounded candidates`]}])}for(const f of o){const h=f.next??f.center;if(!l(f,h))throw new Qe([{strategy:"class-owned-annotation",violations:["Unproved final annotation seat"]}]);for(const m of o)if(m!==f&&!c(f,h,m))throw new Qe([{strategy:"class-owned-annotation",violations:["Unproved final text separation"]}])}for(const f of o)r();for(const f of o){if(!f.next||f.next.x===f.center.x&&f.next.y===f.center.y)continue;const h={x:f.next.x,y:f.next.y+(f.role==="caption"?sa:0)};if(f.role==="caption")f.rel.labelPosition=h;else f.rel[`${f.role}CardinalityPosition`]=h}}var aa=(e,t=1)=>{for(let n=0;n<t;n++)if(e&&!ri(e))throw new Qe([{strategy:"class-elk-contact",violations:["Class contact projection proof work limit"]}])};function pD(e,t,n){if(t.edgeBendRadius!==0||t.cornerRadius!==0)return;let i;aa(n,2);const r=(a=1)=>aa(n,a);const o=a=>{r(2);const l=String(a);r(l.length);return Number(Xe(a))};const s=(a,l,c)=>{r(2048);return ys(a,l,c)};for(let a=0;a<e.relationships.length;a++){r(8);const l=e.relationships[a];if(l.from!==l.to||l.markerAt!=="none"||l.label!==void 0||l.fromCardinality!==void 0||l.toCardinality!==void 0||l.points.length!==4)continue;const c=l.points[0],d=l.points[1],u=l.points[2],f=l.points[3];if((c.x===d.x||c.y===d.y)&&(u.x===f.x||u.y===f.y))continue;let h;for(const T of e.classes){r();if(T.id===l.from){h=T;break}}if(!h||h.isInterface)continue;r(32);if(![c.x,c.y,d.x,d.y,u.x,u.y,f.x,f.y,h.x,h.y,h.width,h.height,t.lineWidth].every(Number.isFinite)||!(h.width>0&&h.height>0&&t.lineWidth>0))continue;r(12);const m={x:o(c.x),y:o(c.y)},p={x:o(d.x),y:o(d.y)},g={x:o(u.x),y:o(u.y)},y={x:o(f.x),y:o(f.y)};if((m.x===p.x||m.y===p.y)&&(g.x===y.x||g.y===y.y))continue;const w=o(h.x),S=o(h.y),x=o(h.width),M=o(h.height);let b,C=0;if(m.x===y.x&&m.y>S&&y.y>S&&s(m.y,S,M)<0&&s(y.y,S,M)<0){if(m.x===w){b="x";C=-1}else if(s(m.x,w,x)===0){b="x";C=1}}else if(m.y===y.y&&m.x>w&&y.x>w&&s(m.x,w,x)<0&&s(y.x,w,x)<0){if(m.y===S){b="y";C=-1}else if(s(m.y,S,M)===0){b="y";C=1}}if(!b)continue;const P=b==="x"?"y":"x";r(10);if(p[b]!==g[b]||Math.sign(p[b]-m[b])!==C||m[P]===y[P]||Math.sign(g[P]-p[P])!==Math.sign(y[P]-m[P]))continue;if(m[P]===p[P]&&g[P]===y[P])continue;r(4);if(Dd(Xe(m[P]),Xe(y[P]),Xe(o(t.lineWidth)),r,r)!==false)continue;r(13);const E={x:d.x,y:d.y},k={x:u.x,y:u.y};E[P]=c[P];k[P]=f[P];k[b]=E[b];const v=[c,E,k,f];if(!i){r();i=new Set}l.points=v;i.add(a)}return i}function gD(e,t,n,i){if(!n?.size)return;aa(i);const r=(l=1)=>aa(i,l);const o=()=>{throw new Qe([{strategy:"class-elk-contact",violations:["Constructed Class self contact has unproved final support"]}])};r(2);const s=Number(Xe(t.lineWidth));r(512);for(const l of e.relationships){r(128);for(const c of l.points){r(8);const d=String(c.x),u=String(c.y);r(4*(d.length+u.length))}if(l.markerAt==="from"||l.markerAt==="both")r(4096);if(l.markerAt==="to"||l.markerAt==="both")r(4096)}const a=Oo(e,t,true,r,false);for(const l of n){r();const c=e.relationships[l].points;if(c.length!==4)o();r(18);const d=c.map(y=>{r(2);const w=String(y.x),S=String(y.y);r(w.length+S.length);return{x:Number(Xe(y.x)),y:Number(Xe(y.y))}});const u=d[0],f=d[1],h=d[2],m=d[3],p=u.x===f.x;r(8);if(p?f.y!==h.y||h.x!==m.x||u.y!==m.y||u.x===m.x||u.y===f.y:u.y!==f.y||f.x!==h.x||h.y!==m.y||u.x!==m.x||u.y===m.y||u.x===f.x)o();r(4);if(Dd(Xe(p?u.x:u.y),Xe(p?m.x:m.y),Xe(s),r,r)!==false)o();r(4);const g=[];for(let y=1;y<d.length;y++){r(3);g.push(Ok([d[y-1],d[y]],s,r))}for(const y of a){r();for(const w of g){r();if(Bk(w,y.box,r))o()}}}}function yD(e,t){const n=new Map(e.classes.map(r=>{aa(t);return[r.id,r]})),i=[];for(const r of e.relationships)for(const o of[true,false]){aa(t);const s=n.get(o?r.from:r.to);if(!s||s.isInterface||r.points.length<2)continue;const a=o?r.points[0]:r.points.at(-1),l=o?r.points[1]:r.points.at(-2);let c;if(a.x===s.x+s.width&&l.x>a.x&&l.y===a.y&&a.y>s.y&&a.y<s.y+s.height)c="x";else if(a.y===s.y+s.height&&l.y>a.y&&l.x===a.x&&a.x>s.x&&a.x<s.x+s.width)c="y";if(c)i.push({node:s,relation:r,from:o,axis:c})}return i}function Lx(e,t){const n=[];for(const{node:i,relation:r,from:o,axis:s}of e){aa(t);const a=o?r.points[0]:r.points.at(-1),l=o?r.points[1]:r.points.at(-2),c=s==="x"?"y":"x",d=s==="x"?i.width:i.height;if(ys(a[s],i[s],d)===0)continue;const u=vx(i[s],d);if(u===void 0)throw new Qe([{strategy:"class-elk-contact",violations:["Exact written Class rectangle face is not representable"]}]);if(!(Number(Xe(l[s]))>u)||Number(Xe(l[c]))!==Number(Xe(a[c])))throw new Qe([{strategy:"class-elk-contact",violations:["Written Class contact has no outward lead"]}]);aa(t);n.push({point:a,axis:s,value:u})}for(const i of n)aa(t);for(const{point:i,axis:r,value:o}of n)i[r]=o}function xD(e,t){const n=Do(t).map(i=>({id:i.id,start:zo(i,{x:0,y:0},{x:1,y:0},"start",t.lineWidth),end:zo(i,{x:0,y:0},{x:-1,y:0},"end",t.lineWidth)}));return e.map(i=>{const r=i.markerAt==="from"||i.markerAt==="both"?i.fromType??i.type:void 0;const o=i.markerAt==="to"||i.markerAt==="both"?i.toType??i.type:void 0;const s=r?n.find(l=>l.id===Pi(r))?.start:void 0;const a=o?n.find(l=>l.id===Pi(o))?.end:void 0;return{...s?.length?{start:s}:{},...a?.length?{end:a}:{}}})}function bD(e,t,n){const i=()=>ri(n),r=u=>{for(let f=0;f<u;f++)if(!i())return false;return true};const o=Number.parseFloat(Xn("stroke-width",String(t.lineWidth)));if(!(o>0)||!Number.isFinite(o)||!r(5))return new Map;const s=Do(t),a=new Map,l=new Map,c=new Map,d=new Map;for(const u of e.classes){if(!i())return new Map;if(!u.isInterface)l.set(u.id,u)}for(const u of e.relationships)for(const f of["from","to"]){if(!i())return new Map;const h=l.get(u[f]),m=u.points;if(!h||m.length<2)continue;const p=f==="from"?m[0]:m.at(-1),g={x:Number(Xe(p.x)),y:Number(Xe(p.y))};let y=g;for(let T=1;T<m.length;T++){if(!i())return new Map;const A=m[f==="from"?T:m.length-T-1],R={x:Number(Xe(A.x)),y:Number(Xe(A.y))};if(R.x!==g.x||R.y!==g.y){y=R;break}}const w=y.x-g.x,S=y.y-g.y;let x;if(S===0&&w<0&&ys(g.x,h.x,0)===0)x="W";else if(S===0&&w>0&&ys(g.x,h.x,h.width)===0)x="E";else if(w===0&&S<0&&ys(g.y,h.y,0)===0)x="N";else if(w===0&&S>0&&ys(g.y,h.y,h.height)===0)x="S";if(!x)continue;const M=x==="W"||x==="E",b=u.markerAt==="both"||u.markerAt===f,C=b?Pi((f==="from"?u.fromType:u.toType)??u.type):null,P=`${f}:${x}:${C??""}`;let E=a.get(P);if(!E){let T=-o/2,A=o/2;let R;if(C)for(const I of s){if(!i())return new Map;if(I.id===C){R=I;break}}if(R){const I={x:x==="E"?1:x==="W"?-1:0,y:x==="S"?1:x==="N"?-1:0},L=f==="from"?I:{x:-I.x,y:-I.y};const $={};let B;try{B=zo(R,{x:0,y:0},L,f==="from"?"start":"end",o,()=>{if(!i())throw $})}catch(F){if(F===$)return new Map;throw F}for(const F of B){if(!i())return new Map;if(F.kind==="circle"){const z=M?F.cy:F.cx;T=Math.min(T,z-F.r);A=Math.max(A,z+F.r)}else for(const z of F.points){if(!i())return new Map;const _=M?z.y:z.x;T=Math.min(T,_);A=Math.max(A,_)}}}a.set(P,E={low:T,high:A})}let k=c.get(h.id);if(!k)c.set(h.id,k=new Map);let v=k.get(x);if(!v)k.set(x,v=[]);v.push({along:M?g.y-h.y:g.x-h.x,low:E.low,high:E.high,marker:C})}for(const[u,f]of c){if(!i())return new Map;const h=l.get(u);let m=h.width,p=h.height;for(const[g,y]of f){if(!i())return new Map;let w=false;for(const T of y){if(!i())return new Map;w||=T.marker!==null}if(!w)continue;const S={};try{y.sort((T,A)=>{if(!i())throw S;return T.along-A.along})}catch(T){if(T===S)return new Map;throw T}const x=y[0],M=y.at(-1),b=g==="W"||g==="E"?h.height:h.width,C=Math.max(0,t.cornerRadius??0),P=Math.min(C,h.width/2,h.height/2);let E=x.along<Math.max(-x.low,P)||b-M.along<Math.max(M.high,P),k=Math.max(-x.low,M.high,C);for(let T=1;T<y.length;T++){if(!i())return new Map;const A=y[T-1],R=y[T],I=A.high-R.low;E||=R.along-A.along<I;k=Math.max(k,I)}if(!E)continue;const v=Math.ceil((y.length+1)*k);if(!Number.isSafeInteger(v)||v<0)throw new Qe([{strategy:"class-marker-capacity",violations:["Nonfinite Class marker face reservation"]}]);if(g==="W"||g==="E")p=Math.max(p,v);else m=Math.max(m,v)}if(m>h.width||p>h.height)d.set(u,{width:m,height:p})}return d}function SD(e,t,n,i,r,o){const s=(c=1)=>{for(let d=0;d<c;d++)if(!ri(o))throw new Qe([{strategy:"class-native-marker-capacity",violations:["Class marker capacity work limit"]}])};s(3);const a=new Map,l=new Map;for(const c of e){s(5);if(!c.isInterface)a.set(c.id,{count:0,low:-i/2,high:i/2,marked:false})}for(let c=0;c<t.length;c++)for(let d=0;d<2;d++){s(8);const u=t[c],f=a.get(d===0?u.from:u.to);if(!f)continue;f.count++;const h=d===0?n[c]?.start:n[c]?.end;if(!h?.length)continue;f.marked=true;for(const m of h){s();if(m.kind==="circle"){s(4);f.low=Math.min(f.low,m.cy-m.r);f.high=Math.max(f.high,m.cy+m.r)}else for(const p of m.points){s(3);f.low=Math.min(f.low,p.y);f.high=Math.max(f.high,p.y)}}}for(const[c,d]of a){s(7);if(!d.marked)continue;const u=d.high-d.low+i,f=Math.ceil((d.count+1)*u);if(!Number.isSafeInteger(f)||f<=0)throw new Qe([{strategy:"class-native-marker-capacity",violations:["Nonfinite Class marker face reservation"]}]);s(4);l.set(c,{width:r==="LR"||r==="RL"?0:f,height:r==="LR"||r==="RL"?f:0,portSpacing:u})}return l}var Vt={padding:40,boxPadX:8,headerBaseHeight:32,annotationHeight:16,memberRowHeight:20,sectionPadY:8,emptySectionHeight:8,minWidth:120,memberFontSize:11,memberFontWeight:400,nodeSpacing:40,layerSpacing:60};var Ax={nodeLabelFontSize:nr.nodeLabel,edgeLabelFontSize:nr.edgeLabel,groupHeaderFontSize:nr.groupHeader,nodeLabelFontWeight:700,edgeLabelFontWeight:Fr.edgeLabel,groupHeaderFontWeight:Fr.groupHeader,nodePaddingX:Vt.boxPadX,nodePaddingY:Vt.sectionPadY,nodeCornerRadius:0,nodeLineWidth:et.outerBox,edgeLineWidth:et.connector,groupCornerRadius:0,groupPaddingX:Vt.boxPadX,groupPaddingY:Vt.sectionPadY,groupLineWidth:et.outerBox};function CD(e,t){if(!e)return t;const n=Bd(e,"class","nodeSpacing");const i=Bd(e,"class","rankSpacing");const r=Mt(e,["class","hierarchicalNamespaces"]);const o=t.class?.hierarchicalNamespaces??(typeof r==="boolean"?r:void 0);if(n===void 0&&i===void 0&&o===void 0)return t;return{...t,nodeSpacing:t.nodeSpacing??n,layerSpacing:t.layerSpacing??i,...o!==void 0?{class:{...t.class,hierarchicalNamespaces:o}}:{}}}function ui(e,t,n,i){return n==="node"?Be(e,{transform:t.nodeTextTransform,fontSize:t.nodeLabelFontSize,fontWeight:t.nodeLabelFontWeight,letterSpacing:t.nodeLetterSpacing,maxWidth:i}):n==="edge"?Be(e,{transform:t.edgeTextTransform,fontSize:t.edgeLabelFontSize,fontWeight:t.edgeLabelFontWeight,letterSpacing:t.edgeLetterSpacing,maxWidth:i}):Be(e,{transform:t.groupTextTransform,fontSize:t.groupHeaderFontSize,fontWeight:t.groupHeaderFontWeight,letterSpacing:t.groupLetterSpacing,fontFamily:t.groupFont,maxWidth:i})}function Vh(e){return Be(PD(Df(e),e.isAbstract),{display:"literal",fontSize:Vt.memberFontSize,fontWeight:400,monospace:true})}function PD(e,t=false){const n=Rt(e,"literal");return t?{...n,lines:n.lines.map(i=>i.map(r=>({...r,italic:true})))}:n}function Ix(e){return Be(PD(`<<${e}>>`,true),{display:"literal",fontSize:10,fontWeight:500})}var ED="ns:";function Fx(e,t,n=true){const i=[];for(const r of e){const o=t?`${t.path}.${r.name}`:r.name;const s={path:o,parentPath:n?t?.path:void 0,ns:!n&&r.label===void 0?{...r,label:o}:r,ancestors:n&&t?[...t.ancestors,o]:[o]};if(n||r.classIds.length>0||r.label!==void 0||r.children.length===0)i.push(s);i.push(...Fx(r.children,s,n))}return i}function jk(e,t){const n=t===void 0?1:t.split("\n").length;return e.groupHeaderFontSize+16+(n-1)*e.groupHeaderFontSize*hi}function WU(e,t){const n=new Map;for(const i of e.classes){const r=ui(qe(i.label,i.labelContent),t,"node");if(i.isInterface){const p=r.height+2*Math.max(16,t.nodePaddingY);n.set(i.id,{width:r.width+2*Math.max(16,t.nodePaddingX),height:p,headerHeight:p,attrHeight:0,methodHeight:0});continue}const o=Math.max(Vt.headerBaseHeight,r.height+t.nodePaddingY*2);const s=i.annotation!==void 0?o+Vt.annotationHeight:o;const a=i.attributes.length>0?i.attributes.length*Vt.memberRowHeight+t.nodePaddingY:Vt.emptySectionHeight;const l=i.methods.length>0?i.methods.length*Vt.memberRowHeight+t.nodePaddingY:Vt.emptySectionHeight;const c=i.annotation===void 0?0:Ix(i.annotation).width;const d=Math.max(r.width,c);const u=kD(i.attributes);const f=kD(i.methods);const h=Math.max(Vt.minWidth,d+t.nodePaddingX*2,u+t.nodePaddingX*2,f+t.nodePaddingX*2);const m=s+a+l;n.set(i.id,{width:h,height:m,headerHeight:s,attrHeight:a,methodHeight:l})}return n}function RD(e,t){let n=0;for(const i of e.relationships){const r=vc(i,t);n=Math.max(n,r.start,r.end)}return n?n+t.edgeBendRadius:0}function zU(e,t,n,i,r=new Map,o=new Map){const s=Ue(t,Ax,i);const a=t.nodeSpacing??Vt.nodeSpacing;const l=t.layerSpacing??Vt.layerSpacing;const c=t.class?.hierarchicalNamespaces!==false;const d=Fx(e.namespaces,void 0,c);const u=d.length>0;const f=RD(e,s);const h={"elk.spacing.edgeNode":String(f),"elk.layered.spacing.edgeNodeBetweenLayers":String(f),"elk.algorithm":"layered","elk.direction":ba(e.direction??"TB"),"elk.spacing.nodeNode":String(a),"elk.layered.spacing.nodeNodeBetweenLayers":String(l),"elk.padding":`[top=${Vt.padding},left=${Vt.padding},bottom=${Vt.padding},right=${Vt.padding}]`,"elk.edgeRouting":"ORTHOGONAL","elk.edgeLabels.placement":"CENTER"};if(u)h["elk.hierarchyHandling"]="INCLUDE_CHILDREN";const m={id:"root",layoutOptions:h,children:[],edges:[]};const p=new Map;for(const S of d){for(const x of S.ns.classIds){if(!p.has(x))p.set(x,S)}}const g=yi(e.classes.map(S=>S.id));const y=new Map;const w=new Map;for(const S of d){const x=ui(qe(S.ns.label??S.ns.name,S.ns.labelContent),s,"group");const M=jk(s,r.get(S.path)??x.text);const b={id:g(ED+S.path,["class","elk-namespace",S.path]),layoutOptions:{"elk.padding":`[top=${M+Math.max(s.groupPaddingY,o.get(S.path)??0)},left=${s.groupPaddingX+8},bottom=${s.groupPaddingY+8},right=${s.groupPaddingX+8}]`,"elk.spacing.nodeNode":String(a),"elk.layered.spacing.nodeNodeBetweenLayers":String(l),"elk.edgeRouting":"ORTHOGONAL","elk.spacing.edgeNode":String(f),"elk.layered.spacing.edgeNodeBetweenLayers":String(f),"elk.edgeLabels.placement":"CENTER"},children:[],edges:[]};y.set(b.id,{...S,headerHeight:M,labelWidth:x.width});w.set(S.path,b);const C=S.parentPath?w.get(S.parentPath):m;C.children.push(b)}for(const S of e.classes){const x=n.get(S.id);const M={id:S.id,width:x.width,height:x.height};const b=p.get(S.id);(b?w.get(b.path):m).children.push(M)}for(const S of y.values()){const x=w.get(S.path);if(x.children.length)continue;x.width=S.labelWidth+2*Math.max(s.groupLabelPaddingX,s.groupPaddingX+8);x.height=S.headerHeight+2*s.groupPaddingY+8}for(let S=0;S<e.relationships.length;S++){const x=e.relationships[S];const M={id:`e${S}`,sources:[x.from],targets:[x.to]};if(x.label){const E=ui(qe(x.label,x.labelContent),s,"edge");if(E.lineBlocks.some(k=>k.runs.some(v=>v.text.trim().length>0))){M.labels=[{text:E.text,width:E.width+8,height:E.height+6}]}}const b=p.get(x.from)?.ancestors??[];const C=p.get(x.to)?.ancestors??[];let P;for(let E=0;E<Math.min(b.length,C.length);E++){if(b[E]===C[E])P=b[E];else break};(P?w.get(P):m).edges.push(M)}return{elkGraph:m,namespaceLayouts:y}}function GU(e,t){const n=[],i=new Map;const r=(o,s,a)=>{for(const l of o.edges??[]){const c=[];if(l.sections&&l.sections.length>0){const f=l.sections[0];c.push({x:f.startPoint.x+s,y:f.startPoint.y+a});for(const h of f.bendPoints??[]){c.push({x:h.x+s,y:h.y+a})}c.push({x:f.endPoint.x+s,y:f.endPoint.y+a})}let d;const u=l.labels?.[0];if(u&&u.x!=null&&u.y!=null){d={x:u.x+(u.width??0)/2+s,y:u.y+(u.height??0)/2+a}}i.set(Number(l.id.slice(1)),{points:Qs(c),labelPosition:d})}for(const l of o.children??[]){const c=(l.x??0)+s,d=(l.y??0)+a;const u=t.get(l.id)?.path;n.push({id:l.id,x:c,y:d,width:l.width,height:l.height,...u!==void 0?{namespacePath:u}:{}});if(u!==void 0)r(l,c,d)}};r(e,0,0);return{width:e.width,height:e.height,nodes:n,routes:i,namespaceLayouts:t}}function vD(e,t){const n=t.isInterface?void 0:e.classDefs.get("default"),i=t.className?e.classDefs.get(t.className):void 0;if(!n&&!i&&!t.inlineStyle)return void 0;return{...Tt(n,"classDef default"),...Tt(i,`classDef ${t.className}`),...Tt(t.inlineStyle,`style ${t.id}`)}}function wD(e,t,n,i,r,o=new Map){const s=new Map;for(const w of t.classes)s.set(w.id,w);const a=e.namespaceLayouts?void 0:new Map(Fx(t.namespaces,void 0,r).map(w=>[w.path,w]));const l=[];const c=[];const d=e.routes;for(const w of e.nodes){const{x:S,y:x}=w;if(w.namespacePath!==void 0){const b=w.namespacePath;const C=e.namespaceLayouts?.get(w.id);const P=C??a?.get(b);c.push({id:b,name:P?.ns.name??b,label:P?.ns.label??P?.ns.name??b,...P?.ns.labelContent?{labelContent:P.ns.labelContent}:{},parentId:P?.parentPath,classIds:P?[...P.ns.classIds]:[],x:S,y:x,width:w.width??0,height:w.height??0,headerHeight:C?.headerHeight??jk(i,o.get(b)??ui(qe(P?.ns.label??P?.ns.name??b,P?.ns.labelContent),i,"group").text),...o.has(b)?{title:o.get(b)}:{}});continue}const M=s.get(w.id);if(M){const b=n.get(M.id),C=vD(t,M);l.push({id:M.id,...M.isInterface?{isInterface:true}:{},label:M.label,...M.labelContent?{labelContent:M.labelContent}:{},annotation:M.annotation,attributes:M.attributes,methods:M.methods,x:S,y:x,width:w.width??b.width,height:w.height??b.height,headerHeight:b.headerHeight,attrHeight:b.attrHeight,methodHeight:b.methodHeight+Math.max(0,(w.height??b.height)-b.height),...M.className?{className:M.className}:{},...M.href?{href:M.href}:{},...M.tooltip!==void 0?{tooltip:M.tooltip}:{},...C?{inlineStyle:C}:{}})}}const u=[];for(let w=0;w<t.relationships.length;w++){const S=t.relationships[w];const x=d.get(w);u.push({from:S.from,to:S.to,type:S.type,lineStyle:S.lineStyle,markerAt:S.markerAt,fromType:S.fromType,toType:S.toType,label:S.label,...S.labelContent?{labelContent:S.labelContent}:{},fromCardinality:S.fromCardinality,...S.fromCardinalityContent?{fromCardinalityContent:S.fromCardinalityContent}:{},toCardinality:S.toCardinality,...S.toCardinalityContent?{toCardinalityContent:S.toCardinalityContent}:{},points:x?.points??[],labelPosition:x?.labelPosition})}let f=e.width??600;let h=e.height??400;TD(u,l,i,f,h);const m=l.map(w=>({x:w.x,y:w.y,width:w.width,height:w.height}));const p=(w,S,x=8)=>w.x<S.x+S.width+x&&w.x+w.width+x>S.x&&w.y<S.y+S.height+x&&w.y+w.height+x>S.y;let g=Math.max(h+16,Vt.padding);const y=t.notes.map(w=>{const S=Be(qe(w.text,w.textContent),{fontSize:12,fontWeight:400});const x=Math.max(90,S.width+24);const M=Math.max(40,S.height+18);const b=w.for?l.find(P=>P.id===w.for):void 0;let C;if(b){const P=[];for(let E=0;E<Math.max(4,t.notes.length+1);E++){const k=E*(M+12);P.push({x:b.x+b.width+24,y:b.y+k,width:x,height:M,targetX:b.x+b.width,targetY:b.y+b.height/2,noteX:b.x+b.width+24,noteY:b.y+k+M/2},{x:b.x-x-24,y:b.y+k,width:x,height:M,targetX:b.x,targetY:b.y+b.height/2,noteX:b.x-24,noteY:b.y+k+M/2},{x:b.x,y:b.y+b.height+24+k,width:x,height:M,targetX:b.x+b.width/2,targetY:b.y+b.height,noteX:b.x+x/2,noteY:b.y+b.height+24+k})}C=P.find(E=>E.x>=Vt.padding&&E.y>=Vt.padding&&!m.some(k=>p(E,k)))??{x:f+24,y:b.y,width:x,height:M,targetX:b.x+b.width,targetY:b.y+b.height/2,noteX:f+24,noteY:b.y+M/2}}else{C={x:Vt.padding,y:g,width:x,height:M};g+=M+12}m.push(C);f=Math.max(f,C.x+x+Vt.padding);h=Math.max(h,C.y+M+Vt.padding);return{text:w.text,...w.textContent?{textContent:w.textContent}:{},...w.for?{for:w.for}:{},...C}});return{width:f,height:h,accessibilityTitle:t.accessibilityTitle,accessibilityDescription:t.accessibilityDescription,classes:l,relationships:u,notes:y,namespaces:c}}function TD(e,t,n,i,r,o=[],s=false){if(!e.some(u=>u.fromCardinality||u.toCardinality))return;const a=(u,f)=>Math.min(u.x1,f.x1)>Math.max(u.x0,f.x0)&&Math.min(u.y1,f.y1)>Math.max(u.y0,f.y0);const l=(u,f)=>Math.min(u.x1,f.x1)-Math.max(u.x0,f.x0)>.5&&Math.min(u.y1,f.y1)-Math.max(u.y0,f.y0)>.5;const c=t.map(u=>({x0:u.x-1,y0:u.y-1,x1:u.x+u.width+1,y1:u.y+u.height+1}));for(const u of e){if(!u.label||!u.labelPosition)continue;const f=ui(qe(u.label,u.labelContent),n,"edge");c.push({x0:u.labelPosition.x-f.width/2-2,y0:u.labelPosition.y-8-f.height/2-2,x1:u.labelPosition.x+f.width/2+2,y1:u.labelPosition.y-8+f.height/2+2})}const d=(u,f,h,m)=>{const p=Be(u,{fontSize:n.edgeLabelFontSize,fontWeight:n.edgeLabelFontWeight,letterSpacing:n.edgeLetterSpacing});const g=p.width/2+2;const y=p.height/2+2;const w=M=>M.x0>=0&&M.y0>=0&&M.x1<=i&&M.y1<=r&&c.every(b=>!l(M,b))&&o.every(b=>!a(M,b));if(s&&m){const M={x0:m.x-g,y0:m.y-y,x1:m.x+g,y1:m.y+y};if(w(M)){c.push(M);return m}}const S=[];for(const M of kx(f,h)){const b={x0:M.x-g,y0:M.y-y,x1:M.x+g,y1:M.y+y};S.push({point:M,box:b});if(w(b)){c.push(b);return M}}if(s)throw new Qe([{strategy:"class-owned-cardinality",violations:["No collision-free endpoint text seat in the existing bounded candidates"]}]);const x=S.map(M=>({...M,collisions:c.filter(b=>l(M.box,b)).length})).sort((M,b)=>M.collisions-b.collisions||M.point.y-b.point.y||M.point.x-b.point.x)[0]??{point:f,box:{x0:f.x,y0:f.y,x1:f.x,y1:f.y}};c.push(x.box);return x.point};for(const u of e){if(u.points.length<2)continue;if(u.fromCardinality){u.fromCardinalityPosition=d(qe(u.fromCardinality,u.fromCardinalityContent),u.points[0],u.points[1],u.fromCardinalityPosition)}if(u.toCardinality){const f=u.points.length-1;u.toCardinalityPosition=d(qe(u.toCardinality,u.toCardinalityContent),u.points[f],u.points[f-1],u.toCardinalityPosition)}}}function LD(e,t={},n,i){Lm(e);const r=Ue(t,Ax,n);const o=i===void 0||i==="backend:default"||(i==="backend:rough"||i==="backend:hybrid")&&e.notes.length===0;const s=e.relationships.some(f=>f.markerAt!=="none");const a=gs();const l=o&&s?{colors:Object.freeze(Zm(t,t.mermaidConfig??{})),work:a}:void 0;if(e.classes.length===0&&!e.namespaces.length&&!e.notes.length){const f=()=>AD({width:0,height:0,accessibilityTitle:e.accessibilityTitle,accessibilityDescription:e.accessibilityDescription,classes:[],relationships:[],notes:[],namespaces:[]},e.title,r);return Qr(t,f,f)}const c=WU(e,r);const d=t.class?.hierarchicalNamespaces!==false;let u=new Map;return Qr(t,()=>{const f=Fx(e.namespaces,void 0,d);const h=new Map(f.map((k,v)=>[k.path,v]));if(h.size!==f.length)throw new Mo("ambiguous Class namespace paths");const m=new Map;for(const[k,v]of f.entries())for(const T of v.ns.classIds)if(!m.has(T))m.set(T,k);const p=yi(e.classes.map(k=>k.id));const g=f.map(k=>{const v=ui(qe(k.ns.label??k.ns.name,k.ns.labelContent),r,"group");const T=jk(r,v.text);return{id:p(`class-namespace:${k.path}`,["class","namespace",k.path]),...k.parentPath?{parent:h.get(k.parentPath)}:{},minWidth:v.width+2*Math.max(r.groupLabelPaddingX,r.groupPaddingX+8),headerHeight:T,padding:{top:T+r.groupPaddingY,right:r.groupPaddingX+8,bottom:r.groupPaddingY+8,left:r.groupPaddingX+8}}});const y=new Map(e.classes.map((k,v)=>[k.id,v]));const w=e.relationships.map(k=>{const v=k.label?ui(qe(k.label,k.labelContent),r,"edge"):void 0;return v?.lineBlocks.some(T=>T.runs.some(A=>A.text.trim()))?{width:v.width+8,height:v.height+6}:void 0});const S=xD(e.relationships,r);const x=a?SD(e.classes,e.relationships,S,r.lineWidth,e.direction??"TB",a):void 0;const M=k=>{for(let v=0;v<k;v++)if(!ri(a))throw new Qe([{strategy:"class-native-marker-capacity",violations:["Class marker capacity work limit"]}])};let b=c;for(const[k,v]of x??[]){M(5);const T=c.get(k),A=Math.max(T.height,v.height),R=Math.max(T.width,v.width);if(A===T.height&&R===T.width)continue;if(b===c){M(c.size+1);b=new Map(c)}M(3);b.set(k,{...T,width:R,height:A,methodHeight:T.methodHeight+(A-T.height)})}const C=e.classes.map(k=>{const v=vD(e,k);const T=Number.parseFloat(v?.["stroke-width"]??"");return Number.isFinite(T)&&T>0?T:r.nodeLineWidth});const P=ei("agentic",()=>Ua({nodes:e.classes.map((k,v)=>({id:k.id,width:b.get(k.id).width,height:b.get(k.id).height,paintStrokeWidth:C[v],...!k.isInterface&&(i===void 0||i==="backend:default")?{paintCornerRadius:r.cornerRadius??0}:{},...x?.has(k.id)?{minimumPortSpacing:x.get(k.id).portSpacing}:{},...m.has(k.id)?{parent:m.get(k.id)}:{}})),groups:g.map(k=>({...k,paintStrokeWidth:r.groupLineWidth,...i===void 0||i==="backend:default"?{paintCornerRadius:r.groupCornerRadius}:{}})),edges:e.relationships.map((k,v)=>{const T=y.get(k.from),A=y.get(k.to);if(T===void 0||A===void 0)throw new Error("Class relationship references an undeclared card");return{source:T,target:A,minSpan:1,markerPaint:S[v],...w[v]?{label:w[v]}:{}}}),direction:e.direction??"TB",padding:Vt.padding,nodeSpacing:t.nodeSpacing??Vt.nodeSpacing,layerSpacing:t.layerSpacing??Vt.layerSpacing,edgeSpacing:Math.max(6,r.lineWidth+4),minimumTerminalLead:Math.max(1,RD(e,r)),maximumEdgeStrokeWidth:r.lineWidth,maximumEdgeBendRadius:r.edgeBendRadius}));if(P.nodes.length!==e.classes.length||(P.groups?.length??0)!==f.length||P.edges.length!==e.relationships.length){throw new TypeError("Native Class placement lost measured subjects")}const E={width:P.width,height:P.height,nodes:[...P.nodes.map((k,v)=>({...k,id:e.classes[v].id,width:b.get(e.classes[v].id).width,height:b.get(e.classes[v].id).height})),...f.map((k,v)=>({...P.groups[v],id:ED+k.path,namespacePath:k.path}))],routes:new Map(P.edges.map((k,v)=>[v,{points:k.points,...k.labelPosition?{labelPosition:{x:k.labelPosition.x,y:k.labelPosition.y+8}}:{}}]))};return MD(wD(E,e,b,r,d),e,r,l,a)},()=>{let f;let h=new Map;let m=c;for(let p=0;p<3;p++){const{elkGraph:g,namespaceLayouts:y}=zU(e,t,m,n,u,h);const w=g.children?.length||g.edges?.length?qa(g):{...g,width:0,height:0};f=wD(GU(w,y),e,m,r,d,u);const S=YU(f.namespaces,r);const x=f.namespaces.length?uD(f,r,h,a):h;const M=l?bD(f,r,l.work):new Map;let b=m;for(const[C,P]of M){const E=m.get(C);const k=Math.max(E.width,P.width),v=Math.max(E.height,P.height);if(k===E.width&&v===E.height)continue;if(b===m)b=new Map(m);b.set(C,{...E,width:k,height:v,methodHeight:E.methodHeight+v-E.height})}if(b===m&&S.size===u.size&&[...S].every(([C,P])=>u.get(C)===P)&&x.size===h.size&&[...x].every(([C,P])=>h.get(C)===P))break;u=S;h=x;m=b}return MD(f,e,r,l,a,true,i===void 0||i==="backend:default")},true)}function MD(e,t,n,i,r,o=false,s=false){for(const d of e.classes){d.labelBlock=ui(qe(d.label,d.labelContent),n,"node");d.attributeBlocks=d.attributes.map(Vh);d.methodBlocks=d.methods.map(Vh);if(d.annotation!==void 0)d.annotationBlock=Ix(d.annotation)}for(const d of e.namespaces)d.labelBlock=ui(qe(d.label,d.labelContent),n,"group",d.width-2*n.groupLabelPaddingX);for(const d of e.notes)d.textBlock=Be(qe(d.text,d.textContent),{fontSize:12,fontWeight:400});for(const d of e.relationships){if(d.label!==void 0)d.labelBlock=ui(qe(d.label,d.labelContent),n,"edge");for(const u of["from","to"]){const f=d[`${u}Cardinality`];if(f!==void 0)d[`${u}CardinalityBlock`]=Be(qe(f,d[`${u}CardinalityContent`]),{fontSize:n.edgeLabelFontSize,fontWeight:n.edgeLabelFontWeight,letterSpacing:n.edgeLetterSpacing})}}const a=o&&s&&r?pD(e,n,r):void 0;const l=yD(e,r);const c=AD(e,t.title,n);if(c.classes.some(d=>d.isInterface)){const d=new Map(c.classes.filter(f=>f.isInterface).map(f=>[f.id,f]));const u={...pg("none"),paint:{fill:"none",stroke:"none",strokeWidth:"0"}};for(const f of c.relationships){const h=d.get(f.from),m=d.get(f.to);if(!h&&!m)continue;const p=Wo({id:"interface-projection",role:"relationship",geometry:{kind:"polyline",points:f.points},lineStyle:"solid",paint:{strokeWidth:String(n.lineWidth)},markers:{...h?{start:u}:{},...m?{end:u}:{}}});for(const g of Yr(p)){const y=g.position==="start"?h:m,w=g.bounds;if(y&&w)y.interfaceBox={x:w.x0,y:w.y0,width:w.x1-w.x0,height:w.y1-w.y0}}}}HU(c,n,r,l,true,a);if(i)hD(c,n,i.colors,i.work);return c}function HU(e,t,n,i,r=false,o){if(i)Lx(i,n);const s=n??gs();let a;if(r&&t.edgeBendRadius===0&&e.namespaces.length&&e.relationships.length){if(!ri(s))throw new Qe([{strategy:"class-final-sharp-contacts",violations:["Class final contact capture work limit"]}]);a={}}const l=cD(e,t,n,a);const c=[...e.namespaces.map(f=>({x0:f.x,y0:f.y,x1:f.x+f.width,y1:f.y+f.headerHeight})),...e.notes.map(f=>({x0:f.x,y0:f.y,x1:f.x+f.width,y1:f.y+f.height}))];if(e.relationships.some(f=>f.markerAt!=="none")){const f=e.classes[0]?.x,h=e.classes[0]?.y;Wk(e,t,Vt.padding,n);if(i&&(e.classes[0]?.x!==f||e.classes[0]?.y!==h))Lx(i,n);Hk(e,t,n??gs(),l)}else{TD(e.relationships,e.classes,t,e.width,e.height,c,true);const f=e.classes[0]?.x,h=e.classes[0]?.y;Wk(e,t,Vt.padding,n);if(i&&(e.classes[0]?.x!==f||e.classes[0]?.y!==h))Lx(i,n)}if(!e.relationships.some(f=>f.markerAt!=="none")&&l.size)Hk(e,t,n??gs(),l);gD(e,t,o,s);const d=dD(e,t);if(d.length)throw new Qe([{strategy:"class-owned-surfaces",violations:d}]);if(!r||t.edgeBendRadius!==0)tD(e,l,t,()=>ri(s));let u;if(a){if(!ri(s))throw new Qe([{strategy:"class-final-sharp-contacts",violations:["Class final contact capture work limit"]}]);u=Q_(a,e.relationships,t,()=>ri(s))}jU(e,t,s,r,l.size>0||!!o?.size,u)}function jU(e,t,n,i,r=false,o){if(t.edgeBendRadius!==0||e.relationships.length<2&&!(i&&r))return;const s=h=>{throw new Qe([{strategy:"class-final-sharp-contacts",violations:[h]}])};const a=(h=1)=>{for(let m=0;m<h;m++)if(!ri(n))s("Class final sharp contact work limit")};a(2*e.classes.length+3*e.relationships.length+8);const l=new Map(e.classes.map((h,m)=>[h.id,m]));const c={nodes:[],edges:e.relationships.map(h=>{const m=l.get(h.from),p=l.get(h.to);if(m===void 0||p===void 0)s("Undeclared final Class endpoint");return{source:m,target:p,minSpan:1}}),direction:"TB",padding:0,nodeSpacing:0,layerSpacing:0,maximumEdgeStrokeWidth:t.lineWidth,maximumEdgeBendRadius:0};const d=e.relationships.map(h=>({points:h.points,style:"solid"}));a();if(i){const h=LA(d,c,a,a,r,o);if(h===false)s("Final Class routes have unsupported cardinal support");const m=typeof h==="function"?h:s("Class final sharp contact work limit");for(let p=0;p+1<d.length;p++){if(!m(p))s("Final Class routes have an uncertified shared contact");d[p].style="invisible"}return}const u=ea(c);let f=0;for(const h of d){a();f+=Math.max(0,h.points.length-1)}for(let h=0;h+1<d.length;h++){const m=d[h],p=Math.max(0,m.points.length-1);f-=p;a(u*p*f+m.points.length+f+d.length);if(os(m.points,h,d,c,a,a,void 0,u,i)===void 0)s("Final Class routes have an uncertified shared contact");m.style="invisible"}}function AD(e,t,n){const i=tn(t,n);if(!i)return e;if(e.width===0&&e.height===0)return{...e,...pa(i,Vt.padding)};const r=i.height;for(const s of e.classes)s.y+=r;for(const s of e.namespaces)s.y+=r;for(const s of e.notes){s.y+=r;if(s.targetY!==void 0)s.targetY+=r;if(s.noteY!==void 0)s.noteY+=r}for(const s of e.relationships){for(const a of s.points)a.y+=r;for(const a of[s.labelPosition,s.fromCardinalityPosition,s.toCardinalityPosition]){if(a)a.y+=r}}const o=Math.max(e.width,i.width+2*Vt.padding);return{...e,width:o,height:e.height+r,title:on(i,o,Vt.padding)}}function YU(e,t){const n=new Map;for(const i of e){const r=i.width-2*t.groupLabelPaddingX;const o=ui(qe(i.label,i.labelContent),t,"group",r);const s=ui(qe(i.label,i.labelContent),t,"group");if(o.text!==s.text)n.set(i.id,o.text)}return n}function kD(e){if(e.length===0)return 0;let t=0;for(const n of e){const i=Vh(n).width;if(i>t)t=i}return t}var $D={memberSize:11,annotationSize:10};function qU(e,t){const n=e.lineBlocks.length===1?e.lineBlocks[0]:void 0;const i=!!n&&!n.fragments&&e.letterSpacing===0&&/^[\x20-\x7e]*$/.test(e.text)&&n.runs.every(r=>!r.bold&&!r.italic&&!r.underline&&!r.strikethrough)&&t.map(r=>r.text).join("")===e.text;return i?{spans:t}:{}}function XU(e,t){const{positioned:n,colors:i,resolved:r}=t;const o=r.renderOptions;const s=i.font??"Inter";const a=o.transparent??false;const l=[];const c=Ue(o,Ax,r.styleFace);const d=`class-${pi(n.width,n.height,n.classes.length,n.relationships.length)}`;const u=`${d}-title`;const f=`${d}-desc`;const h=ki(n.accessibilityTitle,n.accessibilityDescription,u,f);l.push(e.documentOpen({id:"prelude",width:n.width,height:n.height,colors:i,transparent:a,font:s,hasMonoFont:true},Ot(n.width,n.height,i,a,h)+"\n"+Dt(s,true,i.shadow,i.embedFontImport)));const m=[];m.push("<defs>");const p=Do(c);m.push(mi(p));const g=en(i);if(g)m.push(g);m.push("</defs>");l.push(e.definitions({id:"defs",markerResources:p},m.join("\n")));if(n.accessibilityTitle){l.push(e.documentContent({id:"title",role:"chrome",nonPaint:"accessibility"},`<title id="${u}">${ND(n.accessibilityTitle)}</title>`))}if(n.accessibilityDescription){l.push(e.documentContent({id:"desc",role:"chrome",nonPaint:"accessibility"},`<desc id="${f}">${ND(n.accessibilityDescription)}</desc>`))}if(n.title)l.push(e.text(En(n.title,c)));for(const x of n.namespaces){l.push(UU(e,x,c))}const y=new Map;for(const x of n.relationships){const M=`${x.from}->${x.to}`;const b=y.get(M)??0;y.set(M,b+1);l.push(JU(e,x,c,`rel:${M}#${b}`,p))}for(const x of n.classes){l.push(VU(e,x,c,o.security!=="strict",i))}const w=new Map;n.relationships.forEach((x,M)=>{const b=`${x.from}->${x.to}`;const C=w.get(b)??0;w.set(b,C+1);const P=QU(e,x,c,M,`rel:${b}#${C}`,p);if(P)l.push(P)});for(let x=0;x<n.notes.length;x++)l.push(KU(e,n.notes[x],c,x));const S=new Map;for(const x of n.relationships){const M=`${x.from}->${x.to}`;const b=S.get(M)??0;S.set(M,b+1);l.push(...ZU(e,x,c,`${M}#${b}`))}l.push(e.documentClose());return{family:"class",width:n.width,height:n.height,colors:i,transparent:a,parts:l}}function UU(e,t,n){const i=[];const r=`<g class="namespace" data-id="${Ye(t.id)}" data-label="${hn(t.label)}"${t.parentId?` data-parent-id="${Ye(t.parentId)}"`:""}>`;const o=n.groupFillColor??"var(--_group-fill)";const s=n.groupBorderColor??"var(--_node-stroke)";i.push({indent:2,node:e.shape({id:`namespace-rect:${t.id}`,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:o,stroke:s,strokeWidth:String(n.groupLineWidth)}})});const a=n.groupHeaderFillColor??"var(--_group-hdr)";const l=Tr(t.x,t.y,t.width,t.headerHeight,n.groupCornerRadius);i.push({indent:2,node:e.shape({id:`namespace-header:${t.id}`,role:"group-header",geometry:{kind:"path",d:l},paint:{fill:a,stroke:s,strokeWidth:String(n.groupLineWidth)}})});const c=t.labelBlock??ui(qe(t.label,t.labelContent),n,"group",t.width-2*n.groupLabelPaddingX);const d=c.text;const u=n.groupTextColor??"var(--_text-sec)";i.push({indent:2,node:e.text({id:`namespace-label:${t.id}`,role:"group-header",text:d,block:c,x:t.x+n.groupLabelPaddingX,y:t.y+t.headerHeight/2,fontSize:n.groupHeaderFontSize,anchor:"start",paint:{fill:u}})});return e.group({id:`namespace:${t.id}`,role:"group",open:r,close:"</g>",children:i})}function VU(e,t,n,i,r){const{x:o,y:s,width:a,height:l,headerHeight:c,attrHeight:d}=t;const u=[];if(t.isInterface){const B=t.labelBlock??ui(qe(t.label,t.labelContent),n,"node");return e.group({id:`class:${t.id}`,role:"class-box",open:`<g class="class-interface" data-id="${Ye(t.id)}" data-label="${hn(t.label)}" data-interface="true">`,close:"</g>",children:[{indent:2,node:e.text({id:`class:${t.id}:name`,role:"label",text:B.text,block:B,x:o+a/2,y:s+c/2,fontSize:B.fontSize,anchor:"middle",paint:{fill:n.nodeTextColor??"var(--_text)"}})}]})}const f=t.annotation!==void 0?` data-annotation="${Ye(t.annotation)}"`:"";const h=t.className?` ${Ye(t.className)}`:"";const m=t.className?` data-class="${Ye(t.className)}"`:"";const p=i&&t.href?` data-href="${Ye(t.href)}" role="link" tabindex="0"`:"";const g=`<g class="class-node${h}" data-id="${Ye(t.id)}" data-label="${hn(t.label)}"${f}${m}${p}>`;if(i&&t.href&&t.tooltip!==void 0){u.push({indent:2,node:e.documentContent({id:`class:${t.id}:tooltip`,role:"chrome",nonPaint:"interaction-metadata"},`<title>${At(t.tooltip)}</title>`)})}const y=t.inlineStyle??{};const w=n.nodeTextColor!==void 0;const S=Fs(t.inlineStyle,r,w?void 0:n.groupHeaderFillColor??"var(--_group-hdr)");const x=Fs(t.inlineStyle,r,w?void 0:n.nodeFillColor??"var(--_node-fill)");const M=y.fill??n.nodeFillColor??"var(--_node-fill)";const b=y.stroke??n.nodeBorderColor??"var(--_node-stroke)";const C=Number.parseFloat(y["stroke-width"]??"");const P=Number.isFinite(C)&&C>0?C:n.nodeLineWidth;u.push({indent:2,node:e.shape({id:`class:${t.id}:box`,role:"class-box",geometry:{kind:"rect",x:o,y:s,width:a,height:l,rx:n.cornerRadius??0,ry:n.cornerRadius??0},paint:{fill:M,stroke:b,strokeWidth:String(P),...y["stroke-dasharray"]!==void 0?{strokeDasharray:y["stroke-dasharray"]}:{}}})});const E=y.fill??n.groupHeaderFillColor??"var(--_group-hdr)";const k=Tr(o,s,a,c,n.cornerRadius??0);u.push({indent:2,node:e.shape({id:`class:${t.id}:header`,role:"group-header",geometry:{kind:"path",d:k},paint:{fill:E,stroke:b,strokeWidth:String(P),...y["stroke-dasharray"]!==void 0?{strokeDasharray:y["stroke-dasharray"]}:{}}})});let v=s+c/2;if(t.annotation!==void 0){const B=t.annotationBlock??Ix(t.annotation);const F=s+12;const z=S(n.nodeTextColor??"var(--_text-muted)");u.push({indent:2,node:e.text({id:`class:${t.id}:annotation`,role:"label",text:`<<${t.annotation}>>`,block:B,x:o+a/2,y:F,fontSize:$D.annotationSize,fontStyle:"italic",anchor:"middle",paint:{fill:z}})});v=s+c/2+6}const T=S(n.nodeTextColor??"var(--_text)");const A=t.labelBlock??ui(qe(t.label,t.labelContent),n,"node");const R=A.text;u.push({indent:2,node:e.text({id:`class:${t.id}:name`,role:"label",text:R,block:A,x:o+a/2,y:v,fontSize:n.nodeLabelFontSize,anchor:"middle",paint:{fill:T}})});const I=s+c;u.push({indent:2,node:ID(e,t.id,"attrs",o,I,a,n,y["stroke-dasharray"])});const L=20;for(let B=0;B<t.attributes.length;B++){const F=t.attributes[B];const z=I+4+B*L+L/2;u.push({indent:2,node:FD(e,F,o+n.nodePaddingX,z,n,`member:${t.id}:${F.name}`,x,t.attributeBlocks?.[B])})}const $=I+d;u.push({indent:2,node:ID(e,t.id,"methods",o,$,a,n,y["stroke-dasharray"])});for(let B=0;B<t.methods.length;B++){const F=t.methods[B];const z=$+4+B*L+L/2;u.push({indent:2,node:FD(e,F,o+n.nodePaddingX,z,n,`member:${t.id}:${F.name}`,x,t.methodBlocks?.[B])})}return e.group({id:`class:${t.id}`,role:"class-box",open:g,close:"</g>",children:u})}function ID(e,t,n,i,r,o,s,a){const l=s.nodeBorderColor??"var(--_node-stroke)";const c=Math.min(s.nodeLineWidth,et.innerBox);return e.shape({id:`class:${t}:divider:${n}`,role:"chrome",geometry:{kind:"line",x1:i,y1:r,x2:i+o,y2:r},paint:{stroke:l,strokeWidth:String(c),...a!==void 0?{strokeDasharray:a}:{}}})}function FD(e,t,n,i,r,o,s,a){const l=a??Vh(t);const c=Df(t);const d=s(r.nodeTextColor??"var(--_text-sec)");const u=[];if(!t.isMethod&&t.sourceText){if(t.visibility&&c.startsWith(t.visibility)){u.push({text:t.visibility,fill:s("var(--_text-faint)")},{text:c.slice(1),fill:d})}else{u.push({text:c,fill:d})}}else{if(t.visibility)u.push({text:`${t.visibility} `,fill:s("var(--_text-muted)")});const f=t.isMethod?`${t.name}(${t.params||""})`:t.name;u.push({text:za(f),fill:d});if(t.type){u.push({text:": ",fill:s("var(--_text-faint)")},{text:za(t.type),fill:s("var(--_text-muted)")})}}return e.text({id:o,role:"member",text:c,block:l,x:n,y:i,fontSize:$D.memberSize,anchor:"start",paint:{fill:d},...t.isAbstract?{fontStyle:"italic"}:{},...t.isStatic?{textDecoration:"underline"}:{},...qU(l,u),attributes:{className:"mono"}})}function KU(e,t,n,i){const r=n.groupBorderColor??"var(--_node-stroke)";const o=n.groupFillColor??"var(--_group-hdr)";const s=n.groupTextColor??"var(--_text)";const a=t.textBlock??Be(qe(t.text,t.textContent),{fontSize:12,fontWeight:400});const l=[];if(t.targetX!==void 0&&t.targetY!==void 0){l.push({node:e.connector({id:`class-note:${i}:connector`,role:"relationship",geometry:{kind:"line",x1:t.targetX,y1:t.targetY,x2:t.noteX??t.x,y2:t.noteY??t.y+t.height/2},lineStyle:"dashed",paint:{stroke:r,strokeWidth:"1",strokeDasharray:"4 3"},...t.for?{endpoints:{from:t.for,to:`class-note:${i}`,start:{owner:{id:t.for,role:"class-box"}},end:{owner:{id:`class-note:${i}`,role:"note"}}}}:{},attributes:{className:"class-note-connector"}}),indent:2})}l.push({node:e.shape({id:`class-note:${i}:box`,role:"note",geometry:{kind:"rect",x:t.x,y:t.y,width:t.width,height:t.height,rx:2,ry:2},paint:{fill:o,stroke:r,strokeWidth:"1"}}),indent:2});l.push({node:e.text({id:`class-note:${i}:label`,role:"label",text:t.text,block:a,x:t.x+t.width/2,y:t.y+t.height/2,fontSize:12,anchor:"middle",paint:{fill:s}}),indent:2});return e.group({id:`class-note:${i}`,role:"note",open:`<g class="class-note" data-note-index="${i}"${t.for?` data-for="${Ye(t.for)}"`:""}>`,close:"</g>",children:l})}function Yk(e){return{from:e.from,to:e.to,start:{owner:{id:e.from,role:"class-box"}},end:{owner:{id:e.to,role:"class-box"}}}}function JU(e,t,n,i,r){const o=t.label?[{text:t.label,textContent:{value:t.label,prepared:Rt(qe(t.label,t.labelContent))},...t.labelPosition?{anchor:t.labelPosition}:{}}]:[];if(t.points.length<2){return e.connector({id:i,role:"relationship",geometry:{kind:"polyline",points:t.points},lineStyle:"invisible",paint:{},endpoints:Yk(t),relationship:{kind:t.type},labels:o})}const s=nc(t)==="dashed";const a=s?"dashed":"solid";const l=t.markerAt==="from"||t.markerAt==="both"?t.fromType??t.type:void 0;const c=t.markerAt==="to"||t.markerAt==="both"?t.toType??t.type:void 0;const d=l?Pi(l):null;const u=c?Pi(c):null;const f=d?r.find(w=>w.id===d):void 0;const h=u?r.find(w=>w.id===u):void 0;const m={className:"class-relationship",data:{type:t.type,"relation-type":t.type,"marker-at":t.markerAt,...t.label?{label:jr(t.label)}:{},...t.fromCardinality?{"from-cardinality":t.fromCardinality}:{},...t.toCardinality?{"to-cardinality":t.toCardinality}:{}}};const p=n.edgeStrokeColor??"var(--_line)";const g={stroke:p,strokeWidth:String(n.lineWidth),...s?{strokeDasharray:"6 4"}:{}};const y={endpoints:Yk(t),relationship:{kind:t.type},route:{ownership:"layout",bendRadius:n.edgeBendRadius,labelAnchors:t.labelPosition?[t.labelPosition]:[]},labels:o};if(n.edgeBendRadius>0&&t.points.length>2){const w=qn(t.points,n.edgeBendRadius,{metric:"manhattan",terminalClearance:vc(t,n)});return e.connector({id:i,role:"relationship",geometry:w.geometry,lineStyle:a,paint:g,markers:{...f?{start:f}:{},mid:[],...h?{end:h}:{}},...y,route:{...y.route,contours:w.contours},attributes:m})}return e.connector({id:i,role:"relationship",geometry:{kind:"polyline",points:t.points},lineStyle:a,paint:g,markers:{...f?{start:f}:{},mid:[],...h?{end:h}:{}},...y,attributes:m})}function QU(e,t,n,i,r,o){if(t.points.length<2)return null;const s=t.markerAt==="from"||t.markerAt==="both"?t.fromType??t.type:void 0;const a=t.markerAt==="to"||t.markerAt==="both"?t.toType??t.type:void 0;const l=s?Pi(s):null;const c=a?Pi(a):null;if(!l&&!c)return null;const d=o.find(h=>h.id===l);const u=o.find(h=>h.id===c);const f={id:`marker-overlay:${i}`,role:"chrome",owner:{id:r,role:"relationship"},lineStyle:"solid",paint:{fill:"none",stroke:n.edgeStrokeColor??"var(--_line)",strokeWidth:String(n.lineWidth)},stroke:{opacity:0},endpoints:Yk(t),relationship:{kind:"marker-carrier"},markers:{...d?{start:d}:{},mid:[],...u?{end:u}:{}},hit:{pointerEvents:"none"},attributes:{className:"class-marker-overlay",ariaHidden:true}};if(n.edgeBendRadius>0&&t.points.length>2){const h=qn(t.points,n.edgeBendRadius,{metric:"manhattan",terminalClearance:vc(t,n)});return e.connector({...f,geometry:h.geometry,route:{contours:h.contours}})}return e.connector({...f,geometry:{kind:"polyline",points:t.points}})}function ZU(e,t,n,i){if(!t.label&&!t.fromCardinality&&!t.toCardinality||t.points.length<2){return[e.documentContent({id:`rel-labels:${i}`,role:"chrome"},"")]}const r=[];const o=n.edgeTextColor??"var(--_text-muted)";const s={fill:o,stroke:"var(--bg)",strokeWidth:String(lu),strokeLinejoin:"round",paintOrder:"stroke"};if(t.label){const a=cu(t);const l=t.labelBlock??ui(qe(t.label,t.labelContent),n,"edge");const c=l.text;r.push(e.text({id:`rel-label:${i}`,role:"label",text:c,block:l,x:a.x,y:a.y-sa,fontSize:n.edgeLabelFontSize,anchor:"middle",paint:s}))}if(t.fromCardinality){const a=Tc(t,"from");const l=t.fromCardinalityBlock??Be(qe(t.fromCardinality,t.fromCardinalityContent),{fontSize:n.edgeLabelFontSize,fontWeight:n.edgeLabelFontWeight,letterSpacing:n.edgeLetterSpacing});r.push(e.text({id:`rel-card:${i}:from`,role:"cardinality",text:t.fromCardinality,block:l,x:a.x,y:a.y,fontSize:n.edgeLabelFontSize,anchor:"middle",paint:s}))}if(t.toCardinality){const a=Tc(t,"to");const l=t.toCardinalityBlock??Be(qe(t.toCardinality,t.toCardinalityContent),{fontSize:n.edgeLabelFontSize,fontWeight:n.edgeLabelFontWeight,letterSpacing:n.edgeLetterSpacing});r.push(e.text({id:`rel-card:${i}:to`,role:"cardinality",text:t.toCardinality,block:l,x:a.x,y:a.y,fontSize:n.edgeLabelFontSize,anchor:"middle",paint:s}))}return r}var ND=At;var _D=gt(XU);var ave={configDiagnostics:U_,statementEnds:s0,normalizeRequest:e=>({renderOptions:CD(e.source.frontmatter,e.renderOptions)}),layout:e=>{const t=Tn(Vr(WL(e.source.familyLines,e.source.authoredFamilyLines??e.source.familyLines),e.source.accessibility),e.source.frontmatter);Jm(t.classDefs,t.classes);return ht(LD(t,e.renderOptions,e.styleFace,e.paintBackendId))},projectPositioned:ut(bA),lowerScene:ft(_D)};var eV={layoutDirection:qp("TB","TD","BT","LR","RL"),nodeSpacing:Yt,rankSpacing:Yt};var DD=e=>xt("er",e,eV);var Kh={attrSize:11,keySize:9};function tV(e,t){const{positioned:n,colors:i,resolved:r}=t;const o=r.renderOptions;const s=i.font??"Inter";const a=o.transparent??false;const l=[];const c=Ue(o,zd,r.styleFace);const d=`er-${pi(n.width,n.height,n.entities.length,n.relationships.length)}`;const u=`${d}-title`;const f=`${d}-desc`;const h=ki(n.accessibilityTitle,n.accessibilityDescription,u,f);l.push(e.documentOpen({id:"prelude",width:n.width,height:n.height,colors:i,transparent:a,font:s,hasMonoFont:true},Ot(n.width,n.height,i,a,h)+"\n"+Dt(s,true,i.shadow,i.embedFontImport)));const m=[];m.push("<defs>");const p=en(i);if(p)m.push(p);m.push("</defs>");l.push(e.definitions({id:"defs"},m.join("\n")));if(n.accessibilityTitle){l.push(e.documentContent({id:"acc-title",role:"chrome",nonPaint:"accessibility"},`<title id="${u}">${qk(n.accessibilityTitle)}</title>`))}if(n.accessibilityDescription){l.push(e.documentContent({id:"acc-desc",role:"chrome",nonPaint:"accessibility"},`<desc id="${f}">${qk(n.accessibilityDescription)}</desc>`))}if(n.title)l.push(e.text(En(n.title,c)));for(const b of n.groups)l.push(nV(e,b,c));const g=new Map;const y=new Set(n.groups.map(b=>b.id));const w=b=>({id:b,role:y.has(b)?"group":"entity"});for(const b of n.relationships){const C=`${b.entity1}-${b.entity2}`;const P=g.get(C)??0;g.set(C,P+1);l.push(oV(e,b,c,r.styleFace,`rel:${C}#${P}`,w))}for(const b of n.entities){l.push(iV(e,b,c,i))}const S=new Map;for(const b of n.relationships){const C=`${b.entity1}-${b.entity2}`;const P=S.get(C)??0;S.set(C,P+1);l.push(...aV(e,b,c,`card:${C}#${P}`))}const x=Va(n)??na(n,c,r.styleFace);const M=new Map;for(const b of n.relationships){const C=`${b.entity1}-${b.entity2}`;const P=M.get(C)??0;M.set(C,P+1);l.push(...sV(e,b,c,r.styleFace,`rel-label:${C}#${P}`,x.get(b)))}l.push(e.documentClose());return{family:"er",width:n.width,height:n.height,colors:i,transparent:a,parts:l}}function nV(e,t,n){const i=n.groupBorderColor??"var(--_node-stroke)";const r=n.groupFillColor??"var(--_group-fill)";const o=n.groupHeaderFillColor??"var(--_group-hdr)";const s=n.groupTextColor??"var(--_text)";const a=t.labelBlock??Gd(qe(t.label,t.labelContent),n);return e.group({id:`er-group:${t.id}`,role:"group",open:`<g class="er-subgraph" data-id="${Ye(t.id)}" data-label="${hn(t.label)}"${t.parentId?` data-parent-id="${Ye(t.parentId)}"`:""}>`,close:"</g>",children:[{node:e.shape({id:`er-group:${t.id}:box`,role:"group",geometry:{kind:"rect",x:t.x,y:t.y,width:t.width,height:t.height,rx:6,ry:6},paint:{fill:r,stroke:i,strokeWidth:"1.5"}}),indent:2},{node:e.shape({id:`er-group:${t.id}:header`,role:"group-header",geometry:{kind:"rect",x:t.x,y:t.y,width:t.width,height:t.headerHeight,rx:6,ry:6},paint:{fill:o,stroke:"none"}}),indent:2},{node:e.text({id:`er-group:${t.id}:label`,role:"label",text:a.text,block:a,x:t.x+10,y:t.y+t.headerHeight/2,fontSize:a.fontSize,anchor:"start",paint:{fill:s}}),indent:2}]})}function iV(e,t,n,i){const{id:r,x:o,y:s,width:a,height:l,headerHeight:c,rowHeight:d,label:u,attributes:f}=t;const h=[];const m=t.className?` ${Ye(t.className)}`:"";const p=t.className?` data-class="${Ye(t.className)}"`:"";const g=`<g class="entity${m}" data-id="${Ye(r)}" data-label="${hn(u)}"${p}>`;const y=t.inlineStyle??{};const w=n.nodeTextColor!==void 0;const S=Fs(t.inlineStyle,i,w?void 0:n.groupHeaderFillColor??"var(--_group-hdr)");const x=Fs(t.inlineStyle,i,w?void 0:n.nodeFillColor??"var(--_node-fill)");const M=y.fill??n.nodeFillColor??"var(--_node-fill)";const b=y.stroke??n.nodeBorderColor??"var(--_node-stroke)";const C=Number.parseFloat(y["stroke-width"]??"");const P=Number.isFinite(C)&&C>0?C:n.nodeLineWidth;const E=y["stroke-dasharray"];const k=E===void 0?{}:{strokeDasharray:E};h.push({indent:2,node:e.shape({id:`entity-rect:${r}`,role:"entity",geometry:{kind:"rect",x:o,y:s,width:a,height:l,rx:n.cornerRadius??0,ry:n.cornerRadius??0},paint:{fill:M,stroke:b,strokeWidth:String(P),...k}})});const v=y.fill??n.groupHeaderFillColor??"var(--_group-hdr)";const T=Tr(o,s,a,c,n.cornerRadius??0);h.push({indent:2,node:e.shape({id:`entity-header:${r}`,role:"group-header",geometry:{kind:"path",d:T},paint:{fill:v,stroke:b,strokeWidth:String(P),...k}})});const A=S(n.nodeTextColor??"var(--_text)");const R=t.labelBlock??yy(qe(u,t.labelContent),n);const I=R.text;h.push({indent:2,node:e.text({id:`entity-name:${r}`,role:"label",text:I,block:R,x:o+a/2,y:s+c/2,fontSize:n.nodeLabelFontSize,anchor:"middle",paint:{fill:A}})});const L=s+c;const $=Math.min(n.nodeLineWidth,et.innerBox);h.push({indent:2,node:e.shape({id:`entity-divider:${r}`,role:"chrome",geometry:{kind:"line",x1:o,y1:L,x2:o+a,y2:L},paint:{stroke:b,strokeWidth:String($),...k}})});const B=nM(f);for(let F=0;F<f.length;F++){const z=f[F];const _=L+F*d+d/2;for(const H of rV(e,z,r,o,_,a,n,x,B,t.attributeBlocks?.[F])){h.push({indent:2,node:H})}}if(f.length===0){const F=x(n.nodeTextColor??"var(--_text-muted)");const z=t.emptyAttributeBlock??xy();h.push({indent:2,node:e.text({id:`entity-empty:${r}`,role:"attribute",text:z.text,block:z,x:o+a/2,y:L+d/2,fontSize:Kh.attrSize,anchor:"middle",paint:{fill:F}})})}return e.group({id:`entity:${r}`,role:"entity",open:g,close:"</g>",children:h})}function rV(e,t,n,i,r,o,s,a,l,c){const d=[];const u=`attr:${n}:${t.name}`;const f=c??gh(t);const h=s.nodeTextColor??"var(--_text-sec)";const m=a(h);const p=a(s.nodeTextColor??"var(--_text-muted)");let g=0;if(t.keys.length>0){const M=t.keys.join(",");g=f.keys.width+8;const b=i+Math.max(6,s.nodePaddingX/2);d.push(e.shape({id:`${u}:key-badge`,role:"chrome",geometry:{kind:"rect",x:b,y:r-7,width:g,height:14,rx:2,ry:2},paint:{fill:"var(--_key-badge)"}}));d.push(e.text({id:`${u}:key-text`,role:"attribute",text:M,block:f.keys,x:b+g/2,y:r,fontSize:Kh.keySize,anchor:"middle",paint:{fill:h}}))}const y=i+Math.max(8,s.nodePaddingX/2)+(g>0?g+6:0);d.push(e.text({id:`${u}:type`,role:"attribute",text:t.type,block:f.type,x:y,y:r,fontSize:Kh.attrSize,anchor:"start",paint:{fill:p},attributes:{className:"mono"}}));const w=i+o-Math.max(8,s.nodePaddingX/2);const S=w-l;d.push(e.text({id:u,role:"attribute",text:t.name,block:f.name,x:S,y:r,fontSize:Kh.attrSize,anchor:"end",paint:{fill:m},attributes:{className:"mono"}}));if(t.comment){const M=hh(t.comment,t.commentContent);d.push(e.text({id:`${u}:comment`,role:"attribute",text:M,block:f.comment,x:w,y:r,fontSize:Kh.attrSize,anchor:"end",paint:{fill:p}}))}const x=t.comment&&t.comment.length>0;if(x){const M=ws(t.comment);return[e.group({id:`${u}:row`,role:"attribute",open:`<g><title>${qk(M)}</title>`,close:"</g>",children:d.map(b=>({node:b,indent:0}))})]}return d}function oV(e,t,n,i,r,o){const s=t.identifying?"solid":"dashed";const a={category:t.identifying?"identifying":"non-identifying"};const l=It(i,"relationship",a,{includeFallback:false});const c=l?.bendRadius??n.edgeBendRadius;const d={endpoints:{from:t.entity1,to:t.entity2,start:{owner:o(t.entity1)},end:{owner:o(t.entity2)}},relationship:{kind:t.identifying?"identifying":"non-identifying"},route:{ownership:"layout",bendRadius:c},labels:t.label?[{text:t.label,textContent:{value:t.label,prepared:Rt(qe(t.label,t.labelContent))}}]:[]};if(t.points.length<2){return e.connector({id:r,role:"relationship",geometry:{kind:"polyline",points:t.points},lineStyle:"invisible",paint:{},channels:a,...d})}const u={className:"er-relationship",data:{cardinality1:t.cardinality1,cardinality2:t.cardinality2,identifying:String(t.identifying),...t.label?{label:jr(t.label)}:{}}};const f=l?.strokeColor??n.edgeStrokeColor??"var(--_line)";const h=l?.lineWidth??n.lineWidth;const m={stroke:f,strokeWidth:String(h),...!t.identifying?{strokeDasharray:"6 4"}:{}};if(c>0&&t.points.length>2){const p=qn(t.points,c,{metric:"manhattan"});return e.connector({id:r,role:"relationship",geometry:p.geometry,lineStyle:s,paint:m,channels:a,...d,route:{...d.route,contours:p.contours},attributes:u})}return e.connector({id:r,role:"relationship",geometry:{kind:"polyline",points:t.points},lineStyle:s,paint:m,channels:a,...d,attributes:u})}function sV(e,t,n,i,r,o){if(!t.label||t.points.length<2){return[]}const s={category:t.identifying?"identifying":"non-identifying"};const a=It(i,"relationship",s,{includeFallback:false});const l=a?.fontSize??n.edgeLabelFontSize;const c=o??eM(t.points);const d=t.labelBlock??Cr(t,n,i);const u=d.text;const f=e.shape({id:`${r}:bg`,role:"chrome",geometry:F0(d,c),paint:{fill:"var(--bg)",stroke:"var(--_inner-stroke)",strokeWidth:"0.5"},channels:s});const h=a?.textColor??n.edgeTextColor??"var(--_text-muted)";const m=e.text({id:r,role:"label",text:u,block:d,x:c.x,y:c.y,fontSize:l,anchor:"middle",paint:{fill:h},channels:s});return[f,m]}function aV(e,t,n,i){if(t.points.length<2){return[e.shape({id:i,role:"cardinality",geometry:{kind:"compound",children:[]},paint:{}})]}const r=t.points[0];const o=t.points[1];const s=t.points[t.points.length-1];const a=t.points[t.points.length-2];return[OD(e,r,o,t.cardinality1,n,`${i}:1`),OD(e,s,a,t.cardinality2,n,`${i}:2`)]}function OD(e,t,n,i,r,o){const s={stroke:r.edgeStrokeColor??"var(--_line)",strokeWidth:String(r.lineWidth+.25)};const a=I0(t,n,i,s);return e.shape({id:o,role:"cardinality",geometry:{kind:"compound",children:a.map(l=>l.geometry)},paint:s,...a.some(l=>l.paint!==s)?{childPaints:a.map(l=>l.paint)}:{},channels:{category:i}})}var qk=At;var BD=gt(tV);var Hve={configDiagnostics:DD,normalizeRequest:e=>({renderOptions:TI(e.source.frontmatter,e.renderOptions)}),layout:e=>{const t=Tn(vI(Vr(JF(e.source.familyLines),e.source.accessibility),e.source.frontmatter),e.source.frontmatter);Jm(t.classDefs,t.entities);return ht(DI(t,e.renderOptions,e.styleFace))},projectPositioned:ut(OI),lowerScene:ft(BD)};var lV={nodeSpacing:Jt,rankSpacing:Jt,wrappingWidth:Jt};var WD=e=>xt("flowchart",e,lV);var cV=200;function zD(e,t){if(!e)return t;const n=Xk(e,"nodeSpacing");const i=Xk(e,"rankSpacing");const r=Xk(e,"wrappingWidth");if(n===void 0&&i===void 0&&r===void 0)return t;return{...t,nodeSpacing:t.nodeSpacing??n,layerSpacing:t.layerSpacing??i,wrappingWidth:t.wrappingWidth??r}}function Xk(e,t){const n=Mt(e,["flowchart",t]);return typeof n==="number"&&Number.isFinite(n)&&n>0?n:void 0}function GD(e,t,n){const i=t.wrappingWidth;const r=Ue(t,void 0,n);for(const o of e.nodes.values()){const s=i??(o.markdownLabel?cV:void 0);if(s===void 0||!o.label){delete o.labelBlock;continue}o.labelBlock=Be(qe(o.label,o.labelContent),{maxWidth:s,transform:r.nodeTextTransform,fontSize:r.nodeLabelFontSize,fontWeight:r.nodeLabelFontWeight,letterSpacing:r.nodeLetterSpacing})}}var cTe={configDiagnostics:WD,statementEnds:ZT,normalizeRequest:e=>({renderOptions:zD(e.source.frontmatter,e.renderOptions)}),layout:e=>{const t=j2(e.source.authoredFamilyBody??e.source.familyBody,e.source.familyBody);Km(t);GD(t,e.renderOptions,e.styleFace);const n=Nr(e.source.frontmatter);return ht(xx(t,{...e.renderOptions,...e.styleFace?{styleFace:e.styleFace}:{},...n?{diagramTitle:n}:{}}))},projectPositioned:ut(by),lowerScene:ft(ox)};var dV={displayMode:qp("compact"),barHeight:Jt,topAxis:lt,axisFormat:wd,tickInterval:an('a positive Mermaid interval such as "1day" or "2week"',e=>typeof e==="string"&&/^[1-9]\d*(?:millisecond|second|minute|hour|day|week|month)$/i.test(e.trim()))};var HD=e=>xt("gantt",e,dV);function Nx(e,t){return{id:e,shape:"arrow",size:{width:8,height:7},ref:{x:8,y:3.5},orient:"auto",geometry:{kind:"path",d:"M0,0 L8,3.5 L0,7 Z"},paint:{fill:t}}}var fu=(e,t)=>t?Math.max(1.8,e*1.5):Math.max(1.2,e);var uV=xr([Nx("dependency","black")]);var Uk=e=>uV("dependency",e,"end");function jD(e){const t=new Map;for(const n of e){let i=t.get(n.sectionIndex);if(!i)t.set(n.sectionIndex,i=[]);i.push(n)}return t}var Zk=120;var fV=220;var hV=1e4;var mV=2;var Hn={plotWidth:600,padding:16,titleHeight:34,axisHeight:24,rowGap:8,sectionGap:6,barHeight:22,labelGap:12,labelFontSize:13,sectionFontSize:13};var pV={nodeLabelFontSize:Hn.labelFontSize,edgeLabelFontSize:11,groupHeaderFontSize:Hn.sectionFontSize,nodeLabelFontWeight:500,edgeLabelFontWeight:500,groupHeaderFontWeight:600,nodePaddingX:0,nodePaddingY:0,nodeLineWidth:et.innerBox,edgeLineWidth:et.connector,groupCornerRadius:0,groupPaddingX:0,groupPaddingY:0,groupLineWidth:et.outerBox};var Qh={millisecond:1,second:1e3,minute:6e4,hour:36e5,day:An,week:7*An,month:30*An};var Vk=[{unit:"minute",count:1,format:"%H:%M"},{unit:"minute",count:15,format:"%H:%M"},{unit:"hour",count:1,format:"%H:%M"},{unit:"hour",count:6,format:"%H:%M"},{unit:"day",count:1,format:"%m-%d"},{unit:"week",count:1,format:"%m-%d"},{unit:"week",count:2,format:"%m-%d"},{unit:"month",count:1,format:"%b %Y"},{unit:"month",count:3,format:"%b %Y"},{unit:"month",count:12,format:"%Y"}];function e1(e={},t){return Ue(e,pV,t)}function Zh(e){return Math.max(17,e.groupHeaderFontSize)}function t1(e){return Math.max(e.groupHeaderFontWeight,600)}function n1(e){const t=XD(e);return Math.max(t===Hn.titleHeight?18:t/2,Zh(e)+1)}function i1(e){return Math.max(10,e.edgeLabelFontSize*.75)}function XD(e){return Math.max(Hn.titleHeight,Math.ceil(Zh(e)*1.5)+8)}function gV(e){return Math.max(Hn.axisHeight,Math.ceil(i1(e)+e.edgeLabelFontSize*.65+4))}function yV(e,t){const n=Math.max(e.nodeLabelFontSize,e.groupHeaderFontSize)*1.3;return Math.ceil(Math.max(t,n))+Hn.rowGap}function xV(e,t,n=8){const i=e.timeMax-e.timeMin;if(t.tickInterval){const s=Qh[t.tickInterval.unit]*t.tickInterval.count;if(i/s<=Zk){return{...t.tickInterval,format:t.axisFormat??bV(t.tickInterval.unit)}}}for(const s of Vk){const a=Qh[s.unit]*s.count;if(i/a<=n){return{unit:s.unit,count:s.count,format:t.axisFormat??s.format}}}const r=Vk[Vk.length-1];let o=r.count;while(i/(Qh.month*o)>Zk)o*=2;return{unit:"month",count:o,format:t.axisFormat??r.format}}function bV(e){switch(e){case"millisecond":case"second":return"%H:%M:%S";case"minute":case"hour":return"%H:%M";case"day":case"week":return"%m-%d";case"month":return"%b %Y"}}function SV(e,t,n){if(t.unit==="week"){let r=eh(e);let o=0;while(sc(r)!==n&&o++<7)r-=An;return r}if(t.unit==="month"){const r=new Date(e);return Date.UTC(r.getUTCFullYear(),r.getUTCMonth(),1)}if(t.unit==="day")return eh(e);const i=Qh[t.unit]*t.count;return Math.floor(e/i)*i}function wV(e,t){if(t.unit==="month"){const n=new Date(e);return Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+t.count,1)}return e+Qh[t.unit]*t.count}function MV(e,t,n=8){if(e.tasks.length===0)return[];const i=xV(e,t,n);const r=L0[t.weekStart];const o=[];let s=SV(e.timeMin,i,r);let a=0;while(s<=e.timeMax&&a++<=Zk){if(s>=e.timeMin)o.push({time:s,label:A0(s,i.format)});s=wV(s,i)}if(o.length===0){o.push({time:e.timeMin,label:A0(e.timeMin,i.format)})}return o}function kV(e){const t=[];const n=[];let i=0;let r;for(const o of e){let s=-1;if(r){if(r[1]<=o.start){let l=1;while(l<i)l=r[l*2]<=o.start?l*2:l*2+1;s=l-i}}else{s=t.findIndex(l=>l<=o.start)}if(s===-1)s=t.length;const a=s===t.length;t[s]=o.end;n.push(s);if(r&&t.length<=i){let l=i+s;r[l]=t[s];while((l>>=1)>0)r[l]=Math.min(r[l*2],r[l*2+1])}else if(r||a&&t.length===33&&n.length<e.length&&e.every(l=>Number.isFinite(l.start)&&Number.isFinite(l.end))){i=i===0?64:i*2;r=new Array(i*2).fill(Infinity);for(let l=0;l<t.length;l++)r[i+l]=t[l];for(let l=i-1;l>0;l--){r[l]=Math.min(r[l*2],r[l*2+1])}}}return n}var r1=8;var Jn=.01;function Kk(e){if(e.milestoneX!==void 0)return{x:e.milestoneX-e.h/2,y:e.y,w:e.h,h:e.h};return{x:e.x,y:e.y,w:e.w,h:e.h}}function CV(e,t,n,i){const[r,o]=t<=n?[t,n]:[n,t];return e>i.y+Jn&&e<i.y+i.h-Jn&&o>i.x+Jn&&r<i.x+i.w-Jn}function o1(e,t,n,i){const[r,o]=t<=n?[t,n]:[n,t];return e>i.x+Jn&&e<i.x+i.w-Jn&&o>i.y+Jn&&r<i.y+i.h-Jn}function Jh(e,t,n){if(Math.abs(e.x-t.x)<=Jn)return n.some(i=>o1(e.x,e.y,t.y,i));return n.some(i=>CV(e.y,e.x,t.x,i))}function PV(e){return e.map(t=>({y:t.y,h:t.h})).sort((t,n)=>t.y-n.y)}function YD(e,t){return e.findIndex(n=>t>=n.y-Jn&&t<=n.y+n.h+Jn)}function Jk(e,t,n){const i=e[t].y+e[t].h;const r=t+1<e.length?e[t+1].y:n.y+n.h;return(i+r)/2}function Qk(e,t,n){const i=e[t].y;const r=t>0?e[t-1].y+e[t-1].h:n.y;return(r+i)/2}function EV(e,t,n,i){const r=r1;const o=n.x-r;const s=n.x+n.w+r;const a=t.filter(u=>u.y<e.y+e.h-Jn&&u.y+u.h>e.y+Jn);const l=new Set([o]);for(const u of a){l.add(Math.max(o,Math.min(s,u.x-r)));l.add(Math.max(o,Math.min(s,u.x+u.w+r)))}let c=o;let d=Infinity;for(const u of l){if(a.some(h=>o1(u,e.y-1,e.y+e.h+1,h)))continue;const f=Math.abs(u-i);if(f<d-Jn||Math.abs(f-d)<=Jn&&u<c){c=u;d=f}}return c}function RV(e){const t=[];for(const n of e){const i=t[t.length-1];if(i&&Math.abs(i.x-n.x)<=Jn&&Math.abs(i.y-n.y)<=Jn)continue;t.push({x:n.x,y:n.y});const r=t.length;if(r>=3){const o=t[r-3];const s=t[r-2];const a=t[r-1];if(Math.abs(o.x-s.x)<=Jn&&Math.abs(s.x-a.x)<=Jn||Math.abs(o.y-s.y)<=Jn&&Math.abs(s.y-a.y)<=Jn){t.splice(r-2,1)}}}return t}function vV(e,t,n,i,r,o=r1){const s=o;const a=e.rect;const l=t.rect;const c=a.y+a.h/2;const d=l.y+l.h/2;const u=YD(i,c);const f=YD(i,d);if(u===-1||f===-1)return null;const h=u===f;const m=h||f>u;const p=m?Jk(i,u,r):Qk(i,u,r);const g=h?p:m?Qk(i,f,r):Jk(i,f,r);const y=[];const w=a.x+a.w;const S=[{x:w,y:c},{x:w+s,y:c},{x:w+s,y:p}];if(!Jh(S[0],S[1],n)&&!Jh(S[1],S[2],n)){y.push(...S)}else{const v=e.tipX??(a.w>=2*s?w-s:a.x+a.w/2);y.push({x:v,y:m?a.y+a.h:a.y},{x:v,y:p})}let x=y[y.length-1].x;const M=l.x-s;if(!h){const v=m?1:-1;for(let T=u+v;T!==f;T+=v){const A=i[T];if(n.some(R=>o1(x,A.y-1,A.y+A.h+1,R))){const R=m?Qk(i,T,r):Jk(i,T,r);const I=EV(A,n,r,M);y.push({x,y:R},{x:I,y:R});x=I}}}const b=l.x-s;const C=[{x:b,y:g},{x:b,y:d},{x:l.x,y:d}];let P;let E;if(!Jh(C[0],C[1],n)&&!Jh(C[1],C[2],n)){E=C;P="right"}else{const v=t.tipX??(l.w>=2*s?l.x+s:l.x+l.w/2);const T=g<l.y;E=[{x:v,y:g},{x:v,y:T?l.y:l.y+l.h}];P=T?"down":"up"}y.push({x,y:g},...E);const k=RV(y);for(let v=1;v<k.length;v++){if(Jh(k[v-1],k[v],n))return null}return{points:k,arrowDir:P}}function TV(e,t,n,i,r,o,s={}){const a=gA(e);if(a.length===0)return[];const l=new Map(n.map(h=>[h.taskIndex,h]));const c=n.map(Kk);const d=PV(i);const u=new Set(t.analysis?.criticalPathTaskIds??[]);const f=[];for(const h of a){const m=l.get(h.from);const p=l.get(h.to);if(!m||!p)continue;const g=t.tasks[h.from];const y=t.tasks[h.to];const w=h.kind==="after"&&g.id!==void 0&&y.id!==void 0&&u.has(g.id)&&u.has(y.id)&&g.end===y.start;const S=vV({rect:Kk(m),tipX:m.milestoneX},{rect:Kk(p),tipX:p.milestoneX},c,d,r,s.gantt?.dependencyArrows?Uk(fu(o.lineWidth,s.gantt.criticalPath===true&&w)):r1);if(!S)continue;f.push({fromTaskIndex:h.from,toTaskIndex:h.to,kind:h.kind,critical:w,points:S.points,arrowDir:S.arrowDir})}return f}function qD(e,t,n,i,r){const o=Be(e,{display:"literal",transform:t,fontSize:n,fontWeight:i,letterSpacing:r,maxWidth:fV});return{lines:[...o.lines],width:o.width,block:o}}function UD(e,t,n={}){const i=e1(n.renderOptions,n.styleFace);const r=n.compact??e.displayMode==="compact";const o=t.tasks.length===0?Be("No tasks scheduled",{fontSize:i.nodeLabelFontSize,fontWeight:i.nodeLabelFontWeight,transform:i.nodeTextTransform,letterSpacing:i.nodeLetterSpacing}):void 0;const s=n.barHeight??e.barHeight??Hn.barHeight;let a=yV(i,s);const l=t.tasks.filter(K=>K.tags.includes("vert"));const c=t.tasks.filter(K=>!K.tags.includes("vert"));const d=jD(c);const u=new Map;const f=new Map;let h=0;for(const K of c){if(r){const Z=Be(K.label,{display:"literal",transform:i.nodeTextTransform,fontSize:i.nodeLabelFontSize,fontWeight:i.nodeLabelFontWeight,letterSpacing:i.nodeLetterSpacing});u.set(K.index,{lines:Z.lines,width:Z.width,block:Z});h=Math.max(h,Z.width)}else{const Z=qD(K.label,i.nodeTextTransform,i.nodeLabelFontSize,i.nodeLabelFontWeight,i.nodeLetterSpacing);u.set(K.index,Z);h=Math.max(h,Z.width)}}for(let K=0;K<e.sections.length;K++){const Z=e.sections[K];if(Z.label){const Q=qD(ws(Z.label),i.groupTextTransform,i.groupHeaderFontSize,i.groupHeaderFontWeight,i.groupLetterSpacing);f.set(K,Q);h=Math.max(h,Q.width)}}h=Math.ceil(h)+Math.max(Hn.labelGap,n.renderOptions?.gantt?.dependencyArrows?Uk(fu(i.lineWidth,n.renderOptions.gantt.criticalPath===true))+4:0);if(r)a=Math.max(a,...[...u.values()].map(K=>Math.ceil(K.block.height)+Hn.rowGap));const m=new Map(l.map(K=>[K.index,Be(K.label,{display:"literal",transform:i.edgeTextTransform,fontSize:i.edgeLabelFontSize,fontWeight:Math.max(i.edgeLabelFontWeight,600),letterSpacing:i.edgeLetterSpacing})]));const p=Math.max(1,t.timeMax-t.timeMin);const g=MV(t,e).map(K=>({...K,block:Be(K.label,{display:"literal",transform:i.edgeTextTransform,fontSize:i.edgeLabelFontSize,fontWeight:i.edgeLabelFontWeight,letterSpacing:i.edgeLetterSpacing})}));const y=K=>Math.max(0,...g.map(Z=>{const Q=Z.block.width/2;return Q-(t.timeMax-Z.time)/p*K}));const w=Hn.padding+h;const S=n.width??Hn.padding*2+h+Hn.plotWidth;const x=Math.max(Hn.padding,Math.ceil(y(Math.max(120,S-w-Hn.padding))+mV));const M=e.title?Be(e.title,{display:"literal",transform:i.groupTextTransform,fontSize:Zh(i),fontWeight:t1(i),letterSpacing:i.groupLetterSpacing,...n.width===void 0?{}:{maxWidth:Math.max(1,n.width-Hn.padding*2)}}):void 0;const b=M?.width??0;const C=M?M.height-M.lineHeight:0;const P=n.width??Math.max(S+x-Hn.padding,Math.ceil(b)+Hn.padding*2);const E=Math.max(120,P-w-x);const k=M?Math.max(XD(i)+C,M.height):0;const v=gV(i);const T=e.topAxis?v:0;const A=Math.max(0,...[...m.values()].map(K=>(K.height-K.lineHeight)/2));const R=Hn.padding+k+T+A;const I=K=>w+(K-t.timeMin)/p*E;const L=[];const $=[];const B=[];let F=R;const z=(K,Z)=>Math.max(a,Math.ceil(s/2+(K-.5)*Z)+Hn.rowGap);const _=Math.max(i.nodeLabelFontSize*1.3,...[...u.values()].map(K=>K.block.lineHeight));const H=Math.max(i.groupHeaderFontSize*1.3,...[...f.values()].map(K=>K.block.lineHeight));for(let K=0;K<e.sections.length;K++){const Z=e.sections[K];const Q=d.get(K)??[];if(Q.length===0&&Z.label===void 0)continue;const se=B.length;const te=F;const ee=$.length;const ae=f.get(K)?.lines;if(Z.label!==void 0)F+=z(ae?.length??1,H);const ie=r?kV(Q):Q.map((ye,Se)=>Se);const oe=Q.length===0?0:Math.max(...ie)+1;const ue=[];if(r){for(let ye=0;ye<oe;ye++){ue.push({barIndexes:[],sectionIndex:se,y:F+ye*a,h:s})}}else{let ye=F;for(const Se of Q){ue.push({barIndexes:[],sectionIndex:se,y:ye,h:s});ye+=z(u.get(Se.index)?.lines.length??1,_)}}Q.forEach((ye,Se)=>{const Te=ie[Se];const Ie=ue[Te];const Ee=I(ye.start);const ve=Math.max(ye.renderEnd>ye.start?2:0,I(ye.renderEnd)-Ee);const $e=ye.tags.includes("milestone");let De;if($e){const me=s/2;const de=w+me;const be=Math.max(de,w+E-me);De=Math.min(be,Math.max(de,Ee+ve/2))}const fe=u.get(ye.index)?.lines;L.push({taskIndex:ye.index,id:ye.id,label:ye.label,labelBlock:u.get(ye.index)?.block,tags:ye.tags,sectionIndex:se,x:Ee,y:Ie.y,w:ve,h:s,milestoneX:De,rowIndex:ee+(Z.label!==void 0?1:0)+Te,start:ye.start,end:ye.renderEnd,...fe&&fe.length>1?{labelLines:fe}:{}});Ie.barIndexes.push(L.length-1)});$.push(...ue);if(r){F+=oe*a}else{for(const ye of Q)F+=z(u.get(ye.index)?.lines.length??1,_)}B.push({label:Z.label,labelBlock:f.get(K)?.block,y:te,h:F-te,rowStart:ee,rowEnd:$.length,...ae&&ae.length>1?{labelLines:ae}:{}});F+=Hn.sectionGap}const D=Math.max(a,F-R,o?o.height+Hn.padding:0);const j=R+D+v+Hn.padding;const W=g.map(K=>({time:K.time,x:I(K.time),label:K.label,labelBlock:K.block}));const O=l.map(K=>({taskIndex:K.index,label:K.label,labelBlock:m.get(K.index),x:I(K.start+(K.renderEnd-K.start)/2),time:K.start}));const N=n.today!==void 0&&n.today>=t.timeMin&&n.today<=t.timeMax?I(n.today):void 0;const G=[];if(e.excludes.length>0&&t.dateOnly&&(t.timeMax-eh(t.timeMin))/An<=hV){let K;const Z=Q=>{if(K===void 0)return;const se=Math.max(K,t.timeMin);const te=Math.min(Q,t.timeMax);if(te>se)G.push({x:I(se),w:I(te)-I(se),start:se,end:te});K=void 0};for(let Q=eh(t.timeMin);Q<t.timeMax;Q+=An){if(t.isExcludedDay(Q)){if(K===void 0)K=Q}else{Z(Q)}}Z(t.timeMax)}const Y=new Set(t.analysis?.criticalPathTaskIds??[]);const q=t.tasks.filter(K=>K.id!==void 0&&Y.has(K.id)).map(K=>K.index);const V=TV(e,t,L,$,{x:w,y:R,w:E,h:D},i,n.renderOptions);const ne=new Map(e.tasks.flatMap(K=>K.id?[[K.id,K.index]]:[]));const X=e.clicks.flatMap(K=>{if(K.action!=="href")return[];const Z=ne.get(K.taskId);const Q=K.rest.match(/^"((?:\\.|[^"])*)"|^(\S+)/)?.slice(1).find(Boolean);if(Z===void 0||!Q||!/^(?:https?:|mailto:)/i.test(Q))return[];return[{taskIndex:Z,href:Q.replace(/\\(["\\])/g,"$1")}]});const U=new Map;for(const K of L){const Z=U.get(K.y)??[];Z.push(K);U.set(K.y,Z)}for(const K of U.values()){K.sort((Z,Q)=>Z.x-Q.x);K.forEach((Z,Q)=>{const se=Z.labelBlock;if(!se)return;const te=Z.y+Z.h/2;const ee=Q>0?K[Q-1].x+K[Q-1].w+4:2;const ae=Q+1<K.length?K[Q+1].x-4:P-2;Z.labelPosition=!r?{x:16,y:te,anchor:"start"}:Z.x-6-se.width>=ee?{x:Z.x-6,y:te,anchor:"end"}:Z.x+Z.w+6+se.width<=ae?{x:Z.x+Z.w+6,y:te,anchor:"start"}:{x:16,y:te,anchor:"start"}})}return{...o?{emptyLabel:o}:{},title:M?.text,titleBlock:M,titleY:Math.max(n1(i),(M?.lineHeight??0)/2)+C/2,width:P,height:j,plot:{x:w,y:R,w:E,h:D},labelColumnWidth:h,rows:$,sections:B,bars:L,links:X,verts:O,ticks:W,dependencies:V,criticalTaskIndexes:q,excludedBands:G,topAxis:e.topAxis,todayX:N,...e.todayMarker?.style!==void 0?{todayMarkerStyle:e.todayMarker.style}:{},timeMin:t.timeMin,timeMax:t.timeMax,dateOnly:t.dateOnly,compact:r,barHeight:s}}function VD(e,t,n={}){const i=u0(KL(e),t);const r=pA(i,n.clock);const o=UD(i,r,{...n.layout,today:r.today});return{model:i,schedule:r,positioned:o}}var KD={barRadius:3};var JD={plain:"0.6",critical:"0.95"};function LV(e){return{groupFill:e.groupFillColor??"var(--surface, var(--fg))",groupOpacity:e.groupFillColor?"1":"0.07",excludedFill:e.edgeStrokeColor??"var(--muted, var(--line, var(--fg)))",edgeStroke:e.edgeStrokeColor??"var(--line, var(--border, var(--fg)))",nodeFill:e.nodeFillColor??"var(--accent, var(--fg))",nodeBorder:e.nodeBorderColor??"var(--fg)",doneFill:e.nodeFillColor??"var(--muted, var(--line, var(--fg)))",criticalFill:e.nodeFillColor??"var(--fg)",criticalStroke:e.nodeBorderColor??e.edgeStrokeColor??"var(--accent, var(--fg))",titleFill:e.groupTextColor??e.nodeTextColor??"var(--_text)",groupText:e.groupTextColor??e.nodeTextColor??"var(--_text)",taskText:e.nodeTextColor??"var(--_text)",axisText:e.edgeTextColor??e.groupTextColor??"var(--_text-muted)"}}function AV(e){if(e.includes("crit"))return"gantt-bar gantt-bar-crit";if(e.includes("active"))return"gantt-bar gantt-bar-active";if(e.includes("done"))return"gantt-bar gantt-bar-done";return"gantt-bar"}function QD(e){if(e.includes("crit"))return"crit";if(e.includes("active"))return"active";if(e.includes("done"))return"done";return void 0}function IV(e,t,n){const i={stroke:n.nodeBorderColor?t.nodeBorder:"none",...n.nodeBorderColor?{strokeWidth:String(n.nodeLineWidth)}:{}};switch(e){case"crit":return{fill:t.criticalFill,stroke:t.criticalStroke,strokeWidth:String(Math.max(1.5,n.nodeLineWidth)),opacity:"0.95"};case"active":return{fill:t.nodeFill,stroke:t.nodeBorder,strokeWidth:String(Math.max(1.5,n.nodeLineWidth)),opacity:"1"};case"done":return{fill:t.doneFill,...i,opacity:n.nodeFillColor?"0.72":"0.55"};default:return{fill:t.nodeFill,...i,opacity:"0.92"}}}function Bo(e,t,n,i,r,o,s,a,l,c,d="start",u=0,f,h){return e.text({id:t,role:n,text:o,x:Wt(i),y:Wt(r),fontSize:a,block:h,fontWeight:l,letterSpacing:u,display:"literal",anchor:d,paint:{fill:c},channels:f,attributes:{className:s},...h?{}:{baselineShift:0,dominantBaseline:"middle"}})}function ZD(e){if(!e)return{};const t=e.lineWidth===void 0?void 0:e.cue==="outline"?e.lineWidth+1:e.cue==="double-line"?e.lineWidth+2:e.lineWidth;const n=e.cue==="pattern"?"3 2":e.cue==="double-line"?"8 2 2 2":void 0;return{...e.fillColor!==void 0?{fill:e.fillColor}:{},...e.strokeColor??e.borderColor?{stroke:e.strokeColor??e.borderColor}:{},...t!==void 0?{strokeWidth:String(t)}:{},...n!==void 0?{strokeDasharray:n}:{}}}function eO(e,t,n,i){return{className:e,data:{task:t,...n?.cue&&n.cue!=="none"?{"brand-cue":n.cue}:{},...i?{href:i}:{}}}}function Wt(e){return Math.round(e*100)/100}function FV(e,t){const{positioned:n,colors:i,resolved:r}=t;const o=r.renderOptions;const s=i.font??"Inter";const a=o.transparent??false;const l=e1(o,r.styleFace);const c=LV(l);const d=[];const u=o.gantt??{};const f={dependencyArrows:u.dependencyArrows===true&&n.dependencies.length>0,criticalBars:u.criticalPath===true&&n.criticalTaskIndexes.length>0,criticalArrows:u.dependencyArrows===true&&u.criticalPath===true&&n.dependencies.some(F=>F.critical)};const h=new Set(f.criticalBars?n.criticalTaskIndexes:[]);d.push(e.documentOpen({id:"prelude",width:n.width,height:n.height,colors:i,transparent:a,font:s,hasMonoFont:false},Ot(n.width,n.height,i,a)+"\n"+Dt(s,false,i.shadow,i.embedFontImport)));const m=en(i);if(m)d.push(e.definitions({id:"shadow-defs"},`<defs>${m}</defs>`));const p=`${NV(n)}-dep-arrow`;const g=`${p}-crit`;const y=[Nx(p,c.edgeStroke),...f.criticalArrows?[Nx(g,c.criticalStroke)]:[]];if(f.dependencyArrows){d.push(e.definitions({id:"defs",markerResources:y},`<defs>
28
+ ${mi(y)}
29
+ </defs>`))}const w=n.plot;const S=w.y+w.h;const x=new Map;n.sections.forEach((F,z)=>{if(z%2===0){const _=F.label??"";const H=x.get(_)??0;x.set(_,H+1);d.push(e.shape({id:`section-band:${_}#${H}`,role:"section",geometry:{kind:"rect",x:Wt(w.x),y:Wt(F.y),width:Wt(w.w),height:Wt(F.h)},paint:{fill:c.groupFill,opacity:c.groupOpacity},channels:F.label!==void 0?{category:F.label}:void 0,attributes:{className:"gantt-section-band"}}))}});const M={fill:c.excludedFill,opacity:"0.1"};for(const F of n.excludedBands){d.push(e.shape({id:`excluded:${F.start}`,role:"grid",geometry:{kind:"rect",x:Wt(F.x),y:Wt(w.y),width:Wt(F.w),height:Wt(w.h)},paint:M,attributes:{className:"gantt-excluded-band"}}))}const b={stroke:c.edgeStroke,strokeWidth:String(l.lineWidth),opacity:l.edgeStrokeColor?"0.6":"0.45"};for(const F of n.ticks){d.push(e.shape({id:`grid:${F.time}`,role:"grid",geometry:{kind:"line",x1:Wt(F.x),y1:Wt(w.y),x2:Wt(F.x),y2:Wt(S)},paint:b,attributes:{className:"gantt-grid-line"}}))}const C=i1(l);const P=C===10&&l.edgeLabelFontSize===11?12:Math.max(12,C);for(const F of n.ticks){const z=F.labelBlock?.text??gi(F.label,l.edgeTextTransform);d.push(Bo(e,`axis:${F.time}:bottom`,"axis",F.x,S+P,z,"gantt-axis-label",l.edgeLabelFontSize,l.edgeLabelFontWeight,c.axisText,"middle",l.edgeLetterSpacing,void 0,F.labelBlock));if(n.topAxis){d.push(Bo(e,`axis:${F.time}:top`,"axis",F.x,w.y-C,z,"gantt-axis-label",l.edgeLabelFontSize,l.edgeLabelFontWeight,c.axisText,"middle",l.edgeLetterSpacing,void 0,F.labelBlock))}}const E=l.groupHeaderFontSize*1.3;const k=l.nodeLabelFontSize*1.3;const v=new Map;for(const F of n.sections){if(F.label!==void 0){const z=v.get(F.label)??0;v.set(F.label,z+1);const _=F.labelBlock?.lines??F.labelLines??[gi(F.label,l.groupTextTransform)];_.forEach((H,D)=>{const j=D===0?`section-label:${F.label}#${z}`:`section-label:${F.label}#${z}/${D}`;d.push(Bo(e,j,"section",8,F.y+n.barHeight/2+4+D*(F.labelBlock?.lineHeight??E),H,"gantt-section-label",l.groupHeaderFontSize,l.groupHeaderFontWeight,c.groupText,"start",l.groupLetterSpacing,{category:F.label},Ux(F.labelBlock,D)))})}}const T=new Map;const A=F=>{const z=T.get(F)??0;T.set(F,z+1);return z===0?`task-label:${F}`:`task-label:${F}#${z}`};if(!n.compact){for(const F of n.bars){const z=F.labelBlock?.lines??F.labelLines??[gi(F.label,l.nodeTextTransform)];const _=A(F.id??F.label);z.forEach((H,D)=>{const j=D===0?_:`${_}/${D}`;d.push(Bo(e,j,"label",F.labelPosition?.x??16,(F.labelPosition?.y??F.y+F.h/2)+D*(F.labelBlock?.lineHeight??k),H,"gantt-task-label",l.nodeLabelFontSize,l.nodeLabelFontWeight,c.taskText,"start",l.nodeLetterSpacing,void 0,Ux(F.labelBlock,D)))})}}else{const F=new Map;for(const z of n.bars){const _=F.get(z.y)??[];_.push(z);F.set(z.y,_)}for(const z of F.values()){z.sort((_,H)=>_.x-H.x);z.forEach((_,H)=>{const D=_.labelBlock??Be(_.label,{display:"literal",transform:l.nodeTextTransform,fontSize:l.nodeLabelFontSize,fontWeight:l.nodeLabelFontWeight,letterSpacing:l.nodeLetterSpacing});const j=D.text;const W=D.width;const O=_.y+_.h/2;if(_.labelPosition){d.push(Bo(e,A(_.id??_.label),"label",_.labelPosition.x,_.labelPosition.y,j,"gantt-task-label",l.nodeLabelFontSize,l.nodeLabelFontWeight,c.taskText,_.labelPosition.anchor,l.nodeLetterSpacing,void 0,D));return}const N=H>0?z[H-1].x+z[H-1].w+4:2;const G=H+1<z.length?z[H+1].x-4:n.width-2;if(_.x-6-W>=N){d.push(Bo(e,A(_.id??_.label),"label",_.x-6,O,j,"gantt-task-label",l.nodeLabelFontSize,l.nodeLabelFontWeight,c.taskText,"end",l.nodeLetterSpacing,void 0,D))}else if(_.x+_.w+6+W<=G){d.push(Bo(e,A(_.id??_.label),"label",_.x+_.w+6,O,j,"gantt-task-label",l.nodeLabelFontSize,l.nodeLabelFontWeight,c.taskText,"start",l.nodeLetterSpacing,void 0,D))}else{d.push(Bo(e,A(_.id??_.label),"label",16,O,j,"gantt-task-label",l.nodeLabelFontSize,l.nodeLabelFontWeight,c.taskText,"start",l.nodeLetterSpacing,void 0,D))}})}}const R=new Map;const I=F=>{const z=R.get(F)??0;R.set(F,z+1);return z===0?`task:${F}`:`task:${F}#${z}`};const L=new Map(n.links.map(F=>[F.taskIndex,F.href]));for(const F of n.bars){const z=n.sections[F.sectionIndex]?.label;const _=o.security==="strict"?void 0:L.get(F.taskIndex);const H=F.id??F.label;const D=h.has(F.taskIndex);const j=D?" gantt-bar-critical-path":"";const W=D?{stroke:c.criticalStroke,strokeWidth:String(Math.max(2,l.nodeLineWidth*1.5))}:{};if(F.milestoneX!==void 0){const q=F.milestoneX;const V=F.y+F.h/2;const ne=F.h/2;const X=QD(F.tags);const U="gantt-milestone"+(X!==void 0?` gantt-milestone-${X}`:"")+j;const K=`M ${Wt(q)} ${Wt(V-ne)} L ${Wt(q+ne)} ${Wt(V)} L ${Wt(q)} ${Wt(V+ne)} L ${Wt(q-ne)} ${Wt(V)} Z`;const Z=X==="crit"?{fill:c.criticalFill,stroke:c.criticalStroke,strokeWidth:String(Math.max(1.5,l.nodeLineWidth))}:X==="active"?{fill:c.nodeFill,stroke:c.nodeBorder,strokeWidth:String(Math.max(1.5,l.nodeLineWidth)),opacity:"1"}:X==="done"?{fill:c.doneFill,stroke:c.nodeBorder,strokeWidth:String(Math.max(1,l.nodeLineWidth)),opacity:l.nodeFillColor?"0.72":"0.55"}:{fill:c.nodeFill,stroke:c.nodeBorder,strokeWidth:String(Math.max(1,l.nodeLineWidth))};const Q={...X!==void 0?{status:X}:{},...X==="done"?{progress:1}:{},...D?{emphasis:true}:{},...z!==void 0?{category:z}:{}};const se=It(r.styleFace,"milestone",Q,{includeFallback:false});const te={...Z,...ZD(se),...W};d.push(e.shape({id:I(H),role:"milestone",geometry:{kind:"path",d:K},paint:te,channels:Q,attributes:eO(U,H,se,_)}));continue}const O=QD(F.tags);const N={...O!==void 0?{status:O}:{},...O==="done"?{progress:1}:{},...D?{emphasis:true}:{},...z!==void 0?{category:z}:{}};const G=It(r.styleFace,"task",N,{includeFallback:false});const Y={...IV(O,c,l),...ZD(G),...W};d.push(e.shape({id:I(H),role:"task",geometry:{kind:"rect",x:Wt(F.x),y:Wt(F.y),width:Wt(Math.max(2,F.w)),height:Wt(F.h),rx:KD.barRadius,ry:KD.barRadius},paint:Y,channels:N,attributes:eO(`${AV(F.tags)}${j}`,H,G,_)}))}if(f.dependencyArrows){const F=new Map(n.bars.map(_=>[_.taskIndex,_]));const z=new Map;for(const _ of n.dependencies){const H=tO(F.get(_.fromTaskIndex));const D=tO(F.get(_.toTaskIndex));const j=`${H}->${D}:${_.kind}`;const W=z.get(j)??0;z.set(j,W+1);const O=f.criticalArrows&&_.critical;const N=O?"gantt-dep-arrow gantt-dep-arrow-crit":"gantt-dep-arrow";const G=O?g:p;const Y=_.points.map(X=>({x:Wt(X.x),y:Wt(X.y)}));const q=Y.map((X,U)=>`${U===0?"M":"L"} ${X.x} ${X.y}`).join(" ");const V=W===0?`dep:${j}`:`dep:${j}#${W}`;const ne=e.connector({id:V,role:"edge",geometry:{kind:"path",d:q,points:Y},lineStyle:"solid",paint:O?{stroke:c.criticalStroke,strokeWidth:String(fu(l.lineWidth,true))}:{stroke:c.edgeStroke,strokeWidth:String(fu(l.lineWidth,false))},markers:{mid:[],end:y.find(X=>X.id===G)},endpoints:{from:H,to:D},relationship:{kind:_.kind,direction:"forward"},route:{ownership:"layout"},channels:O?{status:"crit",emphasis:true}:void 0,attributes:{className:N}});d.push(e.group({id:`${V}:fade`,role:"chrome",open:"<g>",close:"</g>",paint:{opacity:O?JD.critical:JD.plain},children:[{node:ne,indent:0}]}))}}const $={stroke:c.edgeStroke,strokeWidth:String(Math.max(2,l.lineWidth)),strokeDasharray:"6 3"};const B=new Map;for(const F of n.verts){const z=B.get(F.label)??0;B.set(F.label,z+1);d.push(e.shape({id:`vert:${F.label}#${z}`,role:"marker-line",geometry:{kind:"line",x1:Wt(F.x),y1:Wt(w.y),x2:Wt(F.x),y2:Wt(S)},paint:$,attributes:{className:"gantt-vert-marker"}}));const _=F.labelBlock?.text??gi(F.label,l.edgeTextTransform);const H=n.topAxis?Math.max(24,C+l.edgeLabelFontSize*1.25):C===10&&l.edgeLabelFontSize===11?8:C;d.push(Bo(e,`vert-label:${F.label}#${z}`,"axis",F.x,w.y-H,_,"gantt-axis-label",l.edgeLabelFontSize,Math.max(l.edgeLabelFontWeight,600),c.axisText,"middle",l.edgeLetterSpacing,void 0,F.labelBlock))}if(n.todayX!==void 0){const F=n.todayMarkerStyle!==void 0?wg(n.todayMarkerStyle):void 0;const z=Object.fromEntries(F?.applied??[]);d.push(e.shape({id:"today-marker",role:"marker-line",geometry:{kind:"line",x1:Wt(n.todayX),y1:Wt(w.y),x2:Wt(n.todayX),y2:Wt(S)},paint:{stroke:z["stroke"]??l.edgeStrokeColor??"var(--accent, var(--fg))",strokeWidth:z["stroke-width"]??String(Math.max(2,l.lineWidth)),strokeDasharray:z["stroke-dasharray"]??"4 3",...z["opacity"]!==void 0?{opacity:z["opacity"]}:{}},attributes:{className:"gantt-today-marker"}}))}if(n.title){const F=n.titleBlock?.text??gi(n.title,l.groupTextTransform);const z=n.titleY??n1(l);d.push(Bo(e,"title","title",n.width/2,z,F,"gantt-title",Zh(l),t1(l),c.titleFill,"middle",l.groupLetterSpacing,void 0,n.titleBlock))}if(n.emptyLabel){const F=n.emptyLabel;d.push(Bo(e,"empty-state","label",w.x+w.w/2,w.y+w.h/2,F.text,"gantt-empty-state",F.fontSize,F.fontWeight,c.axisText,"middle",F.letterSpacing,void 0,F))}d.push(e.documentClose());return{family:"gantt",width:n.width,height:n.height,colors:i,transparent:a,parts:d}}function NV(e){return`gantt-${pi(e.width,e.height,...e.bars.map(t=>`${t.taskIndex}:${t.id??t.label}`),...e.dependencies.map(t=>`${t.fromTaskIndex}>${t.toTaskIndex}:${t.kind}`))}`}function tO(e){return e===void 0?"":e.id??e.label}var nO=gt(FV);var qTe={configDiagnostics:HD,normalizeRequest:e=>({familyConfig:{config:Wf(e.source.frontmatter)}}),layout:e=>{const t=e.familyConfig?.config??Wf(void 0);const n=VD(e.source.familyLines,t,{clock:{today:e.renderOptions.ganttToday},layout:{renderOptions:e.renderOptions,...e.styleFace?{styleFace:e.styleFace}:{}}});return ht(n.positioned)},projectPositioned:ut(BI),lowerScene:ft(nO)};var $V={showBranches:lt,showCommitLabel:lt,parallelCommits:lt,rotateCommitLabel:lt,mainBranchName:wd,mainBranchOrder:Yp};var iO=e=>xt("gitgraph",e,$V);function rO(e){const t=e&&typeof e==="object"&&!Array.isArray(e)?e:{};const n={commitLabelFontSize:ax(t)};for(let i=0;i<8;i++){for(const r of[`git${i}`,`gitBranchLabel${i}`,`gitInv${i}`]){const o=Zn(t[r]);if(o!==void 0)n[r]=o}}for(const i of["commitLabelColor","commitLabelBackground"]){const r=Zn(t[i]);if(r!==void 0)n[i]=r}return n}function _V(e,t){const{positioned:n,colors:i,resolved:r}=t;const o=r.renderOptions;const s=i.font??"Inter";const a=o.transparent??false;const l="gitgraph-title";const c="gitgraph-desc";const d=ki(n.accessibilityTitle??"Git graph",n.accessibilityDescription,l,c,"git graph");const u=[Ot(n.width,n.height,i,a,{attrs:d}),Dt(s,false,i.shadow,i.embedFontImport)];const f=en(i);if(f)u.push(`<defs>${f}</defs>`);const h=r.familyAppearance;if(!h)throw new Error("GitGraph rendering requires request-boundary family appearance resolution");const m=h.themeVariables;const p=BV(n,m,i);const g=[e.documentOpen({id:"prelude",width:n.width,height:n.height,colors:i,transparent:a,font:s,hasMonoFont:false},u.join("\n"))];g.push(e.documentText({id:"acc-title",element:"title",domId:l,text:n.accessibilityTitle??"Git graph"}));if(n.accessibilityDescription)g.push(e.documentText({id:"acc-desc",element:"description",domId:c,text:n.accessibilityDescription}));if(n.title){const w=n.titleBlock??Pr(n.title,16,600);g.push(e.text({id:"gitgraph-visible-title",role:"title",identity:{id:"gitgraph-title",classNames:["gitgraph-title"]},text:w.text,block:w,x:n.width/2,y:8+(n.titleBlock?.fontSize??16)*.65+((n.titleBlock?.height??0)-(n.titleBlock?.lineHeight??0))/2,fontSize:w.fontSize,anchor:"middle",paint:{fill:"var(--_text)"},attributes:{className:"gitgraph-title"}}))}if(n.showBranches){for(const w of n.branches){const S=zc("branch",w.name);const x=p.branches.get(w.name);const M=Et(n.direction==="LR"?w.x1-10:w.x1);const b=Et(n.direction==="LR"?w.y1:w.y1-16);const C=w.labelBlock??Pr(w.name,12,600);const P=C.height-C.lineHeight;const E=Et(C.width+10);const k=Et(n.direction==="LR"?M-E:M-E/2);g.push(e.group({id:S,role:"group",channels:{category:w.name},open:`<g class="git-branch" data-id="${Ye(S)}" data-branch="${Ye(w.name)}">`,close:"</g>",children:[{node:e.shape({id:xn(S,"label-bg"),role:"chrome",geometry:{kind:"rect",x:k,y:Et(b-C.fontSize-1-P/2),width:E,height:Et(C.fontSize+6+P),rx:4,ry:4},paint:{fill:x.labelBackground,stroke:x.line,strokeWidth:"1"},attributes:{className:"git-branch-label-background"}}),indent:2},{node:e.shape({id:xn(S,"line"),role:"rail",geometry:{kind:"line",x1:Et(w.x1),y1:Et(w.y1),x2:Et(w.x2),y2:Et(w.y2)},paint:{stroke:x.line,strokeWidth:"3"},channels:{category:w.name},attributes:{className:"git-branch-line",data:{branch:w.name}}}),indent:2},{node:e.text({id:xn(S,"label"),role:"label",text:C.text,block:C,x:M,y:b-C.fontSize*.35,fontSize:C.fontSize,anchor:n.direction==="LR"?"end":"middle",paint:{fill:x.label},channels:{category:w.name},attributes:{className:"git-branch-label",data:{branch:w.name}}}),indent:2}]}))}}const y=new Map(n.commits.map(w=>[w.id,w]));for(const w of n.edges){const S=y.get(w.to)?.branch;const x=S?p.branches.get(S)?.line??"var(--_line)":"var(--_line)";g.push(e.connector({id:mm(w.from,w.to),role:"edge",geometry:{kind:"polyline",points:w.points.map(M=>({x:Et(M.x),y:Et(M.y)}))},lineStyle:w.kind==="cherry-pick"?"dashed":"solid",paint:{fill:"none",stroke:x,strokeWidth:w.kind==="parent"?"2":"2.5",...w.kind==="cherry-pick"?{strokeDasharray:"4 3"}:{}},endpoints:{from:w.from,to:w.to},relationship:{kind:w.kind,direction:"forward"},route:{ownership:"layout"},channels:{category:w.kind},attributes:{className:`git-edge git-edge-${w.kind}`}}))}for(const w of n.commits)g.push(DV(e,w,n,p));g.push(e.documentClose());return{family:"gitgraph",width:n.width,height:n.height,colors:i,transparent:a,parts:g}}function DV(e,t,n,i){const r=t.customType??t.type;const o=OV(t);const s=i.branches.get(t.branch);const a=r==="HIGHLIGHT"?s.highlight:r==="MERGE"?s.line:s.normalFill;const l=s.line;const c=[{node:e.shape({id:xn(t.id,"shape"),role:"chrome",geometry:o,paint:{fill:a,stroke:l,strokeWidth:"2"},channels:{status:r.toLowerCase(),category:t.branch}}),indent:2}];if(r==="MERGE"){c.push({node:e.shape({id:xn(t.id,"inner"),role:"chrome",geometry:{kind:"circle",cx:Et(t.x),cy:Et(t.y),r:5},paint:{fill:"none",stroke:"var(--bg)",strokeWidth:"1.5"}}),indent:2})}if(r==="REVERSE"){for(const u of[-1,1])c.push({node:e.shape({id:xn(t.id,"cross",u),role:"chrome",geometry:{kind:"line",x1:Et(t.x-6),y1:Et(t.y+u*6),x2:Et(t.x+6),y2:Et(t.y-u*6)},paint:{stroke:"var(--_arrow)",strokeWidth:"2"}}),indent:2})}if(n.showCommitLabel){const u=t.labelBlock??Pr(xa(t),i.commitLabelFontSize,500);const f=u.text;const h=u.height-u.lineHeight;const m=n.direction==="LR"?t.x:t.x+14;const p=t.y+Ka(u,n.direction);const g=n.direction==="LR"?"middle":"start";const y=n.direction==="LR"&&n.rotateCommitLabel?{kind:"rotate",angle:45,cx:Et(m),cy:Et(p)}:void 0;if(i.commitLabelBackground){const w=Et(Math.max(18,u.width+yh*2));const S=Et(g==="middle"?m-w/2:m-yh);c.push({node:e.shape({id:xn(t.id,"label-bg"),role:"chrome",geometry:{kind:"rect",x:S,y:Et(p-u.fontSize-h/2),width:w,height:Et(u.fontSize+6+h),rx:3,ry:3},paint:{fill:i.commitLabelBackground,fillOpacity:"0.94",stroke:s.line,strokeWidth:"0.75"},transform:y,attributes:{className:"git-commit-label-background"}}),indent:2})}c.push({node:e.text({id:xn(t.id,"label"),role:"label",text:f,block:u,x:m,y:p-u.fontSize*.35,fontSize:u.fontSize,anchor:g,paint:{fill:i.commitLabelColor},transform:y,attributes:{className:"git-commit-label"}}),indent:2})}const d=t.tagBlocks??t.tags.map(u=>Pr(u,10,600));t.tags.forEach((u,f)=>{const h=d[f];const m=h.height-h.lineHeight;const p=t.x+14;const g=t.y+Sy(d,f);const y=Et(h.width+10);c.push({node:e.shape({id:xn(t.id,"tag-bg",f),role:"chrome",geometry:{kind:"rect",x:Et(p-4),y:Et(g-h.fontSize-1-m/2),width:y,height:Et(h.fontSize+5+m),rx:4,ry:4},paint:{fill:s.labelBackground,stroke:s.line,strokeWidth:"0.75"},attributes:{className:"git-tag-background"}}),indent:2});c.push({node:e.text({id:xn(t.id,"tag",f),role:"label",text:h.text,block:h,x:p,y:g-h.fontSize*.35,fontSize:h.fontSize,anchor:"start",paint:{fill:s.label},attributes:{className:"git-tag"}}),indent:2})});return e.group({id:t.id,role:"node",channels:{status:r.toLowerCase(),category:t.branch},open:`<g class="git-commit type-${r.toLowerCase()}" data-id="${Ye(t.id)}" data-branch="${Ye(t.branch)}" data-commit-type="${t.type}"${r!==t.type?` data-visual-type="${r}"`:""}>`,close:"</g>",children:c})}function OV(e){const t=e.customType??e.type;if(t==="HIGHLIGHT")return{kind:"rect",x:Et(e.x-9),y:Et(e.y-9),width:18,height:18,rx:2,ry:2};if(t==="CHERRY_PICK")return{kind:"polygon",points:[{x:Et(e.x),y:Et(e.y-10)},{x:Et(e.x+10),y:Et(e.y)},{x:Et(e.x),y:Et(e.y+10)},{x:Et(e.x-10),y:Et(e.y)}]};return{kind:"circle",cx:Et(e.x),cy:Et(e.y),r:t==="MERGE"?10:8}}function BV(e,t,n){const i=t&&typeof t==="object"&&!Array.isArray(t)?t:{};const r=typeof n.accent==="string"?n.accent:"#3b82f6";const o=typeof n.bg==="string"?n.bg:"#ffffff";const s=/^#[0-9a-f]{6}$/i.test(r)?r:"#3b82f6";const a=/^#[0-9a-f]{6}$/i.test(o)?o:"#ffffff";const l=Zi(e.branches.length,e.branches.length<=6?{accent:s,bg:a}:{accent:r,bg:o});const c=new Map;e.branches.forEach((u,f)=>{const h=f%8;const m=Zn(i[`git${h}`])??l[f];const p=Zn(i[`gitBranchLabel${h}`])??m;const g=Zn(i[`gitInv${h}`])??m;const y=Nn(m)&&Nn(a)?tr(m,a,18):"var(--_node-fill)";const w=Nn(m)&&Nn(a)?tr(m,a,9):"var(--bg)";const S=yu(p,w,4.5,n.fg);c.set(u.name,{line:m,label:S,highlight:g,normalFill:y,labelBackground:w})});const d=ax(i);return{branches:c,commitLabelColor:Zn(i.commitLabelColor)??"var(--_text-sec)",commitLabelBackground:Zn(i.commitLabelBackground)??(Nn(a)?a:"var(--bg)"),commitLabelFontSize:d}}function Et(e){return Math.round(e*1e3)/1e3}var oO=gt(_V);var yLe={configDiagnostics:iO,statementEnds:$b,normalizeRequest:e=>({familyConfig:{position:KM(e.source.config.gitGraph,e.source.config.themeVariables),...typeof e.source.frontmatter.title==="string"?{title:e.source.frontmatter.title}:{}},appearance:{family:{themeVariables:rO(e.source.config.themeVariables)}}}),layout:e=>{const t=e.familyConfig;const n=t?.position??KM(void 0);const i=Vr(QP(e.source.familyBody,{mainBranchName:n.mainBranchName,mainBranchOrder:n.mainBranchOrder,title:t?.title}),e.source.accessibility);return ht(X$(i,n,e.renderOptions,e.styleFace),{injectAccessibility:false})},projectPositioned:ut(GI),lowerScene:ft(oO)};var WV=Object.fromEntries([...["diagramMarginX","diagramMarginY","leftMargin","maxLabelWidth","width","height","taskMargin"].map(e=>[e,Jt]),...["taskFontSize","titleFontSize"].map(e=>[e,sT]),...["taskFontFamily","titleFontFamily"].map(e=>[e,oT]),["titleColor",wd],...["actorColours","sectionFills","sectionColours"].map(e=>[e,wf]),["useMaxWidth",lt]]);var sO=e=>xt("journey",e,WV);var ot={paddingX:32,paddingY:28,titleFontSize:18,titleFontWeight:600,titleGap:22,sectionFontSize:12,sectionFontWeight:600,sectionHeaderMinHeight:36,sectionHeaderPadX:16,sectionTaskGap:30,sectionSpanPadX:10,sectionGap:8,legendGap:26,legendMinWidth:96,legendTitleGap:26,legendRowGap:22,legendDotRadius:5,legendDotLabelGap:12,scoreLabelGutter:22,scoreLabelGap:12,taskGap:26,taskMinWidth:124,taskMinHeight:58,taskFontSize:13,taskFontWeight:500,taskPadX:14,taskPadY:12,actorDotRadius:4,actorDotGap:8,taskToGuideGap:56,scoreStep:40,markerRadius:16,baselineGap:32,baselineClearance:6,arrowOverhang:28,minPlotWidth:200};var aO={nodeLabelFontSize:ot.taskFontSize,edgeLabelFontSize:11,groupHeaderFontSize:ot.sectionFontSize,nodeLabelFontWeight:ot.taskFontWeight,edgeLabelFontWeight:600,groupHeaderFontWeight:ot.sectionFontWeight,nodePaddingX:ot.taskPadX,nodePaddingY:ot.taskPadY,nodeCornerRadius:5,nodeLineWidth:et.outerBox,edgeLineWidth:et.connector,groupCornerRadius:6,groupPaddingX:ot.sectionHeaderPadX,groupPaddingY:10,groupLabelPaddingX:ot.sectionHeaderPadX,groupLineWidth:et.outerBox};function zV(e){const t=e.mermaidConfig?.journey;const n=dO(t?.titleFontSize,ot.titleFontSize);const i={paddingX:Lc(t?.diagramMarginX,ot.paddingX),paddingY:Lc(t?.diagramMarginY,ot.paddingY),legendMinWidth:Lc(t?.leftMargin,ot.legendMinWidth),maxLabelWidth:Lc(t?.maxLabelWidth,360),taskGap:Lc(t?.taskMargin,ot.taskGap),taskMinWidth:Lc(t?.width,ot.taskMinWidth),taskMinHeight:Lc(t?.height,ot.taskMinHeight),titleFontSize:n,titleFontSizeCss:String(t?.titleFontSize??n),titleFontFamily:xo(t?.titleFontFamily),titleColor:YV(t?.titleColor),taskFontFamily:xo(t?.taskFontFamily),actorColours:t?.actorColours??[],sectionFills:t?.sectionFills??[],sectionColours:t?.sectionColours??[]};return{visual:i,styleDefaults:GV(t),useMaxWidth:t?.useMaxWidth===true}}function s1(e={}){return zV(e)}function GV(e){return{...aO,nodeLabelFontSize:dO(e?.taskFontSize,aO.nodeLabelFontSize)}}function cO(e,t,n={},i){const r=t.visual;const o=Ue(n,t.styleDefaults,i);const s=e.sections.some(_=>!!_.label);const a=e.title?Be(qe(e.title,e.titleContent),{transform:o.groupTextTransform,fontSize:r.titleFontSize,fontWeight:ot.titleFontWeight,letterSpacing:o.groupLetterSpacing,fontFamily:r.titleFontFamily}):void 0;const l=a?.text;const c=a;const d=jV(e).map(_=>{const H=Be(qe(_.value,_.content),{transform:o.edgeTextTransform,fontSize:o.edgeLabelFontSize,fontWeight:o.edgeLabelFontWeight,letterSpacing:o.edgeLetterSpacing,maxWidth:r.maxLabelWidth});return{raw:_.value,key:Ha(_.value,_.content),label:H.text,block:H}});const u=new Map(d.map((_,H)=>[_.key,H]));const f=d.map(_=>_.block);const h=Be("Actors",{transform:o.groupTextTransform,fontSize:o.groupHeaderFontSize,fontWeight:o.groupHeaderFontWeight,letterSpacing:o.groupLetterSpacing});const m=[5,4,3,2,1].map(_=>Be(String(_),{transform:o.edgeTextTransform,fontSize:o.edgeLabelFontSize,fontWeight:o.edgeLabelFontWeight,letterSpacing:o.edgeLetterSpacing}));const p=d.length>0?Math.max(r.legendMinWidth,ot.legendDotRadius*2+ot.legendDotLabelGap+Math.max(h.width,...f.map(_=>_.width))):0;const g=e.sections.map(_=>{const H=_.label??_.id;const D=It(i,"group-header",{category:H},{includeFallback:false});const j=D?.fontSize??o.groupHeaderFontSize;const W=D?.fontWeight??o.groupHeaderFontWeight;const O=D?.letterSpacing??o.groupLetterSpacing;const N=_.label?Be(qe(_.label,_.labelContent),{transform:D?.textTransform??o.groupTextTransform,fontSize:j,fontWeight:W,letterSpacing:O,fontFamily:D?.fontFamily??o.groupFont,maxWidth:r.maxLabelWidth}):void 0;const G=N?.text;const Y=N;const q=Y?.width??0;const V=Y?.height??0;const ne=_.tasks.map(U=>HV(qe(U.text,U.textContent),U.actors.length,o,r));const X=Math.max(r.taskMinWidth,q+ot.sectionHeaderPadX*2);return{category:H,label:G,block:N,labelWidth:q,labelHeight:V,tasks:ne,emptyWidth:X}});const y=Math.max(r.taskMinHeight,...g.flatMap(_=>_.tasks.map(H=>H.height)));let w=r.paddingY;if(c)w+=c.height+ot.titleGap;const S=s?Math.max(ot.sectionHeaderMinHeight,...g.map(_=>_.label?_.labelHeight+o.groupPaddingY*2:0)):0;const x=w;const M=Math.max(x+(s?S+ot.sectionTaskGap:0),d.length>0?ot.legendTitleGap-ot.legendDotRadius+h.height/2:0);const b=M+y+ot.taskToGuideGap;const C=ot.scoreStep*4;const P=b+C;const E=P+ot.baselineGap;const k=r.paddingX+p+(p>0?ot.legendGap:0)+Math.max(ot.scoreLabelGutter,...m.map(_=>_.width+ot.scoreLabelGap));let v=k;const T=[];for(let _=0;_<e.sections.length;_++){const H=e.sections[_];const D=g[_];const j=!!D.label;if(_>0)v+=ot.sectionGap;const W=D.tasks.length>0?D.tasks.reduce((q,V)=>q+V.width,0)+(D.tasks.length-1)*r.taskGap:0;const O=j?Math.max(W>0?W+ot.sectionSpanPadX*2:D.emptyWidth,D.labelWidth+ot.sectionHeaderPadX*2):Math.max(W,D.tasks.length===0?D.emptyWidth:0);const N=v;const G=[];let Y=N+(O-W)/2;for(let q=0;q<H.tasks.length;q++){const V=H.tasks[q];const ne=D.tasks[q];if(q>0)Y+=r.taskGap;const X=Y;const U=X+ne.width/2;const K=lO(V.score,b);const Z=qV(V,u,U,M+ne.height-o.nodePaddingY-ot.actorDotRadius);G.push({id:V.id,sectionId:H.id,text:ne.text,block:ne.block,score:V.score,actors:V.actors,x:X,y:M,width:ne.width,height:ne.height,textX:U,textY:M+o.nodePaddingY+ne.textHeight/2,centerX:U,track:{x:U,y1:M+ne.height,y2:E},marker:{cx:U,cy:K,r:ot.markerRadius,score:V.score},actorDots:Z});Y+=ne.width}v=N+O;T.push({id:H.id,category:D.category,label:D.label,block:D.block,x:N,y:x,width:O,height:j?S:0,labelX:N+O/2,labelY:x+S/2,framed:j,headerHeight:j?S:0,tasks:G})}const A=v+ot.arrowOverhang;const R=Math.max(A,k+ot.minPlotWidth);const I=Math.max(R,...T.map(_=>_.x+_.width));const L=Math.max(I+r.paddingX,c?c.width+2*r.paddingX:0);let $=M+ot.legendDotRadius;const B=d.map((_,H)=>{const D=f[H];const j={category:_.raw,key:_.key,label:_.label,block:_.block,x:r.paddingX+ot.legendDotRadius,y:$,colorIndex:H};const W=_.label.includes("\n");$+=W?Math.max(ot.legendRowGap,D.height+8):ot.legendRowGap;return j});const F=B.length>0?Math.max(...B.map(_=>_.y+Math.max(ot.legendDotRadius,(_.block?.height??0)/2))):0;const z=Math.max(E+ot.baselineClearance+r.paddingY,F+r.paddingY);return{width:L,height:z,title:l?{text:l,block:a,x:L/2,y:r.paddingY+c.height/2}:void 0,accessibilityTitle:e.accessibilityTitle,accessibilityDescription:e.accessibilityDescription,actors:B,actorLegendTitle:h,scoreGuide:{x:k,y:b,width:R-k,height:C,ticks:[5,4,3,2,1].map((_,H)=>{const D=lO(_,b);return{score:_,block:m[H],x1:k,x2:R,y:D,labelX:k-ot.scoreLabelGap,labelY:D}}),baseline:{x1:k,y1:E,x2:R,y2:E}},sections:T}}function HV(e,t,n,i){const r=Be(e,{transform:n.nodeTextTransform,fontSize:n.nodeLabelFontSize,fontWeight:n.nodeLabelFontWeight,letterSpacing:n.nodeLetterSpacing,fontFamily:i.taskFontFamily,maxWidth:i.maxLabelWidth});const o=r.text;const s=r;const a=t>0?t*ot.actorDotRadius*2+(t-1)*ot.actorDotGap:0;const l=Math.max(i.taskMinWidth,s.width+n.nodePaddingX*2,a+n.nodePaddingX*2);const c=t>0?ot.actorDotRadius*2:0;const d=Math.max(i.taskMinHeight,n.nodePaddingY*2+s.height+(c>0?12+c:0));return{text:o,block:r,textWidth:s.width,textHeight:s.height,actorDotsWidth:a,width:l,height:d}}function jV(e){const t=[];const n=new Set;for(const i of e.sections){for(const r of i.tasks){for(const[o,s]of r.actors.entries()){const a=Ha(s,r.actorContents?.[o]);if(n.has(a))continue;n.add(a);t.push({value:s,content:r.actorContents?.[o]})}}}return t}function dO(e,t){if(typeof e==="number"&&Number.isFinite(e)&&e>0)return e;if(typeof e!=="string")return t;const n=e.trim();const i=Number.parseFloat(n);if(!Number.isFinite(i)||i<=0)return t;if(/^[0-9.]+(?:px)?$/i.test(n))return i;if(/^[0-9.]+ex$/i.test(n))return i*8;if(/^[0-9.]+em$/i.test(n))return i*t;return t}function Lc(e,t){return typeof e==="number"&&Number.isFinite(e)&&e>0?e:t}function YV(e){return typeof e==="string"&&e.trim().length>0?e.trim():void 0}function qV(e,t,n,i){const r=e.actors.length;if(r===0)return[];const o=r*ot.actorDotRadius*2+(r-1)*ot.actorDotGap;let s=n-o/2+ot.actorDotRadius;return e.actors.map((a,l)=>{const c={label:a,key:Ha(a,e.actorContents?.[l]),colorIndex:t.get(Ha(a,e.actorContents?.[l]))??0,x:s,y:i,r:ot.actorDotRadius};s+=ot.actorDotRadius*2+ot.actorDotGap;return c})}function lO(e,t){return t+(XV-e)*ot.scoreStep}var XV=5;function uO(e,t={}){const n={sections:[],...Ar(t)};if(re("journey")){Ge("journey","header",e[0]??"",{line:1,unit:"normalized"});he("journey","initialize",n)}let i;let r=0;let o=0;const s=()=>{if(i)return i;i={id:`section-${r++}`,tasks:[]};n.sections.push(i);if(re("journey"))he("journey","addImplicitSection",i);return i};n2(e,1,{title:(a,l,c)=>{if(re("journey"))Ge("journey","title",a,{line:l+1,unit:"normalized"});n.title=a;if(c)n.titleContent=c;else delete n.titleContent;if(re("journey"))he("journey","setTitle",a,{line:l+1,unit:"normalized"})},accTitle:(a,l)=>{if(re("journey"))Ge("journey","accTitle",a,{line:l+1,unit:"normalized"});n.accessibilityTitle=a;if(re("journey"))he("journey","setAccessibilityTitle",a,{line:l+1,unit:"normalized"})},accDescr:(a,l)=>{if(re("journey"))Ge("journey","accDescr",a,{line:l+1,unit:"normalized"});n.accessibilityDescription=a;if(re("journey"))he("journey","setAccessibilityDescription",a,{line:l+1,unit:"normalized"})},section:(a,l,c)=>{if(re("journey"))Ge("journey","section",a,{line:l+1,unit:"normalized"});i={id:`section-${r++}`,label:a,...c?{labelContent:c}:{},tasks:[]};n.sections.push(i);if(re("journey"))he("journey","addSection",i,{line:l+1,unit:"normalized"})},task:(a,l,c,d,u,f)=>{if(re("journey"))Ge("journey","task",a,{line:d+1,unit:"normalized"});const h={id:`task-${o++}`,text:a,...u?{textContent:u}:{},score:l,actors:c,...f?{actorContents:f}:{}};s().tasks.push(h);if(re("journey"))he("journey","addTask",{...h,sectionId:i.id},{line:d+1,unit:"normalized"})},issue:a=>{if(re("journey"))Ge("journey",`invalid:${a.code}`,a.statement,{line:a.lineIndex+1,unit:"normalized"});throw UV(a)}});return n}function UV(e){switch(e.code){case"section_colon":return Je({what:`Invalid user journey section: "${e.statement}"`,expectedForm:"section Section name",example:"section Go to work"});case"empty_task_text":return Je({what:`Invalid user journey task: "${e.statement}"`,expectedForm:"Task name: score: Actor[, Actor\u2026]",example:"Pay: 3: Shopper"});case"invalid_score":case"unclosed_accdescr":return new Error(e.detail);case"empty_title":case"unrecognized_line":return new Error(`Invalid user journey line: "${e.statement}". Expected title, section, accessibility metadata, or "Task name: 3: Actor"`)}}var hu={titleFontSize:18,titleFontWeight:600,sectionFontSize:12,sectionFontWeight:600,taskFontSize:13,taskFontWeight:500,actorFontSize:11,actorFontWeight:600,legendDotRadius:5,legendLabelGap:12,legendTitleGap:26};var $x=5;function VV(e,t){const{positioned:n,colors:i,resolved:r}=t;const o=r.renderOptions;const s=i.font??"Inter";const a=o.transparent??false;const l=[];const c=r.familyAppearance;if(!c)throw new Error("Journey rendering requires request-boundary family appearance resolution");const d=Ue(o,c.styleDefaults,r.styleFace);const u=c.visual;const f=p9(d,u,i,{sectionCount:n.sections.length,actorCount:n.actors.length});const h=JV(n);const m=KV(n);const p=`${m}-arrowhead`;const g=ZV(p,f.arrow);const y=`${m}-title`;const w=`${m}-desc`;const S=o.journey?.experienceCurve!==false?n.sections.flatMap(P=>P.tasks.map(E=>E.marker)):[];const x=S.length>=2;const M=t9(u);l.push(e.documentOpen({id:"prelude",width:n.width,height:n.height,colors:i,transparent:a,font:s,hasMonoFont:false,...M?{extraCss:M}:{}},QV(n,i,a,h,y,w,c.useMaxWidth)));if(h.title){l.push(e.documentContent({id:"a11y-title",role:"chrome",nonPaint:"accessibility"},`<title id="${y}">${At(h.title)}</title>`))}if(h.description){l.push(e.documentContent({id:"a11y-desc",role:"chrome",nonPaint:"accessibility"},`<desc id="${w}">${At(h.description)}</desc>`))}l.push(e.documentContent({id:"style",role:"chrome",nonPaint:"stylesheet"},Dt(s,false,i.shadow,i.embedFontImport)));l.push(e.definitions({id:"defs",markerResources:[g]},e9(i,g)));if(M)l.push(e.documentContent({id:"journey-style",role:"chrome",nonPaint:"stylesheet"},M));l.push(r9(e,n.scoreGuide,d,g));if(n.actors.length>0){l.push(o9(e,n.actors,d,f,n.actorLegendTitle))}const b=o.mermaidConfig?.journey;const C=b?.sectionFills!==void 0||b?.sectionColours!==void 0;n.sections.forEach((P,E)=>{if(P.framed){l.push(s9(e,P,d,f,E,r.styleFace,C))}});if(x){l.push(n9(e,S,d,f))}for(const P of n.sections){for(const E of P.tasks){l.push(l9(e,E,P.label,d,f))}}if(n.title){l.push(e.text({id:"title",role:"title",text:n.title.text,block:n.title.block,x:n.title.x,y:n.title.y,fontSize:u.titleFontSize,fontWeight:hu.titleFontWeight,anchor:"middle",paint:{fill:f.titleColor},attributes:{className:"journey-title"}}))}l.push(e.documentClose());return{family:"journey",width:n.width,height:n.height,colors:i,transparent:a,parts:l}}function KV(e){const t=e.sections.flatMap(n=>[n.id,n.label??"",...n.tasks.flatMap(i=>[i.id,i.text,String(i.score),...i.actors])]);return`journey-${pi(e.width,e.height,e.title?.text??"",e.accessibilityTitle??"",e.accessibilityDescription??"",...t)}`}function JV(e){return{title:e.accessibilityTitle??e.title?.text,description:e.accessibilityDescription}}function QV(e,t,n,i,r,o,s){return Ot(e.width,e.height,t,n,{...s?{width:"100%",height:"100%",style:`max-width:${e.width}px`}:{},attrs:ki(i.title,i.description,r,o,"user journey")})}function ZV(e,t){return{id:e,shape:"arrow",size:{width:10,height:8},ref:{x:9,y:4},orient:"auto",geometry:{kind:"path",d:"M0,0 L10,4 L0,8 Z"},paint:{fill:t}}}function e9(e,t){const n=[en(e),pm(t)].filter(Boolean);return`<defs>
30
+ ${n.join("\n")}
31
+ </defs>`}function t9(e){return e.taskFontFamily?`<style>
32
+ .journey-task-text { font-family: ${e.taskFontFamily}; }
33
+ </style>`:void 0}function n9(e,t,n,i){const r=t.map(s=>({x:s.cx,y:s.cy}));const o=i9(r);return e.connector({id:"experience-curve",role:"series",geometry:o.geometry,lineStyle:"solid",paint:{stroke:`color-mix(in srgb, ${i.arrow} 55%, var(--bg))`,strokeWidth:String(Math.max(2,n.lineWidth*2)),strokeLinecap:"round"},route:{ownership:"family",contours:o.contours},attributes:{className:"journey-curve"}})}function i9(e){const t=e[0];let n=`M${t.x},${t.y}`;const i=[];for(let r=1;r<e.length;r++){const o=e[r-1];const s=e[r];const a=(s.x-o.x)/3;const l={x:o.x+a,y:o.y};const c={x:s.x-a,y:s.y};n+=` C${l.x},${l.y} ${c.x},${c.y} ${s.x},${s.y}`;i.push({kind:"cubic",control1:l,control2:c,end:s})}return _c(n,t,i)}function r9(e,t,n,i){const r=[];for(const s of t.ticks){r.push({indent:2,node:e.connector({id:`score-guide:${s.score}`,role:"grid",geometry:{kind:"line",x1:s.x1,y1:s.y,x2:s.x2,y2:s.y},lineStyle:"solid",paint:{stroke:`color-mix(in srgb, ${n.nodeBorderColor??"var(--_node-stroke)"} 62%, var(--bg))`,strokeWidth:"1"},channels:{value:s.score/$x},attributes:{className:"journey-guide"}})});r.push({indent:2,node:e.text({id:`score-label:${s.score}`,role:"axis",text:s.block?.text??String(s.score),block:s.block,x:s.labelX,y:s.labelY,fontSize:n.edgeLabelFontSize,fontWeight:n.edgeLabelFontWeight,letterSpacing:n.edgeLetterSpacing,anchor:"end",paint:{fill:n.edgeTextColor??"var(--_text-sec)"},channels:{value:s.score/$x},attributes:{className:"journey-score-label"}})})}const o=t.baseline;r.push({indent:2,node:e.connector({id:"journey-baseline",role:"rail",geometry:{kind:"line",x1:o.x1,y1:o.y1,x2:o.x2,y2:o.y2},lineStyle:"solid",paint:{stroke:n.edgeStrokeColor??"var(--_arrow)",strokeWidth:String(Math.max(2,n.lineWidth*2))},markers:{mid:[],end:i},attributes:{className:"journey-baseline"}})});return e.group({id:"score-guide",role:"grid",open:`<g class="journey-score-guide" data-score-min="1" data-score-max="5">`,close:"</g>",children:r})}function o9(e,t,n,i,r){const o=t[0];const s=o.x-hu.legendDotRadius;const a=o.y-hu.legendTitleGap;const l=r?.text??gi("Actors",n.groupTextTransform);const c=[{indent:2,node:e.text({id:"actor-legend-title",role:"legend",text:l,block:r,x:s,y:a,fontSize:n.groupHeaderFontSize,fontWeight:n.groupHeaderFontWeight,letterSpacing:n.groupLetterSpacing,anchor:"start",paint:{fill:n.groupTextColor??"var(--_text-sec)"},attributes:{className:"journey-actor-legend-title"}})}];for(const d of t){c.push({indent:2,node:e.shape({id:zc("actor-legend-dot",d.category,...a1(d.category,d.key)),role:"actor",geometry:{kind:"circle",cx:d.x,cy:d.y,r:hu.legendDotRadius},paint:{fill:xO(d.colorIndex,i),stroke:"var(--bg)",strokeWidth:"1"},channels:{category:d.category},attributes:{className:`journey-actor-dot ${yO(d.colorIndex,i)}`,data:{actor:d.category}}})});c.push({indent:2,node:e.text({id:zc("actor-legend-label",d.category,...a1(d.category,d.key)),role:"legend",text:d.label,block:d.block,x:d.x+hu.legendDotRadius+hu.legendLabelGap,y:d.y,fontSize:n.edgeLabelFontSize,fontWeight:n.edgeLabelFontWeight,letterSpacing:n.edgeLetterSpacing,anchor:"start",paint:{fill:n.groupTextColor??"var(--_text-sec)"},channels:{category:d.category},attributes:{className:"journey-actor-legend-text"}})})}return e.group({id:"actor-legend",role:"legend",open:`<g class="journey-actor-legend">`,close:"</g>",children:c})}function s9(e,t,n,i,r,o,s){const a=t.category;const l=t.label?` data-label="${hn(t.label)}"`:"";const c=[];c.push({indent:2,node:e.shape({id:`section-bg:${t.id}`,role:"section",geometry:{kind:"rect",x:t.x,y:t.y,width:t.width,height:t.height,rx:n.groupCornerRadius,ry:n.groupCornerRadius},paint:{fill:w9(r,i),stroke:M9(r,i),strokeWidth:String(n.groupLineWidth)},attributes:{className:`journey-section-bg journey-section-${r%i.sectionFills.length}`}})});if(t.label){const d={category:a};const u=It(o,"group-header",d,{includeFallback:false});const f=t.block?.text??gi(t.label,u?.textTransform??n.groupTextTransform);const h=u?.fontSize??n.groupHeaderFontSize;const m=u?.fontWeight??n.groupHeaderFontWeight;const p=u?.letterSpacing??n.groupLetterSpacing;const g=s?hO(r,i):u?.textColor??hO(r,i);c.push({indent:2,node:a9(e,t,n,i,r,o,s)});c.push({indent:2,node:e.text({id:`section-label:${t.id}`,role:"group-header",text:f,block:t.block,x:t.labelX,y:t.labelY,fontSize:h,fontWeight:m,letterSpacing:p,anchor:"middle",paint:{fill:g},attributes:{className:`journey-section-label journey-section-label-${r%i.sectionTextColors.length}`}})})}return e.group({id:`section:${t.id}`,role:"section",open:`<g class="journey-section" data-id="${Ye(t.id)}"${l}>`,close:"</g>",children:c,channels:{category:a}})}function a9(e,t,n,i,r,o,s){const a={category:t.category};const l=It(o,"group-header",a,{includeFallback:false});const c=s?fO(r,i):l?.fillColor??fO(r,i);const d=l?.cue??"none";const u=l?.strokeColor??l?.borderColor??(d!=="none"?"var(--fg)":"none");const f=l?.lineWidth??(d!=="none"?n.groupLineWidth:void 0);const h=f===void 0?void 0:d==="outline"?f+1:d==="double-line"?f+2:f;const m=d==="pattern"?"3 2":d==="double-line"?"8 2 2 2":void 0;const p=Math.min(6,Math.max(3,t.height/6));const g=Math.max(18,Math.min(t.height-p*2,n.groupHeaderFontSize+n.groupPaddingY));const y=t.x+p;const w=t.labelY-g/2;const S=Math.max(0,t.width-p*2);const x=Math.min(n.groupCornerRadius,g/2);return e.shape({id:`section-band:${t.id}`,role:"group-header",geometry:{kind:"rect",x:y,y:w,width:S,height:g,rx:x,ry:x},paint:{fill:c,stroke:u,...h!==void 0?{strokeWidth:String(h)}:{},...m?{strokeDasharray:m}:{}},channels:a,attributes:{className:`journey-section-label-band journey-section-band-${r%i.sectionBands.length}`,...d!=="none"?{data:{"brand-cue":d}}:{}}})}function l9(e,t,n,i,r){const o=n?` data-section="${Ye(n)}"`:"";const s=t.actors.length>0?` data-actors="${Ye(t.actors.join(", "))}"`:"";const a=t.score/$x;const l=n?{value:a,category:n}:{value:a};const c=[{indent:2,node:c9(e,t.track,t,i,r)},{indent:2,node:d9(e,t,i,r,l)},{indent:2,node:u9(e,t,i,r,l)}];const d=new Map;for(const u of t.actorDots){const f=u.key??Ha(u.label);const h=d.get(f)??0;d.set(f,h+1);c.push({indent:2,node:f9(e,u,t.id,h,r)})}c.push({indent:2,node:h9(e,t.marker,t.id,r,l)});return e.group({id:`task:${t.id}`,role:"task",open:`<g class="journey-task" data-id="${Ye(t.id)}" data-score="${t.score}"${o}${s}>`,close:"</g>",children:c,channels:l})}function c9(e,t,n,i,r){return e.connector({id:`track:${n.id}`,role:"marker-line",geometry:{kind:"line",x1:t.x,y1:t.y1,x2:t.x,y2:t.y2},lineStyle:"dashed",paint:{stroke:`color-mix(in srgb, ${r.nodeStroke} 78%, var(--bg))`,strokeWidth:String(i.lineWidth),strokeDasharray:"4 7"},channels:{value:n.score/$x},attributes:{className:"journey-track"}})}function d9(e,t,n,i,r){return e.shape({id:`task-box:${t.id}`,role:"task",geometry:{kind:"rect",x:t.x,y:t.y,width:t.width,height:t.height,rx:n.cornerRadius??0,ry:n.cornerRadius??0},paint:{fill:i.nodeFill,stroke:i.nodeStroke,strokeWidth:String(n.nodeLineWidth)},channels:r,attributes:{className:"journey-task-box"}})}function u9(e,t,n,i,r){return e.text({id:`task-label:${t.id}`,role:"label",text:t.text,block:t.block,x:t.textX,y:t.textY,fontSize:n.nodeLabelFontSize,fontWeight:n.nodeLabelFontWeight,letterSpacing:n.nodeLetterSpacing,anchor:"middle",paint:{fill:i.taskText},channels:r,attributes:{className:"journey-task-text"}})}function a1(e,t){return t!==void 0&&t!==Ha(e)?[t]:[]}function f9(e,t,n,i,r){return e.shape({id:zc("actor-dot",n,t.label,...a1(t.label,t.key),...i>0?[i]:[]),role:"actor",geometry:{kind:"circle",cx:t.x,cy:t.y,r:t.r},paint:{fill:xO(t.colorIndex,r),stroke:"var(--bg)",strokeWidth:"1"},channels:{category:t.label},attributes:{className:`journey-actor-dot ${yO(t.colorIndex,r)}`,data:{actor:t.label}}})}function h9(e,t,n,i,r){const o=t.cy-4.5;const s=t.cx-5.5;const a=t.cx+5.5;const l=m9(t);return e.group({id:`score-marker:${n}`,role:"score",open:`<g class="journey-score-marker" data-score="${t.score}">`,close:"</g>",children:[{indent:2,node:e.shape({id:`score-face:${n}`,role:"score",geometry:{kind:"circle",cx:t.cx,cy:t.cy,r:t.r},paint:{fill:i.scoreFaceFill,stroke:i.scoreFaceStroke,strokeWidth:"1.2"},channels:r,attributes:{className:"journey-score-face"}})},{indent:2,node:e.shape({id:`score-eye-left:${n}`,role:"score",geometry:{kind:"circle",cx:s,cy:o,r:2},paint:{fill:i.scoreFaceInk},channels:r,attributes:{className:"journey-face-eye"}})},{indent:2,node:e.shape({id:`score-eye-right:${n}`,role:"score",geometry:{kind:"circle",cx:a,cy:o,r:2},paint:{fill:i.scoreFaceInk},channels:r,attributes:{className:"journey-face-eye"}})},{indent:2,node:e.shape({id:`score-mouth:${n}`,role:"score",geometry:{kind:"path",d:l},paint:{fill:"none",stroke:i.scoreFaceInk,strokeWidth:"1.6",strokeLinecap:"round"},channels:r,attributes:{className:"journey-face-mouth"}})}],channels:r})}function m9(e){const t=e.cx;const n=e.cy;if(e.score>=4.5)return`M${t-8},${n+4} Q${t},${n+13} ${t+8},${n+4}`;if(e.score>3)return`M${t-8},${n+5} Q${t},${n+11} ${t+8},${n+5}`;if(e.score===3)return`M${t-8},${n+6} L${t+8},${n+6}`;if(e.score>=1.5)return`M${t-8},${n+10} Q${t},${n+2} ${t+8},${n+10}`;return`M${t-9},${n+11} Q${t},${n} ${t+9},${n+11}`}function p9(e,t,n,i){const r=e.edgeStrokeColor??"var(--_arrow)";const o=e.nodeFillColor??"var(--_node-fill)";const s=e.nodeBorderColor??"var(--_node-stroke)";const a=g9(r,n,e,i.sectionCount);const l=Math.max(t.sectionFills.length,t.sectionColours.length,Math.min(a.length,Math.max(i.sectionCount,1)));const c=Array.from({length:l},(p,g)=>{const y=t.sectionFills[g%t.sectionFills.length];return y??e.groupFillColor??`color-mix(in srgb, ${a[g%a.length]} ${g===0?8:9}%, var(--bg))`});const d=Array.from({length:l},(p,g)=>{const y=t.sectionFills[g%t.sectionFills.length];return y??e.groupHeaderFillColor??`color-mix(in srgb, ${a[g%a.length]} ${g===0?14:16}%, var(--bg))`});const u=Array.from({length:l},(p,g)=>{const y=t.sectionFills[g%t.sectionFills.length];return y?`color-mix(in srgb, ${y} ${g===0?42:38}%, var(--bg))`:e.groupBorderColor??`color-mix(in srgb, ${a[g%a.length]} ${g===0?42:38}%, var(--bg))`});const f=d.map((p,g)=>{const y=a[g%a.length];const w=t.sectionFills[g%t.sectionFills.length];return w===void 0&&e.groupHeaderFillColor===void 0&&Nn(y)&&Nn(n.bg)?tr(y,n.bg,g===0?14:16):p});const h=Array.from({length:l},(p,g)=>y9(t.sectionColours.length>0?t.sectionColours[g%t.sectionColours.length]:void 0,f[g],e.groupTextColor??"var(--_text)",n));const m=t.actorColours.length>0?t.actorColours:x9(r,n,e,i.actorCount);return{arrow:r,nodeFill:o,nodeStroke:s,taskText:e.nodeTextColor??xi("var(--_text)",o,n),titleColor:t.titleColor??e.groupTextColor??e.nodeTextColor??"var(--_text)",sectionFills:c,sectionBands:d,sectionStrokes:u,sectionTextColors:h,actorColors:m,scoreFaceFill:`color-mix(in srgb, ${r} 22%, var(--bg))`,scoreFaceStroke:r,scoreFaceInk:e.edgeTextColor??e.nodeTextColor??"var(--_text)"}}function g9(e,t,n,i){const r=S9(t,n,Math.max(6,i));if(r)return r;return[e,"var(--line, var(--_line))","var(--accent, var(--_arrow))","var(--muted, var(--_text-sec))","var(--border, var(--_node-stroke))","var(--fg)"]}function y9(e,t,n,i){const r=i.bg;if(e){const a=la(e,t,r);if(a!==null&&a>=4.5)return e}else{const a=_n(n,i);if(a!==void 0&&Nn(t))return xs(a,t)}const o=la("#000000",t,r);const s=la("#ffffff",t,r);if(o!==null&&s!==null)return o>=s?"#000000":"#ffffff";return n}function x9(e,t,n,i){const r=Math.max(i,1);if(r>6&&gO(t.bg)){const s=pO(n.edgeStrokeColor,t.accent);if(s)return Zi(r,{accent:s,bg:t.bg})}if(Nn(t.bg)&&Nn(t.fg)){const s=Ml(t);const a=mO(n.edgeStrokeColor,t.accent,s.arrow);if(a){if(r<=6){const l=b9(a,t.bg,r);if((r<2||Dh(l)>=.1)&&l.every(c=>la(c,t.bg)>=1.25&&Math.abs(tl(c,t.bg))>=15))return l}return Zi(r,{accent:a,bg:t.bg})}}const o=[e,"var(--line, var(--_line))","var(--accent, var(--_arrow))","var(--muted, var(--_text-sec))","var(--border, var(--_node-stroke))","var(--fg)","color-mix(in srgb, var(--accent, var(--_arrow)) 62%, var(--bg))","color-mix(in srgb, var(--line, var(--_line)) 72%, var(--bg))"];return o.slice(0,Math.max(r<=o.length?r:o.length,1))}function b9(e,t,n){const[i,r]=Xy(e);const o=$M(t);const s=r<20?230:i;const a=Math.min(72,Math.max(42,r<20?46:r));const l=o?64:38;const c=[];const d=new Set;const u=Math.min(n,m0);for(let f=0;c.length<u&&f<m0*16;f++){const h=Math.floor(f/360);const m=(s+f%360*137.508)%360;const p=NM(m,Math.max(34,a-h%4*7),Math.max(o?46:24,Math.min(o?78:58,l+(h%2===0?-h*2:h*2))));if(!d.has(p)){d.add(p);c.push(p)}}return Array.from({length:n},(f,h)=>c[h%c.length])}function S9(e,t,n){if(n>6&&gO(e.bg)){const o=pO(t.edgeStrokeColor,e.accent);if(o)return Zi(n,{accent:o,bg:e.bg})}if(!Nn(e.bg)||!Nn(e.fg))return void 0;const i=Ml(e);const r=mO(t.edgeStrokeColor,e.accent,i.arrow);if(!r)return void 0;return Zi(n,{accent:r,bg:e.bg})}function mO(...e){return e.find(t=>t!==void 0&&Nn(t))}function pO(...e){return e.find(t=>t!==void 0&&Kt(t)!==null)}function gO(e){return Kt(e)?.[3]===1}function yO(e,t){return`journey-actor-${e%t.actorColors.length}`}function xO(e,t){return t.actorColors[e%t.actorColors.length]}function w9(e,t){return t.sectionFills[e%t.sectionFills.length]}function fO(e,t){return t.sectionBands[e%t.sectionBands.length]}function M9(e,t){return t.sectionStrokes[e%t.sectionStrokes.length]}function hO(e,t){return t.sectionTextColors[e%t.sectionTextColors.length]}var bO=gt(VV);var o2e={configDiagnostics:sO,normalizeRequest:e=>({appearance:{family:s1(e.renderOptions)}}),layout:e=>ht(cO(Tn(uO(e.source.authoredFamilyLines??e.source.familyLines,e.source.accessibility),e.source.frontmatter),e.familyAppearance??s1(e.renderOptions),e.renderOptions,e.styleFace)),projectPositioned:ut(HI),lowerScene:ft(bO)};var k9={padding:Yt,maxNodeWidth:Jt};var SO=e=>{const t=xt("mindmap",e,k9);const n=e.root;const i=n&&typeof n==="object"&&!Array.isArray(n)?n:void 0;if(i&&"layout"in i&&!["tidy-tree","cose-bilkent","radial"].includes(String(i.layout)))t.push({code:"INEFFECTIVE_CONFIG",field:"layout",message:'layout must be "cose-bilkent", "radial", or "tidy-tree" for mindmap diagrams; the invalid value has no effect.'});return t};var l1=.38;function c1(e,t){const n=e.width*(e.shape==="bang"?l1:.5);return e.x+e.width/2+(t==="right"?n:-n)}var C9=13;var P9=500;function wO(e,t={}){const n=em(t.padding,32);const i=em(t.maxNodeWidth,180);const r=em(t.nodeGap,40);const o=em(t.layerGap,20);const s=E9(e.root,i,t.textStyle);return t.layout==="tidy-tree"?R9(e,s,n,r,o):v9(e,s,n,r,o)}function E9(e,t,n){const i=new Map;const r=(o,s,a)=>{const l=Be(o.label,{fontSize:n?.nodeLabelFontSize??C9,fontWeight:n?.nodeLabelFontWeight??P9,letterSpacing:n?.nodeLetterSpacing,transform:n?.nodeTextTransform,maxWidth:t});const c=l.text;const d=l;let u=Math.max(56,d.width+24);let f=Math.max(34,d.height+18+(o.icon?14:0));if(o.shape==="circle")u=f=Math.max(u,f,54);if(o.shape==="bang"||o.shape==="cloud"){u+=18;f+=10}i.set(o.id,{id:o.id,label:c,labelBlock:l,iconFallbackBlock:o.icon&&!ll(o.icon)?Be(al(o.icon),{fontSize:9,fontWeight:400}):void 0,shape:o.shape,markdown:o.markdown,icon:o.icon,className:o.className,...a?{parentId:a}:{},depth:s,side:s===0?"root":"right",x:0,y:0,width:u,height:f});for(const h of o.children)r(h,s+1,o.id)};r(e,0);return i}function R9(e,t,n,i,r){const o=T9(t);const s=new Map([[0,n]]);const a=Math.max(...Array.from(t.values(),d=>d.depth));for(let d=1;d<=a;d++){s.set(d,s.get(d-1)+(o.get(d-1)??0)+r)}let l=n;const c=d=>{const u=t.get(d.id);u.side=u.depth===0?"root":"right";u.x=s.get(u.depth);if(d.children.length===0){u.y=l;l+=u.height+i;return u.y+u.height/2}const f=d.children.map(c);const h=(f[0]+f.at(-1))/2;u.y=Math.max(n,h-u.height/2);return u.y+u.height/2};c(e.root);MO(t,n);return kO(e,t,n)}function v9(e,t,n,i,r){const o=t.get(e.root.id);const s=P=>{const E=t.get(P.id).height;if(P.children.length===0)return E;return Math.max(E,P.children.reduce((k,v)=>k+s(v),0)+i*(P.children.length-1))};const a=[];const l=[];let c=0;let d=0;e.root.children.forEach((P,E)=>{const k=s(P)+i;const v=E===1||E>1&&c<d;if(v){a.push(P);c+=k}else{l.push(P);d+=k}});const u=(P,E)=>{t.get(P.id).side=E;P.children.forEach(k=>u(k,E))};a.forEach(P=>u(P,"left"));l.forEach(P=>u(P,"right"));const f=P=>{const E=new Map;for(const k of t.values()){if(k.side!==P)continue;E.set(k.depth,Math.max(E.get(k.depth)??0,k.width))}return E};const h=f("left");const m=f("right");const p=P=>[...P.values()].reduce((E,k)=>E+k+r,0);o.x=n+p(h);const g=(P,E)=>{const k=new Map;let v=P==="left"?o.x:o.x+o.width;const T=Math.max(0,...E.keys());for(let A=1;A<=T;A++){const R=E.get(A)??0;if(P==="left"){v-=r+R;k.set(A,v)}else{v+=r;k.set(A,v);v+=R}}return k};const y=g("left",h);const w=g("right",m);const S=(P,E)=>{let k=n;const v=E==="left"?h:m;const T=E==="left"?y:w;const A=R=>{const I=t.get(R.id);const L=T.get(I.depth);I.x=E==="left"?L+(v.get(I.depth)-I.width):L;if(R.children.length===0){I.y=k;k+=I.height+i;return I.y+I.height/2}const $=R.children.map(A);const B=($[0]+$.at(-1))/2;I.y=B-I.height/2;return B};P.forEach(A);return{min:n,max:Math.max(n,k-i)}};const x=S(a,"left");const M=S(l,"right");const b=Math.max(o.height,x.max-x.min,M.max-M.min);o.y=n+Math.max(0,(b-o.height)/2);const C=(P,E)=>{if(P.length===0)return;const k=E.max-E.min;const v=n+(b-k)/2-E.min;const T=A=>{t.get(A.id).y+=v;A.children.forEach(T)};P.forEach(T)};C(a,x);C(l,M);MO(t,n);return kO(e,t,n)}function T9(e){const t=new Map;for(const n of e.values())t.set(n.depth,Math.max(t.get(n.depth)??0,n.width));return t}function MO(e,t){const n=Math.min(...Array.from(e.values(),i=>i.y));if(n<t)for(const i of e.values())i.y+=t-n}function kO(e,t,n){const i=Array.from(t.values()).flatMap(a=>{if(!a.parentId)return[];const l=t.get(a.parentId);const c=a.side==="left";const d={x:c1(l,c?"left":"right"),y:l.y+l.height/2};const u={x:c1(a,c?"right":"left"),y:a.y+a.height/2};const f=Math.abs(u.x-d.x)*.42;const h={x:d.x+(c?-f:f),y:d.y};const m={x:u.x+(c?f:-f),y:u.y};return[{from:l.id,to:a.id,points:[d,h,m,u],d:`M ${In(d.x)} ${In(d.y)} C ${In(h.x)} ${In(h.y)} ${In(m.x)} ${In(m.y)} ${In(u.x)} ${In(u.y)}`}]});const r=Math.min(...Array.from(t.values(),a=>a.x));if(r<n){const a=n-r;for(const l of t.values())l.x+=a;for(const l of i){l.points.forEach(h=>{h.x+=a});const[c,d,u,f]=l.points;l.d=`M ${In(c.x)} ${In(c.y)} C ${In(d.x)} ${In(d.y)} ${In(u.x)} ${In(u.y)} ${In(f.x)} ${In(f.y)}`}}const o=Math.max(...Array.from(t.values(),a=>a.x+a.width))+n;const s=Math.max(...Array.from(t.values(),a=>a.y+a.height))+n;return{width:o,height:s,accessibilityTitle:e.accessibilityTitle,accessibilityDescription:e.accessibilityDescription,nodes:[...t.values()],edges:i}}function CO(e,t,n,i={}){const r=tn(t,n);if(!r)return e;const o=em(i.padding,32);const s=r.height;const a=e.nodes.map(d=>({...d,y:d.y+s}));const l=e.edges.map(d=>{const u=d.points.map(g=>({x:g.x,y:g.y+s}));const[f,h,m,p]=u;return{...d,points:u,d:`M ${In(f.x)} ${In(f.y)} C ${In(h.x)} ${In(h.y)} ${In(m.x)} ${In(m.y)} ${In(p.x)} ${In(p.y)}`}});const c=Math.max(e.width,r.width+2*o);return{...e,width:c,height:e.height+s,nodes:a,edges:l,title:on(r,c,o)}}function em(e,t){return typeof e==="number"&&Number.isFinite(e)&&e>=0?e:t}function In(e){return Math.round(e*1e3)/1e3}function d1(e,t){const n={layout:t==="tidy-tree"?"tidy-tree":"radial"};if(!e||typeof e!=="object"||Array.isArray(e))return n;const i=e;if(typeof i.padding==="number"&&Number.isFinite(i.padding)&&i.padding>=0)n.padding=i.padding;if(typeof i.maxNodeWidth==="number"&&Number.isFinite(i.maxNodeWidth)&&i.maxNodeWidth>0)n.maxNodeWidth=i.maxNodeWidth;return n}function PO(e,t,n={groupLetterSpacing:0}){return CO(wO(e,{...t,textStyle:n}),e.title,n,t)}var L9=13;function A9(e,t){const{positioned:n,colors:i,resolved:r}=t;const o=r.renderOptions;const s=i.font??"Inter";const a=o.transparent??false;const l="mindmap-title";const c="mindmap-desc";const d=ki(n.accessibilityTitle??n.nodes[0]?.label,n.accessibilityDescription,l,c,"mindmap");const u=[Ot(n.width,n.height,i,a,{attrs:d}),Dt(s,false,i.shadow,i.embedFontImport)];const f=en(i);if(f)u.push(`<defs>${f}</defs>`);const h=N9(n);const m=new Set(h.values()).size;const p=Nn(i.accent??"")?i.accent:"#3b82f6";const g=Nn(i.bg)?i.bg:"#ffffff";const y=Zi(m,m<=6?{accent:p,bg:g}:{accent:i.accent??p,bg:i.bg});const w=M=>{const b=h.get(M)??0;return y[b]??p};const S=[e.documentOpen({id:"prelude",width:n.width,height:n.height,colors:i,transparent:a,font:s,hasMonoFont:false},u.join("\n"))];const x=n.accessibilityTitle??n.nodes[0]?.label;if(x)S.push(e.documentText({id:"acc-title",element:"title",domId:l,text:x}));if(n.accessibilityDescription)S.push(e.documentText({id:"acc-desc",element:"description",domId:c,text:n.accessibilityDescription}));if(n.title)S.push(e.text(En(n.title,Ue(o,void 0,r.styleFace))));for(const M of n.edges){const b=w(M.to);const[C,P,E,k]=M.points;if(!C||!P||!E||!k){throw new Error(`Mindmap edge "${M.from}" -> "${M.to}" requires four cubic control points`)}const v=_c(M.d,C,[{kind:"cubic",control1:P,control2:E,end:k}]);S.push(e.connector({id:mm(M.from,M.to),role:"edge",geometry:v.geometry,lineStyle:"solid",paint:{fill:"none",stroke:b,strokeWidth:"2.5"},endpoints:{from:M.from,to:M.to},relationship:{kind:"mindmap-branch",direction:"forward"},route:{ownership:"layout",contours:v.contours},stroke:{lineCap:"round"},channels:{importance:1,category:String(h.get(M.to)??0)},attributes:{className:"mindmap-edge",data:{"branch-index":String(h.get(M.to)??0)}}}))}for(const M of n.nodes)S.push(I9(e,M,i,h.get(M.id),w(M.id)));S.push(e.documentClose());return{family:"mindmap",width:n.width,height:n.height,colors:i,transparent:a,parts:S}}function I9(e,t,n,i,r){const o=Nn(n.bg)&&Nn(n.fg)&&(n.accent===void 0||Nn(n.accent));const s=o?Ml(n).arrow:"var(--_arrow)";const a=o?tr(r,n.bg,t.depth===1?30:t.depth===2?20:13):"var(--_node-fill)";const l=t.depth===0?s:a;const c=t.depth===0?s:r;const d=t.depth===0?o?yu(n.bg,s,4.5,n.fg):"var(--bg)":o?yu(n.fg,a,4.5):"var(--_text)";const u=F9(t);const f=[{node:e.shape({id:xn(t.id,"shape"),role:"chrome",geometry:u,paint:{fill:l,stroke:c,strokeWidth:"1.5"}}),indent:2}];if(t.icon){const w=ll(t.icon);if(w){const S=14;const x=t.x+t.width/2-S/2;const M=t.y+4;const b=S/24;f.push({node:e.pathArtwork({id:xn(t.id,"icon"),paths:w.paths,owner:{id:t.id,role:"node"},open:`<g class="mindmap-icon-glyph" data-icon="${Ye(t.icon)}" data-icon-source="${Ye(w.source)}" transform="translate(${jn(x)} ${jn(M)}) scale(${jn(b)})">`,transform:{kind:"matrix",a:jn(b),b:0,c:0,d:jn(b),e:jn(x),f:jn(M)},paint:{fill:d,stroke:d,strokeWidth:"0.8"}}),indent:2})}else{const S=al(t.icon);f.push({node:e.text({id:xn(t.id,"icon"),role:"icon",owner:{id:t.id,role:"node"},text:S,block:t.iconFallbackBlock,x:jn(t.x+t.width/2),y:jn(t.y+12),fontSize:9,anchor:"middle",paint:{fill:d},baselineShift:0,attributes:{className:"mindmap-icon-fallback",data:{icon:t.icon}}}),indent:2})}}const h=t.y+t.height/2+(t.icon?5:0);const m=t.labelBlock?.fontSize??L9;const p=t.labelBlock?.fontWeight??500;const g=t.labelBlock?.letterSpacing??0;f.push({node:e.text({id:xn(t.id,"label"),role:"label",text:t.label,block:t.labelBlock,x:t.x+t.width/2,y:h,fontSize:m,fontWeight:p,letterSpacing:g,anchor:"middle",paint:{fill:d}}),indent:2});const y=t.className?` ${Ye(t.className)}`:"";return e.group({id:t.id,role:"node",channels:{importance:Math.max(1,5-t.depth),...i===void 0?{}:{category:String(i)}},open:`<g class="mindmap-node depth-${t.depth}${y}" data-id="${Ye(t.id)}" data-label="${hn(t.label)}"${i===void 0?"":` data-branch-index="${i}"`}${t.parentId?` data-parent-id="${Ye(t.parentId)}"`:""}>`,close:"</g>",children:f})}function F9(e){const{x:t,y:n,width:i,height:r}=e;const o=(s,a)=>({x:jn(s),y:jn(a)});if(e.shape==="circle")return{kind:"circle",cx:jn(t+i/2),cy:jn(n+r/2),r:jn(Math.min(i,r)/2)};if(e.shape==="cloud")return{kind:"ellipse",cx:jn(t+i/2),cy:jn(n+r/2),rx:jn(i/2),ry:jn(r/2)};if(e.shape==="hexagon")return{kind:"polygon",points:[o(t+12,n),o(t+i-12,n),o(t+i,n+r/2),o(t+i-12,n+r),o(t+12,n+r),o(t,n+r/2)]};if(e.shape==="bang"){const s=[];for(let a=0;a<12;a++){const l=-Math.PI/2+a*Math.PI/6;const c=a%2===0?i/2:i*l1;const d=a%2===0?r/2:r*.38;s.push(o(t+i/2+Math.cos(l)*c,n+r/2+Math.sin(l)*d))}return{kind:"polygon",points:s}}return{kind:"rect",x:jn(t),y:jn(n),width:jn(i),height:jn(r),rx:e.shape==="rect"?0:e.shape==="rounded"?10:16,ry:e.shape==="rect"?0:e.shape==="rounded"?10:16}}function N9(e){const t=new Map;const n=e.nodes.find(r=>r.depth===0);if(!n)return t;let i=0;for(const r of[...e.nodes].sort((o,s)=>o.depth-s.depth)){if(r.depth===0)continue;if(r.parentId===n.id)t.set(r.id,i++);else if(r.parentId&&t.has(r.parentId))t.set(r.id,t.get(r.parentId))}return t}function jn(e){return Math.round(e*1e3)/1e3}var EO=gt(A9);var G2e={configDiagnostics:SO,statementEnds:qm,normalizeRequest:e=>({familyConfig:{position:d1(e.source.config.mindmap,e.source.config.layout)}}),layout:e=>ht(PO(Tn(Vr(eE(e.source.authoredFamilyBody??e.source.familyBody),e.source.accessibility),e.source.frontmatter),e.familyConfig?.position??d1(void 0,void 0),Ue(e.renderOptions,void 0,e.styleFace)),{injectAccessibility:false}),projectPositioned:ut(jI),lowerScene:ft(EO)};var $9={textPosition:wn(0,1),donutHole:wn(0,.9),legendPosition:qs("top","bottom","left","right","center")};var RO=e=>xt("pie",e,$9);function _9(e){return(Math.round(e*100)/100).toString()}function Ac(e,t,n,i,r){if(!n)throw new TypeError(`Missing retained tooltip layout for ${i}`);const{block:o,bgW:s,bgX:a,bgY:l,textX:c,textY:d,ptrPath:u}=n;const f=h=>Number(_9(h));return e.group({id:i,role:"chrome",owner:r,visibility:"conditional",open:`<g class="${t}-tip">`,close:"</g>",join:"",children:[{indent:0,node:e.shape({id:`${i}:background`,role:"chrome",owner:r,geometry:{kind:"rect",x:f(a),y:f(l),width:f(s),height:Oi.height,rx:Oi.rx},paint:{fill:"var(--_text)"},attributes:{className:`${t}-tip ${t}-tip-bg`}})},{indent:0,node:e.shape({id:`${i}:pointer`,role:"chrome",owner:r,geometry:{kind:"path",d:u},paint:{fill:"var(--_text)"},attributes:{className:`${t}-tip ${t}-tip-ptr`}})},{indent:0,node:e.text({id:`${i}:text`,role:"label",owner:r,text:o.text,block:o,x:f(c),y:f(d),fontSize:Oi.fontSize,fontWeight:Oi.fontWeight,anchor:"middle",paint:{fill:"var(--bg)"},attributes:{className:`${t}-tip ${t}-tip-text`}})}]})}function mu(e,t){const n=t.map(i=>`.${i}:hover .${e}-tip`).join(",\n ");return`
34
+ .${e}-tip { opacity: 0; pointer-events: none; }
35
+ .${e}-tip-bg { fill: var(--_text); }
36
+ .${e}-tip-text { fill: var(--bg); font-size: ${Oi.fontSize}px; font-weight: ${Oi.fontWeight}; }
37
+ .${e}-tip-ptr { fill: var(--_text); }
38
+ ${n} { opacity: 1; }`}var u1={titleFontSize:18,titleFontWeight:600,legendFontSize:13,legendFontWeight:500,sliceStrokeWidth:1.5,dimOpacity:.4};var D9=e=>/[<>*~]/.test(e);function O9(e,t){const{positioned:n,colors:i,resolved:r}=t;const o=r.renderOptions;const s=i.font??"Inter";const a=o.transparent??false;const l=o.interactive??false;const c=Ue(o,aM,r.styleFace);const d=It(r.styleFace,"pie-slice",{},{includeFallback:false});const u=n.visual;const f=[];const h=eu(n.slices.length,{accent:i.accent,bg:i.bg,overrides:u.paletteOverrides});const m=u.highlightSlice==="hover";const p=!m&&n.slices.some(C=>u.highlightSlice===C.label);const g=[];g.push(W9(n,i,a));g.push(Dt(s,false,i.shadow,i.embedFontImport));const y=en(i);if(y)g.push(`<defs>${y}</defs>`);const w=z9(c,u,l,d);g.push(w);f.push(e.documentOpen({id:"prelude",width:n.width,height:n.height,colors:i,transparent:a,font:s,hasMonoFont:false,extraCss:w},g.join("\n")));if(u.outerStrokeWidth!==void 0||u.outerStrokeColor!==void 0){const C=u.outerStrokeWidth??2;const P=TO(n.radius+C/2);f.push(e.shape({id:"outer-circle",role:"chrome",geometry:{kind:"circle",cx:n.cx,cy:n.cy,r:P},paint:{fill:"none",stroke:B9(u,c),strokeWidth:String(C)},attributes:{className:"pie-outer-circle"}}))}const S=new Map;const x=[];const M=(C,P)=>{const E=`${C}:${P}`;const k=S.get(E)??0;S.set(E,k+1);return k===0?E:`${E}#${k}`};const b=f1(u.strokeWidth??d?.lineWidth??c.nodeLineWidth);for(let C=0;C<n.slices.length;C++){const P=n.slices[C];const E=pc(P.fraction);const k={category:P.label,value:P.fraction};const v=It(r.styleFace,"pie-slice",k,{includeFallback:false});const T=u.paletteOverrides[C]??v?.fillColor??h[C];h[C]=T;const A=u.strokeColor??v?.strokeColor??v?.borderColor??c.nodeBorderColor??"var(--bg)";const R=u.strokeWidth??v?.lineWidth??c.nodeLineWidth;const I=v?.cue??"none";const L=I==="outline"?R+1:I==="double-line"?R+2:R;const $=I==="pattern"?"3 2":I==="double-line"?"8 2 2 2":void 0;const B=f1(L);const F=p&&u.highlightSlice===P.label;const z=p&&!F;const _=`pie-slice${F?" highlighted":""}${m?" highlighted-on-hover":""}${z?" pie-dim":""}`;const H=F?1:z?TO((u.opacity??1)*u1.dimOpacity):u.opacity;const D=M("slice",P.label);x[C]=D;f.push(e.shape({id:D,role:"pie-slice",geometry:{kind:"path",d:P.path},paint:{fill:T,stroke:F?"var(--fg)":A,strokeWidth:String(F?B:L),...$?{strokeDasharray:$}:{},...H!==void 0?{opacity:String(H)}:{}},channels:{...k,...F?{emphasis:true}:{}},attributes:{className:_,data:{label:P.label,value:String(P.value),percent:E,...I!=="none"?{"brand-cue":I}:{},...F?{highlighted:"true"}:{}}}}))}for(let C=0;C<n.slices.length;C++){const P=n.slices[C];const E=P.pctLabel;if(!E)continue;const k=p&&u.highlightSlice!==P.label;const v=p&&!k?1:k?(u.opacity??1)*u1.dimOpacity:u.opacity??1;const T=G9(h[C],v,i);const A=c.nodeTextColor??i.fg;const R=u.sectionTextColor??(T===void 0?k?A:Xo(h[C])??A:k?xs(_n(A,i)??A,T):Xo(T)??A);f.push(e.text({id:M("slice-label",P.label),role:"label",text:E.text,x:E.x,y:E.y,fontSize:E.fontSize,fontWeight:XI,block:E.block,anchor:"middle",dominantBaseline:"middle",paint:{fill:R},channels:{category:P.label,value:P.fraction},attributes:{className:"pie-slice-label"}}))}for(let C=0;C<n.legend.length;C++){const P=n.legend[C];const E=h[C];const k=p&&u.highlightSlice===P.label;const v=p&&!k;const T=k?bh:c.nodeLabelFontWeight;f.push(e.shape({id:M("legend",P.label),role:"legend",geometry:{kind:"rect",x:P.x,y:P.y,width:P.swatchSize,height:P.swatchSize,rx:2,ry:2},paint:{fill:E,stroke:c.nodeBorderColor??"var(--_node-stroke)",strokeWidth:String(c.nodeBorderColor?Math.max(1,c.nodeLineWidth):1),...v?{opacity:String(u1.dimOpacity)}:{}},channels:{category:P.label,value:P.fraction},attributes:{className:`pie-legend-swatch${v?" pie-dim":""}`}}));const A=P.lines.join("\n");f.push(e.text({id:M("legend-label",P.label),role:"legend",text:A,x:P.textX,y:P.textY,fontSize:u.legendTextSize??c.nodeLabelFontSize,fontWeight:T,letterSpacing:c.nodeLetterSpacing,block:P.block,...P.literalText===true?{display:"literal"}:{},anchor:"start",dominantBaseline:"middle",paint:{fill:u.legendTextColor??c.nodeTextColor??"var(--_text)"},channels:{category:P.label,value:P.fraction},attributes:{className:"pie-legend-text",...vO(P.literalText===true,A)}}))}if(n.title){const C=n.title.text;f.push(e.text({id:"title",role:"title",text:C,x:n.title.x,y:n.title.y,fontSize:u.titleTextSize??c.groupHeaderFontSize,fontWeight:c.groupHeaderFontWeight,letterSpacing:c.groupLetterSpacing,block:n.title.block,...n.title.literalText===true?{display:"literal"}:{},anchor:"middle",dominantBaseline:"middle",paint:{fill:u.titleTextColor??c.groupTextColor??c.nodeTextColor??"var(--_text)"},attributes:{className:"pie-title",...vO(n.title.literalText===true,C)}}))}if(l||m){for(const[C,P]of n.slices.entries()){const E=`${(P.displayLabel??P.label).replace(/\n/g," ")}: ${ky(P.value)} (${pc(P.fraction)})`;const k=M("tooltip:slice",P.label);const v={id:x[C],role:"pie-slice"};f.push(e.group({id:k,role:"chrome",owner:v,open:'<g class="pie-slice-group">',close:"</g>",join:"",children:[{indent:0,node:e.shape({id:`${k}:hit`,role:"chrome",owner:v,...m?{visibility:"conditional",conditionalPaint:{fill:"transparent",stroke:"var(--fg)",strokeWidth:String(b)}}:{},geometry:{kind:"path",d:P.path},paint:{fill:"transparent",...m?{stroke:"transparent",strokeWidth:String(b)}:{}},...m?{attributes:{className:"pie-slice-hover-target"}}:{}})},...l?[{indent:0,node:e.documentContent({id:`${k}:title`,role:"chrome",nonPaint:"interaction-metadata"},`<title>${At(E)}</title>`)},{indent:0,node:Ac(e,"pie",P.tooltip,`${k}:body`,v)}]:[]]}))}}f.push(e.documentClose());return{family:"pie",width:n.width,height:n.height,colors:i,transparent:a,parts:f}}function B9(e,t){return e.outerStrokeColor??t.nodeBorderColor??"var(--_node-stroke)"}function W9(e,t,n){return Ot(e.width,e.height,t,n,{attrs:{role:"img","aria-roledescription":"pie chart"}})}function z9(e,t,n,i){const r=t.strokeWidth??i?.lineWidth??e.nodeLineWidth;const o=f1(r);const s=n?mu("pie",["pie-slice-group"]):"";const a=t.highlightSlice==="hover"?",\n .pie-slice-group:hover > .pie-slice-hover-target":"";return`<style>
39
+ .pie-slice.highlighted-on-hover:hover${a} { stroke: var(--fg); stroke-width: ${o}; opacity: 1; }${s}
40
+ </style>`}function f1(e){return Math.max(e+1,2.5)}function vO(e,t){return e&&D9(t)?{data:{"literal-text":"true"}}:{}}function TO(e){return Math.round(e*100)/100}function G9(e,t,n){const i=_n("var(--bg)",n);if(i===void 0||!Nn(e))return void 0;return t>=1?e:tr(e,i,t*100)}var LO=gt(O9);var SAe={configDiagnostics:RO,statementEnds:R0,normalizeRequest:e=>({familyConfig:{visual:sM(e.source.frontmatter)}}),layout:e=>ht(UI(Tn(rA(r2(e.source)),e.source.frontmatter),e.renderOptions,e.familyConfig?.visual??sM(),e.styleFace)),projectPositioned:ut(VI),lowerScene:ft(LO)};var H9=Object.fromEntries([...["chartWidth","chartHeight","titleFontSize","quadrantLabelFontSize","xAxisLabelFontSize","yAxisLabelFontSize","pointLabelFontSize","pointRadius"].map(e=>[e,Jt]),...["titlePadding","quadrantPadding","xAxisLabelPadding","yAxisLabelPadding","pointTextPadding","quadrantInternalBorderStrokeWidth","quadrantExternalBorderStrokeWidth"].map(e=>[e,Yt]),["useMaxWidth",lt]]);var AO=e=>xt("quadrant",e,H9);var j9=["chartWidth","chartHeight","titleFontSize","quadrantLabelFontSize","xAxisLabelFontSize","yAxisLabelFontSize","pointLabelFontSize","pointRadius"];var Y9=["titlePadding","quadrantPadding","xAxisLabelPadding","yAxisLabelPadding","pointTextPadding","quadrantInternalBorderStrokeWidth","quadrantExternalBorderStrokeWidth"];function h1(e={}){const t=Sn(e,["quadrantChart"])??{};const n={};for(const r of j9){const o=Mt(t,[r]);if(typeof o==="number"&&Number.isFinite(o)&&o>0)n[r]=o}for(const r of Y9){const o=Mt(t,[r]);if(typeof o==="number"&&Number.isFinite(o)&&o>=0)n[r]=o}const i=Mt(t,["useMaxWidth"]);if(typeof i==="boolean")n.useMaxWidth=i;return n}var Bi={paddingX:24,paddingY:24,titleFontSize:18,titleGap:18,plotSize:380,axisFontSize:13,axisLabelPadding:4,quadrantFontSize:15,pointRadius:6,pointFontSize:12,pointTextPadding:4};function p1(e={}){return{nodeLabelFontSize:e.pointLabelFontSize??Bi.pointFontSize,edgeLabelFontSize:e.xAxisLabelFontSize??Bi.axisFontSize,groupHeaderFontSize:e.quadrantLabelFontSize??Bi.quadrantFontSize,nodeLabelFontWeight:500,edgeLabelFontWeight:500,groupHeaderFontWeight:600,nodePaddingX:0,nodePaddingY:0,nodeLineWidth:et.innerBox,edgeLineWidth:1,groupCornerRadius:0,groupPaddingX:0,groupPaddingY:0,groupLineWidth:2}}function Xt(e){return Math.round(e*100)/100}function _x(e,t,n,i,r,o){return Be(e,{display:"formatted",transform:o,maxWidth:t,fontSize:n,fontWeight:i,letterSpacing:r})}function q9(e){if(e<=8)return Bi.plotSize;return Math.min(720,Bi.plotSize+(e-8)*20)}var nm=class{cells=new Map;values=[];wide=[];visited=[];query=0;cellsOf(t){const n=Math.floor(t.x0/64),i=Math.floor(t.x1/64);const r=Math.floor(t.y0/64),o=Math.floor(t.y1/64);if(![n,i,r,o].every(Number.isSafeInteger)||i<n||o<r||(i-n+1)*(o-r+1)>256)return void 0;return[n,i,r,o]}add(t,n){const i=this.values.length;this.values.push(n);const r=this.cellsOf(t);if(!r){this.wide.push(i);return}const[o,s,a,l]=r;for(let c=a;c<=l;c++)for(let d=o;d<=s;d++){const u=`${d},${c}`,f=this.cells.get(u);if(f)f.push(i);else this.cells.set(u,[i])}}some(t,n){const i=this.cellsOf(t);if(!i)return this.values.some(n);const r=++this.query;const o=d=>{if(this.visited[d]===r)return false;this.visited[d]=r;return n(this.values[d])};for(const d of this.wide)if(o(d))return true;const[s,a,l,c]=i;for(let d=l;d<=c;d++)for(let u=s;u<=a;u++){for(const f of this.cells.get(`${u},${d}`)??[])if(o(f))return true}return false}};var Dx=(e,t)=>Math.min(e.x1,t.x1)-Math.max(e.x0,t.x0)>.5&&Math.min(e.y1,t.y1)-Math.max(e.y0,t.y0)>.5;var X9=[0,Math.PI,-Math.PI/2,Math.PI/2,-Math.PI/4,Math.PI/4,-3*Math.PI/4,3*Math.PI/4,-Math.PI/8,Math.PI/8,-3*Math.PI/8,3*Math.PI/8,-5*Math.PI/8,5*Math.PI/8,-7*Math.PI/8,7*Math.PI/8];var U9=10;var V9=X9.map(e=>{const t=Math.cos(e);return{cos:t,sin:Math.sin(e),anchor:t>.38?"start":t<-.38?"end":"middle"}});function*K9(e,t,n,i,r){yield{x:e+n,y:t,anchor:"start",far:false,box:{x0:e+n,y0:t-r/2,x1:e+n+i,y1:t+r/2}};yield{x:e-n,y:t,anchor:"end",far:false,box:{x0:e-n-i,y0:t-r/2,x1:e-n,y1:t+r/2}};yield{x:e,y:t+n+r/2,anchor:"middle",far:false,box:{x0:e-i/2,y0:t+n,x1:e+i/2,y1:t+n+r}};yield{x:e,y:t-n-r/2,anchor:"middle",far:false,box:{x0:e-i/2,y0:t-n-r,x1:e+i/2,y1:t-n}};for(let o=1;o<=U9;o++){const s=n+o*(r+6);for(const{cos:a,sin:l,anchor:c}of V9){const d=e+a*s;const u=t+l*s;const f=c==="start"?d:c==="end"?d-i:d-i/2;yield{x:d,y:u,anchor:c,far:true,box:{x0:f,y0:u-r/2,x1:f+i,y1:u+r/2}}}}}function IO(e,t,n,i){const r=i.x-e;const o=i.y-t;const s=Math.hypot(r,o)||1;const a=r/s;const l=o/s;const c=i.anchor==="start"?i.box.x0-2:i.anchor==="end"?i.box.x1+2:i.x;const d=i.anchor==="middle"?i.y>t?i.box.y0-1:i.box.y1+1:i.y;return{x1:Xt(e+a*n),y1:Xt(t+l*n),x2:Xt(c),y2:Xt(d)}}function tm(e,t,n,i,r,o){return(n-e)*(o-t)-(i-t)*(r-e)}function Ox(e,t,n){const i=n.x2-n.x1,r=n.y2-n.y1;const o=i*i+r*r;const s=o===0?0:Math.max(0,Math.min(1,((e-n.x1)*i+(t-n.y1)*r)/o));return Math.hypot(e-(n.x1+s*i),t-(n.y1+s*r))}function m1(e,t){if(Math.hypot(e.x1-t.x1,e.y1-t.y1)<=.5)return false;const n=.01;const i=(l,c,d)=>Math.abs(tm(l.x1,l.y1,l.x2,l.y2,c,d))<=n&&c>=Math.min(l.x1,l.x2)-n&&c<=Math.max(l.x1,l.x2)+n&&d>=Math.min(l.y1,l.y2)-n&&d<=Math.max(l.y1,l.y2)+n;const r=tm(e.x1,e.y1,e.x2,e.y2,t.x1,t.y1);const o=tm(e.x1,e.y1,e.x2,e.y2,t.x2,t.y2);const s=tm(t.x1,t.y1,t.x2,t.y2,e.x1,e.y1);const a=tm(t.x1,t.y1,t.x2,t.y2,e.x2,e.y2);if(r*o<-n&&s*a<-n||i(e,t.x1,t.y1)||i(e,t.x2,t.y2)||i(t,e.x1,e.y1)||i(t,e.x2,e.y2))return true;return Math.min(Ox(e.x1,e.y1,t),Ox(e.x2,e.y2,t),Ox(t.x1,t.y1,e),Ox(t.x2,t.y2,e))<3}function FO(e,t){const n={x0:t.x0-2,y0:t.y0-2,x1:t.x1+2,y1:t.y1+2};if(Math.max(e.x1,e.x2)<n.x0||Math.min(e.x1,e.x2)>n.x1||Math.max(e.y1,e.y2)<n.y0||Math.min(e.y1,e.y2)>n.y1)return false;const i=(o,s)=>o>=n.x0&&o<=n.x1&&s>=n.y0&&s<=n.y1;if(i(e.x1,e.y1)||i(e.x2,e.y2))return true;const r=[{x1:n.x0,y1:n.y0,x2:n.x1,y2:n.y0},{x1:n.x1,y1:n.y0,x2:n.x1,y2:n.y1},{x1:n.x1,y1:n.y1,x2:n.x0,y2:n.y1},{x1:n.x0,y1:n.y1,x2:n.x0,y2:n.y0}];return r.some(o=>m1(e,o))}function NO(e,t={},n={},i){const r=Ue(t,p1(n),i);const o=n.quadrantPadding??Bi.paddingX;const s=n.quadrantPadding??Bi.paddingY;const a=n.titleFontSize??Bi.titleFontSize;const l=n.titlePadding??Bi.titleGap;const c=Math.max(r.groupHeaderFontWeight,600);let d=e.title?Be(e.title,{display:"formatted",transform:r.groupTextTransform,fontSize:a,fontWeight:c,letterSpacing:r.groupLetterSpacing}):void 0;let u=d?.text;let f=e.title?a+l:0;const h=n.xAxisLabelFontSize??r.edgeLabelFontSize;const m=n.yAxisLabelFontSize??r.edgeLabelFontSize;const p=n.xAxisLabelPadding??Bi.axisLabelPadding;const g=n.yAxisLabelPadding??Bi.axisLabelPadding;const y=h+p*2+7;const w=m+g*2+7;let S=y;let x=w;let M=q9(e.points.length);let b;let C;for(let V=0;V<2;V++){if(n.chartWidth!==void 0||n.chartHeight!==void 0){const K=o*2+x;const Z=s*2+f+S;const Q=n.chartWidth!==void 0?n.chartWidth-K:Number.POSITIVE_INFINITY;const se=n.chartHeight!==void 0?n.chartHeight-Z:Number.POSITIVE_INFINITY;M=Math.max(60,Math.min(Q,se))}const ne=Math.max(24,M/2-12);b=e.xAxis?{near:_x(e.xAxis.near,ne,h,r.edgeLabelFontWeight,r.edgeLetterSpacing,r.edgeTextTransform),...e.xAxis.far?{far:_x(e.xAxis.far,ne,h,r.edgeLabelFontWeight,r.edgeLetterSpacing,r.edgeTextTransform)}:{}}:void 0;C=e.yAxis?{near:_x(e.yAxis.near,ne,m,r.edgeLabelFontWeight,r.edgeLetterSpacing,r.edgeTextTransform),...e.yAxis.far?{far:_x(e.yAxis.far,ne,m,r.edgeLabelFontWeight,r.edgeLetterSpacing,r.edgeTextTransform)}:{}}:void 0;if(e.title){d=Be(e.title,{display:"formatted",transform:r.groupTextTransform,fontSize:a,fontWeight:c,letterSpacing:r.groupLetterSpacing,maxWidth:M});u=d.text;f=d.height-(d.lineHeight-d.fontSize)+l}const X=Math.max(h*hi,...[b?.near,b?.far].map(K=>K?.height??0));const U=Math.max(m*hi,...[C?.near,C?.far].map(K=>K?.height??0));S=y+X-h*hi;x=w+U-m*hi}const P=o+x;const E=s+f;const k=M/2;const v=P+M+o;const T=E+M+S+s;const A=[{number:2,col:0,row:0},{number:1,col:1,row:0},{number:3,col:0,row:1},{number:4,col:1,row:1}];const R=A.map(({number:V,col:ne,row:X})=>{const U=P+ne*k;const K=E+X*k;return{number:V,label:e.quadrants[V-1],labelBlock:e.quadrants[V-1]===void 0?void 0:Be(e.quadrants[V-1],{display:"formatted",transform:r.groupTextTransform,fontSize:r.groupHeaderFontSize,fontWeight:r.groupHeaderFontWeight,letterSpacing:r.groupLetterSpacing}),x:Xt(U),y:Xt(K),width:Xt(k),height:Xt(k),labelX:Xt(U+k/2),labelY:Xt(K+k/2)}});const I=r.nodeLabelFontSize;const L=r.nodeLabelFontWeight;const $=n.pointTextPadding??Bi.pointTextPadding;const B=R.filter(V=>V.label).map(V=>{const ne=V.labelBlock.width;return{x0:V.labelX-ne/2,y0:V.labelY-V.labelBlock.height/2,x1:V.labelX+ne/2,y1:V.labelY+V.labelBlock.height/2}});const F=n.pointRadius??Bi.pointRadius;const z=e.points.map(V=>a2(V,e.classDefs,{radius:F}));const _=e.points.map((V,ne)=>{const X=P+V.x*M,U=E+(1-V.y)*M,K=z[ne].radius+1;return{x0:X-K,y0:U-K,x1:X+K,y1:U+K}});const H={x0:2,y0:2,x1:v-2,y1:T-2};const D=[];const j=e.points.length>=128;const W=j?new nm:void 0;const O=j?new nm:void 0;const N=j?new nm:void 0;if(W&&O){for(const V of B)W.add(V,V);for(const V of _)O.add(V,V)}const G=e.points.map((V,ne)=>{const X=z[ne];const U=Xt(P+V.x*M);const K=Xt(E+(1-V.y)*M);const Z=Be(V.label,{display:"formatted",transform:r.nodeTextTransform,fontSize:I,fontWeight:L,letterSpacing:r.nodeLetterSpacing});const Q=Z.text;const se=Z.width;const te=Z.height;const ee=X.radius+$;const ae=ye=>{const Se=ye.box;if(!(Se.x0>=H.x0&&Se.y0>=H.y0&&Se.x1<=H.x1&&Se.y1<=H.y1)||(W?W.some(Se,$e=>Dx(Se,$e)):B.some($e=>Dx(Se,$e)))||(O?O.some(Se,$e=>Dx(Se,$e)):_.some($e=>Dx(Se,$e))))return false;if(!ye.far)return true;const Te=IO(U,K,X.radius,ye);if(!W||!N)return!B.some($e=>FO(Te,$e))&&!D.some($e=>m1(Te,$e));const Ie={x0:Math.min(Te.x1,Te.x2),y0:Math.min(Te.y1,Te.y2),x1:Math.max(Te.x1,Te.x2),y1:Math.max(Te.y1,Te.y2)};const Ee={x0:Ie.x0-2,y0:Ie.y0-2,x1:Ie.x1+2,y1:Ie.y1+2};const ve={x0:Ie.x0-3,y0:Ie.y0-3,x1:Ie.x1+3,y1:Ie.y1+3};return!W.some(Ee,$e=>FO(Te,$e))&&!N.some(ve,$e=>m1(Te,$e))};let ie;let oe;for(const ye of K9(U,K,ee,se,te)){ie??=ye;if(ae(ye)){oe=ye;break}}const ue={label:Q,labelBlock:Z,nx:V.x,ny:V.y,cx:U,cy:K,radius:X.radius,labelX:Xt((oe??ie).x),labelY:Xt((oe??ie).y),labelAnchor:(oe??ie).anchor};ue.tooltip=Ja(U,K-X.radius,`${Q}: [${V.x}, ${V.y}]`);if(X.fill!==void 0)ue.fill=X.fill;if(X.stroke!==void 0)ue.stroke=X.stroke;if(X.strokeWidth!==void 0)ue.strokeWidth=X.strokeWidth;if(V.className!==void 0)ue.className=V.className;if(oe){B.push(oe.box);W?.add(oe.box,oe.box);const ye={x0:Xt(oe.box.x0),y0:Xt(oe.box.y0),x1:Xt(oe.box.x1),y1:Xt(oe.box.y1)};ue.labelBox=ye;if(oe.far){ue.leader=IO(U,K,X.radius,oe);D.push(ue.leader);const Se=ue.leader;N?.add({x0:Math.min(Se.x1,Se.x2),y0:Math.min(Se.y1,Se.y2),x1:Math.max(Se.x1,Se.x2),y1:Math.max(Se.y1,Se.y2)},Se)}}else{ue.labelHidden=true}return ue});const Y=[];const q=V=>E+M+Math.max(h,V.lineHeight/2)+p;if(b){Y.push({text:b.near.text,block:b.near,x:Xt(P+4),y:Xt(q(b.near)),anchor:"start",fontSize:h});if(b.far){Y.push({text:b.far.text,block:b.far,x:Xt(P+M-4),y:Xt(q(b.far)),anchor:"end",fontSize:h})}}if(C){const V=ne=>o+Math.max(m,ne.lineHeight/2);Y.push({text:C.near.text,block:C.near,x:Xt(V(C.near)),y:Xt(E+M-4),anchor:"start",fontSize:m});if(C.far){Y.push({text:C.far.text,block:C.far,x:Xt(V(C.far)),y:Xt(E+4),anchor:"end",fontSize:m})}}return{width:Xt(v),height:Xt(T),title:u!==void 0?{text:u,block:d,x:Xt(P+M/2),y:Xt(s+(f-l)/2),fontSize:a}:void 0,accessibility:e.accessibility?{...e.accessibility}:void 0,plot:{x:Xt(P),y:Xt(E),size:Xt(M)},regions:R,points:G,axisLabels:Y,visual:n}}var IAe={titleFontSize:Bi.titleFontSize,axisFontSize:Bi.axisFontSize,quadrantFontSize:Bi.quadrantFontSize,pointFontSize:Bi.pointFontSize};function J9(e,t){const{positioned:n,colors:i,resolved:r}=t;const o=r.renderOptions;const s=i.font??"Inter";const a=o.transparent??false;const l=o.interactive??false;const c=Ue(o,p1(n.visual),r.styleFace);const d=[];const u={title:n.accessibility?.title??n.title?.text,description:n.accessibility?.description};const f=`quadrant-${pi(n.width,n.height,u.title??"",u.description??"",...n.points.flatMap(v=>[v.label,v.nx,v.ny]))}`;const h=`${f}-title`;const m=`${f}-desc`;const p=tK(l);const g=[Q9(n,i,a,u,f,h,m)];if(u.title)g.push(`<title id="${h}">${At(u.title)}</title>`);if(u.description)g.push(`<desc id="${m}">${At(u.description)}</desc>`);g.push(Dt(s,false,i.shadow,i.embedFontImport));const y=en(i);if(y)g.push(`<defs>${y}</defs>`);if(p)g.push(p);d.push(e.documentOpen({id:"prelude",width:n.width,height:n.height,colors:i,transparent:a,font:s,hasMonoFont:false,...p?{extraCss:p}:{}},g.join("\n")));const{plot:w}=n;const S=w.size/2;const x=n.visual.quadrantInternalBorderStrokeWidth??c.lineWidth;const M=n.visual.quadrantExternalBorderStrokeWidth??c.groupLineWidth;for(const v of n.regions){const T=$O(v.number,c);d.push(e.shape({id:`plate:${v.number}`,role:"plate",geometry:{kind:"rect",x:v.x,y:v.y,width:v.width,height:v.height},paint:{fill:T,stroke:"none"},channels:v.label?{category:v.label}:void 0,attributes:{className:"quadrant-region",data:{quadrant:String(v.number)}}}))}const b=w.x+S;const C=w.y+S;const P={stroke:c.edgeStrokeColor??"var(--_line)",strokeWidth:String(x)};d.push(e.shape({id:"divider:v",role:"grid",geometry:{kind:"line",x1:b,y1:w.y,x2:b,y2:w.y+w.size},paint:P,attributes:{className:"quadrant-divider"}}));d.push(e.shape({id:"divider:h",role:"grid",geometry:{kind:"line",x1:w.x,y1:C,x2:w.x+w.size,y2:C},paint:P,attributes:{className:"quadrant-divider"}}));d.push(e.shape({id:"border",role:"chrome",geometry:{kind:"rect",x:w.x,y:w.y,width:w.size,height:w.size},paint:{fill:"none",stroke:c.groupBorderColor??c.nodeBorderColor??"var(--_node-stroke)",strokeWidth:String(M)},attributes:{className:"quadrant-border"}}));for(const v of n.regions){if(!v.label)continue;const T=v.labelBlock?.text??v.label;d.push(e.text({id:`quadrant-label:${v.number}`,role:"label",text:T,x:v.labelX,y:v.labelY,fontSize:c.groupHeaderFontSize,fontWeight:c.groupHeaderFontWeight,letterSpacing:c.groupLetterSpacing,block:v.labelBlock,anchor:"middle",dominantBaseline:"middle",paint:{fill:c.groupTextColor??"var(--_text-sec)"},channels:{category:v.label},attributes:{className:"quadrant-label"}}))}const E=[];const k=new Map;for(const v of n.points){const T=k.get(v.label)??0;k.set(v.label,T+1);const A=T===0?`point:${v.label}`:`point:${v.label}#${T}`;if(v.leader){const I=v.leader;d.push(e.shape({id:`leader:${v.label}`,role:"chrome",geometry:{kind:"line",x1:I.x1,y1:I.y1,x2:I.x2,y2:I.y2},paint:{stroke:c.edgeStrokeColor??"var(--_line)",strokeWidth:"1"},attributes:{className:"quadrant-leader"}}))}const R=v.className?`quadrant-point ${v.className}`:"quadrant-point";d.push(e.shape({id:A,role:"point",geometry:{kind:"circle",cx:v.cx,cy:v.cy,r:v.radius},paint:{fill:v.fill??c.nodeFillColor??"var(--accent, var(--_arrow))",stroke:v.stroke??c.nodeBorderColor??"var(--bg)",strokeWidth:v.strokeWidth??String(Math.max(1,c.nodeLineWidth))},attributes:{className:R,data:{label:v.label,x:String(v.nx),y:String(v.ny)}}}));if(!v.labelHidden){const I=eK(v,n,c);d.push(e.text({id:`${A}:label`,role:"label",text:v.label,x:v.labelX,y:v.labelY,fontSize:c.nodeLabelFontSize,fontWeight:c.nodeLabelFontWeight,letterSpacing:c.nodeLetterSpacing,block:v.labelBlock,anchor:v.labelAnchor,dominantBaseline:"middle",paint:{fill:c.nodeTextColor??"var(--_text)",stroke:I,strokeWidth:String(Z9),strokeLinejoin:"round",paintOrder:"stroke"},attributes:{className:"quadrant-point-label"}}))}if(l){const I=`${v.label}: [${v.nx}, ${v.ny}]`;const L={id:A,role:"point"};E.push(e.group({id:`tooltip:${A}`,role:"chrome",owner:L,open:'<g class="quadrant-point-group">',close:"</g>",join:"",children:[{indent:0,node:e.shape({id:`${A}:hit`,role:"chrome",owner:L,geometry:{kind:"circle",cx:v.cx,cy:v.cy,r:v.radius+6},paint:{fill:"transparent"}})},{indent:0,node:e.documentContent({id:`${A}:title`,role:"chrome",nonPaint:"interaction-metadata"},`<title>${At(I)}</title>`)},{indent:0,node:Ac(e,"quadrant",v.tooltip,`${A}:tooltip`,L)}]}))}}d.push(...E);for(const v of n.axisLabels){const T=v.text.split("\n");const A=T.join("\n");const R=v.x<w.x;const I=R?{kind:"rotate",angle:-90,cx:v.x,cy:v.y}:void 0;const L=v.block?.lineHeight??v.fontSize*1.3;const $=v.y+(T.length-1)*L/2-v.fontSize*.35;d.push(e.text({id:`axis:${v.text}`,role:"axis",text:A,x:v.x,y:$,fontSize:v.fontSize,fontWeight:c.edgeLabelFontWeight,letterSpacing:c.edgeLetterSpacing,block:v.block,anchor:v.anchor,paint:{fill:c.edgeTextColor??"var(--_text-muted)"},transform:I,attributes:{className:"quadrant-axis-label"}}))}if(n.title){const v=n.title.text;d.push(e.text({id:"title",role:"title",text:v,x:n.title.x,y:n.title.y,fontSize:n.title.fontSize,fontWeight:Math.max(c.groupHeaderFontWeight,600),letterSpacing:c.groupLetterSpacing,block:n.title.block,anchor:"middle",dominantBaseline:"middle",paint:{fill:c.groupTextColor??c.nodeTextColor??"var(--_text)"},attributes:{className:"quadrant-title"}}))}d.push(e.documentClose());return{family:"quadrant",width:n.width,height:n.height,colors:i,transparent:a,parts:d}}function Q9(e,t,n,i,r,o,s){const a=e.visual.useMaxWidth?{width:"100%",height:"100%",style:`max-width:${e.width}px`}:{};return Ot(e.width,e.height,t,n,{...a,attrs:{id:r,...ki(i.title,i.description,o,s,"quadrant chart")}})}var Z9=3;function eK(e,t,n){const i=e.labelBox;const r=i?(i.x0+i.x1)/2:e.labelX;const o=i?(i.y0+i.y1)/2:e.labelY;const s=t.regions.find(a=>r>=a.x&&r<=a.x+a.width&&o>=a.y&&o<=a.y+a.height);return s?$O(s.number,n):"var(--bg)"}function $O(e,t){const n=e===1||e===3?10:5;if(t.groupFillColor){const i=e===1||e===3?88:76;return`color-mix(in srgb, ${t.groupFillColor} ${i}%, var(--bg))`}return`color-mix(in srgb, var(--accent, var(--_arrow)) ${n}%, var(--bg))`}function tK(e){return e?`<style>${mu("quadrant",["quadrant-point-group"])}
41
+ </style>`:void 0}var _O=gt(J9);var ZAe={configDiagnostics:AO,statementEnds:$y,normalizeRequest:e=>({familyConfig:{visual:h1(e.source.frontmatter)}}),layout:e=>ht(NO(Tn(Em(nN(e.source.familyLines),e.source.accessibility),e.source.frontmatter),e.renderOptions,e.familyConfig?.visual??h1(),e.styleFace)),projectPositioned:ut(KI),lowerScene:ft(_O)};var DO=["axisColor","axisStrokeWidth","axisLabelFontSize","curveOpacity","curveStrokeWidth","graticuleColor","graticuleStrokeWidth","graticuleOpacity","legendBoxSize","legendFontSize"];var nK=["width","height","axisScaleFactor"];var Cn=Object.freeze({dimension:4096,margin:4096,factor:8,axisLabelFactorMin:1.1,fontSize:256,lineWidth:64,legendBoxSize:512});var iK=["marginTop","marginRight","marginBottom","marginLeft"];function g1(e={}){const t=Sn(e,["radar"])??{};const n={};for(const m of nK){const p=Mt(t,[m]);const g=m==="width"||m==="height"?Cn.dimension:Cn.factor;if(typeof p==="number"&&Number.isFinite(p)&&p>0&&p<=g)n[m]=p}const i=Mt(t,["axisLabelFactor"]);if(typeof i==="number"&&Number.isFinite(i)&&i>=Cn.axisLabelFactorMin&&i<=Cn.factor){n.axisLabelFactor=i}for(const m of iK){const p=Mt(t,[m]);if(typeof p==="number"&&Number.isFinite(p)&&p>=0&&p<=Cn.margin)n[m]=p}const r=Mt(t,["curveTension"]);if(typeof r==="number"&&Number.isFinite(r)&&r>=0&&r<=1){n.curveTension=r}const o=Mt(t,["useMaxWidth"]);if(typeof o==="boolean")n.useMaxWidth=o;const s=Mt(t,["tickLabels"]);if(typeof s==="boolean")n.tickLabels=s;const a=Sn(e,["themeVariables","radar"])??{};const l=["axisStrokeWidth","axisLabelFontSize","curveStrokeWidth","graticuleStrokeWidth","legendBoxSize","legendFontSize"];for(const m of l){const p=Mt(a,[m]);const g=m==="legendBoxSize"?Cn.legendBoxSize:m.endsWith("FontSize")?Cn.fontSize:Cn.lineWidth;if(typeof p==="number"&&Number.isFinite(p)&&p>0&&p<=g)n[m]=p}for(const m of["curveOpacity","graticuleOpacity"]){const p=Mt(a,[m]);if(typeof p==="number"&&Number.isFinite(p)&&p>=0&&p<=1)n[m]=p}for(const m of["axisColor","graticuleColor"]){const p=mn(Mt(a,[m]),m==="graticuleColor");if(p)n[m]=p}const c=mn(Mt(e,["themeVariables","titleColor"]));if(c)n.titleColor=c;const d=Mt(e,["themeVariables","fontSize"]);const u=typeof d==="number"?d:typeof d==="string"&&/^\d+(?:\.\d+)?(?:px)?$/i.test(d.trim())?Number.parseFloat(d):Number.NaN;if(Number.isFinite(u)&&u>0&&u<=Cn.fontSize){n.titleFontSize=u}const f=[];let h=false;for(let m=0;m<12;m++){const p=mn(Mt(e,["themeVariables",`cScale${m}`]));if(p){f[m]=p;h=true}}if(h)n.paletteOverrides=Array.from(f,m=>m??null);return n}var rK={width:es(Cn.dimension),height:es(Cn.dimension),marginTop:Zl(Cn.margin),marginRight:Zl(Cn.margin),marginBottom:Zl(Cn.margin),marginLeft:Zl(Cn.margin),axisScaleFactor:es(Cn.factor),axisLabelFactor:wn(Cn.axisLabelFactorMin,Cn.factor),curveTension:wn(0,1),useMaxWidth:lt,tickLabels:lt};function oK(e){const t=Zr(e,"themeVariables");if(!t||!("radar"in t))return[];const n=Zr(t,"radar");if(!n)return[{code:"INEFFECTIVE_CONFIG",field:"themeVariables.radar",message:"themeVariables.radar must be an object; the invalid value has no effect."}];const i=new Set(DO);const r=[];const o=new Set(["axisStrokeWidth","curveStrokeWidth","graticuleStrokeWidth"]);const s=new Set(["axisLabelFontSize","legendFontSize"]);const a=new Set(["curveOpacity","graticuleOpacity"]);const l=new Set(["axisColor","graticuleColor"]);for(const c of Object.keys(n).sort(Bn)){const d=n[c];let u;if(!i.has(c))u="a documented radar theme field";else if(o.has(c)&&!es(Cn.lineWidth).valid(d))u=es(Cn.lineWidth).expected;else if(s.has(c)&&!es(Cn.fontSize).valid(d))u=es(Cn.fontSize).expected;else if(c==="legendBoxSize"&&!es(Cn.legendBoxSize).valid(d))u=es(Cn.legendBoxSize).expected;else if(a.has(c)&&!wn(0,1).valid(d))u="a finite number from 0 through 1";else if(l.has(c)&&!Sl(d))u="a safe CSS color without url(), variables, or context-breaking characters";if(u)r.push({code:"INEFFECTIVE_CONFIG",field:`themeVariables.radar.${c}`,message:`themeVariables.radar.${c} must be ${u}; the invalid value has no effect.`})}return r}var OO=e=>[...oK(e.root),...xt("radar",e,rK)];var mt={radius:120,margin:22,titleFontSize:18,titleGap:16,axisFontSize:12.5,axisLabelPad:8,axisLabelMaxWidth:96,axisLabelMinWidth:58,labelClearGap:7,leaderMinPush:9,legendFontSize:13,legendLabelMaxWidth:168,legendSwatch:14,legendGap:30,legendRowGap:9,legendColumnGap:16,legendSwatchToText:8,ringLabelFontSize:9.5,tickBoxPadX:4,tickBoxPadY:3,dotRadius:3,curveStrokeWidth:2.2};function y1(e={}){return{nodeLabelFontSize:e.legendFontSize??mt.legendFontSize,edgeLabelFontSize:e.axisLabelFontSize??mt.axisFontSize,groupHeaderFontSize:e.titleFontSize??mt.titleFontSize,nodeLabelFontWeight:500,edgeLabelFontWeight:500,groupHeaderFontWeight:600,nodePaddingX:0,nodePaddingY:0,nodeLineWidth:e.curveStrokeWidth??mt.curveStrokeWidth,edgeLineWidth:e.axisStrokeWidth??1,groupCornerRadius:0,groupPaddingX:0,groupPaddingY:0,groupLineWidth:et.outerBox}}function Lt(e){return Math.round(e*100)/100}function sK(e,t,n){return Math.min(Math.max(e,t),n)}function Fc(e,t){return 2*Math.PI*e/t}function Ic(e,t,n,i){return{x:e+n*Math.sin(i),y:t-n*Math.cos(i)}}function BO(e,t,n=0){return e.left<t.right+n&&t.left<e.right+n&&e.top<t.bottom+n&&t.top<e.bottom+n}function aK(e,t,n){if(e.length===0)return"";if(!t||e.length<3){return"M "+e.map(o=>`${Lt(o.x)} ${Lt(o.y)}`).join(" L ")+" Z"}const i=e.length;let r=`M ${Lt(e[0].x)} ${Lt(e[0].y)}`;for(let o=0;o<i;o++){const s=e[(o-1+i)%i],a=e[o],l=e[(o+1)%i],c=e[(o+2)%i];const d=a.x+(l.x-s.x)*n,u=a.y+(l.y-s.y)*n;const f=l.x-(c.x-a.x)*n,h=l.y-(c.y-a.y)*n;r+=` C ${Lt(d)} ${Lt(u)} ${Lt(f)} ${Lt(h)} ${Lt(l.x)} ${Lt(l.y)}`}return r+" Z"}function zO(e,t={},n={},i){const r=WO(e,t,n,i);const o=t.radar?.maxWidth;if(o===void 0)return r;return wy(r,o,(s,a)=>{if(s===2&&(n.width!==void 0||n.height!==void 0))return void 0;let l;if(s===2){const d=e.axes.map((h,m)=>Math.sin(Fc(m,e.axes.length)));const u=Math.max(0,...d)-Math.min(0,...d);const f=Math.max(1,n.axisScaleFactor??1)+(n.axisLabelFactor===void 0?0:n.axisLabelFactor-1.05);l=Math.max(60,r.radius-Math.max(0,a.width-o)/Math.max(1,u*f))}const c=WO(e,t,n,i,{maxWidth:o,...l===void 0?{}:{radius:l}});return r.tickLabels.some((d,u)=>c.tickLabels[u]?.text!==d.text)?a:c})}function WO(e,t,n,i,r){const o=Ue(t,y1(n),i);const s=e.axes.length;if(s>vh)throw new Error(`Radar charts support at most ${vh} axes.`);let a=mt.radius;if(n.width!==void 0||n.height!==void 0){const le=n.width??n.height??mt.radius*2;const we=n.height??n.width??mt.radius*2;a=sK(Math.min(le,we)/2-56,40,400)}if(r?.radius!==void 0)a=r.radius;const l=n.axisScaleFactor??1;const c=n.axisLabelFactor??1.05;const d=n.curveTension??.17;const u=e.graticule==="circle"&&d>0;const f=SN(e);const{min:h,max:m}=f;const p=le=>a*wN(le,f);const g=o.edgeLabelFontSize;const y=o.edgeLabelFontWeight;const w=g*1.3;const S=o.groupHeaderFontSize;const x=Math.max(o.groupHeaderFontWeight,600);const M=Math.max(mt.axisLabelMinWidth,Math.min(mt.axisLabelMaxWidth,a*1.05));const b=le=>e.axes.map(we=>Be(we.label,{display:"literal",transform:o.edgeTextTransform,fontSize:g,fontWeight:y,letterSpacing:o.edgeLetterSpacing,maxWidth:le}));let C=mt.axisLabelMaxWidth;let P=b(C);for(let le=0;le<8&&Math.max(0,...P.map(we=>we.width))>M&&C>mt.axisLabelMinWidth;le++){C=Math.max(mt.axisLabelMinWidth,C-12);P=b(C)}const E=P.map(le=>le.lines);const k=P.map(le=>le.width);const v=P.map(le=>le.height);const T=new Array(s).fill(0);for(const le of e.curves){if(le.values.length!==s)continue;le.values.forEach((we,ke)=>{T[ke]=Math.max(T[ke],p(we))})}const A=a*1.05+mt.axisLabelPad;const R=n.axisLabelFactor===void 0?0:a*(c-1.05);const I=e.axes.map((le,we)=>{const ke=Math.sin(Fc(we,s));return ke>.3?"start":ke<-.3?"end":"middle"});const L=Math.max(a,a*l,...T)+mt.dotRadius+mt.labelClearGap;const $=new Array(s).fill(0).map((le,we)=>Math.max(0,L+v[we]/2-A)+R);const B=new Array(s).fill(false);const F=le=>{const we=Fc(le,s);const ke=A+$[le];const Le=ke*Math.sin(we);const Fe=-ke*Math.cos(we);const Oe=k[le];const We=I[le]==="start"?Le:I[le]==="end"?Le-Oe:Le-Oe/2;return{left:We,right:We+Oe,top:Fe-v[le]/2,bottom:Fe+v[le]/2,rx:Le,ry:Fe}};const z=[];for(let le=0;le<s;le++){const we=$[le];const ke=()=>z.some(Le=>BO(F(le),F(Le),2));if(ke()){B[le]=true;let Le=6;let Fe=false;for(let Oe=0;Oe<48;Oe++){$[le]=we+Le;if(!ke()){Fe=true;break}Le*=2}if(!Fe)throw new Error("Radar axis labels could not be placed within finite layout bounds.")}z.push(le)}const _=n.marginLeft??mt.margin;const H=n.marginRight??mt.margin;const D=n.marginTop??mt.margin;const j=n.marginBottom??mt.margin;const W=a*Math.max(1,l);let O=W,N=W,G=W,Y=W;for(let le=0;le<s;le++){const we=F(le);O=Math.max(O,-we.left);N=Math.max(N,we.right);G=Math.max(G,-we.top);Y=Math.max(Y,we.bottom)}if(n.width){const le=n.width/2;O=Math.max(O,le);N=Math.max(N,le)}if(n.height){const le=n.height/2;G=Math.max(G,le);Y=Math.max(Y,le)}const q=r?Math.max(r.maxWidth,_+O+N+H):void 0;const V=o.nodeLabelFontSize;const ne=o.nodeLabelFontWeight;const X=V*1.25;const U=e.showLegend&&e.curves.length>0;const K=n.legendBoxSize??mt.legendSwatch;const Z=V*(mt.legendLabelMaxWidth/mt.legendFontSize);const Q=q===void 0?0:q-_-H-K-mt.legendSwatchToText;const se=Q>0?Q:Z;const te=U?e.curves.map(le=>{const we=Be(le.label,{display:"literal",transform:o.nodeTextTransform,fontSize:V,fontWeight:ne,letterSpacing:o.nodeLetterSpacing,maxWidth:se});return r&&we.width>se+.01?Be(we.prepared,{...we,maxWidth:Z}):we}):[];const ee=te.map(le=>({block:le}));const ae={gap:mt.legendRowGap,minRowHeight:K,leadingWidth:K+mt.legendSwatchToText,columnGap:mt.legendColumnGap,...q===void 0?{}:{maxWidth:q-_-H}};const ie=qd(ee,ae);const oe=U?ie.width:0;const ue=ie.height;if(U&&!r){G=Math.max(G,ue/2);Y=Math.max(Y,ue/2)}let ye=e.title?Be(e.title,{display:"literal",transform:o.groupTextTransform,fontSize:S,fontWeight:x,letterSpacing:o.groupLetterSpacing,...q===void 0?{}:{maxWidth:Math.max(1,q-_-H)}}):void 0;if(ye&&q!==void 0&&ye.width>q-_-H+.01){ye=Be(ye.prepared,ye)}const Se=ye?ye.height:0;const Te=ye?Se+mt.titleGap:0;const Ie=U&&!r?mt.legendGap+oe:0;const Ee=_+O+N+Ie+H;const ve=r&&U?Math.max(Ee,_+oe+H):Ee;const $e=_+O+(ve-Ee)/2;const De=ye?.width??0;const fe=Math.max(0,De/2-$e);const me=Math.max(0,$e+De/2-ve);const de=ve+fe+me;const be=D+Te+G+Y+j+(r&&U?mt.legendGap+ue:0);const pe=$e+fe;const Re=D+Te+G;const Ne=[];for(let le=1;s>0&&le<=e.ticks;le++){const we=a*le/e.ticks;const ke=le===e.ticks?m:h+(m-h)*(le/e.ticks);const Le=e.graticule==="polygon"?e.axes.map((Fe,Oe)=>{const We=Ic(pe,Re,we,Fc(Oe,s));return{x:Lt(We.x),y:Lt(We.y)}}):[];Ne.push({r:Lt(we),value:ke,points:Le,emphasized:le===e.ticks})}const J=e.axes.map((le,we)=>{const ke=Fc(we,s);const Le=Ic(pe,Re,a*l,ke);const Fe=A+$[we];const Oe=Ic(pe,Re,Fe,ke);const We=B[we]||$[we]>mt.leaderMinPush?(()=>{const ce=Ic(pe,Re,Math.max(a,a*l)+1,ke);const Ae=Ic(pe,Re,Fe-v[we]/2-2,ke);return{x1:Lt(ce.x),y1:Lt(ce.y),x2:Lt(Ae.x),y2:Lt(Ae.y)}})():void 0;return{id:le.id,label:le.label,block:P[we],x:Lt(Le.x),y:Lt(Le.y),labelX:Lt(Oe.x),labelY:Lt(Oe.y),anchor:I[we],lines:E[we],labelWidth:Lt(k[we]),leader:We}});const ge=e.curves.map((le,we)=>{const ke=le.values.length===s;const Le=ke?le.values.map((Fe,Oe)=>{const We=Ic(pe,Re,p(Fe),Fc(Oe,s));return{x:Lt(We.x),y:Lt(We.y)}}):[];return{id:le.id,label:le.label,colorIndex:we,areaPath:ke?aK(Le,u,d):"",vertices:Le,arityMismatch:!ke}});const Ce=[];if(n.tickLabels&&s>0){const le=Fc(0,s)+Math.PI/s;for(const we of[...Ne].reverse()){const ke=Ic(pe,Re,we.r,le);const Le=jd(we.value);const Fe=Be(Le,{display:"literal",fontSize:mt.ringLabelFontSize,fontWeight:y,letterSpacing:o.edgeLetterSpacing});const Oe=Fe.width+mt.tickBoxPadX*2;const We=mt.ringLabelFontSize+mt.tickBoxPadY*2;const ce={text:Le,block:Fe,x:Lt(ke.x),y:Lt(ke.y),w:Lt(Oe),h:Lt(We)};const Ae={left:ce.x-ce.w/2,right:ce.x+ce.w/2,top:ce.y-ce.h/2,bottom:ce.y+ce.h/2};const Pe=Ce.some(He=>BO(Ae,{left:He.x-He.w/2,right:He.x+He.w/2,top:He.y-He.h/2,bottom:He.y+He.h/2},1));if(!Pe)Ce.unshift(ce)}}const Me=[];if(U){const le=r?(de-oe)/2:fe+_+O+N+mt.legendGap;const we=r?Re+Y+mt.legendGap:Re-ue/2;const ke=qd(ee,{...ae,top:we});e.curves.forEach((Le,Fe)=>{const{item:{block:Oe},x:We=0,top:ce,height:Ae,textY:Pe}=ke.rows[Fe];Me.push({label:Le.label,lines:Oe.lines,block:Oe,colorIndex:Fe,x:Lt(le+We),y:Lt(ce+(Ae-K)/2),swatchSize:K,textX:Lt(le+We+K+mt.legendSwatchToText),textY:Lt(Pe)})})}return{width:Lt(de),height:Lt(be),cx:Lt(pe),cy:Lt(Re),radius:Lt(a),title:e.title?{text:ye.text,block:ye,x:Lt(pe),y:Lt(D+Se/2),fontSize:S}:void 0,accessibility:e.accessibility?{...e.accessibility}:void 0,rings:Ne,axes:J,curves:ge,tickLabels:Ce,legend:Me,polygonGraticule:e.graticule==="polygon",typography:{axisFontSize:g,axisFontWeight:y,legendFontSize:V,legendFontWeight:ne,titleFontSize:S,titleFontWeight:x,tickFontSize:mt.ringLabelFontSize,tickFontWeight:y},visual:n}}var yIe={radius:mt.radius,axisFontSize:mt.axisFontSize,titleFontSize:mt.titleFontSize,legendFontSize:mt.legendFontSize,dotRadius:mt.dotRadius};var xIe={axisLabelMaxWidth:mt.axisLabelMaxWidth,axisLabelMinWidth:mt.axisLabelMinWidth,legendLabelMaxWidth:mt.legendLabelMaxWidth,leaderMinPush:mt.leaderMinPush,tickBoxPadX:mt.tickBoxPadX,tickBoxPadY:mt.tickBoxPadY};function GO(e,t,n){const i=la(e,t);if(i!==null&&i>=4.5)return e;const r=[n,"#000000","#ffffff"].map(s=>({color:s,ratio:la(s,t)})).filter(s=>s.ratio!==null).sort((s,a)=>a.ratio-s.ratio);const o=r[0];return o&&o.ratio>=4.5?o.color:n}function lK(e,t){const{positioned:n,colors:i,resolved:r}=t;const o=r.renderOptions;const s=i.font??"Inter";const a=o.transparent??false;const l=Ue(o,y1(n.visual),r.styleFace);const c=[];const d=eu(n.curves.length,{accent:i.accent,bg:i.bg,overrides:n.visual.paletteOverrides});const u=n.visual.curveOpacity??.5;const f=n.visual.axisColor??l.edgeStrokeColor??"var(--_line)";const h=n.visual.graticuleColor??l.edgeStrokeColor??"var(--_line)";const m=n.visual.axisStrokeWidth??1;const p=n.visual.graticuleStrokeWidth??1;const g=n.visual.graticuleOpacity??.7;const y=n.visual.titleColor??l.groupTextColor??l.nodeTextColor??"var(--_text)";const w=l.nodeBorderColor??"var(--bg)";const S=n.visual.axisColor??GO(l.edgeTextColor??i.fg,i.bg,i.fg);const x=GO(l.edgeTextColor??i.fg,i.bg,i.fg);const M={title:n.accessibility?.title??n.title?.text??"Radar chart",description:n.accessibility?.description};const b=HO(n.axes.map(I=>I.id));const C=HO(n.curves.map(I=>I.id));const P=[n.width,n.height,M.title??""];for(const I of n.axes)P.push(I.id);for(const I of n.curves)P.push(I.label);const E=`radar-${pi(P.join("|"))}`;const k=`${E}-title`;const v=`${E}-desc`;const T=[dK(n,i,a,M,E,k,v)];if(M.title)T.push(`<title id="${k}">${At(M.title)}</title>`);if(M.description)T.push(`<desc id="${v}">${At(M.description)}</desc>`);T.push(Dt(s,false,i.shadow,i.embedFontImport));const A=en(i);if(A)T.push(`<defs>${A}</defs>`);c.push(e.documentOpen({id:"prelude",width:n.width,height:n.height,colors:i,transparent:a,font:s,hasMonoFont:false},T.join("\n")));for(let I=0;I<n.rings.length;I++){const L=n.rings[I];c.push(e.shape({id:`ring:${I}`,role:"grid",geometry:n.polygonGraticule?{kind:"polygon",points:L.points}:{kind:"circle",cx:n.cx,cy:n.cy,r:L.r},paint:{fill:"none",stroke:h,strokeOpacity:String(g),strokeWidth:String(L.emphasized?cK(p):p)},attributes:{className:`radar-ring${L.emphasized?" radar-ring-outer":""}`}}))}for(const[I,L]of n.axes.entries()){const $=b[I];c.push(e.shape({id:`spoke:${$}`,role:"grid",geometry:{kind:"line",x1:n.cx,y1:n.cy,x2:L.x,y2:L.y},paint:{stroke:f,strokeWidth:String(m)},attributes:{className:"radar-axis-line"}}))}const R=new Map;for(const[I,L]of n.curves.entries()){if(L.arityMismatch||L.vertices.length===0)continue;const $=C[I];const B={category:L.label};const F=It(r.styleFace,"pie-slice",B,{includeFallback:false});const z=n.visual.paletteOverrides?.[L.colorIndex];const _=z??F?.fillColor??d[L.colorIndex];const H=z??F?.strokeColor??F?.borderColor??_;R.set(L.colorIndex,H);const D=F?.lineWidth??l.nodeLineWidth;const j={fill:_,fillOpacity:String(u),stroke:H,strokeWidth:String(D),strokeLinejoin:"round"};const W={className:"radar-area",data:{curve:L.label}};c.push(e.shape({id:`curve:${$}`,role:"pie-slice",geometry:n.polygonGraticule?{kind:"polygon",points:L.vertices}:{kind:"path",d:L.areaPath},paint:j,channels:B,attributes:W}))}for(const[I,L]of n.curves.entries()){if(L.arityMismatch)continue;const $=C[I];const B={category:L.label};const F=It(r.styleFace,"point",B,{includeFallback:false});const z=n.visual.paletteOverrides?.[L.colorIndex];const _=z??F?.fillColor??R.get(L.colorIndex)??d[L.colorIndex];const H=F?.strokeColor??F?.borderColor??w;const D=F?.lineWidth??1.2;L.vertices.forEach((j,W)=>{c.push(e.shape({id:`dot:${$}:${W}`,role:"point",geometry:{kind:"circle",cx:j.x,cy:j.y,r:3},paint:{fill:_,stroke:H,strokeWidth:String(D)},channels:B,attributes:{className:"radar-dot"}}))})}for(const[I,L]of n.axes.entries()){if(!L.leader)continue;const $=b[I];const B=L.leader;c.push(e.shape({id:`leader:${$}`,role:"grid",geometry:{kind:"line",x1:B.x1,y1:B.y1,x2:B.x2,y2:B.y2},paint:{stroke:h,strokeOpacity:"0.5",strokeWidth:"1"},attributes:{className:"radar-leader"}}))}for(let I=0;I<n.tickLabels.length;I++){const L=n.tickLabels[I];const $=x1(L.x-L.w/2);const B=x1(L.y-L.h/2);c.push(e.shape({id:`tick-box:${I}`,role:"grid",geometry:{kind:"rect",x:$,y:B,width:L.w,height:L.h,rx:4,ry:4},paint:{fill:"var(--bg)",stroke:h,strokeOpacity:"0.35",strokeWidth:"0.75"},attributes:{className:"radar-tick-box"}}))}for(let I=0;I<n.tickLabels.length;I++){const L=n.tickLabels[I];c.push(e.text({id:`tick:${I}`,role:"axis",text:L.text,x:L.x,y:L.y,fontSize:n.typography.tickFontSize,fontWeight:n.typography.tickFontWeight,letterSpacing:l.edgeLetterSpacing,block:L.block,display:"literal",anchor:"middle",dominantBaseline:"middle",baselineShift:0,paint:{fill:x},attributes:{className:"radar-tick-label"}}))}for(const[I,L]of n.axes.entries()){const $=b[I];const B=L.lines;c.push(e.text({id:`axis-label:${$}`,role:"axis",text:B.join("\n"),x:L.labelX,y:L.labelY,fontSize:n.typography.axisFontSize,block:L.block,fontWeight:n.typography.axisFontWeight,letterSpacing:l.edgeLetterSpacing,display:"literal",anchor:L.anchor,dominantBaseline:"middle",baselineShift:0,paint:{fill:S},attributes:{className:"radar-axis-label",ariaLabel:L.label}}))}for(const I of n.legend){const L={category:I.label};const $=It(r.styleFace,"legend",L,{includeFallback:false});const B=n.visual.paletteOverrides?.[I.colorIndex];const F=B??$?.fillColor??R.get(I.colorIndex)??d[I.colorIndex];const z=$?.strokeColor??$?.borderColor??l.nodeBorderColor??"var(--_node-stroke)";const _=$?.lineWidth??1;c.push(e.shape({id:`legend-swatch:${I.colorIndex}`,role:"legend",geometry:{kind:"rect",x:I.x,y:I.y,width:I.swatchSize,height:I.swatchSize,rx:2,ry:2},paint:{fill:F,fillOpacity:"1",stroke:z,strokeWidth:String(_)},channels:L,attributes:{className:"radar-legend-swatch"}}));c.push(e.text({id:`legend-label:${I.colorIndex}`,role:"legend",text:I.lines.join("\n"),x:I.textX,y:I.textY,fontSize:n.typography.legendFontSize,fontWeight:n.typography.legendFontWeight,letterSpacing:l.nodeLetterSpacing,block:I.block,display:"literal",anchor:"start",dominantBaseline:"middle",baselineShift:0,paint:{fill:$?.textColor??l.nodeTextColor??"var(--_text)"},attributes:{className:"radar-legend-text"}}))}if(n.title){c.push(e.text({id:"title",role:"title",text:n.title.text,x:n.title.x,y:n.title.y,fontSize:n.title.fontSize,fontWeight:n.typography.titleFontWeight,letterSpacing:l.groupLetterSpacing,block:n.title.block,display:"literal",anchor:"middle",dominantBaseline:"middle",baselineShift:0,paint:{fill:y},attributes:{className:"radar-title"}}))}c.push(e.documentClose());return{family:"radar",width:n.width,height:n.height,colors:i,transparent:a,parts:c}}function x1(e){return Math.round(e*100)/100}function cK(e){return x1(e*1.4)}function dK(e,t,n,i,r,o,s){const a=e.visual.useMaxWidth?{width:"100%",height:"100%",style:`max-width:${e.width}px`}:{};return Ot(e.width,e.height,t,n,{...a,attrs:{id:r,"aria-roledescription":"radar chart",...ki(i.title,i.description,o,s,"radar chart")}})}function HO(e){const t=new Map;for(const i of e)t.set(i,(t.get(i)??0)+1);const n=new Map;return e.map(i=>{if((t.get(i)??0)<=1)return i;const r=n.get(i)??0;n.set(i,r+1);return`${i}#${r}`})}var jO=gt(lK);var BIe={configDiagnostics:OO,statementEnds:yN,normalizeRequest:e=>({familyConfig:{visual:g1(e.source.frontmatter)}}),layout:e=>ht(zO(bN(e.source.lines,{title:typeof e.source.frontmatter.title==="string"?e.source.frontmatter.title:void 0}),e.renderOptions,e.familyConfig?.visual??g1(e.source.frontmatter),e.styleFace),{injectAccessibility:false}),projectPositioned:ut(JI),lowerScene:ft(jO)};var uK={width:wn(er.width.min,er.width.max),height:wn(er.height.min,er.height.max),nodeWidth:wn(er.nodeWidth.min,er.nodeWidth.max),nodePadding:Zl(er.nodePadding.max),linkColor:an("source, target, gradient, or a drawable CSS color",e=>typeof e==="string"&&(["source","target","gradient"].includes(e)||mn(e,true)!==void 0)),nodeAlignment:qs("justify","center","left","right"),showValues:lt,prefix:Br,suffix:Br,labelStyle:qs("legacy","outlined"),nodeColors:an("an object mapping node labels to drawable CSS colors",e=>Boolean(e)&&typeof e==="object"&&!Array.isArray(e)&&Object.values(e).every(t=>mn(t,true)!==void 0))};var YO=e=>xt("sankey",e,uK);import{sankey as fK,sankeyCenter as hK,sankeyJustify as mK,sankeyLeft as pK,sankeyRight as gK}from"d3-sankey";function qO(e){const t=yi(e.nodes);const n=new Map;const i=e.links.map(({source:r,target:o})=>{let s=n.get(r);if(!s)n.set(r,s=new Map);const a=s.get(o)??0;s.set(o,a+1);const l=`link:${r}->${o}`;const c=a===0?l:`${l}#${a}`;return{id:t(c,["link",r,o,a]),source:r,target:o,occurrence:a}});return{links:i,...e.title?{titleId:t("title",["title"])}:{}}}function XO(e,t){return`${t.prefix}${jd(e)}${t.suffix}`}var oi={padding:24,titleFontSize:18,titleFontWeight:600,titleGap:20,labelFontSize:13,labelFontWeight:500,valueFontWeight:400,labelGap:6,labelLineHeight:13*1.3,minNodeHeight:1,nodeStrokeWidth:1};var b1={nodeLabelFontSize:oi.labelFontSize,edgeLabelFontSize:oi.labelFontSize,groupHeaderFontSize:oi.titleFontSize,nodeLabelFontWeight:oi.labelFontWeight,edgeLabelFontWeight:oi.labelFontWeight,groupHeaderFontWeight:oi.titleFontWeight,nodePaddingX:0,nodePaddingY:0,nodeLineWidth:oi.nodeStrokeWidth,edgeLineWidth:et.connector,groupCornerRadius:0,groupPaddingX:0,groupPaddingY:0,groupLineWidth:et.outerBox};function Wi(e){return Math.round(e*100)/100}var yK={left:pK,right:gK,center:hK,justify:mK};function dr(e,t){if(e===void 0||!Number.isFinite(e)){throw new Error(`d3-sankey did not assign ${t}`)}return e}function xK(e){const t=new Map(e.nodes.map(o=>[o,0]));const n=new Map;for(const o of e.links){t.set(o.target,(t.get(o.target)??0)+1);n.set(o.source,[...n.get(o.source)??[],o.target])}const i=new Map(e.nodes.map(o=>[o,0]));const r=e.nodes.filter(o=>t.get(o)===0);for(let o=0;o<r.length;o++){const s=r[o];for(const a of n.get(s)??[]){i.set(a,Math.max(i.get(a)??0,(i.get(s)??0)+1));const l=(t.get(a)??1)-1;t.set(a,l);if(l===0)r.push(a)}}return Math.max(1,...i.values())+1}function bK(e){const t=new Map(e.nodes.map(i=>[i,0]));const n=new Map(e.nodes.map(i=>[i,0]));for(const i of e.links){n.set(i.source,(n.get(i.source)??0)+i.value);t.set(i.target,(t.get(i.target)??0)+i.value)}return new Map(e.nodes.map(i=>[i,Math.max(t.get(i)??0,n.get(i)??0)]))}function UO(e,t={},n=UM,i){const r=qO(e);const o=Ue(t,b1,i);const s=o.nodeLabelFontSize;const a=n.nodePadding+(n.showValues?15:0);const l=Math.max(n.width,n.nodeWidth*xK(e));const c=e.links.every(N=>N.value===0);const d=bK(e);const u={nodes:e.nodes.map((N,G)=>({id:N,authoredIndex:G})),links:e.links.map((N,G)=>({source:N.source,target:N.target,value:c?1:N.value,authoredIndex:G,authoredValue:N.value}))};fK().nodeId(N=>N.id).nodeWidth(n.nodeWidth).nodePadding(a).nodeAlign(yK[n.nodeAlignment]).extent([[0,0],[l,n.height]])(u);const f=u.nodes;const h=u.links;const m=new Map(f.map(N=>{const G=d.get(N.id)??0;const Y=n.showValues?`${N.id}
42
+ ${XO(G,n)}`:N.id;return[N,Be(Y,{display:"formatted",transform:o.nodeTextTransform,fontSize:s,fontWeight:o.nodeLabelFontWeight,letterSpacing:o.nodeLetterSpacing,safeFont:true})]}));const p=new Map(h.map(N=>[N,Wi(Math.max(N.authoredValue>0?1:0,c?0:N.width??0))]));const g=new Map;for(const N of f){const G=(N.sourceLinks??[]).reduce((V,ne)=>V+p.get(ne),0);const Y=(N.targetLinks??[]).reduce((V,ne)=>V+p.get(ne),0);const q=c?0:dr(N.y1,`y1 for node ${N.id}`)-dr(N.y0,`y0 for node ${N.id}`);g.set(N,Math.max(oi.minNodeHeight,q,G,Y))}const y=new Map;for(const N of f){const G=N.layer??N.depth??0;y.set(G,[...y.get(G)??[],N])}const w=new Map;let S=n.height;for(const N of y.values()){N.sort((Y,q)=>dr(Y.y0,`y0 for node ${Y.id}`)-dr(q.y0,`y0 for node ${q.id}`)||Y.authoredIndex-q.authoredIndex);let G=0;for(const[Y,q]of N.entries()){const V=g.get(q);const ne=Math.max(0,(m.get(q).height-V)/2);const X=Math.max(dr(q.y0,`y0 for node ${q.id}`),Y===0?0:G+ne);w.set(q,X);G=X+V+ne+a}S=Math.max(S,G-a)}const x=new Map;const M=new Map;for(const N of f){const G=w.get(N);const Y=g.get(N);const q=(V,ne)=>{const X=(V==="source"?N.sourceLinks:N.targetLinks)??[];const U=Q=>dr(V==="source"?Q.y0:Q.y1,`${V} y for link ${Q.authoredIndex}`);X.sort((Q,se)=>U(Q)-U(se)||Q.authoredIndex-se.authoredIndex);const K=X.reduce((Q,se)=>Q+p.get(se),0);let Z=G+(Y-K)/2;for(const Q of X){const se=p.get(Q);ne.set(Q,Z+se/2);Z+=se}};q("source",x);q("target",M)}const b=oi.padding;const C=o.groupHeaderFontSize;const P=e.title?Be(e.title,{display:"formatted",transform:o.groupTextTransform,fontSize:C,fontWeight:o.groupHeaderFontWeight,letterSpacing:o.groupLetterSpacing,safeFont:true}):void 0;const E=P?.text;const k=P?P.height-(P.lineHeight-P.fontSize):0;const v=P?k+oi.titleGap:0;const T=oi.padding+v;const A=b+l/2;const R=f.reduce((N,G)=>(d.get(G.id)??0)>(d.get(N.id)??0)?G:N,f[0]).layer??0;const I=new Map;for(const N of f){const G=N.layer??N.depth??0;const Y=dr(N.x0,`x0 for node ${N.id}`);const q=m.get(N);const V=q.lines;const ne=n.labelStyle==="outlined"?G<R?"end":"start":b+Y<A?"start":"end";const X=q.width;I.set(N,{lines:V,block:q,anchor:ne,width:X})}let L=b;let $=b+l;let B=T;let F=T+S;for(const N of f){const G=I.get(N);const Y=b+dr(N.x0,`x0 for node ${N.id}`);const q=b+dr(N.x1,`x1 for node ${N.id}`);if(G.anchor==="start"){$=Math.max($,q+oi.labelGap+G.width)}else{L=Math.min(L,Y-oi.labelGap-G.width)}const V=T+w.get(N)+g.get(N)/2;B=Math.min(B,V-G.block.height/2);F=Math.max(F,V+G.block.height/2)}for(const N of h){const G=b+dr(N.source.x1,`x1 for node ${N.source.id}`);const Y=b+dr(N.target.x0,`x0 for node ${N.target.id}`);if(!(Y>G))continue;const q=G1((Y-G)/2,(Y-G)/2,Math.abs(M.get(N)-x.get(N)),p.get(N)/2);L=Math.min(L,G-q);$=Math.max($,Y+q)}const z=oi.padding-L;const _=T-B;const H=Math.max($+z+oi.padding,(P?.width??0)+2*oi.padding);const D=F+_+oi.padding;const j=f.map(N=>{const G=I.get(N);const Y=b+dr(N.x0,`x0 for node ${N.id}`)+z;const q=b+dr(N.x1,`x1 for node ${N.id}`)+z;const V=T+w.get(N)+_;const ne=V+g.get(N);return{id:`sankey-node-${N.authoredIndex+1}`,label:N.id,value:d.get(N.id)??0,layer:N.layer??N.depth??0,x0:Wi(Y),y0:Wi(V),x1:Wi(q),y1:Wi(ne),labelLines:G.lines,labelBlock:G.block,labelX:Wi(G.anchor==="start"?q+oi.labelGap:Y-oi.labelGap),labelY:Wi((V+ne)/2),labelAnchor:G.anchor}});const W=new Map(j.map(N=>[N.label,N]));const O=h.map(N=>{const G=N.source;const Y=N.target;const q=r.links[N.authoredIndex];const V=Wi(b+dr(G.x1,`x1 for node ${G.id}`)+z);const ne=Wi(b+dr(Y.x0,`x0 for node ${Y.id}`)+z);const X=Wi(T+x.get(N)+_);const U=Wi(T+M.get(N)+_);const K=SK(V,X,ne,U);return{id:q.id,sceneId:`sankey-link-${N.authoredIndex+1}`,source:q.source,target:q.target,sourceId:W.get(G.id).id,targetId:W.get(Y.id).id,value:N.authoredValue,path:K.path,points:K.points,width:p.get(N),sx:V,sy:X,tx:ne,ty:U}});return{width:Wi(H),height:Wi(D),...E?{title:{id:r.titleId,text:E,block:P,x:Wi(H/2),y:oi.padding+k/2}}:{},nodes:j,links:O,total:e.links.reduce((N,G)=>N+G.value,0),visual:n}}function SK(e,t,n,i){const r=Wi((e+n)/2);const o=`M ${e} ${t} C ${r} ${t}, ${r} ${i}, ${n} ${i}`;const s=[];for(const a of[0,.25,.5,.75,1]){const l=1-a;const c=l*l*l*e+3*l*l*a*r+3*l*a*a*r+a*a*a*n;const d=l*l*l*t+3*l*l*a*t+3*l*a*a*i+a*a*a*i;s.push({x:Wi(c),y:Wi(d)})}return{path:o,points:s}}var S1=.5;var wK=3;function MK(e,t){const{positioned:n,colors:i,resolved:r}=t;const o=r.renderOptions;const s=i.font??"Inter";const a=o.transparent??false;const l=Ue(o,b1,r.styleFace);const c=n.visual;const d=[];const u=kK(i.bg);const f=eu(n.nodes.length,{accent:i.accent,bg:i.bg});const h=new Map;const m=l.nodeBorderColor??"var(--_node-stroke)";const p=l.nodeLineWidth;n.nodes.forEach((x,M)=>{const b=It(r.styleFace,"bar",{category:x.label,value:x.value},{includeFallback:false});const C=q$(c,x.label);const P=b?.fillColor;h.set(x.label,{color:C??P??f[M],derived:C===void 0&&P===void 0,stroke:b?.strokeColor??b?.borderColor??m,strokeWidth:b?.lineWidth??p})});const g=[];g.push(Ot(n.width,n.height,i,a,{attrs:{role:"img","aria-roledescription":"sankey diagram"}}));g.push(Dt(s,false,i.shadow,i.embedFontImport));const y=en(i);if(y)g.push(`<defs>${y}</defs>`);d.push(e.documentOpen({id:"prelude",width:n.width,height:n.height,colors:i,transparent:a,font:s,hasMonoFont:false},g.join("\n")));const w=new Map;if(c.linkColor.mode==="gradient"){const x=n.links.map((M,b)=>{const C=`sankey-gradient-${b+1}`;w.set(M.sceneId,C);const P=h.get(M.source);const E=h.get(M.target);return{id:C,units:"userSpaceOnUse",x1:M.sx,y1:M.sy,x2:M.tx,y2:M.ty,stops:[{offset:0,color:VO(P,i.bg)},{offset:1,color:VO(E,i.bg)}]}});if(x.length>0){d.push(e.definitions({id:"sankey-gradient-definitions",gradientResources:x},`<defs>
43
+ ${CC(x)}
44
+ </defs>`))}}for(const x of n.links){const M=String(x.width);const b=CK(c,i.bg,h.get(x.source),h.get(x.target),w.get(x.sceneId));d.push(e.connector({id:x.sceneId,role:"edge",geometry:{kind:"path",d:x.path,points:x.points},lineStyle:"solid",paint:{fill:"none",stroke:b,strokeWidth:M,opacity:String(S1)},stroke:{mixBlendMode:u,encodesValue:true},identity:{id:x.id,from:x.source,to:x.target},endpoints:{from:x.sourceId,to:x.targetId},relationship:{kind:"flow",direction:"forward"},channels:{category:x.source,value:x.value},attributes:{className:"sankey-link",data:{source:x.source,target:x.target,value:String(x.value)}}}))}for(const x of n.nodes){const M=h.get(x.label);const b=M.color;d.push(e.shape({id:x.id,role:"bar",identity:{id:x.label},geometry:{kind:"rect",x:x.x0,y:x.y0,width:KO(x.x1-x.x0),height:KO(x.y1-x.y0)},paint:{fill:b,stroke:M.stroke,strokeWidth:String(M.strokeWidth)},channels:{category:x.label,value:x.value},attributes:{className:"sankey-node",data:{label:jr(x.label),value:String(x.value),layer:String(x.layer)}}}))}const S=l.nodeTextColor??"var(--_text)";for(const x of n.nodes){const M=x.labelLines.join("\n");d.push(e.text({id:`${x.id}:label`,role:"label",text:M,x:x.labelX,y:x.labelY,fontSize:l.nodeLabelFontSize,fontWeight:l.nodeLabelFontWeight,letterSpacing:l.nodeLetterSpacing,block:x.labelBlock,anchor:x.labelAnchor,dominantBaseline:"middle",paint:{fill:S,stroke:"var(--bg)",strokeWidth:String(wK),paintOrder:"stroke fill"},channels:{category:x.label,value:x.value},attributes:{className:"sankey-node-label"}}))}if(n.title){const x=n.title.text;d.push(e.text({id:"title",identity:{id:n.title.id},role:"title",text:x,x:n.title.x,y:n.title.y,fontSize:l.groupHeaderFontSize,fontWeight:l.groupHeaderFontWeight,letterSpacing:l.groupLetterSpacing,block:n.title.block,anchor:"middle",dominantBaseline:"middle",paint:{fill:l.groupTextColor??l.nodeTextColor??"var(--_text)"},attributes:{className:"sankey-title"}}))}d.push(e.documentClose());return{family:"sankey",width:n.width,height:n.height,colors:i,transparent:a,parts:d}}function VO(e,t){return e.derived?GM(e.color,t,S1*100):e.color}function kK(e){const t=e?sm(e):null;return t!==null&&t<.18?"normal":"multiply"}function CK(e,t,n,i,r){const o=(s,a)=>a?GM(s,t,S1*100):s;switch(e.linkColor.mode){case"source":return o(n.color,n.derived);case"target":return o(i.color,i.derived);case"static":return e.linkColor.color;default:if(!r)throw new Error("Sankey gradient mode requires a typed local gradient resource");return`url(#${r})`}}function KO(e){return Math.round(e*100)/100}var JO=gt(MK);var kFe={configDiagnostics:YO,normalizeRequest:e=>({familyConfig:{visual:VM(e.source.frontmatter)}}),layout:e=>ht(UO(kN(U$(e.source),{title:typeof e.source.frontmatter.title==="string"?e.source.frontmatter.title:void 0}),e.renderOptions,e.familyConfig?.visual??VM(e.source.frontmatter),e.styleFace)),projectPositioned:ut(QI),lowerScene:ft(JO)};var PK=Object.fromEntries([...["actorMargin","width","height","diagramMarginX","diagramMarginY","messageMargin","noteMargin","activationWidth"].map(e=>[e,Yt]),["showSequenceNumbers",lt],["wrap",lt]]);var QO=e=>xt("sequence",e,PK);var OFe={configDiagnostics:QO,normalizeRequest:e=>({familyConfig:{sequence:K$(e.source.frontmatter)}}),layout:e=>{const t=e.familyConfig?.sequence??{};const n=uT(e.source,"decoded");const i=Tn(Vr(PT(n.familyLines,{...t,authoredLine:ET(n)}),e.source.accessibility),e.source.frontmatter);return ht(jy(i,e.renderOptions,t,e.styleFace))},projectPositioned:ut(Jg),lowerScene:ft(YN)};var EK=["compositTitleSize","dividerMargin","fontSize","forkHeight","forkWidth","nodeSpacing","noteMargin","padding","radius","rankSpacing"];var RK=["arrowMarkerAbsolute","edgeLengthFactor","fontSizeFactor","labelHeight","miniPadding","sizeUnit","textHeight","titleShift","titleTopMargin"];var vK=["layout","look","minNodeWidth","theme","wrappingWidth"];var TK=["arrowMarkerAbsolute","compositTitleSize","defaultRenderer","dividerMargin","edgeLengthFactor","fontSize","fontSizeFactor","forkHeight","forkWidth","labelHeight","layout","look","miniPadding","minNodeWidth","nodeSpacing","noteMargin","padding","radius","rankSpacing","sizeUnit","textHeight","theme","titleShift","titleTopMargin","wrappingWidth"];var LK=new Set(TK);var AK=new Set(EK);var IK=new Set(RK);var FK=new Set(vK);var NK=new Set(["fontSize","compositTitleSize","forkWidth","forkHeight"]);var im=e=>typeof e==="number"&&Number.isFinite(e)&&e>0?e:void 0;var Nc=e=>typeof e==="number"&&Number.isFinite(e)&&e>=0?e:void 0;function $K(e){return e.filter(t=>Boolean(t)&&typeof t==="object"&&!Array.isArray(t))}function eB(e,t=false){const n=new Map;for(const r of $K(e)){for(const[o,s]of Object.entries(r))n.set(o,s)}const i=[];for(const[r,o]of[...n].sort(([s],[a])=>Bn(s,a))){if(!LK.has(r)){if(t)i.push({code:"INEFFECTIVE_CONFIG",field:`state.${r}`,message:`State config field "state.${r}" is unknown and has no effect; check the spelling or remove it.`});continue}if(IK.has(r)){i.push({code:"INEFFECTIVE_CONFIG",field:`state.${r}`,message:`State config field "state.${r}" is a legacy Dagre/fixed-metric option with no faithful effect in the ELK measured-text renderer.`});continue}if(FK.has(r)){i.push({code:"INEFFECTIVE_CONFIG",field:`state.${r}`,message:`State config field "state.${r}" is accepted for Mermaid compatibility but has no effect on this renderer.`});continue}if(r==="defaultRenderer"){if(o!=="elk")i.push({code:"INEFFECTIVE_CONFIG",field:"state.defaultRenderer",message:`State config field "state.defaultRenderer" requested ${JSON.stringify(o)}; this renderer supports only "elk" and will not silently select a different engine.`});continue}if(AK.has(r)){const s=NK.has(r);const a=s?im(o)!==void 0:Nc(o)!==void 0;if(!a)i.push({code:"INEFFECTIVE_CONFIG",field:`state.${r}`,message:`State config field "state.${r}" must be a ${s?"positive":"non-negative"} finite number; the supplied value was ignored.`})}}return i}function ZO(e){const t=e?.state;return t&&typeof t==="object"&&!Array.isArray(t)?t:{}}function tB(e,t){const n={...ZO(e),...ZO(t.mermaidConfig)};const i=Nc(n.nodeSpacing);const r=Nc(n.rankSpacing);const o=Nc(n.padding);const s=Nc(n.radius);const a=im(n.fontSize);const l=im(n.compositTitleSize);const c={...zi,...o===void 0?{}:{nodePaddingX:o,nodePaddingY:o},...s===void 0?{}:{nodeCornerRadius:s},...a===void 0?{}:{nodeLabelFontSize:a,edgeLabelFontSize:a},...l===void 0?{}:{groupHeaderFontSize:l}};const d=t.nodeSpacing??i;const u=t.layerSpacing??r;return{...t,...d===void 0?{}:{nodeSpacing:d},...u===void 0?{}:{layerSpacing:u},stateVisual:{forkWidth:im(n.forkWidth)??70,forkHeight:im(n.forkHeight)??10,noteMargin:Nc(n.noteMargin)??18,dividerMargin:Nc(n.dividerMargin)??0,styleDefaults:c}}}var nB=({root:e,config:t})=>{const n=Zr(e,t.section);return n?eB([n],true):yS("state",e,t)};var nNe={configDiagnostics:nB,statementEnds:N2,normalizeRequest:e=>{const t=tB(e.source.frontmatter,e.renderOptions);const{stateVisual:n,...i}=t;return{renderOptions:i,...n?{appearance:{family:{visual:n}}}:{}}},layout:e=>{const t=e.familyAppearance?.visual;const n=Nr(e.source.frontmatter);const i=Hf(e.source.familyText);Km(i);return ht(xx(i,{...e.renderOptions,...e.styleFace?{styleFace:e.styleFace}:{},...t?{stateVisual:t}:{},...n?{diagramTitle:n}:{}}))},projectPositioned:ut(by),lowerScene:ft(ox)};var _K={disableMulticolor:lt,sectionFills:wf,sectionColours:wf};var iB=e=>xt("timeline",e,_K);var at={paddingX:32,paddingY:28,titleFontSize:18,titleFontWeight:600,titleGap:24,titleWrapWidth:420,sectionHeaderHeight:24,sectionFontSize:12,sectionFontWeight:600,sectionHeaderPadX:12,sectionHeaderGap:14,sectionWrapWidth:168,sectionPadX:18,sectionPadBottom:18,sectionGap:28,columnGap:24,pillFontSize:12,pillFontWeight:600,pillWrapWidth:116,pillPadX:12,pillPadY:8,pillMinWidth:72,railToPillGap:22,railToEventsGap:28,markerRadius:8,eventFontSize:12,eventFontWeight:400,eventWrapWidth:148,eventPadX:14,eventPadY:10,eventMinWidth:128,eventGap:10};var rB=36;var w1={nodeLabelFontSize:at.eventFontSize,edgeLabelFontSize:at.pillFontSize,groupHeaderFontSize:at.sectionFontSize,nodeLabelFontWeight:at.eventFontWeight,edgeLabelFontWeight:at.pillFontWeight,groupHeaderFontWeight:at.sectionFontWeight,nodePaddingX:at.eventPadX,nodePaddingY:at.eventPadY,nodeCornerRadius:0,nodeLineWidth:et.outerBox,edgeLineWidth:1.5,groupCornerRadius:0,groupPaddingX:at.sectionPadX,groupPaddingY:at.sectionPadBottom,groupLabelPaddingX:at.sectionHeaderPadX,groupLineWidth:et.outerBox};var DK={pill:at.pillWrapWidth,event:at.eventWrapWidth,pillMinWidth:at.pillMinWidth,eventMinWidth:at.eventMinWidth};function sB(e,t={},n){const i=Ue(t,w1,n);const r=e.direction==="TD";const o=(_,H)=>r?H:_;const s=(_,H)=>r?_:H;const a=e.sections.some(_=>!!_.label);const l=e.sections.length>1||a;let c=a?Math.max(at.sectionHeaderHeight,i.groupHeaderFontSize+i.groupPaddingY):0;const d=l?i.groupPaddingX:0;const u=e.title?Be(e.title,{display:"literal",transform:i.groupTextTransform,fontSize:at.titleFontSize,fontWeight:at.titleFontWeight,letterSpacing:i.groupLetterSpacing,maxWidth:at.titleWrapWidth}):void 0;const f=u?.text;const h=u;let m=oB(e,i,DK,r);const p=t.timeline?.maxWidth;if(!r&&typeof p==="number"&&Number.isFinite(p)&&p>0){const _=OK(m,d,l);const H=m.reduce((D,j)=>D+j.periods.length,0);if(_>p&&H>0){const D=m.reduce((O,N)=>O+N.periods.reduce((G,Y)=>G+Y.mainExtent,0),0);const j=Math.max(rB+i.nodePaddingX*2,(p-(_-D))/H);const W=Math.max(rB,j-i.nodePaddingX*2);m=oB(e,i,{pill:Math.min(at.pillWrapWidth,W),event:Math.min(at.eventWrapWidth,W),pillMinWidth:Math.min(at.pillMinWidth,j),eventMinWidth:Math.min(at.eventMinWidth,j)},r)}}c=Math.max(c,...m.map(_=>_.block?_.block.height+i.groupPaddingY:0));const g=Math.max(0,...m.flatMap(_=>_.periods.map(H=>s(H.pillWidth,H.pillHeight))));let y=at.paddingY;if(h){y+=h.height;y+=at.titleGap}const w=c+(a?at.sectionHeaderGap:0);const S=r?at.paddingX:y;const x=S+(r?l?d:0:w);const M=x+g+at.railToPillGap;const b=M+at.railToEventsGap;const C=r?w:0;let P=r?y:at.paddingX;const E=[];let k=M+at.markerRadius;for(let _=0;_<e.sections.length;_++){const H=e.sections[_];const D=m[_];const j=P;const W=C+D.innerMain+d*2;const O=P+C+d+(D.innerMain-D.runMain)/2;let N=O;const G=[];let Y=M+at.markerRadius;for(let q=0;q<H.periods.length;q++){const V=H.periods[q];const ne=D.periods[q];const X=N+ne.mainExtent/2;let U=b;const K=V.events.map((te,ee)=>{const ae=ne.events[ee];const ie=X-o(ae.width,ae.height)/2;const oe={id:te.id,sectionId:H.id,periodId:V.id,periodLabel:ne.label,text:ae.text,block:ae.block,x:r?U:ie,y:r?ie:U,width:ae.width,height:ae.height};U+=s(ae.width,ae.height)+at.eventGap;return oe});const Z=M+at.markerRadius;const Q=K.length>0?b-10:M+16;const se=X-o(ne.pillWidth,ne.pillHeight)/2;G.push({id:V.id,sectionId:H.id,label:ne.label,block:ne.block,centerX:r?x+ne.pillWidth/2:X,markerX:r?M:X,markerY:r?X:M,pillX:r?x:X-ne.pillWidth/2,pillY:r?se:x,pillWidth:ne.pillWidth,pillHeight:ne.pillHeight,stem:r?{x1:Z,y1:X,x2:Q,y2:X}:{x1:X,y1:Z,x2:X,y2:Q},events:K});if(K.length>0){const te=K[K.length-1];Y=Math.max(Y,r?te.x+te.width:te.y+te.height)}N+=ne.mainExtent+at.columnGap}Y+=i.groupPaddingY;k=Math.max(k,Y);E.push({id:H.id,label:D.label,block:D.block,x:r?S:j,y:r?j:S,width:r?Y-S:W,height:r?W:Y-S,framed:l,headerHeight:c,periods:G});P+=W;if(_<e.sections.length-1){P+=l?at.sectionGap:at.columnGap}}const v=P+(r?at.paddingY:at.paddingX);const T=k+(r?at.paddingX:at.paddingY);const A=Math.max(r?T:v,h?h.width+2*at.paddingX:0);const R=r?v:T;const I=E.flatMap(_=>_.periods);const L=_=>r?_.markerY:_.centerX;const $=I.length>0?L(I[0]):r?y:at.paddingX;const B=I.length>0?L(I[I.length-1]):v-(r?at.paddingY:at.paddingX);const F=$===B?$-42:$;const z=$===B?B+42:B;for(const _ of E)for(const H of _.periods)for(const D of H.events){D.labelX=D.x+i.nodePaddingX}return{width:A,height:R,title:f?{text:f,block:u,x:A/2,y:at.paddingY+h.height/2}:void 0,accessibilityTitle:e.accessibilityTitle,accessibilityDescription:e.accessibilityDescription,rail:r?{x1:M,y1:F,x2:M,y2:z}:{x1:F,y1:M,x2:z,y2:M},sections:E}}function oB(e,t,n,i){const r=(o,s)=>i?s:o;return e.sections.map(o=>{const s=o.label?Be(o.label,{display:"literal",transform:t.groupTextTransform,fontSize:t.groupHeaderFontSize,fontWeight:t.groupHeaderFontWeight,letterSpacing:t.groupLetterSpacing,fontFamily:t.groupFont,maxWidth:at.sectionWrapWidth}):void 0;const a=s?.text;const l=o.periods.map(f=>{const h=Be(f.label,{display:"literal",transform:t.edgeTextTransform,fontSize:t.edgeLabelFontSize,fontWeight:t.edgeLabelFontWeight,letterSpacing:t.edgeLetterSpacing,maxWidth:n.pill});const m=h.text;const p=Math.max(n.pillMinWidth,h.width+t.nodePaddingX*2);const g=h.height+t.nodePaddingY*2;const y=f.events.map(S=>{const x=Be(S.text,{display:"literal",transform:t.nodeTextTransform,fontSize:t.nodeLabelFontSize,fontWeight:t.nodeLabelFontWeight,letterSpacing:t.nodeLetterSpacing,maxWidth:n.event});const M=x.text;return{text:M,block:x,width:Math.max(n.eventMinWidth,x.width+t.nodePaddingX*2),height:x.height+t.nodePaddingY*2}});const w=Math.max(r(p,g),...y.map(S=>r(S.width,S.height)));return{label:m,block:h,pillWidth:p,pillHeight:g,mainExtent:w,events:y}});const c=l.reduce((f,h,m)=>{const p=m===0?0:at.columnGap;return f+p+h.mainExtent},0);const d=a?s.width+t.groupLabelPaddingX*2:0;const u=i?c:Math.max(c,d);return{label:a,block:s,headerWidth:d,runMain:c,innerMain:u,periods:l}})}function OK(e,t,n){let i=at.paddingX;for(let r=0;r<e.length;r++){i+=e[r].innerMain+t*2;if(r<e.length-1)i+=n?at.sectionGap:at.columnGap}return i+at.paddingX}var Bx={titleFontSize:18,titleFontWeight:600,sectionFontSize:12,sectionFontWeight:600,pillFontSize:12,pillFontWeight:600,eventFontSize:12,eventFontWeight:400,markerOuterRadius:8,markerInnerRadius:4.5};function BK(e,t){const{positioned:n,colors:i,resolved:r}=t;const o=r.renderOptions;const s=i.font??"Inter";const a=o.transparent??false;const l=r.familyAppearance;if(!l)throw new Error("Timeline rendering requires request-boundary family appearance resolution");const c=l.timelineConfig;const d=[];const u=Ue(o,w1,r.styleFace);const f=l.familyPalettes;const h=WK(u,i,f);const m=zK(u,h);const p=n.accessibilityTitle??n.title?.text.replace(/\n+/g," ");const g=n.accessibilityDescription;const y=!c.disableMulticolor;const w=y&&n.sections.some(k=>Boolean(k.label));const S=`tl-${pi(n.width,n.height,n.sections.map(k=>k.periods.length).join(","))}`;const x=`${S}-title`;const M=`${S}-desc`;const b=ki(p,g,x,M);const C=[Ot(n.width,n.height,i,a,b),Dt(s,false,i.shadow,i.embedFontImport)];const P=en(i);if(P)C.push(`<defs>${P}</defs>`);d.push(e.documentOpen({id:"prelude",width:n.width,height:n.height,colors:i,transparent:a,font:s,hasMonoFont:false},C.join("\n")));if(p){d.push(e.documentContent({id:"a11y-title",role:"chrome",nonPaint:"accessibility"},`<title id="${x}">${At(p)}</title>`))}if(g){d.push(e.documentContent({id:"a11y-desc",role:"chrome",nonPaint:"accessibility"},`<desc id="${M}">${At(g)}</desc>`))}for(let k=0;k<n.sections.length;k++){const v=n.sections[k];const T=w?k:0;if(v.framed){d.push(GK(e,v,T,f,u,m))}}d.push(e.shape({id:"rail",role:"rail",geometry:{kind:"line",x1:n.rail.x1,y1:n.rail.y1,x2:n.rail.x2,y2:n.rail.y2},paint:m.rail,attributes:{className:"timeline-rail"}}));let E=0;for(let k=0;k<n.sections.length;k++){const v=n.sections[k];const T=w?k:void 0;for(const A of v.periods){const R=T??(y?E++:0);d.push(HK(e,A,v.label,R,f,u,m))}}if(n.title){d.push(e.text({id:"title",role:"title",text:n.title.text,block:n.title.block,x:n.title.x,y:n.title.y,fontSize:Bx.titleFontSize,fontWeight:Bx.titleFontWeight,display:"literal",anchor:"middle",paint:m.title,attributes:Wx("timeline-title")}))}d.push(e.documentClose());return{family:"timeline",width:n.width,height:n.height,colors:i,transparent:a,parts:d}}function WK(e,t,n){const i=e.nodeTextColor??"var(--tl-label, var(--_text-muted))";if(e.nodeTextColor!==void 0||n.some(o=>o.label!=="var(--_text)"))return i;const r=xi("var(--_text)",e.nodeFillColor??"var(--_node-fill)",t);return r==="var(--_text)"?i:r}function zK(e,t){return{title:{fill:e.groupTextColor??e.nodeTextColor??"var(--_text)"},rail:{stroke:e.edgeStrokeColor??"var(--_line)",strokeWidth:String(e.lineWidth),strokeLinecap:"round"},sectionBg:{fill:e.groupFillColor??"var(--tl-section-bg, color-mix(in srgb, var(--_node-fill) 88%, var(--bg)))",stroke:e.groupBorderColor??"var(--tl-line, var(--_node-stroke))",strokeWidth:String(e.groupLineWidth)},sectionBand:{fill:e.groupHeaderFillColor??"var(--tl-section-band, color-mix(in srgb, var(--_arrow) 8%, var(--bg)))",stroke:e.groupBorderColor??"var(--tl-line, var(--_node-stroke))",strokeWidth:String(e.groupLineWidth)},sectionLabel:{fill:e.groupTextColor??"var(--tl-label, var(--_text-sec))"},stem:{stroke:e.edgeStrokeColor??"var(--tl-line, color-mix(in srgb, var(--_arrow) 32%, var(--_line)))",strokeWidth:String(Math.max(1,e.lineWidth*.75)),strokeDasharray:"3 4"},markerRing:{fill:"var(--bg)",stroke:e.edgeStrokeColor??"var(--tl-line, var(--_arrow))",strokeWidth:"1.5"},markerCore:{fill:e.edgeStrokeColor??"var(--tl-accent, var(--_arrow))"},pill:{fill:e.nodeFillColor??"var(--tl-pill-fill, color-mix(in srgb, var(--_arrow) 7%, var(--bg)))",stroke:e.nodeBorderColor??"var(--tl-pill-stroke, color-mix(in srgb, var(--_arrow) 20%, var(--bg)))",strokeWidth:String(e.nodeLineWidth)},periodText:{fill:e.nodeTextColor??"var(--tl-label, var(--_text))"},eventCard:{fill:e.nodeFillColor??"var(--tl-event-fill, var(--_node-fill))",stroke:e.nodeBorderColor??"var(--tl-line, var(--_node-stroke))",strokeWidth:String(e.nodeLineWidth)},eventText:{fill:t}}}function Wx(e){return{className:e,data:{"literal-text":"true"}}}function GK(e,t,n,i,r,o){const s=t.label??t.id;const a=t.label?` data-label="${hn(t.label)}"`:"";const l=aB(n,i);const c=[];c.push({indent:2,node:e.shape({id:`section-bg:${s}`,role:"section",geometry:{kind:"rect",x:t.x,y:t.y,width:t.width,height:t.height,rx:r.groupCornerRadius,ry:r.groupCornerRadius},paint:o.sectionBg,attributes:{className:"timeline-section-bg"}})});if(t.headerHeight>0){const d=Tr(t.x,t.y,t.width,t.headerHeight,r.groupCornerRadius);c.push({indent:2,node:e.shape({id:`section-band:${s}`,role:"group-header",geometry:{kind:"path",d},paint:o.sectionBand,attributes:{className:"timeline-section-band"}})});if(t.label){c.push({indent:2,node:e.text({id:`section-label:${s}`,role:"group-header",text:t.label,block:t.block,x:t.x+r.groupLabelPaddingX,y:t.y+t.headerHeight/2,fontSize:r.groupHeaderFontSize,fontWeight:r.groupHeaderFontWeight,letterSpacing:r.groupLetterSpacing,display:"literal",anchor:"start",paint:o.sectionLabel,attributes:Wx("timeline-section-label")})})}}return e.group({id:`section:${s}`,role:"section",open:`<g class="timeline-section" data-id="${Ye(t.id)}"${a}${l}>`,close:"</g>",children:c,channels:{category:s}})}function HK(e,t,n,i,r,o,s){const a=n?` data-section="${Ye(n)}"`:"";const l=aB(i,r);const c=[];c.push({indent:2,node:e.shape({id:`period-stem:${t.id}`,role:"period",geometry:{kind:"line",x1:t.stem.x1,y1:t.stem.y1,x2:t.stem.x2,y2:t.stem.y2},paint:s.stem,attributes:{className:"timeline-stem"}})});c.push({indent:2,node:e.shape({id:`period-pill:${t.id}`,role:"period",geometry:{kind:"rect",x:t.pillX,y:t.pillY,width:t.pillWidth,height:t.pillHeight,rx:o.cornerRadius??0,ry:o.cornerRadius??0},paint:s.pill,attributes:{className:"timeline-period-pill"}})});c.push({indent:2,node:e.text({id:`period-label:${t.id}`,role:"label",text:t.label,block:t.block,x:t.centerX,y:t.pillY+t.pillHeight/2,fontSize:o.edgeLabelFontSize,fontWeight:o.edgeLabelFontWeight,letterSpacing:o.edgeLetterSpacing,display:"literal",anchor:"middle",paint:s.periodText,attributes:Wx("timeline-period-text")})});c.push({indent:2,node:e.shape({id:`period-marker-ring:${t.id}`,role:"period",geometry:{kind:"circle",cx:t.markerX,cy:t.markerY,r:Bx.markerOuterRadius},paint:s.markerRing,attributes:{className:"timeline-marker-ring"}})});c.push({indent:2,node:e.shape({id:`period-marker-core:${t.id}`,role:"period",geometry:{kind:"circle",cx:t.markerX,cy:t.markerY,r:Bx.markerInnerRadius},paint:s.markerCore,attributes:{className:"timeline-marker-core"}})});for(let d=0;d<t.events.length;d++){c.push({indent:0,node:jK(e,t.events[d],n,i,r,o,s)})}return e.group({id:`period:${t.id}`,role:"period",open:`<g class="timeline-period" data-id="${Ye(t.id)}" data-label="${hn(t.label)}"${a}${l}>`,close:"</g>",children:c})}function jK(e,t,n,i,r,o,s){const a=n?` data-section="${Ye(n)}"`:"";const l=` data-family="${i%r.length}"`;const c=`event:${t.id}`;const d=e.shape({id:c,role:"event",geometry:{kind:"rect",x:t.x,y:t.y,width:t.width,height:t.height,rx:o.cornerRadius??0,ry:o.cornerRadius??0},paint:s.eventCard,attributes:{className:"timeline-event-card"}});const u=e.text({id:`${c}:label`,role:"label",text:t.text,block:t.block,x:t.labelX??t.x+o.nodePaddingX,y:t.y+t.height/2,fontSize:o.nodeLabelFontSize,fontWeight:o.nodeLabelFontWeight,letterSpacing:o.nodeLetterSpacing,display:"literal",anchor:"start",paint:s.eventText,attributes:Wx("timeline-event-text")});return e.group({id:`${c}:group`,role:"event",open:`<g class="timeline-event" data-id="${Ye(t.id)}" data-period="${Ye(t.periodLabel)}"${a}${l}>`,close:"</g>",children:[{indent:2,node:d},{indent:2,node:u}]})}function aB(e,t){const n=e%t.length;const i=t[n];const r=[`--tl-accent:${i.accent}`,`--tl-fill:${i.fill}`,`--tl-label:${i.label}`,`--tl-line:${i.line}`,`--tl-section-bg:${pu(i.fill,"var(--bg)",6)}`,`--tl-section-band:${pu(i.fill,"var(--bg)",12)}`,`--tl-pill-fill:${pu(i.fill,"var(--bg)",11)}`,`--tl-pill-stroke:${pu(i.fill,i.line,36)}`,`--tl-event-fill:${pu(i.fill,"var(--_node-fill)",16)}`].join(";");return` data-family="${n}" style="${Ye(r)}"`}function lB(e={}){const t=e.mermaidConfig?.timeline??{};return{timelineConfig:t,familyPalettes:YK(t,e.mermaidConfig?.themeVariables)}}function YK(e,t){const n=e.sectionFills??[];const i=e.sectionColours??[];return Array.from({length:12},(r,o)=>{const s=n[o%Math.max(n.length,1)]??M1(t,"cScale",o);const a=s??"var(--_node-fill)";const l=i[o%Math.max(i.length,1)]??M1(t,"cScaleLabel",o)??"var(--_text)";const c=M1(t,"cScaleInv",o)??(s?pu(a,"var(--_line)",48):"var(--_line)");const d=s??"var(--_arrow)";return{accent:d,fill:a,label:l,line:c}})}function pu(e,t,n){return`color-mix(in srgb, ${e} ${n}%, ${t})`}function M1(e,t,n){if(!e)return void 0;const i=e[`${t}${n}`];return typeof i==="string"&&i.length>0?i:void 0}var cB=gt(BK);var TNe={configDiagnostics:iB,normalizeRequest:e=>({appearance:{family:{...lB(e.renderOptions)}}}),layout:e=>ht(sB(Tn(CN(e.source.familyLines,e.source.accessibility),e.source.frontmatter),e.renderOptions,e.styleFace)),projectPositioned:ut(ZI),lowerScene:ft(cB)};var qK={width:Jt,height:Jt,useMaxWidth:lt,useWidth:Jt,titleFontSize:Jt,titlePadding:Yt,chartOrientation:qs("vertical","horizontal"),plotReservedSpacePercent:wn(0,100,false),showDataLabel:lt,showDataLabelOutsideBar:lt,showTitle:lt,showLegend:lt,legendFontSize:Jt,legendPadding:Yt,xAxis:an("an axis-config object",e=>Boolean(e)&&typeof e==="object"&&!Array.isArray(e)),yAxis:an("an axis-config object",e=>Boolean(e)&&typeof e==="object"&&!Array.isArray(e))};var XK={showLabel:lt,labelFontSize:Jt,labelPadding:Yt,labelRotation:Yp,showTitle:lt,titleFontSize:Jt,titlePadding:Yt,showTick:lt,tickLength:Yt,tickWidth:Jt,showAxisLine:lt,axisLineWidth:Jt};var dB=e=>{const t=xt("xychart",e,qK);const n=Zr(e.root,e.config.section);if(!n)return t;const i=(r,o)=>{t.push({code:"INEFFECTIVE_CONFIG",field:r,message:`${r} must be ${o}; the invalid value has no effect.`})};for(const r of["xAxis","yAxis"]){const o=n[r];if(!o||typeof o!=="object"||Array.isArray(o))continue;const s=o;for(const a of Object.keys(s).sort()){const l=XK[a];if(!l)i(`xyChart.${r}.${a}`,"a documented axis-config field");else if(!l.valid(s[a]))i(`xyChart.${r}.${a}`,l.expected);else if(a==="labelRotation")t.push({code:"INEFFECTIVE_CONFIG",field:`xyChart.${r}.${a}`,message:`xyChart ${r}.${a} is accepted for Mermaid compatibility but has no effect on this renderer.`})}}return t};var UK=3;var zx={titleWeight:500,axisTitleWeight:400,labelWeight:400,dotRadius:Ey,lineWidth:3};function VK(e,t){const{positioned:n,colors:i,resolved:r}=t;const o=r.renderOptions;const s=i.font??"Inter";const a=o.transparent??false;const l=o.interactive??false;const c=[];const d=Ue(o,lM,r.styleFace);const u=KK(n,d);const f=Boolean(n.theme.plotColorPalette?.length);const h=Math.max(0,...n.bars.map(R=>R.colorIndex),...n.lines.map(R=>R.colorIndex));const m=e7(n);const p=Ot(n.width,n.height,i,a,m.openTag).replace("<svg ",`<svg data-xychart-colors="${h}" `);const{style:g,defs:y}=QK(n,l,i.accent,i.bg);c.push(e.documentOpen({id:"prelude",width:n.width,height:n.height,colors:i,transparent:a,font:s,hasMonoFont:false,extraCss:g},p+"\n"+Dt(s,false,i.shadow,i.embedFontImport)+"\n"+g));const w=en(i);if(w)c.push(e.definitions({id:"shadow-defs"},`<defs>${w}</defs>`));if(y)c.push(e.definitions({id:"defs"},y));if(m.title)c.push(e.documentContent({id:"acc-title",role:"chrome",nonPaint:"accessibility"},m.title));if(m.description)c.push(e.documentContent({id:"acc-desc",role:"chrome",nonPaint:"accessibility"},m.description));const S={stroke:u.gridStroke,strokeWidth:"1",...d.edgeStrokeColor?{opacity:"0.25"}:{}};n.gridLines.forEach((R,I)=>{c.push(e.shape({id:`grid:y:${I}`,role:"grid",geometry:{kind:"line",x1:Pt(R.x1),y1:Pt(R.y1),x2:Pt(R.x2),y2:Pt(R.y2)},paint:S,attributes:{className:"xychart-grid"}}))});uB(e,c,n.xAxis,"x",u.xAxisLineColor,u.xAxisTickColor);uB(e,c,n.yAxis,"y",u.yAxisLineColor,u.yAxisTickColor);const x=Math.max(0,...n.bars.map(R=>Math.abs(R.value)),...n.lines.flatMap(R=>R.points.map(I=>Math.abs(I.value))));const M=R=>x>0?R/x:void 0;const b=[];const C=new Map;const P=hB(n,i.accent,i.bg);const E=new Map;const k=new Map;for(const R of n.bars){const I=C.get(R.seriesIndex)??0;C.set(R.seriesIndex,I+1);const L=`bar:${R.seriesIndex}:${R.label??I}`;const $={category:`bar-${R.seriesIndex}`,value:M(R.value)};const B=It(r.styleFace,"bar",$,{includeFallback:false});const F=`var(--xychart-color-${R.colorIndex})`;const z=f?F:B?.fillColor??F;k.set($.category,z);E.set(R,f?P.concrete(R.colorIndex):B?.fillColor??P.concrete(R.colorIndex));const _=B?.strokeColor??B?.borderColor;const H=B?.lineWidth;c.push(e.shape({id:L,role:"bar",geometry:{kind:"rect",x:Pt(R.x),y:Pt(R.y),width:Pt(R.width),height:Pt(R.height)},paint:{fill:z,stroke:_??"none",...H!==void 0?{strokeWidth:String(H)}:{}},channels:$,attributes:{className:`xychart-bar xychart-color-${R.colorIndex}`,data:{value:String(R.value),...R.label?{label:R.label}:{}}}}));if(l){const D=rc(R.value);const j=R.label?`${R.label}: ${D}`:D;const W={id:L,role:"bar"};b.push(e.group({id:`tooltip:${L}`,role:"chrome",owner:W,open:'<g class="xychart-bar-group">',close:"</g>",join:"",children:[{indent:0,node:e.shape({id:`${L}:hit`,role:"chrome",owner:W,geometry:{kind:"rect",x:Pt(R.x),y:Pt(R.y),width:Pt(R.width),height:Pt(R.height)},paint:{fill:"transparent"}})},{indent:0,node:e.documentContent({id:`${L}:title`,role:"chrome",nonPaint:"interaction-metadata"},`<title>${At(j)}</title>`)},{indent:0,node:Ac(e,"xychart",R.tooltip,`${L}:tooltip`,W)}]}))}}for(const R of n.lines){const I={category:`line-${R.seriesIndex}`};const L=It(r.styleFace,"series",I,{includeFallback:false});const $=`var(--xychart-color-${R.colorIndex})`;const B=f?$:L?.strokeColor??L?.borderColor??$;k.set(I.category,B);if(R.points.length<2)continue;const F=ZK(R.points);const z=L?.lineWidth??d.lineWidth;c.push(e.connector({id:`series:line-${R.seriesIndex}`,role:"series",geometry:{kind:"path",d:F,points:R.points},lineStyle:"solid",paint:{stroke:B,strokeWidth:String(z),strokeLinecap:"round",strokeLinejoin:"round"},channels:I,attributes:{className:`xychart-line xychart-color-${R.colorIndex}`}}))}const v=(R,I,L)=>{const $=`line-${R}`;const B=It(r.styleFace,"point",{category:$,value:M(L)},{includeFallback:false});const F=`var(--xychart-color-${I})`;return{fill:f?F:B?.fillColor??k.get($)??F,stroke:B?.strokeColor??B?.borderColor??"var(--bg)",strokeWidth:String(B?.lineWidth??2)}};for(const R of n.lines){R.points.forEach((I,L)=>{if(I.textLabel===void 0)return;const $=I.textPosition;const B=$?.placement??(n.horizontal?"right":"above");const F=$?.x??I.x+(n.horizontal?8:0);const z=$?.y??I.y+(n.horizontal?4:-8);const _=$?.anchor??(n.horizontal?"start":"middle");c.push(e.shape({id:`point-label-dot:${R.seriesIndex}:${L}`,role:"point",geometry:{kind:"circle",cx:Pt(I.x),cy:Pt(I.y),r:zx.dotRadius},paint:v(R.seriesIndex,R.colorIndex,I.value),channels:{category:`line-${R.seriesIndex}`,value:M(I.value)},attributes:{className:`xychart-dot xychart-color-${R.colorIndex}`,data:{value:String(I.value)}}}));c.push(e.text({id:`point-label:${R.seriesIndex}:${L}`,role:"label",text:I.textBlock?.text??I.textLabel,block:I.textBlock,x:Pt(F),y:Pt(z),fontSize:12,fontWeight:d.nodeLabelFontWeight,letterSpacing:d.nodeLetterSpacing,display:"literal",anchor:_,baselineShift:$?.35:0,paint:{fill:k.get(`line-${R.seriesIndex}`)??`var(--xychart-color-${R.colorIndex})`},channels:{category:`line-${R.seriesIndex}`,value:M(I.value)},attributes:{className:`xychart-point-label xychart-color-${R.colorIndex}`,data:{"label-position":B}}}))})}const T=[];if(l){for(const R of n.lines){R.points.forEach((I,L)=>{const $=`point:line-${R.seriesIndex}:${I.label??L}`;const B=rc(I.value);const F=I.label?`${I.label}: ${B}`:B;T.push(e.group({id:`point-group:line-${R.seriesIndex}:${I.label??L}`,role:"chrome",open:`<g class="xychart-dot-group">`,close:`</g>`,join:"",children:[{node:e.shape({id:`hit:${$}`,role:"chrome",owner:{id:$,role:"point"},geometry:{kind:"circle",cx:Pt(I.x),cy:Pt(I.y),r:zx.dotRadius*3},paint:{fill:"transparent"},attributes:{className:"xychart-hit"}}),indent:0},{node:e.shape({id:$,role:"point",geometry:{kind:"circle",cx:Pt(I.x),cy:Pt(I.y),r:zx.dotRadius},paint:v(R.seriesIndex,R.colorIndex,I.value),channels:{category:`line-${R.seriesIndex}`,value:M(I.value)},attributes:{className:`xychart-dot xychart-color-${R.colorIndex}`,data:{value:String(I.value),...I.label?{label:I.label}:{}}}}),indent:0},{node:e.documentContent({id:`title:${$}`,role:"chrome",nonPaint:"interaction-metadata"},`<title>${At(F)}</title>`),indent:0},{node:Ac(e,"xychart",I.tooltip,`tooltip:${$}`,{id:$,role:"point"}),indent:0}]}))})}}const A=new Map;for(const R of n.dataLabels){const I=R.block?.text??gi(R.text,d.nodeTextTransform);const L=A.get(R.bar.seriesIndex)??0;A.set(R.bar.seriesIndex,L+1);const $=n.theme.dataLabelColor===void 0&&R.placement==="inside"?JK(E.get(R.bar)):void 0;const B=n.theme.dataLabelColor??$??u.labelColor;const F=R.placement==="inside"?E.get(R.bar)??"var(--bg)":"var(--bg)";c.push(e.text({id:`label:bar:${R.bar.seriesIndex}:${R.bar.label??L}`,role:"label",text:I,block:R.block,x:Pt(R.x),y:Pt(R.y),fontSize:R.fontSize,fontWeight:d.nodeLabelFontWeight,letterSpacing:d.nodeLetterSpacing,display:"literal",anchor:R.anchor,...R.dominantBaseline?{dominantBaseline:R.dominantBaseline}:{},baselineShift:0,paint:{fill:B,stroke:F,strokeWidth:String(UK),strokeLinejoin:"round",paintOrder:"stroke"},...$?{pageFill:u.labelColor}:{},channels:{category:`bar-${R.bar.seriesIndex}`,value:M(R.bar.value)},attributes:{className:"xychart-data-label",data:{"literal-text":"true"}}}))}fB(e,c,n.xAxis.ticks,n.xAxis.config.labelFontSize,"x",d,u.xAxisLabelColor);fB(e,c,n.yAxis.ticks,n.yAxis.config.labelFontSize,"y",d,u.yAxisLabelColor);if(n.xAxis.title){const R=n.xAxis.title;const I=R.block?.text??gi(R.text,d.edgeTextTransform);const L=R.rotate?{kind:"rotate",angle:R.rotate,cx:R.x,cy:R.y}:void 0;c.push(e.text({id:"axis:x:title",role:"axis",text:I,block:R.block,x:R.x,y:R.y,fontSize:n.xAxis.config.titleFontSize,fontWeight:d.edgeLabelFontWeight,letterSpacing:d.edgeLetterSpacing,display:"literal",anchor:"middle",paint:{fill:u.xAxisTitleColor},transform:L,attributes:{className:"xychart-axis-title xychart-x-axis-title"}}))}if(n.yAxis.title){const R=n.yAxis.title;const I=R.block?.text??gi(R.text,d.edgeTextTransform);const L=R.rotate?{kind:"rotate",angle:R.rotate,cx:R.x,cy:R.y}:void 0;c.push(e.text({id:"axis:y:title",role:"axis",text:I,block:R.block,x:R.x,y:R.y,fontSize:n.yAxis.config.titleFontSize,fontWeight:d.edgeLabelFontWeight,letterSpacing:d.edgeLetterSpacing,display:"literal",anchor:"middle",paint:{fill:u.yAxisTitleColor},transform:L,attributes:{className:"xychart-axis-title xychart-y-axis-title"}}))}if(n.title){const R=n.title.text;c.push(e.text({id:"title",role:"title",text:R,block:n.title.block,x:n.title.x,y:n.title.y,fontSize:n.config.titleFontSize,fontWeight:d.groupHeaderFontWeight,letterSpacing:d.groupLetterSpacing,display:"literal",anchor:"middle",paint:{fill:u.titleColor},attributes:{className:"xychart-title"}}))}if(n.legend.length>0){const R=[];for(const I of n.legend){const L=I.y+Math.max(po,I.block?.height??0)/2;if(I.type==="bar"){R.push({node:e.shape({id:`legend:swatch:${I.colorIndex}`,role:"legend",geometry:{kind:"rect",x:Pt(I.x),y:Pt(I.y),width:po,height:po,rx:2,ry:2},paint:{fill:k.get(`bar-${I.seriesIndex}`)??`var(--xychart-color-${I.colorIndex})`},channels:{category:`bar-${I.seriesIndex}`},attributes:{className:"xychart-legend-swatch"}}),indent:2})}else{R.push({node:e.shape({id:`legend:swatch:${I.colorIndex}`,role:"legend",geometry:{kind:"line",x1:Pt(I.x),y1:Pt(L),x2:Pt(I.x+po),y2:Pt(L)},paint:{stroke:k.get(`line-${I.seriesIndex}`)??`var(--xychart-color-${I.colorIndex})`,strokeWidth:String(zx.lineWidth),strokeLinecap:"round"},channels:{category:`line-${I.seriesIndex}`},attributes:{className:"xychart-legend-swatch"}}),indent:2});R.push({node:e.shape({id:`legend:dot:${I.colorIndex}`,role:"legend",geometry:{kind:"circle",cx:Pt(I.x+po/2),cy:Pt(L),r:2.5},paint:{fill:k.get(`line-${I.seriesIndex}`)??`var(--xychart-color-${I.colorIndex})`,stroke:"var(--bg)",strokeWidth:"1"},channels:{category:`line-${I.seriesIndex}`},attributes:{className:"xychart-legend-dot"}}),indent:2})}const $=I.block?.text??gi(I.label,d.nodeTextTransform);const B=I.x+po+wh;R.push({node:e.text({id:`legend:label:${I.colorIndex}`,role:"legend",text:$,block:I.block,x:Pt(B),y:Pt(L),fontSize:n.config.legendFontSize,fontWeight:d.nodeLabelFontWeight,letterSpacing:d.nodeLetterSpacing,display:"literal",anchor:"start",dominantBaseline:"middle",baselineShift:0,paint:{fill:u.legendTextColor},attributes:{className:"xychart-legend-label"}}),indent:2})}c.push(e.group({id:"legend",role:"legend",open:'<g class="xychart-legend">',close:"</g>",children:R}))}for(const R of b)c.push(R);for(const R of T)c.push(R);c.push(e.documentClose());return{family:"xychart",width:n.width,height:n.height,colors:i,transparent:a,parts:c}}function uB(e,t,n,i,r,o){if(n.config.showAxisLine){t.push(e.shape({id:`axis:${i}:line`,role:"axis",geometry:{kind:"line",x1:Pt(n.line.x1),y1:Pt(n.line.y1),x2:Pt(n.line.x2),y2:Pt(n.line.y2)},paint:{stroke:r,strokeWidth:String(n.config.axisLineWidth)},attributes:{className:`xychart-axis-line xychart-${i}-axis-line`}}))}if(!n.config.showTick)return;for(const s of n.ticks){t.push(e.shape({id:`axis:${i}:tick:${s.label}`,role:"axis",geometry:{kind:"line",x1:Pt(s.x),y1:Pt(s.y),x2:Pt(s.tx),y2:Pt(s.ty)},paint:{stroke:o,strokeWidth:String(n.config.tickWidth)},attributes:{className:`xychart-tick xychart-${i}-tick`}}))}}function fB(e,t,n,i,r,o,s){for(const a of n){const l=a.block?.text??gi(a.label,o.edgeTextTransform);const c=a.textAnchor==="end";t.push(e.text({id:`axis:${r}:label:${a.label}`,role:"axis",text:l,block:a.block,x:a.labelX,y:a.labelY,fontSize:i,fontWeight:o.nodeLabelFontWeight,letterSpacing:o.nodeLetterSpacing,display:"literal",anchor:a.textAnchor,...c?{dominantBaseline:"middle",baselineShift:0}:{},paint:{fill:s},attributes:{className:`xychart-label xychart-${r}-label`}}))}}function KK(e,t){const n=e.theme;return{gridStroke:t.edgeStrokeColor??"color-mix(in srgb, var(--fg) 14%, transparent)",titleColor:n.titleColor??t.groupTextColor??t.nodeTextColor??"var(--_text)",labelColor:t.nodeTextColor??"var(--_text)",xAxisLabelColor:n.xAxisLabelColor??t.nodeTextColor??"var(--_text)",yAxisLabelColor:n.yAxisLabelColor??t.nodeTextColor??"var(--_text)",xAxisTickColor:n.xAxisTickColor??t.groupTextColor??"var(--_text-sec)",yAxisTickColor:n.yAxisTickColor??t.groupTextColor??"var(--_text-sec)",xAxisLineColor:n.xAxisLineColor??t.edgeStrokeColor??"var(--_text-sec)",yAxisLineColor:n.yAxisLineColor??t.edgeStrokeColor??"var(--_text-sec)",xAxisTitleColor:n.xAxisTitleColor??t.edgeTextColor??t.nodeTextColor??"var(--_text)",yAxisTitleColor:n.yAxisTitleColor??t.edgeTextColor??t.nodeTextColor??"var(--_text)",legendTextColor:n.legendTextColor??t.nodeTextColor??"var(--_text)"}}function hB(e,t,n){const i=t??oa;const r=e.theme.plotColorPalette;const o=Math.max(0,...e.bars.map(l=>l.colorIndex),...e.lines.map(l=>l.colorIndex));const s=Zi(o+1,{accent:i,bg:n});const a=l=>r&&r.length>0?r[l%r.length]:s[l];return{concrete:a,css:l=>!(r&&r.length>0)&&l===0&&s.length<=6&&s[0]===i?`var(--accent, ${oa})`:a(l)}}function JK(e){const t=e===void 0?null:Kt(e);return t&&t[3]===1?Xo(Yn(t[0],t[1],t[2])):void 0}function QK(e,t,n,i){const r=new Set;for(const u of e.bars)r.add(u.colorIndex);for(const u of e.lines)r.add(u.colorIndex);const o=[];const s=hB(e,n,i);for(const u of[...r].sort((f,h)=>f-h)){o.push(` --xychart-color-${u}: ${s.css(u)};`)}const a=t?mu("xychart",["xychart-bar-group","xychart-dot-group"]):"";const l=o.length>0?`
45
+ svg {
46
+ ${o.join("\n")}
47
+ }`:"";const c=e.theme.themeCss?`
48
+ ${e.theme.themeCss}
49
+ `:"";const d=`<style>
50
+ .xychart-data-label { pointer-events: none; }${l}${a}${c}
51
+ </style>`;return{style:d,defs:""}}function ZK(e){if(e.length===0)return"";let t=`M${Gx(e[0].x)},${Gx(e[0].y)}`;for(let n=1;n<e.length;n++){t+=` L${Gx(e[n].x)},${Gx(e[n].y)}`}return t}function Pt(e){return Math.round(e*100)/100}function Gx(e){return Pt(e).toString()}function e7(e){const t=`mermaid-${t7(e)}`;const n=e.accessibility?.title?`chart-title-${t}`:void 0;const i=e.accessibility?.description?`chart-desc-${t}`:void 0;const r=e.config.useWidth??e.width;const o=e.config.useMaxWidth?"100%":String(r);const s=e.config.useMaxWidth?"100%":String(Math.round(e.height*(r/Math.max(1,e.width))));const a=e.config.useMaxWidth?`max-width:${r}px`:void 0;return{openTag:{width:o,height:s,style:a,attrs:{id:t,class:"xychart",role:n||i?"img":void 0,"aria-roledescription":"xychart","aria-labelledby":n,"aria-describedby":i}},title:e.accessibility?.title?`<title id="${n}">${At(e.accessibility.title)}</title>`:void 0,description:e.accessibility?.description?`<desc id="${i}">${At(e.accessibility.description)}</desc>`:void 0}}function t7(e){const t=[e.width,e.height,e.title?.text??"",e.accessibility?.title??"",e.accessibility?.description??"",e.bars.length,e.lines.length].join("|");let n=5381;for(let i=0;i<t.length;i++){n=(n<<5)+n^t.charCodeAt(i)}return Math.abs(n>>>0).toString(36)}var mB=gt(VK);var o$e={configDiagnostics:dB,statementEnds:PM,normalizeRequest:e=>{const t=Ih(e.source.frontmatter);const n=Fh(e.source.frontmatter);return{familyConfig:{config:t},appearance:{...e.renderOptions.bg===void 0&&n.backgroundColor?{colors:{bg:n.backgroundColor}}:{},family:{theme:n}}}},layout:e=>{const t=e.familyConfig;const n=e.familyAppearance;const i=CM(Tn(Em(LN(e.source.familyLines),e.source.accessibility),e.source.frontmatter),t?.config??Ih({}),n?.theme??Fh({}));return ht(oF(i,e.renderOptions,e.styleFace),{injectAccessibility:false})},projectPositioned:ut(bF),lowerScene:ft(mB)};export{v7 as a,T7 as b,Pm as c,mb as d,pb as e,gb as f,X7 as g,U7 as h,V7 as i,K7 as j,J7 as k,Q7 as l,Z7 as m,eJ as n,tJ as o,nJ as p,iJ as q,rJ as r,oJ as s,sJ as t,aJ as u,lJ as v,cJ as w,dJ as x,uJ as y,fJ as z,hJ as A,mJ as B,pJ as C,gJ as D,yJ as E,xJ as F,bJ as G,SJ as H,wJ as I,MJ as J,kJ as K,CJ as L,PJ as M,EJ as N,RJ as O,Nv as P,$v as Q,lE as R,cE as S,dE as T,fE as U,Sa as V,bo as W,Un as X,fP as Y,Dn as Z,dn as _,mP as $,Yo as aa,GJ as ba,Qe as ca,I7 as da,pr as ea,mr as fa,WB as ga,Iu as ha,El as ia,Fu as ja,Yc as ka,FJ as la,NJ as ma,$J as na,bb as oa,qc as pa,vt as qa,zt as ra,Xc as sa,Ar as ta,Vr as ua,Tl as va,Hu as wa,Jb as xa,Qb as ya,$s as za,oS as Aa,uz as Ba,Ls as Ca,Fl as Da,Jc as Ea,lS as Fa,op as Ga,Tn as Ha,Nr as Ia,eee as Ja,xz as Ka,Ma as La,TE as Ma,LE as Na,tee as Oa,nee as Pa,Xu as Qa,wz as Ra,IE as Sa,Qc as Ta,Sn as Ua,Mt as Va,fS as Wa,_me as Xa,Mh as Ya,Xre as Za,Sf as _a,jp as $a,ub as ab,rP as bb,eZ as cb,OW as db,tZ as eb,Vm as fb,vn as gb,WW as hb,Du as ib,GW as jb,Tt as kb,Km as lb,Jm as mb,nZ as nb,iZ as ob,Ao as pb,Xp as qb,Xs as rb,s4 as sb,eoe as tb,Ts as ub,Ve as vb,Tm as wb,Fm as xb,ec as yb,Mf as zb,ooe as Ab,oP as Bb,cT as Cb,Ew as Db,f4 as Eb,uT as Fb,koe as Gb,p4 as Hb,g4 as Ib,x4 as Jb,Vp as Kb,ST as Lb,wT as Mb,PT as Nb,ET as Ob,R4 as Pb,vT as Qb,qoe as Rb,TT as Sb,Qp as Tb,A4 as Ub,AT as Vb,Md as Wb,Voe as Xb,Koe as Yb,Zp as Zb,eg as _b,Joe as $b,$4 as ac,Qoe as bc,_4 as cc,Zoe as dc,D4 as ec,ese as fc,hb as gc,aP as hc,Lr as ic,Rs as jc,vs as kc,tg as lc,Y4 as mc,pse as nc,WT as oc,og as pc,XT as qc,tc as rc,zw as sc,Gw as tc,Rse as uc,ag as vc,Rf as wc,dj as xc,lg as yc,vse as zc,Cb as Ac,eQ as Bc,bP as Cc,wP as Dc,MP as Ec,tQ as Fc,vm as Gc,Ose as Hc,vf as Ic,jw as Jc,rL as Kc,Sj as Lc,wj as Mc,aL as Nc,WX as Oc,Yw as Pc,Kme as Qc,CF as Rc,Ed as Sc,Kse as Tc,Xw as Uc,sQ as Vc,Kr as Wc,Ht as Xc,Ll as Yc,fa as Zc,Aj as _c,Uw as $c,XX as ad,PF as bd,ra as cd,ype as dd,Ly as ed,QN as fd,yc as gd,Fy as hd,Ph as id,Za as jd,RF as kd,c$ as ld,yi as md,mL as nd,Zw as od,Nj as pd,$f as qd,Vs as rd,Af as sd,If as td,Ff as ud,Nf as vd,wL as wd,wae as xd,Bj as yd,Wj as zd,Mae as Ad,zj as Bd,kL as Cd,lQ as Dd,Fb as Ed,zP as Fd,gW as Gd,yW as Hd,vQ as Id,TQ as Jd,LQ as Kd,jP as Ld,YP as Md,qP as Nd,Tae as Od,mg as Pd,jj as Qd,Lae as Rd,e0 as Sd,EL as Td,Oae as Ud,za as Vd,Ga as Wd,Bae as Xd,Df as Yd,Of as Zd,Vj as _d,DL as $d,uo as ae,OL as be,Zae as ce,bg as de,gg as ee,s0 as fe,IL as ge,ele as he,Sg as ie,tle as je,cY as ke,WL as le,dY as me,uY as ne,yg as oe,xg as pe,nc as qe,vF as re,uh as se,fh as te,hh as ue,oX as ve,wfe as we,Mfe as xe,xc as ye,jpe as ze,AF as Ae,a5 as Be,Ype as Ce,qpe as De,HF as Ee,Xpe as Fe,Upe as Ge,g5 as He,JF as Ie,y5 as Je,Vpe as Ke,_F as Le,Di as Me,lle as Ne,cle as Oe,dle as Pe,bY as Qe,wg as Re,wY as Se,ble as Te,c0 as Ue,KL as Ve,Sle as We,Wf as Xe,u0 as Ye,m0 as Ze,Eg as _e,_Y as $e,Ha as af,DY as bf,n2 as cf,vg as df,r2 as ef,WY as ff,Tg as gf,Dle as hf,a2 as if,Ole as jf,$y as kf,E5 as lf,ige as mf,nN as nf,rN as of,age as pf,oN as qf,aN as rf,dN as sf,uN as tf,Gm as uf,ya as vf,IQ as wf,Ag as xf,g2 as yf,eq as zf,Zle as Af,tq as Bf,Fg as Cf,M2 as Df,Ng as Ef,k2 as Ff,C2 as Gf,cq as Hf,$g as If,_g as Jf,P2 as Kf,E2 as Lf,Dg as Mf,Og as Nf,R2 as Of,Bg as Pf,v2 as Qf,oce as Rf,T2 as Sf,Wg as Tf,Gf as Uf,zg as Vf,L2 as Wf,A2 as Xf,I2 as Yf,N2 as Zf,$2 as _f,_2 as $f,ja as ag,Yle as bg,m2 as cg,Xle as dg,Qm as eg,j2 as fg,Hf as gg,kq as hg,q2 as ig,Fq as jg,$ce as kg,C0 as lg,Fd as mg,xa as ng,Rn as og,Nb as pg,QP as qg,zQ as rg,IW as sg,ir as tg,_b as ug,eE as vg,qm as wg,UQ as xg,tE as yg,iE as zg,VQ as Ag,KQ as Bg,rA as Cg,fN as Dg,yN as Eg,bN as Fg,SN as Gg,wN as Hg,MN as Ig,kN as Jg,H5 as Kg,j5 as Lg,CN as Mg,LN as Ng,Oge as Og,CM as Pg,Bge as Qg,Wge as Rg,qf as Sg,Xg as Tg,aA as Ug,rc as Vg,Vg as Wg,Xf as Xg,jge as Yg,BN as Zg,Zm as _g,Hb as $g,Kc as ah,Jce as bh,Gye as ch,rxe as dh,Or as eh,Vb as fh,ka as gh,Vu as hh,$l as ih,YE as jh,gS as kh,Xz as lh,Mo as mh,oE as nh,Uz as oh,Ol as ph,nd as qh,$ee as rh,_ee as sh,Dee as th,lR as uh,cR as vh,eG as wh,Oee as xh,kS as yh,_l as zh,$r as Ah,Yi as Bh,dR as Ch,Wl as Dh,uR as Eh,dG as Fh,Bee as Gh,vS as Hh,Ta as Ih,Jo as Jh,tv as Kh,One as Lh,Oxe as Mh,b6 as Nh,hbe as Oh,Qbe as Ph,FM as Qh,k6 as Rh,oa as Sh,Zi as Th,jSe as Uh,hwe as Vh,Une as Wh,Da as Xh,T$ as Yh,Twe as Zh,c0e as _h,oc as $h,Kf as ai,Jf as bi,Qf as ci,T0 as di,uA as ei,Zy as fi,$$ as gi,Bh as hi,$Me as ii,Xi as ji,zS as ki,W_ as li,pA as mi,A0 as ni,jD as oi,MV as pi,kV as qi,uO as ri,jd as si,YI as ti,sM as ui,ky as vi,pc as wi,eu as xi,g1 as yi,q$ as zi,VM as Ai,qO as Bi,XO as Ci,PX as Di,nF as Ei,U$ as Fi,qPe as Gi,ave as Hi,$d as Ii,Nt as Ji,rs as Ki,Hve as Li,cTe as Mi,qTe as Ni,yLe as Oi,o2e as Pi,G2e as Qi,SAe as Ri,ZAe as Si,BIe as Ti,kFe as Ui,OFe as Vi,nNe as Wi,TNe as Xi,o$e as Yi,Cv as Zi,pw as _i,Gp as $i,Uie as aj,Jv as bj,gw as cj,rT as dj,UH as ej,JH as fj,Hre as gj};
52
+ //# sourceMappingURL=chunk-EHJI3QYE.js.map