agentic-mermaid 0.4.1 → 0.5.3

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 (253) hide show
  1. package/AGENT_NATIVE.md +94 -627
  2. package/CHANGELOG.md +651 -0
  3. package/Instructions_for_agents.md +44 -23
  4. package/LICENSES/Khroma-MIT.txt +21 -0
  5. package/LICENSES/Mermaid-MIT.txt +21 -0
  6. package/LICENSES/es-toolkit-MIT.txt +21 -0
  7. package/LICENSES/pele-MIT.txt +40 -0
  8. package/LICENSES/zenuml-core-MIT.txt +21 -0
  9. package/README.md +93 -50
  10. package/SECURITY.md +28 -12
  11. package/THIRD_PARTY_NOTICES.md +60 -0
  12. package/assets/hero.png +0 -0
  13. package/dist/agent-core.d.ts +478 -210
  14. package/dist/agent-core.js +1 -396
  15. package/dist/agent.d.ts +17 -8
  16. package/dist/agent.js +1 -408
  17. package/dist/agentic-mermaid-mcp.js +1 -11
  18. package/dist/am.js +1 -34562
  19. package/dist/browser-lazy/chunks/agentic-producer-core-CC6OOLDW.js +1 -0
  20. package/dist/browser-lazy/chunks/architecture-QUFVKYJR.js +13 -0
  21. package/dist/browser-lazy/chunks/block-6J3Q63BO.js +11 -0
  22. package/dist/browser-lazy/chunks/builtin-backends-7SOZZHPF.js +12 -0
  23. package/dist/browser-lazy/chunks/c4-SQVBZAKJ.js +10 -0
  24. package/dist/browser-lazy/chunks/chunk-2GPK4VFF.js +5 -0
  25. package/dist/browser-lazy/chunks/chunk-2I4UPL7Q.js +3 -0
  26. package/dist/browser-lazy/chunks/chunk-2SH76OTH.js +1 -0
  27. package/dist/browser-lazy/chunks/chunk-2UIA2IME.js +3 -0
  28. package/dist/browser-lazy/chunks/chunk-4LHYF3BS.js +1 -0
  29. package/dist/browser-lazy/chunks/chunk-5B2Z7575.js +1 -0
  30. package/dist/browser-lazy/chunks/chunk-5FQ534HP.js +1 -0
  31. package/dist/browser-lazy/chunks/chunk-5UVGUSD6.js +1 -0
  32. package/dist/browser-lazy/chunks/chunk-5X6MJX3H.js +1 -0
  33. package/dist/browser-lazy/chunks/chunk-AMJLVPUB.js +4 -0
  34. package/dist/browser-lazy/chunks/chunk-BU5LHXNJ.js +3 -0
  35. package/dist/browser-lazy/chunks/chunk-BY2CPG6B.js +1 -0
  36. package/dist/browser-lazy/chunks/chunk-CN7WTBWB.js +1 -0
  37. package/dist/browser-lazy/chunks/chunk-CQE4HQEW.js +1 -0
  38. package/dist/browser-lazy/chunks/chunk-CSFUKSU6.js +1 -0
  39. package/dist/browser-lazy/chunks/chunk-DF6765YX.js +17 -0
  40. package/dist/browser-lazy/chunks/chunk-E2WMJZNM.js +1 -0
  41. package/dist/browser-lazy/chunks/chunk-FAIMVOX5.js +6 -0
  42. package/dist/browser-lazy/chunks/chunk-GVOEAY52.js +1 -0
  43. package/dist/browser-lazy/chunks/chunk-HLWUNUCM.js +1 -0
  44. package/dist/browser-lazy/chunks/chunk-ICC7HBJX.js +1 -0
  45. package/dist/browser-lazy/chunks/chunk-J35HAQQF.js +20 -0
  46. package/dist/browser-lazy/chunks/chunk-J7FFAFQF.js +1 -0
  47. package/dist/browser-lazy/chunks/chunk-LH7HUDKW.js +1 -0
  48. package/dist/browser-lazy/chunks/chunk-N5ELX7LR.js +2 -0
  49. package/dist/browser-lazy/chunks/chunk-NMQQMRIR.js +1 -0
  50. package/dist/browser-lazy/chunks/chunk-NO7ZIVRU.js +1 -0
  51. package/dist/browser-lazy/chunks/chunk-OZ443IVJ.js +16 -0
  52. package/dist/browser-lazy/chunks/chunk-PQGPS2YV.js +7 -0
  53. package/dist/browser-lazy/chunks/chunk-QA6GJQ4X.js +1 -0
  54. package/dist/browser-lazy/chunks/chunk-RIVTHZAQ.js +1 -0
  55. package/dist/browser-lazy/chunks/chunk-SZELX2EJ.js +1 -0
  56. package/dist/browser-lazy/chunks/chunk-TYZOZXUJ.js +22 -0
  57. package/dist/browser-lazy/chunks/chunk-UL6NDWLL.js +1 -0
  58. package/dist/browser-lazy/chunks/chunk-VQYYGAXP.js +1 -0
  59. package/dist/browser-lazy/chunks/chunk-VWVZGQE2.js +1 -0
  60. package/dist/browser-lazy/chunks/chunk-X2UYKWKM.js +4 -0
  61. package/dist/browser-lazy/chunks/chunk-YCEICNM6.js +1 -0
  62. package/dist/browser-lazy/chunks/chunk-Z3FDIVLN.js +20 -0
  63. package/dist/browser-lazy/chunks/class-5QA4SCTS.js +13 -0
  64. package/dist/browser-lazy/chunks/decode-63UIZGD2.js +1 -0
  65. package/dist/browser-lazy/chunks/elk.bundled-L4CADV5W.js +24 -0
  66. package/dist/browser-lazy/chunks/er-7ZSKGN7Y.js +11 -0
  67. package/dist/browser-lazy/chunks/eventmodeling-2BPLHWRN.js +19 -0
  68. package/dist/browser-lazy/chunks/flowchart-NEIMZTB5.js +4 -0
  69. package/dist/browser-lazy/chunks/forest-implementation-AEP24AIP.js +1 -0
  70. package/dist/browser-lazy/chunks/gantt-RDPIFYAF.js +11 -0
  71. package/dist/browser-lazy/chunks/gitgraph-N4Y5RYB7.js +9 -0
  72. package/dist/browser-lazy/chunks/ishikawa-LD3YBDJN.js +6 -0
  73. package/dist/browser-lazy/chunks/journey-6YQR5DJX.js +16 -0
  74. package/dist/browser-lazy/chunks/kanban-PLMJ7NBW.js +20 -0
  75. package/dist/browser-lazy/chunks/mermaid-yaml-runtime-QVYX4EWK.js +136 -0
  76. package/dist/browser-lazy/chunks/mindmap-K2UBFO3Y.js +12 -0
  77. package/dist/browser-lazy/chunks/packet-CUW4QY6Y.js +7 -0
  78. package/dist/browser-lazy/chunks/pie-7F7UUCG3.js +15 -0
  79. package/dist/browser-lazy/chunks/quadrant-TOONO2WC.js +10 -0
  80. package/dist/browser-lazy/chunks/radar-J6JVWVAX.js +16 -0
  81. package/dist/browser-lazy/chunks/render-core-BZOM3K7D.js +3 -0
  82. package/dist/browser-lazy/chunks/requirement-CMAKDJPO.js +19 -0
  83. package/dist/browser-lazy/chunks/sankey-AWXQEP3F.js +13 -0
  84. package/dist/browser-lazy/chunks/sequence-Q2RJRB4L.js +5 -0
  85. package/dist/browser-lazy/chunks/state-WRBFQEDX.js +4 -0
  86. package/dist/browser-lazy/chunks/timeline-D2KILFXM.js +6 -0
  87. package/dist/browser-lazy/chunks/treemap-N3VYX5D4.js +6 -0
  88. package/dist/browser-lazy/chunks/xychart-G73OGK66.js +16 -0
  89. package/dist/browser-lazy/chunks/zenuml-H4BXNYXR.js +16 -0
  90. package/dist/browser-lazy/index.d.ts +544 -275
  91. package/dist/browser-lazy/index.js +1 -1
  92. package/dist/browser.global.js +802 -565
  93. package/dist/chunk-3LGLPG33.js +2 -0
  94. package/dist/chunk-7CRDX2QR.js +2 -0
  95. package/dist/chunk-7PPW2BMO.js +2 -0
  96. package/dist/chunk-DQDKA5ND.js +2 -0
  97. package/dist/chunk-EHCMJUMD.js +52 -0
  98. package/dist/chunk-GVCHLSHH.js +4 -0
  99. package/dist/chunk-H3NCS2XZ.js +19 -0
  100. package/dist/chunk-JZOJ4YGS.js +201 -0
  101. package/dist/chunk-MKE7GNYU.js +146 -0
  102. package/dist/chunk-NKNFOREZ.js +2 -0
  103. package/dist/chunk-O7H2UX5K.js +2 -0
  104. package/dist/chunk-OMY6NRQD.js +58 -0
  105. package/dist/chunk-UA234O4M.js +4 -0
  106. package/dist/chunk-VUFVLGTH.js +2 -0
  107. package/dist/chunk-XU5LPD2D.js +2 -0
  108. package/dist/cli-YGGTJZH7.js +226 -0
  109. package/dist/elk-constructor.js +2 -0
  110. package/dist/elk-constructor.node.js +11 -0
  111. package/dist/index-EeXqJXr5.d.ts +1223 -0
  112. package/dist/index.d.ts +4 -1
  113. package/dist/index.js +1 -334
  114. package/dist/jsonl-RPJY6YWO.js +2 -0
  115. package/dist/mcp-cli-63DYXTVD.js +2 -0
  116. package/dist/{index-BGA_-6LV.d.ts → paint-certification-6rwQjIv_.d.ts} +5283 -6173
  117. package/dist/server-5NEOHOFS.js +524 -0
  118. package/dist/svg-styles-BdnoM7AT.d.ts +724 -0
  119. package/dist/svg-styles.d.ts +1 -0
  120. package/dist/svg-styles.js +2 -0
  121. package/dist/svg.d.ts +13 -0
  122. package/dist/svg.js +2 -0
  123. package/dist/types-BcS52Mjt.d.ts +1360 -0
  124. package/dist/zenuml/chunks/appearance-UOQ5KA6O.js +1 -0
  125. package/dist/zenuml/chunks/builtin-backends-KDKE7YHO.js +12 -0
  126. package/dist/zenuml/chunks/chunk-42DXZ5C6.js +4 -0
  127. package/dist/zenuml/chunks/chunk-7TVYPTDW.js +1 -0
  128. package/dist/zenuml/chunks/chunk-EVPSMEKN.js +1 -0
  129. package/dist/zenuml/chunks/chunk-OXQWRSBM.js +20 -0
  130. package/dist/zenuml/chunks/chunk-QWX77U7G.js +2 -0
  131. package/dist/zenuml/chunks/chunk-RLJEI7YN.js +29 -0
  132. package/dist/zenuml/chunks/chunk-RZ6XK5CD.js +29 -0
  133. package/dist/zenuml/chunks/decode-BWERFDGK.js +1 -0
  134. package/dist/zenuml/chunks/mermaid-yaml-runtime-KZVU74WU.js +136 -0
  135. package/dist/zenuml/chunks/render-core-V5RQ737O.js +3 -0
  136. package/dist/zenuml/chunks/zenuml-EA2ZFRUX.js +20 -0
  137. package/dist/zenuml-frame.global.js +3626 -0
  138. package/dist/zenuml.d.ts +83 -0
  139. package/dist/zenuml.js +1 -0
  140. package/docs/MCP-DIRECTORY-LISTINGS.md +5 -1
  141. package/docs/README.md +59 -103
  142. package/docs/agent-api-cookbook.md +26 -16
  143. package/docs/agent-mutation-policy.md +86 -15
  144. package/docs/agent-workflow-examples.md +1 -1
  145. package/docs/api-advanced.md +385 -0
  146. package/docs/api.md +320 -366
  147. package/docs/ascii.md +40 -4
  148. package/docs/browser.md +46 -7
  149. package/docs/choosing-a-diagram.md +148 -0
  150. package/docs/code-mode-impact.md +1 -0
  151. package/docs/comparison.md +244 -28
  152. package/docs/computational-aesthetics-prototype-plan.md +10 -10
  153. package/docs/config.md +60 -2
  154. package/docs/custom-fonts.md +78 -21
  155. package/docs/diagram-families.md +160 -10
  156. package/docs/eventmodeling-and-zenuml.md +165 -0
  157. package/docs/features.md +21 -19
  158. package/docs/fork-differences.md +105 -32
  159. package/docs/getting-started.md +56 -51
  160. package/docs/layout-certification.md +126 -0
  161. package/docs/mcp-code-mode-rationale.md +20 -12
  162. package/docs/mcp-http-transport.md +14 -8
  163. package/docs/quality.md +145 -15
  164. package/docs/react.md +76 -31
  165. package/docs/style-authoring.md +23 -11
  166. package/docs/svg-semantic-contract.md +104 -4
  167. package/docs/testing-strategy.md +684 -126
  168. package/docs/theming.md +27 -8
  169. package/examples/styles/readme-hero.md +25 -0
  170. package/examples/styles/readme-hero.mmd +13 -0
  171. package/examples/styles/readme-hero.style.json +7 -0
  172. package/package.json +114 -57
  173. package/server.json +2 -2
  174. package/skills/agentic-mermaid-diagram-workflow/SKILL.md +26 -8
  175. package/skills/agentic-mermaid-diagram-workflow/references/cli.md +13 -3
  176. package/skills/agentic-mermaid-diagram-workflow/references/code-mode.md +2 -1
  177. package/skills/agentic-mermaid-diagram-workflow/references/flowchart.md +9 -6
  178. package/skills/agentic-mermaid-diagram-workflow/references/hosted-mcp.md +1 -0
  179. package/skills/agentic-mermaid-diagram-workflow/references/sequence.md +4 -3
  180. package/skills/agentic-mermaid-diagram-workflow/references/timeline.md +7 -6
  181. package/skills/agentic-mermaid-diagram-workflow/references/upstream/agentflow.md +574 -0
  182. package/skills/agentic-mermaid-diagram-workflow/references/upstream/architecture.md +10 -2
  183. package/skills/agentic-mermaid-diagram-workflow/references/upstream/c4.md +18 -0
  184. package/skills/agentic-mermaid-diagram-workflow/references/upstream/classDiagram.md +123 -0
  185. package/skills/agentic-mermaid-diagram-workflow/references/upstream/cynefin.md +6 -1
  186. package/skills/agentic-mermaid-diagram-workflow/references/upstream/entityRelationshipDiagram.md +129 -9
  187. package/skills/agentic-mermaid-diagram-workflow/references/upstream/eventmodeling.md +22 -0
  188. package/skills/agentic-mermaid-diagram-workflow/references/upstream/flowchart.md +188 -60
  189. package/skills/agentic-mermaid-diagram-workflow/references/upstream/gitgraph.md +13 -7
  190. package/skills/agentic-mermaid-diagram-workflow/references/upstream/mindmap.md +110 -1
  191. package/skills/agentic-mermaid-diagram-workflow/references/upstream/packet.md +38 -0
  192. package/skills/agentic-mermaid-diagram-workflow/references/upstream/requirementDiagram.md +115 -0
  193. package/skills/agentic-mermaid-diagram-workflow/references/upstream/sequenceDiagram.md +101 -0
  194. package/skills/agentic-mermaid-diagram-workflow/references/upstream/stateDiagram.md +87 -0
  195. package/skills/agentic-mermaid-diagram-workflow/references/upstream/swimlanes.md +105 -2
  196. package/skills/agentic-mermaid-diagram-workflow/references/upstream/timeline.md +12 -6
  197. package/skills/agentic-mermaid-diagram-workflow/references/upstream/usecase.md +953 -0
  198. package/skills/agentic-mermaid-diagram-workflow/references/upstream/venn.md +77 -0
  199. package/skills/agentic-mermaid-diagram-workflow/references/upstream/xyChart.md +1 -1
  200. package/dist/browser-lazy/chunks/architecture-KTHE2HX3.js +0 -31
  201. package/dist/browser-lazy/chunks/chunk-2XCPFAD5.js +0 -46
  202. package/dist/browser-lazy/chunks/chunk-3H4F7RBT.js +0 -1
  203. package/dist/browser-lazy/chunks/chunk-4EVLW2NJ.js +0 -1
  204. package/dist/browser-lazy/chunks/chunk-5Q4S74UO.js +0 -1
  205. package/dist/browser-lazy/chunks/chunk-6OAPWSDO.js +0 -1
  206. package/dist/browser-lazy/chunks/chunk-A7L4WWVW.js +0 -143
  207. package/dist/browser-lazy/chunks/chunk-C7FJO2I3.js +0 -4
  208. package/dist/browser-lazy/chunks/chunk-D3XXDKIO.js +0 -1
  209. package/dist/browser-lazy/chunks/chunk-DXA5WL7H.js +0 -4
  210. package/dist/browser-lazy/chunks/chunk-EPFMQPXX.js +0 -1
  211. package/dist/browser-lazy/chunks/chunk-FFOHLPDA.js +0 -2
  212. package/dist/browser-lazy/chunks/chunk-FLD63DXE.js +0 -2
  213. package/dist/browser-lazy/chunks/chunk-G6OLSHRG.js +0 -7
  214. package/dist/browser-lazy/chunks/chunk-GRXCKTHX.js +0 -0
  215. package/dist/browser-lazy/chunks/chunk-I6VE56S7.js +0 -1
  216. package/dist/browser-lazy/chunks/chunk-KJVNXJ5Y.js +0 -1
  217. package/dist/browser-lazy/chunks/chunk-L227EPFP.js +0 -11
  218. package/dist/browser-lazy/chunks/chunk-LNIHDJSF.js +0 -1
  219. package/dist/browser-lazy/chunks/chunk-M6BT2HIP.js +0 -1
  220. package/dist/browser-lazy/chunks/chunk-NZRUMODH.js +0 -1
  221. package/dist/browser-lazy/chunks/chunk-OFRMKQA6.js +0 -1
  222. package/dist/browser-lazy/chunks/chunk-P7HMSKHJ.js +0 -1
  223. package/dist/browser-lazy/chunks/chunk-PXKL3O6H.js +0 -1
  224. package/dist/browser-lazy/chunks/chunk-PZEWZT35.js +0 -1
  225. package/dist/browser-lazy/chunks/chunk-STQRDZ67.js +0 -1
  226. package/dist/browser-lazy/chunks/chunk-SUFMSWTX.js +0 -1
  227. package/dist/browser-lazy/chunks/chunk-T7IJ6V4B.js +0 -3
  228. package/dist/browser-lazy/chunks/chunk-UAEZO5VL.js +0 -1
  229. package/dist/browser-lazy/chunks/chunk-WEUWIFG3.js +0 -1
  230. package/dist/browser-lazy/chunks/chunk-X64T74C5.js +0 -24
  231. package/dist/browser-lazy/chunks/class-F7R6TJ73.js +0 -9
  232. package/dist/browser-lazy/chunks/er-BDK7CM5L.js +0 -9
  233. package/dist/browser-lazy/chunks/flowchart-KFU6XV7S.js +0 -4
  234. package/dist/browser-lazy/chunks/gantt-I64VVDSP.js +0 -28
  235. package/dist/browser-lazy/chunks/gitgraph-EDUVJ5IJ.js +0 -8
  236. package/dist/browser-lazy/chunks/journey-TLO2RNM3.js +0 -40
  237. package/dist/browser-lazy/chunks/mindmap-OJCNDYPM.js +0 -9
  238. package/dist/browser-lazy/chunks/pie-HVG6XO7K.js +0 -19
  239. package/dist/browser-lazy/chunks/quadrant-U6S2L4MJ.js +0 -24
  240. package/dist/browser-lazy/chunks/radar-ZDLOBTVG.js +0 -32
  241. package/dist/browser-lazy/chunks/render-core-Y2DFNMQG.js +0 -12
  242. package/dist/browser-lazy/chunks/sequence-Z4WFS3VB.js +0 -12
  243. package/dist/browser-lazy/chunks/state-2HV2YGN3.js +0 -4
  244. package/dist/browser-lazy/chunks/timeline-XM4UFPOC.js +0 -20
  245. package/dist/browser-lazy/chunks/xychart-7JDHWTQY.js +0 -36
  246. package/dist/chunk-GGXCNCNA.js +0 -4118
  247. package/dist/chunk-IVD4NXNE.js +0 -615
  248. package/dist/chunk-JDMRPUAG.js +0 -37
  249. package/dist/chunk-JWAAW3FH.js +0 -149
  250. package/dist/chunk-LCGBT32P.js +0 -62036
  251. package/dist/chunk-RWMZRUIC.js +0 -4715
  252. package/dist/mcp-cli-4MLKC3ZH.js +0 -17
  253. package/docs/mutation-testing.md +0 -285
@@ -0,0 +1,201 @@
1
+ import{$ as rn,$b as _l,$c as Ei,$e as gb,$f as wh,$g as Xb,$h as bC,A as jg,Aa as Ty,Ab as go,Ac as cx,Ad as cn,Ae as rh,Af as vb,Ag as $b,Ah as Cc,Ai as NC,B as Vg,Ba as vy,Bb as Ds,Bc as Nn,Bd as Px,Be as Us,Bf as yh,Bg as ea,Bh as aC,Bi as PC,C as Yg,Cc as Nl,Cd as Fx,Ce as ih,Cf as lc,Cg as Do,Ch as lC,Ci as wc,D as Hg,Db as Uy,Dd as $x,De as sb,Df as qn,Dg as ta,Dh as Un,Di as Tc,E as Xg,Ea as Iu,Eb as jy,Ec as dx,Ed as qx,Ee as nh,Ef as cc,Eg as qb,Eh as Bh,Ei as FC,F as Kg,Fb as El,Fc as ux,Fd as zx,Fe as oh,Ff as Eb,Fg as ra,Fi as $C,G as Jg,Ga as Si,Gb as yo,Gc as ju,Gd as qs,Gf as xh,Gg as ia,Gh as kc,Gi as qC,H as Qg,Ha as po,Hb as sn,Hc as hx,Hd as Kl,He as js,Hf as dc,Hg as zb,Hh as cC,Hi as zC,I as Zg,Ia as On,Ib as Ns,Ic as Pl,Id as Ju,Ie as ab,If as uc,Ig as Gb,J as ey,Ja as Ey,Jb as Vy,Jc as mx,Jd as Gx,Je as ic,Jf as hc,Jg as gc,K as ty,Ka as wi,Kb as Ml,Kc as vi,Kd as Wx,Ke as lb,Kf as Hs,Kg as Wb,L as ry,La as Br,Lb as Yy,Lc as Fl,Ld as Jl,Le as sh,Lf as bh,Lg as Ub,Li as GC,M as iy,Ma as Lu,Mb as Hy,Mc as fx,Md as Qu,Mf as mc,Mg as yc,Mh as dC,Mi as WC,N as ny,Na as My,Nb as Xy,Nc as px,Ne as cb,Nf as Xs,Ng as na,Nh as _h,Ni as UC,O as oy,Oa as Ay,Ob as Ky,Oc as So,Od as Ql,Oe as db,Of as Mb,Og as jb,Oh as uC,Oi as jC,P as sy,Pa as Is,Pb as Rn,Pc as $l,Pd as Zu,Pe as ub,Pf as Bo,Pg as Vb,Ph as hC,Pi as VC,Q as ay,Qa as st,Qb as an,Qc as wx,Qd as _r,Qf as zn,Qg as No,Qh as mC,Qi as YC,R as gl,Rb as Jy,Rc as ln,Rd as Mo,Re as hb,Rf as Ab,Rg as Yb,Rh as fC,Ri as HC,S as ly,Sa as Oy,Sb as Al,Sc as Tx,Sd as Ux,Se as ah,Sf as Ob,Sg as xc,Sh as pC,Si as XC,T as cy,Ta as Ru,Tb as Ol,Tc as Yu,Td as jx,Te as nc,Tf as _o,Tg as Eh,Th as Sc,Ti as KC,U as yl,Ua as Du,Uc as ql,Ud as dn,Ue as oi,Uf as Oi,Ug as Wn,Uh as gC,Ui as JC,V as En,Va as wl,Vb as Qy,Vc as wo,Vd as Vx,Ve as mb,Vf as Io,Vh as yC,Vi as QC,W as dy,Wa as By,Wb as xo,Wc as Hu,Wd as Ao,Wf as Ch,Wg as Mh,Wi as ZC,X as tn,Xa as _y,Xb as Zy,Xc as Pn,Xd as Mi,Xe as fb,Xf as kh,Xg as Bi,Xi as ek,Y as xl,Ya as Iy,Yb as Ps,Yc as To,Yd as zs,Ye as pb,Yf as Bb,Yh as Ih,Yi as tk,Z as Bu,Za as Ly,Zb as ex,Zc as vx,Ze as lh,Zf as Sh,Zg as Hb,Zh as Lh,Zi as vc,_ as Or,_a as Ry,_b as tx,_c as Xu,_e as ch,_f as Lo,_h as xC,_i as rk,aa as ki,ab as Ny,ac as Lt,ad as Ex,af as dh,ag as _b,ah as Kb,ai as CC,aj as ik,ba as uy,bc as rx,bd as $s,be as Gs,bf as uh,bg as Ks,bi as kC,bj as nk,ca as bl,cb as nn,cc as Il,cd as zl,ce as Yx,cf as Fn,cg as fc,ch as rC,ci as SC,cj as ok,d as Sg,da as hy,db as Bn,dc as Gu,dd as vo,de as Hx,df as yb,dh as iC,di as Rh,e as wg,ea as Cl,eb as ii,ed as Gl,ee as Xx,ef as oc,eg as Js,ei as wC,f as Tg,fa as kl,fb as _n,fc as ix,fd as Wl,fe as Kx,ff as sc,fg as Ib,fi as TC,fj as sk,g as vg,ga as Os,gb as Ti,gd as Mx,ge as Jx,gg as ai,gi as Dh,gj as Fo,h as Eg,ha as my,hb as In,hc as Ve,hd as Ax,hf as xb,hg as Lb,i as Mg,ia as Mn,ic as Bt,id as Ox,ie as Ai,if as bb,ig as Th,ii as vC,j as Ag,ja as fy,jb as ni,jc as Xt,jd as Bx,je as Qx,jf as hh,jg as Rb,k as Og,kb as Py,kc as bo,kd as Eo,kf as Cb,kg as pc,l as Bg,la as py,lb as $u,lc as Co,ld as Ul,le as Zl,lf as mh,li as EC,m as _g,ma as gy,mb as Tl,mc as nx,md as kt,me as Ws,mf as fh,mg as Db,mh as nC,mi as MC,n as Ig,nb as zt,nc as ox,nd as _x,ne as eh,nf as $n,ng as Qs,nh as oC,ni as aa,o as Lg,oa as yy,ob as on,oc as Fs,od as jl,oe as Oo,of as kb,oh as sC,oi as Nh,p as Rg,pb as qu,pc as ko,pe as Zx,pf as si,ph as Oh,pi as AC,q as Dg,qa as ct,qb as Fy,qc as sx,qd as Ix,qe as eb,qf as Vs,qg as Ro,qi as OC,r as Ng,ra as mo,rb as $y,rc as ax,rd as Ku,re as ec,rf as Sb,rg as vh,ri as BC,s as Pg,sa as Sl,sb as qy,sc as lx,sd as Vl,se as tb,sf as Ys,sg as li,si as Ph,t as Fg,ta as Cy,tb as zu,tc as gr,td as Yl,te as tc,tf as wb,ti as _C,u as $g,ua as ky,ub as Ln,uc as Ll,ud as Hl,ue as rb,ui as IC,v as qg,va as fo,vb as vl,vc as Wu,vd as Xl,ve as ib,vf as ph,vg as Gn,vi as Fh,w as zg,wa as Bs,wb as zy,wc as Rl,wd as Lx,we as nb,wg as Nb,wi as LC,x as Gg,xa as _s,xb as Gy,xc as Uu,xd as Rx,xe as ob,xf as ac,xg as Pb,xi as Po,y as Wg,ya as Sy,yb as Rs,yc as Dn,yd as Dx,ye as th,yf as Tb,yg as Fb,yi as RC,z as Ug,za as wy,zb as Wy,zc as Dl,zd as Nx,ze as rc,zf as gh,zg as Zs,zi as DC}from"./chunk-EHCMJUMD.js";import{B as ku,Ba as ug,Bb as Eu,Bd as Zb,C as Su,Cd as eC,D as wu,Dc as Pu,E as Tu,Eb as As,F as vu,Fb as Ci,G as og,Gb as pl,Gc as Fu,I as ri,Ic as gx,Jc as yx,Jd as tC,Kc as xx,La as Ot,Ld as bc,Mc as Vu,Na as hg,Nb as Mu,Nc as bx,Oa as dl,Oc as Cx,Pa as Ge,Pc as kx,Qc as Sx,R as ll,Rb as en,Va as mg,Wa as vn,Xa as fg,Xb as kg,Ya as Es,Za as Ms,_a as ul,ab as pg,ac as Au,b as al,cb as gg,cc as Ou,d as Mr,da as $t,db as yg,e as ig,ea as sg,fa as Ye,fb as Ar,ga as ag,gc as An,hc as wt,ia as lg,ib as Zi,ic as xy,ja as cl,ka as bt,kb as hl,mc as by,nb as xg,nc as _u,ob as bg,pb as Cg,qa as cg,r as ng,s as Ft,sd as un,ta as dg,ud as Jb,vc as Nu,wb as qt,wc as Dy,wd as Qb,xb as ml,xc as Ls,yd as Ah,zb as fl}from"./chunk-OMY6NRQD.js";import{C as Bl,F as oa,G as sa,H as ci,a as re,b as T}from"./chunk-O7H2UX5K.js";var jn=[{role:"prelude",primitives:["document"]},{role:"chrome",primitives:["document"]},{role:"title",primitives:["text"]}];var $o=[{role:"node",primitives:["container","shape"]},{role:"label",primitives:["text"]}];var ak=[{id:"packet",upstreamId:"packet",maturity:"stable",label:"Packet",headers:["packet","packet-beta"],narrower:"asPacket",editorDiagramType:"Packet",editorLabel:"Packet layout",editorDescription:"Bit-accurate packet fields with wrapping word rows.",editorExampleId:"packet-basic",editorGlyph:"PK",config:{section:"packet",keys:_y,noopKeys:["useMaxWidth"]},semanticChannels:[],sceneRoles:[...jn,...$o],detect:Qg,example:'packet\n0-15: "Source port"\n16-31: "Destination port"',editorExample:'packet\ntitle UDP datagram\n+16: "Source port"\n+16: "Destination port"\n+16: "Length"\n+16: "Checksum"\n+32: "Payload"'},{id:"kanban",upstreamId:"kanban",maturity:"stable",label:"Kanban",headers:["kanban"],narrower:"asKanban",editorDiagramType:"Kanban",editorLabel:"Kanban board",editorDescription:"Ordered workflow columns and task cards with assignees and tickets.",editorExampleId:"kanban-basic",editorGlyph:"KB",config:{section:"kanban",keys:Ly,noopKeys:["useMaxWidth"]},semanticChannels:[],sceneRoles:[...jn,...$o,{role:"group",primitives:["container","shape"]},{role:"group-header",primitives:["shape"]}],detect:Zg,example:"kanban\n todo[To do]\n parser[Build parser]\n done[Done]\n research[Research]",editorExample:'kanban\n todo[To do]\n packet[Packet family]@{ assigned: "Maya", priority: "High" }\n doing[In progress]\n kanban[Kanban family]@{ assigned: "Alex", ticket: "AM-409" }\n done[Done]\n research[Community research]'},{id:"requirement",upstreamId:"requirement",maturity:"stable",label:"Requirement",headers:["requirementDiagram","requirement"],narrower:"asRequirement",editorDiagramType:"Requirement",editorLabel:"Requirements",editorDescription:"Requirements, evidence elements and typed traceability relationships.",editorExampleId:"requirement-basic",editorGlyph:"RQ",config:{section:"requirement",keys:["rect_fill","text_color","rect_border_size","rect_border_color","rect_min_width","rect_min_height","maxWidth","fontSize","rect_padding","line_height","nodeSpacing","rankSpacing","useMaxWidth","look","theme"],noopKeys:["useMaxWidth","look","theme"]},semanticChannels:[],sceneRoles:[...jn.filter(t=>t.role!=="chrome"),{role:"chrome",primitives:["document","shape"]},...$o,{role:"relationship",primitives:["connector"]},{role:"attribute",primitives:["text"]},{role:"edge-label",primitives:["text","container"]},{role:"defs",primitives:["document","marker"]}],detect:ey,example:'requirementDiagram\n requirement fast {\n id: 1\n text: Respond within 100ms\n risk: high\n verifymethod: test\n }\n element benchmark {\n type: "test"\n }\n benchmark - verifies -> fast',editorExample:"requirementDiagram\n direction LR\n requirement reliable {\n id: R1\n text: Requests retain authored meaning\n risk: high\n verifymethod: test\n }\n functionalRequirement edits {\n id: R2\n text: Typed edits preserve all relationships\n risk: medium\n verifymethod: inspection\n }\n element suite {\n type: conformance suite\n }\n reliable - contains -> edits\n suite - verifies -> edits"},{id:"treemap",upstreamId:"treemap",maturity:"stable",label:"Treemap",headers:["treemap","treemap-beta"],narrower:"asTreemap",editorDiagramType:"Treemap",editorLabel:"Treemap",editorDescription:"Value-proportional nested rectangles for hierarchical data.",editorExampleId:"treemap-basic",editorGlyph:"TM",config:{section:"treemap",keys:["useMaxWidth","padding","diagramPadding","showValues","nodeWidth","nodeHeight","borderWidth","valueFontSize","labelFontSize","valueFormat"],noopKeys:["useMaxWidth"]},semanticChannels:["value","category"],sceneRoles:[...jn.filter(t=>t.role!=="chrome"),{role:"chrome",primitives:["document","shape"]},{role:"node",primitives:["container"]},{role:"group",primitives:["container"]},{role:"bar",primitives:["shape","data-mark"]},{role:"label",primitives:["text"]}],detect:ty,example:'treemap\n"Product"\n "Engineering": 60\n "Design": 40',editorExample:'treemap\ntitle Product investment\n"Build"\n "Engineering": 60\n "Design": 25\n"Learn"\n "Research": 30\n "Analytics": 15'},{id:"ishikawa",upstreamId:"ishikawa",maturity:"stable",label:"Ishikawa",headers:["ishikawa","ishikawa-beta"],narrower:"asIshikawa",editorDiagramType:"Ishikawa",editorLabel:"Fishbone analysis",editorDescription:"Cause-and-effect fishbone with nested contributing causes.",editorExampleId:"ishikawa-basic",editorGlyph:"IK",config:{section:"ishikawa",keys:["diagramPadding","useMaxWidth"],noopKeys:["useMaxWidth"]},semanticChannels:[],sceneRoles:[...jn,...$o,{role:"defs",primitives:["document","marker"]},{role:"edge",primitives:["connector"]},{role:"rail",primitives:["connector"]}],detect:ry,example:"ishikawa\n Slow release\n Process\n Manual checks\n Tooling\n Slow builds",editorExample:"ishikawa\n Delayed release\n Process\n Manual approvals\n Unclear acceptance\n People\n Shared ownership\n Tooling\n Slow builds\n Cold caches\n Environment\n Unstable test data"},{id:"block",upstreamId:"block",maturity:"stable",label:"Block",headers:["block","block-beta"],narrower:"asBlock",editorDiagramType:"Block",editorLabel:"Block diagram",editorDescription:"Authored grid placement with column spans and nested composites.",editorExampleId:"block-basic",editorGlyph:"BL",config:{section:"block",keys:["padding","useMaxWidth"],noopKeys:["useMaxWidth"]},semanticChannels:[],sceneRoles:[...jn.filter(t=>t.role!=="chrome"),{role:"chrome",primitives:["document","shape"]},...$o,{role:"group",primitives:["container","shape"]},{role:"edge",primitives:["connector"]},{role:"edge-label",primitives:["text","container"]},{role:"defs",primitives:["document","marker"]}],detect:iy,example:'block\n columns 2\n A["API"] B["Database"]\n A --> B',editorExample:'block\n columns 3\n client["Client"] space api["API"]\n block:data:3\n columns 2\n primary[("Primary")] replica[("Replica")]\n primary --> replica\n end\n client --> api\n api --> primary'},{id:"eventmodeling",upstreamId:"eventmodeling",maturity:"experimental",label:"Event Modeling",headers:["eventmodeling"],narrower:"asEventModeling",editorDiagramType:"Event Modeling",editorLabel:"Event Modeling",editorDescription:"Time frames, swimlanes and directed information flow.",editorExampleId:"eventmodeling-basic",editorGlyph:"EM",config:{section:"eventmodeling",keys:["padding","rowHeight","useWidth","useMaxWidth","theme","look","layout"],noopKeys:["useWidth","useMaxWidth","theme","look","layout"]},semanticChannels:[],sceneRoles:[...jn.filter(t=>t.role!=="chrome"),{role:"chrome",primitives:["document","shape"]},...$o,{role:"group",primitives:["container","shape"]},{role:"edge",primitives:["connector"]},{role:"defs",primitives:["document","marker"]}],detect:oy,example:"eventmodeling\ntf 01 ui CartUI\ntf 02 cmd AddItem\ntf 03 evt ItemAdded",editorExample:"eventmodeling\ntf 01 ui CartUI\ntf 02 cmd AddItem\ntf 03 evt ItemAdded\ntf 04 rmo CartItems\ntf 05 ui CartUI"}];function la(t){const e=[];const r=t.split(/\r?\n/);let i=0;for(const n of r){i++;const o=n.trim();if(!o||o.startsWith("%%"))continue;for(const a of o.matchAll(/"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'/g)){const l=a[1]??a[2]??"";if(l)e.push({text:l,target:`line${i}`})}for(const a of o.matchAll(/[\[\(\{]+([^\[\]\(\)\{\}]+?)[\]\)\}]+/g)){const l=(a[1]??"").trim();if(l&&!l.match(/^[A-Za-z_][\w-]*$/))e.push({text:l,target:`line${i}`})}const s=o.indexOf(":");if(s>=0&&s<o.length-1){const a=o.slice(s+1).trim();if(a&&!a.match(/^[\d.]+$/)&&a.length>=2){e.push({text:a,target:`line${i}`})}}}return e}var qo=["detection","source-preservation","parse","serialize","mutation","verify","layout","scene","svg","terminal"];var $h=64*1024;var pk=2;var lk=2;var GN=Object.freeze({detection:"diagnosed","source-preservation":"source-preserved",parse:"diagnosed",serialize:"source-preserved",mutation:"diagnosed",verify:"diagnosed",layout:"diagnosed",scene:"diagnosed",svg:"diagnosed",terminal:"diagnosed"});var ck=class extends Error{report;constructor(e){const r=e.capabilities.filter(i=>i.status==="failed").map(i=>`${i.capability}: ${i.diagnostic}`);super(`Family "${e.familyId}" failed executable registration conformance: ${r.join("; ")}`);this.name="FamilyConformanceError";this.report=e}};function BO(t,e,r){const i=[];for(const n of e){const o=new Map(n.primitives.map(s=>{const a=typeof s==="string"?{primitive:s,realization:"native"}:s;return[a.primitive,a]}));for(const s of Ls){const a=o.get(s);i.push(a?{role:n.role,primitive:s,applicability:"applicable",realization:a.realization,evidence:r,...a.diagnostic?{diagnostic:a.diagnostic}:{}}:{role:n.role,primitive:s,applicability:"not-applicable",realization:"unsupported",evidence:r,diagnostic:`${t}/${n.role} does not lower to the ${s} primitive.`})}}return i}function _O(t,e){const r=["src/__tests__/section-a-family-descriptor-conformance.test.ts"];const i=t==="flowchart"||t==="state"?[...r,"src/__tests__/characterization-layout.test.ts"]:r;return[{capability:"detection",state:"native",evidence:r},{capability:"source-preservation",state:"native",evidence:r},{capability:"parse",state:"native",evidence:r},{capability:"serialize",state:"native",evidence:r},{capability:"mutation",state:e?"native":"diagnosed",evidence:r},{capability:"verify",state:"native",evidence:r},{capability:"layout",state:"native",evidence:r},{capability:"scene",state:"native",evidence:r},{capability:"svg",state:"native",evidence:r},{capability:"terminal",state:"native",evidence:i}]}function le(t,...e){return{role:t,primitives:e}}var dk=[le("prelude","document"),le("title","text"),le("defs","document","marker"),le("chrome","document","shape"),le("actor","container","shape"),le("lifeline","container","connector"),le("activation","container","shape"),le("message","container","connector"),le("block","container","connector","shape"),le("group","container","shape"),le("note","container","shape"),le("label","text"),le("icon","container","shape","text")];var ca=[{id:"flowchart",upstreamId:"flowchart-v2",maturity:"stable",label:"Flowchart",headers:["flowchart","graph"],narrower:"asFlowchart",editorDiagramType:"Flowchart",editorLabel:"Flowchart",editorDescription:"Decision flow with labeled branches.",editorExampleId:"flowchart-basic",editorGlyph:"F",config:{section:"flowchart",keys:["nodeSpacing","rankSpacing","wrappingWidth","titleTopMargin","subGraphTitleMargin","arrowMarkerAbsolute","diagramPadding","htmlLabels","curve","padding","defaultRenderer","inheritDir","look","minNodeWidth","theme"],noopKeys:["arrowMarkerAbsolute","curve","defaultRenderer","diagramPadding","htmlLabels","inheritDir","look","minNodeWidth","padding","subGraphTitleMargin","theme","titleTopMargin"]},aliases:["swimlane"],semanticChannels:[],detect:Sg,sceneRoles:[le("prelude","document"),le("title","text"),le("defs","document","marker"),le("chrome","document","shape"),le("group","container","shape"),le("group-header","text","shape"),le("edge","connector"),le("edge-label","container"),le("node","container","shape"),le("label","text"),le("icon","container","shape","text")],example:"flowchart TD\n A[Start] --> B{Ship?}\n B -->|yes| C[Deploy]\n B -->|no| D[Fix]",editorExample:`flowchart TD
2
+ A[Start] --> B{Decision?}
3
+ B -->|Yes| C[Do the thing]
4
+ B -->|No| D[Skip it]
5
+ C --> E[End]
6
+ D --> E`},{id:"state",upstreamId:"stateDiagram",maturity:"stable",label:"State",headers:["stateDiagram","stateDiagram-v2"],narrower:"asState",editorDiagramType:"State",editorLabel:"State diagram",editorDescription:"Lifecycle using Mermaid stateDiagram-v2 syntax.",editorExampleId:"state-basic",editorGlyph:"S",config:{section:"state",keys:["arrowMarkerAbsolute","compositTitleSize","defaultRenderer","dividerMargin","edgeLengthFactor","fontSize","fontSizeFactor","forkHeight","forkWidth","labelHeight","layout","look","miniPadding","minNodeWidth","nodeSpacing","noteMargin","padding","radius","rankSpacing","sizeUnit","textHeight","theme","titleShift","titleTopMargin","wrappingWidth"]},semanticChannels:["status"],detect:wg,detectLoose:Tg,sceneRoles:[le("prelude","document"),le("title","text"),le("defs","document","marker"),le("chrome","document","shape"),le("group","container","shape"),le("group-header","text","shape"),le("edge","connector"),le("edge-label","container"),le("node","container","shape"),le("note","container","shape"),le("label","text")],example:"stateDiagram-v2\n [*] --> Draft\n Draft --> Review : submit\n Review --> [*] : approve",editorExample:`stateDiagram-v2
7
+ [*] --> Idle
8
+ Idle --> Processing: start
9
+ Processing --> Complete: done
10
+ Processing --> Failed: error
11
+ Failed --> Idle: retry
12
+ Complete --> [*]`},{id:"sequence",upstreamId:"sequence",maturity:"stable",label:"Sequence",headers:["sequenceDiagram"],narrower:"asSequence",editorDiagramType:"Sequence",editorLabel:"Sequence",editorDescription:"Request/response messages between participants.",editorExampleId:"sequence-basic",editorGlyph:"Q",config:{section:"sequence",keys:["actorMargin","width","height","diagramMarginX","diagramMarginY","messageMargin","noteMargin","activationWidth","showSequenceNumbers","boxMargin","boxTextMargin","messageAlign","mirrorActors","bottomMarginAdj","rightAngles","wrap","wrapPadding","labelBoxWidth","labelBoxHeight","hideUnusedParticipants","forceMenus","arrowMarkerAbsolute","noteAlign","actorFontSize","actorFontFamily","actorFontWeight","noteFontSize","noteFontFamily","noteFontWeight","messageFontSize","messageFontFamily","messageFontWeight","actorFont","noteFont","messageFont","useMaxWidth","useWidth","look","theme"],noopKeys:["actorFont","actorFontFamily","actorFontSize","actorFontWeight","arrowMarkerAbsolute","bottomMarginAdj","boxMargin","boxTextMargin","forceMenus","hideUnusedParticipants","labelBoxHeight","labelBoxWidth","look","messageAlign","messageFont","messageFontFamily","messageFontSize","messageFontWeight","mirrorActors","noteAlign","noteFont","noteFontFamily","noteFontSize","noteFontWeight","rightAngles","theme","useMaxWidth","useWidth","wrapPadding"]},semanticChannels:["category"],detect:vg,detectLoose:Eg,sceneRoles:dk,example:"sequenceDiagram\n participant U as User\n participant S as Server\n U->>S: request\n S-->>U: response",editorExample:`sequenceDiagram
13
+ participant User
14
+ participant App
15
+ participant API
16
+ User->>App: Click export
17
+ App->>API: Render SVG
18
+ API-->>App: SVG string
19
+ App-->>User: Download`},{id:"timeline",upstreamId:"timeline",maturity:"experimental",label:"Timeline",headers:["timeline"],narrower:"asTimeline",editorDiagramType:"Timeline",editorLabel:"Timeline",editorDescription:"Chronological milestones with sections.",editorExampleId:"timeline-basic",editorGlyph:"T",config:{section:"timeline",keys:["disableMulticolor","sectionFills","sectionColours","diagramMarginX","diagramMarginY","leftMargin","width","height","padding","boxMargin","boxTextMargin","noteMargin","messageMargin","messageAlign","bottomMarginAdj","rightAngles","taskFontSize","taskFontFamily","taskMargin","activationWidth","textPlacement","actorColours","useMaxWidth","useWidth"],noopKeys:["diagramMarginX","diagramMarginY","leftMargin","width","height","padding","boxMargin","boxTextMargin","noteMargin","messageMargin","messageAlign","bottomMarginAdj","rightAngles","taskFontSize","taskFontFamily","taskMargin","activationWidth","textPlacement","actorColours","useMaxWidth","useWidth"]},semanticChannels:["category"],detect:Mg,detectLoose:Ag,sceneRoles:[le("prelude","document"),le("chrome","document"),le("rail","shape"),le("title","text"),le("section","container","shape"),le("group-header","text","shape"),le("period","container","shape"),le("event","container","shape"),le("label","text")],example:"timeline\n title Roadmap\n 2025 : Alpha : Beta\n 2026 : GA",editorExample:`timeline
20
+ title Product roadmap
21
+ section Foundation
22
+ 2024 Q1 : Prototype
23
+ : Parser coverage
24
+ section Launch
25
+ 2024 Q2 : Public editor
26
+ : SVG export`},{id:"class",upstreamId:"classDiagram",maturity:"stable",label:"Class",headers:["classDiagram","classDiagram-v2"],narrower:"asClass",editorDiagramType:"Class",editorLabel:"Class",editorDescription:"Classes with members, inheritance, and composition.",editorExampleId:"class-basic",editorGlyph:"C",config:{section:"class",keys:["nodeSpacing","rankSpacing","titleTopMargin","arrowMarkerAbsolute","dividerMargin","padding","textHeight","defaultRenderer","diagramPadding","htmlLabels","hideEmptyMembersBox","hierarchicalNamespaces","look","theme"],noopKeys:["arrowMarkerAbsolute","defaultRenderer","diagramPadding","dividerMargin","hideEmptyMembersBox","htmlLabels","look","padding","textHeight","theme","titleTopMargin"]},semanticChannels:[],detect:Og,detectLoose:Bg,sceneRoles:[le("prelude","document"),le("title","text"),le("defs","document","marker"),le("chrome","document","shape","connector"),le("group","container","shape"),le("group-header","text","shape"),le("class-box","container","shape"),le("member","text"),le("relationship","connector"),le("cardinality","text"),le("note","container","shape"),le("label","text")],example:'classDiagram\n class Account {\n +id: string\n +close() void\n }\n Account <|-- Savings\n Account "1" o-- "*" Transaction : logs',editorExample:`classDiagram
27
+ class Renderer {
28
+ <<abstract>>
29
+ +render(source) string
30
+ }
31
+ class SVGRenderer {
32
+ +render(source) string
33
+ }
34
+ class RenderPipeline {
35
+ +run(source) string
36
+ }
37
+ Renderer <|-- SVGRenderer
38
+ RenderPipeline *-- SVGRenderer : owns`},{id:"er",upstreamId:"er",maturity:"stable",label:"ER",headers:["erDiagram"],narrower:"asEr",editorDiagramType:"ER",editorLabel:"ER diagram",editorDescription:"Entities, attributes, keys, and cardinality markers.",editorExampleId:"er-basic",editorGlyph:"ER",config:{section:"er",keys:["layoutDirection","nodeSpacing","rankSpacing","titleTopMargin","diagramPadding","minEntityWidth","minEntityHeight","entityPadding","stroke","fill","fontSize","look","theme"],noopKeys:["diagramPadding","entityPadding","fill","fontSize","look","minEntityHeight","minEntityWidth","stroke","theme","titleTopMargin"]},semanticChannels:["category"],detect:_g,detectLoose:Ig,sceneRoles:[le("prelude","document"),le("title","text"),le("defs","document"),le("chrome","document","shape"),le("group","container","shape"),le("group-header","shape"),le("entity","container","shape"),le("attribute","container","text"),le("relationship","connector"),le("cardinality","shape"),le("label","text")],example:"erDiagram\n CUSTOMER ||--o{ ORDER : places\n ORDER {\n string id\n }",editorExample:`erDiagram
39
+ CUSTOMER {
40
+ string id PK
41
+ string email
42
+ }
43
+ ORDER {
44
+ string id PK
45
+ date created
46
+ }
47
+ LINE_ITEM {
48
+ string id PK
49
+ int quantity
50
+ }
51
+ CUSTOMER ||--o{ ORDER : places
52
+ ORDER ||--|{ LINE_ITEM : contains`},{id:"journey",upstreamId:"journey",maturity:"stable",label:"Journey",headers:["journey"],narrower:"asJourney",editorDiagramType:"Journey",editorLabel:"User journey",editorDescription:"Scored user tasks grouped by section.",editorExampleId:"journey-basic",editorGlyph:"J",config:{section:"journey",keys:["diagramMarginX","diagramMarginY","leftMargin","maxLabelWidth","width","height","taskFontSize","taskFontFamily","taskMargin","actorColours","sectionFills","sectionColours","titleColor","titleFontFamily","titleFontSize","useMaxWidth","boxMargin","boxTextMargin","noteMargin","messageMargin","messageAlign","bottomMarginAdj","rightAngles","activationWidth","textPlacement"],noopKeys:["boxMargin","boxTextMargin","noteMargin","messageMargin","messageAlign","bottomMarginAdj","rightAngles","activationWidth","textPlacement"]},semanticChannels:["value","category"],detect:Lg,detectLoose:Rg,sceneRoles:[le("prelude","document"),le("defs","document","marker"),le("chrome","document"),le("title","text"),le("series","connector"),le("grid","container","connector"),le("axis","text"),le("rail","connector"),le("legend","container","text"),le("actor","shape"),le("section","container","shape"),le("group-header","text","shape"),le("task","container","shape","data-mark"),le("marker-line","connector"),le("label","text"),le("score","container","shape","data-mark")],example:"journey\n title Checkout\n section Browse\n Find product: 4: Shopper\n section Buy\n Pay: 3: Shopper",editorExample:`journey
53
+ title Editor adoption
54
+ section Try
55
+ Open editor: 5: User
56
+ Load example: 4: User, Developer
57
+ section Share
58
+ Copy URL: 5: User
59
+ Export SVG: 4: Developer`},{id:"architecture",upstreamId:"architecture",maturity:"stable",label:"Architecture",headers:["architecture","architecture-beta"],narrower:"asArchitecture",editorDiagramType:"Architecture",editorLabel:"Architecture",editorDescription:"Services, groups, icons, and routed connections.",editorExampleId:"architecture-basic",editorGlyph:"A",config:{section:"architecture",keys:["padding","iconSize","fontSize","nodeSeparation","idealEdgeLengthMultiplier","edgeElasticity","numIter","seed","randomize"],noopKeys:["edgeElasticity","numIter","randomize","seed"]},semanticChannels:[],detect:Dg,detectLoose:Ng,sceneRoles:[le("prelude","document"),le("defs","document","marker"),le("chrome","document","shape"),le("title","text"),le("group","container","shape"),le("group-header","shape"),le("icon","container","shape","text"),le("label","text"),le("service","container","shape"),le("junction","container","shape"),le("edge","connector")],example:"architecture-beta\n group backend(cloud)[Backend]\n service api(server)[API] in backend\n service db(database)[Database] in backend\n service cache(disk)[Cache] in backend\n api:R --> L:db\n api:B -[reads]-> T:cache",editorExample:`architecture-beta
60
+ group app(cloud)[Application]
61
+ group data(database)[Data]
62
+ service web(server)[Web App] in app
63
+ service api(server)[API] in app
64
+ service db(database)[Postgres] in data
65
+ web:R --> L:api
66
+ api:R --> L:db`},{id:"xychart",upstreamId:"xychart",maturity:"stable",label:"XY chart",headers:["xychart","xychart-beta"],narrower:"asXyChart",editorDiagramType:"XY Chart",editorLabel:"XY chart",editorDescription:"Bar and line series using xychart syntax.",editorExampleId:"xychart-basic",editorGlyph:"XY",config:{section:"xyChart",keys:["width","height","useMaxWidth","useWidth","titleFontSize","titlePadding","chartOrientation","plotReservedSpacePercent","showDataLabel","showDataLabelOutsideBar","showTitle","showLegend","legendFontSize","legendPadding","xAxis","yAxis"]},semanticChannels:["value","category"],detect:Pg,sceneRoles:[le("prelude","document"),le("defs","document"),le("chrome","container","document","shape"),le("grid","shape"),le("bar","shape","data-mark"),le("series","connector"),le("point","shape","data-mark"),le("axis","text","shape"),le("legend","container","text","shape"),le("title","text"),le("label","text")],example:'xychart-beta\n title "Revenue"\n x-axis [Q1, Q2, Q3]\n y-axis "USD" 0 --> 100\n bar [45, 62, 80]',editorExample:`xychart
67
+ title "Weekly renders"
68
+ x-axis [Mon, Tue, Wed, Thu, Fri]
69
+ y-axis "Renders" 0 --> 100
70
+ bar [25, 42, 58, 74, 88]
71
+ line [18, 35, 52, 70, 95]`},{id:"pie",upstreamId:"pie",maturity:"stable",label:"Pie",headers:["pie"],narrower:"asPie",editorDiagramType:"Pie",editorLabel:"Pie chart",editorDescription:"Proportional slices with values shown in the legend.",editorExampleId:"pie-basic",editorGlyph:"P",config:{section:"pie",keys:["textPosition","donutHole","legendPosition","highlightSlice","useMaxWidth","useWidth"],noopKeys:["useMaxWidth","useWidth"]},semanticChannels:["value","category","emphasis"],detect:Fg,sceneRoles:[le("prelude","document"),le("chrome","document","shape","container"),le("pie-slice","shape","data-mark"),le("legend","text","shape","data-mark"),le("title","text"),le("label","text")],example:'pie title Plans\n "Free" : 60\n "Pro" : 30\n "Enterprise" : 10',editorExample:`pie showData
72
+ title Export requests by format
73
+ "SVG" : 42
74
+ "PNG" : 28
75
+ "ASCII" : 18
76
+ "Unicode" : 12`},{id:"quadrant",upstreamId:"quadrantChart",maturity:"stable",label:"Quadrant",headers:["quadrantChart"],narrower:"asQuadrant",editorDiagramType:"Quadrant",editorLabel:"Quadrant chart",editorDescription:"Two-axis priority map with labeled regions and points.",editorExampleId:"quadrant-basic",editorGlyph:"4Q",config:{section:"quadrantChart",keys:["chartWidth","chartHeight","titleFontSize","titlePadding","quadrantPadding","quadrantLabelFontSize","xAxisLabelFontSize","yAxisLabelFontSize","xAxisLabelPadding","yAxisLabelPadding","pointLabelFontSize","pointRadius","pointTextPadding","quadrantInternalBorderStrokeWidth","quadrantExternalBorderStrokeWidth","useMaxWidth","quadrantTextTopPadding","xAxisPosition","yAxisPosition","useWidth"],noopKeys:["quadrantTextTopPadding","xAxisPosition","yAxisPosition","useWidth"]},aliases:["quadrant"],semanticChannels:["category"],detect:$g,detectLoose:qg,sceneRoles:[le("prelude","document"),le("chrome","document","shape","container"),le("plate","shape"),le("grid","shape"),le("point","shape"),le("axis","text"),le("title","text"),le("label","text")],example:"quadrantChart\n title Prioritize\n x-axis Low Effort --> High Effort\n y-axis Low Value --> High Value\n Quick win: [0.2, 0.8]\n Money pit: [0.8, 0.2]",editorExample:`quadrantChart
77
+ title Feature priorities
78
+ x-axis Low impact --> High impact
79
+ y-axis Low effort --> High effort
80
+ quadrant-1 Plan carefully
81
+ quadrant-2 Big bets
82
+ quadrant-3 Defer
83
+ quadrant-4 Quick wins
84
+ SVG export: [0.78, 0.28]
85
+ MCP setup: [0.62, 0.72]
86
+ Palette polish: [0.35, 0.24]`},{id:"gantt",upstreamId:"gantt",maturity:"stable",label:"Gantt",headers:["gantt"],narrower:"asGantt",editorDiagramType:"Gantt",editorLabel:"Gantt chart",editorDescription:"Sections, dependencies, status tags, and a milestone.",editorExampleId:"gantt-basic",editorGlyph:"G",config:{section:"gantt",keys:["displayMode","barHeight","topAxis","tickInterval","axisFormat","barGap","topPadding","leftPadding","gridLineStartPadding","fontSize","sectionFontSize","numberSectionStyles","todayMarker","weekday","rightPadding","titleTopMargin"],noopKeys:["barGap","topPadding","leftPadding","rightPadding","titleTopMargin","gridLineStartPadding","fontSize","sectionFontSize","numberSectionStyles","todayMarker","weekday"]},semanticChannels:["status","progress","emphasis","category"],detect:zg,detectLoose:Gg,sceneRoles:[le("prelude","document"),le("defs","document","marker"),le("chrome","document","container"),le("section","text","shape"),le("grid","shape"),le("axis","text"),le("label","text"),le("task","shape"),le("milestone","shape"),le("edge","connector"),le("marker-line","shape"),le("title","text")],example:"gantt\n title Plan\n dateFormat YYYY-MM-DD\n section Build\n Implement :a1, 2026-01-05, 5d\n Review :after a1, 2d",editorExample:`gantt
87
+ title Release train
88
+ dateFormat YYYY-MM-DD
89
+ excludes weekends
90
+ section Build
91
+ Completed task :done, des1, 2024-01-08, 2024-01-10
92
+ Active task :active, des2, 2024-01-11, 3d
93
+ Future task :des3, after des2, 5d
94
+ section Ship
95
+ Crit review :crit, rev1, after des3, 2d
96
+ Release :milestone, m1, after rev1, 0d`},{id:"mindmap",upstreamId:"mindmap",maturity:"stable",label:"Mindmap",headers:["mindmap"],narrower:"asMindmap",editorDiagramType:"Mindmap",editorLabel:"Mindmap",editorDescription:"A centered, bilateral hierarchy with shapes, Markdown, Unicode, accessibility, and deep quality branches.",editorExampleId:"mindmap-basic",editorGlyph:"M",config:{section:"mindmap",keys:["padding","maxNodeWidth","layoutAlgorithm","colorBy"],noopKeys:["colorBy","layoutAlgorithm"]},semanticChannels:["importance","category"],detect:Wg,detectLoose:Ug,sceneRoles:[le("prelude","document"),le("title","text"),le("chrome","document","shape"),le("edge","connector"),le("node","container"),le("icon","container","shape","text"),le("label","text")],example:"mindmap\n root((Product))\n Research\n Interviews\n Evidence\n Delivery\n Launch",editorExample:`mindmap
97
+ root((Agent-native release))
98
+ discovery[Discovery]
99
+ ::icon(fa fa-book)
100
+ :::urgent large
101
+ evidence["\`**Evidence** across
102
+ interviews, benchmarks, and Unicode na\xEFve caf\xE9\`"]
103
+ constraints{{Constraints}}
104
+ Security
105
+ Determinism
106
+ delivery(Delivery)
107
+ beta))Beta signal((
108
+ launch)Launch cloud(
109
+ quality[Quality gates]
110
+ Parser round-trip
111
+ SVG identity
112
+ Terminal width
113
+ Ecosystem
114
+ Mermaid parity
115
+ Terminal tools`},{id:"gitgraph",upstreamId:"gitGraph",maturity:"stable",label:"GitGraph",headers:["gitGraph"],narrower:"asGitGraph",editorDiagramType:"GitGraph",editorLabel:"GitGraph",editorDescription:"Ordered branches, commit types, tags, a semantic merge, and a merge-parent backport.",editorExampleId:"gitgraph-basic",editorGlyph:"Git",config:{section:"gitGraph",keys:["showBranches","showCommitLabel","mainBranchName","mainBranchOrder","parallelCommits","rotateCommitLabel","arrowMarkerAbsolute","diagramPadding","nodeLabel","titleTopMargin"],noopKeys:["arrowMarkerAbsolute","diagramPadding","nodeLabel","titleTopMargin"]},semanticChannels:["status","category"],detect:jg,detectLoose:Vg,sceneRoles:[le("prelude","document"),le("chrome","document","shape"),le("title","text"),le("group","container"),le("rail","shape"),le("edge","connector"),le("node","container"),le("label","text")],example:'gitGraph\n commit id:"base"\n branch feature\n commit id:"work"\n checkout main\n commit id:"release"\n merge feature id:"merge"',editorExample:`---
116
+ title: Release train with backport
117
+ config:
118
+ gitGraph:
119
+ mainBranchName: main
120
+ mainBranchOrder: 0
121
+ showBranches: true
122
+ showCommitLabel: true
123
+ rotateCommitLabel: true
124
+ ---
125
+ gitGraph LR:
126
+ accTitle: Release history with feature merge and backport
127
+ accDescr: Develop and release branches diverge, main merges develop, and release cherry-picks the merge
128
+ commit id:"ROOT" tag:"v1.0.0" msg:"Foundation"
129
+ branch develop order:2
130
+ commit id:"API" type:HIGHLIGHT tag:"beta" msg:"Build API"
131
+ branch release order:3
132
+ commit id:"RC" type:REVERSE tag:"rc.1" msg:"Cut release candidate"
133
+ checkout develop
134
+ commit id:"UI" msg:"Finish interface"
135
+ checkout main
136
+ commit id:"HOTFIX" type:REVERSE msg:"Patch production"
137
+ merge develop id:"MERGE" tag:"v2.0.0" type:HIGHLIGHT
138
+ checkout release
139
+ cherry-pick id:"MERGE" parent:"UI" tag:"backport"
140
+ commit id:"PATCH" msg:"Verify release"`},{id:"radar",upstreamId:"radar",maturity:"experimental",label:"Radar",headers:["radar-beta"],narrower:"asRadar",editorDiagramType:"Radar",editorLabel:"Radar chart",editorDescription:"Multivariate profiles compared across shared axes \u2014 the silhouette is the message.",editorExampleId:"radar-basic",editorGlyph:"R",config:{section:"radar",keys:["width","height","marginTop","marginRight","marginBottom","marginLeft","axisScaleFactor","axisLabelFactor","curveTension","useMaxWidth","tickLabels","useWidth"],noopKeys:["useWidth"]},semanticChannels:["category"],detect:Yg,sceneRoles:[le("prelude","document"),le("chrome","document"),le("grid","shape"),le("pie-slice","shape"),le("point","shape"),le("axis","text"),le("legend","shape","text"),le("title","text")],example:'radar-beta\n title Skills\n axis speed["Speed"], power["Power"], range["Range"]\n curve now["Current"]{4, 3, 5}\n curve goal["Target"]{5, 5, 4}\n max 5',editorExample:`radar-beta
141
+ title Model comparison
142
+ axis speed["Speed"], accuracy["Accuracy"], cost["Cost"]
143
+ axis latency["Latency"], context["Context"], safety["Safety"]
144
+ curve a["Model A"]{4, 5, 3, 4, 4, 5}
145
+ curve b["Model B"]{5, 3, 4, 3, 5, 3}
146
+ graticule polygon
147
+ max 5`},{id:"sankey",upstreamId:"sankey",maturity:"experimental",label:"Sankey",headers:["sankey","sankey-beta"],narrower:"asSankey",editorDiagramType:"Sankey",editorLabel:"Sankey diagram",editorDescription:"Conserved flows between layered stages \u2014 ribbon width is the quantity.",editorExampleId:"sankey-basic",editorGlyph:"SK",config:{section:"sankey",keys:["width","height","linkColor","nodeAlignment","showValues","prefix","suffix","labelStyle","nodeWidth","nodePadding","nodeColors","useMaxWidth"],noopKeys:["useMaxWidth"]},semanticChannels:["value","category"],detect:Hg,detectLoose:Xg,sceneRoles:[le("prelude","document"),le("chrome","document"),le("defs","document"),le("edge","connector"),le("bar","shape","data-mark"),le("label","text"),le("title","text")],example:"sankey-beta\n Coal,Electricity grid,127.93\n Electricity grid,Industry,71.24\n Electricity grid,Losses,56.69",editorExample:`sankey-beta
148
+ Coal,Electricity,60
149
+ Gas,Electricity,80
150
+ Solar,Electricity,40
151
+ Electricity,Homes,120
152
+ Electricity,Industry,60`},{id:"c4",upstreamId:"c4",maturity:"experimental",label:"C4",headers:["C4Context","C4Container","C4Component","C4Dynamic","C4Deployment"],narrower:"asC4",editorDiagramType:"C4",editorLabel:"C4 architecture",editorDescription:"People, software systems, containers and components within nested architecture boundaries.",editorExampleId:"c4-basic",editorGlyph:"C4",config:{section:"c4",keys:[...qy,...zu],noopKeys:zu},semanticChannels:["category","status"],detect:Kg,detectLoose:Jg,sceneRoles:[le("prelude","document"),le("title","text"),le("defs","document","marker"),le("chrome","document","shape"),le("group","container","shape"),le("group-header","text","shape"),le("edge","connector"),le("edge-label","container"),le("node","container","shape"),le("label","text"),le("legend","container","shape","text")],example:'C4Context\n Person(user, "Customer")\n System(api, "API", "Serves requests")\n Rel(user, api, "Uses", "HTTPS")',editorExample:`C4Container
153
+ title Internet banking
154
+ Person(customer, "Customer", "Checks balances and makes payments")
155
+ System_Boundary(bank, "Internet banking") {
156
+ Container(web, "Web application", "TypeScript", "Customer portal")
157
+ Container(api, "API", "Node.js", "Accounts and payments")
158
+ ContainerDb(db, "Accounts", "PostgreSQL", "Balances and transactions")
159
+ }
160
+ Rel(customer, web, "Uses", "HTTPS")
161
+ Rel(web, api, "Calls", "JSON/HTTPS")
162
+ Rel(api, db, "Reads and writes", "SQL")`},...ak,{id:"zenuml",upstreamId:"zenuml",maturity:"experimental",label:"ZenUML",headers:["zenuml"],narrower:"asZenUML",editorDiagramType:"ZenUML",editorLabel:"ZenUML interactions",editorDescription:"Nested calls, replies and control scopes with checked native edits.",editorExampleId:"zenuml-checkout",editorGlyph:"ZU",config:{section:"zenuml",keys:[],noopKeys:[]},semanticChannels:["category"],sceneRoles:dk.filter(t=>t.role!=="group").map(t=>({role:t.role,primitives:t.primitives.filter(e=>!(t.role==="chrome"&&e==="shape")&&!(t.role==="icon"&&e==="text"))})),detect:ny,example:"zenuml\nAlice->Bob: Hello\nBob->Alice: Reply",editorExample:"zenuml\ntitle Checkout\nBuyer as Customer\nAPI\nStore\nBuyer->API.placeOrder() {\n Store.reserve()\n if (inStock) {\n return confirmation\n } else {\n return unavailable\n }\n}\nAPI->Buyer: accepted"}];function IO(t,e){const{sceneRoles:r,narrower:i,editorDiagramType:n,editorLabel:o,editorDescription:s,editorExampleId:a,editorGlyph:l,editorExample:c,...d}=t;const u=r.map(h=>h.role);return yk({...d,...e,contractVersion:pk,identity:Ci({id:`family:${t.id}`,kind:"family",version:"1.0.0",compatibility:{core:ml},provenance:{owner:"agentic-mermaid",source:"built-in"}}),collisionPriority:100,aliases:t.aliases??[],semanticRoles:u,scenePrimitiveEvidence:BO(t.id,r,["src/__tests__/section-a-family-descriptor-conformance.test.ts"]),capabilityEvidence:_O(t.id,e.mutate!==void 0)})}var LO=Object.freeze(ca.map(({id:t,label:e,headers:r,narrower:i,editorDiagramType:n,editorLabel:o,editorDescription:s,editorExampleId:a,editorGlyph:l,editorExample:c,example:d})=>Object.freeze({id:t,label:e,headers:r,narrower:i,editorDiagramType:n,editorLabel:o,editorDescription:s,editorExampleId:a,editorGlyph:l,editorExample:c,example:d})));var WN=true;function UN(t){return LO.find(e=>e.id===t)}var gk=new Set(ca.map(t=>t.id));function Kt(t){return gk.has(t)}function RO(t){return As(t)?.kind==="family"}function _i(t){return t.trim().toLowerCase()}function uk(t){return typeof t==="string"&&t!==""&&t===t.trim()&&!/[;\u0000-\u001f\u007f]/.test(t)}var hk=new Map(Ny.families.flatMap(t=>t.headers.map(e=>[_i(e.value),t.id])));var DO=Object.freeze(["contractVersion","identity","id","upstreamId","label","headers","aliases","maturity","collisionPriority","detect","detectLoose","config","applicableRenderOptions","semanticRoles","semanticChannels","scenePrimitiveEvidence","capabilityEvidence","example","renderSource","normalizeRequest","configDiagnostics","extractLabels","statementEnds","parse","buildSourceMap","serialize","mutate","mutateSource","verify","layout","projectPositioned","renderSvg","lowerScene","renderAscii"]);var NO=true;var mk=1e5;function Go(t,e){if(typeof t!=="object"&&typeof t!=="function"||t===null)return void 0;const r=t;return Object.fromEntries(e.map(i=>[i,Reflect.get(r,i)]))}function Ir(t,e,r){if(!Array.isArray(t))return t;const i=Reflect.get(t,"length");if(!Number.isSafeInteger(i)||i<0){throw new TypeError(`Family descriptor ${e} must have a non-negative integer length`)}if(i>mk){throw new RangeError(`Family descriptor ${e} exceeds the ${mk}-item limit`)}const n=[];for(let o=0;o<i;o++){if(!Object.prototype.hasOwnProperty.call(t,o)){throw new TypeError(`Family descriptor ${e} must not be sparse`)}n.push(r(Reflect.get(t,String(o)),o))}return Object.freeze(n)}function PO(t){if(typeof t!=="object"&&typeof t!=="function"||t===null)return t;return Object.freeze(Object.fromEntries(Object.entries(t)))}function FO(t){const e=Go(t,["id","kind","version","compatibility","provenance"]);if(!e)return t;const r=PO(e.compatibility);const i=Go(e.provenance,["owner","source","reference"]);const n=i?Object.freeze(i):e.provenance;return Ci({id:e.id,kind:e.kind,version:e.version,compatibility:r,provenance:n})}function $O(t){const e=Go(t,["section","keys","noopKeys"]);if(!e)return t;const r=Ir(e.keys,"config.keys",n=>n);const i=e.noopKeys===void 0?void 0:Ir(e.noopKeys,"config.noopKeys",n=>n);return Object.freeze({section:e.section,keys:r,...i===void 0?{}:{noopKeys:i}})}function qO(t,e){const r=Go(t,["role","primitive","applicability","realization","evidence","diagnostic"]);if(!r)return t;return Object.freeze({role:r.role,primitive:r.primitive,applicability:r.applicability,realization:r.realization,evidence:Ir(r.evidence,`scenePrimitiveEvidence[${e}].evidence`,i=>i),...r.diagnostic===void 0?{}:{diagnostic:r.diagnostic}})}function zO(t,e){const r=Go(t,["capability","state","evidence"]);if(!r)return t;return Object.freeze({capability:r.capability,state:r.state,evidence:Ir(r.evidence,`capabilityEvidence[${e}].evidence`,i=>i)})}function yk(t){void NO;const e=Go(t,DO);if(!e)throw new TypeError("Family descriptor must be an object");const r=Object.fromEntries(Object.entries(e).filter(([,i])=>i!==void 0));return Object.freeze({...r,identity:FO(e.identity),headers:Ir(e.headers,"headers",i=>i),aliases:Ir(e.aliases,"aliases",i=>i),semanticRoles:Ir(e.semanticRoles,"semanticRoles",i=>i),semanticChannels:e.semanticChannels===void 0?Object.freeze([]):Ir(e.semanticChannels,"semanticChannels",i=>i),scenePrimitiveEvidence:Ir(e.scenePrimitiveEvidence,"scenePrimitiveEvidence",qO),capabilityEvidence:Ir(e.capabilityEvidence,"capabilityEvidence",zO),...e.config===void 0?{}:{config:$O(e.config)},...e.applicableRenderOptions===void 0?{}:{applicableRenderOptions:Ir(e.applicableRenderOptions,"applicableRenderOptions",i=>i)}})}function fk(t,e){const r=_i(e);if(!Tk(t,r))return false;return t.detect(r)||Boolean(t.detectLoose?.(r))}var GO=new Set(["native","source-preserved","diagnosed","not-applicable","absent"]);function WO(t){if(Object.prototype.hasOwnProperty.call(Mu,t))return true;return/^[a-z0-9][a-z0-9._/-]*:[a-z0-9][a-z0-9._/-]*$/i.test(t)}function xk(t){return t.layout!==void 0&&t.projectPositioned!==void 0}function UO(t){return t.layout!==void 0&&t.lowerScene!==void 0}function bk(t){return t.layout!==void 0&&(t.lowerScene!==void 0||t.renderSvg!==void 0)}function jO(t){return xk(t)&&bk(t)}function VO(t,e){switch(e){case"detection":return"native";case"source-preservation":return t.parse?"native":"source-preserved";case"parse":return t.parse?"native":"source-preserved";case"serialize":return t.serialize?"native":"source-preserved";case"mutation":return Kt(t.id)&&t.mutate?"native":"diagnosed";case"verify":return jO(t)&&(Kt(t.id)||t.verify!==void 0)?"native":"diagnosed";case"layout":return xk(t)?"native":t.layout||t.projectPositioned?"diagnosed":"absent";case"scene":return UO(t)?"native":t.lowerScene?"diagnosed":"absent";case"svg":return bk(t)?"native":"absent";case"terminal":return t.renderAscii?"native":"absent"}}function Ck(t,e,r=ar){if(!t||typeof t!=="object")throw new TypeError("Family descriptor must be an object");if(!Kt(t.id)&&!RO(t.id)){throw new Error(`External family id "${t.id}" must use the "family:" namespace`)}if(!Kt(t.id)&&(t.id==="family:unknown"||t.id.startsWith("family:upstream/")||gk.has(t.id.slice("family:".length)))){throw new Error(`External family id "${t.id}" is reserved by the core family/preservation envelope`)}const i=Kt(t.id)?`family:${t.id}`:t.id;if(t.identity?.id!==i||t.identity.kind!=="family"){throw new Error(`Family descriptor identity must be "${i}" with kind "family"`)}if(t.contractVersion!==pk){throw new Error(`Family "${t.id}" uses an unsupported descriptor contract`)}Ci({id:t.identity.id,kind:t.identity.kind,version:t.identity.version,compatibility:t.identity.compatibility,provenance:t.identity.provenance});if(!Kt(t.id)){Eu(t.identity,"core");if(t.lowerScene)Eu(t.identity,"scene")}if(!t.label){throw new Error(`Family "${t.id}" must declare version, provenance, and label`)}if(!Array.isArray(t.headers)||t.headers.length===0||t.headers.some(g=>!uk(g))){throw new Error(`Family "${t.id}" must declare at least one canonical header without surrounding whitespace, controls, or semicolons`)}if(t.renderSource!==void 0&&typeof t.renderSource!=="function")throw new TypeError(`Family ${t.id} renderSource must be a function`);if(t.statementEnds!==void 0&&typeof t.statementEnds!=="function")throw new TypeError(`Family ${t.id} statementEnds must be a function`);if(typeof t.detect!=="function")throw new Error(`Family "${t.id}" must declare a detector`);if(!Number.isSafeInteger(t.collisionPriority))throw new Error(`Family "${t.id}" must declare an integer collisionPriority`);if(!Array.isArray(t.aliases)||t.aliases.some(g=>!uk(g))){throw new Error(`Family "${t.id}" must declare canonical aliases without surrounding whitespace, controls, or semicolons`)}const n=new Set([...t.headers,...t.aliases].map(_i));for(const[g,y]of r){if(g===e)continue;const C=[...y.headers,...y.aliases].map(_i).find(w=>n.has(w));if(C)throw new Error(`Family header "${C}" is already owned by "${g}"`)}const o=t.aliases.find(g=>hk.has(_i(g)));if(o){throw new Error(`Family "${t.id}" alias "${o}" is an upstream public header and must be declared in headers`)}const s=new Set(t.headers.map(g=>hk.get(_i(g))).filter(g=>g!==void 0));if(s.size>1){throw new Error(`Family "${t.id}" cannot claim upstream headers from multiple Mermaid families`)}if(t.config){if(!t.config.section.trim())throw new Error(`Family "${t.id}" config contract requires a section`);if(!Array.isArray(t.config.keys)||t.config.keys.some(g=>typeof g!=="string"||!g.trim())){throw new Error(`Family "${t.id}" config contract requires non-empty keys`)}if(new Set(t.config.keys).size!==t.config.keys.length){throw new Error(`Family "${t.id}" config contract repeats a key`)}if(t.config.noopKeys){if(new Set(t.config.noopKeys).size!==t.config.noopKeys.length||t.config.noopKeys.some(g=>!t.config.keys.includes(g))){throw new Error(`Family "${t.id}" config noopKeys must be unique members of keys`)}}}if(t.configDiagnostics!==void 0&&typeof t.configDiagnostics!=="function"){throw new TypeError(`Family "${t.id}" configDiagnostics must be a function`)}if(!Array.isArray(t.semanticRoles))throw new Error(`Family "${t.id}" must declare a semanticRoles array`);if(!Array.isArray(t.semanticChannels))throw new Error(`Family "${t.id}" must declare a semanticChannels array`);if(!Array.isArray(t.scenePrimitiveEvidence))throw new Error(`Family "${t.id}" must declare a scenePrimitiveEvidence array`);if(!Array.isArray(t.capabilityEvidence))throw new Error(`Family "${t.id}" must declare a capabilityEvidence array`);if(new Set(t.semanticChannels).size!==t.semanticChannels.length){throw new Error(`Family "${t.id}" declares duplicate semantic channels`)}const a=t.semanticChannels.find(g=>!Dy.includes(g));if(a)throw new Error(`Family "${t.id}" declares unknown semantic channel "${String(a)}"`);if(new Set(t.semanticRoles).size!==t.semanticRoles.length){throw new Error(`Family "${t.id}" declares duplicate Scene roles`)}const l=t.semanticRoles.find(g=>!WO(g));if(l)throw new Error(`Family "${t.id}" declares invalid Scene role "${l}"`);if(t.lowerScene&&t.renderSvg){throw new Error(`Family "${t.id}" must declare one graphical waist: lowerScene, or renderSvg as an extension fallback, not both`)}if(t.lowerScene&&t.semanticRoles.length===0){throw new Error(`Family "${t.id}" has a Scene lowering but declares no Scene roles`)}if(!t.lowerScene&&t.semanticRoles.length>0){throw new Error(`Family "${t.id}" declares Scene roles without a Scene lowering`)}const c=new Set;for(const g of t.scenePrimitiveEvidence){if(!t.semanticRoles.includes(g.role)){throw new Error(`Family "${t.id}" has primitive evidence for undeclared Scene role "${g.role}"`)}if(!Ls.includes(g.primitive)){throw new Error(`Family "${t.id}" has evidence for unknown Scene primitive "${String(g.primitive)}"`)}const y=`${g.role}\0${g.primitive}`;if(c.has(y)){throw new Error(`Family "${t.id}" repeats primitive evidence for "${g.role}/${g.primitive}"`)}c.add(y);if(g.applicability!=="applicable"&&g.applicability!=="not-applicable"){throw new Error(`Family "${t.id}" has invalid applicability for "${g.role}/${g.primitive}"`)}if(!Pu.includes(g.realization)){throw new Error(`Family "${t.id}" has invalid realization for "${g.role}/${g.primitive}"`)}if(!Array.isArray(g.evidence)||g.evidence.length===0||g.evidence.some(C=>typeof C!=="string"||!C.trim())){throw new Error(`Family "${t.id}" must cite evidence for "${g.role}/${g.primitive}"`)}if(new Set(g.evidence).size!==g.evidence.length){throw new Error(`Family "${t.id}" repeats evidence for "${g.role}/${g.primitive}"`)}if(g.applicability==="applicable"&&g.realization==="unsupported"){throw new Error(`Family "${t.id}" cannot mark applicable cell "${g.role}/${g.primitive}" unsupported`)}if(g.applicability==="not-applicable"&&(g.realization!=="unsupported"||!g.diagnostic?.trim())){throw new Error(`Family "${t.id}" must make negative cell "${g.role}/${g.primitive}" explicitly unsupported and diagnosed`)}}for(const g of t.semanticRoles){for(const y of Ls){if(!c.has(`${g}\0${y}`)){throw new Error(`Family "${t.id}" lacks primitive evidence for "${g}/${y}"`)}}}const d=new Map;for(const g of t.capabilityEvidence){if(!qo.includes(g.capability)){throw new Error(`Family "${t.id}" declares unknown capability "${String(g.capability)}"`)}if(d.has(g.capability)){throw new Error(`Family "${t.id}" declares duplicate evidence for capability "${g.capability}"`)}if(!GO.has(g.state)){throw new Error(`Family "${t.id}" declares invalid state "${String(g.state)}" for capability "${g.capability}"`)}if(!Array.isArray(g.evidence)||g.evidence.length===0||g.evidence.some(y=>typeof y!=="string"||y.trim()==="")){throw new Error(`Family "${t.id}" capability "${g.capability}" must cite at least one evidence path`)}if(new Set(g.evidence).size!==g.evidence.length){throw new Error(`Family "${t.id}" capability "${g.capability}" repeats an evidence path`)}d.set(g.capability,g)}const u=qo.find(g=>!d.has(g));if(u)throw new Error(`Family "${t.id}" lacks evidence for capability "${u}"`);if(t.projectPositioned&&!t.layout){throw new Error(`Family "${t.id}" cannot project a positioned artifact without a layout hook`)}if(t.renderSvg&&!t.layout){throw new Error(`Family "${t.id}" cannot render SVG without a layout hook`)}if(t.lowerScene&&!t.layout){throw new Error(`Family "${t.id}" cannot lower Scene without a layout hook`)}for(const g of qo){const y=d.get(g).state;const C=VO(t,g);if(y!==C){throw new Error(`Family "${t.id}" capability "${g}" claims "${y}" but its hooks require "${C}"`)}}if(!Kt(t.id)&&t.capabilityEvidence.some(g=>g.state==="native")){if(typeof t.example!=="string"||t.example.trim()===""){throw new Error(`External family "${t.id}" must declare a canonical example for executable native conformance`)}if(An(t.example,$h)>$h){throw new Error(`External family "${t.id}" example exceeds the ${$h}-byte conformance limit`)}}const h=[...t.headers,...t.aliases].map(_i);if(new Set(h).size!==h.length)throw new Error(`Family "${t.id}" declares duplicate headers`);const m=h.find(g=>!t.detect(g));if(m)throw new Error(`Family detector for "${t.id}" does not recognize its declared header "${m}"`);const f=t.detectLoose?h.find(g=>!t.detectLoose(g)):void 0;if(f){throw new Error(`Family loose detector for "${t.id}" does not recognize its declared header "${f}"`)}const p=new Set(h);for(const[g,y]of r){if(g===e)continue;if(y.identity.id===t.identity.id){throw new pl(t.identity,y.identity)}const C=[...y.headers,...y.aliases].map(_i);const w=C.find(b=>p.has(b));if(w)throw new Error(`Family header "${w}" is already owned by "${g}"`);const x=C.find(b=>fk(t,b));if(x){throw new Error(`Family detector for "${t.id}" overlaps header "${x}" owned by "${g}"`)}const k=h.find(b=>fk(y,b));if(k){throw new Error(`Family header "${k}" overlaps the detector owned by "${g}"`)}}}var ar=new Map;function kk(t,e){const r=ar.get(t);if(r)return r;qh();const i=ca.find(o=>o.id===t);if(!i)throw new Error(`Unknown built-in family "${t}"`);const n=IO(i,e);Ck(n);sy(n);ar.set(t,n);zo.set(t,YO(n));return n}function Sk(t){return Object.freeze({...t,capabilities:Object.freeze(t.capabilities.map(e=>Object.freeze({...e})))})}function YO(t){return Sk({version:lk,familyId:t.id,example:t.example,passed:true,capabilities:qo.map(e=>({capability:e,declaredState:t.capabilityEvidence.find(r=>r.capability===e).state,status:"passed",witnessId:`family-builtin-suite@${lk}/${t.id}/${e}`}))})}var zo=new Map;var hn=null;function qh(){if(hn){throw new Error(`Family registry mutation is forbidden while candidate "${hn.id}" is undergoing conformance`)}}function jN(t,e){qh();const r=Symbol("family-candidate");hn={id:"family:unread-candidate",token:r};try{const i=yk(t);const n=i.id;hn={id:n,token:r};if(Kt(n)){throw new Error(`Built-in family "${n}" already exists; use replaceFamilyForTest explicitly in tests`)}const o=ar.get(n);if(o)throw new pl(i.identity,o.identity);e?.(i);Ck(i);ar.set(n,i);let s=false;const a=()=>{if(hn?.token!==r)throw new Error(`Family candidate "${n}" lost its staging authority`);hn=null;s=true};return Object.freeze({descriptor:i,commit(l){if(s)throw new Error(`Family candidate "${n}" is already settled`);if(l.familyId!==n)throw new Error(`Family conformance report for "${l.familyId}" cannot commit "${n}"`);if(l.capabilities.length!==qo.length||qo.some(u=>!l.capabilities.some(h=>h.capability===u))){throw new Error(`Family conformance report for "${n}" is incomplete`)}const c=Sk(l);zo.set(n,c);a();let d=false;return()=>{if(d)return;qh();if(ar.get(n)===i){ar.delete(n);zo.delete(n)}d=true}},rollback(){if(s)return;if(ar.get(n)===i)ar.delete(n);zo.delete(n);a()}})}catch(i){if(hn?.token===r)hn=null;throw i}}function Ii(t){return ar.get(t)}function VN(t){return zo.get(t)}function YN(t,e){const r=t.capabilityEvidence.find(n=>n.capability===e)?.state??"absent";if(r!=="native")return r;const i=zo.get(t.id)?.capabilities.find(n=>n.capability===e);return i?.status==="passed"?"native":"diagnosed"}function zh(){const t=ca.map(r=>r.id).filter(r=>ar.has(r));const e=Array.from(ar.keys()).filter(r=>!Kt(r)).sort();return[...t,...e]}function wk(){return ca.map(t=>t.id)}function Tk(t,e){return[...t.headers,...t.aliases].some(r=>{const i=_i(r);if(!e.startsWith(i))return false;const n=e[i.length];return n===void 0||n===":"||/\s/.test(n)||t.id==="timeline"&&(n==="#"||n==="%"||n===";")})}function vk(t,e="strict"){const r=fy(t);const i=Array.from(ar.values()).sort((n,o)=>o.collisionPriority-n.collisionPriority||qt(n.id,o.id));for(const n of i){if(!Tk(n,r))continue;const o=e==="loose"?n.detectLoose??n.detect:n.detect;if(o(r))return n}return null}function HN(t,e="strict"){return vk(t,e)?.id??null}py(vk);gy(Ii);var Wh=new WeakMap;var Ak=new WeakMap;function Ok(t,e){Ak.set(t,e)}function eP(t){return Ak.get(t)}var Bk=new WeakMap;function Li(t,e){Bk.set(t,e)}var _k=new WeakMap;function Ik(t,e){_k.set(t,e)}function tP(t,e){return Wh.get(t)?.get(e)?.line??e}function rP(t,e){return Wh.get(t)?.get(e)?.text}function Ec(t){const e=[];let r=0;for(let i=0;i<=t.length;i++){if(i!==t.length&&t.charCodeAt(i)!==10&&t.charCodeAt(i)!==13)continue;e.push({text:t.slice(r,i),start:r});if(t.charCodeAt(i)===13&&t.charCodeAt(i+1)===10)i++;r=i+1}return e}function HO(t,e,r){const i=Ec(t);const n=Ec(e);const o=new Map;let s=Math.max(0,r.header.start.line-1);const a=n[s];const l=a&&Mn(a.text).split("\n");if(a&&l?.length===2){n.splice(s,1,{text:l[0],start:a.start},{text:l[1],start:a.start+a.text.indexOf(l[1],l[0].length)})}for(let c=0;c<i.length;c++){const d=i[c].text.trim();if(!d)continue;let u=-1;for(let h=s;h<n.length;h++){const m=n[h].text;if(m.trim()===d||m.includes("%%{")&&m.replace(new RegExp(kl.source,"g"),"").replace(Os,"").trim()===d){u=h;break}}if(u<0)continue;o.set(c+1,n[u]);s=u+1}return o}function Wo(t){return t.length-t.trimStart().length}function XO(t){const e=new Uint8Array(t.length);let r;let i=false;for(let n=0;n<t.length;n++){const o=t[n];if(r){e[n]=1;if(i)i=false;else if(o==="\\")i=true;else if(o===r)r=void 0;continue}if(o==='"'||o==="'"||o==="`"){e[n]=1;r=o}}return e}function KO(t,e){const r=new Int32Array(t.length);r.fill(-1);const i=[];for(let l=0;l<t.length;l++){const c=t[l];if(e[l])continue;if(c==="["||c==="("||c==="{"){i.push({opener:c,index:l});continue}if(c!=="]"&&c!==")"&&c!=="}")continue;const d=i.pop();const u=d?.opener==="["?"]":d?.opener==="("?")":d?"}":void 0;if(d&&c===u)r[d.index]=l}const n=new Int32Array(t.length+1);const o=new Int32Array(t.length+1);n.fill(-1);o.fill(-1);const s=[];let a;for(let l=0;l<t.length;l++){n[l]=a?.index??-1;o[l]=a?.closer??-1;const c=t[l];if(e[l])continue;if(c==="["||c==="("||c==="{"){const u=r[l];const h={opener:c,index:l,closer:u,previousMatched:a};s.push(h);if(u>=0)a=h;continue}if(c!=="]"&&c!==")"&&c!=="}")continue;const d=s.pop();if(d&&a===d)a=d.previousMatched}n[t.length]=a?.index??-1;o[t.length]=a?.closer??-1;return{openerAt:n,closerAt:o}}function JO(t,e){const r=new Int32Array(t.length+1);const i=new Int32Array(t.length+1);r.fill(-1);i.fill(-1);for(const n of e.regions){if(n.kind!=="shape"||!n.closed)continue;r.fill(n.start,n.start+1,n.end);i.fill(n.end-1,n.start+1,n.end)}return{openerAt:r,closerAt:i}}function QO(t){const e=new Map;for(const r of t.regions){if(r.kind==="string"||r.kind==="markdown")e.set(r.contentStart,r.contentEnd)}return(r,i)=>{const n=e.get(r);return n===void 0?void 0:Math.min(n,i)}}function ZO(t,e,r){if(e===0||t[e-1]!=='"'&&t[e-1]!=="'")return void 0;return Rk(t,e,t[e-1],r)}function Ek(t,e,r){const i="flowchart"in r?r.flowchart:void 0;let n=-1;let o=false;const s=t.match(/^\s*accDescr\s*:?\s*\{/i);if(s){n=t.indexOf("}",s[0].length)}else if(/^\s*namespace\s+[^{};]+\s*\{/.test(t)){n=t.indexOf("{");o=true}else if(/^\s*\}/.test(t)){n=t.indexOf("}")}const a=[n];if(i)a.push(...i.separators.filter(h=>h>n));let l=0;const c=[];let d=false;for(let h=0;"quoted"in r&&h<t.length;h++){const m=t[h];if(r.quoted[h])continue;if(m==="|"&&c.length===0){d=!d;continue}if(m==="["||m==="("||m==="{"){c.push(m);continue}if(m==="]"||m===")"||m==="}"){if(o&&m==="}"&&c.length===1&&c[0]==="{"&&h>n){a.push(h)}c.pop();continue}const f=o&&c.length===1&&c[0]==="{";if(m===";"&&(c.length===0||f)&&!d&&h>n){while(e[l]&&e[l].end<=h)l++;const p=e[l];if(!p||h<p.start||h>=p.end)a.push(h)}}a.push(t.length);const u=[];for(let h=0;h<a.length-1;h++){const m=a[h]+1;const f=a[h+1];const p=m+Wo(t.slice(m,f));const g=t.slice(0,f).trimEnd().length;u.push({through:f,bounds:[Math.min(p,g),Math.max(p,g)]})}return{...o?{header:[Wo(t),n+1]}:{},headerThrough:n,segments:u,fallback:[Wo(t),t.trimEnd().length]}}function Lk(t,e){if(t.header&&e<=t.headerThrough)return t.header;let r=0;let i=t.segments.length;while(r<i){const n=r+Math.floor((i-r)/2);if(e<=t.segments[n].through)i=n;else r=n+1}return t.segments[r]?.bounds??t.fallback}function e1(t,e,r){if(!e||!r)return void 0;const[i,n]=Lk(r.statementBounds,e.at);return bo(t,e.line.start+i,e.line.start+n)}function t1(t,e,r){const i=new Map;for(const n of Dn(t.map(o=>o.text))){if(!n.joined)continue;const o=e.get(n.line+1);const s=n.joined.findLast(c=>e.has(c.line+1));const a=s&&e.get(s.line+1);if(!o||!a||a.start<o.start)continue;const l={text:r.slice(o.start,a.start+a.text.length),start:o.start};for(const c of[n.line,...n.joined.map(d=>d.line)])i.set(c+1,l)}return i}function Mk(t,e,r){let i=t.length;for(const n of r){const o=t.indexOf(n,e);if(o>=e&&o<i)i=o}return i}function Rk(t,e,r,i){let n=false;for(let o=e;o<i;o++){const s=t[o];if(n)n=false;else if(s==="\\")n=true;else if(s===r)return o}return i}function r1(t,e,r,i){const n=Math.min(r,t.closerAt.length-1);const o=t.openerAt[n];const s=t.closerAt[n];return o>=e&&s>=r&&s<=i?s:void 0}function i1(t,e,r,i){const[n,o]=Lk(i.statementBounds,e);const s=Math.min(t.trimEnd().length,o);if(/Cardinality$/i.test(r)){if(e>0&&(t[e-1]==='"'||t[e-1]==="'")){return Rk(t,e,t[e-1],s)}return Math.min(s,e+2)}if(/:(?:member|attr)#\d+$/i.test(r))return s;if(/^gantt:task:/i.test(r)){const h=Mk(t,e,[":"]);return t.slice(0,h).trimEnd().length}if(/^xychart:.*:point#\d+$/i.test(r)){const h=t.slice(e).match(/^[+-]?(?:\d+(?:\.\d+)?|\.\d+)/)?.[0];if(h)return e+h.length}if(/^quadrant:point#\d+$/i.test(r)){const h=t.slice(e,s).search(/\s*:\s*\[/);if(h>=0){const m=t.indexOf(":::",e);return m>=e&&m<e+h?t.slice(0,m).trimEnd().length:e+h}}if(/^radar:(?:axis|curve)#\d+$/i.test(r)){const h=t.slice(e).match(/^[\w](?:[\w-]*[\w])?/)?.[0];if(h)return e+h.length}if(/^sankey:link#\d+$/i.test(r)){return s}const a=i.quoteEnd(e,s);if(a!==void 0)return a;if(e>0&&t[e-1]==="|"){const h=t.indexOf("|",e);if(h>=0&&h<=s)return h}if(/^edge#\d+:/i.test(r)){const h=i.textArrowLabelRanges.find(f=>f.start===e);if(h)return h.end;const m=t.slice(e,s).search(/-{2,}[>ox]|-{3,}|-?\.+-[>ox]?|={2,}[>ox]|={3,}/);if(m>=0)return t.slice(0,e+m).trimEnd().length}const l=r1(i.enclosingDelimiters,n,e,s);if(l!==void 0)return l;const c=["]","}",")","|",'"',"'","["];let d=Mk(t,e,c);const u=t.slice(e).search(/\s+(?=(?:<?[-.=~]+|[-.=~]+[>ox]))/);if(u>=0)d=Math.min(d,e+u);if(/:name$/i.test(r)){const h=t.indexOf("[",e);if(h>=0)d=Math.min(d,h)}return Math.max(e,Math.min(s,t.slice(0,d).trimEnd().length))}function n1(t,e,r,i){if(!e||!i)return void 0;const n=i1(e.line.text,e.at,r,i);return bo(t,e.line.start+e.at,e.line.start+n)}function Gh(t,e,r,i){const n=new Map;for(const[o,s]of t){const a=r(s);const l=e1(e,a,a?i(a.line):void 0);if(l)n.set(o,l)}return n}function Dk(t,e,r,i,n="generic"){const o=Bt(r);const s=HO(e,r,i);const a=Ec(e);const l=n==="flowchart"?t1(a,s,r):new Map;const c=C=>{const w=s.get(C.line);const x=a[C.line-1];if(!w||!x)return void 0;const k=Math.max(0,C.col-1-Wo(x.text));const b=Math.min(w.text.length,Wo(w.text)+k);const A=l.get(C.line);return A?{line:A,at:w.start-A.start+b}:{line:w,at:b}};const d=new Map;const u=C=>{const w=d.get(C);if(w)return w;const x=n==="flowchart"?gr(C.text):void 0;const k=Dl(C.text,x);const b=x?void 0:XO(C.text);const A=x?{textArrowLabelRanges:k,statementBounds:Ek(C.text,k,{flowchart:x}),enclosingDelimiters:JO(C.text,x),quoteEnd:QO(x)}:{textArrowLabelRanges:k,statementBounds:Ek(C.text,k,{quoted:b}),enclosingDelimiters:KO(C.text,b),quoteEnd:(L,B)=>ZO(C.text,L,B)};d.set(C,A);return A};const h=new Map;for(const[C,w]of t.labels){const x=c(w);const k=n1(o,x,C,x?u(x.line):void 0);if(k)h.set(C,k)}const m=Bk.get(t);const f=C=>{const w=c(C);return w&&w.line.start+w.at};const p=(C,w,x)=>{for(const[k,b]of x??[]){const A=w.get(k);const L=A&&f(A);const B=f(b);if(L!==void 0&&B!==void 0&&B>=L)C.set(k,bo(o,L,B))}return C};const g={preserved:i,nodes:p(Gh(t.nodes,o,c,u),t.nodes,m?.nodes),edges:p(Gh(t.edges,o,c,u),t.edges,m?.edges),groups:p(Gh(t.groups,o,c,u),t.groups,m?.groups),labels:p(h,t.labels,m?.labels)};const y=_k.get(t);if(y){const C=new Map([...s].map(([x,k])=>[k.start,x]));const w=Ec(r);for(const x of["nodes","edges","groups","labels"]){const k=y[x];if(!k)continue;g[x]=k;for(const[b,A]of k){const L=w[A.start.line-1];const B=L&&C.get(L.start);const O=B&&a[B-1];const M=t[x].get(b);if(O&&M)t[x].set(b,{line:B,col:M.col+Wo(O.text)});else t[x].delete(b)}}if(y.metadata)g.metadata=y.metadata}t.spans=g;Wh.set(t,new Map([...s].map(([C,w])=>[C,{line:Xt(o,w.start).line,text:w.text}])));return t}var da={parse:t=>{try{const e=Co(Br(t.source));if(e.unsupportedSource!==void 0)return re({kind:"opaque",family:"zenuml",source:t.opaqueSource});if(e.title===void 0&&typeof t.source.frontmatter.title==="string")e.title=t.source.frontmatter.title;return re(e)}catch{return re({kind:"opaque",family:"zenuml",source:t.opaqueSource})}},serialize:(t,e)=>{if(t.kind!=="zenuml")throw Error("Expected native ZenUML");return nx(t,e===void 0||e.frontmatter?.title!==t.title)},extractLabels:t=>{try{const e=Fs(Co(t));return[...e.actors.filter(r=>!r.external).map(r=>({text:r.label,target:r.id})),...e.messages.flatMap(r=>r.id===void 0?[]:[{text:r.label,target:r.id}])]}catch{return[]}},buildSourceMap:(t,e)=>{const r={nodes:new Map,edges:new Map,groups:new Map,labels:new Map};if(t.kind!=="zenuml")return r;const i={nodes:new Map,edges:new Map,labels:new Map};const n=Bt(e);Co(e,o=>{const s=Xt(n,o.start),a=Xt(n,o.end);if(o.kind==="nodes"&&r.nodes.has(o.id))return;r[o.kind].set(o.id,{line:s.line,col:s.col});if(o.kind!=="groups")i[o.kind].set(o.id,{line:a.line,col:a.col})});Li(r,i);return r},verify:t=>t.kind==="zenuml"&&!Fs(t).actors.some(e=>!e.external)?[{code:"EMPTY_DIAGRAM"}]:[]};function Mc(t,e,r=false){const i=e.frontmatter?.title;if(t===i||t===void 0&&typeof i!=="string")return e;const n={...e.frontmatter};if(t===void 0)delete n.title;else n.title=t;if(e.wrapperSource===void 0)return{...e,frontmatter:n};const o=e.wrapperSource;const s=Cl(o);if(!s)return{...e,frontmatter:n,wrapperSource:t===void 0?o:`---
163
+ title: ${JSON.stringify(t)}
164
+ ---
165
+ ${o}`};const a=Ty(s.yaml).find(h=>h.name==="title");let l=s.yaml;if(a){if(t===void 0){let h=a.keyStart,m=a.valueEnd;if(l.trimStart().startsWith("{")){const f=l.slice(m).match(/^\s*,/);if(f)m+=f[0].length;else{const p=l.slice(0,h).match(/,\s*$/);if(p)h-=p[0].length}}l=l.slice(0,h)+l.slice(m)}else l=l.slice(0,a.valueStart)+JSON.stringify(t)+(/[\r\n]$/.test(l.slice(a.valueStart,a.valueEnd))?"\n":"")+l.slice(a.valueEnd)}else if(t!==void 0)l=`title: ${JSON.stringify(t)}
166
+ ${l}`;const c=h=>{const m=wy(h);if(!m.ok)throw Error(m.message);if(m.value==null)return"{}";if(typeof m.value!=="object"||Array.isArray(m.value))throw Error("Expected metadata mapping");const f={...m.value};delete f.title;return JSON.stringify(f)};const d=c(s.yaml);try{if(d!==c(l))throw Error("Title edit would change unrelated YAML metadata through an alias")}catch(h){if(r&&typeof t==="string"&&!/[\r\n]/.test(t))return e;throw h}const u=s.source.indexOf("\n")+1;return{...e,frontmatter:n,wrapperSource:o.slice(0,u)+l+o.slice(u+s.yaml.length)}}function Uh(t,e){if(t.type&&!["json","jsobj","figma","salt","uri","md","html","text"].includes(t.type))throw Error("Invalid data type");if(e?/^}\s*$/m.test(t.text):/[\r\n]/.test(t.text))throw Error("Data cannot be represented without changing its meaning");return`${t.type?`\`${t.type}\``:""}{${e?"\n":""}${t.text}${e?"\n":""}}`}function jh(t,e=true){fx(t,true);const r=["eventmodeling"];fo(r,t);if(t.title!==void 0){if(e)r.unshift(`---
167
+ title: ${JSON.stringify(t.title)}
168
+ ---`)}for(const i of t.entities)r.push(`entity ${i}`);for(const i of t.frames)r.push(`${i.reset?"rf":"tf"} ${i.id} ${i.type} ${i.entity}${i.sources.map(n=>` ->> ${n}`).join("")}${i.dataReference?` [[${i.dataReference}]]`:""}${i.data?` ${Uh(i.data,false)}`:""}`);for(const[i,n]of Object.entries(t.data))r.push(`data ${i} ${Uh(n,true)}`);for(const i of t.notes)r.push(`note ${i.frame} ${Uh(i.data,true)}`);for(const i of t.specifications)r.push(`gwt ${i.frame}
169
+ ${["given","when","then"].filter(n=>i[n].length).map(n=>`${n}
170
+ ${i[n].map(o=>` ${o.type} ${o.entity}`).join("\n")}`).join("\n")}`);return r.join("\n")+"\n"}function Pk(t,e){try{const r=structuredClone(t);r.data=Object.assign(Object.create(null),r.data);const i=a=>{const l=r.frames.findIndex(c=>c.id===a);if(l<0)throw Error(`Unknown frame: ${a}`);return l};const n=(a,l)=>{const c=a??l;if(!Number.isSafeInteger(c)||c<0||c>l)throw Error("Invalid frame position");return c};switch(e.kind){case"insert_frame":r.frames.splice(n(e.index,r.frames.length),0,structuredClone(e.frame));break;case"remove_frame":r.frames.splice(i(e.id),1);break;case"move_frame":{const[a]=r.frames.splice(i(e.id),1);r.frames.splice(n(e.index,r.frames.length),0,a);break}case"set_frame":{if(e.frame.id!==e.id)throw Error("Frame replacement must retain identity");r.frames[i(e.id)]=structuredClone(e.frame);break}case"set_entities":r.entities=structuredClone(e.entities);break;case"set_notes":r.notes=structuredClone(e.notes);break;case"set_specifications":r.specifications=structuredClone(e.specifications);break;case"set_data":r.data[e.id]=structuredClone(e.data);break;case"set_title":r.title=e.title;break;case"set_accessibility_title":r.accessibilityTitle=e.title;break;case"set_accessibility_description":r.accessibilityDescription=e.description;break;default:throw Error(Ve("eventmodeling",e))}const o=_l(r);const s=vi(jh(o));if(Nk(o)!==Nk(s))throw Error("Edit cannot be written without changing owned Event Modeling content");return re(s)}catch(r){return T({code:"INVALID_OP",message:r instanceof Error?r.message:String(r)})}}function Nk(t){return JSON.stringify([t.frames.map(e=>[e.id,e.reset,e.type,e.entity,e.sources,e.dataReference,e.data?.type,e.data?.text]),t.entities,Object.entries(t.data).sort(([e],[r])=>e<r?-1:e>r?1:0).map(([e,r])=>[e,r.type,r.text]),t.notes.map(e=>[e.frame,e.data.type,e.data.text]),t.specifications.map(e=>[e.frame,...["given","when","then"].map(r=>e[r].map(i=>[i.type,i.entity]))]),t.title,t.accessibilityTitle,t.accessibilityDescription])}function Fk(t,e){return Mc(t.title,e)}import{decodeXML as o1}from"entities";function s1(t,e="markdown-lite"){if(typeof t!=="string")return ag(t).split("\n").reduce((n,o)=>Math.max(n,o.length),0);const r=o1(t);const i=e==="literal"?Ge(r,"literal"):Ge(e==="plain"?hg(r):Ot(r));return i.split("\n").reduce((n,o)=>Math.max(n,o.length),0)}function $k(t,e,r,i){const n=s1(e,i);return n>r?{code:"LABEL_OVERFLOW",target:t,charCount:n,limit:r}:null}function lr(t,e){const r=new Set(t);let i=0;return()=>{while(r.has(`${e}-${i}`))i++;const n=`${e}-${i}`;r.add(n);i++;return n}}function Ke(t,e,r=e.labelCharCap??Bl,i){return(n,o)=>{const s=$k(n,o,r,i);if(s)t.push(s)}}function gt(t,e,r,i){if(r===null){delete t[e];return re(void 0)}const n=i(r);if(!n.ok)return n;t[e]=n.value;return re(void 0)}function Ri(t,e,r){if(t===void 0)return re(e);if(!Number.isInteger(t)||t<0||t>e){return T({code:"INVALID_OP",message:`${r} insert index ${t} out of range (0..${e})`})}return re(t)}var ua={parse:t=>{try{const e=vi(t.source.familyBody);if(e.title===void 0&&typeof t.source.frontmatter.title==="string")e.title=t.source.frontmatter.title;if(Fl(e).length)return re({kind:"opaque",family:"eventmodeling",source:t.opaqueSource});return re(e)}catch{return re({kind:"opaque",family:"eventmodeling",source:t.opaqueSource})}},serialize:t=>{if(t.kind!=="eventmodeling")throw Error("Expected Event Modeling body");return jh(t,false)},renderSource:t=>t.kind==="eventmodeling"&&Fl(t).length?"canonical":"serialized",extractLabels:t=>{try{return vi(t).frames.map(e=>({text:e.entity,target:e.id}))}catch{return[]}},buildSourceMap:(t,e)=>{const r={nodes:new Map,edges:new Map,groups:new Map,labels:new Map};if(t.kind!=="eventmodeling")return r;const i={nodes:new Map,edges:new Map,labels:new Map};const n=Bt(e);vi(e,o=>{const s=Xt(n,o.start);const a=Xt(n,o.end);r[o.kind].set(o.id,{line:s.line,col:s.col});i[o.kind].set(o.id,{line:a.line,col:a.col})});Li(r,i);return r},verify:(t,e)=>{if(t.kind!=="eventmodeling")return[];const r=new Map(t.frames.map(o=>[o.id,o]));const i=[...!t.frames.length?[{code:"EMPTY_DIAGRAM"}]:[],...Fl(t).map(o=>({code:"UNSUPPORTED_SYNTAX",syntax:"eventmodeling_keyword_identifier",message:`Identifier ${o} is read literally; pinned Mermaid reserves that keyword. Rename it before exporting or editing.`})),...t.accessibilityTitle!==void 0||t.accessibilityDescription!==void 0?[{code:"UNSUPPORTED_SYNTAX",syntax:"eventmodeling_accessibility",message:"Event Modeling accessibility is retained in native comments on export; pinned Mermaid does not expose these fields."}]:[],...t.frames.flatMap(o=>hx(o.type,o.sources.map(s=>r.get(s)?.type)).map(s=>({code:"EVENT_SOURCE_TYPE",node:o.id,source:o.sources[s.sourceIndex],message:s.message})))];const n=Ke(i,e);if(t.title!==void 0)n("title",bt(t.title,"formatted"));for(const o of px(t))n(o.id,bt(o.label,"literal"));for(const o of t.frames)n(o.id,bt(So(t,o),"literal"));return i}};function PP(t){const e=[];try{vi(t,r=>{if(r.kind==="labels"&&r.id==="unsupported-gwt")e.push({code:"UNSUPPORTED_SYNTAX",syntax:"eventmodeling_gwt_order",message:"Pinned Mermaid requires one given clause, an optional when clause, then one then clause, in that order. Native reading retains the authored clause contents."});if(r.kind==="labels"&&r.id==="title")e.push({code:"UNSUPPORTED_SYNTAX",syntax:"eventmodeling_title_statement",message:"In-body Event Modeling titles are a native read extension. Export uses portable YAML metadata; the pinned renderer does not paint that metadata title."})})}catch{}return e}var Rt=(t=true)=>({type:"string",required:t});var Vh=(t=true)=>({type:"number",required:t});var qk=()=>({type:"object-or-null",required:true});var zk=()=>({type:"string-or-null",required:true});var a1={set_columns:{fields:{columns:Vh(),parentId:Rt(false)}},add_block:{fields:{block:qk(),parentId:Rt(false),index:Vh(false)}},update_block:{fields:{id:Rt(),changes:qk()}},rename_block:{fields:{from:Rt(),to:Rt()}},remove_block:{fields:{id:Rt(),cascade:{type:"boolean",required:false}}},move_block:{fields:{id:Rt(),parentId:Rt(false),index:Vh(false)}},add_edge:{fields:{from:Rt(),to:Rt(),label:Rt(false),style:{type:"enum",values:["solid","dotted","thick"],required:false},arrowStart:Rt(false),arrowEnd:Rt(false)}},remove_edge:{fields:{id:Rt()}},define_class:{fields:{name:Rt(),style:Rt()}},set_node_class:{fields:{id:Rt(),className:zk()}},set_node_style:{fields:{id:Rt(),style:zk()}}};function Gk(t,e={}){const r=mo(t);e=ki({...r.accessibility,...e});try{const i=ln(["block",...r.familyLines]);Oc(i);i.accessibilityTitle=e.title;i.accessibilityDescription=e.descr;return i}catch{return null}}function Lr(t){const e=[];const r=(t.root.children??[]).map(i=>({node:i,parent:t.root,parentId:void 0})).reverse();while(r.length){const i=r.pop();e.push(i);for(let n=(i.node.children?.length??0)-1;n>=0;n--)r.push({node:i.node.children[n],parent:i.node,parentId:i.node.id})}return e}function l1(t){return Lr(t).some(({node:e})=>e.label?.includes("%%{"))||t.edges.some(e=>e.label?.includes("%%{"))}var Wk={na:["[","]"],square:["[","]"],round:["(",")"],circle:["((","))"],rect_left_inv_arrow:[">","]"],diamond:["{","}"],hexagon:["{{","}}"],stadium:["([","])"],subroutine:["[[","]]"],cylinder:["[(",")]"],doublecircle:["(((",")))"],lean_right:["[/","/]"],lean_left:["[\\","\\]"],trapezoid:["[/","\\]"],inv_trapezoid:["[\\","/]"]};function mn(t){if(!t||/[\s()[{}<>:=\-]/.test(t)||t==="end"||t==="block"||/^space\b/.test(t)||t==="columns")throw new Error(`Invalid block id ${t}`);return t}function ha(t){if(typeof t!=="string"||t.includes("\0"))throw new Error("Block labels must be text without NUL");return`"${wx(t)}"`}function c1(t){const e=mn(t.id),r=ha(t.label??t.id);if(t.type==="block_arrow")return`${e}<[${r}]>(${(t.directions??["right"]).join(",")})`;const i=Wk[t.type??"na"];if(!i)throw new Error(`Unknown block shape ${t.type}`);return`${e}${i[0]}${r}${i[1]}`}function Oc(t){const e=["block"];fo(e,t);const r=[{node:t.root,depth:0}];while(r.length){const{node:i,depth:n,close:o}=r.pop(),s=" ".repeat(n);if(o){e.push(`${s}end`);continue}if(i===t.root||i.type==="composite"){if(i!==t.root)e.push(`${s}block:${mn(i.id)}${i.label?`[${ha(i.label)}]`:""}${i.widthInColumns&&i.widthInColumns!==1?`:${i.widthInColumns}`:""}`);const a=i===t.root?n+1:n+1;if(i.columns!==void 0)e.push(`${" ".repeat(a)}columns ${i.columns<0?"auto":i.columns}`);if(i!==t.root)r.push({node:i,depth:n,close:true});for(let l=(i.children?.length??0)-1;l>=0;l--)r.push({node:i.children[l],depth:a})}else if(i.type==="space")e.push(`${s}space${i.width&&i.width!==1?`:${i.width}`:""}`);else e.push(`${s}${c1(i)}${i.widthInColumns&&i.widthInColumns!==1?`:${i.widthInColumns}`:""}`)}for(const i of t.edges){const n=i.arrowTypeStart==="arrow_point"?"<":i.arrowTypeStart==="arrow_circle"?"o":i.arrowTypeStart==="arrow_cross"?"x":"";const o=i.arrowTypeEnd==="arrow_point"?">":i.arrowTypeEnd==="arrow_circle"?"o":i.arrowTypeEnd==="arrow_cross"?"x":"";const s=i.thickness==="thick"?"===":i.pattern==="dotted"?"-.-":"---";const a=`${n}${s}${o}`;e.push(` ${mn(i.start)} ${i.label?`${n}${s.slice(0,2)} ${ha(i.label)} ${s}${o}`:a} ${mn(i.end)}`)}for(const i of t.classDefs)if(i.styles.length)e.push(` classDef ${i.id} ${i.styles.join(",")}`);for(const{node:i}of Lr(t)){if(i.type==="space")continue;for(const n of i.classes??[])e.push(` class ${mn(i.id)} ${n}`);if(i.styles?.length)e.push(` style ${mn(i.id)} ${i.styles.join(",")}`)}return e.join("\n")+"\n"}function Ac(t,e=0){if(!t||typeof t!=="object"||e>64)throw new Error("Block input must be a bounded object");mn(t.id);if(t.label!==void 0)ha(t.label);if(t.type!==void 0&&t.type!=="composite"&&t.type!=="space"&&t.type!=="block_arrow"&&!(t.type in Wk))throw new Error("Invalid block shape");if(t.widthInColumns!==void 0&&(!Number.isInteger(t.widthInColumns)||t.widthInColumns<1||t.widthInColumns>1e3))throw new Error("Block span must be 1..1000");if(t.columns!==void 0&&(!Number.isInteger(t.columns)||t.columns===0||t.columns<-1||t.columns>1e3))throw new Error("Columns must be -1 (auto) or 1..1000");if(t.directions?.some(i=>!["right","left","up","down","x","y"].includes(i)))throw new Error("Invalid block arrow direction");if(t.children&&(!Array.isArray(t.children)||t.children.length>1e4))throw new Error("Block children exceed work limit");const r=(t.children??[]).map(i=>Ac(i,e+1));if(t.type==="composite"&&!r.length)throw new Error("A composite needs at least one child in pinned Mermaid; supply children with add_block");if(t.type!=="composite"&&r.length)throw new Error("Only composite blocks can contain children");if(t.width!==void 0&&(!Number.isInteger(t.width)||t.width<1||t.width>1e4))throw new Error("Space width must be 1..10000");return{type:"square",label:t.id,widthInColumns:1,...t,children:r}}function Uk(t,e){const r=structuredClone(t),i=Lr(r),n=new Map(i.map(l=>[l.node.id,l]));const o=l=>{const c=n.get(l);if(!c)throw new Error(`Block ${l} not found`);return c};const s=l=>{if(l===void 0)return r.root;const c=o(l).node;if(c.type!=="composite")throw new Error("Parent must be a composite block");return c};const a=(l,c,d)=>{const u=c.children??=[];const h=d??u.length;if(!Number.isInteger(h)||h<0||h>u.length)throw new Error("Invalid block index");u.splice(h,0,l)};try{switch(e.kind){case"set_columns":Ac({id:"validate",columns:e.columns});s(e.parentId).columns=e.columns;break;case"add_block":{const d=Ac(e.block);if(n.has(d.id))throw new Error("Block id already exists");a(d,s(e.parentId),e.index);break}case"update_block":{const d=o(e.id).node;const u=Ac({...d,...e.changes});Object.assign(d,u);break}case"rename_block":{mn(e.to);const d=o(e.from).node;if(e.to!==e.from&&n.has(e.to))throw new Error("Block id already exists");d.id=e.to;for(const u of r.edges){if(u.start===e.from)u.start=e.to;if(u.end===e.from)u.end=e.to}break}case"remove_block":{const d=o(e.id),u=new Set([e.id]);for(const h of i)if(h.parentId&&u.has(h.parentId))u.add(h.node.id);if(!e.cascade&&(u.size>1||r.edges.some(h=>u.has(h.start)||u.has(h.end))))throw new Error("Block has children or edges; pass cascade: true");d.parent.children=d.parent.children.filter(h=>h!==d.node);r.edges=r.edges.filter(h=>!u.has(h.start)&&!u.has(h.end));break}case"move_block":{const d=o(e.id),u=s(e.parentId);let h=e.parentId;while(h!==void 0){if(h===e.id)throw new Error("Cannot move a block into its descendant");h=o(h).parentId}d.parent.children=d.parent.children.filter(m=>m!==d.node);a(d.node,u,e.index);break}case"add_edge":{o(e.from);o(e.to);if(e.label!==void 0)ha(e.label);let d=1;while(r.edges.some(u=>u.id===`edge-${d}`))d++;r.edges.push({id:`edge-${d}`,type:"edge",start:e.from,end:e.to,label:e.label??"",thickness:e.style==="thick"?"thick":"normal",pattern:e.style==="dotted"?"dotted":"solid",arrowTypeStart:e.arrowStart??"arrow_open",arrowTypeEnd:e.arrowEnd??"arrow_point"});break}case"remove_edge":if(!r.edges.some(d=>d.id===e.id))throw new Error("Edge not found");r.edges=r.edges.filter(d=>d.id!==e.id);break;case"define_class":{if(!/^\w+$/.test(e.name))throw new Error("Invalid class name");const d=zt(e.style);if(!d.ok)throw new Error(`Invalid style: ${d.reason}`);const u=on(d.value).split(",");const h=r.classDefs.find(m=>m.id===e.name);if(h)h.styles=u;else r.classDefs.push({id:e.name,styles:u,textStyles:[]});break}case"set_node_class":if(e.className!==null&&!/^\w+$/.test(e.className))throw new Error("Invalid class name");o(e.id).node.classes=e.className===null?[]:[e.className];break;case"set_node_style":{const d=o(e.id).node;if(e.style===null)d.styles=[];else{const u=zt(e.style);if(!u.ok)throw new Error(`Invalid style: ${u.reason}`);d.styles=on(u.value).split(",")}break}default:throw new Error(Ve("block",e))}const l=new Set;for(const{node:d}of Lr(r)){if(l.has(d.id))throw new Error(`Duplicate block id ${d.id}`);l.add(d.id)}const c=ln(Oc(r));c.edges.forEach((d,u)=>{d.id=r.edges[u].id});c.accessibilityTitle=r.accessibilityTitle;c.accessibilityDescription=r.accessibilityDescription;return re(c)}catch(l){return T({code:"INVALID_OP",message:l instanceof Error?l.message:String(l)})}}function jk(t,e){const r=[],i=Ke(r,e);const n=Lr(t),o=new Set(n.map(s=>s.node.id));if(!n.length)r.push({code:"EMPTY_DIAGRAM"});for(const{node:s}of n)if(s.type!=="space"&&s.label)i(s.id,s.label);for(const s of t.edges)if(!o.has(s.start)||!o.has(s.end))r.push({code:"UNSUPPORTED_SYNTAX",syntax:"undeclared endpoint",message:`Block edge ${s.id} references an undeclared endpoint`});return r}function KP(t){if(!/acc(?:Title|Descr)|%%\{/i.test(t))return[];const e=st(t);const r=[];if(e.accessibility.title!==void 0||e.accessibility.descr!==void 0)r.push({code:"UNSUPPORTED_SYNTAX",syntax:"block_accessibility",message:"Block accessibility metadata is carried in native comments on export. External Mermaid ignores this metadata; diagram topology is preserved."});try{if(t.includes("%%{")&&l1(ln(e.familyLines)))r.push({code:"UNSUPPORTED_SYNTAX",syntax:"block_directive_text",message:"Block labels containing a directive opener are read literally. The writer protects their quoted payloads with entity codes for pinned Mermaid."})}catch{}return r}var Vn={type:"string",required:true};var Vk={type:"string-or-null",required:true};var d1={set_effect:{fields:{label:Vn}},add_cause:{fields:{label:Vn,parentId:{type:"string",required:false}}},remove_cause:{fields:{id:Vn}},set_label:{fields:{id:Vn,label:Vn}},move_cause:{fields:{id:Vn,parentId:Vn,index:{type:"number",required:false}}},set_accessibility_title:{fields:{title:Vk}},set_accessibility_description:{fields:{description:Vk}}};var u1=/^ishikawa\b/i;function Yh(t){try{return $s(["ishikawa",...t])}catch{return null}}function h1(t){if(typeof t!=="string"||!t||t!==t.trim()||/[\r\n]/.test(t))throw new Error("Ishikawa labels must be nonempty single-line text without surrounding whitespace")}function cF(t){try{$s(t);const e=t.split(/\r?\n/),r=e.findIndex(Ex);const i=e.flatMap((n,o)=>o>r&&u1.test(n.trim())?[{code:"UNSUPPORTED_SYNTAX",syntax:"ishikawa_label",line:o+1,message:`Ishikawa label "${n.trim()}" is read literally. The writer shields its keyword prefix for pinned Mermaid.`}]:[]);if(e[r]?.includes("%%{"))i.push({code:"UNSUPPORTED_SYNTAX",syntax:"ishikawa_header_comment",line:r+1,message:"An unclosed directive-looking comment after the Ishikawa header is read as a comment. Pinned Mermaid rejects this spelling; canonical export writes the header on its own."});for(let n=r+1;n<e.length;n++){const o=ct(e,n);if(!o)continue;i.push({code:"UNSUPPORTED_SYNTAX",syntax:"ishikawa_accessibility",line:n+1,message:"Ishikawa accessibility metadata is carried in native comments on export. External Mermaid ignores this metadata; diagram topology is preserved."});n=o.endIndex}return i}catch{return[]}}function Hh(t){Gl(t.nodes);if(t.nodes.length&&(t.nodes[0].parentId!==void 0||t.nodes.slice(1).some(o=>o.parentId===void 0)))throw new Error("Ishikawa must have one effect first, with every cause below it");const e=["ishikawa"];fo(e,t);const r=zl(t.nodes);const i=[...r.get(void 0)??[]].reverse().map(o=>({node:o,depth:0}));let n=0;while(i.length){const{node:o,depth:s}=i.pop();h1(o.label);n++;e.push(`${" ".repeat(s)}${rn(o.label,"%",/^(?:ishikawa\b|accTitle\b|accDescr\b)/i)}`);for(const a of[...r.get(o.id)??[]].reverse())i.push({node:a,depth:s+1})}if(n!==t.nodes.length)throw new Error("Ishikawa causes must be connected below the effect");return e.join("\n")+"\n"}function Yk(t,e){try{const r=structuredClone(t);const i=n=>{const o=r.nodes.find(s=>s.id===n);if(!o)throw new Error(`Ishikawa node ${n} was not found`);return o};switch(e.kind){case"set_effect":if(r.nodes.length)r.nodes[0].label=e.label;else r.nodes.push({id:"effect",label:e.label});break;case"set_accessibility_title":r.accessibilityTitle=e.title==null?void 0:Ps(e.title);break;case"set_accessibility_description":r.accessibilityDescription=e.description==null?void 0:Ps(e.description);break;case"add_cause":{const n=e.parentId??r.nodes[0]?.id;if(!n)throw new Error("Set the effect before adding a cause");i(n);let o=1;while(r.nodes.some(s=>s.id===`cause-${o}`))o++;r.nodes.push({id:`cause-${o}`,label:e.label,parentId:n});break}case"remove_cause":{const n=i(e.id);if(!n.parentId)throw new Error("The effect cannot be removed as a cause");const o=vo(r.nodes,e.id);r.nodes=r.nodes.filter(s=>!o.has(s.id));break}case"set_label":i(e.id).label=e.label;break;case"move_cause":{const n=i(e.id);i(e.parentId);if(!n.parentId)throw new Error("The effect cannot move");if(vo(r.nodes,e.id).has(e.parentId))throw new Error("A cause cannot move into its own subtree");n.parentId=e.parentId;const o=r.nodes.filter(l=>l.parentId===e.parentId&&l.id!==e.id);const s=e.index??o.length;if(!Number.isSafeInteger(s)||s<0||s>o.length)throw new Error("Invalid destination index");r.nodes=r.nodes.filter(l=>l.id!==e.id);const a=o[s];r.nodes.splice(a?r.nodes.findIndex(l=>l.id===a.id):r.nodes.length,0,n);break}default:throw new Error(Ve("ishikawa",e))}Hh(r);return re(r)}catch(r){return T({code:"INVALID_OP",message:r instanceof Error?r.message:String(r)})}}function Hk(t,e){const r=[];if(!t.nodes.length)r.push({code:"EMPTY_DIAGRAM"});const i=Ke(r,e);for(const n of t.nodes)i(n.id,n.label);return r}import m1 from"yaml";function Xh(t,e){try{const r=e?Br(e).replace(/^[^\r\n]*/,"kanban"):t;return Ei(r,e?.accessibility,e)}catch(r){if(r instanceof Ln&&r.resource==="sourceCharacters")throw r;return null}}function Kh(t){const e=["kanban"];Lt(e,t);const r=(i,n)=>{const o=i.implicitId||/^kanban\b/i.test(i.sourceId);const s=Or(o?i.sourceId:i.label,'"%&').replace(/\r\n/g,"\r\r\n");const a=o?"":Or(i.sourceId,"()[]{}@%&");e.push(`${n}${a}["${s}"]`);const l={...i.metadata};if(o&&i.sourceId!==i.label&&!l.label)l.label=Or(i.label);if(i.icon!==void 0)l.icon=i.icon;if(Object.keys(l).length){const c=Object.entries(l);const d=(u,h=false)=>{const m=go(u).replaceAll("&","\\x26");return h?m:m.replaceAll("#","\\x23")};if(c.every(([,u])=>u===null||["string","number","boolean"].includes(typeof u))){e[e.length-1]+=`@{ ${c.map(([u,h])=>`${d(u)}: ${typeof h==="string"?d(h,u==="label"):String(h)}`).join(", ")} }`}else{e[e.length-1]+="@{";let u;const h=new m1.Document(l,{aliasDuplicateObjects:false,customTags:f=>f.map(p=>typeof p!=="string"&&p.collection===void 0&&p.tag==="tag:yaml.org,2002:str"?{...p,stringify:g=>d(String(g.value),g===u)}:p)});u=h.get("label",true);const m=h.toString();for(const f of m.trimEnd().split("\n"))e.push(`${n} ${f}`);e.push(`${n}}`)}}if(i.className!==void 0)e.push(`${n}:::${i.className}`)};for(const i of t.columns){r(i," ");for(const n of i.tasks)r(n," ")}return e.join("\n")+"\n"}function Xk(t,e){const r=h=>({...h,metadata:structuredClone(h.metadata)});const i={...t,columns:t.columns.map(h=>({...r(h),tasks:h.tasks.map(r)}))};const n=h=>T({code:"INVALID_OP",message:h});const o=()=>i.columns.flatMap(h=>[h,...h.tasks]);const s=h=>o().find(m=>m.id===h);const a=h=>i.columns.find(m=>m.tasks.some(f=>f.id===h));const l=h=>i.columns.find(m=>m.id===h);const c=h=>typeof h==="string"&&!!h.trim()&&!/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/.test(h);const d=h=>typeof h==="string"&&/^[\p{L}\p{N}_-]+$/u.test(h)&&!s(h);const u=(h,m)=>h===void 0?m:Number.isInteger(h)&&h>=0&&h<=m?h:-1;switch(e.kind){case"set_accessibility_title":if(e.title!==void 0&&!c(e.title))return n("Accessibility title must be text");i.accessibilityTitle=e.title;break;case"set_accessibility_description":if(e.description!==void 0&&!c(e.description))return n("Accessibility description must be text");i.accessibilityDescription=e.description;break;case"add_column":{const h=u(e.index,i.columns.length);if(!d(e.id)||!c(e.label)||h<0)return n("add_column requires a new identifier, non-empty label and valid insertion index");i.columns.splice(h,0,{id:e.id,sourceId:e.id,label:e.label,metadata:{},tasks:[]});break}case"remove_column":{const h=l(e.id);if(!h)return n(`Kanban column ${e.id} not found`);if(h.tasks.length&&!e.removeTasks)return n("Column is not empty; move its cards first or set removeTasks: true");i.columns.splice(i.columns.indexOf(h),1);break}case"set_column_label":{const h=l(e.id);if(!h||!c(e.label))return n("set_column_label requires an existing column and non-empty label");h.label=e.label;delete h.metadata.label;break}case"move_column":{const h=l(e.id),m=u(e.index,i.columns.length-1);if(!h||m<0)return n("move_column requires an existing column and destination index");i.columns.splice(i.columns.indexOf(h),1);i.columns.splice(m,0,h);break}case"add_task":{const h=l(e.column);if(!h)return n(`Kanban column ${e.column} not found`);const m=u(e.index,h.tasks.length);if(!d(e.id)||!c(e.label)||m<0||e.metadata!==void 0&&!wt(e.metadata))return n("add_task requires a new identifier, non-empty label, metadata object and insertion index in range");const f=structuredClone(e.metadata??{});const p=Xu(f.label)??e.label;h.tasks.splice(m,0,{id:e.id,sourceId:e.id,label:p,metadata:f,...f.icon?{icon:String(f.icon)}:{}});break}case"remove_task":{const h=a(e.id);if(!h)return n(`Kanban task ${e.id} not found`);h.tasks.splice(h.tasks.findIndex(m=>m.id===e.id),1);break}case"set_task_label":{const h=a(e.id)?.tasks.find(m=>m.id===e.id);if(!h||!c(e.label))return n("set_task_label requires an existing task and non-empty label");h.label=e.label;delete h.metadata.label;break}case"set_task_metadata":{const h=a(e.id)?.tasks.find(m=>m.id===e.id);if(!h||e.metadata!==null&&!wt(e.metadata))return n("set_task_metadata requires an existing task and metadata object or null");h.metadata=structuredClone(e.metadata??{});h.icon=h.metadata.icon?String(h.metadata.icon):void 0;if(h.metadata.label)h.label=Xu(h.metadata.label);break}case"move_task":{const h=a(e.id),m=l(e.column),f=s(e.id);if(!h||!m||!f)return n("move_task requires an existing task and destination column");h.tasks.splice(h.tasks.indexOf(f),1);const p=u(e.index,m.tasks.length);if(p<0)return n("move_task index is out of range");m.tasks.splice(p,0,f);break}case"set_icon":{const h=s(e.id);if(!h||e.icon!==void 0&&!c(e.icon))return n("set_icon requires an existing item and icon text");h.icon=e.icon;delete h.metadata.icon;break}case"set_class":{const h=s(e.id);if(!h||e.className!==void 0&&!/^[\w -]*$/.test(e.className))return n("set_class requires an existing item and CSS class tokens");h.className=e.className;break}default:return n(Ve("kanban",e))}try{Ei(Kh(i))}catch(h){if(h instanceof Ln)return n(h.message);return n(`Kanban edit cannot be serialized as Mermaid: ${h instanceof Error?h.message:String(h)}`)}return re(i)}function Kk(t,e){const r=[];const i=Ke(r,e);if(!t.columns.length)r.push({code:"EMPTY_DIAGRAM"});for(const n of t.columns)for(const o of[n,...n.tasks]){i(o.id,o.label);for(const s of["ticket","assigned","priority"])if(o.metadata[s])i(`${o.id}:${s}`,String(o.metadata[s]))}return r}function Jh(t){try{return Wl(t)}catch{return null}}function Jk(t){const e=["packet"];Lt(e,t);if(t.title!==void 0)e.push(`title ${t.title.replace(/\r?\n/g,"<br/>")}`);for(const r of t.fields)e.push(`${r.start}${r.end===r.start?"":`-${r.end}`}: ${JSON.stringify(r.label).replace(/%%(?=\{)/g,"%\\%")}`);return e.join("\n")+"\n"}function Qk(t,e){const r={...t,fields:t.fields.map(l=>({...l}))};const i=l=>T({code:"INVALID_OP",message:l});const n=l=>typeof l==="string"&&!/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/.test(l);const o=l=>Number.isSafeInteger(l)&&l>0;const s=l=>Number.isInteger(l)&&l>=0&&l<r.fields.length;switch(e.kind){case"set_title":if(e.title!==void 0&&(!n(e.title)||/\r?\n/.test(e.title)))return i("Packet title must be single-line text");r.title=e.title;break;case"set_accessibility_title":if(e.title!==void 0&&!n(e.title))return i("Packet accessibility title must be text");r.accessibilityTitle=e.title;break;case"set_accessibility_description":if(e.description!==void 0&&(!n(e.description)||!e.description.trim()))return i("Packet accessibility description must be non-empty text");r.accessibilityDescription=e.description;break;case"add_field":{const l=e.index??r.fields.length;if(!Number.isInteger(l)||l<0||l>r.fields.length||!n(e.label)||!o(e.bits))return i("add_field requires a label, positive integer bits, and an insertion index in range");const c=new Set(r.fields.map(u=>u.id));let d=0;while(c.has(`field-${d}`))d++;r.fields.splice(l,0,{id:`field-${d}`,start:0,end:e.bits-1,label:e.label});break}case"remove_field":if(!s(e.index))return i("Packet field index is out of range");r.fields.splice(e.index,1);break;case"set_field_label":if(!s(e.index)||!n(e.label))return i("set_field_label requires a field index and text label");r.fields[e.index].label=e.label;break;case"set_field_bits":if(!s(e.index)||!o(e.bits))return i("set_field_bits requires a field index and positive integer bits");r.fields[e.index].end=r.fields[e.index].start+e.bits-1;break;case"move_field":if(!s(e.from)||!s(e.to))return i("move_field indices are out of range");r.fields.splice(e.to,0,r.fields.splice(e.from,1)[0]);break;default:return i(Ve("packet",e))}let a=0;for(const l of r.fields){const c=l.end-l.start+1;l.start=a;a+=c;l.end=a-1}if(!Number.isSafeInteger(a))return i("Packet size exceeds the safe integer range");return re(r)}function Zk(t,e){const r=[];const i=Ke(r,e);if(!t.fields.length)r.push({code:"EMPTY_DIAGRAM"});if(t.title!==void 0)i("title",t.title);for(const n of t.fields)i(n.id,n.label);return r}var di=(t=true)=>({type:"string",required:t});var ma=()=>({type:"object-or-null",required:true});var f1={set_direction:{fields:{direction:{type:"enum",values:["TB","BT","LR","RL"],required:true}}},add_requirement:{fields:{requirement:ma()}},update_requirement:{fields:{id:di(),changes:ma()}},add_element:{fields:{element:ma()}},update_element:{fields:{id:di(),changes:ma()}},rename_node:{fields:{from:di(),to:di()}},remove_node:{fields:{id:di(),cascade:{type:"boolean",required:false}}},add_relation:{fields:{relation:ma()}},remove_relation:{fields:{id:di()}},define_class:{fields:{name:di(),style:di()}},set_node_class:{fields:{id:di(),className:{type:"string-or-null",required:true}}},set_node_style:{fields:{id:di(),style:{type:"string-or-null",required:true}}}};function em(t,e={}){try{const r=typeof t==="string"?t:["requirementDiagram",...t];const i=[];const n=Eo(r,o=>i.push(o));if(rm(n,i))return null;n.accessibilityTitle=e.title??n.accessibilityTitle;n.accessibilityDescription=e.descr??n.accessibilityDescription;return n}catch{return null}}var p1={Requirement:"requirement","Functional Requirement":"functionalRequirement","Interface Requirement":"interfaceRequirement","Performance Requirement":"performanceRequirement","Physical Requirement":"physicalRequirement","Design Constraint":"designConstraint"};function rr(t){if(typeof t!=="string"||t.includes('"')||t.includes("\0"))throw new Error("Requirement strings cannot contain a literal quote or NUL");return`"${t.replace(/\r\n/g,"\r\r\n")}"`}function tm(t){const e=rm(t);if(e)throw new Error(e);const r=["requirementDiagram",` direction ${t.direction}`];Lt(r,t);for(const n of t.classDefs)if(n.styles.length)r.push(` classDef ${n.id} ${n.styles.join(",")}`);const i=n=>{const o=n.classes.filter(s=>s!=="default");if(o.length)r.push(` ${rr(n.name)}:::${o.join(",")}`);if(n.directStyles?.length)r.push(` style ${rr(n.name)} ${n.directStyles.join(",")}`)};for(const n of t.requirements){const o=p1[n.type];if(!o)throw new Error(`Unknown requirement type ${n.type}`);r.push(` ${o} ${rr(n.name)} {`);if(n.requirementId)r.push(` id: ${rr(n.requirementId)}`);if(n.text)r.push(` text: ${rr(n.text)}`);if(n.risk)r.push(` risk: ${n.risk.toLowerCase()}`);if(n.verifyMethod)r.push(` verifymethod: ${n.verifyMethod.toLowerCase()}`);r.push(" }");i(n)}for(const n of t.elements){r.push(` element ${rr(n.name)} {`);if(n.type)r.push(` type: ${rr(n.type)}`);if(n.docRef)r.push(` docref: ${rr(n.docRef)}`);r.push(" }");i(n)}for(const n of t.relations)r.push(` ${rr(n.src)} - ${n.type} -> ${rr(n.dst)}`);return r.join("\n")+"\n"}function Qh(t,e){return/#\w+;/.test(tn(t+e.join(",")).slice(t.length))}function rm(t,e){const r=e??[...t.classDefs.map(i=>({prefix:`classDef ${i.id} `,styles:i.styles})),...[...t.requirements,...t.elements].map(i=>({prefix:`style ${rr(i.name)} `,styles:i.directStyles??[]}))];for(const{prefix:i,styles:n}of r){if(Qh(i,n))return`Requirement ${i.trim()} contains an entity-like style token that pinned Mermaid cannot read, so the authored source must be preserved`;const o=n.join(",");if(!Yu(o))return`Requirement ${i.trim()} contains style text that pinned Mermaid's styleComponent tokens cannot spell losslessly; the authored source must be preserved`;const s=Zh(i,Ti(o));if(s)return s}return void 0}function Zh(t,e){for(const[r,i]of Object.entries(e)){if(/[,;:\s]/.test(r))return`Requirement ${t.trim()} property name ${JSON.stringify(r)} cannot retain its field boundary in pinned Mermaid's style lexer; the authored source must be preserved`;if(!Yu(`${r}:${i}`))return`Requirement ${t.trim()} contains style text that pinned Mermaid's styleComponent tokens cannot spell losslessly; the authored source must be preserved`;if(i.includes(","))return`Requirement ${t.trim()} style value ${JSON.stringify(i)} contains a comma that pinned Mermaid splits into separate fields; the authored source must be preserved`;if(/\s/.test(i))return`Requirement ${t.trim()} style value ${JSON.stringify(i)} loses meaningful whitespace in pinned Mermaid's style lexer; the authored source must be preserved`}return void 0}function GF(t,e){try{const r=[];const i=Si(t).authoredPayloadText;const n=i.split(/\r\n?|\n/);const o=[];let s=1,a=0;const l=Eo(i,d=>r.push(d),d=>{s+=i.slice(a,d).match(/\r\n?|\n/g)?.length??0;a=d;const u=e?.(s)??n[s-1];if(/[^\S\r\n]+$/.test(u)&&!o.some(h=>h.code==="UNSUPPORTED_SYNTAX"&&h.syntax==="requirement_whitespace"))o.push({code:"UNSUPPORTED_SYNTAX",syntax:"requirement_whitespace",line:s,message:"Requirement whitespace before a required line break is read as a statement boundary. Pinned Mermaid consumes that break as whitespace and rejects the next statement; canonical output removes the trailing whitespace."})});const c=rm(l,r);if(c)o.push({code:"UNSUPPORTED_SYNTAX",syntax:"requirement_style_token",message:c});return o}catch{return[]}}function fa(t){if(typeof t.name!=="string"||!t.name.trim())throw new Error("Node name must be non-empty text");for(const e of[t.name,..."text"in t?[t.requirementId,t.text]:[t.type,t.docRef]])rr(e);if("text"in t){if(!Object.values(Mx).includes(t.type))throw new Error("Invalid requirement type");if(t.risk&&!Object.values(Ax).includes(t.risk))throw new Error("Invalid risk; use Low, Medium or High");if(t.verifyMethod&&!Object.values(Ox).includes(t.verifyMethod))throw new Error("Invalid verification method")}}function eS(t,e){const r=structuredClone(t),i=[...r.requirements,...r.elements];const n=s=>{const a=i.find(l=>l.name===s);if(!a)throw new Error(`Requirement node ${s} not found`);return a};const o=s=>{if(i.some(a=>a.name===s))throw new Error(`Requirement node ${s} already exists`)};try{switch(e.kind){case"set_direction":if(!["TB","BT","LR","RL"].includes(e.direction))throw new Error("Invalid requirement direction");r.direction=e.direction;break;case"add_requirement":{const a={type:"Requirement",requirementId:"",text:"",risk:"",verifyMethod:"",classes:["default"],...e.requirement,cssStyles:[]};o(a.name);fa(a);r.requirements.push(a);break}case"update_requirement":{const a=r.requirements.find(l=>l.name===e.id);if(!a)throw new Error(`Requirement ${e.id} not found`);Object.assign(a,e.changes);fa(a);break}case"add_element":{const a={type:"",docRef:"",classes:["default"],...e.element,cssStyles:[]};o(a.name);fa(a);r.elements.push(a);break}case"update_element":{const a=r.elements.find(l=>l.name===e.id);if(!a)throw new Error(`Element ${e.id} not found`);Object.assign(a,e.changes);fa(a);break}case"rename_node":{const a=n(e.from);if(e.from!==e.to)o(e.to);a.name=e.to;fa(a);for(const l of r.relations){if(l.src===e.from)l.src=e.to;if(l.dst===e.from)l.dst=e.to}break}case"remove_node":{n(e.id);if(!e.cascade&&r.relations.some(a=>a.src===e.id||a.dst===e.id))throw new Error("Node has relations; pass cascade: true");r.requirements=r.requirements.filter(a=>a.name!==e.id);r.elements=r.elements.filter(a=>a.name!==e.id);r.relations=r.relations.filter(a=>a.src!==e.id&&a.dst!==e.id);break}case"add_relation":{n(e.relation.src);n(e.relation.dst);if(!Object.values(Bx).includes(e.relation.type))throw new Error("Invalid requirement relation");const a=new Set(r.relations.map(d=>d.id));let l=1;while(a.has(`relation-${l}`))l++;const c=e.relation.id??`relation-${l}`;if(a.has(c))throw new Error("Relation id already exists");r.relations.push({...e.relation,id:c});break}case"remove_relation":if(!r.relations.some(a=>a.id===e.id))throw new Error("Relation not found");r.relations=r.relations.filter(a=>a.id!==e.id);break;case"define_class":{if(!/^\w+$/.test(e.name))throw new Error("Class name must be a word");if(Qh(`classDef ${e.name} `,[e.style]))throw new Error("Requirement class style contains an entity-like token that pinned Mermaid cannot read");const a=zt(e.style);if(!a.ok)throw new Error(`Invalid style: ${a.reason}`);const l=Zh(`classDef ${e.name} `,a.value);if(l)throw new Error(l);const c=Object.entries(a.value).map(([u,h])=>`${u}:${h}`);const d=r.classDefs.find(u=>u.id===e.name);if(d)d.styles=c;else r.classDefs.push({id:e.name,styles:c,textStyles:[]});break}case"set_node_class":{const a=n(e.id);if(e.className!==null&&!/^\w+$/.test(e.className))throw new Error("Invalid class name");a.classes=e.className===null?["default"]:["default",e.className];break}case"set_node_style":{const a=n(e.id);if(e.style===null)a.directStyles=[];else{if(Qh(`style ${rr(a.name)} `,[e.style]))throw new Error("Requirement node style contains an entity-like token that pinned Mermaid cannot read");const l=zt(e.style);if(!l.ok)throw new Error(`Invalid style: ${l.reason}`);const c=Zh(`style ${rr(a.name)} `,l.value);if(c)throw new Error(c);a.directStyles=Object.entries(l.value).map(([d,u])=>`${d}:${u}`)}break}default:throw new Error(Ve("requirement",e))}const s=Eo(Si(tm(r)).authoredPayloadText);s.relations.forEach((a,l)=>{a.id=r.relations[l].id});return re(s)}catch(s){return T({code:"INVALID_OP",message:s instanceof Error?s.message:String(s)})}}function tS(t,e){const r=[],i=Ke(r,e);const n=new Set([...t.requirements,...t.elements].map(o=>o.name));if(!n.size)r.push({code:"EMPTY_DIAGRAM"});for(const o of[...t.requirements,...t.elements]){i(o.name,o.name);if("text"in o)i(o.name,o.text)}for(const o of t.relations)if(!n.has(o.src)||!n.has(o.dst))r.push({code:"UNSUPPORTED_SYNTAX",syntax:"undeclared endpoint",message:`Relation ${o.id} references an undeclared endpoint`});return r}var Di={type:"string",required:true};var im={type:"string",required:false};var Bc={type:"string-or-null",required:true};var g1={set_title:{fields:{title:Bc}},add_node:{fields:{label:Di,value:{type:"number",required:false},parentId:im,className:im}},remove_node:{fields:{id:Di}},set_label:{fields:{id:Di,label:Di}},set_value:{fields:{id:Di,value:{type:"number",required:true}}},move_node:{fields:{id:Di,parentId:im,index:{type:"number",required:false}}},define_class:{fields:{name:Di,style:Di}},set_node_class:{fields:{id:Di,className:Bc}},set_accessibility_title:{fields:{title:Bc}},set_accessibility_description:{fields:{description:Bc}}};function nm(t){try{const e=Ul(["treemap",...t]);_c(e);return e}catch{return null}}function y1(t){return`"${rS(t,'"%')}"`}function rS(t,e){return rn(t,e).replace(/\r/g,"#13;").replace(/\n/g,"#10;")}function _c(t){Gl(t.nodes);const e=["treemap"];Lt(e,{...t.accessibilityTitle!==void 0?{accessibilityTitle:rn(t.accessibilityTitle,":;,%{}")}:{},...t.accessibilityDescription!==void 0?{accessibilityDescription:rn(t.accessibilityDescription,":;,%{}")}:{}});if(t.title!==void 0)e.push(`title ${rS(t.title,"%")}`);const r=new Map;for(const n of t.nodes){const o=r.get(n.parentId)??[];o.push(n);r.set(n.parentId,o)}const i=[...r.get(void 0)??[]].reverse().map(n=>({node:n,depth:0}));while(i.length){const{node:n,depth:o}=i.pop();const s=n.value?.toLocaleString("en-US",{useGrouping:false,maximumSignificantDigits:21});e.push(`${" ".repeat(o)}${y1(n.label)}${s===void 0?"":`: ${s}`}${n.className?`:::${n.className}`:""}`);for(const a of[...r.get(n.id)??[]].reverse())i.push({node:a,depth:o+1})}for(const[n,o]of Object.entries(t.classDefs)){if(!/^[A-Za-z_]\w+$/.test(n))throw new Error("Treemap class definitions require at least two identifier characters");e.push(`classDef ${n} ${Object.entries(o).map(([s,a])=>`${s}:${a}`).join(",")};`)}return e.join("\n")+"\n"}function iS(t,e){try{const r=structuredClone(t);const i=n=>{const o=r.nodes.find(s=>s.id===n);if(!o)throw new Error(`Treemap node ${n} was not found`);return o};switch(e.kind){case"set_title":r.title=e.title??void 0;break;case"set_accessibility_title":r.accessibilityTitle=e.title==null?void 0:ex(e.title);break;case"set_accessibility_description":r.accessibilityDescription=e.description==null?void 0:tx(e.description);break;case"add_node":{if(e.parentId&&i(e.parentId).value!==void 0)throw new Error("A leaf cannot contain children");let n=0;while(r.nodes.some(o=>o.id===`treemap-${n}`))n++;r.nodes.push({id:`treemap-${n}`,label:e.label,...e.parentId?{parentId:e.parentId}:{},...e.value===void 0?{}:{value:e.value},...e.className?{className:e.className}:{}});break}case"remove_node":{i(e.id);const n=vo(r.nodes,e.id);r.nodes=r.nodes.filter(o=>!n.has(o.id));break}case"set_label":i(e.id).label=e.label;break;case"set_value":{if(r.nodes.some(n=>n.parentId===e.id))throw new Error("A section containing children cannot become a leaf");i(e.id).value=e.value;break}case"move_node":{const n=i(e.id);if(e.parentId){if(i(e.parentId).value!==void 0)throw new Error("A leaf cannot contain children");if(vo(r.nodes,e.id).has(e.parentId))throw new Error("A node cannot move inside its own subtree")}n.parentId=e.parentId;const o=r.nodes.filter(l=>l.parentId===e.parentId&&l.id!==n.id);const s=e.index??o.length;if(!Number.isSafeInteger(s)||s<0||s>o.length)throw new Error("Invalid destination index");r.nodes=r.nodes.filter(l=>l.id!==n.id);const a=o[s];r.nodes.splice(a?r.nodes.findIndex(l=>l.id===a.id):r.nodes.length,0,n);break}case"define_class":if(!/^[A-Za-z_]\w*$/.test(e.name)||/[\r\n]/.test(e.style))throw new Error("Class name and style must be valid single-line Mermaid");r.classDefs[e.name]=Py(Ti(e.style),`classDef ${e.name}`);break;case"set_node_class":i(e.id).className=e.className??void 0;break;default:throw new Error(Ve("treemap",e))}for(const n of r.nodes){if(typeof n.label!=="string"||!n.label.trim())throw new Error("Treemap labels must be nonempty text");if(n.value!==void 0&&(!Number.isFinite(n.value)||n.value<0))throw new Error("Treemap values must be finite and nonnegative");if(n.className!==void 0&&!/^[A-Za-z_]\w*$/.test(n.className))throw new Error("Invalid Treemap class name")}_c(r);return re(r)}catch(r){return T({code:"INVALID_OP",message:r instanceof Error?r.message:String(r)})}}function nS(t,e){const r=[];if(!t.nodes.length)r.push({code:"EMPTY_DIAGRAM"});const i=Ke(r,e);for(const n of t.nodes)i(n.id,n.label);return r}function x1(t){return t.kind==="packet"||t.kind==="kanban"||t.kind==="requirement"||t.kind==="block"||t.kind==="treemap"||t.kind==="ishikawa"}function b1(t){switch(t.kind){case"packet":return{nodes:t.fields.map(e=>({id:e.id,label:e.label,value:e.end-e.start+1})),edges:[]};case"kanban":return{nodes:t.columns.flatMap(e=>[{id:e.id,label:e.label},...e.tasks.map(r=>({id:r.id,label:r.label,parentId:e.id}))]),edges:[]};case"requirement":return{nodes:[...t.requirements.map(e=>({id:e.name,label:e.name})),...t.elements.map(e=>({id:e.name,label:e.name}))],edges:t.relations.map(e=>({from:e.src,to:e.dst,label:e.type}))};case"block":return{nodes:Lr(t).filter(e=>e.node.type!=="space").map(e=>({id:e.node.id,label:e.node.label??e.node.id,...e.parentId?{parentId:e.parentId}:{}})),edges:t.edges.map(e=>({from:e.start,to:e.end,...e.label?{label:e.label}:{}}))};case"treemap":return{nodes:t.nodes.map(e=>({...e})),edges:[]};case"ishikawa":return{nodes:t.nodes.map(e=>({...e})),edges:t.nodes.filter(e=>e.parentId).map(e=>({from:e.id,to:e.parentId}))}}}function C1(t){switch(t.kind){case"packet":return{nodes:t.fields.length,edges:0,groups:0};case"kanban":return{nodes:t.columns.reduce((e,r)=>e+r.tasks.length,0),edges:0,groups:t.columns.length};case"requirement":return{nodes:t.requirements.length+t.elements.length,edges:t.relations.length,groups:0};case"block":{const e=Lr(t);return{nodes:e.filter(r=>!["space","composite"].includes(r.node.type??"")).length,edges:t.edges.length,groups:e.filter(r=>r.node.type==="composite").length}}case"treemap":return{nodes:t.nodes.filter(e=>e.value!==void 0).length,edges:0,groups:t.nodes.filter(e=>e.value===void 0).length};case"ishikawa":return{nodes:t.nodes.length,edges:Math.max(0,t.nodes.length-1),groups:0}}}function k1(t){const e=[];const r=i=>JSON.stringify(i);if("title"in t&&t.title!==void 0)e.push(`title ${r(t.title)}`);switch(t.kind){case"packet":t.fields.forEach((i,n)=>e.push(`field#${n} ${i.start}-${i.end} : ${r(i.label)}`));break;case"kanban":t.columns.forEach((i,n)=>{e.push(`column#${n} ${r(i.sourceId)} : ${r(i.label)}`);i.tasks.forEach((o,s)=>{e.push(`task#${n}.${s} ${r(o.sourceId)} : ${r(o.label)}`);for(const[a,l]of Object.entries(o.metadata))e.push(`task#${n}.${s} metadata ${r(a)} ${r(l)}`);if(o.icon)e.push(`task#${n}.${s} icon ${r(o.icon)}`);if(o.className)e.push(`task#${n}.${s} class ${r(o.className)}`)})});break;case"requirement":e.push(`direction ${t.direction}`);t.requirements.forEach(i=>e.push(`requirement ${r(i.name)} ${r(i.type)} id ${r(i.requirementId)} text ${r(i.text)} risk ${r(i.risk)} verify ${r(i.verifyMethod)}`));t.elements.forEach(i=>e.push(`element ${r(i.name)} type ${r(i.type)} docref ${r(i.docRef)}`));t.relations.forEach((i,n)=>e.push(`relation#${n} ${r(i.src)} ${i.type} ${r(i.dst)}`));break;case"block":e.push(`columns root ${t.root.columns??-1}`);for(const{node:i,parentId:n}of Lr(t))e.push(`block ${r(i.id)} parent ${r(n??null)} type ${i.type==="na"?"square":i.type??"square"} span ${i.widthInColumns??1} columns ${i.columns??-1} label ${r(i.label??"")}${i.directions?` directions ${r(i.directions)}`:""}`);t.edges.forEach((i,n)=>e.push(`edge#${n} ${r(i.start)} -> ${r(i.end)} label ${r(i.label??"")} markers ${i.arrowTypeStart??"none"} ${i.arrowTypeEnd??"none"}`));break;case"treemap":t.nodes.forEach((i,n)=>e.push(`node#${n} ${i.id} parent ${i.parentId??"root"} : ${r(i.label)}${i.value===void 0?" section":` value ${i.value}`}${i.className?` class ${i.className}`:""}`));break;case"ishikawa":t.nodes.forEach((i,n)=>e.push(`${i.parentId?"cause":"effect"}#${n} ${i.id}${i.parentId?` parent ${i.parentId}`:""} : ${r(i.label)}`));break}return e}function oS(t){const e=[];if("title"in t&&t.title!==void 0)e.push({text:t.title,target:"title"});switch(t.kind){case"packet":return[...e,...t.fields.map(r=>({text:r.label,target:r.id}))];case"kanban":return[...e,...t.columns.flatMap(r=>[r,...r.tasks].flatMap(i=>[{text:i.label,target:i.id},...Object.entries(i.metadata).filter(([n])=>["ticket","assigned","priority"].includes(n)).map(([,n])=>({text:String(n),target:i.id}))]))];case"requirement":return[...e,...t.requirements.flatMap(r=>[r.name,r.requirementId,r.text,r.risk,r.verifyMethod].filter(Boolean).map(i=>({text:i,target:r.name}))),...t.elements.flatMap(r=>[r.name,r.type,r.docRef].filter(Boolean).map(i=>({text:i,target:r.name}))),...t.relations.map(r=>({text:r.type,target:r.id}))];case"block":return[...e,...Lr(t).filter(r=>r.node.type!=="space").map(r=>({text:r.node.label??r.node.id,target:r.node.id})),...t.edges.filter(r=>r.label).map(r=>({text:r.label,target:r.id}))];case"treemap":case"ishikawa":return[...e,...t.nodes.map(r=>({text:r.label,target:r.id}))]}}function S1(t,e,r){const i={nodes:new Map,edges:new Map,groups:new Map,labels:new Map};const n=e.split(/\r?\n/);const o=u=>{const h=[0];for(let m=0;m<u.length;m++)if(u[m]==="\n")h.push(m+1);return h};const s=o(e);const a=(u,h=s)=>{let m=0,f=h.length;while(m<f){const g=m+f>>>1;if(h[g]<=u)m=g+1;else f=g}const p=Math.max(0,m-1);return{line:p+1,col:u-h[p]+1}};const l=(u,h=0)=>({line:u,col:h+1});const c=(u,h)=>{if(!i.labels.has(u))i.labels.set(u,h)};if(t.kind==="requirement"){const u=r?Br(r,"authored"):e;const h=u.replace(/^[^\r\n]*/,"requirementDiagram");const m=h.split(/[\r\n]/),f=[0];for(let M=0;M<h.length;M++)if(h[M]==="\r"||h[M]==="\n")f.push(M+1);const p=Nn(h).split(/[\r\n]/);const g=new Map;for(let M=0;M<n.length;M++){const E=n[M].trim(),_=g.get(E);if(_)_.rows.push(M);else g.set(E,{rows:[M],next:0})}const y=new Map;let C=0;for(let M=0;M<m.length;M++){const E=p[M].trim();if(!E)continue;const _=g.get(E);if(!_)continue;while(_.next<_.rows.length&&_.rows[_.next]<C)_.next++;const q=_.rows[_.next++];if(q===void 0)continue;y.set(M+1,q+1);C=q+1}const w=ql(h);const x=M=>{const E=a(M,f),_=y.get(E.line);if(_===void 0)return E;const q=Q=>Q.length-Q.trimStart().length;return{line:_,col:E.col-q(m[E.line-1])+q(n[_-1])}};const k=new Map;const b=(M,E)=>{if(i.labels.has(M))return;c(M,x(w.starts[E]));k.set(M,x(w.starts[E]+w.texts[E].length))};const A=M=>x(w.starts[M]);let L,B=0;const O=new Set([...t.requirements.map(M=>M.name),...t.elements.map(M=>M.name)]);for(let M=0;M<w.types.length;M++){const E=w.types[M];if((E>=23&&E<=28||E===36)&&O.has(w.texts[M+1])){L=w.texts[M+1];if(!i.nodes.has(L))i.nodes.set(L,A(M+1));b(`node:${L}`,M+1)}else if(E===16)L=void 0;else if(L&&E>=19&&E<=22||L&&(E===44||E===45)){if(w.types[M+1]===18)b(`node:${L}:${Tx[E].toLowerCase()}`,M+2)}else if(E>=37&&E<=43){const _=t.relations[B];if(!_)continue;i.edges.set(_.id,A(M-2));b(`edge#${B}:${_.src}->${_.dst}`,M);B++}}Li(i,{labels:k});return i}if(t.kind==="kanban"){const u=r?wi(r):{text:e,sourceOffset:x=>x,familyOffset:x=>x};const h=r?wi(r,"authored"):u;const m=r?[0]:[...Bt(h.text)],f=new Map;if(r){for(let x=0;x<h.text.length;x++)if(h.text[x]==="\r"||h.text[x]==="\n")m.push(x+1)}const p=Bt(r?.originalText??e);const g={nodes:new Map,groups:new Map,labels:new Map,metadata:new Map};const y=(x,k)=>bo(p,u.sourceOffset(x,"end"),u.sourceOffset(k,"start"));const C=x=>{const k=a(h.familyOffset(x,"end"),m);let b=f.get(k.line);if(b===void 0){const A=h.text.slice(m[k.line-1],m[k.line]);b=A.length-A.trimStart().length;f.set(k.line,b)}return{line:k.line,col:k.col-b}};let w;Ds("kanban",x=>{if(x.unit==="statement"){w=x;return}if(x.unit!=="mutation"||x.kind!=="add-column"&&x.kind!=="add-task"||!w?.source||!x.value||typeof x.value!=="object"||Array.isArray(x.value))return;const k=x.value;const b=w.source.offset,A=w.source.endOffset;if(typeof k.id!=="string"||b===void 0||A===void 0)return;const L=x.kind==="add-column",B=k.id;const O=b+Number(k.declaredStart);const M=y(O,A);(L?i.groups:i.nodes).set(B,C(M.start.offset));(L?g.groups:g.nodes).set(B,M);const E=typeof k.declaredLabel==="string"?k.declaredLabel:"";if(E&&typeof k.declaredLabelStart==="number"){const _=b+k.declaredLabelStart;const q=y(_,_+E.length);i.labels.set(`${L?"group":"node"}:${B}`,C(q.start.offset));g.labels.set(`${L?"group":"node"}:${B}`,q)}if(Array.isArray(k.metadataSpans)){const _=new Map;for(const q of k.metadataSpans){if(!q||typeof q!=="object"||Array.isArray(q))continue;const Q=q;if(typeof Q.name!=="string"||!["keyStart","keyEnd","valueStart","valueEnd"].every($=>typeof Q[$]==="number"))continue;_.set(Q.name,{key:y(b+Q.keyStart,b+Q.keyEnd),value:y(b+Q.valueStart,b+Q.valueEnd)})}if(_.size)g.metadata.set(B,_)}},()=>Ei(u.text,{},r));Ik(i,g);return i}if(t.kind==="block"){const u=new Map(Lr(t).map(x=>[x.node.id,x.node]));const h=$l(e);let m=-1,f=0,p=-1;const g=new Set;for(let x=0;x<h.types.length;x++){const k=h.types[x];if(k===32){m=x;const b=u.get(h.texts[x]);if(!b||b.type==="space")continue;const A=b.type==="composite",L=A?i.groups:i.nodes;const B=h.types[x-1]===3||h.types[x+1]===27||h.types[x+1]===29;if(!L.has(b.id)||B&&!g.has(b.id)){L.set(b.id,a(h.starts[x]));const O=h.types[x+1]===27||h.types[x+1]===29?x+2:x;if(B||!i.labels.has(`${A?"group":"node"}:${b.id}`))i.labels.set(`${A?"group":"node"}:${b.id}`,a(h.starts[O]))}if(B)g.add(b.id)}else if(k===35)p=x+1;else if(k===33){const b=t.edges[f];if(b&&m>=0){i.edges.set(b.id,a(h.starts[m]));if(p>=0)c(`edge#${f}:${b.start}->${b.end}`,a(h.starts[p]))}f++;p=-1}}const y=[];let C,w;Ds("block",x=>{if(x.unit==="statement"){C=x;if(x.kind==="BLOCK_DIAGRAM_KEY"||x.kind==="id-block")y.push(x.source?.offset??0);else if(x.kind==="end")w=y.pop()}else if(x.unit==="mutation"&&x.kind==="generate-id"&&C?.kind==="end"&&w!==void 0&&typeof x.value==="string"&&u.get(x.value)?.type==="composite"){i.groups.set(x.value,a(w))}},()=>ln(e),{mutations:["generate-id"]});return i}let d;Ds(t.kind,u=>{if(u.unit==="statement"){d=u;return}if(u.unit!=="mutation"||!d?.source?.line||!u.value||typeof u.value!=="object"||Array.isArray(u.value))return;const h=u.value;if(typeof h.id!=="string")return;const m=h.id,f=u.source?.line??d.source.line;const p=n[f-1]??"",g=p.length-p.trimStart().length;if(t.kind==="packet"&&u.kind==="add-field"){i.nodes.set(m,l(f,g));const y=p.indexOf(":",g),C=p.slice(y+1).search(/["']/);if(y>=0&&C>=0)c(`node:${m}`,l(f,y+C+2))}else if((t.kind==="treemap"||t.kind==="ishikawa")&&u.kind==="add-node"){const y=t.kind==="treemap"&&h.value===void 0;const C=u.source?.column===void 0?g:u.source.column-1;(y?i.groups:i.nodes).set(m,l(f,C));c(`${y?"group":"node"}:${m}`,l(f,C+(t.kind==="treemap"?1:0)));if(t.kind==="ishikawa"&&typeof h.parentId==="string")i.edges.set(`branch:${m}`,l(f,g))}},()=>{switch(t.kind){case"packet":return Jh(n);case"treemap":return nm(n.slice(1));case"ishikawa":return Yh(n.slice(1))}});return i}function Uo(t,e,r,i,n,o=false){const s=l=>{const c=l.split(/\r?\n/);const d=c.findIndex(u=>u.trim()&&!u.trimStart().startsWith("%%"));return d<0?[]:c.slice(d)};const a=l=>n?n(l):e(s(l));return{readSource:a,serialize:r,operations:{parse:l=>{const c=n?n(l.source.familyBody,l.source,l.meta.accessibility):e(s(l.source.familyBody),l.meta.accessibility);if(c&&o){const d=ki(l.meta.accessibility);l.meta.accessibility=d;Object.assign(c,Cy(d))}return re(c??{kind:"opaque",family:t,source:l.opaqueSource})},serialize:l=>{if(l.kind!==t)throw new Error(`Expected ${t} body`);return r(l)},verify:(l,c)=>l.kind===t?i(l,c):[],renderSource:l=>l.kind==="opaque"?"canonical":"serialized",extractLabels:l=>{const c=a(l);return c?oS(c):[]},buildSourceMap:(l,c,d)=>l.kind===t?S1(l,c,d):{nodes:new Map,edges:new Map,groups:new Map,labels:new Map}}}}var om=Uo("packet",Jh,Jk,Zk);var sm=om.operations;var am=Uo("kanban",t=>Xh(t),Kh,Kk,(t,e)=>Xh(t,e??st(t)));var lm=am.operations;var cm=Uo("requirement",t=>em(t.slice(1)),tm,tS,(t,e,r)=>em(e?Br(e,"authored"):Si(t).authoredPayloadText,r));var dm=cm.operations;var um=Uo("block",(t,e)=>Gk(t.slice(1),e),Oc,jk,void 0,true);var hm=um.operations;var mm=Uo("treemap",t=>nm(t.slice(1)),_c,nS,void 0,true);var fm={...mm.operations,renderSource:()=>"serialized"};var pm=Uo("ishikawa",t=>Yh(t.slice(1)),Hh,Hk,void 0,true);var gm={...pm.operations,renderSource:()=>"serialized"};var sS={packet:sm,kanban:lm,requirement:dm,block:hm,treemap:fm,ishikawa:gm};function jo(t,e,r){const{readSource:i,serialize:n}=e;return(o,s)=>{if(o.kind!==t)return T({code:"UNSUPPORTED_FAMILY",message:`${t} contains unmodeled syntax and remains preserved verbatim`});const a=r(o,s);if(!a.ok)return a;try{a.value=_l(a.value)}catch(c){if(!(c instanceof xo))throw c;return T({code:"INVALID_OP",message:c.message})}const l=i(n(a.value));if(l&&(a.value.accessibilityTitle!==l.accessibilityTitle||a.value.accessibilityDescription!==l.accessibilityDescription)){return T({code:"INVALID_OP",message:`${t} accessibility text cannot be serialized without changing its value`})}return l?re(l):T({code:"INVALID_OP",message:`${t} edit could not preserve its structured representation`})}}var w1={...sm,mutate:jo("packet",om,Qk)};var T1={...lm,mutate:jo("kanban",am,Xk)};var v1={...dm,mutate:jo("requirement",cm,eS)};var E1={...hm,mutate:jo("block",um,Uk)};var M1={...fm,mutate:jo("treemap",mm,iS)};var A1={...gm,mutate:jo("ishikawa",pm,Yk)};var aS={packet:w1,kanban:T1,requirement:v1,block:E1,treemap:M1,ishikawa:A1};function bS(t,e={}){try{const r=cn(t);if(e.title!==void 0)r.accessibilityTitle=e.title;if(e.descr!==void 0)r.accessibilityDescription=e.descr;return r}catch(r){if(r instanceof jl)throw r;return null}}function Yn(t,e=""){return`"${CS(Or(t,'"\\'+e).replace(/%%\{/g,"%#37;{"))}"`}function CS(t){return t.replace(/^\s+|\s+$/g,e=>[...e].map(r=>dy.test(r)?r:`#${r.codePointAt(0)};`).join(""))}function kS(t,e=""){return/^[A-Za-z_][A-Za-z_0-9]*$/.test(t)?t:Yn(t,e)}function lS(t,e=""){return`"${CS(Or(t,'"\\<>'+e).replace(/%%\{/g,"%#37;{").replace(/\r\n?|\n/g,"<br/>"))}"`}function ym(t,e,r,i){return xl(n=>{const o=[];for(let s=0;s<i;s++){const a=r[s],l=e[a]??"";o.push(a==="alias"||a==="from"||a==="to"||a==="index"?kS(l,n):lS(l,n))}for(let s=i;s<r.length;s++){const a=r[s],l=e[a];if(l!==void 0&&l!=="")o.push(`$${a}=${["techn","descr","type"].includes(a)?lS(l,n):Yn(l,n)}`)}return`${t}(${o.join(", ")})`})}function SS(t){return ym(t.macro,{alias:t.id,label:t.label,techn:t.technology,descr:t.description,sprite:t.sprite,tags:t.tags.join("+")||void 0,link:t.link},Vl(t.macro),2)}function wS(t){return`${ym(t.macro,{alias:t.id,label:t.label,type:t.type,descr:t.description,sprite:t.sprite,tags:t.tags.join("+")||void 0,link:t.link},Yl(t.macro),2)} {`}function TS(t){return ym(t.macro,{index:t.index,from:t.from,to:t.to,label:t.label,techn:t.technology,descr:t.description,sprite:t.sprite,tags:t.tags.join("+")||void 0,link:t.link},Hl(t.macro),t.macro==="RelIndex"?4:3)}function O1(t){if(t.name==="direction")return`direction ${t.args[0]?.value??"TB"}`;return xl(e=>{const r=Lx(t.name);if(r){const i=Ku(t.args,r);if(t.name==="UpdateLayoutConfig"){const s=i.c4BoundaryInRow!==void 0?2:1;return`${t.name}(${r.slice(0,s).map(a=>Yn(i[a]??"",e)).join(", ")})`}const n=t.name==="UpdateElementStyle"?1:2;const o=r.slice(0,n).map(s=>Yn(i[s]??"",e));for(const s of r.slice(n)){if(i[s]!==void 0&&i[s]!=="")o.push(`$${s}=${Yn(i[s],e)}`)}return`${t.name}(${o.join(", ")})`}return`${t.name}(${t.args.map(i=>`${i.name?`$${i.name}=`:""}${Yn(i.value,e)}`).join(", ")})`})}function yr(t,e,r,i=""){const n=kt(t.statements.map(o=>o.id));return{id:n("c4-statement-new"),kind:e,entityId:r,raw:i,span:{start:0,end:0,line:0,column:0}}}function vS(t){const e=[];const r=(s,a,l="")=>{e.push({id:`c4-statement-${e.length+1}`,kind:s,entityId:a,raw:l,span:{start:0,end:0,line:0,column:0}})};r("header");r("trivia",void 0,"\n");if(t.title!==void 0){r("title");r("trivia",void 0,"\n")}if(t.accessibilityTitle!==void 0){r("accessibility","title");r("trivia",void 0,"\n")}if(t.accessibilityDescription!==void 0){r("accessibility","description");r("trivia",void 0,"\n")}const i=new Map;for(const s of[...t.boundaries,...t.elements]){const a=i.get(s.parentId)??[];a.push(s);i.set(s.parentId,a)}const n=(i.get(void 0)??[]).map(s=>({record:s})).reverse();const o=new Set(t.boundaries.map(s=>s.id));while(n.length){const{record:s,close:a}=n.pop();if(a)r("boundary-close",s.id);else if(o.has(s.id)){r("boundary-open",s.id);n.push({record:s,close:true},...(i.get(s.id)??[]).map(l=>({record:l})).reverse())}else r("element",s.id);r("trivia",void 0,"\n")}for(const s of t.relationships){r("relationship",s.id);r("trivia",void 0,"\n")}for(const s of t.directives){r("directive",s.id);r("trivia",void 0,"\n")}return e}var B1=new Set(["c4_multiline_arguments","c4_empty_named_argument","c4_space_before_arguments","c4_quoted_string_extension","c4_relindex_positional_metadata","c4_empty_layout_arguments","c4_unquoted_argument","c4_entity_prepass","c4_empty_accessibility_description"]);function xm(t,e=false){const r=e&&!t.diagnostics.some(p=>p.severity==="error");const i=p=>new Set(r?t.diagnostics.filter(g=>p(g.syntax)).map(g=>g.statementId):[]);const n=i(p=>B1.has(p));const o=i(p=>p==="c4_semicolon_separator");const s=i(p=>p==="c4_statements_on_one_line");const a=[];const l=[];const c=new Map(t.elements.map(p=>[p.id,p]));const d=new Map(t.boundaries.map(p=>[p.id,p]));const u=new Map(t.relationships.map(p=>[p.id,p]));const h=new Map(t.directives.map(p=>[p.id,p]));const m=t.statements.length?t.statements:vS(t);const f=[];for(const p of m){let g,y;let C=false;if(p.kind==="header"){g=t.variant;y=t.variant}else if(p.kind==="trivia"&&n.has(p.id))g='UpdateLayoutConfig("")';else if(p.kind==="title"){if(t.title===void 0)continue;g=xl(k=>`title ${Or(t.title,"#;<>"+k).replace(/%%\{/g,"%#37;{").replace(/\r\n?|\n/g,"<br/>")}`);y=t.title}else if(p.kind==="accessibility"){const k=p.entityId==="title"?t.accessibilityTitle:t.accessibilityDescription;if(k===void 0)continue;const b=[];Lt(b,p.entityId==="title"?{accessibilityTitle:k}:{accessibilityDescription:k});g=b.join("\n").trimStart();y=k}else if(p.kind==="boundary-close"){if(!d.has(p.entityId))continue;g="}"}else if(p.kind==="element"||p.kind==="boundary-open"||p.kind==="relationship"||p.kind==="directive"){const k=p.kind==="element"?c.get(p.entityId):p.kind==="boundary-open"?d.get(p.entityId):p.kind==="relationship"?u.get(p.entityId):h.get(p.entityId);if(!k)continue;const b=p.kind==="element"?Vl(k.macro).slice(0,2):p.kind==="boundary-open"?Yl(k.macro).slice(0,2):p.kind==="relationship"?Hl(k.macro).slice(0,k.macro==="RelIndex"?4:3):[];C=r&&("name"in k?!Rx(k):!Ix(k.args,b));y=Xl(k);g=p.kind==="element"?SS(k):p.kind==="boundary-open"?wS(k):p.kind==="relationship"?TS(k):O1(k)}const w=r&&p.kind==="title";if(r&&f.length&&(p.kind==="title"||p.kind==="accessibility")){l.push({kind:"trivia",text:"\n"},{kind:p.kind,text:g},{kind:"trivia",text:"\n"});continue}let x=g===void 0||p.raw&&(y===p.signature||p.kind==="boundary-close")&&!n.has(p.id)&&!C&&!w?p.raw:g;if(e){if(p.kind==="boundary-close"){if(f.pop()===false)x=`
171
+ UpdateLayoutConfig("")
172
+ ${x}`}else if(p.kind==="element"||p.kind==="relationship"||p.kind==="directive"||p.kind==="boundary-open"||p.kind==="trivia"&&/^\s*UpdateLayoutConfig\(\s*""\s*\)\s*$/.test(x)){if(f.length)f[f.length-1]=true;if(p.kind==="boundary-open")f.push(false)}}if(o.has(p.id))x=x.replace(/;/g,"");if(s.has(p.id))cS(a);a.push({kind:p.kind,text:x});if(o.has(p.id)&&!x.includes("\n"))cS(a)}a.splice(a.findIndex(p=>p.kind==="header")+1,0,...l);return a.map(p=>p.text).join("")}function cS(t){let e=t.length;for(let a=t.length-1;a>=0&&t[a].kind==="trivia";a--){if(t[a].text.includes("\n"))e=a;else if(t[a].text.startsWith("%%"))e=a}const r=e>0&&t[e-1].kind==="trivia"&&/^[ \t]*$/.test(t[e-1].text)?1:0;const i=t.slice(0,e-r);const n=i.map(a=>a.text).join("");const o=/^[ \t]*/.exec(n.slice(n.lastIndexOf("\n")+1))[0];const s=i.findLast(a=>a.kind!=="trivia")?.kind==="boundary-open"?" ":"";t.splice(e-r,r,{kind:"trivia",text:`
173
+ ${o}${s}`})}function ES(t){const e=MS(t);if(e)throw new Error(e);return xm(t,true)}function pa(t,e,r=false){if(typeof t!=="string")return`${e} must be text`;if(r&&!t.trim())return`${e} must not be empty`;if(/\u0000/.test(t))return`${e} cannot contain NUL`;return null}function bm(t){if(!_x.includes(t.variant))return"C4 variant must be a legacy C4 header";if(![t.elements,t.boundaries,t.relationships,t.directives,t.statements].every(Array.isArray))return"C4 collections must be arrays";const e=new Set,r=new Set(t.boundaries.map(s=>s.id));for(const s of[...t.elements,...t.boundaries]){const a=pa(s.id,"C4 alias",true)??pa(s.label,"C4 label");if(a)return a;if(e.has(s.id))return`C4 alias ${JSON.stringify(s.id)} is already declared`;e.add(s.id);if(s.parentId!==void 0&&!r.has(s.parentId))return`C4 parent ${JSON.stringify(s.parentId)} is not a boundary`;if(!Array.isArray(s.tags)||s.tags.some(l=>typeof l!=="string"||!l.trim()||l.includes("+")))return"C4 tags must be non-empty names without + separators";for(const l of["technology","description","type","link","sprite"]){const c=s[l];if(c!==void 0&&typeof c!=="string")return`C4 ${l} must be text`}}const i=new Map(t.boundaries.map(s=>[s.id,s.parentId]));const n=new Set;for(const s of t.boundaries){if(n.has(s.id))continue;const a=new Set([s.id]);let l=s.parentId;while(l!==void 0){if(a.has(l))return`C4 boundary ${JSON.stringify(s.id)} would contain itself`;if(n.has(l))break;a.add(l);l=i.get(l)}for(const c of a)n.add(c)}const o=new Set;for(const s of t.relationships){if(!e.has(s.from)||!e.has(s.to))return`C4 relationship ${s.id} references an undeclared endpoint`;if(o.has(s.id)||e.has(s.id))return`C4 relationship identity ${s.id} collides`;o.add(s.id);if(pa(s.label,"C4 relationship label"))return"C4 relationship label must be text";if(s.source!==(s.reversed?s.to:s.from)||s.target!==(s.reversed?s.from:s.to))return"C4 effective relationship endpoints do not match its authored direction"}return null}function dS(t){const e=r=>{const{args:i,statementId:n,...o}=r;return{...o,args:i.map(({name:s,value:a})=>({name:s,value:a}))}};return{variant:t.variant,title:t.title,accessibilityTitle:t.accessibilityTitle,accessibilityDescription:t.accessibilityDescription,elements:t.elements.map(e),boundaries:t.boundaries.map(e),relationships:t.relationships.map(e),directives:t.directives.map(({name:r,category:i,args:n})=>({name:r,category:i,args:n.map(({name:o,value:s})=>({name:o,value:s}))})),layout:t.layout,legend:t.legend??{visible:false,entries:[]}}}function uS(t){return JSON.stringify(t,(e,r)=>r&&typeof r==="object"&&!Array.isArray(r)?Object.fromEntries(Object.entries(r).sort(([i],[n])=>i<n?-1:i>n?1:0)):r)}function MS(t){try{const e=bm(t);if(e)return e;const r=xm(t);const i=cn(r);if(uS(dS(t))!==uS(dS(i)))return"C4 typed body does not match its serialized semantic model; use typed operations to keep source, fields and identities aligned";return null}catch(e){return`Invalid C4 body: ${e instanceof Error?e.message:String(e)}`}}function _1(t,e){if(t.macro!==void 0)return t.macro;const r=t.kind??e?.kind??"system";const i=t.shape??e?.shape??(r==="person"?"person":"rectangle");if(r==="person"&&i!=="person"||r!=="person"&&i==="person")throw new Error("C4 person shape requires person kind; database and queue shapes require a non-person kind");return r[0].toUpperCase()+r.slice(1)+(i==="database"?"Db":i==="queue"?"Queue":"")+(t.external??e?.external?"_Ext":"")}function I1(t,e){if(t.macro!==void 0)return t.macro;if(t.kind===void 0&&e)return e.macro;return{boundary:"Boundary",enterprise:"Enterprise_Boundary",system:"System_Boundary",container:"Container_Boundary",deployment:"Deployment_Node"}[t.kind??"system"]}function Cm(t,e,r,i){for(const n of r){const o=t[n];const s=e[n];if(o===void 0||o===""&&s===void 0)continue;if(JSON.stringify(o)!==JSON.stringify(s))throw new Error(`C4 ${i} cannot represent ${n} without changing its meaning`)}}function hS(t,e){const r=_1(t,e);const i={...e,...t,macro:r,tags:t.tags??e?.tags??[],style:{},args:[],statementId:""};const n=cn(`C4Context
174
+ ${SS(i)}`).elements[0];if(!n)throw new Error(`C4 ${r} is not an element macro`);if(t.macro!==void 0)for(const o of["kind","shape","external"]){if(t[o]!==void 0&&t[o]!==n[o])throw new Error(`C4 macro ${r} conflicts with ${o}`)}Cm(t,n,["id","label","technology","description","tags","link","sprite"],r);n.parentId=t.parentId??e?.parentId;return n}function mS(t,e){const r=I1(t,e);const i={...e,...t,macro:r,tags:t.tags??e?.tags??[],style:{},args:[],statementId:""};const n=cn(`C4Context
175
+ ${wS(i)}
176
+ }`).boundaries[0];if(!n)throw new Error(`C4 ${r} is not a boundary macro`);Cm(t,n,["id","label","kind","type","description","tags","link","sprite"],r);n.parentId=t.parentId??e?.parentId;return n}function fS(t,e,r){const i=t.macro??r?.macro??(t.index!==void 0?"RelIndex":"Rel");const n={...r,...t,macro:i,tags:t.tags??r?.tags??[],style:{},args:[],statementId:""};const o=[...new Set([t.from,t.to])].map(a=>`System(${kS(a)}, "endpoint")`).join("\n");const s=cn(`C4Context
177
+ ${o}
178
+ ${TS(n)}`).relationships[0];if(!s)throw new Error(`C4 ${i} is not a relationship macro`);Cm(t,s,["from","to","label","technology","description","tags","link","sprite","index"],i);s.id=r?.id??kt([...e.elements,...e.boundaries,...e.relationships].map(a=>a.id))(`c4-rel-${e.relationships.length+1}`);if(t.id!==void 0&&t.id!==s.id)throw new Error("C4 relationship IDs are allocated from authored occurrence order; arbitrary IDs cannot be represented in Mermaid source");s.order=r?.order??e.relationships.length+1;return s}function Ic(t,e,r){const i=r===void 0?-1:t.statements.findIndex(o=>o.kind==="boundary-close"&&o.entityId===r);const n=[yr(t,"trivia",void 0,"\n "),e,yr(t,"trivia",void 0,"\n")];if(i<0)t.statements.push(...n);else t.statements.splice(i,0,...n)}function pS(t,e,r){const i=t.category==="element-style"?["elementName"]:t.category==="relationship-style"||t.name.startsWith("Lay_")||t.name==="AddRelLink"?["from","to"]:t.name==="AddElementLink"?["alias"]:[];for(let n=0;n<t.args.length;n++){const o=t.args[n];if((o.name?i.includes(o.name):n<i.length)&&o.value===e)o.value=r}}function L1(t,e,r){e.parentId=r??void 0;const i=bm(t);if(i)throw new Error(i);const n=t.statements.findIndex(l=>l.id===e.statementId);const o=t.boundaries.some(l=>l.id===e.id)?t.statements.findIndex(l=>l.kind==="boundary-close"&&l.entityId===e.id):n;if(n<0||o<n)throw new Error("C4 source statement is missing");const s=t.statements.splice(n,o-n+1);const a=r===null?t.statements.length:t.statements.findIndex(l=>l.kind==="boundary-close"&&l.entityId===r);if(a<0)throw new Error("C4 parent boundary source is missing");t.statements.splice(a,0,yr(t,"trivia",void 0,"\n"),...s,yr(t,"trivia",void 0,"\n"))}function R1(t){if(!t||typeof t!=="object"||Array.isArray(t))throw new Error("C4 operation payload must be an object");return t}function Vo(t,e){R1(t);for(const[i,n]of Object.entries(t)){if(!e.includes(i))throw new Error(`Unknown C4 field ${i}`);if(n===void 0)continue;if(i==="tags"){if(!Array.isArray(n)||n.some(o=>typeof o!=="string"||!o.trim()||o.includes("+")))throw new Error("C4 tags must be an array of non-empty names without +")}else if(i==="external"){if(typeof n!=="boolean")throw new Error("C4 external must be boolean")}else if(typeof n!=="string")throw new Error(`C4 ${i} must be text`)}const r=t;if(r.shape!==void 0&&!["person","rectangle","database","queue"].includes(r.shape))throw new Error("Invalid C4 shape");return t}var gS=["id","label","macro","kind","external","shape","technology","description","parentId","tags","link","sprite"];var yS=["id","label","macro","kind","type","description","parentId","tags","link","sprite"];var xS=["id","from","to","label","macro","technology","description","tags","link","sprite","index"];function D1(t){const e=kt([...t.elements,...t.boundaries].map(n=>n.id));const r=new Set(t.relationships.map(n=>n.statementId));t.statements=t.statements.filter(n=>n.kind!=="relationship"||r.has(n.id));const i=new Map(t.statements.filter(n=>n.kind==="relationship").map(n=>[n.entityId,n]));for(const[n,o]of t.relationships.entries()){const s=i.get(o.id);o.id=e(`c4-rel-${n+1}`,["c4-relationship",n+1]);o.order=n+1;if(s)s.entityId=o.id}}function AS(t,e){try{const r=MS(t);if(r)throw new Error(r);if(t.diagnostics.some(a=>a.severity==="error"))throw new Error("C4 edits are refused while deferred statements may contain unmodeled references; source is preserved");const i=structuredClone(t);if(i.statements.length===0)i.statements=vS(i);const n=(a,l)=>{throw new Error(`C4 ${a} ${JSON.stringify(l)} was not found`)};switch(e.kind){case"add_element":{const a=hS(Vo(e.element,gS));const l=yr(i,"element",a.id);a.statementId=l.id;i.elements.push(a);Ic(i,l,a.parentId);break}case"update_element":{const a=i.elements.findIndex(u=>u.id===e.id),l=i.elements[a]??n("element",e.id);Vo(e.changes,gS.filter(u=>u!=="id"&&u!=="parentId"));const c={...l,...e.changes,macro:e.changes.macro??(e.changes.kind||e.changes.shape||e.changes.external!==void 0?void 0:l.macro)};if(e.changes.macro!==void 0){c.kind=e.changes.kind;c.shape=e.changes.shape;c.external=e.changes.external}const d=hS(c,l);d.statementId=l.statementId;i.elements[a]=d;break}case"add_boundary":{const a=mS(Vo(e.boundary,yS));const l=yr(i,"boundary-open",a.id);a.statementId=l.id;i.boundaries.push(a);Ic(i,l,a.parentId);const c=i.statements.indexOf(l);i.statements.splice(c+1,0,yr(i,"trivia",void 0,"\n"),yr(i,"boundary-close",a.id));break}case"update_boundary":{const a=i.boundaries.findIndex(u=>u.id===e.id),l=i.boundaries[a]??n("boundary",e.id);Vo(e.changes,yS.filter(u=>u!=="id"&&u!=="parentId"));const c={...l,...e.changes,macro:e.changes.macro??(e.changes.kind?void 0:l.macro)};if(e.changes.macro!==void 0)c.kind=e.changes.kind;const d=mS(c,l);d.statementId=l.statementId;i.boundaries[a]=d;break}case"rename_element":case"rename_boundary":{const a=e.kind==="rename_element"?i.elements:i.boundaries;const l=a.find(c=>c.id===e.from)??n(e.kind==="rename_element"?"element":"boundary",e.from);if(pa(e.to,"C4 alias",true))throw new Error("C4 alias must be non-empty text");l.id=e.to;for(const c of[...i.elements,...i.boundaries])if(c.parentId===e.from)c.parentId=e.to;for(const c of i.relationships){if(c.from===e.from)c.from=e.to;if(c.to===e.from)c.to=e.to;if(c.source===e.from)c.source=e.to;if(c.target===e.from)c.target=e.to}for(const c of i.directives)pS(c,e.from,e.to);for(const c of i.statements)if(c.entityId===e.from&&["element","boundary-open","boundary-close"].includes(c.kind))c.entityId=e.to;break}case"reparent_element":case"reparent_boundary":{const a=e.kind==="reparent_element"?i.elements:i.boundaries;const l=a.find(c=>c.id===e.id)??n("declaration",e.id);L1(i,l,e.parentId);break}case"remove_element":case"remove_boundary":{const a=e.kind==="remove_element"?i.elements:i.boundaries;if(!a.some(h=>h.id===e.id))n("declaration",e.id);const l=new Set([e.id]);let c=true;while(c){c=false;for(const h of[...i.boundaries,...i.elements])if(h.parentId!==void 0&&l.has(h.parentId)&&!l.has(h.id)){l.add(h.id);c=true}}const d=i.relationships.some(h=>l.has(h.from)||l.has(h.to));const u=i.directives.filter(h=>{const m=structuredClone(h);for(const f of l)pS(m,f,"\0removed");return Xl(m)!==Xl(h)});if(!e.cascade&&(l.size>1||d||u.length))throw new Error("C4 declaration has children or references; explicit cascade:true is required");i.elements=i.elements.filter(h=>!l.has(h.id));i.boundaries=i.boundaries.filter(h=>!l.has(h.id));i.relationships=i.relationships.filter(h=>!l.has(h.from)&&!l.has(h.to));i.directives=i.directives.filter(h=>!u.includes(h));break}case"add_relationship":{const a=fS(Vo(e.relationship,xS),i);const l=yr(i,"relationship",a.id);a.statementId=l.id;i.relationships.push(a);Ic(i,l);break}case"update_relationship":{const a=i.relationships.findIndex(d=>d.id===e.id),l=i.relationships[a]??n("relationship",e.id);Vo(e.changes,xS.filter(d=>d!=="id"));const c=fS({...l,...e.changes,...e.changes.index!==void 0&&e.changes.macro===void 0?{macro:"RelIndex"}:{}},i,l);c.statementId=l.statementId;i.relationships[a]=c;break}case"remove_relationship":{if(!i.relationships.some(a=>a.id===e.id))n("relationship",e.id);i.relationships=i.relationships.filter(a=>a.id!==e.id);i.directives=i.directives.filter(a=>{if(a.category!=="relationship-style"&&a.name!=="AddRelLink")return true;const l=Ku(a.args,["from","to"]);return i.relationships.some(c=>c.from===l.from&&c.to===l.to)});break}case"set_title":{if(e.title!==null&&(pa(e.title,"C4 title",true)||/[\r\n]/.test(e.title)))throw new Error("C4 title must be non-empty single-line text or null");i.title=e.title??void 0;if(!i.statements.some(a=>a.kind==="title")&&e.title!==null){const a=i.statements.findIndex(l=>l.kind==="header")+1;i.statements.splice(a,0,yr(i,"trivia",void 0,"\n"),yr(i,"title"))}break}case"set_variant":i.variant=e.variant;break;case"add_directive":case"update_directive":{const a=e.kind==="update_directive"?i.directives.find(d=>d.id===e.id)??n("directive",e.id):void 0;const l=e.kind==="add_directive"?e.name:a.name;if(!["UpdateElementStyle","UpdateRelStyle","UpdateLayoutConfig"].includes(l))throw new Error("Typed C4 directives must use UpdateElementStyle, UpdateRelStyle, or UpdateLayoutConfig supported by pinned Mermaid; reader extensions remain source-preserved");if(!Array.isArray(e.args))throw new Error("C4 directive args must be an array");const c=e.args.map(d=>{if(!d||typeof d!=="object"||typeof d.value!=="string"||d.name!==void 0&&!/^[A-Za-z_][A-Za-z_0-9]*$/.test(d.name))throw new Error("C4 directive arguments require text value and an optional parameter name");return{...d,raw:`${d.name?`$${d.name}=`:""}${Yn(d.value)}`}});if(a)a.args=c;else{const d=yr(i,"directive");const u={id:d.id,name:l,args:c,category:Dx(l),statementId:d.id};d.entityId=u.id;i.directives.push(u);Ic(i,d)}break}case"remove_directive":{if(!i.directives.some(a=>a.id===e.id))n("directive",e.id);i.directives=i.directives.filter(a=>a.id!==e.id);break}default:throw new Error(Ve("c4",e))}D1(i);Nx(i);const o=bm(i);if(o)throw new Error(o);const s=cn(xm(i,true));if(s.diagnostics.some(a=>a.severity==="error"))throw new Error(s.diagnostics.find(a=>a.severity==="error").message);return re(s)}catch(r){return T({code:"INVALID_OP",message:r instanceof Error?r.message:String(r)})}}function OS(t,e){const r=[];const i=Ke(r,e);if(t.elements.length===0&&t.boundaries.length===0)r.push({code:"EMPTY_DIAGRAM"});for(const n of[...t.elements,...t.boundaries,...t.relationships]){for(const o of[n.label,"technology"in n?n.technology:void 0,n.description])if(o)i(n.id,o)}for(const n of t.diagnostics){const o=t.statements.find(s=>s.id===n.statementId);r.push({code:"UNSUPPORTED_SYNTAX",syntax:n.syntax,line:o?.span.line,message:Px(t,n)})}return r}function BS(t,e){const r={nodes:new Map,edges:new Map,groups:new Map,labels:new Map};const i=cn(e);const n=new Map(i.statements.map(o=>[o.id,o]));for(const[o,s,a]of[[i.elements,r.nodes,"node"],[i.boundaries,r.groups,"group"],[i.relationships,r.edges,"edge"]]){for(const l of o){const c=n.get(l.statementId);s.set(l.id,{line:c.span.line,col:c.span.column});const d="from"in l?Hl(l.macro):"external"in l?Vl(l.macro):Yl(l.macro);let u=c.raw.indexOf("(")+1;for(const[h,m]of l.args.entries()){if((m.name??d[h])==="label"){const f=c.raw.slice(0,u);const p=m.name?m.raw.indexOf("=")+1:0;const g=m.raw.slice(p).match(/^\s*/)?.[0].length??0;const y=m.raw[p+g]==='"'||m.raw[p+g]==="'";const C=y?m.raw.slice(p+g+1).match(/^\s*/)?.[0].length??0:0;const w=f+m.raw.slice(0,p+g+(y?1+C:0));const x=w.split(/\r\n?|\n/);r.labels.set(`${a}:${l.id}`,{line:c.span.line+x.length-1,col:x.length===1?c.span.column+w.length:x.at(-1).length+1});break}u+=m.raw.length+1}}}return r}import{decodeXML as $_}from"entities";var N1=new Set(["L","R","T","B"]);function Dc(t){return t.split(/\r?\n/).map(e=>e.trim()).filter(Boolean).join(" ")}function km(t){return t.split(/\r?\n/).map(e=>e.trim()).filter(Boolean).join("\n")}function DS(t,e={},r=t){let i;let n=e.title;let o=e.descr;const s=[];const a=[];const l=[];const c=[];const d=[];const u=new Set;const h=new Set;const m=new Set;for(const f of Jl(r)){if(f.kind==="invalid")return null;if(f.kind==="blank"||f.kind==="comment")continue;if(f.kind==="accessibility"){if(f.directive.title)n=f.directive.value;else o=f.directive.value;continue}if(f.kind==="title"){if(i!==void 0)return null;i=Dc(f.value);if(!i)return null;continue}if(f.kind==="group"){const p=f.declaration;const{id:g,icon:y,parentId:C}=p;if(qs(g)||y&&Kl(y))return null;if(u.has(g)||C&&!h.has(C))return null;u.add(g);h.add(g);const w=km(p.title);s.push({id:g,label:w,icon:y,parentId:C});continue}if(f.kind==="service"){const p=f.declaration;const{id:g,icon:y,iconText:C,parentId:w}=p;if(qs(g)||y&&Kl(y))return null;if(u.has(g)||w&&!h.has(w))return null;u.add(g);m.add(g);const x=km(p.title);a.push({id:g,label:x,icon:y,...C!==void 0?{iconText:C}:{},parentId:w});continue}if(f.kind==="junction"){const{id:p,parentId:g}=f;if(qs(p))return null;if(u.has(p)||g&&!h.has(g))return null;u.add(p);m.add(p);l.push({id:p,parentId:g});continue}if(f.kind==="align"){if(f.alignment.members.some(p=>!m.has(p)))return null;d.push(f.alignment);continue}if(f.kind==="edge"){const{edge:p}=f;if(!m.has(p.source.id)||!m.has(p.target.id))return null;const g=p.label===void 0?void 0:km(p.label);if(g&&(g.includes("[")||g.includes("]")))return null;const y=C=>({id:C.id,side:C.side,...C.boundary==="group"?{boundary:"group"}:{}});c.push({source:y(p.source),target:y(p.target),label:g,hasArrowStart:p.hasArrowStart,hasArrowEnd:p.hasArrowEnd});continue}return null}for(const f of c){if(!m.has(f.source.id)||!m.has(f.target.id))return null;for(const p of[f.source,f.target]){if(p.boundary!=="group")continue;const g=a.find(y=>y.id===p.id);if(!g?.parentId)return null}}for(const f of d){for(const p of f.members){if(!m.has(p))return null}}return{kind:"architecture",title:i,accessibilityTitle:n,accessibilityDescription:o,groups:s,services:a,junctions:l,edges:c,alignments:d}}function _S(t,e,r,i,n,o){const s=o!==void 0?` ${Gx(o)} `:i?`(${i})`:"";const a=`[${Ju(r)}]`;const l=n?` in ${n}`:"";return` ${t} ${e}${s}${a}${l}`}function P1(t){if(t.label!==void 0){return`${t.hasArrowStart?"<":""}-[${Ju(t.label)}]-${t.hasArrowEnd?">":""}`}if(t.hasArrowStart&&t.hasArrowEnd)return"<-->";if(t.hasArrowEnd)return"-->";if(t.hasArrowStart)return"<--";return"--"}function NS(t){const e=["architecture-beta"];if(t.title!==void 0)e.push(` title ${t.title}`);Lt(e,t);for(const r of t.groups)e.push(_S("group",r.id,r.label,r.icon,r.parentId));for(const r of t.services)e.push(_S("service",r.id,r.label,r.icon,r.parentId,r.iconText));for(const r of t.junctions){e.push(` junction ${r.id}${r.parentId?` in ${r.parentId}`:""}`)}for(const r of t.edges){const i=r.source.boundary==="group"?"{group}":"";const n=r.target.boundary==="group"?"{group}":"";e.push(` ${r.source.id}${i}:${r.source.side} ${P1(r)} ${r.target.side}:${r.target.id}${n}`)}for(const r of t.alignments??[]){e.push(` ${$x(r)}`)}return e.join("\n")+"\n"}function F1(t){return{kind:"architecture",title:t.title,accessibilityTitle:t.accessibilityTitle,accessibilityDescription:t.accessibilityDescription,groups:t.groups.map(e=>({...e})),services:t.services.map(e=>({...e})),junctions:t.junctions.map(e=>({...e})),edges:t.edges.map(e=>({source:{...e.source},target:{...e.target},label:e.label,hasArrowStart:e.hasArrowStart,hasArrowEnd:e.hasArrowEnd})),...t.alignments?{alignments:t.alignments.map(e=>({axis:e.axis,members:[...e.members]}))}:{}}}function IS(t,e){if(!t.alignments)return;t.alignments=t.alignments.map(r=>({axis:r.axis,members:r.members.filter(i=>i!==e)})).filter(r=>r.members.length>=2)}function LS(t,e,r){if(!t.alignments)return;for(const i of t.alignments){i.members=i.members.map(n=>n===e?r:n)}}function ga(t){const e=new Set;for(const r of t.groups)e.add(r.id);for(const r of t.services)e.add(r.id);for(const r of t.junctions)e.add(r.id);return e}function Gt(t,e){const r=typeof t==="string"?qs(t):void 0;if(typeof t!=="string"||r){return T({code:"INVALID_OP",message:r?.message??`Architecture ${e} must be a string, got ${JSON.stringify(t)}`})}return re(t)}function Sm(t,e){if(t===void 0||t===null)return re(void 0);const r=typeof t==="string"?t.trim():void 0;if(r===void 0||r!==""&&Kl(r)){return T({code:"INVALID_OP",message:`Architecture ${e} must be letters, digits, _, - and :, got ${JSON.stringify(t)}`})}return re(r||void 0)}function Yo(t,e){if(typeof t!=="string")return T({code:"INVALID_OP",message:`Architecture ${e} must be a string`});const r=Dc(t);if(!r||r.includes("[")||r.includes("]")){return T({code:"INVALID_OP",message:`Architecture ${e} must be non-empty and must not contain [ or ]`})}if(r.includes("\\")){return T({code:"INVALID_OP",message:`Architecture ${e} must not contain a backslash`})}return re(r)}function Lc(t){return typeof t==="string"&&N1.has(t)}function RS(t,e,r){if(typeof t!=="string")return T({code:"INVALID_OP",message:`Architecture ${e} must be a string or null`});const i=r?t.split(/\r?\n/).map(n=>n.trim()).filter(Boolean).join("\n"):Dc(t);if(!i||i.includes("}")){return T({code:"INVALID_OP",message:`Architecture ${e} must be non-empty and must not contain }`})}return re(i)}function Rc(t,e,r){const i=t.services.find(o=>o.id===e);const n=t.junctions.find(o=>o.id===e);if(!i&&!n)return T({code:"SERVICE_NOT_FOUND",message:`No service/junction "${e}"`});if(r==="group"&&!i?.parentId){return T({code:"INVALID_OP",message:i?`Service "${e}" is not inside a group, so boundary "group" is invalid`:`Architecture group boundaries apply only to services; "${e}" is a junction`})}return re(void 0)}function wm(t){return`${t.source.id}->${t.target.id}`}function PS(t,e){const r=F1(t);switch(e.kind){case"set_title":{if(e.title===null){r.title=void 0}else{const i=Dc(e.title);if(!i)return T({code:"INVALID_OP",message:"Architecture title must be a non-empty string or null"});r.title=i}break}case"set_accessibility_title":{const i=gt(r,"accessibilityTitle",e.title,n=>RS(n,"accessibility title",false));if(!i.ok)return i;break}case"set_accessibility_description":{const i=gt(r,"accessibilityDescription",e.description,n=>RS(n,"accessibility description",true));if(!i.ok)return i;break}case"add_service":{const i=Gt(e.id,"service id");if(!i.ok)return i;if(ga(r).has(i.value))return T({code:"INVALID_OP",message:`Identifier "${i.value}" already exists`});const n=Yo(e.label??i.value,"service label");if(!n.ok)return n;const o=Sm(e.icon,"service icon");if(!o.ok)return o;const s=o.value;if(e.iconText!==void 0&&e.iconText!==null&&typeof e.iconText!=="string")return T({code:"INVALID_OP",message:"Architecture iconText must be a string or null"});const a=e.iconText??void 0;if(s&&a!==void 0)return T({code:"INVALID_OP",message:"Choose an Architecture icon name or iconText, not both"});if(e.group!==void 0&&e.group!==null){const l=Gt(e.group,"group id");if(!l.ok)return l;if(!r.groups.some(c=>c.id===l.value))return T({code:"GROUP_NOT_FOUND",message:`No group "${l.value}"`});r.services.push({id:i.value,label:n.value,icon:s,...a!==void 0?{iconText:a}:{},parentId:l.value})}else{r.services.push({id:i.value,label:n.value,icon:s,...a!==void 0?{iconText:a}:{}})}break}case"remove_service":{const i=r.services.findIndex(n=>n.id===e.id);if(i<0)return T({code:"SERVICE_NOT_FOUND",message:`No service "${e.id}"`});r.services.splice(i,1);r.edges=r.edges.filter(n=>n.source.id!==e.id&&n.target.id!==e.id);IS(r,e.id);break}case"rename_service":{const i=Gt(e.from,"service id");if(!i.ok)return i;const n=Gt(e.to,"service id");if(!n.ok)return n;const o=r.services.find(s=>s.id===i.value);if(!o)return T({code:"SERVICE_NOT_FOUND",message:`No service "${i.value}"`});if(i.value!==n.value&&ga(r).has(n.value)){return T({code:"INVALID_OP",message:`Identifier "${n.value}" already exists`})}o.id=n.value;for(const s of r.edges){if(s.source.id===i.value)s.source.id=n.value;if(s.target.id===i.value)s.target.id=n.value}LS(r,i.value,n.value);break}case"set_service_label":{const i=r.services.find(o=>o.id===e.id);if(!i)return T({code:"SERVICE_NOT_FOUND",message:`No service "${e.id}"`});const n=Yo(e.label,"service label");if(!n.ok)return n;i.label=n.value;break}case"set_service_icon":{const i=r.services.find(o=>o.id===e.id);if(!i)return T({code:"SERVICE_NOT_FOUND",message:`No service "${e.id}"`});if(e.icon===null){delete i.icon;delete i.iconText;break}const n=Sm(e.icon,"service icon");if(!n.ok)return n;if(!n.value)return T({code:"INVALID_OP",message:"Architecture service icon must be non-empty (use null to clear)"});i.icon=n.value;delete i.iconText;break}case"set_service_icon_text":{const i=r.services.find(n=>n.id===e.id);if(!i)return T({code:"SERVICE_NOT_FOUND",message:`No service "${e.id}"`});if(e.text===null){delete i.iconText;break}if(typeof e.text!=="string")return T({code:"INVALID_OP",message:"Architecture icon text must be a string or null"});i.iconText=e.text;delete i.icon;break}case"move_service":{const i=r.services.find(o=>o.id===e.id);if(!i)return T({code:"SERVICE_NOT_FOUND",message:`No service "${e.id}"`});if(e.group===null){const o=r.edges.find(s=>s.source.id===e.id&&s.source.boundary==="group"||s.target.id===e.id&&s.target.boundary==="group");if(o){return T({code:"INVALID_OP",message:`Service "${e.id}" has a group-boundary edge; update the edge boundary to "item" before moving it to root`})}delete i.parentId;break}const n=Gt(e.group,"group id");if(!n.ok)return n;if(!r.groups.some(o=>o.id===n.value))return T({code:"GROUP_NOT_FOUND",message:`No group "${n.value}"`});i.parentId=n.value;break}case"add_junction":{const i=Gt(e.id,"junction id");if(!i.ok)return i;if(ga(r).has(i.value))return T({code:"INVALID_OP",message:`Identifier "${i.value}" already exists`});let n;if(e.group!==void 0&&e.group!==null){const o=Gt(e.group,"group id");if(!o.ok)return o;if(!r.groups.some(s=>s.id===o.value))return T({code:"GROUP_NOT_FOUND",message:`No group "${o.value}"`});n=o.value}r.junctions.push({id:i.value,parentId:n});break}case"remove_junction":{const i=r.junctions.findIndex(n=>n.id===e.id);if(i<0)return T({code:"SERVICE_NOT_FOUND",message:`No junction "${e.id}"`});r.junctions.splice(i,1);r.edges=r.edges.filter(n=>n.source.id!==e.id&&n.target.id!==e.id);IS(r,e.id);break}case"rename_junction":{const i=Gt(e.from,"junction id");if(!i.ok)return i;const n=Gt(e.to,"junction id");if(!n.ok)return n;const o=r.junctions.find(s=>s.id===i.value);if(!o)return T({code:"SERVICE_NOT_FOUND",message:`No junction "${i.value}"`});if(i.value!==n.value&&ga(r).has(n.value))return T({code:"INVALID_OP",message:`Identifier "${n.value}" already exists`});o.id=n.value;for(const s of r.edges){if(s.source.id===i.value)s.source.id=n.value;if(s.target.id===i.value)s.target.id=n.value}LS(r,i.value,n.value);break}case"move_junction":{const i=r.junctions.find(o=>o.id===e.id);if(!i)return T({code:"SERVICE_NOT_FOUND",message:`No junction "${e.id}"`});if(e.group===null){delete i.parentId;break}const n=Gt(e.group,"group id");if(!n.ok)return n;if(!r.groups.some(o=>o.id===n.value))return T({code:"GROUP_NOT_FOUND",message:`No group "${n.value}"`});i.parentId=n.value;break}case"add_group":{const i=Gt(e.id,"group id");if(!i.ok)return i;if(ga(r).has(i.value))return T({code:"INVALID_OP",message:`Identifier "${i.value}" already exists`});const n=Yo(e.label??i.value,"group label");if(!n.ok)return n;const o=Sm(e.icon,"group icon");if(!o.ok)return o;const s=o.value;let a;if(e.parent!==void 0&&e.parent!==null){const l=Gt(e.parent,"group id");if(!l.ok)return l;if(!r.groups.some(c=>c.id===l.value))return T({code:"GROUP_NOT_FOUND",message:`No group "${l.value}"`});a=l.value}r.groups.push({id:i.value,label:n.value,icon:s,parentId:a});break}case"set_group_label":{const i=r.groups.find(o=>o.id===e.id);if(!i)return T({code:"GROUP_NOT_FOUND",message:`No group "${e.id}"`});const n=Yo(e.label,"group label");if(!n.ok)return n;i.label=n.value;break}case"remove_group":{const i=r.groups.findIndex(o=>o.id===e.id);if(i<0)return T({code:"GROUP_NOT_FOUND",message:`No group "${e.id}"`});const n=r.services.some(o=>o.parentId===e.id)||r.junctions.some(o=>o.parentId===e.id)||r.groups.some(o=>o.parentId===e.id);if(n)return T({code:"INVALID_OP",message:`Group "${e.id}" is not empty; move or remove its members first`});r.groups.splice(i,1);break}case"add_edge":{const i=Gt(e.from,"service id");if(!i.ok)return i;const n=Gt(e.to,"service id");if(!n.ok)return n;if(!Lc(e.fromSide))return T({code:"INVALID_OP",message:`fromSide must be one of L|R|T|B, got ${JSON.stringify(e.fromSide)}`});if(!Lc(e.toSide))return T({code:"INVALID_OP",message:`toSide must be one of L|R|T|B, got ${JSON.stringify(e.toSide)}`});const o=e.fromBoundary??"item";const s=e.toBoundary??"item";const a=Rc(r,i.value,o);if(!a.ok)return a;const l=Rc(r,n.value,s);if(!l.ok)return l;let c;if(e.label!==void 0&&e.label!==null){const d=Yo(e.label,"edge label");if(!d.ok)return d;c=d.value}r.edges.push({source:{id:i.value,side:e.fromSide,...o==="group"?{boundary:"group"}:{}},target:{id:n.value,side:e.toSide,...s==="group"?{boundary:"group"}:{}},label:c,hasArrowStart:e.hasArrowStart??false,hasArrowEnd:e.hasArrowEnd??true});break}case"update_edge":{if(!Number.isInteger(e.index)||e.index<0||!r.edges[e.index]){return T({code:"EDGE_NOT_FOUND",message:`No edge at index ${e.index}`})}const i=r.edges[e.index];if(e.from!==void 0){const s=Gt(e.from,"service id");if(!s.ok)return s;i.source.id=s.value}if(e.to!==void 0){const s=Gt(e.to,"service id");if(!s.ok)return s;i.target.id=s.value}if(e.fromSide!==void 0){if(!Lc(e.fromSide))return T({code:"INVALID_OP",message:`fromSide must be one of L|R|T|B, got ${JSON.stringify(e.fromSide)}`});i.source.side=e.fromSide}if(e.toSide!==void 0){if(!Lc(e.toSide))return T({code:"INVALID_OP",message:`toSide must be one of L|R|T|B, got ${JSON.stringify(e.toSide)}`});i.target.side=e.toSide}if(e.fromBoundary!==void 0){if(e.fromBoundary==="group")i.source.boundary="group";else delete i.source.boundary}if(e.toBoundary!==void 0){if(e.toBoundary==="group")i.target.boundary="group";else delete i.target.boundary}const n=Rc(r,i.source.id,i.source.boundary);if(!n.ok)return n;const o=Rc(r,i.target.id,i.target.boundary);if(!o.ok)return o;if("label"in e){if(e.label===null||e.label===void 0)delete i.label;else{const s=Yo(e.label,"edge label");if(!s.ok)return s;i.label=s.value}}if(e.hasArrowStart!==void 0)i.hasArrowStart=e.hasArrowStart;if(e.hasArrowEnd!==void 0)i.hasArrowEnd=e.hasArrowEnd;break}case"remove_edge":{if(typeof e.index==="number"){if(!r.edges[e.index])return T({code:"EDGE_NOT_FOUND",message:`No edge at index ${e.index}`});r.edges.splice(e.index,1)}else if(typeof e.id==="string"){const i=r.edges.findIndex(n=>wm(n)===e.id);if(i<0)return T({code:"EDGE_NOT_FOUND",message:`No edge "${e.id}"`});r.edges.splice(i,1)}else{return T({code:"INVALID_OP",message:"remove_edge requires index (number) or id (from->to)"})}break}default:{const i=e;return T({code:"INVALID_OP",message:Ve("architecture",i)})}}return re(r)}var $1=new Set(["cloud","database","disk","internet","server"]);function FS(t,e){return e&&!$1.has(e.trim().toLowerCase())&&ph(e)===null?{code:"UNKNOWN_SHAPE",node:t,shape:`architecture-icon:${e}`}:null}var q1={id:"avoid architecture keywords and prefixes L, R, T, B or title, and keep dashes only inside the id",icon:"name an icon with letters, digits, _, - and : only",title:"put the whole title in double quotes"};function r2(t){const e=t.split(/\r?\n/);const r=e.findIndex(o=>/^architecture(?:-beta)?\b/i.test(o.trim()));if(r<0)return[];const i=[];const n=qx(e);for(let o=r+1;o<e.length;o++){const s=ct(e,o);if(s===void 0)break;if(s!==null){o=s.endIndex;continue}const a=o;o=n[o];for(const{terminal:l,what:c}of Wx(To(e,a,o))){i.push({code:"UNSUPPORTED_SYNTAX",syntax:`architecture_${l}`,line:a+1,message:`${c}. Pinned Mermaid rejects this; ${q1[l]}.`})}}return i}function $S(t){const e=[];for(const r of t.split(/\r?\n/)){const i=r.trim().match(/^(?:service|group)\s+([A-Za-z_][\w-]*)\s*\(([^)]+)\)/i);if(!i)continue;const n=FS(i[1],i[2].trim());if(n)e.push(n)}return e}function qS(t,e){const r=[];const i=Ke(r,e);if(t.groups.length===0&&t.services.length===0&&t.junctions.length===0&&t.title===void 0&&t.accessibilityTitle===void 0&&t.accessibilityDescription===void 0){r.push({code:"EMPTY_DIAGRAM"})}if(t.title!==void 0)i("title",t.title);if(t.accessibilityTitle!==void 0)i("accessibility-title",t.accessibilityTitle);if(t.accessibilityDescription!==void 0)i("accessibility-description",t.accessibilityDescription);const n=(o,s)=>{const a=FS(o,s);if(a)r.push(a)};for(const o of t.groups){i(o.id,o.label);n(o.id,o.icon)}for(const o of t.services){i(o.id,o.label);n(o.id,o.icon)}t.edges.forEach((o,s)=>{const a=new Set([...t.services.map(l=>l.id),...t.junctions.map(l=>l.id)]);if(!a.has(o.source.id)||!a.has(o.target.id)){r.push({code:"EDGE_MISANCHORED",edge:`edge#${s}:${wm(o)}`,from:a.has(o.source.id)?o.source.id:void 0,to:a.has(o.target.id)?o.target.id:void 0})}if(o.label!==void 0)i(`edge#${s}:${wm(o)}`,o.label)});return r}import{decodeXML as xa}from"entities";function ya(t,e){const r=[...e].sort((l,c)=>l.start-c.start||l.end-c.end);let i=0,n=-1,o=t.length;for(const l of r){if(!Number.isInteger(l.start)||!Number.isInteger(l.end)||l.start<0||l.end<l.start||l.end>t.length||typeof l.text!=="string"||l.start<i||l.start===n)throw new RangeError("Source edit plan has invalid, overlapping or ambiguous boundaries");o+=l.text.length-(l.end-l.start);i=l.end;n=l.start}vl("sourceCharacters",o);const s=[];let a=0;for(const l of r){s.push(t.slice(a,l.start),l.text);a=l.end}s.push(t.slice(a));return s.join("")}function Nc(t,e){const r=t.includes("\r\n")?"\r\n":"\n";return[{start:t.length,end:t.length,text:(/[\r\n]$/.test(t)?"":r)+e.replace(/\r?\n/g,r)+r}]}function Ni(t,e){if(Object.is(t,e))return true;if(t===null||e===null||typeof t!=="object"||typeof e!=="object")return false;if(t instanceof Map||e instanceof Map){return t instanceof Map&&e instanceof Map&&Ni([...t],[...e])}if(Array.isArray(t)||Array.isArray(e)){return Array.isArray(t)&&Array.isArray(e)&&t.length===e.length&&t.every((o,s)=>Ni(o,e[s]))}if([t,e].some(o=>![null,Object.prototype].includes(Object.getPrototypeOf(o))))return false;const r=t,i=e;const n=Object.keys(r).filter(o=>r[o]!==void 0);return n.length===Object.keys(i).filter(o=>i[o]!==void 0).length&&n.every(o=>Object.hasOwn(i,o)&&Ni(r[o],i[o]))}function Pc(t,e,r){Object.defineProperty(t,e,{value:r,enumerable:true,writable:true,configurable:true})}function Ho(t,e=false){return e?/^\w+$/.test(t)&&t!=="call"&&Oo(t,false,true):(/^\w+$/.test(t)||t==="-")&&Oo(t,false,false)}function YS(t){return/^\w+$/.test(t)&&t!=="accTitle"&&t!=="accDescr"&&(t==="style"||Oo(t,false,true))}function Xo(t,e){const r=_r(t,e);return r&&Object.keys(r).length?r:void 0}function zS(t,e,r){return Mo(t,e,!YS(r?.[0]?.[0]??Object.keys(e)[0]??""),r)}function Fc(t){return/^\w+$/.test(t)&&t!=="call"&&Oo(t,false,true)}function Am(t){if(/[{}]/.test(t)&&dn(t))return`Class member ${JSON.stringify(t)} requires inline syntax, where a greedy Mermaid direction token consumes it; no supported spelling preserves its authored string`;if(Gs(t)!==null)return;const e=t.indexOf("(");if(e<0||!t.includes(")",e))return;const r=t.slice(0,e);const i=/<[A-Za-z!/?]/;if(/<[A-Za-z!/?][^>]*$/.test(r)||i.test(r)&&r.replace(/<[^>]*>/g,"").replace(/^[#+~-]/,"").trim()===""){return`Class member ${JSON.stringify(t)} loses its method name in Mermaid's HTML sanitization and has no supported spelling that preserves its authored string`}}function Om(t){for(const e of t.classes){if(e.label==="")return"An explicitly empty Class label has no lossless Mermaid spelling; retain the source without typed editing";if(dn(e.id)||e.namespace!==void 0&&dn(e.namespace))return"A Class identity containing a greedy direction token has no lossless Mermaid spelling";if(e.style&&!Fc(e.id))return`Class inline style target ${JSON.stringify(e.id)} is not an ALPHA identifier in Mermaid's style grammar`;if(e.style&&!Xo(e.style,e.styleDeclarations))return`Class style on ${JSON.stringify(e.id)} has no supported lossless Mermaid property/value spelling`;if(e.id.startsWith('"'))return`Class id ${JSON.stringify(e.id)} starts with a double quote and has no supported lossless Mermaid spelling`;for(const r of e.className?.split(/\s+/).filter(Boolean)??[]){if(!Ho(r))return`Class style reference ${JSON.stringify(r)} has no supported lossless Mermaid spelling`}for(const r of e.members){const i=Am(r);if(i)return i}}if(t.namespaces?.some(e=>e.label===""))return"An explicitly empty Class namespace label has no lossless Mermaid spelling; retain the source without typed editing";if(t.namespaces?.some(e=>JS(e.name.split("."))))return"A leading tilde in a Class namespace path segment opens a generic token even inside backticks and has no lossless Mermaid spelling";if(t.namespaces?.some(e=>dn(e.name)))return"A Class namespace identity containing a greedy direction token has no lossless Mermaid spelling";if(Object.keys(t.classDefDeclarations??{}).some(e=>!Object.hasOwn(t.classDefs??{},e)))return"Ordered Class declarations require a matching property record";for(const e of t.classes)if(e.styleDeclarations&&!e.style)return"Ordered Class declarations require a matching property record";for(const[e,r]of Object.entries(t.classDefs??{})){if(!Ho(e,true))return`Class style definition ${JSON.stringify(e)} has no supported lossless Mermaid spelling`;if(!Xo(r,nn(t.classDefDeclarations,e)))return`Class style definition ${JSON.stringify(e)} has no supported lossless Mermaid property/value spelling`}}function HS(t){return{from:t.from,to:t.to,kind:t.type,...t.label?{label:t.label}:{},...t.labelContent?{labelContent:t.labelContent}:{},...t.fromCardinality?{fromCardinality:t.fromCardinality}:{},...t.toCardinality?{toCardinality:t.toCardinality}:{},...t.fromCardinalityContent?{fromCardinalityContent:t.fromCardinalityContent}:{},...t.toCardinalityContent?{toCardinalityContent:t.toCardinalityContent}:{},markerAt:t.markerAt,...t.fromType?{fromKind:t.fromType}:{},...t.toType?{toKind:t.toType}:{},...t.lineStyle?{lineStyle:t.lineStyle}:{},...t.fromGeneric?{fromGeneric:t.fromGeneric}:{},...t.toGeneric?{toGeneric:t.toGeneric}:{}}}function z1(t){const e=eh(t);return e?HS(e):null}function $c(t){const e=Ai(t);if(e.diagnostics.length>0)return null;const r={kind:"class",classes:[],relations:[],notes:[]};const i=new Map;const n=jx(e.statements);const o=[];const s=(u,h,m)=>{let f=i.get(u);if(!f){f={id:u,...h!==void 0?Ao(h,false):{label:h},generic:m,members:[]};i.set(u,f);r.classes.push(f)}else{if(h!==void 0){delete f.labelContent;Object.assign(f,Ao(h,false))}if(m!==void 0&&!f.generic)f.generic=m}return f};const a=[];const l=(u,h)=>{if(h&&u.namespace!==void 0&&u.namespace!==h)return false;if(h&&u.namespace===void 0)u.namespace=h;return true};const c=(u,h)=>{if(u.members.some(m=>Gs(m)!==null))return false;u.members.push(`<<${h}>>`);return true};const d=(u,h="",m)=>{const f=[{nodes:u,path:h,owner:m,index:0}];while(f.length){const p=f.at(-1);if(p.index===p.nodes.length){f.pop();continue}const g=p.nodes[p.index++];const{path:y,owner:C}=p;const w=g.value;switch(w.kind){case"header":case"trivia":case"close":break;case"direction":case"unknown":case"source-only":return false;case"namespace":{if(w.path.some(b=>b.includes(".")))return false;const x=[y,...w.path].filter(Boolean).join(".");let k=a.find(b=>b.name===x);if(!k){k={name:x,...w.label!==void 0?Ao(w.label,false):{}};a.push(k)}else if(w.label!==void 0){delete k.labelContent;Object.assign(k,Ao(w.label,false))}f.push({nodes:g.children,path:x,owner:void 0,index:0});break}case"class":{const x=w.declaration;const k=s(x.id,x.label,x.generic);if(x.className!==void 0)k.className=x.className;if(x.annotation!==void 0&&!c(k,x.annotation))return false;if(!l(k,y))return false;if(g.children)f.push({nodes:g.children,path:y,owner:k,index:0});break}case"member":{const x=w.reference?s(w.reference.id,void 0,w.reference.generic):C;x.members.push(w.text);break}case"body-annotation":if(!c(C,w.text))return false;break;case"annotation":{const x=w.annotation;if(x.placement==="separate"&&!i.has(x.id))return false;const k=s(x.id,x.label,x.generic);if(x.className!==void 0)k.className=x.className;if(!c(k,x.annotation))return false;if(!l(k,y))return false;break}case"interaction":{const x=s(w.interaction.id,void 0,w.interaction.generic);x.href=w.interaction.href;if(w.interaction.tooltip!==void 0)x.tooltip=w.interaction.tooltip;if(!l(x,y))return false;break}case"note":if(/[\r\n]/.test(w.text))return false;if(w.reference)s(w.reference.id,void 0,w.reference.generic);{const{label:x,labelContent:k}=Ao(w.text,false);r.notes.push({text:x,for:w.reference?.id,...k?{textContent:k}:{}})}break;case"title":r.title=w.text;break;case"relationship":{const x=HS(w.relationship);const k=Ux(w.relationship);if(k){const B=k==="from"?x.fromGeneric:x.toGeneric;const O=x[k]+(B?`~${B}~`:"");const M=n();const E=k==="from"?"to":"from";s(x[E],void 0,E==="from"?x.fromGeneric:x.toGeneric);const _={id:M,label:O,...B?{generic:B}:{},isInterface:true,members:[]};i.set(M,_);r.classes.push(_);x[k]=M}else{s(x.from,void 0,x.fromGeneric);s(x.to,void 0,x.toGeneric)}const{fromGeneric:b,toGeneric:A,...L}=x;r.relations.push(L);break}case"classDef":{const x=Xo(w.props,w.declarations);if(!x)return false;r.classDefs??={};for(const k of w.names){const b=Bn([...nn(r.classDefDeclarations,k)??Object.entries(r.classDefs[k]??{}),...w.declarations]);Pc(r.classDefs,k,_n(b));const A=ii(b);if(A){r.classDefDeclarations??={};Pc(r.classDefDeclarations,k,A)}}break}case"assignment":case"style":for(const x of w.references){if(w.kind==="assignment"&&w.form.startsWith("cssClass")){const b=i.get(x.id);if(b)b.className=w.name;else o.push({id:x.id,name:w.name});continue}const k=s(x.id,void 0,x.generic);if(w.kind==="assignment")k.className=w.name;else{const b=Xo(w.props,w.declarations);if(!b)return false;const A=Bn([...k.styleDeclarations??Object.entries(k.style??{}),...w.declarations]);k.style=_n(A);k.styleDeclarations=ii(A);if(!k.styleDeclarations)delete k.styleDeclarations}if(!l(k,y))return false}break}}return true};if(!d(e.statements))return null;for(const{id:u,name:h}of o){const m=i.get(u);if(m&&m.className===void 0)m.className=h}if(a.length>0)r.namespaces=a;if(Om(r))return null;if(a.some(u=>!XS(r,u.name)))return null;r.classes=r.classes.filter(u=>!u.isInterface).concat(r.classes.filter(u=>u.isInterface));return r}function XS(t,e){return t.classes.some(r=>r.namespace===e||r.namespace?.startsWith(`${e}.`))}function Tm(t){const e=(t.namespaces??[]).filter(i=>!XS(t,i.name));const r=e.find(i=>i.label!==void 0);if(r)return T({code:"INVALID_OP",message:`Cannot empty labeled namespace "${r.name}" without losing its label; keep a class in the group or edit the source explicitly`});if(t.namespaces){t.namespaces=t.namespaces.filter(i=>!e.includes(i));if(t.namespaces.length===0)delete t.namespaces}return re(t)}var Pi={inheritance:{from:"<|",to:"|>",shaft:"--",defaultMarkerAt:"from"},composition:{from:"*",to:"*",shaft:"--",defaultMarkerAt:"from"},aggregation:{from:"o",to:"o",shaft:"--",defaultMarkerAt:"from"},association:{from:"<",to:">",shaft:"--",defaultMarkerAt:"to"},dependency:{from:"<",to:">",shaft:"..",defaultMarkerAt:"to"},realization:{from:"<|",to:"|>",shaft:"..",defaultMarkerAt:"to"},"link-solid":{from:"",to:"",shaft:"--",defaultMarkerAt:"none"},"link-dashed":{from:"",to:"",shaft:"..",defaultMarkerAt:"none"},lollipop:{from:"()",to:"()",shaft:"--",defaultMarkerAt:"from"}};function ba(t){const e=t.markerAt??Pi[t.kind].defaultMarkerAt;return{at:e,...e==="from"||e==="both"?{from:t.fromKind??t.kind}:{},...e==="to"||e==="both"?{to:t.toKind??t.kind}:{}}}function vm(t){if(t.lineStyle!==void 0)return t.lineStyle;const e=ba(t);const r=e.from&&Pi[e.from];const i=e.to&&Pi[e.to];const n=r?.shaft===".."||i?.shaft===".."||!r&&!i&&Pi[t.kind].shaft==="..";return n?"dashed":"solid"}function KS(t){const e=ba(t);const r=e.from&&Pi[e.from];const i=e.to&&Pi[e.to];return`${r?.from??""}${vm(t)==="dashed"?"..":"--"}${i?.to??""}`}function cr(t){if(/^[\w$]+$/.test(t)&&t!=="call"&&Zx(t,t)){const e=`${t} -- __endpoint`;const r=Ai([t,e]).statements;if(ct([e],0)===null&&r[0]?.value.kind!=="header"&&r[1]?.value.kind==="relationship")return t}return`\`${t}\``}function Em(t){return/^[\w$]+$/.test(t)?t:`\`${t}\``}function JS(t){return t.some(e=>Em(e).startsWith("`~"))}function GS(t,e,r,i){if(e.isInterface)return;const n=`class ${cr(e.id)}${e.generic?`~${e.generic}~`:""}${e.label?`["${Mi(e.label,e.labelContent)}"]`:""}`;if(e.members.length===0){t.push(`${r}${n}`)}else if(e.members.some(o=>/[{}]/.test(o))){t.push(`${r}${n}`);let o=[];const s=()=>{if(o.length===0)return;i.push(` class ${cr(e.id)} {`,...o.map(a=>` ${a}`)," }");o=[]};for(const a of e.members){if(/[{}]/.test(a)){s();i.push(` ${cr(e.id)} : ${a}`)}else o.push(a)}s()}else{t.push(`${r}${n} {`);for(const o of e.members)t.push(`${r} ${o}`);t.push(`${r}}`)}}function qc(t){const e=Om(t);if(e)throw new Error(e);const r=["classDiagram"];const i=[];if(t.title)r.push(` title ${t.title}`);const n=t.namespaces??[];const o=n.map(u=>u.name);const s=[];for(const u of n){const h=u.label!==void 0&&!t.classes.some(f=>f.namespace===u.name);const m=h?s.findIndex(f=>f.name.startsWith(`${u.name}.`)):-1;if(m<0)s.push(u);else s.splice(m,0,u)}const a=[{entries:s,index:0,prefix:"",depth:1,closes:0}];while(a.length>0){const u=a.at(-1);if(u.index===u.entries.length){for(let C=u.closes;C>0;C--)r.push(`${" ".repeat(u.depth-u.closes+C-1)}}`);a.pop();continue}const h=u.entries[u.index++];const m=t.classes.filter(C=>C.namespace===h.name);if(m.length===0&&h.label===void 0&&o.some(C=>C.startsWith(`${h.name}.`)))continue;const f=m.length===0&&h.label!==void 0?u.entries.filter(C=>C.name.startsWith(`${h.name}.`)):[];const p=h.name.slice(u.prefix.length);const g=p.split(".");const y=g.every(C=>/^[\w$]+$/.test(C))?1:g.length;if(g.every(C=>/^[\w$]+$/.test(C))){r.push(`${" ".repeat(u.depth)}namespace ${p}${h.label!==void 0?`["${Mi(h.label,h.labelContent)}"]`:""} {`)}else{g.forEach((C,w)=>{const x=w===g.length-1&&h.label!==void 0?`["${Mi(h.label,h.labelContent)}"]`:"";r.push(`${" ".repeat(u.depth+w)}namespace ${Em(C)}${x} {`)})}for(const C of m)GS(r,C," ".repeat(u.depth+y),i);if(m.length===0&&f.length>0){u.entries=u.entries.filter(C=>!C.name.startsWith(`${h.name}.`));a.push({entries:f,index:0,prefix:`${h.name}.`,depth:u.depth+y,closes:y})}else{for(let C=y;C>0;C--)r.push(`${" ".repeat(u.depth+C-1)}}`)}}const l=new Set(o);for(const u of t.classes){if(u.namespace!==void 0&&l.has(u.namespace))continue;GS(r,u," ",i)}r.push(...i);for(const u of t.notes){const h=u.textContent||/#\w+;/.test(u.text)?Mi(u.text,u.textContent,'"&\\'):u.text.replace(/&/g,"&amp;").replace(/\\/g,"&#92;").replace(/"/g,"&quot;").replace(/%%\{/g,"%%#123;");if(u.for)r.push(` note for ${cr(u.for)} "${h}"`);else r.push(` note "${h}"`)}const c=new Map(t.classes.map(u=>[u.id,u]));const d=u=>{const h=c.get(u);if(!h?.isInterface)return cr(u);const m=h.label??u,f=h.generic?`~${h.generic}~`:"";return cr(f&&m.endsWith(f)?m.slice(0,-f.length):m)+f};for(const u of t.relations){const h=d(u.from),m=d(u.to);const f=KS(u);const p=u.fromCardinality?`${h} "${Mi(u.fromCardinality,u.fromCardinalityContent)}"`:h;const g=u.toCardinality?`"${Mi(u.toCardinality,u.toCardinalityContent)}" ${m}`:m;const y=u.label?` : ${Mi(u.label,u.labelContent,':;"')}`:"";r.push(` ${p} ${f} ${g}${y}`)}for(const u of t.classes){if(u.className){for(const h of u.className.split(/\s+/).filter(Boolean)){r.push(/[",]/.test(u.id)||!Ho(h,true)?` class ${cr(u.id)}:::${h}`:` cssClass "${u.id}" ${h}`)}}}for(const[u,h]of Object.entries(t.classDefs??{}))r.push(zS(` classDef ${u} `,h,nn(t.classDefDeclarations,u)));for(const u of t.classes){if(u.style)r.push(zS(` style ${Em(u.id)} `,u.style,u.styleDeclarations));if(u.href){r.push(` click ${cr(u.id)} href "${u.href.replace(/&/g,"&amp;").replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"${u.tooltip!==void 0?` "${u.tooltip.replace(/&/g,"&amp;").replace(/"/g,"&quot;")}"`:""}`)}}return r.join("\n")+"\n"}function G1(t){return{kind:"class",title:t.title,classes:t.classes.map(e=>({id:e.id,label:e.label,generic:e.generic,members:[...e.members],namespace:e.namespace,...e.isInterface?{isInterface:true}:{},...e.labelContent?{labelContent:e.labelContent}:{},...e.className?{className:e.className}:{},...e.style?{style:{...e.style}}:{},...e.styleDeclarations?{styleDeclarations:e.styleDeclarations.map(([r,i])=>[r,i])}:{},...e.href?{href:e.href}:{},...e.tooltip!==void 0?{tooltip:e.tooltip}:{}})),...t.classDefDeclarations?{classDefDeclarations:structuredClone(t.classDefDeclarations)}:{},relations:t.relations.map(e=>({...e})),notes:t.notes.map(e=>({...e})),...t.namespaces?{namespaces:t.namespaces.map(e=>({...e}))}:{},...t.classDefs?{classDefs:Object.fromEntries(Object.entries(t.classDefs).map(([e,r])=>[e,{...r}]))}:{}}}var WS=/^[\w$]+(\.[\w$]+)*$/;function US(t){if(typeof t!=="string")return T({code:"INVALID_OP",message:"Class generic must be a string or null"});const e=t.trim();if(!e||e.includes("~")||/[\r\n]/.test(e)){return T({code:"INVALID_OP",message:"Class generic must be non-empty and must not contain ~ or line breaks"})}return re(e)}function jS(t){if(t.startsWith('"'))return{code:"INVALID_OP",message:`Class id ${JSON.stringify(t)} starts with a double quote and has no supported lossless Mermaid spelling`};if(Oo(t,true,false))return void 0;return{code:"INVALID_OP",message:`Class id "${t}" is a keyword to Mermaid's class lexer, which reads \`${t}\` as a keyword even in backticks; choose another id`}}function Mm(t){for(const e of t){const r=typeof e==="string"?xa(e):void 0;if(r===void 0||/[\r\n]/.test(r)){return{code:"INVALID_OP",message:"Class members must be single lines; add each member separately"}}const i=Am(e);if(i)return{code:"INVALID_OP",message:i};if(my(r).length!==1){return{code:"INVALID_OP",message:"Class members must contain text, not blank lines, comments or init directives"}}if(ct([r],0)!==null){return{code:"INVALID_OP",message:"Class members cannot be accessibility directives"}}if(new RegExp(Jx.source,"i").test(r)){return{code:"INVALID_OP",message:"Class members cannot hold a %%{\u2026}%% directive, which Mermaid removes from the source"}}}}function W1(t){const e={code:"INVALID_OP",message:"Class relation kind, marker endpoints and line style must describe the same Mermaid arrow"};if(!Object.hasOwn(Pi,t.kind)||t.fromKind!==void 0&&!Object.hasOwn(Pi,t.fromKind)||t.toKind!==void 0&&!Object.hasOwn(Pi,t.toKind)||t.markerAt!==void 0&&!["from","to","both","none"].includes(t.markerAt)||t.lineStyle!==void 0&&t.lineStyle!=="solid"&&t.lineStyle!=="dashed")return e;const r=ba(t);if(t.fromKind!==void 0&&r.from===void 0||t.toKind!==void 0&&r.to===void 0)return e;const i=z1(`A ${KS(t)} B`);if(!i)return e;const n=ba(i);if(i.kind!==t.kind||n.at!==r.at||n.from!==r.from||n.to!==r.to||vm(i)!==vm(t))return e}function VS(t,e){if(!t.namespaces)t.namespaces=[];if(!t.namespaces.some(r=>r.name===e))t.namespaces.push({name:e})}function QS(t,e){const r=Om(t);if(r)return T({code:"INVALID_OP",message:r});const i="class"in e?e.class:e.kind==="rename_class"?e.from:e.kind==="add_note"?e.for:void 0;if(i&&t.classes.some(l=>l.id===i&&l.isInterface)){return T({code:"INVALID_OP",message:`A lollipop interface occurrence has no standalone class declaration; '${e.kind}' cannot add class-only metadata to '${i}'`})}const n=j1(t,e);if(!n.ok)return n;const o=n.value;if(e.kind==="add_interface"||!t.classes.some(l=>l.isInterface))return n;const s=new Set(o.relations.flatMap(l=>[l.from,l.to]));o.classes=o.classes.filter(l=>!l.isInterface||s.has(l.id));const a=$c(qc(o).trimEnd().split("\n").slice(1));return a?re(a):T({code:"INVALID_OP",message:"Class edit could not retain its lollipop interface occurrences in Mermaid source"})}function U1(t,e,r,i){const n=()=>T({code:"INVALID_OP",message:"Member removal requires an unambiguous authored member owning one complete physical line without comments or directives"});const o=wi(st(t),"authored");if(o.text.includes("\r"))return n();const s=o.text.split("\n"),a=mo(s,Kx(s));const l=Ai(a.familyLines,void 0,false);if(a.unclosedIndex!==void 0||l.diagnostics.length)return n();const c=[],d={attributes:0,methods:0};const u=(M,E)=>{if(E===void 0){c.push({node:M,index:-1});return}const _=Ws(xa(E));if(!_){c.push({node:M,text:E,index:-1});return}const q=_.isMethod?"methods":"attributes";c.push({node:M,text:E,field:q,index:d[q]++})};const h=[{nodes:l.statements,index:0}];while(h.length){const M=h.at(-1);if(M.index===M.nodes.length){h.pop();continue}const E=M.nodes[M.index++],_=E.value;if(_.kind==="class"){if(_.declaration.id===e&&_.declaration.annotation!==void 0)u(E);if(E.children)h.push({nodes:E.children,owner:_.declaration.id,index:0})}else if(_.kind==="namespace")h.push({nodes:E.children,index:0});else if(_.kind==="member"&&(_.reference?.id??M.owner)===e)u(E,_.text);else if(_.kind==="body-annotation"&&M.owner===e||_.kind==="annotation"&&_.annotation.id===e)u(E)}if(!Number.isInteger(r)||r<0||r>=c.length)return T({code:"MEMBER_NOT_FOUND",message:`member index ${r} out of range`});if(d.attributes!==i.attributes.length||d.methods!==i.methods.length||c.some(M=>M.field&&!Ni(Ws(xa(M.text))?.member,i[M.field][M.index])))return n();const m=c[r],f=m.field;if(!f)return n();const p=m.node.source.line-1,g=a.familyLines[p];const y=Bt(a.familyLines.join("\n"));if(m.node.source.end!==y[p]+g.length||m.node.raw.trim()!==g.trim()||m.node.text!==g.trim())return n();const C=a.familyOrigins[p],w=Bt(o.text)[C];const x=o.sourceOffset(w,"end"),k=o.sourceOffset(w+s[C].length,"start");const b=Bt(t),A=Xt(b,x).line-1;const L=b[A],B=b[A+1]??t.length;const O=t.slice(L,B).replace(/\r\n$|[\r\n]$/,"");if(x!==L||k!==L+O.length||xa(O).includes("%%"))return n();return re({edit:{start:L,end:B,text:""},field:f,index:m.index})}function ZS(t,e){if(e.kind!=="add_member"&&e.kind!=="remove_member")return T({code:"INVALID_OP",message:"Source-preserving Class edits support add_member and owned whole-line remove_member only"});const r=i=>{const n=st(i,{},"render");return po(ky(Zl(n.familyLines,n.authoredFamilyLines),n.accessibility),n.frontmatter)};try{const i=r(t),n=i.classes.find(l=>l.id===e.class);if(!n)return T({code:"CLASS_NOT_FOUND",message:`class ${e.class} not found`});if(n.isInterface)return T({code:"INVALID_OP",message:"An interface occurrence has no class member compartment"});let o,s=i;if(e.kind==="add_member"){const l=Mm([e.text]);if(l)return T(l);const c=Ws(e.text);if(Gs(e.text.trim())!==null||!c?.member.name.trim())return T({code:"INVALID_OP",message:"Source-preserving add_member requires an attribute or method, not an annotation or empty member"});const d=c.isMethod?"methods":"attributes";s={...i,classes:i.classes.map(u=>u===n?{...u,[d]:[...u[d],c.member]}:u)};o=Nc(t,`class ${cr(n.id)} {
179
+ ${e.text}
180
+ }`)}else{const l=U1(t,e.class,e.index,n);if(!l.ok)return l;const{field:c,index:d,edit:u}=l.value;s={...i,classes:i.classes.map(h=>h===n?{...h,[c]:h[c].filter((m,f)=>f!==d)}:h)};o=[u]}const a=ya(t,o);if(!Ni(r(a),s))return T({code:"INVALID_OP",message:"The source edit would change Class meaning beyond the requested member"});return re(o)}catch(i){return T({code:"INVALID_OP",message:i instanceof Error?i.message:String(i)})}}function j1(t,e){const r=G1(t);const i=n=>r.classes.find(o=>o.id===n);switch(e.kind){case"set_title":{r.title=e.title??void 0;return re(r)}case"add_class":{if(i(e.id))return T({code:"DUPLICATE_CLASS",message:`class ${e.id} already exists`});const n=jS(e.id);if(n)return T(n);if(e.label==="")return T({code:"INVALID_OP",message:"An explicitly empty Class label has no lossless Mermaid spelling"});const o=Mm(e.members??[]);if(o)return T(o);if(e.namespace!==void 0&&!WS.test(e.namespace)){return T({code:"INVALID_OP",message:`invalid namespace path "${e.namespace}" \u2014 expected dot-joined identifier segments like "Platform.Auth"`})}let s;if(e.generic!==void 0){const a=US(e.generic);if(!a.ok)return a;s=a.value}r.classes.push({id:e.id,label:e.label,generic:s,members:[...e.members??[]],namespace:e.namespace});if(e.namespace!==void 0)VS(r,e.namespace);return re(r)}case"set_class_namespace":{const n=i(e.class);if(!n)return T({code:"CLASS_NOT_FOUND",message:`class ${e.class} not found`});if(e.namespace===null){n.namespace=void 0;return Tm(r)}if(!WS.test(e.namespace)){return T({code:"INVALID_OP",message:`invalid namespace path "${e.namespace}" \u2014 expected dot-joined identifier segments like "Platform.Auth"`})}n.namespace=e.namespace;VS(r,e.namespace);return Tm(r)}case"define_class":{if(typeof e.name!=="string"||!Ho(e.name,true))return T({code:"INVALID_OP",message:"classDef name must be one non-reserved word token"});const n=zt(e.style);if(!n.ok)return T({code:"INVALID_OP",message:n.reason==="MULTILINE"?"classDef style must be a single-line CSS-like property list":n.reason==="UNSAFE_PAINT"?ni(`define_class ${e.name}`,n.paint).message:"classDef style must contain at least one property:value pair"});if(!r.classDefs)r.classDefs={};const o=ii(In(e.style));const s=Xo(n.value,o);if(!s)return T({code:"INVALID_OP",message:"Class style has no supported lossless Mermaid property/value spelling"});Pc(r.classDefs,e.name,s);if(o){r.classDefDeclarations??={};Pc(r.classDefDeclarations,e.name,o)}else if(r.classDefDeclarations){delete r.classDefDeclarations[e.name];if(!Object.keys(r.classDefDeclarations).length)delete r.classDefDeclarations}return re(r)}case"set_css_class":{const n=i(e.class);if(!n)return T({code:"CLASS_NOT_FOUND",message:`class ${e.class} not found`});if(e.className===null)delete n.className;else{if(!Ho(e.className))return T({code:"INVALID_OP",message:"CSS class name must have a lossless Mermaid style reference spelling"});n.className=e.className}return re(r)}case"set_class_style":{const n=i(e.class);if(!n)return T({code:"CLASS_NOT_FOUND",message:`class ${e.class} not found`});if(e.style===null){delete n.style;delete n.styleDeclarations}else{if(!Fc(n.id))return T({code:"INVALID_OP",message:`Class inline style target ${JSON.stringify(n.id)} is not an ALPHA identifier in Mermaid's style grammar`});const o=zt(e.style);if(!o.ok)return T({code:"INVALID_OP",message:o.reason==="MULTILINE"?"Class style must be a single-line CSS-like property list":o.reason==="UNSAFE_PAINT"?ni(`set_class_style ${e.class}`,o.paint).message:"Class style must contain at least one property:value pair"});const s=ii(In(e.style));const a=Xo(o.value,s);if(!a)return T({code:"INVALID_OP",message:"Class style has no supported lossless Mermaid property/value spelling"});n.style=a;if(s)n.styleDeclarations=s;else delete n.styleDeclarations}return re(r)}case"remove_class":{const n=r.classes.findIndex(o=>o.id===e.id);if(n<0)return T({code:"CLASS_NOT_FOUND",message:`class ${e.id} not found`});r.classes.splice(n,1);r.relations=r.relations.filter(o=>o.from!==e.id&&o.to!==e.id);r.notes=r.notes.filter(o=>o.for!==e.id);return Tm(r)}case"rename_class":{const n=i(e.from);if(!n)return T({code:"CLASS_NOT_FOUND",message:`class ${e.from} not found`});if(i(e.to))return T({code:"DUPLICATE_CLASS",message:`class ${e.to} already exists`});const o=jS(e.to);if(o)return T(o);if(n.style&&!Fc(e.to))return T({code:"INVALID_OP",message:`Class inline style target ${JSON.stringify(e.to)} is not an ALPHA identifier in Mermaid's style grammar`});n.id=e.to;for(const s of r.relations){if(s.from===e.from)s.from=e.to;if(s.to===e.from)s.to=e.to}for(const s of r.notes)if(s.for===e.from)s.for=e.to;return re(r)}case"set_class_generic":{const n=i(e.class);if(!n)return T({code:"CLASS_NOT_FOUND",message:`class ${e.class} not found`});if(e.generic===null){n.generic=void 0}else{const o=US(e.generic);if(!o.ok)return o;n.generic=o.value}return re(r)}case"add_member":{const n=i(e.class);if(!n)return T({code:"CLASS_NOT_FOUND",message:`class ${e.class} not found`});const o=Mm([e.text]);if(o)return T(o);n.members.push(e.text);return re(r)}case"remove_member":{const n=i(e.class);if(!n)return T({code:"CLASS_NOT_FOUND",message:`class ${e.class} not found`});if(e.index<0||e.index>=n.members.length)return T({code:"MEMBER_NOT_FOUND",message:`member index ${e.index} out of range`});n.members.splice(e.index,1);return re(r)}case"add_interface":{const n=i(e.class);if(!n)return T({code:"CLASS_NOT_FOUND",message:`class ${e.class} not found`});if(n.isInterface)return T({code:"INVALID_OP",message:"add_interface needs an ordinary class, not another interface occurrence"});if(typeof e.label!=="string"||!e.label.trim()||/[\r\n`]/.test(e.label)||e.side!==void 0&&e.side!=="from"&&e.side!=="to"){return T({code:"INVALID_OP",message:"Interface label must be a non-empty portable single-line name without backticks; side must be from or to"})}if(e.lineStyle!==void 0&&e.lineStyle!=="solid"&&e.lineStyle!=="dashed"||e.relationLabel!==void 0&&(typeof e.relationLabel!=="string"||!e.relationLabel.trim()||/[\r\n]/.test(e.relationLabel))){return T({code:"INVALID_OP",message:"Interface relationLabel must be a non-empty single line; lineStyle must be solid or dashed"})}const o=e.side??"to",s=e.lineStyle==="dashed"?"..":"--";const a=o==="from"?`${cr(e.label)} ()${s} ${cr(n.id)}`:`${cr(n.id)} ${s}() ${cr(e.label)}`;const l=a+(e.relationLabel!==void 0?` : ${Mi(e.relationLabel,void 0,':;"')}`:"");const c=eh(l);if(!c||c[o]!==e.label||(o==="from"?c.fromGeneric:c.toGeneric)||e.relationLabel!==void 0&&c.label!==e.relationLabel){return T({code:"INVALID_OP",message:"Interface label cannot be represented as an exact pinned Mermaid endpoint name"})}const d=$c((qc(r).trimEnd()+`
181
+ ${l}`).split("\n").slice(1));if(!d||d.classes.filter(u=>u.isInterface).length!==r.classes.filter(u=>u.isInterface).length+1){return T({code:"INVALID_OP",message:"add_interface could not retain the new interface occurrence in Mermaid source"})}return re(d)}case"add_relation":{if(!i(e.from))return T({code:"CLASS_NOT_FOUND",message:`class ${e.from} not found`});if(!i(e.to))return T({code:"CLASS_NOT_FOUND",message:`class ${e.to} not found`});const n={from:e.from,to:e.to,kind:e.relKind,label:e.label,...e.markerAt!==void 0?{markerAt:e.markerAt}:{},...e.fromKind!==void 0?{fromKind:e.fromKind}:{},...e.toKind!==void 0?{toKind:e.toKind}:{},...e.lineStyle!==void 0?{lineStyle:e.lineStyle}:{}};const o=W1(n);if(o)return T(o);const s=ba(n);if(s.at==="from"&&s.from==="lollipop"||s.at==="to"&&s.to==="lollipop"||i(e.from)?.isInterface||i(e.to)?.isInterface){return T({code:"INVALID_OP",message:"A lone lollipop creates a distinct interface occurrence and cannot share an existing class endpoint; use add_interface with class, label and optional side"})}r.relations.push(n);return re(r)}case"remove_relation":{if(e.index<0||e.index>=r.relations.length)return T({code:"RELATION_NOT_FOUND",message:`relation index ${e.index} out of range`});r.relations.splice(e.index,1);return re(r)}case"add_note":{if(typeof e.text!=="string"||/[\r\n]/.test(e.text)){return T({code:"INVALID_OP",message:"Class note text must be a single line; use <br/> for displayed line breaks"})}if(e.for&&!i(e.for))return T({code:"CLASS_NOT_FOUND",message:`class ${e.for} not found`});r.notes.push({text:e.text,for:e.for});return re(r)}case"remove_note":{if(e.index<0||e.index>=r.notes.length)return T({code:"NOTE_NOT_FOUND",message:`note index ${e.index} out of range`});r.notes.splice(e.index,1);return re(r)}default:return T({code:"INVALID_OP",message:Ve("class",e)})}}function S2(t){const e=t.split(/\r?\n/);const r=e.findIndex(d=>/^classDiagram(?:-v2)?\b/.test(d.trim()));if(r<0)return[];const i=e.slice(r+1);const n=[];if(!Yx(i)){n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_empty_diagram",line:r+1,message:'A "classDiagram" header with no statement after it draws an empty class diagram. Pinned Mermaid rejects this; add a class, relationship, note or other statement.'})}for(const{index:d,what:u}of Qx(i)){n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_trailing_comment",line:r+2+d,message:`${u}. Pinned Mermaid rejects this; put the comment on a line of its own.`})}const o=d=>d.kind==="class"?[d.declaration.id]:d.kind==="annotation"?[d.annotation.id]:d.kind==="member"&&d.reference?[d.reference.id]:d.kind==="relationship"?[d.relationship.from,d.relationship.to]:[];const s=new Set;const a=d=>{for(const u of d){for(const h of o(u.value))s.add(h);a(u.children??[])}};const l=d=>{a(d);const u=new Set;const h=[...d].reverse();const m=new Set;while(h.length){const f=h.pop();if(f.followsNamespaceCloseOnSameLine&&f.value.kind==="trivia"&&f.raw.startsWith("%%"))n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_trailing_comment",line:r+1+f.source.line,message:"A %% comment after a namespace closing brace is read as a comment. Pinned Mermaid rejects this; put the comment on a line of its own."});else if(f.followsNamespaceCloseOnSameLine&&f.value.kind!=="trivia"&&f.value.kind!=="close")n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_statement_after_namespace_close",line:r+1+f.source.line,message:"A Class statement after a namespace closing brace on the same line is read as a separate statement. Pinned Mermaid rejects this, even with a semicolon; put the statement on a new line."});else if(f.followsClassCloseOnSameLine)n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_statement_after_class_close",line:r+1+f.source.line,message:"A Class statement after a class body's closing brace on the same line is read as a separate statement. Pinned Mermaid rejects this; put the statement on a new line."});if(f.compactSemicolon&&!m.has(f.source.line)){m.add(f.source.line);n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_compact_semicolon_statement_extension",line:r+1+f.source.line,message:"Semicolon-separated statements inside a compact Class namespace are read as separate statements. Pinned Mermaid rejects this source; put each statement on its own line."})}const p=f.value;if(p.kind==="class"&&p.declaration.label===""||p.kind==="namespace"&&p.label==="")n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_empty_label",line:r+1+f.source.line,message:"An explicitly empty Class label is retained for native rendering. Pinned Mermaid requires nonempty label text, so typed editing is unavailable rather than replacing the label with its identity."});if(p.kind==="namespace"&&JS(p.path))n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_namespace_generic",line:r+1+f.source.line,message:"A leading tilde in a Class namespace path segment opens Mermaid generic syntax even inside backticks. Entity codes change the identity; source and native rendering are preserved without typed editing."});if(p.kind==="style"){for(const w of p.references)if(!Fc(w.id))n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_style_target",line:r+1+f.source.line,message:`Class inline style target ${JSON.stringify(w.id)} is outside Mermaid's ALPHA production; quoting does not extend it. Source is preserved; use an explicit named CSS class for this identity.`})}if((p.kind==="classDef"||p.kind==="style")&&Ql(f.text))n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_style_commas",line:r+1+f.source.line,message:_r(p.props)?"Native CSS commas remain inside their property values. Pinned Mermaid splits raw commas into separate styles; the writer protects value delimiters with entity codes.":"This style contains text outside the supported SVG attribute domain. Source is preserved, but typed editing is unavailable."});const g=o(p).concat(p.kind==="interaction"?[p.interaction.id]:p.kind==="note"&&p.reference?[p.reference.id]:[]);if(g.some(dn)||p.kind==="namespace"&&dn(p.path.join(".")))n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_direction_identity",line:r+1+f.source.line,message:"A greedy Mermaid direction token consumes this identity even inside backticks. Native reading and source are retained; typed editing is unavailable."});for(const w of g)if(w.startsWith('"'))n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_id",line:r+1+f.source.line,message:`Class id ${JSON.stringify(w)} starts with a double quote, which pinned Mermaid treats as syntax even inside backticks. Its source and native rendering are preserved, but typed editing is unavailable.`});const y=p.kind==="classDef"?p.names:p.kind==="assignment"?[p.name]:p.kind==="class"?[p.declaration.className]:p.kind==="annotation"?[p.annotation.className]:[];for(const w of y)if(w!==void 0&&!Ho(w,p.kind==="classDef"))n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_style_name",line:r+1+f.source.line,message:`Class style ${p.kind==="classDef"?"definition":"reference"} ${JSON.stringify(w)} has no supported lossless Mermaid spelling. The source and native rendering are preserved, but typed editing is unavailable.`});if(p.kind==="annotation"?p.annotation.placement==="inline"&&p.annotation.className!==void 0:p.kind==="class"&&p.declaration.annotation!==void 0&&p.declaration.className!==void 0)n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_style_before_annotation",line:r+1+f.source.line,message:"A :::style class before an inline <<annotation>> is read as the class's style class. Pinned Mermaid rejects this; put the annotation inside the class body or on a line of its own."});for(const w of o(p))u.add(w);if(p.kind==="assignment"&&p.form==="cssClass"&&p.references.some(w=>s.has(w.id)&&!u.has(w.id)))n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_css_class_before_class",line:r+1+f.source.line,message:"A cssClass before the class it names is applied to that class. Pinned Mermaid applies a cssClass only to classes declared before it, and draws this one unstyled; put the cssClass after the class."});if(p.kind==="assignment"&&p.form!=="cssClass")n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_style_assignment",line:r+1+f.source.line,message:p.form==="class"?`\`class A c\` is read as style class c on A. Pinned Mermaid reads it as one class named \`Ac\`; write \`cssClass "A" c\` or \`class A:::c\`.`:p.form==="shorthand"?'A `:::style` class on a line of its own is read as the class\'s style class. Pinned Mermaid rejects it; write `cssClass "A" c` or `class A:::c`.':'A cssClass whose class list is not quoted is read as written. Pinned Mermaid rejects it; quote the list: `cssClass "A,B" c`.'});if(p.kind==="member"&&p.reference){const w=tn(f.text.replace(/%%\{\s*\w+(?:(?!\}%%)[\s\S])*(?:\}%%)?/g,"")).replace(/#\w+;/g,"#");if(/[:;]/.test(w.slice(w.indexOf(":")+1)))n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_member_text",line:r+1+f.source.line,message:"A colon or `;` in the text after `Class :` is read as part of the member. Pinned Mermaid ends that text at either and rejects the line. The writer writes the member in the class body, `class A { \u2026 }`, which Mermaid reads."})}const C=p.kind==="classDef"||p.kind==="style"?f.text.trim().replace(/^\S+\s+(?:`[^`]*`|"[^"]*"|\S+)\s+/,"").split(":")[0].trim():"";if((p.kind==="classDef"||p.kind==="style")&&(!YS(C)||/[^\w\s#%,]/.test(f.text.replace(/^\S+/,"").split(":")[0])))n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_style_text",line:r+1+f.source.line,message:`\`${p.kind}\` is read with its names and CSS as written. Before the first colon, pinned Mermaid rejects hyphenated property names and reserved Class/accessibility tokens. The writer prefixes an empty CSS declaration, \`style:,stroke-width:2px\`, which sets no property and preserves the complete authored sequence.`});if(p.kind==="member"){const w=Am(p.text);if(w)n.push({code:"UNSUPPORTED_SYNTAX",syntax:/[{}]/.test(p.text)&&dn(p.text)?"class_member_direction":"class_member_html",line:r+1+f.source.line,message:`${w}. Its source and native rendering are preserved, but typed editing is unavailable.`});const x=p.text.replace(/#\w+;/g,"#").trim();if(!(x.startsWith("<<")&&x.endsWith(">>"))&&x.indexOf(")")>0&&!/^[#+~-]?.+\(.*\)/.test(x))n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_member_parenthesis",line:r+1+f.source.line,message:"A member holding a `)` with no name and `(\u2026)` before it is read as written. Pinned Mermaid reads a member holding `)` as a method, and fails on one it cannot split into a name and `(\u2026)`: it draws no diagram. Write the `)` as `#41;`, or the method as `name(\u2026)`."})}if(p.kind==="interaction"){const w=/^(click|link)\s+(?:`[^`]+`|[\w$]+)(?:~[^~]+~)?\s+(href\s+)?(")?/.exec(f.text.trim());if(!w||w[1]==="click"!==(w[2]!==void 0)||w[3]===void 0)n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_link_form",line:r+1+f.source.line,message:'This link is read as a link to its URL. Pinned Mermaid reads a link only as `click A href "\u2026"` or `link A "\u2026"`, its keyword in lower case and its URL quoted, and rejects this line. The writer writes `click A href "\u2026"`.'})}if(p.kind==="header")n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_repeated_header",line:r+1+f.source.line,message:"A second `classDiagram` header is read as nothing, and the writer leaves it out. Pinned Mermaid rejects it. Remove it."});if((p.kind==="classDef"||p.kind==="style")&&Xx(f.text)!==f.text)n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_style_comment",line:r+1+f.source.line,message:`A \`%%\` comment after \`${p.kind}\` paint is read as a comment, and the paint before it is drawn. Pinned Mermaid reads the comment into the last property's value, which CSS then drops, so it draws that property's default. Put the comment on a line of its own.`});if(f.value.kind==="note"&&f.value.escapedQuotes)n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_escaped_note_quotes",line:r+1+f.source.line,message:"Backslash-escaped quotes in Class notes are read as text. Pinned Mermaid rejects this; use &quot; inside the quoted note."});if(f.children)for(let w=f.children.length-1;w>=0;w--)h.push(f.children[w])}};const c=[...i];for(let d=0;d<c.length;d++){const u=ct(c,d);if(u===void 0)break;if(u===null)continue;if(!u.title&&u.form!=="native"&&u.value==="")n.push({code:"UNSUPPORTED_SYNTAX",syntax:"class_empty_accessibility_description",line:r+d+2,message:"An empty accessibility description is retained, but pinned Mermaid rejects an empty Class accDescr block. The writer preserves the empty value in a native metadata comment."});for(let h=d;h<=u.endIndex;h++)c[h]="";if(u.suffixLine)c[u.endIndex]=u.suffixLine;d=u.endIndex}l(Ai(c).statements);return n}function ew(t,e){const r=[];if(t.classes.length===0&&t.title===void 0){r.push({code:"EMPTY_DIAGRAM"});return r}const i=Ke(r,e);if(t.title)i("title",t.title);const n=new Set(t.classes.map(o=>o.id));for(const o of t.classes){if(o.label)i(o.id,Ye(o.label,o.labelContent));for(let s=0;s<o.members.length;s++){const a=xa(o.members[s]);const l=Gs(a);const c=l===null?Ws(a):null;const d=l!==null?`<<${Vx(l)}>>`:c?zs(c.member):"";i(`${o.id}#m${s}`,bt(d,"literal"))}}for(const o of t.namespaces??[]){if(o.label)i(`namespace:${o.name}`,Ye(o.label,o.labelContent))}for(let o=0;o<t.relations.length;o++){const s=t.relations[o];if(!n.has(s.from)||!n.has(s.to)){r.push({code:"EDGE_MISANCHORED",edge:`rel#${o}:${s.from}->${s.to}`,from:n.has(s.from)?s.from:void 0,to:n.has(s.to)?s.to:void 0})}if(s.label)i(`rel#${o}`,Ye(s.label,s.labelContent))}for(let o=0;o<t.notes.length;o++){const s=t.notes[o];i(`note#${o}`,Ye(s.text,s.textContent));if(s.for&&!n.has(s.for)){r.push({code:"EDGE_MISANCHORED",edge:`note#${o}->${s.for}`,from:void 0,to:void 0})}}return r}import{decodeXML as V1}from"entities";function R2(t){const e=t.split(/\r?\n/);const r=e.findIndex(c=>/^erDiagram\b/i.test(c.trim()));if(r<0)return[];const i=[];const n=(c,d,u,h)=>{i.push({code:"UNSUPPORTED_SYNTAX",syntax:d,line:c+1,message:`${u}. Pinned Mermaid rejects this; ${h}.`})};const o=e.slice(r+1);const s=[];for(let c=r+1;c<e.length;c++){const d=ct(e,c);if(d===void 0)break;if(d!==null){for(let u=c;u<=d.endIndex;u++)o[u-r-1]="";if(d.suffixLine)o[d.endIndex-r-1]=d.suffixLine;c=d.endIndex;continue}s.push(c)}const a=[];let l;try{l=js(o,(c,d,u)=>a.push([u,c,d]))}catch{}for(const c of s){const d=e[c].trim();if(!d||d.startsWith("%%"))continue;if(sb(e[c].slice(l?.continuedComments.get(c-r-1)??0)))n(c,"er_trailing_comment","A trailing %% comment after an ER statement is read as a comment","put the comment on a line of its own")}for(const[c,d,u]of a)n(r+c+1,"er_quoted_text",d,u);if(l){const c=new Set;for(const d of l.statements){const{syntax:u}=d;if(u.kind==="unknown")i.push({code:"UNSUPPORTED_SYNTAX",syntax:"er_statement",line:r+d.line+2,message:`ER statement is preserved in source but not drawn: ${d.raw.trim()}`});const h=u.kind==="entity"||u.kind==="block-open"?[u.reference]:u.kind==="relation"?[u.relation.entity1,u.relation.entity2]:[];for(const f of h){if(!f.quoted&&nh(f.id))n(r+d.line+1,"er_keyword_name",`ER name ${f.id} is read as a name, where Mermaid reads a keyword`,`quote it ("${f.id}")`)}const m=u.kind==="class"?u.classNames:h.flatMap(f=>f.className?.split(" ")??[]);for(const f of m)if(!zc(f))n(r+d.line+1,"er_class_name",`ER class name ${JSON.stringify(f)} has no supported lossless spelling`,"the source and drawing are preserved, but typed editing is unavailable");if((u.kind==="style"||u.kind==="class-def")&&Us(u.props)===void 0)n(r+d.line+1,"er_style_text","ER style text contains a property or value with no supported lossless spelling","the source and drawing are preserved, but typed editing is unavailable");if(u.kind==="entity"&&u.reference.id==="1"&&!u.reference.quoted){const f=[o[d.line].slice(d.column),...o.slice(d.line+1)].join("\n").trimStart();if(/^1\s+[A-Za-z_"'0-9]/.test(f))n(r+d.line+1,"er_numeric_name","ER name 1 before another name is read as an entity, where Mermaid reads a cardinality",'quote it ("1")')}if(u.kind==="attribute"&&u.generous)n(r+d.line+1,"er_attribute_form","An attribute with keys apart or after its comment is read as its type, name, keys and comment",'write its keys comma-separated before the comment (`int id PK, FK "c"`)');if(u.kind==="relation"&&u.relation.unreadLabel){const{label:f}=u.relation;if(f==="")n(r+d.line+1,"er_relation_label","A relationship with no label is read without one",'write its label after a `:` on the relationship\'s line (`: ""` for none)');else n(r+d.line+1,"er_relation_label",`ER relation label ${f} is read as written, where Mermaid's lexer reads a keyword, a cardinality, a number or punctuation in it`,`quote it (: "${f.replace(/"/g,"#quot;")}")`)}if(u.kind==="relation"&&u.relation.unquotedWords)i.push({code:"UNSUPPORTED_SYNTAX",syntax:"er_label_words",line:r+d.line+2,message:"A relationship label of several unquoted words, or of a word and a quoted name, is read whole. Pinned Mermaid reads only its first word as the label and declares the others as entities; quote the label"});if(u.kind!=="direction"&&d.entityId===void 0&&!["attribute","block-close","comment","blank"].includes(u.kind)&&/direction\s+(?:TB|BT|LR|RL)/i.test((o[d.line]??"").slice(d.column))&&!c.has(d.line)){c.add(d.line);i.push({code:"UNSUPPORTED_SYNTAX",syntax:"er_direction_line",line:r+d.line+2,message:"A line holding direction TB (BT, LR, RL) beside other text is read statement by statement. Pinned Mermaid reads the whole line as a direction and drops the rest; put the direction on a line of its own"})}}}return i}function tw(t,e){if(Us(e)!==void 0)return void 0;return T({code:"INVALID_OP",message:`${t}: ER style ${on(e)} contains a control character or unpaired surrogate that cannot be retained losslessly in Mermaid's SVG; remove it`})}function rw(t){return rc(t)!==null||t!==""&&!/["%\\\r\n]/.test(t)}function zc(t){return/^[\w-]+$/.test(t)&&!/^\d/.test(t)&&!nh(t)}function Bm(t){for(const e of t.entities){for(const r of e.className?.trim().split(/[ \t]+/)??[]){if(!zc(r))return`ER class name ${JSON.stringify(r)} has no supported lossless Mermaid spelling`}if(e.style&&Us(e.style)===void 0)return`ER entity ${JSON.stringify(e.id)} has style text with no supported lossless Mermaid spelling`}for(const[e,r]of Object.entries(t.classDefs??{})){if(Us(r)===void 0)return`ER classDef ${JSON.stringify(e)} has style text with no supported lossless Mermaid spelling`}}var iw={one:"one-only","zero-one":"zero-or-one",many:"one-or-many","zero-many":"zero-or-many",parent:"parent"};function lw(t,e){try{return Y1(e??t)}catch{return null}}function Y1(t){const e=[];const r={kind:"er",entities:[],relations:[],groups:[],statements:e};const i=new Map;const n=new Map;const o=(u,h)=>{let m=i.get(u);if(!m){if(!rw(u))throw new Error(`ER entity id ${JSON.stringify(u)} has no Mermaid spelling`);m={id:u,attributes:[]};i.set(u,m)}if(h)rh(n,u,h.split(" "));return m};const s=new Set;const a=u=>{if(!s.has(u)){s.add(u);e.push({kind:"entity",id:u})}};const l=js(t);const c=new Map;for(const u of l.statements){const h=u.syntax;switch(h.kind){case"unknown":case"comment":if(u.entityId!==void 0)return null;e.push({kind:"opaque",lines:[u.raw]});break;case"attribute":i.get(u.entityId).attributes.push({text:h.text});break;case"direction":{const m=u.groupId!==void 0?c.get(u.groupId):void 0;if(m)m.direction=h.direction;else r.direction=h.direction;e.push({kind:"direction",...m?{groupId:m.id}:{}});break}case"group-open":{if(!rw(h.id)||h.title==="")return null;const m={id:h.id,...tc(h.title??h.id)};r.groups.push(m);c.set(m.id,m);e.push({kind:"group-open",id:m.id});break}case"end":e.push({kind:"group-close",id:u.groupId});break;case"class-def":if(Object.keys(h.props).length===0)return null;if(!r.classDefs)r.classDefs={};for(const m of h.names)r.classDefs[m]={...h.props};break;case"class":for(const m of h.ids){if(i.has(m))rh(n,m,h.classNames)}break;case"style":if(h.ids.length===0||Object.keys(h.props).length===0)return null;for(const m of h.ids){const f=o(m);f.style={...f.style,...h.props}}break;case"relation":{const{relation:m}=h;const f=sh(m.leftToken);const p=sh(m.rightToken);if(!f||!p||p==="parent")return null;const g=r.relations.length;r.relations.push({from:m.entity1.id,to:m.entity2.id,leftCard:iw[f],rightCard:iw[p],dashed:!m.identifying,...m.label?tc(m.label):{label:void 0}});for(const y of[m.entity1,m.entity2]){if(u.relationEntityIds.includes(y.id))o(y.id,y.className)}e.push({kind:"relation",ref:g});break}case"block-open":{const{reference:m}=h;o(m.id,m.className);a(m.id);break}case"entity":{const{reference:m}=h;o(m.id,m.className);a(m.id);break}}}const d=l.placement;if(d.order.length===0&&l.statements.some(u=>u.syntax.kind==="unknown"))return null;if([...d.alias.values()].includes(""))return null;for(const[u,h]of n)i.get(u).className=h.join(" ");r.entities=d.order.map(u=>{const{attributes:h,...m}=i.get(u);const f=d.alias.get(u);const p=d.owner.get(u);return{...m,...f!==void 0?tc(f):{},attributes:h,...p!==void 0?{groupId:p}:{}}});for(const u of r.groups){const h=d.owner.get(u.id);if(h!==void 0)u.parentId=h}return Bm(r)?null:r}var cw={"one-only":"||","zero-or-one":"|o","zero-or-many":"}o","one-or-many":"}|",parent:"u"};var dw={"one-only":"||","zero-or-one":"o|","zero-or-many":"o{","one-or-many":"|{"};var H1=/^(?:[^\x00-\x7F]|\w|-|\*)+$/;function Fi(t){const e=rc(t.id)!==null&&!oh(t.id);const r=e?t.id:`"${t.id}"`;return t.label===void 0?r:`${r}[${ib(t.label,t.labelContent)}]`}function X1(t){return t.style!==void 0&&t.attributes.length===0&&!t.groupId&&Fi(t)===Fi({...t,label:void 0})}function K1(t,e){const r=ec();for(const i of t.statements??[]){if(i.kind!=="entity"||!e.has(i.id))uw(r,t,i)}return r.finish().owner}function uw(t,e,r){if(r.kind==="group-open")t.open(r.id);else if(r.kind==="group-close")t.close();else if(r.kind==="entity")t.declare(r.id);else if(r.kind==="relation"){const i=e.relations[r.ref];if(i){t.relationEnd(i.from);t.relationEnd(i.to)}}}function J1(t,e,r){const i=Ca(t);const n=ec();const o=i.findIndex(s=>{uw(n,t,s);return n.created(e)});i.splice(o<0?i.length:o+1,0,r)}function hw(t){const e=Bm(t);if(e)throw new Error(e);const r=nw(t,[]);const i=new Map(r.order.map((o,s)=>[o,s]));let n=Infinity;for(let o=t.entities.length-1;o>=0;o--){const s=i.get(t.entities[o].id)??Infinity;if(s>=n)return nw(t,t.entities.slice(0,o+1)).source;n=s}return r.source}function nw(t,e){const r=["erDiagram"];const i=ec();const n=new Set(e.map(d=>d.id));const o=new Map(t.entities.map(d=>[d.id,d]));const s=new Map((t.groups??[]).map(d=>[d.id,d]));const a=d=>{i.declare(d.id);const u=Fi(d);if(d.attributes.length===0)r.push(` ${u}`);else{r.push(` ${u} {`);for(const h of d.attributes)r.push(` ${lb(h.text)}`);r.push(" }")}};const l=d=>{i.relationEnd(d.from);i.relationEnd(d.to);const u=cw[d.leftCard];const h=dw[d.rightCard];if(u===void 0||h===void 0)throw new Error("Invalid ER endpoint marker: parent is only writable before the relationship connector");const m=d.dashed?"..":"--";const f=d.label??"";const p=o.get(d.from);const g=o.get(d.to);const y=p?Fi({...p,label:void 0}):d.from;const C=g?Fi({...g,label:void 0}):d.to;r.push(` ${y} ${u}${m}${h} ${C} : ${nb(f,d.labelContent)}`)};const c=new Set;if(t.statements){for(const O of e)a(O);const{entities:d,statements:u}=t;const h=new Map(d.map((O,M)=>[O.id,M]));const m=K1(t,n);const f=new Set(d.filter(O=>m.get(O.id)!==O.groupId).map(O=>O.id));const p=new Set(n);let g=0;const y=new Set(n);const C=new Set(u.flatMap(O=>O.kind==="entity"?[O.id]:[]));const w=[];const x=O=>{if(y.has(O.id)){r.push(` ${Fi(O)}`);i.declare(O.id)}else a(O);y.add(O.id);p.add(O.id);f.delete(O.id)};const k=O=>!p.has(O.id)&&O.groupId===w.at(-1);const b=O=>{while(g<d.length&&p.has(d[g].id))g++;for(const M of d.slice(g,O))if(k(M))x(M)};const A=O=>{const M=[...new Set(O)].filter(Q=>h.has(Q)&&!p.has(Q)).map(Q=>h.get(Q));if(M.length===0)return;const[E,_]=M;const q=_===void 0||E<_&&!d.slice(E+1,_).some(k);b(q?E:Math.max(E,_));for(const Q of M)p.add(d[Q].id)};const L=O=>{const M=new Set;const E=new Set;for(let q=O,Q=0;q<u.length;q++){const $=u[q];if($.kind==="group-open"){M.add($.id);Q++}else if($.kind==="group-close"&&--Q===0)break;else if($.kind==="entity")E.add($.id);else if($.kind==="relation"){const D=t.relations[$.ref];if(D)E.add(D.from).add(D.to)}}const _=d.findIndex(q=>!p.has(q.id)&&(E.has(q.id)||q.groupId!==void 0&&M.has(q.groupId)));return _<0?0:_};u.forEach((O,M)=>{if(O.kind==="entity"){const E=o.get(O.id);if(E&&!y.has(E.id)){A([E.id]);a(E);y.add(E.id)}}else if(O.kind==="relation"){const E=t.relations[O.ref];if(E){A([E.from,E.to]);l(E);for(const _ of[E.from,E.to]){const q=o.get(_);if(q?.label!==void 0&&!y.has(_)&&!C.has(_)&&Fi(q)!==Fi({...q,label:void 0})){a(q);y.add(_)}}}}else if(O.kind==="direction"){const E=O.groupId?s.get(O.groupId)?.direction:t.direction;if(E)r.push(` direction ${E}`)}else if(O.kind==="group-open"){b(L(M));const E=s.get(O.id);if(E){const _=rc(E.id)!==null&&!/^\d/.test(E.id)&&!oh(E.id)?E.id:`"${E.id}"`;r.push(` subgraph ${_}${E.label!==tb(E.id)?` [${ob(E.label,E.labelContent)}]`:""}`);i.open(O.id)}w.push(O.id)}else if(O.kind==="group-close"){const E=d.filter(_=>_.groupId===w.at(-1));for(const _ of E)if(!p.has(_.id)||f.has(_.id)&&!y.has(_.id))x(_);for(const _ of E)if(f.has(_.id))x(_);w.pop();r.push(" end");i.close()}else{for(const E of O.lines)r.push(E)}});let B=d.length;while(B>0&&!p.has(d[B-1].id)&&X1(d[B-1]))B--;for(const O of d.slice(0,B))if(!p.has(O.id))x(O);for(const O of d.slice(B))c.add(O.id)}else{if(t.direction)r.push(` direction ${t.direction}`);for(const d of t.entities)a(d);for(const d of t.relations)l(d)}for(const[d,u]of Object.entries(t.classDefs??{}))r.push(ih(` classDef ${d}`,u));for(const d of t.entities){const u=Fi({...d,label:void 0});const h=d.className?.trim().split(/[ \t]+/).join(",");const m=h===void 0?void 0:!zc(d.id)?` ${u}:::${h}`:` class ${u} ${h}`;const f=d.style?ih(` style ${H1.test(d.id)?d.id:u}`,d.style):void 0;if(f)i.style(d.id);for(const p of c.has(d.id)?[f,m]:[m,f])if(p)r.push(p)}return{source:r.join("\n")+"\n",order:i.finish().order}}function Q1(t){return{kind:"er",entities:t.entities.map(e=>({id:e.id,...e.label!==void 0?{label:e.label}:{},...e.labelContent?{labelContent:e.labelContent}:{},attributes:e.attributes.map(r=>({...r})),...e.className?{className:e.className}:{},...e.style?{style:{...e.style}}:{},...e.groupId?{groupId:e.groupId}:{}})),relations:t.relations.map(e=>({...e})),...t.groups?{groups:t.groups.map(e=>({...e}))}:{},...t.direction?{direction:t.direction}:{},...t.classDefs?{classDefs:Object.fromEntries(Object.entries(t.classDefs).map(([e,r])=>[e,{...r}]))}:{},...t.statements?{statements:t.statements.map(e=>e.kind==="opaque"?{...e,lines:[...e.lines]}:{...e})}:{}}}function Ca(t){if(!t.statements){t.statements=[...t.direction?[{kind:"direction"}]:[],...t.entities.map(e=>({kind:"entity",id:e.id})),...t.relations.map((e,r)=>({kind:"relation",ref:r}))]}return t.statements}function ow(t,e){const r=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");const i=new RegExp(`(^|[^\\w.-])${r}([^\\w.-]|$)`);return(t.statements??[]).some(n=>n.kind==="opaque"&&n.lines.some(o=>i.test(o)))}function sw(t,e){const r=new Map;const i=[];t.relations.forEach((n,o)=>{if(!e(n,o)){r.set(o,i.length);i.push(n)}});t.relations=i;if(t.statements){const n=[];for(const o of t.statements){if(o.kind!=="relation")n.push(o);else{const s=r.get(o.ref);if(s!==void 0)n.push({kind:"relation",ref:s})}}t.statements=n}}function aw(t,e){if(t===null||t===void 0)return re(void 0);if(typeof t!=="string")return T({code:"INVALID_OP",message:`ER entity ${e} must be a string or null`});const r=t.trim().replace(/\s+/g," ");if(!r||/[\r\n\[\]]/.test(r)){return T({code:"INVALID_OP",message:`ER entity ${e} must be non-empty and must not contain brackets or line breaks`})}return re(r)}function mw(t,e){const r=Bm(t);if(r)return T({code:"INVALID_OP",message:r});const i=Q1(t);const n=o=>i.entities.find(s=>s.id===o);switch(e.kind){case"add_entity":{if(!th(e.id)||e.id.includes(":::")||e.id.includes("[")){return T({code:"INVALID_OP",message:`ER entity id "${e.id}" must be a bare identifier`})}if(n(e.id))return T({code:"DUPLICATE_ENTITY",message:`entity ${e.id} already exists`});const o=e.attributes??[];if(o.some(l=>!ic(l))){return T({code:"INVALID_OP",message:'ER attributes must use: type name [PK, FK, UK] ["comment"]'})}const s=aw(e.label,"label");if(!s.ok)return s;const a=Ca(i);i.entities.push({id:e.id,...s.value!==void 0?{label:s.value}:{},attributes:o.map(l=>({text:l}))});a.push({kind:"entity",id:e.id});return re(i)}case"remove_entity":{const o=i.entities.findIndex(s=>s.id===e.id);if(o<0)return T({code:"ENTITY_NOT_FOUND",message:`entity ${e.id} not found`});if(ow(i,e.id))return T({code:"INVALID_OP",message:`Cannot remove entity ${e.id}: an opaque preserved ER segment references it`});i.entities.splice(o,1);sw(i,s=>s.from===e.id||s.to===e.id);if(i.statements)i.statements=i.statements.filter(s=>s.kind!=="entity"||s.id!==e.id);return re(i)}case"rename_entity":{const o=n(e.from);if(!o)return T({code:"ENTITY_NOT_FOUND",message:`entity ${e.from} not found`});if(!th(e.to)||e.to.includes(":::")||e.to.includes("[")){return T({code:"INVALID_OP",message:`ER entity id "${e.to}" must be a bare identifier`})}if(n(e.to))return T({code:"DUPLICATE_ENTITY",message:`entity ${e.to} already exists`});if(ow(i,e.from))return T({code:"INVALID_OP",message:`Cannot rename entity ${e.from}: an opaque preserved ER segment references it`});o.id=e.to;for(const s of i.statements??[])if(s.kind==="entity"&&s.id===e.from)s.id=e.to;for(const s of i.relations){if(s.from===e.from)s.from=e.to;if(s.to===e.from)s.to=e.to}return re(i)}case"set_entity_label":{const o=n(e.entity);if(!o)return T({code:"ENTITY_NOT_FOUND",message:`entity ${e.entity} not found`});const s=aw(e.label,"label");if(!s.ok)return s;if(s.value!==o.label)delete o.labelContent;if(s.value===void 0)delete o.label;else o.label=s.value;return re(i)}case"add_attribute":{const o=n(e.entity);if(!o)return T({code:"ENTITY_NOT_FOUND",message:`entity ${e.entity} not found`});if(!ic(e.text))return T({code:"INVALID_OP",message:'ER attribute must use: type name [PK, FK, UK] ["comment"]'});o.attributes.push({text:e.text});if(!Ca(i).some(s=>s.kind==="entity"&&s.id===o.id)){J1(i,o.id,{kind:"entity",id:o.id})}return re(i)}case"remove_attribute":{const o=n(e.entity);if(!o)return T({code:"ENTITY_NOT_FOUND",message:`entity ${e.entity} not found`});if(e.index<0||e.index>=o.attributes.length)return T({code:"ATTRIBUTE_NOT_FOUND",message:`attribute index ${e.index} out of range`});o.attributes.splice(e.index,1);return re(i)}case"add_relation":{if(!Object.hasOwn(cw,e.leftCard)||!Object.hasOwn(dw,e.rightCard)){return T({code:"INVALID_OP",message:"Invalid ER endpoint marker: parent is only writable on the left, before the relationship connector"})}if(!n(e.from))return T({code:"ENTITY_NOT_FOUND",message:`entity ${e.from} not found`});if(!n(e.to))return T({code:"ENTITY_NOT_FOUND",message:`entity ${e.to} not found`});i.relations.push({from:e.from,to:e.to,leftCard:e.leftCard,rightCard:e.rightCard,dashed:e.dashed??false,label:e.label});Ca(i).push({kind:"relation",ref:i.relations.length-1});return re(i)}case"remove_relation":{if(e.index<0||e.index>=i.relations.length)return T({code:"RELATION_NOT_FOUND",message:`relation index ${e.index} out of range`});sw(i,(o,s)=>s===e.index);return re(i)}case"set_direction":{i.direction=e.direction;const o=Ca(i);if(!o.some(s=>s.kind==="direction"))o.unshift({kind:"direction"});return re(i)}case"define_class":{if(!/^[\w-]+$/.test(e.name))return T({code:"INVALID_OP",message:"ER classDef name must contain only letters, digits, underscore, or hyphen"});const o=zt(e.style);if(!o.ok)return T({code:"INVALID_OP",message:o.reason==="MULTILINE"?"ER classDef style must be a single-line CSS-like property list":o.reason==="UNSAFE_PAINT"?ni(`define_class ${e.name}`,o.paint).message:"ER classDef style must contain at least one property:value pair"});const s=tw(`define_class ${e.name}`,o.value);if(s)return s;if(!i.classDefs)i.classDefs={};i.classDefs[e.name]=o.value;return re(i)}case"set_entity_class":{const o=n(e.entity);if(!o)return T({code:"ENTITY_NOT_FOUND",message:`entity ${e.entity} not found`});if(e.className===null)delete o.className;else{if(!zc(e.className))return T({code:"INVALID_OP",message:"ER class name must have a nonnumeric, nonkeyword spelling using letters, digits, underscore, or hyphen"});o.className=e.className}return re(i)}case"set_entity_style":{const o=n(e.entity);if(!o)return T({code:"ENTITY_NOT_FOUND",message:`entity ${e.entity} not found`});if(e.style===null)delete o.style;else{const s=zt(e.style);if(!s.ok)return T({code:"INVALID_OP",message:s.reason==="MULTILINE"?"ER entity style must be a single-line CSS-like property list":s.reason==="UNSAFE_PAINT"?ni(`set_entity_style ${e.entity}`,s.paint).message:"ER entity style must contain at least one property:value pair"});const a=tw(`set_entity_style ${e.entity}`,s.value);if(a)return a;o.style=s.value}return re(i)}default:return T({code:"INVALID_OP",message:Ve("er",e)})}}function fw(t,e){const r=[];if(t.entities.length===0&&t.relations.length===0&&(t.groups?.length??0)===0){r.push({code:"EMPTY_DIAGRAM"});return r}const i=new Set([...t.entities.map(o=>o.id),...(t.groups??[]).map(o=>o.id)]);const n=Ke(r,e);for(const o of t.groups??[])n(o.id,Ye(o.label,o.labelContent));for(const o of t.entities){if(o.label)n(o.id,Ye(o.label,o.labelContent));for(let s=0;s<o.attributes.length;s++){const a=ic(V1(o.attributes[s].text));if(!a)continue;const l=[a.type,a.name,a.keys.join(","),rb(a.comment??"",a.commentContent)];n(`${o.id}#a${s}`,bt(l.join("\n"),"literal"))}}for(let o=0;o<t.relations.length;o++){const s=t.relations[o];if(!i.has(s.from)||!i.has(s.to)){r.push({code:"EDGE_MISANCHORED",edge:`rel#${o}:${s.from}->${s.to}`,from:i.has(s.from)?s.from:void 0,to:i.has(s.to)?s.to:void 0})}if(s.label)n(`rel#${o}`,Ye(s.label,s.labelContent))}return r}var Xn=/^\d*(?:classDef|class|style|linkStyle|graph|flowchart|subgraph|end|interpolate)\b/;function Lm(t,e=false){Wu(t);return Object.values(t).every(r=>Ll(r,e))}function Sw(t){return[...t.classDefs.keys(),...[...t.classAssignments.values()].flatMap(Js)].every(e=>!Xn.test(e))&&[...t.classDefs.values()].every(e=>Lm(e,true))&&[...t.nodeStyles.values(),...t.linkStyles.values()].every(e=>Lm(e))}function ww(t){for(const e of t.nodes.keys())if(Xn.test(e))return e;for(const e of t.edges){if(Xn.test(e.source))return e.source;if(Xn.test(e.target))return e.target}return void 0}function Ko(t){return Xn.test(t)?{code:"INVALID_OP",message:`Flowchart node id "${t}" is read as a reserved token by Mermaid and has no portable vertex spelling`}:void 0}function Tw(t,e=t){try{const r=ai(t);if(ww(r)!==void 0||!Sw(r))return re({kind:"opaque",family:"flowchart",source:e});return re({kind:"flowchart",graph:r})}catch(r){if(r instanceof Ln&&r.resource==="sourceCharacters")throw r;return T([{code:"PARSE_FAILED",message:r instanceof Error?r.message:String(r)}])}}function vw(t){return Dn(t).flatMap(e=>Rl(e.text).map(r=>{const i=gr(r.text);const n=new Map;for(const l of i.regions)if(!n.has(l.start))n.set(l.start,l);const o=i.topLevel;const s=Dl(r.text,i);const a=oB(r.text,o);return{...r,group:e,scan:i,regionsByStart:n,pipeLabels:i.regions.filter(l=>l.kind==="pipe"&&l.closed&&l.parent===-1),topLevel:o,textLabelRanges:s,operatorRanges:a,operatorStarts:new Set(a.map(l=>l.start)),operatorEnds:new Set(a.map(l=>l.end))}}))}function Ew(t,e){const r={nodes:new Map,edges:new Map,groups:new Map,labels:new Map};const i=e.split(/\r?\n/);const n=vw(i);const o=rB(t.graph.nodes.keys());const s=new Map;const a=new Map;for(const d of n){for(const{id:u,column:h}of iB(d.text,o)){if(!Aw(d,u,h))continue;const m=a.get(d)??new Map;const f=m.get(u)??[];f.push(h);m.set(u,f);a.set(d,m);const p=s.get(u)??[];if(p.at(-1)!==d){p.push(d);s.set(u,p)}if(r.nodes.has(u))continue;r.nodes.set(u,Gc(d,h));const g=t.graph.nodes.get(u);const y=g?dB(d,g.label,h+u.length):-1;if(y>=0)r.labels.set(`node:${u}`,Gc(d,y))}}for(const d of t.graph.subgraphs)Ow(d,i,r);const l=new Map;const c=new Map;t.graph.edges.forEach((d,u)=>{const h=Yc(u,d);const m=`${d.source}->${d.target}`;const f=`${d.source}\0${d.target}\0${d.label??""}`;let p=c.get(f);if(!p){const C=new Set(s.get(d.target)??[]);const w=(s.get(d.source)??[]).filter(x=>C.has(x));p=w.flatMap(x=>{const k=a.get(x);const b=k.get(d.source)??[];const A=lB(b,d.source===d.target?b:k.get(d.target)??[],d.source.length,x.operatorRanges);return A.flatMap(L=>{const B=L.sourceCol+d.source.length;const O=eB(x,B,L.targetCol);if(!d.label)return O.length>0?[]:[{segment:x,sourceCol:L.sourceCol,labelCol:-1}];const M=Pm(x.text,d.label,O);return M>=0?[{segment:x,sourceCol:L.sourceCol,labelCol:M}]:[]})});c.set(f,p)}const g=l.get(f)??0;l.set(f,g+1);const y=p[Math.min(g,Math.max(0,p.length-1))];if(y){const{segment:C,sourceCol:w,labelCol:x}=y;const k=Gc(C,w);r.edges.set(h,k);if(!r.edges.has(m))r.edges.set(m,k);if(d.label&&x>=0){r.labels.set(h,Gc(C,x))}}});return r}function Gc(t,e){const r=Uu(t.group,t.start+e);return{line:r.line+1,col:r.col+1}}function Z1(t,e,r){const i=[];const n=t.pipeLabels;let o=0;let s=n.length;while(o<s){const a=o+Math.floor((s-o)/2);if(n[a].start<e)o=a+1;else s=a}for(let a=o;a<n.length&&n[a].start<r;a++){const l=n[a];if(l.contentEnd<r&&l.contentEnd>l.contentStart)i.push({start:l.contentStart,end:l.contentEnd})}return i}function eB(t,e,r){return[...Z1(t,e,r),...t.textLabelRanges.filter(i=>i.start>=e&&i.end<=r)].sort((i,n)=>i.start-n.start)}function tB(t,e,r){const i=t.slice(r.start,r.end);let n;try{n=_b(i).text}catch{n=void 0}if(n===e){let o=r.start+i.length-i.trimStart().length;if(t[o]==='"')o+=t[o+1]==="`"?2:1;return o}for(const o of new Set([e,Ks(e)])){const s=t.indexOf(o,r.start);if(s>=r.start&&s+o.length<=r.end)return s}return-1}function Pm(t,e,r){if(!e)return-1;for(const i of r){const n=tB(t,e,i);if(n>=0)return n}return-1}function Mw(t){const e=t.trim();return e==="end"||/^(?:graph|flowchart|swimlane|stateDiagram(?:-v2)?)(?:\s|$)/i.test(e)||/^(?:subgraph|direction|classDef|class|style|linkStyle|click|href)\b/i.test(e)}function Aw(t,e,r){const{text:i,topLevel:n,textLabelRanges:o,operatorStarts:s,operatorEnds:a}=t;if(Mw(i)||!n[r])return false;if(o.some(p=>r>=p.start&&r<p.end))return false;const l=i[r-1];const c=r+e.length;const d=i[c];let u=r;while(u>0&&/\s/.test(i[u-1]))u--;const h=o.some(p=>p.start>c&&/^(?:<)?(?:-{2,}|-\.+|={2,})\s*$/.test(i.slice(c,p.start)));const m=!pw(l)||a.has(r);const f=!pw(d)||s.has(c)||$m(Fm,i,c)>0||h;if(!m||!f)return false;if(i.slice(Math.max(0,u-3),u)===":::"||nB(i,c,s,o))return false;return!((e==="o"||e==="x")&&/^--[ox]/.test(i.slice(c,c+3))&&u>0&&i[u-1]!=="&"&&i[u-1]!=="|"&&!a.has(u))}function rB(t){const e={children:new Map};for(const r of t){let i=e;for(let n=0;n<r.length;n++){const o=r[n];let s=i.children.get(o);if(!s){s={children:new Map};i.children.set(o,s)}i=s};(i.ids??=[]).push(r)}return e}function iB(t,e){const r=[];for(let i=0;i<t.length;i++){let n=e;for(let o=i;o<t.length;o++){n=n.children.get(t[o]);if(!n)break;for(const s of n.ids??[])r.push({id:s,column:i})}}return r}var Fm=new RegExp(ko,"y");function $m(t,e,r){t.lastIndex=r;return t.exec(e)?.[0].length??0}function pw(t){return t!==void 0&&/[\p{L}\p{N}_!"#$%&'*+.`?\\/:-]/u.test(t)}function nB(t,e,r,i){if(t[e]!=="@")return false;let n=e+1;while(/\s/.test(t[n]??""))n++;if(r.has(n)||$m(Fm,t,n)>0)return true;return i.some(o=>o.start>n&&/^(?:<)?(?:-{2,}|-\.+|={2,})\s*$/.test(t.slice(n,o.start)))}function Yc(t,e){return`edge#${t}:${e.source}->${e.target}`}function oB(t,e){const r=[];for(let i=0;i<t.length;i++){if(!e[i])continue;const n=$m(Fm,t,i);if(n===0)continue;r.push({start:i,end:i+n});i+=n-1}return r}function sB(t,e){let r=0;let i=t.length;while(r<i){const n=r+Math.floor((i-r)/2);if(t[n]<e)r=n+1;else i=n}return r}function aB(t,e){let r=0;let i=t.length;while(r<i){const n=r+Math.floor((i-r)/2);if(t[n].start<e)r=n+1;else i=n}return r}function lB(t,e,r,i){const n=[];for(const o of t){const s=o+r;let a=aB(i,s);if(a>0&&i[a-1].end>s)a--;const l=i[a];if(!l)continue;const c=i[a+1]?.start??Number.POSITIVE_INFINITY;for(let d=sB(e,l.end);d<e.length;d++){const u=e[d];if(u>c)break;n.push({sourceCol:o,targetCol:u})}}return n}function cB(t,e,r){const i=gr(t).regions.find(n=>n.kind==="shape"&&n.closed&&n.start>=r);return Pm(t,e,[i?{start:i.contentStart,end:i.contentEnd}:{start:Math.max(0,r),end:t.length}])}function dB(t,e,r){const i=[];let n=r;let o=t.regionsByStart.get(n);if(o?.kind==="shape"&&o.closed){n=o.end;for(let a=t.regionsByStart.get(o.contentStart);a?.kind==="shape"&&a.closed&&a.end===o.contentEnd;a=t.regionsByStart.get(a.contentStart))o=a;i.push({start:o.contentStart,end:o.contentEnd})}const s=t.regionsByStart.get(n);if(s?.kind==="metadata"&&s.closed)i.push({start:s.contentStart,end:s.contentEnd});return Pm(t.text,e,i.reverse())}function Ow(t,e,r){const i=new RegExp(`^\\s*subgraph\\s+${uB(t.id)}(?=\\s|\\[|$)`,"i");for(let n=0;n<e.length;n++){const o=e[n];if(!i.test(o))continue;const s=o.indexOf(t.id);r.groups.set(t.id,{line:n+1,col:s+1});const a=t.label&&t.label!==t.id?cB(o,t.label,s+t.id.length):-1;if(a>=0)r.labels.set(`group:${t.id}`,{line:n+1,col:a+1});break}for(const n of t.children)Ow(n,e,r)}function uB(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Bw(t,e){const r=ww(t);if(r!==void 0)throw new Error(Ko(r).message);if(!Sw(t))throw new Error("Flowchart style contains tokens that cannot be written as Mermaid style properties");const i=[e==="state"?"stateDiagram-v2":`flowchart ${t.direction}`];const n=new Set;const o=new Set;const s=(a,l)=>{i.push(`${l}subgraph ${a.id}${a.label!==a.id?`[${Rw(a.label,a.labelContent)}]`:""}`);if(a.direction)i.push(`${l} direction ${a.direction}`);for(const c of a.children)s(c,l+" ");for(const c of a.nodeIds){const d=t.nodes.get(c);if(d&&Wc(d)){i.push(`${l} ${d.id}${Uc(d)}`);n.add(c)}else{i.push(`${l} ${c}`)}o.add(c)}i.push(`${l}end`)};for(const a of t.subgraphs)s(a," ");for(const a of t.edges){if(a.id)for(const c of[a.source,a.target]){const d=t.nodes.get(c);if(d&&!n.has(c)&&(d.authoredShape!==void 0||d.icon!==void 0||d.image!==void 0)){i.push(` ${c}${Uc(d)}`);n.add(c)}}i.push(" "+mB(a,t.nodes,n));const l=fB(a);if(l)i.push(" "+l)}for(const[a,l]of t.nodes){if(n.has(a)||o.has(a))continue;const c=t.edges.every(d=>d.source!==a&&d.target!==a);if(c&&!Wc(l)&&l.id.includes('"'))i.push(` ${l.id}`);else if(c||Wc(l))i.push(` ${l.id}${Uc(l)}`)}for(const[a,l]of t.classDefs)i.push(` classDef ${a} ${_m(l,true)}`);for(const[a,l]of t.classAssignments)for(const c of Js(l))i.push(` class ${a} ${c}`);for(const[a,l]of t.nodeStyles)i.push(` style ${a} ${_m(l)}`);for(const[a,l]of t.linkStyles){if(a==="default"||a<t.edges.length)i.push(` linkStyle ${a} ${_m(l)}`)}for(const a of t.nodes.values()){if(a.href)i.push(` click ${a.id} href ${hB(a.href)}`)}return i.join("\n")+"\n"}function Wc(t){return t.label!==t.id||t.shape!=="rectangle"||t.authoredShape!==void 0||t.icon!==void 0||t.image!==void 0}function Uc(t){if(t.icon!==void 0||t.image!==void 0){const r=[t.icon!==void 0?`icon: ${go(t.icon)}`:`img: ${go(t.image)}`,...t.iconForm?[`form: ${t.iconForm}`]:[],...t.label!==t.id?[`label: ${Rm(t.label,t.labelContent)}`]:[]];return`@{ ${r.join(", ")} }`}if(t.authoredShape!==void 0){const r=t.label!==t.id?`, label: ${Rm(t.label,t.labelContent)}`:"";return`@{ shape: ${t.authoredShape}${r} }`}const e=Rw(t.label,t.labelContent);switch(t.shape){case"rectangle":return`[${e}]`;case"rounded":return`(${e})`;case"ellipse":return`(-${e}-)`;case"stadium":return`([${e}])`;case"subroutine":return`[[${e}]]`;case"cylinder":return`[(${e})]`;case"circle":return`((${e}))`;case"doublecircle":return`(((${e})))`;case"asymmetric":return`>${e}]`;case"diamond":return`{${e}}`;case"hexagon":return`{{${e}}}`;case"trapezoid":return`[/${e}\\]`;case"trapezoid-alt":return`[\\${e}/]`;case"lean-r":return`[/${e}/]`;case"lean-l":return`[\\${e}\\]`;case"service":return`[${e}]`;case"state-start":case"state-end":case"state-fork":case"state-join":case"state-choice":case"state-history":return"";case"state-note":throw new Error("Floating State notes require the State serializer")}}function _w(t){return t.replace(/direction(?=\s+(?:TB|BT|RL|LR|TD))/g,"#100;irection")}function Iw(t,e){const r=_w(Ks(t,e));const i=e?.value===t&&e.authored?.startsWith("`")&&e.authored.endsWith("`");return`"${r.startsWith("`")&&!i?`#96;${r.slice(1)}`:r}"`}function Rm(t,e){return go(Ks(t,e).replace(/%%(?=\{)/g,"%#37;"))}function hB(t){const e=t.replace(/\r?\n/g,"<br>");return`"${e.replace(/["\\]/g,"\\$&")}"`}function Lw(t,e){if(t==="")return'" "';if(/[\[\]{}()|"@]|^~~~/.test(t)||e?.value===t&&e.authored?.startsWith("`"))return Iw(t,e);return _w(Ks(t,e))}function Rw(t,e){return/;|^[-/\\]/.test(t)?Iw(t,e):Lw(t,e)}function mB(t,e,r){const i=gw(t.source,e,r);const n=gw(t.target,e,r);const o=t.label?`|${Lw(t.label,t.labelContent)}|`:"";const s=t.id?`${t.id}@`:"";return`${i} ${s}${pB(t)}${o} ${n}`}function fB(t){if(!t.id)return null;const e=[...t.animate!==void 0?[`animate: ${t.animate}`]:[],...t.animation?[`animation: ${t.animation}`]:[],...t.curve?[`curve: ${t.curve}`]:[]];return e.length>0?`${t.id}@{ ${e.join(", ")} }`:null}function gw(t,e,r){const i=e.get(t);if(!i)return t;if(Wc(i)&&!r.has(t)){r.add(t);return`${t}${Uc(i)}`}return t}function pB(t){const e=t.hasArrowStart?yw(t.startMarker??"arrow",true):"";const r=t.hasArrowEnd?yw(t.endMarker??"arrow",false):"";const i=Math.max(0,(t.length??1)-1);switch(t.style){case"invisible":return"~".repeat(3+i);case"solid":return`${e}${"-".repeat((!t.hasArrowStart&&!t.hasArrowEnd?3:2)+i)}${r}`;case"dotted":return`${e}-${".".repeat(1+i)}-${r}`;case"thick":return`${e}${"=".repeat((!t.hasArrowStart&&!t.hasArrowEnd?3:2)+i)}${r}`}}function yw(t,e){if(t==="arrow")return e?"<":">";if(t==="circle")return"o";return"x"}function _m(t,e=false){const r=Object.entries(Wu(t));return r.map(([i,n],o)=>{const s=`${i}:${e?n.replace(/,/g,"\\,"):n}`;const a=e&&n.endsWith("\\")?" ,":",";return s+(o<r.length-1?a:"")}).join("")}function ka(t,e){return Pw(qw(t.graph),e)}function Dm(t){const e=st(t).familyBody;const r=ai(e);const i=Oy(t).familyBody;return[r,e===i?r:ai(i)]}function gB(t,e,r){const i=()=>T({code:"INVALID_OP",message:"Node rename requires complete lexical ownership; class/style/click references and colliding group identities are unsupported"});if(r.some(h=>!h.nodes.has(e.from)))return T({code:"NODE_NOT_FOUND",message:`Node "${e.from}" not found in both source views`});if(e.from===e.to)return re([]);const n=Ko(e.to);if(n)return T(n);if(r.some(h=>h.nodes.has(e.to)))return T({code:"DUPLICATE_NODE",message:`Node "${e.to}" already exists`});if(r.some(h=>h.classAssignments.has(e.from)||h.nodeStyles.has(e.from)||h.nodes.get(e.from)?.href!==void 0||Hn(h,e.from)||Hn(h,e.to)))return i();const o=wi(st(t),"authored");if(o.text.includes("\r"))return i();const s=vw(o.text.split("\n")),a=Bt(o.text);if(s.some(h=>/^(?:class|style|click|href)\b/i.test(h.text)))return i();const l=new Map;for(const h of s){if(h.group.directive||h.text.startsWith("%%")||Mw(h.text))continue;if([...h.text.matchAll(/%%/g)].some(m=>h.topLevel[m.index]))return i();for(let m=h.text.indexOf(e.from);m>=0;m=h.text.indexOf(e.from,m+e.from.length)){if(!Aw(h,e.from,m))continue;const f=Uu(h.group,h.start+m);const p=a[f.line]+f.col;const g=o.sourceOffset(p,"end"),y=o.sourceOffset(p+e.from.length,"start");if(t.slice(g,y)!==e.from)return i();l.set(g,{start:g,end:y,text:e.to})}}if(!l.size)return i();const c=[...l.values()],d=ya(t,c);const u=Dm(d);for(const[h,m]of r.entries()){if(h===1&&m===r[0]&&u[1]===u[0])continue;const f=ka({kind:"flowchart",graph:m},e);if(!f.ok)return f;const p=g=>g===e.from?e.to:g;f.value.graph.nodes=new Map([...m.nodes.keys()].map(g=>[p(g),f.value.graph.nodes.get(p(g))]));if(!Ni(f.value.graph,u[h]))return i()}return re(c)}function Dw(t,e){if(e.kind!=="set_label"&&e.kind!=="rename_node")return T({code:"INVALID_OP",message:"Source-preserving Flowchart edits support set_label and owned rename_node only"});try{const r=Dm(t);if(e.kind==="rename_node")return gB(t,e,r);if(r.some(c=>!c.nodes.has(e.target)))return T({code:"NODE_NOT_FOUND",message:`Source-preserving Flowchart label target "${e.target}" must name an existing native node in both source views`});const i=e.label.trim();if(r.every(c=>c.nodes.get(e.target).label===i))return re([]);const n=ka({kind:"flowchart",graph:r[0]},e);const o=[n,r[1]===r[0]?n:ka({kind:"flowchart",graph:r[1]},e)];const s=Nc(t,`${e.target}@{ label: ${Rm(i)} }`);const a=ya(t,s);const l=Dm(a);for(let c=0;c<r.length;c++){if(c===1&&r[1]===r[0]&&l[1]===l[0])continue;const d=o[c];if(!d.ok)return d;if(!Ni(d.value.graph,l[c]))return T({code:"INVALID_OP",message:"Source-preserving Flowchart label cannot be written without changing the requested value or another native graph field"})}return re(s)}catch(r){return T({code:"INVALID_OP",message:`Source-preserving Flowchart label could not be verified: ${r instanceof Error?r.message:String(r)}`})}}function Nw(t){const e=qw(t.graph);return r=>Pw(e,r)}function Pw(t,e){const r=()=>re({kind:"flowchart",graph:t});switch(e.kind){case"add_node":{const i=Ko(e.id);if(i)return T(i);if(t.nodes.has(e.id))return T({code:"DUPLICATE_NODE",message:`Node "${e.id}" already exists`});const n=bw(e.shape??"rectangle");if(!n){return T({code:"INVALID_OP",message:`Unknown shape "${e.shape}" \u2014 pass a geometry (${Nm.join(", ")}) or a Mermaid v11 @{ shape } name/alias (e.g. manual-input, document, delay)`})}t.nodes.set(e.id,{id:e.id,label:e.label.trim(),shape:n.shape,...n.semanticShape!==void 0?{semanticShape:n.semanticShape,authoredShape:n.authoredShape}:{}});if(e.parent){const o=Hn(t,e.parent);if(!o)return T({code:"INVALID_OP",message:`Parent group "${e.parent}" not found`});o.nodeIds.push(e.id)}return r()}case"remove_node":{if(!t.nodes.has(e.id))return T({code:"NODE_NOT_FOUND",message:`Node "${e.id}" not found`});t.nodes.delete(e.id);Im(t,i=>i.source!==e.id&&i.target!==e.id);for(const i of t.subgraphs)jc(i,e.id);t.classAssignments.delete(e.id);t.nodeStyles.delete(e.id);return r()}case"rename_node":{const i=Ko(e.to);if(i)return T(i);if(!t.nodes.has(e.from))return T({code:"NODE_NOT_FOUND",message:`Node "${e.from}" not found`});if(t.nodes.has(e.to))return T({code:"DUPLICATE_NODE",message:`Cannot rename to "${e.to}" \u2014 already exists`});const n=t.nodes.get(e.from);t.nodes.delete(e.from);t.nodes.set(e.to,{...n,id:e.to,label:n.label===e.from?e.to:n.label});for(const o of t.edges){if(o.source===e.from)o.source=e.to;if(o.target===e.from)o.target=e.to}for(const o of t.subgraphs)$w(o,e.from,e.to);if(t.classAssignments.has(e.from)){t.classAssignments.set(e.to,t.classAssignments.get(e.from));t.classAssignments.delete(e.from)}if(t.nodeStyles.has(e.from)){t.nodeStyles.set(e.to,t.nodeStyles.get(e.from));t.nodeStyles.delete(e.from)}return r()}case"set_label":{if(t.nodes.has(e.target)){const n=t.nodes.get(e.target);if(e.label.trim()!==n.label)delete n.labelContent;t.nodes.set(e.target,{...n,label:e.label.trim()});return r()}const i=Vc(t,e.target);if(i>=0){const n=t.edges[i],o=xw(e.label);if(o!==n.label)delete n.labelContent;n.label=o;return r()}return T({code:"NODE_NOT_FOUND",message:`Target "${e.target}" matches no node or edge`})}case"add_edge":{const i=Ko(e.from)??Ko(e.to);if(i)return T(i);kw(t,e.from);kw(t,e.to);t.edges.push({source:e.from,target:e.to,label:xw(e.label),style:e.style??"solid",hasArrowStart:false,hasArrowEnd:true});return r()}case"remove_edge":{const i=Vc(t,e.id);if(i<0)return T({code:"EDGE_NOT_FOUND",message:`Edge "${e.id}" not found \u2014 pass an authored edge ID (e1), "from->to", or "from->to#k" for the k-th parallel edge`});Im(t,(n,o)=>o!==i);return r()}case"set_shape":{const i=t.nodes.get(e.id);if(!i)return T({code:"NODE_NOT_FOUND",message:`Node "${e.id}" not found`});const n=bw(e.shape);if(!n){return T({code:"INVALID_OP",message:`Unknown shape "${e.shape}" \u2014 pass a geometry (${Nm.join(", ")}) or a Mermaid v11 @{ shape } name/alias (e.g. manual-input, document, delay)`})}t.nodes.set(e.id,{...i,shape:n.shape,semanticShape:n.semanticShape,authoredShape:n.authoredShape});return r()}case"set_direction":{if(e.subgraph!==void 0&&e.subgraph!==null){const i=Hn(t,e.subgraph);if(!i)return T({code:"GROUP_NOT_FOUND",message:`Subgraph "${e.subgraph}" not found`});i.direction=e.direction;return r()}t.direction=e.direction;return r()}case"add_subgraph":{if(Hn(t,e.id))return T({code:"INVALID_OP",message:`Subgraph "${e.id}" already exists`});if(t.nodes.has(e.id))return T({code:"INVALID_OP",message:`Identifier "${e.id}" is already a node \u2014 subgraph ids and node ids share one namespace`});const i=[];for(const o of e.members??[]){if(!t.nodes.has(o))return T({code:"NODE_NOT_FOUND",message:`Member node "${o}" not found \u2014 add_node it first`});i.push(o)}const n={id:e.id,label:e.label?.trim()??e.id,nodeIds:[],children:[]};if(e.parent!==void 0&&e.parent!==null){const o=Hn(t,e.parent);if(!o)return T({code:"GROUP_NOT_FOUND",message:`Parent subgraph "${e.parent}" not found`});o.children.push(n)}else{t.subgraphs.push(n)}for(const o of i){for(const s of t.subgraphs)jc(s,o);n.nodeIds.push(o)}return r()}case"remove_subgraph":{const i=yB(t,e.id);if(!i)return T({code:"GROUP_NOT_FOUND",message:`Subgraph "${e.id}" not found`});const{list:n,index:o}=i;const s=n[o];if(e.removeMembers){const a=new Set(Fw(s));for(const l of a){t.nodes.delete(l);t.classAssignments.delete(l);t.nodeStyles.delete(l)}Im(t,l=>!a.has(l.source)&&!a.has(l.target));n.splice(o,1);return r()}n.splice(o,1,...s.children);return r()}case"move_node":{if(!t.nodes.has(e.id))return T({code:"NODE_NOT_FOUND",message:`Node "${e.id}" not found`});const i=e.subgraph===null?null:Hn(t,e.subgraph);if(e.subgraph!==null&&!i)return T({code:"GROUP_NOT_FOUND",message:`Subgraph "${e.subgraph}" not found`});for(const n of t.subgraphs)jc(n,e.id);if(i)i.nodeIds.push(e.id);return r()}case"define_class":{if(!/^[\w-]+$/.test(e.name)||Xn.test(e.name))return T({code:"INVALID_OP",message:"Class name must contain only letters, digits, underscore, or hyphen and must not collide with a Mermaid keyword"});const i=Cw(e.style,`define_class ${e.name}`,"fill:#f96,stroke:#333",true);if("message"in i)return T({code:"INVALID_OP",message:i.message});t.classDefs.set(e.name,i.value);return r()}case"set_node_class":{if(!t.nodes.has(e.id))return T({code:"NODE_NOT_FOUND",message:`Node "${e.id}" not found`});if(e.className===null)t.classAssignments.delete(e.id);else{if(!/^[\w-]+$/.test(e.className)||Xn.test(e.className))return T({code:"INVALID_OP",message:"Class name must contain only letters, digits, underscore, or hyphen and must not collide with a Mermaid keyword"});t.classAssignments.set(e.id,e.className)}return r()}case"set_node_style":{if(!t.nodes.has(e.id))return T({code:"NODE_NOT_FOUND",message:`Node "${e.id}" not found`});if(e.style===null){t.nodeStyles.delete(e.id);return r()}const i=Cw(e.style,`set_node_style ${e.id}`,"fill:#bbf,stroke-width:2px");if("message"in i)return T({code:"INVALID_OP",message:i.message});t.nodeStyles.set(e.id,i.value);return r()}default:{const i=e;return T({code:"INVALID_OP",message:Ve("flowchart",i)})}}}function xw(t){return t?.trim()||void 0}var Nm=["rectangle","service","rounded","diamond","stadium","circle","ellipse","subroutine","doublecircle","hexagon","cylinder","asymmetric","trapezoid","trapezoid-alt","lean-r","lean-l","state-start","state-end"];function bw(t){if(Nm.includes(t)){return{shape:t}}const e=fc(t);if(!e)return null;return{shape:e.geometry,semanticShape:e.canonical,authoredShape:t}}function Cw(t,e,r,i=false){const n=zt(t);if(n.ok){try{if(!Lm(n.value,i))return{message:"Flowchart style value cannot be written losslessly by Mermaid inline-style tokens"};return{value:n.value}}catch(o){return{message:o instanceof Error?o.message:String(o)}}}if(n.reason==="UNSAFE_PAINT")return{message:ni(e,n.paint).message};return{message:`Style "${t}" parses to no properties \u2014 expected CSS-like pairs such as "${r}"`}}function yB(t,e){const r=i=>{for(let n=0;n<i.length;n++){if(i[n].id===e)return{list:i,index:n};const o=r(i[n].children);if(o)return o}return null};return r(t.subgraphs)}function Fw(t){const e=[...t.nodeIds];for(const r of t.children)e.push(...Fw(r));return e}function Im(t,e){const r=t.edges;const i=new Map;const n=[];r.forEach((s,a)=>{if(!e(s,a))return;i.set(a,n.length);n.push(s)});const o=new Map;for(const[s,a]of t.linkStyles){if(s==="default"||!Number.isInteger(s)||s<0||s>=r.length){o.set(s,a);continue}const l=i.get(s);if(l!==void 0)o.set(l,a)}t.edges=n;t.linkStyles=o}function K2(t,e=0){return e===0?`${t.source}->${t.target}`:`${t.source}->${t.target}#${e}`}function Vc(t,e){return Db(t.edges).get(e)??-1}function kw(t,e){if(!t.nodes.has(e))t.nodes.set(e,{id:e,label:e,shape:"rectangle"})}function Hn(t,e){const r=i=>{for(const n of i){if(n.id===e)return n;const o=r(n.children);if(o)return o}return null};return r(t.subgraphs)}function jc(t,e){t.nodeIds=t.nodeIds.filter(r=>r!==e);for(const r of t.children)jc(r,e)}function $w(t,e,r){t.nodeIds=t.nodeIds.map(i=>i===e?r:i);for(const i of t.children)$w(i,e,r)}function qw(t){return{direction:t.direction,nodes:new Map(Array.from(t.nodes,([e,r])=>[e,{...r}])),edges:t.edges.map(e=>({...e})),subgraphs:t.subgraphs.map(zw),classDefs:new Map(Array.from(t.classDefs,([e,r])=>[e,{...r}])),classAssignments:new Map(t.classAssignments),nodeStyles:new Map(Array.from(t.nodeStyles,([e,r])=>[e,{...r}])),linkStyles:new Map(Array.from(t.linkStyles,([e,r])=>[e,{...r}]))}}function zw(t){return{id:t.id,label:t.label,...t.labelContent?{labelContent:t.labelContent}:{},nodeIds:[...t.nodeIds],children:t.children.map(zw),direction:t.direction}}function Gw(t){const e=qm(t);const r=Vw(e);return e.some(({text:i})=>Ww(i)||SB(i)||wB(i)||Yw(i,r)||jw(i))}function sq(t){const e=[];const r=qm(t);const i=Vw(r);const n=_B(r);for(const{text:o,line:s}of r){if(Yw(o,i)){e.push({code:"UNSUPPORTED_SYNTAX",line:s,syntax:"flowchart_edge_metadata",message:"Unsupported edge metadata is source-preserved and ignored by the local renderer/layout; animate, animation, and curve are modeled, and an unknown label key is not reinterpreted as a phantom node."})}if(IB(o,n)){e.push({code:"UNSUPPORTED_SYNTAX",line:s,syntax:"flowchart_implicit_endpoint",message:"A bare implicit edge endpoint closely matches another declared node id. Check it for a typo; Mermaid creates a new node instead of rejecting it."})}if(EB(o)){e.push({code:"UNSUPPORTED_SYNTAX",line:s,syntax:"flowchart_node_metadata",message:"Flowchart node metadata with an undocumented shape name is preserved as source. Documented v11 shape/label/icon/img metadata is modeled."})}if(vB(o)){e.push({code:"UNSUPPORTED_SYNTAX",line:s,syntax:"flowchart_image_placeholder",message:"Flowchart img metadata is typed and preserved, but static offline rendering uses a deterministic placeholder instead of fetching the authored URL."})}if(jw(o)){e.push({code:"UNSUPPORTED_SYNTAX",line:s,syntax:"flowchart_interaction_directive",message:"Flowchart callbacks and unsafe href directives are preserved but never made executable; safe http(s)/mailto hrefs render as inert data-href metadata."})}if(Ww(o)){e.push({code:"UNSUPPORTED_SYNTAX",line:s,syntax:"flowchart_markdown_string",message:"Flowchart markdown strings render with bold/italic styled runs, explicit breaks, and wrapping, but remain source-preserved rather than structurally mutable. The source is preserved verbatim."})}const a=OB(o);if(a){e.push({code:"UNSUPPORTED_SYNTAX",line:s,syntax:a.syntax,message:a.message})}}return e}function aq(t){const e=qm(t);const r=[];const i=[];const n=Rb();for(const{text:o,line:s}of e){if(/^subgraph(?![\w-])/.test(o)&&/direction\s+(?:TB|BT|RL|LR|TD)/.test(o))r.push({code:"UNSUPPORTED_SYNTAX",line:s,syntax:"flowchart_subgraph_direction_text",message:"Direction-like text in a subgraph title is read as its label. Pinned Mermaid consumes the whole line as a direction token, even inside quotes; canonical export protects the label with an entity code."});if(/^subgraph(?![\w-])/.test(o))i.push(s);else if(o==="end"&&i.length>0)i.pop();else if(o==="end"){r.push({code:"UNSUPPORTED_SYNTAX",line:s,syntax:"flowchart_stray_end",message:"An `end` with no subgraph open closes nothing and is ignored. Pinned Mermaid rejects this; remove it."})}const a=o.startsWith("subgraph")||/[@[\](){}|"]/.test(o)?pc(o.includes("<")?Si(o).upstreamText:o,n):void 0;if(/^(?:style|classDef|linkStyle)\s/.test(o)&&gr(o).separators.length>0){r.push({code:"UNSUPPORTED_SYNTAX",line:s,syntax:"flowchart_style_semicolon",message:"A `;` between style properties (fill:#f9f;stroke:#0a0) is read as separating them, as in CSS. Pinned Mermaid ends the statement at the `;` and reads the next property as a node (stroke:blue), or, after a `#` color, joins the two into one declaration that paints nothing; separate style properties with `,`."})}const l=/^(?:style|classDef)\s+\S+\s+(.+)$/.exec(o)??/^linkStyle\s+(?:default|[\d,\s]+)\s+(.+)$/.exec(o);const c=l&&Object.entries(Ti(l[1])).find(([,d])=>!Ll(d,l[0].startsWith("classDef")));if(c)r.push({code:"UNSUPPORTED_SYNTAX",line:s,syntax:"flowchart_style_value",message:`Flowchart style ${c[0]}:${c[1]} is read as native CSS, but pinned Mermaid's inline-style tokens cannot preserve it. The source and drawing are retained; typed style editing is unavailable.`});if(a?.has("empty-string")){r.push({code:"UNSUPPORTED_SYNTAX",line:s,syntax:"flowchart_empty_string",message:'An empty quoted label (A[""], A -->|""| B, subgraph S[""]) is read as an empty label. Pinned Mermaid reads no empty string, and rejects this; put a blank between the quotes (A[" "]), which reads back as an empty label.'})}if(a?.has("empty-pipe-label")){r.push({code:"UNSUPPORTED_SYNTAX",line:s,syntax:"flowchart_empty_pipe_label",message:"A pipe label with nothing between its pipes (A -->|| B) is read as a link with no label. Pinned Mermaid reads no pipe label without text, and rejects this; leave the pipes out (A --> B), as the writer does, or put a blank between them (A -->| | B)."})}if(a?.has("subgraph-title")){r.push({code:"UNSUPPORTED_SYNTAX",line:s,syntax:"flowchart_subgraph_title",message:'This subgraph title is read as its text. Without quotes, pinned Mermaid reads only letters, digits, blanks, the backtick and !#$%&\'*+-./:?\\^_ in a title, with no link, `:::` or `"` starting a word, and rejects this one; quote the title (subgraph "a (b)"), or give an id and a quoted bracket title (subgraph id["a (b)"]).'})}if(a?.has("node-edge-id")){r.push({code:"UNSUPPORTED_SYNTAX",line:s,syntax:"flowchart_node_edge_id",message:'Text that runs on without a blank to an `@`, from a node or subgraph id into its label (A[a@b]) or from the opening pipe of a pipe label (A -->|a@b| B), is read as the id and the label. Pinned Mermaid reads that run as an edge id (any run without blanks or `"` before `@`), and rejects the statement; quote the label (A["a@b"], A -->|"a@b"| B), or put a blank after its opening bracket or pipe.'})}if(a?.has("duplicate-edge-id")){r.push({code:"UNSUPPORTED_SYNTAX",line:s,syntax:"flowchart_duplicate_edge_id",message:"A link whose edge id an earlier link already has (A e1@--> B, then C e1@--> D) is drawn without it: the id names the first link alone, and the writer leaves it off the later one. Pinned Mermaid accepts this and does the same, giving the later link an id of its own; give each link its own edge id."})}if(a?.has("label-delimiter")){r.push({code:"UNSUPPORTED_SYNTAX",line:s,syntax:"flowchart_label_delimiter",message:'Label text holding `(`, `)`, `[`, `]`, `{`, `}`, `|`, or a `"` after the text begins, is read as written. Pinned Mermaid reads these as delimiters in unquoted text, and rejects this; put the whole label in double quotes (A["a (b) c"]), writing a `"` inside it as #quot;.'})}for(const d of gr(o).regions){if(d.kind==="metadata"&&(o.slice(d.start,d.contentStart)!=="@{"||/\s/.test(o[d.start-1]??""))){r.push({code:"UNSUPPORTED_SYNTAX",line:s,syntax:"flowchart_metadata_spacing",message:`A @{\u2026} metadata block with a space before "@" or inside "@{" is read as its node's metadata. Pinned Mermaid rejects this; write id@{ \u2026 } with no space.`})}if(d.kind==="edge-text"&&lx(o,d.start)?.mixed){r.push({code:"UNSUPPORTED_SYNTAX",line:s,syntax:"flowchart_mixed_link_label",message:"A link label opened with one stroke and closed by a link of another (A -- b ==> B) is read as one labelled link. Pinned Mermaid rejects this; close the label with a link of its own stroke (A == b ==> B), or use a pipe label (A ==>|b| B)."})}}}for(const o of i){r.push({code:"UNSUPPORTED_SYNTAX",line:o,syntax:"flowchart_unclosed_subgraph",message:"A subgraph with no `end` holds everything after it, to the end of the diagram. Pinned Mermaid rejects this; close it with `end`."})}return[...r,...xB(t),...kB(t,e)]}function xB(t){const e=t.split(/\r?\n/);const r=[];for(const i of Dn(e)){if(i.directive||!i.text.includes(";")||i.text.trimStart().startsWith("%%"))continue;const n=gr(i.text);const o=Rl(i.text,n);const s=new Set(n.separators.filter(a=>!o.some(l=>a>l.start&&a<l.start+l.text.length)));for(const a of[{at:0,line:i.line,col:0},...i.joined??[]]){if(bB(e[a.line]).some(l=>l>=a.col&&s.has(a.at+l-a.col))){r.push({code:"UNSUPPORTED_SYNTAX",line:a.line+1,syntax:"flowchart_entity_semicolon",message:"Ours ends a statement at a `;` here. Pinned Mermaid reads `#name;` as an entity code, and drops the last `;` of a line where `style` or `classDef` comes before `:\u2026#`, so there the `;` ends nothing: it rejects the line, or reads the text after the `;` into the statement. Drop the `;`, and put any statement after it on its own line."})}}}return r}function bB(t){if(!t.includes(";"))return[];const e=tn(t);const r=[];const i=[];for(let n=0,o=0;n<t.length;n++){if(o<e.length&&t[n]===e[o])r[o++]=n;else if(t.slice(n+1).trim()!=="")i.push(n)}for(const n of e.matchAll(/#\w+;/g))i.push(r[n.index+n[0].length-1]);return i}var CB=/^linkStyle\s+([\d,\s]+)\s+(.+)$/;function kB(t,e){const r=e.flatMap(({text:l,line:c},d)=>{const u=l.match(CB);const h=u?u[1].split(",").map(m=>Number.parseInt(m.trim(),10)).filter(Number.isInteger):[];return h.length>0?[{at:d,line:c,indices:h}]:[]});if(r.length===0)return[];const i=t.split(/\r?\n/,1)[0];const n=l=>{try{return ai([i,...e.slice(0,l).map(c=>c.text)].join("\n")).edges.length}catch{return void 0}};const o=n(e.length);const s=n(r[0].at);if(o===void 0||s===void 0)return[];const a=[];for(const{at:l,line:c,indices:d}of r){const u=d.filter(m=>m>=s);if(u.length===0)continue;const h=n(l)??s;for(const m of u.filter(f=>f>=h)){const f=m>=o?`linkStyle ${m} names no link (the flowchart has ${o}), so it styles nothing. Pinned Mermaid rejects this; ${o===0?"remove it":`use an index from 0 to ${o-1}, counting links in source order`}.`:`linkStyle ${m} comes before the link it styles, and styles it. Pinned Mermaid rejects this; put the linkStyle after that link.`;a.push({code:"UNSUPPORTED_SYNTAX",line:c,syntax:"flowchart_link_style_index",message:f})}}return a}function Ww(t){return t.includes('"`')&&gr(t).regions.some(e=>e.kind==="markdown")}function Hc(t){const e=[];if(!t.includes("@"))return e;for(const r of gr(t).regions){if(r.kind!=="metadata")continue;const i=Rs(t,r.contentStart-1,"flowchart");if(!i.ok)break;e.push(i.entries)}return e}function Uw(t){if(t.size===0)return false;const e=new Set(["shape","label","icon","img","form","pos","h","w","constraint"]);for(const i of t.keys())if(!e.has(i))return false;if(!t.has("shape"))return true;const r=Wy(t.get("shape"))?.trim();return r!==void 0&&fc(r)!==null}function SB(t){return Hc(t).some(e=>!Uw(e)&&!TB(e))}function wB(t){return Hc(t).some(e=>[...e.keys()].some(r=>["pos","h","w","constraint"].includes(r)))}function TB(t){return t.size>0&&[...t.keys()].every(e=>e==="animate"||e==="animation"||e==="curve")}function vB(t){return Hc(t).some(e=>e.has("img"))}function EB(t){return Hc(t).some(e=>Hw(e)&&!Uw(e))}var MB=/^(?:subgraph\s|end$|direction\s|classDef\s|class\s|style\s|linkStyle\s|click\s|href\s)/i;var AB=new RegExp(String.raw`[\p{L}\p{N}_\])}](?:\s+|(?!\.))${ko}(?:\s*\|[^|]*\|)?\s*$`,"u");function OB(t){if(t==="subgraph"){return{syntax:"flowchart_untitled_subgraph",message:'A subgraph with neither an id nor a title cannot be read: pinned Mermaid fails on it, and ours rejects it. Give it an id or a title (subgraph S, or subgraph S["Stage one"]).'}}if(MB.test(t))return null;const e=gr(t);if(e.regions.some(i=>i.kind==="metadata"||i.kind==="markdown"))return null;const r=/,|[xo](?:--|-\.|==)/.test(t)?pc(t):void 0;if(r?.has("comma-id")){return{syntax:"flowchart_comma_id",message:'A "," in a node id (right after its characters, or where a node begins) is part of the id in Mermaid (`A,B` and `,A` are one node there). Ours reads no "," in a node id and rejects the statement; rename the node, or write `A & B` to list two nodes.'}}if(r?.has("link-markers")){return{syntax:"flowchart_link_markers",message:"A link label opened with an `x` or `o` marker and closed by a link with another end (A x-- a --> B) is a link of no type in Mermaid. Ours rejects it; put the same marker at both ends (A x-- a --x B), or none (A -- a --> B)."}}if(AB.test(t)){return{syntax:"flowchart_dangling_edge",message:"Dangling edge operator has no target, so Mermaid rejects the diagram. Add the endpoint or remove the operator."}}if(e.openAtEnd.length>0&&pc(t).has("label-delimiter"))return null;if(e.openAtEnd.includes("string")){return{syntax:"flowchart_unclosed_quote",message:"Unclosed double quote \u2014 the parser drops or mangles everything after it (labels, arrows, edges). Close the quote."}}if(e.openAtEnd.includes("pipe")){return{syntax:"flowchart_unclosed_pipe",message:"Unclosed |edge label| delimiter \u2014 the parser drops the label and the edge target after it. Close the label with a second |."}}if(e.openAtEnd.includes("shape")){return{syntax:"flowchart_unclosed_bracket",message:"Unclosed bracket \u2014 the parser drops or mangles everything after it, including arrows and edges (e.g. `A[Start --> B` loses the A\u2192B edge). Close the bracket or quote the label."}}return null}function qm(t){const e=[];for(const{text:r,line:i,directive:n,joined:o}of Dn(t.split(/\r?\n/))){if(n){const a=ct(r.split("\n"),0)?.suffixLine??"";for(const l of Th(a))e.push({text:l,line:(o?.at(-1)?.line??i)+1});continue}const s=i===0?Lb(r.trim())?.statements??[]:Th(r);for(const a of s){const l=a.trim();if(!l||l.startsWith("%%"))continue;e.push({text:l,line:i+1})}}return e}function BB(t){return/^(?:click|href)\s+/i.test(t.trim())}function jw(t){if(!BB(t))return false;return!/^(?:click\s+)?\S+\s+(?:href\s+)?(?:"(?:https?:|mailto:)[^"]*"|(?:https?:|mailto:)\S+)\s*$/i.test(t.trim())}function Vw(t){const e=new Set;const r=new RegExp(String.raw`(?:^|\s)(${sx})@\s*(?:${ko}|--)`,"gu");for(const{text:i}of t){let n;while((n=r.exec(i))!==null)e.add(n[1])}return e}function Yw(t,e){const r=t.trim();const i=ax(r);const n=i>0?/^\s*@\s*\{/.exec(r.slice(i)):null;if(!n)return false;const o=Rs(r,i+n[0].length-1,"flowchart");if(!o.ok||r.slice(o.end+1).trim()!=="")return false;const{entries:s}=o;if(e.has(r.slice(0,i)))return[...s.keys()].some(a=>a!=="animate"&&a!=="animation"&&a!=="curve");if(Hw(s))return false;return[...s.keys()].some(a=>a!=="animate"&&a!=="animation"&&a!=="curve")}function _B(t){const e=new Set;const r=/(?:^|\s)([A-Za-z_][\w-]*)\s*(?=\[|\(|\{|>|@\s*\{)/g;for(const{text:i}of t){const n=i.trim().match(/^([A-Za-z_][\w-]*)$/);if(n)e.add(n[1]);let o;while((o=r.exec(i))!==null)e.add(o[1])}return e}function IB(t,e){const r=`(?:${ko})`;const i=String.raw`([A-Za-z_][\w-]*)(\s*(?:\[[^\]]*\]|\([^)]*\)|\{[^}]*\}))?`;const n=t.match(new RegExp(`^\\s*${i}\\s*${r}\\s*${i}\\s*$`));if(!n)return false;const o=[{id:n[1],shaped:Boolean(n[2])},{id:n[3],shaped:Boolean(n[4])}];return o.some(({id:s,shaped:a})=>{if(a||s.length<4||e.has(s))return false;return[...e].some(l=>LB(l.toLowerCase(),s.toLowerCase()))})}function LB(t,e){if(t===e||Math.abs(t.length-e.length)>1)return false;if(t.length===e.length){const a=[];for(let l=0;l<t.length;l++)if(t[l]!==e[l])a.push(l);return a.length===1||a.length===2&&a[1]===a[0]+1&&t[a[0]]===e[a[1]]&&t[a[1]]===e[a[0]]}const[r,i]=t.length<e.length?[t,e]:[e,t];let n=0;let o=0;let s=false;while(n<r.length&&o<i.length){if(r[n]===i[o]){n++;o++;continue}if(s)return false;s=true;o++}return true}function Hw(t){return t.has("shape")||t.has("label")||t.has("icon")||t.has("img")}function RB(t){return t?.kind==="opaque-block"&&Array.isArray(t.lines)}function $i(t,e,r){const i=t[t.length-1];if(RB(i))i.lines.push(...e);else t.push(r([...e]))}var Kc=/^[\w-]+$/;function xq(t){const e=oi(t.split(/\r?\n/));const r=e.flatMap(i=>i.kind==="task"&&db(i.labelSource)?[{code:"UNSUPPORTED_SYNTAX",syntax:"gantt_task_label",line:i.startLine,message:`Task label "${i.label}" is drawn literally. Pinned Mermaid reads part of its authored spelling as a directive, keyword, date, or click action; the writer protects that token with an entity code.`}]:[]);return r.concat(e.flatMap((i,n)=>i.kind==="comment"&&e[n-1]?.kind==="task"&&e[n-1].endLine===i.startLine?[{code:"UNSUPPORTED_SYNTAX",syntax:"gantt_inline_task_comment",line:i.startLine,message:"Inline task metadata comments are read as comments. Pinned Mermaid reads them into the end date; put %% comments on their own line for portability."}]:i.afterSemicolon?[{code:"UNSUPPORTED_SYNTAX",syntax:"gantt_semicolon_separator",line:i.startLine,message:"A `;` after task data or a date or format value is read as a statement separator. Pinned Mermaid reads what follows it into the next task's label (`; Task`), or rejects it; put each statement on its own line."}]:[]))}function iT(t,e){const r=e??t;const i={kind:"gantt",sections:[],statements:[]};const n=i.statements;const o=new Set;let s=-1;let a=0;let l=0;const c=()=>{if(s===-1){i.sections.push({id:`section-${a++}`,tasks:[]});s=i.sections.length-1}return s};for(const d of oi(r)){if(d.kind==="blank")continue;if(d.kind==="invalid"&&d.structural)return null;if(d.kind==="directive"&&d.name==="axisFormat"){i.axisFormat=d.value;continue}if(d.kind==="comment"){$i(n,d.raw.map(wo),Xw);continue}if(d.kind==="title"){if(d.value.includes("%%{"))return null;i.title=d.value;n.push({kind:"title"});continue}if(d.kind==="section"){if(d.value.includes("%%{"))return null;i.sections.push({id:`section-${a++}`,label:d.value,tasks:[]});s=i.sections.length-1;n.push({kind:"section",ref:s});continue}if(d.kind==="task"){const{label:u,meta:h}=d;if(h.id!==void 0){if(o.has(h.id))return null;o.add(h.id)}const m=c();const f={id:`task-${l++}`,taskId:h.id,label:u,tags:Sa(h.tags),start:h.start?h.start.kind==="after"?`after ${h.start.refs.join(" ")}`:h.start.raw:void 0,end:h.end.kind==="until"?`until ${h.end.refs.join(" ")}`:h.end.raw};i.sections[m].tasks.push(f);n.push({kind:"task",section:m,ref:i.sections[m].tasks.length-1});continue}$i(n,d.raw,Xw)}return i}function Sa(t){return ah.filter(e=>t.includes(e))}var Xw=t=>({kind:"opaque-block",lines:t});function nT(t){return{tags:Sa(t.tags),id:t.taskId,start:t.start===void 0?void 0:t.start.startsWith("after ")?{kind:"after",refs:t.start.slice("after ".length).split(/\s+/).filter(Boolean)}:{kind:"date",raw:t.start},end:t.end.startsWith("until ")?{kind:"until",refs:t.end.slice("until ".length).split(/\s+/).filter(Boolean)}:{kind:"date",raw:t.end}}}function zm(t){const e=nc(nT(t));const r=ub(t.label);return` ${r}${cb.test(r)?"":" "}:${e.startsWith("%")?" ":""}${e}`}function oT(t){const e=["gantt"];if(t.axisFormat!==void 0){if(typeof t.axisFormat!=="string"||!t.axisFormat.trim())throw new Error("Gantt axisFormat must be nonempty text");if(/[#;\r\n]|%%\{/.test(t.axisFormat))e.unshift(`%%{init: ${JSON.stringify({gantt:{axisFormat:t.axisFormat}}).replace(/%/g,"\\u0025")}}%%`);else e.push(` axisFormat ${t.axisFormat}`)}if(t.statements&&t.statements.length>0){for(const r of t.statements){if(r.kind==="opaque-block"){for(const i of r.lines)e.push(i)}else if(r.kind==="title"){if(t.title!==void 0)e.push(` title ${t.title}`)}else if(r.kind==="section"){const i=t.sections[r.ref];if(i&&i.label!==void 0)e.push(` section ${i.label}`)}else{const i=t.sections[r.section]?.tasks[r.ref];if(i)e.push(zm(i))}}return e.join("\n")+"\n"}if(t.title!==void 0)e.push(` title ${t.title}`);for(const r of t.sections){if(r.label!==void 0)e.push(` section ${r.label}`);for(const i of r.tasks)e.push(zm(i))}return e.join("\n")+"\n"}function DB(t){return{kind:"gantt",title:t.title,...t.axisFormat!==void 0?{axisFormat:t.axisFormat}:{},sections:t.sections.map(e=>({id:e.id,label:e.label,tasks:e.tasks.map(r=>({...r,tags:[...r.tags]}))})),statements:(t.statements??PB(t)).map(NB)}}function NB(t){return t.kind==="opaque-block"?{kind:"opaque-block",lines:[...t.lines]}:{...t}}function PB(t){const e=[];if(t.title!==void 0)e.push({kind:"title"});t.sections.forEach((r,i)=>{if(r.label!==void 0)e.push({kind:"section",ref:i});r.tasks.forEach((n,o)=>e.push({kind:"task",section:i,ref:o}))});return e}function Kw(t,e){return lr(t.sections.flatMap(r=>[r.id,...r.tasks.map(i=>i.id)]),e)}function Jo(t){if(!t.label||/[\r\n]/.test(t.label)){return{code:"INVALID_OP",message:"Gantt task label must be non-empty and must not contain newlines"}}if(t.taskId!==void 0&&!Kc.test(t.taskId)){return{code:"INVALID_OP",message:`Gantt task id "${t.taskId}" must match ${Kc}`}}for(const a of[t.start,t.end]){if(a!==void 0&&/[,:#\r\n]/.test(a)){return{code:"INVALID_OP",message:'Gantt task dates must not contain "," ":" "#" or newlines'}}}if(!t.end)return{code:"INVALID_OP",message:'Gantt task end (date, duration, or "until id") is required'};const e=zm(t).trim();const r=oi([e])[0];const i=r.kind==="task"?r.label:"";const n=r.kind==="task"?r.meta:null;const o=r.kind!=="task";if(!n||i!==t.label||o){return{code:"INVALID_OP",message:`Gantt task does not round-trip through its canonical line ("${e}")`}}const s=nc(n);if(s!==nc(nT(t))){return{code:"INVALID_OP",message:`Gantt task metadata is ambiguous ("${s}")`}}return null}function Jw(t){if(!t.trim()||/[:\r\n]|%%\{/.test(t)){return{code:"INVALID_OP",message:'Gantt section label must be non-empty and must not contain ":" or newlines'}}const e=`section ${t.trim()}`;const r=oi([e])[0];if(r.kind!=="section"||r.value!==t.trim())return{code:"INVALID_OP",message:"Gantt section label does not round-trip"};return null}function Gm(t){const e=new Set;for(const r of t.sections)for(const i of r.tasks)if(i.taskId!==void 0)e.add(i.taskId);return e}function Xc(t){const e=[];for(const r of t.statements??[]){if(r.kind!=="task")continue;const i=t.sections[r.section]?.tasks[r.ref];if(i)e.push(i)}return e}function Qw(t,e,r){const i=[];for(let o=0;o<r.length;o++){const s=r[o];if(s.start!==void 0)continue;const a=e[e.indexOf(s)-1];if(a!==r[o-1])i.push(s.label)}if(i.length===0)return null;const n=i.map(o=>`"${o}"`).join(", ");return{code:"INVALID_OP",message:`${t} would silently change the schedule: task(s) ${n} have an implicit start (they begin when the previous task in source order ends) and this move changes their predecessor. Materialize an explicit start first \u2014 set_task_dates with the resolved start date (read it from describe/analyze) or an "after <taskId>" dependency \u2014 then retry the move.`}}var FB=/\b(?:after|until)\s+([^,:#]+)/gi;function $B(t,e){const r=[];for(const i of t.sections){for(const n of i.tasks){for(const o of[n.start,n.end]){const s=o?.match(aT);if(s&&s[1].split(/\s+/).includes(e)){r.push(n);break}}}}return r}function Zw(t,e){const r=new RegExp(`^click\\s+${e}(?:\\s|$)`,"i");const i=[];for(const n of t.statements??[]){if(n.kind!=="opaque-block")continue;for(const o of n.lines){const s=o.trim();if(!s||s.startsWith("%%"))continue;if(r.test(s)){i.push(s);continue}for(const a of s.matchAll(FB)){if(a[1].trim().split(/\s+/).includes(e)){i.push(s);break}}}}return i}function eT(t,e,r,i){if(!t.startsWith(`${e} `))return t;const n=t.slice(e.length+1).split(/\s+/).filter(Boolean);if(!n.includes(r))return t;return`${e} ${n.map(o=>o===r?i:o).join(" ")}`}function sT(t,e){const r=DB(t);const i=r.statements;const n=Kw(r,"section");const o=Kw(r,"task");const s=l=>r.sections[l];const a=(l,c)=>s(l)?.tasks[c];switch(e.kind){case"set_title":{if(e.title===null){r.title=void 0;Wm(i,d=>d.kind==="title");break}const l=e.title.trim();if(!l||/[\r\n]|%%\{/.test(l))return T({code:"INVALID_OP",message:"Gantt title must be a non-empty single line without a directive opener"});const c=r.title!==void 0;r.title=l;if(!c)i.unshift({kind:"title"});break}case"add_section":{const l=Jw(e.label);if(l)return T(l);r.sections.push({id:n(),label:e.label.trim(),tasks:[]});i.push({kind:"section",ref:r.sections.length-1});break}case"rename_section":{const l=s(e.index);if(!l)return T({code:"SECTION_NOT_FOUND",message:`No section at index ${e.index}`});if(l.label===void 0)return T({code:"INVALID_OP",message:"Cannot rename the implicit (unlabeled) section"});const c=Jw(e.label);if(c)return T(c);l.label=e.label.trim();break}case"remove_section":{if(!s(e.index))return T({code:"SECTION_NOT_FOUND",message:`No section at index ${e.index}`});r.sections.splice(e.index,1);Wm(i,l=>l.kind==="section"&&l.ref===e.index||l.kind==="task"&&l.section===e.index);for(const l of i){if(l.kind==="section"&&l.ref>e.index)l.ref--;if(l.kind==="task"&&l.section>e.index)l.section--}break}case"add_task":{const l=s(e.sectionIndex);if(!l)return T({code:"SECTION_NOT_FOUND",message:`No section at index ${e.sectionIndex}`});if(e.taskId!==void 0&&Gm(r).has(e.taskId)){return T({code:"DUPLICATE_TASK",message:`Task id "${e.taskId}" already exists`})}const c=Ri(e.index,l.tasks.length,"Gantt");if(!c.ok)return c;const d={id:o(),taskId:e.taskId,label:e.label?.trim()??"",tags:Sa(e.tags??[]),start:e.start?.trim()||void 0,end:(e.end??"").trim()};const u=Jo(d);if(u)return T(u);l.tasks.splice(c.value,0,d);tT(i,e.sectionIndex,c.value);break}case"remove_task":{const l=s(e.sectionIndex);if(!l)return T({code:"SECTION_NOT_FOUND",message:`No section at index ${e.sectionIndex}`});if(!l.tasks[e.taskIndex])return T({code:"TASK_NOT_FOUND",message:`No task at index ${e.taskIndex}`});l.tasks.splice(e.taskIndex,1);rT(i,e.sectionIndex,e.taskIndex);break}case"move_task":{const l=s(e.fromSection);if(!l)return T({code:"SECTION_NOT_FOUND",message:`No section at index ${e.fromSection}`});const c=l.tasks[e.fromIndex];if(!c)return T({code:"TASK_NOT_FOUND",message:`No task at index ${e.fromIndex}`});const d=s(e.toSection);if(!d)return T({code:"SECTION_NOT_FOUND",message:`No section at index ${e.toSection}`});const u=Xc(r);l.tasks.splice(e.fromIndex,1);rT(i,e.fromSection,e.fromIndex);if(!Number.isInteger(e.toIndex)||e.toIndex<0||e.toIndex>d.tasks.length){return T({code:"TASK_NOT_FOUND",message:`No insert position ${e.toIndex} in section ${e.toSection} (0..${d.tasks.length})`})}d.tasks.splice(e.toIndex,0,c);tT(i,e.toSection,e.toIndex);const h=Qw("move_task",u,Xc(r));if(h)return T(h);break}case"move_section":{const l=s(e.from);if(!l)return T({code:"SECTION_NOT_FOUND",message:`No section at index ${e.from}`});if(!Number.isInteger(e.to)||e.to<0||e.to>=r.sections.length){return T({code:"SECTION_NOT_FOUND",message:`No section position ${e.to} (0..${r.sections.length-1})`})}if(l.label===void 0){return T({code:"INVALID_OP",message:'Cannot move the implicit (unlabeled) section: its tasks precede the first "section" line by construction. Move the labeled sections around it instead.'})}if(r.sections[0]?.label===void 0&&e.to===0){return T({code:"INVALID_OP",message:'Position 0 is held by the implicit (unlabeled) section \u2014 tasks before the first "section" line. The earliest position for a labeled section is 1.'})}if(e.to===e.from)break;const c=Xc(r);const{preamble:d,spans:u}=qB(i);const h=new Map(u.map(y=>[y.sectionIndex,y]));for(let y=0;y<r.sections.length;y++){if(r.sections[y].label!==void 0&&!h.has(y)){return T({code:"INVALID_OP",message:`move_section: section ${y} has no section statement to move`})}}const m=r.sections.map((y,C)=>C);m.splice(e.from,1);m.splice(e.to,0,e.from);const f=new Array(r.sections.length);m.forEach((y,C)=>{f[y]=C});const[p]=r.sections.splice(e.from,1);r.sections.splice(e.to,0,p);i.length=0;i.push(...d,...m.filter(y=>h.has(y)).flatMap(y=>h.get(y).statements));for(const y of i){if(y.kind==="section")y.ref=f[y.ref];else if(y.kind==="task")y.section=f[y.section]}const g=Qw("move_section",c,Xc(r));if(g)return T(g);break}case"rename_task":{const l=a(e.sectionIndex,e.taskIndex);if(!l)return T({code:"TASK_NOT_FOUND",message:`No task at (${e.sectionIndex},${e.taskIndex})`});const c={...l,label:e.label?.trim()??""};const d=Jo(c);if(d)return T(d);l.label=c.label;break}case"set_task_status":{const l=a(e.sectionIndex,e.taskIndex);if(!l)return T({code:"TASK_NOT_FOUND",message:`No task at (${e.sectionIndex},${e.taskIndex})`});const c=l.tags.filter(u=>u==="milestone"||u==="vert");const d=e.status===null?c:Sa([e.status,...c]);if(e.status!==null&&!["active","done","crit"].includes(e.status)){return T({code:"INVALID_OP",message:`Invalid task status "${String(e.status)}"`})}l.tags=d;break}case"set_task_dates":{const l=a(e.sectionIndex,e.taskIndex);if(!l)return T({code:"TASK_NOT_FOUND",message:`No task at (${e.sectionIndex},${e.taskIndex})`});const c={...l,tags:[...l.tags]};if(e.start!==void 0)c.start=e.start===null?void 0:e.start.trim();if(e.end!==void 0)c.end=e.end.trim();const d=Jo(c);if(d)return T(d);l.start=c.start;l.end=c.end;break}case"set_task_flags":{const l=a(e.sectionIndex,e.taskIndex);if(!l)return T({code:"TASK_NOT_FOUND",message:`No task at (${e.sectionIndex},${e.taskIndex})`});const c=new Set(l.tags);if(e.milestone!==void 0){if(e.milestone)c.add("milestone");else c.delete("milestone")}if(e.vert!==void 0){if(e.vert)c.add("vert");else c.delete("vert")}const d={...l,tags:Sa([...c])};const u=Jo(d);if(u)return T(u);l.tags=d.tags;break}case"set_task_id":{const l=a(e.sectionIndex,e.taskIndex);if(!l)return T({code:"TASK_NOT_FOUND",message:`No task at (${e.sectionIndex},${e.taskIndex})`});const c=l.taskId;if(e.taskId===null){if(c===void 0)break;const m=$B(r,c).filter(y=>y!==l);const f=Zw(r,c);if(m.length>0||f.length>0){const y=[...m.map(C=>`task "${C.label}"`),...f.map(C=>`opaque line "${C}"`)].join(", ");return T({code:"INVALID_OP",message:`Cannot clear task id "${c}": it is referenced by ${y}. Retarget or remove those references first (set_task_dates on the referencing tasks; opaque lines are edited at the source level).`})}const p={...l,taskId:void 0};const g=Jo(p);if(g)return T(g);l.taskId=void 0;break}const d=e.taskId.trim();if(!Kc.test(d)){return T({code:"INVALID_OP",message:`Gantt task id "${d}" must match ${Kc}`})}if(d===c)break;if(Gm(r).has(d)){return T({code:"DUPLICATE_TASK",message:`Task id "${d}" already exists`})}if(c!==void 0){const m=Zw(r,c);if(m.length>0){return T({code:"INVALID_OP",message:`Cannot rename task id "${c}": it is referenced from opaque segment(s) ${m.map(f=>`"${f}"`).join(", ")} \u2014 typed ops never rewrite opaque lines (click/comments/unmodeled syntax). Edit those lines at the source level first.`})}}const u={...l,taskId:d};const h=Jo(u);if(h)return T(h);l.taskId=d;if(c!==void 0){for(const m of r.sections){for(const f of m.tasks){if(f.start!==void 0)f.start=eT(f.start,"after",c,d);f.end=eT(f.end,"until",c,d)}}}break}default:{const l=e;return T({code:"INVALID_OP",message:Ve("gantt",l)})}}return re(r)}function Wm(t,e){for(let r=t.length-1;r>=0;r--)if(e(t[r]))t.splice(r,1)}function tT(t,e,r){for(const s of t){if(s.kind==="task"&&s.section===e&&s.ref>=r)s.ref++}let i=-1;let n=-1;for(let s=0;s<t.length;s++){const a=t[s];if(a.kind==="section"&&a.ref===e)n=s;if(a.kind==="task"&&a.section===e){if(a.ref>r&&i===-1)i=s;n=s}}const o={kind:"task",section:e,ref:r};if(i>=0)t.splice(i,0,o);else if(n>=0)t.splice(n+1,0,o);else t.push(o)}function rT(t,e,r){Wm(t,i=>i.kind==="task"&&i.section===e&&i.ref===r);for(const i of t){if(i.kind==="task"&&i.section===e&&i.ref>r)i.ref--}}function qB(t){const e=[];const r=[];let i=null;for(const n of t){if(n.kind==="section"){i={sectionIndex:n.ref,statements:[n]};r.push(i);continue}if(i)i.statements.push(n);else e.push(n)}return{preamble:e,spans:r}}var aT=/^(?:after|until)\s+(.+)$/;function lT(t,e){const r=[];const i=e.labelCharCap??40;const n=t.sections.flatMap(l=>l.tasks);const o=(t.statements??[]).filter(l=>l.kind==="opaque-block").flatMap(l=>l.lines.map(c=>c.trim())).filter(l=>l.length>0);if(n.length===0)r.push({code:"EMPTY_DIAGRAM"});const s=Ke(r,e,i,"literal");if(t.title!==void 0)s("title",t.title);for(const l of t.sections){if(l.label!==void 0)s(l.id,dl(l.label));for(const c of l.tasks)s(c.id,c.label)}const a=Gm(t);for(const l of o){const c=l.indexOf(":");if(c<=0)continue;const d=l.slice(c+1).split(",").map(m=>m.trim()).filter(Boolean);let u=0;while(u<d.length&&ah.includes(d[u]))u++;const h=d[u];if(h!==void 0&&/^[\w-]+$/.test(h))a.add(h)}for(const l of n){for(const c of[l.start,l.end]){const d=c?.match(aT);if(!d)continue;for(const u of d[1].split(/\s+/).filter(Boolean)){if(!a.has(u)){r.push({code:"EDGE_MISANCHORED",edge:`${l.id}:${c.split(/\s+/)[0]}->${u}`})}}}}return r}function dT(t,e={}){return{kind:"gitgraph",...Ro(t,e)}}function Um(t){return vh(t)}function zB(t){return{...t,commits:t.commits.map(e=>({...e,tags:[...e.tags],parents:[...e.parents]})),branches:t.branches.map(e=>({...e})),statements:t.statements.map(e=>({...e}))}}function wa(t,e){try{const r=Ro(Um(t).trimEnd()+`
182
+ ${e}
183
+ `,{mainBranchName:t.mainBranchName,mainBranchOrder:t.branches.find(n=>n.name===t.mainBranchName)?.order,title:t.title});const i={kind:"gitgraph",...r};return re(i)}catch(r){return T({code:"INVALID_OP",message:r instanceof Error?r.message:String(r)})}}function cT(t){const e=[];if(t.id!==void 0)e.push(`id:${li(t.id)}`);if(t.type!==void 0&&t.type!=="NORMAL")e.push(`type:${t.type}`);for(const r of t.tags??[])e.push(`tag:${li(r)}`);if(t.message!==void 0)e.push(`msg:${li(t.message)}`);return e.length?` ${e.join(" ")}`:""}function qi(t,e){if(typeof t!=="string"||!t.trim()||/[\r\n]/.test(t))return T({code:"INVALID_OP",message:`gitGraph ${e} must be a non-empty single-line string`});return re(t.trim())}function uT(t,e){const r=zB(t);const i=n=>r.commits.find(o=>o.id===n);switch(e.kind){case"append_commit":if(e.id!==void 0&&r.commits.some(n=>n.id===e.id||n.sourceId===e.id))return T({code:"DUPLICATE_NODE",message:`gitGraph commit '${e.id}' already exists; typed append requires an unused ID`});return wa(r,`commit${cT(e)}`);case"create_branch":{const n=qi(e.name,"branch name");if(!n.ok)return n;return wa(r,`branch ${li(n.value)}${e.order!==void 0?` order:${e.order}`:""}`)}case"checkout_branch":{const n=qi(e.name,"branch name");if(!n.ok)return n;return wa(r,`checkout ${li(n.value)}`)}case"merge_branch":{if(e.id!==void 0&&r.commits.some(o=>o.id===e.id||o.sourceId===e.id))return T({code:"DUPLICATE_NODE",message:`gitGraph commit '${e.id}' already exists; typed merge requires an unused ID`});const n=qi(e.name,"branch name");if(!n.ok)return n;return wa(r,`merge ${li(n.value)}${cT(e)}`)}case"cherry_pick":{const n=qi(e.id,"cherry-pick id");if(!n.ok)return n;const o=i(n.value);const s=o?.sourceId??n.value;if(o&&r.commits.findLast(l=>(l.sourceId??l.id)===s)?.id!==o.id){return T({code:"INVALID_OP",message:`Commit '${n.value}' is shadowed by a later authored ID '${s}'; pinned cherry-pick syntax cannot address that earlier occurrence`})}const a=[`id:${li(s)}`];if(e.parent){const l=i(e.parent);const c=l?.sourceId??e.parent;if(l&&r.commits.findLast(d=>(d.sourceId??d.id)===c)?.id!==l.id){return T({code:"INVALID_OP",message:`Parent '${e.parent}' is shadowed by a later authored ID '${c}'; pinned cherry-pick syntax cannot address that earlier occurrence`})}a.push(`parent:${li(c)}`)}for(const l of e.tags??[])a.push(`tag:${li(l)}`);return wa(r,`cherry-pick ${a.join(" ")}`)}case"set_commit_message":{const n=i(e.id);if(!n)return T({code:"NODE_NOT_FOUND",message:`gitGraph commit '${e.id}' not found`});if(n.source!=="commit")return T({code:"INVALID_OP",message:`Commit '${e.id}' is produced by ${n.source}; its generated message cannot be replaced`});if(e.message===null)delete n.message;else{const o=qi(e.message,"commit message");if(!o.ok)return o;n.message=o.value}return re(r)}case"set_commit_type":{const n=i(e.id);if(!n)return T({code:"NODE_NOT_FOUND",message:`gitGraph commit '${e.id}' not found`});if(n.source!=="commit")return T({code:"INVALID_OP",message:`Commit '${e.id}' is produced by ${n.source}; its semantic type cannot be replaced`});n.type=e.type;return re(r)}case"set_commit_tags":{const n=i(e.id);if(!n)return T({code:"NODE_NOT_FOUND",message:`gitGraph commit '${e.id}' not found`});for(const o of e.tags){const s=qi(o,"tag");if(!s.ok)return s}n.tags=[...e.tags];delete n.syntheticCherryTag;return re(r)}case"rename_branch":{if(e.from===r.mainBranchName)return T({code:"INVALID_OP",message:"Renaming the configured main branch requires gitGraph.mainBranchName config; source syntax cannot express it"});const n=r.branches.find(s=>s.name===e.from);if(!n)return T({code:"NODE_NOT_FOUND",message:`gitGraph branch '${e.from}' not found`});const o=qi(e.to,"branch name");if(!o.ok)return o;if(r.branches.some(s=>s.name===o.value))return T({code:"DUPLICATE_NODE",message:`gitGraph branch '${o.value}' already exists`});n.name=o.value;for(const s of r.commits){const a=s.source==="merge"&&s.mergeBranch===e.from;const l=s.source==="merge"&&s.branch===e.from;if(s.branch===e.from)s.branch=o.value;if(a)s.mergeBranch=o.value;if(a||l)s.message=`merged branch ${s.mergeBranch} into ${s.branch}`}for(const s of r.statements){if(s.kind==="branch"&&s.name===e.from)s.name=o.value;else if(s.kind==="checkout"&&s.branch===e.from)s.branch=o.value;else if(s.kind==="merge"&&s.branch===e.from)s.branch=o.value}return re(r)}case"set_accessibility_title":{const n=gt(r,"accessibilityTitle",e.title,o=>qi(o,"accessibility title"));return n.ok?re(r):n}case"set_accessibility_description":{const n=gt(r,"accessibilityDescription",e.description,o=>qi(o,"accessibility description"));return n.ok?re(r):n}default:return T({code:"INVALID_OP",message:Ve("gitgraph",e)})}}function hT(t,e){const r=[];const i=new Set(t.commits.map(o=>o.id));const n=Ke(r,e,void 0,"literal");for(const o of t.commits){n(o.id,Qs(o));for(const s of o.parents)if(!i.has(s))r.push({code:"EDGE_MISANCHORED",edge:`${s}->${o.id}`,to:o.id})}return r}function jm(t){return rn(t.split(/\r?\n/).map(e=>e.trim()).join("<br>"),":;,%{}\\")}function Jc(t,e){const r=bt(Ye(t,e));const i=lg(r,n=>Or(n,";&#:,%<*~").replace(/\\(?=n)/g,"#92;").replace(/^\s+|\s+$/g,o=>Or(o,o)));return/^(?:journey|title|section|accTitle|accDescr)\b/i.test(i)?`#${i.codePointAt(0)};${i.slice(1)}`:i}function Vm(t,e={}){e=ki(e);const r={kind:"journey",sections:[],...e.title!==void 0?{accessibilityTitle:e.title}:{},...e.descr!==void 0?{accessibilityDescription:e.descr}:{}};let i;let n=0,o=0;let s;const a=()=>{if(!i){i={id:`section-${n++}`,tasks:[]};r.sections.push(i)}return i};Fn(t,0,{title:(l,c,d)=>{r.title=l;if(d)r.titleContent=d;else delete r.titleContent},accTitle:l=>{r.accessibilityTitle=l},accDescr:l=>{r.accessibilityDescription=l},section:(l,c,d)=>{i={id:`section-${n++}`,label:l,...d?{labelContent:d}:{},tasks:[]};r.sections.push(i)},task:(l,c,d,u,h,m)=>{a().tasks.push({id:`task-${o++}`,text:l,...h?{textContent:h}:{},score:c,actors:d,...m?{actorContents:m}:{}})},issue:l=>{s=l;return"stop"}});if(s)return{ok:false,issue:s};return{ok:true,body:r}}function Ym(t){const e=["journey"];if(t.title)e.push(` title ${Jc(t.title,t.titleContent)}`);if(t.accessibilityTitle)e.push(` accTitle: ${jm(t.accessibilityTitle)}`);if(t.accessibilityDescription){if(t.accessibilityDescription.includes("\n")){e.push(" accDescr {");for(const r of t.accessibilityDescription.split(/\r?\n/)){e.push(` ${jm(r.trim())}`)}e.push(" }")}else{e.push(` accDescr: ${jm(t.accessibilityDescription)}`)}}for(const r of t.sections){if(r.label!==void 0)e.push(` section ${Jc(r.label,r.labelContent)}`);for(const i of r.tasks){const n=i.actors.length>0?`: ${i.actors.map((o,s)=>Jc(o,i.actorContents?.[s])).join(", ")}`:"";e.push(` ${Jc(i.text,i.textContent)}: ${i.score}${n}`)}}return e.join("\n")+"\n"}function GB(t){return{...t,sections:t.sections.map(e=>({...e,tasks:e.tasks.map(r=>({...r,actors:[...r.actors]}))}))}}function WB(t){const e=t.sections.flatMap(n=>[n.id,...n.tasks.map(o=>o.id)]);const r=lr(e,"section");const i=lr(e,"task");return n=>n==="section"?r():i()}function Ta(t,e,r){if(typeof t!=="string")return T({code:"INVALID_OP",message:`Journey ${e} must be a string`});const i=t===r?t:ch(t);if(!i){return T({code:"INVALID_OP",message:`Journey ${e} must be non-empty`})}return re(i)}function mT(t,e){if(t===null)return re(void 0);if(typeof t!=="string")return T({code:"INVALID_OP",message:`Journey ${e} must be a string or null`});const r=ch(t);if(!r)return T({code:"INVALID_OP",message:`Journey ${e} must be non-empty`});return re(r)}function Qc(t,e=[]){const r=[];for(const i of t??[]){if(typeof i!=="string")return T({code:"INVALID_OP",message:"Journey actor must be a string"});const n=e.includes(i)?i:gb(i);if(!n){return T({code:"INVALID_OP",message:"Journey actor must be non-empty"})}r.push(n)}return re(r)}function pT(t,e){const r=GB(t);const i=WB(r);const n=a=>r.sections[a];const o=(a,l)=>n(a)?.tasks[l];switch(e.kind){case"set_title":{const a=r.title;const l=gt(r,"title",e.title,c=>Ta(c,"title",a));if(!l.ok)return l;if(r.title!==a)delete r.titleContent;break}case"add_section":{const a=Ta(e.label,"section label");if(!a.ok)return a;const l=Ri(e.index,r.sections.length,"Journey");if(!l.ok)return l;r.sections.splice(l.value,0,{id:i("section"),label:a.value,tasks:[]});break}case"remove_section":{if(!n(e.index))return T({code:"SECTION_NOT_FOUND",message:`No section at index ${e.index}`});r.sections.splice(e.index,1);break}case"set_section_label":{const a=n(e.index);if(!a)return T({code:"SECTION_NOT_FOUND",message:`No section at index ${e.index}`});const l=Ta(e.label,"section label",a.label);if(!l.ok)return l;if(a.label!==l.value)delete a.labelContent;a.label=l.value;break}case"add_task":{const a=n(e.sectionIndex);if(!a)return T({code:"SECTION_NOT_FOUND",message:`No section at index ${e.sectionIndex}`});const l=Ta(e.text,"task text");if(!l.ok)return l;if(!uh(e.score))return T({code:"INVALID_OP",message:`Journey score must be a finite number 1..5, got ${e.score}`});const c=Qc(e.actors);if(!c.ok)return c;const d=Ri(e.index,a.tasks.length,"Journey");if(!d.ok)return d;a.tasks.splice(d.value,0,{id:i("task"),text:l.value,score:e.score,actors:c.value});break}case"remove_task":{const a=n(e.sectionIndex);if(!a)return T({code:"SECTION_NOT_FOUND",message:`No section at index ${e.sectionIndex}`});if(!a.tasks[e.taskIndex])return T({code:"TASK_NOT_FOUND",message:`No task at index ${e.taskIndex}`});a.tasks.splice(e.taskIndex,1);if(a.label===void 0&&a.tasks.length===0)r.sections.splice(e.sectionIndex,1);break}case"set_task_text":{const a=o(e.sectionIndex,e.taskIndex);if(!a)return T({code:"TASK_NOT_FOUND",message:`No task at (${e.sectionIndex},${e.taskIndex})`});const l=Ta(e.text,"task text",a.text);if(!l.ok)return l;if(a.text!==l.value)delete a.textContent;a.text=l.value;break}case"set_task_score":{const a=o(e.sectionIndex,e.taskIndex);if(!a)return T({code:"TASK_NOT_FOUND",message:`No task at (${e.sectionIndex},${e.taskIndex})`});if(!uh(e.score))return T({code:"INVALID_OP",message:`Journey score must be a finite number 1..5, got ${e.score}`});a.score=e.score;break}case"set_task_actors":{const a=o(e.sectionIndex,e.taskIndex);if(!a)return T({code:"TASK_NOT_FOUND",message:`No task at (${e.sectionIndex},${e.taskIndex})`});const l=Qc(e.actors,a.actors);if(!l.ok)return l;if(a.actorContents){const c=new Set(l.value.flatMap((m,f)=>m===a.actors[f]?[f]:[]));const d=new Map;const u=new Map;a.actors.forEach((m,f)=>{const p=a.actorContents?.[f];const g=dh(m,p);const y=u.get(m);u.set(m,{key:g,content:p,ambiguous:y!==void 0&&(y.ambiguous||y.key!==g)});if(c.has(f))return;const C=d.get(m)??[];C.push(p);d.set(m,C)});let h=false;a.actorContents=l.value.map((m,f)=>{if(c.has(f))return a.actorContents?.[f];const p=d.get(m);if(p?.length)return p.shift();const g=u.get(m);if(g?.ambiguous)h=true;return g?.content});if(h)return T({code:"INVALID_OP",message:"Journey actor has multiple existing text interpretations; a new copy needs a distinct label"})}a.actors=l.value;break}case"move_task":{const a=n(e.fromSection);if(!a)return T({code:"SECTION_NOT_FOUND",message:`No section at index ${e.fromSection}`});if(!a.tasks[e.fromIndex])return T({code:"TASK_NOT_FOUND",message:`No task at index ${e.fromIndex}`});const l=n(e.toSection);if(!l)return T({code:"SECTION_NOT_FOUND",message:`No section at index ${e.toSection}`});const[c]=a.tasks.splice(e.fromIndex,1);if(!Number.isInteger(e.toIndex)||e.toIndex<0||e.toIndex>l.tasks.length){return T({code:"TASK_NOT_FOUND",message:`No insert position ${e.toIndex} in section ${e.toSection} (0..${l.tasks.length})`})}l.tasks.splice(e.toIndex,0,c);if(a!==l&&a.label===void 0&&a.tasks.length===0){r.sections.splice(r.sections.indexOf(a),1)}break}case"move_section":{if(!n(e.from))return T({code:"SECTION_NOT_FOUND",message:`No section at index ${e.from}`});if(!Number.isInteger(e.to)||e.to<0||e.to>=r.sections.length){return T({code:"SECTION_NOT_FOUND",message:`No section position ${e.to} (0..${r.sections.length-1})`})}const[a]=r.sections.splice(e.from,1);r.sections.splice(e.to,0,a);break}case"set_accessibility_title":{const a=mT(e.title,"accessibility title");if(!a.ok)return a;if(a.value===void 0)delete r.accessibilityTitle;else r.accessibilityTitle=a.value;break}case"set_accessibility_description":{const a=mT(e.description,"accessibility description");if(!a.ok)return a;if(a.value===void 0)delete r.accessibilityDescription;else r.accessibilityDescription=a.value;break}case"rename_actor":{const a=r.sections.flatMap(m=>m.tasks.flatMap(f=>f.actors));const l=Qc([e.from],a);if(!l.ok)return l;const c=Qc([e.to],a);if(!c.ok)return c;const d=l.value[0];const u=c.value[0];let h=false;for(const m of r.sections){for(const f of m.tasks){f.actors=f.actors.map((p,g)=>{if(p===d){h=true;if(f.actorContents&&d!==u)f.actorContents=f.actorContents.map((y,C)=>C===g?void 0:y);return u}return p})}}if(!h)return T({code:"ACTOR_NOT_FOUND",message:`Actor "${d}" not found`});break}default:{const a=e;return T({code:"INVALID_OP",message:Ve("journey",a)})}}r.sections=r.sections.filter(a=>a.label!==void 0||a.tasks.length>0);const s=Vm(Ym(r).trimEnd().split(/\r?\n/).slice(1));if(!s.ok||JSON.stringify(fT(s.body))!==JSON.stringify(fT(r))){return T({code:"INVALID_OP",message:"Journey edit cannot be represented losslessly by Mermaid syntax"})}return re(s.body)}function fT(t){const e=(r,i)=>r===void 0?void 0:{value:r,runs:bt(Ye(r,i)).lines.map(n=>n.map(({text:o,bold:s,italic:a,underline:l,strikethrough:c})=>({text:o,bold:s,italic:a,underline:l,strikethrough:c})))};return{title:e(t.title,t.titleContent),accessibilityTitle:t.accessibilityTitle,accessibilityDescription:t.accessibilityDescription,sections:t.sections.map(r=>({label:e(r.label,r.labelContent),tasks:r.tasks.map(i=>({text:e(i.text,i.textContent),score:i.score,actors:i.actors.map((n,o)=>e(n,i.actorContents?.[o]))}))}))}}function Rq(t){const e=t.split(/\r?\n/);const r=e.findIndex(a=>/^\s*journey\b/i.test(a));if(r<0)return[];const i=new Set;const n=new Set;Fn(e,r+1,{entitySemicolon:a=>i.add(a+1),statementDelimiter:a=>n.add(a+1)});const o=(a,l,c)=>[...a].map(d=>({code:"UNSUPPORTED_SYNTAX",syntax:l,line:d,message:c}));const s=[];Fn(e,r+1,{task:(a,l,c,d)=>{const u=Bu(e[d]??"").split(":",1)[0].trim();if(u.includes("#")||/^journey\b/i.test(u))s.push({code:"UNSUPPORTED_SYNTAX",syntax:"journey_nonportable_text",line:d+1,message:"Journey task text requires grammar escapes to preserve its literal hash or keyword prefix in pinned Mermaid."})},section:(a,l)=>{if(/^\s*section\s+[^\n]*:/i.test(Bu(e[l]??"")))s.push({code:"UNSUPPORTED_SYNTAX",syntax:"journey_section_colon",line:l+1,message:`Journey section ${JSON.stringify(a)} contains a colon read as label text; the writer protects it for pinned Mermaid.`})}});return[...s,...o(n,"journey_semicolon_statement_extension","Semicolon-separated Journey statements are an Agentic Mermaid extension; pinned Mermaid rejects this source. Put each statement on its own line for upstream portability."),...o(i,"journey_entity_semicolon","Pinned Mermaid does not read these as HTML references in Journey labels or actors: it rejects named-reference semicolons and reads numeric references differently. The writer preserves their text with Mermaid entity escapes.")]}function gT(t,e){const r=e.labelCharCap??Bl;const i=[];const n=Ke(i,e,r);const o=t.sections.some(l=>l.tasks.length>0);const s=t.title!==void 0||t.accessibilityTitle!==void 0||t.accessibilityDescription!==void 0||t.sections.length>0;if(!o&&!s)i.push({code:"EMPTY_DIAGRAM"});if(t.title!==void 0){Ke(i,e,Math.max(r,80))("title",Ye(t.title,t.titleContent))}const a=new Set(t.sections.flatMap(l=>l.tasks.flatMap(c=>c.actors.map((d,u)=>dh(d,c.actorContents?.[u])))));if(a.size>lh){i.push({code:"UNSUPPORTED_SYNTAX",syntax:"journey_actor_palette_limit",message:`Journey guarantees unique derived actor colors through ${lh} actors; this diagram has ${a.size}, so colors repeat deterministically above that bound.`})}for(const l of t.sections){if(l.label!==void 0)n(l.id,Ye(l.label,l.labelContent));for(const c of l.tasks){n(c.id,Ye(c.text,c.textContent));c.actors.forEach((d,u)=>n(c.id,Ye(d,c.actorContents?.[u])))}}return i}var CT=new WeakSet;function kT(t,e){const r=Gn(t);const i={kind:"mindmap",...r};if(e!==void 0&&UB(e))CT.add(i);return i}function UB(t){const e=t.replace(/\r\n?/g,"\n").replace(/%%\{[\s\S]*?\}%%/g,"").replace(/^\s*%%(?!\{)[^\n]+\n?/gm,"").replace(/^\s*mindmap/i,"");const r=/^\s*/.exec(e)[0];return r.lastIndexOf("\n")>0&&r.length<e.length}function ST(t){return ea(t)}function wT(t){return{...t,children:t.children.map(wT)}}function jB(t){return{kind:"mindmap",root:wT(t.root),...t.accessibilityTitle!==void 0?{accessibilityTitle:t.accessibilityTitle}:{},...t.accessibilityDescription!==void 0?{accessibilityDescription:t.accessibilityDescription}:{}}}function Rr(t,e,r){if(t.id===e)return{node:t,...r?{parent:r}:{}};for(const i of t.children){const n=Rr(i,e,t);if(n)return n}return void 0}function yT(t,e){try{return re(Ps(t))}catch{return T({code:"INVALID_OP",message:`Mindmap accessibility ${e} must be non-empty text`})}}function Qo(t,e){if(typeof t!=="string"||!t.trim()||/[\r\n]/.test(t))return T({code:"INVALID_OP",message:`Mindmap ${e} must be a non-empty single-line string`});return re(t.trim())}var Zc=["default","rect","rounded","circle","cloud","bang","hexagon"];function ed(t,e,r,i){try{const n=Gn(ea({root:{id:t,label:e,shape:r,...i?{markdown:i}:{},children:[]}})).root;return n.id===t&&n.label===e&&n.shape===r}catch{return false}}function td(t,e,r){const i=r==="default"?e:`${t}/${e}`;const n=r==="default"?"choose a bordered shape for decorated labels":`choose an id and label that do not conflict with ${r} delimiters`;return T({code:"INVALID_OP",message:`${r==="default"?"Default mindmap node text":"Mindmap node text"} '${i}' is not serialization-stable; ${n}`})}function TT(t){return JSON.stringify([t.id,t.label,t.shape,t.markdown,t.icon,t.className,t.children.map(TT)])}function xT(t){return JSON.stringify([t.accessibilityTitle,t.accessibilityDescription,TT(t.root)])}function rd(t){try{return xT(Gn(ea(t)))===xT(t)}catch{return false}}function bT(t,e){return T({code:"INVALID_OP",message:`Mindmap ${t} '${e}' is not serialization-stable`})}function vT(t,e){const r=Zs(t);if(r)return T({code:"INVALID_OP",message:r});const i=jB(t);const n=()=>{const o=new Set;const s=a=>{o.add(a.id);a.children.forEach(s)};s(i.root);return o};switch(e.kind){case"add_node":{const o=Qo(e.id,"node id");if(!o.ok)return o;const s=Qo(e.label,"label");if(!s.ok)return s;if(n().has(o.value))return T({code:"DUPLICATE_NODE",message:`Mindmap node '${o.value}' already exists`});const a=Rr(i.root,e.parent);if(!a)return T({code:"NODE_NOT_FOUND",message:`Mindmap parent '${e.parent}' not found`});const l=e.shape??"default";if(!Zc.includes(l))return T({code:"INVALID_OP",message:`Mindmap shape must be one of: ${Zc.join(", ")}`});if(l==="default"&&o.value!==s.value)return T({code:"INVALID_OP",message:"A default mindmap node uses its label as identity; choose a bordered shape when id and label differ"});if(!ed(o.value,s.value,l))return td(o.value,s.value,l);const c=e.index??a.node.children.length;if(!Number.isInteger(c)||c<0||c>a.node.children.length)return T({code:"INVALID_OP",message:`Mindmap child index ${c} is out of range`});a.node.children.splice(c,0,{id:o.value,label:s.value,shape:l,children:[]});return re(i)}case"remove_node":{const o=Rr(i.root,e.id);if(!o)return T({code:"NODE_NOT_FOUND",message:`Mindmap node '${e.id}' not found`});if(!o.parent)return T({code:"INVALID_OP",message:"The mindmap root cannot be removed"});if(o.node.children.length>0&&e.recursive!==true)return T({code:"INVALID_OP",message:`Mindmap node '${e.id}' has children; pass recursive:true to remove its subtree`});o.parent.children.splice(o.parent.children.indexOf(o.node),1);return re(i)}case"rename_node":{const o=Rr(i.root,e.from);if(!o)return T({code:"NODE_NOT_FOUND",message:`Mindmap node '${e.from}' not found`});const s=Qo(e.to,"rename target");if(!s.ok)return s;if(n().has(s.value))return T({code:"DUPLICATE_NODE",message:`Mindmap node '${s.value}' already exists`});const a=o.node.shape==="default"?s.value:o.node.label;if(!ed(s.value,a,o.node.shape,o.node.markdown))return td(s.value,a,o.node.shape);o.node.label=a;o.node.id=s.value;return re(i)}case"set_label":{const o=Rr(i.root,e.id);if(!o)return T({code:"NODE_NOT_FOUND",message:`Mindmap node '${e.id}' not found`});const s=Qo(e.label,"label");if(!s.ok)return s;const a=o.node.shape==="default"?s.value:o.node.id;if(o.node.shape==="default"&&s.value!==o.node.id&&n().has(s.value))return T({code:"DUPLICATE_NODE",message:`Mindmap node '${s.value}' already exists`});if(!ed(a,s.value,o.node.shape,o.node.markdown))return td(a,s.value,o.node.shape);o.node.id=a;o.node.label=s.value;return re(i)}case"move_node":{const o=Rr(i.root,e.id);const s=Rr(i.root,e.parent);if(!o)return T({code:"NODE_NOT_FOUND",message:`Mindmap node '${e.id}' not found`});if(!s)return T({code:"NODE_NOT_FOUND",message:`Mindmap parent '${e.parent}' not found`});if(!o.parent)return T({code:"INVALID_OP",message:"The mindmap root cannot be moved"});if(Rr(o.node,e.parent))return T({code:"INVALID_OP",message:`Cannot move '${e.id}' into its own subtree`});o.parent.children.splice(o.parent.children.indexOf(o.node),1);const a=e.index??s.node.children.length;if(!Number.isInteger(a)||a<0||a>s.node.children.length)return T({code:"INVALID_OP",message:`Mindmap child index ${a} is out of range`});s.node.children.splice(a,0,o.node);return re(i)}case"set_shape":{const o=Rr(i.root,e.id);if(!o)return T({code:"NODE_NOT_FOUND",message:`Mindmap node '${e.id}' not found`});if(!Zc.includes(e.shape))return T({code:"INVALID_OP",message:`Mindmap shape must be one of: ${Zc.join(", ")}`});if(e.shape==="default"&&o.node.id!==o.node.label)return T({code:"INVALID_OP",message:"Default mindmap shape requires id and label to match"});if(!ed(o.node.id,o.node.label,e.shape,o.node.markdown))return td(o.node.id,o.node.label,e.shape);o.node.shape=e.shape;return re(i)}case"set_icon":{const o=Rr(i.root,e.id);if(!o)return T({code:"NODE_NOT_FOUND",message:`Mindmap node '${e.id}' not found`});if(e.icon===null)delete o.node.icon;else{const s=Qo(e.icon,"icon");if(!s.ok)return s;o.node.icon=s.value;if(!rd(i))return bT("icon",s.value)}return re(i)}case"set_node_class":{const o=Rr(i.root,e.id);if(!o)return T({code:"NODE_NOT_FOUND",message:`Mindmap node '${e.id}' not found`});if(e.className===null)delete o.node.className;else{const s=Qo(e.className,"class");if(!s.ok)return s;o.node.className=s.value;if(!rd(i))return bT("class",s.value)}return re(i)}case"set_accessibility_title":{const o=gt(i,"accessibilityTitle",e.title,s=>yT(s,"title"));if(!o.ok)return o;if(i.accessibilityTitle!==void 0&&!rd(i))return T({code:"INVALID_OP",message:`Mindmap accessibility title '${i.accessibilityTitle}' is not serialization-stable`});return re(i)}case"set_accessibility_description":{const o=gt(i,"accessibilityDescription",e.description,s=>yT(s,"description"));if(!o.ok)return o;if(i.accessibilityDescription!==void 0&&!rd(i))return T({code:"INVALID_OP",message:`Mindmap accessibility description '${i.accessibilityDescription}' is not serialization-stable`});return re(i)}default:return T({code:"INVALID_OP",message:Ve("mindmap",e)})}}function Gq(t){const e=Pb(t).map(o=>({code:"UNSUPPORTED_SYNTAX",syntax:"mindmap_nested_shape_delimiters",line:o,message:"Shape text holding delimiters of its own in pairs, as `root((a (b) c))`, is read whole. Pinned Mermaid ends the shape at the first closing delimiter and rejects the rest; put the whole text in double quotes."}));const r=t.split(/\r?\n/);const i=r.findIndex(o=>/^\s*mindmap\s*$/i.test(o));const n=Nb(r);for(let o=i+1;i>=0&&o<r.length;){const s=ct(r,o);if(s===void 0)break;if(s===null){o=n[o]+1;continue}e.push({code:"UNSUPPORTED_SYNTAX",syntax:"mindmap_accessibility",line:o+1,message:"Mindmap accessibility metadata is carried in native comments on export. External Mermaid ignores this metadata; diagram topology is preserved."});o=s.endIndex+1}for(const o of $b(t))e.push({code:"UNSUPPORTED_SYNTAX",syntax:"mindmap_nonportable_text",line:o.line,message:`${o.message}. The source is preserved; change this text to unlock typed Mindmap edits.`});return e.sort((o,s)=>o.line-s.line)}function ET(t,e){const r=[];const i=Ke(r,e);const n=o=>{i(o.id,o.label);o.children.forEach(n)};n(t.root);if(CT.has(t)){r.push({code:"UNSUPPORTED_SYNTAX",syntax:"mindmap_space_after_header",line:1,message:"Whitespace at the end of the mindmap header line, or a blank line right after it, is ignored. Pinned Mermaid rejects the diagram; remove it, as the writer does."})}return r}function Kn(t){if(!Number.isFinite(t))throw new TypeError("Mermaid numbers must be finite");const e=String(t);const[r,i]=e.split("e");if(i===void 0)return e;const n=r.startsWith("-");const[o,s=""]=(n?r.slice(1):r).split(".");const a=o+s;const l=o.length+Number(i);const c=l<=0?`0.${"0".repeat(-l)}${a}`:l>=a.length?a+"0".repeat(l-a.length):`${a.slice(0,l)}.${a.slice(l)}`;return n?`-${c}`:c}function AT(t){return typeof t==="number"&&Number.isFinite(t)&&t>0}function VB(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/%%(?=\{)/g,"%\\%")}function YB(t){return t.replace(/\r?\n/g,"<br/>")}function OT(t,e){const r=`${e.showData?" showData":""}${e.title===void 0?"":` title ${e.title}`}`;try{const i=Do([`pie${r}`,...t]);if(i.hasDuplicateSourceLabels||new Set(i.entries.map(n=>n.label)).size!==i.entries.length)return null;if(i.hasEscapedControlLabels)return null;if(i.entries.some(n=>!AT(n.value)))return null;return{kind:"pie",...i.title===void 0?{}:{title:i.title},showData:i.showData,slices:i.entries.map((n,o)=>({id:`slice-${o}`,label:n.label,value:n.value}))}}catch{return null}}function BT(t){const e=t.showData?"pie showData":"pie";const r=[e];Lt(r,t);if(t.title!==void 0)r.push(` title ${YB(t.title)}`);for(const i of t.slices){r.push(` "${VB(i.label)}" : ${Kn(i.value)}`)}return r.join("\n")+"\n"}function HB(t){return{kind:"pie",accessibilityTitle:t.accessibilityTitle,accessibilityDescription:t.accessibilityDescription,title:t.title,showData:t.showData,slices:t.slices.map(e=>({id:e.id,label:e.label,value:e.value}))}}function Zo(t,e){if(typeof t!=="string")return T({code:"INVALID_OP",message:`Pie ${e} must be a string`});const r=t.trim();if(!r||e==="title"&&r.includes("\n")){return T({code:"INVALID_OP",message:`Pie ${e} must be non-empty${e==="title"?" single-line":""} text`})}return re(r)}function MT(t){if(!AT(t)){return T({code:"INVALID_OP",message:`Pie slice value must be a positive finite number, got ${JSON.stringify(t)}`})}return re(t)}function va(t,e){return t.slices.findIndex(r=>r.label===e)}function _T(t,e){const r=HB(t);const i=lr(r.slices.map(n=>n.id),"slice");switch(e.kind){case"set_title":{const n=gt(r,"title",e.title,o=>Zo(o,"title"));if(!n.ok)return n;break}case"set_show_data":{if(typeof e.showData!=="boolean"){return T({code:"INVALID_OP",message:"Pie set_show_data requires a boolean showData"})}r.showData=e.showData;break}case"add_slice":{const n=Zo(e.label,"slice label");if(!n.ok)return n;if(va(r,n.value)>=0){return T({code:"INVALID_OP",message:`Pie slice "${n.value}" already exists`})}const o=MT(e.value);if(!o.ok)return o;r.slices.push({id:i(),label:n.value,value:o.value});break}case"remove_slice":{const n=Zo(e.label,"slice label");if(!n.ok)return n;const o=va(r,n.value);if(o<0)return T({code:"SLICE_NOT_FOUND",message:`Pie slice "${n.value}" not found`});r.slices.splice(o,1);break}case"rename_slice":{const n=Zo(e.from,"slice label");if(!n.ok)return n;const o=Zo(e.to,"slice label");if(!o.ok)return o;const s=va(r,n.value);if(s<0)return T({code:"SLICE_NOT_FOUND",message:`Pie slice "${n.value}" not found`});if(n.value!==o.value&&va(r,o.value)>=0){return T({code:"INVALID_OP",message:`Pie slice "${o.value}" already exists`})}r.slices[s].label=o.value;break}case"set_slice_value":{const n=Zo(e.label,"slice label");if(!n.ok)return n;const o=va(r,n.value);if(o<0)return T({code:"SLICE_NOT_FOUND",message:`Pie slice "${n.value}" not found`});const s=MT(e.value);if(!s.ok)return s;r.slices[o].value=s.value;break}case"reorder_slice":{const{from:n,to:o}=e;if(!Number.isInteger(n)||!Number.isInteger(o)||!r.slices[n]||o<0||o>=r.slices.length){return T({code:"SLICE_NOT_FOUND",message:`reorder_slice indices out of range (from=${n}, to=${o})`})}const[s]=r.slices.splice(n,1);r.slices.splice(o,0,s);break}default:{const n=e;return T({code:"INVALID_OP",message:Ve("pie",n)})}}return re(r)}function IT(t,e){const r=[];const i=Ke(r,e,void 0,"literal");if(t.slices.length===0)r.push({code:"EMPTY_DIAGRAM"});if(t.title!==void 0)i("title",t.title);for(const n of t.slices)i(n.id,n.label);return r}function LT(t){return String(t)}function XB(t){return typeof t==="number"&&Number.isFinite(t)&&t>=0&&t<=1}function FT(t){if(!t)return;if(t.radius!==void 0&&(!Number.isSafeInteger(t.radius)||t.radius<0))return"radius requires a non-negative integer";for(const[e,r]of[["color",t.color],["stroke-color",t.strokeColor]]){if(r!==void 0&&!/^#(?:[\da-f]{3}|[\da-f]{6})$/i.test(r))return`${e} requires a three- or six-digit hexadecimal color`}if(t.strokeWidth!==void 0&&(!/^\d+(?:\.\d+)?(?:px)?$/.test(t.strokeWidth)||!Number.isSafeInteger(Number(t.strokeWidth.replace(/px$/,""))))){return"stroke-width requires a non-negative integer pixel width"}if(t.extra?.length)return`style property ${JSON.stringify(t.extra[0].split(":")[0])} is not supported`}function Ma(t){return{...t,...t.strokeWidth===void 0?{}:{strokeWidth:`${Number(t.strokeWidth.replace(/px$/,""))}px`}}}function od(t){const e=[];const r=(o,s)=>{if(o!==void 0&&!fh(o))e.push({syntax:"quadrant_text",message:`${s} ${JSON.stringify(o)} has no supported lossless Mermaid text spelling`})};const i=(o,s)=>{const a=FT(o);if(a)e.push({syntax:o?.extra?.length?"quadrant_style_property":"quadrant_style_value",message:`${s}: ${a}`})};const n=(o,s)=>{if(o===void 0)return;const a=xb(o)&&(s?!o.includes("_")&&mh(o)===o:!o.includes("-"));if(!a)e.push({syntax:"quadrant_class_name",message:`Quadrant class ${s?"definition":"reference"} ${JSON.stringify(o)} has no supported lossless Mermaid spelling`})};r(t.xAxis?.near,"Quadrant x-axis near label");r(t.xAxis?.far,"Quadrant x-axis far label");r(t.yAxis?.near,"Quadrant y-axis near label");r(t.yAxis?.far,"Quadrant y-axis far label");for(const[o,s]of t.quadrants.entries())if(s!=null)r(s,`Quadrant quadrant-${o+1} label`);for(const o of t.points){r(o.label,"Quadrant point label");n(o.className,false);i(o.style,`Quadrant point ${JSON.stringify(o.label)}`)}for(const[o,s]of Object.entries(t.classDefs??{})){n(o,true);i(s,`Quadrant classDef ${JSON.stringify(o)}`)}return e}function $T(t){try{const e=$n(["quadrantChart",...t]);if(od(e).length>0)return null;const r={kind:"quadrant",...e.title===void 0?{}:{title:e.title},...e.xAxis===void 0?{}:{xAxis:{...e.xAxis}},...e.yAxis===void 0?{}:{yAxis:{...e.yAxis}},quadrants:[...e.quadrants],points:e.points.map(i=>({...i,...i.style===void 0?{}:{style:Ma(i.style)}}))};if(Object.keys(e.classDefs).length>0){r.classDefs=Object.assign(Object.create(null),Object.fromEntries(Object.entries(e.classDefs).map(([i,n])=>[i,Ma(n)])))}return r}catch{return null}}function KB(t){return t.replaceAll("&","&amp;").replace(/\r?\n/g,"<br/>")}function nd(t){return mh(t.replaceAll("&","&amp;"),true)}function RT(t,e){const r=e.far!==void 0?` --> ${nd(e.far)}`:"";return` ${t} ${nd(e.near)}${r}`}function qT(t){const e=od(t)[0];if(e)throw new Error(e.message);const r=["quadrantChart"];Lt(r,t);if(t.title!==void 0)r.push(` title ${KB(t.title)}`);if(t.xAxis)r.push(RT("x-axis",t.xAxis));if(t.yAxis)r.push(RT("y-axis",t.yAxis));for(let i=0;i<4;i++){const n=t.quadrants[i];if(n!=null)r.push(` quadrant-${i+1} ${nd(n)}`)}for(const i of t.points){const n=i.className!==void 0?`:::${i.className}`:"";const o=hh(i.style&&Ma(i.style));r.push(` ${nd(i.label)}${n}: [${LT(i.x)}, ${LT(i.y)}]${o?` ${o}`:""}`)}for(const[i,n]of Object.entries(t.classDefs??{})){r.push(` classDef ${i} ${hh(Ma(n))}`)}return r.join("\n")+"\n"}function DT(t){return{near:t.near,far:t.far}}function NT(t){const e={};if(t.radius!==void 0)e.radius=t.radius;if(t.color!==void 0)e.color=t.color;if(t.strokeColor!==void 0)e.strokeColor=t.strokeColor;if(t.strokeWidth!==void 0)e.strokeWidth=t.strokeWidth;if(t.extra!==void 0)e.extra=[...t.extra];return e}function JB(t){const e={kind:"quadrant",accessibilityTitle:t.accessibilityTitle,accessibilityDescription:t.accessibilityDescription,title:t.title,xAxis:t.xAxis?DT(t.xAxis):void 0,yAxis:t.yAxis?DT(t.yAxis):void 0,quadrants:[...t.quadrants],points:t.points.map(r=>{const i={label:r.label,x:r.x,y:r.y};if(r.className!==void 0)i.className=r.className;if(r.style!==void 0)i.style=NT(r.style);return i})};if(t.classDefs!==void 0){e.classDefs=Object.assign(Object.create(null),Object.fromEntries(Object.entries(t.classDefs).map(([r,i])=>[r,NT(i)])))}return e}function fn(t,e,r={}){if(typeof t!=="string")return T({code:"INVALID_OP",message:`Quadrant ${e} must be a string`});const i=t.trim();if(!i||i.includes("\n")){return T({code:"INVALID_OP",message:`Quadrant ${e} must be non-empty single-line text`})}if(!r.title&&!fh(i)){return T({code:"INVALID_OP",message:`Quadrant ${e} ${JSON.stringify(i)} has no supported lossless Mermaid text spelling`})}if(r.point&&(i.includes(":")||i.includes("[")||i.includes("]"))){return T({code:"INVALID_OP",message:`Quadrant ${e} must not contain ':' or brackets`})}return re(i)}function PT(t,e){const r=fn(t,e);if(!r.ok)return r;if(r.value.includes("-->")){return T({code:"INVALID_OP",message:`Quadrant ${e} must not contain "-->"`})}return r}function id(t,e){if(!XB(t)){return T({code:"INVALID_OP",message:`Quadrant ${e} must be a number in [0, 1], got ${JSON.stringify(t)}`})}return re(t)}function Ea(t,e){return t.points.findIndex(r=>r.label===e)}function zT(t,e){const r=od(t)[0];if(r)return T({code:"INVALID_OP",message:r.message});const i=JB(t);switch(e.kind){case"set_title":{const n=gt(i,"title",e.title,o=>fn(o,"title",{title:true}));if(!n.ok)return n;break}case"set_axis_labels":{if(e.axis!=="x"&&e.axis!=="y"){return T({code:"INVALID_OP",message:`Quadrant set_axis_labels axis must be 'x' or 'y', got ${JSON.stringify(e.axis)}`})}if(e.near===null){if(e.axis==="x")delete i.xAxis;else delete i.yAxis;break}const n=PT(e.near,`${e.axis}-axis near label`);if(!n.ok)return n;const o={near:n.value};if(e.far!==void 0&&e.far!==null){const s=PT(e.far,`${e.axis}-axis far label`);if(!s.ok)return s;o.far=s.value}if(e.axis==="x")i.xAxis=o;else i.yAxis=o;break}case"set_quadrant_label":{if(!Number.isInteger(e.quadrant)||e.quadrant<1||e.quadrant>4){return T({code:"INVALID_OP",message:`Quadrant number must be 1..4, got ${JSON.stringify(e.quadrant)}`})}const n=e.quadrant-1;if(e.label===null){i.quadrants[n]=void 0;break}const o=fn(e.label,"quadrant label");if(!o.ok)return o;i.quadrants[n]=o.value;break}case"add_point":{const n=fn(e.label,"point label",{point:true});if(!n.ok)return n;if(Ea(i,n.value)>=0){return T({code:"INVALID_OP",message:`Quadrant point "${n.value}" already exists`})}const o=id(e.x,"point x");if(!o.ok)return o;const s=id(e.y,"point y");if(!s.ok)return s;i.points.push({label:n.value,x:o.value,y:s.value});break}case"remove_point":{const n=fn(e.label,"point label",{point:true});if(!n.ok)return n;const o=Ea(i,n.value);if(o<0)return T({code:"POINT_NOT_FOUND",message:`Quadrant point "${n.value}" not found`});i.points.splice(o,1);break}case"move_point":{const n=fn(e.label,"point label",{point:true});if(!n.ok)return n;const o=Ea(i,n.value);if(o<0)return T({code:"POINT_NOT_FOUND",message:`Quadrant point "${n.value}" not found`});const s=id(e.x,"point x");if(!s.ok)return s;const a=id(e.y,"point y");if(!a.ok)return a;i.points[o].x=s.value;i.points[o].y=a.value;break}case"rename_point":{const n=fn(e.from,"point label",{point:true});if(!n.ok)return n;const o=fn(e.to,"point label",{point:true});if(!o.ok)return o;const s=Ea(i,n.value);if(s<0)return T({code:"POINT_NOT_FOUND",message:`Quadrant point "${n.value}" not found`});if(n.value!==o.value&&Ea(i,o.value)>=0){return T({code:"INVALID_OP",message:`Quadrant point "${o.value}" already exists`})}i.points[s].label=o.value;break}default:{const n=e;return T({code:"INVALID_OP",message:Ve("quadrant",n)})}}return re(i)}function a5(t){const e=t.split(/\r?\n/);const r=e.findIndex(o=>/^quadrant(?:Chart)?\b/i.test(o.trim()));if(r<0)return[];const i=[];const n=Cb(e);for(let o=r+1;o<e.length;o++){const s=ct(e,o);if(s===void 0)break;if(s!==null){o=s.endIndex;continue}try{const a=[];const l=$n(["quadrantChart",To(e,o,n[o]).trim()],c=>a.push(c));for(const c of a)i.push({code:"UNSUPPORTED_SYNTAX",syntax:"quadrant_unquoted_text",line:o+1,message:`${c}, and is read as written. Pinned Mermaid rejects this; put the whole text in double quotes.`});for(const c of od(l))i.push({code:"UNSUPPORTED_SYNTAX",...c,line:o+1,message:`${c.message}. Pinned Mermaid rejects this; the source and native rendering are preserved, and typed editing is unavailable.`});for(const c of[...l.points.map(d=>d.style),...Object.values(l.classDefs)]){if(c?.strokeWidth!==void 0&&!FT(c)&&!/^\d+px$/.test(c.strokeWidth))i.push({code:"UNSUPPORTED_SYNTAX",syntax:"quadrant_stroke_width",line:o+1,message:`Quadrant stroke-width ${JSON.stringify(c.strokeWidth)} is read as a pixel width. Pinned Mermaid requires integer px units; canonical export writes ${Ma(c).strokeWidth}.`})}}catch{}o=n[o]}return i}function GT(t,e){const r=[];const i=Ke(r,e);const n=t.title===void 0&&!t.xAxis&&!t.yAxis&&t.quadrants.every(o=>o===void 0)&&t.points.length===0;if(n)r.push({code:"EMPTY_DIAGRAM"});if(t.title!==void 0)i("title",t.title);if(t.xAxis){i("x-axis",t.xAxis.near);if(t.xAxis.far!==void 0)i("x-axis",t.xAxis.far)}if(t.yAxis){i("y-axis",t.yAxis.near);if(t.yAxis.far!==void 0)i("y-axis",t.yAxis.far)}for(let o=0;o<4;o++){const s=t.quadrants[o];if(s!==void 0)i(`quadrant-${o+1}`,s)}for(const o of t.points)i(o.label,o.label);return r}var QB=/^[A-Za-z_](?:[\w-]*[\w])?$/;var ZB=new Set(["radar-beta","axis","curve","showLegend","ticks","max","min","graticule"]);var e_=/^(?:true|false|circle|polygon|title)/;function sd(t){return QB.test(t)&&!ZB.has(t)&&!e_.test(t)}function VT(t){const e=qb(t);for(let r=0;r<t.length;r=e[r]+1){if(/^\s*acc(?:Title|Descr)\b/i.test(t[r]))return null}try{const r=ra(["radar-beta",...t]);const i={kind:"radar",title:r.title,axes:r.axes.map(n=>({id:n.id,label:n.label})),curves:r.curves.map(n=>({id:n.id,label:n.label,values:[...n.values]})),min:r.min,max:r.max,ticks:r.ticks,graticule:r.graticule,showLegend:r.showLegend};return ad(i,true)===null?{body:i,accessibility:r.statementAccessibility??{}}:null}catch{return null}}function ad(t,e=false){const r=e&&t.axes.length===0&&t.curves.length===0;if(t.axes.length===0&&!r)return"Radar requires at least one axis before curves can exist.";if(t.axes.some(i=>!sd(i.id)))return"Every typed radar axis id must have a portable Mermaid identifier spelling.";if(t.curves.some(i=>!sd(i.id)))return"Every typed radar curve id must have a portable Mermaid identifier spelling.";if(t.axes.some(i=>i.label.trim().length===0))return"Typed radar axis labels must be non-empty.";if(t.curves.some(i=>i.label.trim().length===0))return"Typed radar curve labels must be non-empty.";if(t.title!==void 0&&t.title.trim().length===0)return"A typed radar title must be non-empty.";if(new Set(t.axes.map(i=>i.id)).size!==t.axes.length)return"Radar axis ids must be unique for typed mutation.";if(new Set(t.curves.map(i=>i.id)).size!==t.curves.length)return"Radar curve ids must be unique for typed mutation.";for(const i of t.curves){if(i.values.length!==t.axes.length){return`Radar curve "${i.id}" needs exactly ${t.axes.length} value(s) (one per axis).`}}if(!Number.isInteger(t.ticks)||t.ticks<1||t.ticks>ta){return`Radar ticks must be an integer from 1 through ${ta}.`}if(r){if(!Number.isFinite(t.min)||t.min<0)return"Radar min must be a finite non-negative number.";if(t.max!==void 0&&(!Number.isFinite(t.max)||t.max<=t.min))return"Radar max must be finite and greater than min.";return null}try{ia(t)}catch(i){return i instanceof Error?i.message:String(i)}return null}function WT(t,e){if(e===t)return t;const r=e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t");return`${t}["${r}"]`}function YT(t){const e=["radar-beta"];if(t.title!==void 0)e.push(` title ${t.title.replace(/\r\n?|\n/g,"<br/>")}`);if(t.axes.length>0){e.push(" axis "+t.axes.map(r=>WT(r.id,r.label)).join(", "))}for(const r of t.curves){e.push(` curve ${WT(r.id,r.label)}{${r.values.map(Kn).join(", ")}}`)}if(t.min!==0)e.push(` min ${Kn(t.min)}`);if(t.max!==void 0)e.push(` max ${Kn(t.max)}`);if(t.ticks!==5)e.push(` ticks ${Kn(t.ticks)}`);if(t.graticule!=="circle")e.push(` graticule ${t.graticule}`);if(!t.showLegend)e.push(" showLegend false");return e.join("\n")+"\n"}function t_(t){return{kind:"radar",title:t.title,axes:t.axes.map(e=>({id:e.id,label:e.label})),curves:t.curves.map(e=>({id:e.id,label:e.label,values:[...e.values]})),min:t.min,max:t.max,ticks:t.ticks,graticule:t.graticule,showLegend:t.showLegend}}function es(t,e){if(typeof t!=="string"||!sd(t.trim())){return T({code:"INVALID_OP",message:`Radar ${e} must start with a letter or _, keep dashes inside, and avoid reserved words or prefixes true/false/circle/polygon/title, got ${JSON.stringify(t)}`})}return re(t.trim())}function Aa(t,e){if(typeof t!=="string")return T({code:"INVALID_OP",message:`Radar ${e} must be a string`});const r=Ot(t).trim();if(!r)return T({code:"INVALID_OP",message:`Radar ${e} must be non-empty text`});return re(r)}function ts(t,e){if(typeof t!=="number"||!Number.isFinite(t)||t<0){return T({code:"INVALID_OP",message:`Radar ${e} must be a non-negative number, got ${JSON.stringify(t)}`})}return re(t)}function rs(t,e){return t.axes.findIndex(r=>r.id===e)}function Jn(t,e){return t.curves.findIndex(r=>r.id===e)}function UT(t,e,r){if(t===void 0)return re(e);if(!Number.isInteger(t)||t<0||t>e){return T({code:"INVALID_OP",message:`Radar ${r} index must be an integer from 0 through ${e}, got ${JSON.stringify(t)}`})}return re(t)}function HT(t,e){const r=t_(t);switch(e.kind){case"set_title":{const n=gt(r,"title",e.title,o=>Aa(o,"title"));if(!n.ok)return n;break}case"add_axis":{const n=es(e.id,"axis id");if(!n.ok)return n;if(rs(r,n.value)>=0)return T({code:"INVALID_OP",message:`Radar axis "${n.value}" already exists`});let o=n.value;if(e.label!==void 0&&e.label!==null){const l=Aa(e.label,"axis label");if(!l.ok)return l;o=l.value}let s=r.min;if(e.fill!==void 0){const l=ts(e.fill,"axis fill value");if(!l.ok)return l;s=l.value}const a=UT(e.index,r.axes.length,"axis insertion");if(!a.ok)return a;r.axes.splice(a.value,0,{id:n.value,label:o});for(const l of r.curves)l.values.splice(a.value,0,s);break}case"remove_axis":{const n=rs(r,typeof e.id==="string"?e.id:"");if(n<0)return T({code:"AXIS_NOT_FOUND",message:`Radar axis "${String(e.id)}" not found`});r.axes.splice(n,1);for(const o of r.curves)o.values.splice(n,1);break}case"rename_axis":{const n=es(e.from,"axis id");if(!n.ok)return n;const o=es(e.to,"axis id");if(!o.ok)return o;const s=rs(r,n.value);if(s<0)return T({code:"AXIS_NOT_FOUND",message:`Radar axis "${n.value}" not found`});if(n.value!==o.value&&rs(r,o.value)>=0)return T({code:"INVALID_OP",message:`Radar axis "${o.value}" already exists`});const a=r.axes[s];const l=a.label===a.id;a.id=o.value;if(l)a.label=o.value;break}case"set_axis_label":{const n=rs(r,typeof e.id==="string"?e.id:"");if(n<0)return T({code:"AXIS_NOT_FOUND",message:`Radar axis "${String(e.id)}" not found`});if(e.label===null){r.axes[n].label=r.axes[n].id;break}const o=Aa(e.label,"axis label");if(!o.ok)return o;r.axes[n].label=o.value;break}case"reorder_axis":{const n=jT(r.axes.length,e.from,e.to,"axis");if(!n.ok)return n;const[o,s]=[n.value.from,n.value.to];const[a]=r.axes.splice(o,1);r.axes.splice(s,0,a);for(const l of r.curves){const[c]=l.values.splice(o,1);l.values.splice(s,0,c)}break}case"add_curve":{const n=es(e.id,"curve id");if(!n.ok)return n;if(Jn(r,n.value)>=0)return T({code:"INVALID_OP",message:`Radar curve "${n.value}" already exists`});if(!Array.isArray(e.values)||e.values.length!==r.axes.length){return T({code:"INVALID_OP",message:`Radar curve "${n.value}" needs exactly ${r.axes.length} value(s) (one per axis)`})}const o=[];for(const l of e.values){const c=ts(l,"curve value");if(!c.ok)return c;o.push(c.value)}let s=n.value;if(e.label!==void 0&&e.label!==null){const l=Aa(e.label,"curve label");if(!l.ok)return l;s=l.value}const a=UT(e.index,r.curves.length,"curve insertion");if(!a.ok)return a;r.curves.splice(a.value,0,{id:n.value,label:s,values:o});break}case"remove_curve":{const n=Jn(r,typeof e.id==="string"?e.id:"");if(n<0)return T({code:"CURVE_NOT_FOUND",message:`Radar curve "${String(e.id)}" not found`});r.curves.splice(n,1);break}case"set_curve_values":{const n=Jn(r,typeof e.id==="string"?e.id:"");if(n<0)return T({code:"CURVE_NOT_FOUND",message:`Radar curve "${String(e.id)}" not found`});if(!Array.isArray(e.values)||e.values.length!==r.axes.length){return T({code:"INVALID_OP",message:`Radar curve values must have exactly ${r.axes.length} entr(y/ies) (one per axis)`})}const o=[];for(const s of e.values){const a=ts(s,"curve value");if(!a.ok)return a;o.push(a.value)}r.curves[n].values=o;break}case"set_curve_value":{const n=Jn(r,typeof e.curve==="string"?e.curve:"");if(n<0)return T({code:"CURVE_NOT_FOUND",message:`Radar curve "${String(e.curve)}" not found`});const o=rs(r,typeof e.axis==="string"?e.axis:"");if(o<0)return T({code:"AXIS_NOT_FOUND",message:`Radar axis "${String(e.axis)}" not found`});const s=ts(e.value,"curve value");if(!s.ok)return s;r.curves[n].values[o]=s.value;break}case"set_curve_label":{const n=Jn(r,typeof e.id==="string"?e.id:"");if(n<0)return T({code:"CURVE_NOT_FOUND",message:`Radar curve "${String(e.id)}" not found`});if(e.label===null){r.curves[n].label=r.curves[n].id;break}const o=Aa(e.label,"curve label");if(!o.ok)return o;r.curves[n].label=o.value;break}case"rename_curve":{const n=es(e.from,"curve id");if(!n.ok)return n;const o=es(e.to,"curve id");if(!o.ok)return o;const s=Jn(r,n.value);if(s<0)return T({code:"CURVE_NOT_FOUND",message:`Radar curve "${n.value}" not found`});if(n.value!==o.value&&Jn(r,o.value)>=0)return T({code:"INVALID_OP",message:`Radar curve "${o.value}" already exists`});const a=r.curves[s];const l=a.label===a.id;a.id=o.value;if(l)a.label=o.value;break}case"reorder_curve":{const n=jT(r.curves.length,e.from,e.to,"curve");if(!n.ok)return n;const[o]=r.curves.splice(n.value.from,1);r.curves.splice(n.value.to,0,o);break}case"set_config":{const n={min:r.min,max:r.max,ticks:r.ticks,graticule:r.graticule,showLegend:r.showLegend};if(e.min!==void 0){if(e.min===null)n.min=0;else{const o=ts(e.min,"min");if(!o.ok)return o;n.min=o.value}}if(e.max!==void 0){if(e.max===null)n.max=void 0;else{const o=ts(e.max,"max");if(!o.ok)return o;n.max=o.value}}if(e.ticks!==void 0){if(e.ticks===null)n.ticks=5;else{if(!Number.isInteger(e.ticks)||e.ticks<1||e.ticks>ta)return T({code:"INVALID_OP",message:`Radar ticks must be an integer from 1 through ${ta}, got ${JSON.stringify(e.ticks)}`});n.ticks=e.ticks}}if(e.graticule!==void 0){if(e.graticule===null)n.graticule="circle";else if(e.graticule!=="circle"&&e.graticule!=="polygon")return T({code:"INVALID_OP",message:`Radar graticule must be 'circle' or 'polygon'`});else n.graticule=e.graticule}if(e.showLegend!==void 0){if(e.showLegend===null)n.showLegend=true;else if(typeof e.showLegend!=="boolean")return T({code:"INVALID_OP",message:"Radar showLegend must be a boolean"});else n.showLegend=e.showLegend}if(n.max!==void 0&&n.max<=n.min)return T({code:"INVALID_OP",message:`Radar max (${n.max}) must be greater than min (${n.min})`});r.min=n.min;r.max=n.max;r.ticks=n.ticks;r.graticule=n.graticule;r.showLegend=n.showLegend;break}default:{const n=e;return T({code:"INVALID_OP",message:Ve("radar",n)})}}const i=ad(r,true);if(i)return T({code:"INVALID_OP",message:i});return re(r)}function jT(t,e,r,i){if(!Number.isInteger(e)||e<0||e>=t){return T({code:"INVALID_OP",message:`Radar reorder ${i} 'from' must be 0..${t-1}, got ${JSON.stringify(e)}`})}if(!Number.isInteger(r)||r<0||r>=t){return T({code:"INVALID_OP",message:`Radar reorder ${i} 'to' must be 0..${t-1}, got ${JSON.stringify(r)}`})}return re({from:e,to:r})}function x5(t){const e=st(t);let r;try{r=ra(e.familyLines)}catch{return[]}const i=[];for(const[n,o]of[["axis",r.axes],["curve",r.curves]]){for(const{id:s}of o){if(sd(s))continue;i.push({code:"UNSUPPORTED_SYNTAX",syntax:"radar_id",node:s,message:`Radar ${n} id "${s}" is read as written, but pinned Mermaid reads it as another token. The source is preserved; use an id starting with a letter or _, avoiding reserved words and prefixes true/false/circle/polygon/title, before typed editing.`})}}return i.concat(Il(r.statementAccessibility??{},e.accessibility).map(n=>({code:"UNSUPPORTED_SYNTAX",syntax:"radar_accessibility_order",message:`Radar chart has an ${n} after a statement on its line and another on a line of its own. Mermaid keeps the one written last; this reader cannot tell which that is, so the source is kept as written and the one on its own line is drawn. Keep one ${n}, on a line of its own.`})))}function XT(t,e){const r=[];const i=Ke(r,e,void 0,"literal");const n=ia(t);if(t.min>0)r.push({code:"SCALE_RANGE_EXCLUDES_ZERO",range:n,baseline:t.min,message:"Radar radii use value minus min; a non-zero baseline exaggerates relative differences."});for(const o of t.curves){const s=o.values.filter(a=>a<n.min||a>n.max);if(s.length)r.push({code:"VALUES_OUTSIDE_RANGE",series:o.id,values:s,range:n,message:"Radar values outside the authored range are clipped to its boundary."})}if(t.axes.length===0&&t.curves.length===0)r.push({code:"EMPTY_DIAGRAM"});if(t.title!==void 0)i("title",t.title);for(const o of t.axes)i(o.id,o.label);for(const o of t.curves)i(o.id,o.label);return r}var r_=/^sankey(?:-beta)?\s*:?\s*$/i;function i_(t){return String(t)}function e0(t,e={}){if(t.some(i=>/^\s*acc(?:Title|Descr)\b/i.test(i)))return null;const r=["sankey-beta",...t];try{const i=gc(r);const n={kind:"sankey",links:i.links.map(o=>({source:o.source,target:o.target,value:o.value}))};return t0(n,false)===null?n:null}catch{return null}}function t0(t,e=false){if(t.links.length===0&&!e){return"Sankey requires at least one source,target,value link."}for(const i of t.links){for(const[n,o]of[["source",i.source],["target",i.target]]){if(typeof o!=="string"||o.trim().length===0){return`Every typed sankey link needs a non-empty ${n} label.`}if(/[\r\n]/.test(o))return`Sankey ${n} labels cannot contain line breaks.`;if(o.includes("%%{"))return`Sankey ${n} labels cannot contain a directive opener; CSV has no escape that preserves this identity.`}if(!Number.isFinite(i.value)||i.value<0){return`Sankey link "${i.source}" -> "${i.target}" needs a non-negative finite value.`}if(i.source===i.target){return`Sankey link "${i.source}" -> "${i.target}" is a self-loop; sankey diagrams must be acyclic.`}}const r=Ub(t.links);if(r){return`Sankey links contain a cycle: ${r.map(i=>`"${i}"`).join(" -> ")}; sankey diagrams must be acyclic.`}return null}function KT(t){if(/[",]/.test(t)||t!==t.trim()){return`"${t.replace(/"/g,'""')}"`}return t}function r0(t){const e=["sankey-beta"];for(const r of t.links){e.push(` ${KT(r.source)},${KT(r.target)},${i_(r.value)}`)}return e.join("\n")+"\n"}function n_(t){return{kind:"sankey",links:t.links.map(e=>({source:e.source,target:e.target,value:e.value}))}}function ld(t,e){if(typeof t!=="string"||t.trim().length===0){return T({code:"INVALID_OP",message:`Sankey ${e} must be non-empty text, got ${JSON.stringify(t)}`})}if(/[\r\n]/.test(t)){return T({code:"INVALID_OP",message:`Sankey ${e} cannot contain line breaks`})}return re(t.trim())}function JT(t,e){if(typeof t!=="number"||!Number.isFinite(t)||t<0){return T({code:"INVALID_OP",message:`Sankey ${e} must be a non-negative number, got ${JSON.stringify(t)}`})}return re(t)}function QT(t,e,r,i){let n=i;for(let o=0;o<t.links.length;o++){const s=t.links[o];if(s.source===e&&s.target===r){if(n===0)return o;n--}}return-1}function ZT(t){if(t===void 0)return re(0);if(!Number.isInteger(t)||t<0){return T({code:"INVALID_OP",message:`Sankey occurrence must be a non-negative integer, got ${JSON.stringify(t)}`})}return re(t)}function i0(t,e){const r=n_(t);switch(e.kind){case"add_link":{const n=ld(e.source,"link source");if(!n.ok)return n;const o=ld(e.target,"link target");if(!o.ok)return o;const s=JT(e.value,"link value");if(!s.ok)return s;if(n.value===o.value){return T({code:"INVALID_OP",message:`Sankey link "${n.value}" -> "${o.value}" would be a self-loop`})}let a=r.links.length;if(e.index!==void 0){if(!Number.isInteger(e.index)||e.index<0||e.index>r.links.length){return T({code:"INVALID_OP",message:`Sankey link index must be an integer from 0 through ${r.links.length}, got ${JSON.stringify(e.index)}`})}a=e.index}r.links.splice(a,0,{source:n.value,target:o.value,value:s.value});break}case"remove_link":{const n=ZT(e.occurrence);if(!n.ok)return n;const o=QT(r,String(e.source),String(e.target),n.value);if(o<0){return T({code:"LINK_NOT_FOUND",message:`Sankey link "${String(e.source)}" -> "${String(e.target)}" (occurrence ${n.value}) not found`})}r.links.splice(o,1);break}case"set_link_value":{const n=ZT(e.occurrence);if(!n.ok)return n;const o=JT(e.value,"link value");if(!o.ok)return o;const s=QT(r,String(e.source),String(e.target),n.value);if(s<0){return T({code:"LINK_NOT_FOUND",message:`Sankey link "${String(e.source)}" -> "${String(e.target)}" (occurrence ${n.value}) not found`})}r.links[s].value=o.value;break}case"rename_node":{const n=ld(e.from,"node label");if(!n.ok)return n;const o=ld(e.to,"node label");if(!o.ok)return o;const s=r.links.some(a=>a.source===n.value||a.target===n.value);if(!s)return T({code:"NODE_NOT_FOUND",message:`Sankey node "${n.value}" not found`});if(n.value!==o.value&&r.links.some(a=>a.source===o.value||a.target===o.value)){return T({code:"INVALID_OP",message:`Sankey node "${o.value}" already exists; renaming would merge two nodes' flows`})}for(const a of r.links){if(a.source===n.value)a.source=o.value;if(a.target===n.value)a.target=o.value}break}default:{const n=e;return T({code:"INVALID_OP",message:Ve("sankey",n)})}}const i=t0(r,true);if(i)return T({code:"INVALID_OP",message:i});return re(r)}function n0(t,e){const r=[];const i=Ke(r,e);if(t.links.length===0)r.push({code:"EMPTY_DIAGRAM"});const n=new Set;for(const a of t.links){for(const l of[a.source,a.target]){if(n.has(l))continue;n.add(l);i(l,l)}}const o=new Map;const s=new Map;for(const a of t.links){s.set(a.source,(s.get(a.source)??0)+a.value);o.set(a.target,(o.get(a.target)??0)+a.value)}for(const a of n){const l=o.get(a);const c=s.get(a);if(l===void 0||c===void 0)continue;if(Math.abs(l-c)<=1e-9*Math.max(1,l,c))continue;const d=Number(Math.abs(l-c).toPrecision(12));r.push({code:"FLOW_IMBALANCE",node:a,inflow:l,outflow:c,message:`Sankey node "${a}" receives ${l} but emits ${c}; the unaccounted ${d} renders as node height with no matching ribbon`})}return r}function E5(t,e){const r=t.split(/\r?\n/);const i=r.findIndex(a=>r_.test(a.trim()));if(i<0)return[];let n=r.length-1;while(n>i&&!r[n].trim())n--;const o=[];let s="";for(let a=i+1;a<=n;a++){const l=r[a].trim();if(!l)continue;const c=s.length>0;if(!c&&Gb(l)){o.push({code:"UNSUPPORTED_SYNTAX",syntax:"sankey_repeated_header",line:a+1,message:"A standalone repeated Sankey header is read as a header, not a CSV row. Pinned Mermaid rejects it; canonical export writes one header."});continue}const d=c?null:ct(r,a);if(d===void 0)break;if(d){o.push({code:"UNSUPPORTED_SYNTAX",syntax:"sankey_accessibility",line:a+1,message:"Sankey accessibility metadata is carried in native comments on export. External Mermaid ignores this metadata; diagram topology is preserved."});a=d.endIndex;continue}if(!c&&l.startsWith("%%"))continue;s=c?`${s}
184
+ ${r[a]}`:r[a];if(!Wb(s))s="";const u=e?.(a+1)??r[a];const h=a===n?u.trimEnd():u;if(h.includes("%%{"))o.push({code:"UNSUPPORTED_SYNTAX",syntax:"sankey_directive_text",line:a+1,message:"A Sankey node name containing a directive opener is read as written. Pinned Mermaid rejects it, and CSV has no escape preserving the name; this source remains preserved without typed edits."});const m=/[^\x20-\x7E\r]/u.exec(h)?.[0];if(m!==void 0){const p=m===" "?"a tab":`${JSON.stringify(m)} (U+${m.codePointAt(0).toString(16).toUpperCase().padStart(4,"0")})`;o.push({code:"UNSUPPORTED_SYNTAX",syntax:"sankey_unsupported_character",line:a+1,message:`Pinned Mermaid's Sankey reader takes only printable ASCII characters in a row, quoted or not, and rejects ${p} here. Ours reads the row as written; ${m===" "?"use spaces instead":"Mermaid has no spelling for this character"}.`})}const f=/#\w+;/.exec(tn(h))?.[0];if(f!==void 0)o.push({code:"UNSUPPORTED_SYNTAX",syntax:"sankey_unsupported_character",line:a+1,message:`Pinned Mermaid reads ${f} as an entity code, which its Sankey reader then rejects as a character outside printable ASCII. Ours reads and draws ${f} as written; Mermaid has no spelling for this text, so write the character itself if it is printable ASCII.`})}return o}function Hm(t,e){const r=[];const i=[];const n=new Ml;const o=Rn(e??t);Jm(o);if(o.issues.some(c=>c.syntax==="sequence_block_boundary"))return null;const s=o.statements;let a=0;while(a<s.length){const c=s[a];const d=c.raw;const u=d.trim();const h=c.syntax;if(!u){a++;continue}if(Bs(u)){$i(i,[d],Oa);a++;continue}if(h?.kind==="declaration"){const m=h.declaration;if(m.unmodeledMetadata?.length){n.applyAll(an(h));$i(i,[d],Oa);a++;continue}if(n.has(m.id)&&!m.aliased){$i(i,[d],Oa);a++;continue}n.applyAll(an(h));i.push({kind:"participant",ref:n.indexOf(m.id)});a++;continue}if(h?.kind==="links"){n.applyAll(an(h));i.push({kind:"actor-links",actorId:h.actorId,links:{...h.links}});a++;continue}if(h?.kind==="message"){n.applyAll(an(h));r.push(Xm(h.message));i.push({kind:"message",ref:r.length-1});a++;continue}if(h?.kind==="block"||h?.kind==="box"){const m=s.slice(a,c.endIndex+1);const f=m.map(a0);a=c.endIndex+1;const p=o_(m);for(const g of m)n.applyAll(an(g.syntax));if(p){i.push({kind:"fragment",fragment:p})}else{$i(i,f,Oa)}continue}n.applyAll(an(h));$i(i,[d],Oa);a++}const l={kind:"sequence",participants:n.list().map(s0),messages:r,statements:i};return Km(l)?null:l}var Oa=t=>({kind:"opaque-block",lines:t});function s0({id:t,label:e,type:r,keyword:i,links:n,wrap:o}){const s=sn(e);return{id:t,label:s.value,kind:r,...o===void 0?{}:{wrap:o},...s.content?{labelContent:s.content}:{},...i&&i!==r?{declaration:i}:{},...n&&Object.keys(n).length>0?{links:n}:{}}}function hd(t){const e=t.trim();if(!e||Bs(e))return[];try{return Jy(e)}catch{return[]}}function Xm(t){const e=sn(t.label.trim());return{from:t.from,to:t.to,text:e.value,style:a_(t.arrow),...t.wrap===void 0?{}:{wrap:t.wrap},...e.content?{textContent:e.content}:{},arrow:t.arrow,...t.centralStart?{centralStart:true}:{},...t.centralEnd?{centralEnd:true}:{},...t.activationMark==="+"?{activate:true}:{},...t.activationMark==="-"?{deactivate:true}:{}}}function a0(t){const e=t.syntax?.kind==="message"?t.syntax.message:void 0;if(e?.label.includes("%%"))return Zm(Xm(e));let r=t.raw;if(e?.localArrow){const i=r.indexOf(e.localArrow,r.length-r.trimStart().length+e.from.length);r=r.slice(0,i)+e.arrow+r.slice(i+e.localArrow.length)}return e?l0(e.from,r):r}function o_(t){const e=t[0]?.syntax;const r=e?.kind==="block"?e.opener:void 0;if(!r||!["alt","opt","loop","par","par_over"].includes(r.type))return null;const i=r.type;const n=[{messages:[]}];for(const s of t.slice(1,-1)){const a=s.raw.trim();if(!a)continue;if(a.startsWith("%%"))return null;const l=s.syntax;if(l?.kind==="continuation"){const c=l.continuation;const d=sn(c.label);n.push({...c.wrap===void 0?{}:{wrap:c.wrap},...d.value?{label:d.value}:{},...d.content?{labelContent:d.content}:{},messages:[]});continue}if(l?.kind!=="message")return null;n.at(-1).messages.push(Xm(l.message))}const o=sn(r.label);return{fragmentKind:i,...r.wrap===void 0?{}:{wrap:r.wrap},...o.value?{label:o.value}:{},...o.content?{labelContent:o.content}:{},branches:n,rawLines:t.map(a0)}}function s_(t){const e=[];let r=0;for(const i of t.statements){if(i.kind==="message"){const n=t.messages[i.ref];if(n)e.push({scope:"top-level",message:n})}else if(i.kind==="fragment"){i.fragment.branches.forEach((n,o)=>{for(const s of n.messages)e.push({scope:"fragment",message:s,fragmentIndex:r,branchIndex:o,fragmentKind:i.fragment.fragmentKind,...i.fragment.label?{fragmentLabel:i.fragment.label}:{},...n.label?{branchLabel:n.label}:{}})});r++}}return e}function q5(t){return s_(t).map(e=>e.message)}function a_(t){switch(t){case"->>":return"sync";case"-->>":return"reply";case"->":return"async";case"-->":return"async-dashed";case"-x":return"lost";case"--x":return"lost-dashed";default:return"sync"}}function z5(t){const e=t.split(/\r?\n/);const r=e.findIndex(m=>/^sequenceDiagram\b/.test(m.trim()));if(r<0)return[];const i=[];const n=e.slice(r+1);for(const m of Sy(n)){const f=/&([a-zA-Z][a-zA-Z\d]{0,31})$/.exec(m.raw)?.[1];if(f!==void 0&&n[m.line][m.endColumn]===";"&&Uy(f))i.push({code:"UNSUPPORTED_SYNTAX",syntax:"sequence_named_reference_semicolon",line:r+m.line+2,message:'The renderer reads a named reference such as &amp; or &nbsp; as text, but pinned Mermaid ends the statement at its ";". Write its Mermaid entity (#amp;, #nbsp;) instead.'})}const o=jy(t).split(/\r?\n/);const s=o.findIndex(m=>/^sequenceDiagram\b/.test(m.trim()));if(s<0)return i;let a=s+1;const l=new Ml({onBoxConflict:m=>i.push({code:"UNSUPPORTED_SYNTAX",syntax:"sequence_participant_in_two_boxes",line:a,message:`Participant "${m}" in a second box stays in the box that first placed it. Pinned Mermaid rejects this; put each participant in one box only.`})});const c=o.slice(s+1);for(let m=s+1;m<o.length;m++){const f=ct(o,m);if(f===void 0)break;if(f!==null){for(let p=m;p<=f.endIndex;p++)c[p-s-1]="";if(f.suffixLine)c[f.endIndex-s-1]=f.suffixLine;m=f.endIndex;continue}}const d=Rn(c);for(const m of d.issues)i.push({code:"UNSUPPORTED_SYNTAX",syntax:m.syntax,line:s+m.line+2,message:m.message});const u=new Map;const h=(m,f)=>{const p=u.get(m)??0;if(p>0){u.set(m,p-1);return}i.push({code:"UNSUPPORTED_SYNTAX",syntax:"sequence_inactive_deactivation",line:a,message:`${f} deactivates participant "${m}", which is not active; ours ignores it. Pinned Mermaid rejects this ("Trying to inactivate an inactive participant"); activate "${m}" first or remove the deactivation.`})};for(const m of d.statements){a=s+m.line+2;const f=m.syntax;l.applyAll(an(f));if(f?.kind==="message"&&f.message.activationMark==="+")u.set(f.message.to,(u.get(f.message.to)??0)+1);else if(f?.kind==="message"&&f.message.activationMark==="-")h(f.message.from,'The "-" on this message');else if(f?.kind==="activation"&&f.activate)u.set(f.actorId,(u.get(f.actorId)??0)+1);else if(f?.kind==="activation")h(f.actorId,"This statement");if(f?.kind==="box")l.openBox({actorIds:[]});else if(m.closes!==void 0&&d.statements[m.closes]?.syntax?.kind==="box"){l.closeBox()}}return i}function md(t){const e=Km(t);if(e)throw new Error(e.message);const r=["sequenceDiagram"];if(t.statements.length>0){const i=new Set;for(const n of t.statements){if(n.kind==="opaque-block"){Jm(Rn(n.lines));for(const o of n.lines)r.push(Bs(o)?wo(o):o)}else if(n.kind==="participant"){const o=t.participants[n.ref];if(o)r.push(c_(o,i.has(o.id)))}else if(n.kind==="actor-links"){if(n.actorId.toLowerCase()==="title")r.push(` links ${n.actorId}:${JSON.stringify(n.links)}`);else for(const[o,s]of Object.entries(n.links))r.push(` link ${n.actorId}: ${o} @ ${s}`)}else if(n.kind==="fragment"){r.push(...l_(n.fragment))}else{const o=t.messages[n.ref];if(o)r.push(Zm(o))}for(const o of Qm(n,t.participants,t.messages))i.add(o)}return r.join("\n")+"\n"}return r.join("\n")+"\n"}function is(t,e){if(e==="declaration"){const r=Al(t);return r?{code:"INVALID_OP",message:r}:void 0}if(Yy(t,e))return void 0;return{code:"INVALID_OP",message:`Sequence participant ID "${t}" has no portable spelling as a ${e}; choose another ID and keep display text in its label`}}function ud(t){return is(t.from,"sender")??is(t.to,"receiver")}function Km(t){for(const e of t.statements){let r;if(e.kind==="participant"){const i=t.participants[e.ref];if(i){r=is(i.id,"declaration");const n=i.declaration??(i.kind==="actor"?"actor":"participant");if(/\s/.test(i.id)&&(i.label!==sn(i.id).value||i.kind!==n||i.wrap!==void 0)){r={code:"INVALID_OP",message:"Sequence names containing spaces support a bare participant/actor declaration; aliases and type metadata require an ID without spaces"}}}}else if(e.kind==="actor-links"){r=is(e.actorId,"receiver")}else if(e.kind==="message"){const i=t.messages[e.ref];if(i)r=ud(i)}else if(e.kind==="fragment"){for(const i of e.fragment.branches){for(const n of i.messages){r=ud(n);if(r)return r}}}if(r)return r}return void 0}function l_(t){if(t.rawLines){Jm(Rn(t.rawLines));return[...t.rawLines]}const e=` ${t.fragmentKind} `;const r=[t.label||t.wrap!==void 0?e+yo(t.label??"",t.labelContent,t.wrap,e):e.trimEnd()];t.branches.forEach((i,n)=>{if(n>0){const o=` ${t.fragmentKind==="par"||t.fragmentKind==="par_over"?"and":"else"} `;r.push(i.label||i.wrap!==void 0?o+yo(i.label??"",i.labelContent,i.wrap,o):o.trimEnd())}for(const o of i.messages)r.push(` ${Zm(o).trimStart()}`)});r.push(" end");return r}function c_(t,e){const r=Al(t.id);if(r)throw new Error(r);const i=t.declaration??(t.kind==="actor"?"actor":"participant");const n=t.kind!==i?`@{ "type": "${t.kind}" }`:"";const o=` ${i} ${t.id}${n}`;if(/\s/.test(t.id))return o;const s=yo(t.label,t.labelContent,t.wrap,`${o} as `);return`${o}${s!==t.id||e?` as ${s}`:""}`}function Jm(t){const e=t.issues.find(r=>r.syntax==="sequence_participant_id"||r.syntax==="sequence_participant_id_extension");if(e)throw new Ol(e.message)}function Qm(t,e,r){const i=n=>n?[n.from,n.to]:[];switch(t.kind){case"participant":return e[t.ref]?[e[t.ref].id]:[];case"message":return i(r[t.ref]);case"fragment":return t.fragment.branches.flatMap(n=>n.messages.flatMap(i));case"actor-links":return[t.actorId];case"opaque-block":return t.lines.flatMap(n=>hd(n).map(o=>o.id))}}function l0(t,e){return t.startsWith("@{")?`;${e}`:e}function Zm(t){const e=`${t.from}${t.centralStart?"()":""}`;const r=`${t.centralEnd?"()":""}${t.activate?"+":t.deactivate?"-":""}${t.to}`;const i=` ${e}${t.arrow??d_(t.style)}${r}:${t.to.toLowerCase()==="title"?"":" "}`;return l0(t.from,i+yo(t.text,t.textContent,t.wrap,i))}function d_(t){switch(t){case"sync":return"->>";case"reply":return"-->>";case"async":return"->";case"async-dashed":return"-->";case"lost":return"-x";case"lost-dashed":return"--x"}}function c0(t,e){return h0(u0(t),e)}function d0(t){let e=u0(t);return r=>{const i=h0(e,r);if(i.ok)e=i.value;return i}}function u0(t){const e=t.participants.map(n=>({...n,...n.links?{links:{...n.links}}:{}}));const r=t.messages.map(n=>({...n}));const i=t.statements.map(f0);return{kind:"sequence",participants:e,messages:r,statements:i}}function h0(t,e){const{participants:r,messages:i,statements:n}=t;switch(e.kind){case"add_participant":{const a=is(e.id,"declaration");if(a)return T(a);if(r.some(c=>c.id===e.id))return T({code:"DUPLICATE_PARTICIPANT",message:`Participant "${e.id}" already exists`});if(e.label!==void 0&&(!e.label.trim()||/[\r\n]/.test(e.label))){return T({code:"INVALID_OP",message:"Sequence participant label must be a non-empty single line"})}const l=e.label===void 0?sn(e.id):void 0;r.push({id:e.id,label:e.label??l.value,kind:e.participantKind??"participant",...l?.content?{labelContent:l.content}:{}});n.splice(u_(n,r,i,r.slice(0,-1).map(c=>c.id)),0,{kind:"participant",ref:r.length-1});break}case"remove_participant":{const a=r.findIndex(u=>u.id===e.id);if(a<0)return T({code:"PARTICIPANT_NOT_FOUND",message:`Participant "${e.id}" not found`});if(g_(n,e.id)){return T({code:"INVALID_OP",message:`Participant "${e.id}" is referenced by preserved sequence syntax; remove or model that opaque block before removing the participant`})}r.splice(a,1);const l=new Set;i.forEach((u,h)=>{if(u.from===e.id||u.to===e.id)l.add(h)});const c=i.filter((u,h)=>!l.has(h));const d=C_(n,a,l,e.id);return re(o0({kind:"sequence",participants:r,messages:c,statements:d}))}case"add_message":{const a=ud(e);if(a)return T(a);if(e.index!==void 0&&(!Number.isInteger(e.index)||e.index<0||e.index>i.length)){return T({code:"INVALID_OP",message:`Sequence add_message index ${e.index} out of range (0..${i.length})`})}dd(r,e.from);dd(r,e.to);const l=e.index??i.length;i.splice(l,0,{from:e.from,to:e.to,text:Ns(e.text),style:e.style??"sync",...e.wrap===void 0?{}:{wrap:e.wrap}});x_(n,l);break}case"move_message":{if(!Number.isInteger(e.from)||e.from<0||e.from>=i.length){return T({code:"MESSAGE_NOT_FOUND",message:`No message at index ${e.from} (0..${Math.max(i.length-1,0)})`})}if(!Number.isInteger(e.to)||e.to<0||e.to>=i.length){return T({code:"MESSAGE_NOT_FOUND",message:`No target position ${e.to} (0..${Math.max(i.length-1,0)})`})}if(e.from===e.to)break;b_(n,e.from,e.to);const[a]=i.splice(e.from,1);i.splice(e.to,0,a);break}case"set_participant_label":{const a=is(e.id,"declaration");if(a)return T(a);const l=r.find(g=>g.id===e.id);if(!l)return T({code:"PARTICIPANT_NOT_FOUND",message:`Participant "${e.id}" not found`});const c=Al(l.id);if(c)return T({code:"INVALID_OP",message:c});const d=typeof e.label==="string"?e.label.trim():"";if(!d||/[\r\n]/.test(d)){return T({code:"INVALID_OP",message:"Sequence participant label must be a non-empty single line"})}if(/\s/.test(l.id)&&d!==sn(l.id).value)return T({code:"INVALID_OP",message:"Sequence names containing spaces support a bare participant/actor declaration; an alias requires an ID without spaces"});if(l.label!==d||l.labelContent?.value!==l.label)delete l.labelContent;l.label=d;const u=r.indexOf(l);const h=h_(n,u,l.id);if(h?.preserved&&m_(n[h.index],l))break;const m=h===void 0?p_(n,r,i,l.id)+1:h.preserved?h.index+1:void 0;if(m===void 0)break;const f=f_({kind:"sequence",participants:r,messages:i,statements:n.slice(0,m)},l.id);n.splice(m,0,{kind:"participant",ref:u});if(f.length)n.splice(m+1,0,{kind:"opaque-block",lines:f});const p=m0({kind:"sequence",participants:r,messages:i,statements:n},{upstreamLinks:true}).find(g=>g.id===l.id);if(l.links&&JSON.stringify(p?.links??{})!==JSON.stringify(l.links)){n.splice(m+1,0,{kind:"actor-links",actorId:l.id,links:{...l.links}})}break}case"remove_message":{if(e.index<0||e.index>=i.length)return T({code:"MESSAGE_NOT_FOUND",message:`No message at index ${e.index}`});i.splice(e.index,1);y_(n,e.index);break}case"set_message_wrap":{const a=i[e.index];if(!a)return T({code:"MESSAGE_NOT_FOUND",message:`No message at index ${e.index}`});if(e.wrap===null)delete a.wrap;else a.wrap=e.wrap;break}case"set_message_text":{if(e.index<0||e.index>=i.length)return T({code:"MESSAGE_NOT_FOUND",message:`No message at index ${e.index}`});const a=i[e.index];const l=Ns(e.text);if(a.text!==l||a.textContent?.value!==a.text)delete a.textContent;a.text=l;break}case"add_fragment":{const a=cd(e.label);if(!a.ok)return a;const l=ui(n);const c=e.index??l.length;if(!Number.isInteger(c)||c<0||c>l.length)return T({code:"INVALID_OP",message:`Sequence fragment index ${c} out of range (0..${l.length})`});const d={kind:"fragment",fragment:{fragmentKind:e.fragmentKind,...a.value?{label:a.value}:{},branches:[{messages:[]}]}};const u=c<l.length?l[c].position:n.length;n.splice(u,0,d);break}case"remove_fragment":{const a=ui(n)[e.index];if(!a)return T({code:"INVALID_OP",message:`No sequence fragment at index ${e.index}`});n.splice(a.position,1);break}case"set_fragment_label":{const a=ui(n)[e.index];if(!a)return T({code:"INVALID_OP",message:`No sequence fragment at index ${e.index}`});const l=cd(e.label);if(!l.ok)return l;delete a.statement.fragment.rawLines;if(a.statement.fragment.label!==l.value||a.statement.fragment.labelContent?.value!==a.statement.fragment.label)delete a.statement.fragment.labelContent;if(l.value)a.statement.fragment.label=l.value;else delete a.statement.fragment.label;break}case"add_fragment_branch":{const a=ui(n)[e.fragmentIndex];if(!a)return T({code:"INVALID_OP",message:`No sequence fragment at index ${e.fragmentIndex}`});if(!["alt","par","par_over"].includes(a.statement.fragment.fragmentKind))return T({code:"INVALID_OP",message:"Only alt, par and par_over fragments can have multiple branches"});const l=cd(e.label);if(!l.ok)return l;delete a.statement.fragment.rawLines;a.statement.fragment.branches.push({...l.value?{label:l.value}:{},messages:[]});break}case"set_fragment_branch_label":{const a=ui(n)[e.fragmentIndex];if(!a)return T({code:"INVALID_OP",message:`No sequence fragment at index ${e.fragmentIndex}`});const l=Ba(n,e.fragmentIndex,e.branchIndex);if(!l.ok)return l;const c=cd(e.label);if(!c.ok)return c;delete a.statement.fragment.rawLines;if(l.value.label!==c.value||l.value.labelContent?.value!==l.value.label)delete l.value.labelContent;if(e.branchIndex===0){if(a.statement.fragment.label!==c.value||a.statement.fragment.labelContent?.value!==a.statement.fragment.label)delete a.statement.fragment.labelContent;if(c.value)a.statement.fragment.label=c.value;else delete a.statement.fragment.label;delete l.value.label}else{if(c.value)l.value.label=c.value;else delete l.value.label}break}case"add_fragment_message":{const a=ud(e);if(a)return T(a);const l=ui(n)[e.fragmentIndex];if(!l)return T({code:"INVALID_OP",message:`No sequence fragment at index ${e.fragmentIndex}`});const c=Ba(n,e.fragmentIndex,e.branchIndex??0);if(!c.ok)return c;const d=e.index??c.value.messages.length;if(!Number.isInteger(d)||d<0||d>c.value.messages.length)return T({code:"INVALID_OP",message:`Sequence fragment message index ${d} out of range`});dd(r,e.from);dd(r,e.to);delete l.statement.fragment.rawLines;c.value.messages.splice(d,0,{from:e.from,to:e.to,text:Ns(e.text),style:e.style??"sync",...e.wrap===void 0?{}:{wrap:e.wrap}});break}case"remove_fragment_message":{const a=ui(n)[e.fragmentIndex];if(!a)return T({code:"INVALID_OP",message:`No sequence fragment at index ${e.fragmentIndex}`});const l=Ba(n,e.fragmentIndex,e.branchIndex??0);if(!l.ok)return l;if(!l.value.messages[e.index])return T({code:"MESSAGE_NOT_FOUND",message:`No fragment message at index ${e.index}`});delete a.statement.fragment.rawLines;l.value.messages.splice(e.index,1);break}case"set_fragment_message_wrap":{const a=ui(n)[e.fragmentIndex];if(!a)return T({code:"INVALID_OP",message:`No sequence fragment at index ${e.fragmentIndex}`});const l=Ba(n,e.fragmentIndex,e.branchIndex??0);if(!l.ok)return l;const c=l.value.messages[e.index];if(!c)return T({code:"MESSAGE_NOT_FOUND",message:`No fragment message at index ${e.index}`});delete a.statement.fragment.rawLines;if(e.wrap===null)delete c.wrap;else c.wrap=e.wrap;break}case"set_fragment_message_text":{const a=ui(n)[e.fragmentIndex];if(!a)return T({code:"INVALID_OP",message:`No sequence fragment at index ${e.fragmentIndex}`});const l=Ba(n,e.fragmentIndex,e.branchIndex??0);if(!l.ok)return l;const c=l.value.messages[e.index];if(!c)return T({code:"MESSAGE_NOT_FOUND",message:`No fragment message at index ${e.index}`});delete a.statement.fragment.rawLines;const d=Ns(e.text);if(c.text!==d||c.textContent?.value!==c.text)delete c.textContent;c.text=d;break}default:{const a=e;return T({code:"INVALID_OP",message:Ve("sequence",a)})}}const o={kind:"sequence",participants:r,messages:i,statements:n};const s=Km(o);return s?T(s):re(o0(o))}function o0(t){const e=m0(t).map(s0);if(JSON.stringify(e)===JSON.stringify(t.participants))return t;const r=new Map(e.map((i,n)=>[i.id,n]));return{kind:"sequence",participants:e,messages:t.messages,statements:t.statements.map(i=>i.kind==="participant"?{kind:"participant",ref:r.get(t.participants[i.ref].id)}:i)}}function u_(t,e,r,i){const n=new Set(i);const o=new Set;let s=0;t.forEach((a,l)=>{for(const c of Qm(a,e,r)){if(o.has(c))continue;o.add(c);if(n.has(c))s=l+1}});return s}function m0(t,e={}){const r=new Ml(e);for(const i of _s(md(t).split("\n")).slice(1))r.applyAll(hd(i));return r.list()}function h_(t,e,r){const i=n=>hd(n).some(o=>o.kind==="declare"&&o.id===r&&o.label!==void 0&&!o.create);for(let n=t.length-1;n>=0;n--){const o=t[n];if(o.kind==="participant"&&o.ref===e)return{index:n,preserved:false};if(o.kind==="opaque-block"&&o.lines.some(i))return{index:n,preserved:true}}return void 0}function m_(t,e){if(t.kind!=="opaque-block")return false;const r=Rn(t.lines).statements;const i=r.findLast(h=>h.syntax?.kind==="declaration"&&h.syntax.declaration.id===e.id&&h.syntax.declaration.aliased);if(!i||i.syntax?.kind!=="declaration")return false;const n=i.syntax.declaration;const o=`${n.keyword} ${n.id}`;const s=yo(e.label,e.labelContent,e.wrap,`${o} as `);const a=i.raw.trim();const l=a.indexOf("@{");let c;if(l>=0){const h=Rs(a,l+1,"sequence");if(!h.ok)return false;const m=JSON.stringify({...Object.fromEntries(h.entries),alias:Vy(e.label,e.labelContent)}).replace(/"(?:\\.|[^"\\])*"/g,f=>f.replace(/}/g,"\\u007d"));c=`${o}@${m} as ${s}`}else c=`${o} as ${s}`;const d=t.lines[i.line];const u=i.raw.match(/^\s*/)?.[0]??"";t.lines[i.line]=d.slice(0,i.column)+u+c+d.slice(i.endColumn);return true}function f_(t,e){let r=[];for(const i of Rn(md(t).split("\n").slice(1)).statements){const n=i.syntax;if(n?.kind==="declaration"&&n.declaration.id===e&&n.declaration.aliased)r=[];if(n?.kind==="actor-data"&&n.actorId===e)r.push(i.raw)}return r}function p_(t,e,r,i){const n=t.findIndex(o=>Qm(o,e,r).includes(i));return n<0?t.length-1:n}function g_(t,e){const r=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");const i=new RegExp(`(^|[^A-Za-z0-9_])${r}(?=$|[^A-Za-z0-9_])`);const n=o=>hd(o).some(s=>s.id===e);return t.some(o=>o.kind==="opaque-block"&&o.lines.some(s=>!Bs(s)&&(n(s)||i.test(s)))||o.kind==="fragment"&&o.fragment.branches.some(s=>s.messages.some(a=>a.from===e||a.to===e)))}function f0(t){if(t.kind==="opaque-block")return{kind:"opaque-block",lines:[...t.lines]};if(t.kind==="actor-links")return{...t,links:{...t.links}};if(t.kind==="fragment")return{kind:"fragment",fragment:{...t.fragment,branches:t.fragment.branches.map(e=>({...e,messages:e.messages.map(r=>({...r}))}))}};return{...t}}function ui(t){const e=[];t.forEach((r,i)=>{if(r.kind==="fragment")e.push({position:i,statement:r})});return e}function cd(t){if(t===null||t===void 0)return re(void 0);if(typeof t!=="string"||!t.trim()||/[\r\n]/.test(t))return T({code:"INVALID_OP",message:"Sequence fragment label must be a non-empty single line or null"});return re(t.trim())}function Ba(t,e,r){const i=ui(t)[e];if(!i)return T({code:"INVALID_OP",message:`No sequence fragment at index ${e}`});const n=i.statement.fragment.branches[r];return n?re(n):T({code:"INVALID_OP",message:`No branch ${r} in sequence fragment ${e}`})}function dd(t,e){if(t.some(r=>r.id===e))return;t.push({id:e,label:e,kind:"participant"})}function y_(t,e){const r=t.findIndex(i=>i.kind==="message"&&i.ref===e);if(r>=0)t.splice(r,1);for(const i of t)if(i.kind==="message"&&i.ref>e)i.ref--}function x_(t,e){const r=t.findIndex(i=>i.kind==="message"&&i.ref===e);for(const i of t)if(i.kind==="message"&&i.ref>=e)i.ref++;if(r>=0)t.splice(r,0,{kind:"message",ref:e});else t.push({kind:"message",ref:e})}function b_(t,e,r){const i=t.findIndex(a=>a.kind==="message"&&a.ref===e);if(i<0)return;t.splice(i,1);const n=[];t.forEach((a,l)=>{if(a.kind==="message")n.push(l)});const o=r<n.length?n[r]:n.length>0?n[n.length-1]+1:t.length;t.splice(o,0,{kind:"message",ref:-1});let s=0;for(const a of t)if(a.kind==="message")a.ref=s++}function C_(t,e,r,i){const n=[];for(const o of t){if(o.kind==="opaque-block"){n.push({kind:"opaque-block",lines:[...o.lines]});continue}if(o.kind==="fragment"){n.push(f0(o));continue}if(o.kind==="participant"){if(o.ref===e)continue;n.push({kind:"participant",ref:o.ref>e?o.ref-1:o.ref});continue}if(o.kind==="actor-links"){if(o.actorId!==i)n.push({...o,links:{...o.links}});continue}if(r.has(o.ref))continue;let s=0;for(const a of r)if(a<o.ref)s++;n.push({kind:"message",ref:o.ref-s})}return n}function bd(t,e,r){Object.defineProperty(t,e,{value:r,enumerable:true,writable:true,configurable:true})}var Zn="[*]";function Cd(t){return qn(t)}function p0(t){return t===Zn||zn(t)||qn(t)}function fd(t){return{states:[],transitions:[],byId:t}}function pn(t,e){let r=t.byId.get(e);if(!r){r={id:e};t.states.push(r);t.byId.set(e,r)}return r}function w0(t){const{statements:e}=Lo(En(t));let r;try{r=wh(e)}catch($){if($ instanceof Ln)return null;throw $}if(r.issue)return null;const i=new Map;const n=fd(i);const o=[n];const s=new Set;for(const $ of e){if($.noteBody)continue;const D=$.text.match(Oi);if(!D)continue;const P=D[2];if(s.has(P))return null;s.add(P)}const a=new Map;const l=new Map;const c=[];const d={};const u={};const h=[];const m=[];const f=[];const p=[];const g=[];const y=[];const C=new Set;let w=null;const x=new Map;const k=($,D)=>{x.set($,D);const{text:P,content:U}=Tb(D);$.label=P;if(U)$.labelContent=U;else delete $.labelContent};const b=new Map;const A=($,D)=>{let P=b.get(D);if(!P){P=new Map;b.set(D,P)}if(!P.has($))P.set($,$.transitions.length)};const L=($,D,P,U)=>{const{text:j,content:G}=ac(U);g.push({target:D,side:P,text:j,...G?{textContent:G}:{}});if(!s.has(D)&&!$.byId.has(D)){const se=pn($,D);se.declaredBare=true;A($,se)}};for(const $ of e){const D=$.text;const P=o[o.length-1];if(w){if(bh(D)){L(P,w.target,w.side,w.lines.join("\n"));w=null}else{w.lines.push(D)}continue}if(!D)continue;const U=Hs(D);if(U){if(C.has(U.id))return null;C.add(U.id);const{text:de,content:xe}=ac(U.text);if(!wd(de).ok)return null;const we=r.scopeOf($);y.push({id:U.id,text:de,...xe?{textContent:xe}:{},...we?{scope:we}:{}});continue}const j=uc(D);if(j){L(P,j.target,j.side,j.text);continue}const G=hc(D);if(G){w={target:G.target,side:G.side,lines:[]};continue}const se=D.match(Ch);if(se){const de=Bn(Zu(se[2]));const xe=_r(_n(de),de);if(!xe||Object.keys(xe).length===0)return null;for(const we of se[1].split(",").map(Be=>Be.trim()).filter(Boolean)){const Be=Bn([...nn(u,we)??Object.entries(d[we]??{}),...de]);bd(d,we,_n(Be));const Ie=ii(Be);if(Ie)bd(u,we,Ie)}continue}const ce=xh(D);if(ce){for(const de of ce.ids){h.push({id:de,className:ce.className,scope:P})}continue}const ae=D.match(kh);if(ae){const de=Bn(Zu(ae[2]));const xe=_r(_n(de),de);if(!xe||Object.keys(xe).length===0)return null;for(const we of ae[1].split(",").map(Be=>Be.trim()).filter(Boolean)){if(!to(we))return null;m.push({id:we,props:{...xe},declarations:de,scope:P})}continue}const Y=D.match(Bb);if(Y){const de=Ti(Y[2]);if(Object.keys(de).length===0)return null;const xe=Y[1].trim()==="default"?"default":Y[1].split(",").map(we=>Number.parseInt(we.trim(),10)).filter(Number.isInteger);f.push({target:xe,props:de});continue}if(Xs(D)){if(c.length===0)return null;const de=c[c.length-1];if(!de.regions){if(P.direction!==void 0){de.node.direction=P.direction;delete P.direction}const xe=fd(i);de.regions=[P,xe];o[o.length-1]=xe}else{const xe=fd(i);de.regions.push(xe);o[o.length-1]=xe}continue}const V=D.match(Ob);if(V){P.direction=V[1].toUpperCase();continue}const N=mc(D);if(N){if(!Cd(N.id)||s.has(N.id)&&!P.byId.has(N.id))return null;const de=pn(P,N.id);A(P,de);de.stereotype=N.stereotype;if(N.label!==void 0&&de.label===void 0)k(de,[N.label]);continue}const J=D.match(Oi);if(J){const de=J[2];if(!Cd(de))return null;const xe=J[1]!==void 0?[J[1]]:a.get(de);const we=fd(i);const Be=i.get(de);const Ie=Be??{id:de};A(P,Ie);Ie.states=we.states;Ie.transitions=we.transitions;if(xe!==void 0)k(Ie,xe);if(!Be)P.states.push(Ie);P.byId.set(de,Ie);l.set(de,Ie);c.push({parent:P,node:Ie});o.push(we);continue}if(D==="}"){if(o.length<=1)continue;const de=o.pop();const xe=c.pop();if(xe.regions){xe.node.regions=xe.regions.map(we=>({states:we.states,transitions:we.transitions,...we.direction!==void 0?{direction:we.direction}:{}}));delete xe.node.states;delete xe.node.transitions}else{xe.node.states=de.states;xe.node.transitions=de.transitions;if(de.direction!==void 0)xe.node.direction=de.direction}continue}const ee=D.match(_o);if(ee){const de=ee[2];const xe=[ee[1]];const we=l.get(de);if(we){if(we.label===void 0)k(we,xe)}else if(s.has(de)){if(!a.has(de))a.set(de,xe)}else{const Be=pn(P,de);A(P,Be);if(Be.label===void 0)k(Be,xe)}continue}const X=Bo(D);if(X){const{from:de,to:xe}=X;const we=X.label?ac(X.label):void 0;if(!p0(de)||!p0(xe))return null;const Be=Me=>Me===Zn||zn(Me);if(Be(de)&&X.fromClass?.includes("-")||Be(xe)&&X.toClass?.includes("-"))return null;if(X.fromClass&&!Be(de))h.push({id:de,className:X.fromClass,scope:P});if(X.toClass&&!Be(xe))h.push({id:xe,className:X.toClass,scope:P});if(!Be(de)&&!s.has(de))pn(P,de);if(!Be(xe)&&!s.has(xe))pn(P,xe);const Ie={from:de,to:xe,...X.fromClass&&Be(de)?{fromClass:X.fromClass}:{},...X.toClass&&Be(xe)?{toClass:X.toClass}:{},...we!==void 0?{label:we.text,...we.content?{labelContent:we.content}:{}}:{}};P.transitions.push(Ie);p.push(Ie);continue}const ie=lc(D);if(ie){if(!s.has(ie.id)){const de=pn(P,ie.id);A(P,de);de.declaredBare=true}h.push({id:ie.id,className:ie.className,scope:P});continue}const ge=D.match(Io);if(ge){const de=ge[1];const xe=ge[2].trim();if(s.has(de)&&!l.has(de)){a.set(de,[...a.get(de)??[],xe])}else{const we=l.get(de)??pn(P,de);A(P,we);k(we,[...x.get(we)??[],xe])}continue}const fe=cc(D);if(fe!==null){if(s.has(fe))continue;const de=pn(P,fe);A(P,de);de.declaredBare=true;continue}return null}if(o.length!==1)return null;if(w)return null;if(!k_(n.states,i,r))return null;const B=[];const O=[];for(const{id:$,className:D}of h){const P=i.get($);if(!P){B.push({id:$,className:D});continue}P.className=P.className===void 0?D:`${P.className} ${D}`}for(const{id:$,props:D,declarations:P}of m){const U=i.get($);const j=ii(P);if(!U){O.push({id:$,style:{...D},...j?{styleDeclarations:j}:{}});continue}U.style={...D};if(j)U.styleDeclarations=j;else delete U.styleDeclarations}let M;for(const $ of f){if($.target==="default")M={...M,...$.props};else for(const D of $.target){const P=p[D];if(P)P.style={...P.style,...$.props}}}const E=$=>{for(const D of $){if(D.regions)for(const P of D.regions)E(P.states);else if(D.states)E(D.states);else if(D.stereotype===void 0&&D.label===D.id&&!ns(D.id)){delete D.label;delete D.labelContent;D.declaredBare=true}}};E(n.states);const _=$=>{for(const D of $.states){const P=b.get(D)?.get($);if(P!==void 0)D.declarationBeforeTransition=P}};const q=new Set([n]);for(const $ of b.values())for(const D of $.keys())q.add(D);for(const $ of q)_($);Td(n.states,n.transitions);const Q={kind:"state",states:n.states,transitions:n.transitions,...g.length>0?{notes:g}:{},...y.length>0?{floatingNotes:y}:{},...n.direction!==void 0?{direction:n.direction}:{},...Object.keys(d).length>0?{classDefs:d}:{},...Object.keys(u).length>0?{classDefDeclarations:u}:{},...M?{defaultTransitionStyle:M}:{},...B.length>0?{unresolvedClasses:B}:{},...O.length>0?{unresolvedStyles:O}:{}};if(Sd(Q))return null;M0(Q);try{Ia(Q)}catch($){if($ instanceof eo)return null;throw $}return Q}function k_(t,e,r){const i=new Map;for(const n of e.values()){if(n.regions)n.regions.forEach((o,s)=>i.set(r.regionId(n.id,s),o.states));else if(n.states)i.set(n.id,n.states)}t.length=0;for(const n of i.values())n.length=0;for(const n of e.values())if(!r.ownerOf(n.id))t.push(n);for(const n of r.ownedIds()){const o=e.get(n);const s=r.ownerOf(n);if(!o||!s)continue;const a=i.get(r.scopeId(s));if(!a)return false;a.push(o)}return true}function ns(t){return!/-|^(?:state|note|scale|default|classDef|class|style|click|href|stateDiagram)$/i.test(t)}function T0(t){return/^(?:state|note|scale|classDef|class|style|stateDiagram|accTitle|accDescr)$/i.test(t)}function ef(t){return(t.label?.includes('"')??false)&&ns(t.id)}function pd(t,e,r){return t+vb(e,r,t)}function gd(t,e,r=""){const i=gh(t,e,r).replace(/\r\n?|\n/g,"<br/>");return yh(i.replace(/<<(?:fork|join|choice)>>|\[\[(?:fork|join|choice)\]\]/gi,n=>n.replace(/[<>\[\]]/g,o=>`#${o.charCodeAt(0)};`)))}function Dr(t){return Nr(t)||t.stereotype!==void 0||t.label!==void 0||t.declaredBare===true}function g0(t,e){const r=new Map(t.map(l=>[l.id,l]));const i=new Map(t.map((l,c)=>[l,c]));const n=new Set;const o=[];let s=0;const a=(l,c)=>{for(const d=i.get(l);s<d;s++){const u=t[s];if(n.has(u)||c.has(u)||!Dr(u))continue;o.push({state:u});n.add(u)}};for(const l of e){const c=new Set;for(const m of[l.from,l.to]){const f=r.get(m);if(f&&!n.has(f)&&!Nr(f))c.add(f)}const d=[];const u=[];let h=false;for(const m of[...c].sort((f,p)=>i.get(f)-i.get(p))){if(m.stereotype!==void 0||Dr(m)&&!h)d.push(m);else{u.push(m);h||=!Dr(m)}}for(const m of d){a(m,c);o.push({state:m});n.add(m)}if(u.length>0)a(u.at(-1),c);o.push({transition:l});for(const m of[...c].filter(f=>u.includes(f))){n.add(m);if(Dr(m))o.push({state:m})}}for(const l of t){if(n.has(l))continue;if(Dr(l))o.push({state:l});n.add(l)}return{steps:o,created:[...n]}}function v0(t,e){if(!t.some(c=>c.declarationBeforeTransition!==void 0))return g0(t,e);const r=new Map;let i=0;for(const c of g0(t,e).steps){if("transition"in c)i++;else r.set(c.state,i)}const n=new Map;const o=new Map(t.map(c=>[c.id,c]));const s=new Map;e.forEach((c,d)=>{for(const u of[c.from,c.to])if(!s.has(u))s.set(u,d)});for(const c of t){if(!Dr(c))continue;let d=c.declarationBeforeTransition??r.get(c)??e.length;if(c.stereotype!==void 0){const h=s.get(c.id);if(h!==void 0)d=Math.min(d,h)}const u=n.get(d)??[];u.push(c);n.set(d,u)}const a=[],l=new Set;for(let c=0;c<=e.length;c++){for(const u of n.get(c)??[]){a.push({state:u});l.add(u)}const d=e[c];if(!d)continue;a.push({transition:d});for(const u of[d.from,d.to]){const h=o.get(u);if(h&&!Nr(h))l.add(h)}}for(const c of t)l.add(c);return{steps:a,created:[...l]}}function tf(t,e,r,i,n,o,s){if(r!==void 0)n.push(`${i}direction ${r}`);for(const a of v0(t,e).steps){if("transition"in a){const c=a.transition;const d=(f,p)=>p===void 0&&T0(f);const u=(f,p)=>p===void 0?f:`${f}:::${p}`;const h=d(c.to,c.toClass);const m=`${i}${u(c.from,c.fromClass)}${d(c.from,c.fromClass)?"":" "}--> ${u(c.to,c.toClass)}`;n.push(c.label!==void 0?pd(`${m}${h?":":" :"} `,c.label,c.labelContent):h?`${m}%%`:m);continue}const l=a.state;if(Nr(l)){const c=ef(l);if(c)n.push(pd(`${i}${l.id}: `,l.label,l.labelContent));const d=l.label!==void 0&&!c?`state "${gd(l.label,l.labelContent,'"')}" as ${l.id} {`:`state ${l.id} {`;n.push(`${i}${d}`);if(l.regions){if(l.direction!==void 0)n.push(`${i} direction ${l.direction}`);l.regions.forEach((u,h)=>{tf(u.states,u.transitions,u.direction,i+" ",n,o,{parent:l.id,region:h});if(h<l.regions.length-1)n.push(`${i} --`)})}else{tf(l.states??[],l.transitions??[],l.direction,i+" ",n,o,{parent:l.id})}n.push(`${i}}`)}else if(l.stereotype!==void 0){const c=ef(l);const d=l.label!==void 0&&!c?`"${gd(l.label,l.labelContent,'"')}" as `:"";n.push(`${i}state ${d}${l.id} ${Ab(l.stereotype)}`);if(c)n.push(pd(`${i}${l.id}: `,l.label,l.labelContent))}else if(l.label!==void 0){n.push(Cd(l.id)&&!ef(l)?`${i}state "${gd(l.label,l.labelContent,'"')}" as ${l.id}`:pd(`${i}${l.id}: `,l.label,l.labelContent))}else if(l.declaredBare){n.push(`${i}${ns(l.id)?l.id+(/^as$/i.test(l.id)?"%%":""):`state "${l.id}" as ${l.id}`}`)}}for(const a of o.get(kd(s))??[]){n.push(`${i}note "${gd(a.text,a.textContent,'"')}" as ${a.id}`)}}function kd(t){return JSON.stringify([t?.parent??null,t?.region??0])}function Ia(t){const e=Sd(t);if(e)throw new Error(e);const r=new Set;const i=new Map;for(const c of t.floatingNotes??[]){if(!qn(c.id)||r.has(c.id))throw new Error(`Invalid or duplicate floating State note identity "${c.id}"`);r.add(c.id);const d=wd(c.text);if(!d.ok)throw new Error(`Floating State note "${c.id}": ${d.error.message}`);if(c.scope){const m=Jt(t,c.scope.parent)?.node;if(!m||!Nr(m)||(m.regions?!Number.isInteger(c.scope.region??0)||!m.regions[c.scope.region??0]:c.scope.region!==void 0)){throw new Error(`Invalid scope for floating State note "${c.id}"`)}}const u=kd(c.scope);const h=i.get(u)??[];h.push(c);i.set(u,h)}const n=["stateDiagram-v2"];tf(t.states,t.transitions,t.direction," ",n,i);for(const c of t.notes??[]){const d=gh(c.text,c.textContent);if(!d.trim()||/[\n:;]/.test(c.text)){n.push(` note ${c.side} of ${c.target}`);for(const u of d.replace(/^(\s*):/,"$1#58;").split("\n")){const h=u.replace(/^(\s*)(e)(?=nd note)/i,(m,f,p)=>`${f}#${p.charCodeAt(0)};`);n.push(` ${yh(h)}`)}n.push(" end note")}else{n.push(` note ${c.side} of ${c.target} : ${d}`)}}for(const[c,d]of Object.entries(t.classDefs??{}))n.push(Mo(` classDef ${c} `,d,void 0,nn(t.classDefDeclarations,c)));const o=[];const s=[];const a=(c,d)=>{for(const u of c){o.push(u);if(u.regions)for(const h of u.regions)a(h.states,h.transitions);else if(u.states)a(u.states,u.transitions??[])}s.push(...d)};a(t.states,t.transitions);for(const c of o){for(const d of Js(c.className))n.push(y0(c.id,d));if(c.style)n.push(Mo(` style ${c.id} `,c.style,void 0,c.styleDeclarations))}for(const{id:c,className:d}of t.unresolvedClasses??[])n.push(y0(c,d));for(const{id:c,style:d,styleDeclarations:u}of t.unresolvedStyles??[])n.push(Mo(` style ${c} `,d,void 0,u));if(t.defaultTransitionStyle)n.push(` linkStyle default ${on(t.defaultTransitionStyle)}`);s.forEach((c,d)=>{if(c.style)n.push(` linkStyle ${d} ${on(c.style)}`)});const l=n.join("\n")+"\n";S_(t,l);return l}var eo=class extends Error{};function y0(t,e){if(!to(t))throw new eo(`State class target "${t}" needs letters, digits or underscore for portable export`);return` class ${t} ${e}`}function S_(t,e){const{statements:r}=Lo(En(e.split("\n")));const i=wh(r);if(i.issue)throw new eo(i.issue);const n=(o,s)=>{for(const a of o){const l=i.ownerOf(a.id);if(!i.authored.has(a.id)||kd(l)!==kd(s)){throw new eo(`State '${a.id}' cannot retain its requested scope in Mermaid source. Move or remove transitions that claim it in another scope before changing its ownership.`)}if(a.regions)a.regions.forEach((c,d)=>n(c.states,{parent:a.id,region:d}));else if(a.states)n(a.states,{parent:a.id})}};n(t.states)}var to=t=>/^\w+$/.test(t);var af=t=>/^\w+$/.test(t)&&!/^default$/i.test(t);function Sd(t){const e=Object.keys(t.classDefs??{}).find(a=>!af(a));if(e!==void 0)return`State class definition name "${e}" cannot be written in pinned Mermaid; definition names must contain only letters, digits, or underscore and cannot be default`;const r=t.transitions.find(a=>a.label!==void 0&&/^acc(?:Title|Descr)$/i.test(a.to))?.to;let i=t.unresolvedStyles?.find(a=>!to(a.id))?.id;let n=false;let o=Object.keys(t.classDefDeclarations??{}).some(a=>!Object.hasOwn(t.classDefs??{},a))||Object.entries(t.classDefs??{}).some(([a,l])=>!_r(l,nn(t.classDefDeclarations,a)))||t.unresolvedStyles?.some(a=>!_r(a.style,a.styleDeclarations));const s=(a,l)=>{for(const c of a){if(c.declarationBeforeTransition!==void 0&&(!Number.isInteger(c.declarationBeforeTransition)||c.declarationBeforeTransition<0||c.declarationBeforeTransition>l.length))n=true;if(c.style&&!to(c.id))i??=c.id;if(c.styleDeclarations&&!c.style||c.style&&!_r(c.style,c.styleDeclarations))o=true;if(c.regions)for(const d of c.regions)s(d.states,d.transitions);else if(c.states)s(c.states,c.transitions??[])}};s(t.states,t.transitions);if(n)return"State declaration boundary must be an integer within its owning transition sequence";if(o)return"State style contains text outside the supported SVG attribute domain";if(r!==void 0)return`A top-level labeled State transition to "${r}" cannot be written in pinned Mermaid because the destination and colon start an accessibility directive; rename the destination or remove the label for typed editing`;return i===void 0?void 0:`State style target "${i}" cannot be written in pinned Mermaid; style targets must contain only letters, digits, or underscore`}function o3(t){return ai(Ia(t))}function rf(t){return{...t,...t.style?{style:{...t.style}}:{}}}function nf(t){return{id:t.id,...t.label!==void 0?{label:t.label}:{},...t.labelContent!==void 0?{labelContent:t.labelContent}:{},...t.declaredBare?{declaredBare:true}:{},...t.declarationBeforeTransition!==void 0?{declarationBeforeTransition:t.declarationBeforeTransition}:{},...t.stereotype!==void 0?{stereotype:t.stereotype}:{},...t.className!==void 0?{className:t.className}:{},...t.style!==void 0?{style:{...t.style}}:{},...t.styleDeclarations?{styleDeclarations:structuredClone(t.styleDeclarations)}:{},...t.direction!==void 0?{direction:t.direction}:{},...t.states!==void 0?{states:t.states.map(nf)}:{},...t.transitions!==void 0?{transitions:t.transitions.map(rf)}:{},...t.regions!==void 0?{regions:t.regions.map(e=>({states:e.states.map(nf),transitions:e.transitions.map(rf),...e.direction!==void 0?{direction:e.direction}:{}}))}:{}}}function w_(t){return{kind:"state",states:t.states.map(nf),transitions:t.transitions.map(rf),...t.notes!==void 0?{notes:t.notes.map(e=>({...e}))}:{},...t.floatingNotes?{floatingNotes:t.floatingNotes.map(e=>({...e,...e.scope?{scope:{...e.scope}}:{}}))}:{},...t.direction!==void 0?{direction:t.direction}:{},...t.classDefs!==void 0?{classDefs:Object.fromEntries(Object.entries(t.classDefs).map(([e,r])=>[e,{...r}]))}:{},...t.classDefDeclarations?{classDefDeclarations:structuredClone(t.classDefDeclarations)}:{},...t.defaultTransitionStyle!==void 0?{defaultTransitionStyle:{...t.defaultTransitionStyle}}:{},...t.unresolvedClasses?{unresolvedClasses:t.unresolvedClasses.map(e=>({...e}))}:{},...t.unresolvedStyles?{unresolvedStyles:t.unresolvedStyles.map(e=>({...e,style:{...e.style},...e.styleDeclarations?{styleDeclarations:structuredClone(e.styleDeclarations)}:{}}))}:{}}}function Jt(t,e){const r=(i,n,o)=>{for(const s of i){if(s.id===e)return{node:s,siblings:i,transitions:n,...o?{scope:o}:{}};if(s.regions){for(const[a,l]of s.regions.entries()){const c=r(l.states,l.transitions,{parent:s.id,region:a});if(c)return c}}else if(s.states!==void 0){const a=r(s.states,s.transitions??[],{parent:s.id});if(a)return a}}return null};return r(t.states,t.transitions)}function zi(t,e){for(const r of t){e.add(r.id);if(r.regions)for(const i of r.regions)zi(i.states,e);else if(r.states!==void 0)zi(r.states,e)}}function _a(t,e){if(typeof t!=="string")return T({code:"INVALID_OP",message:`State ${e} must be a string`});const r=Ot(t).trim();if(r.length===0)return T({code:"INVALID_OP",message:`State ${e} must be non-empty`});if(r.includes('"'))return T({code:"INVALID_OP",message:`State ${e} must not contain a double quote`});return re(r)}function yd(t,e){if(typeof t!=="string")return T({code:"INVALID_OP",message:`State ${e} must be a string`});if(!Cd(t)){return T({code:"INVALID_OP",message:`State ${e} must be an identifier (letters, digits, underscore \u2014 no spaces, hyphens, or punctuation)`})}return re(t)}function x0(t,e){if(t===Zn)return re({value:Zn,kind:"pseudo"});if(typeof t==="string"&&zn(t))return re({value:t,kind:"history"});if(typeof t!=="string"||!qn(t)){return T({code:"INVALID_OP",message:`State ${e} must be a state id, [*], [H], [H*], or a qualified history endpoint`})}return re({value:t,kind:"state"})}function b0(t,e,r){if(e.kind!=="history")return re(true);const i=Mb(e.value);const n=i.base||r;if(!n)return T({code:"INVALID_OP",message:`Bare history endpoint '${e.value}' requires a composite parent scope`});const o=Jt(t,n);if(!o)return T({code:"STATE_NOT_FOUND",message:`History endpoint '${e.value}' references missing composite '${n}'`});if(!Nr(o.node))return T({code:"INVALID_OP",message:`History endpoint '${e.value}' requires '${n}' to be a composite state`});return re(true)}function C0(t){if(typeof t!=="string")return T({code:"INVALID_OP",message:"Note text must be a string"});const e=Ot(t).split("\n").map(r=>r.trim()).filter(r=>r.length>0);if(e.length===0)return T({code:"INVALID_OP",message:"Note text must be non-empty"});if(e.some(r=>/^end\s+note$/i.test(r))){return T({code:"INVALID_OP",message:'Note text must not contain an "end note" line (it would terminate the serialized note block)'})}return re(e.join("\n"))}function wd(t){if(typeof t!=="string"||/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/.test(t)){return T({code:"INVALID_OP",message:"Floating note text must be a string without control characters"})}if(t.length===0)return T({code:"INVALID_OP",message:"Floating note text must be non-empty; use remove_floating_note to remove the annotation"});return re(Ot(t).replace(/\r\n?/g,"\n"))}function T_(t){if(t===void 0||t===null)return re("right");if(t==="left"||t==="right")return re(t);return T({code:"INVALID_OP",message:`Note side must be "left" or "right", got ${JSON.stringify(t)}`})}function Nr(t){return t.states!==void 0||t.transitions!==void 0||t.regions!==void 0}function xd(t,e,r=true){const i=zt(t);if(!i.ok){const o=i.reason==="NOT_STRING"?`${e} must be a CSS-like style string`:i.reason==="MULTILINE"?`${e} must be a single-line CSS-like style string`:i.reason==="UNSAFE_PAINT"?ni(e,i.paint).message:`${e} must contain at least one property:value pair`;return T({code:"INVALID_OP",message:o})}const n=r?_r(i.value,In(t)):i.value;return n?re(n):T({code:"INVALID_OP",message:`${e} contains text outside the supported SVG attribute domain`})}function E0(t,e){const r=Sd(t);if(r)return T({code:"INVALID_OP",message:r});const i=w_(t);switch(e.kind){case"add_state":{const o=yd(e.id,"state id");if(!o.ok)return o;const s=new Set;zi(i.states,s);if(s.has(o.value))return T({code:"DUPLICATE_STATE",message:`State '${o.value}' already exists`});let a;if(e.label!==void 0&&e.label!==null){const c=_a(e.label,"label");if(!c.ok)return c;a=c.value}const l={id:o.value,...a!==void 0?{label:a}:{declaredBare:true}};if(e.parent!==void 0&&e.parent!==null){const c=Qn(i,e.parent,e.region);if(!c.ok)return c;l.declarationBeforeTransition=c.value.transitions.length;c.value.states.push(l)}else{if(e.region!==void 0)return T({code:"INVALID_OP",message:"add_state.region requires a composite parent"});l.declarationBeforeTransition=i.transitions.length;i.states.push(l)}break}case"remove_state":{const o=Jt(i,e.id);if(!o)return T({code:"STATE_NOT_FOUND",message:`State '${e.id}' not found`});const s=Nr(o.node)&&(of(o.node).some(c=>c.states.length>0||c.transitions.length>0)||(i.floatingNotes??[]).some(c=>c.scope?.parent===e.id));if(s&&e.recursive!==true){return T({code:"INVALID_OP",message:`Refusing to remove non-empty composite '${e.id}'; remove its children first, or pass recursive: true to remove the whole subtree`})}const a=new Set;zi([o.node],a);const l=o.siblings.indexOf(o.node);o.siblings.splice(l,1);v_(i,a);if(i.notes){i.notes=i.notes.filter(c=>!a.has(c.target));if(i.notes.length===0)delete i.notes}if(i.floatingNotes){i.floatingNotes=i.floatingNotes.filter(c=>!c.scope||!a.has(c.scope.parent));if(!i.floatingNotes.length)delete i.floatingNotes}break}case"rename_state":{const o=yd(e.to,"rename target");if(!o.ok)return o;const s=Jt(i,e.from);if(!s)return T({code:"STATE_NOT_FOUND",message:`State '${e.from}' not found`});const a=new Set;zi(i.states,a);if(a.has(o.value))return T({code:"DUPLICATE_STATE",message:`State '${o.value}' already exists`});s.node.id=o.value;M_(i,e.from,o.value);for(const l of i.notes??[]){if(l.target===e.from)l.target=o.value}for(const l of i.floatingNotes??[])if(l.scope?.parent===e.from)l.scope.parent=o.value;break}case"set_state_label":{const o=Jt(i,e.id);if(!o)return T({code:"STATE_NOT_FOUND",message:`State '${e.id}' not found`});if(!Dr(o.node)){const a=o.transitions.findIndex(l=>l.from===o.node.id||l.to===o.node.id);o.node.declarationBeforeTransition=a<0?o.transitions.length:a+1}delete o.node.labelContent;if(e.label===null){delete o.node.label;o.node.declaredBare=true;break}const s=_a(e.label,"label");if(!s.ok)return s;o.node.label=s.value;delete o.node.declaredBare;break}case"add_transition":{const o=x0(e.from,"transition from");if(!o.ok)return o;const s=x0(e.to,"transition to");if(!s.ok)return s;const a=b0(i,o.value,e.parent);if(!a.ok)return a;const l=b0(i,s.value,e.parent);if(!l.ok)return l;const c=Qn(i,e.parent,e.region);if(!c.ok)return c;const d=c.value;let u;if(e.label!==void 0&&e.label!==null){const h=_a(e.label,"transition label");if(!h.ok)return h;u=h.value}if(o.value.kind==="state")k0(i,d,o.value.value);if(s.value.kind==="state")k0(i,d,s.value.value);d.transitions.push({from:o.value.value,to:s.value.value,...u!==void 0?{label:u}:{}});break}case"remove_transition":{const o=Qn(i,e.parent,e.region);if(!o.ok)return o;const s=o.value.transitions;if(e.index!==void 0){if(!s[e.index])return T({code:"TRANSITION_NOT_FOUND",message:`No transition at index ${e.index}`});sf(o.value.states,s,(a,l)=>l===e.index);break}if(e.from!==void 0&&e.to!==void 0){const a=s.findIndex(l=>l.from===e.from&&l.to===e.to);if(a<0)return T({code:"TRANSITION_NOT_FOUND",message:`No transition ${e.from} --> ${e.to}`});sf(o.value.states,s,(l,c)=>c===a);break}return T({code:"INVALID_OP",message:"remove_transition needs an index or a from/to pair"})}case"set_transition_label":{const o=Qn(i,e.parent,e.region);if(!o.ok)return o;const s=o.value.transitions;let a;if(e.index!==void 0)a=s[e.index];else if(e.from!==void 0&&e.to!==void 0)a=s.find(c=>c.from===e.from&&c.to===e.to);if(!a)return T({code:"TRANSITION_NOT_FOUND",message:"transition not found (need a valid index or from/to pair)"});delete a.labelContent;if(e.label===null){delete a.label;break}const l=_a(e.label,"transition label");if(!l.ok)return l;a.label=l.value;break}case"set_direction":{if(e.state===void 0||e.state===null){i.direction=e.direction;break}const o=Jt(i,e.state);if(!o)return T({code:"STATE_NOT_FOUND",message:`State '${e.state}' not found`});if(!Nr(o.node)){return T({code:"INVALID_OP",message:`'${e.state}' is a simple state \u2014 direction applies to the diagram (omit "state") or to a composite`})}o.node.direction=e.direction;break}case"move_state":{const o=Jt(i,e.id);if(!o)return T({code:"STATE_NOT_FOUND",message:`State '${e.id}' not found`});if(e.parent!==null){if(e.parent===e.id)return T({code:"INVALID_OP",message:`Cannot move state '${e.id}' into itself`});const s=new Set;zi([o.node],s);if(s.has(e.parent)){return T({code:"INVALID_OP",message:`Cannot move '${e.id}' into '${e.parent}' \u2014 it is a descendant of '${e.id}'`})}const a=Qn(i,e.parent,e.region);if(!a.ok)return a;o.siblings.splice(o.siblings.indexOf(o.node),1);if(!Dr(o.node))o.node.declaredBare=true;o.node.declarationBeforeTransition=a.value.transitions.length;a.value.states.push(o.node)}else{if(e.region!==void 0)return T({code:"INVALID_OP",message:"move_state.region requires a composite parent"});if(o.siblings===i.states)break;o.siblings.splice(o.siblings.indexOf(o.node),1);if(!Dr(o.node))o.node.declaredBare=true;o.node.declarationBeforeTransition=i.transitions.length;i.states.push(o.node)}break}case"dissolve_composite":{const o=Jt(i,e.id);if(!o)return T({code:"STATE_NOT_FOUND",message:`State '${e.id}' not found`});if(!Nr(o.node)){return T({code:"INVALID_OP",message:`'${e.id}' is not a composite \u2014 dissolve_composite hoists a composite's children into its parent scope`})}const s=E_(i,e.id);if(s>0){return T({code:"INVALID_OP",message:`${s} transition(s) still reference composite '${e.id}'; remove or retarget them first (remove_transition / add_transition), then dissolve`})}if((i.notes??[]).some(h=>h.target===e.id)){return T({code:"INVALID_OP",message:`A note is anchored to composite '${e.id}'; remove it first (remove_note), then dissolve`})}const a=o.siblings.indexOf(o.node);const l=of(o.node);const c=o.node.declarationBeforeTransition??o.transitions.length;const d=l.reduce((h,m)=>h+m.transitions.length,0);for(const[h,m]of o.siblings.entries())if(m.declarationBeforeTransition!==void 0&&(m.declarationBeforeTransition>c||m.declarationBeforeTransition===c&&h>a))m.declarationBeforeTransition+=d;o.siblings.splice(a,1,...l.flatMap(h=>h.states));let u=c;for(const h of l){for(const m of h.states)if(Dr(m))m.declarationBeforeTransition=u+(m.declarationBeforeTransition??h.transitions.length);u+=h.transitions.length}o.transitions.splice(c,0,...l.flatMap(h=>h.transitions));for(const h of i.floatingNotes??[])if(h.scope?.parent===e.id){if(o.scope)h.scope={...o.scope};else delete h.scope}break}case"add_floating_note":{const o=yd(e.id,"floating note id");if(!o.ok)return o;if(i.floatingNotes?.some(d=>d.id===o.value))return T({code:"INVALID_OP",message:`Floating note '${o.value}' already exists`});const s=wd(e.text);if(!s.ok)return s;const a=Qn(i,e.parent,e.region);if(!a.ok)return a;const l=e.parent?Jt(i,e.parent).node:void 0;const c={id:o.value,text:s.value,...e.parent?{scope:{parent:e.parent,...l?.regions?{region:e.region??0}:{}}}:{}};if(!i.floatingNotes)i.floatingNotes=[];i.floatingNotes.push(c);break}case"remove_floating_note":{const o=i.floatingNotes?.findIndex(s=>s.id===e.id)??-1;if(o<0)return T({code:"NOTE_NOT_FOUND",message:`Floating note '${e.id}' not found`});i.floatingNotes.splice(o,1);if(!i.floatingNotes.length)delete i.floatingNotes;break}case"set_floating_note_text":{const o=i.floatingNotes?.find(a=>a.id===e.id);if(!o)return T({code:"NOTE_NOT_FOUND",message:`Floating note '${e.id}' not found`});const s=wd(e.text);if(!s.ok)return s;o.text=s.value;delete o.textContent;break}case"add_note":{if(typeof e.target!=="string"||!qn(e.target)){return T({code:"INVALID_OP",message:"State note target must be an ordinary state identifier (letters, digits, underscore, or hyphen)"})}const o=e.target;if(!Jt(i,o))return T({code:"STATE_NOT_FOUND",message:`State '${o}' not found`});const s=T_(e.side);if(!s.ok)return s;const a=C0(e.text);if(!a.ok)return a;if(!i.notes)i.notes=[];i.notes.push({target:o,side:s.value,text:a.value});break}case"remove_note":{const o=i.notes??[];if(!Number.isInteger(e.index)||e.index<0||e.index>=o.length){return T({code:"NOTE_NOT_FOUND",message:`No note at index ${e.index} (the body has ${o.length} note(s))`})}o.splice(e.index,1);if(o.length===0)delete i.notes;break}case"set_note_text":{const o=i.notes??[];if(!Number.isInteger(e.index)||e.index<0||e.index>=o.length){return T({code:"NOTE_NOT_FOUND",message:`No note at index ${e.index} (the body has ${o.length} note(s))`})}const s=C0(e.text);if(!s.ok)return s;o[e.index].text=s.value;delete o[e.index].textContent;break}case"define_class":{if(typeof e.name!=="string"||!af(e.name)){return T({code:"INVALID_OP",message:"State class definition name must contain only letters, digits, or underscore and cannot be default"})}const o=xd(e.style,"State class style");if(!o.ok)return o;if(!i.classDefs)i.classDefs={};bd(i.classDefs,e.name,o.value);const s=ii(In(e.style));if(s){i.classDefDeclarations??={};bd(i.classDefDeclarations,e.name,s)}else if(i.classDefDeclarations){delete i.classDefDeclarations[e.name];if(!Object.keys(i.classDefDeclarations).length)delete i.classDefDeclarations}break}case"set_state_class":{const o=Jt(i,e.id);if(!o)return T({code:"STATE_NOT_FOUND",message:`State '${e.id}' not found`});if(e.className===null){delete o.node.className;break}if(typeof e.className!=="string"||!/^[\w-]+$/.test(e.className)){return T({code:"INVALID_OP",message:"State class name must contain only letters, digits, underscore, or hyphen"})}o.node.className=e.className;break}case"set_state_style":{const o=Jt(i,e.id);if(!o)return T({code:"STATE_NOT_FOUND",message:`State '${e.id}' not found`});if(e.style===null){delete o.node.style;delete o.node.styleDeclarations;break}if(!to(o.node.id))return T({code:"INVALID_OP",message:`State style target "${o.node.id}" cannot be written in pinned Mermaid; style targets must contain only letters, digits, or underscore`});const s=xd(e.style,"State inline style");if(!s.ok)return s;o.node.style=s.value;o.node.styleDeclarations=ii(In(e.style));if(!o.node.styleDeclarations)delete o.node.styleDeclarations;break}case"set_transition_style":{if(e.default===true){if(e.index!==void 0||e.parent!==void 0||e.region!==void 0)return T({code:"INVALID_OP",message:"Default transition style is diagram-wide; omit index, parent, and region"});if(e.style===null)delete i.defaultTransitionStyle;else{const a=xd(e.style,"State transition style",false);if(!a.ok)return a;i.defaultTransitionStyle=a.value}break}if(e.index===void 0)return T({code:"INVALID_OP",message:"set_transition_style needs index, or default:true for the diagram-wide style"});const o=Qn(i,e.parent,e.region);if(!o.ok)return o;const s=o.value.transitions[e.index];if(!s)return T({code:"TRANSITION_NOT_FOUND",message:`No transition at index ${e.index}`});if(e.style===null)delete s.style;else{const a=xd(e.style,"State transition style",false);if(!a.ok)return a;s.style=a.value}break}case"make_composite":{const o=yd(e.id,"composite id");if(!o.ok)return o;const s=new Set;zi(i.states,s);if(s.has(o.value))return T({code:"DUPLICATE_STATE",message:`State '${o.value}' already exists`});const a=[];for(const f of e.members){const p=i.states.findIndex(g=>g.id===f);if(p<0)return T({code:"STATE_NOT_FOUND",message:`State '${f}' not found at the top level`});a.push(i.states[p])}const l=new Set(e.members);const c=i.states.filter(f=>!l.has(f.id));const d=[];const u=[];for(const f of i.transitions){if(l.has(f.from)&&l.has(f.to))d.push(f);else u.push(f)}let h;if(e.label!==void 0&&e.label!==null){const f=_a(e.label,"label");if(!f.ok)return f;h=f.value}const m={id:o.value,...h!==void 0?{label:h}:{},states:a,transitions:d};i.states=[...c,m];i.transitions=u;break}default:{const o=e;return T({code:"INVALID_OP",message:Ve("state",o)})}}if(i.unresolvedClasses){i.unresolvedClasses=i.unresolvedClasses.filter(o=>{const s=Jt(i,o.id)?.node;if(!s)return true;s.className=s.className===void 0?o.className:`${s.className} ${o.className}`;return false});if(i.unresolvedClasses.length===0)delete i.unresolvedClasses}if(i.unresolvedStyles){i.unresolvedStyles=i.unresolvedStyles.filter(o=>{const s=Jt(i,o.id)?.node;if(!s)return true;s.style={...o.style};if(o.styleDeclarations)s.styleDeclarations=structuredClone(o.styleDeclarations);else delete s.styleDeclarations;return false});if(i.unresolvedStyles.length===0)delete i.unresolvedStyles}M0(i);Td(i.states,i.transitions);const n=Sd(i);if(n)return T({code:"INVALID_OP",message:n});try{Ia(i)}catch(o){if(o instanceof eo)return T({code:"INVALID_OP",message:o.message});throw o}return re(i)}function M0(t){const e=(r,i)=>{const n=new Set;for(const o of i){n.add(o.from);n.add(o.to)}for(const o of r){if(o.label===void 0&&!o.declaredBare&&o.stereotype===void 0&&!Nr(o)&&!n.has(o.id))o.declaredBare=true;if(o.regions){for(const s of o.regions)e(s.states,s.transitions)}else if(o.states){e(o.states,o.transitions??[])}}};e(t.states,t.transitions)}function Td(t,e){for(const n of t){if(n.regions)for(const o of n.regions)Td(o.states,o.transitions);else if(n.states)Td(n.states,n.transitions??[])}const r=v0(t,e);let i=0;for(const n of r.steps){if("transition"in n)i++;else n.state.declarationBeforeTransition=i}t.splice(0,t.length,...r.created)}function of(t){if(t.regions)return t.regions;return[{states:t.states??[],transitions:t.transitions??[]}]}function Qn(t,e,r){if(e===void 0||e===null){if(r!==void 0)return T({code:"INVALID_OP",message:"A region index requires a composite parent"});return re({states:t.states,transitions:t.transitions})}const i=Jt(t,e);if(!i)return T({code:"STATE_NOT_FOUND",message:`Composite '${e}' not found`});if(!Nr(i.node)){if(r!==void 0)return T({code:"INVALID_OP",message:`State '${e}' is not a concurrent composite, so region is invalid`});i.node.states=[];i.node.transitions=[]}const n=of(i.node);const o=r??0;if(!Number.isInteger(o)||o<0||o>=n.length){return T({code:"INVALID_OP",message:`Composite '${e}' has ${n.length} region/scope(s); region ${String(r)} is out of range`})}return re(n[o])}function k0(t,e,r){if(r===Zn||zn(r))return;const i=new Set;zi(t.states,i);if(i.has(r))return;e.states.push({id:r})}function S0(t,e){return t===e||t===`${e}[H]`||t===`${e}[H*]`}function sf(t,e,r){const i=[0],n=[],o=new Set,s=new Map;e.forEach((a,l)=>{for(const c of[a.from,a.to])if(!s.has(c))s.set(c,l);if(!r(a,l)){n.push(a);o.add(a.from);o.add(a.to)}i.push(n.length)});for(const a of t){if(a.declarationBeforeTransition!==void 0)a.declarationBeforeTransition=i[a.declarationBeforeTransition];else if(!Dr(a)&&!o.has(a.id)){const l=s.get(a.id);if(l!==void 0)a.declarationBeforeTransition=i[l]}}e.splice(0,e.length,...n)}function v_(t,e){const r=n=>e.has(n)||e.has(n.replace(/\[H\*?\]$/,""));const i=(n,o)=>{sf(n,o,s=>r(s.from)||r(s.to));for(const s of n){if(s.regions)for(const a of s.regions)i(a.states,a.transitions);else if(s.states)i(s.states,s.transitions??[])}};i(t.states,t.transitions)}function E_(t,e){let r=0;const i=(n,o)=>{for(const s of o){if(S0(s.from,e)||S0(s.to,e))r++}for(const s of n){if(s.regions)for(const a of s.regions)i(a.states,a.transitions);else if(s.states!==void 0)i(s.states,s.transitions??[])}};i(t.states,t.transitions);return r}function M_(t,e,r){const i=o=>{if(o===e)return r;if(o===`${e}[H]`)return`${r}[H]`;if(o===`${e}[H*]`)return`${r}[H*]`;return o};const n=(o,s)=>{for(const a of s){a.from=i(a.from);a.to=i(a.to)}for(const a of o){if(a.regions)for(const l of a.regions)n(l.states,l.transitions);else if(a.states!==void 0)n(a.states,a.transitions??[])}};n(t.states,t.transitions)}function s3(t,e){const r=t.split(/\r?\n/);const i=r.findIndex(c=>/^stateDiagram(?:-v2)?(?=$|[\s;%])/i.test(c.trim()));if(i<0)return[];const n=r.slice(i+1);const o=Sh(n);for(let c=0;c<n.length;c++){const d=ct(n,c);if(d===void 0)break;if(d===null){c=Sl(o,c,n.length);continue}for(let u=c;u<=d.endIndex;u++)n[u]="";if(d.suffixLine)n[d.endIndex]=d.suffixLine;c=d.endIndex}const s=Lo(En(n));const a=[...s.semicolonLines.map(c=>({code:"UNSUPPORTED_SYNTAX",syntax:"state_semicolon_separator",line:i+c+2,message:"A `;` between State statements is read as a separator. Pinned Mermaid does not separate State statements with `;`: it reads the `;` into a state name, or rejects it after the header. Put each statement on its own line."})),...s.juxtaposedLines.map(c=>({code:"UNSUPPORTED_SYNTAX",syntax:"state_statements_share_line",line:i+c+2,message:'State statements sharing a line with nothing between them are read as separate statements, as Mermaid reads them: `A B` declares the states A and B. For one state whose name has a space, write `state "A B" as AB`; otherwise put each statement on its own line.'})),...s.braceNameLines.map(c=>({code:"UNSUPPORTED_SYNTAX",syntax:"state_brace_after_name",line:i+c+2,message:'A `}` right after a state name, or after the name in `state "\u2026" as A`, is read as closing its composite, and is dropped where no composite is open. Pinned Mermaid reads the `}` into the name (`A}`; after `as`, the rest of the line): inside a composite it then rejects the unclosed composite, and at the top level it draws a state named `A}`. Put the `}` on a line of its own.'})),...s.unopenedBraceLines.map(c=>({code:"UNSUPPORTED_SYNTAX",syntax:"state_brace_unopened",line:i+c+2,message:"A `}` with no composite open closes nothing, and is dropped. Pinned Mermaid reads it as a state named `}`. Remove it, or open the composite it was meant to close with `state X {`."})),...s.braceTextLines.map(c=>({code:"UNSUPPORTED_SYNTAX",syntax:"state_brace_after_description",line:i+c+2,message:"A `}` ending the last description or transition label is read as closing its composite, which nothing else closes. Pinned Mermaid reads the `}` into the text and then rejects the unclosed composite. Put the `}` on a line of its own."})),...s.aliasSuffixLines.map(c=>({code:"UNSUPPORTED_SYNTAX",syntax:"state_alias_suffix",line:i+c+2,message:'After `state "\u2026" as A`, `:::c` is read as the class of A and `: text` as its description, as each reads on a line of its own. Pinned Mermaid splits the rest of the line at every `:` and keeps only the text before a second colon as the description: it drops the class after `:::` (drawing an empty description instead) and the text after a colon inside the description. Write `class A c` or `A : text` on a line of its own.'})),...s.unclosedLines.map(c=>({code:"UNSUPPORTED_SYNTAX",syntax:"state_composite_unclosed",line:i+c+2,message:"This composite state is never closed by `}`, so where it ends cannot be told and the diagram is not drawn; pinned Mermaid rejects it too. Add a `}` where the composite ends."}))];const l=c=>{const d=n[c]??"";const u=e?.(i+c+2);return u?.trim()===d.trim()?u:d};a.push(...A_(s.statements,i,l));return a.sort((c,d)=>c.line-d.line)}function A_(t,e,r){const i=[];const n=(h,m,f,p=h.line)=>{i.push({code:"UNSUPPORTED_SYNTAX",syntax:m,line:e+p+2,message:f})};const o=h=>h.textSpan?.start.line??h.line;const s=(h,m)=>{const f=dc(m);const p=o(h);if(!/;|::/.test(f)&&!(f.endsWith(":")&&r(p).endsWith(":")))return;n(h,"state_text_cut","A `;`, a `::` or a colon ending the line in a description or transition label is read as part of the text. Pinned Mermaid ends the text there: it reads the rest of the line from a `;` as further statements, the `;` starting a state name, and rejects a `::` or a colon ending the line. The writer writes them as `#59;` and `#58;`, which Mermaid reads as the text.",p)};const a=new Set(t.flatMap(h=>{const m=h.noteBody?null:h.text.match(Oi);return m?[m[2]]:[]}));const l=new Map;const c=(h,m)=>{if(!a.has(m))return;const f=(l.get(m)??0)+1;l.set(m,f);if(f===2){n(h,"state_composite_description",`Composite state '${m}' has more than one label or description, which are read as the lines of its label. Pinned Mermaid rejects a composite with more than one (\`Group nodes can only have label\`). Give it one \`state "\u2026" as ${m}\` label.`,o(h))}};let d=false;let u=0;for(const h of t){const m=h.text;if(!h.noteBody){if(m==="}")u=Math.max(0,u-1);else if(h.opens)u++}if(m.includes("%%{")&&(h.noteBody||Hs(m)||uc(m)||m.match(_o)||m.match(Oi)||m.match(Io)||Bo(m)?.label!==void 0)){n(h,"state_text_directive","The directive-looking text is preserved as text. Pinned Mermaid preprocesses `%%{` even inside text; the writer escapes the percent sign as `#37;`.")}if(h.noteBody){if(/^end note/i.test(m))n(h,"state_note_terminator","The whole line is preserved as note text. Pinned Mermaid ends a block note at the `end note` prefix even when text follows; the writer escapes its first letter.");if(d&&m){d=false;if(/^\s*:[^:;\n]/.test(dc(r(h.line)))){n(h,"state_note_block_colon","A block note whose text starts with a colon is read as a block note, the colon its text. Pinned Mermaid reads a colon starting the text after `note \u2026 of X` as starting a one-line note's text, and then rejects `end note`. The writer writes the colon as `#58;`, which Mermaid reads as the colon.")}}continue}d=false;const f=m.match(Ch);if(f&&f[1].split(",").some(O=>!af(O.trim()))){n(h,"state_class_definition_name","The class definition name is preserved in source. Pinned Mermaid accepts only letters, digits, and underscore in definition names except `default`, with no quoted alternative; class references have a different grammar.")}const p=m.match(kh);const g=f?.[2]??p?.[2];if(g!==void 0){const O=Ti(g);if(Ql(g))n(h,"state_style_commas",_r(O)?"Native CSS commas remain inside their property values. Pinned Mermaid splits raw commas into separate styles; the writer protects value delimiters with entity codes.":"This style contains text outside the supported SVG attribute domain. Source is preserved, but typed editing is unavailable.")}if(p&&p[1].split(",").some(O=>!to(O.trim()))){n(h,"state_style_target","The style target is preserved in source. Pinned Mermaid accepts only letters, digits, and underscore in style targets, with no quoted alternative; use a portable target for typed editing.")}const y=lc(m);const C=xh(m)?.ids??(y?[y.id]:[]);if(C.some(O=>!to(O)))n(h,"state_class_target","Class membership is preserved in source. Pinned Mermaid class assignments require targets containing only letters, digits, or underscore; repair the target before typed class editing.");const w=/^(cssClass|linkStyle)\s/.exec(m)?.[1];if(w==="cssClass"){n(h,"state_css_class","`cssClass` is read as `class`, and written so. Pinned Mermaid's State grammar has no `cssClass`: it reads the words of the line as states. Write `class A name`.");continue}if(w==="linkStyle"){n(h,"state_link_style","`linkStyle` paints transitions here, and the writer writes transition paint so. Pinned Mermaid's State grammar has no `linkStyle`: it reads the words of the line as states, or rejects them, and draws no transition paint.");continue}const x=uc(m);const k=x??hc(m);if(k){d=x===null;const O=/note\s+(?:left|right)(\s+)of\s/i.exec(r(h.line));if(O&&O[1]!==" "){n(h,"state_note_position",`The note is read as a note ${k.side} of '${k.target}'. Pinned Mermaid reads \`left of\` and \`right of\` only with one space between the words, and rejects this line. The writer writes one space.`)}if(k.target.includes("-")){n(h,"state_note_target",`The note is on '${k.target}', which pinned Mermaid cannot read as a note's state: there a state name ends at a hyphen. Mermaid rejects a note whose text follows a colon, and puts a block note on the state named before the hyphen, reading the rest as note text, here and in the output. Rename the state to keep it portable.`)}if(x&&/[:;]/.test(dc(x.text))){n(h,"state_note_text_cut","A colon or `;` in a one-line note's text is read as part of the text. Pinned Mermaid ends a one-line note's text at either: it rejects a colon there, and reads the rest of the line from a `;` as further statements. The writer writes the note as a block note.")}continue}const b=Bo(m);if(b){if(u===0&&b.label!==void 0&&/^acc(?:Title|Descr)$/i.test(b.to)){n(h,"state_accessibility_endpoint","The top-level labeled transition is preserved in source. Pinned Mermaid reads this destination followed by a colon as an accessibility directive; rename the destination or remove the label for typed editing.",h.toLine)}for(const O of new Set([b.from,b.to])){if(O===Zn||zn(O)||ns(O))continue;const M=O===b.from?h.line:h.toLine;if(T0(O)){if(h.nameBlanks?.[O===b.from?0:1]===false)continue;n(h,"state_endpoint_name",`The transition names '${O}', which pinned Mermaid cannot read as a state there: before a blank, \`note\`, \`class\`, \`classDef\`, \`style\`, \`scale\` and \`stateDiagram\` start statements of their own, as \`state\` starts a declaration it drops. Mermaid rejects or drops the transition. The writer writes no blank after the name (\`${O}--> \u2026\`, \`\u2026 --> ${O}%%\`), which Mermaid reads.`,M)}else{n(h,"state_endpoint_name",`The transition names '${O}', which pinned Mermaid cannot read as a state there: a name holds no hyphen, and \`default\`, \`click\` and \`href\` start statements of their own. Mermaid rejects the transition, here and in the output. Rename the state to keep it portable.`,M)}}if(b.label!==void 0)s(h,b.label);continue}const A=m.match(Oi);if(A){if(A[1]!==void 0)c(h,A[2]);continue}const L=m.match(_o);if(L){c(h,L[2]);continue}if(qn(m)&&!Xs(m)){if(!ns(m)){n(h,"state_declaration_name",`The line declares '${m}', which pinned Mermaid cannot read as a state there: a name holds no hyphen, and \`default\`, \`href\` and \`stateDiagram\` start statements of their own, as \`state\` starts a declaration of the name after it, which Mermaid drops. Mermaid rejects the line, or reads it otherwise. The writer declares it as \`state "\u2026" as ${m}\` (a composite as \`state ${m} {\`), which Mermaid reads.`)}continue}if(lc(m))continue;const B=m.match(Io);if(B){const O=B[1];c(h,O);if(h.afterAlias)continue;if(!ns(O)){n(h,"state_description_name",`The description names '${O}', which pinned Mermaid cannot read as a state there: a name holds no hyphen, and \`note\`, \`class\`, \`classDef\`, \`style\`, \`default\`, \`click\`, \`href\`, \`scale\` and \`stateDiagram\` start statements of their own, as \`state\` starts a declaration it drops. Mermaid rejects or drops the description. The writer writes it as \`state "\u2026" as ${O}\`, which Mermaid reads.`)}s(h,B[2])}}return i}function A0(t){const e=new Set;let r=false;const i=t.split(/\r?\n/);for(const n of mo(i,Sh(i)).familyLines){const o=yl(n);if(r){if(bh(o))r=false;continue}if(hc(o)){r=true;continue}if(!Eb(o))continue;e.add(o)}return e.size===0?[]:[{code:"UNSUPPORTED_SYNTAX",syntax:"state_layout_directive",message:`State layout directives ${[...e].map(n=>`"${n}"`).join(", ")} are preserved in source but have no effect on local rendering; Agentic Mermaid uses its own layout. Typed mutation is unavailable for this preserved source.`}]}function O0(t,e){const r=[];if(t.states.length===0&&t.transitions.length===0&&(t.notes??[]).length===0&&!t.floatingNotes?.length){return[{code:"EMPTY_DIAGRAM"}]}const i=Ke(r,e);const n=new Set([Zn]);zi(t.states,n);const o=l=>{if(n.has(l))return true;const c=l.match(/^([\w\p{L}-]*)\[H\*?\]$/u);if(!c)return false;return c[1]===""||n.has(c[1])};const s=l=>{if(!zn(l))return;r.push({code:"UNSUPPORTED_SYNTAX",syntax:"state_history",node:l,message:`History pseudostate '${l}' is preserved and rendered as the standard H-circle; history re-entry semantics are not modeled by analysis.`})};const a=(l,c)=>{for(const d of l){if(d.label!==void 0)i(d.id,d.label);if(d.stereotype==="history"||d.stereotype==="deep-history"){r.push({code:"UNSUPPORTED_SYNTAX",syntax:"state_history",node:d.id,message:`History pseudostate '${d.id}' is preserved and rendered as the standard H-circle; history re-entry semantics are not modeled by analysis.`})}if(d.stereotype!==void 0&&d.label!==void 0){r.push({code:"UNSUPPORTED_SYNTAX",syntax:"state_pseudostate_label",node:d.id,message:`Pseudostate '${d.id}' carries the label "${d.label}", but ${d.stereotype} pseudostates render as anonymous glyphs (UML convention); the label is preserved in source and not drawn.`})}if(d.regions)for(const u of d.regions)a(u.states,u.transitions);else if(d.states!==void 0)a(d.states,d.transitions??[])}c.forEach(d=>{const u=`${d.from}->${d.to}`;if(!o(d.from)||!o(d.to)){r.push({code:"EDGE_MISANCHORED",edge:u,from:o(d.from)?d.from:void 0,to:o(d.to)?d.to:void 0})}s(d.from);s(d.to);if(d.label!==void 0)i(u,d.label)})};a(t.states,t.transitions);t.notes?.forEach((l,c)=>{if(!n.has(l.target)){r.push({code:"EDGE_MISANCHORED",edge:`note#${c}->${l.target}`,from:`note#${c}`})}i(`note#${c}`,l.text)});for(const l of t.floatingNotes??[])i(`floating note ${l.id}`,l.text);return r}function I0(t){return kb(t.trim().replace(/\r\n?/g,"\n"))}function df(t,e={}){try{const r=yc(["timeline",...t],e);return{kind:"timeline",...r}}catch{return null}}function p3(t){const e=t.split(/\r?\n/);const r=e.findIndex(n=>Vs(n)!==null);if(r<0)return[];const i=[];for(let n=r+1;n<e.length;n++){let o=e[n].trim();const s=ct(e,n);if(s===void 0)break;if(s){n=s.endIndex;if(!s.suffixLine)continue;o=s.suffixLine.trim()}if(Ys(o)||Sb.test(o))continue;const a=o.match(wb);const l=a?a[1].trim():o.includes(":")?void 0:o;if(l!==void 0&&/^timeline\b/i.test(o))i.push({code:"UNSUPPORTED_SYNTAX",syntax:"timeline_header_in_body",line:n+1,message:`Pinned Mermaid reads "timeline" starting a line as the diagram header, and rejects it after the header. Ours reads this line as the period ${JSON.stringify(l)}; remove a repeated header, or start the period with another word.`})}for(const[n,o]of e.entries()){if(n>r&&o.includes("%%{")&&!Ys(o))i.push({code:"UNSUPPORTED_SYNTAX",syntax:"timeline_text_directive",line:n+1,message:"Directive-looking text is retained as text. Pinned Mermaid preprocesses this opener; the writer protects its percent signs with entity codes."});if(n>r&&/^(?:title|section)$/i.test(o.trim())&&e.slice(n+1).some(s=>s.trim()))i.push({code:"UNSUPPORTED_SYNTAX",syntax:"timeline_cross_line_keyword",line:n+1,message:"This bare period keyword remains a period. Pinned Mermaid can consume the following line as its argument; the writer protects the keyword with an entity code."})}return i}function O_(t){const e=[t.direction?`timeline ${t.direction}`:"timeline"];if(t.title)e.push(` title ${si(t.title,"title")}`);if(t.accessibilityTitle)e.push(` accTitle: ${si(t.accessibilityTitle,"accessibility")}`);if(t.accessibilityDescription){if(t.accessibilityDescription.includes("\n")){e.push(" accDescr {");for(const r of t.accessibilityDescription.split(/\r?\n/)){e.push(` ${si(r.trim(),"accessibility")}`)}e.push(" }")}else{e.push(` accDescr: ${si(t.accessibilityDescription,"accessibility")}`)}}for(const r of t.sections){if(r.label!==void 0)e.push(` section ${si(r.label,"section")}`);for(const i of r.periods){if(i.events.length===0){e.push(` ${si(i.label,"period")}`);continue}e.push(` ${si(i.label,"period")} : ${si(i.events[0].text,"event")}`);for(const n of i.events.slice(1))e.push(` : ${si(n.text,"event")}`)}}return e.join("\n")+"\n"}function uf(t){return O_(t)}function B_(t){return{kind:"timeline",direction:t.direction,title:t.title,accessibilityTitle:t.accessibilityTitle,accessibilityDescription:t.accessibilityDescription,sections:t.sections.map(e=>({id:e.id,label:e.label,periods:e.periods.map(r=>({id:r.id,label:r.label,events:r.events.map(i=>({id:i.id,text:i.text}))}))}))}}function __(t){const e=t.sections.flatMap(i=>[i.id,...i.periods.flatMap(n=>[n.id,...n.events.map(o=>o.id)])]);const r={section:lr(e,"section"),period:lr(e,"period"),event:lr(e,"event")};return i=>r[i]()}function cf(t,e){if(typeof t!=="string")return T({code:"INVALID_OP",message:`Timeline ${e.field} must be a string`});const r=I0(t);if(!r.length){return T({code:"INVALID_OP",message:`Timeline ${e.field} must be non-empty`})}return re(r)}function B0(t){if(typeof t!=="string")return T({code:"INVALID_OP",message:"Timeline section label must be a string"});return re(I0(t))}function I_(t){if(typeof t!=="string")return T({code:"INVALID_OP",message:"Timeline title must be a string"});if(/[\r\n\u2028\u2029]/.test(t)){return T({code:"INVALID_OP",message:"Timeline title must be single-line; pinned Mermaid renders <br> literally in titles"})}const e=t.trim();if(!e){return T({code:"INVALID_OP",message:"Timeline title must be non-empty"})}return re(e)}function lf(t){return cf(t,{field:"event text"})}function _0(t,e){if(t===null)return re(void 0);if(typeof t!=="string")return T({code:"INVALID_OP",message:`Timeline ${e} must be a string or null`});const r=t.split(/\r?\n/).map(i=>i.trim()).filter(Boolean).join("\n");if(!r){return T({code:"INVALID_OP",message:`Timeline ${e} must be non-empty`})}return re(r)}function La(t){return t===0?"(none exist)":`(valid: 0..${t-1})`}function L0(t,e){const r=B_(t);const i=__(r);const n=c=>r.sections[c];const o=(c,d)=>n(c)?.periods[d];const s=c=>T({code:"SECTION_NOT_FOUND",message:`No section at index ${c} ${La(r.sections.length)}`});const a=(c,d)=>T({code:"PERIOD_NOT_FOUND",message:`No period at (${c},${d}) ${La(n(c)?.periods.length??0)}`});const l=c=>{if(c.label===void 0&&c.periods.length===0){r.sections.splice(r.sections.indexOf(c),1)}};switch(e.kind){case"set_title":{const c=gt(r,"title",e.title,d=>I_(d));if(!c.ok)return c;break}case"set_accessibility_title":{const c=_0(e.title,"accessibility title");if(!c.ok)return c;if(c.value===void 0)delete r.accessibilityTitle;else r.accessibilityTitle=c.value.replace(/\n/g," ");break}case"set_accessibility_description":{const c=_0(e.description,"accessibility description");if(!c.ok)return c;if(c.value===void 0)delete r.accessibilityDescription;else r.accessibilityDescription=c.value;break}case"add_section":{const c=B0(e.label);if(!c.ok)return c;const d=Ri(e.index,r.sections.length,"Timeline");if(!d.ok)return d;r.sections.splice(d.value,0,{id:i("section"),label:c.value,periods:[]});break}case"remove_section":{if(!n(e.index))return s(e.index);r.sections.splice(e.index,1);break}case"set_section_label":{const c=n(e.index);if(!c)return s(e.index);const d=B0(e.label);if(!d.ok)return d;c.label=d.value;break}case"add_period":{const c=n(e.sectionIndex);if(!c)return s(e.sectionIndex);const d=cf(e.label,{field:"period label"});if(!d.ok)return d;const u=[];for(const f of e.events??[]){const p=lf(f);if(!p.ok)return p;u.push({id:i("event"),text:p.value})}const h=Ri(e.index,c.periods.length,"Timeline");if(!h.ok)return h;const m={id:i("period"),label:d.value,events:u};c.periods.splice(h.value,0,m);break}case"remove_period":{const c=n(e.sectionIndex);if(!c)return s(e.sectionIndex);if(!c.periods[e.periodIndex])return a(e.sectionIndex,e.periodIndex);c.periods.splice(e.periodIndex,1);l(c);break}case"set_period_label":{const c=o(e.sectionIndex,e.periodIndex);if(!c)return a(e.sectionIndex,e.periodIndex);const d=cf(e.label,{field:"period label"});if(!d.ok)return d;c.label=d.value;break}case"add_event":{const c=o(e.sectionIndex,e.periodIndex);if(!c)return a(e.sectionIndex,e.periodIndex);const d=lf(e.text);if(!d.ok)return d;const u=Ri(e.index,c.events.length,"Timeline");if(!u.ok)return u;c.events.splice(u.value,0,{id:i("event"),text:d.value});break}case"remove_event":{const c=o(e.sectionIndex,e.periodIndex);if(!c)return a(e.sectionIndex,e.periodIndex);if(!c.events[e.eventIndex])return T({code:"EVENT_NOT_FOUND",message:`No event at index ${e.eventIndex} ${La(c.events.length)}`});c.events.splice(e.eventIndex,1);break}case"set_event_text":{const c=o(e.sectionIndex,e.periodIndex);if(!c)return a(e.sectionIndex,e.periodIndex);const d=c.events[e.eventIndex];if(!d)return T({code:"EVENT_NOT_FOUND",message:`No event at index ${e.eventIndex} ${La(c.events.length)}`});const u=lf(e.text);if(!u.ok)return u;d.text=u.value;break}case"move_period":{const c=n(e.fromSection);if(!c)return s(e.fromSection);if(!c.periods[e.fromIndex])return a(e.fromSection,e.fromIndex);const d=n(e.toSection);if(!d)return s(e.toSection);const[u]=c.periods.splice(e.fromIndex,1);if(!Number.isInteger(e.toIndex)||e.toIndex<0||e.toIndex>d.periods.length){return T({code:"PERIOD_NOT_FOUND",message:`No insert position ${e.toIndex} in section ${e.toSection} (0..${d.periods.length})`})}d.periods.splice(e.toIndex,0,u);if(c!==d)l(c);break}case"move_event":{const c=o(e.fromSection,e.fromPeriod);if(!c)return a(e.fromSection,e.fromPeriod);if(!c.events[e.fromIndex])return T({code:"EVENT_NOT_FOUND",message:`No event at index ${e.fromIndex} ${La(c.events.length)}`});const d=o(e.toSection,e.toPeriod);if(!d)return a(e.toSection,e.toPeriod);const[u]=c.events.splice(e.fromIndex,1);if(!Number.isInteger(e.toIndex)||e.toIndex<0||e.toIndex>d.events.length){return T({code:"EVENT_NOT_FOUND",message:`No insert position ${e.toIndex} in period (${e.toSection},${e.toPeriod}) (0..${d.events.length})`})}d.events.splice(e.toIndex,0,u);break}case"move_section":{if(!n(e.from))return s(e.from);if(!Number.isInteger(e.to)||e.to<0||e.to>=r.sections.length){return T({code:"SECTION_NOT_FOUND",message:`No section position ${e.to} (0..${r.sections.length-1})`})}const[c]=r.sections.splice(e.from,1);r.sections.splice(e.to,0,c);break}default:{const c=e;return T({code:"INVALID_OP",message:Ve("timeline",c)})}}if(r.sections.some((c,d)=>d>0&&c.label===void 0)){return T({code:"INVALID_OP",message:"Timeline unnamed section must remain first; name it before inserting or moving a named section ahead of it"})}return re(r)}function hf(t){if(!Number.isFinite(t))throw new Error(`Cannot serialize non-finite XYChart number: ${String(t)}`);if(Object.is(t,-0))return"-0";const e=String(t);const r=e.match(/^(-?)(\d)(?:\.(\d+))?e([+-]?\d+)$/i);if(!r)return e;const i=r[1];const n=r[2]+(r[3]??"");const o=1+Number(r[4]);if(o<=0)return`${i}0.${"0".repeat(-o)}${n}`;if(o>=n.length)return`${i}${n}${"0".repeat(o-n.length)}`;return`${i}${n.slice(0,o)}.${n.slice(o)}`}function vd(t){return typeof t==="number"&&Number.isFinite(t)}var L_=/^[^"'\[\];]+$/;function R_(t){return t.split(/\r?\n/).map(e=>e.trim()).filter(Boolean).join(" ")}function D_(t){return t.length>0&&L_.test(t)&&!t.includes("-->")}function F0(t){try{const e=na([...t],{strict:true});const r=n=>({...n.title!==void 0?{name:n.title}:{},...n.categories!==void 0?{categories:[...n.categories]}:{},...n.rangeAuthored&&n.range!==void 0?{range:{...n.range}}:{}});const i={kind:"xychart",...e.title!==void 0?{title:e.title}:{},...e.accessibility?.title!==void 0?{accessibilityTitle:e.accessibility.title}:{},...e.accessibility?.description!==void 0?{accessibilityDescription:e.accessibility.description}:{},...e.headerOrientation!==void 0?{horizontal:e.horizontal}:{},...e.xAxis.authored?{xAxis:r(e.xAxis)}:{},...e.yAxis.authored?{yAxis:r(e.yAxis)}:{},series:e.series.map((n,o)=>({id:`series-${o}`,kind:n.type,...n.label!==void 0?{name:n.label}:{},values:[...n.data],...n.pointLabels!==void 0?{pointLabels:[...n.pointLabels]}:{}}))};mf(i);return i}catch{return null}}function R0(t,e){const r=[];if(e.name!==void 0)r.push(No(e.name,"token"));if(e.range)r.push(`${hf(e.range.min)} --> ${hf(e.range.max)}`);if(e.categories)r.push(`[${e.categories.map(i=>No(i,"list")).join(", ")}]`);return` ${t} ${r.join(" ")}`}function mf(t){const e=t.horizontal===true?"xychart-beta horizontal":t.horizontal===false?"xychart-beta vertical":"xychart-beta";const r=[e];Lt(r,t);if(t.title!==void 0)r.push(` title ${No(t.title,"free")}`);if(t.xAxis)r.push(R0("x-axis",t.xAxis));if(t.yAxis)r.push(R0("y-axis",t.yAxis));for(const i of t.series){const n=i.name!==void 0?`${No(i.name,"free")} `:"";const o=i.values.map((s,a)=>{const l=i.pointLabels?.[a];return`${hf(s)}${l!==void 0?` ${No(l,"quoted")}`:""}`});r.push(` ${i.kind} ${n}[${o.join(", ")}]`)}return r.join("\n")+"\n"}function D0(t){return{name:t.name,categories:t.categories?[...t.categories]:void 0,range:t.range?{...t.range}:void 0}}function N_(t){return{kind:"xychart",accessibilityTitle:t.accessibilityTitle,accessibilityDescription:t.accessibilityDescription,title:t.title,horizontal:t.horizontal,xAxis:t.xAxis?D0(t.xAxis):void 0,yAxis:t.yAxis?D0(t.yAxis):void 0,series:t.series.map(e=>({id:e.id,kind:e.kind,name:e.name,values:[...e.values],...e.pointLabels?{pointLabels:[...e.pointLabels]}:{}}))}}function Ra(t,e){if(typeof t!=="string")return T({code:"INVALID_OP",message:`XY chart ${e} must be a string`});const r=R_(t);if(!D_(r)){return T({code:"INVALID_OP",message:`XY chart ${e} must be non-empty bare text (no quotes, brackets, ; or -->)`})}return re(r)}function N0(t,e){if(!Array.isArray(t)||t.length===0){return T({code:"INVALID_OP",message:`XY chart ${e} must be a non-empty array of numbers`})}for(const r of t){if(!vd(r))return T({code:"INVALID_OP",message:`XY chart ${e} must contain only finite numbers, got ${JSON.stringify(r)}`})}return re([...t])}function P0(t,e){const r={};if(t.name!==void 0&&t.name!==null){const o=Ra(t.name,`${e}-axis name`);if(!o.ok)return o;r.name=o.value}const i=t.categories!==void 0;const n=t.range!==void 0;if(i&&n){return T({code:"INVALID_OP",message:`XY chart ${e}-axis cannot have both categories and a range`})}if(i){if(e==="y")return T({code:"INVALID_OP",message:"XY chart y-axis cannot be categorical"});if(!Array.isArray(t.categories)||t.categories.length===0){return T({code:"INVALID_OP",message:"XY chart x-axis categories must be a non-empty array"})}const o=[];for(const s of t.categories){const a=Ra(s,"x-axis category");if(!a.ok)return a;o.push(a.value)}r.categories=o}if(n){const{min:o,max:s}=t.range;if(!vd(o)||!vd(s)){return T({code:"INVALID_OP",message:`XY chart ${e}-axis range min/max must be finite numbers`})}r.range={min:o,max:s}}if(r.name===void 0&&!i&&!n){return T({code:"INVALID_OP",message:`XY chart ${e}-axis needs a name, categories, or a range`})}return re(r)}function $0(t,e){const r=N_(t);const i=lr(r.series.map(n=>n.id),"series");switch(e.kind){case"set_title":{const n=gt(r,"title",e.title,o=>Ra(o,"title"));if(!n.ok)return n;break}case"set_x_axis":{const n=gt(r,"xAxis",e.axis,o=>P0(o,"x"));if(!n.ok)return n;break}case"set_y_axis":{const n=gt(r,"yAxis",e.axis,o=>P0(o,"y"));if(!n.ok)return n;break}case"add_series":{if(e.kind2!=="bar"&&e.kind2!=="line"){return T({code:"INVALID_OP",message:`XY chart series kind must be 'bar' or 'line', got ${JSON.stringify(e.kind2)}`})}let n;if(e.name!==void 0&&e.name!==null){const s=Ra(e.name,"series name");if(!s.ok)return s;n=s.value}const o=N0(e.values,"series values");if(!o.ok)return o;r.series.push({id:i(),kind:e.kind2,name:n,values:o.value});break}case"remove_series":{if(!r.series[e.index])return T({code:"SERIES_NOT_FOUND",message:`No series at index ${e.index}`});r.series.splice(e.index,1);break}case"set_series_values":{const n=r.series[e.index];if(!n)return T({code:"SERIES_NOT_FOUND",message:`No series at index ${e.index}`});const o=N0(e.values,"series values");if(!o.ok)return o;n.values=o.value;if(n.pointLabels){n.pointLabels=o.value.map((s,a)=>n.pointLabels?.[a]);if(!n.pointLabels.some(s=>s!==void 0))delete n.pointLabels}break}case"set_series_name":{const n=r.series[e.index];if(!n)return T({code:"SERIES_NOT_FOUND",message:`No series at index ${e.index}`});if(e.name===null){delete n.name;break}const o=Ra(e.name,"series name");if(!o.ok)return o;n.name=o.value;break}case"reorder_series":{const{from:n,to:o}=e;if(!Number.isInteger(n)||!Number.isInteger(o)||!r.series[n]||o<0||o>=r.series.length){return T({code:"SERIES_NOT_FOUND",message:`reorder_series indices out of range (from=${n}, to=${o})`})}const[s]=r.series.splice(n,1);r.series.splice(o,0,s);break}case"set_orientation":{if(typeof e.horizontal!=="boolean"){return T({code:"INVALID_OP",message:`XY chart set_orientation horizontal must be a boolean (true = horizontal, false = vertical), got ${JSON.stringify(e.horizontal)}`})}r.horizontal=e.horizontal;break}case"set_data_point":{const n=Number.isInteger(e.seriesIndex)?r.series[e.seriesIndex]:void 0;if(!n){const o=r.series.length>0?` (valid indices 0..${r.series.length-1})`:" (the chart has no series)";return T({code:"SERIES_NOT_FOUND",message:`No series at index ${JSON.stringify(e.seriesIndex)}${o}`})}if(!Number.isInteger(e.index)||e.index<0||e.index>=n.values.length){return T({code:"POINT_NOT_FOUND",message:`No data point at index ${JSON.stringify(e.index)} in series ${e.seriesIndex} (${n.values.length} values, valid indices 0..${n.values.length-1})`})}if(!vd(e.value)){return T({code:"INVALID_OP",message:`XY chart data point value must be a finite number, got ${JSON.stringify(e.value)}`})}n.values[e.index]=e.value;break}default:{const n=e;return T({code:"INVALID_OP",message:Ve("xychart",n)})}}return re(r)}function T3(t){return[...F_(t),...P_(t)]}function P_(t){const e=t.split(/\r?\n/);const r=e.findIndex(i=>/^xychart(?:-beta)?(?:[\s;]|$)/i.test(i.trim()));if(r<0)return[];return Yb(e.slice(r)).map(({index:i,syntax:n,what:o})=>({code:"UNSUPPORTED_SYNTAX",syntax:n,line:r+i+1,message:`${o}. Ours reads it as written; put the whole text in double quotes.`}))}function F_(t){if(!/acc(?:Title|Descr)/i.test(t))return[];const e=st(t);if(e.accessibility.title===void 0&&e.accessibility.descr===void 0)return[];let r;try{r=na(e.familyLines).accessibility}catch{return[]}return Il({title:r?.title,descr:r?.description},e.accessibility).map(i=>({code:"UNSUPPORTED_SYNTAX",syntax:"xychart_accessibility_order",message:`XY chart has an ${i} after a statement on its line and another on a line of its own. Mermaid keeps the one written last; this reader cannot tell which that is, so the source is kept as written and the one on its own line is drawn. Keep one ${i}, on a line of its own.`}))}function q0(t,e){const r=[];const i=Ke(r,e,void 0,"literal");const n=t.title!==void 0||t.xAxis!==void 0||t.yAxis!==void 0||t.accessibilityTitle!==void 0||t.accessibilityDescription!==void 0;if(t.series.length===0&&!n)r.push({code:"EMPTY_DIAGRAM"});if(t.title!==void 0)i("title",t.title);if(t.xAxis?.name!==void 0)i("x-axis",t.xAxis.name);for(const s of t.xAxis?.categories??[])i("x-axis",s);if(t.yAxis?.name!==void 0)i("y-axis",t.yAxis.name);for(const s of t.series){if(s.name!==void 0)i(s.id,s.name);const a=t.xAxis?.categories?.length;if(a!==void 0&&s.values.length!==a){r.push({code:"UNSUPPORTED_SYNTAX",syntax:"xychart_axis_series_length_mismatch",message:`XY chart series ${s.id} has ${s.values.length} values for ${a} x-axis categories; Mermaid tolerates the mismatch by dropping or synthesizing positions. Make the lengths equal.`})}}const o=t.yAxis?.range;if(o&&t.series.some(s=>s.kind==="bar")){const s=Wn(o);if(s!==0){r.push({code:"BAR_RANGE_EXCLUDES_ZERO",range:{min:o.min,max:o.max},baseline:s,message:`XY chart y-axis range ${o.min} --> ${o.max} excludes zero, so bars start at ${s} and their lengths are not proportional to their values. Include zero in the range (set_y_axis), or draw the series as a line.`})}}if(o){const s=Math.min(o.min,o.max);const a=Math.max(o.min,o.max);for(const l of t.series){const c=l.values.filter(h=>h<s||h>a);if(c.length===0)continue;const d=c.length<=5?c.join(", "):`${c.slice(0,5).join(", ")} and ${c.length-5} more`;const u=l.kind==="bar"?`its bars stop at the edge of the range, so their lengths understate ${c.length===1?"that value":"those values"}`:"its line is drawn past the plot there, beyond the axis it is read against";r.push({code:"VALUES_OUTSIDE_RANGE",series:l.id,values:c,range:{min:o.min,max:o.max},message:`XY chart ${l.kind} series ${l.id} has ${c.length===1?"value":"values"} ${d} outside the y-axis range ${o.min} --> ${o.max}: ${u}. Widen the range (set_y_axis) or remove it so the axis fits the data.`})}}return r}function os(t,e){return{parse:r=>{const i=r.lines;const{opaqueSource:n}=r;const o=e.headerOk?.(i[0]?.trim()??"")??true;const s=r.source.familyBody.split(/\r?\n/);const a=s.findIndex(c=>c.trim()===i[0]?.trim());const l=o?e.parseBody(i.slice(1),r.meta.accessibility,s.slice(a+1)):null;if(l&&e.ownsAccessibility&&("accessibilityTitle"in l||"accessibilityDescription"in l))r.meta.accessibility=uy(l);return re(l??{kind:"opaque",family:t,source:n})},serialize:r=>{if(r.kind!==t)throw new Error(`${t} serializer received body kind ${r.kind}`);return e.serialize(r)}}}var q_=/(?:\["((?:[^"\\]|\\.)*)"\]|\[(["'`]?)([^\]\n]+?)\2\]|\(\(([^)\n]+?)\)\)|\(([^)\n]+?)\)|\{([^}\n]+?)\}|\|([^|\n]+?)\||\>([^\]\n]+?)\])/g;function z_(t){const e=[];const r=t.split(/\r?\n/);for(let i=0;i<r.length;i++){const n=r[i].trim();if(!n||n.startsWith("%%"))continue;const o=n.match(/^([A-Za-z_][\w-]*)/);const s=o?o[1]:`line${i+1}`;for(const a of n.matchAll(q_)){const l=(a[1]??a[3]??a[4]??a[5]??a[6]??a[7]??a[8]??"").trim();if(l)e.push({text:l,target:s})}}return e}function G_(){return{parse:({source:t,opaqueSource:e})=>{if(Gw(t.familyBody))return re({kind:"opaque",family:"flowchart",source:e});return Tw(t.familyBody,e)},buildSourceMap:(t,e)=>t.kind==="flowchart"?Ew(t,e):{nodes:new Map,edges:new Map,groups:new Map,labels:new Map},serialize:t=>{if(t.kind!=="flowchart")throw new Error(`flowchart serializer received body kind ${t.kind}`);return Bw(t.graph,"flowchart")}}}var ff={renderSource:()=>"canonical",extractLabels:z_,...G_()};function W_(t){const e=[];const r=t.split(/\r?\n/);for(let i=0;i<r.length;i++){const n=r[i].trim();if(!n||n.startsWith("%%"))continue;const o=`line${i+1}`;let s;const a=Hs(n);if(a){e.push({text:a.text,target:o})}else if(s=n.match(/^state\s+"([^"]+)"\s+as\s+/i)){e.push({text:s[1].trim(),target:o})}else if(n.includes("-->")&&n.includes(":")){const l=n.indexOf(":");e.push({text:n.slice(l+1).trim(),target:o})}else if(s=n.match(/^[\w\p{L}-]+\s*:\s*(.+)$/u)){e.push({text:s[1].trim(),target:o})}else if(s=n.match(/^note\s+(?:left of|right of)\s+\S+\s*:\s*(.+)$/i)){e.push({text:s[1].trim(),target:o})}}return e}var pf={renderSource:()=>"canonical",extractLabels:W_,verify:(t,e)=>t.kind==="state"?O0(t,e):t.kind==="opaque"?A0(t.source):[],...os("state",{headerOk:t=>/^statediagram(?:-v2)?\s*$/i.test(t),parseBody:w0,serialize:Ia})};function U_(t){const e=[];const r=t.split(/\r?\n/);for(let i=0;i<r.length;i++){const n=r[i].trim();if(!n||n.startsWith("%%"))continue;let o;if(o=n.match(/^(?:participant|actor)\s+\S+\s+as\s+(.+)$/i)){e.push({text:o[1].trim(),target:`line${i+1}`})}else if(o=n.match(/^Note\s+(?:over|left of|right of)\s+[\w,\s]+?:\s*(.+)$/i)){e.push({text:o[1].trim(),target:`line${i+1}`})}else if((o=n.match(/->>?|-->>?|->|-->|-x|--x/))&&n.includes(":")){const s=n.indexOf(":");e.push({text:n.slice(s+1).trim(),target:`line${i+1}`})}else if(o=n.match(/^(?:loop|alt|else|opt|par|and|critical|break|rect)\s+(.+)$/i)){e.push({text:o[1].trim(),target:`line${i+1}`})}else if(o=n.match(/^title\s+(.+)$/i)){e.push({text:o[1].trim(),target:`line${i+1}`})}}return e}var gf={renderSource:t=>t.kind==="opaque"?"canonical":"serialized",extractLabels:U_,parse:({source:t,lines:e,opaqueSource:r})=>{const i=El(t,"authored");const n=i===t?e:i.familyLines;const o=_s(n).map(a=>a.trim()).filter(Boolean);if(!/^sequenceDiagram$/i.test(o[0]??""))return re({kind:"opaque",family:"sequence",source:r});const s=j_(i.familyBody,o);try{const a=Hm(o.slice(1),s);return re(a??{kind:"opaque",family:"sequence",source:r})}catch(a){if(!(a instanceof Ol))throw a;return T([{code:"PARSE_FAILED",message:a.message}])}},serialize:t=>{if(t.kind!=="sequence")throw new Error(`sequence serializer received body kind ${t.kind}`);return md(t)}};function j_(t,e){const r=t.split(/\r?\n/);const i=r.findIndex(n=>/^sequenceDiagram\b/i.test(n.trim()));return i>=0?_s(r.slice(i)).slice(1):e.slice(1)}function V_(t){const e=[];const r=t.split(/\r?\n/);for(let i=0;i<r.length;i++){const n=r[i].trim();if(!n||Ys(n))continue;let o;if(o=n.match(/^title\s+(.+)$/i)){e.push({text:o[1].trim(),target:`line${i+1}`})}else if(o=n.match(/^section\s+(.+)$/i)){e.push({text:o[1].trim(),target:`line${i+1}`})}else if(n.includes(":")){const s=n.split(":").map(a=>a.trim()).filter(Boolean);for(const a of s)e.push({text:a,target:`line${i+1}`})}}return e}function Y_(t){if(t.kind!=="opaque"||t.family!=="timeline")return[];const e=Vs($_(st(t.source).familyLines[0]??""));if(e?.kind!=="unsupported")return[];return[{code:"UNSUPPORTED_SYNTAX",syntax:"timeline_header_direction",message:`Unsupported timeline header suffix "${e.suffix}"; only LR and TD are direction tokens. The source is preserved, but rendering is rejected instead of silently using LR.`}]}var yf={renderSource:()=>"serialized",extractLabels:V_,verify:t=>Y_(t),parse:({lines:t,opaqueSource:e,meta:r})=>{const i=Vs(t[0]??"");const n=i?.kind==="supported"&&!i.hasInlineComment?df(t.slice(1),r.accessibility):null;if(n)r.accessibility={...n.accessibilityTitle!==void 0?{title:n.accessibilityTitle}:{},...n.accessibilityDescription!==void 0?{descr:n.accessibilityDescription}:{}};if(n&&i?.kind==="supported"&&i.direction)n.direction=i.direction;return re(n??{kind:"opaque",family:"timeline",source:e})},serialize:t=>{if(t.kind!=="timeline")throw new Error(`timeline serializer received body kind ${t.kind}`);return uf(t)}};function Md(){return{nodes:new Map,edges:new Map,groups:new Map,labels:new Map}}function ht(t,e){return{line:t,col:Math.max(1,e)}}function Ed(t,e){const r=t.get(e)??0;t.set(e,r+1);return r}function H_(t){const e=[];let r=0;let i;let n=false;const o=s=>{const a=t.slice(r,s);const l=a.match(/^\s*[+-]?(?:\d+(?:\.\d+)?|\.\d+)/);if(l)e.push(r+(l[0].length-l[0].trimStart().length));r=s+1};for(let s=0;s<t.length;s++){const a=t[s];if(i){if(n)n=false;else if(a==="\\")n=true;else if(a===i)i=void 0;continue}if(a==='"'||a==="'"){i=a;continue}if(a===",")o(s)}o(t.length);return e}function X_(t,e,r,i){const n=t.match(/^\s*(?:bar|line)\b/i);if(!n)return void 0;const o=n[0].length;const s=t.slice(o,i>=0?i:t.length);const a=s.match(/(["'])([^"']*)\1/);if(a?.[2]?.trim()===r&&a.index!==void 0){const c=o+a.index+1+(a[2].length-a[2].trimStart().length);return ht(e+1,c+1)}const l=t.indexOf(r,o);return l>=0&&(i<0||l<i)?ht(e+1,l+1):void 0}function K_(t){return vx(t,yb).flatMap((e,r)=>{const i=e.match(/^\s*"((?:[^"\\]|\\.)*)"\s*:/);if(i?.[1]===void 0||i.index===void 0)return[];const n=e.indexOf('"',i.index);return[{label:i[1].replace(/\\(["\\])/g,"$1"),location:ht(r+1,n+2)}]})}function J_(t){return t.search(/<\|--\|>|\(\)--|--\(\)|<\|--|--\|>|\.\.\|>|\*--|--\*|o--|--o|-->|<--|\.\.>|<\.\.?|--|\.\./)}function Q_(t){return[...t.matchAll(/"((?:\\.|[^"\\])*)"/g)].flatMap(e=>e.index===void 0?[]:[{text:e[1].replace(/\\(["\\])/g,"$1"),start:e.index+1,end:e.index+e[0].length-1}])}function Z_(t,e){const r=Md();if(t.kind!=="class")return r;const i=t;const n=e.split(/\r?\n/);const o=Ai(n);const s=new Map;const a=new Map;const l=[];const c=new Map;const d=f=>{const p=f.source.line-1;const g=n[p];const y=g.indexOf(f.text,c.get(p)??0);const C=y>=0?y:g.length-g.trimStart().length;c.set(p,C+f.text.length);return{line:g,lineIndex:p,start:C,trimmed:f.text}};const u=(f,p,g)=>{const y=`${f}\0${p}`;const C=a.get(y)??[];const w=g.line.indexOf(p,g.start);C.push(ht(g.lineIndex+1,(w>=0?w:g.start)+1));a.set(y,C)};const h=(f,p)=>{const g=p.line.indexOf(f,p.start);s.set(f,ht(p.lineIndex+1,(g>=0?g:p.start)+1))};const m=(f,p)=>{const g=[{nodes:f,owner:p,index:0}];while(g.length){const y=g.at(-1);if(y.index===y.nodes.length){g.pop();continue}const C=y.nodes[y.index++];const{owner:w}=y;const x=d(C);const k=C.value;if(k.kind==="class"){h(k.declaration.id,x);if(k.declaration.annotation!==void 0)u(k.declaration.id,`<<${k.declaration.annotation}>>`,x);if(C.children)g.push({nodes:C.children,owner:k.declaration.id,index:0})}else if(k.kind==="namespace")g.push({nodes:C.children,owner:void 0,index:0});else if(k.kind==="relationship")l.push(x);else if(k.kind==="member"){const b=k.reference?.id??w;u(b,k.text,x);if(k.reference&&!s.has(b))h(b,x)}else if(k.kind==="body-annotation")u(w,C.text,x);else if(k.kind==="annotation"){if(!s.has(k.annotation.id))h(k.annotation.id,x);u(k.annotation.id,`<<${k.annotation.annotation}>>`,x)}else if(k.kind==="interaction"||k.kind==="note"){const b=k.kind==="interaction"?k.interaction.id:k.reference?.id;if(b&&!s.has(b))h(b,x)}else if(k.kind==="style"||k.kind==="assignment"){for(const b of k.references)if(!s.has(b.id))h(b.id,x)}}};m(o.statements);for(const f of i.classes){const p=s.get(f.id);if(p)r.nodes.set(f.id,p);const g=new Map;f.members.forEach((y,C)=>{const w=Ed(g,y);const x=a.get(`${f.id}\0${y}`)?.[w];if(x)r.labels.set(`class:${f.id}:member#${C}`,x)})}i.relations.forEach((f,p)=>{const g=l[p];if(!g)return;const y=g;const C=`rel#${p}:${f.from}->${f.to}`;const w=ht(y.lineIndex+1,y.start+1);r.edges.set(C,w);if(!r.nodes.has(f.from))r.nodes.set(f.from,w);if(!r.nodes.has(f.to))r.nodes.set(f.to,w);const x=J_(y.trimmed);const k=x>=0?y.trimmed.indexOf(":",x):-1;if(f.label&&k>=0){const A=y.trimmed.indexOf(f.label,k+1);if(A>=0)r.labels.set(C,ht(y.lineIndex+1,y.start+A+1))}const b=Q_(y.trimmed);if(f.fromCardinality&&x>=0){const A=b.filter(L=>L.start<x).at(-1);if(A)r.labels.set(`${C}:fromCardinality`,ht(y.lineIndex+1,y.start+A.start+1))}if(f.toCardinality&&x>=0){const A=b.find(L=>L.start>x&&(k<0||L.start<k));if(A)r.labels.set(`${C}:toCardinality`,ht(y.lineIndex+1,y.start+A.start+1))}});return r}function eI(t,e){const r=Md();if(t.kind!=="er")return r;const i=t;const n=e.split(/\r?\n/);const o=new Map;const s=new Map;const a=[];const l=n.findIndex(f=>/^erDiagram\s*$/i.test(f.trim()));const c=js(n.slice(l+1));const d={nodes:new Map,edges:new Map,labels:new Map};const u=f=>{const p=f.endLine===f.line?f.column:0;const g=n[l+f.endLine+1].slice(p,f.endColumn);return ht(l+f.endLine+2,p+Pn(g).trimEnd().length+1)};const h=new Map;const m=new Map;for(const f of c.statements){const p={line:n[l+f.line+1],trimmed:f.raw.trim(),lineIndex:l+f.line+1,start:f.column+f.raw.length-f.raw.trimStart().length};const g=f.syntax;if(g.kind==="attribute"){const y=`${f.entityId}\0${g.text}`;const C=s.get(y)??[];C.push(ht(p.lineIndex+1,p.start+1));s.set(y,C);h.set(y,[...h.get(y)??[],u(f)])}else if(g.kind==="relation"){a.push({source:p,relation:g.relation,end:u(f)})}else if(g.kind==="entity"||g.kind==="block-open"){o.set(g.reference.id,ht(p.lineIndex+1,p.start+1));m.set(g.reference.id,u(f))}}for(const f of i.entities){const p=o.get(f.id);if(p){r.nodes.set(f.id,p);d.nodes.set(f.id,m.get(f.id))}const g=new Map;f.attributes.forEach((y,C)=>{const w=Ed(g,y.text);const x=s.get(`${f.id}\0${y.text}`)?.[w];if(!x)return;r.labels.set(`er:${f.id}:attr#${C}`,x);d.labels.set(`er:${f.id}:attr#${C}`,h.get(`${f.id}\0${y.text}`)[w])})}i.relations.forEach((f,p)=>{const g=a[p];if(!g)return;const{source:y,relation:C,end:w}=g;const x=`rel#${p}:${f.from}->${f.to}`;const k=ht(y.lineIndex+1,y.start+1);r.edges.set(x,k);d.edges.set(x,w);for(const B of[f.from,f.to]){if(r.nodes.has(B))continue;r.nodes.set(B,k);d.nodes.set(B,w)}const b=C.identifying?"--":"..";const A=`${C.leftToken}${b}${C.rightToken}`;const L=y.line.indexOf(A,y.start);if(L>=0){r.labels.set(`${x}:leftCardinality`,ht(y.lineIndex+1,L+1));r.labels.set(`${x}:rightCardinality`,ht(y.lineIndex+1,L+C.leftToken.length+b.length+1))}if(f.label){const B=y.line.indexOf(":",Math.max(y.start,L));const O=B>=0?y.line.indexOf(f.label,B+1):-1;if(O>=0){r.labels.set(x,ht(y.lineIndex+1,O+1));d.labels.set(x,ht(y.lineIndex+1,O+f.label.length+1))}}});Li(r,d);return r}function Da(t,e){const r=Md();const i=e.split(/\r?\n/);if(t.kind==="xychart"){const n=t;const o=i.map((s,a)=>({line:s,index:a})).filter(({line:s})=>/^\s*(?:bar|line)\b/i.test(s));n.series.forEach((s,a)=>{const l=o[a];if(!l||!new RegExp(`^\\s*${s.kind}\\b`,"i").test(l.line))return;const c=l.index;const d=l.line;const u=d.indexOf("[");const h=d.lastIndexOf("]");if(s.name){const p=X_(d,c,s.name,u);if(p)r.labels.set(`xychart:${s.id}:name`,p)}const m=u>=0&&h>u?d.slice(u+1,h):"";const f=H_(m);s.values.forEach((p,g)=>{const y=f[g];if(y!==void 0)r.labels.set(`xychart:${s.id}:point#${g}`,ht(c+1,u+2+y))})})}else if(t.kind==="pie"){const n=K_(i);t.slices.forEach((o,s)=>{const a=n[s];if(a?.label===o.label)r.labels.set(`pie:slice#${s}`,a.location)})}else if(t.kind==="quadrant"){const n=Si(e);const o=Bt(e);const s=new Map;let a=0;$n(n.text.split("\n"),void 0,(l,c)=>{const d=`quadrant:point#${a}`;if(t.points[a++]?.label!==l.label)return;const u=Xt(o,Iu(n,c.start));const h=Xt(o,Iu(n,c.end,"end"));r.labels.set(d,ht(u.line,u.col));s.set(d,ht(h.line,h.col))});Li(r,{labels:s})}else if(t.kind==="sankey"){const n=i.map((o,s)=>({line:o,index:s})).filter(({line:o})=>{const s=o.trim();return s.length>0&&!s.startsWith("%%")&&!/^sankey(?:-beta)?\s*:?\s*$/i.test(s)});t.links.forEach((o,s)=>{const a=n[s];if(!a)return;const l=a.line.length-a.line.trimStart().length;r.labels.set(`sankey:link#${s}`,ht(a.index+1,l+1))})}else if(t.kind==="radar"){const n=t;n.axes.forEach((o,s)=>{const a=new RegExp(`(?:^\\s*axis\\s+|,\\s*)(${z0(o.id)})(?=\\s*(?:\\[|,|$))`,"i");for(let l=0;l<i.length;l++){const c=i[l].match(a);if(!c?.[1]||c.index===void 0)continue;r.labels.set(`radar:axis#${s}`,ht(l+1,c.index+c[0].lastIndexOf(c[1])+1));break}});n.curves.forEach((o,s)=>{const a=new RegExp(`^\\s*curve\\s+(${z0(o.id)})(?=\\s*(?:\\[|\\{))`,"i");for(let l=0;l<i.length;l++){const c=i[l].match(a);if(!c?.[1]||c.index===void 0)continue;r.labels.set(`radar:curve#${s}`,ht(l+1,c.index+c[0].lastIndexOf(c[1])+1));break}})}return r}function tI(t,e){const r=Md();if(t.kind!=="gantt")return r;const i=t;const n=e.split(/\r?\n/);const o=oi(n);const s=new Map;const a=new Map;for(const l of i.sections){if(l.label){const c=Ed(a,l.label);let d=0;for(const u of o){if(u.kind!=="section"||u.value!==l.label||d++!==c)continue;const h=ht(u.startLine,u.valueColumn);r.groups.set(l.id,h);r.labels.set(`gantt:${l.id}:label`,h);break}}for(const c of l.tasks){const d=c.taskId??c.id;const u=`${c.label}\0${c.end}`;const h=Ed(s,u);let m=0;for(const f of o){if(f.kind!=="task"||f.label!==c.label)continue;const p=f.meta.end.kind==="until"?`until ${f.meta.end.refs.join(" ")}`:f.meta.end.raw;if(p!==c.end)continue;if(m++!==h)continue;const g=ht(f.startLine,f.valueColumn);r.nodes.set(d,g);r.labels.set(`gantt:task:${d}`,g);break}}}return r}function z0(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function rI(t){const e=[];const r=t.split(/\r?\n/);for(let i=0;i<r.length;i++){const n=r[i].trim();if(!n||n.startsWith("%%"))continue;let o;if(o=n.match(/^class\s+\S+\s+as\s+"([^"]+)"/i)){e.push({text:o[1],target:`line${i+1}`})}else if(o=n.match(/^\S+\s*:\s*(.+)$/)){e.push({text:o[1].trim(),target:`line${i+1}`})}else if(o=n.match(/^[+\-#~]\s*(.+)$/)){e.push({text:o[1].trim(),target:`line${i+1}`})}else if(o=n.match(/^note\s+(?:for\s+\S+\s+)?"([^"]+)"/i)){e.push({text:o[1],target:`line${i+1}`})}}return e}var xf={renderSource:()=>"canonical",extractLabels:rI,verify:(t,e)=>t.kind==="class"?ew(t,e):[],buildSourceMap:Z_,...os("class",{parseBody:$c,serialize:qc})};function iI(t){const e=[];const r=t.split(/\r?\n/);for(let i=0;i<r.length;i++){const n=r[i].trim();if(!n||n.startsWith("%%"))continue;let o;if(o=n.match(/:\s*"?([^"]+?)"?$/)){e.push({text:o[1].trim(),target:`line${i+1}`})}if(n.match(/^\s*\w+\s+\w+/)&&!n.match(/[<>|}]/)){e.push({text:n,target:`line${i+1}`})}}return e}var bf={renderSource:()=>"canonical",extractLabels:iI,verify:(t,e)=>t.kind==="er"?fw(t,e):[],buildSourceMap:eI,...os("er",{headerOk:t=>/^erdiagram\s*$/i.test(t),parseBody:(t,e,r)=>lw(t,r),serialize:hw})};function nI(t){const e=[];const r=t.split(/\r?\n/);const i=r.findIndex(o=>/^\s*journey\b/i.test(o));const n=(o,s)=>{for(const a of o.split("\n")){if(a)e.push({text:a,target:`line${s+1}`})}};Fn(r,i+1,{title:n,accTitle:n,accDescr:n,section:n,task:(o,s,a,l)=>{n(o,l);for(const c of a)n(c,l)}});return e}function oI(t){if(t.kind!=="opaque"||t.family!=="journey")return[];const e=[];const r=t.source.split(/\r?\n/);const i=r.findIndex(o=>/^\s*journey\b/i.test(o));let n;Fn(r,i+1,{issue:o=>{if(o.code==="invalid_score"){e.push({code:"UNSUPPORTED_SYNTAX",line:o.lineIndex+1,syntax:"journey_invalid_score",message:`${o.detail}.`});return}n??=o}});if(n){e.push({code:"UNSUPPORTED_SYNTAX",line:n.lineIndex+1,syntax:`journey_${n.code}`,message:`${n.detail}. The diagram is preserved verbatim as source; fix this line to unlock typed journey mutation.`})}return e}var Cf={renderSource:()=>"canonical",extractLabels:nI,verify:(t,e)=>t.kind==="journey"?gT(t,e):t.kind==="opaque"?oI(t):[],...os("journey",{ownsAccessibility:true,headerOk:t=>/^journey\s*$/i.test(t),parseBody:(t,e)=>{const r=Vm(t,e);return r.ok?r.body:null},serialize:Ym})};function sI(t){const e=[];const r=t.split(/\r?\n/);for(let i=0;i<r.length;i++){const n=r[i].trim();if(!n||n.startsWith("%%"))continue;const o=lI(n);for(const s of o){const a=`line${i+1}`;let l;if(l=s.match(/^accDescr\s*:?\s*\{\s*(.*)$/i)){const p=l[1];const g=p.indexOf("}");if(g>=0){const y=p.slice(0,g).trim();if(y)e.push({text:y,target:a})}else{const y=p.trim();if(y)e.push({text:y,target:a});for(i+=1;i<r.length;i++){const C=r[i].trim();const w=C.indexOf("}");const x=(w>=0?C.slice(0,w):C).trim();if(x)e.push({text:x,target:`line${i+1}`});if(w>=0)break}}continue}if(l=s.match(/^accTitle\s*:?\s*(.+)$/i))e.push({text:l[1].trim(),target:a});else if(l=s.match(/^accDescr\s*:?\s*(.+)$/i))e.push({text:l[1].trim(),target:a});for(const p of aI(s))e.push({text:p,target:a});const c=s.match(/^title\s+(.+)$/i);if(c&&!/^['"]/.test(c[1].trim()))e.push({text:c[1].trim(),target:a});const d=s.match(/^[xy]-axis\s+(.+?)\s*\[[^\]]+\]\s*$/i);const u=s.match(/^[xy]-axis\s+(\S+)\s+[+-]?(?:(?:\d+(?:\.\d+)?|\.\d+)(?:[eE][+-]?\d+)?)\s*-->/i);const h=d??u??s.match(/^[xy]-axis\s+([^\[\d.+-][^\[]*?)\s*(?:\[|[+-]?\d|$)/i);if(h&&!/^['"]/.test(h[1].trim()))e.push({text:h[1].trim(),target:a});const m=s.match(/^(?:bar|line)\s+(.+?)\s+\[[^\]]+\]\s*$/i);if(m&&!/^['"]/.test(m[1].trim()))e.push({text:m[1].trim(),target:a});const f=s.match(/^[xy]-axis\b.*\[([^\]]+)\]/i);if(f){for(const p of f[1].split(",")){const g=p.trim().replace(/^["']|["']$/g,"");if(g)e.push({text:g,target:a})}}}}return e}function aI(t){const e=[];for(const r of['"',"'"]){const i=r==='"'?/"((?:\\.|[^"\\])+)"/g:/'((?:\\.|[^'\\])*)'/g;for(const n of t.matchAll(i))e.push(n[1].replace(/\\"/g,'"').replace(/\\'/g,"'").replace(/\\\\/g,"\\"))}return e}function lI(t){const e=[];let r="";let i=null;for(let o=0;o<t.length;o++){const s=t[o];if(i){r+=s;if(s==="\\"){r+=t[++o]??"";continue}if(s===i)i=null;continue}if(s==='"'||s==="'"){i=s;r+=s;continue}if(s===";"){const a=r.trim();if(a)e.push(a);r="";continue}r+=s}const n=r.trim();if(n)e.push(n);return e}var kf={renderSource:t=>t.kind==="opaque"?"canonical":"serialized",extractLabels:sI,verify:(t,e)=>t.kind==="xychart"?q0(t,e):[],buildSourceMap:Da,parse:({lines:t,opaqueSource:e,meta:r})=>{const i=F0(t);if(!i)return re({kind:"opaque",family:"xychart",source:e});if(!Gu(r,{title:i.accessibilityTitle,descr:i.accessibilityDescription}))return re({kind:"opaque",family:"xychart",source:e});return re(i)},serialize:t=>{if(t.kind!=="xychart")throw new Error(`xychart serializer received body kind ${t.kind}`);return mf(t)}};function cI(t){const e=[];const r=t.split(/\r?\n/);for(let i=0;i<r.length;i++){const n=r[i].trim();if(!n||n.startsWith("%%"))continue;const o=`line${i+1}`;let s;if(s=n.match(/^pie\b\s*(?:showData\b\s*)?title\s+(.+)$/i)){e.push({text:s[1].trim(),target:o});continue}if(/^pie\b/i.test(n))continue;if(s=n.match(/^title\s+(.+)$/i)){e.push({text:s[1].trim(),target:o});continue}if(s=n.match(/^"((?:[^"\\]|\\.)*)"\s*:/)){const a=s[1].replace(/\\"/g,'"').replace(/\\\\/g,"\\").trim();if(a)e.push({text:a,target:o})}}return e}function dI(t){const e=t.match(/^pie\b(.*)$/i);if(!e)return null;let r=e[1].trim();let i=false;const n=r.match(/^showData\b\s*(.*)$/i);if(n){i=true;r=n[1].trim()}const o=r.match(/^title\s+(.+)$/i);if(o)return{showData:i,title:o[1].trim()};if(r.length>0)return null;return{showData:i}}var Sf={renderSource:t=>t.kind==="opaque"?"canonical":"serialized",extractLabels:cI,verify:(t,e)=>t.kind==="pie"?IT(t,e):[],buildSourceMap:Da,parse:({lines:t,opaqueSource:e})=>{const r=dI(Pn(t[0]?.trim()??""));const i=t.slice(1).map(o=>{const s=sc(o,"body");return s?s.decodedPrefix+s.authoredTitle:o});const n=r?OT(i,r):null;return re(n??{kind:"opaque",family:"pie",source:e})},serialize:t=>{if(t.kind!=="pie")throw new Error(`pie serializer received body kind ${t.kind}`);return BT(t)}};function uI(t){const e=[];const r=t.split(/\r?\n/);for(let i=0;i<r.length;i++){const n=r[i].trim();if(!n||n.startsWith("%%"))continue;const o=`line${i+1}`;if(/^quadrant(?:chart)?\b/i.test(n))continue;let s;if(s=n.match(/^title\s+(.+)$/i)){e.push({text:s[1].trim(),target:o});continue}if(s=n.match(/^[xy]-axis\s+(.+)$/i)){const a=s[1].trim();const l=a.indexOf("-->");if(l>=0){const c=a.slice(0,l).trim();const d=a.slice(l+3).trim();if(c)e.push({text:c,target:o});if(d)e.push({text:d,target:o})}else if(a){e.push({text:a,target:o})}continue}if(s=n.match(/^quadrant-[1-4]\s+(.+)$/i)){e.push({text:s[1].trim(),target:o});continue}if(s=n.match(/^(.+?)\s*:\s*\[[^\]]*\]\s*(?:.*)?$/)){const a=s[1].replace(/\s*:::\s*[A-Za-z_][\w-]*\s*$/,"").trim();if(a)e.push({text:a,target:o})}}return e}function hI(t){if(t.kind!=="opaque"||t.family!=="quadrant")return[];const e=[];let r=false;let i=false;for(const n of t.source.split(/\r?\n/)){const o=n.trim();if(!o||o.startsWith("%%"))continue;if(/^classDef\b/i.test(o))i=true;const s=o.match(/^(.+?)\s*:\s*\[[^\]]*\]\s*(.*)$/);if(s&&(s[1].includes(":::")||s[2].trim().length>0))r=true}if(r){e.push({code:"UNSUPPORTED_SYNTAX",syntax:"quadrant_point_style_metadata",message:"Quadrant point style/class metadata is present but this diagram fell back to an opaque body (malformed style metadata or other unmodeled syntax), so typed mutation cannot see the styles. Well-formed radius/color/stroke styling parses structured and renders."})}if(i){e.push({code:"UNSUPPORTED_SYNTAX",syntax:"quadrant_classDef_metadata",message:"Quadrant classDef metadata is present but this diagram fell back to an opaque body (malformed classDef or other unmodeled syntax), so typed mutation cannot see the classes. Well-formed classDefs parse structured and render."})}return e}var wf={renderSource:t=>t.kind==="opaque"?"canonical":"serialized",extractLabels:uI,verify:(t,e)=>t.kind==="quadrant"?GT(t,e):t.kind==="opaque"?hI(t):[],buildSourceMap:Da,parse:t=>{const e=st(t.source.originalText,{},"render");const r=/^quadrant(?:chart)?\s*$/i.test(Pn(e.familyLines[0]??""))?$T(e.familyLines.slice(1)):null;return re(r??{kind:"opaque",family:"quadrant",source:t.opaqueSource})},serialize:t=>{if(t.kind!=="quadrant")throw new Error(`quadrant serializer received body kind ${t.kind}`);return qT(t)}};function mI(t){const e=[];const r=t.split(/\r?\n/);for(const i of oi(r)){const n=`line${i.startLine}`;if(i.kind==="title"||i.kind==="section")e.push({text:i.value,target:n});else if(i.kind==="task")e.push({text:i.label,target:n});else if(i.kind==="accessibility")e.push({text:i.directive.value,target:n})}return e}function fI(t){const e=t.split(/\r?\n/);const r=e.findIndex(i=>/^gantt\b/i.test(i.trim()));return r>=0?e.slice(r+1):e.slice(1)}var Tf={renderSource:t=>t.kind==="opaque"?"canonical":"serialized",extractLabels:mI,verify:(t,e)=>t.kind==="gantt"?lT(t,e):[],buildSourceMap:tI,parse:({source:t,lines:e,opaqueSource:r})=>{const i=/^gantt\s*$/i.test(Pn(e[0]?.trim()??""));const n=i?iT(e.slice(1),fI(t.familyBody)):null;const o=wl(t.frontmatter,["gantt","axisFormat"]);if(n&&n.axisFormat===void 0&&typeof o==="string")n.axisFormat=o;return re(n??{kind:"opaque",family:"gantt",source:r})},serialize:t=>{if(t.kind!=="gantt")throw new Error(`gantt serializer received body kind ${t.kind}`);return oT(t)}};function pI(t){const e=[];const r=t.split(/\r?\n/);for(const i of Jl(r)){if(i.kind==="title")e.push({text:i.value,target:"title"});else if(i.kind==="group"||i.kind==="service")e.push({text:i.declaration.title,target:`line${i.startLine}`});else if(i.kind==="edge"&&i.edge.label!==void 0)e.push({text:i.edge.label,target:`line${i.startLine}`})}return e}var vf={renderSource:()=>"canonical",extractLabels:pI,verify:(t,e)=>t.kind==="architecture"?qS(t,e):t.kind==="opaque"?$S(t.source):[],...os("architecture",{headerOk:t=>/^architecture(?:-beta)?\s*$/i.test(Pn(t)),parseBody:DS,serialize:NS})};var Ef={renderSource:()=>"serialized",extractLabels:la,parse:({source:t,opaqueSource:e,meta:r})=>{try{r.accessibility=ki(r.accessibility);const i=kT(t.familyBody,e);return re(Zs(i,e)?{kind:"opaque",family:"mindmap",source:e}:i)}catch(i){return T([{code:"PARSE_FAILED",message:i instanceof Error?i.message:String(i)}])}},serialize:t=>{if(t.kind!=="mindmap")throw new Error(`mindmap serializer received body kind ${t.kind}`);return ST(t)},verify:(t,e)=>t.kind==="mindmap"?ET(t,e):[]};var Mf={renderSource:()=>"serialized",extractLabels:la,parse:({source:t,meta:e})=>{try{const r={...e.frontmatter?.gitGraph&&typeof e.frontmatter.gitGraph==="object"?e.frontmatter.gitGraph:{}};const i=dT(t.familyBody,{mainBranchName:typeof r.mainBranchName==="string"?r.mainBranchName:void 0,mainBranchOrder:typeof r.mainBranchOrder==="number"?r.mainBranchOrder:void 0,title:typeof e.frontmatter?.title==="string"?e.frontmatter.title:void 0});return re(i)}catch(r){return T([{code:"PARSE_FAILED",message:r instanceof Error?r.message:String(r)}])}},serialize:t=>{if(t.kind!=="gitgraph")throw new Error(`gitgraph serializer received body kind ${t.kind}`);return Um(t)},verify:(t,e)=>t.kind==="gitgraph"?hT(t,e):[]};function gI(t){const e=[];const r=t.split(/\r?\n/);for(let i=0;i<r.length;i++){const n=r[i].trim();if(!n||n.startsWith("%%"))continue;const o=`line${i+1}`;let s;if(s=n.match(/^title\s+(.+)$/i)){e.push({text:s[1].trim(),target:o});continue}if(/^radar-beta\b/i.test(n))continue;for(const a of n.matchAll(/\[\s*["']([^"'\]]+)["']\s*\]/g))e.push({text:a[1],target:o})}return e}var Af={renderSource:t=>t.kind==="opaque"?"canonical":"serialized",extractLabels:gI,verify:(t,e)=>t.kind==="radar"?XT(t,e):[],buildSourceMap:Da,parse:({lines:t,opaqueSource:e,meta:r})=>{const i=/^radar-beta\s*:?\s*$/i.test(Pn(t[0]?.trim()??""))?VT(t.slice(1)):null;if(!i||!Gu(r,i.accessibility))return re({kind:"opaque",family:"radar",source:e});return re(i.body)},serialize:t=>{if(t.kind!=="radar")throw new Error(`radar serializer received body kind ${t.kind}`);return YT(t)}};var yI=/"((?:[^"]|"")*)"|([^,]+)/g;function xI(t){const e=[];const r=t.split(/\r?\n/);for(let i=0;i<r.length;i++){const n=r[i].trim();if(!n||n.startsWith("%%")||/^sankey(?:-beta)?\b/i.test(n))continue;const o=`line${i+1}`;const s=[];for(const a of n.matchAll(yI)){s.push(a[1]!==void 0?a[1].replace(/""/g,'"'):(a[2]??"").trim())}for(const a of s.slice(0,2))if(a)e.push({text:a,target:o})}return e}var Of={renderSource:()=>"serialized",extractLabels:xI,verify:(t,e)=>t.kind==="sankey"?n0(t,e):[],buildSourceMap:Da,...os("sankey",{headerOk:t=>/^sankey(?:-beta)?\s*$/i.test(t),parseBody:(t,e)=>{const r=ki(e);Object.assign(e,r);return e0(t)},serialize:r0})};var Bf={renderSource:t=>t.kind==="opaque"?"canonical":"serialized",parse:t=>{try{return re(bS(t.opaqueSource,t.meta.accessibility)??{kind:"opaque",family:"c4",source:t.opaqueSource})}catch(e){if(!(e instanceof jl))throw e;return T([{code:"PARSE_FAILED",message:e.message}])}},serialize:t=>{if(t.kind!=="c4")throw new Error(`C4 serializer received body kind ${t.kind}`);return ES(t)},verify:(t,e)=>t.kind==="c4"?OS(t,e):[],buildSourceMap:(t,e)=>t.kind==="c4"?BS(t,e):{nodes:new Map,edges:new Map,groups:new Map,labels:new Map},extractLabels:t=>{try{const e=Fx(t);return[...e.title===void 0?[]:[{text:e.title,target:"title"}],...e.elements.flatMap(r=>[r.label,r.technology,r.description].filter(i=>typeof i==="string"&&i.length>0).map(i=>({text:i,target:r.id}))),...e.boundaries.map(r=>({text:r.label,target:r.id})),...e.relationships.flatMap(r=>[r.label,r.technology,r.description].filter(i=>typeof i==="string"&&i.length>0).map(i=>({text:i,target:r.id})))]}catch{return la(t)}}};var b4=Object.freeze({flowchart:ff,state:pf,sequence:gf,timeline:yf,class:xf,er:bf,journey:Cf,xychart:kf,pie:Sf,quadrant:wf,gantt:Tf,architecture:vf,mindmap:Ef,gitgraph:Mf,radar:Af,sankey:Of,c4:Bf,zenuml:da,eventmodeling:ua,...sS});var G0=new WeakMap;function _f(t,e){G0.set(t,e);return t}function w4(t,e){return G0.get(t)?.(e)}function ro(t,e){return(r,i)=>{if(r.kind!==t)return T({code:"INVALID_OP",message:`${t} mutator received body kind ${r.kind}`});return e(r,i)}}var bI={...ff,mutateSource:(t,e)=>Dw(t,e),mutate:_f((t,e)=>{if(t.kind!=="flowchart")return T({code:"INVALID_OP",message:`flowchart mutator received body kind ${t.kind}`});return ka(t,e)},t=>{if(t.kind!=="flowchart")return void 0;const e=Nw(t);return r=>e(r)})};var CI={...pf,mutate:ro("state",E0)};var kI={...gf,mutate:_f((t,e)=>{if(t.kind!=="sequence")return T({code:"INVALID_OP",message:`sequence mutator received body kind ${t.kind}`});return c0(t,e)},t=>{if(t.kind!=="sequence")return void 0;const e=d0(t);return r=>e(r)})};var SI={...yf,mutate:(t,e)=>{if(t.kind!=="timeline")return T({code:"INVALID_OP",message:`timeline mutator received body kind ${t.kind}`});return L0(t,e)}};var wI={...xf,mutate:ro("class",QS),mutateSource:(t,e)=>ZS(t,e)};var TI={...bf,mutate:ro("er",mw)};var vI={...Cf,mutate:ro("journey",pT)};var EI={...kf,mutate:(t,e)=>{if(t.kind!=="xychart")return T({code:"INVALID_OP",message:`xychart mutator received body kind ${t.kind}`});return $0(t,e)}};var MI={...Sf,mutate:(t,e)=>{if(t.kind!=="pie")return T({code:"INVALID_OP",message:`pie mutator received body kind ${t.kind}`});return _T(t,e)}};var AI={...wf,mutate:ro("quadrant",zT)};var OI={...Tf,mutate:(t,e)=>{if(t.kind!=="gantt")return T({code:"INVALID_OP",message:`gantt mutator received body kind ${t.kind}`});return sT(t,e)}};var BI={...vf,mutate:ro("architecture",PS)};var _I={...Ef,mutate:(t,e)=>t.kind==="mindmap"?vT(t,e):T({code:"INVALID_OP",message:`mindmap mutator received body kind ${t.kind}`})};var II={...Mf,mutate:(t,e)=>t.kind==="gitgraph"?uT(t,e):T({code:"INVALID_OP",message:`gitgraph mutator received body kind ${t.kind}`})};var LI={...Af,mutate:(t,e)=>{if(t.kind!=="radar")return T({code:"INVALID_OP",message:`radar mutator received body kind ${t.kind}`});return HT(t,e)}};var RI={...Of,mutate:ro("sankey",i0)};var DI={...Bf,mutate:(t,e)=>t.kind==="c4"?AS(t,e):T({code:"UNSUPPORTED_FAMILY",message:"C4 source contains unmodeled syntax; preserve it verbatim or edit source explicitly."})};var NI={...ua,mutate:(t,e)=>t.kind==="eventmodeling"?Pk(t,e):T({code:"UNSUPPORTED_FAMILY",message:"Unmodeled Event Modeling source remains preserved"})};var PI={...da,mutate:(t,e)=>t.kind==="zenuml"?ox(t,e):T({code:"UNSUPPORTED_FAMILY",message:"Unmodeled ZenUML source remains preserved."})};var W0=Object.freeze({flowchart:bI,state:CI,sequence:kI,timeline:SI,class:wI,er:TI,journey:vI,xychart:EI,pie:MI,quadrant:AI,gantt:OI,architecture:BI,mindmap:_I,gitgraph:II,radar:LI,sankey:RI,c4:DI,zenuml:PI,eventmodeling:NI,...aS});function Fe(t,e={}){return Object.freeze({document:t,serialization:Object.freeze({...e})})}function Tt(t){return t.document.serialize(t.serialization)}var U0=Symbol("native terminal renderer");function dt(t){const e=r=>Tt(t(r));Object.defineProperty(e,U0,{value:t});return Object.freeze(e)}function j0(t,e,r){return t[U0]?.(e,r)}var ir="\0";function If(t){const e=t.codePointAt(0)??0;if(e===ku||e===Su||e===wu)return 0;if(vu(e))return 0;if(Tu(e))return 2;return 1}function ne(t){let e=0;let r=0;let i=false;for(const n of t){const o=n.codePointAt(0)??0;if(o===Su){if(r===1){e+=1;r=2}continue}if(o===ku){if(r===2){e-=1;r=1}continue}if(o===wu){i=true;r=0;continue}if(og(o)&&r===2)continue;if(vu(o)){r=0;continue}let s=Tu(o)?2:1;if(i){s=0;i=false}e+=s;r=s}return e}var FI=Object.freeze({maxBytes:2e6,maxLines:1e5,maxLineCells:1e5});var hi=class extends TypeError{code="TERMINAL_OUTPUT_ADMISSION_FAILED";constructor(e){super(e);this.name="TerminalOutputAdmissionError"}};var $I=/\x1b\[(?:0|3[0-7]|9[0-7])m/g;var Ad="(?:0|[1-9]\\d?|1\\d{2}|2[0-4]\\d|25[0-5])";var qI=new RegExp(`\\x1b\\[(?:0|38;5;${Ad})m`,"g");var zI=new RegExp(`\\x1b\\[(?:0|38;2;${Ad};${Ad};${Ad})m`,"g");var GI=/[\u0000-\u0009\u000b-\u001f\u007f-\u009f]/;function V0(t,e){const r=Y0(e);return r?t.replace(r,""):t}function Y0(t){switch(t){case"ansi16":return $I;case"ansi256":return qI;case"truecolor":return zI;default:return void 0}}function WI(t,e){const r=Y0(e);if(!r)return;let i=false;let n=true;for(const o of t.matchAll(new RegExp(r.source,"g"))){n=o[0]==="\x1B[0m";if(!n)i=true}if(i&&!n){throw new hi(`External family terminal output leaves ANSI color state active for color mode "${e}"`)}}function Rf(t,e){return ne(Od(t,e))}function Od(t,e){if(e==="none")return t;if(e!=="html")return V0(t,e);return t.replace(/<span style="color:[^"<>&]+">|<\/span>/g,"").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&")}function H0(t,e){if(typeof t!=="string"){throw new hi("External family terminal renderer must return a string")}const r=FI;if(An(t,r.maxBytes)>r.maxBytes){throw new hi(`External family terminal output exceeds the ${r.maxBytes}-byte limit`)}const i=e==="html"?Na(t):t;if(i!==t&&An(i,r.maxBytes)>r.maxBytes){throw new hi(`Secured external family terminal output exceeds the ${r.maxBytes}-byte limit`)}const n=V0(i,e);if(GI.test(n)){throw new hi(`External family terminal output contains a disallowed control sequence for color mode "${e}"`)}WI(i,e);const o=Od(i,e).trim();if(o.length===0||ne(o)===0){throw new hi(`External family terminal output has no visible content for color mode "${e}"`)}let s=1;for(let l=i.indexOf("\n");l>=0;l=i.indexOf("\n",l+1)){if(++s>r.maxLines){throw new hi(`External family terminal output exceeds the ${r.maxLines}-line limit`)}}const a=i.split("\n");for(let l=0;l<a.length;l++){if(Rf(a[l],e)>r.maxLineCells){throw new hi(`External family terminal output line ${l+1} exceeds the ${r.maxLineCells}-cell limit`)}}return i}function Lf(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Na(t){const e=/<span style="color:([^"<>&]+)">([^<>]*)<\/span>/g;let r="";let i=0;for(const n of t.matchAll(e)){const o=n.index??0;r+=Lf(t.slice(i,o));const s=Zi(n[1]);const a=!/&(?!amp;|lt;|gt;)/.test(n[2]);r+=s===n[1]&&a?n[0]:Lf(n[0]);i=o+n[0].length}return r+Lf(t.slice(i))}var Pr={fg:"#27272a",border:"#a1a1aa",line:"#71717a",arrow:"#52525b",corner:"#71717a",junction:"#a1a1aa"};var Df=ig;function Ff(t){const e=t.line??Df(t.fg,t.bg,hl.line);const r=t.border??Df(t.fg,t.bg,hl.nodeStroke);return{fg:t.fg,border:r,line:e,arrow:t.accent??Df(t.fg,t.bg,hl.arrow),accent:t.accent,bg:t.bg,corner:e,junction:r}}function $f(t){const e=globalThis.process;if(t?.browser===true)return"html";if(e||t){const r=t?.isTTY??e?.stdout?.isTTY;if(!r){return"none"}const i=t?.env??e?.env??{};const n=i.COLORTERM?.toLowerCase()??"";const o=i.TERM?.toLowerCase()??"";if(o==="dumb"||i.NO_COLOR!==void 0)return"none";if(n==="truecolor"||n==="24bit"){return"truecolor"}if(o.includes("256color")||o.includes("256")){return"ansi256"}if(o&&o!=="dumb"){return"ansi16"}return"none"}return"none"}var _d="\x1B[";var Bd=`${_d}0m`;function X0(t){const[e,r,i]=al(t);return`${_d}38;2;${e};${r};${i}m`}function UI(t,e,r){const i=(t+e+r)/3;const n=Math.max(Math.abs(t-i),Math.abs(e-i),Math.abs(r-i));if(n<10){const c=Math.round(i/255*23);return 232+Math.min(23,Math.max(0,c))}const o=c=>{if(c<48)return 0;if(c<115)return 1;return Math.min(5,Math.floor((c-35)/40))};const s=o(t);const a=o(e);const l=o(r);return 16+36*s+6*a+l}function K0(t){const[e,r,i]=al(t);const n=UI(e,r,i);return`${_d}38;5;${n}m`}function J0(t){const[e,r,i]=al(t);const n=ng(e,r,i);const o=n>100?0:60;let s;if(e>180&&r<100&&i<100)s=31;else if(r>180&&e<100&&i<100)s=32;else if(e>150&&r>150&&i<100)s=33;else if(i>180&&e<100&&r<100)s=34;else if(e>150&&i>150&&r<100)s=35;else if(r>150&&i>150&&e<100)s=36;else if(n>200)s=37;else if(n<50)s=30;else s=37;return`${_d}${s+o}m`}function Pf(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function Q0(t,e){const r=Zi(t);return r?`<span style="color:${r}">${Pf(e)}</span>`:Pf(e)}function Z0(t){const e=Ar(t);const r=e?Ft(e):null;return r&&r[3]===1?Mr(r[0],r[1],r[2]):void 0}function ev(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 Nf(t,e,r){if(r==="none")return"";const i=Z0(ev(t,e));if(!i)return"";switch(r){case"truecolor":return X0(i);case"ansi256":return K0(i);case"ansi16":return J0(i);default:return""}}function tv(t,e,r,i){t=t.map(a=>$t(a));if(i==="none"){return t.join("")}if(i==="html"){return jI(t,e,r)}let n="";let o=null;let s="";for(let a=0;a<t.length;a++){const l=t[a];const c=e[a]??null;if(l===" "){if(s.length>0){if(o!==null){n+=Nf(o,r,i)+s+Bd}else{n+=s}s="";o=null}n+=l;continue}if(c===o){s+=l;continue}if(s.length>0){if(o!==null){n+=Nf(o,r,i)+s+Bd}else{n+=s}}s=l;o=c}if(s.length>0&&o!==null){n+=Nf(o,r,i)+s+Bd}else if(s.length>0){n+=s}return n}function jI(t,e,r){let i="";let n=null;let o="";const s=()=>{if(o.length===0)return;if(n!==null){i+=Q0(ev(n,r),o)}else{i+=Pf(o)}o="";n=null};for(let a=0;a<t.length;a++){const l=t[a];const c=e[a]??null;if(l===" "){s();i+=" ";continue}if(c===n){o+=l;continue}s();o=l;n=c}s();return i}function rv(t,e,r){t=$t(t);if(r==="none"||t.length===0)return t;if(r==="html")return Q0(e,t);const i=Z0(e);if(!i)return t;let n;switch(r){case"truecolor":n=X0(i);break;case"ansi256":n=K0(i);break;case"ansi16":n=J0(i);break;default:return t}return`${n}${t}${Bd}`}var Wt=Object.freeze({maxOperations:1e6,maxOutputCodeUnits:2e6,maxIssues:64});var je={x:1,y:0};var We={x:1,y:2};var $e={x:0,y:1};var Pe={x:2,y:1};var xr={x:2,y:0};var dr={x:0,y:0};var Fr={x:2,y:2};var br={x:0,y:2};var mi={x:1,y:1};function qf(t,e){return t.x===e.x&&t.y===e.y}function Pa(t,e){return t.x===e.x&&t.y===e.y}function io(t,e){return{x:t.x+e.x,y:t.y+e.y}}function ot(t){return`${t.x},${t.y}`}var zf={name:"",styles:{}};var Wf=new WeakSet;var iv=new WeakMap;function Ld(t){if(!t||typeof t!=="object")return void 0;const e=iv.get(t);return e&&Wf.has(e.route)?e:void 0}var VI={T:{x:0,y:-1},R:{x:1,y:0},B:{x:0,y:1},L:{x:-1,y:0}};var YI={T:1,R:2,B:4,L:8};var Gf={T:"B",R:"L",B:"T",L:"R"};function Rd(t,e,r,i){e=Id(e);r=Id(r);const n=i.map(c=>Object.freeze({...c}));const o=c=>Number.isSafeInteger(c.x)&&c.x>=0&&c.x<Number.MAX_SAFE_INTEGER&&Number.isSafeInteger(c.y)&&c.y>=0&&c.y<Number.MAX_SAFE_INTEGER;const s=(c,d)=>c?.x===d.x&&c.y===d.y;const a=(c,d,u)=>{const h=VI[u.side];return!!h&&o(u)&&(s(c,u)||s(c,{x:u.x+h.x,y:u.y+h.y}))&&!s(d,{x:c.x-h.x,y:c.y-h.y})};if(e.end!=="start"||r.end!=="end"||!a(n[0],n[1],e)||!a(n.at(-1),n.at(-2),r))throw new Error(`Terminal route ${t} must join both physical ports from outside their endpoints`);for(let c=0;c<n.length;c++){const d=n[c],u=n[c-1];if(!o(d)||u&&Math.abs(d.x-u.x)+Math.abs(d.y-u.y)!==1)throw new Error(`Terminal route ${t} must be a complete contiguous cell path`)}const l=Object.freeze({id:t,source:Object.freeze({...e}),target:Object.freeze({...r}),points:Object.freeze(n)});Wf.add(l);return l}function ss(t,e,r,i,n="solid"){if(!Wf.has(e))throw new TypeError("Terminal routes must come from complete path allocation");r={...r};if(r.kind!=="edge"||r.id!==e.id||r.from!==e.source.nodeId||r.to!==e.target.nodeId)throw new TypeError("Terminal route identity must match its physical endpoints");r=t.element(r);const o=new Map;const s=(d,u)=>{const h=ot(d),m=o.get(h);o.set(h,{...d,mask:(m?.mask??0)|YI[u]})};for(let d=1;d<e.points.length;d++){const u=e.points[d-1],h=e.points[d];const m=h.x>u.x?"R":h.x<u.x?"L":h.y>u.y?"B":"T";s(u,m);s(h,Gf[m])}s(e.points[0],Gf[e.source.side]);s(e.points.at(-1),Gf[e.target.side]);const a=[...o.values()].map(d=>({...d,role:d.mask&10&&d.mask&5?"corner":"line"}));if(!t.strokeBatch(a,{owner:r,ascii:i,style:n}))return false;t.port(r,e.source);t.port(r,e.target);const l=e.points[0],c=e.points.at(-1);if(r.route==="connected"&&l?.x===e.source.x&&l.y===e.source.y&&c?.x===e.target.x&&c.y===e.target.y){t.reserveTerminalPathWitnessWork(3);const d=Object.freeze({});iv.set(d,Object.freeze({route:e,owner:r,width:t.width,height:t.height}));t.registerTerminalPathWitness(r,d)}return true}var Gi=new WeakMap;var av=Symbol("measured terminal text");function mt(t){const e=$t(typeof t==="string"?t:t.join("\n"),true).split("\n");let r=0;const i=e.map(n=>{let o=0;const s=[...ri(n)].flatMap(a=>{const l=ne(a);if(!l)return[];const c=Object.freeze({glyph:a,x:o,width:l});o+=l;return[c]});r=Math.max(r,o);return Object.freeze(s)});return Object.freeze({[av]:true,width:r,height:i.length,emptyRows:Object.freeze(e.flatMap((n,o)=>n.length===0?[o]:[])),lines:Object.freeze(i)})}var vt=Symbol("terminal stroke contributors");var Dt=Symbol("terminal stroke contributions");function Id(t){const e={...t};if(e.boundary)e.boundary=Object.freeze({...e.boundary});if(e.markers)e.markers=Object.freeze(e.markers.map(r=>Object.freeze({...r})));return e}var it=t=>`${t.kind??"node"}\0${t.id}`;var Uf=(t,e)=>it(t)===it(e)||!!(t.bundle&&t.bundle===e.bundle)||!!(t.parent&&it(t.parent)===it(e))||!!(e.parent&&it(e.parent)===it(t));var nv=(t,e)=>e===void 0?void 0:JSON.stringify([t?[t.kind??"node",t.id]:null,e]);var ov=new WeakSet;var Dd=new WeakSet;var $r=Object.freeze([]);Dd.add($r);var HI=["sourceLine","parent","annotationTarget","bundle","from","to","members","route"];function XI(t){if(ov.has(t))return t;const e={...t};if(e.parent)e.parent=Object.freeze({...e.parent});if(e.annotationTarget)e.annotationTarget=Object.freeze({...e.annotationTarget});if(e.members)e.members=Object.freeze([...e.members]);Object.freeze(e);ov.add(e);return e}function KI(t,e){for(const r of HI){const i=e[r];if(i!==void 0&&(r==="members"?JSON.stringify(i)!==JSON.stringify(t[r]):r==="parent"||r==="annotationTarget"?it(i)!==(t[r]?it(t[r]):void 0):i!==t[r]))throw new Error(`Inconsistent terminal element ${e.id}: ${r}`)}}var Wi={"\u2500":10,"\u2502":5,"\u250C":6,"\u2510":12,"\u2514":3,"\u2518":9,"\u251C":7,"\u2524":13,"\u252C":14,"\u2534":11,"\u253C":15,"\u2574":8,"\u2575":1,"\u2576":2,"\u2577":4};var Vf=new Map(Object.entries(Wi).map(([t,e])=>[e,t]));var gn={"\u2504":10,"\u254C":10,"\u2508":10,"\u2501":10,"\u2550":10,"\u2506":5,"\u250A":5,"\u254E":5,"\u2503":5,"\u2551":5,"\u2554":6,"\u2557":12,"\u255A":3,"\u255D":9};var fi={"-":10,"=":10,".":10,"|":5,":":5,"+":15};function Pd(t){if(t.kind==="stroke")return Wi[t.glyph]??gn[t.glyph]??fi[t.glyph]??0;if(t.kind!=="marker"||!t.marker)return 0;if(t.marker.shape==="arrow")return t.marker.direction==="T"||t.marker.direction==="B"?5:10;return t.marker.shape==="wide-circle"||t.marker.shape==="cross"?15:0}function Fd(t,e){if(t.kind!=="stroke"||t[vt]!==t.owners)return 0;const r=t[Dt];return typeof r==="number"?r===(t.stroke?.mask??Wi[t.glyph]??gn[t.glyph]??fi[t.glyph]??0)?r:0:r?.[e]??0}function lv(t,e){const r=t[Dt];return t[vt]===t.owners&&r!==void 0&&(typeof r==="number"?r===e:r.length===t.owners.length)&&e===(t.stroke?.mask??Wi[t.glyph]??gn[t.glyph]??fi[t.glyph]??0)}var JI={">":"<","<":">","\u25BA":"\u25C4","\u25C4":"\u25BA","\u25B6":"\u25C0","\u25C0":"\u25B6","\u250C":"\u2510","\u2510":"\u250C","\u2514":"\u2518","\u2518":"\u2514","\u251C":"\u2524","\u2524":"\u251C","\u256D":"\u256E","\u256E":"\u256D","\u2570":"\u256F","\u256F":"\u2570","\u2574":"\u2576","\u2576":"\u2574","\u2554":"\u2557","\u2557":"\u2554","\u255A":"\u255D","\u255D":"\u255A","\u25C1":"\u25B7","\u25B7":"\u25C1"};var QI={"^":"v",v:"^","\u25B2":"\u25BC","\u25BC":"\u25B2","\u25E4":"\u25E3","\u25E3":"\u25E4","\u25E5":"\u25E2","\u25E2":"\u25E5","\u250C":"\u2514","\u2514":"\u250C","\u2510":"\u2518","\u2518":"\u2510","\u252C":"\u2534","\u2534":"\u252C","\u256D":"\u2570","\u2570":"\u256D","\u256E":"\u256F","\u256F":"\u256E","\u2575":"\u2577","\u2577":"\u2575","\u2554":"\u255A","\u255A":"\u2554","\u2557":"\u255D","\u255D":"\u2557","\u25B3":"\u25BD","\u25BD":"\u25B3"};function Fa(t){const{mask:e,ascii:r=false,style:i="solid"}=t;const n=(e&10)!==0,o=(e&5)!==0;if(r)return n&&o?"+":n?i==="dashed"||i==="dotted"?".":i==="double"||i==="heavy"?"=":"-":i==="dashed"||i==="dotted"?":":"|";if(t.rounded&&!r&&(e===6||e===12||e===3||e===9))return{6:"\u256D",12:"\u256E",3:"\u2570",9:"\u256F"}[e];if(i==="double")return{10:"\u2550",5:"\u2551",6:"\u2554",12:"\u2557",3:"\u255A",9:"\u255D",7:"\u2560",13:"\u2563",14:"\u2566",11:"\u2569",15:"\u256C"}[e]??Vf.get(e)??"\u2500";if(i==="heavy"&&e===10)return"\u2501";if(i==="heavy"&&e===5)return"\u2503";if(i==="dashed"&&e===10)return"\u254C";if(i==="dashed"&&e===5)return"\u250A";if(i==="dotted"&&e===10)return"\u2504";if(i==="dotted"&&e===5)return"\u2506";return Vf.get(e)??"\u253C"}function Nd(t){const e=t.direction??"R",r=["T","R","B","L"].indexOf(e);const i=e==="R",n=e==="R"||e==="L";if(t.shape==="sequence-cross")return"X";if(t.shape==="half-top")return i?t.ascii?"/":"\u25DC":t.ascii?"\\":"\u25DD";if(t.shape==="half-bottom")return i?t.ascii?"\\":"\u25DF":t.ascii?"/":"\u25DE";if(t.shape==="stick-top")return i?"/":"\\";if(t.shape==="stick-bottom")return i?"\\":"/";if(t.shape==="wide-circle")return t.ascii?"o":"\u25EF";if(t.shape==="lollipop")return t.ascii?"O":"\u25CB";if(t.shape==="filled-diamond")return t.ascii?"*":"\u25C6";if(t.shape==="hollow-diamond")return t.ascii?"o":"\u25C7";if(t.shape==="cardinality-one")return n?t.ascii?"|":"\u2502":t.ascii?"-":"\u2500";if(t.shape==="cardinality-many")return(t.ascii?["^",">","v","<"]:["\u2534","\u2562","\u252C","\u255F"])[r];if(t.shape==="circle")return t.ascii?"o":"\u25CB";if(t.shape==="cross")return t.ascii?"x":"\u2715";if(t.shape==="diamond")return t.ascii?"o":"\u25C6";if(t.ascii)return["^",">","v","<"][r];return(t.shape==="open-arrow"?["\u25B3","\u25B7","\u25BD","\u25C1"]:t.shape==="triangle"?["\u25B2","\u25B6","\u25BC","\u25C0"]:["\u25B2","\u25BA","\u25BC","\u25C4"])[r]}function sv(t,e,r){let i=t.direction??"R",n=t.shape;if(e&&(i==="L"||i==="R"))i=i==="L"?"R":"L";if(r&&(i==="T"||i==="B"))i=i==="T"?"B":"T";if(r)n=n==="half-top"?"half-bottom":n==="half-bottom"?"half-top":n==="stick-top"?"stick-bottom":n==="stick-bottom"?"stick-top":n;return Object.freeze({...t,shape:n,direction:i})}function Yf(t){return t.ascii?"#":t.coverage===3?"\u2588":t.axis==="horizontal"?t.coverage===1?"\u258C":"\u2590":t.coverage===1?"\u2584":"\u2580"}function cv(t){return t.marker?Nd(t.marker):t.numericMark?Yf(t.numericMark):t.stroke?Fa(t.stroke):void 0}function jf(t,e,r){if(e)t=t&5|(t&2)<<2|(t&8)>>2;if(r)t=t&10|(t&1)<<2|(t&4)>>2;return t}function yt(t,e){if(!Number.isSafeInteger(t)||t<0)throw new RangeError(`${e} must be a nonnegative integer terminal coordinate`)}function no(t,e){const r=Math.min(t.x,e.x),i=Math.min(t.y,e.y);return{x:r,y:i,width:Math.max(t.x+t.width,e.x+e.width)-r,height:Math.max(t.y+t.height,e.y+e.height)-i}}var Re=class t{width;height;titleHandled=false;diagnostics=[];metrics={writes:0,overlayVisits:0,outputCells:0};rows=new Map;elements=new Map;ownerSets=new Map;singletonOwners=new WeakMap;importedOwners=new WeakMap;canonicalOwners=new WeakSet;ownerKeys=new WeakMap;ownerUnions=new WeakMap;warningFeatures=new WeakMap;declared=new Map;ports=new Map;activeOwner;activeTextBlock;textGroups=new Map;retainedTextBlocks=new Set;diagnosticKeys=new Set;diagnosticIdentities=new WeakMap;lineWidths;emittedWidths;emittedText;emittedColorMode;strokeProvenanceWork=0;constructor(e=0,r=0){yt(e,"width");yt(r,"height");this.width=e;this.height=r}get occupiedCells(){let e=0;for(const r of this.rows.values())e+=r.size;return e}resize(e,r){yt(e,"width");yt(r,"height");this.width=Math.max(this.width,e);this.height=Math.max(this.height,r);this.emittedWidths=void 0}get(e,r){return this.rows.get(r)?.get(e)?.glyph??" "}cell(e,r){return this.rows.get(r)?.get(e)}hasOwner(e,r){return[...this.elements.values()].some(i=>i.id===e&&(r===void 0||i.kind===r))}*entries(){for(const[e,r]of this.rows)for(const[i,n]of r)yield[i,e,n]}attribute(e,r={}){const i=this.owners(Array.isArray(e)?e:[e]);const n=new Set;for(const[,,o]of this.entries()){if(o.textBlock)n.add(o.textBlock);this.attributeStroke(o,i);o.owners=this.unionOwners(o.owners,i);o.owner??=i[0];if(o.kind!=="text"){if(r.role!==void 0)o.role=r.role;if(r.kind!==void 0)o.kind=r.kind}if(r.color!==void 0)o.color=r.color}for(const o of this.retainedTextBlocks)n.add(o);for(const o of n){this.attributeTextAllocations(o,i);if(o.emptyRows)for(const[s,a]of o.emptyRows)o.emptyRows.set(s,this.unionOwners(a,i))}return this}attributeWithin(e,r,i={}){for(const[a,l]of Object.entries({x:r.x,y:r.y,width:r.width,height:r.height}))yt(l,a);for(const[a,l,c]of this.entries()){if(a<r.x||a>=r.x+r.width||l<r.y||l>=r.y+r.height)continue;if(c.head<r.x||c.head+c.width>r.x+r.width)throw new RangeError("terminal attribution bounds must contain complete graphemes")}const n=this.remember(e);const o=this.owners([n]);const s=new Set;for(const[a,l,c]of this.entries()){if(a<r.x||a>=r.x+r.width||l<r.y||l>=r.y+r.height)continue;this.attributeStroke(c,o);c.owners=this.unionOwners(c.owners,o);if(c.textBlock)s.add(c.textBlock);if(i.role!==void 0&&c.kind!=="text")c.role=i.role;if(i.color!==void 0)c.color=i.color}for(const a of this.retainedTextBlocks)s.add(a);for(const a of s){this.attributeTextAllocations(a,o,r);if(a.x<r.x||a.x+a.width>r.x+r.width||!a.emptyRows)continue;for(const[l,c]of a.emptyRows)if(l>=r.y&&l<r.y+r.height)a.emptyRows.set(l,this.unionOwners(c,o))}return this}remember(e){if(!e)return void 0;return this.admitOwners([e])[0]}admitOwners(e){const r=[],i=new Map,n=new WeakMap;for(const o of e){if(this.canonicalOwners.has(o)){r.push(o);continue}const s=n.get(o)??XI(o),a=it(s);n.set(o,s);const l=i.get(a)??this.elements.get(a);if(l)KI(l,s);else i.set(a,s);r.push(l??s)}for(const[o,s]of i){this.elements.set(o,s);this.canonicalOwners.add(s);this.ownerKeys.set(s,o)}return r}element(e){return this.remember(e)}owners(e){if(e===$r)return $r;const r=Array.isArray(e)&&Dd.has(e);const i=r?this.importedOwners.get(e):void 0;if(i)return i;const n=new Map;for(const l of this.admitOwners(e))n.set(this.ownerKeys.get(l),l);if(!n.size)return $r;if(n.size===1){const l=this.singletonOwnerSet(n.values().next().value);if(r)this.importedOwners.set(e,l);return l}const o=[...n.keys()].sort(qt),s=JSON.stringify(o);let a=this.ownerSets.get(s);if(!a){a=Object.freeze(o.map(l=>n.get(l)));Dd.add(a);this.ownerSets.set(s,a);this.importedOwners.set(a,a)}if(r)this.importedOwners.set(e,a);return a}singletonOwnerSet(e){let r=this.singletonOwners.get(e);if(!r){r=Object.freeze([e]);Dd.add(r);this.singletonOwners.set(e,r);this.importedOwners.set(r,r)}return r}paintOwners(e){const r=e.owner??this.activeOwner;if(!r)return e.owners?this.owners(e.owners):$r;if(this.canonicalOwners.has(r)){const i=this.singletonOwnerSet(r);return e.owners?this.unionOwners(this.owners(e.owners),i):i}if(!e.owners)return this.owners([r]);return this.owners([...e.owners,r])}canonicalPaint(e){e={...e};const r=e.owner??this.activeOwner;const i=e.occludedOwners;if(!e.owners&&!i&&(!r||this.canonicalOwners.has(r)))return r===e.owner?e:{...e,owner:r};const n=[...e.owners??[]];const o=this.admitOwners([...n,...r?[r]:[],...i??[]]);const s=n.length+(r?1:0);const a=this.owners(o.slice(0,s));const l=e;return{...e,owner:r?o[n.length]:void 0,owners:a,...l[vt]===e.owners&&a.length===e.owners?.length?{[vt]:a}:{},...i?{occludedOwners:this.owners(o.slice(s))}:{}}}unionOwners(e,r){const i=this.owners(e),n=this.owners(r);if(!i.length||i===n)return n;if(!n.length)return i;let o=this.ownerUnions.get(i);const s=o?.get(n)??this.ownerUnions.get(n)?.get(i);if(s)return s;const a=i.every(l=>n.includes(l))?n:n.every(l=>i.includes(l))?i:this.owners([...i,...n]);if(!o){o=new WeakMap;this.ownerUnions.set(i,o)}o.set(n,a);return a}scope(e,r){const i=this.activeOwner;const n=this.activeTextBlock;this.activeOwner=this.remember(e);this.activeTextBlock=void 0;try{return r()}finally{this.activeOwner=i;this.activeTextBlock=n}}region(e,r){for(const[s,a]of Object.entries({x:r.x,y:r.y,width:r.width,height:r.height}))yt(a,s);if(r.width===0||r.height===0)return;const i=this.remember(e),n=it(i);this.resize(r.x+r.width,r.y+r.height);const o=this.declared.get(n);this.declared.set(n,o?no(o,r):{...r})}port(e,r){r=Id(r);yt(r.x,"port x");yt(r.y,"port y");yt(r.x+1,"width");yt(r.y+1,"height");const i=it(this.remember(e));const n=this.ports.get(i)??[];if(!n.some(o=>o.end===r.end&&o.nodeId===r.nodeId))n.push(r);this.ports.set(i,n);this.resize(r.x+1,r.y+1)}expectMarkers(e,r,i,n=0){const o=this.ports.get(it(this.remember(e)))?.find(s=>s.end===r);if(!o||o.markers)throw new TypeError(`Terminal endpoint ${e.id}/${r} must have one allocated marker contract`);o.markers=Object.freeze(i.map(s=>Object.freeze({...s,direction:s.direction??"R"})));o.markerOffset=n}projectMarkers(e,r){for(const i of this.ports.get(it(this.remember(e)))??[])i.markerProjection=r}assertMarkers(e=()=>{}){let r=false;let i;for(const[d,u]of this.ports)for(const h of u){e();r||=h.markers!==void 0;if(h.markers&&h.markerProjection)(i??=new Set).add(d)}if(!r)return;const n=i?new Set:void 0;let o;const s=new Map;const a=new Map;const l=(d,u,h=false)=>{if(!["node","group","cluster","subgraph"].includes(d.kind??"node"))return;const m=it(d),f=a.get(m);a.set(m,!h&&f?no(f,u):u);const p=s.get(d.id);if(p?.kind==="node"&&d.kind!=="node")return;s.set(d.id,{kind:d.kind,bounds:!h&&p&&p.kind===d.kind?no(p.bounds,u):u})};for(const[d,u,h]of this.entries()){e();if(i?.size&&h.kind==="text"&&h.glyph.trim()){for(const m of h.owners){e();const f=this.ownerKeys.get(m)??it(m);if(i.delete(f))n.add(f);if(!i.size)break}}if(h.kind!=="text")for(const m of h.owners){e();l(m,{x:d,y:u,width:h.width,height:1})}}for(const[d,u]of this.declared){e();l(this.elements.get(d),u,true)}const c=new Map;for(const[d,u]of this.ports){const h=this.elements.get(d);const m=f=>f?.owners.some(p=>{e();return it(p)===d});for(const f of u){e();if(!f.markers)continue;const p=()=>{throw new Error(`Terminal marker contract failed: ${h.id}/${f.end} at ${f.x},${f.y}`)};if(!f.side)p();const g=f.side==="R"?1:f.side==="L"?-1:0;const y=f.side==="B"?1:f.side==="T"?-1:0;const C=c.get(d)??new Set;c.set(d,C);if(f.markerProjection){if(!o){o=new Set;for(const w of this.diagnostics){e();if(w.code==="TERMINAL_FAMILY_PROJECTION")o.add(w.feature)}}if(!o.has(f.markerProjection)||!n.has(d))p();continue}if(f.markers.length&&f.surface!=="lifeline"){const w=f.boundary?a.get(it(f.boundary)):s.get(f.nodeId)?.bounds;if(!w)p();const x=w;const k=g?g>0?f.x-(x.x+x.width-1):x.x-f.x:y>0?f.y-(x.y+x.height-1):x.y-f.y;const b=g?f.y-x.y:f.x-x.x;if(k<0||k>1||b<0||b>=(g?x.height:x.width))p()}for(const[w,x]of f.markers.entries()){e();const k=(f.markerOffset??0)+w;const b=f.x+g*k,A=f.y+y*k,L=this.cell(b,A);C.add(`${b},${A}`);if(b>=(this.lineWidths?.[A]??this.width)||!m(L)||L?.kind!=="marker"||!L.marker||L.marker.shape!==x.shape||(L.marker.direction??"R")!==(x.direction??"R")||!!L.marker.ascii!==!!x.ascii||L.glyph!==Nd(x))p();if(["arrow","triangle","open-arrow","half-top","half-bottom","stick-top","stick-bottom"].includes(x.shape)&&x.direction!=={T:"B",B:"T",L:"R",R:"L"}[f.side])p()}}}if(!c.size)return;for(const[d,u,h]of this.entries()){e();if(h.kind!=="marker")continue;for(const m of h.owners){e();const f=c.get(it(m));if(f&&!f.has(`${d},${u}`))throw new Error(`Unexpected terminal marker: ${m.id} at ${d},${u}`)}}}report(e){this.addDiagnostic(e,this.diagnosticKey(e))}diagnosticKey(e){return this.diagnosticIdentities.get(e)??JSON.stringify(["feature",e.code,e.feature])}addDiagnostic(e,r){if(this.diagnosticKeys.has(r))return;this.diagnosticKeys.add(r);this.diagnosticIdentities.set(e,r);this.diagnostics.push(e)}warn(e,r,i,n){const o=this.owners(r);let s=this.warningFeatures.get(o);if(!s){s={feature:r.map(d=>`${d.kind??"node"}:${d.id}`).sort(qt).join("|"),keys:{}};this.warningFeatures.set(o,s)}const a=s.feature;const l=s.keys[e]??=JSON.stringify(["owners",e,o.map(d=>[d.kind??"node",d.id])]);if(this.diagnosticKeys.has(l))return;const c=e==="TERMINAL_TEXT_COLLISION"?"Text footprints overlap":e==="TERMINAL_ROUTE_OVERLAP"?"Unrelated route runs overlap":"Incompatible occupied geometry overlaps";this.addDiagnostic({code:e,feature:a,cell:{column:i,row:n},message:`${c}; owners: ${r.map(d=>d.id).join(", ")}.`},l)}reserveStrokeProvenance(e){const r=this.strokeProvenanceWork+e;if(!Number.isSafeInteger(r)||r>Wt.maxOperations)throw new RangeError("Terminal stroke provenance exceeds certification ceiling");this.strokeProvenanceWork=r}contribution(e,r,i){if(!e||e[vt]===void 0)return i;if(e[vt]!==e.owners)return 0;const n=e[Dt];if(e.owners.length===1)return it(e.owners[0])===it(r)?typeof n==="number"?n:n?.[0]??0:0;for(let o=0;o<e.owners.length;o++){this.reserveStrokeProvenance(1);if(it(e.owners[o])===it(r))return typeof n==="number"?n:n?.[o]??0}return 0}strokeSnapshot(e,r,i,n,o){if(!e.length)return(o?.stroke?.mask??(o?Wi[o.glyph]??gn[o.glyph]??fi[o.glyph]??0:0))|n;if(r[vt]===void 0&&r.head!==void 0&&r.width!==void 0)return 0;if(!o&&r[vt]===void 0)return n;if(!o&&r[vt]===r.owners&&!r.owners.length)return r[Dt]??0;if(!o&&e.length<=1&&i.length===e.length)return e.length?this.contribution(r,e[0],n):r[Dt]??n;if(!o&&r[vt]===r.owners&&i.length===e.length){let m=true;for(let f=0;f<e.length;f++){this.reserveStrokeProvenance(1);if(it(e[f])!==it(i[f]))m=false}if(m)return r[Dt]??0}if(e.length===1&&(!o||o.owners===e)&&i===e){return this.contribution(o,e[0],0)|this.contribution(r,e[0],n)}if(o&&o[vt]===o.owners&&typeof o[Dt]==="number"){this.reserveStrokeProvenance(1);const m=r[vt]===void 0?n:r[vt]===r.owners?r[Dt]:void 0;if(m===o[Dt])return m}this.reserveStrokeProvenance(e.length+1);const s=[];const a=o&&o[vt]===o.owners?o.owners:$r;const l=r[vt]===void 0||r[vt]===r.owners?i:$r;const c=o?.[Dt],d=r[Dt];let u=0,h=0;for(const m of e){this.reserveStrokeProvenance(1);const f=it(m);let p=0,g=0;if(u<a.length){this.reserveStrokeProvenance(1);if(it(a[u])===f){p=typeof c==="number"?c:c?.[u]??0;u++}}if(h<l.length){this.reserveStrokeProvenance(1);if(it(l[h])===f){g=r[vt]===void 0?n:typeof d==="number"?d:d?.[h]??0;h++}}s.push(p|g)}return Object.freeze(s)}attributeStroke(e,r){if(e.kind!=="stroke")return;const i=this.unionOwners(e.owners,r);if(i===e.owners)return;const n=e.stroke?.mask??Wi[e.glyph]??gn[e.glyph]??fi[e.glyph]??0;const o=e[Dt];const s=typeof o==="number"?o:o?.every(l=>{this.reserveStrokeProvenance(1);return l===n})?n:void 0;if(r.some(l=>{this.reserveStrokeProvenance(1);return l.kind==="edge"&&!e.owners.some(c=>{this.reserveStrokeProvenance(1);return c===l})})&&s===void 0)throw new TypeError("Cannot attribute ambiguous merged stroke to a new edge");if(!e.owners.length){e[vt]=i;e[Dt]=n;return}this.reserveStrokeProvenance(i.length+1);const a=i.map(l=>{this.reserveStrokeProvenance(1);return e.owners.some(c=>{this.reserveStrokeProvenance(1);return c===l})?this.contribution(e,l,0):l.kind==="edge"?s:0});e[vt]=i;e[Dt]=Object.freeze(a)}retire(e,r){const i=this.rows.get(r),n=i?.get(e);if(!i||!n)return;for(let o=n.head;o<n.head+n.width;o++)i.delete(o)}put(e,r,i,n={}){yt(e,"x");yt(r,"y");if(!i)return;if(i===ir)return;i=$t(i,true);if(i.length!==1||If(i)!==1){this.text(e,r,i,n);return}n=this.canonicalPaint(n);const o=n.owner;const s=n.kind??"stroke";if(i===" "&&s==="stroke"&&!o){this.resize(e+1,r+1);return}this.place(e,r,i,1,{...n,owner:o,kind:s},void 0)}admit(e,r,i,n,o,s,a=false){const l=(d,u,h=true)=>d===u||h&&Uf(d,u);const c=(d,u=true)=>d.length>0&&s.length>0&&(d.some(h=>!s.some(m=>l(h,m,u)))||s.some(h=>!d.some(m=>l(m,h,u))));for(let d=0;d<n;d++){const u=this.cell(e+d,r);if(!u)continue;const h=u.head===e+d?u:this.cell(u.head,r);if(a&&(h.kind==="marker"||h.kind==="surface"||h.kind==="mark")&&(!h.owners.length||!s.length)){this.warn("TERMINAL_GEOMETRY_COLLISION",this.unionOwners(h.owners,s),e+d,r);return false}if(h.kind==="text"){const f=c(h.owners,false);if(f)this.warn("TERMINAL_TEXT_COLLISION",this.unionOwners(h.owners,s),e+d,r);if(f||o.kind!=="text")return false;continue}const m=c(h.owners);if(h.kind==="surface"&&m){this.warn("TERMINAL_GEOMETRY_COLLISION",this.unionOwners(h.owners,s),e+d,r);return false}if(h.kind==="marker"){const f=o.kind==="marker"&&h.head===e&&h.width===n&&h.glyph===i;if(!f&&(m||o.kind!=="text"&&o.kind!=="surface")){if(m)this.warn("TERMINAL_GEOMETRY_COLLISION",this.unionOwners(h.owners,s),e+d,r);return false}}if(h.kind==="mark"&&o.kind!=="stroke"&&m){this.warn("TERMINAL_GEOMETRY_COLLISION",this.unionOwners(h.owners,s),e+d,r);return false}if(h.kind==="stroke"&&o.kind==="text"&&m){this.warn("TERMINAL_GEOMETRY_COLLISION",this.unionOwners(h.owners,s),e+d,r);if(a)return false}}return true}place(e,r,i,n,o,s){const a=this.cell(e,r),l=this.paintOwners(o);if(!this.admit(e,r,i,n,o,l))return false;if(!s&&o.kind==="surface"&&a?.kind==="surface"&&a.textBlock&&e>=a.textBlock.x&&e+n<=a.textBlock.x+a.textBlock.width&&this.compatibleTextSurface(a.owners,l))s=a.textBlock;if(a?.kind==="mark"&&o.kind==="stroke"){a.occludedOwners=this.unionOwners(a.occludedOwners??$r,l);return true}let c=l;const d=o.kind==="stroke"?o:void 0;const u=o.kind==="stroke"?o.stroke?.mask??Wi[i]??gn[i]??fi[i]??0:0;const h=o.occludedOwners;let m=h?this.owners(h):void 0;if(a?.kind==="marker"&&o.kind==="marker")c=this.unionOwners(a.owners,l);if(o.kind==="mark"&&a?.kind==="stroke")m=this.unionOwners(this.unionOwners(a.owners,a.occludedOwners??$r),m??$r);if(a?.kind==="stroke"&&o.kind==="stroke"){const y=a.stroke?.mask??Wi[a.glyph]??gn[a.glyph]??fi[a.glyph];const C=o.stroke?.mask??Wi[i]??gn[i]??fi[i];if(o.stroke||a.stroke){const w={...o.stroke??a.stroke,mask:(y??0)|(C??0)};o={...o,stroke:w};i=Fa(w)}else if(y&&C&&y!==C)i=fi[a.glyph]===void 0&&fi[i]===void 0?Vf.get(y|C)??i:"+";c=this.unionOwners(a.owners,l);if(y!==void 0&&y===C&&a.owners.some(w=>l.some(x=>w.kind==="edge"&&x.kind==="edge"&&w.id!==x.id&&!(w.bundle&&w.bundle===x.bundle))))this.warn("TERMINAL_ROUTE_OVERLAP",c,e,r)}const f=d?this.strokeSnapshot(c,d,d.owners??l,u,a?.kind==="stroke"?a:void 0):void 0;for(let y=0;y<n;y++)this.retire(e+y,r);this.resize(e+n,r+1);let p=this.rows.get(r);if(!p){p=new Map;this.rows.set(r,p)}const g={glyph:i,owners:c,head:e,width:n};if(f!==void 0){g[vt]=c;g[Dt]=f}if(o.owner!==void 0)g.owner=o.owner;if(o.role!==void 0)g.role=o.role;if(o.color!==void 0)g.color=o.color;if(o.kind!==void 0)g.kind=o.kind;if(o.textGroup!==void 0)g.textGroup=o.textGroup;if(o.stroke!==void 0)g.stroke=o.stroke;if(o.marker!==void 0)g.marker=o.marker;if(o.numericMark!==void 0)g.numericMark=o.numericMark;if(s)g.textBlock=s;if(m?.length)g.occludedOwners=m;p.set(e,g);for(let y=1;y<n;y++)p.set(e+y,{...g,glyph:ir});if(this.lineWidths?.[r]!==void 0)this.lineWidths[r]=Math.max(this.lineWidths[r],e+n);this.metrics.writes+=n;return true}stroke(e,r,i,n={}){if(!Number.isInteger(i)||i<1||i>15)throw new RangeError("stroke mask must contain terminal cardinal ports");const o=Object.freeze({mask:i,ascii:n.ascii,style:n.style,rounded:n.rounded});this.put(e,r,Fa(o),{...n,kind:"stroke",stroke:o})}strokeBatch(e,r={}){const i={...r};const n=e.map(({x:a,y:l,mask:c,role:d})=>{yt(a,"x");yt(l,"y");yt(a+1,"width");yt(l+1,"height");if(!Number.isInteger(c)||c<1||c>15)throw new RangeError("stroke mask must contain terminal cardinal ports");const u=Object.freeze({mask:c,ascii:i.ascii,style:i.style,rounded:i.rounded});return{x:a,y:l,glyph:Fa(u),stroke:u,role:d}});const o=this.canonicalPaint({...i,kind:"stroke"});const s=n.map(a=>({...a,paint:{...o,...a.role?{role:a.role}:{},stroke:a.stroke}}));if(s.some(a=>!this.admit(a.x,a.y,a.glyph,1,a.paint,this.paintOwners(a.paint),true)))return false;for(const a of s)this.place(a.x,a.y,a.glyph,1,a.paint,void 0);return true}marker(e,r,i,n={}){const o=Object.freeze({...i,direction:i.direction??"R"});this.put(e,r,Nd(o),{...n,kind:"marker",marker:o})}mark(e,r,i,n={}){this.put(e,r,i,{...n,kind:"mark"})}numericMark(e,r,i,n={}){if(i.coverage!==1&&i.coverage!==2&&i.coverage!==3)throw new RangeError("numeric mark coverage must contain one or both half cells");const o=Object.freeze({...i});this.mark(e,r,Yf(o),{...n,numericMark:o})}compatibleTextSurface(e,r){return e.length>0&&r.length>0&&e.every(i=>r.some(n=>Uf(i,n)))&&r.every(i=>e.some(n=>Uf(n,i)))}bindTextSurface(e,r,i){const n=(o,s,a,l)=>{for(let c=s;c<s+l;c++)for(let d=o;d<o+a;d++){const u=this.cell(d,c);if(u?.kind!=="surface"||u.head<e.x||u.head+u.width>e.x+e.width)continue;if(this.compatibleTextSurface(u.owners,r))u.textBlock=e}};if(!i)n(e.x,e.y,e.width,e.height);else{n(e.x,e.y,e.width,i.y-e.y);n(e.x,i.y+i.height,e.width,e.y+e.height-i.y-i.height);n(e.x,i.y,i.x-e.x,i.height);n(i.x+i.width,i.y,e.x+e.width-i.x-i.width,i.height)}}recordEmptyRows(e,r,i,n){if(!i.length)return;e.emptyRows??=new Map;for(const o of i)e.emptyRows.set(r+o,this.unionOwners(e.emptyRows.get(r+o)??$r,n))}attributeTextAllocations(e,r,i){if(!e.allocations)return;e.allocations=e.allocations.map(n=>{if(!i||n.x>=i.x&&n.y>=i.y&&n.x+n.text.width<=i.x+i.width&&n.y+n.text.height<=i.y+i.height)return{...n,owners:this.unionOwners(n.owners,r)};if(n.x+n.text.width<=i.x||n.x>=i.x+i.width||n.y+n.text.height<=i.y||n.y>=i.y+i.height)return n;return{...n,attributions:[...n.attributions??[],{bounds:{...i},owners:r}]}})}movedTextBlock(e,r,i){const n=r-e.x,o=i-e.y;return{...e,x:r,y:i,...e.allocations?{allocations:e.allocations.map(s=>({...s,x:s.x+n,y:s.y+o,owners:this.owners(s.owners),...s.attributions?{attributions:s.attributions.map(a=>({owners:this.owners(a.owners),bounds:{...a.bounds,x:a.bounds.x+n,y:a.bounds.y+o}}))}:{}}))}:{},...e.emptyRows?{emptyRows:new Map([...e.emptyRows].map(([s,a])=>[s+i-e.y,this.owners(a)]))}:{}}}textBlock(e,r,i,n={}){yt(e,"x");yt(r,"y");const o=typeof i==="object"&&av in i?i:mt(i);n=this.canonicalPaint(n);const s=n.owner,a=this.paintOwners(n);const l={...n,owner:s,kind:"text",role:n.role===void 0?"text":n.role};for(let p=0;p<o.height;p++)for(let g=0;g<o.width;g++)if(!this.admit(e+g,r+p," ",1,l,a,true))return void 0;const c={x:e,y:r,width:o.width,height:o.height};const d=nv(s,n.textGroup);const u=s!==void 0&&s===this.activeOwner;let h=d===void 0?u?this.activeTextBlock:void 0:this.textGroups.get(d);const m=h?{...h}:void 0;if(h)Object.assign(h,no(h,c));else{h={...c};if(u)this.activeTextBlock=h;if(d!==void 0)this.textGroups.set(d,h)}this.retainedTextBlocks.add(h);(h.allocations??=[]).push({x:e,y:r,text:o,owners:a});this.bindTextSurface(h,a,m);const f={...n,owner:s,kind:"surface"};for(let p=0;p<o.height;p++){let g=0;for(const y of o.lines[p]){this.place(e+y.x,r+p,y.glyph,y.width,l,h);g=y.x+y.width}for(let y=g;y<o.width;y++)this.place(e+y,r+p," ",1,f,h)}this.recordEmptyRows(h,r,o.emptyRows,a);this.resize(e+o.width,r+o.height);return Object.freeze({...c,text:o})}text(e,r,i,n={}){yt(e,"x");yt(r,"y");n=this.canonicalPaint(n);const o=n.owner;const s=mt(i);const a={x:e,y:r,width:s.width,height:s.height};const l=n.kind??"text";const c=l==="text"&&o!==void 0&&o===this.activeOwner;const d=nv(o,n.textGroup);let u=d===void 0?c?this.activeTextBlock:void 0:this.textGroups.get(d);const h=u?{...u}:void 0;if(u)Object.assign(u,no(u,a));else{u={...a};if(c)this.activeTextBlock=u;if(d!==void 0)this.textGroups.set(d,u)}const m=this.paintOwners({...n,owner:o});if(l==="text"){this.retainedTextBlocks.add(u);(u.allocations??=[]).push({x:e,y:r,text:s,owners:m});this.bindTextSurface(u,m,h)}const f={...n,owner:o,role:n.role===void 0?"text":n.role,kind:l};let p=false;s.lines.forEach((g,y)=>{for(const C of g)p=this.place(e+C.x,r+y,C.glyph,C.width,f,l==="text"?u:void 0)||p});if(l==="text"&&(p||s.lines.every(g=>g.length===0)))this.recordEmptyRows(u,r,s.emptyRows,m);this.resize(e+a.width,r+a.height);return a}fill(e,r,i,n,o={}){for(const[a,l]of Object.entries({x:e,y:r,width:i,height:n}))yt(l,a);const s={...this.canonicalPaint(o),kind:"surface"};for(let a=r;a<r+n;a++)for(let l=e;l<e+i;l++)this.place(l,a," ",1,s,void 0)}line(e=[],r){r=r?{...r}:void 0;const i=e.map(d=>{d={...d};const u=d.owner??r?.owner;return r?{...r,...d,owner:u,textGroup:d.textGroup??r.textGroup,kind:d.kind??r.kind??(d.role==="text"?"text":d.role==null?"surface":"stroke")}:d});const n=i.map(d=>({paint:d,owner:d.owner??this.activeOwner,owners:[...d.owners??[]]}));const o=this.admitOwners(n.flatMap(d=>[...d.owners,...d.owner?[d.owner]:[]]));let s=0;const a=n.map(({paint:d,owner:u,owners:h})=>{const m=h.length+(u?1:0),f=o.slice(s,s+m);const p=u?f[h.length]:void 0;s+=m;return{...d,owner:p,owners:this.owners(f),...r?{textGroup:d.textGroup??p?.id}:{}}});const l=this.height;this.lineWidths??=Array.from({length:this.height},()=>this.width);let c=0;for(const[d,u]of i.entries()){const h=a[d];this.text(c,l,u.text,h);c+=ne(u.text)}this.resize(c,l+1);this.lineWidths[l]=c}hasTerminalPathWitnessState(){return Gi.has(this)}reserveTerminalPathWitnessWork(e){if(!Number.isSafeInteger(e)||e<0)throw new RangeError("Invalid terminal path witness reservation");const r=Gi.get(this),i=(r?.work??3)+e;if(!Number.isSafeInteger(i)||i>Wt.maxOperations)throw new RangeError("Terminal path witness reservation exceeds certification ceiling");if(r)r.work=i;else Gi.set(this,{work:i,witnesses:new Map})}registerTerminalPathWitness(e,r,i=0,n=0){this.reserveTerminalPathWitnessWork(1);const o=Ld(r);if(!o||e.kind!=="edge"||e.route!=="connected"||e.id!==o.owner.id||e.from!==o.owner.from||e.to!==o.owner.to)return;const s=it(e),a=this.elements.get(s);if(!a||a.route!=="connected"||a.from!==e.from||a.to!==e.to)return;const l=Gi.get(this);if(l.witnesses.has(s)){this.reserveTerminalPathWitnessWork(1);l.witnesses.set(s,null);return}this.reserveTerminalPathWitnessWork(1);if(!Number.isSafeInteger(i)||!Number.isSafeInteger(n)||!Number.isSafeInteger(i+o.width)||!Number.isSafeInteger(n+o.height)||i<0||n<0)return;const c=this.ports.get(s)??[];if(c.length!==2)return;let d=0,u=0;for(const h of c){this.reserveTerminalPathWitnessWork(1);const m=h.end==="start"?o.route.source:o.route.target;if(h.end!==m.end||h.nodeId!==m.nodeId||h.side!==m.side||h.x!==m.x+i||h.y!==m.y+n||h.markerProjection||h.boundary?.id!==m.boundary?.id||h.boundary?.kind!==m.boundary?.kind)return;if(h.end==="start")d++;else u++}if(d!==1||u!==1)return;this.reserveTerminalPathWitnessWork(2);l.witnesses.set(s,Object.freeze({owner:a,token:r,dx:i,dy:n}))}blank(){return new t(this.width,this.height)}overlay(e,r=0,i=0){yt(r,"offset x");yt(i,"offset y");this.admitOwners(e.elements.values());this.resize(r+e.width,i+e.height);this.titleHandled||=e.titleHandled;if(e.lineWidths){this.lineWidths??=Array.from({length:this.height},()=>this.width);for(let c=0;c<e.height;c++)this.lineWidths[c+i]=Math.max(this.lineWidths[c+i]??0,r+(e.lineWidths[c]??e.width))}const n=new Map;const o=new Map;const s=new Map;const a=new Set;for(const[c,d]of e.rows)for(const[u,h]of d){if(!h.textBlock||h.glyph===ir)continue;const m=o.get(h.textBlock)??[];m.push({x:u,y:c,cell:h});o.set(h.textBlock,m)}for(const[c,d]of e.rows)for(const[u,h]of d){if(h.glyph===ir)continue;this.metrics.overlayVisits++;let m;if(h.textBlock){if(!s.has(h.textBlock))s.set(h.textBlock,o.get(h.textBlock).every(p=>{const g={...p.cell,owner:this.remember(p.cell.owner??this.activeOwner)};return this.admit(p.x+r,p.y+i,p.cell.glyph,p.cell.width,g,this.paintOwners(g),true)}));if(!s.get(h.textBlock))continue;m=n.get(h.textBlock);if(!m){m=this.movedTextBlock(h.textBlock,h.textBlock.x+r,h.textBlock.y+i);n.set(h.textBlock,m)}}const f=this.remember(h.owner??this.activeOwner);if(m&&!h.owner&&this.activeOwner){if(!a.has(h.textBlock)){this.attributeTextAllocations(m,this.paintOwners({owner:this.activeOwner}));a.add(h.textBlock)}if(this.activeTextBlock&&this.activeTextBlock!==m){Object.assign(this.activeTextBlock,no(this.activeTextBlock,m));if(m.allocations)(this.activeTextBlock.allocations??=[]).push(...m.allocations);if(m.emptyRows)for(const[p,g]of m.emptyRows)this.recordEmptyRows(this.activeTextBlock,p,[0],this.unionOwners(g,this.paintOwners({owner:this.activeOwner})))}else if(!this.activeTextBlock){this.activeTextBlock=m;if(m.emptyRows)for(const[p,g]of m.emptyRows)m.emptyRows.set(p,this.unionOwners(g,this.paintOwners({owner:this.activeOwner})))}m=this.activeTextBlock;n.set(h.textBlock,m)}if(m)this.retainedTextBlocks.add(m);if(!this.place(u+r,c+i,h.glyph,h.width,{...h,owner:f},m))continue}for(const c of e.retainedTextBlocks)if(!o.has(c)){const d=this.movedTextBlock(c,c.x+r,c.y+i);if(this.activeOwner)this.attributeTextAllocations(d,this.paintOwners({owner:this.activeOwner}));this.retainedTextBlocks.add(d)}for(const c of e.elements.values())this.remember(c);for(const[c,d]of e.declared)this.region(e.elements.get(c),{...d,x:d.x+r,y:d.y+i});for(const[c,d]of e.ports)for(const u of d)this.port(e.elements.get(c),{...u,x:u.x+r,y:u.y+i});this.reserveStrokeProvenance(e.strokeProvenanceWork);const l=Gi.get(e);if(l){this.reserveTerminalPathWitnessWork(l.work);for(const[c,d]of l.witnesses){this.reserveTerminalPathWitnessWork(1);if(!d)Gi.get(this).witnesses.set(c,null);else this.registerTerminalPathWitness(d.owner,d.token,d.dx+r,d.dy+i)}}for(const c of e.diagnostics)this.addDiagnostic(c.cell?{...c,cell:{column:c.cell.column+r,row:c.cell.row+i}}:c,e.diagnosticKey(c))}flip(e,r){const i=Gi.get(this);if(i&&(e||r)){for(const f of i.witnesses)this.reserveTerminalPathWitnessWork(1);this.reserveTerminalPathWitnessWork(1);i.witnesses.clear()}const n=this.lineWidths;const o=new Map;if(n&&r&&!e)for(let f=0;f<this.height;f++){let p=0;for(const y of this.rows.get(f)?.keys()??[])p=Math.max(p,y+1);const g=n[f]??this.width;if(g>p)o.set(this.height-1-f,g)}this.lineWidths=void 0;const s=new Map;const a=new Map;for(const f of this.retainedTextBlocks)a.set(f,this.movedTextBlock(f,e?this.width-f.x-f.width:f.x,r?this.height-f.y-f.height:f.y));this.retainedTextBlocks=new Set(a.values());const l=[];const c=this.diagnostics.length;const d=new Set(this.diagnostics.flatMap(f=>f.cell?[`${f.cell.column},${f.cell.row}`]:[]));const u=new Map;for(const[f,p]of this.rows)for(const[g,y]of p){if(y.glyph===ir)continue;let C=e?this.width-y.width-g:g;let w=r?this.height-1-f:f;let x;let k=y.glyph;let b=y.stroke,A=y.marker,L=y.numericMark;const B=y.textBlock;if((y.kind==="text"||y.kind==="surface")&&B){const E=B;x=a.get(E);if(!x){x=this.movedTextBlock(E,e?this.width-E.x-E.width:E.x,r?this.height-E.y-E.height:E.y);a.set(E,x)}C=x.x+g-E.x;w=x.y+f-E.y}else if(b){b=Object.freeze({...b,mask:jf(b.mask,e,r)});k=Fa(b)}else if(A){A=sv(A,e,r);k=Nd(A)}else if(L){if(L.axis==="horizontal"&&e||L.axis==="vertical"&&r)L=Object.freeze({...L,coverage:L.coverage===1?2:L.coverage===2?1:3});k=Yf(L)}else{if(e)k=JI[k]??k;if(r)k=QI[k]??k}const O={...y,glyph:k,head:C,...b?{stroke:b}:{},...A?{marker:A}:{},...L?{numericMark:L}:{},...x?{textBlock:x}:{}};const M=y[Dt];if(M!==void 0){if(typeof M==="number")O[Dt]=jf(M,e,r);else{this.reserveStrokeProvenance(M.length*2+1);O[Dt]=Object.freeze(M.map(E=>jf(E,e,r)))}}l.push({x:C,y:w,cell:O,...x?{block:x}:{}});for(let E=0;d.size>0&&E<y.width;E++){const _=`${g+E},${f}`;if(d.has(_))u.set(_,{column:C+E,row:w})}}this.rows=s;for(const f of this.declared.values()){if(e)f.x=this.width-f.x-f.width;if(r)f.y=this.height-f.y-f.height}for(const f of this.ports.values())for(const p of f){if(e){p.x=this.width-1-p.x;if(p.side==="L")p.side="R";else if(p.side==="R")p.side="L"}if(r){p.y=this.height-1-p.y;if(p.side==="T")p.side="B";else if(p.side==="B")p.side="T"}if(p.markers)p.markers=Object.freeze(p.markers.map(g=>sv(g,e,r)))}for(let f=0;f<c;f++){const p=this.diagnostics[f];if(p.cell){const g={...p,cell:u.get(`${p.cell.column},${p.cell.row}`)??{column:e?this.width-1-p.cell.column:p.cell.column,row:r?this.height-1-p.cell.row:p.cell.row}};this.diagnosticIdentities.set(g,this.diagnosticKey(p));this.diagnostics[f]=g}}const h=new Map;const m=this.activeOwner;this.activeOwner=void 0;try{for(const f of l)if(!f.block&&f.cell.kind==="surface")this.place(f.x,f.y,f.cell.glyph,f.cell.width,f.cell,void 0);for(const f of l){if(f.block){const p=h.get(f.block)??[];p.push(f);h.set(f.block,p)}else if(f.cell.kind!=="surface")this.place(f.x,f.y,f.cell.glyph,f.cell.width,f.cell,void 0)}for(const[f,p]of h){if(!p.every(g=>this.admit(g.x,g.y,g.cell.glyph,g.cell.width,g.cell,this.paintOwners(g.cell),true)))continue;for(const g of p)this.place(g.x,g.y,g.cell.glyph,g.cell.width,g.cell,f)}}finally{this.activeOwner=m}this.activeTextBlock=void 0;this.textGroups.clear();this.emittedWidths=void 0;if((e||r)&&n)this.lineWidths=Array.from({length:this.height},(f,p)=>{let g=o.get(p)??0;for(const y of this.rows.get(p)?.keys()??[])g=Math.max(g,y+1);return g});else this.lineWidths=n}serialize(e={}){this.assertMarkers();this.metrics.outputCells=0;const r=e.colorMode??"none",i=e.theme??Pr;const n=[],o=[];for(let s=0;s<this.height;s++){const a=this.lineWidths?.[s]??this.width;let l=a;if(e.trimEnd)while(l>0&&this.get(l-1,s)===" "&&this.cell(l-1,s)?.kind!=="text")l--;o.push(l);if(r==="none"){let f="";const p=this.rows.get(s);for(let g=0;g<l;g++){const y=p?.get(g)?.glyph??" ";if(y!==ir)f+=y}n.push($t(f));this.metrics.outputCells+=l;continue}let c="",d="",u,h;const m=()=>{if(!d)return;c+=h?rv(d,h,r):tv([d],[u??null],i,r);d=""};for(let f=0;f<l;f++){const p=this.cell(f,s),g=p?.glyph??" ";if(g===ir)continue;if(g===" "){m();c+=" ";u=void 0;h=void 0;continue}const y=p?.role??null,C=p?.color;if(y!==u||C!==h){m();u=y;h=C}d+=g}m();n.push(c);this.metrics.outputCells+=l}if(e.trimEnd)while(n.length>0&&o.at(-1)===0){n.pop();o.pop()}this.emittedWidths=o;this.emittedColorMode=r;return this.emittedText=n.join("\n")}layoutEvidence(){const e=this;return{width:this.width,height:this.height,emittedWidths:this.emittedWidths,emittedText:this.emittedText,colorMode:this.emittedColorMode,owners:this.elements.values(),pathWitnessWork:Gi.get(this)?.work??0,strokeProvenanceWork:this.strokeProvenanceWork,pathWitnesses:Gi.get(this)?.witnesses.values(),declarations:(function*(){for(const[r,i]of e.declared)yield[e.elements.get(r),i]})(),ports:(function*(){for(const[r,i]of e.ports)for(const n of i)yield[e.elements.get(r),n]})(),textAllocations:(function*(){for(const r of e.retainedTextBlocks)for(const i of r.allocations??[])yield i})()}}regions(){const e=new Map;const r=s=>{const a=it(s);let l=e.get(a);if(!l){l={owner:s,cells:[],occluded:[]};e.set(a,l)}return l};for(const[s,a]of this.rows)for(const[l,c]of a){if(this.emittedWidths&&(s>=this.emittedWidths.length||l>=this.emittedWidths[s]))continue;for(const d of c.owners)r(d).cells.push({x:l,y:s,cell:c});if(c.occludedOwners){for(const d of c.occludedOwners)if(!c.owners.some(u=>it(u)===it(d)))r(d).occluded.push({x:l,y:s,cell:c})}}for(const[s]of this.declared)if(!e.has(s))r(this.elements.get(s));const i=[];const n=(s,a)=>s.y-a.y||s.x-a.x;const o=s=>{const a=[];for(const{x:l,y:c}of s){const d=a.at(-1);if(d&&d.row===c&&d.end===l)d.end++;else a.push({row:c,start:l,end:l+1})}return a};for(const[s,{owner:a,cells:l,occluded:c}]of e){const d=l.sort(n);const u=d.filter(x=>x.cell.kind==="text");const h=u[0]?.cell.textBlock;const m=h?u.filter(x=>x.cell.textBlock===h):u;const f=l.length===0?c:a.kind==="edge"?l:m.length>0?m:l;const p=this.declared.get(s);if(f.length===0&&!p)continue;let g=p??f.reduce((x,k)=>{const b={x:k.x,y:k.y,width:1,height:1};return x?no(x,b):b},void 0);const y=m.filter(({cell:x})=>x.glyph!==ir);const C=new Map;for(const[x,k]of h?.emptyRows??[])if(k.some(b=>it(b)===s))C.set(x,"");for(const x of y)C.set(x.y,(C.get(x.y)??"")+x.cell.glyph);const w=[...C].sort(([x],[k])=>x-k).map(([,x])=>x).join("\n");if(!p&&C.size){let x=g.y,k=g.y+g.height;for(const b of C.keys()){x=Math.min(x,b);k=Math.max(k,b+1)}g={...g,y:x,height:k-x}}i.push({id:a.id,kind:a.kind??"node",...a.sourceLine===void 0?{}:{sourceLine:a.sourceLine},...a.parent===void 0?{}:{parentId:a.parent.id,parentKind:a.parent.kind},...a.annotationTarget===void 0?{}:{annotationTarget:a.annotationTarget},...a.members===void 0?{}:{members:a.members},...a.from===void 0?{}:{from:a.from},...a.to===void 0?{}:{to:a.to},...a.bundle===void 0?{}:{bundle:a.bundle},...this.ports.has(s)?{ports:this.ports.get(s).map(x=>({...x}))}:{},canvasRow:g.y,canvasColStart:g.x,canvasColEnd:g.x+g.width,...g.height>1?{rowSpan:g.height}:{},...y.length===0?{}:{projectedText:w,authoredTextCells:y.map(({x,y:k,cell:b})=>({row:k,column:x,glyph:b.glyph}))},ownedCellSpans:o(d),...c.length?{occludedCellSpans:o(c.sort(n))}:{}})}return i.sort((s,a)=>s.canvasRow-a.canvasRow||s.canvasColStart-a.canvasColStart||qt(s.id,a.id))}};var dv=new WeakMap;function uv(t,e){if(e)dv.set(t,e)}function wz(t){return dv.get(t)}function qr(t,e={}){const r=bt(t,e.display??"literal",e.transform);const i=e.maxWidth&&Number.isFinite(e.maxWidth)&&e.maxWidth>0?Math.max(1,Math.floor(e.maxWidth)):Infinity;const n=[],o=[];for(const[a,l]of r.lines.entries()){if(a>0)o.push({kind:"authored",sourceOffset:r.lineStarts[a]-1});const c=l.map(g=>g.text).join("");if(ne(c)<=i){n.push(c);continue}const d=ri(c);const u=l.flatMap(g=>g.clusters??[{text:g.text,sourceStart:g.sourceStart,sourceEnd:g.sourceEnd}]);const h=[];let m=0,f=0;for(const g of d){h.push(u[m].sourceStart);let y=g.length;while(y>0){const C=Math.min(y,u[m].text.length-f);y-=C;f+=C;if(f===u[m].text.length){m++;f=0}}}let p=0;while(p<d.length){let g=p,y=0,C=-1;while(g<d.length&&y+ne(d[g])<=i){y+=ne(d[g]);if(/\s/u.test(d[g]))C=g+1;g++}if(g===d.length){n.push(d.slice(p).join(""));break}if(g>p&&!/\s/u.test(d[g-1])&&/\s/u.test(d[g]??"")){C=g;while(C<d.length&&/\s/u.test(d[C]))C++}let w=g,x,k=false;if(C>p){if(d.slice(p,C).some(b=>!/\s/u.test(b)))while(C<d.length&&/\s/u.test(d[C]))C++;g=C;w=g;while(w>p&&/\s/u.test(d[w-1]))w--;if(w===p)w=g;else x=d.slice(w,g).join("")}else{g=Math.max(p+1,g);const b=A=>e.hyphenate!==false&&A<d.length&&!(ne(d[A-1])===2&&ne(d[A])===2);while(g>p+1&&b(g)&&ne(d.slice(p,g).join(""))+1>i)g--;w=g;k=b(g)&&ne(d.slice(p,g).join(""))+1<=i}n.push(d.slice(p,w).join("")+(k?"-":""));if(g<d.length)o.push(Object.freeze({kind:k?"hyphen":"wrap",sourceOffset:h[g],...x?{replacedText:x}:{}}));p=g}}const s=n.map(ne);o.forEach(Object.freeze);return Object.freeze({unit:"cell",prepared:r,lines:Object.freeze(n),lineWidths:Object.freeze(s),breaks:Object.freeze(o),width:s.reduce((a,l)=>Math.max(a,l),0),height:n.length})}function ve(t,e,r){return[...qr(t,{maxWidth:e,...r}).lines]}function as(t){const e=new Map;for(const{id:r,side:i}of t){const n=e.get(r)??{T:0,R:0,B:0,L:0};n[i]++;e.set(r,n)}for(const r of e.values())Object.freeze(r);return e}function Ui(t){return t?{width:Math.max(t.T,t.B)*3+2,height:Math.max(t.L,t.R)*3+2}:{width:0,height:0}}function ji(t,e,r,i){if(![t.x,t.y,t.width,t.height].every(a=>Number.isSafeInteger(a)&&a>=0))throw new RangeError("Terminal port allocation needs an integer card rectangle");const n=e==="T"||e==="B"?t.width:t.height;if(!Number.isSafeInteger(i)||i<1||!Number.isSafeInteger(r)||r<0||r>=i||n<i*3+2)throw new RangeError("Terminal card face has insufficient allocated port capacity");const o=Math.floor((r+1)*(n-1)/(i+1));const s=e==="T"?{x:t.x+o,y:t.y-1}:e==="B"?{x:t.x+o,y:t.y+t.height}:e==="L"?{x:t.x-1,y:t.y+o}:{x:t.x+t.width,y:t.y+o};if(!Number.isSafeInteger(s.x)||s.x<0||!Number.isSafeInteger(s.y)||s.y<0)throw new RangeError("Terminal port must have nonnegative integer coordinates");return Object.freeze({...s,side:e})}function Et(t,e,r,i,n=false,o){r=t.element(r);if(e.width<2||e.height<2)throw new RangeError("Terminal frames need room for opposite borders");t.region(r,e);if(n)t.fill(e.x,e.y,e.width,e.height,{owner:r,kind:"surface"});const s={owner:r,role:"border",ascii:i};const a=(l,c,d)=>{if(!o?.(l,c))t.stroke(l,c,d,s)};for(let l=e.x+1;l<e.x+e.width-1;l++){a(l,e.y,10);a(l,e.y+e.height-1,10)}for(let l=e.y+1;l<e.y+e.height-1;l++){a(e.x,l,5);a(e.x+e.width-1,l,5)}a(e.x,e.y,6);a(e.x+e.width-1,e.y,12);a(e.x,e.y+e.height-1,3);a(e.x+e.width-1,e.y+e.height-1,9)}function hv(t,e){return t.fromX===t.toX?t.x:Math.min(t.fromX,t.toX)+Math.floor((Math.abs(t.toX-t.fromX)-ne(e))/2)}function mv(t,e,r,i,n={},o,s){const a=Xy(t.split("\n").map(l=>l.trim()).filter(l=>l&&!l.startsWith("%%")),{...n,...s?{authoredLine:s}:{}});return Xf(a,e,r,i,n,o)}function Xf(t,e,r,i,n={},o){o??=e.targetWidth??e.maxWidth;const s=t.title===void 0&&e.title!==void 0?{...t,title:Ot(e.title)}:t;if(!s.actors.length&&!s.blocks.length){const z=new Re;if(s.title)for(const F of ve(bt(Ye(s.title,s.titleContent)),o))z.line([{text:F,owner:{id:"title",kind:"label"},role:"text"}]);return Fe(z,{colorMode:r,theme:i,trimEnd:true})}const a=kt([...s.actors.map(z=>z.id),...[...s.messages,...s.blocks,...s.notes].flatMap(z=>z.id===void 0?[]:[z.id])]);const l=z=>s.blocks[z].id??a(`block:${z}`);const c=e.useAscii;const d=new Map(s.actors.map((z,F)=>[z.id,F]));const u=o===void 0?void 0:Math.max(1,Math.floor(o/3));const h=(z,F)=>ve(bt(z),F===false?void 0:F?Math.min(u??40,40):u);const m=s.actors.map(z=>{const F=bt(Ye(z.label,z.labelContent));return h(z.type==="participant"||z.type==="actor"?F:cl([`\xAB${z.type}\xBB
185
+ `,F]),z.wrap)});const f=s.messages.map(z=>h(Qy(z),z.wrap));const p=s.notes.map(z=>h(Ye(z.text,z.textContent),z.wrap));const g=s.blocks.map(z=>h(z.label?cl([`${z.type} [`,bt(Ye(z.label,z.labelContent)),"]"]):z.type,z.wrap));const y=s.blocks.map(z=>z.dividers.map(F=>F.label?h(cl(["[",bt(Ye(F.label,F.labelContent)),"]"]),F.wrap):[""]));const C=m.map(z=>Math.max(0,...z.map(ne))+4);const w=(s.boxes??[]).map(z=>z.label?h(Ye(z.label,z.labelContent),z.wrap):[]);s.boxes?.forEach((z,F)=>{const Z=s.actors.flatMap((be,Ce)=>be.box===F?[Ce]:[]);if(Z.length!==1)return;const ue=Z[0];C[ue]=Math.max(C[ue],...w[F].map(be=>ne(be)+2))});const x=s.boxes?.length?Math.max(1,...w.map(z=>z.length))+1:0;const k=C.map(z=>Math.ceil(z/2));const b=s.actors.length?Math.max(3,...m.map(z=>z.length+2)):0;const A=new Array(Math.max(0,s.actors.length-1)).fill(0);s.messages.forEach((z,F)=>{const Z=d.get(z.from),ue=d.get(z.to);const be=Math.max(0,...f[F].map(ne));if(Z===ue){if(Z<A.length)A[Z]=Math.max(A[Z],be+5)}else{for(let Ce=Math.min(Z,ue);Ce<Math.max(Z,ue);Ce++)A[Ce]=Math.max(A[Ce],Math.ceil((be+4)/Math.abs(ue-Z)))}});s.boxes?.forEach((z,F)=>{const Z=s.actors.flatMap((Le,Qe)=>Le.box===F?[Qe]:[]);if(Z.length<2)return;const ue=Math.min(...Z),be=Math.max(...Z);const Ce=Math.max(0,...w[F].map(ne));for(let Le=ue;Le<be;Le++)A[Le]=Math.max(A[Le],Math.ceil((Ce+4)/(be-ue)))});let L=k[0]??4;s.notes.forEach((z,F)=>{const Z=d.get(z.actorIds[0])??0;const ue=d.get(z.actorIds.at(-1))??Z;const be=Math.max(0,...p[F].map(ne))+4;if(z.position==="left"){if(Z===0)L=Math.max(L,be+1);else A[Z-1]=Math.max(A[Z-1],be+1)}else if(z.position==="right"){if(Z<A.length)A[Z]=Math.max(A[Z],be+2)}else if(Z!==ue){for(let Ce=Math.min(Z,ue);Ce<Math.max(Z,ue);Ce++)A[Ce]=Math.max(A[Ce],Math.ceil((be+2)/Math.abs(Z-ue)))}else if(Z===0)L=Math.max(L,Math.floor(be/2))});const B=Hb(s);const O=new Map;B.forEach((z,F)=>z.childBlockIndices.forEach(Z=>O.set(Z,F)));const M=z=>O.has(z)?1+M(O.get(z)):1;const E=Math.max(0,...s.blocks.map((z,F)=>M(F)));if(E)L+=E*4;const _=[L];for(let z=1;z<s.actors.length;z++)_[z]=_[z-1]+Math.max(k[z-1]+k[z]+(s.actors[z-1].box!==s.actors[z].box?4:2),A[z-1]+2,10);const q=s.messages.map((z,F)=>{const Z=_[d.get(z.from)],ue=_[d.get(z.to)];const be=Math.max(0,...f[F].map(ne));const Ce=Z===ue?Z+6:Math.min(Z,ue)+Math.floor((Math.abs(ue-Z)-be)/2);const Le=Math.min(Z,ue,Ce);return{x:Le,width:Math.max(Z,ue,Ce+be-1)-Le+1}});const Q=s.notes.map((z,F)=>{const Z=Math.max(0,...p[F].map(ne))+4;const ue=_[d.get(z.actorIds[0])??0],be=_[d.get(z.actorIds.at(-1))??0];const Ce=z.position==="left"?ue-Z-1:z.position==="right"?ue+2:Math.floor((ue+be)/2)-Math.floor(Z/2);return{x:Math.max(0,Ce),width:Z}});const $=new Map;const D=z=>{const F=$.get(z);if(F)return F;const Z=B[z],ue=s.blocks[z];const be=[...q.slice(ue.startIndex,Z.endMessageExclusive),...Z.noteIndices.map(et=>Q[et]),...Z.childBlockIndices.map(D)];const Ce=Math.max(0,(be.length?Math.min(...be.map(et=>et.x)):_[0])-4);const Le=be.length?Math.max(...be.map(et=>et.x+et.width)):_.at(-1);const Qe=Math.max(0,...g[z].map(ne),...y[z].flatMap(et=>et.map(ne)));const lt={x:Ce,width:Math.max(Le+4-Ce,Qe+2)+(ue.type==="par_over"?Qe:0)};$.set(z,lt);return lt};const P=[];const U=[];const j=new Map;const G=[];const se=[];const ce=new Map;const ae=()=>se.length?l(se.at(-1)):void 0;let Y=x+b;const V=new Map;const N=new Map;const J=z=>{let F=0;const Z=[...N.values()].flatMap(ue=>ue.prior);for(let ue=0;ue<=Z.length;ue++){const be=Z.find(Ce=>z.x<Ce.x+Ce.width+1&&z.x+z.width+1>Ce.x&&z.y+F<Ce.y+Ce.height+1&&z.y+z.height+F+1>Ce.y);if(!be)break;F=be.y+be.height+1-z.y}return F};const ee=z=>{let F={...z};for(const[ue,be]of N){if(be.pending===void 0)continue;const Ce=j.get(ue).dividers[be.pending];const Le=Ce.lines.length?Ce.lines.length+1:0;F={x:F.x,y:F.y-Le,width:Math.max(F.width,...Ce.lines.map(ne)),height:F.height+Le}}const Z=J(F);for(const[ue,be]of N){if(be.pending===void 0)continue;const Ce=j.get(ue).dividers[be.pending];Ce.x=z.x;Ce.y=z.y+Z-Ce.lines.length-1;if(Ce.lines.length)X({x:Ce.x,y:Ce.y,width:Math.max(...Ce.lines.map(ne)),height:Ce.lines.length});delete be.pending}return Z};const X=z=>{for(const F of se){const Z=V.get(F)??[];Z.push(z);V.set(F,Z)}};const ie=z=>{const F=N.get(z);if(F?.pending===void 0)return;const Z=j.get(z).dividers[F.pending];Z.x=_[0];Z.y=Math.max(Y,F.bottom)+1;if(Z.lines.some(Boolean)){X({x:Z.x,y:Z.y,width:Math.max(...Z.lines.map(ne)),height:Z.lines.length});Y=Z.y+Z.lines.length;F.bottom=Math.max(F.bottom,Y)}delete F.pending};let ge=0,fe=0,de=0;const xe=Hy(t)??[];const we=()=>{while(de<xe.length){const z=xe[de];if(z.messageIndex>ge||z.noteIndex>fe)break;const F=z.blockIndex;if(z.kind==="open"){if(N.size){const Z=D(F);for(const[ue,be]of N){const Ce=be.pending===void 0?0:j.get(ue).dividers[be.pending].lines.length+1;for(const Le of be.prior){if(Z.x<Le.x+Le.width+1&&Z.x+Z.width+1>Le.x)Y=Math.max(Y,Le.y+Le.height+Ce+1)}}Y+=ee({...Z,y:Y+1,height:1})}Y++;j.set(F,{index:F,x:0,y:Y,width:0,height:0,header:g[F],dividers:[],parentId:s.blocks[F].parentId??ae()});se.push(F);Y+=Math.max(1,g[F].length);if(s.blocks[F].type==="par_over"){Y+=Math.max(0,...y[F].map(Z=>Z.length?Z.length+1:0));N.set(F,{start:Y,bottom:Y,prior:[]})}}else if(z.kind==="divider"){const Z=N.get(F);if(Z){ie(F);Z.bottom=Math.max(Z.bottom,Y);Z.prior=[...V.get(F)??[]];Y=Z.start;const be=j.get(F);be.dividers.push({y:Y,lines:y[F][z.dividerIndex]});Z.pending=be.dividers.length-1;de++;continue}Y++;const ue=y[F][z.dividerIndex];j.get(F).dividers.push({y:Y,lines:ue});Y+=Math.max(1,ue.length)}else{const Z=N.get(F);if(Z){ie(F);Y=Math.max(Y,Z.bottom);N.delete(F)}Y++;const ue=j.get(F);const be=V.get(F)??[];const Ce=be.length?Math.min(...be.map(et=>et.x)):_[0];const Le=be.length?Math.max(...be.map(et=>et.x+et.width-1)):_.at(-1);ue.x=Math.max(0,Ce-4);const Qe=Math.max(0,...ue.header.map(ne),...ue.dividers.flatMap(et=>et.lines.map(ne)));ue.width=Math.max(Le+4-ue.x+1,Qe+2);ue.height=Y-ue.y+1;const lt=se.lastIndexOf(F);if(lt>=0)se.splice(lt,1);X(ue);G.push(ue);Y++}de++}};while(ge<s.messages.length||fe<s.notes.length||de<xe.length){we();const z=s.notes[fe];if(z&&z.afterIndex<ge){Y++;const F=p[fe];const Z={index:fe,...Q[fe],y:Y,height:F.length+2,lines:F,parentId:s.notes[fe].parentId??ae()};const ue=ee(Z);Y+=ue;Z.y+=ue;U.push(Z);X(Z);Y+=Z.height;fe++}else if(ge<s.messages.length){const F=s.messages[ge];s.actors.forEach((et,xt)=>{if(et.createMessageIndex!==ge)return;Y++;ce.set(xt,Y);Y+=b;X({x:_[xt]-Math.floor(C[xt]/2),y:ce.get(xt),width:C[xt],height:b})});Y++;const Z=f[ge];const ue=_[d.get(F.from)],be=_[d.get(F.to)];const Ce=ue===be;const Le=Math.max(0,...Z.map(ne));const Qe={index:ge,x:Ce?ue+6:Math.min(ue,be)+Math.floor((Math.abs(be-ue)-Le)/2),y:Ce?Y+1:Y,width:Le,height:Z.length,lines:Z,arrowY:Ce?Y:Y+Z.length,fromX:ue,toX:be,parentId:F.parentId??ae()};const lt=ee({x:Math.min(ue,be,Qe.x),y:Y,width:Math.max(ue,be,Qe.x+Le-1)-Math.min(ue,be,Qe.x)+1,height:Z.length+(Ce?2:1)});Y+=lt;Qe.y+=lt;Qe.arrowY+=lt;P.push(Qe);X({x:Math.min(ue,be,Qe.x),y:Y,width:Math.max(ue,be,Qe.x+Le-1)-Math.min(ue,be,Qe.x)+1,height:Z.length+(Ce?2:1)});Y+=Z.length+(Ce?2:1);ge++}else if(z){ge=Math.max(ge,z.afterIndex+1)}else if(de<xe.length){throw new Error("Sequence terminal boundary is beyond the parsed content")}}const Be=Y+1;const Ie=(s.boxes??[]).flatMap((z,F)=>{const Z=s.actors.flatMap((Ce,Le)=>Ce.box===F?[Le]:[]);if(!Z.length)return[];const ue=Math.max(0,Math.min(...Z.map(Ce=>_[Ce]-k[Ce]))-1);const be=Math.max(...Z.map(Ce=>_[Ce]+k[Ce]))+1;return[{index:F,x:ue,width:Math.max(be-ue+1,...w[F].map(Ce=>ne(Ce)+2)),lines:w[F],members:Z.map(Ce=>s.actors[Ce].id)}]});const Me=Math.max(...Ie.map(z=>z.x+z.width),_.at(-1)+(k.at(-1)??0)+2,...P.map(z=>z.x+z.width+2),...U.map(z=>z.x+z.width+1),...G.map(z=>z.x+z.width));const Ae=new Re(Me+1,Be+b+(Ie.length?1:0));for(const z of s.actors)if(z.type!=="participant")Ae.report({code:"TERMINAL_FAMILY_PROJECTION",feature:`sequence.${z.id}.glyph`,message:`The authored ${z.type} participant uses a terminal card${z.type==="actor"?"":" with a type stereotype"} in place of its graphical silhouette.`});s.boxes?.forEach((z,F)=>{if(z.color&&z.color.toLowerCase()!=="transparent")Ae.report({code:"TERMINAL_FAMILY_PROJECTION",feature:`sequence.${a(`box:${F}`)}.background`,message:"The authored participant-box background color is represented by an owned terminal frame; terminal output uses foreground ink without a background fill."})});s.blocks.forEach((z,F)=>{if(z.color&&z.color.toLowerCase()!=="transparent")Ae.report({code:"TERMINAL_FAMILY_PROJECTION",feature:`sequence.${a(`block:${F}`)}.background`,message:"The authored rect background color is represented by an owned terminal frame; terminal output uses foreground ink without a background fill."})});const He=(z,F="node",Z)=>Ae.element({id:z,kind:F,...Z?{parent:Z}:{}});const Ne=(z,F,Z,ue,be,Ce="solid")=>Ae.stroke(z,F,Z,{owner:be,role:ue,ascii:c,style:Ce});const K=(z,F,Z,ue)=>Ae.put(z,F,Z,{owner:ue,role:"arrow",kind:"marker"});const pe=(z,F,Z=false)=>Et(Ae,z,F,c,Z);const ke=G.flatMap(z=>[{x:z.x+1,y:z.y,width:Math.max(0,...z.header.map(ne)),height:z.header.length},...z.dividers.map(F=>({x:F.x??z.x+1,y:F.y,width:Math.max(0,...F.lines.map(ne)),height:F.lines.length}))]);ke.push(...U);P.forEach(z=>z.lines.forEach((F,Z)=>ke.push({x:hv(z,F),y:z.y+Z,width:ne(F),height:1})));s.actors.forEach((z,F)=>{if(z.external)return;const Z={x:_[F]-Math.floor(C[F]/2),y:ce.get(F)??x,width:C[F],height:b};ke.push(Z);if(z.destroyMessageIndex===void 0)ke.push({...Z,y:Be})});const Ee=new Map;for(const z of ke)for(let F=z.y;F<z.y+z.height;F++){const Z=Ee.get(F)??[];Z.push({start:z.x,end:z.x+z.width});Ee.set(F,Z)}const _e=(z,F)=>Ee.get(F)?.some(Z=>z>=Z.start&&z<Z.end)??false;Ie.forEach(z=>{const F=Ae.element({id:a(`box:${z.index}`),kind:"group",members:z.members});Et(Ae,{x:z.x,y:0,width:z.width,height:Be+b+1},F,c,false,_e);Ae.scope(F,()=>z.lines.forEach((Z,ue)=>Ae.text(z.x+1,ue,Z,{role:"text",kind:"text"})))});s.actors.forEach((z,F)=>{if(z.external){He(z.id);return}const Z=He(z.id,"node",z.box===void 0?void 0:{id:a(`box:${z.box}`),kind:"group"});const ue=ce.has(F)?ce.get(F)+b:x+b;const be=z.destroyMessageIndex===void 0?Be:P[z.destroyMessageIndex]?.arrowY??Be;for(let Ce=ue;Ce<=be;Ce++)if(!_e(_[F],Ce))Ne(_[F],Ce,5,"line",Z)});const qe=new Map;let Ze=0;const rt=(z,F,Z)=>{const ue=qe.get(z)??[];if(Z)ue.push({y:F,id:Ze++});else if(ue.length){const be=ue.pop(),Ce=be.y,Le=d.get(z),Qe=_[Le]+ue.length;const lt=He(a(`activation:${be.id}`),"band",{id:z,kind:"node"});Ae.region(lt,{x:Qe-1,y:Ce,width:3,height:Math.max(1,F-Ce+1)});for(let et=Ce;et<=F;et++)for(const xt of[Qe-1,Qe+1])if(!_e(xt,et))Ne(xt,et,5,"line",lt)}qe.set(z,ue)};s.messages.forEach((z,F)=>{const Z=P[F].arrowY;for(const ue of s.activationEvents??[])if(ue.messageIndex===F)rt(ue.actorId,P[F].y,ue.kind==="activate");if(z.activate)rt(z.to,Z,true);if(z.deactivate)rt(z.from,Z,false)});for(const z of s.activationEvents??[])if(z.messageIndex>=s.messages.length)rt(z.actorId,Be-1,z.kind==="activate");for(const[z,F]of qe)while(F.length)rt(z,Be,false);s.actors.forEach((z,F)=>{if(z.external)return;const Z=He(z.id,"node",z.box===void 0?void 0:{id:a(`box:${z.box}`),kind:"group"});const ue=be=>{const Ce=C[F],Le=m[F],Qe=_[F]-Math.floor(Ce/2);pe({x:Qe,y:be,width:Ce,height:b},Z,true);Ae.scope(Z,()=>Le.forEach((lt,et)=>Ae.text(Qe+2+Math.floor((Ce-4-ne(lt))/2),be+1+et,lt,{owner:Z,role:"text",kind:"text"})))};ue(ce.get(F)??x);if(z.destroyMessageIndex===void 0)ue(Be);else K(_[F],P[z.destroyMessageIndex]?.arrowY??Be,"X",Z);if(!c){if(z.createMessageIndex===void 0)Ne(_[F],x+b-1,14,"junction",Z);if(z.destroyMessageIndex===void 0)Ne(_[F],Be,11,"junction",Z)}});for(const z of P){const F=s.messages[z.index],Z=F.from===F.to;const ue=Ae.element({id:F.id??a(`message:${z.index}`),kind:"edge",parent:z.parentId===void 0?void 0:{id:z.parentId,kind:"compartment"},from:F.from,to:F.to});const be=F.lineStyle==="dashed"?"dashed":"solid";const Ce=z.arrowY,Le=z.fromX,Qe=z.toX;const lt=(ft,Je,At,H)=>{const Se=Hf(At?F.startHead:F.endHead,H,c,At?F.centralStart:F.centralEnd);if(Se)Ae.marker(ft,Je,Se,{owner:ue,role:"arrow"})};Ae.port(ue,{nodeId:F.from,x:Le,y:Ce,side:Z||Le<Qe?"R":"L",end:"start",surface:"lifeline"});Ae.port(ue,{nodeId:F.to,x:Qe,y:Z?Ce+z.lines.length+1:Ce,side:Z||Le>Qe?"R":"L",end:"end",surface:"lifeline"});const et=Hf(F.startHead,!Z&&Le>Qe,c,F.centralStart);const xt=Hf(F.endHead,!Z&&Le<Qe,c,F.centralEnd);Ae.expectMarkers(ue,"start",et?[et]:[]);Ae.expectMarkers(ue,"end",xt?[xt]:[]);if(Z){Ne(Le,Ce,7,"junction",ue);for(let Je=Le+1;Je<Le+4;Je++)Ne(Je,Ce,10,"line",ue,be);Ne(Le+4,Ce,12,"corner",ue);for(let Je=Ce+1;Je<=Ce+z.lines.length;Je++)Ne(Le+4,Je,5,"line",ue);const ft=Ce+z.lines.length+1;for(let Je=Le+1;Je<Le+4;Je++)Ne(Je,ft,10,"line",ue,be);Ne(Le+4,ft,9,"corner",ue);lt(Le,ft,false,false);lt(Le,Ce,true,false)}else{for(let ft=Math.min(Le,Qe)+1;ft<Math.max(Le,Qe);ft++)Ne(ft,Ce,10,"line",ue,be);lt(Le,Ce,true,Le>Qe);lt(Qe,Ce,false,Le<Qe)}Ae.scope(ue,()=>z.lines.forEach((ft,Je)=>{Ae.text(hv(z,ft),z.y+Je,ft,{owner:ue,role:"text",kind:"text"})}))}for(const z of[...G].reverse()){const F=He(l(z.index),"compartment",z.parentId===void 0?void 0:{id:z.parentId,kind:"compartment"});pe(z,F);Ae.textBlock(z.x+1,z.y,z.header,{owner:F,role:"text",kind:"text"});z.dividers.forEach(Z=>{if(s.blocks[z.index].type!=="par_over"){for(let ue=z.x;ue<z.x+z.width;ue++)Ne(ue,Z.y,10,"line",F,c?"solid":"dashed")}Ae.textBlock(Z.x??z.x+1,Z.y,Z.lines,{owner:F,role:"text",kind:"text"})})}for(const z of U){const F=He(s.notes[z.index].id??a(`note:${z.index}`),"node",z.parentId===void 0?void 0:{id:z.parentId,kind:"compartment"});pe(z,F,true);Ae.textBlock(z.x+2,z.y+1,z.lines,{owner:F,role:"text",kind:"text"})}if(s.title){const z=ve(bt(Ye(s.title,s.titleContent)),o);const F=new Re(Math.max(Ae.width,...z.map(ne)),Ae.height+z.length+1);const Z=He("title","label");F.scope(Z,()=>z.forEach((ue,be)=>F.text(Math.floor((F.width-ne(ue))/2),be,ue,{role:"text",kind:"text"})));F.overlay(Ae,0,z.length+1);return Fe(F,{colorMode:r,theme:i})}return Fe(Ae,{colorMode:r,theme:i})}function Hf(t,e,r,i){if(i)return{shape:"circle",ascii:r};if(t==="none")return void 0;return{shape:t==="filled"?"triangle":t==="open"?"open-arrow":t==="cross"?"sequence-cross":t,direction:e?"R":"L",ascii:r}}function fv(t,e,r,i,n){return Xf(Fs(Co(t)),e,r,i,{},n)}var zr=class extends Map{columns=new Map;rows=new Map;limits=Object.freeze({maxX:0,maxY:0});constructor(e){super();if(e)for(const[r,i]of e)this.set(r,i)}get extent(){return this.limits}set(e,r){if(!this.has(e)){const[i,n]=Kf(e);this.columns.set(i,(this.columns.get(i)??0)+1);this.rows.set(n,(this.rows.get(n)??0)+1);if(i>this.limits.maxX||n>this.limits.maxY)this.limits=Object.freeze({maxX:Math.max(this.limits.maxX,i),maxY:Math.max(this.limits.maxY,n)})}return super.set(e,r)}delete(e){if(!super.delete(e))return false;const[r,i]=Kf(e);const n=(a,l)=>{const c=a.get(l);if(c===1)a.delete(l);else a.set(l,c-1)};n(this.columns,r);n(this.rows,i);const o=r===this.limits.maxX&&!this.columns.has(r)?pv(this.columns):this.limits.maxX;const s=i===this.limits.maxY&&!this.rows.has(i)?pv(this.rows):this.limits.maxY;if(o!==this.limits.maxX||s!==this.limits.maxY)this.limits=Object.freeze({maxX:o,maxY:s});return true}clear(){super.clear();this.columns.clear();this.rows.clear();this.limits=Object.freeze({maxX:0,maxY:0})}};function Kf(t){const e=t.indexOf(","),r=Number(t.slice(0,e)),i=Number(t.slice(e+1));if(e<1||!Number.isSafeInteger(r)||!Number.isSafeInteger(i)||t!==`${r},${i}`)throw new RangeError("Occupancy keys must be integer x,y coordinates");return[r,i]}function pv(t){let e=0;for(const r of t.keys())e=Math.max(e,r);return e}function gv(t){if("extent"in t)return t;let e=0,r=0;for(const i of t.keys()){const[n,o]=Kf(i);e=Math.max(e,n);r=Math.max(r,o)}return{has:i=>t.has(i),extent:{maxX:e,maxY:r}}}function Ct(t,e){return new Re(Math.max(0,t+1),Math.max(0,e+1))}function at(t){return t.blank()}function Jf(t){return[t.width-1,t.height-1]}function $d(t){t.flip(false,true);return t}function Cr(t,e,r,i=false){const n=mt(r);if(!i)for(let o=0;o<n.height;o++){for(let s=0;s<n.width;s++)if(t.get(e.x+s,e.y+o)!==" ")return}t.textBlock(e.x,e.y,n,{role:"text"})}function yv(t,e,r){t.resize([...e.values()].reduce((i,n)=>i+n,0),[...r.values()].reduce((i,n)=>i+n,0))}function ls(t,e,r="subgraph"){zy(t);const i=e.maxWidth===void 0?void 0:Math.max(e.targetWidth===void 0?8:1,Math.floor(e.maxWidth/3));const n=f=>ve(Ge(f),i).join("\n");const o=ZI(t.subgraphs);const s=new Map;let a=0;for(const[f,p]of t.nodes){if(o.has(f))continue;const g={name:f,displayLabel:n(Ye(p.label,p.labelContent)),shape:p.shape,index:a,gridCoord:null,drawingCoord:null,drawing:null,drawn:false,styleClassName:"",styleClass:zf};s.set(f,g);a++}const l=[];for(const f of t.subgraphs){bv(f,null,s,l)}for(const f of l)f.name=ve(f.name,i).join("\n");eL(t.subgraphs,l);for(const f of[...l].reverse()){if(f.nodes.length)continue;let p=`__container:${f.id}`;while(s.has(p))p+=":";const g={name:p,displayLabel:"",shape:"rectangle",index:a++,gridCoord:null,drawingCoord:null,drawing:null,drawn:true,styleClassName:"",styleClass:zf,containerAnchor:true};s.set(p,g);for(let y=f;y;y=y.parent)y.nodes.push(g)}const c=new Map(l.map(f=>[f.id,f]));const d=cC(t);const u=[];for(let f=0;f<t.edges.length;f++){const p=t.edges[f];const g=s.has(p.source)?void 0:c.get(p.source);const y=s.has(p.target)?void 0:c.get(p.target);const C=s.get(p.source)??(g?xv(t,g,"out"):void 0);const w=s.get(p.target)??(y?xv(t,y,"in"):void 0);if(!C||!w)continue;const x=d[f];if(!x)throw new Error(`ASCII route classification missing for edge ${f}`);u.push({id:p.id??`edge#${f}:${p.source}->${p.target}`,sourceIndex:f,inlineStyle:Kb(f,t),from:C,to:w,fromSubgraph:g,toSubgraph:y,text:n(Ye(p.label??"",p.labelContent)),path:[],labelLine:[],startDir:{x:0,y:0},endDir:{x:0,y:0},routeClass:x,style:p.style,hasArrowStart:p.hasArrowStart,hasArrowEnd:p.hasArrowEnd,startMarker:p.startMarker,endMarker:p.endMarker})}const h=[...s.values()];for(const f of h){f.styleClassName=t.classAssignments.get(f.name)??"";f.styleClass={name:f.styleClassName,styles:Xb(f.name,t)??{}}}const m=Ct(0,0);for(const[f,p]of t.nodes){for(const g of["icon","image","semanticShape"])if(p[g]!==void 0){m.report({code:"TERMINAL_FAMILY_PROJECTION",feature:`node:${f}:${g}`,message:`Node ${f} retains its ${g} metadata in source; terminal output uses its label and a shape cue instead of graphical ${g} geometry.`})}}for(const f of h)for(const p of Object.keys(f.styleClass.styles)){if(p==="color"||p==="stroke")continue;m.report({code:"TERMINAL_FAMILY_PROJECTION",feature:`node:${f.name}:style:${p}`,message:`Node ${f.name} style ${p} projects to a terminal card with text and border ink; its graphical fill, typography and dimensions remain source data.`})}return{containerKind:r,nodes:h,edges:u,canvas:m,grid:new zr,columnWidth:new Map,rowHeight:new Map,subgraphs:l,config:e,offsetX:0,offsetY:0,bundles:[],trunkJunctions:[]}}function ZI(t){const e=new Set;const r=i=>{for(const n of i){e.add(n.id);r(n.children)}};r(t);return e}function xv(t,e,r){const i=new Set(e.nodes.map(a=>a.name));if(i.size===0)return void 0;const n=new Set;const o=new Set;for(const a of t.edges){if(i.has(a.source)&&i.has(a.target)){o.add(a.source);n.add(a.target)}}const s=r==="in"?e.nodes.filter(a=>!n.has(a.name)):e.nodes.filter(a=>!o.has(a.name));return s[0]??e.nodes[0]}function bv(t,e,r,i){let n;if(t.direction){n=t.direction==="LR"||t.direction==="RL"?"LR":"TD"}const o={id:t.id,name:Ge(Ye(t.label,t.labelContent)),nodes:[],parent:e,children:[],minX:0,minY:0,maxX:0,maxY:0,direction:n,...t.concurrencyRegion?{concurrencyRegion:true}:{}};for(const s of t.nodeIds){const a=r.get(s);if(a)o.nodes.push(a)}i.push(o);for(const s of t.children){const a=bv(s,o,r,i);o.children.push(a);for(const l of a.nodes){if(!o.nodes.includes(l)){o.nodes.push(l)}}}return o}function eL(t,e){const r=new Map;rL(t,e,r);const i=new Map;function n(o){const s=r.get(o);if(!s)return;for(const a of o.children){n(a)}for(const a of o.nodeIds){if(!i.has(a)){i.set(a,s)}}}for(const o of t){n(o)}for(const o of e){o.nodes=o.nodes.filter(s=>{const a=s.name;if(!a)return false;const l=i.get(a);if(!l)return true;return tL(o,l)})}}function tL(t,e){let r=e;while(r!==null){if(r===t)return true;r=r.parent}return false}function rL(t,e,r){const i=[];function n(o){for(const s of o){i.push(s);n(s.children)}}n(t);for(let o=0;o<i.length&&o<e.length;o++){r.set(i[o],e[o])}}var Qf=class{items=[];get length(){return this.items.length}push(e){this.items.push(e);this.bubbleUp(this.items.length-1)}pop(){if(this.items.length===0)return void 0;const e=this.items[0];const r=this.items.pop();if(this.items.length>0){this.items[0]=r;this.sinkDown(0)}return e}before(e,r){if(e.priority!==r.priority)return e.priority<r.priority;return e.seq<r.seq}bubbleUp(e){while(e>0){const r=e-1>>1;if(this.before(this.items[e],this.items[r])){;[this.items[e],this.items[r]]=[this.items[r],this.items[e]];e=r}else{break}}}sinkDown(e){const r=this.items.length;while(true){let i=e;const n=2*e+1;const o=2*e+2;if(n<r&&this.before(this.items[n],this.items[i])){i=n}if(o<r&&this.before(this.items[o],this.items[i])){i=o}if(i!==e){;[this.items[e],this.items[i]]=[this.items[i],this.items[e]];e=i}else{break}}}};function iL(t,e){const r=Math.abs(t.x-e.x);const i=Math.abs(t.y-e.y);if(r===0||i===0){return r+i}return r+i+1}var nL=[{x:1,y:0},{x:-1,y:0},{x:0,y:1},{x:0,y:-1}];function oL(t){if(!t)return[...nL];if(t.x===2&&t.y===1){return[{x:1,y:0},{x:-1,y:0},{x:0,y:1},{x:0,y:-1}]}if(t.x===0&&t.y===1){return[{x:-1,y:0},{x:1,y:0},{x:0,y:1},{x:0,y:-1}]}if(t.x===1&&t.y===2){return[{x:0,y:1},{x:0,y:-1},{x:1,y:0},{x:-1,y:0}]}if(t.x===1&&t.y===0){return[{x:0,y:-1},{x:0,y:1},{x:1,y:0},{x:-1,y:0}]}const e=t.x-1;const r=t.y-1;if(Math.abs(e)>=Math.abs(r)){return e>=0?[{x:1,y:0},{x:-1,y:0},{x:0,y:1},{x:0,y:-1}]:[{x:-1,y:0},{x:1,y:0},{x:0,y:1},{x:0,y:-1}]}return r>=0?[{x:0,y:1},{x:0,y:-1},{x:1,y:0},{x:-1,y:0}]:[{x:0,y:-1},{x:0,y:1},{x:1,y:0},{x:-1,y:0}]}function sL(t,e){if(e.x<0||e.y<0)return false;return!t.has(ot(e))}function Cv(t,e,r){if(![e.x,e.y,r.x,r.y].every(s=>Number.isSafeInteger(s)&&s>=0))return null;if(e.x!==r.x&&e.y!==r.y)return null;const i=Math.abs(r.x-e.x)+Math.abs(r.y-e.y);if(i>=1e4)return null;const n=Math.sign(r.x-e.x),o=Math.sign(r.y-e.y);for(let s=1;s<i;s++)if(t.has(`${e.x+n*s},${e.y+o*s}`))return null;return Array.from({length:i+1},(s,a)=>({x:e.x+n*a,y:e.y+o*a}))}function St(t,e,r,i,n){const o=gv(t);const s=Math.max(e.x,r.x,o.extent.maxX);const a=Math.max(e.y,r.y,o.extent.maxY);const l=s+4;const c=a+4;const d=Math.max(1e4,(l+1)*(c+1)*4);const u=oL(i);let h=0;const m=new Qf;m.push({coord:e,priority:0,seq:h++});const f=new Map;f.set(ot(e),0);const p=new Map;p.set(ot(e),null);let g=0;while(m.length>0){if(++g>d)return null;const y=m.pop().coord;if(qf(y,r)){const w=[];let x=y;while(x!==null){w.push(x);x=p.get(ot(x))??null}return w.reverse()}const C=f.get(ot(y));for(const w of u){const x={x:y.x+w.x,y:y.y+w.y};if(x.x>l||x.y>c)continue;if(n&&!n(y,x))continue;if(!sL(o,x)&&!qf(x,r)){continue}const k=C+1;const b=ot(x);const A=f.get(b);if(A===void 0||k<A){f.set(b,k);const L=k+iL(x,r);m.push({coord:x,priority:L,seq:h++});p.set(b,y)}}}return null}function Nt(t){if(t.length<=2)return t;const e=new Set;let r=t[0];let i=t[1];for(let n=2;n<t.length;n++){const o=t[n];const s=i.x-r.x;const a=i.y-r.y;const l=o.x-i.x;const c=o.y-i.y;if(s===l&&a===c){e.add(n-1)}r=i;i=o}return t.filter((n,o)=>!e.has(o))}function qd(t){if(t===je)return We;if(t===We)return je;if(t===$e)return Pe;if(t===Pe)return $e;if(t===xr)return br;if(t===dr)return Fr;if(t===Fr)return dr;if(t===br)return xr;return mi}function Oe(t,e){return t.x===e.x&&t.y===e.y}function _t(t,e){if(t.x===e.x){return t.y<e.y?We:je}else if(t.y===e.y){return t.x<e.x?Pe:$e}else if(t.x<e.x){return t.y<e.y?Fr:xr}else{return t.y<e.y?br:dr}}function aL(t){if(t==="LR")return[Pe,We,We,Pe];return[We,Pe,Pe,We]}function lL(t,e){if(t.from===t.to)return aL(e);const r=_t(t.from.gridCoord,t.to.gridCoord);let i;let n;let o;let s;const a=e==="LR"?Oe(r,$e)||Oe(r,dr)||Oe(r,br):Oe(r,je)||Oe(r,dr)||Oe(r,xr);if(Oe(r,Fr)){if(e==="LR"){i=We;n=$e;o=Pe;s=je}else{i=Pe;n=je;o=We;s=$e}}else if(Oe(r,xr)){if(e==="LR"){i=je;n=$e;o=Pe;s=We}else{i=Pe;n=We;o=je;s=$e}}else if(Oe(r,br)){if(e==="LR"){i=We;n=We;o=$e;s=je}else{i=$e;n=je;o=We;s=Pe}}else if(Oe(r,dr)){if(e==="LR"){i=We;n=We;o=$e;s=We}else{i=Pe;n=Pe;o=je;s=Pe}}else if(a){if(e==="LR"&&Oe(r,$e)){i=We;n=We;o=$e;s=Pe}else if(e==="TD"&&Oe(r,je)){i=Pe;n=Pe;o=je;s=We}else{i=r;n=qd(r);o=r;s=qd(r)}}else{i=r;n=qd(r);o=r;s=qd(r)}return[i,n,o,s]}function kv(t,e){const r=Ut(t,e.from);const i=Ut(t,e.to);const n=r&&r===i&&r.direction?r.direction:t.config.graphDirection;const[o,s,a,l]=lL(e,n);const c=io(e.from.gridCoord,o);const d=io(e.to.gridCoord,s);let u=St(t.grid,c,d,o);const h=io(e.from.gridCoord,a);const m=io(e.to.gridCoord,l);let f=St(t.grid,h,m,a);if(u!==null&&f!==null){u=Nt(u);f=Nt(f);if(u.length<=f.length){e.startDir=o;e.endDir=s;e.path=u}else{e.startDir=a;e.endDir=l;e.path=f}return}if(u!==null){e.startDir=o;e.endDir=s;e.path=Nt(u);return}if(f!==null){e.startDir=a;e.endDir=l;e.path=Nt(f);return}e.startDir=o;e.endDir=s;e.path=[c,d]}function zd(t,e){if(e.text.length===0)return;const r=ne(e.text);const i=e.path.length;const n=t.config.graphDirection==="TD";const o=[];for(let g=1;g<i;g++){const y=e.path[g-1];const C=e.path[g];const w=[y,C];const x=cL(t,w);const k=y.x===C.x;o.push({line:w,width:x,index:g,isVertical:k})}const s=g=>n?g.isVertical:!g.isVertical;let a=o.filter(g=>g.width>=r&&g.index>1&&s(g));if(a.length===0){a=o.filter(g=>g.width>=r&&g.index>1)}let l;if(a.length>0){a.sort((g,y)=>y.width-g.width||y.index-g.index);l=a[0].line}else{const g=o.filter(y=>y.width>=r);if(g.length>0){g.sort((y,C)=>C.width-y.width||C.index-y.index);l=g[0].line}else{o.sort((y,C)=>C.width-y.width||y.line[0].x-C.line[0].x||y.line[0].y-C.line[0].y);l=o[0]?.line??[e.path[0],e.path[1]]}}const c=Math.min(l[0].x,l[1].x);const d=Math.max(l[0].x,l[1].x);const u=c+Math.floor((d-c)/2);const h=t.columnWidth.get(u)??0;const m=l[0].y===l[1].y;const f=m?t.subgraphs.filter(g=>g.nodes.includes(e.from)!==g.nodes.includes(e.to)).length*2:0;const p=!m&&t.edges.some(g=>g!==e&&g.from===e.to&&g.to===e.from);t.columnWidth.set(u,Math.max(h,r*(p?2:1)+2+f));e.labelLine=[l[0],l[1]]}function cL(t,e){let r=0;const i=Math.min(e[0].x,e[1].x);const n=Math.max(e[0].x,e[1].x);for(let o=i;o<=n;o++){r+=t.columnWidth.get(o)??0}return r}function wv(t){if(t.config.graphDirection!=="TD"){return[]}const e=[];const r=new Set;const i=new Map;for(const o of t.edges){if(o.from===o.to)continue;const s=i.get(o.to)??[];s.push(o);i.set(o.to,s)}for(const[o,s]of i){if(s.length<2)continue;if(!Sv(s,t))continue;if(s.some(l=>r.has(l)))continue;const a={type:"fan-in",edges:[...s],sharedNode:o,otherNodes:s.map(l=>l.from),junctionPoint:null,sharedPath:[],junctionDir:mi,sharedNodeDir:mi};for(const l of s){l.bundle=a;r.add(l)}e.push(a)}const n=new Map;for(const o of t.edges){if(o.from===o.to)continue;if(r.has(o))continue;const s=n.get(o.from)??[];s.push(o);n.set(o.from,s)}for(const[o,s]of n){if(s.length<2)continue;if(!Sv(s,t))continue;const a={type:"fan-out",edges:[...s],sharedNode:o,otherNodes:s.map(l=>l.to),junctionPoint:null,sharedPath:[],junctionDir:mi,sharedNodeDir:mi};for(const l of s){l.bundle=a;r.add(l)}e.push(a)}return e}function Sv(t,e){if(t.length<2)return false;const r=t[0].style;const i=Ut(e,t[0].from);const n=Ut(e,t[0].to);for(const o of t){if(o.hasArrowStart||!o.hasArrowEnd||o.endMarker&&o.endMarker!=="arrow")return false;if(o.routeClass!==void 0&&o.routeClass!=="primary-forward")return false;const s=o.from.gridCoord,a=o.to.gridCoord;if(s&&a&&s.y+3>a.y)return false;if(o.style!==r)return false;if(o.inlineStyle?.stroke!==t[0].inlineStyle?.stroke)return false;if(o.text.length>0)return false;const l=Ut(e,o.from);const c=Ut(e,o.to);if(l!==i||c!==n)return false;if(l!==c)return false}return true}function dL(t,e){const r=t.config.graphDirection;const i=e.sharedNode.gridCoord;const n=e.otherNodes.map(o=>o.gridCoord);if(e.type==="fan-in"){const o=Math.min(...n.map(c=>c.x));const s=Math.max(...n.map(c=>c.x));const a=Math.min(...n.map(c=>c.y));const l=Math.max(...n.map(c=>c.y));if(r==="TD"){const c=i.y-1;const d=Math.floor((o+s)/2)+1;const u=i.x+1;return{x:u,y:c}}else{const c=i.x-1;const d=i.y+1;return{x:c,y:d}}}else{const o=Math.min(...n.map(c=>c.x));const s=Math.max(...n.map(c=>c.x));const a=Math.min(...n.map(c=>c.y));const l=Math.max(...n.map(c=>c.y));if(r==="TD"){const c=i.y+3;const d=i.x+1;return{x:d,y:c}}else{const c=i.x+3;const d=i.y+1;return{x:c,y:d}}}}function uL(t,e){const r=t.config.graphDirection;e.junctionPoint=dL(t,e);const i=e.junctionPoint;if(e.type==="fan-in"){e.junctionDir=r==="TD"?je:$e;e.sharedNodeDir=r==="TD"?We:Pe;const n=e.sharedNode.gridCoord;const o=r==="TD"?{x:n.x+1,y:n.y}:{x:n.x,y:n.y+1};const s=St(t.grid,i,o);e.sharedPath=s?Nt(s):[i,o];for(const a of e.edges){const l=a.from.gridCoord;const c=r==="TD"?{x:l.x+1,y:l.y+2}:{x:l.x+2,y:l.y+1};const d=St(t.grid,c,i);a.pathToJunction=d?Nt(d):[c,i];a.startDir=r==="TD"?We:Pe;a.endDir=r==="TD"?je:$e;a.path=[...a.pathToJunction,...e.sharedPath.slice(1)]}}else{e.junctionDir=r==="TD"?We:Pe;e.sharedNodeDir=r==="TD"?je:$e;const n=e.sharedNode.gridCoord;const o=r==="TD"?{x:n.x+1,y:n.y+2}:{x:n.x+2,y:n.y+1};const s=St(t.grid,o,i);e.sharedPath=s?Nt(s):[o,i];for(const a of e.edges){const l=a.to.gridCoord;const c=r==="TD"?{x:l.x+1,y:l.y}:{x:l.x,y:l.y+1};const d=St(t.grid,i,c);a.pathToJunction=d?Nt(d):[i,c];a.startDir=r==="TD"?We:Pe;a.endDir=r==="TD"?je:$e;a.path=[...e.sharedPath,...a.pathToJunction.slice(1)]}}}function Tv(t){for(const e of t.bundles){uL(t,e)}}function It(t){return t.split("\n")}function Vi(t){return Ge(t).replace(/\n/g," ")}function $a(t){const e=It(t);return Math.max(...e.map(r=>ne(r)),0)}function Yi(t){return It(t).length}var vv={rectangle:{unicode:{tl:"\u250C",tr:"\u2510",bl:"\u2514",br:"\u2518"},ascii:{tl:"+",tr:"+",bl:"+",br:"+"}},service:{unicode:{tl:"\u250C",tr:"\u2510",bl:"\u2514",br:"\u2518"},ascii:{tl:"+",tr:"+",bl:"+",br:"+"}},rounded:{unicode:{tl:"\u256D",tr:"\u256E",bl:"\u2570",br:"\u256F"},ascii:{tl:".",tr:".",bl:"'",br:"'"}},circle:{unicode:{tl:"\u25EF",tr:"\u25EF",bl:"\u25EF",br:"\u25EF"},ascii:{tl:"o",tr:"o",bl:"o",br:"o"}},ellipse:{unicode:{tl:"\u25EF",tr:"\u25EF",bl:"\u25EF",br:"\u25EF"},ascii:{tl:"o",tr:"o",bl:"o",br:"o"}},doublecircle:{unicode:{tl:"\u25CE",tr:"\u25CE",bl:"\u25CE",br:"\u25CE"},ascii:{tl:"@",tr:"@",bl:"@",br:"@"}},diamond:{unicode:{tl:"\u25C7",tr:"\u25C7",bl:"\u25C7",br:"\u25C7"},ascii:{tl:"<",tr:">",bl:"<",br:">"}},hexagon:{unicode:{tl:"\u231C",tr:"\u231D",bl:"\u231E",br:"\u231F"},ascii:{tl:"*",tr:"*",bl:"*",br:"*"}},stadium:{unicode:{tl:"(",tr:")",bl:"(",br:")"},ascii:{tl:"(",tr:")",bl:"(",br:")"}},subroutine:{unicode:{tl:"\u255F",tr:"\u2562",bl:"\u255F",br:"\u2562"},ascii:{tl:"|",tr:"|",bl:"|",br:"|"}},cylinder:{unicode:{tl:"\u256D",tr:"\u256E",bl:"\u2570",br:"\u256F"},ascii:{tl:".",tr:".",bl:"'",br:"'"}},asymmetric:{unicode:{tl:"\u25B7",tr:"\u2510",bl:"\u25B7",br:"\u2518"},ascii:{tl:">",tr:"+",bl:">",br:"+"}},trapezoid:{unicode:{tl:"/",tr:"\\",bl:"\u2514",br:"\u2518"},ascii:{tl:"/",tr:"\\",bl:"+",br:"+"}},"trapezoid-alt":{unicode:{tl:"\u250C",tr:"\u2510",bl:"\\",br:"/"},ascii:{tl:"+",tr:"+",bl:"\\",br:"/"}},"lean-r":{unicode:{tl:"/",tr:"/",bl:"/",br:"/"},ascii:{tl:"/",tr:"/",bl:"/",br:"/"}},"lean-l":{unicode:{tl:"\\",tr:"\\",bl:"\\",br:"\\"},ascii:{tl:"\\",tr:"\\",bl:"\\",br:"\\"}},"state-start":{unicode:{tl:"\u25CF",tr:"\u25CF",bl:"\u25CF",br:"\u25CF"},ascii:{tl:"*",tr:"*",bl:"*",br:"*"}},"state-end":{unicode:{tl:"\u25C9",tr:"\u25C9",bl:"\u25C9",br:"\u25C9"},ascii:{tl:"@",tr:"@",bl:"@",br:"@"}},"state-fork":{unicode:{tl:"\u2588",tr:"\u2588",bl:"\u2588",br:"\u2588"},ascii:{tl:"#",tr:"#",bl:"#",br:"#"}},"state-join":{unicode:{tl:"\u2588",tr:"\u2588",bl:"\u2588",br:"\u2588"},ascii:{tl:"#",tr:"#",bl:"#",br:"#"}},"state-choice":{unicode:{tl:"\u25C7",tr:"\u25C7",bl:"\u25C7",br:"\u25C7"},ascii:{tl:"<",tr:">",bl:"<",br:">"}},"state-history":{unicode:{tl:"\u25EF",tr:"\u25EF",bl:"\u25EF",br:"\u25EF"},ascii:{tl:"o",tr:"o",bl:"o",br:"o"}},"state-note":{unicode:{tl:"\u250C",tr:"\u2510",bl:"\u2514",br:"\u2518"},ascii:{tl:"+",tr:"+",bl:"+",br:"+"}}};function Qt(t,e){const r=vv[t]??vv.rectangle;return e?r.ascii:r.unicode}function pi(t,e){const r=It(t);const i=Math.max(...r.map(d=>ne(d)),0);const n=r.length;const o=2*e.padding+i;const s=o+2;const a=n+2*e.padding;const l=a%2===0?a+1:a;const c=l+2;return{width:s,height:c,labelArea:{x:1+e.padding,y:1+e.padding,width:i,height:n},gridColumns:[1,o,1],gridRows:[1,l,1]}}function gi(t,e,r,i){const{width:n,height:o}=e;const s=Ct(n-1,o-1);const a={x:0,y:0};const l={x:n-1,y:o-1};const c={ascii:i};for(let p=a.x+1;p<l.x;p++){s.stroke(p,a.y,10,c);s.stroke(p,l.y,10,c)}for(let p=a.y+1;p<l.y;p++){s.stroke(a.x,p,5,c);s.stroke(l.x,p,5,c)}s.put(a.x,a.y,r.tl,{kind:"marker"});s.put(l.x,a.y,r.tr,{kind:"marker"});s.put(a.x,l.y,r.bl,{kind:"marker"});s.put(l.x,l.y,r.br,{kind:"marker"});const d=It(t);const u=n-1;const h=o-1;const m=Math.floor(h/2);const f=m-Math.floor((d.length-1)/2);for(let p=0;p<d.length;p++){const g=d[p];const y=Math.floor(u/2)-Math.ceil(ne(g)/2)+1;Cr(s,{x:y,y:f+p},g,true)}return s}function nr(t,e,r){const{width:i,height:n}=e;const o=r.x+Math.floor(i/2);const s=r.y+Math.floor(n/2);if(Oe(t,je))return{x:o,y:r.y};if(Oe(t,We))return{x:o,y:r.y+n-1};if(Oe(t,$e))return{x:r.x,y:s};if(Oe(t,Pe))return{x:r.x+i-1,y:s};if(Oe(t,dr))return{x:r.x,y:r.y};if(Oe(t,xr))return{x:r.x+i-1,y:r.y};if(Oe(t,br))return{x:r.x,y:r.y+n-1};if(Oe(t,Fr))return{x:r.x+i-1,y:r.y+n-1};return{x:o,y:s}}var oo={getDimensions:pi,render(t,e,r){const i=Qt("rectangle",r.useAscii);return gi(t,e,i,r.useAscii)},getAttachmentPoint:nr};function yn(t){return{getDimensions:pi,render:(e,r,i)=>gi(e,r,Qt(t,i.useAscii),i.useAscii),getAttachmentPoint:nr}}var Zf=yn("diamond");var Gd=yn("circle");var Ev={getDimensions(t,e){const r=5;const i=3;return{width:r,height:i,labelArea:{x:2,y:1,width:1,height:1},gridColumns:[1,3,1],gridRows:[1,1,1]}},render(t,e,r){const{width:i,height:n}=e;const o=Ct(i-1,n-1);const s=Math.floor(i/2);if(!r.useAscii){o.put(0,0,"\u256D");o.put(1,0,"\u2500");o.put(2,0,"\u2500");o.put(3,0,"\u2500");o.put(4,0,"\u256E");o.put(0,1,"\u2502");o.put(s,1,"\u25CF");o.put(4,1,"\u2502");o.put(0,2,"\u2570");o.put(1,2,"\u2500");o.put(2,2,"\u2500");o.put(3,2,"\u2500");o.put(4,2,"\u256F")}else{o.put(0,0,".");o.put(1,0,"-");o.put(2,0,"-");o.put(3,0,"-");o.put(4,0,".");o.put(0,1,"|");o.put(s,1,"*");o.put(4,1,"|");o.put(0,2,"'");o.put(1,2,"-");o.put(2,2,"-");o.put(3,2,"-");o.put(4,2,"'")}return o},getAttachmentPoint(t,e,r){const{width:i,height:n}=e;const o=r.x+Math.floor(i/2);const s=r.y+Math.floor(n/2);if(Oe(t,je))return{x:o,y:r.y};if(Oe(t,We))return{x:o,y:r.y+n-1};if(Oe(t,$e))return{x:r.x,y:s};if(Oe(t,Pe))return{x:r.x+i-1,y:s};return{x:o,y:s}}};var Mv={getDimensions(t,e){const r=5;const i=3;return{width:r,height:i,labelArea:{x:2,y:1,width:1,height:1},gridColumns:[1,3,1],gridRows:[1,1,1]}},render(t,e,r){const{width:i,height:n}=e;const o=Ct(i-1,n-1);const s=Math.floor(i/2);if(!r.useAscii){o.put(0,0,"\u2554");o.put(1,0,"\u2550");o.put(2,0,"\u2550");o.put(3,0,"\u2550");o.put(4,0,"\u2557");o.put(0,1,"\u2551");o.put(s,1,"\u25CE");o.put(4,1,"\u2551");o.put(0,2,"\u255A");o.put(1,2,"\u2550");o.put(2,2,"\u2550");o.put(3,2,"\u2550");o.put(4,2,"\u255D")}else{o.put(0,0,"#");o.put(1,0,"=");o.put(2,0,"=");o.put(3,0,"=");o.put(4,0,"#");o.put(0,1,"#");o.put(s,1,"*");o.put(4,1,"#");o.put(0,2,"#");o.put(1,2,"=");o.put(2,2,"=");o.put(3,2,"=");o.put(4,2,"#")}return o},getAttachmentPoint(t,e,r){const{width:i,height:n}=e;const o=r.x+Math.floor(i/2);const s=r.y+Math.floor(n/2);if(Oe(t,je))return{x:o,y:r.y};if(Oe(t,We))return{x:o,y:r.y+n-1};if(Oe(t,$e))return{x:r.x,y:s};if(Oe(t,Pe))return{x:r.x+i-1,y:s};return{x:o,y:s}}};var Av=yn("rounded");var Ov={getDimensions(t,e){const r=It(t);const i=Math.max(...r.map(c=>ne(c)),0);const n=r.length;const o=2*e.padding+i;const s=o+4;const a=n+2*e.padding;const l=Math.max(a+2,3);return{width:s,height:l,labelArea:{x:2+e.padding,y:1+e.padding,width:i,height:n},gridColumns:[2,o,2],gridRows:[1,a,1]}},render(t,e,r){const{width:i,height:n}=e;const o=Ct(i-1,n-1);const s=Math.floor(n/2);const a=r.useAscii?"-":"\u2500";if(n===3){o.put(0,s,"(");o.put(i-1,s,")")}else if(!r.useAscii){o.put(0,0,"\u256D");for(let d=1;d<i-1;d++)o.put(d,0,a);o.put(i-1,0,"\u256E");for(let d=1;d<n-1;d++){o.put(0,d,"\u2502");o.put(i-1,d,"\u2502")}o.put(0,n-1,"\u2570");for(let d=1;d<i-1;d++)o.put(d,n-1,a);o.put(i-1,n-1,"\u256F")}else{for(let d=0;d<n;d++){o.put(0,d,"(");o.put(i-1,d,")")}for(let d=1;d<i-1;d++){o.put(d,0,a);o.put(d,n-1,a)}}const l=It(t);const c=s-Math.floor((l.length-1)/2);for(let d=0;d<l.length;d++){const u=l[d];const h=Math.floor(i/2)-Math.floor(ne(u)/2);const m=c+d;if(h>0&&m>=0&&m<n){Cr(o,{x:h,y:m},u,true)}}return o},getAttachmentPoint:nr};var Bv=yn("hexagon");var _v={getDimensions(t,e){const r=It(t);const i=Math.max(...r.map(c=>ne(c)),0);const n=r.length;const o=2*e.padding+i;const s=o+4;const a=n+2*e.padding;const l=a+2;return{width:s,height:l,labelArea:{x:2+e.padding,y:1+e.padding,width:i,height:n},gridColumns:[2,o,2],gridRows:[1,a,1]}},render(t,e,r){const{width:i,height:n}=e;const o=Ct(i-1,n-1);const s=r.useAscii?"-":"\u2500";const a=r.useAscii?"|":"\u2502";o.put(0,0,r.useAscii?"+":"\u250C");o.put(1,0,r.useAscii?"+":"\u252C");for(let u=2;u<i-2;u++)o.put(u,0,s);o.put(i-2,0,r.useAscii?"+":"\u252C");o.put(i-1,0,r.useAscii?"+":"\u2510");for(let u=1;u<n-1;u++){o.put(0,u,a);o.put(1,u,a);o.put(i-2,u,a);o.put(i-1,u,a)}o.put(0,n-1,r.useAscii?"+":"\u2514");o.put(1,n-1,r.useAscii?"+":"\u2534");for(let u=2;u<i-2;u++)o.put(u,n-1,s);o.put(i-2,n-1,r.useAscii?"+":"\u2534");o.put(i-1,n-1,r.useAscii?"+":"\u2518");const l=It(t);const c=Math.floor(n/2);const d=c-Math.floor((l.length-1)/2);for(let u=0;u<l.length;u++){const h=l[u];const m=Math.floor(i/2)-Math.floor(ne(h)/2);const f=d+u;if(m>1&&f>0&&f<n-1){Cr(o,{x:m,y:f},h,true)}}return o},getAttachmentPoint:nr};var Iv={getDimensions:pi,render(t,e,r){const i=Qt("doublecircle",r.useAscii);return gi(t,e,i,r.useAscii)},getAttachmentPoint:nr};var Lv={getDimensions(t,e){const r=It(t);const i=Math.max(...r.map(c=>ne(c)),0);const n=r.length;const o=2*e.padding+i;const s=o+2;const a=n+2*e.padding+2;const l=a+2;return{width:s,height:l,labelArea:{x:1+e.padding,y:2+e.padding,width:i,height:n},gridColumns:[1,o,1],gridRows:[2,a-2,2]}},render(t,e,r){const{width:i,height:n}=e;const o=Ct(i-1,n-1);const s=r.useAscii?"-":"\u2500";const a=r.useAscii?"|":"\u2502";o.put(0,0,r.useAscii?".":"\u256D");for(let u=1;u<i-1;u++)o.put(u,0,s);o.put(i-1,0,r.useAscii?".":"\u256E");o.put(0,1,a);for(let u=1;u<i-1;u++)o.put(u,1,s);o.put(i-1,1,a);for(let u=2;u<n-2;u++){o.put(0,u,a);o.put(i-1,u,a)}o.put(0,n-2,a);for(let u=1;u<i-1;u++)o.put(u,n-2,s);o.put(i-1,n-2,a);o.put(0,n-1,r.useAscii?"'":"\u2570");for(let u=1;u<i-1;u++)o.put(u,n-1,s);o.put(i-1,n-1,r.useAscii?"'":"\u256F");const l=It(t);const c=Math.floor(n/2);const d=c-Math.floor((l.length-1)/2);for(let u=0;u<l.length;u++){const h=l[u];const m=Math.floor(i/2)-Math.floor(ne(h)/2);const f=d+u;if(m>0&&f>1&&f<n-2){Cr(o,{x:m,y:f},h,true)}}return o},getAttachmentPoint:nr};var Rv={getDimensions:pi,render(t,e,r){const i=Qt("asymmetric",r.useAscii);return gi(t,e,i,r.useAscii)},getAttachmentPoint:nr};var Dv={getDimensions:pi,render(t,e,r){const i=Qt("trapezoid",r.useAscii);return gi(t,e,i,r.useAscii)},getAttachmentPoint:nr};var Nv={getDimensions:pi,render(t,e,r){const i=Qt("trapezoid-alt",r.useAscii);return gi(t,e,i,r.useAscii)},getAttachmentPoint:nr};var Pv={getDimensions:pi,render(t,e,r){const i=Qt("lean-r",r.useAscii);return gi(t,e,i,r.useAscii)},getAttachmentPoint:nr};var Fv={getDimensions:pi,render(t,e,r){const i=Qt("lean-l",r.useAscii);return gi(t,e,i,r.useAscii)},getAttachmentPoint:nr};var hL=new Map([["rectangle",oo],["service",oo],["rounded",Av],["diamond",Zf],["stadium",Ov],["circle",Gd],["ellipse",Gd],["subroutine",_v],["doublecircle",Iv],["hexagon",Bv],["cylinder",Lv],["asymmetric",Rv],["trapezoid",Dv],["trapezoid-alt",Nv],["lean-r",Pv],["lean-l",Fv],["state-start",Ev],["state-end",Mv],["state-fork",oo],["state-join",oo],["state-choice",Zf],["state-history",Gd],["state-note",oo]]);function $v(t){return hL.get(t)??oo}function qv(t,e,r){const i=$v(t);return i.getDimensions(e,r)}function zv(t,e,r,i){const n=$v(t);return n.getAttachmentPoint(e,r,i)}var Wd=2;var Gr=(t,e)=>(e?t.cellAllocation?.startEscape:t.cellAllocation?.endEscape)??Wd;var kr=t=>"children"in t;var jt=(t,e)=>e?t.attachFromSubgraph??t.fromSubgraph??t.from:t.attachToSubgraph??t.toSubgraph??t.to;var mL=t=>kr(t)?t.nodes:[t];function Ud(t,e,r){const i=jt(t,e),n=e?t.startDir:t.endDir;const o=e?t.cellAllocation.startOffset:t.cellAllocation.endOffset;const s=n.x!==1,a=s?r.maxY-r.minY:r.maxX-r.minX;const l=kr(i)&&s?Yi(i.name)+1:1;if(!Number.isSafeInteger(o)||o<l||o>=a)return void 0;return s?{x:n.x===0?r.minX:r.maxX,y:r.minY+o}:{x:r.minX+o,y:n.y===0?r.minY:r.maxY}}var fL=t=>{const e=mL(t);return{minX:Math.min(...e.map(r=>r.gridCoord.x)),maxX:Math.max(...e.map(r=>r.gridCoord.x+2)),minY:Math.min(...e.map(r=>r.gridCoord.y)),maxY:Math.max(...e.map(r=>r.gridCoord.y+2))}};function Gv(t){const e=new Map;for(const r of t.edges){const i=r.bundle??r.sharedTrunk??r;const n=e.get(i)??[];n.push(r);e.set(i,n)}return new Map([...e.values()].flatMap(r=>r.map(i=>[i,r])))}function Wv(t){const e=new Map;const r=new Map;const i=new Set;for(const n of t.edges){if(n.style==="invisible")continue;const o=jt(n,true),s=jt(n,false);if(kr(o)||kr(s)||o===s)i.add(n);const a=e.get(o)??new Map;const l=a.get(s)??[];l.push(n);a.set(s,l);e.set(o,a);const c=e.get(s)?.get(o)??[];if(l.length>=2||(kr(o)||kr(s))&&(o===s||c.length)){for(const d of[...l,...c])i.add(d)}for(const d of[true,false]){const u=d?o:s,h=d?n.startDir:n.endDir;const m=r.get(u)??new Map,f=`${h.x},${h.y}`;const p=m.get(f)??new Map;const g=d?n.hasArrowStart:n.hasArrowEnd;const y=g?(d?n.startMarker:n.endMarker)??"arrow":"line";const C=p.get(y)??[];C.push(n);p.set(y,C);m.set(f,p);r.set(u,m)}}for(const n of r.values())for(const o of n.values())if(o.size>1){for(const s of o.values())for(const a of s)i.add(a)}return i}function Uv(t,e,r){if(!r.size)return;const i=new Map;const n=h=>{let m=i.get(h);if(!m){m=fL(h);i.set(h,m)}return m};let o=e();const s=h=>kr(h)?h:o.get(h);const a=new Map;const l=new Map(t.subgraphs.flatMap(h=>h.nodes.map(m=>[m,h])));const c=(h,m,f)=>{const p=a.get(h)??new Map;const g=p.get(m)??{extent:1+(kr(h)&&(m===$e||m===Pe)?Yi(h.name):0),count:0};p.set(m,{extent:g.extent+f+2,count:g.count+1});a.set(h,p);return g.extent+Math.floor(f/2)};for(const h of t.edges){if(h.style==="invisible"||!r.has(h))continue;const m=jt(h,true),f=jt(h,false),p=s(m),g=s(f);const y=p.maxX<g.minX||g.maxX<p.minX,C=p.maxY<g.minY||g.maxY<p.minY;const w=Math.abs(p.minX+p.maxX-g.minX-g.maxX),x=Math.abs(p.minY+p.maxY-g.minY-g.maxY);const k=y&&!C||y===C&&(w>x||w===x&&t.config.graphDirection==="LR");const b=k?p.minX<g.minX:p.minY<g.minY;h.startDir=k?b?Pe:$e:b?We:je;h.endDir=k?b?$e:Pe:b?je:We;if(m===f){h.startDir=Pe;h.endDir=Pe}else if(!y&&!C){h.startDir=Pe;h.endDir=$e}const A=h.startDir===$e||h.startDir===Pe?Yi(h.text):Math.max(1,$a(h.text));h.cellAllocation={startOffset:c(m,h.startDir,A),endOffset:c(f,h.endDir,A)}}for(const h of t.edges)if(h.cellAllocation){for(const m of[true,false]){const f=jt(h,m),p=m?h.startDir:h.endDir;const g=a.get(f).get(p).count;const y=Wd+2*(g-1);if(m)h.cellAllocation.startEscape=y;else h.cellAllocation.endEscape=y}}for(const[h,m]of a){const f=kr(h)?h.parent:l.get(h);if(!f)continue;for(const[p,g]of m){const y=p===$e?"left":p===Pe?"right":p===je?"top":"bottom";f.insets??={};f.insets[y]=Math.max(f.insets[y]??2,Wd+2*(g.count-1)+1+1)}}for(const[h,m]of a)if(!kr(h))for(const[f,p]of m){const g=f===$e||f===Pe;const y=g?h.gridCoord.y+1:h.gridCoord.x+1;const C=g?t.rowHeight:t.columnWidth;C.set(y,Math.max(C.get(y)??0,p.extent))}if([...a.keys()].some(kr))o=e();const d=new Map,u=new Map;for(const[h,m]of a){const f=n(h),p=s(h);for(const[g,y]of m){const C=g===$e||g===Pe;if(kr(h)){const k=C?p.maxY-p.minY:p.maxX-p.minX;const b=Math.max(0,y.extent-k);const A=(C?f.minY:f.minX)+1;const L=C?u:d;L.set(A,Math.max(L.get(A)??0,b))}const w=C?t.columnWidth:t.rowHeight;const x=C?g===$e?f.minX-1:f.maxX:g===je?f.minY-1:f.maxY;if(x>=0)w.set(x,Math.max(w.get(x)??0,Wd+1+y.count*2))}}for(const[h,m]of d)t.columnWidth.set(h,(t.columnWidth.get(h)??0)+m);for(const[h,m]of u)t.rowHeight.set(h,(t.rowHeight.get(h)??0)+m);o=e();d.clear();u.clear();for(const h of t.edges){if(!h.cellAllocation)continue;const m=jt(h,true),f=jt(h,false);if(m===f)continue;const p=h.startDir===$e||h.startDir===Pe;const g=s(m),y=s(f),C=n(m),w=n(f);const x=p?"minX":"minY",k=p?"maxX":"maxY";if(C[k]>=w[x]&&w[k]>=C[x])continue;const b=C[k]<w[x]?g:y,A=b===g?y:g;const L=Math.max(C[x],w[x])-1;const B=p?$a(h.text):Yi(h.text);const O=B+Gr(h,true)+Gr(h,false)+4+(p&&Yi(h.text)>1?4:0);const M=Math.max(0,O-(A[x]-b[k]));const E=p?d:u;E.set(L,Math.max(E.get(L)??0,M))}for(const[h,m]of d)t.columnWidth.set(h,(t.columnWidth.get(h)??0)+m);for(const[h,m]of u)t.rowHeight.set(h,(t.rowHeight.get(h)??0)+m)}function jv(t){const e=s=>!!s&&(s.kind!=="stroke"||s.owners.some(a=>a.kind==="node"));const r=new Set;let i=0,n=0;for(const[s,a,l]of t.entries()){if(e(l)){i=Math.max(i,s);n=Math.max(n,a)}if(l.kind==="text"&&l.textBlock)r.add(l.textBlock)}const o=new Map;for(const s of r)for(let a=s.y;a<s.y+s.height;a++){const l=o.get(a)??[];l.push({left:s.x,right:s.x+s.width});o.set(a,l)}return{extent:{maxX:i,maxY:n},has(s){const a=s.indexOf(",");const l=Number(s.slice(0,a)),c=Number(s.slice(a+1));return e(t.cell(l,c))||!!o.get(c)?.some(d=>l>=d.left&&l<d.right)}}}function Vd(t,e){if(!e)return t;const r=[t[0]];for(let i=1;i<t.length;i++){const n=t[i-1],o=t[i];const s=Math.sign(o.x-n.x),a=Math.sign(o.y-n.y);if(s&&a){r.push(o);continue}const l=Math.abs(o.x-n.x)+Math.abs(o.y-n.y);let c=false;for(let p=1;p<l;p++)if(e.has(`${n.x+s*p},${n.y+a*p}`)){c=true;break}if(!c||l<4){r.push(o);continue}const d={x:n.x+s,y:n.y+a};const u={x:o.x-s*2,y:o.y-a*2};const h=new Set([`${n.x},${n.y}`,`${o.x},${o.y}`,`${o.x-s},${o.y-a}`]);const m={extent:e.extent,has:p=>h.has(p)||e.has(p)};const f=!e.has(`${d.x},${d.y}`)&&!e.has(`${u.x},${u.y}`)?St(m,d,u,_t(n,o)):null;if(f)r.push(...Nt(f),o);else r.push(o)}return ip(r)}function pL(t,e){return gL(t,e)}function gL(t,e){const r=t.gridCoord;const i=e.config.useAscii;let n=0;for(let d=0;d<2;d++){n+=e.columnWidth.get(r.x+d)??0}let o=0;for(let d=0;d<2;d++){o+=e.rowHeight.get(r.y+d)??0}const s={x:0,y:0};const a={x:n,y:o};const l=Ct(Math.max(s.x,a.x),Math.max(s.y,a.y));const c=e.subgraphs.filter(d=>d.nodes.includes(t)).at(-1);return l.scope({id:t.name,kind:"node",...c?{parent:{id:c.id,kind:e.containerKind??"subgraph"}}:{}},()=>{l.fill(1,1,Math.max(0,n-1),Math.max(0,o-1));const d=Qt(t.shape,i);const u=t.shape==="state-end";const h={ascii:i,role:"border",style:u?"double":"solid"};for(let x=s.x+1;x<a.x;x++){l.stroke(x,s.y,10,h);l.stroke(x,a.y,10,h)}for(let x=s.y+1;x<a.y;x++){l.stroke(s.x,x,5,h);l.stroke(a.x,x,5,h)}const m=t.shape==="rectangle"||t.shape==="service";const f=!i&&(t.shape==="rounded"||t.shape==="cylinder");const p=u?i?{tl:"#",tr:"#",bl:"#",br:"#"}:{tl:"\u2554",tr:"\u2557",bl:"\u255A",br:"\u255D"}:d;for(const[x,k,b,A]of[[s.x,s.y,6,p.tl],[a.x,s.y,12,p.tr],[s.x,a.y,3,p.bl],[a.x,a.y,9,p.br]]){if(m||f||u&&!i)l.stroke(x,k,b,{...h,rounded:f});else l.put(x,k,A,{role:"border",kind:"marker"})}const g=t.displayLabel;const y=It(g);const C=s.y+Math.floor(o/2);const w=C-Math.floor((y.length-1)/2);for(let x=0;x<y.length;x++){const k=y[x];const b=s.x+Math.floor(n/2)-Math.ceil(ne(k)/2)+1;Cr(l,{x:b,y:w+x},k,true)}for(const[,,x]of l.entries()){const k=Ar(x.kind==="text"?t.styleClass.styles.color:t.styleClass.styles.stroke);if(k)x.color=k}return l})}function Jv(t,e){return pL(t,e)}function xn(t,e,r=1,i={}){let n=0;for(const m of t){for(const f of m){n=Math.max(n,ne(f))}}const o=n+2*r;const s=Math.max(o+2,i.width??0);let a=0;for(const m of t){a+=Math.max(m.length,1)}const l=t.length-1;const c=Math.max(a+l+2,i.height??0);const d=Ct(s-1,c-1);const u={ascii:e,role:"border"};d.stroke(0,0,6,u);d.stroke(s-1,0,12,u);d.stroke(0,c-1,3,u);d.stroke(s-1,c-1,9,u);for(let m=1;m<s-1;m++){d.stroke(m,0,10,u);d.stroke(m,c-1,10,u)}for(let m=1;m<c-1;m++){d.stroke(0,m,5,u);d.stroke(s-1,m,5,u)}let h=1;for(let m=0;m<t.length;m++){const f=t[m];const p=f.length>0?f:[""];for(const g of p){const y=1+r;Cr(d,{x:y,y:h},g,true);h++}if(m<t.length-1){d.stroke(0,h,7,u);for(let g=1;g<s-1;g++)d.stroke(g,h,10,u);d.stroke(s-1,h,13,u);h++}}return d}function Qv(t,e,r,i,n,o,s="solid"){const a=_t(e,r);const l=[];const c={ascii:o,style:s==="thick"?"heavy":s==="dotted"?"dotted":"solid"};if(Oe(a,je)){for(let d=e.y-i;d>=r.y-n;d--){l.push({x:e.x,y:d});t.stroke(e.x,d,5,c)}}else if(Oe(a,We)){for(let d=e.y+i;d<=r.y+n;d++){l.push({x:e.x,y:d});t.stroke(e.x,d,5,c)}}else if(Oe(a,$e)){for(let d=e.x-i;d>=r.x-n;d--){l.push({x:d,y:e.y});t.stroke(d,e.y,10,c)}}else if(Oe(a,Pe)){for(let d=e.x+i;d<=r.x+n;d++){l.push({x:d,y:e.y});t.stroke(d,e.y,10,c)}}else if(Oe(a,dr)){for(let d=e.x-i;d>=r.x;d--){l.push({x:d,y:e.y});t.stroke(d,e.y,10,c)}for(let d=e.y-1;d>=r.y-n;d--){l.push({x:r.x,y:d});t.stroke(r.x,d,5,c)}}else if(Oe(a,xr)){for(let d=e.x+i;d<=r.x;d++){l.push({x:d,y:e.y});t.stroke(d,e.y,10,c)}for(let d=e.y-1;d>=r.y-n;d--){l.push({x:r.x,y:d});t.stroke(r.x,d,5,c)}}else if(Oe(a,br)){for(let d=e.x-i;d>=r.x;d--){l.push({x:d,y:e.y});t.stroke(d,e.y,10,c)}for(let d=e.y+1;d<=r.y+n;d++){l.push({x:r.x,y:d});t.stroke(r.x,d,5,c)}}else if(Oe(a,Fr)){const d=r.x-e.x;if(d<=1){for(let u=e.y+i;u<=r.y+n;u++){l.push({x:e.x,y:u});t.stroke(e.x,u,5,c)}}else{for(let u=e.x+i;u<=r.x;u++){l.push({x:u,y:e.y});t.stroke(u,e.y,10,c)}for(let u=e.y+1;u<=r.y+n;u++){l.push({x:r.x,y:u});t.stroke(r.x,u,5,c)}}}return l}function rp(t,e,r,i){const n={x:0,y:0};if(e.routeClass!=="feedback"&&e.routeClass!=="container"||e.bundle||e.path.length!==2)return n;const o=r.y===i.y&&(Oe(e.startDir,$e)||Oe(e.startDir,Pe))&&(Oe(e.endDir,$e)||Oe(e.endDir,Pe));const s=r.x===i.x&&(Oe(e.startDir,je)||Oe(e.startDir,We))&&(Oe(e.endDir,je)||Oe(e.endDir,We));if(!o&&!s)return n;const a=t.edges.find(c=>c!==e&&c.from===e.to&&c.to===e.from);if(!a)return n;if(e.routeClass==="container"&&t.edges.indexOf(e)<t.edges.indexOf(a))return n;const l=(c,d,u,h)=>{if(d)return o?u.y+h>d.minY+It(d.name).length&&u.y+h<d.maxY:u.x+h>d.minX&&u.x+h<d.maxX;if(!c.drawing||!c.drawingCoord)return false;const[m,f]=Jf(c.drawing);return o?u.y+h>c.drawingCoord.y&&u.y+h<c.drawingCoord.y+f:u.x+h>c.drawingCoord.x&&u.x+h<c.drawingCoord.x+m};for(const c of[1,-1])if(l(e.from,e.fromSubgraph,r,c)&&l(e.to,e.toSubgraph,i,c))return o?{x:0,y:c}:{x:c,y:0};return n}function yL(t,e,r){if(e.style==="invisible"){const k=at(t.canvas);return[k,k,k,k,k]}if(e.cellRoute){const k=e.cellRoute.points;if(k.length<2)return Array.from({length:5},()=>at(t.canvas));us(t,e,k[0],k.at(-1));const[b,A,L]=za(t,k,e.style);const B=tp(t,e.startDir,k[0]);const O=e.hasArrowEnd?ep(t,A.at(-1),L.at(-1),e.endMarker):at(t.canvas);const M=e.hasArrowStart?ep(t,[k[0]],ds(L[0]),e.startMarker):at(t.canvas);return[b,B,O,M,Ga(t,k)]}if(!e.path.length){const k=at(t.canvas);return[k,k,k,k,k]}if(e.attachToSubgraph||e.attachFromSubgraph||e.toSubgraph||e.fromSubgraph){return xL(t,e,r)}const i=Zt(t,e.from,e.startDir,e.startPort);const n=Zt(t,e.to,e.endDir,e.endPort);const o=rp(t,e,i,n);const s={x:i.x+o.x,y:i.y+o.y};const a={x:n.x+o.x,y:n.y+o.y};let l=e.path.map((k,b)=>b===0?s:b===e.path.length-1?a:er(t,k));const c=!!e.startPort||!Oe(_t(s,l[1]),e.startDir);const d=!!e.endPort||!Oe(_t(l.at(-2),a),ds(e.endDir));if(c||d){const k=(b,A)=>({x:b.x+(A.x-1)*2,y:b.y+(A.y-1)*2});l=[s,...c?[k(s,e.startDir)]:[],...l.slice(1,-1),...d?[k(a,e.endDir)]:[],a]}const u=Vd(l,r);const h=c||d||u.length!==l.length||u.some((k,b)=>!Pa(k,l[b]));us(t,e,s,a);const[m,f,p]=h?za(t,u,e.style):CL(t,e.path,e.style,s,a);const g=e.from.shape==="state-start"||e.from.shape==="state-end";const y=g?at(t.canvas):tp(t,e.startDir,s);let C;if(e.hasArrowEnd){C=ep(t,f[f.length-1],p[p.length-1],e.endMarker)}else{C=at(t.canvas)}const w=at(t.canvas);if(e.hasArrowStart)w.marker(s.x,s.y,so(e.startMarker,Hi(ds(e.startDir))??"T",t.config.useAscii));const x=h?Ga(t,u):SL(t,e.path);return[m,y,C,w,x]}function xL(t,e,r){const i=at(t.canvas);const n=e.attachFromSubgraph??e.fromSubgraph;const o=e.attachToSubgraph??e.toSubgraph;let s=e.path.map((y,C)=>C===0&&!n?Zt(t,e.from,e.startDir,e.startPort):C===e.path.length-1&&!o?Zt(t,e.to,e.endDir,e.endPort):er(t,y));s=ip(s);if(s.length<2)return[i,i,i,i,i];if(n){s=Vv(s,n,"start")}if(o){s=Vv(s,o,"end")}if(s.length<2)return[i,i,i,i,i];const a=rp(t,e,s[0],s.at(-1));if(a.x||a.y)s=s.map(y=>({x:y.x+a.x,y:y.y+a.y}));s=Vd(s,r);const l=(y,C,w)=>!y?w:C.x===y.minX?$e:C.x===y.maxX?Pe:C.y===y.minY?je:We;const c=l(n,s[0],e.startDir);us(t,e,s[0],s.at(-1),c,l(o,s.at(-1),e.endDir));const d=at(t.canvas);const u=t.config.useAscii;const h=!o;for(let y=1;y<s.length;y++){const C=s[y-1];const w=s[y];if(Pa(C,w))continue;const x=y===s.length-1;const k=1;let b;if(x){b=h?-1:0}else{b=-1}Qv(d,C,w,k,b,u,e.style)}const m=at(t.canvas);for(let y=1;y<s.length-1;y++){const C=s[y-1];const w=s[y];const x=s[y+1];const k=_t(C,w);const b=_t(w,x);m.stroke(w.x,w.y,Zv(k,b),{ascii:u})}const f=at(t.canvas);if(e.hasArrowEnd&&s.length>=2){const y=s[s.length-1];const C=s[s.length-2];const w=_t(C,y);if(o){f.marker(y.x,y.y,so(e.endMarker,Hi(w)??"B",u))}else{const x=bL(y,w);f.marker(x.x,x.y,so(e.endMarker,Hi(w)??"B",u))}}const p=at(t.canvas);if(e.hasArrowStart&&s.length>=2){const y=s[0];const C=s[1];const w=_t(C,y);p.marker(y.x,y.y,so(e.startMarker,Hi(w)??"T",u))}const g=e.from.shape==="state-start"||e.from.shape==="state-end"?i:tp(t,c,s[0]);return[d,g,f,p,m]}function bL(t,e){if(Oe(e,je))return{x:t.x,y:t.y+1};if(Oe(e,We))return{x:t.x,y:t.y-1};if(Oe(e,$e))return{x:t.x+1,y:t.y};if(Oe(e,Pe))return{x:t.x-1,y:t.y};return{x:t.x,y:t.y}}function ip(t){const e=[];for(const i of t){const n=e[e.length-1];if(n&&Pa(n,i))continue;e.push({x:i.x,y:i.y})}const r=[];for(let i=0;i<e.length;i++){if(i>0&&i<e.length-1){const n=e[i-1];const o=e[i];const s=e[i+1];const a=n.y===o.y&&o.y===s.y;const l=n.x===o.x&&o.x===s.x;const c=(o.x-n.x)*(s.x-o.x)+(o.y-n.y)*(s.y-o.y)>0;if((a||l)&&c)continue}r.push(e[i])}return r}function Vv(t,e,r){const i=s=>s.x>e.minX&&s.x<e.maxX&&s.y>e.minY&&s.y<e.maxY;if(r==="end"){for(let l=1;l<t.length;l++){const c=t[l-1];const d=t[l];if(!i(c)&&i(d)){const u=qa(c,d,e);return[...t.slice(0,l),u]}if(i(c)){const u=qa(t[Math.max(0,l-2)]??c,c,e);return[...t.slice(0,l-1),u]}}const s=t[t.length-1];const a=t[t.length-2];return[...t.slice(0,t.length-1),qa(a,s,e)]}for(let s=t.length-2;s>=0;s--){const a=t[s+1];const l=t[s];if(!i(a)&&i(l)){const c=qa(a,l,e);return[c,...t.slice(s+1)]}if(i(a))continue}const n=t[0];const o=t[1];return[qa(o,n,e),...t.slice(1)]}function qa(t,e,r){if(t.y===e.y){const i=t.x<e.x?r.minX:r.maxX;return{x:i,y:e.y}}if(t.x===e.x){const i=t.y<e.y?r.minY:r.maxY;return{x:e.x,y:i}}return{x:Math.max(r.minX,Math.min(r.maxX,e.x)),y:Math.max(r.minY,Math.min(r.maxY,e.y))}}function Hi(t){if(Oe(t,je))return"T";if(Oe(t,Pe))return"R";if(Oe(t,We))return"B";if(Oe(t,$e))return"L"}function jd(t){const e=Hi(t);return e==="T"?1:e==="R"?2:e==="B"?4:e==="L"?8:0}function Zv(t,e){return jd(ds(t))|jd(e)||15}function np(t,e,r,i,n=We){t.marker(e.x,e.y,{shape:"arrow",direction:Hi(r)??Hi(n)??"B",ascii:i})}function ds(t){if(Oe(t,je))return We;if(Oe(t,We))return je;if(Oe(t,$e))return Pe;if(Oe(t,Pe))return $e;if(Oe(t,dr))return Fr;if(Oe(t,xr))return br;if(Oe(t,br))return xr;if(Oe(t,Fr))return dr;return mi}function CL(t,e,r="solid",i,n){return za(t,e.map((o,s)=>s===0&&i?i:s===e.length-1&&n?n:er(t,o)),r)}function za(t,e,r){const i=at(t.canvas);const n=[],o=[];for(let s=1;s<e.length;s++){const a=e[s-1],l=e[s];if(Pa(a,l))continue;const c=Qv(i,a,l,1,-1,t.config.useAscii,r);if(!c.length)c.push(a);n.push(c);o.push(_t(a,l))}return[i,n,o]}function Ga(t,e){const r=at(t.canvas);for(let i=1;i<e.length-1;i++){const n=e[i];const o=_t(e[i-1],n),s=_t(n,e[i+1]);if(!Oe(o,s))r.stroke(n.x,n.y,Zv(o,s),{ascii:t.config.useAscii})}return r}function tp(t,e,r){const i=at(t.canvas);if(t.config.useAscii)return i;const n=jd(e);if(n)i.stroke(r.x,r.y,n|(n&5?10:5));return i}function so(t,e,r){return{shape:t==="circle"?"wide-circle":t==="cross"?"cross":"arrow",direction:e,ascii:r}}function ep(t,e,r,i){if(i==="circle"||i==="cross"){const n=at(t.canvas);if(e.length===0)return n;const o=e[e.length-1];n.marker(o.x,o.y,so(i,Hi(r)??"B",t.config.useAscii));return n}return kL(t,e,r)}function kL(t,e,r){const i=at(t.canvas);if(e.length===0)return i;const n=e[0];const o=e[e.length-1];let s=_t(n,o);if(e.length===1||Oe(s,mi))s=r;np(i,o,s,t.config.useAscii,r);return i}function SL(t,e){return Ga(t,e.map(r=>er(t,r)))}function wL(t,e){if(!e.text.length||e.style==="invisible")return void 0;if(e.cellRoute){const d=e.cellRoute.label;if(!d)return void 0;const u=Ar(e.inlineStyle?.color??e.inlineStyle?.stroke);return{owner:yi(t,e),rows:It(e.text).map((h,m)=>({x:d.x,y:d.y+m,text:mt(h)})),...u?{color:u}:{}}}const r=e.fromSubgraph?Yv(t,e.fromSubgraph,e.from,e.startDir):Zt(t,e.from,e.startDir);const i=e.toSubgraph?Yv(t,e.toSubgraph,e.to,e.endDir):Zt(t,e.to,e.endDir);const n=e.attachFromSubgraph||e.attachToSubgraph?{x:0,y:0}:rp(t,e,r,i);const o=eE(t,e.labelLine).map(d=>({x:d.x+n.x,y:d.y+n.y}));const s=t.edges.some(d=>d!==e&&d.from===e.to&&d.to===e.from);let a;if(s&&e.path.length>=2){const d=e.path[0].y;const u=e.path[e.path.length-1].y;if(u<d)a=true;else if(u>d)a=false}const l=e.path.length>=2&&e.path[e.path.length-1].x<e.path[0].x;const c=Ar(e.inlineStyle?.color??e.inlineStyle?.stroke);return{owner:yi(t,e),rows:TL(o,e.text,a,l),...c?{color:c}:{}}}function TL(t,e,r,i=false){if(t.length<2)return[];const n=Math.min(t[0].x,t[1].x);const o=Math.max(t[0].x,t[1].x);const s=Math.min(t[0].y,t[1].y);const a=Math.max(t[0].y,t[1].y);const l=n+Math.floor((o-n)/2);let c=s+Math.floor((a-s)/2);if(r!==void 0&&n===o){const h=a-s;const m=Math.max(1,Math.floor(h/4));if(r){c=c+m}else{c=c-m}}const d=It(e);const u=c-Math.floor((d.length-1)/2);return d.map((h,m)=>{const f=mt(h);const p=l-Math.floor(f.width/2)+(i?1:0);return{x:p,y:u+m,text:f}})}function Zt(t,e,r,i){const n=e.gridCoord;let o=0;for(let c=0;c<2;c++){o+=t.columnWidth.get(n.x+c)??0}let s=0;for(let c=0;c<2;c++){s+=t.rowHeight.get(n.y+c)??0}const a={width:o+1,height:s+1,labelArea:{x:0,y:0,width:0,height:0},gridColumns:[0,0,0],gridRows:[0,0,0]};const l=e.drawingCoord;if(i){const c=Hi(r);const d=ji({x:l.x+1,y:l.y+1,width:o+1,height:s+1},c,i.index,i.count);return{x:d.x-1-(r.x-1),y:d.y-1-(r.y-1)}}return zv(e.shape,r,a,l)}function cs(t,e,r){return Math.max(e,Math.min(r,t))}function Yv(t,e,r,i){const n=Zt(t,r,i);if(Oe(i,je)){return{x:cs(n.x,e.minX+1,e.maxX-1),y:e.minY}}if(Oe(i,We)){return{x:cs(n.x,e.minX+1,e.maxX-1),y:e.maxY}}if(Oe(i,$e)){return{x:e.minX,y:cs(n.y,e.minY+1,e.maxY-1)}}if(Oe(i,Pe)){return{x:e.maxX,y:cs(n.y,e.minY+1,e.maxY-1)}}return n}function vL(t,e,r,i){const n=at(t.canvas);if(!e.pathToJunction||e.pathToJunction.length===0){return[n,n,n,n,n]}const o=t.config.useAscii;const s=Vd(e.pathToJunction.map((d,u)=>{if(r.type==="fan-in"&&u===0){return Zt(t,e.from,e.startDir)}if(r.type==="fan-out"&&u===e.pathToJunction.length-1){return Zt(t,e.to,e.endDir)}return er(t,d)}),i);const[a]=za(t,s,e.style);const l=Ga(t,s);const c=at(t.canvas);if(r.type==="fan-in"&&e.pathToJunction.length>=2){const d=s[0];const u=_t(s[0],s[1]);if(!o){const h=jd(u);if(h)c.stroke(d.x,d.y,h|(h&5?10:5))}}return[a,c,n,n,l]}function EL(t,e,r){if(e.sharedPath.length<2)return[at(t.canvas),at(t.canvas)];const i=e.edges[0]?.style??"solid";const n=t.config.graphDirection;const o=Vd(e.sharedPath.map((a,l)=>{if(e.type==="fan-in"&&l===e.sharedPath.length-1){const c=n==="TD"?je:$e;return Zt(t,e.sharedNode,c)}if(e.type==="fan-out"&&l===0){const c=n==="TD"?We:Pe;return Zt(t,e.sharedNode,c)}return er(t,a)}),r);const[s]=za(t,o,i);return[s,Ga(t,o)]}function ML(t,e){const r=at(t.canvas);if(e.sharedPath.length<2)return r;const i=e.sharedPath.length-1;const n=e.sharedPath[i-1];const o=e.sharedPath[i];const s=_t(n,o);const a=t.config.graphDirection;const l=a==="TD"?je:$e;const c=Zt(t,e.sharedNode,l);if(a==="TD")c.y-=1;else c.x-=1;np(r,c,s,t.config.useAscii);return r}function AL(t,e){const r=at(t.canvas);if(!e.pathToJunction||e.pathToJunction.length<2)return r;const i=e.pathToJunction.length-1;const n=e.pathToJunction[i-1];const o=e.pathToJunction[i];const s=_t(n,o);const a=t.config.graphDirection;const l=a==="TD"?je:$e;const c=Zt(t,e.to,l);if(a==="TD")c.y-=1;else c.x-=1;np(r,c,s,t.config.useAscii);return r}function OL(t,e){const r=at(t.canvas);if(!e.junctionPoint)return r;const i=er(t,e.junctionPoint);const n=t.config.useAscii;let o=false;let s=false;let a=false;let l=false;if(e.sharedPath.length>=2){const d=e.type==="fan-in"?0:e.sharedPath.length-1;const u=e.type==="fan-in"?1:e.sharedPath.length-2;const h=_t(e.sharedPath[d],e.sharedPath[u]);if(Oe(h,We))s=true;else if(Oe(h,je))o=true;else if(Oe(h,Pe))l=true;else if(Oe(h,$e))a=true}for(const d of e.edges){if(d.pathToJunction&&d.pathToJunction.length>=2){const u=e.type==="fan-in"?d.pathToJunction.length-1:0;const h=e.type==="fan-in"?d.pathToJunction.length-2:1;const m=_t(d.pathToJunction[h],d.pathToJunction[u]);if(Oe(m,We))o=true;else if(Oe(m,je))s=true;else if(Oe(m,Pe))a=true;else if(Oe(m,$e))l=true}}const c=(o?1:0)|(l?2:0)|(s?4:0)|(a?8:0);r.stroke(i.x,i.y,c||15,{ascii:n});return r}function BL(t,e){const r=t.maxX-t.minX;const i=t.maxY-t.minY;if(r<=0||i<=0)return Ct(0,0);const n={x:0,y:0};const o={x:r,y:i};const s=Ct(r,i);const a={ascii:e.config.useAscii};for(let l=n.x+1;l<o.x;l++){s.stroke(l,n.y,10,a);s.stroke(l,o.y,10,a)}for(let l=n.y+1;l<o.y;l++){s.stroke(n.x,l,5,a);s.stroke(o.x,l,5,a)}s.stroke(n.x,n.y,6,a);s.stroke(o.x,n.y,12,a);s.stroke(n.x,o.y,3,a);s.stroke(o.x,o.y,9,a);return s}function _L(t,e,r="subgraph"){const i=t.maxX-t.minX;const n=t.maxY-t.minY;if(i<=0||n<=0)return[Ct(0,0),{x:0,y:0}];const o=Ct(i,n);const s=It(t.name);o.scope({id:t.id,kind:r},()=>{for(let a=0;a<s.length;a++){const l=s[a];const c=1+a;let d=Math.floor(i/2)-Math.floor(ne(l)/2);if(d<1)d=1;if(c<n)Cr(o,{x:d,y:c},l,true)}});return[o,{x:t.minX,y:t.minY}]}function IL(t,e){const[r,i]=Jf(t.canvas);const n=Ct(r,i);for(const o of t.subgraphs){const s=o.children.filter(c=>c.concurrencyRegion&&c.nodes.length>0);if(s.length<2)continue;const a=Math.max(...s.map(c=>(c.minX+c.maxX)/2))-Math.min(...s.map(c=>(c.minX+c.maxX)/2));const l=Math.max(...s.map(c=>(c.minY+c.maxY)/2))-Math.min(...s.map(c=>(c.minY+c.maxY)/2));if(a>=l){const c=[...s].sort((d,u)=>d.minX-u.minX);for(let d=1;d<c.length;d++){const u=Math.round((c[d-1].maxX+c[d].minX)/2);const h=Math.max(o.minY+3,Math.min(...s.map(f=>f.minY)));const m=Math.min(o.maxY-1,Math.max(...s.map(f=>f.maxY)));for(let f=h;f<=m;f++)n.stroke(u,f,5,{ascii:t.config.useAscii,style:"dotted",owner:{id:o.id,kind:e},role:"border"})}}else{const c=[...s].sort((d,u)=>d.minY-u.minY);for(let d=1;d<c.length;d++){const u=Math.round((c[d-1].maxY+c[d].minY)/2);const h=Math.max(o.minX+1,Math.min(...s.map(f=>f.minX)));const m=Math.min(o.maxX-1,Math.max(...s.map(f=>f.maxX)));for(let f=h;f<=m;f++)n.stroke(f,u,10,{ascii:t.config.useAscii,style:"dotted",owner:{id:o.id,kind:e},role:"border"})}}}return n}function LL(t){function e(i){return i.parent===null?0:1+e(i.parent)}const r=[...t];r.sort((i,n)=>e(i)-e(n));return r}function yi(t,e){return{id:e.id??`edge#${e.sourceIndex??t.edges.indexOf(e)}:${e.from.name}->${e.to.name}`,kind:"edge",from:e.attachFromSubgraph?.id??e.fromSubgraph?.id??e.from.name,to:e.attachToSubgraph?.id??e.toSubgraph?.id??e.to.name,...e.bundle?{bundle:`bundle:${t.bundles.indexOf(e.bundle)}`}:e.sharedTrunk?{bundle:e.sharedTrunk}:{}}}function us(t,e,r,i,n=e.startDir,o=e.endDir){const s=yi(t,e);const a=l=>Oe(l,je)?"T":Oe(l,We)?"B":Oe(l,$e)?"L":"R";t.canvas.port(s,{nodeId:s.from,...r,side:a(n),end:"start"});t.canvas.port(s,{nodeId:s.to,...i,side:a(o),end:"end"});t.canvas.expectMarkers(s,"start",e.hasArrowStart?[so(e.startMarker,a(ds(n)),t.config.useAscii)]:[]);t.canvas.expectMarkers(s,"end",e.hasArrowEnd?[so(e.endMarker,a(ds(o)),t.config.useAscii)]:[],!e.cellRoute&&(e.attachToSubgraph||e.toSubgraph)?0:1)}function RL(t,e,r){const i=t.edges.filter(B=>B.cellAllocation);const n=new Set;if(!i.length)return n;const o=new Map;const s=new Map([...t.nodes,...t.subgraphs].map((B,O)=>[B,O]));let a=0;const l=B=>{const O=jt(B,true),M=jt(B,false);const E=s.get(O)<s.get(M)?O:M,_=E===O?M:O;const q=o.get(E)??new Map;const Q=q.get(_)??a++;q.set(_,Q);o.set(E,q);return Q};const c=new Map(i.map(B=>[B,l(B)]));i.sort((B,O)=>c.get(B)-c.get(O));const d=new Map;const u=new Map;const h=new Map(t.edges.filter(B=>!B.cellAllocation).map(B=>[yi(t,B).id,B]));for(const[B,O,M]of r.entries())if(M.kind==="stroke"&&M.owners.some(E=>E.kind==="edge")){const E=M.stroke?.mask??0;u.set(`${B},${O}`,(E&5?5:0)|(E&10?10:0))}const m=new Map;for(const[,,B]of r.entries())if(B.textBlock)for(const O of B.owners){const M=O.kind==="edge"?h.get(O.id):void 0;if(M){const E=m.get(B.textBlock)??new Set;E.add(M);m.set(B.textBlock,E)}}const f=new Map;const p=new Map;const g=new Map;const y=new Map;const C=new Map;let w;const x=(B,O,M)=>({x:B.x+(O.x-1)*M,y:B.y+(O.y-1)*M});const k=(B,O,M)=>O>=B.x-(B.height>1?1:0)&&O<B.x+B.width&&M>=B.y&&M<B.y+B.height;const b=(B,O)=>{const M=jt(B,O);return Ud(B,O,"children"in M?M:{minX:M.drawingCoord.x,minY:M.drawingCoord.y,maxX:M.drawingCoord.x+M.drawing.width-1,maxY:M.drawingCoord.y+M.drawing.height-1})};for(const B of i){const O=b(B,true),M=b(B,false);if(!O||!M){B.cellRoute={points:[]};t.canvas.report({code:"TERMINAL_GEOMETRY_COLLISION",feature:`edge-face:${yi(t,B).id}`,message:"The final endpoint envelope has insufficient usable face capacity for its allocated physical port."});continue}f.set(B,[O,M]);for(const[E,_,q]of[[true,O,B.startDir],[false,M,B.endDir]])for(let Q=0;Q<=Gr(B,E);Q++){const $=x(_,q,Q),D=`${$.x},${$.y}`;if(Q>0&&e.has(D)&&!C.has(B))C.set(B,$);const P=r.cell($.x,$.y);if(P)for(const G of P.owners){const se=G.kind==="edge"?h.get(G.id):void 0;if(se)n.add(se)}for(const[G,se]of m)if($.x>=G.x&&$.x<G.x+G.width&&$.y>=G.y&&$.y<G.y+G.height){for(const ce of se)n.add(ce)}const U=g.get(D);if(U&&(U.edge!==B||U.start!==E)){y.set(U.edge,$);y.set(B,$)}else g.set(D,{edge:B,start:E});const j=p.get(D)??new Set;j.add(B);p.set(D,j)}}if(n.size)return n;for(const[B,O]of C){const[M,E]=f.get(B);B.cellRoute={points:[]};us(t,B,M,E);f.delete(B);t.canvas.report({code:"TERMINAL_GEOMETRY_COLLISION",feature:`edge-lane:${yi(t,B).id}`,cell:{column:O.x,row:O.y},message:"Allocated physical ports have an approach blocked by protected terminal content before routing."})}for(const[B,O]of y)if(f.has(B)){B.cellRoute={points:[]};f.delete(B);t.canvas.report({code:"TERMINAL_GEOMETRY_COLLISION",feature:`edge-approach:${yi(t,B).id}`,cell:{column:O.x,row:O.y},message:"Allocated physical endpoint approach corridors overlap before routing."})}if(y.size||C.size)for(const[B,O]of p){for(const M of O)if(y.has(M)||C.has(M))O.delete(M);if(!O.size)p.delete(B)}for(const B of i){if(!f.has(B))continue;if(!B.text)continue;const[O,M]=f.get(B),E=mt(B.text);const _=jt(B,true)===jt(B,false)?{x:O.x+4,y:Math.floor((O.y+M.y-E.height+1)/2)}:{x:Math.floor((O.x+M.x-E.width+1)/2),y:Math.floor((O.y+M.y-E.height+1)/2)};const q=$=>{const D=E.height>1?1:0;if($.x<D||$.y<0)return false;for(let P=$.y;P<$.y+E.height;P++)for(let U=$.x-D;U<$.x+E.width;U++){if(r.cell(U,P)||e.has(`${U},${P}`)||p.has(`${U},${P}`))return false;for(const j of d.values())if(k(j,U,P))return false}return true};let Q=q(_)?_:void 0;if(!Q){const $=new Set([_.x,0]),D=new Set([_.y,0]);for(const U of w??=t.canvas.regions()){const j=U.ownedCellSpans;$.add(Math.min(...j.map(G=>G.start))-E.width-1);$.add(Math.max(...j.map(G=>G.end))+1);D.add(Math.min(...j.map(G=>G.row))-E.height-1);D.add(Math.max(...j.map(G=>G.row))+2)}for(const U of d.values()){$.add(U.x-E.width-1);$.add(U.x+U.width+1);D.add(U.y-E.height-1);D.add(U.y+U.height+1)}const P=[...$].flatMap(U=>[...D].map(j=>({x:U,y:j}))).sort((U,j)=>Math.abs(U.x-_.x)+Math.abs(U.y-_.y)-Math.abs(j.x-_.x)-Math.abs(j.y-_.y)||U.y-j.y||U.x-j.x);Q=P.find(q)}if(Q)d.set(B,{...Q,width:E.width,height:E.height})}const A=[...d];const L={maxX:Math.max(e.extent.maxX,...A.map(([,B])=>B.x+B.width)),maxY:Math.max(e.extent.maxY,...A.map(([,B])=>B.y+B.height))};for(const B of i){if(!f.has(B))continue;const[O,M]=f.get(B),E=d.get(B);const _=x(O,B.startDir,Gr(B,true)),q=x(M,B.endDir,Gr(B,false));const Q=new Set([O,M,x(O,B.startDir,1),x(M,B.endDir,1)].map(se=>`${se.x},${se.y}`));const $={extent:L,has(se){if(Q.has(se)||e.has(se))return true;for(const Y of p.get(se)??[])if(Y!==B)return true;const[ce,ae]=se.split(",").map(Number);return A.some(([Y,V])=>Y!==B?k(V,ce,ae):V.height>1&&ce>=V.x&&ce<V.x+V.width&&ae>=V.y&&ae<V.y+V.height)}};const D=E?E.height>1?{x:E.x-1,y:E.y}:{x:E.x+Math.floor(E.width/2),y:E.y}:void 0;const P=E&&D?{x:D.x,y:D.y+E.height-1}:void 0;const U=(se,ce)=>{const ae=se.x===ce.x?5:10;return!((u.get(`${se.x},${se.y}`)??0)&ae)&&!((u.get(`${ce.x},${ce.y}`)??0)&ae)};const j=!$.has(`${_.x},${_.y}`)&&!$.has(`${q.x},${q.y}`)?St($,_,D??q,B.startDir,U):null;const G=P&&j?St($,P,q,B.endDir,U):[];if(j&&G&&(!B.text||E)){B.cellRoute={points:ip([O,...Nt(j),...P?[P]:[],...Nt(G).slice(1),M]),...E?{label:{x:E.x,y:E.y}}:{}};for(let se=1;se<B.cellRoute.points.length;se++){const ce=B.cellRoute.points[se-1],ae=B.cellRoute.points[se];const Y=Math.sign(ae.x-ce.x),V=Math.sign(ae.y-ce.y),N=Y?10:5;for(let J=ce.x,ee=ce.y;;J+=Y,ee+=V){const X=`${J},${ee}`;u.set(X,(u.get(X)??0)|N);if(J===ae.x&&ee===ae.y)break}}}else{B.cellRoute={points:[]};us(t,B,O,M);const se=!E&&B.text?"complete label rectangle":!j?"source-to-label route":"label-to-target route";t.canvas.report({code:"TERMINAL_GEOMETRY_COLLISION",feature:`edge-lane:${yi(t,B).id}`,...E?{cell:{column:E.x,row:E.y}}:{},message:`Bounded terminal routing could not allocate the ${se} between its physical ports.`})}}return n}function Hv(t,e){const r=new Set(e.map(n=>n.owner.id)),i=new Map;if(e.length)for(const[n,o,s]of t.entries()){if(s.kind!=="stroke"&&s.kind!=="marker")continue;for(const a of s.owners)if(a.kind==="edge"&&r.has(a.id)){const l=i.get(a.id)??[];l.push({x:n,y:o});i.set(a.id,l)}}return i}function Xv(t){const e=new Set;for(const r of t.regions())if(r.kind==="edge")for(const i of r.ports??[]){const n=i.side==="L"?-1:i.side==="R"?1:0;const o=i.side==="T"?-1:i.side==="B"?1:0;e.add(`${i.x},${i.y}`);e.add(`${i.x+n},${i.y+o}`)}return e}function Kv(t,e,r,i){let n=Infinity,o=Infinity,s=0,a=0;for(const g of e.rows){n=Math.min(n,g.x);o=Math.min(o,g.y);s=Math.max(s,g.x+g.text.width-1);a=Math.max(a,g.y+g.text.height-1)}const l=g=>e.owner.id===g.id&&e.owner.kind===g.kind;const c=(g,y,C)=>{if(n+g<0||o+y<0)return false;let w=false;for(let x=o;x<=a;x++)for(let k=n;k<=s;k++){if(i.has(`${k+g},${x+y}`))return false;const b=t.cell(k+g,x+y);if(b&&!(C&&b.kind==="stroke"&&b.owners.length&&b.owners.every(l)))return false;for(const[A,L]of[[k+g,x+y],[k+g-1,x+y],[k+g+1,x+y],[k+g,x+y-1],[k+g,x+y+1]]){if(t.cell(A,L)?.owners.some(l))w=true}}return w};const d=(g,y)=>{const C=at(t);C.scope(e.owner,()=>{for(const w of e.rows)C.textBlock(w.x+g,w.y+y,w.text,{role:"text",...e.color?{color:e.color}:{}})});return C};if(c(0,0,true))return{drawing:d(0,0),admitted:true};const u=new Map;const h=(g,y)=>{const C={x:g-n,y:y-o};if(g>=0&&y>=0)u.set(`${C.x},${C.y}`,C)};const m=s-n+1,f=a-o+1;for(const g of r){for(const y of[cs(o,g.y-f+1,g.y),g.y,g.y-f+1]){h(g.x-m,y);h(g.x+1,y)}for(const y of[cs(n,g.x-m+1,g.x),g.x,g.x-m+1]){h(y,g.y-f);h(y,g.y+1)}}const p=[...u.values()].sort((g,y)=>Math.abs(g.x)+Math.abs(g.y)-Math.abs(y.x)-Math.abs(y.y)||Math.abs(g.x)-Math.abs(y.x)||g.y-y.y||y.x-g.x);for(const g of p)if(c(g.x,g.y,false))return{drawing:d(g.x,g.y),admitted:true};for(let g=1;g<=24;g++)for(let y=0;y<=g;y++){const C=g-y;for(const[w,x]of[[y,-C],[y,C],[-y,-C],[-y,C]])if(c(w,x,false))return{drawing:d(w,x),admitted:true}}return{drawing:d(0,0),admitted:false}}function DL(t,e,r){const i=new Map(t.edges.map(l=>[yi(t,l).id,l]));const n=new Map;for(const l of e)for(const c of l)for(const[d,u,h]of c.entries()){const m=`${d},${u}`,f=n.get(m)??new Map;for(const p of h.owners){const g=p.kind==="edge"?i.get(p.id):void 0;if(!g)continue;const y=g.bundle??g.sharedTrunk??g;const C=f.get(y)??{edges:new Set,mask:0,marker:false};const w=h.stroke?.mask??0;C.edges.add(g);C.mask|=w;C.marker||=h.kind==="marker";f.set(y,C)}n.set(m,f)}const o=new Set;const s=new Map;for(const[l,c,d]of r.entries()){if(d.marker?.shape==="arrow")continue;const u=Pd(d);if(!u)continue;for(const h of d.owners){const m=h.kind==="edge"?i.get(h.id):void 0;if(!m||m.cellAllocation)continue;const f=s.get(m)??new Map;f.set(`${l},${c}`,u);s.set(m,f)}}const a={T:[0,-1,1,4],R:[1,0,2,8],B:[0,1,4,1],L:[-1,0,8,2]};for(const l of r.regions()){const c=l.kind==="edge"?i.get(l.id):void 0;if(!c||c.cellAllocation||c.style==="invisible")continue;const d=l.ports?.find(E=>E.end==="start"),u=l.ports?.find(E=>E.end==="end");if(!d?.side||!u?.side){o.add(c);continue}const[h,m,f,p]=a[d.side],[g,y,,C]=a[u.side];const w=u.x+g*(u.markerOffset??1),x=u.y+y*(u.markerOffset??1);let k=`${d.x+h},${d.y+m}`,b=`${w},${x}`;let A=p;const L=s.get(c);const B={T:"B",R:"L",B:"T",L:"R"};if(c.hasArrowStart&&(!c.startMarker||c.startMarker==="arrow")){const E=r.cell(d.x+h*(d.markerOffset??0),d.y+m*(d.markerOffset??0));if(E?.marker?.shape!=="arrow"||E.marker.direction!==B[d.side]){o.add(c);continue}}if(c.hasArrowEnd&&(!c.endMarker||c.endMarker==="arrow")){const E=r.cell(w,x);if(E?.marker?.shape!=="arrow"||E.marker.direction!==B[u.side]){o.add(c);continue}b=`${w+g},${x+y}`;if(k===`${w},${x}`&&b===`${d.x},${d.y}`&&(L?.get(b)??0)&f){k=b;A=f}}if(!((L?.get(k)??0)&A)||!((L?.get(b)??0)&C)){o.add(c);continue}const O=[k],M=new Set(O);for(let E=0;E<O.length&&!M.has(b);E++){const _=O[E],q=_.indexOf(","),Q=Number(_.slice(0,q)),$=Number(_.slice(q+1)),D=L.get(_);for(const[P,U,j,G]of Object.values(a)){const se=`${Q+P},${$+U}`;if(D&j&&(L.get(se)??0)&G&&!M.has(se)){M.add(se);O.push(se)}}}if(!M.has(b))o.add(c)}for(const l of n.values()){const c=[...l.values()];if(c.length<2)continue;const d=c.some(m=>m.marker);const u=c.filter(m=>m.mask&10).length>1;const h=c.filter(m=>m.mask&5).length>1;for(const m of c)if(d||u&&m.mask&10||h&&m.mask&5){for(const f of m.edges)o.add(f)}}return o}function hs(t){for(;;){const e=NL(t);if(e instanceof Set){if(!t.reserveRouteUnits?.(e))throw new Error("Terminal routing closure did not grow");continue}return e}}function NL(t){const e=t.containerKind??"subgraph";const r=t.canvas;const i=new Map(t.subgraphs.flatMap(b=>b.nodes.map(A=>[A.name,b.id])));for(const b of LL(t.subgraphs)){const A={id:b.id,kind:e,...b.parent?{parent:{id:b.parent.id,kind:e}}:{},members:[...b.nodes.filter(L=>!L.containerAnchor&&i.get(L.name)===b.id).map(L=>L.name),...b.children.map(L=>L.id)]};r.region(A,{x:b.minX,y:b.minY,width:b.maxX-b.minX+1,height:b.maxY-b.minY+1});if(!b.concurrencyRegion)r.overlay(BL(b,t).attribute(A,{role:"border"}),b.minX,b.minY)}r.overlay(IL(t,e));for(const b of t.nodes){if(!b.drawn&&b.drawingCoord&&b.drawing){const A={id:b.name,kind:"node",...i.has(b.name)?{parent:{id:i.get(b.name),kind:e}}:{}};r.overlay(b.drawing.attribute(A,{role:"border"}),b.drawingCoord.x,b.drawingCoord.y);b.drawn=true}}for(const b of t.subgraphs){if(b.nodes.length===0||b.concurrencyRegion)continue;const[A,L]=_L(b,t,e);r.overlay(A.attribute({id:b.id,kind:e},{role:"text"}),L.x,L.y)}const n=jv(r);const o=Array.from({length:7},()=>[]);const s=b=>yi(t,b);const a=new Map(t.edges.map(b=>[s(b).id,b.inlineStyle]));const l=(b,A,L,B)=>{const O=Array.isArray(L)?L[0]:L;const M=a.get(O.id);const E=Ar(B==="text"?M?.color??M?.stroke:M?.stroke);o[b].push(A.attribute(L,{role:B,...E?{color:E}:{},...B==="arrow"?{kind:"marker"}:{}}))};const c=[];const d=new Set;const u=b=>{for(const A of b){const L=s(A);const B=wL(t,A);if(B)c.push(B);if(A.bundle&&A.pathToJunction){const O=A.bundle;us(t,A,Zt(t,A.from,A.startDir),Zt(t,A.to,A.endDir));const[M,E,,,_]=vL(t,A,O,n);l(0,M,L,"line");l(1,_,L,"corner");l(4,E,L,"junction");if(!d.has(O)){d.add(O);const q=O.edges.map(s);const[Q,$]=EL(t,O,n);l(0,Q,q,"line");l(1,$,q,"corner");if(O.type==="fan-in")l(3,ML(t,O),q,"arrow");l(2,OL(t,O),q,"junction")}if(O.type==="fan-out"&&A.hasArrowEnd)l(3,AL(t,A),L,"arrow")}else{const[O,M,E,_,q]=yL(t,A,n);l(0,O,L,"line");l(1,q,L,"corner");l(3,E,L,"arrow");l(4,M,L,"junction");l(5,_,L,"arrow")}}};u(t.edges.filter(b=>!b.cellAllocation));const h=new Map;for(const b of t.edges)if(b.sharedTrunk){const A=h.get(b.sharedTrunk)??[];A.push(b);h.set(b.sharedTrunk,A)}for(const b of t.trunkJunctions){const A=(h.get(b.trunk)??[]).map(s);if(!A.length)continue;const L=er(t,b),B=r.blank();B.stroke(L.x,L.y,t.config.graphDirection==="LR"?t.config.reverseDirection?13:7:14,{ascii:t.config.useAscii});l(6,B,A,"junction")}const m=t.edges.filter(b=>b.cellAllocation);const f=m.length?r.blank():r;if(f!==r)f.overlay(r);for(const b of o)for(const A of b)f.overlay(A);const p=DL(t,o,f);if(p.size)return p;const g=[];const y=Xv(f),C=Hv(f,c);for(const b of c){const A=Kv(f,b,C.get(b.owner.id)??[],y);if(!A.admitted)return new Set(t.edges.filter(L=>s(L).id===b.owner.id));g.push(A.drawing);f.overlay(A.drawing)}if(!m.length)return r;c.length=0;const w=RL(t,jv(f),f);if(w.size)return w;u(m);for(let b=0;b<o.length;b++){for(const A of o[b])r.overlay(A)}for(const b of g)r.overlay(b);const x=Hv(r,c);const k=Xv(r);for(const b of c)r.overlay(Kv(r,b,x.get(b.owner.id)??[],k).drawing);for(const b of t.edges){if(!b.cellRoute||b.cellRoute.points.length||b.style==="invisible")continue;const A=s(b),L=`graph.${A.id}.route`;const B=E=>{if(!(E?b.hasArrowStart:b.hasArrowEnd))return"";const _=E?b.startMarker:b.endMarker;return _==="circle"?"o":_==="cross"?"x":E?"<":">"};const O=b.style==="dotted"?"-.-":b.style==="thick"?"==":"--";const M=`${A.from} ${B(true)}${O}${B(false)} ${A.to}${b.text?` : ${b.text}`:""}`;r.textBlock(0,r.height,mt(M),{owner:A,role:"text"});r.projectMarkers(A,L);r.report({code:"TERMINAL_FAMILY_PROJECTION",feature:L,message:"No complete terminal route was allocated; the authored relationship is retained in an owned endpoint summary."})}return r}function tE(t){const e=n=>({left:Math.min(...n.map(o=>o.gridCoord.x)),right:Math.max(...n.map(o=>o.gridCoord.x+2)),top:Math.min(...n.map(o=>o.gridCoord.y)),bottom:Math.max(...n.map(o=>o.gridCoord.y+2))});const r=t.subgraphs.some(n=>{if(!n.nodes.length)return false;const o=e(n.nodes);return t.nodes.some(s=>!n.nodes.includes(s)&&s.gridCoord.x<=o.right&&s.gridCoord.x+2>=o.left&&s.gridCoord.y<=o.bottom&&s.gridCoord.y+2>=o.top)});if(!r)return;t.compoundRepacked=true;const i=n=>{const o=n?n.children:t.subgraphs.filter(x=>!x.parent);const s=n?n.nodes:t.nodes;const a=new Set(o.flatMap(x=>x.nodes));const l=[...o.map(i),...s.filter(x=>!a.has(x)).map(x=>{x.gridCoord={x:0,y:0};return{nodes:[x],width:3,height:3,order:x.index}})].sort((x,k)=>x.order-k.order);const c=new Map(l.flatMap(x=>x.nodes.map(k=>[k,x])));const d=new Map(l.map(x=>[x,new Set]));for(const x of t.edges){const k=c.get(x.from),b=c.get(x.to);if(k&&b&&k!==b&&x.routeClass==="primary-forward")d.get(b).add(k)}const u=new Map,h=new Set(l);while(h.size){const x=[...h].find(k=>[...d.get(k)].every(b=>!h.has(b)))??[...h][0];u.set(x,Math.max(0,...[...d.get(x)].map(k=>(u.get(k)??-1)+1)));h.delete(x)}const m=n?.direction??t.config.graphDirection;const f=new Map;for(const x of l){const k=u.get(x);f.set(k,Math.max(f.get(k)??0,m==="LR"?x.width:x.height))}const p=new Map,g=new Map;let y=1;for(const x of[...f.keys()].sort((k,b)=>k-b)){p.set(x,y);y+=f.get(x)+2}let C=1,w=1;for(const x of l){const k=u.get(x),b=g.get(k)??1;const A=m==="LR"?p.get(k):b;const L=m==="LR"?b:p.get(k);for(const B of x.nodes){B.gridCoord.x+=A;B.gridCoord.y+=L}g.set(k,b+(m==="LR"?x.height:x.width)+2);C=Math.max(C,A+x.width+1);w=Math.max(w,L+x.height+1)}return{nodes:[...s],width:C,height:w,order:Math.min(...s.map(x=>x.index))}};i(null);t.grid.clear();for(const n of t.nodes)for(let o=0;o<3;o++)for(let s=0;s<3;s++){t.grid.set(ot({x:n.gridCoord.x+o,y:n.gridCoord.y+s}),n)}}function er(t,e,r){const i=r?{x:e.x+r.x,y:e.y+r.y}:e;let n=0;for(let l=0;l<i.x;l++){n+=t.columnWidth.get(l)??0}let o=0;for(let l=0;l<i.y;l++){o+=t.rowHeight.get(l)??0}const s=t.columnWidth.get(i.x)??0;const a=t.rowHeight.get(i.y)??0;return{x:n+Math.floor(s/2)+t.offsetX,y:o+Math.floor(a/2)+t.offsetY}}function eE(t,e){return e.map(r=>er(t,r))}function ms(t,e,r,i){const n=i??FL(t,e);if(t.grid.has(ot(r))){if(n==="LR"){return ms(t,e,{x:r.x,y:r.y+4},n)}else{return ms(t,e,{x:r.x+4,y:r.y},n)}}for(let o=0;o<3;o++){for(let s=0;s<3;s++){const a={x:r.x+o,y:r.y+s};t.grid.set(ot(a),e)}}e.gridCoord=r;return r}function rE(t,e){const r=e.gridCoord;const i=t.config.boxBorderPadding;const n=qv(e.shape,e.displayLabel,{useAscii:t.config.useAscii,padding:i});const o=n.gridColumns;const s=n.gridRows;for(let a=0;a<o.length;a++){const l=r.x+a;const c=t.columnWidth.get(l)??0;t.columnWidth.set(l,Math.max(c,o[a]))}for(let a=0;a<s.length;a++){const l=r.y+a;const c=t.rowHeight.get(l)??0;t.rowHeight.set(l,Math.max(c,s[a]))}if(r.x>0){const a=t.columnWidth.get(r.x-1)??0;t.columnWidth.set(r.x-1,Math.max(a,t.config.paddingX))}if(r.y>0){let a=t.config.paddingY;if($L(t,e)){const c=4;a+=c}const l=t.rowHeight.get(r.y-1)??0;t.rowHeight.set(r.y-1,Math.max(l,a))}}function PL(t){const e=new Map;for(const r of t.edges)for(const i of["start","end"]){if(r.style==="invisible"||!(i==="start"?r.hasArrowStart:r.hasArrowEnd)||(i==="start"?r.fromSubgraph||r.attachFromSubgraph:r.toSubgraph||r.attachToSubgraph))continue;const n=i==="start"?r.from:r.to,o=i==="start"?r.startDir:r.endDir;const s=e.get(n)??new Map,a=`${o.x},${o.y}`,l=s.get(a)??[];l.push({edge:r,end:i,marker:(i==="start"?r.startMarker:r.endMarker)??"arrow"});s.set(a,l);e.set(n,s)}for(const[r,i]of e)for(const[n,o]of i){const s=[...new Set(o.map(h=>h.marker))];if(s.length<2)continue;for(const{edge:h,end:m,marker:f}of o)h[m==="start"?"startPort":"endPort"]={index:s.indexOf(f),count:s.length};const a=n==="1,0"||n==="1,2";const l=a?t.columnWidth:t.rowHeight;const c=a?r.gridCoord.x:r.gridCoord.y;const d=(l.get(c)??0)+(l.get(c+1)??0)+1;const u=Math.max(0,s.length*3+2-d);l.set(c+1,(l.get(c+1)??0)+u)}}function sp(t,e){for(const r of e){if(!t.columnWidth.has(r.x)){t.columnWidth.set(r.x,Math.floor(t.config.paddingX/2))}if(!t.rowHeight.has(r.y)){t.rowHeight.set(r.y,Math.floor(t.config.paddingY/2))}}}function Yd(t,e){return t.subgraphs.some(r=>r.nodes.includes(e))}function Ut(t,e){let r=null;for(const i of t.subgraphs){if(i.nodes.includes(e)){if(!r||ap(r,i)){r=i}}}return r}function ap(t,e){let r=e;while(r!==null){if(r===t)return true;r=r.parent}return false}function FL(t,e){const r=Ut(t,e);if(r?.direction){return r.direction}return t.config.graphDirection}function $L(t,e){const r=Ut(t,e);if(!r)return false;let i=false;for(const n of t.edges){if(n.to===e){const o=Ut(t,n.from);if(o!==r){i=true;break}}}if(!i)return false;for(const n of r.nodes){if(n===e||!n.gridCoord)continue;let o=false;for(const s of t.edges){if(s.to===n){const a=Ut(t,s.from);if(a!==r){o=true;break}}}if(o&&n.gridCoord.y<e.gridCoord.y){return false}}return true}function aE(t,e,r){if(e.nodes.length===0)return;let i=1e6;let n=1e6;let o=-1e6;let s=-1e6;for(const l of e.children){aE(t,l,r);if(l.nodes.length>0){i=Math.min(i,l.minX);n=Math.min(n,l.minY);o=Math.max(o,l.maxX);s=Math.max(s,l.maxY)}}for(const l of e.nodes){const c=r?.get(l)??(l.drawingCoord&&l.drawing?{minX:l.drawingCoord.x,minY:l.drawingCoord.y,maxX:l.drawingCoord.x+l.drawing.width-1,maxY:l.drawingCoord.y+l.drawing.height-1}:void 0);if(!c)continue;i=Math.min(i,c.minX);n=Math.min(n,c.minY);o=Math.max(o,c.maxX);s=Math.max(s,c.maxY)}const a=Math.max(2,Yi(e.name)+1);e.minX=i-(e.insets?.left??2);e.minY=n-(e.insets?.top??2)-a;e.maxX=o+(e.insets?.right??2);e.maxY=s+(e.insets?.bottom??2)}function lE(t,e){for(const r of t.subgraphs){if(!r.parent)aE(t,r,e)}}function iE(t){for(const e of t.subgraphs){const r=e.nodes.filter(l=>l.gridCoord!==null);if(!r.length)continue;const i=r.reduce((l,c)=>l.gridCoord.x<c.gridCoord.x?l:c);const n=Math.min(...r.map(l=>er(t,l.gridCoord).x));const o=Math.max(...r.map(l=>{const c=l.gridCoord;return er(t,c).x+(t.columnWidth.get(c.x)??0)+(t.columnWidth.get(c.x+1)??0)}));const s=Math.max(0,$a(e.name)+2-(o-n+4));if(s){const l=i.gridCoord.x+1;t.columnWidth.set(l,(t.columnWidth.get(l)??0)+s)}const a=Math.min(...r.map(l=>l.gridCoord.y));if(a>0)t.rowHeight.set(a-1,Math.max(t.rowHeight.get(a-1)??0,t.config.paddingY+Math.max(0,Yi(e.name)-2)))}}function cE(t){const e=t.filter(r=>r.gridCoord!==null);if(e.length===0)return null;return{minX:Math.min(...e.map(r=>r.gridCoord.x)),minY:Math.min(...e.map(r=>r.gridCoord.y)),maxX:Math.max(...e.map(r=>r.gridCoord.x+2)),maxY:Math.max(...e.map(r=>r.gridCoord.y+2))}}function qL(t,e){return t.minX<=e.maxX&&t.maxX>=e.minX&&t.minY<=e.maxY&&t.maxY>=e.minY}function zL(t,e,r,i){const n=i==="TD"?t.minX-r<=e.maxX+r&&t.maxX+r>=e.minX-r:t.minX-r<e.maxX+r&&t.maxX+r>e.minX-r;const o=i==="LR"?t.minY-r<=e.maxY+r&&t.maxY+r>=e.minY-r:t.minY-r<e.maxY+r&&t.maxY+r>e.minY-r;return n&&o}function nE(t,e){return{minX:t.minX-e,minY:t.minY-e,maxX:t.maxX+e,maxY:t.maxY+e}}function oE(t,e,r){return e==="LR"?{...t,minY:t.minY+r,maxY:t.maxY+r}:{...t,minX:t.minX+r,maxX:t.maxX+r}}function dE(t){if(!t.gridCoord)return null;const{x:e,y:r}=t.gridCoord;return{minX:e,minY:r,maxX:e+2,maxY:r+2}}function GL(t){let e=lp(t);if(!t.subgraphs.length&&!t.edges.some(d=>d.cellAllocation)&&t.nodes.every(d=>{const u=er(t,{x:d.gridCoord.x+2,y:d.gridCoord.y+2});const h=e.get(d);return h.maxX<=u.x&&h.maxY<=u.y}))return;const r=[];const i=new Map;for(const[d,u]of e){const h={node:d,bounds:u,logical:dE(d)};r.push(h);i.set(d,h)}for(const d of t.subgraphs){const u=cE(d.nodes);if(!u)continue;const h={group:d,logical:u,bounds:{minX:d.minX,minY:d.minY,maxX:d.maxX,maxY:d.maxY}};i.set(d,h);if(!d.concurrencyRegion)r.push(h)}const n=(d,u)=>{const{edge:h,start:m}=d.approach,f=Ud(h,m,u);if(!f)return void 0;const p=m?h.startDir:h.endDir,g=p.x-1,y=p.y-1,C=Gr(h,m);return{minX:Math.min(f.x+g,f.x+g*C),maxX:Math.max(f.x+g,f.x+g*C),minY:Math.min(f.y+y,f.y+y*C),maxY:Math.max(f.y+y,f.y+y*C)}};for(const d of t.edges)if(d.cellAllocation)for(const u of[true,false]){const h=i.get(jt(d,u));const m={...h,approach:{edge:d,start:u}},f=n(m,h.bounds);if(f){m.bounds=f;r.push(m)}}const o=(d,u)=>{if(d.node&&d.node===u.node)return true;if(d.group&&u.node)return d.group.nodes.includes(u.node);if(u.group&&d.node)return u.group.nodes.includes(d.node);if(d.group&&u.group)return ap(d.group,u.group)||ap(u.group,d.group);return false};const s=d=>d.approach?Gr(d.approach.edge,d.approach.start)/2+1:2;const a=new Map,l=new Set;const c=()=>{e=lp(t);for(const d of r){const u=d.node?e.get(d.node):{minX:d.group.minX,minY:d.group.minY,maxX:d.group.maxX,maxY:d.group.maxY};d.bounds=d.approach?n(d,u):u}};for(;;){for(const u of["x","y"]){const h=new Map;for(const m of a.values())if(m.axis===u){const f=h.get(m.index)??[];f.push(m);h.set(m.index,f)}for(const[m,f]of[...h].sort(([p],[g])=>p-g)){c();const p=u==="x"?"minX":"minY",g=u==="x"?"maxX":"maxY";const y=Math.max(0,...f.map(({left:w,right:x,clearance:k})=>w.bounds[g]+k-x.bounds[p]));const C=u==="x"?t.columnWidth:t.rowHeight;if(y)C.set(m,(C.get(m)??0)+y)}}c();let d=false;for(let u=0;u<r.length;u++)for(let h=u+1;h<r.length;h++){const m=r[u],f=r[h],p=`${u}:${h}`;if(o(m,f)||a.has(p)||l.has(p))continue;const g=m.bounds,y=f.bounds;const C=Math.max(s(m),s(f));if(g.maxX+C<=y.minX||y.maxX+C<=g.minX||g.maxY+C<=y.minY||y.maxY+C<=g.minY)continue;const w=[];for(const L of["x","y"]){const B=L==="x"?"minX":"minY",O=L==="x"?"maxX":"maxY";if(m.logical[O]<f.logical[B])w.push({axis:L,index:f.logical[B]-1,left:m,right:f,clearance:C,extra:g[O]+C-y[B]});if(f.logical[O]<m.logical[B])w.push({axis:L,index:m.logical[B]-1,left:f,right:m,clearance:C,extra:y[O]+C-g[B]})}w.sort((L,B)=>L.extra-B.extra||(L.axis===(t.config.graphDirection==="TD"?"y":"x")?-1:1));const x=w[0];if(x){a.set(p,x);d=true;continue}l.add(p);const k=L=>L.approach?`${L.approach.edge.id}:${L.approach.start?"start":"end"}`:L.group?.id??L.node.name;const b=k(m),A=k(f);t.canvas.report({code:"TERMINAL_GEOMETRY_COLLISION",feature:`container-envelope:${b}:${A}`,message:`Unrelated envelopes ${b} and ${A} interleave in both logical axes; spacer capacity cannot separate them.`})}if(!d)return}}function lp(t){const e=new Map;for(const r of t.nodes){if(!r.gridCoord)continue;const i=er(t,r.gridCoord);e.set(r,{minX:i.x,minY:i.y,maxX:i.x+(t.columnWidth.get(r.gridCoord.x)??0)+(t.columnWidth.get(r.gridCoord.x+1)??0),maxY:i.y+(t.rowHeight.get(r.gridCoord.y)??0)+(t.rowHeight.get(r.gridCoord.y+1)??0)})}lE(t,e);return e}function WL(t,e){const r=t.subgraphs.filter(a=>a.parent===null&&a.nodes.length>0);const i=new Set(r.flatMap(a=>a.nodes));const n=t.nodes.filter(a=>!i.has(a)).map(dE).filter(a=>a!==null);const o=[];const s=1;for(const a of r){const l=[...new Set(a.nodes)];const c=cE(l);if(!c)continue;let d=0;while(true){const h=oE(c,e,d);const m=nE(h,s);const f=o.filter(w=>zL(w,h,s,e)).map(w=>nE(w,s));const p=n.filter(w=>qL(w,m));const g=[...f,...p];if(g.length===0)break;const y=Math.max(...g.map(w=>e==="LR"?w.maxY:w.maxX));const C=y+s+1;d=C-(e==="LR"?c.minY:c.minX)}if(d>0){for(const h of l){if(!h.gridCoord)continue;if(e==="LR")h.gridCoord.y+=d;else h.gridCoord.x+=d}}const u=oE(c,e,d);o.push(u);if(d>0){if(e==="LR"){const h=u.minY-1;t.rowHeight.set(h,Math.max(t.rowHeight.get(h)??0,7))}else{const h=u.minX-1;t.columnWidth.set(h,Math.max(t.columnWidth.get(h)??0,5))}}}t.grid.clear();for(const a of t.nodes){if(!a.gridCoord)continue;for(let l=0;l<3;l++){for(let c=0;c<3;c++){t.grid.set(ot({x:a.gridCoord.x+l,y:a.gridCoord.y+c}),a)}}}}function UL(t){if(t.subgraphs.length===0)return;let e=0;let r=0;for(const o of t.subgraphs){e=Math.min(e,o.minX);r=Math.min(r,o.minY)}for(const o of t.edges)if(o.cellAllocation)for(const s of[true,false]){const a=s?o.attachFromSubgraph??o.fromSubgraph:o.attachToSubgraph??o.toSubgraph;const l=s?o.from:o.to,c=s?o.startDir:o.endDir;if(c.x===0)e=Math.min(e,(a?.minX??l.drawingCoord.x)-Gr(o,s));if(c.y===0)r=Math.min(r,(a?.minY??l.drawingCoord.y)-Gr(o,s))}const i=-e;const n=-r;if(i===0&&n===0)return;t.offsetX=i;t.offsetY=n;for(const o of t.subgraphs){o.minX+=i;o.minY+=n;o.maxX+=i;o.maxY+=n}for(const o of t.nodes){if(o.drawingCoord){o.drawingCoord.x+=i;o.drawingCoord.y+=n}}}function fs(t){const e=t.config.graphDirection;const r=new Map;const i=b=>r.get(b)??0;const n=new Set;const o=[];for(const b of t.nodes){if(!n.has(b.name)){o.push(b)}n.add(b.name);for(const A of op(t,b)){n.add(A.name)}}const s=o.filter(b=>{const A=Ut(t,b);if(!A)return true;for(const L of t.edges){if(L.to===b){const B=Ut(t,L.from);if(B!==A){return false}}}return true});let a=false;let l=false;for(const b of s){if(Yd(t,b)){if(op(t,b).length>0)l=true}else{a=true}}const c=e==="LR"&&a&&l;let d;let u=[];if(c){d=s.filter(b=>!Yd(t,b));u=s.filter(b=>Yd(t,b))}else{d=s}const h=b=>{const A=op(t,b);return A.length>0?A[0].name:`__ungrouped__${b.name}`};const m=new Map;for(const b of d){const A=h(b);if(!m.has(A))m.set(A,m.size)}d=[...d].sort((b,A)=>m.get(h(b))-m.get(h(A)));const f=new Map;const p=new Map;for(const b of t.edges){if(b.from.name===b.to.name)continue;if(b.routeClass!=="primary-forward")continue;f.set(b.to.name,(f.get(b.to.name)??0)+1);if(!p.has(b.to.name))p.set(b.to.name,[]);p.get(b.to.name).push(b.from)}for(const b of d){const A=e==="LR"?{x:0,y:i(0)}:{x:i(0),y:0};ms(t,t.nodes[b.index],A);r.set(0,i(0)+4)}if(c&&u.length>0){const b=4;for(const A of u){const L=e==="LR"?{x:b,y:i(b)}:{x:i(b),y:b};ms(t,t.nodes[A.index],L);r.set(b,i(b)+4)}}let g=d.length+u.length;let y=false;while(g<t.nodes.length){const b=g;for(const A of t.nodes){if(A.gridCoord===null)continue;const L=A.gridCoord;for(const B of uE(t,A)){const O=B.to;if(O.gridCoord!==null)continue;if(!y&&(p.get(O.name)??[]).some(P=>P.gridCoord===null))continue;const M=Ut(t,A);const E=Ut(t,O);const _=M&&M===E&&M.direction?M.direction:t.config.graphDirection;let q=_==="LR"?L.x:L.y;if(_===t.config.graphDirection){for(const P of p.get(O.name)??[]){if(P.gridCoord===null)continue;q=Math.max(q,_==="LR"?P.gridCoord.x:P.gridCoord.y)}}const Q=q+4;let $;if(_!==t.config.graphDirection){$=_==="LR"?L.y:L.x}else if(B.fromSubgraph){$=Math.max(i(Q),_==="LR"?L.y:L.x)}else if((f.get(O.name)??0)>1){$=Math.max(i(Q),_==="LR"?L.y:L.x)}else{$=i(Q)}const D=_==="LR"?{x:Q,y:$}:{x:$,y:Q};ms(t,t.nodes[O.index],D,_);if(_===t.config.graphDirection){r.set(Q,$+4)}g++}}if(g===b){if(y){const A=t.nodes.filter(B=>B.gridCoord===null);const L=A.find(B=>!Yd(t,B))??A[0];if(!L)break;ms(t,L,e==="LR"?{x:0,y:i(0)}:{x:i(0),y:0});r.set(0,i(0)+4);g++;y=false;continue}y=true}else{y=false}}WL(t,e);tE(t);if(t.compoundRepacked){t.columnWidth.clear();t.rowHeight.clear()}for(const b of t.nodes){rE(t,b)}iE(t);t.bundles=wv(t);Tv(t);for(const b of t.edges){if(b.bundle&&b.path.length>0){sp(t,b.path);zd(t,b);continue}kv(t,b);sp(t,b.path);zd(t,b)}VL(t);PL(t);if(t.config.reverseDirection){jL(t);for(const b of t.nodes)rE(t,b);iE(t)}const C=Gv(t),w=new Set;const x={columns:new Map(t.columnWidth),rows:new Map(t.rowHeight),bundles:t.bundles,junctions:t.trunkJunctions,edges:new Map(t.edges.map(b=>[b,{startDir:b.startDir,endDir:b.endDir,bundle:b.bundle,sharedTrunk:b.sharedTrunk,pathToJunction:b.pathToJunction}])),insets:new Map(t.subgraphs.map(b=>[b,b.insets?{...b.insets}:void 0])),canvas:t.canvas,drawn:new Map(t.nodes.map(b=>[b,b.drawn]))};const k=()=>{t.columnWidth=new Map(x.columns);t.rowHeight=new Map(x.rows);t.offsetX=0;t.offsetY=0;t.canvas=x.canvas.blank();t.canvas.overlay(x.canvas);for(const[A,L]of x.insets)A.insets=L?{...L}:void 0;for(const[A,L]of x.edges){Object.assign(A,L);delete A.cellAllocation;delete A.cellRoute;if(w.has(A)){delete A.bundle;delete A.sharedTrunk;delete A.pathToJunction}}t.bundles=x.bundles.filter(A=>!A.edges.some(L=>w.has(L)));const b=new Set(t.edges.filter(A=>!w.has(A)).map(A=>A.sharedTrunk));t.trunkJunctions=x.junctions.filter(A=>b.has(A.trunk));Uv(t,()=>lp(t),w);GL(t);for(const A of t.nodes){A.drawn=x.drawn.get(A);A.drawingCoord=er(t,A.gridCoord);A.drawing=Jv(A,t)}yv(t.canvas,t.columnWidth,t.rowHeight);lE(t);UL(t)};t.reserveRouteUnits=b=>{const A=w.size;for(const L of b)for(const B of C.get(L)??[L])w.add(B);if(w.size===A)return false;k();return true};if(!t.reserveRouteUnits(Wv(t)))k()}function sE(t){return{x:2-t.x,y:t.y}}function jL(t){const e=Math.max(0,...t.columnWidth.keys());const r=n=>({x:e-n.x,y:n.y});for(const n of t.nodes){const o=n.gridCoord;n.gridCoord={x:e-(o.x+2),y:o.y}}for(const n of t.edges){n.path=n.path.map(r);n.labelLine=n.labelLine.map(r);n.startDir=sE(n.startDir);n.endDir=sE(n.endDir)}t.trunkJunctions=t.trunkJunctions.map(n=>({...r(n),trunk:n.trunk}));const i=new zr;for(const[n,o]of t.grid){const[s,a]=n.split(",").map(Number);i.set(ot({x:e-s,y:a}),o)}t.grid=i;t.columnWidth=new Map([...t.columnWidth].map(([n,o])=>[e-n,o]))}function VL(t){const e=new Map;for(const i of t.edges){if(i.bundle)continue;const n=`${i.from.name}:${i.startDir.x},${i.startDir.y}:${i.style}:${i.inlineStyle?.stroke??""}`;const o=e.get(n)??[];o.push(i);e.set(n,o)}const r=new Set(t.trunkJunctions.map(i=>`${i.trunk}:${ot(i)}`));for(const i of e.values()){if(i.length<2)continue;if(i.some(c=>c.from===c.to))continue;const n=i[0];const o=n.path;let s=-1;if(o.length>=3){const c=o[1].x-o[0].x;const d=o[1].y-o[0].y;for(let u=2;u<o.length;u++){const h=o[u].x-o[u-1].x;const m=o[u].y-o[u-1].y;if(h!==c||m!==d){s=u-1;break}}}if(s===-1)continue;const a=o.slice(0,s+1);const l=o[s];for(let c=1;c<i.length;c++){const d=i[c];const u=io(d.to.gridCoord,d.endDir);const h=St(t.grid,l,u,d.startDir);if(!h)continue;d.path=[...a,...Nt(h).slice(1)];n.sharedTrunk??=`trunk:${n.id??n.sourceIndex}`;d.sharedTrunk=n.sharedTrunk;const m=`${n.sharedTrunk}:${ot(l)}`;if(!r.has(m)){t.trunkJunctions.push({...l,trunk:n.sharedTrunk});r.add(m)}sp(t,d.path);zd(t,d)}}}function uE(t,e){return t.edges.filter(r=>r.from.name===e.name)}function op(t,e){return uE(t,e).map(r=>r.to)}function hE(t,e,r,i){const n=vi(t);const o={direction:"LR",nodes:new Map(n.frames.map(c=>[c.id,{id:c.id,label:`${Pl(c)}
186
+ ${So(n,c)}`,labelContent:{value:`${Pl(c)}
187
+ ${So(n,c)}`,prepared:bt(`${Pl(c)}
188
+ ${So(n,c)}`,"literal")},shape:"rectangle"}])),edges:mx(n).map(c=>({id:c.id,source:c.from,target:c.to,style:"solid",hasArrowStart:false,hasArrowEnd:true})),subgraphs:[],classDefs:new Map,classAssignments:new Map,nodeStyles:new Map,linkStyles:new Map};const s=ls(o,{...e,graphDirection:"LR"});fs(s);hs(s);const a=new Re;const l=n.title?(a.textBlock(0,0,[n.title],{role:"text",owner:{id:"title",kind:"label"}})?.height??0)+1:0;a.overlay(s.canvas,0,l);return Fe(a,{colorMode:r,theme:i})}var Pt=class extends Error{constructor(r,i,n,o){super(`Cannot render ${n} within ${r} terminal cells; required width is ${i} (${o}).`);this.requestedWidth=r;this.requiredWidth=i;this.family=n;this.reason=o;this.name="AsciiWidthError"}requestedWidth;requiredWidth;family;reason;code="ASCII_TARGET_WIDTH_IMPOSSIBLE"};function mE(t){const e=po(Wl(t.source.familyBody),t.source.frontmatter);const r=t.familyConfig?.visual??Iy(t.source.frontmatter);const i=e.fields.length?Math.floor(e.fields.at(-1).end/r.bitsPerRow)+1:0;vl("nodes",i+e.fields.length);const n=t.options.targetWidth??t.options.maxWidth??t.config.maxWidth;const o=Math.max(3,String(e.fields.at(-1)?.end??0).length+2);const s=r.bitsPerRow*o+1;if(n&&n<s)throw new Pt(n,s,"packet","MINIMUM_GEOMETRY");const a=Math.max(o,n?Math.floor((n-1)/r.bitsPerRow):Math.ceil(r.bitWidth/8));const l=new Re;if(e.title){for(const u of qr(e.title,{display:"formatted",maxWidth:n}).lines)l.line([{text:u,role:"text",owner:{id:"title",kind:"label"}}]);l.line()}let c=l.height;let d=0;for(let u=0;u<i;u++){const h=u*r.bitsPerRow,m=h+r.bitsPerRow-1;while(d<e.fields.length&&e.fields[d].end<h)d++;const f=[];for(let g=d;g<e.fields.length&&e.fields[g].start<=m;g++){const y=e.fields[g];const C=Math.max(h,y.start),w=Math.min(m,y.end);const x=r.bitOrder==="descending"?r.bitsPerRow-(w-h+1):C-h;const k=(w-C+1)*a+1;f.push({field:y,low:C,high:w,x:x*a,width:k,block:qr(y.label,{display:"formatted",maxWidth:k-2})})}const p=Math.max(3,...f.map(g=>g.block.height+2));if(r.showBits)c++;for(const g of f){const y=`${g.field.id}:row-${u}`,C={id:y,kind:"node"};Et(l,{x:g.x,y:c,width:g.width,height:p},C,t.config.useAscii);l.textBlock(g.x+1,c+1,g.block.lines,{role:"text",owner:C});if(r.showBits){const w=r.bitOrder==="descending"?g.high:g.low;const x=r.bitOrder==="descending"?g.low:g.high;if(w===x)l.text(g.x+Math.floor(g.width/2),c-1,String(w),{role:"border",owner:{id:`${y}:bits`,kind:"label",parent:C}});else{l.text(g.x+1,c-1,String(w),{role:"border",owner:{id:`${y}:start`,kind:"label",parent:C}});l.text(g.x+g.width-1-String(x).length,c-1,String(x),{role:"border",owner:{id:`${y}:end`,kind:"label",parent:C}})}}}c+=p+1}return Fe(l,{colorMode:t.colorMode,theme:t.theme,trimEnd:true})}function fE(t){const e=po(Ei(Br(t.source),t.source.accessibility,t.source),t.source.frontmatter);const r=t.familyConfig?.visual??Ry(t.source.frontmatter);const i=t.options.targetWidth??t.options.maxWidth??t.config.maxWidth;const n=e.columns.length,o=n*8+Math.max(0,n-1)*2;if(i&&i<o)throw new Pt(i,o,"kanban","MINIMUM_GEOMETRY");const s=n&&i?Math.max(8,Math.floor((i-(n-1)*2)/n)):Math.max(18,Math.min(40,Math.round(r.sectionWidth/8)));const a=new Re;if(e.title){for(const u of qr(e.title,{display:"formatted",maxWidth:i}).lines)a.line([{text:u,role:"text",owner:{id:"title",kind:"label"}}]);a.line()}const l=a.height;const c=e.columns.map((u,h)=>{const m=new Re,f={id:u.id,kind:"band",members:u.tasks.map(y=>y.id)};const p=_h(u).flatMap(y=>[...qr(y.text,{display:"formatted",maxWidth:s-4}).lines]);let g=p.length+2;m.textBlock(2,1,p,{role:"text",owner:f});for(const y of u.tasks){const C=_h(y).flatMap(x=>[...qr(x.text,{display:"formatted",maxWidth:s-6}).lines]);const w={id:y.id,kind:"node",parent:{id:u.id,kind:"band"}};Et(m,{x:1,y:g,width:s-2,height:C.length+2},w,t.config.useAscii);m.textBlock(2,g+1,C,{role:"text",owner:w});g+=C.length+3}return{local:m,owner:f,x:h*(s+2),height:Math.max(p.length+3,g+1)}});const d=Math.max(3,...c.map(u=>u.height));for(const u of c){Et(u.local,{x:0,y:0,width:s,height:d},u.owner,t.config.useAscii);a.overlay(u.local,u.x,l)}return Fe(a,{colorMode:t.colorMode,theme:t.theme,trimEnd:true})}function Sr(t,e){if(!t)throw new RangeError("Terminal constructive layout: "+e)}var Wr=t=>{const e=t?.some(i=>i.length)?$t(t.join("\n"),true).split("\n"):[];const r=Math.max(0,...e.map(ne));return{lines:e,width:r,height:e.length,cells:r*e.length,extra:e.reduce((i,n)=>i+Math.max(0,n.length-ne(n)),0)}};var cp=(t,e)=>`link ${t}: ${e}`;var pE=(t,e)=>t.x<e.x+e.width&&t.x+t.width>e.x&&t.y<e.y+e.height&&t.y+t.height>e.y;var gE=Symbol("compact contact proof limit");function YL(t,e,r,i){const n=new Map(r.map(d=>[d.id,d])),o=new Map;let s=0;const a=()=>{if(s>=Wt.maxOperations)throw gE;s++};const l=d=>{const u=new Set;let h=i.get(d);while(h){a();if(u.has(h))throw new Error("Cyclic namespace parent");u.add(h);h=n.get(h)?.parentId}return u};for(const d of t){const u=new Set([...l(d.relation.from),...l(d.relation.to)]),h=new Set;for(let m=0;m<d.points.length;m++){a();const f=d.points[m],p=d.points[m-1],g=d.points[m+1],y=f.x+","+f.y;if(h.has(y))return"self-retracing route "+d.relation.id;h.add(y);let C=0;for(const k of[p,g])if(k)C|=k.x>f.x?2:k.x<f.x?8:k.y>f.y?4:1;const w=m===0||m===d.points.length-1,x=o.get(y);if(x&&x.edge!==d.relation.id&&!(!w&&!x.terminal&&(C===10&&x.mask===5||C===5&&x.mask===10)))return"illegal route contact "+x.edge+" / "+d.relation.id;o.set(y,{edge:d.relation.id,mask:x?15:C,terminal:w});for(const k of e){a();if(f.x>=k.x&&f.x<k.x+k.width&&f.y>=k.y&&f.y<k.y+k.height)return"card body contact "+d.relation.id}for(const k of r){a();if(f.x<k.x||f.x>=k.x+k.width||f.y<k.y||f.y>=k.y+k.height)continue;if(f.y<k.y+k.labelLines.length)return"namespace header contact "+d.relation.id;const b=f.x===k.x||f.x===k.x+k.width-1,A=f.y===k.y+k.height-1;if(b||A){if(!u.has(k.id)||!p||!g||b&&A||b&&(p.y!==f.y||g.y!==f.y)||A&&(p.x!==f.x||g.x!==f.x))return"namespace boundary contact "+d.relation.id}}}}const c=t.flatMap(d=>[d.label,d.fromLabel,d.toLabel].filter(u=>!!u));for(let d=0;d<c.length;d++){const u=c[d];for(const h of[...e,...r.map(m=>({x:m.x,y:m.y,width:m.width,height:m.labelLines.length}))]){a();if(pE(u,h))return"label geometry contact"}for(let h=0;h<d;h++){a();if(pE(u,c[h]))return"label overlap"}for(let h=u.y;h<u.y+u.height;h++)for(let m=u.x;m<u.x+u.width;m++){a();if(o.has(m+","+h))return"label shaft contact"}}return void 0}function yE(t,e,r,i){try{const n=YL(t,e,r,i);return n?{status:"invalid",reason:n}:{status:"clear"}}catch(n){if(n===gE)return{status:"unknown"};throw n}}function xE(t,e,r,i,n,o,s,a,l){const c=o==="LR"||o==="RL",d=o==="BT"||o==="RL",u=c?"B":"R";const h=H=>c?H.width:H.height;const m=n.flatMap(H=>[Wr(H.fromLines),Wr(H.toLines)]),f=Math.max(2,...m.map(H=>(c?H.width:H.height)+1));const p=as(n.flatMap(H=>[{id:H.from,side:u},{id:H.to,side:u}]));let g=0;const y=H=>{const Se=H.sections,Xe=Se?.flat()??H.lines??[],ze=Math.max(6,4+Math.max(0,...Xe.map(ne))),nt=Se?Se.reduce((sr,Ji)=>sr+Math.max(1,Ji.length),0)+Se.length+1:Math.max(3,Xe.length+2);const pt=p.get(H.id)?.[u]??0,Yt=Math.max(c?Ui(p.get(H.id)).width:Ui(p.get(H.id)).height,pt?f*(pt+1)+1:0);return{original:H,id:H.id,x:0,y:0,width:Math.max(ze,c?Yt:0),height:Math.max(nt,c?0:Yt),order:g++}};const C=[...t.values()].map(y),w=r.map(y),x=e.map(H=>({original:H,id:H.id,x:0,y:0,width:0,height:0,order:g++,frame:true})),k=new Map(x.map(H=>[H.id,H])),b=new Set,A=new Set;const L=H=>{Sr(!A.has(H.id),"namespace cycle");if(b.has(H.id))return;A.add(H.id);H.children=[...x.filter(ze=>ze.original.parentId===H.id),...C.filter(ze=>i.get(ze.id)===H.id)];for(const ze of H.children)if(ze.frame)L(ze);H.children.sort((ze,nt)=>ze.order-nt.order);if(H.children.length)H.order=Math.min(...H.children.map(ze=>ze.order));if(d)H.children.reverse();const Se=H.original.labelLines.length,Xe=Wr(H.original.labelLines).width;if(c){H.width=Math.max(Xe+4,6,8+H.children.reduce((ze,nt)=>ze+nt.width,0)+4*Math.max(0,H.children.length-1));H.height=Math.max(Se+3,Se+8+Math.max(0,...H.children.map(ze=>ze.height)))}else{H.width=Math.max(Xe+4,6,...H.children.map(ze=>ze.width+8));H.height=H.children.length?Se+8+H.children.reduce((ze,nt)=>ze+nt.height,0)+4*(H.children.length-1):Se+3}A.delete(H.id);b.add(H.id)};Sr(k.size===x.length,"duplicate namespace identity");for(const H of x)L(H);const B=(H,Se,Xe)=>{H.x=Se;H.y=Xe;if(H.frame){let ze=c?Se+4:Xe+H.original.labelLines.length+4;for(const nt of H.children){B(nt,c?ze:Se+4,c?Xe+H.original.labelLines.length+4:ze);ze+=h(nt)+4}}};const O=[...x.filter(H=>H.original.parentId===void 0),...C.filter(H=>!i.has(H.id)),...w].sort((H,Se)=>H.order-Se.order);if(d)O.reverse();let M=4;for(const H of O){B(H,c?M:4,c?4:M);M+=h(H)+4}const E=[...C,...w],_=[...E,...x],q=new Map(E.map(H=>[H.id,H]));Sr(q.size===E.length&&_.every(H=>H.x>=4&&H.y>=4),"node/note identity or parent allocation");const Q=Math.max(0,..._.map(H=>H.x+H.width)),$=Math.max(0,..._.map(H=>H.y+H.height)),D=(c?$:Q)+4,P=Math.max(0,...m.map(H=>c?H.height:H.width));let U=D+P+4,j=(c?Q:$)+4;const G=new Map,se=new Set;const ce=H=>{const Se=q.get(H);Sr(Se,"missing authored endpoint "+H);const Xe=p.get(H)?.[u]??0,ze=G.get(H)??0;G.set(H,ze+1);const nt=Math.floor((ze+1)*((c?Se.width:Se.height)-1)/(Xe+1)),pt=c?Se.x+nt:Se.x+Se.width,Yt=c?Se.y+Se.height:Se.y+nt,sr=c?pt:Yt;Sr(!se.has(sr),"duplicate physical port coordinate");se.add(sr);return{x:pt,y:Yt,index:ze,count:Xe}};const ae=n.map(H=>{const Se=ce(H.from),Xe=ce(H.to),ze=Wr(H.lines),nt=Wr(H.fromLines),pt=Wr(H.toLines),Yt=U,sr=Yt+Math.max(3,(c?ze.height:ze.width)+3),Ji=j+Math.max(1,c?ze.width:ze.height),fr=c?Se.x:Se.y,Ss=c?Xe.x:Xe.y,rl=fr>Ss?Yt:sr,il=Ss>fr?Yt:sr,fu=rl-(c?Se.y:Se.x)+Ji-fr+sr-Yt+Ji-Ss+il-(c?Xe.y:Xe.x)+1;U=sr+1;j=Ji+2;return{relation:H,source:Se,target:Xe,inner:Yt,outer:sr,sourceLane:rl,targetLane:il,aux:Ji,count:fu,central:ze,fromText:nt,toText:pt}});const Y=C.flatMap(H=>H.original.cls?.href?[Wr([cp(H.id,H.original.cls.href)])]:[]);const V=Y.reduce((H,Se)=>H+1+Se.height,0);const N=Wr(s),J=N.height?N.height+1:0,ee=Math.max(Q,N.width,...Y.map(H=>H.width),...ae.map(H=>c?H.aux+1:H.outer+1)),X=Math.max($,...ae.map(H=>c?H.outer+1:H.aux+1)),ie=X+V+J,ge=ae.reduce((H,Se)=>H+Se.count,0);Sr([ee,ie,ge].every(H=>Number.isSafeInteger(H)&&H>=0),"unsafe construction arithmetic");Sr(ie<=Wt.maxOperations&&ge<=Wt.maxOperations,"route/row allocation ceiling");if(a!==void 0&&ee>a)throw new Pt(a,ee,"class","MINIMUM_GEOMETRY");const fe=new Array(ie).fill(0);let de=0;const xe=()=>Sr(++de<=Wt.maxOperations,"construction planning work ceiling");const we=(H,Se,Xe,ze)=>{for(let nt=Se;nt<Se+ze;nt++){xe();fe[nt+J]=Math.max(fe[nt+J]??0,H+Xe)}};for(const H of _)we(H.x,H.y,H.width,H.height);const Be=H=>c?[{text:H.central,x:H.aux-H.central.width,y:H.inner+2},{text:H.fromText,x:H.source.x-H.fromText.width,y:D},{text:H.toText,x:H.target.x-H.toText.width,y:D}]:[{text:H.central,x:H.inner+2,y:H.aux-H.central.height},{text:H.fromText,x:D,y:H.source.y-H.fromText.height},{text:H.toText,x:D,y:H.target.y-H.toText.height}];for(const H of ae){const Se=bE(H,c);for(let Xe=1;Xe<Se.length;Xe++){const ze=Se[Xe-1],nt=Se[Xe];we(Math.min(ze.x,nt.x),Math.min(ze.y,nt.y),Math.abs(nt.x-ze.x)+1,Math.abs(nt.y-ze.y)+1)}for(const Xe of Be(H))if(Xe.text.height)we(Xe.x,Xe.y,Xe.text.width,Xe.text.height)}let Ie=X;for(const H of Y){Ie++;we(0,Ie,H.width,H.height);Ie+=H.height}for(let H=0;H<N.height;H++)fe[H]=Math.ceil((ee+N.width)/2);const Me=fe.reduce((H,Se)=>H+Se,Math.max(0,ie-1))+[...C.flatMap(H=>H.original.sections?.flat()??[]),...r.flatMap(H=>H.lines??[]),...e.flatMap(H=>H.labelLines),...s,...Y.flatMap(H=>H.lines),...ae.flatMap(H=>[...H.central.lines,...H.fromText.lines,...H.toText.lines])].reduce((H,Se)=>H+Math.max(0,Se.length-ne(Se)),0);Sr(Me<=Wt.maxOutputCodeUnits,"encoded output ceiling");let Ae=0,He=3;for(const H of n)for(const Se of[H.from,H.to]){let Xe=i.get(Se);xe();He++;while(Xe){xe();He++;Ae++;Xe=k.get(Xe)?.original?.parentId}}let Ne=0;for(const H of ae)for(const Se of ae)if(H!==Se)for(const[Xe,ze,nt]of[[c?H.source.y:H.source.x,c?H.source.x:H.source.y,H.sourceLane],[c?H.target.y:H.target.x,c?H.target.x:H.target.y,H.targetLane]])for(const[pt,Yt]of[[Se.sourceLane,c?Se.source.x:Se.source.y],[Se.targetLane,c?Se.target.x:Se.target.y]]){xe();if(Xe<pt&&pt<nt&&Yt<ze&&ze<Se.aux)Ne++}const K=E.reduce((H,Se)=>H+Se.width*Se.height,0),pe=x.reduce((H,Se)=>H+2*Se.width+2*Se.height-4,0),ke=ae.reduce((H,Se)=>H+Se.central.cells+Se.fromText.cells+Se.toText.cells,0);const Ee=C.reduce((H,Se)=>H+(Se.original.sections?.length??0),0),_e=C.reduce((H,Se)=>H+(Se.width-2)*(Se.original.sections??[]).reduce((Xe,ze)=>Xe+Math.max(1,ze.length),0),0);const qe=E.length+e.length+n.length+Ee+2*l+(N.height?1:0),Ze=E.length+e.length+Ee,rt=e.reduce((H,Se)=>H+Se.members.length,0),z=2*n.length;const F=e.reduce((H,Se)=>H+Wr(Se.labelLines.map(Xe=>" "+Xe+" ")).cells,0),Z=e.reduce((H,Se)=>H+Se.labelLines.length,0);const ue=C.reduce((H,Se)=>H+(Se.original.sections??[]).reduce((Xe,ze)=>Xe+ze.reduce((nt,pt)=>nt+Wr([pt]).cells,0),0),0)+r.reduce((H,Se)=>H+Wr(Se.lines).cells,0);const be=Y.reduce((H,Se)=>H+Se.cells,0);const Ce=ue+ke+F+N.cells+be,Le=K+ge+ke+pe+F+N.cells+be;const Qe=K+3*n.length+Z+N.height+Y.length,lt=K+V+ae.reduce((H,Se)=>H+Se.central.height+Se.fromText.height+Se.toText.height,0)+Z+N.height;const et=4*qe+qe*qe+rt*(qe+1)+2*n.length;const xt=fe.reduce((H,Se)=>H+Se,0)+ie+et+2*Ze+Qe+lt+18*Ce+5*Le+2*_e+6*z;const ft=(N.height?6+16*n.length:3+9*n.length)+He;const Je=xt+2*ge+2*Ne+Ae+ft+11+22*n.length;const At={width:ee,height:ie,outputUpper:Me,pathPoints:ge,certificationUpper:Je,baselineUpper:xt,planningWork:He,layoutWork:de,frameContacts:Ae,nodeArea:K,perimeters:pe,external:ke,crossings:Ne,identities:qe,declarations:Ze,compartments:Ee,ports:z,footerCells:be};for(const H of _)Object.assign(H.original,{x:H.x,y:H.y,width:H.width,height:H.height});return{horizontal:c,side:u,nodes:E,frames:x,routes:ae,endBand:D,relations:n,report:At}}function bE(t,e){const r=t.source,i=t.target;return e?[r,{x:r.x,y:t.sourceLane},{x:t.aux,y:t.sourceLane},{x:t.aux,y:t.targetLane},{x:i.x,y:t.targetLane},i]:[r,{x:t.sourceLane,y:r.y},{x:t.sourceLane,y:t.aux},{x:t.targetLane,y:t.aux},{x:t.targetLane,y:i.y},i]}function CE(t,e){const r=new Map(t.nodes.map(n=>[n.id,n.original])),i=(n,o,s)=>n.height?Object.freeze({x:o,y:s,width:n.width,height:n.height,lines:Object.freeze([...n.lines]),text:mt(n.lines)}):void 0;return t.routes.map(n=>{const o=ji(r.get(n.relation.from),t.side,n.source.index,n.source.count),s=ji(r.get(n.relation.to),t.side,n.target.index,n.target.count);Sr(o.x===n.source.x&&o.y===n.source.y&&s.x===n.target.x&&s.y===n.target.y,"canonical face allocation binding");const a=bE(n,t.horizontal),l=[];l.push(o);for(let h=1;h<a.length;h++){const m=a[h-1],f=a[h],p=Math.sign(f.x-m.x),g=Math.sign(f.y-m.y);Sr((p!==0||g!==0)&&(!p||!g),"positive orthogonal segment");for(let y=m.x+p,C=m.y+g;;y+=p,C+=g){l.push({x:y,y:C});if(y===f.x&&C===f.y)break}}Sr(l.length===n.count,"path point admission");const c=t.horizontal?i(n.central,n.aux-n.central.width,n.inner+2):i(n.central,n.inner+2,n.aux-n.central.height),d=t.horizontal?i(n.fromText,n.source.x-n.fromText.width,t.endBand):i(n.fromText,t.endBand,n.source.y-n.fromText.height),u=t.horizontal?i(n.toText,n.target.x-n.toText.width,t.endBand):i(n.toText,t.endBand,n.target.y-n.toText.height);return e({relation:n.relation,source:o,target:s,points:l,...c?{label:c}:{},...d?{fromLabel:d}:{},...u?{toLabel:u}:{}})})}var Ur=2;var Wa=class extends Error{};var HL=Symbol("allocated terminal box route");var SE=new WeakSet;var bn={T:{x:0,y:-1},B:{x:0,y:1},L:{x:-1,y:0},R:{x:1,y:0}};var XL={T:je,B:We,L:$e,R:Pe};function wE(t,e,r){if(t.from===t.to)return["R","B"];const i=r?.get(t.from),n=r?.get(t.to);if(i&&n){const o=e!=="LR"&&e!=="RL";if(o&&i.y+i.height<=n.y)return["B","T"];if(o&&n.y+n.height<=i.y)return["T","B"];if(i.x+i.width<=n.x)return["R","L"];if(n.x+n.width<=i.x)return["L","R"];if(i.y+i.height<=n.y)return["B","T"];if(n.y+n.height<=i.y)return["T","B"]}if(e==="LR")return["R","L"];if(e==="RL")return["L","R"];if(e==="BT")return["T","B"];return["B","T"]}function ur(t,e,r){const i=Hd(t,e,r?new Map(r.map(n=>[n.id,n])):void 0);return new Map([...i].map(([n,o])=>[n,Ui(o)]))}function Hd(t,e,r){return as(t.flatMap(i=>{const[n,o]=wE(i,e,r);return[{id:i.from,side:n},{id:i.to,side:o}]}))}function TE(t){const e=Rd(t.relation.id,{...t.source,nodeId:t.relation.from,end:"start"},{...t.target,nodeId:t.relation.to,end:"end"},t.points);const r=Object.freeze({...t.relation,...Object.fromEntries(["lines","fromLines","toLines"].flatMap(n=>{const o=t.relation[n];return o?[[n,Object.freeze([...o])]]:[]}))});const i=Object.freeze({...t,[HL]:true,relation:r,points:e.points,path:e});SE.add(i);return i}function ps(t,e){const r=[...t];if(e!=="RL"&&e!=="BT")return;const i=Math.max(0,...r.map(c=>c.x+c.width)),n=Math.max(0,...r.map(c=>c.y+c.height));const o=Math.min(Infinity,...r.map(c=>c.x)),s=Math.min(Infinity,...r.map(c=>c.y));const a=Math.max(4,o),l=Math.max(4,s);for(const c of r){if(e==="RL")c.x=i-c.x-c.width+a;else c.y=n-c.y-c.height+l}}var kE=(t,e)=>t.x<e.x+e.width&&t.x+t.width>e.x&&t.y<e.y+e.height&&t.y+t.height>e.y;function xi(t,e,r,i=[]){const n=new Map(t.map(k=>[k.id,k]));const o=Hd(e,r,n),s=new Map;const a=(k,b)=>{const A=n.get(k),L=`${k}\0${b}`,B=s.get(L)??0;s.set(L,B+1);const O=o.get(k)[b];return ji(A,b,B,O)};const l=e.map(k=>{if(!n.has(k.from)||!n.has(k.to))throw new Error(`Terminal route ${k.id} has no allocated endpoint box`);const[b,A]=wE(k,r,n);return{relation:k,source:a(k.from,b),target:a(k.to,A)}});const c=true;const d=new zr,u=new Set,h=new Set;const m=new Set;const f=[];const p=k=>{for(let b=k.y;b<k.y+k.height;b++)for(let A=k.x;A<k.x+k.width;A++)d.set(`${A},${b}`,c)};const g=[...t,...i];const y=g.flatMap(k=>k.container?[{x:k.x,y:k.y,width:k.width,height:k.headerHeight??1}]:[k]);const C=g.flatMap(k=>k.container?[{x:k.x,y:k.y,width:k.width,height:k.headerHeight??1},{x:k.x,y:k.y,width:1,height:k.height},{x:k.x+k.width-1,y:k.y,width:1,height:k.height},{x:k.x,y:k.y+k.height-1,width:k.width,height:1}]:[k]);y.forEach(p);for(const k of d.keys())u.add(k);for(const k of l)for(const b of[k.source,k.target]){const A=bn[b.side];for(let L=0;L<=Ur;L++)m.add(`${b.x+A.x*L},${b.y+A.y*L}`)}const w=(k,b)=>{if(!k?.some(q=>q.length>0))return void 0;const A=mt(k),L=A.width,B=A.height;const O=q=>{const Q={x:q.x-1,y:q.y-1,width:q.width+2,height:q.height+2};if(q.x<0||q.y<0||C.some($=>kE(Q,$))||f.some($=>kE(Q,$)))return false;for(let $=Q.y;$<Q.y+Q.height;$++)for(let D=Q.x;D<Q.x+Q.width;D++)if(m.has(`${D},${$}`))return false;for(let $=q.y;$<q.y+B;$++)for(let D=q.x;D<q.x+L;D++)if(h.has(`${D},${$}`))return false;return true};for(let q=0;q<24;q++)for(const Q of b){const $=[{x:Q.x+2,y:Q.y-B-q},{x:Q.x+2+q,y:Q.y},{x:Q.x-L-2-q,y:Q.y},{x:Q.x+2,y:Q.y+1+q}];for(const D of $){const P={...D,width:L,height:B};if(!O(P))continue;f.push(P);p(P);return Object.freeze({...P,lines:Object.freeze([...k]),text:A})}}let M=Math.max(2,...g.map(q=>q.x+q.width+2),...f.map(q=>q.x+q.width+2));const E=Math.max(0,b[0]?.y??0);while(!O({x:M,y:E,width:L,height:B}))M++;const _={x:M,y:E,width:L,height:B};f.push(_);p(_);return Object.freeze({..._,lines:Object.freeze([...k]),text:A})};for(const k of m)d.set(k,c);const x=[];for(const k of l){const{relation:b,source:A,target:L}=k;const B=w(b.fromLines,[A]),O=w(b.toLines,[L]);const M={x:A.x+bn[A.side].x*Ur,y:A.y+bn[A.side].y*Ur};const E={x:L.x+bn[L.side].x*Ur,y:L.y+bn[L.side].y*Ur};const _=[];for(const G of[M,E]){const se=ot(G),ce=d.get(se);if(ce&&!u.has(se)){_.push([se,ce]);d.delete(se)}}const q=G=>{const se=bn[G.side];return Array.from({length:Ur+1},(ce,ae)=>ae).every(ce=>!u.has(`${G.x+se.x*ce},${G.y+se.y*ce}`))};const Q=M.x>=0&&M.y>=0&&E.x>=0&&E.y>=0&&q(A)&&q(L);const $=()=>Cv(d,M,E)??St(d,M,E,XL[A.side]);let D=Q?$():null;if(!D){const G=[];for(const se of h)if(d.has(se)&&!u.has(se)&&!m.has(se)){d.delete(se);G.push(se)}D=Q?$():null;for(const se of G)d.set(se,c)}for(const[G,se]of _)d.set(G,se);if(!D)throw new Wa(`No feasible terminal route for ${b.id}; move the related cards or reduce their label footprint`);const P=G=>Array.from({length:Ur},(se,ce)=>ce===0?G:{x:G.x+bn[G.side].x*ce,y:G.y+bn[G.side].y*ce});const U=[...P(A),...D,...P(L).reverse()];for(const G of U){const se=ot(G);h.add(se);d.set(se,c)}const j=w(b.lines,[U[Math.floor(U.length/2)],A,L]);x.push(TE({...k,points:U,...j?{label:j}:{},...B?{fromLabel:B}:{},...O?{toLabel:O}:{}}))}return x}function jr(t,e,r,i,n=false){if(!SE.has(e))throw new TypeError("Terminal routes must come from box allocation");if(r.kind!=="edge"||r.id!==e.relation.id||r.from!==e.relation.from||r.to!==e.relation.to)throw new TypeError("Terminal route identity must match its allocated endpoints");if(!ss(t,e.path,r,i,n?"dashed":"solid"))throw new Error(`Allocated terminal route ${r.id} conflicts with admitted geometry`)}function wr(t,e,r){r=t.element(r);if(e)t.textBlock(e.x,e.y,e.text,{owner:r,role:"text",kind:"text"})}function Xd(t,e,r,i){const n={};for(const[o,s]of Object.entries(i)){if(o==="color"||o==="stroke"){const l=Ft(s);if(l){n[o==="color"?"text":"stroke"]=Mr(l[0],l[1],l[2]);if(l[3]<1)t.report({code:"TERMINAL_FAMILY_PROJECTION",feature:`${e}.${r}.style.${o}.alpha`,message:`Authored ${e} ${o} alpha on ${r} projects to solid terminal ink.`});continue}}const a=o==="fill"?"an unfilled terminal card surface":o==="stroke-width"||o==="stroke-dasharray"||o==="stroke"?"one-cell terminal borders":o==="color"?"the resolved terminal text palette":"the terminal card, text and border vocabulary";t.report({code:"TERMINAL_FAMILY_PROJECTION",feature:`${e}.${r}.style.${o}`,message:`Authored ${e} style ${o}:${s} on ${r} projects to ${a}.`})}return n}function vE(t){return CE(t,TE)}function EE(t,e,r,i,n={},o){const s=Eo(t),a=s.direction,l=a==="LR"||a==="RL",c=o??e.targetWidth??e.maxWidth;const d=M=>ve(Ge(M),c?Math.max(1,c-8):void 0);const u=s.relations.map(M=>({id:M.id,from:M.src,to:M.dst,lines:[`<<${M.type}>>`]})),h=ur(u,a);const m=[...s.requirements.map(M=>({id:M.name,sections:[[`<<${M.type}>>`,...d(M.name)],...[["ID",M.requirementId],["Text",M.text],["Risk",M.risk],["Verification",M.verifyMethod]].filter(([,E])=>E).map(([E,_])=>d(`${E}: ${_}`))]})),...s.elements.map(M=>({id:M.name,sections:[["<<Element>>",...d(M.name)],...[["Type",M.type],["Doc Ref",M.docRef]].filter(([,E])=>E).map(([E,_])=>d(`${E}: ${_}`))]}))];const f=new Map(m.map(M=>[M.id,{width:Math.max(6,...M.sections.flat().map(E=>ne(E)+4),h.get(M.id)?.width??0),height:Math.max(M.sections.reduce((E,_)=>E+Math.max(1,_.length),0)+M.sections.length+1,h.get(M.id)?.height??0)}]));const p=new Map,g=new Set(s.relations.filter(M=>M.src!==M.dst).map(M=>M.dst)),y=m.filter(M=>!g.has(M.id)).map(M=>M.id);const C=new Map;for(const M of s.relations){if(M.src===M.dst)continue;const E=C.get(M.src);if(E)E.push(M);else C.set(M.src,[M])}y.forEach(M=>p.set(M,0));for(let M=0;M<y.length;M++){const E=y[M];for(const _ of C.get(E)??[]){const q=(p.get(E)??0)+1;if(q>=m.length||(p.get(_.dst)??-1)>=q)continue;p.set(_.dst,q);y.push(_.dst)}}let w=Math.max(-1,...p.values())+1;for(const M of m)if(!p.has(M.id))p.set(M.id,w++);const x=new Map;for(const M of m){const E=p.get(M.id),_=x.get(E);if(_)_.push(M);else x.set(E,[M])}const k=[];let b=4;for(let M=0;M<=Math.max(-1,...p.values());M++){let E=4,_=0;for(const q of x.get(M)??[]){const Q=f.get(q.id);k.push({...Q,id:q.id,sections:q.sections,x:l?b:E,y:l?E:b});E+=(l?Q.height:Q.width)+6;_=Math.max(_,l?Q.width:Q.height)}b+=_+10}ps(k,a);const A=new Re,L=xi(k,u,a);const B=new Map(s.relations.map(M=>[M.id,M]));for(const M of L){const E=B.get(M.relation.id),_=A.element({id:E.id,kind:"edge",from:E.src,to:E.dst});jr(A,M,_,e.useAscii,E.type!=="contains");const q=E.type==="contains"?"start":"end",Q=q==="start"?M.source:M.target,$={shape:E.type==="contains"?"circle":"open-arrow",direction:{T:"B",B:"T",L:"R",R:"L"}[Q.side],ascii:e.useAscii};A.expectMarkers(_,q,[$]);A.expectMarkers(_,q==="start"?"end":"start",[]);A.marker(Q.x,Q.y,$,{owner:_,role:"arrow"});wr(A,M.label,_)}for(const M of k){const E={id:M.id,kind:"node"};A.region(E,M);const _=xn(M.sections,e.useAscii,1,{width:M.width,height:M.height});A.scope(E,()=>A.overlay(_,M.x,M.y))}const O=On(n)??e.title;if(O){const M=ve(Ge(O),c),E=new Re;M.forEach((_,q)=>E.text(0,q,_,{owner:{id:"title",kind:"label"}}));E.overlay(A,0,M.length+1);return Fe(E,{colorMode:r,theme:i})}return Fe(A,{colorMode:r,theme:i})}function ME(t){const e=Ul(t.source.authoredFamilyBody??t.source.familyBody);e.title??=t.config.title;const r=mC(t.source.config.treemap);const i=new Re;i.report({code:"TERMINAL_FAMILY_PROJECTION",feature:"treemap.area",message:"Treemap cell areas are projected as an ordered hierarchy with exact values; terminal cells do not encode rectangle area."});if(e.title)for(const l of ve(e.title,t.options.targetWidth))i.line([{text:l,role:"text",owner:{id:"title",kind:"label"}}]);const n=zl(e.nodes);const o=new Map;for(const l of[...e.nodes].reverse())o.set(l.id,l.value??(n.get(l.id)??[]).reduce((c,d)=>c+(o.get(d.id)??0),0));const s=new Map;let a;for(const l of e.nodes){const c=l.parentId?(s.get(l.parentId)??0)+1:0;s.set(l.id,c);const d=`${" ".repeat(c)}${t.config.useAscii?"+-":"\u251C\u2500"} `;const u=`${l.label}${r.showValues?`: ${(a??=fC(r.valueFormat))(o.get(l.id)??0)}`:""}`;const h=ve(u,t.options.targetWidth?Math.max(1,t.options.targetWidth-d.length):void 0);for(const[m,f]of h.entries())i.line([{text:m===0?d:" ".repeat(d.length),kind:"surface",owner:{id:l.id,kind:"node"}},{text:f,role:"text",owner:{id:l.id,kind:"node"}}])}return Fe(i,{colorMode:t.colorMode,theme:t.theme})}function AE(t){const e=$s(t.source.authoredFamilyBody??t.source.familyBody);const r=new Re;r.report({code:"TERMINAL_FAMILY_PROJECTION",feature:"ishikawa.fishbone",message:"The fishbone is projected as a cause/effect hierarchy; parent identities and complete labels are retained."});if(t.config.title)for(const n of ve(t.config.title,t.options.targetWidth))r.line([{text:n,role:"text",owner:{id:"title",kind:"label"}}]);const i=new Map;for(const n of e.nodes){const o=n.parentId?(i.get(n.parentId)??0)+1:0;i.set(n.id,o);const s=n.parentId?`${" ".repeat(o-1)}${t.config.useAscii?"+-> ":"\u2514\u2500\u2192 "}`:"Effect: ";const a=ve(n.label,t.options.targetWidth?Math.max(1,t.options.targetWidth-s.length):void 0);for(const[l,c]of a.entries())r.line([{text:l===0?s:" ".repeat(s.length),kind:"surface",owner:{id:n.id,kind:"node"}},{text:c,role:"text",owner:{id:n.id,kind:"node"}}])}return Fe(r,{colorMode:t.colorMode,theme:t.theme})}function OE(t,e,r,i,n={},o){const s=ln(t),a=o??e.targetWidth??e.maxWidth,l=s.root.columns&&s.root.columns>0?s.root.columns:Math.max(1,s.root.children?.length??1);const c=(b,A)=>{const L=b.label??(b.type==="composite"?"":b.id),B=ve(Lh(L),a?Math.max(1,Math.floor((a-8)/l)-6):void 0),O=b.type==="composite"&&L?B.length+2:0;return{block:b,lines:B,parentId:A,children:[],columns:b.columns??-1,span:b.widthInColumns??1,space:b.type==="space",head:O,nw:Math.max(6,...B.map(M=>ne(M)+4)),nh:Math.max(5,B.length+2),col:0,row:0,cols:0,heights:[],x:0,y:0,w:0,h:0}};const d=c(s.root),u=[d];d.nw=0;d.nh=0;for(let b=0;b<u.length;b++){const A=u[b];for(const L of A.block.children??[]){const B=c(L,A===d?void 0:A.block.id);A.children.push(B);u.push(B)}}const h=()=>u.slice(1).filter(b=>b.block.type!=="space").map(b=>({...b,id:b.block.id,x:Math.round(b.x-b.w/2)+4,y:Math.round(b.y-b.h/2)+4,width:Math.round(b.w),height:Math.round(b.h),container:b.block.type==="composite",headerHeight:b.head}));const m=s.edges.map(b=>({id:b.id,from:b.start,to:b.end,...b.label?{lines:ve(Lh(b.label),a?Math.max(1,a-8):void 0)}:{}}));const f=m.length?Math.max(6,2*(Ur+1)+1):6;Ih(d,f);let p=h();const g=new Map(u.map(b=>[b.block.id,b]));for(;;){let b=false;const A=new Map(p.map(L=>[L.id,L]));for(const[L,B]of ur(m,"TB",p)){const O=g.get(L),M=A.get(L);if(!O||!M)continue;if(M.width<B.width){O.nw=Math.max(O.nw,B.width);b=true}if(M.height<B.height){if(O.children.length)O.insetY=(O.insetY??f)+Math.ceil((B.height-M.height)/2);else O.nh=Math.max(O.nh,B.height);b=true}}if(!b)break;Ih(d,f);p=h()}const y=xi(p,m,"TB"),C=new Re;const w=new Map,x=new Map(s.edges.map(b=>[b.id,b]));for(const b of p)if(b.parentId){const A=w.get(b.parentId);if(A)A.push(b.id);else w.set(b.parentId,[b.id])}for(const b of p.filter(A=>A.container)){const A={id:b.id,kind:"cluster",parent:b.parentId?{id:b.parentId,kind:"cluster"}:void 0,members:w.get(b.id)??[]};Et(C,b,A,e.useAscii);if(b.block.label)C.textBlock(b.x+2,b.y+1,b.lines,{owner:A})}for(const b of y){const A=x.get(b.relation.id),L=C.element({id:A.id,kind:"edge",from:A.start,to:A.end});jr(C,b,L,e.useAscii,A.pattern==="dotted");for(const[B,O,M]of[["start",b.source,A.arrowTypeStart],["end",b.target,A.arrowTypeEnd]]){const E=M==="arrow_point"?"arrow":M==="arrow_circle"?"circle":M==="arrow_cross"?"cross":void 0,_=E?{shape:E,direction:{T:"B",B:"T",L:"R",R:"L"}[O.side],ascii:e.useAscii}:void 0;C.expectMarkers(L,B,_?[_]:[]);if(_)C.marker(O.x,O.y,_,{owner:L,role:"arrow"})}wr(C,b.label,L)}for(const b of p.filter(A=>!A.container)){const A={id:b.id,kind:"node",parent:b.parentId?{id:b.parentId,kind:"cluster"}:void 0};Et(C,b,A,e.useAscii,true);C.textBlock(b.x+2,b.y+1,b.lines,{owner:A});if(!["na","square"].includes(b.block.type??"na"))C.report({code:"TERMINAL_FAMILY_PROJECTION",feature:`block.${b.id}.shape`,message:`Block shape ${b.block.type} is represented by a terminal frame.`});if(b.block.type==="block_arrow"){C.report({code:"TERMINAL_FAMILY_PROJECTION",feature:`block.${b.id}.directions`,message:`Block arrow directions ${(b.block.directions??[]).join(", ")} are written beside its terminal frame.`});C.text(b.x+1,b.y+b.height-2,(b.block.directions??[]).join(","),{owner:A,role:"text"})}}const k=On(n)??e.title;if(k){const b=ve(Ge(k),a),A=new Re;b.forEach((L,B)=>A.text(0,B,L,{owner:{id:"title",kind:"label"}}));A.overlay(C,0,b.length+1);return Fe(A,{colorMode:r,theme:i})}return Fe(C,{colorMode:r,theme:i})}function BE(t,e,r,i,n,o={}){Gy(t);const s=Fy(o),a=bC(t),l=new Re,c=e.useAscii;l.titleHandled=true;wC(t,s);n??=e.targetWidth??e.maxWidth;const d=n?Math.max(8,Math.min(s.compact?32:Infinity,Math.floor(n/(s.compact?2:3)))):s.compact?32:42;const u=D=>qr(D,{display:"literal",maxWidth:o.wrap===false?void 0:d});const h=new Map,m=new Map;const f=t.relationships.map(D=>({id:a.relationships.get(D.id),from:D.source,to:D.target,lines:u(SC(t,D)).lines}));const p=t.layout.direction??t.layout.hints[0]?.direction??t.relationships.find(D=>D.direction)?.direction??"LR";const g=ur(f,p);for(const D of t.elements){const P=u(CC(D)),U=g.get(D.id),j=qu(D),G=j==="person"?3:j==="database"?2:0;h.set(D.id,P);m.set(D.id,{id:D.id,x:0,y:0,width:Math.max(P.width+(j==="queue"?8:4),U?.width??0,12),height:Math.max(P.height+2+G,U?.height??0,5)})}for(const D of t.boundaries){const P=u(kC(D)),U=g.get(D.id),j=P.height+2;h.set(D.id,P);m.set(D.id,{id:D.id,x:0,y:0,width:Math.max(P.width+4,U?.width??0,14),height:Math.max(j+8,(U?.height??0)+j*2),container:true,headerHeight:j})}const y=t.title??e.title,C=y===void 0?void 0:u(y);const w=s.compact?2:5,x=s.compact?3:5;const k=Math.max(s.compact?6:10,...f.map(D=>Math.max(0,...(D.lines??[]).map(ne))+(s.compact?4:6)));const b=Math.max(s.compact?4:6,...f.map(D=>(D.lines?.length??0)+(s.compact?3:6)));const A=s.compact&&n&&(p==="LR"||p==="RL")?Math.max(1,Math.floor((n-w*2+k)/(Math.max(1,...[...m.values()].filter(D=>!D.container).map(D=>D.width))+k))):s.shapesPerRow;const L={gapX:k,gapY:b,padding:x,marginX:w,marginY:w+(C?.height??0),shapesPerRow:t.layout.shapesPerRow??(s.input.c4ShapeInRow===void 0?Math.min(s.shapesPerRow,A):s.shapesPerRow),boundariesPerRow:t.layout.boundariesPerRow??s.boundariesPerRow,direction:p};let B=Dh(t,m,L);for(let D=0;D<f.length*2+2;D++){let P=false;for(const[U,j]of ur(f,p,[...B.boxes.values()])){const G=m.get(U);if(!G)continue;const se=Math.max(G.width,j.width),ce=Math.max(G.height,j.height+(G.container?(G.headerHeight??0)*2:0));if(se>G.width||ce>G.height){G.width=se;G.height=ce;P=true}}if(!P)break;B=Dh(t,m,L)}const O=xi([...B.boxes.values()],f,p);const M=D=>({id:a.nodes.get(D.id),kind:"external"in D?"node":"cluster",sourceLine:Rh(t,D.statementId),...D.parentId?{parent:{id:D.parentId,kind:"cluster"}}:{},...!("external"in D)?{members:[...t.elements,...t.boundaries].filter(P=>P.parentId===D.id).map(P=>P.id)}:{}});const E=D=>{const P=D?Ft(D):void 0;return P?Mr(P[0],P[1],P[2]):void 0};const _=(D,P)=>{const U=$y(D,s),j=E(U.stroke),G=E(U.text);for(const[se,ce,ae]of[...l.entries()])if(ae.owners.some(Y=>Y.id===P.id&&Y.kind===P.kind)){if(ae.kind==="text"&&G)ae.color=G;else if(ae.stroke){if(j)ae.color=j;if(U.dashed)l.stroke(se,ce,ae.stroke.mask,{owner:P,role:"border",ascii:c,style:D.style.lineStyle==="dotted"?"dotted":"dashed",color:j})}}if(U.fill)l.report({code:"TERMINAL_FILL_PROJECTED",feature:`c4.${D.id}.fill`,message:`C4 fill ${U.fill} on ${D.id} is represented by an unfilled terminal card; its semantic type remains in the label.`});if(U.fontSize||U.fontWeight||U.fontFamily)l.report({code:"TERMINAL_TYPOGRAPHY_PROJECTED",feature:`c4.${D.id}.font`,message:`C4 typography on ${D.id} uses terminal character cells.`})};const q=(D,P,U,j)=>{const G=B.boxes.get(D),se=h.get(D);const ce=U==="left"?G.x+2:U==="right"?G.x+G.width-2-se.width:G.x+Math.floor((G.width-se.width)/2);if(U)se.lines.forEach((ae,Y)=>l.textBlock(U==="left"?G.x+2:G.x+G.width-2-ne(ae),(j??G.y+1)+Y,mt(ae),{owner:P,role:"text",textGroup:`${P.id}:header`}));else l.textBlock(ce,j??G.y+1,mt(se.lines),{owner:P,role:"text"})};const Q=D=>{let P=t.boundaries.find(G=>G.id===D),U=0;const j=new Set;while(P?.parentId&&!j.has(P.id)){j.add(P.id);U++;P=t.boundaries.find(G=>G.id===P.parentId)};return U};for(const D of[...t.boundaries].sort((P,U)=>Q(P.id)-Q(U.id))){const P=B.boxes.get(D.id),U=l.element(M(D));Et(l,P,U,c);const j=P.y+P.headerHeight-1;for(let G=P.x+1;G<P.x+P.width-1;G++)l.stroke(G,j,10,{owner:U,role:"border",ascii:c});q(D.id,U,D.alignment);_(D,U)}for(const D of O){const P=t.relationships.find(j=>j.id===D.relation.id),U=l.element({id:P.id,kind:"edge",from:P.source,to:P.target,sourceLine:Rh(t,P.statementId)});if(P.style.lineStyle==="dotted"){if(!ss(l,D.path,U,c,"dotted"))throw new Error(`Allocated C4 route ${P.id} conflicts with admitted geometry`)}else jr(l,D,U,c,P.style.lineStyle==="dashed");for(const[j,G,se]of[["start",D.source,P.bidirectional],["end",D.target,true]]){const ce=se?{shape:"arrow",direction:{T:"B",R:"L",B:"T",L:"R"}[G.side],ascii:c}:void 0;l.expectMarkers(U,j,ce?[ce]:[]);if(ce)l.marker(G.x,G.y,ce,{owner:U,role:"arrow",color:E(P.style.lineColor)})}wr(l,D.label,U);for(const[,,j]of l.entries())if(j.owners.some(G=>G.id===P.id&&G.kind==="edge")){const G=E(j.kind==="text"?P.style.textColor:P.style.lineColor);if(G)j.color=G}}for(const D of t.elements){const P=B.boxes.get(D.id),U=l.element(M(D)),j=qu(D);Et(l,P,U,c,true);let G=P.y+Math.floor((P.height-h.get(D.id).height)/2);if(j==="person"){const se=P.x+Math.floor(P.width/2);for(const[ce,ae]of[" O ","/|\\","/ \\"].entries())for(const[Y,V]of[...ae].entries())if(V!==" ")l.put(se-1+Y,P.y+1+ce,V,{owner:U,role:"border",kind:"mark"});G=P.y+4}else if(j==="database"){const se=Qt("cylinder",c);for(const[ce,ae,Y,V]of[[P.x,P.y,6,se.tl],[P.x+P.width-1,P.y,12,se.tr],[P.x,P.y+P.height-1,3,se.bl],[P.x+P.width-1,P.y+P.height-1,9,se.br]]){if(c)l.put(ce,ae,V,{owner:U,role:"border",kind:"mark"});else l.stroke(ce,ae,Y,{owner:U,role:"border",ascii:c,rounded:true})}for(const ce of[P.y+1,P.y+P.height-2])for(let ae=P.x+1;ae<P.x+P.width-1;ae++)l.stroke(ae,ce,10,{owner:U,role:"border",ascii:c});G=P.y+2}else if(j==="queue"){for(const se of[P.x+2,P.x+P.width-3])for(let ce=P.y+1;ce<P.y+P.height-1;ce++)l.stroke(se,ce,5,{owner:U,role:"border",ascii:c})}q(D.id,U,void 0,G);_(D,U)}if(C)l.textBlock(5,1,mt(C.lines),{owner:{id:a.generated("c4:title",["c4","title"]),kind:"label"},role:"text"});for(const D of["diagramMarginX","diagramMarginY","c4ShapeMargin","c4ShapePadding","width","height","boxMargin","nextLinePaddingX","wrapPadding","maxWidth"])if(o[D]!==void 0)l.report({code:"TERMINAL_FAMILY_PROJECTION",feature:`c4.config.${D}`,message:`C4 ${D} is a pixel dimension; terminal layout independently allocates measured character cells.`});const $=TC(t,s);if($.length){const D=l.height+2;l.textBlock(5,D,mt("Legend"),{owner:{id:a.generated("c4:legend:title",["c4","legend","title"]),kind:"label"},role:"text"});let P=D+2;for(const U of $){const j=u(`${U.kind==="relationship"?"->":"[]"} ${U.label}`);l.textBlock(5,P,mt(j.lines),{owner:{id:U.id,kind:"label"},role:"text"});P+=j.height+1}}for(const D of t.relationships)if(D.style.offsetX!==void 0||D.style.offsetY!==void 0)l.report({code:"TERMINAL_FAMILY_PROJECTION",feature:`c4.${D.id}.label-offset`,message:`C4 relationship ${D.id} pixel label offsets are retained in the model; terminal labels use independent collision-free cell allocation.`});for(const D of[...t.diagnostics,...B.diagnostics])l.report({code:"TERMINAL_FAMILY_PROJECTION",feature:D.code,message:D.message});return Fe(l,{colorMode:r,theme:i})}import{decodeXML as rR}from"entities";function dp(t,e,r,i,n){return JSON.stringify([t,e,r,i,n])}function _E(t){const e=[{parent:null,region:0,transitions:t.transitions}];const r=i=>{for(const n of i){if(n.regions)n.regions.forEach((o,s)=>{e.push({parent:n.id,region:s,transitions:o.transitions});r(o.states)});else if(n.states){e.push({parent:n.id,region:0,transitions:n.transitions??[]});r(n.states)}}};r(t.states);return e}function n6(t){if(!t.meta.bodyComments?.length||t.body.kind!=="flowchart")return t;return{...t,body:{...t.body,graph:{...t.body.graph,edges:t.body.graph.edges.map(e=>({...e}))}}}}function o6(t,e,r){if(!t.meta.bodyComments?.length||e.kind==="preserved"||e.kind==="extension")return t;const i=r.kind==="rename_node"||r.kind==="rename_state"?r:void 0;const n=d=>{if(!i)return d;if(d===i.from)return i.to;if(t.kind==="state"&&(d===`${i.from}[H]`||d===`${i.from}[H*]`))return i.to+d.slice(i.from.length);return d};const o=new Map;if(t.body.kind==="flowchart"&&e.kind==="flowchart"){const d=r.kind==="remove_edge"&&typeof r.id==="string"?Vc(t.body.graph,r.id):-1;const u=new Map;const h=new Set(e.graph.edges.map(f=>JSON.stringify([f.source,f.target])));let m=0;for(const[f,p]of t.body.graph.edges.entries()){const g=`${p.source}->${p.target}`;const y=u.get(g)??0;u.set(g,y+1);if(f===d||!h.has(JSON.stringify([n(p.source),n(p.target)])))continue;const C=Yc(m++,{...p,source:n(p.source),target:n(p.target)});o.set(Yc(f,p),C);o.set(`${g}#${y}`,C);if(y===0)o.set(g,C)}}else if(t.body.kind==="state"&&e.kind==="state"){const d=_E(e);for(const u of _E(t.body)){const h=u.parent===null?null:n(u.parent);const m=d.find(C=>C.parent===h&&C.region===u.region);if(!m)continue;const f=r.kind==="remove_transition"&&(r.parent??null)===u.parent&&(r.region??0)===u.region?r.index??u.transitions.findIndex(C=>C.from===r.from&&C.to===r.to):-1;const p=new Map;const g=new Map;const y=new Set(m.transitions.map(C=>JSON.stringify([C.from,C.to])));for(const[C,w]of u.transitions.entries()){const x=JSON.stringify([w.from,w.to]);const k=p.get(x)??0;p.set(x,k+1);const b=n(w.from),A=n(w.to);if(C===f||!y.has(JSON.stringify([b,A])))continue;const L=JSON.stringify([b,A]);const B=g.get(L)??0;g.set(L,B+1);o.set(dp(u.parent,u.region,w.from,w.to,k),dp(h,u.region,b,A,B))}}}const s=Ii(t.kind)?.serialize?.(e);const a=s&&e.kind==="state"?up(s):void 0;const l=s&&!a?Ii(t.kind)?.buildSourceMap?.(e,s):void 0;const c=t.meta.bodyComments.map(d=>{if(!d.anchor)return d;const{collection:u,id:h}=d.anchor;const m=u==="edges"&&(e.kind==="flowchart"||e.kind==="state")?o.get(h):n(h);const f=m!==void 0&&(a?a.some(p=>p.collection===u&&p.id===m):l?.[u].has(m));return{...d,anchor:f?{collection:u,id:m}:void 0}});return{...t,meta:{...t.meta,bodyComments:c}}}function up(t){const e=st(t);const r=e.authoredWrapperLength??e.wrapperSource?.length??0;const i=Mn(t.slice(r).split(/\r?\n/,1)[0].trim()).split("\n")[0].trim();const n=Nl(t,i,r).body.start.offset;const o=Nn(t);const s=o.slice(0,n).replace(/[^\r\n]/g," ")+o.slice(n);const a=[];const l=new Set;const c=new Map;const d=[{parent:null,region:0}];for(const u of Lo(En(s.split(/\r?\n/))).statements){if(u.noteBody)continue;if(u.text==="}"){if(d.length>1)d.pop();continue}if(Xs(u.text)){d.at(-1).region++;continue}const h={line:u.line+1,endLine:u.line+1+(u.text.match(/\n/g)??[]).length};const m=Bo(u.text);if(m){const f=JSON.stringify([d.at(-1).parent,d.at(-1).region,m.from,m.to]);const p=c.get(f)??0;a.push({collection:"edges",id:dp(d.at(-1).parent,d.at(-1).region,m.from,m.to,p),...h});c.set(f,p+1)}else{const f=cc(u.text)??mc(u.text)?.id??_o.exec(u.text)?.[2]??Oi.exec(u.text)?.[2]??Io.exec(u.text)?.[1];if(f&&!l.has(f)){l.add(f);a.push({collection:"nodes",id:f,...h})}const p=Oi.exec(u.text);if(p)d.push({parent:p[2],region:0})}}return a}function IE(t,e){if(!t.meta.droppedComments?.length)return;const r=e.split(/\r?\n/);const i=t.kind==="state"?En(r):void 0;const n=(t.kind==="state"?up(e):t.kind!=="flowchart"?[]:["nodes","edges","groups"].flatMap(o=>[...t.source.spans?.[o]??[]].map(([s,a])=>({collection:o,id:s,line:a.start.line,endLine:a.end.line})))).sort((o,s)=>o.line-s.line||Number(s.collection==="edges")-Number(o.collection==="edges"));t.meta.bodyComments=t.meta.droppedComments.map(o=>{const s=r[o.line-1]??"";let a=i?i[o.line-1]?.commentIndex??-1:s.indexOf("%%");while(!i&&a>=0&&s.slice(a+2).trim()!==o.text.trim())a=s.indexOf("%%",a+2);const l=a>=0?s.slice(a):`%% ${o.text}`;const c=a>0&&s.slice(0,a).trim().length>0;const d=c&&o.line!==t.source.spans?.preserved.header.start.line;const u=d?n.find(h=>h.line<=o.line&&h.endLine>=o.line):n.find(h=>h.line>o.line);return{raw:l,...u?{anchor:{collection:u.collection,id:u.id}}:{},placement:d&&u?"after":"before"}});delete t.meta.droppedComments}function LE(t,e,r,i){if(!i.bodyComments?.length||r.kind==="opaque"||r.kind==="preserved"||r.kind==="extension")return t;const n=e==="state"?up(t):void 0;const o=n?void 0:Ii(e)?.buildSourceMap?.(r,t);const s=t.trimEnd().split("\n");const a=new Map;for(const l of i.bodyComments){if(typeof l.raw!=="string"||!l.raw.startsWith("%%")||/[\r\n]/.test(l.raw)||!["before","after"].includes(l.placement)||l.anchor&&!["nodes","edges","groups"].includes(l.anchor.collection))throw new Error("Invalid body comment metadata");const c=l.anchor&&(n?.find(f=>f.collection===l.anchor.collection&&f.id===l.anchor.id)??o?.[l.anchor.collection].get(l.anchor.id));const d=c&&"endLine"in c?c.endLine:c?.line;const u=c?l.placement==="before"?c.line-1:d:s.length;const h=a.get(u)??[];const m=e==="sankey"&&l.raw==="%%"?"%% ":l.raw;h.push(wo(m));a.set(u,h)}return s.flatMap((l,c)=>[...a.get(c)??[],l]).concat(a.get(s.length)??[]).join("\n")+"\n"}function RE(){let t=1e5;function e(){if(--t<0){const v=new Error("Configuration validation exceeded 100000 loop steps");v.name="MermaidConfigWorkLimitError";throw v}}var r=(v,S,{depth:I=2}={})=>{let W={depth:I};if(Array.isArray(S)&&!Array.isArray(v))return S.forEach(ye=>r(v,ye,W)),v;else if(Array.isArray(S)&&Array.isArray(v))return S.forEach(ye=>{if(!v.includes(ye))v.push(ye)}),v;if(v===void 0||v===null||I<=0)if(v!==void 0&&v!==null&&typeof v==="object"&&typeof S==="object")return Object.assign(v,S);else return S;if(S!==void 0&&S!==null&&typeof v==="object"&&typeof S==="object"){let ye=v;Object.entries(S).forEach(([te,Te])=>{if(typeof Te==="object"){if(Te===null)return;if(!Object.hasOwn(v,te))Object.defineProperty(v,te,{value:void 0,writable:true,enumerable:true,configurable:true});if(ye[te]===void 0)ye[te]=Array.isArray(Te)?[]:{};if(typeof ye[te]==="object")ye[te]=r(ye[te],Te,{depth:I-1})}else if(typeof ye[te]!=="object")if(Object.hasOwn(v,te))ye[te]=Te;else Object.defineProperty(v,te,{value:Te,writable:true,enumerable:true,configurable:true})})}return v},i=r;var n={flowchart:{useMaxWidth:true,theme:"redux-color",look:"neo",titleTopMargin:25,subGraphTitleMargin:{top:0,bottom:0},diagramPadding:8,htmlLabels:null,nodeSpacing:50,rankSpacing:50,curve:"basis",padding:15,wrappingWidth:120,minNodeWidth:120,inheritDir:false},swimlane:{useMaxWidth:true,theme:"redux-color",look:"neo",layout:"swimlane",lineHops:"arc",ignoreCrossLaneEdges:true,optimizeRanksByCrossings:true,automaticLaneOrdering:false},agentflow:{useMaxWidth:true,theme:"redux-color",look:"neo",titleTopMargin:25,diagramPadding:8,nodeSpacing:50,rankSpacing:50,wrappingWidth:120,minNodeWidth:120},sequence:{useMaxWidth:true,theme:"redux-color",look:"neo",hideUnusedParticipants:false,activationWidth:10,diagramMarginX:50,diagramMarginY:10,actorMargin:50,width:150,height:65,boxMargin:10,boxTextMargin:5,noteMargin:10,messageMargin:35,messageAlign:"center",mirrorActors:true,forceMenus:false,bottomMarginAdj:1,rightAngles:false,showSequenceNumbers:false,actorFontSize:14,actorFontFamily:'"Open Sans", sans-serif',actorFontWeight:400,noteFontSize:14,noteFontFamily:'"trebuchet ms", verdana, arial, sans-serif',noteFontWeight:400,noteAlign:"center",messageFontSize:16,messageFontFamily:'"trebuchet ms", verdana, arial, sans-serif',messageFontWeight:400,wrap:false,wrapPadding:10,labelBoxWidth:50,labelBoxHeight:20,messageFont:function(){return{fontFamily:this.messageFontFamily,fontSize:this.messageFontSize,fontWeight:this.messageFontWeight}},noteFont:function(){return{fontFamily:this.noteFontFamily,fontSize:this.noteFontSize,fontWeight:this.noteFontWeight}},actorFont:function(){return{fontFamily:this.actorFontFamily,fontSize:this.actorFontSize,fontWeight:this.actorFontWeight}}},gantt:{useMaxWidth:true,titleTopMargin:25,barHeight:20,barGap:4,topPadding:50,rightPadding:75,leftPadding:75,gridLineStartPadding:35,fontSize:11,sectionFontSize:11,numberSectionStyles:4,axisFormat:"%Y-%m-%d",topAxis:false,displayMode:"",weekday:"sunday",tickInterval:void 0,useWidth:void 0},journey:{useMaxWidth:true,diagramMarginX:50,diagramMarginY:10,leftMargin:150,maxLabelWidth:360,width:150,height:50,boxMargin:10,boxTextMargin:5,noteMargin:10,messageMargin:35,messageAlign:"center",bottomMarginAdj:1,rightAngles:false,taskFontSize:14,taskFontFamily:'"Open Sans", sans-serif',taskMargin:50,activationWidth:10,textPlacement:"fo",actorColours:["#8FBC8F","#7CFC00","#00FFFF","#20B2AA","#B0E0E6","#FFFFE0"],sectionFills:["#191970","#8B008B","#4B0082","#2F4F4F","#800000","#8B4513","#00008B"],sectionColours:["#fff"],titleColor:"",titleFontFamily:'"trebuchet ms", verdana, arial, sans-serif',titleFontSize:"4ex"},class:{theme:"redux-color",look:"neo",layout:void 0,hideEmptyMembersBox:false,hierarchicalNamespaces:true},state:{useMaxWidth:true,theme:"redux-color",look:"neo",layout:"elk",wrappingWidth:120,minNodeWidth:120,titleTopMargin:25,dividerMargin:10,sizeUnit:5,padding:8,textHeight:10,titleShift:-15,noteMargin:10,forkWidth:70,forkHeight:7,miniPadding:2,fontSizeFactor:5.02,fontSize:24,labelHeight:16,edgeLengthFactor:"20",compositTitleSize:35,radius:5},er:{useMaxWidth:true,theme:"redux-color",look:"neo",titleTopMargin:25,diagramPadding:20,layoutDirection:"TB",minEntityWidth:100,minEntityHeight:75,entityPadding:15,nodeSpacing:140,rankSpacing:80,stroke:"gray",fill:"honeydew",fontSize:12},pie:{useMaxWidth:true,textPosition:.75,donutHole:0,legendPosition:"right",highlightSlice:"",useWidth:984},quadrantChart:{useMaxWidth:true,chartWidth:500,chartHeight:500,titleFontSize:20,titlePadding:10,quadrantPadding:5,xAxisLabelPadding:5,yAxisLabelPadding:5,xAxisLabelFontSize:16,yAxisLabelFontSize:16,quadrantLabelFontSize:16,quadrantTextTopPadding:5,pointTextPadding:5,pointLabelFontSize:12,pointRadius:5,xAxisPosition:"top",yAxisPosition:"left",quadrantInternalBorderStrokeWidth:1,quadrantExternalBorderStrokeWidth:2},xyChart:{useMaxWidth:true,width:700,height:500,titleFontSize:20,titlePadding:10,showDataLabel:false,showDataLabelOutsideBar:false,showTitle:true,showLegend:true,legendFontSize:14,legendPadding:10,xAxis:{$ref:"#/$defs/XYChartAxisConfig",showLabel:true,labelFontSize:14,labelPadding:5,showTitle:true,titleFontSize:16,titlePadding:5,showTick:true,tickLength:5,tickWidth:2,showAxisLine:true,axisLineWidth:2,labelRotation:0},yAxis:{$ref:"#/$defs/XYChartAxisConfig",showLabel:true,labelFontSize:14,labelPadding:5,showTitle:true,titleFontSize:16,titlePadding:5,showTick:true,tickLength:5,tickWidth:2,showAxisLine:true,axisLineWidth:2,labelRotation:0},chartOrientation:"vertical",plotReservedSpacePercent:50,useWidth:void 0},requirement:{useMaxWidth:true,theme:"redux-color",look:"neo",rect_fill:"#f9f9f9",text_color:"#333",rect_border_size:"0.5px",rect_border_color:"#bbb",rect_min_width:200,rect_min_height:200,fontSize:14,rect_padding:10,line_height:20,useWidth:void 0},mindmap:{useMaxWidth:true,colorBy:"branch",padding:10,maxNodeWidth:200,layoutAlgorithm:"cose-bilkent"},ishikawa:{useMaxWidth:true,diagramPadding:20},kanban:{useMaxWidth:true,padding:8,sectionWidth:200,ticketBaseUrl:""},timeline:{useMaxWidth:true,diagramMarginX:50,diagramMarginY:10,leftMargin:150,width:150,height:50,boxMargin:10,boxTextMargin:5,noteMargin:10,messageMargin:35,messageAlign:"center",bottomMarginAdj:1,rightAngles:false,taskFontSize:14,taskFontFamily:'"Open Sans", sans-serif',taskMargin:50,activationWidth:10,textPlacement:"fo",actorColours:["#8FBC8F","#7CFC00","#00FFFF","#20B2AA","#B0E0E6","#FFFFE0"],sectionFills:["#191970","#8B008B","#4B0082","#2F4F4F","#800000","#8B4513","#00008B"],sectionColours:["#fff"],disableMulticolor:false},gitGraph:{useMaxWidth:true,titleTopMargin:25,diagramPadding:8,nodeLabel:{width:75,height:100,x:-25,y:0},mainBranchName:"main",mainBranchOrder:0,showCommitLabel:true,showBranches:true,rotateCommitLabel:true,parallelCommits:false,arrowMarkerAbsolute:false},c4:{useMaxWidth:true,diagramMarginX:50,diagramMarginY:10,c4ShapeMargin:50,c4ShapePadding:20,width:216,height:60,boxMargin:10,c4ShapeInRow:4,nextLinePaddingX:0,c4BoundaryInRow:2,personFontSize:14,personFontFamily:'"Open Sans", sans-serif',personFontWeight:"normal",external_personFontSize:14,external_personFontFamily:'"Open Sans", sans-serif',external_personFontWeight:"normal",systemFontSize:14,systemFontFamily:'"Open Sans", sans-serif',systemFontWeight:"normal",external_systemFontSize:14,external_systemFontFamily:'"Open Sans", sans-serif',external_systemFontWeight:"normal",system_dbFontSize:14,system_dbFontFamily:'"Open Sans", sans-serif',system_dbFontWeight:"normal",external_system_dbFontSize:14,external_system_dbFontFamily:'"Open Sans", sans-serif',external_system_dbFontWeight:"normal",system_queueFontSize:14,system_queueFontFamily:'"Open Sans", sans-serif',system_queueFontWeight:"normal",external_system_queueFontSize:14,external_system_queueFontFamily:'"Open Sans", sans-serif',external_system_queueFontWeight:"normal",boundaryFontSize:14,boundaryFontFamily:'"Open Sans", sans-serif',boundaryFontWeight:"normal",messageFontSize:12,messageFontFamily:'"Open Sans", sans-serif',messageFontWeight:"normal",containerFontSize:14,containerFontFamily:'"Open Sans", sans-serif',containerFontWeight:"normal",external_containerFontSize:14,external_containerFontFamily:'"Open Sans", sans-serif',external_containerFontWeight:"normal",container_dbFontSize:14,container_dbFontFamily:'"Open Sans", sans-serif',container_dbFontWeight:"normal",external_container_dbFontSize:14,external_container_dbFontFamily:'"Open Sans", sans-serif',external_container_dbFontWeight:"normal",container_queueFontSize:14,container_queueFontFamily:'"Open Sans", sans-serif',container_queueFontWeight:"normal",external_container_queueFontSize:14,external_container_queueFontFamily:'"Open Sans", sans-serif',external_container_queueFontWeight:"normal",componentFontSize:14,componentFontFamily:'"Open Sans", sans-serif',componentFontWeight:"normal",external_componentFontSize:14,external_componentFontFamily:'"Open Sans", sans-serif',external_componentFontWeight:"normal",component_dbFontSize:14,component_dbFontFamily:'"Open Sans", sans-serif',component_dbFontWeight:"normal",external_component_dbFontSize:14,external_component_dbFontFamily:'"Open Sans", sans-serif',external_component_dbFontWeight:"normal",component_queueFontSize:14,component_queueFontFamily:'"Open Sans", sans-serif',component_queueFontWeight:"normal",external_component_queueFontSize:14,external_component_queueFontFamily:'"Open Sans", sans-serif',external_component_queueFontWeight:"normal",wrap:true,wrapPadding:10,person_bg_color:"#08427B",person_border_color:"#073B6F",external_person_bg_color:"#686868",external_person_border_color:"#8A8A8A",system_bg_color:"#1168BD",system_border_color:"#3C7FC0",system_db_bg_color:"#1168BD",system_db_border_color:"#3C7FC0",system_queue_bg_color:"#1168BD",system_queue_border_color:"#3C7FC0",external_system_bg_color:"#999999",external_system_border_color:"#8A8A8A",external_system_db_bg_color:"#999999",external_system_db_border_color:"#8A8A8A",external_system_queue_bg_color:"#999999",external_system_queue_border_color:"#8A8A8A",container_bg_color:"#438DD5",container_border_color:"#3C7FC0",container_db_bg_color:"#438DD5",container_db_border_color:"#3C7FC0",container_queue_bg_color:"#438DD5",container_queue_border_color:"#3C7FC0",external_container_bg_color:"#B3B3B3",external_container_border_color:"#A6A6A6",external_container_db_bg_color:"#B3B3B3",external_container_db_border_color:"#A6A6A6",external_container_queue_bg_color:"#B3B3B3",external_container_queue_border_color:"#A6A6A6",component_bg_color:"#85BBF0",component_border_color:"#78A8D8",component_db_bg_color:"#85BBF0",component_db_border_color:"#78A8D8",component_queue_bg_color:"#85BBF0",component_queue_border_color:"#78A8D8",external_component_bg_color:"#CCCCCC",external_component_border_color:"#BFBFBF",external_component_db_bg_color:"#CCCCCC",external_component_db_border_color:"#BFBFBF",external_component_queue_bg_color:"#CCCCCC",external_component_queue_border_color:"#BFBFBF",useWidth:void 0,personFont:function(){return{fontFamily:this.personFontFamily,fontSize:this.personFontSize,fontWeight:this.personFontWeight}},flowchart:{useMaxWidth:true,theme:"redux-color",look:"neo",titleTopMargin:25,subGraphTitleMargin:{top:0,bottom:0},diagramPadding:8,htmlLabels:null,nodeSpacing:50,rankSpacing:50,curve:"basis",padding:15,wrappingWidth:120,minNodeWidth:120,inheritDir:false},external_personFont:function(){return{fontFamily:this.external_personFontFamily,fontSize:this.external_personFontSize,fontWeight:this.external_personFontWeight}},systemFont:function(){return{fontFamily:this.systemFontFamily,fontSize:this.systemFontSize,fontWeight:this.systemFontWeight}},external_systemFont:function(){return{fontFamily:this.external_systemFontFamily,fontSize:this.external_systemFontSize,fontWeight:this.external_systemFontWeight}},system_dbFont:function(){return{fontFamily:this.system_dbFontFamily,fontSize:this.system_dbFontSize,fontWeight:this.system_dbFontWeight}},external_system_dbFont:function(){return{fontFamily:this.external_system_dbFontFamily,fontSize:this.external_system_dbFontSize,fontWeight:this.external_system_dbFontWeight}},system_queueFont:function(){return{fontFamily:this.system_queueFontFamily,fontSize:this.system_queueFontSize,fontWeight:this.system_queueFontWeight}},external_system_queueFont:function(){return{fontFamily:this.external_system_queueFontFamily,fontSize:this.external_system_queueFontSize,fontWeight:this.external_system_queueFontWeight}},containerFont:function(){return{fontFamily:this.containerFontFamily,fontSize:this.containerFontSize,fontWeight:this.containerFontWeight}},external_containerFont:function(){return{fontFamily:this.external_containerFontFamily,fontSize:this.external_containerFontSize,fontWeight:this.external_containerFontWeight}},container_dbFont:function(){return{fontFamily:this.container_dbFontFamily,fontSize:this.container_dbFontSize,fontWeight:this.container_dbFontWeight}},external_container_dbFont:function(){return{fontFamily:this.external_container_dbFontFamily,fontSize:this.external_container_dbFontSize,fontWeight:this.external_container_dbFontWeight}},container_queueFont:function(){return{fontFamily:this.container_queueFontFamily,fontSize:this.container_queueFontSize,fontWeight:this.container_queueFontWeight}},external_container_queueFont:function(){return{fontFamily:this.external_container_queueFontFamily,fontSize:this.external_container_queueFontSize,fontWeight:this.external_container_queueFontWeight}},componentFont:function(){return{fontFamily:this.componentFontFamily,fontSize:this.componentFontSize,fontWeight:this.componentFontWeight}},external_componentFont:function(){return{fontFamily:this.external_componentFontFamily,fontSize:this.external_componentFontSize,fontWeight:this.external_componentFontWeight}},component_dbFont:function(){return{fontFamily:this.component_dbFontFamily,fontSize:this.component_dbFontSize,fontWeight:this.component_dbFontWeight}},external_component_dbFont:function(){return{fontFamily:this.external_component_dbFontFamily,fontSize:this.external_component_dbFontSize,fontWeight:this.external_component_dbFontWeight}},component_queueFont:function(){return{fontFamily:this.component_queueFontFamily,fontSize:this.component_queueFontSize,fontWeight:this.component_queueFontWeight}},external_component_queueFont:function(){return{fontFamily:this.external_component_queueFontFamily,fontSize:this.external_component_queueFontSize,fontWeight:this.external_component_queueFontWeight}},boundaryFont:function(){return{fontFamily:this.boundaryFontFamily,fontSize:this.boundaryFontSize,fontWeight:this.boundaryFontWeight}},messageFont:function(){return{fontFamily:this.messageFontFamily,fontSize:this.messageFontSize,fontWeight:this.messageFontWeight}}},sankey:{useMaxWidth:true,width:600,height:400,linkColor:"gradient",nodeAlignment:"justify",showValues:true,prefix:"",suffix:"",nodeWidth:10,nodePadding:12,labelStyle:"legacy",nodeColors:void 0},block:{useMaxWidth:true,padding:8},packet:{useMaxWidth:true,rowHeight:32,bitWidth:32,bitsPerRow:32,showBits:true,bitOrder:"ascending",paddingX:5,paddingY:5},treeView:{useMaxWidth:true,rowIndent:10,paddingX:5,paddingY:5,lineThickness:1,showIcons:false,defaultIconPack:"",filenameIcons:{},extensionIcons:{},useWidth:void 0},architecture:{useMaxWidth:true,padding:40,iconSize:80,fontSize:16,randomize:false,nodeSeparation:75,idealEdgeLengthMultiplier:1.5,edgeElasticity:.45,numIter:2500,seed:1},eventmodeling:{useMaxWidth:true,padding:30,rowHeight:32},radar:{useMaxWidth:true,width:600,height:600,marginTop:50,marginRight:50,marginBottom:50,marginLeft:50,axisScaleFactor:1,axisLabelFactor:1.05,curveTension:.17},usecase:{useMaxWidth:true,theme:"redux-color",look:"neo",wrappingWidth:120,minNodeWidth:120,actorFontSize:14,actorFontFamily:'"Open Sans", sans-serif',actorFontWeight:"normal",usecaseFontSize:12,usecaseFontFamily:'"Open Sans", sans-serif',usecaseFontWeight:"normal",nodeSpacing:50,rankSpacing:50,diagramPadding:20,colorScheme:"role"},venn:{useMaxWidth:true,theme:"redux-color",look:"neo",width:800,height:450,padding:8,useDebugLayout:false},cynefin:{useMaxWidth:true,width:800,height:600,padding:40,showDomainDescriptions:true,boundaryAmplitude:8,seed:0},theme:"default",look:"classic",handDrawnSeed:0,layout:"elk",maxTextSize:5e4,maxEdges:500,darkMode:false,fontFamily:'"trebuchet ms", verdana, arial, sans-serif;',logLevel:5,securityLevel:"strict",startOnLoad:true,arrowMarkerAbsolute:false,secure:["secure","securityLevel","startOnLoad","maxTextSize","suppressErrorRendering","maxEdges"],legacyMathML:false,forceLegacyMathML:false,deterministicIds:false,fontSize:16,markdownAutoWrap:true,suppressErrorRendering:false,deterministicIDSeed:void 0,elk:{mergeEdges:false,straightenEdges:true,lineHops:true,preset:"default",nodePlacementStrategy:void 0,layeringStrategy:void 0,cycleBreakingStrategy:void 0,layeringLayerBound:4,nodePlacementAlignment:void 0,forceNodeModelOrder:false,considerModelOrder:"NODES_AND_EDGES",keepEntryNodeOnTop:false,orientFeedbackEdges:true},themeCSS:void 0,themeVariables:{background:"white",primaryColor:"#ECECFF",secondaryColor:"#ffffde",tertiaryColor:"hsl(80, 100%, 96.2745098039%)",primaryBorderColor:"hsl(240, 60%, 86.2745098039%)",secondaryBorderColor:"hsl(60, 60%, 83.5294117647%)",tertiaryBorderColor:"hsl(80, 60%, 86.2745098039%)",primaryTextColor:"#131300",secondaryTextColor:"#000021",tertiaryTextColor:"rgb(6.3333333334, 0, 19.0000000001)",lineColor:"#333333",textColor:"#333",mainBkg:"#ECECFF",secondBkg:"#ffffde",border1:"#9370DB",border2:"#aaaa33",arrowheadColor:"#333333",fontFamily:'"trebuchet ms", verdana, arial, sans-serif',fontSize:"16px",labelBackground:"rgba(232,232,232, 0.8)",THEME_COLOR_LIMIT:12,radius:5,strokeWidth:1,nodeBkg:"#ECECFF",nodeBorder:"#9370DB",clusterBkg:"#ffffde",clusterBorder:"#aaaa33",defaultLinkColor:"#333333",titleColor:"#333",edgeLabelBackground:"rgba(232,232,232, 0.8)",actorBorder:"#9370DB",actorBkg:"#ECECFF",actorTextColor:"black",actorLineColor:"#9370DB",signalColor:"#333",signalTextColor:"#333",labelBoxBkgColor:"#ECECFF",labelBoxBorderColor:"#9370DB",labelTextColor:"black",loopTextColor:"black",noteBorderColor:"#aaaa33",noteBkgColor:"#fff5ad",noteTextColor:"black",activationBorderColor:"#666",activationBkgColor:"#f4f4f4",sequenceNumberColor:"white",sectionBkgColor:"rgba(102, 102, 255, 0.49)",altSectionBkgColor:"white",sectionBkgColor2:"#fff400",excludeBkgColor:"#eeeeee",taskBorderColor:"#534fbc",taskBkgColor:"#8a90dd",taskTextLightColor:"white",taskTextColor:"white",taskTextDarkColor:"black",taskTextOutsideColor:"black",taskTextClickableColor:"#003163",activeTaskBorderColor:"#534fbc",activeTaskBkgColor:"#bfc7ff",gridColor:"lightgrey",doneTaskBkgColor:"lightgrey",doneTaskBorderColor:"grey",critBorderColor:"#ff8888",critBkgColor:"red",todayLineColor:"red",vertLineColor:"navy",noteFontWeight:"normal",fontWeight:"normal",personBorder:"hsl(240, 60%, 86.2745098039%)",personBkg:"#ECECFF",archEdgeColor:"#333333",archEdgeArrowColor:"#333333",archEdgeWidth:"3",archGroupBorderColor:"hsl(240, 60%, 86.2745098039%)",archGroupBorderWidth:"2px",rowOdd:"hsl(240, 100%, 100%)",rowEven:"hsl(240, 100%, 97.2745098039%)",labelColor:"black",errorBkgColor:"#552222",errorTextColor:"#552222",useGradient:false,gradientStart:"hsl(240, 60%, 86.2745098039%)",gradientStop:"hsl(60, 60%, 83.5294117647%)",dropShadow:"drop-shadow(1px 2px 2px rgba(185, 185, 185, 1))",cScale0:"hsl(240, 100%, 76.2745098039%)",cScale1:"hsl(60, 100%, 73.5294117647%)",cScale2:"hsl(80, 100%, 76.2745098039%)",cScale3:"hsl(270, 100%, 76.2745098039%)",cScale4:"hsl(300, 100%, 76.2745098039%)",cScale5:"hsl(330, 100%, 76.2745098039%)",cScale6:"hsl(0, 100%, 76.2745098039%)",cScale7:"hsl(30, 100%, 76.2745098039%)",cScale8:"hsl(90, 100%, 76.2745098039%)",cScale9:"hsl(150, 100%, 76.2745098039%)",cScale10:"hsl(180, 100%, 76.2745098039%)",cScale11:"hsl(210, 100%, 76.2745098039%)",cScalePeer1:"hsl(60, 100%, 48.5294117647%)",cScalePeer2:"hsl(80, 100%, 56.2745098039%)",cScalePeer0:"hsl(240, 100%, 61.2745098039%)",cScalePeer3:"hsl(270, 100%, 61.2745098039%)",cScalePeer4:"hsl(300, 100%, 61.2745098039%)",cScalePeer5:"hsl(330, 100%, 61.2745098039%)",cScalePeer6:"hsl(0, 100%, 61.2745098039%)",cScalePeer7:"hsl(30, 100%, 61.2745098039%)",cScalePeer8:"hsl(90, 100%, 61.2745098039%)",cScalePeer9:"hsl(150, 100%, 61.2745098039%)",cScalePeer10:"hsl(180, 100%, 61.2745098039%)",cScalePeer11:"hsl(210, 100%, 61.2745098039%)",cScaleInv0:"hsl(60, 100%, 86.2745098039%)",cScaleInv1:"hsl(240, 100%, 83.5294117647%)",cScaleInv2:"hsl(260, 100%, 86.2745098039%)",cScaleInv3:"hsl(90, 100%, 86.2745098039%)",cScaleInv4:"hsl(120, 100%, 86.2745098039%)",cScaleInv5:"hsl(150, 100%, 86.2745098039%)",cScaleInv6:"hsl(180, 100%, 86.2745098039%)",cScaleInv7:"hsl(210, 100%, 86.2745098039%)",cScaleInv8:"hsl(270, 100%, 86.2745098039%)",cScaleInv9:"hsl(330, 100%, 86.2745098039%)",cScaleInv10:"hsl(0, 100%, 86.2745098039%)",cScaleInv11:"hsl(30, 100%, 86.2745098039%)",surface0:"hsl(270, 100%, 91.2745098039%)",surfacePeer0:"hsl(270, 100%, 89.2745098039%)",surface1:"hsl(270, 100%, 86.2745098039%)",surfacePeer1:"hsl(270, 100%, 84.2745098039%)",surface2:"hsl(270, 100%, 81.2745098039%)",surfacePeer2:"hsl(270, 100%, 79.2745098039%)",surface3:"hsl(270, 100%, 76.2745098039%)",surfacePeer3:"hsl(270, 100%, 74.2745098039%)",surface4:"hsl(270, 100%, 71.2745098039%)",surfacePeer4:"hsl(270, 100%, 69.2745098039%)",scaleLabelColor:"black",flowContainerStroke:"hsl(60, 60%, 83.5294117647%)",rectBkgColor:"hsl(80, 100%, 96.2745098039%)",transitionColor:"#333333",transitionLabelColor:"#333",stateLabelColor:"#131300",stateBkg:"#ECECFF",labelBackgroundColor:"#ECECFF",compositeBackground:"white",altBackground:"#f0f0f0",compositeTitleBackground:"#ECECFF",compositeBorder:"#9370DB",innerEndBackground:"#9370DB",specialStateColor:"#333333",classText:"#131300",fillType0:"#ECECFF",fillType1:"#ffffde",fillType2:"hsl(304, 100%, 96.2745098039%)",fillType3:"hsl(124, 100%, 93.5294117647%)",fillType4:"hsl(176, 100%, 96.2745098039%)",fillType5:"hsl(-4, 100%, 93.5294117647%)",fillType6:"hsl(8, 100%, 96.2745098039%)",fillType7:"hsl(188, 100%, 93.5294117647%)",pie1:"#ECECFF",pie2:"#ffffde",pie3:"hsl(80, 100%, 56.2745098039%)",pie4:"hsl(240, 100%, 86.2745098039%)",pie5:"hsl(60, 100%, 63.5294117647%)",pie6:"hsl(80, 100%, 76.2745098039%)",pie7:"hsl(300, 100%, 76.2745098039%)",pie8:"hsl(180, 100%, 56.2745098039%)",pie9:"hsl(0, 100%, 56.2745098039%)",pie10:"hsl(300, 100%, 56.2745098039%)",pie11:"hsl(150, 100%, 56.2745098039%)",pie12:"hsl(0, 100%, 66.2745098039%)",pieTitleTextSize:"25px",pieTitleTextColor:"black",pieSectionTextSize:"17px",pieSectionTextColor:"#333",pieLegendTextSize:"17px",pieLegendTextColor:"black",pieStrokeColor:"black",pieStrokeWidth:"2px",pieOuterStrokeWidth:"2px",pieOuterStrokeColor:"black",pieOpacity:"0.7",venn1:"hsl(240, 100%, 66.2745098039%)",venn2:"hsl(60, 100%, 63.5294117647%)",venn3:"hsl(80, 100%, 56.2745098039%)",venn4:"hsl(300, 100%, 66.2745098039%)",venn5:"hsl(180, 100%, 66.2745098039%)",venn6:"hsl(120, 100%, 63.5294117647%)",venn7:"hsl(0, 100%, 66.2745098039%)",venn8:"hsl(180, 100%, 63.5294117647%)",vennTitleTextColor:"#333",vennSetTextColor:"#333",cynefin:{domainFontSize:16,itemFontSize:12,boundaryColor:"#333333",boundaryWidth:2,cliffColor:"#8B0000",cliffWidth:4,arrowColor:"#333333",arrowWidth:2,complexBg:"#E8F5E9",complicatedBg:"#E3F2FD",chaoticBg:"#FBE9E7",clearBg:"#FFF8E1",confusionBg:"#F3E5F5",textColor:"#333",labelColor:"#131300"},quadrant1Fill:"#ECECFF",quadrant2Fill:"#f1f1ff",quadrant3Fill:"#f6f6ff",quadrant4Fill:"#fbfbff",quadrant1TextFill:"#131300",quadrant2TextFill:"#0e0e00",quadrant3TextFill:"#090900",quadrant4TextFill:"#040400",quadrantPointFill:"hsl(240, 100%, NaN%)",quadrantPointTextFill:"#131300",quadrantXAxisTextFill:"#131300",quadrantYAxisTextFill:"#131300",quadrantInternalBorderStrokeFill:"hsl(240, 60%, 86.2745098039%)",quadrantExternalBorderStrokeFill:"hsl(240, 60%, 86.2745098039%)",quadrantTitleFill:"#131300",radar:{axisColor:"#333333",axisStrokeWidth:2,axisLabelFontSize:12,curveOpacity:.5,curveStrokeWidth:2,graticuleColor:"#DEDEDE",graticuleStrokeWidth:1,graticuleOpacity:.3,legendBoxSize:12,legendFontSize:12},wardleyEvolutionColor:"#dc3545",wardley:{backgroundColor:"white",axisColor:"#333333",axisTextColor:"#131300",gridColor:"lightgrey",componentFill:"white",componentStroke:"#333333",componentLabelColor:"#131300",linkStroke:"#333333",evolutionStroke:"#dc3545",annotationStroke:"#333333",annotationTextColor:"#131300",annotationFill:"white"},xyChart:{backgroundColor:"white",titleColor:"#131300",dataLabelColor:"#131300",legendTextColor:"#131300",xAxisTitleColor:"#131300",xAxisLabelColor:"#131300",xAxisTickColor:"#131300",xAxisLineColor:"#131300",yAxisTitleColor:"#131300",yAxisLabelColor:"#131300",yAxisTickColor:"#131300",yAxisLineColor:"#131300",plotColorPalette:"#ECECFF,#8493A6,#FFC3A0,#DCDDE1,#B8E994,#D1A36F,#C3CDE6,#FFB6C1,#496078,#F8F3E3"},requirementBackground:"#ECECFF",requirementBorderColor:"hsl(240, 60%, 86.2745098039%)",requirementBorderSize:"1",requirementTextColor:"#131300",relationColor:"#333333",relationLabelBackground:"rgba(232,232,232, 0.8)",relationLabelColor:"black",git0:"hsl(240, 100%, 46.2745098039%)",git1:"hsl(60, 100%, 43.5294117647%)",git2:"hsl(80, 100%, 46.2745098039%)",git3:"hsl(210, 100%, 46.2745098039%)",git4:"hsl(180, 100%, 46.2745098039%)",git5:"hsl(150, 100%, 46.2745098039%)",git6:"hsl(300, 100%, 46.2745098039%)",git7:"hsl(0, 100%, 46.2745098039%)",gitInv0:"hsl(60, 100%, 3.7254901961%)",gitInv1:"rgb(0, 0, 160.5)",gitInv2:"rgb(48.8333333334, 0, 146.5000000001)",gitInv3:"rgb(146.5000000001, 73.2500000001, 0)",gitInv4:"rgb(146.5000000001, 0, 0)",gitInv5:"rgb(146.5000000001, 0, 73.2500000001)",gitInv6:"rgb(0, 146.5000000001, 0)",gitInv7:"rgb(0, 146.5000000001, 146.5000000001)",gitBranchLabel0:"#ffffff",gitBranchLabel1:"black",gitBranchLabel2:"black",gitBranchLabel3:"#ffffff",gitBranchLabel4:"black",gitBranchLabel5:"black",gitBranchLabel6:"black",gitBranchLabel7:"black",tagLabelColor:"#131300",tagLabelBackground:"#ECECFF",tagLabelBorder:"hsl(240, 60%, 86.2745098039%)",tagLabelFontSize:"10px",commitLabelColor:"#000021",commitLabelBackground:"#ffffde",commitLabelFontSize:"10px",emUiFill:"white",emUiStroke:"#dbdada",emProcessorFill:"#edb3f6",emProcessorStroke:"#b88cbf",emReadModelFill:"#d3f1a2",emReadModelStroke:"#a3b732",emCommandFill:"#bcd6fe",emCommandStroke:"#679ac3",emEventFill:"#ffb778",emEventStroke:"#c19a0f",emSwimlaneBackgroundOdd:"rgb(250,250,250)",emSwimlaneBackgroundStroke:"rgb(240,240,240)",emArrowhead:"#333333",emRelationStroke:"#333333",attributeBackgroundColorOdd:"#ffffff",attributeBackgroundColorEven:"#f2f2f2",cScaleLabel0:"#ffffff",cScaleLabel3:"#ffffff",cScaleLabel1:"black",cScaleLabel2:"black",cScaleLabel4:"black",cScaleLabel5:"black",cScaleLabel6:"black",cScaleLabel7:"black",cScaleLabel8:"black",cScaleLabel9:"black",cScaleLabel10:"black",cScaleLabel11:"black"},railroad:{fontSize:void 0,fontFamily:void 0,terminalFill:void 0,terminalStroke:void 0,terminalTextColor:void 0,nonTerminalFill:void 0,nonTerminalStroke:void 0,nonTerminalTextColor:void 0,lineColor:void 0,markerFill:void 0,commentFill:void 0,commentStroke:void 0,commentTextColor:void 0,specialFill:void 0,specialStroke:void 0,ruleNameColor:void 0},treemap:{useMaxWidth:true,padding:10,diagramPadding:8,showValues:true,nodeWidth:100,nodeHeight:40,borderWidth:1,valueFontSize:12,labelFontSize:14,valueFormat:","}},o=n,s=new Set(["flowchart","useMaxWidth","theme","look","titleTopMargin","subGraphTitleMargin","top","bottom","diagramPadding","htmlLabels","nodeSpacing","rankSpacing","curve","padding","wrappingWidth","minNodeWidth","inheritDir","swimlane","layout","lineHops","ignoreCrossLaneEdges","optimizeRanksByCrossings","automaticLaneOrdering","agentflow","sequence","hideUnusedParticipants","activationWidth","diagramMarginX","diagramMarginY","actorMargin","width","height","boxMargin","boxTextMargin","noteMargin","messageMargin","messageAlign","mirrorActors","forceMenus","bottomMarginAdj","rightAngles","showSequenceNumbers","actorFontSize","actorFontFamily","actorFontWeight","noteFontSize","noteFontFamily","noteFontWeight","noteAlign","messageFontSize","messageFontFamily","messageFontWeight","wrap","wrapPadding","labelBoxWidth","labelBoxHeight","messageFont","noteFont","actorFont","gantt","barHeight","barGap","topPadding","rightPadding","leftPadding","gridLineStartPadding","fontSize","sectionFontSize","numberSectionStyles","axisFormat","topAxis","displayMode","weekday","tickInterval","useWidth","journey","leftMargin","maxLabelWidth","taskFontSize","taskFontFamily","taskMargin","textPlacement","titleColor","titleFontFamily","titleFontSize","class","hideEmptyMembersBox","hierarchicalNamespaces","state","dividerMargin","sizeUnit","textHeight","titleShift","forkWidth","forkHeight","miniPadding","fontSizeFactor","labelHeight","edgeLengthFactor","compositTitleSize","radius","er","layoutDirection","minEntityWidth","minEntityHeight","entityPadding","stroke","fill","pie","textPosition","donutHole","legendPosition","highlightSlice","quadrantChart","chartWidth","chartHeight","titlePadding","quadrantPadding","xAxisLabelPadding","yAxisLabelPadding","xAxisLabelFontSize","yAxisLabelFontSize","quadrantLabelFontSize","quadrantTextTopPadding","pointTextPadding","pointLabelFontSize","pointRadius","xAxisPosition","yAxisPosition","quadrantInternalBorderStrokeWidth","quadrantExternalBorderStrokeWidth","xyChart","showDataLabel","showDataLabelOutsideBar","showTitle","showLegend","legendFontSize","legendPadding","xAxis","$ref","showLabel","labelFontSize","labelPadding","showTick","tickLength","tickWidth","showAxisLine","axisLineWidth","labelRotation","yAxis","chartOrientation","plotReservedSpacePercent","requirement","rect_fill","text_color","rect_border_size","rect_border_color","rect_min_width","rect_min_height","rect_padding","line_height","mindmap","colorBy","maxNodeWidth","layoutAlgorithm","ishikawa","kanban","sectionWidth","ticketBaseUrl","timeline","disableMulticolor","gitGraph","nodeLabel","x","y","mainBranchName","mainBranchOrder","showCommitLabel","showBranches","rotateCommitLabel","parallelCommits","arrowMarkerAbsolute","c4","c4ShapeMargin","c4ShapePadding","c4ShapeInRow","nextLinePaddingX","c4BoundaryInRow","personFontSize","personFontFamily","personFontWeight","external_personFontSize","external_personFontFamily","external_personFontWeight","systemFontSize","systemFontFamily","systemFontWeight","external_systemFontSize","external_systemFontFamily","external_systemFontWeight","system_dbFontSize","system_dbFontFamily","system_dbFontWeight","external_system_dbFontSize","external_system_dbFontFamily","external_system_dbFontWeight","system_queueFontSize","system_queueFontFamily","system_queueFontWeight","external_system_queueFontSize","external_system_queueFontFamily","external_system_queueFontWeight","boundaryFontSize","boundaryFontFamily","boundaryFontWeight","containerFontSize","containerFontFamily","containerFontWeight","external_containerFontSize","external_containerFontFamily","external_containerFontWeight","container_dbFontSize","container_dbFontFamily","container_dbFontWeight","external_container_dbFontSize","external_container_dbFontFamily","external_container_dbFontWeight","container_queueFontSize","container_queueFontFamily","container_queueFontWeight","external_container_queueFontSize","external_container_queueFontFamily","external_container_queueFontWeight","componentFontSize","componentFontFamily","componentFontWeight","external_componentFontSize","external_componentFontFamily","external_componentFontWeight","component_dbFontSize","component_dbFontFamily","component_dbFontWeight","external_component_dbFontSize","external_component_dbFontFamily","external_component_dbFontWeight","component_queueFontSize","component_queueFontFamily","component_queueFontWeight","external_component_queueFontSize","external_component_queueFontFamily","external_component_queueFontWeight","person_bg_color","person_border_color","external_person_bg_color","external_person_border_color","system_bg_color","system_border_color","system_db_bg_color","system_db_border_color","system_queue_bg_color","system_queue_border_color","external_system_bg_color","external_system_border_color","external_system_db_bg_color","external_system_db_border_color","external_system_queue_bg_color","external_system_queue_border_color","container_bg_color","container_border_color","container_db_bg_color","container_db_border_color","container_queue_bg_color","container_queue_border_color","external_container_bg_color","external_container_border_color","external_container_db_bg_color","external_container_db_border_color","external_container_queue_bg_color","external_container_queue_border_color","component_bg_color","component_border_color","component_db_bg_color","component_db_border_color","component_queue_bg_color","component_queue_border_color","external_component_bg_color","external_component_border_color","external_component_db_bg_color","external_component_db_border_color","external_component_queue_bg_color","external_component_queue_border_color","personFont","external_personFont","systemFont","external_systemFont","system_dbFont","external_system_dbFont","system_queueFont","external_system_queueFont","containerFont","external_containerFont","container_dbFont","external_container_dbFont","container_queueFont","external_container_queueFont","componentFont","external_componentFont","component_dbFont","external_component_dbFont","component_queueFont","external_component_queueFont","boundaryFont","sankey","linkColor","nodeAlignment","showValues","prefix","suffix","nodeWidth","nodePadding","labelStyle","nodeColors","block","packet","rowHeight","bitWidth","bitsPerRow","showBits","bitOrder","paddingX","paddingY","treeView","rowIndent","lineThickness","showIcons","defaultIconPack","filenameIcons","extensionIcons","architecture","iconSize","randomize","nodeSeparation","idealEdgeLengthMultiplier","edgeElasticity","numIter","seed","eventmodeling","radar","marginTop","marginRight","marginBottom","marginLeft","axisScaleFactor","axisLabelFactor","curveTension","usecase","usecaseFontSize","usecaseFontFamily","usecaseFontWeight","colorScheme","venn","useDebugLayout","cynefin","showDomainDescriptions","boundaryAmplitude","handDrawnSeed","maxTextSize","maxEdges","darkMode","fontFamily","logLevel","securityLevel","startOnLoad","legacyMathML","forceLegacyMathML","deterministicIds","markdownAutoWrap","suppressErrorRendering","deterministicIDSeed","elk","mergeEdges","straightenEdges","preset","nodePlacementStrategy","layeringStrategy","cycleBreakingStrategy","layeringLayerBound","nodePlacementAlignment","forceNodeModelOrder","considerModelOrder","keepEntryNodeOnTop","orientFeedbackEdges","themeCSS","themeVariables","background","primaryColor","secondaryColor","tertiaryColor","primaryBorderColor","secondaryBorderColor","tertiaryBorderColor","primaryTextColor","secondaryTextColor","tertiaryTextColor","lineColor","textColor","mainBkg","secondBkg","border1","border2","arrowheadColor","labelBackground","THEME_COLOR_LIMIT","strokeWidth","nodeBkg","nodeBorder","clusterBkg","clusterBorder","defaultLinkColor","edgeLabelBackground","actorBorder","actorBkg","actorTextColor","actorLineColor","signalColor","signalTextColor","labelBoxBkgColor","labelBoxBorderColor","labelTextColor","loopTextColor","noteBorderColor","noteBkgColor","noteTextColor","activationBorderColor","activationBkgColor","sequenceNumberColor","sectionBkgColor","altSectionBkgColor","sectionBkgColor2","excludeBkgColor","taskBorderColor","taskBkgColor","taskTextLightColor","taskTextColor","taskTextDarkColor","taskTextOutsideColor","taskTextClickableColor","activeTaskBorderColor","activeTaskBkgColor","gridColor","doneTaskBkgColor","doneTaskBorderColor","critBorderColor","critBkgColor","todayLineColor","vertLineColor","fontWeight","personBorder","personBkg","archEdgeColor","archEdgeArrowColor","archEdgeWidth","archGroupBorderColor","archGroupBorderWidth","rowOdd","rowEven","labelColor","errorBkgColor","errorTextColor","useGradient","gradientStart","gradientStop","dropShadow","cScale0","cScale1","cScale2","cScale3","cScale4","cScale5","cScale6","cScale7","cScale8","cScale9","cScale10","cScale11","cScalePeer1","cScalePeer2","cScalePeer0","cScalePeer3","cScalePeer4","cScalePeer5","cScalePeer6","cScalePeer7","cScalePeer8","cScalePeer9","cScalePeer10","cScalePeer11","cScaleInv0","cScaleInv1","cScaleInv2","cScaleInv3","cScaleInv4","cScaleInv5","cScaleInv6","cScaleInv7","cScaleInv8","cScaleInv9","cScaleInv10","cScaleInv11","surface0","surfacePeer0","surface1","surfacePeer1","surface2","surfacePeer2","surface3","surfacePeer3","surface4","surfacePeer4","scaleLabelColor","flowContainerStroke","rectBkgColor","transitionColor","transitionLabelColor","stateLabelColor","stateBkg","labelBackgroundColor","compositeBackground","altBackground","compositeTitleBackground","compositeBorder","innerEndBackground","specialStateColor","classText","fillType0","fillType1","fillType2","fillType3","fillType4","fillType5","fillType6","fillType7","pie1","pie2","pie3","pie4","pie5","pie6","pie7","pie8","pie9","pie10","pie11","pie12","pieTitleTextSize","pieTitleTextColor","pieSectionTextSize","pieSectionTextColor","pieLegendTextSize","pieLegendTextColor","pieStrokeColor","pieStrokeWidth","pieOuterStrokeWidth","pieOuterStrokeColor","pieOpacity","venn1","venn2","venn3","venn4","venn5","venn6","venn7","venn8","vennTitleTextColor","vennSetTextColor","domainFontSize","itemFontSize","boundaryColor","boundaryWidth","cliffColor","cliffWidth","arrowColor","arrowWidth","complexBg","complicatedBg","chaoticBg","clearBg","confusionBg","quadrant1Fill","quadrant2Fill","quadrant3Fill","quadrant4Fill","quadrant1TextFill","quadrant2TextFill","quadrant3TextFill","quadrant4TextFill","quadrantPointFill","quadrantPointTextFill","quadrantXAxisTextFill","quadrantYAxisTextFill","quadrantInternalBorderStrokeFill","quadrantExternalBorderStrokeFill","quadrantTitleFill","axisColor","axisStrokeWidth","axisLabelFontSize","curveOpacity","curveStrokeWidth","graticuleColor","graticuleStrokeWidth","graticuleOpacity","legendBoxSize","wardleyEvolutionColor","wardley","backgroundColor","axisTextColor","componentFill","componentStroke","componentLabelColor","linkStroke","evolutionStroke","annotationStroke","annotationTextColor","annotationFill","dataLabelColor","legendTextColor","xAxisTitleColor","xAxisLabelColor","xAxisTickColor","xAxisLineColor","yAxisTitleColor","yAxisLabelColor","yAxisTickColor","yAxisLineColor","plotColorPalette","requirementBackground","requirementBorderColor","requirementBorderSize","requirementTextColor","relationColor","relationLabelBackground","relationLabelColor","git0","git1","git2","git3","git4","git5","git6","git7","gitInv0","gitInv1","gitInv2","gitInv3","gitInv4","gitInv5","gitInv6","gitInv7","gitBranchLabel0","gitBranchLabel1","gitBranchLabel2","gitBranchLabel3","gitBranchLabel4","gitBranchLabel5","gitBranchLabel6","gitBranchLabel7","tagLabelColor","tagLabelBackground","tagLabelBorder","tagLabelFontSize","commitLabelColor","commitLabelBackground","commitLabelFontSize","emUiFill","emUiStroke","emProcessorFill","emProcessorStroke","emReadModelFill","emReadModelStroke","emCommandFill","emCommandStroke","emEventFill","emEventStroke","emSwimlaneBackgroundOdd","emSwimlaneBackgroundStroke","emArrowhead","emRelationStroke","attributeBackgroundColorOdd","attributeBackgroundColorEven","cScaleLabel0","cScaleLabel3","cScaleLabel1","cScaleLabel2","cScaleLabel4","cScaleLabel5","cScaleLabel6","cScaleLabel7","cScaleLabel8","cScaleLabel9","cScaleLabel10","cScaleLabel11","railroad","terminalFill","terminalStroke","terminalTextColor","nonTerminalFill","nonTerminalStroke","nonTerminalTextColor","markerFill","commentFill","commentStroke","commentTextColor","specialFill","specialStroke","ruleNameColor","treemap","nodeHeight","borderWidth","valueFontSize","valueFormat"]);var a={trace(){},debug(){},info(){},warn(){},error(){},fatal(){}};var l={nodeColors:/^#[\da-f]{3,8}$|^rgb\([\d\s%,.]+\)$|^hsl\([\d\s%,.]+\)$|^[a-z]+$/i,filenameIcons:/^[\w-]+(?::[\w-]+)?$/,extensionIcons:/^[\w-]+(?::[\w-]+)?$/},c=(v,S)=>{for(let I of Object.keys(v)){e();let W=v[I];if(I.startsWith("__")||I.includes("proto")||I.includes("constr")||typeof W!=="string"||!S.test(W))a.debug("sanitize deleting dictionary entry:",I,W),delete v[I]}},d=v=>{if(a.debug("sanitizeDirective called with",v),typeof v!=="object"||v==null)return;if(Array.isArray(v)){v.forEach(S=>d(S));return}for(let S of Object.keys(v)){e();if(a.debug("Checking key",S),S.startsWith("__")||S.includes("proto")||S.includes("constr")||!s.has(S)||v[S]==null){a.debug("sanitize deleting key: ",S),delete v[S];continue}if(typeof v[S]==="object"){let W=l[S];if(W)c(v[S],W);else a.debug("sanitizing object",S),d(v[S]);continue}let I=["themeCSS","fontFamily","altFontFamily"];for(let W of I){e();if(S.includes(W))a.debug("sanitizing css option",S),v[S]=u(v[S])}}if(v.themeVariables)for(let S of Object.keys(v.themeVariables)){e();let I=v.themeVariables[S];if(I?.match&&!I.match(/^[\d "#%(),.;A-Za-z]+$/))v.themeVariables[S]=""}a.debug("After sanitization",v)},u=v=>{let S=0,I=0;for(let W of v){e();if(S<I)return"{ /* ERROR: Unbalanced CSS */ }";if(W==="{")S++;else if(W==="}")I++}if(S!==I)return"{ /* ERROR: Unbalanced CSS */ }";return v};function h(){}function m(v){return v==null||typeof v!=="object"&&typeof v!=="function"}function f(v){return Object.getOwnPropertySymbols(v).filter(S=>Object.prototype.propertyIsEnumerable.call(v,S))}var p=typeof globalThis==="object"&&globalThis||typeof window==="object"&&window||typeof self==="object"&&self||typeof global==="object"&&global||(function(){return this})();function g(v){return typeof p.Buffer<"u"&&p.Buffer.isBuffer(v)}function y(v){return v==="__proto__"}function C(v){if(typeof v!=="object")return false;if(v==null)return false;if(Object.getPrototypeOf(v)===null)return true;if(Object.prototype.toString.call(v)!=="[object Object]"){var S;let W=v[Symbol.toStringTag];if(W==null)return false;if(!((S=Object.getOwnPropertyDescriptor(v,Symbol.toStringTag))===null||S===void 0?void 0:S.writable))return false;return v.toString()===`[object ${W}]`}let I=v;while(Object.getPrototypeOf(I)!==null){e();I=Object.getPrototypeOf(I)}return Object.getPrototypeOf(v)===I}function w(v){return ArrayBuffer.isView(v)&&!(v instanceof DataView)}function x(v){return w(v)}function k(v){if(v==null)return v===void 0?"[object Undefined]":"[object Null]";return Object.prototype.toString.call(v)}var b="[object RegExp]",A="[object String]",L="[object Number]",B="[object Boolean]",O="[object Arguments]",M="[object Symbol]",E="[object Date]",_="[object Map]",q="[object Set]",Q="[object Array]";var $="[object ArrayBuffer]",D="[object Object]";var P="[object DataView]",U="[object Uint8Array]",j="[object Uint8ClampedArray]",G="[object Uint16Array]",se="[object Uint32Array]";var ce="[object Int8Array]",ae="[object Int16Array]",Y="[object Int32Array]";var V="[object Float32Array]",N="[object Float64Array]";var J=Object.prototype.hasOwnProperty;function ee(v,S){return J.call(v,S)}function X(v){return g(v)}function ie(v,S){return ge(v,void 0,v,new Map,S)}function ge(v,S,I,W,ye){if(ye!=null){let Te=ye(v,S,I,W);if(Te!==void 0)return Te}if(m(v))return v;if(W.has(v))return W.get(v);if(Array.isArray(v)){let Te=Array(v.length);W.set(v,Te);for(let De=0;De<v.length;De++){e();Te[De]=ge(v[De],De,I,W,ye)}if(ee(v,"index"))Te.index=v.index;if(ee(v,"input"))Te.input=v.input;return Te}if(v instanceof Date)return new Date(v.getTime());if(v instanceof RegExp){let Te=new RegExp(v.source,v.flags);return Te.lastIndex=v.lastIndex,Te}if(v instanceof Map){let Te=new Map;return W.set(v,Te),v.forEach((De,tt)=>{Te.set(tt,ge(De,tt,I,W,ye))}),Te}if(v instanceof Set){let Te=new Set;return W.set(v,Te),v.forEach(De=>{Te.add(ge(De,void 0,I,W,ye))}),Te}if(X(v))return v.subarray();if(x(v)){let Te=new(Object.getPrototypeOf(v)).constructor(v.length);W.set(v,Te);for(let De=0;De<v.length;De++){e();Te[De]=ge(v[De],De,I,W,ye)}return Te}if(v instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&v instanceof SharedArrayBuffer)return v.slice(0);if(v instanceof DataView){let Te=new DataView(v.buffer.slice(0),v.byteOffset,v.byteLength);return W.set(v,Te),fe(Te,v,I,W,ye),Te}if(typeof File<"u"&&v instanceof File){let Te=new File([v],v.name,{type:v.type});return W.set(v,Te),fe(Te,v,I,W,ye),Te}if(typeof Blob<"u"&&v instanceof Blob){let Te=new Blob([v],{type:v.type});return W.set(v,Te),fe(Te,v,I,W,ye),Te}let te=k(v);if(te==="[object Error]"){if(v===I)return{};return v}switch(te){case L:case A:case B:{let Te=new v.constructor(v.valueOf());return W.set(v,Te),fe(Te,v,I,W,ye),Te}case O:{let Te={};return W.set(v,Te),fe(Te,v,I,W,ye),Te.length=v.length,Te[Symbol.iterator]=v[Symbol.iterator],Te}}if(typeof v==="object"&&de(te)){let Te=te==="[object Object]"&&typeof v.constructor!=="function"?{}:Object.create(Object.getPrototypeOf(v));return W.set(v,Te),fe(Te,v,I,W,ye),Te}return v}function fe(v,S,I,W,ye){let te=[...Object.keys(S),...f(S)];for(let Te=0;Te<te.length;Te++){e();let De=te[Te],tt=Object.getOwnPropertyDescriptor(v,De);if(tt==null||tt.writable)v[De]=ge(S[De],De,I,W,ye)}}function de(v){switch(v){case O:case Q:case $:case P:case B:case E:case V:case N:case ce:case ae:case Y:case _:case L:case D:case b:case q:case A:case M:case U:case j:case G:case se:return true;default:return false}}function xe(v){return ie(v)}function we(v){return v!==null&&typeof v==="object"&&k(v)==="[object Arguments]"}function Be(v){return typeof v==="object"&&v!==null}function Ie(v){return Number.isSafeInteger(v)&&v>=0}function Me(v){return v!=null&&typeof v!=="function"&&Ie(v.length)}function Ae(v){return Be(v)&&Me(v)}function He(v){if(m(v))return v;if(Array.isArray(v)||w(v)||v instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&v instanceof SharedArrayBuffer)return v.slice(0);let S=Object.getPrototypeOf(v);if(S==null)return Object.assign(Object.create(S),v);let I=S.constructor;if(v instanceof Date||v instanceof Map||v instanceof Set)return new I(v);if(v instanceof RegExp){let W=new I(v);return W.lastIndex=v.lastIndex,W}if(v instanceof DataView)return new I(v.buffer.slice(0));if(v instanceof Error){let W;if(typeof AggregateError<"u"&&v instanceof AggregateError)W=new I(v.errors,v.message,{cause:v.cause});else W=new I(v.message,{cause:v.cause});return W.stack=v.stack,Object.assign(W,v),W}if(typeof File<"u"&&v instanceof File)return new I([v],v.name,{type:v.type,lastModified:v.lastModified});if(typeof v==="object"){let W=Object.create(S);return Object.assign(W,v)}return v}function Ne(v,...S){let I=S.slice(0,-1),W=S[S.length-1],ye=v;for(let te=0;te<I.length;te++){e();let Te=I[te];ye=K(ye,Te,W,new Map)}return ye}function K(v,S,I,W){if(m(v))v=Object(v);if(S==null||typeof S!=="object")return v;if(W.has(S))return He(W.get(S));if(W.set(S,v),Array.isArray(S)){S=S.slice();for(let te=0;te<S.length;te++){e();if(!(te in S))S[te]=void 0}}let ye=[...Object.keys(S),...f(S)];for(let te=0;te<ye.length;te++){e();let Te=ye[te];if(y(Te))continue;let De=S[Te],tt=v[Te];if(we(De))De=Object.assign({},De);if(we(tt))tt=Object.assign({},tt);if(g(De))De=xe(De);if(Array.isArray(De))if(Array.isArray(tt)){let Ht=[],Er=Reflect.ownKeys(tt);for(let Qi=0;Qi<Er.length;Qi++){e();let ho=Er[Qi];Ht[ho]=tt[ho]}tt=Ht}else if(Ae(tt)){let Ht=[];for(let Er=0;Er<tt.length;Er++){e();Ht[Er]=tt[Er]}tt=Ht}else tt=[];let pr=I(tt,De,Te,v,S,W);if(pr!==void 0)v[Te]=pr;else if(Array.isArray(De))v[Te]=K(tt,De,I,W);else if(Be(tt)&&Be(De)&&(C(tt)||C(De)||x(tt)||x(De)))v[Te]=K(tt,De,I,W);else if(tt==null&&C(De))v[Te]=K({},De,I,W);else if(tt==null&&x(De))v[Te]=xe(De);else if(tt===void 0||De!==void 0)v[Te]=De}return v}function pe(v,...S){return Ne(v,...S,h)}var ke={min:{r:0,g:0,b:0,s:0,l:0,a:0},max:{r:255,g:255,b:255,h:360,s:100,l:100,a:1},clamp:{r:v=>v>=255?255:v<0?0:v,g:v=>v>=255?255:v<0?0:v,b:v=>v>=255?255:v<0?0:v,h:v=>v%360,s:v=>v>=100?100:v<0?0:v,l:v=>v>=100?100:v<0?0:v,a:v=>v>=1?1:v<0?0:v},toLinear:v=>{let S=v/255;return v>.03928?Math.pow((S+.055)/1.055,2.4):S/12.92},hue2rgb:(v,S,I)=>{if(I<0)I+=1;if(I>1)I-=1;if(I<.16666666666666666)return v+(S-v)*6*I;if(I<.5)return S;if(I<.6666666666666666)return v+(S-v)*(.6666666666666666-I)*6;return v},hsl2rgb:({h:v,s:S,l:I},W)=>{if(!S)return I*2.55;v/=360,S/=100,I/=100;let ye=I<.5?I*(1+S):I+S-I*S,te=2*I-ye;switch(W){case"r":return ke.hue2rgb(te,ye,v+.3333333333333333)*255;case"g":return ke.hue2rgb(te,ye,v)*255;case"b":return ke.hue2rgb(te,ye,v-.3333333333333333)*255}},rgb2hsl:({r:v,g:S,b:I},W)=>{v/=255,S/=255,I/=255;let ye=Math.max(v,S,I),te=Math.min(v,S,I),Te=(ye+te)/2;if(W==="l")return Te*100;if(ye===te)return 0;let De=ye-te,tt=Te>.5?De/(2-ye-te):De/(ye+te);if(W==="s")return tt*100;switch(ye){case v:return((S-I)/De+(S<I?6:0))*60;case S:return((I-v)/De+2)*60;case I:return((v-S)/De+4)*60;default:return-1}}},Ee=ke;var _e={clamp:(v,S,I)=>{if(S>I)return Math.min(S,Math.max(I,v));return Math.min(I,Math.max(S,v))},round:v=>Math.round(v*1e10)/1e10},qe=_e;var Ze={dec2hex:v=>{let S=Math.round(v).toString(16);return S.length>1?S:`0${S}`}},rt=Ze;var z={channel:Ee,lang:qe,unit:rt},F=z;var Z={};for(let v=0;v<=255;v++){e();Z[v]=F.unit.dec2hex(v)}var ue={ALL:0,RGB:1,HSL:2};class be{constructor(){this.type=ue.ALL}get(){return this.type}set(S){if(this.type&&this.type!==S)throw Error("Cannot change both RGB and HSL channels at the same time");this.type=S}reset(){this.type=ue.ALL}is(S){return this.type===S}}var Ce=be;class Le{constructor(S,I){this.color=I,this.changed=false,this.data=S,this.type=new Ce}set(S,I){return this.color=I,this.changed=false,this.data=S,this.type.type=ue.ALL,this}_ensureHSL(){let S=this.data,{h:I,s:W,l:ye}=S;if(I===void 0)S.h=F.channel.rgb2hsl(S,"h");if(W===void 0)S.s=F.channel.rgb2hsl(S,"s");if(ye===void 0)S.l=F.channel.rgb2hsl(S,"l")}_ensureRGB(){let S=this.data,{r:I,g:W,b:ye}=S;if(I===void 0)S.r=F.channel.hsl2rgb(S,"r");if(W===void 0)S.g=F.channel.hsl2rgb(S,"g");if(ye===void 0)S.b=F.channel.hsl2rgb(S,"b")}get r(){let S=this.data,I=S.r;if(!this.type.is(ue.HSL)&&I!==void 0)return I;return this._ensureHSL(),F.channel.hsl2rgb(S,"r")}get g(){let S=this.data,I=S.g;if(!this.type.is(ue.HSL)&&I!==void 0)return I;return this._ensureHSL(),F.channel.hsl2rgb(S,"g")}get b(){let S=this.data,I=S.b;if(!this.type.is(ue.HSL)&&I!==void 0)return I;return this._ensureHSL(),F.channel.hsl2rgb(S,"b")}get h(){let S=this.data,I=S.h;if(!this.type.is(ue.RGB)&&I!==void 0)return I;return this._ensureRGB(),F.channel.rgb2hsl(S,"h")}get s(){let S=this.data,I=S.s;if(!this.type.is(ue.RGB)&&I!==void 0)return I;return this._ensureRGB(),F.channel.rgb2hsl(S,"s")}get l(){let S=this.data,I=S.l;if(!this.type.is(ue.RGB)&&I!==void 0)return I;return this._ensureRGB(),F.channel.rgb2hsl(S,"l")}get a(){return this.data.a}set r(S){this.type.set(ue.RGB),this.changed=true,this.data.r=S}set g(S){this.type.set(ue.RGB),this.changed=true,this.data.g=S}set b(S){this.type.set(ue.RGB),this.changed=true,this.data.b=S}set h(S){this.type.set(ue.HSL),this.changed=true,this.data.h=S}set s(S){this.type.set(ue.HSL),this.changed=true,this.data.s=S}set l(S){this.type.set(ue.HSL),this.changed=true,this.data.l=S}set a(S){this.changed=true,this.data.a=S}}var Qe=Le;var lt=new Qe({r:0,g:0,b:0,a:0},"transparent"),et=lt;var xt={re:/^#((?:[a-f0-9]{2}){2,4}|[a-f0-9]{3})$/i,parse:v=>{if(v.charCodeAt(0)!==35)return;let S=v.match(xt.re);if(!S)return;let I=S[1],W=parseInt(I,16),ye=I.length,te=ye%4===0,Te=ye>4,De=Te?1:17,tt=Te?8:4,pr=te?0:-1,Ht=Te?255:15;return et.set({r:(W>>tt*(pr+3)&Ht)*De,g:(W>>tt*(pr+2)&Ht)*De,b:(W>>tt*(pr+1)&Ht)*De,a:te?(W&Ht)*De/255:1},v)},stringify:v=>{let{r:S,g:I,b:W,a:ye}=v;if(ye<1)return`#${Z[Math.round(S)]}${Z[Math.round(I)]}${Z[Math.round(W)]}${Z[Math.round(ye*255)]}`;else return`#${Z[Math.round(S)]}${Z[Math.round(I)]}${Z[Math.round(W)]}`}},ft=xt;var Je={re:/^hsla?\(\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e-?\d+)?(?:deg|grad|rad|turn)?)\s*?(?:,|\s)\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e-?\d+)?%)\s*?(?:,|\s)\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e-?\d+)?%)(?:\s*?(?:,|\/)\s*?\+?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e-?\d+)?(%)?))?\s*?\)$/i,hueRe:/^(.+?)(deg|grad|rad|turn)$/i,_hue2deg:v=>{let S=v.match(Je.hueRe);if(S){let[,I,W]=S;switch(W){case"grad":return F.channel.clamp.h(parseFloat(I)*.9);case"rad":return F.channel.clamp.h(parseFloat(I)*180/Math.PI);case"turn":return F.channel.clamp.h(parseFloat(I)*360)}}return F.channel.clamp.h(parseFloat(v))},parse:v=>{let S=v.charCodeAt(0);if(S!==104&&S!==72)return;let I=v.match(Je.re);if(!I)return;let[,W,ye,te,Te,De]=I;return et.set({h:Je._hue2deg(W),s:F.channel.clamp.s(parseFloat(ye)),l:F.channel.clamp.l(parseFloat(te)),a:Te?F.channel.clamp.a(De?parseFloat(Te)/100:parseFloat(Te)):1},v)},stringify:v=>{let{h:S,s:I,l:W,a:ye}=v;if(ye<1)return`hsla(${F.lang.round(S)}, ${F.lang.round(I)}%, ${F.lang.round(W)}%, ${ye})`;else return`hsl(${F.lang.round(S)}, ${F.lang.round(I)}%, ${F.lang.round(W)}%)`}},At=Je;var H={colors:{aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyanaqua:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",transparent:"#00000000",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"},parse:v=>{v=v.toLowerCase();let S=H.colors[v];if(!S)return;return ft.parse(S)},stringify:v=>{let S=ft.stringify(v);for(let I in H.colors){e();if(H.colors[I]===S)return I}return}},Se=H;var Xe={re:/^rgba?\(\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e\d+)?(%?))\s*?(?:,|\s)\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e\d+)?(%?))\s*?(?:,|\s)\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e\d+)?(%?))(?:\s*?(?:,|\/)\s*?\+?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e\d+)?(%?)))?\s*?\)$/i,parse:v=>{let S=v.charCodeAt(0);if(S!==114&&S!==82)return;let I=v.match(Xe.re);if(!I)return;let[,W,ye,te,Te,De,tt,pr,Ht]=I;return et.set({r:F.channel.clamp.r(ye?parseFloat(W)*2.55:parseFloat(W)),g:F.channel.clamp.g(Te?parseFloat(te)*2.55:parseFloat(te)),b:F.channel.clamp.b(tt?parseFloat(De)*2.55:parseFloat(De)),a:pr?F.channel.clamp.a(Ht?parseFloat(pr)/100:parseFloat(pr)):1},v)},stringify:v=>{let{r:S,g:I,b:W,a:ye}=v;if(ye<1)return`rgba(${F.lang.round(S)}, ${F.lang.round(I)}, ${F.lang.round(W)}, ${F.lang.round(ye)})`;else return`rgb(${F.lang.round(S)}, ${F.lang.round(I)}, ${F.lang.round(W)})`}},ze=Xe;var nt={format:{keyword:Se,hex:ft,rgb:ze,rgba:ze,hsl:At,hsla:At},parse:v=>{if(typeof v!=="string")return v;let S=ft.parse(v)||ze.parse(v)||At.parse(v)||Se.parse(v);if(S)return S;throw Error(`Unsupported color format: "${v}"`)},stringify:v=>{if(!v.changed&&v.color)return v.color;if(v.type.is(ue.HSL)||v.data.r===void 0)return At.stringify(v);else if(v.a<1||!Number.isInteger(v.r)||!Number.isInteger(v.g)||!Number.isInteger(v.b))return ze.stringify(v);else return ft.stringify(v)}},pt=nt;var Yt=(v,S)=>{let I=pt.parse(v);for(let W in S){e();I[W]=F.channel.clamp[W](S[W])}return pt.stringify(I)},sr=Yt;var Ji=(v,S,I=0,W=1)=>{if(typeof v!=="number")return sr(v,{a:S});let ye=et.set({r:F.channel.clamp.r(v),g:F.channel.clamp.g(S),b:F.channel.clamp.b(I),a:F.channel.clamp.a(W)});return pt.stringify(ye)},fr=Ji;var Ss=v=>{let{r:S,g:I,b:W}=pt.parse(v),ye=.2126*F.channel.toLinear(S)+.7152*F.channel.toLinear(I)+.0722*F.channel.toLinear(W);return F.lang.round(ye)},rl=Ss;var il=v=>rl(v)>=.5,fu=il;var AA=v=>!fu(v),tr=AA;var OA=(v,S,I)=>{let W=pt.parse(v),ye=W[S],te=F.channel.clamp[S](ye+I);if(ye!==te)W[S]=te;return pt.stringify(W)},Up=OA;var BA=(v,S)=>Up(v,"l",S),he=BA;var _A=(v,S)=>Up(v,"l",-S),me=_A;var IA=(v,S)=>{let I=pt.parse(v),W={};for(let ye in S){e();if(!S[ye])continue;W[ye]=I[ye]+S[ye]}return sr(v,W)},R=IA;var LA=(v,S,I=50)=>{let{r:W,g:ye,b:te,a:Te}=pt.parse(v),{r:De,g:tt,b:pr,a:Ht}=pt.parse(S),Er=I/100,Qi=Er*2-1,ho=Te-Ht,sl=((Qi*ho===-1?Qi:(Qi+ho)/(1+Qi*ho))+1)/2,Cu=1-sl,vO=W*sl+De*Cu,EO=ye*sl+tt*Cu,MO=te*sl+pr*Cu,AO=Te*Er+Ht*(1-Er);return fr(vO,EO,MO,AO)},RA=LA;var DA=(v,S=100)=>{let I=pt.parse(v);return I.r=255-I.r,I.g=255-I.g,I.b=255-I.b,RA(I,v,S)},oe=DA;var Zr="#ffffff",ei="#f2f2f2";var Ue=(v,S)=>S?R(v,{s:-40,l:10}):R(v,{s:-40,l:-10}),jp=v=>typeof v==="object"&&v!==null&&!Array.isArray(v),vr=(v,S)=>jp(v)&&jp(S)?{...v,...S}:S;class NA{constructor(){this.background="#f4f4f4",this.primaryColor="#fff4dd",this.noteBkgColor="#fff5ad",this.noteTextColor="#333",this.THEME_COLOR_LIMIT=12,this.radius=5,this.strokeWidth=1,this.fontFamily='"trebuchet ms", verdana, arial, sans-serif',this.fontSize="16px",this.useGradient=true,this.dropShadow="drop-shadow( 1px 2px 2px rgba(185,185,185,1))"}updateColors(){if(this.primaryTextColor=this.primaryTextColor||(this.darkMode?"#eee":"#333"),this.secondaryColor=this.secondaryColor||R(this.primaryColor,{h:-120}),this.tertiaryColor=this.tertiaryColor||R(this.primaryColor,{h:180,l:5}),this.primaryBorderColor=this.primaryBorderColor||Ue(this.primaryColor,this.darkMode),this.secondaryBorderColor=this.secondaryBorderColor||Ue(this.secondaryColor,this.darkMode),this.tertiaryBorderColor=this.tertiaryBorderColor||Ue(this.tertiaryColor,this.darkMode),this.noteBorderColor=this.noteBorderColor||Ue(this.noteBkgColor,this.darkMode),this.noteBkgColor=this.noteBkgColor||"#fff5ad",this.noteTextColor=this.noteTextColor||"#333",this.secondaryTextColor=this.secondaryTextColor||oe(this.secondaryColor),this.tertiaryTextColor=this.tertiaryTextColor||oe(this.tertiaryColor),this.lineColor=this.lineColor||oe(this.background),this.arrowheadColor=this.arrowheadColor||oe(this.background),this.textColor=this.textColor||this.primaryTextColor,this.border2=this.border2||this.tertiaryBorderColor,this.nodeBkg=this.nodeBkg||this.primaryColor,this.mainBkg=this.mainBkg||this.primaryColor,this.nodeBorder=this.nodeBorder||this.primaryBorderColor,this.clusterBkg=this.clusterBkg||this.tertiaryColor,this.clusterBorder=this.clusterBorder||this.tertiaryBorderColor,this.defaultLinkColor=this.defaultLinkColor||this.lineColor,this.titleColor=this.titleColor||this.tertiaryTextColor,this.edgeLabelBackground=this.edgeLabelBackground||(this.darkMode?me(this.secondaryColor,30):this.secondaryColor),this.flowContainerStroke=this.flowContainerStroke||this.secondaryBorderColor,this.nodeTextColor=this.nodeTextColor||this.primaryTextColor,this.actorBorder=this.actorBorder||this.primaryBorderColor,this.actorBkg=this.actorBkg||this.mainBkg,this.actorTextColor=this.actorTextColor||this.primaryTextColor,this.actorLineColor=this.actorLineColor||this.actorBorder,this.labelBoxBkgColor=this.labelBoxBkgColor||this.actorBkg,this.signalColor=this.signalColor||this.textColor,this.signalTextColor=this.signalTextColor||this.textColor,this.labelBoxBorderColor=this.labelBoxBorderColor||this.actorBorder,this.labelTextColor=this.labelTextColor||this.actorTextColor,this.loopTextColor=this.loopTextColor||this.actorTextColor,this.activationBorderColor=this.activationBorderColor||me(this.secondaryColor,10),this.activationBkgColor=this.activationBkgColor||this.secondaryColor,this.sequenceNumberColor=this.sequenceNumberColor||oe(this.lineColor),this.rectBkgColor=this.rectBkgColor||this.tertiaryColor,this.sectionBkgColor=this.sectionBkgColor||this.tertiaryColor,this.altSectionBkgColor=this.altSectionBkgColor||"white",this.sectionBkgColor=this.sectionBkgColor||this.secondaryColor,this.sectionBkgColor2=this.sectionBkgColor2||this.primaryColor,this.excludeBkgColor=this.excludeBkgColor||"#eeeeee",this.taskBorderColor=this.taskBorderColor||this.primaryBorderColor,this.taskBkgColor=this.taskBkgColor||this.primaryColor,this.activeTaskBorderColor=this.activeTaskBorderColor||this.primaryColor,this.activeTaskBkgColor=this.activeTaskBkgColor||he(this.primaryColor,23),this.gridColor=this.gridColor||"lightgrey",this.doneTaskBkgColor=this.doneTaskBkgColor||"lightgrey",this.doneTaskBorderColor=this.doneTaskBorderColor||"grey",this.critBorderColor=this.critBorderColor||"#ff8888",this.critBkgColor=this.critBkgColor||"red",this.todayLineColor=this.todayLineColor||"red",this.vertLineColor=this.vertLineColor||"navy",this.taskTextColor=this.taskTextColor||this.textColor,this.taskTextOutsideColor=this.taskTextOutsideColor||this.textColor,this.taskTextLightColor=this.taskTextLightColor||this.textColor,this.taskTextColor=this.taskTextColor||this.primaryTextColor,this.taskTextDarkColor=this.taskTextDarkColor||this.textColor,this.taskTextClickableColor=this.taskTextClickableColor||"#003163",this.noteFontWeight=this.noteFontWeight||"normal",this.fontWeight=this.fontWeight||"normal",this.personBorder=this.personBorder||this.primaryBorderColor,this.personBkg=this.personBkg||this.mainBkg,this.darkMode)this.rowOdd=this.rowOdd||me(this.mainBkg,5)||"#ffffff",this.rowEven=this.rowEven||me(this.mainBkg,10);else this.rowOdd=this.rowOdd||he(this.mainBkg,75)||"#ffffff",this.rowEven=this.rowEven||he(this.mainBkg,5);if(this.transitionColor=this.transitionColor||this.lineColor,this.transitionLabelColor=this.transitionLabelColor||this.textColor,this.stateLabelColor=this.stateLabelColor||this.stateBkg||this.primaryTextColor,this.stateBkg=this.stateBkg||this.mainBkg,this.labelBackgroundColor=this.labelBackgroundColor||this.stateBkg,this.compositeBackground=this.compositeBackground||this.background||this.tertiaryColor,this.altBackground=this.altBackground||this.tertiaryColor,this.compositeTitleBackground=this.compositeTitleBackground||this.mainBkg,this.compositeBorder=this.compositeBorder||this.nodeBorder,this.innerEndBackground=this.nodeBorder,this.errorBkgColor=this.errorBkgColor||this.tertiaryColor,this.errorTextColor=this.errorTextColor||this.tertiaryTextColor,this.transitionColor=this.transitionColor||this.lineColor,this.specialStateColor=this.lineColor,this.cScale0=this.cScale0||this.primaryColor,this.cScale1=this.cScale1||this.secondaryColor,this.cScale2=this.cScale2||this.tertiaryColor,this.cScale3=this.cScale3||R(this.primaryColor,{h:30}),this.cScale4=this.cScale4||R(this.primaryColor,{h:60}),this.cScale5=this.cScale5||R(this.primaryColor,{h:90}),this.cScale6=this.cScale6||R(this.primaryColor,{h:120}),this.cScale7=this.cScale7||R(this.primaryColor,{h:150}),this.cScale8=this.cScale8||R(this.primaryColor,{h:210,l:150}),this.cScale9=this.cScale9||R(this.primaryColor,{h:270}),this.cScale10=this.cScale10||R(this.primaryColor,{h:300}),this.cScale11=this.cScale11||R(this.primaryColor,{h:330}),this.darkMode)for(let I=0;I<this.THEME_COLOR_LIMIT;I++){e();this["cScale"+I]=me(this["cScale"+I],75)}else for(let I=0;I<this.THEME_COLOR_LIMIT;I++){e();this["cScale"+I]=me(this["cScale"+I],25)}for(let I=0;I<this.THEME_COLOR_LIMIT;I++){e();this["cScaleInv"+I]=this["cScaleInv"+I]||oe(this["cScale"+I])}for(let I=0;I<this.THEME_COLOR_LIMIT;I++){e();if(this.darkMode)this["cScalePeer"+I]=this["cScalePeer"+I]||he(this["cScale"+I],10);else this["cScalePeer"+I]=this["cScalePeer"+I]||me(this["cScale"+I],10)}this.scaleLabelColor=this.scaleLabelColor||this.labelTextColor;for(let I=0;I<this.THEME_COLOR_LIMIT;I++){e();this["cScaleLabel"+I]=this["cScaleLabel"+I]||this.scaleLabelColor}let S=this.darkMode?-4:-1;for(let I=0;I<5;I++){e();this["surface"+I]=this["surface"+I]||R(this.mainBkg,{h:180,s:-15,l:S*(5+I*3)}),this["surfacePeer"+I]=this["surfacePeer"+I]||R(this.mainBkg,{h:180,s:-15,l:S*(8+I*3)})}if(this.classText=this.classText||this.textColor,this.fillType0=this.fillType0||this.primaryColor,this.fillType1=this.fillType1||this.secondaryColor,this.fillType2=this.fillType2||R(this.primaryColor,{h:64}),this.fillType3=this.fillType3||R(this.secondaryColor,{h:64}),this.fillType4=this.fillType4||R(this.primaryColor,{h:-64}),this.fillType5=this.fillType5||R(this.secondaryColor,{h:-64}),this.fillType6=this.fillType6||R(this.primaryColor,{h:128}),this.fillType7=this.fillType7||R(this.secondaryColor,{h:128}),this.pie1=this.pie1||this.primaryColor,this.pie2=this.pie2||this.secondaryColor,this.pie3=this.pie3||this.tertiaryColor,this.pie4=this.pie4||R(this.primaryColor,{l:-10}),this.pie5=this.pie5||R(this.secondaryColor,{l:-10}),this.pie6=this.pie6||R(this.tertiaryColor,{l:-10}),this.pie7=this.pie7||R(this.primaryColor,{h:60,l:-10}),this.pie8=this.pie8||R(this.primaryColor,{h:-60,l:-10}),this.pie9=this.pie9||R(this.primaryColor,{h:120,l:0}),this.pie10=this.pie10||R(this.primaryColor,{h:60,l:-20}),this.pie11=this.pie11||R(this.primaryColor,{h:-60,l:-20}),this.pie12=this.pie12||R(this.primaryColor,{h:120,l:-10}),this.pieTitleTextSize=this.pieTitleTextSize||"25px",this.pieTitleTextColor=this.pieTitleTextColor||this.taskTextDarkColor,this.pieSectionTextSize=this.pieSectionTextSize||"17px",this.pieSectionTextColor=this.pieSectionTextColor||this.textColor,this.pieLegendTextSize=this.pieLegendTextSize||"17px",this.pieLegendTextColor=this.pieLegendTextColor||this.taskTextDarkColor,this.pieStrokeColor=this.pieStrokeColor||"black",this.pieStrokeWidth=this.pieStrokeWidth||"2px",this.pieOuterStrokeWidth=this.pieOuterStrokeWidth||"2px",this.pieOuterStrokeColor=this.pieOuterStrokeColor||"black",this.pieOpacity=this.pieOpacity||"0.7",this.venn1=this.venn1??R(this.primaryColor,{l:-30}),this.venn2=this.venn2??R(this.secondaryColor,{l:-30}),this.venn3=this.venn3??R(this.tertiaryColor,{l:-30}),this.venn4=this.venn4??R(this.primaryColor,{h:60,l:-30}),this.venn5=this.venn5??R(this.primaryColor,{h:-60,l:-30}),this.venn6=this.venn6??R(this.secondaryColor,{h:60,l:-30}),this.venn7=this.venn7??R(this.primaryColor,{h:120,l:-30}),this.venn8=this.venn8??R(this.secondaryColor,{h:120,l:-30}),this.vennTitleTextColor=this.vennTitleTextColor??this.titleColor,this.vennSetTextColor=this.vennSetTextColor??this.textColor,this.cynefin={domainFontSize:this.cynefin?.domainFontSize||16,itemFontSize:this.cynefin?.itemFontSize||12,boundaryColor:this.cynefin?.boundaryColor||this.lineColor,boundaryWidth:this.cynefin?.boundaryWidth||2,cliffColor:this.cynefin?.cliffColor||"#8B0000",cliffWidth:this.cynefin?.cliffWidth||4,arrowColor:this.cynefin?.arrowColor||this.lineColor,arrowWidth:this.cynefin?.arrowWidth||2,complexBg:this.cynefin?.complexBg||"#E8F5E9",complicatedBg:this.cynefin?.complicatedBg||"#E3F2FD",chaoticBg:this.cynefin?.chaoticBg||"#FBE9E7",clearBg:this.cynefin?.clearBg||"#FFF8E1",confusionBg:this.cynefin?.confusionBg||"#F3E5F5",textColor:this.cynefin?.textColor||this.textColor,labelColor:this.cynefin?.labelColor||this.primaryTextColor},this.radar={axisColor:this.radar?.axisColor||this.lineColor,axisStrokeWidth:this.radar?.axisStrokeWidth||2,axisLabelFontSize:this.radar?.axisLabelFontSize||12,curveOpacity:this.radar?.curveOpacity||.5,curveStrokeWidth:this.radar?.curveStrokeWidth||2,graticuleColor:this.radar?.graticuleColor||"#DEDEDE",graticuleStrokeWidth:this.radar?.graticuleStrokeWidth||1,graticuleOpacity:this.radar?.graticuleOpacity||.3,legendBoxSize:this.radar?.legendBoxSize||12,legendFontSize:this.radar?.legendFontSize||12},this.wardleyEvolutionColor=this.wardleyEvolutionColor||"#dc3545",this.wardley={backgroundColor:this.wardley?.backgroundColor||this.background,axisColor:this.wardley?.axisColor||this.lineColor,axisTextColor:this.wardley?.axisTextColor||this.primaryTextColor,gridColor:this.wardley?.gridColor||this.gridColor,componentFill:this.wardley?.componentFill||this.background,componentStroke:this.wardley?.componentStroke||this.lineColor,componentLabelColor:this.wardley?.componentLabelColor||this.primaryTextColor,linkStroke:this.wardley?.linkStroke||this.lineColor,evolutionStroke:this.wardley?.evolutionStroke||this.wardleyEvolutionColor,annotationStroke:this.wardley?.annotationStroke||this.lineColor,annotationTextColor:this.wardley?.annotationTextColor||this.primaryTextColor,annotationFill:this.wardley?.annotationFill||this.background},this.archEdgeColor=this.archEdgeColor||"#777",this.archEdgeArrowColor=this.archEdgeArrowColor||"#777",this.archEdgeWidth=this.archEdgeWidth||"3",this.archGroupBorderColor=this.archGroupBorderColor||"#000",this.archGroupBorderWidth=this.archGroupBorderWidth||"2px",this.quadrant1Fill=this.quadrant1Fill||this.primaryColor,this.quadrant2Fill=this.quadrant2Fill||R(this.primaryColor,{r:5,g:5,b:5}),this.quadrant3Fill=this.quadrant3Fill||R(this.primaryColor,{r:10,g:10,b:10}),this.quadrant4Fill=this.quadrant4Fill||R(this.primaryColor,{r:15,g:15,b:15}),this.quadrant1TextFill=this.quadrant1TextFill||this.primaryTextColor,this.quadrant2TextFill=this.quadrant2TextFill||R(this.primaryTextColor,{r:-5,g:-5,b:-5}),this.quadrant3TextFill=this.quadrant3TextFill||R(this.primaryTextColor,{r:-10,g:-10,b:-10}),this.quadrant4TextFill=this.quadrant4TextFill||R(this.primaryTextColor,{r:-15,g:-15,b:-15}),this.quadrantPointFill=this.quadrantPointFill||tr(this.quadrant1Fill)?he(this.quadrant1Fill):me(this.quadrant1Fill),this.quadrantPointTextFill=this.quadrantPointTextFill||this.primaryTextColor,this.quadrantXAxisTextFill=this.quadrantXAxisTextFill||this.primaryTextColor,this.quadrantYAxisTextFill=this.quadrantYAxisTextFill||this.primaryTextColor,this.quadrantInternalBorderStrokeFill=this.quadrantInternalBorderStrokeFill||this.primaryBorderColor,this.quadrantExternalBorderStrokeFill=this.quadrantExternalBorderStrokeFill||this.primaryBorderColor,this.quadrantTitleFill=this.quadrantTitleFill||this.primaryTextColor,this.xyChart={backgroundColor:this.xyChart?.backgroundColor||this.background,titleColor:this.xyChart?.titleColor||this.primaryTextColor,dataLabelColor:this.xyChart?.dataLabelColor||this.primaryTextColor,legendTextColor:this.xyChart?.legendTextColor||this.primaryTextColor,xAxisTitleColor:this.xyChart?.xAxisTitleColor||this.primaryTextColor,xAxisLabelColor:this.xyChart?.xAxisLabelColor||this.primaryTextColor,xAxisTickColor:this.xyChart?.xAxisTickColor||this.primaryTextColor,xAxisLineColor:this.xyChart?.xAxisLineColor||this.primaryTextColor,yAxisTitleColor:this.xyChart?.yAxisTitleColor||this.primaryTextColor,yAxisLabelColor:this.xyChart?.yAxisLabelColor||this.primaryTextColor,yAxisTickColor:this.xyChart?.yAxisTickColor||this.primaryTextColor,yAxisLineColor:this.xyChart?.yAxisLineColor||this.primaryTextColor,plotColorPalette:this.xyChart?.plotColorPalette||"#FFF4DD,#FFD8B1,#FFA07A,#ECEFF1,#D6DBDF,#C3E0A8,#FFB6A4,#FFD74D,#738FA7,#FFFFF0"},this.requirementBackground=this.requirementBackground||this.primaryColor,this.requirementBorderColor=this.requirementBorderColor||this.primaryBorderColor,this.requirementBorderSize=this.requirementBorderSize||"1",this.requirementTextColor=this.requirementTextColor||this.primaryTextColor,this.relationColor=this.relationColor||this.lineColor,this.relationLabelBackground=this.relationLabelBackground||(this.darkMode?me(this.secondaryColor,30):this.secondaryColor),this.relationLabelColor=this.relationLabelColor||this.actorTextColor,this.git0=this.git0||this.primaryColor,this.git1=this.git1||this.secondaryColor,this.git2=this.git2||this.tertiaryColor,this.git3=this.git3||R(this.primaryColor,{h:-30}),this.git4=this.git4||R(this.primaryColor,{h:-60}),this.git5=this.git5||R(this.primaryColor,{h:-90}),this.git6=this.git6||R(this.primaryColor,{h:60}),this.git7=this.git7||R(this.primaryColor,{h:120}),this.darkMode)this.git0=he(this.git0,25),this.git1=he(this.git1,25),this.git2=he(this.git2,25),this.git3=he(this.git3,25),this.git4=he(this.git4,25),this.git5=he(this.git5,25),this.git6=he(this.git6,25),this.git7=he(this.git7,25);else this.git0=me(this.git0,25),this.git1=me(this.git1,25),this.git2=me(this.git2,25),this.git3=me(this.git3,25),this.git4=me(this.git4,25),this.git5=me(this.git5,25),this.git6=me(this.git6,25),this.git7=me(this.git7,25);this.gitInv0=this.gitInv0||oe(this.git0),this.gitInv1=this.gitInv1||oe(this.git1),this.gitInv2=this.gitInv2||oe(this.git2),this.gitInv3=this.gitInv3||oe(this.git3),this.gitInv4=this.gitInv4||oe(this.git4),this.gitInv5=this.gitInv5||oe(this.git5),this.gitInv6=this.gitInv6||oe(this.git6),this.gitInv7=this.gitInv7||oe(this.git7),this.branchLabelColor=this.branchLabelColor||(this.darkMode?"black":this.labelTextColor),this.gitBranchLabel0=this.gitBranchLabel0||this.branchLabelColor,this.gitBranchLabel1=this.gitBranchLabel1||this.branchLabelColor,this.gitBranchLabel2=this.gitBranchLabel2||this.branchLabelColor,this.gitBranchLabel3=this.gitBranchLabel3||this.branchLabelColor,this.gitBranchLabel4=this.gitBranchLabel4||this.branchLabelColor,this.gitBranchLabel5=this.gitBranchLabel5||this.branchLabelColor,this.gitBranchLabel6=this.gitBranchLabel6||this.branchLabelColor,this.gitBranchLabel7=this.gitBranchLabel7||this.branchLabelColor,this.tagLabelColor=this.tagLabelColor||this.primaryTextColor,this.tagLabelBackground=this.tagLabelBackground||this.primaryColor,this.tagLabelBorder=this.tagBorder||this.primaryBorderColor,this.tagLabelFontSize=this.tagLabelFontSize||"10px",this.commitLabelColor=this.commitLabelColor||this.secondaryTextColor,this.commitLabelBackground=this.commitLabelBackground||this.secondaryColor,this.commitLabelFontSize=this.commitLabelFontSize||"10px",this.emUiFill=this.emUiFill||"white",this.emUiStroke=this.emUiStroke||"#dbdada",this.emProcessorFill=this.emProcessorFill||"#edb3f6",this.emProcessorStroke=this.emProcessorStroke||"#b88cbf",this.emReadModelFill=this.emReadModelFill||"#d3f1a2",this.emReadModelStroke=this.emReadModelStroke||"#a3b732",this.emCommandFill=this.emCommandFill||"#bcd6fe",this.emCommandStroke=this.emCommandStroke||"#679ac3",this.emEventFill=this.emEventFill||"#ffb778",this.emEventStroke=this.emEventStroke||"#c19a0f",this.emSwimlaneBackgroundOdd=this.emSwimlaneBackgroundOdd||"rgb(250,250,250)",this.emSwimlaneBackgroundStroke=this.emSwimlaneBackgroundStroke||"rgb(240,240,240)",this.emArrowhead=this.emArrowhead||this.lineColor,this.emRelationStroke=this.emRelationStroke||this.lineColor,this.attributeBackgroundColorOdd=this.attributeBackgroundColorOdd||Zr,this.attributeBackgroundColorEven=this.attributeBackgroundColorEven||ei,this.gradientStart=this.primaryBorderColor,this.gradientStop=this.secondaryBorderColor}calculate(S){if(typeof S!=="object"){this.updateColors();return}let I=Object.keys(S);if(I.forEach(W=>{this[W]=S[W]}),this.updateColors(),I.forEach(W=>{this[W]=vr(this[W],S[W])}),Object.hasOwn(S,"nodeBorder")&&!Object.hasOwn(S,"useGradient"))this.useGradient=false}}var PA=v=>{let S=new NA;return S.calculate(v),S};class FA{constructor(){this.background="#333",this.primaryColor="#1f2020",this.secondaryColor=he(this.primaryColor,16),this.tertiaryColor=R(this.primaryColor,{h:-160}),this.primaryBorderColor=oe(this.background),this.secondaryBorderColor=Ue(this.secondaryColor,this.darkMode),this.tertiaryBorderColor=Ue(this.tertiaryColor,this.darkMode),this.primaryTextColor=oe(this.primaryColor),this.secondaryTextColor=oe(this.secondaryColor),this.tertiaryTextColor=oe(this.tertiaryColor),this.lineColor=oe(this.background),this.textColor=oe(this.background),this.mainBkg="#1f2020",this.secondBkg="calculated",this.mainContrastColor="lightgrey",this.darkTextColor=he(oe("#323D47"),10),this.lineColor="calculated",this.border1="#ccc",this.border2=fr(255,255,255,.25),this.arrowheadColor="calculated",this.fontFamily='"trebuchet ms", verdana, arial, sans-serif',this.fontSize="16px",this.labelBackground="#181818",this.textColor="#ccc",this.THEME_COLOR_LIMIT=12,this.radius=5,this.strokeWidth=1,this.nodeBkg="calculated",this.nodeBorder="calculated",this.clusterBkg="calculated",this.clusterBorder="calculated",this.defaultLinkColor="calculated",this.titleColor="#F9FFFE",this.edgeLabelBackground="calculated",this.actorBorder="calculated",this.actorBkg="calculated",this.actorTextColor="calculated",this.actorLineColor="calculated",this.signalColor="calculated",this.signalTextColor="calculated",this.labelBoxBkgColor="calculated",this.labelBoxBorderColor="calculated",this.labelTextColor="calculated",this.loopTextColor="calculated",this.noteBorderColor="calculated",this.noteBkgColor="#fff5ad",this.noteTextColor="calculated",this.activationBorderColor="calculated",this.activationBkgColor="calculated",this.sequenceNumberColor="black",this.clusterBkg="#302F3D",this.sectionBkgColor=me("#EAE8D9",30),this.altSectionBkgColor="calculated",this.sectionBkgColor2="#EAE8D9",this.excludeBkgColor=me(this.sectionBkgColor,10),this.taskBorderColor=fr(255,255,255,70),this.taskBkgColor="calculated",this.taskTextColor="calculated",this.taskTextLightColor="calculated",this.taskTextOutsideColor="calculated",this.taskTextClickableColor="#003163",this.activeTaskBorderColor=fr(255,255,255,50),this.activeTaskBkgColor="#81B1DB",this.gridColor="calculated",this.doneTaskBkgColor="calculated",this.doneTaskBorderColor="grey",this.critBorderColor="#E83737",this.critBkgColor="#E83737",this.taskTextDarkColor="calculated",this.todayLineColor="#DB5757",this.vertLineColor="#00BFFF",this.personBorder=this.primaryBorderColor,this.personBkg=this.mainBkg,this.archEdgeColor="calculated",this.archEdgeArrowColor="calculated",this.archEdgeWidth="3",this.archGroupBorderColor=this.primaryBorderColor,this.archGroupBorderWidth="2px",this.rowOdd=this.rowOdd||he(this.mainBkg,5)||"#ffffff",this.rowEven=this.rowEven||me(this.mainBkg,10),this.labelColor="calculated",this.errorBkgColor="#a44141",this.errorTextColor="#ddd",this.useGradient=true,this.gradientStart=this.primaryBorderColor,this.gradientStop=this.secondaryBorderColor,this.dropShadow="drop-shadow( 1px 2px 2px rgba(185,185,185,1))",this.noteFontWeight=this.noteFontWeight||"normal",this.fontWeight=this.fontWeight||"normal"}updateColors(){this.secondBkg=he(this.mainBkg,16),this.lineColor=this.mainContrastColor,this.arrowheadColor=this.mainContrastColor,this.nodeBkg=this.mainBkg,this.nodeBorder=this.border1,this.clusterBkg=this.secondBkg,this.clusterBorder=this.border2,this.defaultLinkColor=this.lineColor,this.edgeLabelBackground=he(this.labelBackground,25),this.flowContainerStroke=this.flowContainerStroke||this.secondaryBorderColor,this.actorBorder=this.border1,this.actorBkg=this.mainBkg,this.actorTextColor=this.mainContrastColor,this.actorLineColor=this.actorBorder,this.signalColor=this.mainContrastColor,this.signalTextColor=this.mainContrastColor,this.labelBoxBkgColor=this.actorBkg,this.labelBoxBorderColor=this.actorBorder,this.labelTextColor=this.mainContrastColor,this.loopTextColor=this.mainContrastColor,this.noteBorderColor=this.secondaryBorderColor,this.noteBkgColor=this.secondBkg,this.noteTextColor=this.secondaryTextColor,this.activationBorderColor=this.border1,this.activationBkgColor=this.secondBkg,this.rectBkgColor=this.rectBkgColor||this.tertiaryColor,this.altSectionBkgColor=this.background,this.taskBkgColor=he(this.mainBkg,23),this.taskTextColor=this.darkTextColor,this.taskTextLightColor=this.mainContrastColor,this.taskTextOutsideColor=this.taskTextLightColor,this.gridColor=this.mainContrastColor,this.doneTaskBkgColor=this.mainContrastColor,this.taskTextDarkColor=oe(this.doneTaskBkgColor),this.archEdgeColor=this.lineColor,this.archEdgeArrowColor=this.lineColor,this.transitionColor=this.transitionColor||this.lineColor,this.transitionLabelColor=this.transitionLabelColor||this.textColor,this.stateLabelColor=this.stateLabelColor||this.stateBkg||this.primaryTextColor,this.stateBkg=this.stateBkg||this.mainBkg,this.labelBackgroundColor=this.labelBackgroundColor||this.stateBkg,this.compositeBackground=this.compositeBackground||this.background||this.tertiaryColor,this.altBackground=this.altBackground||"#555",this.compositeTitleBackground=this.compositeTitleBackground||this.mainBkg,this.compositeBorder=this.compositeBorder||this.nodeBorder,this.innerEndBackground=this.primaryBorderColor,this.specialStateColor="#f4f4f4",this.errorBkgColor=this.errorBkgColor||this.tertiaryColor,this.errorTextColor=this.errorTextColor||this.tertiaryTextColor,this.fillType0=this.primaryColor,this.fillType1=this.secondaryColor,this.fillType2=R(this.primaryColor,{h:64}),this.fillType3=R(this.secondaryColor,{h:64}),this.fillType4=R(this.primaryColor,{h:-64}),this.fillType5=R(this.secondaryColor,{h:-64}),this.fillType6=R(this.primaryColor,{h:128}),this.fillType7=R(this.secondaryColor,{h:128}),this.cScale1=this.cScale1||"#0b0000",this.cScale2=this.cScale2||"#4d1037",this.cScale3=this.cScale3||"#3f5258",this.cScale4=this.cScale4||"#4f2f1b",this.cScale5=this.cScale5||"#6e0a0a",this.cScale6=this.cScale6||"#3b0048",this.cScale7=this.cScale7||"#995a01",this.cScale8=this.cScale8||"#154706",this.cScale9=this.cScale9||"#161722",this.cScale10=this.cScale10||"#00296f",this.cScale11=this.cScale11||"#01629c",this.cScale12=this.cScale12||"#010029",this.cScale0=this.cScale0||this.primaryColor,this.cScale1=this.cScale1||this.secondaryColor,this.cScale2=this.cScale2||this.tertiaryColor,this.cScale3=this.cScale3||R(this.primaryColor,{h:30}),this.cScale4=this.cScale4||R(this.primaryColor,{h:60}),this.cScale5=this.cScale5||R(this.primaryColor,{h:90}),this.cScale6=this.cScale6||R(this.primaryColor,{h:120}),this.cScale7=this.cScale7||R(this.primaryColor,{h:150}),this.cScale8=this.cScale8||R(this.primaryColor,{h:210}),this.cScale9=this.cScale9||R(this.primaryColor,{h:270}),this.cScale10=this.cScale10||R(this.primaryColor,{h:300}),this.cScale11=this.cScale11||R(this.primaryColor,{h:330});for(let S=0;S<this.THEME_COLOR_LIMIT;S++){e();this["cScaleInv"+S]=this["cScaleInv"+S]||oe(this["cScale"+S])}for(let S=0;S<this.THEME_COLOR_LIMIT;S++){e();this["cScalePeer"+S]=this["cScalePeer"+S]||he(this["cScale"+S],10)}for(let S=0;S<5;S++){e();this["surface"+S]=this["surface"+S]||R(this.mainBkg,{h:30,s:-30,l:-(-10+S*4)}),this["surfacePeer"+S]=this["surfacePeer"+S]||R(this.mainBkg,{h:30,s:-30,l:-(-7+S*4)})}this.scaleLabelColor=this.scaleLabelColor||(this.darkMode?"black":this.labelTextColor);for(let S=0;S<this.THEME_COLOR_LIMIT;S++){e();this["cScaleLabel"+S]=this["cScaleLabel"+S]||this.scaleLabelColor}for(let S=0;S<this.THEME_COLOR_LIMIT;S++){e();this["pie"+S]=this["cScale"+S]}this.pieTitleTextSize=this.pieTitleTextSize||"25px",this.pieTitleTextColor=this.pieTitleTextColor||this.mainContrastColor,this.pieSectionTextSize=this.pieSectionTextSize||"17px",this.pieSectionTextColor=this.pieSectionTextColor||this.textColor,this.pieLegendTextSize=this.pieLegendTextSize||"17px",this.pieLegendTextColor=this.pieLegendTextColor||this.mainContrastColor,this.pieStrokeColor=this.pieStrokeColor||"black",this.pieStrokeWidth=this.pieStrokeWidth||"2px",this.pieOuterStrokeWidth=this.pieOuterStrokeWidth||"2px",this.pieOuterStrokeColor=this.pieOuterStrokeColor||"black",this.pieOpacity=this.pieOpacity||"0.7";for(let S=0;S<8;S++){e();this["venn"+(S+1)]=this["venn"+(S+1)]??he(this["cScale"+S],30)}this.vennTitleTextColor=this.vennTitleTextColor??this.titleColor,this.vennSetTextColor=this.vennSetTextColor??this.textColor,this.cynefin={domainFontSize:this.cynefin?.domainFontSize||16,itemFontSize:this.cynefin?.itemFontSize||12,boundaryColor:this.cynefin?.boundaryColor||this.lineColor,boundaryWidth:this.cynefin?.boundaryWidth||2,cliffColor:this.cynefin?.cliffColor||"#FF6B6B",cliffWidth:this.cynefin?.cliffWidth||4,arrowColor:this.cynefin?.arrowColor||this.lineColor,arrowWidth:this.cynefin?.arrowWidth||2,complexBg:this.cynefin?.complexBg||"#1B5E20",complicatedBg:this.cynefin?.complicatedBg||"#0D47A1",chaoticBg:this.cynefin?.chaoticBg||"#BF360C",clearBg:this.cynefin?.clearBg||"#F57F17",confusionBg:this.cynefin?.confusionBg||"#4A148C",textColor:this.cynefin?.textColor||this.textColor,labelColor:this.cynefin?.labelColor||this.primaryTextColor},this.quadrant1Fill=this.quadrant1Fill||this.primaryColor,this.quadrant2Fill=this.quadrant2Fill||R(this.primaryColor,{r:5,g:5,b:5}),this.quadrant3Fill=this.quadrant3Fill||R(this.primaryColor,{r:10,g:10,b:10}),this.quadrant4Fill=this.quadrant4Fill||R(this.primaryColor,{r:15,g:15,b:15}),this.quadrant1TextFill=this.quadrant1TextFill||this.primaryTextColor,this.quadrant2TextFill=this.quadrant2TextFill||R(this.primaryTextColor,{r:-5,g:-5,b:-5}),this.quadrant3TextFill=this.quadrant3TextFill||R(this.primaryTextColor,{r:-10,g:-10,b:-10}),this.quadrant4TextFill=this.quadrant4TextFill||R(this.primaryTextColor,{r:-15,g:-15,b:-15}),this.quadrantPointFill=this.quadrantPointFill||tr(this.quadrant1Fill)?he(this.quadrant1Fill):me(this.quadrant1Fill),this.quadrantPointTextFill=this.quadrantPointTextFill||this.primaryTextColor,this.quadrantXAxisTextFill=this.quadrantXAxisTextFill||this.primaryTextColor,this.quadrantYAxisTextFill=this.quadrantYAxisTextFill||this.primaryTextColor,this.quadrantInternalBorderStrokeFill=this.quadrantInternalBorderStrokeFill||this.primaryBorderColor,this.quadrantExternalBorderStrokeFill=this.quadrantExternalBorderStrokeFill||this.primaryBorderColor,this.quadrantTitleFill=this.quadrantTitleFill||this.primaryTextColor,this.xyChart={backgroundColor:this.xyChart?.backgroundColor||this.background,titleColor:this.xyChart?.titleColor||this.primaryTextColor,dataLabelColor:this.xyChart?.dataLabelColor||this.primaryTextColor,legendTextColor:this.xyChart?.legendTextColor||this.primaryTextColor,xAxisTitleColor:this.xyChart?.xAxisTitleColor||this.primaryTextColor,xAxisLabelColor:this.xyChart?.xAxisLabelColor||this.primaryTextColor,xAxisTickColor:this.xyChart?.xAxisTickColor||this.primaryTextColor,xAxisLineColor:this.xyChart?.xAxisLineColor||this.primaryTextColor,yAxisTitleColor:this.xyChart?.yAxisTitleColor||this.primaryTextColor,yAxisLabelColor:this.xyChart?.yAxisLabelColor||this.primaryTextColor,yAxisTickColor:this.xyChart?.yAxisTickColor||this.primaryTextColor,yAxisLineColor:this.xyChart?.yAxisLineColor||this.primaryTextColor,plotColorPalette:this.xyChart?.plotColorPalette||"#3498db,#2ecc71,#e74c3c,#f1c40f,#bdc3c7,#ffffff,#34495e,#9b59b6,#1abc9c,#e67e22"},this.packet={startByteColor:this.primaryTextColor,endByteColor:this.primaryTextColor,labelColor:this.primaryTextColor,titleColor:this.primaryTextColor,blockStrokeColor:this.primaryTextColor,blockFillColor:this.background},this.radar={axisColor:this.radar?.axisColor||this.lineColor,axisStrokeWidth:this.radar?.axisStrokeWidth||2,axisLabelFontSize:this.radar?.axisLabelFontSize||12,curveOpacity:this.radar?.curveOpacity||.5,curveStrokeWidth:this.radar?.curveStrokeWidth||2,graticuleColor:this.radar?.graticuleColor||"#DEDEDE",graticuleStrokeWidth:this.radar?.graticuleStrokeWidth||1,graticuleOpacity:this.radar?.graticuleOpacity||.3,legendBoxSize:this.radar?.legendBoxSize||12,legendFontSize:this.radar?.legendFontSize||12},this.wardleyEvolutionColor=this.wardleyEvolutionColor||"#ff6b6b",this.wardley={backgroundColor:this.wardley?.backgroundColor||this.background,axisColor:this.wardley?.axisColor||this.lineColor,axisTextColor:this.wardley?.axisTextColor||this.primaryTextColor,gridColor:this.wardley?.gridColor||this.gridColor,componentFill:this.wardley?.componentFill||this.mainBkg,componentStroke:this.wardley?.componentStroke||this.lineColor,componentLabelColor:this.wardley?.componentLabelColor||this.primaryTextColor,linkStroke:this.wardley?.linkStroke||this.lineColor,evolutionStroke:this.wardley?.evolutionStroke||this.wardleyEvolutionColor,annotationStroke:this.wardley?.annotationStroke||this.lineColor,annotationTextColor:this.wardley?.annotationTextColor||this.primaryTextColor,annotationFill:this.wardley?.annotationFill||this.mainBkg},this.classText=this.primaryTextColor,this.requirementBackground=this.requirementBackground||this.primaryColor,this.requirementBorderColor=this.requirementBorderColor||this.primaryBorderColor,this.requirementBorderSize=this.requirementBorderSize||"1",this.requirementTextColor=this.requirementTextColor||this.primaryTextColor,this.relationColor=this.relationColor||this.lineColor,this.relationLabelBackground=this.relationLabelBackground||(this.darkMode?me(this.secondaryColor,30):this.secondaryColor),this.relationLabelColor=this.relationLabelColor||this.actorTextColor,this.git0=he(this.secondaryColor,20),this.git1=he(this.pie2||this.secondaryColor,20),this.git2=he(this.pie3||this.tertiaryColor,20),this.git3=he(this.pie4||R(this.primaryColor,{h:-30}),20),this.git4=he(this.pie5||R(this.primaryColor,{h:-60}),20),this.git5=he(this.pie6||R(this.primaryColor,{h:-90}),10),this.git6=he(this.pie7||R(this.primaryColor,{h:60}),10),this.git7=he(this.pie8||R(this.primaryColor,{h:120}),20),this.gitInv0=this.gitInv0||oe(this.git0),this.gitInv1=this.gitInv1||oe(this.git1),this.gitInv2=this.gitInv2||oe(this.git2),this.gitInv3=this.gitInv3||oe(this.git3),this.gitInv4=this.gitInv4||oe(this.git4),this.gitInv5=this.gitInv5||oe(this.git5),this.gitInv6=this.gitInv6||oe(this.git6),this.gitInv7=this.gitInv7||oe(this.git7),this.gitBranchLabel0=this.gitBranchLabel0||oe(this.labelTextColor),this.gitBranchLabel1=this.gitBranchLabel1||this.labelTextColor,this.gitBranchLabel2=this.gitBranchLabel2||this.labelTextColor,this.gitBranchLabel3=this.gitBranchLabel3||oe(this.labelTextColor),this.gitBranchLabel4=this.gitBranchLabel4||this.labelTextColor,this.gitBranchLabel5=this.gitBranchLabel5||this.labelTextColor,this.gitBranchLabel6=this.gitBranchLabel6||this.labelTextColor,this.gitBranchLabel7=this.gitBranchLabel7||this.labelTextColor,this.tagLabelColor=this.tagLabelColor||this.primaryTextColor,this.tagLabelBackground=this.tagLabelBackground||this.primaryColor,this.tagLabelBorder=this.tagBorder||this.primaryBorderColor,this.tagLabelFontSize=this.tagLabelFontSize||"10px",this.commitLabelColor=this.commitLabelColor||this.secondaryTextColor,this.commitLabelBackground=this.commitLabelBackground||this.secondaryColor,this.commitLabelFontSize=this.commitLabelFontSize||"10px",this.emUiFill=this.emUiFill||"#2d2d2d",this.emUiStroke=this.emUiStroke||"#555",this.emProcessorFill=this.emProcessorFill||he("#5a3d5c",10),this.emProcessorStroke=this.emProcessorStroke||"#8a6d8c",this.emReadModelFill=this.emReadModelFill||he("#3d5a2d",10),this.emReadModelStroke=this.emReadModelStroke||"#6d8c5c",this.emCommandFill=this.emCommandFill||he("#2d3d5a",10),this.emCommandStroke=this.emCommandStroke||"#5c6d8c",this.emEventFill=this.emEventFill||he("#5a452d",10),this.emEventStroke=this.emEventStroke||"#8c755c",this.emSwimlaneBackgroundOdd=this.emSwimlaneBackgroundOdd||he(this.background,5),this.emSwimlaneBackgroundStroke=this.emSwimlaneBackgroundStroke||he(this.background,12),this.emArrowhead=this.emArrowhead||this.lineColor,this.emRelationStroke=this.emRelationStroke||this.lineColor,this.attributeBackgroundColorOdd=this.attributeBackgroundColorOdd||he(this.background,12),this.attributeBackgroundColorEven=this.attributeBackgroundColorEven||he(this.background,2),this.nodeBorder=this.nodeBorder||"#999"}calculate(S){if(typeof S!=="object"){this.updateColors();return}let I=Object.keys(S);I.forEach(W=>{this[W]=S[W]}),this.updateColors(),I.forEach(W=>{this[W]=vr(this[W],S[W])})}}var $A=v=>{let S=new FA;return S.calculate(v),S};class qA{constructor(){this.background="#f4f4f4",this.primaryColor="#ECECFF",this.secondaryColor=R(this.primaryColor,{h:120}),this.secondaryColor="#ffffde",this.tertiaryColor=R(this.primaryColor,{h:-160}),this.primaryBorderColor=Ue(this.primaryColor,this.darkMode),this.secondaryBorderColor=Ue(this.secondaryColor,this.darkMode),this.tertiaryBorderColor=Ue(this.tertiaryColor,this.darkMode),this.primaryTextColor=oe(this.primaryColor),this.secondaryTextColor=oe(this.secondaryColor),this.tertiaryTextColor=oe(this.tertiaryColor),this.lineColor=oe(this.background),this.textColor=oe(this.background),this.background="white",this.mainBkg="#ECECFF",this.secondBkg="#ffffde",this.lineColor="#333333",this.border1="#9370DB",this.primaryBorderColor=Ue(this.primaryColor,this.darkMode),this.border2="#aaaa33",this.arrowheadColor="#333333",this.fontFamily='"trebuchet ms", verdana, arial, sans-serif',this.fontSize="16px",this.labelBackground="rgba(232,232,232, 0.8)",this.textColor="#333",this.THEME_COLOR_LIMIT=12,this.radius=5,this.strokeWidth=1,this.nodeBkg="calculated",this.nodeBorder="calculated",this.clusterBkg="calculated",this.clusterBorder="calculated",this.defaultLinkColor="calculated",this.titleColor="calculated",this.edgeLabelBackground="calculated",this.actorBorder="calculated",this.actorBkg="calculated",this.actorTextColor="black",this.actorLineColor="calculated",this.signalColor="calculated",this.signalTextColor="calculated",this.labelBoxBkgColor="calculated",this.labelBoxBorderColor="calculated",this.labelTextColor="calculated",this.loopTextColor="calculated",this.noteBorderColor="calculated",this.noteBkgColor="#fff5ad",this.noteTextColor="calculated",this.activationBorderColor="#666",this.activationBkgColor="#f4f4f4",this.sequenceNumberColor="white",this.clusterBkg="#FBFBFF",this.sectionBkgColor="calculated",this.altSectionBkgColor="calculated",this.sectionBkgColor2="calculated",this.excludeBkgColor="#eeeeee",this.taskBorderColor="calculated",this.taskBkgColor="calculated",this.taskTextLightColor="calculated",this.taskTextColor=this.taskTextLightColor,this.taskTextDarkColor="calculated",this.taskTextOutsideColor=this.taskTextDarkColor,this.taskTextClickableColor="calculated",this.activeTaskBorderColor="calculated",this.activeTaskBkgColor="calculated",this.gridColor="calculated",this.doneTaskBkgColor="calculated",this.doneTaskBorderColor="calculated",this.critBorderColor="calculated",this.critBkgColor="calculated",this.todayLineColor="calculated",this.vertLineColor="calculated",this.sectionBkgColor=fr(102,102,255,.49),this.altSectionBkgColor="white",this.sectionBkgColor2="#fff400",this.taskBorderColor="#534fbc",this.taskBkgColor="#8a90dd",this.taskTextLightColor="white",this.taskTextColor="calculated",this.taskTextDarkColor="black",this.taskTextOutsideColor="calculated",this.taskTextClickableColor="#003163",this.activeTaskBorderColor="#534fbc",this.activeTaskBkgColor="#bfc7ff",this.gridColor="lightgrey",this.doneTaskBkgColor="lightgrey",this.doneTaskBorderColor="grey",this.critBorderColor="#ff8888",this.critBkgColor="red",this.todayLineColor="red",this.vertLineColor="navy",this.noteFontWeight=this.noteFontWeight||"normal",this.fontWeight=this.fontWeight||"normal",this.personBorder=this.primaryBorderColor,this.personBkg=this.mainBkg,this.archEdgeColor="calculated",this.archEdgeArrowColor="calculated",this.archEdgeWidth="3",this.archGroupBorderColor=this.primaryBorderColor,this.archGroupBorderWidth="2px",this.rowOdd="calculated",this.rowEven="calculated",this.labelColor="black",this.errorBkgColor="#552222",this.errorTextColor="#552222",this.useGradient=false,this.gradientStart=this.primaryBorderColor,this.gradientStop=this.secondaryBorderColor,this.dropShadow="drop-shadow(1px 2px 2px rgba(185, 185, 185, 1))",this.updateColors()}updateColors(){this.cScale0=this.cScale0||this.primaryColor,this.cScale1=this.cScale1||this.secondaryColor,this.cScale2=this.cScale2||this.tertiaryColor,this.cScale3=this.cScale3||R(this.primaryColor,{h:30}),this.cScale4=this.cScale4||R(this.primaryColor,{h:60}),this.cScale5=this.cScale5||R(this.primaryColor,{h:90}),this.cScale6=this.cScale6||R(this.primaryColor,{h:120}),this.cScale7=this.cScale7||R(this.primaryColor,{h:150}),this.cScale8=this.cScale8||R(this.primaryColor,{h:210}),this.cScale9=this.cScale9||R(this.primaryColor,{h:270}),this.cScale10=this.cScale10||R(this.primaryColor,{h:300}),this.cScale11=this.cScale11||R(this.primaryColor,{h:330}),this.cScalePeer1=this.cScalePeer1||me(this.secondaryColor,45),this.cScalePeer2=this.cScalePeer2||me(this.tertiaryColor,40);for(let S=0;S<this.THEME_COLOR_LIMIT;S++){e();this["cScale"+S]=me(this["cScale"+S],10),this["cScalePeer"+S]=this["cScalePeer"+S]||me(this["cScale"+S],25)}for(let S=0;S<this.THEME_COLOR_LIMIT;S++){e();this["cScaleInv"+S]=this["cScaleInv"+S]||R(this["cScale"+S],{h:180})}for(let S=0;S<5;S++){e();this["surface"+S]=this["surface"+S]||R(this.mainBkg,{h:30,l:-(5+S*5)}),this["surfacePeer"+S]=this["surfacePeer"+S]||R(this.mainBkg,{h:30,l:-(7+S*5)})}if(this.scaleLabelColor=this.scaleLabelColor!=="calculated"&&this.scaleLabelColor?this.scaleLabelColor:this.labelTextColor,this.labelTextColor!=="calculated"){this.cScaleLabel0=this.cScaleLabel0||oe(this.labelTextColor),this.cScaleLabel3=this.cScaleLabel3||oe(this.labelTextColor);for(let S=0;S<this.THEME_COLOR_LIMIT;S++){e();this["cScaleLabel"+S]=this["cScaleLabel"+S]||this.labelTextColor}}if(this.nodeBkg=this.mainBkg,this.nodeBorder=this.border1,this.clusterBkg=this.secondBkg,this.clusterBorder=this.border2,this.defaultLinkColor=this.lineColor,this.titleColor=this.textColor,this.edgeLabelBackground=this.labelBackground,this.flowContainerStroke=this.flowContainerStroke||this.secondaryBorderColor,this.actorBorder=this.border1,this.actorBkg=this.mainBkg,this.labelBoxBkgColor=this.actorBkg,this.signalColor=this.textColor,this.signalTextColor=this.textColor,this.labelBoxBorderColor=this.actorBorder,this.labelTextColor=this.actorTextColor,this.loopTextColor=this.actorTextColor,this.noteBorderColor=this.border2,this.noteTextColor=this.actorTextColor,this.actorLineColor=this.actorBorder,this.rectBkgColor=this.rectBkgColor||this.tertiaryColor,this.taskTextColor=this.taskTextLightColor,this.taskTextOutsideColor=this.taskTextDarkColor,this.archEdgeColor=this.lineColor,this.archEdgeArrowColor=this.lineColor,this.rowOdd=this.rowOdd||he(this.primaryColor,75)||"#ffffff",this.rowEven=this.rowEven||he(this.primaryColor,1),this.transitionColor=this.transitionColor||this.lineColor,this.transitionLabelColor=this.transitionLabelColor||this.textColor,this.stateLabelColor=this.stateLabelColor||this.stateBkg||this.primaryTextColor,this.stateBkg=this.stateBkg||this.mainBkg,this.labelBackgroundColor=this.labelBackgroundColor||this.stateBkg,this.compositeBackground=this.compositeBackground||this.background||this.tertiaryColor,this.altBackground=this.altBackground||"#f0f0f0",this.compositeTitleBackground=this.compositeTitleBackground||this.mainBkg,this.compositeBorder=this.compositeBorder||this.nodeBorder,this.innerEndBackground=this.nodeBorder,this.specialStateColor=this.lineColor,this.errorBkgColor=this.errorBkgColor||this.tertiaryColor,this.errorTextColor=this.errorTextColor||this.tertiaryTextColor,this.transitionColor=this.transitionColor||this.lineColor,this.classText=this.primaryTextColor,this.fillType0=this.primaryColor,this.fillType1=this.secondaryColor,this.fillType2=R(this.primaryColor,{h:64}),this.fillType3=R(this.secondaryColor,{h:64}),this.fillType4=R(this.primaryColor,{h:-64}),this.fillType5=R(this.secondaryColor,{h:-64}),this.fillType6=R(this.primaryColor,{h:128}),this.fillType7=R(this.secondaryColor,{h:128}),this.pie1=this.pie1||this.primaryColor,this.pie2=this.pie2||this.secondaryColor,this.pie3=this.pie3||R(this.tertiaryColor,{l:-40}),this.pie4=this.pie4||R(this.primaryColor,{l:-10}),this.pie5=this.pie5||R(this.secondaryColor,{l:-30}),this.pie6=this.pie6||R(this.tertiaryColor,{l:-20}),this.pie7=this.pie7||R(this.primaryColor,{h:60,l:-20}),this.pie8=this.pie8||R(this.primaryColor,{h:-60,l:-40}),this.pie9=this.pie9||R(this.primaryColor,{h:120,l:-40}),this.pie10=this.pie10||R(this.primaryColor,{h:60,l:-40}),this.pie11=this.pie11||R(this.primaryColor,{h:-90,l:-40}),this.pie12=this.pie12||R(this.primaryColor,{h:120,l:-30}),this.pieTitleTextSize=this.pieTitleTextSize||"25px",this.pieTitleTextColor=this.pieTitleTextColor||this.taskTextDarkColor,this.pieSectionTextSize=this.pieSectionTextSize||"17px",this.pieSectionTextColor=this.pieSectionTextColor||this.textColor,this.pieLegendTextSize=this.pieLegendTextSize||"17px",this.pieLegendTextColor=this.pieLegendTextColor||this.taskTextDarkColor,this.pieStrokeColor=this.pieStrokeColor||"black",this.pieStrokeWidth=this.pieStrokeWidth||"2px",this.pieOuterStrokeWidth=this.pieOuterStrokeWidth||"2px",this.pieOuterStrokeColor=this.pieOuterStrokeColor||"black",this.pieOpacity=this.pieOpacity||"0.7",this.venn1=this.venn1??R(this.primaryColor,{l:-30}),this.venn2=this.venn2??R(this.secondaryColor,{l:-30}),this.venn3=this.venn3??R(this.tertiaryColor,{l:-40}),this.venn4=this.venn4??R(this.primaryColor,{h:60,l:-30}),this.venn5=this.venn5??R(this.primaryColor,{h:-60,l:-30}),this.venn6=this.venn6??R(this.secondaryColor,{h:60,l:-30}),this.venn7=this.venn7??R(this.primaryColor,{h:120,l:-30}),this.venn8=this.venn8??R(this.secondaryColor,{h:120,l:-30}),this.vennTitleTextColor=this.vennTitleTextColor??this.titleColor,this.vennSetTextColor=this.vennSetTextColor??this.textColor,this.cynefin={domainFontSize:this.cynefin?.domainFontSize||16,itemFontSize:this.cynefin?.itemFontSize||12,boundaryColor:this.cynefin?.boundaryColor||this.lineColor,boundaryWidth:this.cynefin?.boundaryWidth||2,cliffColor:this.cynefin?.cliffColor||"#8B0000",cliffWidth:this.cynefin?.cliffWidth||4,arrowColor:this.cynefin?.arrowColor||this.lineColor,arrowWidth:this.cynefin?.arrowWidth||2,complexBg:this.cynefin?.complexBg||"#E8F5E9",complicatedBg:this.cynefin?.complicatedBg||"#E3F2FD",chaoticBg:this.cynefin?.chaoticBg||"#FBE9E7",clearBg:this.cynefin?.clearBg||"#FFF8E1",confusionBg:this.cynefin?.confusionBg||"#F3E5F5",textColor:this.cynefin?.textColor||this.textColor,labelColor:this.cynefin?.labelColor||this.primaryTextColor},this.quadrant1Fill=this.quadrant1Fill||this.primaryColor,this.quadrant2Fill=this.quadrant2Fill||R(this.primaryColor,{r:5,g:5,b:5}),this.quadrant3Fill=this.quadrant3Fill||R(this.primaryColor,{r:10,g:10,b:10}),this.quadrant4Fill=this.quadrant4Fill||R(this.primaryColor,{r:15,g:15,b:15}),this.quadrant1TextFill=this.quadrant1TextFill||this.primaryTextColor,this.quadrant2TextFill=this.quadrant2TextFill||R(this.primaryTextColor,{r:-5,g:-5,b:-5}),this.quadrant3TextFill=this.quadrant3TextFill||R(this.primaryTextColor,{r:-10,g:-10,b:-10}),this.quadrant4TextFill=this.quadrant4TextFill||R(this.primaryTextColor,{r:-15,g:-15,b:-15}),this.quadrantPointFill=this.quadrantPointFill||tr(this.quadrant1Fill)?he(this.quadrant1Fill):me(this.quadrant1Fill),this.quadrantPointTextFill=this.quadrantPointTextFill||this.primaryTextColor,this.quadrantXAxisTextFill=this.quadrantXAxisTextFill||this.primaryTextColor,this.quadrantYAxisTextFill=this.quadrantYAxisTextFill||this.primaryTextColor,this.quadrantInternalBorderStrokeFill=this.quadrantInternalBorderStrokeFill||this.primaryBorderColor,this.quadrantExternalBorderStrokeFill=this.quadrantExternalBorderStrokeFill||this.primaryBorderColor,this.quadrantTitleFill=this.quadrantTitleFill||this.primaryTextColor,this.radar={axisColor:this.radar?.axisColor||this.lineColor,axisStrokeWidth:this.radar?.axisStrokeWidth||2,axisLabelFontSize:this.radar?.axisLabelFontSize||12,curveOpacity:this.radar?.curveOpacity||.5,curveStrokeWidth:this.radar?.curveStrokeWidth||2,graticuleColor:this.radar?.graticuleColor||"#DEDEDE",graticuleStrokeWidth:this.radar?.graticuleStrokeWidth||1,graticuleOpacity:this.radar?.graticuleOpacity||.3,legendBoxSize:this.radar?.legendBoxSize||12,legendFontSize:this.radar?.legendFontSize||12},this.wardleyEvolutionColor=this.wardleyEvolutionColor||"#dc3545",this.wardley={backgroundColor:this.wardley?.backgroundColor||this.background,axisColor:this.wardley?.axisColor||this.lineColor,axisTextColor:this.wardley?.axisTextColor||this.primaryTextColor,gridColor:this.wardley?.gridColor||this.gridColor,componentFill:this.wardley?.componentFill||this.background,componentStroke:this.wardley?.componentStroke||this.lineColor,componentLabelColor:this.wardley?.componentLabelColor||this.primaryTextColor,linkStroke:this.wardley?.linkStroke||this.lineColor,evolutionStroke:this.wardley?.evolutionStroke||this.wardleyEvolutionColor,annotationStroke:this.wardley?.annotationStroke||this.lineColor,annotationTextColor:this.wardley?.annotationTextColor||this.primaryTextColor,annotationFill:this.wardley?.annotationFill||this.background},this.xyChart={backgroundColor:this.xyChart?.backgroundColor||this.background,titleColor:this.xyChart?.titleColor||this.primaryTextColor,dataLabelColor:this.xyChart?.dataLabelColor||this.primaryTextColor,legendTextColor:this.xyChart?.legendTextColor||this.primaryTextColor,xAxisTitleColor:this.xyChart?.xAxisTitleColor||this.primaryTextColor,xAxisLabelColor:this.xyChart?.xAxisLabelColor||this.primaryTextColor,xAxisTickColor:this.xyChart?.xAxisTickColor||this.primaryTextColor,xAxisLineColor:this.xyChart?.xAxisLineColor||this.primaryTextColor,yAxisTitleColor:this.xyChart?.yAxisTitleColor||this.primaryTextColor,yAxisLabelColor:this.xyChart?.yAxisLabelColor||this.primaryTextColor,yAxisTickColor:this.xyChart?.yAxisTickColor||this.primaryTextColor,yAxisLineColor:this.xyChart?.yAxisLineColor||this.primaryTextColor,plotColorPalette:this.xyChart?.plotColorPalette||"#ECECFF,#8493A6,#FFC3A0,#DCDDE1,#B8E994,#D1A36F,#C3CDE6,#FFB6C1,#496078,#F8F3E3"},this.requirementBackground=this.requirementBackground||this.primaryColor,this.requirementBorderColor=this.requirementBorderColor||this.primaryBorderColor,this.requirementBorderSize=this.requirementBorderSize||"1",this.requirementTextColor=this.requirementTextColor||this.primaryTextColor,this.relationColor=this.relationColor||this.lineColor,this.relationLabelBackground=this.relationLabelBackground||this.labelBackground,this.relationLabelColor=this.relationLabelColor||this.actorTextColor,this.git0=this.git0||this.primaryColor,this.git1=this.git1||this.secondaryColor,this.git2=this.git2||this.tertiaryColor,this.git3=this.git3||R(this.primaryColor,{h:-30}),this.git4=this.git4||R(this.primaryColor,{h:-60}),this.git5=this.git5||R(this.primaryColor,{h:-90}),this.git6=this.git6||R(this.primaryColor,{h:60}),this.git7=this.git7||R(this.primaryColor,{h:120}),this.darkMode)this.git0=he(this.git0,25),this.git1=he(this.git1,25),this.git2=he(this.git2,25),this.git3=he(this.git3,25),this.git4=he(this.git4,25),this.git5=he(this.git5,25),this.git6=he(this.git6,25),this.git7=he(this.git7,25);else this.git0=me(this.git0,25),this.git1=me(this.git1,25),this.git2=me(this.git2,25),this.git3=me(this.git3,25),this.git4=me(this.git4,25),this.git5=me(this.git5,25),this.git6=me(this.git6,25),this.git7=me(this.git7,25);this.gitInv0=this.gitInv0||me(oe(this.git0),25),this.gitInv1=this.gitInv1||oe(this.git1),this.gitInv2=this.gitInv2||oe(this.git2),this.gitInv3=this.gitInv3||oe(this.git3),this.gitInv4=this.gitInv4||oe(this.git4),this.gitInv5=this.gitInv5||oe(this.git5),this.gitInv6=this.gitInv6||oe(this.git6),this.gitInv7=this.gitInv7||oe(this.git7),this.gitBranchLabel0=this.gitBranchLabel0||oe(this.labelTextColor),this.gitBranchLabel1=this.gitBranchLabel1||this.labelTextColor,this.gitBranchLabel2=this.gitBranchLabel2||this.labelTextColor,this.gitBranchLabel3=this.gitBranchLabel3||oe(this.labelTextColor),this.gitBranchLabel4=this.gitBranchLabel4||this.labelTextColor,this.gitBranchLabel5=this.gitBranchLabel5||this.labelTextColor,this.gitBranchLabel6=this.gitBranchLabel6||this.labelTextColor,this.gitBranchLabel7=this.gitBranchLabel7||this.labelTextColor,this.tagLabelColor=this.tagLabelColor||this.primaryTextColor,this.tagLabelBackground=this.tagLabelBackground||this.primaryColor,this.tagLabelBorder=this.tagBorder||this.primaryBorderColor,this.tagLabelFontSize=this.tagLabelFontSize||"10px",this.commitLabelColor=this.commitLabelColor||this.secondaryTextColor,this.commitLabelBackground=this.commitLabelBackground||this.secondaryColor,this.commitLabelFontSize=this.commitLabelFontSize||"10px",this.emUiFill=this.emUiFill||"white",this.emUiStroke=this.emUiStroke||"#dbdada",this.emProcessorFill=this.emProcessorFill||"#edb3f6",this.emProcessorStroke=this.emProcessorStroke||"#b88cbf",this.emReadModelFill=this.emReadModelFill||"#d3f1a2",this.emReadModelStroke=this.emReadModelStroke||"#a3b732",this.emCommandFill=this.emCommandFill||"#bcd6fe",this.emCommandStroke=this.emCommandStroke||"#679ac3",this.emEventFill=this.emEventFill||"#ffb778",this.emEventStroke=this.emEventStroke||"#c19a0f",this.emSwimlaneBackgroundOdd=this.emSwimlaneBackgroundOdd||"rgb(250,250,250)",this.emSwimlaneBackgroundStroke=this.emSwimlaneBackgroundStroke||"rgb(240,240,240)",this.emArrowhead=this.emArrowhead||this.lineColor,this.emRelationStroke=this.emRelationStroke||this.lineColor,this.attributeBackgroundColorOdd=this.attributeBackgroundColorOdd||Zr,this.attributeBackgroundColorEven=this.attributeBackgroundColorEven||ei}calculate(S){if(Object.keys(this).forEach(W=>{if(this[W]==="calculated")this[W]=void 0}),typeof S!=="object"){this.updateColors();return}let I=Object.keys(S);I.forEach(W=>{this[W]=S[W]}),this.updateColors(),I.forEach(W=>{this[W]=vr(this[W],S[W])})}}var zA=v=>{let S=new qA;return S.calculate(v),S};class GA{constructor(){this.background="#f4f4f4",this.primaryColor="#cde498",this.secondaryColor="#cdffb2",this.background="white",this.mainBkg="#cde498",this.secondBkg="#cdffb2",this.lineColor="green",this.border1="#13540c",this.border2="#6eaa49",this.arrowheadColor="green",this.fontFamily='"trebuchet ms", verdana, arial, sans-serif',this.fontSize="16px",this.tertiaryColor=he("#cde498",10),this.primaryBorderColor=Ue(this.primaryColor,this.darkMode),this.secondaryBorderColor=Ue(this.secondaryColor,this.darkMode),this.tertiaryBorderColor=Ue(this.tertiaryColor,this.darkMode),this.primaryTextColor=oe(this.primaryColor),this.secondaryTextColor=oe(this.secondaryColor),this.tertiaryTextColor=oe(this.primaryColor),this.lineColor=oe(this.background),this.textColor=oe(this.background),this.THEME_COLOR_LIMIT=12,this.radius=5,this.strokeWidth=1,this.nodeBkg="calculated",this.nodeBorder="calculated",this.clusterBkg="calculated",this.clusterBorder="calculated",this.defaultLinkColor="calculated",this.titleColor="#333",this.edgeLabelBackground="#e8e8e8",this.actorBorder="calculated",this.actorBkg="calculated",this.actorTextColor="black",this.actorLineColor="calculated",this.signalColor="#333",this.signalTextColor="#333",this.labelBoxBkgColor="calculated",this.labelBoxBorderColor="#326932",this.labelTextColor="calculated",this.loopTextColor="calculated",this.noteBorderColor="calculated",this.noteBkgColor="#fff5ad",this.noteTextColor="calculated",this.activationBorderColor="#666",this.activationBkgColor="#f4f4f4",this.sequenceNumberColor="white",this.sectionBkgColor="#6eaa49",this.altSectionBkgColor="white",this.sectionBkgColor2="#6eaa49",this.excludeBkgColor="#eeeeee",this.taskBorderColor="calculated",this.taskBkgColor="#487e3a",this.taskTextLightColor="white",this.taskTextColor="calculated",this.taskTextDarkColor="black",this.taskTextOutsideColor="calculated",this.taskTextClickableColor="#003163",this.activeTaskBorderColor="calculated",this.activeTaskBkgColor="calculated",this.gridColor="lightgrey",this.doneTaskBkgColor="lightgrey",this.doneTaskBorderColor="grey",this.critBorderColor="#ff8888",this.critBkgColor="red",this.todayLineColor="red",this.vertLineColor="#00BFFF",this.personBorder=this.primaryBorderColor,this.personBkg=this.mainBkg,this.archEdgeColor="calculated",this.archEdgeArrowColor="calculated",this.archEdgeWidth="3",this.archGroupBorderColor=this.primaryBorderColor,this.archGroupBorderWidth="2px",this.noteFontWeight="normal",this.fontWeight="normal",this.labelColor="black",this.errorBkgColor="#552222",this.errorTextColor="#552222",this.useGradient=true,this.gradientStart=this.primaryBorderColor,this.gradientStop=this.secondaryBorderColor,this.dropShadow="drop-shadow( 1px 2px 2px rgba(185,185,185,0.5))"}updateColors(){this.actorBorder=me(this.mainBkg,20),this.actorBkg=this.mainBkg,this.labelBoxBkgColor=this.actorBkg,this.labelTextColor=this.actorTextColor,this.loopTextColor=this.actorTextColor,this.noteBorderColor=this.border2,this.noteTextColor=this.actorTextColor,this.actorLineColor=this.actorBorder,this.rectBkgColor=this.rectBkgColor||this.tertiaryColor,this.cScale0=this.cScale0||this.primaryColor,this.cScale1=this.cScale1||this.secondaryColor,this.cScale2=this.cScale2||this.tertiaryColor,this.cScale3=this.cScale3||R(this.primaryColor,{h:30}),this.cScale4=this.cScale4||R(this.primaryColor,{h:60}),this.cScale5=this.cScale5||R(this.primaryColor,{h:90}),this.cScale6=this.cScale6||R(this.primaryColor,{h:120}),this.cScale7=this.cScale7||R(this.primaryColor,{h:150}),this.cScale8=this.cScale8||R(this.primaryColor,{h:210}),this.cScale9=this.cScale9||R(this.primaryColor,{h:270}),this.cScale10=this.cScale10||R(this.primaryColor,{h:300}),this.cScale11=this.cScale11||R(this.primaryColor,{h:330}),this.cScalePeer1=this.cScalePeer1||me(this.secondaryColor,45),this.cScalePeer2=this.cScalePeer2||me(this.tertiaryColor,40);for(let S=0;S<this.THEME_COLOR_LIMIT;S++){e();this["cScale"+S]=me(this["cScale"+S],10),this["cScalePeer"+S]=this["cScalePeer"+S]||me(this["cScale"+S],25)}for(let S=0;S<this.THEME_COLOR_LIMIT;S++){e();this["cScaleInv"+S]=this["cScaleInv"+S]||R(this["cScale"+S],{h:180})}this.scaleLabelColor=this.scaleLabelColor!=="calculated"&&this.scaleLabelColor?this.scaleLabelColor:this.labelTextColor;for(let S=0;S<this.THEME_COLOR_LIMIT;S++){e();this["cScaleLabel"+S]=this["cScaleLabel"+S]||this.scaleLabelColor}for(let S=0;S<5;S++){e();this["surface"+S]=this["surface"+S]||R(this.mainBkg,{h:30,s:-30,l:-(5+S*5)}),this["surfacePeer"+S]=this["surfacePeer"+S]||R(this.mainBkg,{h:30,s:-30,l:-(8+S*5)})}if(this.nodeBkg=this.mainBkg,this.nodeBorder=this.border1,this.clusterBkg=this.secondBkg,this.clusterBorder=this.border2,this.defaultLinkColor=this.lineColor,this.flowContainerStroke=this.flowContainerStroke||this.secondaryBorderColor,this.taskBorderColor=this.border1,this.taskTextColor=this.taskTextLightColor,this.taskTextOutsideColor=this.taskTextDarkColor,this.activeTaskBorderColor=this.taskBorderColor,this.activeTaskBkgColor=this.mainBkg,this.archEdgeColor=this.lineColor,this.archEdgeArrowColor=this.lineColor,this.rowOdd=this.rowOdd||he(this.mainBkg,75)||"#ffffff",this.rowEven=this.rowEven||he(this.mainBkg,20),this.transitionColor=this.transitionColor||this.lineColor,this.transitionLabelColor=this.transitionLabelColor||this.textColor,this.stateLabelColor=this.stateLabelColor||this.stateBkg||this.primaryTextColor,this.stateBkg=this.stateBkg||this.mainBkg,this.labelBackgroundColor=this.labelBackgroundColor||this.stateBkg,this.compositeBackground=this.compositeBackground||this.background||this.tertiaryColor,this.altBackground=this.altBackground||"#f0f0f0",this.compositeTitleBackground=this.compositeTitleBackground||this.mainBkg,this.compositeBorder=this.compositeBorder||this.nodeBorder,this.innerEndBackground=this.primaryBorderColor,this.specialStateColor=this.lineColor,this.errorBkgColor=this.errorBkgColor||this.tertiaryColor,this.errorTextColor=this.errorTextColor||this.tertiaryTextColor,this.transitionColor=this.transitionColor||this.lineColor,this.classText=this.primaryTextColor,this.fillType0=this.primaryColor,this.fillType1=this.secondaryColor,this.fillType2=R(this.primaryColor,{h:64}),this.fillType3=R(this.secondaryColor,{h:64}),this.fillType4=R(this.primaryColor,{h:-64}),this.fillType5=R(this.secondaryColor,{h:-64}),this.fillType6=R(this.primaryColor,{h:128}),this.fillType7=R(this.secondaryColor,{h:128}),this.pie1=this.pie1||this.primaryColor,this.pie2=this.pie2||this.secondaryColor,this.pie3=this.pie3||this.tertiaryColor,this.pie4=this.pie4||R(this.primaryColor,{l:-30}),this.pie5=this.pie5||R(this.secondaryColor,{l:-30}),this.pie6=this.pie6||R(this.tertiaryColor,{h:40,l:-40}),this.pie7=this.pie7||R(this.primaryColor,{h:60,l:-10}),this.pie8=this.pie8||R(this.primaryColor,{h:-60,l:-10}),this.pie9=this.pie9||R(this.primaryColor,{h:120,l:0}),this.pie10=this.pie10||R(this.primaryColor,{h:60,l:-50}),this.pie11=this.pie11||R(this.primaryColor,{h:-60,l:-50}),this.pie12=this.pie12||R(this.primaryColor,{h:120,l:-50}),this.pieTitleTextSize=this.pieTitleTextSize||"25px",this.pieTitleTextColor=this.pieTitleTextColor||this.taskTextDarkColor,this.pieSectionTextSize=this.pieSectionTextSize||"17px",this.pieSectionTextColor=this.pieSectionTextColor||this.textColor,this.pieLegendTextSize=this.pieLegendTextSize||"17px",this.pieLegendTextColor=this.pieLegendTextColor||this.taskTextDarkColor,this.pieStrokeColor=this.pieStrokeColor||"black",this.pieStrokeWidth=this.pieStrokeWidth||"2px",this.pieOuterStrokeWidth=this.pieOuterStrokeWidth||"2px",this.pieOuterStrokeColor=this.pieOuterStrokeColor||"black",this.pieOpacity=this.pieOpacity||"0.7",this.venn1=this.venn1??R(this.primaryColor,{l:-30}),this.venn2=this.venn2??R(this.secondaryColor,{l:-30}),this.venn3=this.venn3??R(this.tertiaryColor,{l:-30}),this.venn4=this.venn4??R(this.primaryColor,{h:60,l:-30}),this.venn5=this.venn5??R(this.primaryColor,{h:-60,l:-30}),this.venn6=this.venn6??R(this.secondaryColor,{h:60,l:-30}),this.venn7=this.venn7??R(this.primaryColor,{h:120,l:-30}),this.venn8=this.venn8??R(this.secondaryColor,{h:120,l:-30}),this.vennTitleTextColor=this.vennTitleTextColor??this.titleColor,this.vennSetTextColor=this.vennSetTextColor??this.textColor,this.cynefin={domainFontSize:this.cynefin?.domainFontSize||16,itemFontSize:this.cynefin?.itemFontSize||12,boundaryColor:this.cynefin?.boundaryColor||this.lineColor,boundaryWidth:this.cynefin?.boundaryWidth||2,cliffColor:this.cynefin?.cliffColor||"#8B4513",cliffWidth:this.cynefin?.cliffWidth||4,arrowColor:this.cynefin?.arrowColor||this.lineColor,arrowWidth:this.cynefin?.arrowWidth||2,complexBg:this.cynefin?.complexBg||"#C8E6C9",complicatedBg:this.cynefin?.complicatedBg||"#DCEDC8",chaoticBg:this.cynefin?.chaoticBg||"#FFE0B2",clearBg:this.cynefin?.clearBg||"#FFF9C4",confusionBg:this.cynefin?.confusionBg||"#D7CCC8",textColor:this.cynefin?.textColor||this.textColor,labelColor:this.cynefin?.labelColor||this.primaryTextColor},this.quadrant1Fill=this.quadrant1Fill||this.primaryColor,this.quadrant2Fill=this.quadrant2Fill||R(this.primaryColor,{r:5,g:5,b:5}),this.quadrant3Fill=this.quadrant3Fill||R(this.primaryColor,{r:10,g:10,b:10}),this.quadrant4Fill=this.quadrant4Fill||R(this.primaryColor,{r:15,g:15,b:15}),this.quadrant1TextFill=this.quadrant1TextFill||this.primaryTextColor,this.quadrant2TextFill=this.quadrant2TextFill||R(this.primaryTextColor,{r:-5,g:-5,b:-5}),this.quadrant3TextFill=this.quadrant3TextFill||R(this.primaryTextColor,{r:-10,g:-10,b:-10}),this.quadrant4TextFill=this.quadrant4TextFill||R(this.primaryTextColor,{r:-15,g:-15,b:-15}),this.quadrantPointFill=this.quadrantPointFill||tr(this.quadrant1Fill)?he(this.quadrant1Fill):me(this.quadrant1Fill),this.quadrantPointTextFill=this.quadrantPointTextFill||this.primaryTextColor,this.quadrantXAxisTextFill=this.quadrantXAxisTextFill||this.primaryTextColor,this.quadrantYAxisTextFill=this.quadrantYAxisTextFill||this.primaryTextColor,this.quadrantInternalBorderStrokeFill=this.quadrantInternalBorderStrokeFill||this.primaryBorderColor,this.quadrantExternalBorderStrokeFill=this.quadrantExternalBorderStrokeFill||this.primaryBorderColor,this.quadrantTitleFill=this.quadrantTitleFill||this.primaryTextColor,this.packet={startByteColor:this.primaryTextColor,endByteColor:this.primaryTextColor,labelColor:this.primaryTextColor,titleColor:this.primaryTextColor,blockStrokeColor:this.primaryTextColor,blockFillColor:this.mainBkg},this.radar={axisColor:this.radar?.axisColor||this.lineColor,axisStrokeWidth:this.radar?.axisStrokeWidth||2,axisLabelFontSize:this.radar?.axisLabelFontSize||12,curveOpacity:this.radar?.curveOpacity||.5,curveStrokeWidth:this.radar?.curveStrokeWidth||2,graticuleColor:this.radar?.graticuleColor||"#DEDEDE",graticuleStrokeWidth:this.radar?.graticuleStrokeWidth||1,graticuleOpacity:this.radar?.graticuleOpacity||.3,legendBoxSize:this.radar?.legendBoxSize||12,legendFontSize:this.radar?.legendFontSize||12},this.wardleyEvolutionColor=this.wardleyEvolutionColor||"#dc3545",this.wardley={backgroundColor:this.wardley?.backgroundColor||this.background,axisColor:this.wardley?.axisColor||this.lineColor,axisTextColor:this.wardley?.axisTextColor||this.primaryTextColor,gridColor:this.wardley?.gridColor||this.gridColor,componentFill:this.wardley?.componentFill||this.background,componentStroke:this.wardley?.componentStroke||this.lineColor,componentLabelColor:this.wardley?.componentLabelColor||this.primaryTextColor,linkStroke:this.wardley?.linkStroke||this.lineColor,evolutionStroke:this.wardley?.evolutionStroke||this.wardleyEvolutionColor,annotationStroke:this.wardley?.annotationStroke||this.lineColor,annotationTextColor:this.wardley?.annotationTextColor||this.primaryTextColor,annotationFill:this.wardley?.annotationFill||this.background},this.xyChart={backgroundColor:this.xyChart?.backgroundColor||this.background,titleColor:this.xyChart?.titleColor||this.primaryTextColor,dataLabelColor:this.xyChart?.dataLabelColor||this.primaryTextColor,legendTextColor:this.xyChart?.legendTextColor||this.primaryTextColor,xAxisTitleColor:this.xyChart?.xAxisTitleColor||this.primaryTextColor,xAxisLabelColor:this.xyChart?.xAxisLabelColor||this.primaryTextColor,xAxisTickColor:this.xyChart?.xAxisTickColor||this.primaryTextColor,xAxisLineColor:this.xyChart?.xAxisLineColor||this.primaryTextColor,yAxisTitleColor:this.xyChart?.yAxisTitleColor||this.primaryTextColor,yAxisLabelColor:this.xyChart?.yAxisLabelColor||this.primaryTextColor,yAxisTickColor:this.xyChart?.yAxisTickColor||this.primaryTextColor,yAxisLineColor:this.xyChart?.yAxisLineColor||this.primaryTextColor,plotColorPalette:this.xyChart?.plotColorPalette||"#CDE498,#FF6B6B,#A0D2DB,#D7BDE2,#F0F0F0,#FFC3A0,#7FD8BE,#FF9A8B,#FAF3E0,#FFF176"},this.requirementBackground=this.requirementBackground||this.primaryColor,this.requirementBorderColor=this.requirementBorderColor||this.primaryBorderColor,this.requirementBorderSize=this.requirementBorderSize||"1",this.requirementTextColor=this.requirementTextColor||this.primaryTextColor,this.relationColor=this.relationColor||this.lineColor,this.relationLabelBackground=this.relationLabelBackground||this.edgeLabelBackground,this.relationLabelColor=this.relationLabelColor||this.actorTextColor,this.git0=this.git0||this.primaryColor,this.git1=this.git1||this.secondaryColor,this.git2=this.git2||this.tertiaryColor,this.git3=this.git3||R(this.primaryColor,{h:-30}),this.git4=this.git4||R(this.primaryColor,{h:-60}),this.git5=this.git5||R(this.primaryColor,{h:-90}),this.git6=this.git6||R(this.primaryColor,{h:60}),this.git7=this.git7||R(this.primaryColor,{h:120}),this.darkMode)this.git0=he(this.git0,25),this.git1=he(this.git1,25),this.git2=he(this.git2,25),this.git3=he(this.git3,25),this.git4=he(this.git4,25),this.git5=he(this.git5,25),this.git6=he(this.git6,25),this.git7=he(this.git7,25);else this.git0=me(this.git0,25),this.git1=me(this.git1,25),this.git2=me(this.git2,25),this.git3=me(this.git3,25),this.git4=me(this.git4,25),this.git5=me(this.git5,25),this.git6=me(this.git6,25),this.git7=me(this.git7,25);this.gitInv0=this.gitInv0||oe(this.git0),this.gitInv1=this.gitInv1||oe(this.git1),this.gitInv2=this.gitInv2||oe(this.git2),this.gitInv3=this.gitInv3||oe(this.git3),this.gitInv4=this.gitInv4||oe(this.git4),this.gitInv5=this.gitInv5||oe(this.git5),this.gitInv6=this.gitInv6||oe(this.git6),this.gitInv7=this.gitInv7||oe(this.git7),this.gitBranchLabel0=this.gitBranchLabel0||oe(this.labelTextColor),this.gitBranchLabel1=this.gitBranchLabel1||this.labelTextColor,this.gitBranchLabel2=this.gitBranchLabel2||this.labelTextColor,this.gitBranchLabel3=this.gitBranchLabel3||oe(this.labelTextColor),this.gitBranchLabel4=this.gitBranchLabel4||this.labelTextColor,this.gitBranchLabel5=this.gitBranchLabel5||this.labelTextColor,this.gitBranchLabel6=this.gitBranchLabel6||this.labelTextColor,this.gitBranchLabel7=this.gitBranchLabel7||this.labelTextColor,this.tagLabelColor=this.tagLabelColor||this.primaryTextColor,this.tagLabelBackground=this.tagLabelBackground||this.primaryColor,this.tagLabelBorder=this.tagBorder||this.primaryBorderColor,this.tagLabelFontSize=this.tagLabelFontSize||"10px",this.commitLabelColor=this.commitLabelColor||this.secondaryTextColor,this.commitLabelBackground=this.commitLabelBackground||this.secondaryColor,this.commitLabelFontSize=this.commitLabelFontSize||"10px",this.emUiFill=this.emUiFill||"white",this.emUiStroke=this.emUiStroke||"#dbdada",this.emProcessorFill=this.emProcessorFill||"#edb3f6",this.emProcessorStroke=this.emProcessorStroke||"#b88cbf",this.emReadModelFill=this.emReadModelFill||"#d3f1a2",this.emReadModelStroke=this.emReadModelStroke||"#a3b732",this.emCommandFill=this.emCommandFill||"#bcd6fe",this.emCommandStroke=this.emCommandStroke||"#679ac3",this.emEventFill=this.emEventFill||"#ffb778",this.emEventStroke=this.emEventStroke||"#c19a0f",this.emSwimlaneBackgroundOdd=this.emSwimlaneBackgroundOdd||"rgb(250,250,250)",this.emSwimlaneBackgroundStroke=this.emSwimlaneBackgroundStroke||"rgb(240,240,240)",this.emArrowhead=this.emArrowhead||this.lineColor,this.emRelationStroke=this.emRelationStroke||this.lineColor,this.attributeBackgroundColorOdd=this.attributeBackgroundColorOdd||Zr,this.attributeBackgroundColorEven=this.attributeBackgroundColorEven||ei}calculate(S){if(typeof S!=="object"){this.updateColors();return}let I=Object.keys(S);I.forEach(W=>{this[W]=S[W]}),this.updateColors(),I.forEach(W=>{this[W]=vr(this[W],S[W])})}}var WA=v=>{let S=new GA;return S.calculate(v),S};class UA{constructor(){this.primaryColor="#eee",this.contrast="#707070",this.secondaryColor=he(this.contrast,55),this.background="#ffffff",this.tertiaryColor=R(this.primaryColor,{h:-160}),this.primaryBorderColor=Ue(this.primaryColor,this.darkMode),this.secondaryBorderColor=Ue(this.secondaryColor,this.darkMode),this.tertiaryBorderColor=Ue(this.tertiaryColor,this.darkMode),this.primaryTextColor=oe(this.primaryColor),this.secondaryTextColor=oe(this.secondaryColor),this.tertiaryTextColor=oe(this.tertiaryColor),this.lineColor=oe(this.background),this.textColor=oe(this.background),this.mainBkg="#eee",this.secondBkg="calculated",this.lineColor="#666",this.border1="#999",this.border2="calculated",this.note="#ffa",this.text="#333",this.critical="#d42",this.done="#bbb",this.arrowheadColor="#333333",this.fontFamily='"trebuchet ms", verdana, arial, sans-serif',this.fontSize="16px",this.THEME_COLOR_LIMIT=12,this.radius=5,this.strokeWidth=1,this.nodeBkg="calculated",this.nodeBorder="calculated",this.clusterBkg="calculated",this.clusterBorder="calculated",this.defaultLinkColor="calculated",this.titleColor="calculated",this.edgeLabelBackground="white",this.actorBorder="calculated",this.actorBkg="calculated",this.actorTextColor="calculated",this.actorLineColor=this.actorBorder,this.signalColor="calculated",this.signalTextColor="calculated",this.labelBoxBkgColor="calculated",this.labelBoxBorderColor="calculated",this.labelTextColor="calculated",this.loopTextColor="calculated",this.noteBorderColor="calculated",this.noteBkgColor="calculated",this.noteTextColor="calculated",this.activationBorderColor="#666",this.activationBkgColor="#f4f4f4",this.sequenceNumberColor="white",this.sectionBkgColor="calculated",this.altSectionBkgColor="white",this.sectionBkgColor2="calculated",this.excludeBkgColor="#eeeeee",this.taskBorderColor="calculated",this.taskBkgColor="calculated",this.taskTextLightColor="white",this.taskTextColor="calculated",this.taskTextDarkColor="calculated",this.taskTextOutsideColor="calculated",this.taskTextClickableColor="#003163",this.activeTaskBorderColor="calculated",this.activeTaskBkgColor="calculated",this.gridColor="calculated",this.doneTaskBkgColor="calculated",this.doneTaskBorderColor="calculated",this.critBkgColor="calculated",this.critBorderColor="calculated",this.todayLineColor="calculated",this.vertLineColor="calculated",this.personBorder=this.primaryBorderColor,this.personBkg=this.mainBkg,this.archEdgeColor="calculated",this.archEdgeArrowColor="calculated",this.archEdgeWidth="3",this.archGroupBorderColor=this.primaryBorderColor,this.archGroupBorderWidth="2px",this.noteFontWeight="normal",this.fontWeight="normal",this.rowOdd=this.rowOdd||he(this.mainBkg,75)||"#ffffff",this.rowEven=this.rowEven||"#f4f4f4",this.labelColor="black",this.errorBkgColor="#552222",this.errorTextColor="#552222",this.useGradient=true,this.gradientStart=this.primaryBorderColor,this.gradientStop=this.secondaryBorderColor,this.dropShadow="drop-shadow( 1px 2px 2px rgba(185,185,185,1))"}updateColors(){this.secondBkg=he(this.contrast,55),this.border2=this.contrast,this.actorBorder=he(this.border1,23),this.actorBkg=this.mainBkg,this.actorTextColor=this.text,this.actorLineColor=this.actorBorder,this.rectBkgColor=this.rectBkgColor||this.tertiaryColor,this.signalColor=this.text,this.signalTextColor=this.text,this.labelBoxBkgColor=this.actorBkg,this.labelBoxBorderColor=this.actorBorder,this.labelTextColor=this.text,this.loopTextColor=this.text,this.noteBorderColor="#999",this.noteBkgColor="#666",this.noteTextColor="#fff",this.cScale0=this.cScale0||"#555",this.cScale1=this.cScale1||"#F4F4F4",this.cScale2=this.cScale2||"#555",this.cScale3=this.cScale3||"#BBB",this.cScale4=this.cScale4||"#777",this.cScale5=this.cScale5||"#999",this.cScale6=this.cScale6||"#DDD",this.cScale7=this.cScale7||"#FFF",this.cScale8=this.cScale8||"#DDD",this.cScale9=this.cScale9||"#BBB",this.cScale10=this.cScale10||"#999",this.cScale11=this.cScale11||"#777";for(let S=0;S<this.THEME_COLOR_LIMIT;S++){e();this["cScaleInv"+S]=this["cScaleInv"+S]||oe(this["cScale"+S])}for(let S=0;S<this.THEME_COLOR_LIMIT;S++){e();if(this.darkMode)this["cScalePeer"+S]=this["cScalePeer"+S]||he(this["cScale"+S],10);else this["cScalePeer"+S]=this["cScalePeer"+S]||me(this["cScale"+S],10)}this.scaleLabelColor=this.scaleLabelColor||(this.darkMode?"black":this.labelTextColor),this.cScaleLabel0=this.cScaleLabel0||this.cScale1,this.cScaleLabel2=this.cScaleLabel2||this.cScale1;for(let S=0;S<this.THEME_COLOR_LIMIT;S++){e();this["cScaleLabel"+S]=this["cScaleLabel"+S]||this.scaleLabelColor}for(let S=0;S<5;S++){e();this["surface"+S]=this["surface"+S]||R(this.mainBkg,{l:-(5+S*5)}),this["surfacePeer"+S]=this["surfacePeer"+S]||R(this.mainBkg,{l:-(8+S*5)})}this.nodeBkg=this.mainBkg,this.nodeBorder=this.border1,this.clusterBkg=this.secondBkg,this.clusterBorder=this.border2,this.defaultLinkColor=this.lineColor,this.titleColor=this.text,this.flowContainerStroke=this.flowContainerStroke||this.secondaryBorderColor,this.sectionBkgColor=he(this.contrast,30),this.sectionBkgColor2=he(this.contrast,30),this.taskBorderColor=me(this.contrast,10),this.taskBkgColor=this.contrast,this.taskTextColor=this.taskTextLightColor,this.taskTextDarkColor=this.text,this.taskTextOutsideColor=this.taskTextDarkColor,this.activeTaskBorderColor=this.taskBorderColor,this.activeTaskBkgColor=this.mainBkg,this.gridColor=he(this.border1,30),this.doneTaskBkgColor=this.done,this.doneTaskBorderColor=this.lineColor,this.critBkgColor=this.critical,this.critBorderColor=me(this.critBkgColor,10),this.todayLineColor=this.critBkgColor,this.vertLineColor=this.critBkgColor,this.archEdgeColor=this.lineColor,this.archEdgeArrowColor=this.lineColor,this.transitionColor=this.transitionColor||"#000",this.transitionLabelColor=this.transitionLabelColor||this.textColor,this.stateLabelColor=this.stateLabelColor||this.stateBkg||this.primaryTextColor,this.stateBkg=this.stateBkg||this.mainBkg,this.labelBackgroundColor=this.labelBackgroundColor||this.stateBkg,this.compositeBackground=this.compositeBackground||this.background||this.tertiaryColor,this.altBackground=this.altBackground||"#f4f4f4",this.compositeTitleBackground=this.compositeTitleBackground||this.mainBkg,this.stateBorder=this.stateBorder||"#000",this.innerEndBackground=this.primaryBorderColor,this.specialStateColor="#222",this.errorBkgColor=this.errorBkgColor||this.tertiaryColor,this.errorTextColor=this.errorTextColor||this.tertiaryTextColor,this.classText=this.primaryTextColor,this.fillType0=this.primaryColor,this.fillType1=this.secondaryColor,this.fillType2=R(this.primaryColor,{h:64}),this.fillType3=R(this.secondaryColor,{h:64}),this.fillType4=R(this.primaryColor,{h:-64}),this.fillType5=R(this.secondaryColor,{h:-64}),this.fillType6=R(this.primaryColor,{h:128}),this.fillType7=R(this.secondaryColor,{h:128});for(let S=0;S<this.THEME_COLOR_LIMIT;S++){e();this["pie"+S]=this["cScale"+S]}this.pie12=this.pie0,this.pieTitleTextSize=this.pieTitleTextSize||"25px",this.pieTitleTextColor=this.pieTitleTextColor||this.taskTextDarkColor,this.pieSectionTextSize=this.pieSectionTextSize||"17px",this.pieSectionTextColor=this.pieSectionTextColor||this.textColor,this.pieLegendTextSize=this.pieLegendTextSize||"17px",this.pieLegendTextColor=this.pieLegendTextColor||this.taskTextDarkColor,this.pieStrokeColor=this.pieStrokeColor||"black",this.pieStrokeWidth=this.pieStrokeWidth||"2px",this.pieOuterStrokeWidth=this.pieOuterStrokeWidth||"2px",this.pieOuterStrokeColor=this.pieOuterStrokeColor||"black",this.pieOpacity=this.pieOpacity||"0.7";for(let S=0;S<8;S++){e();this["venn"+(S+1)]=this["venn"+(S+1)]??this["cScale"+S]}this.vennTitleTextColor=this.vennTitleTextColor??this.titleColor,this.vennSetTextColor=this.vennSetTextColor??this.textColor,this.cynefin={domainFontSize:this.cynefin?.domainFontSize||16,itemFontSize:this.cynefin?.itemFontSize||12,boundaryColor:this.cynefin?.boundaryColor||this.lineColor,boundaryWidth:this.cynefin?.boundaryWidth||2,cliffColor:this.cynefin?.cliffColor||"#8B0000",cliffWidth:this.cynefin?.cliffWidth||4,arrowColor:this.cynefin?.arrowColor||this.lineColor,arrowWidth:this.cynefin?.arrowWidth||2,complexBg:this.cynefin?.complexBg||"#E8F5E9",complicatedBg:this.cynefin?.complicatedBg||"#E3F2FD",chaoticBg:this.cynefin?.chaoticBg||"#FBE9E7",clearBg:this.cynefin?.clearBg||"#FFF8E1",confusionBg:this.cynefin?.confusionBg||"#F3E5F5",textColor:this.cynefin?.textColor||this.textColor,labelColor:this.cynefin?.labelColor||this.primaryTextColor},this.quadrant1Fill=this.quadrant1Fill||this.primaryColor,this.quadrant2Fill=this.quadrant2Fill||R(this.primaryColor,{r:5,g:5,b:5}),this.quadrant3Fill=this.quadrant3Fill||R(this.primaryColor,{r:10,g:10,b:10}),this.quadrant4Fill=this.quadrant4Fill||R(this.primaryColor,{r:15,g:15,b:15}),this.quadrant1TextFill=this.quadrant1TextFill||this.primaryTextColor,this.quadrant2TextFill=this.quadrant2TextFill||R(this.primaryTextColor,{r:-5,g:-5,b:-5}),this.quadrant3TextFill=this.quadrant3TextFill||R(this.primaryTextColor,{r:-10,g:-10,b:-10}),this.quadrant4TextFill=this.quadrant4TextFill||R(this.primaryTextColor,{r:-15,g:-15,b:-15}),this.quadrantPointFill=this.quadrantPointFill||tr(this.quadrant1Fill)?he(this.quadrant1Fill):me(this.quadrant1Fill),this.quadrantPointTextFill=this.quadrantPointTextFill||this.primaryTextColor,this.quadrantXAxisTextFill=this.quadrantXAxisTextFill||this.primaryTextColor,this.quadrantYAxisTextFill=this.quadrantYAxisTextFill||this.primaryTextColor,this.quadrantInternalBorderStrokeFill=this.quadrantInternalBorderStrokeFill||this.primaryBorderColor,this.quadrantExternalBorderStrokeFill=this.quadrantExternalBorderStrokeFill||this.primaryBorderColor,this.quadrantTitleFill=this.quadrantTitleFill||this.primaryTextColor,this.xyChart={backgroundColor:this.xyChart?.backgroundColor||this.background,titleColor:this.xyChart?.titleColor||this.primaryTextColor,dataLabelColor:this.xyChart?.dataLabelColor||this.primaryTextColor,legendTextColor:this.xyChart?.legendTextColor||this.primaryTextColor,xAxisTitleColor:this.xyChart?.xAxisTitleColor||this.primaryTextColor,xAxisLabelColor:this.xyChart?.xAxisLabelColor||this.primaryTextColor,xAxisTickColor:this.xyChart?.xAxisTickColor||this.primaryTextColor,xAxisLineColor:this.xyChart?.xAxisLineColor||this.primaryTextColor,yAxisTitleColor:this.xyChart?.yAxisTitleColor||this.primaryTextColor,yAxisLabelColor:this.xyChart?.yAxisLabelColor||this.primaryTextColor,yAxisTickColor:this.xyChart?.yAxisTickColor||this.primaryTextColor,yAxisLineColor:this.xyChart?.yAxisLineColor||this.primaryTextColor,plotColorPalette:this.xyChart?.plotColorPalette||"#EEE,#6BB8E4,#8ACB88,#C7ACD6,#E8DCC2,#FFB2A8,#FFF380,#7E8D91,#FFD8B1,#FAF3E0"},this.radar={axisColor:this.radar?.axisColor||this.lineColor,axisStrokeWidth:this.radar?.axisStrokeWidth||2,axisLabelFontSize:this.radar?.axisLabelFontSize||12,curveOpacity:this.radar?.curveOpacity||.5,curveStrokeWidth:this.radar?.curveStrokeWidth||2,graticuleColor:this.radar?.graticuleColor||"#DEDEDE",graticuleStrokeWidth:this.radar?.graticuleStrokeWidth||1,graticuleOpacity:this.radar?.graticuleOpacity||.3,legendBoxSize:this.radar?.legendBoxSize||12,legendFontSize:this.radar?.legendFontSize||12},this.wardleyEvolutionColor=this.wardleyEvolutionColor||"#dc3545",this.wardley={backgroundColor:this.wardley?.backgroundColor||this.background,axisColor:this.wardley?.axisColor||this.lineColor,axisTextColor:this.wardley?.axisTextColor||this.primaryTextColor,gridColor:this.wardley?.gridColor||this.gridColor,componentFill:this.wardley?.componentFill||this.background,componentStroke:this.wardley?.componentStroke||this.lineColor,componentLabelColor:this.wardley?.componentLabelColor||this.primaryTextColor,linkStroke:this.wardley?.linkStroke||this.lineColor,evolutionStroke:this.wardley?.evolutionStroke||this.wardleyEvolutionColor,annotationStroke:this.wardley?.annotationStroke||this.lineColor,annotationTextColor:this.wardley?.annotationTextColor||this.primaryTextColor,annotationFill:this.wardley?.annotationFill||this.background},this.requirementBackground=this.requirementBackground||this.primaryColor,this.requirementBorderColor=this.requirementBorderColor||this.primaryBorderColor,this.requirementBorderSize=this.requirementBorderSize||"1",this.requirementTextColor=this.requirementTextColor||this.primaryTextColor,this.relationColor=this.relationColor||this.lineColor,this.relationLabelBackground=this.relationLabelBackground||this.edgeLabelBackground,this.relationLabelColor=this.relationLabelColor||this.actorTextColor,this.git0=me(this.pie1,25)||this.primaryColor,this.git1=this.pie2||this.secondaryColor,this.git2=this.pie3||this.tertiaryColor,this.git3=this.pie4||R(this.primaryColor,{h:-30}),this.git4=this.pie5||R(this.primaryColor,{h:-60}),this.git5=this.pie6||R(this.primaryColor,{h:-90}),this.git6=this.pie7||R(this.primaryColor,{h:60}),this.git7=this.pie8||R(this.primaryColor,{h:120}),this.gitInv0=this.gitInv0||oe(this.git0),this.gitInv1=this.gitInv1||oe(this.git1),this.gitInv2=this.gitInv2||oe(this.git2),this.gitInv3=this.gitInv3||oe(this.git3),this.gitInv4=this.gitInv4||oe(this.git4),this.gitInv5=this.gitInv5||oe(this.git5),this.gitInv6=this.gitInv6||oe(this.git6),this.gitInv7=this.gitInv7||oe(this.git7),this.branchLabelColor=this.branchLabelColor||this.labelTextColor,this.gitBranchLabel0=this.branchLabelColor,this.gitBranchLabel1="white",this.gitBranchLabel2=this.branchLabelColor,this.gitBranchLabel3="white",this.gitBranchLabel4=this.branchLabelColor,this.gitBranchLabel5=this.branchLabelColor,this.gitBranchLabel6=this.branchLabelColor,this.gitBranchLabel7=this.branchLabelColor,this.tagLabelColor=this.tagLabelColor||this.primaryTextColor,this.tagLabelBackground=this.tagLabelBackground||this.primaryColor,this.tagLabelBorder=this.tagBorder||this.primaryBorderColor,this.tagLabelFontSize=this.tagLabelFontSize||"10px",this.commitLabelColor=this.commitLabelColor||this.secondaryTextColor,this.commitLabelBackground=this.commitLabelBackground||this.secondaryColor,this.commitLabelFontSize=this.commitLabelFontSize||"10px",this.emUiFill=this.emUiFill||"white",this.emUiStroke=this.emUiStroke||"#dbdada",this.emProcessorFill=this.emProcessorFill||"#edb3f6",this.emProcessorStroke=this.emProcessorStroke||"#b88cbf",this.emReadModelFill=this.emReadModelFill||"#d3f1a2",this.emReadModelStroke=this.emReadModelStroke||"#a3b732",this.emCommandFill=this.emCommandFill||"#bcd6fe",this.emCommandStroke=this.emCommandStroke||"#679ac3",this.emEventFill=this.emEventFill||"#ffb778",this.emEventStroke=this.emEventStroke||"#c19a0f",this.emSwimlaneBackgroundOdd=this.emSwimlaneBackgroundOdd||"rgb(250,250,250)",this.emSwimlaneBackgroundStroke=this.emSwimlaneBackgroundStroke||"rgb(240,240,240)",this.emArrowhead=this.emArrowhead||this.lineColor,this.emRelationStroke=this.emRelationStroke||this.lineColor,this.attributeBackgroundColorOdd=this.attributeBackgroundColorOdd||Zr,this.attributeBackgroundColorEven=this.attributeBackgroundColorEven||ei}calculate(S){if(typeof S!=="object"){this.updateColors();return}let I=Object.keys(S);I.forEach(W=>{this[W]=S[W]}),this.updateColors(),I.forEach(W=>{this[W]=vr(this[W],S[W])})}}var jA=v=>{let S=new UA;return S.calculate(v),S};class VA{constructor(){this.background="#ffffff",this.primaryColor="#cccccc",this.mainBkg="#ffffff",this.noteBkgColor="#fff5ad",this.noteTextColor="#333",this.THEME_COLOR_LIMIT=12,this.radius=3,this.strokeWidth=2,this.primaryBorderColor=Ue(this.primaryColor,this.darkMode),this.fontFamily="arial, sans-serif",this.fontSize="14px",this.nodeBorder="#000000",this.stateBorder="#000000",this.useGradient=true,this.gradientStart="#0042eb",this.gradientStop="#eb0042",this.dropShadow="drop-shadow( 0px 1px 2px rgba(0, 0, 0, 0.25));",this.tertiaryColor="#ffffff",this.archEdgeColor="calculated",this.archEdgeArrowColor="calculated",this.archEdgeWidth="3",this.archGroupBorderColor=this.primaryBorderColor,this.archGroupBorderWidth="2px",this.noteFontWeight="normal",this.fontWeight="normal"}updateColors(){this.primaryTextColor=this.primaryTextColor||(this.darkMode?"#eee":"#333"),this.secondaryColor=this.secondaryColor||R(this.primaryColor,{h:-120}),this.tertiaryColor=this.tertiaryColor||R(this.primaryColor,{h:180,l:5}),this.primaryBorderColor=this.primaryBorderColor||Ue(this.primaryColor,this.darkMode),this.secondaryBorderColor=this.secondaryBorderColor||Ue(this.secondaryColor,this.darkMode),this.tertiaryBorderColor=this.tertiaryBorderColor||Ue(this.tertiaryColor,this.darkMode),this.noteBorderColor=this.noteBorderColor||Ue(this.noteBkgColor,this.darkMode),this.noteBkgColor=this.noteBkgColor||"#fff5ad",this.noteTextColor=this.noteTextColor||"#333",this.secondaryTextColor=this.secondaryTextColor||oe(this.secondaryColor),this.tertiaryTextColor=this.tertiaryTextColor||oe(this.tertiaryColor),this.lineColor=this.lineColor||oe(this.background),this.arrowheadColor=this.arrowheadColor||oe(this.background),this.textColor=this.textColor||this.primaryTextColor,this.border2=this.border2||this.tertiaryBorderColor,this.nodeBkg=this.nodeBkg||this.primaryColor,this.mainBkg=this.mainBkg||this.primaryColor,this.nodeBorder=this.nodeBorder||this.primaryBorderColor,this.clusterBkg=this.clusterBkg||this.tertiaryColor,this.clusterBorder=this.clusterBorder||this.tertiaryBorderColor,this.defaultLinkColor=this.defaultLinkColor||this.lineColor,this.titleColor=this.titleColor||this.tertiaryTextColor,this.edgeLabelBackground=this.edgeLabelBackground||(this.darkMode?me(this.secondaryColor,30):this.secondaryColor),this.nodeTextColor=this.nodeTextColor||this.primaryTextColor,this.flowContainerStroke=this.flowContainerStroke||this.secondaryBorderColor,this.actorBorder=this.actorBorder||this.primaryBorderColor,this.actorBkg=this.actorBkg||this.mainBkg,this.actorTextColor=this.actorTextColor||this.primaryTextColor,this.actorLineColor=this.actorLineColor||this.actorBorder,this.labelBoxBkgColor=this.labelBoxBkgColor||this.actorBkg,this.signalColor=this.signalColor||this.textColor,this.signalTextColor=this.signalTextColor||this.textColor,this.labelBoxBorderColor=this.labelBoxBorderColor||this.actorBorder,this.labelTextColor=this.labelTextColor||this.actorTextColor,this.loopTextColor=this.loopTextColor||this.actorTextColor,this.activationBorderColor=this.activationBorderColor||me(this.secondaryColor,10),this.activationBkgColor=this.activationBkgColor||this.secondaryColor,this.sequenceNumberColor=this.sequenceNumberColor||oe(this.lineColor),this.rectBkgColor=this.rectBkgColor||(tr(this.background)?he(this.background,4):me(this.background,4));let S="#ECECFE",I="#E9E9F1",W=R(S,{h:180,l:5});if(this.sectionBkgColor=this.sectionBkgColor||W,this.altSectionBkgColor=this.altSectionBkgColor||"white",this.sectionBkgColor=this.sectionBkgColor||I,this.sectionBkgColor2=this.sectionBkgColor2||S,this.excludeBkgColor=this.excludeBkgColor||"#eeeeee",this.taskBorderColor=this.taskBorderColor||this.primaryBorderColor,this.taskBkgColor=this.taskBkgColor||S,this.activeTaskBorderColor=this.activeTaskBorderColor||S,this.activeTaskBkgColor=this.activeTaskBkgColor||he(S,23),this.gridColor=this.gridColor||"lightgrey",this.doneTaskBkgColor=this.doneTaskBkgColor||"lightgrey",this.doneTaskBorderColor=this.doneTaskBorderColor||"grey",this.critBorderColor=this.critBorderColor||"#ff8888",this.critBkgColor=this.critBkgColor||"red",this.todayLineColor=this.todayLineColor||"red",this.taskTextColor=this.taskTextColor||this.textColor,this.taskTextOutsideColor=this.taskTextOutsideColor||this.textColor,this.vertLineColor=this.vertLineColor||this.primaryBorderColor,this.taskTextLightColor=this.taskTextLightColor||this.textColor,this.taskTextColor=this.taskTextColor||this.primaryTextColor,this.taskTextDarkColor=this.taskTextDarkColor||this.textColor,this.taskTextClickableColor=this.taskTextClickableColor||"#003163",this.archEdgeColor=this.lineColor,this.archEdgeArrowColor=this.lineColor,this.personBorder=this.personBorder||this.primaryBorderColor,this.personBkg=this.personBkg||this.mainBkg,this.transitionColor=this.transitionColor||this.lineColor,this.transitionLabelColor=this.transitionLabelColor||this.textColor,this.stateLabelColor=this.stateLabelColor||this.stateBkg||this.primaryTextColor,this.stateBkg=this.stateBkg||this.mainBkg,this.labelBackgroundColor=this.labelBackgroundColor||this.stateBkg,this.compositeBackground=this.compositeBackground||this.background||this.tertiaryColor,this.altBackground=this.altBackground||"#f0f0f0",this.compositeTitleBackground=this.compositeTitleBackground||this.mainBkg,this.compositeBorder=this.compositeBorder||this.nodeBorder,this.innerEndBackground=this.nodeBorder,this.errorBkgColor=this.errorBkgColor||this.tertiaryColor,this.errorTextColor=this.errorTextColor||this.tertiaryTextColor,this.transitionColor=this.transitionColor||this.lineColor,this.specialStateColor=this.lineColor,this.cScale0=this.cScale0||S,this.cScale1=this.cScale1||I,this.cScale2=this.cScale2||W,this.cScale3=this.cScale3||R(S,{h:30}),this.cScale4=this.cScale4||R(S,{h:60}),this.cScale5=this.cScale5||R(S,{h:90}),this.cScale6=this.cScale6||R(S,{h:120}),this.cScale7=this.cScale7||R(S,{h:150}),this.cScale8=this.cScale8||R(S,{h:210,l:150}),this.cScale9=this.cScale9||R(S,{h:270}),this.cScale10=this.cScale10||R(S,{h:300}),this.cScale11=this.cScale11||R(S,{h:330}),this.darkMode)for(let te=0;te<this.THEME_COLOR_LIMIT;te++){e();this["cScale"+te]=me(this["cScale"+te],75)}else for(let te=0;te<this.THEME_COLOR_LIMIT;te++){e();this["cScale"+te]=me(this["cScale"+te],25)}for(let te=0;te<this.THEME_COLOR_LIMIT;te++){e();this["cScaleInv"+te]=this["cScaleInv"+te]||oe(this["cScale"+te])}for(let te=0;te<this.THEME_COLOR_LIMIT;te++){e();if(this.darkMode)this["cScalePeer"+te]=this["cScalePeer"+te]||he(this["cScale"+te],10);else this["cScalePeer"+te]=this["cScalePeer"+te]||me(this["cScale"+te],10)}this.scaleLabelColor=this.scaleLabelColor||this.labelTextColor;for(let te=0;te<this.THEME_COLOR_LIMIT;te++){e();this["cScaleLabel"+te]=this["cScaleLabel"+te]||this.scaleLabelColor}let ye=this.darkMode?-4:-1;for(let te=0;te<5;te++){e();this["surface"+te]=this["surface"+te]||R(this.mainBkg,{h:180,s:-15,l:ye*(5+te*3)}),this["surfacePeer"+te]=this["surfacePeer"+te]||R(this.mainBkg,{h:180,s:-15,l:ye*(8+te*3)})}if(this.classText=this.classText||this.textColor,this.fillType0=this.fillType0||S,this.fillType1=this.fillType1||I,this.fillType2=this.fillType2||R(S,{h:64}),this.fillType3=this.fillType3||R(I,{h:64}),this.fillType4=this.fillType4||R(S,{h:-64}),this.fillType5=this.fillType5||R(I,{h:-64}),this.fillType6=this.fillType6||R(S,{h:128}),this.fillType7=this.fillType7||R(I,{h:128}),this.pie1=this.pie1||S,this.pie2=this.pie2||I,this.pie3=this.pie3||W,this.pie4=this.pie4||R(S,{l:-10}),this.pie5=this.pie5||R(I,{l:-10}),this.pie6=this.pie6||R(W,{l:-10}),this.pie7=this.pie7||R(S,{h:60,l:-10}),this.pie8=this.pie8||R(S,{h:-60,l:-10}),this.pie9=this.pie9||R(S,{h:120,l:0}),this.pie10=this.pie10||R(S,{h:60,l:-20}),this.pie11=this.pie11||R(S,{h:-60,l:-20}),this.pie12=this.pie12||R(S,{h:120,l:-10}),this.pieTitleTextSize=this.pieTitleTextSize||"25px",this.pieTitleTextColor=this.pieTitleTextColor||this.taskTextDarkColor,this.pieSectionTextSize=this.pieSectionTextSize||"17px",this.pieSectionTextColor=this.pieSectionTextColor||this.textColor,this.pieLegendTextSize=this.pieLegendTextSize||"17px",this.pieLegendTextColor=this.pieLegendTextColor||this.taskTextDarkColor,this.pieStrokeColor=this.pieStrokeColor||"black",this.pieStrokeWidth=this.pieStrokeWidth||"2px",this.pieOuterStrokeWidth=this.pieOuterStrokeWidth||"2px",this.pieOuterStrokeColor=this.pieOuterStrokeColor||"black",this.pieOpacity=this.pieOpacity||"0.7",this.vennTitleTextColor=this.vennTitleTextColor??this.titleColor,this.vennSetTextColor=this.vennSetTextColor??this.textColor,this.quadrant1Fill=this.quadrant1Fill||S,this.quadrant2Fill=this.quadrant2Fill||R(S,{r:5,g:5,b:5}),this.quadrant3Fill=this.quadrant3Fill||R(S,{r:10,g:10,b:10}),this.quadrant4Fill=this.quadrant4Fill||R(S,{r:15,g:15,b:15}),this.quadrant1TextFill=this.quadrant1TextFill||this.primaryTextColor,this.quadrant2TextFill=this.quadrant2TextFill||R(this.primaryTextColor,{r:-5,g:-5,b:-5}),this.quadrant3TextFill=this.quadrant3TextFill||R(this.primaryTextColor,{r:-10,g:-10,b:-10}),this.quadrant4TextFill=this.quadrant4TextFill||R(this.primaryTextColor,{r:-15,g:-15,b:-15}),this.quadrantPointFill=this.quadrantPointFill||tr(this.quadrant1Fill)?he(this.quadrant1Fill):me(this.quadrant1Fill),this.quadrantPointTextFill=this.quadrantPointTextFill||this.primaryTextColor,this.quadrantXAxisTextFill=this.quadrantXAxisTextFill||this.primaryTextColor,this.quadrantYAxisTextFill=this.quadrantYAxisTextFill||this.primaryTextColor,this.quadrantInternalBorderStrokeFill=this.quadrantInternalBorderStrokeFill||this.primaryBorderColor,this.quadrantExternalBorderStrokeFill=this.quadrantExternalBorderStrokeFill||this.primaryBorderColor,this.quadrantTitleFill=this.quadrantTitleFill||this.primaryTextColor,this.xyChart={backgroundColor:this.xyChart?.backgroundColor||this.background,titleColor:this.xyChart?.titleColor||this.primaryTextColor,legendTextColor:this.xyChart?.legendTextColor||this.primaryTextColor,xAxisTitleColor:this.xyChart?.xAxisTitleColor||this.primaryTextColor,xAxisLabelColor:this.xyChart?.xAxisLabelColor||this.primaryTextColor,xAxisTickColor:this.xyChart?.xAxisTickColor||this.primaryTextColor,xAxisLineColor:this.xyChart?.xAxisLineColor||this.primaryTextColor,yAxisTitleColor:this.xyChart?.yAxisTitleColor||this.primaryTextColor,yAxisLabelColor:this.xyChart?.yAxisLabelColor||this.primaryTextColor,yAxisTickColor:this.xyChart?.yAxisTickColor||this.primaryTextColor,yAxisLineColor:this.xyChart?.yAxisLineColor||this.primaryTextColor,plotColorPalette:this.xyChart?.plotColorPalette||"#FFF4DD,#FFD8B1,#FFA07A,#ECEFF1,#D6DBDF,#C3E0A8,#FFB6A4,#FFD74D,#738FA7,#FFFFF0"},this.requirementBackground=this.requirementBackground||S,this.requirementBorderColor=this.requirementBorderColor||this.primaryBorderColor,this.requirementBorderSize=this.requirementBorderSize||"1",this.requirementTextColor=this.requirementTextColor||this.primaryTextColor,this.relationColor=this.relationColor||this.lineColor,this.relationLabelBackground=this.relationLabelBackground||(this.darkMode?me(this.secondaryColor,30):this.secondaryColor),this.relationLabelColor=this.relationLabelColor||this.actorTextColor,this.git0=this.git0||S,this.git1=this.git1||I,this.git2=this.git2||W,this.git3=this.git3||R(S,{h:-30}),this.git4=this.git4||R(S,{h:-60}),this.git5=this.git5||R(S,{h:-90}),this.git6=this.git6||R(S,{h:60}),this.git7=this.git7||R(S,{h:120}),this.darkMode)this.git0=he(this.git0,25),this.git1=he(this.git1,25),this.git2=he(this.git2,25),this.git3=he(this.git3,25),this.git4=he(this.git4,25),this.git5=he(this.git5,25),this.git6=he(this.git6,25),this.git7=he(this.git7,25);else this.git0=me(this.git0,25),this.git1=me(this.git1,25),this.git2=me(this.git2,25),this.git3=me(this.git3,25),this.git4=me(this.git4,25),this.git5=me(this.git5,25),this.git6=me(this.git6,25),this.git7=me(this.git7,25);this.gitInv0=this.gitInv0||oe(this.git0),this.gitInv1=this.gitInv1||oe(this.git1),this.gitInv2=this.gitInv2||oe(this.git2),this.gitInv3=this.gitInv3||oe(this.git3),this.gitInv4=this.gitInv4||oe(this.git4),this.gitInv5=this.gitInv5||oe(this.git5),this.gitInv6=this.gitInv6||oe(this.git6),this.gitInv7=this.gitInv7||oe(this.git7),this.branchLabelColor=this.branchLabelColor||(this.darkMode?"black":this.labelTextColor),this.gitBranchLabel0=this.gitBranchLabel0||this.branchLabelColor,this.gitBranchLabel1=this.gitBranchLabel1||this.branchLabelColor,this.gitBranchLabel2=this.gitBranchLabel2||this.branchLabelColor,this.gitBranchLabel3=this.gitBranchLabel3||this.branchLabelColor,this.gitBranchLabel4=this.gitBranchLabel4||this.branchLabelColor,this.gitBranchLabel5=this.gitBranchLabel5||this.branchLabelColor,this.gitBranchLabel6=this.gitBranchLabel6||this.branchLabelColor,this.gitBranchLabel7=this.gitBranchLabel7||this.branchLabelColor,this.tagLabelColor=this.tagLabelColor||this.primaryTextColor,this.tagLabelBackground=this.tagLabelBackground||this.primaryColor,this.tagLabelBorder=this.tagBorder||this.primaryBorderColor,this.tagLabelFontSize=this.tagLabelFontSize||"10px",this.commitLabelColor=this.commitLabelColor||this.secondaryTextColor,this.commitLabelBackground=this.commitLabelBackground||this.secondaryColor,this.commitLabelFontSize=this.commitLabelFontSize||"10px",this.attributeBackgroundColorOdd=this.attributeBackgroundColorOdd||Zr,this.attributeBackgroundColorEven=this.attributeBackgroundColorEven||ei}calculate(S){if(typeof S!=="object"){this.updateColors();return}let I=Object.keys(S);I.forEach(W=>{this[W]=S[W]}),this.updateColors(),I.forEach(W=>{this[W]=vr(this[W],S[W])})}}var YA=v=>{let S=new VA;return S.calculate(v),S};class HA{constructor(){this.background="#333",this.primaryColor="#1f2020",this.secondaryColor=he(this.primaryColor,16),this.tertiaryColor=R(this.primaryColor,{h:-160}),this.primaryBorderColor=oe(this.background),this.secondaryBorderColor=Ue(this.secondaryColor,this.darkMode),this.tertiaryBorderColor=Ue(this.tertiaryColor,this.darkMode),this.primaryTextColor=oe(this.primaryColor),this.secondaryTextColor=oe(this.secondaryColor),this.tertiaryTextColor=oe(this.tertiaryColor),this.mainBkg="#2a2020",this.secondBkg="calculated",this.mainContrastColor="lightgrey",this.darkTextColor=he(oe("#323D47"),10),this.border1="#ccc",this.border2=fr(255,255,255,.25),this.arrowheadColor=oe(this.background),this.fontFamily="arial, sans-serif",this.fontSize="14px",this.labelBackground="#181818",this.textColor="#ccc",this.THEME_COLOR_LIMIT=12,this.radius=3,this.strokeWidth=1,this.noteBkgColor="#fff5ad",this.noteTextColor="#333",this.THEME_COLOR_LIMIT=12,this.fontFamily="arial, sans-serif",this.fontSize="14px",this.useGradient=true,this.gradientStart="#0042eb",this.gradientStop="#eb0042",this.dropShadow="drop-shadow( 1px 2px 2px rgba(185,185,185,0.2))",this.archEdgeColor="calculated",this.archEdgeArrowColor="calculated",this.archEdgeWidth="3",this.archGroupBorderColor=this.primaryBorderColor,this.archGroupBorderWidth="2px",this.noteFontWeight="normal",this.fontWeight="normal"}updateColors(){if(this.primaryTextColor=this.primaryTextColor||(this.darkMode?"#eee":"#333"),this.secondaryColor=this.secondaryColor||R(this.primaryColor,{h:-120}),this.tertiaryColor=this.tertiaryColor||R(this.primaryColor,{h:180,l:5}),this.primaryBorderColor=this.primaryBorderColor||Ue(this.primaryColor,this.darkMode),this.secondaryBorderColor=this.secondaryBorderColor||Ue(this.secondaryColor,this.darkMode),this.tertiaryBorderColor=this.tertiaryBorderColor||Ue(this.tertiaryColor,this.darkMode),this.noteBorderColor=this.noteBorderColor||Ue(this.noteBkgColor,this.darkMode),this.noteBkgColor=this.noteBkgColor||"#fff5ad",this.noteTextColor=this.noteTextColor||"#333",this.secondaryTextColor=this.secondaryTextColor||oe(this.secondaryColor),this.tertiaryTextColor=this.tertiaryTextColor||oe(this.tertiaryColor),this.lineColor=this.lineColor||oe(this.background),this.arrowheadColor=this.arrowheadColor||oe(this.background),this.textColor=this.textColor||this.primaryTextColor,this.border2=this.border2||this.tertiaryBorderColor,this.nodeBkg=this.nodeBkg||this.primaryColor,this.mainBkg=this.mainBkg||this.primaryColor,this.secondBkg=this.secondBkg==="calculated"?he(this.mainBkg,16):this.secondBkg,this.nodeBorder=this.nodeBorder||this.border1,this.clusterBkg=this.clusterBkg||this.tertiaryColor,this.clusterBorder=this.clusterBorder||this.tertiaryBorderColor,this.defaultLinkColor=this.defaultLinkColor||this.lineColor,this.titleColor=this.titleColor||this.tertiaryTextColor,this.edgeLabelBackground=this.edgeLabelBackground||(this.darkMode?me(this.secondaryColor,30):this.secondaryColor),this.nodeTextColor=this.nodeTextColor||this.primaryTextColor,this.flowContainerStroke=this.flowContainerStroke||this.secondaryBorderColor,this.actorBorder=this.actorBorder||this.primaryBorderColor,this.actorBkg=this.actorBkg||this.mainBkg,this.actorTextColor=this.actorTextColor||this.primaryTextColor,this.actorLineColor=this.actorLineColor||this.actorBorder,this.labelBoxBkgColor=this.labelBoxBkgColor||this.actorBkg,this.signalColor=this.signalColor||this.textColor,this.signalTextColor=this.signalTextColor||this.textColor,this.labelBoxBorderColor=this.labelBoxBorderColor||this.actorBorder,this.labelTextColor=this.labelTextColor||this.actorTextColor,this.loopTextColor=this.loopTextColor||this.actorTextColor,this.activationBorderColor=this.activationBorderColor||me(this.secondaryColor,10),this.activationBkgColor=this.activationBkgColor||this.secondaryColor,this.sequenceNumberColor=this.sequenceNumberColor||oe(this.lineColor),this.rectBkgColor=this.rectBkgColor||this.tertiaryColor,this.sectionBkgColor=this.sectionBkgColor||this.tertiaryColor,this.altSectionBkgColor=this.altSectionBkgColor||"white",this.sectionBkgColor=this.sectionBkgColor||this.secondaryColor,this.sectionBkgColor2=this.sectionBkgColor2||this.primaryColor,this.excludeBkgColor=this.excludeBkgColor||"#eeeeee",this.taskBorderColor=this.taskBorderColor||this.primaryBorderColor,this.taskBkgColor=this.taskBkgColor||this.primaryColor,this.activeTaskBorderColor=this.activeTaskBorderColor||this.primaryColor,this.activeTaskBkgColor=this.activeTaskBkgColor||he(this.primaryColor,23),this.gridColor=this.gridColor||"lightgrey",this.doneTaskBkgColor=this.doneTaskBkgColor||this.secondBkg,this.doneTaskBorderColor=this.doneTaskBorderColor||"grey",this.critBorderColor=this.critBorderColor||"#ff8888",this.critBkgColor=this.critBkgColor||"red",this.todayLineColor=this.todayLineColor||"red",this.vertLineColor=this.vertLineColor||this.primaryBorderColor,this.taskTextColor=this.taskTextColor||this.textColor,this.taskTextOutsideColor=this.taskTextOutsideColor||this.textColor,this.taskTextLightColor=this.taskTextLightColor||this.textColor,this.taskTextColor=this.taskTextColor||this.primaryTextColor,this.taskTextDarkColor=this.taskTextDarkColor||this.textColor,this.taskTextClickableColor=this.taskTextClickableColor||"#003163",this.archEdgeColor=this.lineColor,this.archEdgeArrowColor=this.lineColor,this.personBorder=this.personBorder||this.primaryBorderColor,this.personBkg=this.personBkg||this.mainBkg,this.transitionColor=this.transitionColor||this.lineColor,this.transitionLabelColor=this.transitionLabelColor||this.textColor,this.stateLabelColor=this.stateLabelColor||this.stateBkg||this.primaryTextColor,this.stateBkg=this.stateBkg||this.mainBkg,this.labelBackgroundColor=this.labelBackgroundColor||this.stateBkg,this.compositeBackground=this.compositeBackground||this.background||this.tertiaryColor,this.altBackground=this.altBackground||"#f0f0f0",this.compositeTitleBackground=this.compositeTitleBackground||this.mainBkg,this.compositeBorder=this.compositeBorder||this.nodeBorder,this.innerEndBackground=this.nodeBorder,this.errorBkgColor=this.errorBkgColor||this.tertiaryColor,this.errorTextColor=this.errorTextColor||this.tertiaryTextColor,this.transitionColor=this.transitionColor||this.lineColor,this.specialStateColor=this.lineColor,this.cScale0=this.cScale0||this.primaryColor,this.cScale1=this.cScale1||this.secondaryColor,this.cScale2=this.cScale2||this.tertiaryColor,this.cScale3=this.cScale3||R(this.primaryColor,{h:30}),this.cScale4=this.cScale4||R(this.primaryColor,{h:60}),this.cScale5=this.cScale5||R(this.primaryColor,{h:90}),this.cScale6=this.cScale6||R(this.primaryColor,{h:120}),this.cScale7=this.cScale7||R(this.primaryColor,{h:150}),this.cScale8=this.cScale8||R(this.primaryColor,{h:210,l:150}),this.cScale9=this.cScale9||R(this.primaryColor,{h:270}),this.cScale10=this.cScale10||R(this.primaryColor,{h:300}),this.cScale11=this.cScale11||R(this.primaryColor,{h:330}),this.darkMode)for(let I=0;I<this.THEME_COLOR_LIMIT;I++){e();this["cScale"+I]=me(this["cScale"+I],75)}else for(let I=0;I<this.THEME_COLOR_LIMIT;I++){e();this["cScale"+I]=me(this["cScale"+I],25)}for(let I=0;I<this.THEME_COLOR_LIMIT;I++){e();this["cScaleInv"+I]=this["cScaleInv"+I]||oe(this["cScale"+I])}for(let I=0;I<this.THEME_COLOR_LIMIT;I++){e();if(this.darkMode)this["cScalePeer"+I]=this["cScalePeer"+I]||he(this["cScale"+I],10);else this["cScalePeer"+I]=this["cScalePeer"+I]||me(this["cScale"+I],10)}this.scaleLabelColor=this.scaleLabelColor||this.labelTextColor;for(let I=0;I<this.THEME_COLOR_LIMIT;I++){e();this["cScaleLabel"+I]=this["cScaleLabel"+I]||this.scaleLabelColor}let S=this.darkMode?-4:-1;for(let I=0;I<5;I++){e();this["surface"+I]=this["surface"+I]||R(this.mainBkg,{h:180,s:-15,l:S*(5+I*3)}),this["surfacePeer"+I]=this["surfacePeer"+I]||R(this.mainBkg,{h:180,s:-15,l:S*(8+I*3)})}if(this.classText=this.classText||this.textColor,this.fillType0=this.fillType0||this.primaryColor,this.fillType1=this.fillType1||this.secondaryColor,this.fillType2=this.fillType2||R(this.primaryColor,{h:64}),this.fillType3=this.fillType3||R(this.secondaryColor,{h:64}),this.fillType4=this.fillType4||R(this.primaryColor,{h:-64}),this.fillType5=this.fillType5||R(this.secondaryColor,{h:-64}),this.fillType6=this.fillType6||R(this.primaryColor,{h:128}),this.fillType7=this.fillType7||R(this.secondaryColor,{h:128}),this.pie1=this.pie1||this.primaryColor,this.pie2=this.pie2||this.secondaryColor,this.pie3=this.pie3||this.tertiaryColor,this.pie4=this.pie4||R(this.primaryColor,{l:-10}),this.pie5=this.pie5||R(this.secondaryColor,{l:-10}),this.pie6=this.pie6||R(this.tertiaryColor,{l:-10}),this.pie7=this.pie7||R(this.primaryColor,{h:60,l:-10}),this.pie8=this.pie8||R(this.primaryColor,{h:-60,l:-10}),this.pie9=this.pie9||R(this.primaryColor,{h:120,l:0}),this.pie10=this.pie10||R(this.primaryColor,{h:60,l:-20}),this.pie11=this.pie11||R(this.primaryColor,{h:-60,l:-20}),this.pie12=this.pie12||R(this.primaryColor,{h:120,l:-10}),this.pieTitleTextSize=this.pieTitleTextSize||"25px",this.pieTitleTextColor=this.pieTitleTextColor||this.taskTextDarkColor,this.pieSectionTextSize=this.pieSectionTextSize||"17px",this.pieSectionTextColor=this.pieSectionTextColor||this.textColor,this.pieLegendTextSize=this.pieLegendTextSize||"17px",this.pieLegendTextColor=this.pieLegendTextColor||this.taskTextDarkColor,this.pieStrokeColor=this.pieStrokeColor||"black",this.pieStrokeWidth=this.pieStrokeWidth||"2px",this.pieOuterStrokeWidth=this.pieOuterStrokeWidth||"2px",this.pieOuterStrokeColor=this.pieOuterStrokeColor||"black",this.pieOpacity=this.pieOpacity||"0.7",this.vennTitleTextColor=this.vennTitleTextColor??this.titleColor,this.vennSetTextColor=this.vennSetTextColor??this.textColor,this.quadrant1Fill=this.quadrant1Fill||this.primaryColor,this.quadrant2Fill=this.quadrant2Fill||R(this.primaryColor,{r:5,g:5,b:5}),this.quadrant3Fill=this.quadrant3Fill||R(this.primaryColor,{r:10,g:10,b:10}),this.quadrant4Fill=this.quadrant4Fill||R(this.primaryColor,{r:15,g:15,b:15}),this.quadrant1TextFill=this.quadrant1TextFill||this.primaryTextColor,this.quadrant2TextFill=this.quadrant2TextFill||R(this.primaryTextColor,{r:-5,g:-5,b:-5}),this.quadrant3TextFill=this.quadrant3TextFill||R(this.primaryTextColor,{r:-10,g:-10,b:-10}),this.quadrant4TextFill=this.quadrant4TextFill||R(this.primaryTextColor,{r:-15,g:-15,b:-15}),this.quadrantPointFill=this.quadrantPointFill||tr(this.quadrant1Fill)?he(this.quadrant1Fill):me(this.quadrant1Fill),this.quadrantPointTextFill=this.quadrantPointTextFill||this.primaryTextColor,this.quadrantXAxisTextFill=this.quadrantXAxisTextFill||this.primaryTextColor,this.quadrantYAxisTextFill=this.quadrantYAxisTextFill||this.primaryTextColor,this.quadrantInternalBorderStrokeFill=this.quadrantInternalBorderStrokeFill||this.primaryBorderColor,this.quadrantExternalBorderStrokeFill=this.quadrantExternalBorderStrokeFill||this.primaryBorderColor,this.quadrantTitleFill=this.quadrantTitleFill||this.primaryTextColor,this.xyChart={backgroundColor:this.xyChart?.backgroundColor||this.background,titleColor:this.xyChart?.titleColor||this.primaryTextColor,legendTextColor:this.xyChart?.legendTextColor||this.primaryTextColor,xAxisTitleColor:this.xyChart?.xAxisTitleColor||this.primaryTextColor,xAxisLabelColor:this.xyChart?.xAxisLabelColor||this.primaryTextColor,xAxisTickColor:this.xyChart?.xAxisTickColor||this.primaryTextColor,xAxisLineColor:this.xyChart?.xAxisLineColor||this.primaryTextColor,yAxisTitleColor:this.xyChart?.yAxisTitleColor||this.primaryTextColor,yAxisLabelColor:this.xyChart?.yAxisLabelColor||this.primaryTextColor,yAxisTickColor:this.xyChart?.yAxisTickColor||this.primaryTextColor,yAxisLineColor:this.xyChart?.yAxisLineColor||this.primaryTextColor,plotColorPalette:this.xyChart?.plotColorPalette||"#FFF4DD,#FFD8B1,#FFA07A,#ECEFF1,#D6DBDF,#C3E0A8,#FFB6A4,#FFD74D,#738FA7,#FFFFF0"},this.requirementBackground=this.requirementBackground||this.primaryColor,this.requirementBorderColor=this.requirementBorderColor||this.primaryBorderColor,this.requirementBorderSize=this.requirementBorderSize||"1",this.requirementTextColor=this.requirementTextColor||this.primaryTextColor,this.relationColor=this.relationColor||this.lineColor,this.relationLabelBackground=this.relationLabelBackground||(this.darkMode?me(this.secondaryColor,30):this.secondaryColor),this.relationLabelColor=this.relationLabelColor||this.actorTextColor,this.git0=this.git0||"#0b0000",this.git1=this.git1||"#4d1037",this.git2=this.git2||"#3f5258",this.git3=this.git3||"#4f2f1b",this.git4=this.git4||"#6e0a0a",this.git5=this.git5||"#3b0048",this.git6=this.git6||"#995a01",this.git7=this.git7||"#154706",this.gitDarkMode=true,this.gitDarkMode)this.git0=he(this.git0,25),this.git1=he(this.git1,25),this.git2=he(this.git2,25),this.git3=he(this.git3,25),this.git4=he(this.git4,25),this.git5=he(this.git5,25),this.git6=he(this.git6,25),this.git7=he(this.git7,25);else this.git0=me(this.git0,25),this.git1=me(this.git1,25),this.git2=me(this.git2,25),this.git3=me(this.git3,25),this.git4=me(this.git4,25),this.git5=me(this.git5,25),this.git6=me(this.git6,25),this.git7=me(this.git7,25);this.gitInv0=this.gitInv0||oe(this.git0),this.gitInv1=this.gitInv1||oe(this.git1),this.gitInv2=this.gitInv2||oe(this.git2),this.gitInv3=this.gitInv3||oe(this.git3),this.gitInv4=this.gitInv4||oe(this.git4),this.gitInv5=this.gitInv5||oe(this.git5),this.gitInv6=this.gitInv6||oe(this.git6),this.gitInv7=this.gitInv7||oe(this.git7),this.branchLabelColor=this.branchLabelColor||(this.darkMode?"black":this.labelTextColor),this.gitBranchLabel0=this.gitBranchLabel0||this.branchLabelColor,this.gitBranchLabel1=this.gitBranchLabel1||this.branchLabelColor,this.gitBranchLabel2=this.gitBranchLabel2||this.branchLabelColor,this.gitBranchLabel3=this.gitBranchLabel3||this.branchLabelColor,this.gitBranchLabel4=this.gitBranchLabel4||this.branchLabelColor,this.gitBranchLabel5=this.gitBranchLabel5||this.branchLabelColor,this.gitBranchLabel6=this.gitBranchLabel6||this.branchLabelColor,this.gitBranchLabel7=this.gitBranchLabel7||this.branchLabelColor,this.tagLabelColor=this.tagLabelColor||this.primaryTextColor,this.tagLabelBackground=this.tagLabelBackground||this.primaryColor,this.tagLabelBorder=this.tagBorder||this.primaryBorderColor,this.tagLabelFontSize=this.tagLabelFontSize||"10px",this.commitLabelColor=this.commitLabelColor||this.secondaryTextColor,this.commitLabelBackground=this.commitLabelBackground||this.secondaryColor,this.commitLabelFontSize=this.commitLabelFontSize||"10px",this.attributeBackgroundColorOdd=this.attributeBackgroundColorOdd||Zr,this.attributeBackgroundColorEven=this.attributeBackgroundColorEven||ei}calculate(S){if(typeof S!=="object"){this.updateColors();return}let I=Object.keys(S);I.forEach(W=>{this[W]=S[W]}),this.updateColors(),I.forEach(W=>{this[W]=vr(this[W],S[W])})}}var XA=v=>{let S=new HA;return S.calculate(v),S};class KA{constructor(){this.background="#ffffff",this.primaryColor="#cccccc",this.mainBkg="#ffffff",this.noteBkgColor="#fff5ad",this.noteTextColor="#28253D",this.THEME_COLOR_LIMIT=12,this.radius=12,this.strokeWidth=2,this.primaryBorderColor=Ue("#28253D",this.darkMode),this.fontFamily='"Recursive Variable", arial, sans-serif',this.fontSize="14px",this.nodeBorder="#28253D",this.stateBorder="#28253D",this.useGradient=false,this.gradientStart="#0042eb",this.gradientStop="#eb0042",this.dropShadow="url(#drop-shadow)",this.nodeShadow=true,this.tertiaryColor="#ffffff",this.clusterBkg="#F9F9FB",this.clusterBorder="#BDBCCC",this.noteBorderColor="#FACC15",this.archEdgeColor="calculated",this.archEdgeArrowColor="calculated",this.archEdgeWidth="3",this.archGroupBorderColor=this.primaryBorderColor,this.archGroupBorderWidth="2px",this.actorBorder="#28253D",this.filterColor="#000000"}updateColors(){this.primaryTextColor=this.primaryTextColor||(this.darkMode?"#eee":"#28253D"),this.secondaryColor=this.secondaryColor||R(this.primaryColor,{h:-120}),this.tertiaryColor=this.tertiaryColor||R(this.primaryColor,{h:180,l:5}),this.primaryBorderColor=this.primaryBorderColor||Ue(this.primaryColor,this.darkMode),this.secondaryBorderColor=this.secondaryBorderColor||Ue(this.secondaryColor,this.darkMode),this.tertiaryBorderColor=this.tertiaryBorderColor||Ue(this.tertiaryColor,this.darkMode),this.noteBorderColor=this.noteBorderColor||Ue(this.noteBkgColor,this.darkMode),this.noteBkgColor=this.noteBkgColor||"#FEF9C3",this.noteTextColor=this.noteTextColor||"#28253D",this.secondaryTextColor=this.secondaryTextColor||oe(this.secondaryColor),this.tertiaryTextColor=this.tertiaryTextColor||oe(this.tertiaryColor),this.lineColor=this.lineColor||oe(this.background),this.arrowheadColor=this.arrowheadColor||oe(this.background),this.textColor=this.textColor||this.primaryTextColor,this.border2=this.border2||this.tertiaryBorderColor,this.nodeBkg=this.nodeBkg||this.primaryColor,this.mainBkg=this.mainBkg||this.primaryColor,this.nodeBorder=this.nodeBorder||this.primaryBorderColor,this.clusterBkg=this.clusterBkg||this.tertiaryColor,this.clusterBorder=this.clusterBorder||this.tertiaryBorderColor,this.defaultLinkColor=this.defaultLinkColor||this.lineColor,this.titleColor=this.titleColor||this.tertiaryTextColor,this.edgeLabelBackground=this.edgeLabelBackground||(this.darkMode?me(this.secondaryColor,30):this.secondaryColor),this.nodeTextColor=this.nodeTextColor||this.primaryTextColor,this.flowContainerStroke=this.flowContainerStroke||this.secondaryBorderColor,this.noteFontWeight=600,this.actorBorder=this.actorBorder||this.primaryBorderColor,this.actorBkg=this.actorBkg||this.mainBkg,this.actorTextColor=this.actorTextColor||this.primaryTextColor,this.actorLineColor=this.actorLineColor||this.actorBorder,this.labelBoxBkgColor=this.labelBoxBkgColor||this.actorBkg,this.signalColor=this.signalColor||this.textColor,this.signalTextColor=this.signalTextColor||this.textColor,this.labelBoxBorderColor=this.labelBoxBorderColor||this.actorBorder,this.labelTextColor=this.labelTextColor||this.actorTextColor,this.loopTextColor=this.loopTextColor||this.actorTextColor,this.activationBorderColor=this.activationBorderColor||me(this.secondaryColor,10),this.activationBkgColor=this.activationBkgColor||this.secondaryColor,this.sequenceNumberColor=this.sequenceNumberColor||oe(this.lineColor),this.rectBkgColor=this.rectBkgColor||(tr(this.background)?he(this.background,4):me(this.background,4));let S="#ECECFE",I="#E9E9F1",W=R(S,{h:180,l:5});this.sectionBkgColor=this.sectionBkgColor||W,this.altSectionBkgColor=this.altSectionBkgColor||"white",this.sectionBkgColor=this.sectionBkgColor||I,this.sectionBkgColor2=this.sectionBkgColor2||S,this.excludeBkgColor=this.excludeBkgColor||"#eeeeee",this.taskBorderColor=this.taskBorderColor||this.primaryBorderColor,this.taskBkgColor=this.taskBkgColor||S,this.activeTaskBorderColor=this.activeTaskBorderColor||S,this.activeTaskBkgColor=this.activeTaskBkgColor||he(S,23),this.gridColor=this.gridColor||"lightgrey",this.doneTaskBkgColor=this.doneTaskBkgColor||"lightgrey",this.doneTaskBorderColor=this.doneTaskBorderColor||"grey",this.critBorderColor=this.critBorderColor||"#ff8888",this.critBkgColor=this.critBkgColor||"red",this.todayLineColor=this.todayLineColor||"red",this.taskTextColor=this.taskTextColor||this.textColor,this.vertLineColor=this.vertLineColor||this.primaryBorderColor,this.taskTextOutsideColor=this.taskTextOutsideColor||this.textColor,this.taskTextLightColor=this.taskTextLightColor||this.textColor,this.taskTextColor=this.taskTextColor||this.primaryTextColor,this.taskTextDarkColor=this.taskTextDarkColor||this.textColor,this.taskTextClickableColor=this.taskTextClickableColor||"#003163",this.archEdgeColor=this.lineColor,this.archEdgeArrowColor=this.lineColor,this.personBorder=this.personBorder||this.primaryBorderColor,this.personBkg=this.personBkg||this.mainBkg,this.transitionColor=this.transitionColor||this.lineColor,this.transitionLabelColor=this.transitionLabelColor||this.textColor,this.stateLabelColor=this.stateLabelColor||this.stateBkg||this.primaryTextColor,this.compositeTitleBackground="#F9F9FB",this.altBackground="#F9F9FB",this.stateEdgeLabelBackground="#FFFFFF",this.fontWeight=600,this.stateBkg=this.stateBkg||this.mainBkg,this.labelBackgroundColor=this.labelBackgroundColor||this.stateBkg,this.compositeBackground=this.compositeBackground||this.background||this.tertiaryColor,this.altBackground=this.altBackground||"#f0f0f0",this.compositeTitleBackground=this.compositeTitleBackground||this.mainBkg,this.compositeBorder=this.compositeBorder||this.nodeBorder,this.innerEndBackground=this.nodeBorder,this.errorBkgColor=this.errorBkgColor||this.tertiaryColor,this.errorTextColor=this.errorTextColor||this.tertiaryTextColor,this.transitionColor=this.transitionColor||this.lineColor,this.specialStateColor=this.lineColor;for(let te=0;te<this.THEME_COLOR_LIMIT;te++){e();this["cScale"+te]=this.mainBkg}if(this.darkMode)for(let te=0;te<this.THEME_COLOR_LIMIT;te++){e();this["cScale"+te]=me(this["cScale"+te],75)}else for(let te=0;te<this.THEME_COLOR_LIMIT;te++){e();this["cScale"+te]=me(this["cScale"+te],25)}for(let te=0;te<this.THEME_COLOR_LIMIT;te++){e();this["cScaleInv"+te]=this["cScaleInv"+te]||oe(this["cScale"+te])}for(let te=0;te<this.THEME_COLOR_LIMIT;te++){e();if(this.darkMode)this["cScalePeer"+te]=this["cScalePeer"+te]||he(this["cScale"+te],10);else this["cScalePeer"+te]=this["cScalePeer"+te]||me(this["cScale"+te],10)}this.scaleLabelColor=this.scaleLabelColor||this.labelTextColor;for(let te=0;te<this.THEME_COLOR_LIMIT;te++){e();this["cScaleLabel"+te]=this["cScaleLabel"+te]||this.scaleLabelColor}let ye=this.darkMode?-4:-1;for(let te=0;te<5;te++){e();this["surface"+te]=this["surface"+te]||R(this.mainBkg,{h:180,s:-15,l:ye*(5+te*3)}),this["surfacePeer"+te]=this["surfacePeer"+te]||R(this.mainBkg,{h:180,s:-15,l:ye*(8+te*3)})}if(this.classText=this.classText||this.textColor,this.fillType0=this.fillType0||S,this.fillType1=this.fillType1||I,this.fillType2=this.fillType2||R(S,{h:64}),this.fillType3=this.fillType3||R(I,{h:64}),this.fillType4=this.fillType4||R(S,{h:-64}),this.fillType5=this.fillType5||R(I,{h:-64}),this.fillType6=this.fillType6||R(S,{h:128}),this.fillType7=this.fillType7||R(I,{h:128}),this.pie1=this.pie1||S,this.pie2=this.pie2||I,this.pie3=this.pie3||W,this.pie4=this.pie4||R(S,{l:-10}),this.pie5=this.pie5||R(I,{l:-10}),this.pie6=this.pie6||R(W,{l:-10}),this.pie7=this.pie7||R(S,{h:60,l:-10}),this.pie8=this.pie8||R(S,{h:-60,l:-10}),this.pie9=this.pie9||R(S,{h:120,l:0}),this.pie10=this.pie10||R(S,{h:60,l:-20}),this.pie11=this.pie11||R(S,{h:-60,l:-20}),this.pie12=this.pie12||R(S,{h:120,l:-10}),this.pieTitleTextSize=this.pieTitleTextSize||"25px",this.pieTitleTextColor=this.pieTitleTextColor||this.taskTextDarkColor,this.pieSectionTextSize=this.pieSectionTextSize||"17px",this.pieSectionTextColor=this.pieSectionTextColor||this.textColor,this.pieLegendTextSize=this.pieLegendTextSize||"17px",this.pieLegendTextColor=this.pieLegendTextColor||this.taskTextDarkColor,this.pieStrokeColor=this.pieStrokeColor||"black",this.pieStrokeWidth=this.pieStrokeWidth||"2px",this.pieOuterStrokeWidth=this.pieOuterStrokeWidth||"2px",this.pieOuterStrokeColor=this.pieOuterStrokeColor||"black",this.pieOpacity=this.pieOpacity||"0.7",this.vennTitleTextColor=this.vennTitleTextColor??this.titleColor,this.vennSetTextColor=this.vennSetTextColor??this.textColor,this.quadrant1Fill=this.quadrant1Fill||S,this.quadrant2Fill=this.quadrant2Fill||R(S,{r:5,g:5,b:5}),this.quadrant3Fill=this.quadrant3Fill||R(S,{r:10,g:10,b:10}),this.quadrant4Fill=this.quadrant4Fill||R(S,{r:15,g:15,b:15}),this.quadrant1TextFill=this.quadrant1TextFill||this.primaryTextColor,this.quadrant2TextFill=this.quadrant2TextFill||R(this.primaryTextColor,{r:-5,g:-5,b:-5}),this.quadrant3TextFill=this.quadrant3TextFill||R(this.primaryTextColor,{r:-10,g:-10,b:-10}),this.quadrant4TextFill=this.quadrant4TextFill||R(this.primaryTextColor,{r:-15,g:-15,b:-15}),this.quadrantPointFill=this.quadrantPointFill||tr(this.quadrant1Fill)?he(this.quadrant1Fill):me(this.quadrant1Fill),this.quadrantPointTextFill=this.quadrantPointTextFill||this.primaryTextColor,this.quadrantXAxisTextFill=this.quadrantXAxisTextFill||this.primaryTextColor,this.quadrantYAxisTextFill=this.quadrantYAxisTextFill||this.primaryTextColor,this.quadrantInternalBorderStrokeFill=this.quadrantInternalBorderStrokeFill||this.primaryBorderColor,this.quadrantExternalBorderStrokeFill=this.quadrantExternalBorderStrokeFill||this.primaryBorderColor,this.quadrantTitleFill=this.quadrantTitleFill||this.primaryTextColor,this.xyChart={backgroundColor:this.xyChart?.backgroundColor||this.background,titleColor:this.xyChart?.titleColor||this.primaryTextColor,legendTextColor:this.xyChart?.legendTextColor||this.primaryTextColor,xAxisTitleColor:this.xyChart?.xAxisTitleColor||this.primaryTextColor,xAxisLabelColor:this.xyChart?.xAxisLabelColor||this.primaryTextColor,xAxisTickColor:this.xyChart?.xAxisTickColor||this.primaryTextColor,xAxisLineColor:this.xyChart?.xAxisLineColor||this.primaryTextColor,yAxisTitleColor:this.xyChart?.yAxisTitleColor||this.primaryTextColor,yAxisLabelColor:this.xyChart?.yAxisLabelColor||this.primaryTextColor,yAxisTickColor:this.xyChart?.yAxisTickColor||this.primaryTextColor,yAxisLineColor:this.xyChart?.yAxisLineColor||this.primaryTextColor,plotColorPalette:this.xyChart?.plotColorPalette||"#FFF4DD,#FFD8B1,#FFA07A,#ECEFF1,#D6DBDF,#C3E0A8,#FFB6A4,#FFD74D,#738FA7,#FFFFF0"},this.requirementBackground=this.requirementBackground||S,this.requirementBorderColor=this.requirementBorderColor||this.primaryBorderColor,this.requirementBorderSize=this.requirementBorderSize||"1",this.requirementTextColor=this.requirementTextColor||this.primaryTextColor,this.relationColor=this.relationColor||this.lineColor,this.relationLabelBackground=this.relationLabelBackground||(this.darkMode?me(this.secondaryColor,30):this.secondaryColor),this.relationLabelColor=this.relationLabelColor||this.actorTextColor,this.requirementEdgeLabelBackground="#FFFFFF",this.git0=this.git0||S,this.git1=this.git1||I,this.git2=this.git2||W,this.git3=this.git3||R(S,{h:-30}),this.git4=this.git4||R(S,{h:-60}),this.git5=this.git5||R(S,{h:-90}),this.git6=this.git6||R(S,{h:60}),this.git7=this.git7||R(S,{h:120}),this.darkMode)this.git0=he(this.git0,25),this.git1=he(this.git1,25),this.git2=he(this.git2,25),this.git3=he(this.git3,25),this.git4=he(this.git4,25),this.git5=he(this.git5,25),this.git6=he(this.git6,25),this.git7=he(this.git7,25);else this.git0=me(this.git0,25),this.git1=me(this.git1,25),this.git2=me(this.git2,25),this.git3=me(this.git3,25),this.git4=me(this.git4,25),this.git5=me(this.git5,25),this.git6=me(this.git6,25),this.git7=me(this.git7,25);this.gitInv0=this.gitInv0||oe(this.git0),this.gitInv1=this.gitInv1||oe(this.git1),this.gitInv2=this.gitInv2||oe(this.git2),this.gitInv3=this.gitInv3||oe(this.git3),this.gitInv4=this.gitInv4||oe(this.git4),this.gitInv5=this.gitInv5||oe(this.git5),this.gitInv6=this.gitInv6||oe(this.git6),this.gitInv7=this.gitInv7||oe(this.git7),this.branchLabelColor=this.branchLabelColor||(this.darkMode?"black":this.labelTextColor),this.gitBranchLabel0=this.gitBranchLabel0||this.branchLabelColor,this.gitBranchLabel1=this.gitBranchLabel1||this.branchLabelColor,this.gitBranchLabel2=this.gitBranchLabel2||this.branchLabelColor,this.gitBranchLabel3=this.gitBranchLabel3||this.branchLabelColor,this.gitBranchLabel4=this.gitBranchLabel4||this.branchLabelColor,this.gitBranchLabel5=this.gitBranchLabel5||this.branchLabelColor,this.gitBranchLabel6=this.gitBranchLabel6||this.branchLabelColor,this.gitBranchLabel7=this.gitBranchLabel7||this.branchLabelColor,this.tagLabelColor=this.tagLabelColor||this.primaryTextColor,this.tagLabelBackground=this.tagLabelBackground||this.primaryColor,this.tagLabelBorder=this.tagBorder||this.primaryBorderColor,this.tagLabelFontSize=this.tagLabelFontSize||"10px",this.commitLabelColor=this.commitLabelColor||this.secondaryTextColor,this.commitLabelBackground=this.commitLabelBackground||this.secondaryColor,this.commitLabelFontSize=this.commitLabelFontSize||"10px",this.commitLineColor=this.commitLineColor??"#BDBCCC",this.erEdgeLabelBackground="#FFFFFF",this.attributeBackgroundColorOdd=this.attributeBackgroundColorOdd||Zr,this.attributeBackgroundColorEven=this.attributeBackgroundColorEven||ei}calculate(S){if(typeof S!=="object"){this.updateColors();return}let I=Object.keys(S);I.forEach(W=>{this[W]=S[W]}),this.updateColors(),I.forEach(W=>{this[W]=vr(this[W],S[W])})}}var JA=v=>{let S=new KA;return S.calculate(v),S};class QA{constructor(){this.background="#333",this.primaryColor="#1f2020",this.secondaryColor=he(this.primaryColor,16),this.tertiaryColor=R(this.primaryColor,{h:-160}),this.primaryBorderColor=oe(this.background),this.secondaryBorderColor=Ue(this.secondaryColor,this.darkMode),this.tertiaryBorderColor=Ue(this.tertiaryColor,this.darkMode),this.primaryTextColor=oe(this.primaryColor),this.secondaryTextColor=oe(this.secondaryColor),this.tertiaryTextColor=oe(this.tertiaryColor),this.mainBkg="#111113",this.secondBkg="calculated",this.mainContrastColor="lightgrey",this.darkTextColor=he(oe("#323D47"),10),this.border1="#ccc",this.border2=fr(255,255,255,.25),this.arrowheadColor=oe(this.background),this.fontFamily='"Recursive Variable", arial, sans-serif',this.fontSize="14px",this.labelBackground="#111113",this.textColor="#ccc",this.THEME_COLOR_LIMIT=12,this.radius=12,this.strokeWidth=2,this.noteBkgColor=this.noteBkgColor??"#FEF9C3",this.noteTextColor=this.noteTextColor??"#28253D",this.THEME_COLOR_LIMIT=12,this.fontFamily='"Recursive Variable", arial, sans-serif',this.fontSize="14px",this.nodeBorder="#FFFFFF",this.stateBorder="#FFFFFF",this.useGradient=false,this.gradientStart="#0042eb",this.gradientStop="#eb0042",this.dropShadow="url(#drop-shadow)",this.nodeShadow=true,this.archEdgeColor="calculated",this.archEdgeArrowColor="calculated",this.archEdgeWidth="3",this.archGroupBorderColor=this.primaryBorderColor,this.archGroupBorderWidth="2px",this.clusterBkg="#1E1A2E",this.clusterBorder="#BDBCCC",this.noteBorderColor="#FACC15",this.noteFontWeight=600,this.filterColor="#FFFFFF"}updateColors(){if(this.primaryTextColor=this.primaryTextColor||(this.darkMode?"#eee":"#FFFFFF"),this.secondaryColor=this.secondaryColor||R(this.primaryColor,{h:-120}),this.tertiaryColor=this.tertiaryColor||R(this.primaryColor,{h:180,l:5}),this.primaryBorderColor=this.primaryBorderColor||Ue(this.primaryColor,this.darkMode),this.secondaryBorderColor=this.secondaryBorderColor||Ue(this.secondaryColor,this.darkMode),this.tertiaryBorderColor=this.tertiaryBorderColor||Ue(this.tertiaryColor,this.darkMode),this.noteBorderColor=this.noteBorderColor||Ue(this.noteBkgColor,this.darkMode),this.noteBkgColor=this.noteBkgColor||"#fff5ad",this.noteTextColor=this.noteTextColor||"#FFFFFF",this.secondaryTextColor=this.secondaryTextColor||oe(this.secondaryColor),this.tertiaryTextColor=this.tertiaryTextColor||oe(this.tertiaryColor),this.lineColor=this.lineColor||oe(this.background),this.arrowheadColor=this.arrowheadColor||oe(this.background),this.textColor=this.textColor||this.primaryTextColor,this.border2=this.border2||this.tertiaryBorderColor,this.nodeBkg=this.nodeBkg||this.primaryColor,this.mainBkg=this.mainBkg||this.primaryColor,this.secondBkg=this.secondBkg==="calculated"?he(this.mainBkg,16):this.secondBkg,this.nodeBorder=this.nodeBorder||this.border1,this.clusterBkg=this.clusterBkg||this.tertiaryColor,this.clusterBorder=this.clusterBorder||this.tertiaryBorderColor,this.defaultLinkColor=this.defaultLinkColor||this.lineColor,this.titleColor=this.titleColor||this.tertiaryTextColor,this.edgeLabelBackground=this.edgeLabelBackground||(this.darkMode?me(this.secondaryColor,30):this.secondaryColor),this.nodeTextColor=this.nodeTextColor||this.primaryTextColor,this.flowContainerStroke=this.flowContainerStroke||this.secondaryBorderColor,this.actorBorder="#FFFFFF",this.signalColor="#FFFFFF",this.labelBoxBorderColor="#BDBCCC",this.actorBorder=this.actorBorder||this.primaryBorderColor,this.actorBkg=this.actorBkg||this.mainBkg,this.actorTextColor=this.actorTextColor||this.primaryTextColor,this.actorLineColor=this.actorLineColor||this.actorBorder,this.labelBoxBkgColor=this.labelBoxBkgColor||this.actorBkg,this.signalColor=this.signalColor||this.textColor,this.signalTextColor=this.signalTextColor||this.textColor,this.labelBoxBorderColor=this.labelBoxBorderColor||this.actorBorder,this.labelTextColor=this.labelTextColor||this.actorTextColor,this.loopTextColor=this.loopTextColor||this.actorTextColor,this.activationBorderColor=this.activationBorderColor||me(this.secondaryColor,10),this.activationBkgColor=this.activationBkgColor||this.secondaryColor,this.sequenceNumberColor=this.sequenceNumberColor||oe(this.lineColor),this.rectBkgColor=this.rectBkgColor||this.tertiaryColor,this.sectionBkgColor=this.sectionBkgColor||this.tertiaryColor,this.altSectionBkgColor=this.altSectionBkgColor||"white",this.sectionBkgColor=this.sectionBkgColor||this.secondaryColor,this.sectionBkgColor2=this.sectionBkgColor2||this.primaryColor,this.excludeBkgColor=this.excludeBkgColor||"#eeeeee",this.taskBorderColor=this.taskBorderColor||this.primaryBorderColor,this.taskBkgColor=this.taskBkgColor||this.primaryColor,this.activeTaskBorderColor=this.activeTaskBorderColor||this.primaryColor,this.activeTaskBkgColor=this.activeTaskBkgColor||he(this.primaryColor,23),this.gridColor=this.gridColor||"lightgrey",this.doneTaskBkgColor=this.doneTaskBkgColor||this.secondBkg,this.doneTaskBorderColor=this.doneTaskBorderColor||"grey",this.critBorderColor=this.critBorderColor||"#ff8888",this.critBkgColor=this.critBkgColor||"red",this.todayLineColor=this.todayLineColor||"red",this.taskTextColor=this.taskTextColor||this.textColor,this.taskTextOutsideColor=this.taskTextOutsideColor||this.textColor,this.taskTextLightColor=this.taskTextLightColor||this.textColor,this.taskTextColor=this.taskTextColor||this.primaryTextColor,this.taskTextDarkColor=this.taskTextDarkColor||this.textColor,this.taskTextClickableColor=this.taskTextClickableColor||"#003163",this.archEdgeColor=this.lineColor,this.archEdgeArrowColor=this.lineColor,this.personBorder=this.personBorder||this.primaryBorderColor,this.personBkg=this.personBkg||this.mainBkg,this.transitionColor=this.transitionColor||this.lineColor,this.transitionLabelColor=this.transitionLabelColor||this.textColor,this.stateLabelColor=this.stateLabelColor||this.stateBkg||this.primaryTextColor,this.vertLineColor=this.vertLineColor||this.primaryBorderColor,this.compositeBackground="#16141F",this.altBackground="#16141F",this.compositeTitleBackground="#16141F",this.stateEdgeLabelBackground="#16141F",this.fontWeight=600,this.stateBkg=this.stateBkg||this.mainBkg,this.labelBackgroundColor=this.labelBackgroundColor||this.stateBkg,this.compositeBackground=this.compositeBackground||this.background||this.tertiaryColor,this.altBackground=this.altBackground||"#f0f0f0",this.compositeTitleBackground=this.compositeTitleBackground||this.mainBkg,this.compositeBorder=this.compositeBorder||this.nodeBorder,this.innerEndBackground=this.nodeBorder,this.errorBkgColor=this.errorBkgColor||this.tertiaryColor,this.errorTextColor=this.errorTextColor||this.tertiaryTextColor,this.transitionColor=this.transitionColor||this.lineColor,this.specialStateColor=this.lineColor,this.cScale0=this.cScale0||this.primaryColor,this.cScale1=this.cScale1||this.secondaryColor,this.cScale2=this.cScale2||this.tertiaryColor,this.cScale3=this.cScale3||R(this.primaryColor,{h:30}),this.cScale4=this.cScale4||R(this.primaryColor,{h:60}),this.cScale5=this.cScale5||R(this.primaryColor,{h:90}),this.cScale6=this.cScale6||R(this.primaryColor,{h:120}),this.cScale7=this.cScale7||R(this.primaryColor,{h:150}),this.cScale8=this.cScale8||R(this.primaryColor,{h:210,l:150}),this.cScale9=this.cScale9||R(this.primaryColor,{h:270}),this.cScale10=this.cScale10||R(this.primaryColor,{h:300}),this.cScale11=this.cScale11||R(this.primaryColor,{h:330}),this.darkMode)for(let I=0;I<this.THEME_COLOR_LIMIT;I++){e();this["cScale"+I]=me(this["cScale"+I],75)}else for(let I=0;I<this.THEME_COLOR_LIMIT;I++){e();this["cScale"+I]=me(this["cScale"+I],25)}for(let I=0;I<this.THEME_COLOR_LIMIT;I++){e();this["cScaleInv"+I]=this["cScaleInv"+I]||oe(this["cScale"+I])}for(let I=0;I<this.THEME_COLOR_LIMIT;I++){e();if(this.darkMode)this["cScalePeer"+I]=this["cScalePeer"+I]||he(this["cScale"+I],10);else this["cScalePeer"+I]=this["cScalePeer"+I]||me(this["cScale"+I],10)}this.scaleLabelColor=this.scaleLabelColor||this.labelTextColor;for(let I=0;I<this.THEME_COLOR_LIMIT;I++){e();this["cScaleLabel"+I]=this["cScaleLabel"+I]||this.scaleLabelColor}let S=this.darkMode?-4:-1;for(let I=0;I<5;I++){e();this["surface"+I]=this["surface"+I]||R(this.mainBkg,{h:180,s:-15,l:S*(5+I*3)}),this["surfacePeer"+I]=this["surfacePeer"+I]||R(this.mainBkg,{h:180,s:-15,l:S*(8+I*3)})}if(this.classText=this.classText||this.textColor,this.fillType0=this.fillType0||this.primaryColor,this.fillType1=this.fillType1||this.secondaryColor,this.fillType2=this.fillType2||R(this.primaryColor,{h:64}),this.fillType3=this.fillType3||R(this.secondaryColor,{h:64}),this.fillType4=this.fillType4||R(this.primaryColor,{h:-64}),this.fillType5=this.fillType5||R(this.secondaryColor,{h:-64}),this.fillType6=this.fillType6||R(this.primaryColor,{h:128}),this.fillType7=this.fillType7||R(this.secondaryColor,{h:128}),this.pie1=this.pie1||this.primaryColor,this.pie2=this.pie2||this.secondaryColor,this.pie3=this.pie3||this.tertiaryColor,this.pie4=this.pie4||R(this.primaryColor,{l:-10}),this.pie5=this.pie5||R(this.secondaryColor,{l:-10}),this.pie6=this.pie6||R(this.tertiaryColor,{l:-10}),this.pie7=this.pie7||R(this.primaryColor,{h:60,l:-10}),this.pie8=this.pie8||R(this.primaryColor,{h:-60,l:-10}),this.pie9=this.pie9||R(this.primaryColor,{h:120,l:0}),this.pie10=this.pie10||R(this.primaryColor,{h:60,l:-20}),this.pie11=this.pie11||R(this.primaryColor,{h:-60,l:-20}),this.pie12=this.pie12||R(this.primaryColor,{h:120,l:-10}),this.pieTitleTextSize=this.pieTitleTextSize||"25px",this.pieTitleTextColor=this.pieTitleTextColor||this.taskTextDarkColor,this.pieSectionTextSize=this.pieSectionTextSize||"17px",this.pieSectionTextColor=this.pieSectionTextColor||this.textColor,this.pieLegendTextSize=this.pieLegendTextSize||"17px",this.pieLegendTextColor=this.pieLegendTextColor||this.taskTextDarkColor,this.pieStrokeColor=this.pieStrokeColor||"black",this.pieStrokeWidth=this.pieStrokeWidth||"2px",this.pieOuterStrokeWidth=this.pieOuterStrokeWidth||"2px",this.pieOuterStrokeColor=this.pieOuterStrokeColor||"black",this.pieOpacity=this.pieOpacity||"0.7",this.vennTitleTextColor=this.vennTitleTextColor??this.titleColor,this.vennSetTextColor=this.vennSetTextColor??this.textColor,this.quadrant1Fill=this.quadrant1Fill||this.primaryColor,this.quadrant2Fill=this.quadrant2Fill||R(this.primaryColor,{r:5,g:5,b:5}),this.quadrant3Fill=this.quadrant3Fill||R(this.primaryColor,{r:10,g:10,b:10}),this.quadrant4Fill=this.quadrant4Fill||R(this.primaryColor,{r:15,g:15,b:15}),this.quadrant1TextFill=this.quadrant1TextFill||this.primaryTextColor,this.quadrant2TextFill=this.quadrant2TextFill||R(this.primaryTextColor,{r:-5,g:-5,b:-5}),this.quadrant3TextFill=this.quadrant3TextFill||R(this.primaryTextColor,{r:-10,g:-10,b:-10}),this.quadrant4TextFill=this.quadrant4TextFill||R(this.primaryTextColor,{r:-15,g:-15,b:-15}),this.quadrantPointFill=this.quadrantPointFill||tr(this.quadrant1Fill)?he(this.quadrant1Fill):me(this.quadrant1Fill),this.quadrantPointTextFill=this.quadrantPointTextFill||this.primaryTextColor,this.quadrantXAxisTextFill=this.quadrantXAxisTextFill||this.primaryTextColor,this.quadrantYAxisTextFill=this.quadrantYAxisTextFill||this.primaryTextColor,this.quadrantInternalBorderStrokeFill=this.quadrantInternalBorderStrokeFill||this.primaryBorderColor,this.quadrantExternalBorderStrokeFill=this.quadrantExternalBorderStrokeFill||this.primaryBorderColor,this.quadrantTitleFill=this.quadrantTitleFill||this.primaryTextColor,this.xyChart={backgroundColor:this.xyChart?.backgroundColor||this.background,titleColor:this.xyChart?.titleColor||this.primaryTextColor,legendTextColor:this.xyChart?.legendTextColor||this.primaryTextColor,xAxisTitleColor:this.xyChart?.xAxisTitleColor||this.primaryTextColor,xAxisLabelColor:this.xyChart?.xAxisLabelColor||this.primaryTextColor,xAxisTickColor:this.xyChart?.xAxisTickColor||this.primaryTextColor,xAxisLineColor:this.xyChart?.xAxisLineColor||this.primaryTextColor,yAxisTitleColor:this.xyChart?.yAxisTitleColor||this.primaryTextColor,yAxisLabelColor:this.xyChart?.yAxisLabelColor||this.primaryTextColor,yAxisTickColor:this.xyChart?.yAxisTickColor||this.primaryTextColor,yAxisLineColor:this.xyChart?.yAxisLineColor||this.primaryTextColor,plotColorPalette:this.xyChart?.plotColorPalette||"#FFF4DD,#FFD8B1,#FFA07A,#ECEFF1,#D6DBDF,#C3E0A8,#FFB6A4,#FFD74D,#738FA7,#FFFFF0"},this.requirementBackground=this.requirementBackground||this.primaryColor,this.requirementBorderColor=this.requirementBorderColor||this.primaryBorderColor,this.requirementBorderSize=this.requirementBorderSize||"1",this.requirementTextColor=this.requirementTextColor||this.primaryTextColor,this.relationColor=this.relationColor||this.lineColor,this.relationLabelBackground=this.relationLabelBackground||(this.darkMode?me(this.secondaryColor,30):this.secondaryColor),this.relationLabelColor=this.relationLabelColor||this.actorTextColor,this.requirementEdgeLabelBackground="#16141F",this.git0=this.git0||this.primaryColor,this.git1=this.git1||this.secondaryColor,this.git2=this.git2||this.tertiaryColor,this.git3=this.git3||R(this.primaryColor,{h:-30}),this.git4=this.git4||R(this.primaryColor,{h:-60}),this.git5=this.git5||R(this.primaryColor,{h:-90}),this.git6=this.git6||R(this.primaryColor,{h:60}),this.git7=this.git7||R(this.primaryColor,{h:120}),this.darkMode)this.git0=he(this.git0,25),this.git1=he(this.git1,25),this.git2=he(this.git2,25),this.git3=he(this.git3,25),this.git4=he(this.git4,25),this.git5=he(this.git5,25),this.git6=he(this.git6,25),this.git7=he(this.git7,25);else this.git0=me(this.git0,25),this.git1=me(this.git1,25),this.git2=me(this.git2,25),this.git3=me(this.git3,25),this.git4=me(this.git4,25),this.git5=me(this.git5,25),this.git6=me(this.git6,25),this.git7=me(this.git7,25);this.gitInv0=this.gitInv0||oe(this.git0),this.gitInv1=this.gitInv1||oe(this.git1),this.gitInv2=this.gitInv2||oe(this.git2),this.gitInv3=this.gitInv3||oe(this.git3),this.gitInv4=this.gitInv4||oe(this.git4),this.gitInv5=this.gitInv5||oe(this.git5),this.gitInv6=this.gitInv6||oe(this.git6),this.gitInv7=this.gitInv7||oe(this.git7),this.branchLabelColor=this.branchLabelColor||(this.darkMode?"black":this.labelTextColor),this.gitBranchLabel0=this.gitBranchLabel0||this.branchLabelColor,this.gitBranchLabel1=this.gitBranchLabel1||this.branchLabelColor,this.gitBranchLabel2=this.gitBranchLabel2||this.branchLabelColor,this.gitBranchLabel3=this.gitBranchLabel3||this.branchLabelColor,this.gitBranchLabel4=this.gitBranchLabel4||this.branchLabelColor,this.gitBranchLabel5=this.gitBranchLabel5||this.branchLabelColor,this.gitBranchLabel6=this.gitBranchLabel6||this.branchLabelColor,this.gitBranchLabel7=this.gitBranchLabel7||this.branchLabelColor,this.tagLabelColor=this.tagLabelColor||this.primaryTextColor,this.tagLabelBackground=this.tagLabelBackground||this.primaryColor,this.tagLabelBorder=this.tagBorder||this.primaryBorderColor,this.tagLabelFontSize=this.tagLabelFontSize||"10px",this.commitLabelColor=this.commitLabelColor||this.secondaryTextColor,this.commitLabelBackground=this.commitLabelBackground||this.secondaryColor,this.commitLabelFontSize=this.commitLabelFontSize||"10px",this.commitLineColor=this.commitLineColor??"#BDBCCC",this.erEdgeLabelBackground="#16141F",this.attributeBackgroundColorOdd=this.attributeBackgroundColorOdd||Zr,this.attributeBackgroundColorEven=this.attributeBackgroundColorEven||ei}calculate(S){if(typeof S!=="object"){this.updateColors();return}let I=Object.keys(S);I.forEach(W=>{this[W]=S[W]}),this.updateColors(),I.forEach(W=>{this[W]=vr(this[W],S[W])})}}var ZA=v=>{let S=new QA;return S.calculate(v),S};class eO{constructor(){this.background="#ffffff",this.primaryColor="#cccccc",this.mainBkg="#ffffff",this.noteBkgColor="#fff5ad",this.noteTextColor="#28253D",this.THEME_COLOR_LIMIT=12,this.radius=12,this.strokeWidth=2,this.primaryBorderColor=Ue("#28253D",this.darkMode),this.fontFamily='"Recursive Variable", arial, sans-serif',this.fontSize="14px",this.nodeBorder="#28253D",this.stateBorder="#28253D",this.useGradient=false,this.gradientStart="#0042eb",this.gradientStop="#eb0042",this.dropShadow="url(#drop-shadow)",this.nodeShadow=true,this.tertiaryColor="#ffffff",this.clusterBkg="#F9F9FB",this.clusterBorder="#BDBCCC",this.archEdgeColor="calculated",this.archEdgeArrowColor="calculated",this.archEdgeWidth="3",this.archGroupBorderColor=this.primaryBorderColor,this.archGroupBorderWidth="2px",this.actorBorder="#28253D",this.noteBorderColor="#FACC15",this.noteFontWeight=600,this.borderColorArray=["#E879F9","#2DD4BF","#FB923C","#22D3EE","#4ADE80","#A78BFA","#F87171","#FACC15","#818CF8","#A3E635 ","#38BDF8","#FB7185"],this.bkgColorArray=["#FDF4FF","#F0FDFA","#FFF7ED","#ECFEFF","#F0FDF4","#F5F3FF","#FEF2F2","#FEFCE8","#EEF2FF","#F7FEE7","#F0F9FF","#FFF1F2"],this.usecaseActorBorder="#A78BFA",this.usecaseActorBkg="#F5F3FF",this.usecaseBorder="#2DD4BF",this.usecaseBkg="#F0FDFA",this.usecaseBoundaryBorder="#BDBCCC",this.usecaseBoundaryBkg="#FAFAFC",this.usecaseIncludeLine="#38BDF8",this.usecaseExtendLine="#FB923C",this.filterColor="#000000"}updateColors(){this.primaryTextColor=this.primaryTextColor||(this.darkMode?"#eee":"#28253D"),this.secondaryColor=this.secondaryColor||R(this.primaryColor,{h:-120}),this.tertiaryColor=this.tertiaryColor||R(this.primaryColor,{h:180,l:5}),this.primaryBorderColor=this.primaryBorderColor||Ue(this.primaryColor,this.darkMode),this.secondaryBorderColor=this.secondaryBorderColor||Ue(this.secondaryColor,this.darkMode),this.tertiaryBorderColor=this.tertiaryBorderColor||Ue(this.tertiaryColor,this.darkMode),this.noteBorderColor=this.noteBorderColor||Ue(this.noteBkgColor,this.darkMode),this.noteBkgColor=this.noteBkgColor||"#fff5ad",this.noteTextColor=this.noteTextColor||"#28253D",this.secondaryTextColor=this.secondaryTextColor||oe(this.secondaryColor),this.tertiaryTextColor=this.tertiaryTextColor||oe(this.tertiaryColor),this.lineColor=this.lineColor||oe(this.background),this.arrowheadColor=this.arrowheadColor||oe(this.background),this.textColor=this.textColor||this.primaryTextColor,this.border2=this.border2||this.tertiaryBorderColor,this.nodeBkg=this.nodeBkg||this.primaryColor,this.mainBkg=this.mainBkg||this.primaryColor,this.nodeBorder=this.nodeBorder||this.primaryBorderColor,this.clusterBkg=this.clusterBkg||this.tertiaryColor,this.clusterBorder=this.clusterBorder||this.tertiaryBorderColor,this.defaultLinkColor=this.defaultLinkColor||this.lineColor,this.titleColor=this.titleColor||this.tertiaryTextColor,this.edgeLabelBackground=this.edgeLabelBackground||(this.darkMode?me(this.secondaryColor,30):this.secondaryColor),this.nodeTextColor=this.nodeTextColor||this.primaryTextColor,this.flowContainerStroke=this.flowContainerStroke||this.secondaryBorderColor,this.actorBorder=this.actorBorder||this.primaryBorderColor,this.actorBkg=this.actorBkg||this.mainBkg,this.actorTextColor=this.actorTextColor||this.primaryTextColor,this.actorLineColor=this.actorLineColor||this.actorBorder,this.labelBoxBkgColor=this.labelBoxBkgColor||this.actorBkg,this.signalColor=this.signalColor||this.textColor,this.signalTextColor=this.signalTextColor||this.textColor,this.labelBoxBorderColor=this.labelBoxBorderColor||this.actorBorder,this.labelTextColor=this.labelTextColor||this.actorTextColor,this.loopTextColor=this.loopTextColor||this.actorTextColor,this.activationBorderColor=this.activationBorderColor||me(this.secondaryColor,10),this.activationBkgColor=this.activationBkgColor||this.secondaryColor,this.sequenceNumberColor=this.sequenceNumberColor||oe(this.lineColor),this.rectBkgColor=this.rectBkgColor||(tr(this.background)?he(this.background,4):me(this.background,4));let S="#ECECFE",I="#E9E9F1",W=R(S,{h:180,l:5});this.excludeBkgColor=this.excludeBkgColor||"#eeeeee",this.taskBorderColor=this.taskBorderColor||this.primaryBorderColor,this.taskBkgColor=this.taskBkgColor||S,this.activeTaskBorderColor=this.activeTaskBorderColor||S,this.activeTaskBkgColor=this.activeTaskBkgColor||he(S,23),this.gridColor=this.gridColor||"lightgrey",this.doneTaskBkgColor=this.doneTaskBkgColor||"lightgrey",this.doneTaskBorderColor=this.doneTaskBorderColor||"grey",this.critBorderColor=this.critBorderColor||"#ff8888",this.critBkgColor=this.critBkgColor||"red",this.todayLineColor=this.todayLineColor||"red",this.taskTextColor=this.taskTextColor||this.textColor,this.vertLineColor=this.vertLineColor||this.primaryBorderColor,this.taskTextOutsideColor=this.taskTextOutsideColor||this.textColor,this.taskTextLightColor=this.taskTextLightColor||this.textColor,this.taskTextColor=this.taskTextColor||this.primaryTextColor,this.taskTextDarkColor=this.taskTextDarkColor||this.textColor,this.taskTextClickableColor=this.taskTextClickableColor||"#003163",this.archEdgeColor=this.lineColor,this.archEdgeArrowColor=this.lineColor,this.personBorder=this.personBorder||this.primaryBorderColor,this.personBkg=this.personBkg||this.mainBkg,this.transitionColor=this.transitionColor||this.lineColor,this.transitionLabelColor=this.transitionLabelColor||this.textColor,this.stateLabelColor=this.stateLabelColor||this.stateBkg||this.primaryTextColor,this.stateEdgeLabelBackground=this.stateEdgeLabelBackground||"#FFFFFF",this.stateBkg=this.stateBkg||this.mainBkg,this.labelBackgroundColor=this.labelBackgroundColor||this.stateBkg,this.compositeBackground=this.compositeBackground||this.background||this.tertiaryColor,this.altBackground=this.altBackground||"#F9F9FB",this.compositeTitleBackground=this.compositeTitleBackground||"#F9F9FB",this.compositeBorder=this.compositeBorder||this.nodeBorder,this.innerEndBackground=this.nodeBorder,this.errorBkgColor=this.errorBkgColor||this.tertiaryColor,this.errorTextColor=this.errorTextColor||this.tertiaryTextColor,this.transitionColor=this.transitionColor||this.lineColor,this.specialStateColor=this.lineColor,this.cScale0=this.cScale0||"#f4a8ff",this.cScale1=this.cScale1||"#46ecd5",this.cScale2=this.cScale2||"#ffb86a",this.cScale3=this.cScale3||"#dab2ff",this.cScale4=this.cScale4||"#7bf1a8",this.cScale5=this.cScale5||"#c4b4ff",this.cScale6=this.cScale6||"#ffa2a2",this.cScale7=this.cScale7||"#ffdf20",this.cScale8=this.cScale8||"#a3b3ff",this.cScale9=this.cScale9||"#bbf451",this.cScale10=this.cScale10||"#74d4ff",this.cScale11=this.cScale11||"#ffa1ad",this.sectionBkgColor=this.sectionBkgColor||this.cScale0,this.sectionBkgColor2=this.sectionBkgColor2||this.cScale1,this.altSectionBkgColor=this.altSectionBkgColor||"white";for(let te=0;te<this.THEME_COLOR_LIMIT;te++){e();this["cScaleInv"+te]=this["cScaleInv"+te]||oe(this["cScale"+te])}for(let te=0;te<this.THEME_COLOR_LIMIT;te++){e();if(this.darkMode)this["cScalePeer"+te]=this["cScalePeer"+te]||he(this["cScale"+te],10);else this["cScalePeer"+te]=this["cScalePeer"+te]||me(this["cScale"+te],10)}this.scaleLabelColor=this.scaleLabelColor||this.labelTextColor;for(let te=0;te<this.THEME_COLOR_LIMIT;te++){e();this["cScaleLabel"+te]=this["cScaleLabel"+te]||this.scaleLabelColor}let ye=this.darkMode?-4:-1;for(let te=0;te<5;te++){e();this["surface"+te]=this["surface"+te]||R(this.mainBkg,{h:180,s:-15,l:ye*(5+te*3)}),this["surfacePeer"+te]=this["surfacePeer"+te]||R(this.mainBkg,{h:180,s:-15,l:ye*(8+te*3)})}this.classText=this.classText||this.textColor;for(let te=0;te<8;te++){e();this["fillType"+te]=this["fillType"+te]||this.bkgColorArray[te]}for(let te=0;te<this.THEME_COLOR_LIMIT;te++){e();this["pie"+(te+1)]=this["pie"+(te+1)]||this["cScale"+te]}this.pieTitleTextSize=this.pieTitleTextSize||"25px",this.pieTitleTextColor=this.pieTitleTextColor||this.taskTextDarkColor,this.pieSectionTextSize=this.pieSectionTextSize||"17px",this.pieSectionTextColor=this.pieSectionTextColor||this.textColor,this.pieLegendTextSize=this.pieLegendTextSize||"17px",this.pieLegendTextColor=this.pieLegendTextColor||this.taskTextDarkColor,this.pieStrokeColor=this.pieStrokeColor||"black",this.pieStrokeWidth=this.pieStrokeWidth||"2px",this.pieOuterStrokeWidth=this.pieOuterStrokeWidth||"2px",this.pieOuterStrokeColor=this.pieOuterStrokeColor||"black",this.pieOpacity=this.pieOpacity||"0.7";for(let te=0;te<8;te++){e();this["venn"+(te+1)]=this["venn"+(te+1)]??this.borderColorArray[te%this.borderColorArray.length]}if(this.vennTitleTextColor=this.vennTitleTextColor??this.titleColor,this.vennSetTextColor=this.vennSetTextColor??this.textColor,this.quadrant1Fill=this.quadrant1Fill||S,this.quadrant2Fill=this.quadrant2Fill||R(S,{r:5,g:5,b:5}),this.quadrant3Fill=this.quadrant3Fill||R(S,{r:10,g:10,b:10}),this.quadrant4Fill=this.quadrant4Fill||R(S,{r:15,g:15,b:15}),this.quadrant1TextFill=this.quadrant1TextFill||this.primaryTextColor,this.quadrant2TextFill=this.quadrant2TextFill||R(this.primaryTextColor,{r:-5,g:-5,b:-5}),this.quadrant3TextFill=this.quadrant3TextFill||R(this.primaryTextColor,{r:-10,g:-10,b:-10}),this.quadrant4TextFill=this.quadrant4TextFill||R(this.primaryTextColor,{r:-15,g:-15,b:-15}),this.quadrantPointFill=this.quadrantPointFill||tr(this.quadrant1Fill)?he(this.quadrant1Fill):me(this.quadrant1Fill),this.quadrantPointTextFill=this.quadrantPointTextFill||this.primaryTextColor,this.quadrantXAxisTextFill=this.quadrantXAxisTextFill||this.primaryTextColor,this.quadrantYAxisTextFill=this.quadrantYAxisTextFill||this.primaryTextColor,this.quadrantInternalBorderStrokeFill=this.quadrantInternalBorderStrokeFill||this.primaryBorderColor,this.quadrantExternalBorderStrokeFill=this.quadrantExternalBorderStrokeFill||this.primaryBorderColor,this.quadrantTitleFill=this.quadrantTitleFill||this.primaryTextColor,this.xyChart={backgroundColor:this.xyChart?.backgroundColor||this.background,titleColor:this.xyChart?.titleColor||this.primaryTextColor,legendTextColor:this.xyChart?.legendTextColor||this.primaryTextColor,xAxisTitleColor:this.xyChart?.xAxisTitleColor||this.primaryTextColor,xAxisLabelColor:this.xyChart?.xAxisLabelColor||this.primaryTextColor,xAxisTickColor:this.xyChart?.xAxisTickColor||this.primaryTextColor,xAxisLineColor:this.xyChart?.xAxisLineColor||this.primaryTextColor,yAxisTitleColor:this.xyChart?.yAxisTitleColor||this.primaryTextColor,yAxisLabelColor:this.xyChart?.yAxisLabelColor||this.primaryTextColor,yAxisTickColor:this.xyChart?.yAxisTickColor||this.primaryTextColor,yAxisLineColor:this.xyChart?.yAxisLineColor||this.primaryTextColor,plotColorPalette:this.xyChart?.plotColorPalette||"#FFF4DD,#FFD8B1,#FFA07A,#ECEFF1,#D6DBDF,#C3E0A8,#FFB6A4,#FFD74D,#738FA7,#FFFFF0"},this.requirementBackground=this.requirementBackground||S,this.requirementBorderColor=this.requirementBorderColor||this.primaryBorderColor,this.requirementBorderSize=this.requirementBorderSize||"1",this.requirementTextColor=this.requirementTextColor||this.primaryTextColor,this.relationColor=this.relationColor||this.lineColor,this.relationLabelBackground=this.relationLabelBackground||(this.darkMode?me(this.secondaryColor,30):this.secondaryColor),this.relationLabelColor=this.relationLabelColor||this.actorTextColor,this.requirementEdgeLabelBackground="#FFFFFF",this.git0=this.git0||S,this.git1=this.git1||I,this.git2=this.git2||W,this.git3=this.git3||R(S,{h:-30}),this.git4=this.git4||R(S,{h:-60}),this.git5=this.git5||R(S,{h:-90}),this.git6=this.git6||R(S,{h:60}),this.git7=this.git7||R(S,{h:120}),this.darkMode)this.git0=he(this.git0,25),this.git1=he(this.git1,25),this.git2=he(this.git2,25),this.git3=he(this.git3,25),this.git4=he(this.git4,25),this.git5=he(this.git5,25),this.git6=he(this.git6,25),this.git7=he(this.git7,25);else this.git0=me(this.git0,25),this.git1=me(this.git1,25),this.git2=me(this.git2,25),this.git3=me(this.git3,25),this.git4=me(this.git4,25),this.git5=me(this.git5,25),this.git6=me(this.git6,25),this.git7=me(this.git7,25);this.gitInv0=this.gitInv0||oe(this.git0),this.gitInv1=this.gitInv1||oe(this.git1),this.gitInv2=this.gitInv2||oe(this.git2),this.gitInv3=this.gitInv3||oe(this.git3),this.gitInv4=this.gitInv4||oe(this.git4),this.gitInv5=this.gitInv5||oe(this.git5),this.gitInv6=this.gitInv6||oe(this.git6),this.gitInv7=this.gitInv7||oe(this.git7),this.branchLabelColor=this.branchLabelColor||(this.darkMode?"black":this.labelTextColor),this.gitBranchLabel0=this.gitBranchLabel0||this.branchLabelColor,this.gitBranchLabel1=this.gitBranchLabel1||this.branchLabelColor,this.gitBranchLabel2=this.gitBranchLabel2||this.branchLabelColor,this.gitBranchLabel3=this.gitBranchLabel3||this.branchLabelColor,this.gitBranchLabel4=this.gitBranchLabel4||this.branchLabelColor,this.gitBranchLabel5=this.gitBranchLabel5||this.branchLabelColor,this.gitBranchLabel6=this.gitBranchLabel6||this.branchLabelColor,this.gitBranchLabel7=this.gitBranchLabel7||this.branchLabelColor,this.tagLabelColor=this.tagLabelColor||this.primaryTextColor,this.tagLabelBackground=this.tagLabelBackground||this.primaryColor,this.tagLabelBorder=this.tagBorder||this.primaryBorderColor,this.tagLabelFontSize=this.tagLabelFontSize||"10px",this.commitLabelColor=this.commitLabelColor||this.secondaryTextColor,this.commitLabelBackground=this.commitLabelBackground||this.secondaryColor,this.commitLineColor=this.commitLineColor??"#BDBCCC",this.commitLabelFontSize=this.commitLabelFontSize||"10px",this.fontWeight=600,this.erEdgeLabelBackground="#FFFFFF",this.attributeBackgroundColorOdd=this.attributeBackgroundColorOdd||Zr,this.attributeBackgroundColorEven=this.attributeBackgroundColorEven||ei}calculate(S){if(typeof S!=="object"){this.updateColors();return}let I=Object.keys(S);I.forEach(W=>{this[W]=S[W]}),this.updateColors(),I.forEach(W=>{this[W]=vr(this[W],S[W])})}}var tO=v=>{let S=new eO;return S.calculate(v),S};class rO{constructor(){this.background="#333",this.primaryColor="#1f2020",this.secondaryColor=he(this.primaryColor,16),this.tertiaryColor=R(this.primaryColor,{h:-160}),this.primaryBorderColor=oe(this.background),this.secondaryBorderColor=Ue(this.secondaryColor,this.darkMode),this.tertiaryBorderColor=Ue(this.tertiaryColor,this.darkMode),this.primaryTextColor=oe(this.primaryColor),this.secondaryTextColor=oe(this.secondaryColor),this.tertiaryTextColor=oe(this.tertiaryColor),this.mainBkg="#111113",this.secondBkg="calculated",this.mainContrastColor="lightgrey",this.darkTextColor=he(oe("#323D47"),10),this.border1="#ccc",this.border2=fr(255,255,255,.25),this.arrowheadColor=oe(this.background),this.fontFamily='"Recursive Variable", arial, sans-serif',this.fontSize="14px",this.labelBackground="#111113",this.textColor="#ccc",this.THEME_COLOR_LIMIT=12,this.radius=12,this.strokeWidth=2,this.noteBkgColor=this.noteBkgColor??"#FEF9C3",this.noteTextColor=this.noteTextColor??"#28253D",this.THEME_COLOR_LIMIT=12,this.fontFamily='"Recursive Variable", arial, sans-serif',this.fontSize="14px",this.nodeBorder="#FFFFFF",this.stateBorder="#FFFFFF",this.useGradient=false,this.gradientStart="#0042eb",this.gradientStop="#eb0042",this.dropShadow="url(#drop-shadow)",this.nodeShadow=true,this.archEdgeColor="calculated",this.archEdgeArrowColor="calculated",this.archEdgeWidth="3",this.archGroupBorderColor=this.primaryBorderColor,this.archGroupBorderWidth="2px",this.clusterBkg="#1E1A2E",this.clusterBorder="#BDBCCC",this.noteBorderColor="#FACC15",this.noteFontWeight=600,this.borderColorArray=["#E879F9","#2DD4BF","#FB923C","#22D3EE","#4ADE80","#A78BFA","#F87171","#FACC15","#818CF8","#A3E635 ","#38BDF8","#FB7185"],this.bkgColorArray=[],this.usecaseActorBorder="#A78BFA",this.usecaseBorder="#2DD4BF",this.usecaseBoundaryBorder="#BDBCCC",this.usecaseIncludeLine="#38BDF8",this.usecaseExtendLine="#FB923C",this.filterColor="#FFFFFF"}updateColors(){this.primaryTextColor=this.primaryTextColor||(this.darkMode?"#eee":"#FFFFFF"),this.secondaryColor=this.secondaryColor||R(this.primaryColor,{h:-120}),this.tertiaryColor=this.tertiaryColor||R(this.primaryColor,{h:180,l:5}),this.primaryBorderColor=this.primaryBorderColor||Ue(this.primaryColor,this.darkMode),this.secondaryBorderColor=this.secondaryBorderColor||Ue(this.secondaryColor,this.darkMode),this.tertiaryBorderColor=this.tertiaryBorderColor||Ue(this.tertiaryColor,this.darkMode),this.noteBorderColor=this.noteBorderColor||Ue(this.noteBkgColor,this.darkMode),this.noteBkgColor=this.noteBkgColor||"#fff5ad",this.noteTextColor=this.noteTextColor||"#FFFFFF",this.secondaryTextColor=this.secondaryTextColor||oe(this.secondaryColor),this.tertiaryTextColor=this.tertiaryTextColor||oe(this.tertiaryColor),this.lineColor=this.lineColor||oe(this.background),this.arrowheadColor=this.arrowheadColor||oe(this.background),this.textColor=this.textColor||this.primaryTextColor,this.border2=this.border2||this.tertiaryBorderColor,this.nodeBkg=this.nodeBkg||this.primaryColor,this.mainBkg=this.mainBkg||this.primaryColor,this.secondBkg=this.secondBkg==="calculated"?he(this.mainBkg,16):this.secondBkg,this.nodeBorder=this.nodeBorder||this.border1,this.clusterBkg=this.clusterBkg||this.tertiaryColor,this.clusterBorder=this.clusterBorder||this.tertiaryBorderColor,this.defaultLinkColor=this.defaultLinkColor||this.lineColor,this.titleColor=this.titleColor||this.tertiaryTextColor,this.edgeLabelBackground=this.edgeLabelBackground||(this.darkMode?me(this.secondaryColor,30):this.secondaryColor),this.nodeTextColor=this.nodeTextColor||this.primaryTextColor,this.flowContainerStroke=this.flowContainerStroke||this.secondaryBorderColor,this.actorBorder="#FFFFFF",this.signalColor="#FFFFFF",this.labelBoxBorderColor="#BDBCCC",this.actorBorder=this.actorBorder||this.primaryBorderColor,this.actorBkg=this.actorBkg||this.mainBkg,this.actorTextColor=this.actorTextColor||this.primaryTextColor,this.actorLineColor=this.actorLineColor||this.actorBorder,this.labelBoxBkgColor=this.labelBoxBkgColor||this.actorBkg,this.signalColor=this.signalColor||this.textColor,this.signalTextColor=this.signalTextColor||this.textColor,this.labelBoxBorderColor=this.labelBoxBorderColor||this.actorBorder,this.labelTextColor=this.labelTextColor||this.actorTextColor,this.loopTextColor=this.loopTextColor||this.actorTextColor,this.activationBorderColor=this.activationBorderColor||me(this.secondaryColor,10),this.activationBkgColor=this.activationBkgColor||this.secondaryColor,this.sequenceNumberColor=this.sequenceNumberColor||oe(this.lineColor),this.rectBkgColor=this.rectBkgColor||this.tertiaryColor,this.rootLabelColor="#FFFFFF",this.excludeBkgColor=this.excludeBkgColor||"#eeeeee",this.taskBorderColor=this.taskBorderColor||this.primaryBorderColor,this.taskBkgColor=this.taskBkgColor||this.primaryColor,this.activeTaskBorderColor=this.activeTaskBorderColor||this.primaryColor,this.activeTaskBkgColor=this.activeTaskBkgColor||he(this.primaryColor,23),this.gridColor=this.gridColor||"lightgrey",this.doneTaskBkgColor=this.doneTaskBkgColor||this.secondBkg,this.doneTaskBorderColor=this.doneTaskBorderColor||"grey",this.critBorderColor=this.critBorderColor||"#ff8888",this.critBkgColor=this.critBkgColor||"red",this.todayLineColor=this.todayLineColor||"red",this.taskTextColor=this.taskTextColor||this.textColor,this.vertLineColor=this.vertLineColor||this.primaryBorderColor,this.taskTextOutsideColor=this.taskTextOutsideColor||this.textColor,this.taskTextLightColor=this.taskTextLightColor||this.textColor,this.taskTextColor=this.taskTextColor||this.primaryTextColor,this.taskTextDarkColor=this.taskTextDarkColor||this.textColor,this.taskTextClickableColor=this.taskTextClickableColor||"#003163",this.archEdgeColor=this.lineColor,this.archEdgeArrowColor=this.lineColor,this.personBorder=this.personBorder||this.primaryBorderColor,this.personBkg=this.personBkg||this.mainBkg,this.transitionColor=this.transitionColor||this.lineColor,this.transitionLabelColor=this.transitionLabelColor||this.textColor,this.stateLabelColor=this.stateLabelColor||this.stateBkg||this.primaryTextColor,this.stateEdgeLabelBackground=this.stateEdgeLabelBackground||"#16141F",this.stateBkg=this.stateBkg||this.mainBkg,this.labelBackgroundColor=this.labelBackgroundColor||this.stateBkg,this.compositeBackground=this.compositeBackground||"#16141F",this.altBackground=this.altBackground||"#16141F",this.compositeTitleBackground=this.compositeTitleBackground||"#16141F",this.compositeBorder=this.compositeBorder||this.nodeBorder,this.innerEndBackground=this.nodeBorder,this.errorBkgColor=this.errorBkgColor||this.tertiaryColor,this.errorTextColor=this.errorTextColor||this.tertiaryTextColor,this.transitionColor=this.transitionColor||this.lineColor,this.specialStateColor=this.lineColor,this.cScale0=this.cScale0||"#f4a8ff",this.cScale1=this.cScale1||"#46ecd5",this.cScale2=this.cScale2||"#ffb86a",this.cScale3=this.cScale3||"#dab2ff",this.cScale4=this.cScale4||"#7bf1a8",this.cScale5=this.cScale5||"#c4b4ff",this.cScale6=this.cScale6||"#ffa2a2",this.cScale7=this.cScale7||"#ffdf20",this.cScale8=this.cScale8||"#a3b3ff",this.cScale9=this.cScale9||"#bbf451",this.cScale10=this.cScale10||"#74d4ff",this.cScale11=this.cScale11||"#ffa1ad",this.sectionBkgColor=this.sectionBkgColor||this.cScale0,this.sectionBkgColor2=this.sectionBkgColor2||this.cScale1,this.altSectionBkgColor=this.altSectionBkgColor||this.background;for(let I=0;I<this.THEME_COLOR_LIMIT;I++){e();this["cScaleInv"+I]=this["cScaleInv"+I]||oe(this["cScale"+I])}for(let I=0;I<this.THEME_COLOR_LIMIT;I++){e();if(this.darkMode)this["cScalePeer"+I]=this["cScalePeer"+I]||he(this["cScale"+I],10);else this["cScalePeer"+I]=this["cScalePeer"+I]||me(this["cScale"+I],10)}this.scaleLabelColor=this.scaleLabelColor||this.labelTextColor;for(let I=0;I<this.THEME_COLOR_LIMIT;I++){e();this["cScaleLabel"+I]=me(this["cScale"+I],75)}let S=this.darkMode?-4:-1;for(let I=0;I<5;I++){e();this["surface"+I]=this["surface"+I]||R(this.mainBkg,{h:180,s:-15,l:S*(5+I*3)}),this["surfacePeer"+I]=this["surfacePeer"+I]||R(this.mainBkg,{h:180,s:-15,l:S*(8+I*3)})}this.classText=this.classText||this.textColor,["#701a75","#134e4a","#7c2d12","#581c87","#14532d","#4c1d95","#7f1d1d","#713f12"].forEach((I,W)=>{this["fillType"+W]=this["fillType"+W]||I});for(let I=0;I<this.THEME_COLOR_LIMIT;I++){e();this["pie"+(I+1)]=this["pie"+(I+1)]||this["cScale"+I]}this.pieTitleTextSize=this.pieTitleTextSize||"25px",this.pieTitleTextColor=this.pieTitleTextColor||this.taskTextDarkColor,this.pieSectionTextSize=this.pieSectionTextSize||"17px",this.pieSectionTextColor=this.pieSectionTextColor||"#28253D",this.pieLegendTextSize=this.pieLegendTextSize||"17px",this.pieLegendTextColor=this.pieLegendTextColor||this.taskTextDarkColor,this.pieStrokeColor=this.pieStrokeColor||"black",this.pieStrokeWidth=this.pieStrokeWidth||"2px",this.pieOuterStrokeWidth=this.pieOuterStrokeWidth||"2px",this.pieOuterStrokeColor=this.pieOuterStrokeColor||"black",this.pieOpacity=this.pieOpacity||"0.7";for(let I=0;I<8;I++){e();this["venn"+(I+1)]=this["venn"+(I+1)]??this.borderColorArray[I%this.borderColorArray.length]}if(this.vennTitleTextColor=this.vennTitleTextColor??this.titleColor,this.vennSetTextColor=this.vennSetTextColor??this.textColor,this.quadrant1Fill=this.quadrant1Fill||this.primaryColor,this.quadrant2Fill=this.quadrant2Fill||R(this.primaryColor,{r:5,g:5,b:5}),this.quadrant3Fill=this.quadrant3Fill||R(this.primaryColor,{r:10,g:10,b:10}),this.quadrant4Fill=this.quadrant4Fill||R(this.primaryColor,{r:15,g:15,b:15}),this.quadrant1TextFill=this.quadrant1TextFill||this.primaryTextColor,this.quadrant2TextFill=this.quadrant2TextFill||R(this.primaryTextColor,{r:-5,g:-5,b:-5}),this.quadrant3TextFill=this.quadrant3TextFill||R(this.primaryTextColor,{r:-10,g:-10,b:-10}),this.quadrant4TextFill=this.quadrant4TextFill||R(this.primaryTextColor,{r:-15,g:-15,b:-15}),this.quadrantPointFill=this.quadrantPointFill||tr(this.quadrant1Fill)?he(this.quadrant1Fill):me(this.quadrant1Fill),this.quadrantPointTextFill=this.quadrantPointTextFill||this.primaryTextColor,this.quadrantXAxisTextFill=this.quadrantXAxisTextFill||this.primaryTextColor,this.quadrantYAxisTextFill=this.quadrantYAxisTextFill||this.primaryTextColor,this.quadrantInternalBorderStrokeFill=this.quadrantInternalBorderStrokeFill||this.primaryBorderColor,this.quadrantExternalBorderStrokeFill=this.quadrantExternalBorderStrokeFill||this.primaryBorderColor,this.quadrantTitleFill=this.quadrantTitleFill||this.primaryTextColor,this.xyChart={backgroundColor:this.xyChart?.backgroundColor||this.background,titleColor:this.xyChart?.titleColor||this.primaryTextColor,legendTextColor:this.xyChart?.legendTextColor||this.primaryTextColor,xAxisTitleColor:this.xyChart?.xAxisTitleColor||this.primaryTextColor,xAxisLabelColor:this.xyChart?.xAxisLabelColor||this.primaryTextColor,xAxisTickColor:this.xyChart?.xAxisTickColor||this.primaryTextColor,xAxisLineColor:this.xyChart?.xAxisLineColor||this.primaryTextColor,yAxisTitleColor:this.xyChart?.yAxisTitleColor||this.primaryTextColor,yAxisLabelColor:this.xyChart?.yAxisLabelColor||this.primaryTextColor,yAxisTickColor:this.xyChart?.yAxisTickColor||this.primaryTextColor,yAxisLineColor:this.xyChart?.yAxisLineColor||this.primaryTextColor,plotColorPalette:this.xyChart?.plotColorPalette||"#FFF4DD,#FFD8B1,#FFA07A,#ECEFF1,#D6DBDF,#C3E0A8,#FFB6A4,#FFD74D,#738FA7,#FFFFF0"},this.requirementBackground=this.requirementBackground||this.primaryColor,this.requirementBorderColor=this.requirementBorderColor||this.primaryBorderColor,this.requirementBorderSize=this.requirementBorderSize||"1",this.requirementTextColor=this.requirementTextColor||this.primaryTextColor,this.relationColor=this.relationColor||this.lineColor,this.relationLabelBackground=this.relationLabelBackground||(this.darkMode?me(this.secondaryColor,30):this.secondaryColor),this.relationLabelColor=this.relationLabelColor||this.actorTextColor,this.requirementEdgeLabelBackground="#16141F",this.git0=this.git0||this.primaryColor,this.git1=this.git1||this.secondaryColor,this.git2=this.git2||this.tertiaryColor,this.git3=this.git3||R(this.primaryColor,{h:-30}),this.git4=this.git4||R(this.primaryColor,{h:-60}),this.git5=this.git5||R(this.primaryColor,{h:-90}),this.git6=this.git6||R(this.primaryColor,{h:60}),this.git7=this.git7||R(this.primaryColor,{h:120}),this.darkMode)this.git0=he(this.git0,25),this.git1=he(this.git1,25),this.git2=he(this.git2,25),this.git3=he(this.git3,25),this.git4=he(this.git4,25),this.git5=he(this.git5,25),this.git6=he(this.git6,25),this.git7=he(this.git7,25);else this.git0=me(this.git0,25),this.git1=me(this.git1,25),this.git2=me(this.git2,25),this.git3=me(this.git3,25),this.git4=me(this.git4,25),this.git5=me(this.git5,25),this.git6=me(this.git6,25),this.git7=me(this.git7,25);this.gitInv0=this.gitInv0||oe(this.git0),this.gitInv1=this.gitInv1||oe(this.git1),this.gitInv2=this.gitInv2||oe(this.git2),this.gitInv3=this.gitInv3||oe(this.git3),this.gitInv4=this.gitInv4||oe(this.git4),this.gitInv5=this.gitInv5||oe(this.git5),this.gitInv6=this.gitInv6||oe(this.git6),this.gitInv7=this.gitInv7||oe(this.git7),this.branchLabelColor=this.branchLabelColor||(this.darkMode?"black":this.labelTextColor),this.gitBranchLabel0=this.gitBranchLabel0||this.branchLabelColor,this.gitBranchLabel1=this.gitBranchLabel1||this.branchLabelColor,this.gitBranchLabel2=this.gitBranchLabel2||this.branchLabelColor,this.gitBranchLabel3=this.gitBranchLabel3||this.branchLabelColor,this.gitBranchLabel4=this.gitBranchLabel4||this.branchLabelColor,this.gitBranchLabel5=this.gitBranchLabel5||this.branchLabelColor,this.gitBranchLabel6=this.gitBranchLabel6||this.branchLabelColor,this.gitBranchLabel7=this.gitBranchLabel7||this.branchLabelColor,this.tagLabelColor=this.tagLabelColor||this.primaryTextColor,this.tagLabelBackground=this.tagLabelBackground||this.primaryColor,this.tagLabelBorder=this.tagBorder||this.primaryBorderColor,this.tagLabelFontSize=this.tagLabelFontSize||"10px",this.commitLabelColor=this.commitLabelColor||this.secondaryTextColor,this.commitLabelBackground=this.commitLabelBackground||this.secondaryColor,this.commitLabelFontSize=this.commitLabelFontSize||"10px",this.commitLineColor=this.commitLineColor??"#BDBCCC",this.fontWeight=600,this.erEdgeLabelBackground="#16141F",this.attributeBackgroundColorOdd=this.attributeBackgroundColorOdd||Zr,this.attributeBackgroundColorEven=this.attributeBackgroundColorEven||ei}calculate(S){if(typeof S!=="object"){this.updateColors();return}let I=Object.keys(S);I.forEach(W=>{this[W]=S[W]}),this.updateColors(),I.forEach(W=>{this[W]=vr(this[W],S[W])})}}var iO=v=>{let S=new rO;return S.calculate(v),S};var ws={base:{getThemeVariables:PA},dark:{getThemeVariables:$A},default:{getThemeVariables:zA},forest:{getThemeVariables:WA},neutral:{getThemeVariables:jA},neo:{getThemeVariables:YA},"neo-dark":{getThemeVariables:XA},redux:{getThemeVariables:JA},"redux-dark":{getThemeVariables:ZA},"redux-color":{getThemeVariables:tO},"redux-dark-color":{getThemeVariables:iO}};var nO={"flowchart-v2":"flowchart","flowchart-elk":"flowchart",classDiagram:"class",stateDiagram:"state",xychart:"xyChart",railroadAbnf:"railroad",railroadEbnf:"railroad",railroadPeg:"railroad"},oO=v=>nO[v]??v;var nl=Object.freeze(o),sO=["theme","look","layout"],aO=new Set(["classic","handDrawn","neo"]),lO=(v,S)=>{if(v==="theme")return S==="null"||Object.hasOwn(ws,S);return v!=="look"||aO.has(S)},cO=(v,S,I)=>{if(!v)return;return[v[S]?.[I],v[I]].find(W=>W!==void 0&&lO(I,W))};var ti=i({},nl),Vp,Yp={},wn=[],pu=i({},nl),Ts,dO=(v,S)=>{if(!Ts)return;let I=[S,...[...wn].reverse(),Yp,nl],W=v[Ts];for(let ye of sO){e();for(let te of I){e();let Te=cO(te,Ts,ye);if(Te===void 0)continue;if(v[ye]=Te,W?.[ye]!==void 0)W[ye]=Te;break}}},ol=(v,S)=>{let I=i({},v),W={};for(let ye of S){e();Xp(ye),W=i(W,ye)}if(I=i(I,W),dO(I,W),(Boolean(W.theme)||I.theme!==v.theme)&&I.theme&&Object.hasOwn(ws,I.theme)){let ye=i({},Vp),te=i(ye.themeVariables||{},W.themeVariables);I.themeVariables=ws[I.theme].getThemeVariables(te)}return pu=I,gO(pu),pu},Hp=v=>{Ts=v===void 0?void 0:oO(v),ol(ti,wn)},uO=v=>{if(ti=i({},nl),ti=i(ti,v),Yp=i({},v),v.theme&&Object.hasOwn(ws,v.theme))ti.themeVariables=ws[v.theme].getThemeVariables(v.themeVariables);return ol(ti,wn),ti},hO=v=>{Vp=i({},v)};var Xp=v=>{if(!v)return;["secure",...ti.secure??[]].forEach(S=>{if(Object.hasOwn(v,S))a.debug(`Denied attempt to modify a secure key ${S}`,v[S]),delete v[S]}),Object.keys(v).forEach(S=>{if(S.startsWith("__"))delete v[S]}),Object.keys(v).forEach(S=>{if(typeof v[S]==="string"&&(v[S].includes("<")||v[S].includes(">")||v[S].includes("url(data:")))delete v[S];if(typeof v[S]==="object")Xp(v[S])})},mO=v=>{if(d(v),v.fontFamily&&!v.themeVariables?.fontFamily)v.themeVariables={...v.themeVariables,fontFamily:v.fontFamily};wn.push(v),ol(ti,wn)},Kp=(v=ti)=>{wn=[],Ts=void 0,ol(v,wn)},fO={LAZY_LOAD_DEPRECATED:"The configuration options lazyLoadedDiagrams and loadExternalDiagramsAtStartup are deprecated. Please use registerExternalDiagrams instead.",FLOWCHART_HTML_LABELS_DEPRECATED:"flowchart.htmlLabels is deprecated. Please use global htmlLabels instead."},Jp={},pO=v=>{if(Jp[v])return;a.warn(fO[v]),Jp[v]=true},gO=v=>{if(!v)return;if(v.lazyLoadedDiagrams||v.loadExternalDiagramsAtStartup)pO("LAZY_LOAD_DEPRECATED")};var Qp={debug(){},error(){}},gu="",vs=false,yO=()=>gu;function Zp(v,S){if(!v||!S||typeof v!=="object"||typeof S!=="object")return;for(let I of Object.keys(S)){e();if(typeof v[I]==="string"&&typeof S[I]==="string")S[I]=v[I];else Zp(v[I],S[I])}}function xO(v){let S=vs?structuredClone(v):void 0;if(d(v),S)Zp(S,v)}var Tn=/%{2}{\s*(?:(\w+)\s*:|(\w+))\s*(?:(\w+)|((?:(?!}%{2}).|\r?\n)*))?\s*(?:}%{2})?/gi,bO=/\s*(?:(\w+)(?=:):|(\w+))\s*(?:(\w+)|((?:(?!}%{2}).|\r?\n)*))?\s*(?:}%{2})?/gi,yu=function(v,S=null){try{let I=new RegExp(`[%]{2}(?![{]${bO.source})(?=[}][%]{2}).*
189
+ `,"ig");v=v.trim().replace(I,"").replace(/'/gm,'"'),Qp.debug(`Detecting diagram directive${S!==null?" type:"+S:""} based on the text:${v}`);let W,ye=[];while((W=Tn.exec(v))!==null){e();if(W.index===Tn.lastIndex)Tn.lastIndex++;if(W&&!S||S&&W[1]?.match(S)||S&&W[2]?.match(S)){let te=W[1]?W[1]:W[2],Te=W[3]?W[3].trim():W[4]?JSON.parse(W[4].trim()):null;ye.push({type:te,args:Te})}}if(ye.length===0)return{type:v,args:null};return ye.length===1?ye[0]:ye}catch(I){return Qp.error(`ERROR: ${I.message} - Unable to parse directive type: '${S}' based on the text: '${v}'`),{type:void 0,args:null}}},CO=function(v,S){let I=yu(v,/(?:init\b)|(?:initialize\b)/),W={};if(Array.isArray(I)){let Te=I.map(De=>De.args);xO(Te),W=i(W,[...Te])}else W=I.args;if(!W)return;let ye=yO(v,S),te="config";if(W[te]!==void 0){if(ye==="flowchart-v2")ye="flowchart";W[ye]=W[te],delete W[te]}return W},kO=function(v){return v.replace(Tn,"")},eg={detectInit:CO,detectDirective:yu},SO=v=>{let S=eg.detectInit(v)??{},I=eg.detectDirective(v,"wrap");if(Array.isArray(I))S.wrap=I.some(({type:W})=>W==="wrap");else if(I?.type==="wrap")S.wrap=true;return{text:kO(v),directive:S}};function tg(v,S,I=true){if(!/^\w+$/.test(v))throw Error("Invalid directive name");if(!I)return"%%{"+v+"}%%";let W=(Object.is(S,-0)?"-0":JSON.stringify(S)).replace(/[&<>#%'\u2028\u2029]/g,De=>"\\u"+De.charCodeAt(0).toString(16).padStart(4,"0")),ye="%%{"+v+": "+W+"}%%";Tn.lastIndex=0;let te=Tn.exec(ye);Tn.lastIndex=0;let Te=yu(ye,v);if(!te||te[0]!==ye||!Object.is(typeof Te.args,typeof S))throw Error("init argument has no complete pinned scalar token");return ye}function xu(v){return tg("init",v)}function bu(v,S,I,W=false){gu=I,vs=W;try{return pe({},structuredClone(v),SO(S).directive)}finally{vs=false}}function wO(v,S,I,W=false,ye=false){gu=I,vs=ye;try{let te=S.map(xu).join(`
190
+ `)+(W?`
191
+ %%{wrap}%%`:"");return bu(v,te,I,ye)}finally{vs=false}}function TO(v,S,I,W={},ye=false){return rg(v,S.map(xu).join(`
192
+ `)+(ye?`
193
+ %%{wrap}%%`:""),I,W)}function rg(v,S,I,W={}){let ye=structuredClone(v);if(W.title)W.title.toString();if(W.displayMode){let Te=W.displayMode.toString();if(!ye.gantt)ye.gantt={};ye.gantt.displayMode=Te}let te=bu(ye,S,I);Kp(),hO({}),uO({});try{Hp(I),mO(te)}finally{try{Hp(void 0)}finally{Kp()}}}return{configDirective:tg,initDirective:xu,mergeConfig:wO,mergeConfigSource:bu,validateConfig:TO,validateConfigSource:rg}}function DE(...t){return RE().validateConfig(...t)}function hp(...t){return RE().validateConfigSource(...t)}function NE(t,e){const r=t.wrapperSource!==void 0;const i=r?Ay(t.wrapperSource):Ru({},t.frontmatter??{});const n={};for(const d of["title","displayMode"]){if(i[d]!==void 0){n[d]=i[d];delete i[d]}}const o=r&&i.config&&typeof i.config==="object"&&!Array.isArray(i.config)?i.config:{};if(r)delete i.config;const s=Ru(o,i);const a=t.initDirectives.map(d=>{const u=My(d.raw);if(u===void 0)throw new Error("Cannot export canonical Mermaid: init directive payload must be a configuration object or a valid JSON no-op; repair the directive or use verbatim wrapper mode to preserve its source");return u});const l=a.filter(d=>d.kind==="init").map(d=>d.payload);const c=cy(e??"");try{const d=a.map(h=>gl(h.kind,h.payload,h.hasArgs)).join("\n");if(l.length>1||n.displayMode&&l.length||a.some(h=>h.kind!=="init"&&h.kind!=="wrap")){hp(s,d,c,n);return{metadata:n,config:s,directives:a}}if(r&&typeof c==="string"&&!Object.keys(n).length&&!Object.keys(s).length&&d===""){const h=yy(e??"");if(h&&ay(h))return{metadata:n,config:s,directives:[]}}hp(s,d,c,n);const u=ly(s,d,c);DE(u,[],c,n);return{metadata:n,config:u,directives:[]}}catch(d){if(d instanceof Error&&d.name==="MermaidConfigWorkLimitError")throw new Error(`Cannot export canonical Mermaid: ${d.message}; reduce the config's work before retrying. This is a validation resource limit, not a pinned syntax rejection.`);throw new Error(`Cannot export canonical Mermaid: pinned configuration processing rejects this value (${d instanceof Error?d.message:String(d)}); repair the config or use verbatim wrapper mode to preserve its source`)}}function ao(t,e={}){if(t.body.kind==="preserved")return t.body.source;const r=e.wrapper??"verbatim";const i=t.body.kind==="zenuml"?Mc(t.body.title,t.meta,true):t.body.kind==="eventmodeling"?Fk(t.body,t.meta):t.meta;const n=ZL(t.body,t.kind,i,t.body.kind==="extension"&&"descriptorIdentity"in t?t.descriptorIdentity:void 0);const o=LE(n,t.kind,t.body,i);const s=r==="canonical"?Ey(o):o;const a=r==="canonical"?{...i,initDirectives:KL(i,o)}:i;return mp(a,r,s,t.kind)+s}function KL(t,e){const r=[...t.initDirectives];const i=new Map;for(const n of r){const o=Is(n);i.set(o,(i.get(o)??0)+1)}for(const n of Lu(e)){const o=Is(n);const s=i.get(o)??0;if(s)i.set(o,s-1);else r.push(n)}return r}function mp(t,e="verbatim",r="",i){if(e==="verbatim"&&t.wrapperSource!==void 0){const n=Cl(t.wrapperSource);const o=n&&n.yaml===""?t.wrapperSource.slice(n.source.length):t.wrapperSource;return o+JL(t,r)}return QL(t,i)}function JL(t,e){if(t.initDirectives.length===0)return"";const r=new Map;for(const n of[t.wrapperSource??"",e]){for(const o of Lu(n)){const s=Is(o);r.set(s,(r.get(s)??0)+1)}}const i=[];for(const n of t.initDirectives){const o=Is(n);const s=r.get(o)??0;if(s>0){r.set(o,s-1);continue}i.push(n.raw.trimEnd()+"\n")}return i.join("")}function QL(t,e){const r=[];const i=NE(t,e);if(Object.keys(i.metadata).length||Object.keys(i.config).length){const n={...i.metadata};if(Object.keys(i.config).length)n.config=i.config;r.push(`---
194
+ ${vy(n)}---
195
+ `)}for(const n of i.directives){r.push(gl(n.kind,n.payload,n.hasArgs)+"\n")}return r.join("")}function ZL(t,e,r,i){if(t.kind==="opaque"&&(t.family==="eventmodeling"||t.family==="zenuml"))return t.source;if(t.kind==="opaque")return t.source.endsWith("\n")?t.source:t.source+"\n";if(t.kind==="preserved")return t.source;const n=Ii(e);const o=t.kind!=="extension"||fl(i,n?.identity);if(n?.serialize&&o){const s=n.serialize(t,r);const a=rx(s,r.accessibility);const l=t.kind==="extension"?void 0:Zy(a,n.statementEnds);if(l)throw new xo(l);return a}if(t.kind==="extension")return t.source.endsWith("\n")?t.source:t.source+"\n";throw new Error(`No serializer registered for diagram kind "${e}"`)}function O6(t){if(!t||typeof t!=="object"||Array.isArray(t)){return T([{code:"INVALID_PAYLOAD",message:"payload must be a diagram object"}])}const e=t.body;if(!e||typeof e!=="object"||typeof e.kind!=="string"){return T([{code:"INVALID_PAYLOAD",message:"payload.body.kind must be a string"}])}const r=t.kind;if(typeof r!=="string"||!zh().includes(r)){return T([{code:"INVALID_PAYLOAD",message:`payload.kind must be a known diagram family, received ${typeof r==="string"?r:typeof r}`}])}const i=e.kind;const n=i==="opaque"||i==="extension"?e.family:i;if(n!==r){return T([{code:"INVALID_PAYLOAD",message:`payload kind "${r}" does not match body family "${typeof n==="string"?n:typeof n}"`}])}if(i==="pie"){const o=e;if(typeof o.showData!=="boolean"||o.title!==void 0&&typeof o.title!=="string"||!Array.isArray(o.slices)||o.slices.some(s=>!s||typeof s!=="object"||typeof s.id!=="string"||typeof s.label!=="string"||typeof s.value!=="number"||!Number.isFinite(s.value)||s.value<=0)){return T([{code:"INVALID_PAYLOAD",message:"payload pie body must contain typed positive finite slices"}])}}try{if(i==="extension"){const a=e.source;const l=t.canonicalSource;const c=t.meta?.wrapperSource;const d=typeof a==="string"&&a.trim()?(typeof c==="string"?c:"")+a:l;if(typeof d!=="string"||!d.trim()){return T([{code:"INVALID_PAYLOAD",message:"extension payload must retain canonicalSource or body.source"}])}const u=gs(d);if(!u.ok||u.value.kind!==r||u.value.body.kind!=="extension"){const h=u.ok?`serialized source reparsed as ${u.value.kind}/${u.value.body.kind}`:u.error.map(m=>m.message).join("; ");return T([{code:"INVALID_PAYLOAD",message:`serialized extension payload is not a valid ${r} diagram: ${h}`}])}return re(u.value)}const o=eR(t);if(!o.ok)return o;const s=gs(o.value.canonicalSource);if(!s.ok||s.value.kind!==o.value.kind){const a=s.ok?`serialized source reparsed as ${s.value.kind}/${s.value.body.kind}`:s.error.map(l=>l.message).join("; ");return T([{code:"INVALID_PAYLOAD",message:`serialized payload is not a valid ${r} diagram: ${a}`}])}return re({...s.value,canonicalSource:ao(s.value)})}catch(o){return T([{code:"INVALID_PAYLOAD",message:`could not rebuild diagram from payload: ${o.message}`}])}}function eR(t){const e={initDirectives:t.meta?.initDirectives??[],comments:t.meta?.comments??[],accessibility:t.meta?.accessibility??{},frontmatter:t.meta?.frontmatter,wrapperSource:t.meta?.wrapperSource,bodyComments:t.meta?.bodyComments};let r;if(t.body.kind==="flowchart"){const n=t.body.graph;const o=Array.isArray(n?.nodes)?new Map(n.nodes):n?.nodes?new Map(Object.entries(n.nodes)):new Map;r={kind:"flowchart",graph:{direction:n.direction,nodes:o,edges:n.edges??[],subgraphs:PE(n.subgraphs),classDefs:Kd(n.classDefs),classAssignments:Kd(n.classAssignments),nodeStyles:Kd(n.nodeStyles),linkStyles:tR(n.linkStyles)}}}else if(t.body.kind==="radar"){const n=ad(t.body);if(n)return T([{code:"INVALID_PAYLOAD",message:n}]);r=t.body}else if(t.body.kind==="extension"){return T([{code:"INVALID_PAYLOAD",message:"extension payload must be reparsed through its registered descriptor"}])}else if(t.body.kind==="opaque"||zh().includes(t.body.kind)){r=t.body}else{return T([{code:"INVALID_PAYLOAD",message:"unknown body kind"}])}const i={kind:t.kind,meta:e,body:r,source:{nodes:new Map,edges:new Map,groups:new Map,labels:new Map},canonicalSource:""};return re({...i,canonicalSource:ao(i)})}function PE(t,e=new Set){if(!Array.isArray(t))return[];const r=[];for(const i of t){if(!i||typeof i!=="object")continue;if(e.has(i))continue;e.add(i);r.push({id:String(i.id??""),label:i.label??String(i.id??""),nodeIds:Array.isArray(i.nodeIds)?i.nodeIds.map(String):[],children:PE(i.children,e),direction:i.direction});e.delete(i)}return r}function Kd(t){if(t instanceof Map){const e=new Map;for(const[r,i]of t)e.set(String(r),i);return e}if(Array.isArray(t)){const e=new Map;for(const r of t){if(Array.isArray(r)&&r.length>=2){e.set(String(r[0]),r[1])}}return e}if(t&&typeof t==="object"){return new Map(Object.entries(t))}return new Map}function tR(t){const e=Kd(t);const r=new Map;for(const[i,n]of e){if(i==="default"){r.set("default",n);continue}const o=Number(i);if(Number.isInteger(o)&&o>=0)r.set(o,n)}return r}function iR(t){const e=new WeakMap;const r=o=>{if(o===null||typeof o!=="object")return o;const s=e.get(o);if(s)return s;if(Array.isArray(o)){const c=new Array(o.length);e.set(o,c);const d=Object.getOwnPropertyDescriptors(o);for(const u of Reflect.ownKeys(o)){if(u==="length")continue;if(typeof u!=="string"||!/^(?:0|[1-9]\d*)$/.test(u)||Number(u)>=o.length){throw new TypeError("extension data arrays must not define custom properties")}}for(let u=0;u<o.length;u++){const h=d[String(u)];if(!h||!("value"in h)||!h.enumerable){throw new TypeError("extension data arrays must contain only enumerable data properties")}c[u]=r(h.value)}return c}const a={};e.set(o,a);const l=Object.getOwnPropertyDescriptors(o);for(const c of Reflect.ownKeys(o)){if(typeof c!=="string")throw new TypeError("extension data must not contain symbol keys");const d=l[c];if(!d||!("value"in d)||!d.enumerable){throw new TypeError("extension data objects must contain only enumerable data properties")}Object.defineProperty(a,c,{value:r(d.value),enumerable:true,configurable:true,writable:true})}return a};const i=r(t);_u(i,"Extension family parse body.data snapshot");const n=(o,s=new WeakSet)=>{if(o===null||typeof o!=="object"||s.has(o))return;s.add(o);for(const a of Object.values(Object.getOwnPropertyDescriptors(o))){if("value"in a)n(a.value,s)}Object.freeze(o)};n(i);return i}function nR(t,e){_u(t,`Family "${e}" parse body.data`);return iR(t)}function FE(t,e,r){let i=Math.max(0,Math.min(t.length,e));const n=/^[^\r\n]*/.exec(t.slice(i))[0];if(ct([n],0)?.form==="native"){const b=Nn(t,r).replace(new RegExp(Os.source,"gm"),A=>A.replace(/[^\r\n]/g," "));while(i<t.length){const A=/^[^\r\n]*/.exec(b.slice(i))[0];if(A.trim()&&!A.trimStart().startsWith("%%"))break;i+=A.length;if(t[i]==="\r")i++;if(t[i]==="\n")i++}}const o=/[\r\n]/g;o.lastIndex=i;const s=o.exec(t)?.index??t.length;const a=t.charCodeAt(s-1)===13?s-1:s;const l=t.slice(i,a);const c=/^\s*stateDiagram(?:-v2)?(?=$|[\s;%])/i.test(l);const d=c?yl(l):l;const u=d===l?t:`${t.slice(0,i)}${d}${t.slice(a)}`;const h=d.trim();const m=sc(h,"header");let f=-1;for(let b=0;!m&&b<h.length;b++){if(h.charCodeAt(b)!==59)continue;const A=h.lastIndexOf("&",b);if(A>=0&&/^#?(?:x[0-9a-f]+|\d+|[a-z][a-z0-9]+)$/i.test(h.slice(A+1,b)))continue;f=b;break}const p=(f>=0?h.slice(0,f):h).trimEnd();const g=m?p:Mn(p).split("\n")[0].trimEnd();if(!g)return{source:u,authoredHeader:g};const y=d.indexOf(g);const C=i+y;const w=C+g.length;const x=rR(g);const k=m?`${m.decodedPrefix}${m.authoredTitle}`:Mn(x)===x?x:g;return{source:k===g?u:`${u.slice(0,C)}${k}${u.slice(w)}`,authoredHeader:g}}function gs(t){const e=[];let r;const i=k=>{const b=FE(k,0,null).source;r=cx(b,"loose");return r.kind==="registered"?r.family:null};let n;try{n=st(t,{},"authored",i)}catch(k){if(k instanceof By)return T([{code:"INVALID_FRONTMATTER",message:k.message}]);if(k instanceof by)return T([{code:"CONFIG_REJECTED",message:k.message}]);throw k}const o=r.kind==="registered"?r.family:null;const s=n.wrapperSource?.length??0;const a=FE(t,s,o);const l=a.source===t?n:st(a.source,{},"authored",()=>o);const c=l.lines[0]??l.firstLine;const d=l===n?n:{...l,originalText:t,...n.wrapperSource!==void 0?{wrapperSource:n.wrapperSource}:{wrapperSource:void 0}};const u=aR(n);const h=n.text;const m=Nn(h,o);const f=Nl(t,a.authoredHeader||c,s,o);const p=(k,b)=>{if(n.cleanup)Ok(k,n.cleanup);return Dk(k,h,t,f,b)};const g=t.slice(s);if(d.lines.length===0){e.push({code:"EMPTY",message:"Empty diagram"});return T(e)}const y=c;const C=r.kind==="unknown"?{...r,header:y}:r;if(C.kind!=="registered"){const k=dx(C,t,s,a.authoredHeader,o);const b=k.preservation;const A=C.kind==="upstream"?`family:upstream/${C.match.family.id}`:"family:unknown";const L={kind:A,meta:u,body:{kind:"preserved",representation:b.classification==="unknown"?"unknown":"opaque",source:t,preservation:b,spans:b.spans,diagnostic:{code:k.code,message:k.message,help:k.help}},source:p(Ua()),canonicalSource:h};return re(L)}const w=C.family;const x=w.id;if(w.parse){const k={source:d,lines:d.familyLines,envelopeLines:d.lines,opaqueSource:g,meta:u,canonicalSource:h};let b;try{b=w.parse(k)}catch(B){if(Kt(x))throw B;const O=B instanceof Error?B.message:String(B);return T([{code:"FAMILY_DESCRIPTOR_CONTRACT",message:`Family "${x}" parse hook threw: ${O}`,line:1}])}if(!b.ok){e.push(...b.error);return T(e)}if(b.value.kind==="preserved"){return T([{code:"FAMILY_DESCRIPTOR_CONTRACT",message:`Registered family "${x}" cannot return a core preserved-family envelope`,line:1}])}if(!Kt(x)){if(b.value.kind!=="extension"||b.value.family!==x){return T([{code:"FAMILY_DESCRIPTOR_CONTRACT",message:`Family "${x}" parse hook must return an extension body for the same family`,line:1}])}let B;if(b.value.data!==void 0){try{B=nR(b.value.data,x)}catch(M){const E=M instanceof Error?M.message:String(M);return T([{code:"FAMILY_DESCRIPTOR_CONTRACT",message:`Family "${x}" parse hook returned invalid body.data: ${E}`,line:1}])}}const O={kind:x,descriptorIdentity:w.identity,meta:u,body:Object.freeze({kind:"extension",family:x,source:g,...B===void 0?{}:{data:B}}),source:p(Ua()),canonicalSource:h};return re(O)}if(b.value.kind==="extension"){return T([{code:"FAMILY_DESCRIPTOR_CONTRACT",message:`Built-in family "${x}" cannot return an extension body`,line:1}])}oR(b.value,u);const A=p(w.buildSourceMap?.(b.value,m,Object.freeze({originalText:n.originalText,wrapperSource:n.wrapperSource,authoredWrapperLength:n.authoredWrapperLength,cleanup:n.cleanup}))??Ua(),x==="flowchart"?"flowchart":"generic");let L={kind:x,meta:u,body:b.value,source:A,canonicalSource:h};if([u.accessibility.title,u.accessibility.descr].some(B=>B?.includes("%%{"))){try{ao(L)}catch(B){if(!(B instanceof xo))throw B;L={...L,body:{kind:"opaque",family:x,source:g}}}}sR(L,t,w.statementEnds);IE(L,t);return re(L)}if(Kt(x)){return re({kind:x,meta:u,body:{kind:"opaque",family:x,source:g},source:p(Ua()),canonicalSource:h})}return re({kind:x,descriptorIdentity:w.identity,meta:u,body:{kind:"extension",family:x,source:g},source:p(Ua()),canonicalSource:h})}function oR(t,e){ix(t,e.accessibility)}function sR(t,e,r){if(!e.includes("%%")||t.kind==="sequence"||t.kind==="c4"||t.body.kind==="opaque")return;const i=(l,c)=>{const d=y=>y.replace(/[^\r\n]/g," ");const u=l.replace(new RegExp(kl.source,"gm"),d).replace(Os,d);const h=u.split(/\r\n?|\n/).map(y=>y.trim());const m=[...c.comments];const f=new Set(m.map(y=>y.line));if(["flowchart","state","journey","timeline","ishikawa","sankey"].includes(t.kind))return m;if(t.kind==="gantt"){const y=(c.wrapperSource?.match(/\n/g)??[]).length;for(const C of oi(h.map((w,x)=>x<y?"":w))){if(["task","title","section","accessibility","click"].includes(C.kind))continue;C.raw.forEach((w,x)=>{const k=Hu(w);const b=C.startLine+x;if(k>=0&&!f.has(b)){m.push({line:b,text:w.slice(k+2).trim()});f.add(b)}})}return m.sort((C,w)=>C.line-w.line)}if(t.kind==="block"||t.kind==="requirement"){const y=t.kind==="block"?$l:ql;const C=st(l);const w=C.wrapperSource?.length??0;const x=(l.slice(0,w).match(/\n/g)??[]).length;const k=u.slice(w);let b=0,A=x+1;y(k,(L,B)=>{for(;b<L;b++)if(k.charCodeAt(b)===10)A++;if(!f.has(A))m.push({line:A,text:k.slice(L+2,B).trim()})});return m.sort((L,B)=>L.line-B.line)}if(t.kind==="kanban"){const y=st(l);const C=wi(y),w=Bt(l);Ei(C.text,{},y,(x,k,b)=>{const A=C.sourceOffset(b.start,"end"),L=C.sourceOffset(b.end,"start");const B=Xt(w,A).line;if(!f.has(B)){m.push({line:B,text:l.slice(A,L).trim()});f.add(B)}});return m.sort((x,k)=>x.line-k.line)}if(t.kind==="class"){const y=C=>{for(const w of C){if(w.value.kind!=="member"&&w.value.kind!=="body-annotation"){const x=Hx(w.raw);if(x>=0){const k=w.source.line+(w.raw.slice(0,x).match(/\n/g)??[]).length;if(!f.has(k)){m.push({line:k,text:w.raw.slice(x+2).split("\n",1)[0].trim()});f.add(k)}}}if(w.children)y(w.children);if(w.closing)y([w.closing])}};y(Ai(h,void 0,false).statements);return m.sort((C,w)=>C.line-w.line)}const p=(c.wrapperSource?.match(/\r\n?|\n/g)??[]).length;const g=r&&l.includes("%%")?r(h.map((y,C)=>C<p?"":y)):void 0;for(let y=0;y<h.length;y++){const C=Sl(g,y,h.length);const w=To(h,y,C);const x=t.kind==="mindmap"?Fb(w):void 0;const k=x===void 0?Hu(w):x.length<w.length?x.length:-1;if(k>0){const b=y+1+(w.slice(0,k).match(/\n/g)??[]).length;if(!f.has(b))m.push({line:b,text:w.slice(k+2).split("\n",1)[0].trim()})}y=C}return m.sort((y,C)=>y.line-C.line)};const n=i(e,t.meta);if(!n.length)return;const o=ao(t);const s=new Map;for(const l of i(o,st(o)))s.set(l.text,(s.get(l.text)??0)+1);const a=n.filter(l=>{const c=s.get(l.text)??0;if(!c)return true;s.set(l.text,c-1);return false});if(a.length)t.meta.droppedComments=a}function aR(t){return{initDirectives:t.initDirectives,comments:t.comments,accessibility:t.accessibility,wrapperSource:t.wrapperSource??"",...Object.keys(t.frontmatter).length>0?{frontmatter:t.frontmatter}:{}}}function Ua(){return{nodes:new Map,edges:new Map,groups:new Map,labels:new Map}}function Jd(t,e){let r;let i;return Object.freeze({parsed:()=>r??=gs(t),graph(){if(i)return i;const n=st(t).familyBody;if(n===e){const o=this.parsed();if(o.ok&&o.value.body.kind==="flowchart")return i=o.value.body.graph}return i=Ib(n,e)}})}var lR=8;var Qd=24;var Vr=2;var Yr=2;function qE(t,e,r="none",i=Pr,n={}){const o=Qu(t);o.title??=e.title===void 0?void 0:Ot(e.title);const s=kt([...o.services.map(K=>K.id),...o.groups.map(K=>K.id),...o.junctions.map(K=>K.id)]);const a=EC(o,n);const l=n.targetWidth??n.maxWidth??e.targetWidth??e.maxWidth;const c=K=>K.boundary==="group"?o.services.find(pe=>pe.id===K.id)?.parentId??K.id:K.id;const d=as(o.edges.flatMap(K=>[K.source,K.target].map(pe=>({id:c(pe),side:pe.side}))));const u=K=>Ui(d.get(K));const h=[...a.services.map(K=>({x:K.x,right:K.x+K.width})),...a.junctions.map(K=>({x:K.x,right:K.x+K.width})),...fp(a.groups).map(K=>({x:K.x,right:K.x+K.width}))];const m=h.length>0?Math.min(...h.map(K=>K.x)):0;const f=h.length>0?Math.max(...h.map(K=>K.right)):1;const p=Math.min(0,...a.services.map(K=>K.y),...a.junctions.map(K=>K.y),...fp(a.groups).map(K=>K.y));const g=l===void 0?Vr:1;const y=l===void 0?Infinity:Math.max(8,l-Vr-2);const C=Math.max(lR,(f-m)/y);const w=a.title?ve(Ge(a.title.text),l):[];const x=w.length?w.length+1:0;const k=o.alignments.length>0;const b=k?[...a.services,...a.junctions]:[];const A=K=>{const pe=new Map;const ke=_e=>{let qe=_e;while(pe.has(qe))qe=pe.get(qe);while(_e!==qe){const Ze=pe.get(_e);pe.set(_e,qe);_e=Ze}return qe};for(const _e of o.alignments)if(_e.axis===K)for(const qe of _e.members.slice(1)){const Ze=ke(_e.members[0]),rt=ke(qe);if(Ze!==rt)pe.set(rt,Ze)}const Ee=new Map;for(const _e of b){const qe=ke(_e.id),Ze=K==="row"?_e.y+_e.height/2:_e.x+_e.width/2;Ee.set(qe,Math.min(Ee.get(qe)??Infinity,Ze))}return new Map(b.map(_e=>[_e.id,Ee.get(ke(_e.id))]))};const L=k?A("row"):void 0;const B=k?A("column"):void 0;const O=K=>{let pe=g,ke=Vr+x;const Ee=F=>pe+Math.round((F-m)*K/C);const _e=F=>ke+Math.round((F-p)*K/Qd);const qe=new Map;for(const F of a.services){const Z=cR(F.label,F.icon,F.iconText).flatMap(be=>ve(be,l?Math.max(1,l-8):void 0));const ue=Math.max(1,...Z.map(ne));qe.set(F.id,{id:F.id,kind:"service",parentId:F.parentId,x:Ee(F.x),y:_e(F.y),width:Math.max(ue+2,Math.ceil(F.width/C),5,u(F.id).width),height:Math.max(Z.length+2,Math.ceil(F.height/Qd)+1,3,u(F.id).height),labelLines:Z,icon:F.icon,depth:ja(o,F.parentId)+1})}const Ze=new Map;for(const F of a.junctions){const Z=e.useAscii?"(*)":"\u25C9";const ue=`${Z} ${F.id}`;Ze.set(F.id,{id:F.id,kind:"junction",parentId:F.parentId,x:Ee(F.x),y:_e(F.y),width:Math.max(ne(ue)+2,u(F.id).width),height:Math.max(3,u(F.id).height),labelLines:[ue],depth:ja(o,F.parentId)+1})}if(k){for(const be of[...a.services,...a.junctions]){const Ce=qe.get(be.id)??Ze.get(be.id);Ce.x=Ee(B.get(be.id))-Math.floor((Ce.width-1)/2);Ce.y=_e(L.get(be.id))-Math.floor((Ce.height-1)/2)}const F=[...qe.values(),...Ze.values()];const Z=Math.max(0,Vr-Math.min(Infinity,...F.map(be=>be.x)));const ue=Math.max(0,Vr+x-Math.min(Infinity,...F.map(be=>be.y)));pe+=Z;ke+=ue;for(const be of F){be.x+=Z;be.y+=ue}}const rt=dR(o,a.groups,qe,Ze,Ee,_e,C/K,l,Qd/K);for(const F of rt.values()){const Z=d.get(F.id)?.T??0;F.width=Math.max(F.width,u(F.id).width,Z?ne(F.labelLines[0]??"")+3+Z*3+2:0);F.height=Math.max(F.height,u(F.id).height)}const z=[...rt.values(),...qe.values(),...Ze.values()];for(const F of o.edges)for(const[Z,ue]of[[F.source,F.hasArrowStart],[F.target,F.hasArrowEnd]]){const be=z.find(Ce=>Ce.id===c(Z));if(be){be.clearance??={};be.clearance[Z.side]=Math.max(be.clearance[Z.side]??0,ue?2:1)}}uR(z);return{serviceBoxes:qe,junctionBoxes:Ze,groupBoxes:rt,allBoxes:z}};let M=1;let E=O(M);const _=()=>{const K=new Map([...E.serviceBoxes,...E.junctionBoxes]);return o.alignments.some(pe=>{const ke=pe.members.map(Ee=>{const _e=K.get(Ee);return pe.axis==="row"?_e.y+(_e.height-1)/2:_e.x+(_e.width-1)/2});return Math.max(...ke)-Math.min(...ke)>.5})};while(k&&_()){M*=2;const K=Math.max(1,...E.allBoxes.map(Ee=>Hr(Ee)+1));if(l!==void 0&&K>l)throw new Pt(l,K,"architecture","MINIMUM_GEOMETRY");if(!Number.isSafeInteger(M)||M>Wt.maxOperations||E.allBoxes.some(Ee=>!Number.isSafeInteger(Ee.x+Ee.width)||!Number.isSafeInteger(Ee.y+Ee.height)))throw new bl([{strategy:"architecture-terminal-alignment",violations:["aligned cell projection exceeds its allocation bound"]}]);E=O(M);const pe=Math.max(1,...E.allBoxes.map(Ee=>Hr(Ee)+1));const ke=Math.max(1,...E.allBoxes.map(Ee=>Xr(Ee)+1));if(!Number.isSafeInteger(pe*ke)||pe*ke>Wt.maxOperations)throw new bl([{strategy:"architecture-terminal-alignment",violations:["aligned cell projection exceeds its allocation bound"]}])}if(M>1&&l!==void 0){const K=Math.max(1,...E.allBoxes.map(pe=>Hr(pe)+1));if(K>l)throw new Pt(l,K,"architecture","MINIMUM_GEOMETRY")}const{serviceBoxes:q,junctionBoxes:Q,groupBoxes:$,allBoxes:D}=E;const P=a.title?0:Math.min(Infinity,...D.map(K=>K.y));if(Number.isFinite(P)&&P>4)for(const K of D)K.y-=P-4;const U=Math.max(0,...D.map(K=>(K.clearance?.L??0)-K.x));const j=Math.max(0,...D.map(K=>(K.clearance?.T??0)-K.y));for(const K of D){K.x+=U;K.y+=j}const G=Math.max(Vr+1,...w.map(K=>ne(K)+Vr*2),...D.map(Hr));const se=Math.max(Vr+x+1,...D.map(Xr));const ce=Ct(G+Vr+8,se+Vr+5);let ae;const Y=(K,pe,ke=true)=>{ce.textBlock(K.x,K.y,pe,{owner:ae,role:"text",kind:"text"})};if(a.title){ae=ce.element({id:"title",kind:"label"});ce.scope(ae,()=>w.forEach((K,pe)=>{const ke=Math.max(Vr,Math.floor((G-ne(K))/2));Y({x:ke,y:pe},K,true)}))}for(const K of[...$.values()].sort((pe,ke)=>pe.depth-ke.depth||qt(pe.id,ke.id))){ae=ce.element({id:K.id,kind:"group",parent:K.parentId===void 0?void 0:{id:K.parentId,kind:"group"},members:[...$.values(),...q.values(),...Q.values()].filter(pe=>pe.parentId===K.id).map(pe=>pe.id)});ce.region(ae,{x:K.x,y:K.y,width:K.width,height:K.height});Ne(K,true)}const V=new Map;const N=[];const J=[];const ee=new Map;const X=new Map;const ie=(K,pe)=>{const ke=`${K.id}:${pe}`,Ee=X.get(ke)??0,_e=d.get(K.id)?.[pe]??1;X.set(ke,Ee+1);const qe=K.kind==="group"&&pe==="T"?ne(K.labelLines[0]??"")+3:0;return ji(qe?{...K,x:K.x+qe,width:K.width-qe}:K,pe,Ee,_e)};const ge=o.edges.map(K=>{const pe=Ie(K.source),ke=Ie(K.target);return pe&&ke?{source:pe,target:ke,start:ie(pe,K.source.side),end:ie(ke,K.target.side)}:void 0});const fe=(K,pe)=>({x:K.x+(pe==="R"?1:pe==="L"?-1:0),y:K.y+(pe==="B"?1:pe==="T"?-1:0)});const de=ge.flatMap((K,pe)=>{const ke=o.edges[pe];return K?[K.start,...ke.hasArrowStart?[fe(K.start,ke.source.side)]:[],K.end,...ke.hasArrowEnd?[fe(K.end,ke.target.side)]:[]]:[]});const xe=[];for(const[K,pe]of o.edges.entries()){const ke=ce.element({id:s(`edge:${K}`),kind:"edge",from:pe.source.id,to:pe.target.id,route:"connected"});ae=ke;const Ee=ge[K];if(!Ee){xe.push({owner:ke,edge:pe});ce.report({code:"TERMINAL_FAMILY_PROJECTION",feature:`architecture.${ke.id}.endpoint`,message:"An Architecture endpoint has no allocated service, junction or group boundary; the complete relationship is retained in an owned endpoint summary."});continue}const{source:_e,target:qe,start:Ze,end:rt}=Ee;ce.port(ke,{nodeId:pe.source.id,...pe.source.boundary==="group"?{boundary:{id:_e.id,kind:"group"}}:{},x:Ze.x,y:Ze.y,side:pe.source.side,end:"start"});ce.port(ke,{nodeId:pe.target.id,...pe.target.boundary==="group"?{boundary:{id:qe.id,kind:"group"}}:{},x:rt.x,y:rt.y,side:pe.target.side,end:"end"});const z={T:"B",B:"T",L:"R",R:"L"};ce.expectMarkers(ke,"start",pe.hasArrowStart?[{shape:"arrow",direction:z[pe.source.side],ascii:e.useAscii}]:[]);ce.expectMarkers(ke,"end",pe.hasArrowEnd?[{shape:"arrow",direction:z[pe.target.side],ascii:e.useAscii}]:[]);const F=Me(pe);const Z=fe(Ze,pe.source.side),ue=fe(rt,pe.target.side);const be=new Set([Ze,rt,...pe.hasArrowStart?[Z]:[],...pe.hasArrowEnd?[ue]:[]].map(ot));for(const Je of de)if(!be.has(ot(Je)))F.set(ot(Je),true);const Ce=new zr(F);for(const Je of V.keys())Ce.set(Je,true);Ce.delete(ot(Ze));Ce.delete(ot(rt));const Le=(Je,At)=>Je.x===At.x&&Je.y===At.y;const Qe=(Je,At)=>(!Le(Je,Ze)||!pe.hasArrowStart||Le(At,Z))&&(!Le(At,rt)||!pe.hasArrowEnd||Le(Je,ue));const lt=(Je,At)=>Qe(Je,At)&&[Je,At].every(H=>{const Se=V.get(ot(H));if(!Se)return true;return Se.size===2&&(Je.x===At.x?Se.has("E")&&Se.has("W"):Se.has("N")&&Se.has("S"))});const et=Le(Ze,rt)?null:St(Ce,Ze,rt,$E(pe.source.side),Qe)??St(F,Ze,rt,$E(pe.source.side),lt);if(!et){xe.push({owner:ke,edge:pe});ce.projectMarkers(ke,`architecture.${ke.id}.route`);ce.report({code:"TERMINAL_FAMILY_PROJECTION",feature:`architecture.${ke.id}.route`,message:"No obstacle-free route was found for the authored Architecture ports; the complete relationship is retained in an owned endpoint summary."});continue}const xt=Nt(et);J.push({edge:pe,points:xt,owner:ke});const ft={T:"S",R:"W",B:"N",L:"E"};He(Ze,ft[pe.source.side]);He(rt,ft[pe.target.side]);for(let Je=1;Je<xt.length;Je++)Ae(xt[Je-1],xt[Je]);if(pe.hasArrowStart)N.push({point:Ze,side:pe.source.side,owner:ke});if(pe.hasArrowEnd)N.push({point:rt,side:pe.target.side,owner:ke})}for(const K of V.keys()){const pe=K.indexOf(",");const ke=Number(K.slice(0,pe));const Ee=Number(K.slice(pe+1));for(const{owner:_e,dirs:qe}of ee.get(K)?.values()??[]){ae=_e;const Ze={N:1,E:2,S:4,W:8};const rt=[...qe].reduce((z,F)=>z|Ze[F],0);ce.stroke(ke,Ee,rt,{owner:_e,role:qe.size>2?"junction":"line",ascii:e.useAscii})}}for(const K of N){const pe={T:"B",B:"T",L:"R",R:"L"};ce.marker(K.point.x,K.point.y,{shape:"arrow",direction:pe[K.side],ascii:e.useAscii},{owner:K.owner,role:"arrow"})}const we=[];const Be=J.some(({edge:K})=>K.label)?[...V.keys()].map(K=>{const[pe,ke]=K.split(",").map(Number);return{id:"",kind:"junction",x:pe,y:ke,width:1,height:1,labelLines:[],depth:0}}):[];for(const{edge:K,points:pe,owner:ke}of J){ae=ke;if(!K.label)continue;const Ee=`[${Vi(K.label)}]`;const _e=hR(Ee,pe,[...D,...we,...Be]);Y(_e,Ee,true);we.push({id:`edge-label-${we.length}`,kind:"junction",x:_e.x,y:_e.y,width:ne(Ee),height:1,labelLines:[Ee],depth:0})}for(const K of q.values()){ae=ce.element({id:K.id,kind:"node",parent:K.parentId===void 0?void 0:{id:K.parentId,kind:"group"}});ce.region(ae,{x:K.x,y:K.y,width:K.width,height:K.height});Ne(K,false)}for(const K of Q.values()){ae=ce.element({id:K.id,kind:"node",parent:K.parentId===void 0?void 0:{id:K.parentId,kind:"group"}});ce.region(ae,{x:K.x,y:K.y,width:K.width,height:K.height});Ne(K,false)}for(const{owner:K,edge:pe}of xe){const ke=`${pe.source.id}${pe.source.boundary==="group"?"{group}":""}:${pe.source.side} ${pe.hasArrowStart?"<":""}--${pe.hasArrowEnd?">":""} ${pe.target.side}:${pe.target.id}${pe.target.boundary==="group"?"{group}":""}${pe.label?` : ${Vi(pe.label)}`:""}`;for(const Ee of ve(ke,l))ce.text(0,ce.height,Ee,{owner:K,role:"text",kind:"text"})}return Fe(ce,{colorMode:r,theme:i,trimEnd:true});function Ie(K){if(K.boundary==="group"){const pe=q.get(K.id);return pe?.parentId?$.get(pe.parentId):void 0}return q.get(K.id)??Q.get(K.id)}function Me(K){const pe=new zr;const ke=true;const Ee=new Set;const _e=Z=>{let ue=Z;while(ue){if(Ee.has(ue))break;Ee.add(ue);ue=o.groups.find(be=>be.id===ue)?.parentId}};const qe=o.services.find(Z=>Z.id===K.source.id);const Ze=o.services.find(Z=>Z.id===K.target.id);const rt=o.junctions.find(Z=>Z.id===K.source.id);const z=o.junctions.find(Z=>Z.id===K.target.id);_e(qe?.parentId??rt?.parentId);_e(Ze?.parentId??z?.parentId);const F=Z=>{for(let ue=Z.x;ue<=Hr(Z);ue++){for(let be=Z.y;be<=Xr(Z);be++)pe.set(ot({x:ue,y:be}),ke)}};for(const Z of q.values())F(Z);for(const Z of Q.values())F(Z);for(const Z of $.values()){if(Ee.has(Z.id))F({...Z,height:Math.max(1,Z.labelLines.length)});else F(Z)}return pe}function Ae(K,pe){const ke=Math.sign(pe.x-K.x);const Ee=Math.sign(pe.y-K.y);let _e={...K};while(_e.x!==pe.x||_e.y!==pe.y){const qe={x:_e.x+ke,y:_e.y+Ee};const Ze=ke>0?"E":ke<0?"W":Ee>0?"S":"N";const rt=ke>0?"W":ke<0?"E":Ee>0?"N":"S";He(_e,Ze);He(qe,rt);_e=qe}}function He(K,pe){const ke=ot(K);const Ee=ee.get(ke)??new Map;if(ae){const qe=Ee.get(ae.id)??{owner:ae,dirs:new Set};qe.dirs.add(pe);Ee.set(ae.id,qe)}ee.set(ke,Ee);const _e=V.get(ke)??new Set;_e.add(pe);V.set(ke,_e)}function Ne(K,pe){Et(ce,K,ae,e.useAscii,!pe);if(pe){const Ee=K.x+2;ce.scope(ae,()=>K.labelLines.forEach((_e,qe)=>Y({x:Ee,y:K.y+qe},_e,true)));return}const ke=K.y+Math.max(1,Math.floor((K.height-K.labelLines.length)/2));for(let Ee=0;Ee<K.labelLines.length;Ee++){const _e=K.labelLines[Ee];const qe=K.x+Math.max(1,Math.floor((K.width-ne(_e))/2));Y({x:qe,y:ke+Ee},_e,true)}}}function cR(t,e,r){const i=Ge(t).split(/\r?\n/).map(o=>o.trim()).filter(Boolean);const n=i.length>0?i:[""];if(e)n[0]=`[${e}]${n[0]?` ${n[0]}`:""}`;if(r!==void 0)n.unshift(...r.split("\n"));return n}function fp(t){const e=[];const r=i=>{e.push(i);for(const n of i.children)r(n)};for(const i of t)r(i);return e}function ja(t,e){let r=0;let i=e;while(i){r++;i=t.groups.find(n=>n.id===i)?.parentId}return r}function dR(t,e,r,i,n,o,s,a,l=Qd){const c=new Map(fp(e).map(h=>[h.id,h]));const d=new Map;const u=[...t.groups].sort((h,m)=>ja(t,m.id)-ja(t,h.id));for(const h of u){const m=c.get(h.id);const f=ve(`${h.icon?`(${h.icon}) `:""}${Ge(h.label)}`,a?Math.max(1,a-8):void 0);let p=n(m.x);let g=o(m.y);let y=Math.max(8,...f.map(x=>ne(x)+4),Math.ceil(m.width/s));let C=Math.max(f.length+Yr+2,Math.ceil(m.height/l)+1);const w=[...[...r.values()].filter(x=>x.parentId===h.id),...[...i.values()].filter(x=>x.parentId===h.id),...[...d.values()].filter(x=>x.parentId===h.id)];if(w.length>0){const x=Math.min(...w.map(E=>E.x));const k=Math.min(...w.map(E=>E.y));const b=Math.max(...w.map(Hr));const A=Math.max(...w.map(Xr));const L=Math.min(p,x-Yr);const B=Math.min(g,k-Yr);const O=Math.max(p+y-1,b+Yr);const M=Math.max(g+C-1,A+Yr);p=Math.max(0,L);g=Math.max(0,B);y=O-p+1;C=M-g+1}d.set(h.id,{id:h.id,kind:"group",parentId:h.parentId,x:p,y:g,width:y,height:C,labelLines:f,icon:h.icon,depth:ja(t,h.id)})}return d}function uR(t){const e=o=>t.filter(s=>s.parentId===o);const r=o=>({...o,x:o.x-(o.clearance?.L??0),y:o.y-(o.clearance?.T??0),width:o.width+(o.clearance?.L??0)+(o.clearance?.R??0),height:o.height+(o.clearance?.T??0)+(o.clearance?.B??0)});const i=(o,s)=>{o.y+=s;if(o.kind==="group")for(const a of e(o.id))i(a,s)};const n=o=>{const s=e(o);for(const m of s)if(m.kind==="group")n(m.id);const a=t.find(m=>m.id===o);const l=[];const c=s.sort((m,f)=>m.y-f.y||m.x-f.x||qt(m.id,f.id));for(const m of c){if(a&&m.y<a.y+a.labelLines.length+Yr)i(m,a.y+a.labelLines.length+Yr-m.y);for(;;){const f=l.filter(p=>zE(r(m),r(p)));if(!f.length)break;i(m,Math.max(...f.map(p=>Xr(p)+Math.max(Yr,(p.clearance?.B??0)+(m.clearance?.T??0))+1))-m.y)}l.push(m)}if(!a||!s.length)return;const d=Math.max(0,Math.min(a.x,...s.map(m=>m.x-Yr)));const u=Math.max(Hr(a),...s.map(m=>Hr(m)+Yr),d+Math.max(...a.labelLines.map(ne))+3);const h=Math.max(Xr(a),...s.map(m=>Xr(m)+Yr));a.x=d;a.width=u-d+1;a.height=h-a.y+1};n()}function hR(t,e,r){const i=ne(t);const n=r.flatMap(d=>d.kind==="group"?mR(d):[d]);const o=e.slice(1).map((d,u)=>({a:e[u],b:d})).sort((d,u)=>Math.abs(u.b.x-u.a.x)-Math.abs(d.b.x-d.a.x));const s=(d,u)=>{const h={id:"",kind:"junction",x:d,y:u,width:i,height:1,labelLines:[],depth:0};return d>=0&&u>=0&&n.every(m=>!zE(h,m))};for(const d of o){if(d.a.y!==d.b.y)continue;const u=Math.min(d.a.x,d.b.x);const h=Math.max(d.a.x,d.b.x);if(h-u+1<i)continue;const m=Math.floor((u+h-i+1)/2);if(s(m,d.a.y))return{x:m,y:d.a.y}}const a=e[Math.floor(e.length/2)]??{x:0,y:0};for(const d of[-1,1,-2,2,0]){const u=Math.max(0,a.x-Math.floor(i/2));if(s(u,a.y+d))return{x:u,y:a.y+d}}let l=Math.max(0,...r.map(d=>Xr(d)+2));const c=Math.max(0,a.x-Math.floor(i/2));while(!s(c,l))l++;return{x:c,y:l}}function $E(t){if(t==="L")return $e;if(t==="R")return Pe;if(t==="T")return je;return We}function mR(t){const e=(r,i,n,o)=>({...t,x:r,y:i,width:n,height:o});return[e(t.x,t.y,t.width,Math.max(1,t.labelLines.length)),e(t.x,Xr(t),t.width,1),e(t.x,t.y,1,t.height),e(Hr(t),t.y,1,t.height)]}function Hr(t){return t.x+t.width-1}function Xr(t){return t.y+t.height-1}function zE(t,e){return t.x<=Hr(e)&&e.x<=Hr(t)&&t.y<=Xr(e)&&e.y<=Xr(t)}function fR(t,e){const r=[...t.annotation===void 0?[]:ve(`<<${t.annotation}>>`,e),...ve(Ge(Ye(t.label,t.labelContent)),e)];const i=t.attributes.flatMap(o=>ve(zs(o),e));const n=t.methods.flatMap(o=>ve(zs(o),e));return n.length?[r,i,n]:i.length?[r,i]:[r]}function GE(t,e,r){if(t==="link-solid"||t==="link-dashed")return void 0;const i=t==="inheritance"||t==="realization"?"open-arrow":t==="composition"?"filled-diamond":t==="aggregation"?"hollow-diamond":t==="lollipop"?"lollipop":"triangle";return{shape:i,direction:{T:"B",B:"T",L:"R",R:"L"}[e],ascii:r}}function WE(t,e,r,i,n,o){n??=e.targetWidth??e.maxWidth;const s=N=>N.split("\n").map(J=>J.trim()).filter(J=>J&&!J.startsWith("%%"));const a=Zl(s(t),o===void 0?void 0:s(o));a.title??=e.title;Tl(a.classDefs,a.classes);if(!a.classes.length&&!a.namespaces.length&&!a.notes.length){const N=a.title?ve(Ge(Ot(a.title)),n):[];const J=new Re(Math.max(0,...N.map(ne)),N.length);J.scope({id:"title",kind:"label"},()=>N.forEach((ee,X)=>J.text(0,X,ee)));return Fe(J,{colorMode:r,theme:i})}const l=(N,J="")=>N.flatMap(ee=>{const X=J?`${J}.${ee.name}`:ee.name;return[X,...l(ee.children,X)]});const c=kt([...a.classes.map(N=>N.id),...l(a.namespaces)]);const d=a.direction??"TB",u=d==="LR"||d==="RL";const h=N=>ve(Ge(N),n?Math.max(1,Math.floor(n/3)):void 0);const m=a.relationships.map((N,J)=>({id:c(`relationship:${J}`),from:N.from,to:N.to,...N.label?{lines:h(Ye(N.label,N.labelContent))}:{},...N.fromCardinality?{fromLines:h(Ye(N.fromCardinality,N.fromCardinalityContent))}:{},...N.toCardinality?{toLines:h(Ye(N.toCardinality,N.toCardinalityContent))}:{}}));const f=new Map;m.forEach((N,J)=>{if(!f.has(N.id))f.set(N.id,a.relationships[J])});const p=a.notes.map((N,J)=>({id:c(`note:${J}`),targetId:N.for,lines:ve(Ge(Ye(N.text,N.textContent)),n?Math.max(1,n-8):void 0)}));const g=p.flatMap(N=>N.targetId?[{id:c(`${N.id}:connector`),from:N.targetId,to:N.id}]:[]);const y=ur([...m,...g],d);const C=new Map(a.classes.map(N=>[N.id,fR(N,n?Math.max(1,n-8):void 0)]));const w=new Map(a.classes.map(N=>{const J=C.get(N.id),ee=y.get(N.id);return[N.id,{width:Math.max(4+Math.max(0,...J.flat().map(ne)),ee?.width??0),height:Math.max(J.reduce((X,ie)=>X+Math.max(1,ie.length),0)+J.length+1,ee?.height??0)}]}));const x=new Map,k=new Map;for(const N of a.relationships){if(N.from===N.to)continue;const J=N.type==="inheritance"||N.type==="realization";const ee=J&&N.markerAt==="to"?N.to:N.from;const X=J&&N.markerAt==="to"?N.from:N.to;const ie=x.get(ee)??new Set;ie.add(X);x.set(ee,ie);const ge=k.get(X)??new Set;ge.add(ee);k.set(X,ge)}const b=new Map,A=a.classes.filter(N=>!k.has(N.id)).map(N=>N.id);A.forEach(N=>b.set(N,0));for(let N=0;N<A.length;N++){const J=A[N];for(const ee of x.get(J)??[]){const X=b.get(J)+1;if(X>=a.classes.length||(b.get(ee)??-1)>=X)continue;b.set(ee,X);A.push(ee)}}let L=Math.max(-1,...b.values())+1;for(const N of a.classes)if(!b.has(N.id))b.set(N.id,L++);const B=new Map;const O=2*(Ur+1)+1;let M=false;const E=()=>{B.clear();let N=4;const J=Math.max(8,M?O:0,...m.flatMap(ee=>[ee.lines?.length??0,ee.fromLines?.length??0,ee.toLines?.length??0]).map(ee=>ee+6));for(let ee=0;ee<=Math.max(0,...b.values());ee++){let X=4,ie=0;for(const ge of a.classes.filter(fe=>(b.get(fe.id)??0)===ee)){const fe=w.get(ge.id);B.set(ge.id,{id:ge.id,cls:ge,sections:C.get(ge.id),x:u?N:X,y:u?X:N,...fe});X+=(u?fe.height:fe.width)+(M?O:6);ie=Math.max(ie,u?fe.width:fe.height)}N+=ie+J}ps(B.values(),d)};E();for(let N=0;N<(m.length+g.length)*2+2;N++){let J=Math.max(0,...[...B.values()].map(ge=>ge.y+ge.height))+8;const ee=p.map(ge=>{const fe=ge.targetId?B.get(ge.targetId):void 0;const de={id:ge.id,x:fe?.x??4,y:J,width:Math.max(6,...ge.lines.map(xe=>ne(xe)+4)),height:ge.lines.length+2};J+=de.height+4;return de});const X=ur([...m,...g],d,[...B.values(),...ee]);let ie=false;for(const[ge,fe]of X){const de=y.get(ge)??{width:0,height:0};y.set(ge,{width:Math.max(de.width,fe.width),height:Math.max(de.height,fe.height)});const xe=w.get(ge);if(xe&&(xe.width<fe.width||xe.height<fe.height)){xe.width=Math.max(xe.width,fe.width);xe.height=Math.max(xe.height,fe.height);ie=true}}if(!ie)break;E()}const _=new Map,q=[];const Q=()=>{_.clear();q.length=0;if(a.namespaces.length){const N=Me=>h(Me.labelContent?.value===(Me.label??Me.name)?Me.labelContent.prepared:Ot(Me.label??Me.name));const J=4;const ee=(Me,Ae=1)=>Math.max(Ae,...Me.map(He=>ee(He.children,Ae+1)));const X=Me=>Math.max(1,...Me.flatMap(Ae=>[N(Ae).length,X(Ae.children)]));const ie=ee(a.namespaces)*(X(a.namespaces)+J);for(const Me of B.values()){Me.x+=ie;Me.y+=ie}let ge=Math.max(4,...[...B.values()].map(Me=>Me.y+Me.height+4));const fe=(Me,Ae,He=1)=>{const Ne=Ae?`${Ae}.${Me.name}`:Me.name;Me.classIds.forEach(F=>_.set(F,Ne));const K=Me.children.map(F=>fe(F,Ne,He+1)).filter(F=>F!==void 0);const pe=Me.classIds.map(F=>B.get(F)).filter(F=>F!==void 0);const ke=[...K,...pe];const Ee=N(Me);if(!ke.length){const F={id:Ne,parentId:Ae,depth:He,members:[],labelLines:Ee,x:4,y:ge,width:Math.max(6,...Ee.map(Z=>ne(Z)+4)),height:Ee.length+3};ge+=F.height+4;q.push(F);return F}const _e=Math.min(...ke.map(F=>F.x))-J,qe=Math.min(...ke.map(F=>F.y))-Ee.length-J;const Ze=Math.max(...ke.map(F=>F.x+F.width+J-1),_e+Math.max(...Ee.map(ne))+4);const rt=Math.max(...ke.map(F=>F.y+F.height+J-1));const z={id:Ne,parentId:Ae,depth:He,members:[...Me.classIds,...K.map(F=>F.id)],labelLines:Ee,x:_e,y:qe,width:Ze-_e+1,height:rt-qe+1};q.push(z);return z};a.namespaces.forEach(Me=>fe(Me));const de=(Me,Ae)=>{Me.y+=Ae;if("members"in Me){q.filter(He=>He.parentId===Me.id).forEach(He=>de(He,Ae));for(const He of B.values())if(_.get(He.id)===Me.id)de(He,Ae)}};const xe=Me=>{const Ae=[...q.filter(K=>K.parentId===Me),...[...B.values()].filter(K=>_.get(K.id)===Me)];for(const K of Ae)if("members"in K)xe(K.id);const He=[];for(const K of Ae.sort((pe,ke)=>pe.y-ke.y||pe.x-ke.x||qt(pe.id,ke.id))){const pe=ke=>M&&!("members"in K)&&!("members"in ke)?Math.max(J,O):J;for(;;){const ke=He.filter(Ee=>K.x<Ee.x+Ee.width+pe(Ee)&&Ee.x<K.x+K.width+pe(Ee)&&K.y<Ee.y+Ee.height+pe(Ee)&&Ee.y<K.y+K.height+pe(Ee));if(!ke.length)break;de(K,Math.max(...ke.map(Ee=>Ee.y+Ee.height+pe(Ee)))-K.y)}He.push(K)}const Ne=q.find(K=>K.id===Me);if(Ne&&Ae.length){Ne.x=Math.min(...Ae.map(K=>K.x))-J;Ne.y=Math.min(...Ae.map(K=>K.y))-Ne.labelLines.length-J;Ne.width=Math.max(...Ae.map(K=>K.x+K.width+J),Ne.x+Math.max(...Ne.labelLines.map(ne))+4)-Ne.x;Ne.height=Math.max(...Ae.map(K=>K.y+K.height+J))-Ne.y}};xe();const we=[...B.values(),...q];const Be=Math.max(0,-Math.min(0,...we.map(Me=>Me.x)));const Ie=Math.max(0,-Math.min(0,...we.map(Me=>Me.y)));if(Be||Ie)for(const Me of we){Me.x+=Be;Me.y+=Ie}}};const $=()=>{let N=Math.max(0,...[...B.values()].map(J=>J.y+J.height),...q.map(J=>J.y+J.height))+Math.max(8,M?O:0);return p.map(J=>{const ee=y.get(J.id),X=J.targetId?B.get(J.targetId):void 0;const ie={...J,x:X?.x??2,y:N,width:Math.max(6,...J.lines.map(ge=>ne(ge)+4),ee?.width??0),height:Math.max(J.lines.length+2,ee?.height??0)};N+=ie.height+(M?O:4);return ie})};let D=[];const P=(m.length+g.length)*4+1;for(let N=0;N<=P;N++){Q();D=$();const J=[...B.values(),...D];const ee=new Map(J.map(ge=>[ge.id,ge]));const X=Hd([...m,...g],d,ee);let ie=false;for(const[ge,fe]of X){const de=Ui(fe);const xe=y.get(ge)??{width:0,height:0};y.set(ge,{width:Math.max(xe.width,de.width),height:Math.max(xe.height,de.height)});const we=ee.get(ge);if(!we||we.width>=de.width&&we.height>=de.height)continue;const Be=w.get(ge);if(Be){Be.width=Math.max(Be.width,de.width);Be.height=Math.max(Be.height,de.height)}ie=true}if(!ie&&!M){const ge=(fe,de)=>{const xe=X.get(fe.id),we=X.get(de.id);if(!xe||!we)return false;const Be=de.y-fe.y-fe.height,Ie=de.x-fe.x-fe.width;return xe.B>0&&we.T>0&&Be>=0&&Be<O&&fe.x<de.x+de.width&&de.x<fe.x+fe.width||xe.R>0&&we.L>0&&Ie>=0&&Ie<O&&fe.y<de.y+de.height&&de.y<fe.y+fe.height};for(let fe=0;fe<J.length&&!M;fe++)for(let de=fe+1;de<J.length;de++){if(!ge(J[fe],J[de])&&!ge(J[de],J[fe]))continue;M=true;ie=true;break}}if(!ie)break;if(N===P)throw new Error("Terminal face capacity did not stabilize within its incident demand");E()}let U=[],j;const G=[...m,...g],se=[...B.values(),...D];let ce;try{U=xi(se,G,d,q.map(J=>({...J,container:true,headerHeight:J.labelLines.length})));const N=yE(U,se,q,_);if(N.status==="invalid")ce=N.reason}catch(N){if(!(N instanceof Wa))throw N;ce=N.message}if(ce){const N=a.title?ve(Ge(Ot(a.title)),n):[];j=xE(B,q,D,_,G,d,N,n,m.length);U=vE(j)}const ae=new Re;if(j)ae.reserveTerminalPathWitnessWork(j.report.planningWork);const Y=e.useAscii;const V=(N,J,ee=false)=>Et(ae,N,J,Y,ee);for(const N of q.sort((J,ee)=>J.depth-ee.depth||qt(J.id,ee.id))){const J=ae.element({id:N.id,kind:"cluster",parent:N.parentId===void 0?void 0:{id:N.parentId,kind:"cluster"},members:N.members});V(N,J);ae.scope(J,()=>N.labelLines.forEach((ee,X)=>ae.text(N.x+Math.max(1,Math.floor((N.width-ne(ee)-2)/2)),N.y+X,` ${ee} `)))}for(const N of U){const J=f.get(N.relation.id);if(!J){const X={id:N.relation.id,kind:"edge",route:"connected",from:N.relation.from,to:N.relation.to};jr(ae,N,X,Y);ae.expectMarkers(X,"start",[]);ae.expectMarkers(X,"end",[]);continue}const ee=ae.element({id:N.relation.id,kind:"edge",route:"connected",from:J.from,to:J.to});jr(ae,N,ee,Y,eb(J)==="dashed");for(const[X,ie,ge,fe]of[["start",N.source,J.fromType??J.type,J.markerAt==="from"||J.markerAt==="both"],["end",N.target,J.toType??J.type,J.markerAt==="to"||J.markerAt==="both"]]){const de=fe?GE(ge,ie.side,Y):void 0;ae.expectMarkers(ee,X,de?[de]:[]);if(de)ae.marker(ie.x,ie.y,de,{owner:ee,role:"arrow"})}wr(ae,N.label,ee);wr(ae,N.fromLabel,{id:c(`${ee.id}:from-cardinality`),kind:"label",parent:{id:ee.id,kind:"edge"}});wr(ae,N.toLabel,{id:c(`${ee.id}:to-cardinality`),kind:"label",parent:{id:ee.id,kind:"edge"}})}for(const N of B.values()){const J=ae.element({id:N.id,kind:"node",parent:_.has(N.id)?{id:_.get(N.id),kind:"cluster"}:void 0});if(N.cls.isInterface){ae.resize(N.x+N.width,N.y+N.height);const fe=U.find(Ne=>Ne.relation.from===N.id||Ne.relation.to===N.id);const de=fe&&f.get(fe.relation.id);const xe=fe?.relation.from===N.id;const we=fe&&(xe?fe.source:fe.target);const Be=de&&(de.markerAt==="both"||de.markerAt===(xe?"from":"to"));const Ie=de&&we&&Be?GE((xe?de.fromType:de.toType)??de.type,we.side,Y):void 0;const Me=we&&ae.cell(we.x,we.y);if(fe&&we&&Ie?.shape==="lollipop"&&Me?.kind==="marker"&&Me.head===we.x&&Me.marker?.shape===Ie.shape&&Me.marker.direction===Ie.direction&&Me.owners.some(Ne=>Ne.kind==="edge"&&Ne.id===fe.relation.id)&&Me.owners.every(Ne=>Ne.kind!=="edge"||Ne.id===fe.relation.id)){const Ne={x:we.x,y:we.y,width:Me.width,height:1};ae.region(J,Ne);ae.attributeWithin(J,Ne)}else ae.region(J,{x:N.x,y:N.y,width:N.width,height:N.height});const Ae=N.sections[0]??[];const He=N.y+Math.floor((N.height-Ae.length)/2);Ae.forEach((Ne,K)=>ae.text(N.x+Math.floor((N.width-ne(Ne))/2),He+K,Ne,{owner:J}));continue}ae.region(J,{x:N.x,y:N.y,width:N.width,height:N.height});ae.fill(N.x,N.y,N.width,N.height,{owner:J,kind:"surface"});const ee=xn(N.sections,Y,1,{width:N.width,height:N.height});const X=Object.assign({},a.classDefs.get("default"),...(N.cls.className??"").split(/\s+/).map(fe=>a.classDefs.get(fe)),N.cls.inlineStyle);const ie=Xd(ae,"class",N.id,X);for(const[,,fe]of ee.entries()){const de=fe.kind==="text"?ie.text:ie.stroke;if(de)fe.color=de}let ge=1;N.sections.forEach((fe,de)=>{const xe={x:1,y:ge,width:N.width-2,height:Math.max(1,fe.length)},we={id:c(`${N.id}:compartment:${de}`),kind:"compartment",parent:{id:N.id,kind:"node"}};ee.attributeWithin(we,xe);ee.region(we,xe);ge+=xe.height+1});ae.scope(J,()=>ae.overlay(ee,N.x,N.y))}for(const N of D){const J=ae.element({id:N.id,kind:"node",annotationTarget:N.targetId===void 0?void 0:{id:N.targetId,kind:"node"}});V(N,J,true);ae.textBlock(N.x+2,N.y+1,N.lines,{owner:J})}for(const N of a.classes)if(N.href)ae.text(0,ae.height+1,cp(N.id,N.href),{owner:{id:N.id,kind:"node"},role:"text"});if(a.title){const N=ve(Ge(Ot(a.title)),n),J=new Re(Math.max(ae.width,...N.map(ne)),ae.height+N.length+1);J.scope({id:"title",kind:"label"},()=>N.forEach((ee,X)=>J.text(Math.floor((J.width-ne(ee))/2),X,ee)));J.overlay(ae,0,N.length+1);return Fe(J,{colorMode:r,theme:i,...j?{trimEnd:true}:{}})}return Fe(ae,{colorMode:r,theme:i,...j?{trimEnd:true}:{}})}var pR=t=>`${t.keys.length?t.keys.join(","):" "} ${t.type} ${t.name}${t.comment?` # ${t.comment}`:""}`;function gR(t,e,r){if(t==="parent")return[{shape:"hollow-diamond",direction:e.side,ascii:r}];const i={shape:t==="one"||t==="zero-one"?"cardinality-one":"cardinality-many",direction:e.side,ascii:r};return t==="zero-one"||t==="zero-many"?[i,{shape:"circle",ascii:r}]:[i]}function UE(t,e,r,i,n){n??=e.targetWidth??e.maxWidth;const o=ab(t.split("\n").map(_=>_.trim()).filter(_=>_&&!_.startsWith("%%")));o.title??=e.title===void 0?void 0:Ot(e.title);const s=_=>{if(!o.title)return Fe(_,{colorMode:r,theme:i});const q=ve(Ge(o.title),n);const Q=new Re(Math.max(_.width,...q.map(ne)),_.height?_.height+q.length+1:q.length);Q.scope({id:"title",kind:"label"},()=>q.forEach(($,D)=>Q.text(Math.floor((Q.width-ne($))/2),D,$)));if(_.height)Q.overlay(_,0,q.length+1);return Fe(Q,{colorMode:r,theme:i})};Tl(o.classDefs,o.entities);if(!o.entities.length&&!o.groups.length)return s(new Re);const a=kt([...o.entities.map(_=>_.id),...o.groups.map(_=>_.id)]);const l=o.direction??"LR",c=l==="LR"||l==="RL";const d=_=>ve(Ge(_),n?Math.max(1,Math.floor(n/3)):void 0);const u=o.relationships.map((_,q)=>({id:a(`relationship:${q}`),from:_.entity1,to:_.entity2,..._.label?{lines:d(Ye(_.label,_.labelContent))}:{}}));const h=new Map;u.forEach((_,q)=>{if(!h.has(_.id))h.set(_.id,o.relationships[q])});const m=ur(u,l);const f=new Map(o.entities.map(_=>{const q=ve(Ge(Ye(_.label,_.labelContent)),n?Math.max(1,n-8):void 0);const Q=_.attributes.flatMap($=>ve(pR($),n?Math.max(1,n-8):void 0));return[_.id,Q.length?[q,Q]:[q]]}));const p=new Map(o.entities.map(_=>{const q=f.get(_.id),Q=m.get(_.id);return[_.id,{width:Math.max(4+Math.max(0,...q.flat().map(ne)),Q?.width??0),height:Math.max(q.reduce(($,D)=>$+Math.max(1,D.length),0)+q.length+1,Q?.height??0)}]}));const g=new Map(o.entities.map(_=>[_.id,new Set]));for(const _ of u){g.get(_.from)?.add(_.to);g.get(_.to)?.add(_.from)}const y=new Set,C=[];for(const _ of o.entities){if(y.has(_.id))continue;const q=[_.id];y.add(_.id);for(let $=0;$<q.length;$++)for(const D of g.get(q[$])??[])if(!y.has(D)){y.add(D);q.push(D)}const Q=new Set(q);C.push(o.entities.filter($=>Q.has($.id)).map($=>$.id))}const w=new Map,x=new Map(o.entities.map(_=>[_.id,_]));const k=Math.max(0,...u.flatMap(_=>_.lines??[]).map(ne)),b=Math.max(0,...u.map(_=>_.lines?.length??0));const A=Math.max(8,k+4),L=Math.max(8,b+6);let B=[];const O=()=>{w.clear();let _=4;for(const q of C){const Q=Math.max(2,Math.ceil(Math.sqrt(q.length)));let $=4,D=_,P=0,U=0,j=_;for(const G of q){const se=x.get(G),ce=p.get(G);if(P>=Q){D+=U+(c?L:A);$=4;P=0;U=0}w.set(G,{id:G,entity:se,sections:f.get(G),...ce,x:c?$:D,y:c?D:$});$+=(c?ce.width:ce.height)+(c?A:L);U=Math.max(U,c?ce.height:ce.width);j=Math.max(j,D+U);P++}_=j+(c?L:A)}ps(w.values(),l);B=[];if(o.groups.length){const q=(U,j,G)=>{U.x+=j;U.y+=G;if("children"in U)U.children.forEach(se=>q(se,j,G))};const Q=U=>{const j=o.groups.find(ie=>ie.id===U),G=d(Ye(j.label,j.labelContent));const se=4,ce=G.length+1;const ae=[...o.entities.filter(ie=>ie.groupId===U).map(ie=>w.get(ie.id)),...o.groups.filter(ie=>ie.parentId===U).map(ie=>Q(ie.id))];const Y=j.direction??l,V=Y==="LR"||Y==="RL";const N=Y==="RL"||Y==="BT"?[...ae].reverse():ae;let J=V?se:ce+se;for(const ie of N){const ge=V?J:se,fe=V?ce+se:J;q(ie,ge-ie.x,fe-ie.y);J+=(V?ie.width:ie.height)+8}const ee=m.get(U);const X={id:U,parentId:j.parentId,children:ae,labelLines:G,members:[...j.entityIds,...ae.filter(ie=>"children"in ie).map(ie=>ie.id)],container:true,headerHeight:ce,x:0,y:0,width:Math.max(8,...G.map(ie=>ne(ie)+4),...ae.map(ie=>ie.x+ie.width+se),ee?.width??0),height:Math.max(G.length+4,...ae.map(ie=>ie.y+ie.height+se),ee?.height??0)};B.push(X);return X};const $=[...o.groups.filter(U=>!U.parentId).map(U=>Q(U.id)),...o.entities.filter(U=>!U.groupId).map(U=>w.get(U.id))];const D=l==="RL"||l==="BT"?[...$].reverse():$;let P=4;for(const U of D){const j=c?P:4,G=c?4:P;q(U,j-U.x,G-U.y);P+=(c?U.width:U.height)+8}}};O();for(let _=0;_<u.length*2+2;_++){const q=ur(u,l,[...w.values(),...B]);let Q=false;for(const[$,D]of q){const P=m.get($)??{width:0,height:0};if(P.width<D.width||P.height<D.height){m.set($,{width:Math.max(P.width,D.width),height:Math.max(P.height,D.height)});Q=true}const U=p.get($);if(U&&(U.width<D.width||U.height<D.height)){U.width=Math.max(U.width,D.width);U.height=Math.max(U.height,D.height);Q=true}}if(!Q)break;O()}const M=xi([...w.values(),...B],u,l),E=new Re;for(const _ of[...B].reverse()){const q=E.element({id:_.id,kind:"cluster",parent:_.parentId===void 0?void 0:{id:_.parentId,kind:"cluster"},members:_.members});Et(E,_,q,e.useAscii);E.scope(q,()=>_.labelLines.forEach((Q,$)=>E.text(_.x+2,_.y+$,Q)))}for(const _ of M){const q=h.get(_.relation.id);const Q=E.element({id:_.relation.id,kind:"edge",from:q.entity1,to:q.entity2});jr(E,_,Q,e.useAscii,!q.identifying);for(const[$,D,P]of[["start",_.source,q.cardinality1],["end",_.target,q.cardinality2]]){const U=D.side==="L"?-1:D.side==="R"?1:0,j=D.side==="T"?-1:D.side==="B"?1:0;const G=gR(P,D,e.useAscii);E.expectMarkers(Q,$,G);G.forEach((se,ce)=>E.marker(D.x+U*ce,D.y+j*ce,se,{owner:Q,role:"arrow"}))}wr(E,_.label,Q)}for(const _ of w.values()){const q=E.element({id:_.id,kind:"node",parent:_.entity.groupId===void 0?void 0:{id:_.entity.groupId,kind:"cluster"}});E.region(q,{x:_.x,y:_.y,width:_.width,height:_.height});E.fill(_.x,_.y,_.width,_.height,{owner:q,kind:"surface"});const Q=xn(_.sections,e.useAscii,1,{width:_.width,height:_.height});const $=Object.assign({},o.classDefs.get("default"),...(_.entity.className??"").split(/\s+/).map(U=>o.classDefs.get(U)),_.entity.inlineStyle);const D=Xd(E,"er",_.id,$);for(const[,,U]of Q.entries()){const j=U.kind==="text"?D.text:D.stroke;if(j)U.color=j}let P=1;_.sections.forEach((U,j)=>{const G={x:1,y:P,width:_.width-2,height:Math.max(1,U.length)},se={id:a(`${_.id}:compartment:${j}`),kind:"compartment",parent:{id:_.id,kind:"node"}};Q.attributeWithin(se,G);Q.region(se,G);P+=G.height+1});E.scope(q,()=>E.overlay(Q,_.x,_.y))}return s(E)}var jE=40;var yR=12;var VE=" ";var ys=" ";function xR(t){return t?{bar:"#",done:".",active:"=",crit:"!",milestone:"*",vert:":",track:"-",axis:"-"}:{bar:"\u2588",done:"\u2591",active:"\u2593",crit:"\u2592",milestone:"\u25C6",vert:"\u250A",track:"\u2500",axis:"\u2500"}}function bR(t,e){if(t.includes("crit"))return e.crit;if(t.includes("done"))return e.done;if(t.includes("active"))return e.active;return e.bar}function YE(t,e){const r=e.dateOnly?"%m-%d":"%m-%d %H:%M";if(t.tags.includes("milestone")){return aa(t.start+(t.renderEnd-t.start)/2,r)}return`${aa(t.start,r)} \u2192 ${aa(t.renderEnd,r)}`}function HE(t,e,r="none",i=Pr,n,o={}){const s=o.maxWidth??e.maxWidth;const a=pb(mb(t),o.resolvedConfig??fb(n));a.title??=e.title;const l=MC(a,{today:o.today});if(l.tasks.length===0){const Y=new Re;Y.titleHandled=true;for(const V of[a.title,...a.sections.map(N=>N.label),"No tasks scheduled"]){if(V)for(const N of ve(V,s))Y.line([{text:N,role:"text"}])}return Fe(Y,{colorMode:r,theme:i,trimEnd:true})}const c=xR(e.useAscii);const d=e.useAscii?"->":"\u2192";const u=l.tasks.filter(Y=>!Y.tags.includes("vert"));const h=l.tasks.filter(Y=>Y.tags.includes("vert"));const m=Nh(u);const f=Nh(h);const p=a.displayMode==="compact";const g=new Map;if(p){for(let Y=0;Y<a.sections.length;Y++){const V=m.get(Y)??[];if(V.length>0){const N=[];OC(V).forEach((J,ee)=>(N[J]??=[]).push(V[ee]));g.set(Y,N)}}}const y=Y=>(g.get(Y)??[]).map(V=>V.map(N=>N.label).join(", "));const C=kt(l.tasks.flatMap(Y=>Y.id===void 0?[]:[Y.id]));const w=Y=>({id:Y.id??C(`task-${Y.index}`),kind:"node"});const x=(Y,V)=>{const N=[[]];let J=0;Y.forEach((ee,X)=>{const ie=ve(ee.label,Math.max(1,V));ie.forEach((ge,fe)=>{const de=X>0&&fe===0?", ":"";if(J>0&&(fe>0||J+ne(de+ge)>V)){N.push([]);J=0}if(J>0&&de){N.at(-1).push({text:de});J+=ne(de)}N.at(-1).push({text:ge,role:"text",owner:w(ee)});J+=ne(ge)})});return N};let k=0;for(let Y=0;Y<a.sections.length;Y++){const V=m.get(Y)??[];if(p){for(const N of y(Y)){k=Math.max(k,ne(ys+N))}}else{for(const N of V)k=Math.max(k,ne(ys+N.label))}}for(const Y of h)k=Math.max(k,ne(ys+Y.label));const b=Y=>dl(Y).split("\n");for(const Y of a.sections){if(Y.label!==void 0){for(const V of b(Y.label))k=Math.max(k,ne(VE+V))}}const A=u.map(Y=>YE(Y,l).replace("\u2192",d));const L=Math.max(0,...A.map(ne));let B=jE;if(s!==void 0){const Y=k+2+2+L;B=Math.max(yR,Math.min(jE,s-Y));const V=Y+B;if(V>s){k=Math.max(8,k-(V-s))}}const O=l.timeMax-l.timeMin;const M=Y=>{const V=Math.round((Y-l.timeMin)/O*B);return Math.max(0,Math.min(B,V))};const E=new Set(h.map(Y=>Math.min(B-1,M(Y.start+(Y.renderEnd-Y.start)/2))));const _=l.today!==void 0&&l.today>=l.timeMin&&l.today<=l.timeMax?Math.min(B-1,M(l.today)):void 0;const q=a.todayMarker?.style===void 0?void 0:hb(a.todayMarker.style);const Q=q?.applied.find(([Y])=>Y==="stroke")?.[1];const $={id:C("today-marker"),kind:"plot"};const D=e.useAscii?"|":"\u254E";const P=new Re;P.titleHandled=true;if(a.barHeight!==void 0&&u.length>0)P.report({code:"TERMINAL_FAMILY_PROJECTION",feature:"gantt.barHeight",message:`gantt.barHeight=${a.barHeight}px is represented by one terminal bar row per task or compact lane; task labels, dates and interval ownership are retained.`});if(_!==void 0&&q!==void 0){for(const[Y,V]of q.applied){if(Y==="stroke"||Y==="opacity"&&Number(V)===1)continue;P.report({code:"TERMINAL_FAMILY_PROJECTION",feature:`gantt.todayMarker.${Y}`,message:`todayMarker ${Y}=${JSON.stringify(V)} is represented by ${D} at the resolved clock column; CSS opacity, dash lengths and pixel stroke widths are unavailable. The resolved stroke color is retained.`})}}let U;const j=(Y=[])=>{P.line(Y,{owner:U})};if(a.title){U={id:C("title"),kind:"label"};const Y=k+2+B;P.scope(U,()=>{for(const V of ve(a.title,s)){const N=Math.max(0,Math.floor((Y-ne(V))/2));j([{text:" ".repeat(N),kind:"surface"},{text:V,role:"text"}])}});j()}const G=Y=>{const V=Array.from({length:B},()=>({text:c.track,role:"line",kind:"stroke"}));const N=Y.tags.includes("crit")?"crit":Y.tags.includes("active")?"active":Y.tags.includes("done")?"done":void 0;const J=a.sections[Y.sectionIndex]?.label;const ee=Y.tags.includes("milestone")?"milestone":"task";const X=en(o.styleFace,ee,{...N?{status:N}:{},...J?{category:J}:{}},{includeFallback:false});const ie=X?.cue==="outline"?e.useAscii?"+":"\u25C7":X?.cue==="double-line"?"=":X?.cue==="pattern"?e.useAscii?"%":"\u2591":void 0;if(Y.tags.includes("milestone")){const ge=Math.min(B-1,M(Y.start+(Y.renderEnd-Y.start)/2));const fe=X?.cue==="outline"?e.useAscii?"+":"\u25C7":X?.cue==="double-line"?e.useAscii?"#":"\u25C8":X?.cue==="pattern"?e.useAscii?"%":"\u25A3":void 0;V[ge]={text:fe??c.milestone,role:"line",kind:"marker"}}else{const ge=M(Y.start);const fe=Math.max(ge+1,M(Y.renderEnd));const de=Y.tags.includes("crit")?c.crit:ie??bR(Y.tags,c);for(let xe=ge;xe<fe&&xe<B;xe++)V[xe]={text:de,role:"line",kind:"mark"}}for(const ge of E)if(V[ge].text===c.track)V[ge]={text:c.vert,role:"line",kind:"stroke"};if(_!==void 0&&V[_].text===c.track)V[_]={text:D,role:"line",kind:"marker",owner:$,color:Q};return V};const se=()=>{U={id:C("time-axis"),kind:"label"};const Y=P.height;j([{text:" ".repeat(k+2),role:null},{text:c.axis.repeat(B),role:"line"}]);if(_!==void 0)P.put(k+2+_,Y,D,{role:"line",kind:"marker",owner:$,color:Q});const V=AC(l,a,Math.max(2,Math.floor(B/12)));const N=new Array(B+16).fill(" ");for(const J of V){const ee=M(J.time);if(ee>=B)continue;for(let X=0;X<J.label.length;X++){const ie=ee+X;if(ie>=N.length)break;if(X===0&&ee>0&&N[ee-1]!==" ")break;N[ie]=J.label[X]}}j([{text:" ".repeat(k+2),role:null},{text:N.join("").trimEnd(),role:"text"}])};if(a.topAxis)se();const ce=Y=>{U=w(Y);P.scope(U,()=>{x([Y],Math.max(1,k-4)).forEach((V,N)=>{const J=V.reduce((ee,X)=>ee+ne(X.text),0);j([{text:ys,kind:"surface"},...V,...N===0?[{text:" ".repeat(Math.max(0,k-4-J)+2)},{text:CR(Math.min(B-1,M(Y.start+(Y.renderEnd-Y.start)/2)),c.vert),role:"line",kind:"stroke"},{text:" "},{text:aa(Y.start,l.dateOnly?"%m-%d":"%m-%d %H:%M"),role:"text",owner:{id:C(`${w(Y).id}:dates`),kind:"label",parent:{id:w(Y).id,kind:"node"}}}]:[]])})})};let ae=0;for(let Y=0;Y<a.sections.length;Y++){const V=a.sections[Y];const N=P.height;const J=m.get(Y)??[];const ee=f.get(Y)??[];if(J.length===0&&ee.length===0&&V.label===void 0)continue;if(J.length===0&&V.label===void 0){ee.forEach(ce);continue}const X=ae++;U={id:C(`section-label#${X}`),kind:"label"};if(V.label!==void 0){for(const ie of b(V.label)){P.scope(U,()=>{for(const ge of ve(ie,Math.max(1,k-2)))j([{text:VE,kind:"surface"},{text:ge,role:"border",kind:"text"}])})}}if(p&&J.length>0){const ie=g.get(Y);for(let ge=0;ge<ie.length;ge++){const fe=ie[ge];const de=Array.from({length:B},()=>({text:c.track,role:"line",kind:"stroke"}));for(const we of fe){const Be=G(we);for(let Ie=0;Ie<B;Ie++)if(Be[Ie].text!==c.track)de[Ie]={...Be[Ie],owner:Be[Ie].owner??w(we)}}U={id:C(`lane:${Y}:${ge}`),kind:"lane",members:fe.map(we=>w(we).id)};const xe=x(fe,Math.max(1,k-4));xe.forEach((we,Be)=>{const Ie=we.reduce((Me,Ae)=>Me+ne(Ae.text),0);j([{text:ys},...we,...Be===0?[{text:" ".repeat(Math.max(0,k-4-Ie)+2)},...de.map(Me=>({...Me,owner:Me.owner??U}))]:[]])})}}else{for(const ie of J){const ge=w(ie);U=ge;x([ie],Math.max(1,k-4)).forEach((fe,de)=>{const xe=fe.reduce((we,Be)=>we+ne(Be.text),0);j([{text:ys},...fe,...de===0?[{text:" ".repeat(Math.max(0,k-4-xe)+2)},...G(ie),{text:" "},{text:YE(ie,l).replace("\u2192",d),role:"text",owner:{id:C(`${ge.id}:dates`),kind:"label",parent:{id:ge.id,kind:"node"}}}]:[]])})}}ee.forEach(ce);P.region({id:C(`section#${X}`),kind:"band",members:[...J,...ee].map(ie=>w(ie).id)},{x:0,y:N,width:P.width,height:P.height-N})}if(!a.topAxis)se();for(const Y of a.tasks){const V=[...Y.start?.kind==="after"?Y.start.refs.map(N=>({ref:N,kind:"after"})):[],...Y.end.kind==="until"?Y.end.refs.map(N=>({ref:N,kind:"until"})):[]];for(const{ref:N,kind:J}of V){const ee=w(Y).id;const X={id:C(`dependency:${Y.index}:${J}:${N}`),kind:"edge",from:J==="after"?N:ee,to:J==="after"?ee:N};for(const ie of ve(`${Ge(Y.id??Y.label)} ${J} ${Ge(N)}`,s,{hyphenate:false}))P.line([{text:ie,role:"text",kind:"text",owner:X}])}if(V.length)P.report({code:"TERMINAL_FAMILY_PROJECTION",feature:`gantt.${Y.index}.dependencies`,message:"Gantt dependency endpoints are retained as owned after/until text rather than geometric arrows between bars."})}return Fe(P,{colorMode:r,theme:i,trimEnd:true})}function CR(t,e){return" ".repeat(t)+e}function XE(t,e,r,i,n,o){n??=e.targetWidth??e.maxWidth;const s=kt(t.commits.map(V=>V.id));const a=[...t.branches].sort((V,N)=>V.order-N.order||V.sequence-N.sequence||qt(V.name,N.name));const l=new Map(a.map((V,N)=>[V.name,N]));const c=t.title??e.title;const d=c?ve(c,n):[];const u=0;const h=Math.max(4,...a.map(V=>ne(V.name)));const m=Math.max(0,...t.commits.map(V=>V.sequence));const f=t.direction==="TB"||t.direction==="BT";const p=f?Math.max(1,a.length):m+1;const g=n===void 0?void 0:Math.max(1,Math.floor((n-(f?1:h+3))/p)-(f?6:4));const y=new Map(t.commits.map(V=>{const N=ve(Qs(V),g);for(const J of V.tags)N.push(...ve(`tag: ${J}`,g));if(V.syntheticCherryTag&&!V.tags.includes(V.syntheticCherryTag))N.push(...ve(`tag: ${V.syntheticCherryTag}`,g));return[V.id,N]}));const C=Math.max(3,...[...y.values()].flat().map(V=>ne(V)+2));const w=Math.max(5,C+2);const x=Math.max(3,...[...y.values()].map(V=>V.length+2));const k=(V,N)=>f?(l.get(N)??0)*Math.max(w+2,h+4)+1:h+3+V*w;const b=(V,N)=>f?u+2+V*(x+1):u+(l.get(N)??0)*x;const A=new Map(t.commits.map(V=>[V.id,{x:k(V.sequence,V.branch),y:b(V.sequence,V.branch)}]));const L=V=>e.useAscii&&(V.customType??V.type)==="CHERRY_PICK"?2:1;const B=Math.max(1,...t.commits.map(V=>A.get(V.id).x+L(V)+1+Math.max(...y.get(V.id).map(ne))+2),...d.map(ne),f?a.length*Math.max(w+2,h+4):h);const O=Math.max(u+1,...t.commits.map(V=>A.get(V.id).y+(y.get(V.id)?.length??1)+1));const M=new Re(B,O);const E=i.accent??"#3b82f6",_=i.bg??"#ffffff";const q=/^#[0-9a-f]{6}$/i.test(E)?E:"#3b82f6";const Q=/^#[0-9a-f]{6}$/i.test(_)?_:"#ffffff";const $=Sc(a.length,a.length<=6?{accent:q,bg:Q}:{accent:E,bg:_});const D=new Map(a.map((V,N)=>[V.name,Ar(o?.[`git${N%8}`])??$[N]]));const P=(V,N,J,ee)=>({owner:V,role:J,kind:ee,color:D.get(N)});a.forEach(V=>{const N={id:s(`branch:${V.name}`,["branch",V.name]),kind:"lane",members:t.commits.filter(X=>X.branch===V.name).map(X=>X.id)};const J=f?k(0,V.name):Math.max(0,h-ne(V.name));const ee=f?u:b(0,V.name);M.textBlock(J,ee,V.name,P(N,V.name,"text","text"));if(f)for(let X=u+1;X<=O;X++)M.stroke(J,X,5,{...P(N,V.name,"line","stroke"),ascii:e.useAscii});else for(let X=h+1;X<B;X++)M.stroke(X,ee,10,{...P(N,V.name,"line","stroke"),ascii:e.useAscii})});const U=new Map(t.commits.map(V=>[V.id,V]));const j=t.commits.flatMap(V=>V.parents.flatMap(N=>{const J=U.get(N),ee=A.get(N),X=A.get(V.id);return J&&ee?[{commit:V,parent:J,source:ee,target:X,id:s(`edge:${N}:${V.id}`,["edge",N,V.id])}]:[]}));const G=j.map((V,N)=>N);const se=V=>G[V]===V?V:G[V]=se(G[V]);const ce=new Map;const ae=(V,N,J,ee)=>{if(J===ee)return;const X=ce.get(V)??[];X.push({index:N,start:Math.min(J,ee),end:Math.max(J,ee)});ce.set(V,X)};j.forEach((V,N)=>{ae(JSON.stringify(["rail",V.parent.branch]),N,f?V.source.y:V.source.x,f?V.target.y:V.target.x);ae(JSON.stringify(["stem",V.commit.id]),N,f?V.source.x:V.source.y,f?V.target.x:V.target.y)});for(const V of ce.values()){V.sort((J,ee)=>J.start-ee.start||J.end-ee.end||J.index-ee.index);let N=V[0];for(const J of V.slice(1)){if(J.start<N.end){G[se(J.index)]=se(N.index);if(J.end>N.end)N=J}else N=J}}const Y=new Map;j.forEach((V,N)=>{const J=se(N);Y.set(J,(Y.get(J)??0)+1)});for(const[V,N]of j.entries()){const{commit:J,parent:ee,source:X,target:ie,id:ge}=N;const fe=se(V);const de=M.element({id:ge,kind:"edge",from:ee.id,to:J.id,...(Y.get(fe)??0)>1?{bundle:s(`shared-rail:${j[fe].id}`,["shared-rail",j[fe].id])}:{}});M.port(de,{nodeId:ee.id,...X,side:f?"B":"R",end:"start",markers:[]});M.port(de,{nodeId:J.id,...ie,side:f?X.x===ie.x?"T":X.x<ie.x?"L":"R":X.y===ie.y?"L":X.y<ie.y?"T":"B",end:"end",markers:[]});const xe=[X,f?{x:X.x,y:ie.y}:{x:ie.x,y:X.y},ie];const we=new Map;const Be=(Ie,Me,Ae)=>{const He=`${Ie},${Me}`,Ne=we.get(He);if(Ne)Ne.mask|=Ae;else we.set(He,{x:Ie,y:Me,mask:Ae})};for(let Ie=1;Ie<xe.length;Ie++){const Me=xe[Ie-1],Ae=xe[Ie],He=Math.sign(Ae.x-Me.x),Ne=Math.sign(Ae.y-Me.y);const K=He>0?2:He<0?8:Ne>0?4:1,pe=He>0?8:He<0?2:Ne>0?1:4;let{x:ke,y:Ee}=Me;while(ke!==Ae.x||Ee!==Ae.y){Be(ke,Ee,K);ke+=He;Ee+=Ne;Be(ke,Ee,pe)}}for(const{x:Ie,y:Me,mask:Ae}of we.values()){if(Ie===X.x&&Me===X.y||Ie===ie.x&&Me===ie.y)continue;M.stroke(Ie,Me,Ae,{...P(de,J.branch,"line","stroke"),ascii:e.useAscii})}}for(const V of t.commits){const{x:N,y:J}=A.get(V.id);const ee=V.customType??V.type;const X=ee==="HIGHLIGHT"?"#":ee==="REVERSE"?"X":ee==="MERGE"?e.useAscii?"O":"\u25CE":ee==="CHERRY_PICK"?e.useAscii?"<>":"\u25C6":"*";const ie={id:V.id,kind:"node",parent:{id:s(`branch:${V.branch}`,["branch",V.branch]),kind:"lane"}};M.mark(N,J,X,P(ie,V.branch,"arrow","marker"));M.scope(ie,()=>{M.textBlock(N+ne(X)+1,J+1,(y.get(V.id)??[Qs(V)]).map(ge=>`[${ge}]`),P(ie,V.branch,"text","text"))})}if(t.direction==="BT")M.flip(false,true);if(d.length){const V=new Re(Math.max(M.width,...d.map(ne)),M.height+d.length+1);V.scope({id:"title",kind:"label"},()=>d.forEach((N,J)=>V.textBlock(Math.floor((V.width-ne(N))/2),J,N)));V.overlay(M,0,d.length+1);return Fe(V,{colorMode:r,theme:i,trimEnd:true})}return Fe(M,{colorMode:r,theme:i,trimEnd:true})}function kR(t,e){const r=e?"#":"\u25CF";const i=e?".":"\u25CB";const n=Math.floor(t);const o=!Number.isInteger(t);const s=[{text:r.repeat(n),role:"arrow",kind:"mark"},...o?[{text:e?"+":"\u25D0",role:"arrow",kind:"mark"}]:[],{text:i.repeat(5-n-Number(o)),role:"border",kind:"mark"}];return s.filter(a=>a.text.length>0)}var SR=["\u2581","\u2582","\u2584","\u2586","\u2588"];function wR(t,e){return t.sections.map(r=>{const i=r.tasks.some(n=>!Number.isInteger(n.score));return r.tasks.map(n=>e?String(n.score):SR[Math.round(n.score)-1]).join(e&&i?" ":"")}).filter(r=>r.length>0).join(" ")}function KE(t,e,r="none",i=Pr,n,o){n??=e.maxWidth;const s=st(t);const a=BC(s.familyLines,s.accessibility);const l=e.useAscii;const c=new Re;if(a.sections.some(m=>m.tasks.length))c.report({code:"TERMINAL_FAMILY_PROJECTION",feature:"journey.axis",message:"Journey uses ordered scored task lists and a score strip rather than a geometric axis arrow; task order, actors and exact scores are retained."});let d;const u=(m=[])=>{c.line(m,{owner:d})};if(a.title){d={id:"title",kind:"label"};for(const m of ve(Ge(Ye(a.title,a.titleContent)),n)){u([{text:m,role:"text"}])}u()}const h=wR(a,l);if(h){d={id:"score-strip",kind:"label"};const m="scores: ";const f=ve(h,n?Math.max(1,n-m.length):void 0,{hyphenate:false});f.forEach((p,g)=>{u([g===0?{text:m,role:"border",kind:"text"}:{text:" ".repeat(m.length),role:null},{text:p,role:"arrow",kind:"mark"}])});u()}for(let m=0;m<a.sections.length;m++){const f=a.sections[m];const p=c.height;const g={id:f.id,kind:"band",members:f.tasks.map(y=>y.id)};d=g;if(f.label){const y=en(o,"group-header",{category:f.label},{includeFallback:false});const C=y?.cue??"none";const w=C==="outline"?l?"* ":"\u25C7 ":C==="double-line"?l?"= ":"\u2551 ":C==="pattern"?l?"# ":"\u2591 ":"";const x=ve(Ge(Ye(f.label,f.labelContent)).replace(/\n/g," / "),n?Math.max(1,n-2-w.length):void 0);x.forEach((k,b)=>{const A=[{text:b===0?w:" ".repeat(w.length),role:w?"arrow":null},b===0?{text:"[",role:"border"}:{text:" ",role:null},{text:k,role:"text"}];if(b===x.length-1)A.push({text:"]",role:"border"});u(A)})}for(let y=0;y<f.tasks.length;y++){const C=f.tasks[y];d={id:C.id,kind:"node",parent:{id:f.id,kind:"band"}};const w=kR(C.score,l);const x=5;const k=x+1;const b=Number.isInteger(C.score)?"":` (score ${C.score})`;const A=ve(Ge(Ye(C.text,C.textContent))+b,n?Math.max(1,n-k):void 0);u([...w,{text:" ",role:null},{text:A[0]??"",role:"text"}]);for(const O of A.slice(1)){u([{text:" ".repeat(k),role:null},{text:O,role:"text"}])}if(C.actors.length>0){d={id:`${C.id}:actors`,kind:"label",parent:{id:C.id,kind:"node"}};const O=" by ";const M=ve(C.actors.map((E,_)=>Ge(Ye(E,C.actorContents?.[_]))).join(", "),n?Math.max(1,n-ne(O)):void 0);M.forEach((E,_)=>{u([{text:_===0?" ":" ".repeat(ne(O)),role:null},..._===0?[{text:"by",role:"border",kind:"text"},{text:" ",role:null}]:[],{text:E,role:"text"}])})}const L=y<f.tasks.length-1;const B=m<a.sections.length-1;if(L||B)u()}if(c.height>p)c.region(g,{x:0,y:p,width:c.width,height:c.height-p})}return Fe(c,{colorMode:r,theme:i,trimEnd:true})}function QE(t,e,r,i,n){n??=e.targetWidth??e.maxWidth;const o=c=>[c.id,...c.children.flatMap(o)];const s=kt(o(t.root));const a=new Re;const l=(c,d,u,h=false,m,f=[],p)=>{const g=h?"":u?e.useAscii?"`- ":"\u2514\u2500 ":e.useAscii?"+- ":"\u251C\u2500 ";const y=d+g;const C=c.icon?`{${c.icon}} `:"";const w=n===void 0?void 0:Math.max(1,n-ne(y)-ne(C)-4);const x=ve(Ge(c.label),w);const k={id:c.id,kind:"node",parent:m===void 0?void 0:{id:m,kind:"node"}};const[b,A]=JE(c);const L={id:s(`edge:${c.id}`),kind:"edge",from:m,to:c.id};const B=ne(y),O=ne(d);x.forEach((_,q)=>{const Q=a.height;a.line([{text:" ".repeat(B),owner:L,role:"line",kind:"surface"},{text:b+C,owner:k,role:"arrow",kind:"marker"},{text:_,owner:k,role:"text",kind:"text",textGroup:"label"},{text:A,owner:k,role:"arrow",kind:"marker"}]);if(q!==0)return;const $={owner:L,role:"line",ascii:e.useAscii};for(const D of f)a.stroke(D,Q,5,$);if(p){if(e.useAscii)a.put(0,Q,p,{owner:L,role:"line",kind:"marker"});else a.marker(0,Q,{shape:"triangle",direction:p},$)}if(!h){if(e.useAscii&&u)a.put(O,Q,"`",{owner:L,role:"line",kind:"marker"});else a.stroke(O,Q,u?3:7,$);a.stroke(O+1,Q,10,$)}});const M=h?"":d+" ";const E=!h&&!u?[...f,O]:f;c.children.forEach((_,q)=>l(_,M,q===c.children.length-1,false,c.id,E,p))};if(t.root.children.length>=2){const c=[],d=[];t.root.children.forEach((g,y)=>(y%2===1?c:d).push(g));const u={id:t.root.id,kind:"node"};const[h,m]=JE(t.root);const f=t.root.icon?`{${t.root.icon}} `:"";const p=ve(Ge(t.root.label),n===void 0?void 0:Math.max(1,n-8-ne(h+f+m)));p.forEach(g=>{const y=a.height;a.line([{text:" ",owner:u,role:"arrow",kind:"surface"},{text:h+f,owner:u,role:"arrow",kind:"marker"},{text:g,owner:u,role:"text",kind:"text",textGroup:"label"},{text:m,owner:u,role:"arrow",kind:"marker"},{text:" ",owner:u,role:"arrow",kind:"surface"}]);const C={owner:u,role:"arrow",ascii:e.useAscii};const w=7+ne(h+f+g+m);a.marker(0,y,{shape:"triangle",direction:"L",ascii:e.useAscii},C);a.stroke(1,y,10,C);a.stroke(2,y,10,C);a.stroke(w-2,y,10,C);a.stroke(w-1,y,10,C);a.marker(w,y,{shape:"triangle",direction:"R",ascii:e.useAscii},C)});c.forEach((g,y)=>l(g," ",y===c.length-1,false,t.root.id,[],"L"));d.forEach((g,y)=>l(g," ",y===d.length-1,false,t.root.id,[],"R"))}else l(t.root,"",true,true);return Fe(a,{colorMode:r,theme:i,trimEnd:true})}function JE(t){if(t.shape==="rect")return["[","]"];if(t.shape==="rounded")return["(",")"];if(t.shape==="circle")return["((","))"];if(t.shape==="hexagon")return["{{","}}"];if(t.shape==="cloud")return[")","("];if(t.shape==="bang")return["))","(("];return["",""]}var pp=30;function Va(t){return $t(t,true).replace(/\r/g,"?")}function ZE(t,e,r,i,n={},o,s,a){o??=e.maxWidth;const l=Do(t);l.title??=e.title;const c=e.useAscii?"#":"\u2588";const d=_C(l.entries);const u=new Re;const h=s??IC(n);const m=(B,O,M)=>u.report({code:"TERMINAL_FAMILY_PROJECTION",feature:B,message:`${B}=${JSON.stringify(O)} is represented by ${M}; source configuration is retained.`});if(l.entries.length>0){if(h.donutHole>0)m("pie.donutHole",h.donutHole,"a proportional bar list without a circular hole");if(h.legendPosition!=="right")m("pie.legendPosition",h.legendPosition,"the complete slice labels beside their bars, in source order");if(h.textPosition!==.75)m("pie.textPosition",h.textPosition,"percentages in a fixed value column beside the bars");for(const[B,O]of[["pieStrokeColor",h.strokeColor],["pieStrokeWidth",h.strokeWidth]]){if(O!==void 0)m(`themeVariables.${B}`,O,"solid bar glyphs without separate slice outlines")}for(const[B,O]of[["pieOuterStrokeColor",h.outerStrokeColor],["pieOuterStrokeWidth",h.outerStrokeWidth]]){if(O!==void 0)m(`themeVariables.${B}`,O,"a bar list without an outer circle")}if(h.opacity!==void 0&&h.opacity!==1)m("themeVariables.pieOpacity",h.opacity,"opaque per-slice terminal glyphs");for(const[B,O]of[["pieSectionTextSize",h.sectionTextSize],["pieLegendTextSize",h.legendTextSize]]){if(O!==void 0)m(`themeVariables.${B}`,O,"the terminal font cell size with complete wrapped text")}}if(l.title&&h.titleTextSize!==void 0)m("themeVariables.pieTitleTextSize",h.titleTextSize,"the terminal font cell size with the complete title");const f=h.highlightSlice==="hover"?void 0:h.highlightSlice;const p=Po(l.entries.length,{accent:i.accent,bg:i.bg,overrides:h.paletteOverrides});const g=l.entries.map(B=>en(a,"pie-slice",{category:B.label,value:B.value},{includeFallback:false}));const y=g.some(B=>B?.cue!==void 0&&B.cue!=="none");const C=Math.max(...l.entries.map(B=>B.value));const w=l.entries.map(B=>l.showData?ne(` [${Fh(B.value)}]`):0);const x=f!==void 0||y?2:0;const k=x+2+pp+2+6+Math.max(0,...w);const b=o?Math.max(1,o-k):void 0;const A=l.entries.map(B=>ve(Va(B.displayLabel??B.label),b));const L=Math.max(...A.flat().map(ne));if(l.title)for(const B of ve(Va(l.displayTitle??l.title),o)){u.line([{text:B,role:"text",color:h.titleTextColor,textGroup:"title",owner:{id:"title",kind:"label"}}])}l.entries.forEach((B,O)=>{const M=d>0?B.value/d:0;const E=B.value>0?Math.max(1,Math.round(B.value/C*pp)):0;const _=c.repeat(E);const q=" ".repeat(pp-E+2);const Q=LC(M).padStart(6);const $=l.showData?` [${Fh(B.value)}]`:"";const D=A[O];for(let se=0;se<D.length-1;se++){u.line([{text:" ".repeat(x),kind:"surface"},{text:D[se],role:"text",color:h.legendTextColor,textGroup:"label",owner:{id:`slice-${O}`,kind:"node"}}])}const P=f===B.label;const U=g[O]?.cue??"none";const j=U==="outline"?e.useAscii?"* ":"\u25C7 ":U==="double-line"?"= ":U==="pattern"?e.useAscii?"# ":"\u2591 ":"";const G=P?"> ":j||(f!==void 0||y?" ":"");u.line([{text:G,role:"arrow",kind:"marker",owner:{id:`slice-${O}:highlight`,kind:"label",parent:{id:`slice-${O}`,kind:"node"}}},{text:D.at(-1)??"",role:"text",color:h.legendTextColor,textGroup:"label",owner:{id:`slice-${O}`,kind:"node"}},{text:" ".repeat(Math.max(0,L-ne(D.at(-1)??""))+2),kind:"surface"},{text:_,role:"arrow",kind:"mark",color:p[O],owner:{id:`slice-${O}:bar`,kind:"plot",parent:{id:`slice-${O}`,kind:"node"}}},{text:q,kind:"surface"},{text:Q,role:"text",color:h.sectionTextColor,textGroup:"value",owner:{id:`slice-${O}:value`,kind:"label",parent:{id:`slice-${O}`,kind:"node"}}},{text:$,role:"text",color:h.legendTextColor,textGroup:"value",owner:{id:`slice-${O}:value`,kind:"label",parent:{id:`slice-${O}`,kind:"node"}}}])});return Fe(u,{colorMode:r,theme:i})}var Vt=41;var hr=21;function tM(t,e,r,i,n){n??=e.maxWidth;const o=$n(t);const s=o.points.map(y=>bb(y,o.classDefs,{radius:5}));const a=s.map(y=>{const C=y.fill?.trim().toLowerCase()==="none"||y.fill?.trim().toLowerCase()==="transparent";return{glyph:C?e.useAscii?"o":"\u25CB":e.useAscii?"*":"\u25CF",color:(C?y.stroke:y.fill)??TR(i)}});const l=new Re(Vt+2,hr+2);const c={id:"quadrant-plot",kind:"plot"};const d=(y,C,w)=>l.stroke(y,C,w,{ascii:e.useAscii,role:"border",owner:c});const u=Math.floor(Vt/2);const h=Math.floor(hr/2);for(let y=0;y<hr;y++)d(u+1,y+1,5);for(let y=0;y<Vt;y++)d(y+1,h+1,10);const m=new Set;o.points.forEach((y,C)=>{const w=Math.round(y.x*(Vt-1));const x=Math.round((1-y.y)*(hr-1));const k=a[C];l.put(w+1,x+1,k.glyph,{role:"arrow",kind:"marker",color:k.color,owner:{id:`point-${C}`,kind:"node"}});m.add(`${x},${w}`)});const f=o.points.length>0;const p=[];for(const[y,C,w,x,k]of[[2,0,0,h,u],[1,0,u+1,h,Vt],[3,h+1,0,hr,u],[4,h+1,u+1,hr,Vt]]){const b=vR(l,m,o.quadrants[y-1],C,w,x,k,f,y);if(b!==void 0)p.push({quadrant:y,text:b})}const g=new Re;s.forEach((y,C)=>{const w=o.points[C];const x=w.className&&Object.hasOwn(o.classDefs,w.className)?o.classDefs[w.className]:void 0;const k=w.style?.radius??x?.radius;if(k!==void 0)g.report({code:"TERMINAL_FAMILY_PROJECTION",feature:`quadrant.point-${C}.radius`,message:`Quadrant point-${C} radius=${y.radius}px is represented by one terminal marker cell; normalized coordinates and the complete point label are retained.`});if(y.stroke!==void 0||y.strokeWidth!==void 0)g.report({code:"TERMINAL_FAMILY_PROJECTION",feature:`quadrant.point-${C}.stroke`,message:`Quadrant point-${C} stroke=${JSON.stringify(y.stroke??"theme default")}, stroke-width=${JSON.stringify(y.strokeWidth??"theme default")} is projected to a single ${a[C].glyph} marker; a separate pixel outline and its width are unavailable. Hollow markers use the resolved stroke paint.`})});if(o.title){for(const y of ve(Ge(o.title),n))g.line([{text:ER(y,Vt+2),role:"text",textGroup:"title",owner:{id:"title",kind:"label"}}])}d(0,0,6);d(Vt+1,0,12);d(0,hr+1,3);d(Vt+1,hr+1,9);for(let y=1;y<=Vt;y++){d(y,0,y===u+1?14:10);d(y,hr+1,y===u+1?11:10)}for(let y=1;y<=hr;y++){d(0,y,y===h+1?7:5);d(Vt+1,y,y===h+1?13:5)}l.region(c,{x:0,y:0,width:Vt+2,height:hr+2});for(const[y,C,w,x,k]of[[1,u+2,1,Vt-u-1,h],[2,1,1,u,h],[3,1,h+2,u,hr-h-1],[4,u+2,h+2,Vt-u-1,hr-h-1]])l.region({id:`quadrant#${y}`,kind:"compartment"},{x:C,y:w,width:x,height:k});g.overlay(l,0,g.height);if(o.xAxis){const y=Vi(o.xAxis.near);const C=o.xAxis.far===void 0?void 0:Vi(o.xAxis.far);const w=n??Math.max(Vt+2,ne(y)+(C?ne(C)+1:0));const x=C?Math.max(1,Math.floor((w-1)/2)):w;const k=ve(y,x);const b=C?ve(C,x):[];const A=g.height;g.textBlock(0,A,k.join("\n"),{role:"text",owner:{id:"x-axis-near",kind:"label"}});if(C)g.textBlock(w-Math.max(...b.map(ne)),A,b.join("\n"),{role:"text",owner:{id:"x-axis-far",kind:"label"}})}if(o.yAxis){const y="y-axis bottom: ";const C=Vi(o.yAxis.near);const w=o.yAxis.far?Vi(o.yAxis.far):void 0;const x=y+C+(w?` | top: ${w}`:"");if(n===void 0||ne(x)<=n){g.line([{text:y,role:"border",kind:"text",owner:{id:"y-axis-near:prefix",kind:"label",parent:{id:"y-axis-near",kind:"label"}}},{text:C,role:"text",owner:{id:"y-axis-near",kind:"label"}},...w?[{text:" | top: ",role:"border",kind:"text",owner:{id:"y-axis-far:prefix",kind:"label",parent:{id:"y-axis-far",kind:"label"}}},{text:w,role:"text",owner:{id:"y-axis-far",kind:"label"}}]:[]])}else{for(const[k,b,A]of[["y-axis-near","bottom: ",C],["y-axis-far","top: ",w]]){if(A===void 0)continue;const L=ve(A,Math.max(1,n-ne(b)));const B=g.height;g.textBlock(0,B,b,{role:"border",kind:"text",owner:{id:`${k}:prefix`,kind:"label",parent:{id:k,kind:"label"}}});g.textBlock(ne(b),B,L.join("\n"),{role:"text",owner:{id:k,kind:"label"}})}}}for(const{quadrant:y,text:C}of p){const w=`quadrant-${y}: `;const x=ve(C,Math.max(1,(n??Vt+2)-ne(w)));x.forEach((k,b)=>g.line([{text:b===0?w:" ".repeat(ne(w)),role:"border",kind:b===0?"text":"surface",owner:{id:`quadrant-label#${y}:prefix`,kind:"label",parent:{id:`quadrant-label#${y}`,kind:"label"}}},{text:k,role:"text",textGroup:"label",owner:{id:`quadrant-label#${y}`,kind:"label"}}]))}if(o.points.length>0){g.line();for(const[y,C]of o.points.entries()){const w=`: [${eM(C.x)}, ${eM(C.y)}]`;const x=ve(Ge(C.label),n?Math.max(1,n-ne(w)-2):void 0);x.forEach((k,b)=>g.line([{text:a[y].glyph,role:"arrow",kind:"marker",color:a[y].color,owner:{id:`point-${y}:legend`,kind:"label",parent:{id:`point-${y}`,kind:"node"}}},{text:" ",kind:"surface"},{text:k,role:"text",textGroup:"legend",owner:{id:`point-${y}`,kind:"node"}},{text:b===x.length-1?w:"",role:"text",owner:{id:`point-${y}:coordinates`,kind:"label",parent:{id:`point-${y}`,kind:"node"}}}]))}}return Fe(g,{colorMode:r,theme:i})}function TR(t){return t.accent??t.fg}function eM(t){return Number.isInteger(t)?String(t):String(Math.round(t*100)/100)}function vR(t,e,r,i,n,o,s,a,l){if(!r)return;const c=s-n;const d=o-i;const u=Vi(r);if(c<=0||d<=0)return u;const h=ve(u,c).map(mt);if(h.length>d||h.some(p=>p.width>c))return u;const m=a?i+1:i+Math.floor((d-h.length)/2);const f=[m,...Array.from({length:d-h.length+1},(p,g)=>i+g)];for(const p of new Set(f)){if(p<i||p+h.length>o)continue;const g=h.map((C,w)=>({text:C,row:p+w,column:n+Math.floor((c-C.width)/2)}));const y=g.every(C=>Array.from({length:C.text.width},(w,x)=>!e.has(`${C.row},${C.column+x}`)).every(Boolean));if(!y)continue;for(const C of g)t.textBlock(C.column+1,C.row+1,C.text,{role:"text",textGroup:"label",owner:{id:`quadrant-label#${l}`,kind:"label"}});return}return u}function ER(t,e){const r=ne(t);if(r>=e)return t;const i=Math.floor((e-r)/2);return" ".repeat(i)+t}var rM=24;function Cn(t,e){const r=t.split("\n").flatMap(i=>ve(i.trim(),e)).filter(Boolean);return r.length>0?r:[""]}function MR(t){let e=0;for(const r of t)for(const i of Cn(r))e=Math.max(e,ne(i));return e}function iM(t,e,r){const i=new Map,n=new Map;for(const o of t)i.set(o,(i.get(o)??0)+1);return t.map(o=>{const s=n.get(o)??0;n.set(o,s+1);const a=i.get(o)>1?`${o}#${s}`:o;return e.has(o)?`${r}:${a}`:a})}function nM(t,e,r,i,n={},o,s){o??=e.maxWidth;const a=ra(t,{title:wl(n,["title"])});const l=iM(a.axes.map(E=>E.id),new Set(a.curves.map(E=>E.id)),"axis");const c=iM(a.curves.map(E=>E.id),new Set(a.axes.map(E=>E.id)),"curve");const d=new Map(a.curves.map((E,_)=>[E,c[_]]));const u=e.useAscii?"|":"\u2502";const h=E=>{const _=en(s,"pie-slice",{category:E},{includeFallback:false})?.cue;if(_==="outline")return e.useAscii?{marker:"+",bar:"+"}:{marker:"\u25C7",bar:"\u25A1"};if(_==="double-line")return e.useAscii?{marker:"=",bar:"="}:{marker:"\u25C8",bar:"\u2550"};if(_==="pattern")return e.useAscii?{marker:"%",bar:"%"}:{marker:"\u2591",bar:"\u2591"};return e.useAscii?{marker:"*",bar:"#"}:{marker:"\u25CF",bar:"\u2588"}};const m=RC(n);const f=Po(a.curves.length,{accent:i.accent,bg:i.bg,overrides:m.paletteOverrides});const p=ia(a);const g=a.curves.filter(E=>E.values.length===a.axes.length);const y=MR(a.axes.map(E=>E.label));let C=1;for(const E of g)for(const _ of E.values)C=Math.max(C,ne(Ph(_)));const w=o===void 0?void 0:Math.max(2,o-8-C);const x=w===void 0?void 0:Math.max(1,Math.min(y,Math.floor(w/2)));const k=w===void 0?void 0:Math.max(1,w-x);const b=Math.max(0,...a.axes.flatMap(E=>Cn(E.label,x)).map(ne));const A=Math.max(0,...g.flatMap(E=>Cn(E.label,k)).map(ne));let L=rM;if(o){const E=b+2+A+1+ne(u)+1+1+C;L=Math.max(3,Math.min(rM,o-E))}const B=new Re;const O=(E,_,q)=>B.report({code:"TERMINAL_FAMILY_PROJECTION",feature:E,message:`${E}=${JSON.stringify(_)} is represented by ${q}; source configuration is retained.`});if(a.axes.length>0){for(const E of["width","height","marginTop","marginRight","marginBottom","marginLeft","axisScaleFactor","axisLabelFactor"]){if(m[E]!==void 0)O(`radar.${E}`,m[E],"measured terminal label columns and a proportional bar scale, rather than pixel polar positions")}if(m.axisLabelFontSize!==void 0)O("themeVariables.radar.axisLabelFontSize",m.axisLabelFontSize,"the terminal font cell size with complete wrapped axis labels");if(m.axisStrokeWidth!==void 0)O("themeVariables.radar.axisStrokeWidth",m.axisStrokeWidth,"single-cell column separator glyphs")}if(g.length>0){O("radar.graticule",{shape:a.graticule,ticks:a.ticks},"owned threshold marks on the numeric bar ruler rather than concentric polar rings");if(a.graticule==="circle"&&m.curveTension!==void 0)O("radar.curveTension",m.curveTension,"independent per-axis bars without interpolated closed curves");if(m.tickLabels===true)O("radar.tickLabels",true,"the scale minimum/maximum and owned threshold marks; individual ring-value labels are not emitted");for(const E of["curveStrokeWidth","graticuleStrokeWidth"]){if(m[E]!==void 0)O(`themeVariables.radar.${E}`,m[E],"single-cell bar/ruler glyphs without pixel stroke widths")}for(const E of["curveOpacity","graticuleOpacity"]){if(m[E]!==void 0&&m[E]!==1)O(`themeVariables.radar.${E}`,m[E],"opaque terminal bar/ruler glyphs")}}if(a.showLegend&&a.curves.length>0){for(const E of["legendBoxSize","legendFontSize"]){if(m[E]!==void 0)O(`themeVariables.radar.${E}`,m[E],"single-cell legend markers and the terminal font cell size with complete wrapped series labels")}}if(a.title&&m.titleFontSize!==void 0)O("themeVariables.fontSize",m.titleFontSize,"the terminal font cell size with the complete Radar title");if(m.useMaxWidth===true)B.report({code:"TERMINAL_RENDER_OPTION_NOT_APPLICABLE",feature:"radar.useMaxWidth",message:"radar.useMaxWidth=true controls responsive SVG sizing; terminal output uses its measured cell width and the terminal width policy."});if(a.title)for(const E of ve(a.title,o)){B.line([{text:E,role:"text",color:m.titleColor,textGroup:"title",owner:{id:"title",kind:"label"}}])}if(a.showLegend&&a.curves.length>0){let E=[];let _=0;a.curves.forEach((q,Q)=>{const $=d.get(q);const D=h(q.label).marker;const P=ve(Cn(q.label).join(" "),o===void 0?void 0:Math.max(1,o-2));P.forEach((U,j)=>{const G=2+ne(U);if(E.length>0&&(j>0||o!==void 0&&_+3+G>o)){B.line(E);E=[];_=0}if(E.length>0){E.push({text:" ",kind:"surface"});_+=3}E.push({text:D,role:"arrow",kind:"marker",color:f[Q],owner:{id:`${$}:legend`,kind:"label",parent:{id:$,kind:"node"}}},{text:" ",kind:"surface"},{text:U,role:"text",textGroup:"legend",owner:{id:$,kind:"node"}});_+=G})});if(E.length>0)B.line(E);B.line()}const M=a.curves.filter(E=>E.values.length!==a.axes.length);if(M.length>0){for(const E of M){const _=`! ${Cn(E.label).join(" ")}: expected ${a.axes.length} values, got ${E.values.length}; not plotted`;for(const q of ve(_,o))B.line([{text:q,role:"text",textGroup:"warning",owner:{id:d.get(E),kind:"node"}}])}B.line()}if(g.length>0){for(const q of ve(`scale: ${p.min} .. ${p.max}`,o)){B.line([{text:q,role:"text",owner:{id:"radar-scale",kind:"label"}}])}const E=B.height;const _=b+A+5;for(let q=0;q<a.ticks;q++){const Q=_+Math.max(0,Math.round((q+1)/a.ticks*L)-1);B.stroke(Q,E,14,{ascii:e.useAscii,role:"border",color:m.graticuleColor,owner:{id:`ring:${q}`,kind:"ring"}})}B.line()}if(g.length===0){for(const[E,_]of a.axes.entries()){for(const q of Cn(_.label,x)){B.line([{text:q,role:"text",textGroup:"axis",owner:{id:l[E],kind:"node"}},{text:" ".repeat(Math.max(0,b-ne(q))+2)+u,role:"border",kind:"stroke",color:m.axisColor,owner:{id:l[E],kind:"node"}}])}}}a.axes.forEach((E,_)=>{g.forEach((q,Q)=>{const $=l[_],D=d.get(q);const P=q.values[_];const U=zb(P,p);const j=U>0?Math.max(1,Math.round(U*L)):0;const G=h(q.label).bar.repeat(j);const se=a.curves.indexOf(q);const ce=Q===0?Cn(E.label,x):[""];const ae=Cn(q.label,k);const Y=Math.max(ce.length,ae.length);for(let V=0;V<Y;V++){const N=V===0?` ${Ph(P).padStart(C)}`:"";B.line([{text:ce[V]??"",role:"text",textGroup:"axis",...Q===0?{owner:{id:$,kind:"node"}}:{}},{text:" ".repeat(Math.max(0,b-ne(ce[V]??""))+2),kind:"surface"},{text:ae[V]??"",role:"text",textGroup:`table:${$}`,owner:{id:D,kind:"node"}},{text:" ".repeat(Math.max(0,A-ne(ae[V]??""))+1)+u+" ",role:"border",kind:"stroke",color:m.axisColor,owner:{id:$,kind:"node"}},{text:V===0?G:"",role:"arrow",kind:"mark",color:f[se],owner:{id:`${D}:${$}`,kind:"plot",parent:{id:D,kind:"node"}}},{text:N,role:"text",owner:{id:`${D}:${$}:value`,kind:"label",parent:{id:D,kind:"node"}}}])}})});return Fe(B,{colorMode:r,theme:i,trimEnd:true})}var oM=20;function sM(t,e,r,i,n={},o,s){o??=e.maxWidth;const a=s??NC(n);const l=typeof n.title==="string"?n.title:void 0;const c=gc(t,l!==void 0?{title:l}:{});const d=PC(c);const u=e.useAscii?"#":"\u2588";const h=e.useAscii?"|-> ":"\u251C\u2500\u25B6 ";const m=e.useAscii?"`-> ":"\u2514\u2500\u25B6 ";const f=e.useAscii?"| ":"\u2502 ";const p=Po(c.nodes.length,{accent:i.accent,bg:i.bg});const g=new Map;c.nodes.forEach(($,D)=>{g.set($,DC(a,$)??p[D])});const y=new Map;for(const $ of c.links){const D=y.get($.source);if(D)D.push($);else y.set($.source,[$])}const C=new Map;for(const $ of c.links){C.set($.source,(C.get($.source)??0)+$.value)}const w=Math.max(...c.links.map($=>$.value),0);const x=c.links.map($=>a.showValues?wc($.value,a):"");const k=Math.max(0,...x.map(ne));const b=2+4+2+(a.showValues?k+2:0)+oM;const A=o?Math.max(1,o-b):void 0;const L=new Re;L.titleHandled=true;const B=kt([...c.nodes,...d.links.map($=>$.id),...d.titleId?[d.titleId]:[]]);const O=Du(n,["config","sankey"])??Du(n,["sankey"])??{};const M=($,D,P)=>L.report({code:"TERMINAL_FAMILY_PROJECTION",feature:`sankey.${$}`,message:`sankey.${$}=${JSON.stringify(D)} is represented by ${P}; source configuration is retained.`});for(const $ of["width","height","nodeWidth","nodePadding"]){if(typeof O[$]==="number"&&O[$]===a[$]){M($,a[$],"measured adjacency-list columns and proportional bars rather than pixel ribbon/node geometry")}}if(typeof O.nodeAlignment==="string"&&O.nodeAlignment===a.nodeAlignment){M("nodeAlignment",a.nodeAlignment,"adjacency sections in first-appearance order rather than horizontal flow layers")}if(a.labelStyle==="outlined")M("labelStyle",a.labelStyle,"complete terminal labels without a pixel outline halo");if(a.linkColor.mode==="gradient")M("linkColor","gradient","solid target-colored bars rather than a source-to-target gradient");const E=new Map(c.links.map(($,D)=>[$,d.links[D]]));if(c.title){for(const $ of ve(Ge(c.title),o))L.line([{text:$,role:"text",textGroup:"title",owner:{id:d.titleId,kind:"label"}}]);L.line()}const _=c.nodes.filter($=>y.has($));const q=new Map;for(const $ of c.links){if(!q.has($.target)){q.set($.target,ve(Ge($.target),A))}}const Q=Math.max(0,...[...q.values()].flat().map(ne));_.forEach(($,D)=>{const P=y.get($);const U=a.showValues?` ${wc(C.get($)??0,a)}`:"";const j=ve(Ge($),o);for(let G=0;G<j.length-1;G++)L.line([{text:j[G],role:"text",textGroup:"header",owner:{id:$,kind:"node"}}]);L.line([{text:j.at(-1)??"",role:"text",textGroup:"header",owner:{id:$,kind:"node"}},{text:U,role:"text",owner:{id:B(`${$}:value`,["source-value",$]),kind:"label",parent:{id:$,kind:"node"}}}]);P.forEach((G,se)=>{const ce=se===P.length-1;const ae=ce?m:h;const Y=w>0&&G.value>0?Math.max(1,Math.round(G.value/w*oM)):0;const V=u.repeat(Y);const N=a.linkColor.mode==="static"?a.linkColor.color:g.get(a.linkColor.mode==="source"?G.source:G.target);const J=N.trim().toLowerCase()==="none"?"transparent":N;const ee=E.get(G);const X=ee.id;const ie={id:X,kind:"edge",from:ee.source,to:ee.target};if(Y>0&&r!=="none"&&r!=="html"){const xe=Ft(N);if(!xe||xe[3]!==1){const we=a.linkColor.mode==="static"?"sankey.linkColor":`sankey.nodeColors.${a.linkColor.mode==="source"?G.source:G.target}`;L.report({code:"TERMINAL_COLOR_UNREPRESENTABLE",feature:we,message:`${we}=${JSON.stringify(N)} cannot be encoded as an opaque terminal foreground; ANSI bars retain their owned cells without that paint. ${J===N?"HTML retains the safe CSS color.":"HTML projects absent paint to transparent ink."}`})}}const ge=a.showValues?`${AR(wc(G.value,a),k)} `:"";const fe=q.get(G.target);const de=ce?" ":f;fe.forEach((xe,we)=>{const Be=we===0?ae:de;if(we<fe.length-1){L.line([{text:` ${Be}`,role:"line",kind:"stroke",owner:ie},{text:xe,role:"text",textGroup:X,owner:{id:G.target,kind:"node"}}])}else{L.line([{text:` ${Be}`,role:"line",kind:"stroke",owner:ie},{text:xe,role:"text",textGroup:X,owner:{id:G.target,kind:"node"}},{text:" ".repeat(Math.max(0,Q-ne(xe))+2),kind:"surface"},{text:ge,role:"text",owner:{id:B(`${X}:value`,["link-value",X]),kind:"label",parent:{id:X,kind:"edge"}}},{text:V,role:"arrow",kind:"mark",color:J,owner:ie}])}})});if(D<_.length-1)L.line()});return Fe(L,{colorMode:r,theme:i,trimEnd:true})}function AR(t,e){const r=e-ne(t);return r>0?" ".repeat(r)+t:t}function dM(t,e,r,i,n){const o=ls(t,e,"cluster");fs(o);hs(o);if(t.stateNotes?.length)OR(o,t.stateNotes,n??e.maxWidth);if(t.direction==="BT"){$d(o.canvas)}return Fe(o.canvas,{colorMode:r,theme:i})}function OR(t,e,r){const i=r===void 0?void 0:Math.max(1,Math.floor(r/2)-4);const n=e.map(y=>({note:y,canvas:xn([Ge(Ye(y.text,y.textContent)).split(/\r?\n/).flatMap(C=>i?ve(C,i):[C])],t.config.useAscii,1)}));let o=0;for(const{note:y,canvas:C}of n){const w=lM(t,y.target);if(y.side==="left"&&w)o=Math.max(o,C.width+2-cM(w).x)}if(o>0)BR(t,o);const s=t.nodes.flatMap(y=>{const C=uM(y);return C?[C]:[]});const a=[...s];a.push(...t.subgraphs.filter(y=>!y.concurrencyRegion).map(Ya));const l=t.canvas,c=l.blank();const d=[...l.entries()];const u=[];const h=[];const m=[];for(const{note:y,canvas:C}of n){const w=lM(t,y.target);if(!w)continue;const x=cM(w);const k={x:y.side==="right"?x.x+x.width+2:x.x-C.width-2,y:Math.max(0,w.box.y+Math.floor((w.box.height-C.height)/2)),width:C.width,height:C.height};const b=aM(k,y.side);const A=new Set([k.y,...[...a,...h].map(L=>L.y+L.height+1),...d.filter(([L])=>L>=b.x&&L<b.x+b.width).map(([,L])=>L+2)]);k.y=[...A].filter(L=>L>=k.y).sort((L,B)=>L-B).find(L=>{const B={...b,y:L};return![...a,...h].some(O=>IR(B,O))&&!d.some(([O,M])=>hM(B,O,M))});c.scope({id:y.id,kind:"node",annotationTarget:{id:y.target,kind:w.kind}},()=>c.overlay(C,k.x,k.y));m.push({note:y,target:w,box:k});u.push(k);h.push(aM(k,y.side))}const f=new Map;const p=(y,C)=>JSON.stringify(["state-note",C.kind,y.target,y.side]);for(const{note:y,target:C}of m){const w=p(y,C);f.set(w,(f.get(w)??0)+1)}const g=m.map(({note:y,box:C})=>({x:y.side==="right"?C.x-1:C.x+C.width,y:C.y+Math.floor(C.height/2)}));for(const[y,{note:C,target:w,box:x}]of m.entries()){const k=p(C,w);const b={id:`${C.id}:link`,kind:"edge",from:C.target,to:C.id,...(f.get(k)??0)>1?{bundle:k}:{}};_R(l,c,t,s,w,x,u,g.filter((A,L)=>y!==L),C.side,b)}t.canvas.overlay(c)}function aM(t,e){return{...t,x:t.x-(e==="right"?1:0),width:t.width+1}}function Ya(t){return{x:t.minX,y:t.minY,width:t.maxX-t.minX+1,height:t.maxY-t.minY+1}}function lM(t,e){const r=t.subgraphs.find(o=>o.id===e&&!o.concurrencyRegion);if(r){const o=[];for(let s=r;s;s=s.parent)if(!s.concurrencyRegion)o.push(s);return{box:Ya(r),kind:"cluster",frames:o}}const i=t.nodes.find(o=>o.name===e&&!o.containerAnchor);const n=i&&uM(i);return n?{box:n,kind:"node",frames:t.subgraphs.filter(o=>!o.concurrencyRegion&&o.nodes.includes(i))}:void 0}function uM(t){return!t.containerAnchor&&t.drawingCoord&&t.drawing?{x:t.drawingCoord.x,y:t.drawingCoord.y,width:t.drawing.width,height:t.drawing.height??1}:void 0}function cM(t){const e=[t.box,...t.frames.map(Ya)];const r=Math.min(...e.map(n=>n.x)),i=Math.min(...e.map(n=>n.y));return{x:r,y:i,width:Math.max(...e.map(n=>n.x+n.width))-r,height:Math.max(...e.map(n=>n.y+n.height))-i}}function BR(t,e){const r=t.canvas.blank();r.overlay(t.canvas,e,0);t.canvas=r;for(const i of t.nodes)if(i.drawingCoord)i.drawingCoord.x+=e;for(const i of t.subgraphs){i.minX+=e;i.maxX+=e}t.offsetX+=e}function _R(t,e,r,i,n,o,s,a,l,c){const d=l==="right",u=d?1:-1;const h={nodeId:c.from,markers:[],end:"start",side:d?"R":"L",x:d?n.box.x+n.box.width-1:n.box.x,y:n.box.y+Math.floor(n.box.height/2)};const m={nodeId:c.to,markers:[],end:"end",side:d?"L":"R",x:d?o.x:o.x+o.width-1,y:o.y+Math.floor(o.height/2)};const f={x:m.x-u,y:m.y};const p=new Set(n.frames.filter(k=>n.kind!=="cluster"||k.id!==c.from).map(k=>k.id));const g=[...i];g.push(...s,...r.subgraphs.filter(k=>!k.concurrencyRegion&&!p.has(k.id)).map(Ya));g.push(...a.map(k=>({...k,width:1,height:1})));g.push(...n.frames.filter(k=>p.has(k.id)).map(k=>({...Ya(k),height:Ge(k.name).split("\n").length+2})));const y=k=>{if(k.x<0||k.y<0||g.some(A=>hM(A,k.x,k.y)))return false;const b=t.cell(k.x,k.y);return!b||!!b.stroke&&b.owners.length>0&&b.owners.every(A=>A.kind==="edge"||A.kind==="cluster"&&p.has(A.id))};const C=(k,b)=>{const A=k.x===b.x?5:10;return[k,b].every(L=>{if(!y(L))return false;const B=t.cell(L.x,L.y),O=e.cell(L.x,L.y);if(B?.stroke&&B.stroke.mask&A)return false;return!O||!!O.stroke&&O.owners.length>0&&O.owners.every(M=>M.kind==="edge")&&(!(O.stroke.mask&A)||!!c.bundle&&O.owners.every(M=>M.bundle===c.bundle))})};const w={extent:{maxX:Math.max(t.width,e.width),maxY:Math.max(t.height,e.height)},has:k=>{const[b,A]=k.split(",").map(Number);return!y({x:b,y:A})}};const x=new Set([h.y,...Array.from({length:Math.max(0,n.box.height-2)},(k,b)=>n.box.y+b+1)]);for(const k of[...x].sort((b,A)=>Math.abs(b-h.y)-Math.abs(A-h.y)||b-A)){const b={...h,y:k},A={x:h.x+u,y:k};const L=t.cell(b.x,b.y);if(L?.kind!=="stroke"||!L.glyph.trim()||!L.owners.some(M=>M.kind===n.kind&&M.id===c.from))continue;const B=y(A)&&y(f)?St(w,A,f,d?Pe:$e,C):null;if(!B||!B.every(y))continue;const O=Rd(c.id,b,m,B);if(ss(e,O,c,r.config.useAscii,"dotted"))return;break}e.report({code:"TERMINAL_GEOMETRY_COLLISION",feature:`state-note:${c.to}`,cell:{column:h.x,row:h.y},message:`No complete terminal attachment route could be allocated from ${c.from} to ${c.to}. The note remains visible without an attached connector.`})}function IR(t,e){return t.x<e.x+e.width&&e.x<t.x+t.width&&t.y<e.y+e.height&&e.y<t.y+t.height}function hM(t,e,r){return e>=t.x&&e<t.x+t.width&&r>=t.y&&r<t.y+t.height}function mM(t,e,r="none",i=Pr,n){n??=e.maxWidth;const o=yc(t);o.title??=e.title;const s=e.useAscii;const a=s?"o":"\u25CB";const l=s?"|":"\u2502";const c=s?"|":"\u251C";const d=s?"`":"\u2514";const u=s?"-":"\u2500";const h=" ";const m=new Re;if(o.direction!==void 0)m.report({code:"TERMINAL_FAMILY_PROJECTION",feature:"timeline.direction",message:`timeline ${o.direction} is represented by a chronological vertical outline; period order, events and section containment are retained rather than the graphical rail orientation.`});let f;const p=(g=[])=>{m.line(g,{owner:f})};if(o.title){f={id:"title",kind:"label"};for(const g of ve(o.title,n)){p([{text:g,role:"text"}])}p()}for(let g=0;g<o.sections.length;g++){const y=o.sections[g];const C=m.height;const w={id:y.id,kind:"band",members:y.periods.map(x=>x.id)};f=w;if(y.label){const x=ve(y.label.replace(/\n/g," / "),n?Math.max(1,n-2):void 0);x.forEach((k,b)=>{const A=[b===0?{text:"[",role:"border"}:{text:" ",role:null},{text:k,role:"text"}];if(b===x.length-1)A.push({text:"]",role:"border"});p(A)})}for(let x=0;x<y.periods.length;x++){const k=y.periods[x];f={id:k.id,kind:"node",parent:{id:y.id,kind:"band"}};const b=ve(k.label,n?Math.max(1,n-3):void 0);p([{text:a,role:"junction"},{text:" ",role:null},{text:b[0]??"",role:"text"}]);for(const B of b.slice(1)){p([{text:`${h} `,role:null},{text:B,role:"text"}])}for(let B=0;B<k.events.length;B++){const O=k.events[B];f={id:O.id,kind:"node",parent:{id:k.id,kind:"node"}};const M=ve(O.text,n?Math.max(1,n-6):void 0);const E=B===k.events.length-1?d:c;p([{text:l,role:"line"},{text:" ",role:null},{text:E,role:B===k.events.length-1?"corner":"junction"},{text:u,role:"line"},{text:" ",role:null},{text:M[0]??"",role:"text"}]);for(const _ of M.slice(1)){p(B===k.events.length-1?[{text:" ",role:null},{text:_,role:"text"}]:[{text:l,role:"line"},{text:" ",role:null},{text:_,role:"text"}])}}const A=x<y.periods.length-1;const L=g<o.sections.length-1;if(A||L)p()}if(m.height>C)m.region(w,{x:0,y:C,width:m.width,height:m.height-C})}return Fe(m,{colorMode:r,theme:i,trimEnd:true})}function fM(t,e){const r=(i,n=1)=>{const o=t.min===t.max?0:(i-t.min)/(t.max-t.min);return Math.round(Math.max(0,Math.min(1,o))*e*n)/n};return{position:r,ticks(i){const n=new Map;for(const o of[t.min,t.max,...i]){const s=r(o);if(!n.has(s))n.set(s,o)}return[...n.entries()].sort(([o],[s])=>o-s).map(([,o])=>o)},interval(i,n,o){const s=Math.round(r(i,o)*o);const a=Math.round(r(n,o)*o);const l=[];for(let c=Math.min(s,a);c<Math.max(s,a);c++){const d=Math.floor(c/o);const u=o===1?3:1<<c%2;const h=l[l.length-1];if(h?.index===d)h.coverage|=u;else l.push({index:d,coverage:u})}return l}}}var pM=60;var gp=20;var LR={ascii:false,hLine:"\u2500",bar:"\u2588",grid:"\xB7"};var RR={ascii:true,hLine:"-",bar:"#",grid:"."};function gM(){const t=new Map;const e=new Map;return{reserve(r,i,n,o,s){t.set(s.id,{x:r,y:i,text:n,color:o,owner:s});for(const[a,l]of n.lines.entries()){const c=e.get(i+a)??new Set;e.set(i+a,c);for(const d of l)for(let u=0;u<d.width;u++)c.add(r+d.x+u)}},has(r,i){return e.get(i)?.has(r)??false},paint(r,i){const n=t.get(i);if(n)r.textBlock(n.x,n.y,n.text,{role:"text",color:n.color,owner:n.owner,textGroup:n.owner.id})}}}function yM(t,e,r){if(r&&r.length>0){return Array.from({length:t},(i,n)=>r[n%r.length])}return Sc(Math.max(1,t),{accent:e.accent??pC,bg:e.bg})}function xM(t,e,r,i,n={},o,s){const a=t.split("\n").map(g=>g.trim()).filter(g=>g.length>0&&!g.startsWith("%%"));const l=na(a);const c=s?Vb(l,s.config,s.theme):jb(l,n);c.title??=e.title;const d=e.useAscii?RR:LR;const u=o??e.maxWidth;const h=xc(c)===0?xp(c,d,[],Math.max(1,u??ne(c.title??"")),!!c.title&&c.config.showTitle!==false,false):c.horizontal?PR(c,d,i,u,o):NR(c,d,i,u);const m=c.horizontal?c.xAxis:c.yAxis;const f=c.horizontal?c.config.xAxis:c.config.yAxis;const p=c.horizontal?"x-axis":"y-axis";if(m.title&&f?.showTitle!==false){const g=`${p}: `;const y=ve(m.title,u===void 0?void 0:Math.max(1,u-ne(g)));y.forEach((C,w)=>h.line([{text:w===0?g:" ".repeat(ne(g)),role:"border",kind:w===0?"text":"surface",owner:{id:`${p}:prefix`,kind:"label",parent:{id:p,kind:"label"}}},{text:C,role:"text",textGroup:p,owner:{id:p,kind:"label"}}]))}c.series.forEach((g,y)=>{g.pointLabels?.forEach((C,w)=>{if(C===void 0)return;const x=`line ${y+1}.${w+1}: ${C}`;for(const k of ve(x,u))h.line([{text:k,role:"text",textGroup:"point-label",owner:{id:`series-${y}:point-${w}:label`,kind:"label",parent:{id:`series-${y}`,kind:"node"}}}])})});DR(h,c);h.titleHandled=true;return Fe(h,{colorMode:r,theme:i,trimEnd:true})}function DR(t,e){const r=(s,a,l)=>t.report({code:"TERMINAL_FAMILY_PROJECTION",feature:s,message:`${s}=${JSON.stringify(a)} is represented by ${l}; source configuration is retained.`});const i=!!e.title&&e.config.showTitle!==false;const n=e.config.showLegend!==false&&Tc(e.series);const o=e.config.showDataLabel&&e.series.some(s=>s.type==="bar");for(const s of["width","height","useWidth","plotReservedSpacePercent"]){if(e.config[s]!==void 0)r(`xyChart.${s}`,e.config[s],"measured terminal plot cells and the terminal targetWidth/maxWidth policy rather than a pixel chart box")}if(e.config.useMaxWidth===true)t.report({code:"TERMINAL_RENDER_OPTION_NOT_APPLICABLE",feature:"xyChart.useMaxWidth",message:"xyChart.useMaxWidth=true controls responsive SVG sizing; terminal output uses measured cell width and the terminal width policy."});if(i){for(const s of["titleFontSize","titlePadding"]){if(e.config[s]!==void 0)r(`xyChart.${s}`,e.config[s],"the terminal font cell size and wrapped title rows")}}if(n){for(const s of["legendFontSize","legendPadding"]){if(e.config[s]!==void 0)r(`xyChart.${s}`,e.config[s],"single-cell series markers and complete wrapped legend labels")}}for(const s of["xAxis","yAxis"]){const a=e.config[s];if(!a)continue;for(const[l,c]of[[a.showLabel!==false,["labelFontSize","labelPadding"]],[!!e[s].title&&a.showTitle!==false,["titleFontSize","titlePadding"]],[a.showTick!==false,["tickLength","tickWidth"]],[a.showAxisLine!==false,["axisLineWidth"]]]){if(!l)continue;for(const d of c)if(a[d]!==void 0){r(`xyChart.${s}.${d}`,a[d],"single-cell axis/tick glyphs and complete wrapped labels rather than pixel font, padding or stroke dimensions")}}}if(o&&e.config.showDataLabelOutsideBar!==true){r("xyChart.showDataLabelOutsideBar",false,"numeric labels beside bar endpoints; inside-bar text placement is unavailable")}for(const[s,a]of Object.entries(e.theme)){if(a===void 0||s==="plotColorPalette")continue;if(s==="titleColor"&&!i||s==="legendTextColor"&&!n||s==="dataLabelColor"&&!o)continue;const l=/^([xy])Axis(Label|Tick|Line|Title)Color$/.exec(s);if(l){const c=l[1]==="x"?"xAxis":"yAxis",d=e.config[c];const u=l[2]==="Label"?d?.showLabel!==false:l[2]==="Tick"?d?.showTick!==false:l[2]==="Line"?d?.showAxisLine!==false:!!e[c].title&&d?.showTitle!==false;if(!u)continue}r(s==="themeCss"?"themeCSS":`themeVariables.xyChart.${s}`,a,"the shared terminal theme palette; SVG background, per-axis paints and CSS are not applied")}}function NR(t,e,r,i){const n=xc(t);if(n===0)return new Re;const o=t.yAxis.range;const s=yp(o,gp,e.ascii).ticks(Mh(o.min,o.max,6));const a=s.map(G=>Bi(G));const l=t.config.yAxis?.showLabel!==false;const c=t.config.xAxis?.showLabel!==false;const d=l?Math.max(...a.map(ne))+1:0;const u=t.series.flatMap((G,se)=>G.type==="bar"?[{data:G.data,globalIdx:se,labels:t.config.showDataLabel?G.data.map(ce=>mt(Bi(ce))):[]}]:[]);const h=u.reduce((G,se)=>se.labels.reduce((ce,ae)=>Math.max(ce,ae.width),G),0);const m=Math.max(pM,n*6);const f=i===void 0?m:i-d-3;const p=u.length;const g=Math.max(2,p*Math.max(1,h)+Math.max(0,p-1)+2);const y=Math.max(n*g,Math.min(m,f));const C=gp;const w=Math.floor(y/n);const x=Eh(t,n);const k=!!t.title&&t.config.showTitle!==false;const b=!!t.xAxis.title&&t.config.xAxis?.showTitle!==false;const A=t.config.showLegend!==false&&Tc(t.series);const L=d+1;const B=L+w*n+2;const O=yM(t.series.length,r,t.theme.plotColorPalette);const M=xp(t,e,O,B,k,A);const E=M.height;const _=x.map(G=>ve(G,Math.max(1,w-1)));const q=c?Math.max(1,..._.map(G=>G.length)):0;const Q=b?ve(t.xAxis.title,B):[];const $=E+C;const D=$+1;const P=D+q;const U=$+1+q+Q.length;const j=new Re(B,U);j.region({id:"plot",kind:"plot"},{x:L,y:E,width:w*n,height:C+1});return j.scope({id:"plot",kind:"plot"},()=>{j.overlay(M);const G=yp(o,C,e.ascii);const se=G.position;const ce=X=>L+Math.floor(w*(X+.5));const ae=Math.max(1,Math.min(Math.floor((Math.max(1,w-2)-Math.max(0,p-1))/Math.max(1,p)),8));const Y=Math.max(ae,h);const V=Y*p+Math.max(0,p-1);const N=(X,ie)=>ce(X)-Math.floor(V/2)+ie*(Y+1)+Math.floor((Y-ae)/2);for(let X=0;t.config.yAxis?.showAxisLine!==false&&X<=C;X++){const ie=E+C-X;Kr(j,ie,L-1,5,e,"border")}if(t.config.xAxis?.showAxisLine!==false||t.config.yAxis?.showAxisLine!==false)Kr(j,$,L-1,15,e,"border");for(const X of s){const ie=se(X);if(ie<0||ie>C)continue;const ge=E+C-ie;const fe=Bi(X);if(t.config.yAxis?.showTick!==false)Kr(j,ge,L-1,ie===0?15:13,e,"border");if(l){const de=d-ne(fe);xs(j,ge,Math.max(0,de),fe,"text",{id:`y-tick-${X}`,kind:"label"})}}for(let X=L;t.config.xAxis?.showAxisLine!==false&&X<L+w*n;X++){Kr(j,$,X,10,e,"border")}for(let X=0;X<n;X++){const ie=ce(X);if(t.config.xAxis?.showTick!==false)Kr(j,$,ie,14,e,"border");if(c&&D>=0){_[X].forEach((ge,fe)=>{const de=ie-Math.floor(ne(ge)/2);xs(j,D+fe,Math.max(0,de),ge,"text",{id:`x-category-${X}`,kind:"node"})})}}Q.forEach((X,ie)=>{xs(j,P+ie,Math.max(0,Math.floor((B-ne(X))/2)),X,"text",{id:"x-axis",kind:"label"})});const J=gM();if(t.config.showDataLabel)for(const[X,ie]of u.entries()){const ge=G.edge(Wn(o));for(const[fe,de]of ie.data.entries()){const xe=ie.labels[fe],we=G.edge(de);const Be=E+C-Math.ceil(Math.max(ge,we));const Ie=E+C-Math.floor(Math.min(ge,we));const Me=de>=0?Math.max(E,Be-1):Math.min($-1,Ie+1);const Ae=Math.max(L,N(fe,X)+Math.floor(ae/2)-Math.floor(xe.width/2));J.reserve(Ae,Me,xe,O[ie.globalIdx],{id:`series-${ie.globalIdx}:value-${fe}`,kind:"label",parent:{id:`series-${ie.globalIdx}`,kind:"node"}})}}for(const X of s){const ie=se(X);if(ie<0||ie>C)continue;const ge=E+C-ie;for(let fe=L;fe<L+w*n;fe++){if(!J.has(fe,ge)&&CM(j,ge,fe)===" "){bM(j,ge,fe,e.grid,"line")}}}if(u.length>0){const X=Wn(o);for(let ie=0;ie<u.length;ie++){const ge=u[ie];const fe=O[ge.globalIdx];for(let de=0;de<ge.data.length;de++){const xe=N(de,ie);const we=ge.data[de];j.scope({id:`series-${ge.globalIdx}`,kind:"node"},()=>{for(const{cell:Be,coverage:Ie}of G.coverage(X,we)){const Me=E+C-1-Be;for(let Ae=xe;Ae<xe+ae;Ae++)j.numericMark(Ae,Me,{axis:"vertical",coverage:Ie,ascii:e.ascii},{role:"arrow",color:fe})}});if(t.config.showDataLabel)J.paint(j,`series-${ge.globalIdx}:value-${de}`)}}}const ee=[];for(let X=0;X<t.series.length;X++){if(t.series[X].type==="line")ee.push({data:t.series[X].data,globalIdx:X})}for(let X=0;X<ee.length;X++){const ie=ee[X];if(ie.data.length===0)continue;const ge=O[ie.globalIdx];j.scope({id:`series-${ie.globalIdx}`,kind:"node"},()=>{FR(j,ie.data,ce,se,E,C,L,w*n,e,ge,J.has)})}return j})}function PR(t,e,r,i,n){const o=xc(t);if(o===0)return new Re;const s=t.yAxis.range;const a=Eh(t,o);const l=t.config.xAxis?.showLabel!==false;const c=t.config.yAxis?.showLabel!==false;const d=i===void 0?void 0:Math.max(1,Math.floor(i/3));const u=a.map(U=>ve(U,d));const h=l?Math.max(...u.flat().map(ne))+1:0;const m=!!t.title&&t.config.showTitle!==false;const f=!!t.yAxis.title&&t.config.yAxis?.showTitle!==false;const p=h+1;const g=t.config.showDataLabel?12:2;const y=[s.min,s.max].reduce((U,j)=>U+ne(Bi(j)),1);const C=Math.max(1,c?y-p-g:1);const w=p+C;if(n!==void 0&&w>n){const U=[...m?[t.title]:[],...f?[t.yAxis.title]:[],...l?a:[]].filter(G=>G!==void 0);const j=U.some(G=>ri(G).some(se=>ne(se)>n));throw new Pt(n,w,"xychart",j?"UNBREAKABLE_GRAPHEME":"MINIMUM_GEOMETRY")}const x=Math.max(pM,40);const k=i===void 0?x:i-h-2-g;const b=Math.max(C,Math.min(x,k));const A=t.series.filter(U=>U.type==="bar").length;const L=Math.max(2,A*2,...u.map(U=>U.length),Math.floor(gp/o));const B=L*o;const O=t.config.showLegend!==false&&Tc(t.series);const M=p+b+g;const E=yM(t.series.length,r,t.theme.plotColorPalette);const _=xp(t,e,E,M,m,O);const q=_.height;const Q=f?ve(t.yAxis.title,M):[];const $=q+B+1+(c?1:0)+Q.length;const D=q+B;const P=new Re(M,$);P.region({id:"plot",kind:"plot"},{x:p,y:q,width:b,height:B});return P.scope({id:"plot",kind:"plot"},()=>{P.overlay(_);const U=yp(s,b,e.ascii);const j=U.ticks(Mh(s.min,s.max,6));const G=ee=>p+U.position(ee);const se=ee=>q+Math.floor(L*(ee+.5));for(let ee=q;t.config.xAxis?.showAxisLine!==false&&ee<q+B;ee++){Kr(P,ee,p-1,5,e,"border")}if(t.config.xAxis?.showAxisLine!==false||t.config.yAxis?.showAxisLine!==false)Kr(P,D,p-1,15,e,"border");for(let ee=0;ee<o;ee++){const X=se(ee);if(l)u[ee].forEach((ie,ge)=>{const fe=h-ne(ie);const de=X-Math.floor((u[ee].length-1)/2);xs(P,de+ge,Math.max(0,fe),ie,"text",{id:`x-category-${ee}`,kind:"node"})})}for(let ee=p;t.config.yAxis?.showAxisLine!==false&&ee<p+b;ee++){Kr(P,D,ee,10,e,"border")}const ce=new Map;for(const ee of[s.min,s.max,...j]){if(ce.has(ee))continue;const X=ne(Bi(ee));const ie=Math.max(0,Math.min(M-X,G(ee)-Math.floor(X/2)));if([...ce].every(([ge,fe])=>ie>fe+ne(Bi(ge))||ie+X<fe))ce.set(ee,ie)}for(const ee of j){const X=G(ee);if(X<p||X>p+b)continue;if(t.config.yAxis?.showTick!==false)Kr(P,D,X,14,e,"border");if(c&&ce.has(ee)){const ie=Bi(ee);xs(P,D+1,ce.get(ee),ie,"text",{id:`y-tick-${ee}`,kind:"label"})}}Q.forEach((ee,X)=>{xs(P,$-Q.length+X,Math.max(0,Math.floor((M-ne(ee))/2)),ee,"text",{id:"y-axis",kind:"label"})});const ae=t.series.flatMap((ee,X)=>ee.type==="bar"?[{data:ee.data,globalIdx:X,labels:t.config.showDataLabel?ee.data.map(ie=>mt(Bi(ie))):[]}]:[]);const Y=1;const V=Y*ae.length+(ae.length-1);const N=gM();if(t.config.showDataLabel)for(const[ee,X]of ae.entries()){const ie=p+U.edge(Wn(s));for(const[ge,fe]of X.data.entries()){const de=X.labels[ge],xe=p+U.edge(fe);const we=fe>=0?Math.min(M-de.width,Math.ceil(Math.max(ie,xe))+2):Math.max(p,Math.floor(Math.min(ie,xe))-de.width-1);const Be=se(ge)-Math.floor(V/2)+ee*(Y+1);N.reserve(we,Be,de,E[X.globalIdx],{id:`series-${X.globalIdx}:value-${ge}`,kind:"label",parent:{id:`series-${X.globalIdx}`,kind:"node"}})}}for(const ee of j){const X=G(ee);if(X<p||X>p+b)continue;for(let ie=q;ie<q+B;ie++){if(!N.has(X,ie)&&CM(P,ie,X)===" "){bM(P,ie,X,e.grid,"line")}}}if(ae.length>0){const ee=Wn(s);for(let X=0;X<ae.length;X++){const ie=ae[X];const ge=E[ie.globalIdx];for(let fe=0;fe<ie.data.length;fe++){const de=se(fe);const xe=de-Math.floor(V/2);const we=xe+X*(Y+1);const Be=ie.data[fe];P.scope({id:`series-${ie.globalIdx}`,kind:"node"},()=>{for(let Ie=we;Ie<we+Y;Ie++){for(const{cell:Me,coverage:Ae}of U.coverage(ee,Be))P.numericMark(p+Me,Ie,{axis:"horizontal",coverage:Ae,ascii:e.ascii},{role:"arrow",color:ge})}});if(t.config.showDataLabel)N.paint(P,`series-${ie.globalIdx}:value-${fe}`)}}}const J=[];for(let ee=0;ee<t.series.length;ee++){if(t.series[ee].type==="line")J.push({data:t.series[ee].data,globalIdx:ee})}for(let ee=0;ee<J.length;ee++){const X=J[ee];if(X.data.length===0)continue;const ie=E[X.globalIdx];P.scope({id:`series-${X.globalIdx}`,kind:"node"},()=>{$R(P,X.data,se,G,q,B,p,b,e,ie,N.has)})}return P})}function FR(t,e,r,i,n,o,s,a,l,c,d){if(e.length===0)return;const u=e.map((m,f)=>({col:r(f),row:i(m)}));const h=(m,f,p)=>{const g=n+o-f;if(g>=0&&m>=s&&m<s+a&&!d?.(m,g)){Kr(t,g,m,p,l,"arrow",c,true)}};if(u.length===1){h(u[0].col,u[0].row,10);return}for(let m=0;m<u.length-1;m++){const f=u[m];const p=u[m+1];if(f.row===p.row){for(let x=f.col;x<=p.col;x++){h(x,f.row,10)}continue}const g=Math.round((f.col+p.col)/2);const y=p.row>f.row;for(let x=f.col;x<g;x++){h(x,f.row,10)}if(y){h(g,f.row,9)}else{h(g,f.row,12)}const C=Math.min(f.row,p.row);const w=Math.max(f.row,p.row);for(let x=C+1;x<w;x++){h(g,x,5)}if(y){h(g,p.row,6)}else{h(g,p.row,3)}for(let x=g+1;x<=p.col;x++){h(x,p.row,10)}if(m===0){const x=Math.max(s,f.col-Math.floor((p.col-f.col)/4));for(let k=x;k<f.col;k++){h(k,f.row,10)}}if(m===u.length-2){const x=Math.min(s+a-1,p.col+Math.floor((p.col-f.col)/4));for(let k=p.col+1;k<=x;k++){h(k,p.row,10)}}}}function $R(t,e,r,i,n,o,s,a,l,c,d){if(e.length===0)return;const u=e.map((m,f)=>({row:r(f),col:i(m)}));const h=(m,f,p)=>{if(m>=n&&m<n+o&&f>=s&&f<=s+a&&!d?.(f,m)){Kr(t,m,f,p,l,"arrow",c,true)}};if(u.length===1){h(u[0].row,u[0].col,5);return}for(let m=0;m<u.length-1;m++){const f=u[m];const p=u[m+1];if(f.col===p.col){for(let x=f.row;x<=p.row;x++){h(x,f.col,5)}continue}const g=Math.round((f.row+p.row)/2);const y=p.col>f.col;for(let x=f.row;x<g;x++){h(x,f.col,5)}if(y){h(g,f.col,3)}else{h(g,f.col,9)}const C=Math.min(f.col,p.col);const w=Math.max(f.col,p.col);for(let x=C+1;x<w;x++){h(g,x,10)}if(y){h(g,p.col,12)}else{h(g,p.col,6)}for(let x=g+1;x<=p.row;x++){h(x,p.col,5)}}}function xp(t,e,r,i,n,o){const s=new Re;if(n){for(const a of ve(t.title,i)){const l=s.height;s.textBlock(Math.max(0,Math.floor((i-ne(a))/2)),l,a,{role:"text",textGroup:"title",owner:{id:"title",kind:"label"}})}}if(o){let a=[];let l=0;const c=()=>{if(a.length>0){s.line([{text:" ".repeat(Math.max(0,Math.floor((i-l)/2))),kind:"surface"},...a]);a=[];l=0}};for(const d of FC(t.series)){const u=d.type==="bar"?e.bar:e.hLine;const h={id:`series-${d.colorIndex}`,kind:"node"};const m=ve(d.label,Math.max(1,i-2));m.forEach((f,p)=>{const g=2+ne(f);if(a.length>0&&(p>0||l+2+g>i))c();if(a.length>0){a.push({text:" ",kind:"surface"});l+=2}a.push({text:u,role:"arrow",kind:"marker",color:r[d.colorIndex],owner:h},{text:" ",kind:"surface"},{text:f,role:"text",textGroup:"legend",owner:h});l+=g})}c()}if(n)s.line();return s}function Kr(t,e,r,i,n,o,s,a=false){if(r>=0&&r<t.width&&e>=0&&e<t.height){t.stroke(r,e,i,{ascii:n.ascii,rounded:a,role:o,...s?{color:s}:{}})}}function bM(t,e,r,i,n){if(r>=0&&r<t.width&&e>=0&&e<t.height)t.put(r,e,i,{role:n,kind:"stroke"})}function CM(t,e,r){return t.get(r,e)}function xs(t,e,r,i,n,o){if(r>=0&&e>=0)t.textBlock(r,e,i,{role:n,owner:o,textGroup:o?.id})}function yp(t,e,r){const i=fM(t,e);return{edge:n=>i.position(n,r?1:2),position:i.position,ticks:i.ticks,coverage(n,o){return i.interval(n,o,r?1:2).map(({index:s,coverage:a})=>({cell:s,coverage:a}))}}}var qR={...rC,renderAscii:dt(t=>fv(t.source.authoredFamilyBody??t.source.familyBody,t.config,t.colorMode,t.theme,t.options.targetWidth))};var zR={...iC,renderAscii:dt(t=>hE(t.source.authoredFamilyBody??t.source.familyBody,t.config,t.colorMode,t.theme))};function GR(t,e=Jd(t.source.originalText,t.source.familyBody)){const r=e.graph();$u(r);const i={...t.config};if(r.direction==="LR"||r.direction==="RL"){i.graphDirection="LR";i.reverseDirection=r.direction==="RL"}else{i.graphDirection="TD"}const n=ls(r,i);fs(n);hs(n);if(r.direction==="BT"){$d(n.canvas)}return Fe(n.canvas,{colorMode:t.colorMode,theme:t.theme})}function WR(t){const e=ai(t.source.familyText);$u(e);const r={...t.config};r.graphDirection=e.direction==="LR"||e.direction==="RL"?"LR":"TD";r.reverseDirection=e.direction==="RL";return dM(e,r,t.colorMode,t.theme,t.options.targetWidth)}function UR(t){return qE(zx(t.source),t.config,t.colorMode,t.theme,{...t.options,graphLayout:t.renderOptions.graphLayout})}var jR={...WC,renderAscii:dt(GR)};var VR={...ZC,renderAscii:dt(WR)};var YR={...qC,renderAscii:dt(UR)};var HR={...QC,renderAscii:dt(t=>{const e=El(t.source,"decoded");return mv(e.familyText,t.config,t.colorMode,t.theme,t.familyConfig?.sequence??{},t.options.targetWidth,Ky(e))})};var XR={...zC,renderAscii:dt(t=>WE(t.source.familyText,t.config,t.colorMode,t.theme,t.options.targetWidth,(t.source.authoredFamilyLines??t.source.familyLines).join("\n")))};var KR={...GC,renderAscii:dt(t=>UE(t.source.familyText,t.config,t.colorMode,t.theme,t.options.targetWidth))};var JR={...ek,renderAscii:dt(t=>mM(t.source.familyLines,t.config,t.colorMode,t.theme,t.options.maxWidth))};var QR={...VC,renderAscii:dt(t=>KE((t.source.authoredFamilyLines??t.source.familyLines).join("\n"),t.config,t.colorMode,t.theme,t.options.maxWidth,t.styleFace))};var ZR={...tk,renderAscii:dt(t=>{const e=t.familyConfig?.config;const r=t.familyAppearance?.theme;return xM(t.source.familyText,t.config,t.colorMode,t.theme,{},t.options.targetWidth,e&&r?{config:e,theme:r}:void 0)})};var eD={...HC,renderAscii:dt(t=>ZE(oc(t.source),t.config,t.colorMode,t.theme,{},t.options.targetWidth,t.familyConfig?.visual,t.styleFace))};var tD={...XC,renderAscii:dt(t=>tM(t.source.familyLines,t.config,t.colorMode,t.theme,t.options.targetWidth))};var rD={...KC,renderAscii:dt(t=>nM(t.source.familyLines,t.config,t.colorMode,t.theme,t.source.frontmatter,t.options.targetWidth,t.styleFace))};var iD={...JC,renderAscii:dt(t=>sM($C(t.source),t.config,t.colorMode,t.theme,t.source.frontmatter,t.options.targetWidth,t.familyConfig?.visual))};var nD={...UC,renderAscii:dt(t=>HE(t.source.familyLines,t.config,t.colorMode,t.theme,void 0,{maxWidth:t.options.maxWidth,today:t.options.ganttToday,resolvedConfig:t.familyConfig?.config,styleFace:t.styleFace}))};var oD={...YC,renderAscii:dt(t=>QE(Gn(t.source.authoredFamilyBody??t.source.familyBody),t.config,t.colorMode,t.theme,t.options.targetWidth))};var sD={...jC,renderAscii:dt(t=>{const e=t.familyConfig;return XE(Ro(t.source.familyBody,{mainBranchName:e?.position?.mainBranchName,mainBranchOrder:e?.position?.mainBranchOrder,title:e?.title}),t.config,t.colorMode,t.theme,t.options.targetWidth,t.familyAppearance?.themeVariables)})};var aD={...vC,renderAscii:dt(t=>{const e=t.familyConfig;return BE(e.model,t.config,t.colorMode,t.theme,t.options.targetWidth,e.c4)})};var lD={...dC,renderAscii:dt(t=>mE(t))};var cD={...uC,renderAscii:dt(t=>fE(t))};var dD={...hC,renderAscii:dt(t=>EE(Br(t.source),t.config,t.colorMode,t.theme,t.source.frontmatter,t.options.targetWidth))};var uD={...gC,renderAscii:dt(t=>ME(t))};var hD={...yC,renderAscii:dt(t=>AE(t))};var mD={...xC,renderAscii:dt(t=>OE(t.source.familyBody,t.config,t.colorMode,t.theme,t.source.frontmatter,t.options.targetWidth))};var kM=Object.freeze({flowchart:jR,state:VR,sequence:HR,timeline:JR,class:XR,er:KR,journey:QR,xychart:ZR,architecture:YR,pie:eD,quadrant:tD,radar:rD,sankey:iD,c4:aD,packet:lD,kanban:cD,requirement:dD,treemap:uD,ishikawa:hD,block:mD,gantt:nD,mindmap:oD,gitgraph:sD,zenuml:qR,eventmodeling:zR});for(const t of wk())kk(t,{...W0[t],...kM[t]});function fD(t){const e=Ii(t.kind);const r=t.body.kind!=="extension"||"descriptorIdentity"in t&&fl(t.descriptorIdentity,e?.identity);const i=r?e?.renderSource:void 0;const n=i?i(t.body):t.body.kind==="extension"?"serialized":"canonical";if(n!=="canonical"&&n!=="serialized")throw new TypeError(`Family ${t.kind} returned an invalid render source policy`);if(n==="serialized")return ao(t);const o=t.canonicalSource;const s=mp(t.meta,"verbatim",o,t.kind);return o.startsWith(s)?o:s+o}function Tr(t){if(typeof t==="string")return{source:t};if(t.body.kind==="preserved"){throw new ju(ux(t.body))}return{source:fD(t),expectedFamilyId:t.kind}}function SM(t){return Object.fromEntries([...Oh,...oC].filter(e=>t[e]!==void 0).map(e=>[e,t[e]]))}function bp(t,e){for(const r of t){e(r);if(r.kind==="group")bp(r.children.map(i=>i.node),e)}}var wM=1;function pD(...t){return t.some(e=>typeof e==="number"&&e>0)}function TM(t,e,r={},i,n={}){const o=[];if(n.controlsReplaced)EM(o);const s=t.appearance;for(const A of s.unsafeThemeColorKeys??[]){o.push({code:"TERMINAL_UNSAFE_COLOR_REJECTED",feature:`mermaid-theme.${A}`,message:`Mermaid theme variable "${A}" was rejected because it is not a safe non-fetching CSS color.`})}for(const A of t.explicitOptionFields){const L=sC[A];if(L.terminal==="consumed")continue;const B=L.terminal==="not-applicable";o.push({code:B?"TERMINAL_RENDER_OPTION_NOT_APPLICABLE":"TERMINAL_RENDER_OPTION_PROJECTED",feature:`render-option:${A}`,message:`Render option "${A}" ${B?"does not apply to":"is projected for"} terminal output: ${L.terminalNote??"the terminal adapter has no pixel-equivalent representation"}.`})}const a=s.face;const l=Object.values(s.style?.roles??{});if(pD(a?.node?.cornerRadius,a?.group?.cornerRadius,a?.edge?.bendRadius,...l.flatMap(A=>[A?.cornerRadius,A?.bendRadius]))){o.push({code:"TERMINAL_RADIUS_PROJECTED",feature:"corner-and-bend-radius",message:"Terminal cells cannot represent continuous corner or connector bend radius; topology is preserved with box/line glyphs."})}const c=[a?.text,a?.node,a?.edge,a?.group];if(s.font!=="Inter"||a?.group?.fontFamily!==void 0||c.some(A=>A?.fontSize!==void 0||A?.fontWeight!==void 0||A?.letterSpacing!==void 0||A?.textTransform!==void 0)||l.some(A=>A?.fontFamily!==void 0||A?.fontSize!==void 0||A?.fontWeight!==void 0||A?.letterSpacing!==void 0||A?.textTransform!==void 0)){o.push({code:"TERMINAL_TYPOGRAPHY_PROJECTED",feature:"typography",message:"Terminal output preserves text, hierarchy and emphasis but projects font family, size, weight and tracking to terminal cells."})}const d=a?.node?.fillColor!==void 0||a?.group?.fillColor!==void 0||a?.group?.headerFillColor!==void 0||l.some(A=>A?.fillColor!==void 0||A?.headerFillColor!==void 0);const u=a?.text?.textColor!==void 0||a?.node?.textColor!==void 0||a?.node?.borderColor!==void 0||a?.edge?.textColor!==void 0||a?.edge?.strokeColor!==void 0||a?.group?.textColor!==void 0||a?.group?.borderColor!==void 0||l.some(A=>A?.textColor!==void 0||A?.borderColor!==void 0||A?.strokeColor!==void 0);if(s.colors.shadow===true||d){o.push({code:"TERMINAL_ELEVATION_PROJECTED",feature:"elevation",message:"Terminal output does not render graphical shadow or layered surface elevation; grouping remains explicit in borders and labels."})}if(s.style?.stroke&&s.style.stroke!=="crisp"){o.push({code:"TERMINAL_STROKE_CHARACTER_PROJECTED",feature:"stroke-character",message:"Jittered/freehand stroke character projects to deterministic terminal line patterns."})}if(s.style?.fill&&s.style.fill!=="none"&&s.style.fill!=="solid"){o.push({code:"TERMINAL_FILL_PROJECTED",feature:"fill-treatment",message:"Graphical fill texture projects to category/status labels and terminal symbols."})}if(d){o.push({code:"TERMINAL_FILL_PROJECTED",feature:"role-surface-fill",message:"Per-role node, group, and header surface fills project to terminal labels, symbols, and borders."})}if(u){o.push({code:"TERMINAL_ROLE_PAINT_PROJECTED",feature:"role-paint",message:"Per-role text, border, and connector paints project through the smaller terminal theme palette."})}if(l.some(A=>A?.cue!==void 0&&A.cue!=="none")){o.push({code:"TERMINAL_ROLE_CUE_PROJECTED",feature:"role-non-color-cue",message:"Per-role non-color cues project to the terminal label, symbol, marker, and line-pattern vocabulary."})}const h={bg:"#ffffff",fg:"#27272a",line:"#71717a",accent:"#52525b",muted:"#71717a",surface:"#ffffff",border:"#a1a1aa"};const m=(A,L,B)=>{const O=Ar(A);const M=O?Ft(O):null;if(M)return Mr(M[0],M[1],M[2]);o.push({code:O?"TERMINAL_COLOR_UNREPRESENTABLE":"TERMINAL_UNSAFE_COLOR_REJECTED",feature:B,message:O?`Color ${B} is safe CSS but cannot be resolved to terminal sRGB; fallback ${L} was used.`:`Color ${B} was rejected because it is not a safe non-fetching CSS color; fallback ${L} was used.`});return L};const f=s.colors;const p={...f,bg:m(f.bg,h.bg,"appearance.bg"),fg:m(f.fg,h.fg,"appearance.fg"),...f.line===void 0?{}:{line:m(f.line,h.line,"appearance.line")},...f.accent===void 0?{}:{accent:m(f.accent,h.accent,"appearance.accent")},...f.muted===void 0?{}:{muted:m(f.muted,h.muted,"appearance.muted")},...f.surface===void 0?{}:{surface:m(f.surface,h.surface,"appearance.surface")},...f.border===void 0?{}:{border:m(f.border,h.border,"appearance.border")}};const g=Ff(p);const y=["fg","border","line","arrow","accent","bg","corner","junction"];for(const A of y){const L=r[A];if(L===void 0)continue;const B=g[A]??h.fg;g[A]=m(L,B,`terminal-theme.${A}`)}const C=Object.freeze(g);const w=MM(i,o,n.connectorProjectionFailed===true);const x=["labels","symbols","markers","line-patterns"];const k={version:wM,colorMode:e,theme:C,diagnostics:o,semanticFallbacks:x,connectorProjection:w};const b=Bh(k);return Object.freeze({...k,diagnostics:Object.freeze(o),get digest(){return b()}})}function vM(t,e,r=false){const i=[...t.diagnostics];const n=MM(e,i,r);const o={version:t.version,colorMode:t.colorMode,theme:t.theme,diagnostics:i,semanticFallbacks:t.semanticFallbacks,connectorProjection:n};const s=Bh(o);return Object.freeze({...o,diagnostics:Object.freeze(i),get digest(){return s()}})}function EM(t){if(t.some(e=>e.code==="TERMINAL_CONTROL_CHARACTERS_REPLACED"))return;t.push({code:"TERMINAL_CONTROL_CHARACTERS_REPLACED",feature:"terminal-text",message:"User-derived C0/C1 terminal control characters were replaced with inert single-cell text before layout and color projection."})}function gD(t){const e=[];bp(t,r=>{if(r.kind==="connector"&&!(r.role==="chrome"&&r.owner&&r.owner.id!==r.identity?.id))e.push(r)});return e}function MM(t,e,r=false){const i=t?gD(t.parts):[];const n={line:0,polyline:0,path:0};const o={};const s=new Set;const a=new Set;const l={start:0,mid:0,end:0};let c=0;const d=[];const u=new Map;let h=false;const m=(p,g=false)=>{const y=g?sg(p):$t(p);if(y!==p)h=true;return y};for(const p of i){const g=p.terminalProjection;const y=Object.freeze({...g,id:p.id,role:p.role,labels:Object.freeze(g.labels.map(x=>{const k=Ye(x.text,x.textContent);const b=typeof k==="string"?k:Ge(k);const A=m(b,true);const{textContent:L,block:B,...O}=x;return Object.freeze({...O,text:A,...typeof k!=="string"&&L?{textContent:Object.freeze({...L,value:A,...L.authored===void 0?{}:{authored:m(L.authored,true)},prepared:Object.freeze({...k,source:m(k.source,true),lineStarts:Object.freeze([...k.lineStarts]),lines:Object.freeze(k.lines.map(M=>Object.freeze(M.map(E=>Object.freeze({...E,text:m(E.text),...E.clusters?{clusters:Object.freeze(E.clusters.map(_=>Object.freeze({..._,text:m(_.text)})))}:{}})))))})})}:{}})})),diagnostics:Object.freeze(g.diagnostics.map(x=>m(x)))});d.push(y);n[g.topology]++;o[g.realization]=(o[g.realization]??0)+1;s.add(p.relationship.kind);a.add(p.relationship.direction);l.start+=g.markerPlacements.start.length;l.mid+=g.markerPlacements.mid.length;l.end+=g.markerPlacements.end.length;c+=g.labels.length;const C=`${g.realization}:${g.topology}`;const w=u.get(C);if(w)w.count++;else u.set(C,{realization:g.realization,topology:g.topology,count:1});for(const x of g.diagnostics){e.push({code:"TERMINAL_CONNECTOR_DECLARED_LIMITATION",feature:`connector:${m(p.id??p.relationship.kind)}`,message:m(x)})}}if(h)EM(e);if(t===null){e.push({code:"TERMINAL_CONNECTOR_PROJECTION_UNAVAILABLE",feature:"connectors",message:r?"Optional Scene connector projection failed; native terminal rendering continued independently.":"The family renders terminal output but exposes no Scene connector projection evidence."})}for(const p of[...u.values()].sort((g,y)=>qt(`${g.realization}:${g.topology}`,`${y.realization}:${y.topology}`))){if(p.realization==="native")continue;const g=p.realization==="unsupported";e.push({code:g?"TERMINAL_CONNECTOR_UNSUPPORTED":"TERMINAL_CONNECTOR_PROJECTED",feature:`connectors:${p.topology}`,message:`${p.count} ${p.topology} connector${p.count===1?"":"s"} declare ${p.realization} terminal realization; their typed semantics are supplied to the terminal adapter and receipt.`})}const f={evidence:t===void 0?"not-evaluated":t===null?"unavailable":"scene",count:i.length,topologies:Object.freeze(n),realizations:Object.freeze(o),relationships:Object.freeze([...s].sort()),directions:Object.freeze([...a].sort()),markerPositions:Object.freeze(l),labelCount:c,connectors:Object.freeze(d),capabilities:Fu()};return Object.freeze({...f,digest:Un(f)})}var OM=5;var BM=1;var _M=5;var IM=1;var LM=Object.freeze(["none","ansi16","ansi256","truecolor","html"]);var Zd=Object.freeze(["auto",...LM]);var yD=new Set(Zd);var eu=Object.freeze(["fg","border","line","arrow","accent","bg","corner","junction"]);var xD=new Set(eu);var bD=new Set(Object.keys({useAscii:true,paddingX:true,paddingY:true,boxBorderPadding:true,colorMode:true,theme:true,maxWidth:true,targetWidth:true}));function CD(){const t=`{ ${eu.map(e=>`${e}?: string`).join("; ")} }`;return{useAscii:{typeScript:"boolean",schema:{type:"boolean"}},paddingX:{typeScript:"number",schema:{type:"integer",minimum:0}},paddingY:{typeScript:"number",schema:{type:"integer",minimum:0}},boxBorderPadding:{typeScript:"number",schema:{type:"integer",minimum:0}},colorMode:{typeScript:Zd.map(e=>`'${e}'`).join(" | "),resolvedTypeScript:LM.map(e=>`'${e}'`).join(" | "),schema:{type:"string",enum:Zd}},theme:{typeScript:t,resolvedTypeScript:`Readonly<${t}>`,schema:{type:"object",additionalProperties:false,properties:Object.fromEntries(eu.map(e=>[e,{type:"string"}]))}},maxWidth:{typeScript:"number",optionalInPolicy:true,schema:{type:"integer",minimum:1}},targetWidth:{typeScript:"number",optionalInPolicy:true,schema:{type:"integer",minimum:1}}}}function kD(t={}){return Object.entries(CD()).map(([e,r])=>{const i=!t.resolved||r.optionalInPolicy?"?":"";const n=t.resolved?r.resolvedTypeScript??r.typeScript:r.typeScript;return` ${e}${i}: ${n}`}).join("\n")}function xX(){return`interface ResolvedTerminalOutputPolicy {
196
+ version: ${sa}
197
+ ${kD({resolved:true})}
198
+ }`}var or=class extends TypeError{constructor(r,i){super(i);this.code=r;this.name="TerminalOutputPolicyError"}code};function SD(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function Xi(t,e){const r=t[e];if(SD(t,e)&&r===null){throw new or("INVALID_FIELD",`terminal ${e} must be omitted instead of null`)}return r}function Cp(t,e,r){if(t===void 0)return r;if(typeof t!=="number"||!Number.isFinite(t)||!Number.isInteger(t)||t<0){throw new or("INVALID_FIELD",`terminal ${e} must be a non-negative finite integer`)}return t}function AM(t,e){if(t===void 0)return void 0;if(typeof t!=="number"||!Number.isFinite(t)||!Number.isInteger(t)||t<=0){throw new or("INVALID_FIELD",`terminal ${e} must be a positive finite integer`)}return t}function wD(t){if(t===void 0)return Object.freeze({});if(!wt(t)){throw new or("INVALID_FIELD","terminal theme must be a plain object")}const e=Reflect.ownKeys(t).filter(i=>typeof i!=="string"||!xD.has(i));if(e.length>0){throw new or("INVALID_FIELD",`terminal theme has unknown field "${String(e[0])}"`)}const r={};for(const i of eu){const n=Xi(t,i);if(n===void 0)continue;if(typeof n!=="string"){throw new or("INVALID_FIELD",`terminal theme.${i} must be a string`)}r[i]=n}return Object.freeze(r)}function kp(t={}){if(!wt(t)){throw new or("INVALID_INPUT","terminal output policy must be a plain object")}const e=Reflect.ownKeys(t).filter(d=>typeof d!=="string"||!bD.has(d));if(e.length>0){throw new or("INVALID_FIELD",`terminal output policy has unknown field "${String(e[0])}"`)}const r=Xi(t,"useAscii");if(r!==void 0&&typeof r!=="boolean"){throw new or("INVALID_FIELD","terminal useAscii must be a boolean")}const i=Xi(t,"colorMode");if(i!==void 0&&(typeof i!=="string"||!yD.has(i))){throw new or("INVALID_FIELD",`terminal colorMode must be one of ${Zd.join(", ")}`)}const n=i;const o=AM(Xi(t,"maxWidth"),"maxWidth");const s=AM(Xi(t,"targetWidth"),"targetWidth");if(o!==void 0&&s!==void 0){throw new or("WIDTH_CONFLICT","terminal maxWidth and targetWidth are mutually exclusive")}const a=r??false;const l=n===void 0||n==="auto"?$f():n;const c={version:sa,useAscii:a,paddingX:Cp(Xi(t,"paddingX"),"paddingX",s===void 0?OM:BM),paddingY:Cp(Xi(t,"paddingY"),"paddingY",_M),boxBorderPadding:Cp(Xi(t,"boxBorderPadding"),"boxBorderPadding",IM),colorMode:l,theme:wD(Xi(t,"theme")),...o===void 0?{}:{maxWidth:o},...s===void 0?{}:{targetWidth:s}};return Object.freeze(c)}var TD=Object.freeze(["Checks cover the retained terminal cell projection and its emitted encoding, not pixel geometry, font ink or terminal emulator behavior.","Identity and membership checks use native declarations; they do not establish complete correspondence with every authored family model.","Declared route bundles, perpendicular crossings and numeric marks may share cells; composition diagnostics distinguish rejected content from those intentional overlaps.","Directional owned-ink connectivity is checked only for explicitly connected native routes; other families retain endpoint and marker checks without a complete route proof.","A passing cell contract does not certify aesthetic spacing, contrast or the legibility of a particular display."]);var RM=new WeakMap;var ut=t=>{let e=RM.get(t);if(e===void 0){e=JSON.stringify([t.kind??"node",t.id]);RM.set(t,e)}return e};var kn=(t,e)=>`${t},${e}`;function Sp(t,e,r,i,n){n();if(!Number.isSafeInteger(r)||!Number.isSafeInteger(i)||r<0||i<0)return 0;const o=t.cell(r,i);if(!o||!o.glyph.trim()||o.width!==1)return 0;let s=false,a=0;for(let l=0;l<o.owners.length;l++){n();if(ut(o.owners[l])===ut(e)){s=true;a=Fd(o,l)}}if(!s)return 0;return o.kind==="stroke"?a:o.kind==="marker"?o.marker?.direction==="L"||o.marker?.direction==="R"?10:o.marker?.direction==="T"||o.marker?.direction==="B"?5:0:0}function DM(t,e,r,i=Wt){for(const C of["maxOperations","maxOutputCodeUnits","maxIssues"])if(!Number.isSafeInteger(i[C])||i[C]<0||i[C]>Wt[C])throw new RangeError(`Terminal certification ${C} must be within its bounded default.`);const n={cells:0,graphemes:0,ownedCells:0,unownedCells:0,textAllocations:0,textClusters:0,identities:0,ports:0,markerContracts:0};const o=[];const s=[];const a=new Set;let l=0,c=false,d=false,u=false,h="passed";const m=(C,w,x,k,b,A)=>{if(w==="failed"||h==="passed")h=w;const L=JSON.stringify([C,k??null]);if(a.has(L))return;a.add(L);if(o.length>=i.maxIssues){d=true;return}o.push(Object.freeze({code:C,status:w,message:x,...k===void 0?{}:{elementId:k},...b===void 0||A===void 0?{}:{cell:Object.freeze({column:b,row:A})}}))};const f=Symbol("terminal certification budget");const p=()=>{if(l>=i.maxOperations){c=true;throw f}l++};let g;if(e.length>i.maxOutputCodeUnits){c=true;m("TERMINAL_CERTIFICATION_LIMIT","unverified","The final encoded output exceeds the bounded certification scan.")}else g=Un(e);let y;if(!t)m("TERMINAL_DOCUMENT_UNAVAILABLE","unverified","This renderer returned text without a retained native cell document.");else if(!c)try{if(t.hasTerminalPathWitnessState?.())p();const C=t.layoutEvidence();y=Object.freeze({width:C.width,height:C.height});const w=C.emittedWidths;if(!w||C.emittedText===void 0||C.colorMode===void 0){m("TERMINAL_EMISSION_UNAVAILABLE","unverified","The native document has no current final serialization evidence.")}else{const O=C.colorMode==="html"?Na(C.emittedText):C.emittedText;if(C.colorMode!==r||O!==e)m("TERMINAL_OUTPUT_MISMATCH","failed","The returned bytes do not match this native document's final encoding.");const M=Od(e,r);const E=w.length===0&&M===""?[]:M.split("\n");if(E.length!==w.length)m("TERMINAL_OUTPUT_ROWS","failed","The emitted row count differs from the native cell projection.");for(let _=0;_<w.length;_++){p();const q=w[_];if(!Number.isSafeInteger(q)||q<0||q>C.width){m("TERMINAL_OUTPUT_EXTENT","failed","An emitted row has invalid cell bounds.",void 0,0,_);continue}let Q="";for(let $=0;$<q;$++){p();const D=t.cell($,_)?.glyph??" ";if(D!==ir)Q+=D}if(E[_]!==Q)m("TERMINAL_OUTPUT_CELLS","failed","The emitted text differs from the retained final cells.",void 0,0,_)}}const x=new Map,k=new Map;for(const O of C.owners){p();n.identities++;x.set(ut(O),O);const M=k.get(O.id)??[];M.push(O);k.set(O.id,M)}for(const O of x.values()){p();if(O.parent){const E=x.get(ut(O.parent));if(!E)m("TERMINAL_PARENT_UNAVAILABLE","unverified","A native parent reference has no retained identity declaration.",O.id);else if(E.members&&!E.members.some(_=>{p();return _===O.id}))m("TERMINAL_MEMBERSHIP_MISMATCH","failed","The declared native parent does not include its child in its explicit membership.",O.id)}if(O.annotationTarget){p();if(!x.has(ut(O.annotationTarget)))m("TERMINAL_ANNOTATION_TARGET_UNAVAILABLE","unverified","A native annotation target reference has no retained identity declaration.",O.id)}const M=new Set;for(const E of O.members??[]){p();if(M.has(E))m("TERMINAL_MEMBERSHIP_DUPLICATE","failed",`Native member ${E} is declared more than once.`,O.id);M.add(E);const _=k.get(E);if(!_?.length)m("TERMINAL_MEMBER_UNAVAILABLE","unverified",`Native member ${E} has no retained identity declaration.`,O.id);else if(_.every(q=>{p();return q.parent&&ut(q.parent)!==ut(O)}))m("TERMINAL_MEMBERSHIP_MISMATCH","failed",`Native member ${E} declares a different parent.`,O.id)}for(const E of[O.from,O.to])if(E!==void 0){p();if(!k.has(E))m("TERMINAL_ENDPOINT_UNAVAILABLE","unverified",`Native endpoint ${E} has no retained identity declaration.`,O.id)}}const b=new Map;for(const[O,M]of C.declarations){p();b.set(ut(O),M)}let A;for(let O=0;O<C.pathWitnessWork+C.strokeProvenanceWork;O++)p();if(C.pathWitnesses){p();A=new Map;for(const O of C.pathWitnesses){p();if(!O)continue;const M=Ld(O.token),E=x.get(ut(O.owner));if(!M||!E||E.route!=="connected"||E.id!==M.owner.id||E.from!==M.owner.from||E.to!==M.owner.to)continue;p();const{dx:_,dy:q}=O;if(!Number.isSafeInteger(_)||!Number.isSafeInteger(q)||!Number.isSafeInteger(_+M.width)||!Number.isSafeInteger(q+M.height)||_<0||q<0)continue;const Q=ut(E);if(A.has(Q)){A.set(Q,null);continue}p();p();A.set(Q,{admission:M,dx:_,dy:q,valid:true,starts:0,ends:0})}if(A.size){for(let O=0;O<9;O++)p();for(const[O,M]of t.layoutEvidence().ports){p();const E=A.get(ut(O));if(!E)continue;const _=M.end==="start"?E.admission.route.source:E.admission.route.target;if(M.end!==_.end||M.nodeId!==_.nodeId||M.side!==_.side||M.x!==_.x+E.dx||M.y!==_.y+E.dy||M.markerProjection||M.boundary?.id!==_.boundary?.id||M.boundary?.kind!==_.boundary?.kind)E.valid=false;if(M.end==="start"){E.starts++;E.start=M}else{E.ends++;E.end=M}}}}const L=new Map;for(const O of x.values()){p();if(O.route==="connected"){const M=A?.get(ut(O)),E=M?.valid&&M.starts===1&&M.ends===1?M:void 0;if(E){p();p();p()}L.set(ut(O),E?{owner:O,ports:[],witness:E}:{owner:O,ports:[],cells:new Map})}}const B=new Set;for(const O of C.textAllocations){p();n.textAllocations++;const{text:M}=O;for(const[E,_]of M.lines.entries())for(const q of _){p();n.textClusters++;const Q=O.x+q.x,$=O.y+E,D=t.cell(Q,$);B.add(kn(Q,$));if(w&&($>=w.length||Q+q.width>w[$]))m("TERMINAL_TEXT_OMITTED","failed","Retained measured text falls outside the emitted cell extent.",O.owners[0]?.id,Q,$);else if(!D||D.kind!=="text"||D.glyph!==q.glyph||D.width!==q.width||D.head!==Q)m("TERMINAL_TEXT_CHANGED","failed","Retained measured text does not survive in the final cells.",O.owners[0]?.id,Q,$);else{const P=U=>{for(const j of U){p();if(!D.owners.some(G=>{p();return ut(G)===ut(j)}))m("TERMINAL_TEXT_OWNER_CHANGED","failed","Measured text lost its native owner.",j.id,Q,$)}};P(O.owners);for(const U of O.attributions??[]){p();const{bounds:j}=U;if(Q>=j.x&&Q+q.width<=j.x+j.width&&$>=j.y&&$<j.y+j.height)P(U.owners)}}}for(const E of M.emptyRows){p();if(w&&O.y+E>=w.length)m("TERMINAL_EMPTY_TEXT_ROW_OMITTED","unverified","An authored empty text row is not distinguishable in the emitted extent.",O.owners[0]?.id)}}for(const[O,M,E]of t.entries()){p();n.cells++;const _=E.kind==="text"||E.glyph.trim().length!==0;if(_&&w&&(M>=w.length||O>=w[M]))m("TERMINAL_CELL_OMITTED","failed","Visible native content lies outside the emitted cell extent.",E.owners[0]?.id,O,M);if(E.owners.length)n.ownedCells++;else if(_){n.unownedCells++;m("TERMINAL_CELL_OWNER_UNAVAILABLE","unverified","A visible cell has no native semantic ownership.",void 0,O,M)}const q=E.kind==="stroke"&&(E.stroke?.mask??Pd(E))!==0;let Q=0;for(let D=0;D<E.owners.length;D++){const P=E.owners[D];p();const U=E.kind==="stroke"?Fd(E,D):0;if(E.kind==="stroke"){Q|=U;if(!Number.isInteger(U)||U<0||U>15||q&&P.kind==="edge"&&!U)m("TERMINAL_STROKE_PROVENANCE_CHANGED","failed","A visible route stroke lacks its original owner directions.",P.id,O,M);if(q&&P.kind==="edge")for(let G=0;G<D;G++){p();const se=E.owners[G];if(se.kind!=="edge"||P.bundle&&P.bundle===se.bundle)continue;const ce=Fd(E,G);if(!(U===10&&ce===5||U===5&&ce===10))m("TERMINAL_ROUTE_OVERLAP","failed","Unbundled routes share directions or turn at an occupied route cell.",P.id,O,M)}}const j=L.get(ut(P));if(j?.cells&&E.glyph.trim()&&E.width===1){const G=E.kind==="stroke"?U:E.kind==="marker"?E.marker?.direction==="L"||E.marker?.direction==="R"?10:E.marker?.direction==="T"||E.marker?.direction==="B"?5:void 0:void 0;if(G)j.cells.set(kn(O,M),G)}if(!x.has(ut(P)))m("TERMINAL_CELL_OWNER_UNKNOWN","failed","A final cell names an undeclared identity.",P.id,O,M);if(P.parent&&(["group","cluster","subgraph"].includes(P.parent.kind)||P.kind==="compartment")){const G=b.get(ut(P.parent));if(G&&(O<G.x||O>=G.x+G.width||M<G.y||M>=G.y+G.height))m("TERMINAL_PARENT_FRAME_BREACH","failed","Owned content escapes its independently allocated native container frame.",P.id,O,M)}}if(E.kind==="stroke"&&E.owners.length&&!lv(E,Q))m("TERMINAL_STROKE_PROVENANCE_CHANGED","failed","Final stroke ink disagrees with its original owner contributions.",E.owners[0]?.id,O,M);if(E.glyph===ir){const D=t.cell(E.head,M);if(!D||D.glyph===ir||E.head>=O||E.head+E.width<=O||D.width!==E.width)m("TERMINAL_GRAPHEME_CONTINUATION","failed","A wide grapheme continuation has no complete head.",E.owners[0]?.id,O,M);else if(D.kind!==E.kind||D.owners.length!==E.owners.length||D.owners.some(P=>{p();return!E.owners.some(U=>{p();return ut(U)===ut(P)})}))m("TERMINAL_GRAPHEME_OWNER_SPLIT","failed","A wide grapheme has inconsistent semantic ownership across its cells.",D.owners[0]?.id,O,M);continue}n.graphemes++;const $=cv(E);if($!==void 0&&E.glyph!==$)m("TERMINAL_PRIMITIVE_GLYPH_CHANGED","failed","A final glyph disagrees with its retained typed stroke, marker or numeric mark.",E.owners[0]?.id,O,M);if(E.head!==O||E.width!==ne(E.glyph)||E.width<1)m("TERMINAL_GRAPHEME_HEAD","failed","A final grapheme has inconsistent cell width or head coordinates.",E.owners[0]?.id,O,M);for(let D=1;D<E.width;D++){p();const P=t.cell(O+D,M);if(P?.glyph!==ir||P.head!==O||P.width!==E.width)m("TERMINAL_GRAPHEME_SPLIT","failed","A wide grapheme has lost a protected continuation cell.",E.owners[0]?.id,O,M)}if(E.kind==="text"&&!B.has(kn(O,M)))m("TERMINAL_TEXT_MEASUREMENT_UNAVAILABLE","unverified","A painted text cell has no retained measured allocation.",E.owners[0]?.id,O,M)}for(const[O,M]of C.ports){p();n.ports++;L.get(ut(O))?.ports.push(M);if(M.markers)n.markerContracts++;else m("TERMINAL_MARKER_CONTRACT_UNAVAILABLE","unverified","An endpoint has no independent native marker expectation.",O.id,M.x,M.y);const E=M.end==="start"?O.from:O.to;if(E!==void 0&&E!==M.nodeId)m("TERMINAL_PORT_ENDPOINT_MISMATCH","failed","The allocated port disagrees with the native endpoint identity.",O.id,M.x,M.y);if(!k.has(M.nodeId))m("TERMINAL_PORT_TARGET_UNAVAILABLE","unverified","A port target has no retained identity declaration.",O.id,M.x,M.y);if(M.boundary){const _=ut(M.boundary),q=new Set;let Q=x.get(ut({id:M.nodeId,kind:"node"})),$=false;while(Q?.parent){p();const P=ut(Q.parent);if(q.has(P))break;q.add(P);if(P===_){$=true;break}Q=x.get(P)}if(!$||!["group","cluster","subgraph"].includes(M.boundary.kind))m("TERMINAL_PORT_BOUNDARY_MISMATCH","failed","The physical port boundary is not a declared container ancestor of its authored endpoint.",O.id,M.x,M.y);const D=b.get(_);if(!D)m("TERMINAL_PORT_BOUNDARY_UNAVAILABLE","unverified","The physical port boundary has no allocated frame.",O.id,M.x,M.y);else if(!M.markerProjection){const P=M.side==="L"||M.side==="R";const U=M.side==="L"?D.x-M.x:M.side==="R"?M.x-(D.x+D.width-1):M.side==="T"?D.y-M.y:M.y-(D.y+D.height-1);const j=P?M.y-D.y:M.x-D.x;if(!M.side||U<0||U>1||j<0||j>=(P?D.height:D.width))m("TERMINAL_PORT_BOUNDARY_CONTACT","failed","The physical port does not touch its declared container face.",O.id,M.x,M.y)}}}for(const{owner:O,ports:M,cells:E,witness:_}of L.values()){p();if(M.length===2&&M.every(G=>G.markerProjection&&G.markerProjection===M[0].markerProjection))continue;const q=_?_.start:M.find(G=>G.end==="start"),Q=_?_.end:M.find(G=>G.end==="end");for(const G of M){p();const se=G.boundary??{id:G.nodeId,kind:"node"},ce=ut(se);const ae=b.get(ce),Y=_?Sp(t,O,G.x,G.y,p):E.get(kn(G.x,G.y))??0;const V=G.side==="R"?1:G.side==="L"?-1:0,N=G.side==="B"?1:G.side==="T"?-1:0;const J=G.side==="T"?4:G.side==="R"?8:G.side==="B"?1:G.side==="L"?2:0;const ee=!ae?-1:V?V>0?G.x-(ae.x+ae.width-1):ae.x-G.x:N>0?G.y-(ae.y+ae.height-1):ae.y-G.y;const X=ee<0||ee>1?void 0:t.cell(G.x-V*ee,G.y-N*ee);if(!ae||!(Y&J)||!X?.glyph.trim()||X.kind!=="stroke"&&X.kind!=="marker"||!X.owners.some(ie=>{p();return ut(ie)===ce}))m("TERMINAL_ROUTE_CONTACT_FAILED","failed","A connected route lacks visible owned connector and surface ink at its declared physical face.",O.id,G.x,G.y)}let $=E;if(_){const G=_.admission.route.points;let se=M.length===2&&!!q&&!!Q&&G.length>0;for(let ce=0;ce<G.length;ce++){const ae=G[ce],Y=G[ce-1],V=G[ce+1];let N=0;if(Y)N|=Y.x>ae.x?2:Y.x<ae.x?8:Y.y>ae.y?4:1;if(V)N|=V.x>ae.x?2:V.x<ae.x?8:V.y>ae.y?4:1;const J=Sp(t,O,ae.x+_.dx,ae.y+_.dy,p);if(!J||(J&N)!==N)se=false}if(se)continue;p();$=new Map;for(const[ce,ae]of t.entries()){const Y=Sp(t,O,ce,ae,p);if(Y){p();p();$.set(kn(ce,ae),Y)}}}const D=q&&kn(q.x,q.y),P=Q&&kn(Q.x,Q.y);const U=D&&$.has(D)?[D]:[],j=new Set(U);for(let G=0;G<U.length&&!j.has(P??"");G++){p();const se=U[G],[ce,ae]=se.split(",").map(Number),Y=$.get(se);for(const[V,N,J,ee]of[[0,-1,1,4],[1,0,2,8],[0,1,4,1],[-1,0,8,2]]){p();const X=kn(ce+V,ae+N);if(Y&J&&($.get(X)??0)&ee&&!j.has(X)){j.add(X);U.push(X)}}}if(M.length!==2||!D||!P||!j.has(P))m("TERMINAL_ROUTE_DISCONNECTED","failed","Declared connected ports have no complete path through mutually connected visible owned stroke and marker cells.",O.id,q?.x,q?.y)}try{t.assertMarkers(p)}catch(O){if(O===f)throw O;m("TERMINAL_MARKER_CONTRACT_FAILED","failed",O instanceof Error?O.message:"Final native marker admission failed.")}for(const O of t.diagnostics){p();if(["TERMINAL_TEXT_COLLISION","TERMINAL_ROUTE_OVERLAP","TERMINAL_GEOMETRY_COLLISION"].includes(O.code))m(O.code,"failed",O.message,O.feature,O.cell?.column,O.cell?.row);else if(O.code==="TERMINAL_OWNERSHIP_UNAVAILABLE")m(O.code,"unverified",O.message,O.feature);else if(O.code==="TERMINAL_FAMILY_PROJECTION"){if(s.length<i.maxIssues)s.push(Object.freeze({feature:O.feature,message:O.message}));else u=true}}}catch(C){if(C!==f)throw C;m("TERMINAL_CERTIFICATION_LIMIT","unverified","The final native cell inspection exhausted its operation budget.")}return Object.freeze({version:1,unit:"cell",scope:"terminal-cells",status:h,...g===void 0?{}:{outputDigest:g},...y?{bounds:y}:{},coverage:Object.freeze(n),budget:Object.freeze({operations:l,maxOperations:i.maxOperations,outputCodeUnits:e.length,maxOutputCodeUnits:i.maxOutputCodeUnits,exhausted:c,issuesTruncated:d,projectionsTruncated:u}),issues:Object.freeze(o),projections:Object.freeze(s),limitations:TD})}function vD(t){const e=r=>r===void 0?void 0:Zi(r);return{...t,bg:Zi(t.bg)??"#ffffff",fg:Zi(t.fg)??"#27272a",line:e(t.line),accent:e(t.accent),muted:e(t.muted),surface:e(t.surface),border:e(t.border),font:yg(t.font)??"Inter"}}function ED(t,e={}){return NM(t,e).text}function NM(t,e={}){return MD(Tr(t),e).rendered}function MD(t,e){const r=t.source;const i=kp({useAscii:e.useAscii,paddingX:e.paddingX,paddingY:e.paddingY,boxBorderPadding:e.boxBorderPadding,colorMode:e.colorMode,theme:e.theme,maxWidth:e.maxWidth,targetWidth:e.targetWidth});const n={useAscii:i.useAscii,paddingX:i.paddingX,paddingY:i.paddingY,boxBorderPadding:i.boxBorderPadding,graphDirection:"TD"};const o=i.colorMode;const s=i.targetWidth??i.maxWidth;const a=o==="html"?"html":i.useAscii?"ascii":"unicode";const l=SM(e);const c=kc(r,l,a,i,{expectedFamilyId:t.expectedFamilyId});vc(c);const d=Cc(c);const u=d.family;const h=c.source;n.title=On(h.frontmatter);n.maxWidth=s;n.targetWidth=i.targetWidth;const m=u.id==="pie"&&(()=>{const j=Do(oc(h));const G=j.displayTitle??j.title;return G!==void 0&&Va(G)!==G||j.entries.some(se=>{const ce=se.displayLabel??se.label;return Va(ce)!==ce})})();const f=lC(c);const p=u.id;const g=TM(c,o,i.theme,void 0,{controlsReplaced:AD(h)||m});let y;const C=()=>{if(y)return y;let j=null;let G=false;if(u.lowerScene&&u.layout){try{const se=ik(p,c,h);j=ok(u,u.lowerScene({positioned:se.positioned,colors:vD(c.appearance.colors),resolved:f}),true)}catch(se){const ce=hy(se);if(ce)throw ce;G=true}}return y=vM(g,j,G)};if(e.onProjectionDiagnostic)C();for(const j of y?.diagnostics??[])e.onProjectionDiagnostic?.(j);const w=g.theme;const x=Jd(r,h.familyBody);const k={source:h,...f,config:n,colorMode:o,theme:w,get connectorProjection(){return C().connectorProjection.connectors},options:{maxWidth:s,targetWidth:i.targetWidth,ganttToday:f.renderOptions.ganttToday}};const{artifact:b,legacyOutput:A}=nC(j=>rk(c,j,"primary"),()=>{const j=j0(u.renderAscii,k,x);return{artifact:j,legacyOutput:j?void 0:u.renderAscii(k)}});let L=b?.document;const B=On(h.frontmatter);if(L&&B&&!L.titleHandled&&!L.hasOwner("title","label")){const j=new Re;for(const G of ve(Ge(B),s))j.line([{text:G,owner:{id:"title",kind:"label"},role:"text",textGroup:"title"}]);j.line();j.overlay(L,0,j.height);L=j}const O=L?.diagnostics??[];for(const j of O)e.onProjectionDiagnostic?.(j);let M;const E=()=>{if(M)return M;const j=C();if(!O.length)return M=j;const G=Object.freeze([...j.diagnostics,...O]);return M=Object.freeze({...j,diagnostics:G,digest:Un({style:j.digest,diagnostics:G})})};const _=L?L.serialize({...b.serialization,colorMode:o,theme:w,...L!==b.document||i.targetWidth!==void 0?{trimEnd:true}:{}}):A;const q=Kt(u.id)?o==="html"?Na(_):_:H0(_,o);let Q;const $=j=>{let G;const se=()=>G??=DM(L,j,o);if(c.renderOptions.layoutSafety==="strict"&&se().status!=="passed")throw new Error(`Strict terminal layout safety failed: ${se().issues.map(ae=>ae.message).join("; ")}`);const ce={text:j,get receipt(){return Q??=Object.freeze({...aC(c,E().diagnostics),layoutCertification:se()})},get terminalStyle(){return E()},outputPolicy:i};uv(ce,L);return ce};const D=i.targetWidth;if(D===void 0){return{rendered:$(q),model:x}}const P=L?q:q.split("\n").map(j=>j.trimEnd()).join("\n").trimEnd();const U=Math.max(0,...P.split("\n").map(j=>Rf(j,o)));if(U>D){const j=ri(h.body).some(G=>ne(G)>D);throw new Pt(D,U,p,j?"UNBREAKABLE_GRAPHEME":"MINIMUM_GEOMETRY")}return{rendered:$(P),model:x}}function AD(t){const e=r=>{if(typeof r==="string")return $t(r)!==r;if(Array.isArray(r))return r.some(e);if(r!==null&&typeof r==="object"){return Object.entries(r).some(([i,n])=>e(i)||e(n))}return false};return t.originalText.split(/\r?\n/).some(e)||t.body.split(/\r?\n/).some(e)||e(t.config)||e(t.frontmatter)||e(t.initDirectives)||e(t.comments)||e(t.accessibility)}import{decodeXML as PM}from"entities";function $M(t,e=[]){const r=vn(t);const i=[...t.matchAll(/<\/([A-Za-z][\w:-]*)\s*>/g)];const n=[];let o=0;let s;const a=l=>{while(o<i.length&&i[o].index<l){const c=i[o++];const d=n.pop();if(!d||d.node.tag!==c[1])throw new Error("Malformed resolved SVG tree");d.node.text=PM(t.slice(d.start,c.index).replace(/<[^>]*>/g,""))}};r.forEach((l,c)=>{a(l.start);const d=n.at(-1)?.node;const u={tag:l.name,attrs:Object.fromEntries(l.attributes.map(h=>[h.name,PM(h.value)])),children:[],text:"",owner:e[c]??-1,...d?{parent:d}:{}};if(d)d.children.push(u);else if(!s)s=u;else throw new Error("Resolved SVG has multiple roots");if(!l.selfClosing)n.push({node:u,start:l.end})});a(t.length);if(!s||n.length)throw new Error("Resolved SVG has no complete root");return s}var tu={fill:"#000000","fill-opacity":"1",stroke:"none","stroke-opacity":"1","stroke-width":"1",opacity:"1","stroke-linecap":"butt","stroke-linejoin":"miter","stroke-miterlimit":"4","fill-rule":"nonzero","paint-order":"normal","stroke-dasharray":"none","stroke-dashoffset":"0",color:"#000000","font-size":"16","font-family":"serif","font-weight":"400","font-style":"normal","text-anchor":"start","dominant-baseline":"auto","letter-spacing":"normal",display:"inline",visibility:"visible",filter:"none","clip-path":"none",mask:"none","marker-start":"none","marker-end":"none","marker-mid":"none"};var FM=new Set(["opacity","display","filter","clip-path","mask"]);function bs(t,e){const r=[];let i="",n=0,o=0;for(let s=0;s<t.length;s++){const a=t[s];if(i){if(a==="\\")s++;else if(a===i)i=""}else if(a==='"'||a==="'")i=a;else if(a==="("||a==="[")n++;else if(a===")"||a==="]")n--;else if(a===e&&n===0){r.push(t.slice(o,s).trim());o=s+1}}r.push(t.slice(o).trim());return r}function qM(t){return bs(t,";").flatMap(e=>{const r=e.indexOf(":");if(r<0)return[];const i=e.slice(0,r).trim();const n=e.slice(r+1).trim();return[{key:i,value:n.replace(/\s*!important\s*$/i,"").trim(),important:/!important\s*$/i.test(n)}]})}function wp(t,e){if(e.includes(":")&&!e.endsWith(":root"))return false;if(e.endsWith(":root")){if(t.parent)return false;e=e.slice(0,-5)}let r=true;const i=e.replace(/\[([\w:-]+)(?:\s*([~|^$*]?=)\s*["']?([^\]"']*?)["']?)?\]/g,(n,o,s,a)=>{const l=t.attrs[o];r&&=s===void 0?l!==void 0:s==="="?l===a:s==="~="?(l??"").split(/\s+/).includes(a):false;return""}).replace(/([.#])([\w-]+)/g,(n,o,s)=>{r&&=o==="#"?t.attrs.id===s:(t.attrs.class??"").split(/\s+/).includes(s);return""});return r&&(i===""||i==="*"||i===t.tag)}function OD(t,e){const r=e.trim().replace(/\s*>\s*/g," > ").split(/\s+/);let i=t;let n=r.length-1;if(!wp(t,r[n--]))return false;while(n>=0){const o=r[n]===">";if(o)n--;const s=r[n--];i=i?.parent;while(i&&!wp(i,s)&&!o)i=i.parent;if(!i||!wp(i,s))return false}return true}function zM(t){const e=[];const r=i=>{if(i.tag==="style"){const n=i.text.replace(/\/\*[\s\S]*?\*\//g,"").replace(/@import[^;]*;/g,"");for(const o of n.matchAll(/([^{}]+)\{([^{}]*)\}/g)){if(o[1].trim().startsWith("@"))continue;for(const s of bs(o[1],",")){const a=(s.match(/#[\w-]+/g)?.length??0)*100+(s.match(/\.[\w-]+|\[[^\]]+\]|:[\w-]+/g)?.length??0)*10+(s.match(/(?:^|[\s>+~])([a-zA-Z][\w-]*)/g)?.length??0);e.push({selector:s,specificity:a,declarations:qM(o[2])})}}}i.children.forEach(r)};r(t);return e}function Tp(t,e,r=0){if(r>32)throw new Error("Unresolved or cyclic CSS var()");let i="",n=0;while(true){const o=t.indexOf("var(",n);if(o<0)return i+t.slice(n);let s=o+4,a=1;while(s<t.length&&a){if(t[s]==="(")a++;else if(t[s]===")")a--;s++}if(a)throw new Error("Malformed CSS var()");const[l,...c]=bs(t.slice(o+4,s-1),",");const d=e[l]??(c.length?c.join(","):void 0);if(d===void 0)throw new Error(`Unresolved CSS variable ${l}`);i+=t.slice(n,o)+Tp(d,e,r+1);n=s}}function GM(t,e,r){const i={...tu};if(e){for(const[u,h]of Object.entries(e))if(!FM.has(u))i[u]=h}const n=new Map;const o=(u,h)=>{const m=(u.important?1e6:0)+h;if(m<(n.get(u.key)??-1))return;n.set(u.key,m);i[u.key]=u.value==="inherit"||u.value==="unset"&&!FM.has(u.key)?e?.[u.key]??tu[u.key]??"":u.value==="initial"||u.value==="unset"?tu[u.key]??"":u.value};for(const[u,h]of Object.entries(t.attrs))if(u in tu)o({key:u,value:h,important:false},0);for(const u of r)if(OD(t,u.selector))for(const h of u.declarations)o(h,u.specificity+1);for(const u of qM(t.attrs.style??""))o(u,1e4);const s={...i};for(const[u,h]of Object.entries(s))if(u.startsWith("--")){try{i[u]=Tp(h,s)}catch{delete i[u]}}for(const[u,h]of Object.entries(i))if(!u.startsWith("--"))i[u]=Tp(h,i);const a=i["font-size"];i["font-size"]=Ha(lo(a,Number(e?.["font-size"]??16),16));if(i["font-weight"]==="normal")i["font-weight"]="400";if(i["font-weight"]==="bold")i["font-weight"]="700";if(i["font-weight"]==="bolder")i["font-weight"]=Number(e?.["font-weight"]??400)<400?"400":Number(e?.["font-weight"]??400)<600?"700":"900";if(i["font-weight"]==="lighter")i["font-weight"]=Number(e?.["font-weight"]??400)<600?"100":Number(e?.["font-weight"]??400)<800?"400":"700";for(const u of["stroke-width","stroke-dashoffset","letter-spacing"]){if(i[u]!=="normal")i[u]=Ha(lo(i[u],Number(i["font-size"])))}if(i["stroke-dasharray"]!=="none"){i["stroke-dasharray"]=i["stroke-dasharray"].split(/[\s,]+/).map(u=>Ha(lo(u,Number(i["font-size"])))).join(" ")}for(const u of["opacity","fill-opacity","stroke-opacity"]){const h=i[u];const m=Number(h.endsWith("%")?h.slice(0,-1):h)/(h.endsWith("%")?100:1);if(!Number.isFinite(m))throw new Error(`Unsupported ${u}: ${h}`);i[u]=Ha(Math.max(0,Math.min(1,m)))}i["stroke-miterlimit"]=Ha(Number(i["stroke-miterlimit"]));const l=["fill","stroke","markers"];const c=i["paint-order"]==="normal"?[]:i["paint-order"].split(/\s+/);const d=[...c,...l.filter(u=>!c.includes(u))];for(let u=0;u<=d.length;u++){const h=d.slice(0,u);const m=[...h,...l.filter(f=>!h.includes(f))];if(m.join(" ")===d.join(" ")){i["paint-order"]=h.join(" ")||"normal";break}}return i}function Ha(t){const e=Math.fround(t);if(!Number.isFinite(e))throw new Error("Non-finite computed CSS value");return String(Number(e.toPrecision(6)))}function lo(t,e,r=16){const i=t.trim().match(/^([-+]?(?:\d*\.\d+|\d+\.?\d*)(?:e[-+]?\d+)?)(px|em|rem|pt|pc|in|cm|mm|q)?$/i);if(!i)throw new Error(`Unsupported length "${t}"`);const n={px:1,em:e,rem:r,pt:96/72,pc:16,in:96,cm:96/2.54,mm:96/25.4,q:96/101.6};const o=Number(i[1])*(n[i[2]?.toLowerCase()??"px"]??1);if(!Number.isFinite(o))throw new Error(`Non-finite length "${t}"`);return o}var vp=[1,0,0,1,0,0];var Xa=(t,e)=>{const r=[...cg(t,e)];if(!r.every(Number.isFinite))throw new Error("Non-finite transform");return r};function WM(t){if(!t)return[...vp];const e=dg(t);if(e)return[...e];const r=t.match(/^skew([XY])\(\s*([-+\d.eE]+)\s*\)$/);if(r){const i=Math.tan(Number(r[2])*Math.PI/180);return r[1]==="X"?[1,0,i,1,0,0]:[1,i,0,1,0,0]}throw new Error(`Unsupported transform "${t}"`)}function UM(t,e){const r=(i,n=0)=>t.attrs[i]===void 0?n:lo(t.attrs[i],e);switch(t.tag){case"path":return t.attrs.d??"";case"line":return`M${r("x1")} ${r("y1")}L${r("x2")} ${r("y2")}`;case"polygon":case"polyline":{const i=(t.attrs.points??"").trim().split(/[\s,]+/).map(Number);const n=[];for(let o=0;o+1<i.length;o+=2)n.push(`${i[o]} ${i[o+1]}`);return n.length?`M${n.join("L")}${t.tag==="polygon"?"Z":""}`:""}case"rect":{const i=r("x"),n=r("y"),o=r("width"),s=r("height");const a=Math.min(r("rx",r("ry")),o/2),l=Math.min(r("ry",r("rx")),s/2);return a>0&&l>0?`M${i+a} ${n}H${i+o-a}A${a} ${l} 0 0 1 ${i+o} ${n+l}V${n+s-l}A${a} ${l} 0 0 1 ${i+o-a} ${n+s}H${i+a}A${a} ${l} 0 0 1 ${i} ${n+s-l}V${n+l}A${a} ${l} 0 0 1 ${i+a} ${n}Z`:`M${i} ${n}h${o}v${s}h${-o}Z`}case"circle":case"ellipse":{const i=r("cx"),n=r("cy"),o=r("rx",r("r")),s=r("ry",r("r"));return`M${i+o} ${n}A${o} ${s} 0 0 1 ${i} ${n+s}A${o} ${s} 0 0 1 ${i-o} ${n}A${o} ${s} 0 0 1 ${i} ${n-s}A${o} ${s} 0 0 1 ${i+o} ${n}Z`}default:throw new Error(`Unsupported element <${t.tag}>`)}}function jM(t){const e=t.match(/[a-df-zA-DF-Z]|[-+]?(?:\d*\.\d+|\d+\.?\d*)(?:e[-+]?\d+)?/g)??[];let r=0,i="",n="",o={x:0,y:0},s=o,a=o;let l,c,d;const u=(g,y)=>g.x===y.x&&g.y===y.y?void 0:Math.atan2(y.y-g.y,y.x-g.x)*180/Math.PI;const h=g=>{for(let y=1;y<g.length;y++){const C=u(g[0],g[y]);if(C!==void 0)return C}return void 0};const m=(g,y)=>{const C=Math.fround(g.x),w=Math.fround(g.y);const x=Math.fround(y.x),k=Math.fround(y.y);const b=Math.hypot(x-C,k-w);if(!b)return[void 0,void 0];const A=Math.min(.1,b)/b;return[Math.atan2(Math.fround(w+(k-w)*A)-w,Math.fround(C+(x-C)*A)-C)*180/Math.PI,Math.atan2(k-Math.fround(k-(k-w)*A),x-Math.fround(x-(x-C)*A))*180/Math.PI]};const f=(g,y,C)=>{d??=o;if(!l&&y!==void 0)l={point:d,angle:y};c={point:g,angle:C??c?.angle??0};o=g};while(r<e.length){if(/^[a-z]$/i.test(e[r]))i=e[r++];const g=i.toUpperCase(),y=g!==i;if(g==="Z"){f(s,...m(o,s));i="";n=g;continue}const C=g==="A"?7:g==="C"?6:g==="S"||g==="Q"?4:g==="H"||g==="V"?1:g==="M"||g==="L"||g==="T"?2:0;if(!C||r+C>e.length)throw new Error("Unsupported marker path data");const w=e.slice(r,r+C).map(Number);if(!w.every(Number.isFinite))throw new Error("Unsupported marker path data");r+=C;const x=b=>({x:w[b]+(y?o.x:0),y:w[b+1]+(y?o.y:0)});const k=g==="H"?{x:w[0]+(y?o.x:0),y:o.y}:g==="V"?{x:o.x,y:w[0]+(y?o.y:0)}:x(C-2);if(g==="M"){o=k;s=k;d??=k;i=y?"l":"L"}else if(g==="C"||g==="S"||g==="Q"||g==="T"){const b=g==="S"&&["C","S"].includes(n)||g==="T"&&["Q","T"].includes(n)?{x:2*o.x-a.x,y:2*o.y-a.y}:o;const A=g==="S"||g==="T"?b:x(0);const L=g==="C"?x(2):g==="S"?x(0):A;f(k,h([o,A,L,k]),h([k,L,A,o])===void 0?void 0:h([k,L,A,o])+180);a=L}else if(g==="A"&&w[0]&&w[1]&&(o.x!==k.x||o.y!==k.y)){let b=Math.abs(w[0]),A=Math.abs(w[1]);const L=w[2]*Math.PI/180,B=Math.cos(L),O=Math.sin(L);const M=(o.x-k.x)/2,E=(o.y-k.y)/2;const _=B*M+O*E,q=-O*M+B*E;const Q=Math.max(1,Math.hypot(_/b,q/A));b*=Q;A*=Q;const $=(_/b)**2+(q/A)**2;const D=(w[3]===w[4]?-1:1)*Math.sqrt(Math.max(0,(1-$)/$));const P=D*b*q/A,U=-D*A*_/b;const j=(G,se)=>{const ce=-b*se/A,ae=A*G/b,Y=w[4]?1:-1;return Math.atan2(Y*(O*ce+B*ae),Y*(B*ce-O*ae))*180/Math.PI};f(k,j(_-P,q-U),j(-_-P,-q-U))}else f(k,...m(o,k));n=g}const p={point:d??o,angle:0};return[l??p,c??p]}var Ep=2;function VM(t,e,r){const i=$M(t,r);const n=zM(i);const o=new Map;const s=new Map;const a=[];const l=new Map;e.parts.forEach((x,k)=>{if(x.kind==="document")return;const b={id:x.id,role:x.role,kind:x.kind,node:x,primitives:[]};a.push(b);l.set(k,b)});const c=[];let d=-1;const u=x=>{throw new Error(`Resolved Scene part "${l.get(d)?.id??"frame"}": ${x}`)};const h=x=>{if(x.attrs.id)s.set(x.attrs.id,x);x.children.forEach(h)};h(i);const m=x=>{const k=o.get(x);if(k)return k;try{const b=GM(x,x.parent?m(x.parent):void 0,n);o.set(x,b);return b}catch(b){return u(b.message)}};const f=(x,k)=>{if(x==="none")return["none",1];if(/url\s*\(/i.test(x))return u(`paint server ${x}`);if(x.toLowerCase()==="currentcolor")x=k.color;const b=x.match(/^color-mix\(in srgb,\s*(.+)\)$/i);if(b){const L=bs(b[1],",");if(L.length!==2)return u(`Unsupported color ${x}`);const B=Y=>{const V=Y.match(/^(.*?)\s+([\d.]+)%$/);return V?[V[1],Number(V[2])/100]:[Y,void 0]};const[O,M]=B(L[0]),[E,_]=B(L[1]);const q=M??(_===void 0?.5:1-_),Q=_??1-q;const[$,D]=f(O,k),[P,U]=f(E,k);const j=Ft($),G=Ft(P);if(!j||!G)return u(`Unsupported color ${x}`);const se=q+Q;if(!(se>0)||!Number.isFinite(se))return u(`Unsupported color ${x}`);const ce=(D*q+U*Q)/se;const ae=Y=>ce?(j[Y]*D*q+G[Y]*U*Q)/(se*ce):0;return[Mr(ae(0),ae(1),ae(2)).toLowerCase(),ce*Math.min(1,se)]}const A=Ft(x);if(!A)return u(`Unsupported color ${x}`);return[Mr(A[0],A[1],A[2]).toLowerCase(),A[3]]};const p=(x,k)=>lo(x,Number(k["font-size"]));const g=(x,k)=>{const[b,A]=f(x.fill,x),[L,B]=f(x.stroke,x);const O=x["stroke-dasharray"];return{fill:b,fillOpacity:A*Number(x["fill-opacity"]),stroke:L,strokeOpacity:B*Number(x["stroke-opacity"]),strokeWidth:p(x["stroke-width"],x),opacity:k,lineCap:x["stroke-linecap"],lineJoin:x["stroke-linejoin"],miterLimit:Number(x["stroke-miterlimit"]),fillRule:x["fill-rule"],paintOrder:x["paint-order"],...O==="none"?{}:{dashArray:O.split(/[\s,]+/).map(M=>p(M,x)),dashOffset:p(x["stroke-dashoffset"],x)}}};const y=(x,k)=>(l.get(x)?.primitives??c).push(k);const C=new Set;const w=(x,k,b,A,L=false)=>{const B=x.tag;if(["defs","style","title","desc","metadata"].includes(B))return;const O=A??x.owner;d=O;const M=m(x);if(M.display==="none")return;for(const $ of["filter","clip-path","mask","marker-mid"])if(M[$]!=="none")u(`${$}: ${M[$]}`);const E=b*Number(M.opacity);const _=Xa(k,WM(x.attrs.transform));if(B==="g"||B==="a"||B==="svg"){if(B==="svg"&&x!==i)u("nested svg viewport");x.children.forEach($=>w($,_,E,A,L));return}if(B==="text"&&x.children.length){for(const $ of x.children){const D=U=>{if(U.tag!=="tspan")u(`Unsupported text element <${U.tag}>`);U.children.forEach(D)};D($);const P={...x,attrs:{...x.attrs,...$.attrs},children:[],text:$.text};o.set(P,m($));w(P,k,E,O,L)}return}if(M.visibility==="hidden"||M.visibility==="collapse")return;const q=g(M,E);if(B==="text"){const $=P=>x.attrs[P]===void 0?0:p(x.attrs[P],M);const D=M["letter-spacing"]==="normal"?0:p(M["letter-spacing"],M);y(O,{kind:"text",text:x.text,x:$("x")+$("dx"),y:$("y")+$("dy"),fontSize:Number(M["font-size"]),fontFamily:bs(M["font-family"],",").map(P=>P.replace(/^["']|["']$/g,"")),fontWeight:Number(M["font-weight"]),fontStyle:M["font-style"],anchor:M["text-anchor"],...M["dominant-baseline"]==="auto"?{}:{baseline:M["dominant-baseline"]},...x.attrs.textLength===void 0?{}:{textLength:$("textLength"),lengthAdjust:x.attrs.lengthAdjust??"spacing"},...D?{letterSpacing:D}:{},matrix:_,paint:q});return}let Q;try{Q=UM(x,Number(M["font-size"]))}catch($){return u($.message)}y(O,{kind:"path",d:Q,matrix:_,paint:q,...L?{marker:true}:{}});for(const[$,D]of[["marker-start",0],["marker-end",1]]){const P=M[$];if(P==="none")continue;const U=P.match(/#([^)"']+)/)?.[1];const j=(U?s.get(U):void 0)??u(`Unresolved marker ${P}`);if(j.tag!=="marker")u(`Unresolved marker ${P}`);if(C.has(j))u(`Cyclic marker ${P}`);C.add(j);const G=jM(Q)[D];const se=j.attrs.orient??"0";const ce=se.startsWith("auto")?G.angle+(se==="auto-start-reverse"&&D===0?180:0):Number(se);const ae=j.attrs.markerUnits==="userSpaceOnUse"?1:q.strokeWidth;const Y=ce*Math.PI/180;let V=Xa(_,[Math.cos(Y)*ae,Math.sin(Y)*ae,-Math.sin(Y)*ae,Math.cos(Y)*ae,G.point.x,G.point.y]);const N=j.attrs.viewBox?.trim().split(/[\s,]+/).map(Number);if(N?.length===4&&N[2]&&N[3]){const J=Number(j.attrs.markerWidth??3),ee=Number(j.attrs.markerHeight??3);const X=J/N[2],ie=ee/N[3];V=Xa(V,[X,0,0,ie,-N[0]*X,-N[1]*ie])}V=Xa(V,[1,0,0,1,-Number(j.attrs.refX??0),-Number(j.attrs.refY??0)]);j.children.forEach(J=>w(J,V,E,O,true));C.delete(j)}};try{w(i,[...vp],1)}catch(x){if(x.message.startsWith("Resolved Scene part"))throw x;u(x.message)}return JSON.parse(JSON.stringify({version:Ep,family:e.family,width:e.width,height:e.height,svg:t,colors:e.colors,parts:a,frame:c}))}function BD(t,e={}){return mg(()=>{const r=Tr(t);const i=kc(r.source,e,"svg",void 0,{expectedFamilyId:r.expectedFamilyId});const n=Cc(i);if(n.mode!=="scene")throw new Error("Resolved Scene requires a family with Scene lowering");vc(i);const o=nk(i);const s=tC();const{svg:a,layoutCertification:l}=sk(i,o,[],s);if(!s.scene||!s.owners)throw new Error("Backend did not provide resolved Scene ownership");if(vn(a).length!==s.owners.length)throw new Error("Resolved Scene ownership changed during SVG postprocessing");const c=n.backend?.inputName==="default"&&l?.repairs.length?l.viewport:void 0;const d={...s.scene,family:n.family.id,...c?{width:c.width,height:c.height}:{}};return VM(a,d,s.owners)})}var YM=1;var Mt=Object.freeze({input:{version:true,family:true,width:true,height:true,colors:true,metadata:true,markers:true,parts:true},colors:{bg:true,fg:true,line:true,accent:true,muted:true,surface:true,border:true,shadow:true,font:true,embedFontImport:true},metadata:{title:true,description:true,transparent:true},nodes:{shape:{kind:true,id:true,role:true,channels:true,geometry:true,paint:true},"data-mark":{kind:true,id:true,role:true,channels:true,geometry:true,value:true,paint:true},text:{kind:true,id:true,role:true,channels:true,text:true,x:true,y:true,fontSize:true,anchor:true,paint:true},container:{kind:true,id:true,role:true,channels:true,children:true},connector:{kind:true,id:true,role:true,channels:true,geometry:true,from:true,to:true,lineStyle:true,paint:true,closed:true,startMarker:true,midMarker:true,endMarker:true,relationship:true,labels:true}},geometry:{rect:{kind:true,x:true,y:true,width:true,height:true,rx:true,ry:true},circle:{kind:true,cx:true,cy:true,r:true},ellipse:{kind:true,cx:true,cy:true,rx:true,ry:true},line:{kind:true,x1:true,y1:true,x2:true,y2:true},polygon:{kind:true,points:true},polyline:{kind:true,points:true},markerPath:{kind:true,d:true},connectorPath:{kind:true,d:true,points:true},compound:{kind:true,children:true}},point:{x:true,y:true},paint:{fill:true,stroke:true,strokeWidth:true,strokeDasharray:true,strokeDashoffset:true,strokeLinecap:true,strokeLinejoin:true,strokeMiterlimit:true,vectorEffect:true,paintOrder:true,opacity:true},channels:{importance:true,value:true,category:true,status:true,progress:true,route:true,emphasis:true},marker:{id:true,shape:true,geometry:true,size:true,viewBox:true,ref:true,bounds:true,units:true,orient:true,overflow:true,paint:true,scale:true},markerSize:{width:true,height:true},viewBox:{x:true,y:true,width:true,height:true},bounds:{x0:true,y0:true,x1:true,y1:true},relationship:{kind:true,direction:true},label:{id:true,text:true,anchor:true,bounds:true,halo:true,clearance:true,paint:true,fontSize:true,textAnchor:true},halo:{color:true,width:true}});function _D(t){const e=eC(t,Zb,"input");if(e===null||typeof e!=="object"||Array.isArray(e)){throw new TypeError("External Scene input must be a plain object")}const r=e;if(!Array.isArray(r.parts))throw new TypeError("External Scene parts must be a plain array");if(r.markers!==void 0&&!Array.isArray(r.markers)){throw new TypeError("External Scene markers must be a plain array")}ID(r);return e}function Sn(t,e){if(t===null||typeof t!=="object"||Array.isArray(t)){throw new TypeError(`External Scene ${e} must be a plain object`)}return t}function Ki(t,e,r){for(const i of Object.keys(t)){if(!Object.hasOwn(e,i)){throw new TypeError(`External Scene ${r}.${i} is not part of the v1 input contract`)}}}function bi(t,e,r){if(t===void 0)return;Ki(Sn(t,r),e,r)}function co(t,e){if(!Array.isArray(t))throw new TypeError(`External Scene ${e} must be a plain array`);return t}function mr(t,e){if(typeof t!=="string")throw new TypeError(`External Scene ${e} must be a string`)}function Jr(t,e){if(typeof t!=="number"||!Number.isFinite(t)){throw new TypeError(`External Scene ${e} must be a finite number`)}}function iu(t,e){const r=Sn(t,e);Ki(r,Mt.point,e);Jr(r.x,`${e}.x`);Jr(r.y,`${e}.y`)}function nu(t,e,r,i=false){const n=Sn(t,e);mr(n.kind,`${e}.kind`);if(!r.includes(n.kind)){throw new TypeError(`External Scene ${e}.kind must be one of: ${r.join(", ")}`)}const o=n.kind==="path"?i?Mt.geometry.connectorPath:Mt.geometry.markerPath:Mt.geometry[n.kind];Ki(n,o,e);const s=(...a)=>{for(const l of a)Jr(n[l],`${e}.${l}`)};switch(n.kind){case"rect":s("x","y","width","height");if(n.rx!==void 0)Jr(n.rx,`${e}.rx`);if(n.ry!==void 0)Jr(n.ry,`${e}.ry`);return;case"circle":s("cx","cy","r");return;case"ellipse":s("cx","cy","rx","ry");return;case"line":s("x1","y1","x2","y2");return;case"polygon":case"polyline":{const a=co(n.points,`${e}.points`);for(let l=0;l<a.length;l++)iu(a[l],`${e}.points[${l}]`);return}case"path":{mr(n.d,`${e}.d`);if(i){const a=co(n.points,`${e}.points`);for(let l=0;l<a.length;l++)iu(a[l],`${e}.points[${l}]`)}return}case"compound":{const a=co(n.children,`${e}.children`);for(let l=0;l<a.length;l++){nu(a[l],`${e}.children[${l}]`,["rect","circle","ellipse","line","polygon","polyline","path","compound"])}}}}function HM(t,e){const r=Sn(t,e);mr(r.kind,`${e}.kind`);mr(r.id,`${e}.id`);mr(r.role,`${e}.role`);if(!["shape","data-mark","text","container","connector"].includes(r.kind)){throw new TypeError(`External Scene ${e}.kind must be one of: shape, data-mark, text, container, connector`)}Ki(r,Mt.nodes[r.kind],e);bi(r.channels,Mt.channels,`${e}.channels`);bi(r.paint,Mt.paint,`${e}.paint`);if(r.kind==="shape"||r.kind==="data-mark"){nu(r.geometry,`${e}.geometry`,["rect","circle","ellipse","line","polygon","polyline"]);if(r.kind==="data-mark")Jr(r.value,`${e}.value`);return}if(r.kind==="text"){mr(r.text,`${e}.text`);Jr(r.x,`${e}.x`);Jr(r.y,`${e}.y`);Jr(r.fontSize,`${e}.fontSize`);return}if(r.kind==="container"){const i=co(r.children,`${e}.children`);for(let n=0;n<i.length;n++)HM(i[n],`${e}.children[${n}]`);return}nu(r.geometry,`${e}.geometry`,["line","polyline","path"],true);bi(r.relationship,Mt.relationship,`${e}.relationship`);if(typeof r.from!=="string"){throw new TypeError(`External Scene ${e}.from is required for external connectors and must be a string`)}if(typeof r.to!=="string"){throw new TypeError(`External Scene ${e}.to is required for external connectors and must be a string`)}if(r.labels!==void 0){const i=co(r.labels,`${e}.labels`);for(let n=0;n<i.length;n++){const o=`${e}.labels[${n}]`;const s=Sn(i[n],o);Ki(s,Mt.label,o);mr(s.text,`${o}.text`);if(s.anchor!==void 0)iu(s.anchor,`${o}.anchor`);bi(s.bounds,Mt.bounds,`${o}.bounds`);bi(s.halo,Mt.halo,`${o}.halo`);bi(s.paint,Mt.paint,`${o}.paint`)}}}function ID(t){Ki(t,Mt.input,"input");Jr(t.width,"input.width");Jr(t.height,"input.height");mr(t.family,"input.family");const e=Sn(t.colors,"input.colors");Ki(e,Mt.colors,"input.colors");mr(e.bg,"input.colors.bg");mr(e.fg,"input.colors.fg");const r=Sn(t.metadata,"input.metadata");Ki(r,Mt.metadata,"input.metadata");mr(r.title,"input.metadata.title");if(r.description!==void 0)mr(r.description,"input.metadata.description");if(r.transparent!==void 0&&typeof r.transparent!=="boolean"){throw new TypeError("External Scene input.metadata.transparent must be boolean")}const i=co(t.parts,"input.parts");for(let n=0;n<i.length;n++)HM(i[n],`input.parts[${n}]`);if(t.markers!==void 0){const n=co(t.markers,"input.markers");for(let o=0;o<n.length;o++){const s=`input.markers[${o}]`;const a=Sn(n[o],s);Ki(a,Mt.marker,s);mr(a.id,`${s}.id`);nu(a.geometry,`${s}.geometry`,["rect","circle","ellipse","line","polygon","polyline","path","compound"]);bi(a.size,Mt.markerSize,`${s}.size`);bi(a.viewBox,Mt.viewBox,`${s}.viewBox`);if(a.ref!==void 0)iu(a.ref,`${s}.ref`);bi(a.bounds,Mt.bounds,`${s}.bounds`);bi(a.paint,Mt.paint,`${s}.paint`);Au(a)}}}function LD(t){const e=t.lineStyle??"solid";const r=t.paint??{};return{fill:"none",stroke:r.stroke??"var(--_line)",strokeWidth:r.strokeWidth??(e==="thick"?"3":"1.5"),...r.opacity===void 0?{}:{opacity:r.opacity},...r.strokeDasharray!==void 0?{strokeDasharray:r.strokeDasharray}:e==="dotted"?{strokeDasharray:"2 4"}:e==="dashed"?{strokeDasharray:"6 4"}:{},...r.strokeDashoffset===void 0?{}:{strokeDashoffset:r.strokeDashoffset},strokeLinecap:r.strokeLinecap??"round",strokeLinejoin:r.strokeLinejoin??"round",strokeMiterlimit:r.strokeMiterlimit??"4",...r.vectorEffect===void 0?{}:{vectorEffect:r.vectorEffect},...r.paintOrder===void 0?{}:{paintOrder:r.paintOrder}}}function ru(t,e){if(++e.count>un.maxNodes){throw new Error(`External Scene compilation exceeds maximum node count ${un.maxNodes}`)}const r=Math.max(0,un.maxAggregateSerializationBytes-e.serializationBytes);const i=An(kg(t),r);if(i>r){throw new Error(`External Scene serializations exceed the aggregate ${un.maxAggregateSerializationBytes}-byte limit`)}e.serializationBytes+=i;return t}function XM(t,e,r,i){if(i>un.maxDepth){throw new Error(`External Scene parts exceed maximum depth ${un.maxDepth}`)}if(t.kind==="shape"||t.kind==="data-mark"){const p={fill:"none",stroke:"var(--_line)",strokeWidth:"1",...t.paint??{}};return[ru(gx({id:t.id,role:t.role,geometry:t.geometry,paint:p,...(()=>{const g=t.kind==="data-mark"?{...t.channels??{},value:t.value}:t.channels;return g?{channels:g}:{}})()}),r)]}if(t.kind==="text"){const p=t.anchor??"start";const g={fill:"var(--_text)",...t.paint??{}};return[ru(xx({id:t.id,role:t.role,text:t.text,x:t.x,y:t.y,fontSize:t.fontSize,fontWeight:400,display:"literal",anchor:p,baselineShift:0,paint:g,...t.channels?{channels:t.channels}:{}}),r)]}if(t.kind==="container"){return[ru(kx({id:t.id,role:t.role,open:"<g>",close:"</g>",children:t.children.flatMap(p=>XM(p,e,r,i+1).map(g=>({node:g,indent:2}))),...t.channels?{channels:t.channels}:{}}),r)]}const n=t.startMarker===void 0?void 0:e.get(t.startMarker);const o=t.midMarker===void 0?void 0:e.get(t.midMarker);const s=t.endMarker===void 0?void 0:e.get(t.endMarker);if(t.startMarker!==void 0&&!n)throw new Error(`Unknown external Scene marker "${t.startMarker}"`);if(t.midMarker!==void 0&&!o)throw new Error(`Unknown external Scene marker "${t.midMarker}"`);if(t.endMarker!==void 0&&!s)throw new Error(`Unknown external Scene marker "${t.endMarker}"`);if(t.closed!==void 0&&typeof t.closed!=="boolean"){throw new TypeError(`External Scene connector "${t.id}" closed must be boolean`)}if(t.geometry.kind!=="path"&&t.closed!==void 0){throw new TypeError(`External Scene connector "${t.id}" closed is only valid for path geometry`)}const a=t.closed??false;Qb(t.geometry,a);if(o&&t.geometry.kind==="path"){throw new TypeError(`External Scene v1 connector "${t.id}" cannot attach marker-mid to path geometry because v1 does not expose exact SVG marker vertices`)}const l=LD(t);const c=t.geometry.kind==="line"?[{x:t.geometry.x1,y:t.geometry.y1},{x:t.geometry.x2,y:t.geometry.y2}]:t.geometry.points;const d=c[0];const u=c.at(-1);const h=d&&u?{x:(d.x+u.x)/2,y:(d.y+u.y)/2}:{x:0,y:0};const m=(t.labels??[]).map(p=>({...p,anchor:p.anchor??h,paint:{fill:"var(--_text)",...p.paint??{}},fontSize:p.fontSize??12,textAnchor:p.textAnchor??"middle",visual:{kind:"inline"}}));for(const[p,g]of m.entries()){if(!g.bounds)continue;const y=ug(g);if(y&&(g.bounds.x0>y.x0||g.bounds.y0>y.y0||g.bounds.x1<y.x1||g.bounds.y1<y.y1)){throw new RangeError(`External Scene connector "${t.id}" label ${p+1} bounds must cover its inline visual geometry`)}}const f=ru(yx({id:t.id,role:t.role,geometry:t.geometry,lineStyle:t.lineStyle??"solid",paint:l,endpoints:{from:t.from,to:t.to},relationship:t.relationship,route:{closed:a},markers:{...n?{start:n}:{},mid:o?[o]:[],...s?{end:s}:{}},labels:m,...t.channels?{channels:t.channels}:{}}),r);return[f]}function RD(t){const e=_D(t);if(e.version!==YM){throw new Error(`Unsupported external Scene API version ${String(e.version)}`)}const r=As(e.family);if(!r||r.kind!=="family")throw new Error('External Scene family must use a valid "family:" id');const i=[];if(e.markers){for(let f=0;f<e.markers.length;f++)i.push(e.markers[f])}const n=new Map(i.map(f=>[f.id,f]));if(n.size!==i.length)throw new Error("External Scene marker ids must be unique");const o="external-scene-title";const s="external-scene-description";const a=[o,...e.metadata.description!==void 0?[s]:[]].join(" ");const l={...e.colors,embedFontImport:false};const c=l.font??"Inter";const d=Sx({id:"external-scene-prelude",width:e.width,height:e.height,colors:l,transparent:e.metadata.transparent??false,font:c,hasMonoFont:false},[Cg(e.width,e.height,l,e.metadata.transparent,{attrs:{role:"img","aria-labelledby":a}}),bg(c,false,l.shadow,false)].join("\n"));const u=[d,Vu({id:o,element:"title",text:e.metadata.title,domId:o})];if(e.metadata.description!==void 0){u.push(Vu({id:s,element:"description",text:e.metadata.description,domId:s}))}if(i.length>0){u.push(bx({id:"external-scene-definitions",markerResources:i},`<defs>
199
+ ${Ou(i)}
200
+ </defs>`))}const h={count:0,serializationBytes:0};for(let f=0;f<e.parts.length;f++){u.push(...XM(e.parts[f],n,h,0))}u.push(Cx());const m={family:e.family,width:e.width,height:e.height,colors:l,transparent:e.metadata.transparent??false,parts:u};Ah(m,{mode:"external"});return m}var Cs=1;function KM(t){return t instanceof Error?t.message:String(t)}function Ka(t,e,r,i){let n=true;for(const o of Object.keys(t)){if(e.has(o))continue;i.push(`unknown ${r} field "${o}"`);n=false}return n}var DD=new Set(["version","resources"]);var ND=new Set(["identity","path","mediaType","sha256","bytes","license","required","network"]);var PD=new Set(["id","kind","version","compatibility","provenance"]);var FD=new Set(["owner","source","reference"]);var $D=new Set(["spdx","noticePath"]);function Mp(t){if(t===""||t.startsWith("/")||t.includes("\\")||t.includes("\0"))return false;const e=t.split("/");return e.every(r=>r!==""&&r!=="."&&r!=="..")}function qD(t,e,r){if(!wt(t)){r.push(`missing resource identity: ${e}`);return void 0}const i=t.id;const n=t.kind;const o=t.version;const s=t.compatibility;const a=t.provenance;const l=typeof i==="string"?i:e;let c=Ka(t,PD,"resource identity",r);if(typeof i!=="string"){r.push(`invalid resource identity id: ${e}`);c=false}if(n!=="resource"){r.push(`invalid resource identity kind: ${l}`);c=false}if(typeof o!=="string"){r.push(`invalid resource identity version: ${l}`);c=false}const d={};if(s!==void 0){if(!wt(s)){r.push(`invalid resource compatibility: ${l}`);c=false}else{for(const[h,m]of Object.entries(s)){if(m!==void 0&&typeof m!=="string"){r.push(`invalid resource compatibility range "${h}": ${l}`);c=false}else{d[h]=m}}}}let u;if(!wt(a)){r.push(`missing resource provenance: ${l}`);c=false}else{if(!Ka(a,FD,"resource provenance",r))c=false;const h=a.owner;const m=a.source;const f=a.reference;if(typeof h!=="string"||typeof m!=="string"||f!==void 0&&typeof f!=="string"){r.push(`invalid resource provenance: ${l}`);c=false}else{u={owner:h,source:m,...f===void 0?{}:{reference:f}}}}if(!c||u===void 0||typeof o!=="string")return void 0;try{return Ci({id:l,kind:"resource",version:o,compatibility:d,provenance:u})}catch(h){r.push(`invalid resource identity: ${KM(h)}`);return void 0}}function zD(t,e,r){const i=`resource[${e}]`;if(!wt(t)){r.push(`resource entry must be a plain object: ${i}`);return void 0}const n=t.identity;const o=qD(n,i,r);const s=o?.id??i;const a=t.path;const l=t.mediaType;const c=t.sha256;const d=t.bytes;const u=t.required;const h=t.network;let m=o!==void 0;if(!Ka(t,ND,"resource entry",r))m=false;if(typeof a!=="string"||!Mp(a)){r.push(`unsafe resource path: ${s}`);m=false}if(typeof l!=="string"||!/^[\w.+-]+\/[\w.+-]+$/.test(l)){r.push(`invalid media type: ${s}`);m=false}if(typeof c!=="string"||!/^[0-9a-f]{64}$/.test(c)){r.push(`invalid sha256: ${s}`);m=false}if(typeof d!=="number"||!Number.isSafeInteger(d)||d<=0){r.push(`invalid byte size: ${s}`);m=false}if(typeof u!=="boolean"){r.push(`invalid required status: ${s}`);m=false}if(h!=="forbidden"){r.push(`resource permits network fallback: ${s}`);m=false}const f=t.license;let p;if(!wt(f)){r.push(`missing resource licence: ${s}`);m=false}else{if(!Ka(f,$D,"resource licence",r))m=false;const g=f.spdx;const y=f.noticePath;if(typeof g!=="string"||g.trim()===""){r.push(`missing resource licence: ${s}`);m=false}if(typeof y!=="string"||!Mp(y)){r.push(`unsafe resource licence path: ${s}`);m=false}if(typeof g==="string"&&g.trim()!==""&&typeof y==="string"&&Mp(y)){p=Object.freeze({spdx:g,noticePath:y})}}if(!m||o===void 0||p===void 0||typeof a!=="string"||typeof l!=="string"||typeof c!=="string"||typeof d!=="number"||typeof u!=="boolean"){return void 0}return Object.freeze({identity:o,path:a,mediaType:l,sha256:c,bytes:d,license:p,required:u,network:"forbidden"})}function JM(t){const e=[];if(!wt(t))return{errors:Object.freeze(["resource manifest must be a plain object"])};const r=t.version;const i=t.resources;Ka(t,DD,"resource manifest",e);if(r!==Cs)e.push(`unsupported resource manifest version: ${String(r)}`);if(!Array.isArray(i)){e.push("resource manifest resources must be an array");return{errors:Object.freeze(e)}}const n=new Set;const o=new Set;const s=[];for(const[a,l]of Array.from(i).entries()){const c=zD(l,a,e);const d=c?.identity.id??`resource[${a}]`;const u=c?.path;if(n.has(d))e.push(`duplicate resource id: ${d}`);if(u!==void 0&&o.has(u))e.push(`duplicate resource path: ${u}`);n.add(d);if(u!==void 0)o.add(u);if(c!==void 0)s.push(c)}if(e.length>0)return{errors:Object.freeze(e)};return{errors:Object.freeze([]),snapshot:Object.freeze({version:Cs,resources:Object.freeze(s)})}}function QM(t){return[...JM(t).errors]}function ZM(t){const e=JM(t);if(!e.snapshot)throw new TypeError(`INVALID_RESOURCE_MANIFEST: ${e.errors.join("; ")}`);return e.snapshot}function GD(t){return t.length>=4&&t[0]===0&&t[1]===1&&t[2]===0&&t[3]===0}var WD=Object.freeze({"font/ttf":GD});function UD(t){return Array.from(t,e=>e.toString(16).padStart(2,"0")).join("")}async function jD(t,e,r={}){let i;try{const a=t;i=ZM({version:Cs,resources:[{identity:a.identity,path:a.path,mediaType:a.mediaType,sha256:a.sha256,bytes:a.bytes,license:a.license,required:a.required,network:a.network}]}).resources[0]}catch(a){throw new TypeError(`INVALID_RESOURCE_ENTRY: ${KM(a)}`)}if(!(e instanceof Uint8Array))throw new TypeError("INVALID_RESOURCE_BYTES: bytes must be a Uint8Array");if(!wt(r))throw new TypeError("INVALID_RESOURCE_VERIFY_OPTIONS: options must be a plain object");for(const a of Reflect.ownKeys(r)){if(typeof a!=="string"||a!=="mediaTypes"&&a!=="digest"){throw new TypeError(`INVALID_RESOURCE_VERIFY_OPTIONS: unknown option ${String(a)}`)}}if(r.mediaTypes!==void 0){if(!wt(r.mediaTypes))throw new TypeError("INVALID_RESOURCE_VERIFY_OPTIONS: mediaTypes must be a plain object");for(const[a,l]of Object.entries(r.mediaTypes)){if(typeof l!=="function")throw new TypeError(`INVALID_RESOURCE_VERIFY_OPTIONS: mediaTypes.${a} must be a function`)}}if(r.digest!==void 0&&typeof r.digest!=="function"){throw new TypeError("INVALID_RESOURCE_VERIFY_OPTIONS: digest must be a function")}if(e.byteLength!==i.bytes){throw new Error(`RESOURCE_SIZE_MISMATCH: ${i.identity.id} declared ${i.bytes} bytes but received ${e.byteLength}`)}const n=(r.mediaTypes??WD)[i.mediaType];if(!n||!n(e))throw new Error(`RESOURCE_MEDIA_TYPE_MISMATCH: ${i.identity.id} is not ${i.mediaType}`);const o=r.digest??(async a=>{if(!globalThis.crypto?.subtle)throw new Error("RESOURCE_DIGEST_UNAVAILABLE: Web Crypto SHA-256 is required");const l=new Uint8Array(a.byteLength);l.set(a);return UD(new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256",l.buffer)))});const s=await o(e);if(s!==i.sha256)throw new Error(`RESOURCE_DIGEST_MISMATCH: ${i.identity.id}`)}var VD=[{family:"Inter",file:"Inter-Regular.ttf",weight:"400",style:"normal",sha256:"1b08e7fc267a5c7e1d614100f604b83e7e8a0be241f0f288faa2b3ac93a683ba",bytes:324820,license:"OFL-1.1"},{family:"Inter",file:"Inter-Medium.ttf",weight:"500",style:"normal",sha256:"8c883f63b2c4157d997319f2c8bc6995ed4357ef371940d31ca159004a4aae63",bytes:325304,license:"OFL-1.1"},{family:"Inter",file:"Inter-SemiBold.ttf",weight:"600",style:"normal",sha256:"e7a1aaf7eda9f2fad4131725fa556265ec75ca7b2d756260173a040363e8d4f7",bytes:326048,license:"OFL-1.1"},{family:"Inter",file:"Inter-Bold.ttf",weight:"700",style:"normal",sha256:"b37284b5701b6b168dfc770aa1a4ac492106422fd3ba76bc7641e37434e8019c",bytes:326468,license:"OFL-1.1"},{family:"Caveat",file:"Caveat.ttf",weight:"400 700",style:"normal",sha256:"0bdb6b660482d31531b3945849fba5916b3ef8695da7024a9e6b9ee3c4157988",bytes:403648,license:"OFL-1.1"},{family:"EB Garamond",file:"EBGaramond.ttf",weight:"400 700",style:"normal",sha256:"ef9512f92f6d579e5dc75af59a5a4b1b8b47d2eda89e00b954d44520e5369027",bytes:851176,license:"OFL-1.1"},{family:"Architects Daughter",file:"ArchitectsDaughter.ttf",weight:"400",style:"normal",sha256:"6159718a08898e34bc1cb7354086141a5f9a70b73e54dbec27ead0d59a697359",bytes:43352,license:"OFL-1.1"},{family:"Share Tech Mono",file:"ShareTechMono.ttf",weight:"400",style:"normal",sha256:"9ceab1f87414829af259c0f537573ae03ef7dd3147c0b27a36a1a0beb6732677",bytes:43272,license:"OFL-1.1"},{family:"DejaVu Sans",file:"DejaVuSans.ttf",weight:"400",style:"normal",sha256:"ae7b7855e115a5966d8b1b3f80f254ccc117ec86f9965e202ee2940453837280",bytes:759720,license:"Bitstream-Vera"},{family:"DejaVu Sans",file:"DejaVuSans-Bold.ttf",weight:"700",style:"normal",sha256:"5c1247acef7f2b8522a31742c76d6adcb5569bacc0be7ceaa4dc39dd252ce895",bytes:708920,license:"Bitstream-Vera"}];function YD(t){return`font/${t.file.toLowerCase().replace(/[^a-z0-9._/-]+/g,"-")}`}var Ja=Object.freeze(VD.map(t=>Object.freeze({family:t.family,file:t.file,weight:t.weight,style:t.style,path:`assets/fonts/${t.file}`,mediaType:"font/ttf",sha256:t.sha256,bytes:t.bytes,license:Object.freeze({spdx:t.license,noticePath:"assets/fonts/FONT-LICENSES.md"}),required:true,network:"forbidden",identity:Ci({id:`resource:${YD(t)}`,kind:"resource",version:"1.0.0",compatibility:{core:ml},provenance:{owner:"agentic-mermaid",source:"bundled",reference:`assets/fonts/${t.file}`}})})));var eA=Object.freeze({version:Cs,resources:Object.freeze(Ja.map(t=>Object.freeze({identity:t.identity,path:t.path,mediaType:t.mediaType,sha256:t.sha256,bytes:t.bytes,license:t.license,required:t.required,network:t.network})))});function HD(t=eA){return QM(t)}function XD(t){const e=Ja.find(r=>r.file===t);if(!e)throw new Error(`Unknown bundled font resource: ${t}`);return e}var ou=Object.freeze({version:1,id:"srgb",svgColorInterpolation:"sRGB",gamutMapping:"clip-to-srgb",png:Object.freeze({sRGBRenderingIntent:0,cICP:Object.freeze([1,13,0,1]),iCCP:"absent-when-sRGB-is-present",precedence:Object.freeze(["cICP","iCCP","sRGB","gAMA+cHRM"])})});var su=new Uint8Array([137,80,78,71,13,10,26,10]);var KD=new Set(["cICP","iCCP","sRGB","gAMA","cHRM"]);function JD(t){return new TextEncoder().encode(t)}function tA(t){const e=new Uint8Array(4);new DataView(e.buffer).setUint32(0,t>>>0);return e}function Ap(t){const e=new Uint8Array(t.reduce((i,n)=>i+n.length,0));let r=0;for(const i of t){e.set(i,r);r+=i.length}return e}function iA(t){let e=4294967295;for(const r of t){e^=r;for(let i=0;i<8;i++)e=e>>>1^(e&1?3988292384:0)}return(e^4294967295)>>>0}function rA(t,e){const r=JD(t);return Ap([tA(e.length),r,e,tA(iA(Ap([r,e])))])}function QD(t){if(t.length<su.length||su.some((e,r)=>t[r]!==e)){throw new Error("Expected a PNG byte stream")}}function Op(t){QD(t);const e=[];let r=su.length;let i=false;while(r<t.length){if(r+12>t.length)throw new Error("Truncated PNG chunk header");const s=new DataView(t.buffer,t.byteOffset+r,4).getUint32(0);const a=r+12+s;if(a>t.length)throw new Error("Truncated PNG chunk");const l=new TextDecoder().decode(t.subarray(r+4,r+8));if(!/^[A-Za-z]{4}$/.test(l))throw new Error("Invalid PNG chunk type");const c=t.subarray(r+4,r+8+s);const d=new DataView(t.buffer,t.byteOffset+r+8+s,4).getUint32(0);if(d!==iA(c))throw new Error(`Invalid PNG CRC for ${l}`);const u={type:l,bytes:t.slice(r,a),data:t.slice(r+8,r+8+s)};e.push(u);r=a;if(l==="IEND"){if(s!==0)throw new Error("PNG IEND must be empty");i=true;break}}if(r!==t.length)throw new Error("PNG contains trailing bytes after IEND");if(!i)throw new Error("PNG is missing IEND");const n=e[0];if(n?.type!=="IHDR"||n.data.length!==13)throw new Error("PNG IHDR must be first and contain 13 bytes");if(e.filter(s=>s.type==="IHDR").length!==1)throw new Error("PNG must contain exactly one IHDR");const o=new DataView(n.data.buffer,n.data.byteOffset,n.data.byteLength);if(o.getUint32(0)===0||o.getUint32(4)===0)throw new Error("PNG dimensions must be non-zero");if(!e.some(s=>s.type==="IDAT"))throw new Error("PNG is missing IDAT image data");return e}function Bp(t){const e=Op(t)[0];const r=new DataView(e.data.buffer,e.data.byteOffset,e.data.byteLength);return Object.freeze({width:r.getUint32(0),height:r.getUint32(4)})}function _p(t){const e=Op(t);const r=e.find(n=>n.type==="sRGB");const i=e.find(n=>n.type==="cICP");return{chunks:e.map(n=>n.type),sRGBRenderingIntent:r?.data[0],cICP:i?[...i.data]:void 0,hasICC:e.some(n=>n.type==="iCCP"),profile:ou.id}}function Ip(t){const e=Op(t);const r=e[0];if(r?.type!=="IHDR")throw new Error("PNG IHDR must be first");const i=e.slice(1).filter(n=>!KD.has(n.type)).map(n=>n.bytes);return Ap([su,r.bytes,rA("sRGB",new Uint8Array([ou.png.sRGBRenderingIntent])),rA("cICP",new Uint8Array(ou.png.cICP)),...i])}var cA="Inter";var Za=16777216;var uo=16384;var Lp=4194304;var ZD=8388608;var au=16;var lu=4096;var Np=9;var dA=Object.freeze({transparent:"#00000000",black:"#000000",silver:"#c0c0c0",gray:"#808080",grey:"#808080",white:"#ffffff",maroon:"#800000",red:"#ff0000",purple:"#800080",fuchsia:"#ff00ff",green:"#008000",lime:"#00ff00",olive:"#808000",yellow:"#ffff00",navy:"#000080",blue:"#0000ff",teal:"#008080",aqua:"#00ffff",orange:"#ffa500"});var Qa={scope:"portable",input:"serializable",policy:"included",receipt:"included"};var nA={...Qa,scope:"native-host-only"};var Qr={scale:Qa,background:Qa,fitTo:Qa,minLabelPx:Qa,fontDirs:nA,loadSystemFonts:nA,onWarning:{scope:"native-host-only",input:"callback",policy:"excluded",receipt:"excluded"}};function eN(){const t={type:"number",exclusiveMinimum:0};const e={type:"integer",minimum:1};function r(o){return[...o].map(s=>`[${s.toLowerCase()}${s.toUpperCase()}]`).join("")}const i=`^\\s*(?:#[0-9A-Fa-f]{3,4}|#[0-9A-Fa-f]{6}|#[0-9A-Fa-f]{8}|${Object.keys(dA).map(r).join("|")})\\s*$`;const n={type:"object",additionalProperties:false,properties:{width:{...e,description:"Exact output width in integer pixels."},height:{...e,description:"Exact output height in integer pixels."}},oneOf:[{required:["width"]},{required:["height"]}],description:"Exactly one positive output width or height."};return xy({scale:{...Qr.scale,typeScript:"number",description:"Positive output scale used when no fitTo constraint is supplied.",schema:{...t,default:ci}},background:{...Qr.background,typeScript:"string",description:"Portable basic color or hex color painted behind the raster artifact.",schema:{type:"string",minLength:1,pattern:i},runtimeValidator:"portablePngBackground"},fitTo:{...Qr.fitTo,typeScript:"{ width: number; height?: never } | { width?: never; height: number }",description:"Exactly one output width or height constraint.",schema:n},minLabelPx:{...Qr.minLabelPx,typeScript:"number",description:"Legibility floor in effective px: the render warns (BELOW_READABLE_SIZE) when fitTo/scale rasterizes the smallest configured text below it. 0 disables.",schema:{type:"number",minimum:0,default:Np}},fontDirs:{...Qr.fontDirs,typeScript:"readonly string[]",description:"Trusted native host directories searched for additional fonts.",schema:{type:"array",maxItems:au,items:{type:"string",minLength:1,maxLength:lu,pattern:"\\S"}}},loadSystemFonts:{...Qr.loadSystemFonts,typeScript:"boolean",description:"Allow the native rasterizer to load machine-dependent system fonts.",schema:{type:"boolean",default:false}},onWarning:{...Qr.onWarning,typeScript:"(warning: PngRasterWarning) => void",description:"Native host callback for glyph-coverage and raster-legibility warnings; never serialized or receipted."}})}var uA=eN();var el=Object.freeze(Object.keys(Qr));var du=Object.freeze(el.filter(t=>Qr[t].scope==="portable"));var uu=Object.freeze(el.filter(t=>Qr[t].policy==="included"));var tN=Object.freeze(el.filter(t=>Qr[t].scope==="native-host-only"));function Rp(t){if(Array.isArray(t))return t.map(Rp);if(typeof t!=="object"||t===null)return t;return Object.fromEntries(Object.entries(t).map(([e,r])=>[e,Rp(r)]))}function rN(t="portable"){const e=t==="portable"?du:uu;const r=Object.fromEntries(e.map(i=>{const n=uA[i];if(!n.schema)throw new Error(`PNG policy field ${i} has no serializable schema`);return[i,{...Rp(n.schema),description:n.description,"x-agentic-mermaid-scope":n.scope,"x-agentic-mermaid-receipt":n.receipt,..."runtimeValidator"in n?{"x-agentic-mermaid-runtime-validator":n.runtimeValidator}:{}}]}));return{$schema:"https://json-schema.org/draft/2020-12/schema",$id:`https://agentic-mermaid.dev/schemas/png-output-options-v${oa}-${t}.schema.json`,type:"object",additionalProperties:false,properties:r}}function ks(t){if(typeof t!=="string")throw new RangeError("SVG input must be a string for PNG rasterization");const e=fg(t);if(!e)throw new RangeError("could not determine the SVG root for PNG rasterization");return e}function cu(t,e){return Ms(t,e)}function oA(t,e){const r=t?.trim();if(!r||!/^(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?(?:px)?$/i.test(r)){throw new RangeError(`SVG root ${e} must be a positive finite absolute pixel length for PNG rasterization`)}const i=Number(r.replace(/px$/i,""));if(!Number.isFinite(i)||i<=0){throw new RangeError(`SVG root ${e} must be a positive finite absolute pixel length for PNG rasterization`)}return i}function hA(t){const e=cu(t,"viewBox")?.trim().split(/[\s,]+/).map(Number);const r=e?.[2];const i=e?.[3];if(e?.length!==4||e.some(n=>!Number.isFinite(n))||r===void 0||i===void 0||r<=0||i<=0){throw new RangeError("SVG root viewBox must contain four finite values with positive bounds for PNG rasterization")}return Object.freeze({width:r,height:i})}function mA(t){return hA(ks(t))}function hu(t){const e=ks(t);const r=hA(e);const i=cu(e,"width")?.trim();const n=cu(e,"height")?.trim();const o=i==="100%"&&n==="100%";const s=o?r.width:oA(i,"width");const a=o?r.height:oA(n,"height");const l=s/a;const c=r.width/r.height;const d=Math.abs(l-c);const u=Math.max(Math.abs(l),Math.abs(c),1)*1e-9;if(d>u){throw new RangeError(`SVG intrinsic dimensions ${s}\xD7${a} are inconsistent with viewBox ${r.width}\xD7${r.height}`)}return Object.freeze({width:s,height:a})}function fA(t,e){const r=hu(t);if(typeof e!=="number"&&!wt(e)){throw new RangeError("PNG raster policy must be a positive scale or resolved policy object")}if(typeof e==="number"&&(!Number.isFinite(e)||e<=0)){throw new RangeError("PNG raster scale must be a positive finite number")}if(typeof e!=="number"){if(typeof e.scale!=="number"||!Number.isFinite(e.scale)||e.scale<=0||!wt(e.fitTo)||!["zoom","width","height"].includes(String(e.fitTo.mode))||typeof e.fitTo.value!=="number"||!Number.isFinite(e.fitTo.value)||e.fitTo.value<=0){throw new RangeError("PNG raster policy must contain a positive finite scale and fitTo mode/value")}}const i=typeof e==="number"?{mode:"zoom",value:e}:e.fitTo;const n=typeof e==="number"?e:e.scale;const o=i.mode==="width"?i.value:i.mode==="height"?r.width*i.value/r.height:r.width*n;const s=i.mode==="height"?i.value:i.mode==="width"?r.height*i.value/r.width:r.height*n;if(!Number.isFinite(o)||!Number.isFinite(s)||o<=0||s<=0){throw new RangeError("PNG raster budget rejected non-finite or non-positive final dimensions")}const a=Math.max(1,Math.ceil(o));const l=Math.max(1,Math.ceil(s));return Object.freeze({width:a,height:l,pixels:a*l})}function Pp(t,e){if(!Number.isSafeInteger(e.width)||e.width<=0||!Number.isSafeInteger(e.height)||e.height<=0||!Number.isSafeInteger(e.pixels)||e.pixels!==e.width*e.height){throw new RangeError("PNG raster dimensions must be positive safe integers")}const r=ks(t);if(!Es(r,"width")||!Es(r,"height")){throw new RangeError("SVG root must declare intrinsic width and height")}let i=ul(t.slice(r.start,r.end),s=>{if(s.name==="width")return String(e.width);if(s.name==="height")return String(e.height);return void 0});const n=ks(i);i=Es(n,"preserveAspectRatio")?ul(i,s=>s.name==="preserveAspectRatio"?"none":void 0):`${i.slice(0,-1)} preserveAspectRatio="none">`;const o=`width:${e.width}px!important;height:${e.height}px!important`;if(Es(ks(i),"style")){i=ul(i,s=>s.name==="style"?`${s.value.replace(/;?\s*$/,";")}${o}`:void 0)}else{i=`${i.slice(0,-1)} style="${o}">`}return gg(t,r,i)}function Fp(t,e){const r=fA(t,e);if(r.width>uo||r.height>uo||!Number.isSafeInteger(r.pixels)||r.pixels>Za){const i=Number.isFinite(r.pixels)?`${Math.ceil(r.pixels/1e6)}MP`:"a non-finite pixel count";throw new RangeError(`PNG raster budget exceeded: ${r.width}\xD7${r.height} (${i}); maximum dimension is ${uo}px and pixel cap is ${Math.ceil(Za/1e6)}MP`)}return r}function iN(t){const e=wt(t);const r=e?t.width:Number.NaN;const i=e?t.height:Number.NaN;const n=e?t.pixels:Number.NaN;if(!e||!Number.isSafeInteger(r)||r<=0||!Number.isSafeInteger(i)||i<=0||!Number.isSafeInteger(n)||n<=0||n!==r*i||r>uo||i>uo||n>Lp){throw new RangeError(`hosted PNG raster budget exceeded: ${String(r)}\xD7${String(i)}; maximum dimension is ${uo}px and hosted pixel cap is ${Math.ceil(Lp/1e6)}MP`)}return t}var nN=Object.freeze(Ja.map(t=>`${t.identity.id}@${t.identity.version}#sha256:${t.sha256}`));function sA(t,e,r){if(!wt(t))throw new TypeError(`${r} must be a plain object`);const i=new Set(e);for(const n of Reflect.ownKeys(t)){if(typeof n!=="string"||!i.has(n)){throw new TypeError(`${r} contains unknown option ${typeof n==="symbol"?String(n):`"${n}"`}`)}}}function oN(t,e){if(typeof t!=="number"||!Number.isFinite(t)||t<=0){throw new TypeError(`${e} must be a positive finite number`)}return t}function aA(t,e){if(typeof t!=="number"||!Number.isSafeInteger(t)||t<=0){throw new TypeError(`${e} must be a positive integer number of pixels`)}return t}function pA(t){if(typeof t!=="string")return void 0;const e=Ft(t);if(!e)return void 0;const r=e.map((n,o)=>{const s=o===3?n*255:n;return Math.round(Math.max(0,Math.min(255,s)))});const i=r.map(n=>n.toString(16).padStart(2,"0")).join("");return`#${r[3]===255?i.slice(0,6):i}`}function gA(t){if(typeof t!=="string")return void 0;const e=t.trim().toLowerCase();if(!/^#[0-9a-f]{3,4}$/.test(e)&&!/^#[0-9a-f]{6}(?:[0-9a-f]{2})?$/.test(e)&&!(e in dA))return void 0;return pA(e)}var lA="PNG_ARTIFACT_BACKGROUND_UNRESOLVED";var Dp=class extends TypeError{code=lA;paint;constructor(e){super(`${lA}: PNG artifact background must resolve to a concrete CSS color`);this.name="PngArtifactBackgroundError";this.paint=e}};function yA(t,e){if(e.background.mode==="explicit")return e.background.value;const r=cu(ks(t),"style");const i=r?.match(/(?:^|;)\s*--bg\s*:\s*([^;]+)/i)?.[1]?.trim();if(i===void 0)return e.background.fallback;const n=pA(i);if(n===void 0)throw new Dp(i);return n}function xA(t,e){return Object.fromEntries(e.flatMap(r=>Object.prototype.hasOwnProperty.call(t,r)&&t[r]!==void 0?[[r,t[r]]]:[]))}function sN(t){return xA(t,du)}function aN(t){return xA(t,uu)}function lN(t){const e=new Set(el);return Object.fromEntries(Object.entries(t).filter(([r])=>!e.has(r)))}function bA(t,e){const r=e==="portable"?du:uu;sA(t,r,`${e==="portable"?"portable":"native"} PNG output options`);const i=t.scale===void 0?ci:oN(t.scale,"PNG scale");const n=t.minLabelPx===void 0?Np:t.minLabelPx;if(typeof n!=="number"||!Number.isFinite(n)||n<0){throw new RangeError("PNG minLabelPx must be a non-negative finite number")}let o;let s;if(t.fitTo!==void 0){sA(t.fitTo,["width","height"],"PNG fitTo");const m=Object.keys(t.fitTo);if(m.length!==1||m[0]!=="width"&&m[0]!=="height"){throw new TypeError("PNG fitTo accepts exactly one of width or height")}if(Object.prototype.hasOwnProperty.call(t.fitTo,"width")){o=aA(t.fitTo.width,"PNG fitTo.width")}else{s=aA(t.fitTo.height,"PNG fitTo.height")}}if(t.background!==void 0&&typeof t.background!=="string"){throw new TypeError("PNG background must be a safe CSS color")}const a=t.background===void 0?void 0:gA(t.background);if(t.background!==void 0&&!a){throw new TypeError("PNG background must be a safe CSS color in the portable basic-keyword or 3, 4, 6, or 8 digit hex intersection")}let l=[];let c=false;if(e==="native"){if(t.fontDirs!==void 0){const m=t.fontDirs;if(!Array.isArray(m)||Object.getPrototypeOf(m)!==Array.prototype||m.length>au||Reflect.ownKeys(m).some(f=>f!=="length"&&(typeof f!=="string"||!/^(?:0|[1-9]\d*)$/.test(f)||Number(f)>=m.length))){throw new TypeError(`PNG fontDirs must be a dense array of at most ${au} paths`)}for(let f=0;f<m.length;f++){const p=m[f];if(!Object.prototype.hasOwnProperty.call(m,f)||typeof p!=="string"||p.trim()===""||p.length>lu){throw new TypeError(`PNG fontDirs must be a dense array of non-empty paths no longer than ${lu} characters`)}}l=m}if(t.loadSystemFonts!==void 0&&typeof t.loadSystemFonts!=="boolean"){throw new TypeError("PNG loadSystemFonts must be a boolean")}c=t.loadSystemFonts??false}const d=o!==void 0?{mode:"width",value:o}:s!==void 0?{mode:"height",value:s}:{mode:"zoom",value:i};const u=d.mode==="zoom"?i:ci;const h=a===void 0?{mode:"artifact",fallback:"#ffffff"}:{mode:"explicit",value:a};return Object.freeze({version:oa,scale:u,background:Object.freeze(h),fitTo:Object.freeze(d),minLabelPx:n,fonts:Object.freeze({defaultFamily:cA,bundledResources:nN,callerDirectories:Object.freeze([...l]),loadSystemFonts:c})})}function $p(t={}){return bA(t,"portable")}function qp(t={}){return bA(t,"native")}var cN=Object.freeze(["verified-files","verified-buffers","caller-directories","system-fonts","embedded-data-uri","unavailable"]);var CA=Object.freeze({engine:"resvg",engineVersion:"2.6.2",binding:"napi",fontSources:Object.freeze(["verified-files"]),reproducibility:"content-addressed"});var dN=Object.freeze({engine:"resvg",engineVersion:"2.6.2",binding:"wasm",fontSources:Object.freeze(["verified-buffers"]),reproducibility:"content-addressed"});function uN(t={}){const e=["verified-files"];if((t.callerDirectories?.length??0)>0)e.push("caller-directories");if(t.loadSystemFonts)e.push("system-fonts");if(e.length===1)return CA;return Object.freeze({engine:"resvg",engineVersion:"2.6.2",binding:"napi",fontSources:Object.freeze(e),reproducibility:"host-dependent"})}var mu=Object.freeze({engine:"canvas",binding:"browser",fontSources:Object.freeze(["unavailable"]),reproducibility:"host-dependent"});var hN=new Set(["verified-buffers","embedded-data-uri","unavailable"]);var SA=1048576;var mN=Za*4+SA;var kA=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype),"byteLength")?.get;function fN(t){if(kA===void 0){throw new Error("TypedArray byteLength intrinsic is unavailable")}return Reflect.apply(kA,t,[])}function zp(t,e){const r=e.pixels*4+e.height+SA;const i=Math.min(mN,r);if(fN(t)>i){throw new RangeError(`browser PNG rasterizer output exceeds the ${i}-byte allocation-derived limit`)}}function wA(t){if(t===void 0)return mu;if(!Array.isArray(t)||t.length===0){throw new TypeError("browser PNG rasterizer fontSources must be a non-empty array when supplied")}const e=[];for(const r of t){if(!hN.has(r))throw new TypeError(`browser PNG rasterizer reported an invalid font source: ${String(r)}`);if(!e.includes(r))e.push(r)}if(e.length===1&&e[0]==="unavailable")return mu;return Object.freeze({engine:"canvas",binding:"browser",fontSources:Object.freeze(e),reproducibility:"host-dependent"})}var pN=/^(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?(?:px)?$/i;var gN=new Set(["text","tspan","textpath"]);var yN=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;function xN(t){let e=t.trim();while(e.length>0){const r=/^(translate|rotate)\s*\(([^)]*)\)\s*,?\s*/i.exec(e);if(!r)return false;const i=r[2].trim().split(/[\s,]+/).filter(Boolean);if(!i.every(n=>yN.test(n)))return false;if(r[1].toLowerCase()==="translate"&&i.length!==1&&i.length!==2)return false;if(r[1].toLowerCase()==="rotate"&&i.length!==1&&i.length!==3)return false;e=e.slice(r[0].length)}return true}function bN(t){if(/(?:^|[;{\n])\s*(?:font|font-size|transform)\s*:/i.test(pg(t)))return true;for(const e of vn(t)){const r=Ms(e,"transform");if(r!==void 0&&!xN(r))return true}return false}function CN(t){if(bN(t))return void 0;let e;for(const r of vn(t)){if(!gN.has(r.name.toLowerCase()))continue;const i=Ms(r,"font-size")?.trim();if(!i||!pN.test(i))continue;const n=Number(i.replace(/px$/i,""));if(Number.isFinite(n)&&n>=0&&(e===void 0||n<e)){e=n}}return e}var tl=t=>Number(t.toFixed(2)).toString();function TA(t,e,r){if(e.minLabelPx<=0)return[];const i=CN(t);if(i===void 0)return[];const n=hu(t);const o=mA(t);const s=r.height/o.height;const a=i*s;if(a>=e.minLabelPx)return[];const l=e.fitTo.mode==="zoom"?"scale":"fitTo";const c=l==="fitTo"?`fitTo ${e.fitTo.mode} ${e.fitTo.value}px against a ${tl(n.width)}\xD7${tl(n.height)} diagram`:`scale ${e.fitTo.value}`;return[{code:"BELOW_READABLE_SIZE",naturalWidth:n.width,naturalHeight:n.height,effectiveScale:s,baseMinLabelPx:i,effectiveMinLabelPx:a,floorPx:e.minLabelPx,cause:l,message:`smallest measurable configured text is ${tl(i)}px and ${c} projects it to ${tl(a)}px, below the ${tl(e.minLabelPx)}px legibility floor. Raise the fit/scale, split the diagram, or pass minLabelPx: 0 to accept the shrink.`}]}function vA(t,e){const r=Pp(t,e);Jb(r,"PNG raster SVG");return Nu(r,"strict").svg}function EA(t,e,r,i={}){const n=Fo(t,e,"png",r,i);const o=yA(n.svg,r);const s=Fp(n.svg,r);return{...n,outputPolicy:r,rasterBackground:o,rasterDimensions:s,legibilityWarnings:Object.freeze(TA(n.svg,r,s))}}function hK(t,e,r={},i={}){return EA(t,e,qp(r),i)}function MA(t,e,r={},i={}){return EA(t,e,$p(r),i)}function Gp(t){if(t===void 0)return{scale:ci};return typeof t==="number"?{scale:t}:t}function kN(t){if(!t||typeof t!=="object")throw new TypeError("browser PNG renderer host options are required");const e=t.rasterize;if(typeof e!=="function")throw new TypeError("browser PNG rasterizer must be a function");const r=bc(t.backendPolicy);const i=ll(t.textMeasurement);const n=Object.freeze({rasterize:e,...r?{backendPolicy:r}:{},...i?{textMeasurement:i}:{}});return Object.freeze({async renderMermaidPNG(o,s={},a=ci){const l=Tr(o);return(await Wp(l.source,s,Gp(a),{...n,expectedFamilyId:l.expectedFamilyId})).png},renderMermaidPNGWithReceipt(o,s={},a=ci){const l=Tr(o);return Wp(l.source,s,Gp(a),{...n,expectedFamilyId:l.expectedFamilyId})}})}async function SN(t,e,r,i){const n=Tr(t);return Wp(n.source,e,Gp(r),{rasterize:i,expectedFamilyId:n.expectedFamilyId})}async function Wp(t,e,r,i){if(typeof i.rasterize!=="function")throw new TypeError("browser PNG rasterizer must be a function");const n=MA(t,e,r,{backendPolicy:i.backendPolicy,textMeasurement:i.textMeasurement,expectedFamilyId:i.expectedFamilyId});if(n.receipt.output!=="png")throw new Error("browser PNG adapter received a non-PNG receipt");const o=vA(xg(n.svg),n.rasterDimensions);const s=await i.rasterize(o,{outputPolicy:n.outputPolicy,rasterDimensions:n.rasterDimensions,rasterBackground:n.rasterBackground,receipt:n.receipt});const a=s?.png;const l=s?.diagnostics;const c=s?.fontSources;if(!(a instanceof Uint8Array))throw new TypeError("browser PNG rasterizer must return Uint8Array bytes");zp(a,n.rasterDimensions);const d=wA(c);const u=Ip(a);zp(u,n.rasterDimensions);const h=Bp(u);if(h.width!==n.rasterDimensions.width||h.height!==n.rasterDimensions.height){throw new Error(`browser PNG rasterizer returned ${h.width}\xD7${h.height}; expected ${n.rasterDimensions.width}\xD7${n.rasterDimensions.height}`)}const m=_p(u);if(m.profile!=="srgb"||m.hasICC||m.cICP===void 0){throw new Error("browser PNG color-profile gate failed")}return Object.freeze({png:u,receipt:n.receipt,diagnostics:Object.freeze([...n.legibilityWarnings,...l??[]]),colorProfile:Object.freeze(m),runtime:d})}function wN(t,e={}){return TN(t,e).svg}function hQ(t={}){const e=bc(t.backendPolicy);const r=ll(t.textMeasurement);const i=Object.freeze({...e?{backendPolicy:e}:{},...r?{textMeasurement:r}:{}});return Object.freeze({renderMermaidSVG(n,o={}){const s=Tr(n);return Fo(s.source,o,"svg",void 0,{...i,expectedFamilyId:s.expectedFamilyId}).svg},renderMermaidSVGWithReceipt(n,o={}){const s=Tr(n);return Fo(s.source,o,"svg",void 0,{...i,expectedFamilyId:s.expectedFamilyId})}})}function TN(t,e={}){const r=Tr(t);return Fo(r.source,e,"svg",void 0,{expectedFamilyId:r.expectedFamilyId})}async function mQ(t,e={}){return wN(t,e)}export{la as a,qo as b,$h as c,pk as d,lk as e,GN as f,ck as g,BO as h,LO as i,WN as j,UN as k,Kt as l,RO as m,jN as n,Ii as o,VN as p,YN as q,zh as r,wk as s,HN as t,eP as u,tP as v,rP as w,Mc as x,Fk as y,$k as z,PP as A,a1 as B,KP as C,d1 as D,cF as E,f1 as F,GF as G,g1 as H,x1 as I,b1 as J,C1 as K,k1 as L,r2 as M,ya as N,Ni as O,ba as P,vm as Q,S2 as R,R2 as S,K2 as T,sq as U,aq as V,xq as W,Rq as X,Gq as Y,a5 as Z,x5 as _,E5 as $,s_ as aa,q5 as ba,z5 as ca,o3 as da,s3 as ea,p3 as fa,T3 as ga,w4 as ha,wz as ia,Pt as ja,n6 as ka,o6 as la,LE as ma,NE as na,ao as oa,mp as pa,O6 as qa,gs as ra,fD as sa,Tr as ta,bp as ua,wM as va,OM as wa,BM as xa,_M as ya,IM as za,LM as Aa,kD as Ba,xX as Ca,or as Da,kp as Ea,ED as Fa,NM as Ga,MD as Ha,Ep as Ia,BD as Ja,YM as Ka,RD as La,Cs as Ma,ZM as Na,WD as Oa,jD as Pa,Ja as Qa,eA as Ra,HD as Sa,XD as Ta,ou as Ua,Bp as Va,_p as Wa,Ip as Xa,cA as Ya,Za,uo as _a,Lp as $a,ZD as ab,au as bb,lu as cb,Np as db,uA as eb,el as fb,du as gb,uu as hb,tN as ib,rN as jb,hu as kb,fA as lb,Pp as mb,Fp as nb,iN as ob,gA as pb,sN as qb,aN as rb,lN as sb,$p as tb,qp as ub,cN as vb,CA as wb,dN as xb,uN as yb,mu as zb,vA as Ab,hK as Bb,MA as Cb,kN as Db,SN as Eb,wN as Fb,hQ as Gb,TN as Hb,mQ as Ib};
201
+ //# sourceMappingURL=chunk-JZOJ4YGS.js.map