@pi-chamber/web 0.9.4 → 0.9.6

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 (107) hide show
  1. package/README.md +15 -0
  2. package/dist/assets/DiagramView-0Iq1ak1I.js +1 -0
  3. package/dist/assets/{DiffView-CBOrV4hS.js → DiffView-DD1AFRi3.js} +2 -2
  4. package/dist/assets/FileSaveConflictDialog-CoKwDovb.js +3 -0
  5. package/dist/assets/FilesView-B_BF39ef.js +6 -0
  6. package/dist/assets/GitView-LFEpCasf.js +8 -0
  7. package/dist/assets/{JsonTreeView-CKWGm5MS.js → JsonTreeView-Cwjgvh4g.js} +1 -1
  8. package/dist/assets/MarkdownRendererImpl-_7kV1yNw.js +12 -0
  9. package/dist/assets/PatchDiff-DG43C1HW.js +1 -0
  10. package/dist/assets/{SessionSwitcherContent-z9VYCXrT.js → SessionSwitcherContent-DCFXPY3d.js} +1 -1
  11. package/dist/assets/SessionSwitcherDropdown-QY7FKuEQ.js +2 -0
  12. package/dist/assets/SessionUnreadDot-DGT31A3z.js +1 -0
  13. package/dist/assets/SettingsView-eG-wN-yY.js +2 -0
  14. package/dist/assets/SettingsWindow-Dvnp8YrA.js +1 -0
  15. package/dist/assets/ToolOutputDialog-IlCrS6BR.js +8 -0
  16. package/dist/assets/ToolPartDiffPreview-D68JV0rR.js +1 -0
  17. package/dist/assets/{VirtualizedFileDiff-DfaXovGB.js → VirtualizedFileDiff-Bl-rAYeh.js} +3 -3
  18. package/dist/assets/collapsible-BjniCdZ5.js +1 -0
  19. package/dist/assets/computeVirtualFileMetrics-FSOm2VrW.js +3 -0
  20. package/dist/assets/contextFileOpenGuard-Bxb6AIPa.js +1 -0
  21. package/dist/assets/gitStatusPredicates-DxolDpMd.js +134 -0
  22. package/dist/assets/index-BpmGBboM.css +1 -0
  23. package/dist/assets/index-DZnzXhTs.js +8 -0
  24. package/dist/assets/index-Dh58uD3I.js +1 -0
  25. package/dist/assets/isDiffPlainText-D3_04XCh.js +1 -0
  26. package/dist/assets/isFilePlainText-CHouYQhH.js +1 -0
  27. package/dist/assets/{main-DG1oZ0Wj.js → main-CH3EqGJI.js} +2 -2
  28. package/dist/assets/main-HzTrVvbB.js +135 -0
  29. package/dist/assets/{markdownCore-DUjQU2i0.js → markdownCore-DJU4KvHP.js} +2 -2
  30. package/dist/assets/{miniChat-BEAtOkr9.js → miniChat-Ca3TpaaA.js} +2 -2
  31. package/dist/assets/{mobile-DOFBBQg2.js → mobile-lj4gpGsO.js} +2 -2
  32. package/dist/assets/renderElectronMiniChatApp-rUFfaD-T.js +2 -0
  33. package/dist/assets/renderMobileApp-CcWQ1sCf.js +11 -0
  34. package/dist/assets/runtimeEndpointReset-D2MmSbDk.js +53 -0
  35. package/dist/assets/{runtimeSurface-CySRuLbN.js → runtimeSurface-CE_VNjdH.js} +1 -1
  36. package/dist/assets/{useAppFontEffects-C4JL1x7k.js → useAppFontEffects-BvFAP9zG.js} +102 -103
  37. package/dist/assets/useFilesViewSearch-BD79p3A2.js +7 -0
  38. package/dist/assets/usePushVisibilityBeacon-CWg0j-Wg.js +10 -0
  39. package/dist/assets/useSwitcherItems-CazJ6Yox.js +1 -0
  40. package/dist/assets/{vendor-base-ui-vkqQ2P9o.js → vendor-base-ui-CdaWtC7e.js} +1 -1
  41. package/dist/assets/vendor-beautiful-mermaid-D3YCkKz7.js +111 -0
  42. package/dist/assets/{vendor-codemirror-commands-DYppkHEk.js → vendor-codemirror-commands-CNlncqrr.js} +1 -1
  43. package/dist/assets/{vendor-codemirror-language-data-C493X_9w.js → vendor-codemirror-language-data-CP3j3-xu.js} +2 -2
  44. package/dist/assets/{vendor-replit-codemirror-vim-CGHHNQxC.js → vendor-replit-codemirror-vim-DaSwPsXt.js} +1 -1
  45. package/dist/assets/{web-components-B2Rw__yK.js → web-components-DWuadqra.js} +3 -3
  46. package/dist/index.html +4 -4
  47. package/dist/mini-chat.html +3 -3
  48. package/dist/mobile.html +3 -3
  49. package/package.json +2 -2
  50. package/server/lib/fs/DOCUMENTATION.md +15 -3
  51. package/server/lib/fs/routes.js +369 -51
  52. package/server/lib/fs/routes.test.js +565 -3
  53. package/server/lib/fs/search.js +74 -29
  54. package/server/lib/pi/routes.js +56 -3
  55. package/server/lib/pi/routes.test.js +165 -0
  56. package/server/lib/pi/session-daemon/DOCUMENTATION.md +19 -6
  57. package/server/lib/pi/session-daemon/prompt-operations.test.js +151 -3
  58. package/server/lib/pi/session-daemon/prompt-preflight.test.js +556 -0
  59. package/server/lib/pi/session-daemon/sdk-upgrade.test.js +157 -0
  60. package/server/lib/pi/session-daemon/send-operation-dedup.test.js +331 -0
  61. package/server/lib/pi/session-daemon/send-operation-registry.js +264 -0
  62. package/server/lib/pi/session-daemon/send-operation-registry.test.js +205 -0
  63. package/server/lib/pi/session-daemon/session-daemon-extensions.e2e.test.js +16 -5
  64. package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +3 -1
  65. package/server/lib/pi/session-daemon/session-daemon.js +514 -107
  66. package/server/lib/pi/session-daemon/session-daemon.test.js +37 -13
  67. package/server/lib/pi/session-daemon/session-idle-residency.test.js +749 -0
  68. package/server/lib/pi/session-daemon/session-replay.js +98 -0
  69. package/server/lib/pi/session-daemon/session-replay.test.js +628 -0
  70. package/server/lib/pi/ui-settings-store.js +16 -10
  71. package/server/lib/pi/ui-settings-store.test.js +91 -0
  72. package/server/lib/server/cors.js +6 -0
  73. package/server/lib/server/cors.test.js +3 -0
  74. package/server/lib/stt/DOCUMENTATION.md +1 -1
  75. package/server/lib/stt/local/worker-client.js +11 -3
  76. package/server/lib/stt/local/worker-client.test.js +255 -0
  77. package/server/lib/workspace/host.js +6 -2
  78. package/server/lib/workspace/host.test.js +15 -0
  79. package/dist/assets/DiagramEditor-DuGmiPZ5.js +0 -1
  80. package/dist/assets/DiagramView-CHy1Glsl.js +0 -1
  81. package/dist/assets/FilesView-CK2YVs_W.js +0 -6
  82. package/dist/assets/GitView-BEFLOv_7.js +0 -8
  83. package/dist/assets/MarkdownRendererImpl-hE_nmSqe.js +0 -12
  84. package/dist/assets/PatchDiff-BagRxMON.js +0 -1
  85. package/dist/assets/SessionSwitcherDropdown-icxJk_lT.js +0 -2
  86. package/dist/assets/SessionUnreadDot-Bv-5KguB.js +0 -1
  87. package/dist/assets/SettingsView-Ck0qxtKP.js +0 -2
  88. package/dist/assets/SettingsWindow-GQRL2CdD.js +0 -1
  89. package/dist/assets/ToolOutputDialog-CxJUXVZW.js +0 -8
  90. package/dist/assets/ToolPartDiffPreview-BXuLRWHT.js +0 -1
  91. package/dist/assets/collapsible-szfZ0Syc.js +0 -1
  92. package/dist/assets/computeVirtualFileMetrics-DG_E6iaN.js +0 -3
  93. package/dist/assets/contextFileOpenGuard-DPBE3ELv.js +0 -1
  94. package/dist/assets/gitStatusPredicates-OljV4Bb2.js +0 -134
  95. package/dist/assets/index-DNoEeZ2U.css +0 -1
  96. package/dist/assets/index-DmexVlTQ.js +0 -1
  97. package/dist/assets/index-KIdiBFJs.js +0 -8
  98. package/dist/assets/isDiffPlainText-aikgiqLb.js +0 -1
  99. package/dist/assets/isFilePlainText-D-Dl6LqX.js +0 -1
  100. package/dist/assets/main-BXdraZTZ.js +0 -135
  101. package/dist/assets/renderElectronMiniChatApp-B0K72YnS.js +0 -2
  102. package/dist/assets/renderMobileApp-Ca_BO_s4.js +0 -11
  103. package/dist/assets/runtimeEndpointReset-Cx2tsgTo.js +0 -54
  104. package/dist/assets/useFilesViewSearch-Du0DnmKs.js +0 -7
  105. package/dist/assets/usePushVisibilityBeacon-BnHxIv4r.js +0 -10
  106. package/dist/assets/useSwitcherItems-C91mwPJD.js +0 -1
  107. package/dist/assets/vendor-beautiful-mermaid-DneUawHp.js +0 -119
@@ -1,119 +0,0 @@
1
- import{E as So}from"./vendor-elkjs-mzfkf0ML.js";import{d as Lo}from"./vendor-entities-C3BA0AJP.js";var en={bg:"#FFFFFF",fg:"#27272A"},Pt={textSec:60,textMuted:40,textFaint:25,line:50,arrow:85,nodeFill:3,nodeStroke:20,groupHeader:5,innerStroke:12,keyBadge:10};function me(t,e){const n=[`@import url('https://fonts.googleapis.com/css2?family=${encodeURIComponent(t)}:wght@400;500;600;700&display=swap');`,...e?["@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&display=swap');"]:[]],s=`
2
- /* Derived from --bg and --fg (overridable via --line, --accent, etc.) */
3
- --_text: var(--fg);
4
- --_text-sec: var(--muted, color-mix(in srgb, var(--fg) ${Pt.textSec}%, var(--bg)));
5
- --_text-muted: var(--muted, color-mix(in srgb, var(--fg) ${Pt.textMuted}%, var(--bg)));
6
- --_text-faint: color-mix(in srgb, var(--fg) ${Pt.textFaint}%, var(--bg));
7
- --_line: var(--line, color-mix(in srgb, var(--fg) ${Pt.line}%, var(--bg)));
8
- --_arrow: var(--accent, color-mix(in srgb, var(--fg) ${Pt.arrow}%, var(--bg)));
9
- --_node-fill: var(--surface, color-mix(in srgb, var(--fg) ${Pt.nodeFill}%, var(--bg)));
10
- --_node-stroke: var(--border, color-mix(in srgb, var(--fg) ${Pt.nodeStroke}%, var(--bg)));
11
- --_group-fill: var(--bg);
12
- --_group-hdr: color-mix(in srgb, var(--fg) ${Pt.groupHeader}%, var(--bg));
13
- --_inner-stroke: color-mix(in srgb, var(--fg) ${Pt.innerStroke}%, var(--bg));
14
- --_key-badge: color-mix(in srgb, var(--fg) ${Pt.keyBadge}%, var(--bg));`;return["<style>",` ${n.join(`
15
- `)}`,` text { font-family: '${t}', system-ui, sans-serif; }`,...e?[" .mono { font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', ui-monospace, monospace; }"]:[],` svg {${s}`," }","</style>"].join(`
16
- `)}function be(t,e,n,s){const r=[`--bg:${n.bg}`,`--fg:${n.fg}`,n.line?`--line:${n.line}`:"",n.accent?`--accent:${n.accent}`:"",n.muted?`--muted:${n.muted}`:"",n.surface?`--surface:${n.surface}`:"",n.border?`--border:${n.border}`:""].filter(Boolean).join(";");return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${t} ${e}" width="${t}" height="${e}" style="${r}${s?"":";background:var(--bg)"}">`}var Ao=new Set(["i","l","t","f","j","I","1","!","|",".",",",":",";","'"]),Co=new Set(["W","M","w","m","@","%"]),To=new Set(["W","M"]),Io=new Set(["(",")","[","]","{","}","/","\\","-",'"',"`"]);function Ro(t){return t>=768&&t<=879||t>=6832&&t<=6911||t>=7616&&t<=7679||t>=8400&&t<=8447||t>=65056&&t<=65071}function Ho(t){return t>=4352&&t<=4447||t>=11904&&t<=12031||t>=12032&&t<=12255||t>=12288&&t<=12351||t>=12352&&t<=12447||t>=12448&&t<=12543||t>=12544&&t<=12591||t>=12592&&t<=12687||t>=12688&&t<=12799||t>=12800&&t<=13311||t>=13312&&t<=19903||t>=19968&&t<=40959||t>=44032&&t<=55215||t>=63744&&t<=64255||t>=65280&&t<=65376||t>=65504&&t<=65510||t>=131072}var Wo=new RegExp("\\p{Emoji_Presentation}|\\p{Extended_Pictographic}","u");function Yo(t){return Wo.test(t)}function Do(t){const e=t.codePointAt(0);return e===void 0||Ro(e)?0:Ho(e)||Yo(t)?2:t===" "?.3:To.has(t)?1.5:Co.has(t)?1.2:Ao.has(t)?.4:Io.has(t)?.5:t==="r"?.8:e>=65&&e<=90?1.2:(e>=48&&e<=57,1)}function Hn(t,e,n){const s=n>=600?.6:n>=500?.57:.54;let r=0;for(const i of t)r+=Do(i);const o=e*.15;return r*e*s+o}var Wn=1.3;function te(t,e,n){const s=t.split(`
17
- `),r=e*Wn;let o=0;for(const i of s){const a=i.replace(/<\/?(?:b|strong|i|em|u|s|del)\s*>/gi,""),l=Hn(a,e,n);l>o&&(o=l)}return{width:o,height:s.length*r,lines:s,lineHeight:r}}function $t(t){return(t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t).replace(/<br\s*\/?>/gi,`
18
- `).replace(/\\n/g,`
19
- `).replace(/<\/?(?:sub|sup|small|mark)\s*>/gi,"").replace(/\*\*(.+?)\*\*/g,"<b>$1</b>").replace(new RegExp("(?<!\\*)\\*([^\\s*](?:[^*]*[^\\s*])?)\\*(?!\\*)","g"),"<i>$1</i>").replace(/~~(.+?)~~/g,"<s>$1</s>")}function ue(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}var nn=/<(\/)?(?:(b|strong)|(i|em)|(u)|(s|del))\s*>/gi;function Eo(t){const e=[];let n=!1,s=!1,r=!1,o=!1,i=0;nn.lastIndex=0;let a;for(;(a=nn.exec(t))!==null;){a.index>i&&e.push({text:t.slice(i,a.index),bold:n,italic:s,underline:r,strikethrough:o}),i=a.index+a[0].length;const l=!!a[1];a[2]?n=!l:a[3]?s=!l:a[4]?r=!l:a[5]&&(o=!l)}return i<t.length&&e.push({text:t.slice(i),bold:n,italic:s,underline:r,strikethrough:o}),e}var Xo=/<\/?(?:b|strong|i|em|u|s|del)\s*>/i;function on(t){if(!Xo.test(t))return ue(t);const e=Eo(t);return e.length===0?"":e.every(s=>!s.bold&&!s.italic&&!s.underline&&!s.strikethrough)?e.map(s=>ue(s.text)).join(""):e.map(s=>{const r=ue(s.text);if(!s.bold&&!s.italic&&!s.underline&&!s.strikethrough)return r;const o=[];s.bold&&o.push('font-weight="bold"'),s.italic&&o.push('font-style="italic"');const i=[];return s.underline&&i.push("underline"),s.strikethrough&&i.push("line-through"),i.length&&o.push(`text-decoration="${i.join(" ")}"`),`<tspan ${o.join(" ")}>${r}</tspan>`}).join("")}function Ct(t,e,n,s,r,o=.35){const i=t.split(`
20
- `);if(i.length===1){const c=s*o;return`<text x="${e}" y="${n}" ${r} dy="${c}">${on(t)}</text>`}const a=s*Wn,l=-((i.length-1)/2)*a+s*o,h=i.map((c,d)=>`<tspan x="${e}" dy="${d===0?l:a}">${on(c)}</tspan>`).join("");return`<text x="${e}" y="${n}" ${r}>${h}</text>`}function _o(t,e,n,s,r,o,i,a,l){const h=s+i*2,c=r+i*2,d=`<rect x="${e-h/2}" y="${n-c/2}" width="${h}" height="${c}" ${l} />`,f=Ct(t,e,n,o,a);return`${d}
21
- ${f}`}function Yn(t){const e=t.split(`
22
- `).map(s=>s.trim()).filter(s=>s.length>0&&!s.startsWith("%%"));if(e.length===0)throw new Error("Empty mermaid diagram");const n=e[0];return/^stateDiagram(-v2)?\s*$/i.test(n)?zo(e):Po(e)}function Po(t){const e=t[0].match(/^(?:graph|flowchart)\s+(TD|TB|LR|BT|RL)\s*$/i);if(!e)throw new Error(`Invalid mermaid header: "${t[0]}". Expected "graph TD", "flowchart LR", "stateDiagram-v2", etc.`);const s={direction:e[1].toUpperCase(),nodes:new Map,edges:[],subgraphs:[],classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map},r=[];for(let o=1;o<t.length;o++){const i=t[o],a=i.match(/^classDef\s+(\w+)\s+(.+)$/);if(a){const u=a[1],g=a[2],x=Ce(g);s.classDefs.set(u,x);continue}const l=i.match(/^class\s+([\w,-]+)\s+(\w+)$/);if(l){const u=l[1].split(",").map(x=>x.trim()),g=l[2];for(const x of u)s.classAssignments.set(x,g);continue}const h=i.match(/^style\s+([\w,-]+)\s+(.+)$/);if(h){const u=h[1].split(",").map(x=>x.trim()),g=Ce(h[2]);for(const x of u)s.nodeStyles.set(x,{...s.nodeStyles.get(x),...g});continue}const c=i.match(/^linkStyle\s+(default|[\d,\s]+)\s+(.+)$/);if(c){const u=c[1].trim(),g=Ce(c[2]);if(u==="default")s.linkStyles.set("default",{...s.linkStyles.get("default"),...g});else{const x=u.split(",").map(p=>parseInt(p.trim(),10));for(const p of x)isNaN(p)||s.linkStyles.set(p,{...s.linkStyles.get(p),...g})}continue}const d=i.match(/^direction\s+(TD|TB|LR|BT|RL)\s*$/i);if(d&&r.length>0){r[r.length-1].direction=d[1].toUpperCase();continue}const f=i.match(/^subgraph\s+(.+)$/);if(f){const u=f[1].trim(),g=u.match(/^([\w-]+)\s*\[(.+)\]$/);let x,p;g?(x=g[1],p=$t(g[2])):(p=$t(u),x=u.replace(/\s+/g,"_").replace(/[^\w]/g,""));const M={id:x,label:p,nodeIds:[],children:[]};r.push(M);continue}if(i==="end"){const u=r.pop();u&&(r.length>0?r[r.length-1].children.push(u):s.subgraphs.push(u));continue}Fo(i,s,r)}return s}function zo(t){const e={direction:"TD",nodes:new Map,edges:[],subgraphs:[],classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map},n=[],s=new Set;let r=0,o=0;for(let i=1;i<t.length;i++){const a=t[i],l=a.match(/^direction\s+(TD|TB|LR|BT|RL)\s*$/i);if(l){n.length>0?n[n.length-1].direction=l[1].toUpperCase():e.direction=l[1].toUpperCase();continue}const h=a.match(/^linkStyle\s+(default|[\d,\s]+)\s+(.+)$/);if(h){const g=h[1].trim(),x=Ce(h[2]);if(g==="default")e.linkStyles.set("default",{...e.linkStyles.get("default"),...x});else{const p=g.split(",").map(M=>parseInt(M.trim(),10));for(const M of p)isNaN(M)||e.linkStyles.set(M,{...e.linkStyles.get(M),...x})}continue}const c=a.match(/^state\s+(?:"([^"]+)"\s+as\s+)?([\w\p{L}]+)\s*\{$/u);if(c){const g=c[1]??c[2],x=c[2],p={id:x,label:g,nodeIds:[],children:[]};n.push(p),s.add(x),e.nodes.delete(x);continue}if(a==="}"){const g=n.pop();g&&(n.length>0?n[n.length-1].children.push(g):e.subgraphs.push(g));continue}const d=a.match(/^state\s+"([^"]+)"\s+as\s+([\w\p{L}]+)\s*$/u);if(d){const g=$t(d[1]),x=d[2];fe(e,n,{id:x,label:g,shape:"rounded"});continue}const f=a.match(/^(\[\*\]|[\w\p{L}-]+)\s*(-->)\s*(\[\*\]|[\w\p{L}-]+)(?:\s*:\s*(.+))?$/u);if(f){let g=f[1],x=f[3];const p=f[4]?.trim(),M=p?$t(p):void 0;g==="[*]"?(r++,g=`_start${r>1?r:""}`,fe(e,n,{id:g,label:"",shape:"state-start"})):s.has(g)||sn(e,n,g),x==="[*]"?(o++,x=`_end${o>1?o:""}`,fe(e,n,{id:x,label:"",shape:"state-end"})):s.has(x)||sn(e,n,x),e.edges.push({source:g,target:x,label:M,style:"solid",hasArrowStart:!1,hasArrowEnd:!0});continue}const u=a.match(/^([\w\p{L}-]+)\s*:\s*(.+)$/u);if(u){const g=u[1],x=$t(u[2].trim());fe(e,n,{id:g,label:x,shape:"rounded"});continue}}return e}function fe(t,e,n){if(!t.nodes.has(n.id)&&t.nodes.set(n.id,n),e.length>0){const r=e[e.length-1];r.nodeIds.includes(n.id)||r.nodeIds.push(n.id)}}function sn(t,e,n){if(!t.nodes.has(n))fe(t,e,{id:n,label:n,shape:"rounded"});else if(e.length>0){const s=e[e.length-1];s.nodeIds.includes(n)||s.nodeIds.push(n)}}function Ce(t){const e=t.replace(/;\s*$/,""),n={};for(const s of e.split(",")){const r=s.indexOf(":");if(r>0){const o=s.slice(0,r).trim(),i=s.slice(r+1).trim();o&&i&&(n[o]=i)}}return n}var Bo=/^(<)?(-->|-.->|==>|---|-\.-|===)(?:\|([^|]*)\|)?/,No=/^(<)?(--|-\.|==)\s+(.+?)\s+(-->|---|\.\->|-\.\-|==>|===)/,jo=[{regex:/^([\w-]+)\(\(\((.+?)\)\)\)/,shape:"doublecircle"},{regex:/^([\w-]+)\(\[(.+?)\]\)/,shape:"stadium"},{regex:/^([\w-]+)\(\((.+?)\)\)/,shape:"circle"},{regex:/^([\w-]+)\[\[(.+?)\]\]/,shape:"subroutine"},{regex:/^([\w-]+)\[\((.+?)\)\]/,shape:"cylinder"},{regex:/^([\w-]+)\[\/(.+?)\\\]/,shape:"trapezoid"},{regex:/^([\w-]+)\[\\(.+?)\/\]/,shape:"trapezoid-alt"},{regex:/^([\w-]+)>(.+?)\]/,shape:"asymmetric"},{regex:/^([\w-]+)\{\{(.+?)\}\}/,shape:"hexagon"},{regex:/^([\w-]+)\[(.+?)\]/,shape:"rectangle"},{regex:/^([\w-]+)\((.+?)\)/,shape:"rounded"},{regex:/^([\w-]+)\{(.+?)\}/,shape:"diamond"}],Go=/^([\w-]+)/,Oo=/^:::([\w][\w-]*)/;function Fo(t,e,n){let s=t.trim();const r=rn(s,e,n);if(!r||r.ids.length===0)return;s=r.remaining.trim();let o=r.ids;for(;s.length>0;){let i,a,l,h;const c=s.match(Bo);if(c){i=!!c[1];const f=c[2],u=c[3]?.trim();h=u?$t(u):void 0,s=s.slice(c[0].length).trim(),a=Vo(f),l=f.endsWith(">")}else{const f=s.match(No);if(!f)break;i=!!f[1];const u=f[3].trim();h=u?$t(u):void 0;const g=f[2],x=f[4];s=s.slice(f[0].length).trim(),a=qo(g,x),l=x.endsWith(">")}const d=rn(s,e,n);if(!d||d.ids.length===0)break;s=d.remaining.trim();for(const f of o)for(const u of d.ids)e.edges.push({source:f,target:u,label:h,style:a,hasArrowStart:i,hasArrowEnd:l});o=d.ids}}function rn(t,e,n){const s=an(t,e,n);if(!s)return null;const r=[s.id];let o=s.remaining.trim();for(;o.startsWith("&");){o=o.slice(1).trim();const i=an(o,e,n);if(!i)break;r.push(i.id),o=i.remaining.trim()}return{ids:r,remaining:o}}function an(t,e,n){let s=null,r=t;for(const{regex:i,shape:a}of jo){const l=t.match(i);if(l){s=l[1];const h=$t(l[2]);ln(e,n,{id:s,label:h,shape:a}),r=t.slice(l[0].length);break}}if(s===null){const i=t.match(Go);i&&(s=i[1],e.nodes.has(s)||ln(e,n,{id:s,label:s,shape:"rectangle"}),r=t.slice(i[0].length))}if(s===null)return null;const o=r.match(Oo);return o&&(e.classAssignments.set(s,o[1]),r=r.slice(o[0].length)),{id:s,remaining:r}}function ln(t,e,n){!t.nodes.has(n.id)&&t.nodes.set(n.id,n),Jo(e,n.id)}function Jo(t,e){if(t.length>0){const n=t[t.length-1];n.nodeIds.includes(e)||n.nodeIds.push(e)}}function Vo(t){return t==="-.->"||t==="-.-"?"dotted":t==="==>"||t==="==="?"thick":"solid"}function qo(t,e){return t==="-."||e===".->"||e==="-.-"?"dotted":t==="=="||e==="==>"||e==="==="?"thick":"solid"}var nt={x:1,y:0},U={x:1,y:2},ot={x:0,y:1},Q={x:2,y:1},Xt={x:2,y:0},Yt={x:0,y:0},Bt={x:2,y:2},_t={x:0,y:2},ne={x:1,y:1};function cn(t,e){return t.x===e.x&&t.y===e.y}function qe(t,e){return t.x===e.x&&t.y===e.y}function Me(t,e){return{x:t.x+e.x,y:t.y+e.y}}function Ut(t){return`${t.x},${t.y}`}var Uo={name:"",styles:{}},Dn={fg:"#27272a",border:"#a1a1aa",line:"#71717a",arrow:"#52525b",corner:"#71717a",junction:"#a1a1aa"};function Ko(){const t=globalThis.process;if(t){if(!t.stdout?.isTTY)return"none";const e=t.env?.COLORTERM?.toLowerCase()??"",n=t.env?.TERM?.toLowerCase()??"";return e==="truecolor"||e==="24bit"?"truecolor":n.includes("256color")||n.includes("256")?"ansi256":n&&n!=="dumb"?"ansi16":"none"}return typeof document<"u"?"html":"none"}function Ue(t){const e=t.replace("#","");return e.length===3?{r:parseInt(e[0]+e[0],16),g:parseInt(e[1]+e[1],16),b:parseInt(e[2]+e[2],16)}:{r:parseInt(e.substring(0,2),16),g:parseInt(e.substring(2,4),16),b:parseInt(e.substring(4,6),16)}}var De="\x1B[",Te=`${De}0m`;function En(t){const{r:e,g:n,b:s}=Ue(t);return`${De}38;2;${e};${n};${s}m`}function Qo(t,e,n){const s=(t+e+n)/3;if(Math.max(Math.abs(t-s),Math.abs(e-s),Math.abs(n-s))<10){const h=Math.round(s/255*23);return 232+Math.min(23,Math.max(0,h))}const o=h=>h<48?0:h<115?1:Math.min(5,Math.floor((h-35)/40)),i=o(t),a=o(e),l=o(n);return 16+36*i+6*a+l}function Xn(t){const{r:e,g:n,b:s}=Ue(t),r=Qo(e,n,s);return`${De}38;5;${r}m`}function _n(t){const{r:e,g:n,b:s}=Ue(t),r=.299*e+.587*n+.114*s,o=r>100?0:60;let i;return e>180&&n<100&&s<100?i=31:n>180&&e<100&&s<100?i=32:e>150&&n>150&&s<100?i=33:s>180&&e<100&&n<100?i=34:e>150&&s>150&&n<100?i=35:n>150&&s>150&&e<100?i=36:r>200?i=37:r<50?i=30:i=37,`${De}${i+o}m`}function Pn(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function zn(t,e){return`<span style="color:${t}">${Pn(e)}</span>`}function Bn(t,e){switch(t){case"text":return e.fg;case"border":return e.border;case"line":return e.line;case"arrow":return e.arrow;case"corner":return e.corner??e.line;case"junction":return e.junction??e.border;default:return e.fg}}function Xe(t,e,n){if(n==="none")return"";const s=Bn(t,e);switch(n){case"truecolor":return En(s);case"ansi256":return Xn(s);case"ansi16":return _n(s);default:return""}}function Zo(t,e,n,s){if(s==="none")return t.join("");if(s==="html")return ts(t,e,n);let r="",o=null,i="";for(let a=0;a<t.length;a++){const l=t[a],h=e[a]??null;if(l===" "){i.length>0&&(o!==null?r+=Xe(o,n,s)+i+Te:r+=i,i="",o=null),r+=l;continue}if(h===o){i+=l;continue}i.length>0&&(o!==null?r+=Xe(o,n,s)+i+Te:r+=i),i=l,o=h}return i.length>0&&o!==null?r+=Xe(o,n,s)+i+Te:i.length>0&&(r+=i),r}function ts(t,e,n){let s="",r=null,o="";const i=()=>{o.length!==0&&(r!==null?s+=zn(Bn(r,n),o):s+=Pn(o),o="",r=null)};for(let a=0;a<t.length;a++){const l=t[a],h=e[a]??null;if(l===" "){i(),s+=" ";continue}if(h===r){o+=l;continue}i(),o=l,r=h}return i(),s}function _e(t,e,n){if(n==="none"||t.length===0)return t;if(n==="html")return zn(e,t);let s;switch(n){case"truecolor":s=En(e);break;case"ansi256":s=Xn(e);break;case"ansi16":s=_n(e);break;default:return t}return`${s}${t}${Te}`}function wt(t,e){const n=[];for(let s=0;s<=t;s++){const r=[];for(let o=0;o<=e;o++)r.push(" ");n.push(r)}return n}function Mt(t){const[e,n]=ye(t);return wt(e,n)}function $e(t,e){const n=[];for(let s=0;s<=t;s++){const r=[];for(let o=0;o<=e;o++)r.push(null);n.push(r)}return n}function oe(t,e,n){const s=t.length-1,r=(t[0]?.length??1)-1,o=Math.max(e,s),i=Math.max(n,r),a=$e(o,i);for(let l=0;l<a.length;l++)for(let h=0;h<a[0].length;h++)l<t.length&&h<t[0].length&&(a[l][h]=t[l][h]);return t.length=0,t.push(...a),t}function we(t,e,n,s){(e>=t.length||n>=(t[0]?.length??0))&&oe(t,e,n),t[e][n]=s}function ye(t){return[t.length-1,(t[0]?.length??1)-1]}function Zt(t,e,n){const[s,r]=ye(t),o=Math.max(e,s),i=Math.max(n,r),a=wt(o,i);for(let l=0;l<a.length;l++)for(let h=0;h<a[0].length;h++)l<t.length&&h<t[0].length&&(a[l][h]=t[l][h]);return t.length=0,t.push(...a),t}var es=new Set(["─","│","┌","┐","└","┘","├","┤","┬","┴","┼","╴","╵","╶","╷"]);function hn(t){return es.has(t)}function fn(t){return/^[a-zA-Z0-9]$/.test(t)}var ns={"─":{"│":"┼","┌":"┬","┐":"┬","└":"┴","┘":"┴","├":"┼","┤":"┼","┬":"┬","┴":"┴"},"│":{"─":"┼","┌":"├","┐":"┤","└":"├","┘":"┤","├":"├","┤":"┤","┬":"┼","┴":"┼"},"┌":{"─":"┬","│":"├","┐":"┬","└":"├","┘":"┼","├":"├","┤":"┼","┬":"┬","┴":"┼"},"┐":{"─":"┬","│":"┤","┌":"┬","└":"┼","┘":"┤","├":"┼","┤":"┤","┬":"┬","┴":"┼"},"└":{"─":"┴","│":"├","┌":"├","┐":"┼","┘":"┴","├":"├","┤":"┼","┬":"┼","┴":"┴"},"┘":{"─":"┴","│":"┤","┌":"┼","┐":"┤","└":"┴","├":"┼","┤":"┤","┬":"┼","┴":"┴"},"├":{"─":"┼","│":"├","┌":"├","┐":"┼","└":"├","┘":"┼","┤":"┼","┬":"┼","┴":"┼"},"┤":{"─":"┼","│":"┤","┌":"┼","┐":"┤","└":"┼","┘":"┤","├":"┼","┬":"┼","┴":"┼"},"┬":{"─":"┬","│":"┼","┌":"┬","┐":"┬","└":"┼","┘":"┼","├":"┼","┤":"┼","┴":"┼"},"┴":{"─":"┴","│":"┼","┌":"┼","┐":"┼","└":"┴","┘":"┴","├":"┼","┤":"┼","┬":"┼"}};function os(t,e){return ns[t]?.[e]??t}function zt(t,e,n,...s){let[r,o]=ye(t);for(const a of s){const[l,h]=ye(a);r=Math.max(r,l+e.x),o=Math.max(o,h+e.y)}const i=wt(r,o);for(let a=0;a<=r;a++)for(let l=0;l<=o;l++)a<t.length&&l<t[0].length&&(i[a][l]=t[a][l]);for(const a of s)for(let l=0;l<a.length;l++)for(let h=0;h<a[0].length;h++){const c=a[l][h];if(c!==" "){const d=l+e.x,f=h+e.y,u=i[d][f];!n&&hn(c)&&hn(u)?i[d][f]=os(u,c):fn(u)&&fn(c)||(i[d][f]=c)}}return i}function Ee(t,e){const[n,s]=ye(t),r=[],o=e?.roleCanvas,i=e?.colorMode??"none",a=e?.theme??Dn;for(let l=0;l<=s;l++)if(i==="none"||!o){let h="";for(let c=0;c<=n;c++)h+=t[c][l];r.push(h)}else{const h=[],c=[];for(let d=0;d<=n;d++)h.push(t[d][l]),c.push(o[d]?.[l]??null);r.push(Zo(h,c,a,i))}return r.join(`
23
- `)}var ss={"▲":"▼","▼":"▲","◤":"◣","◣":"◤","◥":"◢","◢":"◥","^":"v",v:"^","┌":"└","└":"┌","┐":"┘","┘":"┐","┬":"┴","┴":"┬","╵":"╷","╷":"╵"};function rs(t){for(const e of t)e.reverse();for(const e of t)for(let n=0;n<e.length;n++){const s=ss[e[n]];s&&(e[n]=s)}return t}function is(t){for(const e of t)e.reverse();return t}function as(t,e,n,s=!1){Zt(t,e.x+n.length,e.y);for(let r=0;r<n.length;r++){const o=e.x+r,i=t[o][e.y];(s||i===" ")&&(t[o][e.y]=n[r])}}function ls(t,e,n){let s=0,r=0;for(const o of e.values())s+=o;for(const o of n.values())r+=o;Zt(t,s-1,r-1)}function cs(t,e,n){let s=0,r=0;for(const o of e.values())s+=o;for(const o of n.values())r+=o;oe(t,s-1,r-1)}function hs(t,e){const n=new Map;let s=0;for(const[a,l]of t.nodes){const h={name:a,displayLabel:l.label,shape:l.shape,index:s,gridCoord:null,drawingCoord:null,drawing:null,drawn:!1,styleClassName:"",styleClass:Uo};n.set(a,h),s++}const r=[...n.values()],o=[];for(const a of t.edges){const l=n.get(a.source),h=n.get(a.target);!l||!h||o.push({from:l,to:h,text:a.label??"",path:[],labelLine:[],startDir:{x:0,y:0},endDir:{x:0,y:0},style:a.style,hasArrowStart:a.hasArrowStart,hasArrowEnd:a.hasArrowEnd})}const i=[];for(const a of t.subgraphs)Nn(a,null,n,i);fs(t.subgraphs,i,n);for(const[a,l]of t.classAssignments){const h=n.get(a),c=t.classDefs.get(l);h&&c&&(h.styleClassName=l,h.styleClass={name:l,styles:c})}return{nodes:r,edges:o,canvas:wt(0,0),roleCanvas:$e(0,0),grid:new Map,columnWidth:new Map,rowHeight:new Map,subgraphs:i,config:e,offsetX:0,offsetY:0,bundles:[]}}function Nn(t,e,n,s){let r;t.direction&&(r=t.direction==="LR"||t.direction==="RL"?"LR":"TD");const o={name:t.label,nodes:[],parent:e,children:[],minX:0,minY:0,maxX:0,maxY:0,direction:r};for(const i of t.nodeIds){const a=n.get(i);a&&o.nodes.push(a)}s.push(o);for(const i of t.children){const a=Nn(i,o,n,s);o.children.push(a);for(const l of a.nodes)o.nodes.includes(l)||o.nodes.push(l)}return o}function fs(t,e,n,s){const r=new Map;us(t,e,r);const o=new Map;function i(a){const l=r.get(a);if(l){for(const h of a.children)i(h);for(const h of a.nodeIds)o.has(h)||o.set(h,l)}}for(const a of t)i(a);for(const a of e)a.nodes=a.nodes.filter(l=>{let h;for(const[d,f]of n)if(f===l){h=d;break}if(!h)return!1;const c=o.get(h);return c?ds(a,c):!0})}function ds(t,e){let n=e;for(;n!==null;){if(n===t)return!0;n=n.parent}return!1}function us(t,e,n){const s=[];function r(o){for(const i of o)s.push(i),r(i.children)}r(t);for(let o=0;o<s.length&&o<e.length;o++)n.set(s[o],e[o])}var gs=class{items=[];get length(){return this.items.length}push(t){this.items.push(t),this.bubbleUp(this.items.length-1)}pop(){if(this.items.length===0)return;const t=this.items[0],e=this.items.pop();return this.items.length>0&&(this.items[0]=e,this.sinkDown(0)),t}bubbleUp(t){for(;t>0;){const e=t-1>>1;if(this.items[t].priority<this.items[e].priority)[this.items[t],this.items[e]]=[this.items[e],this.items[t]],t=e;else break}}sinkDown(t){const e=this.items.length;for(;;){let n=t;const s=2*t+1,r=2*t+2;if(s<e&&this.items[s].priority<this.items[n].priority&&(n=s),r<e&&this.items[r].priority<this.items[n].priority&&(n=r),n!==t)[this.items[t],this.items[n]]=[this.items[n],this.items[t]],t=n;else break}}};function xs(t,e){const n=Math.abs(t.x-e.x),s=Math.abs(t.y-e.y);return n===0||s===0?n+s:n+s+1}var ys=[{x:1,y:0},{x:-1,y:0},{x:0,y:1},{x:0,y:-1}];function ps(t,e){return e.x<0||e.y<0?!1:!t.has(Ut(e))}function ae(t,e,n){const s=new gs;s.push({coord:e,priority:0});const r=new Map;r.set(Ut(e),0);const o=new Map;for(o.set(Ut(e),null);s.length>0;){const i=s.pop().coord;if(cn(i,n)){const l=[];let h=i;for(;h!==null;)l.unshift(h),h=o.get(Ut(h))??null;return l}const a=r.get(Ut(i));for(const l of ys){const h={x:i.x+l.x,y:i.y+l.y};if(!ps(t,h)&&!cn(h,n))continue;const c=a+1,d=Ut(h),f=r.get(d);if(f===void 0||c<f){r.set(d,c);const u=c+xs(h,n);s.push({coord:h,priority:u}),o.set(d,i)}}}return null}function Qt(t){if(t.length<=2)return t;const e=new Set;let n=t[0],s=t[1];for(let r=2;r<t.length;r++){const o=t[r],i=s.x-n.x,a=s.y-n.y,l=o.x-s.x,h=o.y-s.y;i===l&&a===h&&e.add(r-1),n=s,s=o}return t.filter((r,o)=>!e.has(o))}function ve(t){return t===nt?U:t===U?nt:t===ot?Q:t===Q?ot:t===Xt?_t:t===Yt?Bt:t===Bt?Yt:t===_t?Xt:ne}function b(t,e){return t.x===e.x&&t.y===e.y}function Tt(t,e){return t.x===e.x?t.y<e.y?U:nt:t.y===e.y?t.x<e.x?Q:ot:t.x<e.x?t.y<e.y?Bt:Xt:t.y<e.y?_t:Yt}function ms(t){return t==="LR"?[Q,U,U,Q]:[U,Q,Q,U]}function bs(t,e){if(t.from===t.to)return ms(e);const n=Tt(t.from.gridCoord,t.to.gridCoord);let s,r,o,i;const a=e==="LR"?b(n,ot)||b(n,Yt)||b(n,_t):b(n,nt)||b(n,Yt)||b(n,Xt);return b(n,Bt)?e==="LR"?(s=U,r=ot,o=Q,i=nt):(s=Q,r=nt,o=U,i=ot):b(n,Xt)?e==="LR"?(s=nt,r=ot,o=Q,i=U):(s=Q,r=U,o=nt,i=ot):b(n,_t)?e==="LR"?(s=U,r=U,o=ot,i=nt):(s=ot,r=nt,o=U,i=Q):b(n,Yt)?e==="LR"?(s=U,r=U,o=ot,i=U):(s=Q,r=Q,o=nt,i=Q):a?e==="LR"&&b(n,ot)?(s=U,r=U,o=ot,i=Q):e==="TD"&&b(n,nt)?(s=Q,r=Q,o=nt,i=U):(s=n,r=ve(n),o=n,i=ve(n)):(s=n,r=ve(n),o=n,i=ve(n)),[s,r,o,i]}function $s(t,e){const n=Rt(t,e.from),s=Rt(t,e.to),r=n&&n===s&&n.direction?n.direction:t.config.graphDirection,[o,i,a,l]=bs(e,r),h=Me(e.from.gridCoord,o),c=Me(e.to.gridCoord,i);let d=ae(t.grid,h,c);const f=Me(e.from.gridCoord,a),u=Me(e.to.gridCoord,l);let g=ae(t.grid,f,u);if(d!==null&&g!==null){d=Qt(d),g=Qt(g),d.length<=g.length?(e.startDir=o,e.endDir=i,e.path=d):(e.startDir=a,e.endDir=l,e.path=g);return}if(d!==null){e.startDir=o,e.endDir=i,e.path=Qt(d);return}if(g!==null){e.startDir=a,e.endDir=l,e.path=Qt(g);return}e.startDir=o,e.endDir=i,e.path=[h,c]}function dn(t,e){if(e.text.length===0)return;const n=e.text.length,s=e.path.length;t.config.graphDirection;const r=[];for(let d=1;d<s;d++){const f=e.path[d-1],u=e.path[d],g=[f,u],x=ws(t,g),p=f.x===u.x;r.push({line:g,width:x,index:d,isVertical:p})}const o=r.filter(d=>d.width>=n&&d.index>1);let i;if(o.length>0)o.sort((d,f)=>f.index-d.index),i=o[0].line;else{const d=r.filter(f=>f.width>=n);d.length>0?(d.sort((f,u)=>u.index-f.index),i=d[0].line):(r.sort((f,u)=>u.width-f.width),i=r[0]?.line??[e.path[0],e.path[1]])}const a=Math.min(i[0].x,i[1].x),l=Math.max(i[0].x,i[1].x),h=a+Math.floor((l-a)/2),c=t.columnWidth.get(h)??0;t.columnWidth.set(h,Math.max(c,n+2)),e.labelLine=[i[0],i[1]]}function ws(t,e){let n=0;const s=Math.min(e[0].x,e[1].x),r=Math.max(e[0].x,e[1].x);for(let o=s;o<=r;o++)n+=t.columnWidth.get(o)??0;return n}function Ms(t){if(t.config.graphDirection!=="TD")return[];const e=[],n=new Set,s=new Map;for(const o of t.edges){if(o.from===o.to)continue;const i=s.get(o.to)??[];i.push(o),s.set(o.to,i)}for(const[o,i]of s){if(i.length<2||!un(i,t)||i.some(l=>n.has(l)))continue;const a={type:"fan-in",edges:[...i],sharedNode:o,otherNodes:i.map(l=>l.from),junctionPoint:null,sharedPath:[],junctionDir:ne,sharedNodeDir:ne};for(const l of i)l.bundle=a,n.add(l);e.push(a)}const r=new Map;for(const o of t.edges){if(o.from===o.to||n.has(o))continue;const i=r.get(o.from)??[];i.push(o),r.set(o.from,i)}for(const[o,i]of r){if(i.length<2||!un(i,t))continue;const a={type:"fan-out",edges:[...i],sharedNode:o,otherNodes:i.map(l=>l.to),junctionPoint:null,sharedPath:[],junctionDir:ne,sharedNodeDir:ne};for(const l of i)l.bundle=a,n.add(l);e.push(a)}return e}function un(t,e){if(t.length<2)return!1;const n=t[0].style,s=Rt(e,t[0].from),r=Rt(e,t[0].to);for(const o of t){if(o.style!==n||o.text.length>0)return!1;const i=Rt(e,o.from),a=Rt(e,o.to);if(i!==s||a!==r||i!==a)return!1}return!0}function vs(t,e){const n=t.config.graphDirection,s=e.sharedNode.gridCoord,r=e.otherNodes.map(o=>o.gridCoord);if(e.type==="fan-in")if(Math.min(...r.map(o=>o.x)),Math.max(...r.map(o=>o.x)),Math.min(...r.map(o=>o.y)),Math.max(...r.map(o=>o.y)),n==="TD"){const o=s.y-1;return{x:s.x+1,y:o}}else{const o=s.x-1,i=s.y+1;return{x:o,y:i}}else if(Math.min(...r.map(o=>o.x)),Math.max(...r.map(o=>o.x)),Math.min(...r.map(o=>o.y)),Math.max(...r.map(o=>o.y)),n==="TD"){const o=s.y+3;return{x:s.x+1,y:o}}else{const o=s.x+3,i=s.y+1;return{x:o,y:i}}}function ks(t,e){const n=t.config.graphDirection;e.junctionPoint=vs(t,e);const s=e.junctionPoint;if(e.type==="fan-in"){e.junctionDir=n==="TD"?nt:ot,e.sharedNodeDir=n==="TD"?U:Q;const r=e.sharedNode.gridCoord,o=n==="TD"?{x:r.x+1,y:r.y}:{x:r.x,y:r.y+1},i=ae(t.grid,s,o);e.sharedPath=i?Qt(i):[s,o];for(const a of e.edges){const l=a.from.gridCoord,h=n==="TD"?{x:l.x+1,y:l.y+2}:{x:l.x+2,y:l.y+1},c=ae(t.grid,h,s);a.pathToJunction=c?Qt(c):[h,s],a.startDir=n==="TD"?U:Q,a.endDir=n==="TD"?nt:ot,a.path=[...a.pathToJunction,...e.sharedPath.slice(1)]}}else{e.junctionDir=n==="TD"?U:Q,e.sharedNodeDir=n==="TD"?nt:ot;const r=e.sharedNode.gridCoord,o=n==="TD"?{x:r.x+1,y:r.y+2}:{x:r.x+2,y:r.y+1},i=ae(t.grid,o,s);e.sharedPath=i?Qt(i):[o,s];for(const a of e.edges){const l=a.to.gridCoord,h=n==="TD"?{x:l.x+1,y:l.y}:{x:l.x,y:l.y+1},c=ae(t.grid,s,h);a.pathToJunction=c?Qt(c):[s,h],a.startDir=n==="TD"?U:Q,a.endDir=n==="TD"?nt:ot,a.path=[...e.sharedPath,...a.pathToJunction.slice(1)]}}}function Ss(t){for(const e of t.bundles)ks(t,e)}function pt(t){return t.split(`
24
- `)}function Pe(t){const e=pt(t);return Math.max(...e.map(n=>n.length),0)}function gn(t){return pt(t).length}var xn={rectangle:{unicode:{tl:"┌",tr:"┐",bl:"└",br:"┘"},ascii:{tl:"+",tr:"+",bl:"+",br:"+"}},rounded:{unicode:{tl:"╭",tr:"╮",bl:"╰",br:"╯"},ascii:{tl:".",tr:".",bl:"'",br:"'"}},circle:{unicode:{tl:"◯",tr:"◯",bl:"◯",br:"◯"},ascii:{tl:"o",tr:"o",bl:"o",br:"o"}},doublecircle:{unicode:{tl:"◎",tr:"◎",bl:"◎",br:"◎"},ascii:{tl:"@",tr:"@",bl:"@",br:"@"}},diamond:{unicode:{tl:"◇",tr:"◇",bl:"◇",br:"◇"},ascii:{tl:"<",tr:">",bl:"<",br:">"}},hexagon:{unicode:{tl:"⌜",tr:"⌝",bl:"⌞",br:"⌟"},ascii:{tl:"*",tr:"*",bl:"*",br:"*"}},stadium:{unicode:{tl:"(",tr:")",bl:"(",br:")"},ascii:{tl:"(",tr:")",bl:"(",br:")"}},subroutine:{unicode:{tl:"╟",tr:"╢",bl:"╟",br:"╢"},ascii:{tl:"|",tr:"|",bl:"|",br:"|"}},cylinder:{unicode:{tl:"╭",tr:"╮",bl:"╰",br:"╯"},ascii:{tl:".",tr:".",bl:"'",br:"'"}},asymmetric:{unicode:{tl:"▷",tr:"┐",bl:"▷",br:"┘"},ascii:{tl:">",tr:"+",bl:">",br:"+"}},trapezoid:{unicode:{tl:"/",tr:"\\",bl:"└",br:"┘"},ascii:{tl:"/",tr:"\\",bl:"+",br:"+"}},"trapezoid-alt":{unicode:{tl:"┌",tr:"┐",bl:"\\",br:"/"},ascii:{tl:"+",tr:"+",bl:"\\",br:"/"}},"state-start":{unicode:{tl:"●",tr:"●",bl:"●",br:"●"},ascii:{tl:"*",tr:"*",bl:"*",br:"*"}},"state-end":{unicode:{tl:"◉",tr:"◉",bl:"◉",br:"◉"},ascii:{tl:"@",tr:"@",bl:"@",br:"@"}}};function jt(t,e){const n=xn[t]??xn.rectangle;return e?n.ascii:n.unicode}function Ft(t,e){const n=pt(t),s=Math.max(...n.map(c=>c.length),0),r=n.length,o=2*e.padding+s,i=o+2,a=r+2*e.padding,l=a%2===0?a+1:a,h=l+2;return{width:i,height:h,labelArea:{x:1+e.padding,y:1+e.padding,width:s,height:r},gridColumns:[1,o,1],gridRows:[1,l,1]}}function Jt(t,e,n,s){const{width:r,height:o}=e,i=wt(r-1,o-1),a={x:0,y:0},l={x:r-1,y:o-1},h=s?"-":"─",c=s?"|":"│";for(let p=a.x+1;p<l.x;p++)i[p][a.y]=h,i[p][l.y]=h;for(let p=a.y+1;p<l.y;p++)i[a.x][p]=c,i[l.x][p]=c;i[a.x][a.y]=n.tl,i[l.x][a.y]=n.tr,i[a.x][l.y]=n.bl,i[l.x][l.y]=n.br;const d=pt(t),f=r-1,u=o-1,x=Math.floor(u/2)-Math.floor((d.length-1)/2);for(let p=0;p<d.length;p++){const M=d[p],D=Math.floor(f/2)-Math.ceil(M.length/2)+1;for(let A=0;A<M.length;A++){const C=D+A,w=x+p;C>=0&&C<i.length&&w>=0&&w<i[0].length&&(i[C][w]=M[A])}}return i}function Dt(t,e,n){const{width:s,height:r}=e,o=n.x+Math.floor(s/2),i=n.y+Math.floor(r/2);return b(t,nt)?{x:o,y:n.y}:b(t,U)?{x:o,y:n.y+r-1}:b(t,ot)?{x:n.x,y:i}:b(t,Q)?{x:n.x+s-1,y:i}:b(t,Yt)?{x:n.x,y:n.y}:b(t,Xt)?{x:n.x+s-1,y:n.y}:b(t,_t)?{x:n.x,y:n.y+r-1}:b(t,Bt)?{x:n.x+s-1,y:n.y+r-1}:{x:o,y:i}}var jn={getDimensions:Ft,render(t,e,n){const s=jt("rectangle",n.useAscii);return Jt(t,e,s,n.useAscii)},getAttachmentPoint:Dt},Ls={getDimensions:Ft,render(t,e,n){const s=jt("diamond",n.useAscii);return Jt(t,e,s,n.useAscii)},getAttachmentPoint:Dt},As={getDimensions:Ft,render(t,e,n){const s=jt("circle",n.useAscii);return Jt(t,e,s,n.useAscii)},getAttachmentPoint:Dt},Cs={getDimensions(t,e){return{width:5,height:3,labelArea:{x:2,y:1,width:1,height:1},gridColumns:[1,3,1],gridRows:[1,1,1]}},render(t,e,n){const{width:s,height:r}=e,o=wt(s-1,r-1),i=Math.floor(s/2);return n.useAscii?(o[0][0]=".",o[1][0]="-",o[2][0]="-",o[3][0]="-",o[4][0]=".",o[0][1]="|",o[i][1]="*",o[4][1]="|",o[0][2]="'",o[1][2]="-",o[2][2]="-",o[3][2]="-",o[4][2]="'"):(o[0][0]="╭",o[1][0]="─",o[2][0]="─",o[3][0]="─",o[4][0]="╮",o[0][1]="│",o[i][1]="●",o[4][1]="│",o[0][2]="╰",o[1][2]="─",o[2][2]="─",o[3][2]="─",o[4][2]="╯"),o},getAttachmentPoint(t,e,n){const{width:s,height:r}=e,o=n.x+Math.floor(s/2),i=n.y+Math.floor(r/2);return b(t,nt)?{x:o,y:n.y}:b(t,U)?{x:o,y:n.y+r-1}:b(t,ot)?{x:n.x,y:i}:b(t,Q)?{x:n.x+s-1,y:i}:{x:o,y:i}}},Ts={getDimensions(t,e){return{width:5,height:3,labelArea:{x:2,y:1,width:1,height:1},gridColumns:[1,3,1],gridRows:[1,1,1]}},render(t,e,n){const{width:s,height:r}=e,o=wt(s-1,r-1),i=Math.floor(s/2);return n.useAscii?(o[0][0]="#",o[1][0]="=",o[2][0]="=",o[3][0]="=",o[4][0]="#",o[0][1]="#",o[i][1]="*",o[4][1]="#",o[0][2]="#",o[1][2]="=",o[2][2]="=",o[3][2]="=",o[4][2]="#"):(o[0][0]="╔",o[1][0]="═",o[2][0]="═",o[3][0]="═",o[4][0]="╗",o[0][1]="║",o[i][1]="◎",o[4][1]="║",o[0][2]="╚",o[1][2]="═",o[2][2]="═",o[3][2]="═",o[4][2]="╝"),o},getAttachmentPoint(t,e,n){const{width:s,height:r}=e,o=n.x+Math.floor(s/2),i=n.y+Math.floor(r/2);return b(t,nt)?{x:o,y:n.y}:b(t,U)?{x:o,y:n.y+r-1}:b(t,ot)?{x:n.x,y:i}:b(t,Q)?{x:n.x+s-1,y:i}:{x:o,y:i}}},Is={getDimensions:Ft,render(t,e,n){const s=jt("rounded",n.useAscii);return Jt(t,e,s,n.useAscii)},getAttachmentPoint:Dt},Rs={getDimensions(t,e){const n=pt(t),s=Math.max(...n.map(h=>h.length),0),r=n.length,o=2*e.padding+s,i=o+4,a=r+2*e.padding,l=Math.max(a+2,3);return{width:i,height:l,labelArea:{x:2+e.padding,y:1+e.padding,width:s,height:r},gridColumns:[2,o,2],gridRows:[1,a,1]}},render(t,e,n){const{width:s,height:r}=e,o=wt(s-1,r-1),i=Math.floor(r/2),a=n.useAscii?"-":"─";if(r===3)o[0][i]="(",o[s-1][i]=")";else if(n.useAscii){for(let c=0;c<r;c++)o[0][c]="(",o[s-1][c]=")";for(let c=1;c<s-1;c++)o[c][0]=a,o[c][r-1]=a}else{o[0][0]="╭";for(let c=1;c<s-1;c++)o[c][0]=a;o[s-1][0]="╮";for(let c=1;c<r-1;c++)o[0][c]="│",o[s-1][c]="│";o[0][r-1]="╰";for(let c=1;c<s-1;c++)o[c][r-1]=a;o[s-1][r-1]="╯"}const l=pt(t),h=i-Math.floor((l.length-1)/2);for(let c=0;c<l.length;c++){const d=l[c],f=Math.floor(s/2)-Math.floor(d.length/2);for(let u=0;u<d.length;u++){const g=f+u,x=h+c;g>0&&g<s-1&&x>=0&&x<r&&(o[g][x]=d[u])}}return o},getAttachmentPoint:Dt},Hs={getDimensions:Ft,render(t,e,n){const s=jt("hexagon",n.useAscii);return Jt(t,e,s,n.useAscii)},getAttachmentPoint:Dt},Ws={getDimensions(t,e){const n=pt(t),s=Math.max(...n.map(h=>h.length),0),r=n.length,o=2*e.padding+s,i=o+4,a=r+2*e.padding,l=a+2;return{width:i,height:l,labelArea:{x:2+e.padding,y:1+e.padding,width:s,height:r},gridColumns:[2,o,2],gridRows:[1,a,1]}},render(t,e,n){const{width:s,height:r}=e,o=wt(s-1,r-1),i=n.useAscii?"-":"─",a=n.useAscii?"|":"│";o[0][0]=n.useAscii?"+":"┌",o[1][0]=n.useAscii?"+":"┬";for(let d=2;d<s-2;d++)o[d][0]=i;o[s-2][0]=n.useAscii?"+":"┬",o[s-1][0]=n.useAscii?"+":"┐";for(let d=1;d<r-1;d++)o[0][d]=a,o[1][d]=a,o[s-2][d]=a,o[s-1][d]=a;o[0][r-1]=n.useAscii?"+":"└",o[1][r-1]=n.useAscii?"+":"┴";for(let d=2;d<s-2;d++)o[d][r-1]=i;o[s-2][r-1]=n.useAscii?"+":"┴",o[s-1][r-1]=n.useAscii?"+":"┘";const l=pt(t),c=Math.floor(r/2)-Math.floor((l.length-1)/2);for(let d=0;d<l.length;d++){const f=l[d],u=Math.floor(s/2)-Math.floor(f.length/2);for(let g=0;g<f.length;g++){const x=u+g,p=c+d;x>1&&x<s-2&&p>0&&p<r-1&&(o[x][p]=f[g])}}return o},getAttachmentPoint:Dt},Ys={getDimensions:Ft,render(t,e,n){const s=jt("doublecircle",n.useAscii);return Jt(t,e,s,n.useAscii)},getAttachmentPoint:Dt},Ds={getDimensions(t,e){const n=pt(t),s=Math.max(...n.map(h=>h.length),0),r=n.length,o=2*e.padding+s,i=o+2,a=r+2*e.padding+2,l=a+2;return{width:i,height:l,labelArea:{x:1+e.padding,y:2+e.padding,width:s,height:r},gridColumns:[1,o,1],gridRows:[2,a-2,2]}},render(t,e,n){const{width:s,height:r}=e,o=wt(s-1,r-1),i=n.useAscii?"-":"─",a=n.useAscii?"|":"│";o[0][0]=n.useAscii?".":"╭";for(let d=1;d<s-1;d++)o[d][0]=i;o[s-1][0]=n.useAscii?".":"╮",o[0][1]=a;for(let d=1;d<s-1;d++)o[d][1]=i;o[s-1][1]=a;for(let d=2;d<r-2;d++)o[0][d]=a,o[s-1][d]=a;o[0][r-2]=a;for(let d=1;d<s-1;d++)o[d][r-2]=i;o[s-1][r-2]=a,o[0][r-1]=n.useAscii?"'":"╰";for(let d=1;d<s-1;d++)o[d][r-1]=i;o[s-1][r-1]=n.useAscii?"'":"╯";const l=pt(t),c=Math.floor(r/2)-Math.floor((l.length-1)/2);for(let d=0;d<l.length;d++){const f=l[d],u=Math.floor(s/2)-Math.floor(f.length/2);for(let g=0;g<f.length;g++){const x=u+g,p=c+d;x>0&&x<s-1&&p>1&&p<r-2&&(o[x][p]=f[g])}}return o},getAttachmentPoint:Dt},Es={getDimensions:Ft,render(t,e,n){const s=jt("asymmetric",n.useAscii);return Jt(t,e,s,n.useAscii)},getAttachmentPoint:Dt},Xs={getDimensions:Ft,render(t,e,n){const s=jt("trapezoid",n.useAscii);return Jt(t,e,s,n.useAscii)},getAttachmentPoint:Dt},_s={getDimensions:Ft,render(t,e,n){const s=jt("trapezoid-alt",n.useAscii);return Jt(t,e,s,n.useAscii)},getAttachmentPoint:Dt},Ps=new Map([["rectangle",jn],["rounded",Is],["diamond",Ls],["stadium",Rs],["circle",As],["subroutine",Ws],["doublecircle",Ys],["hexagon",Hs],["cylinder",Ds],["asymmetric",Es],["trapezoid",Xs],["trapezoid-alt",_s],["state-start",Cs],["state-end",Ts]]);function Gn(t){return Ps.get(t)??jn}function zs(t,e,n){return Gn(t).getDimensions(e,n)}function Bs(t,e,n,s){return Gn(t).getAttachmentPoint(e,n,s)}function Ns(t,e){return js(t,e)}function js(t,e){const n=t.gridCoord,s=e.config.useAscii;let r=0;for(let A=0;A<2;A++)r+=e.columnWidth.get(n.x+A)??0;let o=0;for(let A=0;A<2;A++)o+=e.rowHeight.get(n.y+A)??0;const i={x:0,y:0},a={x:r,y:o},l=wt(Math.max(i.x,a.x),Math.max(i.y,a.y)),h=jt(t.shape,s),c=t.shape==="state-end",d=s?c?"=":"-":c?"═":"─",f=s?c?"‖":"|":c?"║":"│",g=c?s?{tl:"#",tr:"#",bl:"#",br:"#"}:{tl:"╔",tr:"╗",bl:"╚",br:"╝"}:h;for(let A=i.x+1;A<a.x;A++)l[A][i.y]=d;for(let A=i.x+1;A<a.x;A++)l[A][a.y]=d;for(let A=i.y+1;A<a.y;A++)l[i.x][A]=f;for(let A=i.y+1;A<a.y;A++)l[a.x][A]=f;l[i.x][i.y]=g.tl,l[a.x][i.y]=g.tr,l[i.x][a.y]=g.bl,l[a.x][a.y]=g.br;const x=t.displayLabel,p=pt(x),D=i.y+Math.floor(o/2)-Math.floor((p.length-1)/2);for(let A=0;A<p.length;A++){const C=p[A],w=i.x+Math.floor(r/2)-Math.ceil(C.length/2)+1;for(let O=0;O<C.length;O++)w+O>=0&&w+O<l.length&&D+A>=0&&D+A<l[0].length&&(l[w+O][D+A]=C[O])}return l}function Gs(t,e){return Ns(t,e)}function On(t,e,n=1){let s=0;for(const A of t)for(const C of A)s=Math.max(s,C.length);const o=s+2*n+2;let i=0;for(const A of t)i+=Math.max(A.length,1);const a=t.length-1,l=i+a+2,h=e?"-":"─",c=e?"|":"│",d=e?"+":"┌",f=e?"+":"┐",u=e?"+":"└",g=e?"+":"┘",x=e?"+":"├",p=e?"+":"┤",M=wt(o-1,l-1);M[0][0]=d;for(let A=1;A<o-1;A++)M[A][0]=h;M[o-1][0]=f,M[0][l-1]=u;for(let A=1;A<o-1;A++)M[A][l-1]=h;M[o-1][l-1]=g;for(let A=1;A<l-1;A++)M[0][A]=c,M[o-1][A]=c;let D=1;for(let A=0;A<t.length;A++){const C=t[A],w=C.length>0?C:[""];for(const O of w){const st=1+n;for(let y=0;y<O.length;y++)M[st+y][D]=O[y];D++}if(A<t.length-1){M[0][D]=x;for(let O=1;O<o-1;O++)M[O][D]=h;M[o-1][D]=p,D++}}return M}var Os={solid:{h:{unicode:"─",ascii:"-"},v:{unicode:"│",ascii:"|"}},dotted:{h:{unicode:"┄",ascii:"."},v:{unicode:"┆",ascii:":"}},thick:{h:{unicode:"━",ascii:"="},v:{unicode:"┃",ascii:"‖"}}};function Ke(t,e,n,s,r,o,i="solid"){const a=Tt(e,n),l=[],h=Os[i],c=o?h.h.ascii:h.h.unicode,d=o?h.v.ascii:h.v.unicode;if(b(a,nt))for(let f=e.y-s;f>=n.y-r;f--)l.push({x:e.x,y:f}),t[e.x][f]=d;else if(b(a,U))for(let f=e.y+s;f<=n.y+r;f++)l.push({x:e.x,y:f}),t[e.x][f]=d;else if(b(a,ot))for(let f=e.x-s;f>=n.x-r;f--)l.push({x:f,y:e.y}),t[f][e.y]=c;else if(b(a,Q))for(let f=e.x+s;f<=n.x+r;f++)l.push({x:f,y:e.y}),t[f][e.y]=c;else if(b(a,Yt)){for(let f=e.x-s;f>=n.x;f--)l.push({x:f,y:e.y}),t[f][e.y]=c;for(let f=e.y-1;f>=n.y-r;f--)l.push({x:n.x,y:f}),t[n.x][f]=d}else if(b(a,Xt)){for(let f=e.x+s;f<=n.x;f++)l.push({x:f,y:e.y}),t[f][e.y]=c;for(let f=e.y-1;f>=n.y-r;f--)l.push({x:n.x,y:f}),t[n.x][f]=d}else if(b(a,_t)){for(let f=e.x-s;f>=n.x;f--)l.push({x:f,y:e.y}),t[f][e.y]=c;for(let f=e.y+1;f<=n.y+r;f++)l.push({x:n.x,y:f}),t[n.x][f]=d}else if(b(a,Bt))if(n.x-e.x<=1)for(let u=e.y+s;u<=n.y+r;u++)l.push({x:e.x,y:u}),t[e.x][u]=d;else{for(let u=e.x+s;u<=n.x;u++)l.push({x:u,y:e.y}),t[u][e.y]=c;for(let u=e.y+1;u<=n.y+r;u++)l.push({x:n.x,y:u}),t[n.x][u]=d}return l}function Fs(t,e){if(e.path.length===0){const c=Mt(t.canvas);return[c,c,c,c,c,c]}const n=Ks(t,e),[s,r,o]=Vs(t,e.path,e.style),i=qs(t,e.path,r[0],e.from.shape);let a;e.hasArrowEnd?a=yn(t,r[r.length-1],o[o.length-1]):a=Mt(t.canvas);let l;if(e.hasArrowStart&&r.length>0){const d=r[0][0],f=Js(o[0]),u={x:d.x,y:d.y};b(o[0],Q)?u.x=d.x-1:b(o[0],ot)?u.x=d.x+1:b(o[0],U)?u.y=d.y-1:b(o[0],nt)&&(u.y=d.y+1),l=yn(t,[d,u],f)}else l=Mt(t.canvas);const h=Us(t,e.path);return[s,i,a,l,h,n]}function Js(t){return b(t,nt)?U:b(t,U)?nt:b(t,ot)?Q:b(t,Q)?ot:b(t,Yt)?Bt:b(t,Xt)?_t:b(t,_t)?Xt:b(t,Bt)?Yt:ne}function Vs(t,e,n="solid"){const s=Mt(t.canvas);let r=e[0];const o=[],i=[];for(let a=1;a<e.length;a++){const l=e[a],h=Nt(t,r),c=Nt(t,l);if(qe(h,c)){r=l;continue}const d=Tt(r,l),f=Ke(s,h,c,1,-1,t.config.useAscii,n);f.length===0&&f.push(h),o.push(f),i.push(d),r=l}return[s,o,i]}function qs(t,e,n,s){const r=Mt(t.canvas);if(t.config.useAscii||s==="state-start"||s==="state-end")return r;const o=n[0],i=Tt(e[0],e[1]);return b(i,nt)?r[o.x][o.y+1]="┴":b(i,U)?r[o.x][o.y-1]="┬":b(i,ot)?r[o.x+1][o.y]="┤":b(i,Q)&&(r[o.x-1][o.y]="├"),r}function yn(t,e,n){const s=Mt(t.canvas);if(e.length===0)return s;const r=e[0],o=e[e.length-1];let i=Tt(r,o);(e.length===1||b(i,ne))&&(i=n);let a;return t.config.useAscii?b(i,nt)?a="^":b(i,U)?a="v":b(i,ot)?a="<":b(i,Q)?a=">":b(n,nt)?a="^":b(n,U)?a="v":b(n,ot)?a="<":b(n,Q)?a=">":a="*":b(i,nt)?a="▲":b(i,U)?a="▼":b(i,ot)?a="◄":b(i,Q)?a="►":b(i,Xt)?a="◥":b(i,Yt)?a="◤":b(i,Bt)?a="◢":b(i,_t)?a="◣":b(n,nt)?a="▲":b(n,U)?a="▼":b(n,ot)?a="◄":b(n,Q)?a="►":b(n,Xt)?a="◥":b(n,Yt)?a="◤":b(n,Bt)?a="◢":b(n,_t)?a="◣":a="●",s[o.x][o.y]=a,s}function Us(t,e){const n=Mt(t.canvas);for(let s=1;s<e.length-1;s++){const r=e[s],o=Nt(t,r),i=Tt(e[s-1],r),a=Tt(r,e[s+1]);let l;t.config.useAscii?l="+":b(i,Q)&&b(a,U)||b(i,nt)&&b(a,ot)?l="┐":b(i,Q)&&b(a,nt)||b(i,U)&&b(a,ot)?l="┘":b(i,ot)&&b(a,U)||b(i,nt)&&b(a,Q)?l="┌":b(i,ot)&&b(a,nt)||b(i,U)&&b(a,Q)?l="└":l="+",n[o.x][o.y]=l}return n}function Ks(t,e){const n=Mt(t.canvas);if(e.text.length===0)return n;const s=cr(t,e.labelLine);let r;if(e.path.length>=2){const o=e.path[0].y,i=e.path[e.path.length-1].y;i<o?r=!0:i>o&&(r=!1)}return Qs(n,s,e.text,r),n}function Qs(t,e,n,s){if(e.length<2)return;const r=Math.min(e[0].x,e[1].x),o=Math.max(e[0].x,e[1].x),i=Math.min(e[0].y,e[1].y),a=Math.max(e[0].y,e[1].y),l=r+Math.floor((o-r)/2);let h=i+Math.floor((a-i)/2);if(s!==void 0&&r===o){const f=a-i,u=Math.max(1,Math.floor(f/4));s?h=h+u:h=h-u}const c=pt(n),d=h-Math.floor((c.length-1)/2);for(let f=0;f<c.length;f++){const u=c[f],g=l-Math.floor(u.length/2);as(t,{x:g,y:d+f},u)}}function le(t,e,n){const s=e.gridCoord;let r=0;for(let l=0;l<2;l++)r+=t.columnWidth.get(s.x+l)??0;let o=0;for(let l=0;l<2;l++)o+=t.rowHeight.get(s.y+l)??0;const i={width:r+1,height:o+1,labelArea:{x:0,y:0,width:0,height:0},gridColumns:[0,0,0],gridRows:[0,0,0]},a=e.drawingCoord;return Bs(e.shape,n,i,a)}function Zs(t,e,n){const s=Mt(t.canvas);if(!e.pathToJunction||e.pathToJunction.length===0)return[s,s,s,s,s,s];const r=Mt(t.canvas),o=t.config.useAscii,i=e.pathToJunction.map((c,d)=>n.type==="fan-in"&&d===0?le(t,e.from,e.startDir):n.type==="fan-out"&&d===e.pathToJunction.length-1?le(t,e.to,e.endDir):Nt(t,c));for(let c=1;c<i.length;c++){const d=i[c-1],f=i[c];qe(d,f)||Ke(r,d,f,1,-1,o,e.style)}const a=Mt(t.canvas);for(let c=1;c<e.pathToJunction.length-1;c++){const d=e.pathToJunction[c],f=Nt(t,d),u=Tt(e.pathToJunction[c-1],d),g=Tt(d,e.pathToJunction[c+1]);let x;o?x="+":b(u,Q)&&b(g,U)||b(u,nt)&&b(g,ot)?x="┐":b(u,Q)&&b(g,nt)||b(u,U)&&b(g,ot)?x="┘":b(u,ot)&&b(g,U)||b(u,nt)&&b(g,Q)?x="┌":b(u,ot)&&b(g,nt)||b(u,U)&&b(g,Q)?x="└":x="+",a[f.x][f.y]=x}const l=Mt(t.canvas);if(n.type==="fan-in"&&e.pathToJunction.length>=2){const c=i[0],d=Tt(e.pathToJunction[0],e.pathToJunction[1]);o||(b(d,nt)?l[c.x][c.y]="┴":b(d,U)?l[c.x][c.y]="┬":b(d,ot)?l[c.x][c.y]="┤":b(d,Q)&&(l[c.x][c.y]="├"))}const h=Mt(t.canvas);return[r,l,s,s,a,h]}function tr(t,e){const n=Mt(t.canvas),s=Mt(t.canvas);if(e.sharedPath.length<2)return[n,s];const r=t.config.useAscii,o=e.edges[0]?.style??"solid",i=t.config.graphDirection,a=e.sharedPath.map((l,h)=>{if(e.type==="fan-in"&&h===e.sharedPath.length-1){const c=i==="TD"?nt:ot;return le(t,e.sharedNode,c)}if(e.type==="fan-out"&&h===0){const c=i==="TD"?U:Q;return le(t,e.sharedNode,c)}return Nt(t,l)});for(let l=1;l<a.length;l++){const h=a[l-1],c=a[l];qe(h,c)||Ke(n,h,c,1,-1,r,o)}for(let l=1;l<e.sharedPath.length-1;l++){const h=e.sharedPath[l],c=Nt(t,h),d=Tt(e.sharedPath[l-1],h),f=Tt(h,e.sharedPath[l+1]);let u;r?u="+":b(d,Q)&&b(f,U)||b(d,nt)&&b(f,ot)?u="┐":b(d,Q)&&b(f,nt)||b(d,U)&&b(f,ot)?u="┘":b(d,ot)&&b(f,U)||b(d,nt)&&b(f,Q)?u="┌":b(d,ot)&&b(f,nt)||b(d,U)&&b(f,Q)?u="└":u="+",s[c.x][c.y]=u}return[n,s]}function er(t,e){const n=Mt(t.canvas);if(e.sharedPath.length<2)return n;const s=e.sharedPath.length-1,r=e.sharedPath[s-1],o=e.sharedPath[s],i=Tt(r,o),a=t.config.graphDirection,l=a==="TD"?nt:ot,h=le(t,e.sharedNode,l);a==="TD"?h.y-=1:h.x-=1;let c;return t.config.useAscii?b(i,nt)?c="^":b(i,U)?c="v":b(i,ot)?c="<":b(i,Q)?c=">":c="v":b(i,nt)?c="▲":b(i,U)?c="▼":b(i,ot)?c="◄":b(i,Q)?c="►":c="▼",n[h.x][h.y]=c,n}function nr(t,e){const n=Mt(t.canvas);if(!e.pathToJunction||e.pathToJunction.length<2)return n;const s=e.pathToJunction.length-1,r=e.pathToJunction[s-1],o=e.pathToJunction[s],i=Tt(r,o),a=t.config.graphDirection,l=a==="TD"?nt:ot,h=le(t,e.to,l);a==="TD"?h.y-=1:h.x-=1;let c;return t.config.useAscii?b(i,nt)?c="^":b(i,U)?c="v":b(i,ot)?c="<":b(i,Q)?c=">":c="v":b(i,nt)?c="▲":b(i,U)?c="▼":b(i,ot)?c="◄":b(i,Q)?c="►":c="▼",n[h.x][h.y]=c,n}function or(t,e){const n=Mt(t.canvas);if(!e.junctionPoint)return n;const s=Nt(t,e.junctionPoint),r=t.config.useAscii;let o=!1,i=!1,a=!1,l=!1;if(e.sharedPath.length>=2){const c=e.type==="fan-in"?0:e.sharedPath.length-1,d=e.type==="fan-in"?1:e.sharedPath.length-2,f=Tt(e.sharedPath[c],e.sharedPath[d]);b(f,U)?i=!0:b(f,nt)?o=!0:b(f,Q)?l=!0:b(f,ot)&&(a=!0)}for(const c of e.edges)if(c.pathToJunction&&c.pathToJunction.length>=2){const d=e.type==="fan-in"?c.pathToJunction.length-1:0,f=e.type==="fan-in"?c.pathToJunction.length-2:1,u=Tt(c.pathToJunction[f],c.pathToJunction[d]);b(u,U)?o=!0:b(u,nt)?i=!0:b(u,Q)?a=!0:b(u,ot)&&(l=!0)}let h;return r?h="+":o&&i&&a&&l?h="┼":i&&a&&l&&!o?h="┬":o&&a&&l&&!i?h="┴":o&&i&&l&&!a?h="├":o&&i&&a&&!l?h="┤":a&&l?h="─":o&&i?h="│":i&&l?h="┌":i&&a?h="┐":o&&l?h="└":o&&a?h="┘":h="┼",n[s.x][s.y]=h,n}function sr(t,e){const n=t.maxX-t.minX,s=t.maxY-t.minY;if(n<=0||s<=0)return wt(0,0);const r={x:0,y:0},o={x:n,y:s},i=wt(n,s);if(e.config.useAscii){for(let a=r.x+1;a<o.x;a++)i[a][r.y]="-";for(let a=r.x+1;a<o.x;a++)i[a][o.y]="-";for(let a=r.y+1;a<o.y;a++)i[r.x][a]="|";for(let a=r.y+1;a<o.y;a++)i[o.x][a]="|";i[r.x][r.y]="+",i[o.x][r.y]="+",i[r.x][o.y]="+",i[o.x][o.y]="+"}else{for(let a=r.x+1;a<o.x;a++)i[a][r.y]="─";for(let a=r.x+1;a<o.x;a++)i[a][o.y]="─";for(let a=r.y+1;a<o.y;a++)i[r.x][a]="│";for(let a=r.y+1;a<o.y;a++)i[o.x][a]="│";i[r.x][r.y]="┌",i[o.x][r.y]="┐",i[r.x][o.y]="└",i[o.x][o.y]="┘"}return i}function rr(t,e){const n=t.maxX-t.minX,s=t.maxY-t.minY;if(n<=0||s<=0)return[wt(0,0),{x:0,y:0}];const r=wt(n,s),o=pt(t.name);for(let i=0;i<o.length;i++){const a=o[i],l=1+i;let h=Math.floor(n/2)-Math.floor(a.length/2);h<1&&(h=1);for(let c=0;c<a.length;c++)h+c<n&&l<s&&(r[h+c][l]=a[c])}return[r,{x:t.minX,y:t.minY}]}function ir(t){function e(s){return s.parent===null?0:1+e(s.parent)}const n=[...t];return n.sort((s,r)=>e(s)-e(r)),n}function Fe(t,e,n,s){for(let r=0;r<e.length;r++)for(let o=0;o<(e[0]?.length??0);o++){const i=e[r]?.[o];if(i&&i!==" "){const a=r+n.x,l=o+n.y;a>=0&&l>=0&&we(t,a,l,s)}}}function ee(t,e,n,s){for(const r of e)Fe(t,r,n,s)}function ar(t,e,n){const s=r=>/^[┌┐└┘├┤┬┴┼│─╭╮╰╯+\-|.':]$/.test(r);for(let r=0;r<e.length;r++)for(let o=0;o<(e[0]?.length??0);o++){const i=e[r]?.[o];if(i&&i!==" "){const a=r+n.x,l=o+n.y;a>=0&&l>=0&&we(t,a,l,s(i)?"border":"text")}}}function lr(t){const e=t.config.useAscii,n={x:0,y:0},s=ir(t.subgraphs);for(const f of s){const u=sr(f,t),g={x:f.minX,y:f.minY};t.canvas=zt(t.canvas,g,e,u),Fe(t.roleCanvas,u,g,"border")}for(const f of t.nodes)!f.drawn&&f.drawingCoord&&f.drawing&&(t.canvas=zt(t.canvas,f.drawingCoord,e,f.drawing),ar(t.roleCanvas,f.drawing,f.drawingCoord),f.drawn=!0);const r=[],o=[],i=[],a=[],l=[],h=[],c=[],d=new Set;for(const f of t.edges)if(f.bundle&&f.pathToJunction){const u=f.bundle,[g,x,,,p,M]=Zs(t,f,u);if(r.push(g),o.push(p),l.push(x),h.push(M),!d.has(u)){d.add(u);const[D,A]=tr(t,u);if(r.push(D),o.push(A),u.type==="fan-in"){const w=er(t,u);i.push(w)}const C=or(t,u);c.push(C)}if(u.type==="fan-out"&&f.hasArrowEnd){const D=nr(t,f);i.push(D)}}else{const[u,g,x,p,M,D]=Fs(t,f);r.push(u),o.push(M),i.push(x),a.push(p),l.push(g),h.push(D)}t.canvas=zt(t.canvas,n,e,...r),ee(t.roleCanvas,r,n,"line"),t.canvas=zt(t.canvas,n,e,...o),ee(t.roleCanvas,o,n,"corner"),t.canvas=zt(t.canvas,n,e,...c),ee(t.roleCanvas,c,n,"junction"),t.canvas=zt(t.canvas,n,e,...i),ee(t.roleCanvas,i,n,"arrow"),t.canvas=zt(t.canvas,n,e,...l),ee(t.roleCanvas,l,n,"junction"),t.canvas=zt(t.canvas,n,e,...a),ee(t.roleCanvas,a,n,"arrow"),t.canvas=zt(t.canvas,n,e,...h),ee(t.roleCanvas,h,n,"text");for(const f of t.subgraphs){if(f.nodes.length===0)continue;const[u,g]=rr(f);t.canvas=zt(t.canvas,g,e,u),Fe(t.roleCanvas,u,g,"text")}return t.canvas}function Nt(t,e,n){const s=e;let r=0;for(let l=0;l<s.x;l++)r+=t.columnWidth.get(l)??0;let o=0;for(let l=0;l<s.y;l++)o+=t.rowHeight.get(l)??0;const i=t.columnWidth.get(s.x)??0,a=t.rowHeight.get(s.y)??0;return{x:r+Math.floor(i/2)+t.offsetX,y:o+Math.floor(a/2)+t.offsetY}}function cr(t,e){return e.map(n=>Nt(t,n))}function ge(t,e,n,s){const r=s??dr(t,e);if(t.grid.has(Ut(n)))return r==="LR"?ge(t,e,{x:n.x,y:n.y+4},r):ge(t,e,{x:n.x+4,y:n.y},r);for(let o=0;o<3;o++)for(let i=0;i<3;i++){const a={x:n.x+o,y:n.y+i};t.grid.set(Ut(a),e)}return e.gridCoord=n,n}function hr(t,e){const n=e.gridCoord,s=t.config.boxBorderPadding,r=zs(e.shape,e.displayLabel,{useAscii:t.config.useAscii,padding:s}),o=r.gridColumns,i=r.gridRows;for(let a=0;a<o.length;a++){const l=n.x+a,h=t.columnWidth.get(l)??0;t.columnWidth.set(l,Math.max(h,o[a]))}for(let a=0;a<i.length;a++){const l=n.y+a,h=t.rowHeight.get(l)??0;t.rowHeight.set(l,Math.max(h,i[a]))}if(n.x>0){const a=t.columnWidth.get(n.x-1)??0;t.columnWidth.set(n.x-1,Math.max(a,t.config.paddingX))}if(n.y>0){let a=t.config.paddingY;ur(t,e)&&(a+=4);const l=t.rowHeight.get(n.y-1)??0;t.rowHeight.set(n.y-1,Math.max(l,a))}}function pn(t,e){for(const n of e)t.columnWidth.has(n.x)||t.columnWidth.set(n.x,Math.floor(t.config.paddingX/2)),t.rowHeight.has(n.y)||t.rowHeight.set(n.y,Math.floor(t.config.paddingY/2))}function ze(t,e){return t.subgraphs.some(n=>n.nodes.includes(e))}function Rt(t,e){let n=null;for(const s of t.subgraphs)s.nodes.includes(e)&&(!n||fr(n,s))&&(n=s);return n}function fr(t,e){let n=e;for(;n!==null;){if(n===t)return!0;n=n.parent}return!1}function dr(t,e){const n=Rt(t,e);return n?.direction?n.direction:t.config.graphDirection}function ur(t,e){const n=Rt(t,e);if(!n)return!1;let s=!1;for(const r of t.edges)if(r.to===e&&Rt(t,r.from)!==n){s=!0;break}if(!s)return!1;for(const r of n.nodes){if(r===e||!r.gridCoord)continue;let o=!1;for(const i of t.edges)if(i.to===r&&Rt(t,i.from)!==n){o=!0;break}if(o&&r.gridCoord.y<e.gridCoord.y)return!1}return!0}function Fn(t,e){if(e.nodes.length===0)return;let n=1e6,s=1e6,r=-1e6,o=-1e6;for(const l of e.children)Fn(t,l),l.nodes.length>0&&(n=Math.min(n,l.minX),s=Math.min(s,l.minY),r=Math.max(r,l.maxX),o=Math.max(o,l.maxY));for(const l of e.nodes){if(!l.drawingCoord||!l.drawing)continue;const h=l.drawingCoord.x,c=l.drawingCoord.y,d=h+l.drawing.length-1,f=c+l.drawing[0].length-1;n=Math.min(n,h),s=Math.min(s,c),r=Math.max(r,d),o=Math.max(o,f)}const i=2,a=2;e.minX=n-i,e.minY=s-i-a,e.maxX=r+i,e.maxY=o+i}function gr(t){const n=t.subgraphs.filter(s=>s.parent===null&&s.nodes.length>0);for(let s=0;s<n.length;s++)for(let r=s+1;r<n.length;r++){const o=n[s],i=n[r];o.minX<i.maxX&&o.maxX>i.minX&&(o.maxY>=i.minY-1&&o.minY<i.minY?i.minY=o.maxY+1+1:i.maxY>=o.minY-1&&i.minY<o.minY&&(o.minY=i.maxY+1+1)),o.minY<i.maxY&&o.maxY>i.minY&&(o.maxX>=i.minX-1&&o.minX<i.minX?i.minX=o.maxX+1+1:i.maxX>=o.minX-1&&i.minX<o.minX&&(o.minX=i.maxX+1+1))}}function xr(t){for(const e of t.subgraphs)Fn(t,e);gr(t)}function yr(t){if(t.subgraphs.length===0)return;let e=0,n=0;for(const o of t.subgraphs)e=Math.min(e,o.minX),n=Math.min(n,o.minY);const s=-e,r=-n;if(!(s===0&&r===0)){t.offsetX=s,t.offsetY=r;for(const o of t.subgraphs)o.minX+=s,o.minY+=r,o.maxX+=s,o.maxY+=r;for(const o of t.nodes)o.drawingCoord&&(o.drawingCoord.x+=s,o.drawingCoord.y+=r)}}function pr(t){const e=t.config.graphDirection,n=new Array(100).fill(0),s=new Set,r=[];for(const f of t.nodes){s.has(f.name)||r.push(f),s.add(f.name);for(const u of Be(t,f))s.add(u.name)}const o=r.filter(f=>{const u=Rt(t,f);if(!u)return!0;for(const g of t.edges)if(g.to===f&&Rt(t,g.from)!==u)return!1;return!0});let i=!1,a=!1;for(const f of o)ze(t,f)?Be(t,f).length>0&&(a=!0):i=!0;const l=e==="LR"&&i&&a;let h,c=[];l?(h=o.filter(f=>!ze(t,f)),c=o.filter(f=>ze(t,f))):h=o;for(const f of h){const u=e==="LR"?{x:0,y:n[0]}:{x:n[0],y:0};ge(t,t.nodes[f.index],u),n[0]=n[0]+4}if(l&&c.length>0)for(const u of c){const g=e==="LR"?{x:4,y:n[4]}:{x:n[4],y:4};ge(t,t.nodes[u.index],g),n[4]=n[4]+4}let d=h.length+c.length;for(;d<t.nodes.length;){const f=d;for(const u of t.nodes){if(u.gridCoord===null)continue;const g=u.gridCoord;for(const x of Be(t,u)){if(x.gridCoord!==null)continue;const p=Rt(t,u),M=Rt(t,x),D=p&&p===M&&p.direction?p.direction:t.config.graphDirection,A=D==="LR"?g.x+4:g.y+4;let C;D!==t.config.graphDirection?C=D==="LR"?g.y:g.x:C=n[A];const w=D==="LR"?{x:A,y:C}:{x:C,y:A};ge(t,t.nodes[x.index],w,D),D===t.config.graphDirection&&(n[A]=C+4),d++}}if(d===f)break}for(const f of t.nodes)hr(t,f);t.bundles=Ms(t),Ss(t);for(const f of t.edges){if(f.bundle&&f.path.length>0){pn(t,f.path),dn(t,f);continue}$s(t,f),pn(t,f.path),dn(t,f)}for(const f of t.nodes)f.drawingCoord=Nt(t,f.gridCoord),f.drawing=Gs(f,t);ls(t.canvas,t.columnWidth,t.rowHeight),cs(t.roleCanvas,t.columnWidth,t.rowHeight),xr(t),yr(t)}function mr(t,e){return t.edges.filter(n=>n.from.name===e.name)}function Be(t,e){return mr(t,e).map(n=>n.to)}function Jn(t){const e={actors:[],messages:[],blocks:[],notes:[]},n=new Set,s=[];for(let r=1;r<t.length;r++){const o=t[r],i=o.match(/^(participant|actor)\s+(\S+?)(?:\s+as\s+(.+))?$/);if(i){const f=i[1],u=i[2],g=i[3]?.trim()??u,x=$t(g);n.has(u)||(n.add(u),e.actors.push({id:u,label:x,type:f}));continue}const a=o.match(/^Note\s+(left of|right of|over)\s+([^:]+):\s*(.+)$/i);if(a){const f=a[1].toLowerCase(),u=a[2].trim(),g=$t(a[3].trim()),x=u.split(",").map(M=>M.trim());for(const M of x)ce(e,n,M);let p="over";f==="left of"?p="left":f==="right of"&&(p="right"),e.notes.push({actorIds:x,text:g,position:p,afterIndex:e.messages.length-1});continue}const l=o.match(/^(loop|alt|opt|par|critical|break|rect)\s*(.*)$/);if(l){const f=l[1],u=l[2]?.trim()??"",g=$t(u);s.push({type:f,label:g,startIndex:e.messages.length,dividers:[]});continue}const h=o.match(/^(else|and)\s*(.*)$/);if(h&&s.length>0){const f=h[2]?.trim()??"",u=$t(f);s[s.length-1].dividers.push({index:e.messages.length,label:u});continue}if(o==="end"&&s.length>0){const f=s.pop();e.blocks.push({type:f.type,label:f.label,startIndex:f.startIndex,endIndex:Math.max(e.messages.length-1,f.startIndex),dividers:f.dividers});continue}const c=o.match(/^(\S+?)\s*(--?>?>|--?[)x]|--?>>|--?>)\s*([+-]?)(\S+?)\s*:\s*(.+)$/);if(c){const f=c[1],u=c[2],g=c[3],x=c[4],p=$t(c[5].trim());ce(e,n,f),ce(e,n,x);const M=u.startsWith("--")?"dashed":"solid",D=u.includes(">>")||u.includes("x")?"filled":"open",A={from:f,to:x,label:p,lineStyle:M,arrowHead:D};g==="+"&&(A.activate=!0),g==="-"&&(A.deactivate=!0),e.messages.push(A);continue}const d=o.match(/^(\S+?)\s*(->>|-->>|-\)|--\)|-x|--x|->|-->)\s*([+-]?)(\S+?)\s*:\s*(.+)$/);if(d){const f=d[1],u=d[2],g=d[3],x=d[4],p=$t(d[5].trim());ce(e,n,f),ce(e,n,x);const M=u.startsWith("--")?"dashed":"solid",D=u.includes(">>")||u.includes("x")?"filled":"open",A={from:f,to:x,label:p,lineStyle:M,arrowHead:D};g==="+"&&(A.activate=!0),g==="-"&&(A.deactivate=!0),e.messages.push(A);continue}}return e}function ce(t,e,n){e.has(n)||(e.add(n),t.actors.push({id:n,label:n,type:"participant"}))}function br(t,e,n,s){const r=t.split(`
25
- `).map($=>$.trim()).filter($=>$.length>0&&!$.startsWith("%%")),o=Jn(r);if(o.actors.length===0)return"";const i=e.useAscii,a=i?"-":"─",l=i?"|":"│",h=i?"+":"┌",c=i?"+":"┐",d=i?"+":"└",f=i?"+":"┘",u=i?"+":"┬",g=i?"+":"┴",x=i?"+":"├",p=i?"+":"┤",M=new Map;o.actors.forEach(($,I)=>M.set($.id,I));const D=1,C=o.actors.map($=>Pe($.label)+2*D+2).map($=>Math.ceil($/2)),w=o.actors.map($=>gn($.label)+2),O=Math.max(...w,3),st=new Array(Math.max(o.actors.length-1,0)).fill(0);for(const $ of o.messages){const I=M.get($.from),B=M.get($.to);if(I===B)continue;const _=Math.min(I,B),N=Math.max(I,B),W=Pe($.label)+4,it=N-_,G=Math.ceil(W/it);for(let R=_;R<N;R++)st[R]=Math.max(st[R],G)}const y=[C[0]];for(let $=1;$<o.actors.length;$++){const I=Math.max(C[$-1]+C[$]+2,st[$-1]+2,10);y[$]=y[$-1]+I}const m=[],S=[],X=new Map,v=new Map,z=new Map,F=[];let V=O;for(let $=0;$<o.messages.length;$++){for(let N=0;N<o.blocks.length;N++)o.blocks[N].startIndex===$&&(V+=2,X.set(N,V-1));for(let N=0;N<o.blocks.length;N++)for(let W=0;W<o.blocks[N].dividers.length;W++)o.blocks[N].dividers[W].index===$&&(V+=1,z.set(`${N}:${W}`,V),V+=1);V+=1;const I=o.messages[$],B=I.from===I.to,_=gn(I.label);B?(S[$]=V+1,m[$]=V,V+=2+_):(S[$]=V,m[$]=V+_,V+=_+1);for(let N=0;N<o.notes.length;N++)if(o.notes[N].afterIndex===$){V+=1;const W=o.notes[N],it=pt(W.text),G=Math.max(...it.map(q=>q.length))+4,R=it.length+2,K=M.get(W.actorIds[0])??0;let E;if(W.position==="left")E=y[K]-G-1;else if(W.position==="right")E=y[K]+2;else if(W.actorIds.length>=2){const q=M.get(W.actorIds[1])??K;E=Math.floor((y[K]+y[q])/2)-Math.floor(G/2)}else E=y[K]-Math.floor(G/2);E=Math.max(0,E),F.push({x:E,y:V,width:G,height:R,lines:it}),V+=R}for(let N=0;N<o.blocks.length;N++)o.blocks[N].endIndex===$&&(V+=1,v.set(N,V),V+=1)}V+=1;const Y=V,Z=Y+O,at=y[y.length-1]??0,tt=C[C.length-1]??0;let L=at+tt+2;for(let $=0;$<o.messages.length;$++){const I=o.messages[$];if(I.from===I.to){const B=M.get(I.from),_=y[B]+6+2+I.label.length;L=Math.max(L,_+1)}}for(const $ of F)L=Math.max(L,$.x+$.width+1);const P=wt(L,Z-1),H=$e(L,Z-1);function k($,I,B,_){$>=0&&$<P.length&&I>=0&&I<(P[0]?.length??0)&&(P[$][I]=B,we(H,$,I,_))}function j($,I,B){const _=pt(B),N=Pe(B),W=N+2*D+2,it=_.length+2,G=$-Math.floor(W/2);k(G,I,h,"border");for(let K=1;K<W-1;K++)k(G+K,I,a,"border");k(G+W-1,I,c,"border");for(let K=0;K<_.length;K++){const E=I+1+K;k(G,E,l,"border"),k(G+W-1,E,l,"border");const q=_[K],ft=G+1+D+Math.floor((N-q.length)/2);for(let lt=0;lt<q.length;lt++)k(ft+lt,E,q[lt],"text")}const R=I+it-1;k(G,R,d,"border");for(let K=1;K<W-1;K++)k(G+K,R,a,"border");k(G+W-1,R,f,"border")}for(let $=0;$<o.actors.length;$++){const I=y[$];for(let B=O;B<=Y;B++)k(I,B,l,"line")}for(let $=0;$<o.actors.length;$++){const I=o.actors[$];j(y[$],0,I.label),j(y[$],Y,I.label),i||(k(y[$],O-1,u,"junction"),k(y[$],Y,g,"junction"))}for(let $=0;$<o.messages.length;$++){const I=o.messages[$],B=M.get(I.from),_=M.get(I.to),N=y[B],W=y[_],it=B===_,G=I.lineStyle==="dashed",R=I.arrowHead==="filled",K=G?i?".":"╌":a;if(it){const E=m[$],q=Math.max(4,4);k(N,E,x,"junction");for(let ht=N+1;ht<N+q;ht++)k(ht,E,K,"line");k(N+q,E,i?"+":"┐","corner"),k(N+q,E+1,l,"line");const ft=N+q+2;for(let ht=0;ht<I.label.length;ht++)ft+ht<L&&k(ft+ht,E+1,I.label[ht],"text");const lt=R?i?"<":"◀":i?"<":"◁";k(N,E+2,lt,"arrow");for(let ht=N+1;ht<N+q;ht++)k(ht,E+2,K,"line");k(N+q,E+2,i?"+":"┘","corner")}else{const E=S[$],q=m[$],ft=N<W,lt=Math.floor((N+W)/2),ht=pt(I.label);for(let mt=0;mt<ht.length;mt++){const bt=ht[mt],Ht=lt-Math.floor(bt.length/2),Vt=E+mt;for(let Wt=0;Wt<bt.length;Wt++){const re=Ht+Wt;re>=0&&re<L&&k(re,Vt,bt[Wt],"text")}}if(ft){for(let bt=N+1;bt<W;bt++)k(bt,q,K,"line");k(W,q,R?i?">":"▶":i?">":"▷","arrow")}else{for(let bt=W+1;bt<N;bt++)k(bt,q,K,"line");k(W,q,R?i?"<":"◀":i?"<":"◁","arrow")}}}for(let $=0;$<o.blocks.length;$++){const I=o.blocks[$],B=X.get($),_=v.get($);if(B===void 0||_===void 0)continue;let N=L,W=0;for(let E=I.startIndex;E<=I.endIndex&&!(E>=o.messages.length);E++){const q=o.messages[E],ft=M.get(q.from)??0,lt=M.get(q.to)??0;N=Math.min(N,y[Math.min(ft,lt)]),W=Math.max(W,y[Math.max(ft,lt)])}const it=Math.max(0,N-4),G=Math.min(L-1,W+4);k(it,B,h,"border");for(let E=it+1;E<G;E++)k(E,B,a,"border");k(G,B,c,"border");const R=I.label?`${I.type} [${I.label}]`:I.type,K=pt(R);for(let E=0;E<K.length&&B+E<_;E++){const q=K[E];for(let ft=0;ft<q.length&&it+1+ft<G;ft++)k(it+1+ft,B+E,q[ft],"text")}k(it,_,d,"border");for(let E=it+1;E<G;E++)k(E,_,a,"border");k(G,_,f,"border");for(let E=B+1;E<_;E++)k(it,E,l,"border"),k(G,E,l,"border");for(let E=0;E<I.dividers.length;E++){const q=z.get(`${$}:${E}`);if(q===void 0)continue;const ft=et();k(it,q,x,"junction");for(let ht=it+1;ht<G;ht++)k(ht,q,ft,"line");k(G,q,p,"junction");const lt=I.dividers[E].label;if(lt){const ht=`[${lt}]`;for(let mt=0;mt<ht.length&&it+1+mt<G;mt++)k(it+1+mt,q,ht[mt],"text")}}}for(const $ of F){Zt(P,$.x+$.width,$.y+$.height),oe(H,$.x+$.width,$.y+$.height),k($.x,$.y,h,"border");for(let B=1;B<$.width-1;B++)k($.x+B,$.y,a,"border");k($.x+$.width-1,$.y,c,"border");for(let B=0;B<$.lines.length;B++){const _=$.y+1+B;k($.x,_,l,"border"),k($.x+$.width-1,_,l,"border");for(let N=0;N<$.lines[B].length;N++)k($.x+2+N,_,$.lines[B][N],"text")}const I=$.y+$.height-1;k($.x,I,d,"border");for(let B=1;B<$.width-1;B++)k($.x+B,I,a,"border");k($.x+$.width-1,I,f,"border")}return Ee(P,{roleCanvas:H,colorMode:n,theme:s});function et(){return i?"-":"╌"}}function Vn(t){const e={classes:[],relationships:[],namespaces:[]},n=new Map;let s=null,r=null,o=0;for(let i=1;i<t.length;i++){const a=t[i];if(r&&o>0){if(a==="}"){o--,o===0&&(r=null);continue}const g=a.match(/^<<(\w+)>>$/);if(g){r.annotation=g[1];continue}const x=mn(a);x&&(x.isMethod?r.methods.push(x.member):r.attributes.push(x.member));continue}const l=a.match(/^namespace\s+(\S+)\s*\{$/);if(l){s={name:l[1],classIds:[]};continue}if(a==="}"&&s){e.namespaces.push(s),s=null;continue}const h=a.match(/^class\s+(\S+?)(?:\s*~(\w+)~)?\s*\{$/);if(h){const g=h[1],x=h[2],p=ie(n,g);x&&(p.label=`${g}<${x}>`),r=p,o=1,s&&s.classIds.push(g);continue}const c=a.match(/^class\s+(\S+?)(?:\s*~(\w+)~)?\s*$/);if(c){const g=c[1],x=c[2],p=ie(n,g);x&&(p.label=`${g}<${x}>`),s&&s.classIds.push(g);continue}const d=a.match(/^class\s+(\S+?)\s*\{\s*<<(\w+)>>\s*\}$/);if(d){const g=ie(n,d[1]);g.annotation=d[2];continue}const f=a.match(/^(\S+?)\s*:\s*(.+)$/);if(f){const g=f[2];if(!g.match(/<\|--|--|\*--|o--|-->|\.\.>|\.\.\|>/)){const x=ie(n,f[1]),p=mn(g);p&&(p.isMethod?x.methods.push(p.member):x.attributes.push(p.member));continue}}const u=$r(a);if(u){ie(n,u.from),ie(n,u.to),e.relationships.push(u);continue}}return e.classes=[...n.values()],e}function ie(t,e){let n=t.get(e);return n||(n={id:e,label:e,attributes:[],methods:[]},t.set(e,n)),n}function mn(t){const e=t.trim().replace(/;$/,"");if(!e)return null;let n="",s=e;/^[+\-#~]/.test(s)&&(n=s[0],s=s.slice(1).trim());const r=s.match(/^(.+?)\(([^)]*)\)(?:\s*(.+))?$/);if(r){const c=r[1].trim(),d=r[2]?.trim()||void 0,f=r[3]?.trim(),u=c.endsWith("$")||s.includes("$"),g=c.endsWith("*")||s.includes("*");return{member:{visibility:n,name:c.replace(/[$*]$/,""),type:f||void 0,isStatic:u,isAbstract:g,isMethod:!0,params:d},isMethod:!0}}const o=s.split(/\s+/);let i,a;o.length>=2?(a=o[0],i=o.slice(1).join(" ")):i=o[0]??s;const l=i.endsWith("$"),h=i.endsWith("*");return{member:{visibility:n,name:i.replace(/[$*]$/,""),type:a||void 0,isStatic:l,isAbstract:h,isMethod:!1},isMethod:!1}}function $r(t){const e=t.match(/^(\S+?)\s+(?:"([^"]*?)"\s+)?(<\|--|<\|\.\.|\*--|o--|-->|--\*|--o|--\|>|\.\.>|\.\.\|>|<--|<\.\.?|--)\s+(?:"([^"]*?)"\s+)?(\S+?)(?:\s*:\s*(.+))?$/);if(!e)return null;const n=e[1],s=e[2],r=s?$t(s):void 0,o=e[3].trim(),i=e[4],a=i?$t(i):void 0,l=e[5],h=e[6]?.trim(),c=h?$t(h):void 0,d=wr(o);return d?{from:n,to:l,type:d.type,markerAt:d.markerAt,label:c,fromCardinality:r,toCardinality:a}:null}function wr(t){switch(t.trim()){case"<|--":return{type:"inheritance",markerAt:"from"};case"--|>":return{type:"inheritance",markerAt:"to"};case"<|..":return{type:"realization",markerAt:"from"};case"..|>":return{type:"realization",markerAt:"to"};case"*--":return{type:"composition",markerAt:"from"};case"--*":return{type:"composition",markerAt:"to"};case"o--":return{type:"aggregation",markerAt:"from"};case"--o":return{type:"aggregation",markerAt:"to"};case"-->":return{type:"association",markerAt:"to"};case"<--":return{type:"association",markerAt:"from"};case"..>":return{type:"dependency",markerAt:"to"};case"<..":return{type:"dependency",markerAt:"from"};case"--":return{type:"association",markerAt:"to"};default:return null}}function Mr(t){return/^[┌┐└┘├┤┬┴┼│─╭╮╰╯+\-|]$/.test(t)?"border":"text"}function bn(t){const e=t.visibility||"",n=t.type?`: ${t.type}`:"";return`${e}${t.name}${n}`}function vr(t){const e=[];t.annotation&&e.push(`<<${t.annotation}>>`);const n=pt(t.label);e.push(...n);const s=t.attributes.map(bn),r=t.methods.map(bn);return s.length===0&&r.length===0?[e]:r.length===0?[e,s]:[e,s,r]}function kr(t,e){return{type:t,markerAt:e,dashed:t==="dependency"||t==="realization"}}function qt(t,e,n){switch(t){case"inheritance":case"realization":return n==="down"?e?"^":"△":n==="up"?e?"v":"▽":n==="left"?e?">":"◁":e?"<":"▷";case"composition":return e?"*":"◆";case"aggregation":return e?"o":"◇";case"association":case"dependency":return n==="down"?e?"v":"▼":n==="up"?e?"^":"▲":n==="left"?e?"<":"◀":e?">":"▶"}}function Sr(t,e,n,s){const r=t.split(`
26
- `).map(L=>L.trim()).filter(L=>L.length>0&&!L.startsWith("%%")),o=Vn(r);if(o.classes.length===0)return"";const i=e.useAscii,a=4,l=3,h=new Map,c=new Map,d=new Map;for(const L of o.classes){const P=vr(L);h.set(L.id,P);let H=0;for(const $ of P)for(const I of $)H=Math.max(H,I.length);const k=H+4;let j=0;for(const $ of P)j+=Math.max($.length,1);const et=j+(P.length-1)+2;c.set(L.id,k),d.set(L.id,et)}const f=new Map;for(const L of o.classes)f.set(L.id,L);const u=new Map,g=new Map;for(const L of o.relationships){const P=L.type==="inheritance"||L.type==="realization",H=P&&L.markerAt==="to"?L.to:L.from,k=P&&L.markerAt==="to"?L.from:L.to;u.has(k)||u.set(k,new Set),u.get(k).add(H),g.has(H)||g.set(H,new Set),g.get(H).add(k)}const x=new Map,M=o.classes.filter(L=>!u.has(L.id)||u.get(L.id).size===0).map(L=>L.id);for(const L of M)x.set(L,0);const D=o.classes.length-1;let A=0;for(;A<M.length;){const L=M[A++],P=g.get(L);if(P)for(const H of P){const k=(x.get(L)??0)+1;k>D||(!x.has(H)||x.get(H)<k)&&(x.set(H,k),M.push(H))}}for(const L of o.classes)x.has(L.id)||x.set(L.id,0);const C=Math.max(...x.values(),0),w=Array.from({length:C+1},()=>[]);for(const L of o.classes)w[x.get(L.id)].push(L.id);const O=new Map;let st=0;for(let L=0;L<=C;L++){const P=w[L];if(P.length===0)continue;let H=0,k=0;for(const j of P){const et=f.get(j),$=c.get(j),I=d.get(j);O.set(j,{cls:et,sections:h.get(j),x:H,y:st,width:$,height:I}),H+=$+a,k=Math.max(k,I)}st+=k+l}let y=0,m=0;for(const L of O.values())y=Math.max(y,L.x+L.width),m=Math.max(m,L.y+L.height);y+=4,m+=2;const S=wt(y-1,m-1),X=$e(y-1,m-1);function v(L,P,H,k){L>=0&&L<S.length&&P>=0&&P<(S[0]?.length??0)&&(S[L][P]=H,we(X,L,P,k))}for(const L of O.values()){const P=On(L.sections,i);for(let H=0;H<P.length;H++)for(let k=0;k<P[0].length;k++){const j=P[H][k];if(j!==" "){const et=L.x+H,$=L.y+k;et<y&&$<m&&v(et,$,j,Mr(j))}}}const z=[];for(const L of O.values())z.push({x1:L.x,x2:L.x+L.width-1,y1:L.y,y2:L.y+L.height-1});function F(L,P,H){for(const[k,j]of O.entries())if(!H?.has(k)&&L>=j.x&&L<=j.x+j.width-1&&P>=j.y&&P<=j.y+j.height-1)return!0;return!1}function V(L,P,H,k){let j=!0;for(let et=Math.min(P,H);et<=Math.max(P,H);et++)if(F(L,et,k)){j=!1;break}if(j)return L;for(let et=1;et<y+10;et++){const $=L+et;j=!0;for(let B=Math.min(P,H);B<=Math.max(P,H);B++)if(F($,B,k)){j=!1;break}if(j)return $;const I=L-et;if(I>=0){j=!0;for(let B=Math.min(P,H);B<=Math.max(P,H);B++)if(F(I,B,k)){j=!1;break}if(j)return I}}return y+2}const Y=i?"-":"─",Z=i?"|":"│",at=i?".":"╌",tt=i?":":"┊";for(const L of o.relationships){const P=O.get(L.from),H=O.get(L.to);if(!P||!H)continue;const k=kr(L.type,L.markerAt),j=k.dashed?at:Y,et=k.dashed?tt:Z,$=new Set([L.from,L.to]),I=P.x+Math.floor(P.width/2),B=P.y+P.height-1,_=H.x+Math.floor(H.width/2),N=H.y;if(B<N){const W=V(I,B+1,N-1,$),it=W!==I;if(W>=y&&Zt(S,W+2,m),it){const G=B+1,R=N-1,K=Math.min(I,W),E=Math.max(I,W);for(let q=K;q<=E;q++)v(q,G,j,"line");!i&&G<(S[0]?.length??0)&&(I<W?(v(I,G,"└","corner"),v(W,G,"┐","corner")):(v(I,G,"┘","corner"),v(W,G,"┌","corner")));for(let q=G+1;q<=R;q++)v(W,q,et,"line");if(W!==_){const q=Math.min(W,_),ft=Math.max(W,_);for(let lt=q;lt<=ft;lt++)v(lt,R,j,"line");!i&&R<(S[0]?.length??0)&&(W<_?(v(W,R,"└","corner"),v(_,R,"┐","corner")):(v(W,R,"┘","corner"),v(_,R,"┌","corner")))}if(k.markerAt==="to"){const q=qt(k.type,i,"down");v(_,R,q,"arrow")}if(k.markerAt==="from"){const q=qt(k.type,i,"down");v(I,B+1,q,"arrow")}}else{const G=B+Math.floor((N-B)/2);for(let R=B+1;R<=G;R++)v(I,R,et,"line");if(I!==_&&G<(S[0]?.length??0)){const R=Math.min(I,_),K=Math.max(I,_);for(let E=R;E<=K;E++)v(E,G,j,"line");i||(v(I,G,I<_?"└":"┘","corner"),v(_,G,I<_?"┐":"┌","corner"))}for(let R=G+1;R<N;R++)v(_,R,et,"line");k.markerAt==="to"&&v(_,N-1,qt(k.type,i,"down"),"arrow"),k.markerAt==="from"&&v(I,B+1,qt(k.type,i,"down"),"arrow")}}else if(H.y+H.height-1<P.y){const W=P.y,it=H.y+H.height-1,G=it+Math.floor((W-it)/2);for(let R=W-1;R>=G;R--)v(I,R,et,"line");if(I!==_){const R=Math.min(I,_),K=Math.max(I,_);for(let E=R;E<=K;E++)v(E,G,j,"line");!i&&G>=0&&G<m&&(v(I,G,I<_?"┌":"┐","corner"),v(_,G,I<_?"┘":"└","corner"))}for(let R=G-1;R>it;R--)v(_,R,et,"line");if(k.markerAt==="from"){const R=qt(k.type,i,"up"),K=W-1;for(let E=0;E<R.length;E++)v(I-Math.floor(R.length/2)+E,K,R[E],"arrow")}if(k.markerAt==="to"){const K=k.type==="inheritance"||k.type==="realization"?"down":"up",E=qt(k.type,i,K),q=it+1;for(let ft=0;ft<E.length;ft++)v(_-Math.floor(E.length/2)+ft,q,E[ft],"arrow")}}else{const W=Math.max(B,H.y+H.height-1)+2;Zt(S,y,W+1),oe(X,y,W+1);for(let R=B+1;R<=W;R++)v(I,R,et,"line");const it=Math.min(I,_),G=Math.max(I,_);for(let R=it;R<=G;R++)v(R,W,j,"line");for(let R=W-1;R>=H.y+H.height;R--)v(_,R,et,"line");if(k.markerAt==="from"){const R=qt(k.type,i,"down"),K=B+1;for(let E=0;E<R.length;E++)v(I-Math.floor(R.length/2)+E,K,R[E],"arrow")}if(k.markerAt==="to"){const R=qt(k.type,i,"up"),K=H.y+H.height;for(let E=0;E<R.length;E++)v(_-Math.floor(R.length/2)+E,K,R[E],"arrow")}}if(L.label){const W=pt(L.label),it=Math.max(...W.map(lt=>lt.length))+2;let G,R;if(B<N)G=Math.floor((B+1+N-1)/2),R=Math.floor((I+_)/2);else if(H.y+H.height-1<P.y){const lt=H.y+H.height-1;G=Math.floor((lt+1+P.y-1)/2),R=Math.floor((I+_)/2)}else G=Math.max(B,H.y+H.height-1)+2,R=Math.floor((I+_)/2);let K=G;const E=Math.floor(W.length/2);let q=!1;for(let lt=0;lt<W.length;lt++){const ht=K-E+lt,mt=R-Math.floor(it/2),bt=Math.max(0,mt);for(let Ht=bt;Ht<bt+it;Ht++)if(F(Ht,ht,$)){q=!0;break}if(q)break}if(q){const lt=B+1,ht=N-1;for(let mt=lt;mt<=ht;mt++){let bt=!0;const Ht=R-Math.floor(it/2),Vt=Math.max(0,Ht);for(let Wt=Vt;Wt<Vt+it;Wt++)if(F(Wt,mt,$)){bt=!1;break}if(bt){K=mt;break}}}const ft=K-E;for(let lt=0;lt<W.length;lt++){const ht=` ${W[lt]} `,mt=R-Math.floor(ht.length/2),bt=Math.max(0,mt),Ht=ft+lt,Vt=bt+ht.length;Vt>0&&Ht>=0&&(Zt(S,Math.max(Vt,1),Math.max(Ht+1,1)),oe(X,Math.max(Vt,1),Math.max(Ht+1,1)));for(let Wt=0;Wt<ht.length;Wt++){const re=bt+Wt;re>=0&&Ht>=0&&v(re,Ht,ht[Wt],"text")}}}}return Ee(S,{roleCanvas:X,colorMode:n,theme:s})}function qn(t){const e={entities:[],relationships:[]},n=new Map;let s=null;for(let r=1;r<t.length;r++){const o=t[r];if(s){if(o==="}"){s=null;continue}const l=Lr(o);l&&s.attributes.push(l);continue}const i=o.match(/^(\S+)\s*\{$/);if(i){const l=i[1];s=Ne(n,l);continue}const a=Ar(o);if(a){Ne(n,a.entity1),Ne(n,a.entity2),e.relationships.push(a);continue}}return e.entities=[...n.values()],e}function Ne(t,e){let n=t.get(e);return n||(n={id:e,label:e,attributes:[]},t.set(e,n)),n}function Lr(t){const e=t.match(/^(\S+)\s+(\S+)(?:\s+(.+))?$/);if(!e)return null;const n=e[1],s=e[2],r=e[3]?.trim()??"",o=[];let i;const a=r.match(/"([^"]*)"/);a&&(i=$t(a[1]));const l=r.replace(/"[^"]*"/,"").trim();for(const h of l.split(/\s+/)){const c=h.toUpperCase();(c==="PK"||c==="FK"||c==="UK")&&o.push(c)}return{type:n,name:s,keys:o,comment:i}}function Ar(t){const e=t.match(/^(\S+)\s+([|o}{]+(?:--|\.\.)[|o}{]+)\s+(\S+)\s*:\s*(.+)$/);if(!e)return null;const n=e[1],s=e[2],r=e[3],o=e[4].trim().replace(/^["']|["']$/g,""),i=$t(o),a=s.match(/^([|o}{]+)(--|\.\.?)([|o}{]+)$/);if(!a)return null;const l=a[1],h=a[2],c=a[3],d=$n(l),f=$n(c),u=h==="--";return!d||!f?null:{entity1:n,entity2:r,cardinality1:d,cardinality2:f,label:i,identifying:u}}function $n(t){const e=t.split("").sort().join("");return e==="||"?"one":e==="o|"?"zero-one":e==="|}"||e==="{|"?"many":e==="{o"||e==="o{"?"zero-many":null}function Cr(t){return/^[┌┐└┘├┤┬┴┼│─╭╮╰╯+\-|]$/.test(t)?"border":"text"}function Tr(t){return`${t.keys.length>0?t.keys.join(",")+" ":" "}${t.type} ${t.name}`}function Ir(t){const e=pt(t.label),n=t.attributes.map(Tr);return n.length===0?[e]:[e,n]}function ke(t,e,n=!1){if(e)switch(t){case"one":return"|";case"zero-one":return"o|";case"many":return n?"<":">";case"zero-many":return n?"o<":">o"}else switch(t){case"one":return"│";case"zero-one":return"○│";case"many":return n?"╟":"╢";case"zero-many":return n?"○╟":"╢○"}}function Rr(t){const e=new Set,n=[],s=new Map;for(const o of t.entities)s.set(o.id,new Set);for(const o of t.relationships)s.get(o.entity1)?.add(o.entity2),s.get(o.entity2)?.add(o.entity1);function r(o,i){const a=[o];for(;a.length>0;){const l=a.pop();if(!e.has(l)){e.add(l),i.add(l);for(const h of s.get(l)??[])e.has(h)||a.push(h)}}}for(const o of t.entities)if(!e.has(o.id)){const i=new Set;r(o.id,i),i.size>0&&n.push(i)}return n}function Hr(t,e,n,s){const r=t.split(`
27
- `).map(S=>S.trim()).filter(S=>S.length>0&&!S.startsWith("%%")),o=qn(r);if(o.entities.length===0)return"";const i=e.useAscii,a=6,l=4,h=6,c=new Map,d=new Map,f=new Map,u=new Map;for(const S of o.entities){u.set(S.id,S);const X=Ir(S);c.set(S.id,X);let v=0;for(const Y of X)for(const Z of Y)v=Math.max(v,Z.length);const z=v+4;let F=0;for(const Y of X)F+=Math.max(Y.length,1);const V=F+(X.length-1)+2;d.set(S.id,z),f.set(S.id,V)}const g=Rr(o),x=new Map;let p=0;for(const S of g){const X=o.entities.filter(Y=>S.has(Y.id)),v=Math.max(2,Math.ceil(Math.sqrt(X.length)));let z=0,F=0,V=0;for(const Y of X){const Z=d.get(Y.id),at=f.get(Y.id);V>=v&&(p+=F+l,z=0,F=0,V=0),x.set(Y.id,{entity:Y,sections:c.get(Y.id),x:z,y:p,width:Z,height:at}),z+=Z+a,F=Math.max(F,at),V++}p+=F+h}let M=0,D=0;for(const S of x.values())M=Math.max(M,S.x+S.width),D=Math.max(D,S.y+S.height);M+=4,D+=2;const A=wt(M-1,D-1),C=$e(M-1,D-1);function w(S,X,v,z){S>=0&&S<A.length&&X>=0&&X<(A[0]?.length??0)&&(A[S][X]=v,we(C,S,X,z))}for(const S of x.values()){const X=On(S.sections,i);for(let v=0;v<X.length;v++)for(let z=0;z<X[0].length;z++){const F=X[v][z];if(F!==" "){const V=S.x+v,Y=S.y+z;V<M&&Y<D&&w(V,Y,F,Cr(F))}}}const O=i?"-":"─",st=i?"|":"│",y=i?".":"╌",m=i?":":"┊";for(const S of o.relationships){const X=x.get(S.entity1),v=x.get(S.entity2);if(!X||!v)continue;const z=S.identifying?O:y,F=S.identifying?st:m,V=X.x+Math.floor(X.width/2),Y=X.y+Math.floor(X.height/2),Z=v.x+Math.floor(v.width/2),at=v.y+Math.floor(v.height/2);if(Math.abs(Y-at)<Math.max(X.height,v.height)){const[L,P]=V<Z?[X,v]:[v,X],[H,k]=V<Z?[S.cardinality1,S.cardinality2]:[S.cardinality2,S.cardinality1],j=L.x+L.width,et=P.x-1,$=L.y+Math.floor(L.height/2);for(let _=j;_<=et;_++)w(_,$,z,"line");const I=ke(H,i,!1);for(let _=0;_<I.length;_++)w(j+_,$,I[_],"arrow");const B=ke(k,i,!0);for(let _=0;_<B.length;_++)w(et-B.length+1+_,$,B[_],"arrow");if(S.label){const _=pt(S.label),N=Math.floor((j+et)/2);for(let W=0;W<_.length;W++){const it=_[W],G=Math.max(j,N-Math.floor(it.length/2)),R=$+1+W;Zt(A,Math.max(G+it.length,1),Math.max(R+1,1)),oe(C,Math.max(G+it.length,1),Math.max(R+1,1));for(let K=0;K<it.length;K++){const E=G+K;E>=j&&E<=et&&w(E,R,it[K],"text")}}}}else{const[L,P]=Y<at?[X,v]:[v,X],[H,k]=Y<at?[S.cardinality1,S.cardinality2]:[S.cardinality2,S.cardinality1],j=L.y+L.height,et=P.y-1,$=L.x+Math.floor(L.width/2);for(let W=j;W<=et;W++)w($,W,F,"line");const I=P.x+Math.floor(P.width/2);if($!==I){const W=Math.floor((j+et)/2),it=Math.min($,I),G=Math.max($,I);for(let R=it;R<=G;R++)w(R,W,z,"line");for(let R=W+1;R<=et;R++)w(I,R,F,"line")}const B=ke(H,i,!1);for(let W=0;W<B.length;W++)w($-Math.floor(B.length/2)+W,j,B[W],"arrow");const _=$!==I?I:$,N=ke(k,i,!0);for(let W=0;W<N.length;W++)w(_-Math.floor(N.length/2)+W,et,N[W],"arrow");if(S.label){const W=pt(S.label),G=Math.floor((j+et)/2)-Math.floor((W.length-1)/2);for(let R=0;R<W.length;R++){const K=W[R],E=$+2,q=G+R;if(q>=0)for(let ft=0;ft<K.length;ft++){const lt=E+ft;lt>=0&&(Zt(A,lt+1,q+1),oe(C,lt+1,q+1),w(lt,q,K[ft],"text"))}}}}}return Ee(A,{roleCanvas:C,colorMode:n,theme:s})}function Un(t){const e={},n={},s=[];let r,o=!1;for(const i of t){if(/^xychart(-beta)?\b/i.test(i)){/\bhorizontal\b/i.test(i)&&(o=!0);continue}const a=i.match(/^title\s+"([^"]+)"/);if(a){r=a[1];continue}const l=i.match(/^x-axis\s+(?:"([^"]*)"\s*)?\[([^\]]+)\]/);if(l){l[1]&&(e.title=l[1]),e.categories=l[2].split(",").map(g=>g.trim());continue}const h=i.match(/^x-axis\s+(?:"([^"]*)"\s+)?(-?\d+(?:\.\d+)?)\s*-->\s*(-?\d+(?:\.\d+)?)/);if(h){h[1]&&(e.title=h[1]),e.range={min:parseFloat(h[2]),max:parseFloat(h[3])};continue}const c=i.match(/^y-axis\s+(?:"([^"]*)"\s+)?(-?\d+(?:\.\d+)?)\s*-->\s*(-?\d+(?:\.\d+)?)/);if(c){c[1]&&(n.title=c[1]),n.range={min:parseFloat(c[2]),max:parseFloat(c[3])};continue}const d=i.match(/^y-axis\s+"([^"]+)"\s*$/);if(d){n.title=d[1];continue}const f=i.match(/^bar\s+\[([^\]]+)\]/);if(f){s.push({type:"bar",data:wn(f[1])});continue}const u=i.match(/^line\s+\[([^\]]+)\]/);if(u){s.push({type:"line",data:wn(u[1])});continue}}if(!n.range&&s.length>0){const i=s.flatMap(c=>c.data);let a=Math.min(...i),l=Math.max(...i);const h=l-a||1;a=a-h*.1,l=l+h*.1,a>0&&a<h*.5&&(a=0),n.range={min:a,max:l}}return n.range||(n.range={min:0,max:100}),{title:r,horizontal:o,xAxis:e,yAxis:n,series:s}}function wn(t){return t.split(",").map(e=>parseFloat(e.trim()))}var Re="#3b82f6";function Kn(t){const e=t.replace("#",""),n=parseInt(e.substring(0,2),16)/255,s=parseInt(e.substring(2,4),16)/255,r=parseInt(e.substring(4,6),16)/255,o=Math.max(n,s,r),i=Math.min(n,s,r),a=(o+i)/2;if(o===i)return[0,0,a*100];const l=o-i,h=a>.5?l/(2-o-i):l/(o+i);let c;return o===n?c=((s-r)/l+(s<r?6:0))/6:o===s?c=((r-n)/l+2)/6:c=((n-s)/l+4)/6,[c*360,h*100,a*100]}function Wr(t,e,n){const s=e/100,r=n/100,o=(1-Math.abs(2*r-1))*s,i=o*(1-Math.abs(t/60%2-1)),a=r-o/2;let l,h,c;t<60?(l=o,h=i,c=0):t<120?(l=i,h=o,c=0):t<180?(l=0,h=o,c=i):t<240?(l=0,h=i,c=o):t<300?(l=i,h=0,c=o):(l=o,h=0,c=i);const d=f=>Math.round((f+a)*255).toString(16).padStart(2,"0");return`#${d(l)}${d(h)}${d(c)}`}function Mn(t){return/^#[0-9a-fA-F]{6}$/.test(t)}function Yr(t){return Kn(t)[2]<50}function Qn(t,e,n){if(t===0)return e;const s=Mn(e)?e:Re,r=n&&Mn(n)?n:void 0,[o,i]=Kn(s),a=Math.max(55,Math.min(85,i)),l=Math.ceil(t/2),h=t%2===1,c=r&&Yr(r)?!h:h,d=c?Math.max(25,48-l*13):Math.min(78,55+l*11),f=(c?-8:12)*l,u=((o+f)%360+360)%360;return Wr(u,a,d)}var Zn=60,to=20,Dr={hLine:"─",vLine:"│",origin:"┼",yTick:"┤",xTick:"┬",bar:"█",grid:"·",cornerTL:"╭",cornerTR:"╮",cornerBL:"╰",cornerBR:"╯"},Er={hLine:"-",vLine:"|",origin:"+",yTick:"+",xTick:"+",bar:"#",grid:".",cornerTL:"+",cornerTR:"+",cornerBL:"+",cornerBR:"+"};function eo(t,e){const n=e.accent??Re;return t<=1?[n]:Array.from({length:t},(s,r)=>Qn(r,n,e.bg))}function Xr(t,e){switch(t){case"text":return e.fg;case"border":return e.border;case"line":return e.line;case"arrow":return e.arrow;case"corner":return e.corner??e.line;case"junction":return e.junction??e.border;default:return e.fg}}function _r(t,e,n,s){const r=t.split(`
28
- `).map(a=>a.trim()).filter(a=>a.length>0&&!a.startsWith("%%")),o=Un(r),i=e.useAscii?Er:Dr;return o.horizontal?zr(o,i,n,s):Pr(o,i,n,s)}function Pr(t,e,n,s){const r=lo(t);if(r===0)return"";const o=t.yAxis.range,i=ho(o.min,o.max),a=i.map(Y=>He(Y)),l=Math.max(...a.map(Y=>Y.length))+1,h=Math.max(Zn,r*6),c=to,d=Math.floor(h/r),f=co(t,r),u=!!t.title,g=!!t.xAxis.title,x=t.series.length>1,p=u?0:-1,M=(u?2:0)+(x?1:0),D=l+1,A=D+d*r+2,C=M+c,w=C+1,O=g?w+1:-1,st=w+1+(g?1:0)+0,y=oo(A,st),m=so(A,st),S=ro(A,st),X=eo(t.series.length,s),v=Y=>{const Z=(Y-o.min)/(o.max-o.min||1);return Math.round(Z*(c-1))},z=Y=>D+Math.floor(d*(Y+.5));u&&p>=0&&Ot(y,m,p,Math.floor(A/2-t.title.length/2),t.title,"text"),x&&no(y,m,S,t,u?1:0,A,e,X);for(let Y=0;Y<c;Y++){const Z=M+(c-1-Y);kt(y,m,Z,D-1,e.vLine,"border")}kt(y,m,C,D-1,e.origin,"border");for(const Y of i){const Z=v(Y);if(Z<0||Z>=c)continue;const at=M+(c-1-Z),tt=He(Y);kt(y,m,at,D-1,Z===0?e.origin:e.yTick,"border");const L=l-tt.length;Ot(y,m,at,Math.max(0,L),tt,"text")}for(let Y=D;Y<D+d*r;Y++)kt(y,m,C,Y,e.hLine,"border");for(let Y=0;Y<r;Y++){const Z=z(Y);kt(y,m,C,Z,e.xTick,"border");const at=f[Y],tt=Z-Math.floor(at.length/2);Ot(y,m,w,Math.max(0,tt),at,"text")}if(g&&O>=0){const Y=t.xAxis.title;Ot(y,m,O,Math.floor(A/2-Y.length/2),Y,"text")}for(const Y of i){const Z=v(Y);if(Z<0||Z>=c)continue;const at=M+(c-1-Z);for(let tt=D;tt<D+d*r;tt++)io(y,at,tt)===" "&&kt(y,m,at,tt,e.grid,"line")}const F=[];for(let Y=0;Y<t.series.length;Y++)t.series[Y].type==="bar"&&F.push({data:t.series[Y].data,globalIdx:Y});if(F.length>0){const Y=F.length,Z=Math.max(1,d-2),at=Math.max(1,Math.min(Math.floor(Z/Y),8)),tt=at*Y+(Y-1),L=v(Math.max(0,o.min));for(let P=0;P<F.length;P++){const H=F[P],k=X[H.globalIdx];for(let j=0;j<H.data.length;j++){const I=z(j)-Math.floor(tt/2)+P*(at+1),B=v(H.data[j]),_=Math.min(L,B),N=Math.max(L,B);for(let W=_;W<=N;W++){const it=M+(c-1-W);for(let G=I;G<I+at;G++)kt(y,m,it,G,e.bar,"arrow",S,k)}}}}const V=[];for(let Y=0;Y<t.series.length;Y++)t.series[Y].type==="line"&&V.push({data:t.series[Y].data,globalIdx:Y});for(const Y of V){if(Y.data.length===0)continue;const Z=X[Y.globalIdx];Br(y,m,Y.data,z,v,M,c,D,d*r,e,S,Z)}return ao(y,m,S,n,s)}function zr(t,e,n,s){const r=lo(t);if(r===0)return"";const o=t.yAxis.range,i=ho(o.min,o.max),a=co(t,r),l=Math.max(...a.map(v=>v.length))+1,h=Math.max(Zn,40),c=Math.max(2,Math.floor(to/r)),d=c*r,f=!!t.title,u=!!t.yAxis.title,g=t.series.length>1,x=(f?2:0)+(g?1:0),p=l+1,M=p+h+2,D=x+d+2+(u?1:0),A=x+d,C=oo(M,D),w=so(M,D),O=ro(M,D),st=eo(t.series.length,s),y=v=>{const z=(v-o.min)/(o.max-o.min||1);return p+Math.round(z*(h-1))},m=v=>x+Math.floor(c*(v+.5));f&&Ot(C,w,0,Math.floor(M/2-t.title.length/2),t.title,"text"),g&&no(C,w,O,t,f?1:0,M,e,st);for(let v=x;v<x+d;v++)kt(C,w,v,p-1,e.vLine,"border");kt(C,w,A,p-1,e.origin,"border");for(let v=0;v<r;v++){const z=m(v),F=a[v],V=l-F.length;Ot(C,w,z,Math.max(0,V),F,"text")}for(let v=p;v<p+h;v++)kt(C,w,A,v,e.hLine,"border");for(const v of i){const z=y(v);if(z<p||z>=p+h)continue;kt(C,w,A,z,e.xTick,"border");const F=He(v);Ot(C,w,A+1,z-Math.floor(F.length/2),F,"text")}if(u){const v=t.yAxis.title;Ot(C,w,D-1,Math.floor(M/2-v.length/2),v,"text")}for(const v of i){const z=y(v);if(!(z<p||z>=p+h))for(let F=x;F<x+d;F++)io(C,F,z)===" "&&kt(C,w,F,z,e.grid,"line")}const S=[];for(let v=0;v<t.series.length;v++)t.series[v].type==="bar"&&S.push({data:t.series[v].data,globalIdx:v});if(S.length>0){const v=S.length,z=1,F=z*v+(v-1),V=y(Math.max(0,o.min));for(let Y=0;Y<S.length;Y++){const Z=S[Y],at=st[Z.globalIdx];for(let tt=0;tt<Z.data.length;tt++){const H=m(tt)-Math.floor(F/2)+Y*(z+1),k=y(Z.data[tt]),j=Math.min(V,k),et=Math.max(V,k);for(let $=H;$<H+z;$++)for(let I=j;I<=et;I++)kt(C,w,$,I,e.bar,"arrow",O,at)}}}const X=[];for(let v=0;v<t.series.length;v++)t.series[v].type==="line"&&X.push({data:t.series[v].data,globalIdx:v});for(const v of X){if(v.data.length===0)continue;const z=st[v.globalIdx];Nr(C,w,v.data,m,y,x,d,p,h,e,O,z)}return ao(C,w,O,n,s)}function Br(t,e,n,s,r,o,i,a,l,h,c,d){if(n.length===0)return;const f=n.map((g,x)=>({col:s(x),row:r(g)})),u=(g,x,p)=>{const M=o+(i-1-x);M>=0&&g>=a&&g<a+l&&kt(t,e,M,g,p,"arrow",c,d)};if(f.length===1){u(f[0].col,f[0].row,h.hLine);return}for(let g=0;g<f.length-1;g++){const x=f[g],p=f[g+1];if(x.row===p.row){for(let w=x.col;w<=p.col;w++)u(w,x.row,h.hLine);continue}const M=Math.round((x.col+p.col)/2),D=p.row>x.row;for(let w=x.col;w<M;w++)u(w,x.row,h.hLine);D?u(M,x.row,h.cornerBR):u(M,x.row,h.cornerTR);const A=Math.min(x.row,p.row),C=Math.max(x.row,p.row);for(let w=A+1;w<C;w++)u(M,w,h.vLine);D?u(M,p.row,h.cornerTL):u(M,p.row,h.cornerBL);for(let w=M+1;w<=p.col;w++)u(w,p.row,h.hLine);if(g===0){const w=Math.max(a,x.col-Math.floor((p.col-x.col)/4));for(let O=w;O<x.col;O++)u(O,x.row,h.hLine)}if(g===f.length-2){const w=Math.min(a+l-1,p.col+Math.floor((p.col-x.col)/4));for(let O=p.col+1;O<=w;O++)u(O,p.row,h.hLine)}}}function Nr(t,e,n,s,r,o,i,a,l,h,c,d){if(n.length===0)return;const f=n.map((g,x)=>({row:s(x),col:r(g)})),u=(g,x,p)=>{g>=o&&g<o+i&&x>=a&&x<a+l&&kt(t,e,g,x,p,"arrow",c,d)};if(f.length===1){u(f[0].row,f[0].col,h.vLine);return}for(let g=0;g<f.length-1;g++){const x=f[g],p=f[g+1];if(x.col===p.col){for(let w=x.row;w<=p.row;w++)u(w,x.col,h.vLine);continue}const M=Math.round((x.row+p.row)/2),D=p.col>x.col;for(let w=x.row;w<M;w++)u(w,x.col,h.vLine);D?u(M,x.col,h.cornerBL):u(M,x.col,h.cornerBR);const A=Math.min(x.col,p.col),C=Math.max(x.col,p.col);for(let w=A+1;w<C;w++)u(M,w,h.hLine);D?u(M,p.col,h.cornerTR):u(M,p.col,h.cornerTL);for(let w=M+1;w<=p.row;w++)u(w,p.col,h.vLine)}}function no(t,e,n,s,r,o,i,a){const l=[];let h=0,c=0;for(let g=0;g<s.series.length;g++)s.series[g].type==="bar"?(l.push({symbol:i.bar,label:`Bar ${h+1}`,globalIdx:g}),h++):(l.push({symbol:i.hLine,label:`Line ${c+1}`,globalIdx:g}),c++);let d=0;for(let g=0;g<l.length;g++)g>0&&(d+=2),d+=2+l[g].label.length;let u=Math.max(0,Math.floor(o/2-d/2));for(let g=0;g<l.length;g++){g>0&&(u+=2);const x=l[g];kt(t,e,r,u,x.symbol,"arrow",n,a[x.globalIdx]),u+=1,u+=1,Ot(t,e,r,u,x.label,"text"),u+=x.label.length}}function oo(t,e){return Array.from({length:t},()=>Array.from({length:e},()=>" "))}function so(t,e){return Array.from({length:t},()=>Array.from({length:e}).fill(null))}function ro(t,e){return Array.from({length:t},()=>Array.from({length:e}).fill(null))}function kt(t,e,n,s,r,o,i,a){s>=0&&s<t.length&&n>=0&&n<t[0].length&&(t[s][n]=r,e[s][n]=o,i&&a&&(i[s][n]=a))}function io(t,e,n){return n>=0&&n<t.length&&e>=0&&e<t[0].length?t[n][e]:" "}function Ot(t,e,n,s,r,o){for(let i=0;i<r.length;i++)kt(t,e,n,s+i,r[i],o)}function ao(t,e,n,s,r){if(t.length===0)return"";const o=t[0].length,i=t.length,a=[];for(let l=0;l<o;l++){const h=[],c=[],d=[];for(let u=0;u<i;u++)h.push(t[u][l]),c.push(e[u][l]),d.push(n[u][l]);let f=h.length-1;for(;f>=0&&h[f]===" ";)f--;f<0?a.push(""):a.push(jr(h.slice(0,f+1),c.slice(0,f+1),d.slice(0,f+1),r,s))}for(;a.length>0&&a[a.length-1]==="";)a.pop();return a.join(`
29
- `)}function jr(t,e,n,s,r){if(r==="none")return t.join("");let o="",i=null,a="";for(let l=0;l<t.length;l++){const h=t[l];if(h===" "){a.length>0&&(o+=i?_e(a,i,r):a,a="",i=null),o+=" ";continue}const c=n[l]??null,d=e[l]??null,f=c??(d?Xr(d,s):null);f===i?a+=h:(a.length>0&&(o+=i?_e(a,i,r):a),a=h,i=f)}return a.length>0&&(o+=i?_e(a,i,r):a),o}function lo(t){if(t.xAxis.categories)return t.xAxis.categories.length;for(const e of t.series)if(e.data.length>0)return e.data.length;return 0}function co(t,e){if(t.xAxis.categories)return t.xAxis.categories;if(t.xAxis.range){const{min:n,max:s}=t.xAxis.range,r=e>1?(s-n)/(e-1):0;return Array.from({length:e},(o,i)=>He(n+r*i))}return Array.from({length:e},(n,s)=>String(s+1))}function ho(t,e){const n=e-t;if(n<=0)return[t];const s=n/6,r=Math.pow(10,Math.floor(Math.log10(s))),o=s/r;let i;o<=1.5?i=r:o<=3?i=2*r:o<=7?i=5*r:i=10*r;const a=Math.ceil(t/i)*i,l=[];for(let h=a;h<=e+i*.001;h+=i)l.push(Math.round(h*1e10)/1e10);return l}function He(t){return Number.isInteger(t)?String(t):t.toFixed(Math.abs(t)<10?1:0)}function Gr(t){const e=t.trim().split(`
30
- `)[0]?.trim().toLowerCase()??"";return/^xychart(-beta)?\b/.test(e)?"xychart":/^sequencediagram\s*$/.test(e)?"sequence":/^classdiagram\s*$/.test(e)?"class":/^erdiagram\s*$/.test(e)?"er":"flowchart"}function ba(t,e={}){const n={useAscii:e.useAscii??!1,paddingX:e.paddingX??5,paddingY:e.paddingY??5,boxBorderPadding:e.boxBorderPadding??1,graphDirection:"TD"},s=e.colorMode==="auto"||e.colorMode===void 0?Ko():e.colorMode,r={...Dn,...e.theme};switch(Gr(t)){case"xychart":return _r(t,n,s,r);case"sequence":return br(t,n,s,r);case"class":return Sr(t,n,s,r);case"er":return Hr(t,n,s,r);default:{const i=Yn(t);i.direction==="LR"||i.direction==="RL"?n.graphDirection="LR":n.graphDirection="TD";const a=hs(i,n);return pr(a),lr(a),i.direction==="BT"&&(rs(a.canvas),is(a.roleCanvas)),Ee(a.canvas,{roleCanvas:a.roleCanvas,colorMode:s,theme:r})}}}function At(t,e,n){return Hn(t,e,n)}function fo(t,e){return t.length*e*.6}var rt={nodeLabel:13,edgeLabel:11,groupHeader:12},dt={nodeLabel:500,edgeLabel:400,groupHeader:600},he={horizontal:20,vertical:10,diamondExtra:24},gt={outerBox:1,innerBox:.75,connector:1},Lt="0.35em",se={width:8,height:5},je=null,de=null;function Or(){if(je)return;const t=[],e=globalThis.setTimeout;globalThis.setTimeout=(o,i)=>i===0?(t.push(o),0):e(o,i);const n=globalThis,s="self"in n,r=n.self;s&&typeof n.document>"u"&&delete n.self,je=new So,s&&(n.self=r),globalThis.setTimeout=e,t.forEach(o=>o()),de=je.worker.worker}function Qe(t){Or();let e,n;const s=de.onmessage;if(de.onmessage=r=>{r.data.error?n=r.data.error:e=r.data.data},de.dispatcher.saveDispatch({data:{id:0,cmd:"layout",graph:t}}),de.onmessage=s,n)throw n;if(!e)throw new Error("ELK layout did not return synchronously");return e}function vn(t,e,n){if(t.length<2||e.shape==="rectangle"||e.shape==="rounded"||e.shape==="stadium")return t;const s=[...t];if(e.shape==="diamond")if(n)s[0]=kn(t[0],t[1],e);else{const r=t.length-1;s[r]=kn(t[r],t[r-1],e)}return s}function kn(t,e,n){const s=n.x+n.width/2,r=n.y+n.height/2;n.width/2,n.height/2;const o={x:s,y:n.y},i={x:n.x+n.width,y:r},a={x:s,y:n.y+n.height},l={x:n.x,y:r},h=t.x-e.x,c=t.y-e.y;if(Math.abs(h)<Math.abs(c)){const f=t.x;return c>0?f<=s?Le(f,l,o)??o:Le(f,o,i)??o:f<=s?Le(f,a,l)??a:Le(f,i,a)??a}else{const f=t.y;return h>0?f<=r?Se(f,o,l)??l:Se(f,l,a)??l:f<=r?Se(f,o,i)??i:Se(f,i,a)??i}}function Se(t,e,n){const s=n.y-e.y;if(Math.abs(s)<.001)return null;const r=(t-e.y)/s;return r<0||r>1?null:{x:e.x+r*(n.x-e.x),y:t}}function Le(t,e,n){const s=n.x-e.x;if(Math.abs(s)<.001)return null;const r=(t-e.x)/s;if(r<0||r>1)return null;const o=e.y+r*(n.y-e.y);return{x:t,y:o}}var pe={font:"Inter",padding:40,nodeSpacing:28,layerSpacing:48,mergeEdges:!0,thoroughness:3};function uo(t){switch(t){case"LR":return"RIGHT";case"RL":return"LEFT";case"BT":return"UP";default:return"DOWN"}}function go(t,e,n){const s=te(e,rt.nodeLabel,dt.nodeLabel);let r=s.width+he.horizontal*2,o=s.height+he.vertical*2;if(n==="diamond"){const i=Math.max(r,o)+he.diamondExtra;r=i,o=i}if(n==="circle"||n==="doublecircle"){const i=Math.ceil(Math.sqrt(r*r+o*o))+8;r=n==="doublecircle"?i+12:i,o=r}return n==="hexagon"&&(r+=he.horizontal),(n==="trapezoid"||n==="trapezoid-alt")&&(r+=he.horizontal),n==="asymmetric"&&(r+=12),n==="cylinder"&&(o+=14),n==="state-start"||n==="state-end"?{width:28,height:28}:(r=Math.max(r,60),o=Math.max(o,36),{width:r,height:o})}function Fr(t,e){const n=new Set,s=new Set;for(const c of t.subgraphs)s.add(c.id),yo(c,n,s);const r=Jr(t.subgraphs),o=new Map;o.set(null,[]);const i=[];for(let c=0;c<t.edges.length;c++){const d=t.edges[c],f=r.get(d.source),u=r.get(d.target);f&&f===u?(o.has(f)||o.set(f,[]),o.get(f).push({index:c,edge:d})):!f&&!u?o.get(null).push({index:c,edge:d}):i.push({index:c,edge:d,sourceSubgraph:f,targetSubgraph:u})}const a=t.subgraphs.some(c=>c.direction!==void 0),l={id:"root",layoutOptions:{"elk.algorithm":"layered","elk.direction":uo(t.direction),"elk.spacing.nodeNode":String(e.nodeSpacing),"elk.layered.spacing.nodeNodeBetweenLayers":String(e.layerSpacing),"elk.spacing.edgeEdge":"12","elk.layered.spacing.edgeEdgeBetweenLayers":"12","elk.layered.spacing.edgeNodeBetweenLayers":"12","elk.padding":`[top=${e.padding},left=${e.padding},bottom=${e.padding},right=${e.padding}]`,"elk.edgeRouting":"ORTHOGONAL","elk.layered.nodePlacement.bk.fixedAlignment":"BALANCED","elk.contentAlignment":"H_CENTER V_CENTER","elk.layered.thoroughness":String(pe.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.wrapping.strategy":"OFF","elk.hierarchyHandling":a?"SEPARATE":"INCLUDE_CHILDREN"},children:[],edges:[]},h=new Map;if(a)for(const{index:c,edge:d,sourceSubgraph:f,targetSubgraph:u}of i){if(f){const g=`${f}_out_${c}`;h.has(f)||h.set(f,[]),h.get(f).push({portId:g,edgeIndex:c,direction:"outgoing",internalNodeId:d.source})}if(u){const g=`${u}_in_${c}`;h.has(u)||h.set(u,[]),h.get(u).push({portId:g,edgeIndex:c,direction:"incoming",internalNodeId:d.target})}}for(const[c,d]of t.nodes)if(!n.has(c)&&!s.has(c)){const f=go(c,d.label,d.shape);l.children.push({id:c,width:f.width,height:f.height,labels:[{text:d.label}]})}for(const c of t.subgraphs)l.children.push(xo(c,t,e,o,h));for(const{index:c,edge:d}of o.get(null)){const f={id:`e${c}`,sources:[d.source],targets:[d.target]};if(d.label){const u=te(d.label,rt.edgeLabel,dt.edgeLabel);f.labels=[{text:d.label,width:u.width+8,height:u.height+6,layoutOptions:{"elk.edgeLabels.inline":"true","elk.edgeLabels.placement":"CENTER"}}]}l.edges.push(f)}for(const{index:c,edge:d,sourceSubgraph:f,targetSubgraph:u}of i){const g={id:`e${c}`,sources:a&&f?[`${f}_out_${c}`]:[d.source],targets:a&&u?[`${u}_in_${c}`]:[d.target]};if(d.label){const x=te(d.label,rt.edgeLabel,dt.edgeLabel);g.labels=[{text:d.label,width:x.width+8,height:x.height+6,layoutOptions:{"elk.edgeLabels.inline":"true","elk.edgeLabels.placement":"CENTER"}}]}l.edges.push(g)}return l}function xo(t,e,n,s,r){const o={"elk.algorithm":"layered","elk.padding":"[top=44,left=16,bottom=16,right=16]","elk.edgeRouting":"ORTHOGONAL","elk.contentAlignment":"H_CENTER V_CENTER","elk.spacing.edgeEdge":"12","elk.layered.spacing.edgeEdgeBetweenLayers":"12","elk.layered.spacing.edgeNodeBetweenLayers":"12","elk.layered.nodePlacement.bk.fixedAlignment":"BALANCED","elk.layered.spacing.nodeNodeBetweenLayers":String(n.layerSpacing),"elk.spacing.nodeNode":String(n.nodeSpacing)};t.direction&&(o["elk.direction"]=uo(t.direction));const i={id:t.id,layoutOptions:o,labels:t.label?[{text:t.label}]:void 0,children:[],edges:[]},a=r.get(t.id)??[];a.length>0&&(i.ports=a.map(h=>({id:h.portId})));for(const h of t.nodeIds){const c=e.nodes.get(h);if(c){const d=go(h,c.label,c.shape);i.children.push({id:h,width:d.width,height:d.height,labels:[{text:c.label}]})}}for(const h of t.children)i.children.push(xo(h,e,n,s,r));const l=s.get(t.id)??[];for(const{index:h,edge:c}of l){const d={id:`e${h}`,sources:[c.source],targets:[c.target]};if(c.label){const f=te(c.label,rt.edgeLabel,dt.edgeLabel);d.labels=[{text:c.label,width:f.width+8,height:f.height+6,layoutOptions:{"elk.edgeLabels.inline":"true","elk.edgeLabels.placement":"CENTER"}}]}i.edges.push(d)}for(const h of a){const c=`e${h.edgeIndex}_internal`,d=h.direction==="incoming"?{id:c,sources:[h.portId],targets:[h.internalNodeId]}:{id:c,sources:[h.internalNodeId],targets:[h.portId]};i.edges.push(d)}return i}function yo(t,e,n){for(const s of t.nodeIds)e.add(s);for(const s of t.children)n.add(s.id),yo(s,e,n)}function Jr(t){const e=new Map;function n(s){for(const r of s.nodeIds)e.set(r,s.id);for(const r of s.children)n(r)}for(const s of t)n(s);return e}function po(t){const e=[];for(const n of t)e.push({x:n.x,y:n.y,right:n.x+n.width,bottom:n.y+n.height}),e.push(...po(n.children));return e}function Vr(t,e,n=!1){const s=[],r=[],o=[],i=new Set;for(const g of e.subgraphs)$o(g,i);Je(t,e,i,s,o,0,0);const a=po(o),l=a.length>0?{leftX:Math.min(...a.map(g=>g.x))-20,rightX:Math.max(...a.map(g=>g.right))+20}:void 0;qr(t,e,r,0,0,l),Zr(s,r,e.direction),n&&ti(r,s,o,e.direction);const h=new Map(s.map(g=>[g.id,g]));for(const g of r){const x=h.get(g.source),p=h.get(g.target);x&&(g.points=vn(g.points,x,!0)),p&&(g.points=vn(g.points,p,!1))}let c=t.width??800,d=t.height??600;const f=se.width,u=pe.padding;for(const g of r){for(const x of g.points)c=Math.max(c,x.x+f+u),d=Math.max(d,x.y+f+u);g.labelPosition&&(c=Math.max(c,g.labelPosition.x+60+u),d=Math.max(d,g.labelPosition.y+20+u))}return{width:c,height:d,nodes:s,edges:r,groups:o}}function Je(t,e,n,s,r,o,i){if(t.children)for(const a of t.children){const l=(a.x??0)+o,h=(a.y??0)+i,c=a.width??0,d=a.height??0;if(n.has(a.id)){const f=[];Je(a,e,n,s,f,l,h);const u=bo(e.subgraphs,a.id);r.push({id:a.id,label:u?.label??"",x:l,y:h,width:c,height:d,children:f})}else{const f=e.nodes.get(a.id);if(f){const u=Kr(a.id,e);s.push({id:a.id,label:f.label,shape:f.shape,x:l,y:h,width:c,height:d,inlineStyle:u})}a.children&&a.children.length>0&&Je(a,e,n,s,r,l,h)}}}function Sn(t){if(t.length===0)return{x:0,y:0};if(t.length===1)return t[0];let e=0;for(let s=1;s<t.length;s++){const r=t[s].x-t[s-1].x,o=t[s].y-t[s-1].y;e+=Math.sqrt(r*r+o*o)}let n=e/2;for(let s=1;s<t.length;s++){const r=t[s].x-t[s-1].x,o=t[s].y-t[s-1].y,i=Math.sqrt(r*r+o*o);if(n<=i){const a=n/i;return{x:t[s-1].x+a*r,y:t[s-1].y+a*o}}n-=i}return t[t.length-1]}function qr(t,e,n,s,r,o){const i=new Map;mo(t,i,0,0);let a=0;for(const[l,h]of i){const c=e.edges[l];if(!c)continue;const d=[];h.outgoing&&h.outgoing.points.length>0&&d.push(...h.outgoing.points),h.external&&h.external.points.length>0&&(d.length>0?d.push(...h.external.points.slice(1)):d.push(...h.external.points)),h.incoming&&h.incoming.points.length>0&&(d.length>0?d.push(...h.incoming.points.slice(1)):d.push(...h.incoming.points));let f;c.label&&d.length>=2&&(f=h.external?.labelPosition??Sn(d));const u=Ur(d,o,a);u!==d&&a++,c.label&&u!==d&&u.length>=2&&(f=Sn(u)),n.push({source:c.source,target:c.target,label:c.label,style:c.style,hasArrowStart:c.hasArrowStart,hasArrowEnd:c.hasArrowEnd,points:u,labelPosition:f,inlineStyle:Qr(l,e)})}}function Ur(t,e,n=0){if(t.length<2)return t;let s=!1;for(let i=1;i<t.length;i++){const a=Math.abs(t[i].x-t[i-1].x),l=Math.abs(t[i].y-t[i-1].y);if(a>1&&l>1){s=!0;break}}if(!s)return t;const r=12,o=[t[0]];for(let i=1;i<t.length;i++){const a=o[o.length-1],l=t[i],h=Math.abs(l.x-a.x),c=Math.abs(l.y-a.y);if(h>1&&c>1)if(e){const d=n%2===0,f=Math.floor(n/2)*r,u=d?e.rightX+f:e.leftX-f;o.push({x:u,y:a.y}),o.push({x:u,y:l.y})}else{const d=(a.y+l.y)/2;o.push({x:a.x,y:d}),o.push({x:l.x,y:d})}o.push(l)}return o}function mo(t,e,n,s){if(t.edges)for(const r of t.edges){const o=r.id.endsWith("_internal"),i=parseInt(r.id.substring(1),10);if(isNaN(i))continue;const a=[];if(r.sections&&r.sections.length>0){const c=r.sections[0];if(a.push({x:c.startPoint.x+n,y:c.startPoint.y+s}),c.bendPoints)for(const d of c.bendPoints)a.push({x:d.x+n,y:d.y+s});a.push({x:c.endPoint.x+n,y:c.endPoint.y+s})}let l;if(r.labels&&r.labels.length>0){const c=r.labels[0];c.x!=null&&c.y!=null&&(l={x:c.x+(c.width??0)/2+n,y:c.y+(c.height??0)/2+s})}e.has(i)||e.set(i,{});const h=e.get(i);if(o){const c=r.sources?.[0]??"",d=r.targets?.[0]??"",f=c.includes("_in_")||c.includes("_out_"),u=d.includes("_in_")||d.includes("_out_");f?h.incoming={edgeIndex:i,isInternal:o,points:a,labelPosition:l}:u&&(h.outgoing={edgeIndex:i,isInternal:o,points:a,labelPosition:l})}else h.external={edgeIndex:i,isInternal:o,points:a,labelPosition:l}}if(t.children)for(const r of t.children)mo(r,e,n+(r.x??0),s+(r.y??0))}function bo(t,e){for(const n of t){if(n.id===e)return n;const s=bo(n.children,e);if(s)return s}}function $o(t,e){e.add(t.id);for(const n of t.children)$o(n,e)}function Kr(t,e){let n;const s=e.classAssignments.get(t);if(s){const o=e.classDefs.get(s);o&&(n={...o})}const r=e.nodeStyles.get(t);return r&&(n=n?{...n,...r}:{...r}),n}function Qr(t,e){let n;const s=e.linkStyles.get("default");s&&(n={...s});const r=e.linkStyles.get(t);return r&&(n=n?{...n,...r}:{...r}),n}function Zr(t,e,n){if(t.length===0)return;const s=n==="LR"||n==="RL",r=new Set;for(const c of e)r.add(`${c.source}:${c.target}`),r.add(`${c.target}:${c.source}`);const o=pe.layerSpacing*.6,i=[...t].sort((c,d)=>s?c.x-d.x:c.y-d.y),a=[];let l=[i[0]];for(let c=1;c<i.length;c++){const d=s?i[c].x:i[c].y,f=s?i[c-1].x:i[c-1].y,u=d-f,g=l.some(x=>r.has(`${x.id}:${i[c].id}`));u<=o&&!g?l.push(i[c]):(a.push(l),l=[i[c]])}a.push(l);const h=new Map;for(const c of a){if(c.length<=1)continue;const d=c.map(x=>s?x.x:x.y),f=Math.min(...d),u=Math.max(...d);if(u-f<=1)continue;const g=(f+u)/2;for(const x of c){const p=s?x.x:x.y,M=g-p;Math.abs(M)>.5&&(s?x.x=g:x.y=g,h.set(x.id,M))}}if(h.size!==0){new Map(t.map(c=>[c.id,c]));for(const c of e){if(c.points.length<2)continue;const d=h.get(c.source),f=h.get(c.target);if(d!=null){const u=c.points[0];s?(u.x+=d,c.points.length>1&&c.points[1].x===u.x-d&&(c.points[1].x+=d)):(u.y+=d,c.points.length>1&&c.points[1].y===u.y-d&&(c.points[1].y+=d))}if(f!=null){const u=c.points[c.points.length-1];if(s){if(u.x+=f,c.points.length>1){const g=c.points[c.points.length-2];g.x===u.x-f&&(g.x+=f)}}else if(u.y+=f,c.points.length>1){const g=c.points[c.points.length-2];g.y===u.y-f&&(g.y+=f)}}}}}function Ve(t,e,n){const s=[];for(const r of n)t>=r.x&&t<=r.x+r.width&&e>=r.y&&e<=r.y+r.height&&(s.push(r),s.push(...Ve(t,e,r.children)));return s}function Ae(t,e,n,s,r){const i=r==="LR",a=r==="RL",l=r==="BT",h=i||a,c=new Set(Ve(e,n,s).map(x=>x.id)),g=Ve(h?t:e,h?n:t,s).find(x=>!c.has(x.id));return g?i?g.x-12:a?g.x+g.width+12:l?g.y+g.height+12:g.y-12:t}function ti(t,e,n,s){const r=new Map(e.map(f=>[f.id,f])),o=new Set,i=s==="LR",a=s==="RL",l=s==="BT",h=i||a,c=new Map;for(const f of t)f.source!==f.target&&(c.has(f.source)||c.set(f.source,[]),c.get(f.source).push(f));for(const[f,u]of c){if(u.length<2)continue;const g=u[0].style;if(u.some(C=>C.label||C.style!==g))continue;const x=r.get(f);if(!x)continue;const p=u.filter(C=>{const w=r.get(C.target);return w?i?w.x>x.x+x.width:a?w.x+w.width<x.x:l?w.y+w.height<x.y:w.y>x.y+x.height:!1});if(p.length<2)continue;const M=p.map(C=>({edge:C,node:r.get(C.target)})),D=x.x+x.width/2,A=x.y+x.height/2;if(h){const C=i?x.x+x.width:x.x,w=A,O=i?Math.min(...M.map(y=>y.node.x)):Math.max(...M.map(y=>y.node.x+y.node.width));let st=C+(O-C)/2;st=Ae(st,D,A,n,s);for(const{edge:y,node:m}of M){const S=i?m.x:m.x+m.width,X=m.y+m.height/2;y.points=[{x:C,y:w},{x:st,y:w},{x:st,y:X},{x:S,y:X}],o.add(y)}}else{const C=D,w=l?x.y:x.y+x.height,O=l?Math.max(...M.map(y=>y.node.y+y.node.height)):Math.min(...M.map(y=>y.node.y));let st=w+(O-w)/2;st=Ae(st,D,A,n,s);for(const{edge:y,node:m}of M){const S=m.x+m.width/2,X=l?m.y+m.height:m.y;y.points=[{x:C,y:w},{x:C,y:st},{x:S,y:st},{x:S,y:X}],o.add(y)}}}const d=new Map;for(const f of t)o.has(f)||f.source===f.target||(d.has(f.target)||d.set(f.target,[]),d.get(f.target).push(f));for(const[f,u]of d){if(u.length<2)continue;const g=u[0].style;if(u.some(C=>C.label||C.style!==g))continue;const x=r.get(f);if(!x)continue;const p=u.filter(C=>{const w=r.get(C.source);return w?i?w.x+w.width<x.x:a?w.x>x.x+x.width:l?w.y>x.y+x.height:w.y+w.height<x.y:!1});if(p.length<2)continue;const M=p.map(C=>({edge:C,node:r.get(C.source)})),D=x.x+x.width/2,A=x.y+x.height/2;if(h){const C=i?x.x:x.x+x.width,w=A,O=i?Math.max(...M.map(y=>y.node.x+y.node.width)):Math.min(...M.map(y=>y.node.x));let st=O+(C-O)/2;st=Ae(st,D,A,n,s);for(const{edge:y,node:m}of M){const S=i?m.x+m.width:m.x,X=m.y+m.height/2;y.points=[{x:S,y:X},{x:st,y:X},{x:st,y:w},{x:C,y:w}]}}else{const C=D,w=l?x.y+x.height:x.y,O=l?Math.min(...M.map(y=>y.node.y)):Math.max(...M.map(y=>y.node.y+y.node.height));let st=O+(w-O)/2;st=Ae(st,D,A,n,s);for(const{edge:y,node:m}of M){const S=m.x+m.width/2,X=l?m.y:m.y+m.height;y.points=[{x:S,y:X},{x:S,y:st},{x:C,y:st},{x:C,y:w}]}}}}function ei(t,e={}){const n={...pe,...e},s=Fr(t,n),r=Qe(s);return Vr(r,t,pe.mergeEdges)}function ni(t,e,n="Inter",s=!1){const r=[];r.push(be(t.width,t.height,e,s)),r.push(me(n,!1)),r.push("<defs>"),r.push(oi());const o=new Set;for(const i of t.edges)i.inlineStyle?.stroke&&o.add(i.inlineStyle.stroke);for(const i of o)r.push(si(i));r.push("</defs>");for(const i of t.groups)r.push(Mo(i));for(const i of t.edges)r.push(ri(i));for(const i of t.edges)i.label&&r.push(ai(i));for(const i of t.nodes)r.push(ci(i));return r.push("</svg>"),r.join(`
31
- `)}function oi(){const t=se.width,e=se.height,n='fill="var(--_arrow)" stroke="var(--_arrow)" stroke-width="0.75" stroke-linejoin="round"',s=t-1;return` <marker id="arrowhead" markerWidth="${t}" markerHeight="${e}" refX="${s}" refY="${e/2}" orient="auto">
32
- <polygon points="0 0, ${t} ${e/2}, 0 ${e}" ${n} />
33
- </marker>
34
- <marker id="arrowhead-start" markerWidth="${t}" markerHeight="${e}" refX="1" refY="${e/2}" orient="auto-start-reverse">
35
- <polygon points="${t} 0, 0 ${e/2}, ${t} ${e}" ${n} />
36
- </marker>`}function si(t){const e=se.width,n=se.height,s=St(t),r=`fill="${s}" stroke="${s}" stroke-width="0.75" stroke-linejoin="round"`,o=e-1,i=wo(t);return` <marker id="arrowhead-${i}" markerWidth="${e}" markerHeight="${n}" refX="${o}" refY="${n/2}" orient="auto">
37
- <polygon points="0 0, ${e} ${n/2}, 0 ${n}" ${r} />
38
- </marker>
39
- <marker id="arrowhead-start-${i}" markerWidth="${e}" markerHeight="${n}" refX="1" refY="${n/2}" orient="auto-start-reverse">
40
- <polygon points="${e} 0, 0 ${n/2}, ${e} ${n}" ${r} />
41
- </marker>`}function wo(t){return t.replace(/[^a-zA-Z0-9]/g,e=>e.charCodeAt(0).toString(16))}function Mo(t,e){const n=rt.groupHeader+16,s=[];s.push(`<g class="subgraph" data-id="${St(t.id)}" data-label="${St(t.label)}">`),s.push(` <rect x="${t.x}" y="${t.y}" width="${t.width}" height="${t.height}" rx="0" ry="0" fill="var(--_group-fill)" stroke="var(--_node-stroke)" stroke-width="${gt.outerBox}" />`),s.push(` <rect x="${t.x}" y="${t.y}" width="${t.width}" height="${n}" rx="0" ry="0" fill="var(--_group-hdr)" stroke="var(--_node-stroke)" stroke-width="${gt.outerBox}" />`),s.push(" "+Ct(t.label,t.x+12,t.y+n/2,rt.groupHeader,`font-size="${rt.groupHeader}" font-weight="${dt.groupHeader}" fill="var(--_text-sec)"`));for(const r of t.children)s.push(Mo(r));return s.push("</g>"),s.join(`
42
- `)}function ri(t){if(t.points.length<2)return"";const e=ii(t.points),n=t.style==="dotted"?' stroke-dasharray="4 4"':"",s=t.style==="thick"?gt.connector*2:gt.connector,r=St(t.inlineStyle?.stroke??"var(--_line)"),o=St(t.inlineStyle?.["stroke-width"]??String(s)),i=t.inlineStyle?.stroke?`-${wo(t.inlineStyle.stroke)}`:"";let a="";t.hasArrowEnd&&(a+=` marker-end="url(#arrowhead${i})"`),t.hasArrowStart&&(a+=` marker-start="url(#arrowhead-start${i})"`);const l=['class="edge"',`data-from="${St(t.source)}"`,`data-to="${St(t.target)}"`,`data-style="${t.style}"`,`data-arrow-start="${t.hasArrowStart}"`,`data-arrow-end="${t.hasArrowEnd}"`];return t.label&&l.push(`data-label="${St(t.label)}"`),`<polyline ${l.join(" ")} points="${e}" fill="none" stroke="${r}" stroke-width="${o}"${n}${a} />`}function ii(t){return t.map(e=>`${e.x},${e.y}`).join(" ")}function ai(t,e){const n=t.labelPosition??li(t.points),s=t.label,r=8,o=te(s,rt.edgeLabel,dt.edgeLabel),i=_o(s,n.x,n.y,o.width,o.height,rt.edgeLabel,r,`text-anchor="middle" font-size="${rt.edgeLabel}" font-weight="${dt.edgeLabel}" fill="var(--_text-sec)"`,'rx="2" ry="2" fill="var(--bg)" stroke="var(--_inner-stroke)" stroke-width="1"');return`<g class="edge-label" data-from="${St(t.source)}" data-to="${St(t.target)}" data-label="${St(s)}">
43
- ${i.replace(/\n/g,`
44
- `)}
45
- </g>`}function li(t){if(t.length===0)return{x:0,y:0};if(t.length===1)return t[0];let e=0;for(let s=1;s<t.length;s++)e+=Ln(t[s-1],t[s]);let n=e/2;for(let s=1;s<t.length;s++){const r=Ln(t[s-1],t[s]);if(n<=r){const o=n/r;return{x:t[s-1].x+o*(t[s].x-t[s-1].x),y:t[s-1].y+o*(t[s].y-t[s-1].y)}}n-=r}return t[t.length-1]}function Ln(t,e){return Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2)}function ci(t,e){const n=hi(t),s=Si(t),r=[];return r.push(`<g class="node" data-id="${St(t.id)}" data-label="${St(t.label)}" data-shape="${t.shape}">`),r.push(` ${n.replace(/\n/g,`
46
- `)}`),s&&r.push(` ${s.replace(/\n/g,`
47
- `)}`),r.push("</g>"),r.join(`
48
- `)}function hi(t){const{x:e,y:n,width:s,height:r,shape:o,inlineStyle:i}=t,a=St(i?.fill??"var(--_node-fill)"),l=St(i?.stroke??"var(--_node-stroke)"),h=St(i?.["stroke-width"]??String(gt.innerBox));switch(o){case"diamond":return xi(e,n,s,r,a,l,h);case"rounded":return di(e,n,s,r,a,l,h);case"stadium":return ui(e,n,s,r,a,l,h);case"circle":return gi(e,n,s,r,a,l,h);case"subroutine":return yi(e,n,s,r,a,l,h);case"doublecircle":return pi(e,n,s,r,a,l,h);case"hexagon":return mi(e,n,s,r,a,l,h);case"cylinder":return bi(e,n,s,r,a,l,h);case"asymmetric":return $i(e,n,s,r,a,l,h);case"trapezoid":return wi(e,n,s,r,a,l,h);case"trapezoid-alt":return Mi(e,n,s,r,a,l,h);case"state-start":return vi(e,n,s,r);case"state-end":return ki(e,n,s,r);default:return fi(e,n,s,r,a,l,h)}}function fi(t,e,n,s,r,o,i){return`<rect x="${t}" y="${e}" width="${n}" height="${s}" rx="0" ry="0" fill="${r}" stroke="${o}" stroke-width="${i}" />`}function di(t,e,n,s,r,o,i){return`<rect x="${t}" y="${e}" width="${n}" height="${s}" rx="6" ry="6" fill="${r}" stroke="${o}" stroke-width="${i}" />`}function ui(t,e,n,s,r,o,i){const a=s/2;return`<rect x="${t}" y="${e}" width="${n}" height="${s}" rx="${a}" ry="${a}" fill="${r}" stroke="${o}" stroke-width="${i}" />`}function gi(t,e,n,s,r,o,i){const a=t+n/2,l=e+s/2,h=Math.min(n,s)/2;return`<circle cx="${a}" cy="${l}" r="${h}" fill="${r}" stroke="${o}" stroke-width="${i}" />`}function xi(t,e,n,s,r,o,i){const a=t+n/2,l=e+s/2,h=n/2,c=s/2;return`<polygon points="${[`${a},${l-c}`,`${a+h},${l}`,`${a},${l+c}`,`${a-h},${l}`].join(" ")}" fill="${r}" stroke="${o}" stroke-width="${i}" />`}function yi(t,e,n,s,r,o,i){return`<rect x="${t}" y="${e}" width="${n}" height="${s}" rx="0" ry="0" fill="${r}" stroke="${o}" stroke-width="${i}" />
49
- <line x1="${t+8}" y1="${e}" x2="${t+8}" y2="${e+s}" stroke="${o}" stroke-width="${i}" />
50
- <line x1="${t+n-8}" y1="${e}" x2="${t+n-8}" y2="${e+s}" stroke="${o}" stroke-width="${i}" />`}function pi(t,e,n,s,r,o,i){const a=t+n/2,l=e+s/2,h=Math.min(n,s)/2,c=h-5;return`<circle cx="${a}" cy="${l}" r="${h}" fill="${r}" stroke="${o}" stroke-width="${i}" />
51
- <circle cx="${a}" cy="${l}" r="${c}" fill="${r}" stroke="${o}" stroke-width="${i}" />`}function mi(t,e,n,s,r,o,i){const a=s/4;return`<polygon points="${[`${t+a},${e}`,`${t+n-a},${e}`,`${t+n},${e+s/2}`,`${t+n-a},${e+s}`,`${t+a},${e+s}`,`${t},${e+s/2}`].join(" ")}" fill="${r}" stroke="${o}" stroke-width="${i}" />`}function bi(t,e,n,s,r,o,i){const l=t+n/2,h=e+7,c=s-14;return`<rect x="${t}" y="${h}" width="${n}" height="${c}" fill="${r}" stroke="none" />
52
- <line x1="${t}" y1="${h}" x2="${t}" y2="${h+c}" stroke="${o}" stroke-width="${i}" />
53
- <line x1="${t+n}" y1="${h}" x2="${t+n}" y2="${h+c}" stroke="${o}" stroke-width="${i}" />
54
- <ellipse cx="${l}" cy="${e+s-7}" rx="${n/2}" ry="7" fill="${r}" stroke="${o}" stroke-width="${i}" />
55
- <ellipse cx="${l}" cy="${h}" rx="${n/2}" ry="7" fill="${r}" stroke="${o}" stroke-width="${i}" />`}function $i(t,e,n,s,r,o,i){return`<polygon points="${[`${t+12},${e}`,`${t+n},${e}`,`${t+n},${e+s}`,`${t+12},${e+s}`,`${t},${e+s/2}`].join(" ")}" fill="${r}" stroke="${o}" stroke-width="${i}" />`}function wi(t,e,n,s,r,o,i){const a=n*.15;return`<polygon points="${[`${t+a},${e}`,`${t+n-a},${e}`,`${t+n},${e+s}`,`${t},${e+s}`].join(" ")}" fill="${r}" stroke="${o}" stroke-width="${i}" />`}function Mi(t,e,n,s,r,o,i){const a=n*.15;return`<polygon points="${[`${t},${e}`,`${t+n},${e}`,`${t+n-a},${e+s}`,`${t+a},${e+s}`].join(" ")}" fill="${r}" stroke="${o}" stroke-width="${i}" />`}function vi(t,e,n,s){const r=t+n/2,o=e+s/2,i=Math.min(n,s)/2-2;return`<circle cx="${r}" cy="${o}" r="${i}" fill="var(--_text)" stroke="none" />`}function ki(t,e,n,s){const r=t+n/2,o=e+s/2,i=Math.min(n,s)/2-2,a=i-4;return`<circle cx="${r}" cy="${o}" r="${i}" fill="none" stroke="var(--_text)" stroke-width="${gt.innerBox*2}" />
56
- <circle cx="${r}" cy="${o}" r="${a}" fill="var(--_text)" stroke="none" />`}function Si(t,e){if((t.shape==="state-start"||t.shape==="state-end")&&!t.label)return"";const n=t.x+t.width/2,s=t.y+t.height/2,r=St(t.inlineStyle?.color??"var(--_text)");return Ct(t.label,n,s,rt.nodeLabel,`text-anchor="middle" font-size="${rt.nodeLabel}" font-weight="${dt.nodeLabel}" fill="${r}"`)}function St(t){return t.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var ct={padding:30,actorGap:140,actorHeight:40,actorPadX:16,headerGap:20,messageRowHeight:40,selfMessageHeight:30,activationWidth:10,blockPadX:10,blockPadTop:40,blockPadBottom:8,blockHeaderExtra:28,dividerExtra:24,noteWidth:60,notePadX:12,notePadY:6,noteGap:10};function Li(t,e={}){if(t.actors.length===0)return{width:0,height:0,actors:[],lifelines:[],messages:[],activations:[],blocks:[],notes:[]};const n=t.actors.map(m=>{const S=At(m.label,rt.nodeLabel,dt.nodeLabel);return Math.max(S+ct.actorPadX*2,80)}),s=[];let r=ct.padding+n[0]/2;for(let m=0;m<t.actors.length;m++){if(m>0){const S=Math.max(ct.actorGap,(n[m-1]+n[m])/2+40);r+=S}s.push(r)}const o=new Map;for(let m=0;m<t.actors.length;m++)o.set(t.actors[m].id,m);const i=ct.padding,a=t.actors.map((m,S)=>({id:m.id,label:m.label,type:m.type,x:s[S],y:i,width:n[S],height:ct.actorHeight}));let l=i+ct.actorHeight+ct.headerGap;const h=[],c=new Map;for(const m of t.blocks){const S=c.get(m.startIndex)??0;c.set(m.startIndex,Math.max(S,ct.blockHeaderExtra));for(const X of m.dividers){const v=c.get(X.index)??0;c.set(X.index,Math.max(v,ct.dividerExtra))}}const d=new Map;for(const m of t.notes){const S=d.get(m.afterIndex)??[];S.push(m),d.set(m.afterIndex,S)}const f=[],u=new Map,g=[],x=4;for(let m=0;m<t.messages.length;m++){const S=t.messages[m],X=o.get(S.from)??0,v=o.get(S.to)??0,z=S.from===S.to,F=c.get(m)??0;F>0&&(l+=F);const V=s[X],Y=s[v];if(h.push({from:S.from,to:S.to,label:S.label,lineStyle:S.lineStyle,arrowHead:S.arrowHead,x1:V,x2:Y,y:l,isSelf:z}),S.activate){u.has(S.to)||u.set(S.to,[]);const at=u.get(S.to),tt=at.length;at.push({startY:l,depth:tt})}if(S.deactivate){const at=u.get(S.from);if(at&&at.length>0){const{startY:tt,depth:L}=at.pop(),P=o.get(S.from)??0,H=L*x;g.push({actorId:S.from,x:s[P]-ct.activationWidth/2+H,topY:tt,bottomY:l,width:ct.activationWidth})}}l+=z?ct.selfMessageHeight+ct.messageRowHeight:ct.messageRowHeight;const Z=d.get(m);if(Z&&Z.length>0){const at=z?ct.selfMessageHeight:0;let tt=h[m].y+at+8;for(const L of Z){const P=Math.max(ct.noteWidth,At(L.text,rt.edgeLabel,dt.edgeLabel)+ct.notePadX*2),H=rt.edgeLabel+ct.notePadY*2,k=o.get(L.actorIds[0]??"")??0;let j;if(L.position==="left")j=s[k]-n[k]/2-P-ct.noteGap;else if(L.position==="right")j=s[k]+n[k]/2+ct.noteGap;else if(L.actorIds.length>1){const et=o.get(L.actorIds[L.actorIds.length-1]??"")??k;j=(s[k]+s[et])/2-P/2}else j=s[k]-P/2;f.push({text:L.text,x:j,y:tt,width:P,height:H,position:L.position,actors:L.actorIds}),tt+=H+4}l=Math.max(l,tt+ct.messageRowHeight/2)}}for(const[m,S]of u)for(const{startY:X,depth:v}of S){const z=o.get(m)??0,F=v*x;g.push({actorId:m,x:s[z]-ct.activationWidth/2+F,topY:X,bottomY:l-ct.messageRowHeight/2,width:ct.activationWidth})}const p=t.blocks.map(m=>{const S=h[m.startIndex],X=h[m.endIndex],v=(S?.y??l)-ct.blockPadTop,z=(X?.y??l)+ct.blockPadBottom+12,F=new Set;for(let L=m.startIndex;L<=m.endIndex;L++){const P=t.messages[L];P&&(F.add(o.get(P.from)??0),F.add(o.get(P.to)??0))}if(F.size===0)for(let L=0;L<t.actors.length;L++)F.add(L);const V=Math.min(...F),Y=Math.max(...F),Z=s[V]-n[V]/2-ct.blockPadX,at=s[Y]+n[Y]/2+ct.blockPadX,tt=m.dividers.map(L=>{const P=h[L.index],H=P?.y??l;let k=28;if(L.label&&P?.label){const j=`[${L.label}]`,et=At(j,rt.edgeLabel,dt.edgeLabel),$=Z+8,I=$+et,B=At(P.label,rt.edgeLabel,dt.edgeLabel),_=P.isSelf?P.x1+36:(P.x1+P.x2)/2-B/2,N=_+B;I>_&&$<N&&(k=36)}return{y:H-k,label:L.label}});return{type:m.type,label:m.label,x:Z,y:v,width:at-Z,height:z-v,dividers:tt}}),M=f,D=l+ct.padding;let A=ct.padding,C=0;for(const m of a)A=Math.min(A,m.x-m.width/2),C=Math.max(C,m.x+m.width/2);for(const m of p)A=Math.min(A,m.x),C=Math.max(C,m.x+m.width);for(const m of M)A=Math.min(A,m.x),C=Math.max(C,m.x+m.width);for(const m of h)if(m.isSelf&&m.label){const v=m.x1+30+8,z=At(m.label,rt.edgeLabel,dt.edgeLabel);C=Math.max(C,v+z+8)}const w=A<ct.padding?ct.padding-A:0;if(w>0){for(const m of a)m.x+=w;for(const m of h)m.x1+=w,m.x2+=w;for(const m of g)m.x+=w;for(const m of p)m.x+=w;for(const m of M)m.x+=w;for(let m=0;m<s.length;m++)s[m]+=w}const O=t.actors.map((m,S)=>({actorId:m.id,x:s[S],topY:i+ct.actorHeight,bottomY:D-ct.padding})),st=C+w+ct.padding,y=D;return{width:Math.max(st,200),height:Math.max(y,100),actors:a,lifelines:O,messages:h,activations:g,blocks:p,notes:M}}function Ai(t,e,n="Inter",s=!1){const r=[];r.push(be(t.width,t.height,e,s)),r.push(me(n,!1)),r.push("<defs>"),r.push(Ci()),r.push("</defs>");for(const o of t.blocks)r.push(Wi(o));for(const o of t.lifelines)r.push(Ii(o));for(const o of t.activations)r.push(Ri(o));for(const o of t.messages)r.push(Hi(o));for(const o of t.notes)r.push(Yi(o));for(const o of t.actors)r.push(Ti(o));return r.push("</svg>"),r.join(`
57
- `)}function Ci(){const t=se.width,e=se.height;return` <marker id="seq-arrow" markerWidth="${t}" markerHeight="${e}" refX="${t}" refY="${e/2}" orient="auto-start-reverse">
58
- <polygon points="0 0, ${t} ${e/2}, 0 ${e}" fill="var(--_arrow)" />
59
- </marker>
60
- <marker id="seq-arrow-open" markerWidth="${t}" markerHeight="${e}" refX="${t}" refY="${e/2}" orient="auto-start-reverse">
61
- <polyline points="0 0, ${t} ${e/2}, 0 ${e}" fill="none" stroke="var(--_arrow)" stroke-width="1" />
62
- </marker>`}function Ti(t){const{id:e,x:n,y:s,width:r,height:o,label:i,type:a}=t,l=[];if(l.push(`<g class="actor" data-id="${Et(e)}" data-label="${Et(i)}" data-type="${a}">`),a==="actor"){const h=o/24*.9,c=n-12*h,d=s+(o-24*h)/2,f=gt.outerBox/h,u="var(--_line)";l.push(` <g transform="translate(${c},${d}) scale(${h})">
63
- <path d="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" fill="none" stroke="${u}" stroke-width="${f}" />
64
- <path d="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" fill="none" stroke="${u}" stroke-width="${f}" />
65
- <path d="M5.62842 18.3563C7.08963 17.0398 9.39997 16 12 16C14.6 16 16.9104 17.0398 18.3716 18.3563" fill="none" stroke="${u}" stroke-width="${f}" />
66
- </g>`),l.push(" "+Ct(i,n,s+o+14,rt.nodeLabel,`font-size="${rt.nodeLabel}" text-anchor="middle" font-weight="${dt.nodeLabel}" fill="var(--_text)"`))}else{const h=n-r/2;l.push(` <rect x="${h}" y="${s}" width="${r}" height="${o}" rx="4" ry="4" fill="var(--_node-fill)" stroke="var(--_node-stroke)" stroke-width="${gt.outerBox}" />`),l.push(" "+Ct(i,n,s+o/2,rt.nodeLabel,`font-size="${rt.nodeLabel}" text-anchor="middle" font-weight="${dt.nodeLabel}" fill="var(--_text)"`))}return l.push("</g>"),l.join(`
67
- `)}function Ii(t){return`<line class="lifeline" data-actor="${Et(t.actorId)}" x1="${t.x}" y1="${t.topY}" x2="${t.x}" y2="${t.bottomY}" stroke="var(--_line)" stroke-width="0.75" stroke-dasharray="6 4" />`}function Ri(t){return`<rect class="activation" data-actor="${Et(t.actorId)}" x="${t.x}" y="${t.topY}" width="${t.width}" height="${t.bottomY-t.topY}" fill="var(--_node-fill)" stroke="var(--_node-stroke)" stroke-width="${gt.innerBox}" />`}function Hi(t){const e=[],n=t.lineStyle==="dashed"?' stroke-dasharray="6 4"':"",s=t.arrowHead==="filled"?"seq-arrow":"seq-arrow-open";if(e.push(`<g class="message" data-from="${Et(t.from)}" data-to="${Et(t.to)}" data-label="${Et(t.label)}" data-line-style="${t.lineStyle}" data-arrow-head="${t.arrowHead}" data-self="${t.isSelf}">`),t.isSelf)e.push(` <polyline points="${t.x1},${t.y} ${t.x1+30},${t.y} ${t.x1+30},${t.y+20} ${t.x2},${t.y+20}" fill="none" stroke="var(--_line)" stroke-width="${gt.connector}"${n} marker-end="url(#${s})" />`),e.push(" "+Ct(t.label,t.x1+30+8,t.y+20/2,rt.edgeLabel,`font-size="${rt.edgeLabel}" text-anchor="start" font-weight="${dt.edgeLabel}" fill="var(--_text-muted)"`));else{e.push(` <line x1="${t.x1}" y1="${t.y}" x2="${t.x2}" y2="${t.y}" stroke="var(--_line)" stroke-width="${gt.connector}"${n} marker-end="url(#${s})" />`);const r=(t.x1+t.x2)/2;e.push(" "+Ct(t.label,r,t.y-10,rt.edgeLabel,`font-size="${rt.edgeLabel}" text-anchor="middle" font-weight="${dt.edgeLabel}" fill="var(--_text-muted)"`))}return e.push("</g>"),e.join(`
68
- `)}function Wi(t){const e=[],n=t.label?` data-label="${Et(t.label)}"`:"";e.push(`<g class="block" data-type="${Et(t.type)}"${n}>`),e.push(` <rect x="${t.x}" y="${t.y}" width="${t.width}" height="${t.height}" rx="0" ry="0" fill="none" stroke="var(--_node-stroke)" stroke-width="${gt.outerBox}" />`);const s=`${t.type}${t.label?` [${t.label}]`:""}`,r=s.split(`
69
- `)[0],o=At(r,rt.edgeLabel,dt.groupHeader)+16,i=18;e.push(` <rect x="${t.x}" y="${t.y}" width="${o}" height="${i}" fill="var(--_group-hdr)" stroke="var(--_node-stroke)" stroke-width="${gt.outerBox}" />`),e.push(" "+Ct(s,t.x+6,t.y+i/2,rt.edgeLabel,`font-size="${rt.edgeLabel}" font-weight="${dt.groupHeader}" fill="var(--_text-sec)"`));for(const a of t.dividers)e.push(` <line x1="${t.x}" y1="${a.y}" x2="${t.x+t.width}" y2="${a.y}" stroke="var(--_line)" stroke-width="0.75" stroke-dasharray="6 4" />`),a.label&&e.push(" "+Ct(`[${a.label}]`,t.x+8,a.y+14,rt.edgeLabel,`font-size="${rt.edgeLabel}" text-anchor="start" font-weight="${dt.edgeLabel}" fill="var(--_text-muted)"`));return e.push("</g>"),e.join(`
70
- `)}function Yi(t){const{x:n,y:s,width:r,height:o}=t,i=t.actors&&t.actors.length>0?` data-actors="${t.actors.map(Et).join(",")}"`:"",a=t.position?` data-position="${Et(t.position)}"`:"",l=[`${n},${s}`,`${n+r-6},${s}`,`${n+r},${s+6}`,`${n+r},${s+o}`,`${n},${s+o}`].join(" ");return`<g class="note"${a}${i}>
71
- <polygon points="${l}" fill="var(--bg)" stroke="var(--_node-stroke)" stroke-width="${gt.innerBox}" />
72
- <polygon points="${n+r-6},${s} ${n+r},${s+6} ${n+r-6},${s+6}" fill="var(--_inner-stroke)" stroke="var(--_node-stroke)" stroke-width="${gt.innerBox}" />
73
- ${Ct(t.text,n+r/2,s+o/2,rt.edgeLabel,`font-size="${rt.edgeLabel}" text-anchor="middle" font-weight="${dt.edgeLabel}" fill="var(--_text-muted)"`)}
74
- </g>`}function Et(t){return t.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var yt={padding:40,boxPadX:8,headerBaseHeight:32,annotationHeight:16,memberRowHeight:20,sectionPadY:8,emptySectionHeight:8,minWidth:120,memberFontSize:11,nodeSpacing:40,layerSpacing:60};function Di(t,e){const n=new Map;for(const r of t.classes){const o=r.annotation?yt.headerBaseHeight+yt.annotationHeight:yt.headerBaseHeight,i=r.attributes.length>0?r.attributes.length*yt.memberRowHeight+yt.sectionPadY:yt.emptySectionHeight,a=r.methods.length>0?r.methods.length*yt.memberRowHeight+yt.sectionPadY:yt.emptySectionHeight,l=At(r.label,rt.nodeLabel,dt.nodeLabel),h=An(r.attributes),c=An(r.methods),d=Math.max(yt.minWidth,l+yt.boxPadX*2,h+yt.boxPadX*2,c+yt.boxPadX*2),f=o+i+a;n.set(r.id,{width:d,height:f,headerHeight:o,attrHeight:i,methodHeight:a})}const s={id:"root",layoutOptions:{"elk.algorithm":"layered","elk.direction":"DOWN","elk.spacing.nodeNode":String(yt.nodeSpacing),"elk.layered.spacing.nodeNodeBetweenLayers":String(yt.layerSpacing),"elk.padding":`[top=${yt.padding},left=${yt.padding},bottom=${yt.padding},right=${yt.padding}]`,"elk.edgeRouting":"ORTHOGONAL","elk.edgeLabels.placement":"CENTER"},children:[],edges:[]};for(const r of t.classes){const o=n.get(r.id);s.children.push({id:r.id,width:o.width,height:o.height})}for(let r=0;r<t.relationships.length;r++){const o=t.relationships[r],i={id:`e${r}`,sources:[o.from],targets:[o.to]};if(o.label){const a=te(o.label,rt.edgeLabel,dt.edgeLabel);i.labels=[{text:o.label,width:a.width+8,height:a.height+6}]}s.edges.push(i)}return{elkGraph:s,classSizes:n}}function Ei(t,e,n){const s=new Map;for(const i of e.classes)s.set(i.id,i);const r=[];for(const i of t.children??[]){const a=s.get(i.id);if(a){const l=n.get(a.id);r.push({id:a.id,label:a.label,annotation:a.annotation,attributes:a.attributes,methods:a.methods,x:i.x??0,y:i.y??0,width:i.width??l.width,height:i.height??l.height,headerHeight:l.headerHeight,attrHeight:l.attrHeight,methodHeight:l.methodHeight})}}const o=[];for(let i=0;i<(t.edges?.length??0);i++){const a=t.edges[i],l=e.relationships[i],h=[];if(a.sections&&a.sections.length>0){const d=a.sections[0];if(h.push({x:d.startPoint.x,y:d.startPoint.y}),d.bendPoints)for(const f of d.bendPoints)h.push({x:f.x,y:f.y});h.push({x:d.endPoint.x,y:d.endPoint.y})}let c;if(a.labels&&a.labels.length>0){const d=a.labels[0];d.x!=null&&d.y!=null&&(c={x:d.x+(d.width??0)/2,y:d.y+(d.height??0)/2})}o.push({from:l.from,to:l.to,type:l.type,markerAt:l.markerAt,label:l.label,fromCardinality:l.fromCardinality,toCardinality:l.toCardinality,points:h,labelPosition:c})}return{width:t.width??600,height:t.height??400,classes:r,relationships:o}}function Xi(t,e={}){if(t.classes.length===0)return{width:0,height:0,classes:[],relationships:[]};const{elkGraph:n,classSizes:s}=Di(t),r=Qe(n);return Ei(r,t,s)}function An(t){if(t.length===0)return 0;let e=0;for(const n of t){const s=_i(n),r=fo(s,yt.memberFontSize);r>e&&(e=r)}return e}function _i(t){const e=t.visibility?`${t.visibility} `:"",n=t.isMethod?`${t.name}(${t.params||""})`:t.name,s=t.type?`: ${t.type}`:"";return`${e}${n}${s}`}var We={memberSize:11,memberWeight:400,annotationSize:10,annotationWeight:500};function Pi(t,e,n="Inter",s=!1){const r=[];r.push(be(t.width,t.height,e,s)),r.push(me(n,!0)),r.push("<defs>"),r.push(zi()),r.push("</defs>");for(const o of t.relationships)r.push(Ni(o));for(const o of t.classes)r.push(Bi(o));for(const o of t.relationships)r.push(Oi(o));return r.push("</svg>"),r.join(`
75
- `)}function zi(){return` <marker id="cls-inherit" markerWidth="12" markerHeight="10" refX="12" refY="5" orient="auto-start-reverse">
76
- <polygon points="0 0, 12 5, 0 10" fill="var(--bg)" stroke="var(--_arrow)" stroke-width="1.5" />
77
- </marker>
78
- <marker id="cls-composition" markerWidth="12" markerHeight="10" refX="0" refY="5" orient="auto-start-reverse">
79
- <polygon points="6 0, 12 5, 6 10, 0 5" fill="var(--_arrow)" stroke="var(--_arrow)" stroke-width="1" />
80
- </marker>
81
- <marker id="cls-aggregation" markerWidth="12" markerHeight="10" refX="0" refY="5" orient="auto-start-reverse">
82
- <polygon points="6 0, 12 5, 6 10, 0 5" fill="var(--bg)" stroke="var(--_arrow)" stroke-width="1.5" />
83
- </marker>
84
- <marker id="cls-arrow" markerWidth="8" markerHeight="6" refX="8" refY="3" orient="auto-start-reverse">
85
- <polyline points="0 0, 8 3, 0 6" fill="none" stroke="var(--_arrow)" stroke-width="1.5" />
86
- </marker>`}function Bi(t){const{x:e,y:n,width:s,height:r,headerHeight:o,attrHeight:i,methodHeight:a}=t,l=[],h=t.annotation?` data-annotation="${Kt(t.annotation)}"`:"";l.push(`<g class="class-node" data-id="${Kt(t.id)}" data-label="${Kt(t.label)}"${h}>`),l.push(` <rect x="${e}" y="${n}" width="${s}" height="${r}" rx="0" ry="0" fill="var(--_node-fill)" stroke="var(--_node-stroke)" stroke-width="${gt.outerBox}" />`),l.push(` <rect x="${e}" y="${n}" width="${s}" height="${o}" rx="0" ry="0" fill="var(--_group-hdr)" stroke="var(--_node-stroke)" stroke-width="${gt.outerBox}" />`);let c=n+o/2;if(t.annotation){const g=n+12;l.push(` <text x="${e+s/2}" y="${g}" text-anchor="middle" dy="${Lt}" font-size="${We.annotationSize}" font-weight="${We.annotationWeight}" font-style="italic" fill="var(--_text-muted)">&lt;&lt;${Ie(t.annotation)}&gt;&gt;</text>`),c=n+o/2+6}l.push(" "+Ct(t.label,e+s/2,c,rt.nodeLabel,`text-anchor="middle" font-size="${rt.nodeLabel}" font-weight="700" fill="var(--_text)"`));const d=n+o;l.push(` <line x1="${e}" y1="${d}" x2="${e+s}" y2="${d}" stroke="var(--_node-stroke)" stroke-width="${gt.innerBox}" />`);const f=20;for(let g=0;g<t.attributes.length;g++){const x=t.attributes[g],p=d+4+g*f+f/2;l.push(" "+Cn(x,e+yt.boxPadX,p))}const u=d+i;l.push(` <line x1="${e}" y1="${u}" x2="${e+s}" y2="${u}" stroke="var(--_node-stroke)" stroke-width="${gt.innerBox}" />`);for(let g=0;g<t.methods.length;g++){const x=t.methods[g],p=u+4+g*f+f/2;l.push(" "+Cn(x,e+yt.boxPadX,p))}return l.push("</g>"),l.join(`
87
- `)}function Cn(t,e,n){const s=t.isAbstract?' font-style="italic"':"",r=t.isStatic?' text-decoration="underline"':"",o=[];t.visibility&&o.push(`<tspan fill="var(--_text-faint)">${Ie(t.visibility)} </tspan>`);const i=t.isMethod?`${t.name}(${t.params||""})`:t.name;return o.push(`<tspan fill="var(--_text-sec)">${Ie(i)}</tspan>`),t.type&&(o.push('<tspan fill="var(--_text-faint)">: </tspan>'),o.push(`<tspan fill="var(--_text-muted)">${Ie(t.type)}</tspan>`)),`<text x="${e}" y="${n}" class="mono" dy="${Lt}" font-size="${We.memberSize}" font-weight="${We.memberWeight}"${s}${r}>${o.join("")}</text>`}function Ni(t){if(t.points.length<2)return"";const e=t.points.map(i=>`${i.x},${i.y}`).join(" "),s=t.type==="dependency"||t.type==="realization"?' stroke-dasharray="6 4"':"",r=ji(t.type,t.markerAt),o=['class="class-relationship"',`data-from="${Kt(t.from)}"`,`data-to="${Kt(t.to)}"`,`data-type="${t.type}"`,`data-marker-at="${t.markerAt}"`];return t.label&&o.push(`data-label="${Kt(t.label)}"`),t.fromCardinality&&o.push(`data-from-cardinality="${Kt(t.fromCardinality)}"`),t.toCardinality&&o.push(`data-to-cardinality="${Kt(t.toCardinality)}"`),`<polyline ${o.join(" ")} points="${e}" fill="none" stroke="var(--_line)" stroke-width="${gt.connector}"${s}${r} />`}function ji(t,e){const n=Gi(t);return n?e==="from"?` marker-start="url(#${n})"`:` marker-end="url(#${n})"`:""}function Gi(t){switch(t){case"inheritance":case"realization":return"cls-inherit";case"composition":return"cls-composition";case"aggregation":return"cls-aggregation";case"association":case"dependency":return"cls-arrow";default:return null}}function Oi(t){if(!t.label&&!t.fromCardinality&&!t.toCardinality||t.points.length<2)return"";const e=[];if(t.label){const n=t.labelPosition??Fi(t.points);e.push(Ct(t.label,n.x,n.y-8,rt.edgeLabel,`font-size="${rt.edgeLabel}" text-anchor="middle" font-weight="${dt.edgeLabel}" fill="var(--_text-muted)"`))}if(t.fromCardinality){const n=t.points[0],s=t.points[1],r=Tn(n,s);e.push(Ct(t.fromCardinality,n.x+r.x,n.y+r.y,rt.edgeLabel,`font-size="${rt.edgeLabel}" text-anchor="middle" font-weight="${dt.edgeLabel}" fill="var(--_text-muted)"`))}if(t.toCardinality){const n=t.points[t.points.length-1],s=t.points[t.points.length-2],r=Tn(n,s);e.push(Ct(t.toCardinality,n.x+r.x,n.y+r.y,rt.edgeLabel,`font-size="${rt.edgeLabel}" text-anchor="middle" font-weight="${dt.edgeLabel}" fill="var(--_text-muted)"`))}return e.join(`
88
- `)}function Fi(t){if(t.length===0)return{x:0,y:0};const e=Math.floor(t.length/2);return t[e]}function Tn(t,e){const n=e.x-t.x,s=e.y-t.y;return Math.abs(n)>Math.abs(s)?{x:n>0?14:-14,y:-10}:{x:-14,y:s>0?14:-14}}var Ie=ue;function Kt(t){return t.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var It={padding:40,boxPadX:14,headerHeight:34,rowHeight:22,minWidth:140,attrFontSize:11,nodeSpacing:70,layerSpacing:90};function Ji(t,e){const n=new Map;for(const r of t.entities){const o=At(r.label,rt.nodeLabel,dt.nodeLabel);let i=0;for(const h of r.attributes){const c=`${h.type} ${h.name}${h.keys.length>0?" "+h.keys.join(","):""}`,d=fo(c,It.attrFontSize);d>i&&(i=d)}const a=Math.max(It.minWidth,o+It.boxPadX*2,i+It.boxPadX*2),l=It.headerHeight+Math.max(r.attributes.length,1)*It.rowHeight;n.set(r.id,{width:a,height:l})}const s={id:"root",layoutOptions:{"elk.algorithm":"layered","elk.direction":"RIGHT","elk.spacing.nodeNode":String(It.nodeSpacing),"elk.layered.spacing.nodeNodeBetweenLayers":String(It.layerSpacing),"elk.padding":`[top=${It.padding},left=${It.padding},bottom=${It.padding},right=${It.padding}]`,"elk.edgeRouting":"ORTHOGONAL","elk.edgeLabels.placement":"CENTER"},children:[],edges:[]};for(const r of t.entities){const o=n.get(r.id);s.children.push({id:r.id,width:o.width,height:o.height})}for(let r=0;r<t.relationships.length;r++){const o=t.relationships[r],i=te(o.label,rt.edgeLabel,dt.edgeLabel),a={id:`e${r}`,sources:[o.entity1],targets:[o.entity2]};o.label&&(a.labels=[{text:o.label,width:i.width+8,height:i.height+6}]),s.edges.push(a)}return{elkGraph:s,entitySizes:n}}function Vi(t,e,n){const s=new Map;for(const i of e.entities)s.set(i.id,i);const r=[];for(const i of t.children??[]){const a=s.get(i.id);a&&r.push({id:a.id,label:a.label,attributes:a.attributes,x:i.x??0,y:i.y??0,width:i.width??n.get(a.id).width,height:i.height??n.get(a.id).height,headerHeight:It.headerHeight,rowHeight:It.rowHeight})}const o=[];for(let i=0;i<(t.edges?.length??0);i++){const a=t.edges[i],l=e.relationships[i],h=[];if(a.sections&&a.sections.length>0){const c=a.sections[0];if(h.push({x:c.startPoint.x,y:c.startPoint.y}),c.bendPoints)for(const d of c.bendPoints)h.push({x:d.x,y:d.y});h.push({x:c.endPoint.x,y:c.endPoint.y})}o.push({entity1:l.entity1,entity2:l.entity2,cardinality1:l.cardinality1,cardinality2:l.cardinality2,label:l.label,identifying:l.identifying,points:h})}return{width:t.width??600,height:t.height??400,entities:r,relationships:o}}function qi(t,e={}){if(t.entities.length===0)return{width:0,height:0,entities:[],relationships:[]};const{elkGraph:n,entitySizes:s}=Ji(t),r=Qe(n);return Vi(r,t,s)}var Gt={attrSize:11,attrWeight:400,keySize:9,keyWeight:600};function Ui(t,e,n="Inter",s=!1){const r=[];r.push(be(t.width,t.height,e,s)),r.push(me(n,!0)),r.push("<defs>"),r.push("</defs>");for(const o of t.relationships)r.push(Zi(o));for(const o of t.entities)r.push(Ki(o));for(const o of t.relationships)r.push(ea(o));for(const o of t.relationships)r.push(ta(o));return r.push("</svg>"),r.join(`
89
- `)}function Ki(t){const{id:e,x:n,y:s,width:r,height:o,headerHeight:i,rowHeight:a,label:l,attributes:h}=t,c=[];c.push(`<g class="entity" data-id="${xe(e)}" data-label="${xe(l)}">`),c.push(` <rect x="${n}" y="${s}" width="${r}" height="${o}" rx="0" ry="0" fill="var(--_node-fill)" stroke="var(--_node-stroke)" stroke-width="${gt.outerBox}" />`),c.push(` <rect x="${n}" y="${s}" width="${r}" height="${i}" rx="0" ry="0" fill="var(--_group-hdr)" stroke="var(--_node-stroke)" stroke-width="${gt.outerBox}" />`),c.push(" "+Ct(l,n+r/2,s+i/2,rt.nodeLabel,`text-anchor="middle" font-size="${rt.nodeLabel}" font-weight="700" fill="var(--_text)"`));const d=s+i;c.push(` <line x1="${n}" y1="${d}" x2="${n+r}" y2="${d}" stroke="var(--_node-stroke)" stroke-width="${gt.innerBox}" />`);for(let f=0;f<h.length;f++){const u=h[f],g=d+f*a+a/2;c.push(" "+Qi(u,n,g,r).replace(/\n/g,`
90
- `))}return h.length===0&&c.push(` <text x="${n+r/2}" y="${d+a/2}" text-anchor="middle" dy="${Lt}" font-size="${Gt.attrSize}" fill="var(--_text-faint)" font-style="italic">(no attributes)</text>`),c.push("</g>"),c.join(`
91
- `)}function Qi(t,e,n,s){const r=[],o=t.comment&&t.comment.length>0;if(o){const h=t.comment.replace(/<br\s*\/?>/gi,`
92
- `);r.push(`<g><title>${Ge(h)}</title>`)}let i=0;if(t.keys.length>0){const h=t.keys.join(",");i=At(h,Gt.keySize,Gt.keyWeight)+8,r.push(`<rect x="${e+6}" y="${n-7}" width="${i}" height="14" rx="2" ry="2" fill="var(--_key-badge)" />`),r.push(`<text x="${e+6+i/2}" y="${n}" text-anchor="middle" dy="${Lt}" font-size="${Gt.keySize}" font-weight="${Gt.keyWeight}" fill="var(--_text-sec)">${t.keys.join(",")}</text>`)}const a=e+8+(i>0?i+6:0);r.push(`<text x="${a}" y="${n}" class="mono" dy="${Lt}" font-size="${Gt.attrSize}" font-weight="${Gt.attrWeight}"><tspan fill="var(--_text-muted)">${Ge(t.type)}</tspan></text>`);const l=e+s-8;return r.push(`<text x="${l}" y="${n}" class="mono" text-anchor="end" dy="${Lt}" font-size="${Gt.attrSize}" font-weight="${Gt.attrWeight}"><tspan fill="var(--_text-sec)">${Ge(t.name)}</tspan></text>`),o&&r.push("</g>"),r.join(`
93
- `)}function Zi(t){if(t.points.length<2)return"";const e=t.points.map(o=>`${o.x},${o.y}`).join(" "),n=t.identifying?"":' stroke-dasharray="6 4"',s=t.label?` data-label="${xe(t.label)}"`:"";return`<polyline ${['class="er-relationship"',`data-entity1="${xe(t.entity1)}"`,`data-entity2="${xe(t.entity2)}"`,`data-cardinality1="${t.cardinality1}"`,`data-cardinality2="${t.cardinality2}"`,`data-identifying="${t.identifying}"`].join(" ")}${s} points="${e}" fill="none" stroke="var(--_line)" stroke-width="${gt.connector}"${n} />`}function ta(t){if(!t.label||t.points.length<2)return"";const e=na(t.points),n=te(t.label,rt.edgeLabel,dt.edgeLabel),s=n.width+8,r=n.height+6;return`<rect x="${e.x-s/2}" y="${e.y-r/2}" width="${s}" height="${r}" rx="2" ry="2" fill="var(--bg)" stroke="var(--_inner-stroke)" stroke-width="0.5" />
94
- ${Ct(t.label,e.x,e.y,rt.edgeLabel,`text-anchor="middle" font-size="${rt.edgeLabel}" font-weight="${dt.edgeLabel}" fill="var(--_text-muted)"`)}`}function ea(t){if(t.points.length<2)return"";const e=[],n=t.points[0],s=t.points[1];e.push(In(n,s,t.cardinality1));const r=t.points[t.points.length-1],o=t.points[t.points.length-2];return e.push(In(r,o,t.cardinality2)),e.join(`
95
- `)}function In(t,e,n){const s=[],r=gt.connector+.25,o=t.x-e.x,i=t.y-e.y,a=Math.sqrt(o*o+i*i);if(a===0)return"";const l=o/a,h=i/a,c=-h,d=l,f=t.x-l*4,u=t.y-h*4,g=t.x-l*16,x=t.y-h*16,p=n==="one"||n==="zero-one",M=n==="many"||n==="zero-many",D=n==="zero-one"||n==="zero-many";if(p){s.push(`<line x1="${f+c*6}" y1="${u+d*6}" x2="${f-c*6}" y2="${u-d*6}" stroke="var(--_line)" stroke-width="${r}" />`);const C=f-l*4,w=u-h*4;s.push(`<line x1="${C+c*6}" y1="${w+d*6}" x2="${C-c*6}" y2="${w-d*6}" stroke="var(--_line)" stroke-width="${r}" />`)}if(M){const C=f,w=u;s.push(`<line x1="${C+c*7}" y1="${w+d*7}" x2="${g}" y2="${x}" stroke="var(--_line)" stroke-width="${r}" />`),s.push(`<line x1="${C}" y1="${w}" x2="${g}" y2="${x}" stroke="var(--_line)" stroke-width="${r}" />`),s.push(`<line x1="${C-c*7}" y1="${w-d*7}" x2="${g}" y2="${x}" stroke="var(--_line)" stroke-width="${r}" />`)}if(D){const A=M?20:12,C=t.x-l*A,w=t.y-h*A;s.push(`<circle cx="${C}" cy="${w}" r="4" fill="var(--bg)" stroke="var(--_line)" stroke-width="${r}" />`)}return s.join(`
96
- `)}function na(t){if(t.length===0)return{x:0,y:0};if(t.length===1)return t[0];let e=0;for(let r=1;r<t.length;r++){const o=t[r].x-t[r-1].x,i=t[r].y-t[r-1].y;e+=Math.sqrt(o*o+i*i)}if(e===0)return t[0];const n=e/2;let s=0;for(let r=1;r<t.length;r++){const o=t[r].x-t[r-1].x,i=t[r].y-t[r-1].y,a=Math.sqrt(o*o+i*i);if(s+a>=n){const l=a>0?(n-s)/a:0;return{x:t[r-1].x+o*l,y:t[r-1].y+i*l}}s+=a}return t[t.length-1]}var Ge=ue;function xe(t){return t.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var J={plotWidth:600,plotHeight:340,padding:22,titleFontSize:18,titleHeight:42,axisLabelFontSize:14,axisLabelFontWeight:400,xLabelHeight:38,yLabelWidth:58,yLabelGap:18,axisTitlePad:30,tickLength:4,barPadRatio:.2,barGroupGap:0,maxBarWidth:40,legendFontSize:14,legendFontWeight:400,legendHeight:28,legendSwatchW:14,legendGap:6,legendItemGap:16};function oa(t,e={}){return t.horizontal?ra(t):sa(t)}function sa(t){const e=!!t.title,n=!!t.xAxis.title,s=!!t.yAxis.title,r=t.series.length>1,o=t.yAxis.range,i=vo(o.min,o.max),a=Math.max(...i.map(tt=>At(Ye(tt),J.axisLabelFontSize,J.axisLabelFontWeight)),J.yLabelWidth),l=J.padding+(e?J.titleHeight:0)+(r?J.legendHeight:0),h=J.padding+J.xLabelHeight+(n?J.axisTitlePad:0),c=J.padding+a+J.yLabelGap+(s?J.axisTitlePad:0),d=J.padding,f=J.plotWidth,u=J.plotHeight,g=c+f+d,x=l+u+h,p={x:c,y:l,width:f,height:u},M=Ze(t),D=tt=>c+(tt+.5)*(f/M),A=f/M,C=tt=>{const L=(tt-o.min)/(o.max-o.min||1);return l+u-L*u},w=ia(t,D,l+u),O=i.map(tt=>({label:Ye(tt),x:c,y:C(tt),tx:c-J.tickLength,ty:C(tt),labelX:c-J.yLabelGap,labelY:C(tt),textAnchor:"end"})),st=i.map(tt=>({x1:c,y1:C(tt),x2:c+f,y2:C(tt)})),y=tn(t,M),m=t.series.map((tt,L)=>L),S=aa(t,D,C,A,o.min,y,m),X=la(t,D,C,y,m),v=J.padding+(e?J.titleHeight:0)+J.legendHeight/2,z=r?ko(t,g/2,v,m):[],F={x1:c,y1:l+u,x2:c+f,y2:l+u},V={x1:c,y1:l,x2:c,y2:l+u},Y={ticks:w,line:F,...n?{title:{text:t.xAxis.title,x:c+f/2,y:x-J.padding}}:{}},Z={ticks:O,line:V,...s?{title:{text:t.yAxis.title,x:J.padding+4,y:l+u/2,rotate:-90}}:{}},at=e?{text:t.title,x:g/2,y:J.padding+J.titleFontSize}:void 0;return{width:g,height:x,title:at,xAxis:Y,yAxis:Z,plotArea:p,bars:S,lines:X,gridLines:st,legend:z}}function ra(t){const e=!!t.title,n=!!t.xAxis.title,s=!!t.yAxis.title,r=t.series.length>1,o=t.yAxis.range,i=vo(o.min,o.max),a=Ze(t),l=tn(t,a),h=Math.max(...l.map(k=>At(k,J.axisLabelFontSize,J.axisLabelFontWeight)),40),c=J.padding+(e?J.titleHeight:0)+(r?J.legendHeight:0),d=J.padding+J.xLabelHeight+(s?J.axisTitlePad:0),f=J.padding+h+J.yLabelGap+(n?J.axisTitlePad:0),u=J.padding,g=J.plotWidth,x=J.plotHeight,p=f+g+u,M=c+x+d,D={x:f,y:c,width:g,height:x},A=k=>{const j=(k-o.min)/(o.max-o.min||1);return f+j*g},C=x/a,w=k=>c+(k+.5)*C,O=i.map(k=>({label:Ye(k),x:A(k),y:c+x,tx:A(k),ty:c+x+J.tickLength,labelX:A(k),labelY:c+x+18,textAnchor:"middle"})),st=l.map((k,j)=>({label:k,x:f,y:w(j),tx:f-J.tickLength,ty:w(j),labelX:f-J.yLabelGap,labelY:w(j),textAnchor:"end"})),y=i.map(k=>({x1:A(k),y1:c,x2:A(k),y2:c+x})),m=t.series.map((k,j)=>j),X=t.series.filter(k=>k.type==="bar").length,v=[];if(X>0){const k=C*(1-J.barPadRatio),j=X>1?(k-(X-1)*J.barGroupGap)/X:k,et=Math.min(j,J.maxBarWidth),$=X>1?et*X+J.barGroupGap*(X-1):et;let I=0,B=0;for(const _ of t.series){if(_.type!=="bar"){B++;continue}for(let N=0;N<_.data.length;N++){const G=w(N)-$/2+I*(et+J.barGroupGap),R=A(Math.max(_.data[N],o.min)),K=A(Math.max(0,o.min));v.push({x:Math.min(K,R),y:G,width:Math.abs(R-K),height:et,value:_.data[N],label:l[N],seriesIndex:I,colorIndex:m[B]})}I++,B++}}const z=[];let F=0,V=0;for(const k of t.series){if(k.type!=="line"){V++;continue}const j=k.data.map((et,$)=>({x:A(et),y:w($),value:et,label:l[$]}));z.push({points:j,seriesIndex:F,colorIndex:m[V]}),F++,V++}const Y={x1:f,y1:c+x,x2:f+g,y2:c+x},Z={x1:f,y1:c,x2:f,y2:c+x},at={ticks:O,line:Y,...s?{title:{text:t.yAxis.title,x:f+g/2,y:M-J.padding}}:{}},tt={ticks:st,line:Z,...n?{title:{text:t.xAxis.title,x:J.padding+4,y:c+x/2,rotate:-90}}:{}},L=e?{text:t.title,x:p/2,y:J.padding+J.titleFontSize}:void 0,P=J.padding+(e?J.titleHeight:0)+J.legendHeight/2,H=r?ko(t,p/2,P,m):[];return{width:p,height:M,horizontal:!0,title:L,xAxis:at,yAxis:tt,plotArea:D,bars:v,lines:z,gridLines:y,legend:H}}function Ze(t){if(t.xAxis.categories)return t.xAxis.categories.length;for(const e of t.series)if(e.data.length>0)return e.data.length;return 1}function tn(t,e){if(t.xAxis.categories)return t.xAxis.categories;if(t.xAxis.range){const{min:n,max:s}=t.xAxis.range,r=e>1?(s-n)/(e-1):0;return Array.from({length:e},(o,i)=>Ye(n+r*i))}return Array.from({length:e},(n,s)=>String(s+1))}function ia(t,e,n,s){const r=Ze(t);return tn(t,r).map((i,a)=>({label:i,x:e(a),y:n,tx:e(a),ty:n+J.tickLength,labelX:e(a),labelY:n+18,textAnchor:"middle"}))}function aa(t,e,n,s,r,o,i){const l=t.series.filter(p=>p.type==="bar").length;if(l===0)return[];const h=s*(1-J.barPadRatio),c=l>1?(h-(l-1)*J.barGroupGap)/l:h,d=Math.min(c,J.maxBarWidth),f=l>1?d*l+J.barGroupGap*(l-1):d,u=[];let g=0,x=0;for(const p of t.series){if(p.type!=="bar"){x++;continue}for(let M=0;M<p.data.length;M++){const C=e(M)-f/2+g*(d+J.barGroupGap),w=n(p.data[M]),O=n(Math.max(0,r));u.push({x:C,y:Math.min(w,O),width:d,height:Math.abs(O-w),value:p.data[M],label:o[M],seriesIndex:g,colorIndex:i[x]})}g++,x++}return u}function la(t,e,n,s,r){const o=[];let i=0,a=0;for(const l of t.series){if(l.type!=="line"){a++;continue}const h=l.data.map((c,d)=>({x:e(d),y:n(c),value:c,label:s[d]}));o.push({points:h,seriesIndex:i,colorIndex:r[a]}),i++,a++}return o}function vo(t,e){const n=e-t;if(n<=0)return[t];const s=n/6,r=Math.pow(10,Math.floor(Math.log10(s))),o=s/r;let i;o<=1.5?i=r:o<=3?i=2*r:o<=7?i=5*r:i=10*r;const a=Math.ceil(t/i)*i,l=[];for(let h=a;h<=e+i*.001;h+=i)l.push(Math.round(h*1e10)/1e10);return l}function Ye(t){return Number.isInteger(t)?String(t):t.toFixed(Math.abs(t)<10?1:0)}function ko(t,e,n,s){const r=[];let o=0,i=0;for(let c=0;c<t.series.length;c++){const d=t.series[c],f=d.type==="bar"?`Bar ${o+1}`:`Line ${i+1}`;r.push({label:f,x:0,y:n,type:d.type,seriesIndex:d.type==="bar"?o:i,colorIndex:s[c]}),d.type==="bar"?o++:i++}const a=r.map(c=>{const d=At(c.label,J.legendFontSize,J.legendFontWeight);return J.legendSwatchW+J.legendGap+d}),l=a.reduce((c,d)=>c+d,0)+(r.length-1)*J.legendItemGap;let h=e-l/2;for(let c=0;c<r.length;c++)r[c].x=h,h+=a[c]+J.legendItemGap;return r}var xt={titleSize:18,titleWeight:600,axisTitleSize:15,axisTitleWeight:500,labelSize:14,labelWeight:400,legendSize:14,legendWeight:400,dotRadius:5,lineWidth:2.5,barRadius:8},ut={fontSize:15,fontWeight:500,height:32,padX:14,offsetY:12,rx:8,minY:4,pointerSize:6};function ca(t,e,n="Inter",s=!1,r=!1){const o=[],i=Math.max(0,...t.bars.map(y=>y.colorIndex),...t.lines.map(y=>y.colorIndex)),a=be(t.width,t.height,e,s).replace("<svg ",`<svg data-xychart-colors="${i}" `);o.push(a),o.push(me(n,!1));const l=Math.max(...t.lines.map(y=>y.points.length),0),h=l>0&&l<=12,{style:c}=ha(t,r,h,e.accent,e.bg);o.push(c);const{plotArea:d}=t,f=t.xAxis.ticks.map(y=>y.x),u=t.horizontal?t.yAxis.ticks.map(y=>y.y):t.gridLines.map(y=>y.y1),g=f.length>1?Math.abs(f[1]-f[0]):d.width/6,x=u.length>1?Math.abs(u[1]-u[0]):d.height/6,p=g/Math.max(1,Math.round(g/20)),M=x/Math.max(1,Math.round(x/20)),D=f[0]??d.x,A=u[0]??d.y,C=D-Math.ceil((D-d.x)/p)*p,w=A-Math.ceil((A-d.y)/M)*M;for(let y=w;y<=d.y+d.height+.5;y+=M)for(let m=C;m<=d.x+d.width+.5;m+=p)o.push(`<circle cx="${T(m)}" cy="${T(y)}" r="1.5" class="xychart-grid"/>`);const O=[];for(const y of t.bars){const m=` data-value="${y.value}"${y.label?` data-label="${vt(y.label)}"`:""}`,S=t.horizontal?da(y.x,y.y,y.width,y.height,xt.barRadius):fa(y.x,y.y,y.width,y.height,xt.barRadius);if(o.push(`<path d="${S}" class="xychart-bar xychart-color-${y.colorIndex}"${m}/>`),r){const X=Oe(y.value),v=y.label?`${y.label}: ${X}`:X,z=Rn(y.x+y.width/2,y.y,X);O.push(`<g class="xychart-bar-group"><rect x="${T(y.x)}" y="${T(y.y)}" width="${T(y.width)}" height="${T(y.height)}" fill="transparent"/><title>${vt(v)}</title>`+z+"</g>")}}for(const y of t.lines){if(y.points.length===0)continue;const m=ua(y.points);o.push(`<path d="${m}" class="xychart-line-shadow xychart-color-${y.colorIndex}" transform="translate(0,2)"/>`),o.push(`<path d="${m}" class="xychart-line xychart-color-${y.colorIndex}"/>`)}const st=[];if(r||h){const y=new Map;for(const S of t.legend)S.type==="line"&&y.set(S.seriesIndex,S.label);const m=new Map;for(const S of t.lines)for(const X of S.points){const v=T(X.x);m.has(v)||m.set(v,[]),m.get(v).push({x:X.x,y:X.y,value:X.value,label:X.label,seriesIndex:S.seriesIndex,colorIndex:S.colorIndex})}for(const S of m.values()){const X=S[0].x,v=S[0].label||"";if(r&&S.length>1){const z=Math.min(...S.map(H=>H.y)),F=Math.max(...S.map(H=>H.y)),V=xt.dotRadius*3,Y=`<rect x="${T(X-V)}" y="${T(z-V)}" width="${T(V*2)}" height="${T(F-z+V*2)}" fill="transparent" class="xychart-hit"/>`,Z=S.map(H=>({text:Oe(H.value),legendLabel:y.get(H.seriesIndex)||`Line ${H.seriesIndex+1}`})),at=ga(X,z-xt.dotRadius,v,Z),tt=Z.map(H=>H.text),L=v?`${v}: ${tt.join(" · ")}`:tt.join(" · ");let P=`<g class="xychart-dot-group">${Y}`;for(const H of S){const k=` data-value="${H.value}"${H.label?` data-label="${vt(H.label)}"`:""}`;P+=`<circle cx="${T(H.x)}" cy="${T(H.y)}" r="${xt.dotRadius}" class="xychart-dot xychart-color-${H.colorIndex}"${k}/>`}P+=`<title>${vt(L)}</title>${at}</g>`,st.push(P)}else if(r){const z=S[0],F=` data-value="${z.value}"${z.label?` data-label="${vt(z.label)}"`:""}`,V=Oe(z.value),Y=z.label?`${z.label}: ${V}`:V,Z=Rn(X,z.y-xt.dotRadius,V),at=h?`<circle cx="${T(X)}" cy="${T(z.y)}" r="${xt.dotRadius*3}" fill="transparent" class="xychart-hit"/>`:"";st.push(`<g class="xychart-dot-group">${at}<circle cx="${T(z.x)}" cy="${T(z.y)}" r="${xt.dotRadius}" class="xychart-dot xychart-color-${z.colorIndex}"${F}/><title>${vt(Y)}</title>${Z}</g>`)}else for(const z of S){const F=` data-value="${z.value}"${z.label?` data-label="${vt(z.label)}"`:""}`;o.push(`<circle cx="${T(z.x)}" cy="${T(z.y)}" r="${xt.dotRadius}" class="xychart-dot xychart-color-${z.colorIndex}"${F}/>`)}}}for(const y of t.xAxis.ticks)o.push(`<text x="${y.labelX}" y="${y.labelY}" text-anchor="${y.textAnchor}" font-size="${xt.labelSize}" font-weight="${xt.labelWeight}" dy="${Lt}" class="xychart-label">${vt(y.label)}</text>`);for(const y of t.yAxis.ticks)o.push(`<text x="${y.labelX}" y="${y.labelY}" text-anchor="${y.textAnchor}" font-size="${xt.labelSize}" font-weight="${xt.labelWeight}" dy="${Lt}" class="xychart-label">${vt(y.label)}</text>`);if(t.xAxis.title){const y=t.xAxis.title,m=y.rotate?` transform="rotate(${y.rotate},${y.x},${y.y})"`:"";o.push(`<text x="${y.x}" y="${y.y}" text-anchor="middle"${m} font-size="${xt.axisTitleSize}" font-weight="${xt.axisTitleWeight}" dy="${Lt}" class="xychart-axis-title">${vt(y.text)}</text>`)}if(t.yAxis.title){const y=t.yAxis.title,m=y.rotate?` transform="rotate(${y.rotate},${y.x},${y.y})"`:"";o.push(`<text x="${y.x}" y="${y.y}" text-anchor="middle"${m} font-size="${xt.axisTitleSize}" font-weight="${xt.axisTitleWeight}" dy="${Lt}" class="xychart-axis-title">${vt(y.text)}</text>`)}t.title&&o.push(`<text x="${t.title.x}" y="${t.title.y}" text-anchor="middle" font-size="${xt.titleSize}" font-weight="${xt.titleWeight}" dy="${Lt}" class="xychart-title">${vt(t.title.text)}</text>`);for(const y of t.legend){if(y.type==="bar")o.push(`<rect x="${y.x}" y="${y.y-14/2}" width="14" height="14" rx="3" class="xychart-bar xychart-color-${y.colorIndex}"/>`);else{const v=y.y;o.push(`<line x1="${y.x}" y1="${v}" x2="${y.x+14}" y2="${v}" stroke-width="${xt.lineWidth}" stroke-linecap="round" class="xychart-legend-line xychart-color-${y.colorIndex}"/>`)}o.push(`<text x="${y.x+14+6}" y="${y.y}" text-anchor="start" font-size="${xt.legendSize}" font-weight="${xt.legendWeight}" dy="${Lt}" class="xychart-label">${vt(y.label)}</text>`)}for(const y of O)o.push(y);for(const y of st)o.push(y);return o.push("</svg>"),o.join(`
97
- `)}function ha(t,e,n,s,r){const o=s??Re,i=new Set;for(const f of t.bars)i.add(f.colorIndex);for(const f of t.lines)i.add(f.colorIndex);const a=[];for(const f of[...i].sort((u,g)=>u-g)){const u=f===0?`var(--accent, ${Re})`:Qn(f,o,r);a.push(` --xychart-color-${f}: ${u};`),a.push(` --xychart-bar-fill-${f}: color-mix(in srgb, var(--bg) 75%, var(--xychart-color-${f}) 25%);`)}const l=[];for(const f of[...i].sort((u,g)=>u-g)){const u=`var(--xychart-color-${f})`;l.push(` .xychart-bar.xychart-color-${f} { stroke: ${u}; fill: var(--xychart-bar-fill-${f}); }`),l.push(` path.xychart-color-${f}, line.xychart-color-${f} { stroke: ${u}; }`),l.push(` circle.xychart-color-${f} { fill: ${u}; }`)}const h=e?`
98
- .xychart-tip { opacity: 0; pointer-events: none; }
99
- .xychart-tip-bg { fill: var(--_text); filter: drop-shadow(0 1px 3px color-mix(in srgb, var(--fg) 20%, transparent)); }
100
- .xychart-tip-text { fill: var(--bg); font-size: ${ut.fontSize}px; font-weight: ${ut.fontWeight}; }
101
- .xychart-tip-ptr { fill: var(--_text); }
102
- .xychart-bar-group:hover .xychart-tip,
103
- .xychart-dot-group:hover .xychart-tip { opacity: 1; }`:"",c=a.length>0?`
104
- svg {
105
- ${a.join(`
106
- `)}
107
- }`:"";return{style:`<style>
108
- .xychart-grid { fill: var(--_inner-stroke); stroke: none; opacity: 0.65; }
109
- .xychart-bar { stroke-width: 1.5; }
110
- .xychart-line { fill: none; stroke-width: ${xt.lineWidth}; stroke-linecap: round; stroke-linejoin: round; }
111
- .xychart-line-shadow { fill: none; stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; opacity: 0.12; }
112
- .xychart-dot { stroke: var(--bg); stroke-width: 2; }
113
- .xychart-label { fill: var(--_text-muted); }
114
- .xychart-axis-title { fill: var(--_text-sec); }
115
- .xychart-title { fill: var(--_text); }${c}
116
- ${l.join(`
117
- `)}${h}
118
- </style>`,defs:""}}function fa(t,e,n,s,r){const o=Math.min(r,n/2,s/2);return o<=0?`M${T(t)},${T(e)} h${T(n)} v${T(s)} h${T(-n)} Z`:[`M${T(t)},${T(e+o)}`,`Q${T(t)},${T(e)} ${T(t+o)},${T(e)}`,`L${T(t+n-o)},${T(e)}`,`Q${T(t+n)},${T(e)} ${T(t+n)},${T(e+o)}`,`L${T(t+n)},${T(e+s-o)}`,`Q${T(t+n)},${T(e+s)} ${T(t+n-o)},${T(e+s)}`,`L${T(t+o)},${T(e+s)}`,`Q${T(t)},${T(e+s)} ${T(t)},${T(e+s-o)}`,"Z"].join(" ")}function da(t,e,n,s,r){const o=Math.min(r,n/2,s/2);return o<=0?`M${T(t)},${T(e)} h${T(n)} v${T(s)} h${T(-n)} Z`:[`M${T(t+o)},${T(e)}`,`L${T(t+n-o)},${T(e)}`,`Q${T(t+n)},${T(e)} ${T(t+n)},${T(e+o)}`,`L${T(t+n)},${T(e+s-o)}`,`Q${T(t+n)},${T(e+s)} ${T(t+n-o)},${T(e+s)}`,`L${T(t+o)},${T(e+s)}`,`Q${T(t)},${T(e+s)} ${T(t)},${T(e+s-o)}`,`L${T(t)},${T(e+o)}`,`Q${T(t)},${T(e)} ${T(t+o)},${T(e)}`,"Z"].join(" ")}function ua(t){if(t.length===0)return"";if(t.length===1)return`M${T(t[0].x)},${T(t[0].y)}`;if(t.length===2)return`M${T(t[0].x)},${T(t[0].y)} L${T(t[1].x)},${T(t[1].y)}`;const e=t.length,n=[],s=[];for(let a=0;a<e-1;a++)n.push(t[a+1].x-t[a].x),s.push(n[a]===0?0:(t[a+1].y-t[a].y)/n[a]);const r=new Array(e).fill(0);if(e>2){const a=new Array(e).fill(0),l=new Array(e).fill(0);for(let h=1;h<e-1;h++){const c=2*(n[h-1]+n[h]),d=3*(s[h]-s[h-1]);if(h===1)a[h]=n[h]/c,l[h]=d/c;else{const f=c-n[h-1]*a[h-1];a[h]=n[h]/f,l[h]=(d-n[h-1]*l[h-1])/f}}for(let h=e-2;h>=1;h--)r[h]=l[h]-a[h]*r[h+1]}const o=new Array(e).fill(0);for(let a=0;a<e-1;a++)o[a]=s[a]-n[a]*(2*r[a]+r[a+1])/3;o[e-1]=s[e-2]+n[e-2]*r[e-2]/3;let i=`M${T(t[0].x)},${T(t[0].y)}`;for(let a=0;a<e-1;a++){const l=n[a]/3,h=t[a].x+l,c=t[a].y+o[a]*l,d=t[a+1].x-l,f=t[a+1].y-o[a+1]*l;i+=` C${T(h)},${T(c)} ${T(d)},${T(f)} ${T(t[a+1].x)},${T(t[a+1].y)}`}return i}function ga(t,e,n,s){const a=At(n,ut.fontSize,600),l=Math.max(...s.map(w=>{const O=At(w.legendLabel,ut.fontSize,ut.fontWeight),st=At(w.text,ut.fontSize,ut.fontWeight);return O+10+st})),h=Math.max(a,l)+ut.padX*2,c=26+s.length*20+6,d=Math.max(ut.minY,e-ut.offsetY-c-ut.pointerSize),f=t-h/2,u=t,g=d+c,x=ut.pointerSize,p=`<polygon points="${T(u-x)},${T(g)} ${T(u+x)},${T(g)} ${T(u)},${T(g+x)}" class="xychart-tip xychart-tip-ptr"/>`;let M=`<rect x="${T(f)}" y="${T(d)}" width="${T(h)}" height="${c}" rx="${ut.rx}" class="xychart-tip xychart-tip-bg"/>`;M+=p;let D=d+6+20/2;M+=`<text x="${T(t)}" y="${T(D)}" text-anchor="middle" font-weight="600" font-size="${ut.fontSize}" dy="${Lt}" class="xychart-tip xychart-tip-text">${vt(n)}</text>`;const A=f+ut.padX,C=f+h-ut.padX;for(const w of s)D+=20,M+=`<text x="${T(A)}" y="${T(D)}" text-anchor="start" font-size="${ut.fontSize}" font-weight="${ut.fontWeight}" dy="${Lt}" class="xychart-tip xychart-tip-text">${vt(w.legendLabel)}</text>`,M+=`<text x="${T(C)}" y="${T(D)}" text-anchor="end" font-size="${ut.fontSize}" font-weight="${ut.fontWeight}" dy="${Lt}" class="xychart-tip xychart-tip-text">${vt(w.text)}</text>`;return M}function Rn(t,e,n){const r=At(n,ut.fontSize,ut.fontWeight)+ut.padX*2,o=ut.height,i=Math.max(ut.minY,e-ut.offsetY-o-ut.pointerSize),a=t-r/2,l=t,h=i+o/2,c=t,d=i+o,f=ut.pointerSize,u=`<polygon points="${T(c-f)},${T(d)} ${T(c+f)},${T(d)} ${T(c)},${T(d+f)}" class="xychart-tip xychart-tip-ptr"/>`;return`<rect x="${T(a)}" y="${T(i)}" width="${T(r)}" height="${o}" rx="${ut.rx}" class="xychart-tip xychart-tip-bg"/>`+u+`<text x="${T(l)}" y="${T(h)}" text-anchor="middle" dy="${Lt}" class="xychart-tip xychart-tip-text">${vt(n)}</text>`}function Oe(t){return Number.isInteger(t)?t.toLocaleString("en-US"):t.toFixed(Math.abs(t)<10?1:0)}function T(t){return String(Math.round(t*10)/10)}function vt(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}function xa(t){const e=t.trim().split(/[\n;]/)[0]?.trim().toLowerCase()??"";return/^xychart(-beta)?\b/.test(e)?"xychart":/^sequencediagram\s*$/.test(e)?"sequence":/^classdiagram\s*$/.test(e)?"class":/^erdiagram\s*$/.test(e)?"er":"flowchart"}function ya(t){return{bg:t.bg??en.bg,fg:t.fg??en.fg,line:t.line,accent:t.accent,muted:t.muted,surface:t.surface,border:t.border}}function $a(t,e={}){t=Lo(t);const n=ya(e),s=e.font??"Inter",r=e.transparent??!1,o=xa(t),i=t.split(`
119
- `).map(a=>a.trim()).filter(a=>a.length>0&&!a.startsWith("%%"));switch(o){case"sequence":{const a=Jn(i),l=Li(a,e);return Ai(l,n,s,r)}case"class":{const a=Vn(i),l=Xi(a,e);return Pi(l,n,s,r)}case"er":{const a=qn(i),l=qi(a,e);return Ui(l,n,s,r)}case"xychart":{const a=Un(i),l=oa(a,e);return ca(l,n,s,r,e.interactive??!1)}default:{const a=Yn(t),l=ei(a,e);return ni(l,n,s,r)}}}export{$a as a,ba as r};